@lanfermann/ui 0.4.0 → 0.6.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/components/action-bar/action-bar.d.ts +59 -0
- package/dist/components/action-bar/action-bar.js +116 -0
- package/dist/components/alert/alert.d.ts +1 -1
- package/dist/components/alert/alert.js +3 -17
- package/dist/components/alert-dialog/alert-dialog.d.ts +1 -1
- package/dist/components/app-shell/app-shell.d.ts +33 -0
- package/dist/components/app-shell/app-shell.js +93 -0
- package/dist/components/attachment/attachment.d.ts +46 -0
- package/dist/components/attachment/attachment.js +222 -0
- package/dist/components/attachment/kinds.d.ts +7 -0
- package/dist/components/attachment/kinds.js +100 -0
- package/dist/components/avatar/avatar.d.ts +14 -4
- package/dist/components/avatar/avatar.js +57 -13
- package/dist/components/avatar-group/avatar-group.d.ts +33 -0
- package/dist/components/avatar-group/avatar-group.js +110 -0
- package/dist/components/avatar-group/people.d.ts +12 -0
- package/dist/components/avatar-group/people.js +24 -0
- package/dist/components/badge/badge.d.ts +9 -3
- package/dist/components/badge/badge.js +21 -6
- package/dist/components/banner/banner.d.ts +39 -0
- package/dist/components/banner/banner.js +149 -0
- package/dist/components/card/card.d.ts +11 -3
- package/dist/components/card/card.js +18 -4
- package/dist/components/checkbox-card/checkbox-card.d.ts +21 -0
- package/dist/components/checkbox-card/checkbox-card.js +49 -0
- package/dist/components/chip/chip-group.d.ts +15 -0
- package/dist/components/chip/chip-group.js +44 -0
- package/dist/components/chip/chip-variants.d.ts +6 -0
- package/dist/components/chip/chip-variants.js +28 -0
- package/dist/components/chip/chip.d.ts +39 -0
- package/dist/components/chip/chip.js +71 -0
- package/dist/components/code-block/code-block-live.d.ts +13 -1
- package/dist/components/code-block/code-block-live.js +10 -4
- package/dist/components/code-block/code-block.d.ts +1 -0
- package/dist/components/code-block/code-copy.d.ts +3 -11
- package/dist/components/code-block/code-copy.js +15 -62
- package/dist/components/code-block/code-keys.js +10 -22
- package/dist/components/code-block/code-lines-live.d.ts +7 -0
- package/dist/components/code-block/code-lines-live.js +167 -0
- package/dist/components/code-block/code-lines-view.d.ts +1 -0
- package/dist/components/code-block/code-lines-view.js +50 -18
- package/dist/components/code-block/code-lines.d.ts +3 -0
- package/dist/components/code-block/code-tabs.d.ts +1 -0
- package/dist/components/code-block/highlight.d.ts +1 -0
- package/dist/components/code-block/line-diff.js +135 -0
- package/dist/components/combobox/combobox.d.ts +50 -2
- package/dist/components/combobox/combobox.js +178 -9
- package/dist/components/command/command.d.ts +131 -0
- package/dist/components/command/command.js +335 -0
- package/dist/components/consent/consent-card.js +365 -0
- package/dist/components/consent/consent-embed.d.ts +21 -0
- package/dist/components/consent/consent-embed.js +111 -0
- package/dist/components/consent/consent-labels.d.ts +70 -0
- package/dist/components/consent/consent-labels.js +61 -0
- package/dist/components/consent/consent-record.d.ts +95 -0
- package/dist/components/consent/consent-record.js +112 -0
- package/dist/components/consent/consent-store.d.ts +26 -0
- package/dist/components/consent/consent-store.js +240 -0
- package/dist/components/consent/consent.d.ts +86 -0
- package/dist/components/consent/consent.js +306 -0
- package/dist/components/container/container.d.ts +1 -1
- package/dist/components/context-menu/context-menu.d.ts +23 -0
- package/dist/components/context-menu/context-menu.js +50 -0
- package/dist/components/conversation/conversation.d.ts +45 -0
- package/dist/components/conversation/conversation.js +295 -0
- package/dist/components/conversation/stick.js +23 -0
- package/dist/components/copy-button/copy-button.d.ts +50 -0
- package/dist/components/copy-button/copy-button.js +65 -0
- package/dist/components/copy-page/copy-page.js +7 -17
- package/dist/components/copy-pill/copy-pill.js +1 -1
- package/dist/components/description-list/description-list.d.ts +32 -0
- package/dist/components/description-list/description-list.js +51 -0
- package/dist/components/empty/empty.d.ts +38 -0
- package/dist/components/empty/empty.js +57 -0
- package/dist/components/field/field.js +1 -1
- package/dist/components/file-upload/file-upload.d.ts +96 -0
- package/dist/components/file-upload/file-upload.js +347 -0
- package/dist/components/file-upload/files.d.ts +39 -0
- package/dist/components/file-upload/files.js +74 -0
- package/dist/components/grow/grow.d.ts +15 -3
- package/dist/components/grow/grow.js +31 -10
- package/dist/components/heading/heading.d.ts +1 -1
- package/dist/components/icon/icon.d.ts +1 -1
- package/dist/components/input/input.js +1 -1
- package/dist/components/message/message.d.ts +73 -0
- package/dist/components/message/message.js +196 -0
- package/dist/components/otp-field/otp-field.d.ts +37 -0
- package/dist/components/otp-field/otp-field.js +126 -0
- package/dist/components/pagination/pagination.d.ts +50 -0
- package/dist/components/pagination/pagination.js +188 -0
- package/dist/components/prompt-input/keys.js +15 -0
- package/dist/components/prompt-input/prompt-input.d.ts +89 -0
- package/dist/components/prompt-input/prompt-input.js +331 -0
- package/dist/components/radio-card/radio-card.d.ts +23 -0
- package/dist/components/radio-card/radio-card.js +48 -0
- package/dist/components/rolling-number/rolling-number.d.ts +30 -0
- package/dist/components/rolling-number/rolling-number.js +149 -0
- package/dist/components/seam/seam.d.ts +1 -1
- package/dist/components/secret-field/secret-field.d.ts +53 -0
- package/dist/components/secret-field/secret-field.js +121 -0
- package/dist/components/section/section.d.ts +1 -1
- package/dist/components/select/select.d.ts +1 -1
- package/dist/components/select/select.js +1 -1
- package/dist/components/shortcut/shortcut.d.ts +46 -0
- package/dist/components/shortcut/shortcut.js +87 -0
- package/dist/components/sidebar/sidebar-context.js +16 -0
- package/dist/components/sidebar/sidebar.d.ts +161 -0
- package/dist/components/sidebar/sidebar.js +588 -0
- package/dist/components/site-header/site-header.js +1 -1
- package/dist/components/skeleton/loaded.d.ts +21 -0
- package/dist/components/skeleton/loaded.js +57 -0
- package/dist/components/skeleton/skeleton.d.ts +43 -0
- package/dist/components/skeleton/skeleton.js +48 -0
- package/dist/components/sources/source-list.d.ts +17 -0
- package/dist/components/sources/source-list.js +26 -0
- package/dist/components/sources/sources.d.ts +45 -0
- package/dist/components/sources/sources.js +167 -0
- package/dist/components/stat/stat.d.ts +57 -0
- package/dist/components/stat/stat.js +110 -0
- package/dist/components/steps/steps.d.ts +57 -0
- package/dist/components/steps/steps.js +131 -0
- package/dist/components/table/table.d.ts +18 -9
- package/dist/components/table/table.js +21 -13
- package/dist/components/text/text.d.ts +1 -1
- package/dist/components/theme-switch/theme-switch.js +1 -1
- package/dist/components/time-field/time-field.js +1 -1
- package/dist/components/timeline/timeline.d.ts +45 -0
- package/dist/components/timeline/timeline.js +86 -0
- package/dist/components/toast/toast.js +10 -26
- package/dist/components/toggle/toggle.d.ts +24 -0
- package/dist/components/toggle/toggle.js +53 -0
- package/dist/components/toggle-group/toggle-group.d.ts +27 -0
- package/dist/components/toggle-group/toggle-group.js +38 -0
- package/dist/components/toolbar/toolbar-context.js +12 -0
- package/dist/components/toolbar/toolbar.d.ts +45 -0
- package/dist/components/toolbar/toolbar.js +92 -0
- package/dist/components/trace/trace.d.ts +2 -1
- package/dist/components/trace/trace.js +14 -26
- package/dist/index.d.ts +46 -3
- package/dist/index.js +44 -3
- package/dist/internal/arriving-pieces.js +56 -0
- package/dist/internal/arriving.js +171 -0
- package/dist/internal/avatar-cut.d.ts +15 -0
- package/dist/internal/avatar-cut.js +83 -0
- package/dist/internal/choice-card.d.ts +15 -0
- package/dist/internal/choice-card.js +65 -0
- package/dist/internal/clipboard.js +37 -0
- package/dist/internal/copy.js +58 -0
- package/dist/internal/field.js +24 -4
- package/dist/internal/glyphs.js +26 -1
- package/dist/internal/live-list.js +41 -0
- package/dist/internal/number-places.js +156 -0
- package/dist/internal/picker-sheet.js +1 -1
- package/dist/internal/presence-dot.js +24 -0
- package/dist/internal/presence.js +104 -0
- package/dist/internal/rail-mark.d.ts +3 -0
- package/dist/internal/rail-mark.js +33 -0
- package/dist/internal/status-icon.js +22 -0
- package/dist/internal/travelling-mark.js +204 -0
- package/dist/lib/cn.js +4 -0
- package/dist/lib/shortcut.d.ts +11 -0
- package/dist/lib/shortcut.js +165 -0
- package/package.json +1 -1
- package/src/styles/action-bar.css +28 -0
- package/src/styles/assistant.css +83 -0
- package/src/styles/avatar.css +24 -0
- package/src/styles/code.css +89 -1
- package/src/styles/consent.css +65 -0
- package/src/styles/copy.css +12 -11
- package/src/styles/depth.css +46 -2
- package/src/styles/marks.css +20 -2
- package/src/styles/rail.css +49 -0
- package/src/styles/rolling-number.css +94 -0
- package/src/styles/steps.css +98 -0
- package/src/styles/timeline.css +48 -0
- package/src/styles/travel.css +36 -0
- package/src/styles.css +9 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useReducedMotion } from "../../internal/reduced-motion.js";
|
|
3
|
+
import { CodeRows } from "./code-lines-view.js";
|
|
4
|
+
import { changedRange, diffLines } from "./line-diff.js";
|
|
5
|
+
import { lineKinds } from "./lines.js";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
8
|
+
// src/components/code-block/code-lines-live.tsx
|
|
9
|
+
/** How long a closing line is kept at most: past the longest transition, in ms. */
|
|
10
|
+
const LEAVE_AT_MOST = 1500;
|
|
11
|
+
const textOf = (tokens) => tokens.map((token) => token.content).join("");
|
|
12
|
+
function signatureOf(lines, kinds) {
|
|
13
|
+
return `${lines.map((line) => line.map((token) => `${token.content}\u0001${token.color ?? ""}`).join("")).join("\n")}\u0000${kinds.join(",")}`;
|
|
14
|
+
}
|
|
15
|
+
function firstRows(lines, kinds, signature) {
|
|
16
|
+
return {
|
|
17
|
+
signature,
|
|
18
|
+
lines: lines.map((tokens, id) => ({
|
|
19
|
+
id,
|
|
20
|
+
text: textOf(tokens),
|
|
21
|
+
tokens,
|
|
22
|
+
kind: kinds[id]
|
|
23
|
+
})),
|
|
24
|
+
leaving: [],
|
|
25
|
+
fresh: /* @__PURE__ */ new Map(),
|
|
26
|
+
next: lines.length
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The rows after the code changed: a line that goes on keeps its id, a new one gets a new id,
|
|
31
|
+
* and a gone one stays behind the row it followed until it has closed. A line that is on its way
|
|
32
|
+
* out and comes back where it stood takes its id back, so its row turns round instead of
|
|
33
|
+
* opening anew. Under reduced motion nothing is kept on its way out.
|
|
34
|
+
*/
|
|
35
|
+
function nextRows(rows, lines, kinds, signature, still) {
|
|
36
|
+
const texts = lines.map(textOf);
|
|
37
|
+
const { from, removed } = diffLines(rows.lines.map((line) => line.text), texts);
|
|
38
|
+
let next = rows.next;
|
|
39
|
+
const fresh = /* @__PURE__ */ new Map();
|
|
40
|
+
const leaving = still ? [] : [...rows.leaving];
|
|
41
|
+
const ids = [];
|
|
42
|
+
texts.forEach((text, index) => {
|
|
43
|
+
const before = rows.lines[from[index]];
|
|
44
|
+
if (before) {
|
|
45
|
+
ids.push(before.id);
|
|
46
|
+
const range = before.text === text ? null : changedRange(before.text, text);
|
|
47
|
+
if (range) fresh.set(before.id, {
|
|
48
|
+
range,
|
|
49
|
+
stamp: next++
|
|
50
|
+
});
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const after = index === 0 ? -1 : ids[index - 1];
|
|
54
|
+
const back = leaving.findIndex((line) => line.text === text && line.after === after);
|
|
55
|
+
if (back === -1) ids.push(next++);
|
|
56
|
+
else ids.push(...leaving.splice(back, 1).map((line) => line.id));
|
|
57
|
+
});
|
|
58
|
+
if (!still) for (const index of removed) leaving.push({
|
|
59
|
+
...rows.lines[index],
|
|
60
|
+
after: index === 0 ? -1 : rows.lines[index - 1].id
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
signature,
|
|
64
|
+
lines: texts.map((text, index) => ({
|
|
65
|
+
id: ids[index],
|
|
66
|
+
text,
|
|
67
|
+
tokens: lines[index],
|
|
68
|
+
kind: kinds[index]
|
|
69
|
+
})),
|
|
70
|
+
leaving,
|
|
71
|
+
fresh,
|
|
72
|
+
next
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/** The rows in the order they stand: each closing line right after the row it followed. */
|
|
76
|
+
function arrange({ lines, leaving, fresh }) {
|
|
77
|
+
const rows = [];
|
|
78
|
+
const closingAfter = (id) => {
|
|
79
|
+
for (const line of leaving) {
|
|
80
|
+
if (line.after !== id) continue;
|
|
81
|
+
rows.push({
|
|
82
|
+
key: `r${line.id}`,
|
|
83
|
+
tokens: line.tokens,
|
|
84
|
+
kind: line.kind,
|
|
85
|
+
leaving: true
|
|
86
|
+
});
|
|
87
|
+
closingAfter(line.id);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
closingAfter(-1);
|
|
91
|
+
for (const line of lines) {
|
|
92
|
+
rows.push({
|
|
93
|
+
key: `r${line.id}`,
|
|
94
|
+
tokens: line.tokens,
|
|
95
|
+
kind: line.kind,
|
|
96
|
+
fresh: fresh.get(line.id)
|
|
97
|
+
});
|
|
98
|
+
closingAfter(line.id);
|
|
99
|
+
}
|
|
100
|
+
return rows;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The lines of a `CodeBlockLive`: `CodeLinesView` for code that changes under the reader's hand.
|
|
104
|
+
* When the code changes, the lines are matched to the ones before (line-diff.ts). A new line
|
|
105
|
+
* opens like a fold: its row opens and pushes the lines below down while its text fades in. A
|
|
106
|
+
* gone line fades and its row closes, and the part of a line that changed shows as new
|
|
107
|
+
* (code.css). What stands when the block first shows does not move, and neither does a block
|
|
108
|
+
* that has just mounted (the panel of another tab).
|
|
109
|
+
*/
|
|
110
|
+
function CodeLinesLive({ lines, marked, added, removed, changeMotion = "fade", ...options }) {
|
|
111
|
+
const kinds = lineKinds(lines.length, {
|
|
112
|
+
marked,
|
|
113
|
+
added,
|
|
114
|
+
removed
|
|
115
|
+
});
|
|
116
|
+
const signature = signatureOf(lines, kinds);
|
|
117
|
+
const still = useReducedMotion();
|
|
118
|
+
const [rows, setRows] = useState(() => firstRows(lines, kinds, signature));
|
|
119
|
+
if (rows.signature !== signature) setRows(nextRows(rows, lines, kinds, signature, still));
|
|
120
|
+
const [live, setLive] = useState(false);
|
|
121
|
+
useEffect(() => {
|
|
122
|
+
const frame = requestAnimationFrame(() => setLive(true));
|
|
123
|
+
return () => cancelAnimationFrame(frame);
|
|
124
|
+
}, []);
|
|
125
|
+
/** A closing line has closed: it goes, and what stood behind it stands behind its place. */
|
|
126
|
+
const drop = useCallback((id) => {
|
|
127
|
+
setRows((current) => {
|
|
128
|
+
const gone = current.leaving.find((line) => line.id === id);
|
|
129
|
+
if (!gone) return current;
|
|
130
|
+
return {
|
|
131
|
+
...current,
|
|
132
|
+
leaving: current.leaving.filter((line) => line !== gone).map((line) => line.after === id ? {
|
|
133
|
+
...line,
|
|
134
|
+
after: gone.after
|
|
135
|
+
} : line)
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
}, []);
|
|
139
|
+
const code = useRef(null);
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
const element = code.current;
|
|
142
|
+
if (!element) return;
|
|
143
|
+
const closed = (event) => {
|
|
144
|
+
const line = event.target;
|
|
145
|
+
if (event.propertyName !== "grid-template-rows" || line.dataset.motion !== "leave") return;
|
|
146
|
+
drop(Number(line.dataset.row?.slice(1)));
|
|
147
|
+
};
|
|
148
|
+
element.addEventListener("transitionend", closed);
|
|
149
|
+
return () => element.removeEventListener("transitionend", closed);
|
|
150
|
+
}, [drop]);
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
if (rows.leaving.length === 0) return;
|
|
153
|
+
const timer = setTimeout(() => setRows((current) => ({
|
|
154
|
+
...current,
|
|
155
|
+
leaving: []
|
|
156
|
+
})), LEAVE_AT_MOST);
|
|
157
|
+
return () => clearTimeout(timer);
|
|
158
|
+
}, [rows.leaving]);
|
|
159
|
+
return /* @__PURE__ */ jsx(CodeRows, {
|
|
160
|
+
ref: code,
|
|
161
|
+
rows: arrange(rows),
|
|
162
|
+
"data-live": live ? "" : void 0,
|
|
163
|
+
"data-change-motion": changeMotion,
|
|
164
|
+
...options
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
export { CodeLinesLive };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { splitRuns } from "./line-diff.js";
|
|
1
2
|
import { lineKinds } from "./lines.js";
|
|
2
3
|
import { jsx } from "react/jsx-runtime";
|
|
3
4
|
// src/components/code-block/code-lines-view.tsx
|
|
@@ -7,42 +8,73 @@ import { jsx } from "react/jsx-runtime";
|
|
|
7
8
|
* `CodeBlockLive`) is not its business, and no highlighter may be imported here: this is the
|
|
8
9
|
* half that may travel to the browser.
|
|
9
10
|
*/
|
|
10
|
-
function CodeLinesView({ lines,
|
|
11
|
+
function CodeLinesView({ lines, marked, added, removed, ...options }) {
|
|
11
12
|
const kinds = lineKinds(lines.length, {
|
|
12
13
|
marked,
|
|
13
14
|
added,
|
|
14
15
|
removed
|
|
15
16
|
});
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
return /* @__PURE__ */ jsx(CodeRows, {
|
|
18
|
+
rows: lines.map((tokens, index) => ({
|
|
19
|
+
key: index,
|
|
20
|
+
tokens,
|
|
21
|
+
kind: kinds[index]
|
|
22
|
+
})),
|
|
23
|
+
...options
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The `<code>` itself, from rows that may carry an identity, a line on its way out and the part
|
|
28
|
+
* a change put in. `CodeLinesView` draws code that stands; `CodeLinesLive` code that changes.
|
|
29
|
+
*
|
|
30
|
+
* A line is a grid of one row around its body, so the row can open from nothing and close to
|
|
31
|
+
* nothing (`grid-template-rows`, code.css) while the lines below make room.
|
|
32
|
+
*/
|
|
33
|
+
function CodeRows({ rows, lineNumbers = false, wrap = false, addedLabel = "hinzugefügt", removedLabel = "entfernt", style, ...props }) {
|
|
34
|
+
const changes = rows.some((row) => row.kind === "added" || row.kind === "removed");
|
|
35
|
+
const count = rows.filter((row) => !row.leaving).length;
|
|
36
|
+
const digits = lineNumbers ? String(count).length : 0;
|
|
18
37
|
const numberRoom = lineNumbers ? `${digits}ch + 1.25rem` : "0px";
|
|
19
38
|
const signRoom = changes ? "1ch + 0.75rem" : "0px";
|
|
20
|
-
const
|
|
39
|
+
const measures = {
|
|
21
40
|
"--code-digits": `${digits}ch`,
|
|
22
41
|
"--code-sign-at": `calc(${numberRoom})`,
|
|
23
|
-
"--code-gutter": `calc(${numberRoom} + ${signRoom})
|
|
42
|
+
"--code-gutter": `calc(${numberRoom} + ${signRoom})`,
|
|
43
|
+
...style
|
|
24
44
|
};
|
|
25
45
|
return /* @__PURE__ */ jsx("code", {
|
|
26
46
|
"data-slot": "code-block-code",
|
|
27
47
|
"data-line-numbers": lineNumbers ? "" : void 0,
|
|
28
48
|
"data-wrap": wrap ? "" : void 0,
|
|
29
|
-
style,
|
|
30
|
-
|
|
31
|
-
|
|
49
|
+
style: measures,
|
|
50
|
+
...props,
|
|
51
|
+
children: rows.map(({ key, tokens, kind, leaving, fresh }) => {
|
|
52
|
+
const runs = tokens.filter((token) => token.content !== "");
|
|
53
|
+
const pieces = fresh ? splitRuns(runs, fresh.range) : runs;
|
|
32
54
|
return /* @__PURE__ */ jsx("span", {
|
|
33
55
|
"data-slot": "code-block-line",
|
|
34
56
|
"data-kind": kind,
|
|
57
|
+
"data-motion": leaving ? "leave" : void 0,
|
|
58
|
+
"data-row": leaving ? key : void 0,
|
|
35
59
|
"data-label": kind === "added" ? addedLabel : kind === "removed" ? removedLabel : void 0,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
60
|
+
"aria-hidden": leaving || void 0,
|
|
61
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
62
|
+
"data-slot": "code-block-line-body",
|
|
63
|
+
children: pieces.map((piece, at) => {
|
|
64
|
+
const isFresh = "fresh" in piece && piece.fresh;
|
|
65
|
+
return /* @__PURE__ */ jsx("span", {
|
|
66
|
+
"data-slot": isFresh ? "code-block-fresh" : void 0,
|
|
67
|
+
style: {
|
|
68
|
+
color: piece.color,
|
|
69
|
+
fontStyle: piece.italic ? "italic" : void 0,
|
|
70
|
+
fontWeight: piece.bold ? 600 : void 0
|
|
71
|
+
},
|
|
72
|
+
children: piece.content
|
|
73
|
+
}, isFresh ? `fresh-${fresh?.stamp}-${at}` : at);
|
|
74
|
+
})
|
|
75
|
+
})
|
|
76
|
+
}, key);
|
|
45
77
|
})
|
|
46
78
|
});
|
|
47
79
|
}
|
|
48
|
-
export { CodeLinesView };
|
|
80
|
+
export { CodeLinesView, CodeRows };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CodeKeyOptions } from "./code-keys.js";
|
|
2
2
|
import { CodeLinesOptions } from "./code-lines-view.js";
|
|
3
|
+
import "./code-lines.js";
|
|
3
4
|
import { CodeLanguage } from "./highlight.js";
|
|
4
5
|
export type CodeTab = CodeLinesOptions & {
|
|
5
6
|
/** The tab: a noun of one or two words, often the tool's own name („bun“, „npm“). */
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// src/components/code-block/line-diff.ts
|
|
2
|
+
/** Above this many cells the table of a full comparison costs more than a frame. */
|
|
3
|
+
const MAX_CELLS = 25e4;
|
|
4
|
+
/** A line as it is compared: a comma or spaces at its end do not make it another line. */
|
|
5
|
+
function shape(line) {
|
|
6
|
+
return line.trimEnd().replace(/,$/, "");
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* What a line sets, if it sets something: its text up to the first `:` or `=`, indent included
|
|
10
|
+
* (` "SEVDESK_ALLOW"`, `SEVDESK_ALLOW`, ` -e SEVDESK_ALLOW`). Two lines that set the same thing
|
|
11
|
+
* are one line whose value changed.
|
|
12
|
+
*/
|
|
13
|
+
function setting(line) {
|
|
14
|
+
return /^(\s*[^:=\s][^:=]*?)\s*[:=]/.exec(line)?.[1];
|
|
15
|
+
}
|
|
16
|
+
/** Whether two lines that differ are still the same line, changed where it stands. */
|
|
17
|
+
function changedInPlace(before, after) {
|
|
18
|
+
const key = setting(before);
|
|
19
|
+
if (key !== void 0) return key === setting(after);
|
|
20
|
+
if (before.trim() === "" || after.trim() === "") return false;
|
|
21
|
+
let shared = 0;
|
|
22
|
+
while (shared < before.length && before[shared] === after[shared]) shared++;
|
|
23
|
+
return shared * 2 >= Math.max(before.length, after.length);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The pairs of a longest common subsequence of `a[aFrom..aTo)` and `b[bFrom..bTo)` under `same`,
|
|
27
|
+
* in order. Quadratic, so it is only used on code of a page's size.
|
|
28
|
+
*/
|
|
29
|
+
function commonPairs(a, b, same, [aFrom, aTo], [bFrom, bTo]) {
|
|
30
|
+
const rows = aTo - aFrom;
|
|
31
|
+
const cols = bTo - bFrom;
|
|
32
|
+
if (rows === 0 || cols === 0) return [];
|
|
33
|
+
const width = cols + 1;
|
|
34
|
+
const lengths = new Uint32Array((rows + 1) * width);
|
|
35
|
+
for (let i = rows - 1; i >= 0; i--) for (let j = cols - 1; j >= 0; j--) lengths[i * width + j] = same(a[aFrom + i], b[bFrom + j]) ? lengths[(i + 1) * width + j + 1] + 1 : Math.max(lengths[(i + 1) * width + j], lengths[i * width + j + 1]);
|
|
36
|
+
const pairs = [];
|
|
37
|
+
let i = 0;
|
|
38
|
+
let j = 0;
|
|
39
|
+
while (i < rows && j < cols) if (same(a[aFrom + i], b[bFrom + j])) {
|
|
40
|
+
pairs.push([aFrom + i, bFrom + j]);
|
|
41
|
+
i++;
|
|
42
|
+
j++;
|
|
43
|
+
} else if (lengths[(i + 1) * width + j] >= lengths[i * width + j + 1]) i++;
|
|
44
|
+
else j++;
|
|
45
|
+
return pairs;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Which lines of `after` continue lines of `before`, and which of `before` are gone.
|
|
49
|
+
*
|
|
50
|
+
* Lines are first matched by their text, a trailing comma aside (a line that gains one when a
|
|
51
|
+
* line is added below it stays itself). Between two matches, a line that sets the same thing as
|
|
52
|
+
* one before it (`SEVDESK_ALLOW=read` and `SEVDESK_ALLOW=read,draft`) is that line, changed in
|
|
53
|
+
* place; everything else there is new or gone. Code too long to compare is matched line by line
|
|
54
|
+
* from both ends.
|
|
55
|
+
*/
|
|
56
|
+
function diffLines(before, after) {
|
|
57
|
+
const from = Array.from({ length: after.length }, () => -1);
|
|
58
|
+
const kept = /* @__PURE__ */ new Set();
|
|
59
|
+
const pair = ([i, j]) => {
|
|
60
|
+
from[j] = i;
|
|
61
|
+
kept.add(i);
|
|
62
|
+
};
|
|
63
|
+
if (before.length * after.length > MAX_CELLS) {
|
|
64
|
+
let start = 0;
|
|
65
|
+
while (start < before.length && start < after.length && before[start] === after[start]) {
|
|
66
|
+
pair([start, start]);
|
|
67
|
+
start++;
|
|
68
|
+
}
|
|
69
|
+
let end = 0;
|
|
70
|
+
while (end < before.length - start && end < after.length - start && before[before.length - 1 - end] === after[after.length - 1 - end]) {
|
|
71
|
+
pair([before.length - 1 - end, after.length - 1 - end]);
|
|
72
|
+
end++;
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
const a = before.map(shape);
|
|
76
|
+
const b = after.map(shape);
|
|
77
|
+
const matches = commonPairs(a, b, (x, y) => x === y, [0, a.length], [0, b.length]);
|
|
78
|
+
let [i0, j0] = [0, 0];
|
|
79
|
+
for (const [i, j] of [...matches, [a.length, b.length]]) {
|
|
80
|
+
for (const changed of commonPairs(before, after, changedInPlace, [i0, i], [j0, j])) pair(changed);
|
|
81
|
+
if (i < a.length) pair([i, j]);
|
|
82
|
+
[i0, j0] = [i + 1, j + 1];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
from,
|
|
87
|
+
removed: before.map((_, index) => index).filter((index) => !kept.has(index))
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The part of `after` that is not in `before`: what lies between their common start and common
|
|
92
|
+
* end, as `[start, end)` in `after`. Null when nothing was added (the same text, or only a
|
|
93
|
+
* deletion).
|
|
94
|
+
*/
|
|
95
|
+
function changedRange(before, after) {
|
|
96
|
+
const most = Math.min(before.length, after.length);
|
|
97
|
+
let start = 0;
|
|
98
|
+
while (start < most && before[start] === after[start]) start++;
|
|
99
|
+
let end = 0;
|
|
100
|
+
while (end < most - start && before[before.length - 1 - end] === after[after.length - 1 - end]) end++;
|
|
101
|
+
return start < after.length - end ? [start, after.length - end] : null;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The runs of a line, cut where `range` starts and ends, with the runs inside it flagged
|
|
105
|
+
* `fresh`. A run keeps its colour on both sides of a cut.
|
|
106
|
+
*/
|
|
107
|
+
function splitRuns(runs, [start, end]) {
|
|
108
|
+
const pieces = [];
|
|
109
|
+
let at = 0;
|
|
110
|
+
for (const run of runs) {
|
|
111
|
+
const runEnd = at + run.content.length;
|
|
112
|
+
const cuts = [
|
|
113
|
+
at,
|
|
114
|
+
Math.min(Math.max(start, at), runEnd),
|
|
115
|
+
Math.min(Math.max(end, at), runEnd),
|
|
116
|
+
runEnd
|
|
117
|
+
];
|
|
118
|
+
for (let k = 0; k < 3; k++) {
|
|
119
|
+
const [from, to] = [cuts[k], cuts[k + 1]];
|
|
120
|
+
if (to <= from) continue;
|
|
121
|
+
const content = run.content.slice(from - at, to - at);
|
|
122
|
+
pieces.push(k === 1 ? {
|
|
123
|
+
...run,
|
|
124
|
+
content,
|
|
125
|
+
fresh: true
|
|
126
|
+
} : {
|
|
127
|
+
...run,
|
|
128
|
+
content
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
at = runEnd;
|
|
132
|
+
}
|
|
133
|
+
return pieces;
|
|
134
|
+
}
|
|
135
|
+
export { changedRange, diffLines, splitRuns };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ChipVariant } from "../chip/chip-variants.js";
|
|
1
2
|
import { IconSvgElement } from "../icon/icon.js";
|
|
2
3
|
import { FieldSize } from "../../internal/field.js";
|
|
3
4
|
import { ReactNode } from "react";
|
|
@@ -18,7 +19,17 @@ export type ComboboxOptionGroup<Value = string> = {
|
|
|
18
19
|
value: string;
|
|
19
20
|
items: ReadonlyArray<ComboboxOption<Value>>;
|
|
20
21
|
};
|
|
21
|
-
export type ComboboxProps<
|
|
22
|
+
export type ComboboxProps<Value, Multiple extends boolean | undefined = false, Item = Value> = Combobox$1.Root.Props<Value, Multiple, Item> & {
|
|
23
|
+
/**
|
|
24
|
+
* Lets the reader make a value that is not in the list. While what they typed matches no
|
|
25
|
+
* option's name exactly, a last row offers to create it; choosing that row calls this with
|
|
26
|
+
* the typed text. Add the new option to your `items` and return it: it is chosen at once.
|
|
27
|
+
* Needs a flat list of options and a controlled `value`.
|
|
28
|
+
*/
|
|
29
|
+
onCreate?: (label: string) => Value | undefined;
|
|
30
|
+
/** What the row that creates says: „Dringend“ anlegen. */
|
|
31
|
+
createLabel?: (label: string) => ReactNode;
|
|
32
|
+
};
|
|
22
33
|
/**
|
|
23
34
|
* A select you can type into: for lists too long to scan (a customer out of two hundred), where
|
|
24
35
|
* people know what they are looking for. Typing filters the list; only an entry of the list can
|
|
@@ -28,11 +39,15 @@ export type ComboboxProps<Option> = Combobox$1.Root.Props<Option, false>;
|
|
|
28
39
|
* object, is the value: `defaultValue={items[0]}`, `onValueChange={(option) => …}`. In a form
|
|
29
40
|
* its `value` is what is submitted.
|
|
30
41
|
*
|
|
42
|
+
* With `multiple` the value is a list of options and the field is a `ComboboxChips`: every
|
|
43
|
+
* chosen option is a chip in it. The list then stays open after a choice, so several can be
|
|
44
|
+
* taken in a row, and each is submitted under the field's name.
|
|
45
|
+
*
|
|
31
46
|
* Typing ignores case and accents: "gart" finds "Gärtnerei" and "cafe" finds "Café". Pass
|
|
32
47
|
* `locale` (`"de-DE"`) so that does not depend on the machine. The first match is highlighted
|
|
33
48
|
* while typing, so Enter takes it.
|
|
34
49
|
*/
|
|
35
|
-
export declare function Combobox<
|
|
50
|
+
export declare function Combobox<Value, Multiple extends boolean | undefined = false, Item = Value>({ autoHighlight, filter, locale, items, multiple, onCreate, createLabel, inputValue, defaultInputValue, onInputValueChange, onValueChange, onOpenChange, ...props }: ComboboxProps<Value, Multiple, Item>): import("react").JSX.Element;
|
|
36
51
|
export type ComboboxInputProps = Omit<Combobox$1.Input.Props, "className" | "size"> & {
|
|
37
52
|
/** The size of the field, from the density. */
|
|
38
53
|
size?: FieldSize;
|
|
@@ -49,6 +64,39 @@ export type ComboboxInputProps = Omit<Combobox$1.Input.Props, "className" | "siz
|
|
|
49
64
|
* placeholder is an example ("z. B. Schreinerei Huber"), not a label.
|
|
50
65
|
*/
|
|
51
66
|
export declare function ComboboxInput({ className, size, clearLabel, openLabel, ...props }: ComboboxInputProps): import("react").JSX.Element;
|
|
67
|
+
export type ComboboxChipsProps = Omit<Combobox$1.Input.Props, "className" | "size"> & {
|
|
68
|
+
/** The size of the field, from the density. */
|
|
69
|
+
size?: FieldSize;
|
|
70
|
+
/** Classes for the field as a whole, e.g. its width. */
|
|
71
|
+
className?: string;
|
|
72
|
+
/**
|
|
73
|
+
* `flat` (the default): the chips are drawn like a `Badge`, quiet in the field. `plug`: raised
|
|
74
|
+
* plugs seated in it, like a `Chip` on its own, where the values are the field's point (the
|
|
75
|
+
* recipients of a message).
|
|
76
|
+
*/
|
|
77
|
+
chipVariant?: ChipVariant;
|
|
78
|
+
/** The name of the row of chips, for assistive tech. */
|
|
79
|
+
chipsLabel?: string;
|
|
80
|
+
/** The verb of the key that takes a chip away. The chip's text is said before it. */
|
|
81
|
+
removeLabel?: string;
|
|
82
|
+
/** Said with the input once something is chosen: how many, and how to reach them. */
|
|
83
|
+
chipsHint?: (count: number) => string;
|
|
84
|
+
/** The accessible name of the button that clears every choice. */
|
|
85
|
+
clearLabel?: string;
|
|
86
|
+
/** The accessible name of the button that opens the list. */
|
|
87
|
+
openLabel?: string;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* The field of a `Combobox multiple`: every chosen option is a chip in it, and the input stands
|
|
91
|
+
* after the last one. Backspace in the empty input takes the last chip, Arrow left walks into
|
|
92
|
+
* the chips, and each chip has a key that takes it away.
|
|
93
|
+
*
|
|
94
|
+
* A chip that joins seats into its place, one that leaves fades while its neighbours close up,
|
|
95
|
+
* and when the chips need another line the field eases to its new height, so what stands below
|
|
96
|
+
* is pushed and does not jump. Give it a name with a `FieldLabel` or an `aria-label`; the
|
|
97
|
+
* placeholder is an example and shows only while nothing is chosen.
|
|
98
|
+
*/
|
|
99
|
+
export declare function ComboboxChips({ className, size, chipVariant, chipsLabel, removeLabel, chipsHint, clearLabel, openLabel, ...props }: ComboboxChipsProps): import("react").JSX.Element;
|
|
52
100
|
export type ComboboxContentProps = Omit<Combobox$1.Popup.Props, "children"> & Pick<Combobox$1.Positioner.Props, "side" | "align" | "sideOffset" | "alignOffset"> & {
|
|
53
101
|
/**
|
|
54
102
|
* Said when nothing matches what was typed. Name what was looked for ("Kein Kunde
|