Drive virtualized item attrs from Soma runtime

active-uix
dev 5 months ago
parent 06d8926356
commit 8b195e38e2

@ -1,4 +1,5 @@
import type { Morfo } from '../types'; import type { Morfo } from '../types';
import { v } from '../types';
export const virtualGridMorfo = { export const virtualGridMorfo = {
name: 'VirtualGrid', name: 'VirtualGrid',
@ -15,8 +16,8 @@ export const virtualGridMorfo = {
defaultElement: 'div', defaultElement: 'div',
optional: false, optional: false,
data: [ data: [
{ attr: 'data-row-index' }, { attr: 'data-row-index', value: v.propRef('rowIndex'), emit: 'value' },
{ attr: 'data-column-index' } { attr: 'data-column-index', value: v.propRef('columnIndex'), emit: 'value' }
], ],
aria: [] aria: []
} }

@ -1,4 +1,5 @@
import type { Morfo } from '../types'; import type { Morfo } from '../types';
import { v } from '../types';
export const virtualListMorfo = { export const virtualListMorfo = {
name: 'VirtualList', name: 'VirtualList',
@ -12,7 +13,13 @@ export const virtualListMorfo = {
kind: 'public', kind: 'public',
defaultElement: 'div', defaultElement: 'div',
optional: false, optional: false,
data: [{ attr: 'data-orientation', values: ['horizontal', 'vertical'] }], data: [
{
attr: 'data-orientation',
values: ['horizontal', 'vertical'],
value: v.propRef('orientation')
}
],
aria: [] aria: []
}, },
{ {
@ -22,7 +29,13 @@ export const virtualListMorfo = {
kind: 'public', kind: 'public',
defaultElement: 'div', defaultElement: 'div',
optional: true, optional: true,
data: [{ attr: 'data-orientation', values: ['horizontal', 'vertical'] }], data: [
{
attr: 'data-orientation',
values: ['horizontal', 'vertical'],
value: v.propRef('orientation')
}
],
aria: [] aria: []
}, },
{ {
@ -32,7 +45,13 @@ export const virtualListMorfo = {
kind: 'public', kind: 'public',
defaultElement: 'div', defaultElement: 'div',
optional: true, optional: true,
data: [{ attr: 'data-orientation', values: ['horizontal', 'vertical'] }], data: [
{
attr: 'data-orientation',
values: ['horizontal', 'vertical'],
value: v.propRef('orientation')
}
],
aria: [] aria: []
}, },
{ {
@ -43,8 +62,12 @@ export const virtualListMorfo = {
defaultElement: 'div', defaultElement: 'div',
optional: false, optional: false,
data: [ data: [
{ attr: 'data-index' }, { attr: 'data-index', value: v.propRef('index'), emit: 'value' },
{ attr: 'data-orientation', values: ['horizontal', 'vertical'] } {
attr: 'data-orientation',
values: ['horizontal', 'vertical'],
value: v.propRef('orientation')
}
], ],
aria: [] aria: []
} }

@ -294,7 +294,12 @@ export class VirtualGridCellProvider {
this.runtimePart = this.provider.runtime.part('cell', { this.runtimePart = this.provider.runtime.part('cell', {
id: opts.id, id: opts.id,
ref: opts.ref, ref: opts.ref,
owner: this owner: this,
props: {
rowIndex: () => this.opts.rowIndex.current,
columnIndex: () => this.opts.columnIndex.current
},
syncAttrs: true
}); });
} }
@ -305,8 +310,6 @@ export class VirtualGridCellProvider {
const columnSize = this.opts.columnSize.current; const columnSize = this.opts.columnSize.current;
return this.runtimePart.assert({ return this.runtimePart.assert({
...this.runtimePart.props, ...this.runtimePart.props,
'data-row-index': this.opts.rowIndex.current,
'data-column-index': this.opts.columnIndex.current,
style: { style: {
position: 'absolute', position: 'absolute',
top: '0', top: '0',

@ -67,12 +67,17 @@ export class VirtualListProvider {
private constructor(opts: VirtualListOpts) { private constructor(opts: VirtualListOpts) {
this.opts = opts; this.opts = opts;
this.soma = Soma.require(); this.soma = Soma.require();
this.runtime = this.soma.runtime(virtualListMorfo, {}); this.runtime = this.soma.runtime(virtualListMorfo, {
props: {
orientation: () => this.opts.orientation.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: VirtualListProvider.ctx context: VirtualListProvider.ctx,
syncAttrs: true
}); });
} }
@ -293,8 +298,7 @@ export class VirtualListProvider {
readonly props = $derived.by(() => readonly props = $derived.by(() =>
this.runtimePart.assert({ this.runtimePart.assert({
...this.runtimePart.props, ...this.runtimePart.props
'data-orientation': this.opts.orientation.current
} as const) } as const)
); );
} }
@ -321,7 +325,8 @@ export class VirtualListViewportProvider {
owner: this, owner: this,
onRefChange: (el) => { onRefChange: (el) => {
this.provider.viewportRef = el; this.provider.viewportRef = el;
} },
syncAttrs: true
}); });
$effect(() => { $effect(() => {
@ -355,7 +360,6 @@ export class VirtualListViewportProvider {
readonly props = $derived.by(() => readonly props = $derived.by(() =>
this.runtimePart.assert({ this.runtimePart.assert({
...this.runtimePart.props, ...this.runtimePart.props,
'data-orientation': this.provider.opts.orientation.current,
style: { style: {
position: 'relative', position: 'relative',
overflow: this.provider.isHorizontal ? 'auto hidden' : 'hidden auto' overflow: this.provider.isHorizontal ? 'auto hidden' : 'hidden auto'
@ -395,7 +399,8 @@ export class VirtualListWindowViewportProvider {
owner: this, owner: this,
onRefChange: (el) => { onRefChange: (el) => {
this.provider.windowHostRef = el; this.provider.windowHostRef = el;
} },
syncAttrs: true
}); });
$effect(() => { $effect(() => {
@ -447,7 +452,6 @@ export class VirtualListWindowViewportProvider {
readonly props = $derived.by(() => readonly props = $derived.by(() =>
this.runtimePart.assert({ this.runtimePart.assert({
...this.runtimePart.props, ...this.runtimePart.props,
'data-orientation': this.provider.opts.orientation.current,
style: { style: {
position: 'relative' position: 'relative'
} }
@ -475,7 +479,12 @@ export class VirtualListItemProvider {
this.runtimePart = this.provider.runtime.part('item', { this.runtimePart = this.provider.runtime.part('item', {
id: opts.id, id: opts.id,
ref: opts.ref, ref: opts.ref,
owner: this owner: this,
props: {
index: () => this.opts.index.current,
orientation: () => this.provider.opts.orientation.current
},
syncAttrs: true
}); });
// ResizeObserver: report real rendered size back to the provider so // ResizeObserver: report real rendered size back to the provider so
@ -525,8 +534,6 @@ export class VirtualListItemProvider {
: { [crossAxis]: '100%' }; : { [crossAxis]: '100%' };
return this.runtimePart.assert({ return this.runtimePart.assert({
...this.runtimePart.props, ...this.runtimePart.props,
'data-index': this.opts.index.current,
'data-orientation': this.provider.opts.orientation.current,
style: { style: {
position: 'absolute', position: 'absolute',
top: '0', top: '0',

Loading…
Cancel
Save

Powered by TurnKey Linux.