@stachelock/ui 0.6.17 → 0.7.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/composables/index.js +44 -40
- package/dist/index.js +2471 -1973
- package/dist/src/components/layouts/NestedNavigationItem.d.ts +112 -0
- package/dist/src/components/layouts/NestedSidebar.d.ts +162 -0
- package/dist/src/components/layouts/index.d.ts +2 -0
- package/dist/src/composables/index.d.ts +1 -0
- package/dist/src/composables/useSidebarNavigation.d.ts +129 -0
- package/dist/src/views/layouts/index.d.ts +1 -0
- package/dist/style.css +1 -1
- package/dist/useSidebarNavigation-DbXCVGYg.js +291 -0
- package/package.json +3 -2
- package/dist/useCollectionEditor-BYyoAT0U.js +0 -121
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { ref as h, computed as O, watch as q } from "vue";
|
|
2
|
+
var z = /* @__PURE__ */ ((e) => (e.New = "new", e.Pending = "pending", e.Saved = "saved", e.Deleted = "deleted", e))(z || {});
|
|
3
|
+
let M;
|
|
4
|
+
const G = new Uint8Array(16);
|
|
5
|
+
function L() {
|
|
6
|
+
if (!M && (M = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !M))
|
|
7
|
+
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
8
|
+
return M(G);
|
|
9
|
+
}
|
|
10
|
+
const r = [];
|
|
11
|
+
for (let e = 0; e < 256; ++e)
|
|
12
|
+
r.push((e + 256).toString(16).slice(1));
|
|
13
|
+
function Q(e, t = 0) {
|
|
14
|
+
return r[e[t + 0]] + r[e[t + 1]] + r[e[t + 2]] + r[e[t + 3]] + "-" + r[e[t + 4]] + r[e[t + 5]] + "-" + r[e[t + 6]] + r[e[t + 7]] + "-" + r[e[t + 8]] + r[e[t + 9]] + "-" + r[e[t + 10]] + r[e[t + 11]] + r[e[t + 12]] + r[e[t + 13]] + r[e[t + 14]] + r[e[t + 15]];
|
|
15
|
+
}
|
|
16
|
+
const X = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), j = {
|
|
17
|
+
randomUUID: X
|
|
18
|
+
};
|
|
19
|
+
function H(e, t, v) {
|
|
20
|
+
if (j.randomUUID && !e)
|
|
21
|
+
return j.randomUUID();
|
|
22
|
+
e = e || {};
|
|
23
|
+
const l = e.random || (e.rng || L)();
|
|
24
|
+
return l[6] = l[6] & 15 | 64, l[8] = l[8] & 63 | 128, Q(l);
|
|
25
|
+
}
|
|
26
|
+
function Z(e, t) {
|
|
27
|
+
const {
|
|
28
|
+
initialItems: v = [],
|
|
29
|
+
emptyFormValues: l,
|
|
30
|
+
explodeItem: m = (a) => a,
|
|
31
|
+
implodeItem: c = (a) => a,
|
|
32
|
+
statusEnum: g = { New: "new", Pending: "pending", Saved: "saved" }
|
|
33
|
+
} = e, p = h([...v]), o = h(null), u = h({ ...l }), I = h(null), w = h(!1), i = h(null), A = O(() => i.value ? JSON.stringify(u.value) !== JSON.stringify(i.value) : !1), S = O(() => ({
|
|
34
|
+
add: {
|
|
35
|
+
disabled: !1,
|
|
36
|
+
label: "Add"
|
|
37
|
+
},
|
|
38
|
+
save: {
|
|
39
|
+
disabled: !A.value,
|
|
40
|
+
label: "Save"
|
|
41
|
+
},
|
|
42
|
+
delete: {
|
|
43
|
+
disabled: !o.value,
|
|
44
|
+
label: "Delete"
|
|
45
|
+
}
|
|
46
|
+
})), b = () => ({
|
|
47
|
+
...l,
|
|
48
|
+
id: H(),
|
|
49
|
+
status: g.New
|
|
50
|
+
}), C = () => {
|
|
51
|
+
const a = b();
|
|
52
|
+
u.value = m(a), i.value = { ...u.value }, o.value = null, t("item-selected", null);
|
|
53
|
+
}, x = (a) => {
|
|
54
|
+
const y = p.value.findIndex((W) => W.id === u.value.id), U = {
|
|
55
|
+
...u.value,
|
|
56
|
+
...a,
|
|
57
|
+
status: o.value?.status === g.Saved ? g.Pending : u.value.status
|
|
58
|
+
};
|
|
59
|
+
y >= 0 ? p.value[y] = c(U) : p.value.push(c(U)), o.value = U, i.value = { ...u.value }, t("update:modelValue", [...p.value]), t("item-updated", U);
|
|
60
|
+
}, D = () => {
|
|
61
|
+
if (!o.value) return;
|
|
62
|
+
const a = p.value.findIndex((y) => y.id === o.value.id);
|
|
63
|
+
if (a >= 0) {
|
|
64
|
+
const y = p.value[a];
|
|
65
|
+
p.value.splice(a, 1), t("item-deleted", y), t("update:modelValue", [...p.value]);
|
|
66
|
+
}
|
|
67
|
+
N(), w.value = !1;
|
|
68
|
+
}, J = (a) => {
|
|
69
|
+
o.value = a, u.value = m({ ...a }), i.value = { ...u.value }, t("item-selected", a);
|
|
70
|
+
}, N = () => {
|
|
71
|
+
o.value = null, u.value = { ...l, id: H() }, i.value = null, t("item-selected", null);
|
|
72
|
+
}, R = (a) => {
|
|
73
|
+
switch (a) {
|
|
74
|
+
case "add":
|
|
75
|
+
C();
|
|
76
|
+
break;
|
|
77
|
+
case "save":
|
|
78
|
+
I.value?.submitForm ? I.value.submitForm() : x(u.value);
|
|
79
|
+
break;
|
|
80
|
+
case "delete":
|
|
81
|
+
w.value = !0;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}, E = (a) => {
|
|
85
|
+
x(a);
|
|
86
|
+
}, P = (a) => {
|
|
87
|
+
u.value = { ...u.value, ...a };
|
|
88
|
+
}, k = () => {
|
|
89
|
+
D();
|
|
90
|
+
}, B = () => {
|
|
91
|
+
w.value = !1;
|
|
92
|
+
}, F = () => {
|
|
93
|
+
N();
|
|
94
|
+
}, T = () => p.value.map((a) => c(a));
|
|
95
|
+
return v.length > 0 && (p.value = v.map((a) => m(a))), {
|
|
96
|
+
items: p,
|
|
97
|
+
activeItem: o,
|
|
98
|
+
formValues: u,
|
|
99
|
+
formRef: I,
|
|
100
|
+
buttonAttributes: S,
|
|
101
|
+
showDeleteConfirm: w,
|
|
102
|
+
isDirty: A,
|
|
103
|
+
addItem: C,
|
|
104
|
+
updateItem: x,
|
|
105
|
+
deleteItem: D,
|
|
106
|
+
selectItem: J,
|
|
107
|
+
clearSelection: N,
|
|
108
|
+
handleButtonClick: R,
|
|
109
|
+
handleFormSubmit: E,
|
|
110
|
+
handleFormUpdate: P,
|
|
111
|
+
confirmDelete: k,
|
|
112
|
+
cancelDelete: B,
|
|
113
|
+
resetForm: F,
|
|
114
|
+
getItems: T
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function _(e) {
|
|
118
|
+
const {
|
|
119
|
+
items: t,
|
|
120
|
+
initialPath: v = "",
|
|
121
|
+
autoExpandActive: l = !0,
|
|
122
|
+
allowMultipleExpanded: m = !0,
|
|
123
|
+
persistExpanded: c = !1,
|
|
124
|
+
storageKey: g = "sidebar-nav-expanded",
|
|
125
|
+
onNavigate: p
|
|
126
|
+
} = e, o = O(() => t), u = h(v), I = h(!1), w = h(!1), i = h(A());
|
|
127
|
+
function A() {
|
|
128
|
+
if (c && typeof window < "u")
|
|
129
|
+
try {
|
|
130
|
+
const n = localStorage.getItem(g);
|
|
131
|
+
if (n)
|
|
132
|
+
return new Set(JSON.parse(n));
|
|
133
|
+
} catch {
|
|
134
|
+
}
|
|
135
|
+
return /* @__PURE__ */ new Set();
|
|
136
|
+
}
|
|
137
|
+
function S() {
|
|
138
|
+
if (c && typeof window < "u")
|
|
139
|
+
try {
|
|
140
|
+
localStorage.setItem(
|
|
141
|
+
g,
|
|
142
|
+
JSON.stringify([...i.value])
|
|
143
|
+
);
|
|
144
|
+
} catch {
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function b(n, d = []) {
|
|
148
|
+
const s = [];
|
|
149
|
+
for (const f of n)
|
|
150
|
+
s.push({ ...f, parentIds: d }), f.children?.length && s.push(
|
|
151
|
+
...b(f.children, [...d, f.id])
|
|
152
|
+
);
|
|
153
|
+
return s;
|
|
154
|
+
}
|
|
155
|
+
function C(n) {
|
|
156
|
+
return b(o.value).find((s) => s.path === n);
|
|
157
|
+
}
|
|
158
|
+
function x(n) {
|
|
159
|
+
return b(o.value).find((f) => f.path === n)?.parentIds || [];
|
|
160
|
+
}
|
|
161
|
+
function D(n) {
|
|
162
|
+
return !!(n.path === u.value || u.value.startsWith(n.path + "/"));
|
|
163
|
+
}
|
|
164
|
+
function J(n) {
|
|
165
|
+
if (!n.children?.length) return !1;
|
|
166
|
+
const d = (s) => s.some((f) => D(f) ? !0 : f.children?.length ? d(f.children) : !1);
|
|
167
|
+
return d(n.children);
|
|
168
|
+
}
|
|
169
|
+
function N() {
|
|
170
|
+
if (!l || !u.value) return;
|
|
171
|
+
const n = x(u.value), d = b(o.value);
|
|
172
|
+
for (const s of d)
|
|
173
|
+
(u.value.startsWith(s.path + "/") || u.value === s.path) && n.push(...s.parentIds);
|
|
174
|
+
for (const s of new Set(n))
|
|
175
|
+
i.value.add(s);
|
|
176
|
+
}
|
|
177
|
+
function R(n) {
|
|
178
|
+
i.value.has(n) ? P(n) : E(n);
|
|
179
|
+
}
|
|
180
|
+
function E(n) {
|
|
181
|
+
if (!m) {
|
|
182
|
+
const d = b(o.value), s = d.find((f) => f.id === n);
|
|
183
|
+
if (s) {
|
|
184
|
+
const f = d.filter(
|
|
185
|
+
(V) => V.parentIds.length === s.parentIds.length && JSON.stringify(V.parentIds) === JSON.stringify(s.parentIds) && V.id !== n
|
|
186
|
+
);
|
|
187
|
+
for (const V of f)
|
|
188
|
+
i.value.delete(V.id);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
i.value = /* @__PURE__ */ new Set([...i.value, n]), S();
|
|
192
|
+
}
|
|
193
|
+
function P(n) {
|
|
194
|
+
i.value.delete(n), i.value = /* @__PURE__ */ new Set([...i.value]), S();
|
|
195
|
+
}
|
|
196
|
+
function k() {
|
|
197
|
+
const d = b(o.value).filter((s) => s.children?.length).map((s) => s.id);
|
|
198
|
+
i.value = new Set(d), S();
|
|
199
|
+
}
|
|
200
|
+
function B() {
|
|
201
|
+
i.value = /* @__PURE__ */ new Set(), S();
|
|
202
|
+
}
|
|
203
|
+
function F(n) {
|
|
204
|
+
u.value = n, l && N();
|
|
205
|
+
}
|
|
206
|
+
function T(n, d) {
|
|
207
|
+
F(n), y(), p?.(n, d);
|
|
208
|
+
}
|
|
209
|
+
function a() {
|
|
210
|
+
I.value = !0;
|
|
211
|
+
}
|
|
212
|
+
function y() {
|
|
213
|
+
I.value = !1;
|
|
214
|
+
}
|
|
215
|
+
function U() {
|
|
216
|
+
I.value = !I.value;
|
|
217
|
+
}
|
|
218
|
+
function W() {
|
|
219
|
+
w.value = !w.value;
|
|
220
|
+
}
|
|
221
|
+
const K = O(() => b(o.value));
|
|
222
|
+
return q(
|
|
223
|
+
() => u.value,
|
|
224
|
+
() => {
|
|
225
|
+
l && N();
|
|
226
|
+
},
|
|
227
|
+
{ immediate: !0 }
|
|
228
|
+
), {
|
|
229
|
+
// State
|
|
230
|
+
items: o,
|
|
231
|
+
expandedItems: i,
|
|
232
|
+
currentPath: u,
|
|
233
|
+
isMobileOpen: I,
|
|
234
|
+
isCollapsed: w,
|
|
235
|
+
// Actions
|
|
236
|
+
toggleItem: R,
|
|
237
|
+
expandItem: E,
|
|
238
|
+
collapseItem: P,
|
|
239
|
+
expandAll: k,
|
|
240
|
+
collapseAll: B,
|
|
241
|
+
setCurrentPath: F,
|
|
242
|
+
navigate: T,
|
|
243
|
+
openMobile: a,
|
|
244
|
+
closeMobile: y,
|
|
245
|
+
toggleMobile: U,
|
|
246
|
+
toggleCollapsed: W,
|
|
247
|
+
// Helpers
|
|
248
|
+
isItemActive: D,
|
|
249
|
+
hasActiveChild: J,
|
|
250
|
+
getParentIds: x,
|
|
251
|
+
findItemByPath: C,
|
|
252
|
+
flatItems: K
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function $(e) {
|
|
256
|
+
const t = /* @__PURE__ */ new Map(), v = [];
|
|
257
|
+
for (const l of e)
|
|
258
|
+
t.set(l.id, { ...l, children: [] });
|
|
259
|
+
for (const l of e) {
|
|
260
|
+
const m = t.get(l.id);
|
|
261
|
+
if (l.parent) {
|
|
262
|
+
const c = t.get(l.parent);
|
|
263
|
+
c ? (c.children = c.children || [], c.children.push(m)) : v.push(m);
|
|
264
|
+
} else
|
|
265
|
+
v.push(m);
|
|
266
|
+
}
|
|
267
|
+
return v;
|
|
268
|
+
}
|
|
269
|
+
function ee(e, t, v, l = {}) {
|
|
270
|
+
return {
|
|
271
|
+
id: e,
|
|
272
|
+
name: t,
|
|
273
|
+
path: v,
|
|
274
|
+
...l
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
function te(e, t = "name", v = "asc") {
|
|
278
|
+
return [...e].sort((l, m) => {
|
|
279
|
+
const c = l[t], g = m[t];
|
|
280
|
+
return typeof c == "string" && typeof g == "string" ? v === "asc" ? c.localeCompare(g) : g.localeCompare(c) : 0;
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
export {
|
|
284
|
+
z as C,
|
|
285
|
+
_ as a,
|
|
286
|
+
$ as b,
|
|
287
|
+
ee as c,
|
|
288
|
+
te as s,
|
|
289
|
+
Z as u,
|
|
290
|
+
H as v
|
|
291
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stachelock/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "A comprehensive Vue 3 UI component library built with Tailwind CSS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"types": "./dist/index.d.ts"
|
|
13
13
|
},
|
|
14
14
|
"./style.css": "./dist/style.css",
|
|
15
|
-
"./tailwind
|
|
15
|
+
"./tailwind-preset": "./tailwind.config.js",
|
|
16
|
+
"./tailwind.config.js": "./tailwind.config.js",
|
|
16
17
|
"./generate-config": "./scripts/generate-config.cjs",
|
|
17
18
|
"./components/*": {
|
|
18
19
|
"import": "./dist/components/*.js",
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { ref as i, computed as D } from "vue";
|
|
2
|
-
var C = /* @__PURE__ */ ((e) => (e.New = "new", e.Pending = "pending", e.Saved = "saved", e.Deleted = "deleted", e))(C || {});
|
|
3
|
-
let p;
|
|
4
|
-
const H = new Uint8Array(16);
|
|
5
|
-
function T() {
|
|
6
|
-
if (!p && (p = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !p))
|
|
7
|
-
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
8
|
-
return p(H);
|
|
9
|
-
}
|
|
10
|
-
const l = [];
|
|
11
|
-
for (let e = 0; e < 256; ++e)
|
|
12
|
-
l.push((e + 256).toString(16).slice(1));
|
|
13
|
-
function q(e, t = 0) {
|
|
14
|
-
return l[e[t + 0]] + l[e[t + 1]] + l[e[t + 2]] + l[e[t + 3]] + "-" + l[e[t + 4]] + l[e[t + 5]] + "-" + l[e[t + 6]] + l[e[t + 7]] + "-" + l[e[t + 8]] + l[e[t + 9]] + "-" + l[e[t + 10]] + l[e[t + 11]] + l[e[t + 12]] + l[e[t + 13]] + l[e[t + 14]] + l[e[t + 15]];
|
|
15
|
-
}
|
|
16
|
-
const z = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), V = {
|
|
17
|
-
randomUUID: z
|
|
18
|
-
};
|
|
19
|
-
function S(e, t, v) {
|
|
20
|
-
if (V.randomUUID && !e)
|
|
21
|
-
return V.randomUUID();
|
|
22
|
-
e = e || {};
|
|
23
|
-
const d = e.random || (e.rng || T)();
|
|
24
|
-
return d[6] = d[6] & 15 | 64, d[8] = d[8] & 63 | 128, q(d);
|
|
25
|
-
}
|
|
26
|
-
function K(e, t) {
|
|
27
|
-
const {
|
|
28
|
-
initialItems: v = [],
|
|
29
|
-
emptyFormValues: d,
|
|
30
|
-
explodeItem: g = (n) => n,
|
|
31
|
-
implodeItem: b = (n) => n,
|
|
32
|
-
statusEnum: y = { New: "new", Pending: "pending", Saved: "saved" }
|
|
33
|
-
} = e, a = i([...v]), s = i(null), u = i({ ...d }), I = i(null), r = i(!1), o = i(null), U = D(() => o.value ? JSON.stringify(u.value) !== JSON.stringify(o.value) : !1), F = D(() => ({
|
|
34
|
-
add: {
|
|
35
|
-
disabled: !1,
|
|
36
|
-
label: "Add"
|
|
37
|
-
},
|
|
38
|
-
save: {
|
|
39
|
-
disabled: !U.value,
|
|
40
|
-
label: "Save"
|
|
41
|
-
},
|
|
42
|
-
delete: {
|
|
43
|
-
disabled: !s.value,
|
|
44
|
-
label: "Delete"
|
|
45
|
-
}
|
|
46
|
-
})), N = () => ({
|
|
47
|
-
...d,
|
|
48
|
-
id: S(),
|
|
49
|
-
status: y.New
|
|
50
|
-
}), f = () => {
|
|
51
|
-
const n = N();
|
|
52
|
-
u.value = g(n), o.value = { ...u.value }, s.value = null, t("item-selected", null);
|
|
53
|
-
}, w = (n) => {
|
|
54
|
-
const c = a.value.findIndex((B) => B.id === u.value.id), m = {
|
|
55
|
-
...u.value,
|
|
56
|
-
...n,
|
|
57
|
-
status: s.value?.status === y.Saved ? y.Pending : u.value.status
|
|
58
|
-
};
|
|
59
|
-
c >= 0 ? a.value[c] = b(m) : a.value.push(b(m)), s.value = m, o.value = { ...u.value }, t("update:modelValue", [...a.value]), t("item-updated", m);
|
|
60
|
-
}, h = () => {
|
|
61
|
-
if (!s.value) return;
|
|
62
|
-
const n = a.value.findIndex((c) => c.id === s.value.id);
|
|
63
|
-
if (n >= 0) {
|
|
64
|
-
const c = a.value[n];
|
|
65
|
-
a.value.splice(n, 1), t("item-deleted", c), t("update:modelValue", [...a.value]);
|
|
66
|
-
}
|
|
67
|
-
x(), r.value = !1;
|
|
68
|
-
}, R = (n) => {
|
|
69
|
-
s.value = n, u.value = g({ ...n }), o.value = { ...u.value }, t("item-selected", n);
|
|
70
|
-
}, x = () => {
|
|
71
|
-
s.value = null, u.value = { ...d, id: S() }, o.value = null, t("item-selected", null);
|
|
72
|
-
}, k = (n) => {
|
|
73
|
-
switch (n) {
|
|
74
|
-
case "add":
|
|
75
|
-
f();
|
|
76
|
-
break;
|
|
77
|
-
case "save":
|
|
78
|
-
I.value?.submitForm ? I.value.submitForm() : w(u.value);
|
|
79
|
-
break;
|
|
80
|
-
case "delete":
|
|
81
|
-
r.value = !0;
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
}, A = (n) => {
|
|
85
|
-
w(n);
|
|
86
|
-
}, E = (n) => {
|
|
87
|
-
u.value = { ...u.value, ...n };
|
|
88
|
-
}, P = () => {
|
|
89
|
-
h();
|
|
90
|
-
}, J = () => {
|
|
91
|
-
r.value = !1;
|
|
92
|
-
}, O = () => {
|
|
93
|
-
x();
|
|
94
|
-
}, j = () => a.value.map((n) => b(n));
|
|
95
|
-
return v.length > 0 && (a.value = v.map((n) => g(n))), {
|
|
96
|
-
items: a,
|
|
97
|
-
activeItem: s,
|
|
98
|
-
formValues: u,
|
|
99
|
-
formRef: I,
|
|
100
|
-
buttonAttributes: F,
|
|
101
|
-
showDeleteConfirm: r,
|
|
102
|
-
isDirty: U,
|
|
103
|
-
addItem: f,
|
|
104
|
-
updateItem: w,
|
|
105
|
-
deleteItem: h,
|
|
106
|
-
selectItem: R,
|
|
107
|
-
clearSelection: x,
|
|
108
|
-
handleButtonClick: k,
|
|
109
|
-
handleFormSubmit: A,
|
|
110
|
-
handleFormUpdate: E,
|
|
111
|
-
confirmDelete: P,
|
|
112
|
-
cancelDelete: J,
|
|
113
|
-
resetForm: O,
|
|
114
|
-
getItems: j
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
export {
|
|
118
|
-
C,
|
|
119
|
-
K as u,
|
|
120
|
-
S as v
|
|
121
|
-
};
|