@astronox/core 0.1.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/LICENSE +21 -0
- package/README.md +66 -0
- package/package.json +77 -0
- package/src/client/clipboard.ts +7 -0
- package/src/client/focus.ts +17 -0
- package/src/client/index.ts +3 -0
- package/src/client/scroll.ts +15 -0
- package/src/components/actions/ActionListItem/ActionListItem.astro +78 -0
- package/src/components/actions/ActionListItem/ActionListItem.css +43 -0
- package/src/components/actions/Button/Button.astro +100 -0
- package/src/components/actions/Button/Button.css +165 -0
- package/src/components/actions/CardAction/CardAction.astro +97 -0
- package/src/components/actions/CardAction/CardAction.css +188 -0
- package/src/components/actions/MediaTrigger/MediaTrigger.astro +55 -0
- package/src/components/actions/MediaTrigger/MediaTrigger.css +175 -0
- package/src/components/actions/ScrollToTop/ScrollToTop.astro +36 -0
- package/src/components/actions/ScrollToTop/ScrollToTop.css +19 -0
- package/src/components/actions/ScrollToTop/scrollToTopController.ts +32 -0
- package/src/components/content/CardBody/CardBody.astro +31 -0
- package/src/components/content/CardBody/CardBody.css +74 -0
- package/src/components/content/CardFooter/CardFooter.astro +58 -0
- package/src/components/content/CardFooter/CardFooter.css +102 -0
- package/src/components/content/CardHeader/CardHeader.astro +96 -0
- package/src/components/content/CardHeader/CardHeader.css +164 -0
- package/src/components/content/CardLink/CardLink.astro +138 -0
- package/src/components/content/CardLink/CardLink.css +362 -0
- package/src/components/content/CodeBlock/CodeBlock.astro +102 -0
- package/src/components/content/CodeBlock/CodeBlock.css +85 -0
- package/src/components/content/CodeBlock/codeBlockController.ts +60 -0
- package/src/components/content/CodeBlock/contracts.ts +8 -0
- package/src/components/content/InlineDefinition/InlineDefinition.astro +31 -0
- package/src/components/content/InlineDefinition/InlineDefinition.css +9 -0
- package/src/components/content/MarkdownContent/MarkdownContent.astro +32 -0
- package/src/components/content/MarkdownContent/MarkdownContent.css +358 -0
- package/src/components/content/MarkdownContent/MarkdownInline.astro +44 -0
- package/src/components/content/MarkdownContent/MarkdownNode.astro +280 -0
- package/src/components/content/MarkdownContent/MarkdownSymbol.astro +47 -0
- package/src/components/content/MarkdownContent/contracts.ts +181 -0
- package/src/components/data-display/BadgeList/BadgeList.astro +54 -0
- package/src/components/data-display/BadgeList/BadgeList.css +29 -0
- package/src/components/data-display/IconList/IconList.astro +64 -0
- package/src/components/data-display/IconList/IconList.css +55 -0
- package/src/components/data-display/MetricTile/MetricTile.astro +68 -0
- package/src/components/data-display/MetricTile/MetricTile.css +103 -0
- package/src/components/data-display/MetricTile/MetricTileContent.astro +70 -0
- package/src/components/data-display/MetricTile/metricTileController.ts +9 -0
- package/src/components/data-display/Tag/Tag.astro +67 -0
- package/src/components/data-display/Tag/Tag.css +134 -0
- package/src/components/data-display/Tag/TagAffix.astro +33 -0
- package/src/components/data-display/TextPair/TextPair.astro +63 -0
- package/src/components/data-display/TextPair/TextPair.css +99 -0
- package/src/components/feedback/Spinner/Spinner.astro +32 -0
- package/src/components/feedback/Spinner/Spinner.css +37 -0
- package/src/components/feedback/Tooltip/Tooltip.astro +66 -0
- package/src/components/feedback/Tooltip/Tooltip.css +67 -0
- package/src/components/feedback/Tooltip/tooltipController.ts +371 -0
- package/src/components/forms/FieldError/FieldError.astro +31 -0
- package/src/components/forms/FieldError/FieldError.css +12 -0
- package/src/components/forms/FieldError/fieldErrorState.ts +21 -0
- package/src/components/forms/FieldLabel/FieldLabel.astro +32 -0
- package/src/components/forms/FieldLabel/FieldLabel.css +17 -0
- package/src/components/forms/TextInput/TextInput.astro +79 -0
- package/src/components/forms/TextInput/TextInput.css +121 -0
- package/src/components/forms/TextInput/textInputController.ts +53 -0
- package/src/components/icons/ArrowDownIcon.astro +26 -0
- package/src/components/icons/ArrowLeftIcon.astro +26 -0
- package/src/components/icons/ArrowRightIcon.astro +26 -0
- package/src/components/icons/ArrowUpDownIcon.astro +26 -0
- package/src/components/icons/ArrowUpIcon.astro +26 -0
- package/src/components/icons/BulletIcon.astro +21 -0
- package/src/components/icons/BurnIcon.astro +24 -0
- package/src/components/icons/CircleSymbolIcon.css +66 -0
- package/src/components/icons/ClearIcon.astro +28 -0
- package/src/components/icons/CloseIcon.astro +21 -0
- package/src/components/icons/CopyIcon.astro +30 -0
- package/src/components/icons/CurrencyIcon.css +9 -0
- package/src/components/icons/DayIcon.astro +33 -0
- package/src/components/icons/DollarIcon.astro +28 -0
- package/src/components/icons/DownloadIcon.astro +22 -0
- package/src/components/icons/EnterFullscreenIcon.astro +22 -0
- package/src/components/icons/EqualIcon.astro +25 -0
- package/src/components/icons/ExitFullscreenIcon.astro +22 -0
- package/src/components/icons/ExternalLinkIcon.astro +22 -0
- package/src/components/icons/FieldIcon.astro +28 -0
- package/src/components/icons/GrassIcon.astro +29 -0
- package/src/components/icons/InfoIcon.astro +24 -0
- package/src/components/icons/MinusIcon.astro +21 -0
- package/src/components/icons/MountainIcon.astro +31 -0
- package/src/components/icons/NightIcon.astro +32 -0
- package/src/components/icons/PlayIcon.astro +22 -0
- package/src/components/icons/PlusIcon.astro +21 -0
- package/src/components/icons/PoisonIcon.astro +24 -0
- package/src/components/icons/RibbonIcon.astro +25 -0
- package/src/components/icons/SlashIcon.astro +22 -0
- package/src/components/icons/SlowIcon.astro +25 -0
- package/src/components/icons/StarIcon.astro +28 -0
- package/src/components/icons/StunIcon.astro +22 -0
- package/src/components/icons/TableSortIcon.astro +34 -0
- package/src/components/icons/WaterIcon.astro +30 -0
- package/src/components/index.ts +83 -0
- package/src/components/media/CanvasFrame/CanvasFrame.astro +130 -0
- package/src/components/media/CanvasFrame/CanvasFrame.css +59 -0
- package/src/components/media/CanvasFrame/canvasFrameController.ts +104 -0
- package/src/components/media/EmbedFrame/EmbedFrame.astro +147 -0
- package/src/components/media/EmbedFrame/EmbedFrame.css +51 -0
- package/src/components/media/EmbedFrame/embedFrameController.ts +66 -0
- package/src/components/media/MediaFrame/MediaFrame.astro +34 -0
- package/src/components/media/MediaFrame/MediaFrame.css +66 -0
- package/src/components/navigation/Breadcrumbs/Breadcrumbs.astro +55 -0
- package/src/components/navigation/Breadcrumbs/Breadcrumbs.css +89 -0
- package/src/components/navigation/DesktopNavigation.astro +92 -0
- package/src/components/navigation/DesktopNavigation.css +99 -0
- package/src/components/navigation/Header.astro +73 -0
- package/src/components/navigation/Header.css +20 -0
- package/src/components/navigation/MobileNavigation.astro +124 -0
- package/src/components/navigation/MobileNavigation.css +177 -0
- package/src/components/navigation/NavigationBrand.astro +63 -0
- package/src/components/navigation/NavigationBrand.css +52 -0
- package/src/components/navigation/NavigationControl.css +166 -0
- package/src/components/navigation/NavigationItemContent.astro +24 -0
- package/src/components/navigation/NavigationLink.astro +121 -0
- package/src/components/navigation/NavigationLinks.astro +27 -0
- package/src/components/navigation/NavigationMenuList.astro +37 -0
- package/src/components/navigation/NavigationMenuList.css +6 -0
- package/src/components/navigation/SkipLink/SkipLink.astro +18 -0
- package/src/components/navigation/SkipLink/SkipLink.css +26 -0
- package/src/components/navigation/SubNavigation/SubNavigation.astro +124 -0
- package/src/components/navigation/SubNavigation/SubNavigation.css +211 -0
- package/src/components/navigation/mobileNavigationController.ts +122 -0
- package/src/components/navigation/navigationState.ts +35 -0
- package/src/components/navigation/navigationTypes.ts +18 -0
- package/src/components/seo/SeoHead.astro +194 -0
- package/src/components/widgetTypes.ts +3 -0
- package/src/composition/Grid/Grid.astro +82 -0
- package/src/composition/Grid/Grid.css +314 -0
- package/src/composition/GridItem/GridItem.astro +50 -0
- package/src/composition/GridItem/GridItem.css +95 -0
- package/src/composition/Inline/Inline.astro +48 -0
- package/src/composition/Inline/Inline.css +65 -0
- package/src/composition/Stack/Stack.astro +37 -0
- package/src/composition/Stack/Stack.css +31 -0
- package/src/composition/SurfaceGroup/SurfaceGroup.astro +44 -0
- package/src/composition/SurfaceGroup/SurfaceGroup.css +76 -0
- package/src/composition/SurfaceGroup/stickySurfaceGroupController.ts +89 -0
- package/src/composition/index.ts +6 -0
- package/src/config/index.ts +2 -0
- package/src/config/pageMeta.ts +55 -0
- package/src/config/siteConfig.ts +90 -0
- package/src/data/collectionValidation.ts +61 -0
- package/src/data/index.ts +1 -0
- package/src/display/contracts.ts +284 -0
- package/src/display/index.ts +1 -0
- package/src/index.ts +6 -0
- package/src/layouts/BaseLayout.astro +74 -0
- package/src/layouts/PageSurface.astro +15 -0
- package/src/layouts/PageSurface.css +24 -0
- package/src/layouts/index.ts +2 -0
- package/src/patterns/CircuitPuzzle/CircuitPuzzle.astro +93 -0
- package/src/patterns/CircuitPuzzle/CircuitPuzzle.css +118 -0
- package/src/patterns/CircuitPuzzle/circuitPuzzleController.ts +205 -0
- package/src/patterns/CircuitPuzzle/contracts.ts +42 -0
- package/src/patterns/Combobox/Combobox.astro +462 -0
- package/src/patterns/Combobox/Combobox.css +403 -0
- package/src/patterns/Combobox/comboboxController.ts +788 -0
- package/src/patterns/Combobox/contracts.ts +18 -0
- package/src/patterns/Dropdown/Dropdown.astro +127 -0
- package/src/patterns/Dropdown/Dropdown.css +100 -0
- package/src/patterns/Dropdown/dropdownController.ts +157 -0
- package/src/patterns/Fullscreen/FullscreenControl.astro +103 -0
- package/src/patterns/Fullscreen/FullscreenControl.css +49 -0
- package/src/patterns/Fullscreen/fullscreenController.ts +73 -0
- package/src/patterns/GlitchOverlay/GlitchOverlay.astro +50 -0
- package/src/patterns/GlitchOverlay/GlitchOverlay.css +234 -0
- package/src/patterns/GlitchOverlay/glitchOverlayController.ts +152 -0
- package/src/patterns/GuidedFlow/GuidedFlow.astro +60 -0
- package/src/patterns/GuidedFlow/GuidedFlow.css +82 -0
- package/src/patterns/GuidedFlow/contracts.ts +3 -0
- package/src/patterns/GuidedFlow/guidedFlowController.ts +49 -0
- package/src/patterns/MagneticFieldPuzzle/MagneticFieldPuzzle.astro +217 -0
- package/src/patterns/MagneticFieldPuzzle/MagneticFieldPuzzle.css +383 -0
- package/src/patterns/MagneticFieldPuzzle/contracts.ts +81 -0
- package/src/patterns/MagneticFieldPuzzle/magneticFieldPuzzleController.ts +802 -0
- package/src/patterns/MagneticFieldPuzzle/simulation.ts +244 -0
- package/src/patterns/MapViewport/MapViewport.astro +296 -0
- package/src/patterns/MapViewport/MapViewport.css +257 -0
- package/src/patterns/MapViewport/contracts.ts +79 -0
- package/src/patterns/MapViewport/geometry.ts +80 -0
- package/src/patterns/MapViewport/mapViewportController.ts +636 -0
- package/src/patterns/Modal/Modal.astro +64 -0
- package/src/patterns/Modal/Modal.css +87 -0
- package/src/patterns/Modal/ModalClose.astro +37 -0
- package/src/patterns/Modal/ModalOpen.astro +36 -0
- package/src/patterns/Modal/modalController.ts +118 -0
- package/src/patterns/PuzzleGrid/PuzzleGrid.astro +22 -0
- package/src/patterns/PuzzleGrid/PuzzleGrid.css +149 -0
- package/src/patterns/PuzzleGrid/contracts.ts +2 -0
- package/src/patterns/PuzzleGrid/selectionDismissal.ts +27 -0
- package/src/patterns/PuzzleGrid/state.ts +25 -0
- package/src/patterns/SpriteProjectilePreview/SpriteProjectilePreview.astro +65 -0
- package/src/patterns/SpriteProjectilePreview/SpriteProjectilePreview.css +35 -0
- package/src/patterns/SpriteProjectilePreview/contracts.ts +33 -0
- package/src/patterns/SpriteProjectilePreview/spriteProjectilePreviewController.ts +586 -0
- package/src/patterns/StageFlow/StageFlow.astro +57 -0
- package/src/patterns/StageFlow/StageFlow.css +54 -0
- package/src/patterns/StageFlow/StageFlowAlternative.astro +23 -0
- package/src/patterns/StageFlow/StageFlowArrow.astro +22 -0
- package/src/patterns/StageFlow/StageFlowConnector.astro +7 -0
- package/src/patterns/StageFlow/StageFlowConnector.css +4 -0
- package/src/patterns/StageFlow/StageFlowStage.astro +51 -0
- package/src/patterns/StageFlow/StageFlowStage.css +106 -0
- package/src/patterns/StageFlow/StageFlowStep.astro +24 -0
- package/src/patterns/StageFlow/StageFlowStep.css +19 -0
- package/src/patterns/StageFlow/StageFlowSymbol.css +28 -0
- package/src/patterns/Table/Table.astro +176 -0
- package/src/patterns/Table/Table.css +70 -0
- package/src/patterns/Table/TableBody.astro +185 -0
- package/src/patterns/Table/TableBody.css +262 -0
- package/src/patterns/Table/TableCell.astro +59 -0
- package/src/patterns/Table/TableCell.css +99 -0
- package/src/patterns/Table/TableCellValue.astro +86 -0
- package/src/patterns/Table/TableFooter.astro +32 -0
- package/src/patterns/Table/TableFooter.css +31 -0
- package/src/patterns/Table/TableHeader.astro +118 -0
- package/src/patterns/Table/TableHeader.css +209 -0
- package/src/patterns/Table/TablePagination.astro +70 -0
- package/src/patterns/Table/TablePagination.css +133 -0
- package/src/patterns/Table/TableSkeleton.astro +36 -0
- package/src/patterns/Table/TableSkeleton.css +81 -0
- package/src/patterns/Table/tableCellController.ts +11 -0
- package/src/patterns/Table/tableFilterController.ts +206 -0
- package/src/patterns/Table/tableHeaderOverflowController.ts +105 -0
- package/src/patterns/Table/tableLayout.ts +113 -0
- package/src/patterns/Table/tableProgressiveController.ts +319 -0
- package/src/patterns/Table/tableRowNavigationController.ts +91 -0
- package/src/patterns/Table/tableScrollController.ts +192 -0
- package/src/patterns/Table/tableSortController.ts +272 -0
- package/src/patterns/index.ts +46 -0
- package/src/primitives/index.ts +4 -0
- package/src/primitives/layout/Separator/Separator.astro +29 -0
- package/src/primitives/layout/Separator/Separator.css +20 -0
- package/src/primitives/media/AmbientAudio/AmbientAudio.astro +28 -0
- package/src/primitives/media/Media/Media.astro +122 -0
- package/src/primitives/media/Media/Media.css +161 -0
- package/src/primitives/text/TextBlock/TextBlock.astro +46 -0
- package/src/primitives/text/TextBlock/TextBlock.css +21 -0
- package/src/seo/StaticRedirect.astro +32 -0
- package/src/seo/index.ts +6 -0
- package/src/seo/pageSeo.ts +99 -0
- package/src/seo/robots.ts +16 -0
- package/src/seo/sitemap.ts +38 -0
- package/src/seo/structuredData.ts +133 -0
- package/src/seo/url.ts +64 -0
- package/src/styles/base.css +148 -0
- package/src/styles/interaction.css +108 -0
- package/src/styles/style.css +93 -0
- package/src/styles/tokens.css +256 -0
- package/src/theme/contracts.ts +7 -0
- package/src/theme/index.ts +1 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import {
|
|
2
|
+
clearCombobox,
|
|
3
|
+
getComboboxValues,
|
|
4
|
+
type ComboboxChangeDetail,
|
|
5
|
+
} from '../Combobox/comboboxController';
|
|
6
|
+
import { resetTableSort } from './tableSortController';
|
|
7
|
+
|
|
8
|
+
type FilterValues = Readonly<Record<string, readonly string[]>>;
|
|
9
|
+
|
|
10
|
+
type CachedFilterValues = {
|
|
11
|
+
values: FilterValues;
|
|
12
|
+
normalizedSearch: readonly string[];
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const initializedAttribute = 'data-table-filters-initialized';
|
|
16
|
+
const noop = (): void => undefined;
|
|
17
|
+
|
|
18
|
+
export function initTableFilters(root: HTMLElement): () => void {
|
|
19
|
+
if (root.getAttribute(initializedAttribute) === 'true') return noop;
|
|
20
|
+
|
|
21
|
+
const table = root.querySelector<HTMLElement>('[data-table-filter-table]');
|
|
22
|
+
const search = root.querySelector<HTMLInputElement>(
|
|
23
|
+
'[data-table-filter-search]',
|
|
24
|
+
);
|
|
25
|
+
const fields = Array.from(
|
|
26
|
+
root.querySelectorAll<HTMLElement>('[data-table-filter-field]'),
|
|
27
|
+
);
|
|
28
|
+
const reset = root.querySelector<HTMLButtonElement>(
|
|
29
|
+
'[data-table-filter-reset]',
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
if (!table || (!search && fields.length === 0)) return noop;
|
|
33
|
+
|
|
34
|
+
root.setAttribute(initializedAttribute, 'true');
|
|
35
|
+
const locale = document.documentElement.lang || undefined;
|
|
36
|
+
const normalize = (value: string): string =>
|
|
37
|
+
value
|
|
38
|
+
.normalize('NFD')
|
|
39
|
+
.replace(/\p{Diacritic}/gu, '')
|
|
40
|
+
.toLocaleLowerCase(locale);
|
|
41
|
+
const selections = new Map<string, string>();
|
|
42
|
+
const filterValuesCache = new WeakMap<HTMLElement, CachedFilterValues>();
|
|
43
|
+
const rows: HTMLElement[] = [];
|
|
44
|
+
let scheduledFrame: number | null = null;
|
|
45
|
+
|
|
46
|
+
const registerRows = (candidates: readonly HTMLElement[]): void => {
|
|
47
|
+
for (const row of candidates) {
|
|
48
|
+
if (filterValuesCache.has(row)) continue;
|
|
49
|
+
const values = parseFilterValues(row.dataset.tableFilterValues);
|
|
50
|
+
filterValuesCache.set(row, {
|
|
51
|
+
values,
|
|
52
|
+
normalizedSearch: (values.search ?? []).map(normalize),
|
|
53
|
+
});
|
|
54
|
+
rows.push(row);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const isLoadingAllRows = (): boolean => {
|
|
59
|
+
const pagination = table.querySelector<HTMLElement>(
|
|
60
|
+
'[data-table-pagination]',
|
|
61
|
+
);
|
|
62
|
+
const state = pagination?.dataset.tableProgressiveState;
|
|
63
|
+
return Boolean(
|
|
64
|
+
pagination &&
|
|
65
|
+
!pagination.hidden &&
|
|
66
|
+
state !== 'complete' &&
|
|
67
|
+
state !== 'error',
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const updateEmptyState = (visibleRows: number, active: boolean): void => {
|
|
72
|
+
const empty = table.querySelector<HTMLElement>('[data-table-filter-empty]');
|
|
73
|
+
if (!empty) return;
|
|
74
|
+
empty.hidden = !active || visibleRows > 0 || isLoadingAllRows();
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const applyFilters = (): void => {
|
|
78
|
+
const query = normalize(search?.value.trim() ?? '');
|
|
79
|
+
const activeSelections = [...selections.entries()].filter(
|
|
80
|
+
([, value]) => value.length > 0,
|
|
81
|
+
);
|
|
82
|
+
const active = query.length > 0 || activeSelections.length > 0;
|
|
83
|
+
let visibleRows = 0;
|
|
84
|
+
|
|
85
|
+
for (const row of rows) {
|
|
86
|
+
const cached = filterValuesCache.get(row);
|
|
87
|
+
if (!cached) continue;
|
|
88
|
+
const matchesSearch =
|
|
89
|
+
query.length === 0 ||
|
|
90
|
+
cached.normalizedSearch.some((value) => value.includes(query));
|
|
91
|
+
const matchesSelections = activeSelections.every(
|
|
92
|
+
([field, selectedValue]) =>
|
|
93
|
+
(cached.values[field] ?? []).includes(selectedValue),
|
|
94
|
+
);
|
|
95
|
+
const visible = matchesSearch && matchesSelections;
|
|
96
|
+
|
|
97
|
+
if (row.hidden !== !visible) row.hidden = !visible;
|
|
98
|
+
if (visible) visibleRows += 1;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
updateEmptyState(visibleRows, active);
|
|
102
|
+
if (active && isLoadingAllRows()) {
|
|
103
|
+
table.dispatchEvent(new CustomEvent('table:load-all', { bubbles: true }));
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const scheduleFilters = (): void => {
|
|
108
|
+
if (scheduledFrame !== null) return;
|
|
109
|
+
scheduledFrame = window.requestAnimationFrame(() => {
|
|
110
|
+
scheduledFrame = null;
|
|
111
|
+
applyFilters();
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const handleSearch = (): void => {
|
|
116
|
+
scheduleFilters();
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const handleComboboxChange = (event: Event): void => {
|
|
120
|
+
const customEvent = event as CustomEvent<ComboboxChangeDetail>;
|
|
121
|
+
const target = event.target;
|
|
122
|
+
if (
|
|
123
|
+
!(target instanceof HTMLElement) ||
|
|
124
|
+
customEvent.detail?.mode !== 'options'
|
|
125
|
+
) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const field = target.dataset.tableFilterField;
|
|
130
|
+
if (!field) return;
|
|
131
|
+
selections.set(field, customEvent.detail.values[0] ?? '');
|
|
132
|
+
scheduleFilters();
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const handleRowsAppended = (event: Event): void => {
|
|
136
|
+
const detail = (event as CustomEvent<{ rows?: readonly HTMLElement[] }>)
|
|
137
|
+
.detail;
|
|
138
|
+
registerRows(detail?.rows ?? []);
|
|
139
|
+
scheduleFilters();
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const handleProgressiveComplete = (): void => {
|
|
143
|
+
scheduleFilters();
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const handleReset = (): void => {
|
|
147
|
+
if (search) search.value = '';
|
|
148
|
+
for (const field of fields) {
|
|
149
|
+
clearCombobox(field, { emit: false });
|
|
150
|
+
}
|
|
151
|
+
selections.clear();
|
|
152
|
+
resetTableSort(table);
|
|
153
|
+
scheduleFilters();
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
for (const field of fields) {
|
|
157
|
+
const fieldName = field.dataset.tableFilterField;
|
|
158
|
+
const selectedValue = getComboboxValues(field)[0];
|
|
159
|
+
if (fieldName && selectedValue) selections.set(fieldName, selectedValue);
|
|
160
|
+
}
|
|
161
|
+
registerRows(
|
|
162
|
+
Array.from(
|
|
163
|
+
table.querySelectorAll<HTMLElement>(
|
|
164
|
+
'[data-table-row][data-table-filter-values]',
|
|
165
|
+
),
|
|
166
|
+
),
|
|
167
|
+
);
|
|
168
|
+
applyFilters();
|
|
169
|
+
search?.addEventListener('input', handleSearch);
|
|
170
|
+
root.addEventListener('combobox:change', handleComboboxChange);
|
|
171
|
+
table.addEventListener('table:rows-appended', handleRowsAppended);
|
|
172
|
+
table.addEventListener(
|
|
173
|
+
'table:progressive-complete',
|
|
174
|
+
handleProgressiveComplete,
|
|
175
|
+
);
|
|
176
|
+
reset?.addEventListener('click', handleReset);
|
|
177
|
+
|
|
178
|
+
return () => {
|
|
179
|
+
if (scheduledFrame !== null) {
|
|
180
|
+
window.cancelAnimationFrame(scheduledFrame);
|
|
181
|
+
scheduledFrame = null;
|
|
182
|
+
}
|
|
183
|
+
search?.removeEventListener('input', handleSearch);
|
|
184
|
+
root.removeEventListener('combobox:change', handleComboboxChange);
|
|
185
|
+
table.removeEventListener('table:rows-appended', handleRowsAppended);
|
|
186
|
+
table.removeEventListener(
|
|
187
|
+
'table:progressive-complete',
|
|
188
|
+
handleProgressiveComplete,
|
|
189
|
+
);
|
|
190
|
+
reset?.removeEventListener('click', handleReset);
|
|
191
|
+
for (const row of rows) row.hidden = false;
|
|
192
|
+
updateEmptyState(0, false);
|
|
193
|
+
root.removeAttribute(initializedAttribute);
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function parseFilterValues(value: string | undefined): FilterValues {
|
|
198
|
+
if (!value) return {};
|
|
199
|
+
|
|
200
|
+
try {
|
|
201
|
+
const parsed = JSON.parse(value);
|
|
202
|
+
return parsed && typeof parsed === 'object' ? (parsed as FilterValues) : {};
|
|
203
|
+
} catch {
|
|
204
|
+
return {};
|
|
205
|
+
}
|
|
206
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
const initializedAttribute = 'data-table-header-overflow-initialized';
|
|
2
|
+
const labelSelector = '[data-table-header-overflow-label]';
|
|
3
|
+
const textSelector = '[data-table-header-overflow-text-node]';
|
|
4
|
+
const overflowedAttribute = 'data-table-header-overflowed';
|
|
5
|
+
const overflowTolerance = 0.5;
|
|
6
|
+
const noop = (): void => undefined;
|
|
7
|
+
|
|
8
|
+
type HeaderLabel = {
|
|
9
|
+
root: HTMLElement;
|
|
10
|
+
text: HTMLElement;
|
|
11
|
+
value: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
function truncateLabel(label: HeaderLabel): void {
|
|
15
|
+
const { root, text, value } = label;
|
|
16
|
+
text.textContent = value;
|
|
17
|
+
root.removeAttribute(overflowedAttribute);
|
|
18
|
+
|
|
19
|
+
if (text.scrollWidth - text.clientWidth <= overflowTolerance) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
root.setAttribute(overflowedAttribute, '');
|
|
24
|
+
const characters = Array.from(value);
|
|
25
|
+
let lowerBound = 0;
|
|
26
|
+
let upperBound = characters.length;
|
|
27
|
+
|
|
28
|
+
while (lowerBound < upperBound) {
|
|
29
|
+
const candidateLength = Math.ceil((lowerBound + upperBound) / 2);
|
|
30
|
+
text.textContent = characters
|
|
31
|
+
.slice(0, candidateLength)
|
|
32
|
+
.join('')
|
|
33
|
+
.trimEnd();
|
|
34
|
+
|
|
35
|
+
if (text.scrollWidth - text.clientWidth <= overflowTolerance) {
|
|
36
|
+
lowerBound = candidateLength;
|
|
37
|
+
} else {
|
|
38
|
+
upperBound = candidateLength - 1;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
text.textContent = characters.slice(0, lowerBound).join('').trimEnd();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function initTableHeaderOverflow(root: HTMLElement): () => void {
|
|
46
|
+
if (root.getAttribute(initializedAttribute) === 'true') {
|
|
47
|
+
return noop;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const labels = Array.from(
|
|
51
|
+
root.querySelectorAll<HTMLElement>(labelSelector),
|
|
52
|
+
).flatMap((labelRoot): HeaderLabel[] => {
|
|
53
|
+
const text = labelRoot.querySelector<HTMLElement>(textSelector);
|
|
54
|
+
const value = labelRoot.dataset.tableHeaderOverflowText;
|
|
55
|
+
return text && value !== undefined
|
|
56
|
+
? [{ root: labelRoot, text, value }]
|
|
57
|
+
: [];
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
if (labels.length === 0) {
|
|
61
|
+
return noop;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
root.setAttribute(initializedAttribute, 'true');
|
|
65
|
+
let disposed = false;
|
|
66
|
+
let frame: number | undefined;
|
|
67
|
+
|
|
68
|
+
const sync = (): void => {
|
|
69
|
+
frame = undefined;
|
|
70
|
+
for (const label of labels) {
|
|
71
|
+
truncateLabel(label);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const schedule = (): void => {
|
|
76
|
+
if (disposed || frame !== undefined) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
frame = window.requestAnimationFrame(sync);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const resizeObserver =
|
|
83
|
+
'ResizeObserver' in window ? new ResizeObserver(schedule) : null;
|
|
84
|
+
for (const label of labels) {
|
|
85
|
+
const cell = label.root.closest<HTMLElement>('.table-header__cell');
|
|
86
|
+
if (cell) {
|
|
87
|
+
resizeObserver?.observe(cell);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
schedule();
|
|
91
|
+
void document.fonts.ready.then(schedule);
|
|
92
|
+
|
|
93
|
+
return () => {
|
|
94
|
+
disposed = true;
|
|
95
|
+
if (frame !== undefined) {
|
|
96
|
+
window.cancelAnimationFrame(frame);
|
|
97
|
+
}
|
|
98
|
+
resizeObserver?.disconnect();
|
|
99
|
+
for (const label of labels) {
|
|
100
|
+
label.text.textContent = label.value;
|
|
101
|
+
label.root.removeAttribute(overflowedAttribute);
|
|
102
|
+
}
|
|
103
|
+
root.removeAttribute(initializedAttribute);
|
|
104
|
+
};
|
|
105
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
TableColumn,
|
|
3
|
+
TableColumnAlignment,
|
|
4
|
+
TableColumnRole,
|
|
5
|
+
} from '../../display/contracts';
|
|
6
|
+
|
|
7
|
+
export type TableLayout = 'default' | 'index';
|
|
8
|
+
export type TableIndexSizing = 'compact' | 'overflow';
|
|
9
|
+
|
|
10
|
+
const roleAlignments = {
|
|
11
|
+
ordinal: 'center',
|
|
12
|
+
media: 'center',
|
|
13
|
+
primary: 'start',
|
|
14
|
+
value: 'center',
|
|
15
|
+
collection: 'start',
|
|
16
|
+
} satisfies Record<TableColumnRole, TableColumnAlignment>;
|
|
17
|
+
|
|
18
|
+
const compactIndexRoleMinimums = {
|
|
19
|
+
ordinal: 3.5,
|
|
20
|
+
media: 5,
|
|
21
|
+
primary: 8,
|
|
22
|
+
value: 4.75,
|
|
23
|
+
collection: 6.25,
|
|
24
|
+
} satisfies Record<TableColumnRole, number>;
|
|
25
|
+
|
|
26
|
+
const regularIndexRoleMinimums = {
|
|
27
|
+
...compactIndexRoleMinimums,
|
|
28
|
+
value: 7,
|
|
29
|
+
} satisfies Record<TableColumnRole, number>;
|
|
30
|
+
|
|
31
|
+
export function getTableColumnDensity(
|
|
32
|
+
columns: readonly TableColumn[],
|
|
33
|
+
): 'compact' | 'regular' {
|
|
34
|
+
return columns.length >= 7 ? 'compact' : 'regular';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function getTableColumnTemplate(
|
|
38
|
+
columns: readonly TableColumn[],
|
|
39
|
+
layout: TableLayout = 'default',
|
|
40
|
+
indexSizing: TableIndexSizing = 'compact',
|
|
41
|
+
): string {
|
|
42
|
+
const indexMinimums = getIndexRoleMinimums(columns);
|
|
43
|
+
|
|
44
|
+
return columns
|
|
45
|
+
.map((column) =>
|
|
46
|
+
layout === 'index'
|
|
47
|
+
? indexSizing === 'overflow'
|
|
48
|
+
? 'max-content'
|
|
49
|
+
: getIndexColumnTrack(column.role, indexMinimums)
|
|
50
|
+
: getDefaultColumnTrack(column),
|
|
51
|
+
)
|
|
52
|
+
.join(' ');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function getTableMinimumInlineSize(
|
|
56
|
+
columns: readonly TableColumn[],
|
|
57
|
+
layout: TableLayout = 'default',
|
|
58
|
+
): string | undefined {
|
|
59
|
+
if (layout !== 'index') {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const indexMinimums = getIndexRoleMinimums(columns);
|
|
64
|
+
const minimum = columns.reduce(
|
|
65
|
+
(total, column) => total + indexMinimums[column.role],
|
|
66
|
+
0,
|
|
67
|
+
);
|
|
68
|
+
return `${minimum}rem`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function getTableColumnAlignment(
|
|
72
|
+
column: TableColumn,
|
|
73
|
+
): TableColumnAlignment {
|
|
74
|
+
return column.align ?? roleAlignments[column.role];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function getTableHeaderAlignment(
|
|
78
|
+
column: TableColumn,
|
|
79
|
+
): TableColumnAlignment {
|
|
80
|
+
return column.headerAlign ?? getTableColumnAlignment(column);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function getIndexRoleMinimums(
|
|
84
|
+
columns: readonly TableColumn[],
|
|
85
|
+
): Record<TableColumnRole, number> {
|
|
86
|
+
return getTableColumnDensity(columns) === 'compact'
|
|
87
|
+
? compactIndexRoleMinimums
|
|
88
|
+
: regularIndexRoleMinimums;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function getIndexColumnTrack(
|
|
92
|
+
role: TableColumnRole,
|
|
93
|
+
minimums: Record<TableColumnRole, number>,
|
|
94
|
+
): string {
|
|
95
|
+
const minimum = `${minimums[role]}rem`;
|
|
96
|
+
return role === 'primary' ? `minmax(${minimum}, 1fr)` : minimum;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function getDefaultColumnTrack(column: TableColumn): string {
|
|
100
|
+
if (column.sizing === 'fill') {
|
|
101
|
+
return column.wrap
|
|
102
|
+
? 'minmax(min-content, 1fr)'
|
|
103
|
+
: 'minmax(max-content, 1fr)';
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (column.role === 'primary') {
|
|
107
|
+
return column.wrap
|
|
108
|
+
? 'minmax(min-content, 1fr)'
|
|
109
|
+
: 'minmax(max-content, 1fr)';
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return 'max-content';
|
|
113
|
+
}
|