@universal-material/data-grid 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -20
- package/custom-elements.json +35 -7
- package/dist/export/types.d.ts +1 -1
- package/dist/export/types.js.map +1 -1
- package/dist/features/column-chooser.js +3 -2
- package/dist/features/column-chooser.js.map +1 -1
- package/dist/features/filter-row.js +4 -3
- package/dist/features/filter-row.js.map +1 -1
- package/dist/features/header-filter.d.ts +5 -1
- package/dist/features/header-filter.js +15 -6
- package/dist/features/header-filter.js.map +1 -1
- package/dist/features/scroll-port.d.ts +51 -0
- package/dist/features/scroll-port.js +329 -0
- package/dist/features/scroll-port.js.map +1 -0
- package/dist/grid-column-def.d.ts +16 -4
- package/dist/grid-column-def.js.map +1 -1
- package/dist/grid-column.d.ts +8 -2
- package/dist/grid-column.js +8 -2
- package/dist/grid-column.js.map +1 -1
- package/dist/grid.d.ts +30 -4
- package/dist/grid.js +505 -112
- package/dist/grid.js.map +1 -1
- package/dist/grid.min.js +592 -484
- package/dist/grid.styles.js +111 -9
- package/dist/grid.styles.js.map +1 -1
- package/dist/render/group-row.js +2 -1
- package/dist/render/group-row.js.map +1 -1
- package/dist/render/header.d.ts +17 -1
- package/dist/render/header.js +23 -2
- package/dist/render/header.js.map +1 -1
- package/dist/render/virtualizer.d.ts +49 -1
- package/dist/render/virtualizer.js +229 -17
- package/dist/render/virtualizer.js.map +1 -1
- package/dist/row-model/columns.d.ts +22 -0
- package/dist/row-model/columns.js +15 -0
- package/dist/row-model/columns.js.map +1 -1
- package/package.json +7 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group-row.js","sourceRoot":"","sources":["../../src/render/group-row.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAuB,MAAM,KAAK,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE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;QAC7B,oEAAoE;QACpE,+DAA+D;QAC9D,KAAK,CAAC,aAA6B,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,aAAa,CAAc,gBAAgB,CAAC;YAC9F,EAAE,KAAK,EAAE,CAAC;QACZ,QAAQ,CAAC,GAAG,CAAC,CAAC;IAChB,CAAC;;;;;;;;;;;;;iBAaQ,QAAQ;;mBAEN,SAAS,CAAC,SAAS,CAAC;wBACf,SAAS,CAAC,gBAAgB,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,EAAE,UAAU,gBAAgB,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC;gBACjH,IAAI,CAAC,GAAG,CAAC,SAAS,IAAI,YAAY,GAAG,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;;aAE3D,SAAS,CAAC,gBAAgB,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;0CAC3C,GAAG,CAAC,KAAK,GAAG,CAAC,iEAAiE,OAAO,KAAK,SAAS;QACnI,CAAC,CAAC,IAAI,CAAA,GAAG,KAAK,GAAG,IAAI;YACnB,CAAC,CAAC,IAAI,CAAA,gDAAgD,IAAI,SAAS;YACnE,CAAC,CAAC,OAAO,EAAE;QACb,CAAC,CAAC,OAAO,UAAU,gBAAgB;QACnC,CAAC,CAAC,IAAI,CAAA,aAAa,gBAAgB,CAAC,EAAE,sBAAsB,gBAAgB,CAAC,IAAI,SAAS;QAC1F,CAAC,CAAC,OAAO;MACb,QAAQ;GACX,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { html, nothing, type TemplateResult } from 'lit';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\n\nimport { columnText } from '../row-model/columns.js';\nimport type { GroupRow } from '../row-model/types.js';\n\nexport interface GroupRowContext {\n row: GroupRow;\n /** Colunas do DOM: de grupo + comuns + espaçadoras da virtualização. */\n totalColumns: number;\n separator: string;\n /** Valor do grupo já formatado (`displayValue`/`format` da coluna). */\n valueText: string;\n /** Contagem e resumos `inline` já montados (`\"(3, Sum of Population: 1,234)\"`) ou vazio. */\n info?: string;\n /** Colunas cobertas pelo rótulo; padrão: até o fim da linha. */\n labelSpan?: number;\n /** Células depois do rótulo (resumos `display: 'column'`). */\n trailing?: TemplateResult | typeof nothing;\n /** Roving tabindex: `0` quando a linha é a ativa. */\n tabIndex: 0 | -1;\n /** Nome acessível da célula do rótulo quando há resumos em células à parte (a linha é um ponto só da navegação). */\n ariaLabel?: string;\n onToggle: (row: GroupRow) => void;\n /** Conteúdo do `groupRenderer` no lugar do rótulo e da contagem. */\n content?: unknown;\n /**\n * Com `content` e resumos alinhados: o texto deles (oculto) e o prefixo dos\n * ids — o nome da célula é o conteúdo seguido dos resumos (`aria-labelledby`).\n */\n alignedSummaries?: { text: string; id: string };\n}\n\nexport const groupRowLabel = (row: GroupRow, separator: string, valueText: string): string =>\n `${columnText(row.column)}${separator}${valueText}`;\n\n/** Células de uma linha de grupo: recuo, botão de expandir, o rótulo e os resumos alinhados. */\nexport const renderGroupRowCells = ({\n row,\n totalColumns,\n separator,\n valueText,\n info = '',\n tabIndex,\n ariaLabel,\n labelSpan,\n trailing = nothing,\n onToggle,\n content,\n alignedSummaries,\n}: GroupRowContext): TemplateResult => {\n const label = groupRowLabel(row, separator, valueText);\n\n return html`\n ${row.level\n ? html`<td class=\"group-column sticky-cell\" style=\"inset-inline-start: 0\" role=\"presentation\" colspan=${row.level}></td>`\n : nothing}\n <td\n class=\"group-column group-column-toggle sticky-cell ${classMap({ expanded: row.expanded })}\"\n style=\"inset-inline-start: calc(${row.level} * var(--_group-column-width))\"\n role=\"presentation\">\n <button\n class=\"group-toggle\"\n type=\"button\"\n tabindex=\"-1\"\n aria-hidden=\"true\"\n aria-expanded=${row.expanded ? 'true' : 'false'}\n @mousedown=${(event: MouseEvent) => event.preventDefault()}\n @click=${(event: MouseEvent) => {\n // O botão fica fora da navegação (aria-hidden): o foco vai à célula\n // do rótulo, que vira a ativa, em vez de parar nele (spec 17).\n (event.currentTarget as HTMLElement).closest('tr')?.querySelector<HTMLElement>('.grouping-cell')\n ?.focus();\n onToggle(row);\n }}>\n <span class=\"toggle-icon\">\n <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"1em\" viewBox=\"0 -960 960 960\" width=\"1em\" fill=\"currentColor\" aria-hidden=\"true\">\n <path d=\"M504-480 320-664l56-56 240 240-240 240-56-56 184-184Z\"/>\n </svg>\n </span>\n </button>\n </td>\n <td\n class=\"grouping-cell\"\n role=\"gridcell\"\n aria-colindex=\"1\"\n data-col=\"group\"\n tabindex=${tabIndex}\n aria-keyshortcuts=\"Control+G Meta+G\"\n aria-label=${ifDefined(ariaLabel)}\n aria-labelledby=${ifDefined(alignedSummaries ? `${alignedSummaries.id}-label ${alignedSummaries.id}-summaries` : undefined)}\n colspan=${Math.max(labelSpan ?? totalColumns - (row.level + 1), 1)}><span\n class=\"grouping-label\"\n id=${ifDefined(alignedSummaries ? `${alignedSummaries.id}-label` : undefined)}\n style=\"inset-inline-start: calc(${row.level + 1} * var(--_group-column-width) + var(--_cell-inline-padding))\">${content === undefined\n ? html`${label}${info\n ? html` <span class=\"group-info\" part=\"group-count\">${info}</span>`\n : nothing}`\n : content}</span>${alignedSummaries\n ? html`<span id=\"${alignedSummaries.id}-summaries\" hidden>${alignedSummaries.text}</span>`\n : nothing}</td>\n ${trailing}\n `;\n};\n"]}
|
package/dist/render/header.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ export interface HeaderCellContext {
|
|
|
35
35
|
keyShortcuts?: string;
|
|
36
36
|
/** Clique direito: menu do cabeçalho (spec 17, A1). */
|
|
37
37
|
onContextMenu?: (event: MouseEvent) => void;
|
|
38
|
-
/** Conteúdo do rótulo (`headerRenderer`); padrão: `column
|
|
38
|
+
/** Conteúdo do rótulo (`headerRenderer`); padrão: `headerText(column)`. */
|
|
39
39
|
label?: unknown;
|
|
40
40
|
/** Nível de baixo coberto pela célula (`data-level`, frente 13). */
|
|
41
41
|
level?: number;
|
|
@@ -88,5 +88,21 @@ export declare const renderSortIndicator: (order: GridSortOrder | undefined, sor
|
|
|
88
88
|
* sem `aria-sort`; o rótulo quebra linha (WCAG 1.4.12).
|
|
89
89
|
*/
|
|
90
90
|
export declare const renderBandHeaderCell: ({ column, classes, styles, colIndex, colSpan, level, tabIndex, idSuffix, columnId, description, keyShortcuts, onContextMenu, label, }: BandHeaderCellContext) => TemplateResult;
|
|
91
|
+
/** Nome de um controle do cabeçalho que segue o texto renderizado dele (ver `labelledByHeader`). */
|
|
92
|
+
export interface HeaderControlName {
|
|
93
|
+
/** Valor do `aria-labelledby` do controle. */
|
|
94
|
+
labelledBy: string;
|
|
95
|
+
/** Pedaços do modelo antes e depois de `{column}`, escondidos, dentro do controle. */
|
|
96
|
+
parts: TemplateResult;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Com `headerRenderer` o nome em texto da coluna (`columnText`) pode não
|
|
100
|
+
* ser o que se vê no cabeçalho: o botão ⋮, o funil e a alça tiram o nome do
|
|
101
|
+
* modelo traduzido ("Options for {column}") com `{column}` trocado pelo
|
|
102
|
+
* próprio `.header-text` renderizado (`aria-labelledby`), como o
|
|
103
|
+
* `columnheader` (WCAG 4.1.2, 2.4.6, 3.2.4). Os ids são da mesma célula e do
|
|
104
|
+
* mesmo render; funcionam sem JS no SSR.
|
|
105
|
+
*/
|
|
106
|
+
export declare const labelledByHeader: (template: string, idPrefix: string, idSuffix: string) => HeaderControlName;
|
|
91
107
|
export declare const renderHeaderCell: ({ column, classes, styles, colIndex, tabIndex, sortable, order, sortIndex, onActivate, onPointerDown, onKeyDown, trailing, filterButton, menuButton, filtered, description, keyShortcuts, onContextMenu, label, level, rowSpan, idSuffix, columnId, }: HeaderCellContext) => TemplateResult;
|
|
92
108
|
//# sourceMappingURL=header.d.ts.map
|
package/dist/render/header.js
CHANGED
|
@@ -2,6 +2,7 @@ import { html, nothing } from 'lit';
|
|
|
2
2
|
import { classMap } from 'lit/directives/class-map.js';
|
|
3
3
|
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
4
4
|
import { styleMap } from 'lit/directives/style-map.js';
|
|
5
|
+
import { headerText } from '../row-model/columns.js';
|
|
5
6
|
const ariaSort = (order) => order === 'asc' ? 'ascending' : order === 'desc' ? 'descending' : 'none';
|
|
6
7
|
const INTERACTIVE = 'a[href], button, input, select, textarea, [role="button"], [contenteditable=""], [contenteditable="true"]';
|
|
7
8
|
/**
|
|
@@ -50,7 +51,7 @@ const renderDescription = (idSuffix, description) => description ? html `<span i
|
|
|
50
51
|
* Banda: `colspan` nativo (a ARIA manda usar o da linguagem numa `<table>`),
|
|
51
52
|
* sem `aria-sort`; o rótulo quebra linha (WCAG 1.4.12).
|
|
52
53
|
*/
|
|
53
|
-
export const renderBandHeaderCell = ({ column, classes, styles, colIndex, colSpan, level, tabIndex, idSuffix, columnId, description = '', keyShortcuts, onContextMenu, label = column
|
|
54
|
+
export const renderBandHeaderCell = ({ column, classes, styles, colIndex, colSpan, level, tabIndex, idSuffix, columnId, description = '', keyShortcuts, onContextMenu, label = headerText(column), }) => html `
|
|
54
55
|
<th
|
|
55
56
|
class="band-header ${classMap(classes)}"
|
|
56
57
|
style=${styleMap(styles)}
|
|
@@ -68,7 +69,27 @@ export const renderBandHeaderCell = ({ column, classes, styles, colIndex, colSpa
|
|
|
68
69
|
@contextmenu=${onContextMenu ?? nothing}>
|
|
69
70
|
<span class="header-content"><span class="header-text" id="header-text-${idSuffix}">${label}</span></span>${renderDescription(idSuffix, description)}
|
|
70
71
|
</th>`;
|
|
71
|
-
|
|
72
|
+
/**
|
|
73
|
+
* Com `headerRenderer` o nome em texto da coluna (`columnText`) pode não
|
|
74
|
+
* ser o que se vê no cabeçalho: o botão ⋮, o funil e a alça tiram o nome do
|
|
75
|
+
* modelo traduzido ("Options for {column}") com `{column}` trocado pelo
|
|
76
|
+
* próprio `.header-text` renderizado (`aria-labelledby`), como o
|
|
77
|
+
* `columnheader` (WCAG 4.1.2, 2.4.6, 3.2.4). Os ids são da mesma célula e do
|
|
78
|
+
* mesmo render; funcionam sem JS no SSR.
|
|
79
|
+
*/
|
|
80
|
+
export const labelledByHeader = (template, idPrefix, idSuffix) => {
|
|
81
|
+
const at = template.indexOf('{column}');
|
|
82
|
+
const before = at >= 0 ? template.slice(0, at) : template;
|
|
83
|
+
const after = at >= 0 ? template.slice(at + '{column}'.length) : '';
|
|
84
|
+
// Parte vazia (o `{column}` no começo ou no fim do modelo) não vira span nem id.
|
|
85
|
+
const part = (side, text) => text ? html `<span class="visually-hidden" id="${idPrefix}-${side}-${idSuffix}">${text}</span>` : nothing;
|
|
86
|
+
return {
|
|
87
|
+
labelledBy: [before && `${idPrefix}-before-${idSuffix}`, `header-text-${idSuffix}`, after && `${idPrefix}-after-${idSuffix}`]
|
|
88
|
+
.filter(Boolean).join(' '),
|
|
89
|
+
parts: html `${part('before', before)}${part('after', after)}`,
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
export const renderHeaderCell = ({ column, classes, styles, colIndex, tabIndex, sortable, order, sortIndex, onActivate, onPointerDown, onKeyDown, trailing = nothing, filterButton = nothing, menuButton = nothing, filtered = false, description = '', keyShortcuts, onContextMenu, label = headerText(column), level, rowSpan, idSuffix = String(colIndex), columnId, }) => html `
|
|
72
93
|
<th
|
|
73
94
|
class="header-column ${classMap({ ...classes, sortable, sorted: !!order, filtered })}"
|
|
74
95
|
style=${styleMap(styles)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"header.js","sourceRoot":"","sources":["../../src/render/header.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAuB,MAAM,KAAK,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,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C;YACvB,UAAU,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IACD,CAAC,CAAC,OAAO;6EAC8D,QAAQ,KAAK,KAAK,UAAU,mBAAmB,CAAC,KAAK,EAAE,SAAS,CAAC,GACxI,YAAY,KAAK,OAAO,IAAI,UAAU,KAAK,OAAO;IAChD,CAAC,CAAC,OAAO;IACT,CAAC,CAAC,IAAI,CAAA,gCAAgC,YAAY,GAAG,UAAU,SAAS,UAAU,QAAQ,GAC5F,iBAAiB,CAAC,QAAQ,EAAE,WAAW,CAAC;QACtC,CAAC","sourcesContent":["import { html, nothing, type TemplateResult } from 'lit';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport { type StyleInfo, styleMap } from 'lit/directives/style-map.js';\n\nimport type { GridColumnDef, GridSortOrder } from '../grid-column-def.js';\n\nexport type SortActivation = (column: GridColumnDef, event: MouseEvent | KeyboardEvent) => void;\n\nexport interface HeaderCellContext {\n column: GridColumnDef;\n /** Classes de alinhamento/quebra/fixação da coluna (as mesmas das células). */\n classes: Record<string, boolean>;\n /** `min-width` e o deslocamento `sticky` das colunas fixas. */\n styles: StyleInfo;\n /** `aria-colindex` (1-based, conta a coluna de caixas). */\n colIndex: number;\n /** Roving tabindex: `0` só na célula ativa do grid. */\n tabIndex: 0 | -1;\n /** O usuário pode ordenar por esta coluna (modo ≠ `none` e coluna ordenável). */\n sortable: boolean;\n order: GridSortOrder | undefined;\n /** Posição na ordenação (1-based); só aparece com mais de uma coluna. */\n sortIndex: number | undefined;\n onActivate: SortActivation;\n onPointerDown: () => void;\n /** Teclas além da ativação (Alt+←/→ redimensiona). */\n onKeyDown?: (event: KeyboardEvent) => void;\n /** Conteúdo depois do rótulo (alça de redimensionar). */\n trailing?: TemplateResult | typeof nothing;\n /** Botão do filtro do cabeçalho (funil), depois da seta de ordenação. */\n filterButton?: TemplateResult | typeof nothing;\n /** Botão \"⋮\" do menu do cabeçalho, na ponta (depois do funil). */\n menuButton?: TemplateResult | typeof nothing;\n /** A coluna tem filtro (classe `filtered`). */\n filtered?: boolean;\n /** Descrição do cabeçalho (prioridade da ordenação, fixada, filtrada; spec 17, A14). */\n description?: string;\n /** `aria-keyshortcuts` com as teclas que valem nesta coluna (spec 17, A13). */\n keyShortcuts?: string;\n /** Clique direito: menu do cabeçalho (spec 17, A1). */\n onContextMenu?: (event: MouseEvent) => void;\n /** Conteúdo do rótulo (`headerRenderer`); padrão: `column.label`. */\n label?: unknown;\n /** Nível de baixo coberto pela célula (`data-level`, frente 13). */\n level?: number;\n /** Linhas cobertas (folha sem banda acima: até o último nível). */\n rowSpan?: number;\n /** Sufixo único dos ids (nível + coluna): banda e folha não repetem id. */\n idSuffix?: string;\n /** Identidade da coluna para o arrasto (`data-column-id`). */\n columnId?: number;\n}\n\n/** Banda do cabeçalho multinível (frente 13): sem ordenar, filtrar nem redimensionar. */\nexport interface BandHeaderCellContext {\n column: GridColumnDef;\n /** Classes de fixação e alinhamento. */\n classes: Record<string, boolean>;\n styles: StyleInfo;\n /** `aria-colindex` = primeira coluna renderizada sob a banda. */\n colIndex: number;\n colSpan: number;\n level: number;\n tabIndex: 0 | -1;\n idSuffix: string;\n columnId: number;\n description?: string;\n keyShortcuts?: string;\n onContextMenu?: (event: MouseEvent) => void;\n label?: unknown;\n}\n\nconst ariaSort = (order: GridSortOrder | undefined): 'ascending' | 'descending' | 'none' =>\n order === 'asc' ? 'ascending' : order === 'desc' ? 'descending' : 'none';\n\nconst INTERACTIVE = 'a[href], button, input, select, textarea, [role=\"button\"], [contenteditable=\"\"], [contenteditable=\"true\"]';\n\n/**\n * O evento veio de um elemento interativo do conteúdo da célula (botão do\n * `headerRenderer`, funil): não ordena. Para no próprio `<th>`.\n */\nexport const fromInteractiveContent = (event: Event): boolean => {\n for (const node of event.composedPath()) {\n if (node === event.currentTarget) {\n return false;\n }\n\n if (node instanceof Element && node.matches(INTERACTIVE)) {\n return true;\n }\n }\n\n return false;\n};\n\n/** Enter/Espaço ativam como o clique (com os mesmos modificadores). */\nexport const isActivationKey = (event: KeyboardEvent): boolean =>\n event.key === 'Enter' || event.key === ' ';\n\n/**\n * Layout do cabeçalho (como o AG Grid): início/centro `[texto][seta] …\n * [funil][⋮]`; fim (números) `[⋮][funil] … [seta][texto]` — o CSS inverte\n * pela direção lógica (RTL espelha sozinho). Os botões ficam sempre no\n * lugar (espaço reservado); o texto corta com reticências.\n */\n\n/**\n * Seta da ordenação. O número da prioridade vem por CSS (`data-sort-index`)\n * para não entrar no texto do cabeçalho nem ser lido duas vezes — o leitor de\n * tela recebe a ordenação por `aria-sort`.\n */\nexport const renderSortIndicator = (order: GridSortOrder | undefined, sortIndex?: number): TemplateResult | typeof nothing =>\n order\n ? html`\n <span\n class=\"sort-indicator ${order}\"\n part=\"sort-indicator\"\n aria-hidden=\"true\"\n data-sort-index=${sortIndex ?? nothing}>\n <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"1em\" viewBox=\"0 -960 960 960\" width=\"1em\" fill=\"currentColor\">\n <path d=\"M440-160v-487L216-423l-56-57 320-320 320 320-56 57-224-224v487h-80Z\"/>\n </svg>\n </span>`\n : nothing;\n\n/** Descrição oculta do cabeçalho (lida por \\`aria-describedby\\`; spec 17, A14). */\nconst renderDescription = (idSuffix: string, description: string): TemplateResult | typeof nothing =>\n description ? html`<span id=\"header-description-${idSuffix}\" hidden>${description}</span>` : nothing;\n\n/**\n * Banda: `colspan` nativo (a ARIA manda usar o da linguagem numa `<table>`),\n * sem `aria-sort`; o rótulo quebra linha (WCAG 1.4.12).\n */\nexport const renderBandHeaderCell = ({\n column,\n classes,\n styles,\n colIndex,\n colSpan,\n level,\n tabIndex,\n idSuffix,\n columnId,\n description = '',\n keyShortcuts,\n onContextMenu,\n label = column.label,\n}: BandHeaderCellContext): TemplateResult => html`\n <th\n class=\"band-header ${classMap(classes)}\"\n style=${styleMap(styles)}\n part=\"header-cell band-header-cell\"\n role=\"columnheader\"\n colspan=${colSpan}\n aria-colindex=\"${colIndex}\"\n aria-labelledby=\"header-text-${idSuffix}\"\n aria-describedby=${ifDefined(description ? `header-description-${idSuffix}` : undefined)}\n aria-keyshortcuts=${ifDefined(keyShortcuts || undefined)}\n data-col=${colIndex - 1}\n data-level=${level}\n data-column-id=${columnId}\n tabindex=${tabIndex}\n @contextmenu=${onContextMenu ?? nothing}>\n <span class=\"header-content\"><span class=\"header-text\" id=\"header-text-${idSuffix}\">${label}</span></span>${\n renderDescription(idSuffix, description)}\n </th>`;\n\nexport const renderHeaderCell = ({\n column,\n classes,\n styles,\n colIndex,\n tabIndex,\n sortable,\n order,\n sortIndex,\n onActivate,\n onPointerDown,\n onKeyDown,\n trailing = nothing,\n filterButton = nothing,\n menuButton = nothing,\n filtered = false,\n description = '',\n keyShortcuts,\n onContextMenu,\n label = column.label,\n level,\n rowSpan,\n idSuffix = String(colIndex),\n columnId,\n}: HeaderCellContext): TemplateResult => html`\n <th\n class=\"header-column ${classMap({ ...classes, sortable, sorted: !!order, filtered })}\"\n style=${styleMap(styles)}\n part=\"header-cell\"\n role=\"columnheader\"\n rowspan=${ifDefined(rowSpan && rowSpan > 1 ? rowSpan : undefined)}\n aria-colindex=\"${colIndex}\"\n aria-labelledby=\"header-text-${idSuffix}\"\n aria-sort=${ifDefined(sortable || order ? ariaSort(sortIndex === undefined || sortIndex === 1 ? order : undefined) : undefined)}\n aria-describedby=${ifDefined(description ? `header-description-${idSuffix}` : undefined)}\n aria-keyshortcuts=${ifDefined(keyShortcuts || undefined)}\n data-col=${colIndex - 1}\n data-level=${ifDefined(level)}\n data-column-id=${ifDefined(columnId)}\n tabindex=${tabIndex}\n @pointerdown=${sortable ? onPointerDown : nothing}\n @contextmenu=${onContextMenu ?? nothing}\n @click=${sortable ? (event: MouseEvent) => !fromInteractiveContent(event) && onActivate(column, event) : nothing}\n @keydown=${sortable || onKeyDown\n ? (event: KeyboardEvent) => {\n onKeyDown?.(event);\n\n if (sortable && !event.defaultPrevented && isActivationKey(event) && !event.repeat && !fromInteractiveContent(event)) {\n event.preventDefault();\n onActivate(column, event);\n }\n }\n : nothing}>\n <span class=\"header-content\"><span class=\"header-text\" id=\"header-text-${idSuffix}\">${label}</span>${renderSortIndicator(order, sortIndex)}${\n filterButton === nothing && menuButton === nothing\n ? nothing\n : html`<span class=\"header-buttons\">${filterButton}${menuButton}</span>`}</span>${trailing}${\n renderDescription(idSuffix, description)}\n </th>`;\n"]}
|
|
1
|
+
{"version":3,"file":"header.js","sourceRoot":"","sources":["../../src/render/header.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAuB,MAAM,KAAK,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAkB,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAGvE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAoErD,MAAM,QAAQ,GAAG,CAAC,KAAgC,EAAuC,EAAE,CACzF,KAAK,KAAK,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC;AAE3E,MAAM,WAAW,GAAG,2GAA2G,CAAC;AAEhI;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,KAAY,EAAW,EAAE;IAC9D,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,YAAY,EAAE,EAAE,CAAC;QACxC,IAAI,IAAI,KAAK,KAAK,CAAC,aAAa,EAAE,CAAC;YACjC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,IAAI,YAAY,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;YACzD,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,OAAO,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,EAAE,EAAE,CAAC,CAAC,sBAAsB,CAAC,KAAK,CAAC,IAAI,UAAU,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO;eACrG,QAAQ,IAAI,SAAS;IAC9B,CAAC,CAAC,CAAC,KAAoB,EAAE,EAAE;QACzB,SAAS,EAAE,CAAC,KAAK,CAAC,CAAC;QAEnB,IAAI,QAAQ,IAAI,CAAC,KAAK,CAAC,gBAAgB,IAAI,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,EAAE,CAAC;YACrH,KAAK,CAAC,cAAc,EAAE,CAAC;YACvB,UAAU,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IACD,CAAC,CAAC,OAAO;6EAC8D,QAAQ,KAAK,KAAK,UAAU,mBAAmB,CAAC,KAAK,EAAE,SAAS,CAAC,GACxI,YAAY,KAAK,OAAO,IAAI,UAAU,KAAK,OAAO;IAChD,CAAC,CAAC,OAAO;IACT,CAAC,CAAC,IAAI,CAAA,gCAAgC,YAAY,GAAG,UAAU,SAAS,UAAU,QAAQ,GAC5F,iBAAiB,CAAC,QAAQ,EAAE,WAAW,CAAC;QACtC,CAAC","sourcesContent":["import { html, nothing, type TemplateResult } from 'lit';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport { type StyleInfo, styleMap } from 'lit/directives/style-map.js';\n\nimport type { GridColumnDef, GridSortOrder } from '../grid-column-def.js';\nimport { headerText } from '../row-model/columns.js';\n\nexport type SortActivation = (column: GridColumnDef, event: MouseEvent | KeyboardEvent) => void;\n\nexport interface HeaderCellContext {\n column: GridColumnDef;\n /** Classes de alinhamento/quebra/fixação da coluna (as mesmas das células). */\n classes: Record<string, boolean>;\n /** `min-width` e o deslocamento `sticky` das colunas fixas. */\n styles: StyleInfo;\n /** `aria-colindex` (1-based, conta a coluna de caixas). */\n colIndex: number;\n /** Roving tabindex: `0` só na célula ativa do grid. */\n tabIndex: 0 | -1;\n /** O usuário pode ordenar por esta coluna (modo ≠ `none` e coluna ordenável). */\n sortable: boolean;\n order: GridSortOrder | undefined;\n /** Posição na ordenação (1-based); só aparece com mais de uma coluna. */\n sortIndex: number | undefined;\n onActivate: SortActivation;\n onPointerDown: () => void;\n /** Teclas além da ativação (Alt+←/→ redimensiona). */\n onKeyDown?: (event: KeyboardEvent) => void;\n /** Conteúdo depois do rótulo (alça de redimensionar). */\n trailing?: TemplateResult | typeof nothing;\n /** Botão do filtro do cabeçalho (funil), depois da seta de ordenação. */\n filterButton?: TemplateResult | typeof nothing;\n /** Botão \"⋮\" do menu do cabeçalho, na ponta (depois do funil). */\n menuButton?: TemplateResult | typeof nothing;\n /** A coluna tem filtro (classe `filtered`). */\n filtered?: boolean;\n /** Descrição do cabeçalho (prioridade da ordenação, fixada, filtrada; spec 17, A14). */\n description?: string;\n /** `aria-keyshortcuts` com as teclas que valem nesta coluna (spec 17, A13). */\n keyShortcuts?: string;\n /** Clique direito: menu do cabeçalho (spec 17, A1). */\n onContextMenu?: (event: MouseEvent) => void;\n /** Conteúdo do rótulo (`headerRenderer`); padrão: `headerText(column)`. */\n label?: unknown;\n /** Nível de baixo coberto pela célula (`data-level`, frente 13). */\n level?: number;\n /** Linhas cobertas (folha sem banda acima: até o último nível). */\n rowSpan?: number;\n /** Sufixo único dos ids (nível + coluna): banda e folha não repetem id. */\n idSuffix?: string;\n /** Identidade da coluna para o arrasto (`data-column-id`). */\n columnId?: number;\n}\n\n/** Banda do cabeçalho multinível (frente 13): sem ordenar, filtrar nem redimensionar. */\nexport interface BandHeaderCellContext {\n column: GridColumnDef;\n /** Classes de fixação e alinhamento. */\n classes: Record<string, boolean>;\n styles: StyleInfo;\n /** `aria-colindex` = primeira coluna renderizada sob a banda. */\n colIndex: number;\n colSpan: number;\n level: number;\n tabIndex: 0 | -1;\n idSuffix: string;\n columnId: number;\n description?: string;\n keyShortcuts?: string;\n onContextMenu?: (event: MouseEvent) => void;\n label?: unknown;\n}\n\nconst ariaSort = (order: GridSortOrder | undefined): 'ascending' | 'descending' | 'none' =>\n order === 'asc' ? 'ascending' : order === 'desc' ? 'descending' : 'none';\n\nconst INTERACTIVE = 'a[href], button, input, select, textarea, [role=\"button\"], [contenteditable=\"\"], [contenteditable=\"true\"]';\n\n/**\n * O evento veio de um elemento interativo do conteúdo da célula (botão do\n * `headerRenderer`, funil): não ordena. Para no próprio `<th>`.\n */\nexport const fromInteractiveContent = (event: Event): boolean => {\n for (const node of event.composedPath()) {\n if (node === event.currentTarget) {\n return false;\n }\n\n if (node instanceof Element && node.matches(INTERACTIVE)) {\n return true;\n }\n }\n\n return false;\n};\n\n/** Enter/Espaço ativam como o clique (com os mesmos modificadores). */\nexport const isActivationKey = (event: KeyboardEvent): boolean =>\n event.key === 'Enter' || event.key === ' ';\n\n/**\n * Layout do cabeçalho (como o AG Grid): início/centro `[texto][seta] …\n * [funil][⋮]`; fim (números) `[⋮][funil] … [seta][texto]` — o CSS inverte\n * pela direção lógica (RTL espelha sozinho). Os botões ficam sempre no\n * lugar (espaço reservado); o texto corta com reticências.\n */\n\n/**\n * Seta da ordenação. O número da prioridade vem por CSS (`data-sort-index`)\n * para não entrar no texto do cabeçalho nem ser lido duas vezes — o leitor de\n * tela recebe a ordenação por `aria-sort`.\n */\nexport const renderSortIndicator = (order: GridSortOrder | undefined, sortIndex?: number): TemplateResult | typeof nothing =>\n order\n ? html`\n <span\n class=\"sort-indicator ${order}\"\n part=\"sort-indicator\"\n aria-hidden=\"true\"\n data-sort-index=${sortIndex ?? nothing}>\n <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"1em\" viewBox=\"0 -960 960 960\" width=\"1em\" fill=\"currentColor\">\n <path d=\"M440-160v-487L216-423l-56-57 320-320 320 320-56 57-224-224v487h-80Z\"/>\n </svg>\n </span>`\n : nothing;\n\n/** Descrição oculta do cabeçalho (lida por \\`aria-describedby\\`; spec 17, A14). */\nconst renderDescription = (idSuffix: string, description: string): TemplateResult | typeof nothing =>\n description ? html`<span id=\"header-description-${idSuffix}\" hidden>${description}</span>` : nothing;\n\n/**\n * Banda: `colspan` nativo (a ARIA manda usar o da linguagem numa `<table>`),\n * sem `aria-sort`; o rótulo quebra linha (WCAG 1.4.12).\n */\nexport const renderBandHeaderCell = ({\n column,\n classes,\n styles,\n colIndex,\n colSpan,\n level,\n tabIndex,\n idSuffix,\n columnId,\n description = '',\n keyShortcuts,\n onContextMenu,\n label = headerText(column),\n}: BandHeaderCellContext): TemplateResult => html`\n <th\n class=\"band-header ${classMap(classes)}\"\n style=${styleMap(styles)}\n part=\"header-cell band-header-cell\"\n role=\"columnheader\"\n colspan=${colSpan}\n aria-colindex=\"${colIndex}\"\n aria-labelledby=\"header-text-${idSuffix}\"\n aria-describedby=${ifDefined(description ? `header-description-${idSuffix}` : undefined)}\n aria-keyshortcuts=${ifDefined(keyShortcuts || undefined)}\n data-col=${colIndex - 1}\n data-level=${level}\n data-column-id=${columnId}\n tabindex=${tabIndex}\n @contextmenu=${onContextMenu ?? nothing}>\n <span class=\"header-content\"><span class=\"header-text\" id=\"header-text-${idSuffix}\">${label}</span></span>${\n renderDescription(idSuffix, description)}\n </th>`;\n\n/** Nome de um controle do cabeçalho que segue o texto renderizado dele (ver `labelledByHeader`). */\nexport interface HeaderControlName {\n /** Valor do `aria-labelledby` do controle. */\n labelledBy: string;\n /** Pedaços do modelo antes e depois de `{column}`, escondidos, dentro do controle. */\n parts: TemplateResult;\n}\n\n/**\n * Com `headerRenderer` o nome em texto da coluna (`columnText`) pode não\n * ser o que se vê no cabeçalho: o botão ⋮, o funil e a alça tiram o nome do\n * modelo traduzido (\"Options for {column}\") com `{column}` trocado pelo\n * próprio `.header-text` renderizado (`aria-labelledby`), como o\n * `columnheader` (WCAG 4.1.2, 2.4.6, 3.2.4). Os ids são da mesma célula e do\n * mesmo render; funcionam sem JS no SSR.\n */\nexport const labelledByHeader = (template: string, idPrefix: string, idSuffix: string): HeaderControlName => {\n const at = template.indexOf('{column}');\n const before = at >= 0 ? template.slice(0, at) : template;\n const after = at >= 0 ? template.slice(at + '{column}'.length) : '';\n\n // Parte vazia (o `{column}` no começo ou no fim do modelo) não vira span nem id.\n const part = (side: string, text: string) =>\n text ? html`<span class=\"visually-hidden\" id=\"${idPrefix}-${side}-${idSuffix}\">${text}</span>` : nothing;\n\n return {\n labelledBy: [before && `${idPrefix}-before-${idSuffix}`, `header-text-${idSuffix}`, after && `${idPrefix}-after-${idSuffix}`]\n .filter(Boolean).join(' '),\n parts: html`${part('before', before)}${part('after', after)}`,\n };\n};\n\nexport const renderHeaderCell = ({\n column,\n classes,\n styles,\n colIndex,\n tabIndex,\n sortable,\n order,\n sortIndex,\n onActivate,\n onPointerDown,\n onKeyDown,\n trailing = nothing,\n filterButton = nothing,\n menuButton = nothing,\n filtered = false,\n description = '',\n keyShortcuts,\n onContextMenu,\n label = headerText(column),\n level,\n rowSpan,\n idSuffix = String(colIndex),\n columnId,\n}: HeaderCellContext): TemplateResult => html`\n <th\n class=\"header-column ${classMap({ ...classes, sortable, sorted: !!order, filtered })}\"\n style=${styleMap(styles)}\n part=\"header-cell\"\n role=\"columnheader\"\n rowspan=${ifDefined(rowSpan && rowSpan > 1 ? rowSpan : undefined)}\n aria-colindex=\"${colIndex}\"\n aria-labelledby=\"header-text-${idSuffix}\"\n aria-sort=${ifDefined(sortable || order ? ariaSort(sortIndex === undefined || sortIndex === 1 ? order : undefined) : undefined)}\n aria-describedby=${ifDefined(description ? `header-description-${idSuffix}` : undefined)}\n aria-keyshortcuts=${ifDefined(keyShortcuts || undefined)}\n data-col=${colIndex - 1}\n data-level=${ifDefined(level)}\n data-column-id=${ifDefined(columnId)}\n tabindex=${tabIndex}\n @pointerdown=${sortable ? onPointerDown : nothing}\n @contextmenu=${onContextMenu ?? nothing}\n @click=${sortable ? (event: MouseEvent) => !fromInteractiveContent(event) && onActivate(column, event) : nothing}\n @keydown=${sortable || onKeyDown\n ? (event: KeyboardEvent) => {\n onKeyDown?.(event);\n\n if (sortable && !event.defaultPrevented && isActivationKey(event) && !event.repeat && !fromInteractiveContent(event)) {\n event.preventDefault();\n onActivate(column, event);\n }\n }\n : nothing}>\n <span class=\"header-content\"><span class=\"header-text\" id=\"header-text-${idSuffix}\">${label}</span>${renderSortIndicator(order, sortIndex)}${\n filterButton === nothing && menuButton === nothing\n ? nothing\n : html`<span class=\"header-buttons\">${filterButton}${menuButton}</span>`}</span>${trailing}${\n renderDescription(idSuffix, description)}\n </th>`;\n"]}
|
|
@@ -15,8 +15,39 @@ export interface VirtualWindow {
|
|
|
15
15
|
/** Deslocamento (px, coordenadas FÍSICAS do corpo) da 1ª linha renderizada. */
|
|
16
16
|
offset: number;
|
|
17
17
|
}
|
|
18
|
+
/** Retângulo (coordenadas da tela) da parte visível de uma porta de rolagem. */
|
|
19
|
+
export interface PortRect {
|
|
20
|
+
top: number;
|
|
21
|
+
left: number;
|
|
22
|
+
right: number;
|
|
23
|
+
bottom: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Porta de rolagem: um elemento rolável ou a janela, com a mesma interface
|
|
27
|
+
* (spec 27). Na janela, o tamanho visível é o do `documentElement` (sem as
|
|
28
|
+
* barras de rolagem) e a rolagem é a do `scrollingElement`.
|
|
29
|
+
*/
|
|
30
|
+
export declare class ScrollPort {
|
|
31
|
+
readonly source: HTMLElement | Window;
|
|
32
|
+
constructor(source: HTMLElement | Window);
|
|
33
|
+
get isWindow(): boolean;
|
|
34
|
+
/** Onde ouvir o `scroll`/`scrollend`. */
|
|
35
|
+
get target(): EventTarget;
|
|
36
|
+
/** Elemento que rola (na janela, o `scrollingElement`). */
|
|
37
|
+
get element(): HTMLElement;
|
|
38
|
+
get scrollTop(): number;
|
|
39
|
+
set scrollTop(value: number);
|
|
40
|
+
get clientHeight(): number;
|
|
41
|
+
/** Parte visível (por dentro das bordas, sem as barras), em coordenadas da tela. */
|
|
42
|
+
rect(): PortRect;
|
|
43
|
+
}
|
|
18
44
|
export interface RowVirtualizerOptions {
|
|
19
|
-
getScrollElement: () => HTMLElement | null;
|
|
45
|
+
getScrollElement: () => HTMLElement | Window | null;
|
|
46
|
+
/**
|
|
47
|
+
* Porta externa (spec 27): o que vem depois do corpo também rola e o corpo
|
|
48
|
+
* pode estar abaixo da dobra. Só muda o mapeamento físico → virtual na escala.
|
|
49
|
+
*/
|
|
50
|
+
isExternal?: () => boolean;
|
|
20
51
|
/** Altura estimada (e, sem `wrap`, exata) de cada linha. */
|
|
21
52
|
rowHeight: () => number;
|
|
22
53
|
/** Linhas a mais acima e abaixo da janela. */
|
|
@@ -58,6 +89,13 @@ export declare class RowVirtualizer implements ReactiveController {
|
|
|
58
89
|
hostConnected(): void;
|
|
59
90
|
hostUpdated(): void;
|
|
60
91
|
hostDisconnected(): void;
|
|
92
|
+
/** Porta atual (spec 27); `undefined` antes do 1º render ou desconectado. */
|
|
93
|
+
get port(): ScrollPort | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* Relê a margem, o tamanho e a posição sem evento de rolagem (spec 27: o
|
|
96
|
+
* conteúdo acima do grid mudou de altura dentro da porta externa).
|
|
97
|
+
*/
|
|
98
|
+
sync(): void;
|
|
61
99
|
/** Número de linhas. */
|
|
62
100
|
get count(): number;
|
|
63
101
|
set count(count: number);
|
|
@@ -92,6 +130,16 @@ export declare class RowVirtualizer implements ReactiveController {
|
|
|
92
130
|
indexAt(offset: number): number;
|
|
93
131
|
/** Escala ativa: a lista virtual é maior que o corpo físico. */
|
|
94
132
|
get scaled(): boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Porta externa (spec 27): onde a linha `index` fica no corpo FÍSICO para
|
|
135
|
+
* um `scrollIntoView` chegar nela. Fora da escala, o início virtual; na
|
|
136
|
+
* escala, escolhe o par destino (físico, virtual) — passo pequeno 1:1,
|
|
137
|
+
* salto proporcional — e o guarda até a rolagem chegar. `stickyTop` e
|
|
138
|
+
* `stickyBottom`: o que cobre o corpo na porta no destino.
|
|
139
|
+
*/
|
|
140
|
+
revealOffset(index: number, stickyTop: number, stickyBottom: number): number;
|
|
141
|
+
/** A rolagem acabou (`scrollend`) longe do destino: esquece o destino guardado. */
|
|
142
|
+
endGlide(): void;
|
|
95
143
|
/**
|
|
96
144
|
* Janela de linhas a renderizar e o deslocamento físico da 1ª;
|
|
97
145
|
* `undefined` antes de conhecer a altura da janela.
|
|
@@ -6,6 +6,61 @@
|
|
|
6
6
|
export const MAX_SCROLL_HEIGHT = 15_000_000;
|
|
7
7
|
/** Linhas renderizadas antes de conhecer a altura da janela (1º render, SSR). */
|
|
8
8
|
export const INITIAL_RENDER_ROWS = 30;
|
|
9
|
+
/**
|
|
10
|
+
* Porta de rolagem: um elemento rolável ou a janela, com a mesma interface
|
|
11
|
+
* (spec 27). Na janela, o tamanho visível é o do `documentElement` (sem as
|
|
12
|
+
* barras de rolagem) e a rolagem é a do `scrollingElement`.
|
|
13
|
+
*/
|
|
14
|
+
export class ScrollPort {
|
|
15
|
+
constructor(source) {
|
|
16
|
+
this.source = source;
|
|
17
|
+
}
|
|
18
|
+
get isWindow() {
|
|
19
|
+
return !(this.source instanceof HTMLElement);
|
|
20
|
+
}
|
|
21
|
+
/** Onde ouvir o `scroll`/`scrollend`. */
|
|
22
|
+
get target() {
|
|
23
|
+
return this.source;
|
|
24
|
+
}
|
|
25
|
+
/** Elemento que rola (na janela, o `scrollingElement`). */
|
|
26
|
+
get element() {
|
|
27
|
+
const source = this.source;
|
|
28
|
+
return source instanceof HTMLElement
|
|
29
|
+
? source
|
|
30
|
+
: source.document.scrollingElement ?? source.document.documentElement;
|
|
31
|
+
}
|
|
32
|
+
get scrollTop() {
|
|
33
|
+
const source = this.source;
|
|
34
|
+
return source instanceof HTMLElement ? source.scrollTop : source.scrollY;
|
|
35
|
+
}
|
|
36
|
+
set scrollTop(value) {
|
|
37
|
+
const source = this.source;
|
|
38
|
+
if (source instanceof HTMLElement) {
|
|
39
|
+
source.scrollTop = value;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
source.scrollTo({ top: value, behavior: 'instant' });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
get clientHeight() {
|
|
46
|
+
const source = this.source;
|
|
47
|
+
return source instanceof HTMLElement ? source.clientHeight : source.document.documentElement.clientHeight;
|
|
48
|
+
}
|
|
49
|
+
/** Parte visível (por dentro das bordas, sem as barras), em coordenadas da tela. */
|
|
50
|
+
rect() {
|
|
51
|
+
const source = this.source;
|
|
52
|
+
if (!(source instanceof HTMLElement)) {
|
|
53
|
+
const root = source.document.documentElement;
|
|
54
|
+
return { top: 0, left: 0, right: root.clientWidth, bottom: root.clientHeight };
|
|
55
|
+
}
|
|
56
|
+
const box = source.getBoundingClientRect();
|
|
57
|
+
const top = box.top + source.clientTop;
|
|
58
|
+
// Em RTL a barra vertical fica à esquerda: a área útil começa depois dela.
|
|
59
|
+
const bar = Math.max(0, source.offsetWidth - source.clientLeft * 2 - source.clientWidth);
|
|
60
|
+
const left = box.left + source.clientLeft + (bar && getComputedStyle(source).direction === 'rtl' ? bar : 0);
|
|
61
|
+
return { top, left, right: left + source.clientWidth, bottom: top + source.clientHeight };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
9
64
|
/**
|
|
10
65
|
* Virtualizador de linhas do grid (spec 16), no lugar do
|
|
11
66
|
* `@tanstack/lit-virtual`, cujo custo é O(linhas) a cada mudança (um objeto
|
|
@@ -40,6 +95,12 @@ export class RowVirtualizer {
|
|
|
40
95
|
#virtual = 0;
|
|
41
96
|
/** Posição virtual pedida por `scrollToIndex` para a próxima rolagem física. */
|
|
42
97
|
#pending;
|
|
98
|
+
/**
|
|
99
|
+
* Rolagem até um destino na escala com a porta externa (spec 27): a
|
|
100
|
+
* rolagem (suave ou não) vai de `from` até o destino, e as posições do
|
|
101
|
+
* caminho interpolam o virtual — o destino virtual dura até a chegada.
|
|
102
|
+
*/
|
|
103
|
+
#glide;
|
|
43
104
|
/** Alturas medidas (`wrap`): árvore de Fenwick (1-based) e altura por linha. */
|
|
44
105
|
#tree;
|
|
45
106
|
#sizes;
|
|
@@ -53,6 +114,9 @@ export class RowVirtualizer {
|
|
|
53
114
|
#variableTree;
|
|
54
115
|
#scroller;
|
|
55
116
|
#resizeObserver;
|
|
117
|
+
/** Porta = janela: o tamanho visível muda no `resize` (não há elemento a observar). */
|
|
118
|
+
#windowResize;
|
|
119
|
+
#windowFrame = 0;
|
|
56
120
|
/** Janela do último render (para só pedir render quando ela muda). */
|
|
57
121
|
#rendered;
|
|
58
122
|
constructor(host, options) {
|
|
@@ -68,32 +132,69 @@ export class RowVirtualizer {
|
|
|
68
132
|
this.#attach();
|
|
69
133
|
}
|
|
70
134
|
hostDisconnected() {
|
|
71
|
-
|
|
135
|
+
const scroller = this.#scroller;
|
|
136
|
+
scroller?.target.removeEventListener('scroll', this.#onScroll);
|
|
137
|
+
if (this.#windowResize) {
|
|
138
|
+
scroller?.target.removeEventListener('resize', this.#windowResize);
|
|
139
|
+
this.#windowResize = undefined;
|
|
140
|
+
}
|
|
141
|
+
cancelAnimationFrame(this.#windowFrame);
|
|
142
|
+
this.#windowFrame = 0;
|
|
72
143
|
this.#resizeObserver?.disconnect();
|
|
73
144
|
this.#resizeObserver = undefined;
|
|
74
145
|
this.#scroller = undefined;
|
|
146
|
+
this.#glide = undefined;
|
|
147
|
+
this.#pending = undefined;
|
|
148
|
+
}
|
|
149
|
+
/** Porta atual (spec 27); `undefined` antes do 1º render ou desconectado. */
|
|
150
|
+
get port() {
|
|
151
|
+
return this.#scroller;
|
|
75
152
|
}
|
|
76
153
|
#attach() {
|
|
77
|
-
const
|
|
78
|
-
if (!
|
|
154
|
+
const source = this.#options.getScrollElement() ?? undefined;
|
|
155
|
+
if (!source || source === this.#scroller?.source) {
|
|
79
156
|
return;
|
|
80
157
|
}
|
|
81
158
|
this.hostDisconnected();
|
|
159
|
+
const scroller = new ScrollPort(source);
|
|
82
160
|
this.#scroller = scroller;
|
|
83
|
-
scroller.addEventListener('scroll', this.#onScroll, { passive: true });
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
161
|
+
scroller.target.addEventListener('scroll', this.#onScroll, { passive: true });
|
|
162
|
+
const resized = () => {
|
|
163
|
+
const viewport = scroller.clientHeight;
|
|
164
|
+
const margin = this.#options.getScrollMargin?.() ?? 0;
|
|
165
|
+
if (viewport !== this.#viewport || margin !== this.#margin) {
|
|
166
|
+
this.#viewport = viewport;
|
|
167
|
+
this.#margin = margin;
|
|
168
|
+
this.#syncFromScroll(scroller.scrollTop);
|
|
169
|
+
this.#host.requestUpdate();
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
if (scroller.isWindow) {
|
|
173
|
+
this.#windowResize = resized;
|
|
174
|
+
scroller.target.addEventListener('resize', resized, { passive: true });
|
|
175
|
+
// Como o 1º aviso do `ResizeObserver`: depois do 1º render (a hidratação
|
|
176
|
+
// do SSR precisa desenhar as mesmas linhas iniciais que o servidor).
|
|
177
|
+
this.#windowFrame = requestAnimationFrame(() => {
|
|
178
|
+
this.#windowFrame = 0;
|
|
179
|
+
resized();
|
|
94
180
|
});
|
|
95
|
-
this.#resizeObserver.observe(scroller);
|
|
96
181
|
}
|
|
182
|
+
else if (typeof ResizeObserver !== 'undefined') {
|
|
183
|
+
this.#resizeObserver = new ResizeObserver(resized);
|
|
184
|
+
this.#resizeObserver.observe(scroller.element);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Relê a margem, o tamanho e a posição sem evento de rolagem (spec 27: o
|
|
189
|
+
* conteúdo acima do grid mudou de altura dentro da porta externa).
|
|
190
|
+
*/
|
|
191
|
+
sync() {
|
|
192
|
+
const scroller = this.#scroller;
|
|
193
|
+
if (!scroller) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
this.#viewport = scroller.clientHeight || this.#viewport;
|
|
197
|
+
this.#onScroll();
|
|
97
198
|
}
|
|
98
199
|
// ------------------------------------------------------------- tamanhos
|
|
99
200
|
/** Número de linhas. */
|
|
@@ -387,6 +488,45 @@ export class RowVirtualizer {
|
|
|
387
488
|
this.#host.requestUpdate();
|
|
388
489
|
}
|
|
389
490
|
};
|
|
491
|
+
/**
|
|
492
|
+
* Porta externa (spec 27): onde a linha `index` fica no corpo FÍSICO para
|
|
493
|
+
* um `scrollIntoView` chegar nela. Fora da escala, o início virtual; na
|
|
494
|
+
* escala, escolhe o par destino (físico, virtual) — passo pequeno 1:1,
|
|
495
|
+
* salto proporcional — e o guarda até a rolagem chegar. `stickyTop` e
|
|
496
|
+
* `stickyBottom`: o que cobre o corpo na porta no destino.
|
|
497
|
+
*/
|
|
498
|
+
revealOffset(index, stickyTop, stickyBottom) {
|
|
499
|
+
const scroller = this.#scroller;
|
|
500
|
+
const row = Math.min(Math.max(this.#count - 1, 0), Math.max(0, index));
|
|
501
|
+
if (!scroller || !this.scaled) {
|
|
502
|
+
return this.startOf(row);
|
|
503
|
+
}
|
|
504
|
+
this.#margin = this.#options.getScrollMargin?.() ?? this.#margin;
|
|
505
|
+
const viewport = this.#viewport || scroller.clientHeight;
|
|
506
|
+
const start = this.startOf(row) + this.#margin - stickyTop;
|
|
507
|
+
const end = this.startOf(row) + this.sizeOf(row) + this.#margin + stickyBottom;
|
|
508
|
+
const current = this.#virtual;
|
|
509
|
+
let target = current;
|
|
510
|
+
if (start < current) {
|
|
511
|
+
target = start;
|
|
512
|
+
}
|
|
513
|
+
else if (end > current + viewport) {
|
|
514
|
+
target = end - viewport;
|
|
515
|
+
}
|
|
516
|
+
target = Math.max(0, target);
|
|
517
|
+
const physical = Math.abs(target - current) <= viewport
|
|
518
|
+
? this.#physical + target - current
|
|
519
|
+
: this.#externalPhysicalOf(target);
|
|
520
|
+
this.#glide = { fromPhysical: this.#physical, fromVirtual: current, physical, virtual: target };
|
|
521
|
+
// No destino, a linha fica onde o deslocamento do destino a põe.
|
|
522
|
+
return this.startOf(row) - (target - physical);
|
|
523
|
+
}
|
|
524
|
+
/** A rolagem acabou (`scrollend`) longe do destino: esquece o destino guardado. */
|
|
525
|
+
endGlide() {
|
|
526
|
+
if (this.#glide && Math.abs(this.#physical - this.#glide.physical) >= 1) {
|
|
527
|
+
this.#glide = undefined;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
390
530
|
/** Maior `scrollTop` físico (o que vem antes do corpo também rola). */
|
|
391
531
|
#maxPhysical() {
|
|
392
532
|
return Math.max(0, this.getTotalSize() + this.#margin - this.#viewport);
|
|
@@ -394,10 +534,70 @@ export class RowVirtualizer {
|
|
|
394
534
|
#maxVirtual() {
|
|
395
535
|
return Math.max(0, this.virtualSize + this.#margin - this.#viewport);
|
|
396
536
|
}
|
|
537
|
+
#external() {
|
|
538
|
+
return this.#options.isExternal?.() ?? false;
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Porta externa (spec 27), salto na escala: perto das pontas do corpo (uma
|
|
542
|
+
* janela de cada lado) e fora dele, 1:1 com a ponta — o conteúdo do
|
|
543
|
+
* hospedeiro antes e depois não escala, e voltar do rodapé da página cai
|
|
544
|
+
* nas últimas linhas; no meio, proporcional. Contínuo nas emendas.
|
|
545
|
+
*/
|
|
546
|
+
#externalZones() {
|
|
547
|
+
const zone = Math.max(this.#viewport, this.#height());
|
|
548
|
+
const maxPhysical = this.#maxPhysical();
|
|
549
|
+
const maxVirtual = this.#maxVirtual();
|
|
550
|
+
return {
|
|
551
|
+
p0: this.#margin + zone,
|
|
552
|
+
p1: maxPhysical - zone,
|
|
553
|
+
v0: this.#margin + zone,
|
|
554
|
+
v1: maxVirtual - zone,
|
|
555
|
+
maxPhysical,
|
|
556
|
+
maxVirtual,
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
#externalVirtualOf(physical) {
|
|
560
|
+
const { p0, p1, v0, v1, maxPhysical, maxVirtual } = this.#externalZones();
|
|
561
|
+
if (physical <= p0) {
|
|
562
|
+
return physical;
|
|
563
|
+
}
|
|
564
|
+
if (physical >= p1) {
|
|
565
|
+
return maxVirtual + physical - maxPhysical;
|
|
566
|
+
}
|
|
567
|
+
return v0 + (physical - p0) * (v1 - v0) / Math.max(1, p1 - p0);
|
|
568
|
+
}
|
|
569
|
+
#externalPhysicalOf(virtual) {
|
|
570
|
+
const { p0, p1, v0, v1, maxPhysical, maxVirtual } = this.#externalZones();
|
|
571
|
+
if (virtual <= v0) {
|
|
572
|
+
return virtual;
|
|
573
|
+
}
|
|
574
|
+
if (virtual >= v1) {
|
|
575
|
+
return maxPhysical + virtual - maxVirtual;
|
|
576
|
+
}
|
|
577
|
+
return p0 + (virtual - v0) * (p1 - p0) / Math.max(1, v1 - v0);
|
|
578
|
+
}
|
|
397
579
|
/** Atualiza a posição virtual a partir da física (ver a classe). */
|
|
398
580
|
#syncFromScroll(physical) {
|
|
399
581
|
const previous = this.#physical;
|
|
400
582
|
this.#physical = physical;
|
|
583
|
+
const glide = this.#glide;
|
|
584
|
+
if (glide) {
|
|
585
|
+
const low = Math.min(glide.fromPhysical, glide.physical) - 1;
|
|
586
|
+
const high = Math.max(glide.fromPhysical, glide.physical) + 1;
|
|
587
|
+
if (physical >= low && physical <= high) {
|
|
588
|
+
const span = glide.physical - glide.fromPhysical;
|
|
589
|
+
const t = Math.abs(span) < 1 ? 1 : Math.min(1, Math.max(0, (physical - glide.fromPhysical) / span));
|
|
590
|
+
this.#virtual = t === 1
|
|
591
|
+
? glide.virtual + physical - glide.physical
|
|
592
|
+
: glide.fromVirtual + t * (glide.virtual - glide.fromVirtual);
|
|
593
|
+
if (Math.abs(physical - glide.physical) < 1) {
|
|
594
|
+
this.#glide = undefined;
|
|
595
|
+
}
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
// Saiu do caminho (o usuário rolou para outro lado): mapeamento normal.
|
|
599
|
+
this.#glide = undefined;
|
|
600
|
+
}
|
|
401
601
|
if (this.#pending && Math.abs(this.#pending.physical - physical) < 1) {
|
|
402
602
|
this.#virtual = this.#pending.virtual;
|
|
403
603
|
this.#pending = undefined;
|
|
@@ -411,7 +611,14 @@ export class RowVirtualizer {
|
|
|
411
611
|
const maxPhysical = this.#maxPhysical();
|
|
412
612
|
const maxVirtual = this.#maxVirtual();
|
|
413
613
|
const delta = physical - previous;
|
|
414
|
-
if (
|
|
614
|
+
if (this.#external()) {
|
|
615
|
+
// Antes do corpo e depois do fim: 1:1 com a ponta; passo pequeno: 1:1; salto: zonas (acima).
|
|
616
|
+
const small = Math.abs(delta) <= Math.max(this.#viewport, this.#height());
|
|
617
|
+
this.#virtual = physical > this.#margin && physical < maxPhysical - 1 && small
|
|
618
|
+
? Math.min(maxVirtual, Math.max(0, this.#virtual + delta))
|
|
619
|
+
: this.#externalVirtualOf(physical);
|
|
620
|
+
}
|
|
621
|
+
else if (physical <= 0) {
|
|
415
622
|
this.#virtual = 0;
|
|
416
623
|
}
|
|
417
624
|
else if (physical >= maxPhysical - 1) {
|
|
@@ -427,7 +634,12 @@ export class RowVirtualizer {
|
|
|
427
634
|
/** Mantém as posições válidas depois de mudar o tamanho da lista. */
|
|
428
635
|
#clamp() {
|
|
429
636
|
if (!this.scaled) {
|
|
430
|
-
|
|
637
|
+
// Porta externa: depois do corpo há conteúdo do hospedeiro; a posição é a física.
|
|
638
|
+
this.#virtual = this.#external() ? this.#physical : Math.min(this.#physical, this.#maxPhysical());
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
if (this.#external() && (this.#physical <= this.#margin || this.#physical >= this.#maxPhysical() - 1)) {
|
|
642
|
+
this.#virtual = this.#externalVirtualOf(this.#physical);
|
|
431
643
|
return;
|
|
432
644
|
}
|
|
433
645
|
this.#virtual = Math.min(Math.max(0, this.#virtual), this.#maxVirtual());
|