@inditextech/weave-sdk 2.14.0 → 2.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/sdk.d.ts +70 -35
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +178 -120
- package/dist/sdk.js.map +1 -1
- package/dist/sdk.node.d.ts +51 -16
- package/dist/sdk.node.d.ts.map +1 -1
- package/dist/sdk.node.js +178 -120
- package/dist/sdk.node.js.map +1 -1
- package/package.json +2 -2
package/dist/sdk.node.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Konva from "konva";
|
|
2
2
|
import { randomFillSync, randomUUID } from "crypto";
|
|
3
3
|
import pino from "pino";
|
|
4
|
-
import { WEAVE_ASYNC_STATUS, WEAVE_AWARENESS_LAYER_ID, WEAVE_EXPORT_BACKGROUND_COLOR, WEAVE_EXPORT_FORMATS, WEAVE_INSTANCE_STATUS, WEAVE_KONVA_BACKEND, WEAVE_LOG_LEVEL, WEAVE_NODE_CUSTOM_EVENTS, WEAVE_NODE_LAYER_ID, WEAVE_NODE_POSITION, WEAVE_STORE_CONNECTION_STATUS, WEAVE_UTILITY_LAYER_ID } from "@inditextech/weave-types";
|
|
4
|
+
import { WEAVE_ASYNC_STATUS, WEAVE_AWARENESS_LAYER_ID, WEAVE_EXPORT_BACKGROUND_COLOR, WEAVE_EXPORT_FORMATS, WEAVE_INSTANCE_STATUS, WEAVE_KONVA_BACKEND, WEAVE_LOG_LEVEL, WEAVE_NODE_CHANGE_TYPE, WEAVE_NODE_CUSTOM_EVENTS, WEAVE_NODE_LAYER_ID, WEAVE_NODE_POSITION, WEAVE_STORE_CONNECTION_STATUS, WEAVE_UTILITY_LAYER_ID } from "@inditextech/weave-types";
|
|
5
5
|
import { getYjsDoc, getYjsValue, observeDeep, syncedStore } from "@syncedstore/core";
|
|
6
6
|
import * as Y from "yjs";
|
|
7
7
|
import React from "react";
|
|
@@ -15141,7 +15141,6 @@ var WeaveStore = class {
|
|
|
15141
15141
|
}
|
|
15142
15142
|
observeDeep(this.getState(), () => {
|
|
15143
15143
|
const newState = JSON.parse(JSON.stringify(this.getState()));
|
|
15144
|
-
this.logger.debug({ newState }, "State changed");
|
|
15145
15144
|
this.instance.emitEvent("onStateChange", newState);
|
|
15146
15145
|
const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
15147
15146
|
if (this.isRoomLoaded && nodesSelectionPlugin?.getSelectedNodes().length === 1) {
|
|
@@ -17675,8 +17674,11 @@ function moveNodeToContainer(instance, node, containerToMove, originalNode, orig
|
|
|
17675
17674
|
if (nodeHandler) {
|
|
17676
17675
|
instance.stateTransactional(() => {
|
|
17677
17676
|
const actualNode = nodeHandler.serialize(node);
|
|
17678
|
-
instance.removeNodeNT(actualNode);
|
|
17679
|
-
instance.addNodeNT(actualNode, layerToMoveAttrs.id
|
|
17677
|
+
instance.removeNodeNT(actualNode, { emitUserChangeEvent: false });
|
|
17678
|
+
instance.addNodeNT(actualNode, layerToMoveAttrs.id, {
|
|
17679
|
+
emitUserChangeEvent: true,
|
|
17680
|
+
overrideUserChangeType: WEAVE_NODE_CHANGE_TYPE.UPDATE
|
|
17681
|
+
});
|
|
17680
17682
|
});
|
|
17681
17683
|
return true;
|
|
17682
17684
|
}
|
|
@@ -18591,6 +18593,10 @@ const WEAVE_NODES_MULTI_SELECTION_FEEDBACK_PLUGIN_DEFAULT_CONFIG = { style: {
|
|
|
18591
18593
|
//#endregion
|
|
18592
18594
|
//#region src/constants.ts
|
|
18593
18595
|
const DEFAULT_THROTTLE_MS = 50;
|
|
18596
|
+
const DEFAULT_ADD_NODE_OPTIONS = { emitUserChangeEvent: true };
|
|
18597
|
+
const DEFAULT_UPDATE_NODE_OPTIONS = { emitUserChangeEvent: true };
|
|
18598
|
+
const DEFAULT_REMOVE_NODE_OPTIONS = { emitUserChangeEvent: true };
|
|
18599
|
+
const DEFAULT_MOVE_NODE_OPTIONS = { emitUserChangeEvent: true };
|
|
18594
18600
|
|
|
18595
18601
|
//#endregion
|
|
18596
18602
|
//#region src/plugins/users-presence/constants.ts
|
|
@@ -21148,7 +21154,7 @@ var WeaveGroupsManager = class {
|
|
|
21148
21154
|
const groupHandler = this.instance.getNodeHandler("group");
|
|
21149
21155
|
if (groupHandler) {
|
|
21150
21156
|
const groupNode$1 = groupHandler.create(groupId, { draggable: true });
|
|
21151
|
-
this.instance.addNode(groupNode$1, parentNodeId);
|
|
21157
|
+
this.instance.addNode(groupNode$1, parentNodeId, { emitUserChangeEvent: false });
|
|
21152
21158
|
}
|
|
21153
21159
|
const nodesWithZIndex = realNodes.map((node) => {
|
|
21154
21160
|
const instance = mainLayer?.findOne(`#${node.key}`);
|
|
@@ -21174,7 +21180,7 @@ var WeaveGroupsManager = class {
|
|
|
21174
21180
|
const handler = this.instance.getNodeHandler("group");
|
|
21175
21181
|
if (handler) {
|
|
21176
21182
|
const stateNode = handler.serialize(konvaGroup);
|
|
21177
|
-
this.instance.addNode(stateNode, groupId);
|
|
21183
|
+
this.instance.addNode(stateNode, groupId, { emitUserChangeEvent: false });
|
|
21178
21184
|
}
|
|
21179
21185
|
}
|
|
21180
21186
|
continue;
|
|
@@ -21192,7 +21198,7 @@ var WeaveGroupsManager = class {
|
|
|
21192
21198
|
const handler = this.instance.getNodeHandler(konvaNode.getAttrs().nodeType);
|
|
21193
21199
|
if (handler) {
|
|
21194
21200
|
const stateNode = handler.serialize(konvaNode);
|
|
21195
|
-
this.instance.addNode(stateNode, groupId);
|
|
21201
|
+
this.instance.addNode(stateNode, groupId, { emitUserChangeEvent: false });
|
|
21196
21202
|
}
|
|
21197
21203
|
}
|
|
21198
21204
|
}
|
|
@@ -21277,7 +21283,7 @@ var WeaveGroupsManager = class {
|
|
|
21277
21283
|
const groupHandler = this.instance.getNodeHandler("group");
|
|
21278
21284
|
if (groupHandler) {
|
|
21279
21285
|
const groupNode = groupHandler.serialize(konvaGroup);
|
|
21280
|
-
this.instance.removeNode(groupNode);
|
|
21286
|
+
this.instance.removeNode(groupNode, { emitUserChangeEvent: false });
|
|
21281
21287
|
}
|
|
21282
21288
|
setTimeout(() => {
|
|
21283
21289
|
this.getNodesMultiSelectionFeedbackPlugin()?.cleanupSelectedHalos();
|
|
@@ -21622,76 +21628,6 @@ var WeaveCloningManager = class {
|
|
|
21622
21628
|
minPoint
|
|
21623
21629
|
};
|
|
21624
21630
|
}
|
|
21625
|
-
cloneNodes(instancesToClone, targetContainer, onPoint) {
|
|
21626
|
-
if (instancesToClone.length === 0) return;
|
|
21627
|
-
if (!targetContainer) return;
|
|
21628
|
-
const groupId = v4_default();
|
|
21629
|
-
const newGroup = new Konva.Group({ id: groupId });
|
|
21630
|
-
targetContainer.add(newGroup);
|
|
21631
|
-
const nodesWithZIndex = instancesToClone.map((node) => ({
|
|
21632
|
-
node,
|
|
21633
|
-
zIndex: node.zIndex()
|
|
21634
|
-
})).filter((node) => node.zIndex !== -1);
|
|
21635
|
-
const sortedNodesByZIndex = (0, import_lodash.orderBy)(nodesWithZIndex, ["zIndex"], ["asc"]).map((node) => node.node);
|
|
21636
|
-
for (const [index, node] of sortedNodesByZIndex.entries()) {
|
|
21637
|
-
const nodeAttrs = node.getAttrs();
|
|
21638
|
-
if (nodeAttrs.type === "group") {
|
|
21639
|
-
const clonedNode$1 = node.clone({
|
|
21640
|
-
id: v4_default(),
|
|
21641
|
-
type: "group"
|
|
21642
|
-
});
|
|
21643
|
-
const nodePos$1 = clonedNode$1.getAbsolutePosition();
|
|
21644
|
-
const nodeRotation$1 = clonedNode$1.getAbsoluteRotation();
|
|
21645
|
-
const parent$1 = node.getParent();
|
|
21646
|
-
if (parent$1 && parent$1.getAttrs().nodeId && !parent$1.getAttrs().containerId) {
|
|
21647
|
-
const realParent = this.instance.getStage().findOne(`#${parent$1.getAttrs().nodeId}`);
|
|
21648
|
-
if (realParent) {
|
|
21649
|
-
nodePos$1.x += realParent.x();
|
|
21650
|
-
nodePos$1.y += realParent.y();
|
|
21651
|
-
}
|
|
21652
|
-
}
|
|
21653
|
-
clonedNode$1.moveTo(newGroup);
|
|
21654
|
-
clonedNode$1.zIndex(index);
|
|
21655
|
-
clonedNode$1.setAbsolutePosition(nodePos$1);
|
|
21656
|
-
clonedNode$1.rotation(nodeRotation$1);
|
|
21657
|
-
continue;
|
|
21658
|
-
}
|
|
21659
|
-
const clonedNode = node.clone({ id: v4_default() });
|
|
21660
|
-
const nodePos = clonedNode.getAbsolutePosition();
|
|
21661
|
-
const nodeRotation = clonedNode.getAbsoluteRotation();
|
|
21662
|
-
const parent = node.getParent();
|
|
21663
|
-
if (parent && parent.getAttrs().nodeId && !parent.getAttrs().containerId) {
|
|
21664
|
-
const realParent = this.instance.getStage().findOne(`#${parent.getAttrs().nodeId}`);
|
|
21665
|
-
if (realParent) {
|
|
21666
|
-
nodePos.x += realParent.x();
|
|
21667
|
-
nodePos.y += realParent.y();
|
|
21668
|
-
}
|
|
21669
|
-
}
|
|
21670
|
-
clonedNode.moveTo(newGroup);
|
|
21671
|
-
clonedNode.zIndex(index);
|
|
21672
|
-
clonedNode.setAbsolutePosition(nodePos);
|
|
21673
|
-
clonedNode.rotation(nodeRotation);
|
|
21674
|
-
}
|
|
21675
|
-
const actualPos = newGroup.getClientRect({ relativeTo: targetContainer });
|
|
21676
|
-
newGroup.x(onPoint.x - actualPos.x);
|
|
21677
|
-
newGroup.y(onPoint.y - actualPos.y);
|
|
21678
|
-
const groupChildren = [...newGroup.getChildren()];
|
|
21679
|
-
for (const [index, node] of groupChildren.entries()) {
|
|
21680
|
-
const nodePos = node.getAbsolutePosition();
|
|
21681
|
-
const nodeRotation = node.getAbsoluteRotation();
|
|
21682
|
-
node.moveTo(targetContainer);
|
|
21683
|
-
node.zIndex(index);
|
|
21684
|
-
node.setAbsolutePosition(nodePos);
|
|
21685
|
-
node.rotation(nodeRotation);
|
|
21686
|
-
const handler = this.instance.getNodeHandler(node.getAttrs().nodeType);
|
|
21687
|
-
if (handler) {
|
|
21688
|
-
const stateNode = handler.serialize(node);
|
|
21689
|
-
this.instance.addNode(stateNode, targetContainer.getAttrs().id);
|
|
21690
|
-
}
|
|
21691
|
-
node.destroy();
|
|
21692
|
-
}
|
|
21693
|
-
newGroup.destroy();
|
|
21694
|
-
}
|
|
21695
21631
|
recursivelyUpdateKeys(nodes) {
|
|
21696
21632
|
for (const child of nodes) {
|
|
21697
21633
|
const newNodeId = v4_default();
|
|
@@ -21710,7 +21646,7 @@ var WeaveCloningManager = class {
|
|
|
21710
21646
|
serializedNode.key = newNodeId;
|
|
21711
21647
|
serializedNode.props.id = newNodeId;
|
|
21712
21648
|
const realParent = this.instance.getInstanceRecursive(parent);
|
|
21713
|
-
this.instance.addNode(serializedNode, realParent?.getAttrs().id);
|
|
21649
|
+
this.instance.addNode(serializedNode, realParent?.getAttrs().id, { emitUserChangeEvent: false });
|
|
21714
21650
|
return this.instance.getStage().findOne(`#${newNodeId}`);
|
|
21715
21651
|
}
|
|
21716
21652
|
addClone(node) {
|
|
@@ -21775,7 +21711,7 @@ var WeaveZIndexManager = class {
|
|
|
21775
21711
|
const handler = this.instance.getNodeHandler(instance.getAttrs().nodeType);
|
|
21776
21712
|
if (handler) {
|
|
21777
21713
|
const nodeState = handler.serialize(instance);
|
|
21778
|
-
this.instance.
|
|
21714
|
+
this.instance.zMoveNode(nodeState, WEAVE_NODE_POSITION.UP);
|
|
21779
21715
|
}
|
|
21780
21716
|
}
|
|
21781
21717
|
moveDown(instance) {
|
|
@@ -21783,7 +21719,7 @@ var WeaveZIndexManager = class {
|
|
|
21783
21719
|
const handler = this.instance.getNodeHandler(instance.getAttrs().nodeType);
|
|
21784
21720
|
if (handler) {
|
|
21785
21721
|
const nodeState = handler.serialize(instance);
|
|
21786
|
-
this.instance.
|
|
21722
|
+
this.instance.zMoveNode(nodeState, WEAVE_NODE_POSITION.DOWN);
|
|
21787
21723
|
}
|
|
21788
21724
|
}
|
|
21789
21725
|
sendToBack(instances) {
|
|
@@ -21793,7 +21729,7 @@ var WeaveZIndexManager = class {
|
|
|
21793
21729
|
const handler = this.instance.getNodeHandler(node.getAttrs().nodeType);
|
|
21794
21730
|
if (handler) {
|
|
21795
21731
|
const nodeState = handler.serialize(node);
|
|
21796
|
-
this.instance.
|
|
21732
|
+
this.instance.zMoveNode(nodeState, WEAVE_NODE_POSITION.BACK);
|
|
21797
21733
|
}
|
|
21798
21734
|
}
|
|
21799
21735
|
}
|
|
@@ -21804,7 +21740,7 @@ var WeaveZIndexManager = class {
|
|
|
21804
21740
|
const handler = this.instance.getNodeHandler(node.getAttrs().nodeType);
|
|
21805
21741
|
if (handler) {
|
|
21806
21742
|
const nodeState = handler.serialize(node);
|
|
21807
|
-
this.instance.
|
|
21743
|
+
this.instance.zMoveNode(nodeState, WEAVE_NODE_POSITION.FRONT);
|
|
21808
21744
|
}
|
|
21809
21745
|
}
|
|
21810
21746
|
}
|
|
@@ -21999,7 +21935,7 @@ var WeaveStateManager = class {
|
|
|
21999
21935
|
this.instance.emitEvent("onNodeRemoved", node);
|
|
22000
21936
|
}
|
|
22001
21937
|
}
|
|
22002
|
-
|
|
21938
|
+
zMoveNode(node, position) {
|
|
22003
21939
|
const state = this.instance.getStore().getState();
|
|
22004
21940
|
if ((0, import_lodash.isEmpty)(state.weave)) {
|
|
22005
21941
|
const msg = `State is empty, cannot update the node`;
|
|
@@ -22121,7 +22057,7 @@ var WeaveRegisterManager = class {
|
|
|
22121
22057
|
|
|
22122
22058
|
//#endregion
|
|
22123
22059
|
//#region package.json
|
|
22124
|
-
var version = "2.
|
|
22060
|
+
var version = "2.15.0";
|
|
22125
22061
|
|
|
22126
22062
|
//#endregion
|
|
22127
22063
|
//#region src/managers/setup.ts
|
|
@@ -23067,6 +23003,52 @@ var Weave = class {
|
|
|
23067
23003
|
this.moduleLogger.debug(`Removing listening to event [${event}]`);
|
|
23068
23004
|
this.emitter.off(event, callback);
|
|
23069
23005
|
}
|
|
23006
|
+
emitUserChangeEvent(data, changeType) {
|
|
23007
|
+
const stage = this.getStage();
|
|
23008
|
+
const user = this.getStore().getUser();
|
|
23009
|
+
const node = data.node;
|
|
23010
|
+
let parent = void 0;
|
|
23011
|
+
let nodeParent = void 0;
|
|
23012
|
+
if (nodeParent === void 0 && data?.parentId !== void 0 && stage) nodeParent = stage.findOne(`#${data.parentId}`);
|
|
23013
|
+
if (nodeParent === void 0 && data?.parentId === void 0 && stage) {
|
|
23014
|
+
const parentNode = stage.findOne(`#${node.key}`);
|
|
23015
|
+
if (parentNode) nodeParent = this.getNodeContainer(parentNode);
|
|
23016
|
+
}
|
|
23017
|
+
if (nodeParent !== void 0) {
|
|
23018
|
+
const handler = this.getNodeHandler(nodeParent?.getAttrs().nodeType);
|
|
23019
|
+
if (handler) parent = handler.serialize(nodeParent);
|
|
23020
|
+
}
|
|
23021
|
+
if (!parent) return;
|
|
23022
|
+
this.emitEvent("onUserChange", {
|
|
23023
|
+
user,
|
|
23024
|
+
changeType,
|
|
23025
|
+
parent,
|
|
23026
|
+
node
|
|
23027
|
+
});
|
|
23028
|
+
this.cleanupTransactionIdToInstance(node);
|
|
23029
|
+
}
|
|
23030
|
+
setTransactionIdToInstance(node) {
|
|
23031
|
+
const realNode = this.getStage().findOne(`#${node.key}`);
|
|
23032
|
+
if (realNode) {
|
|
23033
|
+
node.props.transactionId = v4_default();
|
|
23034
|
+
realNode.setAttr("transactionId", node.props.transactionId);
|
|
23035
|
+
}
|
|
23036
|
+
}
|
|
23037
|
+
cleanupTransactionIdToInstance(node) {
|
|
23038
|
+
const realNode = this.getStage().findOne(`#${node.key}`);
|
|
23039
|
+
if (realNode) realNode.setAttr("transactionId", void 0);
|
|
23040
|
+
}
|
|
23041
|
+
decorateWithZIndex(node) {
|
|
23042
|
+
const realNode = this.getStage().findOne(`#${node.key}`);
|
|
23043
|
+
if (realNode) {
|
|
23044
|
+
const zIndex = realNode.zIndex();
|
|
23045
|
+
node.props = {
|
|
23046
|
+
...node.props,
|
|
23047
|
+
zIndex
|
|
23048
|
+
};
|
|
23049
|
+
}
|
|
23050
|
+
return node;
|
|
23051
|
+
}
|
|
23070
23052
|
getLogger() {
|
|
23071
23053
|
return this.logger;
|
|
23072
23054
|
}
|
|
@@ -23183,12 +23165,12 @@ var Weave = class {
|
|
|
23183
23165
|
update(newState) {
|
|
23184
23166
|
this.getStore().setState(newState);
|
|
23185
23167
|
this.renderer.render(() => {
|
|
23186
|
-
this.emitEvent("onRender"
|
|
23168
|
+
this.emitEvent("onRender");
|
|
23187
23169
|
});
|
|
23188
23170
|
}
|
|
23189
23171
|
render() {
|
|
23190
23172
|
this.renderer.render(() => {
|
|
23191
|
-
this.emitEvent("onRender"
|
|
23173
|
+
this.emitEvent("onRender");
|
|
23192
23174
|
});
|
|
23193
23175
|
}
|
|
23194
23176
|
findNodeById(tree, key, parent = null, index = -1) {
|
|
@@ -23200,43 +23182,102 @@ var Weave = class {
|
|
|
23200
23182
|
getNode(nodeKey) {
|
|
23201
23183
|
return this.stateManager.getNode(nodeKey);
|
|
23202
23184
|
}
|
|
23203
|
-
addNode(node, parentId = "mainLayer",
|
|
23185
|
+
addNode(node, parentId = "mainLayer", options = DEFAULT_ADD_NODE_OPTIONS) {
|
|
23204
23186
|
this.stateTransactional(() => {
|
|
23205
|
-
this.
|
|
23187
|
+
this.addNodeNT(node, parentId, options);
|
|
23206
23188
|
});
|
|
23207
23189
|
}
|
|
23208
|
-
addNodeNT(node, parentId = "mainLayer",
|
|
23190
|
+
addNodeNT(node, parentId = "mainLayer", options = DEFAULT_ADD_NODE_OPTIONS) {
|
|
23191
|
+
const { index, emitUserChangeEvent, overrideUserChangeType } = mergeExceptArrays(DEFAULT_ADD_NODE_OPTIONS, options);
|
|
23192
|
+
if (emitUserChangeEvent) this.setTransactionIdToInstance(node);
|
|
23209
23193
|
this.stateManager.addNode(node, parentId, index);
|
|
23194
|
+
if (emitUserChangeEvent) {
|
|
23195
|
+
const handleSendEvent = (addedNode) => {
|
|
23196
|
+
if (node.props.transactionId === addedNode.getAttrs().transactionId) {
|
|
23197
|
+
const decoratedNode = this.decorateWithZIndex(node);
|
|
23198
|
+
this.emitUserChangeEvent({
|
|
23199
|
+
node: decoratedNode,
|
|
23200
|
+
parentId
|
|
23201
|
+
}, overrideUserChangeType ?? WEAVE_NODE_CHANGE_TYPE.CREATE);
|
|
23202
|
+
this.removeEventListener("onNodeRenderedAdded", handleSendEvent);
|
|
23203
|
+
}
|
|
23204
|
+
};
|
|
23205
|
+
this.addEventListener("onNodeRenderedAdded", handleSendEvent);
|
|
23206
|
+
}
|
|
23210
23207
|
}
|
|
23211
|
-
updateNode(node) {
|
|
23208
|
+
updateNode(node, options = DEFAULT_UPDATE_NODE_OPTIONS) {
|
|
23212
23209
|
this.stateTransactional(() => {
|
|
23213
|
-
this.
|
|
23210
|
+
this.updateNodeNT(node, options);
|
|
23214
23211
|
});
|
|
23215
23212
|
}
|
|
23216
|
-
updateNodeNT(node) {
|
|
23213
|
+
updateNodeNT(node, options = DEFAULT_UPDATE_NODE_OPTIONS) {
|
|
23214
|
+
const { emitUserChangeEvent } = mergeExceptArrays(DEFAULT_UPDATE_NODE_OPTIONS, options);
|
|
23215
|
+
if (emitUserChangeEvent) this.setTransactionIdToInstance(node);
|
|
23217
23216
|
this.stateManager.updateNode(node);
|
|
23217
|
+
if (emitUserChangeEvent) {
|
|
23218
|
+
const handleSendEvent = (updatedNode) => {
|
|
23219
|
+
if (node.props.transactionId === updatedNode.getAttrs().transactionId) {
|
|
23220
|
+
const decoratedNode = this.decorateWithZIndex(node);
|
|
23221
|
+
this.emitUserChangeEvent({ node: decoratedNode }, WEAVE_NODE_CHANGE_TYPE.UPDATE);
|
|
23222
|
+
this.removeEventListener("onNodeRenderedUpdated", handleSendEvent);
|
|
23223
|
+
}
|
|
23224
|
+
};
|
|
23225
|
+
this.addEventListener("onNodeRenderedUpdated", handleSendEvent);
|
|
23226
|
+
}
|
|
23218
23227
|
}
|
|
23219
|
-
updateNodes(nodes) {
|
|
23228
|
+
updateNodes(nodes, options = DEFAULT_UPDATE_NODE_OPTIONS) {
|
|
23220
23229
|
this.stateTransactional(() => {
|
|
23221
|
-
this.
|
|
23230
|
+
this.updateNodesNT(nodes, options);
|
|
23222
23231
|
});
|
|
23223
23232
|
}
|
|
23224
|
-
updateNodesNT(nodes) {
|
|
23233
|
+
updateNodesNT(nodes, options = DEFAULT_UPDATE_NODE_OPTIONS) {
|
|
23234
|
+
const { emitUserChangeEvent } = mergeExceptArrays(DEFAULT_UPDATE_NODE_OPTIONS, options);
|
|
23235
|
+
const transactionsIds = {};
|
|
23236
|
+
if (emitUserChangeEvent) for (const node of nodes) {
|
|
23237
|
+
this.setTransactionIdToInstance(node);
|
|
23238
|
+
transactionsIds[node.key] = node.props.transactionId;
|
|
23239
|
+
}
|
|
23225
23240
|
this.stateManager.updateNodes(nodes);
|
|
23241
|
+
if (emitUserChangeEvent) {
|
|
23242
|
+
const handleSendEvent = (updatedNode) => {
|
|
23243
|
+
for (const node of nodes) if (transactionsIds[node.key] === updatedNode.getAttrs().transactionId) {
|
|
23244
|
+
const decoratedNode = this.decorateWithZIndex(node);
|
|
23245
|
+
this.emitUserChangeEvent({ node: decoratedNode }, WEAVE_NODE_CHANGE_TYPE.UPDATE);
|
|
23246
|
+
delete transactionsIds[node.key];
|
|
23247
|
+
if (Object.keys(transactionsIds).length === 0) this.removeEventListener("onNodeRenderedUpdated", handleSendEvent);
|
|
23248
|
+
break;
|
|
23249
|
+
}
|
|
23250
|
+
};
|
|
23251
|
+
this.addEventListener("onNodeRenderedUpdated", handleSendEvent);
|
|
23252
|
+
}
|
|
23226
23253
|
}
|
|
23227
|
-
removeNode(node) {
|
|
23254
|
+
removeNode(node, options = DEFAULT_REMOVE_NODE_OPTIONS) {
|
|
23228
23255
|
this.stateTransactional(() => {
|
|
23229
|
-
this.
|
|
23230
|
-
this.runPhaseHooks("onRemoveNode", (hook) => {
|
|
23231
|
-
const nodeInstance = this.getStage().findOne(`#${node.key}`);
|
|
23232
|
-
if (nodeInstance) hook({ node: nodeInstance });
|
|
23233
|
-
});
|
|
23234
|
-
const selectionPlugin = this.getPlugin("nodesSelection");
|
|
23235
|
-
if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
|
|
23256
|
+
this.removeNodeNT(node, options);
|
|
23236
23257
|
});
|
|
23237
23258
|
}
|
|
23238
|
-
removeNodeNT(node) {
|
|
23259
|
+
removeNodeNT(node, options = DEFAULT_REMOVE_NODE_OPTIONS) {
|
|
23260
|
+
const { emitUserChangeEvent } = mergeExceptArrays(DEFAULT_REMOVE_NODE_OPTIONS, options);
|
|
23261
|
+
let parentId = void 0;
|
|
23262
|
+
let decoratedNode = void 0;
|
|
23263
|
+
if (emitUserChangeEvent) {
|
|
23264
|
+
this.setTransactionIdToInstance(node);
|
|
23265
|
+
decoratedNode = this.decorateWithZIndex(node);
|
|
23266
|
+
parentId = this.getContainerByNodeId(node.key);
|
|
23267
|
+
}
|
|
23239
23268
|
this.stateManager.removeNode(node);
|
|
23269
|
+
if (decoratedNode && emitUserChangeEvent) {
|
|
23270
|
+
const handleSendEvent = (removedNode) => {
|
|
23271
|
+
if (node.props.transactionId === removedNode.getAttrs().transactionId) {
|
|
23272
|
+
this.emitUserChangeEvent({
|
|
23273
|
+
node: decoratedNode,
|
|
23274
|
+
parentId
|
|
23275
|
+
}, WEAVE_NODE_CHANGE_TYPE.DELETE);
|
|
23276
|
+
this.removeEventListener("onNodeRenderedRemoved", handleSendEvent);
|
|
23277
|
+
}
|
|
23278
|
+
};
|
|
23279
|
+
this.addEventListener("onNodeRenderedRemoved", handleSendEvent);
|
|
23280
|
+
}
|
|
23240
23281
|
this.runPhaseHooks("onRemoveNode", (hook) => {
|
|
23241
23282
|
const nodeInstance = this.getStage().findOne(`#${node.key}`);
|
|
23242
23283
|
if (nodeInstance) hook({ node: nodeInstance });
|
|
@@ -23244,25 +23285,36 @@ var Weave = class {
|
|
|
23244
23285
|
const selectionPlugin = this.getPlugin("nodesSelection");
|
|
23245
23286
|
if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
|
|
23246
23287
|
}
|
|
23247
|
-
removeNodes(nodes) {
|
|
23288
|
+
removeNodes(nodes, options = DEFAULT_REMOVE_NODE_OPTIONS) {
|
|
23248
23289
|
this.stateTransactional(() => {
|
|
23249
|
-
|
|
23250
|
-
const selectionPlugin = this.getPlugin("nodesSelection");
|
|
23251
|
-
if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
|
|
23290
|
+
this.removeNodesNT(nodes, options);
|
|
23252
23291
|
});
|
|
23253
23292
|
}
|
|
23254
|
-
removeNodesNT(nodes) {
|
|
23255
|
-
for (const node of nodes) this.removeNodeNT(node);
|
|
23293
|
+
removeNodesNT(nodes, options = DEFAULT_REMOVE_NODE_OPTIONS) {
|
|
23294
|
+
for (const node of nodes) this.removeNodeNT(node, options);
|
|
23256
23295
|
const selectionPlugin = this.getPlugin("nodesSelection");
|
|
23257
23296
|
if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
|
|
23258
23297
|
}
|
|
23259
|
-
|
|
23298
|
+
zMoveNode(node, position, options = DEFAULT_MOVE_NODE_OPTIONS) {
|
|
23260
23299
|
this.stateTransactional(() => {
|
|
23261
|
-
this.
|
|
23262
|
-
});
|
|
23263
|
-
}
|
|
23264
|
-
|
|
23265
|
-
|
|
23300
|
+
this.zMoveNodeNT(node, position, options);
|
|
23301
|
+
});
|
|
23302
|
+
}
|
|
23303
|
+
zMoveNodeNT(node, position, options = DEFAULT_MOVE_NODE_OPTIONS) {
|
|
23304
|
+
const { emitUserChangeEvent } = mergeExceptArrays(DEFAULT_MOVE_NODE_OPTIONS, options);
|
|
23305
|
+
if (emitUserChangeEvent) this.setTransactionIdToInstance(node);
|
|
23306
|
+
this.updateNodeNT(node, { emitUserChangeEvent: false });
|
|
23307
|
+
this.stateManager.zMoveNode(node, position);
|
|
23308
|
+
if (emitUserChangeEvent) {
|
|
23309
|
+
const handleSendEvent = (movedNode) => {
|
|
23310
|
+
if (node.props.transactionId === movedNode.getAttrs().transactionId) {
|
|
23311
|
+
const decoratedNode = this.decorateWithZIndex(node);
|
|
23312
|
+
this.emitUserChangeEvent({ node: decoratedNode }, WEAVE_NODE_CHANGE_TYPE.UPDATE);
|
|
23313
|
+
this.removeEventListener("onNodeRenderedUpdated", handleSendEvent);
|
|
23314
|
+
}
|
|
23315
|
+
};
|
|
23316
|
+
this.addEventListener("onNodeRenderedUpdated", handleSendEvent);
|
|
23317
|
+
}
|
|
23266
23318
|
}
|
|
23267
23319
|
getElementsTree() {
|
|
23268
23320
|
return this.stateManager.getElementsTree();
|
|
@@ -23270,6 +23322,15 @@ var Weave = class {
|
|
|
23270
23322
|
isEmpty() {
|
|
23271
23323
|
return this.getElementsTree().length === 0;
|
|
23272
23324
|
}
|
|
23325
|
+
getContainerByNodeId(nodeId) {
|
|
23326
|
+
let parentId = void 0;
|
|
23327
|
+
const nodeParent = this.getStage().findOne(`#${nodeId}`);
|
|
23328
|
+
if (nodeParent) {
|
|
23329
|
+
const parent = this.getNodeContainer(nodeParent);
|
|
23330
|
+
if (parent) parentId = parent.getAttrs().id;
|
|
23331
|
+
}
|
|
23332
|
+
return parentId;
|
|
23333
|
+
}
|
|
23273
23334
|
getNodeContainerId(node) {
|
|
23274
23335
|
const stage = this.getStage();
|
|
23275
23336
|
let nodeContainer = node.getParent()?.getAttrs().id ?? "";
|
|
@@ -23346,9 +23407,6 @@ var Weave = class {
|
|
|
23346
23407
|
nodesToGroupSerialized(instancesToClone) {
|
|
23347
23408
|
return this.cloningManager.nodesToGroupSerialized(instancesToClone);
|
|
23348
23409
|
}
|
|
23349
|
-
cloneNodes(instancesToClone, targetContainer, onPoint) {
|
|
23350
|
-
this.cloningManager.cloneNodes(instancesToClone, targetContainer, onPoint);
|
|
23351
|
-
}
|
|
23352
23410
|
getFonts() {
|
|
23353
23411
|
return this.fontsManager.getFonts();
|
|
23354
23412
|
}
|