@unofficialbox/box-open-elements 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 +125 -0
- package/dist/components/actions/button-group.d.ts +22 -0
- package/dist/components/actions/button-group.js +255 -0
- package/dist/components/actions/button.d.ts +16 -0
- package/dist/components/actions/button.js +190 -0
- package/dist/components/actions/icon-button.d.ts +20 -0
- package/dist/components/actions/icon-button.js +187 -0
- package/dist/components/actions/link-button.d.ts +14 -0
- package/dist/components/actions/link-button.js +137 -0
- package/dist/components/actions/menu-item.d.ts +17 -0
- package/dist/components/actions/menu-item.js +137 -0
- package/dist/components/actions/menu.d.ts +22 -0
- package/dist/components/actions/menu.js +178 -0
- package/dist/components/actions/segmented-control.d.ts +27 -0
- package/dist/components/actions/segmented-control.js +273 -0
- package/dist/components/collections/card.d.ts +13 -0
- package/dist/components/collections/card.js +110 -0
- package/dist/components/collections/carousel.d.ts +40 -0
- package/dist/components/collections/carousel.js +406 -0
- package/dist/components/collections/datalist-item.d.ts +32 -0
- package/dist/components/collections/datalist-item.js +196 -0
- package/dist/components/collections/draggable-list.d.ts +33 -0
- package/dist/components/collections/draggable-list.js +306 -0
- package/dist/components/collections/grid-view.d.ts +38 -0
- package/dist/components/collections/grid-view.js +321 -0
- package/dist/components/collections/pagination.d.ts +19 -0
- package/dist/components/collections/pagination.js +147 -0
- package/dist/components/collections/tree-grid.d.ts +47 -0
- package/dist/components/collections/tree-grid.js +593 -0
- package/dist/components/collections/tree.d.ts +37 -0
- package/dist/components/collections/tree.js +526 -0
- package/dist/components/feedback/alert.d.ts +27 -0
- package/dist/components/feedback/alert.js +263 -0
- package/dist/components/feedback/badge.d.ts +12 -0
- package/dist/components/feedback/badge.js +99 -0
- package/dist/components/feedback/chip.d.ts +33 -0
- package/dist/components/feedback/chip.js +261 -0
- package/dist/components/feedback/empty-state.d.ts +19 -0
- package/dist/components/feedback/empty-state.js +137 -0
- package/dist/components/feedback/error-mask.d.ts +25 -0
- package/dist/components/feedback/error-mask.js +199 -0
- package/dist/components/feedback/help-text.d.ts +22 -0
- package/dist/components/feedback/help-text.js +176 -0
- package/dist/components/feedback/nudge.d.ts +32 -0
- package/dist/components/feedback/nudge.js +299 -0
- package/dist/components/feedback/progress-bar.d.ts +18 -0
- package/dist/components/feedback/progress-bar.js +128 -0
- package/dist/components/feedback/progress-ring.d.ts +21 -0
- package/dist/components/feedback/progress-ring.js +155 -0
- package/dist/components/feedback/progress-steps.d.ts +25 -0
- package/dist/components/feedback/progress-steps.js +276 -0
- package/dist/components/feedback/skeleton.d.ts +14 -0
- package/dist/components/feedback/skeleton.js +95 -0
- package/dist/components/feedback/spinner.d.ts +10 -0
- package/dist/components/feedback/spinner.js +80 -0
- package/dist/components/feedback/toast.d.ts +26 -0
- package/dist/components/feedback/toast.js +205 -0
- package/dist/components/files/drop-zone.d.ts +19 -0
- package/dist/components/files/drop-zone.js +169 -0
- package/dist/components/forms/calendar.d.ts +47 -0
- package/dist/components/forms/calendar.js +499 -0
- package/dist/components/forms/category-selector.d.ts +35 -0
- package/dist/components/forms/category-selector.js +269 -0
- package/dist/components/forms/checkbox-group.d.ts +31 -0
- package/dist/components/forms/checkbox-group.js +267 -0
- package/dist/components/forms/checkbox.d.ts +28 -0
- package/dist/components/forms/checkbox.js +250 -0
- package/dist/components/forms/color-picker.d.ts +34 -0
- package/dist/components/forms/color-picker.js +314 -0
- package/dist/components/forms/combobox.d.ts +37 -0
- package/dist/components/forms/combobox.js +234 -0
- package/dist/components/forms/date-field.d.ts +27 -0
- package/dist/components/forms/date-field.js +187 -0
- package/dist/components/forms/dropdown.d.ts +38 -0
- package/dist/components/forms/dropdown.js +405 -0
- package/dist/components/forms/dual-listbox.d.ts +44 -0
- package/dist/components/forms/dual-listbox.js +484 -0
- package/dist/components/forms/fieldset.d.ts +32 -0
- package/dist/components/forms/fieldset.js +168 -0
- package/dist/components/forms/multi-select.d.ts +30 -0
- package/dist/components/forms/multi-select.js +264 -0
- package/dist/components/forms/number-input.d.ts +32 -0
- package/dist/components/forms/number-input.js +245 -0
- package/dist/components/forms/pill-cloud.d.ts +35 -0
- package/dist/components/forms/pill-cloud.js +230 -0
- package/dist/components/forms/pill-selector-dropdown.d.ts +55 -0
- package/dist/components/forms/pill-selector-dropdown.js +499 -0
- package/dist/components/forms/radio-group.d.ts +32 -0
- package/dist/components/forms/radio-group.js +285 -0
- package/dist/components/forms/range-slider.d.ts +36 -0
- package/dist/components/forms/range-slider.js +294 -0
- package/dist/components/forms/rating.d.ts +31 -0
- package/dist/components/forms/rating.js +302 -0
- package/dist/components/forms/rich-text-input.d.ts +32 -0
- package/dist/components/forms/rich-text-input.js +403 -0
- package/dist/components/forms/search-field.d.ts +27 -0
- package/dist/components/forms/search-field.js +293 -0
- package/dist/components/forms/select.d.ts +30 -0
- package/dist/components/forms/select.js +198 -0
- package/dist/components/forms/slider.d.ts +31 -0
- package/dist/components/forms/slider.js +221 -0
- package/dist/components/forms/spin-button.d.ts +33 -0
- package/dist/components/forms/spin-button.js +352 -0
- package/dist/components/forms/switch.d.ts +32 -0
- package/dist/components/forms/switch.js +302 -0
- package/dist/components/forms/tag-input.d.ts +46 -0
- package/dist/components/forms/tag-input.js +420 -0
- package/dist/components/forms/text-area.d.ts +26 -0
- package/dist/components/forms/text-area.js +188 -0
- package/dist/components/forms/text-field.d.ts +24 -0
- package/dist/components/forms/text-field.js +151 -0
- package/dist/components/forms/time-field.d.ts +29 -0
- package/dist/components/forms/time-field.js +203 -0
- package/dist/components/identity/avatar.d.ts +21 -0
- package/dist/components/identity/avatar.js +191 -0
- package/dist/components/identity/contact-datalist-item.d.ts +31 -0
- package/dist/components/identity/contact-datalist-item.js +235 -0
- package/dist/components/identity/persona.d.ts +28 -0
- package/dist/components/identity/persona.js +272 -0
- package/dist/components/layout/app-shell.d.ts +26 -0
- package/dist/components/layout/app-shell.js +258 -0
- package/dist/components/layout/divider.d.ts +12 -0
- package/dist/components/layout/divider.js +119 -0
- package/dist/components/layout/nav-sidebar.d.ts +23 -0
- package/dist/components/layout/nav-sidebar.js +167 -0
- package/dist/components/layout/section.d.ts +20 -0
- package/dist/components/layout/section.js +143 -0
- package/dist/components/layout/sidebar-toggle-button.d.ts +26 -0
- package/dist/components/layout/sidebar-toggle-button.js +137 -0
- package/dist/components/layout/split-view.d.ts +19 -0
- package/dist/components/layout/split-view.js +157 -0
- package/dist/components/navigation/accordion.d.ts +25 -0
- package/dist/components/navigation/accordion.js +253 -0
- package/dist/components/navigation/tabs.d.ts +27 -0
- package/dist/components/navigation/tabs.js +289 -0
- package/dist/components/overlays/dialog.d.ts +26 -0
- package/dist/components/overlays/dialog.js +267 -0
- package/dist/components/overlays/drawer.d.ts +32 -0
- package/dist/components/overlays/drawer.js +323 -0
- package/dist/components/overlays/popover.d.ts +35 -0
- package/dist/components/overlays/popover.js +317 -0
- package/dist/components/overlays/tooltip.d.ts +26 -0
- package/dist/components/overlays/tooltip.js +204 -0
- package/dist/components/visuals/illustration.d.ts +26 -0
- package/dist/components/visuals/illustration.js +319 -0
- package/dist/core/controller.d.ts +11 -0
- package/dist/core/controller.js +23 -0
- package/dist/core/element.d.ts +22 -0
- package/dist/core/element.js +28 -0
- package/dist/core/event-emitter.d.ts +9 -0
- package/dist/core/event-emitter.js +33 -0
- package/dist/core/form-associated.d.ts +63 -0
- package/dist/core/form-associated.js +218 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.js +4 -0
- package/dist/core/json-schema.d.ts +1 -0
- package/dist/core/json-schema.js +1 -0
- package/dist/foundations/a11y/focus.d.ts +17 -0
- package/dist/foundations/a11y/focus.js +94 -0
- package/dist/foundations/a11y/heading.d.ts +26 -0
- package/dist/foundations/a11y/heading.js +40 -0
- package/dist/foundations/a11y/index.d.ts +5 -0
- package/dist/foundations/a11y/index.js +3 -0
- package/dist/foundations/a11y/keyboard.d.ts +28 -0
- package/dist/foundations/a11y/keyboard.js +77 -0
- package/dist/foundations/geometry/index.d.ts +1 -0
- package/dist/foundations/geometry/index.js +1 -0
- package/dist/foundations/geometry/tokens.d.ts +123 -0
- package/dist/foundations/geometry/tokens.js +154 -0
- package/dist/foundations/icons/box-iconography.d.ts +479 -0
- package/dist/foundations/icons/box-iconography.generated.d.ts +2370 -0
- package/dist/foundations/icons/box-iconography.generated.js +4010 -0
- package/dist/foundations/icons/box-iconography.js +39 -0
- package/dist/foundations/icons/index.d.ts +1 -0
- package/dist/foundations/icons/index.js +1 -0
- package/dist/foundations/motion/index.d.ts +2 -0
- package/dist/foundations/motion/index.js +1 -0
- package/dist/foundations/motion/tokens.d.ts +39 -0
- package/dist/foundations/motion/tokens.js +43 -0
- package/dist/foundations/tokens/box-dark.d.ts +11 -0
- package/dist/foundations/tokens/box-dark.js +46 -0
- package/dist/foundations/tokens/box-defaults.d.ts +5 -0
- package/dist/foundations/tokens/box-defaults.js +52 -0
- package/dist/foundations/tokens/index.d.ts +5 -0
- package/dist/foundations/tokens/index.js +4 -0
- package/dist/foundations/tokens/interaction.d.ts +28 -0
- package/dist/foundations/tokens/interaction.js +72 -0
- package/dist/foundations/tokens/registry.d.ts +14 -0
- package/dist/foundations/tokens/registry.js +92 -0
- package/dist/foundations/tokens/types.d.ts +16 -0
- package/dist/foundations/tokens/types.js +1 -0
- package/dist/foundations/typography/index.d.ts +2 -0
- package/dist/foundations/typography/index.js +1 -0
- package/dist/foundations/typography/tokens.d.ts +76 -0
- package/dist/foundations/typography/tokens.js +27 -0
- package/dist/index.d.ts +87 -0
- package/dist/index.js +98 -0
- package/dist/patterns/content-explorer/actions/controller.d.ts +12 -0
- package/dist/patterns/content-explorer/actions/controller.js +36 -0
- package/dist/patterns/content-explorer/actions/index.d.ts +2 -0
- package/dist/patterns/content-explorer/actions/index.js +1 -0
- package/dist/patterns/content-explorer/actions/types.d.ts +13 -0
- package/dist/patterns/content-explorer/actions/types.js +1 -0
- package/dist/patterns/content-explorer/adapters/action-menu.d.ts +24 -0
- package/dist/patterns/content-explorer/adapters/action-menu.js +312 -0
- package/dist/patterns/content-explorer/adapters/breadcrumbs.d.ts +15 -0
- package/dist/patterns/content-explorer/adapters/breadcrumbs.js +161 -0
- package/dist/patterns/content-explorer/adapters/item-summary.d.ts +11 -0
- package/dist/patterns/content-explorer/adapters/item-summary.js +72 -0
- package/dist/patterns/content-explorer/adapters/items.d.ts +4 -0
- package/dist/patterns/content-explorer/adapters/items.js +12 -0
- package/dist/patterns/content-explorer/adapters/list.d.ts +28 -0
- package/dist/patterns/content-explorer/adapters/list.js +527 -0
- package/dist/patterns/content-explorer/adapters/table.d.ts +23 -0
- package/dist/patterns/content-explorer/adapters/table.js +467 -0
- package/dist/patterns/content-explorer/adapters/toolbar.d.ts +19 -0
- package/dist/patterns/content-explorer/adapters/toolbar.js +234 -0
- package/dist/patterns/content-explorer/box-transport.d.ts +44 -0
- package/dist/patterns/content-explorer/box-transport.js +229 -0
- package/dist/patterns/content-explorer/collection/controller.d.ts +17 -0
- package/dist/patterns/content-explorer/collection/controller.js +67 -0
- package/dist/patterns/content-explorer/collection/index.d.ts +2 -0
- package/dist/patterns/content-explorer/collection/index.js +1 -0
- package/dist/patterns/content-explorer/collection/types.d.ts +20 -0
- package/dist/patterns/content-explorer/collection/types.js +1 -0
- package/dist/patterns/content-explorer/content-explorer.d.ts +85 -0
- package/dist/patterns/content-explorer/content-explorer.js +745 -0
- package/dist/patterns/content-explorer/contracts.d.ts +32 -0
- package/dist/patterns/content-explorer/contracts.js +114 -0
- package/dist/patterns/content-explorer/controller.d.ts +34 -0
- package/dist/patterns/content-explorer/controller.js +399 -0
- package/dist/patterns/content-explorer/host-bindings.d.ts +50 -0
- package/dist/patterns/content-explorer/host-bindings.js +76 -0
- package/dist/patterns/content-explorer/index.d.ts +18 -0
- package/dist/patterns/content-explorer/index.js +24 -0
- package/dist/patterns/content-explorer/navigation/controller.d.ts +10 -0
- package/dist/patterns/content-explorer/navigation/controller.js +48 -0
- package/dist/patterns/content-explorer/navigation/index.d.ts +2 -0
- package/dist/patterns/content-explorer/navigation/index.js +1 -0
- package/dist/patterns/content-explorer/navigation/types.d.ts +20 -0
- package/dist/patterns/content-explorer/navigation/types.js +1 -0
- package/dist/patterns/content-explorer/schemas.d.ts +6 -0
- package/dist/patterns/content-explorer/schemas.js +120 -0
- package/dist/patterns/content-explorer/selection/controller.d.ts +12 -0
- package/dist/patterns/content-explorer/selection/controller.js +54 -0
- package/dist/patterns/content-explorer/selection/index.d.ts +2 -0
- package/dist/patterns/content-explorer/selection/index.js +1 -0
- package/dist/patterns/content-explorer/selection/types.d.ts +14 -0
- package/dist/patterns/content-explorer/selection/types.js +1 -0
- package/dist/patterns/content-explorer/types.d.ts +209 -0
- package/dist/patterns/content-explorer/types.js +10 -0
- package/dist/patterns/file-request/file-request-builder.d.ts +36 -0
- package/dist/patterns/file-request/file-request-builder.js +344 -0
- package/dist/patterns/file-request/index.d.ts +1 -0
- package/dist/patterns/file-request/index.js +1 -0
- package/dist/patterns/governance/governance-panel.d.ts +40 -0
- package/dist/patterns/governance/governance-panel.js +351 -0
- package/dist/patterns/governance/index.d.ts +1 -0
- package/dist/patterns/governance/index.js +1 -0
- package/dist/patterns/insights/bar-chart.d.ts +43 -0
- package/dist/patterns/insights/bar-chart.js +462 -0
- package/dist/patterns/insights/chart-panel.d.ts +43 -0
- package/dist/patterns/insights/chart-panel.js +436 -0
- package/dist/patterns/insights/donut-chart.d.ts +43 -0
- package/dist/patterns/insights/donut-chart.js +535 -0
- package/dist/patterns/insights/index.d.ts +5 -0
- package/dist/patterns/insights/index.js +5 -0
- package/dist/patterns/insights/line-chart.d.ts +46 -0
- package/dist/patterns/insights/line-chart.js +511 -0
- package/dist/patterns/insights/metric-card.d.ts +36 -0
- package/dist/patterns/insights/metric-card.js +278 -0
- package/dist/patterns/item/bulk-action-bar.d.ts +35 -0
- package/dist/patterns/item/bulk-action-bar.js +325 -0
- package/dist/patterns/item/index.d.ts +4 -0
- package/dist/patterns/item/index.js +4 -0
- package/dist/patterns/item/item-details-panel.d.ts +61 -0
- package/dist/patterns/item/item-details-panel.js +429 -0
- package/dist/patterns/item/item-form.d.ts +54 -0
- package/dist/patterns/item/item-form.js +485 -0
- package/dist/patterns/item/preview-header.d.ts +46 -0
- package/dist/patterns/item/preview-header.js +323 -0
- package/dist/patterns/metadata/contracts.d.ts +75 -0
- package/dist/patterns/metadata/contracts.js +91 -0
- package/dist/patterns/metadata/index.d.ts +4 -0
- package/dist/patterns/metadata/index.js +4 -0
- package/dist/patterns/metadata/metadata-filter-builder.d.ts +43 -0
- package/dist/patterns/metadata/metadata-filter-builder.js +362 -0
- package/dist/patterns/metadata/metadata-inspector.d.ts +31 -0
- package/dist/patterns/metadata/metadata-inspector.js +245 -0
- package/dist/patterns/metadata/schemas.d.ts +5 -0
- package/dist/patterns/metadata/schemas.js +66 -0
- package/dist/patterns/preview/annotation-inspector.d.ts +44 -0
- package/dist/patterns/preview/annotation-inspector.js +380 -0
- package/dist/patterns/preview/annotation-thread.d.ts +37 -0
- package/dist/patterns/preview/annotation-thread.js +338 -0
- package/dist/patterns/preview/annotation-toolbar.d.ts +42 -0
- package/dist/patterns/preview/annotation-toolbar.js +393 -0
- package/dist/patterns/preview/content-preview-adapter.d.ts +13 -0
- package/dist/patterns/preview/content-preview-adapter.js +30 -0
- package/dist/patterns/preview/index.d.ts +6 -0
- package/dist/patterns/preview/index.js +6 -0
- package/dist/patterns/preview/preview-element.d.ts +41 -0
- package/dist/patterns/preview/preview-element.js +429 -0
- package/dist/patterns/preview/provider-adapter.d.ts +36 -0
- package/dist/patterns/preview/provider-adapter.js +29 -0
- package/dist/patterns/search/filter-bar.d.ts +50 -0
- package/dist/patterns/search/filter-bar.js +379 -0
- package/dist/patterns/search/index.d.ts +3 -0
- package/dist/patterns/search/index.js +3 -0
- package/dist/patterns/search/saved-view-picker.d.ts +25 -0
- package/dist/patterns/search/saved-view-picker.js +239 -0
- package/dist/patterns/search/search-results-header.d.ts +34 -0
- package/dist/patterns/search/search-results-header.js +288 -0
- package/dist/patterns/share/access-stats.d.ts +19 -0
- package/dist/patterns/share/access-stats.js +204 -0
- package/dist/patterns/share/collaborator-avatars.d.ts +22 -0
- package/dist/patterns/share/collaborator-avatars.js +214 -0
- package/dist/patterns/share/contracts.d.ts +65 -0
- package/dist/patterns/share/contracts.js +75 -0
- package/dist/patterns/share/index.d.ts +14 -0
- package/dist/patterns/share/index.js +14 -0
- package/dist/patterns/share/invite-collaborators-contracts.d.ts +38 -0
- package/dist/patterns/share/invite-collaborators-contracts.js +1 -0
- package/dist/patterns/share/invite-collaborators-controller.d.ts +40 -0
- package/dist/patterns/share/invite-collaborators-controller.js +86 -0
- package/dist/patterns/share/invite-collaborators-modal.d.ts +46 -0
- package/dist/patterns/share/invite-collaborators-modal.js +465 -0
- package/dist/patterns/share/permission-matrix.d.ts +37 -0
- package/dist/patterns/share/permission-matrix.js +360 -0
- package/dist/patterns/share/presence-contracts.d.ts +26 -0
- package/dist/patterns/share/presence-contracts.js +1 -0
- package/dist/patterns/share/presence-controller.d.ts +31 -0
- package/dist/patterns/share/presence-controller.js +47 -0
- package/dist/patterns/share/presence.d.ts +32 -0
- package/dist/patterns/share/presence.js +255 -0
- package/dist/patterns/share/schemas.d.ts +4 -0
- package/dist/patterns/share/schemas.js +41 -0
- package/dist/patterns/share/share-panel.d.ts +75 -0
- package/dist/patterns/share/share-panel.js +565 -0
- package/dist/patterns/share/unified-share-controller.d.ts +52 -0
- package/dist/patterns/share/unified-share-controller.js +97 -0
- package/dist/patterns/share/unified-share-modal.d.ts +50 -0
- package/dist/patterns/share/unified-share-modal.js +646 -0
- package/dist/patterns/task/index.d.ts +2 -0
- package/dist/patterns/task/index.js +2 -0
- package/dist/patterns/task/review-queue-item.d.ts +45 -0
- package/dist/patterns/task/review-queue-item.js +403 -0
- package/dist/patterns/task/task-assignment-panel.d.ts +50 -0
- package/dist/patterns/task/task-assignment-panel.js +450 -0
- package/package.json +151 -0
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
import { BaseElement } from "../../core/index.js";
|
|
2
|
+
import { boeFocusVisibleStyles } from "../../foundations/tokens/index.js";
|
|
3
|
+
import { boeMotionDuration, boeMotionEasing } from "../../foundations/motion/index.js";
|
|
4
|
+
import { boeRadius } from "../../foundations/geometry/index.js";
|
|
5
|
+
const DEFAULT_TAG_NAME = "box-tree-grid";
|
|
6
|
+
const escapeHtml = (value) => value
|
|
7
|
+
.replaceAll("&", "&")
|
|
8
|
+
.replaceAll("<", "<")
|
|
9
|
+
.replaceAll(">", ">")
|
|
10
|
+
.replaceAll('"', """)
|
|
11
|
+
.replaceAll("'", "'");
|
|
12
|
+
const collectBranchValues = (items) => {
|
|
13
|
+
const values = [];
|
|
14
|
+
for (const item of items) {
|
|
15
|
+
if ((item.children?.length ?? 0) > 0) {
|
|
16
|
+
values.push(item.value, ...collectBranchValues(item.children ?? []));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return values;
|
|
20
|
+
};
|
|
21
|
+
const treeGridStyles = `
|
|
22
|
+
:host {
|
|
23
|
+
display: block;
|
|
24
|
+
color: inherit;
|
|
25
|
+
font: inherit;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
[part="controls"] {
|
|
29
|
+
display: flex;
|
|
30
|
+
justify-content: flex-end;
|
|
31
|
+
gap: 0.5rem;
|
|
32
|
+
margin-bottom: 0.625rem;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
[part="controls"][hidden] {
|
|
36
|
+
display: none;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
[part~="control"] {
|
|
40
|
+
width: 1.5rem;
|
|
41
|
+
height: 1.5rem;
|
|
42
|
+
display: inline-grid;
|
|
43
|
+
place-items: center;
|
|
44
|
+
appearance: none;
|
|
45
|
+
border: 1px solid color-mix(in srgb, var(--boe-token-stroke-stroke, #e8e8e8) 88%, var(--boe-token-surface-surface, #ffffff) 12%);
|
|
46
|
+
border-radius: ${boeRadius.size};
|
|
47
|
+
padding: 0;
|
|
48
|
+
line-height: 1;
|
|
49
|
+
background: var(--boe-token-surface-surface, #ffffff);
|
|
50
|
+
color: var(--boe-token-text-text-secondary, #6f6f6f);
|
|
51
|
+
cursor: pointer;
|
|
52
|
+
box-shadow: none;
|
|
53
|
+
transition:
|
|
54
|
+
background-color ${boeMotionDuration.interactive} ${boeMotionEasing.standard},
|
|
55
|
+
border-color ${boeMotionDuration.interactive} ${boeMotionEasing.standard},
|
|
56
|
+
color ${boeMotionDuration.interactive} ${boeMotionEasing.standard};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
[part~="control"]:hover {
|
|
60
|
+
background: var(--boe-token-surface-surface-hover, #f4f4f4);
|
|
61
|
+
color: var(--boe-token-text-text, #222222);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
[part~="control"] svg {
|
|
65
|
+
width: 0.75rem;
|
|
66
|
+
height: 0.75rem;
|
|
67
|
+
display: block;
|
|
68
|
+
stroke: currentColor;
|
|
69
|
+
fill: none;
|
|
70
|
+
stroke-width: 1.3;
|
|
71
|
+
stroke-linecap: round;
|
|
72
|
+
stroke-linejoin: round;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
[part~="control"]:focus-visible {
|
|
76
|
+
outline: 2px solid color-mix(in srgb, var(--boe-token-surface-surface-brand, #0061d5) 34%, transparent);
|
|
77
|
+
outline-offset: 2px;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
[part="tree-grid"] {
|
|
81
|
+
display: grid;
|
|
82
|
+
gap: 0;
|
|
83
|
+
border: 1px solid color-mix(in srgb, var(--boe-token-stroke-stroke, #e8e8e8) 78%, var(--boe-token-surface-surface, #ffffff) 22%);
|
|
84
|
+
border-radius: ${boeRadius.large};
|
|
85
|
+
overflow: hidden;
|
|
86
|
+
background: var(--boe-token-surface-surface, #ffffff);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
[part="header-row"],
|
|
90
|
+
[part="row"] {
|
|
91
|
+
display: grid;
|
|
92
|
+
grid-template-columns: var(--tree-grid-columns, minmax(260px, 1.5fr));
|
|
93
|
+
align-items: center;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
[part="header-cell"],
|
|
97
|
+
[part="cell"],
|
|
98
|
+
[part="tree-cell"] {
|
|
99
|
+
padding: 0.5rem 0.65rem;
|
|
100
|
+
min-width: 0;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
[part="header-cell"] {
|
|
104
|
+
font-size: 0.78rem;
|
|
105
|
+
font-weight: 700;
|
|
106
|
+
letter-spacing: 0.06em;
|
|
107
|
+
text-transform: uppercase;
|
|
108
|
+
color: var(--boe-token-text-text-secondary, #6f6f6f);
|
|
109
|
+
background: color-mix(in srgb, var(--boe-token-surface-surface-secondary, #fbfbfb) 88%, var(--boe-token-surface-surface, #ffffff) 12%);
|
|
110
|
+
border-bottom: 1px solid color-mix(in srgb, var(--boe-token-stroke-stroke, #e8e8e8) 78%, transparent);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
[part="row"] {
|
|
114
|
+
border-bottom: 1px solid color-mix(in srgb, var(--boe-token-stroke-stroke, #e8e8e8) 48%, transparent);
|
|
115
|
+
background: color-mix(in srgb, var(--boe-token-surface-surface, #ffffff) 92%, transparent);
|
|
116
|
+
transition:
|
|
117
|
+
background-color ${boeMotionDuration.interactive} ${boeMotionEasing.standard},
|
|
118
|
+
box-shadow ${boeMotionDuration.interactive} ${boeMotionEasing.standard};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
[part="row"]:hover {
|
|
122
|
+
background: color-mix(in srgb, var(--boe-token-surface-item-surface-hover, #eef4fb) 68%, var(--boe-token-surface-surface, #ffffff) 32%);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
[part="row-selected"],
|
|
126
|
+
[part="row-selected"]:hover {
|
|
127
|
+
background: color-mix(in srgb, var(--boe-token-surface-item-surface-selected, #f2f7fd) 78%, var(--boe-token-surface-surface, #ffffff) 22%);
|
|
128
|
+
box-shadow: inset 3px 0 0 var(--boe-token-surface-surface-brand, #0061d5);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
[part="tree-content"] {
|
|
132
|
+
display: grid;
|
|
133
|
+
grid-template-columns: 1.125rem minmax(0, 1fr);
|
|
134
|
+
gap: 0.55rem;
|
|
135
|
+
align-items: center;
|
|
136
|
+
padding-left: calc(var(--tree-grid-depth, 0) * 1.25rem);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
[part~="toggle"] {
|
|
140
|
+
width: 1.125rem;
|
|
141
|
+
height: 1.125rem;
|
|
142
|
+
display: inline-grid;
|
|
143
|
+
place-items: center;
|
|
144
|
+
appearance: none;
|
|
145
|
+
border: none;
|
|
146
|
+
border-radius: ${boeRadius.size};
|
|
147
|
+
padding: 0;
|
|
148
|
+
line-height: 1;
|
|
149
|
+
background: transparent;
|
|
150
|
+
color: var(--boe-token-text-text-secondary, #6f6f6f);
|
|
151
|
+
font: inherit;
|
|
152
|
+
cursor: pointer;
|
|
153
|
+
transition:
|
|
154
|
+
background-color ${boeMotionDuration.interactive} ${boeMotionEasing.standard},
|
|
155
|
+
color ${boeMotionDuration.interactive} ${boeMotionEasing.standard};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
[part~="toggle"]:hover {
|
|
159
|
+
background: var(--boe-token-surface-surface-hover, #f4f4f4);
|
|
160
|
+
color: var(--boe-token-text-text, #222222);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
[part~="toggle"] svg {
|
|
164
|
+
width: 0.625rem;
|
|
165
|
+
height: 0.625rem;
|
|
166
|
+
display: block;
|
|
167
|
+
stroke: currentColor;
|
|
168
|
+
fill: none;
|
|
169
|
+
stroke-width: 1.6;
|
|
170
|
+
stroke-linecap: round;
|
|
171
|
+
stroke-linejoin: round;
|
|
172
|
+
transition: transform ${boeMotionDuration.interactive} ${boeMotionEasing.standard};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/* Collapsed chevron points right; expanded rotates it down (flat Box idiom). */
|
|
176
|
+
[part~="toggle-expanded"] svg {
|
|
177
|
+
transform: rotate(90deg);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
[part="spacer"] {
|
|
181
|
+
width: 1.125rem;
|
|
182
|
+
height: 1.125rem;
|
|
183
|
+
display: inline-block;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
[part~="item"] {
|
|
187
|
+
appearance: none;
|
|
188
|
+
text-align: left;
|
|
189
|
+
border: 1px solid transparent;
|
|
190
|
+
border-radius: ${boeRadius.med};
|
|
191
|
+
padding: 0.35rem 0.5rem;
|
|
192
|
+
background: transparent;
|
|
193
|
+
color: var(--boe-token-text-text, #222222);
|
|
194
|
+
font: inherit;
|
|
195
|
+
font-size: 0.9rem;
|
|
196
|
+
font-weight: 500;
|
|
197
|
+
cursor: pointer;
|
|
198
|
+
transition:
|
|
199
|
+
border-color ${boeMotionDuration.interactive} ${boeMotionEasing.standard},
|
|
200
|
+
background-color ${boeMotionDuration.interactive} ${boeMotionEasing.standard},
|
|
201
|
+
color ${boeMotionDuration.interactive} ${boeMotionEasing.standard};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
[part~="item"]:hover {
|
|
205
|
+
border-color: color-mix(in srgb, var(--boe-token-surface-surface-brand, #0061d5) 10%, transparent);
|
|
206
|
+
background: color-mix(in srgb, var(--boe-token-surface-item-surface-hover, #eef4fb) 62%, var(--boe-token-surface-surface, #ffffff) 38%);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
[part~="item-selected"] {
|
|
210
|
+
border-color: color-mix(in srgb, var(--boe-token-surface-surface-brand, #0061d5) 18%, transparent);
|
|
211
|
+
background: color-mix(in srgb, var(--boe-token-surface-item-surface-selected, #f2f7fd) 72%, var(--boe-token-surface-surface, #ffffff) 28%);
|
|
212
|
+
color: var(--boe-token-text-text, #222222);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
${boeFocusVisibleStyles('[part~="item"]')}
|
|
216
|
+
${boeFocusVisibleStyles('[part~="toggle"]')}
|
|
217
|
+
|
|
218
|
+
[part="empty"] {
|
|
219
|
+
padding: 0.6rem 0.65rem;
|
|
220
|
+
color: var(--boe-token-text-text-secondary, #6f6f6f);
|
|
221
|
+
}
|
|
222
|
+
`;
|
|
223
|
+
export class BoxTreeGridElement extends BaseElement {
|
|
224
|
+
static get observedAttributes() {
|
|
225
|
+
return ["columns", "items", "label", "value"];
|
|
226
|
+
}
|
|
227
|
+
expandedInternal = new Set();
|
|
228
|
+
valueInternal = "";
|
|
229
|
+
focusValue = null;
|
|
230
|
+
controlsEl;
|
|
231
|
+
expandAllEl;
|
|
232
|
+
collapseAllEl;
|
|
233
|
+
treeGridEl;
|
|
234
|
+
headerRowEl;
|
|
235
|
+
bodyEl;
|
|
236
|
+
get columns() {
|
|
237
|
+
const raw = this.getAttribute("columns");
|
|
238
|
+
if (!raw) {
|
|
239
|
+
return [];
|
|
240
|
+
}
|
|
241
|
+
try {
|
|
242
|
+
const parsed = JSON.parse(raw);
|
|
243
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
244
|
+
}
|
|
245
|
+
catch {
|
|
246
|
+
return [];
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
set columns(value) {
|
|
250
|
+
this.setAttribute("columns", JSON.stringify(value));
|
|
251
|
+
}
|
|
252
|
+
get items() {
|
|
253
|
+
const raw = this.getAttribute("items");
|
|
254
|
+
if (!raw) {
|
|
255
|
+
return [];
|
|
256
|
+
}
|
|
257
|
+
try {
|
|
258
|
+
const parsed = JSON.parse(raw);
|
|
259
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
260
|
+
}
|
|
261
|
+
catch {
|
|
262
|
+
return [];
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
set items(value) {
|
|
266
|
+
this.setAttribute("items", JSON.stringify(value));
|
|
267
|
+
this.seedExpandedState(value);
|
|
268
|
+
}
|
|
269
|
+
get label() {
|
|
270
|
+
return this.getAttribute("label") ?? "Tree Grid";
|
|
271
|
+
}
|
|
272
|
+
set label(value) {
|
|
273
|
+
this.setAttribute("label", value);
|
|
274
|
+
}
|
|
275
|
+
get value() {
|
|
276
|
+
return this.valueInternal;
|
|
277
|
+
}
|
|
278
|
+
set value(nextValue) {
|
|
279
|
+
this.valueInternal = nextValue;
|
|
280
|
+
this.setAttribute("value", nextValue);
|
|
281
|
+
if (this.isRendered) {
|
|
282
|
+
this.update();
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
connectedCallback() {
|
|
286
|
+
this.seedExpandedState(this.items);
|
|
287
|
+
super.connectedCallback();
|
|
288
|
+
}
|
|
289
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
290
|
+
if (name === "items") {
|
|
291
|
+
this.seedExpandedState(this.items);
|
|
292
|
+
}
|
|
293
|
+
if (name === "value") {
|
|
294
|
+
this.valueInternal = this.getAttribute("value") ?? "";
|
|
295
|
+
}
|
|
296
|
+
super.attributeChangedCallback(name, oldValue, newValue);
|
|
297
|
+
}
|
|
298
|
+
seedExpandedState(items) {
|
|
299
|
+
this.expandedInternal.clear();
|
|
300
|
+
for (const item of items) {
|
|
301
|
+
if ((item.children?.length ?? 0) > 0) {
|
|
302
|
+
this.expandedInternal.add(item.value);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
emitExpandChanged(value, expanded) {
|
|
307
|
+
this.dispatchEvent(new CustomEvent("expand-changed", {
|
|
308
|
+
bubbles: true,
|
|
309
|
+
composed: true,
|
|
310
|
+
detail: { value, expanded },
|
|
311
|
+
}));
|
|
312
|
+
}
|
|
313
|
+
toggleExpanded(value) {
|
|
314
|
+
const expanded = !this.expandedInternal.has(value);
|
|
315
|
+
if (expanded) {
|
|
316
|
+
this.expandedInternal.add(value);
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
this.expandedInternal.delete(value);
|
|
320
|
+
}
|
|
321
|
+
this.emitExpandChanged(value, expanded);
|
|
322
|
+
this.update();
|
|
323
|
+
}
|
|
324
|
+
expandAll() {
|
|
325
|
+
this.expandedInternal = new Set(collectBranchValues(this.items));
|
|
326
|
+
this.update();
|
|
327
|
+
}
|
|
328
|
+
collapseAll() {
|
|
329
|
+
this.expandedInternal.clear();
|
|
330
|
+
this.update();
|
|
331
|
+
}
|
|
332
|
+
getVisibleRows(items, depth = 0) {
|
|
333
|
+
const rows = [];
|
|
334
|
+
for (const item of items) {
|
|
335
|
+
const hasChildren = (item.children?.length ?? 0) > 0;
|
|
336
|
+
rows.push({ depth, hasChildren, value: item.value });
|
|
337
|
+
if (hasChildren && this.expandedInternal.has(item.value)) {
|
|
338
|
+
rows.push(...this.getVisibleRows(item.children ?? [], depth + 1));
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return rows;
|
|
342
|
+
}
|
|
343
|
+
renderToggleIcon() {
|
|
344
|
+
// A single right-pointing chevron; CSS rotates it 90° when expanded.
|
|
345
|
+
return `
|
|
346
|
+
<svg viewBox="0 0 12 12" aria-hidden="true" focusable="false">
|
|
347
|
+
<path d="M4.5 2.5 8 6l-3.5 3.5" />
|
|
348
|
+
</svg>
|
|
349
|
+
`;
|
|
350
|
+
}
|
|
351
|
+
renderControlIcon(type) {
|
|
352
|
+
// Double chevron: pointing down = expand all, pointing up = collapse all.
|
|
353
|
+
const paths = type === "expand-all"
|
|
354
|
+
? '<path d="M3 4.25 6 7l3-2.75" /><path d="M3 7.25 6 10l3-2.75" />'
|
|
355
|
+
: '<path d="M3 7.75 6 5l3 2.75" /><path d="M3 4.75 6 2l3 2.75" />';
|
|
356
|
+
return `
|
|
357
|
+
<svg viewBox="0 0 12 12" aria-hidden="true" focusable="false">
|
|
358
|
+
${paths}
|
|
359
|
+
</svg>
|
|
360
|
+
`;
|
|
361
|
+
}
|
|
362
|
+
renderRows(items, depth = 0) {
|
|
363
|
+
return items
|
|
364
|
+
.map(item => {
|
|
365
|
+
const hasChildren = (item.children?.length ?? 0) > 0;
|
|
366
|
+
const isExpanded = this.expandedInternal.has(item.value);
|
|
367
|
+
const isSelected = item.value === this.valueInternal;
|
|
368
|
+
const togglePart = isExpanded ? "toggle toggle-expanded" : "toggle";
|
|
369
|
+
const rowPart = isSelected ? "row row-selected" : "row";
|
|
370
|
+
const itemPart = isSelected ? "item item-selected" : "item";
|
|
371
|
+
const cellMarkup = (item.cells ?? [])
|
|
372
|
+
.map((cell, index) => `
|
|
373
|
+
<div part="cell" role="gridcell" data-column-index="${index + 1}">
|
|
374
|
+
${escapeHtml(cell)}
|
|
375
|
+
</div>
|
|
376
|
+
`)
|
|
377
|
+
.join("");
|
|
378
|
+
const childrenMarkup = hasChildren && isExpanded ? this.renderRows(item.children ?? [], depth + 1) : "";
|
|
379
|
+
return `
|
|
380
|
+
<div
|
|
381
|
+
part="${rowPart}"
|
|
382
|
+
role="row"
|
|
383
|
+
data-depth="${depth}"
|
|
384
|
+
data-selected="${String(isSelected)}"
|
|
385
|
+
aria-level="${depth + 1}"
|
|
386
|
+
${hasChildren ? `aria-expanded="${String(isExpanded)}"` : ""}
|
|
387
|
+
aria-selected="${String(isSelected)}"
|
|
388
|
+
>
|
|
389
|
+
<div part="tree-cell" role="gridcell">
|
|
390
|
+
<div part="tree-content" style="--tree-grid-depth:${depth};">
|
|
391
|
+
${hasChildren
|
|
392
|
+
? `<button
|
|
393
|
+
type="button"
|
|
394
|
+
part="${togglePart}"
|
|
395
|
+
data-value="${escapeHtml(item.value)}"
|
|
396
|
+
aria-expanded="${String(isExpanded)}"
|
|
397
|
+
>${this.renderToggleIcon()}</button>`
|
|
398
|
+
: `<span part="spacer" aria-hidden="true"></span>`}
|
|
399
|
+
<button
|
|
400
|
+
type="button"
|
|
401
|
+
part="${itemPart}"
|
|
402
|
+
role="rowheader"
|
|
403
|
+
data-value="${escapeHtml(item.value)}"
|
|
404
|
+
data-branch="${String(hasChildren)}"
|
|
405
|
+
tabindex="${item.value === (this.focusValue ?? (this.valueInternal || this.items[0]?.value || "")) ? "0" : "-1"}"
|
|
406
|
+
>
|
|
407
|
+
${escapeHtml(item.label)}
|
|
408
|
+
</button>
|
|
409
|
+
</div>
|
|
410
|
+
</div>
|
|
411
|
+
${cellMarkup}
|
|
412
|
+
</div>
|
|
413
|
+
${childrenMarkup}
|
|
414
|
+
`;
|
|
415
|
+
})
|
|
416
|
+
.join("");
|
|
417
|
+
}
|
|
418
|
+
renderTemplate() {
|
|
419
|
+
if (!this.shadowRoot) {
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
this.shadowRoot.innerHTML = `
|
|
423
|
+
<style>${treeGridStyles}</style>
|
|
424
|
+
<div part="controls" hidden>
|
|
425
|
+
<button
|
|
426
|
+
type="button"
|
|
427
|
+
part="control control-expand-all"
|
|
428
|
+
data-action="expand-all"
|
|
429
|
+
aria-label="Expand all"
|
|
430
|
+
title="Expand all"
|
|
431
|
+
>${this.renderControlIcon("expand-all")}</button>
|
|
432
|
+
<button
|
|
433
|
+
type="button"
|
|
434
|
+
part="control control-collapse-all"
|
|
435
|
+
data-action="collapse-all"
|
|
436
|
+
aria-label="Collapse all"
|
|
437
|
+
title="Collapse all"
|
|
438
|
+
>${this.renderControlIcon("collapse-all")}</button>
|
|
439
|
+
</div>
|
|
440
|
+
<section part="tree-grid" role="treegrid">
|
|
441
|
+
<div part="header-row" role="row"></div>
|
|
442
|
+
<div part="body" role="rowgroup"></div>
|
|
443
|
+
</section>
|
|
444
|
+
`;
|
|
445
|
+
this.controlsEl = this.shadowRoot.querySelector('[part="controls"]');
|
|
446
|
+
this.expandAllEl = this.shadowRoot.querySelector('[data-action="expand-all"]');
|
|
447
|
+
this.collapseAllEl = this.shadowRoot.querySelector('[data-action="collapse-all"]');
|
|
448
|
+
this.treeGridEl = this.shadowRoot.querySelector('[part="tree-grid"]');
|
|
449
|
+
this.headerRowEl = this.shadowRoot.querySelector('[part="header-row"]');
|
|
450
|
+
this.bodyEl = this.shadowRoot.querySelector('[part="body"]');
|
|
451
|
+
}
|
|
452
|
+
setupListeners() {
|
|
453
|
+
this.controlsEl.addEventListener("click", event => {
|
|
454
|
+
const control = event.target?.closest('[part~="control"]');
|
|
455
|
+
if (!control || !this.controlsEl.contains(control)) {
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
const action = control.dataset.action;
|
|
459
|
+
if (action === "expand-all") {
|
|
460
|
+
this.expandAll();
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
if (action === "collapse-all") {
|
|
464
|
+
this.collapseAll();
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
this.bodyEl.addEventListener("click", event => {
|
|
468
|
+
const target = event.target;
|
|
469
|
+
const toggle = target?.closest('[part~="toggle"]');
|
|
470
|
+
if (toggle && this.bodyEl.contains(toggle)) {
|
|
471
|
+
const value = toggle.dataset.value ?? "";
|
|
472
|
+
if (value) {
|
|
473
|
+
this.focusValue = value;
|
|
474
|
+
this.toggleExpanded(value);
|
|
475
|
+
}
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
const item = target?.closest('[part~="item"]');
|
|
479
|
+
if (!item || !this.bodyEl.contains(item)) {
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
const value = item.dataset.value ?? "";
|
|
483
|
+
if (!value || value === this.valueInternal) {
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
this.valueInternal = value;
|
|
487
|
+
this.setAttribute("value", value);
|
|
488
|
+
this.dispatchEvent(new CustomEvent("value-changed", {
|
|
489
|
+
bubbles: true,
|
|
490
|
+
composed: true,
|
|
491
|
+
detail: { value },
|
|
492
|
+
}));
|
|
493
|
+
this.update();
|
|
494
|
+
});
|
|
495
|
+
this.bodyEl.addEventListener("keydown", event => {
|
|
496
|
+
const keyboardEvent = event;
|
|
497
|
+
const element = keyboardEvent.target?.closest('[part~="item"]');
|
|
498
|
+
if (!element || !this.bodyEl.contains(element)) {
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
const value = element.dataset.value ?? "";
|
|
502
|
+
const isBranch = element.dataset.branch === "true";
|
|
503
|
+
const visibleRows = this.getVisibleRows(this.items);
|
|
504
|
+
const currentIndex = visibleRows.findIndex(row => row.value === value);
|
|
505
|
+
if (keyboardEvent.key === "ArrowDown" || keyboardEvent.key === "ArrowUp") {
|
|
506
|
+
keyboardEvent.preventDefault();
|
|
507
|
+
const nextIndex = keyboardEvent.key === "ArrowDown"
|
|
508
|
+
? Math.min(visibleRows.length - 1, currentIndex + 1)
|
|
509
|
+
: Math.max(0, currentIndex - 1);
|
|
510
|
+
const nextRow = visibleRows[nextIndex];
|
|
511
|
+
if (nextRow) {
|
|
512
|
+
this.focusValue = nextRow.value;
|
|
513
|
+
this.update();
|
|
514
|
+
}
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
if (keyboardEvent.key === "ArrowRight" && isBranch) {
|
|
518
|
+
keyboardEvent.preventDefault();
|
|
519
|
+
if (!this.expandedInternal.has(value)) {
|
|
520
|
+
this.expandedInternal.add(value);
|
|
521
|
+
this.emitExpandChanged(value, true);
|
|
522
|
+
this.focusValue = value;
|
|
523
|
+
this.update();
|
|
524
|
+
}
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
if (keyboardEvent.key === "ArrowLeft" && isBranch) {
|
|
528
|
+
keyboardEvent.preventDefault();
|
|
529
|
+
if (this.expandedInternal.has(value)) {
|
|
530
|
+
this.expandedInternal.delete(value);
|
|
531
|
+
this.emitExpandChanged(value, false);
|
|
532
|
+
this.focusValue = value;
|
|
533
|
+
this.update();
|
|
534
|
+
}
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
if (keyboardEvent.key === "Enter" || keyboardEvent.key === " ") {
|
|
538
|
+
keyboardEvent.preventDefault();
|
|
539
|
+
element.click();
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
if (keyboardEvent.key === "Home" || keyboardEvent.key === "End") {
|
|
543
|
+
keyboardEvent.preventDefault();
|
|
544
|
+
const nextRow = keyboardEvent.key === "Home" ? visibleRows[0] : visibleRows[visibleRows.length - 1];
|
|
545
|
+
if (nextRow) {
|
|
546
|
+
this.focusValue = nextRow.value;
|
|
547
|
+
this.update();
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
update() {
|
|
553
|
+
if (!this.controlsEl || !this.treeGridEl || !this.headerRowEl || !this.bodyEl) {
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
const columns = this.columns;
|
|
557
|
+
const branchValues = collectBranchValues(this.items);
|
|
558
|
+
const hasBranches = branchValues.length > 0;
|
|
559
|
+
const allExpanded = hasBranches && branchValues.every(value => this.expandedInternal.has(value));
|
|
560
|
+
const columnTemplate = ["minmax(260px, 1.5fr)", ...columns.slice(1).map(() => "minmax(120px, 1fr)")].join(" ");
|
|
561
|
+
this.controlsEl.hidden = !hasBranches;
|
|
562
|
+
this.expandAllEl.disabled = allExpanded;
|
|
563
|
+
this.collapseAllEl.disabled = !this.expandedInternal.size;
|
|
564
|
+
this.treeGridEl.style.setProperty("--tree-grid-columns", columnTemplate);
|
|
565
|
+
this.treeGridEl.setAttribute("aria-label", this.label);
|
|
566
|
+
this.headerRowEl.innerHTML = columns
|
|
567
|
+
.map((column, index) => `
|
|
568
|
+
<div part="header-cell" role="columnheader" data-column-index="${index}">
|
|
569
|
+
${escapeHtml(column.label)}
|
|
570
|
+
</div>
|
|
571
|
+
`)
|
|
572
|
+
.join("");
|
|
573
|
+
this.bodyEl.innerHTML = this.items.length
|
|
574
|
+
? this.renderRows(this.items)
|
|
575
|
+
: `<div part="empty">No items loaded</div>`;
|
|
576
|
+
if (this.focusValue) {
|
|
577
|
+
const valueToFocus = this.focusValue;
|
|
578
|
+
this.focusValue = null;
|
|
579
|
+
queueMicrotask(() => {
|
|
580
|
+
const target = Array.from(this.bodyEl.querySelectorAll('[part~="item"]')).find(node => node.dataset.value === valueToFocus);
|
|
581
|
+
target?.focus();
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
export const defineBoxTreeGridElement = (tagName = DEFAULT_TAG_NAME) => {
|
|
587
|
+
const existingElement = customElements.get(tagName);
|
|
588
|
+
if (existingElement) {
|
|
589
|
+
return existingElement;
|
|
590
|
+
}
|
|
591
|
+
customElements.define(tagName, BoxTreeGridElement);
|
|
592
|
+
return BoxTreeGridElement;
|
|
593
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { BaseElement } from "../../core/index.js";
|
|
2
|
+
type BoxTreeItem = {
|
|
3
|
+
children?: BoxTreeItem[];
|
|
4
|
+
label: string;
|
|
5
|
+
value?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare class BoxTreeElement extends BaseElement {
|
|
8
|
+
static get observedAttributes(): string[];
|
|
9
|
+
private expandedInternal;
|
|
10
|
+
private valueInternal;
|
|
11
|
+
private focusKey;
|
|
12
|
+
private controlsEl;
|
|
13
|
+
private expandAllEl;
|
|
14
|
+
private collapseAllEl;
|
|
15
|
+
private treeEl;
|
|
16
|
+
get label(): string;
|
|
17
|
+
set label(value: string);
|
|
18
|
+
get items(): BoxTreeItem[];
|
|
19
|
+
set items(value: BoxTreeItem[]);
|
|
20
|
+
get value(): string;
|
|
21
|
+
set value(nextValue: string);
|
|
22
|
+
connectedCallback(): void;
|
|
23
|
+
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
|
|
24
|
+
private seedExpandedState;
|
|
25
|
+
private toggleExpanded;
|
|
26
|
+
private expandAll;
|
|
27
|
+
private collapseAll;
|
|
28
|
+
private getVisibleNodes;
|
|
29
|
+
private renderToggleIcon;
|
|
30
|
+
private renderControlIcon;
|
|
31
|
+
private renderItems;
|
|
32
|
+
protected renderTemplate(): void;
|
|
33
|
+
protected setupListeners(): void;
|
|
34
|
+
protected update(): void;
|
|
35
|
+
}
|
|
36
|
+
export declare const defineBoxTreeElement: (tagName?: string) => typeof BoxTreeElement;
|
|
37
|
+
export {};
|