@fr0st/ui-sortable 2.0.0 → 2.0.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frost-ui-sortable.js","sources":["../src/sortable.js","../src/prototype/events.js","../src/prototype/helpers.js","../src/index.js"],"sourcesContent":["import $ from '@fr0st/query';\nimport { BaseComponent } from '@fr0st/ui';\n\n/**\n * Sortable Class\n * @class\n */\nexport default class Sortable extends BaseComponent {\n /**\n * New Sortable constructor.\n * @param {HTMLElement} node The input node.\n * @param {object} [options] The options to create the Sortable with.\n */\n constructor(node, options) {\n super(node, options);\n\n this._selector = this._options.items;\n if (this._options.handle) {\n this._selector += ' ' + this._options.handle;\n }\n\n this._enabled = !this._options.disabled;\n\n this._refreshCursors();\n this._events();\n }\n\n /**\n * Disable the Sortable.\n */\n disable() {\n this._enabled = false;\n }\n\n /**\n * Dispose the Sortable.\n */\n dispose() {\n $.removeEventDelegate(this._node, 'mousedown.ui.sortable touchstart.ui.sortable');\n $.removeEvent(this._node, 'receive.ui.sortable');\n\n this._target = null;\n this._currentSortable = null;\n\n super.dispose();\n }\n\n /**\n * Enable the Sortable.\n */\n enable() {\n this._enabled = true;\n }\n\n /**\n * Get the Sortable item elements.\n * @return {array} The Sortable item elements.\n */\n items() {\n return $.find(this._options.items, this._node);\n }\n}\n","import $ from '@fr0st/query';\nimport { getPosition } from '@fr0st/ui';\n\n/**\n * Attach events for the Sortable.\n */\nexport function _events() {\n const downEvent = (e) => {\n if (\n e.button ||\n !this._enabled ||\n $.is(e.currentTarget, this._options.cancel) ||\n $.getDataset(this._node, 'uiDragging')\n ) {\n return false;\n }\n\n if (e.type === 'mousedown') {\n e.preventDefault();\n }\n\n this._target = this._options.handle ?\n this.items().find((node) => $.hasDescendent(node, e.currentTarget)) :\n e.currentTarget;\n };\n\n const moveEvent = (e) => {\n this._pos = getPosition(e);\n\n if (!$.getDataset(this._node, 'uiDragging')) {\n $.setDataset(this._node, { uiDragging: true });\n\n this._startIndex = $.index(this._target);\n this._currentIndex = this._startIndex;\n\n $.triggerEvent(this._node, 'sort.ui.sortable', {\n detail: {\n target: this._target,\n },\n });\n\n if (this._options.helperClass) {\n $.addClass(this._target, this._options.helperClass);\n }\n\n this._currentSortable = this._node;\n\n if (this._options.scroll) {\n this._checkScroll();\n }\n }\n\n let nearestSortable = this._node;\n\n if (this._options.connectWith) {\n const connected = $.find(this._options.connectWith)\n .filter((node) => {\n const sortable = this.constructor.init(node);\n\n return sortable._options.dropOnEmpty || sortable.items().length;\n });\n\n if (connected.length) {\n nearestSortable = $.nearestTo([this._node, ...connected], this._pos.x, this._pos.y, { offset: true });\n }\n }\n\n const nearestItems = $.isSame(this._node, nearestSortable) ?\n this.items() :\n this.constructor.init(nearestSortable).items();\n\n const nearestItem = $.nearestTo(nearestItems, this._pos.x, this._pos.y, { offset: true });\n\n if (!nearestItem) {\n return;\n }\n\n this._updateTarget(nearestItem, this._pos.x, this._pos.y);\n\n const newIndex = $.index(this._target);\n\n if (!$.isSame(nearestSortable, this._currentSortable)) {\n $.triggerEvent(this._currentSortable, 'send.ui.sortable', {\n detail: {\n target: this._target,\n },\n });\n\n $.triggerEvent(nearestSortable, 'receive.ui.sortable', {\n detail: {\n target: this._target,\n },\n });\n } else if (this._currentIndex !== newIndex) {\n $.triggerEvent(nearestSortable, 'sorting.ui.sortable', {\n detail: {\n target: this._target,\n },\n });\n }\n\n this._currentIndex = newIndex;\n this._currentSortable = nearestSortable;\n };\n\n const upEvent = (e) => {\n if (!$.getDataset(this._node, 'uiDragging')) {\n this._target = null;\n return;\n }\n\n if (e.type === 'mouseup') {\n e.preventDefault();\n }\n\n $.triggerEvent(this._currentSortable, 'sorted.ui.sortable', {\n detail: {\n target: this._target,\n },\n });\n\n if (this._options.helperClass) {\n $.removeClass(this._target, this._options.helperClass);\n }\n\n if (this._currentIndex !== this._startIndex || !$.isSame(this._currentSortable, this._node)) {\n $.triggerEvent(this._currentSortable, 'update.ui.sortable', {\n detail: {\n target: this._target,\n },\n });\n }\n\n $.removeDataset(this._node, 'uiDragging');\n\n if (this._checkScrollTimer) {\n clearTimeout(this._checkScrollTimer);\n this._checkScrollTimer = null;\n }\n\n this._target = null;\n this._currentSortable = null;\n this._currentIndex = null;\n this._startIndex = null;\n };\n\n const dragEvent = $.mouseDragFactory(downEvent, moveEvent, upEvent);\n\n $.addEventDelegate(this._node, 'mousedown.ui.sortable touchstart.ui.sortable', this._selector, dragEvent);\n\n $.addEvent(this._node, 'receive.ui.sortable', (_) => {\n this._refreshCursors();\n });\n};\n","import $ from '@fr0st/query';\n\n/**\n * Check for window scroll.\n */\nexport function _checkScroll() {\n $.hide(this._target);\n\n const originalX = $.getScrollX(window);\n const originalY = $.getScrollY(window);\n\n let offsetX = originalX;\n let offsetY = originalY;\n\n if (this._pos.y < originalY + this._options.scrollSensitivity) {\n offsetY = Math.max(0, originalY - this._options.scrollSpeed);\n } else if (this._pos.y > originalY + $.height(window) - this._options.scrollSensitivity) {\n const docHeight = $.height(document, { boxSize: $.SCROLL_BOX });\n offsetY = Math.min(docHeight, originalY + this._options.scrollSpeed);\n }\n\n if (this._pos.x < originalX + this._options.scrollSensitivity) {\n offsetX = Math.max(0, originalX - this._options.scrollSpeed);\n } else if (this._pos.x > originalX + $.width(window) - this._options.scrollSensitivity) {\n const docWidth = $.width(document, { boxSize: $.SCROLL_BOX });\n offsetX = Math.min(docWidth, originalX + this._options.scrollSpeed);\n }\n\n if (offsetX !== originalX || offsetY !== originalY) {\n $.setStyle(':root', { scrollBehavior: 'initial' });\n $.setScroll(document, offsetX, offsetY);\n $.setStyle(':root', { scrollBehavior: '' });\n\n this._pos.x += offsetX - originalX;\n this._pos.y += offsetY - originalY;\n }\n\n $.show(this._target);\n\n this._checkScrollTimer = setTimeout((_) => {\n this._checkScroll();\n }, 0);\n};\n\n/**\n * Refresh Sortable item cursors.\n */\nexport function _refreshCursors() {\n const elements = $.find(this._selector, this._node);\n\n $.setStyle(elements, { cursor: this._options.cursor });\n};\n\n/**\n * Update the target element.\n * @param {HTMLElement} nearestItem The current nearest item.\n * @param {number} x The mouse X position.\n * @param {number} y The mouse Y position.\n */\nexport function _updateTarget(nearestItem, x, y) {\n const nearestCenter = $.center(nearestItem, { offset: true });\n const targetCenter = $.center(this._target, { offset: true });\n\n let method;\n if (this._options.axis === 'y' || nearestCenter.x === targetCenter.x) {\n method = y < nearestCenter.y ?\n 'before' :\n 'after';\n } else if (this._options.axis === 'x' || nearestCenter.y === targetCenter.y) {\n method = x < nearestCenter.x ?\n 'before' :\n 'after';\n } else {\n method = x < nearestCenter.x && y < nearestCenter.y ?\n 'before' :\n 'after';\n }\n\n $[method](nearestItem, this._target);\n};\n","import { initComponent } from '@fr0st/ui';\nimport Sortable from './sortable.js';\nimport { _events } from './prototype/events.js';\nimport { _checkScroll, _refreshCursors, _updateTarget } from './prototype/helpers.js';\n\n// Sortable default options\nSortable.defaults = {\n appendTo: 'body',\n axis: null,\n cancel: 'input, textarea, button, select, option',\n connectWith: null,\n cursor: 'auto',\n disabled: false,\n dropOnEmpty: true,\n handle: null,\n helperClass: 'bg-body-tertiary',\n items: ':scope > li',\n scroll: true,\n scrollSensitivity: 20,\n scrollSpeed: 5,\n};\n\n// Sortable prototype\nconst proto = Sortable.prototype;\n\nproto._checkScroll = _checkScroll;\nproto._events = _events;\nproto._refreshCursors = _refreshCursors;\nproto._updateTarget = _updateTarget;\n\n// Sortable init\ninitComponent('sortable', Sortable);\n\nexport default Sortable;\n"],"names":["BaseComponent","getPosition","initComponent"],"mappings":";;;;;;IAGA;IACA;IACA;IACA;IACe,MAAM,QAAQ,SAASA,gBAAa,CAAC;IACpD;IACA;IACA;IACA;IACA;IACA,IAAI,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE;IAC/B,QAAQ,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC7B;IACA,QAAQ,IAAI,CAAC,SAAS,GAAG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AE,KAAK;IACnB,IAAI,WAAW,EAAE,IAAI;IACrB,IAAI,MAAM,EAAE,IAAI;IAChB,IAAI,WAAW,EAAE,kBAAkB;IACnC,IAAI,KAAK,EAAE,aAAa;IACxB,IAAI,MAAM,EAAE,IAAI;IAChB,IAAI,iBAAiB,EAAE,EAAE;IACzB,IAAI,WAAW,EAAE,CAAC;IAClB,CAAC,CAAC;AACF;IACA;IACA,MAAM,KAAK,GAAG,QAAQ,CAAC,SAAS,CAAC;AACjC;IACA,KAAK,CAAC,YAAY,GAAG,YAAY,CAAC;IAClC,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,KAAK,CAAC,eAAe,GAAG,eAAe,CAAC;IACxC,KAAK,CAAC,aAAa,GAAG,aAAa,CAAC;AACpC;IACA;AACAC,oBAAa,CAAC,UAAU,EAAE,QAAQ,CAAC;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"frost-ui-sortable.js","sources":["../src/sortable.js","../src/prototype/events.js","../src/prototype/helpers.js","../src/index.js"],"sourcesContent":["import $ from '@fr0st/query';\nimport { BaseComponent } from '@fr0st/ui';\n\n/**\n * Sortable Class\n * @class\n */\nexport default class Sortable extends BaseComponent {\n /**\n * New Sortable constructor.\n * @param {HTMLElement} node The input node.\n * @param {object} [options] The options to create the Sortable with.\n */\n constructor(node, options) {\n super(node, options);\n\n this._selector = this._options.items;\n if (this._options.handle) {\n this._selector += ' ' + this._options.handle;\n }\n\n this._enabled = !this._options.disabled;\n\n this._refreshCursors();\n this._events();\n }\n\n /**\n * Disable the Sortable.\n */\n disable() {\n this._enabled = false;\n }\n\n /**\n * Dispose the Sortable.\n */\n dispose() {\n $.removeEventDelegate(this._node, 'mousedown.ui.sortable touchstart.ui.sortable');\n $.removeEvent(this._node, 'receive.ui.sortable');\n\n this._target = null;\n this._currentSortable = null;\n\n super.dispose();\n }\n\n /**\n * Enable the Sortable.\n */\n enable() {\n this._enabled = true;\n }\n\n /**\n * Get the Sortable item elements.\n * @return {array} The Sortable item elements.\n */\n items() {\n return $.find(this._options.items, this._node);\n }\n}\n","import $ from '@fr0st/query';\nimport { getPosition } from '@fr0st/ui';\n\n/**\n * Attach events for the Sortable.\n */\nexport function _events() {\n const downEvent = (e) => {\n if (\n e.button ||\n !this._enabled ||\n $.is(e.currentTarget, this._options.cancel) ||\n $.getDataset(this._node, 'uiDragging')\n ) {\n return false;\n }\n\n this._target = this._options.handle ?\n this.items().find((node) => $.hasDescendent(node, e.currentTarget)) :\n e.currentTarget;\n };\n\n const moveEvent = (e) => {\n this._pos = getPosition(e);\n\n if (!$.getDataset(this._node, 'uiDragging')) {\n $.setDataset(this._node, { uiDragging: true });\n\n this._startIndex = $.index(this._target);\n this._currentIndex = this._startIndex;\n\n $.triggerEvent(this._node, 'sort.ui.sortable', {\n detail: {\n target: this._target,\n },\n });\n\n if (this._options.helperClass) {\n $.addClass(this._target, this._options.helperClass);\n }\n\n this._currentSortable = this._node;\n\n if (this._options.scroll) {\n this._checkScroll();\n }\n }\n\n let nearestSortable = this._node;\n\n if (this._options.connectWith) {\n const connected = $.find(this._options.connectWith)\n .filter((node) => {\n const sortable = this.constructor.init(node);\n\n return sortable._options.dropOnEmpty || sortable.items().length;\n });\n\n if (connected.length) {\n nearestSortable = $.nearestTo([this._node, ...connected], this._pos.x, this._pos.y, { offset: true });\n }\n }\n\n const nearestItems = $.isSame(this._node, nearestSortable) ?\n this.items() :\n this.constructor.init(nearestSortable).items();\n\n const nearestItem = $.nearestTo(nearestItems, this._pos.x, this._pos.y, { offset: true });\n\n if (!nearestItem) {\n return;\n }\n\n this._updateTarget(nearestItem, this._pos.x, this._pos.y);\n\n const newIndex = $.index(this._target);\n\n if (!$.isSame(nearestSortable, this._currentSortable)) {\n $.triggerEvent(this._currentSortable, 'send.ui.sortable', {\n detail: {\n target: this._target,\n },\n });\n\n $.triggerEvent(nearestSortable, 'receive.ui.sortable', {\n detail: {\n target: this._target,\n },\n });\n } else if (this._currentIndex !== newIndex) {\n $.triggerEvent(nearestSortable, 'sorting.ui.sortable', {\n detail: {\n target: this._target,\n },\n });\n }\n\n this._currentIndex = newIndex;\n this._currentSortable = nearestSortable;\n };\n\n const upEvent = (e) => {\n if (!$.getDataset(this._node, 'uiDragging')) {\n this._target = null;\n return;\n }\n\n if (e.type === 'mouseup') {\n e.preventDefault();\n }\n\n $.triggerEvent(this._currentSortable, 'sorted.ui.sortable', {\n detail: {\n target: this._target,\n },\n });\n\n if (this._options.helperClass) {\n $.removeClass(this._target, this._options.helperClass);\n }\n\n if (this._currentIndex !== this._startIndex || !$.isSame(this._currentSortable, this._node)) {\n $.triggerEvent(this._currentSortable, 'update.ui.sortable', {\n detail: {\n target: this._target,\n },\n });\n }\n\n $.removeDataset(this._node, 'uiDragging');\n\n if (this._checkScrollTimer) {\n clearTimeout(this._checkScrollTimer);\n this._checkScrollTimer = null;\n }\n\n this._target = null;\n this._currentSortable = null;\n this._currentIndex = null;\n this._startIndex = null;\n };\n\n const dragEvent = $.mouseDragFactory(downEvent, moveEvent, upEvent);\n\n $.addEventDelegate(this._node, 'mousedown.ui.sortable touchstart.ui.sortable', this._selector, dragEvent);\n\n $.addEvent(this._node, 'receive.ui.sortable', (_) => {\n this._refreshCursors();\n });\n};\n","import $ from '@fr0st/query';\n\n/**\n * Check for window scroll.\n */\nexport function _checkScroll() {\n $.hide(this._target);\n\n const originalX = $.getScrollX(window);\n const originalY = $.getScrollY(window);\n\n let offsetX = originalX;\n let offsetY = originalY;\n\n if (this._pos.y < originalY + this._options.scrollSensitivity) {\n offsetY = Math.max(0, originalY - this._options.scrollSpeed);\n } else if (this._pos.y > originalY + $.height(window) - this._options.scrollSensitivity) {\n const docHeight = $.height(document, { boxSize: $.SCROLL_BOX });\n offsetY = Math.min(docHeight, originalY + this._options.scrollSpeed);\n }\n\n if (this._pos.x < originalX + this._options.scrollSensitivity) {\n offsetX = Math.max(0, originalX - this._options.scrollSpeed);\n } else if (this._pos.x > originalX + $.width(window) - this._options.scrollSensitivity) {\n const docWidth = $.width(document, { boxSize: $.SCROLL_BOX });\n offsetX = Math.min(docWidth, originalX + this._options.scrollSpeed);\n }\n\n if (offsetX !== originalX || offsetY !== originalY) {\n $.setStyle(':root', { scrollBehavior: 'initial' });\n $.setScroll(document, offsetX, offsetY);\n $.setStyle(':root', { scrollBehavior: '' });\n\n this._pos.x += offsetX - originalX;\n this._pos.y += offsetY - originalY;\n }\n\n $.show(this._target);\n\n this._checkScrollTimer = setTimeout((_) => {\n this._checkScroll();\n }, 0);\n};\n\n/**\n * Refresh Sortable item cursors.\n */\nexport function _refreshCursors() {\n const elements = $.find(this._selector, this._node);\n\n $.setStyle(elements, { cursor: this._options.cursor });\n};\n\n/**\n * Update the target element.\n * @param {HTMLElement} nearestItem The current nearest item.\n * @param {number} x The mouse X position.\n * @param {number} y The mouse Y position.\n */\nexport function _updateTarget(nearestItem, x, y) {\n const nearestCenter = $.center(nearestItem, { offset: true });\n const targetCenter = $.center(this._target, { offset: true });\n\n let method;\n if (this._options.axis === 'y' || nearestCenter.x === targetCenter.x) {\n method = y < nearestCenter.y ?\n 'before' :\n 'after';\n } else if (this._options.axis === 'x' || nearestCenter.y === targetCenter.y) {\n method = x < nearestCenter.x ?\n 'before' :\n 'after';\n } else {\n method = x < nearestCenter.x && y < nearestCenter.y ?\n 'before' :\n 'after';\n }\n\n $[method](nearestItem, this._target);\n};\n","import { initComponent } from '@fr0st/ui';\nimport Sortable from './sortable.js';\nimport { _events } from './prototype/events.js';\nimport { _checkScroll, _refreshCursors, _updateTarget } from './prototype/helpers.js';\n\n// Sortable default options\nSortable.defaults = {\n appendTo: 'body',\n axis: null,\n cancel: 'input, textarea, button, select, option',\n connectWith: null,\n cursor: 'auto',\n disabled: false,\n dropOnEmpty: true,\n handle: null,\n helperClass: 'bg-body-tertiary',\n items: ':scope > li',\n scroll: true,\n scrollSensitivity: 20,\n scrollSpeed: 5,\n};\n\n// Sortable prototype\nconst proto = Sortable.prototype;\n\nproto._checkScroll = _checkScroll;\nproto._events = _events;\nproto._refreshCursors = _refreshCursors;\nproto._updateTarget = _updateTarget;\n\n// Sortable init\ninitComponent('sortable', Sortable);\n\nexport default Sortable;\n"],"names":["BaseComponent","getPosition","initComponent"],"mappings":";;;;;;IAGA;IACA;IACA;IACA;IACe,MAAM,QAAQ,SAASA,gBAAa,CAAC;IACpD;IACA;IACA;IACA;IACA;IACA,IAAI,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE;IAC/B,QAAQ,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC7B;IACA,QAAQ,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;IAC7C,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;IAClC,YAAY,IAAI,CAAC,SAAS,IAAI,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IACzD,SAAS;AACT;IACA,QAAQ,IAAI,CAAC,QAAQ,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;AAChD;IACA,QAAQ,IAAI,CAAC,eAAe,EAAE,CAAC;IAC/B,QAAQ,IAAI,CAAC,OAAO,EAAE,CAAC;IACvB,KAAK;AACL;IACA;IACA;IACA;IACA,IAAI,OAAO,GAAG;IACd,QAAQ,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;IAC9B,KAAK;AACL;IACA;IACA;IACA;IACA,IAAI,OAAO,GAAG;IACd,QAAQ,CAAC,CAAC,mBAAmB,CAAC,IAAI,CAAC,KAAK,EAAE,8CAA8C,CAAC,CAAC;IAC1F,QAAQ,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,EAAE,qBAAqB,CAAC,CAAC;AACzD;IACA,QAAQ,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;IAC5B,QAAQ,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;AACrC;IACA,QAAQ,KAAK,CAAC,OAAO,EAAE,CAAC;IACxB,KAA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AAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACzC;;IC1EA;IACA,QAAQ,CAAC,QAAQ,GAAG;IACpB,IAAI,QAAQ,EAAE,MAAM;IACpB,IAAI,IAAI,EAAE,IAAI;IACd,IAAI,MAAM,EAAE,yCAAyC;IACrD,IAAI,WAAW,EAAE,IAAI;IACrB,IAAI,MAAM,EAAE,MAAM;IAClB,IAAI,QAAQ,EAAE,KAAK;IACnB,IAAI,WAAW,EAAE,IAAI;IACrB,IAAI,MAAM,EAAE,IAAI;IAChB,IAAI,WAAW,EAAE,kBAAkB;IACnC,IAAI,KAAK,EAAE,aAAa;IACxB,IAAI,MAAM,EAAE,IAAI;IAChB,IAAI,iBAAiB,EAAE,EAAE;IACzB,IAAI,WAAW,EAAE,CAAC;IAClB,CAAC,CAAC;AACF;IACA;IACA,MAAM,KAAK,GAAG,QAAQ,CAAC,SAAS,CAAC;AACjC;IACA,KAAK,CAAC,YAAY,GAAG,YAAY,CAAC;IAClC,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,KAAK,CAAC,eAAe,GAAG,eAAe,CAAC;IACxC,KAAK,CAAC,aAAa,GAAG,aAAa,CAAC;AACpC;IACA;AACAC,oBAAa,CAAC,UAAU,EAAE,QAAQ,CAAC;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@fr0st/ui"),require("@fr0st/query")):"function"==typeof define&&define.amd?define(["exports","@fr0st/ui","@fr0st/query"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).UI=t.UI||{},t.UI,t.fQuery)}(this,(function(t,e,s){"use strict";class i extends e.BaseComponent{constructor(t,e){super(t,e),this._selector=this._options.items,this._options.handle&&(this._selector+=" "+this._options.handle),this._enabled=!this._options.disabled,this._refreshCursors(),this._events()}disable(){this._enabled=!1}dispose(){s.removeEventDelegate(this._node,"mousedown.ui.sortable touchstart.ui.sortable"),s.removeEvent(this._node,"receive.ui.sortable"),this._target=null,this._currentSortable=null,super.dispose()}enable(){this._enabled=!0}items(){return s.find(this._options.items,this._node)}}i.defaults={appendTo:"body",axis:null,cancel:"input, textarea, button, select, option",connectWith:null,cursor:"auto",disabled:!1,dropOnEmpty:!0,handle:null,helperClass:"bg-body-tertiary",items:":scope > li",scroll:!0,scrollSensitivity:20,scrollSpeed:5};const o=i.prototype;o._checkScroll=function(){s.hide(this._target);const t=s.getScrollX(window),e=s.getScrollY(window);let i=t,o=e;if(this._pos.y<e+this._options.scrollSensitivity)o=Math.max(0,e-this._options.scrollSpeed);else if(this._pos.y>e+s.height(window)-this._options.scrollSensitivity){const t=s.height(document,{boxSize:s.SCROLL_BOX});o=Math.min(t,e+this._options.scrollSpeed)}if(this._pos.x<t+this._options.scrollSensitivity)i=Math.max(0,t-this._options.scrollSpeed);else if(this._pos.x>t+s.width(window)-this._options.scrollSensitivity){const e=s.width(document,{boxSize:s.SCROLL_BOX});i=Math.min(e,t+this._options.scrollSpeed)}i===t&&o===e||(s.setStyle(":root",{scrollBehavior:"initial"}),s.setScroll(document,i,o),s.setStyle(":root",{scrollBehavior:""}),this._pos.x+=i-t,this._pos.y+=o-e),s.show(this._target),this._checkScrollTimer=setTimeout((t=>{this._checkScroll()}),0)},o._events=function(){const t=s.mouseDragFactory((t=>{if(t.button||!this._enabled||s.is(t.currentTarget,this._options.cancel)||s.getDataset(this._node,"uiDragging"))return!1;
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@fr0st/ui"),require("@fr0st/query")):"function"==typeof define&&define.amd?define(["exports","@fr0st/ui","@fr0st/query"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).UI=t.UI||{},t.UI,t.fQuery)}(this,(function(t,e,s){"use strict";class i extends e.BaseComponent{constructor(t,e){super(t,e),this._selector=this._options.items,this._options.handle&&(this._selector+=" "+this._options.handle),this._enabled=!this._options.disabled,this._refreshCursors(),this._events()}disable(){this._enabled=!1}dispose(){s.removeEventDelegate(this._node,"mousedown.ui.sortable touchstart.ui.sortable"),s.removeEvent(this._node,"receive.ui.sortable"),this._target=null,this._currentSortable=null,super.dispose()}enable(){this._enabled=!0}items(){return s.find(this._options.items,this._node)}}i.defaults={appendTo:"body",axis:null,cancel:"input, textarea, button, select, option",connectWith:null,cursor:"auto",disabled:!1,dropOnEmpty:!0,handle:null,helperClass:"bg-body-tertiary",items:":scope > li",scroll:!0,scrollSensitivity:20,scrollSpeed:5};const o=i.prototype;o._checkScroll=function(){s.hide(this._target);const t=s.getScrollX(window),e=s.getScrollY(window);let i=t,o=e;if(this._pos.y<e+this._options.scrollSensitivity)o=Math.max(0,e-this._options.scrollSpeed);else if(this._pos.y>e+s.height(window)-this._options.scrollSensitivity){const t=s.height(document,{boxSize:s.SCROLL_BOX});o=Math.min(t,e+this._options.scrollSpeed)}if(this._pos.x<t+this._options.scrollSensitivity)i=Math.max(0,t-this._options.scrollSpeed);else if(this._pos.x>t+s.width(window)-this._options.scrollSensitivity){const e=s.width(document,{boxSize:s.SCROLL_BOX});i=Math.min(e,t+this._options.scrollSpeed)}i===t&&o===e||(s.setStyle(":root",{scrollBehavior:"initial"}),s.setScroll(document,i,o),s.setStyle(":root",{scrollBehavior:""}),this._pos.x+=i-t,this._pos.y+=o-e),s.show(this._target),this._checkScrollTimer=setTimeout((t=>{this._checkScroll()}),0)},o._events=function(){const t=s.mouseDragFactory((t=>{if(t.button||!this._enabled||s.is(t.currentTarget,this._options.cancel)||s.getDataset(this._node,"uiDragging"))return!1;this._target=this._options.handle?this.items().find((e=>s.hasDescendent(e,t.currentTarget))):t.currentTarget}),(t=>{this._pos=e.getPosition(t),s.getDataset(this._node,"uiDragging")||(s.setDataset(this._node,{uiDragging:!0}),this._startIndex=s.index(this._target),this._currentIndex=this._startIndex,s.triggerEvent(this._node,"sort.ui.sortable",{detail:{target:this._target}}),this._options.helperClass&&s.addClass(this._target,this._options.helperClass),this._currentSortable=this._node,this._options.scroll&&this._checkScroll());let i=this._node;if(this._options.connectWith){const t=s.find(this._options.connectWith).filter((t=>{const e=this.constructor.init(t);return e._options.dropOnEmpty||e.items().length}));t.length&&(i=s.nearestTo([this._node,...t],this._pos.x,this._pos.y,{offset:!0}))}const o=s.isSame(this._node,i)?this.items():this.constructor.init(i).items(),r=s.nearestTo(o,this._pos.x,this._pos.y,{offset:!0});if(!r)return;this._updateTarget(r,this._pos.x,this._pos.y);const n=s.index(this._target);s.isSame(i,this._currentSortable)?this._currentIndex!==n&&s.triggerEvent(i,"sorting.ui.sortable",{detail:{target:this._target}}):(s.triggerEvent(this._currentSortable,"send.ui.sortable",{detail:{target:this._target}}),s.triggerEvent(i,"receive.ui.sortable",{detail:{target:this._target}})),this._currentIndex=n,this._currentSortable=i}),(t=>{s.getDataset(this._node,"uiDragging")?("mouseup"===t.type&&t.preventDefault(),s.triggerEvent(this._currentSortable,"sorted.ui.sortable",{detail:{target:this._target}}),this._options.helperClass&&s.removeClass(this._target,this._options.helperClass),this._currentIndex===this._startIndex&&s.isSame(this._currentSortable,this._node)||s.triggerEvent(this._currentSortable,"update.ui.sortable",{detail:{target:this._target}}),s.removeDataset(this._node,"uiDragging"),this._checkScrollTimer&&(clearTimeout(this._checkScrollTimer),this._checkScrollTimer=null),this._target=null,this._currentSortable=null,this._currentIndex=null,this._startIndex=null):this._target=null}));s.addEventDelegate(this._node,"mousedown.ui.sortable touchstart.ui.sortable",this._selector,t),s.addEvent(this._node,"receive.ui.sortable",(t=>{this._refreshCursors()}))},o._refreshCursors=function(){const t=s.find(this._selector,this._node);s.setStyle(t,{cursor:this._options.cursor})},o._updateTarget=function(t,e,i){const o=s.center(t,{offset:!0}),r=s.center(this._target,{offset:!0});let n;n="y"===this._options.axis||o.x===r.x?i<o.y?"before":"after":"x"===this._options.axis||o.y===r.y?e<o.x?"before":"after":e<o.x&&i<o.y?"before":"after",s[n](t,this._target)},e.initComponent("sortable",i),t.Sortable=i}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Sortable","BaseComponent","constructor","node","options","super","this","_selector","_options","items","handle","_enabled","disabled","_refreshCursors","_events","disable","dispose","$","removeEventDelegate","_node","removeEvent","_target","_currentSortable","enable","find","defaults","appendTo","axis","cancel","connectWith","cursor","dropOnEmpty","helperClass","scroll","scrollSensitivity","scrollSpeed","proto","prototype","_checkScroll","hide","originalX","getScrollX","window","originalY","getScrollY","offsetX","offsetY","_pos","y","Math","max","height","docHeight","document","boxSize","SCROLL_BOX","min","x","width","docWidth","setStyle","scrollBehavior","setScroll","show","_checkScrollTimer","setTimeout","_","dragEvent","mouseDragFactory","e","button","is","currentTarget","getDataset","type","preventDefault","hasDescendent","getPosition","setDataset","uiDragging","_startIndex","index","_currentIndex","triggerEvent","detail","target","addClass","nearestSortable","connected","filter","sortable","init","length","nearestTo","offset","nearestItems","isSame","nearestItem","_updateTarget","newIndex","removeClass","removeDataset","clearTimeout","addEventDelegate","addEvent","elements","nearestCenter","center","targetCenter","method","initComponent"],"sources":["../src/sortable.js","../src/index.js","../src/prototype/helpers.js","../src/prototype/events.js"],"sourcesContent":["import $ from '@fr0st/query';\nimport { BaseComponent } from '@fr0st/ui';\n\n/**\n * Sortable Class\n * @class\n */\nexport default class Sortable extends BaseComponent {\n /**\n * New Sortable constructor.\n * @param {HTMLElement} node The input node.\n * @param {object} [options] The options to create the Sortable with.\n */\n constructor(node, options) {\n super(node, options);\n\n this._selector = this._options.items;\n if (this._options.handle) {\n this._selector += ' ' + this._options.handle;\n }\n\n this._enabled = !this._options.disabled;\n\n this._refreshCursors();\n this._events();\n }\n\n /**\n * Disable the Sortable.\n */\n disable() {\n this._enabled = false;\n }\n\n /**\n * Dispose the Sortable.\n */\n dispose() {\n $.removeEventDelegate(this._node, 'mousedown.ui.sortable touchstart.ui.sortable');\n $.removeEvent(this._node, 'receive.ui.sortable');\n\n this._target = null;\n this._currentSortable = null;\n\n super.dispose();\n }\n\n /**\n * Enable the Sortable.\n */\n enable() {\n this._enabled = true;\n }\n\n /**\n * Get the Sortable item elements.\n * @return {array} The Sortable item elements.\n */\n items() {\n return $.find(this._options.items, this._node);\n }\n}\n","import { initComponent } from '@fr0st/ui';\nimport Sortable from './sortable.js';\nimport { _events } from './prototype/events.js';\nimport { _checkScroll, _refreshCursors, _updateTarget } from './prototype/helpers.js';\n\n// Sortable default options\nSortable.defaults = {\n appendTo: 'body',\n axis: null,\n cancel: 'input, textarea, button, select, option',\n connectWith: null,\n cursor: 'auto',\n disabled: false,\n dropOnEmpty: true,\n handle: null,\n helperClass: 'bg-body-tertiary',\n items: ':scope > li',\n scroll: true,\n scrollSensitivity: 20,\n scrollSpeed: 5,\n};\n\n// Sortable prototype\nconst proto = Sortable.prototype;\n\nproto._checkScroll = _checkScroll;\nproto._events = _events;\nproto._refreshCursors = _refreshCursors;\nproto._updateTarget = _updateTarget;\n\n// Sortable init\ninitComponent('sortable', Sortable);\n\nexport default Sortable;\n","import $ from '@fr0st/query';\n\n/**\n * Check for window scroll.\n */\nexport function _checkScroll() {\n $.hide(this._target);\n\n const originalX = $.getScrollX(window);\n const originalY = $.getScrollY(window);\n\n let offsetX = originalX;\n let offsetY = originalY;\n\n if (this._pos.y < originalY + this._options.scrollSensitivity) {\n offsetY = Math.max(0, originalY - this._options.scrollSpeed);\n } else if (this._pos.y > originalY + $.height(window) - this._options.scrollSensitivity) {\n const docHeight = $.height(document, { boxSize: $.SCROLL_BOX });\n offsetY = Math.min(docHeight, originalY + this._options.scrollSpeed);\n }\n\n if (this._pos.x < originalX + this._options.scrollSensitivity) {\n offsetX = Math.max(0, originalX - this._options.scrollSpeed);\n } else if (this._pos.x > originalX + $.width(window) - this._options.scrollSensitivity) {\n const docWidth = $.width(document, { boxSize: $.SCROLL_BOX });\n offsetX = Math.min(docWidth, originalX + this._options.scrollSpeed);\n }\n\n if (offsetX !== originalX || offsetY !== originalY) {\n $.setStyle(':root', { scrollBehavior: 'initial' });\n $.setScroll(document, offsetX, offsetY);\n $.setStyle(':root', { scrollBehavior: '' });\n\n this._pos.x += offsetX - originalX;\n this._pos.y += offsetY - originalY;\n }\n\n $.show(this._target);\n\n this._checkScrollTimer = setTimeout((_) => {\n this._checkScroll();\n }, 0);\n};\n\n/**\n * Refresh Sortable item cursors.\n */\nexport function _refreshCursors() {\n const elements = $.find(this._selector, this._node);\n\n $.setStyle(elements, { cursor: this._options.cursor });\n};\n\n/**\n * Update the target element.\n * @param {HTMLElement} nearestItem The current nearest item.\n * @param {number} x The mouse X position.\n * @param {number} y The mouse Y position.\n */\nexport function _updateTarget(nearestItem, x, y) {\n const nearestCenter = $.center(nearestItem, { offset: true });\n const targetCenter = $.center(this._target, { offset: true });\n\n let method;\n if (this._options.axis === 'y' || nearestCenter.x === targetCenter.x) {\n method = y < nearestCenter.y ?\n 'before' :\n 'after';\n } else if (this._options.axis === 'x' || nearestCenter.y === targetCenter.y) {\n method = x < nearestCenter.x ?\n 'before' :\n 'after';\n } else {\n method = x < nearestCenter.x && y < nearestCenter.y ?\n 'before' :\n 'after';\n }\n\n $[method](nearestItem, this._target);\n};\n","import $ from '@fr0st/query';\nimport { getPosition } from '@fr0st/ui';\n\n/**\n * Attach events for the Sortable.\n */\nexport function _events() {\n const downEvent = (e) => {\n if (\n e.button ||\n !this._enabled ||\n $.is(e.currentTarget, this._options.cancel) ||\n $.getDataset(this._node, 'uiDragging')\n ) {\n return false;\n }\n\n if (e.type === 'mousedown') {\n e.preventDefault();\n }\n\n this._target = this._options.handle ?\n this.items().find((node) => $.hasDescendent(node, e.currentTarget)) :\n e.currentTarget;\n };\n\n const moveEvent = (e) => {\n this._pos = getPosition(e);\n\n if (!$.getDataset(this._node, 'uiDragging')) {\n $.setDataset(this._node, { uiDragging: true });\n\n this._startIndex = $.index(this._target);\n this._currentIndex = this._startIndex;\n\n $.triggerEvent(this._node, 'sort.ui.sortable', {\n detail: {\n target: this._target,\n },\n });\n\n if (this._options.helperClass) {\n $.addClass(this._target, this._options.helperClass);\n }\n\n this._currentSortable = this._node;\n\n if (this._options.scroll) {\n this._checkScroll();\n }\n }\n\n let nearestSortable = this._node;\n\n if (this._options.connectWith) {\n const connected = $.find(this._options.connectWith)\n .filter((node) => {\n const sortable = this.constructor.init(node);\n\n return sortable._options.dropOnEmpty || sortable.items().length;\n });\n\n if (connected.length) {\n nearestSortable = $.nearestTo([this._node, ...connected], this._pos.x, this._pos.y, { offset: true });\n }\n }\n\n const nearestItems = $.isSame(this._node, nearestSortable) ?\n this.items() :\n this.constructor.init(nearestSortable).items();\n\n const nearestItem = $.nearestTo(nearestItems, this._pos.x, this._pos.y, { offset: true });\n\n if (!nearestItem) {\n return;\n }\n\n this._updateTarget(nearestItem, this._pos.x, this._pos.y);\n\n const newIndex = $.index(this._target);\n\n if (!$.isSame(nearestSortable, this._currentSortable)) {\n $.triggerEvent(this._currentSortable, 'send.ui.sortable', {\n detail: {\n target: this._target,\n },\n });\n\n $.triggerEvent(nearestSortable, 'receive.ui.sortable', {\n detail: {\n target: this._target,\n },\n });\n } else if (this._currentIndex !== newIndex) {\n $.triggerEvent(nearestSortable, 'sorting.ui.sortable', {\n detail: {\n target: this._target,\n },\n });\n }\n\n this._currentIndex = newIndex;\n this._currentSortable = nearestSortable;\n };\n\n const upEvent = (e) => {\n if (!$.getDataset(this._node, 'uiDragging')) {\n this._target = null;\n return;\n }\n\n if (e.type === 'mouseup') {\n e.preventDefault();\n }\n\n $.triggerEvent(this._currentSortable, 'sorted.ui.sortable', {\n detail: {\n target: this._target,\n },\n });\n\n if (this._options.helperClass) {\n $.removeClass(this._target, this._options.helperClass);\n }\n\n if (this._currentIndex !== this._startIndex || !$.isSame(this._currentSortable, this._node)) {\n $.triggerEvent(this._currentSortable, 'update.ui.sortable', {\n detail: {\n target: this._target,\n },\n });\n }\n\n $.removeDataset(this._node, 'uiDragging');\n\n if (this._checkScrollTimer) {\n clearTimeout(this._checkScrollTimer);\n this._checkScrollTimer = null;\n }\n\n this._target = null;\n this._currentSortable = null;\n this._currentIndex = null;\n this._startIndex = null;\n };\n\n const dragEvent = $.mouseDragFactory(downEvent, moveEvent, upEvent);\n\n $.addEventDelegate(this._node, 'mousedown.ui.sortable touchstart.ui.sortable', this._selector, dragEvent);\n\n $.addEvent(this._node, 'receive.ui.sortable', (_) => {\n this._refreshCursors();\n });\n};\n"],"mappings":"0UAOe,MAAMA,UAAiBC,gBAMlCC,YAAYC,EAAMC,GACdC,MAAMF,EAAMC,GAEZE,KAAKC,UAAYD,KAAKE,SAASC,MAC3BH,KAAKE,SAASE,SACdJ,KAAKC,WAAa,IAAMD,KAAKE,SAASE,QAG1CJ,KAAKK,UAAYL,KAAKE,SAASI,SAE/BN,KAAKO,kBACLP,KAAKQ,SACb,CAKIC,UACIT,KAAKK,UAAW,CACxB,CAKIK,UACIC,EAAEC,oBAAoBZ,KAAKa,MAAO,gDAClCF,EAAEG,YAAYd,KAAKa,MAAO,uBAE1Bb,KAAKe,QAAU,KACff,KAAKgB,iBAAmB,KAExBjB,MAAMW,SACd,CAKIO,SACIjB,KAAKK,UAAW,CACxB,CAMIF,QACI,OAAOQ,EAAEO,KAAKlB,KAAKE,SAASC,MAAOH,KAAKa,MAChD,ECtDAnB,EAASyB,SAAW,CAChBC,SAAU,OACVC,KAAM,KACNC,OAAQ,0CACRC,YAAa,KACbC,OAAQ,OACRlB,UAAU,EACVmB,aAAa,EACbrB,OAAQ,KACRsB,YAAa,mBACbvB,MAAO,cACPwB,QAAQ,EACRC,kBAAmB,GACnBC,YAAa,GAIjB,MAAMC,EAAQpC,EAASqC,UAEvBD,EAAME,aCpBC,WACHrB,EAAEsB,KAAKjC,KAAKe,SAEZ,MAAMmB,EAAYvB,EAAEwB,WAAWC,QACzBC,EAAY1B,EAAE2B,WAAWF,QAE/B,IAAIG,EAAUL,EACVM,EAAUH,EAEd,GAAIrC,KAAKyC,KAAKC,EAAIL,EAAYrC,KAAKE,SAAS0B,kBACxCY,EAAUG,KAAKC,IAAI,EAAGP,EAAYrC,KAAKE,SAAS2B,kBAC7C,GAAI7B,KAAKyC,KAAKC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AAWD,KAAKa,OAE7CF,EAAE2C,SAAS6C,EAAU,CAAE3E,OAAQxB,KAAKE,SAASsB,QACjD,EDvBAM,EAAM8D,cC+BC,SAAuBD,EAAaxC,EAAGT,GAC1C,MAAM0D,EAAgBzF,EAAE0F,OAAOV,EAAa,CAAEH,QAAQ,IAChDc,EAAe3F,EAAE0F,OAAOrG,KAAKe,QAAS,CAAEyE,QAAQ,IAEtD,IAAIe,EAEAA,EADuB,MAAvBvG,KAAKE,SAASmB,MAAgB+E,EAAcjD,IAAMmD,EAAanD,EACtDT,EAAI0D,EAAc1D,EACvB,SACA,QAC0B,MAAvB1C,KAAKE,SAASmB,MAAgB+E,EAAc1D,IAAM4D,EAAa5D,EAC7DS,EAAIiD,EAAcjD,EACvB,SACA,QAEKA,EAAIiD,EAAcjD,GAAKT,EAAI0D,EAAc1D,EAC9C,SACA,QAGR/B,EAAE4F,GAAQZ,EAAa3F,KAAKe,QAChC,EDhDAyF,gBAAc,WAAY9G,G"}
|
|
1
|
+
{"version":3,"names":["Sortable","BaseComponent","constructor","node","options","super","this","_selector","_options","items","handle","_enabled","disabled","_refreshCursors","_events","disable","dispose","$","removeEventDelegate","_node","removeEvent","_target","_currentSortable","enable","find","defaults","appendTo","axis","cancel","connectWith","cursor","dropOnEmpty","helperClass","scroll","scrollSensitivity","scrollSpeed","proto","prototype","_checkScroll","hide","originalX","getScrollX","window","originalY","getScrollY","offsetX","offsetY","_pos","y","Math","max","height","docHeight","document","boxSize","SCROLL_BOX","min","x","width","docWidth","setStyle","scrollBehavior","setScroll","show","_checkScrollTimer","setTimeout","_","dragEvent","mouseDragFactory","e","button","is","currentTarget","getDataset","hasDescendent","getPosition","setDataset","uiDragging","_startIndex","index","_currentIndex","triggerEvent","detail","target","addClass","nearestSortable","connected","filter","sortable","init","length","nearestTo","offset","nearestItems","isSame","nearestItem","_updateTarget","newIndex","type","preventDefault","removeClass","removeDataset","clearTimeout","addEventDelegate","addEvent","elements","nearestCenter","center","targetCenter","method","initComponent"],"sources":["../src/sortable.js","../src/index.js","../src/prototype/helpers.js","../src/prototype/events.js"],"sourcesContent":["import $ from '@fr0st/query';\nimport { BaseComponent } from '@fr0st/ui';\n\n/**\n * Sortable Class\n * @class\n */\nexport default class Sortable extends BaseComponent {\n /**\n * New Sortable constructor.\n * @param {HTMLElement} node The input node.\n * @param {object} [options] The options to create the Sortable with.\n */\n constructor(node, options) {\n super(node, options);\n\n this._selector = this._options.items;\n if (this._options.handle) {\n this._selector += ' ' + this._options.handle;\n }\n\n this._enabled = !this._options.disabled;\n\n this._refreshCursors();\n this._events();\n }\n\n /**\n * Disable the Sortable.\n */\n disable() {\n this._enabled = false;\n }\n\n /**\n * Dispose the Sortable.\n */\n dispose() {\n $.removeEventDelegate(this._node, 'mousedown.ui.sortable touchstart.ui.sortable');\n $.removeEvent(this._node, 'receive.ui.sortable');\n\n this._target = null;\n this._currentSortable = null;\n\n super.dispose();\n }\n\n /**\n * Enable the Sortable.\n */\n enable() {\n this._enabled = true;\n }\n\n /**\n * Get the Sortable item elements.\n * @return {array} The Sortable item elements.\n */\n items() {\n return $.find(this._options.items, this._node);\n }\n}\n","import { initComponent } from '@fr0st/ui';\nimport Sortable from './sortable.js';\nimport { _events } from './prototype/events.js';\nimport { _checkScroll, _refreshCursors, _updateTarget } from './prototype/helpers.js';\n\n// Sortable default options\nSortable.defaults = {\n appendTo: 'body',\n axis: null,\n cancel: 'input, textarea, button, select, option',\n connectWith: null,\n cursor: 'auto',\n disabled: false,\n dropOnEmpty: true,\n handle: null,\n helperClass: 'bg-body-tertiary',\n items: ':scope > li',\n scroll: true,\n scrollSensitivity: 20,\n scrollSpeed: 5,\n};\n\n// Sortable prototype\nconst proto = Sortable.prototype;\n\nproto._checkScroll = _checkScroll;\nproto._events = _events;\nproto._refreshCursors = _refreshCursors;\nproto._updateTarget = _updateTarget;\n\n// Sortable init\ninitComponent('sortable', Sortable);\n\nexport default Sortable;\n","import $ from '@fr0st/query';\n\n/**\n * Check for window scroll.\n */\nexport function _checkScroll() {\n $.hide(this._target);\n\n const originalX = $.getScrollX(window);\n const originalY = $.getScrollY(window);\n\n let offsetX = originalX;\n let offsetY = originalY;\n\n if (this._pos.y < originalY + this._options.scrollSensitivity) {\n offsetY = Math.max(0, originalY - this._options.scrollSpeed);\n } else if (this._pos.y > originalY + $.height(window) - this._options.scrollSensitivity) {\n const docHeight = $.height(document, { boxSize: $.SCROLL_BOX });\n offsetY = Math.min(docHeight, originalY + this._options.scrollSpeed);\n }\n\n if (this._pos.x < originalX + this._options.scrollSensitivity) {\n offsetX = Math.max(0, originalX - this._options.scrollSpeed);\n } else if (this._pos.x > originalX + $.width(window) - this._options.scrollSensitivity) {\n const docWidth = $.width(document, { boxSize: $.SCROLL_BOX });\n offsetX = Math.min(docWidth, originalX + this._options.scrollSpeed);\n }\n\n if (offsetX !== originalX || offsetY !== originalY) {\n $.setStyle(':root', { scrollBehavior: 'initial' });\n $.setScroll(document, offsetX, offsetY);\n $.setStyle(':root', { scrollBehavior: '' });\n\n this._pos.x += offsetX - originalX;\n this._pos.y += offsetY - originalY;\n }\n\n $.show(this._target);\n\n this._checkScrollTimer = setTimeout((_) => {\n this._checkScroll();\n }, 0);\n};\n\n/**\n * Refresh Sortable item cursors.\n */\nexport function _refreshCursors() {\n const elements = $.find(this._selector, this._node);\n\n $.setStyle(elements, { cursor: this._options.cursor });\n};\n\n/**\n * Update the target element.\n * @param {HTMLElement} nearestItem The current nearest item.\n * @param {number} x The mouse X position.\n * @param {number} y The mouse Y position.\n */\nexport function _updateTarget(nearestItem, x, y) {\n const nearestCenter = $.center(nearestItem, { offset: true });\n const targetCenter = $.center(this._target, { offset: true });\n\n let method;\n if (this._options.axis === 'y' || nearestCenter.x === targetCenter.x) {\n method = y < nearestCenter.y ?\n 'before' :\n 'after';\n } else if (this._options.axis === 'x' || nearestCenter.y === targetCenter.y) {\n method = x < nearestCenter.x ?\n 'before' :\n 'after';\n } else {\n method = x < nearestCenter.x && y < nearestCenter.y ?\n 'before' :\n 'after';\n }\n\n $[method](nearestItem, this._target);\n};\n","import $ from '@fr0st/query';\nimport { getPosition } from '@fr0st/ui';\n\n/**\n * Attach events for the Sortable.\n */\nexport function _events() {\n const downEvent = (e) => {\n if (\n e.button ||\n !this._enabled ||\n $.is(e.currentTarget, this._options.cancel) ||\n $.getDataset(this._node, 'uiDragging')\n ) {\n return false;\n }\n\n this._target = this._options.handle ?\n this.items().find((node) => $.hasDescendent(node, e.currentTarget)) :\n e.currentTarget;\n };\n\n const moveEvent = (e) => {\n this._pos = getPosition(e);\n\n if (!$.getDataset(this._node, 'uiDragging')) {\n $.setDataset(this._node, { uiDragging: true });\n\n this._startIndex = $.index(this._target);\n this._currentIndex = this._startIndex;\n\n $.triggerEvent(this._node, 'sort.ui.sortable', {\n detail: {\n target: this._target,\n },\n });\n\n if (this._options.helperClass) {\n $.addClass(this._target, this._options.helperClass);\n }\n\n this._currentSortable = this._node;\n\n if (this._options.scroll) {\n this._checkScroll();\n }\n }\n\n let nearestSortable = this._node;\n\n if (this._options.connectWith) {\n const connected = $.find(this._options.connectWith)\n .filter((node) => {\n const sortable = this.constructor.init(node);\n\n return sortable._options.dropOnEmpty || sortable.items().length;\n });\n\n if (connected.length) {\n nearestSortable = $.nearestTo([this._node, ...connected], this._pos.x, this._pos.y, { offset: true });\n }\n }\n\n const nearestItems = $.isSame(this._node, nearestSortable) ?\n this.items() :\n this.constructor.init(nearestSortable).items();\n\n const nearestItem = $.nearestTo(nearestItems, this._pos.x, this._pos.y, { offset: true });\n\n if (!nearestItem) {\n return;\n }\n\n this._updateTarget(nearestItem, this._pos.x, this._pos.y);\n\n const newIndex = $.index(this._target);\n\n if (!$.isSame(nearestSortable, this._currentSortable)) {\n $.triggerEvent(this._currentSortable, 'send.ui.sortable', {\n detail: {\n target: this._target,\n },\n });\n\n $.triggerEvent(nearestSortable, 'receive.ui.sortable', {\n detail: {\n target: this._target,\n },\n });\n } else if (this._currentIndex !== newIndex) {\n $.triggerEvent(nearestSortable, 'sorting.ui.sortable', {\n detail: {\n target: this._target,\n },\n });\n }\n\n this._currentIndex = newIndex;\n this._currentSortable = nearestSortable;\n };\n\n const upEvent = (e) => {\n if (!$.getDataset(this._node, 'uiDragging')) {\n this._target = null;\n return;\n }\n\n if (e.type === 'mouseup') {\n e.preventDefault();\n }\n\n $.triggerEvent(this._currentSortable, 'sorted.ui.sortable', {\n detail: {\n target: this._target,\n },\n });\n\n if (this._options.helperClass) {\n $.removeClass(this._target, this._options.helperClass);\n }\n\n if (this._currentIndex !== this._startIndex || !$.isSame(this._currentSortable, this._node)) {\n $.triggerEvent(this._currentSortable, 'update.ui.sortable', {\n detail: {\n target: this._target,\n },\n });\n }\n\n $.removeDataset(this._node, 'uiDragging');\n\n if (this._checkScrollTimer) {\n clearTimeout(this._checkScrollTimer);\n this._checkScrollTimer = null;\n }\n\n this._target = null;\n this._currentSortable = null;\n this._currentIndex = null;\n this._startIndex = null;\n };\n\n const dragEvent = $.mouseDragFactory(downEvent, moveEvent, upEvent);\n\n $.addEventDelegate(this._node, 'mousedown.ui.sortable touchstart.ui.sortable', this._selector, dragEvent);\n\n $.addEvent(this._node, 'receive.ui.sortable', (_) => {\n this._refreshCursors();\n });\n};\n"],"mappings":"0UAOe,MAAMA,UAAiBC,gBAMlCC,YAAYC,EAAMC,GACdC,MAAMF,EAAMC,GAEZE,KAAKC,UAAYD,KAAKE,SAASC,MAC3BH,KAAKE,SAASE,SACdJ,KAAKC,WAAa,IAAMD,KAAKE,SAASE,QAG1CJ,KAAKK,UAAYL,KAAKE,SAASI,SAE/BN,KAAKO,kBACLP,KAAKQ,SACb,CAKIC,UACIT,KAAKK,UAAW,CACxB,CAKIK,UACIC,EAAEC,oBAAoBZ,KAAKa,MAAO,gDAClCF,EAAEG,YAAYd,KAAKa,MAAO,uBAE1Bb,KAAKe,QAAU,KACff,KAAKgB,iBAAmB,KAExBjB,MAAMW,SACd,CAKIO,SACIjB,KAAKK,UAAW,CACxB,CAMIF,QACI,O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