@sovereignfs/ui 0.107.3 → 0.110.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/text.d.ts ADDED
@@ -0,0 +1,68 @@
1
+ /**
2
+ * A text as its lines, each with the line break that ends it, so that a text can be read, compared and put together again byte for
3
+ * byte. Pure: no React, no browser.
4
+ */
5
+ type LineEnding = '\n' | '\r\n' | '\r' | '';
6
+ interface TextLine {
7
+ readonly text: string;
8
+ /** The line break that ends it, or none for a last line without one. */
9
+ readonly ending: LineEnding;
10
+ }
11
+ /** The lines of a text. An empty text has none; `joinLines` of the result is the text again. */
12
+ declare function splitLines(text: string): TextLine[];
13
+ declare function joinLines(lines: readonly TextLine[]): string;
14
+
15
+ /** A stretch of lines both texts have, or lines of the first replaced by lines of the second. */
16
+ interface LineChange {
17
+ readonly equal: boolean;
18
+ readonly before: readonly TextLine[];
19
+ readonly after: readonly TextLine[];
20
+ }
21
+ /** A stretch of a line both have, or one replaced by another. */
22
+ interface WordChange {
23
+ readonly equal: boolean;
24
+ readonly before: string;
25
+ readonly after: string;
26
+ }
27
+ declare function diffLines(before: string, after: string): LineChange[];
28
+ declare function diffWords(before: string, after: string): WordChange[];
29
+
30
+ /**
31
+ * - `same`: nobody changed it;
32
+ * - `ours` or `theirs`: one side changed it, and the change is taken;
33
+ * - `both`: both made the same change, taken once;
34
+ * - `conflict`: both changed it, differently.
35
+ */
36
+ type MergePartKind = 'same' | 'ours' | 'theirs' | 'both' | 'conflict';
37
+ /** A stretch of the three texts that stand for each other. */
38
+ interface MergePart {
39
+ readonly kind: MergePartKind;
40
+ readonly base: readonly TextLine[];
41
+ readonly ours: readonly TextLine[];
42
+ readonly theirs: readonly TextLine[];
43
+ }
44
+ interface TextMerge {
45
+ /** In order; the `base`, `ours` and `theirs` lines of all of them are those three texts, whole. */
46
+ readonly parts: readonly MergePart[];
47
+ /** How many of the parts are conflicts. */
48
+ readonly conflicts: number;
49
+ }
50
+ /** How a person settles a conflict: one side, ours then theirs, or a text of their own. */
51
+ type MergeChoice = 'ours' | 'theirs' | 'both' | {
52
+ readonly text: string;
53
+ };
54
+ interface MergeResolution {
55
+ /** The merged text, or `null` while a conflict is open. */
56
+ readonly text: string | null;
57
+ /** How many conflicts have no choice yet. */
58
+ readonly open: number;
59
+ }
60
+ declare function mergeText(base: string, ours: string, theirs: string): TextMerge;
61
+ /**
62
+ * The text a merge makes with the choices for its conflicts, in their order. Where a stretch that ends a text without a line break
63
+ * is followed by another, a line break is put between them.
64
+ */
65
+ declare function resolveMerge(merge: TextMerge, choices?: readonly (MergeChoice | undefined)[]): MergeResolution;
66
+
67
+ export { diffLines, diffWords, joinLines, mergeText, resolveMerge, splitLines };
68
+ export type { LineChange, LineEnding, MergeChoice, MergePart, MergePartKind, MergeResolution, TextLine, TextMerge, WordChange };
package/dist/text.js ADDED
@@ -0,0 +1,268 @@
1
+ // src/text/diff.ts
2
+ var DEFAULT_MAX_EDITS = 4e3;
3
+ function intern(a, b) {
4
+ const ids = /* @__PURE__ */ new Map();
5
+ const encode = (items) => {
6
+ const out = new Int32Array(items.length);
7
+ for (let i = 0; i < items.length; i++) {
8
+ const item = items[i];
9
+ let id = ids.get(item);
10
+ if (id === void 0) {
11
+ id = ids.size;
12
+ ids.set(item, id);
13
+ }
14
+ out[i] = id;
15
+ }
16
+ return out;
17
+ };
18
+ return [encode(a), encode(b)];
19
+ }
20
+ function middleSnake(a, b, aLo, aHi, bLo, bHi, maxEdits) {
21
+ const n = aHi - aLo;
22
+ const m = bHi - bLo;
23
+ const delta = n - m;
24
+ const odd = (delta & 1) !== 0;
25
+ const max = Math.min(Math.ceil((n + m) / 2), Math.ceil(maxEdits / 2));
26
+ const offset = max + 1;
27
+ const forward = new Int32Array(2 * max + 3);
28
+ const backward = new Int32Array(2 * max + 3);
29
+ for (let d = 0; d <= max; d++) {
30
+ for (let k = -d; k <= d; k += 2) {
31
+ const down = k === -d || k !== d && (forward[offset + k - 1] ?? 0) < (forward[offset + k + 1] ?? 0);
32
+ let x = down ? forward[offset + k + 1] ?? 0 : (forward[offset + k - 1] ?? 0) + 1;
33
+ let y = x - k;
34
+ const x0 = x;
35
+ const y0 = y;
36
+ while (x < n && y < m && a[aLo + x] === b[bLo + y]) {
37
+ x++;
38
+ y++;
39
+ }
40
+ forward[offset + k] = x;
41
+ const other = delta - k;
42
+ if (odd && other >= -(d - 1) && other <= d - 1 && x + (backward[offset + other] ?? 0) >= n) {
43
+ return { x: x0, y: y0, u: x, v: y };
44
+ }
45
+ }
46
+ for (let k = -d; k <= d; k += 2) {
47
+ const down = k === -d || k !== d && (backward[offset + k - 1] ?? 0) < (backward[offset + k + 1] ?? 0);
48
+ let x = down ? backward[offset + k + 1] ?? 0 : (backward[offset + k - 1] ?? 0) + 1;
49
+ let y = x - k;
50
+ const x0 = x;
51
+ const y0 = y;
52
+ while (x < n && y < m && a[aHi - 1 - x] === b[bHi - 1 - y]) {
53
+ x++;
54
+ y++;
55
+ }
56
+ backward[offset + k] = x;
57
+ const other = delta - k;
58
+ if (!odd && other >= -d && other <= d && x + (forward[offset + other] ?? 0) >= n) {
59
+ return { x: n - x, y: m - y, u: n - x0, v: m - y0 };
60
+ }
61
+ }
62
+ }
63
+ return void 0;
64
+ }
65
+ function diffSequences(a, b, { maxEdits = DEFAULT_MAX_EDITS } = {}) {
66
+ const [left, right] = intern(a, b);
67
+ const runs = [];
68
+ const push = (equal, aStart, aEnd, bStart, bEnd) => {
69
+ if (aStart === aEnd && bStart === bEnd) return;
70
+ const last = runs[runs.length - 1];
71
+ if (last && last.equal === equal) {
72
+ runs[runs.length - 1] = { ...last, aEnd, bEnd };
73
+ return;
74
+ }
75
+ runs.push({ equal, aStart, aEnd, bStart, bEnd });
76
+ };
77
+ const jobs = [{ aLo: 0, aHi: left.length, bLo: 0, bHi: right.length }];
78
+ while (jobs.length > 0) {
79
+ const job = jobs.pop();
80
+ let { aLo, aHi, bLo, bHi } = job;
81
+ if (job.equal) {
82
+ push(true, aLo, aHi, bLo, bHi);
83
+ continue;
84
+ }
85
+ let head = 0;
86
+ while (aLo + head < aHi && bLo + head < bHi && left[aLo + head] === right[bLo + head]) head++;
87
+ push(true, aLo, aLo + head, bLo, bLo + head);
88
+ aLo += head;
89
+ bLo += head;
90
+ let tail = 0;
91
+ while (aHi - tail > aLo && bHi - tail > bLo && left[aHi - 1 - tail] === right[bHi - 1 - tail]) {
92
+ tail++;
93
+ }
94
+ aHi -= tail;
95
+ bHi -= tail;
96
+ const after = { equal: true, aLo: aHi, aHi: aHi + tail, bLo: bHi, bHi: bHi + tail };
97
+ const snake = aLo < aHi && bLo < bHi ? middleSnake(left, right, aLo, aHi, bLo, bHi, maxEdits) : void 0;
98
+ if (!snake) {
99
+ push(false, aLo, aHi, bLo, bHi);
100
+ jobs.push(after);
101
+ continue;
102
+ }
103
+ jobs.push(
104
+ after,
105
+ { aLo: aLo + snake.u, aHi, bLo: bLo + snake.v, bHi },
106
+ {
107
+ equal: true,
108
+ aLo: aLo + snake.x,
109
+ aHi: aLo + snake.u,
110
+ bLo: bLo + snake.y,
111
+ bHi: bLo + snake.v
112
+ },
113
+ { aLo, aHi: aLo + snake.x, bLo, bHi: bLo + snake.y }
114
+ );
115
+ }
116
+ return runs;
117
+ }
118
+
119
+ // src/text/lines.ts
120
+ function splitLines(text) {
121
+ const lines = [];
122
+ let start = 0;
123
+ for (let i = 0; i < text.length; i++) {
124
+ const code = text.charCodeAt(i);
125
+ if (code !== 10 && code !== 13) continue;
126
+ const crlf = code === 13 && text.charCodeAt(i + 1) === 10;
127
+ const ending = crlf ? "\r\n" : code === 13 ? "\r" : "\n";
128
+ lines.push({ text: text.slice(start, i), ending });
129
+ if (crlf) i++;
130
+ start = i + 1;
131
+ }
132
+ if (start < text.length) lines.push({ text: text.slice(start), ending: "" });
133
+ return lines;
134
+ }
135
+ function joinLines(lines) {
136
+ let out = "";
137
+ for (const line of lines) out += line.text + line.ending;
138
+ return out;
139
+ }
140
+ function dominantEnding(lines) {
141
+ let lf = 0;
142
+ let crlf = 0;
143
+ let cr = 0;
144
+ for (const { ending } of lines) {
145
+ if (ending === "\n") lf++;
146
+ else if (ending === "\r\n") crlf++;
147
+ else if (ending === "\r") cr++;
148
+ }
149
+ if (crlf > lf && crlf >= cr) return "\r\n";
150
+ if (cr > lf && cr > crlf) return "\r";
151
+ return "\n";
152
+ }
153
+
154
+ // src/text/compare.ts
155
+ var whole = (lines) => lines.map((line) => line.text + line.ending);
156
+ function diffLines(before, after) {
157
+ const a = splitLines(before);
158
+ const b = splitLines(after);
159
+ return diffSequences(whole(a), whole(b)).map((run) => ({
160
+ equal: run.equal,
161
+ before: a.slice(run.aStart, run.aEnd),
162
+ after: b.slice(run.bStart, run.bEnd)
163
+ }));
164
+ }
165
+ var WORDS = /[\p{L}\p{M}\p{N}_]+|\s+|[^\p{L}\p{M}\p{N}_\s]/gu;
166
+ function diffWords(before, after) {
167
+ const a = before.match(WORDS) ?? [];
168
+ const b = after.match(WORDS) ?? [];
169
+ return diffSequences(a, b).map((run) => ({
170
+ equal: run.equal,
171
+ before: a.slice(run.aStart, run.aEnd).join(""),
172
+ after: b.slice(run.bStart, run.bEnd).join("")
173
+ }));
174
+ }
175
+
176
+ // src/text/merge.ts
177
+ var whole2 = (lines) => lines.map((line) => line.text + line.ending);
178
+ function mergeText(base, ours, theirs) {
179
+ const original = splitLines(base);
180
+ const left = splitLines(ours);
181
+ const right = splitLines(theirs);
182
+ const lines = whole2(original);
183
+ const changes = (other) => diffSequences(lines, whole2(other)).filter((run) => !run.equal);
184
+ const sides = [changes(left), changes(right)];
185
+ const parts = [];
186
+ let conflicts = 0;
187
+ const next = [0, 0];
188
+ const shift = [0, 0];
189
+ let at = 0;
190
+ const add = (kind, end, from) => {
191
+ parts.push({
192
+ kind,
193
+ base: original.slice(at, end),
194
+ ours: left.slice(from[0], end + shift[0]),
195
+ theirs: right.slice(from[1], end + shift[1])
196
+ });
197
+ };
198
+ const here = () => [at + shift[0], at + shift[1]];
199
+ const peek = (side) => sides[side][next[side]];
200
+ while (peek(0) || peek(1)) {
201
+ const start = Math.min(peek(0)?.aStart ?? Infinity, peek(1)?.aStart ?? Infinity);
202
+ if (start > at) {
203
+ add("same", start, here());
204
+ at = start;
205
+ }
206
+ const from = here();
207
+ const changed = [false, false];
208
+ let end = start;
209
+ for (let grew = true; grew; ) {
210
+ grew = false;
211
+ for (const side of [0, 1]) {
212
+ for (let run = peek(side); run && run.aStart <= end; run = peek(side)) {
213
+ end = Math.max(end, run.aEnd);
214
+ shift[side] = run.bEnd - run.aEnd;
215
+ next[side] = next[side] + 1;
216
+ changed[side] = true;
217
+ grew = true;
218
+ }
219
+ }
220
+ }
221
+ let kind = changed[0] ? "ours" : "theirs";
222
+ if (changed[0] && changed[1]) {
223
+ const a = joinLines(left.slice(from[0], end + shift[0]));
224
+ const b = joinLines(right.slice(from[1], end + shift[1]));
225
+ kind = a === b ? "both" : "conflict";
226
+ }
227
+ if (kind === "conflict") conflicts++;
228
+ add(kind, end, from);
229
+ at = end;
230
+ }
231
+ if (at < original.length) add("same", original.length, here());
232
+ return { parts, conflicts };
233
+ }
234
+ function resolveMerge(merge, choices = []) {
235
+ const usual = dominantEnding(merge.parts.flatMap((part) => [...part.ours, ...part.theirs]));
236
+ let text = "";
237
+ let conflict = 0;
238
+ let open = 0;
239
+ const append = (piece) => {
240
+ if (!piece) return;
241
+ if (text && !text.endsWith("\n") && !text.endsWith("\r")) text += usual;
242
+ text += piece;
243
+ };
244
+ for (const part of merge.parts) {
245
+ if (part.kind === "same") append(joinLines(part.base));
246
+ else if (part.kind === "theirs") append(joinLines(part.theirs));
247
+ else if (part.kind !== "conflict") append(joinLines(part.ours));
248
+ else {
249
+ const choice = choices[conflict++];
250
+ if (choice === void 0) open++;
251
+ else if (choice === "ours") append(joinLines(part.ours));
252
+ else if (choice === "theirs") append(joinLines(part.theirs));
253
+ else if (choice === "both") {
254
+ append(joinLines(part.ours));
255
+ append(joinLines(part.theirs));
256
+ } else append(choice.text);
257
+ }
258
+ }
259
+ return { text: open > 0 ? null : text, open };
260
+ }
261
+ export {
262
+ diffLines,
263
+ diffWords,
264
+ joinLines,
265
+ mergeText,
266
+ resolveMerge,
267
+ splitLines
268
+ };
@@ -75,6 +75,14 @@
75
75
  --sv-color-info-text: var(--sv-blue-800);
76
76
  --sv-color-info-border: var(--sv-blue-200);
77
77
 
78
+ /* Colours of text in a source editor: punctuation and comments, headings, links
79
+ and addresses, code and quoted values, and keywords and tags. */
80
+ --sv-color-syntax-marker: var(--sv-grey-500);
81
+ --sv-color-syntax-heading: var(--sv-red-700);
82
+ --sv-color-syntax-link: var(--sv-blue-800);
83
+ --sv-color-syntax-code: var(--sv-green-800);
84
+ --sv-color-syntax-keyword: var(--sv-amber-800);
85
+
78
86
  /* Overlay surfaces (Dialog/Sheet): the scrim behind a dialog and the panel's
79
87
  elevation shadow. Composed rgba layers, like --sv-shadow-card. */
80
88
  --sv-color-scrim: rgba(0, 0, 0, 0.5);
@@ -150,6 +158,12 @@
150
158
  --sv-color-info-text: var(--sv-blue-100);
151
159
  --sv-color-info-border: var(--sv-blue-800);
152
160
 
161
+ --sv-color-syntax-marker: var(--sv-grey-400);
162
+ --sv-color-syntax-heading: var(--sv-red-200);
163
+ --sv-color-syntax-link: var(--sv-blue-200);
164
+ --sv-color-syntax-code: var(--sv-green-200);
165
+ --sv-color-syntax-keyword: var(--sv-amber-200);
166
+
153
167
  --sv-color-scrim: rgba(0, 0, 0, 0.65);
154
168
 
155
169
  --sv-color-shadow-strong: var(--sv-grey-50);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sovereignfs/ui",
3
- "version": "0.107.3",
3
+ "version": "0.110.0",
4
4
  "type": "module",
5
5
  "description": "Sovereign Design System — design tokens and React components.",
6
6
  "keywords": [
@@ -41,6 +41,18 @@
41
41
  "./map": {
42
42
  "types": "./dist/map.d.ts",
43
43
  "default": "./dist/map.js"
44
+ },
45
+ "./text": {
46
+ "types": "./dist/text.d.ts",
47
+ "default": "./dist/text.js"
48
+ },
49
+ "./markdown": {
50
+ "types": "./dist/markdown.d.ts",
51
+ "default": "./dist/markdown.js"
52
+ },
53
+ "./markdown-editor": {
54
+ "types": "./dist/markdown-editor.d.ts",
55
+ "default": "./dist/markdown-editor.js"
44
56
  }
45
57
  },
46
58
  "files": [
@@ -54,6 +66,20 @@
54
66
  "@dnd-kit/core": "^6.3.1",
55
67
  "@dnd-kit/sortable": "^10.0.0",
56
68
  "maplibre-gl": "^6.18.0",
69
+ "mdast-util-from-markdown": "^2.1.0",
70
+ "mdast-util-gfm": "^3.1.0",
71
+ "mdast-util-to-markdown": "^2.2.5",
72
+ "micromark-extension-gfm": "^3.0.0",
73
+ "prosemirror-commands": "^1.7.2",
74
+ "prosemirror-gapcursor": "^1.4.1",
75
+ "prosemirror-history": "^1.5.2",
76
+ "prosemirror-inputrules": "^1.7.0",
77
+ "prosemirror-keymap": "^1.2.3",
78
+ "prosemirror-model": "^1.25.13",
79
+ "prosemirror-schema-list": "^1.6.1",
80
+ "prosemirror-state": "^1.4.4",
81
+ "prosemirror-tables": "^1.8.5",
82
+ "prosemirror-view": "^1.44.0",
57
83
  "react": "^19.0.0",
58
84
  "react-dom": "^19.0.0"
59
85
  },
@@ -66,6 +92,48 @@
66
92
  },
67
93
  "maplibre-gl": {
68
94
  "optional": true
95
+ },
96
+ "mdast-util-from-markdown": {
97
+ "optional": true
98
+ },
99
+ "mdast-util-gfm": {
100
+ "optional": true
101
+ },
102
+ "mdast-util-to-markdown": {
103
+ "optional": true
104
+ },
105
+ "micromark-extension-gfm": {
106
+ "optional": true
107
+ },
108
+ "prosemirror-commands": {
109
+ "optional": true
110
+ },
111
+ "prosemirror-gapcursor": {
112
+ "optional": true
113
+ },
114
+ "prosemirror-history": {
115
+ "optional": true
116
+ },
117
+ "prosemirror-inputrules": {
118
+ "optional": true
119
+ },
120
+ "prosemirror-keymap": {
121
+ "optional": true
122
+ },
123
+ "prosemirror-model": {
124
+ "optional": true
125
+ },
126
+ "prosemirror-schema-list": {
127
+ "optional": true
128
+ },
129
+ "prosemirror-state": {
130
+ "optional": true
131
+ },
132
+ "prosemirror-tables": {
133
+ "optional": true
134
+ },
135
+ "prosemirror-view": {
136
+ "optional": true
69
137
  }
70
138
  },
71
139
  "devDependencies": {
@@ -82,6 +150,20 @@
82
150
  "@types/react": "^19.3.0",
83
151
  "@types/react-dom": "^19.3.0",
84
152
  "maplibre-gl": "^6.18.0",
153
+ "mdast-util-from-markdown": "2.1.0",
154
+ "mdast-util-gfm": "3.1.0",
155
+ "mdast-util-to-markdown": "2.2.5",
156
+ "micromark-extension-gfm": "3.0.0",
157
+ "prosemirror-commands": "1.7.2",
158
+ "prosemirror-gapcursor": "1.4.1",
159
+ "prosemirror-history": "1.5.2",
160
+ "prosemirror-inputrules": "1.7.0",
161
+ "prosemirror-keymap": "1.2.3",
162
+ "prosemirror-model": "1.25.13",
163
+ "prosemirror-schema-list": "1.6.1",
164
+ "prosemirror-state": "1.4.4",
165
+ "prosemirror-tables": "1.8.5",
166
+ "prosemirror-view": "1.44.0",
85
167
  "react": "^19.3.1",
86
168
  "react-dom": "^19.3.1",
87
169
  "storybook": "^10.6.7",
@@ -93,6 +175,7 @@
93
175
  "storybook": "storybook dev -p 6006",
94
176
  "storybook:visual": "storybook dev -p 6100 --ci --quiet",
95
177
  "build-storybook": "storybook build --output-dir storybook-static",
178
+ "test:policy": "playwright test --config=playwright.policy.config.ts",
96
179
  "test:visual": "playwright test --config=playwright.visual.config.ts",
97
180
  "test:visual:update": "playwright test --config=playwright.visual.config.ts --update-snapshots",
98
181
  "typecheck": "tsc --noEmit"