decantr 0.9.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/AGENTS.md +868 -0
- package/CHANGELOG.md +255 -0
- package/CLAUDE.md +178 -0
- package/LICENSE +21 -0
- package/README.md +229 -0
- package/cli/art.js +127 -0
- package/cli/commands/a11y.js +61 -0
- package/cli/commands/audit.js +225 -0
- package/cli/commands/build.js +38 -0
- package/cli/commands/dev.js +18 -0
- package/cli/commands/doctor.js +197 -0
- package/cli/commands/figma-sync.js +48 -0
- package/cli/commands/figma-tokens.js +55 -0
- package/cli/commands/generate.js +26 -0
- package/cli/commands/init.js +116 -0
- package/cli/commands/lint.js +209 -0
- package/cli/commands/mcp.js +530 -0
- package/cli/commands/migrate.js +175 -0
- package/cli/commands/test.js +38 -0
- package/cli/commands/validate.js +354 -0
- package/cli/index.js +113 -0
- package/package.json +95 -0
- package/reference/atoms.md +517 -0
- package/reference/behaviors.md +384 -0
- package/reference/build-tooling.md +275 -0
- package/reference/color-guidelines.md +965 -0
- package/reference/component-lifecycle.md +137 -0
- package/reference/compound-spacing.md +95 -0
- package/reference/decantation-process.md +499 -0
- package/reference/dev-server-routes.md +93 -0
- package/reference/form-system.md +253 -0
- package/reference/i18n.md +336 -0
- package/reference/icons.md +576 -0
- package/reference/llm-primer.md +953 -0
- package/reference/plugins.md +252 -0
- package/reference/registry-consumption.md +76 -0
- package/reference/router.md +217 -0
- package/reference/shells.md +116 -0
- package/reference/spatial-guidelines.md +541 -0
- package/reference/ssr.md +234 -0
- package/reference/state-data.md +215 -0
- package/reference/state-patterns.md +166 -0
- package/reference/state.md +194 -0
- package/reference/style-system.md +110 -0
- package/reference/tokens.md +460 -0
- package/src/app.js +19 -0
- package/src/chart/_animate.js +266 -0
- package/src/chart/_base.js +109 -0
- package/src/chart/_data.js +209 -0
- package/src/chart/_format.js +106 -0
- package/src/chart/_interact.js +364 -0
- package/src/chart/_palette.js +105 -0
- package/src/chart/_renderer.js +52 -0
- package/src/chart/_scene.js +262 -0
- package/src/chart/_shared.js +371 -0
- package/src/chart/index.js +637 -0
- package/src/chart/layouts/_layout-base.js +328 -0
- package/src/chart/layouts/cartesian.js +148 -0
- package/src/chart/layouts/hierarchy.js +562 -0
- package/src/chart/layouts/polar.js +101 -0
- package/src/chart/renderers/canvas.js +179 -0
- package/src/chart/renderers/svg.js +256 -0
- package/src/chart/renderers/webgpu.js +715 -0
- package/src/chart/types/_type-base.js +26 -0
- package/src/chart/types/area.js +134 -0
- package/src/chart/types/bar.js +173 -0
- package/src/chart/types/box-plot.js +125 -0
- package/src/chart/types/bubble.js +63 -0
- package/src/chart/types/candlestick.js +115 -0
- package/src/chart/types/chord.js +85 -0
- package/src/chart/types/combination.js +108 -0
- package/src/chart/types/funnel.js +68 -0
- package/src/chart/types/gauge.js +163 -0
- package/src/chart/types/heatmap.js +98 -0
- package/src/chart/types/histogram.js +71 -0
- package/src/chart/types/line.js +111 -0
- package/src/chart/types/org-chart.js +93 -0
- package/src/chart/types/pie.js +81 -0
- package/src/chart/types/radar.js +96 -0
- package/src/chart/types/radial.js +68 -0
- package/src/chart/types/range-area.js +55 -0
- package/src/chart/types/range-bar.js +61 -0
- package/src/chart/types/sankey.js +73 -0
- package/src/chart/types/scatter.js +66 -0
- package/src/chart/types/sparkline.js +81 -0
- package/src/chart/types/sunburst.js +69 -0
- package/src/chart/types/swimlane.js +88 -0
- package/src/chart/types/treemap.js +62 -0
- package/src/chart/types/waterfall.js +100 -0
- package/src/components/_base.js +1658 -0
- package/src/components/_behaviors.js +1140 -0
- package/src/components/_primitives.js +534 -0
- package/src/components/_qr-encoder.js +539 -0
- package/src/components/accordion.js +207 -0
- package/src/components/affix.js +62 -0
- package/src/components/alert-dialog.js +75 -0
- package/src/components/alert.js +47 -0
- package/src/components/aspect-ratio.js +24 -0
- package/src/components/avatar-group.js +55 -0
- package/src/components/avatar.js +38 -0
- package/src/components/back-top.js +75 -0
- package/src/components/badge.js +74 -0
- package/src/components/banner.js +68 -0
- package/src/components/breadcrumb.js +162 -0
- package/src/components/button.js +115 -0
- package/src/components/calendar.js +131 -0
- package/src/components/card.js +192 -0
- package/src/components/carousel.js +98 -0
- package/src/components/cascader.js +261 -0
- package/src/components/checkbox.js +80 -0
- package/src/components/chip.js +81 -0
- package/src/components/code-block.js +82 -0
- package/src/components/collapsible.js +50 -0
- package/src/components/color-palette.js +438 -0
- package/src/components/color-picker.js +314 -0
- package/src/components/combobox.js +181 -0
- package/src/components/command.js +174 -0
- package/src/components/comment.js +206 -0
- package/src/components/context-menu.js +76 -0
- package/src/components/data-table.js +724 -0
- package/src/components/date-picker.js +217 -0
- package/src/components/date-range-picker.js +244 -0
- package/src/components/datetime-picker.js +271 -0
- package/src/components/descriptions.js +68 -0
- package/src/components/drawer.js +179 -0
- package/src/components/dropdown.js +88 -0
- package/src/components/empty.js +41 -0
- package/src/components/float-button.js +90 -0
- package/src/components/form.js +106 -0
- package/src/components/hover-card.js +49 -0
- package/src/components/icon.js +87 -0
- package/src/components/image.js +97 -0
- package/src/components/index.js +117 -0
- package/src/components/input-group.js +75 -0
- package/src/components/input-number.js +155 -0
- package/src/components/input-otp.js +178 -0
- package/src/components/input.js +91 -0
- package/src/components/kbd.js +36 -0
- package/src/components/label.js +25 -0
- package/src/components/list.js +118 -0
- package/src/components/masked-input.js +236 -0
- package/src/components/mentions.js +165 -0
- package/src/components/menu.js +259 -0
- package/src/components/message.js +80 -0
- package/src/components/modal.js +147 -0
- package/src/components/navigation-menu.js +166 -0
- package/src/components/notification.js +84 -0
- package/src/components/pagination.js +104 -0
- package/src/components/placeholder.js +132 -0
- package/src/components/popconfirm.js +70 -0
- package/src/components/popover.js +58 -0
- package/src/components/progress.js +61 -0
- package/src/components/qrcode.js +251 -0
- package/src/components/radiogroup.js +120 -0
- package/src/components/range-slider.js +176 -0
- package/src/components/rate.js +186 -0
- package/src/components/resizable.js +83 -0
- package/src/components/result.js +57 -0
- package/src/components/scroll-area.js +43 -0
- package/src/components/segmented.js +97 -0
- package/src/components/select.js +165 -0
- package/src/components/separator.js +31 -0
- package/src/components/shell.js +407 -0
- package/src/components/skeleton.js +39 -0
- package/src/components/slider.js +141 -0
- package/src/components/sortable-list.js +176 -0
- package/src/components/space.js +42 -0
- package/src/components/spinner.js +112 -0
- package/src/components/splitter.js +147 -0
- package/src/components/statistic.js +136 -0
- package/src/components/steps.js +99 -0
- package/src/components/switch.js +95 -0
- package/src/components/table.js +44 -0
- package/src/components/tabs.js +216 -0
- package/src/components/tag.js +115 -0
- package/src/components/textarea.js +82 -0
- package/src/components/time-picker.js +153 -0
- package/src/components/time-range-picker.js +170 -0
- package/src/components/timeline.js +226 -0
- package/src/components/toast.js +71 -0
- package/src/components/toggle.js +213 -0
- package/src/components/tooltip.js +57 -0
- package/src/components/tour.js +159 -0
- package/src/components/transfer.js +163 -0
- package/src/components/tree-select.js +274 -0
- package/src/components/tree.js +141 -0
- package/src/components/typography.js +136 -0
- package/src/components/upload.js +118 -0
- package/src/components/visually-hidden.js +20 -0
- package/src/components/watermark.js +124 -0
- package/src/core/index.js +539 -0
- package/src/core/lifecycle.js +69 -0
- package/src/css/atoms.js +651 -0
- package/src/css/components.js +940 -0
- package/src/css/derive.js +1296 -0
- package/src/css/index.js +265 -0
- package/src/css/runtime.js +268 -0
- package/src/css/styles/addons/bioluminescent.js +93 -0
- package/src/css/styles/addons/clay.js +70 -0
- package/src/css/styles/addons/clean.js +57 -0
- package/src/css/styles/addons/command-center.js +143 -0
- package/src/css/styles/addons/dopamine.js +83 -0
- package/src/css/styles/addons/editorial.js +80 -0
- package/src/css/styles/addons/glassmorphism.js +99 -0
- package/src/css/styles/addons/liquid-glass.js +105 -0
- package/src/css/styles/addons/prismatic.js +100 -0
- package/src/css/styles/addons/retro.js +63 -0
- package/src/css/styles/auradecantism.js +96 -0
- package/src/css/theme-registry.js +444 -0
- package/src/data/entity.js +281 -0
- package/src/data/index.js +13 -0
- package/src/data/persist.js +225 -0
- package/src/data/query.js +839 -0
- package/src/data/realtime.js +299 -0
- package/src/data/url.js +177 -0
- package/src/data/worker.js +134 -0
- package/src/explorer/archetypes.js +243 -0
- package/src/explorer/atoms.js +228 -0
- package/src/explorer/charts.js +497 -0
- package/src/explorer/components.js +129 -0
- package/src/explorer/foundations.js +949 -0
- package/src/explorer/icons.js +178 -0
- package/src/explorer/patterns.js +247 -0
- package/src/explorer/recipes.js +194 -0
- package/src/explorer/shared/pattern-examples.js +1337 -0
- package/src/explorer/shared/showcase-renderer.js +958 -0
- package/src/explorer/shared/spec-table.js +41 -0
- package/src/explorer/shared/usage-links.js +87 -0
- package/src/explorer/shell-config.js +10 -0
- package/src/explorer/shells.js +551 -0
- package/src/explorer/styles.js +161 -0
- package/src/explorer/tokens.js +262 -0
- package/src/explorer/tools.js +525 -0
- package/src/form/index.js +804 -0
- package/src/i18n/index.js +251 -0
- package/src/icons/essential.js +479 -0
- package/src/icons/index.js +53 -0
- package/src/plugins/index.js +282 -0
- package/src/registry/archetypes/content-site.json +71 -0
- package/src/registry/archetypes/docs-explorer.json +23 -0
- package/src/registry/archetypes/ecommerce.json +104 -0
- package/src/registry/archetypes/financial-dashboard.json +77 -0
- package/src/registry/archetypes/index.json +41 -0
- package/src/registry/archetypes/portfolio.json +82 -0
- package/src/registry/archetypes/recipe-community.json +159 -0
- package/src/registry/archetypes/saas-dashboard.json +86 -0
- package/src/registry/architect/cross-cutting.json +45 -0
- package/src/registry/architect/domains/ecommerce.json +294 -0
- package/src/registry/architect/domains/financial-services.json +302 -0
- package/src/registry/architect/index.json +26 -0
- package/src/registry/architect/traits.json +379 -0
- package/src/registry/atoms.json +16 -0
- package/src/registry/chart-showcase.json +160 -0
- package/src/registry/chart.json +136 -0
- package/src/registry/components.json +8616 -0
- package/src/registry/core.json +216 -0
- package/src/registry/css.json +319 -0
- package/src/registry/data.json +135 -0
- package/src/registry/foundations.json +11 -0
- package/src/registry/icons.json +463 -0
- package/src/registry/index.json +101 -0
- package/src/registry/patterns/activity-feed.json +37 -0
- package/src/registry/patterns/article-content.json +27 -0
- package/src/registry/patterns/auth-form.json +37 -0
- package/src/registry/patterns/author-card.json +20 -0
- package/src/registry/patterns/card-grid.json +127 -0
- package/src/registry/patterns/category-nav.json +26 -0
- package/src/registry/patterns/chart-grid.json +36 -0
- package/src/registry/patterns/chat-interface.json +37 -0
- package/src/registry/patterns/checklist-card.json +55 -0
- package/src/registry/patterns/comparison-panel.json +27 -0
- package/src/registry/patterns/component-showcase.json +24 -0
- package/src/registry/patterns/contact-form.json +31 -0
- package/src/registry/patterns/cta-section.json +20 -0
- package/src/registry/patterns/data-table.json +37 -0
- package/src/registry/patterns/detail-header.json +83 -0
- package/src/registry/patterns/detail-panel.json +27 -0
- package/src/registry/patterns/explorer-shell.json +22 -0
- package/src/registry/patterns/filter-bar.json +33 -0
- package/src/registry/patterns/filter-sidebar.json +27 -0
- package/src/registry/patterns/form-sections.json +110 -0
- package/src/registry/patterns/goal-tracker.json +27 -0
- package/src/registry/patterns/hero.json +107 -0
- package/src/registry/patterns/index.json +47 -0
- package/src/registry/patterns/kpi-grid.json +36 -0
- package/src/registry/patterns/media-gallery.json +20 -0
- package/src/registry/patterns/order-history.json +20 -0
- package/src/registry/patterns/pagination.json +19 -0
- package/src/registry/patterns/photo-to-recipe.json +36 -0
- package/src/registry/patterns/pipeline-tracker.json +28 -0
- package/src/registry/patterns/post-list.json +27 -0
- package/src/registry/patterns/pricing-table.json +32 -0
- package/src/registry/patterns/scorecard.json +28 -0
- package/src/registry/patterns/search-bar.json +20 -0
- package/src/registry/patterns/specimen-grid.json +19 -0
- package/src/registry/patterns/stat-card.json +55 -0
- package/src/registry/patterns/stats-bar.json +55 -0
- package/src/registry/patterns/steps-card.json +55 -0
- package/src/registry/patterns/table-of-contents.json +19 -0
- package/src/registry/patterns/testimonials.json +21 -0
- package/src/registry/patterns/timeline.json +27 -0
- package/src/registry/patterns/token-inspector.json +21 -0
- package/src/registry/patterns/wizard.json +27 -0
- package/src/registry/recipe-auradecantism.json +69 -0
- package/src/registry/recipe-clean.json +65 -0
- package/src/registry/recipe-command-center.json +78 -0
- package/src/registry/router.json +73 -0
- package/src/registry/schema/README.md +197 -0
- package/src/registry/skeletons.json +259 -0
- package/src/registry/state.json +137 -0
- package/src/registry/tokens.json +40 -0
- package/src/router/hash.js +17 -0
- package/src/router/history.js +18 -0
- package/src/router/index.js +598 -0
- package/src/ssr/index.js +922 -0
- package/src/state/arrays.js +181 -0
- package/src/state/devtools.js +647 -0
- package/src/state/index.js +498 -0
- package/src/state/middleware.js +288 -0
- package/src/state/scheduler.js +206 -0
- package/src/state/store.js +300 -0
- package/src/tags/index.js +19 -0
- package/src/tannins/auth.js +396 -0
- package/src/test/dom.js +352 -0
- package/src/test/index.js +62 -0
- package/src/test/state.js +306 -0
- package/tools/a11y-audit.js +487 -0
- package/tools/analyzer.js +315 -0
- package/tools/audit.js +706 -0
- package/tools/builder.js +1422 -0
- package/tools/css-extract.js +188 -0
- package/tools/dev-server.js +316 -0
- package/tools/dts-gen.js +1260 -0
- package/tools/figma-components.js +329 -0
- package/tools/figma-patterns.js +516 -0
- package/tools/figma-plugin/code.js +453 -0
- package/tools/figma-plugin/manifest.json +14 -0
- package/tools/figma-plugin/ui.html +268 -0
- package/tools/figma-render.js +293 -0
- package/tools/figma-tokens.js +712 -0
- package/tools/figma-upload.js +318 -0
- package/tools/generate.js +738 -0
- package/tools/icons.js +133 -0
- package/tools/init-templates.js +265 -0
- package/tools/install-hooks.sh +5 -0
- package/tools/migrations/0.5.0.js +53 -0
- package/tools/migrations/0.6.0.js +95 -0
- package/tools/minify.js +170 -0
- package/tools/pre-commit +4 -0
- package/tools/registry.js +662 -0
- package/tools/reset-playground.js +61 -0
- package/tools/starter-templates/content-site/app.js +49 -0
- package/tools/starter-templates/content-site/essence.js +19 -0
- package/tools/starter-templates/content-site/pages.js +31 -0
- package/tools/starter-templates/ecommerce/app.js +50 -0
- package/tools/starter-templates/ecommerce/essence.js +19 -0
- package/tools/starter-templates/ecommerce/pages.js +31 -0
- package/tools/starter-templates/landing-page/app.js +38 -0
- package/tools/starter-templates/landing-page/essence.js +18 -0
- package/tools/starter-templates/landing-page/pages.js +21 -0
- package/tools/starter-templates/portfolio/app.js +45 -0
- package/tools/starter-templates/portfolio/essence.js +19 -0
- package/tools/starter-templates/portfolio/pages.js +33 -0
- package/tools/starter-templates/saas-dashboard/app.js +70 -0
- package/tools/starter-templates/saas-dashboard/essence.js +19 -0
- package/tools/starter-templates/saas-dashboard/pages.js +31 -0
- package/tools/verify-pack.js +203 -0
- package/types/chart.d.ts +77 -0
- package/types/components.d.ts +587 -0
- package/types/core.d.ts +89 -0
- package/types/css.d.ts +149 -0
- package/types/data.d.ts +238 -0
- package/types/form.d.ts +164 -0
- package/types/i18n.d.ts +51 -0
- package/types/icons.d.ts +27 -0
- package/types/index.d.ts +13 -0
- package/types/router.d.ts +116 -0
- package/types/ssr.d.ts +102 -0
- package/types/state.d.ts +83 -0
- package/types/tags.d.ts +62 -0
- package/types/tannins.d.ts +63 -0
- package/types/test.d.ts +48 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TreeSelect — Dropdown with hierarchical tree selection.
|
|
3
|
+
* Supports single/multiple selection, checkboxes, and search.
|
|
4
|
+
* Uses createFieldOverlay behavior.
|
|
5
|
+
*
|
|
6
|
+
* @module decantr/components/tree-select
|
|
7
|
+
*/
|
|
8
|
+
import { onDestroy } from '../core/index.js';
|
|
9
|
+
import { createEffect } from '../state/index.js';
|
|
10
|
+
import { tags } from '../tags/index.js';
|
|
11
|
+
import { injectBase, cx } from './_base.js';
|
|
12
|
+
import { caret, createCheckControl, createFormField } from './_behaviors.js';
|
|
13
|
+
import { applyFieldState, createFieldOverlay } from './_primitives.js';
|
|
14
|
+
|
|
15
|
+
const { div, button: buttonTag, span, input: inputTag } = tags;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {Object} [props]
|
|
19
|
+
* @param {{ value: string, label: string, disabled?: boolean, children?: Object[] }[]} [props.options]
|
|
20
|
+
* @param {string|Array<string>|Function} [props.value]
|
|
21
|
+
* @param {boolean} [props.multiple=false]
|
|
22
|
+
* @param {boolean} [props.checkable=false]
|
|
23
|
+
* @param {Function} [props.onchange]
|
|
24
|
+
* @param {string} [props.placeholder='Select']
|
|
25
|
+
* @param {boolean|Function} [props.disabled]
|
|
26
|
+
* @param {boolean|string|Function} [props.error]
|
|
27
|
+
* @param {boolean|string|Function} [props.success]
|
|
28
|
+
* @param {string} [props.variant='outlined'] - 'outlined'|'filled'|'ghost'
|
|
29
|
+
* @param {string} [props.size] - xs|sm|lg
|
|
30
|
+
* @param {string} [props.label]
|
|
31
|
+
* @param {string} [props.help]
|
|
32
|
+
* @param {boolean} [props.required]
|
|
33
|
+
* @param {string} [props.class]
|
|
34
|
+
* @returns {HTMLElement}
|
|
35
|
+
*/
|
|
36
|
+
export function TreeSelect(props = {}) {
|
|
37
|
+
injectBase();
|
|
38
|
+
const {
|
|
39
|
+
options = [], value, multiple = false, checkable = false,
|
|
40
|
+
onchange, placeholder = 'Select', disabled, error, success,
|
|
41
|
+
variant, size, label, help, required, class: cls
|
|
42
|
+
} = props;
|
|
43
|
+
|
|
44
|
+
const selected = new Set();
|
|
45
|
+
const expanded = new Set();
|
|
46
|
+
let searchText = '';
|
|
47
|
+
|
|
48
|
+
function parseValue(v) {
|
|
49
|
+
selected.clear();
|
|
50
|
+
if (!v) return;
|
|
51
|
+
const val = typeof v === 'function' ? v() : v;
|
|
52
|
+
if (Array.isArray(val)) val.forEach(s => selected.add(s));
|
|
53
|
+
else if (val) selected.add(val);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
parseValue(value);
|
|
57
|
+
|
|
58
|
+
function findLabel(nodes, val) {
|
|
59
|
+
for (const n of nodes) {
|
|
60
|
+
if (n.value === val) return n.label;
|
|
61
|
+
if (n.children) { const r = findLabel(n.children, val); if (r) return r; }
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function getDisplayText() {
|
|
67
|
+
if (!selected.size) return '';
|
|
68
|
+
return [...selected].map(v => findLabel(options, v) || v).join(', ');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Trigger
|
|
72
|
+
const displayEl = span({ class: 'd-treeselect-display' });
|
|
73
|
+
const arrowEl = caret('down', { class: 'd-treeselect-arrow' });
|
|
74
|
+
const trigger = buttonTag({
|
|
75
|
+
type: 'button',
|
|
76
|
+
class: cx('d-treeselect-trigger', 'd-select'),
|
|
77
|
+
'aria-haspopup': 'listbox',
|
|
78
|
+
'aria-expanded': 'false'
|
|
79
|
+
}, displayEl, arrowEl);
|
|
80
|
+
|
|
81
|
+
const panel = div({ class: 'd-treeselect-panel', role: 'tree' });
|
|
82
|
+
const wrap = div({ class: cx('d-treeselect', cls) }, trigger, panel);
|
|
83
|
+
|
|
84
|
+
applyFieldState(wrap, { error, success, disabled, variant, size });
|
|
85
|
+
|
|
86
|
+
function updateDisplay() {
|
|
87
|
+
const text = getDisplayText();
|
|
88
|
+
displayEl.textContent = text || placeholder;
|
|
89
|
+
if (!text) displayEl.classList.add('d-select-placeholder');
|
|
90
|
+
else displayEl.classList.remove('d-select-placeholder');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function emit() {
|
|
94
|
+
updateDisplay();
|
|
95
|
+
if (!onchange) return;
|
|
96
|
+
if (multiple || checkable) onchange([...selected]);
|
|
97
|
+
else onchange(selected.size ? [...selected][0] : null);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function selectNode(node) {
|
|
101
|
+
if (node.disabled) return;
|
|
102
|
+
if (multiple || checkable) {
|
|
103
|
+
if (selected.has(node.value)) selected.delete(node.value);
|
|
104
|
+
else selected.add(node.value);
|
|
105
|
+
} else {
|
|
106
|
+
selected.clear();
|
|
107
|
+
selected.add(node.value);
|
|
108
|
+
overlay.close();
|
|
109
|
+
}
|
|
110
|
+
emit();
|
|
111
|
+
renderTree();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function toggleExpand(node) {
|
|
115
|
+
if (expanded.has(node.value)) expanded.delete(node.value);
|
|
116
|
+
else expanded.add(node.value);
|
|
117
|
+
renderTree();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function matchesSearch(node) {
|
|
121
|
+
if (!searchText) return true;
|
|
122
|
+
const q = searchText.toLowerCase();
|
|
123
|
+
if (node.label.toLowerCase().includes(q)) return true;
|
|
124
|
+
if (node.children) return node.children.some(c => matchesSearch(c));
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function renderNode(node, depth) {
|
|
129
|
+
if (!matchesSearch(node)) return null;
|
|
130
|
+
|
|
131
|
+
const hasChildren = node.children && node.children.length;
|
|
132
|
+
const isExpanded = expanded.has(node.value);
|
|
133
|
+
const isSelected = selected.has(node.value);
|
|
134
|
+
|
|
135
|
+
const content = div({
|
|
136
|
+
class: cx('d-tree-node-content', isSelected && 'd-tree-node-selected'),
|
|
137
|
+
role: 'treeitem',
|
|
138
|
+
'aria-selected': String(isSelected),
|
|
139
|
+
'aria-expanded': hasChildren ? String(isExpanded) : undefined
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
for (let i = 0; i < depth; i++) {
|
|
143
|
+
content.appendChild(span({ class: 'd-tree-node-indent' }));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (hasChildren) {
|
|
147
|
+
const switcher = buttonTag({
|
|
148
|
+
type: 'button',
|
|
149
|
+
class: cx('d-tree-node-switcher', isExpanded && 'd-tree-node-switcher-open'),
|
|
150
|
+
'aria-label': isExpanded ? 'Collapse' : 'Expand',
|
|
151
|
+
tabindex: '-1'
|
|
152
|
+
}, caret('right', { size: '0.875em' }));
|
|
153
|
+
switcher.addEventListener('click', (e) => { e.stopPropagation(); toggleExpand(node); });
|
|
154
|
+
content.appendChild(switcher);
|
|
155
|
+
} else {
|
|
156
|
+
content.appendChild(span({ class: 'd-tree-node-indent' }));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (checkable) {
|
|
160
|
+
const { wrap: cbWrap, input: cb } = createCheckControl({
|
|
161
|
+
tabindex: '-1',
|
|
162
|
+
disabled: node.disabled ? '' : undefined
|
|
163
|
+
});
|
|
164
|
+
cb.checked = isSelected;
|
|
165
|
+
cb.addEventListener('change', (e) => { e.stopPropagation(); selectNode(node); });
|
|
166
|
+
content.appendChild(cbWrap);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
content.appendChild(span({ class: 'd-tree-node-label' }, node.label));
|
|
170
|
+
|
|
171
|
+
if (!checkable && !node.disabled) {
|
|
172
|
+
content.addEventListener('click', () => selectNode(node));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const wrapper = div({ class: 'd-tree-node' }, content);
|
|
176
|
+
|
|
177
|
+
if (hasChildren && isExpanded) {
|
|
178
|
+
const childContainer = div({ class: 'd-tree-children', role: 'group' });
|
|
179
|
+
node.children.forEach(child => {
|
|
180
|
+
const childEl = renderNode(child, depth + 1);
|
|
181
|
+
if (childEl) childContainer.appendChild(childEl);
|
|
182
|
+
});
|
|
183
|
+
wrapper.appendChild(childContainer);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return wrapper;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function renderTree() {
|
|
190
|
+
const existingSearch = panel.querySelector('.d-treeselect-search');
|
|
191
|
+
const hadFocus = existingSearch && document.activeElement === existingSearch;
|
|
192
|
+
const cursorPos = existingSearch ? existingSearch.selectionStart : 0;
|
|
193
|
+
|
|
194
|
+
panel.replaceChildren();
|
|
195
|
+
|
|
196
|
+
const searchInput = inputTag({
|
|
197
|
+
type: 'text',
|
|
198
|
+
class: 'd-treeselect-search',
|
|
199
|
+
placeholder: 'Search...',
|
|
200
|
+
'aria-label': 'Search options'
|
|
201
|
+
});
|
|
202
|
+
searchInput.value = searchText;
|
|
203
|
+
searchInput.addEventListener('input', (e) => {
|
|
204
|
+
searchText = e.target.value;
|
|
205
|
+
renderTree();
|
|
206
|
+
});
|
|
207
|
+
panel.appendChild(searchInput);
|
|
208
|
+
|
|
209
|
+
const treeWrap = div({ class: 'd-tree', role: 'tree' });
|
|
210
|
+
options.forEach(node => {
|
|
211
|
+
const el = renderNode(node, 0);
|
|
212
|
+
if (el) treeWrap.appendChild(el);
|
|
213
|
+
});
|
|
214
|
+
panel.appendChild(treeWrap);
|
|
215
|
+
|
|
216
|
+
if (hadFocus) {
|
|
217
|
+
requestAnimationFrame(() => {
|
|
218
|
+
searchInput.focus();
|
|
219
|
+
searchInput.setSelectionRange(cursorPos, cursorPos);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const overlay = createFieldOverlay(trigger, panel, {
|
|
225
|
+
matchWidth: false,
|
|
226
|
+
onOpen: () => { searchText = ''; wrap.classList.add('d-treeselect-open'); renderTree(); },
|
|
227
|
+
onClose: () => { searchText = ''; wrap.classList.remove('d-treeselect-open'); }
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
trigger.addEventListener('mousedown', (e) => {
|
|
231
|
+
e.preventDefault();
|
|
232
|
+
overlay.toggle();
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
trigger.addEventListener('keydown', (e) => {
|
|
236
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
237
|
+
e.preventDefault();
|
|
238
|
+
overlay.isOpen() ? overlay.close() : overlay.open();
|
|
239
|
+
} else if (e.key === 'ArrowDown') {
|
|
240
|
+
e.preventDefault();
|
|
241
|
+
if (!overlay.isOpen()) overlay.open();
|
|
242
|
+
} else if (e.key === 'Escape') {
|
|
243
|
+
overlay.close();
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
// Reactive disabled
|
|
248
|
+
if (typeof disabled === 'function') {
|
|
249
|
+
createEffect(() => {
|
|
250
|
+
const dis = disabled();
|
|
251
|
+
trigger.disabled = dis;
|
|
252
|
+
trigger.setAttribute('aria-disabled', String(!!dis));
|
|
253
|
+
});
|
|
254
|
+
} else if (disabled) {
|
|
255
|
+
trigger.disabled = true;
|
|
256
|
+
trigger.setAttribute('aria-disabled', 'true');
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Reactive value
|
|
260
|
+
if (typeof value === 'function') {
|
|
261
|
+
createEffect(() => { parseValue(value); updateDisplay(); });
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
onDestroy(() => { overlay.destroy(); });
|
|
265
|
+
|
|
266
|
+
updateDisplay();
|
|
267
|
+
|
|
268
|
+
if (label || help) {
|
|
269
|
+
const { wrapper } = createFormField(wrap, { label, error, help, required, success, variant, size });
|
|
270
|
+
return wrapper;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
return wrap;
|
|
274
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree — Hierarchical tree view with expand/collapse, checkboxes, and selection.
|
|
3
|
+
* Uses createDisclosure behavior for node expand/collapse.
|
|
4
|
+
*
|
|
5
|
+
* @module decantr/components/tree
|
|
6
|
+
*/
|
|
7
|
+
import { h } from '../core/index.js';
|
|
8
|
+
import { injectBase, cx } from './_base.js';
|
|
9
|
+
import { caret, createCheckControl } from './_behaviors.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {Object} TreeNode
|
|
13
|
+
* @property {string} key - Unique identifier
|
|
14
|
+
* @property {string} label
|
|
15
|
+
* @property {string|Node} [icon]
|
|
16
|
+
* @property {boolean} [disabled]
|
|
17
|
+
* @property {boolean} [isLeaf]
|
|
18
|
+
* @property {TreeNode[]} [children]
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {Object} [props]
|
|
23
|
+
* @param {TreeNode[]} [props.data]
|
|
24
|
+
* @param {string[]} [props.expandedKeys] - Initially expanded keys
|
|
25
|
+
* @param {string[]} [props.selectedKeys] - Selected keys
|
|
26
|
+
* @param {string[]} [props.checkedKeys] - Checked keys (requires checkable)
|
|
27
|
+
* @param {boolean} [props.checkable=false] - Show checkboxes
|
|
28
|
+
* @param {boolean} [props.selectable=true]
|
|
29
|
+
* @param {boolean} [props.defaultExpandAll=false]
|
|
30
|
+
* @param {Function} [props.onSelect] - Called with (selectedKeys, {node, selected})
|
|
31
|
+
* @param {Function} [props.onCheck] - Called with (checkedKeys, {node, checked})
|
|
32
|
+
* @param {Function} [props.onExpand] - Called with (expandedKeys, {node, expanded})
|
|
33
|
+
* @param {string} [props.class]
|
|
34
|
+
* @returns {HTMLElement}
|
|
35
|
+
*/
|
|
36
|
+
export function Tree(props = {}) {
|
|
37
|
+
injectBase();
|
|
38
|
+
const { data = [], expandedKeys: initExpanded = [], selectedKeys: initSelected = [], checkedKeys: initChecked = [], checkable = false, selectable = true, defaultExpandAll = false, onSelect, onCheck, onExpand, class: cls } = props;
|
|
39
|
+
|
|
40
|
+
const expanded = new Set(initExpanded);
|
|
41
|
+
const selected = new Set(initSelected);
|
|
42
|
+
const checked = new Set(initChecked);
|
|
43
|
+
|
|
44
|
+
if (defaultExpandAll) {
|
|
45
|
+
const collectKeys = (nodes) => { nodes.forEach(n => { if (n.children?.length) { expanded.add(n.key); collectKeys(n.children); } }); };
|
|
46
|
+
collectKeys(data);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const tree = h('div', { class: cx('d-tree', cls), role: 'tree' });
|
|
50
|
+
|
|
51
|
+
function renderNode(node, depth) {
|
|
52
|
+
const hasChildren = node.children && node.children.length;
|
|
53
|
+
const isExpanded = expanded.has(node.key);
|
|
54
|
+
const isSelected = selected.has(node.key);
|
|
55
|
+
const isChecked = checked.has(node.key);
|
|
56
|
+
|
|
57
|
+
const nodeEl = h('div', { class: cx('d-tree-node', isSelected && 'd-tree-node-selected'), role: 'treeitem', 'aria-expanded': hasChildren ? String(isExpanded) : undefined });
|
|
58
|
+
|
|
59
|
+
const content = h('div', { class: 'd-tree-node-content' });
|
|
60
|
+
|
|
61
|
+
// Indent
|
|
62
|
+
for (let i = 0; i < depth; i++) {
|
|
63
|
+
content.appendChild(h('span', { class: 'd-tree-node-indent' }));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Switcher
|
|
67
|
+
if (hasChildren) {
|
|
68
|
+
const switcher = h('button', {
|
|
69
|
+
type: 'button',
|
|
70
|
+
class: cx('d-tree-node-switcher', isExpanded && 'd-tree-node-switcher-open'),
|
|
71
|
+
'aria-label': isExpanded ? 'Collapse' : 'Expand'
|
|
72
|
+
}, caret('right'));
|
|
73
|
+
switcher.addEventListener('click', (e) => {
|
|
74
|
+
e.stopPropagation();
|
|
75
|
+
if (expanded.has(node.key)) expanded.delete(node.key);
|
|
76
|
+
else expanded.add(node.key);
|
|
77
|
+
render();
|
|
78
|
+
if (onExpand) onExpand([...expanded], { node, expanded: expanded.has(node.key) });
|
|
79
|
+
});
|
|
80
|
+
content.appendChild(switcher);
|
|
81
|
+
} else {
|
|
82
|
+
content.appendChild(h('span', { class: 'd-tree-node-indent' }));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Checkbox
|
|
86
|
+
if (checkable) {
|
|
87
|
+
const { wrap: cbWrap, input: cb } = createCheckControl({
|
|
88
|
+
disabled: node.disabled ? '' : undefined
|
|
89
|
+
});
|
|
90
|
+
cb.checked = isChecked;
|
|
91
|
+
cb.addEventListener('change', (e) => {
|
|
92
|
+
e.stopPropagation();
|
|
93
|
+
if (cb.checked) checked.add(node.key);
|
|
94
|
+
else checked.delete(node.key);
|
|
95
|
+
if (onCheck) onCheck([...checked], { node, checked: cb.checked });
|
|
96
|
+
});
|
|
97
|
+
content.appendChild(cbWrap);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Icon
|
|
101
|
+
if (node.icon) {
|
|
102
|
+
const icon = typeof node.icon === 'string'
|
|
103
|
+
? h('span', { 'aria-hidden': 'true' }, node.icon)
|
|
104
|
+
: node.icon;
|
|
105
|
+
content.appendChild(icon);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Label
|
|
109
|
+
const label = h('span', { class: 'd-tree-node-label' }, node.label);
|
|
110
|
+
content.appendChild(label);
|
|
111
|
+
|
|
112
|
+
// Selection
|
|
113
|
+
if (selectable && !node.disabled) {
|
|
114
|
+
content.addEventListener('click', () => {
|
|
115
|
+
if (selected.has(node.key)) selected.delete(node.key);
|
|
116
|
+
else { selected.clear(); selected.add(node.key); }
|
|
117
|
+
render();
|
|
118
|
+
if (onSelect) onSelect([...selected], { node, selected: selected.has(node.key) });
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
nodeEl.appendChild(content);
|
|
123
|
+
|
|
124
|
+
// Children
|
|
125
|
+
if (hasChildren && isExpanded) {
|
|
126
|
+
const childContainer = h('div', { class: 'd-tree-children', role: 'group' });
|
|
127
|
+
node.children.forEach(child => childContainer.appendChild(renderNode(child, depth + 1)));
|
|
128
|
+
nodeEl.appendChild(childContainer);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return nodeEl;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function render() {
|
|
135
|
+
tree.replaceChildren();
|
|
136
|
+
data.forEach(node => tree.appendChild(renderNode(node, 0)));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
render();
|
|
140
|
+
return tree;
|
|
141
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typography — Title, Text, Paragraph, Link, Blockquote.
|
|
3
|
+
* Semantic text components with consistent token-based sizing.
|
|
4
|
+
*
|
|
5
|
+
* @module decantr/components/typography
|
|
6
|
+
*/
|
|
7
|
+
import { h } from '../core/index.js';
|
|
8
|
+
import { injectBase, cx } from './_base.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Title — Heading element (h1-h5) with consistent styling.
|
|
12
|
+
* @param {Object} [props]
|
|
13
|
+
* @param {1|2|3|4|5} [props.level=3] - Heading level (1-5)
|
|
14
|
+
* @param {string} [props.type] - secondary|success|warning|danger
|
|
15
|
+
* @param {boolean} [props.mark]
|
|
16
|
+
* @param {boolean} [props.underline]
|
|
17
|
+
* @param {boolean} [props.strikethrough]
|
|
18
|
+
* @param {boolean} [props.disabled]
|
|
19
|
+
* @param {string} [props.class]
|
|
20
|
+
* @param {...(string|Node)} children
|
|
21
|
+
* @returns {HTMLElement}
|
|
22
|
+
*/
|
|
23
|
+
export function Title(props = {}, ...children) {
|
|
24
|
+
injectBase();
|
|
25
|
+
const { level = 3, type, mark, underline, strikethrough, disabled, class: cls, ...rest } = props;
|
|
26
|
+
const tag = `h${Math.max(1, Math.min(5, level))}`;
|
|
27
|
+
const className = cx(
|
|
28
|
+
'd-title',
|
|
29
|
+
`d-title-${level}`,
|
|
30
|
+
type && `d-text-${type}`,
|
|
31
|
+
disabled && 'd-text-disabled',
|
|
32
|
+
cls
|
|
33
|
+
);
|
|
34
|
+
let content = children;
|
|
35
|
+
if (mark) content = [h('mark', { class: 'd-text-mark' }, ...content)];
|
|
36
|
+
if (underline) content = [h('u', null, ...content)];
|
|
37
|
+
if (strikethrough) content = [h('s', null, ...content)];
|
|
38
|
+
return h(tag, { class: className, ...rest }, ...content);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Text — Inline text with semantic variants.
|
|
43
|
+
* @param {Object} [props]
|
|
44
|
+
* @param {string} [props.type] - secondary|success|warning|danger
|
|
45
|
+
* @param {boolean} [props.strong]
|
|
46
|
+
* @param {boolean} [props.italic]
|
|
47
|
+
* @param {boolean} [props.underline]
|
|
48
|
+
* @param {boolean} [props.strikethrough]
|
|
49
|
+
* @param {boolean} [props.code]
|
|
50
|
+
* @param {boolean} [props.keyboard]
|
|
51
|
+
* @param {boolean} [props.mark]
|
|
52
|
+
* @param {boolean} [props.disabled]
|
|
53
|
+
* @param {string} [props.class]
|
|
54
|
+
* @param {...(string|Node)} children
|
|
55
|
+
* @returns {HTMLElement}
|
|
56
|
+
*/
|
|
57
|
+
export function Text(props = {}, ...children) {
|
|
58
|
+
injectBase();
|
|
59
|
+
const { type, strong, italic, underline, strikethrough, code, keyboard, mark, disabled, class: cls, ...rest } = props;
|
|
60
|
+
|
|
61
|
+
if (code) return h('code', { class: cx('d-text-code', type && `d-text-${type}`, cls), ...rest }, ...children);
|
|
62
|
+
if (keyboard) return h('kbd', { class: cx('d-kbd', cls), ...rest }, ...children);
|
|
63
|
+
|
|
64
|
+
const className = cx(
|
|
65
|
+
'd-text',
|
|
66
|
+
type && `d-text-${type}`,
|
|
67
|
+
strong && 'd-text-strong',
|
|
68
|
+
italic && 'd-text-italic',
|
|
69
|
+
underline && 'd-text-underline',
|
|
70
|
+
strikethrough && 'd-text-strikethrough',
|
|
71
|
+
disabled && 'd-text-disabled',
|
|
72
|
+
cls
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
let content = children;
|
|
76
|
+
if (mark) content = [h('mark', { class: 'd-text-mark' }, ...content)];
|
|
77
|
+
|
|
78
|
+
return h('span', { class: className, ...rest }, ...content);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Paragraph — Block-level text with relaxed line-height.
|
|
83
|
+
* @param {Object} [props]
|
|
84
|
+
* @param {string} [props.type] - secondary|success|warning|danger
|
|
85
|
+
* @param {boolean} [props.strong]
|
|
86
|
+
* @param {boolean} [props.italic]
|
|
87
|
+
* @param {string} [props.class]
|
|
88
|
+
* @param {...(string|Node)} children
|
|
89
|
+
* @returns {HTMLElement}
|
|
90
|
+
*/
|
|
91
|
+
export function Paragraph(props = {}, ...children) {
|
|
92
|
+
injectBase();
|
|
93
|
+
const { type, strong, italic, class: cls, ...rest } = props;
|
|
94
|
+
const className = cx(
|
|
95
|
+
'd-paragraph',
|
|
96
|
+
type && `d-text-${type}`,
|
|
97
|
+
strong && 'd-text-strong',
|
|
98
|
+
italic && 'd-text-italic',
|
|
99
|
+
cls
|
|
100
|
+
);
|
|
101
|
+
return h('p', { class: className, ...rest }, ...children);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Link — Anchor element with consistent styling.
|
|
106
|
+
* @param {Object} [props]
|
|
107
|
+
* @param {string} [props.href]
|
|
108
|
+
* @param {string} [props.target]
|
|
109
|
+
* @param {string} [props.type] - secondary|success|warning|danger
|
|
110
|
+
* @param {boolean} [props.disabled]
|
|
111
|
+
* @param {string} [props.class]
|
|
112
|
+
* @param {...(string|Node)} children
|
|
113
|
+
* @returns {HTMLElement}
|
|
114
|
+
*/
|
|
115
|
+
export function Link(props = {}, ...children) {
|
|
116
|
+
injectBase();
|
|
117
|
+
const { href, target, type, disabled, class: cls, ...rest } = props;
|
|
118
|
+
const className = cx('d-link', type && `d-text-${type}`, disabled && 'd-text-disabled', cls);
|
|
119
|
+
const el = h('a', { class: className, href, target, ...rest }, ...children);
|
|
120
|
+
if (target === '_blank') el.setAttribute('rel', 'noopener noreferrer');
|
|
121
|
+
if (disabled) { el.setAttribute('aria-disabled', 'true'); el.setAttribute('tabindex', '-1'); }
|
|
122
|
+
return el;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Blockquote — Styled quotation block.
|
|
127
|
+
* @param {Object} [props]
|
|
128
|
+
* @param {string} [props.class]
|
|
129
|
+
* @param {...(string|Node)} children
|
|
130
|
+
* @returns {HTMLElement}
|
|
131
|
+
*/
|
|
132
|
+
export function Blockquote(props = {}, ...children) {
|
|
133
|
+
injectBase();
|
|
134
|
+
const { class: cls, ...rest } = props;
|
|
135
|
+
return h('blockquote', { class: cx('d-blockquote', cls), ...rest }, ...children);
|
|
136
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Upload — File upload with drag-and-drop, file list, and progress.
|
|
3
|
+
*
|
|
4
|
+
* @module decantr/components/upload
|
|
5
|
+
*/
|
|
6
|
+
import { h } from '../core/index.js';
|
|
7
|
+
import { injectBase, cx } from './_base.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {Object} [props]
|
|
11
|
+
* @param {boolean} [props.multiple=false]
|
|
12
|
+
* @param {string} [props.accept] - File type filter (e.g. 'image/*,.pdf')
|
|
13
|
+
* @param {boolean} [props.drag=false] - Enable drag-and-drop zone
|
|
14
|
+
* @param {number} [props.maxSize] - Max file size in bytes
|
|
15
|
+
* @param {number} [props.maxCount] - Max number of files
|
|
16
|
+
* @param {Function} [props.onchange] - Called with FileList
|
|
17
|
+
* @param {Function} [props.onRemove] - Called with file on remove
|
|
18
|
+
* @param {Function} [props.customRequest] - Custom upload handler (file) => void
|
|
19
|
+
* @param {boolean|Function} [props.disabled]
|
|
20
|
+
* @param {string} [props.class]
|
|
21
|
+
* @param {...Node} children - Custom trigger content (for drag mode, shown inside drop zone)
|
|
22
|
+
* @returns {HTMLElement}
|
|
23
|
+
*/
|
|
24
|
+
export function Upload(props = {}, ...children) {
|
|
25
|
+
injectBase();
|
|
26
|
+
const { multiple = false, accept, drag = false, maxSize, maxCount, onchange, onRemove, customRequest, disabled, class: cls } = props;
|
|
27
|
+
|
|
28
|
+
const files = [];
|
|
29
|
+
const fileInput = h('input', {
|
|
30
|
+
type: 'file',
|
|
31
|
+
class: 'd-upload-input',
|
|
32
|
+
multiple: multiple ? '' : undefined,
|
|
33
|
+
accept
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const fileList = h('div', { class: 'd-upload-list' });
|
|
37
|
+
const container = h('div', { class: cx('d-upload', cls) });
|
|
38
|
+
|
|
39
|
+
function addFiles(newFiles) {
|
|
40
|
+
for (const file of newFiles) {
|
|
41
|
+
if (maxSize && file.size > maxSize) continue;
|
|
42
|
+
if (maxCount && files.length >= maxCount) break;
|
|
43
|
+
files.push(file);
|
|
44
|
+
renderFileItem(file);
|
|
45
|
+
if (customRequest) customRequest(file);
|
|
46
|
+
}
|
|
47
|
+
if (onchange) onchange([...files]);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function removeFile(file) {
|
|
51
|
+
const idx = files.indexOf(file);
|
|
52
|
+
if (idx >= 0) files.splice(idx, 1);
|
|
53
|
+
renderFileList();
|
|
54
|
+
if (onRemove) onRemove(file);
|
|
55
|
+
if (onchange) onchange([...files]);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function renderFileItem(file) {
|
|
59
|
+
const item = h('div', { class: 'd-upload-item' });
|
|
60
|
+
item.appendChild(h('span', { class: 'd-upload-item-name' }, file.name));
|
|
61
|
+
const removeBtn = h('button', { type: 'button', class: 'd-upload-item-remove', 'aria-label': `Remove ${file.name}` }, '\u00d7');
|
|
62
|
+
removeBtn.addEventListener('click', () => removeFile(file));
|
|
63
|
+
item.appendChild(removeBtn);
|
|
64
|
+
fileList.appendChild(item);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function renderFileList() {
|
|
68
|
+
fileList.replaceChildren();
|
|
69
|
+
files.forEach(renderFileItem);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
fileInput.addEventListener('change', () => {
|
|
73
|
+
if (fileInput.files.length) addFiles(fileInput.files);
|
|
74
|
+
fileInput.value = '';
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
if (drag) {
|
|
78
|
+
const dragger = h('div', { class: 'd-upload-dragger' },
|
|
79
|
+
...children.length ? children : [h('span', null, 'Click or drag files here')]
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
dragger.addEventListener('click', () => {
|
|
83
|
+
if (typeof disabled === 'function' ? disabled() : disabled) return;
|
|
84
|
+
fileInput.click();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
dragger.addEventListener('dragover', (e) => {
|
|
88
|
+
e.preventDefault();
|
|
89
|
+
dragger.classList.add('d-upload-dragger-active');
|
|
90
|
+
});
|
|
91
|
+
dragger.addEventListener('dragleave', () => {
|
|
92
|
+
dragger.classList.remove('d-upload-dragger-active');
|
|
93
|
+
});
|
|
94
|
+
dragger.addEventListener('drop', (e) => {
|
|
95
|
+
e.preventDefault();
|
|
96
|
+
dragger.classList.remove('d-upload-dragger-active');
|
|
97
|
+
if (e.dataTransfer.files.length) addFiles(e.dataTransfer.files);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
container.appendChild(fileInput);
|
|
101
|
+
container.appendChild(dragger);
|
|
102
|
+
} else {
|
|
103
|
+
const triggerBtn = children.length
|
|
104
|
+
? h('div', { class: 'd-upload-trigger' }, ...children)
|
|
105
|
+
: h('button', { type: 'button', class: 'd-btn d-btn-default' }, 'Upload');
|
|
106
|
+
|
|
107
|
+
triggerBtn.addEventListener('click', () => {
|
|
108
|
+
if (typeof disabled === 'function' ? disabled() : disabled) return;
|
|
109
|
+
fileInput.click();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
container.appendChild(fileInput);
|
|
113
|
+
container.appendChild(triggerBtn);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
container.appendChild(fileList);
|
|
117
|
+
return container;
|
|
118
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VisuallyHidden — Screen-reader-only content wrapper.
|
|
3
|
+
* Renders content that is visually hidden but accessible to assistive technology.
|
|
4
|
+
*
|
|
5
|
+
* @module decantr/components/visually-hidden
|
|
6
|
+
*/
|
|
7
|
+
import { h } from '../core/index.js';
|
|
8
|
+
import { injectBase, cx } from './_base.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {Object} [props]
|
|
12
|
+
* @param {string} [props.class]
|
|
13
|
+
* @param {...Node} children
|
|
14
|
+
* @returns {HTMLElement}
|
|
15
|
+
*/
|
|
16
|
+
export function VisuallyHidden(props = {}, ...children) {
|
|
17
|
+
injectBase();
|
|
18
|
+
const { class: cls, ...rest } = props;
|
|
19
|
+
return h('span', { class: cx('d-sr-only', cls), ...rest }, ...children);
|
|
20
|
+
}
|