soma-kit 0.0.0-stage → 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/README.md +539 -2
- package/bin/soma-kit.mjs +27 -0
- package/package.json +66 -4
- package/packs/ai/agent-run-card.ts +64 -0
- package/packs/ai/evaluation-card.ts +51 -0
- package/packs/ai/guardrail-policy-card.ts +48 -0
- package/packs/ai/index.ts +31 -0
- package/packs/ai/model-card.ts +55 -0
- package/packs/ai/model-routing-card.ts +49 -0
- package/packs/ai/prompt-template-card.ts +49 -0
- package/packs/ai/texts.ts +19 -0
- package/packs/commerce/address-card.ts +58 -0
- package/packs/commerce/coupon-card.ts +64 -0
- package/packs/commerce/index.ts +25 -0
- package/packs/commerce/order-card.ts +60 -0
- package/packs/commerce/purchase-order-card.ts +74 -0
- package/packs/commerce/texts.ts +14 -0
- package/packs/finance/index.ts +30 -0
- package/packs/finance/invoice-summary-card.ts +48 -0
- package/packs/finance/reconcile-board.ts +450 -0
- package/packs/finance/reconcile-case-card.ts +70 -0
- package/packs/finance/reconcile-desk/compile.ts +208 -0
- package/packs/finance/reconcile-desk/index.ts +20 -0
- package/packs/finance/reconcile-desk/shell.ts +27 -0
- package/packs/finance/texts.ts +21 -0
- package/packs/ops/change-window-card.ts +54 -0
- package/packs/ops/dependency-status-card.ts +50 -0
- package/packs/ops/error-budget-card.ts +60 -0
- package/packs/ops/execution-task-runner.ts +61 -0
- package/packs/ops/index.ts +36 -0
- package/packs/ops/integration-status-card.ts +45 -0
- package/packs/ops/release-readiness-card.ts +63 -0
- package/packs/ops/runbook-execution-card.ts +81 -0
- package/packs/ops/texts.ts +21 -0
- package/packs/security/control-evidence-card.ts +54 -0
- package/packs/security/finding-card.ts +96 -0
- package/packs/security/index.ts +29 -0
- package/packs/security/texts.ts +31 -0
- package/packs/shared/card-util.ts +60 -0
- package/packs/shared/wrap.ts +13 -0
- package/spec/generated/kit-app.schema.json +84 -0
- package/spec/generated/kit-page.schema.json +2766 -0
- package/spec/kit-grammar.json +1358 -0
- package/spec/kit-grammar.schema.json +716 -0
- package/src/app/app-config.ts +108 -0
- package/src/app/compose-apps.ts +139 -0
- package/src/app/define-kit-actions.ts +89 -0
- package/src/app/define-kit-app.ts +362 -0
- package/src/app/define-kit-pack.ts +114 -0
- package/src/app/envelope.ts +117 -0
- package/src/app/index.ts +50 -0
- package/src/app/notify-renderer.ts +114 -0
- package/src/app/paged-list-adapter.ts +246 -0
- package/src/app/server-pages.ts +303 -0
- package/src/app/server.ts +244 -0
- package/src/app/submit.types.ts +87 -0
- package/src/base/action-busy.ts +159 -0
- package/src/base/action-gate.ts +267 -0
- package/src/base/action-status.ts +31 -0
- package/src/base/alert.ts +136 -0
- package/src/base/avatar.ts +271 -0
- package/src/base/button.ts +139 -0
- package/src/base/cascader.ts +523 -0
- package/src/base/check-core.ts +214 -0
- package/src/base/checkbox.ts +35 -0
- package/src/base/choice.ts +183 -0
- package/src/base/color-picker.ts +316 -0
- package/src/base/combobox.ts +61 -0
- package/src/base/command-palette.ts +371 -0
- package/src/base/context-menu.ts +103 -0
- package/src/base/countdown.ts +168 -0
- package/src/base/date-range.ts +444 -0
- package/src/base/date.ts +899 -0
- package/src/base/divider.ts +156 -0
- package/src/base/fab.ts +192 -0
- package/src/base/icons.ts +106 -0
- package/src/base/image.ts +177 -0
- package/src/base/index.ts +214 -0
- package/src/base/input.ts +316 -0
- package/src/base/kbd.ts +99 -0
- package/src/base/link.ts +167 -0
- package/src/base/listbox-core.ts +965 -0
- package/src/base/mentions.ts +323 -0
- package/src/base/menu-button.ts +240 -0
- package/src/base/menu-core.ts +341 -0
- package/src/base/month-grid.ts +171 -0
- package/src/base/motion/aura.ts +94 -0
- package/src/base/motion/hover-3d.ts +154 -0
- package/src/base/motion/hover-gallery.ts +185 -0
- package/src/base/motion/index.ts +27 -0
- package/src/base/motion/limits.ts +75 -0
- package/src/base/motion/marquee.ts +157 -0
- package/src/base/motion/text-rotate.ts +195 -0
- package/src/base/number.ts +121 -0
- package/src/base/otp.ts +259 -0
- package/src/base/permission-gate.ts +99 -0
- package/src/base/popover.ts +352 -0
- package/src/base/popup.ts +542 -0
- package/src/base/portal-core.ts +297 -0
- package/src/base/price-text.ts +126 -0
- package/src/base/progress.ts +216 -0
- package/src/base/qr-code.ts +446 -0
- package/src/base/qty-stepper.ts +241 -0
- package/src/base/radio.ts +33 -0
- package/src/base/range.ts +444 -0
- package/src/base/rating.ts +249 -0
- package/src/base/segmented.ts +286 -0
- package/src/base/select.ts +57 -0
- package/src/base/shared.ts +708 -0
- package/src/base/swap.ts +86 -0
- package/src/base/switch.ts +111 -0
- package/src/base/tag-input.ts +464 -0
- package/src/base/tag.ts +250 -0
- package/src/base/text.ts +126 -0
- package/src/base/textarea.ts +129 -0
- package/src/base/time-picker.ts +606 -0
- package/src/base/tree-select.ts +629 -0
- package/src/base/upload.ts +548 -0
- package/src/base/virtual-list.ts +286 -0
- package/src/biz/approval-desk/compile.ts +179 -0
- package/src/biz/approval-desk/index.ts +21 -0
- package/src/biz/approval-desk/shell.ts +50 -0
- package/src/biz/auth-panel/compile.ts +196 -0
- package/src/biz/auth-panel/index.ts +24 -0
- package/src/biz/auth-panel/shell.ts +46 -0
- package/src/biz/category-crud/compile.ts +173 -0
- package/src/biz/category-crud/index.ts +19 -0
- package/src/biz/category-crud/shell.ts +29 -0
- package/src/biz/checkout-page/compile.ts +111 -0
- package/src/biz/checkout-page/index.ts +20 -0
- package/src/biz/checkout-page/shell.ts +50 -0
- package/src/biz/compose.ts +313 -0
- package/src/biz/data-components.ts +26 -0
- package/src/biz/define.ts +23 -0
- package/src/biz/import-wizard/compile.ts +204 -0
- package/src/biz/import-wizard/hub.ts +540 -0
- package/src/biz/import-wizard/index.ts +24 -0
- package/src/biz/import-wizard/shell.ts +161 -0
- package/src/biz/index.ts +80 -0
- package/src/biz/landing-page/compile.ts +67 -0
- package/src/biz/landing-page/index.ts +20 -0
- package/src/biz/landing-page/shell.ts +48 -0
- package/src/biz/link/hub.ts +255 -0
- package/src/biz/link/shared.ts +493 -0
- package/src/biz/master-sub/compile.ts +232 -0
- package/src/biz/master-sub/index.ts +20 -0
- package/src/biz/master-sub/shell.ts +56 -0
- package/src/biz/multi-board/compile.ts +234 -0
- package/src/biz/multi-board/index.ts +19 -0
- package/src/biz/multi-board/shell.ts +70 -0
- package/src/biz/names.ts +30 -0
- package/src/biz/notification-center/compile.ts +138 -0
- package/src/biz/notification-center/index.ts +29 -0
- package/src/biz/notification-center/shell.ts +42 -0
- package/src/biz/page-templates/result-page/compile.ts +46 -0
- package/src/biz/page-templates/result-page/index.ts +19 -0
- package/src/biz/page-templates/result-page/shell.ts +31 -0
- package/src/biz/page-templates/shared.ts +121 -0
- package/src/biz/page-templates/sign-in-page/compile.ts +176 -0
- package/src/biz/page-templates/sign-in-page/index.ts +18 -0
- package/src/biz/page-templates/sign-in-page/shell.ts +116 -0
- package/src/biz/record-detail/compile.ts +290 -0
- package/src/biz/record-detail/index.ts +22 -0
- package/src/biz/record-detail/shell.ts +64 -0
- package/src/biz/settings-center/compile.ts +100 -0
- package/src/biz/settings-center/index.ts +18 -0
- package/src/biz/settings-center/shell.ts +51 -0
- package/src/biz/shared/action-host.ts +469 -0
- package/src/biz/shared/coordinator.ts +516 -0
- package/src/biz/shared/index.ts +9 -0
- package/src/biz/shared/pipes.ts +58 -0
- package/src/biz/shared/runtime-hub.ts +112 -0
- package/src/biz/shared/step-values.ts +25 -0
- package/src/biz/single-form/compile.ts +146 -0
- package/src/biz/single-form/index.ts +18 -0
- package/src/biz/single-form/shell.ts +38 -0
- package/src/biz/standard-crud/bridge.ts +11 -0
- package/src/biz/standard-crud/compile.ts +546 -0
- package/src/biz/standard-crud/index.ts +18 -0
- package/src/biz/standard-crud/shell.ts +157 -0
- package/src/biz/step-form/compile.ts +400 -0
- package/src/biz/step-form/hub.ts +412 -0
- package/src/biz/step-form/index.ts +23 -0
- package/src/biz/step-form/shell.ts +96 -0
- package/src/biz/step-form/steps-ref.ts +112 -0
- package/src/biz/types.ts +96 -0
- package/src/cli/kit-cli.ts +102 -0
- package/src/compile/action-host-attach.ts +76 -0
- package/src/compile/compile-page.ts +472 -0
- package/src/compile/component-candidates.ts +147 -0
- package/src/compile/fragment.ts +104 -0
- package/src/compile/hints.ts +255 -0
- package/src/compile/index.ts +16 -0
- package/src/compile/locate.ts +166 -0
- package/src/compile/page-params.ts +80 -0
- package/src/compile/parse.ts +355 -0
- package/src/compile/redirect.ts +90 -0
- package/src/compile/registry.ts +30 -0
- package/src/compile/remove-guard.ts +99 -0
- package/src/compile/styles.ts +244 -0
- package/src/compile/types.ts +106 -0
- package/src/data/amount-breakdown.ts +132 -0
- package/src/data/anchor-nav.ts +225 -0
- package/src/data/approval-flow.ts +269 -0
- package/src/data/assignment-picker.ts +652 -0
- package/src/data/async-result-panel.ts +308 -0
- package/src/data/breadcrumbs.ts +197 -0
- package/src/data/calendar.ts +363 -0
- package/src/data/carousel.ts +408 -0
- package/src/data/chart.ts +726 -0
- package/src/data/checklist.ts +215 -0
- package/src/data/code-view.ts +415 -0
- package/src/data/comment-thread.ts +342 -0
- package/src/data/confirm-dialog.ts +144 -0
- package/src/data/context-menu.ts +216 -0
- package/src/data/d9-limits.ts +42 -0
- package/src/data/d9-util.ts +81 -0
- package/src/data/diff.ts +239 -0
- package/src/data/display-util.ts +135 -0
- package/src/data/dock.ts +152 -0
- package/src/data/embed.ts +200 -0
- package/src/data/field-mapper.ts +544 -0
- package/src/data/flow-editor-contract.ts +41 -0
- package/src/data/flow-editor.ts +2622 -0
- package/src/data/flow-remote-options.ts +257 -0
- package/src/data/footer.ts +157 -0
- package/src/data/form-draft-registry.ts +76 -0
- package/src/data/gantt.ts +430 -0
- package/src/data/hero.ts +149 -0
- package/src/data/image-viewer.ts +333 -0
- package/src/data/index.ts +268 -0
- package/src/data/item-list.ts +335 -0
- package/src/data/kanban.ts +667 -0
- package/src/data/media-grid.ts +246 -0
- package/src/data/mega-menu.ts +257 -0
- package/src/data/menu-dom.ts +169 -0
- package/src/data/menu.ts +464 -0
- package/src/data/mockup.ts +176 -0
- package/src/data/modal-dialog.ts +182 -0
- package/src/data/navbar.ts +292 -0
- package/src/data/object-form.ts +1981 -0
- package/src/data/options-bus.ts +24 -0
- package/src/data/outcome-watch.ts +40 -0
- package/src/data/overlay-portal.ts +6 -0
- package/src/data/pager.ts +473 -0
- package/src/data/permission-matrix.ts +432 -0
- package/src/data/permission-tree.ts +916 -0
- package/src/data/pricing-table.ts +269 -0
- package/src/data/prompt-dialog.ts +235 -0
- package/src/data/reaction-bar.ts +236 -0
- package/src/data/record-card.ts +413 -0
- package/src/data/record-picker.ts +489 -0
- package/src/data/redirect.ts +109 -0
- package/src/data/remote-options.ts +54 -0
- package/src/data/request-console.ts +399 -0
- package/src/data/resident.ts +58 -0
- package/src/data/result-panel.ts +160 -0
- package/src/data/rich-text.ts +626 -0
- package/src/data/row-editor.ts +1066 -0
- package/src/data/rule-builder.ts +1137 -0
- package/src/data/shape-util.ts +221 -0
- package/src/data/staged-rows.ts +69 -0
- package/src/data/stat-group.ts +231 -0
- package/src/data/static-lazy.ts +63 -0
- package/src/data/static-registry.ts +227 -0
- package/src/data/steps.ts +195 -0
- package/src/data/survey.ts +455 -0
- package/src/data/system-switcher.ts +243 -0
- package/src/data/timeline.ts +204 -0
- package/src/data/tour-guide.ts +392 -0
- package/src/data/transfer.ts +597 -0
- package/src/data/tree-check.ts +30 -0
- package/src/data/tree-table.ts +674 -0
- package/src/data/tree.ts +656 -0
- package/src/data/trend-line.ts +147 -0
- package/src/data/virtual-rows.ts +556 -0
- package/src/data/watermark.ts +140 -0
- package/src/data/wrap.ts +267 -0
- package/src/data/wrapped-candidates.ts +96 -0
- package/src/frames/blank-frame.ts +19 -0
- package/src/frames/index.ts +44 -0
- package/src/frames/page-bar.ts +185 -0
- package/src/frames/page-header.ts +185 -0
- package/src/frames/page-status.ts +54 -0
- package/src/frames/resize-handle.ts +147 -0
- package/src/frames/shared.ts +242 -0
- package/src/frames/single-frame.ts +16 -0
- package/src/frames/split-frame/index.ts +4 -0
- package/src/frames/split-frame/shell.ts +219 -0
- package/src/frames/split-frame/span.ts +64 -0
- package/src/frames/split-frame/wiring.ts +164 -0
- package/src/frames/tabs-frame/index.ts +3 -0
- package/src/frames/tabs-frame/shell.ts +112 -0
- package/src/frames/tabs-frame/wiring.ts +69 -0
- package/src/frames/top-main-frame.ts +20 -0
- package/src/frames/types.ts +72 -0
- package/src/frames/workspace-frame/extras.ts +197 -0
- package/src/frames/workspace-frame/index.ts +13 -0
- package/src/frames/workspace-frame/shell.ts +282 -0
- package/src/frames/workspace-frame/state.ts +152 -0
- package/src/frames/workspace-frame/view.ts +1013 -0
- package/src/generated/kit-grammar-runtime.ts +2822 -0
- package/src/generated/page-origin.ts +57 -0
- package/src/i18n/index.ts +22 -0
- package/src/i18n/kit-text.ts +692 -0
- package/src/i18n/resolve-text-refs.ts +128 -0
- package/src/index.ts +6 -0
- package/src/object-renderer/action-gate.ts +216 -0
- package/src/object-renderer/adopt-gate.ts +333 -0
- package/src/object-renderer/arrange.ts +411 -0
- package/src/object-renderer/candidates.ts +68 -0
- package/src/object-renderer/collapse-wiring.ts +99 -0
- package/src/object-renderer/collection-expand.ts +185 -0
- package/src/object-renderer/collection-parts.ts +653 -0
- package/src/object-renderer/collection-table.ts +503 -0
- package/src/object-renderer/collection.ts +628 -0
- package/src/object-renderer/compile-data.ts +549 -0
- package/src/object-renderer/defaults.ts +252 -0
- package/src/object-renderer/display-checks.ts +153 -0
- package/src/object-renderer/emit-events.ts +498 -0
- package/src/object-renderer/emit-object.ts +98 -0
- package/src/object-renderer/emit-static.ts +1036 -0
- package/src/object-renderer/field-policy.ts +89 -0
- package/src/object-renderer/field-value.ts +581 -0
- package/src/object-renderer/form-detail.ts +116 -0
- package/src/object-renderer/index.ts +13 -0
- package/src/object-renderer/linkage.ts +371 -0
- package/src/object-renderer/merge-class.ts +126 -0
- package/src/object-renderer/mode.ts +25 -0
- package/src/object-renderer/outcome-draft.ts +61 -0
- package/src/object-renderer/parts.ts +136 -0
- package/src/object-renderer/pick-component.ts +36 -0
- package/src/object-renderer/render-object.ts +724 -0
- package/src/object-renderer/request-actions.ts +581 -0
- package/src/object-renderer/skeleton.ts +101 -0
- package/src/object-renderer/table-actions.ts +438 -0
- package/src/object-renderer/table-summary.ts +105 -0
- package/src/object-renderer/table-tools.ts +1072 -0
- package/src/object-renderer/types.ts +936 -0
- package/src/page-target/ai-surface.ts +154 -0
- package/src/page-target/compile.ts +354 -0
- package/src/page-target/drift.ts +186 -0
- package/src/page-target/index.ts +25 -0
- package/src/page-target/intent-map.ts +137 -0
- package/src/page-target/intent-schema.ts +711 -0
- package/src/page-target/origin.ts +17 -0
- package/src/page-target/target.ts +450 -0
- package/src/page-target/writer-policy.ts +315 -0
- package/src/theme/block-theme.ts +202 -0
- package/src/theme/kit-theme-text.ts +2 -0
- package/src/theme/kit-theme.css +275 -0
- package/src/theme/kit-theme.tpl +275 -0
- package/src/theme/theme-tokens.ts +135 -0
|
@@ -0,0 +1,523 @@
|
|
|
1
|
+
// Cascader:级联选择(多级面板,值是一条路径)。D8 组。
|
|
2
|
+
//
|
|
3
|
+
// 归类(2.1a 四问):单值输入(值 = 从根到所选节点的 value 数组),选项树由 prop 显式传入 -> 基础组件。
|
|
4
|
+
// - options: [{ value, label, disabled?, lazy?, children?: [...] }],深度上限 8。节点有 children 或 `lazy: true` 即「分支」。
|
|
5
|
+
// - 默认只能选叶子;`change_on_select` 允许任意一级:点分支项时抛 change 并展开,面板保持打开。
|
|
6
|
+
// - 懒加载:展开一个 `lazy: true` 且还没有 children 的节点时抛 `load { value: [路径], node }`,子列显示加载行,
|
|
7
|
+
// 页面把 children 填进 options 后自动补画(每个节点只抛一次)。
|
|
8
|
+
// - `searchable`:输入框可键入,面板改成「路径平铺结果」(A / B / C),↑/↓ 走项、Enter 选中。
|
|
9
|
+
// a11y:焦点留在输入框(role=combobox,aria-activedescendant),面板 role=listbox,每列 role=group,项 role=option;
|
|
10
|
+
// ↑/↓ 在当前列走项(core 键盘接线),→ 展开并进入子列,← 回到上一列,Enter 选中 / 展开,Esc 收起,Tab 收起。
|
|
11
|
+
// 受控:只抛 change { value: 路径原值数组, labels: 文字数组 }。
|
|
12
|
+
|
|
13
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
14
|
+
import { KIT_STATIC_COMPONENT_LIMITS } from 'soma-foundation/kit-limits';
|
|
15
|
+
import { kitKey, kitText } from '../i18n/kit-text';
|
|
16
|
+
import { kitIcon } from './icons';
|
|
17
|
+
import type { CollectionItem } from 'soma-core/keyboard';
|
|
18
|
+
import {
|
|
19
|
+
EMPTY_ROW_CLASS, KIT_POPUP_CLASS_CANDIDATES, KIT_DROPDOWN_CLASS_CANDIDATES, PANEL_BASE_CLASS,
|
|
20
|
+
syncDropdown, releaseDropdown, cssEscape, createListNav, onOutsidePress, optionClass, scrollIntoViewIfAny,
|
|
21
|
+
} from './popup';
|
|
22
|
+
import {
|
|
23
|
+
CLASS_PROP, FIELD_CLASS, ID_PROPS, SIZE_PROP, classCandidates,
|
|
24
|
+
applyDisabled, bool, createKitController, joinClass, nextUid, setAttr, setBoolAttr, sizeOf, str,
|
|
25
|
+
type KitProps,
|
|
26
|
+
} from './shared';
|
|
27
|
+
|
|
28
|
+
// ---- Tailwind 类常量与候选类清单 ----
|
|
29
|
+
|
|
30
|
+
const WRAP = 'relative block w-full';
|
|
31
|
+
const STATUS = 'sr-only';
|
|
32
|
+
const PANEL_HIDDEN = 'hidden';
|
|
33
|
+
// 位置类(left-0 top-full mt-1 或翻转后的整串)由 popup.ts 的 syncDropdown 拼上,这里只写外观
|
|
34
|
+
const PANEL_COLUMNS = 'absolute z-10 flex max-w-full overflow-auto rounded-lg border border-border-subtle bg-surface-raised shadow-lg';
|
|
35
|
+
const PANEL_FLAT = PANEL_BASE_CLASS;
|
|
36
|
+
const COLUMN = 'max-h-70 min-w-40 overflow-auto border-e border-border-subtle py-1';
|
|
37
|
+
const CHEVRON = 'ms-auto text-fg-subtle';
|
|
38
|
+
const LABEL = 'min-w-0 truncate';
|
|
39
|
+
|
|
40
|
+
export const KIT_CASCADER_CLASS_CANDIDATES: readonly string[] = classCandidates(
|
|
41
|
+
WRAP, STATUS, PANEL_HIDDEN, PANEL_COLUMNS, PANEL_FLAT, COLUMN, CHEVRON, LABEL, EMPTY_ROW_CLASS,
|
|
42
|
+
Object.values(FIELD_CLASS), KIT_POPUP_CLASS_CANDIDATES, KIT_DROPDOWN_CLASS_CANDIDATES,
|
|
43
|
+
optionClass(false, false, false), optionClass(true, false, false), optionClass(false, true, false), optionClass(false, false, true),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
// ---- 选项树规整与搜索(纯函数) ----
|
|
47
|
+
|
|
48
|
+
export interface CascaderNode {
|
|
49
|
+
value: string;
|
|
50
|
+
raw: unknown;
|
|
51
|
+
label: string;
|
|
52
|
+
disabled: boolean;
|
|
53
|
+
lazy: boolean;
|
|
54
|
+
/** null = 没有 children 字段 */
|
|
55
|
+
children: CascaderNode[] | null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const MAX_DEPTH = KIT_STATIC_COMPONENT_LIMITS.navigation.menu.maxDepth;
|
|
59
|
+
|
|
60
|
+
export function cascaderNodesOf(raw: unknown, depth = 0): CascaderNode[] {
|
|
61
|
+
if (!Array.isArray(raw) || depth >= MAX_DEPTH) return [];
|
|
62
|
+
const out: CascaderNode[] = [];
|
|
63
|
+
const seen = new Set<string>();
|
|
64
|
+
for (const item of raw) {
|
|
65
|
+
if (item === null || typeof item !== 'object') continue;
|
|
66
|
+
const rec = item as Record<string, unknown>;
|
|
67
|
+
if (rec.value === undefined || rec.value === null) continue;
|
|
68
|
+
const value = String(rec.value);
|
|
69
|
+
if (seen.has(value)) continue;
|
|
70
|
+
seen.add(value);
|
|
71
|
+
out.push({
|
|
72
|
+
value,
|
|
73
|
+
raw: rec.value,
|
|
74
|
+
label: rec.label === undefined || rec.label === null ? value : String(rec.label),
|
|
75
|
+
disabled: rec.disabled === true,
|
|
76
|
+
lazy: rec.lazy === true,
|
|
77
|
+
children: Array.isArray(rec.children) ? cascaderNodesOf(rec.children, depth + 1) : null,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function isBranch(n: CascaderNode): boolean {
|
|
84
|
+
return (n.children !== null && n.children.length > 0) || n.lazy;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** 沿 keys 取节点链;任何一级找不到回 null */
|
|
88
|
+
export function cascaderPathNodes(tree: readonly CascaderNode[], keys: readonly string[]): CascaderNode[] | null {
|
|
89
|
+
const out: CascaderNode[] = [];
|
|
90
|
+
let level: readonly CascaderNode[] | null = tree;
|
|
91
|
+
for (const key of keys) {
|
|
92
|
+
const hit: CascaderNode | undefined = level?.find((n) => n.value === key);
|
|
93
|
+
if (!hit) return null;
|
|
94
|
+
out.push(hit);
|
|
95
|
+
level = hit.children;
|
|
96
|
+
}
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface CascaderHit { keys: string[]; nodes: CascaderNode[]; text: string; disabled: boolean }
|
|
101
|
+
|
|
102
|
+
/** 搜索:路径文字包含查询词;change_on_select 时分支也算命中;上限 50 条 */
|
|
103
|
+
export function cascaderSearch(tree: readonly CascaderNode[], query: string, anyLevel: boolean, sep: string): CascaderHit[] {
|
|
104
|
+
const needle = query.trim().toLowerCase();
|
|
105
|
+
const out: CascaderHit[] = [];
|
|
106
|
+
const walk = (level: readonly CascaderNode[], trail: CascaderNode[]): void => {
|
|
107
|
+
for (const n of level) {
|
|
108
|
+
if (out.length >= 50) return;
|
|
109
|
+
const nodes = [...trail, n];
|
|
110
|
+
const branch = isBranch(n);
|
|
111
|
+
const text = nodes.map((x) => x.label).join(sep);
|
|
112
|
+
if ((!branch || anyLevel) && (needle === '' || text.toLowerCase().includes(needle))) {
|
|
113
|
+
out.push({ keys: nodes.map((x) => x.value), nodes, text, disabled: nodes.some((x) => x.disabled) });
|
|
114
|
+
}
|
|
115
|
+
if (n.children) walk(n.children, nodes);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
walk(tree, []);
|
|
119
|
+
return out;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const pathAttr = (keys: readonly string[]): string => JSON.stringify(keys);
|
|
123
|
+
|
|
124
|
+
// ---- 组件 ----
|
|
125
|
+
|
|
126
|
+
export function createCascader(): SomaComponentDefinition {
|
|
127
|
+
return {
|
|
128
|
+
contract: {
|
|
129
|
+
name: 'Cascader',
|
|
130
|
+
layer: 'basic',
|
|
131
|
+
props: {
|
|
132
|
+
value: { type: 'array', default: [], desc: '当前路径(从根到所选节点的 value 数组)' },
|
|
133
|
+
options: { type: 'array', default: [], desc: '选项树 [{ value, label, disabled?, lazy?, children? }],深度上限 8' },
|
|
134
|
+
placeholder: { type: 'string', default: '', desc: '占位文字' },
|
|
135
|
+
searchable: { type: 'boolean', default: false, desc: '可键入搜索路径' },
|
|
136
|
+
change_on_select: { type: 'boolean', default: false, desc: '允许选任意一级(点分支项即抛 change 并展开)' },
|
|
137
|
+
separator: { type: 'string', default: ' / ', desc: '路径文字分隔' },
|
|
138
|
+
empty_text: { type: 'string', default: '', desc: '搜索无结果提示;缺省取内置文案(按页面语言)' },
|
|
139
|
+
loading_text: { type: 'string', default: '', desc: '懒加载子列的加载行文字;缺省取内置文案(按页面语言)' },
|
|
140
|
+
disabled: { type: 'boolean', default: false },
|
|
141
|
+
readonly: { type: 'boolean', default: false },
|
|
142
|
+
...ID_PROPS,
|
|
143
|
+
size: SIZE_PROP,
|
|
144
|
+
class: CLASS_PROP,
|
|
145
|
+
},
|
|
146
|
+
emits: {
|
|
147
|
+
change: { payload: { value: { type: 'array' }, labels: { type: 'array' } }, desc: '路径变化;disabled / readonly 时不抛' },
|
|
148
|
+
load: { payload: { value: { type: 'array' }, node: { type: 'string' } }, desc: '展开了还没有 children 的 lazy 节点;value 是到它的路径' },
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
templateHtml:
|
|
152
|
+
`<div data-soma-id="root" class="${WRAP}">` +
|
|
153
|
+
`<input data-soma-id="input" type="text" role="combobox" aria-haspopup="listbox" aria-expanded="false" aria-autocomplete="none" autocomplete="off" class="${FIELD_CLASS.md}" />` +
|
|
154
|
+
`<div data-soma-id="panel" role="listbox" class="${PANEL_HIDDEN}"></div>` +
|
|
155
|
+
`<div data-soma-id="status" role="status" class="${STATUS}"></div></div>`,
|
|
156
|
+
controllerFactory: (ctx) => {
|
|
157
|
+
let open = false;
|
|
158
|
+
let typing = false;
|
|
159
|
+
let query = '';
|
|
160
|
+
let composing = false;
|
|
161
|
+
let cursor: string[] = [];
|
|
162
|
+
let searchCursor: string | null = null;
|
|
163
|
+
const requested = new Set<string>();
|
|
164
|
+
let paintFn: (() => void) | null = null;
|
|
165
|
+
|
|
166
|
+
return createKitController({
|
|
167
|
+
attach(root, api) {
|
|
168
|
+
const input = root.querySelector<HTMLInputElement>('[data-soma-id="input"], [data-soma-scoped-id="input"]') as HTMLInputElement;
|
|
169
|
+
const panel = root.querySelector<HTMLElement>('[data-soma-id="panel"], [data-soma-scoped-id="panel"]') as HTMLElement;
|
|
170
|
+
const status = root.querySelector<HTMLElement>('[data-soma-id="status"], [data-soma-scoped-id="status"]') as HTMLElement;
|
|
171
|
+
const listId = nextUid('kit-cascader');
|
|
172
|
+
panel.id = listId;
|
|
173
|
+
input.setAttribute('aria-controls', listId);
|
|
174
|
+
|
|
175
|
+
const p = (): KitProps => api.props();
|
|
176
|
+
const locked = (): boolean => bool(p().disabled) || bool(p().readonly);
|
|
177
|
+
const tree = (): CascaderNode[] => cascaderNodesOf(p().options);
|
|
178
|
+
const sep = (): string => str(p().separator, ' / ');
|
|
179
|
+
const anyLevel = (): boolean => bool(p().change_on_select);
|
|
180
|
+
const searching = (): boolean => bool(p().searchable) && typing;
|
|
181
|
+
const valueKeys = (): string[] => (Array.isArray(p().value) ? (p().value as unknown[]).map((v) => String(v)) : []);
|
|
182
|
+
const selectedNodes = (): CascaderNode[] | null => {
|
|
183
|
+
const keys = valueKeys();
|
|
184
|
+
return keys.length === 0 ? null : cascaderPathNodes(tree(), keys);
|
|
185
|
+
};
|
|
186
|
+
const selectedText = (): string => selectedNodes()?.map((n) => n.label).join(sep()) ?? '';
|
|
187
|
+
|
|
188
|
+
const siblings = (keys: readonly string[]): CascaderNode[] => {
|
|
189
|
+
if (keys.length <= 1) return tree();
|
|
190
|
+
const parent = cascaderPathNodes(tree(), keys.slice(0, -1));
|
|
191
|
+
const last = parent?.[parent.length - 1];
|
|
192
|
+
return last?.children ?? [];
|
|
193
|
+
};
|
|
194
|
+
const firstEnabled = (list: readonly CascaderNode[]): CascaderNode | undefined => list.find((n) => !n.disabled);
|
|
195
|
+
|
|
196
|
+
// 懒加载:展开的分支没有 children 时抛一次 load
|
|
197
|
+
const ensureLoaded = (): void => {
|
|
198
|
+
const nodes = cascaderPathNodes(tree(), cursor);
|
|
199
|
+
const last = nodes?.[nodes.length - 1];
|
|
200
|
+
if (!nodes || !last || !last.lazy || (last.children !== null && last.children.length > 0)) return;
|
|
201
|
+
const sig = pathAttr(cursor);
|
|
202
|
+
if (requested.has(sig)) return;
|
|
203
|
+
requested.add(sig);
|
|
204
|
+
api.emit('load', { value: nodes.map((n) => n.raw), node: last.value });
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const optionEl = (id: string, text: string, selected: boolean, active: boolean, disabled: boolean, keys: readonly string[], branch: boolean): HTMLElement => {
|
|
208
|
+
const el = document.createElement('div');
|
|
209
|
+
el.id = id;
|
|
210
|
+
el.setAttribute('role', 'option');
|
|
211
|
+
el.setAttribute('data-kit-path', pathAttr(keys));
|
|
212
|
+
el.setAttribute('aria-selected', selected ? 'true' : 'false');
|
|
213
|
+
if (disabled) el.setAttribute('aria-disabled', 'true');
|
|
214
|
+
el.className = optionClass(selected, active, disabled);
|
|
215
|
+
const label = document.createElement('span');
|
|
216
|
+
label.className = LABEL;
|
|
217
|
+
label.textContent = text;
|
|
218
|
+
el.appendChild(label);
|
|
219
|
+
if (branch) {
|
|
220
|
+
const chev = document.createElement('span');
|
|
221
|
+
chev.setAttribute('aria-hidden', 'true');
|
|
222
|
+
chev.className = CHEVRON;
|
|
223
|
+
chev.appendChild(kitIcon('chevron-right', 'sm', 'rtl:-scale-x-100'));
|
|
224
|
+
el.appendChild(chev);
|
|
225
|
+
}
|
|
226
|
+
return el;
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
const paintPanel = (): void => {
|
|
230
|
+
panel.textContent = '';
|
|
231
|
+
let activeId = '';
|
|
232
|
+
let panelBase = PANEL_COLUMNS;
|
|
233
|
+
if (searching()) {
|
|
234
|
+
const hits = cascaderSearch(tree(), query, anyLevel(), sep());
|
|
235
|
+
panelBase = PANEL_FLAT;
|
|
236
|
+
if (hits.length === 0) {
|
|
237
|
+
const row = document.createElement('div');
|
|
238
|
+
row.className = EMPTY_ROW_CLASS;
|
|
239
|
+
row.textContent = str(p().empty_text, kitText('soma.kit.empty_option', undefined, panel));
|
|
240
|
+
panel.appendChild(row);
|
|
241
|
+
status.textContent = row.textContent;
|
|
242
|
+
} else {
|
|
243
|
+
status.textContent = '';
|
|
244
|
+
const sel = valueKeys().join('\u0001');
|
|
245
|
+
hits.forEach((h, i) => {
|
|
246
|
+
const id = `${listId}-s${i}`;
|
|
247
|
+
const active = searchCursor === pathAttr(h.keys);
|
|
248
|
+
const el = optionEl(id, h.text, h.keys.join('\u0001') === sel, active, h.disabled, h.keys, false);
|
|
249
|
+
if (active) activeId = id;
|
|
250
|
+
panel.appendChild(el);
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
} else {
|
|
254
|
+
status.textContent = '';
|
|
255
|
+
const selKeys = valueKeys();
|
|
256
|
+
const columns: Array<{ nodes: CascaderNode[] | null; prefix: string[] }> = [{ nodes: tree(), prefix: [] }];
|
|
257
|
+
for (let i = 0; i < cursor.length; i += 1) {
|
|
258
|
+
const chain = cascaderPathNodes(tree(), cursor.slice(0, i + 1));
|
|
259
|
+
const node = chain?.[chain.length - 1];
|
|
260
|
+
if (!node || !isBranch(node)) break;
|
|
261
|
+
columns.push({ nodes: node.children !== null && node.children.length > 0 ? node.children : null, prefix: cursor.slice(0, i + 1) });
|
|
262
|
+
}
|
|
263
|
+
columns.forEach((col, ci) => {
|
|
264
|
+
const group = document.createElement('div');
|
|
265
|
+
group.setAttribute('role', 'group');
|
|
266
|
+
group.className = COLUMN;
|
|
267
|
+
if (col.nodes === null) {
|
|
268
|
+
const row = document.createElement('div');
|
|
269
|
+
row.className = EMPTY_ROW_CLASS;
|
|
270
|
+
row.textContent = str(p().loading_text, kitText('soma.kit.loading', undefined, panel));
|
|
271
|
+
group.appendChild(row);
|
|
272
|
+
} else {
|
|
273
|
+
col.nodes.forEach((n, ni) => {
|
|
274
|
+
const keys = [...col.prefix, n.value];
|
|
275
|
+
const id = `${listId}-${ci}-${ni}`;
|
|
276
|
+
const onSelectedPath = selKeys.length >= keys.length && keys.every((k, i) => selKeys[i] === k);
|
|
277
|
+
const active = cursor.length >= keys.length && keys.every((k, i) => cursor[i] === k);
|
|
278
|
+
const el = optionEl(id, n.label, onSelectedPath, active, n.disabled, keys, isBranch(n));
|
|
279
|
+
if (active && keys.length === cursor.length) activeId = id;
|
|
280
|
+
group.appendChild(el);
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
panel.appendChild(group);
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
setAttr(input, 'aria-activedescendant', open ? activeId : '');
|
|
287
|
+
syncDropdown(panel, true, panelBase);
|
|
288
|
+
if (activeId !== '') scrollIntoViewIfAny(panel.querySelector(`#${cssEscape(activeId)}`));
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
const paint = (): void => {
|
|
292
|
+
if (open) paintPanel();
|
|
293
|
+
else {
|
|
294
|
+
syncDropdown(panel, false);
|
|
295
|
+
panel.textContent = '';
|
|
296
|
+
input.removeAttribute('aria-activedescendant');
|
|
297
|
+
status.textContent = '';
|
|
298
|
+
}
|
|
299
|
+
input.setAttribute('aria-expanded', open ? 'true' : 'false');
|
|
300
|
+
if (!typing) {
|
|
301
|
+
const label = selectedText();
|
|
302
|
+
if (input.value !== label) input.value = label;
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
paintFn = paint;
|
|
306
|
+
|
|
307
|
+
const openPanel = (): void => {
|
|
308
|
+
if (open || locked()) return;
|
|
309
|
+
open = true;
|
|
310
|
+
typing = false;
|
|
311
|
+
query = '';
|
|
312
|
+
const sel = selectedNodes();
|
|
313
|
+
cursor = sel ? sel.map((n) => n.value) : [];
|
|
314
|
+
if (cursor.length === 0) {
|
|
315
|
+
const first = firstEnabled(tree());
|
|
316
|
+
cursor = first ? [first.value] : [];
|
|
317
|
+
}
|
|
318
|
+
searchCursor = null;
|
|
319
|
+
paint();
|
|
320
|
+
ensureLoaded();
|
|
321
|
+
paint();
|
|
322
|
+
};
|
|
323
|
+
const closePanel = (): void => {
|
|
324
|
+
if (!open) return;
|
|
325
|
+
open = false;
|
|
326
|
+
typing = false;
|
|
327
|
+
query = '';
|
|
328
|
+
cursor = [];
|
|
329
|
+
searchCursor = null;
|
|
330
|
+
paint();
|
|
331
|
+
};
|
|
332
|
+
const commit = (nodes: readonly CascaderNode[], keepOpen: boolean): void => {
|
|
333
|
+
if (locked() || nodes.some((n) => n.disabled)) return;
|
|
334
|
+
api.emit('change', { value: nodes.map((n) => n.raw), labels: nodes.map((n) => n.label) });
|
|
335
|
+
if (!keepOpen) closePanel();
|
|
336
|
+
};
|
|
337
|
+
const expand = (keys: string[]): void => {
|
|
338
|
+
cursor = keys;
|
|
339
|
+
paint();
|
|
340
|
+
ensureLoaded();
|
|
341
|
+
paint();
|
|
342
|
+
};
|
|
343
|
+
// 激活一条路径:叶子选中;分支展开(change_on_select 时同时选中)
|
|
344
|
+
const activate = (keys: string[]): void => {
|
|
345
|
+
const nodes = cascaderPathNodes(tree(), keys);
|
|
346
|
+
const last = nodes?.[nodes.length - 1];
|
|
347
|
+
if (!nodes || !last || nodes.some((n) => n.disabled)) return;
|
|
348
|
+
if (searching()) {
|
|
349
|
+
commit(nodes, false);
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
if (!isBranch(last)) {
|
|
353
|
+
commit(nodes, false);
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
if (anyLevel()) commit(nodes, true);
|
|
357
|
+
expand(keys);
|
|
358
|
+
const child = firstEnabled(last.children ?? []);
|
|
359
|
+
if (child) expand([...keys, child.value]);
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
const nav = createListNav({
|
|
363
|
+
host: () => panel,
|
|
364
|
+
textFocus: true,
|
|
365
|
+
items: (): readonly CollectionItem[] => {
|
|
366
|
+
if (searching()) {
|
|
367
|
+
return cascaderSearch(tree(), query, anyLevel(), sep()).map((h) => ({ key: pathAttr(h.keys), text: h.text, ...(h.disabled ? { disabled: true } : {}) }));
|
|
368
|
+
}
|
|
369
|
+
return siblings(cursor).map((n) => ({ key: n.value, text: n.label, ...(n.disabled ? { disabled: true } : {}) }));
|
|
370
|
+
},
|
|
371
|
+
getCursor: () => (searching() ? searchCursor : (cursor[cursor.length - 1] ?? null)),
|
|
372
|
+
setCursor: (key) => {
|
|
373
|
+
if (searching()) searchCursor = key;
|
|
374
|
+
else cursor = [...cursor.slice(0, -1), key];
|
|
375
|
+
paint();
|
|
376
|
+
if (!searching()) ensureLoaded();
|
|
377
|
+
},
|
|
378
|
+
onActivate: (key) => {
|
|
379
|
+
if (searching()) activate(JSON.parse(key) as string[]);
|
|
380
|
+
else activate([...cursor.slice(0, -1), key]);
|
|
381
|
+
},
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
const onKeydown = (event: KeyboardEvent): void => {
|
|
385
|
+
if (locked()) return;
|
|
386
|
+
if (event.key === 'Escape') {
|
|
387
|
+
if (open) {
|
|
388
|
+
event.preventDefault();
|
|
389
|
+
event.stopPropagation();
|
|
390
|
+
closePanel();
|
|
391
|
+
}
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
if (event.key === 'Tab') {
|
|
395
|
+
closePanel();
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
if (!open) {
|
|
399
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp' || event.key === 'Enter') {
|
|
400
|
+
event.preventDefault();
|
|
401
|
+
openPanel();
|
|
402
|
+
}
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
if (!searching()) {
|
|
406
|
+
const arrow = kitKey(event.key, event.target as Element | null);
|
|
407
|
+
if (arrow === 'ArrowRight') {
|
|
408
|
+
const nodes = cascaderPathNodes(tree(), cursor);
|
|
409
|
+
const last = nodes?.[nodes.length - 1];
|
|
410
|
+
if (last && isBranch(last) && !last.disabled) {
|
|
411
|
+
event.preventDefault();
|
|
412
|
+
const child = firstEnabled(last.children ?? []);
|
|
413
|
+
expand(child ? [...cursor, child.value] : cursor);
|
|
414
|
+
}
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
if (arrow === 'ArrowLeft') {
|
|
418
|
+
if (cursor.length > 1) {
|
|
419
|
+
event.preventDefault();
|
|
420
|
+
expand(cursor.slice(0, -1));
|
|
421
|
+
}
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
if (event.key === 'Enter') {
|
|
426
|
+
event.preventDefault();
|
|
427
|
+
if (searching()) {
|
|
428
|
+
if (searchCursor !== null) activate(JSON.parse(searchCursor) as string[]);
|
|
429
|
+
} else if (cursor.length > 0) {
|
|
430
|
+
const nodes = cascaderPathNodes(tree(), cursor);
|
|
431
|
+
const last = nodes?.[nodes.length - 1];
|
|
432
|
+
if (last && isBranch(last)) {
|
|
433
|
+
// 分支:change_on_select 时选中它;否则只是展开
|
|
434
|
+
if (anyLevel() && !last.disabled) commit(nodes ?? [], true);
|
|
435
|
+
const child = firstEnabled(last.children ?? []);
|
|
436
|
+
expand(child ? [...cursor, child.value] : cursor);
|
|
437
|
+
} else if (nodes) commit(nodes, false);
|
|
438
|
+
}
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
if (nav.handle(event)) event.preventDefault();
|
|
442
|
+
};
|
|
443
|
+
const onInput = (): void => {
|
|
444
|
+
if (composing || locked() || !bool(p().searchable)) return;
|
|
445
|
+
if (!open) open = true;
|
|
446
|
+
typing = true;
|
|
447
|
+
query = input.value;
|
|
448
|
+
const hits = cascaderSearch(tree(), query, anyLevel(), sep());
|
|
449
|
+
const first = hits.find((h) => !h.disabled);
|
|
450
|
+
searchCursor = first ? pathAttr(first.keys) : null;
|
|
451
|
+
paint();
|
|
452
|
+
};
|
|
453
|
+
const onClick = (): void => {
|
|
454
|
+
if (open && !bool(p().searchable)) closePanel();
|
|
455
|
+
else openPanel();
|
|
456
|
+
};
|
|
457
|
+
const onFocus = (): void => {
|
|
458
|
+
if (!bool(p().searchable)) return;
|
|
459
|
+
openPanel();
|
|
460
|
+
};
|
|
461
|
+
const onBlur = (): void => closePanel();
|
|
462
|
+
const onCompStart = (): void => { composing = true; };
|
|
463
|
+
const onCompEnd = (): void => { composing = false; onInput(); };
|
|
464
|
+
const onPanelMouseDown = (event: Event): void => { event.preventDefault(); };
|
|
465
|
+
const onPanelClick = (event: Event): void => {
|
|
466
|
+
const row = (event.target as HTMLElement | null)?.closest<HTMLElement>('[data-kit-path]');
|
|
467
|
+
const raw = row?.getAttribute('data-kit-path');
|
|
468
|
+
if (!row || raw === null || raw === undefined) return;
|
|
469
|
+
if (row.getAttribute('aria-disabled') === 'true') return;
|
|
470
|
+
activate(JSON.parse(raw) as string[]);
|
|
471
|
+
};
|
|
472
|
+
input.addEventListener('keydown', onKeydown);
|
|
473
|
+
input.addEventListener('input', onInput);
|
|
474
|
+
input.addEventListener('click', onClick);
|
|
475
|
+
input.addEventListener('focus', onFocus);
|
|
476
|
+
input.addEventListener('blur', onBlur);
|
|
477
|
+
input.addEventListener('compositionstart', onCompStart);
|
|
478
|
+
input.addEventListener('compositionend', onCompEnd);
|
|
479
|
+
panel.addEventListener('mousedown', onPanelMouseDown);
|
|
480
|
+
panel.addEventListener('click', onPanelClick);
|
|
481
|
+
const offOutside = onOutsidePress(root, () => open, closePanel);
|
|
482
|
+
return () => {
|
|
483
|
+
input.removeEventListener('keydown', onKeydown);
|
|
484
|
+
input.removeEventListener('input', onInput);
|
|
485
|
+
input.removeEventListener('click', onClick);
|
|
486
|
+
input.removeEventListener('focus', onFocus);
|
|
487
|
+
input.removeEventListener('blur', onBlur);
|
|
488
|
+
input.removeEventListener('compositionstart', onCompStart);
|
|
489
|
+
input.removeEventListener('compositionend', onCompEnd);
|
|
490
|
+
panel.removeEventListener('mousedown', onPanelMouseDown);
|
|
491
|
+
panel.removeEventListener('click', onPanelClick);
|
|
492
|
+
offOutside();
|
|
493
|
+
releaseDropdown(panel, false);
|
|
494
|
+
paintFn = null;
|
|
495
|
+
open = false;
|
|
496
|
+
requested.clear();
|
|
497
|
+
};
|
|
498
|
+
},
|
|
499
|
+
render(root, p) {
|
|
500
|
+
const input = root.querySelector<HTMLInputElement>('[data-soma-id="input"], [data-soma-scoped-id="input"]') as HTMLInputElement;
|
|
501
|
+
input.className = FIELD_CLASS[sizeOf(p.size)];
|
|
502
|
+
input.placeholder = str(p.placeholder);
|
|
503
|
+
applyDisabled(input, bool(p.disabled));
|
|
504
|
+
// 不可搜索时输入框只读(select-only combobox)
|
|
505
|
+
setBoolAttr(input, 'readonly', bool(p.readonly) || !bool(p.searchable));
|
|
506
|
+
setAttr(input, 'aria-autocomplete', bool(p.searchable) ? 'list' : 'none');
|
|
507
|
+
setAttr(input, 'id', str(p.id));
|
|
508
|
+
setAttr(input, 'aria-label', str(p.aria_label));
|
|
509
|
+
setAttr(input, 'name', str(p.name));
|
|
510
|
+
if (bool(p.disabled) || bool(p.readonly)) open = false;
|
|
511
|
+
root.className = joinClass(WRAP, p.class);
|
|
512
|
+
paintFn?.();
|
|
513
|
+
// 页面补进了懒加载的 children:该节点的子列自动补画;已加载的节点允许再次触发
|
|
514
|
+
for (const sig of Array.from(requested)) {
|
|
515
|
+
const nodes = cascaderPathNodes(cascaderNodesOf(p.options), JSON.parse(sig) as string[]);
|
|
516
|
+
const last = nodes?.[nodes.length - 1];
|
|
517
|
+
if (last && last.children !== null && last.children.length > 0) requested.delete(sig);
|
|
518
|
+
}
|
|
519
|
+
},
|
|
520
|
+
})(ctx);
|
|
521
|
+
},
|
|
522
|
+
};
|
|
523
|
+
}
|