@lilydesignsystem/vue-motion-picker 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +122 -156
- package/package.json +4 -1
package/dist/index.js
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
import { Fragment as e, createElementBlock as t, createElementVNode as n,
|
|
1
|
+
import { Fragment as e, createElementBlock as t, createElementVNode as n, createVNode as r, defineComponent as i, guardReactiveProps as a, nextTick as o, normalizeClass as s, normalizeProps as c, onBeforeUnmount as l, onMounted as u, openBlock as d, ref as f, renderList as p, renderSlot as m, toDisplayString as h, unref as g, watch as _, withCtx as v } from "vue";
|
|
2
|
+
import { IconButton as y, Listbox as b } from "@lilydesignsystem/vue-headless";
|
|
2
3
|
//#region lily-design-system-vue-motion-picker/MotionPicker.vue?vue&type=script&setup=true&lang.ts
|
|
3
|
-
var
|
|
4
|
-
"aria-label",
|
|
5
|
-
"aria-activedescendant",
|
|
6
|
-
"hidden"
|
|
7
|
-
], y = [
|
|
4
|
+
var x = ["name", "value"], S = [
|
|
8
5
|
"id",
|
|
9
6
|
"aria-selected",
|
|
10
7
|
"data-active",
|
|
11
8
|
"onClick"
|
|
12
9
|
];
|
|
13
|
-
function
|
|
10
|
+
function C(e) {
|
|
14
11
|
return e.split("-").map((e) => e.charAt(0).toUpperCase() + e.slice(1)).join(" ");
|
|
15
12
|
}
|
|
16
|
-
function
|
|
13
|
+
function w() {
|
|
17
14
|
if (typeof window > "u" || typeof window.matchMedia != "function") return !1;
|
|
18
15
|
try {
|
|
19
16
|
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
@@ -21,13 +18,13 @@ function x() {
|
|
|
21
18
|
return !1;
|
|
22
19
|
}
|
|
23
20
|
}
|
|
24
|
-
var
|
|
25
|
-
function
|
|
26
|
-
return
|
|
21
|
+
var T = 0;
|
|
22
|
+
function E() {
|
|
23
|
+
return T += 1, `motion-picker-${T}`;
|
|
27
24
|
}
|
|
28
25
|
//#endregion
|
|
29
26
|
//#region lily-design-system-vue-motion-picker/MotionPicker.vue
|
|
30
|
-
var
|
|
27
|
+
var D = /* @__PURE__ */ i({
|
|
31
28
|
__name: "MotionPicker",
|
|
32
29
|
props: {
|
|
33
30
|
label: {},
|
|
@@ -41,192 +38,161 @@ var w = /* @__PURE__ */ r({
|
|
|
41
38
|
class: { default: "" }
|
|
42
39
|
},
|
|
43
40
|
emits: ["update:value", "change"],
|
|
44
|
-
setup(
|
|
45
|
-
let
|
|
46
|
-
function I(e) {
|
|
47
|
-
let t = w.motionLabels ?? {};
|
|
48
|
-
return e in t ? t[e] : b(e);
|
|
49
|
-
}
|
|
41
|
+
setup(i, { emit: T }) {
|
|
42
|
+
let D = i, O = T, k = E(), A = `${k}-list`, j = (e) => `${k}-option-${e}`, M = f(!1), N = f(-1), P = f(null), F = f(null), I = f(null);
|
|
50
43
|
function L(e) {
|
|
44
|
+
let t = D.motionLabels ?? {};
|
|
45
|
+
return e in t ? t[e] : C(e);
|
|
46
|
+
}
|
|
47
|
+
function R(e) {
|
|
51
48
|
if (!(typeof document > "u" || !e)) {
|
|
52
|
-
if ((
|
|
53
|
-
localStorage.setItem(
|
|
49
|
+
if ((D.target ?? document.documentElement).setAttribute("data-motion", e), D.storageKey) try {
|
|
50
|
+
localStorage.setItem(D.storageKey, e);
|
|
54
51
|
} catch {}
|
|
55
|
-
|
|
52
|
+
O("change", e);
|
|
56
53
|
}
|
|
57
54
|
}
|
|
58
|
-
let
|
|
59
|
-
function
|
|
60
|
-
|
|
55
|
+
let z = f(D.value ?? "");
|
|
56
|
+
function B(e) {
|
|
57
|
+
z.value = e, O("update:value", e);
|
|
61
58
|
}
|
|
62
|
-
|
|
63
|
-
e !== void 0 && e !==
|
|
64
|
-
}),
|
|
65
|
-
e && e !== t &&
|
|
59
|
+
_(() => D.value, (e) => {
|
|
60
|
+
e !== void 0 && e !== z.value && (z.value = e);
|
|
61
|
+
}), _(z, (e, t) => {
|
|
62
|
+
e && e !== t && R(e);
|
|
66
63
|
});
|
|
67
|
-
async function
|
|
68
|
-
let t =
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
async function V(e = !0) {
|
|
72
|
-
k.value && (k.value = !1, A.value = -1, e && (await a(), j.value?.focus({ preventScroll: !0 })));
|
|
64
|
+
async function V(e) {
|
|
65
|
+
let t = D.motions.indexOf(z.value);
|
|
66
|
+
N.value = D.motions.length === 0 ? -1 : e ?? (t >= 0 ? t : 0), M.value = !0, await o(), F.value?.el?.focus({ preventScroll: !0 });
|
|
73
67
|
}
|
|
74
|
-
function H(e) {
|
|
75
|
-
|
|
76
|
-
t && z(t), V();
|
|
68
|
+
async function H(e = !0) {
|
|
69
|
+
M.value && (M.value = !1, N.value = -1, e && (await o(), P.value?.el?.focus({ preventScroll: !0 })));
|
|
77
70
|
}
|
|
78
|
-
function U() {
|
|
79
|
-
|
|
71
|
+
function U(e) {
|
|
72
|
+
let t = D.motions[e];
|
|
73
|
+
t && B(t), H();
|
|
80
74
|
}
|
|
81
|
-
function W(
|
|
82
|
-
|
|
83
|
-
let t = Math.min(Math.max(A.value + e, 0), w.motions.length - 1);
|
|
84
|
-
A.value = t, U();
|
|
75
|
+
function W() {
|
|
76
|
+
N.value < 0 || !F.value?.el || document.getElementById(j(N.value))?.scrollIntoView?.({ block: "nearest" });
|
|
85
77
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
P
|
|
89
|
-
let r = n ? t : P, i = A.value < 0 ? 0 : A.value, a = n ? i + 1 : i;
|
|
90
|
-
for (let e = 0; e < w.motions.length; e++) {
|
|
91
|
-
let t = (a + e) % w.motions.length;
|
|
92
|
-
if (I(w.motions[t]).toLowerCase().startsWith(r)) {
|
|
93
|
-
A.value = t, U();
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
78
|
+
_(N, () => W());
|
|
79
|
+
function G() {
|
|
80
|
+
P.value?.el?.focus?.({ preventScroll: !0 }), H(!1);
|
|
97
81
|
}
|
|
98
82
|
function K() {
|
|
99
|
-
|
|
83
|
+
M.value ? H() : V();
|
|
100
84
|
}
|
|
101
85
|
function q(e) {
|
|
102
86
|
switch (e.key) {
|
|
103
87
|
case "ArrowDown":
|
|
104
88
|
case "Enter":
|
|
105
89
|
case " ":
|
|
106
|
-
e.preventDefault(), B();
|
|
107
|
-
break;
|
|
108
|
-
case "ArrowUp": e.preventDefault(), B(w.motions.length - 1);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
function J(e) {
|
|
112
|
-
switch (e.key) {
|
|
113
|
-
case "ArrowDown":
|
|
114
|
-
e.preventDefault(), W(1);
|
|
115
|
-
break;
|
|
116
|
-
case "ArrowUp":
|
|
117
|
-
e.preventDefault(), W(-1);
|
|
118
|
-
break;
|
|
119
|
-
case "Home":
|
|
120
|
-
e.preventDefault(), A.value = 0, U();
|
|
121
|
-
break;
|
|
122
|
-
case "End":
|
|
123
|
-
e.preventDefault(), A.value = w.motions.length - 1, U();
|
|
124
|
-
break;
|
|
125
|
-
case "Enter":
|
|
126
|
-
case " ":
|
|
127
|
-
e.preventDefault(), A.value >= 0 && H(A.value);
|
|
128
|
-
break;
|
|
129
|
-
case "Escape":
|
|
130
90
|
e.preventDefault(), V();
|
|
131
91
|
break;
|
|
132
|
-
case "
|
|
133
|
-
e.preventDefault(), W(-10);
|
|
134
|
-
break;
|
|
135
|
-
case "PageDown":
|
|
136
|
-
e.preventDefault(), W(10);
|
|
137
|
-
break;
|
|
138
|
-
case "Tab":
|
|
139
|
-
j.value?.focus?.({ preventScroll: !0 }), V(!1);
|
|
140
|
-
break;
|
|
141
|
-
default: e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey && G(e.key);
|
|
92
|
+
case "ArrowUp": e.preventDefault(), V(D.motions.length - 1);
|
|
142
93
|
}
|
|
143
94
|
}
|
|
144
|
-
function
|
|
95
|
+
function J(e) {
|
|
145
96
|
let t = e.relatedTarget;
|
|
146
|
-
t &&
|
|
97
|
+
t && I.value?.contains(t) || H(!1);
|
|
147
98
|
}
|
|
148
|
-
function
|
|
149
|
-
if (!
|
|
99
|
+
function Y(e) {
|
|
100
|
+
if (!M.value) return;
|
|
150
101
|
let t = e.target;
|
|
151
|
-
t &&
|
|
102
|
+
t && I.value && !I.value.contains(t) && H(!1);
|
|
152
103
|
}
|
|
153
|
-
return
|
|
154
|
-
document.addEventListener("click",
|
|
155
|
-
let e =
|
|
156
|
-
if (!e &&
|
|
157
|
-
e = localStorage.getItem(
|
|
104
|
+
return u(() => {
|
|
105
|
+
document.addEventListener("click", Y);
|
|
106
|
+
let e = z.value;
|
|
107
|
+
if (!e && D.storageKey) try {
|
|
108
|
+
e = localStorage.getItem(D.storageKey) ?? "";
|
|
158
109
|
} catch {}
|
|
159
110
|
if (!e) {
|
|
160
|
-
let t =
|
|
161
|
-
e =
|
|
111
|
+
let t = w() ? "reduce" : "no-preference";
|
|
112
|
+
e = D.defaultValue ?? (D.motions.includes(t) ? t : void 0) ?? D.motions[0] ?? "";
|
|
162
113
|
}
|
|
163
|
-
if (e && e !==
|
|
164
|
-
|
|
114
|
+
if (e && e !== z.value) {
|
|
115
|
+
z.value = e, O("update:value", e);
|
|
165
116
|
return;
|
|
166
117
|
}
|
|
167
|
-
e &&
|
|
168
|
-
}),
|
|
169
|
-
document.removeEventListener("click",
|
|
170
|
-
}), (
|
|
118
|
+
e && R(e);
|
|
119
|
+
}), l(() => {
|
|
120
|
+
document.removeEventListener("click", Y);
|
|
121
|
+
}), (o, l) => (d(), t("div", {
|
|
171
122
|
ref_key: "rootEl",
|
|
172
|
-
ref:
|
|
173
|
-
class:
|
|
174
|
-
onFocusout:
|
|
123
|
+
ref: I,
|
|
124
|
+
class: s(`motion-picker ${D.class}`.trim()),
|
|
125
|
+
onFocusout: J
|
|
175
126
|
}, [
|
|
176
127
|
n("input", {
|
|
177
128
|
type: "hidden",
|
|
178
|
-
name:
|
|
179
|
-
value:
|
|
180
|
-
}, null, 8,
|
|
181
|
-
|
|
129
|
+
name: i.name,
|
|
130
|
+
value: z.value
|
|
131
|
+
}, null, 8, x),
|
|
132
|
+
r(g(y), {
|
|
182
133
|
ref_key: "buttonEl",
|
|
183
|
-
ref:
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
"aria-label": r.label,
|
|
134
|
+
ref: P,
|
|
135
|
+
baseClass: "motion-picker-button",
|
|
136
|
+
label: i.label,
|
|
187
137
|
"aria-haspopup": "listbox",
|
|
188
|
-
"aria-expanded":
|
|
189
|
-
"aria-controls":
|
|
138
|
+
"aria-expanded": M.value ? "true" : "false",
|
|
139
|
+
"aria-controls": A,
|
|
190
140
|
onClick: K,
|
|
191
141
|
onKeydown: q
|
|
192
|
-
},
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
142
|
+
}, {
|
|
143
|
+
default: v(() => [m(o.$slots, "default", c(a({
|
|
144
|
+
value: z.value,
|
|
145
|
+
open: M.value,
|
|
146
|
+
labelFor: L
|
|
147
|
+
})), () => [l[2] ||= n("svg", {
|
|
148
|
+
class: "motion-picker-icon",
|
|
149
|
+
viewBox: "0 0 16 16",
|
|
150
|
+
width: "1.05rem",
|
|
151
|
+
height: "1.05rem",
|
|
152
|
+
"aria-hidden": "true",
|
|
153
|
+
fill: "none",
|
|
154
|
+
stroke: "currentColor",
|
|
155
|
+
"stroke-width": "1.6",
|
|
156
|
+
"stroke-linecap": "round",
|
|
157
|
+
"stroke-linejoin": "round"
|
|
158
|
+
}, [n("path", { d: "M5 3v10M11 3v10" })], -1)])]),
|
|
159
|
+
_: 3
|
|
160
|
+
}, 8, ["label", "aria-expanded"]),
|
|
161
|
+
r(g(b), {
|
|
209
162
|
ref_key: "listEl",
|
|
210
|
-
ref:
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
"
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
163
|
+
ref: F,
|
|
164
|
+
as: "ul",
|
|
165
|
+
baseClass: "motion-picker-list",
|
|
166
|
+
id: A,
|
|
167
|
+
label: i.label,
|
|
168
|
+
navigation: "active-descendant",
|
|
169
|
+
clamp: "",
|
|
170
|
+
typeahead: "",
|
|
171
|
+
pageSize: 10,
|
|
172
|
+
activeIndex: N.value,
|
|
173
|
+
"onUpdate:activeIndex": l[0] ||= (e) => N.value = e,
|
|
174
|
+
hidden: !M.value || void 0,
|
|
175
|
+
onActivate: U,
|
|
176
|
+
onEscape: l[1] ||= () => H(),
|
|
177
|
+
onTabOut: G
|
|
178
|
+
}, {
|
|
179
|
+
default: v(() => [(d(!0), t(e, null, p(i.motions, (e, n) => (d(), t("li", {
|
|
180
|
+
key: e,
|
|
181
|
+
class: "motion-picker-option",
|
|
182
|
+
id: j(n),
|
|
183
|
+
role: "option",
|
|
184
|
+
"aria-selected": e === z.value ? "true" : "false",
|
|
185
|
+
"data-active": n === N.value ? "" : void 0,
|
|
186
|
+
onClick: (e) => U(n)
|
|
187
|
+
}, h(L(e)), 9, S))), 128))]),
|
|
188
|
+
_: 1
|
|
189
|
+
}, 8, [
|
|
190
|
+
"label",
|
|
191
|
+
"activeIndex",
|
|
192
|
+
"hidden"
|
|
193
|
+
])
|
|
228
194
|
], 34));
|
|
229
195
|
}
|
|
230
196
|
});
|
|
231
197
|
//#endregion
|
|
232
|
-
export {
|
|
198
|
+
export { D as MotionPicker, D as default, C as motionName, E as nextMotionPickerId, w as prefersReducedMotion };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lilydesignsystem/vue-motion-picker",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": "=26"
|
|
6
6
|
},
|
|
@@ -23,6 +23,9 @@
|
|
|
23
23
|
"scripts": {
|
|
24
24
|
"prepublishOnly": "cd .. && npm run build"
|
|
25
25
|
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@lilydesignsystem/vue-headless": "^0.1.0"
|
|
28
|
+
},
|
|
26
29
|
"peerDependencies": {
|
|
27
30
|
"vue": "^3.0.0"
|
|
28
31
|
},
|