soma-kit 0.1.10 → 0.1.12
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 +103 -110
- package/bin/soma-kit.mjs +1 -1
- package/bin/soma.mjs +22 -0
- package/package.json +13 -7
- package/packs/finance/reconcile-board.ts +5 -2
- package/packs/finance/reconcile-desk/compile.ts +3 -2
- package/spec/generated/kit-app.schema.json +776 -38
- package/spec/generated/kit-page.schema.json +1613 -224
- package/spec/kit-grammar.json +770 -529
- package/spec/kit-grammar.schema.json +1962 -392
- package/src/app/app-config.ts +371 -347
- package/src/app/component-gate.ts +12 -15
- package/src/app/compose-apps.ts +79 -8
- package/src/app/define-kit-actions.ts +245 -41
- package/src/app/define-kit-app.ts +174 -31
- package/src/app/define-kit-view.ts +100 -0
- package/src/app/envelope.ts +1 -161
- package/src/app/index.ts +13 -2
- package/src/app/kit-view-context.ts +290 -0
- package/src/app/notify-renderer.ts +1 -115
- package/src/app/paged-list-adapter.ts +1 -240
- package/src/app/server-pages.ts +8 -2
- package/src/app/server.ts +491 -101
- package/src/app/submit.types.ts +1 -1
- package/src/app/theme-endpoint.ts +63 -0
- package/src/app/theme-runtime-shared.ts +1 -0
- package/src/app/theme-runtime.ts +663 -0
- package/src/base/action-busy.ts +2 -2
- package/src/base/action-gate.ts +4 -255
- package/src/base/action-slots.ts +47 -0
- package/src/base/alert.ts +5 -3
- package/src/base/avatar.ts +2 -2
- package/src/base/button.ts +46 -29
- package/src/base/cascader.ts +11 -12
- package/src/base/check-core.ts +1 -1
- package/src/base/choice.ts +28 -26
- package/src/base/class-candidates.ts +17 -0
- package/src/base/color-picker.ts +6 -6
- package/src/base/combobox.ts +5 -3
- package/src/base/command-palette.ts +9 -5
- package/src/base/countdown.ts +1 -1
- package/src/base/date-range.ts +25 -11
- package/src/base/date.ts +85 -17
- package/src/base/divider.ts +2 -2
- package/src/base/fab.ts +11 -4
- package/src/base/image.ts +1 -1
- package/src/base/index.ts +9 -3
- package/src/base/input.ts +42 -13
- package/src/base/kbd.ts +3 -1
- package/src/base/link.ts +4 -4
- package/src/base/listbox-core.ts +50 -30
- package/src/base/loading-gate.ts +133 -0
- package/src/base/mentions.ts +5 -5
- package/src/base/menu-button.ts +6 -1
- package/src/base/menu-core.ts +4 -0
- package/src/base/motion/aura.ts +2 -2
- package/src/base/motion/hover-3d.ts +2 -2
- package/src/base/motion/hover-gallery.ts +2 -2
- package/src/base/motion/marquee.ts +2 -2
- package/src/base/motion/text-rotate.ts +2 -2
- package/src/base/number.ts +93 -80
- package/src/base/otp.ts +4 -1
- package/src/base/permission-gate.ts +6 -0
- package/src/base/popover.ts +40 -8
- package/src/base/popup.ts +79 -14
- package/src/base/price-text.ts +2 -2
- package/src/base/progress.ts +2 -2
- package/src/base/qr-code.ts +4 -4
- package/src/base/qty-stepper.ts +9 -3
- package/src/base/range.ts +2 -2
- package/src/base/rating.ts +1 -1
- package/src/base/segmented.ts +4 -0
- package/src/base/select.ts +4 -3
- package/src/base/shared.ts +221 -29
- package/src/base/swap.ts +4 -1
- package/src/base/switch.ts +1 -1
- package/src/base/tag-input.ts +14 -10
- package/src/base/tag.ts +5 -1
- package/src/base/text.ts +39 -6
- package/src/base/textarea.ts +37 -11
- package/src/base/time-picker.ts +12 -9
- package/src/base/tree-select.ts +15 -8
- package/src/base/upload.ts +34 -5
- package/src/base/virtual-list.ts +107 -1
- package/src/biz/approval-desk/compile.ts +23 -41
- package/src/biz/auth-panel/compile.ts +37 -52
- package/src/biz/auth-panel/index.ts +1 -1
- package/src/biz/category-crud/compile.ts +22 -36
- package/src/biz/checkout-page/compile.ts +21 -5
- package/src/biz/compose.ts +13 -27
- package/src/biz/define.ts +5 -4
- package/src/biz/import-wizard/compile.ts +22 -26
- package/src/biz/import-wizard/hub.ts +126 -61
- package/src/biz/import-wizard/shell.ts +3 -3
- package/src/biz/index.ts +3 -3
- package/src/biz/landing-page/compile.ts +19 -3
- package/src/biz/link/hub.ts +49 -20
- package/src/biz/link/shared.ts +115 -118
- package/src/biz/master-sub/compile.ts +31 -44
- package/src/biz/multi-board/compile.ts +34 -49
- package/src/biz/multi-board/index.ts +18 -1
- package/src/biz/multi-board/shell.ts +24 -15
- package/src/biz/notification-center/compile.ts +21 -33
- package/src/biz/page-templates/domain-templates.ts +80 -13
- package/src/biz/page-templates/result-page/compile.ts +11 -2
- package/src/biz/page-templates/shared.ts +34 -36
- package/src/biz/record-detail/compile.ts +47 -42
- package/src/biz/record-detail/index.ts +11 -1
- package/src/biz/settings-center/compile.ts +6 -5
- package/src/biz/shared/action-host.ts +91 -211
- package/src/biz/shared/compile-helpers.ts +80 -0
- package/src/biz/shared/coordinator.ts +486 -83
- package/src/biz/shared/index.ts +8 -2
- package/src/biz/shared/overlay-shell.ts +80 -0
- package/src/biz/shared/pipes.ts +43 -30
- package/src/biz/shared/remove-key.ts +6 -0
- package/src/biz/shared/remove-wire.ts +29 -0
- package/src/biz/shared/runtime-hub.ts +216 -24
- package/src/biz/single-form/compile.ts +15 -37
- package/src/biz/standard-crud/compile.ts +62 -107
- package/src/biz/standard-crud/shell.ts +16 -66
- package/src/biz/step-form/compile.ts +26 -97
- package/src/biz/step-form/hub.ts +34 -41
- package/src/biz/types.ts +4 -3
- package/src/cli/core-imports.ts +54 -0
- package/src/cli/kit-cli.ts +130 -26
- package/src/cli/kit-init.ts +222 -0
- package/src/cli/service-endpoint-check.ts +425 -0
- package/src/cli/source-path-check.d.mts +17 -0
- package/src/cli/source-path-check.mjs +334 -0
- package/src/cli/view-writes.ts +752 -0
- package/src/compile/action-host-attach.ts +21 -29
- package/src/compile/closed-set.ts +509 -0
- package/src/compile/compile-page.ts +219 -72
- package/src/compile/component-candidates.ts +1 -1
- package/src/compile/hints.ts +30 -1
- package/src/compile/index.ts +1 -0
- package/src/compile/kit-error.ts +1 -0
- package/src/compile/locate.ts +21 -1
- package/src/compile/parse.ts +370 -41
- package/src/compile/redirect.ts +6 -2
- package/src/compile/styles.ts +35 -2
- package/src/compile/types.ts +18 -2
- package/src/compile/view-check.ts +151 -0
- package/src/data/amount-breakdown.ts +2 -2
- package/src/data/anchor-nav.ts +2 -2
- package/src/data/approval-flow.ts +2 -2
- package/src/data/assignment-picker.ts +40 -29
- package/src/data/async-result-panel.ts +62 -6
- package/src/data/breadcrumbs.ts +2 -2
- package/src/data/calendar.ts +22 -25
- package/src/data/carousel.ts +5 -2
- package/src/data/chart.ts +42 -34
- package/src/data/checklist.ts +2 -2
- package/src/data/code-view.ts +4 -2
- package/src/data/comment-thread.ts +5 -2
- package/src/data/confirm-dialog.ts +10 -0
- package/src/data/context-menu.ts +29 -37
- package/src/data/d9-util.ts +2 -18
- package/src/data/diff.ts +4 -2
- package/src/data/dock.ts +2 -2
- package/src/data/embed.ts +2 -1
- package/src/data/field-mapper.ts +31 -26
- package/src/data/flow-editor-contract.ts +1 -1
- package/src/data/flow-editor.ts +89 -100
- package/src/data/flow-node-options.ts +90 -0
- package/src/data/flow-remote-options.ts +0 -103
- package/src/data/footer.ts +2 -2
- package/src/data/form-draft-registry.ts +2 -4
- package/src/data/gantt.ts +14 -17
- package/src/data/hero.ts +2 -2
- package/src/data/image-viewer.ts +20 -26
- package/src/data/index.ts +0 -2
- package/src/data/item-list.ts +31 -22
- package/src/data/kanban.ts +43 -42
- package/src/data/media-grid.ts +14 -19
- package/src/data/menu.ts +2 -2
- package/src/data/mockup.ts +2 -2
- package/src/data/modal-dialog.ts +22 -18
- package/src/data/navbar.ts +7 -2
- package/src/data/notify-renderer.ts +235 -0
- package/src/data/object-form.ts +1036 -648
- package/src/data/pager.ts +65 -29
- package/src/data/permission-matrix.ts +20 -21
- package/src/data/permission-tree.ts +28 -26
- package/src/data/pricing-table.ts +9 -3
- package/src/data/reaction-bar.ts +77 -88
- package/src/data/read-rollback.ts +73 -0
- package/src/data/record-card.ts +3 -3
- package/src/data/record-picker.ts +93 -50
- package/src/data/redirect.ts +32 -32
- package/src/data/remote-options.ts +13 -6
- package/src/data/request-console.ts +5 -3
- package/src/data/resident.ts +2 -1
- package/src/data/result-panel.ts +4 -2
- package/src/data/rich-text.ts +45 -55
- package/src/data/row-editor.ts +285 -52
- package/src/data/rule-builder.ts +18 -12
- package/src/data/shape-util.ts +4 -0
- package/src/data/stat-group.ts +243 -101
- package/src/data/static-registry.ts +22 -11
- package/src/data/steps.ts +2 -2
- package/src/data/survey.ts +24 -29
- package/src/data/system-switcher.ts +2 -2
- package/src/data/timeline.ts +2 -2
- package/src/data/tour-guide.ts +22 -29
- package/src/data/transfer.ts +27 -23
- package/src/data/tree-table.ts +96 -48
- package/src/data/tree.ts +27 -34
- package/src/data/trend-line.ts +6 -24
- package/src/data/virtual-rows.ts +118 -76
- package/src/data/watermark.ts +2 -2
- package/src/data/wrap.ts +63 -38
- package/src/frames/blank-frame.ts +1 -0
- package/src/frames/index.ts +2 -2
- package/src/frames/page-bar.ts +12 -11
- package/src/frames/page-header.ts +14 -5
- package/src/frames/page-status.ts +2 -2
- package/src/frames/shared.ts +23 -17
- package/src/frames/single-frame.ts +1 -0
- package/src/frames/split-frame/shell.ts +5 -5
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +2 -13
- package/src/frames/tabs-frame/wiring.ts +4 -8
- package/src/frames/top-main-frame.ts +1 -0
- package/src/frames/types.ts +13 -2
- package/src/frames/workspace-frame/extras.ts +20 -4
- package/src/frames/workspace-frame/index.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +1 -0
- package/src/frames/workspace-frame/state.ts +13 -6
- package/src/frames/workspace-frame/view.ts +119 -25
- package/src/generated/kit-grammar-runtime.ts +430 -366
- package/src/generated/page-origin.ts +0 -11
- package/src/i18n/kit-text.ts +23 -27
- package/src/index.ts +2 -1
- package/src/object-renderer/action-gate.ts +11 -147
- package/src/object-renderer/arrange.ts +71 -77
- package/src/object-renderer/collapse-wiring.ts +2 -2
- package/src/object-renderer/collection-expand.ts +2 -2
- package/src/object-renderer/collection-parts.ts +216 -100
- package/src/object-renderer/collection-table.ts +180 -42
- package/src/object-renderer/collection.ts +95 -79
- package/src/object-renderer/compile-data.ts +85 -100
- package/src/object-renderer/crud-bridge.ts +32 -0
- package/src/object-renderer/defaults.ts +8 -14
- package/src/object-renderer/display-checks.ts +3 -24
- package/src/object-renderer/emit-events.ts +186 -172
- package/src/object-renderer/emit-object.ts +15 -2
- package/src/object-renderer/emit-static.ts +174 -132
- package/src/object-renderer/field-value.ts +593 -396
- package/src/object-renderer/filter-reload.ts +70 -0
- package/src/object-renderer/form-detail.ts +112 -2
- package/src/object-renderer/index.ts +26 -0
- package/src/object-renderer/key-field.ts +12 -0
- package/src/object-renderer/linkage.ts +7 -270
- package/src/object-renderer/merge-class.ts +18 -1
- package/src/object-renderer/path-pick.ts +27 -0
- package/src/object-renderer/render-object.ts +405 -86
- package/src/object-renderer/request-actions.ts +230 -249
- package/src/object-renderer/table-actions.ts +195 -95
- package/src/object-renderer/table-summary.ts +2 -2
- package/src/object-renderer/table-tools.ts +418 -84
- package/src/object-renderer/types.ts +128 -122
- package/src/object-renderer/view-binding.ts +196 -0
- package/src/page-target/ai-surface.ts +37 -0
- package/src/page-target/compile.ts +48 -8
- package/src/page-target/index.ts +8 -1
- package/src/page-target/intent-schema.ts +154 -28
- package/src/page-target/target.ts +257 -50
- package/src/page-target/writer-policy.ts +14 -3
- package/src/recipes/container.ts +165 -0
- package/src/recipes/control.ts +219 -0
- package/src/recipes/index.ts +263 -0
- package/src/recipes/overlay.ts +182 -0
- package/src/recipes/state.ts +70 -0
- package/src/recipes/table-row.ts +51 -0
- package/src/recipes/typography.ts +87 -0
- package/src/shared/action-field-guard.ts +41 -0
- package/src/shared/envelope.ts +207 -0
- package/src/shared/escape.ts +57 -0
- package/src/shared/kit-error.ts +21 -0
- package/src/shared/paged-list-adapter.ts +240 -0
- package/src/shared/path-guard.ts +127 -0
- package/src/shared/theme-runtime-shared.ts +175 -0
- package/src/shared/view-info.ts +10 -0
- package/src/theme/index.ts +12 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +38 -1
- package/src/theme/kit-theme.tpl +38 -1
- package/src/theme/nine-dim-structure.ts +77 -0
- package/src/theme/surface-layers.ts +97 -0
- package/src/theme/theme-tokens.ts +85 -79
- package/src/theme/theme-types.ts +71 -0
- package/src/theme/typography.ts +17 -17
- package/src/biz/shared/step-values.ts +0 -25
- package/src/biz/step-form/steps-ref.ts +0 -112
- package/src/data/options-bus.ts +0 -24
- package/src/data/prompt-dialog.ts +0 -235
- package/src/object-renderer/adopt-gate.ts +0 -333
- package/src/object-renderer/field-policy.ts +0 -89
- package/src/object-renderer/outcome-draft.ts +0 -61
- package/src/theme/nine-dim-palettes.ts +0 -1278
package/src/base/choice.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
6
|
applyCommon, bool, nextUid, optionsKey, optionsOf, sameValue, setAttr, sizeOf, str, joinClass,
|
|
7
|
-
type KitApi, type KitOption, type KitProps, type KitSize, type KitView,
|
|
7
|
+
type KitApi, type KitOption, type KitProps, type KitSize, type KitView, type KitViewSetup,
|
|
8
8
|
} from './shared';
|
|
9
9
|
import { attachMarkEvents, createCheck, markChecked, markInput, paintCheck } from './check-core';
|
|
10
10
|
|
|
@@ -119,31 +119,33 @@ function paint(kind: ChoiceKind, root: HTMLElement, p: KitProps): void {
|
|
|
119
119
|
* Radio `variant: segmented`(分段切换)与 Checkbox `variant: buttons`(多选按钮组)改画成按钮(见 segmented.ts)。
|
|
120
120
|
* 两套事件监听都挂在根上,各认各的元素(原生 input / 按钮),形态切换时清空根重建。
|
|
121
121
|
*/
|
|
122
|
-
export function createChoiceView(kind: ChoiceKind):
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
122
|
+
export function createChoiceView(kind: ChoiceKind): KitViewSetup {
|
|
123
|
+
return () => {
|
|
124
|
+
const native = createNativeChoiceView(kind);
|
|
125
|
+
const buttons = kind === 'radio' ? createSegmentedView() : createToggleView();
|
|
126
|
+
const variant = kind === 'radio' ? 'segmented' : 'buttons';
|
|
127
|
+
return {
|
|
128
|
+
attach(root, api) {
|
|
129
|
+
const a = native.attach?.(root, api);
|
|
130
|
+
const b = buttons.attach?.(root, api);
|
|
131
|
+
return () => {
|
|
132
|
+
if (a) a();
|
|
133
|
+
if (b) b();
|
|
134
|
+
};
|
|
135
|
+
},
|
|
136
|
+
render(root, p, api) {
|
|
137
|
+
const mode = p.variant === variant ? variant : 'native';
|
|
138
|
+
if (root.dataset.kitChoiceMode !== mode) {
|
|
139
|
+
// 形态切换:清掉另一形态的 DOM 与缓存键
|
|
140
|
+
root.textContent = '';
|
|
141
|
+
delete root.dataset.kitChoices;
|
|
142
|
+
delete root.dataset.kitSegKey;
|
|
143
|
+
delete root.dataset.kitTogKey;
|
|
144
|
+
root.dataset.kitChoiceMode = mode;
|
|
145
|
+
}
|
|
146
|
+
(mode === 'native' ? native : buttons).render(root, p, api);
|
|
147
|
+
},
|
|
148
|
+
};
|
|
147
149
|
};
|
|
148
150
|
}
|
|
149
151
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// 样式候选类收集辅助函数:纯函数,零依赖,叶子模块。
|
|
2
|
+
// 供基础组件与配方层(recipes)收集 Tailwind 类名候选集,避免与 base/shared.ts 产生循环依赖。
|
|
3
|
+
|
|
4
|
+
export function classCandidates(
|
|
5
|
+
...lists: ReadonlyArray<string | readonly string[] | undefined | null>
|
|
6
|
+
): readonly string[] {
|
|
7
|
+
const set = new Set<string>();
|
|
8
|
+
for (const item of lists) {
|
|
9
|
+
if (!item) continue;
|
|
10
|
+
const parts = typeof item === 'string' ? [item] : item;
|
|
11
|
+
for (const part of parts) {
|
|
12
|
+
if (!part) continue;
|
|
13
|
+
for (const c of part.split(/\s+/)) if (c !== '') set.add(c);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return Object.freeze([...set]);
|
|
17
|
+
}
|
package/src/base/color-picker.ts
CHANGED
|
@@ -125,18 +125,18 @@ export function createColorPicker(): SomaComponentDefinition {
|
|
|
125
125
|
},
|
|
126
126
|
templateHtml:
|
|
127
127
|
`<div data-soma-id="root" class="${ROOT}">` +
|
|
128
|
-
`<button data-soma-id="trigger" type="button" class="${TRIGGER.md}"><span data-soma-id="chip"></span><span data-soma-id="text" class="${TRIGGER_TEXT}"></span></button>` +
|
|
128
|
+
`<button data-soma-id="trigger" type="button" data-kit-face="field" class="${TRIGGER.md}"><span data-soma-id="chip"></span><span data-soma-id="text" class="${TRIGGER_TEXT}"></span></button>` +
|
|
129
129
|
`<div data-soma-id="panel" class="${HIDDEN}">` +
|
|
130
130
|
`<div data-soma-id="presets" role="listbox" aria-orientation="horizontal" class="${PRESETS}"></div>` +
|
|
131
131
|
`<div data-soma-id="custom" class="${HIDDEN}">` +
|
|
132
|
-
`<input data-soma-id="hex" type="text" autocomplete="off" spellcheck="false" maxlength="7" class="${CUSTOM_INPUT}" />` +
|
|
132
|
+
`<input data-soma-id="hex" type="text" autocomplete="off" spellcheck="false" maxlength="7" data-kit-face="field" class="${CUSTOM_INPUT}" />` +
|
|
133
133
|
`<div data-soma-id="error" class="${HIDDEN}"></div></div></div></div>`,
|
|
134
|
-
controllerFactory: (
|
|
134
|
+
controllerFactory: createKitController((api) => {
|
|
135
135
|
let builtKey = '';
|
|
136
136
|
let chipKey: string | null = null;
|
|
137
137
|
let layer: ReturnType<typeof wirePopLayer> | null = null;
|
|
138
138
|
let lastEmit: string | null = null;
|
|
139
|
-
return
|
|
139
|
+
return {
|
|
140
140
|
attach(root, api) {
|
|
141
141
|
const trigger = part(root, 'trigger');
|
|
142
142
|
const panel = part(root, 'panel');
|
|
@@ -310,7 +310,7 @@ export function createColorPicker(): SomaComponentDefinition {
|
|
|
310
310
|
root.className = joinClass(ROOT, p.class);
|
|
311
311
|
layer?.sync();
|
|
312
312
|
},
|
|
313
|
-
}
|
|
314
|
-
},
|
|
313
|
+
};
|
|
314
|
+
}),
|
|
315
315
|
};
|
|
316
316
|
}
|
package/src/base/combobox.ts
CHANGED
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
// change { value, label, free },value 取选项原值(multiple 时是原值数组,label 是本次切换那一项的文字)。
|
|
16
16
|
|
|
17
17
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
18
|
-
import { CLASS_PROP, ID_PROPS, OPTIONS_PROP, SIZE_PROP } from './shared';
|
|
19
|
-
import { KIT_LISTBOX_CLASS_CANDIDATES,
|
|
18
|
+
import { CLASS_PROP, ID_PROPS, INVALID_PROPS, OPTIONS_PROP, SIZE_PROP, createKitController } from './shared';
|
|
19
|
+
import { KIT_LISTBOX_CLASS_CANDIDATES, createListboxView } from './listbox-core';
|
|
20
20
|
|
|
21
21
|
export { chipSlice, comboFilter } from './listbox-core';
|
|
22
22
|
|
|
@@ -42,10 +42,12 @@ export function createCombobox(): SomaComponentDefinition {
|
|
|
42
42
|
empty_text: { type: 'string', default: '', desc: '无结果提示' },
|
|
43
43
|
virtual: { type: 'boolean', default: false, desc: '长选项列表虚拟滚动(面板只画窗口内的选项,走 core 虚拟滚动端口;按固定行高 row_height 档位;带 group 分组或加载中时不虚拟化;引擎不可用时回退为普通渲染并在控制台提示一次)' },
|
|
44
44
|
row_height: { type: 'enum', values: ['sm', 'md', 'lg'], default: 'md', desc: 'virtual 时选项行的固定行高档位(档位名,不接受像素)' },
|
|
45
|
+
options_query: { type: 'string', default: '', desc: '宿主回填 options 时带回这批选项对应的搜索关键词(取自 search 事件的 query);与当前输入不一致时组件忽略这批选项。不传(缺省空串)则不做比对(保持原行为);仅远程搜索(组件已抛过 search)时生效' },
|
|
45
46
|
search_delay: { type: 'string', default: '', desc: '搜索事件去抖毫秒数,缺省 0' },
|
|
46
47
|
disabled: { type: 'boolean', default: false },
|
|
47
48
|
readonly: { type: 'boolean', default: false },
|
|
48
49
|
...ID_PROPS,
|
|
50
|
+
...INVALID_PROPS,
|
|
49
51
|
size: SIZE_PROP,
|
|
50
52
|
class: CLASS_PROP,
|
|
51
53
|
},
|
|
@@ -56,6 +58,6 @@ export function createCombobox(): SomaComponentDefinition {
|
|
|
56
58
|
},
|
|
57
59
|
services: ['engines'],
|
|
58
60
|
templateHtml: '<div data-soma-id="root" class="relative block w-full"></div>',
|
|
59
|
-
controllerFactory:
|
|
61
|
+
controllerFactory: createKitController(createListboxView('combobox')),
|
|
60
62
|
};
|
|
61
63
|
}
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
13
13
|
import { kitText } from '../i18n/kit-text';
|
|
14
|
+
import { setKitFace, setKitFixed } from '../recipes';
|
|
14
15
|
import type { CollectionItem } from 'soma-core/keyboard';
|
|
15
16
|
import {
|
|
16
17
|
EMPTY_ROW_CLASS, cssEscape, createListNav, optionClass, scrollIntoViewIfAny,
|
|
@@ -24,7 +25,7 @@ const ROOT = 'inline-block';
|
|
|
24
25
|
const TRIGGER = 'inline-flex h-9 cursor-pointer items-center gap-3 rounded-md border border-border bg-surface px-3 text-sm text-fg-muted transition-colors hover:bg-surface-sunken focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60';
|
|
25
26
|
const TRIGGER_KEYS = 'rounded-sm border border-border-subtle bg-surface-sunken px-1.5 py-0.5 text-xs text-fg-subtle';
|
|
26
27
|
const HIDDEN = 'hidden';
|
|
27
|
-
const OVERLAY = 'fixed inset-0 z-50 flex items-start justify-center bg-
|
|
28
|
+
const OVERLAY = 'fixed inset-0 z-50 flex items-start justify-center bg-scrim p-4';
|
|
28
29
|
const DIALOG = 'mt-24 flex max-h-96 w-full max-w-lg flex-col overflow-hidden rounded-lg border border-border-subtle bg-surface-raised shadow-lg motion-safe:animate-kit-rise';
|
|
29
30
|
const SEARCH = 'block h-10 w-full appearance-none autofill-clear border-b border-border-subtle bg-transparent px-4 text-sm text-fg placeholder:text-fg-subtle focus-visible:outline-none';
|
|
30
31
|
const LIST = 'min-h-0 flex-1 overflow-auto py-1';
|
|
@@ -126,7 +127,7 @@ export function createCommandPalette(): SomaComponentDefinition {
|
|
|
126
127
|
`<input data-soma-id="search" type="text" role="combobox" aria-expanded="true" aria-autocomplete="list" autocomplete="off" class="${SEARCH}" />` +
|
|
127
128
|
`<div data-soma-id="list" role="listbox" class="${LIST}"></div>` +
|
|
128
129
|
`<div data-soma-id="status" role="status" class="${STATUS}"></div></div></div></div>`,
|
|
129
|
-
controllerFactory: (
|
|
130
|
+
controllerFactory: createKitController((api) => {
|
|
130
131
|
let open = false;
|
|
131
132
|
let query = '';
|
|
132
133
|
let cursor: string | null = null;
|
|
@@ -136,7 +137,7 @@ export function createCommandPalette(): SomaComponentDefinition {
|
|
|
136
137
|
let paintFn: (() => void) | null = null;
|
|
137
138
|
let setOpenFn: ((next: boolean) => void) | null = null;
|
|
138
139
|
|
|
139
|
-
return
|
|
140
|
+
return {
|
|
140
141
|
attach(root, api) {
|
|
141
142
|
const trigger = part(root, 'trigger') as HTMLButtonElement;
|
|
142
143
|
const overlay = part(root, 'overlay');
|
|
@@ -212,6 +213,7 @@ export function createCommandPalette(): SomaComponentDefinition {
|
|
|
212
213
|
|
|
213
214
|
const paint = (): void => {
|
|
214
215
|
overlay.className = open ? OVERLAY : HIDDEN;
|
|
216
|
+
setKitFixed(overlay, open); // 仅展开时才是 fixed:闲置态不抑制祖先毛玻璃
|
|
215
217
|
trigger.setAttribute('aria-expanded', open ? 'true' : 'false');
|
|
216
218
|
if (open) {
|
|
217
219
|
paintList();
|
|
@@ -352,6 +354,8 @@ export function createCommandPalette(): SomaComponentDefinition {
|
|
|
352
354
|
trigger.append(text, keys);
|
|
353
355
|
}
|
|
354
356
|
trigger.className = label === '' ? HIDDEN : TRIGGER;
|
|
357
|
+
// 触发钮带边框与底色,同 Button 标 raised(隐藏时无害)
|
|
358
|
+
setKitFace(trigger, 'raised');
|
|
355
359
|
trigger.disabled = bool(p.disabled);
|
|
356
360
|
applyCommon(trigger, { id: p.id });
|
|
357
361
|
dialog.setAttribute('aria-label', str(p.label, kitText('soma.kit.command_palette', undefined, root)));
|
|
@@ -365,7 +369,7 @@ export function createCommandPalette(): SomaComponentDefinition {
|
|
|
365
369
|
}
|
|
366
370
|
paintFn?.();
|
|
367
371
|
},
|
|
368
|
-
}
|
|
369
|
-
},
|
|
372
|
+
};
|
|
373
|
+
}),
|
|
370
374
|
};
|
|
371
375
|
}
|
package/src/base/countdown.ts
CHANGED
|
@@ -163,6 +163,6 @@ export function createCountdown(): SomaComponentDefinition {
|
|
|
163
163
|
},
|
|
164
164
|
},
|
|
165
165
|
templateHtml: `<span data-soma-id="root" role="timer" class="${ROOT_CLASS.md}"><span class="${HIDDEN}"></span><span aria-hidden="true" class="${DIGITS_CLASS}"></span><span aria-live="polite" class="${SR_CLASS}"></span></span>`,
|
|
166
|
-
controllerFactory: (
|
|
166
|
+
controllerFactory: createKitController(() => makeView()),
|
|
167
167
|
};
|
|
168
168
|
}
|
package/src/base/date-range.ts
CHANGED
|
@@ -10,13 +10,14 @@
|
|
|
10
10
|
|
|
11
11
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
12
12
|
import {
|
|
13
|
-
CLASS_PROP, ID_PROPS, SIZE_PROP,
|
|
14
|
-
bool, classCandidates, createKitController, joinClass, setAttr, sizeOf, str, type KitApi, type KitProps, type KitSize,
|
|
13
|
+
CLASS_PROP, FIELD_INVALID_CLASS, ID_PROPS, INVALID_PROPS, SIZE_PROP,
|
|
14
|
+
applyCommon, bool, classCandidates, createKitController, joinClass, setAttr, sizeOf, str, withInvalid, type KitApi, type KitProps, type KitSize,
|
|
15
15
|
} from './shared';
|
|
16
16
|
import {
|
|
17
17
|
KIT_DATE_CLASS_CANDIDATES, createDatePanel, disabledRulesOf, isDateDisabled, isDateOutOfBounds, isIsoDay, localIso, type DatePanel,
|
|
18
18
|
} from './date';
|
|
19
19
|
import { weekStartProp } from './month-grid';
|
|
20
|
+
import { setKitFace } from '../recipes';
|
|
20
21
|
import { kitText, type KitTextKey } from '../i18n/kit-text';
|
|
21
22
|
|
|
22
23
|
const RANGE_CLASS: Record<KitSize, string> = {
|
|
@@ -47,7 +48,7 @@ const PRESET_CLASS = {
|
|
|
47
48
|
|
|
48
49
|
export const KIT_DATE_RANGE_CLASS_CANDIDATES: readonly string[] = classCandidates(
|
|
49
50
|
Object.values(RANGE_CLASS), FIELDS_CLASS, HIDDEN_CLASS, Object.values(DATE_CLASS), Object.values(OPEN_BTN_CLASS), ICON_CLASS,
|
|
50
|
-
PRESETS_CLASS, Object.values(PRESET_CLASS), KIT_DATE_CLASS_CANDIDATES,
|
|
51
|
+
PRESETS_CLASS, Object.values(PRESET_CLASS), KIT_DATE_CLASS_CANDIDATES, FIELD_INVALID_CLASS,
|
|
51
52
|
);
|
|
52
53
|
|
|
53
54
|
interface Range { start: string; end: string }
|
|
@@ -157,6 +158,8 @@ function paintPresets(root: HTMLElement, p: KitProps, range: Range, editable: bo
|
|
|
157
158
|
const target = presetRange(preset);
|
|
158
159
|
const pressed = range.start === target.start && range.end === target.end;
|
|
159
160
|
btn.className = pressed ? PRESET_CLASS.pressed : PRESET_CLASS.idle;
|
|
161
|
+
// 按下态是 soft 浅底(有面)标 raised;闲置态无底无边(ghost)不标
|
|
162
|
+
setKitFace(btn, pressed ? 'raised' : null);
|
|
160
163
|
btn.setAttribute('aria-pressed', pressed ? 'true' : 'false');
|
|
161
164
|
btn.disabled = !editable || !presetUsable(target, p);
|
|
162
165
|
}
|
|
@@ -210,11 +213,11 @@ function textBad(text: string, p: KitProps): 'format' | 'bounds' | null {
|
|
|
210
213
|
return isDateOutOfBounds(text, str(p.min), str(p.max)) ? 'bounds' : null;
|
|
211
214
|
}
|
|
212
215
|
|
|
213
|
-
function markInvalid(root: HTMLElement, el: HTMLInputElement, bad: 'format' | 'bounds' | null, ruleBad: boolean): void {
|
|
216
|
+
function markInvalid(root: HTMLElement, el: HTMLInputElement, bad: 'format' | 'bounds' | null, ruleBad: boolean, propInvalid = false): void {
|
|
214
217
|
const msg = bad === 'format' ? kitText('soma.kit.dp_invalid', undefined, root)
|
|
215
218
|
: bad === 'bounds' || ruleBad ? kitText('soma.kit.date_disabled', undefined, root) : '';
|
|
216
219
|
el.setCustomValidity(msg);
|
|
217
|
-
if (msg !== '') el.setAttribute('aria-invalid', 'true'); else el.removeAttribute('aria-invalid');
|
|
220
|
+
if (msg !== '' || propInvalid) el.setAttribute('aria-invalid', 'true'); else el.removeAttribute('aria-invalid');
|
|
218
221
|
}
|
|
219
222
|
|
|
220
223
|
function paint(root: HTMLElement, p: KitProps, ui: Ui): void {
|
|
@@ -236,18 +239,25 @@ function paint(root: HTMLElement, p: KitProps, ui: Ui): void {
|
|
|
236
239
|
[ui.startEl, ui.hiddenStart, label === '' ? '' : kitText('soma.kit.dr_start', { label }, root)],
|
|
237
240
|
[ui.endEl, ui.hiddenEnd, label === '' ? '' : kitText('soma.kit.dr_end', { label }, root)],
|
|
238
241
|
];
|
|
242
|
+
const propInvalid = bool(p.invalid);
|
|
239
243
|
for (const [el, hidden, aria] of pairs) {
|
|
240
|
-
el.
|
|
244
|
+
const bad = textBad(el.value.trim(), p);
|
|
245
|
+
const ruleBad = el.value.trim() !== '' && isDateDisabled(el.value.trim(), rules);
|
|
246
|
+
el.className = withInvalid(DATE_CLASS[size], propInvalid || bad !== null || ruleBad);
|
|
241
247
|
el.placeholder = placeholder;
|
|
242
248
|
el.readOnly = readonly;
|
|
243
249
|
el.disabled = off;
|
|
244
250
|
if (off) el.setAttribute('aria-disabled', 'true'); else el.removeAttribute('aria-disabled');
|
|
245
|
-
|
|
251
|
+
applyCommon(el, {
|
|
252
|
+
...p,
|
|
253
|
+
id: el === ui.startEl ? str(p.id) : '',
|
|
254
|
+
name: '',
|
|
255
|
+
aria_label: aria,
|
|
256
|
+
});
|
|
246
257
|
hidden.value = el === ui.startEl ? ui.synced.start : ui.synced.end;
|
|
247
258
|
hidden.disabled = off;
|
|
248
|
-
markInvalid(root, el,
|
|
259
|
+
markInvalid(root, el, bad, ruleBad, propInvalid);
|
|
249
260
|
}
|
|
250
|
-
setAttr(ui.startEl, 'id', str(p.id));
|
|
251
261
|
setAttr(ui.hiddenStart, 'name', name === '' ? '' : `${name}_start`);
|
|
252
262
|
setAttr(ui.hiddenEnd, 'name', name === '' ? '' : `${name}_end`);
|
|
253
263
|
ui.btn.className = OPEN_BTN_CLASS[size];
|
|
@@ -271,6 +281,7 @@ function build(root: HTMLElement, api: KitApi): () => void {
|
|
|
271
281
|
i.type = 'text';
|
|
272
282
|
i.autocomplete = 'off';
|
|
273
283
|
i.spellcheck = false;
|
|
284
|
+
setKitFace(i, 'field');
|
|
274
285
|
return i;
|
|
275
286
|
};
|
|
276
287
|
const mkHidden = (): HTMLInputElement => {
|
|
@@ -289,6 +300,8 @@ function build(root: HTMLElement, api: KitApi): () => void {
|
|
|
289
300
|
btn.type = 'button';
|
|
290
301
|
btn.setAttribute('aria-haspopup', 'dialog');
|
|
291
302
|
btn.setAttribute('aria-expanded', 'false');
|
|
303
|
+
// 独立的描边方钮(OPEN_BTN_CLASS 带 border + bg-surface),与 Button 一样标 raised
|
|
304
|
+
setKitFace(btn, 'raised');
|
|
292
305
|
btn.appendChild(calendarIcon());
|
|
293
306
|
box.append(startEl, toEl, endEl, hiddenStart, hiddenEnd, btn);
|
|
294
307
|
root.appendChild(box);
|
|
@@ -422,6 +435,7 @@ export function createDateRange(): SomaComponentDefinition {
|
|
|
422
435
|
disabled: { type: 'boolean', default: false },
|
|
423
436
|
readonly: { type: 'boolean', default: false },
|
|
424
437
|
...ID_PROPS,
|
|
438
|
+
...INVALID_PROPS,
|
|
425
439
|
size: SIZE_PROP,
|
|
426
440
|
class: CLASS_PROP,
|
|
427
441
|
},
|
|
@@ -431,7 +445,7 @@ export function createDateRange(): SomaComponentDefinition {
|
|
|
431
445
|
},
|
|
432
446
|
},
|
|
433
447
|
templateHtml: `<div data-soma-id="root" role="group" class="${RANGE_CLASS.md}"></div>`,
|
|
434
|
-
controllerFactory: createKitController({
|
|
448
|
+
controllerFactory: createKitController(() => ({
|
|
435
449
|
attach(root, api) {
|
|
436
450
|
return build(root, api);
|
|
437
451
|
},
|
|
@@ -439,6 +453,6 @@ export function createDateRange(): SomaComponentDefinition {
|
|
|
439
453
|
const ui = uis.get(root);
|
|
440
454
|
if (ui) paint(root, p, ui);
|
|
441
455
|
},
|
|
442
|
-
}),
|
|
456
|
+
})),
|
|
443
457
|
};
|
|
444
458
|
}
|
package/src/base/date.ts
CHANGED
|
@@ -17,10 +17,11 @@ import {
|
|
|
17
17
|
addMonths, dayFullName, dayNumOf, monthFirstOf, monthGridCells, monthGridStep, monthTitle, textOfDayNum, weekStartProp, weekdayHeads,
|
|
18
18
|
} from './month-grid';
|
|
19
19
|
import {
|
|
20
|
-
CLASS_PROP, ID_PROPS, SIZE_PROP,
|
|
21
|
-
classCandidates, bool, createKitController, joinClass, nextUid, setAttr, sizeOf, str, type KitApi, type KitProps, type KitSize,
|
|
20
|
+
CLASS_PROP, FIELD_INVALID_CLASS, ID_PROPS, INVALID_PROPS, SIZE_PROP,
|
|
21
|
+
applyCommon, classCandidates, bool, createKitController, joinClass, nextUid, setAttr, sizeOf, str, withInvalid, type KitApi, type KitProps, type KitSize,
|
|
22
22
|
} from './shared';
|
|
23
23
|
import { kitIcon } from './icons';
|
|
24
|
+
import { setKitFace } from '../recipes';
|
|
24
25
|
import { KIT_DROPDOWN_CLASS_CANDIDATES, focusCellQuiet, handoffTab, onOutsidePress, releaseDropdown, syncDropdown, trackInputModality } from './popup';
|
|
25
26
|
|
|
26
27
|
// ── 类串(整串写死,进候选类清单)──────────────────────────────
|
|
@@ -59,7 +60,7 @@ const DAY_CLASS = {
|
|
|
59
60
|
} as const;
|
|
60
61
|
const FOOT_CLASS = 'flex items-center justify-between gap-2';
|
|
61
62
|
// 文字钮用底色表示键盘焦点,不用环
|
|
62
|
-
const TODAY_BTN_CLASS = 'border-0 bg-transparent cursor-pointer rounded-md px-2 py-1 text-sm text-primary transition-colors hover:bg-surface-sunken focus-visible:bg-surface-sunken focus-visible:outline-none';
|
|
63
|
+
const TODAY_BTN_CLASS = 'border-0 bg-transparent cursor-pointer rounded-md px-2 py-1 text-sm text-primary-on-soft transition-colors hover:bg-surface-sunken focus-visible:bg-surface-sunken focus-visible:outline-none';
|
|
63
64
|
// 状态文字不再可见(R7):只给读屏播报
|
|
64
65
|
const STATUS_CLASS = { sr: 'sr-only' } as const;
|
|
65
66
|
|
|
@@ -69,7 +70,7 @@ const focusCell = focusCellQuiet;
|
|
|
69
70
|
export const KIT_DATE_CLASS_CANDIDATES: readonly string[] = classCandidates(
|
|
70
71
|
ROOT_CLASS, HIDDEN_CLASS, Object.values(INPUT_CLASS), OPEN_BTN_CLASS, CLEAR_BTN_CLASS, ICON_CLASS, PANEL_BASE, MONTHS_CLASS, MONTH_CLASS,
|
|
71
72
|
MONTH_HEAD_CLASS, MONTH_TITLE_CLASS, NAV_CLASS, NAV_SPACER_CLASS, NAV_GLYPH_CLASS, ROW_CLASS, HEADCELL_CLASS, SPACER_CELL_CLASS,
|
|
72
|
-
Object.values(DAY_CLASS), FOOT_CLASS, TODAY_BTN_CLASS, Object.values(STATUS_CLASS), 'pointer-events-auto', KIT_DROPDOWN_CLASS_CANDIDATES,
|
|
73
|
+
Object.values(DAY_CLASS), FOOT_CLASS, TODAY_BTN_CLASS, Object.values(STATUS_CLASS), 'pointer-events-auto', KIT_DROPDOWN_CLASS_CANDIDATES, FIELD_INVALID_CLASS,
|
|
73
74
|
);
|
|
74
75
|
|
|
75
76
|
// ── 禁用日期规则(Date / DateRange 共用)────────────────────────
|
|
@@ -90,6 +91,17 @@ export function isIsoDay(raw: string): boolean {
|
|
|
90
91
|
return !Number.isNaN(d.getTime()) && d.toISOString().slice(0, 10) === raw;
|
|
91
92
|
}
|
|
92
93
|
|
|
94
|
+
const LOOSE_DAY = /^(\d{4})[-/.](\d{1,2})[-/.](\d{1,2})$/;
|
|
95
|
+
const COMPACT_DAY = /^(\d{4})(\d{2})(\d{2})$/;
|
|
96
|
+
|
|
97
|
+
/** 宽松手输日期(YYYY/M/D、YYYY.M.D、YYYY-M-D、YYYYMMDD)归一成真实存在的 YYYY-MM-DD;认不出返回 null */
|
|
98
|
+
export function parseLooseDay(raw: string): string | null {
|
|
99
|
+
const m = LOOSE_DAY.exec(raw) ?? COMPACT_DAY.exec(raw);
|
|
100
|
+
if (!m) return null;
|
|
101
|
+
const iso = `${m[1]}-${m[2]!.padStart(2, '0')}-${m[3]!.padStart(2, '0')}`;
|
|
102
|
+
return isIsoDay(iso) ? iso : null;
|
|
103
|
+
}
|
|
104
|
+
|
|
93
105
|
/** 本地日期的 YYYY-MM-DD */
|
|
94
106
|
export function localIso(d: Date): string {
|
|
95
107
|
const mm = String(d.getMonth() + 1).padStart(2, '0');
|
|
@@ -557,13 +569,18 @@ interface FieldState {
|
|
|
557
569
|
ariaLabel: string;
|
|
558
570
|
/** 命令式调用方换掉文本框整串类 */
|
|
559
571
|
fieldClass: string;
|
|
572
|
+
invalid: boolean;
|
|
573
|
+
required: boolean;
|
|
574
|
+
describedby: string;
|
|
575
|
+
errormessage: string;
|
|
560
576
|
}
|
|
561
577
|
|
|
562
578
|
interface FieldHooks {
|
|
563
579
|
read(): FieldState;
|
|
564
580
|
/** value 已写进文本框;typed = 来自键入(原生 change 已冒泡,不必再派发) */
|
|
565
581
|
commit(value: string, typed: boolean): void;
|
|
566
|
-
|
|
582
|
+
/** reason 缺省 = 被禁日期(disabled_date);无法解析的手输文本传 'unparsable' */
|
|
583
|
+
reject(value: string, reason?: string): void;
|
|
567
584
|
}
|
|
568
585
|
|
|
569
586
|
interface FieldUi {
|
|
@@ -600,6 +617,8 @@ function buildDateField(root: HTMLElement, hooks: FieldHooks): FieldUi {
|
|
|
600
617
|
const input = document.createElement('input');
|
|
601
618
|
input.type = 'text';
|
|
602
619
|
input.autocomplete = 'off';
|
|
620
|
+
// 质感标记:带边框的是 input 自己(右侧开关钮 / 清除钮无边无底在其内)
|
|
621
|
+
setKitFace(input, 'field');
|
|
603
622
|
input.spellcheck = false;
|
|
604
623
|
const hidden = document.createElement('input');
|
|
605
624
|
hidden.type = 'hidden';
|
|
@@ -612,7 +631,11 @@ function buildDateField(root: HTMLElement, hooks: FieldHooks): FieldUi {
|
|
|
612
631
|
clear.type = 'button';
|
|
613
632
|
clear.appendChild(kitIcon('close', 'sm'));
|
|
614
633
|
clear.className = HIDDEN_CLASS;
|
|
615
|
-
|
|
634
|
+
// 还原提示的礼貌播报位(仅读屏可听):还原后的值有效,不标 aria-invalid
|
|
635
|
+
const note = document.createElement('p');
|
|
636
|
+
note.setAttribute('role', 'status');
|
|
637
|
+
note.className = STATUS_CLASS.sr;
|
|
638
|
+
root.append(input, hidden, btn, clear, note);
|
|
616
639
|
|
|
617
640
|
let synced = '';
|
|
618
641
|
let internal = false;
|
|
@@ -634,10 +657,14 @@ function buildDateField(root: HTMLElement, hooks: FieldHooks): FieldUi {
|
|
|
634
657
|
btn.setAttribute('aria-controls', panel.el.id);
|
|
635
658
|
btn.setAttribute('aria-expanded', 'false');
|
|
636
659
|
|
|
660
|
+
/** 手输文本无法解析被还原后,保持一次无效提示;用户下一次输入或聚焦时清除 */
|
|
661
|
+
let rejectedHint = false;
|
|
662
|
+
|
|
637
663
|
function setValue(value: string, typed: boolean): void {
|
|
638
664
|
const s = hooks.read();
|
|
639
665
|
if (!canEdit(s)) return;
|
|
640
666
|
if (!typed && value === synced) return;
|
|
667
|
+
rejectedHint = false;
|
|
641
668
|
internal = true;
|
|
642
669
|
input.value = value;
|
|
643
670
|
synced = value;
|
|
@@ -649,12 +676,16 @@ function buildDateField(root: HTMLElement, hooks: FieldHooks): FieldUi {
|
|
|
649
676
|
|
|
650
677
|
function paintValidity(s: FieldState, text: string): void {
|
|
651
678
|
let msg = '';
|
|
679
|
+
note.textContent = rejectedHint ? kitText('soma.kit.dp_reverted', undefined, root) : '';
|
|
652
680
|
if (text !== '') {
|
|
653
681
|
if (!isIsoDay(text)) msg = kitText('soma.kit.dp_invalid', undefined, root);
|
|
654
682
|
else if (isDateOutOfBounds(text, s.min, s.max) || isDateDisabled(text, s.rules)) msg = kitText('soma.kit.date_disabled', undefined, root);
|
|
655
683
|
}
|
|
656
684
|
input.setCustomValidity(msg);
|
|
657
|
-
|
|
685
|
+
const bad = msg !== '' || s.invalid;
|
|
686
|
+
if (bad) input.setAttribute('aria-invalid', 'true'); else input.removeAttribute('aria-invalid');
|
|
687
|
+
const baseCls = s.fieldClass !== '' ? s.fieldClass : INPUT_CLASS[s.size];
|
|
688
|
+
input.className = withInvalid(baseCls, bad);
|
|
658
689
|
}
|
|
659
690
|
|
|
660
691
|
const onInputChange = (): void => {
|
|
@@ -664,7 +695,9 @@ function buildDateField(root: HTMLElement, hooks: FieldHooks): FieldUi {
|
|
|
664
695
|
input.value = synced;
|
|
665
696
|
return;
|
|
666
697
|
}
|
|
667
|
-
const
|
|
698
|
+
const typedText = input.value.trim();
|
|
699
|
+
// 提交输入(回车 / 失焦触发 change)时先做宽松解析并归一
|
|
700
|
+
const raw = parseLooseDay(typedText) ?? typedText;
|
|
668
701
|
if (raw === synced) {
|
|
669
702
|
input.value = raw;
|
|
670
703
|
paintValidity(s, raw);
|
|
@@ -674,8 +707,17 @@ function buildDateField(root: HTMLElement, hooks: FieldHooks): FieldUi {
|
|
|
674
707
|
setValue('', true);
|
|
675
708
|
return;
|
|
676
709
|
}
|
|
677
|
-
if (!isIsoDay(raw)
|
|
678
|
-
//
|
|
710
|
+
if (!isIsoDay(raw)) {
|
|
711
|
+
// 仍无法解析:把文本还原成上一个有效值,屏幕显示与草稿一致,不抛 change;还原后值有效(不标 aria-invalid),只礼貌播报「已恢复原日期」并抛 reject(带被拒原文)
|
|
712
|
+
input.value = synced;
|
|
713
|
+
rejectedHint = true;
|
|
714
|
+
paintValidity(s, synced);
|
|
715
|
+
hooks.reject(raw, 'unparsable');
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
if (isDateOutOfBounds(raw, s.min, s.max)) {
|
|
719
|
+
// 日期真实但越界:文本留着让人改,带 aria-invalid,不抛 change
|
|
720
|
+
input.value = raw;
|
|
679
721
|
paintValidity(s, raw);
|
|
680
722
|
return;
|
|
681
723
|
}
|
|
@@ -687,6 +729,11 @@ function buildDateField(root: HTMLElement, hooks: FieldHooks): FieldUi {
|
|
|
687
729
|
}
|
|
688
730
|
setValue(raw, true);
|
|
689
731
|
};
|
|
732
|
+
const clearRejectedHint = (): void => {
|
|
733
|
+
if (!rejectedHint) return;
|
|
734
|
+
rejectedHint = false;
|
|
735
|
+
paintValidity(hooks.read(), input.value.trim());
|
|
736
|
+
};
|
|
690
737
|
const onInputKeydown = (event: KeyboardEvent): void => {
|
|
691
738
|
const s = hooks.read();
|
|
692
739
|
if (event.key === 'ArrowDown' && canEdit(s) && !panel.isOpen()) {
|
|
@@ -708,6 +755,8 @@ function buildDateField(root: HTMLElement, hooks: FieldHooks): FieldUi {
|
|
|
708
755
|
input.focus();
|
|
709
756
|
};
|
|
710
757
|
input.addEventListener('change', onInputChange);
|
|
758
|
+
input.addEventListener('input', clearRejectedHint);
|
|
759
|
+
input.addEventListener('focus', clearRejectedHint);
|
|
711
760
|
input.addEventListener('keydown', onInputKeydown);
|
|
712
761
|
btn.addEventListener('click', onBtnClick);
|
|
713
762
|
clear.addEventListener('click', onClear);
|
|
@@ -729,8 +778,15 @@ function buildDateField(root: HTMLElement, hooks: FieldHooks): FieldUi {
|
|
|
729
778
|
input.readOnly = s.readonly;
|
|
730
779
|
input.disabled = s.disabled;
|
|
731
780
|
if (s.disabled) input.setAttribute('aria-disabled', 'true'); else input.removeAttribute('aria-disabled');
|
|
732
|
-
|
|
733
|
-
|
|
781
|
+
applyCommon(input, {
|
|
782
|
+
id: s.id,
|
|
783
|
+
aria_label: s.ariaLabel,
|
|
784
|
+
name: '',
|
|
785
|
+
required: s.required,
|
|
786
|
+
invalid: s.invalid,
|
|
787
|
+
describedby: s.describedby,
|
|
788
|
+
errormessage: s.errormessage,
|
|
789
|
+
});
|
|
734
790
|
btn.disabled = !editable;
|
|
735
791
|
btn.setAttribute('aria-label', kitText('soma.kit.dp_open', undefined, root));
|
|
736
792
|
const showClear = editable && s.clearable && synced !== '';
|
|
@@ -747,6 +803,8 @@ function buildDateField(root: HTMLElement, hooks: FieldHooks): FieldUi {
|
|
|
747
803
|
paint,
|
|
748
804
|
dispose() {
|
|
749
805
|
input.removeEventListener('change', onInputChange);
|
|
806
|
+
input.removeEventListener('input', clearRejectedHint);
|
|
807
|
+
input.removeEventListener('focus', clearRejectedHint);
|
|
750
808
|
input.removeEventListener('keydown', onInputKeydown);
|
|
751
809
|
btn.removeEventListener('click', onBtnClick);
|
|
752
810
|
clear.removeEventListener('click', onClear);
|
|
@@ -755,6 +813,7 @@ function buildDateField(root: HTMLElement, hooks: FieldHooks): FieldUi {
|
|
|
755
813
|
hidden.remove();
|
|
756
814
|
btn.remove();
|
|
757
815
|
clear.remove();
|
|
816
|
+
note.remove();
|
|
758
817
|
},
|
|
759
818
|
};
|
|
760
819
|
}
|
|
@@ -775,6 +834,10 @@ function stateOfProps(p: KitProps): FieldState {
|
|
|
775
834
|
name: str(p.name),
|
|
776
835
|
ariaLabel: str(p.aria_label),
|
|
777
836
|
fieldClass: '',
|
|
837
|
+
invalid: bool(p.invalid),
|
|
838
|
+
required: bool(p.required),
|
|
839
|
+
describedby: str(p.aria_describedby, str(p.describedby)),
|
|
840
|
+
errormessage: str(p.aria_errormessage, str(p.errormessage)),
|
|
778
841
|
};
|
|
779
842
|
}
|
|
780
843
|
|
|
@@ -796,21 +859,22 @@ export function createDate(): SomaComponentDefinition {
|
|
|
796
859
|
disabled: { type: 'boolean', default: false },
|
|
797
860
|
readonly: { type: 'boolean', default: false },
|
|
798
861
|
...ID_PROPS,
|
|
862
|
+
...INVALID_PROPS,
|
|
799
863
|
size: SIZE_PROP,
|
|
800
864
|
class: CLASS_PROP,
|
|
801
865
|
},
|
|
802
866
|
emits: {
|
|
803
867
|
change: { payload: { value: { type: 'string' } }, desc: '日期变化(含清除为空串);disabled / readonly 时不抛' },
|
|
804
|
-
reject: { payload: { value: { type: 'string' }, reason: { type: 'string' } }, desc: '选中了 disabled_dates
|
|
868
|
+
reject: { payload: { value: { type: 'string' }, reason: { type: 'string' } }, desc: '选中了 disabled_dates 命中的日期(reason 为 disabled_date),或手输文本无法解析(reason 为 unparsable,value 为被拒原文):值不变' },
|
|
805
869
|
},
|
|
806
870
|
},
|
|
807
871
|
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
|
|
808
|
-
controllerFactory: createKitController({
|
|
872
|
+
controllerFactory: createKitController(() => ({
|
|
809
873
|
attach(root, api: KitApi) {
|
|
810
874
|
const ui = buildDateField(root, {
|
|
811
875
|
read: () => stateOfProps(api.props()),
|
|
812
876
|
commit: (value) => api.emit('change', { value }),
|
|
813
|
-
reject: (value) => api.emit('reject', { value, reason: 'disabled_date' }),
|
|
877
|
+
reject: (value, reason) => api.emit('reject', { value, reason: reason ?? 'disabled_date' }),
|
|
814
878
|
});
|
|
815
879
|
uis.set(root, ui);
|
|
816
880
|
return () => {
|
|
@@ -822,7 +886,7 @@ export function createDate(): SomaComponentDefinition {
|
|
|
822
886
|
root.className = joinClass(ROOT_CLASS, p.class);
|
|
823
887
|
uis.get(root)?.paint();
|
|
824
888
|
},
|
|
825
|
-
}),
|
|
889
|
+
})),
|
|
826
890
|
};
|
|
827
891
|
}
|
|
828
892
|
|
|
@@ -873,6 +937,10 @@ export function mountKitDateField(opts: KitDateFieldOptions = {}): KitDateField
|
|
|
873
937
|
name: '',
|
|
874
938
|
ariaLabel: '',
|
|
875
939
|
fieldClass: opts.fieldClass ?? '',
|
|
940
|
+
invalid: false,
|
|
941
|
+
required: false,
|
|
942
|
+
describedby: '',
|
|
943
|
+
errormessage: '',
|
|
876
944
|
};
|
|
877
945
|
const ui = buildDateField(root, {
|
|
878
946
|
read: () => st,
|
|
@@ -884,7 +952,7 @@ export function mountKitDateField(opts: KitDateFieldOptions = {}): KitDateField
|
|
|
884
952
|
}
|
|
885
953
|
opts.onChange?.(value);
|
|
886
954
|
},
|
|
887
|
-
reject: (value) => opts.onReject?.(value),
|
|
955
|
+
reject: (value, reason) => { if (reason === undefined) opts.onReject?.(value); },
|
|
888
956
|
});
|
|
889
957
|
ui.paint();
|
|
890
958
|
return {
|
package/src/base/divider.ts
CHANGED
|
@@ -129,7 +129,7 @@ export function createKitDivider(): SomaComponentDefinition {
|
|
|
129
129
|
},
|
|
130
130
|
},
|
|
131
131
|
templateHtml: '<div data-soma-id="root" role="separator" class="block w-full border-t border-border-subtle"></div>',
|
|
132
|
-
controllerFactory: createKitController({
|
|
132
|
+
controllerFactory: createKitController(() => ({
|
|
133
133
|
render(root, p) {
|
|
134
134
|
const plan = dividerPlan(p);
|
|
135
135
|
const doc = root.ownerDocument;
|
|
@@ -151,6 +151,6 @@ export function createKitDivider(): SomaComponentDefinition {
|
|
|
151
151
|
b.setAttribute('aria-hidden', 'true');
|
|
152
152
|
root.append(a, text, b);
|
|
153
153
|
},
|
|
154
|
-
}),
|
|
154
|
+
})),
|
|
155
155
|
};
|
|
156
156
|
}
|