@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,4024 @@
|
|
|
1
|
+
import { BLOCK_TYPES, TEMPLATE_IR_STRICT_SCHEMA, DEFAULT_FORM_ROW_HEIGHT, validateIrAgainstSchema, normalizeDesignerTemplate, validateBlockStructure, buildDefinition, parseTableJson, createBlockFromPalette, cellRowspan, splitRowspan, canMergeDown, mergeDown, normalizeTableBlock, MAX_DATA_TABLE_ROWS, isFreeDesignerBlock, applyPin, setOrderConstraints, joinGroup, groupDisplayLabel, leaveGroup, fillableCell, fixedCell } from './chunk-IICCIMZU.mjs';
|
|
2
|
+
import { locateBlockNode } from './chunk-BBZ5ZBEK.mjs';
|
|
3
|
+
import { normalizeFixedTableBackgroundColor, readFixedCellControl, headerControlForCol } from './chunk-K7Z56Q4M.mjs';
|
|
4
|
+
import { finalizeSvgRoot } from './chunk-ZM3WULHX.mjs';
|
|
5
|
+
import { sanitizeHtml, decodeSvgDataUri } from './chunk-4W6PPBHQ.mjs';
|
|
6
|
+
import { readTemplateBlockMeta, getProtectedContentNode } from './chunk-EOUNN3NA.mjs';
|
|
7
|
+
import { tr } from './chunk-W627LLF4.mjs';
|
|
8
|
+
import { genId } from './chunk-CREU4TZJ.mjs';
|
|
9
|
+
import { TableMap } from '@tiptap/pm/tables';
|
|
10
|
+
|
|
11
|
+
// src/editor/copilot/utils/result.ts
|
|
12
|
+
var ok = (message, data, opts) => ({
|
|
13
|
+
status: "success" /* Success */,
|
|
14
|
+
// get_status 双约定:底层 CopilotExecutor 自动附带页面状态时按 success 布尔判定
|
|
15
|
+
// (见 CopilotExecutor.getPageStatus),get_status 场景传 successFlag: true 一并带上。
|
|
16
|
+
...opts?.successFlag ? { success: true } : null,
|
|
17
|
+
message,
|
|
18
|
+
data
|
|
19
|
+
});
|
|
20
|
+
var fail = (message, data) => ({
|
|
21
|
+
status: "error" /* Error */,
|
|
22
|
+
message,
|
|
23
|
+
data
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// src/editor/copilot/utils/guards.ts
|
|
27
|
+
function resolveEditor(context) {
|
|
28
|
+
const editor = context.editorRef.current;
|
|
29
|
+
if (!editor) {
|
|
30
|
+
return { ok: false, result: fail(tr("\u7F16\u8F91\u5668\u5C1A\u672A\u5C31\u7EEA\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5")) };
|
|
31
|
+
}
|
|
32
|
+
return { ok: true, value: editor };
|
|
33
|
+
}
|
|
34
|
+
function findBlock(state, uid, opts) {
|
|
35
|
+
const targetUid = uid ?? state.activeUid;
|
|
36
|
+
if (!targetUid) {
|
|
37
|
+
return {
|
|
38
|
+
ok: false,
|
|
39
|
+
result: fail(tr("\u672A\u6307\u5B9A\u5757 uid \u4E14\u5F53\u524D\u672A\u9009\u4E2D\u5757\uFF0C\u8BF7\u5148\u8C03 get_status \u83B7\u53D6\u5757\u6E05\u5355"))
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const block = state.current.blocks.find((b) => b.uid === targetUid);
|
|
43
|
+
if (!block || opts?.tableOnly && block.type !== "table") {
|
|
44
|
+
return {
|
|
45
|
+
ok: false,
|
|
46
|
+
result: fail(
|
|
47
|
+
opts?.tableOnly ? tr("\u672A\u627E\u5230 uid=${0} \u7684\u8868\u683C\u5757\uFF0C\u8BF7\u5148\u8C03 get_status \u786E\u8BA4", [targetUid]) : tr("\u672A\u627E\u5230 uid=${0} \u7684\u5757\uFF0C\u8BF7\u5148\u8C03 get_status \u83B7\u53D6\u5757\u6E05\u5355", [targetUid])
|
|
48
|
+
)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return { ok: true, value: block };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/editor/usetool/tools/getStatus.ts
|
|
55
|
+
var getStatusTool = (context) => ({
|
|
56
|
+
name: "get_status",
|
|
57
|
+
description: tr(
|
|
58
|
+
"[idocs\u6587\u6863-\u7F16\u8F91\u5668] \u83B7\u53D6\u5F53\u524D\u6587\u6863\u72B6\u6001\uFF0C\u5305\u62EC\u5F53\u524D\u6A21\u677F\u3001\u5927\u7EB2\u7ED3\u6784\u3001\u6B63\u6587\u957F\u5EA6\u3001\u534F\u540C\u6A21\u5F0F\u3002\u4E0D\u8981\u5C55\u793A\u4E0E\u6587\u6863\u72B6\u6001\u65E0\u5173\u7684\u4FE1\u606F\u3002"
|
|
59
|
+
),
|
|
60
|
+
execute: async () => {
|
|
61
|
+
const resolved = resolveEditor(context);
|
|
62
|
+
if (!resolved.ok) return resolved.result;
|
|
63
|
+
const editor = resolved.value;
|
|
64
|
+
const outline = editor.getOutlineItems().map(({ level, text: text2 }) => ({ level, text: text2 }));
|
|
65
|
+
const text = editor.getText();
|
|
66
|
+
return ok(
|
|
67
|
+
tr("\u83B7\u53D6\u6587\u6863\u72B6\u6001\u6210\u529F"),
|
|
68
|
+
{
|
|
69
|
+
templateId: context.activeTemplate.id,
|
|
70
|
+
templateName: context.activeTemplate.name,
|
|
71
|
+
templateVersion: context.activeTemplate.version,
|
|
72
|
+
collabEnabled: context.collabEnabled,
|
|
73
|
+
outline,
|
|
74
|
+
textLength: text.length
|
|
75
|
+
},
|
|
76
|
+
{ successFlag: true }
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
var DEFAULT_MAX_LENGTH = 3800;
|
|
81
|
+
var HARD_MAX_LENGTH_CAP = 32e3;
|
|
82
|
+
var BLOCK_DIGEST_LIMIT = 200;
|
|
83
|
+
var CELL_TEXT_LIMIT = 40;
|
|
84
|
+
function cellKind(cell) {
|
|
85
|
+
if (cell.attrs.templateCellFixed === true || cell.attrs.templateCellFixedLocal === true) return "fixed";
|
|
86
|
+
if (typeof cell.attrs.cellFormula === "string" && cell.attrs.cellFormula.length > 0) return "formula";
|
|
87
|
+
if (cell.attrs.fillable === true) return "fillable";
|
|
88
|
+
return "plain";
|
|
89
|
+
}
|
|
90
|
+
function cellText(cell) {
|
|
91
|
+
const kind = cellKind(cell);
|
|
92
|
+
if (kind === "formula") return `=${String(cell.attrs.cellFormula).slice(0, CELL_TEXT_LIMIT)}`;
|
|
93
|
+
const text = cell.textContent.replace(/\s+/g, " ").trim().slice(0, CELL_TEXT_LIMIT);
|
|
94
|
+
if (text) return text;
|
|
95
|
+
if (kind === "fillable") return "[\u7A7A]";
|
|
96
|
+
return "\xB7";
|
|
97
|
+
}
|
|
98
|
+
function blockDigest(node) {
|
|
99
|
+
let text = "";
|
|
100
|
+
node.descendants((child) => {
|
|
101
|
+
if (child.type.name === "templateInlineSlot") {
|
|
102
|
+
const value = String(child.attrs.value ?? "");
|
|
103
|
+
text += value ? `\u3014${child.attrs.slotKey || "?"}=${value}\u3015` : `\u3014${child.attrs.slotKey || "?"}\u3015`;
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
if (child.isText && child.text) text += child.text;
|
|
107
|
+
return true;
|
|
108
|
+
});
|
|
109
|
+
return text.replace(/\s+/g, " ").trim();
|
|
110
|
+
}
|
|
111
|
+
function dataTableDigest(table) {
|
|
112
|
+
const map = TableMap.get(table);
|
|
113
|
+
const lines = [];
|
|
114
|
+
for (let row = 0; row < map.height; row += 1) {
|
|
115
|
+
const cells = [];
|
|
116
|
+
for (let col = 0; col < map.width; col += 1) {
|
|
117
|
+
const rel = map.map[row * map.width + col];
|
|
118
|
+
const cell = table.nodeAt(rel);
|
|
119
|
+
cells.push(cell ? cellText(cell) : "\xB7");
|
|
120
|
+
}
|
|
121
|
+
lines.push(` \u884C${row}: ${cells.join(" | ")}`);
|
|
122
|
+
}
|
|
123
|
+
return lines;
|
|
124
|
+
}
|
|
125
|
+
function fixedTableDigest(table) {
|
|
126
|
+
const lines = [];
|
|
127
|
+
for (let row = 0; row < table.childCount; row += 1) {
|
|
128
|
+
const rowNode = table.child(row);
|
|
129
|
+
const cells = [];
|
|
130
|
+
for (let col = 0; col < rowNode.childCount; col += 1) {
|
|
131
|
+
const cell = rowNode.child(col);
|
|
132
|
+
cells.push(cell.attrs.covered === true ? "\u2312" : cellText(cell));
|
|
133
|
+
}
|
|
134
|
+
lines.push(` \u884C${row}: ${cells.join(" | ")}`);
|
|
135
|
+
}
|
|
136
|
+
return lines;
|
|
137
|
+
}
|
|
138
|
+
function fillableCellsDigest(node, isFixed) {
|
|
139
|
+
const OPTION_LIST_LIMIT = 15;
|
|
140
|
+
const controlAnnotation = (cell, col) => {
|
|
141
|
+
const control = isFixed ? readFixedCellControl(cell) : headerControlForCol(node, col);
|
|
142
|
+
if (!control) return "";
|
|
143
|
+
if (control.type === "date") {
|
|
144
|
+
return `\u65E5\u671F[${control.dateFormat || "YYYY-MM-DD"}]`;
|
|
145
|
+
}
|
|
146
|
+
const options = control.options.length > OPTION_LIST_LIMIT ? `${control.options.slice(0, OPTION_LIST_LIMIT).join("|")}|\u7B49${control.options.length}\u9879` : control.options.join("|");
|
|
147
|
+
return `\u4E0B\u62C9[${options}]`;
|
|
148
|
+
};
|
|
149
|
+
const empty = [];
|
|
150
|
+
const filled = [];
|
|
151
|
+
const collect = (cell, row, col) => {
|
|
152
|
+
if (cellKind(cell) !== "fillable") return;
|
|
153
|
+
const key = `(${row},${col})${controlAnnotation(cell, col)}`;
|
|
154
|
+
if (cell.textContent.trim()) filled.push(key);
|
|
155
|
+
else empty.push(key);
|
|
156
|
+
};
|
|
157
|
+
if (isFixed) {
|
|
158
|
+
for (let row = 0; row < node.childCount; row += 1) {
|
|
159
|
+
const rowNode = node.child(row);
|
|
160
|
+
for (let col = 0; col < rowNode.childCount; col += 1) collect(rowNode.child(col), row, col);
|
|
161
|
+
}
|
|
162
|
+
} else {
|
|
163
|
+
const map = TableMap.get(node);
|
|
164
|
+
for (let row = 0; row < map.height; row += 1) {
|
|
165
|
+
for (let col = 0; col < map.width; col += 1) {
|
|
166
|
+
const cell = node.nodeAt(map.map[row * map.width + col]);
|
|
167
|
+
if (cell) collect(cell, row, col);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (empty.length === 0 && filled.length === 0) return null;
|
|
172
|
+
const parts = [];
|
|
173
|
+
if (empty.length) parts.push(`\u53EF\u586B\u7A7A\u683C: ${empty.join(" ")}`);
|
|
174
|
+
if (filled.length) parts.push(`\u53EF\u586B\u5DF2\u586B: ${filled.join(" ")}`);
|
|
175
|
+
return ` ${parts.join(" | ")}`;
|
|
176
|
+
}
|
|
177
|
+
function buildDocumentMap(context, doc) {
|
|
178
|
+
const slots = [];
|
|
179
|
+
const sections = [];
|
|
180
|
+
let lockedCount = 0;
|
|
181
|
+
let freeCount = 0;
|
|
182
|
+
doc.forEach((node, _offset, index) => {
|
|
183
|
+
const number = index + 1;
|
|
184
|
+
const meta = readTemplateBlockMeta(node);
|
|
185
|
+
const business = getProtectedContentNode(node) ?? node;
|
|
186
|
+
const nodeType = business.type.name;
|
|
187
|
+
const head = meta ? `[${number}] \u9501\u5B9A id=${meta.blockId} ${nodeType}${meta.label ? `\u300C${meta.label}\u300D` : ""}` : `[${number}] \u81EA\u7531 ${nodeType}`;
|
|
188
|
+
if (meta) lockedCount += 1;
|
|
189
|
+
else freeCount += 1;
|
|
190
|
+
const lines = [head];
|
|
191
|
+
if (nodeType === "table") {
|
|
192
|
+
lines.push(...dataTableDigest(business), fillableCellsDigest(business, false) ?? " \uFF08\u65E0\u53EF\u586B\u683C\uFF09");
|
|
193
|
+
} else if (nodeType === "fixedTable") {
|
|
194
|
+
lines.push(...fixedTableDigest(business), fillableCellsDigest(business, true) ?? " \uFF08\u65E0\u53EF\u586B\u683C\uFF09");
|
|
195
|
+
} else if (nodeType === "templateImage") {
|
|
196
|
+
const src = String(business.attrs.src ?? "");
|
|
197
|
+
lines.push(` \u56FE\u7247\u69FD ${business.attrs.slotKey || "?"} ${src ? `\u5DF2\u586B=${src.slice(0, 80)}` : "\u672A\u586B"}`);
|
|
198
|
+
slots.push({
|
|
199
|
+
slotKey: String(business.attrs.slotKey ?? "") || "(\u65E0key)",
|
|
200
|
+
label: String(business.attrs.slotLabel ?? ""),
|
|
201
|
+
kind: "image",
|
|
202
|
+
required: true,
|
|
203
|
+
filled: Boolean(src.trim()),
|
|
204
|
+
value: src,
|
|
205
|
+
blockIndex: number
|
|
206
|
+
});
|
|
207
|
+
} else {
|
|
208
|
+
const digest = blockDigest(business).slice(0, BLOCK_DIGEST_LIMIT);
|
|
209
|
+
lines.push(digest ? ` ${digest}` : " \uFF08\u7A7A\uFF09");
|
|
210
|
+
}
|
|
211
|
+
business.descendants((child) => {
|
|
212
|
+
if (child.type.name === "templateInlineSlot") {
|
|
213
|
+
const value = String(child.attrs.value ?? "");
|
|
214
|
+
slots.push({
|
|
215
|
+
slotKey: String(child.attrs.slotKey ?? "") || "(\u65E0key)",
|
|
216
|
+
label: String(child.attrs.slotLabel ?? ""),
|
|
217
|
+
kind: "inline",
|
|
218
|
+
required: child.attrs.required === true,
|
|
219
|
+
filled: Boolean(value.trim()),
|
|
220
|
+
value,
|
|
221
|
+
blockIndex: number
|
|
222
|
+
});
|
|
223
|
+
} else if (child.type.name === "templateImage") {
|
|
224
|
+
const src = String(child.attrs.src ?? "");
|
|
225
|
+
slots.push({
|
|
226
|
+
slotKey: String(child.attrs.slotKey ?? "") || "(\u65E0key)",
|
|
227
|
+
label: String(child.attrs.slotLabel ?? ""),
|
|
228
|
+
kind: "image",
|
|
229
|
+
required: true,
|
|
230
|
+
filled: Boolean(src.trim()),
|
|
231
|
+
value: src,
|
|
232
|
+
blockIndex: number
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
return true;
|
|
236
|
+
});
|
|
237
|
+
sections.push(lines.join("\n"));
|
|
238
|
+
});
|
|
239
|
+
const unfilledCount = slots.filter((slot) => !slot.filled).length;
|
|
240
|
+
const totalText = doc.textContent.length;
|
|
241
|
+
const header = `\u6587\u6863\u5730\u56FE\uFF1A\u6A21\u677F\u300C${context.activeTemplate.name}\u300Dv${context.activeTemplate.version} | \u9876\u5C42\u5757 ${doc.childCount}\uFF08\u9501\u5B9A ${lockedCount} / \u81EA\u7531 ${freeCount}\uFF09 | \u6B63\u6587 ${totalText} \u5B57 | \u69FD\u4F4D ${slots.length} \u4E2A\uFF08\u672A\u586B ${unfilledCount}\uFF09`;
|
|
242
|
+
const slotLines = slots.map((slot) => {
|
|
243
|
+
const kindLabel = slot.kind === "image" ? "\u56FE\u7247\u69FD" : "\u884C\u5185\u69FD";
|
|
244
|
+
return ` - ${slot.slotKey}${slot.required ? " \u5FC5\u586B" : ""} ${kindLabel}${slot.label ? `\u300C${slot.label}\u300D` : ""}${slot.filled ? `\u5DF2\u586B=${slot.value.slice(0, 40)}` : "\u672A\u586B"}${slot.blockIndex != null ? ` [\u5757${slot.blockIndex}]` : ""}`;
|
|
245
|
+
});
|
|
246
|
+
const content = [header, "", ...sections, ...slots.length ? ["", "\u69FD\u4F4D\uFF1A", ...slotLines] : []].join("\n");
|
|
247
|
+
return { content, blockCount: doc.childCount, slotCount: slots.length, unfilledCount };
|
|
248
|
+
}
|
|
249
|
+
var getContentTool = (context) => ({
|
|
250
|
+
name: "idocs_doc_get_content",
|
|
251
|
+
description: tr(
|
|
252
|
+
"[idocs\u6587\u6863-\u7F16\u8F91\u5668] \u8BFB\u53D6\u5F53\u524D\u6587\u6863\u3002format=outline\uFF08\u9ED8\u8BA4\uFF09\u4E00\u6B21\u8FD4\u56DE\u7ED3\u6784\u5316\u6587\u6863\u5730\u56FE\uFF1A\u5168\u90E8\u5757\uFF08blockId/\u7C7B\u578B/\u5185\u5BB9\u6458\u8981\uFF09\u3001\u8868\u683C\u884C\u5217\u7F51\u683C\u4E0E\u53EF\u586B\u683C\u5750\u6807\u3001\u884C\u5185/\u56FE\u7247\u69FD\u4F4D\u6E05\u5355\uFF08slotKey+\u5FC5\u586B+\u5DF2\u586B\u503C\uFF09\u2014\u2014\u540E\u7EED\u7CBE\u51C6\u64CD\u4F5C\uFF08block_update/slot_update/mark_update\uFF09\u6240\u9700\u7684\u5B9A\u4F4D\u4FE1\u606F\u4E00\u6B65\u62FF\u9F50\uFF0C\u8BFB\u4E00\u6B21\u5373\u53EF\u76F4\u63A5\u64CD\u4F5C\uFF0C\u4E0D\u8981\u53CD\u590D\u8BFB\u53D6\u3002\u53EF\u586B\u683C\u5750\u6807\u5E26\u63A7\u4EF6\u6807\u6CE8\uFF1A\u4E0B\u62C9[\u9009\u98791|\u9009\u98792] \u8868\u793A\u8BE5\u683C\u53EA\u80FD\u586B\u9009\u9879\u539F\u6587\u4E4B\u4E00\u3001\u65E5\u671F[YYYY-MM-DD] \u8868\u793A\u8BE5\u683C\u586B\u65E5\u671F\uFF08\u5E38\u89C1\u5199\u6CD5\u4F1A\u81EA\u52A8\u5F52\u4E00\u4E3A\u6807\u6CE8\u683C\u5F0F\uFF09\u3002text=\u7EAF\u6587\u672C\uFF08\u603B\u7ED3/\u5BA1\u9605\uFF09\uFF1Bhtml=\u5E26\u683C\u5F0F\uFF08\u6574\u7BC7\u91CD\u5199\u524D\u8BFB\u53D6\uFF09\uFF1Bjson=\u7ED3\u6784\u6811\u3002\u5355\u6B21\u7ED3\u679C\u7ECF\u670D\u52A1\u7AEF\u5B89\u5168\u7F51\u7EA6 4000 \u5B57\u7B26\u622A\u65AD\uFF08\u9ED8\u8BA4 maxLength 3800 \u5DF2\u5BF9\u9F50\uFF0C\u8D85\u957F\u6587\u6863\u8BFB\u53D6\u65F6\u4EE5\u5730\u56FE+\u7CBE\u51C6\u5DE5\u5177\u7EC4\u5408\u66FF\u4EE3\u5168\u6587\u8BFB\u53D6\uFF09\u3002"
|
|
253
|
+
),
|
|
254
|
+
inputSchema: {
|
|
255
|
+
type: "object",
|
|
256
|
+
properties: {
|
|
257
|
+
format: {
|
|
258
|
+
type: "string",
|
|
259
|
+
description: tr(
|
|
260
|
+
`\u8FD4\u56DE\u5185\u5BB9\u683C\u5F0F\uFF1A'outline' \u7ED3\u6784\u5316\u6587\u6863\u5730\u56FE\uFF08\u9ED8\u8BA4\uFF0C\u542B blockId/\u69FD\u4F4D/\u53EF\u586B\u683C\u5750\u6807\uFF09/ 'text' \u7EAF\u6587\u672C / 'html' \u5E26\u683C\u5F0F\u6807\u8BB0 / 'json' \u6587\u6863\u7ED3\u6784\u6811`
|
|
261
|
+
),
|
|
262
|
+
enum: ["outline", "text", "html", "json"],
|
|
263
|
+
default: "outline"
|
|
264
|
+
},
|
|
265
|
+
maxLength: {
|
|
266
|
+
type: "number",
|
|
267
|
+
description: tr("\u8FD4\u56DE\u5185\u5BB9\u7684\u6700\u5927\u5B57\u7B26\u6570\uFF0C\u9ED8\u8BA4 ${0}", [DEFAULT_MAX_LENGTH]),
|
|
268
|
+
default: DEFAULT_MAX_LENGTH,
|
|
269
|
+
// 与执行侧 HARD_MAX_LENGTH_CAP 钳制保持同一口径,模型侧即可见上限
|
|
270
|
+
maximum: HARD_MAX_LENGTH_CAP
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
execute: async (args) => {
|
|
275
|
+
const resolved = resolveEditor(context);
|
|
276
|
+
if (!resolved.ok) return resolved.result;
|
|
277
|
+
const editor = resolved.value;
|
|
278
|
+
const format = args.format ?? "outline";
|
|
279
|
+
const maxLength = Math.min(args.maxLength ?? DEFAULT_MAX_LENGTH, HARD_MAX_LENGTH_CAP);
|
|
280
|
+
let content;
|
|
281
|
+
let summary;
|
|
282
|
+
if (format === "outline") {
|
|
283
|
+
const tiptap = editor.editor;
|
|
284
|
+
if (!tiptap || tiptap.isDestroyed) {
|
|
285
|
+
return fail(tr("\u7F16\u8F91\u5668\u5B9E\u4F8B\u5C1A\u672A\u5C31\u7EEA\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5"));
|
|
286
|
+
}
|
|
287
|
+
const map = buildDocumentMap(context, tiptap.state.doc);
|
|
288
|
+
content = map.content;
|
|
289
|
+
summary = { blocks: map.blockCount, slots: map.slotCount, unfilled: map.unfilledCount };
|
|
290
|
+
} else if (format === "html") {
|
|
291
|
+
content = editor.getHTML();
|
|
292
|
+
} else if (format === "json") {
|
|
293
|
+
content = JSON.stringify(editor.getJSON());
|
|
294
|
+
} else {
|
|
295
|
+
content = editor.getText();
|
|
296
|
+
}
|
|
297
|
+
const truncated = content.length > maxLength;
|
|
298
|
+
return ok(
|
|
299
|
+
truncated ? tr("\u8BFB\u53D6\u6210\u529F\uFF0C\u4F46\u5185\u5BB9\u5171 ${0} \u5B57\u7B26\uFF0C\u4EC5\u8FD4\u56DE\u524D ${1} \u5B57\u7B26", [content.length, maxLength]) : tr("\u8BFB\u53D6\u6587\u6863\u5185\u5BB9\u6210\u529F"),
|
|
300
|
+
{
|
|
301
|
+
format,
|
|
302
|
+
content: truncated ? content.slice(0, maxLength) : content,
|
|
303
|
+
truncated,
|
|
304
|
+
totalLength: content.length,
|
|
305
|
+
...summary ? { summary } : {}
|
|
306
|
+
}
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
// src/editor/usetool/tools/idocsDocSetContent.ts
|
|
312
|
+
var getSetContentTool = (context) => ({
|
|
313
|
+
name: "idocs_doc_set_content",
|
|
314
|
+
description: tr(
|
|
315
|
+
'[idocs\u6587\u6863-\u7F16\u8F91\u5668] \u7528\u7ED9\u5B9A HTML \u5168\u91CF\u66FF\u6362\u5F53\u524D\u6587\u6863\u5185\u5BB9\u3002\u9002\u7528\u573A\u666F\uFF1A\u7528\u6237\u8981\u6C42"\u628A\u6587\u6863\u6539\u5199\u6210\u2026"\u3001"\u91CD\u65B0\u751F\u6210\u5168\u6587"\u65F6\u3002\u3010\u6CE8\u610F\u3011\u8FD9\u662F\u5168\u91CF\u66FF\u6362\uFF0C\u539F\u6709\u5185\u5BB9\u4F1A\u88AB\u8986\u76D6\uFF1B\u7528\u6237\u53EA\u8981\u6C42\u4FEE\u6539\u5C40\u90E8\u65F6\uFF0C\u5E94\u5148\u8BFB\u53D6\u5185\u5BB9\u3001\u6539\u5199\u540E\u6574\u4F53\u56DE\u5199\u3002'
|
|
316
|
+
),
|
|
317
|
+
inputSchema: {
|
|
318
|
+
type: "object",
|
|
319
|
+
properties: {
|
|
320
|
+
html: {
|
|
321
|
+
type: "string",
|
|
322
|
+
description: tr("\u8981\u5199\u5165\u7684 HTML \u5185\u5BB9\uFF0C\u5199\u5165\u524D\u4F1A\u505A\u5B89\u5168\u6D88\u6BD2\uFF0C\u811A\u672C\u4E0E\u5371\u9669\u5C5E\u6027\u4F1A\u88AB\u79FB\u9664")
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
required: ["html"]
|
|
326
|
+
},
|
|
327
|
+
execute: async (args) => {
|
|
328
|
+
const resolved = resolveEditor(context);
|
|
329
|
+
if (!resolved.ok) return resolved.result;
|
|
330
|
+
const editor = resolved.value;
|
|
331
|
+
if (!args.html || typeof args.html !== "string") {
|
|
332
|
+
return fail(tr("\u53C2\u6570 html \u4E0D\u80FD\u4E3A\u7A7A"));
|
|
333
|
+
}
|
|
334
|
+
const result = editor.setContent(sanitizeHtml(args.html));
|
|
335
|
+
if (!result.ok) {
|
|
336
|
+
return fail(tr("\u5199\u5165\u5931\u8D25\uFF1A${0}", [result.message]));
|
|
337
|
+
}
|
|
338
|
+
return ok(tr("\u6587\u6863\u5185\u5BB9\u5DF2\u66F4\u65B0"));
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
// src/editor/usetool/tools/idocsDocApplyTemplate.ts
|
|
343
|
+
var getApplyTemplateTool = (context) => {
|
|
344
|
+
const { activeTemplate } = context;
|
|
345
|
+
return {
|
|
346
|
+
name: "idocs_doc_apply_template",
|
|
347
|
+
description: tr("[idocs\u6587\u6863-\u7F16\u8F91\u5668] \u5E94\u7528\u5F53\u524D\u5DF2\u52A0\u8F7D\u7684\u6A21\u677F\u300C${0}\u300D(v${1})\u3002", [activeTemplate.name, activeTemplate.version]) + tr(
|
|
348
|
+
'\u9002\u7528\u573A\u666F\uFF1A\u7528\u6237\u8981\u6C42"\u6309\u6A21\u677F\u751F\u6210/\u8865\u9F50\u6587\u6863\u7ED3\u6784"\u65F6\u3002\u3010\u80FD\u529B\u8FB9\u754C\u3011\u9875\u9762\u53EA\u52A0\u8F7D\u4E86\u8FD9\u4E00\u4E2A\u6A21\u677F\uFF0C\u4E0D\u80FD\u5957\u7528\u5176\u4ED6\u6A21\u677F\uFF1Breplace-empty \u4EC5\u5728\u6587\u6863\u4E3A\u7A7A\u65F6\u751F\u6548\uFF0C\u975E\u7A7A\u6587\u6863\u8BF7\u7528 insert \u6A21\u5F0F\u63D2\u5165\u3002'
|
|
349
|
+
),
|
|
350
|
+
inputSchema: {
|
|
351
|
+
type: "object",
|
|
352
|
+
properties: {
|
|
353
|
+
definitionId: {
|
|
354
|
+
type: "string",
|
|
355
|
+
description: tr("\u6A21\u677F\u5B9A\u4E49 ID\uFF0C\u5F53\u524D\u4EC5\u652F\u6301\u5DF2\u52A0\u8F7D\u7684\u6FC0\u6D3B\u6A21\u677F"),
|
|
356
|
+
enum: [activeTemplate.id],
|
|
357
|
+
default: activeTemplate.id
|
|
358
|
+
},
|
|
359
|
+
mode: {
|
|
360
|
+
type: "string",
|
|
361
|
+
description: tr(`\u5E94\u7528\u6A21\u5F0F\uFF1A'replace-empty' \u7A7A\u6587\u6863\u6574\u4F53\u5957\u7528\uFF08\u9ED8\u8BA4\uFF09/ 'insert' \u63D2\u5165\u5F53\u524D\u6587\u6863`),
|
|
362
|
+
enum: ["replace-empty", "insert"],
|
|
363
|
+
default: "replace-empty"
|
|
364
|
+
}
|
|
365
|
+
},
|
|
366
|
+
required: ["definitionId"]
|
|
367
|
+
},
|
|
368
|
+
execute: async (args) => {
|
|
369
|
+
const resolved = resolveEditor(context);
|
|
370
|
+
if (!resolved.ok) return resolved.result;
|
|
371
|
+
const editor = resolved.value;
|
|
372
|
+
const result = editor.applyTemplate({ definitionId: args.definitionId, mode: args.mode });
|
|
373
|
+
if (!result.ok) {
|
|
374
|
+
return fail(tr("\u5E94\u7528\u6A21\u677F\u5931\u8D25\uFF1A${0}", [result.message]));
|
|
375
|
+
}
|
|
376
|
+
return ok(tr("\u6A21\u677F\u5DF2\u5E94\u7528\uFF0C\u751F\u6210 ${0} \u4E2A\u5185\u5BB9\u5757", [result.value.blockIds.length]), {
|
|
377
|
+
blockIds: result.value.blockIds
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
// src/editor/usetool/tools/idocsDocValidate.ts
|
|
384
|
+
var getValidateTool = (context) => ({
|
|
385
|
+
name: "idocs_doc_validate",
|
|
386
|
+
description: tr(
|
|
387
|
+
'[idocs\u6587\u6863-\u7F16\u8F91\u5668] \u6821\u9A8C\u5F53\u524D\u6587\u6863\u662F\u5426\u6EE1\u8DB3\u6A21\u677F\u8981\u6C42\uFF08\u5FC5\u586B\u6A21\u5757\u662F\u5426\u9F50\u5168\u3001\u662F\u5426\u586B\u5199\u5B8C\u6574\uFF09\u3002\u9002\u7528\u573A\u666F\uFF1A\u7528\u6237\u95EE"\u6587\u6863\u586B\u5B8C\u4E86\u5417"\u3001"\u8FD8\u5DEE\u54EA\u4E9B\u5185\u5BB9"\u65F6\u3002'
|
|
388
|
+
),
|
|
389
|
+
execute: async () => {
|
|
390
|
+
const resolved = resolveEditor(context);
|
|
391
|
+
if (!resolved.ok) return resolved.result;
|
|
392
|
+
const editor = resolved.value;
|
|
393
|
+
const result = editor.validateTemplate();
|
|
394
|
+
return ok(
|
|
395
|
+
result.valid ? tr("\u6821\u9A8C\u901A\u8FC7\uFF0C\u6A21\u677F\u5FC5\u586B\u9879\u5747\u5DF2\u5B8C\u6210") : tr("\u6821\u9A8C\u672A\u901A\u8FC7\uFF0C\u5171 ${0} \u4E2A\u95EE\u9898\uFF0C\u660E\u7EC6\u89C1\u8FD4\u56DE\u6570\u636E", [result.issues.length]),
|
|
396
|
+
{
|
|
397
|
+
valid: result.valid,
|
|
398
|
+
status: result.status,
|
|
399
|
+
issues: result.issues
|
|
400
|
+
}
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
// src/editor/usetool/tools/idocsDocFocusBlock.ts
|
|
406
|
+
var getFocusBlockTool = (context) => ({
|
|
407
|
+
name: "idocs_doc_focus_block",
|
|
408
|
+
description: tr(
|
|
409
|
+
'[idocs\u6587\u6863-\u7F16\u8F91\u5668] \u628A\u7F16\u8F91\u5668\u5B9A\u4F4D\u5230\u6307\u5B9A\u6A21\u677F\u5757\uFF08\u6EDA\u52A8\u5230\u53EF\u89C6\u533A\u57DF\u5E76\u805A\u7126\uFF09\u3002\u9002\u7528\u573A\u666F\uFF1A\u7528\u6237\u8BF4"\u5E26\u6211\u5230 XX \u90E8\u5206"\u65F6\u3002\u3010\u524D\u7F6E\u6761\u4EF6\u3011blockId \u5FC5\u987B\u6765\u81EA idocs_doc_apply_template \u8FD4\u56DE\u7684 blockIds \u6216 idocs_doc_validate \u7684 issues\uFF0C\u4E0D\u8981\u7F16\u9020\u3002'
|
|
410
|
+
),
|
|
411
|
+
inputSchema: {
|
|
412
|
+
type: "object",
|
|
413
|
+
properties: {
|
|
414
|
+
blockId: {
|
|
415
|
+
type: "string",
|
|
416
|
+
description: tr("\u6A21\u677F\u5185\u5BB9\u5757\u7684\u552F\u4E00\u6807\u8BC6")
|
|
417
|
+
}
|
|
418
|
+
},
|
|
419
|
+
required: ["blockId"]
|
|
420
|
+
},
|
|
421
|
+
execute: async (args) => {
|
|
422
|
+
const resolved = resolveEditor(context);
|
|
423
|
+
if (!resolved.ok) return resolved.result;
|
|
424
|
+
const editor = resolved.value;
|
|
425
|
+
if (!args.blockId) {
|
|
426
|
+
return fail(tr("\u53C2\u6570 blockId \u4E0D\u80FD\u4E3A\u7A7A"));
|
|
427
|
+
}
|
|
428
|
+
const result = editor.focusTemplateBlock(args.blockId);
|
|
429
|
+
if (!result.ok) {
|
|
430
|
+
return fail(tr("\u5B9A\u4F4D\u5931\u8D25\uFF1A${0}", [result.message]));
|
|
431
|
+
}
|
|
432
|
+
return ok(tr("\u5DF2\u5B9A\u4F4D\u5230\u76EE\u6807\u5185\u5BB9\u5757"));
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
// src/editor/copilot/attrMeta/designerIrMeta.ts
|
|
437
|
+
var ALL_BLOCK_TYPES = BLOCK_TYPES.map((item) => item.type);
|
|
438
|
+
function schemaPropsOf(defName) {
|
|
439
|
+
const props = TEMPLATE_IR_STRICT_SCHEMA.$defs?.[defName]?.properties;
|
|
440
|
+
if (!props) {
|
|
441
|
+
throw new Error(`[attrMeta] irSchema $defs \u7F3A\u5C11 ${defName}\uFF0C\u5C5E\u6027\u5143\u6570\u636E\u65E0\u6CD5\u6D3E\u751F\uFF08\u5951\u7EA6\u6F02\u79FB\uFF09`);
|
|
442
|
+
}
|
|
443
|
+
return props;
|
|
444
|
+
}
|
|
445
|
+
function valueTypeOf(schema) {
|
|
446
|
+
if (schema.enum) return "enum";
|
|
447
|
+
if (schema.type === "array" || schema.type === "object" || schema.type === void 0) return "object";
|
|
448
|
+
return schema.type;
|
|
449
|
+
}
|
|
450
|
+
function buildAttrMeta(props, extras) {
|
|
451
|
+
return Object.keys(extras).map((key) => {
|
|
452
|
+
const schema = props[key];
|
|
453
|
+
if (!schema) {
|
|
454
|
+
throw new Error(`[attrMeta] \u5B57\u6BB5 ${key} \u5728 irSchema \u5C5E\u6027\u8868\u4E2D\u4E0D\u5B58\u5728\uFF08\u5951\u7EA6\u6F02\u79FB\uFF09`);
|
|
455
|
+
}
|
|
456
|
+
const extra = extras[key];
|
|
457
|
+
return {
|
|
458
|
+
key,
|
|
459
|
+
type: valueTypeOf(schema),
|
|
460
|
+
...schema.enum ? { enum: schema.enum } : {},
|
|
461
|
+
...schema.minimum !== void 0 ? { minimum: schema.minimum } : {},
|
|
462
|
+
...schema.maximum !== void 0 ? { maximum: schema.maximum } : {},
|
|
463
|
+
...extra.default !== void 0 ? { default: extra.default } : {},
|
|
464
|
+
zhLabel: extra.zhLabel,
|
|
465
|
+
description: extra.description ?? schema.description ?? "",
|
|
466
|
+
appliesTo: extra.appliesTo,
|
|
467
|
+
scope: extra.scope,
|
|
468
|
+
aiWritable: extra.aiWritable
|
|
469
|
+
};
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
var BLOCK_ATTR_EXTRA = {
|
|
473
|
+
uid: { zhLabel: "\u5757 ID", appliesTo: ALL_BLOCK_TYPES, scope: "appearance", aiWritable: false },
|
|
474
|
+
type: { zhLabel: "\u5757\u7C7B\u578B", appliesTo: ALL_BLOCK_TYPES, scope: "appearance", aiWritable: false },
|
|
475
|
+
label: { zhLabel: "\u6807\u7B7E", appliesTo: ALL_BLOCK_TYPES, scope: "appearance", aiWritable: true },
|
|
476
|
+
headingLevel: {
|
|
477
|
+
zhLabel: "\u6807\u9898\u7EA7\u522B",
|
|
478
|
+
appliesTo: ["heading"],
|
|
479
|
+
scope: "appearance",
|
|
480
|
+
aiWritable: true,
|
|
481
|
+
description: "\u6807\u9898\u7EA7\u522B\uFF08\u4EC5\u6807\u9898\u5757\uFF1B\u5EFA\u8BAE 1-3\uFF0C1 \u4E3A\u6700\u9AD8\u7EA7\uFF09\u3002"
|
|
482
|
+
},
|
|
483
|
+
text: {
|
|
484
|
+
zhLabel: "\u6587\u672C\u5185\u5BB9",
|
|
485
|
+
appliesTo: ["heading", "paragraph", "codeBlock"],
|
|
486
|
+
scope: "appearance",
|
|
487
|
+
aiWritable: true
|
|
488
|
+
},
|
|
489
|
+
tableVariant: { zhLabel: "\u8868\u683C\u7528\u9014", appliesTo: ["table"], scope: "appearance", aiWritable: false },
|
|
490
|
+
dataTable: { zhLabel: "\u6570\u636E\u8868\u683C\u6A21\u578B", appliesTo: ["table"], scope: "appearance", aiWritable: false },
|
|
491
|
+
formTable: { zhLabel: "\u56FA\u5B9A\u8868\u683C\u6A21\u578B", appliesTo: ["table"], scope: "appearance", aiWritable: false },
|
|
492
|
+
width: {
|
|
493
|
+
zhLabel: "\u56FE\u7247\u5BBD\u5EA6",
|
|
494
|
+
appliesTo: ["image"],
|
|
495
|
+
scope: "appearance",
|
|
496
|
+
aiWritable: true,
|
|
497
|
+
default: 320,
|
|
498
|
+
description: "\u56FE\u7247\u5360\u4F4D\u8BBE\u8BA1\u5BBD\u5EA6 px\uFF08\u4EC5\u56FE\u7247\u5757\uFF1B\u63A8\u8350 40-2000 px\uFF0C\u7F3A\u7701 320\uFF09\u3002"
|
|
499
|
+
},
|
|
500
|
+
height: {
|
|
501
|
+
zhLabel: "\u56FE\u7247\u9AD8\u5EA6",
|
|
502
|
+
appliesTo: ["image"],
|
|
503
|
+
scope: "appearance",
|
|
504
|
+
aiWritable: true,
|
|
505
|
+
default: 200,
|
|
506
|
+
description: "\u56FE\u7247\u5360\u4F4D\u8BBE\u8BA1\u9AD8\u5EA6 px\uFF08\u4EC5\u56FE\u7247\u5757\uFF1B\u63A8\u8350 40-2000 px\uFF0C\u7F3A\u7701 200\uFF09\u3002"
|
|
507
|
+
},
|
|
508
|
+
isSlot: { zhLabel: "\u662F\u5426\u53EF\u586B\u5199", appliesTo: ALL_BLOCK_TYPES, scope: "appearance", aiWritable: true },
|
|
509
|
+
required: { zhLabel: "\u662F\u5426\u5FC5\u586B", appliesTo: ALL_BLOCK_TYPES, scope: "appearance", aiWritable: true },
|
|
510
|
+
pin: { zhLabel: "\u9489\u4F4F", appliesTo: ALL_BLOCK_TYPES, scope: "structure", aiWritable: true },
|
|
511
|
+
before: { zhLabel: "\u504F\u5E8F\uFF08\u4F4D\u4E8E\u4E4B\u4E0A\uFF09", appliesTo: ALL_BLOCK_TYPES, scope: "structure", aiWritable: true },
|
|
512
|
+
after: { zhLabel: "\u504F\u5E8F\uFF08\u4F4D\u4E8E\u4E4B\u4E0B\uFF09", appliesTo: ALL_BLOCK_TYPES, scope: "structure", aiWritable: true },
|
|
513
|
+
groupId: { zhLabel: "\u7EC4\u4EF6\u7EC4 ID", appliesTo: ALL_BLOCK_TYPES, scope: "structure", aiWritable: true },
|
|
514
|
+
groupLabel: { zhLabel: "\u7EC4\u4EF6\u7EC4\u540D\u79F0", appliesTo: ALL_BLOCK_TYPES, scope: "structure", aiWritable: true },
|
|
515
|
+
data: { zhLabel: "\u81EA\u5B9A\u4E49\u6570\u636E", appliesTo: [], scope: "data", aiWritable: true }
|
|
516
|
+
};
|
|
517
|
+
var FORM_CELL_ATTR_EXTRA = {
|
|
518
|
+
text: { zhLabel: "\u56FA\u5B9A\u6587\u5B57", appliesTo: ["table"], scope: "appearance", aiWritable: true },
|
|
519
|
+
fillable: { zhLabel: "\u53EF\u586B\u5199", appliesTo: ["table"], scope: "appearance", aiWritable: true },
|
|
520
|
+
required: { zhLabel: "\u5FC5\u586B", appliesTo: ["table"], scope: "appearance", aiWritable: true },
|
|
521
|
+
binding: { zhLabel: "\u540E\u7AEF\u53D8\u91CF\u8DEF\u5F84", appliesTo: ["table"], scope: "data", aiWritable: true },
|
|
522
|
+
bold: { zhLabel: "\u52A0\u7C97", appliesTo: ["table"], scope: "appearance", aiWritable: true },
|
|
523
|
+
backgroundColor: { zhLabel: "\u5E95\u8272", appliesTo: ["table"], scope: "appearance", aiWritable: true },
|
|
524
|
+
width: { zhLabel: "\u5355\u5143\u683C\u5BBD\u5EA6", appliesTo: ["table"], scope: "appearance", aiWritable: true },
|
|
525
|
+
widthUnit: {
|
|
526
|
+
zhLabel: "\u5BBD\u5EA6\u5355\u4F4D",
|
|
527
|
+
appliesTo: ["table"],
|
|
528
|
+
scope: "appearance",
|
|
529
|
+
aiWritable: true,
|
|
530
|
+
default: "percent"
|
|
531
|
+
},
|
|
532
|
+
textAlign: {
|
|
533
|
+
zhLabel: "\u6587\u5B57\u5BF9\u9F50",
|
|
534
|
+
appliesTo: ["table"],
|
|
535
|
+
scope: "appearance",
|
|
536
|
+
aiWritable: true,
|
|
537
|
+
default: "left"
|
|
538
|
+
},
|
|
539
|
+
fieldType: {
|
|
540
|
+
zhLabel: "\u8F93\u5165\u7C7B\u578B",
|
|
541
|
+
appliesTo: ["table"],
|
|
542
|
+
scope: "appearance",
|
|
543
|
+
aiWritable: true,
|
|
544
|
+
default: "text"
|
|
545
|
+
},
|
|
546
|
+
options: { zhLabel: "\u5019\u9009\u503C", appliesTo: ["table"], scope: "appearance", aiWritable: true },
|
|
547
|
+
dateFormat: {
|
|
548
|
+
zhLabel: "\u65E5\u671F\u683C\u5F0F",
|
|
549
|
+
appliesTo: ["table"],
|
|
550
|
+
scope: "appearance",
|
|
551
|
+
aiWritable: true,
|
|
552
|
+
default: "YYYY-MM-DD"
|
|
553
|
+
},
|
|
554
|
+
formula: { zhLabel: "\u516C\u5F0F", appliesTo: ["table"], scope: "appearance", aiWritable: true },
|
|
555
|
+
rowspan: { zhLabel: "\u7EB5\u5411\u8DE8\u884C", appliesTo: ["table"], scope: "appearance", aiWritable: true },
|
|
556
|
+
covered: { zhLabel: "\u5E7D\u7075\u683C\u6807\u8BB0", appliesTo: ["table"], scope: "appearance", aiWritable: false }
|
|
557
|
+
};
|
|
558
|
+
var DATA_COLUMN_ATTR_EXTRA = {
|
|
559
|
+
header: { zhLabel: "\u8868\u5934\u6587\u5B57", appliesTo: ["table"], scope: "appearance", aiWritable: true },
|
|
560
|
+
width: { zhLabel: "\u5217\u5BBD", appliesTo: ["table"], scope: "appearance", aiWritable: true },
|
|
561
|
+
fieldType: {
|
|
562
|
+
zhLabel: "\u8F93\u5165\u7C7B\u578B",
|
|
563
|
+
appliesTo: ["table"],
|
|
564
|
+
scope: "appearance",
|
|
565
|
+
aiWritable: true,
|
|
566
|
+
default: "text"
|
|
567
|
+
},
|
|
568
|
+
options: { zhLabel: "\u5019\u9009\u503C", appliesTo: ["table"], scope: "appearance", aiWritable: true },
|
|
569
|
+
dateFormat: {
|
|
570
|
+
zhLabel: "\u65E5\u671F\u683C\u5F0F",
|
|
571
|
+
appliesTo: ["table"],
|
|
572
|
+
scope: "appearance",
|
|
573
|
+
aiWritable: true,
|
|
574
|
+
default: "YYYY-MM-DD"
|
|
575
|
+
},
|
|
576
|
+
binding: { zhLabel: "\u884C\u5B57\u6BB5\u8DEF\u5F84", appliesTo: ["table"], scope: "data", aiWritable: true }
|
|
577
|
+
};
|
|
578
|
+
var DATA_TABLE_ATTR_EXTRA = {
|
|
579
|
+
columns: { zhLabel: "\u5217\u5B9A\u4E49", appliesTo: ["table"], scope: "structure", aiWritable: true },
|
|
580
|
+
defaultRows: { zhLabel: "\u9ED8\u8BA4\u884C\u6570", appliesTo: ["table"], scope: "structure", aiWritable: true },
|
|
581
|
+
defaultDataEnabled: { zhLabel: "\u542F\u7528\u9ED8\u8BA4\u6570\u636E", appliesTo: ["table"], scope: "data", aiWritable: true },
|
|
582
|
+
defaultData: { zhLabel: "\u9ED8\u8BA4\u6570\u636E", appliesTo: ["table"], scope: "data", aiWritable: true },
|
|
583
|
+
defaultDataFixed: { zhLabel: "\u5168\u5C40\u56FA\u5B9A\u9ED8\u8BA4\u6570\u636E", appliesTo: ["table"], scope: "data", aiWritable: true },
|
|
584
|
+
defaultDataCellFixed: { zhLabel: "\u5355\u5143\u683C\u56FA\u5B9A\u77E9\u9635", appliesTo: ["table"], scope: "data", aiWritable: true },
|
|
585
|
+
binding: { zhLabel: "\u884C\u6570\u7EC4\u53D8\u91CF\u8DEF\u5F84", appliesTo: ["table"], scope: "data", aiWritable: true }
|
|
586
|
+
};
|
|
587
|
+
var BLOCK_PROPS = schemaPropsOf("DesignerBlock");
|
|
588
|
+
var FORM_CELL_PROPS = schemaPropsOf("DesignerFormTableCell");
|
|
589
|
+
var FORM_ROW_PROPS = schemaPropsOf("DesignerFormTableRow");
|
|
590
|
+
var DATA_COLUMN_PROPS = schemaPropsOf("DesignerDataTableColumn");
|
|
591
|
+
var DATA_TABLE_PROPS = schemaPropsOf("DesignerDataTableModel");
|
|
592
|
+
var DESIGNER_BLOCK_ATTRS = buildAttrMeta(BLOCK_PROPS, BLOCK_ATTR_EXTRA);
|
|
593
|
+
var DESIGNER_FORM_CELL_ATTRS = buildAttrMeta(FORM_CELL_PROPS, FORM_CELL_ATTR_EXTRA);
|
|
594
|
+
var DESIGNER_DATA_COLUMN_ATTRS = buildAttrMeta(DATA_COLUMN_PROPS, DATA_COLUMN_ATTR_EXTRA);
|
|
595
|
+
var DESIGNER_DATA_TABLE_ATTRS = buildAttrMeta(DATA_TABLE_PROPS, DATA_TABLE_ATTR_EXTRA);
|
|
596
|
+
var DESIGNER_FORM_ROW_HEIGHT_ATTR = buildAttrMeta(
|
|
597
|
+
{ height: FORM_ROW_PROPS.height },
|
|
598
|
+
{
|
|
599
|
+
height: {
|
|
600
|
+
zhLabel: "\u884C\u9AD8",
|
|
601
|
+
appliesTo: ["table"],
|
|
602
|
+
scope: "appearance",
|
|
603
|
+
aiWritable: true,
|
|
604
|
+
default: DEFAULT_FORM_ROW_HEIGHT,
|
|
605
|
+
description: `\u56FA\u5B9A\u8868\u683C\u884C\u9AD8 px\uFF08\u63A8\u8350 36-48\uFF0C\u4F4E\u4E8E 32 \u6587\u5B57\u53EF\u80FD\u88AB\u88C1\u5207\uFF1B\u7F3A\u7701 ${DEFAULT_FORM_ROW_HEIGHT}\uFF09\u3002`
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
)[0];
|
|
609
|
+
|
|
610
|
+
// src/editor/copilot/attrMeta/editorNodeMeta.ts
|
|
611
|
+
function entry(nodeName, zhLabel, attrs) {
|
|
612
|
+
return { nodeName, zhLabel, attrs: attrs.map((attr) => ({ ...attr, appliesTo: [nodeName] })) };
|
|
613
|
+
}
|
|
614
|
+
var TEXT_ALIGN_ATTR = {
|
|
615
|
+
key: "textAlign",
|
|
616
|
+
type: "enum",
|
|
617
|
+
enum: ["left", "center", "right", "justify"],
|
|
618
|
+
default: "left",
|
|
619
|
+
zhLabel: "\u6C34\u5E73\u5BF9\u9F50",
|
|
620
|
+
description: "\u6587\u672C\u6C34\u5E73\u5BF9\u9F50\u65B9\u5F0F\uFF08\u4EC5\u4E24\u7AEF\u5BF9\u9F50 justify \u5728\u7A84\u680F\u4E0B\u89C2\u611F\u8F83\u5DEE\uFF0C\u6B63\u6587\u5EFA\u8BAE left\uFF09\u3002",
|
|
621
|
+
scope: "appearance",
|
|
622
|
+
aiWritable: true
|
|
623
|
+
};
|
|
624
|
+
var TEMPLATE_CELL_STRUCTURE_ATTRS = [
|
|
625
|
+
{
|
|
626
|
+
key: "fillable",
|
|
627
|
+
type: "boolean",
|
|
628
|
+
default: false,
|
|
629
|
+
zhLabel: "\u53EF\u586B\u5199",
|
|
630
|
+
description: "\u6A21\u677F\u53EF\u586B\u533A\u6807\u8BB0\uFF08true \u65F6\u683C\u5185\u6587\u672C\u53EF\u586B\u5199\uFF09\u3002\u7531\u6A21\u677F\u5B9A\u4E49\u51B3\u5B9A\uFF0C\u7F16\u8F91\u5668\u4FA7\u4E0D\u53EF\u6539\u3002",
|
|
631
|
+
scope: "structure",
|
|
632
|
+
aiWritable: false
|
|
633
|
+
},
|
|
634
|
+
{
|
|
635
|
+
key: "required",
|
|
636
|
+
type: "boolean",
|
|
637
|
+
default: false,
|
|
638
|
+
zhLabel: "\u5FC5\u586B",
|
|
639
|
+
description: "\u63D0\u4EA4\u6821\u9A8C\u65F6\u8BE5\u683C\u5FC5\u987B\u975E\u7A7A\u3002\u7531\u6A21\u677F\u5B9A\u4E49\u51B3\u5B9A\uFF0C\u7F16\u8F91\u5668\u4FA7\u4E0D\u53EF\u6539\u3002",
|
|
640
|
+
scope: "structure",
|
|
641
|
+
aiWritable: false
|
|
642
|
+
},
|
|
643
|
+
{
|
|
644
|
+
key: "cellFormula",
|
|
645
|
+
type: "string",
|
|
646
|
+
default: null,
|
|
647
|
+
zhLabel: "\u5355\u5143\u683C\u516C\u5F0F",
|
|
648
|
+
description: "\u516C\u5F0F\uFF08\u5982 =SUM(R1C1:R5C1)\uFF09\uFF0C\u516C\u5F0F\u683C\u5185\u5BB9\u7531\u91CD\u7B97\u63D2\u4EF6\u7EF4\u62A4\u3002\u5C5E\u6A21\u677F\u8BBE\u8BA1\u671F\u914D\u7F6E\uFF0C\u4E0D\u53EF\u6539\u3002",
|
|
649
|
+
scope: "structure",
|
|
650
|
+
aiWritable: false
|
|
651
|
+
}
|
|
652
|
+
];
|
|
653
|
+
var EDITOR_NODE_ATTRS = Object.fromEntries(
|
|
654
|
+
[
|
|
655
|
+
// ─── 文本块 ─────────────────────────────────────────────
|
|
656
|
+
entry("paragraph", "\u6BB5\u843D", [TEXT_ALIGN_ATTR]),
|
|
657
|
+
entry("heading", "\u6807\u9898", [
|
|
658
|
+
{
|
|
659
|
+
key: "level",
|
|
660
|
+
type: "enum",
|
|
661
|
+
enum: [1, 2, 3, 4, 5, 6],
|
|
662
|
+
default: 1,
|
|
663
|
+
zhLabel: "\u6807\u9898\u7EA7\u522B",
|
|
664
|
+
description: "\u6807\u9898\u7EA7\u522B\uFF08\u5EFA\u8BAE 1-3\uFF0C1 \u4E3A\u6700\u9AD8\u7EA7\uFF1B4 \u4EE5\u4E0B\u5C42\u7EA7\u8FC7\u6DF1\uFF0C\u6B63\u6587\u6587\u6863\u5C11\u7528\uFF09\u3002",
|
|
665
|
+
scope: "appearance",
|
|
666
|
+
aiWritable: true
|
|
667
|
+
},
|
|
668
|
+
TEXT_ALIGN_ATTR
|
|
669
|
+
]),
|
|
670
|
+
entry("codeBlock", "\u4EE3\u7801\u5757", [
|
|
671
|
+
{
|
|
672
|
+
key: "language",
|
|
673
|
+
type: "string",
|
|
674
|
+
default: "javascript",
|
|
675
|
+
zhLabel: "\u8BED\u8A00",
|
|
676
|
+
description: "\u4EE3\u7801\u9AD8\u4EAE\u8BED\u8A00\uFF08javascript/typescript/python/java/sql \u7B49\uFF1Bnull \u4E3A\u81EA\u52A8\u68C0\u6D4B\uFF09\u3002",
|
|
677
|
+
scope: "appearance",
|
|
678
|
+
aiWritable: true
|
|
679
|
+
}
|
|
680
|
+
]),
|
|
681
|
+
// ─── 图片 ───────────────────────────────────────────────
|
|
682
|
+
entry("image", "\u56FE\u7247", [
|
|
683
|
+
{
|
|
684
|
+
key: "src",
|
|
685
|
+
type: "string",
|
|
686
|
+
default: null,
|
|
687
|
+
zhLabel: "\u56FE\u7247\u5730\u5740",
|
|
688
|
+
description: "\u56FE\u7247\u5730\u5740\uFF08URL \u6216 dataURL\uFF09\u3002\u81EA\u7531\u56FE\u7247\u6539\u5730\u5740\u7B49\u4EF7\u6362\u56FE\u3002",
|
|
689
|
+
scope: "data",
|
|
690
|
+
aiWritable: true
|
|
691
|
+
},
|
|
692
|
+
{
|
|
693
|
+
key: "alt",
|
|
694
|
+
type: "string",
|
|
695
|
+
default: null,
|
|
696
|
+
zhLabel: "\u66FF\u4EE3\u6587\u672C",
|
|
697
|
+
description: "\u56FE\u7247\u52A0\u8F7D\u5931\u8D25\u65F6\u7684\u66FF\u4EE3\u6587\u672C\uFF08\u65E0\u969C\u788D/\u5BFC\u51FA\u573A\u666F\u5C55\u793A\uFF09\u3002",
|
|
698
|
+
scope: "appearance",
|
|
699
|
+
aiWritable: true
|
|
700
|
+
},
|
|
701
|
+
{
|
|
702
|
+
key: "title",
|
|
703
|
+
type: "string",
|
|
704
|
+
default: null,
|
|
705
|
+
zhLabel: "\u6807\u9898",
|
|
706
|
+
description: "\u56FE\u7247\u6807\u9898\uFF08\u60AC\u505C\u63D0\u793A\u6587\u672C\uFF09\u3002",
|
|
707
|
+
scope: "appearance",
|
|
708
|
+
aiWritable: true
|
|
709
|
+
}
|
|
710
|
+
]),
|
|
711
|
+
entry("templateImage", "\u6A21\u677F\u56FE\u7247", [
|
|
712
|
+
{
|
|
713
|
+
key: "src",
|
|
714
|
+
type: "string",
|
|
715
|
+
default: "",
|
|
716
|
+
zhLabel: "\u56FE\u7247\u5730\u5740",
|
|
717
|
+
description: "\u6A21\u677F\u56FE\u7247\u5DF2\u586B\u5730\u5740\uFF08\u7A7A\u4E32 = \u672A\u586B\u5199\u5360\u4F4D\uFF09\uFF1B\u586B\u5199\u56FE\u7247\u4F4D = \u8BBE\u7F6E src\u3002",
|
|
718
|
+
scope: "data",
|
|
719
|
+
aiWritable: true
|
|
720
|
+
},
|
|
721
|
+
{
|
|
722
|
+
key: "alt",
|
|
723
|
+
type: "string",
|
|
724
|
+
default: "",
|
|
725
|
+
zhLabel: "\u66FF\u4EE3\u6587\u672C",
|
|
726
|
+
description: "\u56FE\u7247\u52A0\u8F7D\u5931\u8D25\u65F6\u7684\u66FF\u4EE3\u6587\u672C\u3002",
|
|
727
|
+
scope: "appearance",
|
|
728
|
+
aiWritable: true
|
|
729
|
+
},
|
|
730
|
+
{
|
|
731
|
+
key: "title",
|
|
732
|
+
type: "string",
|
|
733
|
+
default: "",
|
|
734
|
+
zhLabel: "\u6807\u9898",
|
|
735
|
+
description: "\u56FE\u7247\u6807\u9898\uFF08\u60AC\u505C\u63D0\u793A\u6587\u672C\uFF09\u3002",
|
|
736
|
+
scope: "appearance",
|
|
737
|
+
aiWritable: true
|
|
738
|
+
},
|
|
739
|
+
{
|
|
740
|
+
key: "width",
|
|
741
|
+
type: "number",
|
|
742
|
+
default: null,
|
|
743
|
+
minimum: 40,
|
|
744
|
+
maximum: 2e3,
|
|
745
|
+
zhLabel: "\u5BBD\u5EA6",
|
|
746
|
+
description: "\u5BBD\u5EA6\uFF08\u50CF\u7D20\uFF0C\u5EFA\u8BAE 40-2000\uFF09\u3002\u5DF2\u586B\u6001\u4E3A\u56FE\u7247\u6E32\u67D3\u5BBD\u5EA6\uFF08\u9AD8\u5EA6\u6309\u81EA\u7136\u6BD4\u4F8B\uFF09\uFF1B\u7A7A\u6001\u4E3A\u5360\u4F4D\u6846\u5BBD\u5EA6\u3002",
|
|
747
|
+
scope: "appearance",
|
|
748
|
+
aiWritable: true
|
|
749
|
+
},
|
|
750
|
+
{
|
|
751
|
+
key: "height",
|
|
752
|
+
type: "number",
|
|
753
|
+
default: null,
|
|
754
|
+
minimum: 40,
|
|
755
|
+
maximum: 2e3,
|
|
756
|
+
zhLabel: "\u9AD8\u5EA6",
|
|
757
|
+
description: "\u9AD8\u5EA6\uFF08\u50CF\u7D20\uFF0C\u5EFA\u8BAE 40-2000\uFF09\u3002\u4E3B\u8981\u7528\u4F5C\u7A7A\u6001\u5360\u4F4D\u6846\u9AD8\u5EA6\uFF1B\u5DF2\u586B\u6001\u9AD8\u5EA6\u6309\u56FE\u7247\u81EA\u7136\u6BD4\u4F8B\u81EA\u9002\u5E94\uFF0C\u4E00\u822C\u4E0D\u8BBE\u3002",
|
|
758
|
+
scope: "appearance",
|
|
759
|
+
aiWritable: true
|
|
760
|
+
},
|
|
761
|
+
{
|
|
762
|
+
key: "slotKey",
|
|
763
|
+
type: "string",
|
|
764
|
+
default: "",
|
|
765
|
+
zhLabel: "\u69FD\u4F4D key",
|
|
766
|
+
description: "\u6A21\u677F\u5B9A\u4E49\u4E2D\u7684\u7A33\u5B9A\u69FD\u4F4D\u6807\u8BC6\uFF08\u8EAB\u4EFD\u5C5E\u6027\uFF0C\u4E0D\u53EF\u6539\uFF09\u3002",
|
|
767
|
+
scope: "identity",
|
|
768
|
+
aiWritable: false
|
|
769
|
+
},
|
|
770
|
+
{
|
|
771
|
+
key: "uploadState",
|
|
772
|
+
type: "enum",
|
|
773
|
+
enum: ["empty", "uploading", "filled"],
|
|
774
|
+
default: "empty",
|
|
775
|
+
zhLabel: "\u4E0A\u4F20\u72B6\u6001",
|
|
776
|
+
description: "\u4E0A\u4F20\u8FDB\u884C\u6001\uFF08\u4E34\u65F6\u6D3E\u751F\u503C\uFF0C\u4E0D\u6301\u4E45\u5316\uFF0C\u4E0D\u53EF\u6539\uFF09\u3002",
|
|
777
|
+
scope: "identity",
|
|
778
|
+
aiWritable: false
|
|
779
|
+
}
|
|
780
|
+
]),
|
|
781
|
+
// ─── 模板槽位与容器 ─────────────────────────────────────
|
|
782
|
+
entry("templateInlineSlot", "\u884C\u5185\u586B\u5199\u9879", [
|
|
783
|
+
{
|
|
784
|
+
key: "value",
|
|
785
|
+
type: "string",
|
|
786
|
+
default: "",
|
|
787
|
+
zhLabel: "\u5DF2\u586B\u503C",
|
|
788
|
+
description: "\u884C\u5185\u69FD\u5DF2\u586B\u5199\u7684\u503C\uFF08\u5B58\u4E8E\u8282\u70B9\u5C5E\u6027\u800C\u975E\u6587\u672C\uFF09\uFF1B\u586B\u5199\u884C\u5185\u7A7A\u4F4D = \u8BBE\u7F6E value\u3002",
|
|
789
|
+
scope: "data",
|
|
790
|
+
aiWritable: true
|
|
791
|
+
},
|
|
792
|
+
{
|
|
793
|
+
key: "required",
|
|
794
|
+
type: "boolean",
|
|
795
|
+
default: false,
|
|
796
|
+
zhLabel: "\u5FC5\u586B",
|
|
797
|
+
description: "\u5FC5\u586B\u69FD\u63D0\u4EA4\u6821\u9A8C\u65F6\u975E\u7A7A\uFF08{[\u6807\u7B7E]}=\u5FC5\u586B\uFF09\u3002\u7531\u6A21\u677F\u5B9A\u4E49\u51B3\u5B9A\uFF0C\u4E0D\u53EF\u6539\u3002",
|
|
798
|
+
scope: "structure",
|
|
799
|
+
aiWritable: false
|
|
800
|
+
},
|
|
801
|
+
{
|
|
802
|
+
key: "slotKey",
|
|
803
|
+
type: "string",
|
|
804
|
+
default: "",
|
|
805
|
+
zhLabel: "\u69FD\u4F4D key",
|
|
806
|
+
description: "\u7A33\u5B9A\u69FD\u4F4D\u6807\u8BC6\uFF08\u8EAB\u4EFD\u5C5E\u6027\uFF0C\u4E0D\u53EF\u6539\uFF09\u3002",
|
|
807
|
+
scope: "identity",
|
|
808
|
+
aiWritable: false
|
|
809
|
+
},
|
|
810
|
+
{
|
|
811
|
+
key: "slotLabel",
|
|
812
|
+
type: "string",
|
|
813
|
+
default: "",
|
|
814
|
+
zhLabel: "\u69FD\u4F4D\u6807\u7B7E",
|
|
815
|
+
description: "\u7A7A\u6001\u5360\u4F4D\u63D0\u793A\u4E0E\u5FC5\u586B\u6E05\u5355\u5C55\u793A\u540D\uFF08\u8EAB\u4EFD\u5C5E\u6027\uFF0C\u4E0D\u53EF\u6539\uFF09\u3002",
|
|
816
|
+
scope: "identity",
|
|
817
|
+
aiWritable: false
|
|
818
|
+
}
|
|
819
|
+
]),
|
|
820
|
+
entry("protectedBlock", "\u53D7\u4FDD\u62A4\u5757\u5BB9\u5668", [
|
|
821
|
+
{
|
|
822
|
+
key: "templateBlock",
|
|
823
|
+
type: "object",
|
|
824
|
+
default: null,
|
|
825
|
+
zhLabel: "\u6A21\u677F\u5757\u5143\u6570\u636E",
|
|
826
|
+
description: "\u53D7\u4FDD\u62A4\u5757\u81EA\u63CF\u8FF0\u5143\u6570\u636E\uFF08blockId/kind/label/pin/before/after/groupId \u7B49 14 \u5B57\u6BB5\uFF09\u3002\u8EAB\u4EFD\u4E0E\u7ED3\u6784\u8F7D\u4F53\uFF0C\u4EFB\u4F55\u8FD0\u884C\u6001\u901A\u9053\u90FD\u4E0D\u53EF\u6539\u3002",
|
|
827
|
+
scope: "identity",
|
|
828
|
+
aiWritable: false
|
|
829
|
+
}
|
|
830
|
+
]),
|
|
831
|
+
// ─── 数据表格(table 插件)─────────────────────────────
|
|
832
|
+
entry("table", "\u6570\u636E\u8868\u683C", [
|
|
833
|
+
{
|
|
834
|
+
key: "templateTableMode",
|
|
835
|
+
type: "enum",
|
|
836
|
+
enum: ["data", "form"],
|
|
837
|
+
default: null,
|
|
838
|
+
zhLabel: "\u8868\u683C\u6A21\u677F\u6A21\u5F0F",
|
|
839
|
+
description: "data=\u9501\u8868\u5934\u5141\u8BB8\u589E\u5220\u6570\u636E\u884C\uFF1Bform=\u9501\u5168\u90E8\u5E03\u5C40\u4EC5\u53EF\u586B\u683C\u3002\u6A21\u677F\u8BBE\u8BA1\u671F\u914D\u7F6E\uFF0C\u4E0D\u53EF\u6539\u3002",
|
|
840
|
+
scope: "structure",
|
|
841
|
+
aiWritable: false
|
|
842
|
+
},
|
|
843
|
+
{
|
|
844
|
+
key: "templateDataGlobalFixed",
|
|
845
|
+
type: "boolean",
|
|
846
|
+
default: false,
|
|
847
|
+
zhLabel: "\u5168\u5C40\u56FA\u5B9A",
|
|
848
|
+
description: "\u6570\u636E\u8868\u683C\u5168\u5C40\u56FA\u5B9A\u6807\u8BB0\uFF08\u9ED8\u8BA4\u6570\u636E\u5168\u9501\uFF09\u3002\u6A21\u677F\u8BBE\u8BA1\u671F\u914D\u7F6E\uFF0C\u4E0D\u53EF\u6539\u3002",
|
|
849
|
+
scope: "structure",
|
|
850
|
+
aiWritable: false
|
|
851
|
+
}
|
|
852
|
+
]),
|
|
853
|
+
entry("tableRow", "\u6570\u636E\u8868\u683C\u884C", [
|
|
854
|
+
{
|
|
855
|
+
key: "rowHeight",
|
|
856
|
+
type: "number",
|
|
857
|
+
default: null,
|
|
858
|
+
minimum: 24,
|
|
859
|
+
zhLabel: "\u884C\u9AD8",
|
|
860
|
+
description: "\u884C\u9AD8\uFF08\u50CF\u7D20\uFF0C\u5EFA\u8BAE 36-48\uFF0C\u4E0D\u5C0F\u4E8E 24\uFF09\u3002\u9AA8\u67B6\u767D\u540D\u5355\u5185\u7684\u8868\u73B0\u5C5E\u6027\uFF0C\u9501\u5B9A\u8868\u683C\u4E5F\u53EF\u6539\u3002",
|
|
861
|
+
scope: "appearance",
|
|
862
|
+
aiWritable: true
|
|
863
|
+
},
|
|
864
|
+
{
|
|
865
|
+
key: "templateRowDefault",
|
|
866
|
+
type: "boolean",
|
|
867
|
+
default: false,
|
|
868
|
+
zhLabel: "\u9ED8\u8BA4\u6570\u636E\u884C",
|
|
869
|
+
description: "\u6A21\u677F\u9884\u7F6E\u9ED8\u8BA4\u6570\u636E\u884C\u6807\u8BB0\u3002\u6A21\u677F\u8BBE\u8BA1\u671F\u914D\u7F6E\uFF0C\u4E0D\u53EF\u6539\u3002",
|
|
870
|
+
scope: "structure",
|
|
871
|
+
aiWritable: false
|
|
872
|
+
},
|
|
873
|
+
{
|
|
874
|
+
key: "templateRowFixed",
|
|
875
|
+
type: "boolean",
|
|
876
|
+
default: false,
|
|
877
|
+
zhLabel: "\u9501\u5B9A\u884C",
|
|
878
|
+
description: "\u9501\u5B9A\u884C\u6807\u8BB0\uFF08\u4E0D\u53EF\u5220\u9664\uFF0C\u56FA\u5B9A\u683C\u5185\u5BB9\u8FDB\u9501\u5B9A\u9AA8\u67B6\uFF09\u3002\u6A21\u677F\u8BBE\u8BA1\u671F\u914D\u7F6E\uFF0C\u4E0D\u53EF\u6539\u3002",
|
|
879
|
+
scope: "structure",
|
|
880
|
+
aiWritable: false
|
|
881
|
+
}
|
|
882
|
+
]),
|
|
883
|
+
entry("tableCell", "\u6570\u636E\u8868\u683C\u5355\u5143\u683C", [
|
|
884
|
+
{
|
|
885
|
+
key: "colspan",
|
|
886
|
+
type: "number",
|
|
887
|
+
default: 1,
|
|
888
|
+
minimum: 1,
|
|
889
|
+
zhLabel: "\u6A2A\u5411\u5408\u5E76",
|
|
890
|
+
description: "\u6A2A\u5411\u8DE8\u8D8A\u5217\u6570\uFF08\u7ED3\u6784\u5C5E\u6027\uFF0C\u6539\u52A8\u5373\u6539\u8868\u683C\u7ED3\u6784\uFF0C\u4E0D\u53EF\u6539\uFF09\u3002",
|
|
891
|
+
scope: "structure",
|
|
892
|
+
aiWritable: false
|
|
893
|
+
},
|
|
894
|
+
{
|
|
895
|
+
key: "rowspan",
|
|
896
|
+
type: "number",
|
|
897
|
+
default: 1,
|
|
898
|
+
minimum: 1,
|
|
899
|
+
zhLabel: "\u7EB5\u5411\u5408\u5E76",
|
|
900
|
+
description: "\u7EB5\u5411\u8DE8\u8D8A\u884C\u6570\uFF08\u7ED3\u6784\u5C5E\u6027\uFF0C\u6539\u52A8\u5373\u6539\u8868\u683C\u7ED3\u6784\uFF0C\u4E0D\u53EF\u6539\uFF09\u3002",
|
|
901
|
+
scope: "structure",
|
|
902
|
+
aiWritable: false
|
|
903
|
+
},
|
|
904
|
+
{
|
|
905
|
+
key: "colwidth",
|
|
906
|
+
type: "object",
|
|
907
|
+
default: null,
|
|
908
|
+
zhLabel: "\u5217\u5BBD",
|
|
909
|
+
description: "\u5217\u5BBD\uFF08\u50CF\u7D20\u6570\u7EC4\uFF0C\u9010\u5217\uFF09\u3002\u9AA8\u67B6\u767D\u540D\u5355\u5185\u7684\u8868\u73B0\u5C5E\u6027\uFF08\u62D6\u62FD\u8C03\u5217\u5BBD\u5373\u5199\u5B83\uFF09\u3002",
|
|
910
|
+
scope: "appearance",
|
|
911
|
+
aiWritable: true
|
|
912
|
+
},
|
|
913
|
+
...TEMPLATE_CELL_STRUCTURE_ATTRS,
|
|
914
|
+
{
|
|
915
|
+
key: "templateCellFixed",
|
|
916
|
+
type: "boolean",
|
|
917
|
+
default: false,
|
|
918
|
+
zhLabel: "\u56FA\u5B9A\u683C",
|
|
919
|
+
description: "\u56FA\u5B9A\u683C\u6807\u8BB0\uFF08\u6E32\u67D3\u4E3A\u53EA\u8BFB\uFF09\u3002\u6A21\u677F\u8BBE\u8BA1\u671F\u914D\u7F6E\uFF0C\u4E0D\u53EF\u6539\u3002",
|
|
920
|
+
scope: "structure",
|
|
921
|
+
aiWritable: false
|
|
922
|
+
},
|
|
923
|
+
{
|
|
924
|
+
key: "templateCellFixedLocal",
|
|
925
|
+
type: "boolean",
|
|
926
|
+
default: false,
|
|
927
|
+
zhLabel: "\u5C40\u90E8\u56FA\u5B9A\u683C",
|
|
928
|
+
description: "\u5C40\u90E8\u56FA\u5B9A\u683C\u6807\u8BB0\u3002\u6A21\u677F\u8BBE\u8BA1\u671F\u914D\u7F6E\uFF0C\u4E0D\u53EF\u6539\u3002",
|
|
929
|
+
scope: "structure",
|
|
930
|
+
aiWritable: false
|
|
931
|
+
},
|
|
932
|
+
{
|
|
933
|
+
key: "cellFormulaEscape",
|
|
934
|
+
type: "boolean",
|
|
935
|
+
default: false,
|
|
936
|
+
zhLabel: "\u516C\u5F0F\u8F6C\u4E49",
|
|
937
|
+
description: "\u5185\u5BB9\u4E3A\u4EE5 = \u5F00\u5934\u7684\u5B57\u9762\u6587\u672C\u65F6\u7684\u8F6C\u4E49\u6807\u8BB0\u3002\u5185\u90E8\u673A\u5236\uFF0C\u4E0D\u53EF\u6539\u3002",
|
|
938
|
+
scope: "identity",
|
|
939
|
+
aiWritable: false
|
|
940
|
+
}
|
|
941
|
+
]),
|
|
942
|
+
entry("tableHeader", "\u6570\u636E\u8868\u683C\u8868\u5934", [
|
|
943
|
+
{
|
|
944
|
+
key: "colspan",
|
|
945
|
+
type: "number",
|
|
946
|
+
default: 1,
|
|
947
|
+
minimum: 1,
|
|
948
|
+
zhLabel: "\u6A2A\u5411\u5408\u5E76",
|
|
949
|
+
description: "\u6A2A\u5411\u8DE8\u8D8A\u5217\u6570\uFF08\u7ED3\u6784\u5C5E\u6027\uFF0C\u4E0D\u53EF\u6539\uFF09\u3002",
|
|
950
|
+
scope: "structure",
|
|
951
|
+
aiWritable: false
|
|
952
|
+
},
|
|
953
|
+
{
|
|
954
|
+
key: "rowspan",
|
|
955
|
+
type: "number",
|
|
956
|
+
default: 1,
|
|
957
|
+
minimum: 1,
|
|
958
|
+
zhLabel: "\u7EB5\u5411\u5408\u5E76",
|
|
959
|
+
description: "\u7EB5\u5411\u8DE8\u8D8A\u884C\u6570\uFF08\u7ED3\u6784\u5C5E\u6027\uFF0C\u4E0D\u53EF\u6539\uFF09\u3002",
|
|
960
|
+
scope: "structure",
|
|
961
|
+
aiWritable: false
|
|
962
|
+
},
|
|
963
|
+
{
|
|
964
|
+
key: "colwidth",
|
|
965
|
+
type: "object",
|
|
966
|
+
default: null,
|
|
967
|
+
zhLabel: "\u5217\u5BBD",
|
|
968
|
+
description: "\u5217\u5BBD\uFF08\u50CF\u7D20\u6570\u7EC4\uFF0C\u9010\u5217\uFF09\u3002\u9AA8\u67B6\u767D\u540D\u5355\u5185\u7684\u8868\u73B0\u5C5E\u6027\u3002",
|
|
969
|
+
scope: "appearance",
|
|
970
|
+
aiWritable: true
|
|
971
|
+
},
|
|
972
|
+
...TEMPLATE_CELL_STRUCTURE_ATTRS,
|
|
973
|
+
{
|
|
974
|
+
key: "templateCellFixed",
|
|
975
|
+
type: "boolean",
|
|
976
|
+
default: false,
|
|
977
|
+
zhLabel: "\u56FA\u5B9A\u683C",
|
|
978
|
+
description: "\u56FA\u5B9A\u683C\u6807\u8BB0\uFF08\u6E32\u67D3\u4E3A\u53EA\u8BFB\uFF09\u3002\u6A21\u677F\u8BBE\u8BA1\u671F\u914D\u7F6E\uFF0C\u4E0D\u53EF\u6539\u3002",
|
|
979
|
+
scope: "structure",
|
|
980
|
+
aiWritable: false
|
|
981
|
+
},
|
|
982
|
+
{
|
|
983
|
+
key: "templateCellFixedLocal",
|
|
984
|
+
type: "boolean",
|
|
985
|
+
default: false,
|
|
986
|
+
zhLabel: "\u5C40\u90E8\u56FA\u5B9A\u683C",
|
|
987
|
+
description: "\u5C40\u90E8\u56FA\u5B9A\u683C\u6807\u8BB0\u3002\u6A21\u677F\u8BBE\u8BA1\u671F\u914D\u7F6E\uFF0C\u4E0D\u53EF\u6539\u3002",
|
|
988
|
+
scope: "structure",
|
|
989
|
+
aiWritable: false
|
|
990
|
+
},
|
|
991
|
+
{
|
|
992
|
+
key: "columnType",
|
|
993
|
+
type: "enum",
|
|
994
|
+
enum: ["text", "select", "date"],
|
|
995
|
+
default: "text",
|
|
996
|
+
zhLabel: "\u5217\u7C7B\u578B",
|
|
997
|
+
description: "\u5217\u8F93\u5165\u63A7\u4EF6\u7C7B\u578B\uFF08text/select/date\uFF09\uFF0C\u9A71\u52A8\u8BE5\u5217\u5355\u5143\u683C\u5F55\u5165\u3002\u6A21\u677F\u8BBE\u8BA1\u671F\u914D\u7F6E\uFF0C\u4E0D\u53EF\u6539\u3002",
|
|
998
|
+
scope: "structure",
|
|
999
|
+
aiWritable: false
|
|
1000
|
+
},
|
|
1001
|
+
{
|
|
1002
|
+
key: "columnOptions",
|
|
1003
|
+
type: "object",
|
|
1004
|
+
default: null,
|
|
1005
|
+
zhLabel: "\u5217\u5019\u9009\u503C",
|
|
1006
|
+
description: "select \u5217\u5019\u9009\u503C\uFF08\u5B57\u7B26\u4E32\u6570\u7EC4\uFF09\u3002\u6A21\u677F\u8BBE\u8BA1\u671F\u914D\u7F6E\uFF0C\u4E0D\u53EF\u6539\u3002",
|
|
1007
|
+
scope: "structure",
|
|
1008
|
+
aiWritable: false
|
|
1009
|
+
},
|
|
1010
|
+
{
|
|
1011
|
+
key: "columnDateFormat",
|
|
1012
|
+
type: "string",
|
|
1013
|
+
default: null,
|
|
1014
|
+
zhLabel: "\u5217\u65E5\u671F\u683C\u5F0F",
|
|
1015
|
+
description: "date \u5217\u65E5\u671F\u683C\u5F0F\u3002\u6A21\u677F\u8BBE\u8BA1\u671F\u914D\u7F6E\uFF0C\u4E0D\u53EF\u6539\u3002",
|
|
1016
|
+
scope: "structure",
|
|
1017
|
+
aiWritable: false
|
|
1018
|
+
}
|
|
1019
|
+
]),
|
|
1020
|
+
// ─── 固定表格(fixedtable 插件)─────────────────────────
|
|
1021
|
+
entry("fixedTable", "\u56FA\u5B9A\u8868\u683C", [
|
|
1022
|
+
{
|
|
1023
|
+
key: "hasRowspan",
|
|
1024
|
+
type: "boolean",
|
|
1025
|
+
default: false,
|
|
1026
|
+
zhLabel: "\u542B\u7EB5\u5411\u5408\u5E76",
|
|
1027
|
+
description: "\u662F\u5426\u5B58\u5728 rowspan>1 \u683C\uFF08rowspanSync \u7EF4\u62A4\u7684\u6D3E\u751F\u503C\uFF0C\u9A71\u52A8\u5BB9\u5668\u6837\u5F0F\uFF09\u3002\u6D3E\u751F\u5C5E\u6027\uFF0C\u4E0D\u53EF\u6539\u3002",
|
|
1028
|
+
scope: "identity",
|
|
1029
|
+
aiWritable: false
|
|
1030
|
+
}
|
|
1031
|
+
]),
|
|
1032
|
+
entry("fixedTableRow", "\u56FA\u5B9A\u8868\u683C\u884C", [
|
|
1033
|
+
{
|
|
1034
|
+
key: "rowHeight",
|
|
1035
|
+
type: "number",
|
|
1036
|
+
default: null,
|
|
1037
|
+
minimum: 24,
|
|
1038
|
+
zhLabel: "\u884C\u9AD8",
|
|
1039
|
+
description: "\u884C\u9AD8\uFF08\u50CF\u7D20\uFF0C\u5EFA\u8BAE 36-48\uFF0C\u4E0D\u5C0F\u4E8E 24\uFF09\u3002\u9AA8\u67B6\u767D\u540D\u5355\u5185\u7684\u8868\u73B0\u5C5E\u6027\uFF0C\u9501\u5B9A\u8868\u683C\u4E5F\u53EF\u6539\u3002",
|
|
1040
|
+
scope: "appearance",
|
|
1041
|
+
aiWritable: true
|
|
1042
|
+
}
|
|
1043
|
+
]),
|
|
1044
|
+
entry("fixedTableCell", "\u56FA\u5B9A\u8868\u683C\u5355\u5143\u683C", [
|
|
1045
|
+
...TEMPLATE_CELL_STRUCTURE_ATTRS,
|
|
1046
|
+
{
|
|
1047
|
+
key: "bold",
|
|
1048
|
+
type: "boolean",
|
|
1049
|
+
default: false,
|
|
1050
|
+
zhLabel: "\u52A0\u7C97",
|
|
1051
|
+
description: "\u6574\u683C\u6587\u5B57\u52A0\u7C97\uFF08\u8868\u5934\u683C\u5E38\u7528\uFF09\u3002",
|
|
1052
|
+
scope: "appearance",
|
|
1053
|
+
aiWritable: true
|
|
1054
|
+
},
|
|
1055
|
+
{
|
|
1056
|
+
key: "backgroundColor",
|
|
1057
|
+
type: "string",
|
|
1058
|
+
default: null,
|
|
1059
|
+
zhLabel: "\u80CC\u666F\u8272",
|
|
1060
|
+
description: "\u5355\u5143\u683C\u80CC\u666F\u8272\uFF08CSS \u989C\u8272\u503C\uFF0C\u5982 #fff7e6\uFF1Bnull \u4E3A\u65E0\u5E95\u8272\uFF09\u3002\u9AA8\u67B6\u767D\u540D\u5355\u5185\u7684\u8868\u73B0\u5C5E\u6027\u3002",
|
|
1061
|
+
scope: "appearance",
|
|
1062
|
+
aiWritable: true
|
|
1063
|
+
},
|
|
1064
|
+
{
|
|
1065
|
+
key: "header",
|
|
1066
|
+
type: "boolean",
|
|
1067
|
+
default: false,
|
|
1068
|
+
zhLabel: "\u5F3A\u8C03\uFF08\u65E7\u7248\uFF09",
|
|
1069
|
+
description: "\u65E7\u7248\u300C\u5F3A\u8C03\u300D\u6807\u8BB0\uFF0C\u6E32\u67D3\u6309\u52A0\u7C97\u5904\u7406\uFF08legacy\uFF0C\u8BF7\u6539\u7528 bold\uFF09\u3002",
|
|
1070
|
+
scope: "appearance",
|
|
1071
|
+
aiWritable: false
|
|
1072
|
+
},
|
|
1073
|
+
{
|
|
1074
|
+
key: "width",
|
|
1075
|
+
type: "number",
|
|
1076
|
+
default: null,
|
|
1077
|
+
minimum: 1,
|
|
1078
|
+
zhLabel: "\u5217\u5BBD",
|
|
1079
|
+
description: "\u5217\u5BBD\uFF08\u5355\u4F4D\u7531 widthUnit \u51B3\u5B9A\uFF1Apercent=\u767E\u5206\u6BD4 1-100\uFF0Cpx=\u50CF\u7D20\uFF1Bnull \u5747\u5206\u5269\u4F59\u7A7A\u95F4\uFF09\u3002\u9AA8\u67B6\u767D\u540D\u5355\u5185\u7684\u8868\u73B0\u5C5E\u6027\u3002",
|
|
1080
|
+
scope: "appearance",
|
|
1081
|
+
aiWritable: true
|
|
1082
|
+
},
|
|
1083
|
+
{
|
|
1084
|
+
key: "widthUnit",
|
|
1085
|
+
type: "enum",
|
|
1086
|
+
enum: ["percent", "px"],
|
|
1087
|
+
default: "percent",
|
|
1088
|
+
zhLabel: "\u5217\u5BBD\u5355\u4F4D",
|
|
1089
|
+
description: "\u5217\u5BBD\u5355\u4F4D\uFF08percent=\u767E\u5206\u6BD4 / px=\u50CF\u7D20\uFF09\uFF0C\u4E0E width \u6210\u5BF9\u8C03\u6574\u3002\u9AA8\u67B6\u767D\u540D\u5355\u5185\u7684\u8868\u73B0\u5C5E\u6027\u3002",
|
|
1090
|
+
scope: "appearance",
|
|
1091
|
+
aiWritable: true
|
|
1092
|
+
},
|
|
1093
|
+
{
|
|
1094
|
+
key: "textAlign",
|
|
1095
|
+
type: "enum",
|
|
1096
|
+
enum: ["left", "center", "right"],
|
|
1097
|
+
default: "left",
|
|
1098
|
+
zhLabel: "\u6C34\u5E73\u5BF9\u9F50",
|
|
1099
|
+
description: "\u5355\u5143\u683C\u6587\u5B57\u6C34\u5E73\u5BF9\u9F50\uFF08\u9AA8\u67B6\u767D\u540D\u5355\u5185\u7684\u8868\u73B0\u5C5E\u6027\uFF09\u3002",
|
|
1100
|
+
scope: "appearance",
|
|
1101
|
+
aiWritable: true
|
|
1102
|
+
},
|
|
1103
|
+
{
|
|
1104
|
+
key: "cellType",
|
|
1105
|
+
type: "enum",
|
|
1106
|
+
enum: ["text", "select", "date"],
|
|
1107
|
+
default: "text",
|
|
1108
|
+
zhLabel: "\u5355\u5143\u683C\u7C7B\u578B",
|
|
1109
|
+
description: "\u8F93\u5165\u63A7\u4EF6\u7C7B\u578B\uFF08text/select/date\uFF09\u3002\u6A21\u677F\u8BBE\u8BA1\u671F\u914D\u7F6E\uFF0C\u4E0D\u53EF\u6539\u3002",
|
|
1110
|
+
scope: "structure",
|
|
1111
|
+
aiWritable: false
|
|
1112
|
+
},
|
|
1113
|
+
{
|
|
1114
|
+
key: "cellOptions",
|
|
1115
|
+
type: "object",
|
|
1116
|
+
default: null,
|
|
1117
|
+
zhLabel: "\u5019\u9009\u503C",
|
|
1118
|
+
description: "select \u683C\u5019\u9009\u503C\uFF08\u5B57\u7B26\u4E32\u6570\u7EC4\uFF09\u3002\u6A21\u677F\u8BBE\u8BA1\u671F\u914D\u7F6E\uFF0C\u4E0D\u53EF\u6539\u3002",
|
|
1119
|
+
scope: "structure",
|
|
1120
|
+
aiWritable: false
|
|
1121
|
+
},
|
|
1122
|
+
{
|
|
1123
|
+
key: "cellDateFormat",
|
|
1124
|
+
type: "string",
|
|
1125
|
+
default: null,
|
|
1126
|
+
zhLabel: "\u65E5\u671F\u683C\u5F0F",
|
|
1127
|
+
description: "date \u683C\u65E5\u671F\u683C\u5F0F\u3002\u6A21\u677F\u8BBE\u8BA1\u671F\u914D\u7F6E\uFF0C\u4E0D\u53EF\u6539\u3002",
|
|
1128
|
+
scope: "structure",
|
|
1129
|
+
aiWritable: false
|
|
1130
|
+
},
|
|
1131
|
+
{
|
|
1132
|
+
key: "rowspan",
|
|
1133
|
+
type: "number",
|
|
1134
|
+
default: 1,
|
|
1135
|
+
minimum: 1,
|
|
1136
|
+
zhLabel: "\u7EB5\u5411\u5408\u5E76",
|
|
1137
|
+
description: "\u7EB5\u5411\u8DE8\u8D8A\u884C\u6570\uFF08\u7ED3\u6784\u5C5E\u6027\uFF0C\u6539\u52A8\u89E6\u53D1\u5E7D\u7075\u683C\u91CD\u5BF9\u9F50\uFF0C\u4E0D\u53EF\u6539\uFF09\u3002",
|
|
1138
|
+
scope: "structure",
|
|
1139
|
+
aiWritable: false
|
|
1140
|
+
},
|
|
1141
|
+
{
|
|
1142
|
+
key: "covered",
|
|
1143
|
+
type: "boolean",
|
|
1144
|
+
default: false,
|
|
1145
|
+
zhLabel: "\u88AB\u8986\u76D6\u683C",
|
|
1146
|
+
description: "\u88AB\u4E0A\u65B9 rowspan \u683C\u8986\u76D6\u7684\u54E8\u5175\u5360\u4F4D\u6807\u8BB0\uFF08\u6D3E\u751F\u9632\u5FA1\u6027\u6807\u8BB0\uFF0C\u4E0D\u53EF\u6539\uFF09\u3002",
|
|
1147
|
+
scope: "identity",
|
|
1148
|
+
aiWritable: false
|
|
1149
|
+
},
|
|
1150
|
+
{
|
|
1151
|
+
key: "spanHeight",
|
|
1152
|
+
type: "number",
|
|
1153
|
+
default: null,
|
|
1154
|
+
zhLabel: "\u5408\u5E76\u4E3B\u683C\u9AD8\u5EA6",
|
|
1155
|
+
description: "\u7EB5\u5411\u5408\u5E76\u4E3B\u683C\u671F\u671B\u9AD8\u5EA6\uFF08rowspanSync \u7EF4\u62A4\u7684\u6D3E\u751F\u503C\uFF0C\u4E0D\u53EF\u6539\uFF09\u3002",
|
|
1156
|
+
scope: "identity",
|
|
1157
|
+
aiWritable: false
|
|
1158
|
+
},
|
|
1159
|
+
{
|
|
1160
|
+
key: "spanOverflow",
|
|
1161
|
+
type: "number",
|
|
1162
|
+
default: null,
|
|
1163
|
+
zhLabel: "\u5408\u5E76\u6EA2\u51FA\u9AD8\u5EA6",
|
|
1164
|
+
description: "\u7EB5\u5411\u5408\u5E76\u4E3B\u683C\u5411\u4E0B\u6EA2\u51FA\u9AD8\u5EA6\uFF08rowspanSync \u7EF4\u62A4\u7684\u6D3E\u751F\u503C\uFF0C\u4E0D\u53EF\u6539\uFF09\u3002",
|
|
1165
|
+
scope: "identity",
|
|
1166
|
+
aiWritable: false
|
|
1167
|
+
}
|
|
1168
|
+
]),
|
|
1169
|
+
// ─── 图形块(graphicblock 工厂三兄弟)──────────────────
|
|
1170
|
+
...["flowchartBlock", "mindmapBlock", "whiteboardBlock"].map((name) => {
|
|
1171
|
+
const zhLabel = name === "flowchartBlock" ? "\u6D41\u7A0B\u56FE" : name === "mindmapBlock" ? "\u601D\u7EF4\u5BFC\u56FE" : "\u767D\u677F";
|
|
1172
|
+
return entry(name, zhLabel, [
|
|
1173
|
+
{
|
|
1174
|
+
key: "width",
|
|
1175
|
+
type: "number",
|
|
1176
|
+
default: null,
|
|
1177
|
+
minimum: 1,
|
|
1178
|
+
zhLabel: "\u5BBD\u5EA6",
|
|
1179
|
+
description: "\u9884\u89C8\u5757\u5BBD\uFF08\u50CF\u7D20\uFF1Bnull \u4E3A\u81EA\u9002\u5E94\uFF09\u3002\u4FDD\u5B58\u65F6\u53D6\u5185\u5BB9\u81EA\u7136\u5C3A\u5BF8\uFF0C\u4E4B\u540E\u53EF\u62D6\u62FD\u8C03\u8282\u3002",
|
|
1180
|
+
scope: "appearance",
|
|
1181
|
+
aiWritable: true
|
|
1182
|
+
},
|
|
1183
|
+
{
|
|
1184
|
+
key: "height",
|
|
1185
|
+
type: "number",
|
|
1186
|
+
default: null,
|
|
1187
|
+
minimum: 1,
|
|
1188
|
+
zhLabel: "\u9AD8\u5EA6",
|
|
1189
|
+
description: "\u9884\u89C8\u5757\u9AD8\uFF08\u50CF\u7D20\uFF1Bnull \u4E3A\u81EA\u9002\u5E94\uFF09\u3002",
|
|
1190
|
+
scope: "appearance",
|
|
1191
|
+
aiWritable: true
|
|
1192
|
+
},
|
|
1193
|
+
{
|
|
1194
|
+
key: "data",
|
|
1195
|
+
type: "string",
|
|
1196
|
+
default: "",
|
|
1197
|
+
zhLabel: "\u56FE\u6570\u636E",
|
|
1198
|
+
description: "\u56FE\u6570\u636E JSON \u5B57\u7B26\u4E32\uFF08\u7531\u5404\u56FE\u753B\u5E03\u7F16\u8F91\u5668\u7EF4\u62A4\uFF0C\u7ED3\u6784\u4E0E\u753B\u5E03\u5B9E\u73B0\u8026\u5408\uFF0CAI \u4E0D\u53EF\u5199\uFF09\u3002",
|
|
1199
|
+
scope: "data",
|
|
1200
|
+
aiWritable: false
|
|
1201
|
+
},
|
|
1202
|
+
{
|
|
1203
|
+
key: "svg",
|
|
1204
|
+
type: "string",
|
|
1205
|
+
default: "",
|
|
1206
|
+
zhLabel: "SVG \u5FEB\u7167",
|
|
1207
|
+
description: "\u9884\u89C8\u6001\u4E0E\u5BFC\u51FA\u8FD8\u539F\u7528\u7684 SVG \u5FEB\u7167\uFF08\u753B\u5E03\u4FDD\u5B58\u65F6\u751F\u6210\uFF0CAI \u4E0D\u53EF\u5199\uFF09\u3002",
|
|
1208
|
+
scope: "data",
|
|
1209
|
+
aiWritable: false
|
|
1210
|
+
}
|
|
1211
|
+
]);
|
|
1212
|
+
}),
|
|
1213
|
+
// ─── 行内标记(mark;仅供知识查询,块级写入 API 不触达)──
|
|
1214
|
+
entry("textStyle", "\u6587\u5B57\u6837\u5F0F", [
|
|
1215
|
+
{
|
|
1216
|
+
key: "color",
|
|
1217
|
+
type: "string",
|
|
1218
|
+
default: null,
|
|
1219
|
+
zhLabel: "\u6587\u5B57\u989C\u8272",
|
|
1220
|
+
description: "\u6587\u5B57\u989C\u8272\uFF08CSS \u989C\u8272\u503C\uFF09\u3002\u884C\u5185\u6807\u8BB0\u5C5E\u6027\uFF1A\u5757\u7EA7\u5C5E\u6027\u5DE5\u5177\u4E0D\u89E6\u8FBE\uFF0C\u9700\u884C\u5185\u547D\u4EE4\u901A\u9053\uFF08\u6682\u672A\u5F00\u653E\uFF09\u3002",
|
|
1221
|
+
scope: "appearance",
|
|
1222
|
+
aiWritable: true
|
|
1223
|
+
}
|
|
1224
|
+
]),
|
|
1225
|
+
entry("highlight", "\u9AD8\u4EAE", [
|
|
1226
|
+
{
|
|
1227
|
+
key: "color",
|
|
1228
|
+
type: "string",
|
|
1229
|
+
default: null,
|
|
1230
|
+
zhLabel: "\u9AD8\u4EAE\u8272",
|
|
1231
|
+
description: "\u6587\u5B57\u9AD8\u4EAE\u80CC\u666F\u8272\uFF08CSS \u989C\u8272\u503C\uFF1Bmulticolor \u5DF2\u5F00\u542F\uFF09\u3002\u884C\u5185\u6807\u8BB0\u5C5E\u6027\uFF1A\u5757\u7EA7\u5C5E\u6027\u5DE5\u5177\u4E0D\u89E6\u8FBE\u3002",
|
|
1232
|
+
scope: "appearance",
|
|
1233
|
+
aiWritable: true
|
|
1234
|
+
}
|
|
1235
|
+
]),
|
|
1236
|
+
entry("link", "\u94FE\u63A5", [
|
|
1237
|
+
{
|
|
1238
|
+
key: "href",
|
|
1239
|
+
type: "string",
|
|
1240
|
+
default: null,
|
|
1241
|
+
zhLabel: "\u94FE\u63A5\u5730\u5740",
|
|
1242
|
+
description: "\u94FE\u63A5 URL\uFF08\u4EC5 http(s)/mailto/tel/ftp/\u76F8\u5BF9\u8DEF\u5F84/\u951A\u70B9\uFF0C\u5371\u9669\u534F\u8BAE\u88AB\u767D\u540D\u5355\u62E6\u622A\uFF09\u3002\u884C\u5185\u6807\u8BB0\u5C5E\u6027\uFF1A\u5757\u7EA7\u5C5E\u6027\u5DE5\u5177\u4E0D\u89E6\u8FBE\u3002",
|
|
1243
|
+
scope: "appearance",
|
|
1244
|
+
aiWritable: true
|
|
1245
|
+
},
|
|
1246
|
+
{
|
|
1247
|
+
key: "target",
|
|
1248
|
+
type: "enum",
|
|
1249
|
+
enum: ["_blank", "_self", "_parent", "_top"],
|
|
1250
|
+
default: "_blank",
|
|
1251
|
+
zhLabel: "\u6253\u5F00\u65B9\u5F0F",
|
|
1252
|
+
description: "\u94FE\u63A5\u6253\u5F00\u65B9\u5F0F\uFF08\u9ED8\u8BA4\u65B0\u7A97\u53E3 _blank\uFF09\u3002\u884C\u5185\u6807\u8BB0\u5C5E\u6027\u3002",
|
|
1253
|
+
scope: "appearance",
|
|
1254
|
+
aiWritable: true
|
|
1255
|
+
},
|
|
1256
|
+
{
|
|
1257
|
+
key: "rel",
|
|
1258
|
+
type: "string",
|
|
1259
|
+
default: "noopener noreferrer",
|
|
1260
|
+
zhLabel: "rel \u5C5E\u6027",
|
|
1261
|
+
description: "\u94FE\u63A5 rel\uFF08\u5B89\u5168\u9ED8\u8BA4\u503C noopener noreferrer\uFF09\u3002\u884C\u5185\u6807\u8BB0\u5C5E\u6027\u3002",
|
|
1262
|
+
scope: "appearance",
|
|
1263
|
+
aiWritable: true
|
|
1264
|
+
}
|
|
1265
|
+
])
|
|
1266
|
+
].map((item) => [item.nodeName, item])
|
|
1267
|
+
);
|
|
1268
|
+
|
|
1269
|
+
// src/editor/copilot/attrMeta/index.ts
|
|
1270
|
+
function getBlockAttrMeta(blockType) {
|
|
1271
|
+
return DESIGNER_BLOCK_ATTRS.filter((meta) => meta.appliesTo.includes(blockType));
|
|
1272
|
+
}
|
|
1273
|
+
function getWritableMeta(blockType, scope) {
|
|
1274
|
+
return getBlockAttrMeta(blockType).filter((meta) => meta.aiWritable && (scope === void 0 || meta.scope === scope));
|
|
1275
|
+
}
|
|
1276
|
+
function formatAttrValue(value) {
|
|
1277
|
+
if (value === void 0) return "undefined";
|
|
1278
|
+
try {
|
|
1279
|
+
return JSON.stringify(value) ?? String(value);
|
|
1280
|
+
} catch {
|
|
1281
|
+
return String(value);
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
function formatAttrDomain(meta) {
|
|
1285
|
+
if (meta.enum) return meta.enum.map(formatAttrValue).join(" / ");
|
|
1286
|
+
if (meta.type === "number") {
|
|
1287
|
+
if (meta.minimum !== void 0 && meta.maximum !== void 0) return `${meta.minimum} ~ ${meta.maximum}`;
|
|
1288
|
+
if (meta.minimum !== void 0) return `\u2265 ${meta.minimum}`;
|
|
1289
|
+
if (meta.maximum !== void 0) return `\u2264 ${meta.maximum}`;
|
|
1290
|
+
return tr("\u6570\u5B57");
|
|
1291
|
+
}
|
|
1292
|
+
if (meta.type === "string") return tr("\u5B57\u7B26\u4E32");
|
|
1293
|
+
if (meta.type === "boolean") return "true / false";
|
|
1294
|
+
return tr("\u5BF9\u8C61/\u6570\u7EC4");
|
|
1295
|
+
}
|
|
1296
|
+
function valueTypeMatches(meta, value) {
|
|
1297
|
+
switch (meta.type) {
|
|
1298
|
+
case "string":
|
|
1299
|
+
return typeof value === "string";
|
|
1300
|
+
case "number":
|
|
1301
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
1302
|
+
case "boolean":
|
|
1303
|
+
return typeof value === "boolean";
|
|
1304
|
+
case "enum":
|
|
1305
|
+
return true;
|
|
1306
|
+
case "object":
|
|
1307
|
+
return typeof value === "object" && value !== null;
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
function validateAttrValue(meta, key, value, schemaToolName = "idocs_tpl_block_schema") {
|
|
1311
|
+
const target = meta.find((item) => item.key === key);
|
|
1312
|
+
if (!target) {
|
|
1313
|
+
return {
|
|
1314
|
+
ok: false,
|
|
1315
|
+
message: tr("\u5C5E\u6027 ${0} \u4E0D\u5728\u53EF\u5199\u6E05\u5355\u5185\uFF08\u5F53\u524D\u503C\uFF1A${1}\uFF1B\u5408\u6CD5\u503C\uFF1A${2}\u3002\u5EFA\u8BAE\uFF1A\u5148\u8C03 ${3} \u67E5\u8BE2\u53EF\u5199\u5C5E\u6027\uFF09", [
|
|
1316
|
+
key,
|
|
1317
|
+
formatAttrValue(value),
|
|
1318
|
+
meta.map((item) => item.key).join("\u3001") || tr("\uFF08\u7A7A\uFF09"),
|
|
1319
|
+
schemaToolName
|
|
1320
|
+
])
|
|
1321
|
+
};
|
|
1322
|
+
}
|
|
1323
|
+
if (!valueTypeMatches(target, value)) {
|
|
1324
|
+
return {
|
|
1325
|
+
ok: false,
|
|
1326
|
+
message: tr("\u5C5E\u6027 ${0} \u7C7B\u578B\u9519\u8BEF\uFF08\u5F53\u524D\u503C\uFF1A${1}\uFF1B\u5408\u6CD5\u503C\uFF1A${2}\u3002\u5EFA\u8BAE\uFF1A\u6309\u5408\u6CD5\u503C\u4FEE\u6B63\u540E\u91CD\u8BD5\uFF09", [
|
|
1327
|
+
key,
|
|
1328
|
+
formatAttrValue(value),
|
|
1329
|
+
formatAttrDomain(target)
|
|
1330
|
+
])
|
|
1331
|
+
};
|
|
1332
|
+
}
|
|
1333
|
+
if (target.type === "enum" && target.enum && !target.enum.some((option) => option === value)) {
|
|
1334
|
+
return {
|
|
1335
|
+
ok: false,
|
|
1336
|
+
message: tr("\u5C5E\u6027 ${0} \u53D6\u503C\u8D8A\u754C\uFF08\u5F53\u524D\u503C\uFF1A${1}\uFF1B\u5408\u6CD5\u503C\uFF1A${2}\u3002\u5EFA\u8BAE\uFF1A\u4ECE\u5408\u6CD5\u503C\u4E2D\u9009\u4E00\u4E2A\u91CD\u8BD5\uFF09", [
|
|
1337
|
+
key,
|
|
1338
|
+
formatAttrValue(value),
|
|
1339
|
+
formatAttrDomain(target)
|
|
1340
|
+
])
|
|
1341
|
+
};
|
|
1342
|
+
}
|
|
1343
|
+
if (target.type === "number" && typeof value === "number" && (target.minimum !== void 0 && value < target.minimum || target.maximum !== void 0 && value > target.maximum)) {
|
|
1344
|
+
return {
|
|
1345
|
+
ok: false,
|
|
1346
|
+
message: tr("\u5C5E\u6027 ${0} \u8D85\u51FA\u53D6\u503C\u8303\u56F4\uFF08\u5F53\u524D\u503C\uFF1A${1}\uFF1B\u5408\u6CD5\u503C\uFF1A${2}\u3002\u5EFA\u8BAE\uFF1A\u8C03\u6574\u5230\u8303\u56F4\u5185\u91CD\u8BD5\uFF09", [
|
|
1347
|
+
key,
|
|
1348
|
+
formatAttrValue(value),
|
|
1349
|
+
formatAttrDomain(target)
|
|
1350
|
+
])
|
|
1351
|
+
};
|
|
1352
|
+
}
|
|
1353
|
+
return { ok: true };
|
|
1354
|
+
}
|
|
1355
|
+
function buildAttrSummary(block) {
|
|
1356
|
+
const summary = {};
|
|
1357
|
+
for (const [key, value] of Object.entries(block)) {
|
|
1358
|
+
if (value !== void 0) summary[key] = value;
|
|
1359
|
+
}
|
|
1360
|
+
return summary;
|
|
1361
|
+
}
|
|
1362
|
+
function getNodeAttrMeta(nodeName) {
|
|
1363
|
+
return EDITOR_NODE_ATTRS[nodeName]?.attrs ?? [];
|
|
1364
|
+
}
|
|
1365
|
+
function getWritableNodeMeta(nodeName) {
|
|
1366
|
+
return getNodeAttrMeta(nodeName).filter((meta) => meta.aiWritable);
|
|
1367
|
+
}
|
|
1368
|
+
function getEditorNodeZhLabel(nodeName) {
|
|
1369
|
+
return EDITOR_NODE_ATTRS[nodeName]?.zhLabel ?? nodeName;
|
|
1370
|
+
}
|
|
1371
|
+
function validateNodeAttrValue(meta, key, value) {
|
|
1372
|
+
return validateAttrValue(meta, key, value, "idocs_doc_block_schema");
|
|
1373
|
+
}
|
|
1374
|
+
function buildNodeAttrSummary(nodeName, attrs) {
|
|
1375
|
+
const registered = new Set(getNodeAttrMeta(nodeName).map((meta) => meta.key));
|
|
1376
|
+
const summary = {};
|
|
1377
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
1378
|
+
if (registered.has(key) && value !== void 0) summary[key] = value;
|
|
1379
|
+
}
|
|
1380
|
+
return summary;
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
// src/editor/usetool/tools/idocsDocBlockSchema.ts
|
|
1384
|
+
var getDocBlockSchemaTool = (context) => ({
|
|
1385
|
+
name: "idocs_doc_block_schema",
|
|
1386
|
+
description: tr(
|
|
1387
|
+
"[idocs\u6587\u6863-\u7F16\u8F91\u5668] \u67E5\u8BE2\u67D0\u7C7B\u8282\u70B9\u53EF\u88AB AI \u8C03\u6574\u7684\u5C5E\u6027\u6E05\u5355\u4E0E\u503C\u57DF\uFF08\u952E\u3001\u4E2D\u6587\u540D\u3001\u7C7B\u578B\u3001\u679A\u4E3E/\u8303\u56F4\u3001\u9ED8\u8BA4\u503C\u3001\u8C03\u4F18\u5EFA\u8BAE\uFF09\u3002\u4FEE\u6539\u8282\u70B9\u5C5E\u6027\u524D\u5148\u8C03\u5B83\u4E86\u89E3\u53EF\u6539\u4EC0\u4E48\uFF1BnodeType \u7F3A\u7701\u4E3A\u5F53\u524D\u5149\u6807\u6240\u5728\u8282\u70B9\u7684\u7C7B\u578B\u3002"
|
|
1388
|
+
),
|
|
1389
|
+
inputSchema: {
|
|
1390
|
+
type: "object",
|
|
1391
|
+
properties: {
|
|
1392
|
+
nodeType: {
|
|
1393
|
+
type: "string",
|
|
1394
|
+
description: tr(
|
|
1395
|
+
"\u53EF\u9009\uFF1A\u8282\u70B9\u7C7B\u578B\uFF08\u5982 heading/paragraph/templateImage/table/fixedTable/fixedTableCell\uFF09\uFF0C\u7F3A\u7701\u4E3A\u5F53\u524D\u5149\u6807\u6240\u5728\u8282\u70B9\u7684\u7C7B\u578B"
|
|
1396
|
+
)
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
},
|
|
1400
|
+
execute: async (args) => {
|
|
1401
|
+
const resolved = resolveEditor(context);
|
|
1402
|
+
if (!resolved.ok) return resolved.result;
|
|
1403
|
+
const editorRef = resolved.value;
|
|
1404
|
+
let nodeType = args.nodeType;
|
|
1405
|
+
if (!nodeType) {
|
|
1406
|
+
const tiptap = editorRef.editor;
|
|
1407
|
+
const located = tiptap ? locateBlockNode(tiptap) : null;
|
|
1408
|
+
if (!located) {
|
|
1409
|
+
return fail(
|
|
1410
|
+
tr(
|
|
1411
|
+
"\u672A\u4F20 nodeType \u4E14\u5F53\u524D\u5149\u6807\u65E0\u6CD5\u5B9A\u4F4D\u5230\u8282\u70B9\uFF1A\u8BF7\u4F20\u5165\u8282\u70B9\u7C7B\u578B\uFF08\u5982 heading\u3001templateImage\u3001fixedTableCell\uFF09\uFF0C\u6216\u5148\u628A\u5149\u6807\u79FB\u5165\u76EE\u6807\u5757"
|
|
1412
|
+
)
|
|
1413
|
+
);
|
|
1414
|
+
}
|
|
1415
|
+
nodeType = located.node.type.name;
|
|
1416
|
+
}
|
|
1417
|
+
const all = getNodeAttrMeta(nodeType);
|
|
1418
|
+
if (all.length === 0) {
|
|
1419
|
+
return fail(
|
|
1420
|
+
tr("\u8282\u70B9\u7C7B\u578B ${0} \u7684\u5C5E\u6027\u6E05\u5355\u672A\u767B\u8BB0\uFF08\u5DF2\u767B\u8BB0\u8282\u70B9\u7C7B\u578B\uFF1A${1}\uFF09", [
|
|
1421
|
+
nodeType,
|
|
1422
|
+
Object.keys(EDITOR_NODE_ATTRS).join("\u3001")
|
|
1423
|
+
])
|
|
1424
|
+
);
|
|
1425
|
+
}
|
|
1426
|
+
const attrs = getWritableNodeMeta(nodeType).map((meta) => ({
|
|
1427
|
+
key: meta.key,
|
|
1428
|
+
zhLabel: meta.zhLabel,
|
|
1429
|
+
type: meta.type,
|
|
1430
|
+
...meta.enum ? { enum: meta.enum } : {},
|
|
1431
|
+
...meta.minimum !== void 0 ? { minimum: meta.minimum } : {},
|
|
1432
|
+
...meta.maximum !== void 0 ? { maximum: meta.maximum } : {},
|
|
1433
|
+
...meta.default !== void 0 ? { default: meta.default } : {},
|
|
1434
|
+
description: meta.description,
|
|
1435
|
+
scope: meta.scope
|
|
1436
|
+
}));
|
|
1437
|
+
const readOnly = all.filter((meta) => !meta.aiWritable).map((meta) => ({ key: meta.key, zhLabel: meta.zhLabel, scope: meta.scope }));
|
|
1438
|
+
return ok(tr("\u8282\u70B9 ${0} \u7684\u53EF\u5199\u5C5E\u6027\u6E05\u5355\uFF08\u5171 ${1} \u9879\uFF09", [nodeType, attrs.length]), {
|
|
1439
|
+
nodeType,
|
|
1440
|
+
attrs,
|
|
1441
|
+
readOnly
|
|
1442
|
+
});
|
|
1443
|
+
}
|
|
1444
|
+
});
|
|
1445
|
+
|
|
1446
|
+
// src/editor/usetool/tools/idocsDocBlockUpdate.ts
|
|
1447
|
+
var getDocBlockUpdateTool = (context) => ({
|
|
1448
|
+
name: "idocs_doc_block_update",
|
|
1449
|
+
description: tr(
|
|
1450
|
+
"[idocs\u6587\u6863-\u7F16\u8F91\u5668] \u4FEE\u6539\u6A21\u677F\u5757\u7684\u8868\u73B0\u7C7B\u5C5E\u6027\uFF08\u6807\u9898\u7EA7\u522B\u3001\u5BF9\u9F50\u3001\u56FE\u7247\u5730\u5740/\u5BBD\u9AD8\u7B49\uFF09\u3002attrs \u4E3A\u5C5E\u6027\u8865\u4E01\u952E\u503C\u5BF9\uFF0C\u5408\u6CD5\u952E\u4E0E\u503C\u57DF\u5148\u8C03 idocs_doc_block_schema \u67E5\u8BE2\uFF1BblockId \u7F3A\u7701\u4E3A\u5F53\u524D\u5149\u6807\u6240\u5728\u6A21\u677F\u5757\u3002\u7ED3\u6784\u5C5E\u6027\uFF08\u5408\u5E76\u5355\u5143\u683C\u3001\u53EF\u586B\u6807\u8BB0\u3001\u6A21\u677F\u914D\u7F6E\uFF09\u4E0D\u53EF\u4FEE\u6539\uFF1B\u884C\u5185\u6587\u5B57\u989C\u8272/\u9AD8\u4EAE/\u94FE\u63A5\u662F\u884C\u5185\u6807\u8BB0\uFF0C\u4E0D\u7ECF\u672C\u5DE5\u5177\u3002"
|
|
1451
|
+
),
|
|
1452
|
+
inputSchema: {
|
|
1453
|
+
type: "object",
|
|
1454
|
+
properties: {
|
|
1455
|
+
blockId: {
|
|
1456
|
+
type: "string",
|
|
1457
|
+
description: tr("\u53EF\u9009\uFF1A\u6A21\u677F\u5185\u5BB9\u5757\u7684\u552F\u4E00\u6807\u8BC6\uFF0C\u7F3A\u7701\u4E3A\u5F53\u524D\u5149\u6807\u6240\u5728\u6A21\u677F\u5757")
|
|
1458
|
+
},
|
|
1459
|
+
attrs: {
|
|
1460
|
+
type: "object",
|
|
1461
|
+
description: tr("\u5C5E\u6027\u8865\u4E01\u952E\u503C\u5BF9\uFF08\u4E3B\u901A\u9053\uFF09\uFF1A\u952E\u4E3A\u8BE5\u8282\u70B9\u7C7B\u578B\u53EF\u5199\u5C5E\u6027\uFF0C\u503C\u987B\u8FC7\u503C\u57DF\u6821\u9A8C")
|
|
1462
|
+
}
|
|
1463
|
+
},
|
|
1464
|
+
required: ["attrs"]
|
|
1465
|
+
},
|
|
1466
|
+
execute: async (args) => {
|
|
1467
|
+
const resolved = resolveEditor(context);
|
|
1468
|
+
if (!resolved.ok) return resolved.result;
|
|
1469
|
+
const editorRef = resolved.value;
|
|
1470
|
+
if (!args.attrs || Object.keys(args.attrs).length === 0) {
|
|
1471
|
+
return fail(tr("\u6CA1\u6709\u8981\u4FEE\u6539\u7684\u5C5E\u6027\uFF08attrs \u4E3A\u7A7A\uFF09"));
|
|
1472
|
+
}
|
|
1473
|
+
let blockId = args.blockId;
|
|
1474
|
+
if (!blockId) {
|
|
1475
|
+
const tiptap = editorRef.editor;
|
|
1476
|
+
const located = tiptap ? locateBlockNode(tiptap) : null;
|
|
1477
|
+
blockId = located?.blockId;
|
|
1478
|
+
if (!blockId) {
|
|
1479
|
+
return fail(
|
|
1480
|
+
tr(
|
|
1481
|
+
"\u672A\u6307\u5B9A blockId\uFF0C\u4E14\u5F53\u524D\u5149\u6807\u4E0D\u5728\u4EFB\u4F55\u6A21\u677F\u5757\u5185\u3002\u5EFA\u8BAE\uFF1A\u5148\u7528 idocs_doc_validate / idocs_doc_apply_template \u62FF\u5230\u76EE\u6807\u5757\u7684 blockId \u4F20\u5165\uFF0C\u6216\u8BA9\u7528\u6237\u628A\u5149\u6807\u79FB\u5230\u76EE\u6807\u5757\u5185"
|
|
1482
|
+
)
|
|
1483
|
+
);
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
const current = editorRef.getBlockAttributes({ blockId });
|
|
1487
|
+
if (!current) {
|
|
1488
|
+
return fail(
|
|
1489
|
+
tr(
|
|
1490
|
+
"\u672A\u627E\u5230 blockId=${0} \u7684\u6A21\u677F\u5757\u3002\u5EFA\u8BAE\uFF1A\u8C03 idocs_doc_validate \u4ECE issues \u6216 idocs_doc_apply_template \u7684 blockIds \u83B7\u53D6\u771F\u5B9E blockId",
|
|
1491
|
+
[blockId]
|
|
1492
|
+
)
|
|
1493
|
+
);
|
|
1494
|
+
}
|
|
1495
|
+
const meta = getNodeAttrMeta(current.nodeType);
|
|
1496
|
+
const writable = getWritableNodeMeta(current.nodeType);
|
|
1497
|
+
const patch = {};
|
|
1498
|
+
for (const [key, value] of Object.entries(args.attrs)) {
|
|
1499
|
+
const knownMeta = meta.find((item) => item.key === key);
|
|
1500
|
+
if (!knownMeta) {
|
|
1501
|
+
const validKeys = writable.map((item) => item.key).join("\u3001");
|
|
1502
|
+
return fail(
|
|
1503
|
+
validKeys ? tr("\u5C5E\u6027 ${0} \u672A\u767B\u8BB0\u4E3A ${1} \u8282\u70B9\u7684\u5C5E\u6027\uFF08\u53EF\u5199\u952E\uFF1A${2}\u3002\u5EFA\u8BAE\uFF1A\u5148\u8C03 idocs_doc_block_schema \u67E5\u8BE2\uFF09", [
|
|
1504
|
+
key,
|
|
1505
|
+
current.nodeType,
|
|
1506
|
+
validKeys
|
|
1507
|
+
]) : tr("${0} \u8282\u70B9\u6CA1\u6709\u767B\u8BB0\u53EF\u5199\u5C5E\u6027\uFF08\u6539\u7ED3\u6784/\u6A21\u677F\u914D\u7F6E\u8BF7\u56DE\u5230\u6A21\u677F\u8BBE\u8BA1\u5668\uFF09", [current.nodeType])
|
|
1508
|
+
);
|
|
1509
|
+
}
|
|
1510
|
+
if (!knownMeta.aiWritable) {
|
|
1511
|
+
if (knownMeta.scope === "structure") {
|
|
1512
|
+
return fail(
|
|
1513
|
+
tr(
|
|
1514
|
+
"\u5C5E\u6027 ${0}\uFF08${1}\uFF09\u4E3A\u7ED3\u6784\u5C5E\u6027\uFF0C\u5C5E\u6A21\u677F\u8BBE\u8BA1\u671F\u914D\u7F6E\uFF0C\u6587\u6863\u7F16\u8F91\u5668\u4FA7\u4E0D\u53EF\u4FEE\u6539\uFF08\u5F53\u524D\u503C\uFF1A${2}\u3002\u5EFA\u8BAE\uFF1A\u5982\u9700\u8C03\u6574\u8BF7\u56DE\u5230\u6A21\u677F\u8BBE\u8BA1\u5668\uFF09",
|
|
1515
|
+
[key, knownMeta.zhLabel, formatAttrValue(current.attrs[key])]
|
|
1516
|
+
)
|
|
1517
|
+
);
|
|
1518
|
+
}
|
|
1519
|
+
if (knownMeta.scope === "identity") {
|
|
1520
|
+
return fail(tr("\u5C5E\u6027 ${0}\uFF08${1}\uFF09\u662F\u8282\u70B9\u7684\u6807\u8BC6\u5C5E\u6027\uFF0C\u4E0D\u53EF\u4FEE\u6539", [key, knownMeta.zhLabel]));
|
|
1521
|
+
}
|
|
1522
|
+
return fail(tr("\u5C5E\u6027 ${0}\uFF08${1}\uFF09\u4E0D\u53EF\u7ECF AI \u4FEE\u6539\uFF1A${2}", [key, knownMeta.zhLabel, knownMeta.description]));
|
|
1523
|
+
}
|
|
1524
|
+
const check = validateNodeAttrValue(writable, key, value);
|
|
1525
|
+
if (!check.ok) return fail(check.message);
|
|
1526
|
+
patch[key] = value;
|
|
1527
|
+
}
|
|
1528
|
+
const result = editorRef.updateBlockAttributes({ blockId }, patch);
|
|
1529
|
+
if (!result.ok) {
|
|
1530
|
+
return fail(tr("\u4FEE\u6539\u672A\u751F\u6548\uFF1A${0}", [result.error ?? tr("\u672A\u77E5\u539F\u56E0")]));
|
|
1531
|
+
}
|
|
1532
|
+
const after = editorRef.getBlockAttributes({ blockId });
|
|
1533
|
+
return ok(tr("\u5757\u300C${0}\u300D\u5C5E\u6027\u5DF2\u8C03\u6574\uFF08${1}\uFF09", [blockId, (result.applied ?? []).join("\u3001")]), {
|
|
1534
|
+
blockId,
|
|
1535
|
+
applied: result.applied ?? [],
|
|
1536
|
+
current: after ? buildNodeAttrSummary(after.nodeType, after.attrs) : {}
|
|
1537
|
+
});
|
|
1538
|
+
}
|
|
1539
|
+
});
|
|
1540
|
+
|
|
1541
|
+
// src/editor/copilot/commandMeta.ts
|
|
1542
|
+
var BUILTIN_PLUGIN_ZH_LABELS = {
|
|
1543
|
+
// content 类
|
|
1544
|
+
heading: tr("\u6807\u9898"),
|
|
1545
|
+
list: tr("\u5217\u8868"),
|
|
1546
|
+
"task-list": tr("\u4EFB\u52A1\u5217\u8868"),
|
|
1547
|
+
blockquote: tr("\u5F15\u7528\u5757"),
|
|
1548
|
+
"code-block": tr("\u4EE3\u7801\u5757"),
|
|
1549
|
+
"horizontal-rule": tr("\u6C34\u5E73\u5206\u5272\u7EBF"),
|
|
1550
|
+
// format 类
|
|
1551
|
+
"text-format": tr("\u6587\u672C\u683C\u5F0F"),
|
|
1552
|
+
"text-color": tr("\u6587\u5B57\u989C\u8272"),
|
|
1553
|
+
highlight: tr("\u9AD8\u4EAE"),
|
|
1554
|
+
"text-align": tr("\u6587\u672C\u5BF9\u9F50"),
|
|
1555
|
+
// media 类
|
|
1556
|
+
table: tr("\u6570\u636E\u8868\u683C"),
|
|
1557
|
+
fixedTable: tr("\u56FA\u5B9A\u8868\u683C"),
|
|
1558
|
+
image: tr("\u56FE\u7247"),
|
|
1559
|
+
flowchart: tr("\u6D41\u7A0B\u56FE"),
|
|
1560
|
+
mindmap: tr("\u601D\u7EF4\u5BFC\u56FE"),
|
|
1561
|
+
whiteboard: tr("\u767D\u677F"),
|
|
1562
|
+
// interaction 类
|
|
1563
|
+
link: tr("\u94FE\u63A5"),
|
|
1564
|
+
mention: tr("\u63D0\u53CA")
|
|
1565
|
+
};
|
|
1566
|
+
function getPluginZhLabel(pluginName) {
|
|
1567
|
+
return BUILTIN_PLUGIN_ZH_LABELS[pluginName] ?? pluginName;
|
|
1568
|
+
}
|
|
1569
|
+
function buildAiCommandCatalog(commands) {
|
|
1570
|
+
return commands.reduce((entries, command) => {
|
|
1571
|
+
const separatorIndex = command.id.indexOf(".");
|
|
1572
|
+
if (separatorIndex <= 0 || separatorIndex === command.id.length - 1) return entries;
|
|
1573
|
+
const plugin = command.id.slice(0, separatorIndex);
|
|
1574
|
+
entries.push({ plugin, pluginZhLabel: getPluginZhLabel(plugin), command });
|
|
1575
|
+
return entries;
|
|
1576
|
+
}, []);
|
|
1577
|
+
}
|
|
1578
|
+
function summarizeCatalog(entries, pluginName) {
|
|
1579
|
+
if (pluginName) {
|
|
1580
|
+
return {
|
|
1581
|
+
mode: "detail",
|
|
1582
|
+
plugin: pluginName,
|
|
1583
|
+
pluginZhLabel: getPluginZhLabel(pluginName),
|
|
1584
|
+
commands: entries.filter((entry2) => entry2.plugin === pluginName).map(({ command }) => ({
|
|
1585
|
+
id: command.id,
|
|
1586
|
+
zhLabel: command.zhLabel,
|
|
1587
|
+
kind: command.kind,
|
|
1588
|
+
description: command.description,
|
|
1589
|
+
// params 为可选声明:未声明就不带该键,避免目录里出现空数组噪音
|
|
1590
|
+
...command.params ? { params: command.params } : {}
|
|
1591
|
+
}))
|
|
1592
|
+
};
|
|
1593
|
+
}
|
|
1594
|
+
const order = [];
|
|
1595
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
1596
|
+
for (const entry2 of entries) {
|
|
1597
|
+
if (!grouped.has(entry2.plugin)) {
|
|
1598
|
+
grouped.set(entry2.plugin, []);
|
|
1599
|
+
order.push(entry2.plugin);
|
|
1600
|
+
}
|
|
1601
|
+
grouped.get(entry2.plugin).push(entry2);
|
|
1602
|
+
}
|
|
1603
|
+
return {
|
|
1604
|
+
mode: "overview",
|
|
1605
|
+
plugins: order.map((plugin) => ({
|
|
1606
|
+
plugin,
|
|
1607
|
+
pluginZhLabel: getPluginZhLabel(plugin),
|
|
1608
|
+
count: grouped.get(plugin).length,
|
|
1609
|
+
ids: grouped.get(plugin).map((entry2) => entry2.command.id)
|
|
1610
|
+
}))
|
|
1611
|
+
};
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
// src/editor/usetool/tools/idocsDocCommandSchema.ts
|
|
1615
|
+
var getDocCommandSchemaTool = (context) => ({
|
|
1616
|
+
name: "idocs_doc_command_schema",
|
|
1617
|
+
description: tr(
|
|
1618
|
+
"[idocs\u6587\u6863-\u7F16\u8F91\u5668] \u67E5\u8BE2\u7F16\u8F91\u5668\u63D2\u4EF6\u5411 AI \u58F0\u660E\u7684\u80FD\u529B\u76EE\u5F55\uFF08\u6807\u8BB0/\u547D\u4EE4/HTML \u5199\u6CD5\u77E5\u8BC6\u6E05\u5355\uFF0C\u6309\u63D2\u4EF6\u5206\u7EC4\uFF09\u3002\u6539\u4E0D\u719F\u6089\u7684\u683C\u5F0F\u3001\u6216\u60F3\u7528\u67D0\u63D2\u4EF6\u80FD\u529B\uFF08\u5217\u8868/\u4EFB\u52A1\u5217\u8868/\u4EE3\u7801\u5757/\u56FE\u7247/\u5BF9\u9F50\u7B49\uFF09\u524D\u5148\u8C03\u672C\u76EE\u5F55\u67E5\u5199\u6CD5\uFF0C\u4E0D\u8981\u51ED\u731C\uFF1Bplugin \u4F20\u63D2\u4EF6\u540D\u8FD4\u56DE\u8BE5\u63D2\u4EF6\u6761\u76EE\u660E\u7EC6\uFF08\u542B\u53C2\u6570\u8BF4\u660E\uFF09\uFF0C\u7F3A\u7701\u8FD4\u56DE\u5404\u63D2\u4EF6\u5206\u7EC4\u6458\u8981\u3002"
|
|
1619
|
+
),
|
|
1620
|
+
inputSchema: {
|
|
1621
|
+
type: "object",
|
|
1622
|
+
properties: {
|
|
1623
|
+
plugin: {
|
|
1624
|
+
type: "string",
|
|
1625
|
+
description: tr(
|
|
1626
|
+
"\u53EF\u9009\uFF1A\u63D2\u4EF6\u540D\uFF08\u5982 heading\u3001list\u3001task-list\u3001code-block\u3001horizontal-rule\u3001image\u3001text-align\uFF09\uFF0C\u4F20\u5165\u8FD4\u56DE\u8BE5\u63D2\u4EF6\u5168\u90E8\u6761\u76EE\u660E\u7EC6\uFF1B\u7F3A\u7701\u8FD4\u56DE\u5404\u63D2\u4EF6\u5206\u7EC4\u6458\u8981"
|
|
1627
|
+
)
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
},
|
|
1631
|
+
execute: async (args) => {
|
|
1632
|
+
const resolved = resolveEditor(context);
|
|
1633
|
+
if (!resolved.ok) return resolved.result;
|
|
1634
|
+
const editorRef = resolved.value;
|
|
1635
|
+
const catalog = buildAiCommandCatalog(editorRef.getAiCommands());
|
|
1636
|
+
if (catalog.length === 0) {
|
|
1637
|
+
return fail(tr("\u5F53\u524D\u7F16\u8F91\u5668\u6CA1\u6709\u5DF2\u542F\u7528\u7684\u63D2\u4EF6\u80FD\u529B\u76EE\u5F55\uFF08\u6240\u6709\u53EF\u58F0\u660E\u63D2\u4EF6\u5747\u672A\u542F\u7528\u6216\u672A\u767B\u8BB0\uFF09"));
|
|
1638
|
+
}
|
|
1639
|
+
const digest = summarizeCatalog(catalog, args.plugin);
|
|
1640
|
+
if (digest.mode === "detail") {
|
|
1641
|
+
if (digest.commands.length === 0) {
|
|
1642
|
+
const known = [...new Set(catalog.map((entry2) => entry2.plugin))];
|
|
1643
|
+
return fail(
|
|
1644
|
+
tr("\u63D2\u4EF6 ${0} \u672A\u767B\u8BB0\u80FD\u529B\u76EE\u5F55\uFF08\u5F53\u524D\u5DF2\u767B\u8BB0\u63D2\u4EF6\uFF1A${1}\u3002\u5EFA\u8BAE\uFF1A\u4ECE\u4E0A\u8FF0\u6E05\u5355\u4E2D\u9009\u62E9\uFF0C\u6216\u5148\u67E5\u7F3A\u7701\u5206\u7EC4\u6458\u8981\uFF09", [
|
|
1645
|
+
args.plugin ?? "",
|
|
1646
|
+
known.join("\u3001")
|
|
1647
|
+
])
|
|
1648
|
+
);
|
|
1649
|
+
}
|
|
1650
|
+
return ok(
|
|
1651
|
+
tr("\u63D2\u4EF6 ${0}\uFF08${1}\uFF09\u7684\u80FD\u529B\u6E05\u5355\uFF08\u5171 ${2} \u6761\uFF09", [digest.plugin, digest.pluginZhLabel, digest.commands.length]),
|
|
1652
|
+
digest
|
|
1653
|
+
);
|
|
1654
|
+
}
|
|
1655
|
+
return ok(
|
|
1656
|
+
tr("\u7F16\u8F91\u5668\u80FD\u529B\u76EE\u5F55\uFF08${0} \u4E2A\u63D2\u4EF6\u3001\u5171 ${1} \u6761\u80FD\u529B\uFF1B\u4F20 plugin \u53C2\u6570\u53EF\u67E5\u5355\u63D2\u4EF6\u660E\u7EC6\uFF09", [
|
|
1657
|
+
digest.plugins.length,
|
|
1658
|
+
catalog.length
|
|
1659
|
+
]),
|
|
1660
|
+
digest
|
|
1661
|
+
);
|
|
1662
|
+
}
|
|
1663
|
+
});
|
|
1664
|
+
|
|
1665
|
+
// src/editor/usetool/tools/idocsDocBlockGenerate.ts
|
|
1666
|
+
var getDocBlockGenerateTool = (context) => ({
|
|
1667
|
+
name: "idocs_doc_block_generate",
|
|
1668
|
+
description: tr(
|
|
1669
|
+
"[idocs\u6587\u6863-\u7F16\u8F91\u5668] \u5728\u6307\u5B9A\u4F4D\u7F6E\u63D2\u5165\u65B0\u7684\u5185\u5BB9\u5757\uFF08HTML\uFF09\uFF0C\u4E0D\u6539\u52A8\u6587\u6863\u73B0\u6709\u5185\u5BB9\u3002position \u7F3A\u7701\u4E3A\u6587\u6863\u672B\u5C3E\u8FFD\u52A0\uFF0C\u4F20 blockId+placement \u63D2\u5230\u6307\u5B9A\u6A21\u677F\u5757\u7684\u524D/\u540E\u3002\u4E0E idocs_doc_set_content \u7684\u5206\u5DE5\uFF1A\u672C\u5DE5\u5177\u505A\u5C40\u90E8\u63D2\u5165\uFF0Cidocs_doc_set_content \u662F\u6574\u7BC7\u91CD\u5199\uFF08\u4F1A\u8986\u76D6\u5168\u90E8\u73B0\u6709\u5185\u5BB9\uFF09\u3002\u5404\u683C\u5F0F\uFF08\u8868\u683C/\u5217\u8868/\u4EE3\u7801\u5757/\u56FE\u7247\u7B49\uFF09\u7684 HTML \u5199\u6CD5\u5148\u8C03 idocs_doc_command_schema \u67E5\u8BE2\uFF1B\u6A21\u677F\u6A21\u5F0F\u4E0B\u63D2\u5165\u5230\u9501\u5B9A\u533A\u4F1A\u88AB\u62D2\u7EDD\u5E76\u8BF4\u660E\u539F\u56E0\u3002"
|
|
1670
|
+
),
|
|
1671
|
+
inputSchema: {
|
|
1672
|
+
type: "object",
|
|
1673
|
+
properties: {
|
|
1674
|
+
html: {
|
|
1675
|
+
type: "string",
|
|
1676
|
+
description: tr("\u8981\u63D2\u5165\u7684\u5757\u7EA7 HTML \u7247\u6BB5\uFF08\u5982 <p>\u2026</p>\u3001<h2>\u2026</h2>\u3001<table>\u2026</table>\uFF09\uFF0C\u5199\u5165\u524D\u4F1A\u505A\u5B89\u5168\u6D88\u6BD2")
|
|
1677
|
+
},
|
|
1678
|
+
position: {
|
|
1679
|
+
type: "object",
|
|
1680
|
+
description: tr("\u53EF\u9009\uFF1A\u63D2\u5165\u4F4D\u7F6E\uFF1B\u7F3A\u7701\u4E3A\u6587\u6863\u672B\u5C3E\u8FFD\u52A0"),
|
|
1681
|
+
properties: {
|
|
1682
|
+
blockId: {
|
|
1683
|
+
type: "string",
|
|
1684
|
+
description: tr("\u76F8\u5BF9\u5B9A\u4F4D\u7684\u6A21\u677F\u5757 blockId\uFF08\u53EA\u80FD\u6765\u81EA\u5DE5\u5177\u8FD4\u56DE\uFF0C\u7981\u6B62\u7F16\u9020\uFF09")
|
|
1685
|
+
},
|
|
1686
|
+
placement: {
|
|
1687
|
+
type: "string",
|
|
1688
|
+
description: tr("before=\u63D2\u5230\u8BE5\u5757\u4E4B\u524D\uFF08\u7F3A\u7701 after=\u63D2\u5230\u8BE5\u5757\u4E4B\u540E\uFF09"),
|
|
1689
|
+
enum: ["before", "after"]
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
},
|
|
1694
|
+
required: ["html"]
|
|
1695
|
+
},
|
|
1696
|
+
execute: async (args) => {
|
|
1697
|
+
const resolved = resolveEditor(context);
|
|
1698
|
+
if (!resolved.ok) return resolved.result;
|
|
1699
|
+
const editorRef = resolved.value;
|
|
1700
|
+
if (!args.html || !args.html.trim()) {
|
|
1701
|
+
return fail(
|
|
1702
|
+
tr(
|
|
1703
|
+
"\u53C2\u6570 html \u4E0D\u80FD\u4E3A\u7A7A\uFF08\u5F53\u524D\u503C\uFF1A${0}\uFF1B\u5408\u6CD5\u503C\uFF1A\u5757\u7EA7 HTML \u7247\u6BB5\u3002\u5EFA\u8BAE\uFF1A\u4F20\u5165\u8981\u63D2\u5165\u7684\u5185\u5BB9\uFF0C\u5199\u6CD5\u5148\u8C03 idocs_doc_command_schema \u67E5\u8BE2\uFF09",
|
|
1704
|
+
[args.html ? tr("\u7A7A\u767D\u5B57\u7B26\u4E32") : tr("\u672A\u63D0\u4F9B")]
|
|
1705
|
+
)
|
|
1706
|
+
);
|
|
1707
|
+
}
|
|
1708
|
+
const position = args.position?.blockId ? { blockId: args.position.blockId, placement: args.position.placement ?? "after" } : { placement: "end" };
|
|
1709
|
+
const result = editorRef.insertBlocksAt(position, args.html);
|
|
1710
|
+
if (!result.ok) {
|
|
1711
|
+
return fail(tr("\u63D2\u5165\u672A\u751F\u6548\uFF1A${0}", [result.error]));
|
|
1712
|
+
}
|
|
1713
|
+
const where = args.position?.blockId ? tr("\u6A21\u677F\u5757 ${0} ${1}", [args.position.blockId, args.position.placement === "before" ? tr("\u4E4B\u524D") : tr("\u4E4B\u540E")]) : tr("\u6587\u6863\u672B\u5C3E");
|
|
1714
|
+
return ok(tr("\u5DF2\u5728${0}\u63D2\u5165 ${1} \u4E2A\u5757\uFF08\u7C7B\u578B\uFF1A${2}\uFF09", [where, result.inserted.length, result.inserted.join("\u3001")]), {
|
|
1715
|
+
inserted: result.inserted
|
|
1716
|
+
});
|
|
1717
|
+
}
|
|
1718
|
+
});
|
|
1719
|
+
|
|
1720
|
+
// src/editor/usetool/tools/idocsDocBlockRemove.ts
|
|
1721
|
+
var getDocBlockRemoveTool = (context) => ({
|
|
1722
|
+
name: "idocs_doc_block_remove",
|
|
1723
|
+
description: tr(
|
|
1724
|
+
"[idocs\u6587\u6863-\u7F16\u8F91\u5668] \u5220\u9664\u4E00\u4E2A\u5185\u5BB9\u5757\u3002blockId \u7F3A\u7701\u4E3A\u5F53\u524D\u5149\u6807\u6240\u5728\u5757\uFF1B\u9501\u5B9A\u5757\uFF08\u6A21\u677F\u9AA8\u67B6\u56FA\u5B9A\u5185\u5BB9\uFF09\u4E0D\u53EF\u5220\u3001\u4F1A\u88AB\u62D2\u7EDD\u5E76\u8BF4\u660E\u539F\u56E0\uFF0C\u6A21\u677F\u81EA\u7531\u533A\u5757\u53EF\u5220\u3002\u79FB\u52A8\u5757\u6CA1\u6709\u4E13\u7528\u5DE5\u5177\uFF1A\u5148\u8BFB\u5185\u5BB9\uFF08idocs_doc_get_content\uFF09\uFF0C\u518D\u7528\u672C\u5DE5\u5177\u5220\u9664\u539F\u5757\uFF0C\u6700\u540E\u7528 idocs_doc_block_generate \u5728\u76EE\u6807\u4F4D\u7F6E\u63D2\u56DE\u3002"
|
|
1725
|
+
),
|
|
1726
|
+
inputSchema: {
|
|
1727
|
+
type: "object",
|
|
1728
|
+
properties: {
|
|
1729
|
+
blockId: {
|
|
1730
|
+
type: "string",
|
|
1731
|
+
description: tr("\u53EF\u9009\uFF1A\u6A21\u677F\u5757 blockId\uFF08\u53EA\u80FD\u6765\u81EA\u5DE5\u5177\u8FD4\u56DE\uFF0C\u7981\u6B62\u7F16\u9020\uFF09\uFF0C\u7F3A\u7701\u4E3A\u5F53\u524D\u5149\u6807\u6240\u5728\u5757")
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
},
|
|
1735
|
+
execute: async (args) => {
|
|
1736
|
+
const resolved = resolveEditor(context);
|
|
1737
|
+
if (!resolved.ok) return resolved.result;
|
|
1738
|
+
const editorRef = resolved.value;
|
|
1739
|
+
if (!args.blockId) {
|
|
1740
|
+
const tiptap = editorRef.editor;
|
|
1741
|
+
const located = tiptap ? locateBlockNode(tiptap) : null;
|
|
1742
|
+
if (!located) {
|
|
1743
|
+
return fail(
|
|
1744
|
+
tr(
|
|
1745
|
+
"\u672A\u6307\u5B9A blockId\uFF0C\u4E14\u5F53\u524D\u5149\u6807\u4E0D\u5728\u4EFB\u4F55\u53EF\u5B9A\u4F4D\u7684\u5757\u5185\u3002\u5EFA\u8BAE\uFF1A\u8BA9\u7528\u6237\u628A\u5149\u6807\u79FB\u5230\u76EE\u6807\u5757\u5185\uFF0C\u6216\u5148\u7528 idocs_doc_validate / idocs_doc_apply_template \u62FF\u5230\u76EE\u6807\u5757\u7684 blockId \u4F20\u5165"
|
|
1746
|
+
)
|
|
1747
|
+
);
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
const result = editorRef.removeBlock(args.blockId);
|
|
1751
|
+
if (!result.ok) {
|
|
1752
|
+
return fail(tr("\u5220\u9664\u672A\u751F\u6548\uFF1A${0}", [result.error]));
|
|
1753
|
+
}
|
|
1754
|
+
return ok(tr("\u5DF2\u5220\u9664\u5757\uFF08\u7C7B\u578B\uFF1A${0}\uFF09", [result.removed]), { removed: result.removed });
|
|
1755
|
+
}
|
|
1756
|
+
});
|
|
1757
|
+
|
|
1758
|
+
// src/editor/usetool/tools/idocsDocMarkUpdate.ts
|
|
1759
|
+
var getDocMarkUpdateTool = (context) => ({
|
|
1760
|
+
name: "idocs_doc_mark_update",
|
|
1761
|
+
description: tr(
|
|
1762
|
+
"[idocs\u6587\u6863-\u7F16\u8F91\u5668] \u5BF9\u5757\u5185\u6587\u5B57\u5E94\u7528\u884C\u5185\u6807\u8BB0\uFF08\u52A0\u7C97/\u659C\u4F53/\u4E0B\u5212\u7EBF/\u5220\u9664\u7EBF/\u884C\u5185\u4EE3\u7801/\u6587\u5B57\u989C\u8272/\u9AD8\u4EAE/\u94FE\u63A5\uFF09\u3002\u951A\u6587\u672C target.anchorText \u5FC5\u987B\u4E0E\u6587\u6863\u539F\u6587\u9010\u5B57\u4E00\u81F4\uFF08\u5927\u5C0F\u5199\u654F\u611F\u3001\u542B\u6807\u70B9\uFF0C\u5EFA\u8BAE\u5148\u8C03 idocs_doc_get_content \u8BFB\u539F\u6587\uFF09\uFF1B\u591A\u5904\u51FA\u73B0\u65F6 occurrence \u7F3A\u7701=\u5168\u90E8\u547D\u4E2D\uFF0C\u4F20\u6B63\u6574\u6570=\u7B2C N \u5904\uFF081 \u8D77\uFF09\u3002marks \u4E3A\u6807\u8BB0\u8865\u4E01\u6570\u7EC4\uFF0C\u5408\u6CD5 id \u4E0E\u53C2\u6570\u5148\u8C03 idocs_doc_command_schema \u67E5\u8BE2\uFF08\u5982 text-color.setColor \u7684 color\u3001link.setLink \u7684 href\uFF09\uFF1B\u6E05\u9664\u8BED\u4E49\u8D70\u5BF9\u5E94\u6761\u76EE\uFF08\u628A\u7EA2\u5B57\u6062\u590D\u9ED8\u8BA4\u8272=text-color.unsetColor\uFF0C\u57FA\u7840\u683C\u5F0F\u4E3A toggle \u8BED\u4E49\u91CD\u590D\u8C03\u7528\u5373\u53D6\u6D88\uFF09\u3002\u9501\u5B9A\u533A\u56FA\u5B9A\u6587\u5B57\u4E0A\u7684\u6807\u8BB0\u4F1A\u88AB\u62D2\u7EDD\u5E76\u8BF4\u660E\u539F\u56E0\u3002"
|
|
1763
|
+
),
|
|
1764
|
+
inputSchema: {
|
|
1765
|
+
type: "object",
|
|
1766
|
+
properties: {
|
|
1767
|
+
blockId: {
|
|
1768
|
+
type: "string",
|
|
1769
|
+
description: tr("\u53EF\u9009\uFF1A\u6A21\u677F\u5757 blockId\uFF08\u53EA\u80FD\u6765\u81EA\u5DE5\u5177\u8FD4\u56DE\uFF0C\u7981\u6B62\u7F16\u9020\uFF09\uFF0C\u7F3A\u7701\u4E3A\u5F53\u524D\u5149\u6807\u6240\u5728\u5757")
|
|
1770
|
+
},
|
|
1771
|
+
target: {
|
|
1772
|
+
type: "object",
|
|
1773
|
+
description: tr("\u951A\u6587\u672C\u5B9A\u4F4D\uFF08\u5757\u5185\u5168\u6587\u7CBE\u786E\u5339\u914D\uFF0C\u8DE8\u683C\u5F0F\u8FB9\u754C\u53EF\u547D\u4E2D\uFF09"),
|
|
1774
|
+
properties: {
|
|
1775
|
+
anchorText: {
|
|
1776
|
+
type: "string",
|
|
1777
|
+
description: tr("\u8981\u6807\u8BB0\u7684\u6587\u5B57\uFF0C\u987B\u4E0E\u6587\u6863\u5185\u5BB9\u9010\u5B57\u4E00\u81F4\uFF08\u5927\u5C0F\u5199\u654F\u611F\u3001\u542B\u6807\u70B9\uFF09")
|
|
1778
|
+
},
|
|
1779
|
+
occurrence: {
|
|
1780
|
+
type: "number",
|
|
1781
|
+
description: tr("\u53EF\u9009\uFF1A\u951A\u6587\u672C\u7B2C\u51E0\u5904\uFF081 \u8D77\u7684\u6B63\u6574\u6570\uFF09\uFF1B\u7F3A\u7701=\u5168\u90E8\u547D\u4E2D\u5904\u90FD\u5E94\u7528")
|
|
1782
|
+
}
|
|
1783
|
+
},
|
|
1784
|
+
required: ["anchorText"]
|
|
1785
|
+
},
|
|
1786
|
+
marks: {
|
|
1787
|
+
type: "array",
|
|
1788
|
+
description: tr(
|
|
1789
|
+
'\u6807\u8BB0\u8865\u4E01\u5217\u8868\uFF08\u81F3\u5C11\u4E00\u6761\uFF0C\u6309\u5E8F\u5E94\u7528\u5230\u6BCF\u5904\u547D\u4E2D\uFF09\uFF1A\u5982 [{id:"text-color.setColor",params:{color:"#ff0000"}}]'
|
|
1790
|
+
),
|
|
1791
|
+
items: {
|
|
1792
|
+
type: "object",
|
|
1793
|
+
properties: {
|
|
1794
|
+
id: {
|
|
1795
|
+
type: "string",
|
|
1796
|
+
description: tr(
|
|
1797
|
+
"\u80FD\u529B\u76EE\u5F55 mark \u7C7B\u6761\u76EE id\uFF08\u5982 text-format.setBold\u3001text-color.setColor\u3001highlight.setHighlight\u3001link.setLink\uFF09"
|
|
1798
|
+
)
|
|
1799
|
+
},
|
|
1800
|
+
params: {
|
|
1801
|
+
type: "object",
|
|
1802
|
+
description: tr(
|
|
1803
|
+
"\u53EF\u9009\uFF1A\u6807\u8BB0\u53C2\u6570\uFF08\u5982 setColor \u7684 color\u3001setLink \u7684 href/target\uFF09\uFF0C\u503C\u57DF\u5148\u67E5 idocs_doc_command_schema"
|
|
1804
|
+
)
|
|
1805
|
+
}
|
|
1806
|
+
},
|
|
1807
|
+
required: ["id"]
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
},
|
|
1811
|
+
required: ["target", "marks"]
|
|
1812
|
+
},
|
|
1813
|
+
execute: async (args) => {
|
|
1814
|
+
const resolved = resolveEditor(context);
|
|
1815
|
+
if (!resolved.ok) return resolved.result;
|
|
1816
|
+
const editorRef = resolved.value;
|
|
1817
|
+
if (!args.target?.anchorText || !args.target.anchorText.trim()) {
|
|
1818
|
+
return fail(
|
|
1819
|
+
tr(
|
|
1820
|
+
"\u53C2\u6570 target.anchorText \u4E0D\u80FD\u4E3A\u7A7A\uFF08\u5F53\u524D\u503C\uFF1A${0}\uFF1B\u5408\u6CD5\u503C\uFF1A\u4E0E\u6587\u6863\u539F\u6587\u5B8C\u5168\u4E00\u81F4\u7684\u6587\u5B57\u3002\u5EFA\u8BAE\uFF1A\u5148\u8C03 idocs_doc_get_content \u8BFB\u539F\u6587\u518D\u5B9A\u4F4D\uFF09",
|
|
1821
|
+
[args.target?.anchorText ? tr("\u7A7A\u767D\u5B57\u7B26\u4E32") : tr("\u672A\u63D0\u4F9B")]
|
|
1822
|
+
)
|
|
1823
|
+
);
|
|
1824
|
+
}
|
|
1825
|
+
if (!Array.isArray(args.marks) || args.marks.length === 0) {
|
|
1826
|
+
return fail(
|
|
1827
|
+
tr(
|
|
1828
|
+
"\u53C2\u6570 marks \u4E0D\u80FD\u4E3A\u7A7A\uFF08\u5F53\u524D\u503C\uFF1A${0}\uFF1B\u5408\u6CD5\u503C\uFF1A\u81F3\u5C11\u4E00\u6761 {id, params?} \u8865\u4E01\u3002\u5EFA\u8BAE\uFF1A\u5408\u6CD5 id \u5148\u8C03 idocs_doc_command_schema \u67E5\u8BE2\uFF09",
|
|
1829
|
+
[Array.isArray(args.marks) ? tr("\u7A7A\u6570\u7EC4") : tr("\u672A\u63D0\u4F9B")]
|
|
1830
|
+
)
|
|
1831
|
+
);
|
|
1832
|
+
}
|
|
1833
|
+
const missingId = args.marks.find((patch) => !patch?.id || typeof patch.id !== "string");
|
|
1834
|
+
if (missingId) {
|
|
1835
|
+
return fail(
|
|
1836
|
+
tr(
|
|
1837
|
+
"marks \u5B58\u5728\u7F3A\u5C11 id \u7684\u6761\u76EE\uFF08\u5F53\u524D\u503C\uFF1A${0}\uFF1B\u5408\u6CD5\u503C\uFF1A\u6BCF\u6761\u90FD\u5E26\u80FD\u529B\u76EE\u5F55 mark \u7C7B\u6761\u76EE id\u3002\u5EFA\u8BAE\uFF1A\u5148\u8C03 idocs_doc_command_schema \u67E5\u8BE2\uFF09",
|
|
1838
|
+
[JSON.stringify(missingId)]
|
|
1839
|
+
)
|
|
1840
|
+
);
|
|
1841
|
+
}
|
|
1842
|
+
const result = editorRef.applyMarksToRange(
|
|
1843
|
+
args.blockId,
|
|
1844
|
+
{
|
|
1845
|
+
anchorText: args.target.anchorText,
|
|
1846
|
+
occurrence: args.target.occurrence ?? "all"
|
|
1847
|
+
},
|
|
1848
|
+
args.marks
|
|
1849
|
+
);
|
|
1850
|
+
if (!result.ok) {
|
|
1851
|
+
return fail(tr("\u6807\u8BB0\u672A\u751F\u6548\uFF1A${0}", [result.error ?? tr("\u672A\u77E5\u539F\u56E0")]), {
|
|
1852
|
+
applied: result.applied
|
|
1853
|
+
});
|
|
1854
|
+
}
|
|
1855
|
+
return ok(tr("\u5DF2\u5E94\u7528\u884C\u5185\u6807\u8BB0\uFF08${0}\uFF09", [(result.applied ?? []).join("\u3001")]), { applied: result.applied ?? [] });
|
|
1856
|
+
}
|
|
1857
|
+
});
|
|
1858
|
+
|
|
1859
|
+
// src/editor/usetool/tools/idocsDocSlotUpdate.ts
|
|
1860
|
+
var BATCH_ENTRY_LIMIT = 100;
|
|
1861
|
+
var getDocSlotUpdateTool = (context) => ({
|
|
1862
|
+
name: "idocs_doc_slot_update",
|
|
1863
|
+
description: tr(
|
|
1864
|
+
"[idocs\u6587\u6863-\u7F16\u8F91\u5668] \u586B\u5199\u6A21\u677F\u69FD\u4F4D\uFF08\u652F\u6301\u6279\u91CF\uFF09\u3002\u76EE\u6807\u4E09\u79CD\u5F62\u6001\u2014\u2014{ slotKey } \u884C\u5185\u6587\u5B57\u69FD\uFF08value=\u6587\u672C\uFF09\u3001{ slotKey } \u6A21\u677F\u56FE\u7247\u69FD\uFF08slotKey \u547D\u4E2D\u56FE\u7247\u8282\u70B9\u65F6 value=\u56FE\u7247\u5730\u5740\uFF09\u3001{ blockId, row, col } \u8868\u683C\u53EF\u586B\u5355\u5143\u683C\uFF08value=\u683C\u5185\u6587\u672C\uFF0C\u6574\u683C\u66FF\u6362\u3001\u6362\u884C\u6298\u53E0\u4E3A\u7A7A\u683C\uFF09\u3002\u63A7\u4EF6\u683C\u53D6\u503C\u89C4\u5219\uFF1A\u6807\u6CE8 \u4E0B\u62C9[...] \u7684\u683C value \u5FC5\u987B\u662F\u9009\u9879\u539F\u6587\u4E4B\u4E00\uFF08\u9009\u9879\u6E05\u5355\u89C1 idocs_doc_get_content \u7684\u53EF\u586B\u683C\u6807\u6CE8\uFF09\uFF1B\u6807\u6CE8 \u65E5\u671F[...] \u7684\u683C value \u63A5\u53D7 2026-01-31 / 2026/1/31 / 2026\u5E741\u670831\u65E5 / 20260131 \u7B49\u5E38\u89C1\u5199\u6CD5\uFF0C\u5199\u5165\u65F6\u81EA\u52A8\u5F52\u4E00\u4E3A\u6807\u6CE8\u683C\u5F0F\u3002\u5355\u6761\u4F20 target+value\uFF1B\u6279\u91CF\u4F20 updates: [{target, value}]\uFF08\u4E00\u6761\u8C03\u7528\u586B\u5B8C\u6574\u4EFD\u8868\u5355\uFF0C\u63A8\u8350\uFF09\u3002slotKey/\u53EF\u586B\u683C\u5750\u6807\u5148\u8C03 idocs_doc_get_content(format=outline) \u67E5\u770B\uFF1Brow/col \u4ECE 0 \u8D77\uFF08row 0=\u8868\u5934\u884C\uFF09\u3002\u9501\u5B9A\u683C/\u516C\u5F0F\u683C\u4E0D\u53EF\u586B\u3001value \u4E0D\u80FD\u4E3A\u7A7A\uFF1B\u586B\u5B8C\u8C03 idocs_doc_validate \u590D\u9A8C\u5FC5\u586B\u9879\u3002"
|
|
1865
|
+
),
|
|
1866
|
+
inputSchema: {
|
|
1867
|
+
type: "object",
|
|
1868
|
+
properties: {
|
|
1869
|
+
target: {
|
|
1870
|
+
type: "object",
|
|
1871
|
+
description: tr("\u5355\u6761\u586B\u5199\u76EE\u6807\uFF1AslotKey\uFF08\u884C\u5185\u69FD/\u56FE\u7247\u69FD\uFF09\u6216 blockId+row+col\uFF08\u8868\u683C\u53EF\u586B\u683C\uFF09\uFF0C\u4E8C\u9009\u4E00"),
|
|
1872
|
+
properties: {
|
|
1873
|
+
slotKey: {
|
|
1874
|
+
type: "string",
|
|
1875
|
+
description: tr(
|
|
1876
|
+
"\u884C\u5185\u69FD/\u6A21\u677F\u56FE\u7247\u7684\u69FD\u4F4D key\uFF08\u53EA\u80FD\u6765\u81EA idocs_doc_get_content(outline) \u6216 idocs_doc_validate\uFF0C\u7981\u6B62\u7F16\u9020\uFF09"
|
|
1877
|
+
)
|
|
1878
|
+
},
|
|
1879
|
+
blockId: {
|
|
1880
|
+
type: "string",
|
|
1881
|
+
description: tr("\u8868\u683C\u6A21\u677F\u5757 blockId\uFF08\u683C\u586B\u5199\u5F62\u6001\u5FC5\u586B\uFF0C\u4E0E row/col \u642D\u914D\uFF09")
|
|
1882
|
+
},
|
|
1883
|
+
row: {
|
|
1884
|
+
type: "number",
|
|
1885
|
+
description: tr("\u5355\u5143\u683C\u884C\u53F7\uFF080 \u8D77\uFF0Crow 0=\u8868\u5934\u884C\uFF09")
|
|
1886
|
+
},
|
|
1887
|
+
col: {
|
|
1888
|
+
type: "number",
|
|
1889
|
+
description: tr("\u5355\u5143\u683C\u5217\u53F7\uFF080 \u8D77\uFF09")
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
},
|
|
1893
|
+
value: {
|
|
1894
|
+
type: "string",
|
|
1895
|
+
description: tr(
|
|
1896
|
+
"\u586B\u5199\u7684\u503C\uFF1A\u884C\u5185\u69FD/\u5355\u5143\u683C=\u6587\u672C\uFF1B\u56FE\u7247\u69FD=\u56FE\u7247\u5730\u5740\uFF08https:// \u6216 data: \u56FE\u7247\u5730\u5740\uFF09\uFF1B\u4E0B\u62C9\u683C=\u9009\u9879\u539F\u6587\u4E4B\u4E00\uFF1B\u65E5\u671F\u683C=\u5E38\u89C1\u65E5\u671F\u5199\u6CD5\uFF08\u81EA\u52A8\u6309\u6A21\u677F\u683C\u5F0F\u5F52\u4E00\uFF09"
|
|
1897
|
+
)
|
|
1898
|
+
},
|
|
1899
|
+
updates: {
|
|
1900
|
+
type: "array",
|
|
1901
|
+
description: tr(
|
|
1902
|
+
"\u6279\u91CF\u586B\u5199\u6761\u76EE\u5217\u8868\uFF08\u63A8\u8350\uFF09\uFF1A\u6BCF\u9879 { target, value }\uFF0Ctarget \u5F62\u6001\u540C\u4E0A\uFF1B\u4E00\u6761\u8C03\u7528\u586B\u5B8C\u6240\u6709\u69FD\u4F4D/\u53EF\u586B\u683C\uFF0C\u6700\u591A ${0} \u6761",
|
|
1903
|
+
[String(BATCH_ENTRY_LIMIT)]
|
|
1904
|
+
),
|
|
1905
|
+
items: {
|
|
1906
|
+
type: "object",
|
|
1907
|
+
properties: {
|
|
1908
|
+
target: {
|
|
1909
|
+
type: "object",
|
|
1910
|
+
description: tr("\u586B\u5199\u76EE\u6807\uFF08slotKey \u6216 blockId+row+col \u4E8C\u9009\u4E00\uFF09"),
|
|
1911
|
+
properties: {
|
|
1912
|
+
slotKey: { type: "string", description: tr("\u884C\u5185\u69FD/\u6A21\u677F\u56FE\u7247\u7684\u69FD\u4F4D key") },
|
|
1913
|
+
blockId: { type: "string", description: tr("\u8868\u683C\u6A21\u677F\u5757 blockId") },
|
|
1914
|
+
row: { type: "number", description: tr("\u884C\u53F7\uFF080 \u8D77\uFF09") },
|
|
1915
|
+
col: { type: "number", description: tr("\u5217\u53F7\uFF080 \u8D77\uFF09") }
|
|
1916
|
+
}
|
|
1917
|
+
},
|
|
1918
|
+
value: {
|
|
1919
|
+
type: "string",
|
|
1920
|
+
description: tr("\u586B\u5199\u7684\u503C\uFF08\u975E\u7A7A\uFF1B\u4E0B\u62C9\u683C=\u9009\u9879\u539F\u6587\u4E4B\u4E00\u3001\u65E5\u671F\u683C=\u5E38\u89C1\u65E5\u671F\u5199\u6CD5\u81EA\u52A8\u5F52\u4E00\uFF09")
|
|
1921
|
+
}
|
|
1922
|
+
},
|
|
1923
|
+
required: ["target", "value"]
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
},
|
|
1928
|
+
execute: async (args) => {
|
|
1929
|
+
const resolved = resolveEditor(context);
|
|
1930
|
+
if (!resolved.ok) return resolved.result;
|
|
1931
|
+
const editorRef = resolved.value;
|
|
1932
|
+
const entries = Array.isArray(args.updates) && args.updates.length > 0 ? args.updates : [{ target: args.target, value: args.value }];
|
|
1933
|
+
if (entries.length > BATCH_ENTRY_LIMIT) {
|
|
1934
|
+
return fail(
|
|
1935
|
+
tr("\u6279\u91CF\u6761\u76EE\u8FC7\u591A\uFF08\u5F53\u524D ${0} \u6761\uFF1B\u5408\u6CD5\u503C\uFF1A\u6700\u591A ${1} \u6761\u3002\u5EFA\u8BAE\uFF1A\u5206\u6279\u63D0\u4EA4\uFF09", [
|
|
1936
|
+
String(entries.length),
|
|
1937
|
+
String(BATCH_ENTRY_LIMIT)
|
|
1938
|
+
])
|
|
1939
|
+
);
|
|
1940
|
+
}
|
|
1941
|
+
const applied = [];
|
|
1942
|
+
const failed = [];
|
|
1943
|
+
entries.forEach((entry2, index) => {
|
|
1944
|
+
const value = entry2.value;
|
|
1945
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
1946
|
+
failed.push({
|
|
1947
|
+
index,
|
|
1948
|
+
error: tr("value \u4E0D\u80FD\u4E3A\u7A7A\uFF08\u5408\u6CD5\u503C\uFF1A\u975E\u7A7A\u6587\u672C/\u56FE\u7247\u5730\u5740\uFF09")
|
|
1949
|
+
});
|
|
1950
|
+
return;
|
|
1951
|
+
}
|
|
1952
|
+
const target = entry2.target ?? {};
|
|
1953
|
+
const hasSlotKey = typeof target.slotKey === "string" && target.slotKey.length > 0;
|
|
1954
|
+
const hasCell = typeof target.blockId === "string" && target.blockId.length > 0 && Number.isInteger(target.row) && Number.isInteger(target.col) && (target.row ?? -1) >= 0 && (target.col ?? -1) >= 0;
|
|
1955
|
+
if (!hasSlotKey && !hasCell) {
|
|
1956
|
+
failed.push({
|
|
1957
|
+
index,
|
|
1958
|
+
error: tr(
|
|
1959
|
+
"target \u5F62\u6001\u4E0D\u5B8C\u6574\uFF08\u5408\u6CD5\u503C\uFF1AslotKey\uFF08\u884C\u5185\u69FD/\u56FE\u7247\u69FD\uFF09\u6216 blockId+row+col\uFF08\u53EF\u586B\u5355\u5143\u683C\uFF09\u4E8C\u9009\u4E00\u4E14\u5B57\u6BB5\u9F50\u5907\u3002\u5EFA\u8BAE\uFF1AslotKey/\u5750\u6807\u4ECE idocs_doc_get_content(format=outline) \u83B7\u53D6\uFF09"
|
|
1960
|
+
)
|
|
1961
|
+
});
|
|
1962
|
+
return;
|
|
1963
|
+
}
|
|
1964
|
+
const result = editorRef.fillSlot(
|
|
1965
|
+
hasSlotKey ? { slotKey: target.slotKey } : {
|
|
1966
|
+
blockId: target.blockId,
|
|
1967
|
+
row: target.row,
|
|
1968
|
+
col: target.col
|
|
1969
|
+
},
|
|
1970
|
+
value
|
|
1971
|
+
);
|
|
1972
|
+
if (result.ok) {
|
|
1973
|
+
applied.push({ index, label: result.label ?? tr("\u69FD\u4F4D"), value: result.value ?? "" });
|
|
1974
|
+
} else {
|
|
1975
|
+
failed.push({ index, error: result.error ?? tr("\u672A\u77E5\u539F\u56E0") });
|
|
1976
|
+
}
|
|
1977
|
+
});
|
|
1978
|
+
if (applied.length === 0) {
|
|
1979
|
+
return fail(tr("\u586B\u5199\u5168\u90E8\u672A\u751F\u6548\uFF08${0} \u6761\uFF09\uFF1A${1}", [String(failed.length), failed[0]?.error ?? tr("\u672A\u77E5\u539F\u56E0")]));
|
|
1980
|
+
}
|
|
1981
|
+
if (failed.length > 0) {
|
|
1982
|
+
return ok(
|
|
1983
|
+
tr("\u6279\u91CF\u586B\u5199\u5B8C\u6210\uFF1A\u6210\u529F ${0} \u9879\uFF0C\u5931\u8D25 ${1} \u9879\uFF08\u5931\u8D25\u660E\u7EC6\u89C1\u8FD4\u56DE\u6570\u636E\uFF0C\u53EF\u4FEE\u6B63\u540E\u91CD\u8BD5\u5931\u8D25\u9879\uFF09", [
|
|
1984
|
+
String(applied.length),
|
|
1985
|
+
String(failed.length)
|
|
1986
|
+
]),
|
|
1987
|
+
{ applied, failed }
|
|
1988
|
+
);
|
|
1989
|
+
}
|
|
1990
|
+
return ok(tr("\u6279\u91CF\u586B\u5199\u5B8C\u6210\uFF1A\u6210\u529F ${0} \u9879", [String(applied.length)]), { applied });
|
|
1991
|
+
}
|
|
1992
|
+
});
|
|
1993
|
+
|
|
1994
|
+
// src/editor/usetool/tools/idocsDocTableOps.ts
|
|
1995
|
+
var getDocTableOpsTool = (context) => ({
|
|
1996
|
+
name: "idocs_doc_table_ops",
|
|
1997
|
+
description: tr(
|
|
1998
|
+
"[idocs\u6587\u6863-\u7F16\u8F91\u5668] \u8868\u683C\u7ED3\u6784\u64CD\u4F5C\uFF1A\u52A0\u884C/\u52A0\u5217/\u5220\u884C/\u5220\u5217/\u5408\u5E76\u5355\u5143\u683C/\u62C6\u5206\u5355\u5143\u683C/\u5207\u6362\u8868\u5934\u884C\uFF08op \u679A\u4E3E\u4EE5 idocs_doc_command_schema \u7684 table \u63D2\u4EF6\u6761\u76EE\u4E3A\u51C6\uFF09\u3002\u5750\u6807 row/col \u4ECE 0 \u8D77\uFF08row 0=\u8868\u5934\u884C\uFF09\uFF1BaddRow/addCol \u7F3A\u7701\u672B\u5C3E\u8FFD\u52A0\uFF0C\u5220/\u5408\u5E76/\u62C6\u5206\u5FC5\u987B\u663E\u5F0F\u7ED9\u5750\u6807\uFF1BmergeCells \u7ED9 (row,col)-(toRow,toCol) \u5BF9\u89D2\u3002\u6570\u636E\u8868\u683C\uFF08\u6A21\u677F\uFF09\u4EC5\u652F\u6301\u6570\u636E\u884C\u589E\u5220\uFF08\u8868\u5934\u884C/\u5217\u7ED3\u6784\u88AB\u6A21\u677F\u9501\u5B9A\uFF0C\u8D8A\u754C\u64CD\u4F5C\u4F1A\u88AB\u62D2\u5E76\u8BF4\u660E\u539F\u56E0\uFF09\uFF1B\u81EA\u7531\u533A\u666E\u901A\u8868\u683C\u5168\u91CF\u53EF\u7528\uFF1B\u56FA\u5B9A\u8868\u683C\u4E0D\u652F\u6301\u7ED3\u6784\u64CD\u4F5C\u2014\u2014\u5176\u884C\u5217\u7ED3\u6784\u5C5E\u6A21\u677F\u8BBE\u8BA1\u671F\uFF08\u53EF\u586B\u5185\u5BB9\u8D70 idocs_doc_slot_update\u3001\u8868\u73B0\u5C5E\u6027\u8D70 idocs_doc_block_update\uFF09\u3002"
|
|
1999
|
+
),
|
|
2000
|
+
inputSchema: {
|
|
2001
|
+
type: "object",
|
|
2002
|
+
properties: {
|
|
2003
|
+
blockId: {
|
|
2004
|
+
type: "string",
|
|
2005
|
+
description: tr("\u53EF\u9009\uFF1A\u8868\u683C\u6A21\u677F\u5757 blockId\uFF08\u53EA\u80FD\u6765\u81EA\u5DE5\u5177\u8FD4\u56DE\uFF0C\u7981\u6B62\u7F16\u9020\uFF09\uFF0C\u7F3A\u7701\u4E3A\u5F53\u524D\u5149\u6807\u6240\u5728\u8868\u683C")
|
|
2006
|
+
},
|
|
2007
|
+
op: {
|
|
2008
|
+
type: "string",
|
|
2009
|
+
description: tr(
|
|
2010
|
+
"\u7ED3\u6784\u64CD\u4F5C\uFF1AaddRow | addCol | deleteRow | deleteCol | mergeCells | splitCell | toggleHeaderRow\uFF08\u5408\u6CD5\u96C6\u4EE5 idocs_doc_command_schema \u67E5\u8BE2 table \u63D2\u4EF6\u4E3A\u51C6\uFF09"
|
|
2011
|
+
)
|
|
2012
|
+
},
|
|
2013
|
+
coords: {
|
|
2014
|
+
type: "object",
|
|
2015
|
+
description: tr(
|
|
2016
|
+
"\u5750\u6807\uFF080 \u8D77\uFF0Crow 0=\u8868\u5934\u884C\uFF09\uFF1AaddRow/addCol \u4F20\u951A\u5B9A row/col\uFF08\u7F3A\u7701\u672B\u5C3E\uFF09\uFF1BdeleteRow/deleteCol \u4F20\u76EE\u6807\uFF1BmergeCells \u4F20 row/col/toRow/toCol\uFF1BsplitCell \u4F20 row/col\uFF1BtoggleHeaderRow \u4E0D\u9700\u8981"
|
|
2017
|
+
),
|
|
2018
|
+
properties: {
|
|
2019
|
+
row: { type: "number", description: tr("\u884C\u53F7\uFF080 \u8D77\uFF0Crow 0=\u8868\u5934\u884C\uFF09") },
|
|
2020
|
+
col: { type: "number", description: tr("\u5217\u53F7\uFF080 \u8D77\uFF09") },
|
|
2021
|
+
toRow: { type: "number", description: tr("\u5408\u5E76\u533A\u57DF\u7EC8\u70B9\u884C\uFF08mergeCells \u7528\uFF0C\u4E0E row \u4EFB\u610F\u5BF9\u89D2\u987A\u5E8F\uFF09") },
|
|
2022
|
+
toCol: { type: "number", description: tr("\u5408\u5E76\u533A\u57DF\u7EC8\u70B9\u5217\uFF08mergeCells \u7528\uFF09") }
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
},
|
|
2026
|
+
required: ["op"]
|
|
2027
|
+
},
|
|
2028
|
+
execute: async (args) => {
|
|
2029
|
+
const resolved = resolveEditor(context);
|
|
2030
|
+
if (!resolved.ok) return resolved.result;
|
|
2031
|
+
const editorRef = resolved.value;
|
|
2032
|
+
if (!args.op || typeof args.op !== "string") {
|
|
2033
|
+
return fail(
|
|
2034
|
+
tr(
|
|
2035
|
+
"\u53C2\u6570 op \u4E0D\u80FD\u4E3A\u7A7A\uFF08\u5F53\u524D\u503C\uFF1A${0}\uFF1B\u5408\u6CD5\u503C\uFF1AaddRow/addCol/deleteRow/deleteCol/mergeCells/splitCell/toggleHeaderRow\u3002\u5EFA\u8BAE\uFF1A\u4EE5 idocs_doc_command_schema \u67E5\u8BE2\u7684 table \u63D2\u4EF6\u6761\u76EE\u4E3A\u51C6\uFF09",
|
|
2036
|
+
[args.op ? tr("\u975E\u6CD5\u7C7B\u578B") : tr("\u672A\u63D0\u4F9B")]
|
|
2037
|
+
)
|
|
2038
|
+
);
|
|
2039
|
+
}
|
|
2040
|
+
const result = editorRef.tableOps(args.blockId, args.op, args.coords);
|
|
2041
|
+
if (!result.ok) {
|
|
2042
|
+
return fail(tr("\u8868\u683C\u64CD\u4F5C\u672A\u751F\u6548\uFF1A${0}", [result.error ?? tr("\u672A\u77E5\u539F\u56E0")]));
|
|
2043
|
+
}
|
|
2044
|
+
return ok(tr("\u8868\u683C\u64CD\u4F5C ${0} \u5DF2\u751F\u6548\uFF08\u5F53\u524D\uFF1A${1}\uFF09", [args.op, result.detail ?? tr("\u7ED3\u6784\u5DF2\u66F4\u65B0")]), {
|
|
2045
|
+
op: args.op,
|
|
2046
|
+
detail: result.detail
|
|
2047
|
+
});
|
|
2048
|
+
}
|
|
2049
|
+
});
|
|
2050
|
+
|
|
2051
|
+
// src/editor/plugins/builtin/flowchart/aiConverter.ts
|
|
2052
|
+
var NODE_WIDTH = 120;
|
|
2053
|
+
var NODE_HEIGHT = 50;
|
|
2054
|
+
var MARGIN = 40;
|
|
2055
|
+
var LAYER_GAP_TD = 80;
|
|
2056
|
+
var INNER_GAP_TD = 60;
|
|
2057
|
+
var LAYER_GAP_LR = 100;
|
|
2058
|
+
var INNER_GAP_LR = 40;
|
|
2059
|
+
var SUPPORTED_SYNTAX = tr(
|
|
2060
|
+
"graph TD/LR \u5F00\u5934\uFF1B\u8282\u70B9 id[\u6587\u672C]/id(\u6587\u672C)\uFF08\u8282\u70B9\u884C\u58F0\u660E\u6216\u8FB9\u884C\u5185\u8054\u58F0\u660E\uFF09\uFF1B\u8FB9 A --> B\u3001A -->|\u6807\u7B7E| B\u3001A --\u6807\u7B7E--> B\u3001A --- B\uFF1B%% \u6CE8\u91CA"
|
|
2061
|
+
);
|
|
2062
|
+
var NODE_ID_PATTERN = /^[\w一-龥-]+$/;
|
|
2063
|
+
var INLINE_COMMENT_PATTERN = /%%.*$/;
|
|
2064
|
+
var NODE_RECT_PATTERN = /^([\w一-龥-]+)\s*\[([^\]]*)\]$/;
|
|
2065
|
+
var NODE_ROUND_PATTERN = /^([\w一-龥-]+)\s*\(([^)]*)\)$/;
|
|
2066
|
+
var EDGE_PIPE_LABEL_PATTERN = /^(.+?)-->\|([^|]*)\|\s*(.+)$/;
|
|
2067
|
+
var EDGE_INLINE_LABEL_PATTERN = /^(.+?)--(.+?)-->\s*(.+)$/;
|
|
2068
|
+
var EDGE_NO_ARROW_PATTERN = /^(.+?)(?<!-)---(?!>)\s*(.+)$/;
|
|
2069
|
+
var EDGE_PLAIN_PATTERN = /^(.+?)(?<!-)-->\s*(.+)$/;
|
|
2070
|
+
var HEADER_PATTERN = /^(?:graph|flowchart)\s+([A-Za-z]{2})\s*$/i;
|
|
2071
|
+
function parseEndpoint(raw) {
|
|
2072
|
+
const segment = raw.trim();
|
|
2073
|
+
const rect = NODE_RECT_PATTERN.exec(segment);
|
|
2074
|
+
if (rect) return { id: rect[1], text: rect[2].trim() || void 0 };
|
|
2075
|
+
const round = NODE_ROUND_PATTERN.exec(segment);
|
|
2076
|
+
if (round) return { id: round[1], text: round[2].trim() || void 0 };
|
|
2077
|
+
if (NODE_ID_PATTERN.test(segment)) return { id: segment };
|
|
2078
|
+
return null;
|
|
2079
|
+
}
|
|
2080
|
+
function shapeForNode(node, total) {
|
|
2081
|
+
if (/^(end|stop|finish)$/i.test(node.id)) return "_type_end";
|
|
2082
|
+
if (node.order === 0) return "_type_start";
|
|
2083
|
+
if (node.order === total - 1) return "_type_end";
|
|
2084
|
+
return "_type_step";
|
|
2085
|
+
}
|
|
2086
|
+
function shapeForEdge(label) {
|
|
2087
|
+
if (!label) return "flow-edge";
|
|
2088
|
+
if (/通过|同意|approve/i.test(label)) return "approve";
|
|
2089
|
+
if (/驳回|拒绝|reject/i.test(label)) return "reject";
|
|
2090
|
+
if (/取消|cancel/i.test(label)) return "cancel";
|
|
2091
|
+
return "flow-edge";
|
|
2092
|
+
}
|
|
2093
|
+
function computeDepths(nodes, edges) {
|
|
2094
|
+
const indegree = /* @__PURE__ */ new Map();
|
|
2095
|
+
const adjacency = /* @__PURE__ */ new Map();
|
|
2096
|
+
nodes.forEach((_, id) => {
|
|
2097
|
+
indegree.set(id, 0);
|
|
2098
|
+
adjacency.set(id, []);
|
|
2099
|
+
});
|
|
2100
|
+
for (const edge of edges) {
|
|
2101
|
+
adjacency.get(edge.source).push(edge.target);
|
|
2102
|
+
indegree.set(edge.target, (indegree.get(edge.target) ?? 0) + 1);
|
|
2103
|
+
}
|
|
2104
|
+
const depth = /* @__PURE__ */ new Map();
|
|
2105
|
+
const queue = [];
|
|
2106
|
+
nodes.forEach((node) => {
|
|
2107
|
+
if ((indegree.get(node.id) ?? 0) === 0) {
|
|
2108
|
+
depth.set(node.id, 0);
|
|
2109
|
+
queue.push(node.id);
|
|
2110
|
+
}
|
|
2111
|
+
});
|
|
2112
|
+
for (let i = 0; i < queue.length; i += 1) {
|
|
2113
|
+
const current = queue[i];
|
|
2114
|
+
for (const next of adjacency.get(current) ?? []) {
|
|
2115
|
+
const candidate = (depth.get(current) ?? 0) + 1;
|
|
2116
|
+
if (candidate > (depth.get(next) ?? -1)) depth.set(next, candidate);
|
|
2117
|
+
const remaining = (indegree.get(next) ?? 0) - 1;
|
|
2118
|
+
indegree.set(next, remaining);
|
|
2119
|
+
if (remaining === 0) queue.push(next);
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
nodes.forEach((node) => {
|
|
2123
|
+
if (!depth.has(node.id)) {
|
|
2124
|
+
const maxDepth = depth.size > 0 ? Math.max(...depth.values()) : -1;
|
|
2125
|
+
depth.set(node.id, maxDepth + 1);
|
|
2126
|
+
}
|
|
2127
|
+
});
|
|
2128
|
+
return depth;
|
|
2129
|
+
}
|
|
2130
|
+
function parseFlowchartMermaid(source) {
|
|
2131
|
+
const lines = (source ?? "").split(/\r?\n/);
|
|
2132
|
+
const fail2 = (error) => ({ ok: false, error });
|
|
2133
|
+
const lineError = (lineNo, content, suggestion) => fail2(
|
|
2134
|
+
tr("\u7B2C ${0} \u884C\u65E0\u6CD5\u89E3\u6790\uFF1A\u300C${1}\u300D\uFF08\u671F\u671B\u8BED\u6CD5\uFF1A${2}\u3002\u5EFA\u8BAE\uFF1A${3}\uFF09", [
|
|
2135
|
+
String(lineNo),
|
|
2136
|
+
content.trim(),
|
|
2137
|
+
SUPPORTED_SYNTAX,
|
|
2138
|
+
suggestion
|
|
2139
|
+
])
|
|
2140
|
+
);
|
|
2141
|
+
let headerLineNo = -1;
|
|
2142
|
+
let direction = null;
|
|
2143
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
2144
|
+
const text = lines[i].replace(INLINE_COMMENT_PATTERN, "").trim();
|
|
2145
|
+
if (!text) continue;
|
|
2146
|
+
headerLineNo = i + 1;
|
|
2147
|
+
const header = HEADER_PATTERN.exec(text);
|
|
2148
|
+
if (header) {
|
|
2149
|
+
const dir = header[1].toUpperCase();
|
|
2150
|
+
if (dir === "TD" || dir === "LR") {
|
|
2151
|
+
direction = dir;
|
|
2152
|
+
} else {
|
|
2153
|
+
return fail2(
|
|
2154
|
+
tr(
|
|
2155
|
+
"\u7B2C ${0} \u884C\u65B9\u5411\u300C${1}\u300D\u4E0D\u652F\u6301\uFF08\u5F53\u524D\u503C\uFF1A${1}\uFF1B\u5408\u6CD5\u503C\uFF1ATD\uFF08\u7EB5\u5411\uFF09/ LR\uFF08\u6A2A\u5411\uFF09\u3002\u5EFA\u8BAE\uFF1A\u6539\u7528 graph TD \u6216 graph LR\uFF09",
|
|
2156
|
+
[String(headerLineNo), dir]
|
|
2157
|
+
)
|
|
2158
|
+
);
|
|
2159
|
+
}
|
|
2160
|
+
} else if (/^(?:graph|flowchart)\b/i.test(text)) {
|
|
2161
|
+
return lineError(headerLineNo, text, tr("\u5934\u90E8\u5199\u6CD5\u4E3A graph TD \u6216 graph LR\uFF08flowchart \u5173\u952E\u5B57\u540C\u6548\uFF09"));
|
|
2162
|
+
} else {
|
|
2163
|
+
return fail2(
|
|
2164
|
+
tr(
|
|
2165
|
+
"\u7B2C ${0} \u884C\u5FC5\u987B\u662F\u56FE\u5F62\u58F0\u660E\uFF08\u5F53\u524D\u503C\uFF1A\u300C${1}\u300D\uFF1B\u671F\u671B\u8BED\u6CD5\uFF1Agraph TD \u6216 graph LR \u5F00\u5934\u3002\u5EFA\u8BAE\uFF1A\u9996\u884C\u5199 graph TD\uFF08\u7EB5\u5411\u6D41\u7A0B\uFF09\u6216 graph LR\uFF08\u6A2A\u5411\u6D41\u7A0B\uFF09\uFF09",
|
|
2166
|
+
[String(headerLineNo), text]
|
|
2167
|
+
)
|
|
2168
|
+
);
|
|
2169
|
+
}
|
|
2170
|
+
break;
|
|
2171
|
+
}
|
|
2172
|
+
if (!direction) {
|
|
2173
|
+
return fail2(
|
|
2174
|
+
tr(
|
|
2175
|
+
"\u5185\u5BB9\u4E3A\u7A7A\uFF08\u5F53\u524D\u503C\uFF1A\u65E0\u6709\u6548\u884C\uFF1B\u671F\u671B\u8BED\u6CD5\uFF1Agraph TD/LR \u5F00\u5934 + \u8282\u70B9/\u8FB9\u884C\u3002\u5EFA\u8BAE\uFF1A\u5148\u5199 graph TD\uFF0C\u518D\u9010\u884C\u58F0\u660E\u8282\u70B9\u4E0E\u8FDE\u7EBF\uFF09"
|
|
2176
|
+
)
|
|
2177
|
+
);
|
|
2178
|
+
}
|
|
2179
|
+
const nodes = /* @__PURE__ */ new Map();
|
|
2180
|
+
const edges = [];
|
|
2181
|
+
const declareNode = (ref, lineNo) => {
|
|
2182
|
+
const existing = nodes.get(ref.id);
|
|
2183
|
+
if (existing) {
|
|
2184
|
+
if (ref.text != null) {
|
|
2185
|
+
return fail2(
|
|
2186
|
+
tr(
|
|
2187
|
+
"\u7B2C ${0} \u884C\uFF1A\u8282\u70B9 ${1} \u91CD\u590D\u5B9A\u4E49\uFF08\u5F53\u524D\u503C\uFF1A\u5DF2\u58F0\u660E\u4E3A\u300C${2}\u300D\uFF1B\u671F\u671B\u8BED\u6CD5\uFF1A\u540C\u4E00 id \u53EA\u58F0\u660E\u4E00\u6B21\u3002\u5EFA\u8BAE\uFF1A\u540E\u4E00\u5904\u6539\u7528\u88F8 id\uFF08${1}\uFF09\u5F15\u7528\uFF09",
|
|
2188
|
+
[String(lineNo), ref.id, existing.text]
|
|
2189
|
+
)
|
|
2190
|
+
);
|
|
2191
|
+
}
|
|
2192
|
+
return null;
|
|
2193
|
+
}
|
|
2194
|
+
nodes.set(ref.id, { id: ref.id, text: ref.text ?? ref.id, order: nodes.size });
|
|
2195
|
+
return null;
|
|
2196
|
+
};
|
|
2197
|
+
for (let i = headerLineNo; i < lines.length; i += 1) {
|
|
2198
|
+
const lineNo = i + 1;
|
|
2199
|
+
const text = lines[i].replace(INLINE_COMMENT_PATTERN, "").trim();
|
|
2200
|
+
if (!text) continue;
|
|
2201
|
+
const pipeLabel = EDGE_PIPE_LABEL_PATTERN.exec(text);
|
|
2202
|
+
const inlineLabel = pipeLabel ? null : EDGE_INLINE_LABEL_PATTERN.exec(text);
|
|
2203
|
+
const noArrow = pipeLabel || inlineLabel ? null : EDGE_NO_ARROW_PATTERN.exec(text);
|
|
2204
|
+
const plain = pipeLabel || inlineLabel || noArrow ? null : EDGE_PLAIN_PATTERN.exec(text);
|
|
2205
|
+
const edgeMatch = pipeLabel ?? inlineLabel ?? noArrow ?? plain;
|
|
2206
|
+
if (edgeMatch) {
|
|
2207
|
+
const label = pipeLabel || inlineLabel ? edgeMatch[2].trim() || void 0 : void 0;
|
|
2208
|
+
const rightRaw = pipeLabel || inlineLabel ? edgeMatch[3] : edgeMatch[2];
|
|
2209
|
+
const sourceRef = parseEndpoint(edgeMatch[1]);
|
|
2210
|
+
const targetParsed = parseEndpoint(rightRaw);
|
|
2211
|
+
if (!sourceRef || !targetParsed) {
|
|
2212
|
+
return lineError(lineNo, text, tr("\u8FB9\u7684\u4E24\u7AEF\u5E94\u4E3A\u5DF2\u58F0\u660E\u8282\u70B9 id \u6216\u5185\u8054\u58F0\u660E\uFF08id[\u6587\u672C]/id(\u6587\u672C)\uFF09"));
|
|
2213
|
+
}
|
|
2214
|
+
if (sourceRef.text == null && !nodes.has(sourceRef.id)) {
|
|
2215
|
+
return fail2(
|
|
2216
|
+
tr(
|
|
2217
|
+
"\u7B2C ${0} \u884C\uFF1A\u8FB9\u5F15\u7528\u4E86\u672A\u58F0\u660E\u7684\u8282\u70B9 ${1}\uFF08\u5F53\u524D\u503C\uFF1A\u672A\u5B9A\u4E49\uFF1B\u671F\u671B\u8BED\u6CD5\uFF1A\u5148\u7528\u8282\u70B9\u884C\u58F0\u660E\uFF08${1}[\u6587\u672C]\uFF09\uFF0C\u6216\u5728\u8FB9\u884C\u5185\u8054\u58F0\u660E\u3002\u5EFA\u8BAE\uFF1A\u628A ${1} \u6539\u4E3A ${1}[\u6587\u672C] \u5185\u8054\u58F0\u660E\uFF09",
|
|
2218
|
+
[String(lineNo), sourceRef.id]
|
|
2219
|
+
)
|
|
2220
|
+
);
|
|
2221
|
+
}
|
|
2222
|
+
if (targetParsed.text == null && !nodes.has(targetParsed.id)) {
|
|
2223
|
+
return fail2(
|
|
2224
|
+
tr(
|
|
2225
|
+
"\u7B2C ${0} \u884C\uFF1A\u8FB9\u5F15\u7528\u4E86\u672A\u58F0\u660E\u7684\u8282\u70B9 ${1}\uFF08\u5F53\u524D\u503C\uFF1A\u672A\u5B9A\u4E49\uFF1B\u671F\u671B\u8BED\u6CD5\uFF1A\u5148\u7528\u8282\u70B9\u884C\u58F0\u660E\uFF08${1}[\u6587\u672C]\uFF09\uFF0C\u6216\u5728\u8FB9\u884C\u5185\u8054\u58F0\u660E\u3002\u5EFA\u8BAE\uFF1A\u628A ${1} \u6539\u4E3A ${1}[\u6587\u672C] \u5185\u8054\u58F0\u660E\uFF09",
|
|
2226
|
+
[String(lineNo), targetParsed.id]
|
|
2227
|
+
)
|
|
2228
|
+
);
|
|
2229
|
+
}
|
|
2230
|
+
const sourceError = declareNode(sourceRef, lineNo);
|
|
2231
|
+
if (sourceError) return sourceError;
|
|
2232
|
+
const targetError = declareNode(targetParsed, lineNo);
|
|
2233
|
+
if (targetError) return targetError;
|
|
2234
|
+
edges.push({ source: sourceRef.id, target: targetParsed.id, label });
|
|
2235
|
+
continue;
|
|
2236
|
+
}
|
|
2237
|
+
const rect = NODE_RECT_PATTERN.exec(text);
|
|
2238
|
+
const round = rect ? null : NODE_ROUND_PATTERN.exec(text);
|
|
2239
|
+
if (rect || round) {
|
|
2240
|
+
const matched = rect ?? round;
|
|
2241
|
+
const ref = { id: matched[1], text: matched[2].trim() || void 0 };
|
|
2242
|
+
const declared = declareNode({ id: ref.id, text: ref.text ?? ref.id }, lineNo);
|
|
2243
|
+
if (declared) return declared;
|
|
2244
|
+
continue;
|
|
2245
|
+
}
|
|
2246
|
+
if (NODE_ID_PATTERN.test(text)) {
|
|
2247
|
+
const declared = declareNode({ id: text }, lineNo);
|
|
2248
|
+
if (declared) return declared;
|
|
2249
|
+
continue;
|
|
2250
|
+
}
|
|
2251
|
+
return lineError(lineNo, text, tr("subgraph/style/class/\u83F1\u5F62\u7B49\u8BED\u6CD5\u4E0D\u5728\u652F\u6301\u96C6\u5185\uFF0C\u8BF7\u6539\u7528\u652F\u6301\u96C6\u8BED\u6CD5\u91CD\u5199\u8BE5\u884C"));
|
|
2252
|
+
}
|
|
2253
|
+
if (nodes.size === 0) {
|
|
2254
|
+
return fail2(
|
|
2255
|
+
tr(
|
|
2256
|
+
"\u672A\u58F0\u660E\u4EFB\u4F55\u8282\u70B9\uFF08\u5F53\u524D\u503C\uFF1A0 \u4E2A\u8282\u70B9\uFF1B\u671F\u671B\u8BED\u6CD5\uFF1A\u81F3\u5C11\u4E00\u4E2A\u8282\u70B9\u884C\uFF08id[\u6587\u672C]\uFF09\u6216\u4E00\u6761\u5185\u8054\u58F0\u660E\u7684\u8FB9\u3002\u5EFA\u8BAE\uFF1A\u8865\u5145\u8282\u70B9\u58F0\u660E\uFF0C\u5982 start[\u5F00\u59CB] --> end[\u7ED3\u675F]\uFF09"
|
|
2257
|
+
)
|
|
2258
|
+
);
|
|
2259
|
+
}
|
|
2260
|
+
const depth = computeDepths(nodes, edges);
|
|
2261
|
+
const layers = /* @__PURE__ */ new Map();
|
|
2262
|
+
nodes.forEach((node) => {
|
|
2263
|
+
const level = depth.get(node.id) ?? 0;
|
|
2264
|
+
if (!layers.has(level)) layers.set(level, []);
|
|
2265
|
+
layers.get(level).push(node);
|
|
2266
|
+
});
|
|
2267
|
+
const sortedLayers = [...layers.entries()].sort((a, b) => a[0] - b[0]);
|
|
2268
|
+
const positions = /* @__PURE__ */ new Map();
|
|
2269
|
+
if (direction === "TD") {
|
|
2270
|
+
const layerWidths = sortedLayers.map(
|
|
2271
|
+
([, layerNodes]) => layerNodes.length * NODE_WIDTH + (layerNodes.length - 1) * INNER_GAP_TD
|
|
2272
|
+
);
|
|
2273
|
+
const maxWidth = Math.max(...layerWidths);
|
|
2274
|
+
sortedLayers.forEach(([, layerNodes], layerIndex) => {
|
|
2275
|
+
const offsetX = MARGIN + (maxWidth - layerWidths[layerIndex]) / 2;
|
|
2276
|
+
layerNodes.forEach((node, index) => {
|
|
2277
|
+
positions.set(node.id, {
|
|
2278
|
+
x: offsetX + index * (NODE_WIDTH + INNER_GAP_TD),
|
|
2279
|
+
y: MARGIN + layerIndex * (NODE_HEIGHT + LAYER_GAP_TD)
|
|
2280
|
+
});
|
|
2281
|
+
});
|
|
2282
|
+
});
|
|
2283
|
+
} else {
|
|
2284
|
+
const layerHeights = sortedLayers.map(
|
|
2285
|
+
([, layerNodes]) => layerNodes.length * NODE_HEIGHT + (layerNodes.length - 1) * INNER_GAP_LR
|
|
2286
|
+
);
|
|
2287
|
+
const maxHeight = Math.max(...layerHeights);
|
|
2288
|
+
sortedLayers.forEach(([, layerNodes], layerIndex) => {
|
|
2289
|
+
const offsetY = MARGIN + (maxHeight - layerHeights[layerIndex]) / 2;
|
|
2290
|
+
layerNodes.forEach((node, index) => {
|
|
2291
|
+
positions.set(node.id, {
|
|
2292
|
+
x: MARGIN + layerIndex * (NODE_WIDTH + LAYER_GAP_LR),
|
|
2293
|
+
y: offsetY + index * (NODE_HEIGHT + INNER_GAP_LR)
|
|
2294
|
+
});
|
|
2295
|
+
});
|
|
2296
|
+
});
|
|
2297
|
+
}
|
|
2298
|
+
const cells = [];
|
|
2299
|
+
nodes.forEach((node) => {
|
|
2300
|
+
const position = positions.get(node.id);
|
|
2301
|
+
cells.push({
|
|
2302
|
+
id: node.id,
|
|
2303
|
+
shape: shapeForNode(node, nodes.size),
|
|
2304
|
+
position,
|
|
2305
|
+
size: { width: NODE_WIDTH, height: NODE_HEIGHT },
|
|
2306
|
+
attrs: { text: { text: node.text } }
|
|
2307
|
+
});
|
|
2308
|
+
});
|
|
2309
|
+
edges.forEach((edge, index) => {
|
|
2310
|
+
cells.push({
|
|
2311
|
+
id: `edge-${index + 1}`,
|
|
2312
|
+
shape: shapeForEdge(edge.label),
|
|
2313
|
+
source: { cell: edge.source },
|
|
2314
|
+
target: { cell: edge.target },
|
|
2315
|
+
...edge.label ? { labels: [{ attrs: { label: { text: edge.label } } }] } : {}
|
|
2316
|
+
});
|
|
2317
|
+
});
|
|
2318
|
+
return {
|
|
2319
|
+
ok: true,
|
|
2320
|
+
data: { cells },
|
|
2321
|
+
stats: { nodes: nodes.size, edges: edges.length }
|
|
2322
|
+
};
|
|
2323
|
+
}
|
|
2324
|
+
|
|
2325
|
+
// src/editor/plugins/builtin/mindmap/aiConverter.ts
|
|
2326
|
+
var HEADER_PATTERN2 = /^mindmap\s*$/i;
|
|
2327
|
+
var INLINE_COMMENT_PATTERN2 = /%%.*$/;
|
|
2328
|
+
var DOUBLE_ROUND_PATTERN = /^\(\((.*)\)\)$/;
|
|
2329
|
+
var SQUARE_PATTERN = /^\[(.*)\]$/;
|
|
2330
|
+
var ROUND_PATTERN = /^\((.*)\)$/;
|
|
2331
|
+
function stripModifier(raw) {
|
|
2332
|
+
const doubleRound = DOUBLE_ROUND_PATTERN.exec(raw);
|
|
2333
|
+
if (doubleRound) return doubleRound[1].trim();
|
|
2334
|
+
const square = SQUARE_PATTERN.exec(raw);
|
|
2335
|
+
if (square) return square[1].trim();
|
|
2336
|
+
const round = ROUND_PATTERN.exec(raw);
|
|
2337
|
+
if (round) return round[1].trim();
|
|
2338
|
+
return raw;
|
|
2339
|
+
}
|
|
2340
|
+
function measureIndent(line) {
|
|
2341
|
+
let indent = 0;
|
|
2342
|
+
for (const ch of line) {
|
|
2343
|
+
if (ch === " ") indent += 1;
|
|
2344
|
+
else if (ch === " ") indent += 2;
|
|
2345
|
+
else break;
|
|
2346
|
+
}
|
|
2347
|
+
return indent;
|
|
2348
|
+
}
|
|
2349
|
+
function parseMindmapMermaid(source) {
|
|
2350
|
+
const lines = (source ?? "").split(/\r?\n/);
|
|
2351
|
+
const fail2 = (error) => ({ ok: false, error });
|
|
2352
|
+
let headerLineNo = -1;
|
|
2353
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
2354
|
+
const text = lines[i].replace(INLINE_COMMENT_PATTERN2, "").trim();
|
|
2355
|
+
if (!text) continue;
|
|
2356
|
+
if (!HEADER_PATTERN2.test(text)) {
|
|
2357
|
+
return fail2(
|
|
2358
|
+
tr(
|
|
2359
|
+
"\u7B2C ${0} \u884C\u5FC5\u987B\u662F\u601D\u7EF4\u5BFC\u56FE\u58F0\u660E\uFF08\u5F53\u524D\u503C\uFF1A\u300C${1}\u300D\uFF1B\u671F\u671B\u8BED\u6CD5\uFF1Amindmap \u72EC\u5360\u4E00\u884C\u5F00\u5934\u3002\u5EFA\u8BAE\uFF1A\u9996\u884C\u5199 mindmap\uFF0C\u4E4B\u540E\u6BCF\u884C\u4E00\u4E2A\u8282\u70B9\u3001\u7528\u7F29\u8FDB\u8868\u8FBE\u7236\u5B50\u5C42\u7EA7\uFF09",
|
|
2360
|
+
[String(i + 1), text]
|
|
2361
|
+
)
|
|
2362
|
+
);
|
|
2363
|
+
}
|
|
2364
|
+
headerLineNo = i + 1;
|
|
2365
|
+
break;
|
|
2366
|
+
}
|
|
2367
|
+
if (headerLineNo < 0) {
|
|
2368
|
+
return fail2(
|
|
2369
|
+
tr(
|
|
2370
|
+
"\u5185\u5BB9\u4E3A\u7A7A\uFF08\u5F53\u524D\u503C\uFF1A\u65E0\u6709\u6548\u884C\uFF1B\u671F\u671B\u8BED\u6CD5\uFF1Amindmap \u5F00\u5934 + \u7F29\u8FDB\u8282\u70B9\u6811\u3002\u5EFA\u8BAE\uFF1A\u9996\u884C\u5199 mindmap\uFF0C\u7B2C\u4E8C\u884C\u8D77\u5199\u6839\u8282\u70B9\u4E0E\u5B50\u8282\u70B9\uFF09"
|
|
2371
|
+
)
|
|
2372
|
+
);
|
|
2373
|
+
}
|
|
2374
|
+
const stack = [];
|
|
2375
|
+
let root = null;
|
|
2376
|
+
let rootIndent = 0;
|
|
2377
|
+
let count = 0;
|
|
2378
|
+
for (let i = headerLineNo; i < lines.length; i += 1) {
|
|
2379
|
+
const lineNo = i + 1;
|
|
2380
|
+
const raw = lines[i].replace(INLINE_COMMENT_PATTERN2, "");
|
|
2381
|
+
const text = raw.trim();
|
|
2382
|
+
if (!text) continue;
|
|
2383
|
+
const indent = measureIndent(raw);
|
|
2384
|
+
const nodeText = stripModifier(text);
|
|
2385
|
+
if (!nodeText) {
|
|
2386
|
+
return fail2(
|
|
2387
|
+
tr(
|
|
2388
|
+
"\u7B2C ${0} \u884C\u8282\u70B9\u6587\u672C\u4E3A\u7A7A\uFF08\u5F53\u524D\u503C\uFF1A\u300C${1}\u300D\uFF1B\u671F\u671B\u8BED\u6CD5\uFF1A\u6BCF\u884C\u4E00\u4E2A\u975E\u7A7A\u8282\u70B9\u6587\u672C\uFF0C\u53EF\u5E26 ((\u6587\u672C))/[\u6587\u672C]/(\u6587\u672C) \u4FEE\u9970\u7B26\u3002\u5EFA\u8BAE\uFF1A\u8865\u4E0A\u8282\u70B9\u6587\u5B57\uFF09",
|
|
2389
|
+
[String(lineNo), text]
|
|
2390
|
+
)
|
|
2391
|
+
);
|
|
2392
|
+
}
|
|
2393
|
+
const node = { data: { text: nodeText }, children: [] };
|
|
2394
|
+
count += 1;
|
|
2395
|
+
if (!root) {
|
|
2396
|
+
root = node;
|
|
2397
|
+
rootIndent = indent;
|
|
2398
|
+
stack.push({ indent, node });
|
|
2399
|
+
continue;
|
|
2400
|
+
}
|
|
2401
|
+
const top = stack[stack.length - 1];
|
|
2402
|
+
if (indent > top.indent) {
|
|
2403
|
+
top.node.children.push(node);
|
|
2404
|
+
stack.push({ indent, node });
|
|
2405
|
+
continue;
|
|
2406
|
+
}
|
|
2407
|
+
while (stack.length > 0 && stack[stack.length - 1].indent > indent) stack.pop();
|
|
2408
|
+
if (stack.length === 0) {
|
|
2409
|
+
return fail2(
|
|
2410
|
+
tr("\u7B2C ${0} \u884C\u7F29\u8FDB\u8D8A\u8FC7\u4E86\u6839\u8282\u70B9\uFF08\u5F53\u524D\u503C\uFF1A\u7F29\u8FDB ${1}\uFF0C\u6839\u8282\u70B9\u7F29\u8FDB ${2}\uFF1B\u5EFA\u8BAE\uFF1A\u8282\u70B9\u7F29\u8FDB\u4E0D\u5F97\u5C0F\u4E8E\u6839\u8282\u70B9\u7F29\u8FDB\uFF09", [
|
|
2411
|
+
String(lineNo),
|
|
2412
|
+
String(indent),
|
|
2413
|
+
String(rootIndent)
|
|
2414
|
+
])
|
|
2415
|
+
);
|
|
2416
|
+
}
|
|
2417
|
+
const levelTop = stack[stack.length - 1];
|
|
2418
|
+
if (levelTop.indent === indent) {
|
|
2419
|
+
stack.pop();
|
|
2420
|
+
const parent = stack[stack.length - 1];
|
|
2421
|
+
if (!parent) {
|
|
2422
|
+
return fail2(
|
|
2423
|
+
tr(
|
|
2424
|
+
"\u7B2C ${0} \u884C\u4E0E\u6839\u8282\u70B9\u540C\u7EA7\uFF08\u5F53\u524D\u503C\uFF1A\u7F29\u8FDB ${1}\uFF1B\u5408\u6CD5\u503C\uFF1A\u601D\u7EF4\u5BFC\u56FE\u53EA\u652F\u6301\u5355\u4E2A\u6839\u8282\u70B9\u3002\u5EFA\u8BAE\uFF1A\u628A\u8BE5\u884C\u6539\u4E3A\u6839\u8282\u70B9\u7684\u5B50\u8282\u70B9\uFF08\u589E\u52A0\u7F29\u8FDB\uFF09\uFF0C\u6216\u5E76\u5165\u5DF2\u6709\u5206\u652F\uFF09",
|
|
2425
|
+
[String(lineNo), String(indent)]
|
|
2426
|
+
)
|
|
2427
|
+
);
|
|
2428
|
+
}
|
|
2429
|
+
parent.node.children.push(node);
|
|
2430
|
+
stack.push({ indent, node });
|
|
2431
|
+
continue;
|
|
2432
|
+
}
|
|
2433
|
+
return fail2(
|
|
2434
|
+
tr(
|
|
2435
|
+
"\u7B2C ${0} \u884C\u7F29\u8FDB\u5C42\u7EA7\u672A\u5BF9\u9F50\uFF08\u5F53\u524D\u503C\uFF1A\u7F29\u8FDB ${1}\uFF1B\u5408\u6CD5\u503C\uFF1A\u4E0E\u67D0\u4E00\u5C42\u5144\u5F1F\u8282\u70B9\u7F29\u8FDB\u4E00\u81F4\uFF0C\u6216\u6BD4\u7236\u7EA7\u66F4\u6DF1\u3002\u5F53\u524D\u5C42\u7EA7\u94FE\u7F29\u8FDB\uFF1A${2}\u3002\u5EFA\u8BAE\uFF1A\u4E0E\u76EE\u6807\u7236\u7EA7\u7684\u5B50\u8282\u70B9\u4FDD\u6301\u76F8\u540C\u7F29\u8FDB\uFF09",
|
|
2436
|
+
[String(lineNo), String(indent), stack.map((entry2) => entry2.indent).join(" < ")]
|
|
2437
|
+
)
|
|
2438
|
+
);
|
|
2439
|
+
}
|
|
2440
|
+
if (!root) {
|
|
2441
|
+
return fail2(
|
|
2442
|
+
tr(
|
|
2443
|
+
"\u601D\u7EF4\u5BFC\u56FE\u81F3\u5C11\u9700\u8981\u4E00\u4E2A\u6839\u8282\u70B9\uFF08\u5F53\u524D\u503C\uFF1A0 \u4E2A\u8282\u70B9\uFF1B\u671F\u671B\u8BED\u6CD5\uFF1Amindmap \u5934\u4E4B\u540E\u6BCF\u884C\u4E00\u4E2A\u8282\u70B9\u6587\u672C\uFF0C\u7F29\u8FDB\u8868\u7236\u5B50\u3002\u5EFA\u8BAE\uFF1A\u7B2C\u4E8C\u884C\u5199\u6839\u8282\u70B9\u4E3B\u9898\uFF0C\u540E\u7EED\u884C\u7F29\u8FDB\u5199\u5206\u652F\uFF09"
|
|
2444
|
+
)
|
|
2445
|
+
);
|
|
2446
|
+
}
|
|
2447
|
+
return { ok: true, data: root, stats: { nodes: count } };
|
|
2448
|
+
}
|
|
2449
|
+
|
|
2450
|
+
// src/editor/plugins/builtin/shared/graphicblock/offscreenSnapshot.ts
|
|
2451
|
+
var OFFSCREEN_TIMEOUT_MS = 5e3;
|
|
2452
|
+
var OFFSCREEN_WIDTH = 800;
|
|
2453
|
+
var OFFSCREEN_HEIGHT = 600;
|
|
2454
|
+
function createOffscreenHost() {
|
|
2455
|
+
const host = document.createElement("div");
|
|
2456
|
+
host.style.cssText = `position:fixed;left:-99999px;top:-99999px;width:${OFFSCREEN_WIDTH}px;height:${OFFSCREEN_HEIGHT}px;overflow:hidden;visibility:hidden;`;
|
|
2457
|
+
document.body.appendChild(host);
|
|
2458
|
+
return host;
|
|
2459
|
+
}
|
|
2460
|
+
function withTimeout(promise) {
|
|
2461
|
+
return new Promise((resolve, reject) => {
|
|
2462
|
+
const timer = setTimeout(() => reject(new Error("offscreen snapshot timeout")), OFFSCREEN_TIMEOUT_MS);
|
|
2463
|
+
promise.then(
|
|
2464
|
+
(value) => {
|
|
2465
|
+
clearTimeout(timer);
|
|
2466
|
+
resolve(value);
|
|
2467
|
+
},
|
|
2468
|
+
(err) => {
|
|
2469
|
+
clearTimeout(timer);
|
|
2470
|
+
reject(err instanceof Error ? err : new Error(String(err)));
|
|
2471
|
+
}
|
|
2472
|
+
);
|
|
2473
|
+
});
|
|
2474
|
+
}
|
|
2475
|
+
async function renderFlowchartSvg(data) {
|
|
2476
|
+
let host = null;
|
|
2477
|
+
let graph = null;
|
|
2478
|
+
try {
|
|
2479
|
+
const [{ Graph }, { Export }, { registerFlowShapes }] = await Promise.all([
|
|
2480
|
+
import('@antv/x6'),
|
|
2481
|
+
import('@antv/x6-plugin-export'),
|
|
2482
|
+
import('./shapes-5SMSF6ML.mjs')
|
|
2483
|
+
]);
|
|
2484
|
+
registerFlowShapes();
|
|
2485
|
+
host = createOffscreenHost();
|
|
2486
|
+
const flowGraph = new Graph({
|
|
2487
|
+
container: host,
|
|
2488
|
+
width: OFFSCREEN_WIDTH,
|
|
2489
|
+
height: OFFSCREEN_HEIGHT,
|
|
2490
|
+
async: false
|
|
2491
|
+
});
|
|
2492
|
+
flowGraph.use(new Export());
|
|
2493
|
+
graph = flowGraph;
|
|
2494
|
+
flowGraph.fromJSON({ cells: data.cells ?? [] });
|
|
2495
|
+
const raw = await withTimeout(
|
|
2496
|
+
new Promise((resolve) => {
|
|
2497
|
+
flowGraph.toSVG((svgString) => resolve(svgString), {
|
|
2498
|
+
copyStyles: false,
|
|
2499
|
+
preserveDimensions: true,
|
|
2500
|
+
// viewBox 取内容包围盒四周留白 16px(与 FlowchartEditor.handleSave 同参数同理由)
|
|
2501
|
+
viewBox: (() => {
|
|
2502
|
+
const box = flowGraph.getContentArea();
|
|
2503
|
+
const PAD = 16;
|
|
2504
|
+
return {
|
|
2505
|
+
x: box.x - PAD,
|
|
2506
|
+
y: box.y - PAD,
|
|
2507
|
+
width: box.width + PAD * 2,
|
|
2508
|
+
height: box.height + PAD * 2
|
|
2509
|
+
};
|
|
2510
|
+
})()
|
|
2511
|
+
});
|
|
2512
|
+
})
|
|
2513
|
+
);
|
|
2514
|
+
const doc = new DOMParser().parseFromString(raw, "image/svg+xml");
|
|
2515
|
+
if (doc.querySelector("parsererror") || doc.documentElement.tagName.toLowerCase() !== "svg") {
|
|
2516
|
+
return null;
|
|
2517
|
+
}
|
|
2518
|
+
const result = finalizeSvgRoot(doc.documentElement, {
|
|
2519
|
+
stripSelectors: [".x6-port", ".x6-port-body", ".x6-cell-tool", ".x6-cell-tools"],
|
|
2520
|
+
forceAspectRatio: true
|
|
2521
|
+
});
|
|
2522
|
+
return result.svg || null;
|
|
2523
|
+
} catch {
|
|
2524
|
+
return null;
|
|
2525
|
+
} finally {
|
|
2526
|
+
try {
|
|
2527
|
+
graph?.dispose();
|
|
2528
|
+
} catch {
|
|
2529
|
+
}
|
|
2530
|
+
host?.remove();
|
|
2531
|
+
}
|
|
2532
|
+
}
|
|
2533
|
+
async function renderMindmapSvg(data) {
|
|
2534
|
+
let host = null;
|
|
2535
|
+
let mindMap = null;
|
|
2536
|
+
try {
|
|
2537
|
+
const [mindMapModule, exportModule, constantsModule] = await Promise.all([
|
|
2538
|
+
import('simple-mind-map'),
|
|
2539
|
+
import('simple-mind-map/src/plugins/Export.js'),
|
|
2540
|
+
import('./mindmapConstants-X75XUXV3.mjs')
|
|
2541
|
+
]);
|
|
2542
|
+
await import('simple-mind-map/dist/simpleMindMap.esm.css').catch(() => void 0);
|
|
2543
|
+
const MindMapCtor = mindMapModule.default;
|
|
2544
|
+
MindMapCtor.usePlugin(
|
|
2545
|
+
exportModule.default
|
|
2546
|
+
);
|
|
2547
|
+
host = createOffscreenHost();
|
|
2548
|
+
const instance = new MindMapCtor({
|
|
2549
|
+
el: host,
|
|
2550
|
+
data,
|
|
2551
|
+
layout: "logicalStructure",
|
|
2552
|
+
themeConfig: constantsModule.THEME_CONFIG
|
|
2553
|
+
});
|
|
2554
|
+
mindMap = instance;
|
|
2555
|
+
await withTimeout(
|
|
2556
|
+
new Promise((resolve) => {
|
|
2557
|
+
const done = () => resolve();
|
|
2558
|
+
instance.on("node_tree_render_end", done);
|
|
2559
|
+
if (instance.renderer?.root) {
|
|
2560
|
+
instance.off("node_tree_render_end", done);
|
|
2561
|
+
resolve();
|
|
2562
|
+
}
|
|
2563
|
+
})
|
|
2564
|
+
);
|
|
2565
|
+
const dataUrl = await withTimeout(instance.export("svg", false, "mindmap"));
|
|
2566
|
+
const raw = decodeSvgDataUri(dataUrl);
|
|
2567
|
+
if (!raw) return null;
|
|
2568
|
+
const doc = new DOMParser().parseFromString(raw, "image/svg+xml");
|
|
2569
|
+
if (doc.querySelector("parsererror") || doc.documentElement.tagName.toLowerCase() !== "svg") {
|
|
2570
|
+
return null;
|
|
2571
|
+
}
|
|
2572
|
+
const result = finalizeSvgRoot(doc.documentElement, { stripSelectors: [".smm-hover-node"] });
|
|
2573
|
+
return result.svg || null;
|
|
2574
|
+
} catch {
|
|
2575
|
+
return null;
|
|
2576
|
+
} finally {
|
|
2577
|
+
try {
|
|
2578
|
+
mindMap?.destroy();
|
|
2579
|
+
} catch {
|
|
2580
|
+
}
|
|
2581
|
+
host?.remove();
|
|
2582
|
+
}
|
|
2583
|
+
}
|
|
2584
|
+
|
|
2585
|
+
// src/editor/usetool/tools/idocsDocDiagramGenerate.ts
|
|
2586
|
+
var GENERATOR_IDS = {
|
|
2587
|
+
flowchart: "flowchart.generate",
|
|
2588
|
+
mindmap: "mindmap.generate"
|
|
2589
|
+
};
|
|
2590
|
+
var getDocDiagramGenerateTool = (context) => ({
|
|
2591
|
+
name: "idocs_doc_diagram_generate",
|
|
2592
|
+
description: tr(
|
|
2593
|
+
"[idocs\u6587\u6863-\u7F16\u8F91\u5668] \u7531 Mermaid \u5B50\u96C6 DSL \u751F\u6210\u6D41\u7A0B\u56FE/\u601D\u7EF4\u5BFC\u56FE\u5757\u5E76\u63D2\u5165\u6587\u6863\uFF0C\u4E0D\u52A8\u73B0\u6709\u5185\u5BB9\u3002kind=flowchart \u5B50\u96C6\uFF1Agraph TD/LR \u5F00\u5934\uFF0C\u8282\u70B9 id[\u6587\u672C]/id(\u6587\u672C)\uFF08\u8282\u70B9\u884C\u58F0\u660E\u6216\u8FB9\u884C\u5185\u8054\u58F0\u660E\uFF09\uFF0C\u8FB9 A --> B\u3001A -->|\u6807\u7B7E| B\u3001A --\u6807\u7B7E--> B\u3001A --- B\uFF08\u8FB9\u6807\u7B7E\u542B\u300C\u901A\u8FC7/\u540C\u610F\u300D\u6620\u5C04\u5BA1\u6279\u8FB9\u3001\u300C\u9A73\u56DE/\u62D2\u7EDD\u300D\u6620\u5C04\u9A73\u56DE\u8FB9\u3001\u300C\u53D6\u6D88\u300D\u6620\u5C04\u53D6\u6D88\u8FB9\uFF09\u3002kind=mindmap \u5B50\u96C6\uFF1Amindmap \u5F00\u5934 + \u7F29\u8FDB\u6811\uFF08\u6BCF\u884C\u4E00\u4E2A\u8282\u70B9\uFF0C\u7F29\u8FDB\u5C42\u7EA7\u5373\u7236\u5B50\uFF0C\u5355\u6839\uFF09\u3002\u5B8C\u6574\u8BED\u6CD5\u4E0E\u793A\u4F8B\u5148 invoke_skill \u67E5\u770B\uFF1B\u8BED\u6CD5\u9519\u8BEF\u4F1A\u8FD4\u56DE\u884C\u53F7\u4E0E\u671F\u671B\u8BED\u6CD5\uFF0C\u4FEE\u6B63\u540E\u91CD\u8BD5\u5373\u53EF\u3002position \u7F3A\u7701\u4E3A\u6587\u6863\u672B\u5C3E\u8FFD\u52A0\uFF1B\u6A21\u677F\u6A21\u5F0F\u4E0B\u63D2\u5165\u5230\u9501\u5B9A\u533A\u4F1A\u88AB\u62D2\u7EDD\u5E76\u8BF4\u660E\u539F\u56E0\u3002\u751F\u6210\u540E\u7528\u6237\u53EF\u70B9\u5F00\u753B\u5E03\u7EE7\u7EED\u7F16\u8F91\u3002"
|
|
2594
|
+
),
|
|
2595
|
+
inputSchema: {
|
|
2596
|
+
type: "object",
|
|
2597
|
+
properties: {
|
|
2598
|
+
kind: {
|
|
2599
|
+
type: "string",
|
|
2600
|
+
description: tr("\u56FE\u5F62\u79CD\u7C7B\uFF1Aflowchart=\u6D41\u7A0B\u56FE / mindmap=\u601D\u7EF4\u5BFC\u56FE"),
|
|
2601
|
+
enum: ["flowchart", "mindmap"]
|
|
2602
|
+
},
|
|
2603
|
+
mermaid: {
|
|
2604
|
+
type: "string",
|
|
2605
|
+
description: tr(
|
|
2606
|
+
"Mermaid \u5B50\u96C6 DSL \u6587\u672C\uFF08\u8BED\u6CD5\u5B50\u96C6\u89C1\u5DE5\u5177\u63CF\u8FF0\u4E0E idocs_doc_command_schema \u7684 generator \u6761\u76EE\uFF1B\u5B8C\u6574\u8BED\u6CD5\u5148 invoke_skill \u6216\u770B\u62A5\u9519\u63D0\u793A\uFF09"
|
|
2607
|
+
)
|
|
2608
|
+
},
|
|
2609
|
+
position: {
|
|
2610
|
+
type: "object",
|
|
2611
|
+
description: tr("\u53EF\u9009\uFF1A\u63D2\u5165\u4F4D\u7F6E\uFF1B\u7F3A\u7701\u4E3A\u6587\u6863\u672B\u5C3E\u8FFD\u52A0"),
|
|
2612
|
+
properties: {
|
|
2613
|
+
blockId: {
|
|
2614
|
+
type: "string",
|
|
2615
|
+
description: tr("\u76F8\u5BF9\u5B9A\u4F4D\u7684\u6A21\u677F\u5757 blockId\uFF08\u53EA\u80FD\u6765\u81EA\u5DE5\u5177\u8FD4\u56DE\uFF0C\u7981\u6B62\u7F16\u9020\uFF09")
|
|
2616
|
+
},
|
|
2617
|
+
placement: {
|
|
2618
|
+
type: "string",
|
|
2619
|
+
description: tr("before=\u63D2\u5230\u8BE5\u5757\u4E4B\u524D\uFF08\u7F3A\u7701 after=\u63D2\u5230\u8BE5\u5757\u4E4B\u540E\uFF09"),
|
|
2620
|
+
enum: ["before", "after"]
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2623
|
+
}
|
|
2624
|
+
},
|
|
2625
|
+
required: ["kind", "mermaid"]
|
|
2626
|
+
},
|
|
2627
|
+
execute: async (args) => {
|
|
2628
|
+
const resolved = resolveEditor(context);
|
|
2629
|
+
if (!resolved.ok) return resolved.result;
|
|
2630
|
+
const editorRef = resolved.value;
|
|
2631
|
+
if (args.kind !== "flowchart" && args.kind !== "mindmap") {
|
|
2632
|
+
return fail(
|
|
2633
|
+
tr(
|
|
2634
|
+
"\u53C2\u6570 kind \u975E\u6CD5\uFF08\u5F53\u524D\u503C\uFF1A${0}\uFF1B\u5408\u6CD5\u503C\uFF1Aflowchart\uFF08\u6D41\u7A0B\u56FE\uFF09/ mindmap\uFF08\u601D\u7EF4\u5BFC\u56FE\uFF09\u3002\u5EFA\u8BAE\uFF1A\u6309\u7528\u6237\u8981\u7684\u56FE\u5F62\u79CD\u7C7B\u9009\u62E9\uFF09",
|
|
2635
|
+
[args.kind ? String(args.kind) : tr("\u672A\u63D0\u4F9B")]
|
|
2636
|
+
)
|
|
2637
|
+
);
|
|
2638
|
+
}
|
|
2639
|
+
const kind = args.kind;
|
|
2640
|
+
if (!args.mermaid || !args.mermaid.trim()) {
|
|
2641
|
+
return fail(
|
|
2642
|
+
tr(
|
|
2643
|
+
"\u53C2\u6570 mermaid \u4E0D\u80FD\u4E3A\u7A7A\uFF08\u5F53\u524D\u503C\uFF1A${0}\uFF1B\u5408\u6CD5\u503C\uFF1AMermaid \u5B50\u96C6 DSL \u6587\u672C\u3002\u5EFA\u8BAE\uFF1A\u5B50\u96C6\u8BED\u6CD5\u5148\u8C03 idocs_doc_command_schema \u67E5 ${1} \u6761\u76EE\uFF0C\u6216 invoke_skill \u770B\u5B8C\u6574\u793A\u4F8B\uFF09",
|
|
2644
|
+
[args.mermaid ? tr("\u7A7A\u767D\u5B57\u7B26\u4E32") : tr("\u672A\u63D0\u4F9B"), GENERATOR_IDS[kind]]
|
|
2645
|
+
)
|
|
2646
|
+
);
|
|
2647
|
+
}
|
|
2648
|
+
const generatorId = GENERATOR_IDS[kind];
|
|
2649
|
+
const generatorAvailable = editorRef.getAiCommands().some((command) => command.kind === "generator" && command.id === generatorId);
|
|
2650
|
+
if (!generatorAvailable) {
|
|
2651
|
+
return fail(
|
|
2652
|
+
tr("${0}\u63D2\u4EF6\u672A\u542F\u7528\uFF08\u80FD\u529B\u76EE\u5F55\u65E0 ${1} \u6761\u76EE\uFF09\uFF0C\u65E0\u6CD5\u751F\u6210\u56FE\u5F62\u5757\u3002\u5EFA\u8BAE\uFF1A\u6539\u7528\u6587\u5B57/\u8868\u683C\u8868\u8FBE\uFF0C\u6216\u8054\u7CFB\u7BA1\u7406\u5458\u542F\u7528\u8BE5\u63D2\u4EF6", [
|
|
2653
|
+
kind === "flowchart" ? tr("\u6D41\u7A0B\u56FE") : tr("\u601D\u7EF4\u5BFC\u56FE"),
|
|
2654
|
+
generatorId
|
|
2655
|
+
])
|
|
2656
|
+
);
|
|
2657
|
+
}
|
|
2658
|
+
let diagram;
|
|
2659
|
+
if (kind === "flowchart") {
|
|
2660
|
+
const parsed = parseFlowchartMermaid(args.mermaid);
|
|
2661
|
+
if (!parsed.ok) return fail(parsed.error);
|
|
2662
|
+
diagram = {
|
|
2663
|
+
kind,
|
|
2664
|
+
data: parsed.data,
|
|
2665
|
+
svg: await renderFlowchartSvg(parsed.data),
|
|
2666
|
+
stats: parsed.stats
|
|
2667
|
+
};
|
|
2668
|
+
} else {
|
|
2669
|
+
const parsed = parseMindmapMermaid(args.mermaid);
|
|
2670
|
+
if (!parsed.ok) return fail(parsed.error);
|
|
2671
|
+
diagram = {
|
|
2672
|
+
kind,
|
|
2673
|
+
data: parsed.data,
|
|
2674
|
+
svg: await renderMindmapSvg(parsed.data),
|
|
2675
|
+
stats: parsed.stats
|
|
2676
|
+
};
|
|
2677
|
+
}
|
|
2678
|
+
const position = args.position?.blockId ? { blockId: args.position.blockId, placement: args.position.placement ?? "after" } : { placement: "end" };
|
|
2679
|
+
const result = editorRef.insertDiagram(diagram, position);
|
|
2680
|
+
if (!result.ok) {
|
|
2681
|
+
return fail(tr("\u63D2\u5165\u672A\u751F\u6548\uFF1A${0}", [result.error ?? tr("\u672A\u77E5\u539F\u56E0")]));
|
|
2682
|
+
}
|
|
2683
|
+
const edgeCount = "edges" in diagram.stats ? diagram.stats.edges : void 0;
|
|
2684
|
+
const kindLabel = kind === "flowchart" ? tr("\u6D41\u7A0B\u56FE") : tr("\u601D\u7EF4\u5BFC\u56FE");
|
|
2685
|
+
const statsLabel = edgeCount != null ? tr("${0} \u4E2A\u8282\u70B9\u3001${1} \u6761\u8FDE\u7EBF", [String(diagram.stats.nodes), String(edgeCount)]) : tr("${0} \u4E2A\u8282\u70B9", [String(diagram.stats.nodes)]);
|
|
2686
|
+
return ok(
|
|
2687
|
+
diagram.svg ? tr("\u5DF2\u751F\u6210${0}\u5757\uFF08${1}\uFF0C\u542B\u9884\u89C8\u5FEB\u7167\uFF09\u3002\u7528\u6237\u53EF\u70B9\u5F00\u753B\u5E03\u7EE7\u7EED\u7F16\u8F91", [kindLabel, statsLabel]) : tr("\u5DF2\u751F\u6210${0}\u5757\uFF08${1}\uFF1B\u9884\u89C8\u5F85\u6253\u5F00\u753B\u5E03\u540E\u751F\u6210\u2014\u2014\u79BB\u5C4F\u5FEB\u7167\u5931\u8D25\u5C5E\u6B63\u5E38\u964D\u7EA7\uFF0C\u4E0D\u5F71\u54CD\u5757\u5185\u6570\u636E\u4E0E\u753B\u5E03\u7F16\u8F91\uFF09", [
|
|
2688
|
+
kindLabel,
|
|
2689
|
+
statsLabel
|
|
2690
|
+
]),
|
|
2691
|
+
{
|
|
2692
|
+
kind,
|
|
2693
|
+
stats: diagram.stats,
|
|
2694
|
+
preview: diagram.svg != null,
|
|
2695
|
+
inserted: result.inserted
|
|
2696
|
+
}
|
|
2697
|
+
);
|
|
2698
|
+
}
|
|
2699
|
+
});
|
|
2700
|
+
|
|
2701
|
+
// src/editor/usetool/index.tsx
|
|
2702
|
+
function createEditorCopilotTools(context) {
|
|
2703
|
+
return [
|
|
2704
|
+
getStatusTool(context),
|
|
2705
|
+
getContentTool(context),
|
|
2706
|
+
getSetContentTool(context),
|
|
2707
|
+
getApplyTemplateTool(context),
|
|
2708
|
+
getValidateTool(context),
|
|
2709
|
+
getFocusBlockTool(context),
|
|
2710
|
+
getDocBlockSchemaTool(context),
|
|
2711
|
+
getDocBlockUpdateTool(context),
|
|
2712
|
+
getDocCommandSchemaTool(context),
|
|
2713
|
+
getDocBlockGenerateTool(context),
|
|
2714
|
+
getDocBlockRemoveTool(context),
|
|
2715
|
+
getDocMarkUpdateTool(context),
|
|
2716
|
+
getDocSlotUpdateTool(context),
|
|
2717
|
+
getDocTableOpsTool(context),
|
|
2718
|
+
getDocDiagramGenerateTool(context)
|
|
2719
|
+
];
|
|
2720
|
+
}
|
|
2721
|
+
|
|
2722
|
+
// src/editor/features/templatedesigner/usetool/tools/getStatus.ts
|
|
2723
|
+
function resolveActiveCellSnapshot(state) {
|
|
2724
|
+
const { current, activeCell } = state;
|
|
2725
|
+
if (!activeCell) return null;
|
|
2726
|
+
const block = current.blocks.find((b) => b.uid === activeCell.uid);
|
|
2727
|
+
if (!block || block.type !== "table") return { ...activeCell, invalid: true };
|
|
2728
|
+
if (block.tableVariant === "form" && block.formTable) {
|
|
2729
|
+
const cellData = block.formTable.rows[activeCell.row]?.cells[activeCell.cell];
|
|
2730
|
+
return {
|
|
2731
|
+
...activeCell,
|
|
2732
|
+
variant: "form",
|
|
2733
|
+
covered: cellData?.covered ?? false,
|
|
2734
|
+
text: cellData?.text,
|
|
2735
|
+
fillable: cellData?.fillable,
|
|
2736
|
+
required: cellData?.required,
|
|
2737
|
+
fieldType: cellData?.fieldType
|
|
2738
|
+
};
|
|
2739
|
+
}
|
|
2740
|
+
if (block.dataTable) {
|
|
2741
|
+
if (activeCell.row === 0) {
|
|
2742
|
+
const column = block.dataTable.columns[activeCell.cell];
|
|
2743
|
+
return {
|
|
2744
|
+
...activeCell,
|
|
2745
|
+
variant: "data",
|
|
2746
|
+
position: "\u8868\u5934",
|
|
2747
|
+
header: column?.header,
|
|
2748
|
+
fieldType: column?.fieldType
|
|
2749
|
+
};
|
|
2750
|
+
}
|
|
2751
|
+
return {
|
|
2752
|
+
...activeCell,
|
|
2753
|
+
variant: "data",
|
|
2754
|
+
position: "\u6570\u636E\u884C",
|
|
2755
|
+
text: block.dataTable.defaultData?.[activeCell.row - 1]?.[activeCell.cell]
|
|
2756
|
+
};
|
|
2757
|
+
}
|
|
2758
|
+
return { ...activeCell, invalid: true };
|
|
2759
|
+
}
|
|
2760
|
+
function resolveSelectedBlockSummary(current, activeUid) {
|
|
2761
|
+
const activeBlock = activeUid ? current.blocks.find((b) => b.uid === activeUid) : void 0;
|
|
2762
|
+
return activeBlock ? {
|
|
2763
|
+
uid: activeBlock.uid,
|
|
2764
|
+
type: activeBlock.type,
|
|
2765
|
+
tableVariant: activeBlock.tableVariant,
|
|
2766
|
+
label: activeBlock.label,
|
|
2767
|
+
attrs: buildAttrSummary(activeBlock)
|
|
2768
|
+
} : null;
|
|
2769
|
+
}
|
|
2770
|
+
var getStatusTool2 = (context) => ({
|
|
2771
|
+
name: "get_status",
|
|
2772
|
+
description: tr(
|
|
2773
|
+
"[idocs\u6A21\u677F\u8BBE\u8BA1\u5668-\u753B\u5E03] \u83B7\u53D6\u5F53\u524D\u6A21\u677F\u72B6\u6001\uFF1A\u6A21\u677F\u4FE1\u606F\u3001\u5757\u6E05\u5355\uFF08uid/\u7C7B\u578B/\u6807\u9898\uFF09\u3001\u5F53\u524D\u9009\u4E2D\u7684\u5757\u4E0E\u5355\u5143\u683C\u53CA\u5176\u5185\u5BB9\u3002\u505A\u5C40\u90E8\u8C03\u6574\u524D\u5FC5\u987B\u5148\u8C03\u7528\u5B83\u786E\u8BA4\u9009\u4E2D\u5BF9\u8C61\u3002"
|
|
2774
|
+
),
|
|
2775
|
+
execute: async () => {
|
|
2776
|
+
const state = context.stateRef.current;
|
|
2777
|
+
const { current } = state;
|
|
2778
|
+
return ok(
|
|
2779
|
+
tr("\u83B7\u53D6\u8BBE\u8BA1\u5668\u72B6\u6001\u6210\u529F"),
|
|
2780
|
+
{
|
|
2781
|
+
templateId: current.id,
|
|
2782
|
+
templateName: current.name,
|
|
2783
|
+
templateVersion: current.version,
|
|
2784
|
+
blockCount: current.blocks.length,
|
|
2785
|
+
// 块清单只给定位所需的最小信息,具体块内容用 idocs_tpl_get 按 uid 取
|
|
2786
|
+
blocks: current.blocks.map((b) => ({
|
|
2787
|
+
uid: b.uid,
|
|
2788
|
+
type: b.type,
|
|
2789
|
+
label: b.label,
|
|
2790
|
+
tableVariant: b.tableVariant,
|
|
2791
|
+
isSlot: b.isSlot,
|
|
2792
|
+
required: b.required
|
|
2793
|
+
})),
|
|
2794
|
+
selectedBlock: resolveSelectedBlockSummary(current, state.activeUid),
|
|
2795
|
+
selectedCell: resolveActiveCellSnapshot(state)
|
|
2796
|
+
},
|
|
2797
|
+
{ successFlag: true }
|
|
2798
|
+
);
|
|
2799
|
+
}
|
|
2800
|
+
});
|
|
2801
|
+
|
|
2802
|
+
// src/editor/features/templatedesigner/usetool/tools/idocsTplGet.ts
|
|
2803
|
+
var getTemplateTool = (context) => ({
|
|
2804
|
+
name: "idocs_tpl_get",
|
|
2805
|
+
description: tr(
|
|
2806
|
+
"[idocs\u6A21\u677F\u8BBE\u8BA1\u5668-\u753B\u5E03] \u8BFB\u53D6\u5F53\u524D\u6A21\u677F\uFF08\u6216\u6307\u5B9A\u5757\uFF09\u7684\u5B8C\u6574 IR JSON\u3002\u9002\u7528\u573A\u666F\uFF1A\u8C03\u6574\u6A21\u677F\u524D\u5148\u4E86\u89E3\u73B0\u6709\u7ED3\u6784\uFF1B\u8FD4\u56DE\u683C\u5F0F\u4E0E idocs_tpl_set \u7684\u5165\u53C2\u683C\u5F0F\u4E00\u81F4\u3002"
|
|
2807
|
+
),
|
|
2808
|
+
inputSchema: {
|
|
2809
|
+
type: "object",
|
|
2810
|
+
properties: {
|
|
2811
|
+
uid: {
|
|
2812
|
+
type: "string",
|
|
2813
|
+
description: tr("\u53EF\u9009\uFF1A\u53EA\u8BFB\u53D6\u6307\u5B9A\u5757\u7684 JSON\uFF1B\u7F3A\u7701\u8FD4\u56DE\u6574\u4E2A\u6A21\u677F IR")
|
|
2814
|
+
}
|
|
2815
|
+
}
|
|
2816
|
+
},
|
|
2817
|
+
execute: async (args) => {
|
|
2818
|
+
const { current } = context.stateRef.current;
|
|
2819
|
+
if (args.uid) {
|
|
2820
|
+
const found = findBlock({ current }, args.uid);
|
|
2821
|
+
if (!found.ok) return found.result;
|
|
2822
|
+
return ok(tr("\u8BFB\u53D6\u5757\u6210\u529F"), found.value);
|
|
2823
|
+
}
|
|
2824
|
+
return ok(tr("\u8BFB\u53D6\u6A21\u677F\u6210\u529F"), current);
|
|
2825
|
+
}
|
|
2826
|
+
});
|
|
2827
|
+
|
|
2828
|
+
// src/editor/features/templatedesigner/usetool/tools/idocsTplBlockSchema.ts
|
|
2829
|
+
var getBlockSchemaTool = (context) => ({
|
|
2830
|
+
name: "idocs_tpl_block_schema",
|
|
2831
|
+
description: tr(
|
|
2832
|
+
"[idocs\u6A21\u677F\u8BBE\u8BA1\u5668-\u753B\u5E03] \u67E5\u8BE2\u67D0\u7C7B\u5757\u53EF\u88AB AI \u8C03\u6574\u7684\u5C5E\u6027\u6E05\u5355\u4E0E\u503C\u57DF\uFF08\u952E\u3001\u4E2D\u6587\u540D\u3001\u7C7B\u578B\u3001\u679A\u4E3E/\u8303\u56F4\u3001\u9ED8\u8BA4\u503C\u3001\u8C03\u4F18\u5EFA\u8BAE\uFF09\u3002"
|
|
2833
|
+
) + tr("\u6539\u5757\u5C5E\u6027\u524D\u5148\u8C03\u5B83\u4E86\u89E3\u53EF\u6539\u4EC0\u4E48\uFF1Btype \u7F3A\u7701\u4E3A\u5F53\u524D\u9009\u4E2D\u5757\u7684\u5757\u578B\u3002"),
|
|
2834
|
+
inputSchema: {
|
|
2835
|
+
type: "object",
|
|
2836
|
+
properties: {
|
|
2837
|
+
type: {
|
|
2838
|
+
type: "string",
|
|
2839
|
+
description: tr("\u53EF\u9009\uFF1A\u5757\u578B\uFF08heading/paragraph/image/table/codeBlock\uFF09\uFF0C\u7F3A\u7701\u4E3A\u5F53\u524D\u9009\u4E2D\u5757\u7684\u5757\u578B")
|
|
2840
|
+
}
|
|
2841
|
+
}
|
|
2842
|
+
},
|
|
2843
|
+
execute: async (args) => {
|
|
2844
|
+
let blockType = args.type;
|
|
2845
|
+
if (!blockType) {
|
|
2846
|
+
const { current, activeUid } = context.stateRef.current;
|
|
2847
|
+
const selected = activeUid ? current.blocks.find((b) => b.uid === activeUid) : void 0;
|
|
2848
|
+
if (!selected) {
|
|
2849
|
+
return fail(
|
|
2850
|
+
tr("\u672A\u4F20 type \u4E14\u5F53\u524D\u672A\u9009\u4E2D\u5757\uFF1A\u8BF7\u4F20\u5165\u5757\u578B\uFF08heading/paragraph/image/table/codeBlock\uFF09\uFF0C\u6216\u5148\u5728\u753B\u5E03\u9009\u4E2D\u4E00\u4E2A\u5757")
|
|
2851
|
+
);
|
|
2852
|
+
}
|
|
2853
|
+
blockType = selected.type;
|
|
2854
|
+
}
|
|
2855
|
+
if (!BLOCK_TYPES.some((item) => item.type === blockType)) {
|
|
2856
|
+
return fail(
|
|
2857
|
+
tr("\u5757\u578B ${0} \u7684\u5C5E\u6027\u6E05\u5355\u672A\u767B\u8BB0\uFF08\u5DF2\u767B\u8BB0\u5757\u578B\uFF1A${1}\uFF09", [blockType, BLOCK_TYPES.map((item) => item.type).join("\u3001")])
|
|
2858
|
+
);
|
|
2859
|
+
}
|
|
2860
|
+
const attrs = getWritableMeta(blockType).map((meta) => ({
|
|
2861
|
+
key: meta.key,
|
|
2862
|
+
zhLabel: meta.zhLabel,
|
|
2863
|
+
type: meta.type,
|
|
2864
|
+
...meta.enum ? { enum: meta.enum } : {},
|
|
2865
|
+
...meta.minimum !== void 0 ? { minimum: meta.minimum } : {},
|
|
2866
|
+
...meta.maximum !== void 0 ? { maximum: meta.maximum } : {},
|
|
2867
|
+
...meta.default !== void 0 ? { default: meta.default } : {},
|
|
2868
|
+
description: meta.description,
|
|
2869
|
+
scope: meta.scope
|
|
2870
|
+
}));
|
|
2871
|
+
return ok(tr("\u5757\u578B ${0} \u7684\u53EF\u5199\u5C5E\u6027\u6E05\u5355\uFF08\u5171 ${1} \u9879\uFF09", [blockType, attrs.length]), { type: blockType, attrs });
|
|
2872
|
+
}
|
|
2873
|
+
});
|
|
2874
|
+
|
|
2875
|
+
// src/editor/features/templatedesigner/usetool/tools/idocsTplSet.ts
|
|
2876
|
+
var getSetTemplateTool = (context) => ({
|
|
2877
|
+
name: "idocs_tpl_set",
|
|
2878
|
+
description: tr(
|
|
2879
|
+
'[idocs\u6A21\u677F\u8BBE\u8BA1\u5668-\u753B\u5E03] \u7528 AI \u751F\u6210\u7684\u6A21\u677F IR JSON \u6574\u4F53\u66FF\u6362\u5F53\u524D\u6A21\u677F\u3002\u9002\u7528\u573A\u666F\uFF1A\u7528\u6237\u8981\u6C42"\u751F\u6210\u4E00\u4EFD XX \u6A21\u677F"\u65F6\u3002\u3010\u6267\u884C\u8981\u6C42\u3011JSON \u5FC5\u987B\u662F DesignerTemplate \u7ED3\u6784'
|
|
2880
|
+
) + tr(
|
|
2881
|
+
"\uFF08{ id, name, version, description, blocks[] }\uFF1B\u5757\u542B uid/type/label\uFF0C\u8868\u683C\u5757\u7528 tableVariant+dataTable/formTable\uFF0C\u7ED3\u6784\u95E8\u63A7\u7528 pin/before/after/groupId\uFF09\uFF1B\u8868\u683C\u5757\u5EFA\u8BAE\u6539\u7528 idocs_tpl_table_generate \u5355\u72EC\u751F\u6210\u540E\u63D2\u5165\u3002"
|
|
2882
|
+
) + tr("\u3010\u6CE8\u610F\u3011\u6574\u4F53\u66FF\u6362\u4F1A\u8986\u76D6\u5F53\u524D\u5168\u90E8\u5185\u5BB9\uFF0C\u7528\u6237\u5DF2\u6709\u5185\u5BB9\u65F6\u5E94\u5148\u8C03 idocs_tpl_get \u786E\u8BA4\u3002"),
|
|
2883
|
+
inputSchema: {
|
|
2884
|
+
type: "object",
|
|
2885
|
+
properties: {
|
|
2886
|
+
templateJson: {
|
|
2887
|
+
// 必须声明 object 而非 string:网关按声明类型建 Pydantic 校验,string 会把模型
|
|
2888
|
+
// 直传的 JSON 对象拒掉(Input should be a valid string);object 声明下对象直传即过,
|
|
2889
|
+
// 模型若仍传 JSON 字符串,网关 before-validator 会兜底反序列化,execute 内再统一归一化。
|
|
2890
|
+
type: "object",
|
|
2891
|
+
description: tr("DesignerTemplate \u7684 JSON\uFF08\u5BF9\u8C61\u6216 JSON \u5B57\u7B26\u4E32\u5747\u53EF\uFF09")
|
|
2892
|
+
}
|
|
2893
|
+
},
|
|
2894
|
+
required: ["templateJson"]
|
|
2895
|
+
},
|
|
2896
|
+
execute: async (args) => {
|
|
2897
|
+
if (!args.templateJson) {
|
|
2898
|
+
return fail(tr("\u53C2\u6570 templateJson \u4E0D\u80FD\u4E3A\u7A7A"));
|
|
2899
|
+
}
|
|
2900
|
+
let parsed;
|
|
2901
|
+
if (typeof args.templateJson === "string") {
|
|
2902
|
+
try {
|
|
2903
|
+
parsed = JSON.parse(args.templateJson);
|
|
2904
|
+
} catch {
|
|
2905
|
+
return fail(tr("templateJson \u4E0D\u662F\u5408\u6CD5 JSON\uFF0C\u8BF7\u4FEE\u6B63\u540E\u91CD\u8BD5"));
|
|
2906
|
+
}
|
|
2907
|
+
} else {
|
|
2908
|
+
parsed = args.templateJson;
|
|
2909
|
+
}
|
|
2910
|
+
const schemaIssues = validateIrAgainstSchema(parsed, TEMPLATE_IR_STRICT_SCHEMA);
|
|
2911
|
+
if (schemaIssues.length > 0) {
|
|
2912
|
+
return fail(tr("\u6A21\u677F IR \u672A\u901A\u8FC7 schema \u6821\u9A8C\uFF08${0} \u5904\uFF09\uFF0C\u8BF7\u6309 issues \u4FEE\u6B63\u540E\u91CD\u8BD5", [schemaIssues.length]), {
|
|
2913
|
+
issues: schemaIssues
|
|
2914
|
+
});
|
|
2915
|
+
}
|
|
2916
|
+
const normalized = normalizeDesignerTemplate(parsed);
|
|
2917
|
+
const structureIssues = validateBlockStructure(normalized.blocks);
|
|
2918
|
+
const build = buildDefinition(normalized);
|
|
2919
|
+
const buildIssues = build.ok ? [] : build.issues;
|
|
2920
|
+
const issues = [...structureIssues, ...buildIssues];
|
|
2921
|
+
if (issues.length > 0) {
|
|
2922
|
+
return fail(tr("\u6A21\u677F\u7ED3\u6784\u6821\u9A8C\u672A\u901A\u8FC7\uFF08${0} \u5904\uFF09\uFF0C\u8BF7\u6309 issues \u4FEE\u6B63\u540E\u91CD\u8BD5", [issues.length]), { issues });
|
|
2923
|
+
}
|
|
2924
|
+
context.setCurrent(normalized);
|
|
2925
|
+
return ok(
|
|
2926
|
+
tr("\u6A21\u677F\u300C${0}\u300D\u5DF2\u751F\u6210\u5E76\u8F7D\u5165\u753B\u5E03\uFF08\u5171 ${1} \u4E2A\u5757\uFF09\uFF0C\u4FDD\u5B58\u4ECD\u9700\u7528\u6237\u624B\u52A8\u89E6\u53D1", [
|
|
2927
|
+
normalized.name,
|
|
2928
|
+
normalized.blocks.length
|
|
2929
|
+
]),
|
|
2930
|
+
{ templateId: normalized.id, templateName: normalized.name, blockCount: normalized.blocks.length }
|
|
2931
|
+
);
|
|
2932
|
+
}
|
|
2933
|
+
});
|
|
2934
|
+
|
|
2935
|
+
// src/editor/features/templatedesigner/usetool/tools/idocsTplTableGenerate.ts
|
|
2936
|
+
var getTableGenerateTool = (context) => ({
|
|
2937
|
+
name: "idocs_tpl_table_generate",
|
|
2938
|
+
description: tr(
|
|
2939
|
+
'[idocs\u6A21\u677F\u8BBE\u8BA1\u5668-\u8868\u683C] \u751F\u6210\u6574\u5F20\u8868\u683C\uFF08\u63D2\u5165\u65B0\u8868\u683C\u5757\uFF0C\u6216\u6574\u8868\u66FF\u6362\u6307\u5B9A\u8868\u683C\u5757\uFF09\u3002\u9002\u7528\u573A\u666F\uFF1A\u7528\u6237\u8981\u6C42"\u751F\u6210\u4E00\u5F20 XX \u8868\u683C"\u65F6\u3002\n'
|
|
2940
|
+
) + tr(
|
|
2941
|
+
'\u3010\u6570\u636E\u8868\u683C\uFF08columns \u5224\u5B9A\uFF09\u3011\u9002\u5408\u6241\u5E73\u540C\u6784\u5217\u8868\uFF0C\u683C\u5F0F\uFF1A{"columns":[{"header":"\u7269\u6599","fieldType":"text","width":160},{"header":"\u65E5\u671F","fieldType":"date"}],"defaultRows":5,"defaultData":[["\u793A\u4F8B",""]]}\uFF1B'
|
|
2942
|
+
) + tr(
|
|
2943
|
+
"fieldType \u652F\u6301 text/select/date\uFF08select \u9700 options\uFF09\uFF0C\u516C\u5F0F\u7528\u5217\u5F15\u7528\u5982 =SUM(B) \u6216 =SUM(B:E)\uFF0C\u5199\u5728 defaultData \u5355\u5143\u683C\u91CC\u3001\u4EE5 = \u5F00\u5934\u3002\n"
|
|
2944
|
+
) + tr(
|
|
2945
|
+
'\u3010\u56FA\u5B9A\u8868\u683C\uFF08rows \u5224\u5B9A\uFF09\u3011\u9002\u5408\u8868\u5355\u5F0F\u5E03\u5C40\uFF0C\u683C\u5F0F\uFF1A{"rows":[{"cells":[{"text":"\u59D3\u540D","fillable":false,"width":30},{"text":"","fillable":true,"required":true,"width":70}]}]}\uFF1B'
|
|
2946
|
+
) + tr(
|
|
2947
|
+
'\u6BCF\u884C\u5BBD\u5EA6\uFF08\u767E\u5206\u6BD4\u6211\uFF09\u5408\u8BA1\u987B\u4E3A 100\uFF1B\u7EB5\u5411\u5408\u5E76\uFF1A\u4E3B\u683C\u5199 "rowspan":2\uFF0C\u88AB\u8986\u76D6\u884C\u5BF9\u5E94\u4F4D\u7F6E\u53EF\u7701\u7565\uFF08\u81EA\u52A8\u8865\u5E7D\u7075\u683C\uFF09\uFF1B\u516C\u5F0F\u7528 R/C \u65B9\u8A00\u5982 =R1C2*R1C4\u3001=SUM(R1C1:R5C1)\uFF081 \u8D77\u6570\uFF09\uFF0C'
|
|
2948
|
+
) + tr('\u516C\u5F0F\u683C\u987B\u58F0\u660E "fieldType":"formula"\u3002\n') + tr("\u3010\u9009\u62E9\u53D8\u4F53\u3011\u5217\u7ED3\u6784\u89C4\u6574\u3001\u884C\u6570\u7531\u7528\u6237\u586B \u2192 \u6570\u636E\u8868\u683C\uFF1Blabel:\u586B\u5199\u533A \u76F8\u95F4\u3001\u6709\u5408\u5E76\u683C \u2192 \u56FA\u5B9A\u8868\u683C\u3002"),
|
|
2949
|
+
inputSchema: {
|
|
2950
|
+
type: "object",
|
|
2951
|
+
properties: {
|
|
2952
|
+
tableJson: {
|
|
2953
|
+
// 必须声明 object 而非 string:网关按声明类型建 Pydantic 校验,string 会把模型
|
|
2954
|
+
// 直传的 JSON 对象拒掉(Input should be a valid string);object 声明下对象直传即过,
|
|
2955
|
+
// 模型若仍传 JSON 字符串,网关 before-validator 会兜底反序列化,execute 内再统一归一化。
|
|
2956
|
+
type: "object",
|
|
2957
|
+
description: tr("\u8868\u683C JSON\uFF08\u5BF9\u8C61\u6216 JSON \u5B57\u7B26\u4E32\u5747\u53EF\uFF1B\u542B columns \u5373\u6570\u636E\u8868\u683C\uFF0C\u542B rows \u5373\u56FA\u5B9A\u8868\u683C\uFF09")
|
|
2958
|
+
},
|
|
2959
|
+
targetUid: {
|
|
2960
|
+
type: "string",
|
|
2961
|
+
description: tr("\u53EF\u9009\uFF1A\u6574\u8868\u66FF\u6362\u6307\u5B9A uid \u7684\u8868\u683C\u5757\uFF1B\u7F3A\u7701\u4F5C\u4E3A\u65B0\u5757\u63D2\u5165\u753B\u5E03")
|
|
2962
|
+
},
|
|
2963
|
+
label: {
|
|
2964
|
+
type: "string",
|
|
2965
|
+
description: tr('\u53EF\u9009\uFF1A\u8868\u683C\u5757\u6807\u9898\uFF08\u5982"\u7269\u6599\u6E05\u5355"\uFF09')
|
|
2966
|
+
}
|
|
2967
|
+
},
|
|
2968
|
+
required: ["tableJson"]
|
|
2969
|
+
},
|
|
2970
|
+
execute: async (args) => {
|
|
2971
|
+
const tableJson = typeof args.tableJson === "string" ? args.tableJson : args.tableJson ? JSON.stringify(args.tableJson) : "";
|
|
2972
|
+
if (!tableJson) {
|
|
2973
|
+
return fail(tr("\u53C2\u6570 tableJson \u4E0D\u80FD\u4E3A\u7A7A"));
|
|
2974
|
+
}
|
|
2975
|
+
const result = parseTableJson(tableJson);
|
|
2976
|
+
if (!result.ok) {
|
|
2977
|
+
return fail(tr("\u8868\u683C JSON \u89E3\u6790\u5931\u8D25\uFF1A${0}", [result.message]));
|
|
2978
|
+
}
|
|
2979
|
+
if (args.targetUid) {
|
|
2980
|
+
const found = findBlock({ current: context.stateRef.current.current }, args.targetUid, { tableOnly: true });
|
|
2981
|
+
if (!found.ok) return found.result;
|
|
2982
|
+
const blockPatch = { ...result.block };
|
|
2983
|
+
if (result.variant === "data") {
|
|
2984
|
+
blockPatch.formTable = void 0;
|
|
2985
|
+
} else {
|
|
2986
|
+
blockPatch.dataTable = void 0;
|
|
2987
|
+
}
|
|
2988
|
+
if (args.label !== void 0) blockPatch.label = args.label;
|
|
2989
|
+
context.patchBlock(args.targetUid, blockPatch);
|
|
2990
|
+
return ok(
|
|
2991
|
+
tr("\u8868\u683C\u5DF2\u6574\u8868\u66FF\u6362\uFF08${0}\uFF09", [result.variant === "data" ? tr("\u6570\u636E\u8868\u683C") : tr("\u56FA\u5B9A\u8868\u683C")]) + (result.warnings.length ? tr("\uFF0C\u6CE8\u610F\uFF1A${0}", [result.warnings.join("\uFF1B")]) : ""),
|
|
2992
|
+
{ uid: args.targetUid, variant: result.variant, warnings: result.warnings }
|
|
2993
|
+
);
|
|
2994
|
+
}
|
|
2995
|
+
const newBlock = createBlockFromPalette({
|
|
2996
|
+
...result.block,
|
|
2997
|
+
...args.label !== void 0 ? { label: args.label } : {}
|
|
2998
|
+
});
|
|
2999
|
+
context.insertBlock(newBlock);
|
|
3000
|
+
return ok(
|
|
3001
|
+
tr("\u8868\u683C\u5DF2\u751F\u6210\u5E76\u63D2\u5165\u753B\u5E03\uFF08${0}\uFF0C\u5DF2\u81EA\u52A8\u9009\u4E2D\uFF09", [result.variant === "data" ? tr("\u6570\u636E\u8868\u683C") : tr("\u56FA\u5B9A\u8868\u683C")]) + (result.warnings.length ? tr("\uFF0C\u6CE8\u610F\uFF1A${0}", [result.warnings.join("\uFF1B")]) : ""),
|
|
3002
|
+
{ uid: newBlock.uid, variant: result.variant, warnings: result.warnings }
|
|
3003
|
+
);
|
|
3004
|
+
}
|
|
3005
|
+
});
|
|
3006
|
+
|
|
3007
|
+
// src/editor/features/templatedesigner/usetool/tools/idocsTplCellUpdate.ts
|
|
3008
|
+
var FORM_ROW_HEIGHT_BOUNDS = { min: 32, max: 400 };
|
|
3009
|
+
var getCellUpdateTool = (context) => ({
|
|
3010
|
+
name: "idocs_tpl_cell_update",
|
|
3011
|
+
description: tr(
|
|
3012
|
+
'[idocs\u6A21\u677F\u8BBE\u8BA1\u5668-\u8868\u683C] \u8C03\u6574\u5355\u4E2A\u8868\u683C\u5355\u5143\u683C\u3002\u9002\u7528\u573A\u666F\uFF1A\u7528\u6237\u9009\u4E2D\u67D0\u4E2A\u5355\u5143\u683C\u540E\u8BF4"\u6539\u6210\u5FC5\u586B/\u6539\u6210\u4E0B\u62C9/\u52A0\u516C\u5F0F/\u6539\u6587\u5B57"\u65F6\u3002\u3010\u76EE\u6807\u3011\u7F3A\u7701\u8C03\u6574\u5F53\u524D\u9009\u4E2D\u683C\uFF08\u5148\u8C03 get_status \u786E\u8BA4\u9009\u4E2D\uFF09\uFF1B\u4E5F\u53EF\u7528 target \u663E\u5F0F\u6307\u5B9A {uid,row,cell}\u3002'
|
|
3013
|
+
) + tr(
|
|
3014
|
+
"\u3010\u5750\u6807\u7CFB\u3011\u6570\u636E\u8868\u683C row 0 \u662F\u8868\u5934\u683C\uFF08\u53EF\u6539\u5217\u540D text\u3001fieldType\u3001options\u3001width\uFF09\uFF0Crow \u2265 1 \u662F\u6570\u636E\u683C\uFF08\u53EA\u80FD\u6539 text \u503C\u4E0E fixed \u56FA\u5B9A\u6807\u8BB0\uFF0C\u5217\u516C\u5F0F\u76F4\u63A5\u5199\u4EE5 = \u5F00\u5934\u7684 text\uFF09\uFF1B"
|
|
3015
|
+
) + tr(
|
|
3016
|
+
"\u56FA\u5B9A\u8868\u683C row/cell \u76F4\u63A5\u5BF9\u5E94\u884C\u5217\uFF08\u53EF\u6539 text/fillable/required/bold/width/widthUnit/textAlign/fieldType/options/dateFormat/formula/backgroundColor/rowspan/rowHeight\uFF0C\u516C\u5F0F\u7528 R/C \u65B9\u8A00\uFF1BbackgroundColor \u4F20\u7A7A\u5B57\u7B26\u4E32\u6062\u590D\u9ED8\u8BA4\u5E95\u8272\uFF0Crowspan \u22652 \u5411\u4E0B\u7EB5\u5411\u5408\u5E76\u3001\u4F20 1 \u62C6\u5206\u5408\u5E76\uFF0CrowHeight \u4F5C\u7528\u4E8E\u6240\u5728\u884C 32-400 \u7F3A\u7701 ${0}\uFF09\u3002",
|
|
3017
|
+
[DEFAULT_FORM_ROW_HEIGHT]
|
|
3018
|
+
),
|
|
3019
|
+
inputSchema: {
|
|
3020
|
+
type: "object",
|
|
3021
|
+
properties: {
|
|
3022
|
+
target: {
|
|
3023
|
+
type: "object",
|
|
3024
|
+
description: tr("\u53EF\u9009\uFF1A\u76EE\u6807\u5355\u5143\u683C\u5750\u6807 {uid,row,cell}\uFF0C\u7F3A\u7701\u4E3A\u5F53\u524D\u9009\u4E2D\u683C"),
|
|
3025
|
+
properties: {
|
|
3026
|
+
uid: { type: "string", description: tr("\u8868\u683C\u5757 uid") },
|
|
3027
|
+
row: { type: "number", description: tr("\u884C\u4E0B\u6807\uFF080 \u8D77\uFF1B\u6570\u636E\u8868\u683C 0=\u8868\u5934\u884C\uFF09"), minimum: 0 },
|
|
3028
|
+
cell: { type: "number", description: tr("\u683C\u4E0B\u6807\uFF080 \u8D77\uFF09"), minimum: 0 }
|
|
3029
|
+
},
|
|
3030
|
+
required: ["uid", "row", "cell"]
|
|
3031
|
+
},
|
|
3032
|
+
text: { type: "string", description: tr("\u6587\u672C\u5185\u5BB9/\u5217\u540D/\u5355\u5143\u683C\u503C") },
|
|
3033
|
+
fillable: { type: "boolean", description: tr("\uFF08\u56FA\u5B9A\u8868\u683C\uFF09\u662F\u5426\u53EF\u586B\u5199") },
|
|
3034
|
+
required: { type: "boolean", description: tr("\uFF08\u56FA\u5B9A\u8868\u683C\u53EF\u586B\u683C\uFF09\u662F\u5426\u5FC5\u586B") },
|
|
3035
|
+
bold: { type: "boolean", description: tr("\uFF08\u56FA\u5B9A\u8868\u683C\uFF09\u662F\u5426\u52A0\u7C97") },
|
|
3036
|
+
width: { type: "number", description: tr("\u5BBD\u5EA6\uFF08\u56FA\u5B9A\u8868\u683C\u6309 widthUnit\uFF1B\u6570\u636E\u8868\u683C\u5217\u56FA\u5B9A\u4E3A px\uFF09") },
|
|
3037
|
+
widthUnit: { type: "string", enum: ["percent", "px"], description: tr("\uFF08\u56FA\u5B9A\u8868\u683C\uFF09\u5BBD\u5EA6\u5355\u4F4D") },
|
|
3038
|
+
textAlign: { type: "string", enum: ["left", "center", "right"], description: tr("\uFF08\u56FA\u5B9A\u8868\u683C\uFF09\u6587\u672C\u5BF9\u9F50") },
|
|
3039
|
+
fieldType: {
|
|
3040
|
+
type: "string",
|
|
3041
|
+
enum: ["text", "select", "date", "formula"],
|
|
3042
|
+
description: tr("\u63A7\u4EF6\u7C7B\u578B\uFF08\u6570\u636E\u8868\u683C\u5217\u4E0D\u652F\u6301 formula\uFF09")
|
|
3043
|
+
},
|
|
3044
|
+
options: { type: "array", items: { type: "string" }, description: tr("select \u5019\u9009\u503C") },
|
|
3045
|
+
dateFormat: { type: "string", description: tr("date \u683C\u5F0F") },
|
|
3046
|
+
formula: { type: "string", description: tr("\uFF08\u56FA\u5B9A\u8868\u683C\uFF09R/C \u65B9\u8A00\u516C\u5F0F\uFF0C\u987B\u914D\u5408 fieldType=formula") },
|
|
3047
|
+
backgroundColor: {
|
|
3048
|
+
type: "string",
|
|
3049
|
+
description: tr(
|
|
3050
|
+
"\uFF08\u56FA\u5B9A\u8868\u683C\uFF09\u5E95\u8272\uFF1ARGB/RGBA/\u5341\u516D\u8FDB\u5236\uFF08\u5982 rgb(255, 255, 255)\u3001#fff7e6\uFF09\uFF1B\u7A7A\u5B57\u7B26\u4E32 = \u6062\u590D\u9ED8\u8BA4\u5E95\u8272"
|
|
3051
|
+
)
|
|
3052
|
+
},
|
|
3053
|
+
rowspan: {
|
|
3054
|
+
type: "number",
|
|
3055
|
+
description: tr("\uFF08\u56FA\u5B9A\u8868\u683C\uFF09\u7EB5\u5411\u5408\u5E76\uFF1A\u22652 \u7684\u6574\u6570 = \u5411\u4E0B\u5408\u5E76\u5230\u8BE5\u8DE8\u884C\u6570\uFF1B1 = \u62C6\u5206\u5408\u5E76"),
|
|
3056
|
+
minimum: 1
|
|
3057
|
+
},
|
|
3058
|
+
rowHeight: {
|
|
3059
|
+
type: "number",
|
|
3060
|
+
description: tr("\uFF08\u56FA\u5B9A\u8868\u683C\uFF09\u6240\u5728\u884C\u9AD8 px\uFF0C32-400\uFF0C\u7F3A\u7701 ${0}", [DEFAULT_FORM_ROW_HEIGHT])
|
|
3061
|
+
},
|
|
3062
|
+
fixed: { type: "boolean", description: tr("\uFF08\u6570\u636E\u8868\u683C\u6570\u636E\u683C\uFF09\u9ED8\u8BA4\u6570\u636E\u56FA\u5B9A\u6807\u8BB0") }
|
|
3063
|
+
}
|
|
3064
|
+
},
|
|
3065
|
+
execute: async (args) => {
|
|
3066
|
+
const { current, activeCell } = context.stateRef.current;
|
|
3067
|
+
const target = args.target ?? activeCell;
|
|
3068
|
+
if (!target) {
|
|
3069
|
+
return fail(tr("\u672A\u6307\u5B9A\u76EE\u6807\u5355\u5143\u683C\uFF0C\u4E14\u753B\u5E03\u5F53\u524D\u6CA1\u6709\u9009\u4E2D\u4EFB\u4F55\u5355\u5143\u683C\u3002\u8BF7\u5148\u8BA9\u7528\u6237\u9009\u4E2D\u5355\u5143\u683C\uFF0C\u6216\u7528 target \u53C2\u6570\u663E\u5F0F\u6307\u5B9A"));
|
|
3070
|
+
}
|
|
3071
|
+
const found = findBlock({ current }, target.uid, { tableOnly: true });
|
|
3072
|
+
if (!found.ok) return found.result;
|
|
3073
|
+
const block = found.value;
|
|
3074
|
+
if (block.tableVariant === "form") {
|
|
3075
|
+
const model2 = block.formTable;
|
|
3076
|
+
const cellData = model2?.rows[target.row]?.cells[target.cell];
|
|
3077
|
+
if (!model2 || !cellData) {
|
|
3078
|
+
return fail(tr("\u5355\u5143\u683C\u5750\u6807\u8D8A\u754C\uFF08row=${0}, cell=${1}\uFF09", [target.row, target.cell]));
|
|
3079
|
+
}
|
|
3080
|
+
if (cellData.covered) {
|
|
3081
|
+
return fail(tr("\u8BE5\u683C\u662F\u88AB\u7EB5\u5411\u5408\u5E76\u8986\u76D6\u7684\u5E7D\u7075\u683C\uFF0C\u4E0D\u53EF\u76F4\u63A5\u8C03\u6574\uFF0C\u8BF7\u5B9A\u4F4D\u5230\u4E0A\u65B9\u7684\u5408\u5E76\u4E3B\u683C\uFF08\u5E26 rowspan \u7684\u683C\uFF09"));
|
|
3082
|
+
}
|
|
3083
|
+
if (args.backgroundColor !== void 0) {
|
|
3084
|
+
const metaCheck = validateAttrValue(DESIGNER_FORM_CELL_ATTRS, "backgroundColor", args.backgroundColor);
|
|
3085
|
+
if (!metaCheck.ok) return fail(metaCheck.message);
|
|
3086
|
+
if (args.backgroundColor !== "" && normalizeFixedTableBackgroundColor(args.backgroundColor) === null) {
|
|
3087
|
+
return fail(
|
|
3088
|
+
tr(
|
|
3089
|
+
"\u5C5E\u6027 backgroundColor \u53D6\u503C\u975E\u6CD5\uFF08\u5F53\u524D\u503C\uFF1A${0}\uFF1B\u5408\u6CD5\u503C\uFF1ARGB/RGBA/\u5341\u516D\u8FDB\u5236\u989C\u8272\uFF08\u5982 rgb(255, 255, 255)\u3001#fff7e6\uFF09\uFF0C\u7A7A\u5B57\u7B26\u4E32 = \u6062\u590D\u9ED8\u8BA4\u5E95\u8272\u3002\u5EFA\u8BAE\uFF1A\u4FEE\u6B63\u683C\u5F0F\u540E\u91CD\u8BD5\uFF09",
|
|
3090
|
+
[args.backgroundColor]
|
|
3091
|
+
)
|
|
3092
|
+
);
|
|
3093
|
+
}
|
|
3094
|
+
}
|
|
3095
|
+
if (args.rowHeight !== void 0) {
|
|
3096
|
+
const metaCheck = validateAttrValue([DESIGNER_FORM_ROW_HEIGHT_ATTR], "height", args.rowHeight);
|
|
3097
|
+
if (!metaCheck.ok) return fail(metaCheck.message);
|
|
3098
|
+
if (args.rowHeight < FORM_ROW_HEIGHT_BOUNDS.min || args.rowHeight > FORM_ROW_HEIGHT_BOUNDS.max) {
|
|
3099
|
+
return fail(
|
|
3100
|
+
tr("\u5C5E\u6027 rowHeight \u8D85\u51FA\u53D6\u503C\u8303\u56F4\uFF08\u5F53\u524D\u503C\uFF1A${0}\uFF1B\u5408\u6CD5\u503C\uFF1A${1} ~ ${2}\u3002\u5EFA\u8BAE\uFF1A\u8C03\u6574\u5230\u8303\u56F4\u5185\u91CD\u8BD5\uFF09", [
|
|
3101
|
+
args.rowHeight,
|
|
3102
|
+
FORM_ROW_HEIGHT_BOUNDS.min,
|
|
3103
|
+
FORM_ROW_HEIGHT_BOUNDS.max
|
|
3104
|
+
])
|
|
3105
|
+
);
|
|
3106
|
+
}
|
|
3107
|
+
}
|
|
3108
|
+
const currentSpan = cellRowspan(cellData);
|
|
3109
|
+
if (args.rowspan !== void 0) {
|
|
3110
|
+
if (typeof args.rowspan !== "number" || !Number.isInteger(args.rowspan) || args.rowspan < 1) {
|
|
3111
|
+
return fail(
|
|
3112
|
+
tr(
|
|
3113
|
+
"\u5C5E\u6027 rowspan \u53D6\u503C\u975E\u6CD5\uFF08\u5F53\u524D\u503C\uFF1A${0}\uFF1B\u5408\u6CD5\u503C\uFF1A\u22652 \u7684\u6574\u6570 = \u5411\u4E0B\u5408\u5E76\u5230\u8BE5\u8DE8\u884C\u6570\uFF0C1 = \u62C6\u5206\u5408\u5E76\u3002\u5EFA\u8BAE\uFF1A\u4FEE\u6B63\u540E\u91CD\u8BD5\uFF09",
|
|
3114
|
+
[formatAttrValue(args.rowspan)]
|
|
3115
|
+
)
|
|
3116
|
+
);
|
|
3117
|
+
}
|
|
3118
|
+
if (args.rowspan >= 2) {
|
|
3119
|
+
const metaCheck = validateAttrValue(DESIGNER_FORM_CELL_ATTRS, "rowspan", args.rowspan);
|
|
3120
|
+
if (!metaCheck.ok) return fail(metaCheck.message);
|
|
3121
|
+
const maxSpan = model2.rows.length - target.row;
|
|
3122
|
+
if (maxSpan < 2) {
|
|
3123
|
+
return fail(
|
|
3124
|
+
tr(
|
|
3125
|
+
"\u672C\u683C\u4F4D\u4E8E\u6700\u540E\u4E00\u884C\uFF0C\u65E0\u6CD5\u5411\u4E0B\u5408\u5E76\uFF08\u5F53\u524D\uFF1A\u7B2C ${0} \u884C\u3002\u5EFA\u8BAE\uFF1A\u5148\u7528 idocs_tpl_table_update \u8FFD\u52A0\u884C\u540E\u518D\u5408\u5E76\uFF09",
|
|
3126
|
+
[target.row + 1]
|
|
3127
|
+
)
|
|
3128
|
+
);
|
|
3129
|
+
}
|
|
3130
|
+
if (args.rowspan > maxSpan) {
|
|
3131
|
+
return fail(
|
|
3132
|
+
tr(
|
|
3133
|
+
"\u5C5E\u6027 rowspan \u8D85\u51FA\u53EF\u5408\u5E76\u8303\u56F4\uFF08\u5F53\u524D\u503C\uFF1A${0}\uFF1B\u5408\u6CD5\u503C\uFF1A2 ~ ${1}\uFF08\u672C\u683C\u4E0B\u65B9\u4EC5\u6709 ${2} \u884C\uFF09\u3002\u5EFA\u8BAE\uFF1A\u51CF\u5C0F\u8DE8\u5EA6\uFF0C\u6216\u5148\u7528 idocs_tpl_table_update \u8FFD\u52A0\u884C\uFF09",
|
|
3134
|
+
[args.rowspan, maxSpan, maxSpan - 1]
|
|
3135
|
+
)
|
|
3136
|
+
);
|
|
3137
|
+
}
|
|
3138
|
+
if (args.rowspan < currentSpan) {
|
|
3139
|
+
return fail(
|
|
3140
|
+
tr(
|
|
3141
|
+
"\u4E0D\u652F\u6301\u628A\u5DF2\u5408\u5E76 ${0} \u884C\u7684\u683C\u76F4\u63A5\u7F29\u5C0F\u5230 ${1} \u884C\uFF08\u5408\u6CD5\u503C\uFF1A1 = \u62C6\u5206\u5408\u5E76\uFF0C\u6216 \u2265${2} \u7EE7\u7EED\u5411\u4E0B\u5408\u5E76\u3002\u5EFA\u8BAE\uFF1A\u5148\u4F20 1 \u62C6\u5206\uFF0C\u518D\u6309\u9700\u91CD\u65B0\u5408\u5E76\uFF09",
|
|
3142
|
+
[currentSpan, args.rowspan, currentSpan]
|
|
3143
|
+
)
|
|
3144
|
+
);
|
|
3145
|
+
}
|
|
3146
|
+
}
|
|
3147
|
+
}
|
|
3148
|
+
const patch = {};
|
|
3149
|
+
if (args.text !== void 0) patch.text = args.text;
|
|
3150
|
+
if (args.fillable !== void 0) patch.fillable = args.fillable;
|
|
3151
|
+
if (args.required !== void 0) patch.required = args.required;
|
|
3152
|
+
if (args.bold !== void 0) patch.bold = args.bold;
|
|
3153
|
+
if (args.width !== void 0) patch.width = args.width;
|
|
3154
|
+
if (args.widthUnit !== void 0) patch.widthUnit = args.widthUnit;
|
|
3155
|
+
if (args.textAlign !== void 0) patch.textAlign = args.textAlign;
|
|
3156
|
+
if (args.fieldType !== void 0) patch.fieldType = args.fieldType;
|
|
3157
|
+
if (args.options !== void 0) patch.options = args.options;
|
|
3158
|
+
if (args.dateFormat !== void 0) patch.dateFormat = args.dateFormat;
|
|
3159
|
+
if (args.formula !== void 0) patch.formula = args.formula;
|
|
3160
|
+
if (args.backgroundColor !== void 0) {
|
|
3161
|
+
patch.backgroundColor = args.backgroundColor === "" ? void 0 : normalizeFixedTableBackgroundColor(args.backgroundColor) ?? void 0;
|
|
3162
|
+
}
|
|
3163
|
+
if (Object.keys(patch).length === 0 && args.rowHeight === void 0 && args.rowspan === void 0) {
|
|
3164
|
+
return fail(tr("\u6CA1\u6709\u8981\u4FEE\u6539\u7684\u5B57\u6BB5"));
|
|
3165
|
+
}
|
|
3166
|
+
let working = model2;
|
|
3167
|
+
if (Object.keys(patch).length > 0) {
|
|
3168
|
+
working = {
|
|
3169
|
+
rows: working.rows.map(
|
|
3170
|
+
(row, ri) => ri === target.row ? { ...row, cells: row.cells.map((c, ci) => ci === target.cell ? { ...c, ...patch } : c) } : row
|
|
3171
|
+
)
|
|
3172
|
+
};
|
|
3173
|
+
}
|
|
3174
|
+
if (args.rowHeight !== void 0) {
|
|
3175
|
+
const rowHeight = args.rowHeight;
|
|
3176
|
+
working = {
|
|
3177
|
+
rows: working.rows.map((row, ri) => ri === target.row ? { ...row, height: rowHeight } : row)
|
|
3178
|
+
};
|
|
3179
|
+
}
|
|
3180
|
+
const mergeNotes = [];
|
|
3181
|
+
let rowspanApplied = false;
|
|
3182
|
+
if (args.rowspan !== void 0) {
|
|
3183
|
+
if (args.rowspan === 1) {
|
|
3184
|
+
if (currentSpan > 1) {
|
|
3185
|
+
working = splitRowspan(working, target.row, target.cell);
|
|
3186
|
+
rowspanApplied = true;
|
|
3187
|
+
}
|
|
3188
|
+
} else if (args.rowspan > currentSpan) {
|
|
3189
|
+
const autoHeightRows = /* @__PURE__ */ new Set();
|
|
3190
|
+
let removedPayload = false;
|
|
3191
|
+
let widthUnresolved = false;
|
|
3192
|
+
let span = currentSpan;
|
|
3193
|
+
while (span < args.rowspan) {
|
|
3194
|
+
if (!canMergeDown(working, target.row, target.cell)) {
|
|
3195
|
+
return fail(
|
|
3196
|
+
tr(
|
|
3197
|
+
"\u5408\u5E76\u5230\u7B2C ${0} \u884C\u65F6\u8986\u76D6\u8303\u56F4\u4E0B\u4E00\u884C\u4E0D\u5B58\u5728\uFF08\u5F53\u524D\u8DE8\u5EA6\uFF1A${1}\u3002\u5EFA\u8BAE\uFF1A\u5148\u7528 idocs_tpl_table_update \u8FFD\u52A0\u884C\u540E\u91CD\u8BD5\uFF09",
|
|
3198
|
+
[target.row + span + 1, span]
|
|
3199
|
+
)
|
|
3200
|
+
);
|
|
3201
|
+
}
|
|
3202
|
+
const result = mergeDown(working, target.row, target.cell);
|
|
3203
|
+
if (result.blocked) {
|
|
3204
|
+
return fail(
|
|
3205
|
+
tr(
|
|
3206
|
+
"\u5408\u5E76\u8303\u56F4\u4E0E\u7B2C ${0} \u884C\u5DF2\u6709\u7684\u5408\u5E76\u5360\u4F4D\u91CD\u53E0\uFF08\u5F53\u524D\u8DE8\u5EA6\uFF1A${1}\u3002\u5EFA\u8BAE\uFF1A\u5148\u62C6\u5206\u8BE5\u884C\u7684\u5408\u5E76\u6216\u8C03\u6574\u5355\u5143\u683C\u5BBD\u5EA6\u540E\u91CD\u8BD5\uFF09",
|
|
3207
|
+
[target.row + span + 1, span]
|
|
3208
|
+
)
|
|
3209
|
+
);
|
|
3210
|
+
}
|
|
3211
|
+
working = result.model;
|
|
3212
|
+
result.autoHeightRows.forEach((index) => autoHeightRows.add(index));
|
|
3213
|
+
removedPayload = removedPayload || result.removedPayload;
|
|
3214
|
+
widthUnresolved = widthUnresolved || result.widthUnresolved;
|
|
3215
|
+
span += 1;
|
|
3216
|
+
}
|
|
3217
|
+
rowspanApplied = true;
|
|
3218
|
+
if (autoHeightRows.size > 0) {
|
|
3219
|
+
mergeNotes.push(
|
|
3220
|
+
tr("\u5DF2\u81EA\u52A8\u4E3A\u7B2C ${0} \u884C\u8BBE\u7F6E\u9ED8\u8BA4\u884C\u9AD8", [[...autoHeightRows].map((index) => index + 1).join("\u3001")])
|
|
3221
|
+
);
|
|
3222
|
+
}
|
|
3223
|
+
if (removedPayload) {
|
|
3224
|
+
mergeNotes.push(tr("\u4E0B\u4E00\u884C\u4E2D\u88AB\u5408\u5E76\u8303\u56F4\u5B8C\u5168\u8986\u76D6\u7684\u5355\u5143\u683C\u5DF2\u968F\u5408\u5E76\u79FB\u9664\uFF08\u542B\u6587\u5B57/\u5FC5\u586B/\u516C\u5F0F\u914D\u7F6E\uFF09"));
|
|
3225
|
+
}
|
|
3226
|
+
if (widthUnresolved) {
|
|
3227
|
+
mergeNotes.push(tr("\u8BE5\u884C\u5305\u542B\u50CF\u7D20\u5BBD\u5EA6\u5355\u5143\u683C\uFF0C\u65E0\u6CD5\u81EA\u52A8\u5BF9\u9F50\u5408\u5E76\u5BBD\u5EA6\uFF0C\u5EFA\u8BAE\u4E3A\u5408\u5E76\u683C\u8BBE\u7F6E\u660E\u786E\u5BBD\u5EA6"));
|
|
3228
|
+
}
|
|
3229
|
+
}
|
|
3230
|
+
}
|
|
3231
|
+
if (Object.keys(patch).length === 0 && args.rowHeight === void 0 && !rowspanApplied) {
|
|
3232
|
+
return ok(tr("\u5355\u5143\u683C\u5DF2\u5904\u4E8E\u76EE\u6807\u72B6\u6001\uFF0C\u65E0\u9700\u53D8\u66F4"), { target });
|
|
3233
|
+
}
|
|
3234
|
+
const nextBlock2 = normalizeTableBlock({ ...block, formTable: working });
|
|
3235
|
+
context.patchBlock(target.uid, { formTable: nextBlock2.formTable });
|
|
3236
|
+
const applied = Object.keys(patch);
|
|
3237
|
+
if (args.rowHeight !== void 0) applied.push("rowHeight");
|
|
3238
|
+
if (rowspanApplied) applied.push("rowspan");
|
|
3239
|
+
return ok(
|
|
3240
|
+
tr("\u5355\u5143\u683C\u5DF2\u8C03\u6574\uFF08${0}\uFF09", [applied.join("\u3001")]) + (mergeNotes.length ? tr("\uFF0C\u6CE8\u610F\uFF1A${0}", [mergeNotes.join("\uFF1B")]) : ""),
|
|
3241
|
+
{
|
|
3242
|
+
target,
|
|
3243
|
+
patch,
|
|
3244
|
+
...args.rowHeight !== void 0 ? { rowHeight: args.rowHeight } : {},
|
|
3245
|
+
...rowspanApplied ? { rowspan: cellRowspan(nextBlock2.formTable?.rows[target.row]?.cells[target.cell]) } : {}
|
|
3246
|
+
}
|
|
3247
|
+
);
|
|
3248
|
+
}
|
|
3249
|
+
const model = block.dataTable;
|
|
3250
|
+
if (!model) {
|
|
3251
|
+
return fail(tr("\u8BE5\u8868\u683C\u5757\u7F3A\u5C11\u6570\u636E\u8868\u683C\u6A21\u578B"));
|
|
3252
|
+
}
|
|
3253
|
+
if (args.backgroundColor !== void 0 || args.rowspan !== void 0 || args.rowHeight !== void 0) {
|
|
3254
|
+
return fail(
|
|
3255
|
+
tr(
|
|
3256
|
+
"\u6570\u636E\u8868\u683C\u4E0D\u652F\u6301 backgroundColor/rowspan/rowHeight\uFF08\u4EC5\u56FA\u5B9A\u8868\u683C\u652F\u6301\uFF1B\u6570\u636E\u8868\u683C\u884C\u9AD8\u6309\u5185\u5BB9\u6491\u5F00\u3001\u65E0\u7EB5\u5411\u5408\u5E76\u4E0E\u683C\u5E95\u8272\uFF09\u3002\u5EFA\u8BAE\uFF1A\u884C\u5217\u589E\u5220\u4E0E\u9ED8\u8BA4\u884C\u6570\u8C03\u6574\u8BF7\u7528 idocs_tpl_table_update"
|
|
3257
|
+
)
|
|
3258
|
+
);
|
|
3259
|
+
}
|
|
3260
|
+
if (target.row === 0) {
|
|
3261
|
+
const column = model.columns[target.cell];
|
|
3262
|
+
if (!column) {
|
|
3263
|
+
return fail(tr("\u5217\u4E0B\u6807\u8D8A\u754C\uFF08cell=${0}\uFF0C\u5171 ${1} \u5217\uFF09", [target.cell, model.columns.length]));
|
|
3264
|
+
}
|
|
3265
|
+
const fieldType = args.fieldType;
|
|
3266
|
+
if (fieldType === "formula") {
|
|
3267
|
+
return fail(tr("\u6570\u636E\u8868\u683C\u7684\u5217\u4E0D\u652F\u6301 fieldType=formula\uFF1B\u516C\u5F0F\u8BF7\u5199\u5728\u6570\u636E\u683C\u7684 text \u91CC\u3001\u4EE5 = \u5F00\u5934\uFF08\u5982 =SUM(B)\uFF09"));
|
|
3268
|
+
}
|
|
3269
|
+
const nextColumns = model.columns.map(
|
|
3270
|
+
(c, ci) => ci === target.cell ? {
|
|
3271
|
+
...c,
|
|
3272
|
+
...args.text !== void 0 ? { header: args.text } : {},
|
|
3273
|
+
...fieldType !== void 0 ? { fieldType } : {},
|
|
3274
|
+
...args.options !== void 0 ? { options: args.options } : {},
|
|
3275
|
+
...args.dateFormat !== void 0 ? { dateFormat: args.dateFormat } : {},
|
|
3276
|
+
...args.width !== void 0 ? { width: args.width } : {}
|
|
3277
|
+
} : c
|
|
3278
|
+
);
|
|
3279
|
+
const nextBlock2 = normalizeTableBlock({ ...block, dataTable: { ...model, columns: nextColumns } });
|
|
3280
|
+
context.patchBlock(target.uid, { dataTable: nextBlock2.dataTable });
|
|
3281
|
+
return ok(tr("\u7B2C ${0} \u5217\u7684\u5217\u8BBE\u7F6E\u5DF2\u8C03\u6574", [target.cell + 1]), { target });
|
|
3282
|
+
}
|
|
3283
|
+
const dataRow = target.row - 1;
|
|
3284
|
+
if (target.row < 0 || dataRow >= model.defaultRows) {
|
|
3285
|
+
return fail(tr("\u884C\u4E0B\u6807\u8D8A\u754C\uFF08row=${0}\uFF0C\u6570\u636E\u884C\u5171 ${1} \u884C\uFF09", [target.row, model.defaultRows]));
|
|
3286
|
+
}
|
|
3287
|
+
if (target.cell < 0 || target.cell >= model.columns.length) {
|
|
3288
|
+
return fail(tr("\u5217\u4E0B\u6807\u8D8A\u754C\uFF08cell=${0}\uFF0C\u5171 ${1} \u5217\uFF09", [target.cell, model.columns.length]));
|
|
3289
|
+
}
|
|
3290
|
+
if (args.text === void 0 && args.fixed === void 0) {
|
|
3291
|
+
return fail(
|
|
3292
|
+
tr(
|
|
3293
|
+
"\u6570\u636E\u884C\u5355\u5143\u683C\u53EA\u80FD\u8C03\u6574 text\uFF08\u503C\uFF0C\u4EE5 = \u5F00\u5934\u5373\u5217\u5F15\u7528\u516C\u5F0F\uFF09\u4E0E fixed\uFF08\u56FA\u5B9A\u6807\u8BB0\uFF09\uFF1B\u5217\u7ED3\u6784\u8BF7\u9009\u4E2D\u8868\u5934\u683C\uFF08row=0\uFF09\u8C03\u6574"
|
|
3294
|
+
)
|
|
3295
|
+
);
|
|
3296
|
+
}
|
|
3297
|
+
const width = model.columns.length;
|
|
3298
|
+
const base = model.defaultData ?? Array.from({ length: model.defaultRows }, () => Array.from({ length: width }, () => ""));
|
|
3299
|
+
const nextData = base.map(
|
|
3300
|
+
(row, ri) => ri === dataRow ? row.map((v, ci) => ci === target.cell && args.text !== void 0 ? args.text : v) : row
|
|
3301
|
+
);
|
|
3302
|
+
const fixed = args.fixed;
|
|
3303
|
+
const nextFixed = fixed === void 0 ? model.defaultDataCellFixed : (model.defaultDataCellFixed ?? Array.from({ length: model.defaultRows }, () => Array.from({ length: width }, () => false))).map((row, ri) => ri === dataRow ? row.map((v, ci) => ci === target.cell ? fixed : v) : row);
|
|
3304
|
+
const nextBlock = normalizeTableBlock({
|
|
3305
|
+
...block,
|
|
3306
|
+
dataTable: { ...model, defaultData: nextData, defaultDataCellFixed: nextFixed }
|
|
3307
|
+
});
|
|
3308
|
+
context.patchBlock(target.uid, { dataTable: nextBlock.dataTable });
|
|
3309
|
+
return ok(tr("\u7B2C ${0} \u884C\u7B2C ${1} \u683C\u5DF2\u8C03\u6574", [target.row, target.cell + 1]), { target });
|
|
3310
|
+
}
|
|
3311
|
+
});
|
|
3312
|
+
|
|
3313
|
+
// src/editor/features/templatedesigner/usetool/tools/idocsTplTableUpdate.ts
|
|
3314
|
+
var DATA_TABLE_MAX_COLUMNS = 10;
|
|
3315
|
+
var FORM_TABLE_MAX_ROWS = 20;
|
|
3316
|
+
var TABLE_ATTR_KEYS = ["defaultRows", "defaultDataEnabled", "defaultDataFixed", "defaultDataCellFixed"];
|
|
3317
|
+
function labelValueRow() {
|
|
3318
|
+
return { height: DEFAULT_FORM_ROW_HEIGHT, cells: [fixedCell("\u5B57\u6BB5\u540D", 20), fillableCell()] };
|
|
3319
|
+
}
|
|
3320
|
+
function fillRow() {
|
|
3321
|
+
return { height: DEFAULT_FORM_ROW_HEIGHT, cells: [fillableCell()] };
|
|
3322
|
+
}
|
|
3323
|
+
function summarizeDataTable(model) {
|
|
3324
|
+
return {
|
|
3325
|
+
variant: "data",
|
|
3326
|
+
columns: model.columns.length,
|
|
3327
|
+
defaultRows: model.defaultRows,
|
|
3328
|
+
defaultDataEnabled: model.defaultDataEnabled === true,
|
|
3329
|
+
defaultDataFixed: model.defaultDataFixed === true
|
|
3330
|
+
};
|
|
3331
|
+
}
|
|
3332
|
+
function summarizeFormTable(model) {
|
|
3333
|
+
return { variant: "form", rows: model.rows.length };
|
|
3334
|
+
}
|
|
3335
|
+
function opDomainFor(variant) {
|
|
3336
|
+
return variant === "data" ? "addColumn / removeColumn / addRow / removeRow" : "addRow / removeRow";
|
|
3337
|
+
}
|
|
3338
|
+
var getTableUpdateTool = (context) => ({
|
|
3339
|
+
name: "idocs_tpl_table_update",
|
|
3340
|
+
description: tr(
|
|
3341
|
+
'[idocs\u6A21\u677F\u8BBE\u8BA1\u5668-\u8868\u683C] \u8C03\u6574\u8868\u683C\u7684\u8868\u7EA7\u5C5E\u6027\u4E0E\u884C\u5217\u7ED3\u6784\u3002\u9002\u7528\u573A\u666F\uFF1A\u7528\u6237\u8BF4"\u9ED8\u8BA4\u884C\u6570\u6539\u6210 5/\u5F00\u542F\u9ED8\u8BA4\u6570\u636E/\u52A0\u4E00\u5217/\u5220\u4E00\u884C"\u65F6\u3002\u3010\u76EE\u6807\u3011uid \u7F3A\u7701\u4E3A\u5F53\u524D\u9009\u4E2D\u5757\uFF08\u5FC5\u987B\u8868\u683C\u5757\uFF0C\u5148\u8C03 get_status \u786E\u8BA4\uFF09\u3002'
|
|
3342
|
+
) + tr(
|
|
3343
|
+
"\u3010\u8868\u7EA7\u5C5E\u6027 attrs\u3011\u4EC5\u6570\u636E\u8868\u683C\uFF1AdefaultRows\uFF081-20 \u9ED8\u8BA4\u884C\u6570\uFF09/defaultDataEnabled\uFF08\u9ED8\u8BA4\u6570\u636E\u5F00\u5173\uFF09/defaultDataFixed\uFF08\u5168\u5C40\u56FA\u5B9A\uFF09/defaultDataCellFixed\uFF08\u5355\u5143\u683C\u56FA\u5B9A\u5E03\u5C14\u77E9\u9635\uFF0C\u9700\u9ED8\u8BA4\u6570\u636E\u5DF2\u542F\u7528\uFF09\uFF1B\u503C\u57DF\u7EC6\u8282\u5148\u8C03 idocs_tpl_block_schema\u3002\u56FA\u5B9A\u8868\u683C\u65E0\u8868\u7EA7\u5C5E\u6027\u3002"
|
|
3344
|
+
) + tr(
|
|
3345
|
+
'\u3010\u7ED3\u6784\u64CD\u4F5C op\u3011\u4E0E attrs \u540C\u4F20\u65F6\u5148\u6267\u884C op \u518D\u5E94\u7528 attrs\u3002\u6570\u636E\u8868\u683C\uFF1AaddColumn\uFF08index \u63D2\u5165\u4F4D\u7F6E\u7F3A\u7701\u8FFD\u52A0\u672B\u5C3E\uFF0Cheader \u7F3A\u7701"\u5217N"\uFF0CfieldType \u9650 text/select/date\uFF09\u3001removeColumn\uFF08index 0 \u8D77\u5217\u4E0B\u6807\uFF0C\u4EC5\u5269 1 \u5217\u62D2\u5220\uFF09\u3001addRow\uFF08\u9ED8\u8BA4\u6570\u636E\u884C +1\uFF0C\u8FBE 20 \u4E0A\u9650\u62D2\u52A0\uFF09\u3001removeRow\uFF08index 0 \u8D77\u6570\u636E\u884C\u4E0B\u6807\u4E0D\u542B\u8868\u5934\uFF0C\u4EC5\u5269 1 \u884C\u62D2\u5220\uFF09\uFF1B\u56FA\u5B9A\u8868\u683C\uFF1AaddRow\uFF08template="labelValue" \u8FFD\u52A0\u300C\u6807\u7B7E+\u586B\u5199\u300D\u884C / "fill" \u8FFD\u52A0\u6574\u884C\u586B\u5199\u884C\uFF0C\u7F3A\u7701 labelValue\uFF09\u3001removeRow\uFF08index 0 \u8D77\uFF0C\u542B\u7EB5\u5411\u5408\u5E76\u7684\u884C\u62D2\u5220\u9700\u5148\u62C6\u5206\uFF09\u3002'
|
|
3346
|
+
) + tr("\u3010\u8FB9\u754C\u3011\u5355\u5143\u683C\u5185\u5BB9/\u5E95\u8272/\u5408\u5E76/\u884C\u9AD8\u7528 idocs_tpl_cell_update\uFF1B\u6574\u8868\u91CD\u5EFA\u7528 idocs_tpl_table_generate\u3002"),
|
|
3347
|
+
inputSchema: {
|
|
3348
|
+
type: "object",
|
|
3349
|
+
properties: {
|
|
3350
|
+
uid: { type: "string", description: tr("\u53EF\u9009\uFF1A\u76EE\u6807\u8868\u683C\u5757 uid\uFF0C\u7F3A\u7701\u4E3A\u5F53\u524D\u9009\u4E2D\u5757") },
|
|
3351
|
+
attrs: {
|
|
3352
|
+
type: "object",
|
|
3353
|
+
description: tr(
|
|
3354
|
+
"\u53EF\u9009\uFF1A\uFF08\u4EC5\u6570\u636E\u8868\u683C\uFF09\u8868\u7EA7\u5C5E\u6027\u8865\u4E01\uFF0C\u952E\u9650 defaultRows/defaultDataEnabled/defaultDataFixed/defaultDataCellFixed"
|
|
3355
|
+
)
|
|
3356
|
+
},
|
|
3357
|
+
op: {
|
|
3358
|
+
type: "string",
|
|
3359
|
+
enum: ["addColumn", "removeColumn", "addRow", "removeRow"],
|
|
3360
|
+
description: tr("\u53EF\u9009\uFF1A\u7ED3\u6784\u64CD\u4F5C\uFF1B\u4E0E attrs \u540C\u4F20\u65F6\u5148\u6267\u884C op \u518D\u5E94\u7528 attrs")
|
|
3361
|
+
},
|
|
3362
|
+
index: {
|
|
3363
|
+
type: "number",
|
|
3364
|
+
description: tr(
|
|
3365
|
+
"op=removeColumn/removeRow \u7684\u76EE\u6807\u4E0B\u6807\uFF080 \u8D77\uFF1B\u6570\u636E\u884C\u4E0B\u6807\u4E0D\u542B\u8868\u5934\uFF09\uFF1BaddColumn \u7684\u63D2\u5165\u4F4D\u7F6E\uFF08\u7F3A\u7701\u8FFD\u52A0\u672B\u5C3E\uFF09"
|
|
3366
|
+
),
|
|
3367
|
+
minimum: 0
|
|
3368
|
+
},
|
|
3369
|
+
header: { type: "string", description: tr('op=addColumn \u7684\u5217\u8868\u5934\uFF08\u7F3A\u7701"\u5217N"\uFF09') },
|
|
3370
|
+
fieldType: {
|
|
3371
|
+
type: "string",
|
|
3372
|
+
enum: ["text", "select", "date"],
|
|
3373
|
+
description: tr("op=addColumn \u7684\u5217\u8F93\u5165\u7C7B\u578B\uFF08\u7F3A\u7701 text\uFF1B\u6570\u636E\u8868\u683C\u5217\u4E0D\u652F\u6301 formula\uFF09")
|
|
3374
|
+
},
|
|
3375
|
+
template: {
|
|
3376
|
+
type: "string",
|
|
3377
|
+
enum: ["labelValue", "fill"],
|
|
3378
|
+
description: tr("\uFF08\u56FA\u5B9A\u8868\u683C\uFF09op=addRow \u7684\u884C\u6A21\u677F\uFF1AlabelValue=\u300C\u6807\u7B7E+\u586B\u5199\u300D\u4E24\u683C\u884C\uFF08\u7F3A\u7701\uFF09\uFF0Cfill=\u6574\u884C\u586B\u5199")
|
|
3379
|
+
}
|
|
3380
|
+
}
|
|
3381
|
+
},
|
|
3382
|
+
execute: async (args) => {
|
|
3383
|
+
const state = context.stateRef.current;
|
|
3384
|
+
const found = findBlock(state, args.uid, { tableOnly: true });
|
|
3385
|
+
if (!found.ok) return found.result;
|
|
3386
|
+
const block = found.value;
|
|
3387
|
+
const uid = block.uid;
|
|
3388
|
+
const hasAttrs = args.attrs !== void 0 && Object.keys(args.attrs).length > 0;
|
|
3389
|
+
if (args.op === void 0 && !hasAttrs) {
|
|
3390
|
+
return fail(tr("\u6CA1\u6709\u8981\u4FEE\u6539\u7684\u5185\u5BB9\uFF1A\u8BF7\u4F20 op\uFF08\u884C\u5217\u7ED3\u6784\u64CD\u4F5C\uFF09\u6216 attrs\uFF08\u8868\u7EA7\u5C5E\u6027\u8865\u4E01\uFF09"));
|
|
3391
|
+
}
|
|
3392
|
+
if (block.tableVariant === "form") {
|
|
3393
|
+
const model2 = block.formTable;
|
|
3394
|
+
if (!model2) {
|
|
3395
|
+
return fail(tr("\u8BE5\u8868\u683C\u5757\u7F3A\u5C11\u56FA\u5B9A\u8868\u683C\u6A21\u578B"));
|
|
3396
|
+
}
|
|
3397
|
+
if (hasAttrs) {
|
|
3398
|
+
return fail(
|
|
3399
|
+
tr(
|
|
3400
|
+
"\u56FA\u5B9A\u8868\u683C\u6CA1\u6709\u8868\u7EA7\u5C5E\u6027\u53EF\u8865\u4E01\uFF08\u56FA\u5B9A\u8868\u683C\u6A21\u578B\u4EC5 rows \u884C\u5217\u8868\uFF1B\u5F53\u524D\u4F20\u5165\u952E\uFF1A${0}\u3002\u5EFA\u8BAE\uFF1A\u884C\u8FFD\u52A0/\u5220\u9664\u7528 op=addRow/removeRow\uFF0C\u884C\u9AD8\u4E0E\u683C\u5C5E\u6027\u7528 idocs_tpl_cell_update\uFF09",
|
|
3401
|
+
[Object.keys(args.attrs ?? {}).join("\u3001")]
|
|
3402
|
+
)
|
|
3403
|
+
);
|
|
3404
|
+
}
|
|
3405
|
+
if (args.op !== "addRow" && args.op !== "removeRow") {
|
|
3406
|
+
return fail(
|
|
3407
|
+
tr(
|
|
3408
|
+
"\u56FA\u5B9A\u8868\u683C\u4E0D\u652F\u6301 op=${0}\uFF08\u5408\u6CD5\u503C\uFF1A${1}\uFF1B\u56FA\u5B9A\u8868\u683C\u6BCF\u884C\u72EC\u7ACB\u5B9A\u4E49\u5355\u5143\u683C\uFF0C\u65E0\u7EDF\u4E00\u5217\u7ED3\u6784\u3002\u5EFA\u8BAE\uFF1A\u683C\u7EA7\u5185\u5BB9/\u5BBD\u5EA6/\u5408\u5E76\u7528 idocs_tpl_cell_update\uFF09",
|
|
3409
|
+
[formatAttrValue(args.op), opDomainFor("form")]
|
|
3410
|
+
)
|
|
3411
|
+
);
|
|
3412
|
+
}
|
|
3413
|
+
let nextRows;
|
|
3414
|
+
let opLabel;
|
|
3415
|
+
if (args.op === "addRow") {
|
|
3416
|
+
if (model2.rows.length >= FORM_TABLE_MAX_ROWS) {
|
|
3417
|
+
return fail(
|
|
3418
|
+
tr("\u56FA\u5B9A\u8868\u683C\u884C\u6570\u5DF2\u8FBE\u4E0A\u9650\uFF08\u5F53\u524D\u503C\uFF1A${0} \u884C\uFF1B\u5408\u6CD5\u503C\uFF1A\u2264 ${1} \u884C\u3002\u5EFA\u8BAE\uFF1A\u5220\u9664\u5197\u4F59\u884C\u540E\u518D\u8FFD\u52A0\uFF09", [
|
|
3419
|
+
model2.rows.length,
|
|
3420
|
+
FORM_TABLE_MAX_ROWS
|
|
3421
|
+
])
|
|
3422
|
+
);
|
|
3423
|
+
}
|
|
3424
|
+
if (args.template !== void 0 && args.template !== "labelValue" && args.template !== "fill") {
|
|
3425
|
+
return fail(
|
|
3426
|
+
tr(
|
|
3427
|
+
'op=addRow \u7684 template \u53D6\u503C\u8D8A\u754C\uFF08\u5F53\u524D\u503C\uFF1A${0}\uFF1B\u5408\u6CD5\u503C\uFF1A"labelValue" / "fill"\u3002\u5EFA\u8BAE\uFF1A\u7F3A\u7701\u6309 labelValue \u8FFD\u52A0\u300C\u6807\u7B7E+\u586B\u5199\u300D\u884C\uFF09',
|
|
3428
|
+
[formatAttrValue(args.template)]
|
|
3429
|
+
)
|
|
3430
|
+
);
|
|
3431
|
+
}
|
|
3432
|
+
nextRows = [...model2.rows, args.template === "fill" ? fillRow() : labelValueRow()];
|
|
3433
|
+
opLabel = args.template === "fill" ? tr("\u8FFD\u52A0\u6574\u884C\u586B\u5199\u884C") : tr("\u8FFD\u52A0\u300C\u6807\u7B7E+\u586B\u5199\u300D\u884C");
|
|
3434
|
+
} else {
|
|
3435
|
+
const index = args.index;
|
|
3436
|
+
if (typeof index !== "number" || !Number.isInteger(index) || index < 0 || index >= model2.rows.length) {
|
|
3437
|
+
return fail(
|
|
3438
|
+
tr(
|
|
3439
|
+
"op=removeRow \u7684 index \u8D8A\u754C\uFF08\u5F53\u524D\u503C\uFF1A${0}\uFF1B\u5408\u6CD5\u503C\uFF1A0 ~ ${1} \u7684\u6574\u6570\u884C\u4E0B\u6807\u3002\u5EFA\u8BAE\uFF1A\u5148\u8C03 idocs_tpl_get \u786E\u8BA4\u884C\u6570\uFF09",
|
|
3440
|
+
[formatAttrValue(index), model2.rows.length - 1]
|
|
3441
|
+
)
|
|
3442
|
+
);
|
|
3443
|
+
}
|
|
3444
|
+
if (model2.rows.length <= 1) {
|
|
3445
|
+
return fail(tr("\u56FA\u5B9A\u8868\u683C\u81F3\u5C11\u4FDD\u7559 1 \u884C\uFF0C\u62D2\u7EDD\u5220\u9664\u6700\u540E\u4E00\u884C\u3002\u5EFA\u8BAE\uFF1A\u6574\u8868\u79FB\u9664\u8BF7\u7528 idocs_tpl_block_remove"));
|
|
3446
|
+
}
|
|
3447
|
+
const row = model2.rows[index];
|
|
3448
|
+
if (row.cells.some((cell) => cell.covered === true || cellRowspan(cell) > 1)) {
|
|
3449
|
+
return fail(
|
|
3450
|
+
tr(
|
|
3451
|
+
"\u7B2C ${0} \u884C\u542B\u7EB5\u5411\u5408\u5E76\u5355\u5143\u683C\uFF0C\u8BF7\u5148\u62C6\u5206\u5408\u5E76\u540E\u518D\u5220\u9664\uFF08\u5EFA\u8BAE\uFF1A\u5BF9\u5408\u5E76\u4E3B\u683C\u7528 idocs_tpl_cell_update \u4F20 rowspan=1 \u62C6\u5206\uFF09",
|
|
3452
|
+
[index + 1]
|
|
3453
|
+
)
|
|
3454
|
+
);
|
|
3455
|
+
}
|
|
3456
|
+
nextRows = model2.rows.filter((_, ri) => ri !== index);
|
|
3457
|
+
opLabel = tr("\u5220\u9664\u7B2C ${0} \u884C", [index + 1]);
|
|
3458
|
+
}
|
|
3459
|
+
const nextBlock2 = normalizeTableBlock({ ...block, formTable: { rows: nextRows } });
|
|
3460
|
+
context.patchBlock(uid, { formTable: nextBlock2.formTable });
|
|
3461
|
+
return ok(tr("\u56FA\u5B9A\u8868\u683C\u5DF2\u8C03\u6574\uFF08${0}\uFF09", [opLabel]), {
|
|
3462
|
+
uid,
|
|
3463
|
+
applied: [`op:${args.op}`],
|
|
3464
|
+
current: summarizeFormTable(nextBlock2.formTable ?? { rows: nextRows })
|
|
3465
|
+
});
|
|
3466
|
+
}
|
|
3467
|
+
const model = block.dataTable;
|
|
3468
|
+
if (!model) {
|
|
3469
|
+
return fail(tr("\u8BE5\u8868\u683C\u5757\u7F3A\u5C11\u6570\u636E\u8868\u683C\u6A21\u578B"));
|
|
3470
|
+
}
|
|
3471
|
+
let working = model;
|
|
3472
|
+
const applied = [];
|
|
3473
|
+
if (args.op !== void 0) {
|
|
3474
|
+
if (args.op === "addColumn") {
|
|
3475
|
+
if (working.columns.length >= DATA_TABLE_MAX_COLUMNS) {
|
|
3476
|
+
return fail(
|
|
3477
|
+
tr("\u6570\u636E\u8868\u683C\u5217\u6570\u5DF2\u8FBE\u4E0A\u9650\uFF08\u5F53\u524D\u503C\uFF1A${0} \u5217\uFF1B\u5408\u6CD5\u503C\uFF1A\u2264 ${1} \u5217\u3002\u5EFA\u8BAE\uFF1A\u5220\u9664\u5197\u4F59\u5217\u540E\u518D\u65B0\u589E\uFF09", [
|
|
3478
|
+
working.columns.length,
|
|
3479
|
+
DATA_TABLE_MAX_COLUMNS
|
|
3480
|
+
])
|
|
3481
|
+
);
|
|
3482
|
+
}
|
|
3483
|
+
const columnIndex = args.index === void 0 ? working.columns.length : args.index;
|
|
3484
|
+
if (!Number.isInteger(columnIndex) || columnIndex < 0 || columnIndex > working.columns.length) {
|
|
3485
|
+
return fail(
|
|
3486
|
+
tr(
|
|
3487
|
+
"op=addColumn \u7684 index \u8D8A\u754C\uFF08\u5F53\u524D\u503C\uFF1A${0}\uFF1B\u5408\u6CD5\u503C\uFF1A0 ~ ${1} \u7684\u6574\u6570\uFF08${1} = \u8FFD\u52A0\u5230\u672B\u5C3E\uFF0C\u7F3A\u7701\u540C\uFF09\u3002\u5EFA\u8BAE\uFF1A\u4FEE\u6B63\u540E\u91CD\u8BD5\uFF09",
|
|
3488
|
+
[formatAttrValue(args.index), working.columns.length]
|
|
3489
|
+
)
|
|
3490
|
+
);
|
|
3491
|
+
}
|
|
3492
|
+
if (args.header !== void 0 && (typeof args.header !== "string" || args.header.trim().length === 0)) {
|
|
3493
|
+
return fail(
|
|
3494
|
+
tr('op=addColumn \u7684 header \u987B\u4E3A\u975E\u7A7A\u5B57\u7B26\u4E32\uFF08\u5F53\u524D\u503C\uFF1A${0}\u3002\u5EFA\u8BAE\uFF1A\u7F3A\u7701\u81EA\u52A8\u547D\u540D"\u5217N"\uFF09', [
|
|
3495
|
+
formatAttrValue(args.header)
|
|
3496
|
+
])
|
|
3497
|
+
);
|
|
3498
|
+
}
|
|
3499
|
+
if (args.fieldType !== void 0) {
|
|
3500
|
+
const check = validateAttrValue(DESIGNER_DATA_COLUMN_ATTRS, "fieldType", args.fieldType);
|
|
3501
|
+
if (!check.ok) return fail(check.message);
|
|
3502
|
+
}
|
|
3503
|
+
const newColumn = {
|
|
3504
|
+
header: args.header ?? `\u5217${working.columns.length + 1}`,
|
|
3505
|
+
// 面板列类型切换口径:text 即缺省不落字段
|
|
3506
|
+
...args.fieldType !== void 0 && args.fieldType !== "text" ? { fieldType: args.fieldType } : {}
|
|
3507
|
+
};
|
|
3508
|
+
working = {
|
|
3509
|
+
...working,
|
|
3510
|
+
columns: [...working.columns.slice(0, columnIndex), newColumn, ...working.columns.slice(columnIndex)],
|
|
3511
|
+
defaultData: working.defaultData?.map((row) => [...row.slice(0, columnIndex), "", ...row.slice(columnIndex)]),
|
|
3512
|
+
defaultDataCellFixed: working.defaultDataCellFixed?.map((row) => [
|
|
3513
|
+
...row.slice(0, columnIndex),
|
|
3514
|
+
false,
|
|
3515
|
+
...row.slice(columnIndex)
|
|
3516
|
+
])
|
|
3517
|
+
};
|
|
3518
|
+
applied.push(tr("op:addColumn\uFF08\u7B2C ${0} \u5217\u300C${1}\u300D\uFF09", [columnIndex + 1, newColumn.header]));
|
|
3519
|
+
} else if (args.op === "removeColumn") {
|
|
3520
|
+
const index = args.index;
|
|
3521
|
+
if (typeof index !== "number" || !Number.isInteger(index) || index < 0 || index >= working.columns.length) {
|
|
3522
|
+
return fail(
|
|
3523
|
+
tr(
|
|
3524
|
+
"op=removeColumn \u7684 index \u8D8A\u754C\uFF08\u5F53\u524D\u503C\uFF1A${0}\uFF1B\u5408\u6CD5\u503C\uFF1A0 ~ ${1} \u7684\u6574\u6570\u5217\u4E0B\u6807\u3002\u5EFA\u8BAE\uFF1A\u5148\u8C03 idocs_tpl_get \u786E\u8BA4\u5217\u6570\uFF09",
|
|
3525
|
+
[formatAttrValue(index), working.columns.length - 1]
|
|
3526
|
+
)
|
|
3527
|
+
);
|
|
3528
|
+
}
|
|
3529
|
+
if (working.columns.length <= 1) {
|
|
3530
|
+
return fail(tr("\u6570\u636E\u8868\u683C\u81F3\u5C11\u4FDD\u7559 1 \u5217\uFF0C\u62D2\u7EDD\u5220\u9664\u6700\u540E\u4E00\u5217\u3002\u5EFA\u8BAE\uFF1A\u6574\u8868\u79FB\u9664\u8BF7\u7528 idocs_tpl_block_remove"));
|
|
3531
|
+
}
|
|
3532
|
+
working = {
|
|
3533
|
+
...working,
|
|
3534
|
+
columns: working.columns.filter((_, ci) => ci !== index),
|
|
3535
|
+
defaultData: working.defaultData?.map((row) => row.filter((_, ci) => ci !== index)),
|
|
3536
|
+
defaultDataCellFixed: working.defaultDataCellFixed?.map((row) => row.filter((_, ci) => ci !== index))
|
|
3537
|
+
};
|
|
3538
|
+
applied.push(tr("op:removeColumn\uFF08\u7B2C ${0} \u5217\uFF09", [index + 1]));
|
|
3539
|
+
} else if (args.op === "addRow") {
|
|
3540
|
+
const defaultRows = working.defaultRows ?? 1;
|
|
3541
|
+
if (defaultRows >= MAX_DATA_TABLE_ROWS) {
|
|
3542
|
+
return fail(
|
|
3543
|
+
tr("\u6570\u636E\u8868\u683C\u9ED8\u8BA4\u884C\u6570\u5DF2\u8FBE\u4E0A\u9650\uFF08\u5F53\u524D\u503C\uFF1A${0} \u884C\uFF1B\u5408\u6CD5\u503C\uFF1A\u2264 ${1} \u884C\u3002\u5EFA\u8BAE\uFF1A\u5220\u9664\u5197\u4F59\u9ED8\u8BA4\u884C\u540E\u518D\u65B0\u589E\uFF09", [
|
|
3544
|
+
defaultRows,
|
|
3545
|
+
MAX_DATA_TABLE_ROWS
|
|
3546
|
+
])
|
|
3547
|
+
);
|
|
3548
|
+
}
|
|
3549
|
+
working = { ...working, defaultRows: defaultRows + 1 };
|
|
3550
|
+
applied.push(tr("op:addRow\uFF08\u9ED8\u8BA4\u884C\u6570 ${0} \u2192 ${1}\uFF09", [defaultRows, defaultRows + 1]));
|
|
3551
|
+
} else if (args.op === "removeRow") {
|
|
3552
|
+
const defaultRows = working.defaultRows ?? 1;
|
|
3553
|
+
const index = args.index;
|
|
3554
|
+
if (typeof index !== "number" || !Number.isInteger(index) || index < 0 || index >= defaultRows) {
|
|
3555
|
+
return fail(
|
|
3556
|
+
tr(
|
|
3557
|
+
"op=removeRow \u7684 index \u8D8A\u754C\uFF08\u5F53\u524D\u503C\uFF1A${0}\uFF1B\u5408\u6CD5\u503C\uFF1A0 ~ ${1} \u7684\u6574\u6570\u6570\u636E\u884C\u4E0B\u6807\uFF080 \u8D77\uFF0C\u4E0D\u542B\u8868\u5934\uFF09\u3002\u5EFA\u8BAE\uFF1A\u5148\u8C03 idocs_tpl_get \u786E\u8BA4\u9ED8\u8BA4\u884C\u6570\uFF09",
|
|
3558
|
+
[formatAttrValue(index), defaultRows - 1]
|
|
3559
|
+
)
|
|
3560
|
+
);
|
|
3561
|
+
}
|
|
3562
|
+
if (defaultRows <= 1) {
|
|
3563
|
+
return fail(tr("\u6570\u636E\u8868\u683C\u81F3\u5C11\u4FDD\u7559 1 \u884C\uFF0C\u62D2\u7EDD\u5220\u9664\u6700\u540E\u4E00\u884C\u3002\u5EFA\u8BAE\uFF1A\u6574\u8868\u79FB\u9664\u8BF7\u7528 idocs_tpl_block_remove"));
|
|
3564
|
+
}
|
|
3565
|
+
working = {
|
|
3566
|
+
...working,
|
|
3567
|
+
defaultRows: defaultRows - 1,
|
|
3568
|
+
defaultData: working.defaultData?.filter((_, ri) => ri !== index),
|
|
3569
|
+
defaultDataCellFixed: working.defaultDataCellFixed?.filter((_, ri) => ri !== index)
|
|
3570
|
+
};
|
|
3571
|
+
applied.push(tr("op:removeRow\uFF08\u7B2C ${0} \u6570\u636E\u884C\uFF09", [index + 1]));
|
|
3572
|
+
} else {
|
|
3573
|
+
return fail(tr("op \u53D6\u503C\u8D8A\u754C\uFF08\u5F53\u524D\u503C\uFF1A${0}\uFF1B\u5408\u6CD5\u503C\uFF1A${1}\uFF09", [formatAttrValue(args.op), opDomainFor("data")]));
|
|
3574
|
+
}
|
|
3575
|
+
}
|
|
3576
|
+
let requestedDisable = false;
|
|
3577
|
+
if (hasAttrs) {
|
|
3578
|
+
const attrs = args.attrs ?? {};
|
|
3579
|
+
const entries = Object.entries(attrs);
|
|
3580
|
+
const attrPatch = {};
|
|
3581
|
+
for (const [key, value] of entries) {
|
|
3582
|
+
if (key === "columns") {
|
|
3583
|
+
return fail(
|
|
3584
|
+
tr(
|
|
3585
|
+
"\u5C5E\u6027 columns \u662F\u5217\u7ED3\u6784\u6574\u4F53\uFF0C\u4E0D\u8D70 attrs \u8865\u4E01\u3002\u5EFA\u8BAE\uFF1A\u589E\u5220\u5217\u7528 op=addColumn/removeColumn\uFF1B\u6539\u5217\u540D/\u5217\u5BBD/\u5217\u7C7B\u578B\u9009\u4E2D\u8868\u5934\u683C\u7528 idocs_tpl_cell_update"
|
|
3586
|
+
)
|
|
3587
|
+
);
|
|
3588
|
+
}
|
|
3589
|
+
if (key === "defaultData") {
|
|
3590
|
+
return fail(
|
|
3591
|
+
tr(
|
|
3592
|
+
"\u5C5E\u6027 defaultData \u662F\u9ED8\u8BA4\u6570\u636E\u77E9\u9635\u6574\u4F53\uFF0C\u4E0D\u8D70 attrs \u8865\u4E01\u3002\u5EFA\u8BAE\uFF1A\u9010\u683C\u6539\u503C\u7528 idocs_tpl_cell_update \u7684\u6570\u636E\u884C\u5206\u652F\uFF08row \u2265 1\uFF09"
|
|
3593
|
+
)
|
|
3594
|
+
);
|
|
3595
|
+
}
|
|
3596
|
+
if (!TABLE_ATTR_KEYS.includes(key)) {
|
|
3597
|
+
return fail(
|
|
3598
|
+
tr(
|
|
3599
|
+
"\u5C5E\u6027 ${0} \u4E0D\u5728\u8868\u7EA7\u53EF\u5199\u6E05\u5355\u5185\uFF08\u5F53\u524D\u503C\uFF1A${1}\uFF1B\u5408\u6CD5\u503C\uFF1A${2}\u3002\u5EFA\u8BAE\uFF1A\u5148\u8C03 idocs_tpl_block_schema \u67E5\u8BE2\u8BE5\u5757\u578B\u7684\u53EF\u5199\u5C5E\u6027\uFF09",
|
|
3600
|
+
[key, formatAttrValue(value), TABLE_ATTR_KEYS.join("\u3001")]
|
|
3601
|
+
)
|
|
3602
|
+
);
|
|
3603
|
+
}
|
|
3604
|
+
const check = validateAttrValue(DESIGNER_DATA_TABLE_ATTRS, key, value);
|
|
3605
|
+
if (!check.ok) return fail(check.message);
|
|
3606
|
+
if (key === "defaultDataCellFixed") {
|
|
3607
|
+
if (!Array.isArray(value) || !value.every((row) => Array.isArray(row) && row.every((item) => typeof item === "boolean"))) {
|
|
3608
|
+
return fail(
|
|
3609
|
+
tr(
|
|
3610
|
+
"\u5C5E\u6027 defaultDataCellFixed \u5F62\u6001\u9519\u8BEF\uFF08\u5F53\u524D\u503C\uFF1A${0}\uFF1B\u5408\u6CD5\u503C\uFF1A\u5E03\u5C14\u77E9\u9635\uFF08\u884C\xD7\u5217\uFF0C\u4E0E\u9ED8\u8BA4\u6570\u636E\u540C\u7EF4\uFF09\u3002\u5EFA\u8BAE\uFF1A\u4FEE\u6B63\u540E\u91CD\u8BD5\uFF09",
|
|
3611
|
+
[formatAttrValue(value)]
|
|
3612
|
+
)
|
|
3613
|
+
);
|
|
3614
|
+
}
|
|
3615
|
+
}
|
|
3616
|
+
attrPatch[key] = value;
|
|
3617
|
+
}
|
|
3618
|
+
const wantsDisable = attrPatch.defaultDataEnabled === false;
|
|
3619
|
+
const fixedKeys = entries.map(([key]) => key).filter((key) => key === "defaultDataFixed" || key === "defaultDataCellFixed");
|
|
3620
|
+
if (wantsDisable && fixedKeys.length > 0) {
|
|
3621
|
+
return fail(
|
|
3622
|
+
tr(
|
|
3623
|
+
"\u5173\u95ED\u9ED8\u8BA4\u6570\u636E\u7684\u540C\u65F6\u4E0D\u80FD\u8BBE\u7F6E\u56FA\u5B9A\u6807\u8BB0\uFF08${0} \u968F\u5173\u95ED\u4E00\u5E76\u5F52\u96F6\u3002\u5EFA\u8BAE\uFF1A\u5982\u9700\u4FDD\u7559\u56FA\u5B9A\uFF0C\u53BB\u6389 defaultDataEnabled=false\uFF09",
|
|
3624
|
+
[fixedKeys.join("\u3001")]
|
|
3625
|
+
)
|
|
3626
|
+
);
|
|
3627
|
+
}
|
|
3628
|
+
if (!wantsDisable && fixedKeys.length > 0) {
|
|
3629
|
+
const enabledAfter = (attrPatch.defaultDataEnabled ?? working.defaultDataEnabled) === true;
|
|
3630
|
+
const hasData = (working.defaultData ?? []).some((row) => row.some((cell) => (cell ?? "").trim().length > 0));
|
|
3631
|
+
if (!enabledAfter && !hasData) {
|
|
3632
|
+
return fail(
|
|
3633
|
+
tr(
|
|
3634
|
+
"\u9ED8\u8BA4\u6570\u636E\u672A\u542F\u7528\uFF0C\u56FA\u5B9A\u6807\u8BB0\uFF08${0}\uFF09\u4F1A\u88AB\u5F52\u4E00\u5316\u6E05\u96F6\uFF08\u5F53\u524D\u503C\uFF1AdefaultDataEnabled=${1}\u3002\u5EFA\u8BAE\uFF1A\u5148\u4F20 defaultDataEnabled=true \u5F00\u542F\u9ED8\u8BA4\u6570\u636E\uFF0C\u518D\u8BBE\u7F6E\u56FA\u5B9A\u6807\u8BB0\uFF09",
|
|
3635
|
+
[fixedKeys.join("\u3001"), formatAttrValue(working.defaultDataEnabled)]
|
|
3636
|
+
)
|
|
3637
|
+
);
|
|
3638
|
+
}
|
|
3639
|
+
}
|
|
3640
|
+
requestedDisable = wantsDisable;
|
|
3641
|
+
working = { ...working, ...attrPatch };
|
|
3642
|
+
applied.push(...entries.map(([key]) => `attrs:${key}`));
|
|
3643
|
+
}
|
|
3644
|
+
const nextBlock = normalizeTableBlock({ ...block, dataTable: working });
|
|
3645
|
+
let finalModel = nextBlock.dataTable ?? working;
|
|
3646
|
+
if (requestedDisable) {
|
|
3647
|
+
finalModel = {
|
|
3648
|
+
...finalModel,
|
|
3649
|
+
defaultDataEnabled: false,
|
|
3650
|
+
defaultDataFixed: false,
|
|
3651
|
+
defaultData: working.defaultData ?? finalModel.defaultData,
|
|
3652
|
+
defaultDataCellFixed: working.defaultDataCellFixed ?? finalModel.defaultDataCellFixed
|
|
3653
|
+
};
|
|
3654
|
+
}
|
|
3655
|
+
const blockPatch = { dataTable: finalModel };
|
|
3656
|
+
context.patchBlock(uid, blockPatch);
|
|
3657
|
+
return ok(tr("\u6570\u636E\u8868\u683C\u5DF2\u8C03\u6574\uFF08${0}\uFF09", [applied.join("\u3001")]), {
|
|
3658
|
+
uid,
|
|
3659
|
+
applied,
|
|
3660
|
+
current: summarizeDataTable(finalModel)
|
|
3661
|
+
});
|
|
3662
|
+
}
|
|
3663
|
+
});
|
|
3664
|
+
|
|
3665
|
+
// src/editor/features/templatedesigner/usetool/tools/idocsTplBlockUpdate.ts
|
|
3666
|
+
var TABLE_MODEL_KEYS = ["dataTable", "formTable"];
|
|
3667
|
+
var getBlockUpdateTool = (context) => ({
|
|
3668
|
+
name: "idocs_tpl_block_update",
|
|
3669
|
+
description: tr("[idocs\u6A21\u677F\u8BBE\u8BA1\u5668-\u753B\u5E03] \u6309 uid \u4FEE\u6539\u5355\u4E2A\u5757\u7684\u8868\u73B0\u7C7B\u5C5E\u6027\uFF08\u6807\u9898\u3001\u6587\u672C\u3001\u6807\u9898\u7EA7\u522B\u3001\u56FE\u7247\u5BBD\u9AD8\u7B49\uFF09\u3002") + tr("attrs \u4E3A\u5C5E\u6027\u8865\u4E01\u952E\u503C\u5BF9\uFF0C\u5408\u6CD5\u952E\u4E0E\u503C\u57DF\u5148\u8C03 idocs_tpl_block_schema \u67E5\u8BE2\uFF1Buid \u7F3A\u7701\u4E3A\u5F53\u524D\u9009\u4E2D\u5757\u3002") + tr(
|
|
3670
|
+
"\u7ED3\u6784\u5C5E\u6027\uFF08pin/before/after/groupId/groupLabel\uFF09\u8BF7\u7528 idocs_tpl_structure_ops\uFF1B\u8868\u683C\u5355\u5143\u683C\u8BF7\u7528 idocs_tpl_cell_update\uFF1B\u6574\u8868\u91CD\u5EFA\u8BF7\u7528 idocs_tpl_table_generate\u3002"
|
|
3671
|
+
),
|
|
3672
|
+
inputSchema: {
|
|
3673
|
+
type: "object",
|
|
3674
|
+
properties: {
|
|
3675
|
+
uid: { type: "string", description: tr("\u53EF\u9009\uFF1A\u76EE\u6807\u5757 uid\uFF0C\u7F3A\u7701\u4E3A\u5F53\u524D\u9009\u4E2D\u5757") },
|
|
3676
|
+
attrs: {
|
|
3677
|
+
type: "object",
|
|
3678
|
+
description: tr("\u5C5E\u6027\u8865\u4E01\u952E\u503C\u5BF9\uFF08\u4E3B\u901A\u9053\uFF09\uFF1A\u952E\u4E3A\u8BE5\u5757\u578B\u53EF\u5199\u8868\u73B0\u5C5E\u6027\uFF0C\u503C\u987B\u8FC7\u503C\u57DF\u6821\u9A8C")
|
|
3679
|
+
}
|
|
3680
|
+
}
|
|
3681
|
+
},
|
|
3682
|
+
execute: async (args) => {
|
|
3683
|
+
const { current, activeUid } = context.stateRef.current;
|
|
3684
|
+
const uid = args.uid ?? activeUid;
|
|
3685
|
+
if (!uid) {
|
|
3686
|
+
return fail(tr("\u672A\u6307\u5B9A\u76EE\u6807\u5757\uFF0C\u4E14\u753B\u5E03\u5F53\u524D\u6CA1\u6709\u9009\u4E2D\u4EFB\u4F55\u5757\u3002\u8BF7\u5148\u8BA9\u7528\u6237\u9009\u4E2D\u5757\uFF0C\u6216\u7528 uid \u53C2\u6570\u663E\u5F0F\u6307\u5B9A"));
|
|
3687
|
+
}
|
|
3688
|
+
const found = findBlock({ current }, uid);
|
|
3689
|
+
if (!found.ok) return found.result;
|
|
3690
|
+
const block = found.value;
|
|
3691
|
+
const incoming = { ...args.attrs ?? {} };
|
|
3692
|
+
if (Object.keys(incoming).length === 0) {
|
|
3693
|
+
return fail(tr("\u6CA1\u6709\u8981\u4FEE\u6539\u7684\u5B57\u6BB5"));
|
|
3694
|
+
}
|
|
3695
|
+
if (block.type === "table" && (incoming.text !== void 0 || incoming.required !== void 0)) {
|
|
3696
|
+
return fail(
|
|
3697
|
+
tr(
|
|
3698
|
+
"\u8868\u683C\u5757\u4E0D\u652F\u6301\u5728\u5757\u7EA7\u4FEE\u6539 text/required\uFF1A\u5355\u5143\u683C\u5185\u5BB9\u8BF7\u7528 idocs_tpl_cell_update\uFF0C\u6574\u8868\u91CD\u5EFA\u8BF7\u7528 idocs_tpl_table_generate"
|
|
3699
|
+
)
|
|
3700
|
+
);
|
|
3701
|
+
}
|
|
3702
|
+
const writable = getWritableMeta(block.type, "appearance");
|
|
3703
|
+
const known = getBlockAttrMeta(block.type);
|
|
3704
|
+
const patch = {};
|
|
3705
|
+
for (const [key, value] of Object.entries(incoming)) {
|
|
3706
|
+
if (writable.some((meta) => meta.key === key)) {
|
|
3707
|
+
const check = validateAttrValue(writable, key, value);
|
|
3708
|
+
if (!check.ok) return fail(check.message);
|
|
3709
|
+
patch[key] = value;
|
|
3710
|
+
continue;
|
|
3711
|
+
}
|
|
3712
|
+
const knownMeta = known.find((meta) => meta.key === key);
|
|
3713
|
+
if (knownMeta?.scope === "structure") {
|
|
3714
|
+
return fail(
|
|
3715
|
+
tr("\u5C5E\u6027 ${0} \u4E3A\u7ED3\u6784\u5C5E\u6027\uFF0C\u8BF7\u7528 idocs_tpl_structure_ops\uFF08\u5F53\u524D\u503C\uFF1A${1}\uFF09", [
|
|
3716
|
+
key,
|
|
3717
|
+
formatAttrValue(block[key])
|
|
3718
|
+
])
|
|
3719
|
+
);
|
|
3720
|
+
}
|
|
3721
|
+
if (TABLE_MODEL_KEYS.includes(key)) {
|
|
3722
|
+
return fail(
|
|
3723
|
+
tr(
|
|
3724
|
+
"\u5C5E\u6027 ${0} \u662F\u8868\u683C\u6A21\u578B\uFF0C\u4E0D\u5728\u5757\u7EA7\u8C03\u6574\uFF1A\u5355\u5143\u683C\u8BF7\u7528 idocs_tpl_cell_update\uFF0C\u6574\u8868\u8BF7\u7528 idocs_tpl_table_generate",
|
|
3725
|
+
[key]
|
|
3726
|
+
)
|
|
3727
|
+
);
|
|
3728
|
+
}
|
|
3729
|
+
if (knownMeta) {
|
|
3730
|
+
return fail(tr("\u5C5E\u6027 ${0} \u662F\u5757\u7684\u6807\u8BC6\u5C5E\u6027\uFF0C\u4E0D\u53EF\u4FEE\u6539", [key]));
|
|
3731
|
+
}
|
|
3732
|
+
const validKeys = writable.map((meta) => meta.key).join("\u3001");
|
|
3733
|
+
return fail(
|
|
3734
|
+
validKeys ? tr("\u5C5E\u6027 ${0} \u4E0D\u662F ${1} \u5757\u7684\u53EF\u5199\u8868\u73B0\u5C5E\u6027\uFF08\u5408\u6CD5\u952E\uFF1A${2}\u3002\u5EFA\u8BAE\uFF1A\u5148\u8C03 idocs_tpl_block_schema \u67E5\u8BE2\uFF09", [
|
|
3735
|
+
key,
|
|
3736
|
+
block.type,
|
|
3737
|
+
validKeys
|
|
3738
|
+
]) : tr("${0} \u5757\u6CA1\u6709\u767B\u8BB0\u53EF\u5199\u8868\u73B0\u5C5E\u6027\uFF08\u81EA\u5B9A\u4E49\u5757\u578B\u7684\u4E13\u6709\u5C5E\u6027\u8BF7\u843D\u5728\u5176 data \u5B57\u6BB5\u5185\uFF09", [block.type])
|
|
3739
|
+
);
|
|
3740
|
+
}
|
|
3741
|
+
context.patchBlock(uid, patch);
|
|
3742
|
+
const merged = { ...block, ...patch };
|
|
3743
|
+
return ok(tr("\u5757\u300C${0}\u300D\u5DF2\u8C03\u6574\uFF08${1}\uFF09", [merged.label || block.type, Object.keys(patch).join("\u3001")]), {
|
|
3744
|
+
uid,
|
|
3745
|
+
applied: Object.keys(patch),
|
|
3746
|
+
current: buildAttrSummary(merged)
|
|
3747
|
+
});
|
|
3748
|
+
}
|
|
3749
|
+
});
|
|
3750
|
+
|
|
3751
|
+
// src/editor/features/templatedesigner/usetool/tools/idocsTplStructureOps.ts
|
|
3752
|
+
var OP_LABELS = {
|
|
3753
|
+
pin: tr("\u9489\u4F4F"),
|
|
3754
|
+
order: tr("\u987A\u5E8F\u7EA6\u675F"),
|
|
3755
|
+
group: tr("\u52A0\u5165\u7EC4\u4EF6\u7EC4"),
|
|
3756
|
+
ungroup: tr("\u9000\u51FA\u7EC4\u4EF6\u7EC4")
|
|
3757
|
+
};
|
|
3758
|
+
var STRUCTURE_KEYS = ["pin", "before", "after", "groupId", "groupLabel"];
|
|
3759
|
+
function describeStructure(block) {
|
|
3760
|
+
return tr("\u9489\u4F4F=${0}\u3001\u4F4D\u4E8E\u4E4B\u4E0A=${1}\u3001\u4F4D\u4E8E\u4E4B\u4E0B=${2}\u3001\u7EC4\u4EF6\u7EC4=${3}", [
|
|
3761
|
+
formatAttrValue(block.pin),
|
|
3762
|
+
formatAttrValue(block.before),
|
|
3763
|
+
formatAttrValue(block.after),
|
|
3764
|
+
block.groupId ? groupDisplayLabel(block.groupLabel) : tr("\u65E0")
|
|
3765
|
+
]);
|
|
3766
|
+
}
|
|
3767
|
+
function nextGroupLabel(blocks) {
|
|
3768
|
+
const seenGroupIds = /* @__PURE__ */ new Set();
|
|
3769
|
+
let maxNumber = 0;
|
|
3770
|
+
let parsedAny = false;
|
|
3771
|
+
blocks.forEach((block) => {
|
|
3772
|
+
if (!block.groupId || seenGroupIds.has(block.groupId)) return;
|
|
3773
|
+
seenGroupIds.add(block.groupId);
|
|
3774
|
+
const match = /^组件组(\d+)$/.exec(block.groupLabel?.trim() ?? "");
|
|
3775
|
+
if (match) {
|
|
3776
|
+
parsedAny = true;
|
|
3777
|
+
maxNumber = Math.max(maxNumber, Number.parseInt(match[1], 10));
|
|
3778
|
+
}
|
|
3779
|
+
});
|
|
3780
|
+
const nextNumber = parsedAny ? maxNumber + 1 : seenGroupIds.size + 1;
|
|
3781
|
+
return `\u7EC4\u4EF6\u7EC4${nextNumber}`;
|
|
3782
|
+
}
|
|
3783
|
+
function pickStructureValues(blocks, uid) {
|
|
3784
|
+
const block = blocks.find((b) => b.uid === uid);
|
|
3785
|
+
const current = {};
|
|
3786
|
+
if (!block) return current;
|
|
3787
|
+
for (const key of STRUCTURE_KEYS) {
|
|
3788
|
+
const value = block[key];
|
|
3789
|
+
if (value !== void 0) current[key] = value;
|
|
3790
|
+
}
|
|
3791
|
+
return current;
|
|
3792
|
+
}
|
|
3793
|
+
var getStructureOpsTool = (context) => ({
|
|
3794
|
+
name: "idocs_tpl_structure_ops",
|
|
3795
|
+
description: tr("[idocs\u6A21\u677F\u8BBE\u8BA1\u5668-\u753B\u5E03] \u8C03\u6574\u5355\u4E2A\u5757\u7684\u7ED3\u6784\u5C5E\u6027\uFF08\u7F6E\u9876/\u7F6E\u5E95\u9489\u4F4F\u3001\u5FC5\u987B\u4F4D\u4E8E\u4E4B\u4E0A/\u4E4B\u4E0B\u7684\u987A\u5E8F\u7EA6\u675F\u3001\u52A0\u5165/\u9000\u51FA\u7EC4\u4EF6\u7EC4\uFF09\u3002") + tr(
|
|
3796
|
+
'uid \u7F3A\u7701\u4E3A\u5F53\u524D\u9009\u4E2D\u5757\uFF1Bop=pin \u65F6 value \u4F20 "top"/"bottom"/null\uFF08\u53D6\u6D88\u9489\u4F4F\uFF09\uFF1Bop=order \u65F6 value \u4F20 { "before": ["\u5757uid"], "after": ["\u5757uid"] }\uFF08\u7A7A\u6570\u7EC4\u5373\u6E05\u9664\u8BE5\u65B9\u5411\u7EA6\u675F\uFF09\uFF1Bop=group \u65F6 value \u4F20 { "groupId": "\u5DF2\u6709\u7EC4ID", "groupLabel": "\u7EC4\u540D" }\uFF08\u90FD\u7F3A\u7701\u5219\u65B0\u5EFA\u7EC4\u4EF6\u7EC4\uFF09\uFF1Bop=ungroup \u65E0\u9700 value\u3002'
|
|
3797
|
+
) + tr("\u8868\u73B0\u7C7B\u5C5E\u6027\uFF08\u6807\u9898/\u6587\u672C/\u5BBD\u9AD8\u7B49\uFF09\u8BF7\u7528 idocs_tpl_block_update\u3002"),
|
|
3798
|
+
inputSchema: {
|
|
3799
|
+
type: "object",
|
|
3800
|
+
properties: {
|
|
3801
|
+
uid: { type: "string", description: tr("\u53EF\u9009\uFF1A\u76EE\u6807\u5757 uid\uFF0C\u7F3A\u7701\u4E3A\u5F53\u524D\u9009\u4E2D\u5757") },
|
|
3802
|
+
op: {
|
|
3803
|
+
type: "string",
|
|
3804
|
+
enum: ["pin", "order", "group", "ungroup"],
|
|
3805
|
+
description: tr(
|
|
3806
|
+
"\u7ED3\u6784\u64CD\u4F5C\uFF1Apin=\u9489\u4F4F/\u53D6\u6D88\u9489\u4F4F\uFF1Border=\u8BBE\u7F6E\u987A\u5E8F\u7EA6\u675F\uFF1Bgroup=\u52A0\u5165\uFF08\u6216\u65B0\u5EFA\uFF09\u7EC4\u4EF6\u7EC4\uFF1Bungroup=\u9000\u51FA\u7EC4\u4EF6\u7EC4"
|
|
3807
|
+
)
|
|
3808
|
+
},
|
|
3809
|
+
value: {
|
|
3810
|
+
description: tr(
|
|
3811
|
+
'\u6309 op \u63D0\u4F9B\uFF1Apin \u2192 "top" / "bottom" / null\uFF1Border \u2192 { before?: string[], after?: string[] }\uFF08\u5757 uid \u6E05\u5355\uFF09\uFF1Bgroup \u2192 { groupId?: string, groupLabel?: string }\uFF1Bungroup \u4E0D\u4F20'
|
|
3812
|
+
)
|
|
3813
|
+
}
|
|
3814
|
+
},
|
|
3815
|
+
required: ["op"]
|
|
3816
|
+
},
|
|
3817
|
+
execute: async (args) => {
|
|
3818
|
+
const state = context.stateRef.current;
|
|
3819
|
+
const { current } = state;
|
|
3820
|
+
const blocks = current.blocks;
|
|
3821
|
+
const found = findBlock(state, args.uid);
|
|
3822
|
+
if (!found.ok) return found.result;
|
|
3823
|
+
const block = found.value;
|
|
3824
|
+
const uid = block.uid;
|
|
3825
|
+
if (args.op !== "ungroup" && isFreeDesignerBlock(block)) {
|
|
3826
|
+
return fail(
|
|
3827
|
+
tr(
|
|
3828
|
+
"\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\uFF08\u5F53\u524D\uFF1A${0}\u3002\u5EFA\u8BAE\uFF1A\u5148\u5173\u95ED\u300C\u53EF\u586B\u5199\u300D\u6216\u5F00\u542F\u300C\u5FC5\u586B\u300D\u540E\u518D\u8BBE\u7F6E\uFF1B\u8868\u73B0\u5C5E\u6027\u53EF\u7528 idocs_tpl_block_update \u8C03\u6574\uFF09",
|
|
3829
|
+
[describeStructure(block)]
|
|
3830
|
+
)
|
|
3831
|
+
);
|
|
3832
|
+
}
|
|
3833
|
+
let next;
|
|
3834
|
+
if (args.op === "pin") {
|
|
3835
|
+
const value = args.value;
|
|
3836
|
+
if (value !== null && value !== "top" && value !== "bottom") {
|
|
3837
|
+
return fail(
|
|
3838
|
+
tr(
|
|
3839
|
+
'op=pin \u7684 value \u53D6\u503C\u8D8A\u754C\uFF08\u5F53\u524D\u503C\uFF1A${0}\uFF1B\u5408\u6CD5\u503C\uFF1A"top" / "bottom" / null\uFF08\u53D6\u6D88\u9489\u4F4F\uFF09\u3002\u5EFA\u8BAE\uFF1A\u4ECE\u5408\u6CD5\u503C\u4E2D\u9009\u4E00\u4E2A\u91CD\u8BD5\uFF09',
|
|
3840
|
+
[formatAttrValue(value)]
|
|
3841
|
+
)
|
|
3842
|
+
);
|
|
3843
|
+
}
|
|
3844
|
+
const pin = value === null ? void 0 : value;
|
|
3845
|
+
next = applyPin(blocks, uid, pin);
|
|
3846
|
+
if (!next) {
|
|
3847
|
+
return fail(
|
|
3848
|
+
tr("\u9489\u4F4F\u64CD\u4F5C\u672A\u751F\u6548\uFF08\u5F53\u524D\uFF1A${0}\uFF1B\u5EFA\u8BAE\uFF1A\u9489\u4F4F\u4E0E\u73B0\u6709\u987A\u5E8F\u7EA6\u675F/\u7EC4\u4EF6\u7EC4\u9489\u4F4F\u51B2\u7A81\u65F6\uFF0C\u5148\u89E3\u9664\u51B2\u7A81\u7EA6\u675F\u518D\u91CD\u8BD5\uFF09", [
|
|
3849
|
+
describeStructure(block)
|
|
3850
|
+
])
|
|
3851
|
+
);
|
|
3852
|
+
}
|
|
3853
|
+
} else if (args.op === "order") {
|
|
3854
|
+
const value = args.value;
|
|
3855
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
3856
|
+
return fail(
|
|
3857
|
+
tr(
|
|
3858
|
+
'op=order \u7684 value \u5F62\u6001\u9519\u8BEF\uFF08\u5F53\u524D\u503C\uFF1A${0}\uFF1B\u5408\u6CD5\u503C\uFF1A{ "before": ["\u5757uid"], "after": ["\u5757uid"] }\uFF0C\u7A7A\u6570\u7EC4\u5373\u6E05\u9664\u8BE5\u65B9\u5411\u7EA6\u675F\uFF09',
|
|
3859
|
+
[formatAttrValue(value)]
|
|
3860
|
+
)
|
|
3861
|
+
);
|
|
3862
|
+
}
|
|
3863
|
+
const { before: rawBefore, after: rawAfter } = value;
|
|
3864
|
+
const isUidList = (item) => Array.isArray(item) && item.every((ref) => typeof ref === "string");
|
|
3865
|
+
if (rawBefore !== void 0 && !isUidList(rawBefore)) {
|
|
3866
|
+
return fail(
|
|
3867
|
+
tr(
|
|
3868
|
+
"op=order \u7684 before/after \u5FC5\u987B\u662F\u5757 uid \u5B57\u7B26\u4E32\u6570\u7EC4\uFF08\u5F53\u524D\u503C\uFF1A${0}\u3002\u5EFA\u8BAE\uFF1A\u5148\u8C03 get_status \u83B7\u53D6\u5757\u6E05\u5355\u53D6\u771F\u5B9E uid\uFF09",
|
|
3869
|
+
[formatAttrValue(value)]
|
|
3870
|
+
)
|
|
3871
|
+
);
|
|
3872
|
+
}
|
|
3873
|
+
if (rawAfter !== void 0 && !isUidList(rawAfter)) {
|
|
3874
|
+
return fail(
|
|
3875
|
+
tr(
|
|
3876
|
+
"op=order \u7684 before/after \u5FC5\u987B\u662F\u5757 uid \u5B57\u7B26\u4E32\u6570\u7EC4\uFF08\u5F53\u524D\u503C\uFF1A${0}\u3002\u5EFA\u8BAE\uFF1A\u5148\u8C03 get_status \u83B7\u53D6\u5757\u6E05\u5355\u53D6\u771F\u5B9E uid\uFF09",
|
|
3877
|
+
[formatAttrValue(value)]
|
|
3878
|
+
)
|
|
3879
|
+
);
|
|
3880
|
+
}
|
|
3881
|
+
if (rawBefore === void 0 && rawAfter === void 0) {
|
|
3882
|
+
return fail(tr("op=order \u9700\u8981 value.before \u6216 value.after \u81F3\u5C11\u4F20\u4E00\u4E2A\uFF08\u4F20\u7A7A\u6570\u7EC4\u5373\u6E05\u9664\u8BE5\u65B9\u5411\u7EA6\u675F\uFF09"));
|
|
3883
|
+
}
|
|
3884
|
+
const beforeList = rawBefore;
|
|
3885
|
+
const afterList = rawAfter;
|
|
3886
|
+
const before = beforeList?.length ? beforeList : void 0;
|
|
3887
|
+
const after = afterList?.length ? afterList : void 0;
|
|
3888
|
+
next = setOrderConstraints(blocks, uid, { before, after });
|
|
3889
|
+
if (!next) {
|
|
3890
|
+
const patched = blocks.map((b) => b.uid === uid ? { ...b, before, after } : b);
|
|
3891
|
+
const issue = validateBlockStructure(patched)[0];
|
|
3892
|
+
return fail(
|
|
3893
|
+
issue ? tr("\u987A\u5E8F\u7EA6\u675F\u672A\u751F\u6548\uFF1A${0}\uFF08\u5F53\u524D\uFF1A${1}\u3002\u5EFA\u8BAE\uFF1A\u53BB\u6389\u51B2\u7A81\u7EA6\u675F\u9879\u540E\u91CD\u8BD5\uFF09", [
|
|
3894
|
+
issue.message,
|
|
3895
|
+
describeStructure(block)
|
|
3896
|
+
]) : tr("\u987A\u5E8F\u7EA6\u675F\u672A\u751F\u6548\uFF08\u5F53\u524D\uFF1A${0}\uFF1B\u5EFA\u8BAE\uFF1A\u7EA6\u675F\u4E0E\u9489\u4F4F\u533A\u6BB5\u51B2\u7A81\uFF0C\u5148\u8C03\u6574\u9489\u4F4F\u6216\u51CF\u5C11\u7EA6\u675F\u9879\u540E\u91CD\u8BD5\uFF09", [
|
|
3897
|
+
describeStructure(block)
|
|
3898
|
+
])
|
|
3899
|
+
);
|
|
3900
|
+
}
|
|
3901
|
+
} else if (args.op === "group") {
|
|
3902
|
+
const value = args.value;
|
|
3903
|
+
if (value !== void 0 && (typeof value !== "object" || value === null || Array.isArray(value))) {
|
|
3904
|
+
return fail(
|
|
3905
|
+
tr(
|
|
3906
|
+
'op=group \u7684 value \u5F62\u6001\u9519\u8BEF\uFF08\u5F53\u524D\u503C\uFF1A${0}\uFF1B\u5408\u6CD5\u503C\uFF1A{ "groupId": "\u5DF2\u6709\u7EC4ID", "groupLabel": "\u7EC4\u540D" }\uFF0C\u90FD\u7F3A\u7701\u5219\u65B0\u5EFA\u7EC4\u4EF6\u7EC4\uFF09',
|
|
3907
|
+
[formatAttrValue(value)]
|
|
3908
|
+
)
|
|
3909
|
+
);
|
|
3910
|
+
}
|
|
3911
|
+
const { groupId: rawGroupId, groupLabel: rawGroupLabel } = value ?? {};
|
|
3912
|
+
if (rawGroupId !== void 0 && typeof rawGroupId !== "string") {
|
|
3913
|
+
return fail(tr("op=group \u7684 groupId/groupLabel \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\uFF08\u5F53\u524D\u503C\uFF1A${0}\uFF09", [formatAttrValue(value)]));
|
|
3914
|
+
}
|
|
3915
|
+
if (rawGroupLabel !== void 0 && typeof rawGroupLabel !== "string") {
|
|
3916
|
+
return fail(tr("op=group \u7684 groupId/groupLabel \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\uFF08\u5F53\u524D\u503C\uFF1A${0}\uFF09", [formatAttrValue(value)]));
|
|
3917
|
+
}
|
|
3918
|
+
const groupIdArg = rawGroupId;
|
|
3919
|
+
const groupLabelArg = rawGroupLabel;
|
|
3920
|
+
const existing = groupIdArg ? blocks.find((b) => b.groupId === groupIdArg) : void 0;
|
|
3921
|
+
const groupId = groupIdArg || `grp-${genId()}`;
|
|
3922
|
+
const groupLabel = existing ? existing.groupLabel ?? "" : groupLabelArg?.trim() || nextGroupLabel(blocks);
|
|
3923
|
+
next = joinGroup(blocks, uid, groupId, groupLabel);
|
|
3924
|
+
if (!next) {
|
|
3925
|
+
return fail(
|
|
3926
|
+
tr(
|
|
3927
|
+
"\u52A0\u5165\u7EC4\u4EF6\u7EC4\u672A\u751F\u6548\uFF08\u5F53\u524D\uFF1A${0}\uFF1B\u76EE\u6807\u7EC4\uFF1A${1}\u3002\u5EFA\u8BAE\uFF1A\u5148\u8C03 get_status \u786E\u8BA4\u76EE\u6807\u7EC4\u5B58\u5728\uFF1B\u76EE\u6807\u7EC4\u9489\u4F4F\u72B6\u6001\u4E0E\u672C\u5757\u51B2\u7A81\u65F6\u5148\u5BF9\u9F50\u9489\u4F4F\uFF1B\u6216\u4E0D\u4F20 groupId \u65B0\u5EFA\u7EC4\u4EF6\u7EC4\uFF09",
|
|
3928
|
+
[
|
|
3929
|
+
describeStructure(block),
|
|
3930
|
+
groupIdArg ? groupDisplayLabel(existing?.groupLabel ?? groupLabelArg) : tr("\uFF08\u65B0\u5EFA\uFF09")
|
|
3931
|
+
]
|
|
3932
|
+
)
|
|
3933
|
+
);
|
|
3934
|
+
}
|
|
3935
|
+
} else if (args.op === "ungroup") {
|
|
3936
|
+
next = leaveGroup(blocks, uid);
|
|
3937
|
+
if (!next) {
|
|
3938
|
+
return fail(
|
|
3939
|
+
tr("\u9000\u51FA\u7EC4\u4EF6\u7EC4\u672A\u751F\u6548\uFF08\u5F53\u524D\uFF1A${0}\uFF1B\u5EFA\u8BAE\uFF1A\u8BE5\u5757\u4E0D\u5728\u4EFB\u4F55\u7EC4\u4EF6\u7EC4\u4E2D\u65F6\u65E0\u9700\u9000\u51FA\uFF1B\u9000\u7EC4\u4F1A\u62C6\u6563\u7EC4\u65F6\u8BF7\u6574\u7EC4\u4E00\u8D77\u8C03\u6574\uFF09", [
|
|
3940
|
+
describeStructure(block)
|
|
3941
|
+
])
|
|
3942
|
+
);
|
|
3943
|
+
}
|
|
3944
|
+
} else {
|
|
3945
|
+
return fail(tr("op \u53D6\u503C\u8D8A\u754C\uFF08\u5F53\u524D\u503C\uFF1A${0}\uFF1B\u5408\u6CD5\u503C\uFF1Apin / order / group / ungroup\uFF09", [formatAttrValue(args.op)]));
|
|
3946
|
+
}
|
|
3947
|
+
const issues = validateBlockStructure(next);
|
|
3948
|
+
if (issues.length > 0) {
|
|
3949
|
+
return fail(
|
|
3950
|
+
tr("\u7ED3\u6784\u6821\u9A8C\u672A\u901A\u8FC7\uFF1A${0}\uFF08\u5F53\u524D\uFF1A${1}\u3002\u64CD\u4F5C\u672A\u843D\u72B6\u6001\uFF09", [issues[0].message, describeStructure(block)])
|
|
3951
|
+
);
|
|
3952
|
+
}
|
|
3953
|
+
context.setCurrent({ ...current, blocks: next });
|
|
3954
|
+
return ok(tr("\u5757\u300C${0}\u300D\u7ED3\u6784\u5DF2\u8C03\u6574\uFF08${1}\uFF09", [block.label || block.type, OP_LABELS[args.op]]), {
|
|
3955
|
+
uid,
|
|
3956
|
+
op: args.op,
|
|
3957
|
+
current: pickStructureValues(next, uid)
|
|
3958
|
+
});
|
|
3959
|
+
}
|
|
3960
|
+
});
|
|
3961
|
+
|
|
3962
|
+
// src/editor/features/templatedesigner/usetool/tools/idocsTplBlockRemove.ts
|
|
3963
|
+
var getBlockRemoveTool = (context) => ({
|
|
3964
|
+
name: "idocs_tpl_block_remove",
|
|
3965
|
+
description: tr(
|
|
3966
|
+
'[idocs\u6A21\u677F\u8BBE\u8BA1\u5668-\u753B\u5E03] \u4ECE\u6A21\u677F\u4E2D\u5220\u9664\u4E00\u4E2A\u5757\u3002\u9002\u7528\u573A\u666F\uFF1A\u7528\u6237\u9009\u4E2D\u5757\u540E\u8BF4"\u5220\u6389\u8FD9\u4E2A/\u5220\u9664\u8BE5\u6BB5\u843D/\u79FB\u9664\u8FD9\u5F20\u8868"\u65F6\u3002\u3010\u76EE\u6807\u3011\u7F3A\u7701\u5220\u9664\u5F53\u524D\u9009\u4E2D\u5757\uFF08\u5148\u8C03 get_status \u786E\u8BA4\uFF09\uFF1B\u4E5F\u53EF\u7528 uid \u663E\u5F0F\u6307\u5B9A\u3002\u3010\u6CE8\u610F\u3011\u5220\u9664\u8868\u683C\u5757\u4F1A\u6574\u8868\u79FB\u9664\uFF1B\u82E5\u5176\u5B83\u5757\u7684"\u5FC5\u987B\u4F4D\u4E8E\u4E4B\u4E0A/\u4E4B\u4E0B"\u5F15\u7528\u4E86\u88AB\u5220\u5757\uFF0C\u4F1A\u7559\u4E0B\u60AC\u7A7A\u7EA6\u675F\uFF0C\u5220\u9664\u540E\u8BF7\u8C03 idocs_tpl_validate \u81EA\u68C0\u3002\u5220\u9664\u53EA\u8FDB\u753B\u5E03\u9884\u89C8\uFF0C\u4FDD\u5B58\u7531\u7528\u6237\u624B\u52A8\u89E6\u53D1\u3002'
|
|
3967
|
+
),
|
|
3968
|
+
inputSchema: {
|
|
3969
|
+
type: "object",
|
|
3970
|
+
properties: {
|
|
3971
|
+
uid: { type: "string", description: tr("\u53EF\u9009\uFF1A\u76EE\u6807\u5757 uid\uFF0C\u7F3A\u7701\u4E3A\u5F53\u524D\u9009\u4E2D\u5757") }
|
|
3972
|
+
}
|
|
3973
|
+
},
|
|
3974
|
+
execute: async (args) => {
|
|
3975
|
+
const { current, activeUid } = context.stateRef.current;
|
|
3976
|
+
const uid = args.uid ?? activeUid;
|
|
3977
|
+
if (!uid) {
|
|
3978
|
+
return fail(tr("\u672A\u6307\u5B9A\u76EE\u6807\u5757\uFF0C\u4E14\u753B\u5E03\u5F53\u524D\u6CA1\u6709\u9009\u4E2D\u4EFB\u4F55\u5757\u3002\u8BF7\u5148\u8BA9\u7528\u6237\u9009\u4E2D\u5757\uFF0C\u6216\u7528 uid \u53C2\u6570\u663E\u5F0F\u6307\u5B9A"));
|
|
3979
|
+
}
|
|
3980
|
+
const found = findBlock({ current }, uid);
|
|
3981
|
+
if (!found.ok) return found.result;
|
|
3982
|
+
const block = found.value;
|
|
3983
|
+
context.removeBlock(uid);
|
|
3984
|
+
return ok(tr("\u5757\u300C${0}\u300D\u5DF2\u5220\u9664", [block.label ?? block.type]), { uid, type: block.type });
|
|
3985
|
+
}
|
|
3986
|
+
});
|
|
3987
|
+
|
|
3988
|
+
// src/editor/features/templatedesigner/usetool/tools/idocsTplValidate.ts
|
|
3989
|
+
var getValidateTool2 = (context) => ({
|
|
3990
|
+
name: "idocs_tpl_validate",
|
|
3991
|
+
description: tr(
|
|
3992
|
+
'[idocs\u6A21\u677F\u8BBE\u8BA1\u5668-\u753B\u5E03] \u6821\u9A8C\u5F53\u524D\u6A21\u677F\u80FD\u5426\u901A\u8FC7\u7F16\u8BD1\uFF08\u7ED3\u6784\u95E8\u63A7\u3001\u8868\u683C\u884C\u5BBD\u3001\u516C\u5F0F\u7B49\uFF09\u3002\u9002\u7528\u573A\u666F\uFF1A\u7528\u6237\u95EE"\u73B0\u5728\u7684\u6A21\u677F\u6709\u6CA1\u6709\u95EE\u9898"\u65F6\uFF0C\u6216 AI \u5B8C\u6210\u4E00\u6279\u8C03\u6574\u540E\u81EA\u68C0\u3002'
|
|
3993
|
+
),
|
|
3994
|
+
execute: async () => {
|
|
3995
|
+
const { current } = context.stateRef.current;
|
|
3996
|
+
const build = buildDefinition(current);
|
|
3997
|
+
const issues = build.ok ? [] : build.issues;
|
|
3998
|
+
return ok(
|
|
3999
|
+
build.ok ? tr("\u6821\u9A8C\u901A\u8FC7\uFF0C\u6A21\u677F\u53EF\u4EE5\u4FDD\u5B58") : tr("\u6821\u9A8C\u672A\u901A\u8FC7\uFF0C\u5171 ${0} \u4E2A\u95EE\u9898\uFF0C\u660E\u7EC6\u89C1\u8FD4\u56DE\u6570\u636E", [issues.length]),
|
|
4000
|
+
{ ok: build.ok, issues }
|
|
4001
|
+
);
|
|
4002
|
+
}
|
|
4003
|
+
});
|
|
4004
|
+
|
|
4005
|
+
// src/editor/features/templatedesigner/usetool/index.tsx
|
|
4006
|
+
function createDesignerCopilotTools(context) {
|
|
4007
|
+
return [
|
|
4008
|
+
getStatusTool2(context),
|
|
4009
|
+
getTemplateTool(context),
|
|
4010
|
+
getBlockSchemaTool(context),
|
|
4011
|
+
getSetTemplateTool(context),
|
|
4012
|
+
getTableGenerateTool(context),
|
|
4013
|
+
getCellUpdateTool(context),
|
|
4014
|
+
getTableUpdateTool(context),
|
|
4015
|
+
getBlockUpdateTool(context),
|
|
4016
|
+
getStructureOpsTool(context),
|
|
4017
|
+
getBlockRemoveTool(context),
|
|
4018
|
+
getValidateTool2(context)
|
|
4019
|
+
];
|
|
4020
|
+
}
|
|
4021
|
+
|
|
4022
|
+
export { buildNodeAttrSummary, createDesignerCopilotTools, createEditorCopilotTools, getEditorNodeZhLabel, resolveActiveCellSnapshot, resolveSelectedBlockSummary };
|
|
4023
|
+
//# sourceMappingURL=chunk-EEUFVA37.mjs.map
|
|
4024
|
+
//# sourceMappingURL=chunk-EEUFVA37.mjs.map
|