@c2n/reorder-list 0.0.4 → 0.0.6

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Nguyen Thai Vinh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,473 +1,510 @@
1
- import { nothing as E } from "lit/html.js";
2
- import { directive as k, PartType as D } from "lit/directive.js";
3
- import { AsyncDirective as M } from "lit/async-directive.js";
4
- import { unsafeCSS as $, LitElement as R, html as u } from "lit";
5
- import { query as S, queryAll as T, property as y, state as O, eventOptions as B, customElement as L } from "lit/decorators.js";
6
- import { classMap as f } from "lit/directives/class-map.js";
7
- import { styleMap as F } from "lit/directives/style-map.js";
8
- const z = /* @__PURE__ */ new WeakMap();
9
- let x = 0;
10
- const v = /* @__PURE__ */ new Map(), I = /* @__PURE__ */ new WeakSet(), P = () => new Promise((i) => requestAnimationFrame(i)), C = (i, t) => {
11
- const e = i - t;
12
- return e === 0 ? void 0 : e;
13
- }, w = (i, t) => {
14
- const e = i / t;
15
- return e === 1 ? void 0 : e;
16
- }, b = { left: (i, t) => {
17
- const e = C(i, t);
18
- return { value: e, transform: e && `translateX(${e}px)` };
19
- }, top: (i, t) => {
20
- const e = C(i, t);
21
- return { value: e, transform: e && `translateY(${e}px)` };
22
- }, width: (i, t) => {
23
- const e = w(i, t);
24
- return { value: e, transform: e && `scaleX(${e})` };
25
- }, height: (i, t) => {
26
- const e = w(i, t);
27
- return { value: e, transform: e && `scaleY(${e})` };
28
- } }, U = { duration: 333, easing: "ease-in-out" }, _ = ["left", "top", "width", "height", "opacity", "color", "background"], A = /* @__PURE__ */ new WeakMap();
29
- class X extends M {
30
- constructor(t) {
31
- if (super(t), this.t = null, this.i = null, this.o = !0, this.shouldLog = !1, t.type === D.CHILD)
32
- throw Error("The `animate` directive must be used in attribute position.");
33
- this.createFinished();
34
- }
35
- createFinished() {
36
- var t;
37
- (t = this.resolveFinished) === null || t === void 0 || t.call(this), this.finished = new Promise((e) => {
38
- this.h = e;
39
- });
40
- }
41
- async resolveFinished() {
42
- var t;
43
- (t = this.h) === null || t === void 0 || t.call(this), this.h = void 0;
44
- }
45
- render(t) {
46
- return E;
47
- }
48
- getController() {
49
- return z.get(this.l);
50
- }
51
- isDisabled() {
52
- var t;
53
- return this.options.disabled || ((t = this.getController()) === null || t === void 0 ? void 0 : t.disabled);
54
- }
55
- update(t, [e]) {
56
- var s;
57
- const o = this.l === void 0;
58
- return o && (this.l = (s = t.options) === null || s === void 0 ? void 0 : s.host, this.l.addController(this), this.element = t.element, A.set(this.element, this)), this.optionsOrCallback = e, (o || typeof e != "function") && this.u(e), this.render(e);
59
- }
60
- u(t) {
61
- var e, s;
62
- t = t != null ? t : {};
63
- const o = this.getController();
64
- o !== void 0 && ((t = { ...o.defaultOptions, ...t }).keyframeOptions = { ...o.defaultOptions.keyframeOptions, ...t.keyframeOptions }), (e = (s = t).properties) !== null && e !== void 0 || (s.properties = _), this.options = t;
65
- }
66
- v() {
67
- const t = {}, e = this.element.getBoundingClientRect(), s = getComputedStyle(this.element);
68
- return this.options.properties.forEach((o) => {
69
- var r;
70
- const n = (r = e[o]) !== null && r !== void 0 ? r : b[o] ? void 0 : s[o], l = Number(n);
71
- t[o] = isNaN(l) ? n + "" : l;
72
- }), t;
73
- }
74
- p() {
75
- let t, e = !0;
76
- return this.options.guard && (t = this.options.guard(), e = ((s, o) => {
77
- if (Array.isArray(s)) {
78
- if (Array.isArray(o) && o.length === s.length && s.every((r, n) => r === o[n]))
79
- return !1;
80
- } else if (o === s)
81
- return !1;
82
- return !0;
83
- })(t, this.m)), this.o = this.l.hasUpdated && !this.isDisabled() && !this.isAnimating() && e && this.element.isConnected, this.o && (this.m = Array.isArray(t) ? Array.from(t) : t), this.o;
84
- }
85
- hostUpdate() {
86
- var t;
87
- typeof this.optionsOrCallback == "function" && this.u(this.optionsOrCallback()), this.p() && (this.g = this.v(), this.t = (t = this.t) !== null && t !== void 0 ? t : this.element.parentNode, this.i = this.element.nextSibling);
88
- }
89
- async hostUpdated() {
90
- if (!this.o || !this.element.isConnected || this.options.skipInitial && !this.isHostRendered)
91
- return;
92
- let t;
93
- this.prepare(), await P;
94
- const e = this._(), s = this.A(this.options.keyframeOptions, e), o = this.v();
95
- if (this.g !== void 0) {
96
- const { from: r, to: n } = this.O(this.g, o, e);
97
- this.log("measured", [this.g, o, r, n]), t = this.calculateKeyframes(r, n);
98
- } else {
99
- const r = v.get(this.options.inId);
100
- if (r) {
101
- v.delete(this.options.inId);
102
- const { from: n, to: l } = this.O(r, o, e);
103
- t = this.calculateKeyframes(n, l), t = this.options.in ? [{ ...this.options.in[0], ...t[0] }, ...this.options.in.slice(1), t[1]] : t, x++, t.forEach((d) => d.zIndex = x);
104
- } else
105
- this.options.in && (t = [...this.options.in, {}]);
106
- }
107
- this.animate(t, s);
108
- }
109
- resetStyles() {
110
- var t;
111
- this.P !== void 0 && (this.element.setAttribute("style", (t = this.P) !== null && t !== void 0 ? t : ""), this.P = void 0);
112
- }
113
- commitStyles() {
114
- var t, e;
115
- this.P = this.element.getAttribute("style"), (t = this.webAnimation) === null || t === void 0 || t.commitStyles(), (e = this.webAnimation) === null || e === void 0 || e.cancel();
116
- }
117
- reconnected() {
118
- }
119
- async disconnected() {
120
- var t;
121
- if (!this.o || (this.options.id !== void 0 && v.set(this.options.id, this.g), this.options.out === void 0))
122
- return;
123
- if (this.prepare(), await P(), (t = this.t) === null || t === void 0 ? void 0 : t.isConnected) {
124
- const s = this.i && this.i.parentNode === this.t ? this.i : null;
125
- if (this.t.insertBefore(this.element, s), this.options.stabilizeOut) {
126
- const o = this.v();
127
- this.log("stabilizing out");
128
- const r = this.g.left - o.left, n = this.g.top - o.top;
129
- getComputedStyle(this.element).position !== "static" || r === 0 && n === 0 || (this.element.style.position = "relative"), r !== 0 && (this.element.style.left = r + "px"), n !== 0 && (this.element.style.top = n + "px");
130
- }
131
- }
132
- const e = this.A(this.options.keyframeOptions);
133
- await this.animate(this.options.out, e), this.element.remove();
134
- }
135
- prepare() {
136
- this.createFinished();
137
- }
138
- start() {
139
- var t, e;
140
- (e = (t = this.options).onStart) === null || e === void 0 || e.call(t, this);
141
- }
142
- didFinish(t) {
143
- var e, s;
144
- t && ((s = (e = this.options).onComplete) === null || s === void 0 || s.call(e, this)), this.g = void 0, this.animatingProperties = void 0, this.frames = void 0, this.resolveFinished();
145
- }
146
- _() {
147
- const t = [];
148
- for (let e = this.element.parentNode; e; e = e == null ? void 0 : e.parentNode) {
149
- const s = A.get(e);
150
- s && !s.isDisabled() && s && t.push(s);
151
- }
152
- return t;
153
- }
154
- get isHostRendered() {
155
- const t = I.has(this.l);
156
- return t || this.l.updateComplete.then(() => {
157
- I.add(this.l);
158
- }), t;
159
- }
160
- A(t, e = this._()) {
161
- const s = { ...U };
162
- return e.forEach((o) => Object.assign(s, o.options.keyframeOptions)), Object.assign(s, t), s;
163
- }
164
- O(t, e, s) {
165
- t = { ...t }, e = { ...e };
166
- const o = s.map((l) => l.animatingProperties).filter((l) => l !== void 0);
167
- let r = 1, n = 1;
168
- return o !== void 0 && (o.forEach((l) => {
169
- l.width && (r /= l.width), l.height && (n /= l.height);
170
- }), t.left !== void 0 && e.left !== void 0 && (t.left = r * t.left, e.left = r * e.left), t.top !== void 0 && e.top !== void 0 && (t.top = n * t.top, e.top = n * e.top)), { from: t, to: e };
171
- }
172
- calculateKeyframes(t, e, s = !1) {
173
- var o;
174
- const r = {}, n = {};
175
- let l = !1;
176
- const d = {};
177
- for (const p in e) {
178
- const c = t[p], g = e[p];
179
- if (p in b) {
180
- const N = b[p];
181
- if (c === void 0 || g === void 0)
182
- continue;
183
- const m = N(c, g);
184
- m.transform !== void 0 && (d[p] = m.value, l = !0, r.transform = `${(o = r.transform) !== null && o !== void 0 ? o : ""} ${m.transform}`);
185
- } else
186
- c !== g && c !== void 0 && g !== void 0 && (l = !0, r[p] = c, n[p] = g);
187
- }
188
- return r.transformOrigin = n.transformOrigin = s ? "center center" : "top left", this.animatingProperties = d, l ? [r, n] : void 0;
189
- }
190
- async animate(t, e = this.options.keyframeOptions) {
191
- this.start(), this.frames = t;
192
- let s = !1;
193
- if (!this.isAnimating() && !this.isDisabled() && (this.options.onFrames && (this.frames = t = this.options.onFrames(this), this.log("modified frames", t)), t !== void 0)) {
194
- this.log("animate", [t, e]), s = !0, this.webAnimation = this.element.animate(t, e);
195
- const o = this.getController();
196
- o == null || o.add(this);
197
- try {
198
- await this.webAnimation.finished;
199
- } catch {
200
- }
201
- o == null || o.remove(this);
202
- }
203
- return this.didFinish(s), s;
204
- }
205
- isAnimating() {
206
- var t, e;
207
- return ((t = this.webAnimation) === null || t === void 0 ? void 0 : t.playState) === "running" || ((e = this.webAnimation) === null || e === void 0 ? void 0 : e.pending);
208
- }
209
- log(t, e) {
210
- this.shouldLog && !this.isDisabled() && console.log(t, this.options.id, e);
211
- }
1
+ import { nothing as e } from "lit/html.js";
2
+ import { PartType as t, directive as n } from "lit/directive.js";
3
+ import { AsyncDirective as r } from "lit/async-directive.js";
4
+ import { LitElement as i, html as a, unsafeCSS as o } from "lit";
5
+ import { customElement as s, eventOptions as c, property as l, query as u, queryAll as d, state as f } from "lit/decorators.js";
6
+ import { classMap as p } from "lit/directives/class-map.js";
7
+ import { styleMap as m } from "lit/directives/style-map.js";
8
+ //#region ../../../node_modules/@lit-labs/motion/animate-controller.js
9
+ var h = /* @__PURE__ */ new WeakMap(), g = 0, _ = /* @__PURE__ */ new Map(), v = /* @__PURE__ */ new WeakSet(), y = () => new Promise((e) => requestAnimationFrame(e)), b = (e, t) => {
10
+ let n = e - t;
11
+ return n === 0 ? void 0 : n;
12
+ }, x = (e, t) => {
13
+ let n = e / t;
14
+ return n === 1 ? void 0 : n;
15
+ }, S = {
16
+ left: (e, t) => {
17
+ let n = b(e, t);
18
+ return {
19
+ value: n,
20
+ transform: n == null || isNaN(n) ? void 0 : `translateX(${n}px)`
21
+ };
22
+ },
23
+ top: (e, t) => {
24
+ let n = b(e, t);
25
+ return {
26
+ value: n,
27
+ transform: n == null || isNaN(n) ? void 0 : `translateY(${n}px)`
28
+ };
29
+ },
30
+ width: (e, t) => {
31
+ let n;
32
+ t === 0 && (t = 1, n = { width: "1px" });
33
+ let r = x(e, t);
34
+ return {
35
+ value: r,
36
+ overrideFrom: n,
37
+ transform: r == null || isNaN(r) ? void 0 : `scaleX(${r})`
38
+ };
39
+ },
40
+ height: (e, t) => {
41
+ let n;
42
+ t === 0 && (t = 1, n = { height: "1px" });
43
+ let r = x(e, t);
44
+ return {
45
+ value: r,
46
+ overrideFrom: n,
47
+ transform: r == null || isNaN(r) ? void 0 : `scaleY(${r})`
48
+ };
49
+ }
50
+ }, C = {
51
+ duration: 333,
52
+ easing: "ease-in-out"
53
+ }, w = [
54
+ "left",
55
+ "top",
56
+ "width",
57
+ "height",
58
+ "opacity",
59
+ "color",
60
+ "background"
61
+ ], T = /* @__PURE__ */ new WeakMap(), E = n(class extends r {
62
+ constructor(e) {
63
+ if (super(e), this.t = !1, this.i = null, this.o = null, this.h = !0, this.shouldLog = !1, e.type === t.CHILD) throw Error("The `animate` directive must be used in attribute position.");
64
+ this.createFinished();
65
+ }
66
+ createFinished() {
67
+ this.resolveFinished?.(), this.finished = new Promise((e) => {
68
+ this.l = e;
69
+ });
70
+ }
71
+ async resolveFinished() {
72
+ this.l?.(), this.l = void 0;
73
+ }
74
+ render(t) {
75
+ return e;
76
+ }
77
+ getController() {
78
+ return h.get(this.u);
79
+ }
80
+ isDisabled() {
81
+ return this.options.disabled || this.getController()?.disabled;
82
+ }
83
+ update(e, [t]) {
84
+ let n = this.u === void 0;
85
+ return n && (this.u = e.options?.host, this.u.addController(this), this.u.updateComplete.then((e) => this.t = !0), this.element = e.element, T.set(this.element, this)), this.optionsOrCallback = t, (n || typeof t != "function") && this.m(t), this.render(t);
86
+ }
87
+ m(e) {
88
+ e ??= {};
89
+ let t = this.getController();
90
+ t !== void 0 && ((e = {
91
+ ...t.defaultOptions,
92
+ ...e
93
+ }).keyframeOptions = {
94
+ ...t.defaultOptions.keyframeOptions,
95
+ ...e.keyframeOptions
96
+ }), e.properties ??= w, this.options = e;
97
+ }
98
+ p() {
99
+ let e = {}, t = this.element.getBoundingClientRect(), n = getComputedStyle(this.element);
100
+ return this.options.properties.forEach((r) => {
101
+ let i = t[r] ?? (S[r] ? void 0 : n[r]), a = Number(i);
102
+ e[r] = isNaN(a) ? i + "" : a;
103
+ }), e;
104
+ }
105
+ v() {
106
+ let e, t = !0;
107
+ return this.options.guard && (e = this.options.guard(), t = ((e, t) => {
108
+ if (Array.isArray(e)) {
109
+ if (Array.isArray(t) && t.length === e.length && e.every((e, n) => e === t[n])) return !1;
110
+ } else if (t === e) return !1;
111
+ return !0;
112
+ })(e, this._)), this.h = this.t && !this.isDisabled() && !this.isAnimating() && t && this.element.isConnected, this.h && (this._ = Array.isArray(e) ? Array.from(e) : e), this.h;
113
+ }
114
+ hostUpdate() {
115
+ typeof this.optionsOrCallback == "function" && this.m(this.optionsOrCallback()), this.v() && (this.A = this.p(), this.i = this.i ?? this.element.parentNode, this.o = this.element.nextSibling);
116
+ }
117
+ async hostUpdated() {
118
+ if (!this.h || !this.element.isConnected || this.options.skipInitial && !this.isHostRendered) return;
119
+ let e;
120
+ this.prepare(), await y;
121
+ let t = this.P(), n = this.V(this.options.keyframeOptions, t), r = this.p();
122
+ if (this.A !== void 0) {
123
+ let { from: n, to: i } = this.O(this.A, r, t);
124
+ this.log("measured", [
125
+ this.A,
126
+ r,
127
+ n,
128
+ i
129
+ ]), e = this.calculateKeyframes(n, i);
130
+ } else {
131
+ let n = _.get(this.options.inId);
132
+ if (n) {
133
+ _.delete(this.options.inId);
134
+ let { from: i, to: a } = this.O(n, r, t);
135
+ e = this.calculateKeyframes(i, a), e = this.options.in ? [
136
+ {
137
+ ...this.options.in[0],
138
+ ...e[0]
139
+ },
140
+ ...this.options.in.slice(1),
141
+ e[1]
142
+ ] : e, g++, e.forEach((e) => e.zIndex = g);
143
+ } else this.options.in && (e = [...this.options.in, {}]);
144
+ }
145
+ this.animate(e, n);
146
+ }
147
+ resetStyles() {
148
+ this.j !== void 0 && (this.element.setAttribute("style", this.j ?? ""), this.j = void 0);
149
+ }
150
+ commitStyles() {
151
+ this.j = this.element.getAttribute("style"), this.webAnimation?.commitStyles(), this.webAnimation?.cancel();
152
+ }
153
+ reconnected() {}
154
+ async disconnected() {
155
+ if (!this.h || (this.options.id !== void 0 && _.set(this.options.id, this.A), this.options.out === void 0)) return;
156
+ if (this.prepare(), await y(), this.i?.isConnected) {
157
+ let e = this.o && this.o.parentNode === this.i ? this.o : null;
158
+ if (this.i.insertBefore(this.element, e), this.options.stabilizeOut) {
159
+ let e = this.p();
160
+ this.log("stabilizing out");
161
+ let t = this.A.left - e.left, n = this.A.top - e.top;
162
+ getComputedStyle(this.element).position !== "static" || t === 0 && n === 0 || (this.element.style.position = "relative"), t !== 0 && (this.element.style.left = t + "px"), n !== 0 && (this.element.style.top = n + "px");
163
+ }
164
+ }
165
+ let e = this.V(this.options.keyframeOptions);
166
+ await this.animate(this.options.out, e), this.element.remove();
167
+ }
168
+ prepare() {
169
+ this.createFinished();
170
+ }
171
+ start() {
172
+ this.options.onStart?.(this);
173
+ }
174
+ didFinish(e) {
175
+ e && this.options.onComplete?.(this), this.A = void 0, this.animatingProperties = void 0, this.frames = void 0, this.resolveFinished();
176
+ }
177
+ P() {
178
+ let e = [];
179
+ for (let t = this.element.parentNode; t; t = t?.parentNode) {
180
+ let n = T.get(t);
181
+ n && !n.isDisabled() && n && e.push(n);
182
+ }
183
+ return e;
184
+ }
185
+ get isHostRendered() {
186
+ let e = v.has(this.u);
187
+ return e || this.u.updateComplete.then(() => {
188
+ v.add(this.u);
189
+ }), e;
190
+ }
191
+ V(e, t = this.P()) {
192
+ let n = { ...C };
193
+ return t.forEach((e) => Object.assign(n, e.options.keyframeOptions)), Object.assign(n, e), n;
194
+ }
195
+ O(e, t, n) {
196
+ e = { ...e }, t = { ...t };
197
+ let r = n.map((e) => e.animatingProperties).filter((e) => e !== void 0), i = 1, a = 1;
198
+ return r.length > 0 && (r.forEach((e) => {
199
+ e.width && (i /= e.width), e.height && (a /= e.height);
200
+ }), e.left !== void 0 && t.left !== void 0 && (e.left = i * e.left, t.left = i * t.left), e.top !== void 0 && t.top !== void 0 && (e.top = a * e.top, t.top = a * t.top)), {
201
+ from: e,
202
+ to: t
203
+ };
204
+ }
205
+ calculateKeyframes(e, t, n = !1) {
206
+ let r = {}, i = {}, a = !1, o = {};
207
+ for (let n in t) {
208
+ let s = e[n], c = t[n];
209
+ if (n in S) {
210
+ let e = S[n];
211
+ if (s === void 0 || c === void 0) continue;
212
+ let t = e(s, c);
213
+ t.transform !== void 0 && (o[n] = t.value, a = !0, r.transform = `${r.transform ?? ""} ${t.transform}`, t.overrideFrom !== void 0 && Object.assign(r, t.overrideFrom));
214
+ } else s !== c && s !== void 0 && c !== void 0 && (a = !0, r[n] = s, i[n] = c);
215
+ }
216
+ return r.transformOrigin = i.transformOrigin = n ? "center center" : "top left", this.animatingProperties = o, a ? [r, i] : void 0;
217
+ }
218
+ async animate(e, t = this.options.keyframeOptions) {
219
+ this.start(), this.frames = e;
220
+ let n = !1;
221
+ if (!this.isAnimating() && !this.isDisabled() && (this.options.onFrames && (this.frames = e = this.options.onFrames(this), this.log("modified frames", e)), e !== void 0)) {
222
+ this.log("animate", [e, t]), n = !0, this.webAnimation = this.element.animate(e, t);
223
+ let r = this.getController();
224
+ r?.add(this);
225
+ try {
226
+ await this.webAnimation.finished;
227
+ } catch {}
228
+ r?.remove(this);
229
+ }
230
+ return this.didFinish(n), n;
231
+ }
232
+ isAnimating() {
233
+ return this.webAnimation?.playState === "running" || this.webAnimation?.pending;
234
+ }
235
+ log(e, t) {
236
+ this.shouldLog && !this.isDisabled() && console.log(e, this.options.id, t);
237
+ }
238
+ }), D = [
239
+ "top",
240
+ "right",
241
+ "bottom",
242
+ "left"
243
+ ];
244
+ n(class extends r {
245
+ constructor(e) {
246
+ if (super(e), e.type !== t.ELEMENT) throw Error("The `position` directive must be used in attribute position.");
247
+ }
248
+ render(t, n) {
249
+ return e;
250
+ }
251
+ update(e, [t, n]) {
252
+ return this.u === void 0 && (this.u = e.options?.host, this.u.addController(this)), this.C = e.element, this.N = t, this.S = n ?? [
253
+ "left",
254
+ "top",
255
+ "width",
256
+ "height"
257
+ ], this.render(t, n);
258
+ }
259
+ hostUpdated() {
260
+ this.F();
261
+ }
262
+ F() {
263
+ let e = typeof this.N == "function" ? this.N() : this.N?.value, t = e.offsetParent;
264
+ if (e === void 0 || !t) return;
265
+ let n = e.getBoundingClientRect(), r = t.getBoundingClientRect();
266
+ this.S?.forEach((e) => {
267
+ let t = D.includes(e) ? n[e] - r[e] : n[e];
268
+ this.C.style[e] = t + "px";
269
+ });
270
+ }
271
+ });
272
+ //#endregion
273
+ //#region src/reorder-list.scss?inline
274
+ var O = ":host{position:relative}.c2-reorder-list-container{gap:var(--c2-reorder-list--container-gap,0px);border-width:var(--c2-reorder-list--container-border-width,0px);border-color:var(--c2-reorder-list--container-border-color,#bcbcc6);border-radius:var(--c2-reorder-list--container-border-radius,8px);padding:var(--c2-reorder-list--container-padding,0px);margin:var(--c2-reorder-list--container-margin,0px);border-style:solid;flex-direction:column;display:flex;position:relative}.c2-reorder-list-container .list-item{background:var(--c2-reorder-list--item-background,transparent);padding:var(--c2-reorder-list--item-padding,0px);border-radius:initial;box-sizing:border-box;position:relative}.c2-reorder-list-container .list-item:not(:last-child){border-bottom:var(--c2-reorder-list--divider-height,0px) solid var(--c2-reorder-list--divider-color,#bcbcc6)}.c2-reorder-list-container .list-item:first-child{border-top-left-radius:inherit;border-top-right-radius:inherit}.c2-reorder-list-container .list-item:last-child{border-bottom-left-radius:inherit;border-bottom-right-radius:inherit}.c2-reorder-list-container .list-item--reorderable ::slotted(:not([data-fixed])){cursor:pointer;touch-action:none;-webkit-user-drag:none;-webkit-tap-highlight-color:transparent;-webkit-user-select:none;user-select:none}.c2-reorder-list-container .dragging-placeholder{background-color:var(--c2-reorder-list--placeholder-background,transparent);z-index:1}.dragging-item{box-sizing:border-box;background-color:var(--c2-reorder-list--dragging-item-background,transparent);cursor:pointer;z-index:100000;display:none;position:fixed}.dragging-item.dragging-item--active{display:flex}";
275
+ //#endregion
276
+ //#region \0@oxc-project+runtime@0.148.0/helpers/esm/decorate.js
277
+ function k(e, t, n, r) {
278
+ var i = arguments.length, a = i < 3 ? t : r === null ? r = Object.getOwnPropertyDescriptor(t, n) : r, o;
279
+ if (typeof Reflect == "object" && typeof Reflect.decorate == "function") a = Reflect.decorate(e, t, n, r);
280
+ else for (var s = e.length - 1; s >= 0; s--) (o = e[s]) && (a = (i < 3 ? o(a) : i > 3 ? o(t, n, a) : o(t, n)) || a);
281
+ return i > 3 && a && Object.defineProperty(t, n, a), a;
212
282
  }
213
- const Y = k(X), j = ["top", "right", "bottom", "left"];
214
- class H extends M {
215
- constructor(t) {
216
- if (super(t), t.type !== D.ELEMENT)
217
- throw Error("The `position` directive must be used in attribute position.");
218
- }
219
- render(t, e) {
220
- return E;
221
- }
222
- update(t, [e, s]) {
223
- var o;
224
- return this.l === void 0 && (this.l = (o = t.options) === null || o === void 0 ? void 0 : o.host, this.l.addController(this)), this.j = t.element, this.S = e, this.C = s != null ? s : ["left", "top", "width", "height"], this.render(e, s);
225
- }
226
- hostUpdated() {
227
- this.F();
228
- }
229
- F() {
230
- var t, e;
231
- const s = typeof this.S == "function" ? this.S() : (t = this.S) === null || t === void 0 ? void 0 : t.value, o = s.offsetParent;
232
- if (s === void 0 || !o)
233
- return;
234
- const r = s.getBoundingClientRect(), n = o.getBoundingClientRect();
235
- (e = this.C) === null || e === void 0 || e.forEach((l) => {
236
- const d = j.includes(l) ? r[l] - n[l] : r[l];
237
- this.j.style[l] = d + "px";
238
- });
239
- }
240
- }
241
- k(H);
242
- const q = `:host{position:relative}.c2-reorder-list-container{display:flex;flex-direction:column;position:relative;gap:var(--c2-reorder-list-container-gap, 0px);border-width:var(--c2-reorder-list-container-border-width, 0px);border-color:var(--c2-reorder-list-container-border-color, #bcbcc6);border-style:solid;border-radius:var(--c2-reorder-list-container-border-radius, 8px);padding:var(--c2-reorder-list-container-padding, 0px);margin:var(--c2-reorder-list-container-margin, 0px)}.c2-reorder-list-container .list-item{background:var(--c2-reorder-list-item-background, transparent);padding:var(--c2-reorder-list-item-padding, 0px);border-radius:initial;box-sizing:border-box;position:relative}.c2-reorder-list-container .list-item:not(:last-child){border-bottom:var(--c2-reorder-list-divider-height, 0px) solid var(--c2-reorder-list-divider-color, #bcbcc6)}.c2-reorder-list-container .list-item:first-child{border-top-left-radius:inherit;border-top-right-radius:inherit}.c2-reorder-list-container .list-item:last-child{border-bottom-left-radius:inherit;border-bottom-right-radius:inherit}.c2-reorder-list-container .list-item--reorderable{cursor:pointer}.c2-reorder-list-container .list-item--reorderable ::slotted(*){touch-action:none;-webkit-user-drag:none;-webkit-tap-highlight-color:transparent;user-select:none}.c2-reorder-list-container .dragging-placeholder{background-color:var(--c2-reorder-list-placeholder-background, transparent);z-index:1}.dragging-item{box-sizing:border-box;position:fixed;background-color:var(--c2-reorder-list-dragging-item-background, transparent);cursor:pointer;z-index:100000;display:none}.dragging-item.dragging-item--active{display:flex}
243
- `;
244
- var K = Object.defineProperty, W = Object.getOwnPropertyDescriptor, h = (i, t, e, s) => {
245
- for (var o = s > 1 ? void 0 : s ? W(t, e) : t, r = i.length - 1, n; r >= 0; r--)
246
- (n = i[r]) && (o = (s ? n(t, e, o) : n(o)) || o);
247
- return s && o && K(t, e, o), o;
248
- };
249
- let a = class extends R {
250
- constructor() {
251
- super(...arguments), this.editable = !1, this.dragStartThreshold = 10, this.autoScrollDisabled = !1, this.placeholderSlotIndex = -1, this.placeholderSize = { width: "0px", height: "0px" }, this.childListObserver = null, this.hostBoundingClientRect = null, this.scrollableParent = null, this.scrollableParentRect = void 0, this.pickupPosition = { x: 0, y: 0 }, this.itemPositions = [], this.currentDraggingItem = null, this.currentDraggingSlotIndex = -1, this.skipAnimation = !1, this.hasStartedDragging = !1, this.scrollingTimer = 0, this.cacheMouseEvent = null, this.handleMouseMove = async (i) => {
252
- var t;
253
- if (!this.isUpdatePending)
254
- if (this.hasStartedDragging) {
255
- this.cacheMouseEvent = { pageX: i.pageX, pageY: i.pageY }, this.applyTransform(i);
256
- const e = this.getItemIndexFromPointerPosition(i);
257
- e > -1 && e !== this.placeholderSlotIndex && (this.placeholderSlotIndex = e);
258
- } else {
259
- const e = this.getPointerPosition(i), s = Math.abs(e.x - this.pickupPosition.x), o = Math.abs(e.y - this.pickupPosition.y);
260
- if (!(s + o >= this.dragStartThreshold))
261
- return;
262
- this.hasStartedDragging = !0, this.skipAnimation = !0;
263
- const n = this.getSlottedTargetIndex(i);
264
- if (n == -1)
265
- return;
266
- const l = i.composedPath()[n], d = l.getAttribute("slot"), p = i.composedPath()[n + 2];
267
- if (!d) {
268
- this.stopDrag();
269
- return;
270
- }
271
- this.pickupPosition = this.getPointerPosition(i);
272
- const c = p.getBoundingClientRect(), g = l.getBoundingClientRect();
273
- this.currentDraggingItem = l, this.placeholderSlotIndex = parseInt(d), this.currentDraggingSlotIndex = parseInt(d), this.placeholderSize = { width: `${g.width}px`, height: `${g.height}px` }, this.draggingElement.style.width = `${c.width}px`, this.draggingElement.style.height = `${c.height}px`, this.draggingElement.style.top = `${c.top}px`, this.draggingElement.style.left = `${c.left}px`, l.setAttribute("slot", "dragging-item"), this.applyTransform(i), this.updateItemPositions(), this.scrollableParent = this.getNearestScrollableParent(), this.scrollableParentRect = (t = this.scrollableParent) == null ? void 0 : t.getBoundingClientRect(), this.scrollableParent && this.scrollableParent.addEventListener("scroll", this.handleScroll, { passive: !0 });
274
- }
275
- }, this.handleScroll = () => {
276
- if (this.cacheMouseEvent) {
277
- this.updateItemPositions(), this.applyTransform(this.cacheMouseEvent);
278
- const i = this.getItemIndexFromPointerPosition(this.cacheMouseEvent);
279
- i > -1 && i !== this.placeholderSlotIndex && (this.placeholderSlotIndex = i);
280
- }
281
- }, this.handleMouseUp = () => {
282
- if (this.hasStartedDragging && this.currentDraggingItem) {
283
- const i = this.getSortChildrenBySlot(), t = this.placeholderSlotIndex;
284
- for (let e = 0; e < i.length; e++) {
285
- const s = parseInt(i[e].getAttribute("slot"));
286
- t > this.currentDraggingSlotIndex && s > this.currentDraggingSlotIndex && s <= t && i[e].setAttribute("slot", (s - 1).toString()), t < this.currentDraggingSlotIndex && s >= t && s < this.currentDraggingSlotIndex && i[e].setAttribute("slot", (s + 1).toString());
287
- }
288
- this.currentDraggingItem.setAttribute("slot", this.placeholderSlotIndex.toString()), this.skipAnimation = !0, this.dispatchChangeEvent();
289
- }
290
- this.stopDrag();
291
- }, this.startScrollInterval = (i) => {
292
- this.stopScrolling();
293
- const t = 2;
294
- this.scrollingTimer = window.requestAnimationFrame(() => {
295
- var e;
296
- this.skipAnimation = !0, (e = this.scrollableParent) == null || e.scrollBy(0, i === "up" ? -t : t), this.startScrollInterval(i);
297
- });
298
- };
299
- }
300
- connectedCallback() {
301
- super.connectedCallback(), this.observeChildList(), this.updateSlotMapping();
302
- }
303
- disconnectedCallback() {
304
- super.disconnectedCallback(), this.childListObserver && this.childListObserver.disconnect();
305
- }
306
- renderSlots() {
307
- const i = { "list-item--reorderable": this.editable }, t = this.createPlaceHolder(i), e = this.getChildItems().length, s = Array.from({ length: e }).map((o, r) => {
308
- const n = {
309
- id: r,
310
- inId: r,
311
- skipInitial: !0,
312
- disabled: this.skipAnimation || r === e - 1
313
- };
314
- return this.placeholderSlotIndex !== -1 && this.currentDraggingSlotIndex === r ? u`` : u`<div class="list-item ${f(i)}" ${Y(n)}>
283
+ //#endregion
284
+ //#region src/reorder-list.ts
285
+ var A = class extends i {
286
+ constructor(...e) {
287
+ super(...e), this.editable = !1, this.dragStartThreshold = 10, this.autoScrollDisabled = !1, this.placeholderSlotIndex = -1, this.placeholderSize = {
288
+ width: "0px",
289
+ height: "0px"
290
+ }, this.childListObserver = null, this.hostBoundingClientRect = null, this.scrollableParent = null, this.scrollableParentRect = void 0, this.pickupPosition = {
291
+ x: 0,
292
+ y: 0
293
+ }, this.itemPositions = [], this.currentDraggingItem = null, this.currentDraggingSlotIndex = -1, this.skipAnimation = !1, this.hasStartedDragging = !1, this.scrollingTimer = 0, this.cacheMouseEvent = null, this.handleMouseMove = async (e) => {
294
+ if (!this.isUpdatePending) {
295
+ if (this.hasStartedDragging) {
296
+ this.cacheMouseEvent = {
297
+ pageX: e.pageX,
298
+ pageY: e.pageY
299
+ }, this.applyTransform(e);
300
+ let t = this.getItemIndexFromPointerPosition(e);
301
+ t > -1 && t !== this.placeholderSlotIndex && (this.placeholderSlotIndex = t);
302
+ } else {
303
+ let t = this.getPointerPosition(e);
304
+ if (!(Math.abs(t.x - this.pickupPosition.x) + Math.abs(t.y - this.pickupPosition.y) >= this.dragStartThreshold)) return;
305
+ this.hasStartedDragging = !0, this.skipAnimation = !0;
306
+ let n = this.getSlottedTargetIndex(e);
307
+ if (n == -1) return;
308
+ let r = e.composedPath()[n], i = r.getAttribute("slot"), a = e.composedPath()[n + 2];
309
+ if (!i) {
310
+ this.stopDrag();
311
+ return;
312
+ }
313
+ this.pickupPosition = this.getPointerPosition(e);
314
+ let o = a.getBoundingClientRect(), s = r.getBoundingClientRect();
315
+ this.currentDraggingItem = r, this.placeholderSlotIndex = parseInt(i), this.currentDraggingSlotIndex = parseInt(i), this.placeholderSize = {
316
+ width: `${s.width}px`,
317
+ height: `${s.height}px`
318
+ }, this.draggingElement.style.width = `${o.width}px`, this.draggingElement.style.height = `${o.height}px`, this.draggingElement.style.top = `${o.top}px`, this.draggingElement.style.left = `${o.left}px`, r.setAttribute("slot", "dragging-item"), this.applyTransform(e), this.updateItemPositions(), this.scrollableParent = this.getNearestScrollableParent(), this.scrollableParentRect = this.scrollableParent?.getBoundingClientRect(), this.scrollableParent && this.scrollableParent.addEventListener("scroll", this.handleScroll, { passive: !0 });
319
+ }
320
+ }
321
+ }, this.handleScroll = () => {
322
+ if (this.cacheMouseEvent) {
323
+ this.updateItemPositions(), this.applyTransform(this.cacheMouseEvent);
324
+ let e = this.getItemIndexFromPointerPosition(this.cacheMouseEvent);
325
+ e > -1 && e !== this.placeholderSlotIndex && (this.placeholderSlotIndex = e);
326
+ }
327
+ }, this.handleMouseUp = () => {
328
+ if (this.hasStartedDragging && this.currentDraggingItem) {
329
+ let e = this.getSortChildrenBySlot(), t = this.placeholderSlotIndex;
330
+ for (let n = 0; n < e.length; n++) {
331
+ let r = parseInt(e[n].getAttribute("slot"));
332
+ t > this.currentDraggingSlotIndex && r > this.currentDraggingSlotIndex && r <= t && e[n].setAttribute("slot", (r - 1).toString()), t < this.currentDraggingSlotIndex && r >= t && r < this.currentDraggingSlotIndex && e[n].setAttribute("slot", (r + 1).toString());
333
+ }
334
+ this.currentDraggingItem.setAttribute("slot", this.placeholderSlotIndex.toString()), this.skipAnimation = !0, this.dispatchChangeEvent();
335
+ }
336
+ this.stopDrag();
337
+ }, this.startScrollInterval = (e) => {
338
+ this.stopScrolling(), this.scrollingTimer = window.requestAnimationFrame(() => {
339
+ this.skipAnimation = !0, this.scrollableParent?.scrollBy(0, e === "up" ? -2 : 2), this.startScrollInterval(e);
340
+ });
341
+ };
342
+ }
343
+ connectedCallback() {
344
+ super.connectedCallback(), this.observeChildList(), this.updateSlotMapping();
345
+ }
346
+ disconnectedCallback() {
347
+ super.disconnectedCallback(), this.childListObserver && this.childListObserver.disconnect();
348
+ }
349
+ renderSlots() {
350
+ let e = { "list-item--reorderable": this.editable }, t = this.createPlaceHolder(e), n = this.getChildItems().length, r = Array.from({ length: n }).map((t, r) => {
351
+ let i = {
352
+ id: r,
353
+ inId: r,
354
+ skipInitial: !0,
355
+ disabled: this.skipAnimation || r === n - 1
356
+ };
357
+ return this.placeholderSlotIndex !== -1 && this.currentDraggingSlotIndex === r ? a`` : a`<div class="list-item ${p(e)}" ${E(i)}>
315
358
  <slot name="${r}"></slot>
316
359
  </div>`;
317
- });
318
- return this.placeholderSlotIndex !== -1 && (this.placeholderSlotIndex === this.currentDraggingSlotIndex ? s[this.placeholderSlotIndex] = t : this.placeholderSlotIndex <= this.currentDraggingSlotIndex ? s.splice(this.placeholderSlotIndex, 0, t) : s.splice(this.placeholderSlotIndex + 1, 0, t)), s;
319
- }
320
- createPlaceHolder(i) {
321
- return u` <div class="list-item placeholder ${f(i)}">
360
+ });
361
+ return this.placeholderSlotIndex !== -1 && (this.placeholderSlotIndex === this.currentDraggingSlotIndex ? r[this.placeholderSlotIndex] = t : this.placeholderSlotIndex <= this.currentDraggingSlotIndex ? r.splice(this.placeholderSlotIndex, 0, t) : r.splice(this.placeholderSlotIndex + 1, 0, t)), r;
362
+ }
363
+ createPlaceHolder(e) {
364
+ return a` <div class="list-item placeholder ${p(e)}">
322
365
  <slot name="placeholder">
323
- <div class="dragging-placeholder" style=${F(this.placeholderSize)}></div>
366
+ <div class="dragging-placeholder" style=${m(this.placeholderSize)}></div>
324
367
  </slot>
325
368
  </div>`;
326
- }
327
- render() {
328
- const i = { "dragging-item--active": this.placeholderSlotIndex > -1 };
329
- return u`
369
+ }
370
+ render() {
371
+ let e = { "dragging-item--active": this.placeholderSlotIndex > -1 };
372
+ return a`
330
373
  <div class="c2-reorder-list-container" @mousedown=${this.handleMouseDown}>${this.renderSlots()}</div>
331
- <div class="dragging-item ${f(i)}">
374
+ <div class="dragging-item ${p(e)}">
332
375
  <slot name="dragging-item"></slot>
333
376
  </div>
334
377
  `;
335
- }
336
- handleMouseDown(i) {
337
- const t = this.getSlottedTargetIndex(i);
338
- if (t == -1)
339
- return;
340
- i.composedPath()[t].getAttribute("slot") && (this.hostBoundingClientRect = this.getBoundingClientRect(), this.pickupPosition = this.getPointerPosition(i), document.addEventListener("mousemove", this.handleMouseMove, { passive: !0 }), document.addEventListener("mouseup", this.handleMouseUp, { passive: !0 }));
341
- }
342
- getItemIndexFromPointerPosition(i) {
343
- return this.itemPositions.findIndex((s) => {
344
- const o = s.x + 5, r = s.y + 5, n = s.width - 5, l = s.height - 5;
345
- return o < i.pageX && r < i.pageY && o + n > i.pageX && r + l > i.pageY;
346
- });
347
- }
348
- dispatchChangeEvent() {
349
- const i = this.getChildItems().map((t) => parseInt(t.getAttribute("slot")));
350
- this.dispatchEvent(
351
- new CustomEvent("change", {
352
- bubbles: !0,
353
- cancelable: !0,
354
- detail: i
355
- })
356
- );
357
- }
358
- stopDrag() {
359
- document.removeEventListener("mousemove", this.handleMouseMove), document.removeEventListener("mouseup", this.handleMouseUp), this.scrollableParent && this.scrollableParent.removeEventListener("scroll", this.handleScroll), this.pickupPosition = { x: 0, y: 0 }, this.itemPositions = [], this.hasStartedDragging = !1, this.placeholderSlotIndex = -1, this.scrollableParent = null, this.cacheMouseEvent = null;
360
- }
361
- getPointerPosition(i) {
362
- var s, o;
363
- const t = i.pageX - (((s = this.hostBoundingClientRect) == null ? void 0 : s.left) || 0), e = i.pageY - (((o = this.hostBoundingClientRect) == null ? void 0 : o.top) || 0);
364
- return { x: t, y: e };
365
- }
366
- observeChildList() {
367
- this.childListObserver = new MutationObserver(() => {
368
- this.updateSlotMapping();
369
- }), this.childListObserver.observe(this, { subtree: !1, childList: !0 });
370
- }
371
- async firstUpdated() {
372
- this.updateSlotMapping();
373
- }
374
- updated(i) {
375
- i.has("placeholderSlotIndex") && (this.skipAnimation = !1, this.startScrollingIfNecessary(), this.updateItemPositions()), super.updated(i);
376
- }
377
- startScrollingIfNecessary() {
378
- if (this.placeholderElement && this.scrollableParent) {
379
- const i = this.placeholderElement.getBoundingClientRect(), t = i.top;
380
- t < this.scrollableParentRect.top ? this.startScrollInterval("up") : t + i.height > this.scrollableParentRect.bottom ? this.startScrollInterval("down") : this.stopScrolling();
381
- }
382
- }
383
- stopScrolling() {
384
- window.cancelAnimationFrame(this.scrollingTimer);
385
- }
386
- updateSlotMapping() {
387
- const i = this.getChildItems();
388
- let t = /* @__PURE__ */ new Map(), e = 0, s = !1;
389
- for (const n of i) {
390
- const l = n.getAttribute("slot");
391
- l && (Number.isNaN(parseInt(l)) ? l === "dragging-item" && t.set(e, this.currentDraggingSlotIndex) : t.set(e, parseInt(l))), e++;
392
- }
393
- const o = Array.from(t.keys()).sort(
394
- (n, l) => t.get(n) - t.get(l)
395
- );
396
- o.forEach((n, l) => {
397
- t.get(n), i[n].setAttribute("slot", l.toString()), s = !0;
398
- });
399
- let r = o.length;
400
- for (const n of i)
401
- n.getAttribute("slot") || (n.setAttribute("slot", r.toString()), r++, s = !0);
402
- s && (this.requestUpdate(), this.dispatchChangeEvent());
403
- }
404
- updateItemPositions() {
405
- this.itemPositions = [], this.listItemElements.forEach((i) => {
406
- this.itemPositions.push(i.getBoundingClientRect());
407
- });
408
- }
409
- applyTransform(i) {
410
- const t = this.getPointerPosition(i), e = t.x - this.pickupPosition.x, s = t.y - this.pickupPosition.y;
411
- this.draggingElement.style.transform = this.getTransform(e, s);
412
- }
413
- getTransform(i, t) {
414
- return `translate3d(${Math.round(i)}px, ${Math.round(t)}px, 0)`;
415
- }
416
- getSlottedTargetIndex(i) {
417
- return i.composedPath().findIndex((t) => t instanceof Element && !!t.getAttribute("slot"));
418
- }
419
- getChildItems() {
420
- const i = [];
421
- for (const t of this.children) {
422
- const e = t.getAttribute("slot");
423
- (e === "dragging-item" || !e || !Number.isNaN(parseInt(e))) && i.push(t);
424
- }
425
- return i;
426
- }
427
- getSortChildrenBySlot() {
428
- return this.getChildItems().filter((i) => i !== this.currentDraggingItem).sort((i, t) => {
429
- const e = i.getAttribute("slot"), s = t.getAttribute("slot");
430
- return parseInt(e || "") - parseInt(s || "");
431
- });
432
- }
433
- getNearestScrollableParent(i = this) {
434
- return i == null ? null : i.scrollHeight > i.clientHeight ? i : this.getNearestScrollableParent(i.parentNode);
435
- }
436
- };
437
- a.styles = $(q);
438
- h([
439
- S(".dragging-item")
440
- ], a.prototype, "draggingElement", 2);
441
- h([
442
- S(".placeholder")
443
- ], a.prototype, "placeholderElement", 2);
444
- h([
445
- S(".c2-reorder-list-container")
446
- ], a.prototype, "containerElement", 2);
447
- h([
448
- T(".list-item")
449
- ], a.prototype, "listItemElements", 2);
450
- h([
451
- y({ type: Boolean, reflect: !0 })
452
- ], a.prototype, "editable", 2);
453
- h([
454
- y({ type: Number })
455
- ], a.prototype, "dragStartThreshold", 2);
456
- h([
457
- y({ type: Boolean })
458
- ], a.prototype, "autoScrollDisabled", 2);
459
- h([
460
- O()
461
- ], a.prototype, "placeholderSlotIndex", 2);
462
- h([
463
- O()
464
- ], a.prototype, "placeholderSize", 2);
465
- h([
466
- B({ passive: !0 })
467
- ], a.prototype, "handleMouseDown", 1);
468
- a = h([
469
- L("c2-reorder-list")
470
- ], a);
471
- export {
472
- a as ReorderList
378
+ }
379
+ handleMouseDown(e) {
380
+ let t = this.getSlottedTargetIndex(e);
381
+ if (t == -1) return;
382
+ let n = e.composedPath()[t];
383
+ n.getAttribute("slot") && !this.isFixedItem(n) && (this.hostBoundingClientRect = this.getBoundingClientRect(), this.pickupPosition = this.getPointerPosition(e), document.addEventListener("mousemove", this.handleMouseMove, { passive: !0 }), document.addEventListener("mouseup", this.handleMouseUp, { passive: !0 }));
384
+ }
385
+ isFixedItem(e) {
386
+ return !!e && !!e.dataset.fixed;
387
+ }
388
+ getItemIndexFromPointerPosition(e) {
389
+ return this.itemPositions.findIndex((t) => {
390
+ if (t.isFixed) return !1;
391
+ let n = t.x + 5, r = t.y + 5, i = t.width - 5, a = t.height - 5;
392
+ return n < e.pageX && r < e.pageY && n + i > e.pageX && r + a > e.pageY;
393
+ });
394
+ }
395
+ dispatchChangeEvent() {
396
+ let e = this.getChildItems().map((e) => parseInt(e.getAttribute("slot")));
397
+ this.dispatchEvent(new CustomEvent("change", {
398
+ bubbles: !0,
399
+ cancelable: !0,
400
+ detail: e
401
+ }));
402
+ }
403
+ stopDrag() {
404
+ document.removeEventListener("mousemove", this.handleMouseMove), document.removeEventListener("mouseup", this.handleMouseUp), this.scrollableParent && this.scrollableParent.removeEventListener("scroll", this.handleScroll), this.pickupPosition = {
405
+ x: 0,
406
+ y: 0
407
+ }, this.itemPositions = [], this.hasStartedDragging = !1, this.placeholderSlotIndex = -1, this.scrollableParent = null, this.cacheMouseEvent = null;
408
+ }
409
+ getPointerPosition(e) {
410
+ return {
411
+ x: e.pageX - (this.hostBoundingClientRect?.left || 0),
412
+ y: e.pageY - (this.hostBoundingClientRect?.top || 0)
413
+ };
414
+ }
415
+ observeChildList() {
416
+ this.childListObserver = new MutationObserver(() => {
417
+ this.updateSlotMapping();
418
+ }), this.childListObserver.observe(this, {
419
+ subtree: !1,
420
+ childList: !0
421
+ });
422
+ }
423
+ async firstUpdated() {
424
+ this.updateSlotMapping();
425
+ }
426
+ updated(e) {
427
+ e.has("placeholderSlotIndex") && (this.skipAnimation = !1, this.startScrollingIfNecessary(), this.updateItemPositions()), super.updated(e);
428
+ }
429
+ startScrollingIfNecessary() {
430
+ if (this.placeholderElement && this.scrollableParent) {
431
+ let e = this.placeholderElement.getBoundingClientRect(), t = e.top;
432
+ t < this.scrollableParentRect.top ? this.startScrollInterval("up") : t + e.height > this.scrollableParentRect.bottom ? this.startScrollInterval("down") : this.stopScrolling();
433
+ }
434
+ }
435
+ stopScrolling() {
436
+ window.cancelAnimationFrame(this.scrollingTimer);
437
+ }
438
+ updateSlotMapping() {
439
+ let e = this.getChildItems(), t = /* @__PURE__ */ new Map(), n = 0, r = !1;
440
+ for (let r of e) {
441
+ let e = r.getAttribute("slot");
442
+ e && (Number.isNaN(parseInt(e)) ? e === "dragging-item" && t.set(n, this.currentDraggingSlotIndex) : t.set(n, parseInt(e))), n++;
443
+ }
444
+ let i = Array.from(t.keys()).sort((e, n) => t.get(e) - t.get(n));
445
+ i.forEach((t, n) => {
446
+ e[t].setAttribute("slot", n.toString()), r = !0;
447
+ });
448
+ let a = i.length;
449
+ for (let t of e) t.getAttribute("slot") || (t.setAttribute("slot", a.toString()), a++, r = !0);
450
+ r && (this.requestUpdate(), this.dispatchChangeEvent());
451
+ }
452
+ updateItemPositions() {
453
+ this.itemPositions = [], this.listItemElements.forEach((e) => {
454
+ let t = e.querySelector("slot");
455
+ this.itemPositions.push({
456
+ ...j(e),
457
+ isFixed: t ? this.isFixedItem(t.assignedNodes()[0]) : !1
458
+ });
459
+ }), console.log(this.itemPositions);
460
+ }
461
+ applyTransform(e) {
462
+ let t = this.getPointerPosition(e), n = t.x - this.pickupPosition.x, r = t.y - this.pickupPosition.y;
463
+ this.draggingElement.style.transform = this.getTransform(n, r);
464
+ }
465
+ getTransform(e, t) {
466
+ return `translate3d(${Math.round(e)}px, ${Math.round(t)}px, 0)`;
467
+ }
468
+ getSlottedTargetIndex(e) {
469
+ return e.composedPath().findIndex((e) => e instanceof Element && !!e.getAttribute("slot"));
470
+ }
471
+ getChildItems() {
472
+ let e = [];
473
+ for (let t of this.children) {
474
+ let n = t.getAttribute("slot");
475
+ (n === "dragging-item" || !n || !Number.isNaN(parseInt(n))) && e.push(t);
476
+ }
477
+ return e;
478
+ }
479
+ getSortChildrenBySlot() {
480
+ return this.getChildItems().filter((e) => e !== this.currentDraggingItem).sort((e, t) => {
481
+ let n = e.getAttribute("slot"), r = t.getAttribute("slot");
482
+ return parseInt(n || "") - parseInt(r || "");
483
+ });
484
+ }
485
+ getNearestScrollableParent(e = this) {
486
+ return e == null ? null : e.scrollHeight > e.clientHeight ? e : this.getNearestScrollableParent(e.parentNode);
487
+ }
488
+ static {
489
+ this.styles = o(O);
490
+ }
473
491
  };
492
+ k([u(".dragging-item")], A.prototype, "draggingElement", void 0), k([u(".placeholder")], A.prototype, "placeholderElement", void 0), k([u(".c2-reorder-list-container")], A.prototype, "containerElement", void 0), k([d(".list-item")], A.prototype, "listItemElements", void 0), k([l({
493
+ type: Boolean,
494
+ reflect: !0
495
+ })], A.prototype, "editable", void 0), k([l({ type: Number })], A.prototype, "dragStartThreshold", void 0), k([l({ type: Boolean })], A.prototype, "autoScrollDisabled", void 0), k([f()], A.prototype, "placeholderSlotIndex", void 0), k([f()], A.prototype, "placeholderSize", void 0), k([c({ passive: !0 })], A.prototype, "handleMouseDown", null), A = k([s("c2-reorder-list")], A);
496
+ function j(e) {
497
+ let t = e.getBoundingClientRect();
498
+ return {
499
+ top: t.top,
500
+ right: t.right,
501
+ bottom: t.bottom,
502
+ left: t.left,
503
+ width: t.width,
504
+ height: t.height,
505
+ x: t.x,
506
+ y: t.y
507
+ };
508
+ }
509
+ //#endregion
510
+ export { A as ReorderList, j as getMutableClientRect };
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "@c2n/reorder-list",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "type": "module",
5
5
  "main": "dist/reorder-list.js",
6
6
  "exports": {
7
- ".": "./dist/reorder-list.js"
7
+ ".": {
8
+ "default": "./dist/reorder-list.js",
9
+ "types": "./types/src/reorder-list.d.ts"
10
+ },
11
+ "./custom-elements.json": "./custom-elements.json"
8
12
  },
9
- "types": "types/src/index.d.ts",
10
13
  "files": [
11
14
  "dist",
12
15
  "types"
@@ -26,87 +29,31 @@
26
29
  "url": "https://github.com/code2nguyen/web-components.git"
27
30
  },
28
31
  "scripts": {
29
- "lint": "npm run lint:lit-analyzer && npm run lint:eslint",
30
- "lint:eslint": "eslint 'src/**/*.ts'",
31
- "lint:lit-analyzer": "lit-analyzer",
32
32
  "dev": "vite",
33
- "build": "tsc && vite build"
33
+ "build": "wireit",
34
+ "type-check": "wireit"
35
+ },
36
+ "wireit": {
37
+ "type-check": {
38
+ "dependencies": [
39
+ "../../core:build"
40
+ ],
41
+ "command": "tsc -p tsconfig.lib.json --composite false"
42
+ },
43
+ "build": {
44
+ "dependencies": [
45
+ "type-check"
46
+ ],
47
+ "command": "vite build"
48
+ }
34
49
  },
35
50
  "dependencies": {
36
- "@c2n/wc-utils": "0.0.4",
37
- "@lit-labs/motion": "1.0.3",
38
- "lit": "2.3.0"
51
+ "@c2n/core": "0.0.6",
52
+ "@lit-labs/motion": "1.1.0",
53
+ "lit": "3.3.3"
39
54
  },
40
55
  "devDependencies": {
41
- "@typescript-eslint/eslint-plugin": "5.33.1",
42
- "@typescript-eslint/parser": "5.33.1",
43
- "eslint": "8.22.0",
44
- "lit-analyzer": "1.2.1",
45
- "prettier": "2.7.1",
46
- "typescript": "4.7.4",
47
- "vite": "3.0.8"
48
- },
49
- "prettier": {
50
- "singleQuote": true,
51
- "printWidth": 160,
52
- "tabWidth": 2,
53
- "semi": false
54
- },
55
- "eslintConfig": {
56
- "root": true,
57
- "extends": [
58
- "eslint:recommended",
59
- "plugin:@typescript-eslint/eslint-recommended",
60
- "plugin:@typescript-eslint/recommended"
61
- ],
62
- "parser": "@typescript-eslint/parser",
63
- "parserOptions": {
64
- "ecmaVersion": 2020,
65
- "sourceType": "module"
66
- },
67
- "plugins": [
68
- "@typescript-eslint"
69
- ],
70
- "env": {
71
- "browser": true
72
- },
73
- "rules": {
74
- "no-prototype-builtins": "off",
75
- "@typescript-eslint/ban-types": "off",
76
- "@typescript-eslint/explicit-function-return-type": "off",
77
- "@typescript-eslint/explicit-module-boundary-types": "off",
78
- "@typescript-eslint/no-explicit-any": "error",
79
- "@typescript-eslint/no-empty-function": "off",
80
- "@typescript-eslint/no-non-null-assertion": "off",
81
- "@typescript-eslint/no-unused-vars": [
82
- "warn",
83
- {
84
- "argsIgnorePattern": "^_"
85
- }
86
- ]
87
- },
88
- "overrides": [
89
- {
90
- "files": [
91
- "rollup.config.js",
92
- "web-test-runner.config.js"
93
- ],
94
- "env": {
95
- "node": true
96
- }
97
- },
98
- {
99
- "files": [
100
- "*_test.ts",
101
- "**/custom_typings/*.ts",
102
- "packages/labs/ssr/src/test/integration/tests/**",
103
- "packages/labs/ssr/src/lib/util/parse5-utils.ts"
104
- ],
105
- "rules": {
106
- "@typescript-eslint/no-explicit-any": "off"
107
- }
108
- }
109
- ]
56
+ "@c2n/config": "*"
110
57
  },
111
- "gitHead": "a5ffa12eeca6664d4e9f175053f6b86d49eca1a1"
58
+ "gitHead": "2921054bc75299da66dad11c1e374246ff88a51e"
112
59
  }
@@ -1,4 +1,4 @@
1
- import { LitElement, PropertyValueMap, TemplateResult } from 'lit';
1
+ import { LitElement, type PropertyValueMap, type TemplateResult } from 'lit';
2
2
  export interface Point {
3
3
  x: number;
4
4
  y: number;
@@ -29,13 +29,13 @@ export declare class ReorderList extends LitElement {
29
29
  private hasStartedDragging;
30
30
  private scrollingTimer;
31
31
  private cacheMouseEvent;
32
- /** Cached positions of scrollable parent elements. */
33
32
  connectedCallback(): void;
34
33
  disconnectedCallback(): void;
35
- renderSlots(): TemplateResult<1 | 2>[];
34
+ renderSlots(): TemplateResult[];
36
35
  private createPlaceHolder;
37
36
  render(): TemplateResult<1>;
38
37
  private handleMouseDown;
38
+ private isFixedItem;
39
39
  handleMouseMove: (event: MouseEvent) => Promise<void>;
40
40
  handleScroll: () => void;
41
41
  private getItemIndexFromPointerPosition;
@@ -64,4 +64,5 @@ declare global {
64
64
  'c2-reorder-list': ReorderList;
65
65
  }
66
66
  }
67
+ export declare function getMutableClientRect(element: Element): DOMRect;
67
68
  //# sourceMappingURL=reorder-list.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"reorder-list.d.ts","sourceRoot":"","sources":["../../src/reorder-list.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,UAAU,EAAE,gBAAgB,EAAE,cAAc,EAAa,MAAM,KAAK,CAAA;AAMnF,MAAM,WAAW,KAAK;IACpB,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;CACV;AACD,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CACd;AAED,qBACa,WAAY,SAAQ,UAAU;IAChB,SAAS,CAAC,eAAe,EAAG,WAAW,CAAA;IACzC,SAAS,CAAC,kBAAkB,EAAG,WAAW,CAAA;IAC5B,SAAS,CAAC,gBAAgB,EAAG,WAAW,CAAA;IACrD,SAAS,CAAC,gBAAgB,EAAG,UAAU,CAAC,cAAc,CAAC,CAAA;IAEnC,QAAQ,UAAQ;IAChC,kBAAkB,SAAK;IACtB,kBAAkB,UAAQ;IAGvD,OAAO,CAAC,oBAAoB,CAAK;IAGjC,OAAO,CAAC,eAAe,CAAkC;IAEzD,OAAO,CAAC,iBAAiB,CAAgC;IACzD,OAAO,CAAC,sBAAsB,CAAuB;IACrD,OAAO,CAAC,gBAAgB,CAA2B;IACnD,OAAO,CAAC,oBAAoB,CAAiC;IAC7D,OAAO,CAAC,cAAc,CAAwB;IAC9C,OAAO,CAAC,aAAa,CAAgB;IAErC,OAAO,CAAC,mBAAmB,CAAuB;IAClD,OAAO,CAAC,wBAAwB,CAAK;IAErC,OAAO,CAAC,aAAa,CAAQ;IAC7B,OAAO,CAAC,kBAAkB,CAAQ;IAClC,OAAO,CAAC,cAAc,CAAI;IAC1B,OAAO,CAAC,eAAe,CAAgC;IACvD,sDAAsD;IAG7C,iBAAiB,IAAI,IAAI;IAOzB,oBAAoB,IAAI,IAAI;IAQrC,WAAW;IAiCX,OAAO,CAAC,iBAAiB;IAQhB,MAAM;IAWf,OAAO,CAAC,eAAe;IAcvB,eAAe,UAAiB,UAAU,mBA+CzC;IAED,YAAY,aAcX;IAED,OAAO,CAAC,+BAA+B;IAYvC,aAAa,aAkBZ;IAED,OAAO,CAAC,mBAAmB;IAa3B,OAAO,CAAC,QAAQ;IAahB,OAAO,CAAC,kBAAkB;IAM1B,OAAO,CAAC,gBAAgB;cAOC,YAAY;cAKlB,OAAO,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,GAAG,IAAI;IASvG,OAAO,CAAC,yBAAyB;IAcjC,OAAO,CAAC,mBAAmB,CAQ1B;IAED,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,iBAAiB;IAyCzB,OAAO,CAAC,mBAAmB;IAO3B,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,aAAa;IAWrB,OAAO,CAAC,qBAAqB;IAU7B,OAAO,CAAC,0BAA0B;IAWlC,OAAgB,MAAM,0BAAoB;CAC3C;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,iBAAiB,EAAE,WAAW,CAAA;KAC/B;CACF"}
1
+ {"version":3,"file":"reorder-list.d.ts","sourceRoot":"","sources":["../../src/reorder-list.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,UAAU,EAAE,KAAK,gBAAgB,EAAE,KAAK,cAAc,EAAa,MAAM,KAAK,CAAA;AAM7F,MAAM,WAAW,KAAK;IACpB,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;CACV;AACD,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CACd;AAED,qBACa,WAAY,SAAQ,UAAU;IAChB,SAAS,CAAC,eAAe,EAAG,WAAW,CAAA;IACzC,SAAS,CAAC,kBAAkB,EAAG,WAAW,CAAA;IAC5B,SAAS,CAAC,gBAAgB,EAAG,WAAW,CAAA;IACrD,SAAS,CAAC,gBAAgB,EAAG,UAAU,CAAC,cAAc,CAAC,CAAA;IAEnC,QAAQ,UAAQ;IAChC,kBAAkB,SAAK;IACtB,kBAAkB,UAAQ;IAGvD,OAAO,CAAC,oBAAoB,CAAK;IAGjC,OAAO,CAAC,eAAe,CAAkC;IAEzD,OAAO,CAAC,iBAAiB,CAAgC;IACzD,OAAO,CAAC,sBAAsB,CAAuB;IACrD,OAAO,CAAC,gBAAgB,CAA2B;IACnD,OAAO,CAAC,oBAAoB,CAAiC;IAC7D,OAAO,CAAC,cAAc,CAAwB;IAC9C,OAAO,CAAC,aAAa,CAA6C;IAElE,OAAO,CAAC,mBAAmB,CAAuB;IAClD,OAAO,CAAC,wBAAwB,CAAK;IAErC,OAAO,CAAC,aAAa,CAAQ;IAC7B,OAAO,CAAC,kBAAkB,CAAQ;IAClC,OAAO,CAAC,cAAc,CAAI;IAC1B,OAAO,CAAC,eAAe,CAAgC;IAE9C,iBAAiB,IAAI,IAAI;IAMzB,oBAAoB,IAAI,IAAI;IAQrC,WAAW;IAiCX,OAAO,CAAC,iBAAiB;IAQhB,MAAM;IAWf,OAAO,CAAC,eAAe;IAcvB,OAAO,CAAC,WAAW;IAInB,eAAe,GAAU,OAAO,UAAU,mBA+CzC;IAED,YAAY,aAWX;IAED,OAAO,CAAC,+BAA+B;IAavC,aAAa,aAkBZ;IAED,OAAO,CAAC,mBAAmB;IAa3B,OAAO,CAAC,QAAQ;IAahB,OAAO,CAAC,kBAAkB;IAM1B,OAAO,CAAC,gBAAgB;cAOC,YAAY;cAKlB,OAAO,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,GAAG,IAAI;IASvG,OAAO,CAAC,yBAAyB;IAcjC,OAAO,CAAC,mBAAmB,CAQ1B;IAED,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,iBAAiB;IAwCzB,OAAO,CAAC,mBAAmB;IAY3B,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,aAAa;IAWrB,OAAO,CAAC,qBAAqB;IAU7B,OAAO,CAAC,0BAA0B;IAWlC,OAAgB,MAAM,0BAAoB;CAC3C;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,iBAAiB,EAAE,WAAW,CAAA;KAC/B;CACF;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAY9D"}
@@ -1,2 +0,0 @@
1
- export * from './reorder-list';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA"}