|
|
|
|
@ -7,7 +7,7 @@ import { FormProvider } from '../form/form-provider.svelte';
|
|
|
|
|
|
|
|
|
|
import { fieldMorfo } from '../../../morfo/components/field';
|
|
|
|
|
import { Soma } from '../../core/soma.svelte';
|
|
|
|
|
import type { SomaRuntimePart } from '../../runtime.svelte';
|
|
|
|
|
import type { SomaRuntime, SomaRuntimePart } from '../../runtime.svelte';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ── Root ─────────────────────────────────────────────────────────────────────
|
|
|
|
|
@ -30,6 +30,8 @@ interface FieldOpts
|
|
|
|
|
export class FieldProvider {
|
|
|
|
|
readonly opts: FieldOpts;
|
|
|
|
|
readonly runtimePart: SomaRuntimePart;
|
|
|
|
|
readonly soma: Soma;
|
|
|
|
|
readonly runtime: SomaRuntime;
|
|
|
|
|
static readonly ctx = context<FieldProvider>('Field');
|
|
|
|
|
static get(): FieldProvider | undefined {
|
|
|
|
|
return this.ctx.getOr(undefined) as FieldProvider | undefined;
|
|
|
|
|
@ -53,9 +55,14 @@ export class FieldProvider {
|
|
|
|
|
|
|
|
|
|
private constructor(opts: FieldOpts) {
|
|
|
|
|
this.opts = opts;
|
|
|
|
|
this.runtimePart = Soma.require()
|
|
|
|
|
.runtime(fieldMorfo, {})
|
|
|
|
|
.part('provider', { id: opts.id, ref: opts.ref, owner: this, context: FieldProvider.ctx });
|
|
|
|
|
this.soma = Soma.require();
|
|
|
|
|
this.runtime = this.soma.runtime(fieldMorfo, {});
|
|
|
|
|
this.runtimePart = this.runtime.part('provider', {
|
|
|
|
|
id: opts.id,
|
|
|
|
|
ref: opts.ref,
|
|
|
|
|
owner: this,
|
|
|
|
|
context: FieldProvider.ctx
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Auto-register / unregister with the parent Form (if `name` is set).
|
|
|
|
|
$effect(() => {
|
|
|
|
|
@ -174,10 +181,12 @@ export class FieldLabelProvider {
|
|
|
|
|
|
|
|
|
|
private constructor(opts: FieldLabelOpts) {
|
|
|
|
|
this.opts = opts;
|
|
|
|
|
this.runtimePart = Soma.require()
|
|
|
|
|
.runtime(fieldMorfo, {})
|
|
|
|
|
.part('label', { id: opts.id, ref: opts.ref, owner: this });
|
|
|
|
|
this.provider = FieldProvider.require();
|
|
|
|
|
this.runtimePart = this.provider.runtime.part('label', {
|
|
|
|
|
id: opts.id,
|
|
|
|
|
ref: opts.ref,
|
|
|
|
|
owner: this
|
|
|
|
|
});
|
|
|
|
|
this.provider.labelId.current = opts.id.current;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -207,10 +216,12 @@ export class FieldControlProvider {
|
|
|
|
|
|
|
|
|
|
private constructor(opts: FieldControlOpts) {
|
|
|
|
|
this.opts = opts;
|
|
|
|
|
this.runtimePart = Soma.require()
|
|
|
|
|
.runtime(fieldMorfo, {})
|
|
|
|
|
.part('control', { id: opts.id, ref: opts.ref, owner: this });
|
|
|
|
|
this.provider = FieldProvider.require();
|
|
|
|
|
this.runtimePart = this.provider.runtime.part('control', {
|
|
|
|
|
id: opts.id,
|
|
|
|
|
ref: opts.ref,
|
|
|
|
|
owner: this
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
readonly props = $derived.by(() =>
|
|
|
|
|
@ -246,10 +257,12 @@ export class FieldInputProvider {
|
|
|
|
|
|
|
|
|
|
private constructor(opts: FieldInputOpts) {
|
|
|
|
|
this.opts = opts;
|
|
|
|
|
this.runtimePart = Soma.require()
|
|
|
|
|
.runtime(fieldMorfo, {})
|
|
|
|
|
.part('input', { id: opts.id, ref: opts.ref, owner: this });
|
|
|
|
|
this.provider = FieldProvider.require();
|
|
|
|
|
this.runtimePart = this.provider.runtime.part('input', {
|
|
|
|
|
id: opts.id,
|
|
|
|
|
ref: opts.ref,
|
|
|
|
|
owner: this
|
|
|
|
|
});
|
|
|
|
|
this.provider.inputId.current = opts.id.current;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -303,10 +316,12 @@ export class FieldHelperTextProvider {
|
|
|
|
|
|
|
|
|
|
private constructor(opts: FieldHelperTextOpts) {
|
|
|
|
|
this.opts = opts;
|
|
|
|
|
this.runtimePart = Soma.require()
|
|
|
|
|
.runtime(fieldMorfo, {})
|
|
|
|
|
.part('helper-text', { id: opts.id, ref: opts.ref, owner: this });
|
|
|
|
|
this.provider = FieldProvider.require();
|
|
|
|
|
this.runtimePart = this.provider.runtime.part('helper-text', {
|
|
|
|
|
id: opts.id,
|
|
|
|
|
ref: opts.ref,
|
|
|
|
|
owner: this
|
|
|
|
|
});
|
|
|
|
|
this.provider.helperId.current = opts.id.current;
|
|
|
|
|
|
|
|
|
|
$effect(() => {
|
|
|
|
|
@ -340,10 +355,12 @@ export class FieldErrorTextProvider {
|
|
|
|
|
|
|
|
|
|
private constructor(opts: FieldErrorTextOpts) {
|
|
|
|
|
this.opts = opts;
|
|
|
|
|
this.runtimePart = Soma.require()
|
|
|
|
|
.runtime(fieldMorfo, {})
|
|
|
|
|
.part('error-text', { id: opts.id, ref: opts.ref, owner: this });
|
|
|
|
|
this.provider = FieldProvider.require();
|
|
|
|
|
this.runtimePart = this.provider.runtime.part('error-text', {
|
|
|
|
|
id: opts.id,
|
|
|
|
|
ref: opts.ref,
|
|
|
|
|
owner: this
|
|
|
|
|
});
|
|
|
|
|
this.provider.errorId.current = opts.id.current;
|
|
|
|
|
|
|
|
|
|
$effect(() => {
|
|
|
|
|
@ -370,16 +387,19 @@ interface FieldPrefixOpts extends WithRefOpts {}
|
|
|
|
|
export class FieldPrefixProvider {
|
|
|
|
|
readonly opts: FieldPrefixOpts;
|
|
|
|
|
readonly runtimePart: SomaRuntimePart;
|
|
|
|
|
readonly provider: FieldProvider;
|
|
|
|
|
static create(opts: FieldPrefixOpts) {
|
|
|
|
|
return new FieldPrefixProvider(opts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private constructor(opts: FieldPrefixOpts) {
|
|
|
|
|
this.opts = opts;
|
|
|
|
|
this.runtimePart = Soma.require()
|
|
|
|
|
.runtime(fieldMorfo, {})
|
|
|
|
|
.part('prefix', { id: opts.id, ref: opts.ref, owner: this });
|
|
|
|
|
FieldProvider.require();
|
|
|
|
|
this.provider = FieldProvider.require();
|
|
|
|
|
this.runtimePart = this.provider.runtime.part('prefix', {
|
|
|
|
|
id: opts.id,
|
|
|
|
|
ref: opts.ref,
|
|
|
|
|
owner: this
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
readonly props = $derived.by(() =>
|
|
|
|
|
@ -397,16 +417,19 @@ interface FieldSuffixOpts extends WithRefOpts {}
|
|
|
|
|
export class FieldSuffixProvider {
|
|
|
|
|
readonly opts: FieldSuffixOpts;
|
|
|
|
|
readonly runtimePart: SomaRuntimePart;
|
|
|
|
|
readonly provider: FieldProvider;
|
|
|
|
|
static create(opts: FieldSuffixOpts) {
|
|
|
|
|
return new FieldSuffixProvider(opts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private constructor(opts: FieldSuffixOpts) {
|
|
|
|
|
this.opts = opts;
|
|
|
|
|
this.runtimePart = Soma.require()
|
|
|
|
|
.runtime(fieldMorfo, {})
|
|
|
|
|
.part('suffix', { id: opts.id, ref: opts.ref, owner: this });
|
|
|
|
|
FieldProvider.require();
|
|
|
|
|
this.provider = FieldProvider.require();
|
|
|
|
|
this.runtimePart = this.provider.runtime.part('suffix', {
|
|
|
|
|
id: opts.id,
|
|
|
|
|
ref: opts.ref,
|
|
|
|
|
owner: this
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
readonly props = $derived.by(() =>
|
|
|
|
|
|