@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,234 @@
|
|
|
1
|
+
import { BaseElement } from "../../../core/index.js";
|
|
2
|
+
import { defineBoxSearchFieldElement, } from "../../../components/forms/search-field.js";
|
|
3
|
+
import { applyRovingTabindex, handleRovingKeydown } from "../../../foundations/a11y/index.js";
|
|
4
|
+
import { boeNeutralInteractiveStyles } from "../../../foundations/tokens/index.js";
|
|
5
|
+
import { boeMotionDuration, boeMotionEasing } from "../../../foundations/motion/index.js";
|
|
6
|
+
import { boePanel } from "../../../foundations/geometry/index.js";
|
|
7
|
+
const DEFAULT_TAG_NAME = "box-explorer-toolbar";
|
|
8
|
+
const toKebabCase = (value) => value.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`);
|
|
9
|
+
const elementStyles = `
|
|
10
|
+
:host {
|
|
11
|
+
display: block;
|
|
12
|
+
color: inherit;
|
|
13
|
+
font: inherit;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
[part="toolbar"] {
|
|
17
|
+
display: flex;
|
|
18
|
+
flex-wrap: wrap;
|
|
19
|
+
align-items: end;
|
|
20
|
+
gap: ${boePanel.gap};
|
|
21
|
+
padding: 0.55rem 0.65rem;
|
|
22
|
+
border: 1px solid color-mix(in srgb, var(--boe-token-stroke-stroke, #e8e8e8) 84%, var(--boe-token-surface-surface, #ffffff) 16%);
|
|
23
|
+
border-radius: ${boePanel.radius};
|
|
24
|
+
background: var(--boe-token-surface-surface, #ffffff);
|
|
25
|
+
box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
[part="search"] {
|
|
29
|
+
flex: 1 1 14rem;
|
|
30
|
+
min-width: 12rem;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
[part="status"],
|
|
34
|
+
[part="selection-count"] {
|
|
35
|
+
color: var(--boe-token-text-text-secondary, #6f6f6f);
|
|
36
|
+
font-size: 0.85rem;
|
|
37
|
+
white-space: nowrap;
|
|
38
|
+
padding-bottom: 0.45rem;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
[part="selection-count"] {
|
|
42
|
+
margin-right: auto;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
[part="status"][data-status="failed"] {
|
|
46
|
+
color: color-mix(in srgb, var(--boe-token-surface-status-surface-error, #ed3757) 72%, black 28%);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
[part="refresh"],
|
|
50
|
+
[part="clear-selection"] {
|
|
51
|
+
appearance: none;
|
|
52
|
+
font: inherit;
|
|
53
|
+
font-size: 0.88rem;
|
|
54
|
+
font-weight: 500;
|
|
55
|
+
padding: 0.42rem 0.8rem;
|
|
56
|
+
border: 1px solid color-mix(in srgb, var(--boe-token-stroke-stroke, #e8e8e8) 86%, var(--boe-token-surface-surface, #ffffff) 14%);
|
|
57
|
+
border-radius: ${boePanel.radius};
|
|
58
|
+
background: var(--boe-token-surface-surface, #ffffff);
|
|
59
|
+
color: var(--boe-token-text-text, #222222);
|
|
60
|
+
cursor: pointer;
|
|
61
|
+
transition:
|
|
62
|
+
border-color ${boeMotionDuration.interactive} ${boeMotionEasing.standard},
|
|
63
|
+
background-color ${boeMotionDuration.interactive} ${boeMotionEasing.standard},
|
|
64
|
+
color ${boeMotionDuration.interactive} ${boeMotionEasing.standard},
|
|
65
|
+
box-shadow ${boeMotionDuration.interactive} ${boeMotionEasing.standard};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
${boeNeutralInteractiveStyles('[part="refresh"]')}
|
|
69
|
+
${boeNeutralInteractiveStyles('[part="clear-selection"]')}
|
|
70
|
+
`;
|
|
71
|
+
export class BoxExplorerToolbarElement extends BaseElement {
|
|
72
|
+
controllerValue = null;
|
|
73
|
+
unsubscribeFns = [];
|
|
74
|
+
listenersBound = false;
|
|
75
|
+
get controller() {
|
|
76
|
+
return this.controllerValue;
|
|
77
|
+
}
|
|
78
|
+
set controller(value) {
|
|
79
|
+
this.controllerValue = value;
|
|
80
|
+
this.bindController();
|
|
81
|
+
if (this.isRendered) {
|
|
82
|
+
this.update();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
connectedCallback() {
|
|
86
|
+
defineBoxSearchFieldElement();
|
|
87
|
+
this.bindController();
|
|
88
|
+
super.connectedCallback();
|
|
89
|
+
}
|
|
90
|
+
disconnectedCallback() {
|
|
91
|
+
this.teardownSubscriptions();
|
|
92
|
+
}
|
|
93
|
+
bindController() {
|
|
94
|
+
this.teardownSubscriptions();
|
|
95
|
+
if (!this.isConnected || !this.controllerValue) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
for (const eventName of [
|
|
99
|
+
"loadingChanged",
|
|
100
|
+
"selectionChanged",
|
|
101
|
+
"loadFailed",
|
|
102
|
+
"viewChanged",
|
|
103
|
+
"searchSucceeded",
|
|
104
|
+
"loadSucceeded",
|
|
105
|
+
]) {
|
|
106
|
+
this.unsubscribeFns.push(this.controllerValue.subscribe(eventName, payload => {
|
|
107
|
+
this.dispatchEvent(new CustomEvent(toKebabCase(String(eventName)), {
|
|
108
|
+
bubbles: true,
|
|
109
|
+
composed: true,
|
|
110
|
+
detail: payload,
|
|
111
|
+
}));
|
|
112
|
+
if (this.isRendered) {
|
|
113
|
+
this.update();
|
|
114
|
+
}
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
teardownSubscriptions() {
|
|
119
|
+
for (const unsubscribe of this.unsubscribeFns) {
|
|
120
|
+
unsubscribe();
|
|
121
|
+
}
|
|
122
|
+
this.unsubscribeFns = [];
|
|
123
|
+
}
|
|
124
|
+
getSearchField() {
|
|
125
|
+
return this.shadowRoot?.querySelector('[part="search"]');
|
|
126
|
+
}
|
|
127
|
+
syncSearchField(query, loading) {
|
|
128
|
+
const searchField = this.getSearchField();
|
|
129
|
+
if (!searchField) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const active = this.shadowRoot?.activeElement;
|
|
133
|
+
const searchFocused = active === searchField || (active != null && searchField.contains(active));
|
|
134
|
+
if (!searchFocused && searchField.value !== query) {
|
|
135
|
+
searchField.value = query;
|
|
136
|
+
}
|
|
137
|
+
searchField.disabled = loading;
|
|
138
|
+
}
|
|
139
|
+
renderTemplate() {
|
|
140
|
+
if (!this.shadowRoot) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
defineBoxSearchFieldElement();
|
|
144
|
+
this.shadowRoot.innerHTML = `
|
|
145
|
+
<style>${elementStyles}</style>
|
|
146
|
+
<div part="toolbar" role="toolbar" aria-label="Explorer toolbar">
|
|
147
|
+
<box-search-field
|
|
148
|
+
part="search"
|
|
149
|
+
label="Search"
|
|
150
|
+
placeholder="Search files and folders"
|
|
151
|
+
></box-search-field>
|
|
152
|
+
<span part="status" data-status="ready" role="status" aria-live="polite">ready</span>
|
|
153
|
+
<span part="selection-count">0 selected</span>
|
|
154
|
+
<button type="button" part="refresh">Refresh</button>
|
|
155
|
+
<button type="button" part="clear-selection" disabled>Clear Selection</button>
|
|
156
|
+
</div>
|
|
157
|
+
`;
|
|
158
|
+
this.listenersBound = false;
|
|
159
|
+
}
|
|
160
|
+
setupListeners() {
|
|
161
|
+
if (!this.shadowRoot || this.listenersBound) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
this.listenersBound = true;
|
|
165
|
+
const toolbar = this.shadowRoot.querySelector('[part="toolbar"]');
|
|
166
|
+
const searchField = this.getSearchField();
|
|
167
|
+
searchField?.addEventListener("search", event => {
|
|
168
|
+
const value = String(event.detail?.value ?? "").trim();
|
|
169
|
+
if (value) {
|
|
170
|
+
void this.controllerValue?.search(value);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
void this.controllerValue?.clearSearch();
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
searchField?.addEventListener("clear", () => {
|
|
177
|
+
void this.controllerValue?.clearSearch();
|
|
178
|
+
});
|
|
179
|
+
this.shadowRoot.querySelector('[part="refresh"]')?.addEventListener("click", () => {
|
|
180
|
+
void this.controllerValue?.refresh();
|
|
181
|
+
});
|
|
182
|
+
this.shadowRoot.querySelector('[part="clear-selection"]')?.addEventListener("click", () => {
|
|
183
|
+
this.controllerValue?.clearSelection();
|
|
184
|
+
});
|
|
185
|
+
toolbar?.addEventListener("keydown", event => {
|
|
186
|
+
const buttons = Array.from(this.shadowRoot?.querySelectorAll('[part="refresh"], [part="clear-selection"]') ?? []).filter(button => !button.disabled);
|
|
187
|
+
handleRovingKeydown(event, buttons, { orientation: "horizontal" });
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
update() {
|
|
191
|
+
if (!this.shadowRoot) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const state = this.controllerValue?.getState();
|
|
195
|
+
const loading = state?.loading ?? false;
|
|
196
|
+
const selectedCount = state?.selectedItemIds.length ?? 0;
|
|
197
|
+
const hasError = Boolean(state?.error);
|
|
198
|
+
const statusText = loading ? "loading" : hasError ? "failed" : "ready";
|
|
199
|
+
const searchQuery = state?.view.searchQuery ?? "";
|
|
200
|
+
const status = this.shadowRoot.querySelector('[part="status"]');
|
|
201
|
+
const selectionCount = this.shadowRoot.querySelector('[part="selection-count"]');
|
|
202
|
+
const refresh = this.shadowRoot.querySelector('[part="refresh"]');
|
|
203
|
+
const clearSelection = this.shadowRoot.querySelector('[part="clear-selection"]');
|
|
204
|
+
if (status) {
|
|
205
|
+
status.dataset.status = statusText;
|
|
206
|
+
status.textContent = statusText;
|
|
207
|
+
}
|
|
208
|
+
if (selectionCount) {
|
|
209
|
+
selectionCount.textContent = `${selectedCount} selected`;
|
|
210
|
+
}
|
|
211
|
+
if (refresh) {
|
|
212
|
+
refresh.disabled = loading;
|
|
213
|
+
}
|
|
214
|
+
if (clearSelection) {
|
|
215
|
+
clearSelection.disabled = selectedCount === 0;
|
|
216
|
+
}
|
|
217
|
+
this.syncSearchField(searchQuery, loading);
|
|
218
|
+
const activePart = this.shadowRoot.activeElement?.getAttribute("part") ?? null;
|
|
219
|
+
const buttons = Array.from(this.shadowRoot.querySelectorAll('[part="refresh"], [part="clear-selection"]')).filter(button => !button.disabled);
|
|
220
|
+
const restoreIndex = activePart
|
|
221
|
+
? buttons.findIndex(button => button.getAttribute("part") === activePart)
|
|
222
|
+
: -1;
|
|
223
|
+
applyRovingTabindex(buttons, restoreIndex >= 0 ? restoreIndex : 0);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
export const defineBoxExplorerToolbarElement = (tagName = DEFAULT_TAG_NAME) => {
|
|
227
|
+
defineBoxSearchFieldElement();
|
|
228
|
+
const existingElement = customElements.get(tagName);
|
|
229
|
+
if (existingElement) {
|
|
230
|
+
return existingElement;
|
|
231
|
+
}
|
|
232
|
+
customElements.define(tagName, BoxExplorerToolbarElement);
|
|
233
|
+
return BoxExplorerToolbarElement;
|
|
234
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ExplorerFetchLike, ExplorerItem, ExplorerTransport } from "./types.js";
|
|
2
|
+
interface BoxOwnedBy {
|
|
3
|
+
id?: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
type?: string;
|
|
6
|
+
}
|
|
7
|
+
interface BoxSharedLink {
|
|
8
|
+
url?: string;
|
|
9
|
+
access?: string;
|
|
10
|
+
effective_access?: string;
|
|
11
|
+
}
|
|
12
|
+
interface BoxPermissions {
|
|
13
|
+
can_download?: boolean;
|
|
14
|
+
can_preview?: boolean;
|
|
15
|
+
can_share?: boolean;
|
|
16
|
+
can_delete?: boolean;
|
|
17
|
+
can_rename?: boolean;
|
|
18
|
+
can_upload?: boolean;
|
|
19
|
+
}
|
|
20
|
+
interface BoxFolderItem {
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
type: string;
|
|
24
|
+
size?: number | null;
|
|
25
|
+
modified_at?: string | null;
|
|
26
|
+
created_at?: string | null;
|
|
27
|
+
extension?: string | null;
|
|
28
|
+
owned_by?: BoxOwnedBy | null;
|
|
29
|
+
shared_link?: BoxSharedLink | null;
|
|
30
|
+
permissions?: BoxPermissions | null;
|
|
31
|
+
parent?: {
|
|
32
|
+
id?: string;
|
|
33
|
+
name?: string;
|
|
34
|
+
type?: string;
|
|
35
|
+
} | null;
|
|
36
|
+
}
|
|
37
|
+
export interface BoxExplorerTransportOptions {
|
|
38
|
+
apiBaseUrl?: string;
|
|
39
|
+
fields?: string[];
|
|
40
|
+
fetch?: ExplorerFetchLike;
|
|
41
|
+
}
|
|
42
|
+
export declare const normalizeBoxExplorerItem: (entry: BoxFolderItem) => ExplorerItem | null;
|
|
43
|
+
export declare const createBoxExplorerTransport: (options?: BoxExplorerTransportOptions) => ExplorerTransport;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
const DEFAULT_API_BASE_URL = "https://api.box.com/2.0";
|
|
2
|
+
const DEFAULT_FIELDS = [
|
|
3
|
+
"id",
|
|
4
|
+
"name",
|
|
5
|
+
"type",
|
|
6
|
+
"size",
|
|
7
|
+
"modified_at",
|
|
8
|
+
"created_at",
|
|
9
|
+
"extension",
|
|
10
|
+
"owned_by",
|
|
11
|
+
"shared_link",
|
|
12
|
+
"permissions",
|
|
13
|
+
"parent",
|
|
14
|
+
];
|
|
15
|
+
const isSupportedItemType = (type) => type === "file" || type === "folder" || type === "web_link";
|
|
16
|
+
const mapOwner = (ownedBy) => {
|
|
17
|
+
if (ownedBy == null) {
|
|
18
|
+
return ownedBy === null ? null : undefined;
|
|
19
|
+
}
|
|
20
|
+
if (!ownedBy.id || !ownedBy.name) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
const type = ownedBy.type === "group" || ownedBy.type === "user" ? ownedBy.type : undefined;
|
|
24
|
+
return { id: ownedBy.id, name: ownedBy.name, ...(type ? { type } : {}) };
|
|
25
|
+
};
|
|
26
|
+
const mapPermissions = (permissions) => {
|
|
27
|
+
if (!permissions) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
...(typeof permissions.can_download === "boolean" ? { canDownload: permissions.can_download } : {}),
|
|
32
|
+
...(typeof permissions.can_preview === "boolean" ? { canPreview: permissions.can_preview } : {}),
|
|
33
|
+
...(typeof permissions.can_share === "boolean" ? { canShare: permissions.can_share } : {}),
|
|
34
|
+
...(typeof permissions.can_delete === "boolean" ? { canDelete: permissions.can_delete } : {}),
|
|
35
|
+
...(typeof permissions.can_rename === "boolean" ? { canRename: permissions.can_rename } : {}),
|
|
36
|
+
...(typeof permissions.can_upload === "boolean" ? { canUpload: permissions.can_upload } : {}),
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
const mapSharedLink = (sharedLink) => {
|
|
40
|
+
if (sharedLink === undefined) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
if (sharedLink === null || !sharedLink.url) {
|
|
44
|
+
return sharedLink === null ? null : { isShared: false };
|
|
45
|
+
}
|
|
46
|
+
const accessRaw = sharedLink.effective_access ?? sharedLink.access;
|
|
47
|
+
const access = accessRaw === "open" || accessRaw === "company" || accessRaw === "collaborators" ? accessRaw : undefined;
|
|
48
|
+
return {
|
|
49
|
+
isShared: true,
|
|
50
|
+
...(access ? { access } : {}),
|
|
51
|
+
url: sharedLink.url,
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
export const normalizeBoxExplorerItem = (entry) => {
|
|
55
|
+
if (!isSupportedItemType(entry.type)) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
const owner = mapOwner(entry.owned_by);
|
|
59
|
+
const permissions = mapPermissions(entry.permissions);
|
|
60
|
+
const sharedLink = mapSharedLink(entry.shared_link);
|
|
61
|
+
const parent = entry.parent?.id != null
|
|
62
|
+
? { id: entry.parent.id, ...(entry.parent.name ? { name: entry.parent.name } : {}) }
|
|
63
|
+
: entry.parent === null
|
|
64
|
+
? null
|
|
65
|
+
: undefined;
|
|
66
|
+
const item = {
|
|
67
|
+
id: entry.id,
|
|
68
|
+
name: entry.name,
|
|
69
|
+
type: entry.type,
|
|
70
|
+
};
|
|
71
|
+
if (entry.size !== undefined) {
|
|
72
|
+
item.size = entry.size;
|
|
73
|
+
}
|
|
74
|
+
if (entry.modified_at !== undefined) {
|
|
75
|
+
item.modifiedAt = entry.modified_at;
|
|
76
|
+
}
|
|
77
|
+
if (entry.created_at !== undefined) {
|
|
78
|
+
item.createdAt = entry.created_at;
|
|
79
|
+
}
|
|
80
|
+
if (entry.extension !== undefined) {
|
|
81
|
+
item.extension = entry.extension;
|
|
82
|
+
}
|
|
83
|
+
if (owner !== undefined) {
|
|
84
|
+
item.owner = owner;
|
|
85
|
+
}
|
|
86
|
+
if (permissions && Object.keys(permissions).length > 0) {
|
|
87
|
+
item.permissions = permissions;
|
|
88
|
+
}
|
|
89
|
+
if (sharedLink !== undefined) {
|
|
90
|
+
item.sharedLink = sharedLink;
|
|
91
|
+
}
|
|
92
|
+
if (entry.extension !== undefined || permissions?.canPreview !== undefined) {
|
|
93
|
+
item.preview = {
|
|
94
|
+
...(typeof permissions?.canPreview === "boolean" ? { canPreview: permissions.canPreview } : {}),
|
|
95
|
+
...(entry.extension !== undefined ? { extension: entry.extension } : {}),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
if (parent !== undefined) {
|
|
99
|
+
item.parent = parent;
|
|
100
|
+
}
|
|
101
|
+
return item;
|
|
102
|
+
};
|
|
103
|
+
const normalizeItems = (entries) => ({
|
|
104
|
+
entries: entries
|
|
105
|
+
.map(normalizeBoxExplorerItem)
|
|
106
|
+
.filter((entry) => entry !== null),
|
|
107
|
+
});
|
|
108
|
+
const normalizeFolder = (payload, folderId) => ({
|
|
109
|
+
id: payload.id ?? folderId,
|
|
110
|
+
name: payload.name ?? folderId,
|
|
111
|
+
type: "folder",
|
|
112
|
+
});
|
|
113
|
+
const normalizeBreadcrumbs = (payload, folder) => {
|
|
114
|
+
const parents = payload.path_collection?.entries?.filter((entry) => entry.type === "folder") ?? [];
|
|
115
|
+
return [...parents, folder];
|
|
116
|
+
};
|
|
117
|
+
const resolveFetch = (providedFetch) => {
|
|
118
|
+
if (providedFetch) {
|
|
119
|
+
return providedFetch;
|
|
120
|
+
}
|
|
121
|
+
if (typeof globalThis.fetch !== "function") {
|
|
122
|
+
throw new Error("A fetch implementation is required to use the Box explorer transport");
|
|
123
|
+
}
|
|
124
|
+
return globalThis.fetch.bind(globalThis);
|
|
125
|
+
};
|
|
126
|
+
const createFolderItemsUrl = (apiBaseUrl, folderId, fields, limit, offset) => {
|
|
127
|
+
const url = new URL(`${apiBaseUrl.replace(/\/$/, "")}/folders/${folderId}/items`);
|
|
128
|
+
url.searchParams.set("fields", fields.join(","));
|
|
129
|
+
if (typeof limit === "number") {
|
|
130
|
+
url.searchParams.set("limit", String(limit));
|
|
131
|
+
}
|
|
132
|
+
if (typeof offset === "number") {
|
|
133
|
+
url.searchParams.set("offset", String(offset));
|
|
134
|
+
}
|
|
135
|
+
return url.toString();
|
|
136
|
+
};
|
|
137
|
+
const createSearchUrl = (apiBaseUrl, query, fields, ancestorFolderId, limit, offset) => {
|
|
138
|
+
const url = new URL(`${apiBaseUrl.replace(/\/$/, "")}/search`);
|
|
139
|
+
url.searchParams.set("query", query);
|
|
140
|
+
url.searchParams.set("fields", fields.join(","));
|
|
141
|
+
if (ancestorFolderId) {
|
|
142
|
+
url.searchParams.set("ancestor_folder_ids", ancestorFolderId);
|
|
143
|
+
}
|
|
144
|
+
if (typeof limit === "number") {
|
|
145
|
+
url.searchParams.set("limit", String(limit));
|
|
146
|
+
}
|
|
147
|
+
if (typeof offset === "number") {
|
|
148
|
+
url.searchParams.set("offset", String(offset));
|
|
149
|
+
}
|
|
150
|
+
return url.toString();
|
|
151
|
+
};
|
|
152
|
+
const getErrorMessage = async (response) => {
|
|
153
|
+
try {
|
|
154
|
+
const payload = (await response.json());
|
|
155
|
+
if (payload.message) {
|
|
156
|
+
return payload.code ? `${payload.code}: ${payload.message}` : payload.message;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
// Ignore JSON parse issues and fall back to status text.
|
|
161
|
+
}
|
|
162
|
+
return `Box API request failed with status ${response.status}`;
|
|
163
|
+
};
|
|
164
|
+
const toPagination = (payload, rawEntriesLength, request) => {
|
|
165
|
+
const offset = payload.offset ?? request.offset ?? 0;
|
|
166
|
+
const limit = payload.limit ?? request.limit ?? rawEntriesLength;
|
|
167
|
+
const totalCount = payload.total_count ?? null;
|
|
168
|
+
const nextOffset = offset + rawEntriesLength;
|
|
169
|
+
return {
|
|
170
|
+
hasMoreItems: totalCount === null ? rawEntriesLength === limit : nextOffset < totalCount,
|
|
171
|
+
limit,
|
|
172
|
+
offset,
|
|
173
|
+
totalCount,
|
|
174
|
+
nextOffset,
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
export const createBoxExplorerTransport = (options = {}) => {
|
|
178
|
+
const apiBaseUrl = options.apiBaseUrl ?? DEFAULT_API_BASE_URL;
|
|
179
|
+
const fields = options.fields ?? DEFAULT_FIELDS;
|
|
180
|
+
const fetchImpl = resolveFetch(options.fetch);
|
|
181
|
+
return {
|
|
182
|
+
async loadFolderItems(request) {
|
|
183
|
+
const response = await fetchImpl(createFolderItemsUrl(apiBaseUrl, request.folderId, fields, request.limit, request.offset), {
|
|
184
|
+
headers: {
|
|
185
|
+
Authorization: `Bearer ${request.token}`,
|
|
186
|
+
"Accept-Language": request.language ?? "en-US",
|
|
187
|
+
},
|
|
188
|
+
method: "GET",
|
|
189
|
+
signal: request.signal,
|
|
190
|
+
});
|
|
191
|
+
if (!response.ok) {
|
|
192
|
+
throw new Error(await getErrorMessage(response));
|
|
193
|
+
}
|
|
194
|
+
const payload = (await response.json());
|
|
195
|
+
const rawEntries = payload.entries ?? [];
|
|
196
|
+
const { entries } = normalizeItems(rawEntries);
|
|
197
|
+
const folder = normalizeFolder(payload, request.folderId);
|
|
198
|
+
return {
|
|
199
|
+
breadcrumbs: normalizeBreadcrumbs(payload, folder),
|
|
200
|
+
folder,
|
|
201
|
+
folderId: request.folderId,
|
|
202
|
+
items: entries,
|
|
203
|
+
pagination: toPagination(payload, rawEntries.length, request),
|
|
204
|
+
};
|
|
205
|
+
},
|
|
206
|
+
async searchItems(request) {
|
|
207
|
+
const response = await fetchImpl(createSearchUrl(apiBaseUrl, request.query, fields, request.ancestorFolderId, request.limit, request.offset), {
|
|
208
|
+
headers: {
|
|
209
|
+
Authorization: `Bearer ${request.token}`,
|
|
210
|
+
"Accept-Language": request.language ?? "en-US",
|
|
211
|
+
},
|
|
212
|
+
method: "GET",
|
|
213
|
+
signal: request.signal,
|
|
214
|
+
});
|
|
215
|
+
if (!response.ok) {
|
|
216
|
+
throw new Error(await getErrorMessage(response));
|
|
217
|
+
}
|
|
218
|
+
const payload = (await response.json());
|
|
219
|
+
const rawEntries = payload.entries ?? [];
|
|
220
|
+
const { entries } = normalizeItems(rawEntries);
|
|
221
|
+
return {
|
|
222
|
+
query: request.query,
|
|
223
|
+
...(request.ancestorFolderId ? { ancestorFolderId: request.ancestorFolderId } : {}),
|
|
224
|
+
items: entries,
|
|
225
|
+
pagination: toPagination(payload, rawEntries.length, request),
|
|
226
|
+
};
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Controller } from "../../../core/controller.js";
|
|
2
|
+
import type { ExplorerItem, ExplorerPaginationState } from "../types.js";
|
|
3
|
+
import type { ExplorerCollectionControllerOptions, ExplorerCollectionEvents, ExplorerCollectionState } from "./types.js";
|
|
4
|
+
export interface ExplorerCollectionLoadResult {
|
|
5
|
+
items: ExplorerItem[];
|
|
6
|
+
pagination: ExplorerPaginationState;
|
|
7
|
+
}
|
|
8
|
+
export declare class ExplorerCollectionController extends Controller<ExplorerCollectionState, ExplorerCollectionEvents> {
|
|
9
|
+
private readonly options;
|
|
10
|
+
constructor(options?: ExplorerCollectionControllerOptions);
|
|
11
|
+
reset(): void;
|
|
12
|
+
setItems(items: ExplorerCollectionState["items"]): void;
|
|
13
|
+
startLoading(): void;
|
|
14
|
+
applyLoadResult(result: ExplorerCollectionLoadResult, append: boolean): void;
|
|
15
|
+
applyLoadFailure(): void;
|
|
16
|
+
canLoadNextPage(): boolean;
|
|
17
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Controller } from "../../../core/controller.js";
|
|
2
|
+
const DEFAULT_PAGE_SIZE = 100;
|
|
3
|
+
const createInitialPaginationState = (options = {}) => ({
|
|
4
|
+
hasMoreItems: false,
|
|
5
|
+
limit: options.pageSize ?? DEFAULT_PAGE_SIZE,
|
|
6
|
+
offset: 0,
|
|
7
|
+
totalCount: null,
|
|
8
|
+
});
|
|
9
|
+
const createInitialState = (options = {}) => ({
|
|
10
|
+
items: [],
|
|
11
|
+
loading: false,
|
|
12
|
+
pagination: createInitialPaginationState(options),
|
|
13
|
+
});
|
|
14
|
+
export class ExplorerCollectionController extends Controller {
|
|
15
|
+
options;
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
super(createInitialState(options));
|
|
18
|
+
this.options = options;
|
|
19
|
+
}
|
|
20
|
+
reset() {
|
|
21
|
+
this.setState(createInitialState(this.options));
|
|
22
|
+
this.emit("itemsChanged", { items: this.state.items });
|
|
23
|
+
this.emit("paginationChanged", { pagination: this.state.pagination });
|
|
24
|
+
this.emit("loadingChanged", { loading: this.state.loading });
|
|
25
|
+
}
|
|
26
|
+
setItems(items) {
|
|
27
|
+
this.setState({
|
|
28
|
+
...this.state,
|
|
29
|
+
items,
|
|
30
|
+
});
|
|
31
|
+
this.emit("itemsChanged", { items });
|
|
32
|
+
}
|
|
33
|
+
startLoading() {
|
|
34
|
+
if (this.state.loading) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
this.setState({
|
|
38
|
+
...this.state,
|
|
39
|
+
loading: true,
|
|
40
|
+
});
|
|
41
|
+
this.emit("loadingChanged", { loading: true });
|
|
42
|
+
}
|
|
43
|
+
applyLoadResult(result, append) {
|
|
44
|
+
const items = append ? [...this.state.items, ...result.items] : result.items;
|
|
45
|
+
this.setState({
|
|
46
|
+
items,
|
|
47
|
+
loading: false,
|
|
48
|
+
pagination: result.pagination,
|
|
49
|
+
});
|
|
50
|
+
this.emit("itemsChanged", { items });
|
|
51
|
+
this.emit("paginationChanged", { pagination: result.pagination });
|
|
52
|
+
this.emit("loadingChanged", { loading: false });
|
|
53
|
+
}
|
|
54
|
+
applyLoadFailure() {
|
|
55
|
+
if (!this.state.loading) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
this.setState({
|
|
59
|
+
...this.state,
|
|
60
|
+
loading: false,
|
|
61
|
+
});
|
|
62
|
+
this.emit("loadingChanged", { loading: false });
|
|
63
|
+
}
|
|
64
|
+
canLoadNextPage() {
|
|
65
|
+
return !this.state.loading && this.state.pagination.hasMoreItems;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ExplorerCollectionController } from "./controller.js";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ExplorerItem, ExplorerPaginationState } from "../types.js";
|
|
2
|
+
export interface ExplorerCollectionControllerOptions {
|
|
3
|
+
pageSize?: number;
|
|
4
|
+
}
|
|
5
|
+
export interface ExplorerCollectionState {
|
|
6
|
+
items: ExplorerItem[];
|
|
7
|
+
loading: boolean;
|
|
8
|
+
pagination: ExplorerPaginationState;
|
|
9
|
+
}
|
|
10
|
+
export interface ExplorerCollectionEvents {
|
|
11
|
+
itemsChanged: {
|
|
12
|
+
items: ExplorerItem[];
|
|
13
|
+
};
|
|
14
|
+
loadingChanged: {
|
|
15
|
+
loading: boolean;
|
|
16
|
+
};
|
|
17
|
+
paginationChanged: {
|
|
18
|
+
pagination: ExplorerPaginationState;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|