@inditextech/weave-sdk 5.0.0-SNAPSHOT.345.1 → 5.0.0-SNAPSHOT.377.1
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.js +1640 -1451
- package/dist/sdk.node.js +1640 -1451
- package/dist/sdk.node.stats.html +1 -1
- package/dist/sdk.stats.html +1 -1
- package/dist/types.d.ts +388 -182
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1640 -1451
- package/dist/types.js.map +1 -1
- package/dist/types.stats.html +1 -1
- package/package.json +7 -6
package/dist/sdk.js
CHANGED
|
@@ -1157,8 +1157,8 @@ var require_isArray = __commonJS({ "../../node_modules/lodash/isArray.js"(export
|
|
|
1157
1157
|
* _.isArray(_.noop);
|
|
1158
1158
|
* // => false
|
|
1159
1159
|
*/
|
|
1160
|
-
var isArray$
|
|
1161
|
-
module.exports = isArray$
|
|
1160
|
+
var isArray$13 = Array.isArray;
|
|
1161
|
+
module.exports = isArray$13;
|
|
1162
1162
|
} });
|
|
1163
1163
|
|
|
1164
1164
|
//#endregion
|
|
@@ -1383,7 +1383,7 @@ var require_isTypedArray = __commonJS({ "../../node_modules/lodash/isTypedArray.
|
|
|
1383
1383
|
//#endregion
|
|
1384
1384
|
//#region ../../node_modules/lodash/isEmpty.js
|
|
1385
1385
|
var require_isEmpty = __commonJS({ "../../node_modules/lodash/isEmpty.js"(exports, module) {
|
|
1386
|
-
var baseKeys$1 = require__baseKeys(), getTag$1 = require__getTag(), isArguments$3 = require_isArguments(), isArray$
|
|
1386
|
+
var baseKeys$1 = require__baseKeys(), getTag$1 = require__getTag(), isArguments$3 = require_isArguments(), isArray$12 = require_isArray(), isArrayLike$6 = require_isArrayLike(), isBuffer$3 = require_isBuffer(), isPrototype$2 = require__isPrototype(), isTypedArray$3 = require_isTypedArray();
|
|
1387
1387
|
/** `Object#toString` result references. */
|
|
1388
1388
|
var mapTag$1 = "[object Map]", setTag$1 = "[object Set]";
|
|
1389
1389
|
/** Used for built-in method references. */
|
|
@@ -1425,7 +1425,7 @@ var require_isEmpty = __commonJS({ "../../node_modules/lodash/isEmpty.js"(export
|
|
|
1425
1425
|
*/
|
|
1426
1426
|
function isEmpty(value) {
|
|
1427
1427
|
if (value == null) return true;
|
|
1428
|
-
if (isArrayLike$6(value) && (isArray$
|
|
1428
|
+
if (isArrayLike$6(value) && (isArray$12(value) || typeof value == "string" || typeof value.splice == "function" || isBuffer$3(value) || isTypedArray$3(value) || isArguments$3(value))) return !value.length;
|
|
1429
1429
|
var tag = getTag$1(value);
|
|
1430
1430
|
if (tag == mapTag$1 || tag == setTag$1) return !value.size;
|
|
1431
1431
|
if (isPrototype$2(value)) return !baseKeys$1(value).length;
|
|
@@ -1752,13 +1752,6 @@ const WEAVE_NODES_SELECTION_DEFAULT_CONFIG = {
|
|
|
1752
1752
|
style: { dragOpacity: .75 }
|
|
1753
1753
|
};
|
|
1754
1754
|
|
|
1755
|
-
//#endregion
|
|
1756
|
-
//#region src/plugins/context-menu/constants.ts
|
|
1757
|
-
const WEAVE_CONTEXT_MENU_PLUGIN_KEY = "contextMenu";
|
|
1758
|
-
const WEAVE_CONTEXT_MENU_X_OFFSET_DEFAULT = 4;
|
|
1759
|
-
const WEAVE_CONTEXT_MENU_Y_OFFSET_DEFAULT = 4;
|
|
1760
|
-
const WEAVE_CONTEXT_MENU_TAP_HOLD_TIMEOUT = 500;
|
|
1761
|
-
|
|
1762
1755
|
//#endregion
|
|
1763
1756
|
//#region ../../node_modules/lodash/_listCacheClear.js
|
|
1764
1757
|
var require__listCacheClear = __commonJS({ "../../node_modules/lodash/_listCacheClear.js"(exports, module) {
|
|
@@ -2865,7 +2858,7 @@ var require__isIndex = __commonJS({ "../../node_modules/lodash/_isIndex.js"(expo
|
|
|
2865
2858
|
//#endregion
|
|
2866
2859
|
//#region ../../node_modules/lodash/_arrayLikeKeys.js
|
|
2867
2860
|
var require__arrayLikeKeys = __commonJS({ "../../node_modules/lodash/_arrayLikeKeys.js"(exports, module) {
|
|
2868
|
-
var baseTimes = require__baseTimes(), isArguments$2 = require_isArguments(), isArray$
|
|
2861
|
+
var baseTimes = require__baseTimes(), isArguments$2 = require_isArguments(), isArray$11 = require_isArray(), isBuffer$2 = require_isBuffer(), isIndex$2 = require__isIndex(), isTypedArray$2 = require_isTypedArray();
|
|
2869
2862
|
/** Used for built-in method references. */
|
|
2870
2863
|
var objectProto$4 = Object.prototype;
|
|
2871
2864
|
/** Used to check objects for own properties. */
|
|
@@ -2879,7 +2872,7 @@ var require__arrayLikeKeys = __commonJS({ "../../node_modules/lodash/_arrayLikeK
|
|
|
2879
2872
|
* @returns {Array} Returns the array of property names.
|
|
2880
2873
|
*/
|
|
2881
2874
|
function arrayLikeKeys$2(value, inherited) {
|
|
2882
|
-
var isArr = isArray$
|
|
2875
|
+
var isArr = isArray$11(value), isArg = !isArr && isArguments$2(value), isBuff = !isArr && !isArg && isBuffer$2(value), isType = !isArr && !isArg && !isBuff && isTypedArray$2(value), skipIndexes = isArr || isArg || isBuff || isType, result = skipIndexes ? baseTimes(value.length, String) : [], length = result.length;
|
|
2883
2876
|
for (var key in value) if ((inherited || hasOwnProperty$3.call(value, key)) && !(skipIndexes && (key == "length" || isBuff && (key == "offset" || key == "parent") || isType && (key == "buffer" || key == "byteLength" || key == "byteOffset") || isIndex$2(key, length)))) result.push(key);
|
|
2884
2877
|
return result;
|
|
2885
2878
|
}
|
|
@@ -3000,7 +2993,7 @@ var require_toPlainObject = __commonJS({ "../../node_modules/lodash/toPlainObjec
|
|
|
3000
2993
|
//#endregion
|
|
3001
2994
|
//#region ../../node_modules/lodash/_baseMergeDeep.js
|
|
3002
2995
|
var require__baseMergeDeep = __commonJS({ "../../node_modules/lodash/_baseMergeDeep.js"(exports, module) {
|
|
3003
|
-
var assignMergeValue$1 = require__assignMergeValue(), cloneBuffer = require__cloneBuffer(), cloneTypedArray = require__cloneTypedArray(), copyArray = require__copyArray(), initCloneObject = require__initCloneObject(), isArguments$1 = require_isArguments(), isArray$
|
|
2996
|
+
var assignMergeValue$1 = require__assignMergeValue(), cloneBuffer = require__cloneBuffer(), cloneTypedArray = require__cloneTypedArray(), copyArray = require__copyArray(), initCloneObject = require__initCloneObject(), isArguments$1 = require_isArguments(), isArray$10 = require_isArray(), isArrayLikeObject = require_isArrayLikeObject(), isBuffer$1 = require_isBuffer(), isFunction = require_isFunction(), isObject$7 = require_isObject(), isPlainObject = require_isPlainObject(), isTypedArray$1 = require_isTypedArray(), safeGet$1 = require__safeGet(), toPlainObject = require_toPlainObject();
|
|
3004
2997
|
/**
|
|
3005
2998
|
* A specialized version of `baseMerge` for arrays and objects which performs
|
|
3006
2999
|
* deep merges and tracks traversed objects enabling objects with circular
|
|
@@ -3025,9 +3018,9 @@ var require__baseMergeDeep = __commonJS({ "../../node_modules/lodash/_baseMergeD
|
|
|
3025
3018
|
var newValue = customizer ? customizer(objValue, srcValue, key + "", object, source, stack) : void 0;
|
|
3026
3019
|
var isCommon = newValue === void 0;
|
|
3027
3020
|
if (isCommon) {
|
|
3028
|
-
var isArr = isArray$
|
|
3021
|
+
var isArr = isArray$10(srcValue), isBuff = !isArr && isBuffer$1(srcValue), isTyped = !isArr && !isBuff && isTypedArray$1(srcValue);
|
|
3029
3022
|
newValue = srcValue;
|
|
3030
|
-
if (isArr || isBuff || isTyped) if (isArray$
|
|
3023
|
+
if (isArr || isBuff || isTyped) if (isArray$10(objValue)) newValue = objValue;
|
|
3031
3024
|
else if (isArrayLikeObject(objValue)) newValue = copyArray(objValue);
|
|
3032
3025
|
else if (isBuff) {
|
|
3033
3026
|
isCommon = false;
|
|
@@ -3703,223 +3696,6 @@ function isNumber(value) {
|
|
|
3703
3696
|
return typeof value === "number" && !Number.isNaN(value);
|
|
3704
3697
|
}
|
|
3705
3698
|
|
|
3706
|
-
//#endregion
|
|
3707
|
-
//#region src/actions/selection-tool/constants.ts
|
|
3708
|
-
const SELECTION_TOOL_ACTION_NAME = "selectionTool";
|
|
3709
|
-
const SELECTION_TOOL_STATE = {
|
|
3710
|
-
["IDLE"]: "idle",
|
|
3711
|
-
["SELECTING"]: "selection"
|
|
3712
|
-
};
|
|
3713
|
-
|
|
3714
|
-
//#endregion
|
|
3715
|
-
//#region src/plugins/context-menu/context-menu.ts
|
|
3716
|
-
var WeaveContextMenuPlugin = class extends WeavePlugin {
|
|
3717
|
-
getLayerName = void 0;
|
|
3718
|
-
initLayer = void 0;
|
|
3719
|
-
constructor(params) {
|
|
3720
|
-
super();
|
|
3721
|
-
const { config } = params ?? {};
|
|
3722
|
-
this.config = {
|
|
3723
|
-
xOffset: WEAVE_CONTEXT_MENU_X_OFFSET_DEFAULT,
|
|
3724
|
-
yOffset: WEAVE_CONTEXT_MENU_Y_OFFSET_DEFAULT,
|
|
3725
|
-
...config
|
|
3726
|
-
};
|
|
3727
|
-
this.initialize();
|
|
3728
|
-
}
|
|
3729
|
-
initialize() {
|
|
3730
|
-
this.timer = null;
|
|
3731
|
-
this.tapHold = false;
|
|
3732
|
-
this.contextMenuVisible = false;
|
|
3733
|
-
this.tapStart = {
|
|
3734
|
-
x: 0,
|
|
3735
|
-
y: 0,
|
|
3736
|
-
time: 0
|
|
3737
|
-
};
|
|
3738
|
-
this.tapHoldTimeout = WEAVE_CONTEXT_MENU_TAP_HOLD_TIMEOUT;
|
|
3739
|
-
this.pointers = {};
|
|
3740
|
-
}
|
|
3741
|
-
getName() {
|
|
3742
|
-
return WEAVE_CONTEXT_MENU_PLUGIN_KEY;
|
|
3743
|
-
}
|
|
3744
|
-
onInit() {
|
|
3745
|
-
this.initEvents();
|
|
3746
|
-
}
|
|
3747
|
-
isPressed(e) {
|
|
3748
|
-
return e.evt.buttons > 0;
|
|
3749
|
-
}
|
|
3750
|
-
setTapStart(e) {
|
|
3751
|
-
this.tapStart = {
|
|
3752
|
-
x: e.evt.clientX,
|
|
3753
|
-
y: e.evt.clientY,
|
|
3754
|
-
time: performance.now()
|
|
3755
|
-
};
|
|
3756
|
-
}
|
|
3757
|
-
triggerContextMenu(eventTarget, target) {
|
|
3758
|
-
const stage = this.instance.getStage();
|
|
3759
|
-
const selectionPlugin = this.getSelectionPlugin();
|
|
3760
|
-
let nodes = [];
|
|
3761
|
-
if (target && target !== stage) {
|
|
3762
|
-
const nodeHandler = this.instance.getNodeHandler(target.getAttrs().nodeType);
|
|
3763
|
-
nodes = [{
|
|
3764
|
-
instance: target,
|
|
3765
|
-
node: nodeHandler?.serialize(target)
|
|
3766
|
-
}];
|
|
3767
|
-
}
|
|
3768
|
-
const eventTargetParent = eventTarget.getParent();
|
|
3769
|
-
if (eventTargetParent instanceof Konva.Transformer) nodes = eventTargetParent.nodes().map((node) => {
|
|
3770
|
-
const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
|
|
3771
|
-
return {
|
|
3772
|
-
instance: node,
|
|
3773
|
-
node: nodeHandler?.serialize(node)
|
|
3774
|
-
};
|
|
3775
|
-
});
|
|
3776
|
-
if (this.contextMenuVisible) this.closeContextMenu();
|
|
3777
|
-
let allNodesMutexUnlocked = true;
|
|
3778
|
-
let allNodesUnlocked = true;
|
|
3779
|
-
const actUser = this.instance.getStore().getUser();
|
|
3780
|
-
for (const node of nodes) {
|
|
3781
|
-
const locked = node.instance.getAttrs().locked;
|
|
3782
|
-
const mutexInfo = this.instance.getNodeMutexLock(node.node?.key ?? "");
|
|
3783
|
-
if (locked) {
|
|
3784
|
-
allNodesUnlocked = false;
|
|
3785
|
-
break;
|
|
3786
|
-
}
|
|
3787
|
-
if (mutexInfo && mutexInfo.user.id !== actUser.id) {
|
|
3788
|
-
allNodesMutexUnlocked = false;
|
|
3789
|
-
break;
|
|
3790
|
-
}
|
|
3791
|
-
}
|
|
3792
|
-
if (!allNodesMutexUnlocked || !allNodesUnlocked) return;
|
|
3793
|
-
if (selectionPlugin && !(eventTarget.getParent() instanceof Konva.Transformer && selectionPlugin.getSelectedNodes().length > 0)) {
|
|
3794
|
-
selectionPlugin.setSelectedNodes([...nodes.map((node) => node.instance)]);
|
|
3795
|
-
selectionPlugin.getHoverTransformer().nodes([]);
|
|
3796
|
-
}
|
|
3797
|
-
const containerRect = stage.container().getBoundingClientRect();
|
|
3798
|
-
const pointerPos = stage.getPointerPosition();
|
|
3799
|
-
const relativeClickPoint = stage.getRelativePointerPosition();
|
|
3800
|
-
if (containerRect && pointerPos && relativeClickPoint && allNodesUnlocked) {
|
|
3801
|
-
const contextMenuPoint = {
|
|
3802
|
-
x: containerRect.left + pointerPos.x + (this.config.xOffset ?? 4),
|
|
3803
|
-
y: containerRect.top + pointerPos.y + (this.config.yOffset ?? 4)
|
|
3804
|
-
};
|
|
3805
|
-
const stageClickPoint = this.getStageClickPoint(pointerPos);
|
|
3806
|
-
this.contextMenuVisible = true;
|
|
3807
|
-
this.instance.emitEvent("onNodeContextMenu", {
|
|
3808
|
-
selection: nodes,
|
|
3809
|
-
contextMenuPoint,
|
|
3810
|
-
clickPoint: pointerPos,
|
|
3811
|
-
stageClickPoint,
|
|
3812
|
-
visible: true
|
|
3813
|
-
});
|
|
3814
|
-
}
|
|
3815
|
-
}
|
|
3816
|
-
closeContextMenu() {
|
|
3817
|
-
this.contextMenuVisible = false;
|
|
3818
|
-
this.instance.emitEvent("onNodeContextMenu", {
|
|
3819
|
-
selection: [],
|
|
3820
|
-
contextMenuPoint: {
|
|
3821
|
-
x: 0,
|
|
3822
|
-
y: 0
|
|
3823
|
-
},
|
|
3824
|
-
clickPoint: {
|
|
3825
|
-
x: 0,
|
|
3826
|
-
y: 0
|
|
3827
|
-
},
|
|
3828
|
-
stageClickPoint: {
|
|
3829
|
-
x: 0,
|
|
3830
|
-
y: 0
|
|
3831
|
-
},
|
|
3832
|
-
visible: false
|
|
3833
|
-
});
|
|
3834
|
-
}
|
|
3835
|
-
getSelectionPlugin() {
|
|
3836
|
-
const selectionPlugin = this.instance.getPlugin(WEAVE_NODES_SELECTION_KEY);
|
|
3837
|
-
return selectionPlugin;
|
|
3838
|
-
}
|
|
3839
|
-
cancelLongPressTimer() {
|
|
3840
|
-
if (this.timer) {
|
|
3841
|
-
clearTimeout(this.timer);
|
|
3842
|
-
this.timer = null;
|
|
3843
|
-
}
|
|
3844
|
-
}
|
|
3845
|
-
initEvents() {
|
|
3846
|
-
const stage = this.instance.getStage();
|
|
3847
|
-
stage.on("pointerdown", (e) => {
|
|
3848
|
-
this.setTapStart(e);
|
|
3849
|
-
this.pointers[e.evt.pointerId] = e.evt;
|
|
3850
|
-
if (e.evt.buttons === 0) return;
|
|
3851
|
-
if (e.evt.pointerType === "mouse") return;
|
|
3852
|
-
if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length > 1) return;
|
|
3853
|
-
if (this.timer) return;
|
|
3854
|
-
this.timer = setTimeout(() => {
|
|
3855
|
-
this.tapHold = true;
|
|
3856
|
-
const actualActions = this.instance.getActiveAction();
|
|
3857
|
-
if (actualActions !== SELECTION_TOOL_ACTION_NAME) return;
|
|
3858
|
-
delete this.pointers[e.evt.pointerId];
|
|
3859
|
-
const selectedGroup = getTargetedNode(this.instance);
|
|
3860
|
-
this.triggerContextMenu(e.target, selectedGroup);
|
|
3861
|
-
}, this.tapHoldTimeout);
|
|
3862
|
-
});
|
|
3863
|
-
stage.on("pointerup", (e) => {
|
|
3864
|
-
delete this.pointers[e.evt.pointerId];
|
|
3865
|
-
if (e.evt.pointerType === "mouse") return;
|
|
3866
|
-
if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length + 1 > 1) return;
|
|
3867
|
-
if (this.timer) {
|
|
3868
|
-
clearTimeout(this.timer);
|
|
3869
|
-
this.timer = null;
|
|
3870
|
-
this.tapHold = false;
|
|
3871
|
-
}
|
|
3872
|
-
});
|
|
3873
|
-
stage.on("contextmenu", (e) => {
|
|
3874
|
-
e.evt.preventDefault();
|
|
3875
|
-
if (!this.enabled) return;
|
|
3876
|
-
const selectedGroup = getTargetedNode(this.instance);
|
|
3877
|
-
this.triggerContextMenu(e.target, selectedGroup);
|
|
3878
|
-
});
|
|
3879
|
-
this.instance.addEventListener("onStageSelection", () => {
|
|
3880
|
-
if (this.tapHold) return;
|
|
3881
|
-
const containerRect = stage.container().getBoundingClientRect();
|
|
3882
|
-
const pointerPos = stage.getPointerPosition();
|
|
3883
|
-
if (containerRect && pointerPos) {
|
|
3884
|
-
const contextMenuPoint = {
|
|
3885
|
-
x: containerRect.left + pointerPos.x + (this.config.xOffset ?? 4),
|
|
3886
|
-
y: containerRect.top + pointerPos.y + (this.config.yOffset ?? 4)
|
|
3887
|
-
};
|
|
3888
|
-
const stageClickPoint = this.getStageClickPoint(pointerPos);
|
|
3889
|
-
this.instance.emitEvent("onNodeContextMenu", {
|
|
3890
|
-
selection: [],
|
|
3891
|
-
contextMenuPoint,
|
|
3892
|
-
clickPoint: pointerPos,
|
|
3893
|
-
stageClickPoint,
|
|
3894
|
-
visible: false
|
|
3895
|
-
});
|
|
3896
|
-
}
|
|
3897
|
-
});
|
|
3898
|
-
}
|
|
3899
|
-
getStageClickPoint(pointerPos) {
|
|
3900
|
-
const stage = this.instance.getStage();
|
|
3901
|
-
const scale = stage.scale();
|
|
3902
|
-
const position = stage.position();
|
|
3903
|
-
const stageClickPoint = {
|
|
3904
|
-
x: (pointerPos.x - position.x) / scale.x,
|
|
3905
|
-
y: (pointerPos.y - position.y) / scale.y
|
|
3906
|
-
};
|
|
3907
|
-
return stageClickPoint;
|
|
3908
|
-
}
|
|
3909
|
-
isContextMenuVisible() {
|
|
3910
|
-
return this.contextMenuVisible;
|
|
3911
|
-
}
|
|
3912
|
-
isTapHold() {
|
|
3913
|
-
return this.tapHold;
|
|
3914
|
-
}
|
|
3915
|
-
enable() {
|
|
3916
|
-
this.enabled = true;
|
|
3917
|
-
}
|
|
3918
|
-
disable() {
|
|
3919
|
-
this.enabled = false;
|
|
3920
|
-
}
|
|
3921
|
-
};
|
|
3922
|
-
|
|
3923
3699
|
//#endregion
|
|
3924
3700
|
//#region src/plugins/users-selection/constants.ts
|
|
3925
3701
|
const WEAVE_USERS_SELECTION_KEY = "usersSelection";
|
|
@@ -4077,7 +3853,7 @@ var require_toNumber = __commonJS({ "../../node_modules/lodash/toNumber.js"(expo
|
|
|
4077
3853
|
var require_debounce = __commonJS({ "../../node_modules/lodash/debounce.js"(exports, module) {
|
|
4078
3854
|
var isObject$3 = require_isObject(), now = require_now(), toNumber = require_toNumber();
|
|
4079
3855
|
/** Error message constants. */
|
|
4080
|
-
var FUNC_ERROR_TEXT$
|
|
3856
|
+
var FUNC_ERROR_TEXT$2 = "Expected a function";
|
|
4081
3857
|
var nativeMax = Math.max, nativeMin = Math.min;
|
|
4082
3858
|
/**
|
|
4083
3859
|
* Creates a debounced function that delays invoking `func` until after `wait`
|
|
@@ -4135,7 +3911,7 @@ var require_debounce = __commonJS({ "../../node_modules/lodash/debounce.js"(expo
|
|
|
4135
3911
|
*/
|
|
4136
3912
|
function debounce$1(func, wait, options) {
|
|
4137
3913
|
var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
|
|
4138
|
-
if (typeof func != "function") throw new TypeError(FUNC_ERROR_TEXT$
|
|
3914
|
+
if (typeof func != "function") throw new TypeError(FUNC_ERROR_TEXT$2);
|
|
4139
3915
|
wait = toNumber(wait) || 0;
|
|
4140
3916
|
if (isObject$3(options)) {
|
|
4141
3917
|
leading = !!options.leading;
|
|
@@ -4210,7 +3986,7 @@ var require_debounce = __commonJS({ "../../node_modules/lodash/debounce.js"(expo
|
|
|
4210
3986
|
var require_throttle = __commonJS({ "../../node_modules/lodash/throttle.js"(exports, module) {
|
|
4211
3987
|
var debounce = require_debounce(), isObject$2 = require_isObject();
|
|
4212
3988
|
/** Error message constants. */
|
|
4213
|
-
var FUNC_ERROR_TEXT$
|
|
3989
|
+
var FUNC_ERROR_TEXT$1 = "Expected a function";
|
|
4214
3990
|
/**
|
|
4215
3991
|
* Creates a throttled function that only invokes `func` at most once per
|
|
4216
3992
|
* every `wait` milliseconds. The throttled function comes with a `cancel`
|
|
@@ -4257,7 +4033,7 @@ var require_throttle = __commonJS({ "../../node_modules/lodash/throttle.js"(expo
|
|
|
4257
4033
|
*/
|
|
4258
4034
|
function throttle(func, wait, options) {
|
|
4259
4035
|
var leading = true, trailing = true;
|
|
4260
|
-
if (typeof func != "function") throw new TypeError(FUNC_ERROR_TEXT$
|
|
4036
|
+
if (typeof func != "function") throw new TypeError(FUNC_ERROR_TEXT$1);
|
|
4261
4037
|
if (isObject$2(options)) {
|
|
4262
4038
|
leading = "leading" in options ? !!options.leading : leading;
|
|
4263
4039
|
trailing = "trailing" in options ? !!options.trailing : trailing;
|
|
@@ -4278,170 +4054,310 @@ const WEAVE_STAGE_NODE_TYPE = "stage";
|
|
|
4278
4054
|
const WEAVE_STAGE_DEFAULT_MODE = "default";
|
|
4279
4055
|
|
|
4280
4056
|
//#endregion
|
|
4281
|
-
//#region src/
|
|
4282
|
-
const
|
|
4283
|
-
const
|
|
4284
|
-
["
|
|
4285
|
-
["
|
|
4057
|
+
//#region src/actions/selection-tool/constants.ts
|
|
4058
|
+
const SELECTION_TOOL_ACTION_NAME = "selectionTool";
|
|
4059
|
+
const SELECTION_TOOL_STATE = {
|
|
4060
|
+
["IDLE"]: "idle",
|
|
4061
|
+
["SELECTING"]: "selection"
|
|
4286
4062
|
};
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
|
|
4063
|
+
|
|
4064
|
+
//#endregion
|
|
4065
|
+
//#region src/constants.ts
|
|
4066
|
+
const DEFAULT_THROTTLE_MS = 50;
|
|
4067
|
+
const DEFAULT_ADD_NODE_OPTIONS = { emitUserChangeEvent: false };
|
|
4068
|
+
const DEFAULT_UPDATE_NODE_OPTIONS = { emitUserChangeEvent: false };
|
|
4069
|
+
const DEFAULT_REMOVE_NODE_OPTIONS = { emitUserChangeEvent: false };
|
|
4070
|
+
const DEFAULT_MOVE_NODE_OPTIONS = { emitUserChangeEvent: false };
|
|
4071
|
+
const WEAVE_DEFAULT_CONFIG = {
|
|
4072
|
+
behaviors: { axisLockThreshold: 5 },
|
|
4073
|
+
performance: { upscale: { enabled: false } }
|
|
4290
4074
|
};
|
|
4291
|
-
const WEAVE_GRID_DEFAULT_CONFIG = {
|
|
4292
|
-
type: WEAVE_GRID_TYPES.LINES,
|
|
4293
|
-
gridColor: "#b3b3b3",
|
|
4294
|
-
gridMajorColor: "#b3b3b3",
|
|
4295
|
-
gridOriginColor: "#ff746c",
|
|
4296
|
-
gridSize: 20,
|
|
4297
|
-
gridMajorEvery: 10,
|
|
4298
|
-
gridMajorRatio: 2,
|
|
4299
|
-
gridStroke: 1,
|
|
4300
|
-
gridDotType: WEAVE_GRID_DOT_TYPES.CIRCLE,
|
|
4301
|
-
gridDotRadius: 1,
|
|
4302
|
-
gridDotRectSize: 2
|
|
4303
|
-
};
|
|
4304
|
-
const WEAVE_GRID_LAYER_ID = "gridLayer";
|
|
4305
4075
|
|
|
4306
4076
|
//#endregion
|
|
4307
|
-
//#region src/plugins/
|
|
4308
|
-
const
|
|
4309
|
-
const
|
|
4310
|
-
const
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
-
|
|
4077
|
+
//#region src/plugins/nodes-selection/gesture-detector.ts
|
|
4078
|
+
const MOVED_DISTANCE = 5;
|
|
4079
|
+
const DOUBLE_TAP_DISTANCE = 10;
|
|
4080
|
+
const DOUBLE_TAP_TIME = 300;
|
|
4081
|
+
/**
|
|
4082
|
+
* Tracks single-tap, double-tap, and drag-move gesture state for the
|
|
4083
|
+
* nodes-selection plugin. Has no dependency on Weave or Konva internals.
|
|
4084
|
+
*/
|
|
4085
|
+
var GestureDetector = class {
|
|
4086
|
+
taps = 0;
|
|
4087
|
+
tapStart = null;
|
|
4088
|
+
previousTap = null;
|
|
4089
|
+
tapTimeoutId = null;
|
|
4090
|
+
isDoubleTap = false;
|
|
4091
|
+
/** Call on every pointerdown to record the tap origin. */
|
|
4092
|
+
setTapStart(clientX, clientY) {
|
|
4093
|
+
this.taps += 1;
|
|
4094
|
+
this.tapStart = {
|
|
4095
|
+
x: clientX,
|
|
4096
|
+
y: clientY,
|
|
4097
|
+
time: performance.now()
|
|
4098
|
+
};
|
|
4099
|
+
}
|
|
4100
|
+
/** Returns true if the pointer moved more than the move threshold since tap start. */
|
|
4101
|
+
checkMoved(clientX, clientY) {
|
|
4102
|
+
if (!this.tapStart) return false;
|
|
4103
|
+
const dist = Math.hypot(clientX - this.tapStart.x, clientY - this.tapStart.y);
|
|
4104
|
+
return dist > MOVED_DISTANCE;
|
|
4105
|
+
}
|
|
4106
|
+
/** Returns true if a drag moved further than the move threshold between two stage positions. */
|
|
4107
|
+
checkMovedDrag(init, actual) {
|
|
4108
|
+
if (!this.tapStart) return false;
|
|
4109
|
+
const dist = Math.hypot(actual.x - init.x, actual.y - init.y);
|
|
4110
|
+
return dist > MOVED_DISTANCE;
|
|
4111
|
+
}
|
|
4112
|
+
/**
|
|
4113
|
+
* Call on pointerup after setTapStart to detect a double-tap.
|
|
4114
|
+
* Sets isDoubleTap = true when two taps occur close in time and space.
|
|
4115
|
+
*/
|
|
4116
|
+
checkDoubleTap(clientX, clientY) {
|
|
4117
|
+
if (!this.previousTap) return;
|
|
4118
|
+
const now$2 = performance.now();
|
|
4119
|
+
const dist = Math.hypot(clientX - this.previousTap.x, clientY - this.previousTap.y);
|
|
4120
|
+
if (this.tapTimeoutId) clearTimeout(this.tapTimeoutId);
|
|
4121
|
+
this.tapTimeoutId = setTimeout(() => {
|
|
4122
|
+
this.taps = 0;
|
|
4123
|
+
}, DOUBLE_TAP_TIME + 5);
|
|
4124
|
+
if (this.taps > 1 && now$2 - this.previousTap.time < DOUBLE_TAP_TIME && dist < DOUBLE_TAP_DISTANCE) {
|
|
4125
|
+
this.taps = 0;
|
|
4126
|
+
this.tapStart = null;
|
|
4127
|
+
this.isDoubleTap = true;
|
|
4128
|
+
}
|
|
4129
|
+
}
|
|
4130
|
+
/** Call after checkDoubleTap on pointerup to advance the tap history. */
|
|
4131
|
+
commitTap() {
|
|
4132
|
+
this.previousTap = this.tapStart;
|
|
4133
|
+
}
|
|
4134
|
+
resetDoubleTap() {
|
|
4135
|
+
this.isDoubleTap = false;
|
|
4136
|
+
}
|
|
4137
|
+
reset() {
|
|
4138
|
+
this.taps = 0;
|
|
4139
|
+
this.tapStart = null;
|
|
4140
|
+
this.previousTap = null;
|
|
4141
|
+
this.isDoubleTap = false;
|
|
4142
|
+
if (this.tapTimeoutId) {
|
|
4143
|
+
clearTimeout(this.tapTimeoutId);
|
|
4144
|
+
this.tapTimeoutId = null;
|
|
4145
|
+
}
|
|
4146
|
+
}
|
|
4335
4147
|
};
|
|
4336
4148
|
|
|
4337
4149
|
//#endregion
|
|
4338
|
-
//#region src/plugins/
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
selectionStart = null;
|
|
4347
|
-
panSpeed = {
|
|
4150
|
+
//#region src/plugins/nodes-selection/edge-panning.ts
|
|
4151
|
+
/**
|
|
4152
|
+
* Handles the rAF-driven auto-pan loop that scrolls the canvas when the
|
|
4153
|
+
* pointer is held near an edge during area selection.
|
|
4154
|
+
*/
|
|
4155
|
+
var EdgePanning = class {
|
|
4156
|
+
panLoopId = null;
|
|
4157
|
+
direction = {
|
|
4348
4158
|
x: 0,
|
|
4349
4159
|
y: 0
|
|
4350
4160
|
};
|
|
4351
|
-
|
|
4161
|
+
speed = {
|
|
4352
4162
|
x: 0,
|
|
4353
4163
|
y: 0
|
|
4354
4164
|
};
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
dragInProcess = false;
|
|
4359
|
-
dragSelectedNodes = [];
|
|
4360
|
-
transformInProcess = false;
|
|
4361
|
-
serializedSelectedNodes = [];
|
|
4362
|
-
constructor(params) {
|
|
4363
|
-
super();
|
|
4364
|
-
this.config = mergeExceptArrays(WEAVE_NODES_SELECTION_DEFAULT_CONFIG, params?.config ?? {});
|
|
4365
|
-
this.initialize();
|
|
4165
|
+
constructor(config, callbacks) {
|
|
4166
|
+
this.config = config;
|
|
4167
|
+
this.callbacks = callbacks;
|
|
4366
4168
|
}
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
"top-center",
|
|
4371
|
-
"top-right",
|
|
4372
|
-
"middle-right",
|
|
4373
|
-
"middle-left",
|
|
4374
|
-
"bottom-left",
|
|
4375
|
-
"bottom-center",
|
|
4376
|
-
"bottom-right"
|
|
4377
|
-
];
|
|
4378
|
-
this.taps = 0;
|
|
4379
|
-
this.isSpaceKeyPressed = false;
|
|
4380
|
-
this.isDoubleTap = false;
|
|
4381
|
-
this.tapStart = null;
|
|
4382
|
-
this.previousTap = null;
|
|
4383
|
-
this.active = false;
|
|
4384
|
-
this.didMove = false;
|
|
4385
|
-
this.selecting = false;
|
|
4386
|
-
this.initialized = false;
|
|
4387
|
-
this.enabled = false;
|
|
4388
|
-
this.pointers = {};
|
|
4389
|
-
this.panLoopId = null;
|
|
4390
|
-
this.tapTimeoutId = null;
|
|
4391
|
-
this.dragSelectedNodes = [];
|
|
4392
|
-
this.dragInProcess = false;
|
|
4169
|
+
/** Start the panning rAF loop. */
|
|
4170
|
+
start() {
|
|
4171
|
+
this.panLoopId = requestAnimationFrame(() => this.loop());
|
|
4393
4172
|
}
|
|
4394
|
-
|
|
4395
|
-
|
|
4173
|
+
/** Stop the panning rAF loop. */
|
|
4174
|
+
stop() {
|
|
4175
|
+
if (this.panLoopId !== null) {
|
|
4176
|
+
cancelAnimationFrame(this.panLoopId);
|
|
4177
|
+
this.panLoopId = null;
|
|
4178
|
+
}
|
|
4396
4179
|
}
|
|
4397
|
-
|
|
4398
|
-
|
|
4180
|
+
/** Reset direction and speed vectors to zero. */
|
|
4181
|
+
reset() {
|
|
4182
|
+
this.direction.x = 0;
|
|
4183
|
+
this.direction.y = 0;
|
|
4184
|
+
this.speed = {
|
|
4185
|
+
x: 0,
|
|
4186
|
+
y: 0
|
|
4187
|
+
};
|
|
4399
4188
|
}
|
|
4400
|
-
|
|
4401
|
-
|
|
4189
|
+
/**
|
|
4190
|
+
* Recalculate pan direction and speed based on current pointer position.
|
|
4191
|
+
* Should be called on every pointermove during area selection.
|
|
4192
|
+
*/
|
|
4193
|
+
updateDirection() {
|
|
4194
|
+
const stage = this.callbacks.getStage();
|
|
4195
|
+
const pos = stage.getPointerPosition();
|
|
4196
|
+
const viewWidth = stage.width();
|
|
4197
|
+
const viewHeight = stage.height();
|
|
4198
|
+
if (!pos) return;
|
|
4199
|
+
const distLeft = pos.x;
|
|
4200
|
+
const distRight = viewWidth - pos.x;
|
|
4201
|
+
const distTop = pos.y;
|
|
4202
|
+
const distBottom = viewHeight - pos.y;
|
|
4203
|
+
this.direction.x = 0;
|
|
4204
|
+
this.direction.y = 0;
|
|
4205
|
+
this.speed = {
|
|
4206
|
+
x: 0,
|
|
4207
|
+
y: 0
|
|
4208
|
+
};
|
|
4209
|
+
if (distLeft < this.config.edgeThreshold) {
|
|
4210
|
+
this.direction.x = 1;
|
|
4211
|
+
this.speed.x = this.getSpeedFromEdge(distLeft);
|
|
4212
|
+
} else if (distRight < this.config.edgeThreshold) {
|
|
4213
|
+
this.direction.x = -1;
|
|
4214
|
+
this.speed.x = this.getSpeedFromEdge(distRight);
|
|
4215
|
+
}
|
|
4216
|
+
if (distTop < this.config.edgeThreshold) {
|
|
4217
|
+
this.direction.y = 1;
|
|
4218
|
+
this.speed.y = this.getSpeedFromEdge(distTop);
|
|
4219
|
+
} else if (distBottom < this.config.edgeThreshold) {
|
|
4220
|
+
this.direction.y = -1;
|
|
4221
|
+
this.speed.y = this.getSpeedFromEdge(distBottom);
|
|
4222
|
+
}
|
|
4402
4223
|
}
|
|
4403
|
-
|
|
4404
|
-
const stage = this.
|
|
4405
|
-
const
|
|
4406
|
-
|
|
4224
|
+
getSpeedFromEdge(distanceFromEdge) {
|
|
4225
|
+
const stage = this.callbacks.getStage();
|
|
4226
|
+
const scaledDistance = distanceFromEdge / stage.scaleX();
|
|
4227
|
+
if (scaledDistance < this.config.edgeThreshold) {
|
|
4228
|
+
const factor = 1 - scaledDistance / this.config.edgeThreshold;
|
|
4229
|
+
return this.config.minScrollSpeed + (this.config.maxScrollSpeed - this.config.minScrollSpeed) * factor;
|
|
4230
|
+
}
|
|
4231
|
+
return 0;
|
|
4407
4232
|
}
|
|
4408
|
-
|
|
4409
|
-
const
|
|
4410
|
-
if (
|
|
4411
|
-
|
|
4233
|
+
loop() {
|
|
4234
|
+
const stage = this.callbacks.getStage();
|
|
4235
|
+
if (this.callbacks.isSelecting() && (this.direction.x !== 0 || this.direction.y !== 0)) {
|
|
4236
|
+
const scale = stage.scaleX();
|
|
4237
|
+
const stepX = (this.speed.x || 0) / scale;
|
|
4238
|
+
const stepY = (this.speed.y || 0) / scale;
|
|
4239
|
+
stage.x(stage.x() + this.direction.x * stepX);
|
|
4240
|
+
stage.y(stage.y() + this.direction.y * stepY);
|
|
4241
|
+
this.callbacks.onTick(this.direction.x * stepX, this.direction.y * stepY);
|
|
4242
|
+
}
|
|
4243
|
+
if (this.callbacks.isSelecting()) this.panLoopId = requestAnimationFrame(() => this.loop());
|
|
4412
4244
|
}
|
|
4413
|
-
|
|
4414
|
-
|
|
4245
|
+
};
|
|
4246
|
+
|
|
4247
|
+
//#endregion
|
|
4248
|
+
//#region src/plugins/nodes-selection/area-selection.ts
|
|
4249
|
+
/**
|
|
4250
|
+
* Manages the visual selection-rectangle drawn while the user drags an area
|
|
4251
|
+
* selection, plus the coordinate state (x1/y1/x2/y2) that tracks its bounds.
|
|
4252
|
+
*/
|
|
4253
|
+
var AreaSelector = class {
|
|
4254
|
+
x1 = 0;
|
|
4255
|
+
y1 = 0;
|
|
4256
|
+
x2 = 0;
|
|
4257
|
+
y2 = 0;
|
|
4258
|
+
/** The stage-space anchor point when area selection started (updated by edge panning). */
|
|
4259
|
+
selectionStart = null;
|
|
4260
|
+
/**
|
|
4261
|
+
* Create and add the selection Konva.Rect to the given layer.
|
|
4262
|
+
* Must be called once during plugin initialisation.
|
|
4263
|
+
*/
|
|
4264
|
+
init(layer, config, scaleX) {
|
|
4265
|
+
this.rect = new Konva.Rect({
|
|
4266
|
+
...config,
|
|
4267
|
+
...config.strokeWidth && { strokeWidth: config.strokeWidth / scaleX },
|
|
4268
|
+
...config.dash && { dash: config.dash.map((d) => d / scaleX) },
|
|
4269
|
+
visible: false,
|
|
4270
|
+
listening: false
|
|
4271
|
+
});
|
|
4272
|
+
layer.add(this.rect);
|
|
4415
4273
|
}
|
|
4416
|
-
|
|
4417
|
-
return this.
|
|
4274
|
+
getRect() {
|
|
4275
|
+
return this.rect;
|
|
4418
4276
|
}
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
return selected;
|
|
4277
|
+
/** Returns the screen-space bounding box of the selection rectangle. */
|
|
4278
|
+
getBox() {
|
|
4279
|
+
return this.rect.getClientRect();
|
|
4423
4280
|
}
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4281
|
+
/** Set the anchor corner when area selection begins. */
|
|
4282
|
+
setStart(x, y) {
|
|
4283
|
+
this.x1 = x;
|
|
4284
|
+
this.y1 = y;
|
|
4285
|
+
this.x2 = x;
|
|
4286
|
+
this.y2 = y;
|
|
4287
|
+
this.selectionStart = {
|
|
4288
|
+
x,
|
|
4289
|
+
y
|
|
4290
|
+
};
|
|
4291
|
+
}
|
|
4292
|
+
/**
|
|
4293
|
+
* Adjust stroke and dash to compensate for stage scale, reset dimensions.
|
|
4294
|
+
* Call when area selection starts so the rect looks pixel-perfect at any zoom.
|
|
4295
|
+
*/
|
|
4296
|
+
resetForScale(scaleX, config) {
|
|
4297
|
+
this.rect.strokeWidth(config.strokeWidth / scaleX);
|
|
4298
|
+
this.rect.dash(config.dash?.map((d) => d / scaleX) ?? []);
|
|
4299
|
+
this.rect.width(0);
|
|
4300
|
+
this.rect.height(0);
|
|
4301
|
+
}
|
|
4302
|
+
/**
|
|
4303
|
+
* Recalculate x2/y2 from the current pointer position and repaint the rect.
|
|
4304
|
+
* @param selectNone — Callback that clears the transformer selection; called
|
|
4305
|
+
* before updating the rect so previously selected nodes are deselected.
|
|
4306
|
+
*/
|
|
4307
|
+
update(stage, selectNone) {
|
|
4308
|
+
this.x2 = stage.getRelativePointerPosition()?.x ?? 0;
|
|
4309
|
+
this.y2 = stage.getRelativePointerPosition()?.y ?? 0;
|
|
4310
|
+
selectNone();
|
|
4311
|
+
this.rect.setAttrs({
|
|
4312
|
+
visible: true,
|
|
4313
|
+
x: Math.min(this.x1, this.x2),
|
|
4314
|
+
y: Math.min(this.y1, this.y2),
|
|
4315
|
+
width: Math.abs(this.x2 - this.x1),
|
|
4316
|
+
height: Math.abs(this.y2 - this.y1)
|
|
4435
4317
|
});
|
|
4436
|
-
|
|
4437
|
-
|
|
4318
|
+
}
|
|
4319
|
+
hide() {
|
|
4320
|
+
this.rect.setAttrs({
|
|
4321
|
+
width: 0,
|
|
4322
|
+
height: 0,
|
|
4323
|
+
visible: false
|
|
4324
|
+
});
|
|
4325
|
+
}
|
|
4326
|
+
};
|
|
4327
|
+
|
|
4328
|
+
//#endregion
|
|
4329
|
+
//#region src/plugins/nodes-selection/transformer-controller.ts
|
|
4330
|
+
/**
|
|
4331
|
+
* Creates and owns both Konva.Transformer instances (selection + hover) and
|
|
4332
|
+
* registers all transformer-level event handlers. Business-logic callbacks are
|
|
4333
|
+
* injected to keep this class decoupled from WeaveNodesSelectionPlugin internals.
|
|
4334
|
+
*/
|
|
4335
|
+
var TransformerController = class {
|
|
4336
|
+
dragInProcess = false;
|
|
4337
|
+
transformInProcess = false;
|
|
4338
|
+
didMove = false;
|
|
4339
|
+
initialPos = null;
|
|
4340
|
+
originalNodes = {};
|
|
4341
|
+
originalContainers = {};
|
|
4342
|
+
currentDragSelectedNodes = [];
|
|
4343
|
+
/** Mirrors the previous transformer node list for undo/redo handling. */
|
|
4344
|
+
prevSelectedNodes = [];
|
|
4345
|
+
constructor(instance, config, gesture, callbacks) {
|
|
4346
|
+
this.instance = instance;
|
|
4347
|
+
this.config = config;
|
|
4348
|
+
this.gesture = gesture;
|
|
4349
|
+
this.callbacks = callbacks;
|
|
4350
|
+
}
|
|
4351
|
+
/** Create transformers, add to layer, and register all events. Must be called once during onInit. */
|
|
4352
|
+
setup(layer) {
|
|
4353
|
+
this.tr = new Konva.Transformer({
|
|
4438
4354
|
id: "selectionTransformer",
|
|
4439
4355
|
...this.config.selection,
|
|
4440
4356
|
listening: true,
|
|
4441
4357
|
shouldOverdrawWholeArea: true
|
|
4442
4358
|
});
|
|
4443
|
-
|
|
4444
|
-
|
|
4359
|
+
layer.add(this.tr);
|
|
4360
|
+
this.trHover = new Konva.Transformer({
|
|
4445
4361
|
id: "hoverTransformer",
|
|
4446
4362
|
...this.config.hover,
|
|
4447
4363
|
ignoreStroke: true,
|
|
@@ -4450,94 +4366,87 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
4450
4366
|
enabledAnchors: [],
|
|
4451
4367
|
listening: false
|
|
4452
4368
|
});
|
|
4453
|
-
|
|
4369
|
+
layer.add(this.trHover);
|
|
4370
|
+
this.registerStagePointerMove();
|
|
4371
|
+
this.registerTransformerEvents();
|
|
4372
|
+
this.registerInstanceEvents();
|
|
4373
|
+
}
|
|
4374
|
+
getTransformer() {
|
|
4375
|
+
return this.tr;
|
|
4376
|
+
}
|
|
4377
|
+
getHoverTransformer() {
|
|
4378
|
+
return this.trHover;
|
|
4379
|
+
}
|
|
4380
|
+
isDragging() {
|
|
4381
|
+
return this.dragInProcess;
|
|
4382
|
+
}
|
|
4383
|
+
isTransforming() {
|
|
4384
|
+
return this.transformInProcess;
|
|
4385
|
+
}
|
|
4386
|
+
getStage() {
|
|
4387
|
+
return this.instance.getStage();
|
|
4388
|
+
}
|
|
4389
|
+
registerStagePointerMove() {
|
|
4390
|
+
const stage = this.getStage();
|
|
4454
4391
|
const handlePointerMoveInit = () => {
|
|
4455
4392
|
if (this.dragInProcess) return;
|
|
4456
|
-
if (tr.nodes().length === 1 && tr.nodes()[0].getAttrs().isContainerPrincipal) {
|
|
4393
|
+
if (this.tr.nodes().length === 1 && this.tr.nodes()[0].getAttrs().isContainerPrincipal) {
|
|
4457
4394
|
const pos = stage.getPointerPosition();
|
|
4458
4395
|
if (!pos) return;
|
|
4459
4396
|
const shapeUnder = stage.getIntersection(pos);
|
|
4460
4397
|
if (!shapeUnder) {
|
|
4461
|
-
tr.setAttrs({ listening: true });
|
|
4462
|
-
tr.forceUpdate();
|
|
4398
|
+
this.tr.setAttrs({ listening: true });
|
|
4399
|
+
this.tr.forceUpdate();
|
|
4463
4400
|
}
|
|
4464
|
-
if (shapeUnder && tr.getChildren().includes(shapeUnder) && shapeUnder.name() === "back") {
|
|
4465
|
-
tr.setAttrs({ listening: false });
|
|
4466
|
-
tr.forceUpdate();
|
|
4401
|
+
if (shapeUnder && this.tr.getChildren().includes(shapeUnder) && shapeUnder.name() === "back") {
|
|
4402
|
+
this.tr.setAttrs({ listening: false });
|
|
4403
|
+
this.tr.forceUpdate();
|
|
4467
4404
|
}
|
|
4468
|
-
if (shapeUnder && tr.nodes()[0].getChildren().includes(shapeUnder)) {
|
|
4469
|
-
tr.setAttrs({ listening: false });
|
|
4470
|
-
tr.forceUpdate();
|
|
4405
|
+
if (shapeUnder && this.tr.nodes()[0].getChildren().includes(shapeUnder)) {
|
|
4406
|
+
this.tr.setAttrs({ listening: false });
|
|
4407
|
+
this.tr.forceUpdate();
|
|
4471
4408
|
}
|
|
4472
|
-
if (shapeUnder && !tr.getChildren().includes(shapeUnder) && tr.nodes()[0].getChildren().includes(shapeUnder)) {
|
|
4473
|
-
tr.setAttrs({ listening: true });
|
|
4474
|
-
tr.forceUpdate();
|
|
4409
|
+
if (shapeUnder && !this.tr.getChildren().includes(shapeUnder) && this.tr.nodes()[0].getChildren().includes(shapeUnder)) {
|
|
4410
|
+
this.tr.setAttrs({ listening: true });
|
|
4411
|
+
this.tr.forceUpdate();
|
|
4475
4412
|
}
|
|
4476
4413
|
}
|
|
4477
4414
|
};
|
|
4478
4415
|
stage.on("pointermove", (0, import_throttle.default)(handlePointerMoveInit, DEFAULT_THROTTLE_MS));
|
|
4479
|
-
|
|
4416
|
+
}
|
|
4417
|
+
registerTransformerEvents() {
|
|
4418
|
+
const stage = this.getStage();
|
|
4419
|
+
let nodeHovered = void 0;
|
|
4420
|
+
this.tr.on("transformstart", (e) => {
|
|
4480
4421
|
this.transformInProcess = true;
|
|
4481
|
-
this.triggerSelectedNodesEvent();
|
|
4482
|
-
const selectedNodes
|
|
4483
|
-
for (const node of selectedNodes
|
|
4484
|
-
if (
|
|
4485
|
-
nodeIds: selectedNodes
|
|
4422
|
+
this.callbacks.triggerSelectedNodesEvent();
|
|
4423
|
+
const selectedNodes = this.tr.nodes();
|
|
4424
|
+
for (const node of selectedNodes) node.handleMouseout(e);
|
|
4425
|
+
if (selectedNodes.length > 1) this.instance.setMutexLock({
|
|
4426
|
+
nodeIds: selectedNodes.map((node) => node.id()),
|
|
4486
4427
|
operation: "nodes-transform"
|
|
4487
4428
|
});
|
|
4488
4429
|
this.instance.getHooks().callHook("weave:onTransformerTransformStart", {
|
|
4489
4430
|
e,
|
|
4490
|
-
nodes: selectedNodes
|
|
4431
|
+
nodes: selectedNodes
|
|
4491
4432
|
});
|
|
4492
4433
|
});
|
|
4493
|
-
let nodeHovered = void 0;
|
|
4494
|
-
tr.on("mousemove", (e) => {
|
|
4495
|
-
if (this.dragInProcess) return;
|
|
4496
|
-
const pointerPos = stage.getPointerPosition();
|
|
4497
|
-
if (!pointerPos) return;
|
|
4498
|
-
this.disable();
|
|
4499
|
-
const shape = stage.getIntersection(pointerPos);
|
|
4500
|
-
this.enable();
|
|
4501
|
-
if (shape) {
|
|
4502
|
-
const targetNode = this.instance.getInstanceRecursive(shape);
|
|
4503
|
-
if (targetNode && targetNode !== nodeHovered) {
|
|
4504
|
-
this.instance.getStage().handleMouseover(e);
|
|
4505
|
-
nodeHovered?.handleMouseout?.(e);
|
|
4506
|
-
targetNode?.handleMouseover?.(e);
|
|
4507
|
-
nodeHovered = targetNode;
|
|
4508
|
-
}
|
|
4509
|
-
targetNode?.handleMouseover?.(e);
|
|
4510
|
-
} else nodeHovered?.handleMouseout?.(e);
|
|
4511
|
-
});
|
|
4512
|
-
tr.on("mouseover", () => {
|
|
4513
|
-
const nodesSelected = tr.nodes();
|
|
4514
|
-
if (nodesSelected.length > 1) stage.container().style.cursor = "grab";
|
|
4515
|
-
});
|
|
4516
|
-
tr.on("mouseout", (e) => {
|
|
4517
|
-
this.instance.getStage().handleMouseover?.(e);
|
|
4518
|
-
nodeHovered = void 0;
|
|
4519
|
-
});
|
|
4520
|
-
window.addEventListener("mouseout", (e) => {
|
|
4521
|
-
if (nodeHovered) {
|
|
4522
|
-
nodeHovered.handleMouseout?.(e);
|
|
4523
|
-
nodeHovered = void 0;
|
|
4524
|
-
}
|
|
4525
|
-
this.instance.getStage().handleMouseover?.(e);
|
|
4526
|
-
}, { signal: this.instance.getEventsController()?.signal });
|
|
4527
4434
|
const handleTransform = (e) => {
|
|
4528
|
-
const moved = this.checkMoved(e);
|
|
4529
|
-
if (moved) this.getContextMenuPlugin()?.cancelLongPressTimer();
|
|
4530
|
-
this.triggerSelectedNodesEvent();
|
|
4435
|
+
const moved = this.gesture.checkMoved(e.evt.clientX, e.evt.clientY);
|
|
4436
|
+
if (moved) this.callbacks.getContextMenuPlugin()?.cancelLongPressTimer();
|
|
4437
|
+
this.callbacks.triggerSelectedNodesEvent();
|
|
4438
|
+
const selectedNodes = this.tr.nodes();
|
|
4531
4439
|
this.instance.getHooks().callHook("weave:onTransformerTransform", {
|
|
4532
4440
|
e,
|
|
4533
4441
|
nodes: selectedNodes
|
|
4534
4442
|
});
|
|
4535
|
-
|
|
4536
|
-
|
|
4443
|
+
const usersPresence = this.callbacks.getUsersPresencePlugin();
|
|
4444
|
+
if (usersPresence) {
|
|
4445
|
+
for (const node of this.tr.nodes()) {
|
|
4537
4446
|
let parentId = node.getParent()?.id() ?? "";
|
|
4538
4447
|
const parent = node.getParent();
|
|
4539
4448
|
if (parent?.getAttrs().nodeId) parentId = parent.getAttrs().nodeId;
|
|
4540
|
-
|
|
4449
|
+
usersPresence.setPresence(node.id(), parentId, {
|
|
4541
4450
|
x: node.x(),
|
|
4542
4451
|
y: node.y(),
|
|
4543
4452
|
width: node.width(),
|
|
@@ -4548,65 +4457,92 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
4548
4457
|
strokeScaleEnabled: false
|
|
4549
4458
|
}, false);
|
|
4550
4459
|
}
|
|
4551
|
-
|
|
4460
|
+
usersPresence.forceSendPresence();
|
|
4552
4461
|
}
|
|
4553
4462
|
};
|
|
4554
|
-
tr.on("transform", (0, import_throttle.default)(handleTransform, DEFAULT_THROTTLE_MS));
|
|
4555
|
-
tr.on("transformend", (e) => {
|
|
4463
|
+
this.tr.on("transform", (0, import_throttle.default)(handleTransform, DEFAULT_THROTTLE_MS));
|
|
4464
|
+
this.tr.on("transformend", (e) => {
|
|
4556
4465
|
this.transformInProcess = false;
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
for (const node of selectedNodes
|
|
4466
|
+
const selectedNodes = this.tr.nodes();
|
|
4467
|
+
if (selectedNodes.length > 1) this.instance.releaseMutexLock();
|
|
4468
|
+
for (const node of selectedNodes) {
|
|
4560
4469
|
node.handleDeselectNode();
|
|
4561
4470
|
node.handleSelectNode();
|
|
4562
4471
|
}
|
|
4563
|
-
tr.forceUpdate();
|
|
4564
|
-
this.triggerSelectedNodesEvent();
|
|
4472
|
+
this.tr.forceUpdate();
|
|
4473
|
+
this.callbacks.triggerSelectedNodesEvent();
|
|
4565
4474
|
this.instance.getHooks().callHook("weave:onTransformerTransformEnd", {
|
|
4566
4475
|
e,
|
|
4567
|
-
nodes: selectedNodes
|
|
4476
|
+
nodes: selectedNodes
|
|
4568
4477
|
});
|
|
4569
4478
|
});
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4573
|
-
|
|
4574
|
-
|
|
4479
|
+
this.tr.on("mousemove", (e) => {
|
|
4480
|
+
if (this.dragInProcess) return;
|
|
4481
|
+
const pointerPos = stage.getPointerPosition();
|
|
4482
|
+
if (!pointerPos) return;
|
|
4483
|
+
this.callbacks.disablePlugin();
|
|
4484
|
+
const shape = stage.getIntersection(pointerPos);
|
|
4485
|
+
this.callbacks.enablePlugin();
|
|
4486
|
+
if (shape) {
|
|
4487
|
+
const targetNode = this.instance.getInstanceRecursive(shape);
|
|
4488
|
+
if (targetNode && targetNode !== nodeHovered) {
|
|
4489
|
+
this.instance.getStage().handleMouseover(e);
|
|
4490
|
+
nodeHovered?.handleMouseout?.(e);
|
|
4491
|
+
targetNode?.handleMouseover?.(e);
|
|
4492
|
+
nodeHovered = targetNode;
|
|
4493
|
+
}
|
|
4494
|
+
targetNode?.handleMouseover?.(e);
|
|
4495
|
+
} else nodeHovered?.handleMouseout?.(e);
|
|
4496
|
+
});
|
|
4497
|
+
this.tr.on("mouseover", () => {
|
|
4498
|
+
const nodesSelected = this.tr.nodes();
|
|
4499
|
+
if (nodesSelected.length > 1) stage.container().style.cursor = "grab";
|
|
4500
|
+
});
|
|
4501
|
+
this.tr.on("mouseout", (e) => {
|
|
4502
|
+
this.instance.getStage().handleMouseover?.(e);
|
|
4503
|
+
nodeHovered = void 0;
|
|
4504
|
+
});
|
|
4505
|
+
window.addEventListener("mouseout", (e) => {
|
|
4506
|
+
if (nodeHovered) {
|
|
4507
|
+
nodeHovered.handleMouseout?.(e);
|
|
4508
|
+
nodeHovered = void 0;
|
|
4509
|
+
}
|
|
4510
|
+
this.instance.getStage().handleMouseover?.(e);
|
|
4511
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
4512
|
+
this.tr.on("dragstart", (e) => {
|
|
4575
4513
|
this.dragInProcess = true;
|
|
4576
4514
|
if (!e?.evt) return;
|
|
4577
|
-
|
|
4578
|
-
if (e.evt?.button === 1) isWheelMousePressed = true;
|
|
4515
|
+
const isWheelMousePressed = e.evt?.button === 1;
|
|
4579
4516
|
const mainLayer = this.instance.getMainLayer();
|
|
4580
4517
|
if (!mainLayer) return;
|
|
4581
|
-
initialPos = {
|
|
4518
|
+
this.initialPos = {
|
|
4582
4519
|
x: e.target.x(),
|
|
4583
4520
|
y: e.target.y()
|
|
4584
4521
|
};
|
|
4585
4522
|
this.didMove = false;
|
|
4586
|
-
|
|
4587
|
-
this.
|
|
4588
|
-
this.
|
|
4589
|
-
selectedNodes = tr.nodes();
|
|
4523
|
+
this.callbacks.saveDragSelectedNodes();
|
|
4524
|
+
this.callbacks.setNodesOpacityOnDrag();
|
|
4525
|
+
this.currentDragSelectedNodes = this.tr.nodes();
|
|
4590
4526
|
if (isWheelMousePressed) {
|
|
4591
4527
|
e.cancelBubble = true;
|
|
4592
4528
|
e.target.stopDrag();
|
|
4593
4529
|
return;
|
|
4594
4530
|
}
|
|
4595
|
-
for (const node of
|
|
4531
|
+
for (const node of this.currentDragSelectedNodes) {
|
|
4596
4532
|
const originalNode = node.clone();
|
|
4597
4533
|
let originalContainer = node.getParent();
|
|
4598
|
-
if (originalContainer?.getAttrs().nodeId) originalContainer = stage
|
|
4599
|
-
originalNodes[node.getAttrs().id ?? ""] = originalNode;
|
|
4600
|
-
originalContainers[node.getAttrs().id ?? ""] = originalContainer;
|
|
4534
|
+
if (originalContainer?.getAttrs().nodeId) originalContainer = stage.findOne(`#${originalContainer.getAttrs().nodeId}`);
|
|
4535
|
+
this.originalNodes[node.getAttrs().id ?? ""] = originalNode;
|
|
4536
|
+
this.originalContainers[node.getAttrs().id ?? ""] = originalContainer;
|
|
4601
4537
|
}
|
|
4602
4538
|
e.cancelBubble = true;
|
|
4603
4539
|
this.instance.getHooks().callHook("weave:onTransformerDragStart", {
|
|
4604
4540
|
e,
|
|
4605
|
-
nodes:
|
|
4541
|
+
nodes: this.currentDragSelectedNodes
|
|
4606
4542
|
});
|
|
4607
|
-
tr.forceUpdate();
|
|
4608
|
-
if (
|
|
4609
|
-
nodeIds:
|
|
4543
|
+
this.tr.forceUpdate();
|
|
4544
|
+
if (this.currentDragSelectedNodes.length > 1) this.instance.setMutexLock({
|
|
4545
|
+
nodeIds: this.currentDragSelectedNodes.map((node) => node.id()),
|
|
4610
4546
|
operation: "nodes-drag"
|
|
4611
4547
|
});
|
|
4612
4548
|
});
|
|
@@ -4615,16 +4551,15 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
4615
4551
|
x: e.target.x(),
|
|
4616
4552
|
y: e.target.y()
|
|
4617
4553
|
};
|
|
4618
|
-
|
|
4619
|
-
if (e.evt?.button === 1) isWheelMousePressed = true;
|
|
4554
|
+
const isWheelMousePressed = e.evt?.button === 1;
|
|
4620
4555
|
e.cancelBubble = true;
|
|
4621
4556
|
this.instance.getHooks().callHook("weave:onTransformerDragMove", {
|
|
4622
4557
|
e,
|
|
4623
|
-
nodes:
|
|
4558
|
+
nodes: this.currentDragSelectedNodes
|
|
4624
4559
|
});
|
|
4625
|
-
if (initialPos) {
|
|
4626
|
-
const moved = this.checkMovedDrag(initialPos, actualPos);
|
|
4627
|
-
if (moved) this.getContextMenuPlugin()?.cancelLongPressTimer();
|
|
4560
|
+
if (this.initialPos) {
|
|
4561
|
+
const moved = this.gesture.checkMovedDrag(this.initialPos, actualPos);
|
|
4562
|
+
if (moved) this.callbacks.getContextMenuPlugin()?.cancelLongPressTimer();
|
|
4628
4563
|
}
|
|
4629
4564
|
if (isWheelMousePressed) {
|
|
4630
4565
|
e.cancelBubble = true;
|
|
@@ -4633,64 +4568,65 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
4633
4568
|
}
|
|
4634
4569
|
this.didMove = true;
|
|
4635
4570
|
let selectionContainsFrames = false;
|
|
4636
|
-
for (let i = 0; i <
|
|
4637
|
-
const node =
|
|
4571
|
+
for (let i = 0; i < this.currentDragSelectedNodes.length; i++) {
|
|
4572
|
+
const node = this.currentDragSelectedNodes[i];
|
|
4638
4573
|
selectionContainsFrames = selectionContainsFrames || hasFrames(node);
|
|
4639
4574
|
node.updatePosition(node.getAbsolutePosition());
|
|
4640
4575
|
}
|
|
4641
|
-
if (
|
|
4642
|
-
originalNodes = {};
|
|
4643
|
-
originalContainers = {};
|
|
4576
|
+
if (this.currentDragSelectedNodes.length === 1) {
|
|
4577
|
+
this.originalNodes = {};
|
|
4578
|
+
this.originalContainers = {};
|
|
4644
4579
|
}
|
|
4645
|
-
if (this.isSelecting() &&
|
|
4580
|
+
if (this.callbacks.isSelecting() && this.currentDragSelectedNodes.length > 1) {
|
|
4646
4581
|
clearContainerTargets(this.instance);
|
|
4647
|
-
const layerToMove = containerOverCursor(this.instance,
|
|
4648
|
-
|
|
4649
|
-
|
|
4582
|
+
const layerToMove = containerOverCursor(this.instance, this.currentDragSelectedNodes);
|
|
4583
|
+
const usersPresence = this.callbacks.getUsersPresencePlugin();
|
|
4584
|
+
if (usersPresence && this.dragInProcess) {
|
|
4585
|
+
for (const node of this.currentDragSelectedNodes) {
|
|
4650
4586
|
let parentId = node.getParent()?.id() ?? "";
|
|
4651
4587
|
const parent = node.getParent();
|
|
4652
4588
|
if (parent?.getAttrs().nodeId) parentId = parent.getAttrs().nodeId;
|
|
4653
|
-
|
|
4589
|
+
usersPresence.setPresence(node.id(), parentId, {
|
|
4654
4590
|
x: node.x(),
|
|
4655
4591
|
y: node.y()
|
|
4656
4592
|
}, false);
|
|
4657
4593
|
}
|
|
4658
|
-
|
|
4594
|
+
usersPresence.forceSendPresence();
|
|
4659
4595
|
}
|
|
4660
4596
|
if (layerToMove && !selectionContainsFrames) layerToMove.fire(WEAVE_NODE_CUSTOM_EVENTS.onTargetEnter, { bubbles: true });
|
|
4661
4597
|
}
|
|
4662
|
-
tr.forceUpdate();
|
|
4598
|
+
this.tr.forceUpdate();
|
|
4663
4599
|
};
|
|
4664
|
-
tr.on("dragmove", handleDragMove);
|
|
4665
|
-
tr.on("dragend", (e) => {
|
|
4600
|
+
this.tr.on("dragmove", handleDragMove);
|
|
4601
|
+
this.tr.on("dragend", (e) => {
|
|
4666
4602
|
this.dragInProcess = false;
|
|
4667
4603
|
const mainLayer = this.instance.getMainLayer();
|
|
4668
4604
|
if (!mainLayer) return;
|
|
4669
4605
|
this.instance.getSelectionLayer()?.hitGraphEnabled(true);
|
|
4670
4606
|
this.instance.getMainLayer()?.hitGraphEnabled(true);
|
|
4671
4607
|
if (!this.didMove) return;
|
|
4672
|
-
if (
|
|
4608
|
+
if (this.currentDragSelectedNodes.length > 1) this.instance.releaseMutexLock();
|
|
4673
4609
|
e.cancelBubble = true;
|
|
4674
4610
|
this.instance.getHooks().callHook("weave:onTransformerDragEnd", {
|
|
4675
4611
|
e,
|
|
4676
|
-
nodes:
|
|
4612
|
+
nodes: this.currentDragSelectedNodes
|
|
4677
4613
|
});
|
|
4678
4614
|
this.instance.getCloningManager().cleanupClones();
|
|
4679
|
-
this.getStagePanningPlugin()?.cleanupEdgeMoveIntervals();
|
|
4615
|
+
this.callbacks.getStagePanningPlugin()?.cleanupEdgeMoveIntervals();
|
|
4680
4616
|
let selectionContainsFrames = false;
|
|
4681
|
-
for (let i = 0; i <
|
|
4682
|
-
const node =
|
|
4617
|
+
for (let i = 0; i < this.currentDragSelectedNodes.length; i++) {
|
|
4618
|
+
const node = this.currentDragSelectedNodes[i];
|
|
4683
4619
|
selectionContainsFrames = selectionContainsFrames || hasFrames(node);
|
|
4684
4620
|
node.updatePosition(node.getAbsolutePosition());
|
|
4685
4621
|
}
|
|
4686
|
-
if (this.isSelecting() &&
|
|
4622
|
+
if (this.callbacks.isSelecting() && this.currentDragSelectedNodes.length > 1) {
|
|
4687
4623
|
const toSelect = [];
|
|
4688
4624
|
const toUpdate = [];
|
|
4689
4625
|
this.instance.stateTransactional(() => {
|
|
4690
4626
|
const actualCursor = stage.container().style.cursor;
|
|
4691
4627
|
stage.container().style.cursor = "wait";
|
|
4692
4628
|
clearContainerTargets(this.instance);
|
|
4693
|
-
const layerToMove = containerOverCursor(this.instance,
|
|
4629
|
+
const layerToMove = containerOverCursor(this.instance, this.currentDragSelectedNodes);
|
|
4694
4630
|
const nodeUpdate = (node) => {
|
|
4695
4631
|
const isLockedToContainer = node.getAttrs().lockToContainer;
|
|
4696
4632
|
let moved = false;
|
|
@@ -4700,18 +4636,17 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
4700
4636
|
let containerToMove = this.instance.getMainLayer();
|
|
4701
4637
|
if (layerToMove) containerToMove = layerToMove;
|
|
4702
4638
|
if (containerToMove && !selectionContainsFrames) {
|
|
4703
|
-
moved = moveNodeToContainerNT(this.instance, node, containerToMove, originalNodes[node.getAttrs().id ?? ""], originalContainers[node.getAttrs().id ?? ""]);
|
|
4639
|
+
moved = moveNodeToContainerNT(this.instance, node, containerToMove, this.originalNodes[node.getAttrs().id ?? ""], this.originalContainers[node.getAttrs().id ?? ""]);
|
|
4704
4640
|
if (moved) this.instance.emitEvent("onNodeChangedContainer", {
|
|
4705
|
-
originalNode: originalNodes[node.getAttrs().id ?? ""] ?? null,
|
|
4706
|
-
originalContainer: originalContainers[node.getAttrs().id ?? ""] ?? null,
|
|
4641
|
+
originalNode: this.originalNodes[node.getAttrs().id ?? ""] ?? null,
|
|
4642
|
+
originalContainer: this.originalContainers[node.getAttrs().id ?? ""] ?? null,
|
|
4707
4643
|
newNode: node,
|
|
4708
4644
|
newContainer: containerToMove
|
|
4709
4645
|
});
|
|
4710
4646
|
toSelect.push(node.getAttrs().id ?? "");
|
|
4711
|
-
delete originalNodes[node.getAttrs().id ?? ""];
|
|
4712
|
-
delete originalContainers[node.getAttrs().id ?? ""];
|
|
4713
|
-
} else
|
|
4714
|
-
else toSelect.push(node.getAttrs().id ?? "");
|
|
4647
|
+
delete this.originalNodes[node.getAttrs().id ?? ""];
|
|
4648
|
+
delete this.originalContainers[node.getAttrs().id ?? ""];
|
|
4649
|
+
} else toSelect.push(node.getAttrs().nodeId ? node.getAttrs().nodeId ?? "" : node.getAttrs().id ?? "");
|
|
4715
4650
|
if (containerToMove) containerToMove.fire(WEAVE_NODE_CUSTOM_EVENTS.onTargetLeave, { bubbles: true });
|
|
4716
4651
|
if (!nodeHandler) return;
|
|
4717
4652
|
if (!moved) toUpdate.push(nodeHandler.serialize(node));
|
|
@@ -4723,14 +4658,14 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
4723
4658
|
toUpdate.push(nodeHandler.serialize(node));
|
|
4724
4659
|
}
|
|
4725
4660
|
};
|
|
4726
|
-
for (let i = 0; i <
|
|
4661
|
+
for (let i = 0; i < this.currentDragSelectedNodes.length; i++) nodeUpdate(this.currentDragSelectedNodes[i]);
|
|
4727
4662
|
if (toUpdate.length > 0) this.instance.updateNodesNT(toUpdate);
|
|
4728
4663
|
this.instance.runPhaseHooks("onMoveNodesToContainer", (hook) => {
|
|
4729
|
-
hook({ nodes:
|
|
4664
|
+
hook({ nodes: this.currentDragSelectedNodes });
|
|
4730
4665
|
});
|
|
4731
4666
|
stage.container().style.cursor = actualCursor;
|
|
4732
4667
|
});
|
|
4733
|
-
for (const node of
|
|
4668
|
+
for (const node of this.currentDragSelectedNodes) node.setAttrs({ isCloned: void 0 });
|
|
4734
4669
|
const finalSelectedNodes = [];
|
|
4735
4670
|
for (const nodeId of toSelect) {
|
|
4736
4671
|
const actNode = this.instance.getStage().findOne(`#${nodeId}`);
|
|
@@ -4740,17 +4675,19 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
4740
4675
|
actNode.handleSelectNode();
|
|
4741
4676
|
}
|
|
4742
4677
|
}
|
|
4743
|
-
this.setSelectedNodes(finalSelectedNodes);
|
|
4744
|
-
tr.forceUpdate();
|
|
4678
|
+
this.callbacks.setSelectedNodes(finalSelectedNodes);
|
|
4679
|
+
this.tr.forceUpdate();
|
|
4745
4680
|
}
|
|
4746
4681
|
});
|
|
4682
|
+
}
|
|
4683
|
+
registerInstanceEvents() {
|
|
4747
4684
|
this.instance.addEventListener("onNodesChange", () => {
|
|
4748
|
-
const currentSelectedNodes = tr.nodes();
|
|
4685
|
+
const currentSelectedNodes = this.tr.nodes();
|
|
4749
4686
|
const unselectedNodes = this.prevSelectedNodes.filter((node) => !currentSelectedNodes.map((node1) => node1.getAttrs().id).includes(node.getAttrs().id));
|
|
4750
4687
|
if (currentSelectedNodes.length > 1) for (const node of currentSelectedNodes) node.handleSelectNode();
|
|
4751
4688
|
if (currentSelectedNodes.length === 1) currentSelectedNodes[0]?.handleDeselectNode?.();
|
|
4752
4689
|
for (const node of unselectedNodes) node.handleDeselectNode();
|
|
4753
|
-
this.prevSelectedNodes = tr.nodes();
|
|
4690
|
+
this.prevSelectedNodes = this.tr.nodes();
|
|
4754
4691
|
});
|
|
4755
4692
|
this.instance.addEventListener("onUndoChange", () => {
|
|
4756
4693
|
this.handleUndoRedoSelectionChange();
|
|
@@ -4758,32 +4695,10 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
4758
4695
|
this.instance.addEventListener("onRedoChange", () => {
|
|
4759
4696
|
this.handleUndoRedoSelectionChange();
|
|
4760
4697
|
});
|
|
4761
|
-
this.tr = tr;
|
|
4762
|
-
this.trHover = trHover;
|
|
4763
|
-
this.selectionRectangle = selectionRectangle;
|
|
4764
|
-
this.initEvents();
|
|
4765
|
-
this.initialized = true;
|
|
4766
|
-
this.instance.addEventListener("onActiveActionChange", (activeAction) => {
|
|
4767
|
-
if (typeof activeAction !== "undefined" && activeAction !== SELECTION_TOOL_ACTION_NAME) {
|
|
4768
|
-
this.active = false;
|
|
4769
|
-
return;
|
|
4770
|
-
}
|
|
4771
|
-
this.active = true;
|
|
4772
|
-
});
|
|
4773
|
-
this.instance.addEventListener("onNodeRemoved", (node) => {
|
|
4774
|
-
const selectedNodes$1 = this.getSelectedNodes();
|
|
4775
|
-
const newSelectedNodes = selectedNodes$1.filter((actNode) => {
|
|
4776
|
-
return actNode.getAttrs().id !== node.id;
|
|
4777
|
-
});
|
|
4778
|
-
this.setSelectedNodes(newSelectedNodes);
|
|
4779
|
-
stage.container().tabIndex = 1;
|
|
4780
|
-
stage.container().focus();
|
|
4781
|
-
stage.container().style.cursor = "default";
|
|
4782
|
-
});
|
|
4783
4698
|
}
|
|
4784
4699
|
handleUndoRedoSelectionChange() {
|
|
4785
4700
|
const selectionLayer = this.instance.getSelectionLayer();
|
|
4786
|
-
const selectionFeedbackPlugin = this.getNodesSelectionFeedbackPlugin();
|
|
4701
|
+
const selectionFeedbackPlugin = this.callbacks.getNodesSelectionFeedbackPlugin();
|
|
4787
4702
|
if (selectionLayer && selectionFeedbackPlugin) {
|
|
4788
4703
|
selectionLayer.find(`.selection-halo`).forEach((node) => node.destroy());
|
|
4789
4704
|
selectionFeedbackPlugin.cleanupSelectedHalos();
|
|
@@ -4793,17 +4708,553 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
4793
4708
|
this.prevSelectedNodes = currentSelectedNodes;
|
|
4794
4709
|
}
|
|
4795
4710
|
}
|
|
4711
|
+
};
|
|
4712
|
+
|
|
4713
|
+
//#endregion
|
|
4714
|
+
//#region src/plugins/context-menu/constants.ts
|
|
4715
|
+
const WEAVE_CONTEXT_MENU_PLUGIN_KEY = "contextMenu";
|
|
4716
|
+
const WEAVE_CONTEXT_MENU_X_OFFSET_DEFAULT = 4;
|
|
4717
|
+
const WEAVE_CONTEXT_MENU_Y_OFFSET_DEFAULT = 4;
|
|
4718
|
+
const WEAVE_CONTEXT_MENU_TAP_HOLD_TIMEOUT = 500;
|
|
4719
|
+
|
|
4720
|
+
//#endregion
|
|
4721
|
+
//#region src/plugins/stage-grid/constants.ts
|
|
4722
|
+
const WEAVE_STAGE_GRID_PLUGIN_KEY = "stageGrid";
|
|
4723
|
+
const WEAVE_GRID_TYPES = {
|
|
4724
|
+
["LINES"]: "lines",
|
|
4725
|
+
["DOTS"]: "dots"
|
|
4726
|
+
};
|
|
4727
|
+
const WEAVE_GRID_DOT_TYPES = {
|
|
4728
|
+
["SQUARE"]: "square",
|
|
4729
|
+
["CIRCLE"]: "circle"
|
|
4730
|
+
};
|
|
4731
|
+
const WEAVE_GRID_DEFAULT_CONFIG = {
|
|
4732
|
+
type: WEAVE_GRID_TYPES.LINES,
|
|
4733
|
+
gridColor: "#b3b3b3",
|
|
4734
|
+
gridMajorColor: "#b3b3b3",
|
|
4735
|
+
gridOriginColor: "#ff746c",
|
|
4736
|
+
gridSize: 20,
|
|
4737
|
+
gridMajorEvery: 10,
|
|
4738
|
+
gridMajorRatio: 2,
|
|
4739
|
+
gridStroke: 1,
|
|
4740
|
+
gridDotType: WEAVE_GRID_DOT_TYPES.CIRCLE,
|
|
4741
|
+
gridDotRadius: 1,
|
|
4742
|
+
gridDotRectSize: 2
|
|
4743
|
+
};
|
|
4744
|
+
const WEAVE_GRID_LAYER_ID = "gridLayer";
|
|
4745
|
+
|
|
4746
|
+
//#endregion
|
|
4747
|
+
//#region src/plugins/stage-panning/constants.ts
|
|
4748
|
+
const WEAVE_STAGE_PANNING_KEY = "stagePanning";
|
|
4749
|
+
const WEAVE_STAGE_PANNING_THROTTLE_MS = 20;
|
|
4750
|
+
const WEAVE_STAGE_PANNING_DEFAULT_CONFIG = { edgePan: {
|
|
4751
|
+
offset: 25,
|
|
4752
|
+
speed: 20
|
|
4753
|
+
} };
|
|
4754
|
+
|
|
4755
|
+
//#endregion
|
|
4756
|
+
//#region src/plugins/nodes-multi-selection-feedback/constants.ts
|
|
4757
|
+
const WEAVE_NODES_MULTI_SELECTION_FEEDBACK_PLUGIN_KEY = "nodesMultiSelectionFeedback";
|
|
4758
|
+
const WEAVE_NODES_MULTI_SELECTION_FEEDBACK_PLUGIN_LAYER_ID = "selectionLayer";
|
|
4759
|
+
const WEAVE_NODES_MULTI_SELECTION_FEEDBACK_PLUGIN_DEFAULT_CONFIG = { style: {
|
|
4760
|
+
stroke: "#ff2c2cff",
|
|
4761
|
+
strokeWidth: 2,
|
|
4762
|
+
fill: "transparent"
|
|
4763
|
+
} };
|
|
4764
|
+
|
|
4765
|
+
//#endregion
|
|
4766
|
+
//#region src/plugins/users-presence/constants.ts
|
|
4767
|
+
const WEAVE_USER_PRESENCE_KEY = "userPresence";
|
|
4768
|
+
const WEAVE_USERS_PRESENCE_PLUGIN_KEY = "usersPresence";
|
|
4769
|
+
const WEAVE_USERS_PRESENCE_CONFIG_DEFAULT_PROPS = { awarenessThrottleMs: DEFAULT_THROTTLE_MS };
|
|
4770
|
+
|
|
4771
|
+
//#endregion
|
|
4772
|
+
//#region src/plugins/nodes-selection/plugin-accessors.ts
|
|
4773
|
+
function getContextMenuPlugin(instance) {
|
|
4774
|
+
return instance.getPlugin(WEAVE_CONTEXT_MENU_PLUGIN_KEY);
|
|
4775
|
+
}
|
|
4776
|
+
function getStageGridPlugin(instance) {
|
|
4777
|
+
return instance.getPlugin(WEAVE_STAGE_GRID_PLUGIN_KEY);
|
|
4778
|
+
}
|
|
4779
|
+
function getStagePanningPlugin(instance) {
|
|
4780
|
+
return instance.getPlugin(WEAVE_STAGE_PANNING_KEY);
|
|
4781
|
+
}
|
|
4782
|
+
function getNodesSelectionFeedbackPlugin(instance) {
|
|
4783
|
+
return instance.getPlugin(WEAVE_NODES_MULTI_SELECTION_FEEDBACK_PLUGIN_KEY);
|
|
4784
|
+
}
|
|
4785
|
+
function getUsersPresencePlugin(instance) {
|
|
4786
|
+
return instance.getPlugin(WEAVE_USERS_PRESENCE_PLUGIN_KEY);
|
|
4787
|
+
}
|
|
4788
|
+
|
|
4789
|
+
//#endregion
|
|
4790
|
+
//#region src/plugins/nodes-selection/events/click-tap.ts
|
|
4791
|
+
/**
|
|
4792
|
+
* Handles a single click or tap on the canvas: resolves the targeted node,
|
|
4793
|
+
* applies single/multi-selection logic, and triggers the selection-change
|
|
4794
|
+
* event. Called from both pointerdown (immediate click) and pointerup
|
|
4795
|
+
* (after area-selection ends with a tap).
|
|
4796
|
+
*/
|
|
4797
|
+
function handleClickOrTap(ctx, e) {
|
|
4798
|
+
const weave = ctx.getWeaveInstance();
|
|
4799
|
+
const stage = weave.getStage();
|
|
4800
|
+
const tr = ctx.getTransformerController().getTransformer();
|
|
4801
|
+
ctx.setClickOrTapHandled(true);
|
|
4802
|
+
e.cancelBubble = true;
|
|
4803
|
+
if (!ctx.isEnabled()) return;
|
|
4804
|
+
if (weave.getActiveAction() !== SELECTION_TOOL_ACTION_NAME) return;
|
|
4805
|
+
const contextMenuPlugin = ctx.getContextMenuPlugin();
|
|
4806
|
+
if (contextMenuPlugin?.isContextMenuVisible()) ctx.getEdgePanning().stop();
|
|
4807
|
+
ctx.hideHoverState();
|
|
4808
|
+
const selectedGroup = getTargetedNode(weave);
|
|
4809
|
+
if (!ctx.isInitialized()) return;
|
|
4810
|
+
if (e.evt.pointerType === "mouse" && e.evt?.button && e.evt?.button !== 0) return;
|
|
4811
|
+
let areNodesSelected = false;
|
|
4812
|
+
let nodeTargeted = selectedGroup && !(selectedGroup.getAttrs().active ?? false) ? selectedGroup : e.target;
|
|
4813
|
+
if (e.target === weave.getStage()) {
|
|
4814
|
+
ctx.getGesture().resetDoubleTap();
|
|
4815
|
+
ctx.getNodesSelectionFeedbackPlugin()?.cleanupSelectedHalos();
|
|
4816
|
+
return;
|
|
4817
|
+
}
|
|
4818
|
+
nodeTargeted = weave.getRealSelectedNode(nodeTargeted);
|
|
4819
|
+
if (!nodeTargeted.getAttrs().nodeType) {
|
|
4820
|
+
ctx.getGesture().resetDoubleTap();
|
|
4821
|
+
return;
|
|
4822
|
+
}
|
|
4823
|
+
const metaPressed = e.evt.shiftKey || e.evt.ctrlKey || e.evt.metaKey;
|
|
4824
|
+
const nodeSelectedIndex = tr.nodes().findIndex((node) => {
|
|
4825
|
+
return node.getAttrs().id === nodeTargeted.getAttrs().id;
|
|
4826
|
+
});
|
|
4827
|
+
const isSelected = nodeSelectedIndex !== -1;
|
|
4828
|
+
const user = weave.getStore().getUser();
|
|
4829
|
+
const isLocked = nodeTargeted.getAttrs().locked ?? false;
|
|
4830
|
+
const isMutexLocked = nodeTargeted.getAttrs().mutexLocked && nodeTargeted.getAttrs().mutexUserId !== user.id;
|
|
4831
|
+
if (isLocked || isMutexLocked) {
|
|
4832
|
+
const parent = weave.getInstanceRecursive(nodeTargeted.getParent());
|
|
4833
|
+
const mainLayer = weave.getMainLayer();
|
|
4834
|
+
const isStage = parent instanceof Konva.Stage;
|
|
4835
|
+
const isMainLayer = parent === mainLayer;
|
|
4836
|
+
const isContainerEmptyArea = e.target.getAttrs().isContainerPrincipal !== void 0 && !e.target.getAttrs().isContainerPrincipal;
|
|
4837
|
+
if (isStage || isMainLayer || isContainerEmptyArea) ctx.setSelectedNodes([]);
|
|
4838
|
+
return;
|
|
4839
|
+
}
|
|
4840
|
+
if (nodeTargeted.getAttrs().nodeId) {
|
|
4841
|
+
const realNode = stage.findOne(`#${nodeTargeted.getAttrs().nodeId}`);
|
|
4842
|
+
if (realNode) nodeTargeted = realNode;
|
|
4843
|
+
}
|
|
4844
|
+
if (typeof nodeTargeted.getAttrs().isContainerPrincipal !== "undefined" && !nodeTargeted.getAttrs().isContainerPrincipal) return;
|
|
4845
|
+
if (ctx.getGesture().isDoubleTap && !metaPressed) {
|
|
4846
|
+
ctx.getGesture().resetDoubleTap();
|
|
4847
|
+
nodeTargeted.dblClick();
|
|
4848
|
+
return;
|
|
4849
|
+
}
|
|
4850
|
+
const isCtrlOrCmdPressed = e.evt.ctrlKey || e.evt.metaKey;
|
|
4851
|
+
if (isCtrlOrCmdPressed) return;
|
|
4852
|
+
if (!metaPressed) {
|
|
4853
|
+
tr.nodes([nodeTargeted]);
|
|
4854
|
+
tr.show();
|
|
4855
|
+
areNodesSelected = true;
|
|
4856
|
+
}
|
|
4857
|
+
if (metaPressed && isSelected) {
|
|
4858
|
+
const nodes = tr.nodes().slice();
|
|
4859
|
+
nodes.splice(nodes.indexOf(nodeTargeted), 1);
|
|
4860
|
+
tr.nodes(nodes);
|
|
4861
|
+
areNodesSelected = true;
|
|
4862
|
+
}
|
|
4863
|
+
if (metaPressed && !isSelected) {
|
|
4864
|
+
tr.nodes(tr.nodes().concat([nodeTargeted]));
|
|
4865
|
+
areNodesSelected = true;
|
|
4866
|
+
}
|
|
4867
|
+
ctx.handleMultipleSelectionBehavior();
|
|
4868
|
+
ctx.handleBehaviors();
|
|
4869
|
+
if (areNodesSelected) {
|
|
4870
|
+
stage.container().tabIndex = 1;
|
|
4871
|
+
stage.container().focus();
|
|
4872
|
+
stage.container().style.cursor = (typeof nodeTargeted?.defineMousePointer === "function" ? nodeTargeted.defineMousePointer() : null) ?? "grab";
|
|
4873
|
+
}
|
|
4874
|
+
ctx.triggerSelectedNodesEvent();
|
|
4875
|
+
}
|
|
4876
|
+
|
|
4877
|
+
//#endregion
|
|
4878
|
+
//#region src/plugins/nodes-selection/events/keyboard.ts
|
|
4879
|
+
/**
|
|
4880
|
+
* Registers keydown/keyup listeners on the stage container.
|
|
4881
|
+
* Space key toggles the panning-override flag; Backspace/Delete removes
|
|
4882
|
+
* the currently selected nodes.
|
|
4883
|
+
*/
|
|
4884
|
+
function registerKeyboardHandlers(ctx) {
|
|
4885
|
+
const stage = ctx.getWeaveInstance().getStage();
|
|
4886
|
+
const signal = ctx.getWeaveInstance().getEventsController().signal;
|
|
4887
|
+
stage.container().addEventListener("keydown", (e) => {
|
|
4888
|
+
if (e.code === "Space") ctx.setSpaceKeyPressed(true);
|
|
4889
|
+
if (e.code === "Backspace" || e.code === "Delete") {
|
|
4890
|
+
Promise.resolve().then(() => {
|
|
4891
|
+
ctx.removeSelectedNodes();
|
|
4892
|
+
});
|
|
4893
|
+
return;
|
|
4894
|
+
}
|
|
4895
|
+
}, { signal });
|
|
4896
|
+
stage.container().addEventListener("keyup", (e) => {
|
|
4897
|
+
if (e.code === "Space") ctx.setSpaceKeyPressed(false);
|
|
4898
|
+
}, { signal });
|
|
4899
|
+
}
|
|
4900
|
+
|
|
4901
|
+
//#endregion
|
|
4902
|
+
//#region src/plugins/nodes-selection/events/pointer-down.ts
|
|
4903
|
+
/**
|
|
4904
|
+
* Handles the stage `pointerdown` event: records pointer state, decides
|
|
4905
|
+
* whether to start an area-selection or delegate to a click/tap handler.
|
|
4906
|
+
*/
|
|
4907
|
+
function handlePointerDown(ctx, e) {
|
|
4908
|
+
ctx.getGesture().setTapStart(e.evt.clientX, e.evt.clientY);
|
|
4909
|
+
if (e.target.getClassName().includes("custom-snap-guide")) return;
|
|
4910
|
+
ctx.setClickOrTapHandled(false);
|
|
4911
|
+
ctx.registerPointer(e.evt.pointerId, e.evt);
|
|
4912
|
+
if (e.evt.pointerType === "touch" && ctx.getPointerCount() > 1) return;
|
|
4913
|
+
if (e.evt.pointerType === "mouse" && e.evt?.button !== 0) return;
|
|
4914
|
+
if (e.evt.pointerType === "pen" && e.evt?.pressure <= .05) return;
|
|
4915
|
+
if (!ctx.isInitialized()) return;
|
|
4916
|
+
if (!ctx.isActive()) return;
|
|
4917
|
+
const stage = ctx.getWeaveInstance().getStage();
|
|
4918
|
+
if (stage.mode() !== WEAVE_STAGE_DEFAULT_MODE) return;
|
|
4919
|
+
const selectedGroup = getTargetedNode(ctx.getWeaveInstance());
|
|
4920
|
+
if (selectedGroup?.getParent() instanceof Konva.Transformer) {
|
|
4921
|
+
ctx.setAreaSelecting(false);
|
|
4922
|
+
ctx.getEdgePanning().stop();
|
|
4923
|
+
ctx.getAreaSelector().hide();
|
|
4924
|
+
return;
|
|
4925
|
+
}
|
|
4926
|
+
const isStage = e.target instanceof Konva.Stage;
|
|
4927
|
+
const isTransformer = e.target?.getParent() instanceof Konva.Transformer;
|
|
4928
|
+
const canBeTargeted = e.target.getAttrs().canBeTargeted !== false;
|
|
4929
|
+
const isContainerEmptyArea = e.target.getAttrs().isContainerPrincipal !== void 0 && !e.target.getAttrs().isContainerPrincipal;
|
|
4930
|
+
if (isTransformer) return;
|
|
4931
|
+
if (!isStage && !isContainerEmptyArea && canBeTargeted) {
|
|
4932
|
+
ctx.setAreaSelecting(false);
|
|
4933
|
+
ctx.getEdgePanning().stop();
|
|
4934
|
+
ctx.getAreaSelector().hide();
|
|
4935
|
+
handleClickOrTap(ctx, e);
|
|
4936
|
+
return;
|
|
4937
|
+
}
|
|
4938
|
+
ctx.getEdgePanning().reset();
|
|
4939
|
+
const relPos = stage.getRelativePointerPosition() ?? {
|
|
4940
|
+
x: 0,
|
|
4941
|
+
y: 0
|
|
4942
|
+
};
|
|
4943
|
+
ctx.getAreaSelector().setStart(relPos.x, relPos.y);
|
|
4944
|
+
ctx.getAreaSelector().resetForScale(stage.scaleX(), ctx.getConfiguration().selectionArea);
|
|
4945
|
+
ctx.setAreaSelecting(true);
|
|
4946
|
+
const isCtrlOrMetaPressed = e.evt.ctrlKey || e.evt.metaKey;
|
|
4947
|
+
if (isCtrlOrMetaPressed) {
|
|
4948
|
+
const tr = ctx.getTransformerController().getTransformer();
|
|
4949
|
+
const nodesSelected = tr.nodes();
|
|
4950
|
+
for (const node of nodesSelected) node.fire("onSelectionCleared", { bubbles: true });
|
|
4951
|
+
}
|
|
4952
|
+
ctx.selectNone();
|
|
4953
|
+
ctx.getWeaveInstance().emitEvent("onSelectionState", true);
|
|
4954
|
+
ctx.getEdgePanning().start();
|
|
4955
|
+
}
|
|
4956
|
+
|
|
4957
|
+
//#endregion
|
|
4958
|
+
//#region src/plugins/nodes-selection/events/pointer-move.ts
|
|
4959
|
+
/**
|
|
4960
|
+
* Handles the stage `pointermove` event: cancels long-press timers when
|
|
4961
|
+
* the pointer moves, hides the selection rect when no movement, and
|
|
4962
|
+
* updates the area-selection rectangle and edge-panning direction while
|
|
4963
|
+
* a selection drag is in progress.
|
|
4964
|
+
*/
|
|
4965
|
+
function handlePointerMove(ctx, e) {
|
|
4966
|
+
if (!e?.evt) return;
|
|
4967
|
+
const moved = ctx.getGesture().checkMoved(e.evt.clientX, e.evt.clientY);
|
|
4968
|
+
if (e.evt?.buttons === 0) return;
|
|
4969
|
+
if (e.evt.pointerType === "touch" && ctx.getPointerCount() > 1) return;
|
|
4970
|
+
if (!ctx.isInitialized()) return;
|
|
4971
|
+
if (!ctx.isActive()) return;
|
|
4972
|
+
const contextMenuPlugin = ctx.getContextMenuPlugin();
|
|
4973
|
+
if (moved) contextMenuPlugin?.cancelLongPressTimer();
|
|
4974
|
+
else ctx.getAreaSelector().hide();
|
|
4975
|
+
if (contextMenuPlugin?.isContextMenuVisible()) ctx.getEdgePanning().stop();
|
|
4976
|
+
if (ctx.getSpaceKeyPressedState()) return;
|
|
4977
|
+
if (!ctx.isAreaSelecting()) return;
|
|
4978
|
+
ctx.getAreaSelector().update(ctx.getWeaveInstance().getStage(), () => ctx.selectNone());
|
|
4979
|
+
ctx.getEdgePanning().updateDirection();
|
|
4980
|
+
}
|
|
4981
|
+
|
|
4982
|
+
//#endregion
|
|
4983
|
+
//#region src/plugins/nodes-selection/events/pointer-up.ts
|
|
4984
|
+
/**
|
|
4985
|
+
* Handles the stage `pointerup` event: ends any in-progress area-selection
|
|
4986
|
+
* (including the node-filtering/commit step), or delegates to the click/tap
|
|
4987
|
+
* handler for point interactions.
|
|
4988
|
+
*/
|
|
4989
|
+
function handlePointerUp(ctx, e) {
|
|
4990
|
+
const weave = ctx.getWeaveInstance();
|
|
4991
|
+
const stage = weave.getStage();
|
|
4992
|
+
const store = weave.getStore();
|
|
4993
|
+
const actUser = store.getUser();
|
|
4994
|
+
const tr = ctx.getTransformerController().getTransformer();
|
|
4995
|
+
tr.setAttrs({ listening: true });
|
|
4996
|
+
ctx.setAreaSelecting(false);
|
|
4997
|
+
ctx.getEdgePanning().stop();
|
|
4998
|
+
const moved = ctx.getGesture().checkMoved(e.evt.clientX, e.evt.clientY);
|
|
4999
|
+
ctx.getGesture().checkDoubleTap(e.evt.clientX, e.evt.clientY);
|
|
5000
|
+
ctx.unregisterPointer(e.evt.pointerId);
|
|
5001
|
+
ctx.getGesture().commitTap();
|
|
5002
|
+
if (stage.mode() !== WEAVE_STAGE_DEFAULT_MODE) return;
|
|
5003
|
+
const contextMenuPlugin = ctx.getContextMenuPlugin();
|
|
5004
|
+
if (!ctx.isInitialized()) {
|
|
5005
|
+
ctx.getAreaSelector().hide();
|
|
5006
|
+
return;
|
|
5007
|
+
}
|
|
5008
|
+
if (!ctx.isActive()) {
|
|
5009
|
+
ctx.getAreaSelector().hide();
|
|
5010
|
+
return;
|
|
5011
|
+
}
|
|
5012
|
+
weave.emitEvent("onSelectionState", false);
|
|
5013
|
+
if (ctx.getGesture().isDoubleTap) {
|
|
5014
|
+
ctx.getAreaSelector().hide();
|
|
5015
|
+
handleClickOrTap(ctx, e);
|
|
5016
|
+
return;
|
|
5017
|
+
}
|
|
5018
|
+
const isStage = e.target instanceof Konva.Stage;
|
|
5019
|
+
const isContainerEmptyArea = e.target.getAttrs().isContainerPrincipal !== void 0 && !e.target.getAttrs().isContainerPrincipal;
|
|
5020
|
+
if ((isStage || isContainerEmptyArea) && !moved) {
|
|
5021
|
+
ctx.setAreaSelecting(false);
|
|
5022
|
+
ctx.getEdgePanning().stop();
|
|
5023
|
+
ctx.getAreaSelector().hide();
|
|
5024
|
+
ctx.setSelectedNodes([]);
|
|
5025
|
+
return;
|
|
5026
|
+
}
|
|
5027
|
+
if (e.evt.pointerType === "touch" && ctx.getPointerCount() + 1 > 1) {
|
|
5028
|
+
ctx.getAreaSelector().hide();
|
|
5029
|
+
return;
|
|
5030
|
+
}
|
|
5031
|
+
if (contextMenuPlugin?.isContextMenuVisible()) ctx.getEdgePanning().stop();
|
|
5032
|
+
const selectedGroup = getTargetedNode(weave);
|
|
5033
|
+
if (!moved && selectedGroup?.getParent() instanceof Konva.Transformer && !ctx.wasClickOrTapHandled()) {
|
|
5034
|
+
ctx.setAreaSelecting(false);
|
|
5035
|
+
ctx.getEdgePanning().stop();
|
|
5036
|
+
ctx.getAreaSelector().hide();
|
|
5037
|
+
handleClickOrTap(ctx, e);
|
|
5038
|
+
return;
|
|
5039
|
+
}
|
|
5040
|
+
if (!ctx.getAreaSelector().getRect().visible()) {
|
|
5041
|
+
ctx.getAreaSelector().hide();
|
|
5042
|
+
return;
|
|
5043
|
+
}
|
|
5044
|
+
const shapes = stage.find((node) => {
|
|
5045
|
+
return ["Shape", "Group"].includes(node.getType()) && typeof node.getAttrs().id !== "undefined";
|
|
5046
|
+
});
|
|
5047
|
+
const box = ctx.getAreaSelector().getBox();
|
|
5048
|
+
ctx.getAreaSelector().getRect().visible(false);
|
|
5049
|
+
const selected = shapes.filter((shape) => {
|
|
5050
|
+
const shapeMutex = weave.getNodeMutexLock(shape.id());
|
|
5051
|
+
if (shapeMutex && shapeMutex.user.id !== actUser.id) return false;
|
|
5052
|
+
let parent = weave.getInstanceRecursive(shape.getParent());
|
|
5053
|
+
if (parent.getAttrs().nodeId) parent = stage.findOne(`#${parent.getAttrs().nodeId}`);
|
|
5054
|
+
if (shape.getAttrs().nodeType && shape.getAttrs().nodeType === "frame") {
|
|
5055
|
+
const frameBox = shape.getClientRect();
|
|
5056
|
+
return frameBox.x >= box.x && frameBox.y >= box.y && frameBox.x + frameBox.width <= box.x + box.width && frameBox.y + frameBox.height <= box.y + box.height;
|
|
5057
|
+
}
|
|
5058
|
+
if (shape.getAttrs().nodeType && shape?.getAttrs().nodeType === "group" && ["layer", "frame"].includes(parent?.getAttrs().nodeType)) return shape.getAttrs().nodeType && Konva.Util.haveIntersection(box, shape.getClientRect());
|
|
5059
|
+
if (shape.getAttrs().nodeType && shape.getAttrs().nodeType !== "group" && ["layer", "frame"].includes(parent?.getAttrs().nodeType)) return shape.getAttrs().nodeType && Konva.Util.haveIntersection(box, shape.getClientRect());
|
|
5060
|
+
return false;
|
|
5061
|
+
});
|
|
5062
|
+
const selectedNodes = new Set();
|
|
5063
|
+
const containerNodesIds = [];
|
|
5064
|
+
const otherNodes = [];
|
|
5065
|
+
for (const node of selected) {
|
|
5066
|
+
let realNode = node;
|
|
5067
|
+
if (node.getAttrs().nodeId) realNode = stage.findOne(`#${node.getAttrs().nodeId}`);
|
|
5068
|
+
if (!realNode) continue;
|
|
5069
|
+
const isContainer = typeof realNode.getAttrs().isContainerPrincipal !== "undefined" && realNode.getAttrs().isContainerPrincipal;
|
|
5070
|
+
if (isContainer) {
|
|
5071
|
+
containerNodesIds.push(realNode.getAttrs().id ?? "");
|
|
5072
|
+
if (!realNode.getAttrs().locked) selectedNodes.add(realNode);
|
|
5073
|
+
} else otherNodes.push(realNode);
|
|
5074
|
+
}
|
|
5075
|
+
for (const node of otherNodes) {
|
|
5076
|
+
let parent = weave.getInstanceRecursive(node.getParent());
|
|
5077
|
+
if (parent?.getAttrs().nodeId) parent = stage.findOne(`#${parent.getAttrs().nodeId}`);
|
|
5078
|
+
if (parent && !containerNodesIds.includes(parent?.getAttrs().id ?? "") && !node.getAttrs().locked) selectedNodes.add(node);
|
|
5079
|
+
}
|
|
5080
|
+
ctx.setAreaSelecting(false);
|
|
5081
|
+
ctx.getEdgePanning().stop();
|
|
5082
|
+
tr.nodes([...selectedNodes]);
|
|
5083
|
+
ctx.handleMultipleSelectionBehavior();
|
|
5084
|
+
ctx.handleBehaviors();
|
|
5085
|
+
if (tr.nodes().length > 0) {
|
|
5086
|
+
stage.container().tabIndex = 1;
|
|
5087
|
+
stage.container().focus();
|
|
5088
|
+
}
|
|
5089
|
+
ctx.triggerSelectedNodesEvent();
|
|
5090
|
+
}
|
|
5091
|
+
|
|
5092
|
+
//#endregion
|
|
5093
|
+
//#region src/plugins/nodes-selection/nodes-selection.ts
|
|
5094
|
+
var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
5095
|
+
gesture = new GestureDetector();
|
|
5096
|
+
_handledClickOrTap = false;
|
|
5097
|
+
dragSelectedNodes = [];
|
|
5098
|
+
constructor(params) {
|
|
5099
|
+
super();
|
|
5100
|
+
this.config = mergeExceptArrays(WEAVE_NODES_SELECTION_DEFAULT_CONFIG, params?.config ?? {});
|
|
5101
|
+
this.initialize();
|
|
5102
|
+
}
|
|
5103
|
+
initialize() {
|
|
5104
|
+
this._defaultEnabledAnchors = this.config.selection?.enabledAnchors ?? [
|
|
5105
|
+
"top-left",
|
|
5106
|
+
"top-center",
|
|
5107
|
+
"top-right",
|
|
5108
|
+
"middle-right",
|
|
5109
|
+
"middle-left",
|
|
5110
|
+
"bottom-left",
|
|
5111
|
+
"bottom-center",
|
|
5112
|
+
"bottom-right"
|
|
5113
|
+
];
|
|
5114
|
+
this.gesture.reset();
|
|
5115
|
+
this._isSpaceKeyPressed = false;
|
|
5116
|
+
this.active = false;
|
|
5117
|
+
this.selecting = false;
|
|
5118
|
+
this.initialized = false;
|
|
5119
|
+
this.enabled = false;
|
|
5120
|
+
this.pointers = {};
|
|
5121
|
+
this.dragSelectedNodes = [];
|
|
5122
|
+
}
|
|
5123
|
+
getName() {
|
|
5124
|
+
return WEAVE_NODES_SELECTION_KEY;
|
|
5125
|
+
}
|
|
5126
|
+
getLayerName() {
|
|
5127
|
+
return WEAVE_NODES_SELECTION_LAYER_ID;
|
|
5128
|
+
}
|
|
5129
|
+
getConfiguration() {
|
|
5130
|
+
return this.config;
|
|
5131
|
+
}
|
|
5132
|
+
getWeaveInstance() {
|
|
5133
|
+
return this.instance;
|
|
5134
|
+
}
|
|
5135
|
+
getGesture() {
|
|
5136
|
+
return this.gesture;
|
|
5137
|
+
}
|
|
5138
|
+
getAreaSelector() {
|
|
5139
|
+
return this.areaSelector;
|
|
5140
|
+
}
|
|
5141
|
+
getEdgePanning() {
|
|
5142
|
+
return this.edgePanning;
|
|
5143
|
+
}
|
|
5144
|
+
getTransformerController() {
|
|
5145
|
+
return this.transformerCtrl;
|
|
5146
|
+
}
|
|
5147
|
+
getDefaultEnabledAnchors() {
|
|
5148
|
+
return this._defaultEnabledAnchors;
|
|
5149
|
+
}
|
|
5150
|
+
isInitialized() {
|
|
5151
|
+
return this.initialized;
|
|
5152
|
+
}
|
|
5153
|
+
isActive() {
|
|
5154
|
+
return this.active;
|
|
5155
|
+
}
|
|
5156
|
+
getSpaceKeyPressedState() {
|
|
5157
|
+
return this._isSpaceKeyPressed;
|
|
5158
|
+
}
|
|
5159
|
+
setSpaceKeyPressed(val) {
|
|
5160
|
+
this._isSpaceKeyPressed = val;
|
|
5161
|
+
}
|
|
5162
|
+
getPointerCount() {
|
|
5163
|
+
return Object.keys(this.pointers).length;
|
|
5164
|
+
}
|
|
5165
|
+
registerPointer(id, evt) {
|
|
5166
|
+
this.pointers[id] = evt;
|
|
5167
|
+
}
|
|
5168
|
+
unregisterPointer(id) {
|
|
5169
|
+
delete this.pointers[id];
|
|
5170
|
+
}
|
|
5171
|
+
wasClickOrTapHandled() {
|
|
5172
|
+
return this._handledClickOrTap;
|
|
5173
|
+
}
|
|
5174
|
+
setClickOrTapHandled(val) {
|
|
5175
|
+
this._handledClickOrTap = val;
|
|
5176
|
+
}
|
|
5177
|
+
setAreaSelecting(val) {
|
|
5178
|
+
this.selecting = val;
|
|
5179
|
+
}
|
|
5180
|
+
initLayer() {
|
|
5181
|
+
const stage = this.instance.getStage();
|
|
5182
|
+
const layer = new Konva.Layer({ id: this.getLayerName() });
|
|
5183
|
+
stage.add(layer);
|
|
5184
|
+
}
|
|
5185
|
+
isPasting() {
|
|
5186
|
+
const copyPastePlugin = this.instance.getPlugin("copyPasteNodes");
|
|
5187
|
+
if (!copyPastePlugin) return false;
|
|
5188
|
+
return copyPastePlugin.isPasting();
|
|
5189
|
+
}
|
|
5190
|
+
isAreaSelecting() {
|
|
5191
|
+
return this.selecting;
|
|
5192
|
+
}
|
|
5193
|
+
isSelecting() {
|
|
5194
|
+
return this.instance.getActiveAction() === SELECTION_TOOL_ACTION_NAME;
|
|
5195
|
+
}
|
|
5196
|
+
isNodeSelected(ele) {
|
|
5197
|
+
return this.getSelectedNodes().length === 1 && this.getSelectedNodes()[0].getAttrs().id === ele.getAttrs().id;
|
|
5198
|
+
}
|
|
5199
|
+
onInit() {
|
|
5200
|
+
const stage = this.instance.getStage();
|
|
5201
|
+
const selectionLayer = this.getLayer();
|
|
5202
|
+
stage.container().tabIndex = 1;
|
|
5203
|
+
stage.container().focus();
|
|
5204
|
+
this.areaSelector = new AreaSelector();
|
|
5205
|
+
this.areaSelector.init(selectionLayer, this.config.selectionArea, stage.scaleX());
|
|
5206
|
+
this.edgePanning = new EdgePanning(this.config.panningWhenSelection, {
|
|
5207
|
+
getStage: () => this.instance.getStage(),
|
|
5208
|
+
isSelecting: () => this.isAreaSelecting(),
|
|
5209
|
+
onTick: (dx, dy) => {
|
|
5210
|
+
if (this.areaSelector.selectionStart) {
|
|
5211
|
+
this.areaSelector.selectionStart.x += dx;
|
|
5212
|
+
this.areaSelector.selectionStart.y += dy;
|
|
5213
|
+
}
|
|
5214
|
+
this.getStageGridPlugin()?.onRender();
|
|
5215
|
+
this.areaSelector.update(this.instance.getStage(), () => this.selectNone());
|
|
5216
|
+
}
|
|
5217
|
+
});
|
|
5218
|
+
const callbacks = {
|
|
5219
|
+
isSelecting: () => this.isSelecting(),
|
|
5220
|
+
setSelectedNodes: (nodes) => this.setSelectedNodes(nodes),
|
|
5221
|
+
triggerSelectedNodesEvent: () => this.triggerSelectedNodesEvent(),
|
|
5222
|
+
saveDragSelectedNodes: () => this.saveDragSelectedNodes(),
|
|
5223
|
+
setNodesOpacityOnDrag: () => this.setNodesOpacityOnDrag(),
|
|
5224
|
+
disablePlugin: () => this.disable(),
|
|
5225
|
+
enablePlugin: () => this.enable(),
|
|
5226
|
+
getContextMenuPlugin: () => this.getContextMenuPlugin(),
|
|
5227
|
+
getUsersPresencePlugin: () => this.getUsersPresencePlugin(),
|
|
5228
|
+
getStagePanningPlugin: () => this.getStagePanningPlugin(),
|
|
5229
|
+
getNodesSelectionFeedbackPlugin: () => this.getNodesSelectionFeedbackPlugin()
|
|
5230
|
+
};
|
|
5231
|
+
this.transformerCtrl = new TransformerController(this.instance, this.config, this.gesture, callbacks);
|
|
5232
|
+
this.transformerCtrl.setup(selectionLayer);
|
|
5233
|
+
this.initEvents();
|
|
5234
|
+
this.initialized = true;
|
|
5235
|
+
this.instance.addEventListener("onActiveActionChange", (activeAction) => {
|
|
5236
|
+
if (typeof activeAction !== "undefined" && activeAction !== SELECTION_TOOL_ACTION_NAME) {
|
|
5237
|
+
this.active = false;
|
|
5238
|
+
return;
|
|
5239
|
+
}
|
|
5240
|
+
this.active = true;
|
|
5241
|
+
});
|
|
5242
|
+
this.instance.addEventListener("onNodeRemoved", (node) => {
|
|
5243
|
+
const selectedNodes = this.getSelectedNodes();
|
|
5244
|
+
const newSelectedNodes = selectedNodes.filter((actNode) => actNode.getAttrs().id !== node.id);
|
|
5245
|
+
this.setSelectedNodes(newSelectedNodes);
|
|
5246
|
+
stage.container().tabIndex = 1;
|
|
5247
|
+
stage.container().focus();
|
|
5248
|
+
stage.container().style.cursor = "default";
|
|
5249
|
+
});
|
|
5250
|
+
}
|
|
4796
5251
|
getLayer() {
|
|
4797
5252
|
const stage = this.instance.getStage();
|
|
4798
5253
|
return stage.findOne(`#${this.getLayerName()}`);
|
|
4799
5254
|
}
|
|
4800
5255
|
triggerSelectedNodesEvent() {
|
|
4801
|
-
this.
|
|
4802
|
-
|
|
4803
|
-
this.triggerOnNodesChangeEvent();
|
|
4804
|
-
}
|
|
4805
|
-
serializeSelectedNodes() {
|
|
4806
|
-
const selectedNodes = this.tr.getNodes().map((node) => {
|
|
5256
|
+
const tr = this.transformerCtrl.getTransformer();
|
|
5257
|
+
const selectedNodes = tr.getNodes().map((node) => {
|
|
4807
5258
|
const nodeType = node.getAttr("nodeType");
|
|
4808
5259
|
const nodeHandler = this.instance.getNodeHandler(nodeType);
|
|
4809
5260
|
return {
|
|
@@ -4811,17 +5262,12 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
4811
5262
|
node: nodeHandler?.serialize(node)
|
|
4812
5263
|
};
|
|
4813
5264
|
});
|
|
4814
|
-
this.serializedSelectedNodes = selectedNodes;
|
|
4815
|
-
}
|
|
4816
|
-
triggerSelectionAwarenessEvent() {
|
|
4817
5265
|
const usersSelectionPlugin = this.instance.getPlugin(WEAVE_USERS_SELECTION_KEY);
|
|
4818
5266
|
if (usersSelectionPlugin) requestAnimationFrame(() => {
|
|
4819
|
-
usersSelectionPlugin.sendSelectionAwarenessInfo(
|
|
5267
|
+
usersSelectionPlugin.sendSelectionAwarenessInfo(tr);
|
|
4820
5268
|
});
|
|
4821
|
-
}
|
|
4822
|
-
triggerOnNodesChangeEvent() {
|
|
4823
5269
|
requestAnimationFrame(() => {
|
|
4824
|
-
this.instance.emitEvent("onNodesChange",
|
|
5270
|
+
this.instance.emitEvent("onNodesChange", selectedNodes);
|
|
4825
5271
|
});
|
|
4826
5272
|
}
|
|
4827
5273
|
removeElement(element) {
|
|
@@ -4841,334 +5287,13 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
4841
5287
|
this.selectNone();
|
|
4842
5288
|
this.triggerSelectedNodesEvent();
|
|
4843
5289
|
}
|
|
4844
|
-
updateSelectionRect() {
|
|
4845
|
-
const stage = this.instance.getStage();
|
|
4846
|
-
this.x2 = stage.getRelativePointerPosition()?.x ?? 0;
|
|
4847
|
-
this.y2 = stage.getRelativePointerPosition()?.y ?? 0;
|
|
4848
|
-
this.selectNone();
|
|
4849
|
-
this.selectionRectangle.setAttrs({
|
|
4850
|
-
visible: true,
|
|
4851
|
-
x: Math.min(this.x1, this.x2),
|
|
4852
|
-
y: Math.min(this.y1, this.y2),
|
|
4853
|
-
width: Math.abs(this.x2 - this.x1),
|
|
4854
|
-
height: Math.abs(this.y2 - this.y1)
|
|
4855
|
-
});
|
|
4856
|
-
}
|
|
4857
|
-
getSpeedFromEdge(distanceFromEdge) {
|
|
4858
|
-
const stage = this.instance.getStage();
|
|
4859
|
-
const scaledDistance = distanceFromEdge / stage.scaleX();
|
|
4860
|
-
if (scaledDistance < this.config.panningWhenSelection.edgeThreshold) {
|
|
4861
|
-
const factor = 1 - scaledDistance / this.config.panningWhenSelection.edgeThreshold;
|
|
4862
|
-
return this.config.panningWhenSelection.minScrollSpeed + (this.config.panningWhenSelection.maxScrollSpeed - this.config.panningWhenSelection.minScrollSpeed) * factor;
|
|
4863
|
-
}
|
|
4864
|
-
return 0;
|
|
4865
|
-
}
|
|
4866
|
-
updatePanDirection() {
|
|
4867
|
-
const stage = this.instance.getStage();
|
|
4868
|
-
const pos = stage.getPointerPosition();
|
|
4869
|
-
const viewWidth = stage.width();
|
|
4870
|
-
const viewHeight = stage.height();
|
|
4871
|
-
if (!pos) return;
|
|
4872
|
-
const distLeft = pos.x;
|
|
4873
|
-
const distRight = viewWidth - pos.x;
|
|
4874
|
-
const distTop = pos.y;
|
|
4875
|
-
const distBottom = viewHeight - pos.y;
|
|
4876
|
-
this.panDirection.x = 0;
|
|
4877
|
-
this.panDirection.y = 0;
|
|
4878
|
-
this.panSpeed = {
|
|
4879
|
-
x: 0,
|
|
4880
|
-
y: 0
|
|
4881
|
-
};
|
|
4882
|
-
if (distLeft < this.config.panningWhenSelection.edgeThreshold) {
|
|
4883
|
-
this.panDirection.x = 1;
|
|
4884
|
-
this.panSpeed.x = this.getSpeedFromEdge(distLeft);
|
|
4885
|
-
} else if (distRight < this.config.panningWhenSelection.edgeThreshold) {
|
|
4886
|
-
this.panDirection.x = -1;
|
|
4887
|
-
this.panSpeed.x = this.getSpeedFromEdge(distRight);
|
|
4888
|
-
}
|
|
4889
|
-
if (distTop < this.config.panningWhenSelection.edgeThreshold) {
|
|
4890
|
-
this.panDirection.y = 1;
|
|
4891
|
-
this.panSpeed.y = this.getSpeedFromEdge(distTop);
|
|
4892
|
-
} else if (distBottom < this.config.panningWhenSelection.edgeThreshold) {
|
|
4893
|
-
this.panDirection.y = -1;
|
|
4894
|
-
this.panSpeed.y = this.getSpeedFromEdge(distBottom);
|
|
4895
|
-
}
|
|
4896
|
-
}
|
|
4897
|
-
stopPanLoop() {
|
|
4898
|
-
if (this.panLoopId) {
|
|
4899
|
-
cancelAnimationFrame(this.panLoopId);
|
|
4900
|
-
this.panLoopId = null;
|
|
4901
|
-
}
|
|
4902
|
-
}
|
|
4903
|
-
panLoop() {
|
|
4904
|
-
const stage = this.instance.getStage();
|
|
4905
|
-
if (this.isAreaSelecting() && (this.panDirection.x !== 0 || this.panDirection.y !== 0)) {
|
|
4906
|
-
const scale = stage.scaleX();
|
|
4907
|
-
const stepX = (this.panSpeed.x || 0) / scale;
|
|
4908
|
-
const stepY = (this.panSpeed.y || 0) / scale;
|
|
4909
|
-
stage.x(stage.x() + this.panDirection.x * stepX);
|
|
4910
|
-
stage.y(stage.y() + this.panDirection.y * stepY);
|
|
4911
|
-
if (this.selectionStart) {
|
|
4912
|
-
this.selectionStart.x += this.panDirection.x * stepX;
|
|
4913
|
-
this.selectionStart.y += this.panDirection.y * stepY;
|
|
4914
|
-
}
|
|
4915
|
-
this.getStageGridPlugin()?.onRender();
|
|
4916
|
-
this.updateSelectionRect();
|
|
4917
|
-
}
|
|
4918
|
-
if (this.isAreaSelecting()) this.panLoopId = requestAnimationFrame(() => this.panLoop());
|
|
4919
|
-
}
|
|
4920
|
-
setTapStart(e) {
|
|
4921
|
-
this.taps = this.taps + 1;
|
|
4922
|
-
this.tapStart = {
|
|
4923
|
-
x: e.evt.clientX,
|
|
4924
|
-
y: e.evt.clientY,
|
|
4925
|
-
time: performance.now()
|
|
4926
|
-
};
|
|
4927
|
-
}
|
|
4928
|
-
checkMovedDrag(init, actual) {
|
|
4929
|
-
if (!this.tapStart) return false;
|
|
4930
|
-
const dx = actual.x - init.x;
|
|
4931
|
-
const dy = actual.y - init.y;
|
|
4932
|
-
const dist = Math.hypot(dx, dy);
|
|
4933
|
-
const MOVED_DISTANCE = 5;
|
|
4934
|
-
if (dist <= MOVED_DISTANCE) return false;
|
|
4935
|
-
return true;
|
|
4936
|
-
}
|
|
4937
|
-
checkMoved(e) {
|
|
4938
|
-
if (!this.tapStart) return false;
|
|
4939
|
-
const dx = e.evt.clientX - this.tapStart.x;
|
|
4940
|
-
const dy = e.evt.clientY - this.tapStart.y;
|
|
4941
|
-
const dist = Math.hypot(dx, dy);
|
|
4942
|
-
const MOVED_DISTANCE = 5;
|
|
4943
|
-
if (dist <= MOVED_DISTANCE) return false;
|
|
4944
|
-
return true;
|
|
4945
|
-
}
|
|
4946
|
-
checkDoubleTap(e) {
|
|
4947
|
-
if (!this.previousTap) return;
|
|
4948
|
-
const now$2 = performance.now();
|
|
4949
|
-
const dx = e.evt.clientX - this.previousTap.x;
|
|
4950
|
-
const dy = e.evt.clientY - this.previousTap.y;
|
|
4951
|
-
const dist = Math.hypot(dx, dy);
|
|
4952
|
-
const DOUBLE_TAP_DISTANCE = 10;
|
|
4953
|
-
const DOUBLE_TAP_TIME = 300;
|
|
4954
|
-
if (this.tapTimeoutId) clearTimeout(this.tapTimeoutId);
|
|
4955
|
-
this.tapTimeoutId = setTimeout(() => {
|
|
4956
|
-
this.taps = 0;
|
|
4957
|
-
}, DOUBLE_TAP_TIME + 5);
|
|
4958
|
-
if (this.taps > 1 && now$2 - this.previousTap.time < DOUBLE_TAP_TIME && dist < DOUBLE_TAP_DISTANCE) {
|
|
4959
|
-
this.taps = 0;
|
|
4960
|
-
this.tapStart = null;
|
|
4961
|
-
this.isDoubleTap = true;
|
|
4962
|
-
}
|
|
4963
|
-
}
|
|
4964
|
-
hideSelectorArea() {
|
|
4965
|
-
this.selectionRectangle.setAttrs({
|
|
4966
|
-
width: 0,
|
|
4967
|
-
height: 0,
|
|
4968
|
-
visible: false
|
|
4969
|
-
});
|
|
4970
|
-
}
|
|
4971
5290
|
initEvents() {
|
|
4972
5291
|
this.selecting = false;
|
|
4973
5292
|
const stage = this.instance.getStage();
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
this.removeSelectedNodes();
|
|
4979
|
-
});
|
|
4980
|
-
return;
|
|
4981
|
-
}
|
|
4982
|
-
}, { signal: this.instance.getEventsController()?.signal });
|
|
4983
|
-
stage.container().addEventListener("keyup", (e) => {
|
|
4984
|
-
if (e.code === "Space") this.isSpaceKeyPressed = false;
|
|
4985
|
-
}, { signal: this.instance.getEventsController()?.signal });
|
|
4986
|
-
stage.on("pointerdown", (e) => {
|
|
4987
|
-
this.setTapStart(e);
|
|
4988
|
-
if (e.target.getClassName().includes("custom-snap-guide")) return;
|
|
4989
|
-
this.handledClickOrTap = false;
|
|
4990
|
-
this.pointers[e.evt.pointerId] = e.evt;
|
|
4991
|
-
if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length > 1) return;
|
|
4992
|
-
if (e.evt.pointerType === "mouse" && e.evt?.button !== 0) return;
|
|
4993
|
-
if (e.evt.pointerType === "pen" && e.evt?.pressure <= .05) return;
|
|
4994
|
-
if (!this.initialized) return;
|
|
4995
|
-
if (!this.active) return;
|
|
4996
|
-
if (stage.mode() !== WEAVE_STAGE_DEFAULT_MODE) return;
|
|
4997
|
-
const selectedGroup = getTargetedNode(this.instance);
|
|
4998
|
-
if (selectedGroup?.getParent() instanceof Konva.Transformer) {
|
|
4999
|
-
this.selecting = false;
|
|
5000
|
-
this.stopPanLoop();
|
|
5001
|
-
this.hideSelectorArea();
|
|
5002
|
-
return;
|
|
5003
|
-
}
|
|
5004
|
-
const isStage = e.target instanceof Konva.Stage;
|
|
5005
|
-
const isTransformer = e.target?.getParent() instanceof Konva.Transformer;
|
|
5006
|
-
const canBeTargeted = e.target.getAttrs().canBeTargeted !== false;
|
|
5007
|
-
const isContainerEmptyArea = e.target.getAttrs().isContainerPrincipal !== void 0 && !e.target.getAttrs().isContainerPrincipal;
|
|
5008
|
-
if (isTransformer) return;
|
|
5009
|
-
if (!isStage && !isContainerEmptyArea && canBeTargeted) {
|
|
5010
|
-
this.selecting = false;
|
|
5011
|
-
this.stopPanLoop();
|
|
5012
|
-
this.hideSelectorArea();
|
|
5013
|
-
this.handleClickOrTap(e);
|
|
5014
|
-
return;
|
|
5015
|
-
}
|
|
5016
|
-
if (isStage || isContainerEmptyArea) {
|
|
5017
|
-
this.setSelectedNodes([]);
|
|
5018
|
-
this.serializeSelectedNodes();
|
|
5019
|
-
this.triggerOnNodesChangeEvent();
|
|
5020
|
-
}
|
|
5021
|
-
this.panDirection.x = 0;
|
|
5022
|
-
this.panDirection.y = 0;
|
|
5023
|
-
this.panSpeed = {
|
|
5024
|
-
x: 0,
|
|
5025
|
-
y: 0
|
|
5026
|
-
};
|
|
5027
|
-
const intStage = this.instance.getStage();
|
|
5028
|
-
this.x1 = intStage.getRelativePointerPosition()?.x ?? 0;
|
|
5029
|
-
this.y1 = intStage.getRelativePointerPosition()?.y ?? 0;
|
|
5030
|
-
this.x2 = intStage.getRelativePointerPosition()?.x ?? 0;
|
|
5031
|
-
this.y2 = intStage.getRelativePointerPosition()?.y ?? 0;
|
|
5032
|
-
this.selectionStart = {
|
|
5033
|
-
x: this.x1,
|
|
5034
|
-
y: this.y1
|
|
5035
|
-
};
|
|
5036
|
-
this.selectionRectangle.strokeWidth(this.config.selectionArea.strokeWidth / stage.scaleX());
|
|
5037
|
-
this.selectionRectangle.dash(this.config.selectionArea.dash?.map((d) => d / stage.scaleX()) ?? []);
|
|
5038
|
-
this.selectionRectangle.width(0);
|
|
5039
|
-
this.selectionRectangle.height(0);
|
|
5040
|
-
this.selecting = true;
|
|
5041
|
-
const isCtrlOrMetaPressed = e.evt.ctrlKey || e.evt.metaKey;
|
|
5042
|
-
if (isCtrlOrMetaPressed) {
|
|
5043
|
-
const nodesSelected = this.tr.nodes();
|
|
5044
|
-
for (const node of nodesSelected) node.fire("onSelectionCleared", { bubbles: true });
|
|
5045
|
-
}
|
|
5046
|
-
this.selectNone();
|
|
5047
|
-
this.instance.emitEvent("onSelectionState", true);
|
|
5048
|
-
this.panLoopId = requestAnimationFrame(() => this.panLoop());
|
|
5049
|
-
});
|
|
5050
|
-
const handleMouseMove = (e) => {
|
|
5051
|
-
if (!e?.evt) return;
|
|
5052
|
-
const moved = this.checkMoved(e);
|
|
5053
|
-
if (e.evt?.buttons === 0) return;
|
|
5054
|
-
if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length > 1) return;
|
|
5055
|
-
if (!this.initialized) return;
|
|
5056
|
-
if (!this.active) return;
|
|
5057
|
-
const contextMenuPlugin = this.getContextMenuPlugin();
|
|
5058
|
-
if (moved) contextMenuPlugin?.cancelLongPressTimer();
|
|
5059
|
-
else this.hideSelectorArea();
|
|
5060
|
-
if (contextMenuPlugin?.isContextMenuVisible()) this.stopPanLoop();
|
|
5061
|
-
if (this.isSpaceKeyPressed) return;
|
|
5062
|
-
if (!this.selecting) return;
|
|
5063
|
-
this.updateSelectionRect();
|
|
5064
|
-
this.updatePanDirection();
|
|
5065
|
-
};
|
|
5066
|
-
stage.on("pointermove", (0, import_throttle.default)(handleMouseMove, DEFAULT_THROTTLE_MS));
|
|
5067
|
-
this.panLoop();
|
|
5068
|
-
stage.on("pointerup", (e) => {
|
|
5069
|
-
const store = this.instance.getStore();
|
|
5070
|
-
const actUser = store.getUser();
|
|
5071
|
-
this.tr.setAttrs({ listening: true });
|
|
5072
|
-
this.selecting = false;
|
|
5073
|
-
this.stopPanLoop();
|
|
5074
|
-
const moved = this.checkMoved(e);
|
|
5075
|
-
this.checkDoubleTap(e);
|
|
5076
|
-
delete this.pointers[e.evt.pointerId];
|
|
5077
|
-
this.previousTap = this.tapStart;
|
|
5078
|
-
if (stage.mode() !== WEAVE_STAGE_DEFAULT_MODE) return;
|
|
5079
|
-
const contextMenuPlugin = this.getContextMenuPlugin();
|
|
5080
|
-
if (!this.initialized) {
|
|
5081
|
-
this.hideSelectorArea();
|
|
5082
|
-
return;
|
|
5083
|
-
}
|
|
5084
|
-
if (!this.active) {
|
|
5085
|
-
this.hideSelectorArea();
|
|
5086
|
-
return;
|
|
5087
|
-
}
|
|
5088
|
-
this.instance.emitEvent("onSelectionState", false);
|
|
5089
|
-
if (this.isDoubleTap) {
|
|
5090
|
-
this.hideSelectorArea();
|
|
5091
|
-
this.handleClickOrTap(e);
|
|
5092
|
-
return;
|
|
5093
|
-
}
|
|
5094
|
-
const isStage = e.target instanceof Konva.Stage;
|
|
5095
|
-
const isContainerEmptyArea = e.target.getAttrs().isContainerPrincipal !== void 0 && !e.target.getAttrs().isContainerPrincipal;
|
|
5096
|
-
if ((isStage || isContainerEmptyArea) && !moved) {
|
|
5097
|
-
this.selecting = false;
|
|
5098
|
-
this.stopPanLoop();
|
|
5099
|
-
this.hideSelectorArea();
|
|
5100
|
-
this.getSelectionPlugin()?.setSelectedNodes([]);
|
|
5101
|
-
return;
|
|
5102
|
-
}
|
|
5103
|
-
if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length + 1 > 1) {
|
|
5104
|
-
this.hideSelectorArea();
|
|
5105
|
-
return;
|
|
5106
|
-
}
|
|
5107
|
-
if (contextMenuPlugin?.isContextMenuVisible()) this.stopPanLoop();
|
|
5108
|
-
const selectedGroup = getTargetedNode(this.instance);
|
|
5109
|
-
if (!moved && selectedGroup?.getParent() instanceof Konva.Transformer && !this.handledClickOrTap) {
|
|
5110
|
-
this.selecting = false;
|
|
5111
|
-
this.stopPanLoop();
|
|
5112
|
-
this.hideSelectorArea();
|
|
5113
|
-
this.handleClickOrTap(e);
|
|
5114
|
-
return;
|
|
5115
|
-
}
|
|
5116
|
-
if (!this.selectionRectangle.visible()) {
|
|
5117
|
-
this.hideSelectorArea();
|
|
5118
|
-
return;
|
|
5119
|
-
}
|
|
5120
|
-
const shapes = stage.find((node) => {
|
|
5121
|
-
return ["Shape", "Group"].includes(node.getType()) && typeof node.getAttrs().id !== "undefined";
|
|
5122
|
-
});
|
|
5123
|
-
const box = this.selectionRectangle.getClientRect();
|
|
5124
|
-
this.selectionRectangle.visible(false);
|
|
5125
|
-
const selected = shapes.filter((shape) => {
|
|
5126
|
-
const shapeMutex = this.instance.getNodeMutexLock(shape.id());
|
|
5127
|
-
if (shapeMutex && shapeMutex.user.id !== actUser.id) return false;
|
|
5128
|
-
let parent = this.instance.getInstanceRecursive(shape.getParent());
|
|
5129
|
-
if (parent.getAttrs().nodeId) parent = this.instance.getStage().findOne(`#${parent.getAttrs().nodeId}`);
|
|
5130
|
-
if (shape.getAttrs().nodeType && shape.getAttrs().nodeType === "frame") {
|
|
5131
|
-
const frameBox = shape.getClientRect();
|
|
5132
|
-
const isContained = frameBox.x >= box.x && frameBox.y >= box.y && frameBox.x + frameBox.width <= box.x + box.width && frameBox.y + frameBox.height <= box.y + box.height;
|
|
5133
|
-
return isContained;
|
|
5134
|
-
}
|
|
5135
|
-
if (shape.getAttrs().nodeType && shape?.getAttrs().nodeType === "group" && ["layer", "frame"].includes(parent?.getAttrs().nodeType)) return shape.getAttrs().nodeType && Konva.Util.haveIntersection(box, shape.getClientRect());
|
|
5136
|
-
if (shape.getAttrs().nodeType && shape.getAttrs().nodeType !== "group" && ["layer", "frame"].includes(parent?.getAttrs().nodeType)) return shape.getAttrs().nodeType && Konva.Util.haveIntersection(box, shape.getClientRect());
|
|
5137
|
-
return false;
|
|
5138
|
-
});
|
|
5139
|
-
const selectedNodes = new Set();
|
|
5140
|
-
const uniqueContainerNodesIds = new Set();
|
|
5141
|
-
const containerNodesIds = [];
|
|
5142
|
-
const containerNodes = [];
|
|
5143
|
-
const otherNodes = [];
|
|
5144
|
-
for (const node of selected) {
|
|
5145
|
-
let realNode = node;
|
|
5146
|
-
if (node.getAttrs().nodeId) realNode = stage.findOne(`#${node.getAttrs().nodeId}`);
|
|
5147
|
-
if (!realNode) continue;
|
|
5148
|
-
const isContainer = typeof realNode.getAttrs().isContainerPrincipal !== "undefined" && realNode.getAttrs().isContainerPrincipal;
|
|
5149
|
-
if (isContainer) {
|
|
5150
|
-
containerNodes.push(realNode);
|
|
5151
|
-
containerNodesIds.push(realNode.getAttrs().id ?? "");
|
|
5152
|
-
uniqueContainerNodesIds.add(realNode.getAttrs().id ?? "");
|
|
5153
|
-
if (!realNode.getAttrs().locked) selectedNodes.add(realNode);
|
|
5154
|
-
} else otherNodes.push(realNode);
|
|
5155
|
-
}
|
|
5156
|
-
for (const node of otherNodes) {
|
|
5157
|
-
let parent = this.instance.getInstanceRecursive(node.getParent());
|
|
5158
|
-
if (parent?.getAttrs().nodeId) parent = this.instance.getStage().findOne(`#${parent.getAttrs().nodeId}`);
|
|
5159
|
-
if (parent && !containerNodesIds.includes(parent?.getAttrs().id ?? "") && !node.getAttrs().locked) selectedNodes.add(node);
|
|
5160
|
-
}
|
|
5161
|
-
this.selecting = false;
|
|
5162
|
-
this.stopPanLoop();
|
|
5163
|
-
this.tr.nodes([...selectedNodes]);
|
|
5164
|
-
this.handleMultipleSelectionBehavior();
|
|
5165
|
-
this.handleBehaviors();
|
|
5166
|
-
if (this.tr.nodes().length > 0) {
|
|
5167
|
-
stage.container().tabIndex = 1;
|
|
5168
|
-
stage.container().focus();
|
|
5169
|
-
}
|
|
5170
|
-
this.triggerSelectedNodesEvent();
|
|
5171
|
-
});
|
|
5293
|
+
registerKeyboardHandlers(this);
|
|
5294
|
+
stage.on("pointerdown", (e) => handlePointerDown(this, e));
|
|
5295
|
+
stage.on("pointermove", (0, import_throttle.default)((e) => handlePointerMove(this, e), DEFAULT_THROTTLE_MS));
|
|
5296
|
+
stage.on("pointerup", (e) => handlePointerUp(this, e));
|
|
5172
5297
|
this.instance.addEventListener("onStateChange", () => {
|
|
5173
5298
|
requestAnimationFrame(() => {
|
|
5174
5299
|
this.syncSelection();
|
|
@@ -5181,129 +5306,53 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
5181
5306
|
});
|
|
5182
5307
|
}
|
|
5183
5308
|
handleMultipleSelectionBehavior() {
|
|
5184
|
-
|
|
5185
|
-
|
|
5186
|
-
this.tr.
|
|
5187
|
-
|
|
5309
|
+
const tr = this.transformerCtrl.getTransformer();
|
|
5310
|
+
if (tr.nodes().length > 1 && this.config.behaviors?.onMultipleSelection) {
|
|
5311
|
+
const selectionBehavior = this.config.behaviors.onMultipleSelection(tr.nodes());
|
|
5312
|
+
tr.setAttrs(selectionBehavior);
|
|
5313
|
+
tr.forceUpdate();
|
|
5188
5314
|
}
|
|
5189
5315
|
}
|
|
5190
5316
|
syncSelection() {
|
|
5191
5317
|
const stageMode = this.instance.getStage().mode();
|
|
5192
5318
|
if (![WEAVE_STAGE_DEFAULT_MODE].includes(stageMode)) return;
|
|
5319
|
+
const tr = this.transformerCtrl.getTransformer();
|
|
5193
5320
|
const newSelectedNodes = [];
|
|
5194
|
-
const actualSelectedNodes =
|
|
5321
|
+
const actualSelectedNodes = tr.nodes();
|
|
5195
5322
|
for (const node of actualSelectedNodes) {
|
|
5196
5323
|
const existNode = this.instance.getStage().findOne(`#${node.getAttrs().id}`);
|
|
5197
5324
|
if (existNode) newSelectedNodes.push(existNode);
|
|
5198
5325
|
}
|
|
5199
|
-
|
|
5200
|
-
if (newSelectedNodes.length > 0)
|
|
5326
|
+
tr.nodes([...newSelectedNodes]);
|
|
5327
|
+
if (newSelectedNodes.length > 0) tr.forceUpdate();
|
|
5201
5328
|
this.triggerSelectedNodesEvent();
|
|
5202
5329
|
}
|
|
5203
5330
|
getSelectionPlugin() {
|
|
5204
|
-
|
|
5205
|
-
return selectionPlugin;
|
|
5331
|
+
return this.instance.getPlugin("nodesSelection");
|
|
5206
5332
|
}
|
|
5207
5333
|
hideHoverState() {
|
|
5208
5334
|
const selectionPlugin = this.getSelectionPlugin();
|
|
5209
5335
|
if (!selectionPlugin) return;
|
|
5210
5336
|
selectionPlugin.getHoverTransformer().nodes([]);
|
|
5211
5337
|
}
|
|
5212
|
-
handleClickOrTap(e) {
|
|
5213
|
-
const stage = this.instance.getStage();
|
|
5214
|
-
this.handledClickOrTap = true;
|
|
5215
|
-
e.cancelBubble = true;
|
|
5216
|
-
if (!this.enabled) return;
|
|
5217
|
-
if (this.instance.getActiveAction() !== SELECTION_TOOL_ACTION_NAME) return;
|
|
5218
|
-
const contextMenuPlugin = this.getContextMenuPlugin();
|
|
5219
|
-
if (contextMenuPlugin?.isContextMenuVisible()) this.stopPanLoop();
|
|
5220
|
-
this.hideHoverState();
|
|
5221
|
-
const selectedGroup = getTargetedNode(this.instance);
|
|
5222
|
-
if (!this.initialized) return;
|
|
5223
|
-
if (e.evt.pointerType === "mouse" && e.evt?.button && e.evt?.button !== 0) return;
|
|
5224
|
-
let areNodesSelected = false;
|
|
5225
|
-
let nodeTargeted = selectedGroup && !(selectedGroup.getAttrs().active ?? false) ? selectedGroup : e.target;
|
|
5226
|
-
if (e.target === this.instance.getStage()) {
|
|
5227
|
-
this.isDoubleTap = false;
|
|
5228
|
-
this.getNodesSelectionFeedbackPlugin()?.cleanupSelectedHalos();
|
|
5229
|
-
return;
|
|
5230
|
-
}
|
|
5231
|
-
nodeTargeted = this.instance.getRealSelectedNode(nodeTargeted);
|
|
5232
|
-
if (!nodeTargeted.getAttrs().nodeType) {
|
|
5233
|
-
this.isDoubleTap = false;
|
|
5234
|
-
return;
|
|
5235
|
-
}
|
|
5236
|
-
const metaPressed = e.evt.shiftKey || e.evt.ctrlKey || e.evt.metaKey;
|
|
5237
|
-
const nodeSelectedIndex = this.tr.nodes().findIndex((node) => {
|
|
5238
|
-
return node.getAttrs().id === nodeTargeted.getAttrs().id;
|
|
5239
|
-
});
|
|
5240
|
-
const isSelected = nodeSelectedIndex !== -1;
|
|
5241
|
-
const user = this.instance.getStore().getUser();
|
|
5242
|
-
const isLocked = nodeTargeted.getAttrs().locked ?? false;
|
|
5243
|
-
const isMutexLocked = nodeTargeted.getAttrs().mutexLocked && nodeTargeted.getAttrs().mutexUserId !== user.id;
|
|
5244
|
-
if (isLocked || isMutexLocked) {
|
|
5245
|
-
const parent = this.instance.getInstanceRecursive(nodeTargeted.getParent());
|
|
5246
|
-
const mainLayer = this.instance.getMainLayer();
|
|
5247
|
-
const isStage = parent instanceof Konva.Stage;
|
|
5248
|
-
const isMainLayer = parent === mainLayer;
|
|
5249
|
-
const isContainerEmptyArea = e.target.getAttrs().isContainerPrincipal !== void 0 && !e.target.getAttrs().isContainerPrincipal;
|
|
5250
|
-
if (isStage || isMainLayer || isContainerEmptyArea) this.getSelectionPlugin()?.setSelectedNodes([]);
|
|
5251
|
-
return;
|
|
5252
|
-
}
|
|
5253
|
-
if (nodeTargeted.getAttrs().nodeId) {
|
|
5254
|
-
const realNode = stage.findOne(`#${nodeTargeted.getAttrs().nodeId}`);
|
|
5255
|
-
if (realNode) nodeTargeted = realNode;
|
|
5256
|
-
}
|
|
5257
|
-
if (typeof nodeTargeted.getAttrs().isContainerPrincipal !== "undefined" && !nodeTargeted.getAttrs().isContainerPrincipal) return;
|
|
5258
|
-
if (this.isDoubleTap && !metaPressed) {
|
|
5259
|
-
this.isDoubleTap = false;
|
|
5260
|
-
nodeTargeted.dblClick();
|
|
5261
|
-
return;
|
|
5262
|
-
}
|
|
5263
|
-
const isCtrlOrCmdPressed = e.evt.ctrlKey || e.evt.metaKey;
|
|
5264
|
-
if (isCtrlOrCmdPressed) return;
|
|
5265
|
-
if (!metaPressed) {
|
|
5266
|
-
this.tr.nodes([nodeTargeted]);
|
|
5267
|
-
this.tr.show();
|
|
5268
|
-
areNodesSelected = true;
|
|
5269
|
-
}
|
|
5270
|
-
if (metaPressed && isSelected) {
|
|
5271
|
-
const nodes = this.tr.nodes().slice();
|
|
5272
|
-
nodes.splice(nodes.indexOf(nodeTargeted), 1);
|
|
5273
|
-
this.tr.nodes(nodes);
|
|
5274
|
-
areNodesSelected = true;
|
|
5275
|
-
}
|
|
5276
|
-
if (metaPressed && !isSelected) {
|
|
5277
|
-
const nodes = this.tr.nodes().concat([nodeTargeted]);
|
|
5278
|
-
this.tr.nodes(nodes);
|
|
5279
|
-
areNodesSelected = true;
|
|
5280
|
-
}
|
|
5281
|
-
this.handleMultipleSelectionBehavior();
|
|
5282
|
-
this.handleBehaviors();
|
|
5283
|
-
if (areNodesSelected) {
|
|
5284
|
-
stage.container().tabIndex = 1;
|
|
5285
|
-
stage.container().focus();
|
|
5286
|
-
stage.container().style.cursor = (typeof nodeTargeted?.defineMousePointer === "function" ? nodeTargeted.defineMousePointer() : null) ?? "grab";
|
|
5287
|
-
}
|
|
5288
|
-
this.triggerSelectedNodesEvent();
|
|
5289
|
-
}
|
|
5290
5338
|
getTransformer() {
|
|
5291
|
-
return this.
|
|
5339
|
+
return this.transformerCtrl.getTransformer();
|
|
5292
5340
|
}
|
|
5293
5341
|
getHoverTransformer() {
|
|
5294
|
-
return this.
|
|
5342
|
+
return this.transformerCtrl.getHoverTransformer();
|
|
5295
5343
|
}
|
|
5296
5344
|
handleBehaviors() {
|
|
5345
|
+
const tr = this.transformerCtrl.getTransformer();
|
|
5297
5346
|
const nodes = this.getSelectedNodes();
|
|
5298
5347
|
const nodesSelected = nodes.length;
|
|
5299
|
-
if (nodesSelected > 1 && !this.config.behaviors.multipleSelection.enabled || nodesSelected === 1 && !this.config.behaviors.singleSelection.enabled)
|
|
5300
|
-
if (nodesSelected > 1 && this.config.behaviors.multipleSelection.enabled || nodesSelected === 1 && this.config.behaviors.singleSelection.enabled)
|
|
5348
|
+
if (nodesSelected > 1 && !this.config.behaviors.multipleSelection.enabled || nodesSelected === 1 && !this.config.behaviors.singleSelection.enabled) tr.enabledAnchors([]);
|
|
5349
|
+
if (nodesSelected > 1 && this.config.behaviors.multipleSelection.enabled || nodesSelected === 1 && this.config.behaviors.singleSelection.enabled) tr.enabledAnchors(this._defaultEnabledAnchors);
|
|
5301
5350
|
let transformerAttrs = { ...this.config.selection };
|
|
5302
|
-
if (
|
|
5303
|
-
const currentAttrs =
|
|
5351
|
+
if (tr && tr.nodes().length > 0) {
|
|
5352
|
+
const currentAttrs = tr.getAttrs();
|
|
5304
5353
|
Object.keys(currentAttrs).forEach((key) => {
|
|
5305
|
-
if (["rotationSnaps", "enabledAnchors"].includes(key))
|
|
5306
|
-
else
|
|
5354
|
+
if (["rotationSnaps", "enabledAnchors"].includes(key)) tr.setAttr(key, []);
|
|
5355
|
+
else tr.setAttr(key, void 0);
|
|
5307
5356
|
});
|
|
5308
5357
|
}
|
|
5309
5358
|
if (nodesSelected === 1) {
|
|
@@ -5313,31 +5362,32 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
5313
5362
|
if (nodesSelected > 1) {
|
|
5314
5363
|
const anchorsArrays = [];
|
|
5315
5364
|
for (const node of nodes) anchorsArrays.push(node?.allowedAnchors?.() ?? []);
|
|
5316
|
-
|
|
5317
|
-
transformerAttrs.enabledAnchors = enabledAnchors;
|
|
5365
|
+
transformerAttrs.enabledAnchors = intersectArrays(anchorsArrays);
|
|
5318
5366
|
}
|
|
5319
|
-
if (
|
|
5367
|
+
if (tr && tr.nodes().length > 0) {
|
|
5320
5368
|
if (transformerAttrs.enabledAnchors?.length === 0) transformerAttrs.resizeEnabled = false;
|
|
5321
|
-
|
|
5322
|
-
|
|
5323
|
-
|
|
5369
|
+
tr.setAttrs(transformerAttrs);
|
|
5370
|
+
tr.forceUpdate();
|
|
5371
|
+
tr.getLayer()?.batchDraw();
|
|
5324
5372
|
}
|
|
5325
5373
|
}
|
|
5326
5374
|
setSelectedNodes(nodes) {
|
|
5327
|
-
this.
|
|
5375
|
+
const tr = this.transformerCtrl.getTransformer();
|
|
5376
|
+
tr.setNodes(nodes);
|
|
5328
5377
|
this.handleBehaviors();
|
|
5329
5378
|
if (nodes.length === 0) this.getNodesSelectionFeedbackPlugin()?.cleanupSelectedHalos();
|
|
5330
5379
|
const usersSelectionPlugin = this.instance.getPlugin(WEAVE_USERS_SELECTION_KEY);
|
|
5331
5380
|
if (usersSelectionPlugin) requestAnimationFrame(() => {
|
|
5332
|
-
usersSelectionPlugin.sendSelectionAwarenessInfo(
|
|
5381
|
+
usersSelectionPlugin.sendSelectionAwarenessInfo(tr);
|
|
5333
5382
|
});
|
|
5334
5383
|
}
|
|
5335
5384
|
getSelectedNodes() {
|
|
5336
|
-
if (!this.
|
|
5337
|
-
return this.
|
|
5385
|
+
if (!this.transformerCtrl) return [];
|
|
5386
|
+
return this.transformerCtrl.getTransformer().nodes();
|
|
5338
5387
|
}
|
|
5339
5388
|
getSelectedNodesExtended() {
|
|
5340
|
-
const
|
|
5389
|
+
const tr = this.transformerCtrl.getTransformer();
|
|
5390
|
+
return tr.getNodes().map((node) => {
|
|
5341
5391
|
const nodeType = node.getAttr("nodeType");
|
|
5342
5392
|
const nodeHandler = this.instance.getNodeHandler(nodeType);
|
|
5343
5393
|
return {
|
|
@@ -5345,17 +5395,13 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
5345
5395
|
node: nodeHandler?.serialize(node)
|
|
5346
5396
|
};
|
|
5347
5397
|
});
|
|
5348
|
-
return selectedNodes;
|
|
5349
5398
|
}
|
|
5350
5399
|
selectAll() {
|
|
5351
5400
|
const mainLayer = this.instance.getMainLayer();
|
|
5352
|
-
if (mainLayer)
|
|
5353
|
-
const nodes = mainLayer.getChildren();
|
|
5354
|
-
this.tr.nodes(nodes);
|
|
5355
|
-
}
|
|
5401
|
+
if (mainLayer) this.transformerCtrl.getTransformer().nodes(mainLayer.getChildren());
|
|
5356
5402
|
}
|
|
5357
5403
|
selectNone() {
|
|
5358
|
-
this.
|
|
5404
|
+
this.transformerCtrl.getTransformer().nodes([]);
|
|
5359
5405
|
}
|
|
5360
5406
|
enable() {
|
|
5361
5407
|
this.getLayer()?.show();
|
|
@@ -5366,36 +5412,31 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
|
|
|
5366
5412
|
this.enabled = false;
|
|
5367
5413
|
}
|
|
5368
5414
|
getNodesSelectionFeedbackPlugin() {
|
|
5369
|
-
|
|
5370
|
-
return selectionFeedbackPlugin;
|
|
5415
|
+
return getNodesSelectionFeedbackPlugin(this.instance);
|
|
5371
5416
|
}
|
|
5372
5417
|
getContextMenuPlugin() {
|
|
5373
|
-
|
|
5374
|
-
return contextMenuPlugin;
|
|
5418
|
+
return getContextMenuPlugin(this.instance);
|
|
5375
5419
|
}
|
|
5376
5420
|
getStageGridPlugin() {
|
|
5377
|
-
|
|
5378
|
-
return gridPlugin;
|
|
5421
|
+
return getStageGridPlugin(this.instance);
|
|
5379
5422
|
}
|
|
5380
5423
|
getStagePanningPlugin() {
|
|
5381
|
-
|
|
5382
|
-
return stagePanning;
|
|
5424
|
+
return getStagePanningPlugin(this.instance);
|
|
5383
5425
|
}
|
|
5384
5426
|
getUsersPresencePlugin() {
|
|
5385
|
-
|
|
5386
|
-
return usersPresencePlugin;
|
|
5427
|
+
return getUsersPresencePlugin(this.instance);
|
|
5387
5428
|
}
|
|
5388
5429
|
isTransforming() {
|
|
5389
|
-
return this.
|
|
5430
|
+
return this.transformerCtrl.isTransforming();
|
|
5390
5431
|
}
|
|
5391
5432
|
isDragging() {
|
|
5392
|
-
return this.
|
|
5433
|
+
return this.transformerCtrl.isDragging();
|
|
5393
5434
|
}
|
|
5394
5435
|
getSelectorConfig() {
|
|
5395
5436
|
return this.config.selection;
|
|
5396
5437
|
}
|
|
5397
5438
|
saveDragSelectedNodes() {
|
|
5398
|
-
this.dragSelectedNodes = this.
|
|
5439
|
+
this.dragSelectedNodes = this.transformerCtrl.getTransformer().nodes();
|
|
5399
5440
|
}
|
|
5400
5441
|
getDragSelectedNodes() {
|
|
5401
5442
|
return this.dragSelectedNodes;
|
|
@@ -5473,30 +5514,30 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
5473
5514
|
this.initEvents();
|
|
5474
5515
|
}
|
|
5475
5516
|
writeClipboardImage(base64Data) {
|
|
5476
|
-
return new Promise((resolve, reject
|
|
5517
|
+
return new Promise((resolve, reject) => {
|
|
5477
5518
|
setTimeout(async () => {
|
|
5478
|
-
if (navigator.clipboard === void 0) return reject
|
|
5519
|
+
if (navigator.clipboard === void 0) return reject(new Error("Clipboard API not supported"));
|
|
5479
5520
|
const res = await fetch(base64Data);
|
|
5480
5521
|
const imageBlob = await res.blob();
|
|
5481
5522
|
const item = new ClipboardItem({ [imageBlob.type]: imageBlob });
|
|
5482
5523
|
navigator.clipboard.write([item]).then(() => {
|
|
5483
5524
|
resolve();
|
|
5484
5525
|
}).catch((error) => {
|
|
5485
|
-
reject
|
|
5526
|
+
reject(error);
|
|
5486
5527
|
});
|
|
5487
5528
|
});
|
|
5488
5529
|
});
|
|
5489
5530
|
}
|
|
5490
5531
|
writeClipboardData(data) {
|
|
5491
|
-
return new Promise((resolve, reject
|
|
5532
|
+
return new Promise((resolve, reject) => {
|
|
5492
5533
|
setTimeout(async () => {
|
|
5493
|
-
if (navigator.clipboard === void 0) return reject
|
|
5534
|
+
if (navigator.clipboard === void 0) return reject(new Error("Clipboard API not supported"));
|
|
5494
5535
|
const textBlob = new Blob([data], { type: "text/plain" });
|
|
5495
5536
|
const item = new ClipboardItem({ [textBlob.type]: textBlob });
|
|
5496
5537
|
navigator.clipboard.write([item]).then(() => {
|
|
5497
5538
|
resolve();
|
|
5498
5539
|
}).catch((error) => {
|
|
5499
|
-
reject
|
|
5540
|
+
reject(error);
|
|
5500
5541
|
});
|
|
5501
5542
|
});
|
|
5502
5543
|
});
|
|
@@ -5566,7 +5607,7 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
5566
5607
|
this.focusPasteCatcher();
|
|
5567
5608
|
if (!this.enabled) return;
|
|
5568
5609
|
}
|
|
5569
|
-
}, { signal: this.instance.getEventsController()
|
|
5610
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
5570
5611
|
if (catcher) catcher.addEventListener("paste", async (e) => {
|
|
5571
5612
|
e.preventDefault();
|
|
5572
5613
|
let items = void 0;
|
|
@@ -5585,7 +5626,7 @@ var WeaveCopyPasteNodesPlugin = class extends WeavePlugin {
|
|
|
5585
5626
|
return;
|
|
5586
5627
|
}
|
|
5587
5628
|
this.sendExternalPasteEvent(void 0, items);
|
|
5588
|
-
}, { signal: this.instance.getEventsController()
|
|
5629
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
5589
5630
|
}
|
|
5590
5631
|
sendExternalPasteEvent(dataList, items) {
|
|
5591
5632
|
const stage = this.instance.getStage();
|
|
@@ -6828,7 +6869,7 @@ var require__arrayMap = __commonJS({ "../../node_modules/lodash/_arrayMap.js"(ex
|
|
|
6828
6869
|
//#endregion
|
|
6829
6870
|
//#region ../../node_modules/lodash/_isKey.js
|
|
6830
6871
|
var require__isKey = __commonJS({ "../../node_modules/lodash/_isKey.js"(exports, module) {
|
|
6831
|
-
var isArray$
|
|
6872
|
+
var isArray$9 = require_isArray(), isSymbol$3 = require_isSymbol();
|
|
6832
6873
|
/** Used to match property names within property paths. */
|
|
6833
6874
|
var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, reIsPlainProp = /^\w*$/;
|
|
6834
6875
|
/**
|
|
@@ -6840,7 +6881,7 @@ var require__isKey = __commonJS({ "../../node_modules/lodash/_isKey.js"(exports,
|
|
|
6840
6881
|
* @returns {boolean} Returns `true` if `value` is a property name, else `false`.
|
|
6841
6882
|
*/
|
|
6842
6883
|
function isKey$3(value, object) {
|
|
6843
|
-
if (isArray$
|
|
6884
|
+
if (isArray$9(value)) return false;
|
|
6844
6885
|
var type = typeof value;
|
|
6845
6886
|
if (type == "number" || type == "symbol" || type == "boolean" || value == null || isSymbol$3(value)) return true;
|
|
6846
6887
|
return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || object != null && value in Object(object);
|
|
@@ -6853,7 +6894,7 @@ var require__isKey = __commonJS({ "../../node_modules/lodash/_isKey.js"(exports,
|
|
|
6853
6894
|
var require_memoize = __commonJS({ "../../node_modules/lodash/memoize.js"(exports, module) {
|
|
6854
6895
|
var MapCache$1 = require__MapCache();
|
|
6855
6896
|
/** Error message constants. */
|
|
6856
|
-
var FUNC_ERROR_TEXT
|
|
6897
|
+
var FUNC_ERROR_TEXT = "Expected a function";
|
|
6857
6898
|
/**
|
|
6858
6899
|
* Creates a function that memoizes the result of `func`. If `resolver` is
|
|
6859
6900
|
* provided, it determines the cache key for storing the result based on the
|
|
@@ -6899,7 +6940,7 @@ var require_memoize = __commonJS({ "../../node_modules/lodash/memoize.js"(export
|
|
|
6899
6940
|
* _.memoize.Cache = WeakMap;
|
|
6900
6941
|
*/
|
|
6901
6942
|
function memoize$2(func, resolver) {
|
|
6902
|
-
if (typeof func != "function" || resolver != null && typeof resolver != "function") throw new TypeError(FUNC_ERROR_TEXT
|
|
6943
|
+
if (typeof func != "function" || resolver != null && typeof resolver != "function") throw new TypeError(FUNC_ERROR_TEXT);
|
|
6903
6944
|
var memoized = function() {
|
|
6904
6945
|
var args = arguments, key = resolver ? resolver.apply(this, args) : args[0], cache = memoized.cache;
|
|
6905
6946
|
if (cache.has(key)) return cache.get(key);
|
|
@@ -6968,7 +7009,7 @@ var require__stringToPath = __commonJS({ "../../node_modules/lodash/_stringToPat
|
|
|
6968
7009
|
//#endregion
|
|
6969
7010
|
//#region ../../node_modules/lodash/_baseToString.js
|
|
6970
7011
|
var require__baseToString = __commonJS({ "../../node_modules/lodash/_baseToString.js"(exports, module) {
|
|
6971
|
-
var Symbol$2 = require__Symbol(), arrayMap$1 = require__arrayMap(), isArray$
|
|
7012
|
+
var Symbol$2 = require__Symbol(), arrayMap$1 = require__arrayMap(), isArray$8 = require_isArray(), isSymbol$2 = require_isSymbol();
|
|
6972
7013
|
/** Used as references for various `Number` constants. */
|
|
6973
7014
|
var INFINITY$1 = Infinity;
|
|
6974
7015
|
/** Used to convert symbols to primitives and strings. */
|
|
@@ -6983,7 +7024,7 @@ var require__baseToString = __commonJS({ "../../node_modules/lodash/_baseToStrin
|
|
|
6983
7024
|
*/
|
|
6984
7025
|
function baseToString$1(value) {
|
|
6985
7026
|
if (typeof value == "string") return value;
|
|
6986
|
-
if (isArray$
|
|
7027
|
+
if (isArray$8(value)) return arrayMap$1(value, baseToString$1) + "";
|
|
6987
7028
|
if (isSymbol$2(value)) return symbolToString ? symbolToString.call(value) : "";
|
|
6988
7029
|
var result = value + "";
|
|
6989
7030
|
return result == "0" && 1 / value == -INFINITY$1 ? "-0" : result;
|
|
@@ -7025,7 +7066,7 @@ var require_toString = __commonJS({ "../../node_modules/lodash/toString.js"(expo
|
|
|
7025
7066
|
//#endregion
|
|
7026
7067
|
//#region ../../node_modules/lodash/_castPath.js
|
|
7027
7068
|
var require__castPath = __commonJS({ "../../node_modules/lodash/_castPath.js"(exports, module) {
|
|
7028
|
-
var isArray$
|
|
7069
|
+
var isArray$7 = require_isArray(), isKey$2 = require__isKey(), stringToPath = require__stringToPath(), toString = require_toString();
|
|
7029
7070
|
/**
|
|
7030
7071
|
* Casts `value` to a path array if it's not one.
|
|
7031
7072
|
*
|
|
@@ -7035,7 +7076,7 @@ var require__castPath = __commonJS({ "../../node_modules/lodash/_castPath.js"(ex
|
|
|
7035
7076
|
* @returns {Array} Returns the cast property path array.
|
|
7036
7077
|
*/
|
|
7037
7078
|
function castPath$2(value, object) {
|
|
7038
|
-
if (isArray$
|
|
7079
|
+
if (isArray$7(value)) return value;
|
|
7039
7080
|
return isKey$2(value, object) ? [value] : stringToPath(toString(value));
|
|
7040
7081
|
}
|
|
7041
7082
|
module.exports = castPath$2;
|
|
@@ -7362,7 +7403,7 @@ var require__arrayPush = __commonJS({ "../../node_modules/lodash/_arrayPush.js"(
|
|
|
7362
7403
|
//#endregion
|
|
7363
7404
|
//#region ../../node_modules/lodash/_baseGetAllKeys.js
|
|
7364
7405
|
var require__baseGetAllKeys = __commonJS({ "../../node_modules/lodash/_baseGetAllKeys.js"(exports, module) {
|
|
7365
|
-
var arrayPush = require__arrayPush(), isArray$
|
|
7406
|
+
var arrayPush = require__arrayPush(), isArray$6 = require_isArray();
|
|
7366
7407
|
/**
|
|
7367
7408
|
* The base implementation of `getAllKeys` and `getAllKeysIn` which uses
|
|
7368
7409
|
* `keysFunc` and `symbolsFunc` to get the enumerable property names and
|
|
@@ -7376,7 +7417,7 @@ var require__baseGetAllKeys = __commonJS({ "../../node_modules/lodash/_baseGetAl
|
|
|
7376
7417
|
*/
|
|
7377
7418
|
function baseGetAllKeys$1(object, keysFunc, symbolsFunc) {
|
|
7378
7419
|
var result = keysFunc(object);
|
|
7379
|
-
return isArray$
|
|
7420
|
+
return isArray$6(object) ? result : arrayPush(result, symbolsFunc(object));
|
|
7380
7421
|
}
|
|
7381
7422
|
module.exports = baseGetAllKeys$1;
|
|
7382
7423
|
} });
|
|
@@ -7393,7 +7434,7 @@ var require__arrayFilter = __commonJS({ "../../node_modules/lodash/_arrayFilter.
|
|
|
7393
7434
|
* @param {Function} predicate The function invoked per iteration.
|
|
7394
7435
|
* @returns {Array} Returns the new filtered array.
|
|
7395
7436
|
*/
|
|
7396
|
-
function arrayFilter$
|
|
7437
|
+
function arrayFilter$1(array, predicate) {
|
|
7397
7438
|
var index = -1, length = array == null ? 0 : array.length, resIndex = 0, result = [];
|
|
7398
7439
|
while (++index < length) {
|
|
7399
7440
|
var value = array[index];
|
|
@@ -7401,7 +7442,7 @@ var require__arrayFilter = __commonJS({ "../../node_modules/lodash/_arrayFilter.
|
|
|
7401
7442
|
}
|
|
7402
7443
|
return result;
|
|
7403
7444
|
}
|
|
7404
|
-
module.exports = arrayFilter$
|
|
7445
|
+
module.exports = arrayFilter$1;
|
|
7405
7446
|
} });
|
|
7406
7447
|
|
|
7407
7448
|
//#endregion
|
|
@@ -7434,7 +7475,7 @@ var require_stubArray = __commonJS({ "../../node_modules/lodash/stubArray.js"(ex
|
|
|
7434
7475
|
//#endregion
|
|
7435
7476
|
//#region ../../node_modules/lodash/_getSymbols.js
|
|
7436
7477
|
var require__getSymbols = __commonJS({ "../../node_modules/lodash/_getSymbols.js"(exports, module) {
|
|
7437
|
-
var arrayFilter
|
|
7478
|
+
var arrayFilter = require__arrayFilter(), stubArray = require_stubArray();
|
|
7438
7479
|
/** Used for built-in method references. */
|
|
7439
7480
|
var objectProto$2 = Object.prototype;
|
|
7440
7481
|
/** Built-in value references. */
|
|
@@ -7450,7 +7491,7 @@ var require__getSymbols = __commonJS({ "../../node_modules/lodash/_getSymbols.js
|
|
|
7450
7491
|
var getSymbols$1 = !nativeGetSymbols ? stubArray : function(object) {
|
|
7451
7492
|
if (object == null) return [];
|
|
7452
7493
|
object = Object(object);
|
|
7453
|
-
return arrayFilter
|
|
7494
|
+
return arrayFilter(nativeGetSymbols(object), function(symbol) {
|
|
7454
7495
|
return propertyIsEnumerable.call(object, symbol);
|
|
7455
7496
|
});
|
|
7456
7497
|
};
|
|
@@ -7574,7 +7615,7 @@ var require__equalObjects = __commonJS({ "../../node_modules/lodash/_equalObject
|
|
|
7574
7615
|
//#endregion
|
|
7575
7616
|
//#region ../../node_modules/lodash/_baseIsEqualDeep.js
|
|
7576
7617
|
var require__baseIsEqualDeep = __commonJS({ "../../node_modules/lodash/_baseIsEqualDeep.js"(exports, module) {
|
|
7577
|
-
var Stack$1 = require__Stack(), equalArrays = require__equalArrays(), equalByTag = require__equalByTag(), equalObjects = require__equalObjects(), getTag = require__getTag(), isArray$
|
|
7618
|
+
var Stack$1 = require__Stack(), equalArrays = require__equalArrays(), equalByTag = require__equalByTag(), equalObjects = require__equalObjects(), getTag = require__getTag(), isArray$5 = require_isArray(), isBuffer = require_isBuffer(), isTypedArray = require_isTypedArray();
|
|
7578
7619
|
/** Used to compose bitmasks for value comparisons. */
|
|
7579
7620
|
var COMPARE_PARTIAL_FLAG$2 = 1;
|
|
7580
7621
|
/** `Object#toString` result references. */
|
|
@@ -7598,7 +7639,7 @@ var require__baseIsEqualDeep = __commonJS({ "../../node_modules/lodash/_baseIsEq
|
|
|
7598
7639
|
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
|
7599
7640
|
*/
|
|
7600
7641
|
function baseIsEqualDeep$1(object, other, bitmask, customizer, equalFunc, stack) {
|
|
7601
|
-
var objIsArr = isArray$
|
|
7642
|
+
var objIsArr = isArray$5(object), othIsArr = isArray$5(other), objTag = objIsArr ? arrayTag : getTag(object), othTag = othIsArr ? arrayTag : getTag(other);
|
|
7602
7643
|
objTag = objTag == argsTag ? objectTag : objTag;
|
|
7603
7644
|
othTag = othTag == argsTag ? objectTag : othTag;
|
|
7604
7645
|
var objIsObj = objTag == objectTag, othIsObj = othTag == objectTag, isSameTag = objTag == othTag;
|
|
@@ -7834,7 +7875,7 @@ var require__baseHasIn = __commonJS({ "../../node_modules/lodash/_baseHasIn.js"(
|
|
|
7834
7875
|
//#endregion
|
|
7835
7876
|
//#region ../../node_modules/lodash/_hasPath.js
|
|
7836
7877
|
var require__hasPath = __commonJS({ "../../node_modules/lodash/_hasPath.js"(exports, module) {
|
|
7837
|
-
var castPath = require__castPath(), isArguments = require_isArguments(), isArray$
|
|
7878
|
+
var castPath = require__castPath(), isArguments = require_isArguments(), isArray$4 = require_isArray(), isIndex = require__isIndex(), isLength = require_isLength(), toKey$2 = require__toKey();
|
|
7838
7879
|
/**
|
|
7839
7880
|
* Checks if `path` exists on `object`.
|
|
7840
7881
|
*
|
|
@@ -7854,7 +7895,7 @@ var require__hasPath = __commonJS({ "../../node_modules/lodash/_hasPath.js"(expo
|
|
|
7854
7895
|
}
|
|
7855
7896
|
if (result || ++index != length) return result;
|
|
7856
7897
|
length = object == null ? 0 : object.length;
|
|
7857
|
-
return !!length && isLength(length) && isIndex(key, length) && (isArray$
|
|
7898
|
+
return !!length && isLength(length) && isIndex(key, length) && (isArray$4(object) || isArguments(object));
|
|
7858
7899
|
}
|
|
7859
7900
|
module.exports = hasPath$1;
|
|
7860
7901
|
} });
|
|
@@ -7991,7 +8032,7 @@ var require_property = __commonJS({ "../../node_modules/lodash/property.js"(expo
|
|
|
7991
8032
|
//#endregion
|
|
7992
8033
|
//#region ../../node_modules/lodash/_baseIteratee.js
|
|
7993
8034
|
var require__baseIteratee = __commonJS({ "../../node_modules/lodash/_baseIteratee.js"(exports, module) {
|
|
7994
|
-
var baseMatches = require__baseMatches(), baseMatchesProperty = require__baseMatchesProperty(), identity$1 = require_identity(), isArray$
|
|
8035
|
+
var baseMatches = require__baseMatches(), baseMatchesProperty = require__baseMatchesProperty(), identity$1 = require_identity(), isArray$3 = require_isArray(), property = require_property();
|
|
7995
8036
|
/**
|
|
7996
8037
|
* The base implementation of `_.iteratee`.
|
|
7997
8038
|
*
|
|
@@ -7999,13 +8040,13 @@ var require__baseIteratee = __commonJS({ "../../node_modules/lodash/_baseIterate
|
|
|
7999
8040
|
* @param {*} [value=_.identity] The value to convert to an iteratee.
|
|
8000
8041
|
* @returns {Function} Returns the iteratee.
|
|
8001
8042
|
*/
|
|
8002
|
-
function baseIteratee$
|
|
8043
|
+
function baseIteratee$1(value) {
|
|
8003
8044
|
if (typeof value == "function") return value;
|
|
8004
8045
|
if (value == null) return identity$1;
|
|
8005
|
-
if (typeof value == "object") return isArray$
|
|
8046
|
+
if (typeof value == "object") return isArray$3(value) ? baseMatchesProperty(value[0], value[1]) : baseMatches(value);
|
|
8006
8047
|
return property(value);
|
|
8007
8048
|
}
|
|
8008
|
-
module.exports = baseIteratee$
|
|
8049
|
+
module.exports = baseIteratee$1;
|
|
8009
8050
|
} });
|
|
8010
8051
|
|
|
8011
8052
|
//#endregion
|
|
@@ -8062,14 +8103,14 @@ var require__baseEach = __commonJS({ "../../node_modules/lodash/_baseEach.js"(ex
|
|
|
8062
8103
|
* @param {Function} iteratee The function invoked per iteration.
|
|
8063
8104
|
* @returns {Array|Object} Returns `collection`.
|
|
8064
8105
|
*/
|
|
8065
|
-
var baseEach$
|
|
8066
|
-
module.exports = baseEach$
|
|
8106
|
+
var baseEach$1 = createBaseEach(baseForOwn);
|
|
8107
|
+
module.exports = baseEach$1;
|
|
8067
8108
|
} });
|
|
8068
8109
|
|
|
8069
8110
|
//#endregion
|
|
8070
8111
|
//#region ../../node_modules/lodash/_baseMap.js
|
|
8071
8112
|
var require__baseMap = __commonJS({ "../../node_modules/lodash/_baseMap.js"(exports, module) {
|
|
8072
|
-
var baseEach
|
|
8113
|
+
var baseEach = require__baseEach(), isArrayLike = require_isArrayLike();
|
|
8073
8114
|
/**
|
|
8074
8115
|
* The base implementation of `_.map` without support for iteratee shorthands.
|
|
8075
8116
|
*
|
|
@@ -8080,7 +8121,7 @@ var require__baseMap = __commonJS({ "../../node_modules/lodash/_baseMap.js"(expo
|
|
|
8080
8121
|
*/
|
|
8081
8122
|
function baseMap$1(collection, iteratee) {
|
|
8082
8123
|
var index = -1, result = isArrayLike(collection) ? Array(collection.length) : [];
|
|
8083
|
-
baseEach
|
|
8124
|
+
baseEach(collection, function(value, key, collection$1) {
|
|
8084
8125
|
result[++index] = iteratee(value, key, collection$1);
|
|
8085
8126
|
});
|
|
8086
8127
|
return result;
|
|
@@ -8170,7 +8211,7 @@ var require__compareMultiple = __commonJS({ "../../node_modules/lodash/_compareM
|
|
|
8170
8211
|
//#endregion
|
|
8171
8212
|
//#region ../../node_modules/lodash/_baseOrderBy.js
|
|
8172
8213
|
var require__baseOrderBy = __commonJS({ "../../node_modules/lodash/_baseOrderBy.js"(exports, module) {
|
|
8173
|
-
var arrayMap = require__arrayMap(), baseGet = require__baseGet(), baseIteratee
|
|
8214
|
+
var arrayMap = require__arrayMap(), baseGet = require__baseGet(), baseIteratee = require__baseIteratee(), baseMap = require__baseMap(), baseSortBy = require__baseSortBy(), baseUnary = require__baseUnary(), compareMultiple = require__compareMultiple(), identity = require_identity(), isArray$2 = require_isArray();
|
|
8174
8215
|
/**
|
|
8175
8216
|
* The base implementation of `_.orderBy` without param guards.
|
|
8176
8217
|
*
|
|
@@ -8182,14 +8223,14 @@ var require__baseOrderBy = __commonJS({ "../../node_modules/lodash/_baseOrderBy.
|
|
|
8182
8223
|
*/
|
|
8183
8224
|
function baseOrderBy$1(collection, iteratees, orders) {
|
|
8184
8225
|
if (iteratees.length) iteratees = arrayMap(iteratees, function(iteratee) {
|
|
8185
|
-
if (isArray$
|
|
8226
|
+
if (isArray$2(iteratee)) return function(value) {
|
|
8186
8227
|
return baseGet(value, iteratee.length === 1 ? iteratee[0] : iteratee);
|
|
8187
8228
|
};
|
|
8188
8229
|
return iteratee;
|
|
8189
8230
|
});
|
|
8190
8231
|
else iteratees = [identity];
|
|
8191
8232
|
var index = -1;
|
|
8192
|
-
iteratees = arrayMap(iteratees, baseUnary(baseIteratee
|
|
8233
|
+
iteratees = arrayMap(iteratees, baseUnary(baseIteratee));
|
|
8193
8234
|
var result = baseMap(collection, function(value, key, collection$1) {
|
|
8194
8235
|
var criteria = arrayMap(iteratees, function(iteratee) {
|
|
8195
8236
|
return iteratee(value);
|
|
@@ -8210,7 +8251,7 @@ var require__baseOrderBy = __commonJS({ "../../node_modules/lodash/_baseOrderBy.
|
|
|
8210
8251
|
//#endregion
|
|
8211
8252
|
//#region ../../node_modules/lodash/orderBy.js
|
|
8212
8253
|
var require_orderBy = __commonJS({ "../../node_modules/lodash/orderBy.js"(exports, module) {
|
|
8213
|
-
var baseOrderBy = require__baseOrderBy(), isArray$
|
|
8254
|
+
var baseOrderBy = require__baseOrderBy(), isArray$1 = require_isArray();
|
|
8214
8255
|
/**
|
|
8215
8256
|
* This method is like `_.sortBy` except that it allows specifying the sort
|
|
8216
8257
|
* orders of the iteratees to sort by. If `orders` is unspecified, all values
|
|
@@ -8242,9 +8283,9 @@ var require_orderBy = __commonJS({ "../../node_modules/lodash/orderBy.js"(export
|
|
|
8242
8283
|
*/
|
|
8243
8284
|
function orderBy(collection, iteratees, orders, guard) {
|
|
8244
8285
|
if (collection == null) return [];
|
|
8245
|
-
if (!isArray$
|
|
8286
|
+
if (!isArray$1(iteratees)) iteratees = iteratees == null ? [] : [iteratees];
|
|
8246
8287
|
orders = guard ? void 0 : orders;
|
|
8247
|
-
if (!isArray$
|
|
8288
|
+
if (!isArray$1(orders)) orders = orders == null ? [] : [orders];
|
|
8248
8289
|
return baseOrderBy(collection, iteratees, orders);
|
|
8249
8290
|
}
|
|
8250
8291
|
module.exports = orderBy;
|
|
@@ -8312,8 +8353,7 @@ var WeaveGroupsManager = class {
|
|
|
8312
8353
|
tr.hide();
|
|
8313
8354
|
selectionPlugin.setSelectedNodes([]);
|
|
8314
8355
|
}
|
|
8315
|
-
|
|
8316
|
-
if (typeof parentNodeId === "undefined") parentNodeId = WEAVE_NODE_LAYER_ID;
|
|
8356
|
+
const parentNodeId = parentId ?? WEAVE_NODE_LAYER_ID;
|
|
8317
8357
|
const parentLayer = stage.findOne(`#${parentNodeId}`);
|
|
8318
8358
|
const groupId = v4_default();
|
|
8319
8359
|
const groupInstance = new Konva.Group({
|
|
@@ -9442,7 +9482,7 @@ var WeaveRegisterManager = class {
|
|
|
9442
9482
|
|
|
9443
9483
|
//#endregion
|
|
9444
9484
|
//#region package.json
|
|
9445
|
-
var version = "5.0.0-SNAPSHOT.
|
|
9485
|
+
var version = "5.0.0-SNAPSHOT.377.1";
|
|
9446
9486
|
|
|
9447
9487
|
//#endregion
|
|
9448
9488
|
//#region src/managers/setup.ts
|
|
@@ -9669,121 +9709,161 @@ var WeaveStoreManager = class {
|
|
|
9669
9709
|
};
|
|
9670
9710
|
|
|
9671
9711
|
//#endregion
|
|
9672
|
-
//#region
|
|
9673
|
-
var
|
|
9674
|
-
|
|
9675
|
-
|
|
9676
|
-
|
|
9677
|
-
|
|
9678
|
-
|
|
9679
|
-
|
|
9680
|
-
|
|
9681
|
-
|
|
9682
|
-
|
|
9683
|
-
|
|
9684
|
-
|
|
9685
|
-
|
|
9686
|
-
|
|
9712
|
+
//#region src/managers/export/export.ts
|
|
9713
|
+
var WeaveExportManager = class {
|
|
9714
|
+
constructor(instance) {
|
|
9715
|
+
this.instance = instance;
|
|
9716
|
+
this.logger = this.instance.getChildLogger("export-manager");
|
|
9717
|
+
this.logger.debug("Export manager created");
|
|
9718
|
+
}
|
|
9719
|
+
parseExportOptions(options) {
|
|
9720
|
+
return {
|
|
9721
|
+
format: options.format ?? WEAVE_EXPORT_FORMATS.PNG,
|
|
9722
|
+
padding: options.padding ?? 0,
|
|
9723
|
+
pixelRatio: options.pixelRatio ?? 1,
|
|
9724
|
+
backgroundColor: options.backgroundColor ?? WEAVE_EXPORT_BACKGROUND_COLOR
|
|
9725
|
+
};
|
|
9726
|
+
}
|
|
9727
|
+
saveAndDisablePlugins() {
|
|
9728
|
+
const nodesSelectionPluginPrev = this.getNodesSelectionPlugin()?.isEnabled();
|
|
9729
|
+
const nodesStageGridPluginPrev = this.getStageGridPlugin()?.isEnabled();
|
|
9730
|
+
this.getNodesSelectionPlugin()?.disable();
|
|
9731
|
+
this.getStageGridPlugin()?.disable();
|
|
9732
|
+
return {
|
|
9733
|
+
nodesSelectionPluginPrev,
|
|
9734
|
+
nodesStageGridPluginPrev
|
|
9735
|
+
};
|
|
9736
|
+
}
|
|
9737
|
+
restorePlugins(nodesSelectionPluginPrev, nodesStageGridPluginPrev) {
|
|
9738
|
+
if (nodesSelectionPluginPrev) this.getNodesSelectionPlugin()?.enable();
|
|
9739
|
+
if (nodesStageGridPluginPrev) this.getStageGridPlugin()?.enable();
|
|
9740
|
+
}
|
|
9741
|
+
saveAndResetStage(resetPosition = false) {
|
|
9742
|
+
const stage = this.instance.getStage();
|
|
9743
|
+
const originalPosition = {
|
|
9744
|
+
x: stage.x(),
|
|
9745
|
+
y: stage.y()
|
|
9746
|
+
};
|
|
9747
|
+
const originalScale = {
|
|
9748
|
+
x: stage.scaleX(),
|
|
9749
|
+
y: stage.scaleY()
|
|
9750
|
+
};
|
|
9751
|
+
stage.scale({
|
|
9752
|
+
x: 1,
|
|
9753
|
+
y: 1
|
|
9687
9754
|
});
|
|
9688
|
-
|
|
9755
|
+
if (resetPosition) stage.position({
|
|
9756
|
+
x: 0,
|
|
9757
|
+
y: 0
|
|
9758
|
+
});
|
|
9759
|
+
return {
|
|
9760
|
+
stage,
|
|
9761
|
+
originalPosition,
|
|
9762
|
+
originalScale
|
|
9763
|
+
};
|
|
9689
9764
|
}
|
|
9690
|
-
|
|
9691
|
-
|
|
9692
|
-
|
|
9693
|
-
|
|
9694
|
-
|
|
9695
|
-
|
|
9696
|
-
|
|
9697
|
-
|
|
9698
|
-
|
|
9699
|
-
|
|
9700
|
-
|
|
9701
|
-
|
|
9702
|
-
|
|
9703
|
-
|
|
9704
|
-
|
|
9705
|
-
|
|
9706
|
-
|
|
9707
|
-
|
|
9708
|
-
|
|
9709
|
-
|
|
9710
|
-
|
|
9711
|
-
|
|
9712
|
-
|
|
9713
|
-
|
|
9714
|
-
|
|
9715
|
-
|
|
9716
|
-
|
|
9717
|
-
|
|
9718
|
-
|
|
9719
|
-
|
|
9720
|
-
|
|
9721
|
-
|
|
9722
|
-
|
|
9723
|
-
|
|
9724
|
-
|
|
9725
|
-
|
|
9726
|
-
|
|
9727
|
-
|
|
9728
|
-
|
|
9765
|
+
restoreStage(stage, originalPosition, originalScale) {
|
|
9766
|
+
stage.position(originalPosition);
|
|
9767
|
+
stage.scale(originalScale);
|
|
9768
|
+
stage.batchDraw();
|
|
9769
|
+
}
|
|
9770
|
+
buildNodesExportGroup(nodes, boundingNodes, stage, mainLayer, padding, backgroundColor) {
|
|
9771
|
+
const bounds = getExportBoundingBox(boundingNodes(nodes));
|
|
9772
|
+
const scaleX = stage.scaleX();
|
|
9773
|
+
const scaleY = stage.scaleY();
|
|
9774
|
+
const unscaledBounds = {
|
|
9775
|
+
x: bounds.x / scaleX,
|
|
9776
|
+
y: bounds.y / scaleY,
|
|
9777
|
+
width: bounds.width / scaleX,
|
|
9778
|
+
height: bounds.height / scaleY
|
|
9779
|
+
};
|
|
9780
|
+
const exportGroup = new Konva.Group();
|
|
9781
|
+
const background = new Konva.Rect({
|
|
9782
|
+
x: unscaledBounds.x - padding,
|
|
9783
|
+
y: unscaledBounds.y - padding,
|
|
9784
|
+
width: unscaledBounds.width + 2 * padding,
|
|
9785
|
+
height: unscaledBounds.height + 2 * padding,
|
|
9786
|
+
strokeWidth: 0,
|
|
9787
|
+
fill: backgroundColor
|
|
9788
|
+
});
|
|
9789
|
+
exportGroup.add(background);
|
|
9790
|
+
for (const node of nodes) {
|
|
9791
|
+
const clonedNode = node.clone({ id: v4_default() });
|
|
9792
|
+
const absPos = node.getAbsolutePosition();
|
|
9793
|
+
clonedNode.absolutePosition({
|
|
9794
|
+
x: absPos.x / scaleX,
|
|
9795
|
+
y: absPos.y / scaleY
|
|
9796
|
+
});
|
|
9797
|
+
exportGroup.add(clonedNode);
|
|
9798
|
+
}
|
|
9799
|
+
mainLayer.add(exportGroup);
|
|
9800
|
+
const backgroundRect = background.getClientRect();
|
|
9801
|
+
stage.batchDraw();
|
|
9802
|
+
return {
|
|
9803
|
+
exportGroup,
|
|
9804
|
+
background,
|
|
9805
|
+
backgroundRect
|
|
9729
9806
|
};
|
|
9730
9807
|
}
|
|
9731
|
-
|
|
9732
|
-
|
|
9733
|
-
|
|
9734
|
-
|
|
9735
|
-
|
|
9736
|
-
|
|
9737
|
-
|
|
9738
|
-
|
|
9739
|
-
|
|
9740
|
-
|
|
9741
|
-
|
|
9742
|
-
|
|
9743
|
-
|
|
9744
|
-
|
|
9745
|
-
|
|
9746
|
-
|
|
9747
|
-
|
|
9748
|
-
|
|
9749
|
-
|
|
9750
|
-
|
|
9751
|
-
|
|
9752
|
-
|
|
9753
|
-
|
|
9754
|
-
|
|
9755
|
-
|
|
9756
|
-
|
|
9757
|
-
* _.reject(users, function(o) { return !o.active; });
|
|
9758
|
-
* // => objects for ['fred']
|
|
9759
|
-
*
|
|
9760
|
-
* // The `_.matches` iteratee shorthand.
|
|
9761
|
-
* _.reject(users, { 'age': 40, 'active': true });
|
|
9762
|
-
* // => objects for ['barney']
|
|
9763
|
-
*
|
|
9764
|
-
* // The `_.matchesProperty` iteratee shorthand.
|
|
9765
|
-
* _.reject(users, ['active', false]);
|
|
9766
|
-
* // => objects for ['fred']
|
|
9767
|
-
*
|
|
9768
|
-
* // The `_.property` iteratee shorthand.
|
|
9769
|
-
* _.reject(users, 'active');
|
|
9770
|
-
* // => objects for ['barney']
|
|
9771
|
-
*/
|
|
9772
|
-
function reject(collection, predicate) {
|
|
9773
|
-
var func = isArray$1(collection) ? arrayFilter : baseFilter;
|
|
9774
|
-
return func(collection, negate(baseIteratee(predicate, 3)));
|
|
9808
|
+
buildAreaBackground(area, stage, mainLayer, padding, backgroundColor, relativeToStage = false) {
|
|
9809
|
+
const bounds = area;
|
|
9810
|
+
const scaleX = stage.scaleX();
|
|
9811
|
+
const scaleY = stage.scaleY();
|
|
9812
|
+
const unscaledBounds = {
|
|
9813
|
+
x: bounds.x / scaleX,
|
|
9814
|
+
y: bounds.y / scaleY,
|
|
9815
|
+
width: bounds.width / scaleX,
|
|
9816
|
+
height: bounds.height / scaleY
|
|
9817
|
+
};
|
|
9818
|
+
const background = new Konva.Rect({
|
|
9819
|
+
x: unscaledBounds.x - padding,
|
|
9820
|
+
y: unscaledBounds.y - padding,
|
|
9821
|
+
width: unscaledBounds.width + 2 * padding,
|
|
9822
|
+
height: unscaledBounds.height + 2 * padding,
|
|
9823
|
+
strokeWidth: 0,
|
|
9824
|
+
fill: backgroundColor
|
|
9825
|
+
});
|
|
9826
|
+
mainLayer.add(background);
|
|
9827
|
+
background.moveToBottom();
|
|
9828
|
+
stage.batchDraw();
|
|
9829
|
+
const backgroundRect = relativeToStage ? background.getClientRect({ relativeTo: stage }) : background.getClientRect();
|
|
9830
|
+
return {
|
|
9831
|
+
background,
|
|
9832
|
+
backgroundRect
|
|
9833
|
+
};
|
|
9775
9834
|
}
|
|
9776
|
-
|
|
9777
|
-
|
|
9778
|
-
|
|
9779
|
-
|
|
9780
|
-
|
|
9781
|
-
|
|
9782
|
-
|
|
9783
|
-
|
|
9784
|
-
|
|
9785
|
-
|
|
9786
|
-
|
|
9835
|
+
async renderTiles(source, backgroundRect, format, pixelRatio, quality) {
|
|
9836
|
+
const composites = [];
|
|
9837
|
+
const imageWidth = Math.round(backgroundRect.width);
|
|
9838
|
+
const imageHeight = Math.round(backgroundRect.height);
|
|
9839
|
+
const maxRenderSize = 1920;
|
|
9840
|
+
const cols = Math.ceil(imageWidth / maxRenderSize);
|
|
9841
|
+
const rows = Math.ceil(imageHeight / maxRenderSize);
|
|
9842
|
+
const tileWidth = Math.floor(imageWidth / cols);
|
|
9843
|
+
const tileHeight = Math.floor(imageHeight / rows);
|
|
9844
|
+
for (let y = 0; y < imageHeight; y += tileHeight) for (let x = 0; x < imageWidth; x += tileWidth) {
|
|
9845
|
+
const width = Math.min(tileWidth, imageWidth - x);
|
|
9846
|
+
const height = Math.min(tileHeight, imageHeight - y);
|
|
9847
|
+
const canvas = await source.toCanvas({
|
|
9848
|
+
x: Math.round(backgroundRect.x) + x,
|
|
9849
|
+
y: Math.round(backgroundRect.y) + y,
|
|
9850
|
+
width,
|
|
9851
|
+
height,
|
|
9852
|
+
mimeType: format,
|
|
9853
|
+
pixelRatio,
|
|
9854
|
+
quality
|
|
9855
|
+
});
|
|
9856
|
+
let buffer = null;
|
|
9857
|
+
if (globalThis._weave_serverSideBackend === WEAVE_KONVA_BACKEND.CANVAS) buffer = canvas.toBuffer();
|
|
9858
|
+
if (globalThis._weave_serverSideBackend === WEAVE_KONVA_BACKEND.SKIA) buffer = await canvas.toBuffer();
|
|
9859
|
+
if (!buffer) throw new Error("Failed to generate image buffer");
|
|
9860
|
+
composites.push({
|
|
9861
|
+
top: y * pixelRatio,
|
|
9862
|
+
left: x * pixelRatio,
|
|
9863
|
+
input: buffer
|
|
9864
|
+
});
|
|
9865
|
+
}
|
|
9866
|
+
return { composites };
|
|
9787
9867
|
}
|
|
9788
9868
|
fitKonvaPixelRatio(sw, sh, targetPR = 1, maxArea = 16777216) {
|
|
9789
9869
|
if (sw <= 0 || sh <= 0) return {
|
|
@@ -9894,7 +9974,7 @@ var WeaveExportManager = class {
|
|
|
9894
9974
|
});
|
|
9895
9975
|
}
|
|
9896
9976
|
exportNodesAsBlob(nodes, boundingNodes, options) {
|
|
9897
|
-
return new Promise((resolve) => {
|
|
9977
|
+
return new Promise((resolve, reject) => {
|
|
9898
9978
|
const { format = WEAVE_EXPORT_FORMATS.PNG } = options;
|
|
9899
9979
|
const { stage, mainLayer, originalScale: { scaleX, scaleY } } = this.cloneStageForExport();
|
|
9900
9980
|
if (mainLayer) {
|
|
@@ -9920,7 +10000,7 @@ var WeaveExportManager = class {
|
|
|
9920
10000
|
exportGroup.destroy();
|
|
9921
10001
|
stage.destroy();
|
|
9922
10002
|
if (!blob) {
|
|
9923
|
-
(
|
|
10003
|
+
reject(new Error("Failed to generate image blob"));
|
|
9924
10004
|
return;
|
|
9925
10005
|
}
|
|
9926
10006
|
resolve(blob);
|
|
@@ -9993,7 +10073,7 @@ var WeaveExportManager = class {
|
|
|
9993
10073
|
});
|
|
9994
10074
|
}
|
|
9995
10075
|
exportAreaAsBlob(area, options) {
|
|
9996
|
-
return new Promise((resolve) => {
|
|
10076
|
+
return new Promise((resolve, reject) => {
|
|
9997
10077
|
const { format = WEAVE_EXPORT_FORMATS.PNG } = options;
|
|
9998
10078
|
const { stage, mainLayer, originalScale: { scaleX, scaleY } } = this.cloneStageForExport();
|
|
9999
10079
|
if (mainLayer) {
|
|
@@ -10018,7 +10098,7 @@ var WeaveExportManager = class {
|
|
|
10018
10098
|
callback: (blob) => {
|
|
10019
10099
|
stage.destroy();
|
|
10020
10100
|
if (!blob) {
|
|
10021
|
-
(
|
|
10101
|
+
reject(new Error("Failed to generate image blob"));
|
|
10022
10102
|
return;
|
|
10023
10103
|
}
|
|
10024
10104
|
resolve(blob);
|
|
@@ -10059,178 +10139,44 @@ var WeaveExportManager = class {
|
|
|
10059
10139
|
});
|
|
10060
10140
|
}
|
|
10061
10141
|
async exportNodesServerSide(nodes, boundingNodes, options) {
|
|
10062
|
-
const { format
|
|
10063
|
-
this.
|
|
10064
|
-
this.
|
|
10065
|
-
const stage = this.instance.getStage();
|
|
10142
|
+
const { format, padding, pixelRatio, backgroundColor } = this.parseExportOptions(options);
|
|
10143
|
+
const { nodesSelectionPluginPrev, nodesStageGridPluginPrev } = this.saveAndDisablePlugins();
|
|
10144
|
+
const { stage, originalPosition, originalScale } = this.saveAndResetStage();
|
|
10066
10145
|
const mainLayer = this.instance.getMainLayer();
|
|
10067
10146
|
if (!mainLayer) throw new Error("Main layer not found");
|
|
10068
|
-
const originalPosition = {
|
|
10069
|
-
x: stage.x(),
|
|
10070
|
-
y: stage.y()
|
|
10071
|
-
};
|
|
10072
|
-
const originalScale = {
|
|
10073
|
-
x: stage.scaleX(),
|
|
10074
|
-
y: stage.scaleY()
|
|
10075
|
-
};
|
|
10076
|
-
stage.scale({
|
|
10077
|
-
x: 1,
|
|
10078
|
-
y: 1
|
|
10079
|
-
});
|
|
10080
10147
|
let realNodes = [...nodes];
|
|
10081
|
-
if (nodes.length === 0) realNodes = mainLayer.getChildren().map((node) => node.getAttrs().id ?? "") ?? [];
|
|
10082
|
-
const konvaNodes = [];
|
|
10083
|
-
for (const nodeId of realNodes) {
|
|
10084
|
-
const node = stage.findOne(`#${nodeId}`);
|
|
10085
|
-
if (node) konvaNodes.push(node);
|
|
10086
|
-
}
|
|
10087
|
-
const bounds = getExportBoundingBox(boundingNodes(konvaNodes));
|
|
10088
|
-
const scaleX = stage.scaleX();
|
|
10089
|
-
const scaleY = stage.scaleY();
|
|
10090
|
-
const unscaledBounds = {
|
|
10091
|
-
x: bounds.x / scaleX,
|
|
10092
|
-
y: bounds.y / scaleY,
|
|
10093
|
-
width: bounds.width / scaleX,
|
|
10094
|
-
height: bounds.height / scaleY
|
|
10095
|
-
};
|
|
10096
|
-
const exportGroup = new Konva.Group();
|
|
10097
|
-
const background = new Konva.Rect({
|
|
10098
|
-
x: unscaledBounds.x - padding,
|
|
10099
|
-
y: unscaledBounds.y - padding,
|
|
10100
|
-
width: unscaledBounds.width + 2 * padding,
|
|
10101
|
-
height: unscaledBounds.height + 2 * padding,
|
|
10102
|
-
strokeWidth: 0,
|
|
10103
|
-
fill: backgroundColor
|
|
10104
|
-
});
|
|
10105
|
-
exportGroup.add(background);
|
|
10106
|
-
for (const node of konvaNodes) {
|
|
10107
|
-
const clonedNode = node.clone({ id: v4_default() });
|
|
10108
|
-
const absPos = node.getAbsolutePosition();
|
|
10109
|
-
clonedNode.absolutePosition({
|
|
10110
|
-
x: absPos.x / scaleX,
|
|
10111
|
-
y: absPos.y / scaleY
|
|
10112
|
-
});
|
|
10113
|
-
exportGroup.add(clonedNode);
|
|
10114
|
-
}
|
|
10115
|
-
mainLayer.add(exportGroup);
|
|
10116
|
-
const backgroundRect = background.getClientRect();
|
|
10117
|
-
const composites = [];
|
|
10118
|
-
const imageWidth = Math.round(backgroundRect.width);
|
|
10119
|
-
const imageHeight = Math.round(backgroundRect.height);
|
|
10120
|
-
const maxRenderSize = 1920;
|
|
10121
|
-
const cols = Math.ceil(imageWidth / maxRenderSize);
|
|
10122
|
-
const rows = Math.ceil(imageHeight / maxRenderSize);
|
|
10123
|
-
const tileWidth = Math.floor(imageWidth / cols);
|
|
10124
|
-
const tileHeight = Math.floor(imageHeight / rows);
|
|
10125
|
-
for (let y = 0; y < imageHeight; y += tileHeight) for (let x = 0; x < imageWidth; x += tileWidth) {
|
|
10126
|
-
const width = Math.min(tileWidth, imageWidth - x);
|
|
10127
|
-
const height = Math.min(tileHeight, imageHeight - y);
|
|
10128
|
-
const canvas = await exportGroup.toCanvas({
|
|
10129
|
-
x: Math.round(backgroundRect.x) + x,
|
|
10130
|
-
y: Math.round(backgroundRect.y) + y,
|
|
10131
|
-
width,
|
|
10132
|
-
height,
|
|
10133
|
-
mimeType: format,
|
|
10134
|
-
pixelRatio,
|
|
10135
|
-
quality: options.quality ?? 1
|
|
10136
|
-
});
|
|
10137
|
-
let buffer = null;
|
|
10138
|
-
if (globalThis._weave_serverSideBackend === WEAVE_KONVA_BACKEND.CANVAS) buffer = canvas.toBuffer();
|
|
10139
|
-
if (globalThis._weave_serverSideBackend === WEAVE_KONVA_BACKEND.SKIA) buffer = await canvas.toBuffer();
|
|
10140
|
-
if (!buffer) throw new Error("Failed to generate image buffer");
|
|
10141
|
-
composites.push({
|
|
10142
|
-
top: y * pixelRatio,
|
|
10143
|
-
left: x * pixelRatio,
|
|
10144
|
-
input: buffer
|
|
10145
|
-
});
|
|
10146
|
-
}
|
|
10147
|
-
exportGroup.destroy();
|
|
10148
|
-
stage.position(originalPosition);
|
|
10149
|
-
stage.scale(originalScale);
|
|
10150
|
-
stage.batchDraw();
|
|
10151
|
-
this.getNodesSelectionPlugin()?.enable();
|
|
10152
|
-
this.getStageGridPlugin()?.enable();
|
|
10153
|
-
return {
|
|
10154
|
-
composites,
|
|
10155
|
-
width: imageWidth * pixelRatio,
|
|
10156
|
-
height: imageHeight * pixelRatio
|
|
10157
|
-
};
|
|
10158
|
-
}
|
|
10159
|
-
async exportAreaServerSide(area, options) {
|
|
10160
|
-
const { format = WEAVE_EXPORT_FORMATS.PNG, padding = 0, pixelRatio = 1, backgroundColor = WEAVE_EXPORT_BACKGROUND_COLOR } = options;
|
|
10161
|
-
this.getNodesSelectionPlugin()?.disable();
|
|
10162
|
-
this.getStageGridPlugin()?.disable();
|
|
10163
|
-
const stage = this.instance.getStage();
|
|
10164
|
-
const mainLayer = this.instance.getMainLayer();
|
|
10165
|
-
if (!mainLayer) throw new Error("Main layer not found");
|
|
10166
|
-
const originalPosition = {
|
|
10167
|
-
x: stage.x(),
|
|
10168
|
-
y: stage.y()
|
|
10169
|
-
};
|
|
10170
|
-
const originalScale = {
|
|
10171
|
-
x: stage.scaleX(),
|
|
10172
|
-
y: stage.scaleY()
|
|
10173
|
-
};
|
|
10174
|
-
stage.scale({
|
|
10175
|
-
x: 1,
|
|
10176
|
-
y: 1
|
|
10177
|
-
});
|
|
10178
|
-
const bounds = area;
|
|
10179
|
-
const scaleX = stage.scaleX();
|
|
10180
|
-
const scaleY = stage.scaleY();
|
|
10181
|
-
const unscaledBounds = {
|
|
10182
|
-
x: bounds.x / scaleX,
|
|
10183
|
-
y: bounds.y / scaleY,
|
|
10184
|
-
width: bounds.width / scaleX,
|
|
10185
|
-
height: bounds.height / scaleY
|
|
10186
|
-
};
|
|
10187
|
-
const background = new Konva.Rect({
|
|
10188
|
-
x: unscaledBounds.x - padding,
|
|
10189
|
-
y: unscaledBounds.y - padding,
|
|
10190
|
-
width: unscaledBounds.width + 2 * padding,
|
|
10191
|
-
height: unscaledBounds.height + 2 * padding,
|
|
10192
|
-
strokeWidth: 0,
|
|
10193
|
-
fill: backgroundColor
|
|
10194
|
-
});
|
|
10195
|
-
mainLayer.add(background);
|
|
10196
|
-
background.moveToBottom();
|
|
10197
|
-
const backgroundRect = background.getClientRect({ relativeTo: stage });
|
|
10198
|
-
const composites = [];
|
|
10199
|
-
const imageWidth = Math.round(backgroundRect.width);
|
|
10200
|
-
const imageHeight = Math.round(backgroundRect.height);
|
|
10201
|
-
const maxRenderSize = 1920;
|
|
10202
|
-
const cols = Math.ceil(imageWidth / maxRenderSize);
|
|
10203
|
-
const rows = Math.ceil(imageHeight / maxRenderSize);
|
|
10204
|
-
const tileWidth = Math.floor(imageWidth / cols);
|
|
10205
|
-
const tileHeight = Math.floor(imageHeight / rows);
|
|
10206
|
-
for (let y = 0; y < imageHeight; y += tileHeight) for (let x = 0; x < imageWidth; x += tileWidth) {
|
|
10207
|
-
const width = Math.min(tileWidth, imageWidth - x);
|
|
10208
|
-
const height = Math.min(tileHeight, imageHeight - y);
|
|
10209
|
-
const canvas = await mainLayer.toCanvas({
|
|
10210
|
-
x: Math.round(backgroundRect.x) + x,
|
|
10211
|
-
y: Math.round(backgroundRect.y) + y,
|
|
10212
|
-
width,
|
|
10213
|
-
height,
|
|
10214
|
-
mimeType: format,
|
|
10215
|
-
pixelRatio,
|
|
10216
|
-
quality: options.quality ?? 1
|
|
10217
|
-
});
|
|
10218
|
-
let buffer = null;
|
|
10219
|
-
if (globalThis._weave_serverSideBackend === WEAVE_KONVA_BACKEND.CANVAS) buffer = canvas.toBuffer();
|
|
10220
|
-
if (globalThis._weave_serverSideBackend === WEAVE_KONVA_BACKEND.SKIA) buffer = await canvas.toBuffer();
|
|
10221
|
-
if (!buffer) throw new Error("Failed to generate image buffer");
|
|
10222
|
-
composites.push({
|
|
10223
|
-
top: y * pixelRatio,
|
|
10224
|
-
left: x * pixelRatio,
|
|
10225
|
-
input: buffer
|
|
10226
|
-
});
|
|
10148
|
+
if (nodes.length === 0) realNodes = mainLayer.getChildren().map((node) => node.getAttrs().id ?? "") ?? [];
|
|
10149
|
+
const konvaNodes = [];
|
|
10150
|
+
for (const nodeId of realNodes) {
|
|
10151
|
+
const node = stage.findOne(`#${nodeId}`);
|
|
10152
|
+
if (node) konvaNodes.push(node);
|
|
10227
10153
|
}
|
|
10154
|
+
const { exportGroup, backgroundRect } = this.buildNodesExportGroup(konvaNodes, boundingNodes, stage, mainLayer, padding, backgroundColor);
|
|
10155
|
+
const { composites } = await this.renderTiles(exportGroup, backgroundRect, format, pixelRatio, options.quality ?? 1);
|
|
10156
|
+
const imageWidth = Math.round(backgroundRect.width);
|
|
10157
|
+
const imageHeight = Math.round(backgroundRect.height);
|
|
10158
|
+
exportGroup.destroy();
|
|
10159
|
+
this.restoreStage(stage, originalPosition, originalScale);
|
|
10160
|
+
this.restorePlugins(nodesSelectionPluginPrev, nodesStageGridPluginPrev);
|
|
10161
|
+
return {
|
|
10162
|
+
composites,
|
|
10163
|
+
width: imageWidth * pixelRatio,
|
|
10164
|
+
height: imageHeight * pixelRatio
|
|
10165
|
+
};
|
|
10166
|
+
}
|
|
10167
|
+
async exportAreaServerSide(area, options) {
|
|
10168
|
+
const { format, padding, pixelRatio, backgroundColor } = this.parseExportOptions(options);
|
|
10169
|
+
const { nodesSelectionPluginPrev, nodesStageGridPluginPrev } = this.saveAndDisablePlugins();
|
|
10170
|
+
const { stage, originalPosition, originalScale } = this.saveAndResetStage();
|
|
10171
|
+
const mainLayer = this.instance.getMainLayer();
|
|
10172
|
+
if (!mainLayer) throw new Error("Main layer not found");
|
|
10173
|
+
const { background, backgroundRect } = this.buildAreaBackground(area, stage, mainLayer, padding, backgroundColor, true);
|
|
10174
|
+
const { composites } = await this.renderTiles(mainLayer, backgroundRect, format, pixelRatio, options.quality ?? 1);
|
|
10175
|
+
const imageWidth = Math.round(backgroundRect.width);
|
|
10176
|
+
const imageHeight = Math.round(backgroundRect.height);
|
|
10228
10177
|
background.destroy();
|
|
10229
|
-
|
|
10230
|
-
|
|
10231
|
-
stage.batchDraw();
|
|
10232
|
-
this.getNodesSelectionPlugin()?.enable();
|
|
10233
|
-
this.getStageGridPlugin()?.enable();
|
|
10178
|
+
this.restoreStage(stage, originalPosition, originalScale);
|
|
10179
|
+
this.restorePlugins(nodesSelectionPluginPrev, nodesStageGridPluginPrev);
|
|
10234
10180
|
return {
|
|
10235
10181
|
composites,
|
|
10236
10182
|
width: imageWidth * pixelRatio,
|
|
@@ -10258,10 +10204,10 @@ var WeaveExportManager = class {
|
|
|
10258
10204
|
return gridPlugin;
|
|
10259
10205
|
}
|
|
10260
10206
|
blobToDataURL(blob) {
|
|
10261
|
-
return new Promise((resolve, reject
|
|
10207
|
+
return new Promise((resolve, reject) => {
|
|
10262
10208
|
const reader = new FileReader();
|
|
10263
10209
|
reader.onloadend = () => resolve(reader.result);
|
|
10264
|
-
reader.onerror = () => reject
|
|
10210
|
+
reader.onerror = () => reject(new Error("Failed to convert blob to data URL"));
|
|
10265
10211
|
reader.readAsDataURL(blob);
|
|
10266
10212
|
});
|
|
10267
10213
|
}
|
|
@@ -11508,6 +11454,7 @@ var Weave = class {
|
|
|
11508
11454
|
return this.dragAndDropManager.getDragProperties();
|
|
11509
11455
|
}
|
|
11510
11456
|
getEventsController() {
|
|
11457
|
+
if (!this.eventsController) throw new Error("Events controller not initialized");
|
|
11511
11458
|
return this.eventsController;
|
|
11512
11459
|
}
|
|
11513
11460
|
getHooks() {
|
|
@@ -11526,14 +11473,14 @@ var Weave = class {
|
|
|
11526
11473
|
//#endregion
|
|
11527
11474
|
//#region src/utils/image.ts
|
|
11528
11475
|
function loadImageSource(image, options) {
|
|
11529
|
-
return new Promise((resolve, reject
|
|
11476
|
+
return new Promise((resolve, reject) => {
|
|
11530
11477
|
const { crossOrigin } = mergeExceptArrays({ crossOrigin: "anonymous" }, options);
|
|
11531
11478
|
const reader = new FileReader();
|
|
11532
11479
|
reader.onloadend = () => {
|
|
11533
11480
|
const imageSource = Konva.Util.createImageElement();
|
|
11534
11481
|
imageSource.crossOrigin = crossOrigin;
|
|
11535
11482
|
imageSource.onerror = () => {
|
|
11536
|
-
reject
|
|
11483
|
+
reject(new Error("Failed to load image source"));
|
|
11537
11484
|
};
|
|
11538
11485
|
imageSource.onload = async () => {
|
|
11539
11486
|
resolve(imageSource);
|
|
@@ -11541,7 +11488,7 @@ function loadImageSource(image, options) {
|
|
|
11541
11488
|
imageSource.src = reader.result;
|
|
11542
11489
|
};
|
|
11543
11490
|
reader.onerror = () => {
|
|
11544
|
-
reject
|
|
11491
|
+
reject(new Error("Failed to read image file"));
|
|
11545
11492
|
};
|
|
11546
11493
|
reader.readAsDataURL(image);
|
|
11547
11494
|
});
|
|
@@ -11562,12 +11509,12 @@ async function downscaleImageFile(file, ratio) {
|
|
|
11562
11509
|
});
|
|
11563
11510
|
}
|
|
11564
11511
|
function getImageSizeFromFile(file) {
|
|
11565
|
-
return new Promise((resolve, reject
|
|
11512
|
+
return new Promise((resolve, reject) => {
|
|
11566
11513
|
const img = new Image();
|
|
11567
11514
|
const url = URL.createObjectURL(file);
|
|
11568
11515
|
img.onload = () => {
|
|
11569
11516
|
if (img.naturalWidth === 0) {
|
|
11570
|
-
reject
|
|
11517
|
+
reject(new Error("Invalid image", { cause: "InvalidImage" }));
|
|
11571
11518
|
return;
|
|
11572
11519
|
}
|
|
11573
11520
|
resolve({
|
|
@@ -11577,7 +11524,7 @@ function getImageSizeFromFile(file) {
|
|
|
11577
11524
|
URL.revokeObjectURL(url);
|
|
11578
11525
|
};
|
|
11579
11526
|
img.onerror = () => {
|
|
11580
|
-
reject
|
|
11527
|
+
reject(new Error("Invalid image", { cause: "InvalidImage" }));
|
|
11581
11528
|
};
|
|
11582
11529
|
img.src = url;
|
|
11583
11530
|
});
|
|
@@ -11592,7 +11539,7 @@ function getDownscaleRatio(width, height, options) {
|
|
|
11592
11539
|
return Math.min(widthRatio, heightRatio, 1);
|
|
11593
11540
|
}
|
|
11594
11541
|
const downscaleImageFromURL = (url, options) => {
|
|
11595
|
-
return new Promise((resolve, reject
|
|
11542
|
+
return new Promise((resolve, reject) => {
|
|
11596
11543
|
const { type, crossOrigin, maxWidth, maxHeight } = mergeExceptArrays({
|
|
11597
11544
|
type: "image/png",
|
|
11598
11545
|
crossOrigin: "anonymous",
|
|
@@ -11603,7 +11550,7 @@ const downscaleImageFromURL = (url, options) => {
|
|
|
11603
11550
|
img.crossOrigin = crossOrigin;
|
|
11604
11551
|
img.onload = () => {
|
|
11605
11552
|
if (img.naturalWidth === 0) {
|
|
11606
|
-
reject
|
|
11553
|
+
reject(new Error("Invalid image", { cause: "InvalidImage" }));
|
|
11607
11554
|
return;
|
|
11608
11555
|
}
|
|
11609
11556
|
const ratio = Math.min(maxWidth / img.width, maxHeight / img.height, 1);
|
|
@@ -11619,7 +11566,7 @@ const downscaleImageFromURL = (url, options) => {
|
|
|
11619
11566
|
resolve(dataURL);
|
|
11620
11567
|
};
|
|
11621
11568
|
img.onerror = () => {
|
|
11622
|
-
reject
|
|
11569
|
+
reject(new Error("Invalid image", { cause: "InvalidImage" }));
|
|
11623
11570
|
};
|
|
11624
11571
|
img.src = url;
|
|
11625
11572
|
});
|
|
@@ -11736,10 +11683,10 @@ var WeaveStageNode = class extends WeaveNode {
|
|
|
11736
11683
|
container.setAttribute("tabindex", "0");
|
|
11737
11684
|
stage.container().addEventListener("focus", () => {
|
|
11738
11685
|
this.stageFocused = true;
|
|
11739
|
-
}, { signal: this.instance.getEventsController()
|
|
11686
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
11740
11687
|
stage.container().addEventListener("blur", () => {
|
|
11741
11688
|
this.stageFocused = false;
|
|
11742
|
-
}, { signal: this.instance.getEventsController()
|
|
11689
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
11743
11690
|
}
|
|
11744
11691
|
Konva.Stage.prototype.mode = function(mode) {
|
|
11745
11692
|
if (typeof mode !== "undefined") this._mode = mode;
|
|
@@ -11806,7 +11753,7 @@ var WeaveStageNode = class extends WeaveNode {
|
|
|
11806
11753
|
const selectedNode = transformer.nodes()[0];
|
|
11807
11754
|
selectedNode.fire("onCmdCtrlPressed");
|
|
11808
11755
|
}
|
|
11809
|
-
}, { signal: this.instance.getEventsController()
|
|
11756
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
11810
11757
|
window.addEventListener("keyup", (e) => {
|
|
11811
11758
|
if (!(e.ctrlKey || e.metaKey)) {
|
|
11812
11759
|
this.instance.getStage().container().style.cursor = "default";
|
|
@@ -11816,7 +11763,7 @@ var WeaveStageNode = class extends WeaveNode {
|
|
|
11816
11763
|
const selectedNode = transformer.nodes()[0];
|
|
11817
11764
|
selectedNode.fire("onCmdCtrlReleased");
|
|
11818
11765
|
}
|
|
11819
|
-
}, { signal: this.instance.getEventsController()
|
|
11766
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
11820
11767
|
this.globalEventsInitialized = true;
|
|
11821
11768
|
}
|
|
11822
11769
|
isOnlyCtrlOrMeta(event) {
|
|
@@ -12724,7 +12671,8 @@ const WEAVE_STAGE_TEXT_EDITION_MODE = "text-edition";
|
|
|
12724
12671
|
const WEAVE_TEXT_NODE_DEFAULT_CONFIG = {
|
|
12725
12672
|
transform: { ...WEAVE_NODES_SELECTION_DEFAULT_CONFIG.selection },
|
|
12726
12673
|
outline: { enabled: false },
|
|
12727
|
-
cursor: { color: "#000000" }
|
|
12674
|
+
cursor: { color: "#000000" },
|
|
12675
|
+
edition: { borderSize: 2 }
|
|
12728
12676
|
};
|
|
12729
12677
|
const TEXT_LAYOUT = {
|
|
12730
12678
|
["SMART"]: "smart",
|
|
@@ -12782,7 +12730,7 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
12782
12730
|
onAdd() {
|
|
12783
12731
|
if (!this.instance.isServerSide() && !this.keyPressHandler) {
|
|
12784
12732
|
this.keyPressHandler = this.handleKeyPress.bind(this);
|
|
12785
|
-
window.addEventListener("keypress", this.keyPressHandler, { signal: this.instance.getEventsController()
|
|
12733
|
+
window.addEventListener("keypress", this.keyPressHandler, { signal: this.instance.getEventsController().signal });
|
|
12786
12734
|
}
|
|
12787
12735
|
}
|
|
12788
12736
|
onRender(props) {
|
|
@@ -12941,7 +12889,7 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
12941
12889
|
});
|
|
12942
12890
|
if (!this.instance.isServerSide() && !this.keyPressHandler) {
|
|
12943
12891
|
this.keyPressHandler = this.handleKeyPress.bind(this);
|
|
12944
|
-
window.addEventListener("keypress", this.keyPressHandler, { signal: this.instance.getEventsController()
|
|
12892
|
+
window.addEventListener("keypress", this.keyPressHandler, { signal: this.instance.getEventsController().signal });
|
|
12945
12893
|
}
|
|
12946
12894
|
return text;
|
|
12947
12895
|
}
|
|
@@ -13020,7 +12968,8 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
13020
12968
|
if (!this.textArea || !this.textAreaContainer) return;
|
|
13021
12969
|
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL || textNode.getAttrs().layout === TEXT_LAYOUT.SMART && !textNode.getAttrs().smartFixedWidth) {
|
|
13022
12970
|
const { width: textAreaWidth } = this.textRenderedSize(this.textArea.value, textNode);
|
|
13023
|
-
const
|
|
12971
|
+
const borderSize = this.config.edition.borderSize;
|
|
12972
|
+
const width = (textAreaWidth + borderSize * 2) * textNode.getAbsoluteScale().x / this.instance.getStage().scaleX();
|
|
13024
12973
|
this.textAreaContainer.style.width = width + "px";
|
|
13025
12974
|
}
|
|
13026
12975
|
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT || textNode.getAttrs().layout === TEXT_LAYOUT.SMART) {
|
|
@@ -13119,13 +13068,15 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
13119
13068
|
this.textAreaContainer.style.top = position.y * upscaleScale + "px";
|
|
13120
13069
|
this.textAreaContainer.style.left = position.x * upscaleScale + "px";
|
|
13121
13070
|
if (textNode.getAttrs().layout === TEXT_LAYOUT.SMART && !textNode.getAttrs().smartFixedWidth) {
|
|
13071
|
+
const borderSize$1 = this.config.edition.borderSize;
|
|
13122
13072
|
const rect = textNode.getClientRect({ relativeTo: stage });
|
|
13123
|
-
this.textAreaContainer.style.width = (rect.width + 2) * textNode.getAbsoluteScale().x + "px";
|
|
13073
|
+
this.textAreaContainer.style.width = (rect.width + borderSize$1 * 2) * textNode.getAbsoluteScale().x + "px";
|
|
13124
13074
|
this.textAreaContainer.style.height = (textNode.height() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + "px";
|
|
13125
13075
|
}
|
|
13126
13076
|
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL) {
|
|
13077
|
+
const borderSize$1 = this.config.edition.borderSize;
|
|
13127
13078
|
const rect = textNode.getClientRect({ relativeTo: stage });
|
|
13128
|
-
this.textAreaContainer.style.width = (rect.width + 2) * textNode.getAbsoluteScale().x + "px";
|
|
13079
|
+
this.textAreaContainer.style.width = (rect.width + borderSize$1 * 2) * textNode.getAbsoluteScale().x + "px";
|
|
13129
13080
|
this.textAreaContainer.style.height = (textNode.height() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + "px";
|
|
13130
13081
|
}
|
|
13131
13082
|
if (textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT || textNode.getAttrs().layout === TEXT_LAYOUT.SMART && textNode.getAttrs().smartFixedWidth) {
|
|
@@ -13138,7 +13089,9 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
13138
13089
|
this.textAreaContainer.style.width = (textNode.width() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + "px";
|
|
13139
13090
|
this.textAreaContainer.style.height = (textNode.height() - textNode.padding() * 2) * textNode.getAbsoluteScale().x + "px";
|
|
13140
13091
|
}
|
|
13141
|
-
this.
|
|
13092
|
+
const size = this.textRenderedSize(textNode.text(), textNode);
|
|
13093
|
+
const borderSize = this.config.edition.borderSize;
|
|
13094
|
+
this.textAreaContainer.style.border = `solid ${borderSize}px #1e40af`;
|
|
13142
13095
|
this.textArea.style.position = "absolute";
|
|
13143
13096
|
this.textArea.style.top = "0px";
|
|
13144
13097
|
this.textArea.style.left = "0px";
|
|
@@ -13147,11 +13100,12 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
13147
13100
|
this.textArea.style.scrollBehavior = "auto";
|
|
13148
13101
|
this.textArea.style.caretColor = "black";
|
|
13149
13102
|
this.textArea.style.width = "100%";
|
|
13103
|
+
this.textArea.style.height = `${size.height}px`;
|
|
13150
13104
|
this.textArea.style.minHeight = "auto";
|
|
13151
13105
|
this.textArea.style.margin = "0px";
|
|
13152
13106
|
this.textArea.style.padding = "0px";
|
|
13153
13107
|
this.textArea.style.paddingTop = "0px";
|
|
13154
|
-
this.textArea.style.boxSizing = "
|
|
13108
|
+
this.textArea.style.boxSizing = "content-box";
|
|
13155
13109
|
this.textArea.style.overflow = "hidden";
|
|
13156
13110
|
this.textArea.style.background = "transparent";
|
|
13157
13111
|
this.textArea.style.border = "none";
|
|
@@ -13165,8 +13119,8 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
13165
13119
|
this.textArea.style.backgroundColor = "transparent";
|
|
13166
13120
|
this.textAreaContainer.style.transformOrigin = "left top";
|
|
13167
13121
|
this.mimicTextNode(textNode);
|
|
13168
|
-
this.textArea.style.left =
|
|
13169
|
-
this.textArea.style.top =
|
|
13122
|
+
this.textArea.style.left = `${-borderSize}px`;
|
|
13123
|
+
this.textArea.style.top = `${-borderSize + (size.height - this.textArea.offsetHeight)}px`;
|
|
13170
13124
|
this.textArea.onfocus = () => {
|
|
13171
13125
|
this.textAreaDomResize(textNode);
|
|
13172
13126
|
};
|
|
@@ -13189,17 +13143,17 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
13189
13143
|
this.textAreaSuperContainer.scrollTop = 0;
|
|
13190
13144
|
this.textAreaSuperContainer.scrollLeft = 0;
|
|
13191
13145
|
}
|
|
13192
|
-
}, { signal: this.instance.getEventsController()
|
|
13146
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
13193
13147
|
this.textAreaContainer.addEventListener("scroll", () => {
|
|
13194
13148
|
if (!this.textAreaContainer) return;
|
|
13195
13149
|
this.textAreaContainer.scrollTop = 0;
|
|
13196
13150
|
this.textAreaContainer.scrollLeft = 0;
|
|
13197
|
-
}, { signal: this.instance.getEventsController()
|
|
13151
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
13198
13152
|
this.textArea.addEventListener("scroll", () => {
|
|
13199
13153
|
if (!this.textArea) return;
|
|
13200
13154
|
this.textArea.scrollTop = 0;
|
|
13201
13155
|
this.textArea.scrollLeft = 0;
|
|
13202
|
-
}, { signal: this.instance.getEventsController()
|
|
13156
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
13203
13157
|
const rotation = textNode.getAbsoluteRotation();
|
|
13204
13158
|
if (rotation) {
|
|
13205
13159
|
const transform = "rotate(" + rotation + "deg)";
|
|
@@ -13212,7 +13166,10 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
13212
13166
|
const width = textAreaWidth / this.instance.getStage().scaleX();
|
|
13213
13167
|
textNode.width(width);
|
|
13214
13168
|
}
|
|
13215
|
-
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL || textNode.getAttrs().layout === TEXT_LAYOUT.SMART)
|
|
13169
|
+
if (!textNode.getAttrs().layout || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_HEIGHT || textNode.getAttrs().layout === TEXT_LAYOUT.AUTO_ALL || textNode.getAttrs().layout === TEXT_LAYOUT.SMART) {
|
|
13170
|
+
const size$1 = this.textRenderedSize(this.textArea.value, textNode);
|
|
13171
|
+
textNode.height(size$1.height * (1 / textNode.getAbsoluteScale().x));
|
|
13172
|
+
}
|
|
13216
13173
|
};
|
|
13217
13174
|
const handleKeyDown = (e) => {
|
|
13218
13175
|
if (this.textArea && textNode && e.code === "Escape") {
|
|
@@ -13249,8 +13206,8 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
13249
13206
|
this.textAreaDomResize(textNode);
|
|
13250
13207
|
}
|
|
13251
13208
|
};
|
|
13252
|
-
this.textArea.addEventListener("keydown", handleKeyDown, { signal: this.instance.getEventsController()
|
|
13253
|
-
this.textArea.addEventListener("keyup", handleKeyUp, { signal: this.instance.getEventsController()
|
|
13209
|
+
this.textArea.addEventListener("keydown", handleKeyDown, { signal: this.instance.getEventsController().signal });
|
|
13210
|
+
this.textArea.addEventListener("keyup", handleKeyUp, { signal: this.instance.getEventsController().signal });
|
|
13254
13211
|
this.textArea.tabIndex = 1;
|
|
13255
13212
|
this.textArea.focus();
|
|
13256
13213
|
const handleOutsideClick = (e) => {
|
|
@@ -13276,7 +13233,7 @@ var WeaveTextNode = class extends WeaveNode {
|
|
|
13276
13233
|
}
|
|
13277
13234
|
};
|
|
13278
13235
|
setTimeout(() => {
|
|
13279
|
-
window.addEventListener("pointerup", handleOutsideClick, { signal: this.instance.getEventsController()
|
|
13236
|
+
window.addEventListener("pointerup", handleOutsideClick, { signal: this.instance.getEventsController().signal });
|
|
13280
13237
|
}, 0);
|
|
13281
13238
|
this.instance.getStage().mode(WEAVE_STAGE_TEXT_EDITION_MODE);
|
|
13282
13239
|
this.editing = true;
|
|
@@ -13736,7 +13693,7 @@ var WeaveImageCrop = class WeaveImageCrop {
|
|
|
13736
13693
|
utilityLayer?.add(this.transformer);
|
|
13737
13694
|
this.transformer?.forceUpdate();
|
|
13738
13695
|
this.cropGroup.show();
|
|
13739
|
-
window.addEventListener("keydown", this.handleHide, { signal: this.instance.getEventsController()
|
|
13696
|
+
if (!this.instance.isServerSide()) window.addEventListener("keydown", this.handleHide, { signal: this.instance.getEventsController().signal });
|
|
13740
13697
|
if (options.cmdCtrl.triggered) {
|
|
13741
13698
|
utilityLayer?.hide();
|
|
13742
13699
|
const stage = this.instance.getStage();
|
|
@@ -16279,9 +16236,48 @@ var WeaveStrokeNode = class extends WeaveNode {
|
|
|
16279
16236
|
result.push(pts[pts.length - 1]);
|
|
16280
16237
|
return result;
|
|
16281
16238
|
}
|
|
16239
|
+
drawRoundCap(ctx, a, b, color) {
|
|
16240
|
+
const cx = (a.x + b.x) / 2;
|
|
16241
|
+
const cy = (a.y + b.y) / 2;
|
|
16242
|
+
const r = Math.hypot(a.x - b.x, a.y - b.y) / 2;
|
|
16243
|
+
ctx.beginPath();
|
|
16244
|
+
ctx.fillStyle = color;
|
|
16245
|
+
ctx.arc(cx, cy, r, 0, Math.PI * 2);
|
|
16246
|
+
ctx.fill();
|
|
16247
|
+
}
|
|
16248
|
+
/**
|
|
16249
|
+
* Draws a filled polygon from the accumulated left/right outline points of a
|
|
16250
|
+
* dash segment and adds round caps at both ends.
|
|
16251
|
+
* NOTE: mutates `rightSide` via Array.reverse() — callers must not reuse it after this call.
|
|
16252
|
+
*/
|
|
16253
|
+
drawDashPolygon(ctx, leftSide, rightSide, color) {
|
|
16254
|
+
const capStartL = leftSide[0];
|
|
16255
|
+
const capStartR = rightSide[0];
|
|
16256
|
+
const capEndL = leftSide.at(-1);
|
|
16257
|
+
const capEndR = rightSide.at(-1);
|
|
16258
|
+
const smoothLeft = this.getSplinePoints(leftSide, 4);
|
|
16259
|
+
const smoothRight = this.getSplinePoints(rightSide.reverse(), 4);
|
|
16260
|
+
ctx.beginPath();
|
|
16261
|
+
ctx.fillStyle = color;
|
|
16262
|
+
ctx.moveTo(smoothLeft[0].x, smoothLeft[0].y);
|
|
16263
|
+
for (const p of smoothLeft) ctx.lineTo(p.x, p.y);
|
|
16264
|
+
for (const p of smoothRight) ctx.lineTo(p.x, p.y);
|
|
16265
|
+
ctx.closePath();
|
|
16266
|
+
ctx.fill();
|
|
16267
|
+
this.drawRoundCap(ctx, capStartL, capStartR, color);
|
|
16268
|
+
this.drawRoundCap(ctx, capEndL, capEndR, color);
|
|
16269
|
+
}
|
|
16282
16270
|
drawRibbonWithDash(ctx, pts, baseW, color, dash) {
|
|
16283
16271
|
if (!pts) return;
|
|
16284
|
-
if (pts.length < 2)
|
|
16272
|
+
if (pts.length < 2) {
|
|
16273
|
+
const pt = pts[0];
|
|
16274
|
+
const r = Math.max(baseW * pt.pressure / 2, .5);
|
|
16275
|
+
ctx.beginPath();
|
|
16276
|
+
ctx.fillStyle = color;
|
|
16277
|
+
ctx.arc(pt.x, pt.y, r, 0, Math.PI * 2);
|
|
16278
|
+
ctx.fill();
|
|
16279
|
+
return;
|
|
16280
|
+
}
|
|
16285
16281
|
const filtered = this.resamplePoints(pts, 2);
|
|
16286
16282
|
const centerline = this.getSplinePoints(filtered, 8);
|
|
16287
16283
|
let dashIndex = 0;
|
|
@@ -16334,17 +16330,7 @@ var WeaveStrokeNode = class extends WeaveNode {
|
|
|
16334
16330
|
}
|
|
16335
16331
|
dashRemaining -= step;
|
|
16336
16332
|
if (dashRemaining <= 0) {
|
|
16337
|
-
if (dashOn && leftSide.length && rightSide.length)
|
|
16338
|
-
const smoothLeft = this.getSplinePoints(leftSide, 4);
|
|
16339
|
-
const smoothRight = this.getSplinePoints(rightSide.reverse(), 4);
|
|
16340
|
-
ctx.beginPath();
|
|
16341
|
-
ctx.fillStyle = color;
|
|
16342
|
-
ctx.moveTo(smoothLeft[0].x, smoothLeft[0].y);
|
|
16343
|
-
for (const p of smoothLeft) ctx.lineTo(p.x, p.y);
|
|
16344
|
-
for (const p of smoothRight) ctx.lineTo(p.x, p.y);
|
|
16345
|
-
ctx.closePath();
|
|
16346
|
-
ctx.fill();
|
|
16347
|
-
}
|
|
16333
|
+
if (dashOn && leftSide.length && rightSide.length) this.drawDashPolygon(ctx, leftSide, rightSide, color);
|
|
16348
16334
|
leftSide = [];
|
|
16349
16335
|
rightSide = [];
|
|
16350
16336
|
dashOn = !dashOn;
|
|
@@ -16354,17 +16340,7 @@ var WeaveStrokeNode = class extends WeaveNode {
|
|
|
16354
16340
|
traveled += step;
|
|
16355
16341
|
}
|
|
16356
16342
|
}
|
|
16357
|
-
if (dashOn && leftSide.length && rightSide.length)
|
|
16358
|
-
const smoothLeft = this.getSplinePoints(leftSide, 4);
|
|
16359
|
-
const smoothRight = this.getSplinePoints(rightSide.reverse(), 4);
|
|
16360
|
-
ctx.beginPath();
|
|
16361
|
-
ctx.fillStyle = color;
|
|
16362
|
-
ctx.moveTo(smoothLeft[0].x, smoothLeft[0].y);
|
|
16363
|
-
for (const p of smoothLeft) ctx.lineTo(p.x, p.y);
|
|
16364
|
-
for (const p of smoothRight) ctx.lineTo(p.x, p.y);
|
|
16365
|
-
ctx.closePath();
|
|
16366
|
-
ctx.fill();
|
|
16367
|
-
}
|
|
16343
|
+
if (dashOn && leftSide.length && rightSide.length) this.drawDashPolygon(ctx, leftSide, rightSide, color);
|
|
16368
16344
|
}
|
|
16369
16345
|
drawShape(ctx, shape) {
|
|
16370
16346
|
const strokeElements = shape.getAttrs().strokeElements;
|
|
@@ -16381,8 +16357,6 @@ var WeaveStrokeNode = class extends WeaveNode {
|
|
|
16381
16357
|
sceneFunc: (ctx, shape) => {
|
|
16382
16358
|
this.drawShape(ctx, shape);
|
|
16383
16359
|
},
|
|
16384
|
-
lineCap: "round",
|
|
16385
|
-
lineJoin: "round",
|
|
16386
16360
|
dashEnabled: false,
|
|
16387
16361
|
hitFunc: (context, shape) => {
|
|
16388
16362
|
context.beginPath();
|
|
@@ -16838,10 +16812,10 @@ var WeaveStrokeSingleNode = class extends WeaveNode {
|
|
|
16838
16812
|
if (this.eventsInitialized) return;
|
|
16839
16813
|
window.addEventListener("keydown", (e) => {
|
|
16840
16814
|
if (e.key === "Shift") this.shiftPressed = true;
|
|
16841
|
-
}, { signal: this.instance.getEventsController()
|
|
16815
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
16842
16816
|
window.addEventListener("keyup", (e) => {
|
|
16843
16817
|
if (e.key === "Shift") this.shiftPressed = false;
|
|
16844
|
-
}, { signal: this.instance.getEventsController()
|
|
16818
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
16845
16819
|
this.eventsInitialized = true;
|
|
16846
16820
|
}
|
|
16847
16821
|
onRender(props) {
|
|
@@ -20928,7 +20902,7 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
|
|
|
20928
20902
|
}
|
|
20929
20903
|
}, {
|
|
20930
20904
|
passive: false,
|
|
20931
|
-
signal: this.instance.getEventsController()
|
|
20905
|
+
signal: this.instance.getEventsController().signal
|
|
20932
20906
|
});
|
|
20933
20907
|
stage.getContent().addEventListener("touchmove", (e) => {
|
|
20934
20908
|
e.preventDefault();
|
|
@@ -20971,7 +20945,7 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
|
|
|
20971
20945
|
}
|
|
20972
20946
|
}, {
|
|
20973
20947
|
passive: false,
|
|
20974
|
-
signal: this.instance.getEventsController()
|
|
20948
|
+
signal: this.instance.getEventsController().signal
|
|
20975
20949
|
});
|
|
20976
20950
|
stage.getContent().addEventListener("touchend", () => {
|
|
20977
20951
|
this.pinching = false;
|
|
@@ -20979,7 +20953,7 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
|
|
|
20979
20953
|
lastCenter = null;
|
|
20980
20954
|
}, {
|
|
20981
20955
|
passive: false,
|
|
20982
|
-
signal: this.instance.getEventsController()
|
|
20956
|
+
signal: this.instance.getEventsController().signal
|
|
20983
20957
|
});
|
|
20984
20958
|
let doZoom = false;
|
|
20985
20959
|
const handleWheelImmediate = (e) => {
|
|
@@ -21000,7 +20974,7 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
|
|
|
21000
20974
|
doZoom = true;
|
|
21001
20975
|
};
|
|
21002
20976
|
window.addEventListener("wheel", handleWheelImmediate, {
|
|
21003
|
-
signal: this.instance.getEventsController()
|
|
20977
|
+
signal: this.instance.getEventsController().signal,
|
|
21004
20978
|
passive: false
|
|
21005
20979
|
});
|
|
21006
20980
|
const handleWheel = (e) => {
|
|
@@ -21016,7 +20990,7 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
|
|
|
21016
20990
|
};
|
|
21017
20991
|
const throttledHandleWheel = (0, import_throttle.default)(handleWheel, DEFAULT_THROTTLE_MS);
|
|
21018
20992
|
window.addEventListener("wheel", throttledHandleWheel, {
|
|
21019
|
-
signal: this.instance.getEventsController()
|
|
20993
|
+
signal: this.instance.getEventsController().signal,
|
|
21020
20994
|
passive: true
|
|
21021
20995
|
});
|
|
21022
20996
|
}
|
|
@@ -21244,7 +21218,7 @@ var WeaveMoveToolAction = class extends WeaveAction {
|
|
|
21244
21218
|
this.cancelAction();
|
|
21245
21219
|
return;
|
|
21246
21220
|
}
|
|
21247
|
-
}, { signal: this.instance.getEventsController()
|
|
21221
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
21248
21222
|
stage.on("pointerdown", () => {
|
|
21249
21223
|
if ([MOVE_TOOL_ACTION_NAME].includes(this.instance.getActiveAction() ?? "")) stage.container().style.cursor = "grabbing";
|
|
21250
21224
|
});
|
|
@@ -21405,7 +21379,7 @@ var WeaveEraserToolAction = class extends WeaveAction {
|
|
|
21405
21379
|
this.cancelAction();
|
|
21406
21380
|
return;
|
|
21407
21381
|
}
|
|
21408
|
-
}, { signal: this.instance.getEventsController()
|
|
21382
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
21409
21383
|
this.initialized = true;
|
|
21410
21384
|
}
|
|
21411
21385
|
setState(state) {
|
|
@@ -21510,7 +21484,7 @@ var WeaveRectangleToolAction = class extends WeaveAction {
|
|
|
21510
21484
|
this.cancelAction();
|
|
21511
21485
|
return;
|
|
21512
21486
|
}
|
|
21513
|
-
}, { signal: this.instance.getEventsController()
|
|
21487
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
21514
21488
|
stage.on("pointermove", () => {
|
|
21515
21489
|
if (this.state === RECTANGLE_TOOL_STATE.IDLE) return;
|
|
21516
21490
|
this.setCursor();
|
|
@@ -21731,7 +21705,7 @@ var WeaveEllipseToolAction = class extends WeaveAction {
|
|
|
21731
21705
|
this.cancelAction();
|
|
21732
21706
|
return;
|
|
21733
21707
|
}
|
|
21734
|
-
}, { signal: this.instance.getEventsController()
|
|
21708
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
21735
21709
|
stage.on("pointerdown", (e) => {
|
|
21736
21710
|
this.setTapStart(e);
|
|
21737
21711
|
this.pointers.set(e.evt.pointerId, {
|
|
@@ -21950,7 +21924,7 @@ var WeavePenToolAction = class extends WeaveAction {
|
|
|
21950
21924
|
this.cancelAction();
|
|
21951
21925
|
return;
|
|
21952
21926
|
}
|
|
21953
|
-
}, { signal: this.instance.getEventsController()
|
|
21927
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
21954
21928
|
stage.on("pointerdown", (e) => {
|
|
21955
21929
|
this.setTapStart(e);
|
|
21956
21930
|
this.pointers.set(e.evt.pointerId, {
|
|
@@ -22234,13 +22208,13 @@ var WeaveLineToolAction = class extends WeaveAction {
|
|
|
22234
22208
|
this.snappedAngle = null;
|
|
22235
22209
|
this.shiftPressed = true;
|
|
22236
22210
|
}
|
|
22237
|
-
}, { signal: this.instance.getEventsController()
|
|
22211
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
22238
22212
|
window.addEventListener("keyup", (e) => {
|
|
22239
22213
|
if (e.key === "Shift" && this.instance.getActiveAction() === LINE_TOOL_ACTION_NAME) {
|
|
22240
22214
|
this.snappedAngle = null;
|
|
22241
22215
|
this.shiftPressed = false;
|
|
22242
22216
|
}
|
|
22243
|
-
}, { signal: this.instance.getEventsController()
|
|
22217
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
22244
22218
|
stage.on("pointerdown", (e) => {
|
|
22245
22219
|
this.setTapStart(e);
|
|
22246
22220
|
this.pointers.set(e.evt.pointerId, {
|
|
@@ -22509,7 +22483,7 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
22509
22483
|
stage.container().style.touchAction = "none";
|
|
22510
22484
|
window.addEventListener("keyup", (e) => {
|
|
22511
22485
|
if (e.code === "Space" && this.instance.getActiveAction() === BRUSH_TOOL_ACTION_NAME) this.isSpacePressed = false;
|
|
22512
|
-
}, { signal: this.instance.getEventsController()
|
|
22486
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
22513
22487
|
window.addEventListener("keydown", (e) => {
|
|
22514
22488
|
if (e.code === "Enter" && this.instance.getActiveAction() === BRUSH_TOOL_ACTION_NAME) {
|
|
22515
22489
|
e.stopPropagation();
|
|
@@ -22525,8 +22499,8 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
22525
22499
|
e.stopPropagation();
|
|
22526
22500
|
this.cancelAction();
|
|
22527
22501
|
}
|
|
22528
|
-
}, { signal: this.instance.getEventsController()
|
|
22529
|
-
const handlePointerDown = (e) => {
|
|
22502
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
22503
|
+
const handlePointerDown$1 = (e) => {
|
|
22530
22504
|
if (this.state === BRUSH_TOOL_STATE.INACTIVE) return;
|
|
22531
22505
|
if (this.state !== BRUSH_TOOL_STATE.IDLE) return;
|
|
22532
22506
|
if (this.getZoomPlugin()?.isPinching()) return;
|
|
@@ -22538,8 +22512,8 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
22538
22512
|
this.handleStartStroke(pointPressure);
|
|
22539
22513
|
e.evt.stopPropagation();
|
|
22540
22514
|
};
|
|
22541
|
-
stage.on("pointerdown", handlePointerDown);
|
|
22542
|
-
const handlePointerMove = (e) => {
|
|
22515
|
+
stage.on("pointerdown", handlePointerDown$1);
|
|
22516
|
+
const handlePointerMove$1 = (e) => {
|
|
22543
22517
|
if (this.state === BRUSH_TOOL_STATE.INACTIVE) return;
|
|
22544
22518
|
this.setCursor();
|
|
22545
22519
|
if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
|
|
@@ -22562,15 +22536,15 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
22562
22536
|
}
|
|
22563
22537
|
e.evt.stopPropagation();
|
|
22564
22538
|
};
|
|
22565
|
-
stage.on("pointermove", handlePointerMove);
|
|
22566
|
-
const handlePointerUp = (e) => {
|
|
22539
|
+
stage.on("pointermove", handlePointerMove$1);
|
|
22540
|
+
const handlePointerUp$1 = (e) => {
|
|
22567
22541
|
this.penActive = false;
|
|
22568
22542
|
if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
|
|
22569
22543
|
if (this.getZoomPlugin()?.isPinching()) return;
|
|
22570
22544
|
this.handleEndStroke();
|
|
22571
22545
|
e.evt.stopPropagation();
|
|
22572
22546
|
};
|
|
22573
|
-
stage.on("pointerup", handlePointerUp);
|
|
22547
|
+
stage.on("pointerup", handlePointerUp$1);
|
|
22574
22548
|
this.initialized = true;
|
|
22575
22549
|
}
|
|
22576
22550
|
setState(state) {
|
|
@@ -22664,34 +22638,40 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
22664
22638
|
if (nodeHandler) nodeHandler.onUpdate(tempStroke, tempStroke.getAttrs());
|
|
22665
22639
|
}
|
|
22666
22640
|
}
|
|
22641
|
+
finalizeStroke(tempStroke, nodeHandler) {
|
|
22642
|
+
const box = this.getBoundingBox(tempStroke.getAttrs().strokeElements);
|
|
22643
|
+
let newStrokeElements = [...tempStroke.getAttrs().strokeElements];
|
|
22644
|
+
if (this.predictedCount > 0) {
|
|
22645
|
+
newStrokeElements = newStrokeElements.slice(0, -1 * this.predictedCount);
|
|
22646
|
+
this.predictedCount = 0;
|
|
22647
|
+
}
|
|
22648
|
+
newStrokeElements = newStrokeElements.map((point) => ({
|
|
22649
|
+
...point,
|
|
22650
|
+
x: point.x - box.x,
|
|
22651
|
+
y: point.y - box.y
|
|
22652
|
+
}));
|
|
22653
|
+
const compressedPoints = simplify(newStrokeElements, 1, true);
|
|
22654
|
+
const sw = tempStroke.getAttrs().strokeWidth ?? 1;
|
|
22655
|
+
const finalWidth = Math.max(box.width, sw);
|
|
22656
|
+
const finalHeight = Math.max(box.height, sw);
|
|
22657
|
+
const finalX = box.width === 0 ? box.x - sw / 2 : box.x;
|
|
22658
|
+
const finalY = box.height === 0 ? box.y - sw / 2 : box.y;
|
|
22659
|
+
tempStroke.setAttrs({
|
|
22660
|
+
width: finalWidth,
|
|
22661
|
+
height: finalHeight,
|
|
22662
|
+
x: finalX,
|
|
22663
|
+
y: finalY,
|
|
22664
|
+
strokeElements: compressedPoints
|
|
22665
|
+
});
|
|
22666
|
+
const realNode = this.instance.getStage().findOne(`#${tempStroke.getAttrs().id}`);
|
|
22667
|
+
if (realNode) realNode.destroy();
|
|
22668
|
+
if (tempStroke.getAttrs().strokeElements.length >= 1) this.instance.addNode(nodeHandler.serialize(tempStroke), this.container?.getAttrs().id);
|
|
22669
|
+
}
|
|
22667
22670
|
handleEndStroke() {
|
|
22668
22671
|
const tempStroke = this.instance.getStage().findOne(`#${this.strokeId}`);
|
|
22669
22672
|
if (tempStroke) {
|
|
22670
22673
|
const nodeHandler = this.instance.getNodeHandler("stroke");
|
|
22671
|
-
if (nodeHandler)
|
|
22672
|
-
const box = this.getBoundingBox(tempStroke.getAttrs().strokeElements);
|
|
22673
|
-
let newStrokeElements = [...tempStroke.getAttrs().strokeElements];
|
|
22674
|
-
if (this.predictedCount > 0) {
|
|
22675
|
-
newStrokeElements = newStrokeElements.slice(0, -1 * this.predictedCount);
|
|
22676
|
-
this.predictedCount = 0;
|
|
22677
|
-
}
|
|
22678
|
-
newStrokeElements = newStrokeElements.map((point) => ({
|
|
22679
|
-
...point,
|
|
22680
|
-
x: point.x - box.x,
|
|
22681
|
-
y: point.y - box.y
|
|
22682
|
-
}));
|
|
22683
|
-
const compressedPoints = simplify(newStrokeElements, 1, true);
|
|
22684
|
-
tempStroke.setAttrs({
|
|
22685
|
-
width: box.width,
|
|
22686
|
-
height: box.height,
|
|
22687
|
-
x: box.x,
|
|
22688
|
-
y: box.y,
|
|
22689
|
-
strokeElements: compressedPoints
|
|
22690
|
-
});
|
|
22691
|
-
const realNode = this.instance.getStage().findOne(`#${tempStroke.getAttrs().id}`);
|
|
22692
|
-
if (realNode) realNode.destroy();
|
|
22693
|
-
if (tempStroke.getAttrs().strokeElements.length >= 3) this.instance.addNode(nodeHandler.serialize(tempStroke), this.container?.getAttrs().id);
|
|
22694
|
-
}
|
|
22674
|
+
if (nodeHandler) this.finalizeStroke(tempStroke, nodeHandler);
|
|
22695
22675
|
this.clickPoint = null;
|
|
22696
22676
|
this.setCursor();
|
|
22697
22677
|
this.setFocusStage();
|
|
@@ -22802,7 +22782,7 @@ var WeaveTextToolAction = class extends WeaveAction {
|
|
|
22802
22782
|
this.cancelAction();
|
|
22803
22783
|
return;
|
|
22804
22784
|
}
|
|
22805
|
-
}, { signal: this.instance.getEventsController()
|
|
22785
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
22806
22786
|
stage.on("pointermove", () => {
|
|
22807
22787
|
if (this.state === TEXT_TOOL_STATE.IDLE) return;
|
|
22808
22788
|
this.setCursor();
|
|
@@ -22978,7 +22958,7 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
22978
22958
|
this.cancelAction();
|
|
22979
22959
|
return;
|
|
22980
22960
|
}
|
|
22981
|
-
}, { signal: this.instance.getEventsController()
|
|
22961
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
22982
22962
|
stage.on("pointerdown", (e) => {
|
|
22983
22963
|
this.setTapStart(e);
|
|
22984
22964
|
if (this.ignorePointerEvents) return;
|
|
@@ -23301,10 +23281,10 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
23301
23281
|
return this.state;
|
|
23302
23282
|
}
|
|
23303
23283
|
loadImageDataURL(imageDataURL) {
|
|
23304
|
-
return new Promise((resolve, reject
|
|
23284
|
+
return new Promise((resolve, reject) => {
|
|
23305
23285
|
const imageEle = Konva.Util.createImageElement();
|
|
23306
23286
|
imageEle.onerror = (error) => {
|
|
23307
|
-
reject
|
|
23287
|
+
reject(error);
|
|
23308
23288
|
};
|
|
23309
23289
|
imageEle.onload = async () => {
|
|
23310
23290
|
resolve(imageEle);
|
|
@@ -23313,13 +23293,13 @@ var WeaveImageToolAction = class extends WeaveAction {
|
|
|
23313
23293
|
});
|
|
23314
23294
|
}
|
|
23315
23295
|
getDataURL(blob) {
|
|
23316
|
-
return new Promise((resolve, reject
|
|
23296
|
+
return new Promise((resolve, reject) => {
|
|
23317
23297
|
const reader = new FileReader();
|
|
23318
23298
|
reader.onloadend = () => {
|
|
23319
23299
|
resolve(reader.result);
|
|
23320
23300
|
};
|
|
23321
23301
|
reader.onerror = () => {
|
|
23322
|
-
reject
|
|
23302
|
+
reject(new Error("Failed to generate dataURL from file"));
|
|
23323
23303
|
};
|
|
23324
23304
|
reader.readAsDataURL(blob);
|
|
23325
23305
|
});
|
|
@@ -23438,7 +23418,7 @@ var WeaveImagesToolAction = class extends WeaveAction {
|
|
|
23438
23418
|
const stage = this.instance.getStage();
|
|
23439
23419
|
stage.container().addEventListener("keydown", (e) => {
|
|
23440
23420
|
if (e.key === "Escape" && this.instance.getActiveAction() === WEAVE_IMAGES_TOOL_ACTION_NAME) this.cancelAction();
|
|
23441
|
-
}, { signal: this.instance.getEventsController()
|
|
23421
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
23442
23422
|
stage.on("pointerdown", (e) => {
|
|
23443
23423
|
this.setTapStart(e);
|
|
23444
23424
|
this.pointers.set(e.evt.pointerId, {
|
|
@@ -23856,7 +23836,7 @@ var WeaveStarToolAction = class extends WeaveAction {
|
|
|
23856
23836
|
this.cancelAction();
|
|
23857
23837
|
return;
|
|
23858
23838
|
}
|
|
23859
|
-
}, { signal: this.instance.getEventsController()
|
|
23839
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
23860
23840
|
stage.on("pointerdown", (e) => {
|
|
23861
23841
|
this.setTapStart(e);
|
|
23862
23842
|
this.pointers.set(e.evt.pointerId, {
|
|
@@ -24079,7 +24059,7 @@ var WeaveArrowToolAction = class extends WeaveAction {
|
|
|
24079
24059
|
return;
|
|
24080
24060
|
}
|
|
24081
24061
|
if (e.code === "Escape" && this.instance.getActiveAction() === WEAVE_ARROW_TOOL_ACTION_NAME) this.cancelAction();
|
|
24082
|
-
}, { signal: this.instance.getEventsController()
|
|
24062
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
24083
24063
|
stage.on("pointerdown", (e) => {
|
|
24084
24064
|
this.setTapStart(e);
|
|
24085
24065
|
this.pointers.set(e.evt.pointerId, {
|
|
@@ -24370,10 +24350,10 @@ var WeaveStrokeToolAction = class extends WeaveAction {
|
|
|
24370
24350
|
return;
|
|
24371
24351
|
}
|
|
24372
24352
|
if (e.key === "Shift" && this.getNames().includes(this.instance.getActiveAction() ?? "")) this.shiftPressed = true;
|
|
24373
|
-
}, { signal: this.instance.getEventsController()
|
|
24353
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
24374
24354
|
window.addEventListener("keyup", (e) => {
|
|
24375
24355
|
if (e.key === "Shift" && this.getNames().includes(this.instance.getActiveAction() ?? "")) this.shiftPressed = false;
|
|
24376
|
-
}, { signal: this.instance.getEventsController()
|
|
24356
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
24377
24357
|
stage.on("pointerdown", (e) => {
|
|
24378
24358
|
this.setTapStart(e);
|
|
24379
24359
|
this.pointers.set(e.evt.pointerId, {
|
|
@@ -24603,7 +24583,7 @@ var WeaveRegularPolygonToolAction = class extends WeaveAction {
|
|
|
24603
24583
|
this.cancelAction();
|
|
24604
24584
|
return;
|
|
24605
24585
|
}
|
|
24606
|
-
}, { signal: this.instance.getEventsController()
|
|
24586
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
24607
24587
|
stage.on("pointerdown", (e) => {
|
|
24608
24588
|
this.setTapStart(e);
|
|
24609
24589
|
this.pointers.set(e.evt.pointerId, {
|
|
@@ -24807,7 +24787,7 @@ var WeaveFrameToolAction = class extends WeaveAction {
|
|
|
24807
24787
|
this.cancelAction();
|
|
24808
24788
|
return;
|
|
24809
24789
|
}
|
|
24810
|
-
}, { signal: this.instance.getEventsController()
|
|
24790
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
24811
24791
|
stage.on("pointermove", () => {
|
|
24812
24792
|
if (this.state === FRAME_TOOL_STATE.IDLE) return;
|
|
24813
24793
|
this.setCursor();
|
|
@@ -25348,7 +25328,7 @@ var WeaveCommentToolAction = class extends WeaveAction {
|
|
|
25348
25328
|
return;
|
|
25349
25329
|
}
|
|
25350
25330
|
if (e.code === "Escape" && this.state === WEAVE_COMMENT_TOOL_STATE.CREATING_COMMENT) this.setState(WEAVE_COMMENT_TOOL_STATE.ADDING);
|
|
25351
|
-
}, { signal: this.instance.getEventsController()
|
|
25331
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
25352
25332
|
stage.on("pointermove", (e) => {
|
|
25353
25333
|
if (this.state === WEAVE_COMMENT_TOOL_STATE.IDLE) return;
|
|
25354
25334
|
if (commentNodeHandler?.isCommentViewing()) {
|
|
@@ -25550,7 +25530,7 @@ var WeaveVideoToolAction = class extends WeaveAction {
|
|
|
25550
25530
|
this.cancelAction();
|
|
25551
25531
|
return;
|
|
25552
25532
|
}
|
|
25553
|
-
}, { signal: this.instance.getEventsController()
|
|
25533
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
25554
25534
|
stage.on("pointerdown", (e) => {
|
|
25555
25535
|
this.setTapStart(e);
|
|
25556
25536
|
this.pointers.set(e.evt.pointerId, {
|
|
@@ -25713,7 +25693,7 @@ var WeaveMeasureToolAction = class extends WeaveAction {
|
|
|
25713
25693
|
const stage = this.instance.getStage();
|
|
25714
25694
|
window.addEventListener("keydown", (e) => {
|
|
25715
25695
|
if (e.code === "Escape" && this.instance.getActiveAction() === MEASURE_TOOL_ACTION_NAME) this.cancelAction();
|
|
25716
|
-
}, { signal: this.instance.getEventsController()
|
|
25696
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
25717
25697
|
stage.on("pointermove", () => {
|
|
25718
25698
|
if (this.state === MEASURE_TOOL_STATE.IDLE) return;
|
|
25719
25699
|
if (this.state === MEASURE_TOOL_STATE.SET_TO) {
|
|
@@ -26024,7 +26004,7 @@ var WeaveConnectorToolAction = class extends WeaveAction {
|
|
|
26024
26004
|
return;
|
|
26025
26005
|
}
|
|
26026
26006
|
if (e.code === "Escape" && this.instance.getActiveAction() === CONNECTOR_TOOL_ACTION_NAME) this.cancelAction();
|
|
26027
|
-
}, { signal: this.instance.getEventsController()
|
|
26007
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
26028
26008
|
let nodeHovered = void 0;
|
|
26029
26009
|
stage.on("pointermove", () => {
|
|
26030
26010
|
if (!(this.state === CONNECTOR_TOOL_STATE.SELECTING_INITIAL || this.state === CONNECTOR_TOOL_STATE.SELECTING_FINAL)) return;
|
|
@@ -26840,7 +26820,7 @@ var WeaveGuideToolAction = class extends WeaveAction {
|
|
|
26840
26820
|
window.addEventListener("keyup", (e) => {
|
|
26841
26821
|
const isOptionAltPressed = e.key === "Alt" || e.key === "Option";
|
|
26842
26822
|
if (isOptionAltPressed) this.guideDistanceToTargetInfo.cleanup();
|
|
26843
|
-
}, { signal: this.instance.getEventsController()
|
|
26823
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
26844
26824
|
window.addEventListener("keydown", (e) => {
|
|
26845
26825
|
const isOptionAltPressed = e.key === "Alt" || e.key === "Option";
|
|
26846
26826
|
if (isOptionAltPressed && this.instance.getActiveAction() === GUIDE_TOOL_ACTION_NAME && this.state === GUIDE_TOOL_STATE.ADDING) this.moveGuide(true);
|
|
@@ -26860,7 +26840,7 @@ var WeaveGuideToolAction = class extends WeaveAction {
|
|
|
26860
26840
|
this.cancelAction();
|
|
26861
26841
|
}
|
|
26862
26842
|
}
|
|
26863
|
-
}, { signal: this.instance.getEventsController()
|
|
26843
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
26864
26844
|
stage.on("pointermove", (e) => {
|
|
26865
26845
|
if (this.state === GUIDE_TOOL_STATE.IDLE) return;
|
|
26866
26846
|
this.setCursor();
|
|
@@ -27132,10 +27112,10 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
|
|
|
27132
27112
|
const stage = this.instance.getStage();
|
|
27133
27113
|
window.addEventListener("keydown", (e) => {
|
|
27134
27114
|
if (e.code === "Space") this.isSpaceKeyPressed = true;
|
|
27135
|
-
}, { signal: this.instance.getEventsController()
|
|
27115
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
27136
27116
|
window.addEventListener("keyup", (e) => {
|
|
27137
27117
|
if (e.code === "Space") this.isSpaceKeyPressed = false;
|
|
27138
|
-
}, { signal: this.instance.getEventsController()
|
|
27118
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
27139
27119
|
this.instance.addEventListener("onStageMove", () => {
|
|
27140
27120
|
this.onRender();
|
|
27141
27121
|
});
|
|
@@ -27452,7 +27432,7 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
|
|
|
27452
27432
|
this.isSpaceKeyPressed = true;
|
|
27453
27433
|
this.setCursor();
|
|
27454
27434
|
}
|
|
27455
|
-
}, { signal: this.instance.getEventsController()
|
|
27435
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
27456
27436
|
window.addEventListener("keyup", (e) => {
|
|
27457
27437
|
if (e.code === "Space") {
|
|
27458
27438
|
this.getContextMenuPlugin()?.enable();
|
|
@@ -27460,7 +27440,7 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
|
|
|
27460
27440
|
this.isSpaceKeyPressed = false;
|
|
27461
27441
|
this.disableMove();
|
|
27462
27442
|
}
|
|
27463
|
-
}, { signal: this.instance.getEventsController()
|
|
27443
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
27464
27444
|
let lastPos = null;
|
|
27465
27445
|
stage.on("pointerdown", (e) => {
|
|
27466
27446
|
this.pointers.set(e.evt.pointerId, {
|
|
@@ -27536,7 +27516,7 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
|
|
|
27536
27516
|
const handleWheelThrottled = (0, import_throttle.default)(handleWheel, WEAVE_STAGE_PANNING_THROTTLE_MS);
|
|
27537
27517
|
window.addEventListener("wheel", handleWheelThrottled, {
|
|
27538
27518
|
passive: true,
|
|
27539
|
-
signal: this.instance.getEventsController()
|
|
27519
|
+
signal: this.instance.getEventsController().signal
|
|
27540
27520
|
});
|
|
27541
27521
|
stage.on("dragstart", (e) => {
|
|
27542
27522
|
const duration = 1e3 / 60;
|
|
@@ -27588,7 +27568,7 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
|
|
|
27588
27568
|
e.preventDefault();
|
|
27589
27569
|
}, {
|
|
27590
27570
|
passive: false,
|
|
27591
|
-
signal: this.instance.getEventsController()
|
|
27571
|
+
signal: this.instance.getEventsController().signal
|
|
27592
27572
|
});
|
|
27593
27573
|
}
|
|
27594
27574
|
isPanning() {
|
|
@@ -27874,7 +27854,7 @@ var WeaveStageResizePlugin = class extends WeavePlugin {
|
|
|
27874
27854
|
}, DEFAULT_THROTTLE_MS);
|
|
27875
27855
|
window.addEventListener("resize", () => {
|
|
27876
27856
|
throttledResize();
|
|
27877
|
-
}, { signal: this.instance.getEventsController()
|
|
27857
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
27878
27858
|
const resizeObserver = new ResizeObserver(() => {
|
|
27879
27859
|
throttledResize();
|
|
27880
27860
|
});
|
|
@@ -28598,6 +28578,215 @@ var WeaveUsersPresencePlugin = class extends WeavePlugin {
|
|
|
28598
28578
|
}
|
|
28599
28579
|
};
|
|
28600
28580
|
|
|
28581
|
+
//#endregion
|
|
28582
|
+
//#region src/plugins/context-menu/context-menu.ts
|
|
28583
|
+
var WeaveContextMenuPlugin = class extends WeavePlugin {
|
|
28584
|
+
getLayerName = void 0;
|
|
28585
|
+
initLayer = void 0;
|
|
28586
|
+
constructor(params) {
|
|
28587
|
+
super();
|
|
28588
|
+
const { config } = params ?? {};
|
|
28589
|
+
this.config = {
|
|
28590
|
+
xOffset: WEAVE_CONTEXT_MENU_X_OFFSET_DEFAULT,
|
|
28591
|
+
yOffset: WEAVE_CONTEXT_MENU_Y_OFFSET_DEFAULT,
|
|
28592
|
+
...config
|
|
28593
|
+
};
|
|
28594
|
+
this.initialize();
|
|
28595
|
+
}
|
|
28596
|
+
initialize() {
|
|
28597
|
+
this.timer = null;
|
|
28598
|
+
this.tapHold = false;
|
|
28599
|
+
this.contextMenuVisible = false;
|
|
28600
|
+
this.tapStart = {
|
|
28601
|
+
x: 0,
|
|
28602
|
+
y: 0,
|
|
28603
|
+
time: 0
|
|
28604
|
+
};
|
|
28605
|
+
this.tapHoldTimeout = WEAVE_CONTEXT_MENU_TAP_HOLD_TIMEOUT;
|
|
28606
|
+
this.pointers = {};
|
|
28607
|
+
}
|
|
28608
|
+
getName() {
|
|
28609
|
+
return WEAVE_CONTEXT_MENU_PLUGIN_KEY;
|
|
28610
|
+
}
|
|
28611
|
+
onInit() {
|
|
28612
|
+
this.initEvents();
|
|
28613
|
+
}
|
|
28614
|
+
isPressed(e) {
|
|
28615
|
+
return e.evt.buttons > 0;
|
|
28616
|
+
}
|
|
28617
|
+
setTapStart(e) {
|
|
28618
|
+
this.tapStart = {
|
|
28619
|
+
x: e.evt.clientX,
|
|
28620
|
+
y: e.evt.clientY,
|
|
28621
|
+
time: performance.now()
|
|
28622
|
+
};
|
|
28623
|
+
}
|
|
28624
|
+
triggerContextMenu(eventTarget, target) {
|
|
28625
|
+
const stage = this.instance.getStage();
|
|
28626
|
+
const selectionPlugin = this.getSelectionPlugin();
|
|
28627
|
+
let nodes = [];
|
|
28628
|
+
if (target && target !== stage) {
|
|
28629
|
+
const nodeHandler = this.instance.getNodeHandler(target.getAttrs().nodeType);
|
|
28630
|
+
nodes = [{
|
|
28631
|
+
instance: target,
|
|
28632
|
+
node: nodeHandler?.serialize(target)
|
|
28633
|
+
}];
|
|
28634
|
+
}
|
|
28635
|
+
const eventTargetParent = eventTarget.getParent();
|
|
28636
|
+
if (eventTargetParent instanceof Konva.Transformer) nodes = eventTargetParent.nodes().map((node) => {
|
|
28637
|
+
const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
|
|
28638
|
+
return {
|
|
28639
|
+
instance: node,
|
|
28640
|
+
node: nodeHandler?.serialize(node)
|
|
28641
|
+
};
|
|
28642
|
+
});
|
|
28643
|
+
if (this.contextMenuVisible) this.closeContextMenu();
|
|
28644
|
+
let allNodesMutexUnlocked = true;
|
|
28645
|
+
let allNodesUnlocked = true;
|
|
28646
|
+
const actUser = this.instance.getStore().getUser();
|
|
28647
|
+
for (const node of nodes) {
|
|
28648
|
+
const locked = node.instance.getAttrs().locked;
|
|
28649
|
+
const mutexInfo = this.instance.getNodeMutexLock(node.node?.key ?? "");
|
|
28650
|
+
if (locked) {
|
|
28651
|
+
allNodesUnlocked = false;
|
|
28652
|
+
break;
|
|
28653
|
+
}
|
|
28654
|
+
if (mutexInfo && mutexInfo.user.id !== actUser.id) {
|
|
28655
|
+
allNodesMutexUnlocked = false;
|
|
28656
|
+
break;
|
|
28657
|
+
}
|
|
28658
|
+
}
|
|
28659
|
+
if (!allNodesMutexUnlocked || !allNodesUnlocked) return;
|
|
28660
|
+
if (selectionPlugin && !(eventTarget.getParent() instanceof Konva.Transformer && selectionPlugin.getSelectedNodes().length > 0)) {
|
|
28661
|
+
selectionPlugin.setSelectedNodes([...nodes.map((node) => node.instance)]);
|
|
28662
|
+
selectionPlugin.getHoverTransformer().nodes([]);
|
|
28663
|
+
}
|
|
28664
|
+
const containerRect = stage.container().getBoundingClientRect();
|
|
28665
|
+
const pointerPos = stage.getPointerPosition();
|
|
28666
|
+
const relativeClickPoint = stage.getRelativePointerPosition();
|
|
28667
|
+
if (containerRect && pointerPos && relativeClickPoint && allNodesUnlocked) {
|
|
28668
|
+
const contextMenuPoint = {
|
|
28669
|
+
x: containerRect.left + pointerPos.x + (this.config.xOffset ?? 4),
|
|
28670
|
+
y: containerRect.top + pointerPos.y + (this.config.yOffset ?? 4)
|
|
28671
|
+
};
|
|
28672
|
+
const stageClickPoint = this.getStageClickPoint(pointerPos);
|
|
28673
|
+
this.contextMenuVisible = true;
|
|
28674
|
+
this.instance.emitEvent("onNodeContextMenu", {
|
|
28675
|
+
selection: nodes,
|
|
28676
|
+
contextMenuPoint,
|
|
28677
|
+
clickPoint: pointerPos,
|
|
28678
|
+
stageClickPoint,
|
|
28679
|
+
visible: true
|
|
28680
|
+
});
|
|
28681
|
+
}
|
|
28682
|
+
}
|
|
28683
|
+
closeContextMenu() {
|
|
28684
|
+
this.contextMenuVisible = false;
|
|
28685
|
+
this.instance.emitEvent("onNodeContextMenu", {
|
|
28686
|
+
selection: [],
|
|
28687
|
+
contextMenuPoint: {
|
|
28688
|
+
x: 0,
|
|
28689
|
+
y: 0
|
|
28690
|
+
},
|
|
28691
|
+
clickPoint: {
|
|
28692
|
+
x: 0,
|
|
28693
|
+
y: 0
|
|
28694
|
+
},
|
|
28695
|
+
stageClickPoint: {
|
|
28696
|
+
x: 0,
|
|
28697
|
+
y: 0
|
|
28698
|
+
},
|
|
28699
|
+
visible: false
|
|
28700
|
+
});
|
|
28701
|
+
}
|
|
28702
|
+
getSelectionPlugin() {
|
|
28703
|
+
const selectionPlugin = this.instance.getPlugin(WEAVE_NODES_SELECTION_KEY);
|
|
28704
|
+
return selectionPlugin;
|
|
28705
|
+
}
|
|
28706
|
+
cancelLongPressTimer() {
|
|
28707
|
+
if (this.timer) {
|
|
28708
|
+
clearTimeout(this.timer);
|
|
28709
|
+
this.timer = null;
|
|
28710
|
+
}
|
|
28711
|
+
}
|
|
28712
|
+
initEvents() {
|
|
28713
|
+
const stage = this.instance.getStage();
|
|
28714
|
+
stage.on("pointerdown", (e) => {
|
|
28715
|
+
this.setTapStart(e);
|
|
28716
|
+
this.pointers[e.evt.pointerId] = e.evt;
|
|
28717
|
+
if (e.evt.buttons === 0) return;
|
|
28718
|
+
if (e.evt.pointerType === "mouse") return;
|
|
28719
|
+
if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length > 1) return;
|
|
28720
|
+
if (this.timer) return;
|
|
28721
|
+
this.timer = setTimeout(() => {
|
|
28722
|
+
this.tapHold = true;
|
|
28723
|
+
const actualActions = this.instance.getActiveAction();
|
|
28724
|
+
if (actualActions !== SELECTION_TOOL_ACTION_NAME) return;
|
|
28725
|
+
delete this.pointers[e.evt.pointerId];
|
|
28726
|
+
const selectedGroup = getTargetedNode(this.instance);
|
|
28727
|
+
this.triggerContextMenu(e.target, selectedGroup);
|
|
28728
|
+
}, this.tapHoldTimeout);
|
|
28729
|
+
});
|
|
28730
|
+
stage.on("pointerup", (e) => {
|
|
28731
|
+
delete this.pointers[e.evt.pointerId];
|
|
28732
|
+
if (e.evt.pointerType === "mouse") return;
|
|
28733
|
+
if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length + 1 > 1) return;
|
|
28734
|
+
if (this.timer) {
|
|
28735
|
+
clearTimeout(this.timer);
|
|
28736
|
+
this.timer = null;
|
|
28737
|
+
this.tapHold = false;
|
|
28738
|
+
}
|
|
28739
|
+
});
|
|
28740
|
+
stage.on("contextmenu", (e) => {
|
|
28741
|
+
e.evt.preventDefault();
|
|
28742
|
+
if (!this.enabled) return;
|
|
28743
|
+
const selectedGroup = getTargetedNode(this.instance);
|
|
28744
|
+
this.triggerContextMenu(e.target, selectedGroup);
|
|
28745
|
+
});
|
|
28746
|
+
this.instance.addEventListener("onStageSelection", () => {
|
|
28747
|
+
if (this.tapHold) return;
|
|
28748
|
+
const containerRect = stage.container().getBoundingClientRect();
|
|
28749
|
+
const pointerPos = stage.getPointerPosition();
|
|
28750
|
+
if (containerRect && pointerPos) {
|
|
28751
|
+
const contextMenuPoint = {
|
|
28752
|
+
x: containerRect.left + pointerPos.x + (this.config.xOffset ?? 4),
|
|
28753
|
+
y: containerRect.top + pointerPos.y + (this.config.yOffset ?? 4)
|
|
28754
|
+
};
|
|
28755
|
+
const stageClickPoint = this.getStageClickPoint(pointerPos);
|
|
28756
|
+
this.instance.emitEvent("onNodeContextMenu", {
|
|
28757
|
+
selection: [],
|
|
28758
|
+
contextMenuPoint,
|
|
28759
|
+
clickPoint: pointerPos,
|
|
28760
|
+
stageClickPoint,
|
|
28761
|
+
visible: false
|
|
28762
|
+
});
|
|
28763
|
+
}
|
|
28764
|
+
});
|
|
28765
|
+
}
|
|
28766
|
+
getStageClickPoint(pointerPos) {
|
|
28767
|
+
const stage = this.instance.getStage();
|
|
28768
|
+
const scale = stage.scale();
|
|
28769
|
+
const position = stage.position();
|
|
28770
|
+
const stageClickPoint = {
|
|
28771
|
+
x: (pointerPos.x - position.x) / scale.x,
|
|
28772
|
+
y: (pointerPos.y - position.y) / scale.y
|
|
28773
|
+
};
|
|
28774
|
+
return stageClickPoint;
|
|
28775
|
+
}
|
|
28776
|
+
isContextMenuVisible() {
|
|
28777
|
+
return this.contextMenuVisible;
|
|
28778
|
+
}
|
|
28779
|
+
isTapHold() {
|
|
28780
|
+
return this.tapHold;
|
|
28781
|
+
}
|
|
28782
|
+
enable() {
|
|
28783
|
+
this.enabled = true;
|
|
28784
|
+
}
|
|
28785
|
+
disable() {
|
|
28786
|
+
this.enabled = false;
|
|
28787
|
+
}
|
|
28788
|
+
};
|
|
28789
|
+
|
|
28601
28790
|
//#endregion
|
|
28602
28791
|
//#region src/plugins/stage-drop-area/constants.ts
|
|
28603
28792
|
const WEAVE_STAGE_DROP_AREA_KEY = "stageDropArea";
|
|
@@ -28625,18 +28814,18 @@ var WeaveStageDropAreaPlugin = class extends WeavePlugin {
|
|
|
28625
28814
|
stage.container().addEventListener("dragover", (e) => {
|
|
28626
28815
|
e.preventDefault();
|
|
28627
28816
|
e.stopPropagation();
|
|
28628
|
-
}, { signal: this.instance.getEventsController()
|
|
28817
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
28629
28818
|
stage.container().addEventListener("drop", (e) => {
|
|
28630
28819
|
e.preventDefault();
|
|
28631
28820
|
e.stopPropagation();
|
|
28632
28821
|
this.instance.emitEvent("onStageDrop", e);
|
|
28633
|
-
}, { signal: this.instance.getEventsController()
|
|
28822
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
28634
28823
|
window.addEventListener("dragover", (e) => e.preventDefault(), {
|
|
28635
|
-
signal: this.instance.getEventsController()
|
|
28824
|
+
signal: this.instance.getEventsController().signal,
|
|
28636
28825
|
passive: false
|
|
28637
28826
|
});
|
|
28638
28827
|
window.addEventListener("drop", (e) => e.preventDefault(), {
|
|
28639
|
-
signal: this.instance.getEventsController()
|
|
28828
|
+
signal: this.instance.getEventsController().signal,
|
|
28640
28829
|
passive: false
|
|
28641
28830
|
});
|
|
28642
28831
|
}
|
|
@@ -28804,7 +28993,7 @@ var WeaveStageKeyboardMovePlugin = class extends WeavePlugin {
|
|
|
28804
28993
|
if (e.code === "ArrowLeft") this.handleNodesMovement(WEAVE_STAGE_KEYBOARD_MOVE_ORIENTATION.LEFT, { isShiftPressed });
|
|
28805
28994
|
if (e.code === "ArrowRight") this.handleNodesMovement(WEAVE_STAGE_KEYBOARD_MOVE_ORIENTATION.RIGHT, { isShiftPressed });
|
|
28806
28995
|
if (e.code === "ArrowDown") this.handleNodesMovement(WEAVE_STAGE_KEYBOARD_MOVE_ORIENTATION.DOWN, { isShiftPressed });
|
|
28807
|
-
}, { signal: this.instance.getEventsController()
|
|
28996
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
28808
28997
|
}
|
|
28809
28998
|
enable() {
|
|
28810
28999
|
this.enabled = true;
|
|
@@ -28872,18 +29061,18 @@ var WeaveNodesSnappingCustomGuides = class {
|
|
|
28872
29061
|
const isOptionAltPressed = e.altKey;
|
|
28873
29062
|
this.cleanupDistanceGuide();
|
|
28874
29063
|
if (isOptionAltPressed && this.isDragging) this.handleDistanceGuide(isOptionAltPressed);
|
|
28875
|
-
}, { signal: this.instance.getEventsController()
|
|
29064
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
28876
29065
|
window.addEventListener("keyup", (e) => {
|
|
28877
29066
|
const isOptionAltPressed = e.key === "Alt" || e.key === "Option";
|
|
28878
29067
|
if (isOptionAltPressed) this.cleanupDistanceGuide();
|
|
28879
|
-
}, { signal: this.instance.getEventsController()
|
|
29068
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
28880
29069
|
window.addEventListener("keydown", (e) => {
|
|
28881
29070
|
const isOptionAltPressed = e.key === "Alt" || e.key === "Option";
|
|
28882
29071
|
if (isOptionAltPressed && this.isDragging) {
|
|
28883
29072
|
this.cleanupDistanceGuide();
|
|
28884
29073
|
this.handleDistanceGuide(isOptionAltPressed);
|
|
28885
29074
|
}
|
|
28886
|
-
}, { signal: this.instance.getEventsController()
|
|
29075
|
+
}, { signal: this.instance.getEventsController().signal });
|
|
28887
29076
|
}
|
|
28888
29077
|
getAllCustomGuides() {
|
|
28889
29078
|
return this.customGuides;
|
|
@@ -29082,7 +29271,7 @@ var WeaveNodesSnappingCustomGuides = class {
|
|
|
29082
29271
|
this.setupEvents = false;
|
|
29083
29272
|
}
|
|
29084
29273
|
if (!this.noGuidesVisible() && !this.setupEvents) {
|
|
29085
|
-
stage.container().addEventListener("keydown", this.handleArrowKeys, { signal: this.instance.getEventsController()
|
|
29274
|
+
stage.container().addEventListener("keydown", this.handleArrowKeys, { signal: this.instance.getEventsController().signal });
|
|
29086
29275
|
stage.on("pointerclick", this.handlePointerClick);
|
|
29087
29276
|
this.instance.addEventListener("onNodesChange", this.handleOnNodesSelectedChange);
|
|
29088
29277
|
this.instance.addEventListener("onStageMove", this.handleStagePanChange);
|