svelte-dnd-action 0.9.24 → 0.9.25
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/README.md +41 -21
- package/dist/index.d.ts +6 -0
- package/dist/index.js +42 -11
- package/dist/index.mjs +41 -12
- package/package.json +1 -1
- package/src/action.js +6 -1
- package/src/constants.js +1 -1
- package/src/featureFlags.js +32 -0
- package/src/helpers/styler.js +6 -5
- package/src/helpers/svelteNodeClone.js +22 -22
- package/src/index.js +2 -0
package/README.md
CHANGED
|
@@ -223,7 +223,25 @@ It applies globally (as in, all of your items everywhere are expected to have a
|
|
|
223
223
|
|
|
224
224
|
### Debug output
|
|
225
225
|
|
|
226
|
-
By default no debug output will be logged to the console. If you want to see internal debug messages, you can enable the debug output like this:
|
|
226
|
+
By default, no debug output will be logged to the console. If you want to see internal debug messages, you can enable the debug output like this:
|
|
227
|
+
|
|
228
|
+
```javascript
|
|
229
|
+
import {setDebugMode} from "svelte-dnd-action";
|
|
230
|
+
setDebugMode(true);
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Feature Flags
|
|
234
|
+
|
|
235
|
+
Feature flags allow controlling global optional behaviour. They were originally introduced as a way to enable a workaround for a browser bug that helps in certain scenarios but comes with unwanted side effects in others.
|
|
236
|
+
In order to set a feature flag use:
|
|
237
|
+
|
|
238
|
+
```javascript
|
|
239
|
+
import {setFeatueFlag, FEATURE_FLAG_NAMES} from "svelte-dnd-action";
|
|
240
|
+
setFeatueFlag(FEATURE_FLAG_NAMES.MY_FLAG, true);
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Currently, there is only one flag: USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT, which defaults to false.
|
|
244
|
+
See issues [454](https://github.com/isaacHagoel/svelte-dnd-action/issues/454) and [470](https://github.com/isaacHagoel/svelte-dnd-action/issues/470) for details about why it is needed and when (most users don't need to care about this)
|
|
227
245
|
|
|
228
246
|
```javascript
|
|
229
247
|
import {setDebugMode} from "svelte-dnd-action";
|
|
@@ -233,28 +251,31 @@ setDebugMode(true);
|
|
|
233
251
|
### Typescript
|
|
234
252
|
|
|
235
253
|
If you are using Typescript, you will need to add the following block to your `global.d.ts` (at least until [this svelte issue](https://github.com/sveltejs/language-tools/issues/431) is resolved):
|
|
254
|
+
|
|
236
255
|
#### Svelte 3 or below
|
|
256
|
+
|
|
237
257
|
```typescript
|
|
238
|
-
declare type Item = import(
|
|
239
|
-
declare type DndEvent<ItemType = Item> = import(
|
|
258
|
+
declare type Item = import("svelte-dnd-action").Item;
|
|
259
|
+
declare type DndEvent<ItemType = Item> = import("svelte-dnd-action").DndEvent<ItemType>;
|
|
240
260
|
declare namespace svelte.JSX {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
261
|
+
interface HTMLAttributes<T> {
|
|
262
|
+
onconsider?: (event: CustomEvent<DndEvent<ItemType>> & {target: EventTarget & T}) => void;
|
|
263
|
+
onfinalize?: (event: CustomEvent<DndEvent<ItemType>> & {target: EventTarget & T}) => void;
|
|
264
|
+
}
|
|
245
265
|
}
|
|
246
|
-
|
|
247
266
|
```
|
|
267
|
+
|
|
248
268
|
#### Svelte 4:
|
|
269
|
+
|
|
249
270
|
```typescript
|
|
250
|
-
declare type Item = import(
|
|
251
|
-
declare type DndEvent<ItemType = Item> = import(
|
|
271
|
+
declare type Item = import("svelte-dnd-action").Item;
|
|
272
|
+
declare type DndEvent<ItemType = Item> = import("svelte-dnd-action").DndEvent<ItemType>;
|
|
252
273
|
declare namespace svelteHTML {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
274
|
+
interface HTMLAttributes<T> {
|
|
275
|
+
"on:consider"?: (event: CustomEvent<DndEvent<ItemType>> & {target: EventTarget & T}) => void;
|
|
276
|
+
"on:finalize"?: (event: CustomEvent<DndEvent<ItemType>> & {target: EventTarget & T}) => void;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
258
279
|
```
|
|
259
280
|
|
|
260
281
|
You may need to edit `tsconfig.json` to include `global.d.ts` if it doesn't already: "include": ["src/**/*", "global.d.ts"].
|
|
@@ -318,15 +339,14 @@ You can use generics to set the type of `items` you are expecting in `DndEvent`.
|
|
|
318
339
|
items = e.detail.items;
|
|
319
340
|
}
|
|
320
341
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
342
|
+
let items: Dog[] = [
|
|
343
|
+
{id: 1, name: "Fido", breed: "bulldog"},
|
|
344
|
+
{id: 2, name: "Spot", breed: "labrador"},
|
|
345
|
+
{id: 3, name: "Jacky", breed: "golden retriever"}
|
|
346
|
+
];
|
|
326
347
|
</script>
|
|
327
348
|
```
|
|
328
349
|
|
|
329
|
-
|
|
330
350
|
### Contributing [](https://github.com/isaacHagoel/svelte-dnd-action/issues)
|
|
331
351
|
|
|
332
352
|
There is still quite a lot to do. If you'd like to contribute please get in touch (raise an issue or comment on an existing one).
|
package/dist/index.d.ts
CHANGED
|
@@ -83,3 +83,9 @@ export declare const DRAGGED_ELEMENT_ID: "dnd-action-dragged-el";
|
|
|
83
83
|
* Allows the user to show/hide console debug output
|
|
84
84
|
*/
|
|
85
85
|
export declare function setDebugMode(isDebug: boolean): void;
|
|
86
|
+
|
|
87
|
+
export enum FEATURE_FLAG_NAMES {
|
|
88
|
+
// Default value: false, This flag exists as a workaround for issue 454 (basically a browser bug) - seems like these rect values take time to update when in grid layout. Setting it to true can cause strange behaviour in the REPL for non-grid zones, see issue 470
|
|
89
|
+
USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT = "FEATURE_FLAG_NAMES.USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT"
|
|
90
|
+
}
|
|
91
|
+
export declare function setFeatureFlag(flagName: FEATURE_FLAG_NAMES, flagValue: boolean);
|
package/dist/index.js
CHANGED
|
@@ -332,7 +332,7 @@
|
|
|
332
332
|
|
|
333
333
|
/**
|
|
334
334
|
* Allows the user to show/hide console debug output
|
|
335
|
-
* * @param {
|
|
335
|
+
* * @param {boolean} isDebug
|
|
336
336
|
*/
|
|
337
337
|
function setDebugMode(isDebug) {
|
|
338
338
|
if (isDebug) {
|
|
@@ -950,15 +950,15 @@
|
|
|
950
950
|
* Since svelte manages select value internally.
|
|
951
951
|
* @see https://github.com/sveltejs/svelte/issues/6717
|
|
952
952
|
* @see https://github.com/isaacHagoel/svelte-dnd-action/issues/306
|
|
953
|
-
*
|
|
954
|
-
* @param {HTMLElement} el
|
|
955
|
-
* @returns
|
|
953
|
+
*
|
|
954
|
+
* @param {HTMLElement} el
|
|
955
|
+
* @returns
|
|
956
956
|
*/
|
|
957
957
|
function svelteNodeClone(el) {
|
|
958
958
|
var cloned = el.cloneNode(true);
|
|
959
959
|
var values = [];
|
|
960
960
|
var elIsSelect = el.tagName === "SELECT";
|
|
961
|
-
var selects = elIsSelect ? [el] : _toConsumableArray(el.querySelectorAll(
|
|
961
|
+
var selects = elIsSelect ? [el] : _toConsumableArray(el.querySelectorAll("select"));
|
|
962
962
|
var _iterator = _createForOfIteratorHelper(selects),
|
|
963
963
|
_step;
|
|
964
964
|
try {
|
|
@@ -974,18 +974,46 @@
|
|
|
974
974
|
if (selects.length <= 0) {
|
|
975
975
|
return cloned;
|
|
976
976
|
}
|
|
977
|
-
var clonedSelects = elIsSelect ? [cloned] : _toConsumableArray(cloned.querySelectorAll(
|
|
977
|
+
var clonedSelects = elIsSelect ? [cloned] : _toConsumableArray(cloned.querySelectorAll("select"));
|
|
978
978
|
for (var i = 0; i < clonedSelects.length; i++) {
|
|
979
979
|
var select = clonedSelects[i];
|
|
980
980
|
var value = values[i];
|
|
981
981
|
var optionEl = select.querySelector("option[value=\"".concat(value, "\""));
|
|
982
982
|
if (optionEl) {
|
|
983
|
-
optionEl.setAttribute(
|
|
983
|
+
optionEl.setAttribute("selected", true);
|
|
984
984
|
}
|
|
985
985
|
}
|
|
986
986
|
return cloned;
|
|
987
987
|
}
|
|
988
988
|
|
|
989
|
+
/**
|
|
990
|
+
* @type {{USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT: string}}
|
|
991
|
+
*/
|
|
992
|
+
var FEATURE_FLAG_NAMES = Object.freeze({
|
|
993
|
+
// This flag exists as a workaround for issue 454 (basically a browser bug) - seems like these rect values take time to update when in grid layout. Setting it to true can cause strange behaviour in the REPL for non-grid zones, see issue 470
|
|
994
|
+
USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT: "USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT"
|
|
995
|
+
});
|
|
996
|
+
var featureFlagsMap = _defineProperty({}, FEATURE_FLAG_NAMES.USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT, false);
|
|
997
|
+
|
|
998
|
+
/**
|
|
999
|
+
* @param {FEATURE_FLAG_NAMES} flagName
|
|
1000
|
+
* @param {boolean} flagValue
|
|
1001
|
+
*/
|
|
1002
|
+
function setFeatureFlag(flagName, flagValue) {
|
|
1003
|
+
if (!FEATURE_FLAG_NAMES[flagName]) throw new Error("Can't set non existing feature flag ".concat(flagName, "! Supported flags: ").concat(Object.keys(FEATURE_FLAG_NAMES)));
|
|
1004
|
+
featureFlagsMap[flagName] = !!flagValue;
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
/**
|
|
1008
|
+
*
|
|
1009
|
+
* @param {FEATURE_FLAG_NAMES} flagName
|
|
1010
|
+
* @return {boolean}
|
|
1011
|
+
*/
|
|
1012
|
+
function getFeatureFlag(flagName) {
|
|
1013
|
+
if (!FEATURE_FLAG_NAMES[flagName]) throw new Error("Can't get non existing feature flag ".concat(flagName, "! Supported flags: ").concat(Object.keys(FEATURE_FLAG_NAMES)));
|
|
1014
|
+
return featureFlagsMap[flagName];
|
|
1015
|
+
}
|
|
1016
|
+
|
|
989
1017
|
var TRANSITION_DURATION_SECONDS = 0.2;
|
|
990
1018
|
|
|
991
1019
|
/**
|
|
@@ -1062,9 +1090,10 @@
|
|
|
1062
1090
|
left: (currentMouseX - draggedElRect.left) / draggedElRect.width,
|
|
1063
1091
|
top: (currentMouseY - draggedElRect.top) / draggedElRect.height
|
|
1064
1092
|
};
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1093
|
+
if (!getFeatureFlag(FEATURE_FLAG_NAMES.USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT)) {
|
|
1094
|
+
draggedEl.style.height = "".concat(newRect.height, "px");
|
|
1095
|
+
draggedEl.style.width = "".concat(newRect.width, "px");
|
|
1096
|
+
}
|
|
1068
1097
|
draggedEl.style.left = "".concat(parseFloat(draggedEl.style.left) - relativeDistanceOfMousePointerFromDraggedSides.left * widthChange, "px");
|
|
1069
1098
|
draggedEl.style.top = "".concat(parseFloat(draggedEl.style.top) - relativeDistanceOfMousePointerFromDraggedSides.top * heightChange, "px");
|
|
1070
1099
|
}
|
|
@@ -1079,7 +1108,7 @@
|
|
|
1079
1108
|
Array.from(computedStyle).filter(function (s) {
|
|
1080
1109
|
return s.startsWith("background") || s.startsWith("padding") || s.startsWith("font") || s.startsWith("text") || s.startsWith("align") || s.startsWith("justify") || s.startsWith("display") || s.startsWith("flex") || s.startsWith("border") || s === "opacity" || s === "color" || s === "list-style-type" ||
|
|
1081
1110
|
// copying with and height to make up for rect update timing issues in some browsers
|
|
1082
|
-
s === "width" || s === "height";
|
|
1111
|
+
getFeatureFlag(FEATURE_FLAG_NAMES.USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT) && (s === "width" || s === "height");
|
|
1083
1112
|
}).forEach(function (s) {
|
|
1084
1113
|
return copyToEl.style.setProperty(s, computedStyle.getPropertyValue(s), computedStyle.getPropertyPriority(s));
|
|
1085
1114
|
});
|
|
@@ -2410,6 +2439,7 @@
|
|
|
2410
2439
|
}
|
|
2411
2440
|
|
|
2412
2441
|
exports.DRAGGED_ELEMENT_ID = DRAGGED_ELEMENT_ID;
|
|
2442
|
+
exports.FEATURE_FLAG_NAMES = FEATURE_FLAG_NAMES;
|
|
2413
2443
|
exports.SHADOW_ITEM_MARKER_PROPERTY_NAME = SHADOW_ITEM_MARKER_PROPERTY_NAME;
|
|
2414
2444
|
exports.SHADOW_PLACEHOLDER_ITEM_ID = SHADOW_PLACEHOLDER_ITEM_ID;
|
|
2415
2445
|
exports.SOURCES = SOURCES;
|
|
@@ -2418,6 +2448,7 @@
|
|
|
2418
2448
|
exports.dndzone = dndzone$2;
|
|
2419
2449
|
exports.overrideItemIdKeyNameBeforeInitialisingDndZones = overrideItemIdKeyNameBeforeInitialisingDndZones;
|
|
2420
2450
|
exports.setDebugMode = setDebugMode;
|
|
2451
|
+
exports.setFeatureFlag = setFeatureFlag;
|
|
2421
2452
|
|
|
2422
2453
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2423
2454
|
|
package/dist/index.mjs
CHANGED
|
@@ -326,7 +326,7 @@ var printDebug = function printDebug() {};
|
|
|
326
326
|
|
|
327
327
|
/**
|
|
328
328
|
* Allows the user to show/hide console debug output
|
|
329
|
-
* * @param {
|
|
329
|
+
* * @param {boolean} isDebug
|
|
330
330
|
*/
|
|
331
331
|
function setDebugMode(isDebug) {
|
|
332
332
|
if (isDebug) {
|
|
@@ -944,15 +944,15 @@ function disarmWindowScroller() {
|
|
|
944
944
|
* Since svelte manages select value internally.
|
|
945
945
|
* @see https://github.com/sveltejs/svelte/issues/6717
|
|
946
946
|
* @see https://github.com/isaacHagoel/svelte-dnd-action/issues/306
|
|
947
|
-
*
|
|
948
|
-
* @param {HTMLElement} el
|
|
949
|
-
* @returns
|
|
947
|
+
*
|
|
948
|
+
* @param {HTMLElement} el
|
|
949
|
+
* @returns
|
|
950
950
|
*/
|
|
951
951
|
function svelteNodeClone(el) {
|
|
952
952
|
var cloned = el.cloneNode(true);
|
|
953
953
|
var values = [];
|
|
954
954
|
var elIsSelect = el.tagName === "SELECT";
|
|
955
|
-
var selects = elIsSelect ? [el] : _toConsumableArray(el.querySelectorAll(
|
|
955
|
+
var selects = elIsSelect ? [el] : _toConsumableArray(el.querySelectorAll("select"));
|
|
956
956
|
var _iterator = _createForOfIteratorHelper(selects),
|
|
957
957
|
_step;
|
|
958
958
|
try {
|
|
@@ -968,18 +968,46 @@ function svelteNodeClone(el) {
|
|
|
968
968
|
if (selects.length <= 0) {
|
|
969
969
|
return cloned;
|
|
970
970
|
}
|
|
971
|
-
var clonedSelects = elIsSelect ? [cloned] : _toConsumableArray(cloned.querySelectorAll(
|
|
971
|
+
var clonedSelects = elIsSelect ? [cloned] : _toConsumableArray(cloned.querySelectorAll("select"));
|
|
972
972
|
for (var i = 0; i < clonedSelects.length; i++) {
|
|
973
973
|
var select = clonedSelects[i];
|
|
974
974
|
var value = values[i];
|
|
975
975
|
var optionEl = select.querySelector("option[value=\"".concat(value, "\""));
|
|
976
976
|
if (optionEl) {
|
|
977
|
-
optionEl.setAttribute(
|
|
977
|
+
optionEl.setAttribute("selected", true);
|
|
978
978
|
}
|
|
979
979
|
}
|
|
980
980
|
return cloned;
|
|
981
981
|
}
|
|
982
982
|
|
|
983
|
+
/**
|
|
984
|
+
* @type {{USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT: string}}
|
|
985
|
+
*/
|
|
986
|
+
var FEATURE_FLAG_NAMES = Object.freeze({
|
|
987
|
+
// This flag exists as a workaround for issue 454 (basically a browser bug) - seems like these rect values take time to update when in grid layout. Setting it to true can cause strange behaviour in the REPL for non-grid zones, see issue 470
|
|
988
|
+
USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT: "USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT"
|
|
989
|
+
});
|
|
990
|
+
var featureFlagsMap = _defineProperty({}, FEATURE_FLAG_NAMES.USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT, false);
|
|
991
|
+
|
|
992
|
+
/**
|
|
993
|
+
* @param {FEATURE_FLAG_NAMES} flagName
|
|
994
|
+
* @param {boolean} flagValue
|
|
995
|
+
*/
|
|
996
|
+
function setFeatureFlag(flagName, flagValue) {
|
|
997
|
+
if (!FEATURE_FLAG_NAMES[flagName]) throw new Error("Can't set non existing feature flag ".concat(flagName, "! Supported flags: ").concat(Object.keys(FEATURE_FLAG_NAMES)));
|
|
998
|
+
featureFlagsMap[flagName] = !!flagValue;
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
/**
|
|
1002
|
+
*
|
|
1003
|
+
* @param {FEATURE_FLAG_NAMES} flagName
|
|
1004
|
+
* @return {boolean}
|
|
1005
|
+
*/
|
|
1006
|
+
function getFeatureFlag(flagName) {
|
|
1007
|
+
if (!FEATURE_FLAG_NAMES[flagName]) throw new Error("Can't get non existing feature flag ".concat(flagName, "! Supported flags: ").concat(Object.keys(FEATURE_FLAG_NAMES)));
|
|
1008
|
+
return featureFlagsMap[flagName];
|
|
1009
|
+
}
|
|
1010
|
+
|
|
983
1011
|
var TRANSITION_DURATION_SECONDS = 0.2;
|
|
984
1012
|
|
|
985
1013
|
/**
|
|
@@ -1056,9 +1084,10 @@ function morphDraggedElementToBeLike(draggedEl, copyFromEl, currentMouseX, curre
|
|
|
1056
1084
|
left: (currentMouseX - draggedElRect.left) / draggedElRect.width,
|
|
1057
1085
|
top: (currentMouseY - draggedElRect.top) / draggedElRect.height
|
|
1058
1086
|
};
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1087
|
+
if (!getFeatureFlag(FEATURE_FLAG_NAMES.USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT)) {
|
|
1088
|
+
draggedEl.style.height = "".concat(newRect.height, "px");
|
|
1089
|
+
draggedEl.style.width = "".concat(newRect.width, "px");
|
|
1090
|
+
}
|
|
1062
1091
|
draggedEl.style.left = "".concat(parseFloat(draggedEl.style.left) - relativeDistanceOfMousePointerFromDraggedSides.left * widthChange, "px");
|
|
1063
1092
|
draggedEl.style.top = "".concat(parseFloat(draggedEl.style.top) - relativeDistanceOfMousePointerFromDraggedSides.top * heightChange, "px");
|
|
1064
1093
|
}
|
|
@@ -1073,7 +1102,7 @@ function copyStylesFromTo(copyFromEl, copyToEl) {
|
|
|
1073
1102
|
Array.from(computedStyle).filter(function (s) {
|
|
1074
1103
|
return s.startsWith("background") || s.startsWith("padding") || s.startsWith("font") || s.startsWith("text") || s.startsWith("align") || s.startsWith("justify") || s.startsWith("display") || s.startsWith("flex") || s.startsWith("border") || s === "opacity" || s === "color" || s === "list-style-type" ||
|
|
1075
1104
|
// copying with and height to make up for rect update timing issues in some browsers
|
|
1076
|
-
s === "width" || s === "height";
|
|
1105
|
+
getFeatureFlag(FEATURE_FLAG_NAMES.USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT) && (s === "width" || s === "height");
|
|
1077
1106
|
}).forEach(function (s) {
|
|
1078
1107
|
return copyToEl.style.setProperty(s, computedStyle.getPropertyValue(s), computedStyle.getPropertyPriority(s));
|
|
1079
1108
|
});
|
|
@@ -2403,4 +2432,4 @@ function isInt(value) {
|
|
|
2403
2432
|
}(parseFloat(value));
|
|
2404
2433
|
}
|
|
2405
2434
|
|
|
2406
|
-
export { DRAGGED_ELEMENT_ID, SHADOW_ITEM_MARKER_PROPERTY_NAME, SHADOW_PLACEHOLDER_ITEM_ID, SOURCES, TRIGGERS, alertToScreenReader, dndzone$2 as dndzone, overrideItemIdKeyNameBeforeInitialisingDndZones, setDebugMode };
|
|
2435
|
+
export { DRAGGED_ELEMENT_ID, FEATURE_FLAG_NAMES, SHADOW_ITEM_MARKER_PROPERTY_NAME, SHADOW_PLACEHOLDER_ITEM_ID, SOURCES, TRIGGERS, alertToScreenReader, dndzone$2 as dndzone, overrideItemIdKeyNameBeforeInitialisingDndZones, setDebugMode, setFeatureFlag };
|
package/package.json
CHANGED
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"dist"
|
|
44
44
|
],
|
|
45
45
|
"description": "*An awesome drag and drop library for Svelte 3 (not using the browser's built-in dnd, thanks god): Rich animations, nested containers, touch support and more *",
|
|
46
|
-
"version": "0.9.
|
|
46
|
+
"version": "0.9.25",
|
|
47
47
|
"repository": {
|
|
48
48
|
"type": "git",
|
|
49
49
|
"url": "git+https://github.com/isaacHagoel/svelte-dnd-action.git"
|
package/src/action.js
CHANGED
|
@@ -78,5 +78,10 @@ function validateOptions(options) {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
function isInt(value) {
|
|
81
|
-
return
|
|
81
|
+
return (
|
|
82
|
+
!isNaN(value) &&
|
|
83
|
+
(function (x) {
|
|
84
|
+
return (x | 0) === x;
|
|
85
|
+
})(parseFloat(value))
|
|
86
|
+
);
|
|
82
87
|
}
|
package/src/constants.js
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @type {{USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT: string}}
|
|
3
|
+
*/
|
|
4
|
+
export const FEATURE_FLAG_NAMES = Object.freeze({
|
|
5
|
+
// This flag exists as a workaround for issue 454 (basically a browser bug) - seems like these rect values take time to update when in grid layout. Setting it to true can cause strange behaviour in the REPL for non-grid zones, see issue 470
|
|
6
|
+
USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT: "USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT"
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const featureFlagsMap = {
|
|
10
|
+
[FEATURE_FLAG_NAMES.USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT]: false
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {FEATURE_FLAG_NAMES} flagName
|
|
15
|
+
* @param {boolean} flagValue
|
|
16
|
+
*/
|
|
17
|
+
export function setFeatureFlag(flagName, flagValue) {
|
|
18
|
+
if (!FEATURE_FLAG_NAMES[flagName])
|
|
19
|
+
throw new Error(`Can't set non existing feature flag ${flagName}! Supported flags: ${Object.keys(FEATURE_FLAG_NAMES)}`);
|
|
20
|
+
featureFlagsMap[flagName] = !!flagValue;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @param {FEATURE_FLAG_NAMES} flagName
|
|
26
|
+
* @return {boolean}
|
|
27
|
+
*/
|
|
28
|
+
export function getFeatureFlag(flagName) {
|
|
29
|
+
if (!FEATURE_FLAG_NAMES[flagName])
|
|
30
|
+
throw new Error(`Can't get non existing feature flag ${flagName}! Supported flags: ${Object.keys(FEATURE_FLAG_NAMES)}`);
|
|
31
|
+
return featureFlagsMap[flagName];
|
|
32
|
+
}
|
package/src/helpers/styler.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {SHADOW_ELEMENT_ATTRIBUTE_NAME, DRAGGED_ELEMENT_ID} from "../constants";
|
|
2
2
|
import {findCenter} from "./intersection";
|
|
3
3
|
import {svelteNodeClone} from "./svelteNodeClone";
|
|
4
|
+
import {getFeatureFlag, FEATURE_FLAG_NAMES} from "../featureFlags";
|
|
4
5
|
|
|
5
6
|
const TRANSITION_DURATION_SECONDS = 0.2;
|
|
6
7
|
|
|
@@ -77,9 +78,10 @@ export function morphDraggedElementToBeLike(draggedEl, copyFromEl, currentMouseX
|
|
|
77
78
|
left: (currentMouseX - draggedElRect.left) / draggedElRect.width,
|
|
78
79
|
top: (currentMouseY - draggedElRect.top) / draggedElRect.height
|
|
79
80
|
};
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
if (!getFeatureFlag(FEATURE_FLAG_NAMES.USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT)) {
|
|
82
|
+
draggedEl.style.height = `${newRect.height}px`;
|
|
83
|
+
draggedEl.style.width = `${newRect.width}px`;
|
|
84
|
+
}
|
|
83
85
|
draggedEl.style.left = `${parseFloat(draggedEl.style.left) - relativeDistanceOfMousePointerFromDraggedSides.left * widthChange}px`;
|
|
84
86
|
draggedEl.style.top = `${parseFloat(draggedEl.style.top) - relativeDistanceOfMousePointerFromDraggedSides.top * heightChange}px`;
|
|
85
87
|
}
|
|
@@ -107,8 +109,7 @@ function copyStylesFromTo(copyFromEl, copyToEl) {
|
|
|
107
109
|
s === "color" ||
|
|
108
110
|
s === "list-style-type" ||
|
|
109
111
|
// copying with and height to make up for rect update timing issues in some browsers
|
|
110
|
-
s === "width" ||
|
|
111
|
-
s === "height"
|
|
112
|
+
(getFeatureFlag(FEATURE_FLAG_NAMES.USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT) && (s === "width" || s === "height"))
|
|
112
113
|
)
|
|
113
114
|
.forEach(s => copyToEl.style.setProperty(s, computedStyle.getPropertyValue(s), computedStyle.getPropertyPriority(s)));
|
|
114
115
|
}
|
|
@@ -3,33 +3,33 @@
|
|
|
3
3
|
* Since svelte manages select value internally.
|
|
4
4
|
* @see https://github.com/sveltejs/svelte/issues/6717
|
|
5
5
|
* @see https://github.com/isaacHagoel/svelte-dnd-action/issues/306
|
|
6
|
-
*
|
|
7
|
-
* @param {HTMLElement} el
|
|
8
|
-
* @returns
|
|
6
|
+
*
|
|
7
|
+
* @param {HTMLElement} el
|
|
8
|
+
* @returns
|
|
9
9
|
*/
|
|
10
10
|
export function svelteNodeClone(el) {
|
|
11
|
-
|
|
11
|
+
const cloned = el.cloneNode(true);
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
const values = [];
|
|
14
|
+
const elIsSelect = el.tagName === "SELECT";
|
|
15
|
+
const selects = elIsSelect ? [el] : [...el.querySelectorAll("select")];
|
|
16
|
+
for (const select of selects) {
|
|
17
|
+
values.push(select.value);
|
|
18
|
+
}
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
if (selects.length <= 0) {
|
|
21
|
+
return cloned;
|
|
22
|
+
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
const clonedSelects = elIsSelect ? [cloned] : [...cloned.querySelectorAll("select")];
|
|
25
|
+
for (let i = 0; i < clonedSelects.length; i++) {
|
|
26
|
+
const select = clonedSelects[i];
|
|
27
|
+
const value = values[i];
|
|
28
|
+
const optionEl = select.querySelector(`option[value="${value}"`);
|
|
29
|
+
if (optionEl) {
|
|
30
|
+
optionEl.setAttribute("selected", true);
|
|
31
|
+
}
|
|
31
32
|
}
|
|
32
|
-
}
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
return cloned;
|
|
35
35
|
}
|