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,667 @@
|
|
|
1
|
+
// Kanban:看板(layer: data,写死形状,accept: list)。
|
|
2
|
+
//
|
|
3
|
+
// 数据:`data` 是行数组(每行一张卡);`value` 给了就覆盖 data(view.value 绑定,行数组)。
|
|
4
|
+
// 配置全部外部显式传入(view.props):
|
|
5
|
+
// group —— 行里决定泳道的字段名;
|
|
6
|
+
// lanes —— [{ value, label }],泳道顺序即显示顺序;group 值不在 lanes 里的行不显示;
|
|
7
|
+
// card —— { title: 字段, fields?: [字段 | { field, label? }] },卡片标题与附带事实行;
|
|
8
|
+
// wip —— { 泳道 value: 上限 },在制品上限:泳道满了不接收新卡(移入被拒,抛 wip_blocked),超限显示红色计数;
|
|
9
|
+
// wip_mode —— hard(缺省)| soft:soft 为软上限,满了只提示并抛 wip_exceeded,移入照常进行。
|
|
10
|
+
// 卡片 id 取行的 id_field(默认 id)。
|
|
11
|
+
//
|
|
12
|
+
// 移动(拖放、菜单、键盘三条路汇入同一个 move):
|
|
13
|
+
// - 拖放:经 core 拖放端口(`services.engines.dnd`):卡是 draggable + 上下沿 dropTarget,泳道体是 dropTarget(落到末尾);
|
|
14
|
+
// 没有装配拖放端口时,每张卡上显示「移到…」菜单(move_label),点泳道项即移动;
|
|
15
|
+
// - 键盘:卡片可聚焦(roving tabindex):↑↓ 同泳道换卡,←→ 到相邻泳道的卡;Alt+↑↓ 泳道内调序,Alt+←→ 移到相邻泳道末尾;
|
|
16
|
+
// Enter / Space 抛 select;M 开关移动菜单(菜单内 ↑↓ 走项,Enter 选定,Esc 关闭)。
|
|
17
|
+
// 每次成功移动:组件内立即按新位置重排(乐观),并抛
|
|
18
|
+
// `move { id, from, to, index, target, orderField?, position, set, object }` —— 后四项对齐 core 内置 `data.orderMove` 的纯顺序载荷
|
|
19
|
+
// (target = 卡主键,orderField = `order` 非空才有,set = { [group]: to };
|
|
20
|
+
// position:配了 `order` 时是序值——落在两卡中间取中点、首位取首卡序值 - 1、末位取末卡序值 + 1、空泳道取 0(kanbanOrderValue),
|
|
21
|
+
// 没配 `order` 时退化为泳道内 0 起下标;`index` 永远是下标)。
|
|
22
|
+
// 接数据对象写回的配置要求:数据对象必须声明 `write.update`(orderMove 经它落库),view.props 要给排序字段名 `order`,
|
|
23
|
+
// 并把 move 事件接到 `ACTION | data.orderMove`(跨泳道时 set 同时改分组字段)。
|
|
24
|
+
// 与 `change { value }`(value 为移动后的全部行,供 view.value 写回)。
|
|
25
|
+
// 点卡片抛 `select { id, item }`。data 内容变化(内容签名变)才重置本地顺序。
|
|
26
|
+
|
|
27
|
+
import type { SomaComponentControllerContext, SomaComponentDefinition, SomaDataPort } from 'soma-core';
|
|
28
|
+
import { bool, findRoot, joinClass, str } from '../base/shared';
|
|
29
|
+
import { kitText } from '../i18n/kit-text';
|
|
30
|
+
import { provideCtxRows } from './context-menu';
|
|
31
|
+
|
|
32
|
+
// ───────── 样式常量:Tailwind 类串与候选类清单 ─────────
|
|
33
|
+
|
|
34
|
+
const ROOT_CLASS = '@container flex flex-col gap-2';
|
|
35
|
+
const BOARD_CLASS = 'flex items-start gap-3 overflow-x-auto pb-2';
|
|
36
|
+
const LANE_CLASS = 'flex w-72 shrink-0 flex-col gap-2 rounded-lg border border-border-subtle bg-surface-sunken p-2';
|
|
37
|
+
const LANE_HEAD_CLASS = 'flex items-center justify-between gap-2 px-1 text-sm';
|
|
38
|
+
const LANE_TITLE_CLASS = 'font-medium text-fg';
|
|
39
|
+
const COUNT_CLASS = 'text-fg-muted';
|
|
40
|
+
const COUNT_OVER_CLASS = 'font-medium text-danger-on-soft';
|
|
41
|
+
const LANE_BODY_CLASS = 'flex min-h-16 flex-col gap-2 rounded-md';
|
|
42
|
+
const DROP_CLASS = 'ring-2 ring-inset ring-ring';
|
|
43
|
+
const CARD_CLASS = 'flex flex-col gap-1 rounded-lg border border-border-subtle bg-surface p-3 text-sm text-fg shadow-xs transition-colors hover:bg-surface-sunken focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring';
|
|
44
|
+
const CARD_DRAG_CLASS = 'cursor-grab active:cursor-grabbing';
|
|
45
|
+
const CARD_TITLE_CLASS = 'font-medium text-fg';
|
|
46
|
+
const FACT_CLASS = 'flex items-baseline justify-between gap-2 text-xs text-fg-muted';
|
|
47
|
+
const FACT_VALUE_CLASS = 'truncate text-fg';
|
|
48
|
+
const EMPTY_CLASS = 'px-2 py-3 text-center text-sm text-fg-muted';
|
|
49
|
+
const MOVE_BTN_CLASS = 'inline-flex h-7 items-center self-start rounded-md border border-border bg-surface px-2 text-xs text-fg hover:bg-surface-sunken focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50';
|
|
50
|
+
const MENU_CLASS = 'flex flex-col gap-1 rounded-md border border-border bg-surface p-1';
|
|
51
|
+
const MENU_ITEM_CLASS = 'flex h-7 items-center rounded-md px-2 text-start text-xs text-fg hover:bg-surface-sunken focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:text-fg-subtle';
|
|
52
|
+
const NOTICE_CLASS = 'rounded-md border border-border-subtle bg-warning-soft px-3 py-1.5 text-xs text-warning-on-soft';
|
|
53
|
+
const HIDDEN_CLASS = 'hidden';
|
|
54
|
+
const LIVE_CLASS = 'sr-only';
|
|
55
|
+
|
|
56
|
+
/** 本组件自带的全部类(供编译器并入候选类) */
|
|
57
|
+
export const KIT_KANBAN_CLASS_CANDIDATES: readonly string[] = Object.freeze(
|
|
58
|
+
[...new Set([
|
|
59
|
+
ROOT_CLASS, BOARD_CLASS, LANE_CLASS, LANE_HEAD_CLASS, LANE_TITLE_CLASS, COUNT_CLASS, COUNT_OVER_CLASS, LANE_BODY_CLASS,
|
|
60
|
+
DROP_CLASS, CARD_CLASS, CARD_DRAG_CLASS, CARD_TITLE_CLASS, FACT_CLASS, FACT_VALUE_CLASS, EMPTY_CLASS,
|
|
61
|
+
MOVE_BTN_CLASS, MENU_CLASS, MENU_ITEM_CLASS, NOTICE_CLASS, HIDDEN_CLASS, LIVE_CLASS,
|
|
62
|
+
].flatMap((s) => s.split(/\s+/)).filter((c) => c !== ''))].sort(),
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
// ───────── 数据规整:看板配置解析、卡片移动、序值换算(均为纯函数) ─────────
|
|
66
|
+
|
|
67
|
+
export interface KitKanbanLane {
|
|
68
|
+
value: string;
|
|
69
|
+
label: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface KitKanbanField {
|
|
73
|
+
field: string;
|
|
74
|
+
label: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface KitKanbanConfig {
|
|
78
|
+
group: string;
|
|
79
|
+
lanes: KitKanbanLane[];
|
|
80
|
+
title: string;
|
|
81
|
+
fields: KitKanbanField[];
|
|
82
|
+
wip: Record<string, number>;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export type Row = Record<string, unknown>;
|
|
86
|
+
|
|
87
|
+
function recOf(raw: unknown): Record<string, unknown> {
|
|
88
|
+
return raw !== null && typeof raw === 'object' && !Array.isArray(raw) ? raw as Record<string, unknown> : {};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** 解析看板配置(纯函数):lanes 的 value 去重、空值丢弃;fields 接字符串或 { field, label };wip 只留正整数 */
|
|
92
|
+
export function kanbanConfigOf(groupRaw: unknown, lanesRaw: unknown, cardRaw: unknown, wipRaw: unknown): KitKanbanConfig {
|
|
93
|
+
const lanes: KitKanbanLane[] = [];
|
|
94
|
+
const seen = new Set<string>();
|
|
95
|
+
for (const raw of Array.isArray(lanesRaw) ? lanesRaw : []) {
|
|
96
|
+
const r = typeof raw === 'string' ? { value: raw } : recOf(raw);
|
|
97
|
+
const value = str(r.value).trim();
|
|
98
|
+
if (value === '' || seen.has(value)) continue;
|
|
99
|
+
seen.add(value);
|
|
100
|
+
lanes.push({ value, label: str(r.label).trim() || value });
|
|
101
|
+
}
|
|
102
|
+
const card = recOf(cardRaw);
|
|
103
|
+
const fields: KitKanbanField[] = [];
|
|
104
|
+
for (const raw of Array.isArray(card.fields) ? card.fields : []) {
|
|
105
|
+
const r = typeof raw === 'string' ? { field: raw } : recOf(raw);
|
|
106
|
+
const field = str(r.field).trim();
|
|
107
|
+
if (field !== '') fields.push({ field, label: str(r.label).trim() || field });
|
|
108
|
+
}
|
|
109
|
+
const wip: Record<string, number> = {};
|
|
110
|
+
for (const [k, v] of Object.entries(recOf(wipRaw))) {
|
|
111
|
+
if (typeof v === 'number' && Number.isInteger(v) && v > 0) wip[k] = v;
|
|
112
|
+
}
|
|
113
|
+
return { group: str(groupRaw).trim(), lanes, title: str(card.title).trim(), fields, wip };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** 把卡 id 从 rows 取出,放进 to 泳道的第 index 位(0 起,超出放末尾),并改写 group 字段。纯函数,返回新数组;找不到卡返回 null */
|
|
117
|
+
export function moveKanbanCard(rows: readonly Row[], idField: string, group: string, id: string, to: string, index: number): Row[] | null {
|
|
118
|
+
const at = rows.findIndex((r) => str(r[idField]) === id);
|
|
119
|
+
if (at < 0) return null;
|
|
120
|
+
const moved: Row = { ...rows[at]!, [group]: to };
|
|
121
|
+
const rest = rows.filter((_, i) => i !== at);
|
|
122
|
+
const laneIdx: number[] = [];
|
|
123
|
+
rest.forEach((r, i) => { if (str(r[group]) === to) laneIdx.push(i); });
|
|
124
|
+
const pos = Math.max(0, Math.min(index, laneIdx.length));
|
|
125
|
+
let insertAt: number;
|
|
126
|
+
if (laneIdx.length === 0) insertAt = rest.length;
|
|
127
|
+
else if (pos < laneIdx.length) insertAt = laneIdx[pos]!;
|
|
128
|
+
else insertAt = laneIdx[laneIdx.length - 1]! + 1;
|
|
129
|
+
return [...rest.slice(0, insertAt), moved, ...rest.slice(insertAt)];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* 序值换算(纯函数,规则写死):peers 为目标泳道内(不含被移动卡)按序排好的序值,pos 为落点下标。
|
|
134
|
+
* 空泳道 -> 0;落在首位 -> 首卡序值 - 1;落在末位 -> 末卡序值 + 1;落在两卡中间 -> 两卡序值的中点。
|
|
135
|
+
* 序值不是有限数时按下标计,保证总有一个数。
|
|
136
|
+
*/
|
|
137
|
+
export function kanbanOrderValue(peers: readonly number[], pos: number): number {
|
|
138
|
+
if (peers.length === 0) return 0;
|
|
139
|
+
const at = (i: number): number => (Number.isFinite(peers[i]) ? peers[i]! : i);
|
|
140
|
+
if (pos <= 0) return at(0) - 1;
|
|
141
|
+
if (pos >= peers.length) return at(peers.length - 1) + 1;
|
|
142
|
+
return (at(pos - 1) + at(pos)) / 2;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// ───────── 组件 ─────────
|
|
146
|
+
|
|
147
|
+
interface DragPortLike {
|
|
148
|
+
draggable(el: HTMLElement, source: { id: string; data: () => Record<string, unknown>; canDrag?: () => boolean }): () => void;
|
|
149
|
+
dropTarget(el: HTMLElement, target: {
|
|
150
|
+
id: string; edges?: readonly ('top' | 'bottom' | 'left' | 'right')[]; onOver?(edge: unknown): void; onLeave?(): void;
|
|
151
|
+
}): () => void;
|
|
152
|
+
onMove(handler: (intent: { sourceId: string; targetId: string; edge: unknown }) => void): () => void;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
let instanceCount = 0;
|
|
156
|
+
|
|
157
|
+
export function createKanban(): SomaComponentDefinition {
|
|
158
|
+
return {
|
|
159
|
+
contract: {
|
|
160
|
+
name: 'Kanban',
|
|
161
|
+
layer: 'data',
|
|
162
|
+
props: {
|
|
163
|
+
data: { type: 'array', default: [], desc: '行数组,每行一张卡' },
|
|
164
|
+
value: { type: 'array', default: null, desc: '行数组(view.value 绑定);给了就覆盖 data' },
|
|
165
|
+
group: { type: 'string', default: '', desc: '决定泳道的字段名' },
|
|
166
|
+
lanes: { type: 'array', default: [], desc: '泳道 [{ value, label }],顺序即显示顺序' },
|
|
167
|
+
card: { type: 'object', default: {}, desc: '卡片 { title: 字段, fields?: [字段 | { field, label }] }' },
|
|
168
|
+
wip: { type: 'object', default: {}, desc: '在制品上限 { 泳道 value: 正整数 }:缺省泳道满了不接收新卡,超限计数标红' },
|
|
169
|
+
wip_mode: { type: 'enum', values: ['hard', 'soft'], default: 'hard', desc: 'hard 硬上限(满了拒收,抛 wip_blocked);soft 软上限(只提示并抛 wip_exceeded,照常移入)' },
|
|
170
|
+
id_field: { type: 'string', default: 'id', desc: '卡主键字段名' },
|
|
171
|
+
order: { type: 'string', default: '', desc: '排序字段名(数值);非空时泳道内按它排序,move 载荷带 orderField,position 为序值而不是下标' },
|
|
172
|
+
object: { type: 'string', default: '', desc: '数据对象名(move 载荷的 object)' },
|
|
173
|
+
disabled: { type: 'boolean', default: false, desc: '只读:不可移动' },
|
|
174
|
+
move_label: { type: 'string', default: '', desc: '无拖放端口时卡片上的菜单钮文案' },
|
|
175
|
+
empty_text: { type: 'string', default: '', desc: '空泳道文案' },
|
|
176
|
+
class: { type: 'string', default: '', desc: '外部传入的类,追加在根节点类串末尾' },
|
|
177
|
+
},
|
|
178
|
+
emits: {
|
|
179
|
+
move: {
|
|
180
|
+
payload: {
|
|
181
|
+
id: { type: 'string' }, from: { type: 'string' }, to: { type: 'string' }, index: { type: 'number' },
|
|
182
|
+
target: { type: 'string' }, orderField: { type: 'string' }, position: { type: 'number' }, set: { type: 'object' }, object: { type: 'string' },
|
|
183
|
+
},
|
|
184
|
+
desc: '一张卡被移动(拖放 / 菜单 / 键盘):index 为目标泳道内 0 起序位;target / orderField / position / set 对齐 data.orderMove 的纯顺序载荷',
|
|
185
|
+
},
|
|
186
|
+
change: { payload: { value: { type: 'array' } }, desc: '移动后抛出,value 为移动后的全部行(view.value 写回)' },
|
|
187
|
+
select: { payload: { id: { type: 'string' }, item: { type: 'object' } }, desc: '点卡片或 Enter / Space' },
|
|
188
|
+
wip_blocked: { payload: { id: { type: 'string' }, to: { type: 'string' }, limit: { type: 'number' } }, desc: '目标泳道已满,移入被拒(硬上限)' },
|
|
189
|
+
wip_exceeded: { payload: { id: { type: 'string' }, to: { type: 'string' }, limit: { type: 'number' } }, desc: '目标泳道已满仍照常移入(wip_mode: soft)' },
|
|
190
|
+
},
|
|
191
|
+
keyboard: { layout: 'grid', columns: 'runtime', wrap: false, typeahead: false, focus_model: 'roving', space: 'activate' },
|
|
192
|
+
},
|
|
193
|
+
services: ['engines', 'data', 'notify'],
|
|
194
|
+
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
|
|
195
|
+
controllerFactory: (ctx: SomaComponentControllerContext) => {
|
|
196
|
+
const P = (): Record<string, unknown> => (ctx.readProps ? ctx.readProps() : ctx.props);
|
|
197
|
+
const uid = `kit-kanban-${++instanceCount}`;
|
|
198
|
+
let root: HTMLElement | null = null;
|
|
199
|
+
let noticeEl: HTMLElement | null = null;
|
|
200
|
+
let board: HTMLElement | null = null;
|
|
201
|
+
let live: HTMLElement | null = null;
|
|
202
|
+
let rows: Row[] = [];
|
|
203
|
+
let sig = '';
|
|
204
|
+
let tabKey: string | null = null;
|
|
205
|
+
let menuFor: string | null = null;
|
|
206
|
+
let pendingFocus: string | null = null;
|
|
207
|
+
let cleanups: Array<() => void> = [];
|
|
208
|
+
let offMove: (() => void) | null = null;
|
|
209
|
+
let removers: Array<() => void> = [];
|
|
210
|
+
// 写回失败的回弹:每次移动前的行快照(按发生顺序),写入结果经 data 端口回来后据此决定保留还是回弹
|
|
211
|
+
let snaps: Row[][] = [];
|
|
212
|
+
let snapEpoch = 0;
|
|
213
|
+
let epoch = 0;
|
|
214
|
+
let dataSig = '';
|
|
215
|
+
let begun = 0;
|
|
216
|
+
let lastSeq = 0;
|
|
217
|
+
let armTimer: ReturnType<typeof setTimeout> | null = null;
|
|
218
|
+
let offOutcome: (() => void) | null = null;
|
|
219
|
+
const dataPort = (): SomaDataPort | undefined => {
|
|
220
|
+
const port = (ctx.services as { data?: SomaDataPort } | undefined)?.data;
|
|
221
|
+
return port && typeof port === 'object' ? port : undefined;
|
|
222
|
+
};
|
|
223
|
+
const notifyPort = (): { toast?: (o: { level: string; message: string }) => void } | undefined =>
|
|
224
|
+
(ctx.services as { notify?: { toast?: (o: { level: string; message: string }) => void } } | undefined)?.notify;
|
|
225
|
+
|
|
226
|
+
const config = (): KitKanbanConfig => {
|
|
227
|
+
const p = P();
|
|
228
|
+
return kanbanConfigOf(p.group, p.lanes, p.card, p.wip);
|
|
229
|
+
};
|
|
230
|
+
const idField = (): string => str(P().id_field, 'id') || 'id';
|
|
231
|
+
const locked = (): boolean => bool(P().disabled);
|
|
232
|
+
const softWip = (): boolean => str(P().wip_mode) === 'soft';
|
|
233
|
+
const idOf = (r: Row): string => str(r[idField()]);
|
|
234
|
+
const dndPort = (): DragPortLike | null => {
|
|
235
|
+
const engines = (ctx.services as { engines?: { dnd?: DragPortLike } } | undefined)?.engines;
|
|
236
|
+
return engines?.dnd ?? null;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const laneRows = (cfg: KitKanbanConfig, lane: string): Row[] => {
|
|
240
|
+
const list = rows.filter((r) => idOf(r) !== '' && str(r[cfg.group]) === lane);
|
|
241
|
+
const f = str(P().order);
|
|
242
|
+
if (f === '') return list;
|
|
243
|
+
const key = (r: Row): number => { const n = Number(r[f]); return Number.isFinite(n) ? n : Number.MAX_SAFE_INTEGER; };
|
|
244
|
+
return list.map((r, i) => ({ r, i })).sort((a, b) => key(a.r) - key(b.r) || a.i - b.i).map((x) => x.r);
|
|
245
|
+
};
|
|
246
|
+
const announce = (text: string): void => { if (live) live.textContent = text; };
|
|
247
|
+
const showNotice = (text: string): void => {
|
|
248
|
+
if (!noticeEl) return;
|
|
249
|
+
noticeEl.textContent = text;
|
|
250
|
+
noticeEl.className = text === '' ? HIDDEN_CLASS : NOTICE_CLASS;
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
const clearTrack = (): void => {
|
|
254
|
+
snaps = [];
|
|
255
|
+
begun = 0;
|
|
256
|
+
if (armTimer !== null) { clearTimeout(armTimer); armTimer = null; }
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
/** 写回失败:回弹到最早一次未落定移动之前,并明确提示「排序未保存」+ 原因(成功时不提示) */
|
|
260
|
+
const rollbackMove = (message: string, conflict: boolean): void => {
|
|
261
|
+
const first = snaps[0];
|
|
262
|
+
const several = snaps.length > 1;
|
|
263
|
+
const restore = first !== undefined && snapEpoch === epoch;
|
|
264
|
+
clearTrack();
|
|
265
|
+
const reason = message !== '' ? message
|
|
266
|
+
: kitText(conflict ? 'soma.kit.order_unsaved_conflict' : 'soma.kit.order_unsaved_unknown', undefined, ctx.host);
|
|
267
|
+
const text = kitText('soma.kit.order_unsaved', { reason }, ctx.host);
|
|
268
|
+
if (restore && first !== undefined) {
|
|
269
|
+
rows = first.map((r) => ({ ...r }));
|
|
270
|
+
menuFor = null;
|
|
271
|
+
ctx.emit('change', { value: rows.map((r) => ({ ...r })) });
|
|
272
|
+
}
|
|
273
|
+
showNotice(text);
|
|
274
|
+
announce(text);
|
|
275
|
+
notifyPort()?.toast?.({ level: 'danger', message: text });
|
|
276
|
+
paint();
|
|
277
|
+
// 连着移了好几次、中间结果不可知:以服务端为准重取
|
|
278
|
+
if (several) {
|
|
279
|
+
const object = str(P().object);
|
|
280
|
+
if (object !== '') void dataPort()?.reload([object]);
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
const onOutcome = (scope: string): void => {
|
|
285
|
+
if (snaps.length === 0 || scope !== str(P().object)) return;
|
|
286
|
+
const view = dataPort()?.writeOutcome(scope);
|
|
287
|
+
if (!view) return;
|
|
288
|
+
if (view.status === 'pending') {
|
|
289
|
+
if (view.seq > lastSeq && begun < snaps.length) { lastSeq = view.seq; begun++; }
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
// 只认本组件发起的最近一次写入结果(core 对被新写入顶替的旧 seq 不再回报)
|
|
293
|
+
if (begun === 0 || view.seq !== lastSeq) return;
|
|
294
|
+
if (view.status === 'saved') {
|
|
295
|
+
snaps = snaps.slice(begun);
|
|
296
|
+
begun = 0;
|
|
297
|
+
if (snaps.length === 0) clearTrack();
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (view.status === 'failed' || view.status === 'conflict') rollbackMove(view.message, view.status === 'conflict');
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
/** 登记一次乐观移动(移动前的行快照);没有接数据对象写回(无 object / 无数据端口)时不跟踪 */
|
|
304
|
+
const trackMove = (before: Row[]): void => {
|
|
305
|
+
const port = dataPort();
|
|
306
|
+
if (str(P().object) === '' || !port || typeof port.onWriteOutcome !== 'function') return;
|
|
307
|
+
if (snaps.length === 0) snapEpoch = epoch;
|
|
308
|
+
snaps.push(before);
|
|
309
|
+
offOutcome ??= port.onWriteOutcome(onOutcome);
|
|
310
|
+
if (armTimer !== null) clearTimeout(armTimer);
|
|
311
|
+
// 移动没有接 data.orderMove(一直没有写入开始):不继续等
|
|
312
|
+
armTimer = setTimeout(() => { armTimer = null; if (begun === 0) snaps = []; }, 2000);
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
const sync = (): void => {
|
|
316
|
+
const p = P();
|
|
317
|
+
const src = Array.isArray(p.value) ? p.value : p.data;
|
|
318
|
+
const next = JSON.stringify([src, p.group, idField()]);
|
|
319
|
+
if (next === sig) return;
|
|
320
|
+
sig = next;
|
|
321
|
+
// 数据源(data)被重取替换过:此前的快照不再是服务端真相,失败时不回弹旧快照(value 回写不算)
|
|
322
|
+
const dsig = JSON.stringify(p.data ?? null);
|
|
323
|
+
if (dsig !== dataSig) { dataSig = dsig; epoch++; }
|
|
324
|
+
rows = (Array.isArray(src) ? src : []).filter((r): r is Row => r !== null && typeof r === 'object' && !Array.isArray(r)).map((r) => ({ ...r }));
|
|
325
|
+
menuFor = null;
|
|
326
|
+
showNotice('');
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
/** 把一张卡移到 to 泳道的 index 位;成功返回 true */
|
|
330
|
+
const move = (id: string, to: string, index: number): boolean => {
|
|
331
|
+
if (locked()) return false;
|
|
332
|
+
const cfg = config();
|
|
333
|
+
if (cfg.group === '') return false;
|
|
334
|
+
const row = rows.find((r) => idOf(r) === id);
|
|
335
|
+
if (!row) return false;
|
|
336
|
+
const from = str(row[cfg.group]);
|
|
337
|
+
if (!cfg.lanes.some((l) => l.value === to)) return false;
|
|
338
|
+
const limit = cfg.wip[to];
|
|
339
|
+
if (from !== to && limit !== undefined && laneRows(cfg, to).length >= limit) {
|
|
340
|
+
const laneLabel = cfg.lanes.find((l) => l.value === to)?.label ?? to;
|
|
341
|
+
if (!softWip()) {
|
|
342
|
+
const msg = kitText('soma.kit.wip_limit', { lane: laneLabel, n: limit }, ctx.host);
|
|
343
|
+
announce(msg);
|
|
344
|
+
showNotice(msg);
|
|
345
|
+
ctx.emit('wip_blocked', { id, to, limit });
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
// 软上限:只提示与抛事件,移入照常进行(超限的计数由 paint 标红)
|
|
349
|
+
const msg = kitText('soma.kit.wip_exceeded', { lane: laneLabel, n: limit }, ctx.host);
|
|
350
|
+
announce(msg);
|
|
351
|
+
showNotice(msg);
|
|
352
|
+
ctx.emit('wip_exceeded', { id, to, limit });
|
|
353
|
+
}
|
|
354
|
+
const peers = laneRows(cfg, to).filter((r) => idOf(r) !== id);
|
|
355
|
+
const position = Math.max(0, Math.min(index, peers.length));
|
|
356
|
+
const next = moveKanbanCard(rows, idField(), cfg.group, id, to, position);
|
|
357
|
+
if (!next) return false;
|
|
358
|
+
// 同泳道原位不动:不抛事件
|
|
359
|
+
if (from === to && laneRows(cfg, to).findIndex((r) => idOf(r) === id) === position) return false;
|
|
360
|
+
const orderField = str(P().order);
|
|
361
|
+
// 有排序字段:position 是序值(落点相邻两卡的中点 / 首卡 - 1 / 末卡 + 1 / 空泳道 0),否则退化为泳道内下标
|
|
362
|
+
const seq = orderField !== '' ? kanbanOrderValue(peers.map((r) => Number(r[orderField])), position) : position;
|
|
363
|
+
const before = rows;
|
|
364
|
+
rows = orderField !== '' ? next.map((r) => (idOf(r) === id ? { ...r, [orderField]: seq } : r)) : next;
|
|
365
|
+
// 先登记快照再抛事件:写入可能在 emit 内同步开始,失败结果要能找到回弹点
|
|
366
|
+
trackMove(before);
|
|
367
|
+
menuFor = null;
|
|
368
|
+
tabKey = id;
|
|
369
|
+
pendingFocus = id;
|
|
370
|
+
ctx.emit('move', {
|
|
371
|
+
id, from, to, index: position,
|
|
372
|
+
target: id,
|
|
373
|
+
...(orderField !== '' ? { orderField } : {}),
|
|
374
|
+
position: seq,
|
|
375
|
+
set: { [cfg.group]: to },
|
|
376
|
+
object: str(P().object),
|
|
377
|
+
});
|
|
378
|
+
ctx.emit('change', { value: rows.map((r) => ({ ...r })) });
|
|
379
|
+
showNotice('');
|
|
380
|
+
announce(kitText('soma.kit.moved_to', { lane: cfg.lanes.find((l) => l.value === to)?.label ?? to, n: position + 1 }, ctx.host));
|
|
381
|
+
paint();
|
|
382
|
+
return true;
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
const el = <K extends keyof HTMLElementTagNameMap>(tag: K, className: string, text?: string): HTMLElementTagNameMap[K] => {
|
|
386
|
+
const node = document.createElement(tag);
|
|
387
|
+
if (className !== '') node.className = className;
|
|
388
|
+
if (text !== undefined) node.textContent = text;
|
|
389
|
+
return node;
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
const cardKeys = (cfg: KitKanbanConfig): string[][] => cfg.lanes.map((l) => laneRows(cfg, l.value).map(idOf));
|
|
393
|
+
|
|
394
|
+
const buildCard = (cfg: KitKanbanConfig, row: Row, lane: string, hasDnd: boolean): HTMLElement => {
|
|
395
|
+
const id = idOf(row);
|
|
396
|
+
const card = el('div', hasDnd && !locked() ? `${CARD_CLASS} ${CARD_DRAG_CLASS}` : CARD_CLASS);
|
|
397
|
+
card.id = `${uid}-card-${encodeURIComponent(id).replace(/%/g, '_')}`;
|
|
398
|
+
card.setAttribute('role', 'group');
|
|
399
|
+
card.setAttribute('data-kit-key', id);
|
|
400
|
+
card.setAttribute('data-kit-lane', lane);
|
|
401
|
+
card.tabIndex = tabKey === id ? 0 : -1;
|
|
402
|
+
const title = cfg.title !== '' ? str(row[cfg.title]) || id : id;
|
|
403
|
+
card.setAttribute('aria-label', title);
|
|
404
|
+
card.appendChild(el('div', CARD_TITLE_CLASS, title));
|
|
405
|
+
for (const f of cfg.fields) {
|
|
406
|
+
const v = row[f.field];
|
|
407
|
+
if (v === undefined || v === null || v === '') continue;
|
|
408
|
+
const line = el('div', FACT_CLASS);
|
|
409
|
+
line.appendChild(el('span', '', f.label));
|
|
410
|
+
line.appendChild(el('span', FACT_VALUE_CLASS, str(v)));
|
|
411
|
+
card.appendChild(line);
|
|
412
|
+
}
|
|
413
|
+
if (!hasDnd && !locked()) {
|
|
414
|
+
const btn = el('button', MOVE_BTN_CLASS, str(P().move_label) || kitText('soma.kit.move_to', undefined, ctx.host));
|
|
415
|
+
btn.type = 'button';
|
|
416
|
+
btn.setAttribute('data-kit-move', id);
|
|
417
|
+
btn.setAttribute('aria-haspopup', 'menu');
|
|
418
|
+
btn.setAttribute('aria-expanded', menuFor === id ? 'true' : 'false');
|
|
419
|
+
card.appendChild(btn);
|
|
420
|
+
if (menuFor === id) {
|
|
421
|
+
const menu = el('div', MENU_CLASS);
|
|
422
|
+
menu.setAttribute('role', 'menu');
|
|
423
|
+
for (const l of cfg.lanes) {
|
|
424
|
+
const item = el('button', MENU_ITEM_CLASS, l.label);
|
|
425
|
+
item.type = 'button';
|
|
426
|
+
item.setAttribute('role', 'menuitem');
|
|
427
|
+
item.setAttribute('data-kit-to', l.value);
|
|
428
|
+
const full = !softWip() && l.value !== lane && cfg.wip[l.value] !== undefined && laneRows(cfg, l.value).length >= cfg.wip[l.value]!;
|
|
429
|
+
if (l.value === lane || full) item.disabled = true;
|
|
430
|
+
menu.appendChild(item);
|
|
431
|
+
}
|
|
432
|
+
card.appendChild(menu);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
return card;
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
function paint(): void {
|
|
439
|
+
if (!root || !board) return;
|
|
440
|
+
const p = P();
|
|
441
|
+
root.className = joinClass(ROOT_CLASS, p.class);
|
|
442
|
+
for (const fn of cleanups) fn();
|
|
443
|
+
cleanups = [];
|
|
444
|
+
// 重绘会重建全部节点:焦点原本在卡片内(含其按钮)时记下卡主键,重绘后还回去(props 更新 / 点移动钮不丢焦点)
|
|
445
|
+
if (pendingFocus === null) {
|
|
446
|
+
const active = document.activeElement;
|
|
447
|
+
if (active instanceof HTMLElement && board.contains(active)) {
|
|
448
|
+
pendingFocus = active.closest<HTMLElement>('[data-kit-key]')?.getAttribute('data-kit-key') ?? null;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
const cfg = config();
|
|
452
|
+
const port = dndPort();
|
|
453
|
+
const hasDnd = port !== null;
|
|
454
|
+
const emptyText = str(p.empty_text, kitText('soma.kit.empty_card', undefined, ctx.host));
|
|
455
|
+
const keys = cardKeys(cfg);
|
|
456
|
+
const all = keys.flat();
|
|
457
|
+
if (tabKey === null || !all.includes(tabKey)) tabKey = all[0] ?? null;
|
|
458
|
+
|
|
459
|
+
board.textContent = '';
|
|
460
|
+
for (const lane of cfg.lanes) {
|
|
461
|
+
const list = laneRows(cfg, lane.value);
|
|
462
|
+
const limit = cfg.wip[lane.value];
|
|
463
|
+
const over = limit !== undefined && list.length > limit;
|
|
464
|
+
const col = el('section', LANE_CLASS);
|
|
465
|
+
col.setAttribute('aria-label', lane.label);
|
|
466
|
+
col.setAttribute('data-kit-lane-box', lane.value);
|
|
467
|
+
const head = el('div', LANE_HEAD_CLASS);
|
|
468
|
+
head.appendChild(el('span', LANE_TITLE_CLASS, lane.label));
|
|
469
|
+
head.appendChild(el('span', over ? COUNT_OVER_CLASS : COUNT_CLASS, limit !== undefined ? `${list.length}/${limit}` : String(list.length)));
|
|
470
|
+
col.appendChild(head);
|
|
471
|
+
const body = el('div', LANE_BODY_CLASS);
|
|
472
|
+
body.setAttribute('data-kit-lane-body', lane.value);
|
|
473
|
+
if (list.length === 0) {
|
|
474
|
+
const empty = el('div', EMPTY_CLASS, emptyText);
|
|
475
|
+
empty.setAttribute('role', 'status');
|
|
476
|
+
body.appendChild(empty);
|
|
477
|
+
}
|
|
478
|
+
for (const row of list) body.appendChild(buildCard(cfg, row, lane.value, hasDnd));
|
|
479
|
+
col.appendChild(body);
|
|
480
|
+
board.appendChild(col);
|
|
481
|
+
|
|
482
|
+
if (port && !locked()) {
|
|
483
|
+
const over2 = (on: boolean) => (): void => { for (const c of DROP_CLASS.split(' ')) body.classList.toggle(c, on); };
|
|
484
|
+
cleanups.push(port.dropTarget(body, { id: `${uid}:lane:${lane.value}`, onOver: over2(true), onLeave: over2(false) }));
|
|
485
|
+
for (const node of body.querySelectorAll<HTMLElement>('[data-kit-key]')) {
|
|
486
|
+
const key = node.getAttribute('data-kit-key')!;
|
|
487
|
+
cleanups.push(port.draggable(node, { id: `${uid}:card:${key}`, data: () => ({ id: key, lane: lane.value }) }));
|
|
488
|
+
cleanups.push(port.dropTarget(node, { id: `${uid}:card:${key}`, edges: ['top', 'bottom'] }));
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
if (cfg.lanes.length === 0) board.appendChild(el('div', EMPTY_CLASS, emptyText));
|
|
493
|
+
|
|
494
|
+
if (pendingFocus !== null) {
|
|
495
|
+
const target = [...board.querySelectorAll<HTMLElement>('[data-kit-key]')].find((n) => n.getAttribute('data-kit-key') === pendingFocus);
|
|
496
|
+
pendingFocus = null;
|
|
497
|
+
target?.focus();
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
const intentMove = (intent: { sourceId: string; targetId: string; edge: unknown }): void => {
|
|
502
|
+
const cardPrefix = `${uid}:card:`;
|
|
503
|
+
const lanePrefix = `${uid}:lane:`;
|
|
504
|
+
if (!intent.sourceId.startsWith(cardPrefix)) return;
|
|
505
|
+
const id = intent.sourceId.slice(cardPrefix.length);
|
|
506
|
+
const cfg = config();
|
|
507
|
+
if (intent.targetId.startsWith(lanePrefix)) {
|
|
508
|
+
const to = intent.targetId.slice(lanePrefix.length);
|
|
509
|
+
move(id, to, laneRows(cfg, to).filter((r) => idOf(r) !== id).length);
|
|
510
|
+
} else if (intent.targetId.startsWith(cardPrefix)) {
|
|
511
|
+
const tid = intent.targetId.slice(cardPrefix.length);
|
|
512
|
+
const trow = rows.find((r) => idOf(r) === tid);
|
|
513
|
+
if (!trow || tid === id) return;
|
|
514
|
+
const to = str(trow[cfg.group]);
|
|
515
|
+
const peers = laneRows(cfg, to).filter((r) => idOf(r) !== id);
|
|
516
|
+
const at = peers.findIndex((r) => idOf(r) === tid);
|
|
517
|
+
move(id, to, at + (intent.edge === 'bottom' ? 1 : 0));
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
const focusCard = (id: string | undefined): void => {
|
|
522
|
+
if (id === undefined || !board) return;
|
|
523
|
+
tabKey = id;
|
|
524
|
+
for (const n of board.querySelectorAll<HTMLElement>('[data-kit-key]')) n.tabIndex = n.getAttribute('data-kit-key') === id ? 0 : -1;
|
|
525
|
+
[...board.querySelectorAll<HTMLElement>('[data-kit-key]')].find((n) => n.getAttribute('data-kit-key') === id)?.focus();
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
const onKeydown = (event: Event): void => {
|
|
529
|
+
const e = event as KeyboardEvent;
|
|
530
|
+
if (e.isComposing) return;
|
|
531
|
+
const target = e.target as HTMLElement | null;
|
|
532
|
+
// 菜单内:↑↓ 走项、Esc 关闭,其余交给按钮本身
|
|
533
|
+
const menuItem = target?.closest<HTMLElement>('[role="menuitem"]');
|
|
534
|
+
const cardEl = target?.closest<HTMLElement>('[data-kit-key]');
|
|
535
|
+
if (!cardEl) return;
|
|
536
|
+
const id = cardEl.getAttribute('data-kit-key')!;
|
|
537
|
+
if (menuItem) {
|
|
538
|
+
const items = [...cardEl.querySelectorAll<HTMLButtonElement>('[role="menuitem"]')].filter((b) => !b.disabled);
|
|
539
|
+
const at = items.indexOf(menuItem as HTMLButtonElement);
|
|
540
|
+
if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); menuFor = null; pendingFocus = id; paint(); return; }
|
|
541
|
+
if (e.key === 'ArrowDown') { e.preventDefault(); items[(at + 1) % items.length]?.focus(); return; }
|
|
542
|
+
if (e.key === 'ArrowUp') { e.preventDefault(); items[(at - 1 + items.length) % items.length]?.focus(); return; }
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
if (e.key === 'Escape' && menuFor === id) { e.preventDefault(); e.stopPropagation(); menuFor = null; pendingFocus = id; paint(); return; }
|
|
546
|
+
if (target !== cardEl) return; // 卡内的按钮自己处理
|
|
547
|
+
const cfg = config();
|
|
548
|
+
const keys = cardKeys(cfg);
|
|
549
|
+
const li = keys.findIndex((k) => k.includes(id));
|
|
550
|
+
if (li < 0) return;
|
|
551
|
+
const ci = keys[li]!.indexOf(id);
|
|
552
|
+
const lane = cfg.lanes[li]!.value;
|
|
553
|
+
const key = e.key;
|
|
554
|
+
if (key === 'Enter' || key === ' ') {
|
|
555
|
+
e.preventDefault();
|
|
556
|
+
ctx.emit('select', { id, item: rows.find((r) => idOf(r) === id) ?? {} });
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
if ((key === 'm' || key === 'M') && !e.altKey && !e.ctrlKey && !e.metaKey && !dndPort() && !locked()) {
|
|
560
|
+
e.preventDefault();
|
|
561
|
+
menuFor = menuFor === id ? null : id;
|
|
562
|
+
pendingFocus = menuFor === null ? id : null;
|
|
563
|
+
paint();
|
|
564
|
+
if (menuFor !== null) {
|
|
565
|
+
[...board!.querySelectorAll<HTMLElement>('[data-kit-key]')].find((n) => n.getAttribute('data-kit-key') === id)
|
|
566
|
+
?.querySelector<HTMLElement>('[role="menuitem"]:not(:disabled)')?.focus();
|
|
567
|
+
}
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
const horizontal = key === 'ArrowLeft' ? -1 : key === 'ArrowRight' ? 1 : 0;
|
|
571
|
+
const vertical = key === 'ArrowUp' ? -1 : key === 'ArrowDown' ? 1 : 0;
|
|
572
|
+
if (horizontal === 0 && vertical === 0) return;
|
|
573
|
+
e.preventDefault();
|
|
574
|
+
if (e.altKey) {
|
|
575
|
+
if (horizontal !== 0) {
|
|
576
|
+
const nl = cfg.lanes[li + horizontal];
|
|
577
|
+
if (nl) move(id, nl.value, laneRows(cfg, nl.value).length);
|
|
578
|
+
} else {
|
|
579
|
+
move(id, lane, ci + vertical);
|
|
580
|
+
}
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
if (vertical !== 0) { focusCard(keys[li]![ci + vertical]); return; }
|
|
584
|
+
let nl = li + horizontal;
|
|
585
|
+
while (nl >= 0 && nl < keys.length && keys[nl]!.length === 0) nl += horizontal;
|
|
586
|
+
const col = keys[nl];
|
|
587
|
+
if (col) focusCard(col[Math.min(ci, col.length - 1)]);
|
|
588
|
+
};
|
|
589
|
+
|
|
590
|
+
const onClick = (event: Event): void => {
|
|
591
|
+
const target = event.target as HTMLElement | null;
|
|
592
|
+
if (!target) return;
|
|
593
|
+
const toBtn = target.closest<HTMLElement>('[data-kit-to]');
|
|
594
|
+
const cardEl = target.closest<HTMLElement>('[data-kit-key]');
|
|
595
|
+
if (toBtn && cardEl) {
|
|
596
|
+
move(cardEl.getAttribute('data-kit-key')!, toBtn.getAttribute('data-kit-to')!, laneRows(config(), toBtn.getAttribute('data-kit-to')!).length);
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
const moveBtn = target.closest<HTMLElement>('[data-kit-move]');
|
|
600
|
+
if (moveBtn) {
|
|
601
|
+
const id = moveBtn.getAttribute('data-kit-move')!;
|
|
602
|
+
menuFor = menuFor === id ? null : id;
|
|
603
|
+
paint();
|
|
604
|
+
if (menuFor !== null) {
|
|
605
|
+
[...board!.querySelectorAll<HTMLElement>('[data-kit-key]')].find((n) => n.getAttribute('data-kit-key') === id)
|
|
606
|
+
?.querySelector<HTMLElement>('[role="menuitem"]:not(:disabled)')?.focus();
|
|
607
|
+
}
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
if (cardEl) {
|
|
611
|
+
const id = cardEl.getAttribute('data-kit-key')!;
|
|
612
|
+
tabKey = id;
|
|
613
|
+
ctx.emit('select', { id, item: rows.find((r) => idOf(r) === id) ?? {} });
|
|
614
|
+
}
|
|
615
|
+
};
|
|
616
|
+
|
|
617
|
+
return {
|
|
618
|
+
onMount(): void {
|
|
619
|
+
root = findRoot(ctx.host);
|
|
620
|
+
root.textContent = '';
|
|
621
|
+
noticeEl = el('div', HIDDEN_CLASS);
|
|
622
|
+
noticeEl.setAttribute('role', 'alert');
|
|
623
|
+
noticeEl.setAttribute('data-kit-wip-notice', '');
|
|
624
|
+
board = el('div', BOARD_CLASS);
|
|
625
|
+
live = el('div', LIVE_CLASS);
|
|
626
|
+
live.setAttribute('role', 'status');
|
|
627
|
+
live.setAttribute('aria-live', 'polite');
|
|
628
|
+
root.appendChild(noticeEl);
|
|
629
|
+
root.appendChild(board);
|
|
630
|
+
root.appendChild(live);
|
|
631
|
+
const on = (type: string, fn: (event: Event) => void): void => {
|
|
632
|
+
board!.addEventListener(type, fn);
|
|
633
|
+
const b = board!;
|
|
634
|
+
removers.push(() => b.removeEventListener(type, fn));
|
|
635
|
+
};
|
|
636
|
+
on('keydown', onKeydown);
|
|
637
|
+
on('click', onClick);
|
|
638
|
+
const port = dndPort();
|
|
639
|
+
if (port) offMove = port.onMove(intentMove);
|
|
640
|
+
// 右键菜单(页面声明了 contextMenu 才有宿主壳):按卡主键取行
|
|
641
|
+
removers.push(provideCtxRows(root, (key) => rows.find((r) => idOf(r) === key)));
|
|
642
|
+
sync();
|
|
643
|
+
paint();
|
|
644
|
+
},
|
|
645
|
+
onPropsChange(): void {
|
|
646
|
+
sync();
|
|
647
|
+
paint();
|
|
648
|
+
},
|
|
649
|
+
onUnmount(): void {
|
|
650
|
+
for (const fn of cleanups) fn();
|
|
651
|
+
cleanups = [];
|
|
652
|
+
for (const fn of removers) fn();
|
|
653
|
+
removers = [];
|
|
654
|
+
offMove?.();
|
|
655
|
+
offMove = null;
|
|
656
|
+
offOutcome?.();
|
|
657
|
+
offOutcome = null;
|
|
658
|
+
clearTrack();
|
|
659
|
+
root = null;
|
|
660
|
+
noticeEl = null;
|
|
661
|
+
board = null;
|
|
662
|
+
live = null;
|
|
663
|
+
},
|
|
664
|
+
};
|
|
665
|
+
},
|
|
666
|
+
};
|
|
667
|
+
}
|