@scalio-cloud/ui 0.68.0 → 0.71.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/README.md +8 -1
- package/nav.css +16 -0
- package/package.json +1 -1
- package/react/ai.js +2 -2
- package/react/markdown.js +85 -12
- package/react/nav.js +55 -11
package/README.md
CHANGED
|
@@ -174,7 +174,7 @@ const NAV = { sections: [
|
|
|
174
174
|
] },
|
|
175
175
|
] };
|
|
176
176
|
|
|
177
|
-
const apps = useScalioApps(() => api.get("/apps").then((r) => r.data)); // once per page load
|
|
177
|
+
const apps = useScalioApps(() => api.get("/apps").then((r) => r.data)); // once per page load, retried after 1/2/4 s (not on 401/403/404)
|
|
178
178
|
<AppShell
|
|
179
179
|
switcher={apps.features.switcher && <ProductSwitcher current="citadel" links={apps.links} stage={apps.stage} sso={sso} lang={lang} />}
|
|
180
180
|
header={<AppHeader ... onMenu={() => setDrawer(true)}
|
|
@@ -749,6 +749,13 @@ markdownOutline(page.body) // [{ level, text, id }] for a table of contents; h
|
|
|
749
749
|
`labels` overrides the callout titles (`{ note, tip, important, warning, caution }`). Also exported:
|
|
750
750
|
`parseMarkdownBlocks`, `parseMarkdownInline`, `markdownHeadingId`, `safeHref`. Test IDs: `callout-<kind>`.
|
|
751
751
|
|
|
752
|
+
From 0.70.0: `pageLinks` reads `[[Title]]`, `[[KEY:Title]]` and `[[Title|text]]` as page links (shown as text with a
|
|
753
|
+
dotted line, `.scalio-md-pagelink`, unless the app renders them). `render={{ image, link, pagelink }}` puts the app's
|
|
754
|
+
own elements in: `image(node, key)`, `link(node, key, children)`, `pagelink(node, key)`; a function that returns
|
|
755
|
+
`undefined` keeps the building block's element (Folio: images of the space, router links, resolved page links). Also
|
|
756
|
+
`markdownPageLinks(text)` (every page link once, not in code), `markdownPageLinkKey(space, title)` and
|
|
757
|
+
`parseMarkdownPageLink(inner)`.
|
|
758
|
+
|
|
752
759
|
## shadcn/ui components (from 0.38.0)
|
|
753
760
|
|
|
754
761
|
One copy of the shadcn/ui components the apps used to keep in `src/components/ui` (code-quality plan QA6, decision
|
package/nav.css
CHANGED
|
@@ -330,6 +330,21 @@
|
|
|
330
330
|
.dark .scalio-notice.is-warn { --notice-tone: 245 158 11; }
|
|
331
331
|
.dark .scalio-notice.is-error { --notice-tone: 248 113 113; }
|
|
332
332
|
.dark .scalio-notice { background: rgb(var(--notice-tone) / 0.12); }
|
|
333
|
+
/* On/off switch: <input type="checkbox" role="switch" class="scalio-switch">, a slider like the shadcn Switch. */
|
|
334
|
+
.scalio-switch {
|
|
335
|
+
appearance: none; -webkit-appearance: none; position: relative; flex: none; width: 2.75rem; height: 1.5rem; margin: 0;
|
|
336
|
+
border: 2px solid transparent; border-radius: 9999px; background: hsl(var(--input)); cursor: pointer;
|
|
337
|
+
transition: background-color 0.15s ease;
|
|
338
|
+
}
|
|
339
|
+
.scalio-switch::before {
|
|
340
|
+
content: ""; position: absolute; top: 0; left: 0; width: 1.25rem; height: 1.25rem; border-radius: 50%;
|
|
341
|
+
background: hsl(var(--background)); box-shadow: 0 1px 3px rgb(0 0 0 / 0.25); transition: transform 0.15s ease;
|
|
342
|
+
}
|
|
343
|
+
.scalio-switch:checked { background: hsl(var(--primary)); }
|
|
344
|
+
.scalio-switch:checked::before { transform: translateX(1.25rem); }
|
|
345
|
+
.scalio-switch:disabled { cursor: not-allowed; opacity: 0.5; }
|
|
346
|
+
.scalio-switch:focus-visible { outline: 2px solid hsl(var(--ring)); outline-offset: 2px; }
|
|
347
|
+
@media (prefers-reduced-motion: reduce) { .scalio-switch, .scalio-switch::before { transition: none; } }
|
|
333
348
|
.scalio-badge {
|
|
334
349
|
display: inline-flex; align-items: center; gap: 0.25rem; padding: 0.0625rem 0.375rem; border: 1px solid; border-radius: 2px;
|
|
335
350
|
font-family: 'JetBrains Mono', monospace; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; white-space: nowrap;
|
|
@@ -932,6 +947,7 @@ ul.scalio-notice { flex-direction: column; gap: 0.25rem; padding-left: 2rem; lis
|
|
|
932
947
|
.scalio-md-h5, .scalio-md-h6 { font-size: 0.875rem; }
|
|
933
948
|
.scalio-md-h6 { color: hsl(var(--muted-foreground)); }
|
|
934
949
|
.scalio-md-link { color: hsl(var(--primary)); text-decoration: underline; }
|
|
950
|
+
.scalio-md-pagelink { text-decoration: underline dotted; }
|
|
935
951
|
.scalio-md-code { padding: 0.125rem 0.25rem; border-radius: 2px; background: hsl(var(--secondary)); font-family: 'JetBrains Mono', monospace; font-size: 0.85em; }
|
|
936
952
|
.scalio-md-pre { padding: 0.75rem; border-radius: 2px; background: hsl(var(--secondary)); font-family: 'JetBrains Mono', monospace; font-size: 0.75rem; overflow-x: auto; white-space: pre; }
|
|
937
953
|
.scalio-md-rule { border: 0; border-top: 1px solid hsl(var(--border)); }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scalio-cloud/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.71.0",
|
|
4
4
|
"description": "Scalio Control Room design tokens, Tailwind preset, self-hosted fonts, the shared app header, sign-in layout, sidebar and page blocks",
|
|
5
5
|
"license": "SEE LICENSE IN README.md",
|
|
6
6
|
"private": false,
|
package/react/ai.js
CHANGED
|
@@ -31,7 +31,7 @@ const LABELS = {
|
|
|
31
31
|
title: "KI-Assistent",
|
|
32
32
|
hint: "KI ist eine Option: Sie erklärt, fasst zusammen und schlägt vor. Was etwas ändert, bestätigen Sie immer selbst.",
|
|
33
33
|
enable: "KI einschalten",
|
|
34
|
-
enableHint: "
|
|
34
|
+
enableHint: "Ausgeschaltet sind alle KI-Funktionen ausgeblendet.",
|
|
35
35
|
statusOff: "Aus",
|
|
36
36
|
statusReady: "Bereit",
|
|
37
37
|
statusSetup: "Einrichtung nötig",
|
|
@@ -96,7 +96,7 @@ const LABELS = {
|
|
|
96
96
|
title: "AI assistant",
|
|
97
97
|
hint: "AI is optional: it explains, summarises and suggests. Anything that changes something you always confirm yourself.",
|
|
98
98
|
enable: "Turn on AI",
|
|
99
|
-
enableHint: "
|
|
99
|
+
enableHint: "When off, all AI features are hidden.",
|
|
100
100
|
statusOff: "Off",
|
|
101
101
|
statusReady: "Ready",
|
|
102
102
|
statusSetup: "Setup needed",
|
package/react/markdown.js
CHANGED
|
@@ -129,14 +129,26 @@ function parseBlocks(src) {
|
|
|
129
129
|
return blocks;
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
//
|
|
133
|
-
const
|
|
132
|
+
// [[Title]], [[KEY:Title]] and [[Title|text]]: a link to another page by its title (Folio). KEY is a space key.
|
|
133
|
+
const PAGE_LINK = /^\s*(?:([A-Z][A-Z0-9]{1,9})\s*:\s*)?([^|]*?)\s*(?:\\?\|\s*(.*?)\s*)?$/; // \| in a table cell
|
|
134
|
+
function parsePageLink(inner) {
|
|
135
|
+
const m = String(inner || "").match(PAGE_LINK);
|
|
136
|
+
const title = m ? m[2].replace(/\s+/g, " ") : "";
|
|
137
|
+
return title ? { space: m[1] || "", title, label: m[3] || "" } : null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// code | image | link | bold | strike | italic | bare url (| page link, only with the option pageLinks)
|
|
141
|
+
const INLINE_SRC = "(`+)([\\s\\S]*?[^`])\\1(?!`)|!\\[([^\\]]*)\\]\\(([^)\\s]+)(?:\\s+\"[^\"]*\")?\\)|\\[([^\\]]+)\\]\\(([^)\\s]+)(?:\\s+\"[^\"]*\")?\\)|\\*\\*([\\s\\S]+?)\\*\\*|__([\\s\\S]+?)__|~~([\\s\\S]+?)~~|\\*([^*\\s][^*]*?)\\*|(?<![\\w])_([^_\\s][^_]*?)_(?![\\w])|(https?:\\/\\/[^\\s<>()]+[^\\s<>().,;:!?])";
|
|
142
|
+
const INLINE = new RegExp(INLINE_SRC, "g");
|
|
143
|
+
const INLINE_PAGES = new RegExp(INLINE_SRC + "|\\[\\[([^[\\]\\n]+)\\]\\]", "g");
|
|
134
144
|
|
|
135
|
-
|
|
145
|
+
// opts.pageLinks: [[...]] becomes {type: "pagelink", space, title, label} (else it stays text).
|
|
146
|
+
function parseInline(src, opts) {
|
|
147
|
+
const pages = !!(opts && opts.pageLinks);
|
|
136
148
|
const out = [];
|
|
137
149
|
const text = String(src || "");
|
|
138
150
|
let last = 0;
|
|
139
|
-
for (const m of text.matchAll(INLINE)) {
|
|
151
|
+
for (const m of text.matchAll(pages ? INLINE_PAGES : INLINE)) {
|
|
140
152
|
if (m.index > last) out.push({ type: "text", text: text.slice(last, m.index) });
|
|
141
153
|
if (m[1]) out.push({ type: "code", text: m[2].trim() ? m[2].replace(/^ (.*) $/, "$1") : m[2] });
|
|
142
154
|
else if (m[4] !== undefined) {
|
|
@@ -144,11 +156,15 @@ function parseInline(src) {
|
|
|
144
156
|
out.push(href ? { type: "image", alt: m[3], href } : { type: "text", text: m[0] });
|
|
145
157
|
} else if (m[6] !== undefined) {
|
|
146
158
|
const href = safeHref(m[6]);
|
|
147
|
-
out.push(href ? { type: "link", href, children: parseInline(m[5]) } : { type: "text", text: m[5] });
|
|
148
|
-
} else if (m[7] !== undefined || m[8] !== undefined) out.push({ type: "bold", children: parseInline(m[7] ?? m[8]) });
|
|
149
|
-
else if (m[9] !== undefined) out.push({ type: "strike", children: parseInline(m[9]) });
|
|
150
|
-
else if (m[10] !== undefined || m[11] !== undefined) out.push({ type: "italic", children: parseInline(m[10] ?? m[11]) });
|
|
159
|
+
out.push(href ? { type: "link", href, children: parseInline(m[5], opts) } : { type: "text", text: m[5] });
|
|
160
|
+
} else if (m[7] !== undefined || m[8] !== undefined) out.push({ type: "bold", children: parseInline(m[7] ?? m[8], opts) });
|
|
161
|
+
else if (m[9] !== undefined) out.push({ type: "strike", children: parseInline(m[9], opts) });
|
|
162
|
+
else if (m[10] !== undefined || m[11] !== undefined) out.push({ type: "italic", children: parseInline(m[10] ?? m[11], opts) });
|
|
151
163
|
else if (m[12]) out.push({ type: "link", href: m[12], children: [{ type: "text", text: m[12] }] });
|
|
164
|
+
else if (m[13] !== undefined) {
|
|
165
|
+
const link = parsePageLink(m[13]);
|
|
166
|
+
out.push(link ? Object.assign({ type: "pagelink" }, link) : { type: "text", text: m[0] });
|
|
167
|
+
}
|
|
152
168
|
last = m.index + m[0].length;
|
|
153
169
|
}
|
|
154
170
|
if (last < text.length) out.push({ type: "text", text: text.slice(last) });
|
|
@@ -165,8 +181,53 @@ function outline(src) {
|
|
|
165
181
|
.map((b) => ({ level: b.level, text: b.text, id: headingId(b.text) }));
|
|
166
182
|
}
|
|
167
183
|
|
|
184
|
+
const pageLinkKey = (space, title) => `${space || ""}:${String(title || "").trim().replace(/\s+/g, " ").toLowerCase()}`;
|
|
185
|
+
|
|
186
|
+
// Every [[page link]] of a text (not in code), once per space and title.
|
|
187
|
+
function pageLinks(src) {
|
|
188
|
+
const found = new Map();
|
|
189
|
+
const nodes = (ns) => ns.forEach((n) => {
|
|
190
|
+
if (n.type === "pagelink") { const k = pageLinkKey(n.space, n.title); if (!found.has(k)) found.set(k, { space: n.space, title: n.title }); }
|
|
191
|
+
else if (n.children) nodes(n.children);
|
|
192
|
+
});
|
|
193
|
+
const inl = (text) => nodes(parseInline(text, { pageLinks: true }));
|
|
194
|
+
const list = (l) => l.items.forEach((it) => { inl(it.text); if (it.children) list(it.children); });
|
|
195
|
+
const walk = (blocks) => blocks.forEach((b) => {
|
|
196
|
+
if (b.type === "heading" || b.type === "paragraph") inl(b.text);
|
|
197
|
+
else if (b.type === "list") list(b);
|
|
198
|
+
else if (b.type === "table") [b.head, ...b.rows].forEach((r) => r.forEach(inl));
|
|
199
|
+
else if (b.blocks) walk(b.blocks);
|
|
200
|
+
});
|
|
201
|
+
walk(parseBlocks(src));
|
|
202
|
+
return [...found.values()];
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// The app's own elements (props.render): image(node, key), link(node, key, children), pagelink(node, key). A function
|
|
206
|
+
// that returns undefined leaves the building block's own element.
|
|
207
|
+
const Ctx = React.createContext({ render: {}, opts: null });
|
|
208
|
+
|
|
209
|
+
function own(ctx, kind, args) {
|
|
210
|
+
const fn = ctx.render && ctx.render[kind];
|
|
211
|
+
if (typeof fn !== "function") return undefined;
|
|
212
|
+
return fn.apply(null, args);
|
|
213
|
+
}
|
|
214
|
+
|
|
168
215
|
function Inline(props) {
|
|
216
|
+
const ctx = React.useContext(Ctx);
|
|
169
217
|
return h(React.Fragment, null, props.nodes.map((n, i) => {
|
|
218
|
+
if (n.type === "image") {
|
|
219
|
+
const mine = own(ctx, "image", [n, i]);
|
|
220
|
+
if (mine !== undefined) return mine;
|
|
221
|
+
}
|
|
222
|
+
if (n.type === "link") {
|
|
223
|
+
const mine = own(ctx, "link", [n, i, h(Inline, { nodes: n.children })]);
|
|
224
|
+
if (mine !== undefined) return mine;
|
|
225
|
+
}
|
|
226
|
+
if (n.type === "pagelink") {
|
|
227
|
+
const mine = own(ctx, "pagelink", [n, i]);
|
|
228
|
+
if (mine !== undefined) return mine;
|
|
229
|
+
return h("span", { key: i, className: "scalio-md-pagelink" }, n.label || n.title);
|
|
230
|
+
}
|
|
170
231
|
if (n.type === "code") return h("code", { key: i, className: "scalio-md-code" }, n.text);
|
|
171
232
|
if (n.type === "bold") return h("strong", { key: i }, h(Inline, { nodes: n.children }));
|
|
172
233
|
if (n.type === "italic") return h("em", { key: i }, h(Inline, { nodes: n.children }));
|
|
@@ -183,7 +244,11 @@ function Inline(props) {
|
|
|
183
244
|
}));
|
|
184
245
|
}
|
|
185
246
|
|
|
186
|
-
|
|
247
|
+
function InlineText(props) {
|
|
248
|
+
const ctx = React.useContext(Ctx);
|
|
249
|
+
return h(Inline, { nodes: parseInline(props.text, ctx.opts) });
|
|
250
|
+
}
|
|
251
|
+
const inline = (text) => h(InlineText, { text });
|
|
187
252
|
|
|
188
253
|
function List(props) {
|
|
189
254
|
const list = props.list;
|
|
@@ -223,11 +288,16 @@ function Blocks(props) {
|
|
|
223
288
|
}));
|
|
224
289
|
}
|
|
225
290
|
|
|
226
|
-
// <Markdown text="..." lang="de" /> shows the text; labels.markdown overrides the callout titles.
|
|
291
|
+
// <Markdown text="..." lang="de" /> shows the text; labels.markdown overrides the callout titles. pageLinks reads
|
|
292
|
+
// [[...]] as page links; render = {image, link, pagelink} puts the app's own elements in (Folio: images of the space,
|
|
293
|
+
// router links, resolved page links).
|
|
227
294
|
function Markdown(props) {
|
|
228
295
|
const L = Object.assign({}, labelsFor(props.lang).markdown, props.labels);
|
|
229
|
-
|
|
230
|
-
|
|
296
|
+
const ctx = React.useMemo(() => ({ render: props.render || {}, opts: props.pageLinks ? { pageLinks: true } : null }),
|
|
297
|
+
[props.render, props.pageLinks]);
|
|
298
|
+
return h(Ctx.Provider, { value: ctx },
|
|
299
|
+
h("div", { className: "scalio-md" + (props.className ? " " + props.className : ""), "data-testid": props.testId },
|
|
300
|
+
h(Blocks, { blocks: parseBlocks(props.text), labels: L })));
|
|
231
301
|
}
|
|
232
302
|
|
|
233
303
|
module.exports = {
|
|
@@ -236,5 +306,8 @@ module.exports = {
|
|
|
236
306
|
parseMarkdownInline: parseInline,
|
|
237
307
|
markdownOutline: outline,
|
|
238
308
|
markdownHeadingId: headingId,
|
|
309
|
+
markdownPageLinks: pageLinks,
|
|
310
|
+
markdownPageLinkKey: pageLinkKey,
|
|
311
|
+
parseMarkdownPageLink: parsePageLink,
|
|
239
312
|
safeHref,
|
|
240
313
|
};
|
package/react/nav.js
CHANGED
|
@@ -421,24 +421,66 @@ function ProductSwitcher({ current, links, stage, sso, lang, labels, products, t
|
|
|
421
421
|
|
|
422
422
|
// GET /api/apps once per page load. fetchApps returns a promise with the JSON answer.
|
|
423
423
|
// Until the answer is in (or on error) switcher and support stay hidden.
|
|
424
|
+
// A failed call is retried after 1, 2 and 4 s (options.retryDelays in ms), but not on 401/403/404 (error.response.status
|
|
425
|
+
// as with axios, or error.status). When the last component using the hook unmounts, a waiting retry is dropped;
|
|
426
|
+
// after the last retry the next mount asks again. All users share one call; the first caller's options count.
|
|
427
|
+
const SCALIO_APPS_RETRY_DELAYS = [1000, 2000, 4000];
|
|
424
428
|
let appsCache = null;
|
|
425
429
|
let appsPending = null;
|
|
430
|
+
let appsUsers = 0;
|
|
431
|
+
let appsAbort = null;
|
|
426
432
|
|
|
427
|
-
function
|
|
433
|
+
function errorStatus(e) {
|
|
434
|
+
return e && (e.status || (e.response && e.response.status));
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
function loadScalioApps(fetchApps, delays) {
|
|
438
|
+
let attempt = 0;
|
|
439
|
+
const run = () =>
|
|
440
|
+
Promise.resolve()
|
|
441
|
+
.then(fetchApps)
|
|
442
|
+
.catch((e) => {
|
|
443
|
+
const status = errorStatus(e);
|
|
444
|
+
if (status === 401 || status === 403 || status === 404 || attempt >= delays.length || appsUsers <= 0) throw e;
|
|
445
|
+
const pause = delays[attempt++];
|
|
446
|
+
return new Promise((resolve, reject) => {
|
|
447
|
+
const timer = setTimeout(() => {
|
|
448
|
+
appsAbort = null;
|
|
449
|
+
resolve(run());
|
|
450
|
+
}, pause);
|
|
451
|
+
appsAbort = () => {
|
|
452
|
+
clearTimeout(timer);
|
|
453
|
+
appsAbort = null;
|
|
454
|
+
reject(e);
|
|
455
|
+
};
|
|
456
|
+
});
|
|
457
|
+
});
|
|
458
|
+
return run().then((d) => {
|
|
459
|
+
appsCache = d || {};
|
|
460
|
+
return appsCache;
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
function useScalioApps(fetchApps, options) {
|
|
428
465
|
const [data, setData] = React.useState(appsCache);
|
|
466
|
+
const delays = (options && options.retryDelays) || SCALIO_APPS_RETRY_DELAYS;
|
|
429
467
|
React.useEffect(() => {
|
|
430
468
|
if (appsCache || !fetchApps) return undefined;
|
|
431
469
|
let alive = true;
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
appsPending.then((d) => alive && setData(d)).catch(() => {
|
|
441
|
-
return () => {
|
|
470
|
+
appsUsers++;
|
|
471
|
+
if (!appsPending) {
|
|
472
|
+
const pending = loadScalioApps(fetchApps, delays);
|
|
473
|
+
appsPending = pending;
|
|
474
|
+
pending.catch(() => {
|
|
475
|
+
if (appsPending === pending) appsPending = null;
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
appsPending.then((d) => alive && setData(d)).catch(() => {});
|
|
479
|
+
return () => {
|
|
480
|
+
alive = false;
|
|
481
|
+
appsUsers--;
|
|
482
|
+
if (appsUsers <= 0 && appsAbort) appsAbort();
|
|
483
|
+
};
|
|
442
484
|
}, [fetchApps]);
|
|
443
485
|
return {
|
|
444
486
|
links: (data && data.links) || {},
|
|
@@ -449,6 +491,7 @@ function useScalioApps(fetchApps) {
|
|
|
449
491
|
}
|
|
450
492
|
|
|
451
493
|
function resetScalioApps() {
|
|
494
|
+
if (appsAbort) appsAbort();
|
|
452
495
|
appsCache = null;
|
|
453
496
|
appsPending = null;
|
|
454
497
|
}
|
|
@@ -550,6 +593,7 @@ module.exports = {
|
|
|
550
593
|
stageBadge,
|
|
551
594
|
scalioFeatures,
|
|
552
595
|
useScalioApps,
|
|
596
|
+
SCALIO_APPS_RETRY_DELAYS,
|
|
553
597
|
resetScalioApps,
|
|
554
598
|
SupportDrawer,
|
|
555
599
|
visibleSections,
|