@limetech/lime-elements 39.5.7 → 39.7.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/CHANGELOG.md +14 -0
- package/dist/cjs/lime-elements.cjs.js +1 -1
- package/dist/cjs/{limel-action-bar_2.cjs.entry.js → limel-action-bar_3.cjs.entry.js} +111 -93
- package/dist/cjs/limel-ai-avatar.cjs.entry.js +1 -1
- package/dist/cjs/limel-breadcrumbs_7.cjs.entry.js +6 -6
- package/dist/cjs/limel-button-group.cjs.entry.js +7 -8
- package/dist/cjs/limel-callout.cjs.entry.js +1 -1
- package/dist/cjs/limel-chart.cjs.entry.js +1 -1
- package/dist/cjs/limel-chip_2.cjs.entry.js +1 -1
- package/dist/cjs/limel-code-diff.cjs.entry.js +1758 -0
- package/dist/cjs/limel-code-editor.cjs.entry.js +2 -2
- package/dist/cjs/limel-collapsible-section.cjs.entry.js +2 -2
- package/dist/cjs/limel-color-picker-palette.cjs.entry.js +2 -2
- package/dist/cjs/limel-color-picker.cjs.entry.js +1 -1
- package/dist/cjs/limel-dialog.cjs.entry.js +2 -2
- package/dist/cjs/limel-dock.cjs.entry.js +2 -2
- package/dist/cjs/limel-drag-handle.cjs.entry.js +2 -2
- package/dist/cjs/limel-email-viewer.cjs.entry.js +2 -2
- package/dist/cjs/limel-file-dropzone_2.cjs.entry.js +2 -2
- package/dist/cjs/limel-file-viewer.cjs.entry.js +1 -1
- package/dist/cjs/limel-file.cjs.entry.js +2 -2
- package/dist/cjs/limel-flatpickr-adapter.cjs.entry.js +2 -2
- package/dist/cjs/limel-flex-container.cjs.entry.js +1 -1
- package/dist/cjs/limel-form.cjs.entry.js +1 -1
- package/dist/cjs/limel-grid.cjs.entry.js +1 -1
- package/dist/cjs/limel-header.cjs.entry.js +1 -1
- package/dist/cjs/limel-help-content.cjs.entry.js +1 -1
- package/dist/cjs/limel-help.cjs.entry.js +2 -2
- package/dist/cjs/limel-helper-line_2.cjs.entry.js +3 -3
- package/dist/cjs/limel-icon-button.cjs.entry.js +1 -1
- package/dist/cjs/limel-icon.cjs.entry.js +1 -1
- package/dist/cjs/limel-info-tile.cjs.entry.js +2 -2
- package/dist/cjs/limel-linear-progress.cjs.entry.js +1 -1
- package/dist/cjs/limel-list-item.cjs.entry.js +4 -4
- package/dist/cjs/limel-markdown.cjs.entry.js +1 -1
- package/dist/cjs/limel-menu-item-meta.cjs.entry.js +1 -1
- package/dist/cjs/limel-picker.cjs.entry.js +1 -1
- package/dist/cjs/limel-popover_2.cjs.entry.js +2 -2
- package/dist/cjs/limel-portal_3.cjs.entry.js +4 -4
- package/dist/cjs/limel-profile-picture.cjs.entry.js +1 -1
- package/dist/cjs/limel-prosemirror-adapter.cjs.entry.js +2 -2
- package/dist/cjs/limel-radio-button-group.cjs.entry.js +1 -1
- package/dist/cjs/limel-radio-button.cjs.entry.js +2 -2
- package/dist/cjs/limel-select.cjs.entry.js +1 -1
- package/dist/cjs/limel-shortcut.cjs.entry.js +1 -1
- package/dist/cjs/limel-slider.cjs.entry.js +1 -1
- package/dist/cjs/limel-snackbar.cjs.entry.js +3 -3
- package/dist/cjs/limel-split-button.cjs.entry.js +2 -2
- package/dist/cjs/limel-tab-bar.cjs.entry.js +2 -2
- package/dist/cjs/limel-tab-panel.cjs.entry.js +1 -1
- package/dist/cjs/limel-table.cjs.entry.js +4 -4
- package/dist/cjs/limel-text-editor-link-menu.cjs.entry.js +120 -0
- package/dist/cjs/limel-text-editor.cjs.entry.js +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/{translations-BBGWKIVD.js → translations-Bu_0fli7.js} +236 -4
- package/dist/collection/collection-manifest.json +1 -0
- package/dist/collection/components/button-group/button-group.css +38 -650
- package/dist/collection/components/button-group/button-group.js +6 -7
- package/dist/collection/components/code-diff/code-diff.css +519 -0
- package/dist/collection/components/code-diff/code-diff.js +775 -0
- package/dist/collection/components/code-diff/content-utils.js +49 -0
- package/dist/collection/components/code-diff/diff-engine.js +308 -0
- package/dist/collection/components/code-diff/search-utils.js +41 -0
- package/dist/collection/components/code-diff/syntax-highlighter.js +87 -0
- package/dist/collection/components/code-diff/types.js +1 -0
- package/dist/collection/components/code-editor/code-editor.js +1 -1
- package/dist/collection/components/collapsible-section/collapsible-section.js +1 -1
- package/dist/collection/components/color-picker/color-picker-palette.js +2 -2
- package/dist/collection/components/color-picker/color-picker.js +1 -1
- package/dist/collection/components/date-picker/flatpickr-adapter/flatpickr-adapter.js +1 -1
- package/dist/collection/components/dialog/dialog.js +2 -2
- package/dist/collection/components/dock/dock.js +2 -2
- package/dist/collection/components/drag-handle/drag-handle.js +1 -1
- package/dist/collection/components/email-viewer/email-viewer.js +1 -1
- package/dist/collection/components/file/file.js +1 -1
- package/dist/collection/components/file-dropzone/file-dropzone.js +1 -1
- package/dist/collection/components/file-input/file-input.js +1 -1
- package/dist/collection/components/flex-container/flex-container.js +1 -1
- package/dist/collection/components/form/form.js +1 -1
- package/dist/collection/components/grid/grid.js +1 -1
- package/dist/collection/components/header/header.js +1 -1
- package/dist/collection/components/help/help-content.js +1 -1
- package/dist/collection/components/help/help.js +2 -2
- package/dist/collection/components/helper-line/helper-line.js +2 -2
- package/dist/collection/components/icon/icon.js +1 -1
- package/dist/collection/components/icon-button/icon-button.js +1 -1
- package/dist/collection/components/info-tile/info-tile.js +2 -2
- package/dist/collection/components/input-field/input-field.js +1 -1
- package/dist/collection/components/list/list.css +2 -1
- package/dist/collection/components/list/list.js +1 -1
- package/dist/collection/components/list-item/list-item.css +4 -1
- package/dist/collection/components/list-item/list-item.js +2 -2
- package/dist/collection/components/list-item/menu-item-meta/menu-item-meta.js +1 -1
- package/dist/collection/components/markdown/markdown.js +1 -1
- package/dist/collection/components/menu/menu.js +1 -1
- package/dist/collection/components/menu-list/menu-list.css +2 -1
- package/dist/collection/components/menu-list/menu-list.js +1 -1
- package/dist/collection/components/menu-surface/menu-surface.js +1 -1
- package/dist/collection/components/notched-outline/notched-outline.js +1 -1
- package/dist/collection/components/picker/picker.js +1 -1
- package/dist/collection/components/popover/popover.js +1 -1
- package/dist/collection/components/popover-surface/popover-surface.js +1 -1
- package/dist/collection/components/portal/portal.js +1 -1
- package/dist/collection/components/radio-button-group/radio-button-group.js +1 -1
- package/dist/collection/components/radio-button-group/radio-button.js +2 -2
- package/dist/collection/components/select/select.js +1 -1
- package/dist/collection/components/shortcut/shortcut.js +1 -1
- package/dist/collection/components/slider/slider.js +1 -1
- package/dist/collection/components/snackbar/snackbar.js +2 -2
- package/dist/collection/components/spinner/spinner.js +1 -1
- package/dist/collection/components/split-button/split-button.js +2 -2
- package/dist/collection/components/tab-bar/tab-bar.js +2 -2
- package/dist/collection/components/tab-panel/tab-panel.js +1 -1
- package/dist/collection/components/table/table.js +3 -3
- package/dist/collection/components/text-editor/link-menu/editor-link-menu.js +3 -3
- package/dist/collection/components/text-editor/prosemirror-adapter/prosemirror-adapter.js +1 -1
- package/dist/collection/components/text-editor/text-editor.js +1 -1
- package/dist/collection/components/tooltip/tooltip-content.js +1 -1
- package/dist/collection/components/tooltip/tooltip.js +2 -2
- package/dist/collection/translations/da.js +29 -0
- package/dist/collection/translations/de.js +29 -0
- package/dist/collection/translations/en.js +29 -0
- package/dist/collection/translations/fi.js +29 -0
- package/dist/collection/translations/fr.js +33 -4
- package/dist/collection/translations/nl.js +29 -0
- package/dist/collection/translations/no.js +29 -0
- package/dist/collection/translations/sv.js +29 -0
- package/dist/esm/lime-elements.js +1 -1
- package/dist/esm/{limel-action-bar_2.entry.js → limel-action-bar_3.entry.js} +110 -93
- package/dist/esm/limel-ai-avatar.entry.js +1 -1
- package/dist/esm/limel-breadcrumbs_7.entry.js +6 -6
- package/dist/esm/limel-button-group.entry.js +7 -8
- package/dist/esm/limel-callout.entry.js +1 -1
- package/dist/esm/limel-chart.entry.js +1 -1
- package/dist/esm/limel-chip_2.entry.js +1 -1
- package/dist/esm/limel-code-diff.entry.js +1756 -0
- package/dist/esm/limel-code-editor.entry.js +2 -2
- package/dist/esm/limel-collapsible-section.entry.js +2 -2
- package/dist/esm/limel-color-picker-palette.entry.js +2 -2
- package/dist/esm/limel-color-picker.entry.js +1 -1
- package/dist/esm/limel-dialog.entry.js +2 -2
- package/dist/esm/limel-dock.entry.js +2 -2
- package/dist/esm/limel-drag-handle.entry.js +2 -2
- package/dist/esm/limel-email-viewer.entry.js +2 -2
- package/dist/esm/limel-file-dropzone_2.entry.js +2 -2
- package/dist/esm/limel-file-viewer.entry.js +1 -1
- package/dist/esm/limel-file.entry.js +2 -2
- package/dist/esm/limel-flatpickr-adapter.entry.js +2 -2
- package/dist/esm/limel-flex-container.entry.js +1 -1
- package/dist/esm/limel-form.entry.js +1 -1
- package/dist/esm/limel-grid.entry.js +1 -1
- package/dist/esm/limel-header.entry.js +1 -1
- package/dist/esm/limel-help-content.entry.js +1 -1
- package/dist/esm/limel-help.entry.js +2 -2
- package/dist/esm/limel-helper-line_2.entry.js +3 -3
- package/dist/esm/limel-icon-button.entry.js +1 -1
- package/dist/esm/limel-icon.entry.js +1 -1
- package/dist/esm/limel-info-tile.entry.js +2 -2
- package/dist/esm/limel-linear-progress.entry.js +1 -1
- package/dist/esm/limel-list-item.entry.js +4 -4
- package/dist/esm/limel-markdown.entry.js +1 -1
- package/dist/esm/limel-menu-item-meta.entry.js +1 -1
- package/dist/esm/limel-picker.entry.js +1 -1
- package/dist/esm/limel-popover_2.entry.js +2 -2
- package/dist/esm/limel-portal_3.entry.js +4 -4
- package/dist/esm/limel-profile-picture.entry.js +1 -1
- package/dist/esm/limel-prosemirror-adapter.entry.js +2 -2
- package/dist/esm/limel-radio-button-group.entry.js +1 -1
- package/dist/esm/limel-radio-button.entry.js +2 -2
- package/dist/esm/limel-select.entry.js +1 -1
- package/dist/esm/limel-shortcut.entry.js +1 -1
- package/dist/esm/limel-slider.entry.js +1 -1
- package/dist/esm/limel-snackbar.entry.js +3 -3
- package/dist/esm/limel-split-button.entry.js +2 -2
- package/dist/esm/limel-tab-bar.entry.js +2 -2
- package/dist/esm/limel-tab-panel.entry.js +1 -1
- package/dist/esm/limel-table.entry.js +4 -4
- package/dist/esm/limel-text-editor-link-menu.entry.js +118 -0
- package/dist/esm/limel-text-editor.entry.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/{translations-BHybIZJs.js → translations-DVRaJQvC.js} +236 -4
- package/dist/lime-elements/lime-elements.esm.js +1 -1
- package/dist/lime-elements/{p-58176f7b.entry.js → p-05ff053d.entry.js} +1 -1
- package/dist/lime-elements/{p-7dd4e4bb.entry.js → p-08d1b87a.entry.js} +1 -1
- package/dist/lime-elements/{p-94f78e7a.entry.js → p-0fa2add8.entry.js} +1 -1
- package/dist/lime-elements/{p-40883e25.entry.js → p-1547b9c8.entry.js} +1 -1
- package/dist/lime-elements/{p-16a5f421.entry.js → p-1c244f85.entry.js} +1 -1
- package/dist/lime-elements/{p-ba9d6d42.entry.js → p-21dc4586.entry.js} +1 -1
- package/dist/lime-elements/{p-8e6a36a7.entry.js → p-2292181d.entry.js} +1 -1
- package/dist/lime-elements/{p-889d0000.entry.js → p-26bc957e.entry.js} +1 -1
- package/dist/lime-elements/{p-d4a51f0a.entry.js → p-287c4fb1.entry.js} +1 -1
- package/dist/lime-elements/p-358b277c.entry.js +1 -0
- package/dist/lime-elements/{p-f43e4cb8.entry.js → p-44295cc0.entry.js} +1 -1
- package/dist/lime-elements/{p-78fffaa9.entry.js → p-5178cc39.entry.js} +1 -1
- package/dist/lime-elements/{p-ec5b360a.entry.js → p-518fe33c.entry.js} +2 -2
- package/dist/lime-elements/{p-911db0aa.entry.js → p-53b94806.entry.js} +1 -1
- package/dist/lime-elements/p-5be668d8.entry.js +1 -0
- package/dist/lime-elements/{p-f49e5d8a.entry.js → p-68ffd790.entry.js} +1 -1
- package/dist/lime-elements/{p-fdfecf3d.entry.js → p-6a26ea78.entry.js} +1 -1
- package/dist/lime-elements/{p-5f593160.entry.js → p-6b05db4a.entry.js} +1 -1
- package/dist/lime-elements/p-70e2e60c.entry.js +1 -0
- package/dist/lime-elements/{p-3ad102a1.entry.js → p-756f452c.entry.js} +1 -1
- package/dist/lime-elements/{p-fa6aea91.entry.js → p-8784a57c.entry.js} +1 -1
- package/dist/lime-elements/{p-6d28c7b4.entry.js → p-89dfbd4a.entry.js} +1 -1
- package/dist/lime-elements/{p-5280d11e.entry.js → p-8ec4fdee.entry.js} +1 -1
- package/dist/lime-elements/{p-1b0eec07.entry.js → p-90f8d2ef.entry.js} +1 -1
- package/dist/lime-elements/p-965288d2.entry.js +1 -0
- package/dist/lime-elements/{p-8b77d2a8.entry.js → p-9908b57a.entry.js} +1 -1
- package/dist/lime-elements/{p-2d7a2258.entry.js → p-9e3e4f2c.entry.js} +1 -1
- package/dist/lime-elements/p-DVRaJQvC.js +1 -0
- package/dist/lime-elements/{p-971f9c16.entry.js → p-a2295fa6.entry.js} +1 -1
- package/dist/lime-elements/{p-14bfd676.entry.js → p-a489f4b0.entry.js} +1 -1
- package/dist/lime-elements/{p-d5e954d4.entry.js → p-aeebf410.entry.js} +1 -1
- package/dist/lime-elements/{p-f4c9301d.entry.js → p-b11751c9.entry.js} +1 -1
- package/dist/lime-elements/{p-a1c1c40d.entry.js → p-b6ccc921.entry.js} +1 -1
- package/dist/lime-elements/{p-60f12574.entry.js → p-b95a42ea.entry.js} +1 -1
- package/dist/lime-elements/{p-8118cd4f.entry.js → p-bb38bb3c.entry.js} +1 -1
- package/dist/lime-elements/{p-d93f1c5f.entry.js → p-c3d565e2.entry.js} +1 -1
- package/dist/lime-elements/{p-a113dc9d.entry.js → p-c3ff8518.entry.js} +1 -1
- package/dist/lime-elements/{p-e00a96bd.entry.js → p-c6b9425b.entry.js} +1 -1
- package/dist/lime-elements/{p-373b7df7.entry.js → p-c6e9af7c.entry.js} +1 -1
- package/dist/lime-elements/{p-7997c118.entry.js → p-ce22f3da.entry.js} +1 -1
- package/dist/lime-elements/{p-8c6dfb19.entry.js → p-d5da5b05.entry.js} +1 -1
- package/dist/lime-elements/{p-b255e8e6.entry.js → p-da4429a8.entry.js} +1 -1
- package/dist/lime-elements/{p-6aa7cd43.entry.js → p-dcf3cc71.entry.js} +1 -1
- package/dist/lime-elements/{p-97f719ae.entry.js → p-de1e5ad9.entry.js} +1 -1
- package/dist/lime-elements/{p-13d0ec04.entry.js → p-eaac5ad2.entry.js} +1 -1
- package/dist/lime-elements/{p-ce178fbd.entry.js → p-ed8129db.entry.js} +1 -1
- package/dist/lime-elements/{p-b92431c8.entry.js → p-ee3afb60.entry.js} +3 -3
- package/dist/lime-elements/{p-8eff8a18.entry.js → p-ef75eed9.entry.js} +1 -1
- package/dist/lime-elements/{p-46b95d7c.entry.js → p-ef9bb368.entry.js} +1 -1
- package/dist/lime-elements/{p-912f53a3.entry.js → p-f70b8487.entry.js} +1 -1
- package/dist/lime-elements/{p-d53b8de5.entry.js → p-f9d5513d.entry.js} +1 -1
- package/dist/lime-elements/{p-bc4b4e46.entry.js → p-fb6c42a6.entry.js} +1 -1
- package/dist/types/components/code-diff/code-diff.d.ts +147 -0
- package/dist/types/components/code-diff/content-utils.d.ts +27 -0
- package/dist/types/components/code-diff/diff-engine.d.ts +36 -0
- package/dist/types/components/code-diff/search-utils.d.ts +30 -0
- package/dist/types/components/code-diff/syntax-highlighter.d.ts +19 -0
- package/dist/types/components/code-diff/types.d.ts +50 -0
- package/dist/types/components.d.ts +175 -0
- package/dist/types/translations/da.d.ts +29 -0
- package/dist/types/translations/de.d.ts +29 -0
- package/dist/types/translations/en.d.ts +29 -0
- package/dist/types/translations/fi.d.ts +29 -0
- package/dist/types/translations/fr.d.ts +29 -0
- package/dist/types/translations/nl.d.ts +29 -0
- package/dist/types/translations/no.d.ts +29 -0
- package/dist/types/translations/sv.d.ts +29 -0
- package/package.json +2 -1
- package/dist/cjs/limel-action-bar-item_2.cjs.entry.js +0 -137
- package/dist/esm/limel-action-bar-item_2.entry.js +0 -134
- package/dist/lime-elements/p-854a3ffe.entry.js +0 -1
- package/dist/lime-elements/p-8f2ac274.entry.js +0 -1
- package/dist/lime-elements/p-BHybIZJs.js +0 -1
- package/dist/lime-elements/p-accc6cc0.entry.js +0 -1
|
@@ -0,0 +1,775 @@
|
|
|
1
|
+
import { h, Host } from "@stencil/core";
|
|
2
|
+
import translate from "../../global/translations";
|
|
3
|
+
import { buildSplitLines, computeDiff, normalizeForDiff } from "./diff-engine";
|
|
4
|
+
import { tokenize } from "./syntax-highlighter";
|
|
5
|
+
import { buildSearchRegex, navigateMatchIndex } from "./search-utils";
|
|
6
|
+
import { extractRemovedContent, extractRemovedContentFromSplit, } from "./content-utils";
|
|
7
|
+
/**
|
|
8
|
+
* Displays a visual diff between two text values, modeled on
|
|
9
|
+
* GitHub's code difference view.
|
|
10
|
+
*
|
|
11
|
+
* Supports unified and split (side-by-side) views with line numbers,
|
|
12
|
+
* color-coded additions and removals, word-level inline highlighting,
|
|
13
|
+
* and collapsible unchanged context sections.
|
|
14
|
+
*
|
|
15
|
+
* @beta
|
|
16
|
+
* @exampleComponent limel-example-code-diff-basic
|
|
17
|
+
* @exampleComponent limel-example-code-diff-headings
|
|
18
|
+
* @exampleComponent limel-example-code-diff-json
|
|
19
|
+
* @exampleComponent limel-example-code-diff-split
|
|
20
|
+
* @exampleComponent limel-example-code-diff-line-wrap
|
|
21
|
+
* @exampleComponent limel-example-code-diff-expand
|
|
22
|
+
*/
|
|
23
|
+
export class CodeDiff {
|
|
24
|
+
constructor() {
|
|
25
|
+
/**
|
|
26
|
+
* The "before" value to compare.
|
|
27
|
+
* Can be a string or an object (which will be serialized to JSON).
|
|
28
|
+
*/
|
|
29
|
+
this.oldValue = '';
|
|
30
|
+
/**
|
|
31
|
+
* The "after" value to compare.
|
|
32
|
+
* Can be a string or an object (which will be serialized to JSON).
|
|
33
|
+
*/
|
|
34
|
+
this.newValue = '';
|
|
35
|
+
/**
|
|
36
|
+
* The layout of the diff view.
|
|
37
|
+
* - `unified` — single column with interleaved additions and removals
|
|
38
|
+
* - `split` — side-by-side comparison with old on left, new on right
|
|
39
|
+
*/
|
|
40
|
+
this.layout = 'unified';
|
|
41
|
+
/**
|
|
42
|
+
* Number of unchanged context lines to display around each change.
|
|
43
|
+
*/
|
|
44
|
+
this.contextLines = 3;
|
|
45
|
+
/**
|
|
46
|
+
* When `true`, long lines are wrapped instead of causing
|
|
47
|
+
* horizontal scrolling. Useful when comparing prose or
|
|
48
|
+
* config files with long values.
|
|
49
|
+
*/
|
|
50
|
+
this.lineWrapping = true;
|
|
51
|
+
/**
|
|
52
|
+
* When `true`, JSON values are parsed, keys are sorted,
|
|
53
|
+
* and indentation is normalized before diffing.
|
|
54
|
+
* This eliminates noise from formatting or key-order differences.
|
|
55
|
+
*/
|
|
56
|
+
this.reformatJson = false;
|
|
57
|
+
/**
|
|
58
|
+
* Defines the language for translations.
|
|
59
|
+
* Will translate all visible labels and announcements.
|
|
60
|
+
*/
|
|
61
|
+
this.translationLanguage = 'en';
|
|
62
|
+
this.diffResult = {
|
|
63
|
+
hunks: [],
|
|
64
|
+
additions: 0,
|
|
65
|
+
deletions: 0,
|
|
66
|
+
allLines: [],
|
|
67
|
+
};
|
|
68
|
+
this.liveAnnouncement = '';
|
|
69
|
+
this.copyState = 'idle';
|
|
70
|
+
this.searchVisible = false;
|
|
71
|
+
this.searchTerm = '';
|
|
72
|
+
this.currentMatchIndex = 0;
|
|
73
|
+
this.focusedRowIndex = -1;
|
|
74
|
+
this.normalizedOldText = '';
|
|
75
|
+
/**
|
|
76
|
+
* Render-time counter that increments for each search match
|
|
77
|
+
* found while rendering removed lines. Used to determine which
|
|
78
|
+
* match is the "current" one for navigation highlighting.
|
|
79
|
+
*/
|
|
80
|
+
this.searchMatchCounter = 0;
|
|
81
|
+
/**
|
|
82
|
+
* Total search matches found during the last render pass.
|
|
83
|
+
*/
|
|
84
|
+
this.totalSearchMatches = 0;
|
|
85
|
+
/**
|
|
86
|
+
* Whether the current render is inside a removed line,
|
|
87
|
+
* so search highlighting knows when to activate.
|
|
88
|
+
*/
|
|
89
|
+
this.isRenderingRemovedLine = false;
|
|
90
|
+
/**
|
|
91
|
+
* Cached search regex for the current render pass.
|
|
92
|
+
* Built once in render() and reused across all renderSearchableText calls.
|
|
93
|
+
*/
|
|
94
|
+
this.activeSearchRegex = null;
|
|
95
|
+
this.prevSearchVisible = false;
|
|
96
|
+
}
|
|
97
|
+
componentWillLoad() {
|
|
98
|
+
this.recomputeDiff();
|
|
99
|
+
}
|
|
100
|
+
componentDidRender() {
|
|
101
|
+
var _a, _b;
|
|
102
|
+
if (this.searchVisible && !this.prevSearchVisible) {
|
|
103
|
+
(_a = this.searchInputEl) === null || _a === void 0 ? void 0 : _a.focus();
|
|
104
|
+
}
|
|
105
|
+
this.prevSearchVisible = this.searchVisible;
|
|
106
|
+
if (this.searchTerm && this.totalSearchMatches > 0) {
|
|
107
|
+
const current = (_b = this.host.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('.search-match--current');
|
|
108
|
+
current === null || current === void 0 ? void 0 : current.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
render() {
|
|
112
|
+
this.searchMatchCounter = 0;
|
|
113
|
+
this.activeSearchRegex = buildSearchRegex(this.searchTerm);
|
|
114
|
+
const diffContent = this.renderDiff();
|
|
115
|
+
// Capture total matches after rendering completes
|
|
116
|
+
this.totalSearchMatches = this.searchMatchCounter;
|
|
117
|
+
const lineNumberWidth = this.computeLineNumberWidth();
|
|
118
|
+
return (h(Host, { key: '8122ede0d323b9021dae44cd5f65703d03083617', style: { '--limel-line-number-min-width': lineNumberWidth } }, this.renderHeader(), this.renderScreenReaderSummary(), this.searchVisible && this.renderSearchBar(), h("div", { key: 'fefe6e4898cbc82b6eb87f7dff7af71a14c7c91e', class: "diff-body", role: "table", "aria-label": this.getTranslation('code-diff.table-label'), tabindex: "0", onKeyDown: (event) => this.handleKeyDown(event) }, diffContent), h("div", { key: '2af1c7b29f2060a58af13d67fb174cb4de085efb', class: "screen-reader-only", role: "status", "aria-live": "polite", "aria-atomic": "true" }, this.liveAnnouncement)));
|
|
119
|
+
}
|
|
120
|
+
watchInputs() {
|
|
121
|
+
this.recomputeDiff();
|
|
122
|
+
}
|
|
123
|
+
recomputeDiff() {
|
|
124
|
+
const oldText = normalizeForDiff(this.oldValue, this.reformatJson);
|
|
125
|
+
const newText = normalizeForDiff(this.newValue, this.reformatJson);
|
|
126
|
+
this.normalizedOldText = oldText;
|
|
127
|
+
this.diffResult = computeDiff(oldText, newText, this.contextLines);
|
|
128
|
+
this.focusedRowIndex = -1;
|
|
129
|
+
}
|
|
130
|
+
formatSrSummary() {
|
|
131
|
+
const { additions, deletions } = this.diffResult;
|
|
132
|
+
if (additions === 0 && deletions === 0) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
const parts = [];
|
|
136
|
+
if (additions > 0) {
|
|
137
|
+
const key = additions === 1
|
|
138
|
+
? 'code-diff.diff-addition'
|
|
139
|
+
: 'code-diff.diff-additions';
|
|
140
|
+
parts.push(this.getTranslation(key, { count: additions }));
|
|
141
|
+
}
|
|
142
|
+
if (deletions > 0) {
|
|
143
|
+
const key = deletions === 1
|
|
144
|
+
? 'code-diff.diff-deletion'
|
|
145
|
+
: 'code-diff.diff-deletions';
|
|
146
|
+
parts.push(this.getTranslation(key, { count: deletions }));
|
|
147
|
+
}
|
|
148
|
+
return this.getTranslation('code-diff.diff-summary', {
|
|
149
|
+
parts: parts.join(', '),
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
renderScreenReaderSummary() {
|
|
153
|
+
const summary = this.formatSrSummary();
|
|
154
|
+
return (h("div", { class: "screen-reader-only", role: "status", "aria-live": "polite" }, summary !== null && summary !== void 0 ? summary : this.getTranslation('code-diff.no-differences-found')));
|
|
155
|
+
}
|
|
156
|
+
handleKeyDown(event) {
|
|
157
|
+
if (event.key !== 'ArrowUp' && event.key !== 'ArrowDown') {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
event.preventDefault();
|
|
161
|
+
const rows = this.getDiffRows();
|
|
162
|
+
if (rows.length === 0) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (event.key === 'ArrowDown') {
|
|
166
|
+
this.focusedRowIndex = Math.min(this.focusedRowIndex + 1, rows.length - 1);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
this.focusedRowIndex = Math.max(this.focusedRowIndex - 1, 0);
|
|
170
|
+
}
|
|
171
|
+
this.updateRowFocus(rows);
|
|
172
|
+
}
|
|
173
|
+
getDiffRows() {
|
|
174
|
+
var _a;
|
|
175
|
+
const body = (_a = this.host.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('.diff-body');
|
|
176
|
+
if (!body) {
|
|
177
|
+
return [];
|
|
178
|
+
}
|
|
179
|
+
return [
|
|
180
|
+
...body.querySelectorAll('.diff-line:not(.diff-line--collapsed)'),
|
|
181
|
+
];
|
|
182
|
+
}
|
|
183
|
+
updateRowFocus(rows) {
|
|
184
|
+
for (const row of rows) {
|
|
185
|
+
row.removeAttribute('tabindex');
|
|
186
|
+
row.classList.remove('diff-line--focused');
|
|
187
|
+
}
|
|
188
|
+
const target = rows[this.focusedRowIndex];
|
|
189
|
+
if (target) {
|
|
190
|
+
target.setAttribute('tabindex', '-1');
|
|
191
|
+
target.classList.add('diff-line--focused');
|
|
192
|
+
target.focus();
|
|
193
|
+
this.announceLine(target);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
announceLine(row) {
|
|
197
|
+
var _a, _b;
|
|
198
|
+
let lineType = this.getTranslation('code-diff.line-context');
|
|
199
|
+
if (row.classList.contains('diff-line--added')) {
|
|
200
|
+
lineType = this.getTranslation('code-diff.line-added');
|
|
201
|
+
}
|
|
202
|
+
else if (row.classList.contains('diff-line--removed')) {
|
|
203
|
+
lineType = this.getTranslation('code-diff.line-removed');
|
|
204
|
+
}
|
|
205
|
+
const content = (_b = (_a = row.querySelector('.line-content, .split-content')) === null || _a === void 0 ? void 0 : _a.textContent) !== null && _b !== void 0 ? _b : '';
|
|
206
|
+
const trimmed = content.length > 80 ? content.slice(0, 80) + '…' : content;
|
|
207
|
+
this.liveAnnouncement = `${lineType}: ${trimmed}`;
|
|
208
|
+
}
|
|
209
|
+
renderHeader() {
|
|
210
|
+
var _a, _b;
|
|
211
|
+
const oldHeading = (_a = this.oldHeading) !== null && _a !== void 0 ? _a : this.getTranslation('code-diff.old-heading');
|
|
212
|
+
const newHeading = (_b = this.newHeading) !== null && _b !== void 0 ? _b : this.getTranslation('code-diff.new-heading');
|
|
213
|
+
const { additions, deletions } = this.diffResult;
|
|
214
|
+
const hasDiff = additions > 0 || deletions > 0;
|
|
215
|
+
return (h("div", { class: "diff-header" }, h("div", { class: "diff-header__labels" }, h("span", { class: "diff-header__old" }, oldHeading), h("span", { class: "diff-header__new" }, newHeading)), h("div", { class: "diff-header__actions" }, h("div", { class: "diff-header__stats" }, additions > 0 && (h("span", { class: "stat stat--added" }, "+", additions)), deletions > 0 && (h("span", { class: "stat stat--removed" }, "-", deletions))), hasDiff && this.renderCopyButton(), deletions > 0 && this.renderSearchToggle())));
|
|
216
|
+
}
|
|
217
|
+
renderCopyButton() {
|
|
218
|
+
const label = this.copyState === 'copied'
|
|
219
|
+
? this.getTranslation('code-diff.copied')
|
|
220
|
+
: this.getTranslation('code-diff.copy-old-version');
|
|
221
|
+
const icon = this.copyState === 'copied' ? 'checkmark' : 'copy';
|
|
222
|
+
return (h("limel-icon-button", { label: label, icon: icon, onClick: () => this.copyToClipboard(this.normalizedOldText) }));
|
|
223
|
+
}
|
|
224
|
+
async copyToClipboard(text) {
|
|
225
|
+
try {
|
|
226
|
+
await navigator.clipboard.writeText(text);
|
|
227
|
+
this.copyState = 'copied';
|
|
228
|
+
this.liveAnnouncement = this.getTranslation('code-diff.copied-to-clipboard');
|
|
229
|
+
setTimeout(() => {
|
|
230
|
+
this.copyState = 'idle';
|
|
231
|
+
}, 2000);
|
|
232
|
+
}
|
|
233
|
+
catch (_a) {
|
|
234
|
+
// Clipboard API may fail in insecure contexts
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
renderSearchToggle() {
|
|
238
|
+
return (h("limel-icon-button", { class: { 'search-toggle--active': this.searchVisible }, label: this.getTranslation('code-diff.search'), icon: "search", onClick: () => this.toggleSearch() }));
|
|
239
|
+
}
|
|
240
|
+
renderSearchBar() {
|
|
241
|
+
const matchInfo = this.totalSearchMatches === 0
|
|
242
|
+
? this.getTranslation('code-diff.no-matches')
|
|
243
|
+
: this.getTranslation('code-diff.match-count', {
|
|
244
|
+
current: this.currentMatchIndex + 1,
|
|
245
|
+
total: this.totalSearchMatches,
|
|
246
|
+
});
|
|
247
|
+
return (h("div", { class: "search-bar" }, h("limel-input-field", { class: "search-bar__input", type: "search", placeholder: this.getTranslation('code-diff.search') + '…', value: this.searchTerm, onChange: (e) => this.onSearchInput(e), onKeyDown: (e) => this.onSearchKeyDown(e), ref: (el) => (this.searchInputEl = el) }), h("span", { class: "search-bar__count" }, matchInfo), h("limel-action-bar", { actions: this.getSearchActions(), onItemSelected: (e) => this.onSearchAction(e) })));
|
|
248
|
+
}
|
|
249
|
+
toggleSearch() {
|
|
250
|
+
this.searchVisible = !this.searchVisible;
|
|
251
|
+
if (!this.searchVisible) {
|
|
252
|
+
this.searchTerm = '';
|
|
253
|
+
this.currentMatchIndex = 0;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
onSearchInput(event) {
|
|
257
|
+
this.searchTerm = event.detail;
|
|
258
|
+
this.currentMatchIndex = 0;
|
|
259
|
+
}
|
|
260
|
+
onSearchKeyDown(event) {
|
|
261
|
+
if (event.key === 'Enter') {
|
|
262
|
+
event.preventDefault();
|
|
263
|
+
if (event.shiftKey) {
|
|
264
|
+
this.navigateSearch(-1);
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
this.navigateSearch(1);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
else if (event.key === 'Escape') {
|
|
271
|
+
this.toggleSearch();
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
computeLineNumberWidth() {
|
|
275
|
+
const maxLineNumber = this.diffResult.allLines.length;
|
|
276
|
+
const digits = String(maxLineNumber).length;
|
|
277
|
+
return `calc(${digits}ch + 2 * var(--limel-code-diff-line-number-padding))`;
|
|
278
|
+
}
|
|
279
|
+
getSearchActions() {
|
|
280
|
+
const noMatches = this.totalSearchMatches === 0;
|
|
281
|
+
return [
|
|
282
|
+
{
|
|
283
|
+
text: this.getTranslation('code-diff.previous-match'),
|
|
284
|
+
icon: '-lime-caret-top',
|
|
285
|
+
iconOnly: true,
|
|
286
|
+
disabled: noMatches,
|
|
287
|
+
value: 'prev',
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
text: this.getTranslation('code-diff.next-match'),
|
|
291
|
+
icon: '-lime-caret-bottom',
|
|
292
|
+
iconOnly: true,
|
|
293
|
+
disabled: noMatches,
|
|
294
|
+
value: 'next',
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
text: this.getTranslation('code-diff.close-search'),
|
|
298
|
+
icon: 'cancel',
|
|
299
|
+
iconOnly: true,
|
|
300
|
+
value: 'close',
|
|
301
|
+
},
|
|
302
|
+
];
|
|
303
|
+
}
|
|
304
|
+
onSearchAction(event) {
|
|
305
|
+
const { value } = event.detail;
|
|
306
|
+
if (value === 'prev') {
|
|
307
|
+
this.navigateSearch(-1);
|
|
308
|
+
}
|
|
309
|
+
else if (value === 'next') {
|
|
310
|
+
this.navigateSearch(1);
|
|
311
|
+
}
|
|
312
|
+
else if (value === 'close') {
|
|
313
|
+
this.toggleSearch();
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
navigateSearch(direction) {
|
|
317
|
+
this.currentMatchIndex = navigateMatchIndex(this.currentMatchIndex, direction, this.totalSearchMatches);
|
|
318
|
+
}
|
|
319
|
+
renderDiff() {
|
|
320
|
+
const { hunks, collapsedAfter } = this.diffResult;
|
|
321
|
+
if (hunks.length === 0) {
|
|
322
|
+
return (h("div", { class: "diff-empty" }, this.getTranslation('code-diff.no-differences')));
|
|
323
|
+
}
|
|
324
|
+
const lineRenderer = this.layout === 'split'
|
|
325
|
+
? (hunk) => this.renderSplitHunkRows(hunk)
|
|
326
|
+
: (hunk) => this.renderHunkLines(hunk);
|
|
327
|
+
return this.renderHunks(hunks, collapsedAfter, lineRenderer);
|
|
328
|
+
}
|
|
329
|
+
renderHunks(hunks, collapsedAfter, lineRenderer) {
|
|
330
|
+
const elements = [];
|
|
331
|
+
for (const [i, hunk] of hunks.entries()) {
|
|
332
|
+
if (hunk.collapsedBefore) {
|
|
333
|
+
elements.push(this.renderCollapsedRow(hunk.collapsedBefore, i));
|
|
334
|
+
}
|
|
335
|
+
elements.push(...lineRenderer(hunk));
|
|
336
|
+
}
|
|
337
|
+
if (collapsedAfter) {
|
|
338
|
+
elements.push(this.renderCollapsedAfterRow(collapsedAfter));
|
|
339
|
+
}
|
|
340
|
+
return elements;
|
|
341
|
+
}
|
|
342
|
+
renderHunkLines(hunk) {
|
|
343
|
+
const elements = [];
|
|
344
|
+
let i = 0;
|
|
345
|
+
while (i < hunk.lines.length) {
|
|
346
|
+
const line = hunk.lines[i];
|
|
347
|
+
if (line.type === 'context') {
|
|
348
|
+
elements.push(this.renderLine(line));
|
|
349
|
+
i++;
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
// Collect consecutive changed lines as a change block
|
|
353
|
+
const blockLines = [];
|
|
354
|
+
while (i < hunk.lines.length && hunk.lines[i].type !== 'context') {
|
|
355
|
+
blockLines.push(hunk.lines[i]);
|
|
356
|
+
i++;
|
|
357
|
+
}
|
|
358
|
+
elements.push(this.renderChangeBlock(blockLines));
|
|
359
|
+
}
|
|
360
|
+
return elements;
|
|
361
|
+
}
|
|
362
|
+
renderChangeBlock(lines) {
|
|
363
|
+
const removedContent = extractRemovedContent(lines);
|
|
364
|
+
return (h("div", { class: "change-group" }, lines.map((line) => this.renderLine(line)), removedContent && this.renderBlockCopyButton(removedContent)));
|
|
365
|
+
}
|
|
366
|
+
renderLine(line) {
|
|
367
|
+
var _a, _b;
|
|
368
|
+
const lineClass = {
|
|
369
|
+
'diff-line': true,
|
|
370
|
+
[`diff-line--${line.type}`]: true,
|
|
371
|
+
};
|
|
372
|
+
const indicatorMap = {
|
|
373
|
+
added: '+',
|
|
374
|
+
removed: '-',
|
|
375
|
+
context: ' ',
|
|
376
|
+
};
|
|
377
|
+
const indicator = indicatorMap[line.type];
|
|
378
|
+
return (h("div", { class: lineClass, role: "row" }, h("span", { class: "line-number line-number--old", role: "cell", "aria-label": line.oldLineNumber
|
|
379
|
+
? this.getTranslation('code-diff.old-line', {
|
|
380
|
+
number: line.oldLineNumber,
|
|
381
|
+
})
|
|
382
|
+
: undefined }, (_a = line.oldLineNumber) !== null && _a !== void 0 ? _a : ''), h("span", { class: "line-number line-number--new", role: "cell", "aria-label": line.newLineNumber
|
|
383
|
+
? this.getTranslation('code-diff.new-line', {
|
|
384
|
+
number: line.newLineNumber,
|
|
385
|
+
})
|
|
386
|
+
: undefined }, (_b = line.newLineNumber) !== null && _b !== void 0 ? _b : ''), h("span", { class: "line-indicator", role: "cell" }, indicator), h("span", { class: "line-content", role: "cell" }, this.renderContent(line))));
|
|
387
|
+
}
|
|
388
|
+
renderSplitHunkRows(hunk) {
|
|
389
|
+
var _a, _b, _c, _d;
|
|
390
|
+
const splitRows = buildSplitLines(hunk.lines);
|
|
391
|
+
const elements = [];
|
|
392
|
+
let i = 0;
|
|
393
|
+
while (i < splitRows.length) {
|
|
394
|
+
const row = splitRows[i];
|
|
395
|
+
const isContext = ((_a = row.left) === null || _a === void 0 ? void 0 : _a.type) === 'context' && ((_b = row.right) === null || _b === void 0 ? void 0 : _b.type) === 'context';
|
|
396
|
+
if (isContext) {
|
|
397
|
+
elements.push(this.renderSplitRow(row));
|
|
398
|
+
i++;
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
// Collect consecutive changed rows
|
|
402
|
+
const blockRows = [];
|
|
403
|
+
while (i < splitRows.length) {
|
|
404
|
+
const r = splitRows[i];
|
|
405
|
+
const rIsContext = ((_c = r.left) === null || _c === void 0 ? void 0 : _c.type) === 'context' && ((_d = r.right) === null || _d === void 0 ? void 0 : _d.type) === 'context';
|
|
406
|
+
if (rIsContext) {
|
|
407
|
+
break;
|
|
408
|
+
}
|
|
409
|
+
blockRows.push(r);
|
|
410
|
+
i++;
|
|
411
|
+
}
|
|
412
|
+
elements.push(this.renderSplitChangeBlock(blockRows));
|
|
413
|
+
}
|
|
414
|
+
return elements;
|
|
415
|
+
}
|
|
416
|
+
renderSplitChangeBlock(rows) {
|
|
417
|
+
const removedContent = extractRemovedContentFromSplit(rows);
|
|
418
|
+
return (h("div", { class: "change-group" }, rows.map((row) => this.renderSplitRow(row)), removedContent && this.renderBlockCopyButton(removedContent)));
|
|
419
|
+
}
|
|
420
|
+
renderSplitRow(row) {
|
|
421
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
422
|
+
const leftType = (_b = (_a = row.left) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : 'empty';
|
|
423
|
+
const rightType = (_d = (_c = row.right) === null || _c === void 0 ? void 0 : _c.type) !== null && _d !== void 0 ? _d : 'empty';
|
|
424
|
+
const oldLineLabel = ((_e = row.left) === null || _e === void 0 ? void 0 : _e.oldLineNumber)
|
|
425
|
+
? this.getTranslation('code-diff.old-line', {
|
|
426
|
+
number: row.left.oldLineNumber,
|
|
427
|
+
})
|
|
428
|
+
: undefined;
|
|
429
|
+
const newLineLabel = ((_f = row.right) === null || _f === void 0 ? void 0 : _f.newLineNumber)
|
|
430
|
+
? this.getTranslation('code-diff.new-line', {
|
|
431
|
+
number: row.right.newLineNumber,
|
|
432
|
+
})
|
|
433
|
+
: undefined;
|
|
434
|
+
return (h("div", { class: "diff-line diff-line--split", role: "row" }, h("span", { class: "line-number line-number--old", role: "cell", "aria-label": oldLineLabel }, (_h = (_g = row.left) === null || _g === void 0 ? void 0 : _g.oldLineNumber) !== null && _h !== void 0 ? _h : ''), h("span", { class: `split-content split-content--left split-content--${leftType}`, role: "cell" }, row.left ? this.renderContent(row.left) : ''), h("span", { class: "line-number line-number--new", role: "cell", "aria-label": newLineLabel }, (_k = (_j = row.right) === null || _j === void 0 ? void 0 : _j.newLineNumber) !== null && _k !== void 0 ? _k : ''), h("span", { class: `split-content split-content--right split-content--${rightType}`, role: "cell" }, row.right ? this.renderContent(row.right) : '')));
|
|
435
|
+
}
|
|
436
|
+
renderBlockCopyButton(removedContent) {
|
|
437
|
+
return (h("limel-icon-button", { class: "change-group__copy", elevated: true, label: this.getTranslation('code-diff.copy-change'), icon: "copy", onClick: () => this.copyToClipboard(removedContent) }));
|
|
438
|
+
}
|
|
439
|
+
renderContent(line) {
|
|
440
|
+
this.isRenderingRemovedLine =
|
|
441
|
+
line.type === 'removed' && this.searchTerm.length > 0;
|
|
442
|
+
if (!line.segments || line.segments.length === 0) {
|
|
443
|
+
return this.renderSyntaxTokens(line.content);
|
|
444
|
+
}
|
|
445
|
+
return line.segments.map((segment) => this.renderSegment(segment, line.type));
|
|
446
|
+
}
|
|
447
|
+
renderSegment(segment, lineType) {
|
|
448
|
+
const content = this.renderSyntaxTokens(segment.value);
|
|
449
|
+
if (segment.type === 'equal') {
|
|
450
|
+
return content;
|
|
451
|
+
}
|
|
452
|
+
const segmentClass = lineType === 'removed' ? 'segment--removed' : 'segment--added';
|
|
453
|
+
return h("mark", { class: segmentClass }, content);
|
|
454
|
+
}
|
|
455
|
+
renderSyntaxTokens(text) {
|
|
456
|
+
const tokens = tokenize(text, this.language);
|
|
457
|
+
if (tokens.length === 1 && tokens[0].type === 'plain') {
|
|
458
|
+
return this.renderSearchableText(text);
|
|
459
|
+
}
|
|
460
|
+
return tokens.map((token) => this.renderSyntaxToken(token));
|
|
461
|
+
}
|
|
462
|
+
renderSyntaxToken(token) {
|
|
463
|
+
const text = this.renderSearchableText(token.value);
|
|
464
|
+
if (token.type === 'plain') {
|
|
465
|
+
return text;
|
|
466
|
+
}
|
|
467
|
+
return h("span", { class: `syntax--${token.type}` }, text);
|
|
468
|
+
}
|
|
469
|
+
renderSearchableText(text) {
|
|
470
|
+
if (!this.isRenderingRemovedLine || !this.activeSearchRegex) {
|
|
471
|
+
return text;
|
|
472
|
+
}
|
|
473
|
+
const parts = text.split(this.activeSearchRegex);
|
|
474
|
+
if (parts.length === 1) {
|
|
475
|
+
return text;
|
|
476
|
+
}
|
|
477
|
+
return parts.map((part, i) => {
|
|
478
|
+
// Odd indices are the captured matches from split
|
|
479
|
+
if (i % 2 === 0) {
|
|
480
|
+
return part;
|
|
481
|
+
}
|
|
482
|
+
const matchIndex = this.searchMatchCounter++;
|
|
483
|
+
const isCurrent = matchIndex === this.currentMatchIndex;
|
|
484
|
+
const cls = {
|
|
485
|
+
'search-match': true,
|
|
486
|
+
'search-match--current': isCurrent,
|
|
487
|
+
};
|
|
488
|
+
return (h("mark", { key: `match-${matchIndex}`, class: cls }, part));
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
renderCollapsedRow(count, hunkIndex) {
|
|
492
|
+
return (h("div", { class: "diff-line diff-line--collapsed", role: "row" }, h("button", { class: "expand-button", type: "button", onClick: () => this.expandHunk(hunkIndex), "aria-label": this.getTranslation('code-diff.show-hidden-lines', {
|
|
493
|
+
count,
|
|
494
|
+
}) }, this.getTranslation('code-diff.hidden-lines', { count }))));
|
|
495
|
+
}
|
|
496
|
+
renderCollapsedAfterRow(count) {
|
|
497
|
+
return (h("div", { class: "diff-line diff-line--collapsed", role: "row" }, h("button", { class: "expand-button", type: "button", onClick: () => this.expandAfter(), "aria-label": this.getTranslation('code-diff.show-hidden-lines', {
|
|
498
|
+
count,
|
|
499
|
+
}) }, this.getTranslation('code-diff.hidden-lines', { count }))));
|
|
500
|
+
}
|
|
501
|
+
expandHunk(hunkIndex) {
|
|
502
|
+
const hunks = [...this.diffResult.hunks];
|
|
503
|
+
const hunk = hunks[hunkIndex];
|
|
504
|
+
const prevHunkEnd = hunkIndex > 0
|
|
505
|
+
? hunks[hunkIndex - 1].startIndex +
|
|
506
|
+
hunks[hunkIndex - 1].lines.length
|
|
507
|
+
: 0;
|
|
508
|
+
const hiddenLines = this.diffResult.allLines.slice(prevHunkEnd, hunk.startIndex);
|
|
509
|
+
hunks[hunkIndex] = Object.assign(Object.assign({}, hunk), { lines: [...hiddenLines, ...hunk.lines], collapsedBefore: undefined, startIndex: prevHunkEnd });
|
|
510
|
+
this.diffResult = Object.assign(Object.assign({}, this.diffResult), { hunks });
|
|
511
|
+
this.liveAnnouncement = this.getTranslation('code-diff.expanded-lines');
|
|
512
|
+
}
|
|
513
|
+
expandAfter() {
|
|
514
|
+
const hunks = [...this.diffResult.hunks];
|
|
515
|
+
const lastIndex = hunks.length - 1;
|
|
516
|
+
const lastHunk = hunks[lastIndex];
|
|
517
|
+
const lastHunkEnd = lastHunk.startIndex + lastHunk.lines.length;
|
|
518
|
+
const hiddenLines = this.diffResult.allLines.slice(lastHunkEnd);
|
|
519
|
+
hunks[lastIndex] = Object.assign(Object.assign({}, lastHunk), { lines: [...lastHunk.lines, ...hiddenLines] });
|
|
520
|
+
this.diffResult = Object.assign(Object.assign({}, this.diffResult), { hunks, collapsedAfter: undefined });
|
|
521
|
+
this.liveAnnouncement = this.getTranslation('code-diff.expanded-lines-end');
|
|
522
|
+
}
|
|
523
|
+
getTranslation(key, params) {
|
|
524
|
+
return translate.get(key, this.translationLanguage, params);
|
|
525
|
+
}
|
|
526
|
+
static get is() { return "limel-code-diff"; }
|
|
527
|
+
static get encapsulation() { return "shadow"; }
|
|
528
|
+
static get originalStyleUrls() {
|
|
529
|
+
return {
|
|
530
|
+
"$": ["code-diff.scss"]
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
static get styleUrls() {
|
|
534
|
+
return {
|
|
535
|
+
"$": ["code-diff.css"]
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
static get properties() {
|
|
539
|
+
return {
|
|
540
|
+
"oldValue": {
|
|
541
|
+
"type": "string",
|
|
542
|
+
"mutable": false,
|
|
543
|
+
"complexType": {
|
|
544
|
+
"original": "string | object",
|
|
545
|
+
"resolved": "object | string",
|
|
546
|
+
"references": {}
|
|
547
|
+
},
|
|
548
|
+
"required": false,
|
|
549
|
+
"optional": false,
|
|
550
|
+
"docs": {
|
|
551
|
+
"tags": [],
|
|
552
|
+
"text": "The \"before\" value to compare.\nCan be a string or an object (which will be serialized to JSON)."
|
|
553
|
+
},
|
|
554
|
+
"getter": false,
|
|
555
|
+
"setter": false,
|
|
556
|
+
"reflect": false,
|
|
557
|
+
"attribute": "old-value",
|
|
558
|
+
"defaultValue": "''"
|
|
559
|
+
},
|
|
560
|
+
"newValue": {
|
|
561
|
+
"type": "string",
|
|
562
|
+
"mutable": false,
|
|
563
|
+
"complexType": {
|
|
564
|
+
"original": "string | object",
|
|
565
|
+
"resolved": "object | string",
|
|
566
|
+
"references": {}
|
|
567
|
+
},
|
|
568
|
+
"required": false,
|
|
569
|
+
"optional": false,
|
|
570
|
+
"docs": {
|
|
571
|
+
"tags": [],
|
|
572
|
+
"text": "The \"after\" value to compare.\nCan be a string or an object (which will be serialized to JSON)."
|
|
573
|
+
},
|
|
574
|
+
"getter": false,
|
|
575
|
+
"setter": false,
|
|
576
|
+
"reflect": false,
|
|
577
|
+
"attribute": "new-value",
|
|
578
|
+
"defaultValue": "''"
|
|
579
|
+
},
|
|
580
|
+
"oldHeading": {
|
|
581
|
+
"type": "string",
|
|
582
|
+
"mutable": false,
|
|
583
|
+
"complexType": {
|
|
584
|
+
"original": "string",
|
|
585
|
+
"resolved": "string",
|
|
586
|
+
"references": {}
|
|
587
|
+
},
|
|
588
|
+
"required": false,
|
|
589
|
+
"optional": true,
|
|
590
|
+
"docs": {
|
|
591
|
+
"tags": [],
|
|
592
|
+
"text": "Heading for the original (before) version, displayed in the diff header.\nDefaults to `\"Original\"`, localized via `translationLanguage`."
|
|
593
|
+
},
|
|
594
|
+
"getter": false,
|
|
595
|
+
"setter": false,
|
|
596
|
+
"reflect": true,
|
|
597
|
+
"attribute": "old-heading"
|
|
598
|
+
},
|
|
599
|
+
"newHeading": {
|
|
600
|
+
"type": "string",
|
|
601
|
+
"mutable": false,
|
|
602
|
+
"complexType": {
|
|
603
|
+
"original": "string",
|
|
604
|
+
"resolved": "string",
|
|
605
|
+
"references": {}
|
|
606
|
+
},
|
|
607
|
+
"required": false,
|
|
608
|
+
"optional": true,
|
|
609
|
+
"docs": {
|
|
610
|
+
"tags": [],
|
|
611
|
+
"text": "Heading for the modified (after) version, displayed in the diff header.\nDefaults to `\"Modified\"`, localized via `translationLanguage`."
|
|
612
|
+
},
|
|
613
|
+
"getter": false,
|
|
614
|
+
"setter": false,
|
|
615
|
+
"reflect": true,
|
|
616
|
+
"attribute": "new-heading"
|
|
617
|
+
},
|
|
618
|
+
"layout": {
|
|
619
|
+
"type": "string",
|
|
620
|
+
"mutable": false,
|
|
621
|
+
"complexType": {
|
|
622
|
+
"original": "'unified' | 'split'",
|
|
623
|
+
"resolved": "\"split\" | \"unified\"",
|
|
624
|
+
"references": {}
|
|
625
|
+
},
|
|
626
|
+
"required": false,
|
|
627
|
+
"optional": false,
|
|
628
|
+
"docs": {
|
|
629
|
+
"tags": [],
|
|
630
|
+
"text": "The layout of the diff view.\n- `unified` \u2014 single column with interleaved additions and removals\n- `split` \u2014 side-by-side comparison with old on left, new on right"
|
|
631
|
+
},
|
|
632
|
+
"getter": false,
|
|
633
|
+
"setter": false,
|
|
634
|
+
"reflect": true,
|
|
635
|
+
"attribute": "layout",
|
|
636
|
+
"defaultValue": "'unified'"
|
|
637
|
+
},
|
|
638
|
+
"contextLines": {
|
|
639
|
+
"type": "number",
|
|
640
|
+
"mutable": false,
|
|
641
|
+
"complexType": {
|
|
642
|
+
"original": "number",
|
|
643
|
+
"resolved": "number",
|
|
644
|
+
"references": {}
|
|
645
|
+
},
|
|
646
|
+
"required": false,
|
|
647
|
+
"optional": false,
|
|
648
|
+
"docs": {
|
|
649
|
+
"tags": [],
|
|
650
|
+
"text": "Number of unchanged context lines to display around each change."
|
|
651
|
+
},
|
|
652
|
+
"getter": false,
|
|
653
|
+
"setter": false,
|
|
654
|
+
"reflect": true,
|
|
655
|
+
"attribute": "context-lines",
|
|
656
|
+
"defaultValue": "3"
|
|
657
|
+
},
|
|
658
|
+
"lineWrapping": {
|
|
659
|
+
"type": "boolean",
|
|
660
|
+
"mutable": false,
|
|
661
|
+
"complexType": {
|
|
662
|
+
"original": "boolean",
|
|
663
|
+
"resolved": "boolean",
|
|
664
|
+
"references": {}
|
|
665
|
+
},
|
|
666
|
+
"required": false,
|
|
667
|
+
"optional": false,
|
|
668
|
+
"docs": {
|
|
669
|
+
"tags": [],
|
|
670
|
+
"text": "When `true`, long lines are wrapped instead of causing\nhorizontal scrolling. Useful when comparing prose or\nconfig files with long values."
|
|
671
|
+
},
|
|
672
|
+
"getter": false,
|
|
673
|
+
"setter": false,
|
|
674
|
+
"reflect": true,
|
|
675
|
+
"attribute": "line-wrapping",
|
|
676
|
+
"defaultValue": "true"
|
|
677
|
+
},
|
|
678
|
+
"language": {
|
|
679
|
+
"type": "string",
|
|
680
|
+
"mutable": false,
|
|
681
|
+
"complexType": {
|
|
682
|
+
"original": "string",
|
|
683
|
+
"resolved": "string",
|
|
684
|
+
"references": {}
|
|
685
|
+
},
|
|
686
|
+
"required": false,
|
|
687
|
+
"optional": true,
|
|
688
|
+
"docs": {
|
|
689
|
+
"tags": [],
|
|
690
|
+
"text": "Language for syntax highlighting.\nCurrently supports `\"json\"`. When set, code tokens are\ncolorized (strings, numbers, keys, etc.) alongside the\ndiff highlighting."
|
|
691
|
+
},
|
|
692
|
+
"getter": false,
|
|
693
|
+
"setter": false,
|
|
694
|
+
"reflect": true,
|
|
695
|
+
"attribute": "language"
|
|
696
|
+
},
|
|
697
|
+
"reformatJson": {
|
|
698
|
+
"type": "boolean",
|
|
699
|
+
"mutable": false,
|
|
700
|
+
"complexType": {
|
|
701
|
+
"original": "boolean",
|
|
702
|
+
"resolved": "boolean",
|
|
703
|
+
"references": {}
|
|
704
|
+
},
|
|
705
|
+
"required": false,
|
|
706
|
+
"optional": false,
|
|
707
|
+
"docs": {
|
|
708
|
+
"tags": [],
|
|
709
|
+
"text": "When `true`, JSON values are parsed, keys are sorted,\nand indentation is normalized before diffing.\nThis eliminates noise from formatting or key-order differences."
|
|
710
|
+
},
|
|
711
|
+
"getter": false,
|
|
712
|
+
"setter": false,
|
|
713
|
+
"reflect": true,
|
|
714
|
+
"attribute": "reformat-json",
|
|
715
|
+
"defaultValue": "false"
|
|
716
|
+
},
|
|
717
|
+
"translationLanguage": {
|
|
718
|
+
"type": "string",
|
|
719
|
+
"mutable": false,
|
|
720
|
+
"complexType": {
|
|
721
|
+
"original": "Languages",
|
|
722
|
+
"resolved": "\"da\" | \"de\" | \"en\" | \"fi\" | \"fr\" | \"nb\" | \"nl\" | \"no\" | \"sv\"",
|
|
723
|
+
"references": {
|
|
724
|
+
"Languages": {
|
|
725
|
+
"location": "import",
|
|
726
|
+
"path": "../date-picker/date.types",
|
|
727
|
+
"id": "src/components/date-picker/date.types.ts::Languages",
|
|
728
|
+
"referenceLocation": "Languages"
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
},
|
|
732
|
+
"required": false,
|
|
733
|
+
"optional": false,
|
|
734
|
+
"docs": {
|
|
735
|
+
"tags": [],
|
|
736
|
+
"text": "Defines the language for translations.\nWill translate all visible labels and announcements."
|
|
737
|
+
},
|
|
738
|
+
"getter": false,
|
|
739
|
+
"setter": false,
|
|
740
|
+
"reflect": true,
|
|
741
|
+
"attribute": "translation-language",
|
|
742
|
+
"defaultValue": "'en'"
|
|
743
|
+
}
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
static get states() {
|
|
747
|
+
return {
|
|
748
|
+
"diffResult": {},
|
|
749
|
+
"liveAnnouncement": {},
|
|
750
|
+
"copyState": {},
|
|
751
|
+
"searchVisible": {},
|
|
752
|
+
"searchTerm": {},
|
|
753
|
+
"currentMatchIndex": {}
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
static get elementRef() { return "host"; }
|
|
757
|
+
static get watchers() {
|
|
758
|
+
return [{
|
|
759
|
+
"propName": "oldValue",
|
|
760
|
+
"methodName": "watchInputs"
|
|
761
|
+
}, {
|
|
762
|
+
"propName": "newValue",
|
|
763
|
+
"methodName": "watchInputs"
|
|
764
|
+
}, {
|
|
765
|
+
"propName": "contextLines",
|
|
766
|
+
"methodName": "watchInputs"
|
|
767
|
+
}, {
|
|
768
|
+
"propName": "reformatJson",
|
|
769
|
+
"methodName": "watchInputs"
|
|
770
|
+
}, {
|
|
771
|
+
"propName": "layout",
|
|
772
|
+
"methodName": "watchInputs"
|
|
773
|
+
}];
|
|
774
|
+
}
|
|
775
|
+
}
|