@coolms/ui-react 0.0.0-stage → 0.1.0-alpha.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/CHANGELOG.md +32 -0
- package/LICENSE +21 -0
- package/README.md +99 -2
- package/design-tokens.lock.json +27 -0
- package/dist/components/Button.d.ts +22 -0
- package/dist/components/Collections.d.ts +62 -0
- package/dist/components/Dialogs.d.ts +40 -0
- package/dist/components/Fields.d.ts +50 -0
- package/dist/components/Status.d.ts +44 -0
- package/dist/components/Structure.d.ts +46 -0
- package/dist/components/internal.d.ts +7 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +553 -0
- package/dist/server/capability.d.ts +31 -0
- package/dist/server/client-update.d.ts +13 -0
- package/dist/server/conflict.d.ts +9 -0
- package/dist/server/refusal.d.ts +21 -0
- package/dist/server/reread.d.ts +9 -0
- package/kit.contract.json +34 -0
- package/package.json +63 -4
- package/src/kit.css +271 -0
- package/src/tokens/coolms-tokens.css +164 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,553 @@
|
|
|
1
|
+
import { jsx as t, jsxs as v, Fragment as S } from "react/jsx-runtime";
|
|
2
|
+
import { useId as A, useState as k, useRef as w, useEffect as x, useLayoutEffect as B, useCallback as K } from "react";
|
|
3
|
+
import { createPortal as C } from "react-dom";
|
|
4
|
+
function _(...e) {
|
|
5
|
+
return e.filter(Boolean).join(" ");
|
|
6
|
+
}
|
|
7
|
+
function N({ name: e }) {
|
|
8
|
+
const n = { width: 16, height: 16, viewBox: "0 0 16 16", "aria-hidden": !0, focusable: !1 };
|
|
9
|
+
switch (e) {
|
|
10
|
+
case "lock":
|
|
11
|
+
return /* @__PURE__ */ t("svg", { ...n, className: "cms-glyph", children: /* @__PURE__ */ t("path", { fill: "currentColor", d: "M5 7V5a3 3 0 1 1 6 0v2h.5A1.5 1.5 0 0 1 13 8.5v5A1.5 1.5 0 0 1 11.5 15h-7A1.5 1.5 0 0 1 3 13.5v-5A1.5 1.5 0 0 1 4.5 7H5Zm1.5 0h3V5a1.5 1.5 0 0 0-3 0v2Z" }) });
|
|
12
|
+
case "spinner":
|
|
13
|
+
return /* @__PURE__ */ t("svg", { ...n, className: "cms-glyph cms-spinner", children: /* @__PURE__ */ t("circle", { cx: "8", cy: "8", r: "6", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeDasharray: "28", strokeDashoffset: "10" }) });
|
|
14
|
+
case "back":
|
|
15
|
+
return /* @__PURE__ */ t("svg", { ...n, className: "cms-glyph", children: /* @__PURE__ */ t("path", { fill: "currentColor", d: "M10.7 2.3a1 1 0 0 1 0 1.4L6.4 8l4.3 4.3a1 1 0 0 1-1.4 1.4l-5-5a1 1 0 0 1 0-1.4l5-5a1 1 0 0 1 1.4 0Z" }) });
|
|
16
|
+
case "close":
|
|
17
|
+
return /* @__PURE__ */ t("svg", { ...n, className: "cms-glyph", children: /* @__PURE__ */ t("path", { fill: "currentColor", d: "M3.3 3.3a1 1 0 0 1 1.4 0L8 6.6l3.3-3.3a1 1 0 1 1 1.4 1.4L9.4 8l3.3 3.3a1 1 0 0 1-1.4 1.4L8 9.4l-3.3 3.3a1 1 0 0 1-1.4-1.4L6.6 8 3.3 4.7a1 1 0 0 1 0-1.4Z" }) });
|
|
18
|
+
case "warning":
|
|
19
|
+
return /* @__PURE__ */ t("svg", { ...n, className: "cms-glyph", children: /* @__PURE__ */ t("path", { fill: "currentColor", d: "M8.9 1.5a1 1 0 0 0-1.8 0l-6 11A1 1 0 0 0 2 14h12a1 1 0 0 0 .9-1.5l-6-11ZM8 5a1 1 0 0 1 1 1v3a1 1 0 0 1-2 0V6a1 1 0 0 1 1-1Zm0 7.5A1 1 0 1 1 8 10.5a1 1 0 0 1 0 2Z" }) });
|
|
20
|
+
case "check":
|
|
21
|
+
return /* @__PURE__ */ t("svg", { ...n, className: "cms-glyph", children: /* @__PURE__ */ t("path", { fill: "currentColor", d: "M13.7 4.3a1 1 0 0 1 0 1.4l-6 6a1 1 0 0 1-1.4 0l-3-3a1 1 0 1 1 1.4-1.4L7 9.6l5.3-5.3a1 1 0 0 1 1.4 0Z" }) });
|
|
22
|
+
case "info":
|
|
23
|
+
return /* @__PURE__ */ t("svg", { ...n, className: "cms-glyph", children: /* @__PURE__ */ t("path", { fill: "currentColor", d: "M8 1a7 7 0 1 1 0 14A7 7 0 0 1 8 1Zm0 5.5a1 1 0 0 0-1 1V11a1 1 0 1 0 2 0V7.5a1 1 0 0 0-1-1ZM8 4a1 1 0 1 0 0 2 1 1 0 0 0 0-2Z" }) });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function E({
|
|
27
|
+
variant: e = "secondary",
|
|
28
|
+
busy: n = !1,
|
|
29
|
+
busyLabel: l,
|
|
30
|
+
locked: a = !1,
|
|
31
|
+
lockedReason: s,
|
|
32
|
+
icon: m,
|
|
33
|
+
disabled: i,
|
|
34
|
+
className: u,
|
|
35
|
+
children: d,
|
|
36
|
+
type: f = "button",
|
|
37
|
+
title: r,
|
|
38
|
+
...o
|
|
39
|
+
}) {
|
|
40
|
+
const c = !!i || n;
|
|
41
|
+
return /* @__PURE__ */ v(
|
|
42
|
+
"button",
|
|
43
|
+
{
|
|
44
|
+
...o,
|
|
45
|
+
type: f,
|
|
46
|
+
className: _("cms-button", `cms-button--${e}`, n && "is-busy", a && "is-locked", u),
|
|
47
|
+
disabled: c,
|
|
48
|
+
"aria-busy": n || void 0,
|
|
49
|
+
title: a ? s ?? r : r,
|
|
50
|
+
children: [
|
|
51
|
+
n ? /* @__PURE__ */ t(N, { name: "spinner" }) : a ? /* @__PURE__ */ t(N, { name: "lock" }) : m,
|
|
52
|
+
/* @__PURE__ */ t("span", { className: "cms-button__label", children: n && l !== void 0 ? l : d }),
|
|
53
|
+
a && s ? /* @__PURE__ */ v("span", { className: "cms-visually-hidden", children: [
|
|
54
|
+
", ",
|
|
55
|
+
s
|
|
56
|
+
] }) : null
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
function L({ id: e, label: n, help: l, error: a, pinned: s, children: m }) {
|
|
62
|
+
return /* @__PURE__ */ v("div", { className: _("cms-field", a != null && "is-invalid"), children: [
|
|
63
|
+
/* @__PURE__ */ t("label", { className: "cms-field__label", htmlFor: e, children: n }),
|
|
64
|
+
m,
|
|
65
|
+
s != null ? /* @__PURE__ */ v("p", { className: "cms-field__pinned", id: `${e}-pinned`, children: [
|
|
66
|
+
/* @__PURE__ */ t(N, { name: "lock" }),
|
|
67
|
+
" ",
|
|
68
|
+
s
|
|
69
|
+
] }) : null,
|
|
70
|
+
a != null ? /* @__PURE__ */ t("p", { className: "cms-field__error", id: `${e}-error`, role: "alert", children: a }) : null,
|
|
71
|
+
l != null ? /* @__PURE__ */ t("p", { className: "cms-field__help", id: `${e}-help`, children: l }) : null
|
|
72
|
+
] });
|
|
73
|
+
}
|
|
74
|
+
function $(e, n) {
|
|
75
|
+
const l = [n.error != null && `${e}-error`, n.pinned != null && `${e}-pinned`, n.help != null && `${e}-help`].filter(Boolean).join(" ");
|
|
76
|
+
return l === "" ? void 0 : l;
|
|
77
|
+
}
|
|
78
|
+
function Y({ label: e, help: n, error: l, disabled: a, readOnly: s, pinned: m, value: i, onChange: u, placeholder: d, type: f = "text", name: r }) {
|
|
79
|
+
const o = A();
|
|
80
|
+
return /* @__PURE__ */ t(L, { id: o, label: e, help: n, error: l, pinned: m, children: /* @__PURE__ */ t(
|
|
81
|
+
"input",
|
|
82
|
+
{
|
|
83
|
+
id: o,
|
|
84
|
+
name: r,
|
|
85
|
+
type: f,
|
|
86
|
+
className: "cms-input",
|
|
87
|
+
value: i,
|
|
88
|
+
placeholder: d,
|
|
89
|
+
disabled: a,
|
|
90
|
+
readOnly: s || m != null,
|
|
91
|
+
"aria-invalid": l != null || void 0,
|
|
92
|
+
"aria-describedby": $(o, { help: n, error: l, pinned: m }),
|
|
93
|
+
onChange: (c) => u == null ? void 0 : u(c.target.value)
|
|
94
|
+
}
|
|
95
|
+
) });
|
|
96
|
+
}
|
|
97
|
+
function J({ label: e, help: n, error: l, disabled: a, readOnly: s, value: m, options: i, onChange: u, emptyText: d = "Nothing to choose from yet.", name: f }) {
|
|
98
|
+
const r = A(), o = i.length === 0;
|
|
99
|
+
return /* @__PURE__ */ t(L, { id: r, label: e, help: o ? d : n, error: l, children: /* @__PURE__ */ t(
|
|
100
|
+
"select",
|
|
101
|
+
{
|
|
102
|
+
id: r,
|
|
103
|
+
name: f,
|
|
104
|
+
className: "cms-input cms-select",
|
|
105
|
+
value: m,
|
|
106
|
+
disabled: a || o,
|
|
107
|
+
"aria-readonly": s || void 0,
|
|
108
|
+
"aria-invalid": l != null || void 0,
|
|
109
|
+
"aria-describedby": $(r, { help: o ? d : n, error: l }),
|
|
110
|
+
onChange: (c) => {
|
|
111
|
+
s || u == null || u(c.target.value);
|
|
112
|
+
},
|
|
113
|
+
children: i.map((c) => /* @__PURE__ */ t("option", { value: c.value, disabled: s && c.value !== m, children: c.label }, c.value))
|
|
114
|
+
}
|
|
115
|
+
) });
|
|
116
|
+
}
|
|
117
|
+
function z({ label: e, checked: n, onChange: l, disabled: a, readOnly: s, help: m }) {
|
|
118
|
+
const i = A();
|
|
119
|
+
return /* @__PURE__ */ v("div", { className: "cms-toggle-row", children: [
|
|
120
|
+
/* @__PURE__ */ t(
|
|
121
|
+
"button",
|
|
122
|
+
{
|
|
123
|
+
id: i,
|
|
124
|
+
type: "button",
|
|
125
|
+
role: "switch",
|
|
126
|
+
className: _("cms-toggle", n && "is-on"),
|
|
127
|
+
"aria-checked": n,
|
|
128
|
+
"aria-readonly": s || void 0,
|
|
129
|
+
"aria-describedby": m != null ? `${i}-help` : void 0,
|
|
130
|
+
disabled: a,
|
|
131
|
+
onClick: () => {
|
|
132
|
+
s || l == null || l(!n);
|
|
133
|
+
},
|
|
134
|
+
children: /* @__PURE__ */ t("span", { className: "cms-toggle__thumb" })
|
|
135
|
+
}
|
|
136
|
+
),
|
|
137
|
+
/* @__PURE__ */ t("label", { className: "cms-toggle__label", htmlFor: i, children: e }),
|
|
138
|
+
m != null ? /* @__PURE__ */ t("p", { className: "cms-field__help", id: `${i}-help`, children: m }) : null
|
|
139
|
+
] });
|
|
140
|
+
}
|
|
141
|
+
const Z = 150;
|
|
142
|
+
function I({ open: e, title: n, onClose: l, dirty: a = !1, onDirtyClose: s, children: m, footer: i }) {
|
|
143
|
+
const [u, d] = k(e), [f, r] = k(!1), o = w(null), c = w(null), g = A();
|
|
144
|
+
if (x(() => {
|
|
145
|
+
if (e) {
|
|
146
|
+
c.current = document.activeElement, d(!0), r(!1);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (!u) return;
|
|
150
|
+
r(!0);
|
|
151
|
+
const h = window.setTimeout(() => {
|
|
152
|
+
var y, b;
|
|
153
|
+
d(!1), r(!1), (b = (y = c.current) == null ? void 0 : y.focus) == null || b.call(y);
|
|
154
|
+
}, Z);
|
|
155
|
+
return () => window.clearTimeout(h);
|
|
156
|
+
}, [e, u]), x(() => {
|
|
157
|
+
var h, y;
|
|
158
|
+
if (e && u) {
|
|
159
|
+
const b = 'input, select, textarea, button, [href], [tabindex]:not([tabindex="-1"])';
|
|
160
|
+
(y = ((h = o.current) == null ? void 0 : h.querySelector(`.cms-modal__body :is(${b}), .cms-modal__foot :is(${b})`)) ?? o.current) == null || y.focus();
|
|
161
|
+
}
|
|
162
|
+
}, [e, u]), !u) return null;
|
|
163
|
+
const p = () => {
|
|
164
|
+
a ? s == null || s() : l();
|
|
165
|
+
};
|
|
166
|
+
return C(
|
|
167
|
+
/* @__PURE__ */ t("div", { className: _("cms-modal-scrim", f && "is-closing"), onMouseDown: (h) => {
|
|
168
|
+
h.target === h.currentTarget && p();
|
|
169
|
+
}, children: /* @__PURE__ */ v(
|
|
170
|
+
"div",
|
|
171
|
+
{
|
|
172
|
+
ref: o,
|
|
173
|
+
className: _("cms-modal", f && "is-closing", a && "is-dirty"),
|
|
174
|
+
role: "dialog",
|
|
175
|
+
"aria-modal": "true",
|
|
176
|
+
"aria-labelledby": g,
|
|
177
|
+
tabIndex: -1,
|
|
178
|
+
onKeyDown: (h) => {
|
|
179
|
+
var y;
|
|
180
|
+
if (h.key === "Escape")
|
|
181
|
+
h.stopPropagation(), p();
|
|
182
|
+
else if (h.key === "Tab") {
|
|
183
|
+
const b = (y = o.current) == null ? void 0 : y.querySelectorAll('input, select, textarea, button:not([disabled]), [href], [tabindex]:not([tabindex="-1"])');
|
|
184
|
+
if (!b || b.length === 0) return;
|
|
185
|
+
const D = b[0], M = b[b.length - 1];
|
|
186
|
+
h.shiftKey && document.activeElement === D ? (h.preventDefault(), M.focus()) : !h.shiftKey && document.activeElement === M && (h.preventDefault(), D.focus());
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
children: [
|
|
190
|
+
/* @__PURE__ */ v("header", { className: "cms-modal__head", children: [
|
|
191
|
+
/* @__PURE__ */ t("h2", { className: "cms-modal__title", id: g, children: n }),
|
|
192
|
+
/* @__PURE__ */ t("button", { type: "button", className: "cms-icon-button", "aria-label": "Close", onClick: p, children: /* @__PURE__ */ t(N, { name: "close" }) })
|
|
193
|
+
] }),
|
|
194
|
+
/* @__PURE__ */ t("div", { className: "cms-modal__body", children: m }),
|
|
195
|
+
i != null ? /* @__PURE__ */ t("footer", { className: "cms-modal__foot", children: i }) : null
|
|
196
|
+
]
|
|
197
|
+
}
|
|
198
|
+
) }),
|
|
199
|
+
document.body
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
function O({ open: e, title: n, message: l, kind: a = "default", confirmLabel: s, cancelLabel: m, onConfirm: i, onCancel: u }) {
|
|
203
|
+
const d = a === "discard-changes";
|
|
204
|
+
return /* @__PURE__ */ t(
|
|
205
|
+
I,
|
|
206
|
+
{
|
|
207
|
+
open: e,
|
|
208
|
+
title: n,
|
|
209
|
+
onClose: u,
|
|
210
|
+
footer: /* @__PURE__ */ v(S, { children: [
|
|
211
|
+
/* @__PURE__ */ t(E, { onClick: u, children: m ?? (d ? "Keep editing" : "Cancel") }),
|
|
212
|
+
/* @__PURE__ */ t(E, { variant: a === "default" ? "primary" : "danger", onClick: i, children: s ?? (d ? "Discard changes" : "Confirm") })
|
|
213
|
+
] }),
|
|
214
|
+
children: a !== "default" ? /* @__PURE__ */ v("p", { className: "cms-confirm__warning", children: [
|
|
215
|
+
/* @__PURE__ */ t(N, { name: "warning" }),
|
|
216
|
+
" ",
|
|
217
|
+
l
|
|
218
|
+
] }) : /* @__PURE__ */ t("p", { children: l })
|
|
219
|
+
}
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
function ee({ kind: e, message: n, action: l, onDismiss: a }) {
|
|
223
|
+
return /* @__PURE__ */ v("div", { className: _("cms-toast", `cms-toast--${e}`), role: e === "error" ? "alert" : "status", children: [
|
|
224
|
+
/* @__PURE__ */ t(N, { name: e === "success" ? "check" : e === "error" ? "warning" : "info" }),
|
|
225
|
+
/* @__PURE__ */ t("span", { className: "cms-toast__message", children: n }),
|
|
226
|
+
l ? /* @__PURE__ */ t(E, { className: "cms-toast__action", onClick: l.onAction, children: l.label }) : null,
|
|
227
|
+
a ? /* @__PURE__ */ t("button", { type: "button", className: "cms-icon-button", "aria-label": "Dismiss", onClick: a, children: /* @__PURE__ */ t(N, { name: "close" }) }) : null
|
|
228
|
+
] });
|
|
229
|
+
}
|
|
230
|
+
function ne({ children: e }) {
|
|
231
|
+
return /* @__PURE__ */ t("div", { className: "cms-toast-region", children: e });
|
|
232
|
+
}
|
|
233
|
+
function q({ what: e, layout: n = "inline" }) {
|
|
234
|
+
return /* @__PURE__ */ v("div", { className: _("cms-loading", `cms-loading--${n}`), role: "status", "aria-live": "polite", children: [
|
|
235
|
+
/* @__PURE__ */ t(N, { name: "spinner" }),
|
|
236
|
+
/* @__PURE__ */ t("span", { children: e })
|
|
237
|
+
] });
|
|
238
|
+
}
|
|
239
|
+
function F({ title: e, hint: n, action: l }) {
|
|
240
|
+
return /* @__PURE__ */ v("div", { className: "cms-empty", children: [
|
|
241
|
+
/* @__PURE__ */ t("p", { className: "cms-empty__title", children: e }),
|
|
242
|
+
n != null ? /* @__PURE__ */ t("p", { className: "cms-empty__hint", children: n }) : null,
|
|
243
|
+
l != null ? /* @__PURE__ */ t("div", { className: "cms-empty__action", children: l }) : null
|
|
244
|
+
] });
|
|
245
|
+
}
|
|
246
|
+
function R({ message: e, onRetry: n }) {
|
|
247
|
+
return /* @__PURE__ */ v("div", { className: "cms-error-banner", role: "alert", children: [
|
|
248
|
+
/* @__PURE__ */ t(N, { name: "warning" }),
|
|
249
|
+
/* @__PURE__ */ t("span", { className: "cms-error-banner__message", children: e }),
|
|
250
|
+
n ? /* @__PURE__ */ t(E, { onClick: n, children: "Try again" }) : null
|
|
251
|
+
] });
|
|
252
|
+
}
|
|
253
|
+
function te({ title: e, scope: n, actions: l, backLink: a }) {
|
|
254
|
+
return /* @__PURE__ */ v("header", { className: "cms-page-header", children: [
|
|
255
|
+
a ? /* @__PURE__ */ v(
|
|
256
|
+
"a",
|
|
257
|
+
{
|
|
258
|
+
className: "cms-page-header__back",
|
|
259
|
+
href: a.href ?? "#",
|
|
260
|
+
onClick: (s) => {
|
|
261
|
+
a.onBack && (s.preventDefault(), a.onBack());
|
|
262
|
+
},
|
|
263
|
+
children: [
|
|
264
|
+
/* @__PURE__ */ t(N, { name: "back" }),
|
|
265
|
+
" ",
|
|
266
|
+
a.label
|
|
267
|
+
]
|
|
268
|
+
}
|
|
269
|
+
) : null,
|
|
270
|
+
/* @__PURE__ */ v("div", { className: "cms-page-header__row", children: [
|
|
271
|
+
/* @__PURE__ */ v("div", { className: "cms-page-header__titles", children: [
|
|
272
|
+
/* @__PURE__ */ t("h1", { className: "cms-page-header__title", children: e }),
|
|
273
|
+
n != null ? /* @__PURE__ */ t("p", { className: "cms-page-header__scope", children: n }) : null
|
|
274
|
+
] }),
|
|
275
|
+
l != null ? /* @__PURE__ */ t("div", { className: "cms-page-header__actions", children: l }) : null
|
|
276
|
+
] })
|
|
277
|
+
] });
|
|
278
|
+
}
|
|
279
|
+
function le({ tabs: e, active: n, onSelect: l, label: a }) {
|
|
280
|
+
const s = w([]), m = (i, u) => {
|
|
281
|
+
var o;
|
|
282
|
+
const d = e.length - 1, f = i.key === "ArrowRight" ? u === d ? 0 : u + 1 : i.key === "ArrowLeft" ? u === 0 ? d : u - 1 : i.key === "Home" ? 0 : i.key === "End" ? d : null;
|
|
283
|
+
if (f === null) return;
|
|
284
|
+
i.preventDefault();
|
|
285
|
+
const r = e[f];
|
|
286
|
+
r && (l(r.id), (o = s.current[f]) == null || o.focus());
|
|
287
|
+
};
|
|
288
|
+
return /* @__PURE__ */ t("div", { className: "cms-tabs", role: "tablist", "aria-label": a, children: e.map((i, u) => {
|
|
289
|
+
const d = i.id === n;
|
|
290
|
+
return /* @__PURE__ */ v(
|
|
291
|
+
"button",
|
|
292
|
+
{
|
|
293
|
+
ref: (f) => {
|
|
294
|
+
s.current[u] = f;
|
|
295
|
+
},
|
|
296
|
+
type: "button",
|
|
297
|
+
role: "tab",
|
|
298
|
+
className: _("cms-tab", d && "is-active"),
|
|
299
|
+
"aria-selected": d,
|
|
300
|
+
tabIndex: d ? 0 : -1,
|
|
301
|
+
onClick: () => l(i.id),
|
|
302
|
+
onKeyDown: (f) => m(f, u),
|
|
303
|
+
children: [
|
|
304
|
+
i.label,
|
|
305
|
+
i.count !== void 0 ? /* @__PURE__ */ t("span", { className: "cms-tab__count", children: i.count }) : null
|
|
306
|
+
]
|
|
307
|
+
},
|
|
308
|
+
i.id
|
|
309
|
+
);
|
|
310
|
+
}) });
|
|
311
|
+
}
|
|
312
|
+
function V(e) {
|
|
313
|
+
var a;
|
|
314
|
+
const n = e.trim().split(/\s+/).filter(Boolean);
|
|
315
|
+
return (n.length > 1 ? [n[0][0], n[n.length - 1][0]] : [(a = n[0]) == null ? void 0 : a[0]]).filter(Boolean).join("").toUpperCase();
|
|
316
|
+
}
|
|
317
|
+
function re({ name: e, pictureUrl: n, presence: l, size: a = 32 }) {
|
|
318
|
+
return /* @__PURE__ */ v(
|
|
319
|
+
"span",
|
|
320
|
+
{
|
|
321
|
+
className: "cms-avatar",
|
|
322
|
+
style: { width: a, height: a, fontSize: Math.round(a * 0.4) },
|
|
323
|
+
role: "img",
|
|
324
|
+
"aria-label": l ? `${e}, ${l}` : e,
|
|
325
|
+
children: [
|
|
326
|
+
n ? /* @__PURE__ */ t("img", { src: n, alt: "", className: "cms-avatar__picture" }) : /* @__PURE__ */ t("span", { "aria-hidden": "true", children: V(e) }),
|
|
327
|
+
l ? /* @__PURE__ */ t("span", { className: _("cms-avatar__presence", `is-${l}`), "aria-hidden": "true" }) : null
|
|
328
|
+
]
|
|
329
|
+
}
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
function ae({ label: e, rows: n, error: l, onRetry: a, loadingText: s = "Loading", emptyTitle: m = "Nothing here yet", emptyHint: i, selected: u, onOpen: d, onRowMenu: f }) {
|
|
333
|
+
const r = w([]);
|
|
334
|
+
if (l != null) return /* @__PURE__ */ t(R, { message: l, onRetry: a });
|
|
335
|
+
if (n === null) return /* @__PURE__ */ t(q, { what: s, layout: "block" });
|
|
336
|
+
if (n.length === 0) return /* @__PURE__ */ t(F, { title: m, hint: i });
|
|
337
|
+
const o = (c, g, p) => {
|
|
338
|
+
var h;
|
|
339
|
+
if (c.key === "ArrowDown" || c.key === "ArrowUp")
|
|
340
|
+
c.preventDefault(), (h = r.current[Math.min(n.length - 1, Math.max(0, g + (c.key === "ArrowDown" ? 1 : -1)))]) == null || h.focus();
|
|
341
|
+
else if (c.key === "Enter")
|
|
342
|
+
d == null || d(p);
|
|
343
|
+
else if ((c.key === "ContextMenu" || c.shiftKey && c.key === "F10") && f) {
|
|
344
|
+
c.preventDefault();
|
|
345
|
+
const y = c.currentTarget.getBoundingClientRect();
|
|
346
|
+
f(p, { x: y.left + 16, y: y.bottom });
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
return /* @__PURE__ */ t("ul", { className: "cms-list", role: "listbox", "aria-label": e, children: n.map((c, g) => {
|
|
350
|
+
const p = c.id === u;
|
|
351
|
+
return /* @__PURE__ */ v(
|
|
352
|
+
"li",
|
|
353
|
+
{
|
|
354
|
+
ref: (h) => {
|
|
355
|
+
r.current[g] = h;
|
|
356
|
+
},
|
|
357
|
+
role: "option",
|
|
358
|
+
"aria-selected": p,
|
|
359
|
+
tabIndex: p || u == null && g === 0 ? 0 : -1,
|
|
360
|
+
className: _("cms-list__row", p && "is-selected"),
|
|
361
|
+
onClick: () => d == null ? void 0 : d(c.id),
|
|
362
|
+
onKeyDown: (h) => o(h, g, c.id),
|
|
363
|
+
onContextMenu: f ? (h) => {
|
|
364
|
+
h.preventDefault(), f(c.id, { x: h.clientX, y: h.clientY });
|
|
365
|
+
} : void 0,
|
|
366
|
+
children: [
|
|
367
|
+
c.lead != null ? /* @__PURE__ */ t("span", { className: "cms-list__lead", children: c.lead }) : null,
|
|
368
|
+
/* @__PURE__ */ v("span", { className: "cms-list__text", children: [
|
|
369
|
+
/* @__PURE__ */ t("span", { className: "cms-list__primary", children: c.primary }),
|
|
370
|
+
c.secondary != null ? /* @__PURE__ */ t("span", { className: "cms-list__secondary", children: c.secondary }) : null
|
|
371
|
+
] }),
|
|
372
|
+
c.meta != null ? /* @__PURE__ */ t("span", { className: "cms-list__meta", children: c.meta }) : null
|
|
373
|
+
]
|
|
374
|
+
},
|
|
375
|
+
c.id
|
|
376
|
+
);
|
|
377
|
+
}) });
|
|
378
|
+
}
|
|
379
|
+
function se({ at: e, items: n, onClose: l, label: a = "Actions" }) {
|
|
380
|
+
const s = w(null), m = w(null), [i, u] = k(e), d = n.filter((r) => r.offer.offered);
|
|
381
|
+
if (B(() => {
|
|
382
|
+
if (!e) return;
|
|
383
|
+
const r = s.current, o = (r == null ? void 0 : r.offsetWidth) ?? 0, c = (r == null ? void 0 : r.offsetHeight) ?? 0;
|
|
384
|
+
u({ x: Math.max(0, Math.min(e.x, window.innerWidth - o)), y: Math.max(0, Math.min(e.y, window.innerHeight - c)) });
|
|
385
|
+
}, [e]), x(() => {
|
|
386
|
+
var o, c;
|
|
387
|
+
if (!e) return;
|
|
388
|
+
m.current = document.activeElement, (c = (o = s.current) == null ? void 0 : o.querySelector('[role="menuitem"]:not([aria-disabled="true"])')) == null || c.focus();
|
|
389
|
+
const r = (g) => {
|
|
390
|
+
var p;
|
|
391
|
+
(p = s.current) != null && p.contains(g.target) || l();
|
|
392
|
+
};
|
|
393
|
+
return document.addEventListener("mousedown", r), () => {
|
|
394
|
+
var g, p;
|
|
395
|
+
document.removeEventListener("mousedown", r), (p = (g = m.current) == null ? void 0 : g.focus) == null || p.call(g);
|
|
396
|
+
};
|
|
397
|
+
}, [e, l]), !e || d.length === 0) return null;
|
|
398
|
+
const f = (r) => {
|
|
399
|
+
var g, p;
|
|
400
|
+
const o = Array.from(((g = s.current) == null ? void 0 : g.querySelectorAll('[role="menuitem"]')) ?? []), c = o.indexOf(document.activeElement);
|
|
401
|
+
if (r.key === "Escape" || r.key === "Tab")
|
|
402
|
+
r.preventDefault(), l();
|
|
403
|
+
else if (r.key === "ArrowDown" || r.key === "ArrowUp") {
|
|
404
|
+
r.preventDefault();
|
|
405
|
+
const h = r.key === "ArrowDown" ? 1 : -1;
|
|
406
|
+
(p = o[(c + h + o.length) % o.length]) == null || p.focus();
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
return C(
|
|
410
|
+
/* @__PURE__ */ t(
|
|
411
|
+
"div",
|
|
412
|
+
{
|
|
413
|
+
ref: s,
|
|
414
|
+
className: "cms-menu",
|
|
415
|
+
role: "menu",
|
|
416
|
+
"aria-label": a,
|
|
417
|
+
style: { left: (i ?? e).x, top: (i ?? e).y },
|
|
418
|
+
onKeyDown: f,
|
|
419
|
+
onContextMenu: (r) => r.preventDefault(),
|
|
420
|
+
children: d.map((r) => {
|
|
421
|
+
const o = r.offer.refusal !== void 0;
|
|
422
|
+
return /* @__PURE__ */ v(
|
|
423
|
+
"div",
|
|
424
|
+
{
|
|
425
|
+
role: "menuitem",
|
|
426
|
+
tabIndex: -1,
|
|
427
|
+
"aria-disabled": o || void 0,
|
|
428
|
+
title: o ? r.offer.refusal : void 0,
|
|
429
|
+
className: _("cms-menu__item", r.danger && "is-danger", r.offer.locked && "is-locked", o && "is-refused"),
|
|
430
|
+
onClick: () => {
|
|
431
|
+
o || (l(), r.onSelect());
|
|
432
|
+
},
|
|
433
|
+
onKeyDown: (c) => {
|
|
434
|
+
(c.key === "Enter" || c.key === " ") && !o && (c.preventDefault(), l(), r.onSelect());
|
|
435
|
+
},
|
|
436
|
+
children: [
|
|
437
|
+
r.offer.locked ? /* @__PURE__ */ t(N, { name: "lock" }) : null,
|
|
438
|
+
/* @__PURE__ */ t("span", { className: "cms-menu__label", children: r.label }),
|
|
439
|
+
o ? /* @__PURE__ */ t("span", { className: "cms-menu__refusal", children: r.offer.refusal }) : null
|
|
440
|
+
]
|
|
441
|
+
},
|
|
442
|
+
r.id
|
|
443
|
+
);
|
|
444
|
+
})
|
|
445
|
+
}
|
|
446
|
+
),
|
|
447
|
+
document.body
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
function j(e) {
|
|
451
|
+
return e === "allowed" || e === "elevate" || e === "denied";
|
|
452
|
+
}
|
|
453
|
+
function ce(e, n) {
|
|
454
|
+
if (!j(e))
|
|
455
|
+
return n.showRefused ? { offered: !0, locked: !1, refusal: "not available: the server gave an answer this app does not know", unknown: !0 } : { offered: !1, locked: !1, unknown: !0 };
|
|
456
|
+
switch (e) {
|
|
457
|
+
case "allowed":
|
|
458
|
+
return { offered: !0, locked: !1 };
|
|
459
|
+
case "elevate":
|
|
460
|
+
return n.elevates ? { offered: !0, locked: !0 } : { offered: !1, locked: !1 };
|
|
461
|
+
case "denied":
|
|
462
|
+
return n.showRefused ? { offered: !0, locked: !1, refusal: n.refusal ?? "not allowed" } : { offered: !1, locked: !1 };
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
function H(e, n) {
|
|
466
|
+
if (!e) return;
|
|
467
|
+
if (typeof e.get == "function") return e.get(n) ?? void 0;
|
|
468
|
+
const l = e, a = Object.keys(l).find((s) => s.toLowerCase() === n.toLowerCase());
|
|
469
|
+
return a === void 0 ? void 0 : l[a];
|
|
470
|
+
}
|
|
471
|
+
function P(e) {
|
|
472
|
+
if (e && typeof e == "object") {
|
|
473
|
+
const n = e;
|
|
474
|
+
if (typeof n.detail == "string" && n.detail !== "") return n.detail;
|
|
475
|
+
if (typeof n.title == "string" && n.title !== "") return n.title;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
function ie(e, n, l, a) {
|
|
479
|
+
if (e !== 403) return { kind: "none" };
|
|
480
|
+
const s = P(l);
|
|
481
|
+
return H(n, "X-Elevation-Required") !== void 0 ? a.elevates ? { kind: "elevation-required", message: s ?? "This needs an elevated session." } : { kind: "refused", message: "This can only be done in the admin, in an elevated session." } : { kind: "refused", message: s ?? "The server refused this." };
|
|
482
|
+
}
|
|
483
|
+
const T = "coolms-kit:reread";
|
|
484
|
+
function oe() {
|
|
485
|
+
window.dispatchEvent(new Event(T));
|
|
486
|
+
}
|
|
487
|
+
function ue(e) {
|
|
488
|
+
const [n, l] = k(void 0), [a, s] = k(void 0), [m, i] = k(!0), u = w(e);
|
|
489
|
+
u.current = e;
|
|
490
|
+
const d = w(0), f = K(() => {
|
|
491
|
+
const r = ++d.current;
|
|
492
|
+
i(!0), u.current().then(
|
|
493
|
+
(o) => {
|
|
494
|
+
r === d.current && (l(o), s(void 0), i(!1));
|
|
495
|
+
},
|
|
496
|
+
(o) => {
|
|
497
|
+
r === d.current && (s(o), i(!1));
|
|
498
|
+
}
|
|
499
|
+
);
|
|
500
|
+
}, []);
|
|
501
|
+
return x(() => {
|
|
502
|
+
f();
|
|
503
|
+
const r = () => f();
|
|
504
|
+
return window.addEventListener("focus", r), window.addEventListener(T, r), () => {
|
|
505
|
+
window.removeEventListener("focus", r), window.removeEventListener(T, r);
|
|
506
|
+
};
|
|
507
|
+
}, [f]), { value: n, error: a, loading: m, reread: f };
|
|
508
|
+
}
|
|
509
|
+
function de(e) {
|
|
510
|
+
return e === 412 ? { conflict: !0, message: "Someone changed this since you opened it. Nothing was saved; read it again to see the change." } : { conflict: !1 };
|
|
511
|
+
}
|
|
512
|
+
const U = "/errors/client-update-required";
|
|
513
|
+
function W(e, n) {
|
|
514
|
+
const l = e.split(".").map((s) => Number.parseInt(s, 10) || 0), a = n.split(".").map((s) => Number.parseInt(s, 10) || 0);
|
|
515
|
+
for (let s = 0; s < Math.max(l.length, a.length); s++) {
|
|
516
|
+
const m = l[s] ?? 0, i = a[s] ?? 0;
|
|
517
|
+
if (m !== i) return m < i;
|
|
518
|
+
}
|
|
519
|
+
return !1;
|
|
520
|
+
}
|
|
521
|
+
function me(e) {
|
|
522
|
+
return e.problemType !== void 0 && e.problemType.endsWith(U) ? !0 : e.minimumVersion !== void 0 && W(e.version, e.minimumVersion);
|
|
523
|
+
}
|
|
524
|
+
export {
|
|
525
|
+
re as Avatar,
|
|
526
|
+
E as Button,
|
|
527
|
+
U as CLIENT_UPDATE_REQUIRED,
|
|
528
|
+
O as ConfirmDialog,
|
|
529
|
+
se as ContextMenu,
|
|
530
|
+
F as EmptyState,
|
|
531
|
+
R as ErrorBanner,
|
|
532
|
+
ae as List,
|
|
533
|
+
q as Loading,
|
|
534
|
+
Z as MODAL_CLOSE_MS,
|
|
535
|
+
I as Modal,
|
|
536
|
+
te as PageHeader,
|
|
537
|
+
J as Select,
|
|
538
|
+
le as TabStrip,
|
|
539
|
+
Y as TextField,
|
|
540
|
+
ee as Toast,
|
|
541
|
+
ne as ToastRegion,
|
|
542
|
+
z as Toggle,
|
|
543
|
+
V as initialsOf,
|
|
544
|
+
j as isCapability,
|
|
545
|
+
me as needsClientUpdate,
|
|
546
|
+
ce as offerFor,
|
|
547
|
+
de as readConflict,
|
|
548
|
+
ie as readRefusal,
|
|
549
|
+
P as refusalText,
|
|
550
|
+
oe as rereadAll,
|
|
551
|
+
ue as useReread,
|
|
552
|
+
W as versionBelow
|
|
553
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a declared action comes to for this caller on this subject, as the server answered it in the subject's
|
|
3
|
+
* capabilities map (contract: server state `capability`, reactions R3 and R4). An action is offered from that answer
|
|
4
|
+
* only -- never computed from mode bits, owner, membership or role.
|
|
5
|
+
*
|
|
6
|
+
* allowed offered
|
|
7
|
+
* elevate offered locked by a client that elevates; not offered by one that never does
|
|
8
|
+
* denied not offered, or offered disabled with the server's refusal when the client shows why
|
|
9
|
+
* anything else -- a state this client does not know -- is denied, and said (R4)
|
|
10
|
+
*/
|
|
11
|
+
export type Capability = 'allowed' | 'elevate' | 'denied';
|
|
12
|
+
export interface Offer {
|
|
13
|
+
/** Whether the action is shown at all. */
|
|
14
|
+
readonly offered: boolean;
|
|
15
|
+
/** Shown, but behind elevation (only in a client that elevates). */
|
|
16
|
+
readonly locked: boolean;
|
|
17
|
+
/** Shown, but refused: the refusal in words, as the server gave it. */
|
|
18
|
+
readonly refusal?: string;
|
|
19
|
+
/** The server's answer was not one this client knows (R4): treated as denied. */
|
|
20
|
+
readonly unknown?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface OfferOptions {
|
|
23
|
+
/** Whether this client can ask for elevation (theme-admin does; a workspace client does not). */
|
|
24
|
+
readonly elevates: boolean;
|
|
25
|
+
/** Show a denied action disabled, with its refusal, instead of leaving it out. */
|
|
26
|
+
readonly showRefused?: boolean;
|
|
27
|
+
/** The server's refusal phrase for a denied action, when it gave one. */
|
|
28
|
+
readonly refusal?: string;
|
|
29
|
+
}
|
|
30
|
+
export declare function isCapability(answer: unknown): answer is Capability;
|
|
31
|
+
export declare function offerFor(answer: unknown, options: OfferOptions): Offer;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether this client's version is still supported (contract: server state `client-version`, reaction R6): a response
|
|
3
|
+
* typed /errors/client-update-required (any status), or a discovery minimumVersion above this client's version, means
|
|
4
|
+
* stop using that server and say an update is needed.
|
|
5
|
+
*/
|
|
6
|
+
export declare const CLIENT_UPDATE_REQUIRED = "/errors/client-update-required";
|
|
7
|
+
/** Compares dotted numeric versions ("1.10.2" > "1.9"); a part that is not a number counts as 0. */
|
|
8
|
+
export declare function versionBelow(version: string, minimum: string): boolean;
|
|
9
|
+
export declare function needsClientUpdate(input: {
|
|
10
|
+
readonly problemType?: string | undefined;
|
|
11
|
+
readonly minimumVersion?: string | undefined;
|
|
12
|
+
readonly version: string;
|
|
13
|
+
}): boolean;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A write that named the version it read (If-Match) and answered 412 changed nothing (contract: server state
|
|
3
|
+
* `versioned-write`, reaction R5): say so and offer to read again -- never resend the write over what changed.
|
|
4
|
+
*/
|
|
5
|
+
export interface Conflict {
|
|
6
|
+
readonly conflict: boolean;
|
|
7
|
+
readonly message?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function readConflict(status: number): Conflict;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether an action is allowed NOW is the action's own response (contract: server state `action-now`, reaction R2):
|
|
3
|
+
* a 403 stamped X-Elevation-Required asks for elevation -- a client that never elevates says it cannot do that here --
|
|
4
|
+
* and any other 403 is a refusal, quoted as the server gave it. A flag read earlier never stands in for it.
|
|
5
|
+
*/
|
|
6
|
+
export type Refusal = {
|
|
7
|
+
readonly kind: 'none';
|
|
8
|
+
} | {
|
|
9
|
+
readonly kind: 'elevation-required';
|
|
10
|
+
readonly message: string;
|
|
11
|
+
} | {
|
|
12
|
+
readonly kind: 'refused';
|
|
13
|
+
readonly message: string;
|
|
14
|
+
};
|
|
15
|
+
type HeaderSource = Headers | Readonly<Record<string, string | undefined>>;
|
|
16
|
+
/** The server's own words for a refusal: a problem+json `detail`, else its `title`. */
|
|
17
|
+
export declare function refusalText(body: unknown): string | undefined;
|
|
18
|
+
export declare function readRefusal(status: number, headers: HeaderSource | undefined, body: unknown, options: {
|
|
19
|
+
elevates: boolean;
|
|
20
|
+
}): Refusal;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Tell every useReread on the page to read again (an elevation granted or ended, a refusal answered). */
|
|
2
|
+
export declare function rereadAll(): void;
|
|
3
|
+
export interface Reread<T> {
|
|
4
|
+
readonly value: T | undefined;
|
|
5
|
+
readonly error: unknown;
|
|
6
|
+
readonly loading: boolean;
|
|
7
|
+
readonly reread: () => void;
|
|
8
|
+
}
|
|
9
|
+
export declare function useReread<T>(read: () => Promise<T>): Reread<T>;
|