soma-kit 0.1.11 → 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 -1473
package/src/data/embed.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type { SomaComponentDefinition } from 'soma-core';
|
|
|
9
9
|
import { releaseDropdownsIn } from '../base/popup';
|
|
10
10
|
import { createSelect } from '../base/select';
|
|
11
11
|
import { hintUndeclaredKitUse } from './wrapped-candidates';
|
|
12
|
+
import { kitFail } from '../compile/kit-error';
|
|
12
13
|
|
|
13
14
|
export type KitEmitHandlers = Record<string, (payload: any) => void>;
|
|
14
15
|
|
|
@@ -26,7 +27,7 @@ export interface KitMount {
|
|
|
26
27
|
const UNSAFE_TEMPLATE = /<\s*\/?\s*(script|iframe|object|embed)\b|\son[a-z]+\s*=|javascript\s*:/i;
|
|
27
28
|
|
|
28
29
|
export function assertTrustedTemplate(html: string): string {
|
|
29
|
-
if (UNSAFE_TEMPLATE.test(html))
|
|
30
|
+
if (UNSAFE_TEMPLATE.test(html)) kitFail('KIT-COMP-005', 'templateHtml', 'mountKitComponent: templateHtml 含脚本 / 事件属性 / javascript: 地址,拒绝挂载', '模板里去掉 script / iframe / on* 属性 / javascript: 地址;交互走组件控制器,数据走 props');
|
|
30
31
|
return html;
|
|
31
32
|
}
|
|
32
33
|
|
package/src/data/field-mapper.ts
CHANGED
|
@@ -11,10 +11,11 @@
|
|
|
11
11
|
// 每次改动抛 `change { value, ready }`(ready = 必填都已映射且至少映射了一项);
|
|
12
12
|
// save_label 非空时出现保存钮(未就绪时禁用),抛 `saved { value }`;cancel_label 非空时出现取消钮,抛 `cancel {}`。
|
|
13
13
|
|
|
14
|
-
import type {
|
|
15
|
-
import { bool,
|
|
14
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
15
|
+
import { bool, createKitController, joinClass, num, str } from '../base/shared';
|
|
16
16
|
import { kitIcon } from '../base/icons';
|
|
17
17
|
import { kitText, type KitTextKey } from '../i18n/kit-text';
|
|
18
|
+
import { setKitFace } from '../recipes';
|
|
18
19
|
import { createKitBusy, KIT_BUSY_PROP_DEFS } from '../base/action-busy';
|
|
19
20
|
import { KIT_LISTBOX_CLASS_CANDIDATES } from '../base/listbox-core';
|
|
20
21
|
import { createKitEmbedBag, mountKitSelectField, type KitSelectField } from './embed';
|
|
@@ -194,9 +195,9 @@ export function createFieldMapper(): SomaComponentDefinition {
|
|
|
194
195
|
},
|
|
195
196
|
},
|
|
196
197
|
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
|
|
197
|
-
controllerFactory: (
|
|
198
|
-
const P = (): Record<string, unknown> =>
|
|
199
|
-
const tx = (key: KitTextKey, params?: Record<string, string | number>): string => kitText(key, params,
|
|
198
|
+
controllerFactory: createKitController((api) => {
|
|
199
|
+
const P = (): Record<string, unknown> => api.props();
|
|
200
|
+
const tx = (key: KitTextKey, params?: Record<string, string | number>): string => kitText(key, params, api.host);
|
|
200
201
|
let root: HTMLElement | null = null;
|
|
201
202
|
let parsed: ParsedMapperData = { targets: [], sources: [], mapping: {}, arrayShape: false, sample: [] };
|
|
202
203
|
let draft: KitFieldMapping = {};
|
|
@@ -262,6 +263,7 @@ export function createFieldMapper(): SomaComponentDefinition {
|
|
|
262
263
|
return { node: field.el, control: field.input };
|
|
263
264
|
}
|
|
264
265
|
const input = el('input', CONTROL_CLASS);
|
|
266
|
+
setKitFace(input, 'field');
|
|
265
267
|
input.type = 'text';
|
|
266
268
|
input.setAttribute('autocomplete', 'off');
|
|
267
269
|
input.setAttribute('aria-label', label);
|
|
@@ -345,6 +347,7 @@ export function createFieldMapper(): SomaComponentDefinition {
|
|
|
345
347
|
if (allowAdd()) {
|
|
346
348
|
const add = el('div', ADD_ROW_CLASS);
|
|
347
349
|
const target = el('input', CONTROL_CLASS);
|
|
350
|
+
setKitFace(target, 'field');
|
|
348
351
|
target.type = 'text';
|
|
349
352
|
target.placeholder = tx('soma.kit.fm_target');
|
|
350
353
|
target.setAttribute('aria-label', tx('soma.kit.fm_add_target'));
|
|
@@ -359,6 +362,7 @@ export function createFieldMapper(): SomaComponentDefinition {
|
|
|
359
362
|
add.appendChild(src.node);
|
|
360
363
|
const btn = el('button', BTN_CLASS, tx('soma.kit.add'));
|
|
361
364
|
btn.type = 'button';
|
|
365
|
+
setKitFace(btn, 'raised');
|
|
362
366
|
btn.setAttribute('data-kit-add', '');
|
|
363
367
|
btn.disabled = locked();
|
|
364
368
|
add.appendChild(btn);
|
|
@@ -407,7 +411,7 @@ export function createFieldMapper(): SomaComponentDefinition {
|
|
|
407
411
|
|
|
408
412
|
const commit = (): void => {
|
|
409
413
|
paintStatus();
|
|
410
|
-
|
|
414
|
+
api.emit('change', { value: exportMapping(draft, parsed.arrayShape), ready: ready() });
|
|
411
415
|
};
|
|
412
416
|
|
|
413
417
|
const setField = (key: string, source: string): void => {
|
|
@@ -443,12 +447,15 @@ export function createFieldMapper(): SomaComponentDefinition {
|
|
|
443
447
|
foot.setAttribute('data-kit-foot', '');
|
|
444
448
|
const reset = el('button', BTN_CLASS);
|
|
445
449
|
reset.type = 'button';
|
|
450
|
+
setKitFace(reset, 'raised');
|
|
446
451
|
reset.setAttribute('data-kit-reset', '');
|
|
447
452
|
const cancel = el('button', BTN_CLASS);
|
|
448
453
|
cancel.type = 'button';
|
|
454
|
+
setKitFace(cancel, 'raised');
|
|
449
455
|
cancel.setAttribute('data-kit-cancel', '');
|
|
450
456
|
saveBtn = el('button', SAVE_CLASS);
|
|
451
457
|
saveBtn.type = 'button';
|
|
458
|
+
setKitFace(saveBtn, 'raised');
|
|
452
459
|
saveBtn.setAttribute('data-kit-save', '');
|
|
453
460
|
const boxOf = (child: HTMLElement): HTMLElement => { const b = el('div', ''); b.appendChild(child); return b; };
|
|
454
461
|
boxes.reset = boxOf(reset);
|
|
@@ -504,41 +511,39 @@ export function createFieldMapper(): SomaComponentDefinition {
|
|
|
504
511
|
if (t?.closest('[data-kit-cancel]')) {
|
|
505
512
|
draft = { ...parsed.mapping };
|
|
506
513
|
rebuildRows();
|
|
507
|
-
|
|
514
|
+
api.emit('cancel', {});
|
|
508
515
|
return;
|
|
509
516
|
}
|
|
510
517
|
if (t?.closest('[data-kit-save]')) {
|
|
511
518
|
if (locked() || !ready() || kb.busy()) return;
|
|
512
519
|
const value = exportMapping(draft, parsed.arrayShape);
|
|
513
|
-
|
|
520
|
+
api.emit('saved', { values: { value }, object: str(P().object), model: { value }, mode: str(P().mode, 'edit'), value });
|
|
514
521
|
}
|
|
515
522
|
});
|
|
516
523
|
};
|
|
517
524
|
|
|
518
525
|
return {
|
|
519
|
-
|
|
520
|
-
|
|
526
|
+
busyAware: true,
|
|
527
|
+
attach(rootEl) {
|
|
528
|
+
root = rootEl;
|
|
521
529
|
build(root);
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
530
|
+
return () => {
|
|
531
|
+
embeds.release(rowsBox);
|
|
532
|
+
for (const fn of removers) fn();
|
|
533
|
+
removers = [];
|
|
534
|
+
root = null;
|
|
535
|
+
rowsBox = null;
|
|
536
|
+
noticeEl = null;
|
|
537
|
+
previewBox = null;
|
|
538
|
+
saveBtn = null;
|
|
539
|
+
};
|
|
525
540
|
},
|
|
526
|
-
|
|
541
|
+
render(rootEl) {
|
|
542
|
+
root = rootEl;
|
|
527
543
|
if (!sync()) paintStatus();
|
|
528
544
|
paintChrome();
|
|
529
545
|
},
|
|
530
|
-
onUnmount(): void {
|
|
531
|
-
kb.dispose();
|
|
532
|
-
embeds.release(rowsBox);
|
|
533
|
-
for (const fn of removers) fn();
|
|
534
|
-
removers = [];
|
|
535
|
-
root = null;
|
|
536
|
-
rowsBox = null;
|
|
537
|
-
noticeEl = null;
|
|
538
|
-
previewBox = null;
|
|
539
|
-
saveBtn = null;
|
|
540
|
-
},
|
|
541
546
|
};
|
|
542
|
-
},
|
|
547
|
+
}),
|
|
543
548
|
};
|
|
544
549
|
}
|
|
@@ -21,7 +21,7 @@ export const FLOW_EDITOR_CONTRACT = {
|
|
|
21
21
|
disabled: { type: 'boolean', default: false, desc: '禁用:同只读(表单禁用该字段时由表单置真)' },
|
|
22
22
|
validation: { type: 'array', default: [], desc: '外部传入的问题 [{ target: node | edge, id, level: error | warning, message }],按节点或连线标记' },
|
|
23
23
|
suggestions: { type: 'array', default: [], desc: 'AI 建议 [{ id, label, reason?, nodes, edges }],画成虚影,可采纳或拒绝' },
|
|
24
|
-
|
|
24
|
+
nodeOptions: { type: 'object', default: {}, desc: '节点字段候选项 { "<节点类型>.<字段键>": [{ value, label, meta? }] }(页面写 nodeOptions: view.<成员>,由展示对象按别的字段取数后整体替换引用写入):并进该类型 select 字段的 options,meta 在选中时并入节点;键不在表里的字段保持自己的静态 / 远程候选,键在表里(含空数组)以它为准' },
|
|
25
25
|
allowCycles: { type: 'boolean', default: false, desc: '允许成环;缺省拒绝形成环的连线' },
|
|
26
26
|
statusTones: { type: 'object', default: {}, desc: '节点状态值 -> 语气(neutral / info / success / warning / danger / primary)' },
|
|
27
27
|
texts: { type: 'object', default: {}, desc: '文案覆盖(键见 FLOW_DEFAULT_TEXTS)' },
|
package/src/data/flow-editor.ts
CHANGED
|
@@ -11,15 +11,15 @@
|
|
|
11
11
|
// 本文件依次是:数据与配置形状、类串表、几何、撤销栈、分层布局、输入解析、图编辑规则、组件。
|
|
12
12
|
// 纯函数(布局、几何、规则、撤销栈、解析)均已导出,供业务组件与测试直接用。
|
|
13
13
|
|
|
14
|
-
import type {
|
|
15
|
-
import { watchKitOutcome } from './outcome-watch';
|
|
14
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
16
15
|
import { mappingPrefixOf } from './flow-remote-options';
|
|
16
|
+
import { clearFlowNodeField, withNodeOptions } from './flow-node-options';
|
|
17
17
|
import { FLOW_EDITOR_CONTRACT } from './flow-editor-contract';
|
|
18
|
-
import { pickPath } from '../object-renderer/adopt-gate';
|
|
19
18
|
import { designFlowEditorGeometry } from 'soma-foundation/layout';
|
|
20
19
|
import { KIT_DATA_LIMITS } from 'soma-foundation/kit-limits';
|
|
21
|
-
import { bool,
|
|
20
|
+
import { bool, createKitController, joinClass, num, str } from '../base/shared';
|
|
22
21
|
import { kitText, type KitTextKey } from '../i18n/kit-text';
|
|
22
|
+
import { setKitFace } from '../recipes';
|
|
23
23
|
import { kitIcon, type KitIconName } from '../base/icons';
|
|
24
24
|
import { createInput, KIT_INPUT_CLASS_CANDIDATES } from '../base/input';
|
|
25
25
|
import { createTextarea, KIT_TEXTAREA_CLASS_CANDIDATES } from '../base/textarea';
|
|
@@ -892,21 +892,6 @@ export function suggestionsOf(raw: unknown): FlowSuggestion[] {
|
|
|
892
892
|
return out;
|
|
893
893
|
}
|
|
894
894
|
|
|
895
|
-
/**
|
|
896
|
-
* 请求结果 -> 画布建议(纯函数;`adopt: { from, path? }` 的取值,与表单采纳同口径):outcome.data 按 path 取值,
|
|
897
|
-
* 数组 = 多条建议,带 nodes / edges 的对象 = 一条。建议 id 带请求序号前缀,重新请求后「忽略」自动重置;
|
|
898
|
-
* 节点与连线 id 保持原样(采纳后就是画布草稿里的 id)。个数不超过 dataLimits.flowEditor.adoptSuggestMax。
|
|
899
|
-
*/
|
|
900
|
-
export function adoptSuggestionsOf(data: unknown, path: string, seq: number, label: string): FlowSuggestion[] {
|
|
901
|
-
const root = pickPath(data, path);
|
|
902
|
-
const items = Array.isArray(root) ? root : root !== null && typeof root === 'object' ? [root] : [];
|
|
903
|
-
const raw = items.slice(0, KIT_DATA_LIMITS.flowEditor.adoptSuggestMax).map((item, i) => {
|
|
904
|
-
const o = rec(item);
|
|
905
|
-
return { ...o, id: `adopt${seq}-${str(o.id) !== '' ? str(o.id) : String(i)}`, label: str(o.label) !== '' ? str(o.label) : label };
|
|
906
|
-
});
|
|
907
|
-
return suggestionsOf(raw);
|
|
908
|
-
}
|
|
909
|
-
|
|
910
895
|
function layoutOf(raw: unknown): FlowLayoutMode {
|
|
911
896
|
return raw === 'layered' ? 'layered' : 'manual';
|
|
912
897
|
}
|
|
@@ -937,7 +922,8 @@ export function configOf(props: Record<string, unknown>, at?: Element | null): F
|
|
|
937
922
|
const dataCfg = rec(rec(props.data).config);
|
|
938
923
|
const pick = (key: string): unknown => pickOf(props, key);
|
|
939
924
|
return {
|
|
940
|
-
|
|
925
|
+
// nodeOptions:展示对象给的节点字段候选项(页面 nodeOptions: view.<成员>),并进对应 select 字段的 options
|
|
926
|
+
nodeTypes: nodeTypesOf(withNodeOptions(pick('nodeTypes'), pick('nodeOptions'))),
|
|
941
927
|
layout: layoutOf(pick('layout')),
|
|
942
928
|
readonly: bool(props.readonly) || bool(props.disabled) || bool(dataCfg.readonly),
|
|
943
929
|
allowCycles: bool(pick('allowCycles')),
|
|
@@ -1248,12 +1234,13 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1248
1234
|
contract: FLOW_EDITOR_CONTRACT,
|
|
1249
1235
|
services: ['engines', 'data'],
|
|
1250
1236
|
templateHtml: `<div data-soma-id="root" class="${FLOW_CLASS.root}"></div>`,
|
|
1251
|
-
controllerFactory: (
|
|
1252
|
-
const P = (): Record<string, unknown> =>
|
|
1237
|
+
controllerFactory: createKitController((api) => {
|
|
1238
|
+
const P = (): Record<string, unknown> => api.props();
|
|
1253
1239
|
const uid = `kit-flow-${++SEQ}`;
|
|
1254
1240
|
|
|
1255
1241
|
// ---- 状态
|
|
1256
1242
|
let root: HTMLElement | null = null;
|
|
1243
|
+
let mounted = false;
|
|
1257
1244
|
let cfg: FlowConfig = configOf({});
|
|
1258
1245
|
let graph: FlowGraph = { nodes: [], edges: [] };
|
|
1259
1246
|
let history: FlowHistory = emptyHistory();
|
|
@@ -1261,12 +1248,6 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1261
1248
|
let suggestions: FlowSuggestion[] = [];
|
|
1262
1249
|
let rejected = new Set<string>();
|
|
1263
1250
|
let sugSig = '';
|
|
1264
|
-
// adopt:来自请求结果的建议(订阅的 into 名、路径、标签、当前建议、退订)
|
|
1265
|
-
let adoptFrom = '';
|
|
1266
|
-
let adoptPath = '';
|
|
1267
|
-
let adoptLabel = '';
|
|
1268
|
-
let adoptSug: FlowSuggestion[] = [];
|
|
1269
|
-
let adoptOff: (() => void) | null = null;
|
|
1270
1251
|
let lastDataSig = '';
|
|
1271
1252
|
let view: FlowView = { zoom: 1, panX: 0, panY: 0 };
|
|
1272
1253
|
let needFit = true;
|
|
@@ -1319,7 +1300,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1319
1300
|
const editable = (): boolean => !cfg.readonly;
|
|
1320
1301
|
const movable = (): boolean => editable() && cfg.layout === 'manual';
|
|
1321
1302
|
const dndPort = (): DragPortLike | null => {
|
|
1322
|
-
const engines = (
|
|
1303
|
+
const engines = (api.services as { engines?: { dnd?: DragPortLike } } | undefined)?.engines;
|
|
1323
1304
|
return engines?.dnd ?? null;
|
|
1324
1305
|
};
|
|
1325
1306
|
const nodeById = (id: string): FlowNode | undefined => graph.nodes.find((n) => n.id === id);
|
|
@@ -1387,8 +1368,8 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1387
1368
|
|
|
1388
1369
|
const emitSelect = (lastKey?: string): void => {
|
|
1389
1370
|
const k = lastKey ?? [...selected][selected.size - 1];
|
|
1390
|
-
if (k === undefined)
|
|
1391
|
-
else
|
|
1371
|
+
if (k === undefined) api.emit('select', { id: '', kind: 'none' });
|
|
1372
|
+
else api.emit('select', { id: k.slice(2), kind: k.startsWith('n:') ? 'node' : 'edge' });
|
|
1392
1373
|
};
|
|
1393
1374
|
|
|
1394
1375
|
const setSelection = (keys: Iterable<string>, lastKey?: string): void => {
|
|
@@ -1409,7 +1390,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1409
1390
|
history = pushHistory(history, graph, FLOW_GEOMETRY.historyLimit, coalesce);
|
|
1410
1391
|
graph = next;
|
|
1411
1392
|
pruneSelection();
|
|
1412
|
-
|
|
1393
|
+
api.emit('change', payload(graph));
|
|
1413
1394
|
paint();
|
|
1414
1395
|
};
|
|
1415
1396
|
|
|
@@ -1528,14 +1509,14 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1528
1509
|
const r = undoHistory(history, graph);
|
|
1529
1510
|
if (!r) return;
|
|
1530
1511
|
history = r.history; graph = r.graph; pruneSelection();
|
|
1531
|
-
|
|
1512
|
+
api.emit('change', payload(graph));
|
|
1532
1513
|
paint();
|
|
1533
1514
|
};
|
|
1534
1515
|
const doRedo = (): void => {
|
|
1535
1516
|
const r = redoHistory(history, graph);
|
|
1536
1517
|
if (!r) return;
|
|
1537
1518
|
history = r.history; graph = r.graph; pruneSelection();
|
|
1538
|
-
|
|
1519
|
+
api.emit('change', payload(graph));
|
|
1539
1520
|
paint();
|
|
1540
1521
|
};
|
|
1541
1522
|
|
|
@@ -1553,11 +1534,12 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1553
1534
|
const setField = (id: string, f: FlowField, value: unknown): void => {
|
|
1554
1535
|
const cur = nodeById(id);
|
|
1555
1536
|
if (!cur || !editable()) return;
|
|
1556
|
-
const
|
|
1537
|
+
const latest = panelFieldsOf(typeOf(cur)).find((x) => x.key === f.key) ?? f;
|
|
1538
|
+
const next = applyFieldValue(cur, latest, value);
|
|
1557
1539
|
panelVals = panelSig(next, panelFieldsOf(typeOf(cur)));
|
|
1558
1540
|
if (f.kind === 'select' || (f.resets?.length ?? 0) > 0) { panelForce = true; panelRefocus = f.key; }
|
|
1559
1541
|
commit({ ...graph, nodes: graph.nodes.map((n) => (n.id === id ? next : n)) }, `meta:${id}:${f.key}`);
|
|
1560
|
-
|
|
1542
|
+
api.emit('node_change', { id, label: next.label, meta: next.meta ?? {} });
|
|
1561
1543
|
};
|
|
1562
1544
|
|
|
1563
1545
|
const mountCtl = (def: SomaComponentDefinition, parent: HTMLElement, props: Record<string, unknown>, handlers: Record<string, (p: any) => void>): void => {
|
|
@@ -1652,6 +1634,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1652
1634
|
hintEls = [];
|
|
1653
1635
|
panelId = '';
|
|
1654
1636
|
panelVals = '';
|
|
1637
|
+
panelOptsSig = '';
|
|
1655
1638
|
};
|
|
1656
1639
|
|
|
1657
1640
|
const focusPanel = (key = ''): void => {
|
|
@@ -1676,7 +1659,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1676
1659
|
// 候选签名覆盖候选的真实内容:select 的选项(值 + 标签)、mapping 的声明目标(key + 标签,随 targets_by 当前值取);
|
|
1677
1660
|
// 不含 meta 里用户自己写出的映射键(那随打字变化,不该触发重建)
|
|
1678
1661
|
const optsSig = JSON.stringify(fields.map((f) => {
|
|
1679
|
-
if (f.kind === 'select') return [f.key, f.placeholder ?? '', (f.options ?? []).map((o) => [o.value, o.label])];
|
|
1662
|
+
if (f.kind === 'select') return [f.key, f.placeholder ?? '', (f.options ?? []).map((o) => [o.value, o.label, o.meta])];
|
|
1680
1663
|
if (f.kind === 'mapping') {
|
|
1681
1664
|
const by = f.targets_by !== undefined ? str(node.meta?.[f.targets_by]) : '';
|
|
1682
1665
|
const base = f.targets_by !== undefined ? (f.targets_map?.[by] ?? []) : (f.targets ?? []);
|
|
@@ -1730,7 +1713,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1730
1713
|
if (!nodeById(id)) return;
|
|
1731
1714
|
const key = keyOfNode(id);
|
|
1732
1715
|
if (!(selected.size === 1 && selected.has(key))) { setSelection([key], key); paint(); }
|
|
1733
|
-
|
|
1716
|
+
api.emit('node_config', { id });
|
|
1734
1717
|
if (panelTarget() !== null) focusPanel();
|
|
1735
1718
|
};
|
|
1736
1719
|
|
|
@@ -1740,12 +1723,12 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1740
1723
|
const base = withPositions(graph);
|
|
1741
1724
|
const next = applySuggestion(base, s, ghostPosCache);
|
|
1742
1725
|
commit(next);
|
|
1743
|
-
|
|
1726
|
+
api.emit('suggestion_accept', { id: sid });
|
|
1744
1727
|
};
|
|
1745
1728
|
const reject = (sid: string): void => {
|
|
1746
1729
|
rejected = new Set([...rejected, sid]);
|
|
1747
1730
|
paint();
|
|
1748
|
-
|
|
1731
|
+
api.emit('suggestion_reject', { id: sid });
|
|
1749
1732
|
};
|
|
1750
1733
|
|
|
1751
1734
|
// ---- 视图
|
|
@@ -1810,6 +1793,8 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
1810
1793
|
b.appendChild(document.createTextNode(` ${text}`));
|
|
1811
1794
|
} else b.textContent = text;
|
|
1812
1795
|
if (opts.disabled) b.disabled = true;
|
|
1796
|
+
// 工具栏按钮(btn / btnPrimary 都带边框与底色)单点标 raised
|
|
1797
|
+
setKitFace(b, 'raised');
|
|
1813
1798
|
return b;
|
|
1814
1799
|
};
|
|
1815
1800
|
|
|
@@ -2131,40 +2116,16 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2131
2116
|
}
|
|
2132
2117
|
lastDataSig = dsig;
|
|
2133
2118
|
external = (pickOf(p, 'validation') !== undefined ? issuesOf(pickOf(p, 'validation')) : []);
|
|
2134
|
-
bindAdopt(p);
|
|
2135
2119
|
deriveSuggestions(p);
|
|
2136
2120
|
};
|
|
2137
2121
|
|
|
2138
|
-
// 建议 = 显式 suggestions
|
|
2122
|
+
// 建议 = 显式 suggestions;集合变了「忽略」重置
|
|
2139
2123
|
const deriveSuggestions = (p: Record<string, unknown>): void => {
|
|
2140
|
-
suggestions =
|
|
2124
|
+
suggestions = suggestionsOf(pickOf(p, 'suggestions'));
|
|
2141
2125
|
const sig = JSON.stringify(suggestions.map((s) => s.id));
|
|
2142
2126
|
if (sig !== sugSig) { sugSig = sig; rejected = new Set(); }
|
|
2143
2127
|
};
|
|
2144
2128
|
|
|
2145
|
-
// adopt.from 变了才重订;订阅当下的那次回调只取值不重绘(sync 随后会 paint)
|
|
2146
|
-
const bindAdopt = (p: Record<string, unknown>): void => {
|
|
2147
|
-
const decl = rec(p.adopt);
|
|
2148
|
-
adoptPath = str(decl.path);
|
|
2149
|
-
adoptLabel = str(decl.label) !== '' ? str(decl.label) : kitText('soma.kit.flow_adopt_label', undefined, root);
|
|
2150
|
-
const from = str(decl.from);
|
|
2151
|
-
if (from === adoptFrom) return;
|
|
2152
|
-
adoptOff?.();
|
|
2153
|
-
adoptOff = null;
|
|
2154
|
-
adoptFrom = from;
|
|
2155
|
-
adoptSug = [];
|
|
2156
|
-
if (from === '') return;
|
|
2157
|
-
let subscribing = true;
|
|
2158
|
-
adoptOff = watchKitOutcome((ctx.services as { data?: SomaDataPort } | undefined)?.data, from, (o) => {
|
|
2159
|
-
adoptSug = o.status === 'saved' ? adoptSuggestionsOf(o.data, adoptPath, o.seq, adoptLabel) : [];
|
|
2160
|
-
flash = o.status === 'saved' && adoptSug.length === 0 ? kitText('soma.kit.flow_adopt_none', undefined, root) : '';
|
|
2161
|
-
if (subscribing) return;
|
|
2162
|
-
deriveSuggestions(P());
|
|
2163
|
-
paint();
|
|
2164
|
-
});
|
|
2165
|
-
subscribing = false;
|
|
2166
|
-
};
|
|
2167
|
-
|
|
2168
2129
|
// ---- 指针
|
|
2169
2130
|
const stagePoint = (e: PointerEvent | MouseEvent | WheelEvent): Pt => {
|
|
2170
2131
|
const r = stage.getBoundingClientRect();
|
|
@@ -2291,6 +2252,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2291
2252
|
return;
|
|
2292
2253
|
}
|
|
2293
2254
|
// 节点
|
|
2255
|
+
lastPointerNodeKey = pr.key;
|
|
2294
2256
|
if (pr.moved && dragPos !== null && movable()) {
|
|
2295
2257
|
const moved = dragPos;
|
|
2296
2258
|
dragPos = null;
|
|
@@ -2298,17 +2260,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2298
2260
|
return;
|
|
2299
2261
|
}
|
|
2300
2262
|
dragPos = null;
|
|
2301
|
-
|
|
2302
|
-
if (connectFrom !== null) { tryConnect(connectFrom, id); return; }
|
|
2303
|
-
if (pr.additive) {
|
|
2304
|
-
const next = new Set(selected);
|
|
2305
|
-
if (next.has(pr.key)) next.delete(pr.key); else next.add(pr.key);
|
|
2306
|
-
setSelection(next, pr.key);
|
|
2307
|
-
} else {
|
|
2308
|
-
setSelection([pr.key], pr.key);
|
|
2309
|
-
}
|
|
2310
|
-
active = pr.key;
|
|
2311
|
-
paint();
|
|
2263
|
+
activateNodeKey(pr.key, pr.additive);
|
|
2312
2264
|
};
|
|
2313
2265
|
|
|
2314
2266
|
const onPointerCancel = (): void => {
|
|
@@ -2349,7 +2301,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2349
2301
|
case 'zoom-in': zoomBy(FLOW_GEOMETRY.zoomFactor); break;
|
|
2350
2302
|
case 'zoom-out': zoomBy(1 / FLOW_GEOMETRY.zoomFactor); break;
|
|
2351
2303
|
case 'fit': fit(); break;
|
|
2352
|
-
case 'save':
|
|
2304
|
+
case 'save': api.emit('save', payload(graph)); break;
|
|
2353
2305
|
case 'cfg': requestConfig(arg); break;
|
|
2354
2306
|
case 'accept': accept(arg); break;
|
|
2355
2307
|
case 'reject': reject(arg); break;
|
|
@@ -2365,13 +2317,37 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2365
2317
|
}
|
|
2366
2318
|
};
|
|
2367
2319
|
|
|
2320
|
+
let lastPointerNodeKey = '';
|
|
2321
|
+
const activateNodeKey = (nodeKey: string, additive: boolean): void => {
|
|
2322
|
+
const id = nodeKey.slice(2);
|
|
2323
|
+
if (connectFrom !== null) { tryConnect(connectFrom, id); return; }
|
|
2324
|
+
if (additive) {
|
|
2325
|
+
const next = new Set(selected);
|
|
2326
|
+
if (next.has(nodeKey)) next.delete(nodeKey); else next.add(nodeKey);
|
|
2327
|
+
setSelection(next, nodeKey);
|
|
2328
|
+
} else {
|
|
2329
|
+
setSelection([nodeKey], nodeKey);
|
|
2330
|
+
}
|
|
2331
|
+
active = nodeKey;
|
|
2332
|
+
paint();
|
|
2333
|
+
};
|
|
2334
|
+
|
|
2368
2335
|
const onClick = (e: MouseEvent): void => {
|
|
2336
|
+
const consumedPointerKey = lastPointerNodeKey;
|
|
2337
|
+
lastPointerNodeKey = '';
|
|
2369
2338
|
const target = e.target as Element | null;
|
|
2370
2339
|
if (!target) return;
|
|
2371
2340
|
const act = target.closest('[data-flow-act]')?.getAttribute('data-flow-act');
|
|
2372
2341
|
if (act) { runAct(act); return; }
|
|
2373
2342
|
const port = target.closest('[data-flow-port]')?.getAttribute('data-flow-port');
|
|
2374
2343
|
if (port) { flash = ''; startConnect(port); return; }
|
|
2344
|
+
const nodeKey = target.closest('[data-flow-key^="n:"]')?.getAttribute('data-flow-key');
|
|
2345
|
+
if (nodeKey) {
|
|
2346
|
+
if (consumedPointerKey === nodeKey) return;
|
|
2347
|
+
flash = '';
|
|
2348
|
+
activateNodeKey(nodeKey, e.shiftKey || e.ctrlKey || e.metaKey);
|
|
2349
|
+
return;
|
|
2350
|
+
}
|
|
2375
2351
|
const edgeKey = target.closest('[data-flow-key^="e:"]')?.getAttribute('data-flow-key');
|
|
2376
2352
|
if (edgeKey) {
|
|
2377
2353
|
flash = '';
|
|
@@ -2432,7 +2408,7 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2432
2408
|
if (mod && (key === 'z' || key === 'Z')) { handled(); flash = ''; if (e.shiftKey) doRedo(); else doUndo(); return; }
|
|
2433
2409
|
if (mod && (key === 'y' || key === 'Y')) { handled(); flash = ''; doRedo(); return; }
|
|
2434
2410
|
if (mod && (key === 'a' || key === 'A')) { handled(); setSelection(graph.nodes.map((n) => keyOfNode(n.id))); paint(); return; }
|
|
2435
|
-
if (mod && (key === 's' || key === 'S') && editable()) { handled();
|
|
2411
|
+
if (mod && (key === 's' || key === 'S') && editable()) { handled(); api.emit('save', payload(graph)); return; }
|
|
2436
2412
|
if (mod) return;
|
|
2437
2413
|
if (key === '+' || key === '=') { handled(); zoomBy(FLOW_GEOMETRY.zoomFactor); return; }
|
|
2438
2414
|
if (key === '-' || key === '_') { handled(); zoomBy(1 / FLOW_GEOMETRY.zoomFactor); return; }
|
|
@@ -2568,9 +2544,24 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2568
2544
|
};
|
|
2569
2545
|
|
|
2570
2546
|
return {
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2547
|
+
/**
|
|
2548
|
+
* 展示对象可调用的公开方法(core 的 ctx.component(id).call):读当前节点、清空某类型节点的某个字段值。
|
|
2549
|
+
* 清空走 commit:入撤销栈、抛 change、重绘,与用户在面板里改值同一条通道。
|
|
2550
|
+
*/
|
|
2551
|
+
handle: {
|
|
2552
|
+
nodes: (): FlowNode[] => graph.nodes.map((n) => ({ ...n, ...(n.meta ? { meta: { ...n.meta } } : {}) })),
|
|
2553
|
+
clearNodeField: (type: unknown, key: unknown): number => {
|
|
2554
|
+
if (typeof type !== 'string' || typeof key !== 'string' || type === '' || key === '' || !editable()) return 0;
|
|
2555
|
+
const rawTypes = pickOf(P(), 'nodeTypes');
|
|
2556
|
+
const res = clearFlowNodeField({ nodes: graph.nodes, edges: graph.edges }, rawTypes, type, key);
|
|
2557
|
+
if (res.cleared === 0) return 0;
|
|
2558
|
+
commit({ ...graph, nodes: (res.value as { nodes: FlowNode[] }).nodes });
|
|
2559
|
+
return res.cleared;
|
|
2560
|
+
},
|
|
2561
|
+
},
|
|
2562
|
+
attach(rootEl) {
|
|
2563
|
+
root = rootEl;
|
|
2564
|
+
mounted = false;
|
|
2574
2565
|
build(root);
|
|
2575
2566
|
on(stage, 'pointerdown', onPointerDown as (e: Event) => void);
|
|
2576
2567
|
on(stage, 'pointermove', onPointerMove as (e: Event) => void);
|
|
@@ -2596,27 +2587,25 @@ export function createFlowEditor(): SomaComponentDefinition {
|
|
|
2596
2587
|
tryConnect(from, intent.targetId.slice(prefix.length));
|
|
2597
2588
|
});
|
|
2598
2589
|
}
|
|
2599
|
-
|
|
2590
|
+
return () => {
|
|
2591
|
+
mounted = false;
|
|
2592
|
+
for (const fn of removers) fn();
|
|
2593
|
+
removers = [];
|
|
2594
|
+
for (const fn of dndCleanups) fn();
|
|
2595
|
+
dndCleanups = [];
|
|
2596
|
+
offMove?.();
|
|
2597
|
+
offMove = null;
|
|
2598
|
+
panelEmbeds.release(panelInner);
|
|
2599
|
+
root = null;
|
|
2600
|
+
};
|
|
2600
2601
|
},
|
|
2601
|
-
|
|
2602
|
-
|
|
2602
|
+
render(rootEl) {
|
|
2603
|
+
root = rootEl;
|
|
2604
|
+
sync(!mounted);
|
|
2605
|
+
mounted = true;
|
|
2603
2606
|
paint();
|
|
2604
2607
|
},
|
|
2605
|
-
onUnmount(): void {
|
|
2606
|
-
for (const fn of removers) fn();
|
|
2607
|
-
removers = [];
|
|
2608
|
-
for (const fn of dndCleanups) fn();
|
|
2609
|
-
dndCleanups = [];
|
|
2610
|
-
offMove?.();
|
|
2611
|
-
offMove = null;
|
|
2612
|
-
adoptOff?.();
|
|
2613
|
-
adoptOff = null;
|
|
2614
|
-
adoptFrom = '';
|
|
2615
|
-
adoptSug = [];
|
|
2616
|
-
panelEmbeds.release(panelInner);
|
|
2617
|
-
root = null;
|
|
2618
|
-
},
|
|
2619
2608
|
};
|
|
2620
|
-
},
|
|
2609
|
+
}),
|
|
2621
2610
|
};
|
|
2622
2611
|
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// 流程画布节点候选项的纯函数(无 DOM;表单与画布共用,不拉画布分片)。
|
|
2
|
+
// 展示对象把「各节点字段的候选项」写成一个对象成员,页面用纯路径 `nodeOptions: view.<成员>` 绑到画布字段;
|
|
3
|
+
// 成员形如 { "<节点类型>.<字段键>": [{ value, label, meta? }] }。画布把它并进 nodeTypes 里对应 select 字段的 options,
|
|
4
|
+
// 键不在表里的字段保持自己的静态 / 远程候选;表里给了键(哪怕是空数组)就以它为准。
|
|
5
|
+
// 另提供展示对象经控制器 handle 要用的两个操作:读节点、清空某类型节点的某个 meta 字段。
|
|
6
|
+
// 数字读 kit-limits#formLinkage.flowOptions.rowsMax,不手抄。
|
|
7
|
+
|
|
8
|
+
import { KIT_FORM_LINKAGE_LIMITS } from 'soma-foundation/kit-limits';
|
|
9
|
+
|
|
10
|
+
type Rec = Record<string, unknown>;
|
|
11
|
+
type Json = Record<string, any>;
|
|
12
|
+
|
|
13
|
+
const ROWS_MAX = ((KIT_FORM_LINKAGE_LIMITS as unknown as Json).flowOptions as { rowsMax: number }).rowsMax;
|
|
14
|
+
|
|
15
|
+
const isRec = (v: unknown): v is Rec => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
16
|
+
|
|
17
|
+
/** nodeOptions 对象成员的键:节点类型与字段键用点连接 */
|
|
18
|
+
export function flowNodeOptionKey(type: string, key: string): string {
|
|
19
|
+
return `${type}.${key}`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** 一条候选行规整成 { value, label, meta? };value 为空丢弃 */
|
|
23
|
+
function optionRows(raw: unknown): Rec[] {
|
|
24
|
+
if (!Array.isArray(raw)) return [];
|
|
25
|
+
const out: Rec[] = [];
|
|
26
|
+
for (const item of raw) {
|
|
27
|
+
if (out.length >= ROWS_MAX) break;
|
|
28
|
+
if (!isRec(item)) continue;
|
|
29
|
+
const value = typeof item.value === 'string' ? item.value : typeof item.value === 'number' ? String(item.value) : '';
|
|
30
|
+
if (value === '') continue;
|
|
31
|
+
out.push({
|
|
32
|
+
value,
|
|
33
|
+
label: typeof item.label === 'string' && item.label !== '' ? item.label : value,
|
|
34
|
+
...(isRec(item.meta) ? { meta: item.meta } : {}),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 把 nodeOptions 并进 nodeTypes(原始配置,数组或对象两种写法都认):返回新对象,不改入参。
|
|
42
|
+
* 只作用于 kind 为 select 的字段;没给 nodeOptions(或不是对象)原样返回。
|
|
43
|
+
*/
|
|
44
|
+
export function withNodeOptions(nodeTypes: unknown, nodeOptions: unknown): unknown {
|
|
45
|
+
if (!isRec(nodeOptions) || Object.keys(nodeOptions).length === 0) return nodeTypes;
|
|
46
|
+
const patch = (type: string, def: unknown): unknown => {
|
|
47
|
+
if (!isRec(def) || !Array.isArray(def.fields)) return def;
|
|
48
|
+
const fields = def.fields.map((f) => {
|
|
49
|
+
if (!isRec(f) || f.kind !== 'select' || typeof f.key !== 'string') return f;
|
|
50
|
+
const k = flowNodeOptionKey(type, f.key);
|
|
51
|
+
return Object.prototype.hasOwnProperty.call(nodeOptions, k) ? { ...f, options: optionRows(nodeOptions[k]) } : f;
|
|
52
|
+
});
|
|
53
|
+
return { ...def, fields };
|
|
54
|
+
};
|
|
55
|
+
if (Array.isArray(nodeTypes)) return nodeTypes.map((d) => patch(isRec(d) && typeof d.type === 'string' ? d.type : '', d));
|
|
56
|
+
if (!isRec(nodeTypes)) return nodeTypes;
|
|
57
|
+
const out: Rec = {};
|
|
58
|
+
for (const [type, def] of Object.entries(nodeTypes)) out[type] = patch(type, def);
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** 画布字段的值 { nodes, edges, mappings? } 里的节点(浅拷贝,调用方改不到草稿) */
|
|
63
|
+
export function flowValueNodes(value: unknown): Rec[] {
|
|
64
|
+
return isRec(value) && Array.isArray(value.nodes) ? value.nodes.filter(isRec).map((n) => ({ ...n })) : [];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 清空某类型节点的某个 meta 字段(连带该字段声明的 resets 键):返回新的画布值与被清的节点数,不改入参。
|
|
69
|
+
* nodeTypes 用来找字段的 resets 声明(可缺省:只清这一个键)。没有节点带该键时返回原值。
|
|
70
|
+
* 字段声明了 as_label(选中的值同步成节点标题)时,清空后节点标题重置为该节点类型的默认名(类型的 label,缺省用类型名)。
|
|
71
|
+
*/
|
|
72
|
+
export function clearFlowNodeField(value: unknown, nodeTypes: unknown, type: string, key: string): { value: unknown; cleared: number } {
|
|
73
|
+
if (!isRec(value) || !Array.isArray(value.nodes)) return { value, cleared: 0 };
|
|
74
|
+
const defs: unknown = Array.isArray(nodeTypes)
|
|
75
|
+
? nodeTypes.find((d) => isRec(d) && d.type === type)
|
|
76
|
+
: isRec(nodeTypes) ? nodeTypes[type] : undefined;
|
|
77
|
+
const decl = isRec(defs) && Array.isArray(defs.fields) ? defs.fields.find((f) => isRec(f) && f.key === key) : undefined;
|
|
78
|
+
const drop = [key, ...(isRec(decl) && Array.isArray(decl.resets) ? decl.resets.filter((k): k is string => typeof k === 'string') : [])];
|
|
79
|
+
const defaultName = isRec(defs) && typeof defs.label === 'string' && defs.label !== '' ? defs.label : type;
|
|
80
|
+
const resetsLabel = isRec(decl) && decl.as_label === true;
|
|
81
|
+
let cleared = 0;
|
|
82
|
+
const nodes = value.nodes.map((n) => {
|
|
83
|
+
if (!isRec(n) || n.type !== type || !isRec(n.meta) || !(key in n.meta)) return n;
|
|
84
|
+
const meta: Rec = { ...n.meta };
|
|
85
|
+
for (const k of drop) delete meta[k];
|
|
86
|
+
cleared += 1;
|
|
87
|
+
return { ...n, ...(resetsLabel ? { label: defaultName } : {}), meta };
|
|
88
|
+
});
|
|
89
|
+
return cleared === 0 ? { value, cleared: 0 } : { value: { ...value, nodes }, cleared };
|
|
90
|
+
}
|