|
|
|
|
@ -10,7 +10,7 @@ import { GRID_LIST_LANGS } from './langs';
|
|
|
|
|
import type { GridListSelectionMode } from './types';
|
|
|
|
|
|
|
|
|
|
import { gridListMorfo } from '../../../morfo/components/grid-list';
|
|
|
|
|
import type { SomaRuntimePart } from '../../runtime.svelte';
|
|
|
|
|
import type { SomaRuntime, SomaRuntimePart } from '../../runtime.svelte';
|
|
|
|
|
|
|
|
|
|
const attrs = createAttrs(gridListMorfo);
|
|
|
|
|
|
|
|
|
|
@ -38,6 +38,8 @@ interface GridListOpts
|
|
|
|
|
export class GridListProvider {
|
|
|
|
|
readonly opts: GridListOpts;
|
|
|
|
|
readonly runtimePart: SomaRuntimePart;
|
|
|
|
|
readonly soma: Soma;
|
|
|
|
|
readonly runtime: SomaRuntime;
|
|
|
|
|
static readonly ctx = context<GridListProvider>('GridList');
|
|
|
|
|
static get(): GridListProvider | undefined {
|
|
|
|
|
return this.ctx.getOr(undefined) as GridListProvider | undefined;
|
|
|
|
|
@ -50,7 +52,6 @@ export class GridListProvider {
|
|
|
|
|
return new GridListProvider(opts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
readonly soma = Soma.get();
|
|
|
|
|
readonly field = FieldProvider.get();
|
|
|
|
|
|
|
|
|
|
private typeaheadBuffer = '';
|
|
|
|
|
@ -60,9 +61,14 @@ export class GridListProvider {
|
|
|
|
|
|
|
|
|
|
private constructor(opts: GridListOpts) {
|
|
|
|
|
this.opts = opts;
|
|
|
|
|
this.runtimePart = Soma.require()
|
|
|
|
|
.runtime(gridListMorfo, {})
|
|
|
|
|
.part('provider', { id: opts.id, ref: opts.ref, owner: this, context: GridListProvider.ctx });
|
|
|
|
|
this.soma = Soma.require();
|
|
|
|
|
this.runtime = this.soma.runtime(gridListMorfo, {});
|
|
|
|
|
this.runtimePart = this.runtime.part('provider', {
|
|
|
|
|
id: opts.id,
|
|
|
|
|
ref: opts.ref,
|
|
|
|
|
owner: this,
|
|
|
|
|
context: GridListProvider.ctx
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$effect(() => {
|
|
|
|
|
return () => {
|
|
|
|
|
@ -87,13 +93,13 @@ export class GridListProvider {
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
readonly resolvedDir: Active<Direction> = readableActive(
|
|
|
|
|
() => this.soma?.prefs.getDir() ?? 'ltr'
|
|
|
|
|
() => this.soma.prefs.getDir() ?? 'ltr'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
readonly resolvedAriaLabel: Active<string | undefined> = readableActive(() =>
|
|
|
|
|
this.opts.ariaLabelledby.current
|
|
|
|
|
? undefined
|
|
|
|
|
: this.opts.ariaLabel.current || this.soma?.langs.ts(GRID_LIST_LANGS.LABEL) || undefined
|
|
|
|
|
: this.opts.ariaLabel.current || this.soma.langs.ts(GRID_LIST_LANGS.LABEL) || undefined
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
readonly isEmpty = $derived.by(() => this.opts.value.current.length === 0);
|
|
|
|
|
@ -448,10 +454,12 @@ export class GridListRowProvider {
|
|
|
|
|
|
|
|
|
|
private constructor(opts: GridListRowOpts) {
|
|
|
|
|
this.opts = opts;
|
|
|
|
|
this.runtimePart = Soma.require()
|
|
|
|
|
.runtime(gridListMorfo, {})
|
|
|
|
|
.part('row', { id: opts.id, ref: opts.ref, owner: this });
|
|
|
|
|
this.provider = GridListProvider.require();
|
|
|
|
|
this.runtimePart = this.provider.runtime.part('row', {
|
|
|
|
|
id: opts.id,
|
|
|
|
|
ref: opts.ref,
|
|
|
|
|
owner: this
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
readonly isSelected = $derived.by(() => this.provider.isSelected(this.opts.value.current));
|
|
|
|
|
@ -508,10 +516,12 @@ export class GridListCellProvider {
|
|
|
|
|
|
|
|
|
|
private constructor(opts: GridListCellOpts) {
|
|
|
|
|
this.opts = opts;
|
|
|
|
|
this.runtimePart = Soma.require()
|
|
|
|
|
.runtime(gridListMorfo, {})
|
|
|
|
|
.part('cell', { id: opts.id, ref: opts.ref, owner: this });
|
|
|
|
|
this.provider = GridListProvider.require();
|
|
|
|
|
this.runtimePart = this.provider.runtime.part('cell', {
|
|
|
|
|
id: opts.id,
|
|
|
|
|
ref: opts.ref,
|
|
|
|
|
owner: this
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -550,10 +560,12 @@ export class GridListSelectionCheckboxProvider {
|
|
|
|
|
|
|
|
|
|
private constructor(opts: GridListSelectionCheckboxOpts) {
|
|
|
|
|
this.opts = opts;
|
|
|
|
|
this.runtimePart = Soma.require()
|
|
|
|
|
.runtime(gridListMorfo, {})
|
|
|
|
|
.part('selection-checkbox', { id: opts.id, ref: opts.ref, owner: this });
|
|
|
|
|
this.provider = GridListProvider.require();
|
|
|
|
|
this.runtimePart = this.provider.runtime.part('selection-checkbox', {
|
|
|
|
|
id: opts.id,
|
|
|
|
|
ref: opts.ref,
|
|
|
|
|
owner: this
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Read the enclosing row's value lazily (on click). */
|
|
|
|
|
@ -579,7 +591,7 @@ export class GridListSelectionCheckboxProvider {
|
|
|
|
|
readonly resolvedAriaLabel = $derived.by(
|
|
|
|
|
() =>
|
|
|
|
|
this.opts.ariaLabel.current ||
|
|
|
|
|
this.provider.soma?.langs.ts(GRID_LIST_LANGS.SELECT_ROW) ||
|
|
|
|
|
this.provider.soma.langs.ts(GRID_LIST_LANGS.SELECT_ROW) ||
|
|
|
|
|
undefined
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|