@gantfdt/semiword 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +6 -0
- package/README.md +258 -2
- package/dist-lib/FlowchartEditor-EFUVACVN.mjs +442 -0
- package/dist-lib/FlowchartEditor-EFUVACVN.mjs.map +1 -0
- package/dist-lib/MindmapEditor-CCJRPI4I.mjs +141 -0
- package/dist-lib/MindmapEditor-CCJRPI4I.mjs.map +1 -0
- package/dist-lib/WhiteboardEditor-STZ7W7XX.mjs +120 -0
- package/dist-lib/WhiteboardEditor-STZ7W7XX.mjs.map +1 -0
- package/dist-lib/ai.d.mts +33 -0
- package/dist-lib/ai.mjs +14 -0
- package/dist-lib/ai.mjs.map +1 -0
- package/dist-lib/chunk-347SCO7S.mjs +3 -0
- package/dist-lib/chunk-347SCO7S.mjs.map +1 -0
- package/dist-lib/chunk-4F4NEVHE.mjs +100 -0
- package/dist-lib/chunk-4F4NEVHE.mjs.map +1 -0
- package/dist-lib/chunk-4W6PPBHQ.mjs +474 -0
- package/dist-lib/chunk-4W6PPBHQ.mjs.map +1 -0
- package/dist-lib/chunk-7AAZUM6M.mjs +45 -0
- package/dist-lib/chunk-7AAZUM6M.mjs.map +1 -0
- package/dist-lib/chunk-BBZ5ZBEK.mjs +1510 -0
- package/dist-lib/chunk-BBZ5ZBEK.mjs.map +1 -0
- package/dist-lib/chunk-CREU4TZJ.mjs +24 -0
- package/dist-lib/chunk-CREU4TZJ.mjs.map +1 -0
- package/dist-lib/chunk-EEUFVA37.mjs +4024 -0
- package/dist-lib/chunk-EEUFVA37.mjs.map +1 -0
- package/dist-lib/chunk-EOIJPQZI.mjs +370 -0
- package/dist-lib/chunk-EOIJPQZI.mjs.map +1 -0
- package/dist-lib/chunk-EOUNN3NA.mjs +1517 -0
- package/dist-lib/chunk-EOUNN3NA.mjs.map +1 -0
- package/dist-lib/chunk-FOIP7DEC.mjs +12 -0
- package/dist-lib/chunk-FOIP7DEC.mjs.map +1 -0
- package/dist-lib/chunk-GGIOCI2I.mjs +2442 -0
- package/dist-lib/chunk-GGIOCI2I.mjs.map +1 -0
- package/dist-lib/chunk-IICCIMZU.mjs +5272 -0
- package/dist-lib/chunk-IICCIMZU.mjs.map +1 -0
- package/dist-lib/chunk-JC5ZZPSL.mjs +600 -0
- package/dist-lib/chunk-JC5ZZPSL.mjs.map +1 -0
- package/dist-lib/chunk-K7Z56Q4M.mjs +6327 -0
- package/dist-lib/chunk-K7Z56Q4M.mjs.map +1 -0
- package/dist-lib/chunk-NPPS63UI.mjs +285 -0
- package/dist-lib/chunk-NPPS63UI.mjs.map +1 -0
- package/dist-lib/chunk-PFA3XERW.mjs +19 -0
- package/dist-lib/chunk-PFA3XERW.mjs.map +1 -0
- package/dist-lib/chunk-QWDJU3H7.mjs +18 -0
- package/dist-lib/chunk-QWDJU3H7.mjs.map +1 -0
- package/dist-lib/chunk-TOA6CRSJ.mjs +3917 -0
- package/dist-lib/chunk-TOA6CRSJ.mjs.map +1 -0
- package/dist-lib/chunk-W627LLF4.mjs +16 -0
- package/dist-lib/chunk-W627LLF4.mjs.map +1 -0
- package/dist-lib/chunk-XAEALEVP.mjs +547 -0
- package/dist-lib/chunk-XAEALEVP.mjs.map +1 -0
- package/dist-lib/chunk-ZM3WULHX.mjs +910 -0
- package/dist-lib/chunk-ZM3WULHX.mjs.map +1 -0
- package/dist-lib/context-DKwyjx1q.d.mts +37 -0
- package/dist-lib/designer.d.mts +215 -0
- package/dist-lib/designer.mjs +15 -0
- package/dist-lib/designer.mjs.map +1 -0
- package/dist-lib/document.d.mts +12 -0
- package/dist-lib/document.mjs +4 -0
- package/dist-lib/document.mjs.map +1 -0
- package/dist-lib/editor.d.mts +408 -0
- package/dist-lib/editor.mjs +19 -0
- package/dist-lib/editor.mjs.map +1 -0
- package/dist-lib/gant-ai.d.mts +40 -0
- package/dist-lib/gant-ai.mjs +217 -0
- package/dist-lib/gant-ai.mjs.map +1 -0
- package/dist-lib/index.d.mts +22 -0
- package/dist-lib/index.mjs +19 -0
- package/dist-lib/index.mjs.map +1 -0
- package/dist-lib/interface-RYndHNLS.d.mts +91 -0
- package/dist-lib/io.d.mts +75 -0
- package/dist-lib/io.mjs +9 -0
- package/dist-lib/io.mjs.map +1 -0
- package/dist-lib/memoryHistoryStore-DY47xjO_.d.mts +280 -0
- package/dist-lib/mindmapConstants-X75XUXV3.mjs +4 -0
- package/dist-lib/mindmapConstants-X75XUXV3.mjs.map +1 -0
- package/dist-lib/resolve-BMcwblyP.d.mts +114 -0
- package/dist-lib/sdk.d.mts +60 -0
- package/dist-lib/sdk.mjs +137 -0
- package/dist-lib/sdk.mjs.map +1 -0
- package/dist-lib/shapes-5SMSF6ML.mjs +4 -0
- package/dist-lib/shapes-5SMSF6ML.mjs.map +1 -0
- package/dist-lib/storage.d.mts +91 -0
- package/dist-lib/storage.mjs +5 -0
- package/dist-lib/storage.mjs.map +1 -0
- package/dist-lib/template.d.mts +155 -0
- package/dist-lib/template.mjs +6 -0
- package/dist-lib/template.mjs.map +1 -0
- package/dist-lib/types-CO6ppyIY.d.mts +18 -0
- package/dist-lib/types-CUsV1hUm.d.mts +49 -0
- package/dist-lib/types-ClQ38-C_.d.mts +256 -0
- package/dist-lib/types-D1D2miCr.d.mts +117 -0
- package/dist-lib/types-DiyyKlc1.d.mts +355 -0
- package/dist-lib/types-s1JYaGtG.d.mts +56 -0
- package/dist-lib/types-vl8k8NDK.d.mts +562 -0
- package/dist-lib/useDocumentPersistence-DOpnQsZQ.d.mts +228 -0
- package/package.json +282 -4
|
@@ -0,0 +1,3917 @@
|
|
|
1
|
+
import { RichEditor } from './chunk-GGIOCI2I.mjs';
|
|
2
|
+
import { useTemplateStorage, TemplateStorageProvider, DEFAULT_MAX_DRAFTS } from './chunk-4F4NEVHE.mjs';
|
|
3
|
+
import { useBlockOutlineStyles, getDesignerBlockDescriptor, blockTypeMeta, isFreeDesignerBlock, useCanvasBlockItemStyles, useCanvasPanelStyles, explainRelocateReject, structureSignatureOf, useBlockSettingsFormStyles, ControlItem, DataBindingSelect, IMAGE_DEFAULT_WIDTH, IMAGE_DEFAULT_HEIGHT, useBlockPaletteToolbarStyles, getDesignerPalette, TEMPLATE_PIN_OPTIONS, DataTableView_default, FormTableView_default, parseInlineSlots, groupDisplayLabel, buildDefinition, parseDefinition, normalizeDesignerTemplate, explainGroupSelection, explainUngroupSelection, TooltipButton, useTemplateDesignerStyles, emptyTemplate, validateBlockStructure, applyFreeSwitch, insertionIndexForNewBlock, nextDesignerUid, tryMoveBlocks, relocateUnitBefore, applyPin, setOrderConstraints, leaveGroup, joinGroup, groupSelectedBlocks, ungroupSelectedBlocks, renameGroup, collectGroupOptions, countRequiredSlots, parseTableJson, createBlockFromPalette, useDesignerTopBarStyles, useLibrarySidePanelStyles, useInspectorPanelStyles, useTemplateBasicInfoFormStyles, TEMPLATE_ID_PATTERN, useTableJsonImportModalStyles, useTemplateLibraryPanelStyles, storedBlockCount, LIB_ITEM_DELETE_CLS, extractDesignerNodeText } from './chunk-IICCIMZU.mjs';
|
|
4
|
+
import { createTemplateDataPreviewDefinition, resolveTemplateDataFromSource } from './chunk-NPPS63UI.mjs';
|
|
5
|
+
import { getImportSchemaExtensions, exportHtml, jsonToMarkdown, markdownToHtml } from './chunk-XAEALEVP.mjs';
|
|
6
|
+
import { showMessage, downloadFile, showConfirmModal } from './chunk-K7Z56Q4M.mjs';
|
|
7
|
+
import { createStyles, Checkbox, Tag, Button, Tooltip, Input, Radio, InputNumber, Space, Dropdown, Switch, Select, Select2, Spin, CustomEmpty, Modal, Drawer, Popover, Alert, Tabs } from './chunk-ZM3WULHX.mjs';
|
|
8
|
+
import { sanitizeHtml } from './chunk-4W6PPBHQ.mjs';
|
|
9
|
+
import { tr } from './chunk-W627LLF4.mjs';
|
|
10
|
+
import { genId } from './chunk-CREU4TZJ.mjs';
|
|
11
|
+
import { memo, useRef, useCallback, useMemo, useState, useEffect, useLayoutEffect, Fragment as Fragment$1 } from 'react';
|
|
12
|
+
import { generateHTML, generateJSON } from '@tiptap/core';
|
|
13
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
14
|
+
import { ArrowUpOutlined, ArrowDownOutlined, CodeOutlined, TableOutlined, PictureOutlined, AlignLeftOutlined, FontSizeOutlined, BlockOutlined, HolderOutlined, DeleteOutlined, AppstoreAddOutlined, DownOutlined, AuditOutlined, ArrowLeftOutlined, EditOutlined, WarningOutlined, SaveOutlined, ImportOutlined, ExportOutlined, DatabaseOutlined, MenuUnfoldOutlined, PlusOutlined, MenuFoldOutlined, FileTextOutlined } from '@ant-design/icons';
|
|
15
|
+
|
|
16
|
+
function isDesignerTemplate(template) {
|
|
17
|
+
return (template.designer?.blocks?.length ?? 0) > 0;
|
|
18
|
+
}
|
|
19
|
+
function useTemplateLibrary(options) {
|
|
20
|
+
const { storage, savedTemplateIdRef } = options;
|
|
21
|
+
const { templates, history } = storage;
|
|
22
|
+
const [library, setLibrary] = useState([]);
|
|
23
|
+
const reloadLibrary = useCallback(async () => {
|
|
24
|
+
try {
|
|
25
|
+
const list = await templates.list();
|
|
26
|
+
setLibrary(list.filter(isDesignerTemplate));
|
|
27
|
+
} catch (e) {
|
|
28
|
+
console.error("[TemplateDesigner] \u8BFB\u53D6\u6A21\u677F\u5E93\u5931\u8D25:", e);
|
|
29
|
+
showMessage(tr("\u8BFB\u53D6\u6A21\u677F\u5E93\u5931\u8D25"), { type: "error" });
|
|
30
|
+
}
|
|
31
|
+
}, [templates]);
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
reloadLibrary();
|
|
34
|
+
}, [reloadLibrary]);
|
|
35
|
+
const handleDelete = useCallback(
|
|
36
|
+
(item) => {
|
|
37
|
+
showConfirmModal({
|
|
38
|
+
title: tr("\u5220\u9664\u6A21\u677F"),
|
|
39
|
+
content: tr("\u786E\u5B9A\u5220\u9664\u6A21\u677F\u300C${0}\u300D\uFF1F\u6B64\u64CD\u4F5C\u4E0D\u53EF\u64A4\u9500\u3002", [item.name]),
|
|
40
|
+
type: "warning",
|
|
41
|
+
okType: "danger",
|
|
42
|
+
okButtonProps: { danger: true },
|
|
43
|
+
okText: tr("\u5220\u9664"),
|
|
44
|
+
cancelText: tr("\u53D6\u6D88"),
|
|
45
|
+
onOk: async () => {
|
|
46
|
+
try {
|
|
47
|
+
await templates.remove(item.id);
|
|
48
|
+
if (savedTemplateIdRef.current === item.id) savedTemplateIdRef.current = null;
|
|
49
|
+
try {
|
|
50
|
+
await history.deleteAllForTemplate(item.id);
|
|
51
|
+
} catch (e) {
|
|
52
|
+
console.error("[TemplateDesigner] \u5386\u53F2\u7248\u672C\u7EA7\u8054\u6E05\u7406\u5931\u8D25:", e);
|
|
53
|
+
}
|
|
54
|
+
await reloadLibrary();
|
|
55
|
+
showMessage(tr("\u5DF2\u5220\u9664"), { type: "success" });
|
|
56
|
+
} catch (e) {
|
|
57
|
+
console.error("[TemplateDesigner] \u5220\u9664\u5931\u8D25:", e);
|
|
58
|
+
showMessage(tr("\u5220\u9664\u5931\u8D25"), { type: "error" });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
[templates, history, reloadLibrary, savedTemplateIdRef]
|
|
64
|
+
);
|
|
65
|
+
return { library, reload: reloadLibrary, handleDelete };
|
|
66
|
+
}
|
|
67
|
+
var MAX_IMPORT_FILE_SIZE = 10 * 1024 * 1024;
|
|
68
|
+
var IMPORT_EXTENSION_FORMAT = {
|
|
69
|
+
json: "json",
|
|
70
|
+
md: "markdown",
|
|
71
|
+
markdown: "markdown",
|
|
72
|
+
html: "html",
|
|
73
|
+
htm: "html"
|
|
74
|
+
};
|
|
75
|
+
function exportTemplate(designer, format) {
|
|
76
|
+
const built = buildDefinition(designer);
|
|
77
|
+
if (!built.ok) {
|
|
78
|
+
return { ok: false, message: built.issues[0]?.message ?? "\u6A21\u677F\u7F16\u8BD1\u5931\u8D25" };
|
|
79
|
+
}
|
|
80
|
+
const { definition } = built;
|
|
81
|
+
const previewDefinition = createTemplateDataPreviewDefinition(definition);
|
|
82
|
+
switch (format) {
|
|
83
|
+
case "json": {
|
|
84
|
+
downloadFile(JSON.stringify(definition, null, 2), `${definition.id}.json`, "application/json");
|
|
85
|
+
return { ok: true };
|
|
86
|
+
}
|
|
87
|
+
case "markdown": {
|
|
88
|
+
const md = jsonToMarkdown(previewDefinition.content);
|
|
89
|
+
if (!md.trim()) {
|
|
90
|
+
return { ok: false, message: "\u6A21\u677F\u5185\u5BB9\u4E3A\u7A7A\uFF0C\u65E0 Markdown \u53EF\u5BFC\u51FA" };
|
|
91
|
+
}
|
|
92
|
+
downloadFile(md, `${definition.id}.md`, "text/markdown");
|
|
93
|
+
return { ok: true };
|
|
94
|
+
}
|
|
95
|
+
case "html": {
|
|
96
|
+
const doc = downgradeForHtmlExport(previewDefinition.content) ?? previewDefinition.content;
|
|
97
|
+
let html;
|
|
98
|
+
try {
|
|
99
|
+
html = generateHTML(doc, getImportSchemaExtensions());
|
|
100
|
+
} catch {
|
|
101
|
+
return { ok: false, message: "\u751F\u6210 HTML \u5931\u8D25\uFF1A\u6A21\u677F\u5305\u542B\u5BFC\u51FA\u73AF\u5883\u4E0D\u652F\u6301\u7684\u8282\u70B9" };
|
|
102
|
+
}
|
|
103
|
+
if (!html.trim()) {
|
|
104
|
+
return { ok: false, message: "\u6A21\u677F\u5185\u5BB9\u4E3A\u7A7A\uFF0C\u65E0 HTML \u53EF\u5BFC\u51FA" };
|
|
105
|
+
}
|
|
106
|
+
exportHtml(html, definition.id);
|
|
107
|
+
return { ok: true };
|
|
108
|
+
}
|
|
109
|
+
default:
|
|
110
|
+
return { ok: false, message: `\u4E0D\u652F\u6301\u7684\u5BFC\u51FA\u683C\u5F0F\uFF1A${format}` };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
async function importTemplateFile(file) {
|
|
114
|
+
if (file.size > MAX_IMPORT_FILE_SIZE) {
|
|
115
|
+
return { ok: false, message: "\u6587\u4EF6\u5927\u5C0F\u8D85\u8FC7 10MB \u9650\u5236" };
|
|
116
|
+
}
|
|
117
|
+
const ext = file.name.split(".").pop()?.toLowerCase() ?? "";
|
|
118
|
+
const format = IMPORT_EXTENSION_FORMAT[ext];
|
|
119
|
+
if (!format) {
|
|
120
|
+
return { ok: false, message: "\u4E0D\u652F\u6301\u7684\u6587\u4EF6\u7C7B\u578B\uFF08\u652F\u6301 .json/.md/.html\uFF09" };
|
|
121
|
+
}
|
|
122
|
+
let text;
|
|
123
|
+
try {
|
|
124
|
+
text = await file.text();
|
|
125
|
+
} catch {
|
|
126
|
+
return { ok: false, message: "\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25" };
|
|
127
|
+
}
|
|
128
|
+
if (format === "json") {
|
|
129
|
+
return importJsonText(text);
|
|
130
|
+
}
|
|
131
|
+
const html = format === "markdown" ? markdownToHtml(text) : text;
|
|
132
|
+
return importHtmlContent(html, format, file.name);
|
|
133
|
+
}
|
|
134
|
+
function importJsonText(text) {
|
|
135
|
+
let parsed;
|
|
136
|
+
try {
|
|
137
|
+
parsed = JSON.parse(text);
|
|
138
|
+
} catch {
|
|
139
|
+
return { ok: false, message: "JSON \u683C\u5F0F\u4E0D\u6B63\u786E" };
|
|
140
|
+
}
|
|
141
|
+
const result = parseDefinition(parsed);
|
|
142
|
+
if (!result.ok) {
|
|
143
|
+
return { ok: false, message: result.message };
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
ok: true,
|
|
147
|
+
format: "json",
|
|
148
|
+
designer: result.designer,
|
|
149
|
+
skipped: result.skipped,
|
|
150
|
+
warnings: result.warnings
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function importHtmlContent(html, format, fileName) {
|
|
154
|
+
let docJson;
|
|
155
|
+
try {
|
|
156
|
+
docJson = generateJSON(sanitizeHtml(html), getImportSchemaExtensions());
|
|
157
|
+
} catch {
|
|
158
|
+
return { ok: false, message: "\u5185\u5BB9\u89E3\u6790\u5931\u8D25" };
|
|
159
|
+
}
|
|
160
|
+
if (docJson.type !== "doc" || !Array.isArray(docJson.content)) {
|
|
161
|
+
return { ok: false, message: "\u5185\u5BB9\u89E3\u6790\u5931\u8D25" };
|
|
162
|
+
}
|
|
163
|
+
const definition = {
|
|
164
|
+
schemaVersion: 2,
|
|
165
|
+
// genId 保证唯一:同毫秒内连续导入时 Date.now() 会撞出重复 id。
|
|
166
|
+
id: `tpl-${genId()}`,
|
|
167
|
+
name: fileName.replace(/\.[^.]+$/, "") || "\u5BFC\u5165\u6A21\u677F",
|
|
168
|
+
version: "1.0.0",
|
|
169
|
+
content: docJson
|
|
170
|
+
};
|
|
171
|
+
const result = parseDefinition(definition);
|
|
172
|
+
if (!result.ok) {
|
|
173
|
+
return { ok: false, message: result.message };
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
ok: true,
|
|
177
|
+
format,
|
|
178
|
+
designer: result.designer,
|
|
179
|
+
skipped: result.skipped,
|
|
180
|
+
warnings: result.warnings
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function downgradeForHtmlExport(node) {
|
|
184
|
+
if (node.type === "templateInlineSlot") {
|
|
185
|
+
const attrs = node.attrs ?? {};
|
|
186
|
+
const value = typeof attrs.value === "string" ? attrs.value : "";
|
|
187
|
+
const label = typeof attrs.slotLabel === "string" ? attrs.slotLabel : "";
|
|
188
|
+
const placeholder = attrs.required === true ? `{[${label}]}` : `{{${label}}}`;
|
|
189
|
+
const text = value || placeholder;
|
|
190
|
+
return text ? { type: "text", text } : null;
|
|
191
|
+
}
|
|
192
|
+
if (!Array.isArray(node.content)) return node;
|
|
193
|
+
const content = node.content.map(downgradeForHtmlExport).filter((child) => child !== null);
|
|
194
|
+
return { ...node, content };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// src/editor/features/templatedesigner/history/utils/hash.ts
|
|
198
|
+
function hashDesignerTemplate(designer) {
|
|
199
|
+
const text = JSON.stringify(normalizeDesignerTemplate(designer));
|
|
200
|
+
let hash = 2166136261;
|
|
201
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
202
|
+
hash ^= text.charCodeAt(index);
|
|
203
|
+
hash = Math.imul(hash, 16777619);
|
|
204
|
+
}
|
|
205
|
+
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
206
|
+
}
|
|
207
|
+
function useTemplateDraftHistory(options) {
|
|
208
|
+
const { template, maxDrafts, enabled, debounceMs, store: storeOverride } = options;
|
|
209
|
+
const inheritedStore = useTemplateStorage().history;
|
|
210
|
+
const store = storeOverride ?? inheritedStore;
|
|
211
|
+
const [lastCapturedAt, setLastCapturedAt] = useState(null);
|
|
212
|
+
const savedHashRef = useRef(null);
|
|
213
|
+
const baselineTemplateIdRef = useRef(null);
|
|
214
|
+
const timerRef = useRef(null);
|
|
215
|
+
const clearTimer = () => {
|
|
216
|
+
if (timerRef.current !== null) {
|
|
217
|
+
window.clearTimeout(timerRef.current);
|
|
218
|
+
timerRef.current = null;
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
useEffect(() => {
|
|
222
|
+
const templateId = template.id.trim();
|
|
223
|
+
const active = enabled !== false && !!templateId;
|
|
224
|
+
if (!active) {
|
|
225
|
+
clearTimer();
|
|
226
|
+
baselineTemplateIdRef.current = null;
|
|
227
|
+
savedHashRef.current = null;
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
if (baselineTemplateIdRef.current !== templateId) {
|
|
231
|
+
clearTimer();
|
|
232
|
+
baselineTemplateIdRef.current = templateId;
|
|
233
|
+
savedHashRef.current = hashDesignerTemplate(template);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
clearTimer();
|
|
237
|
+
const delay = debounceMs ?? 2e3;
|
|
238
|
+
timerRef.current = window.setTimeout(() => {
|
|
239
|
+
timerRef.current = null;
|
|
240
|
+
const contentHash = hashDesignerTemplate(template);
|
|
241
|
+
if (contentHash === savedHashRef.current) return;
|
|
242
|
+
const entry = {
|
|
243
|
+
id: genId(),
|
|
244
|
+
templateId,
|
|
245
|
+
kind: "draft",
|
|
246
|
+
createdAt: Date.now(),
|
|
247
|
+
designer: structuredClone(template),
|
|
248
|
+
contentHash
|
|
249
|
+
};
|
|
250
|
+
store.appendDraft(entry, maxDrafts).then((saved) => {
|
|
251
|
+
if (baselineTemplateIdRef.current !== templateId) return;
|
|
252
|
+
savedHashRef.current = contentHash;
|
|
253
|
+
if (saved) setLastCapturedAt(saved.createdAt);
|
|
254
|
+
}).catch((error) => {
|
|
255
|
+
console.error("[TemplateHistory] \u81EA\u52A8\u8349\u7A3F\u4FDD\u5B58\u5931\u8D25", error);
|
|
256
|
+
});
|
|
257
|
+
}, delay);
|
|
258
|
+
return clearTimer;
|
|
259
|
+
}, [template, maxDrafts, enabled, debounceMs, store]);
|
|
260
|
+
return { lastCapturedAt };
|
|
261
|
+
}
|
|
262
|
+
var useStyles = createStyles(({ css, token }) => ({
|
|
263
|
+
/** 纸张:流式撑满容器(与编辑器内容同构),随内容自然撑高。 */
|
|
264
|
+
paper: css`
|
|
265
|
+
width: 100%;
|
|
266
|
+
background: ${token.colorBgContainer};
|
|
267
|
+
border: 1px solid ${token.colorBorderSecondary};
|
|
268
|
+
border-radius: ${token.borderRadiusLG}px;
|
|
269
|
+
padding: 24px;
|
|
270
|
+
`
|
|
271
|
+
}));
|
|
272
|
+
function TemplatePreviewEditor(props) {
|
|
273
|
+
const { definition, documentKey, suffix, editorRef, minHeight = 120 } = props;
|
|
274
|
+
const { styles } = useStyles();
|
|
275
|
+
const previewDefinition = useMemo(() => createTemplateDataPreviewDefinition(definition), [definition]);
|
|
276
|
+
const contentSignature = useMemo(() => JSON.stringify(previewDefinition.content), [previewDefinition.content]);
|
|
277
|
+
return /* @__PURE__ */ jsx("div", { className: styles.paper, style: { minHeight }, children: /* @__PURE__ */ jsx(
|
|
278
|
+
RichEditor,
|
|
279
|
+
{
|
|
280
|
+
editable: true,
|
|
281
|
+
documentId: `${documentKey}-${suffix}`,
|
|
282
|
+
toolbar: { visible: false },
|
|
283
|
+
template: { definitions: [previewDefinition], initialTemplateId: previewDefinition.id },
|
|
284
|
+
style: { minHeight },
|
|
285
|
+
ref: editorRef
|
|
286
|
+
},
|
|
287
|
+
`${documentKey}-${suffix}-${previewDefinition.id}-${contentSignature}`
|
|
288
|
+
) });
|
|
289
|
+
}
|
|
290
|
+
function useBlockReorderDrag(options) {
|
|
291
|
+
const { explainReject, relocateBlock } = options;
|
|
292
|
+
const [draggingUid, setDraggingUid] = useState(null);
|
|
293
|
+
const [indicator, setIndicator] = useState(null);
|
|
294
|
+
const dragUidRef = useRef(null);
|
|
295
|
+
const predictCacheRef = useRef(/* @__PURE__ */ new Map());
|
|
296
|
+
const predict = useCallback(
|
|
297
|
+
(uid, anchorUid) => {
|
|
298
|
+
const key = `${uid}\u2192${anchorUid ?? ""}`;
|
|
299
|
+
const cached = predictCacheRef.current.get(key);
|
|
300
|
+
if (cached !== void 0) return cached;
|
|
301
|
+
const reason = explainReject(uid, anchorUid);
|
|
302
|
+
predictCacheRef.current.set(key, reason);
|
|
303
|
+
return reason;
|
|
304
|
+
},
|
|
305
|
+
[explainReject]
|
|
306
|
+
);
|
|
307
|
+
const clearDragState = useCallback(() => {
|
|
308
|
+
dragUidRef.current = null;
|
|
309
|
+
predictCacheRef.current.clear();
|
|
310
|
+
setDraggingUid(null);
|
|
311
|
+
setIndicator(null);
|
|
312
|
+
}, []);
|
|
313
|
+
const getDragSourceProps = useCallback(
|
|
314
|
+
(uid) => ({
|
|
315
|
+
draggable: true,
|
|
316
|
+
onDragStart: (event) => {
|
|
317
|
+
dragUidRef.current = uid;
|
|
318
|
+
predictCacheRef.current.clear();
|
|
319
|
+
setDraggingUid(uid);
|
|
320
|
+
event.dataTransfer.setData("text/plain", uid);
|
|
321
|
+
event.dataTransfer.effectAllowed = "move";
|
|
322
|
+
},
|
|
323
|
+
onDragEnd: () => {
|
|
324
|
+
clearDragState();
|
|
325
|
+
}
|
|
326
|
+
}),
|
|
327
|
+
[clearDragState]
|
|
328
|
+
);
|
|
329
|
+
const getDropTargetProps = useCallback(
|
|
330
|
+
({ targetUid, beforeAnchor, afterAnchor }) => ({
|
|
331
|
+
onDragOver: (event) => {
|
|
332
|
+
const uid = dragUidRef.current;
|
|
333
|
+
if (!uid) return;
|
|
334
|
+
event.preventDefault();
|
|
335
|
+
const rect = event.currentTarget.getBoundingClientRect();
|
|
336
|
+
const upper = event.clientY < rect.top + rect.height / 2;
|
|
337
|
+
const anchorUid = upper ? beforeAnchor : afterAnchor;
|
|
338
|
+
const reason = predict(uid, anchorUid);
|
|
339
|
+
event.dataTransfer.dropEffect = reason === null ? "move" : "none";
|
|
340
|
+
setIndicator(
|
|
341
|
+
(prev) => prev && prev.anchorUid === anchorUid && prev.targetUid === targetUid && prev.forbidden === (reason !== null) && prev.reason === (reason ?? void 0) ? prev : { anchorUid, targetUid, forbidden: reason !== null, reason: reason ?? void 0 }
|
|
342
|
+
);
|
|
343
|
+
},
|
|
344
|
+
onDragLeave: (event) => {
|
|
345
|
+
const related = event.relatedTarget;
|
|
346
|
+
if (related && event.currentTarget.contains(related)) return;
|
|
347
|
+
setIndicator((prev) => prev && prev.targetUid === targetUid ? null : prev);
|
|
348
|
+
},
|
|
349
|
+
onDrop: (event) => {
|
|
350
|
+
event.preventDefault();
|
|
351
|
+
const uid = dragUidRef.current ?? event.dataTransfer.getData("text/plain");
|
|
352
|
+
if (uid) {
|
|
353
|
+
const rect = event.currentTarget.getBoundingClientRect();
|
|
354
|
+
const upper = event.clientY < rect.top + rect.height / 2;
|
|
355
|
+
const anchorUid = upper ? beforeAnchor : afterAnchor;
|
|
356
|
+
relocateBlock(uid, anchorUid);
|
|
357
|
+
}
|
|
358
|
+
clearDragState();
|
|
359
|
+
}
|
|
360
|
+
}),
|
|
361
|
+
[predict, relocateBlock, clearDragState]
|
|
362
|
+
);
|
|
363
|
+
return { draggingUid, indicator, getDragSourceProps, getDropTargetProps };
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// src/editor/features/templatedesigner/utils/outlineModel.ts
|
|
367
|
+
function entryFirstUid(entry) {
|
|
368
|
+
return entry.kind === "single" ? entry.block.uid : entry.blocks[0].uid;
|
|
369
|
+
}
|
|
370
|
+
function splitOutlineSections(blocks) {
|
|
371
|
+
const pinOf = (block) => {
|
|
372
|
+
return isFreeDesignerBlock(block) ? void 0 : block.pin;
|
|
373
|
+
};
|
|
374
|
+
return {
|
|
375
|
+
top: blocks.filter((block) => pinOf(block) === "top"),
|
|
376
|
+
middle: blocks.filter((block) => pinOf(block) !== "top" && pinOf(block) !== "bottom"),
|
|
377
|
+
bottom: blocks.filter((block) => pinOf(block) === "bottom")
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
function buildOutlineEntries(blocks) {
|
|
381
|
+
const entries = [];
|
|
382
|
+
for (const block of blocks) {
|
|
383
|
+
const last = entries[entries.length - 1];
|
|
384
|
+
if (block.groupId) {
|
|
385
|
+
if (last && last.kind === "group" && last.groupId === block.groupId) {
|
|
386
|
+
last.blocks.push(block);
|
|
387
|
+
} else {
|
|
388
|
+
entries.push({
|
|
389
|
+
kind: "group",
|
|
390
|
+
groupId: block.groupId,
|
|
391
|
+
label: groupDisplayLabel(block.groupLabel),
|
|
392
|
+
blocks: [block]
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
} else {
|
|
396
|
+
entries.push({ kind: "single", block });
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return entries;
|
|
400
|
+
}
|
|
401
|
+
function buildAfterAnchorByFirstUid(sections) {
|
|
402
|
+
const all = [...sections.top, ...sections.middle, ...sections.bottom];
|
|
403
|
+
const map = /* @__PURE__ */ new Map();
|
|
404
|
+
all.forEach((entry, index) => {
|
|
405
|
+
map.set(entryFirstUid(entry), index + 1 < all.length ? entryFirstUid(all[index + 1]) : null);
|
|
406
|
+
});
|
|
407
|
+
return map;
|
|
408
|
+
}
|
|
409
|
+
function buildCanvasDragAnchors(blocks) {
|
|
410
|
+
const entries = buildOutlineEntries(blocks);
|
|
411
|
+
const map = /* @__PURE__ */ new Map();
|
|
412
|
+
entries.forEach((entry, index) => {
|
|
413
|
+
const firstUid = entryFirstUid(entry);
|
|
414
|
+
const afterAnchor = index + 1 < entries.length ? entryFirstUid(entries[index + 1]) : null;
|
|
415
|
+
const members = entry.kind === "group" ? entry.blocks : [entry.block];
|
|
416
|
+
members.forEach((block) => {
|
|
417
|
+
map.set(block.uid, { unitUid: firstUid, beforeAnchor: firstUid, afterAnchor });
|
|
418
|
+
});
|
|
419
|
+
});
|
|
420
|
+
return map;
|
|
421
|
+
}
|
|
422
|
+
var BLOCK_VISUALS = {
|
|
423
|
+
heading: { accent: "#2f54eb", softBg: "#2f54eb1a", tagColor: "geekblue", icon: FontSizeOutlined },
|
|
424
|
+
paragraph: { accent: "#1677ff", softBg: "#1677ff1a", tagColor: "blue", icon: AlignLeftOutlined },
|
|
425
|
+
image: { accent: "#722ed1", softBg: "#722ed11a", tagColor: "purple", icon: PictureOutlined },
|
|
426
|
+
table: { accent: "#13c2c2", softBg: "#13c2c21a", tagColor: "cyan", icon: TableOutlined },
|
|
427
|
+
codeBlock: { accent: "#fa8c16", softBg: "#fa8c161a", tagColor: "orange", icon: CodeOutlined }
|
|
428
|
+
};
|
|
429
|
+
var FALLBACK_VISUAL = {
|
|
430
|
+
accent: "#8c8c8c",
|
|
431
|
+
softBg: "#8c8c8c1a",
|
|
432
|
+
tagColor: "default",
|
|
433
|
+
icon: BlockOutlined
|
|
434
|
+
};
|
|
435
|
+
function getBlockVisual(type) {
|
|
436
|
+
return BLOCK_VISUALS[type] ?? FALLBACK_VISUAL;
|
|
437
|
+
}
|
|
438
|
+
function areOutlineRowPropsEqual(prev, next) {
|
|
439
|
+
return prev.block === next.block && prev.active === next.active && prev.indented === next.indented && prev.draggableRow === next.draggableRow && prev.checked === next.checked && prev.onCheckChange === next.onCheckChange && prev.labelOf === next.labelOf && prev.draggingUid === next.draggingUid && prev.indicator === next.indicator && prev.getDragSourceProps === next.getDragSourceProps && prev.structureKey === next.structureKey && prev.beforeAnchor === next.beforeAnchor && prev.afterAnchor === next.afterAnchor && prev.onSelect === next.onSelect && prev.onMove === next.onMove && prev.canMoveUp === next.canMoveUp && prev.canMoveDown === next.canMoveDown;
|
|
440
|
+
}
|
|
441
|
+
function StructureBadges({
|
|
442
|
+
block,
|
|
443
|
+
free,
|
|
444
|
+
labelOf
|
|
445
|
+
}) {
|
|
446
|
+
const { styles } = useBlockOutlineStyles();
|
|
447
|
+
const before = block.before ?? [];
|
|
448
|
+
const after = block.after ?? [];
|
|
449
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
450
|
+
!free && block.pin === "top" && /* @__PURE__ */ jsx(Tag, { color: "purple", className: styles.tag, children: tr("\u7F6E\u9876") }),
|
|
451
|
+
!free && block.pin === "bottom" && /* @__PURE__ */ jsx(Tag, { color: "geekblue", className: styles.tag, children: tr("\u7F6E\u5E95") }),
|
|
452
|
+
before.length > 0 && /* @__PURE__ */ jsx(Tag, { color: "gold", className: styles.tag, title: tr("\u5FC5\u987B\u4F4D\u4E8E\u4E4B\u4E0A\uFF1A${0}", [before.map(labelOf).join("\u3001")]), children: tr("\u5728 ${0} \u5757\u4E4B\u4E0A", [before.length]) }),
|
|
453
|
+
after.length > 0 && /* @__PURE__ */ jsx(Tag, { color: "green", className: styles.tag, title: tr("\u5FC5\u987B\u4F4D\u4E8E\u4E4B\u4E0B\uFF1A${0}", [after.map(labelOf).join("\u3001")]), children: tr("\u5728 ${0} \u5757\u4E4B\u4E0B", [after.length]) })
|
|
454
|
+
] });
|
|
455
|
+
}
|
|
456
|
+
var OutlineRow = memo(function OutlineRow2({
|
|
457
|
+
block,
|
|
458
|
+
active,
|
|
459
|
+
indented,
|
|
460
|
+
draggableRow,
|
|
461
|
+
checked,
|
|
462
|
+
onCheckChange,
|
|
463
|
+
labelOf,
|
|
464
|
+
draggingUid,
|
|
465
|
+
indicator,
|
|
466
|
+
getDragSourceProps,
|
|
467
|
+
getDropTargetProps,
|
|
468
|
+
beforeAnchor,
|
|
469
|
+
afterAnchor,
|
|
470
|
+
onSelect,
|
|
471
|
+
onMove,
|
|
472
|
+
canMoveUp,
|
|
473
|
+
canMoveDown
|
|
474
|
+
}) {
|
|
475
|
+
const { styles, cx } = useBlockOutlineStyles();
|
|
476
|
+
const descriptor = getDesignerBlockDescriptor(block.type);
|
|
477
|
+
const typeLabel = blockTypeMeta(block.type).label;
|
|
478
|
+
const typeColor = getBlockVisual(block.type).tagColor;
|
|
479
|
+
const free = isFreeDesignerBlock(block);
|
|
480
|
+
const summary = descriptor?.getSummary?.(block) ?? block.label;
|
|
481
|
+
const lineHere = !indented && indicator && indicator.anchorUid === block.uid ? indicator : null;
|
|
482
|
+
const forbiddenHere = indicator?.targetUid === block.uid && indicator.forbidden;
|
|
483
|
+
return /* @__PURE__ */ jsxs(
|
|
484
|
+
"div",
|
|
485
|
+
{
|
|
486
|
+
className: cx(
|
|
487
|
+
styles.row,
|
|
488
|
+
active && styles.rowActive,
|
|
489
|
+
indented && styles.rowIndented,
|
|
490
|
+
draggingUid === block.uid && styles.rowDragging,
|
|
491
|
+
forbiddenHere && styles.rowForbidden
|
|
492
|
+
),
|
|
493
|
+
title: forbiddenHere && indicator?.reason ? tr(indicator.reason) : void 0,
|
|
494
|
+
onClick: () => onSelect(block.uid),
|
|
495
|
+
...draggableRow ? getDragSourceProps(block.uid) : {},
|
|
496
|
+
...getDropTargetProps({ targetUid: block.uid, beforeAnchor, afterAnchor }),
|
|
497
|
+
children: [
|
|
498
|
+
lineHere && /* @__PURE__ */ jsx("div", { className: cx(styles.dropLine, lineHere.forbidden && styles.dropLineForbidden) }),
|
|
499
|
+
onCheckChange && /* @__PURE__ */ jsx("span", { className: styles.rowCheck, onClick: (event) => event.stopPropagation(), children: /* @__PURE__ */ jsx(
|
|
500
|
+
Checkbox,
|
|
501
|
+
{
|
|
502
|
+
checked: checked ?? false,
|
|
503
|
+
onChange: (event) => onCheckChange([block.uid], event.target.checked)
|
|
504
|
+
}
|
|
505
|
+
) }),
|
|
506
|
+
/* @__PURE__ */ jsx(Tag, { color: typeColor, className: styles.tag, children: typeLabel }),
|
|
507
|
+
free && /* @__PURE__ */ jsx(Tag, { color: "default", className: styles.tag, children: tr("\u81EA\u7531") }),
|
|
508
|
+
/* @__PURE__ */ jsx(StructureBadges, { block, free, labelOf }),
|
|
509
|
+
/* @__PURE__ */ jsx("span", { className: styles.blockLabel, title: block.label, children: block.label }),
|
|
510
|
+
/* @__PURE__ */ jsx("span", { className: styles.summary, title: summary, children: summary }),
|
|
511
|
+
/* @__PURE__ */ jsxs("span", { className: styles.actions, children: [
|
|
512
|
+
/* @__PURE__ */ jsx(
|
|
513
|
+
Button,
|
|
514
|
+
{
|
|
515
|
+
size: "small",
|
|
516
|
+
type: "text",
|
|
517
|
+
icon: /* @__PURE__ */ jsx(ArrowUpOutlined, {}),
|
|
518
|
+
disabled: !canMoveUp,
|
|
519
|
+
onClick: (event) => {
|
|
520
|
+
event.stopPropagation();
|
|
521
|
+
onMove(block.uid, -1);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
),
|
|
525
|
+
/* @__PURE__ */ jsx(
|
|
526
|
+
Button,
|
|
527
|
+
{
|
|
528
|
+
size: "small",
|
|
529
|
+
type: "text",
|
|
530
|
+
icon: /* @__PURE__ */ jsx(ArrowDownOutlined, {}),
|
|
531
|
+
disabled: !canMoveDown,
|
|
532
|
+
onClick: (event) => {
|
|
533
|
+
event.stopPropagation();
|
|
534
|
+
onMove(block.uid, 1);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
)
|
|
538
|
+
] })
|
|
539
|
+
]
|
|
540
|
+
}
|
|
541
|
+
);
|
|
542
|
+
}, areOutlineRowPropsEqual);
|
|
543
|
+
function areOutlineGroupRowPropsEqual(prev, next) {
|
|
544
|
+
return prev.blocks.length === next.blocks.length && prev.blocks.every((block, index) => block === next.blocks[index]) && prev.label === next.label && prev.activeUid === next.activeUid && prev.selectedUids === next.selectedUids && prev.onCheckChange === next.onCheckChange && prev.labelOf === next.labelOf && prev.beforeAnchor === next.beforeAnchor && prev.afterAnchor === next.afterAnchor && prev.draggingUid === next.draggingUid && prev.indicator === next.indicator && prev.getDragSourceProps === next.getDragSourceProps && prev.structureKey === next.structureKey && prev.onSelect === next.onSelect && prev.onMove === next.onMove && prev.canMoveUp === next.canMoveUp && prev.canMoveDown === next.canMoveDown;
|
|
545
|
+
}
|
|
546
|
+
var OutlineGroupRow = memo(function OutlineGroupRow2({
|
|
547
|
+
blocks,
|
|
548
|
+
label,
|
|
549
|
+
activeUid,
|
|
550
|
+
selectedUids,
|
|
551
|
+
onCheckChange,
|
|
552
|
+
labelOf,
|
|
553
|
+
beforeAnchor,
|
|
554
|
+
afterAnchor,
|
|
555
|
+
draggingUid,
|
|
556
|
+
indicator,
|
|
557
|
+
getDragSourceProps,
|
|
558
|
+
getDropTargetProps,
|
|
559
|
+
structureKey,
|
|
560
|
+
onSelect,
|
|
561
|
+
onMove,
|
|
562
|
+
canMoveUp,
|
|
563
|
+
canMoveDown
|
|
564
|
+
}) {
|
|
565
|
+
const { styles, cx } = useBlockOutlineStyles();
|
|
566
|
+
const firstUid = blocks[0].uid;
|
|
567
|
+
const groupLine = indicator && indicator.anchorUid === firstUid ? indicator : null;
|
|
568
|
+
const memberUids = blocks.map((member) => member.uid);
|
|
569
|
+
const checkedCount = memberUids.filter((uid) => selectedUids.has(uid)).length;
|
|
570
|
+
return (
|
|
571
|
+
// key 用组内首块 uid(由 PinSection 指定):非连续同组块会拆成多个组条目(导入场景),
|
|
572
|
+
// 用 groupId 作 key 会重复触发 React key 冲突/复用错乱。
|
|
573
|
+
/* @__PURE__ */ jsxs(
|
|
574
|
+
"div",
|
|
575
|
+
{
|
|
576
|
+
className: cx(styles.group, blocks.some((member) => member.uid === draggingUid) && styles.groupDragging),
|
|
577
|
+
...getDragSourceProps(firstUid),
|
|
578
|
+
children: [
|
|
579
|
+
groupLine && /* @__PURE__ */ jsx("div", { className: cx(styles.dropLine, groupLine.forbidden && styles.dropLineForbidden) }),
|
|
580
|
+
/* @__PURE__ */ jsxs(
|
|
581
|
+
"div",
|
|
582
|
+
{
|
|
583
|
+
className: cx(
|
|
584
|
+
styles.groupHeader,
|
|
585
|
+
indicator?.targetUid === firstUid && indicator.forbidden && styles.rowForbidden
|
|
586
|
+
),
|
|
587
|
+
title: indicator?.targetUid === firstUid && indicator.forbidden && indicator.reason ? tr(indicator.reason) : void 0,
|
|
588
|
+
...getDropTargetProps({ targetUid: firstUid, beforeAnchor, afterAnchor }),
|
|
589
|
+
children: [
|
|
590
|
+
/* @__PURE__ */ jsx("span", { className: styles.rowCheck, onClick: (event) => event.stopPropagation(), children: /* @__PURE__ */ jsx(
|
|
591
|
+
Checkbox,
|
|
592
|
+
{
|
|
593
|
+
checked: checkedCount === memberUids.length,
|
|
594
|
+
indeterminate: checkedCount > 0 && checkedCount < memberUids.length,
|
|
595
|
+
onChange: (event) => onCheckChange(memberUids, event.target.checked)
|
|
596
|
+
}
|
|
597
|
+
) }),
|
|
598
|
+
label
|
|
599
|
+
]
|
|
600
|
+
}
|
|
601
|
+
),
|
|
602
|
+
/* @__PURE__ */ jsx("div", { className: styles.groupBody, children: blocks.map((member) => /* @__PURE__ */ jsx(
|
|
603
|
+
OutlineRow,
|
|
604
|
+
{
|
|
605
|
+
block: member,
|
|
606
|
+
active: member.uid === activeUid,
|
|
607
|
+
indented: true,
|
|
608
|
+
labelOf,
|
|
609
|
+
draggingUid,
|
|
610
|
+
indicator,
|
|
611
|
+
getDragSourceProps,
|
|
612
|
+
getDropTargetProps,
|
|
613
|
+
structureKey,
|
|
614
|
+
beforeAnchor,
|
|
615
|
+
afterAnchor,
|
|
616
|
+
onSelect,
|
|
617
|
+
onMove,
|
|
618
|
+
canMoveUp,
|
|
619
|
+
canMoveDown
|
|
620
|
+
},
|
|
621
|
+
member.uid
|
|
622
|
+
)) })
|
|
623
|
+
]
|
|
624
|
+
}
|
|
625
|
+
)
|
|
626
|
+
);
|
|
627
|
+
}, areOutlineGroupRowPropsEqual);
|
|
628
|
+
function PinSection({
|
|
629
|
+
label,
|
|
630
|
+
dot,
|
|
631
|
+
entries,
|
|
632
|
+
blockCount,
|
|
633
|
+
emptyHint,
|
|
634
|
+
activeUid,
|
|
635
|
+
selectedUids,
|
|
636
|
+
onCheckChange,
|
|
637
|
+
labelOf,
|
|
638
|
+
afterAnchorOf,
|
|
639
|
+
drag,
|
|
640
|
+
structureKey,
|
|
641
|
+
onSelect,
|
|
642
|
+
onMove,
|
|
643
|
+
moveAvailability
|
|
644
|
+
}) {
|
|
645
|
+
const { styles } = useBlockOutlineStyles();
|
|
646
|
+
return /* @__PURE__ */ jsxs("section", { className: styles.section, children: [
|
|
647
|
+
/* @__PURE__ */ jsxs("div", { className: styles.sectionHeader, children: [
|
|
648
|
+
/* @__PURE__ */ jsx("span", { className: styles.sectionDot, style: { background: dot } }),
|
|
649
|
+
/* @__PURE__ */ jsx("span", { className: styles.sectionTitle, children: label }),
|
|
650
|
+
/* @__PURE__ */ jsx("span", { className: styles.sectionCount, children: blockCount })
|
|
651
|
+
] }),
|
|
652
|
+
entries.length === 0 ? /* @__PURE__ */ jsx("div", { className: styles.emptyHint, children: emptyHint }) : entries.map((entry) => {
|
|
653
|
+
const firstUid = entryFirstUid(entry);
|
|
654
|
+
const afterAnchor = afterAnchorOf(firstUid);
|
|
655
|
+
if (entry.kind === "group") {
|
|
656
|
+
const availability2 = moveAvailability.get(firstUid);
|
|
657
|
+
return /* @__PURE__ */ jsx(
|
|
658
|
+
OutlineGroupRow,
|
|
659
|
+
{
|
|
660
|
+
blocks: entry.blocks,
|
|
661
|
+
label: entry.label,
|
|
662
|
+
activeUid,
|
|
663
|
+
selectedUids,
|
|
664
|
+
onCheckChange,
|
|
665
|
+
labelOf,
|
|
666
|
+
beforeAnchor: firstUid,
|
|
667
|
+
afterAnchor,
|
|
668
|
+
draggingUid: drag.draggingUid,
|
|
669
|
+
indicator: drag.indicator,
|
|
670
|
+
getDragSourceProps: drag.getDragSourceProps,
|
|
671
|
+
getDropTargetProps: drag.getDropTargetProps,
|
|
672
|
+
structureKey,
|
|
673
|
+
onSelect,
|
|
674
|
+
onMove,
|
|
675
|
+
canMoveUp: availability2?.up ?? false,
|
|
676
|
+
canMoveDown: availability2?.down ?? false
|
|
677
|
+
},
|
|
678
|
+
`group-${firstUid}`
|
|
679
|
+
);
|
|
680
|
+
}
|
|
681
|
+
const availability = moveAvailability.get(entry.block.uid);
|
|
682
|
+
return /* @__PURE__ */ jsx(
|
|
683
|
+
OutlineRow,
|
|
684
|
+
{
|
|
685
|
+
block: entry.block,
|
|
686
|
+
active: entry.block.uid === activeUid,
|
|
687
|
+
draggableRow: true,
|
|
688
|
+
checked: selectedUids.has(entry.block.uid),
|
|
689
|
+
onCheckChange,
|
|
690
|
+
labelOf,
|
|
691
|
+
draggingUid: drag.draggingUid,
|
|
692
|
+
indicator: drag.indicator,
|
|
693
|
+
getDragSourceProps: drag.getDragSourceProps,
|
|
694
|
+
getDropTargetProps: drag.getDropTargetProps,
|
|
695
|
+
structureKey,
|
|
696
|
+
beforeAnchor: firstUid,
|
|
697
|
+
afterAnchor,
|
|
698
|
+
onSelect,
|
|
699
|
+
onMove,
|
|
700
|
+
canMoveUp: availability?.up ?? false,
|
|
701
|
+
canMoveDown: availability?.down ?? false
|
|
702
|
+
},
|
|
703
|
+
entry.block.uid
|
|
704
|
+
);
|
|
705
|
+
})
|
|
706
|
+
] });
|
|
707
|
+
}
|
|
708
|
+
function BlockOutline(props) {
|
|
709
|
+
const { blocks, activeUid, onSelect, onMove, moveAvailability, relocateBlock, onGroupSelected, onUngroupSelected } = props;
|
|
710
|
+
const { styles, cx } = useBlockOutlineStyles();
|
|
711
|
+
const explainReject = useCallback(
|
|
712
|
+
(uid, anchorUid) => explainRelocateReject(blocks, uid, anchorUid),
|
|
713
|
+
[blocks]
|
|
714
|
+
);
|
|
715
|
+
const drag = useBlockReorderDrag({ explainReject, relocateBlock });
|
|
716
|
+
const structureKey = useMemo(() => structureSignatureOf(blocks), [blocks]);
|
|
717
|
+
const [selectedUids, setSelectedUids] = useState(() => /* @__PURE__ */ new Set());
|
|
718
|
+
useEffect(() => {
|
|
719
|
+
setSelectedUids((prev) => {
|
|
720
|
+
if (prev.size === 0) return prev;
|
|
721
|
+
const alive = new Set(blocks.map((block) => block.uid));
|
|
722
|
+
const next = new Set([...prev].filter((uid) => alive.has(uid)));
|
|
723
|
+
return next.size === prev.size ? prev : next;
|
|
724
|
+
});
|
|
725
|
+
}, [blocks]);
|
|
726
|
+
const handleCheckChange = useCallback((uids, checked) => {
|
|
727
|
+
setSelectedUids((prev) => {
|
|
728
|
+
const next = new Set(prev);
|
|
729
|
+
uids.forEach((uid) => {
|
|
730
|
+
if (checked) next.add(uid);
|
|
731
|
+
else next.delete(uid);
|
|
732
|
+
});
|
|
733
|
+
return next;
|
|
734
|
+
});
|
|
735
|
+
}, []);
|
|
736
|
+
const selectedList = useMemo(() => blocks.filter((block) => selectedUids.has(block.uid)), [blocks, selectedUids]);
|
|
737
|
+
const groupDisabledReason = useMemo(() => explainGroupSelection(blocks, [...selectedUids]), [blocks, selectedUids]);
|
|
738
|
+
const ungroupDisabledReason = useMemo(
|
|
739
|
+
() => explainUngroupSelection(blocks, [...selectedUids]),
|
|
740
|
+
[blocks, selectedUids]
|
|
741
|
+
);
|
|
742
|
+
const handleGroupSelected = () => {
|
|
743
|
+
if (onGroupSelected([...selectedUids])) setSelectedUids(/* @__PURE__ */ new Set());
|
|
744
|
+
};
|
|
745
|
+
const handleUngroupSelected = () => {
|
|
746
|
+
if (onUngroupSelected([...selectedUids])) setSelectedUids(/* @__PURE__ */ new Set());
|
|
747
|
+
};
|
|
748
|
+
const sections = useMemo(() => splitOutlineSections(blocks), [blocks]);
|
|
749
|
+
const sectionEntries = useMemo(
|
|
750
|
+
() => ({
|
|
751
|
+
top: buildOutlineEntries(sections.top),
|
|
752
|
+
middle: buildOutlineEntries(sections.middle),
|
|
753
|
+
bottom: buildOutlineEntries(sections.bottom)
|
|
754
|
+
}),
|
|
755
|
+
[sections]
|
|
756
|
+
);
|
|
757
|
+
const afterAnchorByFirstUid = useMemo(() => buildAfterAnchorByFirstUid(sectionEntries), [sectionEntries]);
|
|
758
|
+
const afterAnchorOf = (firstUid) => afterAnchorByFirstUid.get(firstUid) ?? null;
|
|
759
|
+
const labelByUid = useMemo(() => new Map(blocks.map((block) => [block.uid, block.label])), [blocks]);
|
|
760
|
+
const labelByUidRef = useRef(labelByUid);
|
|
761
|
+
labelByUidRef.current = labelByUid;
|
|
762
|
+
const labelOf = useCallback((uid) => labelByUidRef.current.get(uid) || uid, []);
|
|
763
|
+
const sectionProps = {
|
|
764
|
+
activeUid,
|
|
765
|
+
selectedUids,
|
|
766
|
+
onCheckChange: handleCheckChange,
|
|
767
|
+
labelOf,
|
|
768
|
+
afterAnchorOf,
|
|
769
|
+
drag,
|
|
770
|
+
structureKey,
|
|
771
|
+
onSelect,
|
|
772
|
+
onMove,
|
|
773
|
+
moveAvailability
|
|
774
|
+
};
|
|
775
|
+
const endLine = drag.indicator && drag.indicator.anchorUid === null ? drag.indicator : null;
|
|
776
|
+
return /* @__PURE__ */ jsxs("div", { className: styles.root, children: [
|
|
777
|
+
selectedList.length > 0 && /* @__PURE__ */ jsxs("div", { className: styles.selectionBar, children: [
|
|
778
|
+
/* @__PURE__ */ jsx("span", { className: styles.selectionInfo, children: tr("\u5DF2\u9009 ${0} \u9879", [selectedList.length]) }),
|
|
779
|
+
/* @__PURE__ */ jsx(
|
|
780
|
+
TooltipButton,
|
|
781
|
+
{
|
|
782
|
+
autoWidth: false,
|
|
783
|
+
size: "small",
|
|
784
|
+
type: "primary",
|
|
785
|
+
disabled: !!groupDisabledReason,
|
|
786
|
+
onClick: handleGroupSelected,
|
|
787
|
+
title: groupDisabledReason ? tr(groupDisabledReason) : void 0,
|
|
788
|
+
children: tr("\u7EC4\u5408 (${0})", [selectedList.length])
|
|
789
|
+
}
|
|
790
|
+
),
|
|
791
|
+
/* @__PURE__ */ jsx(
|
|
792
|
+
TooltipButton,
|
|
793
|
+
{
|
|
794
|
+
autoWidth: false,
|
|
795
|
+
size: "small",
|
|
796
|
+
disabled: !!ungroupDisabledReason,
|
|
797
|
+
onClick: handleUngroupSelected,
|
|
798
|
+
title: ungroupDisabledReason ? tr(ungroupDisabledReason) : void 0,
|
|
799
|
+
children: tr("\u53D6\u6D88\u7EC4\u5408")
|
|
800
|
+
}
|
|
801
|
+
),
|
|
802
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "text", onClick: () => setSelectedUids(/* @__PURE__ */ new Set()), children: tr("\u6E05\u9664") })
|
|
803
|
+
] }),
|
|
804
|
+
sectionEntries.top.length > 0 && /* @__PURE__ */ jsx(
|
|
805
|
+
PinSection,
|
|
806
|
+
{
|
|
807
|
+
label: tr("\u7F6E\u9876"),
|
|
808
|
+
dot: "#722ed1",
|
|
809
|
+
entries: sectionEntries.top,
|
|
810
|
+
blockCount: sections.top.length,
|
|
811
|
+
...sectionProps
|
|
812
|
+
}
|
|
813
|
+
),
|
|
814
|
+
/* @__PURE__ */ jsx(
|
|
815
|
+
PinSection,
|
|
816
|
+
{
|
|
817
|
+
label: tr("\u4E2D\u95F4"),
|
|
818
|
+
dot: "#1677ff",
|
|
819
|
+
entries: sectionEntries.middle,
|
|
820
|
+
blockCount: sections.middle.length,
|
|
821
|
+
emptyHint: tr("\u4E2D\u95F4\u533A\u53EF\u81EA\u7531\u63D2\u5165\u5185\u5BB9"),
|
|
822
|
+
...sectionProps
|
|
823
|
+
}
|
|
824
|
+
),
|
|
825
|
+
sectionEntries.bottom.length > 0 && /* @__PURE__ */ jsx(
|
|
826
|
+
PinSection,
|
|
827
|
+
{
|
|
828
|
+
label: tr("\u7F6E\u5E95"),
|
|
829
|
+
dot: "#2f54eb",
|
|
830
|
+
entries: sectionEntries.bottom,
|
|
831
|
+
blockCount: sections.bottom.length,
|
|
832
|
+
...sectionProps
|
|
833
|
+
}
|
|
834
|
+
),
|
|
835
|
+
endLine && /* @__PURE__ */ jsx("div", { className: cx(styles.endLine, endLine.forbidden && styles.endLineForbidden) })
|
|
836
|
+
] });
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
// src/editor/features/templatedesigner/history/utils/entryDefinition.ts
|
|
840
|
+
var SUMMARY_MAX_LENGTH = 50;
|
|
841
|
+
function resolveEntryDefinition(entry) {
|
|
842
|
+
const built = buildDefinition(entry.designer);
|
|
843
|
+
return built.ok ? built.definition : null;
|
|
844
|
+
}
|
|
845
|
+
function summarizeEntry(definition) {
|
|
846
|
+
if (!definition) return "";
|
|
847
|
+
const text = extractDesignerNodeText(definition.content).trim();
|
|
848
|
+
if (!text) return "\uFF08\u65E0\u6587\u672C\u5185\u5BB9\uFF09";
|
|
849
|
+
return text.length > SUMMARY_MAX_LENGTH ? `${text.slice(0, SUMMARY_MAX_LENGTH)}\u2026` : text;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
// src/editor/features/templatedesigner/history/utils/format.ts
|
|
853
|
+
function formatTime(timestamp) {
|
|
854
|
+
const pad = (value) => String(value).padStart(2, "0");
|
|
855
|
+
const date = new Date(timestamp);
|
|
856
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
// src/editor/features/templatedesigner/history/styles.ts
|
|
860
|
+
var useStyles2 = createStyles(({ css, token, glassEffect }) => ({
|
|
861
|
+
toolbar: css`
|
|
862
|
+
display: flex;
|
|
863
|
+
align-items: center;
|
|
864
|
+
justify-content: space-between;
|
|
865
|
+
gap: 12px;
|
|
866
|
+
padding-bottom: 12px;
|
|
867
|
+
border-bottom: 1px solid ${token.colorBorderSecondary};
|
|
868
|
+
`,
|
|
869
|
+
toolbarLeft: css`
|
|
870
|
+
display: flex;
|
|
871
|
+
align-items: center;
|
|
872
|
+
gap: 8px;
|
|
873
|
+
font-size: 13px;
|
|
874
|
+
color: ${token.colorText};
|
|
875
|
+
/* 右栏 300px 下空间有限,标签(CJK 可任意断行)不许换行,完整让宽度过 */
|
|
876
|
+
white-space: nowrap;
|
|
877
|
+
`,
|
|
878
|
+
section: css`
|
|
879
|
+
display: flex;
|
|
880
|
+
flex-direction: column;
|
|
881
|
+
gap: 8px;
|
|
882
|
+
`,
|
|
883
|
+
sectionTitle: css`
|
|
884
|
+
margin: 0;
|
|
885
|
+
font-size: 13px;
|
|
886
|
+
font-weight: 600;
|
|
887
|
+
color: ${token.colorText};
|
|
888
|
+
`,
|
|
889
|
+
entry: css`
|
|
890
|
+
display: flex;
|
|
891
|
+
flex-direction: column;
|
|
892
|
+
gap: 4px;
|
|
893
|
+
padding: 10px 12px;
|
|
894
|
+
/* 历史条目卡片按框架容器规则适配:毛玻璃态半透明底 + 玻璃边框 + 卡片圆角,
|
|
895
|
+
传统态变量回落为不透明容器色 / none,故边框补传统态分支保持原视觉 */
|
|
896
|
+
border: ${glassEffect ? "var(--glass-border)" : `1px solid ${token.colorBorderSecondary}`};
|
|
897
|
+
border-radius: var(--borderRadiusCard);
|
|
898
|
+
background: var(--colorBgAlphaColorContainer);
|
|
899
|
+
`,
|
|
900
|
+
entryHeader: css`
|
|
901
|
+
display: flex;
|
|
902
|
+
align-items: center;
|
|
903
|
+
flex-wrap: wrap;
|
|
904
|
+
gap: 4px 8px;
|
|
905
|
+
`,
|
|
906
|
+
entryTime: css`
|
|
907
|
+
font-size: 12px;
|
|
908
|
+
color: ${token.colorTextTertiary};
|
|
909
|
+
font-variant-numeric: tabular-nums;
|
|
910
|
+
/* 时间串不在「-」「:」处断行;放不下时随 entryHeader 整体换行 */
|
|
911
|
+
white-space: nowrap;
|
|
912
|
+
`,
|
|
913
|
+
entryActions: css`
|
|
914
|
+
display: flex;
|
|
915
|
+
gap: 4px;
|
|
916
|
+
margin-left: auto;
|
|
917
|
+
`,
|
|
918
|
+
entryTitle: css`
|
|
919
|
+
font-size: 13px;
|
|
920
|
+
color: ${token.colorText};
|
|
921
|
+
`,
|
|
922
|
+
entryLabel: css`
|
|
923
|
+
font-size: 12px;
|
|
924
|
+
color: ${token.colorTextSecondary};
|
|
925
|
+
`,
|
|
926
|
+
entrySummary: css`
|
|
927
|
+
font-size: 12px;
|
|
928
|
+
color: ${token.colorTextTertiary};
|
|
929
|
+
overflow: hidden;
|
|
930
|
+
text-overflow: ellipsis;
|
|
931
|
+
white-space: nowrap;
|
|
932
|
+
`,
|
|
933
|
+
entryBroken: css`
|
|
934
|
+
font-size: 12px;
|
|
935
|
+
color: ${token.colorError};
|
|
936
|
+
`,
|
|
937
|
+
emptySection: css`
|
|
938
|
+
font-size: 12px;
|
|
939
|
+
color: ${token.colorTextTertiary};
|
|
940
|
+
padding: 4px 0 8px;
|
|
941
|
+
`,
|
|
942
|
+
loading: css`
|
|
943
|
+
display: flex;
|
|
944
|
+
align-items: center;
|
|
945
|
+
justify-content: center;
|
|
946
|
+
padding: 48px 0;
|
|
947
|
+
`,
|
|
948
|
+
listEmpty: css`
|
|
949
|
+
padding-top: 24px;
|
|
950
|
+
`,
|
|
951
|
+
list: css`
|
|
952
|
+
display: flex;
|
|
953
|
+
flex-direction: column;
|
|
954
|
+
gap: 12px;
|
|
955
|
+
padding-top: 12px;
|
|
956
|
+
`,
|
|
957
|
+
previewScroll: css`
|
|
958
|
+
max-height: 68vh;
|
|
959
|
+
overflow: auto;
|
|
960
|
+
padding: 16px;
|
|
961
|
+
background: ${token.colorBgLayout};
|
|
962
|
+
`,
|
|
963
|
+
previewPage: css`
|
|
964
|
+
width: 100%;
|
|
965
|
+
display: flex;
|
|
966
|
+
flex-direction: column;
|
|
967
|
+
padding: 24px;
|
|
968
|
+
background: ${token.colorBgContainer};
|
|
969
|
+
box-shadow: ${token.boxShadowTertiary};
|
|
970
|
+
min-height: 500px;
|
|
971
|
+
`,
|
|
972
|
+
brokenTip: css`
|
|
973
|
+
padding: 24px 0;
|
|
974
|
+
text-align: center;
|
|
975
|
+
font-size: 13px;
|
|
976
|
+
color: ${token.colorTextTertiary};
|
|
977
|
+
`
|
|
978
|
+
}));
|
|
979
|
+
function HistoryEntryItem({ entry, onView, onRestore, onRemove }) {
|
|
980
|
+
const { styles } = useStyles2();
|
|
981
|
+
const definition = useMemo(() => resolveEntryDefinition(entry), [entry]);
|
|
982
|
+
return /* @__PURE__ */ jsxs("div", { className: styles.entry, children: [
|
|
983
|
+
/* @__PURE__ */ jsxs("div", { className: styles.entryHeader, children: [
|
|
984
|
+
/* @__PURE__ */ jsx("span", { className: styles.entryTime, children: formatTime(entry.createdAt) }),
|
|
985
|
+
entry.kind === "pinned" ? /* @__PURE__ */ jsx(Tag, { color: "gold", children: tr("\u56FA\u5B9A") }) : /* @__PURE__ */ jsx(Tag, { children: tr("\u8349\u7A3F") }),
|
|
986
|
+
/* @__PURE__ */ jsxs("div", { className: styles.entryActions, children: [
|
|
987
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "text", onClick: () => onView(entry), children: tr("\u67E5\u770B") }),
|
|
988
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "text", onClick: () => onRestore(entry), children: tr("\u6062\u590D") }),
|
|
989
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "text", danger: true, onClick: () => onRemove(entry), children: tr("\u5220\u9664") })
|
|
990
|
+
] })
|
|
991
|
+
] }),
|
|
992
|
+
/* @__PURE__ */ jsxs("div", { className: styles.entryTitle, children: [
|
|
993
|
+
entry.designer.name,
|
|
994
|
+
" \xB7 v",
|
|
995
|
+
entry.designer.version
|
|
996
|
+
] }),
|
|
997
|
+
entry.label ? /* @__PURE__ */ jsx("div", { className: styles.entryLabel, children: tr("\u5907\u6CE8\uFF1A${0}", [entry.label]) }) : null,
|
|
998
|
+
definition ? /* @__PURE__ */ jsx("div", { className: styles.entrySummary, children: summarizeEntry(definition) }) : /* @__PURE__ */ jsx("div", { className: styles.entryBroken, children: tr("\u7F16\u8BD1\u5B58\u5728\u95EE\u9898") })
|
|
999
|
+
] });
|
|
1000
|
+
}
|
|
1001
|
+
function HistoryPreviewModal({ viewing, onClose }) {
|
|
1002
|
+
const { styles } = useStyles2();
|
|
1003
|
+
const definition = useMemo(() => viewing ? resolveEntryDefinition(viewing) : null, [viewing]);
|
|
1004
|
+
return /* @__PURE__ */ jsx(
|
|
1005
|
+
Modal,
|
|
1006
|
+
{
|
|
1007
|
+
width: 720,
|
|
1008
|
+
title: tr("\u67E5\u770B\u7248\u672C \xB7 ${0}", [viewing ? formatTime(viewing.createdAt) : ""]),
|
|
1009
|
+
open: !!viewing,
|
|
1010
|
+
onCancel: onClose,
|
|
1011
|
+
footer: false,
|
|
1012
|
+
children: viewing && definition ? /* @__PURE__ */ jsx("div", { className: styles.previewScroll, children: /* @__PURE__ */ jsx("div", { className: styles.previewPage, children: /* @__PURE__ */ jsx(
|
|
1013
|
+
RichEditor,
|
|
1014
|
+
{
|
|
1015
|
+
editable: true,
|
|
1016
|
+
documentId: `history-view-${viewing.id}`,
|
|
1017
|
+
toolbar: { visible: false },
|
|
1018
|
+
template: {
|
|
1019
|
+
definitions: [definition],
|
|
1020
|
+
initialTemplateId: definition.id
|
|
1021
|
+
},
|
|
1022
|
+
style: { flex: 1, minHeight: 400 }
|
|
1023
|
+
},
|
|
1024
|
+
`history-view-${viewing.id}-${viewing.contentHash}`
|
|
1025
|
+
) }) }) : /* @__PURE__ */ jsx("div", { className: styles.brokenTip, children: tr("\u8BE5\u7248\u672C\u5185\u5BB9\u5B58\u5728\u6821\u9A8C\u95EE\u9898\uFF0C\u65E0\u6CD5\u6E32\u67D3\u9884\u89C8\uFF0C\u53EF\u6062\u590D\u540E\u4FEE\u6B63") })
|
|
1026
|
+
}
|
|
1027
|
+
);
|
|
1028
|
+
}
|
|
1029
|
+
function TemplateHistoryPanel(props) {
|
|
1030
|
+
const { templateId, templateName, maxDrafts, onMaxDraftsChange, onRestore } = props;
|
|
1031
|
+
const { styles } = useStyles2();
|
|
1032
|
+
const store = useTemplateStorage().history;
|
|
1033
|
+
const [entries, setEntries] = useState(null);
|
|
1034
|
+
const [viewing, setViewing] = useState(null);
|
|
1035
|
+
const refreshIdRef = useRef(0);
|
|
1036
|
+
const refresh = useCallback(async () => {
|
|
1037
|
+
const myId = refreshIdRef.current + 1;
|
|
1038
|
+
refreshIdRef.current = myId;
|
|
1039
|
+
try {
|
|
1040
|
+
const list = await store.listEntries(templateId);
|
|
1041
|
+
if (myId !== refreshIdRef.current) return;
|
|
1042
|
+
setEntries(list);
|
|
1043
|
+
} catch (error) {
|
|
1044
|
+
console.error("[TemplateHistory] \u52A0\u8F7D\u5386\u53F2\u7248\u672C\u5931\u8D25", error);
|
|
1045
|
+
if (myId !== refreshIdRef.current) return;
|
|
1046
|
+
setEntries([]);
|
|
1047
|
+
showMessage(tr("\u5386\u53F2\u7248\u672C\u52A0\u8F7D\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5"), { type: "error" });
|
|
1048
|
+
}
|
|
1049
|
+
}, [store, templateId]);
|
|
1050
|
+
useEffect(() => {
|
|
1051
|
+
setEntries(null);
|
|
1052
|
+
void refresh();
|
|
1053
|
+
}, [templateId, refresh]);
|
|
1054
|
+
const pinnedEntries = useMemo(() => (entries ?? []).filter((entry) => entry.kind === "pinned"), [entries]);
|
|
1055
|
+
const draftEntries = useMemo(() => (entries ?? []).filter((entry) => entry.kind === "draft"), [entries]);
|
|
1056
|
+
const handleClearDrafts = () => {
|
|
1057
|
+
showConfirmModal({
|
|
1058
|
+
title: tr("\u6E05\u7A7A\u8349\u7A3F"),
|
|
1059
|
+
content: tr("\u786E\u5B9A\u6E05\u7A7A\u6A21\u677F\u300C${0}\u300D\u7684\u5168\u90E8\u8349\u7A3F\u7248\u672C\uFF1F\u56FA\u5B9A\u7248\u672C\u4E0D\u53D7\u5F71\u54CD\uFF0C\u6B64\u64CD\u4F5C\u4E0D\u53EF\u64A4\u9500\u3002", [templateName]),
|
|
1060
|
+
type: "warning",
|
|
1061
|
+
okType: "danger",
|
|
1062
|
+
okButtonProps: { danger: true },
|
|
1063
|
+
okText: tr("\u6E05\u7A7A"),
|
|
1064
|
+
cancelText: tr("\u53D6\u6D88"),
|
|
1065
|
+
onOk: async () => {
|
|
1066
|
+
try {
|
|
1067
|
+
await store.clearDrafts(templateId);
|
|
1068
|
+
await refresh();
|
|
1069
|
+
} catch (error) {
|
|
1070
|
+
console.error("[TemplateHistory] \u6E05\u7A7A\u8349\u7A3F\u5931\u8D25", error);
|
|
1071
|
+
showMessage(tr("\u6E05\u7A7A\u8349\u7A3F\u5931\u8D25"), { type: "error" });
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
});
|
|
1075
|
+
};
|
|
1076
|
+
const handleRestore = (entry) => {
|
|
1077
|
+
showConfirmModal({
|
|
1078
|
+
title: tr("\u6062\u590D\u7248\u672C"),
|
|
1079
|
+
content: tr("\u5C06\u7528\u8BE5\u7248\u672C\u5185\u5BB9\u66FF\u6362\u5F53\u524D\u7F16\u8F91\u4E2D\u7684\u8349\u7A3F\uFF0C\u5F53\u524D\u672A\u4FDD\u5B58\u4FEE\u6539\u5C06\u4E22\u5931\uFF0C\u7EE7\u7EED\uFF1F"),
|
|
1080
|
+
okText: tr("\u6062\u590D"),
|
|
1081
|
+
cancelText: tr("\u53D6\u6D88"),
|
|
1082
|
+
onOk: () => {
|
|
1083
|
+
onRestore(entry);
|
|
1084
|
+
setViewing(null);
|
|
1085
|
+
}
|
|
1086
|
+
});
|
|
1087
|
+
};
|
|
1088
|
+
const handleRemove = (entry) => {
|
|
1089
|
+
showConfirmModal({
|
|
1090
|
+
title: tr("\u5220\u9664\u7248\u672C"),
|
|
1091
|
+
content: tr("\u786E\u5B9A\u5220\u9664\u8BE5${0}\u7248\u672C\uFF08${1}\uFF09\uFF1F\u6B64\u64CD\u4F5C\u4E0D\u53EF\u64A4\u9500\u3002", [
|
|
1092
|
+
entry.kind === "pinned" ? tr("\u56FA\u5B9A") : tr("\u8349\u7A3F"),
|
|
1093
|
+
formatTime(entry.createdAt)
|
|
1094
|
+
]),
|
|
1095
|
+
type: "warning",
|
|
1096
|
+
okType: "danger",
|
|
1097
|
+
okButtonProps: { danger: true },
|
|
1098
|
+
okText: tr("\u5220\u9664"),
|
|
1099
|
+
cancelText: tr("\u53D6\u6D88"),
|
|
1100
|
+
onOk: async () => {
|
|
1101
|
+
try {
|
|
1102
|
+
await store.removeEntry(entry.id);
|
|
1103
|
+
await refresh();
|
|
1104
|
+
} catch (error) {
|
|
1105
|
+
console.error("[TemplateHistory] \u5220\u9664\u5386\u53F2\u7248\u672C\u5931\u8D25", error);
|
|
1106
|
+
showMessage(tr("\u5220\u9664\u5386\u53F2\u7248\u672C\u5931\u8D25"), { type: "error" });
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
});
|
|
1110
|
+
};
|
|
1111
|
+
const handleMaxDraftsChange = (value) => {
|
|
1112
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
1113
|
+
onMaxDraftsChange(value);
|
|
1114
|
+
}
|
|
1115
|
+
};
|
|
1116
|
+
const renderSection = (title, list) => /* @__PURE__ */ jsxs("div", { className: styles.section, children: [
|
|
1117
|
+
/* @__PURE__ */ jsx("div", { className: styles.sectionTitle, children: title }),
|
|
1118
|
+
list.length === 0 ? /* @__PURE__ */ jsx("div", { className: styles.emptySection, children: tr("\u6682\u65E0") }) : list.map((entry) => /* @__PURE__ */ jsx(
|
|
1119
|
+
HistoryEntryItem,
|
|
1120
|
+
{
|
|
1121
|
+
entry,
|
|
1122
|
+
onView: setViewing,
|
|
1123
|
+
onRestore: handleRestore,
|
|
1124
|
+
onRemove: handleRemove
|
|
1125
|
+
},
|
|
1126
|
+
entry.id
|
|
1127
|
+
))
|
|
1128
|
+
] });
|
|
1129
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
1130
|
+
/* @__PURE__ */ jsxs("div", { className: styles.toolbar, children: [
|
|
1131
|
+
/* @__PURE__ */ jsxs("div", { className: styles.toolbarLeft, children: [
|
|
1132
|
+
tr("\u8349\u7A3F\u4E0A\u9650"),
|
|
1133
|
+
/* @__PURE__ */ jsx(
|
|
1134
|
+
InputNumber,
|
|
1135
|
+
{
|
|
1136
|
+
size: "small",
|
|
1137
|
+
min: 5,
|
|
1138
|
+
max: 100,
|
|
1139
|
+
value: maxDrafts,
|
|
1140
|
+
onChange: handleMaxDraftsChange,
|
|
1141
|
+
style: { width: 80 }
|
|
1142
|
+
}
|
|
1143
|
+
)
|
|
1144
|
+
] }),
|
|
1145
|
+
/* @__PURE__ */ jsx(Button, { size: "small", danger: true, onClick: handleClearDrafts, children: tr("\u6E05\u7A7A\u8349\u7A3F") })
|
|
1146
|
+
] }),
|
|
1147
|
+
entries === null ? /* @__PURE__ */ jsx("div", { className: styles.loading, children: /* @__PURE__ */ jsx(Spin, {}) }) : entries.length === 0 ? /* @__PURE__ */ jsx("div", { className: styles.listEmpty, children: /* @__PURE__ */ jsx(CustomEmpty, { emptyText: tr("\u6682\u65E0\u5386\u53F2\u7248\u672C") }) }) : /* @__PURE__ */ jsxs("div", { className: styles.list, children: [
|
|
1148
|
+
renderSection(tr("\u56FA\u5B9A\u7248\u672C"), pinnedEntries),
|
|
1149
|
+
renderSection(tr("\u8349\u7A3F\u7248\u672C"), draftEntries)
|
|
1150
|
+
] }),
|
|
1151
|
+
/* @__PURE__ */ jsx(HistoryPreviewModal, { viewing, onClose: () => setViewing(null) })
|
|
1152
|
+
] });
|
|
1153
|
+
}
|
|
1154
|
+
function useTableJsonImport(onCreate) {
|
|
1155
|
+
const [tableJsonOpen, setTableJsonOpen] = useState(false);
|
|
1156
|
+
const [tableJsonText, setTableJsonText] = useState("");
|
|
1157
|
+
const [tableJsonError, setTableJsonError] = useState(null);
|
|
1158
|
+
const openTableJsonImport = useCallback(() => {
|
|
1159
|
+
setTableJsonOpen(true);
|
|
1160
|
+
}, []);
|
|
1161
|
+
const closeTableJsonImport = useCallback(() => {
|
|
1162
|
+
setTableJsonOpen(false);
|
|
1163
|
+
setTableJsonError(null);
|
|
1164
|
+
}, []);
|
|
1165
|
+
const handleImportTableJson = useCallback(() => {
|
|
1166
|
+
const result = parseTableJson(tableJsonText);
|
|
1167
|
+
if (!result.ok) {
|
|
1168
|
+
setTableJsonError(result.message);
|
|
1169
|
+
return;
|
|
1170
|
+
}
|
|
1171
|
+
const block = createBlockFromPalette(result.block);
|
|
1172
|
+
onCreate(block);
|
|
1173
|
+
setTableJsonOpen(false);
|
|
1174
|
+
setTableJsonText("");
|
|
1175
|
+
setTableJsonError(null);
|
|
1176
|
+
showMessage(
|
|
1177
|
+
result.warnings.length > 0 ? tr("\u5DF2\u521B\u5EFA${0}\u8868\u683C\u5757\uFF1B${1} \u5904\u975E\u6CD5\u5185\u5BB9\u88AB\u81EA\u52A8\u4FEE\u6B63\uFF08\u8BE6\u60C5\u89C1\u63A7\u5236\u53F0\uFF09", [
|
|
1178
|
+
result.variant === "data" ? tr("\u6570\u636E") : tr("\u56FA\u5B9A"),
|
|
1179
|
+
result.warnings.length
|
|
1180
|
+
]) : tr("\u5DF2\u521B\u5EFA${0}\u8868\u683C\u5757", [result.variant === "data" ? tr("\u6570\u636E") : tr("\u56FA\u5B9A")]),
|
|
1181
|
+
{ type: result.warnings.length > 0 ? "info" : "success" }
|
|
1182
|
+
);
|
|
1183
|
+
if (result.warnings.length > 0) {
|
|
1184
|
+
console.info("[TemplateDesigner] \u8868\u683C JSON \u5BFC\u5165\u4FEE\u6B63\u9879\uFF1A\n- " + result.warnings.join("\n- "));
|
|
1185
|
+
}
|
|
1186
|
+
}, [tableJsonText, onCreate]);
|
|
1187
|
+
return {
|
|
1188
|
+
open: tableJsonOpen,
|
|
1189
|
+
text: tableJsonText,
|
|
1190
|
+
error: tableJsonError,
|
|
1191
|
+
setText: setTableJsonText,
|
|
1192
|
+
openModal: openTableJsonImport,
|
|
1193
|
+
handleOk: handleImportTableJson,
|
|
1194
|
+
closeModal: closeTableJsonImport
|
|
1195
|
+
};
|
|
1196
|
+
}
|
|
1197
|
+
function warnStructureIssues(blocks) {
|
|
1198
|
+
const issues = validateBlockStructure(blocks);
|
|
1199
|
+
if (issues.length > 0) {
|
|
1200
|
+
showMessage(tr("\u6A21\u677F\u7ED3\u6784\u5B58\u5728\u95EE\u9898\uFF1A${0}\uFF08\u4FDD\u5B58/\u5BFC\u51FA\u524D\u8BF7\u5728\u7ED3\u6784\u5927\u7EB2\u4E2D\u4FEE\u6B63\uFF09", [issues[0].message]), {
|
|
1201
|
+
type: "warning"
|
|
1202
|
+
});
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
function useTemplatePersistence({
|
|
1206
|
+
current,
|
|
1207
|
+
setCurrent,
|
|
1208
|
+
setActiveUid,
|
|
1209
|
+
storage,
|
|
1210
|
+
savedTemplateIdRef,
|
|
1211
|
+
reloadLibrary,
|
|
1212
|
+
setSaving
|
|
1213
|
+
}) {
|
|
1214
|
+
const [maxDrafts, setMaxDrafts] = useState(DEFAULT_MAX_DRAFTS);
|
|
1215
|
+
useEffect(() => {
|
|
1216
|
+
let cancelled = false;
|
|
1217
|
+
const templateId = current.id.trim();
|
|
1218
|
+
if (!templateId) return;
|
|
1219
|
+
storage.history.getConfig(templateId).then((config) => {
|
|
1220
|
+
if (!cancelled) setMaxDrafts(config.maxDrafts);
|
|
1221
|
+
}).catch(() => {
|
|
1222
|
+
});
|
|
1223
|
+
return () => {
|
|
1224
|
+
cancelled = true;
|
|
1225
|
+
};
|
|
1226
|
+
}, [current.id, storage]);
|
|
1227
|
+
useTemplateDraftHistory({ template: current, maxDrafts, enabled: !!current.id.trim() });
|
|
1228
|
+
const handleNew = useCallback(() => {
|
|
1229
|
+
setCurrent(emptyTemplate());
|
|
1230
|
+
setActiveUid(void 0);
|
|
1231
|
+
savedTemplateIdRef.current = null;
|
|
1232
|
+
}, []);
|
|
1233
|
+
const handleLoad = useCallback((item) => {
|
|
1234
|
+
const designer = normalizeDesignerTemplate(structuredClone(item.designer));
|
|
1235
|
+
setCurrent(designer);
|
|
1236
|
+
setActiveUid(void 0);
|
|
1237
|
+
savedTemplateIdRef.current = item.id;
|
|
1238
|
+
warnStructureIssues(designer.blocks);
|
|
1239
|
+
}, []);
|
|
1240
|
+
const handleSave = useCallback(async () => {
|
|
1241
|
+
const result = buildDefinition(current);
|
|
1242
|
+
if (!result.ok) {
|
|
1243
|
+
showMessage(tr(result.issues[0]?.message ?? "\u6A21\u677F\u6821\u9A8C\u5931\u8D25"), { type: "warning" });
|
|
1244
|
+
return;
|
|
1245
|
+
}
|
|
1246
|
+
setSaving(true);
|
|
1247
|
+
try {
|
|
1248
|
+
const previousTemplateId = savedTemplateIdRef.current;
|
|
1249
|
+
await storage.templates.save({
|
|
1250
|
+
id: result.definition.id,
|
|
1251
|
+
name: result.definition.name,
|
|
1252
|
+
description: result.definition.description,
|
|
1253
|
+
version: result.definition.version,
|
|
1254
|
+
updatedAt: Date.now(),
|
|
1255
|
+
// 落库的设计器快照 ID 收敛为 trim 后的落库值,与库记录本体/编译产物同口径,
|
|
1256
|
+
// 否则 ID 带空白时回读编辑会拿到未 trim 的旧 ID(库高亮/历史检测错位)。
|
|
1257
|
+
designer: { ...current, id: result.definition.id },
|
|
1258
|
+
definition: result.definition
|
|
1259
|
+
});
|
|
1260
|
+
setCurrent((prev) => prev.id.trim() === result.definition.id ? prev : { ...prev, id: result.definition.id });
|
|
1261
|
+
if (previousTemplateId && previousTemplateId !== result.definition.id) {
|
|
1262
|
+
storage.history.deleteAllForTemplate(previousTemplateId).catch((e) => {
|
|
1263
|
+
console.error("[TemplateDesigner] \u65E7 ID \u5386\u53F2\u7EA7\u8054\u6E05\u7406\u5931\u8D25:", e);
|
|
1264
|
+
});
|
|
1265
|
+
}
|
|
1266
|
+
savedTemplateIdRef.current = result.definition.id;
|
|
1267
|
+
await reloadLibrary();
|
|
1268
|
+
showMessage(tr("\u6A21\u677F\u5DF2\u4FDD\u5B58"), { type: "success" });
|
|
1269
|
+
const savedDesigner = { ...current, id: result.definition.id };
|
|
1270
|
+
storage.history.addPinned({
|
|
1271
|
+
// genId 在非安全上下文(内网 http)下自动兜底,crypto.randomUUID 会直接抛 TypeError。
|
|
1272
|
+
id: genId(),
|
|
1273
|
+
templateId: result.definition.id,
|
|
1274
|
+
kind: "pinned",
|
|
1275
|
+
createdAt: Date.now(),
|
|
1276
|
+
designer: structuredClone(savedDesigner),
|
|
1277
|
+
contentHash: hashDesignerTemplate(savedDesigner)
|
|
1278
|
+
}).catch((e) => {
|
|
1279
|
+
console.error("[TemplateDesigner] \u56FA\u5B9A\u7248\u672C\u8BB0\u5F55\u5931\u8D25:", e);
|
|
1280
|
+
});
|
|
1281
|
+
} catch (e) {
|
|
1282
|
+
console.error("[TemplateDesigner] \u4FDD\u5B58\u5931\u8D25:", e);
|
|
1283
|
+
showMessage(tr("\u6A21\u677F\u4FDD\u5B58\u5931\u8D25\uFF1A${0}", [e.message]), { type: "error" });
|
|
1284
|
+
} finally {
|
|
1285
|
+
setSaving(false);
|
|
1286
|
+
}
|
|
1287
|
+
}, [current, storage, reloadLibrary]);
|
|
1288
|
+
const handleExport = useCallback(
|
|
1289
|
+
(format) => {
|
|
1290
|
+
const result = exportTemplate(current, format);
|
|
1291
|
+
if (!result.ok) {
|
|
1292
|
+
showMessage(tr(result.message ?? "\u5BFC\u51FA\u5931\u8D25"), { type: "warning" });
|
|
1293
|
+
return;
|
|
1294
|
+
}
|
|
1295
|
+
const label = format === "json" ? tr("\u6A21\u677F JSON") : format === "markdown" ? "Markdown" : "HTML";
|
|
1296
|
+
showMessage(tr("\u5DF2\u5BFC\u51FA${0}", [label]), { type: "success" });
|
|
1297
|
+
},
|
|
1298
|
+
[current]
|
|
1299
|
+
);
|
|
1300
|
+
const handleImportFile = useCallback(async (file) => {
|
|
1301
|
+
const result = await importTemplateFile(file);
|
|
1302
|
+
if (!result.ok) {
|
|
1303
|
+
showMessage(tr(result.message), { type: "warning" });
|
|
1304
|
+
return;
|
|
1305
|
+
}
|
|
1306
|
+
const designer = normalizeDesignerTemplate(structuredClone(result.designer));
|
|
1307
|
+
const structureIssues = validateBlockStructure(designer.blocks);
|
|
1308
|
+
if (structureIssues.length > 0) {
|
|
1309
|
+
showMessage(tr(structureIssues[0].message), { type: "error" });
|
|
1310
|
+
return;
|
|
1311
|
+
}
|
|
1312
|
+
setCurrent(designer);
|
|
1313
|
+
setActiveUid(void 0);
|
|
1314
|
+
savedTemplateIdRef.current = designer.id.trim();
|
|
1315
|
+
result.warnings.slice(0, 3).forEach((warning) => {
|
|
1316
|
+
showMessage(tr(warning), { type: "warning" });
|
|
1317
|
+
});
|
|
1318
|
+
if (result.warnings.length > 3) {
|
|
1319
|
+
showMessage(tr("\u5BFC\u5165\u544A\u8B66\u5171 ${0} \u6761\uFF0C\u4EE5\u4E0A\u4EC5\u5C55\u793A\u524D 3 \u6761", [result.warnings.length]), { type: "warning" });
|
|
1320
|
+
}
|
|
1321
|
+
const tips = [];
|
|
1322
|
+
if (result.format !== "json") {
|
|
1323
|
+
tips.push(tr("MD/HTML \u5BFC\u5165\u7684\u5757\u5747\u4E3A\u56FA\u5B9A\u6587\u5B57\uFF0C\u69FD\u4F4D/\u7ED3\u6784\u9700\u91CD\u65B0\u8BBE\u7F6E"));
|
|
1324
|
+
}
|
|
1325
|
+
if (result.skipped > 0) {
|
|
1326
|
+
tips.push(tr("${0} \u4E2A\u5757\u7C7B\u578B\u8BBE\u8BA1\u5668\u4E0D\u652F\u6301\uFF0C\u5DF2\u8DF3\u8FC7", [result.skipped]));
|
|
1327
|
+
}
|
|
1328
|
+
showMessage(
|
|
1329
|
+
tr("\u5DF2\u5BFC\u5165\u300C${0}\u300D${1}", [designer.name, tips.length > 0 ? `\uFF1A${tips.join("\uFF1B")}` : tr("\uFF0C\u53EF\u7EE7\u7EED\u7F16\u8F91")]),
|
|
1330
|
+
{
|
|
1331
|
+
type: tips.length > 0 ? "info" : "success"
|
|
1332
|
+
}
|
|
1333
|
+
);
|
|
1334
|
+
}, []);
|
|
1335
|
+
const handleRestoreHistory = useCallback((entry) => {
|
|
1336
|
+
const designer = normalizeDesignerTemplate(structuredClone(entry.designer));
|
|
1337
|
+
setCurrent(designer);
|
|
1338
|
+
setActiveUid(void 0);
|
|
1339
|
+
showMessage(
|
|
1340
|
+
tr("\u5DF2\u6062\u590D ${0} \u7684${1}\u7248\u672C\u5230\u5F53\u524D\u8349\u7A3F", [
|
|
1341
|
+
formatTime(entry.createdAt),
|
|
1342
|
+
entry.kind === "pinned" ? tr("\u56FA\u5B9A") : tr("\u8349\u7A3F")
|
|
1343
|
+
]),
|
|
1344
|
+
{
|
|
1345
|
+
type: "success"
|
|
1346
|
+
}
|
|
1347
|
+
);
|
|
1348
|
+
warnStructureIssues(designer.blocks);
|
|
1349
|
+
}, []);
|
|
1350
|
+
const handleMaxDraftsChange = useCallback(
|
|
1351
|
+
(value) => {
|
|
1352
|
+
setMaxDrafts(value);
|
|
1353
|
+
if (current.id.trim()) {
|
|
1354
|
+
storage.history.saveConfig(current.id.trim(), { maxDrafts: value }).catch(() => {
|
|
1355
|
+
});
|
|
1356
|
+
}
|
|
1357
|
+
},
|
|
1358
|
+
[current.id, storage]
|
|
1359
|
+
);
|
|
1360
|
+
return {
|
|
1361
|
+
maxDrafts,
|
|
1362
|
+
handleMaxDraftsChange,
|
|
1363
|
+
handleNew,
|
|
1364
|
+
handleLoad,
|
|
1365
|
+
handleSave,
|
|
1366
|
+
handleExport,
|
|
1367
|
+
handleImportFile,
|
|
1368
|
+
handleRestoreHistory
|
|
1369
|
+
};
|
|
1370
|
+
}
|
|
1371
|
+
function nextGroupNaming(blocks) {
|
|
1372
|
+
const seenGroupIds = /* @__PURE__ */ new Set();
|
|
1373
|
+
let maxNumber = 0;
|
|
1374
|
+
let parsedAny = false;
|
|
1375
|
+
blocks.forEach((block) => {
|
|
1376
|
+
if (!block.groupId || seenGroupIds.has(block.groupId)) return;
|
|
1377
|
+
seenGroupIds.add(block.groupId);
|
|
1378
|
+
const match = /^组件组(\d+)$/.exec(block.groupLabel?.trim() ?? "");
|
|
1379
|
+
if (match) {
|
|
1380
|
+
parsedAny = true;
|
|
1381
|
+
maxNumber = Math.max(maxNumber, Number.parseInt(match[1], 10));
|
|
1382
|
+
}
|
|
1383
|
+
});
|
|
1384
|
+
const nextNumber = parsedAny ? maxNumber + 1 : seenGroupIds.size + 1;
|
|
1385
|
+
return { groupId: `grp-${genId()}`, groupLabel: `\u7EC4\u4EF6\u7EC4${nextNumber}` };
|
|
1386
|
+
}
|
|
1387
|
+
function useBlockStructureOps({
|
|
1388
|
+
blocks,
|
|
1389
|
+
setCurrent,
|
|
1390
|
+
setActiveUid,
|
|
1391
|
+
setInspectorTab
|
|
1392
|
+
}) {
|
|
1393
|
+
const blocksRef = useRef(blocks);
|
|
1394
|
+
useEffect(() => {
|
|
1395
|
+
blocksRef.current = blocks;
|
|
1396
|
+
});
|
|
1397
|
+
const patchBlock = useCallback((uid, patch) => {
|
|
1398
|
+
setCurrent((prev) => ({
|
|
1399
|
+
...prev,
|
|
1400
|
+
blocks: prev.blocks.map((b) => b.uid === uid ? { ...b, ...patch } : b)
|
|
1401
|
+
}));
|
|
1402
|
+
}, []);
|
|
1403
|
+
const switchBlockFree = useCallback((uid, patch) => {
|
|
1404
|
+
setCurrent((prev) => {
|
|
1405
|
+
const blocks2 = applyFreeSwitch(prev.blocks, uid, patch);
|
|
1406
|
+
return blocks2 === null ? prev : { ...prev, blocks: blocks2 };
|
|
1407
|
+
});
|
|
1408
|
+
}, []);
|
|
1409
|
+
const insertBlock = useCallback((block) => {
|
|
1410
|
+
setCurrent((prev) => {
|
|
1411
|
+
const insertAt = insertionIndexForNewBlock(prev.blocks);
|
|
1412
|
+
const blocks2 = prev.blocks.slice();
|
|
1413
|
+
blocks2.splice(insertAt, 0, block);
|
|
1414
|
+
return { ...prev, blocks: blocks2 };
|
|
1415
|
+
});
|
|
1416
|
+
setActiveUid(block.uid);
|
|
1417
|
+
setInspectorTab("properties");
|
|
1418
|
+
}, []);
|
|
1419
|
+
const addFromPalette = useCallback(
|
|
1420
|
+
(item) => insertBlock({ ...item.create(), uid: nextDesignerUid() }),
|
|
1421
|
+
[insertBlock]
|
|
1422
|
+
);
|
|
1423
|
+
const removeBlock = useCallback((uid) => {
|
|
1424
|
+
setCurrent((prev) => ({ ...prev, blocks: prev.blocks.filter((b) => b.uid !== uid) }));
|
|
1425
|
+
setActiveUid((prev) => prev === uid ? void 0 : prev);
|
|
1426
|
+
}, []);
|
|
1427
|
+
const moveBlock = useCallback((uid, dir) => {
|
|
1428
|
+
setCurrent((prev) => {
|
|
1429
|
+
const next = tryMoveBlocks(prev.blocks, uid, dir);
|
|
1430
|
+
return next ? { ...prev, blocks: next } : prev;
|
|
1431
|
+
});
|
|
1432
|
+
}, []);
|
|
1433
|
+
const moveAvailability = useMemo(() => {
|
|
1434
|
+
const map = /* @__PURE__ */ new Map();
|
|
1435
|
+
blocks.forEach((block) => {
|
|
1436
|
+
map.set(block.uid, {
|
|
1437
|
+
up: tryMoveBlocks(blocks, block.uid, -1) !== null,
|
|
1438
|
+
down: tryMoveBlocks(blocks, block.uid, 1) !== null
|
|
1439
|
+
});
|
|
1440
|
+
});
|
|
1441
|
+
return map;
|
|
1442
|
+
}, [blocks]);
|
|
1443
|
+
const relocateBlock = useCallback((uid, anchorUid) => {
|
|
1444
|
+
const blocks2 = blocksRef.current;
|
|
1445
|
+
const next = relocateUnitBefore(blocks2, uid, anchorUid);
|
|
1446
|
+
if (next === null) return false;
|
|
1447
|
+
if (next !== blocks2) {
|
|
1448
|
+
setCurrent((prev) => ({ ...prev, blocks: next }));
|
|
1449
|
+
}
|
|
1450
|
+
return true;
|
|
1451
|
+
}, []);
|
|
1452
|
+
const applyBlockPin = useCallback((uid, pin) => {
|
|
1453
|
+
setCurrent((prev) => {
|
|
1454
|
+
const blocks2 = applyPin(prev.blocks, uid, pin);
|
|
1455
|
+
return blocks2 === null ? prev : { ...prev, blocks: blocks2 };
|
|
1456
|
+
});
|
|
1457
|
+
}, []);
|
|
1458
|
+
const setBlockOrderConstraints = useCallback(
|
|
1459
|
+
(uid, constraints) => {
|
|
1460
|
+
const next = setOrderConstraints(blocksRef.current, uid, constraints);
|
|
1461
|
+
if (next === null) return false;
|
|
1462
|
+
setCurrent((prev) => ({ ...prev, blocks: next }));
|
|
1463
|
+
return true;
|
|
1464
|
+
},
|
|
1465
|
+
[]
|
|
1466
|
+
);
|
|
1467
|
+
const setBlockGroup = useCallback((uid, groupId) => {
|
|
1468
|
+
setCurrent((prev) => {
|
|
1469
|
+
if (!groupId) {
|
|
1470
|
+
const blocks3 = leaveGroup(prev.blocks, uid);
|
|
1471
|
+
return blocks3 === null ? prev : { ...prev, blocks: blocks3 };
|
|
1472
|
+
}
|
|
1473
|
+
const existing = prev.blocks.find((item) => item.groupId === groupId);
|
|
1474
|
+
const label = existing?.groupLabel ?? "";
|
|
1475
|
+
const blocks2 = joinGroup(prev.blocks, uid, groupId, label);
|
|
1476
|
+
return blocks2 === null ? prev : { ...prev, blocks: blocks2 };
|
|
1477
|
+
});
|
|
1478
|
+
}, []);
|
|
1479
|
+
const createGroupFor = useCallback((uid) => {
|
|
1480
|
+
setCurrent((prev) => {
|
|
1481
|
+
const { groupId, groupLabel } = nextGroupNaming(prev.blocks);
|
|
1482
|
+
const blocks2 = joinGroup(prev.blocks, uid, groupId, groupLabel);
|
|
1483
|
+
return blocks2 === null ? prev : { ...prev, blocks: blocks2 };
|
|
1484
|
+
});
|
|
1485
|
+
}, []);
|
|
1486
|
+
const groupSelected = useCallback((uids) => {
|
|
1487
|
+
const blocks2 = blocksRef.current;
|
|
1488
|
+
const { groupId, groupLabel } = nextGroupNaming(blocks2);
|
|
1489
|
+
const next = groupSelectedBlocks(blocks2, uids, groupId, groupLabel);
|
|
1490
|
+
if (!next) {
|
|
1491
|
+
showMessage(tr("\u6240\u9009\u5757\u65E0\u6CD5\u7EC4\u5408\uFF1A\u53EF\u80FD\u5B58\u5728\u81EA\u7531\u5757\u6216\u9489\u4F4F/\u987A\u5E8F\u7EA6\u675F\u51B2\u7A81"), { type: "warning" });
|
|
1492
|
+
return false;
|
|
1493
|
+
}
|
|
1494
|
+
setCurrent((prev) => ({ ...prev, blocks: next }));
|
|
1495
|
+
return true;
|
|
1496
|
+
}, []);
|
|
1497
|
+
const ungroupSelected = useCallback((uids) => {
|
|
1498
|
+
const next = ungroupSelectedBlocks(blocksRef.current, uids);
|
|
1499
|
+
if (!next) {
|
|
1500
|
+
showMessage(tr("\u6240\u9009\u5757\u65E0\u6CD5\u53D6\u6D88\u7EC4\u5408\uFF1A\u9700\u6574\u7EC4\u9009\u4E2D\uFF08\u90E8\u5206\u9000\u7EC4\u8BF7\u5728\u5757\u8BBE\u7F6E\u8868\u5355\u4E2D\u5355\u72EC\u9000\u51FA\uFF09"), { type: "warning" });
|
|
1501
|
+
return false;
|
|
1502
|
+
}
|
|
1503
|
+
setCurrent((prev) => ({ ...prev, blocks: next }));
|
|
1504
|
+
return true;
|
|
1505
|
+
}, []);
|
|
1506
|
+
const renameGroupLabel = useCallback((groupId, label) => {
|
|
1507
|
+
setCurrent((prev) => ({ ...prev, blocks: renameGroup(prev.blocks, groupId, label) }));
|
|
1508
|
+
}, []);
|
|
1509
|
+
const groupOptions = useMemo(() => collectGroupOptions(blocks), [blocks]);
|
|
1510
|
+
return {
|
|
1511
|
+
patchBlock,
|
|
1512
|
+
switchBlockFree,
|
|
1513
|
+
insertBlock,
|
|
1514
|
+
addFromPalette,
|
|
1515
|
+
removeBlock,
|
|
1516
|
+
moveBlock,
|
|
1517
|
+
moveAvailability,
|
|
1518
|
+
relocateBlock,
|
|
1519
|
+
applyBlockPin,
|
|
1520
|
+
setBlockOrderConstraints,
|
|
1521
|
+
setBlockGroup,
|
|
1522
|
+
createGroupFor,
|
|
1523
|
+
groupSelected,
|
|
1524
|
+
ungroupSelected,
|
|
1525
|
+
renameGroupLabel,
|
|
1526
|
+
groupOptions
|
|
1527
|
+
};
|
|
1528
|
+
}
|
|
1529
|
+
function useDesignerCopilotContext({
|
|
1530
|
+
current,
|
|
1531
|
+
setCurrent,
|
|
1532
|
+
activeUid,
|
|
1533
|
+
activeCell,
|
|
1534
|
+
patchBlock,
|
|
1535
|
+
insertBlock,
|
|
1536
|
+
removeBlock,
|
|
1537
|
+
selectTableCell,
|
|
1538
|
+
activateBlock
|
|
1539
|
+
}) {
|
|
1540
|
+
const copilotStateRef = useRef({ current, activeUid, activeCell });
|
|
1541
|
+
useLayoutEffect(() => {
|
|
1542
|
+
copilotStateRef.current = { current, activeUid, activeCell };
|
|
1543
|
+
});
|
|
1544
|
+
return useMemo(
|
|
1545
|
+
() => ({
|
|
1546
|
+
stateRef: copilotStateRef,
|
|
1547
|
+
setCurrent,
|
|
1548
|
+
patchBlock,
|
|
1549
|
+
insertBlock,
|
|
1550
|
+
removeBlock,
|
|
1551
|
+
selectTableCell,
|
|
1552
|
+
activateBlock
|
|
1553
|
+
}),
|
|
1554
|
+
[patchBlock, insertBlock, removeBlock, selectTableCell, activateBlock]
|
|
1555
|
+
);
|
|
1556
|
+
}
|
|
1557
|
+
function useDesignerSelection({ blocks }) {
|
|
1558
|
+
const [activeUid, setActiveUid] = useState(void 0);
|
|
1559
|
+
const [activeCell, setActiveCell] = useState(null);
|
|
1560
|
+
const [inspectorTab, setInspectorTab] = useState("properties");
|
|
1561
|
+
const itemRefs = useRef(/* @__PURE__ */ new Map());
|
|
1562
|
+
const itemRefHandlerCache = useRef(/* @__PURE__ */ new Map());
|
|
1563
|
+
const selectedBlock = useMemo(() => blocks.find((block) => block.uid === activeUid), [blocks, activeUid]);
|
|
1564
|
+
const activateBlock = useCallback((uid) => {
|
|
1565
|
+
setActiveUid(uid);
|
|
1566
|
+
if (uid) setInspectorTab("properties");
|
|
1567
|
+
}, []);
|
|
1568
|
+
const selectTableCell = useCallback(
|
|
1569
|
+
(uid, cell) => {
|
|
1570
|
+
setActiveCell((prev) => {
|
|
1571
|
+
if (!cell) return null;
|
|
1572
|
+
if (prev && prev.uid === uid && prev.row === cell.row && prev.cell === cell.cell) {
|
|
1573
|
+
return null;
|
|
1574
|
+
}
|
|
1575
|
+
return { uid, ...cell };
|
|
1576
|
+
});
|
|
1577
|
+
if (cell) activateBlock(uid);
|
|
1578
|
+
},
|
|
1579
|
+
[activateBlock]
|
|
1580
|
+
);
|
|
1581
|
+
const registerItemRef = useCallback((uid) => {
|
|
1582
|
+
const cache = itemRefHandlerCache.current;
|
|
1583
|
+
let handler = cache.get(uid);
|
|
1584
|
+
if (!handler) {
|
|
1585
|
+
handler = (el) => {
|
|
1586
|
+
if (el) itemRefs.current.set(uid, el);
|
|
1587
|
+
else itemRefs.current.delete(uid);
|
|
1588
|
+
};
|
|
1589
|
+
cache.set(uid, handler);
|
|
1590
|
+
}
|
|
1591
|
+
return handler;
|
|
1592
|
+
}, []);
|
|
1593
|
+
const handleOutlineSelect = useCallback(
|
|
1594
|
+
(uid) => {
|
|
1595
|
+
activateBlock(uid);
|
|
1596
|
+
requestAnimationFrame(() => {
|
|
1597
|
+
itemRefs.current.get(uid)?.scrollIntoView({ behavior: "smooth", block: "nearest" });
|
|
1598
|
+
});
|
|
1599
|
+
},
|
|
1600
|
+
[activateBlock]
|
|
1601
|
+
);
|
|
1602
|
+
useEffect(() => {
|
|
1603
|
+
if (activeUid && !blocks.some((block) => block.uid === activeUid)) {
|
|
1604
|
+
setActiveUid(void 0);
|
|
1605
|
+
}
|
|
1606
|
+
if (activeCell && !blocks.some((block) => block.uid === activeCell.uid)) {
|
|
1607
|
+
setActiveCell(null);
|
|
1608
|
+
}
|
|
1609
|
+
}, [blocks, activeUid, activeCell]);
|
|
1610
|
+
return {
|
|
1611
|
+
activeUid,
|
|
1612
|
+
setActiveUid,
|
|
1613
|
+
activeCell,
|
|
1614
|
+
selectedBlock,
|
|
1615
|
+
inspectorTab,
|
|
1616
|
+
setInspectorTab,
|
|
1617
|
+
activateBlock,
|
|
1618
|
+
selectTableCell,
|
|
1619
|
+
handleOutlineSelect,
|
|
1620
|
+
registerItemRef
|
|
1621
|
+
};
|
|
1622
|
+
}
|
|
1623
|
+
function useValidationRehearsal(runValidation) {
|
|
1624
|
+
const [open, setOpen] = useState(false);
|
|
1625
|
+
const [editor, setEditor] = useState(null);
|
|
1626
|
+
const runValidationRef = useRef(runValidation);
|
|
1627
|
+
useEffect(() => {
|
|
1628
|
+
runValidationRef.current = runValidation;
|
|
1629
|
+
});
|
|
1630
|
+
const start = useCallback(() => {
|
|
1631
|
+
setOpen(true);
|
|
1632
|
+
}, []);
|
|
1633
|
+
const close = useCallback(() => {
|
|
1634
|
+
setOpen(false);
|
|
1635
|
+
setEditor(null);
|
|
1636
|
+
}, []);
|
|
1637
|
+
const validateNow = useCallback(() => {
|
|
1638
|
+
if (!editor) return;
|
|
1639
|
+
runValidationRef.current(editor);
|
|
1640
|
+
}, [editor]);
|
|
1641
|
+
return { open, start, close, setEditor, validateNow, editorReady: editor !== null };
|
|
1642
|
+
}
|
|
1643
|
+
|
|
1644
|
+
// src/editor/features/templatedesigner/hooks/useDesignerValidation.ts
|
|
1645
|
+
function useDesignerValidation({ build }) {
|
|
1646
|
+
const runValidation = useCallback(
|
|
1647
|
+
(ref) => {
|
|
1648
|
+
if (!build.ok) return;
|
|
1649
|
+
const result = ref.validateTemplate();
|
|
1650
|
+
if (result.valid) {
|
|
1651
|
+
showMessage(tr("\u6821\u9A8C\u901A\u8FC7\uFF1A\u5F53\u524D\u9884\u89C8\u5185\u5BB9\u6EE1\u8DB3\u5168\u90E8\u5FC5\u586B\u9879"), { type: "success" });
|
|
1652
|
+
return;
|
|
1653
|
+
}
|
|
1654
|
+
const applyIssue = result.issues.find((issue) => issue.errorCode);
|
|
1655
|
+
if (applyIssue) {
|
|
1656
|
+
showMessage(tr(applyIssue.message ?? tr("\u6A21\u677F\u5957\u7528\u5931\u8D25\uFF1A${0}", [applyIssue.label])), {
|
|
1657
|
+
type: "warning"
|
|
1658
|
+
});
|
|
1659
|
+
return;
|
|
1660
|
+
}
|
|
1661
|
+
const requiredCount = countRequiredSlots(build.definition.content);
|
|
1662
|
+
if (requiredCount === 0) {
|
|
1663
|
+
showMessage(tr("\u8BE5\u6A21\u677F\u672A\u5B9A\u4E49\u5FC5\u586B\u69FD\u4F4D\uFF0C\u65E0\u9700\u6821\u9A8C"), { type: "info" });
|
|
1664
|
+
return;
|
|
1665
|
+
}
|
|
1666
|
+
const labels = result.issues.map((issue) => issue.label).join("\u3001");
|
|
1667
|
+
showMessage(
|
|
1668
|
+
labels ? tr("\u5B58\u5728 ${0} \u4E2A\u672A\u586B\u5FC5\u586B\u9879\uFF1A${1}", [result.issues.length, labels]) : tr("\u6821\u9A8C\u672A\u901A\u8FC7\uFF08${0}\uFF09", [result.status]),
|
|
1669
|
+
{
|
|
1670
|
+
type: "warning"
|
|
1671
|
+
}
|
|
1672
|
+
);
|
|
1673
|
+
const first = result.issues[0];
|
|
1674
|
+
if (first?.blockId) ref.focusTemplateBlock(first.blockId);
|
|
1675
|
+
},
|
|
1676
|
+
[build]
|
|
1677
|
+
);
|
|
1678
|
+
const {
|
|
1679
|
+
open: validationOpen,
|
|
1680
|
+
start: startValidation,
|
|
1681
|
+
close: closeValidation,
|
|
1682
|
+
setEditor: setValidationEditor,
|
|
1683
|
+
validateNow,
|
|
1684
|
+
editorReady: validationEditorReady
|
|
1685
|
+
} = useValidationRehearsal(runValidation);
|
|
1686
|
+
const handleValidatePreview = useCallback(() => {
|
|
1687
|
+
if (!build.ok) {
|
|
1688
|
+
showMessage(tr(build.issues[0]?.message ?? "\u6A21\u677F\u5B58\u5728\u95EE\u9898\uFF0C\u65E0\u6CD5\u6821\u9A8C"), { type: "warning" });
|
|
1689
|
+
return;
|
|
1690
|
+
}
|
|
1691
|
+
startValidation();
|
|
1692
|
+
}, [build, startValidation]);
|
|
1693
|
+
return {
|
|
1694
|
+
validationOpen,
|
|
1695
|
+
closeValidation,
|
|
1696
|
+
setValidationEditor,
|
|
1697
|
+
handleValidatePreview,
|
|
1698
|
+
runValidationNow: validateNow,
|
|
1699
|
+
validationEditorReady
|
|
1700
|
+
};
|
|
1701
|
+
}
|
|
1702
|
+
function DesignerTopBar({
|
|
1703
|
+
name,
|
|
1704
|
+
version,
|
|
1705
|
+
blockCount,
|
|
1706
|
+
build,
|
|
1707
|
+
saving,
|
|
1708
|
+
leading,
|
|
1709
|
+
onBack,
|
|
1710
|
+
onRename,
|
|
1711
|
+
onSave,
|
|
1712
|
+
onImportFile,
|
|
1713
|
+
onExport,
|
|
1714
|
+
onValidate,
|
|
1715
|
+
dataPreview,
|
|
1716
|
+
actionsExtra
|
|
1717
|
+
}) {
|
|
1718
|
+
const { styles } = useDesignerTopBarStyles();
|
|
1719
|
+
const [editing, setEditing] = useState(false);
|
|
1720
|
+
const [draft, setDraft] = useState("");
|
|
1721
|
+
const escCancelRef = useRef(false);
|
|
1722
|
+
const importInputRef = useRef(null);
|
|
1723
|
+
const startEditing = () => {
|
|
1724
|
+
escCancelRef.current = false;
|
|
1725
|
+
setDraft(name);
|
|
1726
|
+
setEditing(true);
|
|
1727
|
+
};
|
|
1728
|
+
const commitRename = () => {
|
|
1729
|
+
if (escCancelRef.current) {
|
|
1730
|
+
escCancelRef.current = false;
|
|
1731
|
+
return;
|
|
1732
|
+
}
|
|
1733
|
+
const next = draft.trim();
|
|
1734
|
+
if (next && next !== name) onRename(next);
|
|
1735
|
+
setEditing(false);
|
|
1736
|
+
};
|
|
1737
|
+
const cancelRename = () => {
|
|
1738
|
+
escCancelRef.current = true;
|
|
1739
|
+
setEditing(false);
|
|
1740
|
+
};
|
|
1741
|
+
return /* @__PURE__ */ jsxs("div", { className: styles.topBar, children: [
|
|
1742
|
+
/* @__PURE__ */ jsx("div", { className: styles.topBarLeft, children: leading ?? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1743
|
+
onBack && /* @__PURE__ */ jsx(Button, { type: "text", icon: /* @__PURE__ */ jsx(ArrowLeftOutlined, {}), onClick: onBack, children: tr("\u8FD4\u56DE\u7F16\u8F91\u5668") }),
|
|
1744
|
+
/* @__PURE__ */ jsx("span", { className: styles.topBarTitle, children: tr("\u6A21\u677F\u8BBE\u8BA1\u5668") })
|
|
1745
|
+
] }) }),
|
|
1746
|
+
/* @__PURE__ */ jsxs("div", { className: styles.topBarCenter, children: [
|
|
1747
|
+
editing ? /* @__PURE__ */ jsx(
|
|
1748
|
+
Input,
|
|
1749
|
+
{
|
|
1750
|
+
size: "small",
|
|
1751
|
+
autoFocus: true,
|
|
1752
|
+
allowClear: false,
|
|
1753
|
+
className: styles.nameEditInput,
|
|
1754
|
+
value: draft,
|
|
1755
|
+
placeholder: tr("\u6A21\u677F\u540D\u79F0"),
|
|
1756
|
+
onChange: (v) => setDraft(v),
|
|
1757
|
+
onPressEnter: commitRename,
|
|
1758
|
+
onBlur: commitRename,
|
|
1759
|
+
onKeyDown: (e) => {
|
|
1760
|
+
if (e.key === "Escape") cancelRename();
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1764
|
+
/* @__PURE__ */ jsx("span", { className: styles.nameText, title: name, children: name || tr("\u672A\u547D\u540D\u6A21\u677F") }),
|
|
1765
|
+
/* @__PURE__ */ jsx(Tooltip, { title: tr("\u4FEE\u6539\u6A21\u677F\u540D\u79F0"), children: /* @__PURE__ */ jsx(
|
|
1766
|
+
Button,
|
|
1767
|
+
{
|
|
1768
|
+
type: "text",
|
|
1769
|
+
size: "small",
|
|
1770
|
+
className: styles.renameBtn,
|
|
1771
|
+
icon: /* @__PURE__ */ jsx(EditOutlined, {}),
|
|
1772
|
+
onClick: startEditing
|
|
1773
|
+
}
|
|
1774
|
+
) })
|
|
1775
|
+
] }),
|
|
1776
|
+
/* @__PURE__ */ jsxs("span", { className: styles.topBarMeta, children: [
|
|
1777
|
+
/* @__PURE__ */ jsxs("span", { className: styles.metaPill, children: [
|
|
1778
|
+
"v",
|
|
1779
|
+
version
|
|
1780
|
+
] }),
|
|
1781
|
+
/* @__PURE__ */ jsx("span", { className: styles.metaPill, children: tr("${0} \u5757", [blockCount]) })
|
|
1782
|
+
] })
|
|
1783
|
+
] }),
|
|
1784
|
+
/* @__PURE__ */ jsxs("div", { className: styles.topBarActions, children: [
|
|
1785
|
+
actionsExtra,
|
|
1786
|
+
!build.ok && /* @__PURE__ */ jsx(
|
|
1787
|
+
Popover,
|
|
1788
|
+
{
|
|
1789
|
+
title: tr("\u7F16\u8BD1\u95EE\u9898\uFF08${0}\uFF09", [build.issues.length]),
|
|
1790
|
+
content: /* @__PURE__ */ jsx("ul", { className: styles.issueList, children: build.issues.map((issue, index) => /* @__PURE__ */ jsx("li", { children: tr(issue.message) }, index)) }),
|
|
1791
|
+
children: /* @__PURE__ */ jsxs("span", { className: styles.issueBadge, children: [
|
|
1792
|
+
/* @__PURE__ */ jsx(WarningOutlined, {}),
|
|
1793
|
+
" ",
|
|
1794
|
+
build.issues.length
|
|
1795
|
+
] })
|
|
1796
|
+
}
|
|
1797
|
+
),
|
|
1798
|
+
/* @__PURE__ */ jsx(
|
|
1799
|
+
Button,
|
|
1800
|
+
{
|
|
1801
|
+
size: "small",
|
|
1802
|
+
type: "primary",
|
|
1803
|
+
icon: /* @__PURE__ */ jsx(SaveOutlined, {}),
|
|
1804
|
+
loading: saving,
|
|
1805
|
+
disabled: !build.ok,
|
|
1806
|
+
onClick: onSave,
|
|
1807
|
+
children: tr("\u4FDD\u5B58\u5230\u672C\u5730\u5E93")
|
|
1808
|
+
}
|
|
1809
|
+
),
|
|
1810
|
+
dataPreview,
|
|
1811
|
+
/* @__PURE__ */ jsx(Button, { size: "small", icon: /* @__PURE__ */ jsx(AuditOutlined, {}), disabled: !build.ok, onClick: onValidate, children: tr("\u5FC5\u586B\u6821\u9A8C\u9884\u6F14") }),
|
|
1812
|
+
/* @__PURE__ */ jsx(
|
|
1813
|
+
Button,
|
|
1814
|
+
{
|
|
1815
|
+
size: "small",
|
|
1816
|
+
icon: /* @__PURE__ */ jsx(ImportOutlined, {}),
|
|
1817
|
+
title: tr("\u5BFC\u5165\u6A21\u677F\u6587\u4EF6\uFF08JSON / MD / HTML\uFF0C\u6309\u6269\u5C55\u540D\u8BC6\u522B\uFF09"),
|
|
1818
|
+
onClick: () => importInputRef.current?.click(),
|
|
1819
|
+
children: tr("\u5BFC\u5165\u6A21\u677F")
|
|
1820
|
+
}
|
|
1821
|
+
),
|
|
1822
|
+
/* @__PURE__ */ jsx(
|
|
1823
|
+
"input",
|
|
1824
|
+
{
|
|
1825
|
+
ref: importInputRef,
|
|
1826
|
+
type: "file",
|
|
1827
|
+
accept: ".json,.md,.markdown,.html,.htm",
|
|
1828
|
+
style: { display: "none" },
|
|
1829
|
+
onChange: (e) => {
|
|
1830
|
+
const file = e.target.files?.[0];
|
|
1831
|
+
e.target.value = "";
|
|
1832
|
+
if (file) void onImportFile(file);
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
),
|
|
1836
|
+
/* @__PURE__ */ jsx(
|
|
1837
|
+
Dropdown,
|
|
1838
|
+
{
|
|
1839
|
+
trigger: ["click"],
|
|
1840
|
+
menu: {
|
|
1841
|
+
items: [
|
|
1842
|
+
{ key: "json", label: tr("\u6A21\u677F JSON\uFF08\u65E0\u635F\uFF0C\u53EF\u56DE\u5BFC\uFF09") },
|
|
1843
|
+
{ key: "markdown", label: tr("Markdown\uFF08\u5185\u5BB9\u5FEB\u7167\uFF09") },
|
|
1844
|
+
{ key: "html", label: tr("HTML\uFF08\u5185\u5BB9\u5FEB\u7167\uFF09") }
|
|
1845
|
+
],
|
|
1846
|
+
onClick: ({ key }) => onExport(key)
|
|
1847
|
+
},
|
|
1848
|
+
children: /* @__PURE__ */ jsxs(Button, { size: "small", icon: /* @__PURE__ */ jsx(ExportOutlined, {}), disabled: !build.ok, children: [
|
|
1849
|
+
tr("\u5BFC\u51FA"),
|
|
1850
|
+
" ",
|
|
1851
|
+
/* @__PURE__ */ jsx(DownOutlined, {})
|
|
1852
|
+
] })
|
|
1853
|
+
}
|
|
1854
|
+
)
|
|
1855
|
+
] })
|
|
1856
|
+
] });
|
|
1857
|
+
}
|
|
1858
|
+
function TemplateDataPreview({ build, dataSource }) {
|
|
1859
|
+
const [open, setOpen] = useState(false);
|
|
1860
|
+
const [loading, setLoading] = useState(false);
|
|
1861
|
+
const [result, setResult] = useState(null);
|
|
1862
|
+
const [error, setError] = useState("");
|
|
1863
|
+
const requestIdRef = useRef(0);
|
|
1864
|
+
useEffect(
|
|
1865
|
+
() => () => {
|
|
1866
|
+
requestIdRef.current += 1;
|
|
1867
|
+
},
|
|
1868
|
+
[]
|
|
1869
|
+
);
|
|
1870
|
+
const load = useCallback(async () => {
|
|
1871
|
+
if (!build.ok || !dataSource) return;
|
|
1872
|
+
const requestId = ++requestIdRef.current;
|
|
1873
|
+
setOpen(true);
|
|
1874
|
+
setLoading(true);
|
|
1875
|
+
setResult(null);
|
|
1876
|
+
setError("");
|
|
1877
|
+
try {
|
|
1878
|
+
const resolved = await resolveTemplateDataFromSource(build.definition, [dataSource]);
|
|
1879
|
+
if (requestId !== requestIdRef.current) return;
|
|
1880
|
+
if (resolved.ok) setResult(resolved);
|
|
1881
|
+
else setError(resolved.issues.map((issue) => issue.message).join("\uFF1B"));
|
|
1882
|
+
} catch (cause) {
|
|
1883
|
+
if (requestId === requestIdRef.current) {
|
|
1884
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
1885
|
+
}
|
|
1886
|
+
} finally {
|
|
1887
|
+
if (requestId === requestIdRef.current) setLoading(false);
|
|
1888
|
+
}
|
|
1889
|
+
}, [build, dataSource]);
|
|
1890
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1891
|
+
/* @__PURE__ */ jsx(
|
|
1892
|
+
Button,
|
|
1893
|
+
{
|
|
1894
|
+
size: "small",
|
|
1895
|
+
icon: /* @__PURE__ */ jsx(DatabaseOutlined, {}),
|
|
1896
|
+
disabled: !build.ok || !dataSource,
|
|
1897
|
+
title: dataSource ? tr("\u8C03\u7528\u771F\u5B9E\u63A5\u53E3\u9884\u89C8\u7ED1\u5B9A\u7ED3\u679C") : tr("\u8BF7\u5148\u5728\u6A21\u677F\u57FA\u672C\u4FE1\u606F\u4E2D\u9009\u62E9\u6570\u636E\u6E90"),
|
|
1898
|
+
onClick: () => void load(),
|
|
1899
|
+
children: tr("\u6570\u636E\u9884\u89C8")
|
|
1900
|
+
}
|
|
1901
|
+
),
|
|
1902
|
+
/* @__PURE__ */ jsx(
|
|
1903
|
+
Modal,
|
|
1904
|
+
{
|
|
1905
|
+
title: tr("\u540E\u7AEF\u6570\u636E\u9884\u89C8"),
|
|
1906
|
+
width: "80%",
|
|
1907
|
+
open,
|
|
1908
|
+
destroyOnHidden: true,
|
|
1909
|
+
onCancel: () => setOpen(false),
|
|
1910
|
+
footer: /* @__PURE__ */ jsxs(Space, { children: [
|
|
1911
|
+
/* @__PURE__ */ jsx(Button, { onClick: () => setOpen(false), children: tr("\u5173\u95ED") }),
|
|
1912
|
+
/* @__PURE__ */ jsx(Button, { type: "primary", loading, onClick: () => void load(), children: tr("\u91CD\u65B0\u52A0\u8F7D") })
|
|
1913
|
+
] }),
|
|
1914
|
+
children: loading ? /* @__PURE__ */ jsx(Spin, { tip: tr("\u6B63\u5728\u52A0\u8F7D\u63A5\u53E3\u6570\u636E\u2026") }) : error ? /* @__PURE__ */ jsx(Alert, { type: "error", showIcon: true, message: tr("\u6570\u636E\u52A0\u8F7D\u6216\u89E3\u6790\u5931\u8D25"), description: error }) : result ? /* @__PURE__ */ jsxs(Space, { direction: "vertical", size: "middle", children: [
|
|
1915
|
+
result.issues.length > 0 && /* @__PURE__ */ jsx(
|
|
1916
|
+
Alert,
|
|
1917
|
+
{
|
|
1918
|
+
type: "warning",
|
|
1919
|
+
showIcon: true,
|
|
1920
|
+
message: tr("\u90E8\u5206\u53D8\u91CF\u672A\u63D0\u4F9B\u503C"),
|
|
1921
|
+
description: result.issues.map((issue) => issue.message).join("\uFF1B")
|
|
1922
|
+
}
|
|
1923
|
+
),
|
|
1924
|
+
/* @__PURE__ */ jsx(
|
|
1925
|
+
TemplatePreviewEditor,
|
|
1926
|
+
{
|
|
1927
|
+
definition: result.definition,
|
|
1928
|
+
documentKey: `designer-data-${result.definition.id}`,
|
|
1929
|
+
suffix: "data-preview",
|
|
1930
|
+
minHeight: 400
|
|
1931
|
+
}
|
|
1932
|
+
)
|
|
1933
|
+
] }) : null
|
|
1934
|
+
}
|
|
1935
|
+
)
|
|
1936
|
+
] });
|
|
1937
|
+
}
|
|
1938
|
+
function TemplateLibraryPanel({
|
|
1939
|
+
library,
|
|
1940
|
+
currentId,
|
|
1941
|
+
onLoad,
|
|
1942
|
+
onDelete,
|
|
1943
|
+
onNew
|
|
1944
|
+
}) {
|
|
1945
|
+
const { styles, cx } = useTemplateLibraryPanelStyles();
|
|
1946
|
+
return /* @__PURE__ */ jsxs("div", { className: styles.library, children: [
|
|
1947
|
+
/* @__PURE__ */ jsx(Button, { block: true, type: "primary", size: "small", icon: /* @__PURE__ */ jsx(PlusOutlined, {}), onClick: onNew, children: tr("\u65B0\u5EFA\u6A21\u677F") }),
|
|
1948
|
+
library.length === 0 && /* @__PURE__ */ jsx("div", { className: styles.emptyHint, children: tr("\u6682\u65E0\u6A21\u677F\uFF0C\u8BBE\u8BA1\u540E\u70B9\u51FB\u4FDD\u5B58") }),
|
|
1949
|
+
library.map((item) => /* @__PURE__ */ jsxs(
|
|
1950
|
+
"div",
|
|
1951
|
+
{
|
|
1952
|
+
className: cx(styles.libItem, item.id === currentId && styles.libItemActive),
|
|
1953
|
+
onClick: () => onLoad(item),
|
|
1954
|
+
children: [
|
|
1955
|
+
/* @__PURE__ */ jsx("span", { className: styles.libItemIcon, children: /* @__PURE__ */ jsx(FileTextOutlined, {}) }),
|
|
1956
|
+
/* @__PURE__ */ jsxs("span", { className: styles.libItemText, children: [
|
|
1957
|
+
/* @__PURE__ */ jsx("span", { className: styles.libItemName, title: item.name, children: item.name }),
|
|
1958
|
+
/* @__PURE__ */ jsxs("span", { className: styles.libItemMeta, children: [
|
|
1959
|
+
"v",
|
|
1960
|
+
item.version,
|
|
1961
|
+
" \xB7 ",
|
|
1962
|
+
tr("${0} \u5757", [storedBlockCount(item.designer)])
|
|
1963
|
+
] })
|
|
1964
|
+
] }),
|
|
1965
|
+
/* @__PURE__ */ jsx(
|
|
1966
|
+
Button,
|
|
1967
|
+
{
|
|
1968
|
+
className: cx(styles.libItemDelete, LIB_ITEM_DELETE_CLS),
|
|
1969
|
+
size: "small",
|
|
1970
|
+
type: "text",
|
|
1971
|
+
danger: true,
|
|
1972
|
+
icon: /* @__PURE__ */ jsx(DeleteOutlined, {}),
|
|
1973
|
+
title: tr("\u5220\u9664\u6A21\u677F"),
|
|
1974
|
+
onClick: (e) => {
|
|
1975
|
+
e.stopPropagation();
|
|
1976
|
+
onDelete(item);
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
)
|
|
1980
|
+
]
|
|
1981
|
+
},
|
|
1982
|
+
item.id
|
|
1983
|
+
))
|
|
1984
|
+
] });
|
|
1985
|
+
}
|
|
1986
|
+
function LibrarySidePanel({
|
|
1987
|
+
library,
|
|
1988
|
+
currentId,
|
|
1989
|
+
collapsed,
|
|
1990
|
+
onToggleCollapsed,
|
|
1991
|
+
onLoad,
|
|
1992
|
+
onDelete,
|
|
1993
|
+
onNew
|
|
1994
|
+
}) {
|
|
1995
|
+
const { styles, cx } = useLibrarySidePanelStyles();
|
|
1996
|
+
if (collapsed) {
|
|
1997
|
+
return /* @__PURE__ */ jsx("div", { className: cx(styles.leftPanel, styles.leftPanelCollapsed), children: /* @__PURE__ */ jsxs("div", { className: styles.collapsedBar, children: [
|
|
1998
|
+
/* @__PURE__ */ jsx(Tooltip, { title: tr("\u5C55\u5F00\u6A21\u677F\u5E93"), placement: "right", children: /* @__PURE__ */ jsx(Button, { type: "text", icon: /* @__PURE__ */ jsx(MenuUnfoldOutlined, {}), onClick: onToggleCollapsed }) }),
|
|
1999
|
+
/* @__PURE__ */ jsx(Tooltip, { title: tr("\u65B0\u5EFA\u6A21\u677F"), placement: "right", children: /* @__PURE__ */ jsx(Button, { type: "text", icon: /* @__PURE__ */ jsx(PlusOutlined, {}), onClick: onNew }) }),
|
|
2000
|
+
/* @__PURE__ */ jsx(Tooltip, { title: tr("\u6A21\u677F\u5E93\uFF08${0}\uFF09", [library.length]), placement: "right", children: /* @__PURE__ */ jsx(Button, { type: "text", icon: /* @__PURE__ */ jsx(DatabaseOutlined, {}), onClick: onToggleCollapsed }) })
|
|
2001
|
+
] }) });
|
|
2002
|
+
}
|
|
2003
|
+
return /* @__PURE__ */ jsxs("div", { className: styles.leftPanel, children: [
|
|
2004
|
+
/* @__PURE__ */ jsxs("div", { className: styles.panelHeader, children: [
|
|
2005
|
+
/* @__PURE__ */ jsx(DatabaseOutlined, { className: styles.panelHeaderIcon }),
|
|
2006
|
+
tr("\u6A21\u677F\u5E93"),
|
|
2007
|
+
/* @__PURE__ */ jsx("span", { className: styles.panelHeaderCount, children: library.length }),
|
|
2008
|
+
/* @__PURE__ */ jsx(Tooltip, { title: tr("\u6536\u8D77\u6A21\u677F\u5E93"), children: /* @__PURE__ */ jsx(
|
|
2009
|
+
Button,
|
|
2010
|
+
{
|
|
2011
|
+
type: "text",
|
|
2012
|
+
size: "small",
|
|
2013
|
+
className: styles.collapseBtn,
|
|
2014
|
+
icon: /* @__PURE__ */ jsx(MenuFoldOutlined, {}),
|
|
2015
|
+
onClick: onToggleCollapsed
|
|
2016
|
+
}
|
|
2017
|
+
) })
|
|
2018
|
+
] }),
|
|
2019
|
+
/* @__PURE__ */ jsx("div", { className: styles.panelBody, children: /* @__PURE__ */ jsx(
|
|
2020
|
+
TemplateLibraryPanel,
|
|
2021
|
+
{
|
|
2022
|
+
library,
|
|
2023
|
+
currentId,
|
|
2024
|
+
onLoad,
|
|
2025
|
+
onDelete,
|
|
2026
|
+
onNew
|
|
2027
|
+
}
|
|
2028
|
+
) })
|
|
2029
|
+
] });
|
|
2030
|
+
}
|
|
2031
|
+
var ID_INVALID_MESSAGE = tr("\u4EC5\u652F\u6301\u5B57\u6BCD/\u6570\u5B57\u5F00\u5934\uFF0C\u53EF\u542B . _ - \uFF0C\u4E0D\u652F\u6301\u4E2D\u6587\u4E0E\u7A7A\u683C");
|
|
2032
|
+
function TemplateBasicInfoForm({ template, dataSources, onPatch }) {
|
|
2033
|
+
const { styles } = useTemplateBasicInfoFormStyles();
|
|
2034
|
+
const idInvalid = template.id !== "" && !TEMPLATE_ID_PATTERN.test(template.id);
|
|
2035
|
+
return /* @__PURE__ */ jsxs("div", { className: styles.card, children: [
|
|
2036
|
+
/* @__PURE__ */ jsx("div", { className: styles.cardHeader, children: /* @__PURE__ */ jsx("p", { className: styles.sectionTitle, children: tr("\u57FA\u672C\u4FE1\u606F") }) }),
|
|
2037
|
+
/* @__PURE__ */ jsxs("div", { className: styles.infoGrid, children: [
|
|
2038
|
+
/* @__PURE__ */ jsx(ControlItem, { label: "ID", children: /* @__PURE__ */ jsxs("div", { className: styles.idField, children: [
|
|
2039
|
+
/* @__PURE__ */ jsx(
|
|
2040
|
+
Input,
|
|
2041
|
+
{
|
|
2042
|
+
value: template.id,
|
|
2043
|
+
onChange: (v) => onPatch({ id: v }),
|
|
2044
|
+
placeholder: tr("\u6A21\u677F\u552F\u4E00 ID"),
|
|
2045
|
+
status: idInvalid ? "error" : void 0
|
|
2046
|
+
}
|
|
2047
|
+
),
|
|
2048
|
+
idInvalid && /* @__PURE__ */ jsx("span", { className: styles.idError, children: ID_INVALID_MESSAGE })
|
|
2049
|
+
] }) }),
|
|
2050
|
+
/* @__PURE__ */ jsx(ControlItem, { label: tr("\u7248\u672C"), children: /* @__PURE__ */ jsx(
|
|
2051
|
+
Input,
|
|
2052
|
+
{
|
|
2053
|
+
style: { flex: 1 },
|
|
2054
|
+
value: template.version,
|
|
2055
|
+
onChange: (v) => onPatch({ version: v }),
|
|
2056
|
+
placeholder: "1.0.0"
|
|
2057
|
+
}
|
|
2058
|
+
) }),
|
|
2059
|
+
/* @__PURE__ */ jsx(ControlItem, { label: tr("\u540D\u79F0"), children: /* @__PURE__ */ jsx(
|
|
2060
|
+
Input,
|
|
2061
|
+
{
|
|
2062
|
+
style: { flex: 1 },
|
|
2063
|
+
value: template.name,
|
|
2064
|
+
onChange: (v) => onPatch({ name: v }),
|
|
2065
|
+
placeholder: tr("\u6A21\u677F\u540D\u79F0")
|
|
2066
|
+
}
|
|
2067
|
+
) }),
|
|
2068
|
+
/* @__PURE__ */ jsx(ControlItem, { label: tr("\u63CF\u8FF0"), children: /* @__PURE__ */ jsx(
|
|
2069
|
+
Input,
|
|
2070
|
+
{
|
|
2071
|
+
style: { flex: 1 },
|
|
2072
|
+
value: template.description,
|
|
2073
|
+
onChange: (v) => onPatch({ description: v }),
|
|
2074
|
+
placeholder: tr("\u6A21\u677F\u63CF\u8FF0\uFF08\u53EF\u9009\uFF09")
|
|
2075
|
+
}
|
|
2076
|
+
) }),
|
|
2077
|
+
dataSources.length > 0 && /* @__PURE__ */ jsx(ControlItem, { label: tr("\u6570\u636E\u6E90"), hint: tr("\u4EC5\u4FDD\u5B58\u6570\u636E\u6E90\u6807\u8BC6\uFF1B\u63A5\u53E3\u5730\u5740\u3001\u9274\u6743\u548C\u54CD\u5E94\u4E0D\u5199\u5165\u6A21\u677F"), children: /* @__PURE__ */ jsx(
|
|
2078
|
+
Select2,
|
|
2079
|
+
{
|
|
2080
|
+
size: "small",
|
|
2081
|
+
allowClear: true,
|
|
2082
|
+
value: template.dataSource || void 0,
|
|
2083
|
+
onChange: (value) => onPatch({ dataSource: value || void 0 }),
|
|
2084
|
+
options: dataSources.map((source) => ({ value: source.key, label: source.label })),
|
|
2085
|
+
placeholder: tr("\u4E0D\u7ED1\u5B9A\u6570\u636E\u6E90")
|
|
2086
|
+
}
|
|
2087
|
+
) })
|
|
2088
|
+
] })
|
|
2089
|
+
] });
|
|
2090
|
+
}
|
|
2091
|
+
var TABLE_JSON_IMPORT_KEY = "__table_json_import__";
|
|
2092
|
+
function BlockPaletteToolbar({ onAdd, onOpenTableJsonImport }) {
|
|
2093
|
+
const { styles } = useBlockPaletteToolbarStyles();
|
|
2094
|
+
const paletteEntries = useMemo(() => getDesignerPalette(), []);
|
|
2095
|
+
return /* @__PURE__ */ jsxs("div", { className: styles.toolbar, children: [
|
|
2096
|
+
/* @__PURE__ */ jsx("p", { className: styles.sectionTitle, style: { margin: 0 }, children: tr("\u6DFB\u52A0\u5757") }),
|
|
2097
|
+
/* @__PURE__ */ jsx(Space, { size: 6, wrap: true, children: paletteEntries.map(({ descriptor, items }) => {
|
|
2098
|
+
const visual = getBlockVisual(descriptor.type);
|
|
2099
|
+
const TypeIcon = visual.icon;
|
|
2100
|
+
const icon = /* @__PURE__ */ jsx(TypeIcon, { style: { color: visual.accent } });
|
|
2101
|
+
return items.length === 1 ? /* @__PURE__ */ jsx(
|
|
2102
|
+
Button,
|
|
2103
|
+
{
|
|
2104
|
+
size: "small",
|
|
2105
|
+
type: "dashed",
|
|
2106
|
+
icon,
|
|
2107
|
+
title: tr("\u6DFB\u52A0${0}", [items[0].label]),
|
|
2108
|
+
onClick: () => onAdd(items[0]),
|
|
2109
|
+
children: items[0].label
|
|
2110
|
+
},
|
|
2111
|
+
descriptor.type
|
|
2112
|
+
) : /* @__PURE__ */ jsx(
|
|
2113
|
+
Dropdown,
|
|
2114
|
+
{
|
|
2115
|
+
trigger: ["click"],
|
|
2116
|
+
menu: {
|
|
2117
|
+
className: styles.tableMenu,
|
|
2118
|
+
items: [
|
|
2119
|
+
...items.map((item) => ({ key: item.key, label: item.label })),
|
|
2120
|
+
// 表格物料项追加「从 JSON 导入」入口(AI 生成 / Excel 转换的表格 JSON)
|
|
2121
|
+
...descriptor.type === "table" ? [
|
|
2122
|
+
{ type: "divider" },
|
|
2123
|
+
// Dropdown 菜单挂 body,文案走 tr()。
|
|
2124
|
+
{ key: TABLE_JSON_IMPORT_KEY, label: tr("\u4ECE JSON \u5BFC\u5165\u8868\u683C\u2026") }
|
|
2125
|
+
] : []
|
|
2126
|
+
],
|
|
2127
|
+
onClick: ({ key }) => {
|
|
2128
|
+
if (key === TABLE_JSON_IMPORT_KEY) {
|
|
2129
|
+
onOpenTableJsonImport();
|
|
2130
|
+
return;
|
|
2131
|
+
}
|
|
2132
|
+
const item = items.find((candidate) => candidate.key === key);
|
|
2133
|
+
if (item) onAdd(item);
|
|
2134
|
+
}
|
|
2135
|
+
},
|
|
2136
|
+
children: /* @__PURE__ */ jsxs(Button, { size: "small", type: "dashed", icon, children: [
|
|
2137
|
+
descriptor.label,
|
|
2138
|
+
" ",
|
|
2139
|
+
/* @__PURE__ */ jsx(DownOutlined, {})
|
|
2140
|
+
] })
|
|
2141
|
+
},
|
|
2142
|
+
descriptor.type
|
|
2143
|
+
);
|
|
2144
|
+
}) })
|
|
2145
|
+
] });
|
|
2146
|
+
}
|
|
2147
|
+
function areCanvasBlockItemPropsEqual(prev, next) {
|
|
2148
|
+
return prev.block === next.block && prev.active === next.active && prev.activeCell === next.activeCell && prev.onSelectCell === next.onSelectCell && prev.canMoveUp === next.canMoveUp && prev.canMoveDown === next.canMoveDown && prev.unitUid === next.unitUid && prev.beforeAnchor === next.beforeAnchor && prev.afterAnchor === next.afterAnchor && prev.unitDragging === next.unitDragging && prev.dropSide === next.dropSide && prev.dropForbidden === next.dropForbidden && prev.dropReason === next.dropReason && prev.getDragSourceProps === next.getDragSourceProps && prev.structureKey === next.structureKey && prev.onSelect === next.onSelect && prev.onMove === next.onMove && prev.onRemove === next.onRemove && prev.registerRef === next.registerRef;
|
|
2149
|
+
}
|
|
2150
|
+
function InlineSlotsText({ text }) {
|
|
2151
|
+
const { styles } = useCanvasBlockItemStyles();
|
|
2152
|
+
return /* @__PURE__ */ jsx(Fragment, { children: parseInlineSlots(text, 0).map(
|
|
2153
|
+
(node, index) => node.type === "templateInlineSlot" ? /* @__PURE__ */ jsxs("span", { className: styles.inlineSlot, children: [
|
|
2154
|
+
node.attrs?.required === true && /* @__PURE__ */ jsx("span", { className: styles.inlineSlotStar, children: "*" }),
|
|
2155
|
+
typeof node.attrs?.slotLabel === "string" ? node.attrs.slotLabel : tr("\u586B\u5199")
|
|
2156
|
+
] }, index) : /* @__PURE__ */ jsx("span", { children: node.text }, index)
|
|
2157
|
+
) });
|
|
2158
|
+
}
|
|
2159
|
+
function TablePreview({
|
|
2160
|
+
block,
|
|
2161
|
+
active,
|
|
2162
|
+
activeCell,
|
|
2163
|
+
onSelectCell
|
|
2164
|
+
}) {
|
|
2165
|
+
const { styles } = useCanvasBlockItemStyles();
|
|
2166
|
+
const selected = active === true && activeCell && activeCell.uid === block.uid ? { row: activeCell.row, cell: activeCell.cell } : null;
|
|
2167
|
+
const handleSelectCell = onSelectCell ? (row, cell) => onSelectCell(block.uid, { row, cell }) : void 0;
|
|
2168
|
+
if ((block.tableVariant ?? "data") === "data") {
|
|
2169
|
+
const model2 = block.dataTable;
|
|
2170
|
+
if (!model2 || model2.columns.length === 0) {
|
|
2171
|
+
return /* @__PURE__ */ jsx("div", { className: styles.schematicUnknown, children: tr("\u6570\u636E\u8868\u683C\uFF08\u7A7A\uFF09") });
|
|
2172
|
+
}
|
|
2173
|
+
return /* @__PURE__ */ jsx(DataTableView_default, { model: model2, interactive: !!onSelectCell, selected, onSelectCell: handleSelectCell });
|
|
2174
|
+
}
|
|
2175
|
+
const model = block.formTable;
|
|
2176
|
+
if (!model || model.rows.length === 0) {
|
|
2177
|
+
return /* @__PURE__ */ jsx("div", { className: styles.schematicUnknown, children: tr("\u56FA\u5B9A\u8868\u683C\uFF08\u7A7A\uFF09") });
|
|
2178
|
+
}
|
|
2179
|
+
return /* @__PURE__ */ jsx(FormTableView_default, { model, interactive: !!onSelectCell, selected, onSelectCell: handleSelectCell });
|
|
2180
|
+
}
|
|
2181
|
+
function BlockSchematic({
|
|
2182
|
+
block,
|
|
2183
|
+
active,
|
|
2184
|
+
activeCell,
|
|
2185
|
+
onSelectCell
|
|
2186
|
+
}) {
|
|
2187
|
+
const { styles, cx } = useCanvasBlockItemStyles();
|
|
2188
|
+
const meta = blockTypeMeta(block.type);
|
|
2189
|
+
switch (block.type) {
|
|
2190
|
+
case "heading": {
|
|
2191
|
+
const level = block.headingLevel ?? 2;
|
|
2192
|
+
const className = level === 1 ? styles.schematicH1 : level === 3 ? styles.schematicH3 : styles.schematicH2;
|
|
2193
|
+
const text = block.text || (block.isSlot ? tr("\u8BF7\u586B\u5199${0}", [block.label || "\u6807\u9898"]) : block.label || "\u6807\u9898");
|
|
2194
|
+
return /* @__PURE__ */ jsx("div", { className: cx(className, block.isSlot && styles.schematicSlotEditable), children: block.isSlot ? text : /* @__PURE__ */ jsx(InlineSlotsText, { text }) });
|
|
2195
|
+
}
|
|
2196
|
+
case "paragraph": {
|
|
2197
|
+
const text = block.text || (block.isSlot ? tr("\u8BF7\u586B\u5199${0}", [block.label || "\u5185\u5BB9"]) : "");
|
|
2198
|
+
return /* @__PURE__ */ jsx(
|
|
2199
|
+
"p",
|
|
2200
|
+
{
|
|
2201
|
+
className: cx(
|
|
2202
|
+
styles.schematicParagraph,
|
|
2203
|
+
block.isSlot && styles.schematicSlotEditable,
|
|
2204
|
+
!text && styles.schematicPlaceholder
|
|
2205
|
+
),
|
|
2206
|
+
children: text ? block.isSlot ? text : /* @__PURE__ */ jsx(InlineSlotsText, { text }) : tr("\u6587\u672C\u6BB5\u843D\uFF08\u7A7A\uFF09")
|
|
2207
|
+
}
|
|
2208
|
+
);
|
|
2209
|
+
}
|
|
2210
|
+
case "image":
|
|
2211
|
+
return /* @__PURE__ */ jsxs(
|
|
2212
|
+
"div",
|
|
2213
|
+
{
|
|
2214
|
+
className: styles.schematicImage,
|
|
2215
|
+
style: { width: block.width ?? IMAGE_DEFAULT_WIDTH, height: block.height ?? IMAGE_DEFAULT_HEIGHT },
|
|
2216
|
+
children: [
|
|
2217
|
+
/* @__PURE__ */ jsx(PictureOutlined, { className: styles.schematicImageIcon }),
|
|
2218
|
+
/* @__PURE__ */ jsx("span", { children: tr("\u56FE\u7247\u5360\u4F4D \xB7 ${0} \xD7 ${1} px", [
|
|
2219
|
+
block.width ?? IMAGE_DEFAULT_WIDTH,
|
|
2220
|
+
block.height ?? IMAGE_DEFAULT_HEIGHT
|
|
2221
|
+
]) })
|
|
2222
|
+
]
|
|
2223
|
+
}
|
|
2224
|
+
);
|
|
2225
|
+
case "codeBlock":
|
|
2226
|
+
return /* @__PURE__ */ jsxs("div", { className: styles.schematicCode, children: [
|
|
2227
|
+
/* @__PURE__ */ jsx("div", { className: styles.schematicCodeHeader, children: tr("\u4EE3\u7801\u5757") }),
|
|
2228
|
+
/* @__PURE__ */ jsx("pre", { className: styles.schematicCodePre, children: /* @__PURE__ */ jsx("code", { className: cx(!block.text && styles.schematicPlaceholder), children: block.text || tr("\u4EE3\u7801\u5757\uFF08\u7A7A\uFF09") }) })
|
|
2229
|
+
] });
|
|
2230
|
+
case "table":
|
|
2231
|
+
return /* @__PURE__ */ jsx(TablePreview, { block, active, activeCell, onSelectCell });
|
|
2232
|
+
default: {
|
|
2233
|
+
const descriptor = getDesignerBlockDescriptor(block.type);
|
|
2234
|
+
const summary = descriptor?.getSummary?.(block) ?? block.label;
|
|
2235
|
+
return /* @__PURE__ */ jsxs("div", { className: styles.schematicUnknown, children: [
|
|
2236
|
+
meta.label,
|
|
2237
|
+
summary ? ` \xB7 ${summary}` : ""
|
|
2238
|
+
] });
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
function CanvasBlockItemImpl({
|
|
2243
|
+
block,
|
|
2244
|
+
active,
|
|
2245
|
+
activeCell,
|
|
2246
|
+
onSelectCell,
|
|
2247
|
+
canMoveUp,
|
|
2248
|
+
canMoveDown,
|
|
2249
|
+
unitUid,
|
|
2250
|
+
beforeAnchor,
|
|
2251
|
+
afterAnchor,
|
|
2252
|
+
unitDragging,
|
|
2253
|
+
dropSide,
|
|
2254
|
+
dropForbidden,
|
|
2255
|
+
dropReason,
|
|
2256
|
+
getDragSourceProps,
|
|
2257
|
+
getDropTargetProps,
|
|
2258
|
+
structureKey,
|
|
2259
|
+
onSelect,
|
|
2260
|
+
onMove,
|
|
2261
|
+
onRemove,
|
|
2262
|
+
registerRef
|
|
2263
|
+
}) {
|
|
2264
|
+
const { styles, cx } = useCanvasBlockItemStyles();
|
|
2265
|
+
const meta = blockTypeMeta(block.type);
|
|
2266
|
+
const rootRef = useRef(null);
|
|
2267
|
+
const setRootEl = useCallback(
|
|
2268
|
+
(el) => {
|
|
2269
|
+
rootRef.current = el;
|
|
2270
|
+
registerRef(el);
|
|
2271
|
+
},
|
|
2272
|
+
[registerRef]
|
|
2273
|
+
);
|
|
2274
|
+
const sourceProps = getDragSourceProps(unitUid);
|
|
2275
|
+
return /* @__PURE__ */ jsxs(
|
|
2276
|
+
"div",
|
|
2277
|
+
{
|
|
2278
|
+
ref: setRootEl,
|
|
2279
|
+
"data-active": active ? "true" : void 0,
|
|
2280
|
+
className: cx(
|
|
2281
|
+
styles.canvasItem,
|
|
2282
|
+
active && styles.canvasItemActive,
|
|
2283
|
+
unitDragging && styles.canvasItemDragging,
|
|
2284
|
+
dropForbidden && styles.canvasItemDropForbidden
|
|
2285
|
+
),
|
|
2286
|
+
role: "button",
|
|
2287
|
+
tabIndex: 0,
|
|
2288
|
+
title: dropForbidden && dropReason ? tr(dropReason) : void 0,
|
|
2289
|
+
onClick: (e) => {
|
|
2290
|
+
e.stopPropagation();
|
|
2291
|
+
onSelect(block.uid);
|
|
2292
|
+
},
|
|
2293
|
+
onKeyDown: (e) => {
|
|
2294
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
2295
|
+
e.preventDefault();
|
|
2296
|
+
e.stopPropagation();
|
|
2297
|
+
onSelect(block.uid);
|
|
2298
|
+
}
|
|
2299
|
+
},
|
|
2300
|
+
...getDropTargetProps({ targetUid: block.uid, beforeAnchor, afterAnchor }),
|
|
2301
|
+
children: [
|
|
2302
|
+
dropSide && /* @__PURE__ */ jsx(
|
|
2303
|
+
"div",
|
|
2304
|
+
{
|
|
2305
|
+
className: cx(
|
|
2306
|
+
dropSide === "top" ? styles.dropLineTop : styles.dropLineBottom,
|
|
2307
|
+
dropForbidden && styles.dropLineForbidden
|
|
2308
|
+
)
|
|
2309
|
+
}
|
|
2310
|
+
),
|
|
2311
|
+
/* @__PURE__ */ jsx(
|
|
2312
|
+
"span",
|
|
2313
|
+
{
|
|
2314
|
+
"data-drag-handle": "true",
|
|
2315
|
+
className: styles.dragHandle,
|
|
2316
|
+
title: tr("\u62D6\u62FD\u8C03\u6574\u4F4D\u7F6E"),
|
|
2317
|
+
...sourceProps,
|
|
2318
|
+
onDragStart: (event) => {
|
|
2319
|
+
sourceProps.onDragStart(event);
|
|
2320
|
+
const root = rootRef.current;
|
|
2321
|
+
if (root) {
|
|
2322
|
+
event.dataTransfer.setDragImage(root, 0, Math.round(root.getBoundingClientRect().height / 2));
|
|
2323
|
+
}
|
|
2324
|
+
},
|
|
2325
|
+
children: /* @__PURE__ */ jsx(HolderOutlined, {})
|
|
2326
|
+
}
|
|
2327
|
+
),
|
|
2328
|
+
active && /* @__PURE__ */ jsxs("div", { className: styles.canvasItemToolbar, onClick: (e) => e.stopPropagation(), children: [
|
|
2329
|
+
/* @__PURE__ */ jsx("span", { className: styles.toolbarLabel, children: meta.label }),
|
|
2330
|
+
/* @__PURE__ */ jsx(Tooltip, { title: tr("\u4E0A\u79FB"), children: /* @__PURE__ */ jsx(
|
|
2331
|
+
"span",
|
|
2332
|
+
{
|
|
2333
|
+
role: "button",
|
|
2334
|
+
className: cx(styles.toolbarBtn, !canMoveUp && styles.toolbarBtnDisabled),
|
|
2335
|
+
onClick: () => {
|
|
2336
|
+
if (canMoveUp) onMove(block.uid, -1);
|
|
2337
|
+
},
|
|
2338
|
+
children: /* @__PURE__ */ jsx(ArrowUpOutlined, {})
|
|
2339
|
+
}
|
|
2340
|
+
) }),
|
|
2341
|
+
/* @__PURE__ */ jsx(Tooltip, { title: tr("\u4E0B\u79FB"), children: /* @__PURE__ */ jsx(
|
|
2342
|
+
"span",
|
|
2343
|
+
{
|
|
2344
|
+
role: "button",
|
|
2345
|
+
className: cx(styles.toolbarBtn, !canMoveDown && styles.toolbarBtnDisabled),
|
|
2346
|
+
onClick: () => {
|
|
2347
|
+
if (canMoveDown) onMove(block.uid, 1);
|
|
2348
|
+
},
|
|
2349
|
+
children: /* @__PURE__ */ jsx(ArrowDownOutlined, {})
|
|
2350
|
+
}
|
|
2351
|
+
) }),
|
|
2352
|
+
/* @__PURE__ */ jsx(Tooltip, { title: tr("\u5220\u9664\u8BE5\u5757"), children: /* @__PURE__ */ jsx("span", { role: "button", className: styles.toolbarBtn, onClick: () => onRemove(block.uid), children: /* @__PURE__ */ jsx(DeleteOutlined, {}) }) })
|
|
2353
|
+
] }),
|
|
2354
|
+
/* @__PURE__ */ jsx(BlockSchematic, { block, active, activeCell, onSelectCell })
|
|
2355
|
+
]
|
|
2356
|
+
}
|
|
2357
|
+
);
|
|
2358
|
+
}
|
|
2359
|
+
var CanvasBlockItem_default = memo(CanvasBlockItemImpl, areCanvasBlockItemPropsEqual);
|
|
2360
|
+
function CanvasPanelImpl({
|
|
2361
|
+
blocks,
|
|
2362
|
+
activeUid,
|
|
2363
|
+
activeCell,
|
|
2364
|
+
onSelectCell,
|
|
2365
|
+
moveAvailability,
|
|
2366
|
+
onSelect,
|
|
2367
|
+
onMove,
|
|
2368
|
+
onRemove,
|
|
2369
|
+
relocateBlock,
|
|
2370
|
+
onAdd,
|
|
2371
|
+
onOpenTableJsonImport,
|
|
2372
|
+
registerItemRef
|
|
2373
|
+
}) {
|
|
2374
|
+
const { styles } = useCanvasPanelStyles();
|
|
2375
|
+
const explainReject = useCallback(
|
|
2376
|
+
(uid, anchorUid) => explainRelocateReject(blocks, uid, anchorUid),
|
|
2377
|
+
[blocks]
|
|
2378
|
+
);
|
|
2379
|
+
const drag = useBlockReorderDrag({ explainReject, relocateBlock });
|
|
2380
|
+
const anchors = useMemo(() => buildCanvasDragAnchors(blocks), [blocks]);
|
|
2381
|
+
const structureKey = useMemo(() => structureSignatureOf(blocks), [blocks]);
|
|
2382
|
+
return /* @__PURE__ */ jsx("div", { className: styles.canvasPanel, children: /* @__PURE__ */ jsxs("div", { className: styles.canvasInner, children: [
|
|
2383
|
+
/* @__PURE__ */ jsx(BlockPaletteToolbar, { onAdd, onOpenTableJsonImport }),
|
|
2384
|
+
/* @__PURE__ */ jsx("div", { className: styles.canvasPaper, onClick: () => onSelect(void 0), children: blocks.length === 0 ? /* @__PURE__ */ jsxs("div", { className: styles.canvasEmpty, children: [
|
|
2385
|
+
/* @__PURE__ */ jsx(AppstoreAddOutlined, { className: styles.emptyIcon }),
|
|
2386
|
+
/* @__PURE__ */ jsx("span", { children: tr("\u8FD8\u6CA1\u6709\u5185\u5BB9\u5757\uFF0C\u70B9\u51FB\u4E0A\u65B9\u6309\u94AE\u6DFB\u52A0") })
|
|
2387
|
+
] }) : blocks.map((block) => {
|
|
2388
|
+
const availability = moveAvailability.get(block.uid);
|
|
2389
|
+
const anchor = anchors.get(block.uid);
|
|
2390
|
+
const indicator = drag.indicator;
|
|
2391
|
+
let dropSide = null;
|
|
2392
|
+
if (indicator && anchor && indicator.targetUid === block.uid) {
|
|
2393
|
+
dropSide = indicator.anchorUid === anchor.afterAnchor ? "bottom" : "top";
|
|
2394
|
+
}
|
|
2395
|
+
return /* @__PURE__ */ jsx(
|
|
2396
|
+
CanvasBlockItem_default,
|
|
2397
|
+
{
|
|
2398
|
+
block,
|
|
2399
|
+
active: block.uid === activeUid,
|
|
2400
|
+
activeCell,
|
|
2401
|
+
onSelectCell,
|
|
2402
|
+
canMoveUp: availability?.up ?? false,
|
|
2403
|
+
canMoveDown: availability?.down ?? false,
|
|
2404
|
+
unitUid: anchor?.unitUid ?? block.uid,
|
|
2405
|
+
beforeAnchor: anchor?.beforeAnchor ?? block.uid,
|
|
2406
|
+
afterAnchor: anchor?.afterAnchor ?? null,
|
|
2407
|
+
unitDragging: drag.draggingUid != null && drag.draggingUid === anchor?.unitUid,
|
|
2408
|
+
dropSide,
|
|
2409
|
+
dropForbidden: indicator?.targetUid === block.uid && indicator.forbidden,
|
|
2410
|
+
dropReason: indicator?.targetUid === block.uid ? indicator.reason : void 0,
|
|
2411
|
+
getDragSourceProps: drag.getDragSourceProps,
|
|
2412
|
+
getDropTargetProps: drag.getDropTargetProps,
|
|
2413
|
+
structureKey,
|
|
2414
|
+
onSelect,
|
|
2415
|
+
onMove,
|
|
2416
|
+
onRemove,
|
|
2417
|
+
registerRef: registerItemRef(block.uid)
|
|
2418
|
+
},
|
|
2419
|
+
block.uid
|
|
2420
|
+
);
|
|
2421
|
+
}) })
|
|
2422
|
+
] }) });
|
|
2423
|
+
}
|
|
2424
|
+
var CanvasPanel_default = memo(CanvasPanelImpl);
|
|
2425
|
+
function InspectorPanel({
|
|
2426
|
+
activeTab,
|
|
2427
|
+
onTabChange,
|
|
2428
|
+
properties,
|
|
2429
|
+
structure,
|
|
2430
|
+
history
|
|
2431
|
+
}) {
|
|
2432
|
+
const { styles } = useInspectorPanelStyles();
|
|
2433
|
+
const [historyVisits, setHistoryVisits] = useState(0);
|
|
2434
|
+
return /* @__PURE__ */ jsx("div", { className: styles.rightPanel, children: /* @__PURE__ */ jsx("div", { className: styles.tabsHost, children: /* @__PURE__ */ jsx(
|
|
2435
|
+
Tabs,
|
|
2436
|
+
{
|
|
2437
|
+
className: styles.panelTabs,
|
|
2438
|
+
contentPadding: false,
|
|
2439
|
+
activeKey: activeTab,
|
|
2440
|
+
onChange: (key) => {
|
|
2441
|
+
const next = key;
|
|
2442
|
+
onTabChange(next);
|
|
2443
|
+
if (next === "history") setHistoryVisits((v) => v + 1);
|
|
2444
|
+
},
|
|
2445
|
+
items: [
|
|
2446
|
+
{
|
|
2447
|
+
key: "properties",
|
|
2448
|
+
label: tr("\u5C5E\u6027"),
|
|
2449
|
+
children: properties
|
|
2450
|
+
},
|
|
2451
|
+
{
|
|
2452
|
+
key: "structure",
|
|
2453
|
+
label: tr("\u7ED3\u6784"),
|
|
2454
|
+
children: structure
|
|
2455
|
+
},
|
|
2456
|
+
{
|
|
2457
|
+
key: "history",
|
|
2458
|
+
label: tr("\u5386\u53F2"),
|
|
2459
|
+
// 仅激活时挂载;key 随进入次数递增(Fragment 不产生额外 DOM),
|
|
2460
|
+
// 每次进入都重挂载注入的历史节点。
|
|
2461
|
+
children: activeTab === "history" ? /* @__PURE__ */ jsx(Fragment$1, { children: history }, historyVisits) : null
|
|
2462
|
+
}
|
|
2463
|
+
]
|
|
2464
|
+
}
|
|
2465
|
+
) }) });
|
|
2466
|
+
}
|
|
2467
|
+
function SlotSwitches({ block, onPatch, onSwitchFree }) {
|
|
2468
|
+
const { styles } = useBlockSettingsFormStyles();
|
|
2469
|
+
return /* @__PURE__ */ jsx(
|
|
2470
|
+
ControlItem,
|
|
2471
|
+
{
|
|
2472
|
+
label: tr("\u586B\u5199"),
|
|
2473
|
+
hint: /* @__PURE__ */ jsxs("div", { className: styles.slotHintText, children: [
|
|
2474
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
2475
|
+
/* @__PURE__ */ jsx("b", { children: tr("\u56FA\u5B9A\u6587\u5B57") }),
|
|
2476
|
+
tr("\uFF08\u53EF\u586B\u5199\u5173\uFF09\uFF1A\u9501\u5B9A\u7ED3\u6784\u4E0E\u5185\u5BB9\uFF0C\u4E0D\u53EF\u6539\u4E0D\u53EF\u5220\u3002")
|
|
2477
|
+
] }),
|
|
2478
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
2479
|
+
/* @__PURE__ */ jsx("b", { children: tr("\u53EF\u586B\u5199") }),
|
|
2480
|
+
tr("\uFF08\u53EF\u586B\u5199\u5F00\u3001\u5FC5\u586B\u5173\uFF09\uFF1A\u81EA\u7531\u5757\uFF0C\u53EF\u81EA\u7531\u4FEE\u6539/\u5220\u9664\uFF0C\u65E0\u6821\u9A8C\uFF1B\u53EA\u80FD\u4F4D\u4E8E\u4E2D\u95F4\u533A\u3002")
|
|
2481
|
+
] }),
|
|
2482
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
2483
|
+
/* @__PURE__ */ jsx("b", { children: tr("\u5FC5\u586B") }),
|
|
2484
|
+
tr("\uFF08\u53EF\u586B\u5199\u5F00\u3001\u5FC5\u586B\u5F00\uFF09\uFF1A\u9501\u5B9A\u7ED3\u6784\u4E0D\u53EF\u5220\u5757\uFF0C\u53EF\u7F16\u8F91\u5185\u90E8\u6587\u5B57\uFF0C\u63D0\u4EA4\u65F6\u6821\u9A8C\u975E\u7A7A\u3002")
|
|
2485
|
+
] }),
|
|
2486
|
+
/* @__PURE__ */ jsx("div", { className: styles.slotHintDivider, children: tr("\u56FA\u5B9A\u6587\u5B57\u5185\u53EF\u7528\u8BED\u6CD5\u6807\u8BB0\u884C\u5185\u53EF\u586B\u4F4D\uFF1A") }),
|
|
2487
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
2488
|
+
"{{\u6807\u7B7E}}",
|
|
2489
|
+
" ",
|
|
2490
|
+
tr("= \u53EF\u586B\u9879\uFF08\u4E0D\u6821\u9A8C\uFF09")
|
|
2491
|
+
] }),
|
|
2492
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
2493
|
+
"{[\u6807\u7B7E]}",
|
|
2494
|
+
" ",
|
|
2495
|
+
tr("= \u5FC5\u586B\u9879\uFF08\u63D0\u4EA4\u65F6\u5FC5\u987B\u586B\u5199\uFF09")
|
|
2496
|
+
] })
|
|
2497
|
+
] }),
|
|
2498
|
+
children: /* @__PURE__ */ jsxs(Space, { size: 16, children: [
|
|
2499
|
+
/* @__PURE__ */ jsxs(Space, { size: 6, children: [
|
|
2500
|
+
/* @__PURE__ */ jsx("span", { className: styles.fieldNote, children: tr("\u53EF\u586B\u5199") }),
|
|
2501
|
+
/* @__PURE__ */ jsx(
|
|
2502
|
+
Switch,
|
|
2503
|
+
{
|
|
2504
|
+
size: "small",
|
|
2505
|
+
checked: block.isSlot,
|
|
2506
|
+
onChange: (checked) => {
|
|
2507
|
+
if (checked && !block.required) {
|
|
2508
|
+
onSwitchFree(block.uid, { isSlot: true, required: false });
|
|
2509
|
+
} else {
|
|
2510
|
+
onPatch(block.uid, {
|
|
2511
|
+
isSlot: checked,
|
|
2512
|
+
required: checked ? block.required : false
|
|
2513
|
+
});
|
|
2514
|
+
}
|
|
2515
|
+
}
|
|
2516
|
+
}
|
|
2517
|
+
)
|
|
2518
|
+
] }),
|
|
2519
|
+
/* @__PURE__ */ jsxs(Space, { size: 6, children: [
|
|
2520
|
+
/* @__PURE__ */ jsx("span", { className: styles.fieldNote, children: tr("\u5FC5\u586B") }),
|
|
2521
|
+
/* @__PURE__ */ jsx(
|
|
2522
|
+
Switch,
|
|
2523
|
+
{
|
|
2524
|
+
size: "small",
|
|
2525
|
+
disabled: !block.isSlot,
|
|
2526
|
+
checked: block.required,
|
|
2527
|
+
onChange: (checked) => {
|
|
2528
|
+
if (!checked) {
|
|
2529
|
+
onSwitchFree(block.uid, { isSlot: block.isSlot, required: false });
|
|
2530
|
+
} else {
|
|
2531
|
+
onPatch(block.uid, { required: true });
|
|
2532
|
+
}
|
|
2533
|
+
}
|
|
2534
|
+
}
|
|
2535
|
+
)
|
|
2536
|
+
] })
|
|
2537
|
+
] })
|
|
2538
|
+
}
|
|
2539
|
+
);
|
|
2540
|
+
}
|
|
2541
|
+
var NEW_GROUP_VALUE = "__new_group__";
|
|
2542
|
+
var FREE_BLOCK_STRUCTURE_HINT = tr(
|
|
2543
|
+
"\u81EA\u7531\u5757\uFF08\u53EF\u586B\u5199\u4E14\u975E\u5FC5\u586B\uFF09\u4E0D\u53D7\u7ED3\u6784\u4FDD\u62A4\uFF0C\u4E0D\u80FD\u9489\u4F4F/\u7EC4\u5408/\u8BBE\u987A\u5E8F\u7EA6\u675F\uFF1B\u5173\u95ED\u300C\u53EF\u586B\u5199\u300D\u6216\u5F00\u542F\u300C\u5FC5\u586B\u300D\u540E\u53EF\u8BBE\u7F6E"
|
|
2544
|
+
);
|
|
2545
|
+
function StructureFields({
|
|
2546
|
+
block,
|
|
2547
|
+
blocks,
|
|
2548
|
+
free,
|
|
2549
|
+
groupOptions,
|
|
2550
|
+
onPinChange,
|
|
2551
|
+
onSetOrderConstraints,
|
|
2552
|
+
onGroupChange,
|
|
2553
|
+
onCreateGroup,
|
|
2554
|
+
onRenameGroup
|
|
2555
|
+
}) {
|
|
2556
|
+
const { styles } = useBlockSettingsFormStyles();
|
|
2557
|
+
const orderOptions = useMemo(() => {
|
|
2558
|
+
const candidates = blocks.filter((item) => item.uid !== block.uid && !isFreeDesignerBlock(item));
|
|
2559
|
+
const labelCount = /* @__PURE__ */ new Map();
|
|
2560
|
+
candidates.forEach((item) => {
|
|
2561
|
+
const text = item.label || blockTypeMeta(item.type).label;
|
|
2562
|
+
labelCount.set(text, (labelCount.get(text) ?? 0) + 1);
|
|
2563
|
+
});
|
|
2564
|
+
return candidates.map((item) => {
|
|
2565
|
+
const text = item.label || blockTypeMeta(item.type).label;
|
|
2566
|
+
return {
|
|
2567
|
+
value: item.uid,
|
|
2568
|
+
label: (labelCount.get(text) ?? 0) > 1 ? `${text}\uFF08${blockTypeMeta(item.type).label}\uFF09` : text
|
|
2569
|
+
};
|
|
2570
|
+
});
|
|
2571
|
+
}, [blocks, block.uid]);
|
|
2572
|
+
const handleOrderChange = (direction, value) => {
|
|
2573
|
+
const ok = onSetOrderConstraints(block.uid, {
|
|
2574
|
+
before: direction === "before" ? value : block.before ?? [],
|
|
2575
|
+
after: direction === "after" ? value : block.after ?? []
|
|
2576
|
+
});
|
|
2577
|
+
if (!ok) {
|
|
2578
|
+
showMessage(tr("\u8BE5\u987A\u5E8F\u7EA6\u675F\u4E0E\u73B0\u6709\u7EA6\u675F/\u4F4D\u7F6E\u51B2\u7A81\uFF0C\u672A\u751F\u6548"), { type: "warning" });
|
|
2579
|
+
}
|
|
2580
|
+
};
|
|
2581
|
+
const fields = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2582
|
+
/* @__PURE__ */ jsx(
|
|
2583
|
+
ControlItem,
|
|
2584
|
+
{
|
|
2585
|
+
label: tr("\u9489\u4F4F"),
|
|
2586
|
+
hint: tr(
|
|
2587
|
+
"\u7F6E\u9876\uFF1A\u5FC5\u987B\u4F4D\u4E8E\u6700\u524D\u5806\u53E0\u533A\uFF0C\u5176\u4E0A\u4E0D\u53EF\u63D2\u5165\u5185\u5BB9\uFF1B\u7F6E\u5E95\uFF1A\u5FC5\u987B\u4F4D\u4E8E\u6700\u540E\u5806\u53E0\u533A\uFF0C\u5176\u540E\u4E0D\u53EF\u63D2\u5165\u5185\u5BB9\uFF1B\u4E0D\u9489\u4F4F\uFF1A\u9ED8\u8BA4\u4E2D\u95F4\u533A\u3002\u5207\u6362\u540E\u5757\u81EA\u52A8\u79FB\u52A8\u5230\u5BF9\u5E94\u533A\u6BB5\uFF1B\u7EC4\u4EF6\u7EC4\u6574\u7EC4\u540C\u6B65\u9489\u4F4F\u3002"
|
|
2588
|
+
),
|
|
2589
|
+
children: /* @__PURE__ */ jsx(
|
|
2590
|
+
Select,
|
|
2591
|
+
{
|
|
2592
|
+
size: "small",
|
|
2593
|
+
className: styles.fieldControl,
|
|
2594
|
+
disabled: free,
|
|
2595
|
+
value: block.pin ?? "none",
|
|
2596
|
+
dataSource: TEMPLATE_PIN_OPTIONS.map((option) => ({
|
|
2597
|
+
value: option.value,
|
|
2598
|
+
label: option.label
|
|
2599
|
+
})),
|
|
2600
|
+
onChange: (value) => onPinChange(block.uid, value === "none" ? void 0 : value)
|
|
2601
|
+
}
|
|
2602
|
+
)
|
|
2603
|
+
}
|
|
2604
|
+
),
|
|
2605
|
+
/* @__PURE__ */ jsx(
|
|
2606
|
+
ControlItem,
|
|
2607
|
+
{
|
|
2608
|
+
label: tr("\u5FC5\u987B\u4F4D\u4E8E\u4E4B\u4E0A"),
|
|
2609
|
+
hint: tr("\u672C\u5757\u5FC5\u987B\u6392\u5728\u8FD9\u4E9B\u5757\u4E4B\u524D\uFF08\u4E2D\u95F4\u53EF\u9694\u5176\u5B83\u5757\uFF09\u3002\u4E0E\u73B0\u6709\u7EA6\u675F\u6216\u9489\u4F4F\u4F4D\u7F6E\u51B2\u7A81\u65F6\u4E0D\u751F\u6548\u3002"),
|
|
2610
|
+
children: /* @__PURE__ */ jsx(
|
|
2611
|
+
Select2,
|
|
2612
|
+
{
|
|
2613
|
+
mode: "multiple",
|
|
2614
|
+
size: "small",
|
|
2615
|
+
className: styles.fieldControl,
|
|
2616
|
+
placeholder: orderOptions.length > 0 ? tr("\u65E0") : tr("\u6682\u65E0\u5176\u5B83\u53D7\u4FDD\u62A4\u5757"),
|
|
2617
|
+
disabled: free || orderOptions.length === 0,
|
|
2618
|
+
value: block.before ?? [],
|
|
2619
|
+
options: orderOptions,
|
|
2620
|
+
onChange: (value) => handleOrderChange("before", value)
|
|
2621
|
+
}
|
|
2622
|
+
)
|
|
2623
|
+
}
|
|
2624
|
+
),
|
|
2625
|
+
/* @__PURE__ */ jsx(
|
|
2626
|
+
ControlItem,
|
|
2627
|
+
{
|
|
2628
|
+
label: tr("\u5FC5\u987B\u4F4D\u4E8E\u4E4B\u4E0B"),
|
|
2629
|
+
hint: tr("\u672C\u5757\u5FC5\u987B\u6392\u5728\u8FD9\u4E9B\u5757\u4E4B\u540E\uFF08\u4E2D\u95F4\u53EF\u9694\u5176\u5B83\u5757\uFF09\u3002\u4E0E\u73B0\u6709\u7EA6\u675F\u6216\u9489\u4F4F\u4F4D\u7F6E\u51B2\u7A81\u65F6\u4E0D\u751F\u6548\u3002"),
|
|
2630
|
+
children: /* @__PURE__ */ jsx(
|
|
2631
|
+
Select2,
|
|
2632
|
+
{
|
|
2633
|
+
mode: "multiple",
|
|
2634
|
+
size: "small",
|
|
2635
|
+
className: styles.fieldControl,
|
|
2636
|
+
placeholder: orderOptions.length > 0 ? tr("\u65E0") : tr("\u6682\u65E0\u5176\u5B83\u53D7\u4FDD\u62A4\u5757"),
|
|
2637
|
+
disabled: free || orderOptions.length === 0,
|
|
2638
|
+
value: block.after ?? [],
|
|
2639
|
+
options: orderOptions,
|
|
2640
|
+
onChange: (value) => handleOrderChange("after", value)
|
|
2641
|
+
}
|
|
2642
|
+
)
|
|
2643
|
+
}
|
|
2644
|
+
),
|
|
2645
|
+
/* @__PURE__ */ jsxs(
|
|
2646
|
+
ControlItem,
|
|
2647
|
+
{
|
|
2648
|
+
label: tr("\u7EC4\u4EF6\u7EC4"),
|
|
2649
|
+
hint: tr(
|
|
2650
|
+
"\u628A\u591A\u4E2A\u76F8\u90BB\u7EC4\u4EF6\u5408\u5E76\u4E3A\u4E00\u7EC4\uFF1A\u8BBE\u8BA1\u5668\u5185\u6574\u7EC4\u79FB\u52A8\uFF1B\u8FD0\u884C\u65F6\u6210\u5458\u4E4B\u95F4\u4E0D\u53EF\u63D2\u5165\u5185\u5BB9\u3001\u4EC5\u53EF\u5728\u7EC4\u5185\u91CD\u6392\uFF08\u6574\u7EC4\u79FB\u52A8\u8BF7\u56DE\u5230\u8BBE\u8BA1\u5668\u8C03\u6574\uFF09\u3002\u9009\u62E9\u5DF2\u6709\u7EC4\u65F6\u5757\u4F1A\u81EA\u52A8\u79FB\u52A8\u5230\u8BE5\u7EC4\u65C1\u8FB9\u3002"
|
|
2651
|
+
),
|
|
2652
|
+
children: [
|
|
2653
|
+
/* @__PURE__ */ jsx(
|
|
2654
|
+
Select2,
|
|
2655
|
+
{
|
|
2656
|
+
size: "small",
|
|
2657
|
+
className: styles.fieldControlNarrow,
|
|
2658
|
+
allowClear: true,
|
|
2659
|
+
disabled: free,
|
|
2660
|
+
placeholder: tr("\u65E0"),
|
|
2661
|
+
value: block.groupId || void 0,
|
|
2662
|
+
options: [...groupOptions, { value: NEW_GROUP_VALUE, label: tr("\uFF0B \u65B0\u5EFA\u7EC4\u4EF6\u7EC4") }],
|
|
2663
|
+
onChange: (value) => {
|
|
2664
|
+
if (value === NEW_GROUP_VALUE) {
|
|
2665
|
+
onCreateGroup(block.uid);
|
|
2666
|
+
return;
|
|
2667
|
+
}
|
|
2668
|
+
onGroupChange(block.uid, value || void 0);
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2671
|
+
),
|
|
2672
|
+
block.groupId && /* @__PURE__ */ jsx(
|
|
2673
|
+
Input,
|
|
2674
|
+
{
|
|
2675
|
+
size: "small",
|
|
2676
|
+
className: styles.fieldControlNarrow,
|
|
2677
|
+
value: block.groupLabel ?? "",
|
|
2678
|
+
onChange: (v) => onRenameGroup(block.groupId, v),
|
|
2679
|
+
placeholder: tr("\u7EC4\u540D\uFF08\u6574\u7EC4\u540C\u6B65\uFF0C\u7559\u7A7A\u663E\u793A\u4E3A\u300C\u672A\u547D\u540D\u7EC4\u300D\uFF09")
|
|
2680
|
+
}
|
|
2681
|
+
)
|
|
2682
|
+
]
|
|
2683
|
+
}
|
|
2684
|
+
)
|
|
2685
|
+
] });
|
|
2686
|
+
if (!free) return fields;
|
|
2687
|
+
return /* @__PURE__ */ jsx(Tooltip, { autoWidth: false, title: FREE_BLOCK_STRUCTURE_HINT, children: /* @__PURE__ */ jsx("div", { style: { display: "flex", flexDirection: "column", gap: 8 }, children: fields }) });
|
|
2688
|
+
}
|
|
2689
|
+
function orderCandidatesEqual(prev, next) {
|
|
2690
|
+
if (prev === next) return true;
|
|
2691
|
+
if (prev.length !== next.length) return false;
|
|
2692
|
+
return prev.every(
|
|
2693
|
+
(block, index) => block.uid === next[index].uid && block.type === next[index].type && block.isSlot === next[index].isSlot && block.required === next[index].required
|
|
2694
|
+
);
|
|
2695
|
+
}
|
|
2696
|
+
function groupOptionsEqual(prev, next) {
|
|
2697
|
+
if (prev === next) return true;
|
|
2698
|
+
return prev.length === next.length && prev.every((option, index) => option.value === next[index].value && option.label === next[index].label);
|
|
2699
|
+
}
|
|
2700
|
+
function areBlockSettingsFormPropsEqual(prev, next) {
|
|
2701
|
+
return prev.block === next.block && orderCandidatesEqual(prev.blocks, next.blocks) && groupOptionsEqual(prev.groupOptions, next.groupOptions) && prev.dataSource === next.dataSource && prev.onPatch === next.onPatch && prev.activeCell === next.activeCell && prev.onCellSelectionChange === next.onCellSelectionChange && prev.onSwitchFree === next.onSwitchFree && prev.onPinChange === next.onPinChange && prev.onSetOrderConstraints === next.onSetOrderConstraints && prev.onGroupChange === next.onGroupChange && prev.onCreateGroup === next.onCreateGroup && prev.onRenameGroup === next.onRenameGroup;
|
|
2702
|
+
}
|
|
2703
|
+
function SettingsGroup({ title, children }) {
|
|
2704
|
+
const { styles } = useBlockSettingsFormStyles();
|
|
2705
|
+
return /* @__PURE__ */ jsxs("section", { className: styles.settingsCard, children: [
|
|
2706
|
+
/* @__PURE__ */ jsx("p", { className: styles.settingsCardTitle, children: title }),
|
|
2707
|
+
children
|
|
2708
|
+
] });
|
|
2709
|
+
}
|
|
2710
|
+
function BlockSettingsFormImpl(props) {
|
|
2711
|
+
const {
|
|
2712
|
+
block,
|
|
2713
|
+
blocks,
|
|
2714
|
+
groupOptions,
|
|
2715
|
+
dataSource,
|
|
2716
|
+
onPatch,
|
|
2717
|
+
activeCell,
|
|
2718
|
+
onCellSelectionChange,
|
|
2719
|
+
onSwitchFree,
|
|
2720
|
+
onPinChange,
|
|
2721
|
+
onSetOrderConstraints,
|
|
2722
|
+
onGroupChange,
|
|
2723
|
+
onCreateGroup,
|
|
2724
|
+
onRenameGroup
|
|
2725
|
+
} = props;
|
|
2726
|
+
const { styles } = useBlockSettingsFormStyles();
|
|
2727
|
+
const meta = blockTypeMeta(block.type);
|
|
2728
|
+
const descriptor = getDesignerBlockDescriptor(block.type);
|
|
2729
|
+
const free = isFreeDesignerBlock(block);
|
|
2730
|
+
const supportsInlineSlots = block.type === "heading" || block.type === "paragraph";
|
|
2731
|
+
const inlineSlotHint = tr(
|
|
2732
|
+
"\u56FA\u5B9A\u6587\u5B57\uFF1B\u7528 {{\u6807\u7B7E}} \u6807\u8BB0\u53EF\u586B\u4F4D\uFF0C{[\u6807\u7B7E]} \u6807\u8BB0\u5FC5\u586B\u4F4D\uFF0C\u5982\uFF1A\u7532\u65B9 {[\u7532\u65B9\u540D\u79F0]}\uFF08{{\u5907\u6CE8}} \u4E3A\u53EF\u586B\uFF09"
|
|
2733
|
+
);
|
|
2734
|
+
const blockSlotHint = tr("\u53EF\u586B\u5199\u5757\uFF1A\u7559\u7A7A\u5219\u4EE5\u300C\u6807\u7B7E\u300D\u4E3A\u63D0\u793A\uFF1B\u4E5F\u53EF\u81EA\u5B9A\u4E49\u9884\u586B\u63D0\u793A\uFF0C\u5982\uFF1A\u8BF7\u8F93\u5165\u7532\u65B9\u540D\u79F0");
|
|
2735
|
+
const textPlaceholder = supportsInlineSlots ? block.isSlot ? blockSlotHint : inlineSlotHint : tr("\u9884\u586B / \u5360\u4F4D\u63D0\u793A\u6587\u672C");
|
|
2736
|
+
return /* @__PURE__ */ jsxs("div", { className: styles.settingsGroups, children: [
|
|
2737
|
+
/* @__PURE__ */ jsxs("div", { className: styles.blockContext, children: [
|
|
2738
|
+
/* @__PURE__ */ jsx("span", { children: tr("\u5F53\u524D\u5757") }),
|
|
2739
|
+
/* @__PURE__ */ jsx("span", { children: "\u203A" }),
|
|
2740
|
+
/* @__PURE__ */ jsx("span", { className: styles.blockContextName, children: meta.label }),
|
|
2741
|
+
meta.slotEligible && /* @__PURE__ */ jsx("span", { className: styles.blockContextState, children: free ? tr("\u81EA\u7531\u5757") : block.isSlot ? tr("\u5FC5\u586B\u5757") : tr("\u56FA\u5B9A\u6587\u5B57") })
|
|
2742
|
+
] }),
|
|
2743
|
+
meta.slotEligible && /* @__PURE__ */ jsx(SettingsGroup, { title: tr("\u57FA\u672C"), children: /* @__PURE__ */ jsx(ControlItem, { label: tr("\u6807\u7B7E"), children: /* @__PURE__ */ jsx(
|
|
2744
|
+
Input,
|
|
2745
|
+
{
|
|
2746
|
+
size: "small",
|
|
2747
|
+
className: styles.fieldFill,
|
|
2748
|
+
value: block.label,
|
|
2749
|
+
onChange: (v) => onPatch(block.uid, { label: v }),
|
|
2750
|
+
placeholder: tr("\u5757\u6807\u7B7E")
|
|
2751
|
+
}
|
|
2752
|
+
) }) }),
|
|
2753
|
+
(block.type === "heading" || block.type === "paragraph" || block.type === "codeBlock" || block.type === "image") && /* @__PURE__ */ jsxs(SettingsGroup, { title: tr("\u5185\u5BB9"), children: [
|
|
2754
|
+
block.type === "heading" && /* @__PURE__ */ jsx(ControlItem, { label: tr("\u7EA7\u522B"), children: /* @__PURE__ */ jsx(
|
|
2755
|
+
Radio,
|
|
2756
|
+
{
|
|
2757
|
+
optionType: "button",
|
|
2758
|
+
buttonStyle: "solid",
|
|
2759
|
+
size: "small",
|
|
2760
|
+
value: block.headingLevel ?? 2,
|
|
2761
|
+
onChange: (value) => onPatch(block.uid, { headingLevel: value }),
|
|
2762
|
+
dataSource: [
|
|
2763
|
+
{ label: "H1", value: 1 },
|
|
2764
|
+
{ label: "H2", value: 2 },
|
|
2765
|
+
{ label: "H3", value: 3 }
|
|
2766
|
+
]
|
|
2767
|
+
}
|
|
2768
|
+
) }),
|
|
2769
|
+
(block.type === "heading" || block.type === "paragraph" || block.type === "codeBlock") && /* @__PURE__ */ jsx(ControlItem, { label: block.type === "heading" ? tr("\u6587\u5B57") : tr("\u5360\u4F4D"), children: block.type === "paragraph" ? (
|
|
2770
|
+
// 文本段落常为多行固定条款或长文本,用 TextArea 随内容撑高(不设 maxRows 上限)。
|
|
2771
|
+
/* @__PURE__ */ jsx(
|
|
2772
|
+
Input.TextArea,
|
|
2773
|
+
{
|
|
2774
|
+
size: "small",
|
|
2775
|
+
className: styles.fieldFill,
|
|
2776
|
+
autoSize: { minRows: 2 },
|
|
2777
|
+
value: block.text ?? "",
|
|
2778
|
+
onChange: (v) => onPatch(block.uid, { text: v }),
|
|
2779
|
+
placeholder: textPlaceholder
|
|
2780
|
+
}
|
|
2781
|
+
)
|
|
2782
|
+
) : /* @__PURE__ */ jsx(
|
|
2783
|
+
Input,
|
|
2784
|
+
{
|
|
2785
|
+
size: "small",
|
|
2786
|
+
className: styles.fieldFill,
|
|
2787
|
+
value: block.text ?? "",
|
|
2788
|
+
onChange: (v) => onPatch(block.uid, { text: v }),
|
|
2789
|
+
placeholder: textPlaceholder
|
|
2790
|
+
}
|
|
2791
|
+
) }),
|
|
2792
|
+
supportsInlineSlots && dataSource && /* @__PURE__ */ jsx(ControlItem, { label: tr("\u540E\u7AEF\u53D8\u91CF"), hint: tr("\u9009\u62E9\u540E\u63D2\u5165\u5230\u6587\u672C\u672B\u5C3E\uFF1B\u53EF\u7EE7\u7EED\u7F16\u8F91\u6587\u672C\u8C03\u6574\u53D8\u91CF\u4F4D\u7F6E"), children: /* @__PURE__ */ jsx(
|
|
2793
|
+
DataBindingSelect,
|
|
2794
|
+
{
|
|
2795
|
+
source: dataSource,
|
|
2796
|
+
mode: "scalar",
|
|
2797
|
+
onChange: (path) => {
|
|
2798
|
+
if (!path) return;
|
|
2799
|
+
const separator = block.text?.trim() ? " " : "";
|
|
2800
|
+
onPatch(block.uid, { text: `${block.text ?? ""}${separator}[[@${path}]]` });
|
|
2801
|
+
}
|
|
2802
|
+
}
|
|
2803
|
+
) }),
|
|
2804
|
+
block.type === "image" && /* @__PURE__ */ jsxs(ControlItem, { label: tr("\u5C3A\u5BF8"), children: [
|
|
2805
|
+
/* @__PURE__ */ jsx("span", { className: styles.fieldNote, children: tr("\u5BBD") }),
|
|
2806
|
+
/* @__PURE__ */ jsx(
|
|
2807
|
+
InputNumber,
|
|
2808
|
+
{
|
|
2809
|
+
size: "small",
|
|
2810
|
+
min: 40,
|
|
2811
|
+
max: 2e3,
|
|
2812
|
+
value: block.width ?? IMAGE_DEFAULT_WIDTH,
|
|
2813
|
+
onChange: (v) => onPatch(block.uid, { width: v ?? IMAGE_DEFAULT_WIDTH }),
|
|
2814
|
+
style: { width: 90 }
|
|
2815
|
+
}
|
|
2816
|
+
),
|
|
2817
|
+
/* @__PURE__ */ jsx("span", { children: "\xD7" }),
|
|
2818
|
+
/* @__PURE__ */ jsx("span", { className: styles.fieldNote, children: tr("\u9AD8") }),
|
|
2819
|
+
/* @__PURE__ */ jsx(
|
|
2820
|
+
InputNumber,
|
|
2821
|
+
{
|
|
2822
|
+
size: "small",
|
|
2823
|
+
min: 40,
|
|
2824
|
+
max: 2e3,
|
|
2825
|
+
value: block.height ?? IMAGE_DEFAULT_HEIGHT,
|
|
2826
|
+
onChange: (v) => onPatch(block.uid, { height: v ?? IMAGE_DEFAULT_HEIGHT }),
|
|
2827
|
+
style: { width: 90 }
|
|
2828
|
+
}
|
|
2829
|
+
)
|
|
2830
|
+
] })
|
|
2831
|
+
] }),
|
|
2832
|
+
descriptor?.renderSettings && /* @__PURE__ */ jsx(SettingsGroup, { title: descriptor?.alwaysStructured ? tr("\u8868\u683C\u8BBE\u7F6E") : tr("${0}\u8BBE\u7F6E", [meta.label]), children: descriptor.renderSettings({
|
|
2833
|
+
block,
|
|
2834
|
+
dataSource,
|
|
2835
|
+
onPatch: (patch) => onPatch(block.uid, patch),
|
|
2836
|
+
cellSelection: activeCell && activeCell.uid === block.uid ? { row: activeCell.row, cell: activeCell.cell } : null,
|
|
2837
|
+
onCellSelectionChange: (cell) => onCellSelectionChange?.(block.uid, cell)
|
|
2838
|
+
}) }),
|
|
2839
|
+
meta.slotEligible && !descriptor?.alwaysStructured && /* @__PURE__ */ jsx(SettingsGroup, { title: tr("\u586B\u5199\u8BBE\u7F6E"), children: /* @__PURE__ */ jsx(SlotSwitches, { block, onPatch, onSwitchFree }) }),
|
|
2840
|
+
/* @__PURE__ */ jsx(SettingsGroup, { title: tr("\u7ED3\u6784\u8BBE\u7F6E"), children: /* @__PURE__ */ jsx(
|
|
2841
|
+
StructureFields,
|
|
2842
|
+
{
|
|
2843
|
+
block,
|
|
2844
|
+
blocks,
|
|
2845
|
+
free,
|
|
2846
|
+
groupOptions,
|
|
2847
|
+
onPinChange,
|
|
2848
|
+
onSetOrderConstraints,
|
|
2849
|
+
onGroupChange,
|
|
2850
|
+
onCreateGroup,
|
|
2851
|
+
onRenameGroup
|
|
2852
|
+
}
|
|
2853
|
+
) })
|
|
2854
|
+
] });
|
|
2855
|
+
}
|
|
2856
|
+
var BlockSettingsForm_default = memo(BlockSettingsFormImpl, areBlockSettingsFormPropsEqual);
|
|
2857
|
+
function TableJsonImportModal({
|
|
2858
|
+
open,
|
|
2859
|
+
text,
|
|
2860
|
+
error,
|
|
2861
|
+
onTextChange,
|
|
2862
|
+
onOk,
|
|
2863
|
+
onCancel
|
|
2864
|
+
}) {
|
|
2865
|
+
const { styles } = useTableJsonImportModalStyles();
|
|
2866
|
+
return (
|
|
2867
|
+
// 从 JSON 导入表格(粘贴 AI 生成 / Excel 转换的表格 JSON)
|
|
2868
|
+
/* @__PURE__ */ jsx(
|
|
2869
|
+
Modal,
|
|
2870
|
+
{
|
|
2871
|
+
title: tr("\u4ECE JSON \u5BFC\u5165\u8868\u683C"),
|
|
2872
|
+
width: 640,
|
|
2873
|
+
open,
|
|
2874
|
+
okText: tr("\u521B\u5EFA\u8868\u683C\u5757"),
|
|
2875
|
+
cancelText: tr("\u53D6\u6D88"),
|
|
2876
|
+
onOk,
|
|
2877
|
+
onCancel,
|
|
2878
|
+
children: /* @__PURE__ */ jsxs("div", { style: { display: "flex", flexDirection: "column", gap: 8 }, children: [
|
|
2879
|
+
/* @__PURE__ */ jsx("span", { className: styles.hint, children: tr(
|
|
2880
|
+
"\u7C98\u8D34\u8868\u683C JSON\uFF1A\u6570\u636E\u8868\u683C\u63D0\u4F9B columns\uFF08\u53EF\u542B defaultRows/defaultData/\u5217\u7C7B\u578B\uFF09\uFF0C \u56FA\u5B9A\u8868\u683C\u63D0\u4F9B rows\uFF08\u53EF\u542B\u884C\u9AD8/\u5BBD\u5EA6/\u7EB5\u5411\u5408\u5E76/\u5355\u5143\u683C\u7C7B\u578B\u4E0E\u516C\u5F0F\uFF09\uFF0C\u5B8C\u6574\u683C\u5F0F\u89C1 TABLE_JSON.md\u3002 \u975E\u6CD5\u5B57\u6BB5\u4F1A\u81EA\u52A8\u56DE\u9000\u5E76\u5728\u5BFC\u5165\u540E\u63D0\u793A\u3002"
|
|
2881
|
+
) }),
|
|
2882
|
+
/* @__PURE__ */ jsx(
|
|
2883
|
+
Input.TextArea,
|
|
2884
|
+
{
|
|
2885
|
+
rows: 12,
|
|
2886
|
+
value: text,
|
|
2887
|
+
onChange: onTextChange,
|
|
2888
|
+
placeholder: '{\n "columns": [\n { "header": "\u540D\u79F0" },\n { "header": "\u6570\u91CF", "fieldType": "text" }\n ],\n "defaultRows": 3\n}'
|
|
2889
|
+
}
|
|
2890
|
+
),
|
|
2891
|
+
error && /* @__PURE__ */ jsx("span", { className: styles.errorText, children: tr(error) })
|
|
2892
|
+
] })
|
|
2893
|
+
}
|
|
2894
|
+
)
|
|
2895
|
+
);
|
|
2896
|
+
}
|
|
2897
|
+
function TemplateDesigner({
|
|
2898
|
+
storage: storageProp,
|
|
2899
|
+
headerLeading,
|
|
2900
|
+
headerActionsExtra,
|
|
2901
|
+
onBack,
|
|
2902
|
+
dataSources = [],
|
|
2903
|
+
aiRegistrar
|
|
2904
|
+
}) {
|
|
2905
|
+
const inheritedStorage = useTemplateStorage();
|
|
2906
|
+
const storage = storageProp ?? inheritedStorage;
|
|
2907
|
+
return /* @__PURE__ */ jsx(TemplateStorageProvider, { storage, children: /* @__PURE__ */ jsx(
|
|
2908
|
+
TemplateDesignerContent,
|
|
2909
|
+
{
|
|
2910
|
+
storage,
|
|
2911
|
+
headerLeading,
|
|
2912
|
+
headerActionsExtra,
|
|
2913
|
+
onBack,
|
|
2914
|
+
dataSources,
|
|
2915
|
+
aiRegistrar
|
|
2916
|
+
}
|
|
2917
|
+
) });
|
|
2918
|
+
}
|
|
2919
|
+
function TemplateDesignerContent({
|
|
2920
|
+
storage,
|
|
2921
|
+
headerLeading,
|
|
2922
|
+
headerActionsExtra,
|
|
2923
|
+
onBack,
|
|
2924
|
+
dataSources = [],
|
|
2925
|
+
aiRegistrar: AiRegistrar
|
|
2926
|
+
}) {
|
|
2927
|
+
const { styles } = useTemplateDesignerStyles();
|
|
2928
|
+
const [current, setCurrent] = useState(() => emptyTemplate());
|
|
2929
|
+
const [saving, setSaving] = useState(false);
|
|
2930
|
+
const [libraryCollapsed, setLibraryCollapsed] = useState(false);
|
|
2931
|
+
const savedTemplateIdRef = useRef(null);
|
|
2932
|
+
const selection = useDesignerSelection({ blocks: current.blocks });
|
|
2933
|
+
const templateLibrary = useTemplateLibrary({ storage, savedTemplateIdRef });
|
|
2934
|
+
const persistence = useTemplatePersistence({
|
|
2935
|
+
current,
|
|
2936
|
+
setCurrent,
|
|
2937
|
+
setActiveUid: selection.setActiveUid,
|
|
2938
|
+
storage,
|
|
2939
|
+
savedTemplateIdRef,
|
|
2940
|
+
reloadLibrary: templateLibrary.reload,
|
|
2941
|
+
setSaving
|
|
2942
|
+
});
|
|
2943
|
+
const blockOps = useBlockStructureOps({
|
|
2944
|
+
blocks: current.blocks,
|
|
2945
|
+
setCurrent,
|
|
2946
|
+
setActiveUid: selection.setActiveUid,
|
|
2947
|
+
setInspectorTab: selection.setInspectorTab
|
|
2948
|
+
});
|
|
2949
|
+
const build = useMemo(() => buildDefinition(current), [current]);
|
|
2950
|
+
const dataSource = dataSources.find((source) => source.key === current.dataSource);
|
|
2951
|
+
const patchTemplate = useCallback(
|
|
2952
|
+
(patch) => setCurrent((prev) => ({ ...prev, ...patch })),
|
|
2953
|
+
[]
|
|
2954
|
+
);
|
|
2955
|
+
const validation = useDesignerValidation({ build });
|
|
2956
|
+
const tableJson = useTableJsonImport(blockOps.insertBlock);
|
|
2957
|
+
const copilotContext = useDesignerCopilotContext({
|
|
2958
|
+
current,
|
|
2959
|
+
setCurrent,
|
|
2960
|
+
activeUid: selection.activeUid,
|
|
2961
|
+
activeCell: selection.activeCell,
|
|
2962
|
+
patchBlock: blockOps.patchBlock,
|
|
2963
|
+
insertBlock: blockOps.insertBlock,
|
|
2964
|
+
removeBlock: blockOps.removeBlock,
|
|
2965
|
+
selectTableCell: selection.selectTableCell,
|
|
2966
|
+
activateBlock: selection.activateBlock
|
|
2967
|
+
});
|
|
2968
|
+
const toggleLibraryCollapsed = useCallback(() => {
|
|
2969
|
+
setLibraryCollapsed((prev) => !prev);
|
|
2970
|
+
}, []);
|
|
2971
|
+
return /* @__PURE__ */ jsxs("div", { className: styles.page, children: [
|
|
2972
|
+
AiRegistrar && /* @__PURE__ */ jsx(
|
|
2973
|
+
AiRegistrar,
|
|
2974
|
+
{
|
|
2975
|
+
context: copilotContext,
|
|
2976
|
+
activeUid: selection.activeUid,
|
|
2977
|
+
activeCell: selection.activeCell,
|
|
2978
|
+
activeLabel: current.blocks.find((block) => block.uid === selection.activeUid)?.label
|
|
2979
|
+
}
|
|
2980
|
+
),
|
|
2981
|
+
/* @__PURE__ */ jsx(
|
|
2982
|
+
DesignerTopBar,
|
|
2983
|
+
{
|
|
2984
|
+
name: current.name,
|
|
2985
|
+
version: current.version,
|
|
2986
|
+
blockCount: current.blocks.length,
|
|
2987
|
+
build,
|
|
2988
|
+
saving,
|
|
2989
|
+
leading: headerLeading,
|
|
2990
|
+
actionsExtra: headerActionsExtra,
|
|
2991
|
+
onBack: headerLeading ? void 0 : onBack,
|
|
2992
|
+
onRename: (name) => patchTemplate({ name }),
|
|
2993
|
+
onSave: persistence.handleSave,
|
|
2994
|
+
onImportFile: persistence.handleImportFile,
|
|
2995
|
+
onExport: persistence.handleExport,
|
|
2996
|
+
onValidate: validation.handleValidatePreview,
|
|
2997
|
+
dataPreview: dataSources.length > 0 ? /* @__PURE__ */ jsx(TemplateDataPreview, { build, dataSource }) : void 0
|
|
2998
|
+
}
|
|
2999
|
+
),
|
|
3000
|
+
/* @__PURE__ */ jsxs("div", { className: styles.body, children: [
|
|
3001
|
+
/* @__PURE__ */ jsx(
|
|
3002
|
+
LibrarySidePanel,
|
|
3003
|
+
{
|
|
3004
|
+
library: templateLibrary.library,
|
|
3005
|
+
currentId: current.id,
|
|
3006
|
+
collapsed: libraryCollapsed,
|
|
3007
|
+
onToggleCollapsed: toggleLibraryCollapsed,
|
|
3008
|
+
onLoad: persistence.handleLoad,
|
|
3009
|
+
onDelete: templateLibrary.handleDelete,
|
|
3010
|
+
onNew: persistence.handleNew
|
|
3011
|
+
}
|
|
3012
|
+
),
|
|
3013
|
+
/* @__PURE__ */ jsx(
|
|
3014
|
+
CanvasPanel_default,
|
|
3015
|
+
{
|
|
3016
|
+
blocks: current.blocks,
|
|
3017
|
+
activeUid: selection.activeUid,
|
|
3018
|
+
activeCell: selection.activeCell,
|
|
3019
|
+
onSelectCell: selection.selectTableCell,
|
|
3020
|
+
moveAvailability: blockOps.moveAvailability,
|
|
3021
|
+
onSelect: selection.activateBlock,
|
|
3022
|
+
onMove: blockOps.moveBlock,
|
|
3023
|
+
onRemove: blockOps.removeBlock,
|
|
3024
|
+
relocateBlock: blockOps.relocateBlock,
|
|
3025
|
+
onAdd: blockOps.addFromPalette,
|
|
3026
|
+
onOpenTableJsonImport: tableJson.openModal,
|
|
3027
|
+
registerItemRef: selection.registerItemRef
|
|
3028
|
+
}
|
|
3029
|
+
),
|
|
3030
|
+
/* @__PURE__ */ jsx(
|
|
3031
|
+
InspectorPanel,
|
|
3032
|
+
{
|
|
3033
|
+
activeTab: selection.inspectorTab,
|
|
3034
|
+
onTabChange: selection.setInspectorTab,
|
|
3035
|
+
properties: selection.selectedBlock ? /* @__PURE__ */ jsx(
|
|
3036
|
+
BlockSettingsForm_default,
|
|
3037
|
+
{
|
|
3038
|
+
block: selection.selectedBlock,
|
|
3039
|
+
blocks: current.blocks,
|
|
3040
|
+
groupOptions: blockOps.groupOptions,
|
|
3041
|
+
dataSource,
|
|
3042
|
+
onPatch: blockOps.patchBlock,
|
|
3043
|
+
activeCell: selection.activeCell,
|
|
3044
|
+
onCellSelectionChange: selection.selectTableCell,
|
|
3045
|
+
onSwitchFree: blockOps.switchBlockFree,
|
|
3046
|
+
onPinChange: blockOps.applyBlockPin,
|
|
3047
|
+
onSetOrderConstraints: blockOps.setBlockOrderConstraints,
|
|
3048
|
+
onGroupChange: blockOps.setBlockGroup,
|
|
3049
|
+
onCreateGroup: blockOps.createGroupFor,
|
|
3050
|
+
onRenameGroup: blockOps.renameGroupLabel
|
|
3051
|
+
}
|
|
3052
|
+
) : /* @__PURE__ */ jsx(TemplateBasicInfoForm, { template: current, dataSources, onPatch: patchTemplate }),
|
|
3053
|
+
structure: /* @__PURE__ */ jsx(
|
|
3054
|
+
BlockOutline,
|
|
3055
|
+
{
|
|
3056
|
+
blocks: current.blocks,
|
|
3057
|
+
activeUid: selection.activeUid,
|
|
3058
|
+
onSelect: selection.handleOutlineSelect,
|
|
3059
|
+
onMove: blockOps.moveBlock,
|
|
3060
|
+
moveAvailability: blockOps.moveAvailability,
|
|
3061
|
+
relocateBlock: blockOps.relocateBlock,
|
|
3062
|
+
onGroupSelected: blockOps.groupSelected,
|
|
3063
|
+
onUngroupSelected: blockOps.ungroupSelected
|
|
3064
|
+
}
|
|
3065
|
+
),
|
|
3066
|
+
history: /* @__PURE__ */ jsx(
|
|
3067
|
+
TemplateHistoryPanel,
|
|
3068
|
+
{
|
|
3069
|
+
templateId: current.id.trim(),
|
|
3070
|
+
templateName: current.name,
|
|
3071
|
+
maxDrafts: persistence.maxDrafts,
|
|
3072
|
+
onMaxDraftsChange: persistence.handleMaxDraftsChange,
|
|
3073
|
+
onRestore: persistence.handleRestoreHistory
|
|
3074
|
+
}
|
|
3075
|
+
)
|
|
3076
|
+
}
|
|
3077
|
+
)
|
|
3078
|
+
] }),
|
|
3079
|
+
/* @__PURE__ */ jsx(
|
|
3080
|
+
TableJsonImportModal,
|
|
3081
|
+
{
|
|
3082
|
+
open: tableJson.open,
|
|
3083
|
+
text: tableJson.text,
|
|
3084
|
+
error: tableJson.error,
|
|
3085
|
+
onTextChange: tableJson.setText,
|
|
3086
|
+
onOk: tableJson.handleOk,
|
|
3087
|
+
onCancel: tableJson.closeModal
|
|
3088
|
+
}
|
|
3089
|
+
),
|
|
3090
|
+
/* @__PURE__ */ jsxs(
|
|
3091
|
+
Modal,
|
|
3092
|
+
{
|
|
3093
|
+
title: tr("\u5FC5\u586B\u6821\u9A8C\u9884\u6F14"),
|
|
3094
|
+
width: "80%",
|
|
3095
|
+
open: validation.validationOpen,
|
|
3096
|
+
footer: /* @__PURE__ */ jsxs(Space, { children: [
|
|
3097
|
+
/* @__PURE__ */ jsx(Button, { onClick: validation.closeValidation, children: tr("\u5173\u95ED") }),
|
|
3098
|
+
/* @__PURE__ */ jsx(
|
|
3099
|
+
Button,
|
|
3100
|
+
{
|
|
3101
|
+
type: "primary",
|
|
3102
|
+
icon: /* @__PURE__ */ jsx(AuditOutlined, {}),
|
|
3103
|
+
disabled: !validation.validationEditorReady,
|
|
3104
|
+
onClick: validation.runValidationNow,
|
|
3105
|
+
children: tr("\u7ACB\u5373\u6821\u9A8C")
|
|
3106
|
+
}
|
|
3107
|
+
)
|
|
3108
|
+
] }),
|
|
3109
|
+
destroyOnHidden: true,
|
|
3110
|
+
onCancel: validation.closeValidation,
|
|
3111
|
+
children: [
|
|
3112
|
+
/* @__PURE__ */ jsx("p", { className: styles.validateHint, children: tr(
|
|
3113
|
+
"\u5DF2\u6309\u5F53\u524D\u6A21\u677F\u5957\u7528\u5185\u5BB9\uFF08\u5FC5\u586B\u69FD\u4F4D\u4FDD\u6301\u672A\u586B\u72B6\u6001\uFF09\uFF0C\u70B9\u51FB\u300C\u7ACB\u5373\u6821\u9A8C\u300D\u6267\u884C\u5FC5\u586B\u6821\u9A8C\uFF0C\u672A\u586B\u9879\u5C06\u5217\u51FA\u5E76\u5B9A\u4F4D\u5230\u9996\u4E2A\u672A\u586B\u5757\u3002"
|
|
3114
|
+
) }),
|
|
3115
|
+
build.ok && /* @__PURE__ */ jsx(
|
|
3116
|
+
TemplatePreviewEditor,
|
|
3117
|
+
{
|
|
3118
|
+
definition: build.definition,
|
|
3119
|
+
documentKey: `designer-validate-${current.id.trim()}`,
|
|
3120
|
+
suffix: "rehearsal",
|
|
3121
|
+
minHeight: 400,
|
|
3122
|
+
editorRef: validation.setValidationEditor
|
|
3123
|
+
}
|
|
3124
|
+
)
|
|
3125
|
+
]
|
|
3126
|
+
}
|
|
3127
|
+
)
|
|
3128
|
+
] });
|
|
3129
|
+
}
|
|
3130
|
+
|
|
3131
|
+
// src/editor/features/templatedesigner/examples/headingFixed.example.ts
|
|
3132
|
+
var exampleHeadingFixed = {
|
|
3133
|
+
id: "ir-example-heading-fixed",
|
|
3134
|
+
name: "\u56FA\u5B9A\u6807\u9898\u793A\u4F8B",
|
|
3135
|
+
description: "\u56FA\u5B9A\u6807\u9898\uFF08\u7F6E\u9876\uFF09+ \u56FA\u5B9A\u8BF4\u660E\u6BB5\u843D\uFF08\u542B\u884C\u5185\u53EF\u586B/\u5FC5\u586B\u7A7A\u4F4D\uFF09\u3002",
|
|
3136
|
+
version: "1.0.0",
|
|
3137
|
+
blocks: [
|
|
3138
|
+
{
|
|
3139
|
+
uid: "b1-title",
|
|
3140
|
+
type: "heading",
|
|
3141
|
+
label: "\u62A5\u544A\u6807\u9898",
|
|
3142
|
+
headingLevel: 1,
|
|
3143
|
+
text: "\u68C0\u9A8C\u68C0\u6D4B\u62A5\u544A",
|
|
3144
|
+
isSlot: false,
|
|
3145
|
+
required: false,
|
|
3146
|
+
pin: "top"
|
|
3147
|
+
},
|
|
3148
|
+
{
|
|
3149
|
+
uid: "b2-meta",
|
|
3150
|
+
type: "paragraph",
|
|
3151
|
+
label: "\u62A5\u544A\u4FE1\u606F",
|
|
3152
|
+
text: "\u62A5\u544A\u7F16\u53F7\uFF1A{[\u62A5\u544A\u7F16\u53F7]}\u3000\u59D4\u6258\u5355\u4F4D\uFF1A{{\u59D4\u6258\u5355\u4F4D}}\u3000\u68C0\u6D4B\u65E5\u671F\uFF1A{{\u68C0\u6D4B\u65E5\u671F}}",
|
|
3153
|
+
isSlot: false,
|
|
3154
|
+
required: false
|
|
3155
|
+
}
|
|
3156
|
+
]
|
|
3157
|
+
};
|
|
3158
|
+
|
|
3159
|
+
// src/editor/features/templatedesigner/examples/paragraphSlot.example.ts
|
|
3160
|
+
var exampleParagraphSlot = {
|
|
3161
|
+
id: "ir-example-paragraph-slot",
|
|
3162
|
+
name: "\u6587\u672C\u4E09\u6001\u793A\u4F8B",
|
|
3163
|
+
description: "\u56FA\u5B9A\u6761\u6B3E + \u5FC5\u586B\u5BA1\u6279\u610F\u89C1\u69FD\u4F4D + \u81EA\u7531\u8865\u5145\u6BB5\u843D\u3002",
|
|
3164
|
+
version: "1.0.0",
|
|
3165
|
+
blocks: [
|
|
3166
|
+
{
|
|
3167
|
+
uid: "b1-clause",
|
|
3168
|
+
type: "paragraph",
|
|
3169
|
+
label: "\u56FA\u5B9A\u6761\u6B3E",
|
|
3170
|
+
text: "\u672C\u62A5\u544A\u4F9D\u636E ISO/IEC 17025 \u68C0\u6D4B\u89C4\u7A0B\u51FA\u5177\uFF0C\u672A\u52A0\u76D6\u68C0\u6D4B\u4E13\u7528\u7AE0\u65E0\u6548\u3002",
|
|
3171
|
+
isSlot: false,
|
|
3172
|
+
required: false
|
|
3173
|
+
},
|
|
3174
|
+
{
|
|
3175
|
+
uid: "b2-opinion",
|
|
3176
|
+
type: "paragraph",
|
|
3177
|
+
label: "\u5BA1\u6279\u610F\u89C1",
|
|
3178
|
+
// text 省略时编译器以「请填写<标签>」作占位。
|
|
3179
|
+
isSlot: true,
|
|
3180
|
+
required: true
|
|
3181
|
+
},
|
|
3182
|
+
{
|
|
3183
|
+
uid: "b3-extra",
|
|
3184
|
+
type: "paragraph",
|
|
3185
|
+
label: "\u8865\u5145\u8BF4\u660E",
|
|
3186
|
+
text: "\uFF08\u6B64\u5904\u4E3A\u81EA\u7531\u6BB5\u843D\uFF0C\u586B\u5199\u8005\u53EF\u81EA\u7531\u589E\u5220\u6539\uFF09",
|
|
3187
|
+
isSlot: true,
|
|
3188
|
+
required: false
|
|
3189
|
+
}
|
|
3190
|
+
]
|
|
3191
|
+
};
|
|
3192
|
+
|
|
3193
|
+
// src/editor/features/templatedesigner/examples/imageBlock.example.ts
|
|
3194
|
+
var exampleImageBlock = {
|
|
3195
|
+
id: "ir-example-image-block",
|
|
3196
|
+
name: "\u56FE\u7247\u5757\u793A\u4F8B",
|
|
3197
|
+
description: "\u73B0\u573A\u7167\u7247\u5FC5\u586B\u56FE\u7247\u69FD\u4F4D\u3002",
|
|
3198
|
+
version: "1.0.0",
|
|
3199
|
+
blocks: [
|
|
3200
|
+
{
|
|
3201
|
+
uid: "b1-photo",
|
|
3202
|
+
type: "image",
|
|
3203
|
+
label: "\u73B0\u573A\u7167\u7247",
|
|
3204
|
+
width: 480,
|
|
3205
|
+
height: 320,
|
|
3206
|
+
isSlot: true,
|
|
3207
|
+
required: true
|
|
3208
|
+
}
|
|
3209
|
+
]
|
|
3210
|
+
};
|
|
3211
|
+
|
|
3212
|
+
// src/editor/features/templatedesigner/examples/codeBlock.example.ts
|
|
3213
|
+
var exampleCodeBlock = {
|
|
3214
|
+
id: "ir-example-code-block",
|
|
3215
|
+
name: "\u4EE3\u7801\u5757\u793A\u4F8B",
|
|
3216
|
+
description: "\u793A\u4F8B\u4EE3\u7801\u5FC5\u586B\u69FD\u4F4D\uFF08\u9884\u586B\u63D0\u793A\u6587\u672C\uFF09\u3002",
|
|
3217
|
+
version: "1.0.0",
|
|
3218
|
+
blocks: [
|
|
3219
|
+
{
|
|
3220
|
+
uid: "b1-code",
|
|
3221
|
+
type: "codeBlock",
|
|
3222
|
+
label: "\u793A\u4F8B\u4EE3\u7801",
|
|
3223
|
+
text: `SELECT part_code FROM bom WHERE status = 'released';`,
|
|
3224
|
+
isSlot: true,
|
|
3225
|
+
required: true
|
|
3226
|
+
}
|
|
3227
|
+
]
|
|
3228
|
+
};
|
|
3229
|
+
|
|
3230
|
+
// src/editor/features/templatedesigner/examples/dataTableBasic.example.ts
|
|
3231
|
+
var exampleDataTableBasic = {
|
|
3232
|
+
id: "ir-example-data-table-basic",
|
|
3233
|
+
name: "\u6570\u636E\u8868\u683C\u793A\u4F8B",
|
|
3234
|
+
description: "\u6765\u6599\u68C0\u9A8C\u660E\u7EC6\uFF1A\u6587\u672C\u5217 + \u4E0B\u62C9\u5217 + \u65E5\u671F\u5217\u3002",
|
|
3235
|
+
version: "1.0.0",
|
|
3236
|
+
blocks: [
|
|
3237
|
+
{
|
|
3238
|
+
uid: "b1-detail",
|
|
3239
|
+
type: "table",
|
|
3240
|
+
label: "\u68C0\u9A8C\u660E\u7EC6",
|
|
3241
|
+
tableVariant: "data",
|
|
3242
|
+
isSlot: true,
|
|
3243
|
+
required: true,
|
|
3244
|
+
dataTable: {
|
|
3245
|
+
columns: [
|
|
3246
|
+
{ header: "\u7269\u6599\u7F16\u7801" },
|
|
3247
|
+
{ header: "\u7269\u6599\u540D\u79F0", width: 180 },
|
|
3248
|
+
{ header: "\u5355\u4F4D" },
|
|
3249
|
+
{
|
|
3250
|
+
header: "\u68C0\u9A8C\u7ED3\u679C",
|
|
3251
|
+
fieldType: "select",
|
|
3252
|
+
options: ["\u5408\u683C", "\u4E0D\u5408\u683C", "\u8BA9\u6B65\u63A5\u6536"]
|
|
3253
|
+
},
|
|
3254
|
+
{ header: "\u68C0\u9A8C\u65E5\u671F", fieldType: "date" }
|
|
3255
|
+
],
|
|
3256
|
+
defaultRows: 3
|
|
3257
|
+
}
|
|
3258
|
+
}
|
|
3259
|
+
]
|
|
3260
|
+
};
|
|
3261
|
+
|
|
3262
|
+
// src/editor/features/templatedesigner/examples/dataTableFormula.example.ts
|
|
3263
|
+
var exampleDataTableFormula = {
|
|
3264
|
+
id: "ir-example-data-table-formula",
|
|
3265
|
+
name: "\u6570\u636E\u8868\u683C\u516C\u5F0F\u793A\u4F8B",
|
|
3266
|
+
description: "\u4E24\u884C\u7269\u6599\u9ED8\u8BA4\u6570\u636E\uFF0C\u91D1\u989D\u5217 = \u672C\u884C\u6570\u91CF\xD7\u5355\u4EF7\uFF08\u884C\u5185\u533A\u95F4\u516C\u5F0F\uFF09\uFF0C\u6F14\u793A\u5F15\u53F7\u8F6C\u4E49\u3002",
|
|
3267
|
+
version: "1.0.0",
|
|
3268
|
+
blocks: [
|
|
3269
|
+
{
|
|
3270
|
+
uid: "b1-items",
|
|
3271
|
+
type: "table",
|
|
3272
|
+
label: "\u7269\u6599\u660E\u7EC6",
|
|
3273
|
+
tableVariant: "data",
|
|
3274
|
+
isSlot: true,
|
|
3275
|
+
required: true,
|
|
3276
|
+
dataTable: {
|
|
3277
|
+
columns: [{ header: "\u7269\u6599" }, { header: "\u6570\u91CF" }, { header: "\u5355\u4EF7" }, { header: "\u91D1\u989D\uFF08\u81EA\u52A8\uFF09" }],
|
|
3278
|
+
defaultRows: 2,
|
|
3279
|
+
defaultDataEnabled: true,
|
|
3280
|
+
defaultData: [
|
|
3281
|
+
["\u87BA\u6813 M8\xD730", "10", "0.80", "=SUM(B:B)*SUM(C:C)"],
|
|
3282
|
+
["\u57AB\u7247 \u03A68", "40", '"=0.05"', "=SUM(B:B)*SUM(C:C)"]
|
|
3283
|
+
],
|
|
3284
|
+
// 仅公式列(第 4 列)固定;其余默认格保持可编辑。
|
|
3285
|
+
defaultDataCellFixed: [
|
|
3286
|
+
[false, false, false, true],
|
|
3287
|
+
[false, false, false, true]
|
|
3288
|
+
]
|
|
3289
|
+
}
|
|
3290
|
+
}
|
|
3291
|
+
]
|
|
3292
|
+
};
|
|
3293
|
+
|
|
3294
|
+
// src/editor/features/templatedesigner/examples/formTableBasic.example.ts
|
|
3295
|
+
var LABEL_BG = "#f0f2f5";
|
|
3296
|
+
var exampleFormTableBasic = {
|
|
3297
|
+
id: "ir-example-form-table-basic",
|
|
3298
|
+
name: "\u56FA\u5B9A\u8868\u683C\u793A\u4F8B",
|
|
3299
|
+
description: "\u68C0\u9A8C\u4FE1\u606F\u8868\uFF1A\u6807\u7B7E\u683C + \u5FC5\u586B\u683C + \u4E0B\u62C9\u683C + \u65E5\u671F\u683C\u3002",
|
|
3300
|
+
version: "1.0.0",
|
|
3301
|
+
blocks: [
|
|
3302
|
+
{
|
|
3303
|
+
uid: "b1-form",
|
|
3304
|
+
type: "table",
|
|
3305
|
+
label: "\u68C0\u9A8C\u4FE1\u606F",
|
|
3306
|
+
tableVariant: "form",
|
|
3307
|
+
isSlot: true,
|
|
3308
|
+
required: true,
|
|
3309
|
+
formTable: {
|
|
3310
|
+
rows: [
|
|
3311
|
+
{
|
|
3312
|
+
cells: [
|
|
3313
|
+
{
|
|
3314
|
+
text: "\u68C0\u9A8C\u5458",
|
|
3315
|
+
fillable: false,
|
|
3316
|
+
required: false,
|
|
3317
|
+
bold: true,
|
|
3318
|
+
backgroundColor: LABEL_BG,
|
|
3319
|
+
width: 20,
|
|
3320
|
+
widthUnit: "percent",
|
|
3321
|
+
textAlign: "center"
|
|
3322
|
+
},
|
|
3323
|
+
{ text: "", fillable: true, required: true, width: 30, widthUnit: "percent" },
|
|
3324
|
+
{
|
|
3325
|
+
text: "\u68C0\u9A8C\u65E5\u671F",
|
|
3326
|
+
fillable: false,
|
|
3327
|
+
required: false,
|
|
3328
|
+
bold: true,
|
|
3329
|
+
backgroundColor: LABEL_BG,
|
|
3330
|
+
width: 20,
|
|
3331
|
+
widthUnit: "percent",
|
|
3332
|
+
textAlign: "center"
|
|
3333
|
+
},
|
|
3334
|
+
{ text: "", fillable: true, required: true, fieldType: "date", width: 30, widthUnit: "percent" }
|
|
3335
|
+
]
|
|
3336
|
+
},
|
|
3337
|
+
{
|
|
3338
|
+
cells: [
|
|
3339
|
+
{
|
|
3340
|
+
text: "\u68C0\u9A8C\u7ED3\u8BBA",
|
|
3341
|
+
fillable: false,
|
|
3342
|
+
required: false,
|
|
3343
|
+
bold: true,
|
|
3344
|
+
backgroundColor: LABEL_BG,
|
|
3345
|
+
width: 20,
|
|
3346
|
+
widthUnit: "percent",
|
|
3347
|
+
textAlign: "center"
|
|
3348
|
+
},
|
|
3349
|
+
{
|
|
3350
|
+
text: "",
|
|
3351
|
+
fillable: true,
|
|
3352
|
+
required: false,
|
|
3353
|
+
fieldType: "select",
|
|
3354
|
+
options: ["\u5408\u683C", "\u4E0D\u5408\u683C", "\u8BA9\u6B65\u63A5\u6536"],
|
|
3355
|
+
width: 30,
|
|
3356
|
+
widthUnit: "percent"
|
|
3357
|
+
},
|
|
3358
|
+
{
|
|
3359
|
+
text: "\u5907\u6CE8",
|
|
3360
|
+
fillable: false,
|
|
3361
|
+
required: false,
|
|
3362
|
+
bold: true,
|
|
3363
|
+
backgroundColor: LABEL_BG,
|
|
3364
|
+
width: 20,
|
|
3365
|
+
widthUnit: "percent",
|
|
3366
|
+
textAlign: "center"
|
|
3367
|
+
},
|
|
3368
|
+
{ text: "", fillable: true, required: false, width: 30, widthUnit: "percent" }
|
|
3369
|
+
]
|
|
3370
|
+
}
|
|
3371
|
+
]
|
|
3372
|
+
}
|
|
3373
|
+
}
|
|
3374
|
+
]
|
|
3375
|
+
};
|
|
3376
|
+
|
|
3377
|
+
// src/editor/features/templatedesigner/examples/formTableMerge.example.ts
|
|
3378
|
+
var LABEL_BG2 = "#f0f2f5";
|
|
3379
|
+
var exampleFormTableMerge = {
|
|
3380
|
+
id: "ir-example-form-table-merge",
|
|
3381
|
+
name: "\u56FA\u5B9A\u8868\u683C\u5408\u5E76\u516C\u5F0F\u793A\u4F8B",
|
|
3382
|
+
description: "\u68C0\u6D4B\u9879\u76EE\u7EB5\u5411\u5408\u5E76\u4E24\u884C\uFF0C\u6362\u7B97\u503C\u5217\u516C\u5F0F\u5F15\u7528\u672C\u884C\u8F93\u5165\u683C\uFF0C\u672B\u884C\u6C42\u548C\u4E24\u4E2A\u6362\u7B97\u503C\u683C\u3002",
|
|
3383
|
+
version: "1.0.0",
|
|
3384
|
+
blocks: [
|
|
3385
|
+
{
|
|
3386
|
+
uid: "b1-form",
|
|
3387
|
+
type: "table",
|
|
3388
|
+
label: "\u68C0\u6D4B\u8BB0\u5F55",
|
|
3389
|
+
tableVariant: "form",
|
|
3390
|
+
isSlot: true,
|
|
3391
|
+
required: true,
|
|
3392
|
+
formTable: {
|
|
3393
|
+
rows: [
|
|
3394
|
+
{
|
|
3395
|
+
cells: [
|
|
3396
|
+
{
|
|
3397
|
+
text: "\u68C0\u6D4B\u9879\u76EE",
|
|
3398
|
+
fillable: false,
|
|
3399
|
+
required: false,
|
|
3400
|
+
bold: true,
|
|
3401
|
+
backgroundColor: LABEL_BG2,
|
|
3402
|
+
width: 30,
|
|
3403
|
+
widthUnit: "percent",
|
|
3404
|
+
textAlign: "center",
|
|
3405
|
+
rowspan: 2
|
|
3406
|
+
},
|
|
3407
|
+
{
|
|
3408
|
+
text: "\u6570\u503C",
|
|
3409
|
+
fillable: false,
|
|
3410
|
+
required: false,
|
|
3411
|
+
bold: true,
|
|
3412
|
+
backgroundColor: LABEL_BG2,
|
|
3413
|
+
width: 35,
|
|
3414
|
+
widthUnit: "percent",
|
|
3415
|
+
textAlign: "center"
|
|
3416
|
+
},
|
|
3417
|
+
{
|
|
3418
|
+
text: "\u6362\u7B97\u503C",
|
|
3419
|
+
fillable: false,
|
|
3420
|
+
required: false,
|
|
3421
|
+
bold: true,
|
|
3422
|
+
backgroundColor: LABEL_BG2,
|
|
3423
|
+
width: 35,
|
|
3424
|
+
widthUnit: "percent",
|
|
3425
|
+
textAlign: "center"
|
|
3426
|
+
}
|
|
3427
|
+
]
|
|
3428
|
+
},
|
|
3429
|
+
{
|
|
3430
|
+
cells: [
|
|
3431
|
+
{ text: "", fillable: false, required: false, covered: true, width: 30, widthUnit: "percent" },
|
|
3432
|
+
{ text: "", fillable: true, required: true, width: 35, widthUnit: "percent" },
|
|
3433
|
+
{
|
|
3434
|
+
text: "",
|
|
3435
|
+
fillable: false,
|
|
3436
|
+
required: false,
|
|
3437
|
+
fieldType: "formula",
|
|
3438
|
+
formula: "=R2C1*10",
|
|
3439
|
+
width: 35,
|
|
3440
|
+
widthUnit: "percent",
|
|
3441
|
+
textAlign: "right"
|
|
3442
|
+
}
|
|
3443
|
+
]
|
|
3444
|
+
},
|
|
3445
|
+
{
|
|
3446
|
+
cells: [
|
|
3447
|
+
{
|
|
3448
|
+
text: "\u590D\u6838\u503C",
|
|
3449
|
+
fillable: false,
|
|
3450
|
+
required: false,
|
|
3451
|
+
bold: true,
|
|
3452
|
+
backgroundColor: LABEL_BG2,
|
|
3453
|
+
width: 30,
|
|
3454
|
+
widthUnit: "percent",
|
|
3455
|
+
textAlign: "center"
|
|
3456
|
+
},
|
|
3457
|
+
{ text: "", fillable: true, required: false, width: 35, widthUnit: "percent" },
|
|
3458
|
+
{
|
|
3459
|
+
text: "",
|
|
3460
|
+
fillable: false,
|
|
3461
|
+
required: false,
|
|
3462
|
+
fieldType: "formula",
|
|
3463
|
+
formula: "=R3C2*10",
|
|
3464
|
+
width: 35,
|
|
3465
|
+
widthUnit: "percent",
|
|
3466
|
+
textAlign: "right"
|
|
3467
|
+
}
|
|
3468
|
+
]
|
|
3469
|
+
},
|
|
3470
|
+
{
|
|
3471
|
+
cells: [
|
|
3472
|
+
{
|
|
3473
|
+
text: "\u6362\u7B97\u5408\u8BA1",
|
|
3474
|
+
fillable: false,
|
|
3475
|
+
required: false,
|
|
3476
|
+
bold: true,
|
|
3477
|
+
backgroundColor: LABEL_BG2,
|
|
3478
|
+
width: 30,
|
|
3479
|
+
widthUnit: "percent",
|
|
3480
|
+
textAlign: "center"
|
|
3481
|
+
},
|
|
3482
|
+
{ text: "\u2014", fillable: false, required: false, width: 35, widthUnit: "percent", textAlign: "center" },
|
|
3483
|
+
{
|
|
3484
|
+
text: "",
|
|
3485
|
+
fillable: false,
|
|
3486
|
+
required: false,
|
|
3487
|
+
fieldType: "formula",
|
|
3488
|
+
formula: "=R2C2+R3C3",
|
|
3489
|
+
width: 35,
|
|
3490
|
+
widthUnit: "percent",
|
|
3491
|
+
textAlign: "right"
|
|
3492
|
+
}
|
|
3493
|
+
]
|
|
3494
|
+
}
|
|
3495
|
+
]
|
|
3496
|
+
}
|
|
3497
|
+
}
|
|
3498
|
+
]
|
|
3499
|
+
};
|
|
3500
|
+
|
|
3501
|
+
// src/editor/features/templatedesigner/examples/structureGating.example.ts
|
|
3502
|
+
var exampleStructureGating = {
|
|
3503
|
+
id: "ir-example-structure-gating",
|
|
3504
|
+
name: "\u7ED3\u6784\u95E8\u63A7\u793A\u4F8B",
|
|
3505
|
+
description: "\u7F6E\u9876\u6807\u9898 + \u504F\u5E8F\u7EA6\u675F\u7684\u5FC5\u586B\u6BB5\u843D + \u81EA\u7531\u6BB5\u843D + \u7F6E\u5E95\u7B7E\u7F72\u7EC4\u3002",
|
|
3506
|
+
version: "1.0.0",
|
|
3507
|
+
blocks: [
|
|
3508
|
+
{
|
|
3509
|
+
uid: "b1-title",
|
|
3510
|
+
type: "heading",
|
|
3511
|
+
label: "\u5236\u5EA6\u6807\u9898",
|
|
3512
|
+
headingLevel: 1,
|
|
3513
|
+
text: "\u6837\u54C1\u7BA1\u7406\u5236\u5EA6",
|
|
3514
|
+
isSlot: false,
|
|
3515
|
+
required: false,
|
|
3516
|
+
pin: "top"
|
|
3517
|
+
},
|
|
3518
|
+
{
|
|
3519
|
+
uid: "b2-scope",
|
|
3520
|
+
type: "paragraph",
|
|
3521
|
+
label: "\u9002\u7528\u8303\u56F4",
|
|
3522
|
+
isSlot: true,
|
|
3523
|
+
required: true,
|
|
3524
|
+
// 本块必须位于标题之下(偏序;中间可插入其它块)。
|
|
3525
|
+
after: ["b1-title"]
|
|
3526
|
+
},
|
|
3527
|
+
{
|
|
3528
|
+
uid: "b3-note",
|
|
3529
|
+
type: "paragraph",
|
|
3530
|
+
label: "\u81EA\u7531\u8BF4\u660E",
|
|
3531
|
+
text: "\uFF08\u81EA\u7531\u6BB5\u843D\uFF1A\u586B\u5199\u8005\u53EF\u589E\u5220\u6539\uFF0C\u4E0D\u53C2\u4E0E\u7ED3\u6784\u4FDD\u62A4\uFF09",
|
|
3532
|
+
isSlot: true,
|
|
3533
|
+
required: false
|
|
3534
|
+
},
|
|
3535
|
+
{
|
|
3536
|
+
uid: "b4-approver",
|
|
3537
|
+
type: "paragraph",
|
|
3538
|
+
label: "\u6279\u51C6\u7B7E\u7F72",
|
|
3539
|
+
text: "\u6279\u51C6\uFF1A{[\u6279\u51C6\u4EBA]}",
|
|
3540
|
+
isSlot: false,
|
|
3541
|
+
required: false,
|
|
3542
|
+
pin: "bottom",
|
|
3543
|
+
groupId: "g-sign",
|
|
3544
|
+
groupLabel: "\u7B7E\u7F72\u533A"
|
|
3545
|
+
},
|
|
3546
|
+
{
|
|
3547
|
+
uid: "b5-date",
|
|
3548
|
+
type: "paragraph",
|
|
3549
|
+
label: "\u751F\u6548\u65E5\u671F",
|
|
3550
|
+
text: "\u751F\u6548\u65E5\u671F\uFF1A{[\u751F\u6548\u65E5\u671F]}",
|
|
3551
|
+
isSlot: false,
|
|
3552
|
+
required: false,
|
|
3553
|
+
pin: "bottom",
|
|
3554
|
+
groupId: "g-sign",
|
|
3555
|
+
groupLabel: "\u7B7E\u7F72\u533A"
|
|
3556
|
+
}
|
|
3557
|
+
]
|
|
3558
|
+
};
|
|
3559
|
+
|
|
3560
|
+
// src/editor/features/templatedesigner/examples/fullDocument.example.ts
|
|
3561
|
+
var LABEL_BG3 = "#f0f2f5";
|
|
3562
|
+
var exampleFullDocument = {
|
|
3563
|
+
id: "ir-example-full-document",
|
|
3564
|
+
name: "\u8BBE\u5907\u70B9\u68C0\u8BB0\u5F55\u8868",
|
|
3565
|
+
description: "\u6574\u6A21\u677F\u7EC4\u5408\u793A\u4F8B\uFF1A\u6807\u9898/\u884C\u5185\u4FE1\u606F/\u8BBE\u5907\u4FE1\u606F\u56FA\u5B9A\u8868/\u70B9\u68C0\u660E\u7EC6\u6570\u636E\u8868/\u7167\u7247/\u7B7E\u7F72\u7EC4\u3002",
|
|
3566
|
+
version: "1.0.0",
|
|
3567
|
+
blocks: [
|
|
3568
|
+
{
|
|
3569
|
+
uid: "b1-title",
|
|
3570
|
+
type: "heading",
|
|
3571
|
+
label: "\u8868\u5355\u6807\u9898",
|
|
3572
|
+
headingLevel: 1,
|
|
3573
|
+
text: "\u8BBE\u5907\u70B9\u68C0\u8BB0\u5F55\u8868",
|
|
3574
|
+
isSlot: false,
|
|
3575
|
+
required: false,
|
|
3576
|
+
pin: "top"
|
|
3577
|
+
},
|
|
3578
|
+
{
|
|
3579
|
+
uid: "b2-meta",
|
|
3580
|
+
type: "paragraph",
|
|
3581
|
+
label: "\u57FA\u672C\u4FE1\u606F",
|
|
3582
|
+
text: "\u8BBE\u5907\u7F16\u53F7\uFF1A{[\u8BBE\u5907\u7F16\u53F7]}\u3000\u70B9\u68C0\u65E5\u671F\uFF1A{[\u70B9\u68C0\u65E5\u671F]}\u3000\u73ED\u6B21\uFF1A{{\u73ED\u6B21}}",
|
|
3583
|
+
isSlot: false,
|
|
3584
|
+
required: false
|
|
3585
|
+
},
|
|
3586
|
+
{
|
|
3587
|
+
uid: "b3-purpose",
|
|
3588
|
+
type: "paragraph",
|
|
3589
|
+
label: "\u70B9\u68C0\u76EE\u7684",
|
|
3590
|
+
isSlot: true,
|
|
3591
|
+
required: true
|
|
3592
|
+
},
|
|
3593
|
+
{
|
|
3594
|
+
uid: "b4-device-form",
|
|
3595
|
+
type: "table",
|
|
3596
|
+
label: "\u8BBE\u5907\u4FE1\u606F",
|
|
3597
|
+
tableVariant: "form",
|
|
3598
|
+
isSlot: true,
|
|
3599
|
+
required: false,
|
|
3600
|
+
formTable: {
|
|
3601
|
+
rows: [
|
|
3602
|
+
{
|
|
3603
|
+
cells: [
|
|
3604
|
+
{
|
|
3605
|
+
text: "\u8BBE\u5907\u540D\u79F0",
|
|
3606
|
+
fillable: false,
|
|
3607
|
+
required: false,
|
|
3608
|
+
bold: true,
|
|
3609
|
+
backgroundColor: LABEL_BG3,
|
|
3610
|
+
width: 25,
|
|
3611
|
+
widthUnit: "percent",
|
|
3612
|
+
textAlign: "center"
|
|
3613
|
+
},
|
|
3614
|
+
{ text: "", fillable: true, required: true, width: 75, widthUnit: "percent" }
|
|
3615
|
+
]
|
|
3616
|
+
},
|
|
3617
|
+
{
|
|
3618
|
+
cells: [
|
|
3619
|
+
{
|
|
3620
|
+
text: "\u89C4\u683C\u578B\u53F7",
|
|
3621
|
+
fillable: false,
|
|
3622
|
+
required: false,
|
|
3623
|
+
bold: true,
|
|
3624
|
+
backgroundColor: LABEL_BG3,
|
|
3625
|
+
width: 25,
|
|
3626
|
+
widthUnit: "percent",
|
|
3627
|
+
textAlign: "center"
|
|
3628
|
+
},
|
|
3629
|
+
{ text: "", fillable: true, required: false, width: 75, widthUnit: "percent" }
|
|
3630
|
+
]
|
|
3631
|
+
},
|
|
3632
|
+
{
|
|
3633
|
+
cells: [
|
|
3634
|
+
{
|
|
3635
|
+
text: "\u5B89\u88C5\u4F4D\u7F6E",
|
|
3636
|
+
fillable: false,
|
|
3637
|
+
required: false,
|
|
3638
|
+
bold: true,
|
|
3639
|
+
backgroundColor: LABEL_BG3,
|
|
3640
|
+
width: 25,
|
|
3641
|
+
widthUnit: "percent",
|
|
3642
|
+
textAlign: "center"
|
|
3643
|
+
},
|
|
3644
|
+
{ text: "", fillable: true, required: false, width: 75, widthUnit: "percent" }
|
|
3645
|
+
]
|
|
3646
|
+
}
|
|
3647
|
+
]
|
|
3648
|
+
}
|
|
3649
|
+
},
|
|
3650
|
+
{
|
|
3651
|
+
uid: "b5-check-data",
|
|
3652
|
+
type: "table",
|
|
3653
|
+
label: "\u70B9\u68C0\u660E\u7EC6",
|
|
3654
|
+
tableVariant: "data",
|
|
3655
|
+
isSlot: true,
|
|
3656
|
+
required: true,
|
|
3657
|
+
dataTable: {
|
|
3658
|
+
columns: [
|
|
3659
|
+
{ header: "\u70B9\u68C0\u9879\u76EE", width: 160 },
|
|
3660
|
+
{ header: "\u70B9\u68C0\u6807\u51C6", width: 120 },
|
|
3661
|
+
{ header: "\u5224\u5B9A", fieldType: "select", options: ["\u6B63\u5E38", "\u5F02\u5E38"] },
|
|
3662
|
+
{ header: "\u5907\u6CE8" }
|
|
3663
|
+
],
|
|
3664
|
+
defaultRows: 4
|
|
3665
|
+
}
|
|
3666
|
+
},
|
|
3667
|
+
{
|
|
3668
|
+
uid: "b6-photo",
|
|
3669
|
+
type: "image",
|
|
3670
|
+
label: "\u73B0\u573A\u7167\u7247",
|
|
3671
|
+
width: 480,
|
|
3672
|
+
height: 320,
|
|
3673
|
+
isSlot: true,
|
|
3674
|
+
required: true
|
|
3675
|
+
},
|
|
3676
|
+
{
|
|
3677
|
+
uid: "b7-extra",
|
|
3678
|
+
type: "paragraph",
|
|
3679
|
+
label: "\u9644\u52A0\u8BF4\u660E",
|
|
3680
|
+
text: "\u9644\u52A0\u8BF4\u660E\uFF08\u53EF\u81EA\u7531\u589E\u5220\uFF09\uFF1A",
|
|
3681
|
+
isSlot: true,
|
|
3682
|
+
required: false
|
|
3683
|
+
},
|
|
3684
|
+
{
|
|
3685
|
+
uid: "b8-maker",
|
|
3686
|
+
type: "paragraph",
|
|
3687
|
+
label: "\u7F16\u5236\u7B7E\u7F72",
|
|
3688
|
+
text: "\u7F16\u5236\uFF1A{[\u7F16\u5236\u4EBA]}",
|
|
3689
|
+
isSlot: false,
|
|
3690
|
+
required: false,
|
|
3691
|
+
pin: "bottom",
|
|
3692
|
+
groupId: "g-sign",
|
|
3693
|
+
groupLabel: "\u7B7E\u7F72\u533A"
|
|
3694
|
+
},
|
|
3695
|
+
{
|
|
3696
|
+
uid: "b9-checker",
|
|
3697
|
+
type: "paragraph",
|
|
3698
|
+
label: "\u5BA1\u6838\u7B7E\u7F72",
|
|
3699
|
+
text: "\u5BA1\u6838\uFF1A{[\u5BA1\u6838\u4EBA]}",
|
|
3700
|
+
isSlot: false,
|
|
3701
|
+
required: false,
|
|
3702
|
+
pin: "bottom",
|
|
3703
|
+
groupId: "g-sign",
|
|
3704
|
+
groupLabel: "\u7B7E\u7F72\u533A"
|
|
3705
|
+
}
|
|
3706
|
+
]
|
|
3707
|
+
};
|
|
3708
|
+
|
|
3709
|
+
// src/editor/features/templatedesigner/examples/customBlock.example.ts
|
|
3710
|
+
var exampleCustomBlock = {
|
|
3711
|
+
id: "ir-example-custom-block",
|
|
3712
|
+
name: "\u81EA\u5B9A\u4E49\u5757\u793A\u4F8B",
|
|
3713
|
+
description: "\u4E1A\u52A1\u81EA\u5B9A\u4E49\u300C\u5173\u8054\u7269\u6599\u300D\u5757\uFF1A\u4E13\u6709\u6570\u636E\u843D\u5728 data \u69FD\u4F4D\u3002",
|
|
3714
|
+
version: "1.0.0",
|
|
3715
|
+
blocks: [
|
|
3716
|
+
{
|
|
3717
|
+
uid: "b1-intro",
|
|
3718
|
+
type: "paragraph",
|
|
3719
|
+
label: "\u56FA\u5B9A\u8BF4\u660E",
|
|
3720
|
+
text: "\u8BF7\u4ECE\u7269\u6599\u5E93\u9009\u62E9\u672C\u5355\u5173\u8054\u7684\u7269\u6599\uFF1A",
|
|
3721
|
+
isSlot: false,
|
|
3722
|
+
required: false
|
|
3723
|
+
},
|
|
3724
|
+
{
|
|
3725
|
+
uid: "b2-ref",
|
|
3726
|
+
type: "demoReference",
|
|
3727
|
+
label: "\u5173\u8054\u7269\u6599",
|
|
3728
|
+
isSlot: true,
|
|
3729
|
+
required: true,
|
|
3730
|
+
data: {
|
|
3731
|
+
mode: "tree",
|
|
3732
|
+
maxCount: 5,
|
|
3733
|
+
onlyReleased: true
|
|
3734
|
+
}
|
|
3735
|
+
}
|
|
3736
|
+
]
|
|
3737
|
+
};
|
|
3738
|
+
|
|
3739
|
+
// src/editor/features/templatedesigner/examples/dataBinding.example.ts
|
|
3740
|
+
var exampleDataBinding = {
|
|
3741
|
+
id: "ir-example-data-binding",
|
|
3742
|
+
name: "\u91C7\u8D2D\u5408\u540C\uFF08\u540E\u7AEF\u53D8\u91CF\uFF09",
|
|
3743
|
+
description: "\u6587\u672C\u591A\u53D8\u91CF\u3001\u56FA\u5B9A\u8868\u683C\u6807\u91CF\u7ED1\u5B9A\u3001\u6570\u636E\u8868\u683C\u6570\u7EC4\u4E0E\u5217\u5B57\u6BB5\u7ED1\u5B9A\uFF08\u4E00\u6B21\u54CD\u5E94\u542B\u591A\u4E2A\u6570\u7EC4\uFF0C\u591A\u4E2A\u6570\u636E\u8868\u683C\u5404\u7ED1\u5404\u7684\u6570\u7EC4\uFF09\u3002",
|
|
3744
|
+
version: "1.0.0",
|
|
3745
|
+
dataSource: "demo-contract",
|
|
3746
|
+
blocks: [
|
|
3747
|
+
{
|
|
3748
|
+
uid: "b1-text",
|
|
3749
|
+
type: "paragraph",
|
|
3750
|
+
label: "\u5408\u540C\u4FE1\u606F",
|
|
3751
|
+
text: "\u5408\u540C\u53F7\uFF1A[[@contractNo]]\uFF1B\u5BA2\u6237\uFF1A[[@customer.name]]\uFF1B\u542F\u7528\uFF1A[[@enabled]]\uFF1B\u5907\u6CE8\uFF1A[[@optional]]\uFF1B{{\u8865\u5145\u8BF4\u660E}}",
|
|
3752
|
+
isSlot: false,
|
|
3753
|
+
required: false
|
|
3754
|
+
},
|
|
3755
|
+
{
|
|
3756
|
+
uid: "b2-form",
|
|
3757
|
+
type: "table",
|
|
3758
|
+
label: "\u5BA2\u6237\u4FE1\u606F",
|
|
3759
|
+
tableVariant: "form",
|
|
3760
|
+
isSlot: true,
|
|
3761
|
+
required: false,
|
|
3762
|
+
formTable: {
|
|
3763
|
+
rows: [
|
|
3764
|
+
{
|
|
3765
|
+
cells: [
|
|
3766
|
+
{ text: "\u5BA2\u6237\u540D\u79F0", fillable: false, required: false, bold: true, width: 25, widthUnit: "percent" },
|
|
3767
|
+
{ text: "", binding: "customer.name", fillable: false, required: false, width: 75, widthUnit: "percent" }
|
|
3768
|
+
]
|
|
3769
|
+
}
|
|
3770
|
+
]
|
|
3771
|
+
}
|
|
3772
|
+
},
|
|
3773
|
+
{
|
|
3774
|
+
uid: "b3-items",
|
|
3775
|
+
type: "table",
|
|
3776
|
+
label: "\u91C7\u8D2D\u660E\u7EC6",
|
|
3777
|
+
tableVariant: "data",
|
|
3778
|
+
isSlot: true,
|
|
3779
|
+
required: false,
|
|
3780
|
+
dataTable: {
|
|
3781
|
+
binding: "items",
|
|
3782
|
+
columns: [{ header: "\u4EA7\u54C1", binding: "name" }, { header: "\u6570\u91CF", binding: "quantity" }, { header: "\u5907\u6CE8" }],
|
|
3783
|
+
defaultRows: 1,
|
|
3784
|
+
defaultDataEnabled: true,
|
|
3785
|
+
defaultData: [["", "", "\u672A\u7ED1\u5B9A\u5217\u4FDD\u7559"]],
|
|
3786
|
+
defaultDataCellFixed: [[false, false, false]]
|
|
3787
|
+
}
|
|
3788
|
+
},
|
|
3789
|
+
{
|
|
3790
|
+
uid: "b4-payments",
|
|
3791
|
+
type: "table",
|
|
3792
|
+
label: "\u4ED8\u6B3E\u8BA1\u5212",
|
|
3793
|
+
tableVariant: "data",
|
|
3794
|
+
isSlot: true,
|
|
3795
|
+
required: false,
|
|
3796
|
+
dataTable: {
|
|
3797
|
+
binding: "payments",
|
|
3798
|
+
columns: [{ header: "\u9636\u6BB5", binding: "stage" }, { header: "\u6BD4\u4F8B", binding: "ratio" }, { header: "\u5907\u6CE8" }],
|
|
3799
|
+
defaultRows: 1,
|
|
3800
|
+
defaultDataEnabled: true,
|
|
3801
|
+
defaultData: [["", "", "\u5F85\u8865\u5145"]],
|
|
3802
|
+
defaultDataCellFixed: [[false, false, false]]
|
|
3803
|
+
}
|
|
3804
|
+
}
|
|
3805
|
+
]
|
|
3806
|
+
};
|
|
3807
|
+
var exampleDataBindingPayload = {
|
|
3808
|
+
contractNo: "HT-2026-001",
|
|
3809
|
+
customer: { name: "\u793A\u4F8B\u5BA2\u6237\u6709\u9650\u516C\u53F8" },
|
|
3810
|
+
enabled: true,
|
|
3811
|
+
optional: null,
|
|
3812
|
+
items: [
|
|
3813
|
+
{ name: "\u7F16\u8F91\u5668\u6388\u6743", quantity: 2 },
|
|
3814
|
+
{ name: "\u5B9E\u65BD\u670D\u52A1", quantity: 1 }
|
|
3815
|
+
],
|
|
3816
|
+
payments: [
|
|
3817
|
+
{ stage: "\u9884\u4ED8\u6B3E", ratio: 30 },
|
|
3818
|
+
{ stage: "\u5C3E\u6B3E", ratio: 70 }
|
|
3819
|
+
]
|
|
3820
|
+
};
|
|
3821
|
+
|
|
3822
|
+
// src/editor/features/templatedesigner/examples/index.ts
|
|
3823
|
+
var IR_EXAMPLES = [
|
|
3824
|
+
{
|
|
3825
|
+
id: exampleHeadingFixed.id,
|
|
3826
|
+
description: "\u56FA\u5B9A\u6807\u9898\uFF08\u7F6E\u9876\uFF09+ \u56FA\u5B9A\u6BB5\u843D\uFF08{{\u53EF\u586B}}/{[\u5FC5\u586B]} \u884C\u5185\u69FD\uFF09",
|
|
3827
|
+
template: exampleHeadingFixed,
|
|
3828
|
+
covers: ["heading", "paragraph"]
|
|
3829
|
+
},
|
|
3830
|
+
{
|
|
3831
|
+
id: exampleParagraphSlot.id,
|
|
3832
|
+
description: "\u6587\u672C\u4E09\u6001\uFF1A\u56FA\u5B9A\u5757 / \u5FC5\u586B\u69FD\u4F4D / \u81EA\u7531\u5757",
|
|
3833
|
+
template: exampleParagraphSlot,
|
|
3834
|
+
covers: ["paragraph"]
|
|
3835
|
+
},
|
|
3836
|
+
{
|
|
3837
|
+
id: exampleImageBlock.id,
|
|
3838
|
+
description: "\u56FE\u7247\u5FC5\u586B\u69FD\u4F4D\u4E0E\u5360\u4F4D\u5C3A\u5BF8",
|
|
3839
|
+
template: exampleImageBlock,
|
|
3840
|
+
covers: ["image"]
|
|
3841
|
+
},
|
|
3842
|
+
{
|
|
3843
|
+
id: exampleCodeBlock.id,
|
|
3844
|
+
description: "\u4EE3\u7801\u5757\u69FD\u4F4D\u4E0E\u9884\u586B\u63D0\u793A\u6587\u672C",
|
|
3845
|
+
template: exampleCodeBlock,
|
|
3846
|
+
covers: ["codeBlock"]
|
|
3847
|
+
},
|
|
3848
|
+
{
|
|
3849
|
+
id: exampleDataTableBasic.id,
|
|
3850
|
+
description: "\u6570\u636E\u8868\u683C\uFF1A\u5217\u63A7\u4EF6 select/date\u3001\u9ED8\u8BA4\u884C\u6570",
|
|
3851
|
+
template: exampleDataTableBasic,
|
|
3852
|
+
covers: ["table"]
|
|
3853
|
+
},
|
|
3854
|
+
{
|
|
3855
|
+
id: exampleDataTableFormula.id,
|
|
3856
|
+
description: "\u6570\u636E\u8868\u683C\uFF1A\u9ED8\u8BA4\u6570\u636E\u77E9\u9635\u3001\u5217\u65B9\u8A00\u516C\u5F0F\u683C\u3001\u5F15\u53F7\u8F6C\u4E49",
|
|
3857
|
+
template: exampleDataTableFormula,
|
|
3858
|
+
covers: ["table"]
|
|
3859
|
+
},
|
|
3860
|
+
{
|
|
3861
|
+
id: exampleFormTableBasic.id,
|
|
3862
|
+
description: "\u56FA\u5B9A\u8868\u683C\uFF1A\u6807\u7B7E\u683C/\u53EF\u586B\u683C/\u4E0B\u62C9\u683C/\u65E5\u671F\u683C\u4E0E\u884C\u5BBD\u51D1\u6EE1",
|
|
3863
|
+
template: exampleFormTableBasic,
|
|
3864
|
+
covers: ["table"]
|
|
3865
|
+
},
|
|
3866
|
+
{
|
|
3867
|
+
id: exampleFormTableMerge.id,
|
|
3868
|
+
description: "\u56FA\u5B9A\u8868\u683C\uFF1Arowspan+covered \u7EB5\u5411\u5408\u5E76\u3001R/C \u516C\u5F0F\u4E0E\u533A\u95F4\u6C42\u548C",
|
|
3869
|
+
template: exampleFormTableMerge,
|
|
3870
|
+
covers: ["table"]
|
|
3871
|
+
},
|
|
3872
|
+
{
|
|
3873
|
+
id: exampleStructureGating.id,
|
|
3874
|
+
description: "\u7ED3\u6784\u95E8\u63A7\uFF1Apin \u7F6E\u9876\u7F6E\u5E95\u3001after \u504F\u5E8F\u3001\u540C\u7EC4\u540C pin \u7B7E\u7F72\u7EC4",
|
|
3875
|
+
template: exampleStructureGating,
|
|
3876
|
+
covers: ["heading", "paragraph"]
|
|
3877
|
+
},
|
|
3878
|
+
{
|
|
3879
|
+
id: exampleFullDocument.id,
|
|
3880
|
+
description: "\u6574\u6A21\u677F\u7EC4\u5408\uFF1A\u4E94\u79CD\u5185\u7F6E\u5757\u578B\u4E2D\u7684\u56DB\u79CD + \u5206\u533A\u6392\u7248\u7684\u5B8C\u6574\u8868\u5355\uFF08codeBlock \u89C1 codeBlock.example\uFF09",
|
|
3881
|
+
template: exampleFullDocument,
|
|
3882
|
+
covers: ["heading", "paragraph", "image", "table"]
|
|
3883
|
+
},
|
|
3884
|
+
{
|
|
3885
|
+
id: exampleCustomBlock.id,
|
|
3886
|
+
description: "\u81EA\u5B9A\u4E49\u5757\uFF1A\u4E13\u6709\u6570\u636E\u843D data \u69FD\u4F4D\uFF08stub \u6CE8\u518C\u89C1 verifyTemplates.ts\uFF09",
|
|
3887
|
+
template: exampleCustomBlock,
|
|
3888
|
+
covers: ["demoReference"]
|
|
3889
|
+
},
|
|
3890
|
+
{
|
|
3891
|
+
id: exampleDataBinding.id,
|
|
3892
|
+
description: "\u540E\u7AEF\u53D8\u91CF\uFF1A\u6587\u672C\u6DF7\u6392\u3001\u56FA\u5B9A\u8868\u683C\u6807\u91CF\u3001\u6570\u636E\u8868\u683C\u6570\u7EC4\u884C\u6620\u5C04",
|
|
3893
|
+
template: exampleDataBinding,
|
|
3894
|
+
data: exampleDataBindingPayload,
|
|
3895
|
+
covers: ["paragraph", "table"]
|
|
3896
|
+
}
|
|
3897
|
+
];
|
|
3898
|
+
function coveredBlockTypes() {
|
|
3899
|
+
return [...new Set(IR_EXAMPLES.flatMap((entry) => entry.covers))];
|
|
3900
|
+
}
|
|
3901
|
+
function TemplateHistoryDrawer(props) {
|
|
3902
|
+
const { open, onClose, onRestore, ...panelProps } = props;
|
|
3903
|
+
return /* @__PURE__ */ jsx(Drawer, { width: 480, title: tr("\u5386\u53F2\u7248\u672C"), open, onClose, footer: false, children: open && /* @__PURE__ */ jsx(
|
|
3904
|
+
TemplateHistoryPanel,
|
|
3905
|
+
{
|
|
3906
|
+
...panelProps,
|
|
3907
|
+
onRestore: (entry) => {
|
|
3908
|
+
onRestore(entry);
|
|
3909
|
+
onClose();
|
|
3910
|
+
}
|
|
3911
|
+
}
|
|
3912
|
+
) });
|
|
3913
|
+
}
|
|
3914
|
+
|
|
3915
|
+
export { BlockOutline, IR_EXAMPLES, TemplateDesigner, TemplateHistoryDrawer, TemplateHistoryPanel, TemplatePreviewEditor, coveredBlockTypes, exportTemplate, hashDesignerTemplate, importTemplateFile, isDesignerTemplate, useTemplateDraftHistory };
|
|
3916
|
+
//# sourceMappingURL=chunk-TOA6CRSJ.mjs.map
|
|
3917
|
+
//# sourceMappingURL=chunk-TOA6CRSJ.mjs.map
|