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