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/data/calendar.ts
CHANGED
|
@@ -6,11 +6,12 @@
|
|
|
6
6
|
// 网格键盘走 core 键盘接线的日期网格:方向键逐日 / 逐周,Home / End 本周首末,PageUp / PageDown 翻月,Shift+PageUp / PageDown 翻年,Enter / Space 选中该日。
|
|
7
7
|
// 事件:点日期格(或 Enter)抛 `date { date, events }`;点事件块抛 `event { id, item }`;翻页 / 切视图抛 `navigate { view, anchor, from, to }`(from / to = 可见区间首末日,页面据此取数)。
|
|
8
8
|
|
|
9
|
-
import type {
|
|
9
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
10
10
|
import { createKeyboardWiring, type CollectionItem } from 'soma-core/keyboard';
|
|
11
11
|
import { SOMA_SIZE_UNITS } from 'soma-foundation/theme';
|
|
12
|
-
import { joinClass, num, str } from '../base/shared';
|
|
12
|
+
import { createKitController, joinClass, num, str } from '../base/shared';
|
|
13
13
|
import { kitText } from '../i18n/kit-text';
|
|
14
|
+
import { setKitFace } from '../recipes';
|
|
14
15
|
import { classTokens, keyMap, mk, rowsOf, shapeToneOf, textOf, TONE_SOFT, type Rec } from './shape-util';
|
|
15
16
|
import { monthGridCells, monthGridRange, monthGridStep, weekdayHeads, type MonthGridRange } from '../base/month-grid';
|
|
16
17
|
import {
|
|
@@ -117,15 +118,14 @@ export function createCalendar(): SomaComponentDefinition {
|
|
|
117
118
|
keyboard: { layout: 'grid', date_grid: true, wrap: false, typeahead: false, focus_model: 'roving', space: 'activate' },
|
|
118
119
|
},
|
|
119
120
|
templateHtml: `<section data-soma-id="root" class="${ROOT_CLASS}"></section>`,
|
|
120
|
-
controllerFactory: (
|
|
121
|
-
const P = (): Record<string, unknown> =>
|
|
121
|
+
controllerFactory: createKitController((api) => {
|
|
122
|
+
const P = (): Record<string, unknown> => api.props();
|
|
122
123
|
let root: HTMLElement | null = null;
|
|
123
124
|
let view: KitCalendarView = 'month';
|
|
124
125
|
let anchor = 0;
|
|
125
126
|
let cursor = 0;
|
|
126
127
|
let selected: number | null = null;
|
|
127
128
|
let last = { view: '', month: '', selected: '' };
|
|
128
|
-
let removeListeners: Array<() => void> = [];
|
|
129
129
|
|
|
130
130
|
const todayNum = (): number => {
|
|
131
131
|
const given = dayNumOf(str(P().today));
|
|
@@ -138,7 +138,7 @@ export function createCalendar(): SomaComponentDefinition {
|
|
|
138
138
|
|
|
139
139
|
const announce = (): void => {
|
|
140
140
|
const r = range();
|
|
141
|
-
|
|
141
|
+
api.emit('navigate', { view, anchor: textOfDayNum(anchor), from: textOfDayNum(r.from), to: textOfDayNum(r.to) });
|
|
142
142
|
};
|
|
143
143
|
|
|
144
144
|
const sync = (): void => {
|
|
@@ -175,7 +175,7 @@ export function createCalendar(): SomaComponentDefinition {
|
|
|
175
175
|
paint();
|
|
176
176
|
focusCursor();
|
|
177
177
|
const events = calendarEventsOf(P().data, P().map).filter((e) => e.from <= n && n <= e.to).map((e) => e.raw);
|
|
178
|
-
|
|
178
|
+
api.emit('date', { date: textOfDayNum(n), events });
|
|
179
179
|
};
|
|
180
180
|
|
|
181
181
|
const pageBy = (dir: number): void => {
|
|
@@ -220,12 +220,15 @@ export function createCalendar(): SomaComponentDefinition {
|
|
|
220
220
|
const head = mk('div', HEAD_CLASS);
|
|
221
221
|
const prev = mk('button', BTN_CLASS, str(p.prev_text, kitText('soma.kit.prev_page', undefined, root)));
|
|
222
222
|
prev.type = 'button';
|
|
223
|
+
setKitFace(prev, 'raised');
|
|
223
224
|
prev.setAttribute('data-kit-nav', 'prev');
|
|
224
225
|
const next = mk('button', BTN_CLASS, str(p.next_text, kitText('soma.kit.next_page', undefined, root)));
|
|
225
226
|
next.type = 'button';
|
|
227
|
+
setKitFace(next, 'raised');
|
|
226
228
|
next.setAttribute('data-kit-nav', 'next');
|
|
227
229
|
const todayBtn = mk('button', BTN_CLASS, str(p.today_text, kitText('soma.kit.cal_today', undefined, root)));
|
|
228
230
|
todayBtn.type = 'button';
|
|
231
|
+
setKitFace(todayBtn, 'raised');
|
|
229
232
|
todayBtn.setAttribute('data-kit-nav', 'today');
|
|
230
233
|
const title = mk('h2', TITLE_CLASS, view === 'week'
|
|
231
234
|
? `${textOfDayNum(r.from)} ~ ${textOfDayNum(r.to)}`
|
|
@@ -235,6 +238,7 @@ export function createCalendar(): SomaComponentDefinition {
|
|
|
235
238
|
for (const v of ['month', 'week'] as const) {
|
|
236
239
|
const b = mk('button', v === view ? BTN_ON_CLASS : BTN_CLASS, str(p[`${v}_text`], kitText(v === 'month' ? 'soma.kit.cal_month' : 'soma.kit.cal_week', undefined, root)));
|
|
237
240
|
b.type = 'button';
|
|
241
|
+
setKitFace(b, 'raised');
|
|
238
242
|
b.setAttribute('data-kit-view', v);
|
|
239
243
|
b.setAttribute('aria-pressed', v === view ? 'true' : 'false');
|
|
240
244
|
head.appendChild(b);
|
|
@@ -295,12 +299,9 @@ export function createCalendar(): SomaComponentDefinition {
|
|
|
295
299
|
}
|
|
296
300
|
|
|
297
301
|
return {
|
|
298
|
-
|
|
299
|
-
root =
|
|
300
|
-
?? ctx.host.querySelector<HTMLElement>('[data-soma-id="root"]')
|
|
301
|
-
?? ctx.host;
|
|
302
|
+
attach(rootEl) {
|
|
303
|
+
root = rootEl;
|
|
302
304
|
const r = root;
|
|
303
|
-
sync();
|
|
304
305
|
const onClick = (event: Event): void => {
|
|
305
306
|
const target = event.target as HTMLElement | null;
|
|
306
307
|
const nav = target?.closest<HTMLElement>('[data-kit-nav]');
|
|
@@ -319,7 +320,7 @@ export function createCalendar(): SomaComponentDefinition {
|
|
|
319
320
|
if (ev) {
|
|
320
321
|
const key = ev.getAttribute('data-kit-event');
|
|
321
322
|
const hit = calendarEventsOf(P().data, P().map).find((e) => e.key === key);
|
|
322
|
-
if (hit)
|
|
323
|
+
if (hit) api.emit('event', { id: hit.key, item: hit.raw });
|
|
323
324
|
return;
|
|
324
325
|
}
|
|
325
326
|
const cell = target?.closest<HTMLElement>('[data-kit-date]');
|
|
@@ -336,23 +337,19 @@ export function createCalendar(): SomaComponentDefinition {
|
|
|
336
337
|
};
|
|
337
338
|
r.addEventListener('click', onClick);
|
|
338
339
|
r.addEventListener('keydown', onKeydown as EventListener);
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
340
|
+
return () => {
|
|
341
|
+
r.removeEventListener('click', onClick);
|
|
342
|
+
r.removeEventListener('keydown', onKeydown as EventListener);
|
|
343
|
+
root = null;
|
|
344
|
+
};
|
|
344
345
|
},
|
|
345
|
-
|
|
346
|
+
render(rootEl) {
|
|
347
|
+
root = rootEl;
|
|
346
348
|
sync();
|
|
347
349
|
paint();
|
|
348
350
|
},
|
|
349
|
-
onUnmount(): void {
|
|
350
|
-
for (const off of removeListeners) off();
|
|
351
|
-
removeListeners = [];
|
|
352
|
-
root = null;
|
|
353
|
-
},
|
|
354
351
|
};
|
|
355
|
-
},
|
|
352
|
+
}),
|
|
356
353
|
};
|
|
357
354
|
}
|
|
358
355
|
|
package/src/data/carousel.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { KIT_STATIC_COMPONENT_LIMITS } from 'soma-foundation/kit-limits';
|
|
|
17
17
|
import { bool, createKitController, joinClass, str } from '../base/shared';
|
|
18
18
|
import { kitIcon } from '../base/icons';
|
|
19
19
|
import { kitText } from '../i18n/kit-text';
|
|
20
|
+
import { setKitFace } from '../recipes';
|
|
20
21
|
import { kitKey } from '../i18n/kit-text';
|
|
21
22
|
import { classTokens, emptyNode, mk, textOf, type Rec } from './shape-util';
|
|
22
23
|
import { clampInt, keyOfRow, listOf, prefersReducedMotion, urlOf } from './display-util';
|
|
@@ -271,7 +272,7 @@ export function createCarousel(): SomaComponentDefinition {
|
|
|
271
272
|
},
|
|
272
273
|
},
|
|
273
274
|
templateHtml: `<section data-soma-id="root" role="region" aria-roledescription="carousel" class="${ROOT_CLASS}"></section>`,
|
|
274
|
-
controllerFactory: createKitController({
|
|
275
|
+
controllerFactory: createKitController(() => ({
|
|
275
276
|
attach(root, api) {
|
|
276
277
|
const s = stateOf(root);
|
|
277
278
|
const onClick = (event: Event): void => {
|
|
@@ -372,11 +373,13 @@ export function createCarousel(): SomaComponentDefinition {
|
|
|
372
373
|
const prev = mk('button', NAV_CLASS, '');
|
|
373
374
|
prev.appendChild(kitIcon('chevron-left', 'md', 'rtl:-scale-x-100'));
|
|
374
375
|
prev.type = 'button';
|
|
376
|
+
setKitFace(prev, 'raised');
|
|
375
377
|
prev.setAttribute('data-kit-prev', '');
|
|
376
378
|
prev.setAttribute('aria-label', kitText('soma.kit.prev_item', undefined, root));
|
|
377
379
|
const next = mk('button', NAV_CLASS, '');
|
|
378
380
|
next.appendChild(kitIcon('chevron-right', 'md', 'rtl:-scale-x-100'));
|
|
379
381
|
next.type = 'button';
|
|
382
|
+
setKitFace(next, 'raised');
|
|
380
383
|
next.setAttribute('data-kit-next', '');
|
|
381
384
|
next.setAttribute('aria-label', kitText('soma.kit.next_item', undefined, root));
|
|
382
385
|
const dots = mk('div', DOTS_CLASS);
|
|
@@ -403,6 +406,6 @@ export function createCarousel(): SomaComponentDefinition {
|
|
|
403
406
|
applyIndex(root, s, loop, layout, edge);
|
|
404
407
|
syncTimer(root, api);
|
|
405
408
|
},
|
|
406
|
-
}),
|
|
409
|
+
})),
|
|
407
410
|
};
|
|
408
411
|
}
|
package/src/data/chart.ts
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
// 没装配图表引擎、没数据、配置非法、引擎加载失败,都显示降级空态,不抛。
|
|
11
11
|
// 颜色只取 `--soma-*` 令牌(读运行期计算值交给引擎主题,源码里不写裸色值);样式类只用语义色名与 utilityScales 内的尺度。
|
|
12
12
|
|
|
13
|
-
import type {
|
|
14
|
-
import {
|
|
13
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
14
|
+
import { createKitController, joinClass, num, str } from '../base/shared';
|
|
15
15
|
import { kitText } from '../i18n/kit-text';
|
|
16
16
|
import { KIT_DATA_LIMITS } from 'soma-foundation/kit-limits';
|
|
17
17
|
import { KIT_GRAMMAR_RUNTIME as grammarJson } from '../generated/kit-grammar-runtime';
|
|
@@ -578,8 +578,8 @@ export function createChart(): SomaComponentDefinition {
|
|
|
578
578
|
+ `<div data-soma-id="stageWrap" class="hidden"><div data-soma-id="stage" class="${STAGE_CLASS}"></div></div>`
|
|
579
579
|
+ `<div data-soma-id="emptyWrap"><div data-soma-id="emptyText" class="${EMPTY_INNER_CLASS}"></div></div>`
|
|
580
580
|
+ '</div>',
|
|
581
|
-
controllerFactory: (
|
|
582
|
-
const P = (): Record<string, unknown> =>
|
|
581
|
+
controllerFactory: createKitController((api) => {
|
|
582
|
+
const P = (): Record<string, unknown> => api.props();
|
|
583
583
|
let root: HTMLElement | null = null;
|
|
584
584
|
let stageWrap: HTMLElement | null = null;
|
|
585
585
|
let stage: HTMLElement | null = null;
|
|
@@ -646,7 +646,7 @@ export function createChart(): SomaComponentDefinition {
|
|
|
646
646
|
};
|
|
647
647
|
|
|
648
648
|
const portOf = (): ChartEnginePort | null => {
|
|
649
|
-
const engines = (
|
|
649
|
+
const engines = (api.services as { engines?: { chart?: ChartEnginePort } } | undefined)?.engines;
|
|
650
650
|
return engines?.chart ?? null;
|
|
651
651
|
};
|
|
652
652
|
|
|
@@ -668,19 +668,27 @@ export function createChart(): SomaComponentDefinition {
|
|
|
668
668
|
if (instance === null) {
|
|
669
669
|
if (creating === null) {
|
|
670
670
|
creating = (async () => {
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
671
|
+
try {
|
|
672
|
+
await port.ensure(engineSeriesListOf(config.type), engineComponentsOf(config.type, (config.refLines?.length ?? 0) > 0));
|
|
673
|
+
const locale = str(p.locale);
|
|
674
|
+
const created = await port.create(stage!, { theme: { color: theme.palette }, ...(locale !== '' ? { locale } : {}) });
|
|
675
|
+
if (!alive) { created.dispose(); return; }
|
|
676
|
+
instance = created;
|
|
677
|
+
if (typeof ResizeObserver === 'function') {
|
|
678
|
+
resizeObs = new ResizeObserver(() => instance?.resize());
|
|
679
|
+
resizeObs.observe(stage!);
|
|
680
|
+
}
|
|
681
|
+
} finally {
|
|
682
|
+
creating = null;
|
|
679
683
|
}
|
|
680
684
|
})();
|
|
681
685
|
}
|
|
682
|
-
|
|
683
|
-
|
|
686
|
+
try {
|
|
687
|
+
await creating;
|
|
688
|
+
} catch (err) {
|
|
689
|
+
creating = null;
|
|
690
|
+
throw err;
|
|
691
|
+
}
|
|
684
692
|
}
|
|
685
693
|
// 异步期间又有新一轮 paint 或已卸载:交给最新一轮
|
|
686
694
|
if (!alive || mine !== seq || instance === null) return;
|
|
@@ -694,33 +702,33 @@ export function createChart(): SomaComponentDefinition {
|
|
|
694
702
|
};
|
|
695
703
|
|
|
696
704
|
return {
|
|
697
|
-
|
|
705
|
+
attach(rootEl) {
|
|
698
706
|
alive = true;
|
|
699
|
-
root =
|
|
707
|
+
root = rootEl;
|
|
700
708
|
stageWrap = find('stageWrap');
|
|
701
709
|
stage = find('stage');
|
|
702
710
|
emptyWrap = find('emptyWrap');
|
|
703
711
|
emptyText = find('emptyText');
|
|
704
712
|
watchScheme();
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
713
|
+
return () => {
|
|
714
|
+
alive = false;
|
|
715
|
+
unwatchScheme();
|
|
716
|
+
resizeObs?.disconnect();
|
|
717
|
+
resizeObs = null;
|
|
718
|
+
instance?.dispose();
|
|
719
|
+
instance = null;
|
|
720
|
+
root = null;
|
|
721
|
+
stageWrap = null;
|
|
722
|
+
stage = null;
|
|
723
|
+
emptyWrap = null;
|
|
724
|
+
emptyText = null;
|
|
725
|
+
};
|
|
709
726
|
},
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
resizeObs?.disconnect();
|
|
714
|
-
resizeObs = null;
|
|
715
|
-
instance?.dispose();
|
|
716
|
-
instance = null;
|
|
717
|
-
root = null;
|
|
718
|
-
stageWrap = null;
|
|
719
|
-
stage = null;
|
|
720
|
-
emptyWrap = null;
|
|
721
|
-
emptyText = null;
|
|
727
|
+
async render(rootEl) {
|
|
728
|
+
root = rootEl;
|
|
729
|
+
await paint();
|
|
722
730
|
},
|
|
723
731
|
};
|
|
724
|
-
},
|
|
732
|
+
}),
|
|
725
733
|
};
|
|
726
734
|
}
|
package/src/data/checklist.ts
CHANGED
|
@@ -104,7 +104,7 @@ export function createChecklist(): SomaComponentDefinition {
|
|
|
104
104
|
},
|
|
105
105
|
},
|
|
106
106
|
templateHtml: `<section data-soma-id="root" class="${ROOT_CLASS}"></section>`,
|
|
107
|
-
controllerFactory: createKitController({
|
|
107
|
+
controllerFactory: createKitController(() => ({
|
|
108
108
|
attach(root, api) {
|
|
109
109
|
const onChange = (event: Event): void => {
|
|
110
110
|
const box = event.target as HTMLInputElement | null;
|
|
@@ -139,7 +139,7 @@ export function createChecklist(): SomaComponentDefinition {
|
|
|
139
139
|
render(root, p) {
|
|
140
140
|
renderChecklist(root, p);
|
|
141
141
|
},
|
|
142
|
-
}),
|
|
142
|
+
})),
|
|
143
143
|
};
|
|
144
144
|
|
|
145
145
|
// 视图渲染(attach 里的乐观重绘也走它;函数声明会提升)
|
package/src/data/code-view.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
9
9
|
import { bool, createKitController, joinClass, str } from '../base/shared';
|
|
10
10
|
import { kitIcon } from '../base/icons';
|
|
11
|
+
import { KIT_PART_ATTRIBUTE, KIT_PART_WELL } from '../recipes';
|
|
11
12
|
import { kitText } from '../i18n/kit-text';
|
|
12
13
|
import { actionButton, classTokens, BUTTON_CLASS_TOKENS, mk, recOf, textOf } from './shape-util';
|
|
13
14
|
import {
|
|
@@ -220,7 +221,7 @@ export function createCodeView(): SomaComponentDefinition {
|
|
|
220
221
|
},
|
|
221
222
|
},
|
|
222
223
|
templateHtml: `<section data-soma-id="root" class="${ROOT_CLASS}"></section>`,
|
|
223
|
-
controllerFactory: createKitController({
|
|
224
|
+
controllerFactory: createKitController(() => ({
|
|
224
225
|
attach(root, api) {
|
|
225
226
|
const onClick = (event: Event): void => {
|
|
226
227
|
const btn = (event.target as HTMLElement | null)?.closest<HTMLButtonElement>('[data-kit-action="copy"]');
|
|
@@ -322,7 +323,7 @@ export function createCodeView(): SomaComponentDefinition {
|
|
|
322
323
|
render(root, p) {
|
|
323
324
|
renderCode(root, p);
|
|
324
325
|
},
|
|
325
|
-
}),
|
|
326
|
+
})),
|
|
326
327
|
};
|
|
327
328
|
|
|
328
329
|
function renderCode(root: HTMLElement, p: Record<string, unknown>): void {
|
|
@@ -388,6 +389,7 @@ export function createCodeView(): SomaComponentDefinition {
|
|
|
388
389
|
: mk('pre', `${KIT_CODE_PRE_CLASS}${height !== '' ? ` ${height}` : ''}`);
|
|
389
390
|
pre.tabIndex = 0;
|
|
390
391
|
pre.setAttribute('data-kit-code', '');
|
|
392
|
+
pre.setAttribute(KIT_PART_ATTRIBUTE, KIT_PART_WELL);
|
|
391
393
|
const label = str(p.aria_label) !== '' ? str(p.aria_label) : title;
|
|
392
394
|
if (label !== '') pre.setAttribute('aria-label', label);
|
|
393
395
|
if (stream) {
|
|
@@ -10,6 +10,7 @@ import type { SomaComponentDefinition } from 'soma-core';
|
|
|
10
10
|
import { matchSubmitKey } from 'soma-core/keyboard';
|
|
11
11
|
import { bool, createKitController, formatValue, joinClass, num, str } from '../base/shared';
|
|
12
12
|
import { kitText } from '../i18n/kit-text';
|
|
13
|
+
import { setKitFace } from '../recipes';
|
|
13
14
|
import { actionButton, BUTTON_CLASS_TOKENS, classTokens, emptyNode, keyMap, mk, rowsOf, textOf, TONE_SOFT } from './shape-util';
|
|
14
15
|
import { AVATAR_CLASS_TOKENS, avatarNode } from './d9-util';
|
|
15
16
|
import { CHAT_MAX_LENGTH, CHAT_MAX_MESSAGES, CHAT_STATUSES } from './d9-limits';
|
|
@@ -146,7 +147,7 @@ export function createCommentThread(): SomaComponentDefinition {
|
|
|
146
147
|
},
|
|
147
148
|
},
|
|
148
149
|
templateHtml: `<section data-soma-id="root" class="${ROOT_CLASS}"></section>`,
|
|
149
|
-
controllerFactory: createKitController({
|
|
150
|
+
controllerFactory: createKitController(() => ({
|
|
150
151
|
attach(root, api) {
|
|
151
152
|
const submit = (): void => {
|
|
152
153
|
const c = parts.get(root);
|
|
@@ -209,6 +210,7 @@ export function createCommentThread(): SomaComponentDefinition {
|
|
|
209
210
|
const composer = mk('div', COMPOSER_CLASS);
|
|
210
211
|
composer.setAttribute('data-kit-composer', '');
|
|
211
212
|
const area = mk('textarea', INPUT_CLASS);
|
|
213
|
+
setKitFace(area, 'field');
|
|
212
214
|
area.rows = 3;
|
|
213
215
|
const foot = mk('div', COMPOSER_FOOT);
|
|
214
216
|
const counter = mk('span', COUNTER_CLASS);
|
|
@@ -316,6 +318,7 @@ export function createCommentThread(): SomaComponentDefinition {
|
|
|
316
318
|
if (!attach) {
|
|
317
319
|
attach = mk('button', CHAT_ATTACH);
|
|
318
320
|
attach.type = 'button';
|
|
321
|
+
setKitFace(attach, 'raised');
|
|
319
322
|
attach.setAttribute('data-kit-attach', '');
|
|
320
323
|
c.send.parentElement?.insertBefore(attach, c.send);
|
|
321
324
|
}
|
|
@@ -326,7 +329,7 @@ export function createCommentThread(): SomaComponentDefinition {
|
|
|
326
329
|
c.send.textContent = str(p.send_text, kitText('soma.kit.ct_send', undefined, root));
|
|
327
330
|
syncComposer(c, p);
|
|
328
331
|
},
|
|
329
|
-
}),
|
|
332
|
+
})),
|
|
330
333
|
};
|
|
331
334
|
}
|
|
332
335
|
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
// 无 DOM 环境(SSR / 测试)时不弹,直接 resolve whenNoDom(缺省 false)。
|
|
10
10
|
|
|
11
11
|
import { kitText } from '../i18n/kit-text';
|
|
12
|
+
import { setKitFace } from '../recipes';
|
|
12
13
|
import { KIT_MODAL_CLASS_CANDIDATES, mountKitModal } from './modal-dialog';
|
|
13
14
|
import { BUTTON_CLASS_TOKENS, classTokens, type ActionTone } from './shape-util';
|
|
14
15
|
|
|
@@ -47,17 +48,21 @@ export interface KitConfirmOptions {
|
|
|
47
48
|
at?: Element | null;
|
|
48
49
|
/** 没有 DOM 时的结果,缺省 false */
|
|
49
50
|
whenNoDom?: boolean;
|
|
51
|
+
/** 调用方卸载 / 作废时中止:已中止直接 resolve(false);打开后中止就关闭对话框并 resolve(false)(确认框不会在调用方卸载后变成孤儿) */
|
|
52
|
+
signal?: AbortSignal;
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
function btn(doc: Document, tone: ActionTone, label: string): HTMLButtonElement {
|
|
53
56
|
const b = doc.createElement('button');
|
|
54
57
|
b.type = 'button';
|
|
55
58
|
b.className = `${BUTTON_BASE} ${BUTTON_TONE[tone]}`;
|
|
59
|
+
setKitFace(b, 'raised');
|
|
56
60
|
b.textContent = label;
|
|
57
61
|
return b;
|
|
58
62
|
}
|
|
59
63
|
|
|
60
64
|
export function askKitConfirm(opts: KitConfirmOptions): Promise<boolean> {
|
|
65
|
+
if (opts.signal?.aborted === true) return Promise.resolve(false);
|
|
61
66
|
if (typeof document === 'undefined' || document.body === null) return Promise.resolve(opts.whenNoDom === true);
|
|
62
67
|
const doc = opts.at?.ownerDocument ?? document;
|
|
63
68
|
return new Promise<boolean>((resolve) => {
|
|
@@ -78,10 +83,12 @@ export function askKitConfirm(opts: KitConfirmOptions): Promise<boolean> {
|
|
|
78
83
|
settled = true;
|
|
79
84
|
watch?.disconnect();
|
|
80
85
|
watch = null;
|
|
86
|
+
opts.signal?.removeEventListener('abort', onAbort);
|
|
81
87
|
modal.close();
|
|
82
88
|
modal.destroy();
|
|
83
89
|
resolve(ok);
|
|
84
90
|
};
|
|
91
|
+
const onAbort = (): void => finish(false);
|
|
85
92
|
|
|
86
93
|
const msg = doc.createElement('p');
|
|
87
94
|
msg.className = MESSAGE_CLASS;
|
|
@@ -108,6 +115,7 @@ export function askKitConfirm(opts: KitConfirmOptions): Promise<boolean> {
|
|
|
108
115
|
input = doc.createElement('input');
|
|
109
116
|
input.type = 'text';
|
|
110
117
|
input.className = INPUT_CLASS;
|
|
118
|
+
setKitFace(input, 'field');
|
|
111
119
|
input.setAttribute('aria-label', hint.textContent);
|
|
112
120
|
input.autocomplete = 'off';
|
|
113
121
|
const sync = (): void => {
|
|
@@ -138,6 +146,8 @@ export function askKitConfirm(opts: KitConfirmOptions): Promise<boolean> {
|
|
|
138
146
|
watch = new MutationObserver(() => { if (!modal.layer.isConnected) finish(false); });
|
|
139
147
|
watch.observe(doc.body, { childList: true, subtree: true });
|
|
140
148
|
}
|
|
149
|
+
// 调用方中止(如协调组件卸载):按取消收口,对话框随之关闭
|
|
150
|
+
opts.signal?.addEventListener('abort', onAbort, { once: true });
|
|
141
151
|
// 焦点:键入式 → 输入框;危险 → 取消钮;其余 → 确认钮
|
|
142
152
|
(input ?? (tone === 'danger' && cancel !== null ? cancel : ok)).focus();
|
|
143
153
|
});
|
package/src/data/context-menu.ts
CHANGED
|
@@ -11,19 +11,19 @@
|
|
|
11
11
|
//
|
|
12
12
|
// 菜单内容复用 base/menu-core 的 wireMenu(键盘、焦点回收、点外部关闭,Esc 只关栈顶);按落点经 showAtPoint 挂浮层
|
|
13
13
|
// (portal-core 的 placeAtPoint 是唯一 CSSOM 写点,见 kit-grammar.json#cssomWrites);浮层端口缺失 → 退回就地绝对定位(不写 CSSOM)。
|
|
14
|
-
//
|
|
14
|
+
// 菜单项点击抛槽位事件 `row_action_<序号>`,载荷与 KitTableActions 完全一致(带整行),页面 `_event` 给每个菜单项各绑一条管道,组件不直连数据写入。
|
|
15
15
|
// 条件显隐 `when`、权限 `permission` 沿用行操作;危险项(tone: danger)红字;`confirm` 尾段在 `_event` 管道里,沿用。
|
|
16
16
|
|
|
17
|
-
import type { SomaComponentDefinition
|
|
17
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
18
18
|
import { classCandidates, createKitController, str } from '../base/shared';
|
|
19
19
|
import { permissionCheckerOf } from '../base/permission-gate';
|
|
20
20
|
import { wireMenu, type MenuHandle, type MenuItemSpec } from '../base/menu-core';
|
|
21
21
|
import {
|
|
22
22
|
CONTEXT_POINT_PANEL, CONTEXT_SHOWN, KIT_CONTEXT_MENU_CLASS_CANDIDATES, wireContextTrigger, type Corner,
|
|
23
23
|
} from '../base/context-menu';
|
|
24
|
-
import { holds } from '../object-renderer/linkage';
|
|
25
|
-
import { evalActionGate, gateOutcomeReader, gateRowKey } from '../base/action-gate';
|
|
26
24
|
import { MORE_MENU_CLASSES, emitRowAction, itemsOf } from '../object-renderer/table-actions';
|
|
25
|
+
import { rowActionState } from '../object-renderer/view-binding';
|
|
26
|
+
import { KIT_ACTION_SLOT_BASE, actionSlotEmits } from '../base/action-slots';
|
|
27
27
|
|
|
28
28
|
const ROOT_CLASS = 'absolute size-0';
|
|
29
29
|
const MENU_HIDDEN = 'hidden';
|
|
@@ -64,32 +64,30 @@ export function createKitContextMenu(): SomaComponentDefinition {
|
|
|
64
64
|
name: 'KitContextMenu',
|
|
65
65
|
layer: 'data',
|
|
66
66
|
props: {
|
|
67
|
-
menu: { type: 'array', default: [], desc: '菜单项 [{ id, name, tone?, builtin?, target?, permission
|
|
67
|
+
menu: { type: 'array', default: [], desc: '菜单项 [{ id, name, tone?, builtin?, target?, permission? }],即 behavior.actions 里被 contextMenu 引用的动作;无权限的项不显示,全部不显示时不拦截系统菜单' },
|
|
68
|
+
actionState: { type: 'object', default: {}, desc: '行级动作状态 { 动作id: { hidden, disabled } }(仅 mode: row):叶子是行字段路径,core 逐行求值;hidden 为真该行菜单不含此项,disabled 为真置灰且点不到' },
|
|
68
69
|
row: { type: 'object', default: {}, desc: '行实例的当前行数据,原样随 row_action 上抛' },
|
|
69
70
|
rows: { type: 'array', default: [], desc: 'mode: virtual 时的行数组(与 KitVirtualRows 同源,按 data-kit-index 取行)' },
|
|
70
71
|
mode: { type: 'string', default: 'row', desc: 'row(行实例,监听 [data-kit-ctx])、virtual(监听 [data-kit-vscroll],按下标取行)或 host(监听 [data-kit-ctxhost] 宿主壳,按行主键经组件登记的取行函数取行)' },
|
|
71
72
|
long_press: { type: 'boolean', default: true, desc: '触屏长按 500ms 打开' },
|
|
72
73
|
},
|
|
73
74
|
emits: {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
},
|
|
83
|
-
desc: '点击某个菜单项;载荷自带整行,与行操作同形',
|
|
84
|
-
},
|
|
75
|
+
...actionSlotEmits(KIT_ACTION_SLOT_BASE.row, {
|
|
76
|
+
kit_action: { type: 'string', desc: '动作判别键(同 KitTableActions)' },
|
|
77
|
+
id: { type: 'string', desc: '动作 id' },
|
|
78
|
+
name: { type: 'string', desc: '动作显示名' },
|
|
79
|
+
builtin: { type: 'string', desc: '内置动作名' },
|
|
80
|
+
target: { type: 'string', desc: '目标浮层' },
|
|
81
|
+
row: { type: 'object', desc: '当前行' },
|
|
82
|
+
}, '点击某个菜单项;载荷自带整行,与行操作同形,序号 = 该动作在 menu 数组里的位置'),
|
|
85
83
|
},
|
|
86
84
|
},
|
|
87
|
-
services: ['permission'
|
|
85
|
+
services: ['permission'],
|
|
88
86
|
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
|
|
89
|
-
controllerFactory: (
|
|
90
|
-
const check = permissionCheckerOf(
|
|
91
|
-
return
|
|
92
|
-
attach(root
|
|
87
|
+
controllerFactory: createKitController((api) => {
|
|
88
|
+
const check = permissionCheckerOf(api as unknown as any);
|
|
89
|
+
return {
|
|
90
|
+
attach(root) {
|
|
93
91
|
const modeName = str(api.props().mode, 'row');
|
|
94
92
|
const virtual = modeName === 'virtual';
|
|
95
93
|
const hosted = modeName === 'host';
|
|
@@ -121,19 +119,11 @@ export function createKitContextMenu(): SomaComponentDefinition {
|
|
|
121
119
|
return row === undefined ? null : { row, el };
|
|
122
120
|
};
|
|
123
121
|
|
|
124
|
-
/**
|
|
125
|
-
const visibleActions = (): ReturnType<typeof itemsOf> =>
|
|
126
|
-
|
|
127
|
-
const port = (ctx.services as { data?: SomaDataPort } | undefined)?.data;
|
|
128
|
-
return itemsOf(api.props().menu).filter((a) =>
|
|
129
|
-
!(a.permission !== undefined && check !== null && !check(a.permission)) && holds(a.when, row)
|
|
130
|
-
&& !evalActionGate(a.gate, row, gateOutcomeReader(port, gateRowKey(a.gateKey, row))).hidden);
|
|
131
|
-
};
|
|
132
|
-
// GA2:菜单每次打开才画,打开那一刻读最新的写入结果即可(不需要订阅)
|
|
133
|
-
const gateDisabled = (a: ReturnType<typeof itemsOf>[number]): boolean =>
|
|
134
|
-
evalActionGate(a.gate, current?.row ?? {}, gateOutcomeReader((ctx.services as { data?: SomaDataPort } | undefined)?.data, gateRowKey(a.gateKey, current?.row))).disabled;
|
|
122
|
+
/** 当前命中行下可见的动作(权限) */
|
|
123
|
+
const visibleActions = (): ReturnType<typeof itemsOf> =>
|
|
124
|
+
itemsOf(api.props().menu).filter((a) => !(a.permission !== undefined && check !== null && !check(a.permission)) && !rowActionState(api.props().actionState, a.id).hidden);
|
|
135
125
|
const specs = (): MenuItemSpec[] =>
|
|
136
|
-
visibleActions().map((a) => ({ key: a.id, label: a.name, icon: '', disabled:
|
|
126
|
+
visibleActions().map((a) => ({ key: a.id, label: a.name, icon: '', disabled: rowActionState(api.props().actionState, a.id).disabled, danger: a.tone === 'danger', divider: false }));
|
|
137
127
|
|
|
138
128
|
const ensure = (): MenuHandle => {
|
|
139
129
|
if (handle !== null) return handle;
|
|
@@ -158,9 +148,11 @@ export function createKitContextMenu(): SomaComponentDefinition {
|
|
|
158
148
|
locked: () => false,
|
|
159
149
|
clickOpens: () => false,
|
|
160
150
|
onPick: (item) => {
|
|
161
|
-
const hit = visibleActions().find((a) => a.id === item.key);
|
|
151
|
+
const hit = visibleActions().find((a) => a.id === item.key && !rowActionState(api.props().actionState, a.id).disabled);
|
|
162
152
|
const picked = current;
|
|
163
|
-
if (hit !== undefined && picked !== null
|
|
153
|
+
if (hit !== undefined && picked !== null) {
|
|
154
|
+
emitRowAction({ emit: (n, p) => api.emit(n, p), props: () => ({ row: picked.row }) }, hit, itemsOf(api.props().menu).findIndex((a) => a.id === hit.id));
|
|
155
|
+
}
|
|
164
156
|
},
|
|
165
157
|
onToggle: (open) => {
|
|
166
158
|
if (open || current === null) return;
|
|
@@ -210,7 +202,7 @@ export function createKitContextMenu(): SomaComponentDefinition {
|
|
|
210
202
|
render(root) {
|
|
211
203
|
root.className = ROOT_CLASS;
|
|
212
204
|
},
|
|
213
|
-
}
|
|
214
|
-
},
|
|
205
|
+
};
|
|
206
|
+
}),
|
|
215
207
|
};
|
|
216
208
|
}
|
package/src/data/d9-util.ts
CHANGED
|
@@ -51,24 +51,8 @@ export function avatarNode(name: string, src: unknown, size: AvatarSize = 'md'):
|
|
|
51
51
|
|
|
52
52
|
// ── 焦点 ─────────────────────────────────────────────────────
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
export function focusablesIn(el: HTMLElement): HTMLElement[] {
|
|
57
|
-
return [...el.querySelectorAll<HTMLElement>(FOCUSABLE)].filter((n) => !n.hasAttribute('hidden'));
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** Tab 在容器内循环(对话框式浮层的焦点隔离);返回 true = 已处理 */
|
|
61
|
-
export function trapTab(event: KeyboardEvent, container: HTMLElement): boolean {
|
|
62
|
-
if (event.key !== 'Tab') return false;
|
|
63
|
-
const list = focusablesIn(container);
|
|
64
|
-
if (list.length === 0) { event.preventDefault(); container.focus(); return true; }
|
|
65
|
-
const first = list[0]!;
|
|
66
|
-
const last = list[list.length - 1]!;
|
|
67
|
-
const active = document.activeElement;
|
|
68
|
-
if (event.shiftKey && (active === first || !container.contains(active))) { event.preventDefault(); last.focus(); return true; }
|
|
69
|
-
if (!event.shiftKey && (active === last || !container.contains(active))) { event.preventDefault(); first.focus(); return true; }
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
54
|
+
export { focusablesIn, trapTab } from '../base/popup';
|
|
55
|
+
import { focusablesIn, trapTab } from '../base/popup';
|
|
72
56
|
|
|
73
57
|
/** 给 id 里的特殊字符转义,拼进属性选择器 */
|
|
74
58
|
export function attrEsc(value: string): string {
|
package/src/data/diff.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
11
11
|
import { KIT_STATIC_COMPONENT_LIMITS } from 'soma-foundation/kit-limits';
|
|
12
12
|
import { kitText } from '../i18n/kit-text';
|
|
13
|
+
import { setKitFace } from '../recipes';
|
|
13
14
|
import { createKitController, joinClass, str } from '../base/shared';
|
|
14
15
|
import { classTokens, mk, recOf, textOf, type Rec } from './shape-util';
|
|
15
16
|
import { clampInt, singleOf, urlOf } from './display-util';
|
|
@@ -135,7 +136,7 @@ export function createDiff(): SomaComponentDefinition {
|
|
|
135
136
|
},
|
|
136
137
|
},
|
|
137
138
|
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
|
|
138
|
-
controllerFactory: createKitController({
|
|
139
|
+
controllerFactory: createKitController(() => ({
|
|
139
140
|
attach(root, api) {
|
|
140
141
|
const s = stateOf(root);
|
|
141
142
|
const setStep = (next: number): void => {
|
|
@@ -227,6 +228,7 @@ export function createDiff(): SomaComponentDefinition {
|
|
|
227
228
|
handle.appendChild(mk('span', LINE_CLASS));
|
|
228
229
|
const knob = mk('span', KNOB_CLASS, '⇆');
|
|
229
230
|
knob.setAttribute('aria-hidden', 'true');
|
|
231
|
+
setKitFace(knob, 'raised'); // 实心把手有 shadow-md,质感经合成槽叠进去
|
|
230
232
|
handle.appendChild(knob);
|
|
231
233
|
root.appendChild(under);
|
|
232
234
|
root.appendChild(box);
|
|
@@ -234,6 +236,6 @@ export function createDiff(): SomaComponentDefinition {
|
|
|
234
236
|
}
|
|
235
237
|
applyStep(root, s.step);
|
|
236
238
|
},
|
|
237
|
-
}),
|
|
239
|
+
})),
|
|
238
240
|
};
|
|
239
241
|
}
|
package/src/data/dock.ts
CHANGED
|
@@ -101,7 +101,7 @@ export function createDock(): SomaComponentDefinition {
|
|
|
101
101
|
keyboard: { layout: 'list', orientation: 'horizontal', wrap: true, typeahead: false, focus_model: 'roving', space: 'activate' },
|
|
102
102
|
},
|
|
103
103
|
templateHtml: `<nav data-soma-id="root" class="${ROOT_CLASS}"></nav>`,
|
|
104
|
-
controllerFactory: createKitController({
|
|
104
|
+
controllerFactory: createKitController(() => ({
|
|
105
105
|
attach(root, api) {
|
|
106
106
|
const s = stateOf(root);
|
|
107
107
|
const off = wireRovingRow(root, {
|
|
@@ -147,6 +147,6 @@ export function createDock(): SomaComponentDefinition {
|
|
|
147
147
|
}
|
|
148
148
|
paintSelected(root, s.selected);
|
|
149
149
|
},
|
|
150
|
-
}),
|
|
150
|
+
})),
|
|
151
151
|
};
|
|
152
152
|
}
|