@xeonr/platform-ui 1.10.2 → 1.12.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/auth/AuthCode.d.ts +48 -0
- package/dist/auth/AuthCode.d.ts.map +1 -0
- package/dist/auth/AuthCode.js +197 -0
- package/dist/auth/AuthCode.js.map +1 -0
- package/dist/auth/AuthConsent.d.ts +69 -0
- package/dist/auth/AuthConsent.d.ts.map +1 -0
- package/dist/auth/AuthConsent.js +155 -0
- package/dist/auth/AuthConsent.js.map +1 -0
- package/dist/auth/AuthControls.d.ts +133 -0
- package/dist/auth/AuthControls.d.ts.map +1 -0
- package/dist/auth/AuthControls.js +379 -0
- package/dist/auth/AuthControls.js.map +1 -0
- package/dist/auth/AuthPanel.d.ts +106 -0
- package/dist/auth/AuthPanel.d.ts.map +1 -0
- package/dist/auth/AuthPanel.js +317 -0
- package/dist/auth/AuthPanel.js.map +1 -0
- package/dist/auth.d.ts +5 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +15 -0
- package/dist/auth.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/kit/Anchored.js +109 -109
- package/dist/kit/Anchored.js.map +1 -1
- package/dist/kit/ApiKeyForm.js +73 -73
- package/dist/kit/ApiKeyForm.js.map +1 -1
- package/dist/kit/ApiKeys.js +144 -144
- package/dist/kit/ApiKeys.js.map +1 -1
- package/dist/kit/Badge.js +45 -45
- package/dist/kit/Badge.js.map +1 -1
- package/dist/kit/Blocks.d.ts.map +1 -1
- package/dist/kit/Blocks.js +103 -102
- package/dist/kit/Blocks.js.map +1 -1
- package/dist/kit/Board.js +54 -54
- package/dist/kit/Board.js.map +1 -1
- package/dist/kit/Button.d.ts +3 -3
- package/dist/kit/Button.d.ts.map +1 -1
- package/dist/kit/Button.js +55 -50
- package/dist/kit/Button.js.map +1 -1
- package/dist/kit/Card.d.ts.map +1 -1
- package/dist/kit/Card.js +36 -29
- package/dist/kit/Card.js.map +1 -1
- package/dist/kit/ChartFrame.js +54 -54
- package/dist/kit/ChartFrame.js.map +1 -1
- package/dist/kit/ChartTypes.js +215 -215
- package/dist/kit/ChartTypes.js.map +1 -1
- package/dist/kit/Charts.js +605 -605
- package/dist/kit/Charts.js.map +1 -1
- package/dist/kit/Checkbox.js +16 -16
- package/dist/kit/Checkbox.js.map +1 -1
- package/dist/kit/Chip.js +21 -21
- package/dist/kit/Chip.js.map +1 -1
- package/dist/kit/Choice.js +24 -24
- package/dist/kit/Choice.js.map +1 -1
- package/dist/kit/CodeEditor.d.ts.map +1 -1
- package/dist/kit/CodeEditor.js +26 -48
- package/dist/kit/CodeEditor.js.map +1 -1
- package/dist/kit/Color.js +74 -74
- package/dist/kit/Color.js.map +1 -1
- package/dist/kit/Combobox.js +67 -67
- package/dist/kit/Combobox.js.map +1 -1
- package/dist/kit/CommandPalette.d.ts.map +1 -1
- package/dist/kit/CommandPalette.js +96 -86
- package/dist/kit/CommandPalette.js.map +1 -1
- package/dist/kit/Comment.js +7 -7
- package/dist/kit/Comment.js.map +1 -1
- package/dist/kit/Controls.js +122 -122
- package/dist/kit/Controls.js.map +1 -1
- package/dist/kit/DataGrid.js +97 -97
- package/dist/kit/DataGrid.js.map +1 -1
- package/dist/kit/DataTable.d.ts.map +1 -1
- package/dist/kit/DataTable.js +196 -195
- package/dist/kit/DataTable.js.map +1 -1
- package/dist/kit/DatePicker.js +242 -242
- package/dist/kit/DatePicker.js.map +1 -1
- package/dist/kit/Drawer.d.ts.map +1 -1
- package/dist/kit/Drawer.js +15 -14
- package/dist/kit/Drawer.js.map +1 -1
- package/dist/kit/Dropzone.js +80 -80
- package/dist/kit/Dropzone.js.map +1 -1
- package/dist/kit/Editable.d.ts.map +1 -1
- package/dist/kit/Editable.js +130 -129
- package/dist/kit/Editable.js.map +1 -1
- package/dist/kit/EmptyState.d.ts.map +1 -1
- package/dist/kit/EmptyState.js +14 -13
- package/dist/kit/EmptyState.js.map +1 -1
- package/dist/kit/EntityHeader.d.ts.map +1 -1
- package/dist/kit/EntityHeader.js +17 -16
- package/dist/kit/EntityHeader.js.map +1 -1
- package/dist/kit/Facet.js +52 -52
- package/dist/kit/Facet.js.map +1 -1
- package/dist/kit/FacetRail.js +91 -91
- package/dist/kit/FacetRail.js.map +1 -1
- package/dist/kit/Forbidden.js +7 -7
- package/dist/kit/Forbidden.js.map +1 -1
- package/dist/kit/Form.d.ts.map +1 -1
- package/dist/kit/Form.js +144 -143
- package/dist/kit/Form.js.map +1 -1
- package/dist/kit/Graph.d.ts +14 -3
- package/dist/kit/Graph.d.ts.map +1 -1
- package/dist/kit/Graph.js +473 -314
- package/dist/kit/Graph.js.map +1 -1
- package/dist/kit/GroupedMultiSelect.js +115 -115
- package/dist/kit/GroupedMultiSelect.js.map +1 -1
- package/dist/kit/Icon.d.ts +2 -0
- package/dist/kit/Icon.d.ts.map +1 -1
- package/dist/kit/Icon.js +3 -1
- package/dist/kit/Icon.js.map +1 -1
- package/dist/kit/JumpList.js +11 -11
- package/dist/kit/JumpList.js.map +1 -1
- package/dist/kit/KV.js +6 -6
- package/dist/kit/KV.js.map +1 -1
- package/dist/kit/Layout.js +5 -5
- package/dist/kit/Layout.js.map +1 -1
- package/dist/kit/List.js +74 -74
- package/dist/kit/List.js.map +1 -1
- package/dist/kit/LogView.js +68 -68
- package/dist/kit/LogView.js.map +1 -1
- package/dist/kit/Markdown.js +37 -37
- package/dist/kit/Markdown.js.map +1 -1
- package/dist/kit/Marker.js +42 -42
- package/dist/kit/Marker.js.map +1 -1
- package/dist/kit/Menu.js +128 -128
- package/dist/kit/Menu.js.map +1 -1
- package/dist/kit/Modal.d.ts.map +1 -1
- package/dist/kit/Modal.js +86 -75
- package/dist/kit/Modal.js.map +1 -1
- package/dist/kit/MultiCombobox.js +157 -157
- package/dist/kit/MultiCombobox.js.map +1 -1
- package/dist/kit/PageHeader.d.ts.map +1 -1
- package/dist/kit/PageHeader.js +8 -7
- package/dist/kit/PageHeader.js.map +1 -1
- package/dist/kit/Panel.d.ts.map +1 -1
- package/dist/kit/Panel.js +33 -14
- package/dist/kit/Panel.js.map +1 -1
- package/dist/kit/Picker.js +159 -159
- package/dist/kit/Picker.js.map +1 -1
- package/dist/kit/PipelineFlow.js +86 -86
- package/dist/kit/PipelineFlow.js.map +1 -1
- package/dist/kit/Popover.js +67 -67
- package/dist/kit/Popover.js.map +1 -1
- package/dist/kit/Range.js +76 -76
- package/dist/kit/Range.js.map +1 -1
- package/dist/kit/Reorder.js +95 -95
- package/dist/kit/Reorder.js.map +1 -1
- package/dist/kit/Search.js +27 -27
- package/dist/kit/Search.js.map +1 -1
- package/dist/kit/Secret.js +26 -26
- package/dist/kit/Secret.js.map +1 -1
- package/dist/kit/Skeleton.js +14 -14
- package/dist/kit/Skeleton.js.map +1 -1
- package/dist/kit/Sparkline.js +51 -51
- package/dist/kit/Sparkline.js.map +1 -1
- package/dist/kit/Spectrum.js +163 -163
- package/dist/kit/Spectrum.js.map +1 -1
- package/dist/kit/Splash.js +3 -3
- package/dist/kit/Splash.js.map +1 -1
- package/dist/kit/Split.js +13 -13
- package/dist/kit/Split.js.map +1 -1
- package/dist/kit/SplitButton.d.ts.map +1 -1
- package/dist/kit/SplitButton.js +8 -6
- package/dist/kit/SplitButton.js.map +1 -1
- package/dist/kit/Stat.d.ts.map +1 -1
- package/dist/kit/Stat.js +61 -60
- package/dist/kit/Stat.js.map +1 -1
- package/dist/kit/Stepper.js +22 -22
- package/dist/kit/Stepper.js.map +1 -1
- package/dist/kit/TabStrip.js +68 -68
- package/dist/kit/TabStrip.js.map +1 -1
- package/dist/kit/Text.js +63 -63
- package/dist/kit/Text.js.map +1 -1
- package/dist/kit/Toast.js +29 -29
- package/dist/kit/Toast.js.map +1 -1
- package/dist/kit/Tooltip.js +83 -83
- package/dist/kit/Tooltip.js.map +1 -1
- package/dist/kit/Trace.js +33 -33
- package/dist/kit/Trace.js.map +1 -1
- package/dist/kit/Upload.js +88 -88
- package/dist/kit/Upload.js.map +1 -1
- package/dist/kit/graphLayout.d.ts +32 -0
- package/dist/kit/graphLayout.d.ts.map +1 -0
- package/dist/kit/graphLayout.js +179 -0
- package/dist/kit/graphLayout.js.map +1 -0
- package/dist/theme/ThemeProvider.d.ts +17 -1
- package/dist/theme/ThemeProvider.d.ts.map +1 -1
- package/dist/theme/ThemeProvider.js +40 -4
- package/dist/theme/ThemeProvider.js.map +1 -1
- package/dist/theme/ThemeScope.d.ts +9 -1
- package/dist/theme/ThemeScope.d.ts.map +1 -1
- package/dist/theme/ThemeScope.js +11 -4
- package/dist/theme/ThemeScope.js.map +1 -1
- package/dist/theme/tokens.d.ts +74 -0
- package/dist/theme/tokens.d.ts.map +1 -1
- package/dist/theme/tokens.js +197 -3
- package/dist/theme/tokens.js.map +1 -1
- package/package.json +12 -6
- package/scripts/check-colour-literals.mjs +5 -1
- package/scripts/stable-styled-ids.mjs +75 -0
package/dist/kit/Trace.js
CHANGED
|
@@ -16,48 +16,48 @@ import { Icon } from "./Icon.js";
|
|
|
16
16
|
// `setTraceLinks` and `setErrorReporter`.
|
|
17
17
|
const HEX32 = /^[0-9a-f]{32}$/;
|
|
18
18
|
function norm(raw) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
if (typeof raw !== "string")
|
|
20
|
+
return undefined;
|
|
21
|
+
const id = raw.trim().toLowerCase().replace(/-/g, "");
|
|
22
|
+
return HEX32.test(id) && !/^0+$/.test(id) ? id : undefined;
|
|
23
23
|
}
|
|
24
24
|
function header(bag) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
if (typeof bag !== "object" || bag === null || typeof bag.get !== "function")
|
|
26
|
+
return undefined;
|
|
27
|
+
return norm(bag.get("x-trace-id"));
|
|
28
28
|
}
|
|
29
29
|
/** The X-Trace-Id behind an error or a response (its metadata, headers, `traceId`, or its cause's), or undefined. */
|
|
30
30
|
export function traceIdOf(e, depth = 0) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
if (typeof e !== "object" || e === null || depth > 3)
|
|
32
|
+
return undefined;
|
|
33
|
+
try {
|
|
34
|
+
const o = e;
|
|
35
|
+
return header(o.metadata) ?? header(o.headers) ?? norm(o.traceId) ?? traceIdOf(o.response, depth + 1) ?? traceIdOf(o.cause, depth + 1);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
40
|
}
|
|
41
41
|
let traceHref;
|
|
42
42
|
let reporter;
|
|
43
43
|
/** Where a trace id links to (Lantern's trace view), or undefined for no link. One per page; console-shell sets it. */
|
|
44
44
|
export function setTraceLinks(fn) {
|
|
45
|
-
|
|
45
|
+
traceHref = fn;
|
|
46
46
|
}
|
|
47
47
|
/** Who hears about an error shown in a toast (`useToast().error`). One per page; console-shell sets it to telemetry. */
|
|
48
48
|
export function setErrorReporter(fn) {
|
|
49
|
-
|
|
49
|
+
reporter = fn;
|
|
50
50
|
}
|
|
51
51
|
/** @internal the toast's hook into the page's reporter. Never throws. */
|
|
52
52
|
export function reportShownError(err, traceId) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
53
|
+
try {
|
|
54
|
+
reporter?.(err, { source: "toast", traceId });
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
|
|
58
|
+
/* a reporter never breaks the toast */}
|
|
59
59
|
}
|
|
60
|
-
const Wrap = styled.span `
|
|
60
|
+
const Wrap = styled.span.withConfig({ componentId: "sc-zbw6kb-0" })`
|
|
61
61
|
display: inline-flex;
|
|
62
62
|
align-items: center;
|
|
63
63
|
gap: 2px;
|
|
@@ -65,22 +65,22 @@ const Wrap = styled.span `
|
|
|
65
65
|
font-size: 11px;
|
|
66
66
|
color: ${v.faint};
|
|
67
67
|
`;
|
|
68
|
-
const Id = styled.code `
|
|
68
|
+
const Id = styled.code.withConfig({ componentId: "sc-zbw6kb-1" })`
|
|
69
69
|
font-family: ${v.mono};
|
|
70
70
|
font-size: 10.5px;
|
|
71
71
|
color: ${v.muted};
|
|
72
72
|
border: 1px solid ${v.line2};
|
|
73
|
-
border-radius: 5px;
|
|
73
|
+
border-radius: min(5px, ${v.rCtl});
|
|
74
74
|
padding: 1px 6px;
|
|
75
75
|
white-space: nowrap;
|
|
76
76
|
cursor: help;
|
|
77
77
|
`;
|
|
78
|
-
const Open = styled.a `
|
|
78
|
+
const Open = styled.a.withConfig({ componentId: "sc-zbw6kb-2" })`
|
|
79
79
|
display: inline-flex;
|
|
80
80
|
align-items: center;
|
|
81
81
|
padding: 3px 5px;
|
|
82
82
|
color: ${v.faint};
|
|
83
|
-
border-radius: 5px;
|
|
83
|
+
border-radius: min(5px, ${v.rCtl});
|
|
84
84
|
&:hover { color: ${v.text}; background: ${v.hover}; }
|
|
85
85
|
`;
|
|
86
86
|
/**
|
|
@@ -90,8 +90,8 @@ const Open = styled.a `
|
|
|
90
90
|
* explicit `href`); `href={null}` suppresses it.
|
|
91
91
|
*/
|
|
92
92
|
export function TraceRef({ id, href }) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
const full = norm(id) ?? id;
|
|
94
|
+
const link = href === null ? undefined : href ?? traceHref?.(full);
|
|
95
|
+
return _jsxs(Wrap, { children: [_jsxs(Id, { title: full, children: ["trace ", full.slice(0, 8), "\u2026"] }), _jsx(CopyIcon, { text: full, label: "Copy trace id" }), link ? _jsx(Open, { href: link, target: "_blank", rel: "noreferrer", "aria-label": "Open trace", title: "Open trace", children: _jsx(Icon, { name: "external" }) }) : null] });
|
|
96
96
|
}
|
|
97
|
-
//# sourceMappingURL=Trace.js.map
|
|
97
|
+
//# sourceMappingURL=Trace.js.map
|
package/dist/kit/Trace.js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,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,cAAO,EAC/C,KAAC,QAAQ,IAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAC,eAAe,GAAG,EAC7C,IAAI,GACH,KAAC,IAAI,IAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAC,QAAQ,EAAC,GAAG,EAAC,YAAY,gBAAY,YAAY,EAAC,KAAK,EAAC,YAAY,YAC3F,KAAC,IAAI,IAAC,IAAI,EAAC,UAAU,GAAG,GACnB,GACL,IAAI,IACH;AAEX","ignoreList":[]}
|
package/dist/kit/Upload.js
CHANGED
|
@@ -10,32 +10,32 @@ import { InlineError } from "./Form.js";
|
|
|
10
10
|
import { AppButton } from "./Button.js";
|
|
11
11
|
/** The whole file's digest as lowercase hex. Reads the file into memory: fine for installers, not for a multi-gigabyte archive. */
|
|
12
12
|
export async function digestFile(file, algorithm = "SHA-512") {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
const buffer = await file.arrayBuffer();
|
|
14
|
+
const hash = await crypto.subtle.digest(algorithm, buffer);
|
|
15
|
+
return Array.from(new Uint8Array(hash)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
16
16
|
}
|
|
17
17
|
/** One PUT with upload progress, resolving with the response's ETag (empty when the origin does not expose it). */
|
|
18
18
|
export function putWithProgress(url, body, opts = {}) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
const xhr = new XMLHttpRequest();
|
|
21
|
+
xhr.open("PUT", url);
|
|
22
|
+
if (opts.contentType)
|
|
23
|
+
xhr.setRequestHeader("Content-Type", opts.contentType);
|
|
24
|
+
xhr.upload.onprogress = (e) => opts.onProgress?.(e.loaded);
|
|
25
|
+
xhr.onload = () => {
|
|
26
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
27
|
+
opts.onProgress?.(body.size);
|
|
28
|
+
resolve(xhr.getResponseHeader("ETag") ?? "");
|
|
29
|
+
} else
|
|
30
|
+
{
|
|
31
|
+
reject(new Error(`storage refused the upload (HTTP ${xhr.status})`));
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
xhr.onerror = () => reject(new Error("the upload to storage failed — the network dropped, or storage refused the origin"));
|
|
35
|
+
xhr.onabort = () => reject(new DOMException("upload cancelled", "AbortError"));
|
|
36
|
+
opts.signal?.addEventListener("abort", () => xhr.abort(), { once: true });
|
|
37
|
+
xhr.send(body);
|
|
38
|
+
});
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
41
|
* PUT a file's parts to their presigned URLs, sliced at the plan's offsets,
|
|
@@ -43,36 +43,36 @@ export function putWithProgress(url, body, opts = {}) {
|
|
|
43
43
|
* completing call wants.
|
|
44
44
|
*/
|
|
45
45
|
export async function uploadInParts(file, parts, opts = {}) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
46
|
+
const ordered = [...parts].sort((a, b) => a.partNumber - b.partNumber);
|
|
47
|
+
let offset = 0;
|
|
48
|
+
const jobs = ordered.map((part) => {
|
|
49
|
+
const start = offset;
|
|
50
|
+
offset += part.sizeBytes;
|
|
51
|
+
return { part, blob: file.slice(start, offset) };
|
|
52
|
+
});
|
|
53
|
+
if (offset !== file.size)
|
|
54
|
+
throw new Error(`the server planned ${offset} bytes for a ${file.size}-byte file`);
|
|
55
|
+
const sent = new Map();
|
|
56
|
+
const report = () => opts.onProgress?.([...sent.values()].reduce((a, b) => a + b, 0));
|
|
57
|
+
const etags = [];
|
|
58
|
+
let next = 0;
|
|
59
|
+
const worker = async () => {
|
|
60
|
+
while (next < jobs.length) {
|
|
61
|
+
const job = jobs[next++];
|
|
62
|
+
if (!job)
|
|
63
|
+
return;
|
|
64
|
+
const etag = await putWithProgress(job.part.uploadUrl, job.blob, {
|
|
65
|
+
contentType: null,
|
|
66
|
+
signal: opts.signal,
|
|
67
|
+
onProgress: (n) => {sent.set(job.part.partNumber, n);report();}
|
|
68
|
+
});
|
|
69
|
+
if (!etag)
|
|
70
|
+
throw new Error("storage did not expose the part's ETag (CORS ExposeHeaders), so the upload cannot be completed");
|
|
71
|
+
etags.push({ partNumber: job.part.partNumber, etag });
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
await Promise.all(Array.from({ length: Math.min(opts.concurrency ?? 4, jobs.length) }, worker));
|
|
75
|
+
return etags.sort((a, b) => a.partNumber - b.partNumber);
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
78
|
* Send a file as its plan says: the parts when there are any, else the one
|
|
@@ -80,46 +80,46 @@ export async function uploadInParts(file, parts, opts = {}) {
|
|
|
80
80
|
* confirming call.
|
|
81
81
|
*/
|
|
82
82
|
export async function uploadPlanned(file, plan, opts = {}) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
83
|
+
if (plan.parts && plan.parts.length > 0)
|
|
84
|
+
return uploadInParts(file, plan.parts, opts);
|
|
85
|
+
if (!plan.uploadUrl)
|
|
86
|
+
throw new Error("the server returned no upload URL and no parts");
|
|
87
|
+
await putWithProgress(plan.uploadUrl, file, { contentType: opts.contentType ?? (file.type || "application/octet-stream"), signal: opts.signal, onProgress: opts.onProgress });
|
|
88
|
+
return [];
|
|
89
89
|
}
|
|
90
90
|
/** Bytes for a label: 1.5 MB, 240 KB, 3 GB. */
|
|
91
91
|
export function fmtBytes(n) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
92
|
+
if (n === undefined)
|
|
93
|
+
return "—";
|
|
94
|
+
let val = Number(n);
|
|
95
|
+
const units = ["B", "KB", "MB", "GB", "TB", "PB"];
|
|
96
|
+
let i = 0;
|
|
97
|
+
while (val >= 1024 && i < units.length - 1) {
|
|
98
|
+
val /= 1024;
|
|
99
|
+
i++;
|
|
100
|
+
}
|
|
101
|
+
return `${val < 10 && i > 0 ? val.toFixed(2) : val < 100 && i > 0 ? val.toFixed(1) : Math.round(val)} ${units[i]}`;
|
|
102
102
|
}
|
|
103
103
|
const PILL = {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
104
|
+
queued: { label: "Queued", tone: "mut" },
|
|
105
|
+
hashing: { label: "Hashing", tone: "info", live: true },
|
|
106
|
+
uploading: { label: "Uploading", tone: "info", live: true },
|
|
107
|
+
confirming: { label: "Confirming", tone: "info", live: true },
|
|
108
|
+
done: { label: "Uploaded", tone: "ok" },
|
|
109
|
+
failed: { label: "Failed", tone: "crit" },
|
|
110
|
+
cancelled: { label: "Cancelled", tone: "mut" }
|
|
111
111
|
};
|
|
112
112
|
/** Whether a transfer is still going, so a Cancel can apply to it. */
|
|
113
113
|
export function transferActive(status) {
|
|
114
|
-
|
|
114
|
+
return status === "queued" || status === "hashing" || status === "uploading" || status === "confirming";
|
|
115
115
|
}
|
|
116
|
-
const Lines = styled.div `
|
|
116
|
+
const Lines = styled.div.withConfig({ componentId: "sc-1ucd3fz-0" })`
|
|
117
117
|
display: flex;
|
|
118
118
|
flex-direction: column;
|
|
119
119
|
gap: 4px;
|
|
120
120
|
min-width: 0;
|
|
121
121
|
`;
|
|
122
|
-
const Sub = styled.div `
|
|
122
|
+
const Sub = styled.div.withConfig({ componentId: "sc-1ucd3fz-1" })`
|
|
123
123
|
display: flex;
|
|
124
124
|
align-items: center;
|
|
125
125
|
gap: 8px;
|
|
@@ -128,19 +128,19 @@ const Sub = styled.div `
|
|
|
128
128
|
`;
|
|
129
129
|
/** One file going up: its name, a meter while it moves, its status, and Cancel while it can still be cancelled. */
|
|
130
130
|
export function TransferRow({ item, onCancel }) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
const pill = PILL[item.status];
|
|
132
|
+
const moving = item.status === "uploading";
|
|
133
|
+
return _jsx(ListRow, { dense: true, leading: _jsx(Icon, { name: item.status === "done" ? "check" : item.status === "failed" ? "error" : "file" }), trailing: _jsx(StatusPill, { "$tone": pill.tone, "$live": pill.live, children: pill.label }), actions: onCancel && transferActive(item.status) ? _jsx(AppButton, { size: "xs", variant: "quiet", icon: "stop", onClick: () => onCancel(item.id), children: "Cancel" }) : undefined, keepActions: true, children: _jsxs(Lines, { children: [_jsx(Mono, { "$truncate": true, title: item.name, children: item.name }), item.meta ? _jsx(Sub, { children: item.meta }) : null, moving ? _jsx(Meter, { value: item.loaded, max: Math.max(item.size, 1), tone: "brand", label: `${fmtBytes(item.loaded)} of ${fmtBytes(item.size)}` }) : item.status === "failed" && item.error ? _jsx(InlineError, { children: item.error }) : _jsx(Faint, { children: fmtBytes(item.size) })] }) });
|
|
134
134
|
}
|
|
135
135
|
/**
|
|
136
136
|
* The transfers in flight and just finished, with one meter for the whole
|
|
137
137
|
* batch above the rows when more than one file is moving.
|
|
138
138
|
*/
|
|
139
139
|
export function TransferList({ items, onCancel, empty }) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
140
|
+
if (items.length === 0)
|
|
141
|
+
return empty ? _jsx(Faint, { children: empty }) : null;
|
|
142
|
+
const sent = items.reduce((a, i) => a + (i.status === "done" ? i.size : i.loaded), 0);
|
|
143
|
+
const total = items.reduce((a, i) => a + i.size, 0);
|
|
144
|
+
return _jsxs(Lines, { children: [items.length > 1 && items.some((i) => transferActive(i.status)) ? _jsx(Meter, { value: sent, max: Math.max(total, 1), tone: "brand", label: `${fmtBytes(sent)} of ${fmtBytes(total)}` }) : null, _jsx(RowList, { children: items.map((item) => _jsx(TransferRow, { item: item, onCancel: onCancel }, item.id)) })] });
|
|
145
145
|
}
|
|
146
|
-
//# sourceMappingURL=Upload.js.map
|
|
146
|
+
//# sourceMappingURL=Upload.js.map
|
package/dist/kit/Upload.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":[],"sources":["../../src/kit/Upload.tsx"],"sourcesContent":[null],"mappings":";AAAA,OAAO,MAAM,MAAM,mBAAmB;AAEtC,SAAS,CAAC,QAAQ,oBAAoB;AACtC,SAAS,IAAI,QAAQ,WAAY;AACjC,SAAS,OAAO,EAAE,OAAO,QAAQ,WAAY;AAC7C,SAAS,KAAK,QAAQ,WAAY;AAClC,SAAS,UAAU,QAAQ,YAAa;AACxC,SAAS,KAAK,EAAE,IAAI,QAAQ,WAAY;AACxC,SAAS,WAAW,QAAQ,WAAY;AACxC,SAAS,SAAS,QAAQ,aAAc;AAmBxC;AACA,OAAO,eAAe,UAAU,CAAC,IAAU,EAAE,YAA6B,SAAS;EACjF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,WAAW,EAAE;EACvC,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC;EAC1D,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CA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CAAC,GAC9D,KAAC,KAAK,IAAC,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,IAAI,EAAC,OAAO,EAAC,KAAK,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,QAAQ,CAAC,KAAK,CAAC,EAAE,GAAI,GAC5G,IAAI,EACR,KAAC,OAAO,cACL,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,KAAC,WAAW,IAAe,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,IAAvC,IAAI,CAAC,EAAE,CAAoC,CAAC,GAC3E,IACJ;AAEZ","ignoreList":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface LayoutEdge {
|
|
2
|
+
id: string;
|
|
3
|
+
from: string;
|
|
4
|
+
to: string;
|
|
5
|
+
}
|
|
6
|
+
/** One slot in a column: a node, or the slot an edge passes through. */
|
|
7
|
+
export type LayoutSlot = {
|
|
8
|
+
kind: "node";
|
|
9
|
+
id: string;
|
|
10
|
+
} | {
|
|
11
|
+
kind: "pass";
|
|
12
|
+
edge: string;
|
|
13
|
+
};
|
|
14
|
+
export interface LayeredLayout {
|
|
15
|
+
/** each node's column (its depth: the longest chain of edges into it) */
|
|
16
|
+
column: Map<string, number>;
|
|
17
|
+
/** the columns, left to right, each top to bottom */
|
|
18
|
+
columns: LayoutSlot[][];
|
|
19
|
+
/** the edges drawn, after `reduce`; edges naming an unknown node, self-loops and those closing a cycle are dropped */
|
|
20
|
+
edges: LayoutEdge[];
|
|
21
|
+
/** for each edge drawn, the slot index it passes through in each column strictly between its ends, left to right */
|
|
22
|
+
passes: Map<string, number[]>;
|
|
23
|
+
/** each node's ancestors and descendants over every edge given (not only those drawn): what highlighting a node lights */
|
|
24
|
+
related: (id: string) => Set<string>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Lay a graph out in columns. `nodes` is the caller's order, which breaks ties
|
|
28
|
+
* (siblings keep it when the crossings are equal). With `reduce`, an edge
|
|
29
|
+
* implied by a longer path (a→c when a→b→c) is not drawn.
|
|
30
|
+
*/
|
|
31
|
+
export declare function layeredLayout(nodes: readonly string[], edgesIn: readonly LayoutEdge[], reduce: boolean): LayeredLayout;
|
|
32
|
+
//# sourceMappingURL=graphLayout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphLayout.d.ts","sourceRoot":"","sources":["../../src/kit/graphLayout.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,wEAAwE;AACxE,MAAM,MAAM,UAAU,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvF,MAAM,WAAW,aAAa;IAC5B,yEAAyE;IACzE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,qDAAqD;IACrD,OAAO,EAAE,UAAU,EAAE,EAAE,CAAC;IACxB,sHAAsH;IACtH,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,oHAAoH;IACpH,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC9B,0HAA0H;IAC1H,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,GAAG,CAAC,MAAM,CAAC,CAAC;CACtC;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,SAAS,UAAU,EAAE,EAAE,MAAM,EAAE,OAAO,GAAG,aAAa,CAyJtH"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// The layered layout behind `<Graph layout="layered">`: a DAG in columns by
|
|
2
|
+
// dependency depth, nodes in one column stacked, ordered to cross as few edges
|
|
3
|
+
// as a few barycentre sweeps can manage, and every edge that spans more than
|
|
4
|
+
// one column given a slot of its own in each column it passes through, so it
|
|
5
|
+
// is drawn through an empty slot and never under a node. Pure, so it is tested
|
|
6
|
+
// on its own and a console can lay out its own list view the same way.
|
|
7
|
+
/**
|
|
8
|
+
* Lay a graph out in columns. `nodes` is the caller's order, which breaks ties
|
|
9
|
+
* (siblings keep it when the crossings are equal). With `reduce`, an edge
|
|
10
|
+
* implied by a longer path (a→c when a→b→c) is not drawn.
|
|
11
|
+
*/
|
|
12
|
+
export function layeredLayout(nodes, edgesIn, reduce) {
|
|
13
|
+
const known = new Set(nodes);
|
|
14
|
+
const place = new Map(nodes.map((n, i) => [n, i]));
|
|
15
|
+
// Edges between known nodes, without self-loops or duplicates, and without
|
|
16
|
+
// any edge that would close a cycle (taken in the caller's order).
|
|
17
|
+
const out = new Map(nodes.map((n) => [n, []]));
|
|
18
|
+
const all = [];
|
|
19
|
+
const seen = new Set();
|
|
20
|
+
const reaches = (a, b) => {
|
|
21
|
+
const stack = [a];
|
|
22
|
+
const visited = new Set();
|
|
23
|
+
while (stack.length) {
|
|
24
|
+
const x = stack.pop();
|
|
25
|
+
if (x === b)
|
|
26
|
+
return true;
|
|
27
|
+
if (visited.has(x))
|
|
28
|
+
continue;
|
|
29
|
+
visited.add(x);
|
|
30
|
+
stack.push(...(out.get(x) ?? []));
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
};
|
|
34
|
+
for (const e of edgesIn) {
|
|
35
|
+
if (!known.has(e.from) || !known.has(e.to) || e.from === e.to)
|
|
36
|
+
continue;
|
|
37
|
+
const key = `${e.from}\u0000${e.to}`;
|
|
38
|
+
if (seen.has(key) || reaches(e.to, e.from))
|
|
39
|
+
continue;
|
|
40
|
+
seen.add(key);
|
|
41
|
+
out.get(e.from).push(e.to);
|
|
42
|
+
all.push(e);
|
|
43
|
+
}
|
|
44
|
+
const inn = new Map(nodes.map((n) => [n, []]));
|
|
45
|
+
for (const e of all)
|
|
46
|
+
inn.get(e.to).push(e.from);
|
|
47
|
+
// Depth: the longest chain into a node.
|
|
48
|
+
const column = new Map();
|
|
49
|
+
const depth = (n) => {
|
|
50
|
+
const known = column.get(n);
|
|
51
|
+
if (known !== undefined)
|
|
52
|
+
return known;
|
|
53
|
+
let d = 0;
|
|
54
|
+
for (const p of inn.get(n))
|
|
55
|
+
d = Math.max(d, depth(p) + 1);
|
|
56
|
+
column.set(n, d);
|
|
57
|
+
return d;
|
|
58
|
+
};
|
|
59
|
+
for (const n of nodes)
|
|
60
|
+
depth(n);
|
|
61
|
+
// Transitive reduction: drop a→c when c is reachable from a without it.
|
|
62
|
+
const drawn = reduce
|
|
63
|
+
? all.filter((e) => {
|
|
64
|
+
const stack = out.get(e.from).filter((x) => x !== e.to);
|
|
65
|
+
const visited = new Set();
|
|
66
|
+
while (stack.length) {
|
|
67
|
+
const x = stack.pop();
|
|
68
|
+
if (x === e.to)
|
|
69
|
+
return false;
|
|
70
|
+
if (visited.has(x))
|
|
71
|
+
continue;
|
|
72
|
+
visited.add(x);
|
|
73
|
+
stack.push(...out.get(x));
|
|
74
|
+
}
|
|
75
|
+
return true;
|
|
76
|
+
})
|
|
77
|
+
: all;
|
|
78
|
+
// Columns with a pass-through slot per long edge.
|
|
79
|
+
const width = Math.max(0, ...column.values()) + 1;
|
|
80
|
+
const columns = Array.from({ length: width }, () => []);
|
|
81
|
+
for (const n of [...nodes].sort((a, b) => place.get(a) - place.get(b)))
|
|
82
|
+
columns[column.get(n)].push({ kind: "node", id: n });
|
|
83
|
+
for (const e of drawn) {
|
|
84
|
+
for (let c = column.get(e.from) + 1; c < column.get(e.to); c++)
|
|
85
|
+
columns[c].push({ kind: "pass", edge: e.id });
|
|
86
|
+
}
|
|
87
|
+
// Each slot's neighbours in the columns either side: a node's drawn edges,
|
|
88
|
+
// a pass's previous and next slot along its edge.
|
|
89
|
+
const keyOf = (s) => (s.kind === "node" ? `n:${s.id}` : `p:${s.edge}`);
|
|
90
|
+
const left = new Map();
|
|
91
|
+
const right = new Map();
|
|
92
|
+
const link = (a, b) => {
|
|
93
|
+
(right.get(a) ?? right.set(a, []).get(a)).push(b);
|
|
94
|
+
(left.get(b) ?? left.set(b, []).get(b)).push(a);
|
|
95
|
+
};
|
|
96
|
+
for (const e of drawn) {
|
|
97
|
+
const chain = [`n:${e.from}`];
|
|
98
|
+
for (let c = column.get(e.from) + 1; c < column.get(e.to); c++)
|
|
99
|
+
chain.push(`p:${e.id}@${c}`);
|
|
100
|
+
chain.push(`n:${e.to}`);
|
|
101
|
+
for (let i = 0; i + 1 < chain.length; i++)
|
|
102
|
+
link(chain[i], chain[i + 1]);
|
|
103
|
+
}
|
|
104
|
+
const slotKey = (s, c) => (s.kind === "node" ? keyOf(s) : `p:${s.edge}@${c}`);
|
|
105
|
+
// Barycentre sweeps, keeping the order with the fewest crossings.
|
|
106
|
+
const crossings = (cols) => {
|
|
107
|
+
let total = 0;
|
|
108
|
+
for (let c = 0; c + 1 < cols.length; c++) {
|
|
109
|
+
const pos = new Map(cols[c + 1].map((s, i) => [slotKey(s, c + 1), i]));
|
|
110
|
+
const segs = [];
|
|
111
|
+
cols[c].forEach((s, i) => {
|
|
112
|
+
for (const r of right.get(slotKey(s, c)) ?? []) {
|
|
113
|
+
const j = pos.get(r);
|
|
114
|
+
if (j !== undefined)
|
|
115
|
+
segs.push([i, j]);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
for (let a = 0; a < segs.length; a++)
|
|
119
|
+
for (let b = a + 1; b < segs.length; b++) {
|
|
120
|
+
const [i1, j1] = segs[a];
|
|
121
|
+
const [i2, j2] = segs[b];
|
|
122
|
+
if ((i1 - i2) * (j1 - j2) < 0)
|
|
123
|
+
total++;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return total;
|
|
127
|
+
};
|
|
128
|
+
const sortBy = (cols, c, ref, side) => {
|
|
129
|
+
const pos = new Map(cols[ref].map((s, i) => [slotKey(s, ref), i]));
|
|
130
|
+
const was = new Map(cols[c].map((s, i) => [slotKey(s, c), i]));
|
|
131
|
+
const bary = (s) => {
|
|
132
|
+
const ns = (side.get(slotKey(s, c)) ?? []).map((k) => pos.get(k)).filter((x) => x !== undefined);
|
|
133
|
+
return ns.length ? ns.reduce((a, b) => a + b, 0) / ns.length : was.get(slotKey(s, c));
|
|
134
|
+
};
|
|
135
|
+
cols[c] = [...cols[c]].map((s) => ({ s, b: bary(s), w: was.get(slotKey(s, c)) })).sort((x, y) => x.b - y.b || x.w - y.w).map((x) => x.s);
|
|
136
|
+
};
|
|
137
|
+
let cols = columns.map((c) => [...c]);
|
|
138
|
+
let best = cols.map((c) => [...c]);
|
|
139
|
+
let bestCross = crossings(cols);
|
|
140
|
+
for (let round = 0; round < 8 && bestCross > 0; round++) {
|
|
141
|
+
if (round % 2 === 0)
|
|
142
|
+
for (let c = 1; c < cols.length; c++)
|
|
143
|
+
sortBy(cols, c, c - 1, left);
|
|
144
|
+
else
|
|
145
|
+
for (let c = cols.length - 2; c >= 0; c--)
|
|
146
|
+
sortBy(cols, c, c + 1, right);
|
|
147
|
+
const n = crossings(cols);
|
|
148
|
+
if (n < bestCross) {
|
|
149
|
+
bestCross = n;
|
|
150
|
+
best = cols.map((c) => [...c]);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
cols = best;
|
|
154
|
+
const passes = new Map();
|
|
155
|
+
for (const e of drawn) {
|
|
156
|
+
const at = [];
|
|
157
|
+
for (let c = column.get(e.from) + 1; c < column.get(e.to); c++)
|
|
158
|
+
at.push(cols[c].findIndex((s) => s.kind === "pass" && s.edge === e.id));
|
|
159
|
+
passes.set(e.id, at);
|
|
160
|
+
}
|
|
161
|
+
const walk = (start, next, into) => {
|
|
162
|
+
const stack = [...(next.get(start) ?? [])];
|
|
163
|
+
while (stack.length) {
|
|
164
|
+
const x = stack.pop();
|
|
165
|
+
if (into.has(x))
|
|
166
|
+
continue;
|
|
167
|
+
into.add(x);
|
|
168
|
+
stack.push(...(next.get(x) ?? []));
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
const related = (id) => {
|
|
172
|
+
const s = new Set([id]);
|
|
173
|
+
walk(id, inn, s);
|
|
174
|
+
walk(id, out, s);
|
|
175
|
+
return s;
|
|
176
|
+
};
|
|
177
|
+
return { column, columns: cols, edges: drawn, passes, related };
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=graphLayout.js.map
|