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/redirect.ts
CHANGED
|
@@ -11,7 +11,7 @@ import type { SomaComponentDefinition } from 'soma-core';
|
|
|
11
11
|
import { CLASS_PROP, createKitController, joinClass, str } from '../base/shared';
|
|
12
12
|
|
|
13
13
|
const ROOT_CLASS = 'flex flex-col gap-2 text-sm text-fg-muted';
|
|
14
|
-
const LINK_CLASS = 'w-fit text-sm text-primary underline underline-offset-2 hover:text-primary-
|
|
14
|
+
const LINK_CLASS = 'w-fit text-sm text-primary-on-soft underline underline-offset-2 hover:text-primary-on-soft focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
15
15
|
|
|
16
16
|
export const KIT_REDIRECT_CLASS_CANDIDATES: readonly string[] = Object.freeze([...new Set([
|
|
17
17
|
ROOT_CLASS, LINK_CLASS,
|
|
@@ -72,38 +72,38 @@ export function createKitRedirect(): SomaComponentDefinition {
|
|
|
72
72
|
},
|
|
73
73
|
},
|
|
74
74
|
templateHtml: `<section data-soma-id="root" class="${ROOT_CLASS}" aria-live="polite"></section>`,
|
|
75
|
-
controllerFactory: (
|
|
75
|
+
controllerFactory: createKitController((api) => {
|
|
76
76
|
// 工厂每个实例调用一次,done 属于该实例
|
|
77
77
|
let done = false;
|
|
78
|
-
return
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
},
|
|
78
|
+
return {
|
|
79
|
+
attach(_root) {
|
|
80
|
+
const win = api.host.ownerDocument.defaultView;
|
|
81
|
+
const p = api.props();
|
|
82
|
+
const target = redirectHref(str(p.to), queryOf(p), win?.location.search ?? '', win?.location.hash ?? '');
|
|
83
|
+
if (!win || done || target === '') return;
|
|
84
|
+
done = true;
|
|
85
|
+
if (p.replace === false || p.replace === 'false') win.location.assign(target);
|
|
86
|
+
else win.location.replace(target);
|
|
87
|
+
},
|
|
88
|
+
render(root, p) {
|
|
89
|
+
const doc = root.ownerDocument;
|
|
90
|
+
const win = doc.defaultView;
|
|
91
|
+
const safe = safeRedirectTarget(str(p.to));
|
|
92
|
+
// 兜底链接带上运行期透传的 query(脚本跳转前可见,也是点击兜底)
|
|
93
|
+
const href = safe === '' ? '' : redirectHref(safe, queryOf(p), win?.location.search ?? '', win?.location.hash ?? '') || safe;
|
|
94
|
+
root.className = joinClass(ROOT_CLASS, p.class);
|
|
95
|
+
const msg = doc.createElement('p');
|
|
96
|
+
msg.textContent = str(p.message);
|
|
97
|
+
root.replaceChildren(msg);
|
|
98
|
+
if (href !== '') {
|
|
99
|
+
const a = doc.createElement('a');
|
|
100
|
+
a.className = LINK_CLASS;
|
|
101
|
+
a.setAttribute('href', href);
|
|
102
|
+
a.textContent = str(p.linkLabel) || href; // 链接不能没有可访问名
|
|
103
|
+
root.appendChild(a);
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}),
|
|
108
108
|
};
|
|
109
109
|
}
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
// 失败照实 reject(调用方显示『选项加载失败』),不吞成空列表。
|
|
5
5
|
|
|
6
6
|
import { KIT_FORM_LINKAGE } from '../object-renderer/defaults';
|
|
7
|
-
import {
|
|
7
|
+
import { kitText } from '../i18n/kit-text';
|
|
8
|
+
import { unwrapEnvelope, envelopeMessage, getKitAppEnvelope, type KitEnvelope } from '../shared/envelope';
|
|
8
9
|
|
|
9
10
|
type Rec = Record<string, unknown>;
|
|
10
11
|
type Json = Record<string, any>;
|
|
@@ -22,11 +23,15 @@ function pickPath(root: unknown, path: string): unknown {
|
|
|
22
23
|
return cur;
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
/**
|
|
26
|
-
|
|
26
|
+
/**
|
|
27
|
+
* 响应体 -> 候选行数组(拆信封,命中业务失败则抛错;成功在 unwrapped.data 或原响应上查找数组)。
|
|
28
|
+
* 信封:显式传入的 `env` 优先;未传时按 `at`(当前组件宿主元素)向上找所属页面宿主登记的信封,同一文档多个宿主互不串。
|
|
29
|
+
*/
|
|
30
|
+
export function rowsOfOptionsResponse(res: unknown, rowsPath: string, envelope?: KitEnvelope, at?: Element | null): Rec[] {
|
|
31
|
+
const env = envelope ?? getKitAppEnvelope(at);
|
|
27
32
|
const unwrapped = unwrapEnvelope(res, env);
|
|
28
33
|
if (!unwrapped.ok) {
|
|
29
|
-
const msg = envelopeMessage(res, env) || '
|
|
34
|
+
const msg = envelopeMessage(res, env) || kitText('soma.kit.options_load_failed');
|
|
30
35
|
throw new Error(msg);
|
|
31
36
|
}
|
|
32
37
|
const payload = unwrapped.data;
|
|
@@ -58,17 +63,19 @@ interface HttpPort {
|
|
|
58
63
|
baseURL?: unknown;
|
|
59
64
|
}
|
|
60
65
|
|
|
61
|
-
/** 取候选行;没有 http 服务 / 请求失败都 reject */
|
|
66
|
+
/** 取候选行;没有 http 服务 / 请求失败都 reject;`envelope` 显式给出时优先,否则 `at`(当前组件宿主元素)用来找所属页面宿主的信封 */
|
|
62
67
|
export function fetchRemoteOptionRows(
|
|
63
68
|
services: Record<string, unknown> | undefined,
|
|
64
69
|
from: string,
|
|
65
70
|
params: Readonly<Record<string, string>>,
|
|
66
71
|
rowsPath: string,
|
|
72
|
+
at?: Element | null,
|
|
73
|
+
envelope?: KitEnvelope,
|
|
67
74
|
): Promise<Rec[]> {
|
|
68
75
|
const http = services?.http as HttpPort | undefined;
|
|
69
76
|
if (!http || typeof http.get !== 'function') return Promise.reject(new Error('no http service'));
|
|
70
77
|
const rawBase = http.baseURL;
|
|
71
78
|
const baseURL = typeof rawBase === 'string' ? rawBase.replace(/\/+$/, '') : '/api';
|
|
72
79
|
const api = baseURL !== '' && baseURL !== '/' && from.startsWith(`${baseURL}/`) ? from.slice(baseURL.length) : from;
|
|
73
|
-
return http.get<unknown>(api, { params: { ...params } }).then((res) => rowsOfOptionsResponse(res, rowsPath));
|
|
80
|
+
return http.get<unknown>(api, { params: { ...params } }).then((res) => rowsOfOptionsResponse(res, rowsPath, envelope, at));
|
|
74
81
|
}
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
import type { SomaComponentDefinition, SomaDataPort } from 'soma-core';
|
|
14
14
|
import { KIT_DATA_LIMITS } from 'soma-foundation/kit-limits';
|
|
15
15
|
import { kitText } from '../i18n/kit-text';
|
|
16
|
-
import {
|
|
16
|
+
import { setKitFace } from '../recipes';
|
|
17
|
+
import { pickPath } from '../object-renderer/path-pick';
|
|
17
18
|
import { watchKitOutcome, type KitOutcome } from './outcome-watch';
|
|
18
19
|
import { bool, createKitController, FIELD_CLASS, joinClass, str } from '../base/shared';
|
|
19
20
|
import {
|
|
@@ -164,7 +165,7 @@ export function createRequestConsole(): SomaComponentDefinition {
|
|
|
164
165
|
},
|
|
165
166
|
services: ['data'],
|
|
166
167
|
templateHtml: `<section data-soma-id="root" class="${ROOT_CLASS}"></section>`,
|
|
167
|
-
controllerFactory: createKitController({
|
|
168
|
+
controllerFactory: createKitController(() => ({
|
|
168
169
|
busyAware: true,
|
|
169
170
|
attach(root, api) {
|
|
170
171
|
const snapshot = (): { method: string; target: string; params: string } => {
|
|
@@ -238,7 +239,7 @@ export function createRequestConsole(): SomaComponentDefinition {
|
|
|
238
239
|
}
|
|
239
240
|
paint(root, p);
|
|
240
241
|
},
|
|
241
|
-
}),
|
|
242
|
+
})),
|
|
242
243
|
};
|
|
243
244
|
|
|
244
245
|
function paint(root: HTMLElement, p: Record<string, unknown>): void {
|
|
@@ -337,6 +338,7 @@ export function createRequestConsole(): SomaComponentDefinition {
|
|
|
337
338
|
const wrap = mk('label', FIELD_WRAP);
|
|
338
339
|
wrap.appendChild(mk('span', LABEL_CLASS, str(p.params_label, kitText('soma.kit.rc_params', undefined, root))));
|
|
339
340
|
const area = mk('textarea', AREA_CLASS);
|
|
341
|
+
setKitFace(area, 'field');
|
|
340
342
|
area.setAttribute('data-kit-params', '');
|
|
341
343
|
wrap.appendChild(area);
|
|
342
344
|
n.paramsWrap.appendChild(wrap);
|
package/src/data/resident.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// 浏览器面只 import 本文件(不 import ./index,那里静态连着全部写死形状件),写死形状件走 static-lazy 按需加载。
|
|
3
3
|
|
|
4
4
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
5
|
+
import { createKitController } from '../base/shared';
|
|
5
6
|
import { createKitObjectForm } from './object-form';
|
|
6
7
|
import { createRowEditor } from './row-editor';
|
|
7
8
|
import { FLOW_EDITOR_CONTRACT } from './flow-editor-contract';
|
|
@@ -34,7 +35,7 @@ export function createKitResidentDataComponents(
|
|
|
34
35
|
const flowEditorShell: SomaComponentDefinition = {
|
|
35
36
|
contract: FLOW_EDITOR_CONTRACT,
|
|
36
37
|
templateHtml: '<div data-soma-id="root"></div>',
|
|
37
|
-
controllerFactory: () => ({}),
|
|
38
|
+
controllerFactory: createKitController(() => ({ render() {} })),
|
|
38
39
|
} as unknown as SomaComponentDefinition;
|
|
39
40
|
return {
|
|
40
41
|
RowEditor: rowEditor,
|
package/src/data/result-panel.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
12
12
|
import { bool, createKitController, joinClass, str } from '../base/shared';
|
|
13
13
|
import { kitIcon, type KitIconName } from '../base/icons';
|
|
14
|
+
import { KIT_PART_ATTRIBUTE, KIT_PART_PANEL } from '../recipes';
|
|
14
15
|
import { singleOf } from './display-util';
|
|
15
16
|
import { kitText, type KitTextKey } from '../i18n/kit-text';
|
|
16
17
|
import {
|
|
@@ -120,7 +121,7 @@ export function createResultPanel(): SomaComponentDefinition {
|
|
|
120
121
|
},
|
|
121
122
|
},
|
|
122
123
|
templateHtml: `<section data-soma-id="root" class="${ROOT_CLASS}"></section>`,
|
|
123
|
-
controllerFactory: createKitController({
|
|
124
|
+
controllerFactory: createKitController(() => ({
|
|
124
125
|
attach(root, api) {
|
|
125
126
|
const onClick = (event: Event): void => {
|
|
126
127
|
const hit = (event.target as HTMLElement | null)?.closest<HTMLElement>('[data-kit-action]');
|
|
@@ -135,6 +136,7 @@ export function createResultPanel(): SomaComponentDefinition {
|
|
|
135
136
|
render(root, p) {
|
|
136
137
|
const compact = bool(p.compact);
|
|
137
138
|
root.className = joinClass(compact ? ROOT_COMPACT_CLASS : ROOT_CLASS, p.class);
|
|
139
|
+
root.setAttribute(KIT_PART_ATTRIBUTE, KIT_PART_PANEL);
|
|
138
140
|
root.textContent = '';
|
|
139
141
|
const model = resultModelOf(p.data, p, root);
|
|
140
142
|
const isCode = model.glyph.length === 3;
|
|
@@ -155,6 +157,6 @@ export function createResultPanel(): SomaComponentDefinition {
|
|
|
155
157
|
root.appendChild(bar);
|
|
156
158
|
}
|
|
157
159
|
},
|
|
158
|
-
}),
|
|
160
|
+
})),
|
|
159
161
|
};
|
|
160
162
|
}
|
package/src/data/rich-text.ts
CHANGED
|
@@ -9,9 +9,10 @@
|
|
|
9
9
|
// `readonly` 为真时只展示净化后的内容,不出工具栏。
|
|
10
10
|
// `source: markdown`(A17):内容是 Markdown 文本,转成 HTML 后经同一净化器渲染,固定只读;见「Markdown(只读来源)」段。
|
|
11
11
|
|
|
12
|
-
import type {
|
|
13
|
-
import { bool, joinClass, num, str } from '../base/shared';
|
|
12
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
13
|
+
import { bool, createKitController, joinClass, num, str } from '../base/shared';
|
|
14
14
|
import { kitText, type KitTextKey } from '../i18n/kit-text';
|
|
15
|
+
import { setKitFace } from '../recipes';
|
|
15
16
|
import { classTokens, mk, recOf } from './shape-util';
|
|
16
17
|
import { RICH_ALLOWED_TAGS, RICH_COMMANDS, RICH_LINK_PROTOCOLS, RICH_MAX_LENGTH } from './d9-limits';
|
|
17
18
|
|
|
@@ -297,8 +298,8 @@ export function createRichTextEditor(): SomaComponentDefinition {
|
|
|
297
298
|
},
|
|
298
299
|
},
|
|
299
300
|
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
|
|
300
|
-
controllerFactory: (
|
|
301
|
-
const P = (): Record<string, unknown> =>
|
|
301
|
+
controllerFactory: createKitController((api) => {
|
|
302
|
+
const P = (): Record<string, unknown> => api.props();
|
|
302
303
|
let root: HTMLElement | null = null;
|
|
303
304
|
let area: HTMLElement | null = null;
|
|
304
305
|
let holder: HTMLElement | null = null;
|
|
@@ -309,7 +310,6 @@ export function createRichTextEditor(): SomaComponentDefinition {
|
|
|
309
310
|
let savedRange: Range | null = null;
|
|
310
311
|
let lastInit = '\u0000';
|
|
311
312
|
let builtReadonly: boolean | null = null;
|
|
312
|
-
let removeListeners: Array<() => void> = [];
|
|
313
313
|
|
|
314
314
|
/** source: markdown 时内容是 Markdown 文本(value 优先,其次 data.markdown,再退 data.html),一律只读 */
|
|
315
315
|
const isMarkdown = (): boolean => P().source === 'markdown';
|
|
@@ -343,7 +343,7 @@ export function createRichTextEditor(): SomaComponentDefinition {
|
|
|
343
343
|
const value = sanitizeRichHtml(area.innerHTML);
|
|
344
344
|
const text = (area.textContent ?? '');
|
|
345
345
|
refresh();
|
|
346
|
-
|
|
346
|
+
api.emit('change', { value: text.trim() === '' ? '' : value, empty: text.trim() === '', length: text.length });
|
|
347
347
|
};
|
|
348
348
|
|
|
349
349
|
const setContent = (html: string): void => {
|
|
@@ -480,9 +480,9 @@ export function createRichTextEditor(): SomaComponentDefinition {
|
|
|
480
480
|
if (!ro) {
|
|
481
481
|
bar = mk('div', BAR_CLASS);
|
|
482
482
|
bar.setAttribute('role', 'toolbar');
|
|
483
|
-
bar.setAttribute('aria-label', str(p.label, kitText('soma.kit.rt_area', undefined,
|
|
483
|
+
bar.setAttribute('aria-label', str(p.label, kitText('soma.kit.rt_area', undefined, api.host)));
|
|
484
484
|
const can = typeof document.execCommand === 'function';
|
|
485
|
-
richCommandsOf(p.commands,
|
|
485
|
+
richCommandsOf(p.commands, api.host).forEach((c, i) => {
|
|
486
486
|
const b = mk('button', BTN_CLASS);
|
|
487
487
|
const glyph = mk('span', '', c.text);
|
|
488
488
|
glyph.setAttribute('aria-hidden', 'true');
|
|
@@ -499,10 +499,11 @@ export function createRichTextEditor(): SomaComponentDefinition {
|
|
|
499
499
|
root.appendChild(bar);
|
|
500
500
|
linkBar = mk('div', `${LINKBAR_CLASS} hidden`);
|
|
501
501
|
linkInput = mk('input', LINK_INPUT);
|
|
502
|
+
setKitFace(linkInput, 'field');
|
|
502
503
|
linkInput.type = 'url';
|
|
503
|
-
linkInput.placeholder = str(p.link_text, kitText('soma.kit.rt_link_url', undefined,
|
|
504
|
-
linkInput.setAttribute('aria-label', str(p.link_text, kitText('soma.kit.rt_link_url', undefined,
|
|
505
|
-
const ok = mk('button', BTN_CLASS, str(p.apply_text, kitText('soma.kit.ok', undefined,
|
|
504
|
+
linkInput.placeholder = str(p.link_text, kitText('soma.kit.rt_link_url', undefined, api.host));
|
|
505
|
+
linkInput.setAttribute('aria-label', str(p.link_text, kitText('soma.kit.rt_link_url', undefined, api.host)));
|
|
506
|
+
const ok = mk('button', BTN_CLASS, str(p.apply_text, kitText('soma.kit.ok', undefined, api.host)));
|
|
506
507
|
ok.type = 'button';
|
|
507
508
|
ok.setAttribute('data-kit-link-apply', '');
|
|
508
509
|
linkBar.append(linkInput, ok);
|
|
@@ -512,7 +513,7 @@ export function createRichTextEditor(): SomaComponentDefinition {
|
|
|
512
513
|
area = mk('div', AREA_CLASS);
|
|
513
514
|
area.setAttribute('role', 'textbox');
|
|
514
515
|
area.setAttribute('aria-multiline', 'true');
|
|
515
|
-
area.setAttribute('aria-label', str(p.label, kitText('soma.kit.rt_area', undefined,
|
|
516
|
+
area.setAttribute('aria-label', str(p.label, kitText('soma.kit.rt_area', undefined, api.host)));
|
|
516
517
|
if (!ro) area.setAttribute('contenteditable', 'true');
|
|
517
518
|
holder = mk('span', HOLDER_CLASS);
|
|
518
519
|
holder.setAttribute('aria-hidden', 'true');
|
|
@@ -523,26 +524,9 @@ export function createRichTextEditor(): SomaComponentDefinition {
|
|
|
523
524
|
lastInit = '\u0000';
|
|
524
525
|
};
|
|
525
526
|
|
|
526
|
-
const paint = (): void => {
|
|
527
|
-
if (!root) return;
|
|
528
|
-
const ro = bool(P().readonly) || isMarkdown();
|
|
529
|
-
if (builtReadonly !== ro || !area) {
|
|
530
|
-
// 模式切换要重建 DOM:先带走当前内容
|
|
531
|
-
const keep = area ? sanitizeRichHtml(area.innerHTML) : null;
|
|
532
|
-
build();
|
|
533
|
-
if (keep !== null) { setContent(keep); lastInit = initialHtml(); }
|
|
534
|
-
}
|
|
535
|
-
const init = initialHtml();
|
|
536
|
-
if (init !== lastInit) { lastInit = init; setContent(init); }
|
|
537
|
-
if (holder) holder.textContent = str(P().placeholder);
|
|
538
|
-
refresh();
|
|
539
|
-
};
|
|
540
|
-
|
|
541
527
|
return {
|
|
542
|
-
|
|
543
|
-
root =
|
|
544
|
-
?? ctx.host.querySelector<HTMLElement>('[data-soma-id="root"]')
|
|
545
|
-
?? ctx.host;
|
|
528
|
+
attach(rootEl) {
|
|
529
|
+
root = rootEl;
|
|
546
530
|
const r = root;
|
|
547
531
|
const onClick = (event: Event): void => {
|
|
548
532
|
const t = event.target as HTMLElement | null;
|
|
@@ -595,32 +579,38 @@ export function createRichTextEditor(): SomaComponentDefinition {
|
|
|
595
579
|
r.addEventListener('paste', onPaste as EventListener);
|
|
596
580
|
r.addEventListener('mousedown', onDown);
|
|
597
581
|
document.addEventListener('selectionchange', onSelection);
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
582
|
+
return () => {
|
|
583
|
+
r.removeEventListener('click', onClick);
|
|
584
|
+
r.removeEventListener('input', onInput);
|
|
585
|
+
r.removeEventListener('keydown', onKeydown as EventListener);
|
|
586
|
+
r.removeEventListener('paste', onPaste as EventListener);
|
|
587
|
+
r.removeEventListener('mousedown', onDown);
|
|
588
|
+
document.removeEventListener('selectionchange', onSelection);
|
|
589
|
+
savedRange = null;
|
|
590
|
+
root = null;
|
|
591
|
+
area = null;
|
|
592
|
+
holder = null;
|
|
593
|
+
foot = null;
|
|
594
|
+
bar = null;
|
|
595
|
+
linkBar = null;
|
|
596
|
+
linkInput = null;
|
|
597
|
+
};
|
|
610
598
|
},
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
599
|
+
render(rootEl, p) {
|
|
600
|
+
root = rootEl;
|
|
601
|
+
const ro = bool(p.readonly) || isMarkdown();
|
|
602
|
+
if (builtReadonly !== ro || !area) {
|
|
603
|
+
// 模式切换要重建 DOM:先带走当前内容
|
|
604
|
+
const keep = area ? sanitizeRichHtml(area.innerHTML) : null;
|
|
605
|
+
build();
|
|
606
|
+
if (keep !== null) { setContent(keep); lastInit = initialHtml(); }
|
|
607
|
+
}
|
|
608
|
+
const init = initialHtml();
|
|
609
|
+
if (init !== lastInit) { lastInit = init; setContent(init); }
|
|
610
|
+
if (holder) holder.textContent = str(p.placeholder);
|
|
611
|
+
refresh();
|
|
622
612
|
},
|
|
623
613
|
};
|
|
624
|
-
},
|
|
614
|
+
}),
|
|
625
615
|
};
|
|
626
616
|
}
|