wj-elements 0.7.7 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/animations.js +28 -51
- package/dist/animations.js.map +1 -1
- package/dist/base-path.js +19 -31
- package/dist/base-path.js.map +1 -1
- package/dist/custom-elements.json +11504 -11499
- package/dist/dark.css +1 -302
- package/dist/date.js +16 -36
- package/dist/date.js.map +1 -1
- package/dist/element-utils.js +20 -81
- package/dist/element-utils.js.map +1 -1
- package/dist/event.js +49 -165
- package/dist/event.js.map +1 -1
- package/dist/form-associated-element-BjeJn7j8.js +101 -0
- package/dist/{form-associated-element-DEQ4y-jn.js.map → form-associated-element-BjeJn7j8.js.map} +1 -1
- package/dist/icon-DmsqtDpL.js +102 -0
- package/dist/{icon-CReYMzAK.js.map → icon-DmsqtDpL.js.map} +1 -1
- package/dist/light.css +1 -731
- package/dist/localize.js +36 -111
- package/dist/localize.js.map +1 -1
- package/dist/packages/wje-accordion-item/accordion-item.element.d.ts +3 -2
- package/dist/permissions.js +14 -41
- package/dist/permissions.js.map +1 -1
- package/dist/popup.element-CbkhthPP.js +806 -0
- package/dist/{popup.element-CwXvVFK7.js.map → popup.element-CbkhthPP.js.map} +1 -1
- package/dist/router-links-CNsJ-elb.js +105 -0
- package/dist/{router-links-wjqCnncc.js.map → router-links-CNsJ-elb.js.map} +1 -1
- package/dist/skeleton.css +1 -197
- package/dist/styles.css +1 -866
- package/dist/universal-service.js +48 -109
- package/dist/universal-service.js.map +1 -1
- package/dist/utils.js +11 -18
- package/dist/utils.js.map +1 -1
- package/dist/web-types.json +760 -760
- package/dist/wje-accordion-item.js +33 -106
- package/dist/wje-accordion-item.js.map +1 -1
- package/dist/wje-accordion.js +19 -84
- package/dist/wje-accordion.js.map +1 -1
- package/dist/wje-animation.js +37 -4258
- package/dist/wje-animation.js.map +1 -1
- package/dist/wje-aside.js +9 -34
- package/dist/wje-aside.js.map +1 -1
- package/dist/wje-avatar.js +36 -126
- package/dist/wje-avatar.js.map +1 -1
- package/dist/wje-badge.js +10 -52
- package/dist/wje-badge.js.map +1 -1
- package/dist/wje-breadcrumb.js +205 -672
- package/dist/wje-breadcrumb.js.map +1 -1
- package/dist/wje-breadcrumbs.js +177 -633
- package/dist/wje-breadcrumbs.js.map +1 -1
- package/dist/wje-button-group.js +48 -153
- package/dist/wje-button-group.js.map +1 -1
- package/dist/wje-button.js +92 -413
- package/dist/wje-button.js.map +1 -1
- package/dist/wje-card-content.js +7 -30
- package/dist/wje-card-content.js.map +1 -1
- package/dist/wje-card-controls.js +7 -30
- package/dist/wje-card-controls.js.map +1 -1
- package/dist/wje-card-header.js +7 -30
- package/dist/wje-card-header.js.map +1 -1
- package/dist/wje-card-subtitle.js +7 -34
- package/dist/wje-card-subtitle.js.map +1 -1
- package/dist/wje-card-title.js +7 -34
- package/dist/wje-card-title.js.map +1 -1
- package/dist/wje-card.js +15 -71
- package/dist/wje-card.js.map +1 -1
- package/dist/wje-carousel-item.js +12 -56
- package/dist/wje-carousel-item.js.map +1 -1
- package/dist/wje-carousel.js +154 -509
- package/dist/wje-carousel.js.map +1 -1
- package/dist/wje-checkbox.js +50 -227
- package/dist/wje-checkbox.js.map +1 -1
- package/dist/wje-chip.js +43 -160
- package/dist/wje-chip.js.map +1 -1
- package/dist/wje-col.js +7 -20
- package/dist/wje-col.js.map +1 -1
- package/dist/wje-color-picker.js +445 -1464
- package/dist/wje-color-picker.js.map +1 -1
- package/dist/wje-container.js +9 -35
- package/dist/wje-container.js.map +1 -1
- package/dist/wje-copy-button.js +64 -204
- package/dist/wje-copy-button.js.map +1 -1
- package/dist/wje-dialog.js +85 -553
- package/dist/wje-dialog.js.map +1 -1
- package/dist/wje-divider.js +7 -34
- package/dist/wje-divider.js.map +1 -1
- package/dist/wje-dropdown.js +78 -305
- package/dist/wje-dropdown.js.map +1 -1
- package/dist/wje-element.js +191 -700
- package/dist/wje-element.js.map +1 -1
- package/dist/wje-file-upload-item.js +51 -156
- package/dist/wje-file-upload-item.js.map +1 -1
- package/dist/wje-file-upload.js +181 -619
- package/dist/wje-file-upload.js.map +1 -1
- package/dist/wje-footer.js +7 -31
- package/dist/wje-footer.js.map +1 -1
- package/dist/wje-form.js +7 -32
- package/dist/wje-form.js.map +1 -1
- package/dist/wje-format-digital.js +26 -118
- package/dist/wje-format-digital.js.map +1 -1
- package/dist/wje-grid.js +7 -33
- package/dist/wje-grid.js.map +1 -1
- package/dist/wje-header.js +9 -35
- package/dist/wje-header.js.map +1 -1
- package/dist/wje-icon-library.js +12 -18
- package/dist/wje-icon-library.js.map +1 -1
- package/dist/wje-icon-picker.js +65 -320
- package/dist/wje-icon-picker.js.map +1 -1
- package/dist/wje-icon.js +1 -1
- package/dist/wje-img-comparer.js +37 -114
- package/dist/wje-img-comparer.js.map +1 -1
- package/dist/wje-img.js +50 -198
- package/dist/wje-img.js.map +1 -1
- package/dist/wje-infinite-scroll.js +94 -346
- package/dist/wje-infinite-scroll.js.map +1 -1
- package/dist/wje-input-file.js +23 -84
- package/dist/wje-input-file.js.map +1 -1
- package/dist/wje-input.js +78 -392
- package/dist/wje-input.js.map +1 -1
- package/dist/wje-item.js +11 -64
- package/dist/wje-item.js.map +1 -1
- package/dist/wje-kanban.js +124 -401
- package/dist/wje-kanban.js.map +1 -1
- package/dist/wje-label.js +9 -32
- package/dist/wje-label.js.map +1 -1
- package/dist/wje-level-indicator.js +38 -157
- package/dist/wje-level-indicator.js.map +1 -1
- package/dist/wje-list.js +10 -40
- package/dist/wje-list.js.map +1 -1
- package/dist/wje-main.js +7 -31
- package/dist/wje-main.js.map +1 -1
- package/dist/wje-masonry.js +66 -211
- package/dist/wje-masonry.js.map +1 -1
- package/dist/wje-master.js +45 -161
- package/dist/wje-master.js.map +1 -1
- package/dist/wje-menu-button.js +10 -38
- package/dist/wje-menu-button.js.map +1 -1
- package/dist/wje-menu-item.js +127 -577
- package/dist/wje-menu-item.js.map +1 -1
- package/dist/wje-menu-label.js +9 -35
- package/dist/wje-menu-label.js.map +1 -1
- package/dist/wje-menu.js +14 -49
- package/dist/wje-menu.js.map +1 -1
- package/dist/wje-option.js +48 -279
- package/dist/wje-option.js.map +1 -1
- package/dist/wje-options.js +130 -384
- package/dist/wje-options.js.map +1 -1
- package/dist/wje-orgchart-group.js +16 -52
- package/dist/wje-orgchart-group.js.map +1 -1
- package/dist/wje-orgchart-item.js +24 -93
- package/dist/wje-orgchart-item.js.map +1 -1
- package/dist/wje-orgchart.js +18 -68
- package/dist/wje-orgchart.js.map +1 -1
- package/dist/wje-pagination.js +113 -397
- package/dist/wje-pagination.js.map +1 -1
- package/dist/wje-popup.js +3 -3
- package/dist/wje-popup.js.map +1 -1
- package/dist/wje-progress-bar.js +53 -205
- package/dist/wje-progress-bar.js.map +1 -1
- package/dist/wje-qr-code.js +398 -2980
- package/dist/wje-qr-code.js.map +1 -1
- package/dist/wje-radio-group.js +52 -190
- package/dist/wje-radio-group.js.map +1 -1
- package/dist/wje-radio.js +24 -118
- package/dist/wje-radio.js.map +1 -1
- package/dist/wje-rate.js +62 -266
- package/dist/wje-rate.js.map +1 -1
- package/dist/wje-relative-time.js +24 -99
- package/dist/wje-relative-time.js.map +1 -1
- package/dist/wje-reorder-dropzone.js +9 -31
- package/dist/wje-reorder-dropzone.js.map +1 -1
- package/dist/wje-reorder-handle.js +67 -204
- package/dist/wje-reorder-handle.js.map +1 -1
- package/dist/wje-reorder-item.js +14 -44
- package/dist/wje-reorder-item.js.map +1 -1
- package/dist/wje-reorder.js +61 -246
- package/dist/wje-reorder.js.map +1 -1
- package/dist/wje-route.js +6 -24
- package/dist/wje-route.js.map +1 -1
- package/dist/wje-router-link.js +11 -39
- package/dist/wje-router-link.js.map +1 -1
- package/dist/wje-router-outlet.js +76 -172
- package/dist/wje-router-outlet.js.map +1 -1
- package/dist/wje-routerx.js +537 -1331
- package/dist/wje-routerx.js.map +1 -1
- package/dist/wje-row.js +9 -31
- package/dist/wje-row.js.map +1 -1
- package/dist/wje-select.js +326 -1152
- package/dist/wje-select.js.map +1 -1
- package/dist/wje-slider.js +44 -225
- package/dist/wje-slider.js.map +1 -1
- package/dist/wje-sliding-container.js +295 -1319
- package/dist/wje-sliding-container.js.map +1 -1
- package/dist/wje-split-view.js +35 -121
- package/dist/wje-split-view.js.map +1 -1
- package/dist/wje-status.js +14 -45
- package/dist/wje-status.js.map +1 -1
- package/dist/wje-step.js +9 -32
- package/dist/wje-step.js.map +1 -1
- package/dist/wje-stepper.js +109 -357
- package/dist/wje-stepper.js.map +1 -1
- package/dist/wje-store.js +67 -360
- package/dist/wje-store.js.map +1 -1
- package/dist/wje-tab-group.js +85 -314
- package/dist/wje-tab-group.js.map +1 -1
- package/dist/wje-tab-panel.js +7 -28
- package/dist/wje-tab-panel.js.map +1 -1
- package/dist/wje-tab.js +21 -198
- package/dist/wje-tab.js.map +1 -1
- package/dist/wje-textarea.js +64 -264
- package/dist/wje-textarea.js.map +1 -1
- package/dist/wje-thumbnail.js +10 -51
- package/dist/wje-thumbnail.js.map +1 -1
- package/dist/wje-toast.js +127 -632
- package/dist/wje-toast.js.map +1 -1
- package/dist/wje-toggle.js +52 -177
- package/dist/wje-toggle.js.map +1 -1
- package/dist/wje-toolbar-action.js +128 -456
- package/dist/wje-toolbar-action.js.map +1 -1
- package/dist/wje-toolbar.js +75 -270
- package/dist/wje-toolbar.js.map +1 -1
- package/dist/wje-tooltip.js +50 -161
- package/dist/wje-tooltip.js.map +1 -1
- package/dist/wje-tree-item.js +70 -301
- package/dist/wje-tree-item.js.map +1 -1
- package/dist/wje-tree.js +145 -489
- package/dist/wje-tree.js.map +1 -1
- package/dist/wje-visually-hidden.js +7 -34
- package/dist/wje-visually-hidden.js.map +1 -1
- package/package.json +3 -2
- package/dist/form-associated-element-DEQ4y-jn.js +0 -245
- package/dist/icon-CReYMzAK.js +0 -245
- package/dist/popup.element-CwXvVFK7.js +0 -2133
- package/dist/router-links-wjqCnncc.js +0 -156
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wje-relative-time.js","sources":["../packages/wje-relative-time/relative-time.element.js","../packages/wje-relative-time/relative-time.js"],"sourcesContent":["import { Localizer } from '../utils/localize.js';\nimport { default as WJElement } from '../wje-element/element.js';\n\n/**\n * `RelativeTime` is a custom web component that represents a relative time component.\n * @summary This element represents a relative time component.\n * @documentation https://elements.webjet.sk/components/relative-time\n * @status stable\n * @augments WJElement\n * @csspart native - The native part of the relative time component.\n * @tag wje-relative-time\n */\n\nexport default class RelativeTime extends WJElement {\n /**\n * Creates an instance of RelativeTime.\n * @class\n */\n constructor() {\n super();\n this.localizer = new Localizer(this);\n }\n\n /**\n * Sets the date of the relative time component.\n * @param value\n */\n set date(value) {\n this.setAttribute('date', value);\n }\n\n /**\n * Gets the date of the relative time component.\n * @returns {string}\n */\n get date() {\n return this.getAttribute('date');\n }\n\n /**\n * Sets the object date of the relative time component.\n * @param value\n */\n set objectDate(value) {\n this.setAttribute('object-date', value);\n }\n\n /**\n * Gets the object date of the relative time component.\n * @returns {Date}\n */\n get objectDate() {\n let date = new Date();\n let inputDate = this.date;\n\n if (!!inputDate && inputDate !== '') {\n inputDate = this.isISODate(inputDate) ? inputDate : +inputDate * 1000;\n\n date = new Date(inputDate);\n }\n\n return date;\n }\n\n /**\n * Sets the lang of the relative time component.\n * @type {string}\n */\n className = 'RelativeTime';\n\n /**\n * Returns the list of attributes to observe for changes.\n * @static\n * @returns {Array<string>}\n */\n static get observedAttributes() {\n return ['date', 'lang'];\n }\n\n attributeChangedCallback(name, oldValue, newValue) {\n super.attributeChangedCallback?.(name, oldValue, newValue);\n if (oldValue === newValue) return;\n if (this.native) {\n this.native.innerText = this.getRelativeTimeString();\n if (this.date) this.native.setAttribute('datetime', this.date);\n else this.native.removeAttribute('datetime');\n }\n }\n\n /**\n * Sets up the attributes for the component.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n this.setAriaState({ role: 'status' });\n }\n\n /**\n * Draws the component for the relative time.\n * @returns {DocumentFragment}\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let element = document.createElement('div');\n element.setAttribute('part', 'native');\n element.classList.add('native-relative-time');\n element.innerText = this.getRelativeTimeString();\n if (this.date) element.setAttribute('datetime', this.date);\n\n fragment.appendChild(element);\n this.native = element;\n\n return fragment;\n }\n\n /**\n * Returns the relative time string for the given date.\n */\n getRelativeTimeString(lang = navigator.language) {\n if (this.objectDate.toString() === 'Invalid Date' || this.objectDate.toString() === 'NaN') {\n return '';\n }\n\n const timeMs = this.objectDate.getTime();\n\n const deltaSeconds = Math.round((timeMs - Date.now()) / 1000);\n\n const cutoffs = [60, 3600, 86400, 86400 * 7, 86400 * 30, 86400 * 365, Infinity];\n\n const units = ['second', 'minute', 'hour', 'day', 'week', 'month', 'year'];\n const unitIndex = cutoffs.findIndex((cutoff) => cutoff > Math.abs(deltaSeconds));\n const divisor = unitIndex ? cutoffs[unitIndex - 1] : 1;\n\n return this.localizer.relativeTime(\n this.getAttribute('lang'),\n Math.trunc(deltaSeconds / divisor),\n units[unitIndex],\n { numeric: 'auto' }\n );\n }\n\n /**\n * Checks if the given string is an ISO date.\n * @param {string} str The string to check.\n * @returns {boolean} True if the string is an ISO date, false otherwise.\n */\n isISODate(str) {\n const date = new Date(str);\n return !isNaN(date.getTime());\n }\n}\n","import RelativeTime from './relative-time.element.js';\n\nexport default RelativeTime;\n\nRelativeTime.define('wje-relative-time', RelativeTime);\n"],"names":[],"mappings":";;;;;AAae,
|
|
1
|
+
{"version":3,"file":"wje-relative-time.js","sources":["../packages/wje-relative-time/relative-time.element.js","../packages/wje-relative-time/relative-time.js"],"sourcesContent":["import { Localizer } from '../utils/localize.js';\nimport { default as WJElement } from '../wje-element/element.js';\n\n/**\n * `RelativeTime` is a custom web component that represents a relative time component.\n * @summary This element represents a relative time component.\n * @documentation https://elements.webjet.sk/components/relative-time\n * @status stable\n * @augments WJElement\n * @csspart native - The native part of the relative time component.\n * @tag wje-relative-time\n */\n\nexport default class RelativeTime extends WJElement {\n /**\n * Creates an instance of RelativeTime.\n * @class\n */\n constructor() {\n super();\n this.localizer = new Localizer(this);\n }\n\n /**\n * Sets the date of the relative time component.\n * @param value\n */\n set date(value) {\n this.setAttribute('date', value);\n }\n\n /**\n * Gets the date of the relative time component.\n * @returns {string}\n */\n get date() {\n return this.getAttribute('date');\n }\n\n /**\n * Sets the object date of the relative time component.\n * @param value\n */\n set objectDate(value) {\n this.setAttribute('object-date', value);\n }\n\n /**\n * Gets the object date of the relative time component.\n * @returns {Date}\n */\n get objectDate() {\n let date = new Date();\n let inputDate = this.date;\n\n if (!!inputDate && inputDate !== '') {\n inputDate = this.isISODate(inputDate) ? inputDate : +inputDate * 1000;\n\n date = new Date(inputDate);\n }\n\n return date;\n }\n\n /**\n * Sets the lang of the relative time component.\n * @type {string}\n */\n className = 'RelativeTime';\n\n /**\n * Returns the list of attributes to observe for changes.\n * @static\n * @returns {Array<string>}\n */\n static get observedAttributes() {\n return ['date', 'lang'];\n }\n\n attributeChangedCallback(name, oldValue, newValue) {\n super.attributeChangedCallback?.(name, oldValue, newValue);\n if (oldValue === newValue) return;\n if (this.native) {\n this.native.innerText = this.getRelativeTimeString();\n if (this.date) this.native.setAttribute('datetime', this.date);\n else this.native.removeAttribute('datetime');\n }\n }\n\n /**\n * Sets up the attributes for the component.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n this.setAriaState({ role: 'status' });\n }\n\n /**\n * Draws the component for the relative time.\n * @returns {DocumentFragment}\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let element = document.createElement('div');\n element.setAttribute('part', 'native');\n element.classList.add('native-relative-time');\n element.innerText = this.getRelativeTimeString();\n if (this.date) element.setAttribute('datetime', this.date);\n\n fragment.appendChild(element);\n this.native = element;\n\n return fragment;\n }\n\n /**\n * Returns the relative time string for the given date.\n */\n getRelativeTimeString(lang = navigator.language) {\n if (this.objectDate.toString() === 'Invalid Date' || this.objectDate.toString() === 'NaN') {\n return '';\n }\n\n const timeMs = this.objectDate.getTime();\n\n const deltaSeconds = Math.round((timeMs - Date.now()) / 1000);\n\n const cutoffs = [60, 3600, 86400, 86400 * 7, 86400 * 30, 86400 * 365, Infinity];\n\n const units = ['second', 'minute', 'hour', 'day', 'week', 'month', 'year'];\n const unitIndex = cutoffs.findIndex((cutoff) => cutoff > Math.abs(deltaSeconds));\n const divisor = unitIndex ? cutoffs[unitIndex - 1] : 1;\n\n return this.localizer.relativeTime(\n this.getAttribute('lang'),\n Math.trunc(deltaSeconds / divisor),\n units[unitIndex],\n { numeric: 'auto' }\n );\n }\n\n /**\n * Checks if the given string is an ISO date.\n * @param {string} str The string to check.\n * @returns {boolean} True if the string is an ISO date, false otherwise.\n */\n isISODate(str) {\n const date = new Date(str);\n return !isNaN(date.getTime());\n }\n}\n","import RelativeTime from './relative-time.element.js';\n\nexport default RelativeTime;\n\nRelativeTime.define('wje-relative-time', RelativeTime);\n"],"names":["RelativeTime","WJElement","constructor","super","className","this","localizer","Localizer","value","setAttribute","date","getAttribute","objectDate","Date","inputDate","isISODate","observedAttributes","name","oldValue","newValue","attributeChangedCallback","native","innerText","getRelativeTimeString","removeAttribute","setupAttributes","isShadowRoot","setAriaState","role","draw","fragment","document","createDocumentFragment","element","createElement","classList","add","appendChild","lang","navigator","language","toString","timeMs","getTime","deltaSeconds","Math","round","now","cutoffs","Infinity","unitIndex","findIndex","cutoff","abs","divisor","relativeTime","trunc","numeric","str","isNaN","define"],"mappings":";;;;;AAae,MAAMA,UAAqBC,EAAAA;AAAAA,EAKtC,cAAAC;AACIC,UAAAA;AAiDJC,qCAAY;AAhDRC,SAAKC,YAAY,IAAIC,EAAUF,IAAAA;AAAAA,EACnC;AAAA,EAMA,IAAA,KAASG,IAAAA;AACLH,SAAKI,aAAa,QAAQD,EAAAA;AAAAA,EAC9B;AAAA,EAMA,IAAA,OAAIE;AACA,WAAOL,KAAKM,aAAa,MAAA;AAAA,EAC7B;AAAA,EAMA,IAAA,WAAeH,IAAAA;AACXH,SAAKI,aAAa,eAAeD,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KAAKC,OAAOJ,KAAS7B,KAAKkC,IAAAA,KAAS,GAAA,GAElDC,IAAU,CAAC,IAAI,MAAM,OAAO,QAAW,QAAY,SAAaC,IAAAA,CAAAA,GAGhEC,IAAYF,EAAQG,UAAWC,CAAAA,OAAWA,KAASP,KAAKQ,IAAIT,EAAAA,CAAAA,GAC5DU,IAAUJ,IAAYF,EAAQE,IAAY,CAAA,IAAK;AAErD,WAAO7C,KAAKC,UAAUiD,aAClBlD,KAAKM,aAAa,MAAA,GAClBkC,KAAKW,MAAMZ,KAAeU,CAAAA,GANhB,CAAC,UAAU,UAAU,QAAQ,OAAO,QAAQ,SAAS,MAAA,EAOzDJ,CAAAA,GACN,EAAEO,SAAS,OAAA,CAAA;AAAA,EAEnB;AAAA,EAOA,UAAUC,IAAAA;AACN,UAAMhD,KAAO,IAAIG,KAAK6C,EAAAA;AACtB,WAAA,CAAQC,MAAMjD,GAAKiC,QAAAA,CAAAA;AAAAA,EACvB;AAAA;AClJJ3C,EAAa4D,OAAO,qBAAqB5D,CAAAA;"}
|
|
@@ -1,49 +1,27 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
class ReorderDropzone extends WJElement {
|
|
7
|
-
/**
|
|
8
|
-
* Creates an instance of ReorderDropzone.
|
|
9
|
-
*/
|
|
4
|
+
import e from "./wje-element.js";
|
|
5
|
+
class t extends e {
|
|
10
6
|
constructor() {
|
|
11
7
|
super();
|
|
12
|
-
/**
|
|
13
|
-
* The class name for the component.
|
|
14
|
-
* @type {string}
|
|
15
|
-
*/
|
|
16
8
|
__publicField(this, "className", "ReorderDropzone");
|
|
17
9
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Returns the CSS stylesheet for the component.
|
|
20
|
-
* @returns {CSSStyleSheet} The CSS stylesheet.
|
|
21
|
-
*/
|
|
22
10
|
static get cssStyleSheet() {
|
|
23
|
-
return
|
|
11
|
+
return ".dropzone{border:1px dashed lightgrey;border-radius:var(--wje-border-radius-small);margin:.5rem;display:flex;flex-direction:column;align-items:center;overflow:hidden;justify-content:center;min-height:250px;width:200px}";
|
|
24
12
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Sets up the attributes for the component.
|
|
27
|
-
*/
|
|
28
13
|
setupAttributes() {
|
|
29
14
|
this.isShadowRoot = "open";
|
|
30
15
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Returns the list of observed attributes.
|
|
33
|
-
* @returns {DocumentFragment}
|
|
34
|
-
*/
|
|
35
16
|
draw() {
|
|
36
|
-
let
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
dropzone.appendChild(slot);
|
|
41
|
-
fragment.appendChild(dropzone);
|
|
42
|
-
return fragment;
|
|
17
|
+
let e2 = document.createDocumentFragment(), t2 = document.createElement("div");
|
|
18
|
+
t2.classList.add("dropzone");
|
|
19
|
+
let r = document.createElement("slot");
|
|
20
|
+
return t2.appendChild(r), e2.appendChild(t2), e2;
|
|
43
21
|
}
|
|
44
22
|
}
|
|
45
|
-
|
|
23
|
+
t.define("wje-reorder-dropzone", t);
|
|
46
24
|
export {
|
|
47
|
-
|
|
25
|
+
t as default
|
|
48
26
|
};
|
|
49
27
|
//# sourceMappingURL=wje-reorder-dropzone.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wje-reorder-dropzone.js","sources":["../packages/wje-reorder-dropzone/reorder-dropzone.element.js","../packages/wje-reorder-dropzone/reorder-dropzone.js"],"sourcesContent":["import { default as WJElement } from '../wje-element/element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * `ReorderDropzone` is a custom web component that represents a reorder dropzone.\n * @summary This element represents a reorder dropzone.\n * @documentation https://elements.webjet.sk/components/reorder-dropzone\n * @status stable\n * @augments WJElement\n * @csspart native - The native part of the reorder dropzone.\n * @slot - The default slot for the reorder dropzone.\n * @tag wje-reorder-dropzone\n */\nexport default class ReorderDropzone extends WJElement {\n /**\n * Creates an instance of ReorderDropzone.\n */\n constructor() {\n super();\n }\n\n /**\n * The class name for the component.\n * @type {string}\n */\n className = 'ReorderDropzone';\n\n /**\n * Returns the CSS stylesheet for the component.\n * @returns {CSSStyleSheet} The CSS stylesheet.\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Sets up the attributes for the component.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Returns the list of observed attributes.\n * @returns {DocumentFragment}\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let dropzone = document.createElement('div');\n dropzone.classList.add('dropzone');\n\n let slot = document.createElement('slot');\n\n dropzone.appendChild(slot);\n\n fragment.appendChild(dropzone);\n\n return fragment;\n }\n}\n","import ReorderDropzone from './reorder-dropzone.element';\n\nexport default ReorderDropzone;\n\nReorderDropzone.define('wje-reorder-dropzone', ReorderDropzone);\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wje-reorder-dropzone.js","sources":["../packages/wje-reorder-dropzone/reorder-dropzone.element.js","../packages/wje-reorder-dropzone/reorder-dropzone.js"],"sourcesContent":["import { default as WJElement } from '../wje-element/element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * `ReorderDropzone` is a custom web component that represents a reorder dropzone.\n * @summary This element represents a reorder dropzone.\n * @documentation https://elements.webjet.sk/components/reorder-dropzone\n * @status stable\n * @augments WJElement\n * @csspart native - The native part of the reorder dropzone.\n * @slot - The default slot for the reorder dropzone.\n * @tag wje-reorder-dropzone\n */\nexport default class ReorderDropzone extends WJElement {\n /**\n * Creates an instance of ReorderDropzone.\n */\n constructor() {\n super();\n }\n\n /**\n * The class name for the component.\n * @type {string}\n */\n className = 'ReorderDropzone';\n\n /**\n * Returns the CSS stylesheet for the component.\n * @returns {CSSStyleSheet} The CSS stylesheet.\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Sets up the attributes for the component.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Returns the list of observed attributes.\n * @returns {DocumentFragment}\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let dropzone = document.createElement('div');\n dropzone.classList.add('dropzone');\n\n let slot = document.createElement('slot');\n\n dropzone.appendChild(slot);\n\n fragment.appendChild(dropzone);\n\n return fragment;\n }\n}\n","import ReorderDropzone from './reorder-dropzone.element';\n\nexport default ReorderDropzone;\n\nReorderDropzone.define('wje-reorder-dropzone', ReorderDropzone);\n"],"names":["ReorderDropzone","WJElement","super","className","cssStyleSheet","setupAttributes","this","isShadowRoot","draw","fragment","document","createDocumentFragment","dropzone","createElement","classList","add","slot","appendChild","define"],"mappings":";;;;AAae,MAAMA,UAAwBC,EAAAA;AAAAA,EAIzC;AACIC,UAAAA;AAOJC,qCAAY;AAAA,EANZ;AAAA,EAYA,WAAA,gBAAWC;AACP;EACJ;AAAA,EAKA,kBAAAC;AACIC,SAAKC,eAAe;AAAA,EACxB;AAAA,EAMA,OAAAC;AACI,QAAIC,KAAWC,SAASC,0BAEpBC,KAAWF,SAASG,cAAc,KAAA;AACtCD,IAAAA,GAASE,UAAUC,IAAI,UAAA;AAEvB,QAAIC,IAAON,SAASG,cAAc,MAAA;AAMlC,WAJAD,GAASK,YAAYD,CAAAA,GAErBP,GAASQ,YAAYL,EAAAA,GAEdH;AAAAA,EACX;AAAA;ACvDJT,EAAgBkB,OAAO,wBAAwBlB,CAAAA;"}
|
|
@@ -1,251 +1,114 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
import
|
|
5
|
-
import { event } from "./event.js";
|
|
6
|
-
|
|
7
|
-
class ReorderHandle extends WJElement {
|
|
8
|
-
/**
|
|
9
|
-
* Creates an instance of ReorderHandle.
|
|
10
|
-
*/
|
|
4
|
+
import t from "./wje-element.js";
|
|
5
|
+
import { event as e } from "./event.js";
|
|
6
|
+
class s extends t {
|
|
11
7
|
constructor() {
|
|
12
8
|
super();
|
|
13
|
-
/**
|
|
14
|
-
* The class name for the component.
|
|
15
|
-
* @type {string}
|
|
16
|
-
*/
|
|
17
9
|
__publicField(this, "className", "ReorderHandle");
|
|
18
|
-
this.addEventListener("mousedown", this.startDrag.bind(this));
|
|
19
|
-
this.addEventListener("touchstart", this.startTouchDrag.bind(this));
|
|
10
|
+
this.addEventListener("mousedown", this.startDrag.bind(this)), this.addEventListener("touchstart", this.startTouchDrag.bind(this));
|
|
20
11
|
}
|
|
21
|
-
/**
|
|
22
|
-
* Returns the CSS styles for the component.
|
|
23
|
-
* @returns {*}
|
|
24
|
-
*/
|
|
25
12
|
static get cssStyleSheet() {
|
|
26
|
-
return
|
|
13
|
+
return ".disabled{opacity:.3}";
|
|
27
14
|
}
|
|
28
|
-
/**
|
|
29
|
-
* Returns the list of attributes to observe for changes.
|
|
30
|
-
* @returns {string[]}
|
|
31
|
-
*/
|
|
32
15
|
static get observedAttributes() {
|
|
33
16
|
return ["dropzone", "parent"];
|
|
34
17
|
}
|
|
35
18
|
setupAttributes() {
|
|
36
|
-
this.isShadowRoot = "open";
|
|
37
|
-
this.syncAria();
|
|
19
|
+
this.isShadowRoot = "open", this.syncAria();
|
|
38
20
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Draws the component.
|
|
41
|
-
* @returns {DocumentFragment}
|
|
42
|
-
*/
|
|
43
21
|
draw() {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const slot = document.createElement("slot");
|
|
49
|
-
container.appendChild(slot);
|
|
50
|
-
fragment.appendChild(container);
|
|
51
|
-
return fragment;
|
|
22
|
+
const t2 = document.createDocumentFragment(), e2 = document.createElement("div");
|
|
23
|
+
e2.classList.add("container"), e2.setAttribute("part", "native");
|
|
24
|
+
const s2 = document.createElement("slot");
|
|
25
|
+
return e2.appendChild(s2), t2.appendChild(e2), t2;
|
|
52
26
|
}
|
|
53
|
-
/**
|
|
54
|
-
* Draws the component after it is connected to the DOM.
|
|
55
|
-
*/
|
|
56
27
|
afterDraw() {
|
|
57
|
-
this.syncAria();
|
|
58
|
-
if (this.hasAttribute("disabled")) {
|
|
59
|
-
this.style.opacity = ".3";
|
|
60
|
-
}
|
|
28
|
+
this.syncAria(), this.hasAttribute("disabled") && (this.style.opacity = ".3");
|
|
61
29
|
}
|
|
62
|
-
/**
|
|
63
|
-
* Sync ARIA attributes on host.
|
|
64
|
-
*/
|
|
65
30
|
syncAria() {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
if (!this.hasAttribute("tabindex")) {
|
|
70
|
-
this.setAttribute("tabindex", "0");
|
|
71
|
-
}
|
|
72
|
-
if (this.hasAttribute("disabled")) {
|
|
73
|
-
this.setAriaState({ disabled: true });
|
|
74
|
-
}
|
|
75
|
-
const ariaLabel = this.getAttribute("aria-label");
|
|
76
|
-
const label = this.getAttribute("label") || "Reorder item";
|
|
77
|
-
if (!ariaLabel && label) {
|
|
78
|
-
this.setAriaState({ label });
|
|
79
|
-
}
|
|
31
|
+
this.hasAttribute("role") || this.setAriaState({ role: "button" }), this.hasAttribute("tabindex") || this.setAttribute("tabindex", "0"), this.hasAttribute("disabled") && this.setAriaState({ disabled: true });
|
|
32
|
+
const t2 = this.getAttribute("aria-label"), e2 = this.getAttribute("label") || "Reorder item";
|
|
33
|
+
!t2 && e2 && this.setAriaState({ label: e2 });
|
|
80
34
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
* @param {DragEvent} e
|
|
84
|
-
*/
|
|
85
|
-
startDrag(e) {
|
|
86
|
-
if (this.hasAttribute("disabled") || this.hasAttribute("locked")) return;
|
|
87
|
-
this.startDragAction(e.clientX, e.clientY);
|
|
88
|
-
event.dispatchCustomEvent(this, "wje-reorder-handle:start", { draggable: this.getDraggable() });
|
|
35
|
+
startDrag(t2) {
|
|
36
|
+
this.hasAttribute("disabled") || this.hasAttribute("locked") || (this.startDragAction(t2.clientX, t2.clientY), e.dispatchCustomEvent(this, "wje-reorder-handle:start", { draggable: this.getDraggable() }));
|
|
89
37
|
}
|
|
90
|
-
|
|
91
|
-
* Handles the touch start event.
|
|
92
|
-
* @param {TouchEvent} e
|
|
93
|
-
*/
|
|
94
|
-
startTouchDrag(e) {
|
|
38
|
+
startTouchDrag(t2) {
|
|
95
39
|
if (this.hasAttribute("disabled") || this.hasAttribute("locked")) return;
|
|
96
|
-
const
|
|
97
|
-
this.startDragAction(
|
|
40
|
+
const e2 = t2.touches[0];
|
|
41
|
+
this.startDragAction(e2.clientX, e2.clientY);
|
|
98
42
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
this.setAttribute("dropzone", initialContainer.localName);
|
|
109
|
-
}
|
|
110
|
-
const rect = draggable.getBoundingClientRect();
|
|
111
|
-
const offsetX = clientX - rect.left;
|
|
112
|
-
const offsetY = clientY - rect.top;
|
|
113
|
-
let placeholder = document.createElement("div");
|
|
114
|
-
placeholder.classList.add("sortable-item");
|
|
115
|
-
placeholder.style.visibility = "hidden";
|
|
116
|
-
placeholder.style.height = `${rect.height}px`;
|
|
117
|
-
draggable.classList.add("dragging");
|
|
118
|
-
draggable.style.position = "fixed";
|
|
119
|
-
draggable.style.zIndex = "1000";
|
|
120
|
-
draggable.style.width = `${rect.width}px`;
|
|
121
|
-
const moveAt = (pageX, pageY) => {
|
|
122
|
-
draggable.style.left = `${pageX - offsetX - document.documentElement.scrollLeft}px`;
|
|
123
|
-
draggable.style.top = `${pageY - offsetY - document.documentElement.scrollTop}px`;
|
|
43
|
+
startDragAction(t2, s2) {
|
|
44
|
+
let i = this.getDraggable();
|
|
45
|
+
const r = this.getDropzone(i);
|
|
46
|
+
this.getAttribute("dropzone") || this.setAttribute("dropzone", r.localName);
|
|
47
|
+
const n = i.getBoundingClientRect(), o = t2 - n.left, a = s2 - n.top;
|
|
48
|
+
let l = document.createElement("div");
|
|
49
|
+
l.classList.add("sortable-item"), l.style.visibility = "hidden", l.style.height = `${n.height}px`, i.classList.add("dragging"), i.style.position = "fixed", i.style.zIndex = "1000", i.style.width = `${n.width}px`;
|
|
50
|
+
const d = (t3, e2) => {
|
|
51
|
+
i.style.left = t3 - o - document.documentElement.scrollLeft + "px", i.style.top = e2 - a - document.documentElement.scrollTop + "px";
|
|
124
52
|
};
|
|
125
|
-
|
|
126
|
-
const
|
|
53
|
+
d(t2, s2);
|
|
54
|
+
const h = (t3) => {
|
|
127
55
|
var _a;
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
if (!
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if ((_a = sibling.children[0]) == null ? void 0 : _a.hasAttribute("locked")) continue;
|
|
137
|
-
if (e.clientY > siblingRect.top && e.clientY < siblingRect.bottom) {
|
|
138
|
-
if (e.clientY < siblingRect.top + siblingRect.height / 2) {
|
|
139
|
-
dropzone.insertBefore(placeholder, sibling);
|
|
140
|
-
} else {
|
|
141
|
-
dropzone.insertBefore(placeholder, sibling.nextSibling);
|
|
142
|
-
}
|
|
56
|
+
d(t3.pageX, t3.pageY);
|
|
57
|
+
const e2 = this.getClosestDropzone(t3.clientX, t3.clientY);
|
|
58
|
+
if (!e2) return;
|
|
59
|
+
const s3 = Array.from(e2.children).filter((t4) => t4 !== i && t4 !== l);
|
|
60
|
+
for (const i2 of s3) {
|
|
61
|
+
const s4 = i2.getBoundingClientRect();
|
|
62
|
+
if (!((_a = i2.children[0]) == null ? void 0 : _a.hasAttribute("locked")) && (t3.clientY > s4.top && t3.clientY < s4.bottom)) {
|
|
63
|
+
t3.clientY < s4.top + s4.height / 2 ? e2.insertBefore(l, i2) : e2.insertBefore(l, i2.nextSibling);
|
|
143
64
|
break;
|
|
144
65
|
}
|
|
145
66
|
}
|
|
67
|
+
}, c = () => {
|
|
68
|
+
document.removeEventListener("mousemove", h), document.removeEventListener("mouseup", c), i.classList.remove("dragging"), i.style.position = "", i.style.zIndex = "", i.style.left = "", i.style.top = "", i.style.width = "";
|
|
69
|
+
const t3 = l.parentElement;
|
|
70
|
+
t3.insertBefore(i, l), t3.removeChild(l), this.reIndexItems(t3), e.dispatchCustomEvent(this, "wje-reorder-handle:change", { finalContainer: t3, draggable: i });
|
|
146
71
|
};
|
|
147
|
-
|
|
148
|
-
document.removeEventListener("mousemove", onMouseMove);
|
|
149
|
-
document.removeEventListener("mouseup", onMouseUp);
|
|
150
|
-
draggable.classList.remove("dragging");
|
|
151
|
-
draggable.style.position = "";
|
|
152
|
-
draggable.style.zIndex = "";
|
|
153
|
-
draggable.style.left = "";
|
|
154
|
-
draggable.style.top = "";
|
|
155
|
-
draggable.style.width = "";
|
|
156
|
-
const finalContainer = placeholder.parentElement;
|
|
157
|
-
finalContainer.insertBefore(draggable, placeholder);
|
|
158
|
-
finalContainer.removeChild(placeholder);
|
|
159
|
-
this.reIndexItems(finalContainer);
|
|
160
|
-
event.dispatchCustomEvent(this, "wje-reorder-handle:change", { finalContainer, draggable });
|
|
161
|
-
};
|
|
162
|
-
document.addEventListener("mousemove", onMouseMove);
|
|
163
|
-
document.addEventListener("mouseup", onMouseUp);
|
|
164
|
-
initialContainer.insertBefore(placeholder, draggable);
|
|
72
|
+
document.addEventListener("mousemove", h), document.addEventListener("mouseup", c), r.insertBefore(l, i);
|
|
165
73
|
}
|
|
166
|
-
/**
|
|
167
|
-
* Retrieves the closest draggable element based on attribute conditions.
|
|
168
|
-
* If the element has a "parent" attribute, the method attempts to find the closest ancestor
|
|
169
|
-
* matching the CSS selector specified in the attribute. If no such ancestor exists,
|
|
170
|
-
* the method defaults to returning the immediate parent element.
|
|
171
|
-
* @returns {Element|null} The closest matching ancestor or the immediate parent element if no match is found, or null if the element has no parent.
|
|
172
|
-
*/
|
|
173
74
|
getDraggable() {
|
|
174
75
|
if (this.hasAttribute("parent")) {
|
|
175
|
-
let
|
|
176
|
-
if (
|
|
76
|
+
let t2 = this.closest(this.getAttribute("parent"));
|
|
77
|
+
if (t2) return t2;
|
|
177
78
|
}
|
|
178
79
|
return this.parentElement;
|
|
179
80
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
*/
|
|
185
|
-
getDropzone(element) {
|
|
186
|
-
this.getAttribute("dropzone");
|
|
187
|
-
if (this.hasAttribute("dropzone")) {
|
|
188
|
-
let dropzone = element.closest(this.getAttribute("dropzone"));
|
|
189
|
-
if (dropzone) return dropzone;
|
|
81
|
+
getDropzone(t2) {
|
|
82
|
+
if (this.getAttribute("dropzone"), this.hasAttribute("dropzone")) {
|
|
83
|
+
let e2 = t2.closest(this.getAttribute("dropzone"));
|
|
84
|
+
if (e2) return e2;
|
|
190
85
|
}
|
|
191
|
-
return
|
|
86
|
+
return t2.parentElement;
|
|
192
87
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
* @param {number} clientY The y-coordinate relative to the viewport.
|
|
197
|
-
* @returns {HTMLElement|null} - The closest dropzone element matching the `dropzone` attribute, or `null` if none is found.
|
|
198
|
-
*/
|
|
199
|
-
getClosestDropzone(clientX, clientY) {
|
|
200
|
-
const elements = this.getElementsFromPointAll(clientX, clientY);
|
|
201
|
-
for (const element of elements) {
|
|
202
|
-
if (element.matches(this.getAttribute("dropzone"))) {
|
|
203
|
-
return element;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
88
|
+
getClosestDropzone(t2, e2) {
|
|
89
|
+
const s2 = this.getElementsFromPointAll(t2, e2);
|
|
90
|
+
for (const t3 of s2) if (t3.matches(this.getAttribute("dropzone"))) return t3;
|
|
206
91
|
return null;
|
|
207
92
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
*/
|
|
216
|
-
getElementsFromPointAll(x, y, root = document, visited = /* @__PURE__ */ new Set()) {
|
|
217
|
-
if (visited.has(root)) return [];
|
|
218
|
-
visited.add(root);
|
|
219
|
-
const elements = root.elementsFromPoint(x, y);
|
|
220
|
-
let allElements = [...elements];
|
|
221
|
-
for (const element of elements) {
|
|
222
|
-
if (element.shadowRoot && !visited.has(element.shadowRoot)) {
|
|
223
|
-
allElements = allElements.concat(this.getElementsFromPointAll(x, y, element.shadowRoot, visited));
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
return allElements;
|
|
93
|
+
getElementsFromPointAll(t2, e2, s2 = document, i = /* @__PURE__ */ new Set()) {
|
|
94
|
+
if (i.has(s2)) return [];
|
|
95
|
+
i.add(s2);
|
|
96
|
+
const r = s2.elementsFromPoint(t2, e2);
|
|
97
|
+
let n = [...r];
|
|
98
|
+
for (const s3 of r) s3.shadowRoot && !i.has(s3.shadowRoot) && (n = n.concat(this.getElementsFromPointAll(t2, e2, s3.shadowRoot, i)));
|
|
99
|
+
return n;
|
|
227
100
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
*/
|
|
233
|
-
reIndexItems(container) {
|
|
234
|
-
const items = Array.from(container.children);
|
|
235
|
-
let index = 0;
|
|
236
|
-
items.forEach((child) => {
|
|
101
|
+
reIndexItems(t2) {
|
|
102
|
+
const e2 = Array.from(t2.children);
|
|
103
|
+
let s2 = 0;
|
|
104
|
+
e2.forEach((t3) => {
|
|
237
105
|
var _a;
|
|
238
|
-
|
|
239
|
-
child.dataset.index = index;
|
|
240
|
-
} else {
|
|
241
|
-
child.dataset.index = index;
|
|
242
|
-
}
|
|
243
|
-
index++;
|
|
106
|
+
(_a = t3.children[0]) == null ? void 0 : _a.hasAttribute("locked"), t3.dataset.index = s2, s2++;
|
|
244
107
|
});
|
|
245
108
|
}
|
|
246
109
|
}
|
|
247
|
-
|
|
110
|
+
s.define("wje-reorder-handle", s);
|
|
248
111
|
export {
|
|
249
|
-
|
|
112
|
+
s as default
|
|
250
113
|
};
|
|
251
114
|
//# sourceMappingURL=wje-reorder-handle.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wje-reorder-handle.js","sources":["../packages/wje-reorder-handle/reorder-handle.element.js","../packages/wje-reorder-handle/reorder-handle.js"],"sourcesContent":["import { default as WJElement, event } from '../wje-element/element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * `ReorderHandle` is a custom web component that represents a reorder handle.\n * @summary This element represents a reorder handle.\n * @documentation https://elements.webjet.sk/components/reorder-handle\n * @status stable\n * @augments WJElement\n * @csspart native - The native part of the reorder handle.\n * @slot - The default slot for the reorder handle.\n * @tag wje-reorder-handle\n */\nexport default class ReorderHandle extends WJElement {\n /**\n * Creates an instance of ReorderHandle.\n */\n constructor() {\n super();\n this.addEventListener('mousedown', this.startDrag.bind(this));\n this.addEventListener('touchstart', this.startTouchDrag.bind(this));\n }\n\n /**\n * The class name for the component.\n * @type {string}\n */\n className = 'ReorderHandle';\n\n /**\n * Returns the CSS styles for the component.\n * @returns {*}\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Returns the list of attributes to observe for changes.\n * @returns {string[]}\n */\n static get observedAttributes() {\n return ['dropzone', 'parent'];\n }\n\n setupAttributes() {\n this.isShadowRoot = 'open';\n this.syncAria();\n }\n\n /**\n * Draws the component.\n * @returns {DocumentFragment}\n */\n draw() {\n const fragment = document.createDocumentFragment();\n\n const container = document.createElement('div');\n container.classList.add('container');\n container.setAttribute('part', 'native');\n\n const slot = document.createElement('slot');\n\n container.appendChild(slot);\n\n fragment.appendChild(container);\n\n return fragment;\n }\n\n /**\n * Draws the component after it is connected to the DOM.\n */\n afterDraw() {\n this.syncAria();\n if (this.hasAttribute('disabled')) {\n this.style.opacity = '.3';\n }\n }\n\n /**\n * Sync ARIA attributes on host.\n */\n syncAria() {\n if (!this.hasAttribute('role')) {\n this.setAriaState({ role: 'button' });\n }\n\n if (!this.hasAttribute('tabindex')) {\n this.setAttribute('tabindex', '0');\n }\n\n if (this.hasAttribute('disabled')) {\n this.setAriaState({ disabled: true });\n }\n\n const ariaLabel = this.getAttribute('aria-label');\n const label = this.getAttribute('label') || 'Reorder item';\n if (!ariaLabel && label) {\n this.setAriaState({ label });\n }\n }\n\n /**\n * Handles the attribute changes.\n * @param {DragEvent} e\n */\n startDrag(e) {\n if (this.hasAttribute('disabled') || this.hasAttribute('locked')) return;\n this.startDragAction(e.clientX, e.clientY);\n event.dispatchCustomEvent(this, 'wje-reorder-handle:start', {draggable: this.getDraggable()});\n }\n\n /**\n * Handles the touch start event.\n * @param {TouchEvent} e\n */\n startTouchDrag(e) {\n if (this.hasAttribute('disabled') || this.hasAttribute('locked')) return;\n const touch = e.touches[0];\n this.startDragAction(touch.clientX, touch.clientY);\n }\n\n /**\n * Initiates the drag-and-drop action for a sortable element.\n * @param {number} clientX The x-coordinate of the mouse pointer at the start of the drag action.\n * @param {number} clientY The y-coordinate of the mouse pointer at the start of the drag action.\n */\n startDragAction(clientX, clientY) {\n let draggable = this.getDraggable();\n\n const initialContainer = this.getDropzone(draggable);\n\n if (!this.getAttribute('dropzone')) {\n this.setAttribute('dropzone', initialContainer.localName);\n }\n\n const rect = draggable.getBoundingClientRect();\n const offsetX = clientX - rect.left;\n const offsetY = clientY - rect.top;\n\n let placeholder = document.createElement('div');\n placeholder.classList.add('sortable-item');\n placeholder.style.visibility = 'hidden';\n placeholder.style.height = `${rect.height}px`;\n\n draggable.classList.add('dragging');\n\n draggable.style.position = 'fixed';\n draggable.style.zIndex = '1000';\n draggable.style.width = `${rect.width}px`;\n\n const moveAt = (pageX, pageY) => {\n draggable.style.left = `${pageX - offsetX - document.documentElement.scrollLeft}px`;\n draggable.style.top = `${pageY - offsetY - document.documentElement.scrollTop}px`;\n };\n\n moveAt(clientX, clientY);\n\n const onMouseMove = (e) => {\n moveAt(e.pageX, e.pageY);\n\n const dropzone = this.getClosestDropzone(e.clientX, e.clientY);\n if (!dropzone) return;\n\n const siblings = Array.from(dropzone.children).filter(\n (child) => child !== draggable && child !== placeholder\n );\n\n for (const sibling of siblings) {\n const siblingRect = sibling.getBoundingClientRect();\n\n if (sibling.children[0]?.hasAttribute('locked')) continue;\n\n if (e.clientY > siblingRect.top && e.clientY < siblingRect.bottom) {\n if (e.clientY < siblingRect.top + siblingRect.height / 2) {\n dropzone.insertBefore(placeholder, sibling);\n } else {\n dropzone.insertBefore(placeholder, sibling.nextSibling);\n }\n break;\n }\n }\n }\n\n const onMouseUp = () => {\n document.removeEventListener('mousemove', onMouseMove);\n document.removeEventListener('mouseup', onMouseUp);\n\n draggable.classList.remove('dragging');\n\n draggable.style.position = '';\n draggable.style.zIndex = '';\n draggable.style.left = '';\n draggable.style.top = '';\n draggable.style.width = '';\n\n const finalContainer = placeholder.parentElement;\n finalContainer.insertBefore(draggable, placeholder);\n finalContainer.removeChild(placeholder);\n\n this.reIndexItems(finalContainer);\n\n event.dispatchCustomEvent(this, 'wje-reorder-handle:change', {finalContainer: finalContainer, draggable: draggable});\n };\n\n document.addEventListener('mousemove', onMouseMove);\n document.addEventListener('mouseup', onMouseUp);\n\n initialContainer.insertBefore(placeholder, draggable);\n }\n\n /**\n * Retrieves the closest draggable element based on attribute conditions.\n * If the element has a \"parent\" attribute, the method attempts to find the closest ancestor\n * matching the CSS selector specified in the attribute. If no such ancestor exists,\n * the method defaults to returning the immediate parent element.\n * @returns {Element|null} The closest matching ancestor or the immediate parent element if no match is found, or null if the element has no parent.\n */\n getDraggable() {\n if (this.hasAttribute('parent')) {\n let parent = this.closest(this.getAttribute('parent'));\n if(parent) return parent;\n }\n return this.parentElement;\n }\n\n /**\n * Retrieves the nearest dropzone element based on the element's attributes or its parent element.\n * @param {HTMLElement} element The HTML element for which the dropzone is being determined.\n * @returns {HTMLElement|null} The nearest dropzone element if found; otherwise, the parent element or null.\n */\n getDropzone(element) {\n const dropzoneAttr = this.getAttribute('dropzone');\n if (this.hasAttribute('dropzone')) {\n let dropzone = element.closest(this.getAttribute('dropzone'));\n if (dropzone) return dropzone;\n }\n return element.parentElement;\n }\n\n /**\n * Retrieves the closest dropzone element at the specified coordinates.\n * @param {number} clientX The x-coordinate relative to the viewport.\n * @param {number} clientY The y-coordinate relative to the viewport.\n * @returns {HTMLElement|null} - The closest dropzone element matching the `dropzone` attribute, or `null` if none is found.\n */\n getClosestDropzone(clientX, clientY) {\n const elements = this.getElementsFromPointAll(clientX, clientY);\n for (const element of elements) {\n if (element.matches(this.getAttribute('dropzone'))) {\n return element;\n }\n }\n return null;\n }\n\n /**\n * Retrieves all elements at the specified coordinates, including those within shadow DOMs.\n * @param {number} x The x-coordinate relative to the viewport.\n * @param {number} y The y-coordinate relative to the viewport.\n * @param {Document|ShadowRoot} [root] The root context in which to search. Defaults to the main document.\n * @param {Set<Node>} [visited] A set of already visited nodes to avoid infinite recursion in nested shadow DOMs.\n * @returns {HTMLElement[]} An array of all elements found at the specified coordinates, including shadow DOM elements.\n */\n getElementsFromPointAll(x, y, root = document, visited = new Set()) {\n if (visited.has(root)) return [];\n visited.add(root);\n\n const elements = root.elementsFromPoint(x, y);\n let allElements = [...elements];\n\n for (const element of elements) {\n if (element.shadowRoot && !visited.has(element.shadowRoot)) {\n allElements = allElements.concat(this.getElementsFromPointAll(x, y, element.shadowRoot, visited));\n }\n }\n\n return allElements;\n }\n\n /**\n * Re-indexes child elements of the given container by setting their dataset index.\n * @param {HTMLElement} container The container element whose children are to be re-indexed.\n * @returns {void}\n */\n reIndexItems(container) {\n const items = Array.from(container.children);\n let index = 0;\n\n items.forEach((child) => {\n if (child.children[0]?.hasAttribute('locked')) {\n child.dataset.index = index;\n } else {\n child.dataset.index = index;\n }\n index++;\n });\n }\n}\n","import ReorderHandle from './reorder-handle.element.js';\n\nexport default ReorderHandle;\n\nReorderHandle.define('wje-reorder-handle', ReorderHandle);\n"],"names":[],"mappings":";;;;;;AAae,MAAM,sBAAsB,UAAU;AAAA;AAAA;AAAA;AAAA,EAIjD,cAAc;AACV,UAAK;AAST;AAAA;AAAA;AAAA;AAAA,qCAAY;AARR,SAAK,iBAAiB,aAAa,KAAK,UAAU,KAAK,IAAI,CAAC;AAC5D,SAAK,iBAAiB,cAAc,KAAK,eAAe,KAAK,IAAI,CAAC;AAAA,EACtE;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,WAAW,gBAAgB;AACvB,WAAO;AAAA,EACX;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,WAAW,qBAAqB;AAC5B,WAAO,CAAC,YAAY,QAAQ;AAAA,EAChC;AAAA,EAEA,kBAAkB;AACd,SAAK,eAAe;AACpB,SAAK,SAAQ;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO;AACH,UAAM,WAAW,SAAS,uBAAsB;AAEhD,UAAM,YAAY,SAAS,cAAc,KAAK;AAC9C,cAAU,UAAU,IAAI,WAAW;AACnC,cAAU,aAAa,QAAQ,QAAQ;AAEvC,UAAM,OAAO,SAAS,cAAc,MAAM;AAE1C,cAAU,YAAY,IAAI;AAE1B,aAAS,YAAY,SAAS;AAE9B,WAAO;AAAA,EACX;AAAA;AAAA;AAAA;AAAA,EAKA,YAAY;AACR,SAAK,SAAQ;AACb,QAAI,KAAK,aAAa,UAAU,GAAG;AAC/B,WAAK,MAAM,UAAU;AAAA,IACzB;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA,EAKA,WAAW;AACP,QAAI,CAAC,KAAK,aAAa,MAAM,GAAG;AAC5B,WAAK,aAAa,EAAE,MAAM,SAAQ,CAAE;AAAA,IACxC;AAEA,QAAI,CAAC,KAAK,aAAa,UAAU,GAAG;AAChC,WAAK,aAAa,YAAY,GAAG;AAAA,I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QAAQ,cAAc,CAAC,QAAQ,IAAI,QAAQ,UAAU,GAAG;AACxD,sBAAc,YAAY,OAAO,KAAK,wBAAwB,GAAG,GAAG,QAAQ,YAAY,OAAO,CAAC;AAAA,MACpG;AAAA,IACJ;AAEA,WAAO;AAAA,EACX;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,aAAa,WAAW;AACpB,UAAM,QAAQ,MAAM,KAAK,UAAU,QAAQ;AAC3C,QAAI,QAAQ;AAEZ,UAAM,QAAQ,CAAC,UAAU;;AACrB,WAAI,WAAM,SAAS,CAAC,MAAhB,mBAAmB,aAAa,WAAW;AAC3C,cAAM,QAAQ,QAAQ;AAAA,MAC1B,OAAO;AACH,cAAM,QAAQ,QAAQ;AAAA,MAC1B;AACA;AAAA,IACJ,CAAC;AAAA,EACL;AACJ;ACvSA,cAAc,OAAO,sBAAsB,aAAa;"}
|
|
1
|
+
{"version":3,"file":"wje-reorder-handle.js","sources":["../packages/wje-reorder-handle/reorder-handle.element.js","../packages/wje-reorder-handle/reorder-handle.js"],"sourcesContent":["import { default as WJElement, event } from '../wje-element/element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * `ReorderHandle` is a custom web component that represents a reorder handle.\n * @summary This element represents a reorder handle.\n * @documentation https://elements.webjet.sk/components/reorder-handle\n * @status stable\n * @augments WJElement\n * @csspart native - The native part of the reorder handle.\n * @slot - The default slot for the reorder handle.\n * @tag wje-reorder-handle\n */\nexport default class ReorderHandle extends WJElement {\n /**\n * Creates an instance of ReorderHandle.\n */\n constructor() {\n super();\n this.addEventListener('mousedown', this.startDrag.bind(this));\n this.addEventListener('touchstart', this.startTouchDrag.bind(this));\n }\n\n /**\n * The class name for the component.\n * @type {string}\n */\n className = 'ReorderHandle';\n\n /**\n * Returns the CSS styles for the component.\n * @returns {*}\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Returns the list of attributes to observe for changes.\n * @returns {string[]}\n */\n static get observedAttributes() {\n return ['dropzone', 'parent'];\n }\n\n setupAttributes() {\n this.isShadowRoot = 'open';\n this.syncAria();\n }\n\n /**\n * Draws the component.\n * @returns {DocumentFragment}\n */\n draw() {\n const fragment = document.createDocumentFragment();\n\n const container = document.createElement('div');\n container.classList.add('container');\n container.setAttribute('part', 'native');\n\n const slot = document.createElement('slot');\n\n container.appendChild(slot);\n\n fragment.appendChild(container);\n\n return fragment;\n }\n\n /**\n * Draws the component after it is connected to the DOM.\n */\n afterDraw() {\n this.syncAria();\n if (this.hasAttribute('disabled')) {\n this.style.opacity = '.3';\n }\n }\n\n /**\n * Sync ARIA attributes on host.\n */\n syncAria() {\n if (!this.hasAttribute('role')) {\n this.setAriaState({ role: 'button' });\n }\n\n if (!this.hasAttribute('tabindex')) {\n this.setAttribute('tabindex', '0');\n }\n\n if (this.hasAttribute('disabled')) {\n this.setAriaState({ disabled: true });\n }\n\n const ariaLabel = this.getAttribute('aria-label');\n const label = this.getAttribute('label') || 'Reorder item';\n if (!ariaLabel && label) {\n this.setAriaState({ label });\n }\n }\n\n /**\n * Handles the attribute changes.\n * @param {DragEvent} e\n */\n startDrag(e) {\n if (this.hasAttribute('disabled') || this.hasAttribute('locked')) return;\n this.startDragAction(e.clientX, e.clientY);\n event.dispatchCustomEvent(this, 'wje-reorder-handle:start', {draggable: this.getDraggable()});\n }\n\n /**\n * Handles the touch start event.\n * @param {TouchEvent} e\n */\n startTouchDrag(e) {\n if (this.hasAttribute('disabled') || this.hasAttribute('locked')) return;\n const touch = e.touches[0];\n this.startDragAction(touch.clientX, touch.clientY);\n }\n\n /**\n * Initiates the drag-and-drop action for a sortable element.\n * @param {number} clientX The x-coordinate of the mouse pointer at the start of the drag action.\n * @param {number} clientY The y-coordinate of the mouse pointer at the start of the drag action.\n */\n startDragAction(clientX, clientY) {\n let draggable = this.getDraggable();\n\n const initialContainer = this.getDropzone(draggable);\n\n if (!this.getAttribute('dropzone')) {\n this.setAttribute('dropzone', initialContainer.localName);\n }\n\n const rect = draggable.getBoundingClientRect();\n const offsetX = clientX - rect.left;\n const offsetY = clientY - rect.top;\n\n let placeholder = document.createElement('div');\n placeholder.classList.add('sortable-item');\n placeholder.style.visibility = 'hidden';\n placeholder.style.height = `${rect.height}px`;\n\n draggable.classList.add('dragging');\n\n draggable.style.position = 'fixed';\n draggable.style.zIndex = '1000';\n draggable.style.width = `${rect.width}px`;\n\n const moveAt = (pageX, pageY) => {\n draggable.style.left = `${pageX - offsetX - document.documentElement.scrollLeft}px`;\n draggable.style.top = `${pageY - offsetY - document.documentElement.scrollTop}px`;\n };\n\n moveAt(clientX, clientY);\n\n const onMouseMove = (e) => {\n moveAt(e.pageX, e.pageY);\n\n const dropzone = this.getClosestDropzone(e.clientX, e.clientY);\n if (!dropzone) return;\n\n const siblings = Array.from(dropzone.children).filter(\n (child) => child !== draggable && child !== placeholder\n );\n\n for (const sibling of siblings) {\n const siblingRect = sibling.getBoundingClientRect();\n\n if (sibling.children[0]?.hasAttribute('locked')) continue;\n\n if (e.clientY > siblingRect.top && e.clientY < siblingRect.bottom) {\n if (e.clientY < siblingRect.top + siblingRect.height / 2) {\n dropzone.insertBefore(placeholder, sibling);\n } else {\n dropzone.insertBefore(placeholder, sibling.nextSibling);\n }\n break;\n }\n }\n }\n\n const onMouseUp = () => {\n document.removeEventListener('mousemove', onMouseMove);\n document.removeEventListener('mouseup', onMouseUp);\n\n draggable.classList.remove('dragging');\n\n draggable.style.position = '';\n draggable.style.zIndex = '';\n draggable.style.left = '';\n draggable.style.top = '';\n draggable.style.width = '';\n\n const finalContainer = placeholder.parentElement;\n finalContainer.insertBefore(draggable, placeholder);\n finalContainer.removeChild(placeholder);\n\n this.reIndexItems(finalContainer);\n\n event.dispatchCustomEvent(this, 'wje-reorder-handle:change', {finalContainer: finalContainer, draggable: draggable});\n };\n\n document.addEventListener('mousemove', onMouseMove);\n document.addEventListener('mouseup', onMouseUp);\n\n initialContainer.insertBefore(placeholder, draggable);\n }\n\n /**\n * Retrieves the closest draggable element based on attribute conditions.\n * If the element has a \"parent\" attribute, the method attempts to find the closest ancestor\n * matching the CSS selector specified in the attribute. If no such ancestor exists,\n * the method defaults to returning the immediate parent element.\n * @returns {Element|null} The closest matching ancestor or the immediate parent element if no match is found, or null if the element has no parent.\n */\n getDraggable() {\n if (this.hasAttribute('parent')) {\n let parent = this.closest(this.getAttribute('parent'));\n if(parent) return parent;\n }\n return this.parentElement;\n }\n\n /**\n * Retrieves the nearest dropzone element based on the element's attributes or its parent element.\n * @param {HTMLElement} element The HTML element for which the dropzone is being determined.\n * @returns {HTMLElement|null} The nearest dropzone element if found; otherwise, the parent element or null.\n */\n getDropzone(element) {\n const dropzoneAttr = this.getAttribute('dropzone');\n if (this.hasAttribute('dropzone')) {\n let dropzone = element.closest(this.getAttribute('dropzone'));\n if (dropzone) return dropzone;\n }\n return element.parentElement;\n }\n\n /**\n * Retrieves the closest dropzone element at the specified coordinates.\n * @param {number} clientX The x-coordinate relative to the viewport.\n * @param {number} clientY The y-coordinate relative to the viewport.\n * @returns {HTMLElement|null} - The closest dropzone element matching the `dropzone` attribute, or `null` if none is found.\n */\n getClosestDropzone(clientX, clientY) {\n const elements = this.getElementsFromPointAll(clientX, clientY);\n for (const element of elements) {\n if (element.matches(this.getAttribute('dropzone'))) {\n return element;\n }\n }\n return null;\n }\n\n /**\n * Retrieves all elements at the specified coordinates, including those within shadow DOMs.\n * @param {number} x The x-coordinate relative to the viewport.\n * @param {number} y The y-coordinate relative to the viewport.\n * @param {Document|ShadowRoot} [root] The root context in which to search. Defaults to the main document.\n * @param {Set<Node>} [visited] A set of already visited nodes to avoid infinite recursion in nested shadow DOMs.\n * @returns {HTMLElement[]} An array of all elements found at the specified coordinates, including shadow DOM elements.\n */\n getElementsFromPointAll(x, y, root = document, visited = new Set()) {\n if (visited.has(root)) return [];\n visited.add(root);\n\n const elements = root.elementsFromPoint(x, y);\n let allElements = [...elements];\n\n for (const element of elements) {\n if (element.shadowRoot && !visited.has(element.shadowRoot)) {\n allElements = allElements.concat(this.getElementsFromPointAll(x, y, element.shadowRoot, visited));\n }\n }\n\n return allElements;\n }\n\n /**\n * Re-indexes child elements of the given container by setting their dataset index.\n * @param {HTMLElement} container The container element whose children are to be re-indexed.\n * @returns {void}\n */\n reIndexItems(container) {\n const items = Array.from(container.children);\n let index = 0;\n\n items.forEach((child) => {\n if (child.children[0]?.hasAttribute('locked')) {\n child.dataset.index = index;\n } else {\n child.dataset.index = index;\n }\n index++;\n });\n }\n}\n","import ReorderHandle from './reorder-handle.element.js';\n\nexport default ReorderHandle;\n\nReorderHandle.define('wje-reorder-handle', ReorderHandle);\n"],"names":["ReorderHandle","WJElement","constructor","super","className","this","addEventListener","startDrag","bind","startTouchDrag","cssStyleSheet","observedAttributes","setupAttributes","isShadowRoot","syncAria","draw","fragment","document","createDocumentFragment","container","createElement","classList","add","setAttribute","slot","appendChild","afterDraw","hasAttribute","style","opacity","setAriaState","role","disabled","ariaLabel","getAttribute","label","e","startDragAction","clientX","clientY","event","dispatchCustomEvent","draggable","getDraggable","touch","touches","initialContainer","getDropzone","localName","rect","getBoundingClientRect","offsetX","left","offsetY","top","placeholder","visibility","height","position","zIndex","width","moveAt","pageX","pageY","documentElement","scrollLeft","scrollTop","onMouseMove","dropzone","getClosestDropzone","siblings","Array","from","children","filter","child","sibling","siblingRect","bottom","insertBefore","nextSibling","onMouseUp","removeEventListener","remove","finalContainer","parentElement","removeChild","reIndexItems","parent","closest","element","elements","getElementsFromPointAll","matches","x","y","root","visited","Set","has","elementsFromPoint","allElements","shadowRoot","concat","items","index","forEach","dataset","define"],"mappings":";;;;;AAae,MAAMA,UAAsBC,EAAAA;AAAAA,EAIvC,cAAAC;AACIC,UAAAA;AASJC,qCAAY;AARRC,SAAKC,iBAAiB,aAAaD,KAAKE,UAAUC,KAAKH,IAAAA,CAAAA,GACvDA,KAAKC,iBAAiB,cAAcD,KAAKI,eAAeD,KAAKH;EACjE;AAAA,EAYA,WAAA,gBAAWK;AACP;EACJ;AAAA,EAMA,gCAAWC;AACP,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item.js
CHANGED
|
@@ -1,62 +1,32 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
import
|
|
5
|
-
import { WjElementUtils } from "./element-utils.js";
|
|
6
|
-
|
|
7
|
-
class ReorderItem extends WJElement {
|
|
8
|
-
/**
|
|
9
|
-
* Creates an instance of ReorderItem.
|
|
10
|
-
*/
|
|
4
|
+
import e from "./wje-element.js";
|
|
5
|
+
import { WjElementUtils as t } from "./element-utils.js";
|
|
6
|
+
class r extends e {
|
|
11
7
|
constructor() {
|
|
12
8
|
super();
|
|
13
|
-
/**
|
|
14
|
-
* The class name for the component.
|
|
15
|
-
* @type {string}
|
|
16
|
-
*/
|
|
17
9
|
__publicField(this, "className", "ReorderItem");
|
|
18
10
|
}
|
|
19
|
-
/**
|
|
20
|
-
* Returns the CSS stylesheet for the component.
|
|
21
|
-
* @returns {CSSStyleSheet} The CSS stylesheet.
|
|
22
|
-
*/
|
|
23
11
|
static get cssStyleSheet() {
|
|
24
|
-
return
|
|
12
|
+
return ":host{--reorder-item-spacing: .5rem}.item{width:134px;height:19px;display:flex;align-items:center;justify-content:left;position:relative;gap:var(--reorder-item-spacing);padding:var(--reorder-item-spacing);border-radius:var(--wje-border-radius-small);background-color:var(--reorder-background-color);cursor:grab;transition:top .3s ease,left .3s ease}.item-w-handle{cursor:default}.item-w-handle:active{opacity:.3}.item:active:not(.item-w-handle):not(.moving){background-color:var(--reorder-background-color);cursor:grabbing}.moving{background-color:#d3d3d3}.handle{cursor:grab;gap:10px}.handle:active{cursor:grabbing}.name{width:108px;height:19px;text-align:center;font-size:var(--wje-font-size);font-weight:400;line-height:19.36px;gap:10px}.item{transform:var(--item-transform)}";
|
|
25
13
|
}
|
|
26
|
-
/**
|
|
27
|
-
* Sets up the attributes for the component.
|
|
28
|
-
*/
|
|
29
14
|
setupAttributes() {
|
|
30
15
|
this.isShadowRoot = "open";
|
|
31
16
|
}
|
|
32
|
-
/**
|
|
33
|
-
* Returns the list of observed attributes.
|
|
34
|
-
* @returns {DocumentFragment}
|
|
35
|
-
*/
|
|
36
17
|
draw() {
|
|
37
|
-
let
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
handle.classList.add("handle");
|
|
46
|
-
handle.setAttribute("name", "handle");
|
|
47
|
-
handle.setAttribute("part", "handle-part");
|
|
48
|
-
wrapper.classList.add("item-w-handle");
|
|
49
|
-
wrapper.appendChild(handle);
|
|
50
|
-
} else {
|
|
51
|
-
element.setAttribute("draggable", "true");
|
|
52
|
-
}
|
|
53
|
-
wrapper.appendChild(element);
|
|
54
|
-
fragment.appendChild(wrapper);
|
|
55
|
-
return fragment;
|
|
18
|
+
let e2 = document.createDocumentFragment(), r2 = document.createElement("div");
|
|
19
|
+
r2.classList.add("item"), r2.setAttribute("part", "native-reorder-item");
|
|
20
|
+
let a = document.createElement("slot");
|
|
21
|
+
if (a.classList.add("name"), t.hasSlot(this, "handle")) {
|
|
22
|
+
const e3 = document.createElement("slot");
|
|
23
|
+
e3.classList.add("handle"), e3.setAttribute("name", "handle"), e3.setAttribute("part", "handle-part"), r2.classList.add("item-w-handle"), r2.appendChild(e3);
|
|
24
|
+
} else a.setAttribute("draggable", "true");
|
|
25
|
+
return r2.appendChild(a), e2.appendChild(r2), e2;
|
|
56
26
|
}
|
|
57
27
|
}
|
|
58
|
-
|
|
28
|
+
r.define("wje-reorder-item", r);
|
|
59
29
|
export {
|
|
60
|
-
|
|
30
|
+
r as default
|
|
61
31
|
};
|
|
62
32
|
//# sourceMappingURL=wje-reorder-item.js.map
|