@flowgram.ai/document 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.js +40 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +40 -4
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -308,7 +308,7 @@ declare class FlowDocument<T = FlowDocumentJSON> implements Disposable {
|
|
|
308
308
|
* @param data
|
|
309
309
|
* @param addedNodes
|
|
310
310
|
*/
|
|
311
|
-
addNode(data: AddNodeData, addedNodes?: FlowNodeEntity[], ignoreCreateAndUpdateEvent?: boolean): FlowNodeEntity;
|
|
311
|
+
addNode(data: AddNodeData, addedNodes?: FlowNodeEntity[], ignoreCreateAndUpdateEvent?: boolean, ignoreBlocks?: boolean): FlowNodeEntity;
|
|
312
312
|
addBlocksAsChildren(parent: FlowNodeEntity, blocks: FlowNodeJSON[], addedNodes?: FlowNodeEntity[]): void;
|
|
313
313
|
/**
|
|
314
314
|
* block 格式:
|
|
@@ -342,6 +342,12 @@ declare class FlowDocument<T = FlowDocumentJSON> implements Disposable {
|
|
|
342
342
|
* @param registries
|
|
343
343
|
*/
|
|
344
344
|
registerFlowNodes<T extends FlowNodeRegistry<any>>(...registries: T[]): void;
|
|
345
|
+
/**
|
|
346
|
+
* Check node extend
|
|
347
|
+
* @param currentType
|
|
348
|
+
* @param parentType
|
|
349
|
+
*/
|
|
350
|
+
isExtend(currentType: FlowNodeType, parentType: FlowNodeType): boolean;
|
|
345
351
|
/**
|
|
346
352
|
* 导出数据,可以重载
|
|
347
353
|
*/
|
|
@@ -1128,12 +1134,17 @@ interface FlowNodeRegistry<M extends FlowNodeMeta = FlowNodeMeta> {
|
|
|
1128
1134
|
hidden?: boolean;
|
|
1129
1135
|
index?: number;
|
|
1130
1136
|
}) => FlowNodeEntity;
|
|
1137
|
+
/**
|
|
1138
|
+
* 内部用于继承逻辑判断,不要使用
|
|
1139
|
+
*/
|
|
1140
|
+
__extends__?: FlowNodeType[];
|
|
1131
1141
|
/**
|
|
1132
1142
|
* 扩展注册器
|
|
1133
1143
|
*/
|
|
1134
1144
|
[key: string]: any;
|
|
1135
1145
|
}
|
|
1136
1146
|
declare namespace FlowNodeRegistry {
|
|
1147
|
+
function mergeChildRegistries(r1?: FlowNodeRegistry[], r2?: FlowNodeRegistry[]): FlowNodeRegistry[];
|
|
1137
1148
|
function merge(registry1: FlowNodeRegistry, registry2: FlowNodeRegistry, finalType: FlowNodeType): FlowNodeRegistry;
|
|
1138
1149
|
function extend(registry: FlowNodeRegistry, extendRegistries: FlowNodeRegistry[]): FlowNodeRegistry;
|
|
1139
1150
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -308,7 +308,7 @@ declare class FlowDocument<T = FlowDocumentJSON> implements Disposable {
|
|
|
308
308
|
* @param data
|
|
309
309
|
* @param addedNodes
|
|
310
310
|
*/
|
|
311
|
-
addNode(data: AddNodeData, addedNodes?: FlowNodeEntity[], ignoreCreateAndUpdateEvent?: boolean): FlowNodeEntity;
|
|
311
|
+
addNode(data: AddNodeData, addedNodes?: FlowNodeEntity[], ignoreCreateAndUpdateEvent?: boolean, ignoreBlocks?: boolean): FlowNodeEntity;
|
|
312
312
|
addBlocksAsChildren(parent: FlowNodeEntity, blocks: FlowNodeJSON[], addedNodes?: FlowNodeEntity[]): void;
|
|
313
313
|
/**
|
|
314
314
|
* block 格式:
|
|
@@ -342,6 +342,12 @@ declare class FlowDocument<T = FlowDocumentJSON> implements Disposable {
|
|
|
342
342
|
* @param registries
|
|
343
343
|
*/
|
|
344
344
|
registerFlowNodes<T extends FlowNodeRegistry<any>>(...registries: T[]): void;
|
|
345
|
+
/**
|
|
346
|
+
* Check node extend
|
|
347
|
+
* @param currentType
|
|
348
|
+
* @param parentType
|
|
349
|
+
*/
|
|
350
|
+
isExtend(currentType: FlowNodeType, parentType: FlowNodeType): boolean;
|
|
345
351
|
/**
|
|
346
352
|
* 导出数据,可以重载
|
|
347
353
|
*/
|
|
@@ -1128,12 +1134,17 @@ interface FlowNodeRegistry<M extends FlowNodeMeta = FlowNodeMeta> {
|
|
|
1128
1134
|
hidden?: boolean;
|
|
1129
1135
|
index?: number;
|
|
1130
1136
|
}) => FlowNodeEntity;
|
|
1137
|
+
/**
|
|
1138
|
+
* 内部用于继承逻辑判断,不要使用
|
|
1139
|
+
*/
|
|
1140
|
+
__extends__?: FlowNodeType[];
|
|
1131
1141
|
/**
|
|
1132
1142
|
* 扩展注册器
|
|
1133
1143
|
*/
|
|
1134
1144
|
[key: string]: any;
|
|
1135
1145
|
}
|
|
1136
1146
|
declare namespace FlowNodeRegistry {
|
|
1147
|
+
function mergeChildRegistries(r1?: FlowNodeRegistry[], r2?: FlowNodeRegistry[]): FlowNodeRegistry[];
|
|
1137
1148
|
function merge(registry1: FlowNodeRegistry, registry2: FlowNodeRegistry, finalType: FlowNodeType): FlowNodeRegistry;
|
|
1138
1149
|
function extend(registry: FlowNodeRegistry, extendRegistries: FlowNodeRegistry[]): FlowNodeRegistry;
|
|
1139
1150
|
}
|
package/dist/index.js
CHANGED
|
@@ -239,13 +239,37 @@ var DEFAULT_FLOW_NODE_META = (nodeType, document) => {
|
|
|
239
239
|
};
|
|
240
240
|
var FlowNodeRegistry;
|
|
241
241
|
((FlowNodeRegistry4) => {
|
|
242
|
+
function mergeChildRegistries(r1 = [], r2 = []) {
|
|
243
|
+
if (r1.length === 0 || r2.length === 0) {
|
|
244
|
+
return [...r1, ...r2];
|
|
245
|
+
}
|
|
246
|
+
const r1Filter = r1.map((r1Current) => {
|
|
247
|
+
const r2Current = r2.find((n) => n.type === r1Current.type);
|
|
248
|
+
if (r2Current) {
|
|
249
|
+
return merge(r1Current, r2Current, r1Current.type);
|
|
250
|
+
}
|
|
251
|
+
return r1Current;
|
|
252
|
+
});
|
|
253
|
+
const r2Filter = r2.filter((n) => !r1.some((r) => r.type === n.type));
|
|
254
|
+
return [...r1Filter, ...r2Filter];
|
|
255
|
+
}
|
|
256
|
+
FlowNodeRegistry4.mergeChildRegistries = mergeChildRegistries;
|
|
242
257
|
function merge(registry1, registry2, finalType) {
|
|
258
|
+
const extendKeys = registry1.__extends__ ? registry1.__extends__.slice() : [];
|
|
259
|
+
if (registry1.type !== registry2.type) {
|
|
260
|
+
extendKeys.unshift(registry1.type);
|
|
261
|
+
}
|
|
243
262
|
return {
|
|
244
263
|
...registry1,
|
|
245
264
|
...registry2,
|
|
265
|
+
extendChildRegistries: mergeChildRegistries(
|
|
266
|
+
registry1.extendChildRegistries,
|
|
267
|
+
registry2.extendChildRegistries
|
|
268
|
+
),
|
|
246
269
|
meta: { ...registry1.meta, ...registry2.meta },
|
|
247
270
|
extend: void 0,
|
|
248
|
-
type: finalType
|
|
271
|
+
type: finalType,
|
|
272
|
+
__extends__: extendKeys
|
|
249
273
|
};
|
|
250
274
|
}
|
|
251
275
|
FlowNodeRegistry4.merge = merge;
|
|
@@ -1827,7 +1851,7 @@ var FlowDocument = class {
|
|
|
1827
1851
|
* @param data
|
|
1828
1852
|
* @param addedNodes
|
|
1829
1853
|
*/
|
|
1830
|
-
addNode(data, addedNodes, ignoreCreateAndUpdateEvent) {
|
|
1854
|
+
addNode(data, addedNodes, ignoreCreateAndUpdateEvent, ignoreBlocks) {
|
|
1831
1855
|
const { id, type = "block", originParent, parent, meta, hidden, index } = data;
|
|
1832
1856
|
let node = this.getNode(id);
|
|
1833
1857
|
let isNew = false;
|
|
@@ -1869,7 +1893,7 @@ var FlowDocument = class {
|
|
|
1869
1893
|
if (extendNodes && addedNodes) {
|
|
1870
1894
|
addedNodes.push(...extendNodes);
|
|
1871
1895
|
}
|
|
1872
|
-
} else if (data.blocks && data.blocks.length > 0) {
|
|
1896
|
+
} else if (data.blocks && data.blocks.length > 0 && !ignoreBlocks) {
|
|
1873
1897
|
if (!data.blocks[0].type) {
|
|
1874
1898
|
this.addInlineBlocks(node, data.blocks, addedNodes);
|
|
1875
1899
|
} else {
|
|
@@ -1995,10 +2019,22 @@ var FlowDocument = class {
|
|
|
1995
2019
|
meta: {
|
|
1996
2020
|
...preRegistry?.meta,
|
|
1997
2021
|
...newRegistry?.meta
|
|
1998
|
-
}
|
|
2022
|
+
},
|
|
2023
|
+
extendChildRegistries: FlowNodeRegistry.mergeChildRegistries(
|
|
2024
|
+
preRegistry?.extendChildRegistries,
|
|
2025
|
+
newRegistry?.extendChildRegistries
|
|
2026
|
+
)
|
|
1999
2027
|
});
|
|
2000
2028
|
});
|
|
2001
2029
|
}
|
|
2030
|
+
/**
|
|
2031
|
+
* Check node extend
|
|
2032
|
+
* @param currentType
|
|
2033
|
+
* @param parentType
|
|
2034
|
+
*/
|
|
2035
|
+
isExtend(currentType, parentType) {
|
|
2036
|
+
return (this.getNodeRegistry(currentType).__extends__ || []).includes(parentType);
|
|
2037
|
+
}
|
|
2002
2038
|
/**
|
|
2003
2039
|
* 导出数据,可以重载
|
|
2004
2040
|
*/
|