@tillsc/progressive-web-components 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -2
- package/dist/all-bs5.js +212 -0
- package/dist/all.js +212 -0
- package/dist/zone-transfer.js +315 -0
- package/package.json +3 -2
- package/src/dialog-opener/index.html +24 -0
- package/src/dialog-opener/test/basic.html +1 -1
- package/src/dialog-opener/test/bs5-basic.html +1 -1
- package/src/index-bs5.js +3 -1
- package/src/index.js +1 -0
- package/src/modal-dialog/index.html +24 -0
- package/src/modal-dialog/test/basic.html +1 -1
- package/src/modal-dialog/test/bs5-basic.html +1 -1
- package/src/multiselect-dual-list/index.html +26 -0
- package/src/multiselect-dual-list/test/basic.html +1 -1
- package/src/multiselect-dual-list/test/bs5-basic.html +1 -1
- package/src/multiselect-dual-list/test/dynamic-options.html +1 -1
- package/src/multiselect-dual-list/test/filter-api.html +1 -1
- package/src/zone-transfer/INTERNALS.md +80 -0
- package/src/zone-transfer/README.md +166 -0
- package/src/zone-transfer/index.html +24 -0
- package/src/zone-transfer/index.js +9 -0
- package/src/zone-transfer/test/basic.html +78 -0
- package/src/zone-transfer/test/keyboard.html +111 -0
- package/src/zone-transfer/zone-transfer.css +12 -0
- package/src/zone-transfer/zone-transfer.js +292 -0
- package/src/dialog-opener/test/index.html +0 -19
- package/src/modal-dialog/test/index.html +0 -19
- package/src/multiselect-dual-list/test/index.html +0 -21
package/README.md
CHANGED
|
@@ -17,8 +17,9 @@ A collection of Custom Elements designed to work with server-rendered HTML and p
|
|
|
17
17
|
|
|
18
18
|
| Component | Description |
|
|
19
19
|
|-----------|-------------|
|
|
20
|
-
| [`<pwc-dialog-opener>`](src/dialog-opener/
|
|
21
|
-
| [`<pwc-modal-dialog>`](src/modal-dialog/
|
|
20
|
+
| [`<pwc-dialog-opener>`](src/dialog-opener/) | Enhances links to open their targets in a modal dialog |
|
|
21
|
+
| [`<pwc-modal-dialog>`](src/modal-dialog/) | Low-level building block for modal dialogs from JavaScript |
|
|
22
|
+
| [`<pwc-multiselect-dual-list>`](src/multiselect-dual-list/) | Dual-list multiselect UI that enhances a native `<select>` element |
|
|
22
23
|
|
|
23
24
|
Each component ships a **vanilla** variant and a **Bootstrap 5** variant.
|
|
24
25
|
|
|
@@ -28,3 +29,5 @@ Each component ships a **vanilla** variant and a **Bootstrap 5** variant.
|
|
|
28
29
|
|
|
29
30
|
- `dialog-opener.js` / `dialog-opener-bs5.js`
|
|
30
31
|
- `modal-dialog.js` / `modal-dialog-bs5.js`
|
|
32
|
+
- `multiselect-dual-list.js` / `multiselect-dual-list-bs5.js`
|
|
33
|
+
- `all.js` / `all-bs5.js` (all components bundled)
|
package/dist/all-bs5.js
CHANGED
|
@@ -781,3 +781,215 @@ function register3() {
|
|
|
781
781
|
define3();
|
|
782
782
|
}
|
|
783
783
|
register3();
|
|
784
|
+
|
|
785
|
+
// src/zone-transfer/zone-transfer.js
|
|
786
|
+
var PwcZoneTransfer = class extends PwcChildrenObserverElement {
|
|
787
|
+
static events = ["dragstart", "dragover", "drop", "dragend", "keydown"];
|
|
788
|
+
static observeMode = "tree";
|
|
789
|
+
static zoneSelector = "pwc-zone-transfer-zone, [data-pwc-zone]";
|
|
790
|
+
static itemSelector = "pwc-zone-transfer-item, [data-pwc-item]";
|
|
791
|
+
static handleSelector = "pwc-zone-transfer-handle, [data-pwc-handle]";
|
|
792
|
+
onChildrenChanged() {
|
|
793
|
+
const items = this._items();
|
|
794
|
+
for (const item of items) {
|
|
795
|
+
if (!item.hasAttribute("draggable")) item.setAttribute("draggable", "true");
|
|
796
|
+
if (!item.hasAttribute("tabindex")) item.tabIndex = -1;
|
|
797
|
+
if (!item.hasAttribute("role")) item.setAttribute("role", "option");
|
|
798
|
+
}
|
|
799
|
+
for (const zone of this._zones()) {
|
|
800
|
+
if (!zone.hasAttribute("role")) zone.setAttribute("role", "listbox");
|
|
801
|
+
if (!zone.hasAttribute("tabindex")) zone.tabIndex = -1;
|
|
802
|
+
}
|
|
803
|
+
const active = items.find((it) => it.tabIndex === 0) || items[0] || null;
|
|
804
|
+
for (const it of items) it.tabIndex = it === active ? 0 : -1;
|
|
805
|
+
}
|
|
806
|
+
handleEvent(e) {
|
|
807
|
+
if (e.type === "dragstart") return this._onDragStart(e);
|
|
808
|
+
if (e.type === "dragover") return this._onDragOver(e);
|
|
809
|
+
if (e.type === "drop") return this._onDrop(e);
|
|
810
|
+
if (e.type === "dragend") return this._onDragEnd();
|
|
811
|
+
if (e.type === "keydown") return this._onKeyDown(e);
|
|
812
|
+
}
|
|
813
|
+
_zones() {
|
|
814
|
+
return Array.from(this.querySelectorAll(this.constructor.zoneSelector));
|
|
815
|
+
}
|
|
816
|
+
_items(zoneEl) {
|
|
817
|
+
return Array.from((zoneEl || this).querySelectorAll(this.constructor.itemSelector));
|
|
818
|
+
}
|
|
819
|
+
_onDragStart(e) {
|
|
820
|
+
const item = this._closestItem(e.target);
|
|
821
|
+
if (!item) return;
|
|
822
|
+
if (item.querySelector(this.constructor.handleSelector) && !this._closestHandle(e.target)) {
|
|
823
|
+
e.preventDefault();
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
const zone = this._closestZone(item);
|
|
827
|
+
if (!zone) return;
|
|
828
|
+
this._drag = { item, fromZone: zone };
|
|
829
|
+
if (e.dataTransfer) e.dataTransfer.effectAllowed = "move";
|
|
830
|
+
item.classList.add("pwc-zone-transfer-dragging");
|
|
831
|
+
this._ensurePlaceholder(item);
|
|
832
|
+
}
|
|
833
|
+
_onDragOver(e) {
|
|
834
|
+
if (!this._drag?.item) return;
|
|
835
|
+
const zone = this._closestZone(e.target);
|
|
836
|
+
if (!zone) return;
|
|
837
|
+
e.preventDefault();
|
|
838
|
+
if (e.dataTransfer) e.dataTransfer.dropEffect = "move";
|
|
839
|
+
this._ensurePlaceholder(this._drag.item);
|
|
840
|
+
const beforeEl = this._beforeFromPointer(zone, e, this._drag.item);
|
|
841
|
+
this._movePlaceholder(zone, beforeEl);
|
|
842
|
+
this._drag.overZone = zone;
|
|
843
|
+
this._drag.overMethod = beforeEl ? "before" : "append";
|
|
844
|
+
}
|
|
845
|
+
_onDrop(e) {
|
|
846
|
+
if (!this._drag?.item) return;
|
|
847
|
+
const zone = this._closestZone(e.target);
|
|
848
|
+
if (!zone) return;
|
|
849
|
+
e.preventDefault();
|
|
850
|
+
this._applyMove(this._drag.item, this._drag.fromZone, zone, this._drag.overMethod || "append");
|
|
851
|
+
this._clearPlaceholder();
|
|
852
|
+
}
|
|
853
|
+
_onDragEnd() {
|
|
854
|
+
if (this._drag?.item) this._drag.item.classList.remove("pwc-zone-transfer-dragging");
|
|
855
|
+
this._drag = null;
|
|
856
|
+
this._clearPlaceholder();
|
|
857
|
+
}
|
|
858
|
+
_onKeyDown(e) {
|
|
859
|
+
if (e.target?.closest?.("input,textarea,select,button,[contenteditable]")) return;
|
|
860
|
+
const item = this._closestItem(e.target);
|
|
861
|
+
if (!item) return;
|
|
862
|
+
if (e.key === "ArrowUp" || e.key === "ArrowDown") {
|
|
863
|
+
e.preventDefault();
|
|
864
|
+
const dir = e.key === "ArrowDown" ? 1 : -1;
|
|
865
|
+
if (e.ctrlKey || e.metaKey) this._keyboardReorder(item, dir);
|
|
866
|
+
else this._focusSibling(item, dir);
|
|
867
|
+
return;
|
|
868
|
+
}
|
|
869
|
+
const zone = this._zoneByHotkey(e.key);
|
|
870
|
+
if (!zone) return;
|
|
871
|
+
e.preventDefault();
|
|
872
|
+
this._keyboardMoveToZone(item, zone);
|
|
873
|
+
}
|
|
874
|
+
_keyboardReorder(item, dir) {
|
|
875
|
+
const zone = this._closestZone(item);
|
|
876
|
+
if (!zone) return;
|
|
877
|
+
const items = this._items(zone);
|
|
878
|
+
const i = items.indexOf(item);
|
|
879
|
+
if (i < 0) return;
|
|
880
|
+
const j = i + dir;
|
|
881
|
+
if (j < 0 || j >= items.length) return;
|
|
882
|
+
zone.insertBefore(item, dir > 0 ? items[j].nextElementSibling : items[j]);
|
|
883
|
+
for (const it of this._items()) it.tabIndex = it === item ? 0 : -1;
|
|
884
|
+
item.focus();
|
|
885
|
+
this._emitChange(item, zone, zone, this._indexInZone(item, zone), "before");
|
|
886
|
+
}
|
|
887
|
+
_keyboardMoveToZone(item, zone) {
|
|
888
|
+
const fromZone = this._closestZone(item);
|
|
889
|
+
if (!fromZone || fromZone === zone) return;
|
|
890
|
+
zone.appendChild(item);
|
|
891
|
+
for (const it of this._items()) it.tabIndex = it === item ? 0 : -1;
|
|
892
|
+
item.focus();
|
|
893
|
+
this._emitChange(item, fromZone, zone, this._indexInZone(item, zone), "append");
|
|
894
|
+
}
|
|
895
|
+
_zoneByHotkey(key) {
|
|
896
|
+
const zones = this._zones();
|
|
897
|
+
if (!zones.some((z) => z.hasAttribute("data-pwc-zone-key"))) return null;
|
|
898
|
+
return zones.find((z) => z.getAttribute("data-pwc-zone-key") === key) || null;
|
|
899
|
+
}
|
|
900
|
+
_emitChange(item, fromZone, toZone, index, method) {
|
|
901
|
+
this.dispatchEvent(
|
|
902
|
+
new CustomEvent("pwc-zone-transfer:change", {
|
|
903
|
+
bubbles: true,
|
|
904
|
+
detail: {
|
|
905
|
+
itemId: this._itemId(item),
|
|
906
|
+
fromZone: this._zoneName(fromZone),
|
|
907
|
+
toZone: this._zoneName(toZone),
|
|
908
|
+
index,
|
|
909
|
+
method
|
|
910
|
+
}
|
|
911
|
+
})
|
|
912
|
+
);
|
|
913
|
+
}
|
|
914
|
+
_applyMove(item, fromZone, toZone, method) {
|
|
915
|
+
if (this._placeholder?.parentNode === toZone) toZone.insertBefore(item, this._placeholder);
|
|
916
|
+
else toZone.appendChild(item);
|
|
917
|
+
for (const it of this._items()) it.tabIndex = it === item ? 0 : -1;
|
|
918
|
+
this._emitChange(item, fromZone, toZone, this._indexInZone(item, toZone), method);
|
|
919
|
+
}
|
|
920
|
+
_focusSibling(item, dir) {
|
|
921
|
+
const zone = this._closestZone(item);
|
|
922
|
+
if (!zone) return;
|
|
923
|
+
const items = this._items(zone);
|
|
924
|
+
const i = items.indexOf(item);
|
|
925
|
+
if (i < 0) return;
|
|
926
|
+
const next = items[i + dir];
|
|
927
|
+
if (!next) return;
|
|
928
|
+
item.tabIndex = -1;
|
|
929
|
+
next.tabIndex = 0;
|
|
930
|
+
next.focus();
|
|
931
|
+
}
|
|
932
|
+
_ensurePlaceholder(itemEl) {
|
|
933
|
+
if (this._placeholder?.isConnected) return;
|
|
934
|
+
this._placeholder = document.createElement("div");
|
|
935
|
+
this._placeholder.className = "pwc-zone-transfer-placeholder";
|
|
936
|
+
this._placeholder.setAttribute("aria-hidden", "true");
|
|
937
|
+
this._placeholder.style.height = `${Math.max(8, Math.round(itemEl.getBoundingClientRect().height || 0))}px`;
|
|
938
|
+
}
|
|
939
|
+
_movePlaceholder(zoneEl, beforeEl) {
|
|
940
|
+
if (!this._placeholder) return;
|
|
941
|
+
if (beforeEl && beforeEl.parentNode === zoneEl) zoneEl.insertBefore(this._placeholder, beforeEl);
|
|
942
|
+
else zoneEl.appendChild(this._placeholder);
|
|
943
|
+
}
|
|
944
|
+
_clearPlaceholder() {
|
|
945
|
+
if (this._placeholder?.parentNode) this._placeholder.parentNode.removeChild(this._placeholder);
|
|
946
|
+
}
|
|
947
|
+
_beforeFromPointer(zoneEl, e, draggedItem) {
|
|
948
|
+
const y = e.clientY;
|
|
949
|
+
for (const it of this._items(zoneEl)) {
|
|
950
|
+
if (it === draggedItem || it === this._placeholder) continue;
|
|
951
|
+
const r = it.getBoundingClientRect();
|
|
952
|
+
if (y <= r.top + r.height / 2) return it;
|
|
953
|
+
}
|
|
954
|
+
return null;
|
|
955
|
+
}
|
|
956
|
+
_closestZone(node) {
|
|
957
|
+
if (!(node instanceof Element)) return null;
|
|
958
|
+
const zone = node.closest(this.constructor.zoneSelector);
|
|
959
|
+
return zone && this.contains(zone) ? zone : null;
|
|
960
|
+
}
|
|
961
|
+
_closestItem(node) {
|
|
962
|
+
if (!(node instanceof Element)) return null;
|
|
963
|
+
const item = node.closest(this.constructor.itemSelector);
|
|
964
|
+
return item && this.contains(item) ? item : null;
|
|
965
|
+
}
|
|
966
|
+
_closestHandle(node) {
|
|
967
|
+
if (!(node instanceof Element)) return null;
|
|
968
|
+
const handle = node.closest(this.constructor.handleSelector);
|
|
969
|
+
return handle && this.contains(handle) ? handle : null;
|
|
970
|
+
}
|
|
971
|
+
_zoneName(zoneEl) {
|
|
972
|
+
if (!zoneEl) return "";
|
|
973
|
+
return zoneEl.tagName.toLowerCase() === "pwc-zone-transfer-zone" ? zoneEl.getAttribute("name") || "" : zoneEl.getAttribute("data-pwc-zone") || "";
|
|
974
|
+
}
|
|
975
|
+
_itemId(itemEl) {
|
|
976
|
+
if (!itemEl) return "";
|
|
977
|
+
return itemEl.tagName.toLowerCase() === "pwc-zone-transfer-item" ? itemEl.getAttribute("id") || itemEl.getAttribute("data-id") || "" : itemEl.getAttribute("data-pwc-item") || itemEl.getAttribute("id") || "";
|
|
978
|
+
}
|
|
979
|
+
_indexInZone(itemEl, zoneEl) {
|
|
980
|
+
return Math.max(0, this._items(zoneEl).indexOf(itemEl));
|
|
981
|
+
}
|
|
982
|
+
};
|
|
983
|
+
function define4() {
|
|
984
|
+
defineOnce("pwc-zone-transfer", PwcZoneTransfer);
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
// src/zone-transfer/zone-transfer.css
|
|
988
|
+
var zone_transfer_default = 'pwc-zone-transfer [draggable="true"] {\n cursor: grab;\n}\n\npwc-zone-transfer .pwc-zone-transfer-dragging {\n cursor: grabbing;\n opacity: 0.6;\n}\n\npwc-zone-transfer .pwc-zone-transfer-placeholder {\n opacity: 0.3;\n}';
|
|
989
|
+
|
|
990
|
+
// src/zone-transfer/index.js
|
|
991
|
+
function register4() {
|
|
992
|
+
PwcZoneTransfer.registerCss(zone_transfer_default);
|
|
993
|
+
define4();
|
|
994
|
+
}
|
|
995
|
+
register4();
|
package/dist/all.js
CHANGED
|
@@ -761,3 +761,215 @@ function register3() {
|
|
|
761
761
|
define3();
|
|
762
762
|
}
|
|
763
763
|
register3();
|
|
764
|
+
|
|
765
|
+
// src/zone-transfer/zone-transfer.js
|
|
766
|
+
var PwcZoneTransfer = class extends PwcChildrenObserverElement {
|
|
767
|
+
static events = ["dragstart", "dragover", "drop", "dragend", "keydown"];
|
|
768
|
+
static observeMode = "tree";
|
|
769
|
+
static zoneSelector = "pwc-zone-transfer-zone, [data-pwc-zone]";
|
|
770
|
+
static itemSelector = "pwc-zone-transfer-item, [data-pwc-item]";
|
|
771
|
+
static handleSelector = "pwc-zone-transfer-handle, [data-pwc-handle]";
|
|
772
|
+
onChildrenChanged() {
|
|
773
|
+
const items = this._items();
|
|
774
|
+
for (const item of items) {
|
|
775
|
+
if (!item.hasAttribute("draggable")) item.setAttribute("draggable", "true");
|
|
776
|
+
if (!item.hasAttribute("tabindex")) item.tabIndex = -1;
|
|
777
|
+
if (!item.hasAttribute("role")) item.setAttribute("role", "option");
|
|
778
|
+
}
|
|
779
|
+
for (const zone of this._zones()) {
|
|
780
|
+
if (!zone.hasAttribute("role")) zone.setAttribute("role", "listbox");
|
|
781
|
+
if (!zone.hasAttribute("tabindex")) zone.tabIndex = -1;
|
|
782
|
+
}
|
|
783
|
+
const active = items.find((it) => it.tabIndex === 0) || items[0] || null;
|
|
784
|
+
for (const it of items) it.tabIndex = it === active ? 0 : -1;
|
|
785
|
+
}
|
|
786
|
+
handleEvent(e) {
|
|
787
|
+
if (e.type === "dragstart") return this._onDragStart(e);
|
|
788
|
+
if (e.type === "dragover") return this._onDragOver(e);
|
|
789
|
+
if (e.type === "drop") return this._onDrop(e);
|
|
790
|
+
if (e.type === "dragend") return this._onDragEnd();
|
|
791
|
+
if (e.type === "keydown") return this._onKeyDown(e);
|
|
792
|
+
}
|
|
793
|
+
_zones() {
|
|
794
|
+
return Array.from(this.querySelectorAll(this.constructor.zoneSelector));
|
|
795
|
+
}
|
|
796
|
+
_items(zoneEl) {
|
|
797
|
+
return Array.from((zoneEl || this).querySelectorAll(this.constructor.itemSelector));
|
|
798
|
+
}
|
|
799
|
+
_onDragStart(e) {
|
|
800
|
+
const item = this._closestItem(e.target);
|
|
801
|
+
if (!item) return;
|
|
802
|
+
if (item.querySelector(this.constructor.handleSelector) && !this._closestHandle(e.target)) {
|
|
803
|
+
e.preventDefault();
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
806
|
+
const zone = this._closestZone(item);
|
|
807
|
+
if (!zone) return;
|
|
808
|
+
this._drag = { item, fromZone: zone };
|
|
809
|
+
if (e.dataTransfer) e.dataTransfer.effectAllowed = "move";
|
|
810
|
+
item.classList.add("pwc-zone-transfer-dragging");
|
|
811
|
+
this._ensurePlaceholder(item);
|
|
812
|
+
}
|
|
813
|
+
_onDragOver(e) {
|
|
814
|
+
if (!this._drag?.item) return;
|
|
815
|
+
const zone = this._closestZone(e.target);
|
|
816
|
+
if (!zone) return;
|
|
817
|
+
e.preventDefault();
|
|
818
|
+
if (e.dataTransfer) e.dataTransfer.dropEffect = "move";
|
|
819
|
+
this._ensurePlaceholder(this._drag.item);
|
|
820
|
+
const beforeEl = this._beforeFromPointer(zone, e, this._drag.item);
|
|
821
|
+
this._movePlaceholder(zone, beforeEl);
|
|
822
|
+
this._drag.overZone = zone;
|
|
823
|
+
this._drag.overMethod = beforeEl ? "before" : "append";
|
|
824
|
+
}
|
|
825
|
+
_onDrop(e) {
|
|
826
|
+
if (!this._drag?.item) return;
|
|
827
|
+
const zone = this._closestZone(e.target);
|
|
828
|
+
if (!zone) return;
|
|
829
|
+
e.preventDefault();
|
|
830
|
+
this._applyMove(this._drag.item, this._drag.fromZone, zone, this._drag.overMethod || "append");
|
|
831
|
+
this._clearPlaceholder();
|
|
832
|
+
}
|
|
833
|
+
_onDragEnd() {
|
|
834
|
+
if (this._drag?.item) this._drag.item.classList.remove("pwc-zone-transfer-dragging");
|
|
835
|
+
this._drag = null;
|
|
836
|
+
this._clearPlaceholder();
|
|
837
|
+
}
|
|
838
|
+
_onKeyDown(e) {
|
|
839
|
+
if (e.target?.closest?.("input,textarea,select,button,[contenteditable]")) return;
|
|
840
|
+
const item = this._closestItem(e.target);
|
|
841
|
+
if (!item) return;
|
|
842
|
+
if (e.key === "ArrowUp" || e.key === "ArrowDown") {
|
|
843
|
+
e.preventDefault();
|
|
844
|
+
const dir = e.key === "ArrowDown" ? 1 : -1;
|
|
845
|
+
if (e.ctrlKey || e.metaKey) this._keyboardReorder(item, dir);
|
|
846
|
+
else this._focusSibling(item, dir);
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
849
|
+
const zone = this._zoneByHotkey(e.key);
|
|
850
|
+
if (!zone) return;
|
|
851
|
+
e.preventDefault();
|
|
852
|
+
this._keyboardMoveToZone(item, zone);
|
|
853
|
+
}
|
|
854
|
+
_keyboardReorder(item, dir) {
|
|
855
|
+
const zone = this._closestZone(item);
|
|
856
|
+
if (!zone) return;
|
|
857
|
+
const items = this._items(zone);
|
|
858
|
+
const i = items.indexOf(item);
|
|
859
|
+
if (i < 0) return;
|
|
860
|
+
const j = i + dir;
|
|
861
|
+
if (j < 0 || j >= items.length) return;
|
|
862
|
+
zone.insertBefore(item, dir > 0 ? items[j].nextElementSibling : items[j]);
|
|
863
|
+
for (const it of this._items()) it.tabIndex = it === item ? 0 : -1;
|
|
864
|
+
item.focus();
|
|
865
|
+
this._emitChange(item, zone, zone, this._indexInZone(item, zone), "before");
|
|
866
|
+
}
|
|
867
|
+
_keyboardMoveToZone(item, zone) {
|
|
868
|
+
const fromZone = this._closestZone(item);
|
|
869
|
+
if (!fromZone || fromZone === zone) return;
|
|
870
|
+
zone.appendChild(item);
|
|
871
|
+
for (const it of this._items()) it.tabIndex = it === item ? 0 : -1;
|
|
872
|
+
item.focus();
|
|
873
|
+
this._emitChange(item, fromZone, zone, this._indexInZone(item, zone), "append");
|
|
874
|
+
}
|
|
875
|
+
_zoneByHotkey(key) {
|
|
876
|
+
const zones = this._zones();
|
|
877
|
+
if (!zones.some((z) => z.hasAttribute("data-pwc-zone-key"))) return null;
|
|
878
|
+
return zones.find((z) => z.getAttribute("data-pwc-zone-key") === key) || null;
|
|
879
|
+
}
|
|
880
|
+
_emitChange(item, fromZone, toZone, index, method) {
|
|
881
|
+
this.dispatchEvent(
|
|
882
|
+
new CustomEvent("pwc-zone-transfer:change", {
|
|
883
|
+
bubbles: true,
|
|
884
|
+
detail: {
|
|
885
|
+
itemId: this._itemId(item),
|
|
886
|
+
fromZone: this._zoneName(fromZone),
|
|
887
|
+
toZone: this._zoneName(toZone),
|
|
888
|
+
index,
|
|
889
|
+
method
|
|
890
|
+
}
|
|
891
|
+
})
|
|
892
|
+
);
|
|
893
|
+
}
|
|
894
|
+
_applyMove(item, fromZone, toZone, method) {
|
|
895
|
+
if (this._placeholder?.parentNode === toZone) toZone.insertBefore(item, this._placeholder);
|
|
896
|
+
else toZone.appendChild(item);
|
|
897
|
+
for (const it of this._items()) it.tabIndex = it === item ? 0 : -1;
|
|
898
|
+
this._emitChange(item, fromZone, toZone, this._indexInZone(item, toZone), method);
|
|
899
|
+
}
|
|
900
|
+
_focusSibling(item, dir) {
|
|
901
|
+
const zone = this._closestZone(item);
|
|
902
|
+
if (!zone) return;
|
|
903
|
+
const items = this._items(zone);
|
|
904
|
+
const i = items.indexOf(item);
|
|
905
|
+
if (i < 0) return;
|
|
906
|
+
const next = items[i + dir];
|
|
907
|
+
if (!next) return;
|
|
908
|
+
item.tabIndex = -1;
|
|
909
|
+
next.tabIndex = 0;
|
|
910
|
+
next.focus();
|
|
911
|
+
}
|
|
912
|
+
_ensurePlaceholder(itemEl) {
|
|
913
|
+
if (this._placeholder?.isConnected) return;
|
|
914
|
+
this._placeholder = document.createElement("div");
|
|
915
|
+
this._placeholder.className = "pwc-zone-transfer-placeholder";
|
|
916
|
+
this._placeholder.setAttribute("aria-hidden", "true");
|
|
917
|
+
this._placeholder.style.height = `${Math.max(8, Math.round(itemEl.getBoundingClientRect().height || 0))}px`;
|
|
918
|
+
}
|
|
919
|
+
_movePlaceholder(zoneEl, beforeEl) {
|
|
920
|
+
if (!this._placeholder) return;
|
|
921
|
+
if (beforeEl && beforeEl.parentNode === zoneEl) zoneEl.insertBefore(this._placeholder, beforeEl);
|
|
922
|
+
else zoneEl.appendChild(this._placeholder);
|
|
923
|
+
}
|
|
924
|
+
_clearPlaceholder() {
|
|
925
|
+
if (this._placeholder?.parentNode) this._placeholder.parentNode.removeChild(this._placeholder);
|
|
926
|
+
}
|
|
927
|
+
_beforeFromPointer(zoneEl, e, draggedItem) {
|
|
928
|
+
const y = e.clientY;
|
|
929
|
+
for (const it of this._items(zoneEl)) {
|
|
930
|
+
if (it === draggedItem || it === this._placeholder) continue;
|
|
931
|
+
const r = it.getBoundingClientRect();
|
|
932
|
+
if (y <= r.top + r.height / 2) return it;
|
|
933
|
+
}
|
|
934
|
+
return null;
|
|
935
|
+
}
|
|
936
|
+
_closestZone(node) {
|
|
937
|
+
if (!(node instanceof Element)) return null;
|
|
938
|
+
const zone = node.closest(this.constructor.zoneSelector);
|
|
939
|
+
return zone && this.contains(zone) ? zone : null;
|
|
940
|
+
}
|
|
941
|
+
_closestItem(node) {
|
|
942
|
+
if (!(node instanceof Element)) return null;
|
|
943
|
+
const item = node.closest(this.constructor.itemSelector);
|
|
944
|
+
return item && this.contains(item) ? item : null;
|
|
945
|
+
}
|
|
946
|
+
_closestHandle(node) {
|
|
947
|
+
if (!(node instanceof Element)) return null;
|
|
948
|
+
const handle = node.closest(this.constructor.handleSelector);
|
|
949
|
+
return handle && this.contains(handle) ? handle : null;
|
|
950
|
+
}
|
|
951
|
+
_zoneName(zoneEl) {
|
|
952
|
+
if (!zoneEl) return "";
|
|
953
|
+
return zoneEl.tagName.toLowerCase() === "pwc-zone-transfer-zone" ? zoneEl.getAttribute("name") || "" : zoneEl.getAttribute("data-pwc-zone") || "";
|
|
954
|
+
}
|
|
955
|
+
_itemId(itemEl) {
|
|
956
|
+
if (!itemEl) return "";
|
|
957
|
+
return itemEl.tagName.toLowerCase() === "pwc-zone-transfer-item" ? itemEl.getAttribute("id") || itemEl.getAttribute("data-id") || "" : itemEl.getAttribute("data-pwc-item") || itemEl.getAttribute("id") || "";
|
|
958
|
+
}
|
|
959
|
+
_indexInZone(itemEl, zoneEl) {
|
|
960
|
+
return Math.max(0, this._items(zoneEl).indexOf(itemEl));
|
|
961
|
+
}
|
|
962
|
+
};
|
|
963
|
+
function define4() {
|
|
964
|
+
defineOnce("pwc-zone-transfer", PwcZoneTransfer);
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
// src/zone-transfer/zone-transfer.css
|
|
968
|
+
var zone_transfer_default = 'pwc-zone-transfer [draggable="true"] {\n cursor: grab;\n}\n\npwc-zone-transfer .pwc-zone-transfer-dragging {\n cursor: grabbing;\n opacity: 0.6;\n}\n\npwc-zone-transfer .pwc-zone-transfer-placeholder {\n opacity: 0.3;\n}';
|
|
969
|
+
|
|
970
|
+
// src/zone-transfer/index.js
|
|
971
|
+
function register4() {
|
|
972
|
+
PwcZoneTransfer.registerCss(zone_transfer_default);
|
|
973
|
+
define4();
|
|
974
|
+
}
|
|
975
|
+
register4();
|