@dflex/draggable
Advanced tools
Comparing version 3.5.1 to 3.5.2
@@ -1,52 +0,6 @@ | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var __accessCheck = (obj, member, msg) => { | ||
if (!member.has(obj)) | ||
throw TypeError("Cannot " + msg); | ||
}; | ||
var __privateGet = (obj, member, getter) => { | ||
__accessCheck(obj, member, "read from private field"); | ||
return getter ? getter.call(obj) : member.get(obj); | ||
}; | ||
var __privateAdd = (obj, member, value) => { | ||
if (member.has(obj)) | ||
throw TypeError("Cannot add the same private member more than once"); | ||
member instanceof WeakSet ? member.add(obj) : member.set(obj, value); | ||
}; | ||
var __privateSet = (obj, member, value, setter) => { | ||
__accessCheck(obj, member, "write to private field"); | ||
setter ? setter.call(obj, value) : member.set(obj, value); | ||
return value; | ||
}; | ||
var __privateMethod = (obj, member, method) => { | ||
__accessCheck(obj, member, "access private method"); | ||
return method; | ||
}; | ||
'use strict'; | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
AbstractDraggable: () => AbstractDraggable_default, | ||
Draggable: () => Draggable_default, | ||
store: () => DraggableStoreImp_default | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
// ../utils/src/Point/Point.ts | ||
var Point = class { | ||
class Point { | ||
constructor(x, y) { | ||
@@ -71,7 +25,5 @@ this.setAxes(x, y); | ||
} | ||
}; | ||
var Point_default = Point; | ||
} | ||
// ../utils/src/Point/PointNum.ts | ||
var PointNum = class extends Point_default { | ||
class PointNum extends Point { | ||
increase(point) { | ||
@@ -92,273 +44,46 @@ this.x += point.x; | ||
} | ||
}; | ||
var PointNum_default = PointNum; | ||
// ../utils/src/Threshold/FourDirectionsBool.ts | ||
var FourDirectionsBool = class { | ||
constructor() { | ||
this.reset(); | ||
} | ||
reset() { | ||
this.isLeftFromTop = false; | ||
this.isLeftFromBottom = false; | ||
this.isLeftFromLeft = false; | ||
this.isLeftFromRight = false; | ||
} | ||
isOutY() { | ||
return this.isLeftFromTop || this.isLeftFromBottom; | ||
} | ||
setOutY(up, down) { | ||
this.isLeftFromTop = up; | ||
this.isLeftFromBottom = down; | ||
} | ||
setOutYFalsy() { | ||
this.isLeftFromTop = false; | ||
this.isLeftFromBottom = false; | ||
} | ||
isOutX() { | ||
return this.isLeftFromLeft || this.isLeftFromRight; | ||
} | ||
setOutX(left, right) { | ||
this.isLeftFromLeft = left; | ||
this.isLeftFromRight = right; | ||
} | ||
setOutXFalsy() { | ||
this.isLeftFromLeft = false; | ||
this.isLeftFromRight = false; | ||
} | ||
}; | ||
var FourDirectionsBool_default = FourDirectionsBool; | ||
// ../utils/src/collections/assignBiggestRect.ts | ||
function dirtyAssignBiggestRect($, elm) { | ||
const { top, left, right, bottom } = elm; | ||
if (left < $.left) { | ||
$.left = left; | ||
} | ||
if (top < $.top) { | ||
$.top = top; | ||
} | ||
if (right > $.right) { | ||
$.right = right; | ||
} | ||
if (bottom > $.bottom) { | ||
$.bottom = bottom; | ||
} | ||
} | ||
var assignBiggestRect_default = dirtyAssignBiggestRect; | ||
// ../utils/src/collections/combineKeys.ts | ||
function combineKeys(k1, k2) { | ||
return `${k1}-${k2}`; | ||
} | ||
var combineKeys_default = combineKeys; | ||
// ../utils/src/Threshold/Threshold.ts | ||
var _pixels, _percentages, _setPixels, setPixels_fn, _initIndicators, initIndicators_fn, _getScrollThreshold, getScrollThreshold_fn, _getThreshold, getThreshold_fn, _createThreshold, createThreshold_fn, _addDepthThreshold, addDepthThreshold_fn; | ||
var Threshold = class { | ||
constructor(percentages) { | ||
__privateAdd(this, _setPixels); | ||
__privateAdd(this, _initIndicators); | ||
__privateAdd(this, _getScrollThreshold); | ||
__privateAdd(this, _getThreshold); | ||
__privateAdd(this, _createThreshold); | ||
__privateAdd(this, _addDepthThreshold); | ||
__privateAdd(this, _pixels, void 0); | ||
__privateAdd(this, _percentages, void 0); | ||
__privateSet(this, _percentages, percentages); | ||
this.thresholds = {}; | ||
this.isOut = {}; | ||
process.env.NODE_ENV === "production"; | ||
class Generator { | ||
constructor() { | ||
this.indicator = {}; | ||
this.branches = {}; | ||
this.branchesByDepth = {}; | ||
this.prevDepth = -99; | ||
this.prevKey = combineKeys(0, 0); | ||
} | ||
setScrollThreshold(key, rect) { | ||
__privateMethod(this, _setPixels, setPixels_fn).call(this, rect); | ||
this.thresholds[key] = __privateMethod(this, _getScrollThreshold, getScrollThreshold_fn).call(this, rect); | ||
if (!this.isOut[key]) { | ||
this.isOut[key] = new FourDirectionsBool_default(); | ||
} else { | ||
this.isOut[key].reset(); | ||
initIndicators(dp) { | ||
if (this.indicator[dp] === void 0) { | ||
this.indicator[dp] = -1; | ||
} | ||
if (this.indicator[dp + 1] === void 0) { | ||
this.indicator[dp + 1] = 0; | ||
} | ||
if (this.indicator[dp + 2] === void 0) { | ||
this.indicator[dp + 2] = 0; | ||
} | ||
} | ||
setMainThreshold(key, rect) { | ||
__privateMethod(this, _setPixels, setPixels_fn).call(this, rect); | ||
const { top, left, height, width } = rect; | ||
__privateMethod(this, _createThreshold, createThreshold_fn).call(this, key, { | ||
top, | ||
left, | ||
bottom: top + height, | ||
right: left + width | ||
}); | ||
addElementIDToDepthCollection(SK, depth) { | ||
if (!Array.isArray(this.branchesByDepth[depth])) { | ||
this.branchesByDepth[depth] = [SK]; | ||
return; | ||
} | ||
const is = this.branchesByDepth[depth].find((k) => k === SK); | ||
if (!is) { | ||
this.branchesByDepth[depth].push(SK); | ||
} | ||
} | ||
setContainerThreshold(key, depth, rect, unifiedContainerDimensions) { | ||
__privateMethod(this, _createThreshold, createThreshold_fn).call(this, key, rect); | ||
queueMicrotask(() => { | ||
const { top, left } = rect; | ||
const { height, width } = unifiedContainerDimensions; | ||
const composedK = combineKeys_default(depth, key); | ||
__privateMethod(this, _createThreshold, createThreshold_fn).call(this, composedK, { | ||
left, | ||
top, | ||
right: left + width, | ||
bottom: top + height | ||
}); | ||
__privateMethod(this, _addDepthThreshold, addDepthThreshold_fn).call(this, composedK, depth); | ||
}); | ||
} | ||
isOutThresholdH(key, XLeft, XRight) { | ||
const { left, right } = this.thresholds[key]; | ||
this.isOut[key].setOutX(XLeft < left, XRight > right); | ||
return this.isOut[key].isOutX(); | ||
} | ||
isOutThresholdV(key, YTop, YBottom) { | ||
const { top, bottom } = this.thresholds[key]; | ||
this.isOut[key].setOutY(YTop < top, YBottom > bottom); | ||
return this.isOut[key].isOutY(); | ||
} | ||
destroy() { | ||
this.thresholds = null; | ||
this.isOut = null; | ||
} | ||
}; | ||
_pixels = new WeakMap(); | ||
_percentages = new WeakMap(); | ||
_setPixels = new WeakSet(); | ||
setPixels_fn = function({ width, height }) { | ||
const x = Math.round(__privateGet(this, _percentages).horizontal * width / 100); | ||
const y = Math.round(__privateGet(this, _percentages).vertical * height / 100); | ||
__privateSet(this, _pixels, new PointNum_default(x, y)); | ||
}; | ||
_initIndicators = new WeakSet(); | ||
initIndicators_fn = function(key) { | ||
if (!this.isOut[key]) { | ||
this.isOut[key] = new FourDirectionsBool_default(); | ||
} else { | ||
this.isOut[key].reset(); | ||
} | ||
}; | ||
_getScrollThreshold = new WeakSet(); | ||
getScrollThreshold_fn = function(rect) { | ||
const { top, left, height, width } = rect; | ||
const { x, y } = __privateGet(this, _pixels); | ||
return { | ||
left: Math.abs(left - x), | ||
right: left - x + width, | ||
top: Math.abs(top - y), | ||
bottom: height - y | ||
}; | ||
}; | ||
_getThreshold = new WeakSet(); | ||
getThreshold_fn = function(rect) { | ||
const { top, left, bottom, right } = rect; | ||
const { x, y } = __privateGet(this, _pixels); | ||
return { | ||
left: left - x, | ||
right: right + x, | ||
top: top - y, | ||
bottom: bottom + y | ||
}; | ||
}; | ||
_createThreshold = new WeakSet(); | ||
createThreshold_fn = function(key, rect) { | ||
this.thresholds[key] = __privateMethod(this, _getThreshold, getThreshold_fn).call(this, rect); | ||
__privateMethod(this, _initIndicators, initIndicators_fn).call(this, key); | ||
}; | ||
_addDepthThreshold = new WeakSet(); | ||
addDepthThreshold_fn = function(key, depth) { | ||
const dp = `${depth}`; | ||
if (!this.thresholds[dp]) { | ||
__privateMethod(this, _createThreshold, createThreshold_fn).call(this, dp, { | ||
...this.thresholds[key] | ||
}); | ||
return; | ||
} | ||
const $ = this.thresholds[depth]; | ||
assignBiggestRect_default($, this.thresholds[key]); | ||
}; | ||
// ../utils/src/Tracker/Tracker.ts | ||
var _prefix; | ||
var Tracker = class { | ||
constructor(prefix) { | ||
__privateAdd(this, _prefix, void 0); | ||
this.travelID = 0; | ||
if (prefix) { | ||
__privateSet(this, _prefix, prefix); | ||
addElementIDToSiblingsBranch(id, SK) { | ||
if (!Array.isArray(this.branches[SK])) { | ||
this.branches[SK] = []; | ||
} | ||
const selfIndex = this.branches[SK].push(id) - 1; | ||
return selfIndex; | ||
} | ||
newTravel(prefix) { | ||
const pre = prefix || __privateGet(this, _prefix); | ||
this.travelID += 1; | ||
return pre ? `${pre}-${this.travelID}` : `${this.travelID}`; | ||
} | ||
}; | ||
_prefix = new WeakMap(); | ||
// ../utils/src/Migration/Migration.ts | ||
var AbstractMigration = class { | ||
constructor(index, SK, id) { | ||
this.index = index; | ||
this.SK = SK; | ||
this.id = id; | ||
this.marginBottom = null; | ||
this.marginTop = null; | ||
} | ||
}; | ||
var _migrations; | ||
var Migration = class { | ||
constructor(index, SK, id) { | ||
__privateAdd(this, _migrations, void 0); | ||
__privateSet(this, _migrations, [new AbstractMigration(index, SK, id)]); | ||
this.complete(); | ||
} | ||
latest() { | ||
return __privateGet(this, _migrations)[__privateGet(this, _migrations).length - 1]; | ||
} | ||
prev() { | ||
return __privateGet(this, _migrations)[__privateGet(this, _migrations).length - 2]; | ||
} | ||
getALlMigrations() { | ||
return __privateGet(this, _migrations); | ||
} | ||
setIndex(index) { | ||
this.latest().index = index; | ||
} | ||
preserveVerticalMargin(type, m) { | ||
this.latest()[type === "bottom" ? "marginBottom" : "marginTop"] = m; | ||
} | ||
clearMargins() { | ||
this.latest().marginBottom = null; | ||
this.latest().marginTop = null; | ||
} | ||
add(index, key, id) { | ||
__privateGet(this, _migrations).push(new AbstractMigration(index, key, id)); | ||
} | ||
start() { | ||
this.isTransitioning = true; | ||
} | ||
complete() { | ||
this.isTransitioning = false; | ||
this.preserveVerticalMargin("top", null); | ||
this.preserveVerticalMargin("bottom", null); | ||
} | ||
dispose() { | ||
__privateSet(this, _migrations, []); | ||
} | ||
}; | ||
_migrations = new WeakMap(); | ||
// ../dom-gen/src/Generator.ts | ||
var _indicator, _prevDepth, _prevKey, _initIndicators2, initIndicators_fn2, _addElementIDToDepthCollection, addElementIDToDepthCollection_fn, _addElementIDToSiblingsBranch, addElementIDToSiblingsBranch_fn; | ||
var Generator = class { | ||
constructor() { | ||
__privateAdd(this, _initIndicators2); | ||
__privateAdd(this, _addElementIDToDepthCollection); | ||
__privateAdd(this, _addElementIDToSiblingsBranch); | ||
__privateAdd(this, _indicator, void 0); | ||
__privateAdd(this, _prevDepth, void 0); | ||
__privateAdd(this, _prevKey, void 0); | ||
__privateSet(this, _indicator, {}); | ||
this.branches = {}; | ||
this.branchesByDepth = {}; | ||
__privateSet(this, _prevDepth, -99); | ||
__privateSet(this, _prevKey, combineKeys_default(0, 0)); | ||
} | ||
getElmBranch(SK) { | ||
@@ -368,15 +93,15 @@ return this.branches[SK]; | ||
accumulateIndicators(depth) { | ||
if (depth !== __privateGet(this, _prevDepth)) { | ||
__privateMethod(this, _initIndicators2, initIndicators_fn2).call(this, depth); | ||
if (depth !== this.prevDepth) { | ||
this.initIndicators(depth); | ||
} | ||
const parentIndex = __privateGet(this, _indicator)[depth + 1]; | ||
const SK = combineKeys_default(depth, parentIndex); | ||
const PK = combineKeys_default(depth + 1, __privateGet(this, _indicator)[depth + 2]); | ||
const CHK = depth === 0 ? null : __privateGet(this, _prevKey); | ||
__privateSet(this, _prevKey, SK); | ||
__privateGet(this, _indicator)[depth] += 1; | ||
if (depth < __privateGet(this, _prevDepth)) { | ||
__privateGet(this, _indicator)[0] = 0; | ||
const parentIndex = this.indicator[depth + 1]; | ||
const SK = combineKeys(depth, parentIndex); | ||
const PK = combineKeys(depth + 1, this.indicator[depth + 2]); | ||
const CHK = depth === 0 ? null : this.prevKey; | ||
this.prevKey = SK; | ||
this.indicator[depth] += 1; | ||
if (depth < this.prevDepth) { | ||
this.indicator[0] = 0; | ||
} | ||
__privateSet(this, _prevDepth, depth); | ||
this.prevDepth = depth; | ||
return { | ||
@@ -391,4 +116,4 @@ CHK, | ||
const { CHK, SK, PK, parentIndex } = this.accumulateIndicators(depth); | ||
__privateMethod(this, _addElementIDToDepthCollection, addElementIDToDepthCollection_fn).call(this, SK, depth); | ||
const selfIndex = __privateMethod(this, _addElementIDToSiblingsBranch, addElementIDToSiblingsBranch_fn).call(this, id, SK); | ||
this.addElementIDToDepthCollection(SK, depth); | ||
const selfIndex = this.addElementIDToSiblingsBranch(id, SK); | ||
const keys = { | ||
@@ -442,3 +167,3 @@ SK, | ||
"branchesByDepth", | ||
"#indicator" | ||
"indicator" | ||
].forEach((key) => { | ||
@@ -448,44 +173,5 @@ this[key] = null; | ||
} | ||
}; | ||
_indicator = new WeakMap(); | ||
_prevDepth = new WeakMap(); | ||
_prevKey = new WeakMap(); | ||
_initIndicators2 = new WeakSet(); | ||
initIndicators_fn2 = function(dp) { | ||
if (__privateGet(this, _indicator)[dp] === void 0) { | ||
__privateGet(this, _indicator)[dp] = -1; | ||
} | ||
if (__privateGet(this, _indicator)[dp + 1] === void 0) { | ||
__privateGet(this, _indicator)[dp + 1] = 0; | ||
} | ||
if (__privateGet(this, _indicator)[dp + 2] === void 0) { | ||
__privateGet(this, _indicator)[dp + 2] = 0; | ||
} | ||
}; | ||
_addElementIDToDepthCollection = new WeakSet(); | ||
addElementIDToDepthCollection_fn = function(SK, depth) { | ||
if (!Array.isArray(this.branchesByDepth[depth])) { | ||
this.branchesByDepth[depth] = [SK]; | ||
return; | ||
} | ||
const is = this.branchesByDepth[depth].find((k) => k === SK); | ||
if (!is) { | ||
this.branchesByDepth[depth].push(SK); | ||
} | ||
}; | ||
_addElementIDToSiblingsBranch = new WeakSet(); | ||
addElementIDToSiblingsBranch_fn = function(id, SK) { | ||
if (!Array.isArray(this.branches[SK])) { | ||
this.branches[SK] = []; | ||
} | ||
const selfIndex = this.branches[SK].push(id) - 1; | ||
return selfIndex; | ||
}; | ||
var Generator_default = Generator; | ||
} | ||
// ../dom-gen/src/index.ts | ||
var src_default = Generator_default; | ||
// ../core-instance/src/Node/Abstract.ts | ||
var Abstract = class { | ||
class Abstract { | ||
constructor({ ref, id }, opts) { | ||
@@ -527,3 +213,3 @@ this.id = id; | ||
if (!this.translate) { | ||
this.translate = new PointNum_default(0, 0); | ||
this.translate = new PointNum(0, 0); | ||
this.hasAttribute = {}; | ||
@@ -570,17 +256,8 @@ } | ||
} | ||
}; | ||
var Abstract_default = Abstract; | ||
} | ||
// ../core-instance/src/Node/Core.ts | ||
var _translateHistory, _initIndicators3, initIndicators_fn3, _updateCurrentIndicators, updateCurrentIndicators_fn, _updateOrderIndexing, updateOrderIndexing_fn, _leaveToNewPosition, leaveToNewPosition_fn, _seTranslate, seTranslate_fn; | ||
var NodeCore = class extends Abstract_default { | ||
class NodeCore extends Abstract { | ||
constructor(eleWithPointer, opts) { | ||
const { order, keys, depth, scrollX, scrollY, ...element } = eleWithPointer; | ||
super(element, opts); | ||
__privateAdd(this, _initIndicators3); | ||
__privateAdd(this, _updateCurrentIndicators); | ||
__privateAdd(this, _updateOrderIndexing); | ||
__privateAdd(this, _leaveToNewPosition); | ||
__privateAdd(this, _seTranslate); | ||
__privateAdd(this, _translateHistory, void 0); | ||
this.order = order; | ||
@@ -594,6 +271,25 @@ this.keys = keys; | ||
if (!this.isPaused) { | ||
__privateMethod(this, _initIndicators3, initIndicators_fn3).call(this, scrollX, scrollY); | ||
this.initIndicators(scrollX, scrollY); | ||
} | ||
this.animatedFrame = null; | ||
} | ||
initIndicators(scrollX, scrollY) { | ||
const { height, width, left, top } = this.ref.getBoundingClientRect(); | ||
this.offset = { | ||
height, | ||
width, | ||
left: left + scrollX, | ||
top: top + scrollY | ||
}; | ||
this.currentPosition = new PointNum(this.offset.left, this.offset.top); | ||
this.grid = new PointNum(0, 0); | ||
this.hasToTransform = false; | ||
} | ||
updateCurrentIndicators(space) { | ||
this.translate.increase(space); | ||
const { left, top } = this.offset; | ||
this.currentPosition.setAxes(left + this.translate.x, top + this.translate.y); | ||
if (!this.isVisible) | ||
this.hasToTransform = true; | ||
} | ||
resume(scrollX, scrollY) { | ||
@@ -603,3 +299,3 @@ if (!this.isInitialized) | ||
this.initTranslate(); | ||
__privateMethod(this, _initIndicators3, initIndicators_fn3).call(this, scrollX, scrollY); | ||
this.initIndicators(scrollX, scrollY); | ||
} | ||
@@ -624,5 +320,12 @@ changeVisibility(isVisible) { | ||
} | ||
updateOrderIndexing(i) { | ||
const { self: oldIndex } = this.order; | ||
const newIndex = oldIndex + i; | ||
this.order.self = newIndex; | ||
this.setDataset("index", newIndex); | ||
return { oldIndex, newIndex }; | ||
} | ||
assignNewPosition(branchIDsOrder, newIndex) { | ||
if (newIndex < 0 || newIndex > branchIDsOrder.length - 1) { | ||
if (true) { | ||
{ | ||
console.error(`Illegal Attempt: Received an index:${newIndex} on siblings list:${branchIDsOrder.length - 1}. | ||
@@ -634,3 +337,3 @@ `); | ||
if (branchIDsOrder[newIndex].length > 0) { | ||
if (true) { | ||
{ | ||
console.error("Illegal Attempt: Colliding in positions.\n", `Element id: ${this.id} | ||
@@ -645,2 +348,27 @@ `, `Collided at index: ${newIndex} | ||
} | ||
leaveToNewPosition(branchIDsOrder, newIndex, oldIndex) { | ||
branchIDsOrder[oldIndex] = ""; | ||
branchIDsOrder[newIndex] = this.id; | ||
} | ||
seTranslate(elmSpace, axis, operationID, isForceTransform = false) { | ||
if (operationID) { | ||
const elmAxesHistory = { | ||
ID: operationID, | ||
axis, | ||
translate: { x: this.translate.x, y: this.translate.y } | ||
}; | ||
if (!Array.isArray(this.translateHistory)) { | ||
this.translateHistory = [elmAxesHistory]; | ||
} else { | ||
this.translateHistory.push(elmAxesHistory); | ||
} | ||
} | ||
this.updateCurrentIndicators(elmSpace); | ||
if (!isForceTransform && !this.isVisible) { | ||
this.hasToTransform = true; | ||
return; | ||
} | ||
this.transformElm(); | ||
this.hasToTransform = false; | ||
} | ||
setPosition(iDsInOrder, direction, elmSpace, operationID, axis) { | ||
@@ -653,4 +381,4 @@ const numberOfPassedElm = 1; | ||
} | ||
__privateMethod(this, _seTranslate, seTranslate_fn).call(this, elmSpace, axis, operationID); | ||
const { oldIndex, newIndex } = __privateMethod(this, _updateOrderIndexing, updateOrderIndexing_fn).call(this, direction * numberOfPassedElm); | ||
this.seTranslate(elmSpace, axis, operationID); | ||
const { oldIndex, newIndex } = this.updateOrderIndexing(direction * numberOfPassedElm); | ||
if (axis === "z") { | ||
@@ -661,13 +389,13 @@ const inc = direction * numberOfPassedElm; | ||
this.grid[axis] += direction * numberOfPassedElm; | ||
if (true) { | ||
{ | ||
this.setDataset(`grid${axis.toUpperCase()}`, this.grid[axis]); | ||
} | ||
} | ||
__privateMethod(this, _leaveToNewPosition, leaveToNewPosition_fn).call(this, iDsInOrder, newIndex, oldIndex); | ||
this.leaveToNewPosition(iDsInOrder, newIndex, oldIndex); | ||
} | ||
rollBack(operationID, isForceTransform) { | ||
if (!Array.isArray(__privateGet(this, _translateHistory)) || __privateGet(this, _translateHistory).length === 0 || __privateGet(this, _translateHistory)[__privateGet(this, _translateHistory).length - 1].ID !== operationID) { | ||
if (!Array.isArray(this.translateHistory) || this.translateHistory.length === 0 || this.translateHistory[this.translateHistory.length - 1].ID !== operationID) { | ||
return; | ||
} | ||
const lastMovement = __privateGet(this, _translateHistory).pop(); | ||
const lastMovement = this.translateHistory.pop(); | ||
const { translate: preTranslate, axis } = lastMovement; | ||
@@ -685,72 +413,13 @@ const elmSpace = { | ||
this.grid[axis] += increment; | ||
if (true) { | ||
{ | ||
this.setDataset(`grid${axis.toUpperCase()}`, this.grid[axis]); | ||
} | ||
} | ||
__privateMethod(this, _seTranslate, seTranslate_fn).call(this, elmSpace, axis, void 0, isForceTransform); | ||
__privateMethod(this, _updateOrderIndexing, updateOrderIndexing_fn).call(this, increment); | ||
this.seTranslate(elmSpace, axis, void 0, isForceTransform); | ||
this.updateOrderIndexing(increment); | ||
this.rollBack(operationID, isForceTransform); | ||
} | ||
}; | ||
_translateHistory = new WeakMap(); | ||
_initIndicators3 = new WeakSet(); | ||
initIndicators_fn3 = function(scrollX, scrollY) { | ||
const { height, width, left, top } = this.ref.getBoundingClientRect(); | ||
this.offset = { | ||
height, | ||
width, | ||
left: left + scrollX, | ||
top: top + scrollY | ||
}; | ||
this.currentPosition = new PointNum_default(this.offset.left, this.offset.top); | ||
this.grid = new PointNum_default(0, 0); | ||
this.hasToTransform = false; | ||
}; | ||
_updateCurrentIndicators = new WeakSet(); | ||
updateCurrentIndicators_fn = function(space) { | ||
this.translate.increase(space); | ||
const { left, top } = this.offset; | ||
this.currentPosition.setAxes(left + this.translate.x, top + this.translate.y); | ||
if (!this.isVisible) | ||
this.hasToTransform = true; | ||
}; | ||
_updateOrderIndexing = new WeakSet(); | ||
updateOrderIndexing_fn = function(i) { | ||
const { self: oldIndex } = this.order; | ||
const newIndex = oldIndex + i; | ||
this.order.self = newIndex; | ||
this.setDataset("index", newIndex); | ||
return { oldIndex, newIndex }; | ||
}; | ||
_leaveToNewPosition = new WeakSet(); | ||
leaveToNewPosition_fn = function(branchIDsOrder, newIndex, oldIndex) { | ||
branchIDsOrder[oldIndex] = ""; | ||
branchIDsOrder[newIndex] = this.id; | ||
}; | ||
_seTranslate = new WeakSet(); | ||
seTranslate_fn = function(elmSpace, axis, operationID, isForceTransform = false) { | ||
if (operationID) { | ||
const elmAxesHistory = { | ||
ID: operationID, | ||
axis, | ||
translate: { x: this.translate.x, y: this.translate.y } | ||
}; | ||
if (!Array.isArray(__privateGet(this, _translateHistory))) { | ||
__privateSet(this, _translateHistory, [elmAxesHistory]); | ||
} else { | ||
__privateGet(this, _translateHistory).push(elmAxesHistory); | ||
} | ||
} | ||
__privateMethod(this, _updateCurrentIndicators, updateCurrentIndicators_fn).call(this, elmSpace); | ||
if (!isForceTransform && !this.isVisible) { | ||
this.hasToTransform = true; | ||
return; | ||
} | ||
this.transformElm(); | ||
this.hasToTransform = false; | ||
}; | ||
var Core_default = NodeCore; | ||
} | ||
// ../core-instance/src/Node/CoreUtils.ts | ||
var CoreUtils = class extends Core_default { | ||
class CoreUtils extends NodeCore { | ||
static getRectByAxis(axis) { | ||
@@ -804,103 +473,32 @@ return axis === "x" ? "width" : "height"; | ||
} | ||
}; | ||
var CoreUtils_default = CoreUtils; | ||
} | ||
// ../core-instance/src/Container/Container.ts | ||
var _boundariesByRow, _gridSiblingsHasNewRow, _addNewElmToGridIndicator, addNewElmToGridIndicator_fn; | ||
var _Container = class { | ||
class Store { | ||
constructor() { | ||
__privateAdd(this, _addNewElmToGridIndicator); | ||
__privateAdd(this, _boundariesByRow, void 0); | ||
__privateAdd(this, _gridSiblingsHasNewRow, void 0); | ||
this.grid = new PointNum_default(1, 1); | ||
this.originLength = _Container.OUT_OF_RANGE; | ||
__privateSet(this, _boundariesByRow, {}); | ||
__privateSet(this, _gridSiblingsHasNewRow, false); | ||
this.lastKeyIdentifier = null; | ||
this.registry = {}; | ||
this.DOMGen = new Generator(); | ||
} | ||
registerNewElm(offset, unifiedContainerDimensions) { | ||
const { height, left, top, width } = offset; | ||
const right = left + width; | ||
const bottom = top + height; | ||
const elmRectBoundaries = { | ||
top, | ||
left, | ||
right, | ||
bottom | ||
submitElementToRegistry(element) { | ||
const { id, depth, isPaused, isInitialized, ...rest } = element; | ||
const { order, keys } = this.DOMGen.register(id, depth); | ||
const coreElement = { | ||
id, | ||
order, | ||
keys, | ||
depth, | ||
...rest | ||
}; | ||
if (!this.boundaries) { | ||
this.boundaries = elmRectBoundaries; | ||
} else { | ||
assignBiggestRect_default(this.boundaries, elmRectBoundaries); | ||
} | ||
__privateMethod(this, _addNewElmToGridIndicator, addNewElmToGridIndicator_fn).call(this, elmRectBoundaries); | ||
const $ = this.boundaries; | ||
const uni = unifiedContainerDimensions; | ||
if (!uni) | ||
return; | ||
const $height = $.bottom - $.top; | ||
const $width = $.right - $.left; | ||
if (uni.height < $height) { | ||
uni.height = $height; | ||
} | ||
if (uni.width < $width) { | ||
uni.width = $height; | ||
} | ||
this.registry[id] = new CoreUtils(coreElement, { | ||
isInitialized, | ||
isPaused | ||
}); | ||
} | ||
resetIndicators() { | ||
this.boundaries = null; | ||
this.grid.setAxes(1, 1); | ||
__privateSet(this, _boundariesByRow, {}); | ||
__privateSet(this, _gridSiblingsHasNewRow, false); | ||
} | ||
preservePosition(position) { | ||
this.lastElmPosition = new PointNum_default(position.x, position.y); | ||
} | ||
}; | ||
var Container = _Container; | ||
_boundariesByRow = new WeakMap(); | ||
_gridSiblingsHasNewRow = new WeakMap(); | ||
_addNewElmToGridIndicator = new WeakSet(); | ||
addNewElmToGridIndicator_fn = function(rect) { | ||
if (!__privateGet(this, _boundariesByRow)[this.grid.x]) { | ||
__privateGet(this, _boundariesByRow)[this.grid.x] = { | ||
...rect | ||
}; | ||
return; | ||
} | ||
const $ = __privateGet(this, _boundariesByRow)[this.grid.x]; | ||
if (rect.bottom > $.bottom || rect.top < $.top) { | ||
this.grid.y += 1; | ||
__privateSet(this, _gridSiblingsHasNewRow, true); | ||
$.left = 0; | ||
$.right = 0; | ||
} | ||
if (rect.left > $.right || rect.right < $.left) { | ||
if (__privateGet(this, _gridSiblingsHasNewRow)) { | ||
this.grid.x = 1; | ||
__privateSet(this, _gridSiblingsHasNewRow, false); | ||
} else { | ||
this.grid.x += 1; | ||
} | ||
} | ||
assignBiggestRect_default($, rect); | ||
}; | ||
Container.OUT_OF_RANGE = -1; | ||
// ../store/src/Store.ts | ||
var _lastKeyIdentifier, _submitElementToRegistry, submitElementToRegistry_fn; | ||
var Store = class { | ||
constructor() { | ||
__privateAdd(this, _submitElementToRegistry); | ||
__privateAdd(this, _lastKeyIdentifier, void 0); | ||
__privateSet(this, _lastKeyIdentifier, null); | ||
this.registry = {}; | ||
this.DOMGen = new src_default(); | ||
} | ||
register(element) { | ||
if (element.parentID) { | ||
if (!__privateGet(this, _lastKeyIdentifier)) { | ||
__privateSet(this, _lastKeyIdentifier, element.parentID); | ||
} else if (element.parentID !== __privateGet(this, _lastKeyIdentifier)) { | ||
if (!this.lastKeyIdentifier) { | ||
this.lastKeyIdentifier = element.parentID; | ||
} else if (element.parentID !== this.lastKeyIdentifier) { | ||
const { id, depth, ...rest } = element; | ||
__privateMethod(this, _submitElementToRegistry, submitElementToRegistry_fn).call(this, { | ||
this.submitElementToRegistry({ | ||
id: element.parentID, | ||
@@ -912,3 +510,3 @@ depth: depth + 1, | ||
} | ||
__privateMethod(this, _submitElementToRegistry, submitElementToRegistry_fn).call(this, element); | ||
this.submitElementToRegistry(element); | ||
} | ||
@@ -934,27 +532,5 @@ getElmBranchByKey(siblingsKy) { | ||
} | ||
}; | ||
_lastKeyIdentifier = new WeakMap(); | ||
_submitElementToRegistry = new WeakSet(); | ||
submitElementToRegistry_fn = function(element) { | ||
const { id, depth, isPaused, isInitialized, ...rest } = element; | ||
const { order, keys } = this.DOMGen.register(id, depth); | ||
const coreElement = { | ||
id, | ||
order, | ||
keys, | ||
depth, | ||
...rest | ||
}; | ||
this.registry[id] = new CoreUtils_default(coreElement, { | ||
isInitialized, | ||
isPaused | ||
}); | ||
}; | ||
var Store_default = Store; | ||
} | ||
// ../store/src/index.ts | ||
var src_default2 = Store_default; | ||
// src/DraggableStoreImp.ts | ||
var DraggableStoreImp = class extends src_default2 { | ||
class DraggableStoreImp extends Store { | ||
register(element) { | ||
@@ -979,15 +555,14 @@ var _a; | ||
} | ||
}; | ||
var DraggableStoreImp_default = function createStoreInstance() { | ||
} | ||
var store = (function createStoreInstance() { | ||
const store = new DraggableStoreImp(); | ||
return store; | ||
}(); | ||
})(); | ||
// src/AbstractDraggable.ts | ||
var _AbstractDraggable = class { | ||
const _AbstractDraggable = class { | ||
constructor(abstractCoreElm, { x: initX, y: initY }) { | ||
this.draggedElm = abstractCoreElm; | ||
const { translate } = this.draggedElm; | ||
this.outerOffset = new PointNum_default(-initX + translate.x, -initY + translate.y); | ||
this.translatePlaceholder = new PointNum_default(0, 0); | ||
this.outerOffset = new PointNum(-initX + translate.x, -initY + translate.y); | ||
this.translatePlaceholder = new PointNum(0, 0); | ||
this.setDragged(true); | ||
@@ -1023,3 +598,3 @@ } | ||
}; | ||
var AbstractDraggable = _AbstractDraggable; | ||
let AbstractDraggable = _AbstractDraggable; | ||
AbstractDraggable.draggedStyle = [ | ||
@@ -1042,8 +617,6 @@ { | ||
]; | ||
var AbstractDraggable_default = AbstractDraggable; | ||
// src/Draggable.ts | ||
var Draggable = class extends AbstractDraggable_default { | ||
class Draggable extends AbstractDraggable { | ||
constructor(id, clickCoordinates) { | ||
const element = DraggableStoreImp_default.registry[id]; | ||
const element = store.registry[id]; | ||
super(element, clickCoordinates); | ||
@@ -1058,3 +631,6 @@ } | ||
} | ||
}; | ||
var Draggable_default = Draggable; | ||
} | ||
exports.AbstractDraggable = AbstractDraggable; | ||
exports.Draggable = Draggable; | ||
exports.store = store; |
{ | ||
"name": "@dflex/draggable", | ||
"version": "3.5.1", | ||
"version": "3.5.2", | ||
"description": "Draggable only package for all JavaScript frameworks", | ||
@@ -11,5 +11,10 @@ "author": "Jalal Maskoun", | ||
".": { | ||
"development": { | ||
"import": "./dist/dev.mjs", | ||
"require": "./dist/dev.js" | ||
}, | ||
"require": "./dist/dflex-draggable.js", | ||
"import": "./dist/dflex-draggable.mjs" | ||
} | ||
}, | ||
"./dist/*": "./dist/*" | ||
}, | ||
@@ -25,6 +30,6 @@ "homepage": "https://github.com/dflex-js/dflex/tree/master/packages/draggable", | ||
"devDependencies": { | ||
"@dflex/core-instance": "^3.5.1", | ||
"@dflex/store": "^3.5.1", | ||
"@dflex/utils": "^3.5.1", | ||
"eslint-config-dflex-react": "0.2.1" | ||
"@dflex/core-instance": "^3.5.2", | ||
"@dflex/store": "^3.5.2", | ||
"@dflex/utils": "^3.5.2", | ||
"eslint-config-dflex-react": "0.2.2" | ||
}, | ||
@@ -55,7 +60,4 @@ "keywords": [ | ||
"emit": "tsc --emitDeclarationOnly", | ||
"build:cjs": "esbuild src/index.ts --bundle --format=cjs --outfile=dist/dflex-draggable.js", | ||
"build:esm": "esbuild src/index.ts --bundle --format=esm --outfile=dist/dflex-draggable.mjs", | ||
"build": "pnpm clean && pnpm build:cjs && pnpm build:esm && pnpm emit", | ||
"server": "pnpm start --filter dflex-react-draggable" | ||
"server": "pnpm start --filter dflex-draggable-playground" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
40625
1313