@inditextech/weave-sdk 0.40.0 → 0.40.2
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.cjs +146 -145
- package/dist/sdk.js +146 -145
- package/dist/sdk.js.map +1 -1
- package/package.json +2 -2
package/dist/sdk.js
CHANGED
|
@@ -15548,7 +15548,6 @@ var WeaveStore = class {
|
|
|
15548
15548
|
this.getState().weave
|
|
15549
15549
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15550
15550
|
);
|
|
15551
|
-
console.log(`User: ${this.config.getUser().id}`);
|
|
15552
15551
|
if (weaveStateValues) {
|
|
15553
15552
|
this.undoManager = new UndoManager([weaveStateValues], {
|
|
15554
15553
|
captureTimeout: 250,
|
|
@@ -15578,6 +15577,7 @@ var WeaveStore = class {
|
|
|
15578
15577
|
}
|
|
15579
15578
|
observeDeep(this.getState(), () => {
|
|
15580
15579
|
const newState = JSON.parse(JSON.stringify(this.getState()));
|
|
15580
|
+
this.logger.info({ newState }, "State changed");
|
|
15581
15581
|
this.instance.emitEvent("onStateChange", newState);
|
|
15582
15582
|
const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
15583
15583
|
if (this.isRoomLoaded && nodesSelectionPlugin && nodesSelectionPlugin.getSelectedNodes().length === 1) {
|
|
@@ -17482,9 +17482,13 @@ var WeaveStateSerializer = class {
|
|
|
17482
17482
|
});
|
|
17483
17483
|
const { key, type, props } = element;
|
|
17484
17484
|
if (typeof type !== "string") throw new Error(`Deserialization error: element type must be string received [${type}]`);
|
|
17485
|
-
|
|
17485
|
+
let restProps = {};
|
|
17486
17486
|
let childrenNodes = [];
|
|
17487
|
-
if (children)
|
|
17487
|
+
if (props.children) {
|
|
17488
|
+
const { children,...actRestProps } = props;
|
|
17489
|
+
restProps = actRestProps;
|
|
17490
|
+
if (children) childrenNodes = this.deserializeElement(children);
|
|
17491
|
+
} else restProps = props;
|
|
17488
17492
|
return React.createElement(type.toLowerCase(), {
|
|
17489
17493
|
...restProps,
|
|
17490
17494
|
key
|
|
@@ -18305,13 +18309,17 @@ var WeaveZIndexManager = class {
|
|
|
18305
18309
|
this.logger = this.instance.getChildLogger("zindex-manager");
|
|
18306
18310
|
this.logger.debug("zIndex manager created");
|
|
18307
18311
|
}
|
|
18312
|
+
getSelectionPlugin() {
|
|
18313
|
+
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
18314
|
+
return selectionPlugin;
|
|
18315
|
+
}
|
|
18308
18316
|
moveUp(instance) {
|
|
18309
18317
|
this.logger.debug(`Moving instance with id [${instance.getAttrs().id}], up one step of z-index`);
|
|
18310
18318
|
instance.moveUp();
|
|
18311
18319
|
const handler = this.instance.getNodeHandler(instance.getAttrs().nodeType);
|
|
18312
18320
|
if (handler) {
|
|
18313
|
-
const
|
|
18314
|
-
this.instance.moveNode(
|
|
18321
|
+
const nodeState = handler.serialize(instance);
|
|
18322
|
+
this.instance.moveNode(nodeState, WEAVE_NODE_POSITION.UP);
|
|
18315
18323
|
}
|
|
18316
18324
|
}
|
|
18317
18325
|
moveDown(instance) {
|
|
@@ -18319,8 +18327,8 @@ var WeaveZIndexManager = class {
|
|
|
18319
18327
|
instance.moveDown();
|
|
18320
18328
|
const handler = this.instance.getNodeHandler(instance.getAttrs().nodeType);
|
|
18321
18329
|
if (handler) {
|
|
18322
|
-
const
|
|
18323
|
-
this.instance.moveNode(
|
|
18330
|
+
const nodeState = handler.serialize(instance);
|
|
18331
|
+
this.instance.moveNode(nodeState, WEAVE_NODE_POSITION.DOWN);
|
|
18324
18332
|
}
|
|
18325
18333
|
}
|
|
18326
18334
|
sendToBack(instances) {
|
|
@@ -18331,7 +18339,6 @@ var WeaveZIndexManager = class {
|
|
|
18331
18339
|
const handler = this.instance.getNodeHandler(node.getAttrs().nodeType);
|
|
18332
18340
|
if (handler) {
|
|
18333
18341
|
const nodeState = handler.serialize(node);
|
|
18334
|
-
this.instance.updateNode(nodeState);
|
|
18335
18342
|
this.instance.moveNode(nodeState, WEAVE_NODE_POSITION.BACK);
|
|
18336
18343
|
}
|
|
18337
18344
|
}
|
|
@@ -18344,7 +18351,6 @@ var WeaveZIndexManager = class {
|
|
|
18344
18351
|
const handler = this.instance.getNodeHandler(node.getAttrs().nodeType);
|
|
18345
18352
|
if (handler) {
|
|
18346
18353
|
const nodeState = handler.serialize(node);
|
|
18347
|
-
this.instance.updateNode(nodeState);
|
|
18348
18354
|
this.instance.moveNode(nodeState, WEAVE_NODE_POSITION.FRONT);
|
|
18349
18355
|
}
|
|
18350
18356
|
}
|
|
@@ -18419,156 +18425,151 @@ var WeaveStateManager = class {
|
|
|
18419
18425
|
return this.findNodeById(state, nodeKey);
|
|
18420
18426
|
}
|
|
18421
18427
|
addNode(node, parentId = "mainLayer", index = void 0) {
|
|
18422
|
-
const
|
|
18423
|
-
this.
|
|
18424
|
-
|
|
18425
|
-
|
|
18426
|
-
|
|
18427
|
-
|
|
18428
|
-
|
|
18429
|
-
|
|
18430
|
-
|
|
18431
|
-
|
|
18432
|
-
|
|
18433
|
-
|
|
18434
|
-
|
|
18435
|
-
|
|
18436
|
-
|
|
18437
|
-
|
|
18438
|
-
|
|
18439
|
-
|
|
18440
|
-
|
|
18441
|
-
|
|
18442
|
-
|
|
18443
|
-
|
|
18444
|
-
|
|
18445
|
-
|
|
18446
|
-
|
|
18447
|
-
|
|
18448
|
-
|
|
18449
|
-
|
|
18450
|
-
|
|
18451
|
-
|
|
18452
|
-
|
|
18453
|
-
|
|
18454
|
-
|
|
18455
|
-
|
|
18456
|
-
|
|
18457
|
-
|
|
18458
|
-
|
|
18459
|
-
|
|
18460
|
-
|
|
18461
|
-
|
|
18462
|
-
|
|
18463
|
-
|
|
18464
|
-
|
|
18465
|
-
|
|
18466
|
-
|
|
18467
|
-
|
|
18468
|
-
|
|
18469
|
-
|
|
18470
|
-
|
|
18471
|
-
|
|
18472
|
-
|
|
18473
|
-
};
|
|
18474
|
-
parent.props.children.push(finalNode);
|
|
18475
|
-
}
|
|
18476
|
-
this.instance.emitEvent("onNodeAdded", node);
|
|
18477
|
-
}, userId);
|
|
18428
|
+
const state = this.instance.getStore().getState();
|
|
18429
|
+
this.logger.info({ state: JSON.parse(JSON.stringify(state)) }, "State before addNode");
|
|
18430
|
+
if ((0, import_lodash.isEmpty)(state.weave)) {
|
|
18431
|
+
const msg = `State is empty, cannot add the node`;
|
|
18432
|
+
this.logger.warn({
|
|
18433
|
+
node,
|
|
18434
|
+
parentId
|
|
18435
|
+
}, msg);
|
|
18436
|
+
return;
|
|
18437
|
+
}
|
|
18438
|
+
const { node: nodeState } = this.findNodeById(state.weave, node.key);
|
|
18439
|
+
if (nodeState) {
|
|
18440
|
+
const msg = `Node with key [${node.key}] already exists, cannot add it`;
|
|
18441
|
+
this.logger.warn({
|
|
18442
|
+
node,
|
|
18443
|
+
parentId
|
|
18444
|
+
}, msg);
|
|
18445
|
+
return;
|
|
18446
|
+
}
|
|
18447
|
+
const { node: parent } = this.findNodeById(state.weave, parentId);
|
|
18448
|
+
if (!parent) {
|
|
18449
|
+
const msg = `Parent container with key [${node.key}] doesn't exists, cannot add it`;
|
|
18450
|
+
this.logger.warn({
|
|
18451
|
+
node,
|
|
18452
|
+
parentId
|
|
18453
|
+
}, msg);
|
|
18454
|
+
return;
|
|
18455
|
+
}
|
|
18456
|
+
this.logger.info({ parent: JSON.parse(JSON.stringify(parent)) }, "addNode: parent before init");
|
|
18457
|
+
const newChildren = JSON.parse(JSON.stringify(parent.props.children ?? []));
|
|
18458
|
+
this.logger.info({ parent: JSON.parse(JSON.stringify(parent)) }, "addNode: parent before add");
|
|
18459
|
+
if (index) {
|
|
18460
|
+
newChildren?.splice(index, 0, node);
|
|
18461
|
+
for (let i = 0; i < newChildren.length; i++) newChildren[i].props.zIndex = i;
|
|
18462
|
+
}
|
|
18463
|
+
if (!index) {
|
|
18464
|
+
const childrenAmount = newChildren.length;
|
|
18465
|
+
node.props.zIndex = childrenAmount;
|
|
18466
|
+
const nodeToAdd = {
|
|
18467
|
+
...node,
|
|
18468
|
+
props: {
|
|
18469
|
+
...node.props,
|
|
18470
|
+
zIndex: childrenAmount
|
|
18471
|
+
}
|
|
18472
|
+
};
|
|
18473
|
+
this.logger.info({ node: JSON.parse(JSON.stringify(nodeToAdd)) }, "addNode: node to add");
|
|
18474
|
+
newChildren.push(nodeToAdd);
|
|
18475
|
+
}
|
|
18476
|
+
if (typeof newChildren !== "undefined") parent.props.children = newChildren;
|
|
18477
|
+
this.logger.info({ parent: JSON.parse(JSON.stringify(parent)) }, "addNode: parent after add");
|
|
18478
|
+
this.instance.emitEvent("onNodeAdded", node);
|
|
18478
18479
|
}
|
|
18479
18480
|
updateNode(node) {
|
|
18480
|
-
const
|
|
18481
|
-
this.
|
|
18482
|
-
|
|
18483
|
-
|
|
18484
|
-
|
|
18485
|
-
|
|
18486
|
-
|
|
18487
|
-
|
|
18488
|
-
|
|
18489
|
-
|
|
18490
|
-
|
|
18491
|
-
|
|
18492
|
-
|
|
18493
|
-
|
|
18494
|
-
|
|
18495
|
-
|
|
18496
|
-
|
|
18497
|
-
|
|
18498
|
-
|
|
18499
|
-
|
|
18500
|
-
},
|
|
18481
|
+
const state = this.instance.getStore().getState();
|
|
18482
|
+
this.logger.info({ state: JSON.parse(JSON.stringify(state)) }, "State before updateNode");
|
|
18483
|
+
if ((0, import_lodash.isEmpty)(state.weave)) {
|
|
18484
|
+
const msg = `State is empty, cannot update the node`;
|
|
18485
|
+
this.logger.warn({ node }, msg);
|
|
18486
|
+
return;
|
|
18487
|
+
}
|
|
18488
|
+
const { node: nodeState } = this.findNodeById(state.weave, node.key);
|
|
18489
|
+
if (!nodeState) {
|
|
18490
|
+
const msg = `Node with key [${node.key}] doesn't exists, cannot update it`;
|
|
18491
|
+
this.logger.warn({ node }, msg);
|
|
18492
|
+
return;
|
|
18493
|
+
}
|
|
18494
|
+
this.logger.info({ node: JSON.parse(JSON.stringify(nodeState)) }, "updateNode: before update");
|
|
18495
|
+
const newNode = JSON.parse(JSON.stringify(nodeState));
|
|
18496
|
+
newNode.props = {
|
|
18497
|
+
...newNode.props,
|
|
18498
|
+
...node.props
|
|
18499
|
+
};
|
|
18500
|
+
if (typeof newNode.props !== "undefined") nodeState.props = newNode.props;
|
|
18501
|
+
this.logger.info({ node: JSON.parse(JSON.stringify(nodeState)) }, "updateNode: after update");
|
|
18502
|
+
this.instance.emitEvent("onNodeUpdated", node);
|
|
18501
18503
|
}
|
|
18502
18504
|
removeNode(node) {
|
|
18503
|
-
const
|
|
18504
|
-
this.
|
|
18505
|
-
|
|
18506
|
-
|
|
18507
|
-
|
|
18508
|
-
|
|
18509
|
-
|
|
18510
|
-
|
|
18511
|
-
|
|
18512
|
-
|
|
18513
|
-
|
|
18514
|
-
|
|
18515
|
-
|
|
18516
|
-
|
|
18517
|
-
|
|
18518
|
-
|
|
18519
|
-
|
|
18520
|
-
|
|
18521
|
-
|
|
18522
|
-
|
|
18523
|
-
|
|
18505
|
+
const state = this.instance.getStore().getState();
|
|
18506
|
+
this.logger.info({ stage: JSON.parse(JSON.stringify(state)) }, "State before removeNode");
|
|
18507
|
+
if ((0, import_lodash.isEmpty)(state.weave)) {
|
|
18508
|
+
const msg = `State is empty, cannot update the node`;
|
|
18509
|
+
this.logger.warn({ node }, msg);
|
|
18510
|
+
return;
|
|
18511
|
+
}
|
|
18512
|
+
const { node: nodeState, parent } = this.findNodeById(state.weave, node.key);
|
|
18513
|
+
if (!nodeState) {
|
|
18514
|
+
const msg = `Node with key [${node.key}] doesn't exists, cannot remove it`;
|
|
18515
|
+
this.logger.warn({ node }, msg);
|
|
18516
|
+
return;
|
|
18517
|
+
}
|
|
18518
|
+
if (!parent) {
|
|
18519
|
+
const msg = `Parent doesn't exists, cannot remove it`;
|
|
18520
|
+
this.logger.warn({ node }, msg);
|
|
18521
|
+
return;
|
|
18522
|
+
}
|
|
18523
|
+
this.logger.info({ key: node.key }, "removeNode: node to remove");
|
|
18524
|
+
this.logger.info({ parent: JSON.parse(JSON.stringify(parent)) }, "removeNode: parent before remove");
|
|
18525
|
+
const newChildren = JSON.parse(JSON.stringify(parent.props.children ?? []));
|
|
18526
|
+
for (let i = newChildren.length - 1; i >= 0; i--) if (newChildren[i].key === node.key) {
|
|
18527
|
+
newChildren.splice(i, 1);
|
|
18528
|
+
break;
|
|
18529
|
+
}
|
|
18530
|
+
for (let i = 0; i < newChildren.length; i++) newChildren[i].props.zIndex = i;
|
|
18531
|
+
if (typeof newChildren !== "undefined") parent.props.children = newChildren;
|
|
18532
|
+
this.logger.info({ parent: JSON.parse(JSON.stringify(parent)) }, "removeNode: parent after remove");
|
|
18533
|
+
this.instance.emitEvent("onNodeRemoved", node);
|
|
18524
18534
|
}
|
|
18525
18535
|
removeNodes(nodes) {
|
|
18526
18536
|
for (const node of nodes) this.removeNode(node);
|
|
18527
18537
|
}
|
|
18528
18538
|
moveNode(node, position) {
|
|
18529
|
-
const
|
|
18530
|
-
this.
|
|
18531
|
-
|
|
18532
|
-
|
|
18533
|
-
|
|
18534
|
-
|
|
18535
|
-
|
|
18536
|
-
|
|
18537
|
-
|
|
18538
|
-
|
|
18539
|
-
|
|
18540
|
-
|
|
18541
|
-
|
|
18542
|
-
|
|
18543
|
-
|
|
18544
|
-
|
|
18545
|
-
|
|
18546
|
-
|
|
18547
|
-
|
|
18548
|
-
|
|
18549
|
-
|
|
18550
|
-
|
|
18551
|
-
|
|
18552
|
-
|
|
18553
|
-
|
|
18554
|
-
|
|
18555
|
-
|
|
18556
|
-
props: {
|
|
18557
|
-
...actNode.props,
|
|
18558
|
-
zIndex: index
|
|
18559
|
-
}
|
|
18560
|
-
};
|
|
18561
|
-
});
|
|
18562
|
-
if (!nodeParent.props.children) nodeParent.props.children = [];
|
|
18563
|
-
nodeParent.props.children = nodeParentNewChildren;
|
|
18564
|
-
}
|
|
18565
|
-
}, userId);
|
|
18539
|
+
const state = this.instance.getStore().getState();
|
|
18540
|
+
this.logger.info({ stage: JSON.parse(JSON.stringify(state)) }, "State before moveNode");
|
|
18541
|
+
if ((0, import_lodash.isEmpty)(state.weave)) {
|
|
18542
|
+
const msg = `State is empty, cannot update the node`;
|
|
18543
|
+
this.logger.warn({ node }, msg);
|
|
18544
|
+
return;
|
|
18545
|
+
}
|
|
18546
|
+
const { node: nodeState, parent } = this.findNodeById(state.weave, node.key);
|
|
18547
|
+
if (!nodeState) {
|
|
18548
|
+
const msg = `Node with key [${node.key}] doesn't exists, cannot update it`;
|
|
18549
|
+
this.logger.warn({ node }, msg);
|
|
18550
|
+
return;
|
|
18551
|
+
}
|
|
18552
|
+
this.logger.info({ parent: JSON.parse(JSON.stringify(parent)) }, "moveNode: parent before move");
|
|
18553
|
+
if (parent && parent.props.children) {
|
|
18554
|
+
const childrenAmount = parent.props.children.length;
|
|
18555
|
+
const nodeIndex = parent.props.children.findIndex((child) => child.key === node.key);
|
|
18556
|
+
const newChildren = JSON.parse(JSON.stringify(parent.props.children ?? []));
|
|
18557
|
+
newChildren.splice(nodeIndex, 1);
|
|
18558
|
+
if (position === WEAVE_NODE_POSITION.UP) newChildren.splice(nodeIndex + 1, 0, { ...node });
|
|
18559
|
+
if (position === WEAVE_NODE_POSITION.DOWN) newChildren.splice(nodeIndex - 1, 0, { ...node });
|
|
18560
|
+
if (position === WEAVE_NODE_POSITION.FRONT) newChildren.splice(childrenAmount - 1, 0, { ...node });
|
|
18561
|
+
if (position === WEAVE_NODE_POSITION.BACK) newChildren.splice(0, 0, { ...node });
|
|
18562
|
+
for (let i = 0; i < newChildren.length; i++) newChildren[i].props.zIndex = i;
|
|
18563
|
+
if (typeof newChildren !== "undefined") parent.props.children = newChildren;
|
|
18564
|
+
}
|
|
18565
|
+
this.logger.info({ parent: JSON.parse(JSON.stringify(parent)) }, "moveNode: parent after move");
|
|
18566
18566
|
}
|
|
18567
18567
|
getElementsTree() {
|
|
18568
18568
|
const state = this.instance.getStore().getState().weave;
|
|
18569
18569
|
const jsonState = JSON.parse(JSON.stringify(state, null, 2));
|
|
18570
18570
|
const mainLayer = jsonState.props?.children.find((node) => node.key === "mainLayer");
|
|
18571
18571
|
if (!mainLayer) return [];
|
|
18572
|
+
if (!mainLayer.props?.children) return [];
|
|
18572
18573
|
return mainLayer.props.children;
|
|
18573
18574
|
}
|
|
18574
18575
|
};
|
|
@@ -18646,7 +18647,7 @@ var WeaveRegisterManager = class {
|
|
|
18646
18647
|
|
|
18647
18648
|
//#endregion
|
|
18648
18649
|
//#region package.json
|
|
18649
|
-
var version = "0.40.
|
|
18650
|
+
var version = "0.40.2";
|
|
18650
18651
|
|
|
18651
18652
|
//#endregion
|
|
18652
18653
|
//#region src/managers/setup.ts
|