@flowgram.ai/type-editor 0.1.0-alpha.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5021 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __decorateClass = (decorators, target, key, kind) => {
4
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
+ if (decorator = decorators[i])
7
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
+ if (kind && result) __defProp(target, key, result);
9
+ return result;
10
+ };
11
+
12
+ // src/types/type-editor.ts
13
+ var TypeEditorColumnType = /* @__PURE__ */ ((TypeEditorColumnType2) => {
14
+ TypeEditorColumnType2["Key"] = "key";
15
+ TypeEditorColumnType2["Type"] = "type";
16
+ TypeEditorColumnType2["Required"] = "required";
17
+ TypeEditorColumnType2["Description"] = "description";
18
+ TypeEditorColumnType2["Default"] = "default";
19
+ TypeEditorColumnType2["Operate"] = "operate";
20
+ TypeEditorColumnType2["Value"] = "value";
21
+ TypeEditorColumnType2["Private"] = "private";
22
+ return TypeEditorColumnType2;
23
+ })(TypeEditorColumnType || {});
24
+
25
+ // src/contexts/index.tsx
26
+ import React8, { createContext, useContext, useEffect as useEffect2, useMemo } from "react";
27
+ import { Container } from "inversify";
28
+
29
+ // src/utils/registry-adapter.tsx
30
+ import React from "react";
31
+ import { Space, Typography } from "@douyinfe/semi-ui";
32
+ var registryFormatter = (registry, manager) => {
33
+ const res = {
34
+ ...registry
35
+ };
36
+ const apiMap = {
37
+ getItemTypes: "getSupportedItemTypes",
38
+ getIJsonSchemaByStringValue: "getTypeSchemaByStringValue",
39
+ getStringValue: "getStringValueByTypeSchema",
40
+ getIJsonSchemaProperties: "getTypeSchemaProperties",
41
+ getIJsonSchemaPropertiesParent: "getPropertiesParent",
42
+ getChildrenExtraJsonPaths: "getJsonPaths",
43
+ getDefaultIJsonSchema: "getDefaultSchema"
44
+ };
45
+ Object.keys(apiMap).forEach((api) => {
46
+ if (res[api]) {
47
+ res[apiMap[api]] = res[api];
48
+ }
49
+ if (res[apiMap[api]]) {
50
+ res[api] = res[apiMap[api]];
51
+ }
52
+ });
53
+ return {
54
+ ...res,
55
+ getDisplayLabel: (type) => /* @__PURE__ */ React.createElement(Space, { style: { width: "100%" } }, manager?.getDisplayIcon(type), /* @__PURE__ */ React.createElement("div", { style: { flex: 1, width: 0, display: "flex" } }, /* @__PURE__ */ React.createElement(Typography.Text, { size: "small", ellipsis: { showTooltip: true } }, manager.getComplexText(type)))),
56
+ getIJsonSchemaDeepField: (type) => manager.getTypeSchemaDeepChildField(type)
57
+ };
58
+ };
59
+ var getTypeDefinitionAdapter = (manager) => {
60
+ const typeDefinitionManager = {
61
+ getDefinitionByIJsonSchema: (typeSchema) => typeSchema ? manager.getTypeBySchema(typeSchema) : void 0,
62
+ getAllTypeDefinitions: () => manager.getTypeRegistriesWithParentType(),
63
+ getDefinitionByType: (type) => manager.getTypeByName(type),
64
+ getUndefinedIJsonSchema: () => manager.getTypeByName("unknown").getDefaultSchema()
65
+ };
66
+ return {
67
+ typeDefinitionManager,
68
+ utils: {
69
+ getComposedLabel: (type) => manager.getComplexText(type)
70
+ }
71
+ };
72
+ };
73
+
74
+ // src/type-registry/string.tsx
75
+ import React2 from "react";
76
+ import { Input } from "@douyinfe/semi-ui";
77
+ var stringRegistryCreator = () => ({
78
+ type: "string",
79
+ getInputNode: ({ value, onChange, onSubmit }) => /* @__PURE__ */ React2.createElement(
80
+ Input,
81
+ {
82
+ style: {
83
+ width: "100%",
84
+ height: "100%",
85
+ display: "flex",
86
+ alignItems: "center"
87
+ },
88
+ autoFocus: true,
89
+ value,
90
+ onChange,
91
+ onBlur: onSubmit
92
+ }
93
+ )
94
+ });
95
+
96
+ // src/type-registry/object.tsx
97
+ import React3 from "react";
98
+ import { Typography as Typography2 } from "@douyinfe/semi-ui";
99
+ var objectRegistryCreator = () => ({
100
+ type: "object",
101
+ getInputNode: () => /* @__PURE__ */ React3.createElement(
102
+ "div",
103
+ {
104
+ style: {
105
+ width: "100%",
106
+ height: "100%",
107
+ display: "flex",
108
+ alignItems: "center",
109
+ padding: "0 8px"
110
+ }
111
+ },
112
+ /* @__PURE__ */ React3.createElement(Typography2.Text, null, "Not Supported")
113
+ )
114
+ });
115
+
116
+ // src/type-registry/number.tsx
117
+ import React4 from "react";
118
+ import { InputNumber } from "@douyinfe/semi-ui";
119
+ var numberRegistryCreator = () => ({
120
+ type: "number",
121
+ getInputNode({ value, onChange, onSubmit }) {
122
+ return /* @__PURE__ */ React4.createElement(
123
+ InputNumber,
124
+ {
125
+ autoFocus: true,
126
+ value,
127
+ style: { width: "100%", height: "100%" },
128
+ onChange,
129
+ onBlur: onSubmit
130
+ }
131
+ );
132
+ }
133
+ });
134
+
135
+ // src/type-registry/integer.tsx
136
+ import React5 from "react";
137
+ import { InputNumber as InputNumber2 } from "@douyinfe/semi-ui";
138
+ var integerRegistryCreator = () => ({
139
+ type: "integer",
140
+ getInputNode({ value, onChange, onSubmit }) {
141
+ return /* @__PURE__ */ React5.createElement(
142
+ InputNumber2,
143
+ {
144
+ autoFocus: true,
145
+ value,
146
+ style: { width: "100%", height: "100%" },
147
+ onChange,
148
+ onBlur: onSubmit
149
+ }
150
+ );
151
+ }
152
+ });
153
+
154
+ // src/type-registry/boolean.tsx
155
+ import React6 from "react";
156
+ import { Select } from "@douyinfe/semi-ui";
157
+ var booleanRegistryCreator = () => ({
158
+ type: "boolean",
159
+ getInputNode({ value, onChange, onSubmit }) {
160
+ return /* @__PURE__ */ React6.createElement(
161
+ Select,
162
+ {
163
+ style: {
164
+ width: "100%",
165
+ height: "100%",
166
+ display: "flex",
167
+ alignItems: "center",
168
+ background: "var(--semi-color-bg-0)"
169
+ },
170
+ optionList: [
171
+ {
172
+ value: 1,
173
+ label: "True"
174
+ },
175
+ {
176
+ value: 0,
177
+ label: "False"
178
+ }
179
+ ],
180
+ className: "flow-type-select",
181
+ value: Number(value),
182
+ onSelect: (v) => {
183
+ onChange(Boolean(v));
184
+ onSubmit();
185
+ }
186
+ }
187
+ );
188
+ }
189
+ });
190
+
191
+ // src/type-registry/array.tsx
192
+ import React7 from "react";
193
+ import { Space as Space2, Typography as Typography3 } from "@douyinfe/semi-ui";
194
+ var arrayRegistryCreator = ({ typeManager }) => ({
195
+ type: "array",
196
+ getDisplayLabel: (type) => {
197
+ const config = typeManager.getTypeBySchema(type);
198
+ return /* @__PURE__ */ React7.createElement(Space2, { style: { width: "100%" } }, config?.getDisplayIcon(type) || config?.icon, /* @__PURE__ */ React7.createElement("div", { style: { flex: 1, width: 0, display: "flex" } }, /* @__PURE__ */ React7.createElement(Typography3.Text, { size: "small", ellipsis: { showTooltip: true } }, typeManager.getComplexText(type))));
199
+ }
200
+ });
201
+
202
+ // src/type-registry/index.ts
203
+ var defaultTypeRegistryCreators = [
204
+ stringRegistryCreator,
205
+ numberRegistryCreator,
206
+ integerRegistryCreator,
207
+ booleanRegistryCreator,
208
+ objectRegistryCreator,
209
+ arrayRegistryCreator
210
+ ];
211
+
212
+ // src/services/type-registry-manager.ts
213
+ import { JsonSchemaTypeManager } from "@flowgram.ai/json-schema";
214
+ var TypeEditorRegistryManager = class extends JsonSchemaTypeManager {
215
+ };
216
+
217
+ // src/services/index.tsx
218
+ import "reflect-metadata";
219
+
220
+ // src/services/type-editor-service.ts
221
+ import { inject, injectable as injectable2 } from "inversify";
222
+ import { Emitter as Emitter3 } from "@flowgram.ai/utils";
223
+
224
+ // src/utils/monitor-data/monitor-data.ts
225
+ import { Emitter } from "@flowgram.ai/utils";
226
+ var MonitorData = class {
227
+ constructor(initialValue) {
228
+ this.onDataChangeEmitter = new Emitter();
229
+ this.onDataChange = this.onDataChangeEmitter.event;
230
+ if (initialValue !== void 0) {
231
+ this._data = initialValue;
232
+ }
233
+ }
234
+ get data() {
235
+ return this._data;
236
+ }
237
+ update(data) {
238
+ const prev = this._data;
239
+ this._data = data;
240
+ this.onDataChangeEmitter.fire({
241
+ prev,
242
+ next: data
243
+ });
244
+ }
245
+ };
246
+
247
+ // src/utils/monitor-data/use-monitor-data.ts
248
+ import { useEffect, useState } from "react";
249
+ var useMonitorData = (monitorData) => {
250
+ const [data, setData] = useState(monitorData?.data);
251
+ useEffect(() => {
252
+ const dispose = monitorData?.onDataChange(({ prev, next }) => {
253
+ setData(next);
254
+ });
255
+ return () => {
256
+ dispose?.dispose();
257
+ };
258
+ }, [monitorData]);
259
+ return {
260
+ data
261
+ };
262
+ };
263
+
264
+ // src/components/type-editor/common.ts
265
+ var SUFFIX = "___empty___";
266
+ var HEADER_HIGHT = 36;
267
+ var CELL_HIGHT = 36 + 1;
268
+ var CELL_PADDING = 8;
269
+ var INDENT_WIDTH = 16;
270
+ var TAB_BRA_HIGHT = 0;
271
+ var COMPONENT_ID_PREFIX = "type-editor-component-id";
272
+ var ROOT_FIELD_ID = "root";
273
+
274
+ // src/services/clipboard-service.ts
275
+ import { injectable } from "inversify";
276
+ import { Emitter as Emitter2 } from "@flowgram.ai/utils";
277
+ var ClipboardService = class {
278
+ constructor() {
279
+ this.onClipboardChangedEmitter = new Emitter2();
280
+ this.onClipboardChanged = this.onClipboardChangedEmitter.event;
281
+ }
282
+ /**
283
+ * 读取浏览器数据
284
+ */
285
+ get data() {
286
+ return navigator.clipboard.readText();
287
+ }
288
+ async saveReadData() {
289
+ try {
290
+ const data = await this.data;
291
+ return {
292
+ data
293
+ };
294
+ } catch (error) {
295
+ return {
296
+ error
297
+ };
298
+ }
299
+ }
300
+ /**
301
+ * 设置剪切板数据
302
+ */
303
+ async writeData(newStrData) {
304
+ const oldSaveData = await this.saveReadData();
305
+ if (oldSaveData.error || oldSaveData.data !== newStrData) {
306
+ if (navigator.clipboard && window.isSecureContext) {
307
+ await navigator.clipboard.writeText(newStrData);
308
+ const event = document.createEvent("Event");
309
+ event.initEvent("onchange");
310
+ event.value = newStrData;
311
+ navigator.clipboard.dispatchEvent(event);
312
+ } else {
313
+ const textarea = document.createElement("textarea");
314
+ textarea.value = newStrData;
315
+ textarea.style.display = "absolute";
316
+ textarea.style.left = "-99999999px";
317
+ document.body.prepend(textarea);
318
+ textarea.select();
319
+ try {
320
+ document.execCommand("copy");
321
+ } catch (err) {
322
+ console.log(err);
323
+ } finally {
324
+ textarea.remove();
325
+ }
326
+ }
327
+ this.onClipboardChangedEmitter.fire(newStrData);
328
+ }
329
+ }
330
+ /**
331
+ * 获取剪切板数据
332
+ */
333
+ async readData() {
334
+ const res = await this.saveReadData();
335
+ if (res.error) {
336
+ throw Error(res.error);
337
+ }
338
+ return res.data || "";
339
+ }
340
+ clearData() {
341
+ this.writeData("");
342
+ }
343
+ };
344
+ ClipboardService = __decorateClass([
345
+ injectable()
346
+ ], ClipboardService);
347
+
348
+ // src/services/type-editor-service.ts
349
+ var TypeEditorService = class {
350
+ constructor() {
351
+ this._configs = /* @__PURE__ */ new Map();
352
+ this._activePos = { x: -1, y: -1 };
353
+ // -1 为 header
354
+ this._dropInfo = {
355
+ rowDataId: "",
356
+ indent: -1,
357
+ index: -2
358
+ };
359
+ this.errorMsgs = new MonitorData([]);
360
+ this.dataSource = [];
361
+ this.dataSourceMap = {};
362
+ this.dataSourceTouchedMap = {};
363
+ this.blink = new MonitorData(false);
364
+ this.columnViewConfig = [];
365
+ this.onActivePosChange = new Emitter3();
366
+ this.onDropInfoChange = new Emitter3();
367
+ this.setErrorMsg = (pos, msg) => {
368
+ const newMsgs = [...this.errorMsgs.data];
369
+ const item = newMsgs.find((v) => v.pos.x === pos.x && v.pos.y === pos.y);
370
+ if (item) {
371
+ item.msg = msg;
372
+ } else {
373
+ newMsgs.push({ pos, msg });
374
+ }
375
+ this.errorMsgs.update(newMsgs);
376
+ };
377
+ this.refreshErrorMsgAfterRemove = (index) => {
378
+ const newMsgs = this.errorMsgs.data.filter((msg) => msg.pos.y !== index);
379
+ newMsgs.forEach((msg) => {
380
+ if (msg.pos.y > index) {
381
+ msg.pos.y = msg.pos.y - 1;
382
+ }
383
+ });
384
+ this.errorMsgs.update(newMsgs);
385
+ };
386
+ this.checkActivePosError = () => {
387
+ const pos = this.activePos;
388
+ return !!this.errorMsgs.data.find((v) => v.pos.x === pos.x && v.pos.y === pos.y && v.msg);
389
+ };
390
+ this.setEditValue = (val) => {
391
+ this.editValue = val;
392
+ };
393
+ this.getConfigs = () => Array.from(this._configs.values());
394
+ this.checkRowDataColumnCanEdit = (rowData, column) => !(rowData.disableEditColumn || []).map((v) => v.column).includes(column) && this.getConfigByType(column)?.focusable !== false;
395
+ /**
396
+ * 获取下一个可编辑的
397
+ */
398
+ this.getNextEditItem = (pos) => {
399
+ const newPos = { ...pos };
400
+ if (newPos.x === this.columnViewConfig.length - 1) {
401
+ newPos.y = (1 + newPos.y) % this.dataSource.length;
402
+ newPos.x = 0;
403
+ } else {
404
+ newPos.x = newPos.x + 1;
405
+ }
406
+ if (this.checkRowDataColumnCanEdit(
407
+ this.dataSource[newPos.y],
408
+ this.columnViewConfig[newPos.x].type
409
+ )) {
410
+ return newPos;
411
+ }
412
+ return this.getNextEditItem(newPos);
413
+ };
414
+ }
415
+ registerConfigs(config) {
416
+ const configs = Array.isArray(config) ? config : [config];
417
+ configs.map((c) => {
418
+ this._configs.set(c.type, c);
419
+ });
420
+ }
421
+ addConfigProps(type, config) {
422
+ const configByType = this.getConfigByType(type);
423
+ if (!configByType) {
424
+ return;
425
+ }
426
+ const newConfig = {
427
+ ...configByType,
428
+ ...config
429
+ };
430
+ this._configs.set(type, newConfig);
431
+ }
432
+ getConfigByType(type) {
433
+ return this._configs.get(type);
434
+ }
435
+ triggerShortcutEvent(event) {
436
+ const column = this.columnViewConfig[this.activePos.x];
437
+ const columnConfig = this.getConfigByType(column?.type);
438
+ if (!columnConfig) {
439
+ return;
440
+ }
441
+ const ctx = {
442
+ value: this.editValue,
443
+ rowData: this.dataSource[this.activePos.y],
444
+ onRemoveEmptyLine: this.onRemoveEmptyLine,
445
+ onChange: this.onChange,
446
+ typeEditor: this,
447
+ typeDefinitionService: this.typeDefinition
448
+ };
449
+ switch (event) {
450
+ case "enter": {
451
+ columnConfig.shortcuts?.onEnter?.(ctx);
452
+ return;
453
+ }
454
+ case "tab": {
455
+ columnConfig.shortcuts?.onTab?.(ctx);
456
+ return;
457
+ }
458
+ case "down": {
459
+ columnConfig.shortcuts?.onDown?.(ctx);
460
+ return;
461
+ }
462
+ case "up": {
463
+ columnConfig.shortcuts?.onUp?.(ctx);
464
+ return;
465
+ }
466
+ case "left": {
467
+ columnConfig.shortcuts?.onLeft?.(ctx);
468
+ return;
469
+ }
470
+ case "right": {
471
+ columnConfig.shortcuts?.onRight?.(ctx);
472
+ return;
473
+ }
474
+ case "copy": {
475
+ columnConfig.shortcuts?.onCopy?.(ctx);
476
+ return;
477
+ }
478
+ case "paste": {
479
+ columnConfig.shortcuts?.onPaste?.(ctx);
480
+ return;
481
+ }
482
+ case "delete": {
483
+ columnConfig.shortcuts?.onDelete?.(ctx);
484
+ return;
485
+ }
486
+ default: {
487
+ return;
488
+ }
489
+ }
490
+ }
491
+ get activePos() {
492
+ return this._activePos;
493
+ }
494
+ /**
495
+ * 获取可编辑的下一列/上一列
496
+ */
497
+ getCanEditColumn(originPos, direction) {
498
+ const newX = (originPos.x + this.columnViewConfig.length + (direction === "next" ? 1 : -1)) % this.columnViewConfig.length;
499
+ const newPos = {
500
+ y: originPos.y,
501
+ x: newX
502
+ };
503
+ if (this.checkRowDataColumnCanEdit(
504
+ this.dataSource[newPos.y],
505
+ this.columnViewConfig[newPos.x].type
506
+ )) {
507
+ return newPos;
508
+ }
509
+ return this.getCanEditColumn(newPos, direction);
510
+ }
511
+ /**
512
+ * 获取可编辑的下一行/上一行
513
+ */
514
+ getCanEditLine(originPos, direction) {
515
+ const newY = (originPos.y + this.dataSource.length + (direction === "next" ? 1 : -1)) % this.dataSource.length;
516
+ const newPos = {
517
+ y: newY,
518
+ x: originPos.x
519
+ };
520
+ if (this.checkRowDataColumnCanEdit(
521
+ this.dataSource[newPos.y],
522
+ this.columnViewConfig[newPos.x].type
523
+ )) {
524
+ return newPos;
525
+ }
526
+ return this.getCanEditLine(newPos, direction);
527
+ }
528
+ moveActivePosToNextLine() {
529
+ const newPos = this.getCanEditLine(this.activePos, "next");
530
+ this.setActivePos(newPos);
531
+ }
532
+ moveActivePosToNextLineWithAddLine(rowData) {
533
+ const newPos = { ...this.activePos };
534
+ if (!rowData.parentId) {
535
+ return;
536
+ }
537
+ const parentData = this.dataSourceMap[rowData.parentId] || this.dataSourceMap[ROOT_FIELD_ID];
538
+ const id = this.dataSourceMap[rowData.parentId] ? rowData.parentId : ROOT_FIELD_ID;
539
+ const addChild = parentData.index + parentData.deepChildrenCount === rowData.index;
540
+ if (addChild) {
541
+ if (this.onGlobalAdd) {
542
+ this.onGlobalAdd(id);
543
+ newPos.y = newPos.y + 1;
544
+ } else {
545
+ newPos.y = -1;
546
+ }
547
+ } else {
548
+ newPos.y = newPos.y + 1;
549
+ }
550
+ this.setActivePos(newPos);
551
+ }
552
+ moveActivePosToLastLine() {
553
+ const newPos = this.getCanEditLine(this.activePos, "last");
554
+ this.setActivePos(newPos);
555
+ }
556
+ moveActivePosToLastColumn() {
557
+ const newPos = this.getCanEditColumn(this.activePos, "last");
558
+ this.setActivePos(newPos);
559
+ }
560
+ moveActivePosToNextColumn() {
561
+ const newPos = this.getCanEditColumn(this.activePos, "next");
562
+ this.setActivePos(newPos);
563
+ }
564
+ moveActivePosToNextItem() {
565
+ const newPos = this.getNextEditItem(this.activePos);
566
+ this.setActivePos(newPos);
567
+ }
568
+ setActivePos(pos) {
569
+ if (this.checkActivePosError()) {
570
+ return;
571
+ }
572
+ this._activePos = pos;
573
+ this.onActivePosChange.fire(this._activePos);
574
+ }
575
+ clearActivePos() {
576
+ this._activePos = { x: -1, y: -1 };
577
+ this.onActivePosChange.fire(this._activePos);
578
+ }
579
+ setDataSource(newData) {
580
+ this.dataSource = newData;
581
+ }
582
+ getDataSource() {
583
+ return this.dataSource;
584
+ }
585
+ setColumnViewConfig(config) {
586
+ this.columnViewConfig = config;
587
+ }
588
+ get dropInfo() {
589
+ return this._dropInfo;
590
+ }
591
+ setDropInfo(dropInfo) {
592
+ if (dropInfo.indent === this.dropInfo.indent && this.dropInfo.rowDataId === dropInfo.rowDataId && this.dropInfo.index === dropInfo.index) {
593
+ return;
594
+ }
595
+ this._dropInfo = dropInfo;
596
+ this.onDropInfoChange.fire(dropInfo);
597
+ }
598
+ clearDropInfo() {
599
+ this.setDropInfo({ rowDataId: "", indent: -1, index: -2 });
600
+ }
601
+ };
602
+ __decorateClass([
603
+ inject(ClipboardService)
604
+ ], TypeEditorService.prototype, "clipboard", 2);
605
+ __decorateClass([
606
+ inject(TypeEditorRegistryManager)
607
+ ], TypeEditorService.prototype, "typeDefinition", 2);
608
+ TypeEditorService = __decorateClass([
609
+ injectable2()
610
+ ], TypeEditorService);
611
+
612
+ // src/services/shortcut-service.ts
613
+ import { injectable as injectable3 } from "inversify";
614
+ var ShortcutsService = class {
615
+ };
616
+ ShortcutsService = __decorateClass([
617
+ injectable3()
618
+ ], ShortcutsService);
619
+
620
+ // src/services/type-operation-service.ts
621
+ import { isEqual } from "lodash";
622
+ import { injectable as injectable4 } from "inversify";
623
+ var TypeEditorOperationService = class {
624
+ constructor() {
625
+ this.undoStack = [];
626
+ this.redoStack = [];
627
+ this._id_idx = 0;
628
+ this._storeState = (value) => {
629
+ if (this.redoStack.length > 0) {
630
+ this.redoStack.splice(0);
631
+ }
632
+ this.undoStack.push({
633
+ id: this._getNewId(),
634
+ value: JSON.stringify(value)
635
+ });
636
+ this.refreshUndoRedoStatus();
637
+ };
638
+ this.canUndo = new MonitorData(false);
639
+ this.canRedo = new MonitorData(false);
640
+ this.refreshUndoRedoStatus();
641
+ }
642
+ _getNewId() {
643
+ return `${this._id_idx++}`;
644
+ }
645
+ refreshUndoRedoStatus() {
646
+ this.canRedo.update(this.redoStack.length !== 0);
647
+ this.canUndo.update(this.undoStack.length > 1);
648
+ }
649
+ getCurrentState() {
650
+ const top = this.undoStack[this.undoStack.length - 1];
651
+ if (top) {
652
+ return JSON.parse(top.value);
653
+ }
654
+ return;
655
+ }
656
+ clear() {
657
+ this.undoStack = [];
658
+ this.redoStack = [];
659
+ }
660
+ storeState(value) {
661
+ if (isEqual(this.getCurrentState(), value)) {
662
+ return;
663
+ }
664
+ this._storeState(value);
665
+ }
666
+ async undo() {
667
+ const top = this.undoStack.pop();
668
+ if (top) {
669
+ this.redoStack.push(top);
670
+ }
671
+ this.refreshUndoRedoStatus();
672
+ }
673
+ async redo() {
674
+ const top = this.redoStack.pop();
675
+ if (top) {
676
+ this.undoStack.push(top);
677
+ }
678
+ this.refreshUndoRedoStatus();
679
+ }
680
+ debugger() {
681
+ console.log("getCurrentState - debugger", this.getCurrentState());
682
+ }
683
+ };
684
+ TypeEditorOperationService = __decorateClass([
685
+ injectable4()
686
+ ], TypeEditorOperationService);
687
+
688
+ // src/contexts/index.tsx
689
+ var TypeEditorContext = createContext({});
690
+ var TypeContext = createContext({
691
+ container: new Container()
692
+ });
693
+ function useService(identifier) {
694
+ const container = useContext(TypeContext).container;
695
+ return container.get(identifier);
696
+ }
697
+ var TypeEditorProvider = ({
698
+ children,
699
+ typeRegistryCreators = [],
700
+ onInit
701
+ }) => {
702
+ const container = useMemo(() => {
703
+ const res = new Container();
704
+ res.bind(TypeEditorService).toSelf().inSingletonScope();
705
+ res.bind(TypeEditorOperationService).toSelf().inSingletonScope();
706
+ res.bind(TypeEditorRegistryManager).toSelf().inSingletonScope();
707
+ res.bind(ShortcutsService).toSelf().inSingletonScope();
708
+ res.bind(ClipboardService).toSelf().inSingletonScope();
709
+ return res;
710
+ }, []);
711
+ useEffect2(() => {
712
+ const typeManager = container.get(TypeEditorRegistryManager);
713
+ [...defaultTypeRegistryCreators].forEach((creator) => {
714
+ typeManager.register(
715
+ creator
716
+ );
717
+ });
718
+ }, [container]);
719
+ useEffect2(() => {
720
+ const typeManager = container.get(TypeEditorRegistryManager);
721
+ const adapter = getTypeDefinitionAdapter(typeManager);
722
+ typeRegistryCreators.forEach((creator) => {
723
+ typeManager.register(creator({ typeManager, ...adapter }));
724
+ });
725
+ typeManager.getAllTypeRegistries().forEach((registry) => {
726
+ const res = registryFormatter(registry, typeManager);
727
+ typeManager.register(res);
728
+ });
729
+ typeManager.triggerChanges();
730
+ onInit?.();
731
+ }, [typeRegistryCreators, onInit, container]);
732
+ return /* @__PURE__ */ React8.createElement(TypeContext.Provider, { value: { container } }, children);
733
+ };
734
+ var useTypeDefinitionManager = () => useService(TypeEditorRegistryManager);
735
+
736
+ // src/components/type-editor/columns/value.tsx
737
+ import { useCallback, useEffect as useEffect3, useMemo as useMemo2, useRef, useState as useState2 } from "react";
738
+ import React9 from "react";
739
+ import { Tooltip, Typography as Typography5 } from "@douyinfe/semi-ui";
740
+
741
+ // src/components/type-editor/hooks/disabled.ts
742
+ var useDisabled = (type, rowData) => {
743
+ const disabled = (rowData.disableEditColumn || []).find((r) => r.column === type);
744
+ if (disabled?.reason) {
745
+ return disabled?.reason;
746
+ }
747
+ if (typeof rowData.extra?.editable === "string") {
748
+ return rowData.extra?.editable;
749
+ }
750
+ return rowData.extra?.editable === false ? `${type} is not editable.` : void 0;
751
+ };
752
+
753
+ // src/components/type-editor/columns/style.ts
754
+ import styled, { createGlobalStyle } from "styled-components";
755
+ import { Input as Input2, Typography as Typography4 } from "@douyinfe/semi-ui";
756
+ var KeyViewContainer = styled.div`
757
+ width: 100%;
758
+ display: flex;
759
+ align-items: center;
760
+ height: 20px;
761
+ ${(props) => props.disabled ? "cursor: not-allowed !important;" : ""}
762
+ svg {
763
+ width: 12px;
764
+ height: 12px;
765
+ flex-shrink: 0;
766
+ }
767
+ `;
768
+ var KeyViewContent = styled.div`
769
+ font-size: 12px;
770
+ display: flex;
771
+ align-items: center;
772
+ gap: 4px;
773
+ width: 0;
774
+ flex: 1;
775
+ `;
776
+ var KeyEditorContainer = styled.div`
777
+ height: 100%;
778
+ width: 100%;
779
+ display: flex;
780
+
781
+ svg {
782
+ flex-shrink: 0;
783
+ }
784
+
785
+ .semi-input-wrapper-focus {
786
+ border-color: transparent !important;
787
+ }
788
+
789
+ .semi-input-wrapper:hover {
790
+ background-color: var(--semi-color-fill-0);
791
+ }
792
+
793
+ .semi-cascader:hover {
794
+ background-color: var(--semi-color-fill-0);
795
+ }
796
+
797
+ .semi-cascader:focus {
798
+ border-color: transparent !important;
799
+ }
800
+
801
+ .semi-cascader-focus {
802
+ border-color: transparent !important;
803
+ }
804
+ `;
805
+ var KeyEditorInput = styled(Input2)`
806
+ flex: 1;
807
+ height: 100%;
808
+ display: flex;
809
+ align-items: center;
810
+ input {
811
+ font-size: 12px !important;
812
+ }
813
+ `;
814
+ var KeyViewText = styled(Typography4.Text)`
815
+ flex: 1;
816
+ cursor: text;
817
+ font-size: 12px;
818
+ height: 100%;
819
+ ${(props) => props.disabled ? `
820
+ cursor: not-allowed !important;
821
+ ` : ""}
822
+ `;
823
+ var BaseIcon = styled.div`
824
+ color: var(--semi-color-text-2);
825
+ cursor: pointer;
826
+
827
+ ${(props) => props.draggable ? `
828
+ cursor: grab;
829
+ margin-right: 4px;
830
+ ` : ""}
831
+
832
+ ${(props) => props.triangle ? `
833
+ transform: rotate(270deg);
834
+
835
+ ` : ""}
836
+
837
+ ${(props) => props.isRotate ? `
838
+ transform: rotate(360deg);
839
+
840
+ ` : ""}
841
+
842
+ ${(props) => props.disabled ? `
843
+ opacity: 0.5;
844
+ cursor: not-allowed;
845
+ ` : ""}
846
+
847
+ ${(props) => props.primary ? `
848
+ color: var(--semi-color-primary) !important;
849
+ ` : ""}
850
+
851
+ &:hover {
852
+ color: var(--semi-color-primary);
853
+ }
854
+ `;
855
+ var CenterContainer = styled.div`
856
+ width: 100%;
857
+ height: 20px;
858
+ display: flex;
859
+ align-items: center;
860
+ gap: 12px;
861
+ justify-content: center;
862
+ `;
863
+ var TypeDisableViewContainer = styled(KeyViewContainer)`
864
+ color: var(--semi-color-disabled-text) !important;
865
+ cursor: not-allowed;
866
+ font-size: 12px;
867
+
868
+ :global {
869
+ .semi-typography {
870
+ color: var(--semi-color-disabled-text) !important;
871
+ }
872
+ }
873
+ `;
874
+ var TypeTextContainer = styled.div`
875
+ width: 100%;
876
+ height: 100%;
877
+ display: flex;
878
+ box-sizing: border-box;
879
+ align-items: center;
880
+ padding: 1px 5px;
881
+ `;
882
+ var GlobalSelectStyle = createGlobalStyle`
883
+ .semi-select {
884
+ border: none !important
885
+ }
886
+
887
+ `;
888
+
889
+ // src/components/type-editor/columns/value.tsx
890
+ var TypeText = ({ value, type }) => {
891
+ const typeDefinition = useTypeDefinitionManager();
892
+ const content = useMemo2(() => {
893
+ const config = typeDefinition.getTypeBySchema(type);
894
+ return config?.getValueText ? config.getValueText(value) : value || "";
895
+ }, [value, type]);
896
+ return /* @__PURE__ */ React9.createElement(TypeTextContainer, null, /* @__PURE__ */ React9.createElement(Typography5.Text, { ellipsis: { showTooltip: true } }, content));
897
+ };
898
+ var ViewRender = ({ rowData, onEditMode }) => {
899
+ const disabled = useDisabled("value" /* Value */, rowData);
900
+ if (disabled) {
901
+ return /* @__PURE__ */ React9.createElement(KeyViewContainer, { disabled: true }, /* @__PURE__ */ React9.createElement(Tooltip, { content: disabled }, /* @__PURE__ */ React9.createElement("div", { style: { width: "100%", height: "100%" } }, /* @__PURE__ */ React9.createElement(TypeText, { value: rowData.self?.extra?.value, type: rowData.self }))));
902
+ }
903
+ return /* @__PURE__ */ React9.createElement(KeyViewContainer, { onClick: () => onEditMode() }, /* @__PURE__ */ React9.createElement(TypeText, { value: rowData.self?.extra?.value, type: rowData.self }));
904
+ };
905
+ var EditRender = ({
906
+ rowData,
907
+ onChange,
908
+ typeEditor,
909
+ onViewMode
910
+ }) => {
911
+ const valueRef = useRef(rowData.self.extra?.value);
912
+ const [value, setValue] = useState2(rowData.self.extra?.value);
913
+ const typeDefinition = useTypeDefinitionManager();
914
+ const config = useMemo2(() => typeDefinition.getTypeBySchema(rowData.self), [rowData.self]);
915
+ useEffect3(() => {
916
+ typeEditor.editValue = value;
917
+ }, [typeEditor, value]);
918
+ useEffect3(() => {
919
+ setValue(rowData.self.extra?.value);
920
+ valueRef.current = rowData.self.extra?.value;
921
+ }, [rowData.self.extra?.value]);
922
+ const handleSubmit = useCallback(() => {
923
+ if (!rowData.self.extra) {
924
+ rowData.self.extra = {};
925
+ }
926
+ rowData.self.extra.value = valueRef.current;
927
+ onChange();
928
+ onViewMode();
929
+ }, [onChange, rowData]);
930
+ return /* @__PURE__ */ React9.createElement(KeyEditorContainer, null, /* @__PURE__ */ React9.createElement(GlobalSelectStyle, null), config && config?.getInputNode?.({
931
+ value,
932
+ onChange: (v) => {
933
+ valueRef.current = v;
934
+ setValue(v);
935
+ },
936
+ type: rowData.self,
937
+ onSubmit: () => {
938
+ handleSubmit();
939
+ onViewMode();
940
+ }
941
+ }));
942
+ };
943
+ var valueColumnConfig = {
944
+ type: "value" /* Value */,
945
+ width: 15,
946
+ label: "Value",
947
+ viewRender: ViewRender,
948
+ shortcuts: {
949
+ onEnter: ({ rowData, onChange, typeEditor, value, typeDefinitionService }) => {
950
+ const config = typeDefinitionService.getTypeBySchema(rowData.self);
951
+ if (config?.typeInputConfig?.canEnter) {
952
+ rowData.self.description = value;
953
+ onChange();
954
+ typeEditor.moveActivePosToNextLine();
955
+ }
956
+ },
957
+ onTab: ({ rowData, value, onChange, typeEditor }) => {
958
+ rowData.self.description = value;
959
+ onChange();
960
+ typeEditor.moveActivePosToNextItem();
961
+ }
962
+ },
963
+ editRender: EditRender
964
+ };
965
+
966
+ // src/components/type-editor/columns/type.tsx
967
+ import React18, { useEffect as useEffect7, useMemo as useMemo9, useState as useState10 } from "react";
968
+ import { pick } from "@flowgram.ai/utils";
969
+ import { Toast, Tooltip as Tooltip3 } from "@douyinfe/semi-ui";
970
+ import { IconHelpCircle } from "@douyinfe/semi-icons";
971
+
972
+ // src/components/type-editor/utils.ts
973
+ import { forwardRef } from "react";
974
+ import { nanoid } from "nanoid";
975
+
976
+ // src/components/type-editor/formatter/index.ts
977
+ var extraFormatter = (type) => {
978
+ if (type.extra !== void 0) {
979
+ type.extra = type.extra;
980
+ delete type.extra;
981
+ }
982
+ };
983
+ var extraDeFormatter = (type) => {
984
+ if (type.extra !== void 0) {
985
+ type.extra = type.extra;
986
+ delete type.extra;
987
+ }
988
+ };
989
+ var emptyKeyFormatter = (type) => {
990
+ if (type.properties) {
991
+ Object.keys(type.properties).forEach((k) => {
992
+ if (k.startsWith(SUFFIX)) {
993
+ delete type.properties[k];
994
+ }
995
+ });
996
+ }
997
+ };
998
+ var disableFixIndexFormatter = (type) => {
999
+ if (type.extra) {
1000
+ delete type.extra.index;
1001
+ if (Object.keys(type.extra).length === 0) {
1002
+ delete type.extra;
1003
+ }
1004
+ }
1005
+ };
1006
+
1007
+ // src/components/type-editor/utils.ts
1008
+ var genNewTypeSchema = (index) => {
1009
+ const newKey = genEmptyKey();
1010
+ return [
1011
+ newKey,
1012
+ {
1013
+ type: "string",
1014
+ extra: {
1015
+ index
1016
+ }
1017
+ }
1018
+ ];
1019
+ };
1020
+ var traverseIJsonSchema = (root, cb) => {
1021
+ if (root) {
1022
+ cb(root);
1023
+ if (root.items) {
1024
+ traverseIJsonSchema(root.items, cb);
1025
+ }
1026
+ if (root.additionalProperties) {
1027
+ traverseIJsonSchema(root.additionalProperties, cb);
1028
+ }
1029
+ if (root.properties) {
1030
+ Object.values(root.properties).forEach((v) => {
1031
+ traverseIJsonSchema(v, cb);
1032
+ });
1033
+ }
1034
+ }
1035
+ };
1036
+ var jsonParse = (jsonString) => {
1037
+ try {
1038
+ return JSON.parse(jsonString || "");
1039
+ } catch (error) {
1040
+ return void 0;
1041
+ }
1042
+ };
1043
+ var sortProperties = (typeSchema) => {
1044
+ const { properties = {} } = typeSchema;
1045
+ const originKeys = Object.keys(properties);
1046
+ const sortKeys = originKeys.sort(
1047
+ (a, b) => (properties[a].extra?.index || 0) - (properties[b].extra?.index || 0)
1048
+ );
1049
+ for (let i = 0; i < sortKeys.length; i++) {
1050
+ const key = sortKeys[i];
1051
+ fixFlowIndex(properties[key]);
1052
+ properties[key].extra.index = i;
1053
+ }
1054
+ };
1055
+ var fixFlowIndex = (type, idx = 0) => {
1056
+ if (!type) {
1057
+ return;
1058
+ }
1059
+ if (!type.extra) {
1060
+ type.extra = {};
1061
+ }
1062
+ if (type.extra.index === void 0) {
1063
+ type.extra.index = idx;
1064
+ }
1065
+ };
1066
+ var getInitialSchema = () => {
1067
+ const res = {
1068
+ type: "object",
1069
+ properties: {}
1070
+ };
1071
+ return res;
1072
+ };
1073
+ var clone = (val) => val ? JSON.parse(JSON.stringify(val)) : val;
1074
+ var isTempState = (type, customValidateName) => {
1075
+ let error = false;
1076
+ traverseIJsonSchema(type, (c) => {
1077
+ if (c.properties) {
1078
+ Object.keys(c.properties).forEach((key) => {
1079
+ const res = isEmptyKey(key) || customValidateName?.(key);
1080
+ if (res) {
1081
+ error = true;
1082
+ }
1083
+ });
1084
+ }
1085
+ });
1086
+ return error;
1087
+ };
1088
+ var genEmptyKey = () => SUFFIX + nanoid();
1089
+ var isEmptyKey = (key) => key.startsWith(SUFFIX);
1090
+ var formateKey = (key) => isEmptyKey(key) ? "" : key;
1091
+ var deFormateKey = (key, originKey) => !key ? originKey || genEmptyKey() : key;
1092
+ var formateTypeSchema = (typeSchema, config) => {
1093
+ const newSchema = JSON.parse(JSON.stringify(typeSchema));
1094
+ const formatters = [emptyKeyFormatter];
1095
+ if (config.disableFixIndex) {
1096
+ formatters.push(disableFixIndexFormatter);
1097
+ }
1098
+ traverseIJsonSchema(newSchema, (type) => {
1099
+ formatters.forEach((formatter) => {
1100
+ formatter(type);
1101
+ });
1102
+ });
1103
+ return newSchema;
1104
+ };
1105
+ var valueToTypeSchema = (value) => {
1106
+ switch (typeof value) {
1107
+ case "string": {
1108
+ return {
1109
+ type: "string"
1110
+ };
1111
+ }
1112
+ case "bigint":
1113
+ case "number": {
1114
+ return {
1115
+ type: "number"
1116
+ };
1117
+ }
1118
+ case "boolean": {
1119
+ return {
1120
+ type: "boolean"
1121
+ };
1122
+ }
1123
+ case "object": {
1124
+ if (value) {
1125
+ if (Array.isArray(value)) {
1126
+ return {
1127
+ type: "array",
1128
+ items: valueToTypeSchema(value[0])
1129
+ };
1130
+ } else {
1131
+ const object = {
1132
+ type: "object",
1133
+ properties: {}
1134
+ };
1135
+ Object.keys(value).forEach((k) => {
1136
+ object.properties[k] = valueToTypeSchema(value[k]);
1137
+ });
1138
+ return object;
1139
+ }
1140
+ }
1141
+ break;
1142
+ }
1143
+ default:
1144
+ break;
1145
+ }
1146
+ return { type: "string" };
1147
+ };
1148
+ var typeEditorUtils = {
1149
+ genNewTypeSchema,
1150
+ sortProperties,
1151
+ traverseIJsonSchema,
1152
+ fixFlowIndex,
1153
+ genEmptyKey,
1154
+ jsonParse,
1155
+ clone,
1156
+ formateTypeSchema,
1157
+ isTempState,
1158
+ valueToTypeSchema,
1159
+ deFormateKey,
1160
+ formateKey,
1161
+ getInitialSchema
1162
+ };
1163
+ function fixedTSForwardRef(render) {
1164
+ return forwardRef(render);
1165
+ }
1166
+ var getComponentId = (id) => `${COMPONENT_ID_PREFIX}-${id}`;
1167
+
1168
+ // src/components/type-selector/index.tsx
1169
+ import React17, { useState as useState9 } from "react";
1170
+
1171
+ // src/components/type-selector/cascader-v2/index.tsx
1172
+ import React16, { useEffect as useEffect6, useRef as useRef3, useState as useState8 } from "react";
1173
+ import { Popover } from "@douyinfe/semi-ui";
1174
+
1175
+ // src/components/type-selector/cascader-v2/type-search.tsx
1176
+ import React11, {
1177
+ forwardRef as forwardRef2,
1178
+ useCallback as useCallback3,
1179
+ useEffect as useEffect4,
1180
+ useMemo as useMemo5,
1181
+ useRef as useRef2,
1182
+ useState as useState4
1183
+ } from "react";
1184
+ import classNames from "classnames";
1185
+ import { Typography as Typography7 } from "@douyinfe/semi-ui";
1186
+
1187
+ // src/components/type-selector/hooks/use-hight-light.tsx
1188
+ import React10 from "react";
1189
+ var useHighlightKeyword = (label, keyword, hightLightStyle = {}, id) => {
1190
+ if (label && keyword) {
1191
+ return label.split(new RegExp(`(${keyword})`, "gi")).map(
1192
+ (c, i) => c.toLocaleLowerCase() === keyword.toLocaleLowerCase() ? /* @__PURE__ */ React10.createElement(
1193
+ "span",
1194
+ {
1195
+ key: c + i + id,
1196
+ style: {
1197
+ color: "rgba(var(--semi-orange-5), 1)",
1198
+ ...hightLightStyle
1199
+ }
1200
+ },
1201
+ c
1202
+ ) : /* @__PURE__ */ React10.createElement("span", { key: c + i + id }, c)
1203
+ );
1204
+ }
1205
+ return [label];
1206
+ };
1207
+
1208
+ // src/components/type-selector/hooks/option-value.ts
1209
+ import { useMemo as useMemo3 } from "react";
1210
+ var useTypeTransform = () => {
1211
+ const typeService = useTypeDefinitionManager();
1212
+ const convertValueToOptionValue = useMemo3(
1213
+ () => (originValue) => {
1214
+ const type = originValue && typeService.getTypeBySchema(originValue);
1215
+ return originValue && type?.getStringValueByTypeSchema?.(originValue) || "";
1216
+ },
1217
+ [typeService]
1218
+ );
1219
+ const convertOptionValueToModeValue = useMemo3(
1220
+ () => (optionValue) => {
1221
+ const [root, ...rest] = (optionValue || "").split("-");
1222
+ const rooType = typeService.getTypeByName(root);
1223
+ if (rooType?.getTypeSchemaByStringValue) {
1224
+ return rooType.getTypeSchemaByStringValue(rest.join("-"));
1225
+ }
1226
+ return rooType?.getDefaultSchema();
1227
+ },
1228
+ [typeService]
1229
+ );
1230
+ const checkHasChildren = useMemo3(
1231
+ () => (typeDef, ctx) => typeDef?.getSupportedItemTypes && typeDef.getSupportedItemTypes(ctx).length !== 0 || !!typeDef.container,
1232
+ [typeService]
1233
+ );
1234
+ const getModeOptionChildrenType = useMemo3(
1235
+ () => (typeDef, ctx) => {
1236
+ const getSupportType = (parentType = "") => typeService.getTypeRegistriesWithParentType(
1237
+ parentType
1238
+ );
1239
+ const support = new Set(getSupportType(ctx.parentType).map((v) => v.type));
1240
+ return (typeDef?.getSupportedItemTypes && typeDef.getSupportedItemTypes(ctx) || []).filter((v) => support.has(v.type));
1241
+ },
1242
+ [typeService]
1243
+ );
1244
+ return {
1245
+ convertOptionValueToModeValue,
1246
+ convertValueToOptionValue,
1247
+ checkHasChildren,
1248
+ getModeOptionChildrenType
1249
+ };
1250
+ };
1251
+
1252
+ // src/components/type-selector/hooks/focus-item.ts
1253
+ import { useCallback as useCallback2, useImperativeHandle, useMemo as useMemo4, useState as useState3 } from "react";
1254
+ import { noop } from "lodash";
1255
+ var validatePos = (pos) => pos.x >= 0 && pos.y >= 0;
1256
+ var useFocusItemCascader = ({
1257
+ rootTypes,
1258
+ renderData,
1259
+ cascaderTypes,
1260
+ ref,
1261
+ onCollapse,
1262
+ onChange
1263
+ }) => {
1264
+ const [focusPos, setFocusPos] = useState3({ x: -1, y: -1 });
1265
+ const allOptions = useMemo4(
1266
+ () => [rootTypes, ...renderData.map((item) => item.options)],
1267
+ [rootTypes, renderData]
1268
+ );
1269
+ const initPos = useCallback2(() => {
1270
+ setFocusPos({
1271
+ x: 0,
1272
+ y: 0
1273
+ });
1274
+ }, []);
1275
+ const focusItem = useMemo4(() => allOptions[focusPos.x]?.[focusPos.y], [focusPos, allOptions]);
1276
+ const focusValue = useMemo4(
1277
+ () => allOptions[focusPos.x]?.[focusPos.y]?.value,
1278
+ [focusPos, allOptions]
1279
+ );
1280
+ useImperativeHandle(
1281
+ ref,
1282
+ () => ({
1283
+ initFocusItem() {
1284
+ initPos();
1285
+ },
1286
+ clearFocusItem() {
1287
+ setFocusPos({
1288
+ x: -1,
1289
+ y: -1
1290
+ });
1291
+ },
1292
+ moveFocusItemUp() {
1293
+ if (!validatePos(focusPos)) {
1294
+ initPos();
1295
+ return;
1296
+ }
1297
+ const { x, y } = focusPos;
1298
+ if (!allOptions[x]?.[y]) {
1299
+ return;
1300
+ }
1301
+ let newY = (y - 1 + allOptions[x].length) % allOptions[x].length;
1302
+ let item = allOptions[x]?.[newY];
1303
+ while (item?.disabled && newY !== y) {
1304
+ newY = (newY - 1 + allOptions[x].length) % allOptions[x].length;
1305
+ item = allOptions[x]?.[newY];
1306
+ }
1307
+ if (newY !== y) {
1308
+ setFocusPos({
1309
+ x,
1310
+ y: newY
1311
+ });
1312
+ }
1313
+ },
1314
+ moveFocusItemDown() {
1315
+ if (!validatePos(focusPos)) {
1316
+ initPos();
1317
+ return;
1318
+ }
1319
+ const { x, y } = focusPos;
1320
+ if (!allOptions[x]?.[y]) {
1321
+ return;
1322
+ }
1323
+ let newY = (y + 1) % allOptions[x].length;
1324
+ let item = allOptions[x]?.[newY];
1325
+ while (item?.disabled && newY !== y) {
1326
+ newY = (newY + 1) % allOptions[x].length;
1327
+ item = allOptions[x]?.[newY];
1328
+ }
1329
+ if (newY !== y) {
1330
+ setFocusPos({
1331
+ x,
1332
+ y: newY
1333
+ });
1334
+ }
1335
+ },
1336
+ moveFocusItemLeft() {
1337
+ if (!validatePos(focusPos)) {
1338
+ initPos();
1339
+ return;
1340
+ }
1341
+ const childrenPanelLen = cascaderTypes.length;
1342
+ if (childrenPanelLen > 0) {
1343
+ const lastParentType = cascaderTypes[childrenPanelLen - 1];
1344
+ const newY = allOptions[childrenPanelLen - 1]?.findIndex(
1345
+ (v) => v.type === lastParentType
1346
+ );
1347
+ onCollapse(lastParentType, childrenPanelLen - 1);
1348
+ setFocusPos({
1349
+ x: focusPos.x - 1,
1350
+ y: newY || 0
1351
+ });
1352
+ }
1353
+ },
1354
+ moveFocusItemRight() {
1355
+ if (!validatePos(focusPos)) {
1356
+ initPos();
1357
+ return;
1358
+ }
1359
+ if (focusItem && !focusItem.isLeaf && cascaderTypes[focusPos.x] !== focusItem.type) {
1360
+ onCollapse(focusItem.type, focusPos.x);
1361
+ setFocusPos({
1362
+ x: focusPos.x + 1,
1363
+ y: 0
1364
+ });
1365
+ }
1366
+ },
1367
+ selectFocusItem() {
1368
+ if (!validatePos(focusPos)) {
1369
+ return;
1370
+ }
1371
+ if (focusItem?.isLeaf) {
1372
+ onChange(focusValue);
1373
+ }
1374
+ }
1375
+ })
1376
+ );
1377
+ return {
1378
+ focusValue
1379
+ };
1380
+ };
1381
+ var useFocusItemSearch = ({
1382
+ ref,
1383
+ onChange,
1384
+ viewValue
1385
+ }) => {
1386
+ const [focusPos, setFocusPos] = useState3(-1);
1387
+ const focusValue = useMemo4(() => viewValue[focusPos]?.value, [viewValue, focusPos]);
1388
+ const focusItem = useMemo4(() => viewValue[focusPos], [viewValue, focusPos]);
1389
+ useImperativeHandle(ref, () => ({
1390
+ selectFocusItem() {
1391
+ if (!focusItem.disabled) {
1392
+ onChange(focusValue);
1393
+ }
1394
+ },
1395
+ moveFocusItemDown() {
1396
+ if (focusPos < 0) {
1397
+ setFocusPos(0);
1398
+ return;
1399
+ }
1400
+ let newPos = (focusPos + 1) % viewValue.length;
1401
+ while (viewValue[newPos]?.disabled && newPos !== focusPos) {
1402
+ newPos = (newPos + 1) % viewValue.length;
1403
+ }
1404
+ setFocusPos(newPos);
1405
+ },
1406
+ moveFocusItemLeft: noop,
1407
+ moveFocusItemRight: noop,
1408
+ moveFocusItemUp() {
1409
+ if (focusPos < 0) {
1410
+ setFocusPos(0);
1411
+ return;
1412
+ }
1413
+ let newPos = (focusPos - 1 + viewValue.length) % viewValue.length;
1414
+ while (viewValue[newPos]?.disabled && newPos !== focusPos) {
1415
+ newPos = (newPos - 1 + viewValue.length) % viewValue.length;
1416
+ }
1417
+ setFocusPos(newPos);
1418
+ },
1419
+ initFocusItem() {
1420
+ setFocusPos(0);
1421
+ },
1422
+ clearFocusItem() {
1423
+ setFocusPos(-1);
1424
+ }
1425
+ }));
1426
+ return {
1427
+ focusValue
1428
+ };
1429
+ };
1430
+
1431
+ // src/components/type-selector/cascader-v2/style.ts
1432
+ import styled2, { createGlobalStyle as createGlobalStyle2 } from "styled-components";
1433
+ import { Typography as Typography6 } from "@douyinfe/semi-ui";
1434
+ var StyledFullContainer = styled2.div`
1435
+ width: 100%;
1436
+ height: 100%;
1437
+ `;
1438
+ var CustomCascaderContainer = styled2.span`
1439
+ display: flex;
1440
+ align-items: center;
1441
+ justify-content: center;
1442
+ width: 100%;
1443
+ height: 100%;
1444
+ `;
1445
+ var CascaderContainer = styled2(StyledFullContainer)`
1446
+ position: relative;
1447
+ `;
1448
+ var TriggerText = styled2.div`
1449
+ display: flex;
1450
+ width: 100%;
1451
+ `;
1452
+ var CascaderDropdown = styled2.div`
1453
+ display: flex;
1454
+ width: 100%;
1455
+ height: 100%;
1456
+ `;
1457
+ var TriggerGlobalStyle = createGlobalStyle2`
1458
+ .semi-cascader-selection {
1459
+ font-size: 12px !important;
1460
+
1461
+ svg {
1462
+ width: 12px;
1463
+ height: 12px;
1464
+ }
1465
+ }
1466
+ `;
1467
+ var CascaderOptionItem = styled2.li`
1468
+ ${(props) => props.focus ? "background-color: var(--semi-color-fill-0)" : ""}
1469
+ `;
1470
+ var DropdownGlobalStyle = createGlobalStyle2`
1471
+ .semi-cascader-option-lists {
1472
+ max-width: 510px;
1473
+ overflow-x: auto;
1474
+ height: auto;
1475
+
1476
+
1477
+ .semi-cascader-option-list {
1478
+ width: 150px;
1479
+ flex-shrink: 0;
1480
+ border-left: none;
1481
+ border-right: 1px solid var(--semi-color-fill-0);
1482
+
1483
+ max-height: 50vh;
1484
+
1485
+ ::-webkit-scrollbar {
1486
+ width: 0;
1487
+ height: 0;
1488
+ }
1489
+
1490
+ .semi-cascader-option {
1491
+ font-size: 12px !important;
1492
+ width: 100%;
1493
+ padding: 6px 12px;
1494
+ cursor: pointer;
1495
+ box-sizing: border-box;
1496
+
1497
+ svg {
1498
+ width: 12px;
1499
+ height: 12px;
1500
+ }
1501
+ }
1502
+ }
1503
+
1504
+
1505
+ .semi-cascader-option-disabled {
1506
+ cursor: not-allowed;
1507
+ }
1508
+
1509
+ }
1510
+
1511
+ .semi-cascader-option-icon {
1512
+ margin-right:8px;
1513
+ }
1514
+
1515
+ .semi-cascader-option-icon-empty {
1516
+ margin-right: 0;
1517
+ }
1518
+
1519
+ `;
1520
+ var StyledSearchList = styled2.ul`
1521
+ &::-webkit-scrollbar {
1522
+ display: none;
1523
+ }
1524
+ width: 100%;
1525
+ height: 100%;
1526
+ `;
1527
+ var TypeSearchText = styled2(Typography6.Text)`
1528
+ padding: 8px 12px;
1529
+ `;
1530
+ var TextGlobalStyle = createGlobalStyle2`
1531
+ .semi-typography {
1532
+ color: unset !important;
1533
+ }
1534
+
1535
+ `;
1536
+ var SearchText = styled2.span`
1537
+ display: inline-flex;
1538
+ align-items: center;
1539
+ width: 100%;
1540
+ gap: 8px;
1541
+ cursor: ${(props) => props.disabled ? "not-allowed" : "pointer"};
1542
+ ${(props) => props.disabled ? "color: var(--semi-color-disabled-text);" : ""};
1543
+ `;
1544
+ var SearchIcon = styled2.span`
1545
+ display: inline-flex;
1546
+ align-items: center;
1547
+
1548
+ svg {
1549
+ width: 12px;
1550
+ height: 12px;
1551
+ }
1552
+ `;
1553
+
1554
+ // src/components/type-selector/cascader-v2/type-search.tsx
1555
+ var defaultDeep = 2;
1556
+ var SearchItem = ({ item, query, focusValue, onSelect, selectValue }) => {
1557
+ const typeService = useTypeDefinitionManager();
1558
+ const { convertOptionValueToModeValue } = useTypeTransform();
1559
+ const config = typeService.getTypeByName(item.type);
1560
+ const typeSchema = useMemo5(
1561
+ () => convertOptionValueToModeValue(item.value),
1562
+ [item.value]
1563
+ );
1564
+ const text = useMemo5(() => config?.getDisplayText(typeSchema), [typeSchema, config]);
1565
+ const label = useHighlightKeyword(
1566
+ text || "",
1567
+ query,
1568
+ {
1569
+ color: "var(--semi-color-primary)",
1570
+ fontWeight: 600
1571
+ },
1572
+ item.value
1573
+ );
1574
+ return /* @__PURE__ */ React11.createElement(
1575
+ "li",
1576
+ {
1577
+ key: item.value,
1578
+ onClick: () => item.disabled ? void 0 : onSelect(item, typeSchema),
1579
+ style: {
1580
+ minWidth: "unset",
1581
+ background: focusValue === item.value ? "var(--semi-color-fill-0)" : void 0
1582
+ },
1583
+ className: classNames(
1584
+ "semi-cascader-option",
1585
+ item.disabled && "semi-cascader-option-disabled",
1586
+ selectValue === item.value && "semi-cascader-option-select"
1587
+ )
1588
+ },
1589
+ /* @__PURE__ */ React11.createElement(TextGlobalStyle, null),
1590
+ /* @__PURE__ */ React11.createElement(SearchText, { disabled: !!item.disabled }, /* @__PURE__ */ React11.createElement(SearchIcon, null, config?.getDisplayIcon?.(typeSchema)), /* @__PURE__ */ React11.createElement(Typography7.Text, { ellipsis: { showTooltip: true } }, /* @__PURE__ */ React11.createElement("span", null, label)))
1591
+ );
1592
+ };
1593
+ var TypeSearchPanel = forwardRef2(({ query, disableTypes = [], onChange, triggerRef, value, onSearchChange }, ref) => {
1594
+ const typeService = useTypeDefinitionManager();
1595
+ const {
1596
+ convertValueToOptionValue,
1597
+ checkHasChildren,
1598
+ convertOptionValueToModeValue,
1599
+ getModeOptionChildrenType
1600
+ } = useTypeTransform();
1601
+ const customDisableType = useMemo5(() => {
1602
+ const map = /* @__PURE__ */ new Map();
1603
+ disableTypes.forEach((v) => {
1604
+ map.set(v.type, v.reason);
1605
+ });
1606
+ return map;
1607
+ }, [disableTypes]);
1608
+ const selectValue = useMemo5(() => convertValueToOptionValue(value), [value]);
1609
+ const [searchResult, setSearchResult] = useState4([]);
1610
+ const levelCache = useRef2([]);
1611
+ const handleGenLevelInfo = useCallback3(
1612
+ (level) => {
1613
+ for (let i = 0; i < level; i++) {
1614
+ if (levelCache.current[i]) {
1615
+ continue;
1616
+ }
1617
+ if (i === 0) {
1618
+ const newRootTypes = typeService.getTypeRegistriesWithParentType();
1619
+ levelCache.current[i] = newRootTypes.map((type) => ({
1620
+ key: type.type,
1621
+ type: type.type,
1622
+ parentLabels: [],
1623
+ disabled: customDisableType.get(type.type)
1624
+ }));
1625
+ } else {
1626
+ const lastLevelCache = levelCache.current[i - 1];
1627
+ const newCacheTypes = [];
1628
+ levelCache.current[i] = newCacheTypes;
1629
+ lastLevelCache.forEach((type) => {
1630
+ if (type.disabled) {
1631
+ return;
1632
+ }
1633
+ const config = typeService.getTypeByName(type.type);
1634
+ const parentTypes = type.key.split("-");
1635
+ if (config && checkHasChildren(config, {
1636
+ level: i
1637
+ })) {
1638
+ const childrenTypes = getModeOptionChildrenType(
1639
+ config,
1640
+ {
1641
+ parentType: type.type,
1642
+ level: i,
1643
+ parentTypes
1644
+ }
1645
+ );
1646
+ childrenTypes.forEach((child) => {
1647
+ const childConfig = typeService.getTypeByName(child.type);
1648
+ newCacheTypes.push({
1649
+ type: child.type,
1650
+ key: [...parentTypes, child.type].join("-"),
1651
+ disabled: child.disabled || (childConfig?.customDisabled ? childConfig.customDisabled({
1652
+ level: i + 1,
1653
+ parentType: type.type,
1654
+ parentTypes
1655
+ }) : void 0)
1656
+ });
1657
+ });
1658
+ }
1659
+ });
1660
+ }
1661
+ }
1662
+ },
1663
+ [customDisableType]
1664
+ );
1665
+ const handleGenSearchResult = useCallback3(() => {
1666
+ const len = levelCache.current.length;
1667
+ if (!query) {
1668
+ setSearchResult([]);
1669
+ return;
1670
+ }
1671
+ const newSearchResult = [];
1672
+ for (let i = 0; i < len; i++) {
1673
+ const cacheTypes = levelCache.current[i] || [];
1674
+ cacheTypes.forEach((type) => {
1675
+ const config = typeService.getTypeByName(type.type);
1676
+ if (config && config.label.toLocaleLowerCase().indexOf(query.toLocaleLowerCase()) > -1) {
1677
+ newSearchResult.push({
1678
+ value: type.key,
1679
+ icon: config.icon,
1680
+ disabled: type.disabled,
1681
+ level: i,
1682
+ type: type.type
1683
+ });
1684
+ }
1685
+ });
1686
+ }
1687
+ setSearchResult(newSearchResult);
1688
+ }, [query]);
1689
+ useEffect4(() => {
1690
+ handleGenLevelInfo(defaultDeep);
1691
+ }, [handleGenLevelInfo]);
1692
+ useEffect4(() => {
1693
+ handleGenSearchResult();
1694
+ }, [query]);
1695
+ const viewValue = useMemo5(
1696
+ () => searchResult.filter((item) => {
1697
+ const config = typeService.getTypeByName(item.type);
1698
+ return config && !checkHasChildren(config, {
1699
+ level: item.level
1700
+ });
1701
+ }),
1702
+ [searchResult, typeService]
1703
+ );
1704
+ const { focusValue } = useFocusItemSearch({
1705
+ ref,
1706
+ viewValue,
1707
+ onChange: (v) => {
1708
+ const newVal = convertOptionValueToModeValue(v);
1709
+ onChange?.(newVal, { source: "custom-panel" });
1710
+ onSearchChange("");
1711
+ }
1712
+ });
1713
+ return /* @__PURE__ */ React11.createElement(
1714
+ "div",
1715
+ {
1716
+ className: classNames("semi-cascader-option-lists"),
1717
+ style: triggerRef.current ? { width: Math.max(triggerRef.current.clientWidth, 150) } : {}
1718
+ },
1719
+ /* @__PURE__ */ React11.createElement(StyledSearchList, { className: classNames("semi-cascader-option-list") }, /* @__PURE__ */ React11.createElement(React11.Fragment, null, viewValue.length === 0 ? /* @__PURE__ */ React11.createElement(TypeSearchText, { type: "secondary" }, "No results.") : /* @__PURE__ */ React11.createElement(React11.Fragment, null, viewValue.map((item) => /* @__PURE__ */ React11.createElement(
1720
+ SearchItem,
1721
+ {
1722
+ selectValue,
1723
+ key: item.value,
1724
+ query,
1725
+ focusValue,
1726
+ item,
1727
+ onSelect: (_, v) => onChange?.(v, { source: "type-selector" })
1728
+ }
1729
+ )))))
1730
+ );
1731
+ });
1732
+
1733
+ // src/components/type-selector/cascader-v2/type-cascader.tsx
1734
+ import React13, { forwardRef as forwardRef3, useCallback as useCallback4, useMemo as useMemo6, useState as useState6 } from "react";
1735
+ import classNames2 from "classnames";
1736
+ import { Tooltip as Tooltip2 } from "@douyinfe/semi-ui";
1737
+ import { IconCheckboxTick, IconChevronRight } from "@douyinfe/semi-icons";
1738
+
1739
+ // src/components/type-selector/utils/index.tsx
1740
+ import React12 from "react";
1741
+ var definitionToCascaderOption = ({
1742
+ config,
1743
+ customDisableType = /* @__PURE__ */ new Map(),
1744
+ prefix,
1745
+ parentTypes,
1746
+ disabled,
1747
+ parentType,
1748
+ level
1749
+ }) => {
1750
+ const typeValue = config.type;
1751
+ const optionValue = prefix ? [prefix, typeValue].join("-") : typeValue;
1752
+ const label = /* @__PURE__ */ React12.createElement("div", { style: { display: "flex", gap: 8, alignItems: "center" } }, config.icon, /* @__PURE__ */ React12.createElement("span", null, config.label));
1753
+ const customDisabled = config.customDisabled && config.customDisabled({ level, parentType, parentTypes });
1754
+ const reason = disabled || customDisableType.get(typeValue) || customDisabled;
1755
+ return {
1756
+ disabled: reason,
1757
+ value: optionValue,
1758
+ label,
1759
+ type: typeValue,
1760
+ source: config.typeCascaderConfig?.unClosePanelAfterSelect ? "custom-panel" : "type-selector",
1761
+ isLeaf: reason ? true : !(config.getSupportedItemTypes && config.getSupportedItemTypes({ level }).length !== 0 || config.container)
1762
+ };
1763
+ };
1764
+ var typeSelectorUtils = {
1765
+ definitionToCascaderOption
1766
+ };
1767
+
1768
+ // src/components/type-selector/hooks/root-types.ts
1769
+ import { useEffect as useEffect5, useState as useState5 } from "react";
1770
+ var genId = (options) => options.map((v) => `${v.disabled}${v.label}`).join("-");
1771
+ var useCascaderRootTypes = (customDisableType) => {
1772
+ const [rootTypes, setRootTypes] = useState5([]);
1773
+ const typeService = useTypeDefinitionManager();
1774
+ useEffect5(() => {
1775
+ const init = () => {
1776
+ const newRootTypes = typeService.getTypeRegistriesWithParentType().map((config) => {
1777
+ const res = typeSelectorUtils.definitionToCascaderOption({
1778
+ customDisableType,
1779
+ config,
1780
+ level: 0,
1781
+ parentTypes: []
1782
+ });
1783
+ return res;
1784
+ });
1785
+ if (genId(newRootTypes) !== genId(rootTypes)) {
1786
+ setRootTypes(newRootTypes);
1787
+ }
1788
+ };
1789
+ init();
1790
+ const dispose = typeService.onTypeRegistryChange(init);
1791
+ return () => {
1792
+ dispose.dispose();
1793
+ };
1794
+ }, [rootTypes, customDisableType]);
1795
+ return rootTypes;
1796
+ };
1797
+
1798
+ // src/components/type-selector/cascader-v2/type-cascader.tsx
1799
+ var OptionList = ({
1800
+ options,
1801
+ activeType,
1802
+ selectValue,
1803
+ onCollapse,
1804
+ onSelect,
1805
+ focusValue
1806
+ }) => /* @__PURE__ */ React13.createElement("ul", { className: "semi-cascader-option-list" }, options.map((opt) => {
1807
+ const child = /* @__PURE__ */ React13.createElement(
1808
+ CascaderOptionItem,
1809
+ {
1810
+ focus: focusValue === opt.value,
1811
+ onClick: !opt.disabled ? () => opt.isLeaf ? onSelect?.(
1812
+ opt.value,
1813
+ opt.source
1814
+ ) : onCollapse?.(opt.type) : void 0,
1815
+ key: opt.value,
1816
+ className: classNames2(
1817
+ "semi-cascader-option",
1818
+ activeType === opt.type && "semi-cascader-option-active",
1819
+ selectValue === opt.value && "semi-cascader-option-select",
1820
+ opt.disabled && "semi-cascader-option-disabled"
1821
+ )
1822
+ },
1823
+ /* @__PURE__ */ React13.createElement("span", { className: "semi-cascader-option-label" }, selectValue === opt.value ? /* @__PURE__ */ React13.createElement(
1824
+ IconCheckboxTick,
1825
+ {
1826
+ className: classNames2("semi-cascader-option-icon"),
1827
+ style: {
1828
+ color: selectValue === opt.value ? "var(--semi-color-primary)" : void 0
1829
+ }
1830
+ }
1831
+ ) : /* @__PURE__ */ React13.createElement("span", { className: "semi-cascader-option-icon semi-cascader-option-icon-empty" }), typeof opt.label === "string" ? /* @__PURE__ */ React13.createElement("span", null, opt.label) : opt.label),
1832
+ !opt.isLeaf && /* @__PURE__ */ React13.createElement(IconChevronRight, null)
1833
+ );
1834
+ return opt.disabled ? /* @__PURE__ */ React13.createElement(Tooltip2, { content: opt.disabled }, child) : child;
1835
+ }));
1836
+ var useGenerateCascaderTypes = () => {
1837
+ const typeService = useTypeDefinitionManager();
1838
+ const generateCascaderTypes = useCallback4(
1839
+ (value) => {
1840
+ const res = [];
1841
+ const types = value?.split("-") || [];
1842
+ const arr = types.splice(0, types.length - 1) || [];
1843
+ while (arr.length > 0) {
1844
+ const type = arr.shift();
1845
+ if (type) {
1846
+ const config = type ? typeService.getTypeByName(type) : void 0;
1847
+ if (config?.customChildOptionValue) {
1848
+ const extras = config.customChildOptionValue();
1849
+ arr.splice(0, extras.length);
1850
+ }
1851
+ res.push(type);
1852
+ }
1853
+ }
1854
+ return res;
1855
+ },
1856
+ [typeService]
1857
+ );
1858
+ return generateCascaderTypes;
1859
+ };
1860
+ var generateCustomPanelType = (value) => (value?.split("-") || []).pop() || "";
1861
+ var TypeCascader = forwardRef3(({ value: originValue, onChange, onContextChange, onRePos, disableTypes = [] }, ref) => {
1862
+ const typeService = useTypeDefinitionManager();
1863
+ const {
1864
+ convertOptionValueToModeValue,
1865
+ convertValueToOptionValue,
1866
+ getModeOptionChildrenType
1867
+ } = useTypeTransform();
1868
+ const customDisableType = useMemo6(() => {
1869
+ const map = /* @__PURE__ */ new Map();
1870
+ disableTypes.forEach((v) => {
1871
+ map.set(v.type, v.reason);
1872
+ });
1873
+ return map;
1874
+ }, [disableTypes]);
1875
+ const rootTypes = useCascaderRootTypes(customDisableType);
1876
+ const generateCascaderTypes = useGenerateCascaderTypes();
1877
+ const value = useMemo6(() => convertValueToOptionValue(originValue), [originValue]);
1878
+ const [cascaderTypes, setCascaderLTypes] = useState6(generateCascaderTypes(value));
1879
+ const [customPanelType, setCustomPanelType] = useState6(generateCustomPanelType(value));
1880
+ const handleChange = useCallback4(
1881
+ (newOptionValue, source = "type-selector") => {
1882
+ if (newOptionValue === value) {
1883
+ setCascaderLTypes(generateCascaderTypes(newOptionValue));
1884
+ setCustomPanelType(generateCustomPanelType(newOptionValue));
1885
+ onRePos();
1886
+ return;
1887
+ }
1888
+ const newValue = convertOptionValueToModeValue(newOptionValue);
1889
+ if (onChange) {
1890
+ onChange(newValue, {
1891
+ source
1892
+ });
1893
+ }
1894
+ setCascaderLTypes(generateCascaderTypes(newOptionValue));
1895
+ setCustomPanelType(generateCustomPanelType(newOptionValue));
1896
+ const newCtx = newValue && typeService.getTypeBySchema(newValue)?.typeCascaderConfig?.generateInitCtx?.(newValue) || {};
1897
+ onContextChange(newCtx);
1898
+ },
1899
+ [onChange, onContextChange, value]
1900
+ );
1901
+ const renderData = useMemo6(
1902
+ () => cascaderTypes.map((item, level) => {
1903
+ const parentDef = typeService.getTypeByName(item);
1904
+ const childrenType = getModeOptionChildrenType(
1905
+ parentDef,
1906
+ {
1907
+ parentType: item,
1908
+ level: level + 1,
1909
+ parentTypes: [...cascaderTypes].splice(0, level)
1910
+ }
1911
+ );
1912
+ const prefix = [...cascaderTypes].splice(0, level + 1).map((type) => {
1913
+ const config = typeService.getTypeByName(type);
1914
+ if (config?.customChildOptionValue) {
1915
+ return [type, config.customChildOptionValue()];
1916
+ }
1917
+ return type;
1918
+ }).flat().join("-");
1919
+ const options = childrenType.map((child) => {
1920
+ const def = typeService.getTypeByName(child.type);
1921
+ if (def) {
1922
+ return typeSelectorUtils.definitionToCascaderOption({
1923
+ config: def,
1924
+ customDisableType,
1925
+ prefix,
1926
+ // parentConfig: parentDef,
1927
+ level: level + 1,
1928
+ disabled: child.disabled,
1929
+ parentType: item,
1930
+ parentTypes: [...cascaderTypes].splice(0, level + 1)
1931
+ });
1932
+ }
1933
+ }).filter(Boolean);
1934
+ return {
1935
+ item,
1936
+ options
1937
+ };
1938
+ }),
1939
+ [cascaderTypes, customDisableType]
1940
+ );
1941
+ const handleCollapse = useCallback4(
1942
+ (type, level) => {
1943
+ const newCascaderTypes = [...cascaderTypes];
1944
+ if (cascaderTypes[level] !== type) {
1945
+ newCascaderTypes.splice(level);
1946
+ newCascaderTypes.push(type);
1947
+ } else {
1948
+ newCascaderTypes.splice(level);
1949
+ }
1950
+ setCustomPanelType("");
1951
+ onRePos();
1952
+ setCascaderLTypes(newCascaderTypes);
1953
+ },
1954
+ [cascaderTypes]
1955
+ );
1956
+ const { focusValue } = useFocusItemCascader({
1957
+ rootTypes,
1958
+ onCollapse: handleCollapse,
1959
+ renderData,
1960
+ cascaderTypes,
1961
+ onChange: (v) => handleChange(v, "type-selector"),
1962
+ ref
1963
+ });
1964
+ return /* @__PURE__ */ React13.createElement(CascaderDropdown, null, /* @__PURE__ */ React13.createElement(DropdownGlobalStyle, null), /* @__PURE__ */ React13.createElement("div", { className: "semi-cascader-option-lists" }, /* @__PURE__ */ React13.createElement(
1965
+ OptionList,
1966
+ {
1967
+ activeType: cascaderTypes[0],
1968
+ selectValue: value,
1969
+ options: rootTypes,
1970
+ focusValue,
1971
+ onSelect: handleChange,
1972
+ onCollapse: (type) => handleCollapse(type, 0)
1973
+ }
1974
+ ), renderData.map(({ item, options }, level) => /* @__PURE__ */ React13.createElement(
1975
+ OptionList,
1976
+ {
1977
+ onSelect: handleChange,
1978
+ key: item + level,
1979
+ focusValue,
1980
+ activeType: cascaderTypes[level + 1],
1981
+ selectValue: value,
1982
+ options,
1983
+ onCollapse: (type) => handleCollapse(type, level + 1)
1984
+ }
1985
+ )), originValue && typeService.getTypeByName(customPanelType)?.typeCascaderConfig?.customCascaderPanel?.({
1986
+ typeSchema: originValue,
1987
+ onChange: (newVal) => {
1988
+ onChange?.(newVal, {
1989
+ source: "custom-panel"
1990
+ });
1991
+ const newCtx = typeService.getTypeBySchema(newVal)?.typeCascaderConfig?.generateInitCtx?.(newVal) || {};
1992
+ onContextChange(newCtx);
1993
+ }
1994
+ }) || null));
1995
+ });
1996
+
1997
+ // src/components/type-selector/cascader-v2/trigger.tsx
1998
+ import React15, { useMemo as useMemo8, useState as useState7 } from "react";
1999
+ import classNames3 from "classnames";
2000
+ import { Input as Input3 } from "@douyinfe/semi-ui";
2001
+ import { IconChevronDown } from "@douyinfe/semi-icons";
2002
+
2003
+ // src/components/type-selector/hooks/hot-key.ts
2004
+ import { useMemo as useMemo7 } from "react";
2005
+ var useTypeSelectorHotKey = (selector) => {
2006
+ const hotKeyConfig = useMemo7(() => {
2007
+ const res = [
2008
+ {
2009
+ matcher: (e) => e.key === "Enter",
2010
+ callback: () => {
2011
+ selector.current?.selectFocusItem();
2012
+ }
2013
+ },
2014
+ {
2015
+ matcher: (e) => e.key === "ArrowUp",
2016
+ callback: () => {
2017
+ selector.current?.moveFocusItemUp();
2018
+ },
2019
+ preventDefault: true
2020
+ },
2021
+ {
2022
+ matcher: (e) => e.key === "ArrowLeft",
2023
+ callback: () => {
2024
+ selector.current?.moveFocusItemLeft();
2025
+ },
2026
+ preventDefault: true
2027
+ },
2028
+ {
2029
+ matcher: (e) => e.key === "ArrowRight",
2030
+ callback: () => {
2031
+ selector.current?.moveFocusItemRight();
2032
+ },
2033
+ preventDefault: true
2034
+ },
2035
+ {
2036
+ matcher: (e) => e.key === "ArrowDown",
2037
+ callback: () => {
2038
+ selector.current?.moveFocusItemDown();
2039
+ },
2040
+ preventDefault: true
2041
+ }
2042
+ ];
2043
+ return res;
2044
+ }, []);
2045
+ return hotKeyConfig;
2046
+ };
2047
+
2048
+ // src/components/type-selector/cascader-v2/trigger.tsx
2049
+ var Trigger = ({
2050
+ value: originValue,
2051
+ ctx,
2052
+ typeSelectorRef,
2053
+ triggerRef,
2054
+ searchValue,
2055
+ onSearchChange
2056
+ }) => {
2057
+ const typeService = useTypeDefinitionManager();
2058
+ const value = useMemo8(() => {
2059
+ if (!originValue) {
2060
+ return;
2061
+ }
2062
+ const type = typeService.getTypeBySchema(originValue);
2063
+ return type?.getStringValueByTypeSchema?.(originValue) || "";
2064
+ }, [originValue]);
2065
+ const [focus, setFocus] = useState7(false);
2066
+ const hotkeys = useTypeSelectorHotKey(typeSelectorRef);
2067
+ const reverseLabel = useMemo8(() => {
2068
+ if (!value || !originValue) {
2069
+ return;
2070
+ }
2071
+ const def = typeService.getTypeBySchema(originValue);
2072
+ return def ? def.getDisplayLabel(originValue) : /* @__PURE__ */ React15.createElement(React15.Fragment, null, value);
2073
+ }, [originValue, value]);
2074
+ return /* @__PURE__ */ React15.createElement(
2075
+ StyledFullContainer,
2076
+ {
2077
+ ref: triggerRef,
2078
+ className: classNames3(
2079
+ "semi-cascader semi-cascader-focus semi-cascader-single semi-cascader-filterable"
2080
+ )
2081
+ },
2082
+ /* @__PURE__ */ React15.createElement(TriggerGlobalStyle, null),
2083
+ /* @__PURE__ */ React15.createElement("div", { className: "semi-cascader-selection" }, /* @__PURE__ */ React15.createElement("div", { className: "semi-cascader-search-wrapper" }, !searchValue && /* @__PURE__ */ React15.createElement(
2084
+ TriggerText,
2085
+ {
2086
+ style: {
2087
+ opacity: focus ? 0.5 : 1
2088
+ },
2089
+ className: classNames3("semi-cascader-selection-text-inactive")
2090
+ },
2091
+ /* @__PURE__ */ React15.createElement(React15.Fragment, null, reverseLabel)
2092
+ ), /* @__PURE__ */ React15.createElement("div", { className: "semi-input-wrapper semi-input-wrapper-focus semi-input-wrapper-default" }, /* @__PURE__ */ React15.createElement(
2093
+ Input3,
2094
+ {
2095
+ autoFocus: true,
2096
+ onFocus: () => {
2097
+ setFocus(true);
2098
+ },
2099
+ onKeyDown: (e) => {
2100
+ const hotKey = hotkeys.find((item) => item.matcher(e));
2101
+ hotKey?.callback();
2102
+ if (hotKey?.preventDefault) {
2103
+ e.preventDefault();
2104
+ }
2105
+ },
2106
+ value: searchValue,
2107
+ onChange: (newVal) => {
2108
+ onSearchChange(newVal);
2109
+ },
2110
+ className: "semi-cascader-input",
2111
+ onBlur: () => {
2112
+ setFocus(false);
2113
+ }
2114
+ }
2115
+ )))),
2116
+ /* @__PURE__ */ React15.createElement("div", { className: "semi-cascader-arrow" }, /* @__PURE__ */ React15.createElement(IconChevronDown, null))
2117
+ );
2118
+ };
2119
+
2120
+ // src/components/type-selector/cascader-v2/index.tsx
2121
+ var CascaderV2 = (props) => {
2122
+ const {
2123
+ triggerRender,
2124
+ disabled,
2125
+ defaultOpen,
2126
+ onInit,
2127
+ value,
2128
+ onDropdownVisibleChange,
2129
+ getPopupContainer = () => document.body
2130
+ } = props;
2131
+ const triggerRef = useRef3(null);
2132
+ const typeSelectorRef = useRef3(null);
2133
+ const [searchValue, setSearchValue] = useState8("");
2134
+ const typeService = useTypeDefinitionManager();
2135
+ useEffect6(() => {
2136
+ if (typeSelectorRef.current) {
2137
+ onInit?.(typeSelectorRef.current);
2138
+ }
2139
+ }, [typeSelectorRef.current, onInit]);
2140
+ const [rePosKey, setReposKey] = useState8(0);
2141
+ const [context, setContext] = useState8(
2142
+ value && typeService.getTypeBySchema(value)?.typeCascaderConfig?.generateInitCtx?.(value) || {}
2143
+ );
2144
+ const [visible, setVisible] = useState8(defaultOpen);
2145
+ if (disabled) {
2146
+ return /* @__PURE__ */ React16.createElement(React16.Fragment, null, triggerRender ? /* @__PURE__ */ React16.createElement(CustomCascaderContainer, null, triggerRender()) : /* @__PURE__ */ React16.createElement(CascaderContainer, null, /* @__PURE__ */ React16.createElement(
2147
+ Trigger,
2148
+ {
2149
+ typeSelectorRef,
2150
+ triggerRef,
2151
+ searchValue,
2152
+ onSearchChange: setSearchValue,
2153
+ ctx: context,
2154
+ ...props
2155
+ }
2156
+ )));
2157
+ }
2158
+ return /* @__PURE__ */ React16.createElement(React16.Fragment, null, /* @__PURE__ */ React16.createElement(
2159
+ Popover,
2160
+ {
2161
+ rePosKey,
2162
+ visible,
2163
+ onVisibleChange: (v) => {
2164
+ setVisible(v);
2165
+ if (onDropdownVisibleChange) {
2166
+ onDropdownVisibleChange(v);
2167
+ }
2168
+ if (v) {
2169
+ setReposKey((key) => key + 1);
2170
+ }
2171
+ },
2172
+ autoAdjustOverflow: true,
2173
+ trigger: "click",
2174
+ position: "bottomLeft",
2175
+ getPopupContainer,
2176
+ content: !searchValue ? /* @__PURE__ */ React16.createElement(
2177
+ TypeCascader,
2178
+ {
2179
+ ref: typeSelectorRef,
2180
+ onContextChange: setContext,
2181
+ onRePos: () => setReposKey((pre) => pre + 1),
2182
+ ...props
2183
+ }
2184
+ ) : /* @__PURE__ */ React16.createElement(
2185
+ TypeSearchPanel,
2186
+ {
2187
+ onSearchChange: setSearchValue,
2188
+ ref: typeSelectorRef,
2189
+ triggerRef,
2190
+ query: searchValue,
2191
+ ...props
2192
+ }
2193
+ )
2194
+ },
2195
+ triggerRender ? /* @__PURE__ */ React16.createElement(CustomCascaderContainer, null, triggerRender()) : /* @__PURE__ */ React16.createElement(CascaderContainer, null, /* @__PURE__ */ React16.createElement(
2196
+ Trigger,
2197
+ {
2198
+ triggerRef,
2199
+ searchValue,
2200
+ onSearchChange: setSearchValue,
2201
+ typeSelectorRef,
2202
+ ctx: context,
2203
+ ...props
2204
+ }
2205
+ ))
2206
+ ));
2207
+ };
2208
+
2209
+ // src/components/type-selector/index.tsx
2210
+ var TypeSelector = (props) => {
2211
+ const [init, setInit] = useState9(false);
2212
+ return /* @__PURE__ */ React17.createElement(
2213
+ TypeEditorProvider,
2214
+ {
2215
+ typeRegistryCreators: props.typeRegistryCreators,
2216
+ onInit: () => setInit(true)
2217
+ },
2218
+ init ? /* @__PURE__ */ React17.createElement(CascaderV2, { ...props }) : /* @__PURE__ */ React17.createElement(React17.Fragment, null)
2219
+ );
2220
+ };
2221
+
2222
+ // src/components/type-editor/columns/type.tsx
2223
+ var ViewRender2 = ({ rowData, onEditMode }) => {
2224
+ const typeService = useTypeDefinitionManager();
2225
+ const disabled = useDisabled("type" /* Type */, rowData);
2226
+ const [refresh, setRefresh] = useState10(0);
2227
+ useEffect7(() => {
2228
+ typeService.onTypeRegistryChange(() => {
2229
+ setRefresh((v) => v + 1);
2230
+ });
2231
+ }, [typeService]);
2232
+ const typeConfig = useMemo9(() => typeService.getTypeBySchema(rowData.self), [refresh, rowData]);
2233
+ const unknownNode = /* @__PURE__ */ React18.createElement(BaseIcon, null, /* @__PURE__ */ React18.createElement(IconHelpCircle, { style: { marginRight: 4 } }), "Unknown");
2234
+ return disabled ? /* @__PURE__ */ React18.createElement(React18.Fragment, null, /* @__PURE__ */ React18.createElement(TypeDisableViewContainer, null, /* @__PURE__ */ React18.createElement(Tooltip3, { content: disabled }, typeConfig?.getDisplayLabel?.(rowData) || unknownNode))) : /* @__PURE__ */ React18.createElement(
2235
+ KeyViewContainer,
2236
+ {
2237
+ onClick: () => {
2238
+ onEditMode();
2239
+ }
2240
+ },
2241
+ typeConfig?.getDisplayLabel?.(rowData) || unknownNode
2242
+ );
2243
+ };
2244
+ var setCellValue = (rowData, newData) => {
2245
+ const othersProps = pick(rowData.self, ["required", "description", "flow"]);
2246
+ if (rowData.parent?.properties) {
2247
+ rowData.parent.properties[rowData.key] = {
2248
+ ...newData,
2249
+ ...othersProps
2250
+ };
2251
+ }
2252
+ };
2253
+ var EditRender2 = ({
2254
+ rowData,
2255
+ onChange,
2256
+ typeEditor,
2257
+ onViewMode
2258
+ }) => {
2259
+ const [value, setValue] = useState10(rowData.self);
2260
+ const typeService = useTypeDefinitionManager();
2261
+ return /* @__PURE__ */ React18.createElement(KeyEditorContainer, null, /* @__PURE__ */ React18.createElement(
2262
+ TypeSelector,
2263
+ {
2264
+ value,
2265
+ typeRegistryCreators: typeEditor.typeRegistryCreators,
2266
+ disableTypes: rowData.extraConfig?.customDisabledTypes,
2267
+ onDropdownVisibleChange: (vis) => {
2268
+ if (!vis) {
2269
+ onViewMode();
2270
+ }
2271
+ },
2272
+ onChange: (newData, ctx) => {
2273
+ if (!newData) {
2274
+ return;
2275
+ }
2276
+ setCellValue(rowData, newData);
2277
+ setValue(newData);
2278
+ onChange();
2279
+ let unClose = false;
2280
+ typeEditorUtils.traverseIJsonSchema(newData, (type) => {
2281
+ const def = typeService.getTypeBySchema(type);
2282
+ if (def?.typeCascaderConfig?.unClosePanelAfterSelect) {
2283
+ unClose = true;
2284
+ }
2285
+ });
2286
+ if (ctx.source === "type-selector" && !unClose) {
2287
+ onViewMode();
2288
+ }
2289
+ },
2290
+ defaultOpen: true,
2291
+ onBlur: () => {
2292
+ onViewMode();
2293
+ }
2294
+ }
2295
+ ));
2296
+ };
2297
+ var typeColumnConfig = {
2298
+ type: "type" /* Type */,
2299
+ label: "Type",
2300
+ width: 20,
2301
+ viewRender: ViewRender2,
2302
+ shortcuts: {
2303
+ onTab: ({ typeEditor }) => {
2304
+ typeEditor.moveActivePosToNextItem();
2305
+ },
2306
+ onCopy: (ctx) => {
2307
+ const {
2308
+ typeEditor: { typeDefinition, clipboard },
2309
+ rowData
2310
+ } = ctx;
2311
+ const config = typeDefinition.getTypeBySchema(rowData.self);
2312
+ if (config) {
2313
+ const optionValue = config.getStringValueByTypeSchema?.(rowData.self);
2314
+ const type = optionValue && config.getTypeSchemaByStringValue ? config.getTypeSchemaByStringValue(optionValue) : config.getDefaultSchema();
2315
+ type.properties = rowData.properties;
2316
+ type.required = rowData.required;
2317
+ clipboard.writeData(JSON.stringify(type));
2318
+ Toast.success("Copy type success!");
2319
+ } else {
2320
+ Toast.error("Copy type failed: this type undefined");
2321
+ }
2322
+ },
2323
+ onPaste: (ctx) => {
2324
+ const {
2325
+ typeEditor: { typeDefinition, clipboard, onChange },
2326
+ rowData
2327
+ } = ctx;
2328
+ clipboard.readData().then((data) => {
2329
+ const parseData = typeEditorUtils.jsonParse(data);
2330
+ const originIndex = rowData.extra?.index || 0;
2331
+ const config = parseData && typeDefinition.getTypeBySchema(parseData);
2332
+ if (config && typeof parseData === "object") {
2333
+ typeEditorUtils.fixFlowIndex(parseData);
2334
+ if (parseData.extra) {
2335
+ parseData.extra.index = originIndex;
2336
+ }
2337
+ setCellValue(rowData, parseData);
2338
+ onChange();
2339
+ } else {
2340
+ Toast.warning("Please paste the correct type schema!");
2341
+ }
2342
+ });
2343
+ }
2344
+ },
2345
+ editRender: EditRender2
2346
+ };
2347
+
2348
+ // src/components/type-editor/columns/required.tsx
2349
+ import React19 from "react";
2350
+ import { Checkbox, Toast as Toast2, Tooltip as Tooltip4 } from "@douyinfe/semi-ui";
2351
+ var setCellValue2 = (rowData) => {
2352
+ const { parent } = rowData;
2353
+ if (!parent) {
2354
+ return;
2355
+ }
2356
+ if (!parent.required) {
2357
+ parent.required = [];
2358
+ }
2359
+ const idx = parent.required.findIndex((key) => key === rowData.key);
2360
+ if (idx !== -1) {
2361
+ parent.required.splice(idx, 1);
2362
+ } else {
2363
+ parent.required.push(rowData.key);
2364
+ }
2365
+ };
2366
+ var ViewRender3 = ({
2367
+ rowData,
2368
+ onChange,
2369
+ onEditMode
2370
+ }) => {
2371
+ const disabled = useDisabled("required" /* Required */, rowData);
2372
+ const child = /* @__PURE__ */ React19.createElement(
2373
+ Checkbox,
2374
+ {
2375
+ disabled: !!disabled,
2376
+ checked: !!rowData.isRequired,
2377
+ onChange: () => {
2378
+ setCellValue2(rowData);
2379
+ onChange();
2380
+ onEditMode();
2381
+ }
2382
+ }
2383
+ );
2384
+ return /* @__PURE__ */ React19.createElement(CenterContainer, { onClick: !disabled ? () => onEditMode() : void 0 }, disabled ? /* @__PURE__ */ React19.createElement(Tooltip4, { content: disabled }, child) : child);
2385
+ };
2386
+ var requiredColumnConfig = {
2387
+ type: "required" /* Required */,
2388
+ label: "Required",
2389
+ width: 11,
2390
+ viewRender: ViewRender3,
2391
+ shortcuts: {
2392
+ onEnter: ({ onChange, rowData, typeEditor }) => {
2393
+ setCellValue2(rowData);
2394
+ onChange();
2395
+ typeEditor.moveActivePosToNextLine();
2396
+ },
2397
+ onTab: ({ typeEditor }) => {
2398
+ typeEditor.moveActivePosToNextItem();
2399
+ },
2400
+ onCopy: (ctx) => {
2401
+ const {
2402
+ rowData,
2403
+ typeEditor: { clipboard }
2404
+ } = ctx;
2405
+ clipboard.writeData(
2406
+ JSON.stringify({
2407
+ required: rowData.isRequired
2408
+ })
2409
+ );
2410
+ Toast2.success("Copy required success!");
2411
+ },
2412
+ onPaste: (ctx) => {
2413
+ const {
2414
+ typeEditor: { clipboard, onChange },
2415
+ rowData
2416
+ } = ctx;
2417
+ clipboard.readData().then((data) => {
2418
+ const parseData = typeEditorUtils.jsonParse(data);
2419
+ const disabled = (rowData.disableEditColumn || []).find(
2420
+ (r) => r.column === "required" /* Required */
2421
+ );
2422
+ if (disabled) {
2423
+ Toast2.warning("The current cell does not support editing!");
2424
+ return;
2425
+ }
2426
+ if (parseData && typeof parseData === "object" && parseData.required !== void 0) {
2427
+ const { parent } = rowData;
2428
+ if (!parent) {
2429
+ return;
2430
+ }
2431
+ if (!parent.required) {
2432
+ parent.required = [];
2433
+ }
2434
+ const idx = parent.required.findIndex((key) => key === rowData.key);
2435
+ const originRequired = idx !== -1;
2436
+ if (originRequired !== parseData.required) {
2437
+ if (idx !== -1) {
2438
+ parent.required.splice(idx, 1);
2439
+ } else {
2440
+ parent.required.push(rowData.key);
2441
+ }
2442
+ onChange();
2443
+ }
2444
+ } else {
2445
+ Toast2.warning("Please paste the correct info!");
2446
+ }
2447
+ });
2448
+ },
2449
+ onDown: (ctx) => {
2450
+ ctx.typeEditor.moveActivePosToNextLine();
2451
+ },
2452
+ onLeft: (ctx) => {
2453
+ ctx.typeEditor.moveActivePosToLastColumn();
2454
+ },
2455
+ onUp: (ctx) => {
2456
+ ctx.typeEditor.moveActivePosToLastLine();
2457
+ },
2458
+ onRight: (ctx) => {
2459
+ ctx.typeEditor.moveActivePosToNextColumn();
2460
+ }
2461
+ }
2462
+ };
2463
+
2464
+ // src/components/type-editor/columns/private.tsx
2465
+ import React20 from "react";
2466
+ import { Checkbox as Checkbox2, Toast as Toast3, Tooltip as Tooltip5 } from "@douyinfe/semi-ui";
2467
+ var setCellValue3 = (rowData) => {
2468
+ if (!rowData.extra) {
2469
+ rowData.extra = {};
2470
+ }
2471
+ rowData.extra.private = !rowData.extra.private;
2472
+ };
2473
+ var ViewRender4 = ({
2474
+ rowData,
2475
+ onChange,
2476
+ onEditMode
2477
+ }) => {
2478
+ const disabled = useDisabled("required" /* Required */, rowData);
2479
+ const child = /* @__PURE__ */ React20.createElement(
2480
+ Checkbox2,
2481
+ {
2482
+ disabled: !!disabled,
2483
+ checked: !!rowData.extra?.private,
2484
+ onChange: () => {
2485
+ setCellValue3(rowData);
2486
+ onChange();
2487
+ onEditMode();
2488
+ }
2489
+ }
2490
+ );
2491
+ return /* @__PURE__ */ React20.createElement(CenterContainer, { onClick: !disabled ? () => onEditMode() : void 0 }, disabled ? /* @__PURE__ */ React20.createElement(Tooltip5, { content: disabled }, child) : child);
2492
+ };
2493
+ var privateColumnConfig = {
2494
+ type: "private" /* Private */,
2495
+ label: "Private",
2496
+ width: 11,
2497
+ viewRender: ViewRender4,
2498
+ info: () => "Private under the current project.",
2499
+ shortcuts: {
2500
+ onEnter: ({ onChange, rowData, typeEditor }) => {
2501
+ setCellValue3(rowData);
2502
+ onChange();
2503
+ typeEditor.moveActivePosToNextLine();
2504
+ },
2505
+ onTab: ({ typeEditor }) => {
2506
+ typeEditor.moveActivePosToNextItem();
2507
+ },
2508
+ onCopy: (ctx) => {
2509
+ const {
2510
+ rowData,
2511
+ typeEditor: { clipboard }
2512
+ } = ctx;
2513
+ clipboard.writeData(
2514
+ JSON.stringify({
2515
+ private: !!rowData.extra?.private
2516
+ })
2517
+ );
2518
+ Toast3.success("Copy required success!");
2519
+ },
2520
+ onPaste: (ctx) => {
2521
+ const {
2522
+ typeEditor: { clipboard, onChange },
2523
+ rowData
2524
+ } = ctx;
2525
+ clipboard.readData().then((data) => {
2526
+ const parseData = typeEditorUtils.jsonParse(data);
2527
+ const disabled = (rowData.disableEditColumn || []).find(
2528
+ (r) => r.column === "private" /* Private */
2529
+ );
2530
+ if (disabled) {
2531
+ Toast3.warning("The current cell does not support editing!");
2532
+ return;
2533
+ }
2534
+ if (parseData && typeof parseData === "object" && parseData.private !== void 0) {
2535
+ if (!rowData.extra) {
2536
+ rowData.extra = {};
2537
+ }
2538
+ rowData.extra.private = parseData.private;
2539
+ onChange();
2540
+ } else {
2541
+ Toast3.warning("Please paste the correct info!");
2542
+ }
2543
+ });
2544
+ },
2545
+ onDown: (ctx) => {
2546
+ ctx.typeEditor.moveActivePosToNextLine();
2547
+ },
2548
+ onLeft: (ctx) => {
2549
+ ctx.typeEditor.moveActivePosToLastColumn();
2550
+ },
2551
+ onUp: (ctx) => {
2552
+ ctx.typeEditor.moveActivePosToLastLine();
2553
+ },
2554
+ onRight: (ctx) => {
2555
+ ctx.typeEditor.moveActivePosToNextColumn();
2556
+ }
2557
+ }
2558
+ };
2559
+
2560
+ // src/components/type-editor/columns/operate.tsx
2561
+ import React22 from "react";
2562
+ import { pick as pick2 } from "@flowgram.ai/utils";
2563
+ import toast from "@douyinfe/semi-ui/lib/es/toast";
2564
+ import { Toast as Toast5, Tooltip as Tooltip6 } from "@douyinfe/semi-ui";
2565
+ import { IconCopy, IconCopyAdd, IconDelete } from "@douyinfe/semi-icons";
2566
+
2567
+ // src/components/type-editor/hooks/type-edit.ts
2568
+ import { useCallback as useCallback5 } from "react";
2569
+ import { Toast as Toast4 } from "@douyinfe/semi-ui";
2570
+
2571
+ // src/components/type-editor/hooks/paste-data.ts
2572
+ import { useEffect as useEffect8, useMemo as useMemo10, useState as useState11 } from "react";
2573
+ var usePasteData = () => {
2574
+ const clipboard = useService(ClipboardService);
2575
+ const [pasteData, setPasteData] = useState11({
2576
+ type: "invalid"
2577
+ });
2578
+ const typeDefinition = useTypeDefinitionManager();
2579
+ const pasteDataFormate = useMemo10(
2580
+ () => (data) => {
2581
+ const parseData = typeEditorUtils.jsonParse(data);
2582
+ if (!parseData || typeof parseData !== "object") {
2583
+ return {
2584
+ type: "invalid"
2585
+ };
2586
+ }
2587
+ if (Array.isArray(parseData)) {
2588
+ const isValid = parseData.every((item) => {
2589
+ const config = typeDefinition.getTypeBySchema(item);
2590
+ return !!config;
2591
+ });
2592
+ if (isValid) {
2593
+ return {
2594
+ type: "multiple",
2595
+ value: parseData
2596
+ };
2597
+ } else {
2598
+ return {
2599
+ type: "invalid"
2600
+ };
2601
+ }
2602
+ } else {
2603
+ const config = typeDefinition.getTypeBySchema(parseData);
2604
+ if (config) {
2605
+ return {
2606
+ type: "single",
2607
+ value: parseData
2608
+ };
2609
+ } else {
2610
+ return {
2611
+ type: "invalid"
2612
+ };
2613
+ }
2614
+ }
2615
+ },
2616
+ [typeDefinition]
2617
+ );
2618
+ useEffect8(() => {
2619
+ clipboard.readData().then(
2620
+ (v) => {
2621
+ if (v !== void 0) {
2622
+ setPasteData(pasteDataFormate(v));
2623
+ }
2624
+ },
2625
+ (error) => {
2626
+ }
2627
+ );
2628
+ const dispose = clipboard.onClipboardChanged((newData) => {
2629
+ setPasteData(pasteDataFormate(newData));
2630
+ });
2631
+ return () => {
2632
+ dispose.dispose();
2633
+ };
2634
+ }, [pasteDataFormate]);
2635
+ return {
2636
+ pasteDataFormate,
2637
+ pasteData
2638
+ };
2639
+ };
2640
+
2641
+ // src/components/type-editor/hooks/type-edit.ts
2642
+ var useAddType = (rowData, onChange) => {
2643
+ const typeEditor = useService(TypeEditorService);
2644
+ const typeService = useTypeDefinitionManager();
2645
+ const config = typeService.getTypeBySchema(rowData.self);
2646
+ const handleAddType = useCallback5(
2647
+ (e) => {
2648
+ if (!config) {
2649
+ return;
2650
+ }
2651
+ const currentSchema = rowData.self;
2652
+ if (currentSchema) {
2653
+ let index = -1;
2654
+ const parent = config.getPropertiesParent?.(currentSchema);
2655
+ if (!parent) {
2656
+ return false;
2657
+ }
2658
+ if (!parent.properties) {
2659
+ parent.properties = {};
2660
+ }
2661
+ Object.values(parent.properties).forEach((val) => {
2662
+ if (!val.extra) {
2663
+ val.extra = {
2664
+ index: 0
2665
+ };
2666
+ }
2667
+ index = Math.max(index, val.extra?.index || 0);
2668
+ });
2669
+ const [key, schema] = typeEditorUtils.genNewTypeSchema(index + 1);
2670
+ parent.properties[key] = schema;
2671
+ const dataSource = typeEditor.getDataSource();
2672
+ let addIndex = rowData.index + 1;
2673
+ for (let i = rowData.index + 1, len = dataSource.length; i < len; i++) {
2674
+ if (dataSource[i].level > rowData.level) {
2675
+ addIndex++;
2676
+ } else {
2677
+ break;
2678
+ }
2679
+ }
2680
+ const newPos = {
2681
+ x: 0,
2682
+ y: addIndex
2683
+ };
2684
+ onChange();
2685
+ typeEditor.setActivePos(newPos);
2686
+ }
2687
+ e.stopPropagation();
2688
+ e.preventDefault();
2689
+ },
2690
+ [rowData, config, onChange]
2691
+ );
2692
+ return handleAddType;
2693
+ };
2694
+ var usePasteAddType = (rowData, onChange, onPaste) => {
2695
+ const typeService = useTypeDefinitionManager();
2696
+ const clipboard = useService(ClipboardService);
2697
+ const { pasteDataFormate } = usePasteData();
2698
+ const handlePasteAddType = useCallback5(
2699
+ (e) => {
2700
+ clipboard.readData().then((data) => {
2701
+ const parseData = pasteDataFormate(data);
2702
+ if (parseData.type === "invalid") {
2703
+ Toast4.warning("Please paste the correct type schema!");
2704
+ e.stopPropagation();
2705
+ e.preventDefault();
2706
+ return;
2707
+ }
2708
+ const currentSchema = rowData.self;
2709
+ let index = -1;
2710
+ const pasteDataItems = parseData.type === "single" ? [parseData.value] : [...parseData.value];
2711
+ const config = typeService.getTypeBySchema(currentSchema);
2712
+ const parent = config?.getPropertiesParent?.(currentSchema);
2713
+ if (!parent) {
2714
+ return;
2715
+ }
2716
+ if (!parent.properties) {
2717
+ parent.properties = {};
2718
+ }
2719
+ Object.values(parent.properties).forEach((val) => {
2720
+ if (!val.extra) {
2721
+ val.extra = {
2722
+ index: 0
2723
+ };
2724
+ }
2725
+ index = Math.max(index, val.extra.index || 0);
2726
+ });
2727
+ pasteDataItems.forEach((item) => {
2728
+ let itemKey = item?.extra?.key || typeEditorUtils.genEmptyKey();
2729
+ while (parent.properties[itemKey]) {
2730
+ itemKey = `${itemKey}__copy`;
2731
+ }
2732
+ if (!item?.extra?.value) {
2733
+ delete item.extra;
2734
+ }
2735
+ item.extra = { index: ++index };
2736
+ if (onPaste) {
2737
+ item = onPaste(item) || item;
2738
+ }
2739
+ parent.properties[itemKey] = item;
2740
+ });
2741
+ onChange();
2742
+ });
2743
+ e.stopPropagation();
2744
+ e.preventDefault();
2745
+ },
2746
+ [rowData, onChange]
2747
+ );
2748
+ return handlePasteAddType;
2749
+ };
2750
+ var useRemoveType = (rowData, onChange) => {
2751
+ const typeEditorService = useService(TypeEditorService);
2752
+ return useCallback5(() => {
2753
+ const { parent } = rowData;
2754
+ if (!parent) {
2755
+ return;
2756
+ }
2757
+ const { properties = {} } = parent;
2758
+ delete properties[rowData.key];
2759
+ typeEditorUtils.sortProperties(rowData.parent);
2760
+ if (typeEditorService.activePos.y === rowData.index) {
2761
+ typeEditorService.clearActivePos();
2762
+ }
2763
+ typeEditorService.refreshErrorMsgAfterRemove(rowData.index);
2764
+ onChange();
2765
+ }, [onChange, rowData]);
2766
+ };
2767
+
2768
+ // src/components/type-editor/hooks/error-cell.ts
2769
+ import { useMemo as useMemo11 } from "react";
2770
+
2771
+ // src/components/type-editor/hooks/active-pos.ts
2772
+ import { useEffect as useEffect9, useState as useState12 } from "react";
2773
+ var useActivePos = () => {
2774
+ const typeEditorService = useService(TypeEditorService);
2775
+ const [activePos, setActivePos] = useState12(typeEditorService.activePos);
2776
+ useEffect9(() => {
2777
+ const dispose = typeEditorService.onActivePosChange.event((v) => {
2778
+ setActivePos(v);
2779
+ });
2780
+ return () => {
2781
+ dispose.dispose();
2782
+ };
2783
+ }, []);
2784
+ return activePos;
2785
+ };
2786
+
2787
+ // src/components/type-editor/hooks/error-cell.ts
2788
+ var useEditCellErrorMsg = (pos) => {
2789
+ const typeEditor = useService(TypeEditorService);
2790
+ const { data: errorMsgs } = useMonitorData(typeEditor.errorMsgs);
2791
+ const msg = useMemo11(
2792
+ () => errorMsgs?.find((v) => v.pos.x === pos.x && v.pos.y === pos.y)?.msg,
2793
+ [pos, errorMsgs]
2794
+ );
2795
+ return msg;
2796
+ };
2797
+ var useViewCellErrorMsg = (rowData, config, pos) => {
2798
+ const activePos = useActivePos();
2799
+ const res = useMemo11(
2800
+ () => (activePos.x !== pos.x || activePos.y !== pos.y) && config.validateCell ? config.validateCell(rowData, rowData.extraConfig) : void 0,
2801
+ [rowData, config, activePos, pos]
2802
+ );
2803
+ return res;
2804
+ };
2805
+ var useHasErrorCell = (rowData, typeEditor) => {
2806
+ const res = useMemo11(() => {
2807
+ const configs = typeEditor.columnViewConfig.map((v) => typeEditor.getConfigByType(v.type));
2808
+ return configs.map(
2809
+ (config) => config?.validateCell ? config.validateCell(rowData, rowData.extraConfig) : void 0
2810
+ ).filter(Boolean).length !== 0;
2811
+ }, [rowData, typeEditor]);
2812
+ return res;
2813
+ };
2814
+
2815
+ // src/components/type-editor/columns/operate.tsx
2816
+ var pasteTooltipsMap = {
2817
+ invalid: "Please confirm whether the clipboard value is correct",
2818
+ multiple: "Multiple fields are not supported to be pasted into this field.",
2819
+ single: void 0
2820
+ };
2821
+ var setCellValue4 = (rowData, newData, onPaste) => {
2822
+ const othersProps = pick2(rowData.self, ["required", "description", "flow", "extra"]);
2823
+ if (rowData.parent?.properties) {
2824
+ const { parent } = rowData;
2825
+ if (newData.extra) {
2826
+ let { key } = newData.extra;
2827
+ const { required } = newData.extra;
2828
+ while (parent.properties[key] && key !== rowData.key) {
2829
+ key = `${key}__copy`;
2830
+ }
2831
+ delete parent.properties[rowData.key];
2832
+ delete newData.extra;
2833
+ let newPasteData = {
2834
+ ...newData,
2835
+ ...othersProps
2836
+ };
2837
+ if (onPaste) {
2838
+ newPasteData = onPaste(newPasteData) || newPasteData;
2839
+ }
2840
+ parent.properties[key] = newPasteData;
2841
+ if (!parent.required) {
2842
+ parent.required = [];
2843
+ }
2844
+ const idx = parent.required.findIndex((v) => v === rowData.key);
2845
+ if (idx !== -1) {
2846
+ parent.required.splice(idx, 1);
2847
+ }
2848
+ if (required) {
2849
+ parent.required.push(key);
2850
+ }
2851
+ } else {
2852
+ let newPasteData = {
2853
+ ...newData,
2854
+ ...othersProps
2855
+ };
2856
+ if (onPaste) {
2857
+ newPasteData = onPaste(newPasteData) || newPasteData;
2858
+ }
2859
+ parent.properties[rowData.key] = newPasteData;
2860
+ }
2861
+ }
2862
+ };
2863
+ var operateColumnConfig = {
2864
+ type: "operate" /* Operate */,
2865
+ label: "Operate",
2866
+ width: 11,
2867
+ focusable: false,
2868
+ viewRender: ({ rowData, onChange, typeEditor, onPaste }) => {
2869
+ const disabled = useDisabled("operate" /* Operate */, rowData);
2870
+ const clipboard = useService(ClipboardService);
2871
+ const { pasteData } = usePasteData();
2872
+ const typeDefinition = useTypeDefinitionManager();
2873
+ const hasError = useHasErrorCell(rowData, typeEditor);
2874
+ const handleRemove = useRemoveType(rowData, onChange);
2875
+ const pasteErrorTips = pasteTooltipsMap[pasteData.type];
2876
+ return /* @__PURE__ */ React22.createElement(CenterContainer, null, /* @__PURE__ */ React22.createElement(Tooltip6, { content: disabled || "Remove" }, /* @__PURE__ */ React22.createElement(BaseIcon, { primary: true, disabled: !!disabled }, /* @__PURE__ */ React22.createElement(
2877
+ IconDelete,
2878
+ {
2879
+ id: getComponentId("remove-field"),
2880
+ onClick: disabled ? void 0 : handleRemove,
2881
+ size: "small"
2882
+ }
2883
+ ))), /* @__PURE__ */ React22.createElement(
2884
+ Tooltip6,
2885
+ {
2886
+ content: hasError ? "The current field is incorrect and does not support copying." : "Copy this field"
2887
+ },
2888
+ /* @__PURE__ */ React22.createElement(BaseIcon, { primary: true, disabled: !!hasError }, /* @__PURE__ */ React22.createElement(
2889
+ IconCopy,
2890
+ {
2891
+ onClick: () => {
2892
+ if (hasError) {
2893
+ return;
2894
+ }
2895
+ const copyData = {
2896
+ ...rowData.self,
2897
+ extra: {
2898
+ key: rowData.key,
2899
+ required: rowData.isRequired,
2900
+ ...rowData.self.extra || {}
2901
+ }
2902
+ };
2903
+ clipboard.writeData(JSON.stringify(copyData));
2904
+ toast.success("copy this field success!");
2905
+ },
2906
+ size: "small"
2907
+ }
2908
+ ))
2909
+ ), /* @__PURE__ */ React22.createElement(
2910
+ Tooltip6,
2911
+ {
2912
+ content: disabled ? disabled : !pasteErrorTips ? "Paste field here" : pasteErrorTips
2913
+ },
2914
+ /* @__PURE__ */ React22.createElement(BaseIcon, { primary: true, disabled: !!(pasteErrorTips || disabled) }, /* @__PURE__ */ React22.createElement(
2915
+ IconCopyAdd,
2916
+ {
2917
+ size: "small",
2918
+ onClick: () => {
2919
+ if (pasteErrorTips || disabled) {
2920
+ return;
2921
+ }
2922
+ clipboard.readData().then((data) => {
2923
+ const parseData = typeEditorUtils.jsonParse(data);
2924
+ const originIndex = rowData.extra?.index || 0;
2925
+ const config = parseData && typeDefinition.getTypeBySchema(parseData);
2926
+ if (config && typeof parseData === "object") {
2927
+ typeEditorUtils.fixFlowIndex(parseData);
2928
+ parseData.extra.index = originIndex;
2929
+ setCellValue4(rowData, parseData, onPaste);
2930
+ onChange();
2931
+ } else {
2932
+ Toast5.warning("Please paste the correct type schema!");
2933
+ }
2934
+ });
2935
+ }
2936
+ }
2937
+ ))
2938
+ ));
2939
+ },
2940
+ shortcuts: {
2941
+ onEnter: ({ typeEditor }) => {
2942
+ typeEditor.moveActivePosToNextLine();
2943
+ },
2944
+ onTab: ({ typeEditor }) => {
2945
+ typeEditor.moveActivePosToNextItem();
2946
+ },
2947
+ onDown: (ctx) => {
2948
+ ctx.typeEditor.moveActivePosToNextLine();
2949
+ },
2950
+ onLeft: (ctx) => {
2951
+ ctx.typeEditor.moveActivePosToLastColumn();
2952
+ },
2953
+ onUp: (ctx) => {
2954
+ ctx.typeEditor.moveActivePosToLastLine();
2955
+ },
2956
+ onRight: (ctx) => {
2957
+ ctx.typeEditor.moveActivePosToNextColumn();
2958
+ }
2959
+ }
2960
+ };
2961
+
2962
+ // src/components/type-editor/columns/key.tsx
2963
+ import React25, { useEffect as useEffect10, useState as useState13 } from "react";
2964
+ import { Tooltip as Tooltip8 } from "@douyinfe/semi-ui";
2965
+ import { IconCopyAdd as IconCopyAdd2, IconHandle, IconPlus, IconTreeTriangleDown } from "@douyinfe/semi-icons";
2966
+
2967
+ // src/components/type-editor/indent.tsx
2968
+ import React23 from "react";
2969
+ var WidthIndent = ({ width, style = {} }) => /* @__PURE__ */ React23.createElement("div", { style: { height: "100%", flexShrink: 0, width, ...style } });
2970
+
2971
+ // src/components/type-editor/hooks/key-visible.tsx
2972
+ import React24, { useCallback as useCallback6 } from "react";
2973
+ import { Tooltip as Tooltip7 } from "@douyinfe/semi-ui";
2974
+ import { IconEyeClosed, IconEyeOpened } from "@douyinfe/semi-icons";
2975
+ var useKeyVisible = (rowData, onChange, extraConfig) => {
2976
+ const disabled = useDisabled("key" /* Key */, rowData);
2977
+ const handleVisibleChange = useCallback6(
2978
+ (e) => {
2979
+ const currentSchema = rowData.self;
2980
+ if (!currentSchema.extra) {
2981
+ currentSchema.extra = {};
2982
+ }
2983
+ currentSchema.extra.hidden = !currentSchema.extra.hidden;
2984
+ onChange();
2985
+ e.stopPropagation();
2986
+ e.preventDefault();
2987
+ },
2988
+ [rowData.self, onChange]
2989
+ );
2990
+ const disableContent = disabled || typeof extraConfig.editorVisible === "string" ? disabled || extraConfig.editorVisible : void 0;
2991
+ const visibleNode = /* @__PURE__ */ React24.createElement(React24.Fragment, null, disableContent ? /* @__PURE__ */ React24.createElement(Tooltip7, { content: disableContent }, /* @__PURE__ */ React24.createElement(BaseIcon, { disabled: true }, /* @__PURE__ */ React24.createElement(IconEyeOpened, { size: "small" }))) : rowData.extra?.hidden ? /* @__PURE__ */ React24.createElement(BaseIcon, null, /* @__PURE__ */ React24.createElement(IconEyeClosed, { onClick: handleVisibleChange, size: "small" })) : /* @__PURE__ */ React24.createElement(BaseIcon, null, /* @__PURE__ */ React24.createElement(IconEyeOpened, { onClick: handleVisibleChange, size: "small" })));
2992
+ return extraConfig.editorVisible ? visibleNode : /* @__PURE__ */ React24.createElement(React24.Fragment, null);
2993
+ };
2994
+
2995
+ // src/components/type-editor/columns/key.tsx
2996
+ var ViewRender5 = ({
2997
+ rowData,
2998
+ onEditMode,
2999
+ readonly,
3000
+ onChange,
3001
+ onPaste,
3002
+ unOpenKeys,
3003
+ onChildrenVisibleChange,
3004
+ dragSource
3005
+ }) => {
3006
+ const { extraConfig } = rowData;
3007
+ const typeService = useTypeDefinitionManager();
3008
+ const config = typeService.getTypeBySchema(rowData.self);
3009
+ const disabled = useDisabled("key" /* Key */, rowData);
3010
+ const { hiddenDrag: originHiddenDrag } = extraConfig;
3011
+ const hiddenDrag = originHiddenDrag || readonly;
3012
+ const text = /* @__PURE__ */ React25.createElement(KeyViewText, { disabled: !!disabled, ellipsis: { showTooltip: true } }, typeEditorUtils.formateKey(rowData.key));
3013
+ const visibleNode = useKeyVisible(rowData, onChange, extraConfig);
3014
+ const handleAddType = useAddType(rowData, onChange);
3015
+ const draggable = !(rowData.cannotDrag || disabled || hiddenDrag);
3016
+ const { pasteData } = usePasteData();
3017
+ const handlePasteAddType = usePasteAddType(rowData, onChange, onPaste);
3018
+ if (config && config.canAddField?.(rowData)) {
3019
+ const disabledAdd = extraConfig.disabledAdd ? extraConfig.disabledAdd(rowData) : void 0;
3020
+ return /* @__PURE__ */ React25.createElement(
3021
+ KeyViewContainer,
3022
+ {
3023
+ id: getComponentId("key-text"),
3024
+ onClick: disabled ? void 0 : () => {
3025
+ onEditMode();
3026
+ }
3027
+ },
3028
+ !hiddenDrag && /* @__PURE__ */ React25.createElement(BaseIcon, { draggable: true, disabled: !draggable }, /* @__PURE__ */ React25.createElement(IconHandle, { ref: draggable ? dragSource : void 0 })),
3029
+ /* @__PURE__ */ React25.createElement(WidthIndent, { width: rowData.level * 16 }),
3030
+ /* @__PURE__ */ React25.createElement(KeyViewContent, null, rowData.childrenCount ? /* @__PURE__ */ React25.createElement(BaseIcon, { triangle: true, isRotate: !unOpenKeys[rowData.id] }, /* @__PURE__ */ React25.createElement(
3031
+ IconTreeTriangleDown,
3032
+ {
3033
+ size: "small",
3034
+ onClick: (e) => {
3035
+ onChildrenVisibleChange(rowData.id, !unOpenKeys[rowData.id]);
3036
+ e.stopPropagation();
3037
+ }
3038
+ }
3039
+ )) : /* @__PURE__ */ React25.createElement(WidthIndent, { width: 12 }), disabled ? /* @__PURE__ */ React25.createElement("div", { style: { flex: 1 } }, /* @__PURE__ */ React25.createElement(Tooltip8, { content: disabled }, text)) : text, !readonly && /* @__PURE__ */ React25.createElement(React25.Fragment, null, disabledAdd ? /* @__PURE__ */ React25.createElement(Tooltip8, { content: disabledAdd }, /* @__PURE__ */ React25.createElement(BaseIcon, { disabled: true }, /* @__PURE__ */ React25.createElement(IconPlus, { id: getComponentId("add-field"), size: "small" }))) : /* @__PURE__ */ React25.createElement(Tooltip8, { content: "add child field" }, /* @__PURE__ */ React25.createElement(BaseIcon, null, /* @__PURE__ */ React25.createElement(
3040
+ IconPlus,
3041
+ {
3042
+ size: "small",
3043
+ onClick: handleAddType,
3044
+ id: getComponentId("add-field")
3045
+ }
3046
+ ))), disabledAdd || pasteData.type === "invalid" ? /* @__PURE__ */ React25.createElement(
3047
+ Tooltip8,
3048
+ {
3049
+ content: disabledAdd || "Please confirm whether the clipboard value is correct"
3050
+ },
3051
+ /* @__PURE__ */ React25.createElement(BaseIcon, { disabled: true }, /* @__PURE__ */ React25.createElement(IconCopyAdd2, { size: "small" }))
3052
+ ) : /* @__PURE__ */ React25.createElement(Tooltip8, { content: "paste as new child fields" }, /* @__PURE__ */ React25.createElement(BaseIcon, null, /* @__PURE__ */ React25.createElement(IconCopyAdd2, { size: "small", onClick: handlePasteAddType })))), extraConfig.editorVisible && visibleNode)
3053
+ );
3054
+ }
3055
+ return /* @__PURE__ */ React25.createElement(
3056
+ KeyViewContainer,
3057
+ {
3058
+ id: getComponentId("key-text"),
3059
+ onClick: disabled ? void 0 : () => {
3060
+ onEditMode();
3061
+ }
3062
+ },
3063
+ !hiddenDrag && /* @__PURE__ */ React25.createElement(BaseIcon, { draggable: true, disabled: !draggable }, /* @__PURE__ */ React25.createElement(IconHandle, { ref: draggable ? dragSource : void 0 })),
3064
+ /* @__PURE__ */ React25.createElement(WidthIndent, { width: (rowData.level + 1) * 16 }),
3065
+ /* @__PURE__ */ React25.createElement(KeyViewContent, null, disabled ? /* @__PURE__ */ React25.createElement(Tooltip8, { content: disabled }, text) : text, extraConfig.editorVisible && visibleNode)
3066
+ );
3067
+ };
3068
+ var validate = (value, rowData) => {
3069
+ const res = rowData.extraConfig?.customValidateName?.(value);
3070
+ const lastValue = rowData.key;
3071
+ const parentTypeSchema = rowData.parent;
3072
+ if (value !== lastValue && parentTypeSchema?.properties?.[value]) {
3073
+ return "The same key exists at the current level.";
3074
+ }
3075
+ if (res) {
3076
+ return res;
3077
+ }
3078
+ };
3079
+ var changeValue = ({
3080
+ rowData,
3081
+ value
3082
+ }) => {
3083
+ const lastValue = rowData.key;
3084
+ const parentTypeSchema = rowData.parent;
3085
+ if (value !== lastValue) {
3086
+ if (parentTypeSchema && parentTypeSchema.properties) {
3087
+ parentTypeSchema.properties[value] = parentTypeSchema.properties[lastValue];
3088
+ }
3089
+ if (parentTypeSchema?.properties) {
3090
+ delete parentTypeSchema.properties[lastValue];
3091
+ }
3092
+ }
3093
+ };
3094
+ var EditRender3 = ({
3095
+ rowData,
3096
+ onChange,
3097
+ typeEditor,
3098
+ onError,
3099
+ onFieldChange,
3100
+ onViewMode
3101
+ }) => {
3102
+ const [value, setValue] = useState13(typeEditorUtils.formateKey(rowData.key));
3103
+ useEffect10(() => {
3104
+ typeEditor.editValue = value;
3105
+ }, [typeEditor, value]);
3106
+ return /* @__PURE__ */ React25.createElement(KeyEditorContainer, null, /* @__PURE__ */ React25.createElement(
3107
+ WidthIndent,
3108
+ {
3109
+ style: { background: "var(--semi-color-fill-0)" },
3110
+ width: (rowData.level + 2) * 14 + (2 * rowData.level - 1) + (rowData.extraConfig.hiddenDrag ? -16 : 0)
3111
+ }
3112
+ ), /* @__PURE__ */ React25.createElement(
3113
+ KeyEditorInput,
3114
+ {
3115
+ id: getComponentId("key-edit"),
3116
+ onChange: (v) => {
3117
+ setValue(v);
3118
+ typeEditor.dataSourceTouchedMap[rowData.id] = true;
3119
+ const res = validate(v, rowData);
3120
+ typeEditor.setErrorMsg(typeEditor.activePos, res);
3121
+ if (onError) {
3122
+ onError(res ? [res] : []);
3123
+ }
3124
+ },
3125
+ autoFocus: true,
3126
+ onBlur: (e) => {
3127
+ const oldValue = rowData.key;
3128
+ if (value && validate(value, rowData)) {
3129
+ typeEditor.blink.update(true);
3130
+ e.stopPropagation();
3131
+ e.preventDefault();
3132
+ return;
3133
+ }
3134
+ const newVal = typeEditorUtils.deFormateKey(value, oldValue);
3135
+ changeValue({ rowData, value: newVal });
3136
+ onFieldChange && onFieldChange({
3137
+ type: "key" /* Key */,
3138
+ oldValue,
3139
+ newValue: newVal
3140
+ });
3141
+ if (onError) {
3142
+ onError([]);
3143
+ }
3144
+ onChange();
3145
+ onViewMode();
3146
+ },
3147
+ value
3148
+ }
3149
+ ));
3150
+ };
3151
+ var dealMove = ({ rowData, value, onChange, typeEditor }, cb) => {
3152
+ const validateRes = validate(value, rowData);
3153
+ if (value && validateRes) {
3154
+ typeEditor.blink.update(true);
3155
+ } else {
3156
+ changeValue({
3157
+ value: typeEditorUtils.deFormateKey(value),
3158
+ rowData
3159
+ });
3160
+ typeEditor.setErrorMsg(typeEditor.activePos);
3161
+ onChange();
3162
+ cb();
3163
+ }
3164
+ };
3165
+ var keyColumnConfig = {
3166
+ type: "key" /* Key */,
3167
+ label: "Key",
3168
+ viewRender: ViewRender5,
3169
+ width: 43,
3170
+ validateCell: (rowData, ctx) => {
3171
+ const key = typeEditorUtils.formateKey(rowData.key);
3172
+ if (!key) {
3173
+ return {
3174
+ level: "warning",
3175
+ msg: "Empty lines will not be saved."
3176
+ };
3177
+ }
3178
+ if (ctx.customValidateName) {
3179
+ const customValidateRes = ctx.customValidateName(key);
3180
+ if (customValidateRes) {
3181
+ return {
3182
+ level: "error",
3183
+ msg: customValidateRes
3184
+ };
3185
+ }
3186
+ return;
3187
+ }
3188
+ if (validate(key, rowData)) {
3189
+ return {
3190
+ level: "error",
3191
+ msg: validate(key, rowData)
3192
+ };
3193
+ }
3194
+ },
3195
+ shortcuts: {
3196
+ onEnter: (ctx) => {
3197
+ dealMove(ctx, () => {
3198
+ ctx.typeEditor.moveActivePosToNextLineWithAddLine(ctx.rowData);
3199
+ });
3200
+ },
3201
+ onTab: (ctx) => {
3202
+ dealMove(ctx, () => {
3203
+ ctx.typeEditor.moveActivePosToNextItem();
3204
+ });
3205
+ }
3206
+ },
3207
+ editRender: EditRender3
3208
+ };
3209
+
3210
+ // src/components/type-editor/columns/description.tsx
3211
+ import { useEffect as useEffect12, useState as useState15 } from "react";
3212
+ import React28 from "react";
3213
+ import { Tooltip as Tooltip9 } from "@douyinfe/semi-ui";
3214
+
3215
+ // src/components/type-editor/hooks/editor-listener.tsx
3216
+ import React27, { useEffect as useEffect11, useRef as useRef4, useState as useState14 } from "react";
3217
+
3218
+ // src/components/type-editor/hooks/hot-key.ts
3219
+ import { useMemo as useMemo12 } from "react";
3220
+ var useTypeEditorHotKey = () => {
3221
+ const typeEditor = useService(TypeEditorService);
3222
+ const operator = useService(TypeEditorOperationService);
3223
+ const hotKeyConfig = useMemo12(() => {
3224
+ const res = [
3225
+ {
3226
+ matcher: (e) => e.key === "Enter",
3227
+ callback: () => {
3228
+ typeEditor.triggerShortcutEvent("enter");
3229
+ },
3230
+ preventDefault: true
3231
+ },
3232
+ {
3233
+ matcher: (e) => e.key === "ArrowUp",
3234
+ callback: () => {
3235
+ typeEditor.triggerShortcutEvent("up");
3236
+ },
3237
+ preventDefault: true
3238
+ },
3239
+ {
3240
+ matcher: (e) => e.key === "Tab",
3241
+ callback: () => {
3242
+ typeEditor.triggerShortcutEvent("tab");
3243
+ },
3244
+ preventDefault: true
3245
+ },
3246
+ {
3247
+ matcher: (e) => e.key === "ArrowLeft",
3248
+ callback: () => {
3249
+ typeEditor.triggerShortcutEvent("left");
3250
+ }
3251
+ },
3252
+ {
3253
+ matcher: (e) => e.key === "ArrowRight",
3254
+ callback: () => {
3255
+ typeEditor.triggerShortcutEvent("right");
3256
+ }
3257
+ },
3258
+ {
3259
+ matcher: (e) => e.key === "ArrowDown",
3260
+ callback: () => {
3261
+ typeEditor.triggerShortcutEvent("down");
3262
+ },
3263
+ preventDefault: true
3264
+ },
3265
+ {
3266
+ matcher: (e) => (e.metaKey || e.ctrlKey) && e.key === "c",
3267
+ callback: () => {
3268
+ typeEditor.triggerShortcutEvent("copy");
3269
+ }
3270
+ },
3271
+ {
3272
+ matcher: (e) => (e.metaKey || e.ctrlKey) && e.key === "v",
3273
+ callback: () => {
3274
+ typeEditor.triggerShortcutEvent("paste");
3275
+ }
3276
+ },
3277
+ {
3278
+ matcher: (e) => (e.metaKey || e.ctrlKey) && e.key === "z",
3279
+ callback: () => {
3280
+ operator.undo();
3281
+ }
3282
+ },
3283
+ {
3284
+ matcher: (e) => (e.metaKey || e.ctrlKey) && e.shiftKey && e.key === "z",
3285
+ callback: () => {
3286
+ operator.redo();
3287
+ }
3288
+ }
3289
+ ];
3290
+ return res;
3291
+ }, [typeEditor]);
3292
+ return hotKeyConfig;
3293
+ };
3294
+
3295
+ // src/components/type-editor/hooks/editor-listener.tsx
3296
+ var TypeEditorListener = ({
3297
+ configs = [],
3298
+ children
3299
+ }) => {
3300
+ const dom = useRef4();
3301
+ const lastWidth = useRef4(0);
3302
+ const typeEditorService = useService(TypeEditorService);
3303
+ const [init, setInit] = useState14(false);
3304
+ useEffect11(() => {
3305
+ if (dom.current) {
3306
+ const el = dom.current;
3307
+ const resize = new ResizeObserver((entries) => {
3308
+ if (lastWidth.current === 0) {
3309
+ lastWidth.current = entries[0].contentRect.width;
3310
+ }
3311
+ if (entries[0].contentRect.width !== lastWidth.current) {
3312
+ typeEditorService.clearActivePos();
3313
+ }
3314
+ });
3315
+ resize.observe(el);
3316
+ return () => {
3317
+ resize.unobserve(el);
3318
+ };
3319
+ }
3320
+ }, [dom.current, typeEditorService]);
3321
+ useEffect11(() => {
3322
+ typeEditorService.registerConfigs(
3323
+ columnConfigs
3324
+ );
3325
+ configs.forEach(
3326
+ (config) => config.config && typeEditorService.addConfigProps(config.type, config.config)
3327
+ );
3328
+ setInit(true);
3329
+ }, [typeEditorService, configs]);
3330
+ const composition = useRef4(false);
3331
+ const hotkeys = useTypeEditorHotKey();
3332
+ return /* @__PURE__ */ React27.createElement(
3333
+ "div",
3334
+ {
3335
+ style: { width: "100%" },
3336
+ onCompositionStart: () => composition.current = true,
3337
+ onCompositionEnd: () => composition.current = false,
3338
+ onKeyDown: (e) => {
3339
+ if (composition.current) return;
3340
+ const hotKey = hotkeys.find((item) => item.matcher(e));
3341
+ hotKey?.callback();
3342
+ if (hotKey?.preventDefault) {
3343
+ e.preventDefault();
3344
+ e.stopPropagation();
3345
+ }
3346
+ },
3347
+ ref: dom
3348
+ },
3349
+ init && children
3350
+ );
3351
+ };
3352
+
3353
+ // src/components/type-editor/hooks/drag-drop.ts
3354
+ import { useDrag, useDrop } from "react-dnd";
3355
+ import { Toast as Toast6 } from "@douyinfe/semi-ui";
3356
+ var useRowDrag = (id, onChildrenVisibleChange) => {
3357
+ const [{ isDragging }, drag, preview] = useDrag(
3358
+ () => ({
3359
+ type: "node-editor-dnd",
3360
+ item: () => {
3361
+ onChildrenVisibleChange(id, true);
3362
+ return {
3363
+ id
3364
+ };
3365
+ },
3366
+ collect: (monitor) => ({
3367
+ isDragging: monitor.isDragging()
3368
+ })
3369
+ }),
3370
+ [id]
3371
+ );
3372
+ return {
3373
+ drag,
3374
+ isDragging,
3375
+ preview
3376
+ };
3377
+ };
3378
+ var useCellDrop = (rowData, index, dataSource, onChange) => {
3379
+ const typeEditor = useService(TypeEditorService);
3380
+ const typeService = useTypeDefinitionManager();
3381
+ const [{ isOver }, drop] = useDrop(
3382
+ () => ({
3383
+ accept: "node-editor-dnd",
3384
+ drop: (item) => {
3385
+ if (item.id === rowData.id) {
3386
+ typeEditor.clearDropInfo();
3387
+ return;
3388
+ }
3389
+ const dragData = dataSource[item.id];
3390
+ const definition = typeService.getTypeBySchema(rowData.self);
3391
+ if (definition) {
3392
+ const canHasChild = definition.canAddField?.(rowData.self);
3393
+ let dropParent;
3394
+ let dropIndex;
3395
+ if (canHasChild) {
3396
+ dropParent = definition.getPropertiesParent?.(rowData.self);
3397
+ dropIndex = -1;
3398
+ } else {
3399
+ dropParent = rowData.parent;
3400
+ dropIndex = (rowData.extra?.index || 0) + 0.1;
3401
+ }
3402
+ if (dropParent?.properties?.[dragData.key] && dropParent !== dragData.parent) {
3403
+ Toast6.error("drop error: there is a duplicate key in the current object");
3404
+ typeEditor.clearDropInfo();
3405
+ return;
3406
+ }
3407
+ if (dragData.parent?.properties) {
3408
+ delete dragData.parent.properties[dragData.key];
3409
+ }
3410
+ if (!dropParent.properties) {
3411
+ dropParent.properties = {};
3412
+ }
3413
+ dropParent.properties[dragData.key] = dragData.self;
3414
+ typeEditorUtils.fixFlowIndex(dragData);
3415
+ dragData.extra.index = dropIndex;
3416
+ typeEditorUtils.sortProperties(dropParent);
3417
+ typeEditorUtils.sortProperties(dragData.parent);
3418
+ onChange();
3419
+ }
3420
+ typeEditor.clearDropInfo();
3421
+ },
3422
+ hover() {
3423
+ typeEditor.setDropInfo({
3424
+ indent: rowData.level,
3425
+ index,
3426
+ rowDataId: rowData.id
3427
+ });
3428
+ },
3429
+ collect: (monitor) => ({
3430
+ isOver: monitor.isOver()
3431
+ })
3432
+ }),
3433
+ [rowData]
3434
+ );
3435
+ return {
3436
+ drop,
3437
+ isOver
3438
+ };
3439
+ };
3440
+ var useHeaderDrop = (root, dataSource, onChange) => {
3441
+ const typeEditor = useService(TypeEditorService);
3442
+ const typeService = useTypeDefinitionManager();
3443
+ const [{ isOver }, drop] = useDrop(
3444
+ () => ({
3445
+ accept: "node-editor-dnd",
3446
+ drop: (item) => {
3447
+ const dragData = dataSource[item.id];
3448
+ const definition = typeService.getTypeBySchema(root);
3449
+ if (definition) {
3450
+ const canHasChild = definition.canAddField(root);
3451
+ let dropParent;
3452
+ let dropIndex;
3453
+ if (canHasChild) {
3454
+ dropParent = definition.getPropertiesParent(root);
3455
+ dropIndex = -1;
3456
+ if (dropParent?.properties?.[dragData.key] && dropParent !== dragData.parent) {
3457
+ Toast6.error("drop error: there is a duplicate key in the current object");
3458
+ typeEditor.clearDropInfo();
3459
+ return;
3460
+ }
3461
+ if (dragData.parent?.properties) {
3462
+ delete dragData.parent.properties[dragData.key];
3463
+ }
3464
+ if (!dropParent.properties) {
3465
+ dropParent.properties = {};
3466
+ }
3467
+ dropParent.properties[dragData.key] = dragData.self;
3468
+ typeEditorUtils.fixFlowIndex(dragData);
3469
+ dragData.extra.index = dropIndex;
3470
+ typeEditorUtils.sortProperties(dropParent);
3471
+ typeEditorUtils.sortProperties(dragData.parent);
3472
+ onChange();
3473
+ }
3474
+ typeEditor.clearDropInfo();
3475
+ }
3476
+ },
3477
+ hover() {
3478
+ typeEditor.setDropInfo({
3479
+ indent: 0,
3480
+ index: -1,
3481
+ rowDataId: "header"
3482
+ });
3483
+ },
3484
+ collect: (monitor) => ({
3485
+ isOver: monitor.isOver()
3486
+ })
3487
+ }),
3488
+ [root]
3489
+ );
3490
+ return {
3491
+ drop,
3492
+ isOver
3493
+ };
3494
+ };
3495
+
3496
+ // src/components/type-editor/columns/description.tsx
3497
+ var ViewRender6 = ({ rowData, onEditMode }) => {
3498
+ const disabled = useDisabled("description" /* Description */, rowData);
3499
+ if (disabled) {
3500
+ return /* @__PURE__ */ React28.createElement(KeyViewContainer, { disabled: true }, /* @__PURE__ */ React28.createElement(Tooltip9, { content: disabled }, /* @__PURE__ */ React28.createElement(KeyViewText, null, rowData.description)));
3501
+ }
3502
+ return /* @__PURE__ */ React28.createElement(KeyViewContainer, { onClick: () => onEditMode() }, /* @__PURE__ */ React28.createElement(KeyViewText, null, rowData.description));
3503
+ };
3504
+ var EditRender4 = ({
3505
+ rowData,
3506
+ onChange,
3507
+ typeEditor,
3508
+ onViewMode
3509
+ }) => {
3510
+ const [value, setValue] = useState15(rowData.description);
3511
+ useEffect12(() => {
3512
+ typeEditor.editValue = value;
3513
+ }, [typeEditor, value]);
3514
+ useEffect12(() => {
3515
+ setValue(rowData.description);
3516
+ }, [rowData.description]);
3517
+ return /* @__PURE__ */ React28.createElement(KeyEditorContainer, null, /* @__PURE__ */ React28.createElement(
3518
+ KeyEditorInput,
3519
+ {
3520
+ onChange: setValue,
3521
+ autoFocus: true,
3522
+ onBlur: () => {
3523
+ const { self } = rowData;
3524
+ self.description = value;
3525
+ onChange();
3526
+ onViewMode();
3527
+ },
3528
+ value
3529
+ }
3530
+ ));
3531
+ };
3532
+ var descriptionColumnConfig = {
3533
+ type: "description" /* Description */,
3534
+ width: 15,
3535
+ label: "Description",
3536
+ viewRender: ViewRender6,
3537
+ shortcuts: {
3538
+ onEnter: ({ rowData, value, onChange, typeEditor }) => {
3539
+ rowData.self.description = value;
3540
+ onChange();
3541
+ typeEditor.moveActivePosToNextLineWithAddLine(rowData);
3542
+ },
3543
+ onTab: ({ rowData, value, onChange, typeEditor }) => {
3544
+ rowData.self.description = value;
3545
+ onChange();
3546
+ typeEditor.moveActivePosToNextItem();
3547
+ }
3548
+ },
3549
+ editRender: EditRender4
3550
+ };
3551
+
3552
+ // src/components/type-editor/columns/default.tsx
3553
+ import React29, { useCallback as useCallback7, useEffect as useEffect13, useMemo as useMemo13, useRef as useRef5, useState as useState16 } from "react";
3554
+ import { Tooltip as Tooltip10, Typography as Typography8 } from "@douyinfe/semi-ui";
3555
+ var useFormatValue = ({
3556
+ rowData,
3557
+ onChange,
3558
+ typeEditor
3559
+ }) => {
3560
+ const valueRef = useRef5(rowData.self.default);
3561
+ const [value, setValue] = useState16(rowData.self.default);
3562
+ const typeDefinition = useTypeDefinitionManager();
3563
+ useEffect13(() => {
3564
+ typeEditor.editValue = value;
3565
+ }, [typeEditor, value]);
3566
+ useEffect13(() => {
3567
+ setValue(rowData.self.default);
3568
+ valueRef.current = rowData.self.default;
3569
+ }, [rowData.self.default]);
3570
+ const handleSubmit = useCallback7(() => {
3571
+ rowData.self.default = valueRef.current;
3572
+ const config = typeDefinition.getTypeBySchema(rowData.self);
3573
+ if (config?.formatDefault) {
3574
+ config.formatDefault(valueRef.current, rowData.self);
3575
+ }
3576
+ const parenConfig = rowData.parent && typeDefinition.getTypeBySchema(rowData.parent);
3577
+ if (parenConfig?.formatDefault) {
3578
+ parenConfig.formatDefault(valueRef.current, rowData.parent);
3579
+ }
3580
+ onChange();
3581
+ }, [onChange, rowData, typeDefinition]);
3582
+ const deFormatValue = useMemo13(() => {
3583
+ const config = typeDefinition.getTypeBySchema(rowData.self);
3584
+ return config?.deFormatDefault ? config.deFormatDefault(value) : value;
3585
+ }, [value, rowData]);
3586
+ const handleChange = useCallback7((v) => {
3587
+ valueRef.current = v;
3588
+ setValue(v);
3589
+ }, []);
3590
+ return {
3591
+ handleChange,
3592
+ handleSubmit,
3593
+ deFormatValue
3594
+ };
3595
+ };
3596
+ var TypeText2 = ({
3597
+ value,
3598
+ type
3599
+ }) => {
3600
+ const typeDefinition = useTypeDefinitionManager();
3601
+ const content = useMemo13(() => {
3602
+ const config = typeDefinition.getTypeBySchema(type);
3603
+ return config?.getValueText ? config.getValueText(value) : value;
3604
+ }, [value, type]);
3605
+ return /* @__PURE__ */ React29.createElement(TypeTextContainer, null, /* @__PURE__ */ React29.createElement(Typography8.Text, { ellipsis: { showTooltip: true } }, content));
3606
+ };
3607
+ var ViewRender7 = ({
3608
+ rowData,
3609
+ typeEditor,
3610
+ onEditMode,
3611
+ onChange
3612
+ }) => {
3613
+ const disabled = useDisabled("default" /* Default */, rowData);
3614
+ const typeDefinition = useTypeDefinitionManager();
3615
+ const { defaultMode = "default" } = rowData.extraConfig;
3616
+ const { customDefaultView } = rowData.extraConfig;
3617
+ const { deFormatValue, handleChange, handleSubmit } = useFormatValue({
3618
+ rowData,
3619
+ onChange,
3620
+ typeEditor
3621
+ });
3622
+ const customNode = customDefaultView && customDefaultView({
3623
+ rowData,
3624
+ disabled,
3625
+ value: deFormatValue,
3626
+ onChange: handleChange,
3627
+ onSubmit: (v) => {
3628
+ handleChange(v);
3629
+ handleSubmit();
3630
+ }
3631
+ });
3632
+ if (customNode) {
3633
+ return /* @__PURE__ */ React29.createElement(React29.Fragment, null, " ", customNode);
3634
+ }
3635
+ if (disabled) {
3636
+ return /* @__PURE__ */ React29.createElement(KeyViewContainer, { disabled: true }, /* @__PURE__ */ React29.createElement(Tooltip10, { content: disabled }, /* @__PURE__ */ React29.createElement("div", { style: { width: "100%", height: "100%" } }, /* @__PURE__ */ React29.createElement(TypeText2, { value: deFormatValue, type: rowData.self }))));
3637
+ }
3638
+ if (defaultMode === "server") {
3639
+ const config = typeDefinition.getTypeBySchema(rowData.self);
3640
+ return /* @__PURE__ */ React29.createElement(Tooltip10, { content: "The default value is not allowed to be modified." }, /* @__PURE__ */ React29.createElement(KeyViewContainer, { disabled: true }, /* @__PURE__ */ React29.createElement(Typography8.Text, null, JSON.stringify(config?.getDefaultValue?.()))));
3641
+ }
3642
+ return /* @__PURE__ */ React29.createElement(KeyViewContainer, { onClick: () => onEditMode() }, /* @__PURE__ */ React29.createElement(TypeText2, { value: deFormatValue, type: rowData.self }));
3643
+ };
3644
+ var EditRender5 = ({
3645
+ rowData,
3646
+ onChange,
3647
+ typeEditor,
3648
+ onViewMode
3649
+ }) => {
3650
+ const { deFormatValue, handleChange, handleSubmit } = useFormatValue({
3651
+ rowData,
3652
+ onChange,
3653
+ typeEditor
3654
+ });
3655
+ const typeDefinition = useTypeDefinitionManager();
3656
+ const config = useMemo13(() => typeDefinition.getTypeBySchema(rowData.self), [rowData.self]);
3657
+ return /* @__PURE__ */ React29.createElement(KeyEditorContainer, null, /* @__PURE__ */ React29.createElement(GlobalSelectStyle, null), config && config?.getInputNode?.({
3658
+ value: deFormatValue,
3659
+ onChange: handleChange,
3660
+ type: rowData.self,
3661
+ onSubmit: () => {
3662
+ handleSubmit();
3663
+ onViewMode();
3664
+ }
3665
+ }));
3666
+ };
3667
+ var defaultColumnConfig = {
3668
+ type: "default" /* Default */,
3669
+ width: 15,
3670
+ label: "Default",
3671
+ viewRender: ViewRender7,
3672
+ shortcuts: {
3673
+ onEnter: ({ rowData, onChange, typeEditor, value, typeDefinitionService }) => {
3674
+ const config = typeDefinitionService.getTypeBySchema(rowData.self);
3675
+ if (config?.typeInputConfig?.canEnter) {
3676
+ rowData.self.default = value;
3677
+ onChange();
3678
+ typeEditor.moveActivePosToNextLineWithAddLine(rowData);
3679
+ }
3680
+ },
3681
+ onTab: ({ rowData, value, onChange, typeEditor }) => {
3682
+ rowData.self.default = value;
3683
+ onChange();
3684
+ typeEditor.moveActivePosToNextItem();
3685
+ }
3686
+ },
3687
+ editRender: EditRender5
3688
+ };
3689
+
3690
+ // src/components/type-editor/columns/index.ts
3691
+ var columnConfigs = [
3692
+ keyColumnConfig,
3693
+ typeColumnConfig,
3694
+ requiredColumnConfig,
3695
+ descriptionColumnConfig,
3696
+ privateColumnConfig,
3697
+ valueColumnConfig,
3698
+ defaultColumnConfig,
3699
+ operateColumnConfig
3700
+ ];
3701
+
3702
+ // src/components/type-editor/index.tsx
3703
+ import React41, { useImperativeHandle as useImperativeHandle2, useState as useState21 } from "react";
3704
+ import { noop as noop2 } from "lodash";
3705
+ import { Space as Space6 } from "@douyinfe/semi-ui";
3706
+
3707
+ // src/components/type-editor/type-editor.tsx
3708
+ import React37 from "react";
3709
+ import styled7 from "styled-components";
3710
+
3711
+ // src/components/type-editor/table.tsx
3712
+ import { HTML5Backend } from "react-dnd-html5-backend";
3713
+ import { DndProvider } from "react-dnd";
3714
+ import { useCallback as useCallback9, useEffect as useEffect16, useMemo as useMemo19, useRef as useRef6, useState as useState19 } from "react";
3715
+ import React36 from "react";
3716
+ import { isEqual as isEqual2 } from "lodash";
3717
+ import classNames6 from "classnames";
3718
+ import { Space as Space3 } from "@douyinfe/semi-ui";
3719
+
3720
+ // src/components/type-editor/style.ts
3721
+ import styled3 from "styled-components";
3722
+ var ErrorMsgContainer = styled3.div`
3723
+ position: absolute;
3724
+ bottom: 0;
3725
+ left: 0;
3726
+ transform: translateY(100%);
3727
+ width: calc(100% - 6px);
3728
+ `;
3729
+ var EditCellContainer = styled3.div`
3730
+ position: absolute;
3731
+ width: 100%;
3732
+ left: 0;
3733
+ top: 0;
3734
+ background-color: var(--semi-color-bg-0);
3735
+ border: 1px solid var(--semi-color-focus-border);
3736
+ height: 38px;
3737
+ display: flex;
3738
+ align-items: center;
3739
+ transition: background-color 200ms;
3740
+ box-sizing: border-box;
3741
+ ${(props) => props.error ? "border: 1px solid var(--semi-color-danger);" : ""}
3742
+ ${(props) => props.blink ? "background-color: rgba(238, 245, 40) !important;" : ""}
3743
+ `;
3744
+ var DragRowContainer = styled3.tr`
3745
+ opacity: ${(props) => props.dragging ? 0.5 : 1};
3746
+ `;
3747
+ var EditorTableHeader = styled3.th`
3748
+ border-right: 1px solid var(--semi-color-border);
3749
+ border-bottom-width: 1px !important;
3750
+ height: 37px;
3751
+ box-sizing: border-box;
3752
+ font-size: 12px;
3753
+ `;
3754
+ var EditorTableCell = styled3.td`
3755
+ border-right: 1px solid var(--semi-color-border) !important;
3756
+ position: relative;
3757
+
3758
+ padding: 8px !important;
3759
+ height: 36px;
3760
+ `;
3761
+ var EditorTable = styled3.table`
3762
+ min-width: 600px;
3763
+ border-left-width: 1px;
3764
+ border-top-width: 1px;
3765
+ box-sizing: border-box;
3766
+ border-color: var(--semi-color-border);
3767
+ width: 100%;
3768
+ position: relative;
3769
+ border-style: solid;
3770
+ border-bottom: none;
3771
+ border-right: none;
3772
+ `;
3773
+ var EditorTableTitle = styled3.div`
3774
+ display: flex;
3775
+ align-items: center;
3776
+ cursor: pointer;
3777
+ `;
3778
+ var BaseIcon2 = styled3.div`
3779
+ width: 12px;
3780
+ height: 12px;
3781
+ flex-shrink: 0;
3782
+ `;
3783
+
3784
+ // src/components/type-editor/hooks/formatter-value.ts
3785
+ import { useMemo as useMemo14 } from "react";
3786
+
3787
+ // src/components/type-editor/mode/type-definition.ts
3788
+ var typeDefinitionConfig = {
3789
+ mode: "type-definition",
3790
+ convertSchemaToValue: (val) => val,
3791
+ convertValueToSchema: (val) => val,
3792
+ commonValueToSubmitValue: (val) => {
3793
+ if (val) {
3794
+ return typeEditorUtils.valueToTypeSchema(val);
3795
+ }
3796
+ return {
3797
+ type: "object",
3798
+ properties: {}
3799
+ };
3800
+ },
3801
+ toolConfig: {
3802
+ createByData: {
3803
+ viewConfig: [
3804
+ {
3805
+ type: "key" /* Key */,
3806
+ visible: true
3807
+ },
3808
+ {
3809
+ type: "type" /* Type */,
3810
+ visible: true
3811
+ }
3812
+ ],
3813
+ genDefaultValue() {
3814
+ return {
3815
+ type: "object",
3816
+ properties: {}
3817
+ };
3818
+ }
3819
+ }
3820
+ }
3821
+ };
3822
+
3823
+ // src/components/type-editor/mode/declare-assign.ts
3824
+ import { set, get } from "lodash";
3825
+ var traverseIJsonSchema2 = (root, path, cb) => {
3826
+ if (root) {
3827
+ cb(root, path);
3828
+ if (root.properties) {
3829
+ Object.keys(root.properties).forEach((k) => {
3830
+ traverseIJsonSchema2(root.properties[k], [...path, k], cb);
3831
+ });
3832
+ }
3833
+ }
3834
+ };
3835
+ var declareAssignConfig = {
3836
+ mode: "declare-assign",
3837
+ convertSchemaToValue: (val) => {
3838
+ const data = {};
3839
+ const newSchema = JSON.parse(JSON.stringify(val));
3840
+ traverseIJsonSchema2(newSchema, [], (type, path) => {
3841
+ if (type.extra?.value !== void 0) {
3842
+ set(data, path, type.extra?.value);
3843
+ }
3844
+ if (type.extra) {
3845
+ delete type.extra;
3846
+ }
3847
+ });
3848
+ return {
3849
+ data,
3850
+ definition: { schema: newSchema }
3851
+ };
3852
+ },
3853
+ convertValueToSchema: (schema) => {
3854
+ const { data } = schema;
3855
+ const newSchema = JSON.parse(JSON.stringify(schema.definition.schema));
3856
+ traverseIJsonSchema2(newSchema, [], (type, path) => {
3857
+ const value = get(data, path);
3858
+ if (value !== void 0 && type.type !== "object") {
3859
+ type.extra = { value };
3860
+ }
3861
+ });
3862
+ return newSchema;
3863
+ },
3864
+ commonValueToSubmitValue: (val) => {
3865
+ const type = val ? typeEditorUtils.valueToTypeSchema(val) : {
3866
+ type: "object",
3867
+ properties: {}
3868
+ };
3869
+ return {
3870
+ data: val || {},
3871
+ definition: {
3872
+ schema: type
3873
+ }
3874
+ };
3875
+ },
3876
+ toolConfig: {
3877
+ createByData: {
3878
+ viewConfig: [
3879
+ {
3880
+ type: "key" /* Key */,
3881
+ visible: true
3882
+ },
3883
+ {
3884
+ type: "type" /* Type */,
3885
+ visible: true
3886
+ },
3887
+ {
3888
+ type: "value" /* Value */,
3889
+ visible: true
3890
+ }
3891
+ ],
3892
+ genDefaultValue: () => ({
3893
+ data: {},
3894
+ definition: {
3895
+ schema: {
3896
+ type: "object",
3897
+ properties: {}
3898
+ }
3899
+ }
3900
+ })
3901
+ }
3902
+ }
3903
+ };
3904
+
3905
+ // src/components/type-editor/mode/index.ts
3906
+ var modeValueConfig = [
3907
+ declareAssignConfig,
3908
+ typeDefinitionConfig
3909
+ ];
3910
+
3911
+ // src/services/utils.ts
3912
+ var traverseIJsonSchema3 = (root, cb) => {
3913
+ if (root) {
3914
+ cb(root);
3915
+ if (root.items) {
3916
+ traverseIJsonSchema3(root.items, cb);
3917
+ }
3918
+ if (root.additionalProperties) {
3919
+ traverseIJsonSchema3(root.additionalProperties, cb);
3920
+ }
3921
+ if (root.properties) {
3922
+ Object.values(root.properties).forEach((v) => {
3923
+ traverseIJsonSchema3(v, cb);
3924
+ });
3925
+ }
3926
+ }
3927
+ };
3928
+
3929
+ // src/components/type-editor/hooks/formatter-value.ts
3930
+ var useFormatter = ({
3931
+ extraConfig = {},
3932
+ mode
3933
+ }) => {
3934
+ const { useExtra } = extraConfig;
3935
+ const modeConfig = useMemo14(
3936
+ () => modeValueConfig.find((v) => v.mode === mode),
3937
+ [mode]
3938
+ );
3939
+ const formatter = useMemo14(
3940
+ () => (value) => {
3941
+ const originSchema = value && modeConfig.convertValueToSchema(value);
3942
+ let res = originSchema ? JSON.parse(JSON.stringify(originSchema)) : originSchema;
3943
+ const formatters = [];
3944
+ if (useExtra) {
3945
+ formatters.push(extraFormatter);
3946
+ }
3947
+ if (formatters.length !== 0 && res) {
3948
+ traverseIJsonSchema3(res, (type) => {
3949
+ formatters.forEach((f) => f(type));
3950
+ });
3951
+ }
3952
+ return res;
3953
+ },
3954
+ [modeConfig, useExtra]
3955
+ );
3956
+ const deFormatter = useMemo14(
3957
+ () => (originSchema) => {
3958
+ let schema = originSchema ? JSON.parse(JSON.stringify(originSchema)) : originSchema;
3959
+ const formatters = [];
3960
+ if (useExtra) {
3961
+ formatters.push(extraDeFormatter);
3962
+ }
3963
+ if (formatters.length !== 0 && schema) {
3964
+ traverseIJsonSchema3(schema, (type) => {
3965
+ formatters.forEach((f) => f(type));
3966
+ });
3967
+ }
3968
+ return schema && modeConfig.convertSchemaToValue(schema);
3969
+ },
3970
+ [modeConfig, useExtra]
3971
+ );
3972
+ return {
3973
+ formatter,
3974
+ deFormatter
3975
+ };
3976
+ };
3977
+
3978
+ // src/components/type-editor/header.tsx
3979
+ import React30 from "react";
3980
+ import { Tooltip as Tooltip11 } from "@douyinfe/semi-ui";
3981
+ import { IconInfoCircle } from "@douyinfe/semi-icons";
3982
+ var Header = ({
3983
+ displayColumn,
3984
+ value,
3985
+ readonly,
3986
+ dataSourceMap,
3987
+ onChange
3988
+ }) => {
3989
+ const typeEditorService = useService(TypeEditorService);
3990
+ const { drop } = useHeaderDrop(value, dataSourceMap, onChange);
3991
+ return /* @__PURE__ */ React30.createElement("thead", { className: "semi-table-thead" }, /* @__PURE__ */ React30.createElement("tr", { ref: drop, className: "semi-table-row" }, displayColumn.map((v) => {
3992
+ const config = typeEditorService.getConfigByType(v);
3993
+ return /* @__PURE__ */ React30.createElement(
3994
+ EditorTableHeader,
3995
+ {
3996
+ key: v,
3997
+ style: {
3998
+ width: config?.width ? `${config.width}%` : void 0,
3999
+ paddingLeft: readonly ? "24px !important" : void 0
4000
+ },
4001
+ className: "semi-table-row-head",
4002
+ scope: "col"
4003
+ },
4004
+ /* @__PURE__ */ React30.createElement(EditorTableTitle, null, config?.label, config?.info && /* @__PURE__ */ React30.createElement(Tooltip11, { content: config.info() }, /* @__PURE__ */ React30.createElement(BaseIcon2, null, /* @__PURE__ */ React30.createElement(IconInfoCircle, { style: { marginLeft: 4 }, size: "small" }))))
4005
+ );
4006
+ })));
4007
+ };
4008
+
4009
+ // src/components/type-editor/drop-tip.tsx
4010
+ import { useEffect as useEffect14, useMemo as useMemo15, useState as useState17 } from "react";
4011
+ import React31 from "react";
4012
+ import styled4 from "styled-components";
4013
+ var StyledDragTip = styled4.div`
4014
+ position: absolute;
4015
+ height: 1px;
4016
+ background-color: var(--semi-color-primary);
4017
+ `;
4018
+ var DropTip = ({
4019
+ dataSource
4020
+ }) => {
4021
+ const typeEditor = useService(TypeEditorService);
4022
+ const [dropInfo, setDropInfo] = useState17(typeEditor.dropInfo);
4023
+ const typeService = useTypeDefinitionManager();
4024
+ useEffect14(() => {
4025
+ const dispose = typeEditor.onDropInfoChange.event(setDropInfo);
4026
+ return () => {
4027
+ dispose.dispose();
4028
+ };
4029
+ }, []);
4030
+ const rowData = useMemo15(() => dataSource[dropInfo.rowDataId], [dropInfo.rowDataId]);
4031
+ const rowDataCanHasChildren = useMemo15(
4032
+ () => rowData && rowData.type && typeService.getTypeByName(rowData.type)?.canAddField?.(rowData),
4033
+ [rowData]
4034
+ );
4035
+ return /* @__PURE__ */ React31.createElement(React31.Fragment, null, (rowData || dropInfo.rowDataId === "header") && /* @__PURE__ */ React31.createElement(
4036
+ StyledDragTip,
4037
+ {
4038
+ style: {
4039
+ top: HEADER_HIGHT + TAB_BRA_HIGHT + (dropInfo.index + 1) * CELL_HIGHT - 1,
4040
+ right: 0,
4041
+ width: `calc(100% - ${/**
4042
+ * 表格 padding
4043
+ * 初始 drag icon 占一个缩进
4044
+ * rowData 本身 level 个缩进,如果是含有子节点,因为默认添加到子元素内,还需要额外加一个缩进
4045
+ */
4046
+ CELL_PADDING + INDENT_WIDTH + (dropInfo.indent + (rowDataCanHasChildren ? 1 : 0) + 1) * INDENT_WIDTH}px)`
4047
+ }
4048
+ }
4049
+ ));
4050
+ };
4051
+
4052
+ // src/components/type-editor/cell.tsx
4053
+ import React34, { useCallback as useCallback8, useMemo as useMemo18 } from "react";
4054
+ import classNames4 from "classnames";
4055
+ import { NOOP } from "@flowgram.ai/utils";
4056
+
4057
+ // src/components/feedback/feedback.tsx
4058
+ import React32, { useMemo as useMemo16 } from "react";
4059
+
4060
+ // src/components/feedback/style.ts
4061
+ import styled5 from "styled-components";
4062
+ var FeedbackStyle = styled5.div`
4063
+ position: absolute;
4064
+
4065
+ ${(props) => props.expanded ? `
4066
+ position: relative;
4067
+ ` : ""}
4068
+
4069
+ color: #fff;
4070
+ max-width: 100%;
4071
+ width: fit-content;
4072
+ padding: 0 4px;
4073
+ font-size: 10px;
4074
+ line-height: 18px;
4075
+ word-break: break-all;
4076
+
4077
+ &.expandable {
4078
+ }
4079
+
4080
+ ${(props) => props.expandable ? `
4081
+ white-space: nowrap;
4082
+ overflow: hidden;
4083
+ text-overflow: ellipsis;
4084
+
4085
+ &:hover {
4086
+ white-space: normal;
4087
+ overflow: visible;
4088
+ }
4089
+ ` : ""}
4090
+
4091
+ ${(props) => props.error ? `
4092
+ background-color: var(--semi-color-danger);
4093
+ ` : ""}
4094
+
4095
+
4096
+ ${(props) => props.warning ? `
4097
+ background-color:var(--semi-color-warning);
4098
+ ` : ""}
4099
+
4100
+
4101
+ z-index: 1;
4102
+ `;
4103
+ var RelativeWrapper = styled5.div`
4104
+ position: relative;
4105
+ height: 18px;
4106
+
4107
+ ${(props) => props.expanded ? `
4108
+ height: fit-content;
4109
+ ` : ""}
4110
+ `;
4111
+
4112
+ // src/components/feedback/feedback.tsx
4113
+ var Feedback = ({ message, layout, level = "error", expanded = false }) => {
4114
+ const feedbackContent = useMemo16(
4115
+ () => /* @__PURE__ */ React32.createElement(
4116
+ FeedbackStyle,
4117
+ {
4118
+ expanded,
4119
+ error: level === "error",
4120
+ warning: level === "warning",
4121
+ expandable: !expanded
4122
+ },
4123
+ message
4124
+ ),
4125
+ [level, message, expanded]
4126
+ );
4127
+ return layout === "relative" ? /* @__PURE__ */ React32.createElement(RelativeWrapper, { expanded }, feedbackContent) : feedbackContent;
4128
+ };
4129
+
4130
+ // src/components/type-editor/hooks/blink.ts
4131
+ import { useEffect as useEffect15, useMemo as useMemo17, useState as useState18 } from "react";
4132
+ var useIsBlink = () => {
4133
+ const typeEditor = useService(TypeEditorService);
4134
+ const blinkData = useMemo17(() => typeEditor.blink, [typeEditor.blink]);
4135
+ const [blink, setBlink] = useState18(blinkData.data);
4136
+ useEffect15(() => {
4137
+ const dispose = blinkData.onDataChange(({ next }) => {
4138
+ setBlink(next);
4139
+ if (next) {
4140
+ setTimeout(() => {
4141
+ blinkData.update(false);
4142
+ }, 200);
4143
+ }
4144
+ });
4145
+ return () => {
4146
+ dispose.dispose();
4147
+ };
4148
+ }, [blinkData]);
4149
+ return blink;
4150
+ };
4151
+
4152
+ // src/components/type-editor/error.tsx
4153
+ import React33 from "react";
4154
+ import styled6 from "styled-components";
4155
+ var TopLine = styled6.div`
4156
+ position: absolute;
4157
+ background-color: ${(props) => props.level === "warning" ? "var(--semi-color-warning)" : "var(--semi-color-danger)"};
4158
+ width: 100%;
4159
+ height: 1px;
4160
+ top: 0;
4161
+ left: 0;
4162
+ `;
4163
+ var BottomLine = styled6.div`
4164
+ position: absolute;
4165
+ background-color: ${(props) => props.level === "warning" ? "var(--semi-color-warning)" : "var(--semi-color-danger)"};
4166
+ width: 100%;
4167
+ height: 1px;
4168
+ bottom: -1px;
4169
+ left: 0;
4170
+ `;
4171
+ var RightLine = styled6.div`
4172
+ position: absolute;
4173
+ background-color: ${(props) => props.level === "warning" ? "var(--semi-color-warning)" : "var(--semi-color-danger)"};
4174
+ height: calc(100% + 1px);
4175
+ width: 1px;
4176
+ bottom: -1px;
4177
+ right: 0px;
4178
+ `;
4179
+ var LeftLine = styled6.div`
4180
+ position: absolute;
4181
+ background-color: ${(props) => props.level === "warning" ? "var(--semi-color-warning)" : "var(--semi-color-danger)"};
4182
+ height: calc(100% + 1px);
4183
+ width: 1px;
4184
+ bottom: -1px;
4185
+ left: 0;
4186
+ `;
4187
+ var ErrorCellBorder = ({ level }) => /* @__PURE__ */ React33.createElement(React33.Fragment, null, /* @__PURE__ */ React33.createElement(TopLine, { level }), /* @__PURE__ */ React33.createElement(BottomLine, { level }), /* @__PURE__ */ React33.createElement(LeftLine, { level }), /* @__PURE__ */ React33.createElement(RightLine, { level }));
4188
+
4189
+ // src/components/type-editor/cell.tsx
4190
+ var ViewCell = ({
4191
+ rowData,
4192
+ rowIndex,
4193
+ columnIndex,
4194
+ onChange,
4195
+ dataSourceMap,
4196
+ onError,
4197
+ onFieldChange,
4198
+ onPaste,
4199
+ unOpenKeys,
4200
+ viewConfigs,
4201
+ readonly,
4202
+ onChildrenVisibleChange,
4203
+ dragSource,
4204
+ columnType
4205
+ }) => {
4206
+ const typeEditorService = useService(TypeEditorService);
4207
+ const config = typeEditorService.getConfigByType(columnType);
4208
+ const { drop } = useCellDrop(rowData, rowIndex, dataSourceMap, onChange);
4209
+ const handleEditMode = useCallback8(() => {
4210
+ if (!readonly) {
4211
+ typeEditorService.setActivePos({ x: columnIndex, y: rowIndex });
4212
+ }
4213
+ }, [columnIndex, readonly, rowIndex]);
4214
+ const handleViewMode = useCallback8(() => {
4215
+ typeEditorService.clearActivePos();
4216
+ }, []);
4217
+ const Render = config.viewRender;
4218
+ const feedbackInfo = useViewCellErrorMsg(rowData, config, {
4219
+ x: columnIndex,
4220
+ y: rowIndex
4221
+ });
4222
+ return /* @__PURE__ */ React34.createElement(
4223
+ EditorTableCell,
4224
+ {
4225
+ ref: config.customDrop ? void 0 : drop,
4226
+ className: classNames4("semi-table-row-cell", "cell-container")
4227
+ },
4228
+ feedbackInfo && /* @__PURE__ */ React34.createElement(React34.Fragment, null, /* @__PURE__ */ React34.createElement(ErrorCellBorder, { level: feedbackInfo.level }), /* @__PURE__ */ React34.createElement(ErrorMsgContainer, null, /* @__PURE__ */ React34.createElement(Feedback, { message: feedbackInfo.msg, level: feedbackInfo.level, layout: "absolute" }))),
4229
+ Render ? /* @__PURE__ */ React34.createElement(
4230
+ Render,
4231
+ {
4232
+ readonly,
4233
+ config: viewConfigs.find((v) => v.type === columnType) || {},
4234
+ dragSource,
4235
+ unOpenKeys,
4236
+ onFieldChange,
4237
+ typeEditor: typeEditorService,
4238
+ onPaste,
4239
+ error: !!feedbackInfo,
4240
+ onError,
4241
+ onChange,
4242
+ onChildrenVisibleChange,
4243
+ onViewMode: handleViewMode,
4244
+ onEditMode: handleEditMode,
4245
+ rowData
4246
+ }
4247
+ ) : `${rowData[columnType]}`
4248
+ );
4249
+ };
4250
+ var EditCell = ({
4251
+ displayColumn,
4252
+ onFieldChange,
4253
+ dataSource,
4254
+ onPaste,
4255
+ unOpenKeys,
4256
+ onError,
4257
+ viewConfigs,
4258
+ onChildrenVisibleChange,
4259
+ tableDom,
4260
+ onChange
4261
+ }) => {
4262
+ const typeEditorService = useService(TypeEditorService);
4263
+ const activePos = useActivePos();
4264
+ const handleViewMode = useCallback8(() => {
4265
+ typeEditorService.clearActivePos();
4266
+ }, []);
4267
+ const columnType = useMemo18(() => displayColumn[activePos.x], [displayColumn, activePos.x]);
4268
+ const columnEachWidth = useMemo18(() => {
4269
+ const headerNodes = tableDom.childNodes?.[0]?.childNodes?.[0];
4270
+ const width = [];
4271
+ for (const item of headerNodes.childNodes.values()) {
4272
+ width.push(item.clientWidth + 1);
4273
+ }
4274
+ return width;
4275
+ }, [displayColumn, tableDom, tableDom.clientWidth]);
4276
+ const columnAccWidth = useMemo18(() => {
4277
+ let acc = 0;
4278
+ return columnEachWidth.map((width) => {
4279
+ acc += width;
4280
+ return acc - width;
4281
+ });
4282
+ }, [columnEachWidth]);
4283
+ const rowData = useMemo18(() => dataSource[activePos.y], [dataSource, activePos.y]);
4284
+ const config = typeEditorService.getConfigByType(columnType);
4285
+ const Render = config && (config.editRender || config.viewRender);
4286
+ const errorMsg = useEditCellErrorMsg(activePos);
4287
+ const blink = useIsBlink();
4288
+ if (!config) {
4289
+ return /* @__PURE__ */ React34.createElement(React34.Fragment, null);
4290
+ }
4291
+ return /* @__PURE__ */ React34.createElement(React34.Fragment, null, rowData && /* @__PURE__ */ React34.createElement(
4292
+ EditCellContainer,
4293
+ {
4294
+ error: !!errorMsg,
4295
+ blink,
4296
+ key: rowData.key + columnType,
4297
+ style: {
4298
+ width: columnEachWidth[activePos.x] + 1,
4299
+ top: HEADER_HIGHT + TAB_BRA_HIGHT + activePos.y * CELL_HIGHT + 1,
4300
+ left: columnAccWidth[activePos.x]
4301
+ }
4302
+ },
4303
+ Render ? /* @__PURE__ */ React34.createElement(
4304
+ Render,
4305
+ {
4306
+ error: !!errorMsg,
4307
+ onError,
4308
+ config: viewConfigs.find((v) => v.type === columnType) || {},
4309
+ key: rowData.id,
4310
+ unOpenKeys,
4311
+ onChange,
4312
+ onPaste,
4313
+ typeEditor: typeEditorService,
4314
+ onFieldChange,
4315
+ onChildrenVisibleChange,
4316
+ onEditMode: NOOP,
4317
+ onViewMode: handleViewMode,
4318
+ rowData
4319
+ }
4320
+ ) : `${rowData[columnType]}`,
4321
+ errorMsg && /* @__PURE__ */ React34.createElement(ErrorMsgContainer, { style: { left: -1 } }, /* @__PURE__ */ React34.createElement(Feedback, { message: errorMsg, level: "error", layout: "absolute" }))
4322
+ ));
4323
+ };
4324
+
4325
+ // src/components/type-editor/body.tsx
4326
+ import React35 from "react";
4327
+ import classNames5 from "classnames";
4328
+ import { Empty } from "@douyinfe/semi-ui";
4329
+ import { IllustrationNoContent, IllustrationNoContentDark } from "@douyinfe/semi-illustrations";
4330
+ var Row = ({
4331
+ displayColumn,
4332
+ data,
4333
+ ...rest
4334
+ }) => {
4335
+ const { preview, drag, isDragging } = useRowDrag(data.id, rest.onChildrenVisibleChange);
4336
+ return /* @__PURE__ */ React35.createElement(DragRowContainer, { ref: preview, dragging: isDragging, className: classNames5("semi-table-row") }, displayColumn.map((column, columnIndex) => /* @__PURE__ */ React35.createElement(
4337
+ ViewCell,
4338
+ {
4339
+ dragSource: data.cannotDrag ? void 0 : drag,
4340
+ key: data.id + column,
4341
+ columnType: column,
4342
+ columnIndex,
4343
+ rowData: data,
4344
+ ...rest
4345
+ }
4346
+ )));
4347
+ };
4348
+ var Body = ({
4349
+ dataSource,
4350
+ customEmptyNode,
4351
+ ...rest
4352
+ }) => {
4353
+ if (dataSource.length === 0) {
4354
+ const rows = rest.displayColumn.length;
4355
+ return /* @__PURE__ */ React35.createElement("tbody", null, /* @__PURE__ */ React35.createElement("tr", null, /* @__PURE__ */ React35.createElement("td", { colSpan: rows }, customEmptyNode ? customEmptyNode : /* @__PURE__ */ React35.createElement(
4356
+ Empty,
4357
+ {
4358
+ style: { marginTop: 40 },
4359
+ image: /* @__PURE__ */ React35.createElement(IllustrationNoContent, { style: { width: 100, height: 100 } }),
4360
+ darkModeImage: /* @__PURE__ */ React35.createElement(IllustrationNoContentDark, { style: { width: 100, height: 100 } }),
4361
+ description: "No content. Please add."
4362
+ }
4363
+ ))));
4364
+ }
4365
+ return /* @__PURE__ */ React35.createElement("tbody", { className: "semi-table-tbody" }, /* @__PURE__ */ React35.createElement(React35.Fragment, null, dataSource.map((data, rowIndex) => /* @__PURE__ */ React35.createElement(Row, { key: data.id, ...rest, data, rowIndex }))));
4366
+ };
4367
+
4368
+ // src/components/type-editor/table.tsx
4369
+ var TableInner = ({
4370
+ value,
4371
+ onChange,
4372
+ mode,
4373
+ viewConfigs,
4374
+ onInit,
4375
+ forceUpdate,
4376
+ onEditRowDataSource,
4377
+ rootLevel = 0,
4378
+ customEmptyNode,
4379
+ tableClassName,
4380
+ onError,
4381
+ disableEditColumn,
4382
+ readonly,
4383
+ onPaste,
4384
+ typeRegistryCreators,
4385
+ onFieldChange,
4386
+ getRootSchema,
4387
+ onCustomSetValue,
4388
+ extraConfig: originExtraConfig = {}
4389
+ }) => {
4390
+ const extraConfig = useMemo19(
4391
+ () => ({
4392
+ ...originExtraConfig
4393
+ }),
4394
+ [originExtraConfig]
4395
+ );
4396
+ const { deFormatter, formatter } = useFormatter({
4397
+ mode,
4398
+ extraConfig
4399
+ });
4400
+ const typeSchema = useMemo19(() => formatter(value), [formatter, value]);
4401
+ const typeEditor = useService(TypeEditorService);
4402
+ const typeOperator = useService(
4403
+ TypeEditorOperationService
4404
+ );
4405
+ const [tableDom, setTableDom] = useState19();
4406
+ const [initialSchema, setInitialSchema] = useState19(() => {
4407
+ const res = typeEditorUtils.clone(typeSchema) || typeEditorUtils.getInitialSchema();
4408
+ typeOperator.storeState(res);
4409
+ return res;
4410
+ });
4411
+ const editor = useRef6();
4412
+ useEffect16(() => {
4413
+ const instance = {
4414
+ getService: () => typeEditor,
4415
+ setValue(originNewVal) {
4416
+ let newVal = originNewVal;
4417
+ if (onCustomSetValue) {
4418
+ newVal = onCustomSetValue(newVal);
4419
+ }
4420
+ const newSchema = formatter(newVal);
4421
+ setInitialSchema(newSchema);
4422
+ typeOperator.storeState(newSchema);
4423
+ const final = typeEditorUtils.formateTypeSchema(newSchema, extraConfig);
4424
+ const newValue = deFormatter(final);
4425
+ if (onChange) {
4426
+ onChange(newValue);
4427
+ }
4428
+ },
4429
+ getContainer: () => tableDom,
4430
+ getValue: () => {
4431
+ const rootValue = deFormatter(typeEditor.rootTypeSchema);
4432
+ return rootValue;
4433
+ },
4434
+ undo: () => {
4435
+ typeOperator.undo();
4436
+ typeEditor.onChange(typeOperator.getCurrentState(), {
4437
+ storeState: false
4438
+ });
4439
+ },
4440
+ redo: () => {
4441
+ typeOperator.redo();
4442
+ typeEditor.onChange(typeOperator.getCurrentState(), {
4443
+ storeState: false
4444
+ });
4445
+ },
4446
+ getOperator() {
4447
+ return typeOperator;
4448
+ }
4449
+ };
4450
+ editor.current = instance;
4451
+ }, [typeEditor, onChange, tableDom, deFormatter, formatter, extraConfig, onCustomSetValue]);
4452
+ useEffect16(() => {
4453
+ onInit?.(editor);
4454
+ }, [onInit]);
4455
+ const [unOpenKeys, setUnOpenKeys] = useState19({});
4456
+ useEffect16(() => {
4457
+ if (!isEqual2(typeSchema, initialSchema) && typeSchema && (forceUpdate || !typeEditorUtils.isTempState(initialSchema, extraConfig?.customValidateName))) {
4458
+ setInitialSchema(typeEditorUtils.clone(typeSchema));
4459
+ }
4460
+ }, [typeSchema, extraConfig?.customValidateName]);
4461
+ const typeService = useTypeDefinitionManager();
4462
+ const displayColumn = useMemo19(
4463
+ () => viewConfigs.filter((v) => v.visible).map((v) => v.type),
4464
+ [viewConfigs]
4465
+ );
4466
+ const { dataSource } = useMemo19(() => {
4467
+ const res = [];
4468
+ let index = -1;
4469
+ const dfs = (schema, config) => {
4470
+ const {
4471
+ parentId,
4472
+ level = -1,
4473
+ key = ROOT_FIELD_ID,
4474
+ path,
4475
+ parent,
4476
+ canValueEditable = true,
4477
+ canDefaultEditable = true
4478
+ } = config;
4479
+ const id = [parentId, key || (/* @__PURE__ */ new Date()).valueOf().toString()].join("-");
4480
+ const typeConfig = typeService.getTypeBySchema(schema);
4481
+ const uid = parentId ? id : key;
4482
+ const rowData = {
4483
+ ...schema,
4484
+ key,
4485
+ index,
4486
+ id: uid,
4487
+ level,
4488
+ self: schema,
4489
+ parentId,
4490
+ parent,
4491
+ deepChildrenCount: 0,
4492
+ isRequired: (parent?.required || []).includes(key),
4493
+ childrenCount: 0,
4494
+ disableEditColumn: [...disableEditColumn || []],
4495
+ path,
4496
+ extraConfig: { ...extraConfig }
4497
+ };
4498
+ index += 1;
4499
+ typeEditor.dataSourceMap[rowData.id] = rowData;
4500
+ res.push(rowData);
4501
+ const customDefaultValidate = extraConfig.customDefaultEditable && extraConfig.customDefaultEditable(rowData);
4502
+ if (typeof customDefaultValidate === "string") {
4503
+ rowData.disableEditColumn.push({
4504
+ column: "default" /* Default */,
4505
+ reason: customDefaultValidate
4506
+ });
4507
+ }
4508
+ if (typeof canDefaultEditable === "string" && level > rootLevel) {
4509
+ rowData.disableEditColumn.push({
4510
+ column: "default" /* Default */,
4511
+ reason: canDefaultEditable
4512
+ });
4513
+ }
4514
+ if (typeof canValueEditable === "string" && level > rootLevel) {
4515
+ rowData.disableEditColumn.push({
4516
+ column: "value" /* Value */,
4517
+ reason: canValueEditable
4518
+ });
4519
+ }
4520
+ if (typeConfig) {
4521
+ const children = typeConfig.getTypeSchemaProperties && typeConfig.getTypeSchemaProperties(schema);
4522
+ const childrenParent = typeConfig.getPropertiesParent && typeConfig.getPropertiesParent(schema);
4523
+ const childrenParentConfig = childrenParent && typeService.getTypeBySchema(childrenParent);
4524
+ if (!extraConfig.customDefaultEditable && typeof childrenParentConfig?.defaultEditable === "string") {
4525
+ rowData.disableEditColumn.push({
4526
+ column: "default" /* Default */,
4527
+ reason: childrenParentConfig?.defaultEditable
4528
+ });
4529
+ }
4530
+ if (children) {
4531
+ const originLen = res.length;
4532
+ rowData.childrenCount = Object.keys(children).length;
4533
+ if (unOpenKeys[uid]) {
4534
+ return;
4535
+ }
4536
+ const parentPath = [...path, ...typeConfig.getJsonPaths?.(schema) || []];
4537
+ let idx = 0;
4538
+ const childCanValueEditable = typeConfig?.childrenValueEditable?.(schema);
4539
+ Object.keys(children).map((k) => {
4540
+ typeEditorUtils.fixFlowIndex(children[k], idx);
4541
+ idx++;
4542
+ return k;
4543
+ }).sort((k1, k2) => (children[k1].extra?.index || 0) - (children[k2].extra?.index || 0)).forEach((k) => {
4544
+ const canDefaultEditableFromParent = typeConfig.childrenDefaultEditable?.(schema);
4545
+ dfs(children[k], {
4546
+ key: k,
4547
+ parentId: id,
4548
+ parent: childrenParent,
4549
+ level: level + 1,
4550
+ path: [...parentPath, k],
4551
+ canDefaultEditable: typeof canDefaultEditableFromParent === "string" ? canDefaultEditableFromParent : canDefaultEditable,
4552
+ canValueEditable: childCanValueEditable
4553
+ });
4554
+ });
4555
+ rowData.deepChildrenCount = res.length - originLen;
4556
+ } else {
4557
+ if (!extraConfig.customDefaultEditable && typeof typeConfig?.defaultEditable === "string") {
4558
+ rowData.disableEditColumn.push({
4559
+ column: "default" /* Default */,
4560
+ reason: typeConfig?.defaultEditable
4561
+ });
4562
+ }
4563
+ }
4564
+ }
4565
+ };
4566
+ if (initialSchema) {
4567
+ dfs(initialSchema, { level: -1, path: [] });
4568
+ res.shift();
4569
+ const newData = onEditRowDataSource ? onEditRowDataSource(res) : res;
4570
+ typeEditor.setDataSource(newData);
4571
+ return {
4572
+ dataSource: newData
4573
+ };
4574
+ }
4575
+ return {
4576
+ dataSource: []
4577
+ };
4578
+ }, [initialSchema, disableEditColumn, unOpenKeys, onEditRowDataSource]);
4579
+ const activePos = useActivePos();
4580
+ useEffect16(() => {
4581
+ typeEditor.rootTypeSchema = initialSchema;
4582
+ }, [initialSchema]);
4583
+ const handleTypeSchemaChange = useCallback9(
4584
+ (type, ctx = {}) => {
4585
+ const { storeState = true } = ctx;
4586
+ const newSchema = JSON.parse(JSON.stringify(type || initialSchema));
4587
+ setInitialSchema({ ...newSchema });
4588
+ const final = typeEditorUtils.formateTypeSchema(newSchema, extraConfig);
4589
+ if (storeState) {
4590
+ typeOperator.storeState(newSchema);
4591
+ }
4592
+ const newValue = deFormatter(final);
4593
+ if (onChange) {
4594
+ onChange(newValue);
4595
+ }
4596
+ },
4597
+ [initialSchema, deFormatter, extraConfig]
4598
+ );
4599
+ const handleRowDataAdd = useCallback9(
4600
+ (id) => {
4601
+ const rowData = typeEditor.dataSourceMap[id];
4602
+ const currentSchema = rowData.self;
4603
+ const config = typeService.getTypeBySchema(rowData.self);
4604
+ if (currentSchema && config) {
4605
+ let index = -1;
4606
+ const parent = config.getPropertiesParent?.(currentSchema);
4607
+ if (!parent) {
4608
+ return;
4609
+ }
4610
+ if (!parent.properties) {
4611
+ parent.properties = {};
4612
+ }
4613
+ Object.values(parent.properties).forEach((val) => {
4614
+ if (!val.extra) {
4615
+ val.extra = {
4616
+ index: 0
4617
+ };
4618
+ }
4619
+ index = Math.max(index, val.extra.index || 0);
4620
+ });
4621
+ const [key, schema] = typeEditorUtils.genNewTypeSchema(index + 1);
4622
+ parent.properties[key] = schema;
4623
+ const newDataSource = typeEditor.getDataSource();
4624
+ let addIndex = rowData.index + 1;
4625
+ for (let i = rowData.index + 1, len = dataSource.length; i < len; i++) {
4626
+ if (newDataSource[i].level > rowData.level) {
4627
+ addIndex++;
4628
+ } else {
4629
+ break;
4630
+ }
4631
+ }
4632
+ const newPos = {
4633
+ x: 0,
4634
+ y: addIndex
4635
+ };
4636
+ typeEditor.setActivePos(newPos);
4637
+ handleTypeSchemaChange();
4638
+ }
4639
+ },
4640
+ [initialSchema, getRootSchema]
4641
+ );
4642
+ useEffect16(() => {
4643
+ typeEditor.columnViewConfig = viewConfigs.filter((v) => v.visible);
4644
+ typeEditor.onChange = handleTypeSchemaChange;
4645
+ typeEditor.onGlobalAdd = handleRowDataAdd;
4646
+ typeEditor.typeRegistryCreators = typeRegistryCreators;
4647
+ }, [viewConfigs, handleTypeSchemaChange, typeRegistryCreators]);
4648
+ const handleChildrenVisibleChange = useCallback9(
4649
+ (rowDataId, newVal) => {
4650
+ const newData = { ...unOpenKeys };
4651
+ newData[rowDataId] = newVal;
4652
+ setUnOpenKeys(newData);
4653
+ },
4654
+ [unOpenKeys]
4655
+ );
4656
+ return /* @__PURE__ */ React36.createElement(React36.Fragment, null, /* @__PURE__ */ React36.createElement(DndProvider, { backend: HTML5Backend }, /* @__PURE__ */ React36.createElement(Space3, { vertical: true, style: { width: "100%" } }, /* @__PURE__ */ React36.createElement("div", { style: { width: "100%" } }, /* @__PURE__ */ React36.createElement(
4657
+ EditorTable,
4658
+ {
4659
+ ref: (dom) => setTableDom(dom),
4660
+ className: classNames6("semi-table", tableClassName)
4661
+ },
4662
+ /* @__PURE__ */ React36.createElement(
4663
+ Header,
4664
+ {
4665
+ dataSourceMap: typeEditor.dataSourceMap,
4666
+ value: initialSchema,
4667
+ readonly,
4668
+ onChange: handleTypeSchemaChange,
4669
+ displayColumn
4670
+ }
4671
+ ),
4672
+ /* @__PURE__ */ React36.createElement(
4673
+ Body,
4674
+ {
4675
+ viewConfigs,
4676
+ onFieldChange,
4677
+ onPaste,
4678
+ customEmptyNode,
4679
+ readonly,
4680
+ dataSourceMap: typeEditor.dataSourceMap,
4681
+ unOpenKeys,
4682
+ onError,
4683
+ onChildrenVisibleChange: handleChildrenVisibleChange,
4684
+ onChange: handleTypeSchemaChange,
4685
+ dataSource,
4686
+ displayColumn
4687
+ }
4688
+ )
4689
+ )))), activePos.x !== -1 && activePos.y !== -1 && tableDom && /* @__PURE__ */ React36.createElement(
4690
+ EditCell,
4691
+ {
4692
+ viewConfigs,
4693
+ unOpenKeys,
4694
+ onPaste,
4695
+ onFieldChange,
4696
+ onError,
4697
+ onChildrenVisibleChange: handleChildrenVisibleChange,
4698
+ onChange: handleTypeSchemaChange,
4699
+ tableDom,
4700
+ dataSource,
4701
+ displayColumn
4702
+ }
4703
+ ), /* @__PURE__ */ React36.createElement(DropTip, { dataSource: typeEditor.dataSourceMap }));
4704
+ };
4705
+ var Table = fixedTSForwardRef(TableInner);
4706
+
4707
+ // src/components/type-editor/type-editor.tsx
4708
+ var Container2 = styled7.div`
4709
+ position: relative;
4710
+
4711
+ display: flex;
4712
+ flex-direction: column;
4713
+ gap: 4px;
4714
+
4715
+ outline: none;
4716
+
4717
+ table {
4718
+ table-layout: fixed;
4719
+ }
4720
+ `;
4721
+ var TypeEditorTable = (props) => /* @__PURE__ */ React37.createElement(TypeEditorProvider, { typeRegistryCreators: props.typeRegistryCreators }, /* @__PURE__ */ React37.createElement(TypeEditorListener, { configs: props.viewConfigs }, /* @__PURE__ */ React37.createElement(Container2, null, /* @__PURE__ */ React37.createElement(Table, { ...props }))));
4722
+
4723
+ // src/components/type-editor/tool-bar.tsx
4724
+ import React40, { useMemo as useMemo21 } from "react";
4725
+ import { Space as Space5, Tooltip as Tooltip13 } from "@douyinfe/semi-ui";
4726
+
4727
+ // src/components/type-editor/type.ts
4728
+ var ToolbarKey = /* @__PURE__ */ ((ToolbarKey2) => {
4729
+ ToolbarKey2["Import"] = "Import";
4730
+ ToolbarKey2["UndoRedo"] = "UndoRedo";
4731
+ return ToolbarKey2;
4732
+ })(ToolbarKey || {});
4733
+
4734
+ // src/components/type-editor/tools/undo-redo.tsx
4735
+ import React38 from "react";
4736
+ import { Button, Tooltip as Tooltip12 } from "@douyinfe/semi-ui";
4737
+ import { IconRedo, IconUndo } from "@douyinfe/semi-icons";
4738
+ var UndoRedo = ({
4739
+ editor
4740
+ }) => {
4741
+ const { data: canUndo } = useMonitorData(editor.getOperator()?.canUndo);
4742
+ const { data: canRedo } = useMonitorData(editor.getOperator()?.canRedo);
4743
+ return /* @__PURE__ */ React38.createElement(React38.Fragment, null, /* @__PURE__ */ React38.createElement(Tooltip12, { content: "Undo" }, /* @__PURE__ */ React38.createElement(
4744
+ Button,
4745
+ {
4746
+ disabled: !canUndo,
4747
+ icon: /* @__PURE__ */ React38.createElement(IconUndo, null),
4748
+ size: "small",
4749
+ onClick: () => {
4750
+ editor?.undo();
4751
+ }
4752
+ }
4753
+ )), /* @__PURE__ */ React38.createElement(Tooltip12, { content: "Redo" }, /* @__PURE__ */ React38.createElement(
4754
+ Button,
4755
+ {
4756
+ size: "small",
4757
+ icon: /* @__PURE__ */ React38.createElement(IconRedo, null),
4758
+ disabled: !canRedo,
4759
+ onClick: () => {
4760
+ editor?.redo();
4761
+ }
4762
+ }
4763
+ )));
4764
+ };
4765
+
4766
+ // src/components/type-editor/tools/create-by-data.tsx
4767
+ import React39, { useCallback as useCallback10, useMemo as useMemo20, useState as useState20 } from "react";
4768
+ import { debounce } from "lodash";
4769
+ import { Button as Button2, Divider, Empty as Empty2, Modal, Space as Space4, TextArea } from "@douyinfe/semi-ui";
4770
+ import { IllustrationFailure, IllustrationFailureDark } from "@douyinfe/semi-illustrations";
4771
+
4772
+ // src/components/type-editor/tools/style.ts
4773
+ import styled8 from "styled-components";
4774
+ var DataTransform = styled8.div`
4775
+ height: 406px;
4776
+ display: flex;
4777
+ gap: 4px;
4778
+ `;
4779
+
4780
+ // src/components/type-editor/tools/create-by-data.tsx
4781
+ var CreateByData = ({
4782
+ mode,
4783
+ disabled,
4784
+ customInputRender: CustomInputRender,
4785
+ editor
4786
+ }) => {
4787
+ const modeConfig = useMemo20(() => modeValueConfig.find((v) => v.mode === mode), [mode]);
4788
+ const [visible, setVisible] = useState20(false);
4789
+ const [typeEditorValue, setTypeEditorValue] = useState20(
4790
+ modeConfig.toolConfig.createByData.genDefaultValue()
4791
+ );
4792
+ const [errorEmpty, setErrorEmpty] = useState20(false);
4793
+ const handleClose = useCallback10(() => {
4794
+ setVisible(false);
4795
+ setTypeEditorValue(
4796
+ modeConfig.toolConfig.createByData.genDefaultValue()
4797
+ );
4798
+ }, [modeConfig]);
4799
+ const handleOk = useCallback10(async () => {
4800
+ if (editor) {
4801
+ editor.setValue(typeEditorValue);
4802
+ handleClose();
4803
+ }
4804
+ }, [handleClose, typeEditorValue, editor]);
4805
+ const onChange = debounce((newVal) => {
4806
+ const parsedValue = typeEditorUtils.jsonParse(newVal);
4807
+ const error = newVal && !(parsedValue && typeof parsedValue === "object" && !Array.isArray(parsedValue));
4808
+ if (!error) {
4809
+ setTypeEditorValue(
4810
+ modeConfig.commonValueToSubmitValue(parsedValue)
4811
+ );
4812
+ setErrorEmpty(false);
4813
+ } else if (parsedValue) {
4814
+ setErrorEmpty(true);
4815
+ }
4816
+ }, 500);
4817
+ return /* @__PURE__ */ React39.createElement("div", null, /* @__PURE__ */ React39.createElement(Button2, { disabled, size: "small", onClick: () => setVisible(true) }, "Import from JSON"), /* @__PURE__ */ React39.createElement(
4818
+ Modal,
4819
+ {
4820
+ okText: `Import`,
4821
+ width: 960,
4822
+ okButtonProps: {},
4823
+ cancelText: "Cancel",
4824
+ title: "Import from JSON",
4825
+ visible,
4826
+ onOk: handleOk,
4827
+ onCancel: handleClose
4828
+ },
4829
+ /* @__PURE__ */ React39.createElement(DataTransform, null, /* @__PURE__ */ React39.createElement("div", { style: { height: "100%", flex: 1 } }, CustomInputRender ? /* @__PURE__ */ React39.createElement(CustomInputRender, { value: "{}", onChange }) : /* @__PURE__ */ React39.createElement(TextArea, { defaultValue: "{}", onChange })), /* @__PURE__ */ React39.createElement(Divider, { layout: "vertical", style: { height: "100%" } }), /* @__PURE__ */ React39.createElement(Space4, { align: "start", vertical: true, style: { height: "100%", flex: 1 } }, /* @__PURE__ */ React39.createElement("div", { style: { height: "100%", flex: 1, overflowY: "scroll" } }, /* @__PURE__ */ React39.createElement(
4830
+ TypeEditorTable,
4831
+ {
4832
+ readonly: true,
4833
+ mode,
4834
+ forceUpdate: true,
4835
+ value: errorEmpty ? void 0 : typeEditorValue,
4836
+ customEmptyNode: errorEmpty ? /* @__PURE__ */ React39.createElement(
4837
+ Empty2,
4838
+ {
4839
+ style: { marginTop: 40 },
4840
+ image: /* @__PURE__ */ React39.createElement(IllustrationFailure, { style: { width: 100, height: 100 } }),
4841
+ darkModeImage: /* @__PURE__ */ React39.createElement(IllustrationFailureDark, { style: { width: 100, height: 100 } }),
4842
+ description: "Invalid value"
4843
+ }
4844
+ ) : void 0,
4845
+ viewConfigs: modeConfig.toolConfig.createByData.viewConfig
4846
+ }
4847
+ ))))
4848
+ ));
4849
+ };
4850
+
4851
+ // src/components/type-editor/tool-bar.tsx
4852
+ var ToolBar = ({
4853
+ mode,
4854
+ editor,
4855
+ toolbarConfig = []
4856
+ }) => {
4857
+ const config = useMemo21(() => {
4858
+ const res = /* @__PURE__ */ new Map();
4859
+ toolbarConfig.forEach((tool) => {
4860
+ if (typeof tool === "string") {
4861
+ res.set(tool, { type: tool });
4862
+ } else {
4863
+ res.set(tool.type, tool);
4864
+ }
4865
+ });
4866
+ return res;
4867
+ }, [toolbarConfig]);
4868
+ const importConfig = config.get("Import" /* Import */);
4869
+ return /* @__PURE__ */ React40.createElement("div", { style: { width: "100%" } }, editor && /* @__PURE__ */ React40.createElement(Space5, { style: { float: "right" } }, /* @__PURE__ */ React40.createElement(React40.Fragment, null, importConfig && /* @__PURE__ */ React40.createElement(React40.Fragment, null, importConfig.disabled ? /* @__PURE__ */ React40.createElement(Tooltip13, { content: importConfig.disabled }, /* @__PURE__ */ React40.createElement(CreateByData, { disabled: true, mode, editor })) : /* @__PURE__ */ React40.createElement(
4870
+ CreateByData,
4871
+ {
4872
+ mode,
4873
+ customInputRender: importConfig.customInputRender,
4874
+ editor
4875
+ }
4876
+ ))), config.has("UndoRedo" /* UndoRedo */) && /* @__PURE__ */ React40.createElement(UndoRedo, { editor })));
4877
+ };
4878
+
4879
+ // src/components/type-editor/index.tsx
4880
+ var TypeEditorContainer = (props, ref) => {
4881
+ const [instance, setInstance] = useState21();
4882
+ useImperativeHandle2(ref, () => ({
4883
+ getContainer: () => instance?.getContainer(),
4884
+ setValue: instance?.setValue || noop2,
4885
+ getService: instance?.getService || (() => void 0),
4886
+ undo: instance?.undo || noop2,
4887
+ redo: instance?.redo || noop2,
4888
+ getValue() {
4889
+ return instance?.getValue();
4890
+ },
4891
+ getOperator() {
4892
+ return instance?.getOperator();
4893
+ }
4894
+ }));
4895
+ return /* @__PURE__ */ React41.createElement(Space6, { spacing: 4, vertical: true }, instance && /* @__PURE__ */ React41.createElement(ToolBar, { ...props, editor: instance }), /* @__PURE__ */ React41.createElement(
4896
+ TypeEditorTable,
4897
+ {
4898
+ onInit: (editor) => {
4899
+ setInstance(editor.current);
4900
+ },
4901
+ ...props
4902
+ }
4903
+ ));
4904
+ };
4905
+ var TypeEditor = fixedTSForwardRef(TypeEditorContainer);
4906
+
4907
+ // src/index.ts
4908
+ export * from "@flowgram.ai/json-schema";
4909
+
4910
+ // src/preset/object-type-editor/index.tsx
4911
+ import React42, { useMemo as useMemo22 } from "react";
4912
+ var defaultViewConfigs = [
4913
+ {
4914
+ type: "key" /* Key */,
4915
+ visible: true
4916
+ },
4917
+ {
4918
+ type: "type" /* Type */,
4919
+ visible: true
4920
+ },
4921
+ {
4922
+ type: "description" /* Description */,
4923
+ visible: true
4924
+ },
4925
+ {
4926
+ type: "required" /* Required */,
4927
+ visible: true
4928
+ },
4929
+ {
4930
+ type: "default" /* Default */,
4931
+ visible: true
4932
+ },
4933
+ {
4934
+ type: "operate" /* Operate */,
4935
+ visible: true
4936
+ }
4937
+ ];
4938
+ function ObjectTypeEditor(props) {
4939
+ const { value, onChange, config, readonly } = props;
4940
+ const { rootKey = "outputs", viewConfigs = defaultViewConfigs } = config || {};
4941
+ const wrapValue = useMemo22(
4942
+ () => ({
4943
+ type: "object",
4944
+ properties: { [rootKey]: value || { type: "object" } }
4945
+ }),
4946
+ [value, rootKey]
4947
+ );
4948
+ const disableEditColumn = useMemo22(() => {
4949
+ const res = [];
4950
+ if (readonly) {
4951
+ viewConfigs.forEach((v) => {
4952
+ res.push({
4953
+ column: v.type,
4954
+ reason: "This field is not editable."
4955
+ });
4956
+ });
4957
+ }
4958
+ return res;
4959
+ }, [readonly, viewConfigs]);
4960
+ return /* @__PURE__ */ React42.createElement("div", null, /* @__PURE__ */ React42.createElement(
4961
+ TypeEditor,
4962
+ {
4963
+ readonly,
4964
+ mode: "type-definition",
4965
+ toolbarConfig: ["Import" /* Import */, "UndoRedo" /* UndoRedo */],
4966
+ rootLevel: 1,
4967
+ value: wrapValue,
4968
+ disableEditColumn,
4969
+ onChange: (_v) => onChange?.(_v?.properties?.[rootKey]),
4970
+ onCustomSetValue: (newType) => ({
4971
+ type: "object",
4972
+ properties: {
4973
+ [rootKey]: newType
4974
+ }
4975
+ }),
4976
+ getRootSchema: (type) => type.properties[rootKey],
4977
+ viewConfigs: defaultViewConfigs,
4978
+ onEditRowDataSource: (dataSource) => {
4979
+ if (dataSource[0]) {
4980
+ dataSource[0].disableEditColumn = [
4981
+ {
4982
+ column: "key" /* Key */,
4983
+ reason: "This field is not editable."
4984
+ },
4985
+ {
4986
+ column: "type" /* Type */,
4987
+ reason: "This field is not editable."
4988
+ },
4989
+ {
4990
+ column: "required" /* Required */,
4991
+ reason: "This field is not editable."
4992
+ },
4993
+ {
4994
+ column: "default" /* Default */,
4995
+ reason: "This field is not editable."
4996
+ },
4997
+ {
4998
+ column: "operate" /* Operate */,
4999
+ reason: "This field is not editable."
5000
+ }
5001
+ ];
5002
+ dataSource[0].cannotDrag = true;
5003
+ }
5004
+ return dataSource;
5005
+ }
5006
+ }
5007
+ ));
5008
+ }
5009
+ export {
5010
+ ObjectTypeEditor,
5011
+ ToolbarKey,
5012
+ TypeEditor,
5013
+ columnConfigs as TypeEditorColumnConfigs,
5014
+ TypeEditorColumnType,
5015
+ TypeEditorContext,
5016
+ TypeEditorRegistryManager,
5017
+ TypeEditorService,
5018
+ TypeSelector,
5019
+ columnConfigs as typeEditorColumnConfigs
5020
+ };
5021
+ //# sourceMappingURL=index.js.map