Drive Editable root attrs from Soma runtime

active-uix
dev 5 months ago
parent e28b486c1c
commit 0eb50840e0

@ -14,10 +14,10 @@ export const editableMorfo = {
defaultElement: 'div', defaultElement: 'div',
optional: false, optional: false,
data: [ data: [
{ attr: 'data-editing', severity: 'optional' }, { attr: 'data-editing', value: v.propRef('editing'), severity: 'optional' },
{ attr: 'data-empty', severity: 'optional' }, { attr: 'data-empty', value: v.propRef('empty'), severity: 'optional' },
{ attr: 'data-disabled', severity: 'optional' }, { attr: 'data-disabled', value: v.propRef('disabled'), severity: 'optional' },
{ attr: 'data-readonly', severity: 'optional' } { attr: 'data-readonly', value: v.propRef('readonly'), severity: 'optional' }
], ],
aria: [] aria: []
}, },
@ -27,7 +27,11 @@ export const editableMorfo = {
kind: 'public', kind: 'public',
defaultElement: 'div', defaultElement: 'div',
optional: true, optional: true,
data: [], data: [
{ attr: 'data-editing', value: v.propRef('editing'), severity: 'optional' },
{ attr: 'data-disabled', value: v.propRef('disabled'), severity: 'optional' },
{ attr: 'data-readonly', value: v.propRef('readonly'), severity: 'optional' }
],
aria: [] aria: []
}, },
{ {

@ -62,12 +62,20 @@ export class EditableProvider {
private constructor(opts: EditableOpts) { private constructor(opts: EditableOpts) {
this.opts = opts; this.opts = opts;
this.soma = Soma.require(); this.soma = Soma.require();
this.runtime = this.soma.runtime(editableMorfo, {}); this.runtime = this.soma.runtime(editableMorfo, {
props: {
editing: () => this.isEditing,
empty: () => this.isEmpty,
disabled: () => this.opts.disabled.current,
readonly: () => this.opts.readonly.current
}
});
this.runtimePart = this.runtime.part('provider', { this.runtimePart = this.runtime.part('provider', {
id: opts.id, id: opts.id,
ref: opts.ref, ref: opts.ref,
owner: this, owner: this,
context: EditableProvider.ctx context: EditableProvider.ctx,
syncAttrs: true
}); });
this.draft = opts.value.current; this.draft = opts.value.current;
@ -134,11 +142,7 @@ export class EditableProvider {
readonly props = $derived.by(() => readonly props = $derived.by(() =>
this.runtimePart.assert({ this.runtimePart.assert({
...this.runtimePart.props, ...this.runtimePart.props
'data-editing': boolToEmptyStrOrUndef(this.isEditing),
'data-empty': boolToEmptyStrOrUndef(this.isEmpty),
'data-disabled': boolToEmptyStrOrUndef(this.opts.disabled.current),
'data-readonly': boolToEmptyStrOrUndef(this.opts.readonly.current)
} as const) } as const)
); );
} }
@ -162,16 +166,14 @@ export class EditableAreaProvider {
this.runtimePart = this.provider.runtime.part('area', { this.runtimePart = this.provider.runtime.part('area', {
id: opts.id, id: opts.id,
ref: opts.ref, ref: opts.ref,
owner: this owner: this,
syncAttrs: true
}); });
} }
readonly props = $derived.by(() => readonly props = $derived.by(() =>
this.runtimePart.assert({ this.runtimePart.assert({
...this.runtimePart.props, ...this.runtimePart.props
'data-editing': boolToEmptyStrOrUndef(this.provider.isEditing),
'data-disabled': boolToEmptyStrOrUndef(this.provider.opts.disabled.current),
'data-readonly': boolToEmptyStrOrUndef(this.provider.opts.readonly.current)
} as const) } as const)
); );
} }

Loading…
Cancel
Save

Powered by TurnKey Linux.