@adecore/editor-react 0.58.0 → 0.60.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/PeekPanel.js CHANGED
@@ -11,7 +11,7 @@ import { PANEL_BODY_HEIGHT } from './panel-size.js';
11
11
  import { PanelResizeHandle } from "./PanelResizeHandle.js";
12
12
  import { basenameOf, relativeTo } from './paths.js';
13
13
  import { PathText } from "./PathText.js";
14
- import { distinguishingFolders, visualColumnOf } from './peek-model.js';
14
+ import { distinguishingFolders, highlightedLinesOf, visualColumnOf } from './peek-model.js';
15
15
  import { PEEK_HEIGHT } from './peek.js';
16
16
  import { useEditorRendering } from './rendering-context.js';
17
17
  import { usePanelBody } from './use-panel-body.js';
@@ -278,11 +278,87 @@ function columnsOf(line, name) {
278
278
  function folderOf(path) {
279
279
  return path.slice(0, Math.max(0, path.lastIndexOf('/')));
280
280
  }
281
- /* A line of code with its name in the text color and the rest muted. */
281
+ /*
282
+ * The syntax-colored markup of each place's line, by place id, once the highlighter has answered. A file's
283
+ * lines go through it together, in the language of the file, and a file it fails for keeps its plain lines.
284
+ */
285
+ function useHighlightedPlaces(files) {
286
+ const $ = _c(8);
287
+ const {
288
+ theme,
289
+ highlight
290
+ } = useEditorRendering();
291
+ const [done, setDone] = useState(null);
292
+ let t0;
293
+ if ($[0] !== files) {
294
+ t0 = files.map(_temp3).join("\0");
295
+ $[0] = files;
296
+ $[1] = t0;
297
+ } else {
298
+ t0 = $[1];
299
+ }
300
+ const key = `${theme}\0${t0}`;
301
+ let t1;
302
+ let t2;
303
+ if ($[2] !== files || $[3] !== highlight || $[4] !== key || $[5] !== theme) {
304
+ t1 = () => {
305
+ if (highlight === undefined) {
306
+ return;
307
+ }
308
+ let alive = true;
309
+ Promise.all(files.map(async file_0 => {
310
+ const texts = file_0.places.map(_temp4);
311
+ if (texts.every(_temp5)) {
312
+ return [];
313
+ }
314
+ const html = await highlight(texts.join("\n"), shikiLanguageOfPath(fileUriToPath(file_0.uri) ?? file_0.uri), theme).catch(_temp6);
315
+ const lines = html === null ? null : highlightedLinesOf(html, texts.length);
316
+ return lines === null ? [] : file_0.places.flatMap((place_1, index) => place_1.text === "" ? [] : [[place_1.id, lines[index]]]);
317
+ })).then(entries => alive && setDone({
318
+ key,
319
+ lines: new Map(entries.flat())
320
+ })).catch(_temp7);
321
+ return () => {
322
+ alive = false;
323
+ };
324
+ };
325
+ t2 = [files, theme, key, highlight];
326
+ $[2] = files;
327
+ $[3] = highlight;
328
+ $[4] = key;
329
+ $[5] = theme;
330
+ $[6] = t1;
331
+ $[7] = t2;
332
+ } else {
333
+ t1 = $[6];
334
+ t2 = $[7];
335
+ }
336
+ useEffect(t1, t2);
337
+ return done?.key === key ? done.lines : NO_LINES;
338
+ }
339
+ function _temp7() {}
340
+ function _temp6() {
341
+ return null;
342
+ }
343
+ function _temp5(text) {
344
+ return text === "";
345
+ }
346
+ function _temp4(place_0) {
347
+ return place_0.text;
348
+ }
349
+ function _temp3(file) {
350
+ return `${file.uri}\0${file.places.map(_temp2).join("\n")}`;
351
+ }
352
+ function _temp2(place) {
353
+ return place.text;
354
+ }
355
+ const NO_LINES = new Map();
356
+ /* A line of code in the colors of its syntax with the name marked, or with its name in the text color and the rest muted while no colors are at hand. */
282
357
  function PlaceText(t0) {
283
- const $ = _c(20);
358
+ const $ = _c(27);
284
359
  const {
285
- place
360
+ place,
361
+ html
286
362
  } = t0;
287
363
  if (place.text === "") {
288
364
  const t1 = `:${place.line + 1}`;
@@ -302,71 +378,114 @@ function PlaceText(t0) {
302
378
  const {
303
379
  name
304
380
  } = place;
381
+ if (html !== undefined) {
382
+ let t1;
383
+ if ($[2] !== name) {
384
+ t1 = name !== null && /*#__PURE__*/_jsx("span", {
385
+ "aria-hidden": true,
386
+ className: "absolute inset-y-0 rounded-sm bg-(--editor-occurrence)",
387
+ style: {
388
+ left: `${name.start}ch`,
389
+ width: `${name.end - name.start}ch`
390
+ }
391
+ });
392
+ $[2] = name;
393
+ $[3] = t1;
394
+ } else {
395
+ t1 = $[3];
396
+ }
397
+ let t2;
398
+ if ($[4] !== html) {
399
+ t2 = /*#__PURE__*/_jsx("span", {
400
+ className: "relative",
401
+ dangerouslySetInnerHTML: {
402
+ __html: html
403
+ }
404
+ });
405
+ $[4] = html;
406
+ $[5] = t2;
407
+ } else {
408
+ t2 = $[5];
409
+ }
410
+ let t3;
411
+ if ($[6] !== t1 || $[7] !== t2) {
412
+ t3 = /*#__PURE__*/_jsxs("span", {
413
+ className: "relative min-w-0 truncate whitespace-pre",
414
+ children: [t1, t2]
415
+ });
416
+ $[6] = t1;
417
+ $[7] = t2;
418
+ $[8] = t3;
419
+ } else {
420
+ t3 = $[8];
421
+ }
422
+ return t3;
423
+ }
305
424
  if (name === null) {
306
425
  let t1;
307
- if ($[2] !== place.text) {
426
+ if ($[9] !== place.text) {
308
427
  t1 = /*#__PURE__*/_jsx("span", {
309
428
  className: "min-w-0 truncate text-text-muted",
310
429
  children: place.text
311
430
  });
312
- $[2] = place.text;
313
- $[3] = t1;
431
+ $[9] = place.text;
432
+ $[10] = t1;
314
433
  } else {
315
- t1 = $[3];
434
+ t1 = $[10];
316
435
  }
317
436
  return t1;
318
437
  }
319
438
  let t1;
320
- if ($[4] !== name.start || $[5] !== place.text) {
439
+ if ($[11] !== name.start || $[12] !== place.text) {
321
440
  t1 = place.text.slice(0, name.start);
322
- $[4] = name.start;
323
- $[5] = place.text;
324
- $[6] = t1;
441
+ $[11] = name.start;
442
+ $[12] = place.text;
443
+ $[13] = t1;
325
444
  } else {
326
- t1 = $[6];
445
+ t1 = $[13];
327
446
  }
328
447
  let t2;
329
- if ($[7] !== name.end || $[8] !== name.start || $[9] !== place.text) {
448
+ if ($[14] !== name.end || $[15] !== name.start || $[16] !== place.text) {
330
449
  t2 = place.text.slice(name.start, name.end);
331
- $[7] = name.end;
332
- $[8] = name.start;
333
- $[9] = place.text;
334
- $[10] = t2;
450
+ $[14] = name.end;
451
+ $[15] = name.start;
452
+ $[16] = place.text;
453
+ $[17] = t2;
335
454
  } else {
336
- t2 = $[10];
455
+ t2 = $[17];
337
456
  }
338
457
  let t3;
339
- if ($[11] !== t2) {
458
+ if ($[18] !== t2) {
340
459
  t3 = /*#__PURE__*/_jsx("span", {
341
460
  className: "font-semibold text-text",
342
461
  children: t2
343
462
  });
344
- $[11] = t2;
345
- $[12] = t3;
463
+ $[18] = t2;
464
+ $[19] = t3;
346
465
  } else {
347
- t3 = $[12];
466
+ t3 = $[19];
348
467
  }
349
468
  let t4;
350
- if ($[13] !== name.end || $[14] !== place.text) {
469
+ if ($[20] !== name.end || $[21] !== place.text) {
351
470
  t4 = place.text.slice(name.end);
352
- $[13] = name.end;
353
- $[14] = place.text;
354
- $[15] = t4;
471
+ $[20] = name.end;
472
+ $[21] = place.text;
473
+ $[22] = t4;
355
474
  } else {
356
- t4 = $[15];
475
+ t4 = $[22];
357
476
  }
358
477
  let t5;
359
- if ($[16] !== t1 || $[17] !== t3 || $[18] !== t4) {
478
+ if ($[23] !== t1 || $[24] !== t3 || $[25] !== t4) {
360
479
  t5 = /*#__PURE__*/_jsxs("span", {
361
480
  className: "min-w-0 truncate text-text-muted",
362
481
  children: [t1, t3, t4]
363
482
  });
364
- $[16] = t1;
365
- $[17] = t3;
366
- $[18] = t4;
367
- $[19] = t5;
483
+ $[23] = t1;
484
+ $[24] = t3;
485
+ $[25] = t4;
486
+ $[26] = t5;
368
487
  } else {
369
- t5 = $[19];
488
+ t5 = $[26];
370
489
  }
371
490
  return t5;
372
491
  }
@@ -391,6 +510,7 @@ function Places(t0) {
391
510
  }
392
511
  const paths = view.files.map(t1);
393
512
  const folders = distinguishingFolders(paths);
513
+ const highlighted = useHighlightedPlaces(view.files);
394
514
  let t2;
395
515
  if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
396
516
  t2 = () => {
@@ -450,7 +570,8 @@ function Places(t0) {
450
570
  onClick: () => place.id === view.active ? language.peek.go(place.id) : language.peek.select(place.id),
451
571
  onDoubleClick: () => language.peek.go(place.id),
452
572
  children: /*#__PURE__*/_jsx(PlaceText, {
453
- place: place
573
+ place: place,
574
+ html: highlighted.get(place.id)
454
575
  })
455
576
  }, place.id))]
456
577
  }, file_0.uri);
@@ -492,7 +613,7 @@ export function PeekPanel(t0) {
492
613
  } else {
493
614
  t1 = $[1];
494
615
  }
495
- const active = view.files.flatMap(_temp2).find(t1);
616
+ const active = view.files.flatMap(_temp8).find(t1);
496
617
  const path = active === undefined ? null : fileUriToPath(active.location.uri);
497
618
  const folder = language.project.folder;
498
619
  const shown = path === null ? "" : folderOf(relativeTo(path, folder));
@@ -513,7 +634,7 @@ export function PeekPanel(t0) {
513
634
  } else {
514
635
  t5 = $[3];
515
636
  }
516
- const t6 = _temp3;
637
+ const t6 = _temp9;
517
638
  let t7;
518
639
  if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
519
640
  t7 = /*#__PURE__*/_jsx("div", {
@@ -723,9 +844,9 @@ export function PeekPanel(t0) {
723
844
  }
724
845
  return t27;
725
846
  }
726
- function _temp3(event) {
847
+ function _temp9(event) {
727
848
  return event.preventDefault();
728
849
  }
729
- function _temp2(file) {
850
+ function _temp8(file) {
730
851
  return file.places;
731
852
  }
@@ -24,5 +24,6 @@ export interface PeekSnippet {
24
24
  }
25
25
  export declare function snippetOf(text: string, line: number, range: Range): PeekSnippet;
26
26
  export declare function definitionSnippetOf(text: string, line: number, declaration: Range | null, range: Range): PeekSnippet;
27
+ export declare function highlightedLinesOf(html: string, count: number): string[] | null;
27
28
  export declare function distinguishingFolders(paths: readonly string[]): string[];
28
29
  export declare function visualColumnOf(line: string, character: number, tabSize: number): number;
@@ -88,6 +88,20 @@ export function definitionSnippetOf(text, line, declaration, range) {
88
88
  name: columnsOf(range, line, (lines[line] ?? '').length)
89
89
  };
90
90
  }
91
+ const HIGHLIGHTED_LINE = /^<span class="line">([\s\S]*)<\/span>$/;
92
+ /*
93
+ * The markup of each line out of highlighted code, which puts every line in a `span.line` and separates them
94
+ * with a newline. Null when the code does not come back as `count` such lines, so a caller draws plain text
95
+ * instead of lines that belong to other code.
96
+ */
97
+ export function highlightedLinesOf(html, count) {
98
+ const code = /<code[^>]*>([\s\S]*)<\/code>/.exec(html)?.[1];
99
+ if (code === undefined) {
100
+ return null;
101
+ }
102
+ const lines = code.split('\n').map(line => HIGHLIGHTED_LINE.exec(line)?.[1]);
103
+ return lines.length === count && lines.every(line => line !== undefined) ? lines : null;
104
+ }
91
105
  /*
92
106
  * For each path, the trailing folders that tell it from the other paths with the same file name, as few
93
107
  * as it takes; empty for a file whose name is its own.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adecore/editor-react",
3
- "version": "0.58.0",
3
+ "version": "0.60.0",
4
4
  "type": "module",
5
5
  "description": "Language-enabled editors, feature coordination and React popups over injected language services.",
6
6
  "license": "FSL-1.1-MIT",
@@ -62,9 +62,9 @@
62
62
  "test": "bun test --conditions=source"
63
63
  },
64
64
  "dependencies": {
65
- "@adecore/editor": "0.58.0",
66
- "@adecore/lsp": "0.58.0",
67
- "@adecore/merge": "0.58.0",
65
+ "@adecore/editor": "0.60.0",
66
+ "@adecore/lsp": "0.60.0",
67
+ "@adecore/merge": "0.60.0",
68
68
  "emmet": "^2.4.11",
69
69
  "lucide-react": "^1.65.0",
70
70
  "react-markdown": "^10.1.0",
@@ -73,14 +73,14 @@
73
73
  "zustand": "^5.0.16"
74
74
  },
75
75
  "peerDependencies": {
76
- "@adecore/ui": "^0.58.0",
76
+ "@adecore/ui": "^0.60.0",
77
77
  "i18next": "^26.5.12",
78
78
  "react": "^19.3.1",
79
79
  "react-dom": "^19.3.1",
80
80
  "react-i18next": "^17.1.9"
81
81
  },
82
82
  "devDependencies": {
83
- "@adecore/ui": "0.58.0",
83
+ "@adecore/ui": "0.60.0",
84
84
  "@types/bun": "^1.4.4",
85
85
  "@types/react": "^19.3.0",
86
86
  "@types/react-dom": "^19.3.0",
package/src/PeekPanel.tsx CHANGED
@@ -11,7 +11,7 @@ import { PANEL_BODY_HEIGHT } from './panel-size.ts';
11
11
  import { PanelResizeHandle } from './PanelResizeHandle.tsx';
12
12
  import { basenameOf, relativeTo } from './paths.ts';
13
13
  import { PathText } from './PathText.tsx';
14
- import { distinguishingFolders, visualColumnOf, type NameRange, type PeekPlace } from './peek-model.ts';
14
+ import { distinguishingFolders, highlightedLinesOf, visualColumnOf, type NameRange, type PeekFile, type PeekPlace } from './peek-model.ts';
15
15
  import { PEEK_HEIGHT } from './peek.ts';
16
16
  import type { PeekView } from './popups.ts';
17
17
  import { useEditorRendering } from './rendering-context.ts';
@@ -108,14 +108,74 @@ function folderOf(path: string): string {
108
108
  return path.slice(0, Math.max(0, path.lastIndexOf('/')));
109
109
  }
110
110
 
111
- /* A line of code with its name in the text color and the rest muted. */
112
- function PlaceText({ place }: { place: PeekPlace }) {
111
+ /*
112
+ * The syntax-colored markup of each place's line, by place id, once the highlighter has answered. A file's
113
+ * lines go through it together, in the language of the file, and a file it fails for keeps its plain lines.
114
+ */
115
+ function useHighlightedPlaces(files: readonly PeekFile[]): ReadonlyMap<string, string> {
116
+ const { theme, highlight } = useEditorRendering();
117
+ const [done, setDone] = useState<{ key: string; lines: ReadonlyMap<string, string> } | null>(null);
118
+ const key = `${theme}\0${files.map((file) => `${file.uri}\0${file.places.map((place) => place.text).join('\n')}`).join('\0')}`;
119
+
120
+ useEffect(() => {
121
+ if (highlight === undefined) {
122
+ return;
123
+ }
124
+
125
+ let alive = true;
126
+
127
+ Promise.all(
128
+ files.map(async (file): Promise<Array<[string, string]>> => {
129
+ const texts = file.places.map((place) => place.text);
130
+
131
+ if (texts.every((text) => text === '')) {
132
+ return [];
133
+ }
134
+
135
+ const html = await highlight(texts.join('\n'), shikiLanguageOfPath(fileUriToPath(file.uri) ?? file.uri), theme).catch(() => null);
136
+ const lines = html === null ? null : highlightedLinesOf(html, texts.length);
137
+
138
+ return lines === null
139
+ ? []
140
+ : file.places.flatMap((place, index): Array<[string, string]> => (place.text === '' ? [] : [[place.id, lines[index]!]]));
141
+ })
142
+ )
143
+ .then((entries) => alive && setDone({ key, lines: new Map(entries.flat()) }))
144
+ .catch(() => undefined);
145
+
146
+ return () => {
147
+ alive = false;
148
+ };
149
+ }, [files, theme, key, highlight]);
150
+
151
+ return done?.key === key ? done.lines : NO_LINES;
152
+ }
153
+
154
+ const NO_LINES: ReadonlyMap<string, string> = new Map();
155
+
156
+ /* A line of code in the colors of its syntax with the name marked, or with its name in the text color and the rest muted while no colors are at hand. */
157
+ function PlaceText({ place, html }: { place: PeekPlace; html: string | undefined }) {
113
158
  if (place.text === '') {
114
159
  return <span className="min-w-0 truncate text-text-muted">{`:${place.line + 1}`}</span>;
115
160
  }
116
161
 
117
162
  const { name } = place;
118
163
 
164
+ if (html !== undefined) {
165
+ return (
166
+ <span className="relative min-w-0 truncate whitespace-pre">
167
+ {name !== null && (
168
+ <span
169
+ aria-hidden
170
+ className="absolute inset-y-0 rounded-sm bg-(--editor-occurrence)"
171
+ style={{ left: `${name.start}ch`, width: `${name.end - name.start}ch` }}
172
+ />
173
+ )}
174
+ <span className="relative" dangerouslySetInnerHTML={{ __html: html }} />
175
+ </span>
176
+ );
177
+ }
178
+
119
179
  if (name === null) {
120
180
  return <span className="min-w-0 truncate text-text-muted">{place.text}</span>;
121
181
  }
@@ -135,6 +195,7 @@ function Places({ language, view }: { language: EditorLanguage; view: PeekView }
135
195
  const folder = language.project.folder;
136
196
  const paths = view.files.map((file) => relativeTo(fileUriToPath(file.uri) ?? file.uri, folder));
137
197
  const folders = distinguishingFolders(paths);
198
+ const highlighted = useHighlightedPlaces(view.files);
138
199
 
139
200
  useEffect(() => {
140
201
  activeRow.current?.scrollIntoView({ block: 'nearest' });
@@ -172,7 +233,7 @@ function Places({ language, view }: { language: EditorLanguage; view: PeekView }
172
233
  onClick={() => (place.id === view.active ? language.peek.go(place.id) : language.peek.select(place.id))}
173
234
  onDoubleClick={() => language.peek.go(place.id)}
174
235
  >
175
- <PlaceText place={place} />
236
+ <PlaceText place={place} html={highlighted.get(place.id)} />
176
237
  </button>
177
238
  ))}
178
239
  </div>
package/src/peek-model.ts CHANGED
@@ -126,6 +126,25 @@ export function definitionSnippetOf(text: string, line: number, declaration: Ran
126
126
  return { startLine, text: lines.slice(startLine, end + 1).join('\n'), active: line - startLine, name: columnsOf(range, line, (lines[line] ?? '').length) };
127
127
  }
128
128
 
129
+ const HIGHLIGHTED_LINE = /^<span class="line">([\s\S]*)<\/span>$/;
130
+
131
+ /*
132
+ * The markup of each line out of highlighted code, which puts every line in a `span.line` and separates them
133
+ * with a newline. Null when the code does not come back as `count` such lines, so a caller draws plain text
134
+ * instead of lines that belong to other code.
135
+ */
136
+ export function highlightedLinesOf(html: string, count: number): string[] | null {
137
+ const code = /<code[^>]*>([\s\S]*)<\/code>/.exec(html)?.[1];
138
+
139
+ if (code === undefined) {
140
+ return null;
141
+ }
142
+
143
+ const lines = code.split('\n').map((line) => HIGHLIGHTED_LINE.exec(line)?.[1]);
144
+
145
+ return lines.length === count && lines.every((line) => line !== undefined) ? (lines as string[]) : null;
146
+ }
147
+
129
148
  /*
130
149
  * For each path, the trailing folders that tell it from the other paths with the same file name, as few
131
150
  * as it takes; empty for a file whose name is its own.