@nldd/design-system 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/custom-elements.json +3084 -784
- package/dist/components/actions/button/button.d.ts +10 -0
- package/dist/components/actions/button/button.d.ts.map +1 -1
- package/dist/components/actions/button/button.js +23 -0
- package/dist/components/actions/button/button.js.map +1 -1
- package/dist/components/actions/button/button.styles.d.ts.map +1 -1
- package/dist/components/actions/button/button.styles.js +22 -0
- package/dist/components/actions/button/button.styles.js.map +1 -1
- package/dist/components/actions/button/button.template.d.ts +1 -0
- package/dist/components/actions/button/button.template.d.ts.map +1 -1
- package/dist/components/actions/button/button.template.js +20 -2
- package/dist/components/actions/button/button.template.js.map +1 -1
- package/dist/components/actions/icon-button/icon-button.d.ts +10 -0
- package/dist/components/actions/icon-button/icon-button.d.ts.map +1 -1
- package/dist/components/actions/icon-button/icon-button.js +23 -0
- package/dist/components/actions/icon-button/icon-button.js.map +1 -1
- package/dist/components/actions/icon-button/icon-button.template.d.ts.map +1 -1
- package/dist/components/actions/icon-button/icon-button.template.js +10 -3
- package/dist/components/actions/icon-button/icon-button.template.js.map +1 -1
- package/dist/components/actions/menu/menu.styles.js +1 -1
- package/dist/components/actions/split-button/split-button.d.ts +8 -0
- package/dist/components/actions/split-button/split-button.d.ts.map +1 -1
- package/dist/components/actions/split-button/split-button.js +20 -0
- package/dist/components/actions/split-button/split-button.js.map +1 -1
- package/dist/components/actions/split-button/split-button.template.d.ts.map +1 -1
- package/dist/components/actions/split-button/split-button.template.js +4 -0
- package/dist/components/actions/split-button/split-button.template.js.map +1 -1
- package/dist/components/components.js +2857 -1993
- package/dist/components/content/code-viewer/code-viewer.d.ts +14 -1
- package/dist/components/content/code-viewer/code-viewer.d.ts.map +1 -1
- package/dist/components/content/code-viewer/code-viewer.diff.d.ts +40 -0
- package/dist/components/content/code-viewer/code-viewer.diff.d.ts.map +1 -0
- package/dist/components/content/code-viewer/code-viewer.diff.js +261 -0
- package/dist/components/content/code-viewer/code-viewer.diff.js.map +1 -0
- package/dist/components/content/code-viewer/code-viewer.i18n.d.ts +5 -0
- package/dist/components/content/code-viewer/code-viewer.i18n.d.ts.map +1 -1
- package/dist/components/content/code-viewer/code-viewer.i18n.js +9 -0
- package/dist/components/content/code-viewer/code-viewer.i18n.js.map +1 -1
- package/dist/components/content/code-viewer/code-viewer.js +98 -6
- package/dist/components/content/code-viewer/code-viewer.js.map +1 -1
- package/dist/components/content/code-viewer/code-viewer.styles.d.ts.map +1 -1
- package/dist/components/content/code-viewer/code-viewer.styles.js +134 -1
- package/dist/components/content/code-viewer/code-viewer.styles.js.map +1 -1
- package/dist/components/content/code-viewer/code-viewer.template.d.ts.map +1 -1
- package/dist/components/content/code-viewer/code-viewer.template.js +5 -4
- package/dist/components/content/code-viewer/code-viewer.template.js.map +1 -1
- package/dist/components/content/icon/icon-aliases.d.ts.map +1 -1
- package/dist/components/content/icon/icon-aliases.js +13 -4
- package/dist/components/content/icon/icon-aliases.js.map +1 -1
- package/dist/components/content/icon/icon-gallery-status.d.ts.map +1 -1
- package/dist/components/content/icon/icon-gallery-status.js +9 -0
- package/dist/components/content/icon/icon-gallery-status.js.map +1 -1
- package/dist/components/content/icon/icon-registry.d.ts.map +1 -1
- package/dist/components/content/icon/icon-registry.js +9 -2
- package/dist/components/content/icon/icon-registry.js.map +1 -1
- package/dist/components/content/keyboard-shortcut/keyboard-shortcut.d.ts +3 -3
- package/dist/components/content/keyboard-shortcut/keyboard-shortcut.d.ts.map +1 -1
- package/dist/components/content/keyboard-shortcut/keyboard-shortcut.js +6 -21
- package/dist/components/content/keyboard-shortcut/keyboard-shortcut.js.map +1 -1
- package/dist/components/content/keyboard-shortcut/keyboard-shortcut.styles.d.ts.map +1 -1
- package/dist/components/content/keyboard-shortcut/keyboard-shortcut.styles.js +3 -0
- package/dist/components/content/keyboard-shortcut/keyboard-shortcut.styles.js.map +1 -1
- package/dist/components/content/rich-text/rich-text.d.ts +10 -0
- package/dist/components/content/rich-text/rich-text.d.ts.map +1 -1
- package/dist/components/content/rich-text/rich-text.js +10 -0
- package/dist/components/content/rich-text/rich-text.js.map +1 -1
- package/dist/components/content/tooltip/tooltip.d.ts +14 -0
- package/dist/components/content/tooltip/tooltip.d.ts.map +1 -1
- package/dist/components/content/tooltip/tooltip.js +45 -6
- package/dist/components/content/tooltip/tooltip.js.map +1 -1
- package/dist/components/content/tooltip/tooltip.styles.d.ts.map +1 -1
- package/dist/components/content/tooltip/tooltip.styles.js +13 -0
- package/dist/components/content/tooltip/tooltip.styles.js.map +1 -1
- package/dist/components/content/tooltip/tooltip.template.d.ts.map +1 -1
- package/dist/components/content/tooltip/tooltip.template.js +18 -2
- package/dist/components/content/tooltip/tooltip.template.js.map +1 -1
- package/dist/components/{dist-Bo5Jeyfn.js → dist-B5E3q-ea.js} +2 -1
- package/dist/components/{dist-DbNhCpS5.js → dist-BFw_yEMS.js} +2 -1
- package/dist/components/{dist-DnZmcpbQ.js → dist-BNLAXAyO.js} +2 -1
- package/dist/components/{dist-DkqAbJH8.js → dist-BOVSVPSz.js} +1 -1
- package/dist/components/{dist-Ch3gNAuT.js → dist-BPB3rWnd.js} +2 -1
- package/dist/components/{dist-Bud_7w5g.js → dist-BWlUmyq3.js} +34 -2869
- package/dist/components/dist-CC8oiVtm.js +366 -0
- package/dist/components/dist-COKR0tYU.js +2860 -0
- package/dist/components/{dist-CaxHkqR2.js → dist-Co-tsc9S.js} +4 -3
- package/dist/components/{dist-iC2RTM0V.js → dist-D_9ZyZ5v.js} +3 -2
- package/dist/components/{dist-BB5mlo7D.js → dist-Dn9pjiud.js} +3 -2
- package/dist/components/{dist-B2QcygzG.js → dist-Dz28se9B.js} +2 -1
- package/dist/components/{dist-CA0yDFIt.js → dist-IPm8ilWf.js} +3 -2
- package/dist/components/{icon-D_ZGezHx.js → icon-DFhgRf3P.js} +19 -7
- package/dist/components/{icon-button-BVhiOwX9.js → icon-button-Sxkh5cVr.js} +526 -61
- package/dist/components/inputs/code-editor/code-editor.d.ts +4 -54
- package/dist/components/inputs/code-editor/code-editor.d.ts.map +1 -1
- package/dist/components/inputs/code-editor/code-editor.js +22 -262
- package/dist/components/inputs/code-editor/code-editor.js.map +1 -1
- package/dist/components/inputs/code-editor/code-editor.styles.d.ts.map +1 -1
- package/dist/components/inputs/code-editor/code-editor.styles.js +9 -1
- package/dist/components/inputs/code-editor/code-editor.styles.js.map +1 -1
- package/dist/components/inputs/date-picker/date-picker.styles.d.ts.map +1 -1
- package/dist/components/inputs/date-picker/date-picker.styles.js +29 -5
- package/dist/components/inputs/date-picker/date-picker.styles.js.map +1 -1
- package/dist/components/inputs/search-field/search-field.d.ts +11 -0
- package/dist/components/inputs/search-field/search-field.d.ts.map +1 -1
- package/dist/components/inputs/search-field/search-field.js +30 -1
- package/dist/components/inputs/search-field/search-field.js.map +1 -1
- package/dist/components/inputs/search-field/search-field.styles.d.ts.map +1 -1
- package/dist/components/inputs/search-field/search-field.styles.js +18 -0
- package/dist/components/inputs/search-field/search-field.styles.js.map +1 -1
- package/dist/components/inputs/search-field/search-field.template.d.ts.map +1 -1
- package/dist/components/inputs/search-field/search-field.template.js +12 -0
- package/dist/components/inputs/search-field/search-field.template.js.map +1 -1
- package/dist/components/inputs/segmented-control/segmented-control.d.ts +10 -0
- package/dist/components/inputs/segmented-control/segmented-control.d.ts.map +1 -1
- package/dist/components/inputs/segmented-control/segmented-control.js +25 -1
- package/dist/components/inputs/segmented-control/segmented-control.js.map +1 -1
- package/dist/components/inputs/segmented-control/segmented-control.template.d.ts.map +1 -1
- package/dist/components/inputs/segmented-control/segmented-control.template.js +20 -3
- package/dist/components/inputs/segmented-control/segmented-control.template.js.map +1 -1
- package/dist/components/inputs/text-editor/text-editor.annotation-sentinels.d.ts.map +1 -1
- package/dist/components/inputs/text-editor/text-editor.annotation-sentinels.js +9 -7
- package/dist/components/inputs/text-editor/text-editor.annotation-sentinels.js.map +1 -1
- package/dist/components/inputs/text-editor/text-editor.annotations.js +1 -1
- package/dist/components/inputs/text-editor/text-editor.annotations.js.map +1 -1
- package/dist/components/inputs/text-editor/text-editor.clipboard.d.ts +16 -0
- package/dist/components/inputs/text-editor/text-editor.clipboard.d.ts.map +1 -0
- package/dist/components/inputs/text-editor/text-editor.clipboard.js +50 -0
- package/dist/components/inputs/text-editor/text-editor.clipboard.js.map +1 -0
- package/dist/components/inputs/text-editor/text-editor.commands.d.ts.map +1 -1
- package/dist/components/inputs/text-editor/text-editor.commands.js +31 -58
- package/dist/components/inputs/text-editor/text-editor.commands.js.map +1 -1
- package/dist/components/inputs/text-editor/text-editor.d.ts +17 -64
- package/dist/components/inputs/text-editor/text-editor.d.ts.map +1 -1
- package/dist/components/inputs/text-editor/text-editor.drag.d.ts.map +1 -1
- package/dist/components/inputs/text-editor/text-editor.drag.js +2 -1
- package/dist/components/inputs/text-editor/text-editor.drag.js.map +1 -1
- package/dist/components/inputs/text-editor/text-editor.focus-selection.d.ts +3 -0
- package/dist/components/inputs/text-editor/text-editor.focus-selection.d.ts.map +1 -0
- package/dist/components/inputs/text-editor/text-editor.focus-selection.js +55 -0
- package/dist/components/inputs/text-editor/text-editor.focus-selection.js.map +1 -0
- package/dist/components/inputs/text-editor/text-editor.hidden-syntax.d.ts +6 -0
- package/dist/components/inputs/text-editor/text-editor.hidden-syntax.d.ts.map +1 -0
- package/dist/components/inputs/text-editor/text-editor.hidden-syntax.js +257 -0
- package/dist/components/inputs/text-editor/text-editor.hidden-syntax.js.map +1 -0
- package/dist/components/inputs/text-editor/text-editor.js +93 -313
- package/dist/components/inputs/text-editor/text-editor.js.map +1 -1
- package/dist/components/inputs/text-editor/text-editor.keymap.d.ts +6 -0
- package/dist/components/inputs/text-editor/text-editor.keymap.d.ts.map +1 -0
- package/dist/components/inputs/text-editor/text-editor.keymap.js +38 -0
- package/dist/components/inputs/text-editor/text-editor.keymap.js.map +1 -0
- package/dist/components/inputs/text-editor/text-editor.links.d.ts.map +1 -1
- package/dist/components/inputs/text-editor/text-editor.links.js +11 -9
- package/dist/components/inputs/text-editor/text-editor.links.js.map +1 -1
- package/dist/components/inputs/text-editor/text-editor.markdown.d.ts +1 -17
- package/dist/components/inputs/text-editor/text-editor.markdown.d.ts.map +1 -1
- package/dist/components/inputs/text-editor/text-editor.markdown.js +26 -186
- package/dist/components/inputs/text-editor/text-editor.markdown.js.map +1 -1
- package/dist/components/inputs/text-editor/text-editor.mention.d.ts +52 -0
- package/dist/components/inputs/text-editor/text-editor.mention.d.ts.map +1 -0
- package/dist/components/inputs/text-editor/text-editor.mention.js +186 -0
- package/dist/components/inputs/text-editor/text-editor.mention.js.map +1 -0
- package/dist/components/inputs/text-editor/text-editor.mentions.d.ts +0 -16
- package/dist/components/inputs/text-editor/text-editor.mentions.d.ts.map +1 -1
- package/dist/components/inputs/text-editor/text-editor.mentions.js +1 -41
- package/dist/components/inputs/text-editor/text-editor.mentions.js.map +1 -1
- package/dist/components/inputs/text-editor/text-editor.selection.d.ts +13 -0
- package/dist/components/inputs/text-editor/text-editor.selection.d.ts.map +1 -0
- package/dist/components/inputs/text-editor/text-editor.selection.js +62 -0
- package/dist/components/inputs/text-editor/text-editor.selection.js.map +1 -0
- package/dist/components/inputs/text-editor/text-editor.spellcheck.d.ts.map +1 -1
- package/dist/components/inputs/text-editor/text-editor.spellcheck.js +4 -6
- package/dist/components/inputs/text-editor/text-editor.spellcheck.js.map +1 -1
- package/dist/components/inputs/text-editor/text-editor.styles.d.ts.map +1 -1
- package/dist/components/inputs/text-editor/text-editor.styles.js +185 -64
- package/dist/components/inputs/text-editor/text-editor.styles.js.map +1 -1
- package/dist/components/inputs/text-editor/text-editor.syntax.d.ts +22 -0
- package/dist/components/inputs/text-editor/text-editor.syntax.d.ts.map +1 -1
- package/dist/components/inputs/text-editor/text-editor.syntax.js +44 -0
- package/dist/components/inputs/text-editor/text-editor.syntax.js.map +1 -1
- package/dist/components/inputs/toggle-button/toggle-button.d.ts +10 -0
- package/dist/components/inputs/toggle-button/toggle-button.d.ts.map +1 -1
- package/dist/components/inputs/toggle-button/toggle-button.js +25 -1
- package/dist/components/inputs/toggle-button/toggle-button.js.map +1 -1
- package/dist/components/inputs/toggle-button/toggle-button.template.d.ts.map +1 -1
- package/dist/components/inputs/toggle-button/toggle-button.template.js +21 -7
- package/dist/components/inputs/toggle-button/toggle-button.template.js.map +1 -1
- package/dist/components/layout/card/card.styles.js +4 -4
- package/dist/components/layout/container/container.d.ts +2 -0
- package/dist/components/layout/container/container.d.ts.map +1 -1
- package/dist/components/layout/container/container.js +9 -0
- package/dist/components/layout/container/container.js.map +1 -1
- package/dist/components/layout/container/container.styles.d.ts.map +1 -1
- package/dist/components/layout/container/container.styles.js +13 -0
- package/dist/components/layout/container/container.styles.js.map +1 -1
- package/dist/components/lists-and-tables/cells/step-cell/step-cell.styles.d.ts.map +1 -1
- package/dist/components/lists-and-tables/cells/step-cell/step-cell.styles.js +9 -5
- package/dist/components/lists-and-tables/cells/step-cell/step-cell.styles.js.map +1 -1
- package/dist/components/navigation/document-tab-bar/document-tab-bar.styles.d.ts.map +1 -1
- package/dist/components/navigation/document-tab-bar/document-tab-bar.styles.js +16 -15
- package/dist/components/navigation/document-tab-bar/document-tab-bar.styles.js.map +1 -1
- package/dist/components/navigation/menu-bar-item/menu-bar-item.styles.js +2 -2
- package/dist/components/navigation/tab-bar/tab-bar.styles.js +9 -9
- package/dist/components/status-and-feedback/activity-indicator/activity-indicator.d.ts +16 -9
- package/dist/components/status-and-feedback/activity-indicator/activity-indicator.d.ts.map +1 -1
- package/dist/components/status-and-feedback/activity-indicator/activity-indicator.js +16 -9
- package/dist/components/status-and-feedback/activity-indicator/activity-indicator.js.map +1 -1
- package/dist/components/status-and-feedback/activity-indicator/activity-indicator.styles.d.ts.map +1 -1
- package/dist/components/status-and-feedback/activity-indicator/activity-indicator.styles.js +23 -18
- package/dist/components/status-and-feedback/activity-indicator/activity-indicator.styles.js.map +1 -1
- package/dist/components/status-and-feedback/activity-indicator/activity-indicator.template.d.ts.map +1 -1
- package/dist/components/status-and-feedback/activity-indicator/activity-indicator.template.js +19 -21
- package/dist/components/status-and-feedback/activity-indicator/activity-indicator.template.js.map +1 -1
- package/dist/components/status-and-feedback/inline-dialog/inline-dialog.styles.js +1 -1
- package/dist/components/status-and-feedback/notification/notification.d.ts +2 -1
- package/dist/components/status-and-feedback/notification/notification.d.ts.map +1 -1
- package/dist/components/status-and-feedback/notification/notification.js +5 -2
- package/dist/components/status-and-feedback/notification/notification.js.map +1 -1
- package/dist/components/status-and-feedback/notification/notification.styles.d.ts.map +1 -1
- package/dist/components/status-and-feedback/notification/notification.styles.js +19 -1
- package/dist/components/status-and-feedback/notification/notification.styles.js.map +1 -1
- package/dist/components/status-and-feedback/notification/notifications-area.d.ts.map +1 -1
- package/dist/components/status-and-feedback/notification/notifications-area.js +14 -0
- package/dist/components/status-and-feedback/notification/notifications-area.js.map +1 -1
- package/dist/components/status-and-feedback/progress-bar/progress-bar.styles.js +4 -4
- package/dist/components/status-and-feedback/progress-circle/progress-circle.styles.js +3 -3
- package/dist/components/status-and-feedback/progress-circle/progress-circle.template.js +1 -1
- package/dist/components/status-and-feedback/progress-circle/progress-circle.template.js.map +1 -1
- package/dist/components/status-and-feedback/step-bar/step-bar.styles.d.ts.map +1 -1
- package/dist/components/status-and-feedback/step-bar/step-bar.styles.js +7 -5
- package/dist/components/status-and-feedback/step-bar/step-bar.styles.js.map +1 -1
- package/dist/css/rich-text.css +61 -1
- package/dist/css/themes/bruin.css +108 -64
- package/dist/css/themes/donkerblauw.css +108 -64
- package/dist/css/themes/donkerbruin.css +88 -64
- package/dist/css/themes/donkergeel.css +149 -94
- package/dist/css/themes/donkergroen.css +93 -64
- package/dist/css/themes/geel.css +149 -94
- package/dist/css/themes/groen.css +108 -64
- package/dist/css/themes/hemelblauw.css +108 -64
- package/dist/css/themes/lichtblauw.css +111 -64
- package/dist/css/themes/mintgroen.css +111 -64
- package/dist/css/themes/mosgroen.css +108 -64
- package/dist/css/themes/oranje.css +162 -99
- package/dist/css/themes/paars.css +115 -64
- package/dist/css/themes/robijnrood.css +159 -96
- package/dist/css/themes/rood.css +159 -96
- package/dist/css/themes/roze.css +118 -64
- package/dist/css/themes/violet.css +93 -64
- package/dist/css/themes.css +2047 -1247
- package/dist/css/variables.css +142 -70
- package/dist/nldd.min.js +1468 -998
- package/dist/translations/en-US.d.ts.map +1 -1
- package/dist/translations/en-US.js +5 -0
- package/dist/translations/en-US.js.map +1 -1
- package/dist/translations/nl.generated.d.ts +5 -0
- package/dist/translations/nl.generated.d.ts.map +1 -1
- package/dist/types/vue.d.ts +138 -32
- package/dist/utilities/codemirror/codemirror-input.d.ts +90 -0
- package/dist/utilities/codemirror/codemirror-input.d.ts.map +1 -0
- package/dist/utilities/codemirror/codemirror-input.js +250 -0
- package/dist/utilities/codemirror/codemirror-input.js.map +1 -0
- package/dist/utilities/codemirror/theme.js +1 -1
- package/dist/utilities/codemirror/theme.js.map +1 -1
- package/dist/utilities/shortcut.d.ts +50 -0
- package/dist/utilities/shortcut.d.ts.map +1 -0
- package/dist/utilities/shortcut.js +77 -0
- package/dist/utilities/shortcut.js.map +1 -0
- package/package.json +2 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Extension } from '@codemirror/state';
|
|
2
2
|
import { NLDDCodeMirrorElement } from '../../../utilities/codemirror/codemirror-element.js';
|
|
3
|
+
import { type ParsedDiff } from './code-viewer.diff.js';
|
|
3
4
|
import type { NLDDCodeViewerTranslations } from './code-viewer.i18n.js';
|
|
4
5
|
import '../../actions/icon-button/icon-button.js';
|
|
5
6
|
import '../tooltip/tooltip.js';
|
|
@@ -11,6 +12,8 @@ export declare class NLDDCodeViewer extends NLDDCodeMirrorElement {
|
|
|
11
12
|
* fill with; `simple` drops the frame. */
|
|
12
13
|
appearance: CodeViewerAppearance;
|
|
13
14
|
language: string;
|
|
15
|
+
/** The content is a unified diff. */
|
|
16
|
+
diff: boolean;
|
|
14
17
|
/** Hide the copy-to-clipboard button (shown by default). */
|
|
15
18
|
noCopy: boolean;
|
|
16
19
|
wrap: boolean;
|
|
@@ -22,7 +25,12 @@ export declare class NLDDCodeViewer extends NLDDCodeMirrorElement {
|
|
|
22
25
|
_copyState: CodeViewerCopyState;
|
|
23
26
|
private _languageCompartment;
|
|
24
27
|
private _wrapCompartment;
|
|
28
|
+
private _diffCompartment;
|
|
29
|
+
private _wordCompartment;
|
|
25
30
|
private _languagePending;
|
|
31
|
+
private _wordsPending;
|
|
32
|
+
/** The parsed diff on screen, or null without `diff`. */
|
|
33
|
+
_parsedDiff: ParsedDiff | null;
|
|
26
34
|
private _unsubscribeScheme?;
|
|
27
35
|
private _resizeObserver?;
|
|
28
36
|
private _mutationObserver?;
|
|
@@ -41,7 +49,12 @@ export declare class NLDDCodeViewer extends NLDDCodeMirrorElement {
|
|
|
41
49
|
protected onEditorMounted(): void;
|
|
42
50
|
updated(changed: Map<string, unknown>): void;
|
|
43
51
|
_onSlotChange(): void;
|
|
44
|
-
|
|
52
|
+
private _applyContent;
|
|
53
|
+
private _diffExtension;
|
|
54
|
+
private _applyWords;
|
|
55
|
+
/** The summary a screen reader hears before a diff. */
|
|
56
|
+
get _diffSummary(): string;
|
|
57
|
+
_t(key: keyof NLDDCodeViewerTranslations, vars?: Record<string, string | number>): string;
|
|
45
58
|
getUpdateComplete(): Promise<boolean>;
|
|
46
59
|
private _applyLanguage;
|
|
47
60
|
private _runLanguage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-viewer.d.ts","sourceRoot":"","sources":["../../../../src/components/content/code-viewer/code-viewer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"code-viewer.d.ts","sourceRoot":"","sources":["../../../../src/components/content/code-viewer/code-viewer.ts"],"names":[],"mappings":"AAwDA,OAAO,EAA4B,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,qDAAqD,CAAC;AAM5F,OAAO,EA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
5
|
+
text: string;
|
|
6
|
+
oldNumber: number | null;
|
|
7
|
+
newNumber: number | null;
|
|
8
|
+
/** The `@@` header of the hunk this line opens, if it opens one. */
|
|
9
|
+
hunk: string | null;
|
|
10
|
+
}
|
|
11
|
+
export interface ParsedDiff {
|
|
12
|
+
/** The code: every line of the diff without its first character. */
|
|
13
|
+
doc: string;
|
|
14
|
+
lines: DiffLine[];
|
|
15
|
+
added: number;
|
|
16
|
+
removed: number;
|
|
17
|
+
}
|
|
18
|
+
/** Parse a unified diff. File headers (`diff --git`, `index`, `---`, `+++` and
|
|
19
|
+
* the like) are left out: the file name belongs to the page around the viewer.
|
|
20
|
+
* So is ``. A hunk ends where its `@@` header says
|
|
21
|
+
* it does, so the headers of a next file in a multi-file diff are not taken for
|
|
22
|
+
* code; their name is lost, though, so give each file a viewer of its own.
|
|
23
|
+
* Without any `@@` header, every line after the file header is code and the
|
|
24
|
+
* numbers start at 1. */
|
|
25
|
+
export declare function parseUnifiedDiff(raw: string): ParsedDiff;
|
|
26
|
+
/** The removed and added lines that are one change: within a hunk, a run of
|
|
27
|
+
* removed lines directly followed by a run of added lines, paired in order.
|
|
28
|
+
* Indices are into `lines`. */
|
|
29
|
+
export declare function pairChangedLines(lines: DiffLine[]): Array<[number, number]>;
|
|
30
|
+
export interface DiffLabels {
|
|
31
|
+
addedLine(number: number): string;
|
|
32
|
+
removedLine(number: number): string;
|
|
33
|
+
}
|
|
34
|
+
/** Line colors, gutters, hunk headers and line labels for a parsed diff. */
|
|
35
|
+
export declare function diffExtensions(parsed: ParsedDiff, labels: DiffLabels): Extension;
|
|
36
|
+
/** Marks on the words that differ between each paired removed and added line.
|
|
37
|
+
* Loads @codemirror/merge on first use, so a viewer without a diff never
|
|
38
|
+
* fetches it. */
|
|
39
|
+
export declare function wordExtensions(parsed: ParsedDiff): Promise<Extension>;
|
|
40
|
+
//# sourceMappingURL=code-viewer.diff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-viewer.diff.d.ts","sourceRoot":"","sources":["../../../../src/components/content/code-viewer/code-viewer.diff.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,KAAK,SAAS,EAAc,MAAM,mBAAmB,CAAC;AAQzE,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC;AAE3D,MAAM,WAAW,QAAQ;IACxB,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,oEAAoE;IACpE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IAC1B,oEAAoE;IACpE,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CAChB;AAiBD;;;;;;0BAM0B;AAC1B,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAuDxD;AAED;;gCAEgC;AAChC,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAiB3E;AAED,MAAM,WAAW,UAAU;IAC1B,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IAClC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;CACpC;AAqFD,4EAA4E;AAC5E,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,GAAG,SAAS,CA4ChF;AASD;;kBAEkB;AAClB,wBAAsB,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,CAoB3E"}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { Decoration, EditorView, GutterMarker, WidgetType, gutter, gutterLineClass } from '@codemirror/view';
|
|
2
|
+
import { RangeSet } from '@codemirror/state';
|
|
3
|
+
const HUNK_RE = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/;
|
|
4
|
+
const FILE_HEADER_RE = /^(diff |index |--- |\+\+\+ |new file|deleted file|similarity |rename |old mode|new mode)/;
|
|
5
|
+
/** Without `@@` headers every line is code, so file headers in front of it would
|
|
6
|
+
* read as a removed and an added line. They are taken off when they hold the
|
|
7
|
+
* `---` and `+++` pair that only a file header has; a code line that happens to
|
|
8
|
+
* start with `---` stays. */
|
|
9
|
+
function withoutLeadingFileHeader(source) {
|
|
10
|
+
let end = 0;
|
|
11
|
+
while (end < source.length && FILE_HEADER_RE.test(source[end]))
|
|
12
|
+
end++;
|
|
13
|
+
const head = source.slice(0, end);
|
|
14
|
+
const hasPair = head.some((line, i) => line.startsWith('--- ') && head[i + 1]?.startsWith('+++ '));
|
|
15
|
+
return hasPair ? source.slice(end) : source;
|
|
16
|
+
}
|
|
17
|
+
/** Parse a unified diff. File headers (`diff --git`, `index`, `---`, `+++` and
|
|
18
|
+
* the like) are left out: the file name belongs to the page around the viewer.
|
|
19
|
+
* So is ``. A hunk ends where its `@@` header says
|
|
20
|
+
* it does, so the headers of a next file in a multi-file diff are not taken for
|
|
21
|
+
* code; their name is lost, though, so give each file a viewer of its own.
|
|
22
|
+
* Without any `@@` header, every line after the file header is code and the
|
|
23
|
+
* numbers start at 1. */
|
|
24
|
+
export function parseUnifiedDiff(raw) {
|
|
25
|
+
const all = raw.replace(/\r\n?/g, '\n').replace(/\n$/, '').split('\n');
|
|
26
|
+
const hasHunks = all.some((line) => HUNK_RE.test(line));
|
|
27
|
+
const source = hasHunks ? all : withoutLeadingFileHeader(all);
|
|
28
|
+
const lines = [];
|
|
29
|
+
let oldNumber = 1;
|
|
30
|
+
let newNumber = 1;
|
|
31
|
+
// Lines the current hunk still holds on each side; Infinity without headers.
|
|
32
|
+
let oldLeft = hasHunks ? 0 : Infinity;
|
|
33
|
+
let newLeft = hasHunks ? 0 : Infinity;
|
|
34
|
+
let hunk = null;
|
|
35
|
+
let added = 0;
|
|
36
|
+
let removed = 0;
|
|
37
|
+
// Lines past a hunk's counts that are not the header of a next file: a tool
|
|
38
|
+
// that wrote the counts wrong loses them, which development should hear about.
|
|
39
|
+
let seenHunk = false;
|
|
40
|
+
let dropped = 0;
|
|
41
|
+
for (const line of source) {
|
|
42
|
+
const header = HUNK_RE.exec(line);
|
|
43
|
+
if (header) {
|
|
44
|
+
oldNumber = Number(header[1]);
|
|
45
|
+
oldLeft = header[2] === undefined ? 1 : Number(header[2]);
|
|
46
|
+
newNumber = Number(header[3]);
|
|
47
|
+
newLeft = header[4] === undefined ? 1 : Number(header[4]);
|
|
48
|
+
hunk = line;
|
|
49
|
+
seenHunk = true;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (oldLeft <= 0 && newLeft <= 0) {
|
|
53
|
+
if (seenHunk && line !== '' && !line.startsWith('\\') && !FILE_HEADER_RE.test(line))
|
|
54
|
+
dropped++;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (line.startsWith('\\'))
|
|
58
|
+
continue;
|
|
59
|
+
const sign = line[0];
|
|
60
|
+
const text = line.slice(1);
|
|
61
|
+
if (sign === '+') {
|
|
62
|
+
lines.push({ kind: 'added', text, oldNumber: null, newNumber: newNumber++, hunk });
|
|
63
|
+
newLeft--;
|
|
64
|
+
added++;
|
|
65
|
+
}
|
|
66
|
+
else if (sign === '-') {
|
|
67
|
+
lines.push({ kind: 'removed', text, oldNumber: oldNumber++, newNumber: null, hunk });
|
|
68
|
+
oldLeft--;
|
|
69
|
+
removed++;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
// A space, or an empty line where a tool dropped the trailing space.
|
|
73
|
+
lines.push({ kind: 'context', text, oldNumber: oldNumber++, newNumber: newNumber++, hunk });
|
|
74
|
+
oldLeft--;
|
|
75
|
+
newLeft--;
|
|
76
|
+
}
|
|
77
|
+
hunk = null;
|
|
78
|
+
}
|
|
79
|
+
if (dropped > 0 && import.meta.env?.DEV) {
|
|
80
|
+
console.warn(`<nldd-code-viewer>: ${dropped} line(s) of the diff fall outside the line counts of their @@ header and are not shown. Check the counts in the hunk headers.`);
|
|
81
|
+
}
|
|
82
|
+
return { doc: lines.map((line) => line.text).join('\n'), lines, added, removed };
|
|
83
|
+
}
|
|
84
|
+
/** The removed and added lines that are one change: within a hunk, a run of
|
|
85
|
+
* removed lines directly followed by a run of added lines, paired in order.
|
|
86
|
+
* Indices are into `lines`. */
|
|
87
|
+
export function pairChangedLines(lines) {
|
|
88
|
+
const pairs = [];
|
|
89
|
+
let i = 0;
|
|
90
|
+
while (i < lines.length) {
|
|
91
|
+
if (lines[i].kind !== 'removed') {
|
|
92
|
+
i++;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const removedFrom = i;
|
|
96
|
+
while (i < lines.length && lines[i].kind === 'removed' && (i === removedFrom || !lines[i].hunk))
|
|
97
|
+
i++;
|
|
98
|
+
const addedFrom = i;
|
|
99
|
+
while (i < lines.length && lines[i].kind === 'added' && !lines[i].hunk)
|
|
100
|
+
i++;
|
|
101
|
+
for (let k = 0; k < Math.min(addedFrom - removedFrom, i - addedFrom); k++) {
|
|
102
|
+
pairs.push([removedFrom + k, addedFrom + k]);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return pairs;
|
|
106
|
+
}
|
|
107
|
+
class NumberMarker extends GutterMarker {
|
|
108
|
+
constructor(text) {
|
|
109
|
+
super();
|
|
110
|
+
this.text = text;
|
|
111
|
+
}
|
|
112
|
+
eq(other) {
|
|
113
|
+
return other.text === this.text;
|
|
114
|
+
}
|
|
115
|
+
toDOM() {
|
|
116
|
+
return document.createTextNode(this.text);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
class LineClassMarker extends GutterMarker {
|
|
120
|
+
constructor(className) {
|
|
121
|
+
super();
|
|
122
|
+
this.className = className;
|
|
123
|
+
this.elementClass = className;
|
|
124
|
+
}
|
|
125
|
+
eq(other) {
|
|
126
|
+
return other.className === this.className;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/* What a screen reader says before a changed line: the gutters are hidden
|
|
130
|
+
* from it, and a color says nothing. Not in the document, so not in a copy. */
|
|
131
|
+
class LineLabelWidget extends WidgetType {
|
|
132
|
+
constructor(text) {
|
|
133
|
+
super();
|
|
134
|
+
this.text = text;
|
|
135
|
+
}
|
|
136
|
+
eq(other) {
|
|
137
|
+
return other.text === this.text;
|
|
138
|
+
}
|
|
139
|
+
toDOM() {
|
|
140
|
+
const label = document.createElement('span');
|
|
141
|
+
label.className = 'cm-diff-line-label';
|
|
142
|
+
label.textContent = `${this.text}: `;
|
|
143
|
+
return label;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/* The `@@` header between hunks. A screen reader skips it: the label on each
|
|
147
|
+
* changed line already says where it is. */
|
|
148
|
+
class HunkWidget extends WidgetType {
|
|
149
|
+
constructor(header) {
|
|
150
|
+
super();
|
|
151
|
+
this.header = header;
|
|
152
|
+
}
|
|
153
|
+
eq(other) {
|
|
154
|
+
return other.header === this.header;
|
|
155
|
+
}
|
|
156
|
+
toDOM() {
|
|
157
|
+
const row = document.createElement('div');
|
|
158
|
+
row.className = 'cm-diff-hunk';
|
|
159
|
+
row.setAttribute('aria-hidden', 'true');
|
|
160
|
+
row.textContent = this.header;
|
|
161
|
+
return row;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const lineClass = {
|
|
165
|
+
added: 'cm-diff-added',
|
|
166
|
+
removed: 'cm-diff-removed',
|
|
167
|
+
context: 'cm-diff-context',
|
|
168
|
+
};
|
|
169
|
+
const SIGN = { added: '+', removed: '−', context: '' };
|
|
170
|
+
/** Where each line starts in the document. */
|
|
171
|
+
function lineOffsets(lines) {
|
|
172
|
+
const starts = [];
|
|
173
|
+
let pos = 0;
|
|
174
|
+
for (const line of lines) {
|
|
175
|
+
starts.push(pos);
|
|
176
|
+
pos += line.text.length + 1;
|
|
177
|
+
}
|
|
178
|
+
return starts;
|
|
179
|
+
}
|
|
180
|
+
/** Line colors, gutters, hunk headers and line labels for a parsed diff. */
|
|
181
|
+
export function diffExtensions(parsed, labels) {
|
|
182
|
+
const { lines } = parsed;
|
|
183
|
+
if (lines.length === 0)
|
|
184
|
+
return [];
|
|
185
|
+
const lineStarts = lineOffsets(lines);
|
|
186
|
+
const decorations = [];
|
|
187
|
+
const gutterClasses = [];
|
|
188
|
+
lines.forEach((line, i) => {
|
|
189
|
+
const from = lineStarts[i];
|
|
190
|
+
if (line.hunk)
|
|
191
|
+
decorations.push(Decoration.widget({ widget: new HunkWidget(line.hunk), block: true, side: -1 }).range(from));
|
|
192
|
+
decorations.push(Decoration.line({ class: lineClass[line.kind] }).range(from));
|
|
193
|
+
if (line.kind === 'added')
|
|
194
|
+
decorations.push(Decoration.widget({ widget: new LineLabelWidget(labels.addedLine(line.newNumber)), side: -1 }).range(from));
|
|
195
|
+
if (line.kind === 'removed')
|
|
196
|
+
decorations.push(Decoration.widget({ widget: new LineLabelWidget(labels.removedLine(line.oldNumber)), side: -1 }).range(from));
|
|
197
|
+
gutterClasses.push(new LineClassMarker(lineClass[line.kind]).range(from));
|
|
198
|
+
});
|
|
199
|
+
const lineAt = (view, block) => lines[view.state.doc.lineAt(block.from).number - 1];
|
|
200
|
+
// A reduce, not Math.max(...): spreading a very long diff runs past the
|
|
201
|
+
// engine's argument limit.
|
|
202
|
+
const widest = (pick) => String(lines.reduce((max, line) => Math.max(max, pick(line) ?? 0), 0));
|
|
203
|
+
const numberGutter = (name, pick) => gutter({
|
|
204
|
+
class: `cm-diff-gutter cm-diff-${name}-gutter`,
|
|
205
|
+
lineMarker: (view, block) => {
|
|
206
|
+
const line = lineAt(view, block);
|
|
207
|
+
const number = line ? pick(line) : null;
|
|
208
|
+
return number === null ? null : new NumberMarker(String(number));
|
|
209
|
+
},
|
|
210
|
+
initialSpacer: () => new NumberMarker(widest(pick)),
|
|
211
|
+
});
|
|
212
|
+
return [
|
|
213
|
+
EditorView.decorations.of(Decoration.set(decorations, true)),
|
|
214
|
+
gutterLineClass.of(RangeSet.of(gutterClasses, true)),
|
|
215
|
+
numberGutter('old', (line) => line.oldNumber),
|
|
216
|
+
numberGutter('new', (line) => line.newNumber),
|
|
217
|
+
gutter({
|
|
218
|
+
class: 'cm-diff-gutter cm-diff-sign-gutter',
|
|
219
|
+
lineMarker: (view, block) => {
|
|
220
|
+
const line = lineAt(view, block);
|
|
221
|
+
return line && line.kind !== 'context' ? new NumberMarker(SIGN[line.kind]) : null;
|
|
222
|
+
},
|
|
223
|
+
initialSpacer: () => new NumberMarker('+'),
|
|
224
|
+
}),
|
|
225
|
+
];
|
|
226
|
+
}
|
|
227
|
+
/** Above this share of a line changed, marking the words says less than
|
|
228
|
+
* marking none: the whole line is new. */
|
|
229
|
+
const WORD_MARK_LIMIT = 0.5;
|
|
230
|
+
const removedWord = Decoration.mark({ class: 'cm-diff-removed-word' });
|
|
231
|
+
const addedWord = Decoration.mark({ class: 'cm-diff-added-word' });
|
|
232
|
+
/** Marks on the words that differ between each paired removed and added line.
|
|
233
|
+
* Loads @codemirror/merge on first use, so a viewer without a diff never
|
|
234
|
+
* fetches it. */
|
|
235
|
+
export async function wordExtensions(parsed) {
|
|
236
|
+
const pairs = pairChangedLines(parsed.lines);
|
|
237
|
+
if (pairs.length === 0)
|
|
238
|
+
return [];
|
|
239
|
+
const { presentableDiff } = await import('@codemirror/merge');
|
|
240
|
+
const lineStarts = lineOffsets(parsed.lines);
|
|
241
|
+
const marks = [];
|
|
242
|
+
for (const [r, a] of pairs) {
|
|
243
|
+
const before = parsed.lines[r].text;
|
|
244
|
+
const after = parsed.lines[a].text;
|
|
245
|
+
const changes = presentableDiff(before, after);
|
|
246
|
+
if (changes.length === 0)
|
|
247
|
+
continue;
|
|
248
|
+
const changedBefore = changes.reduce((sum, c) => sum + c.toA - c.fromA, 0);
|
|
249
|
+
const changedAfter = changes.reduce((sum, c) => sum + c.toB - c.fromB, 0);
|
|
250
|
+
if (changedBefore + changedAfter > (before.length + after.length) * WORD_MARK_LIMIT)
|
|
251
|
+
continue;
|
|
252
|
+
for (const change of changes) {
|
|
253
|
+
if (change.toA > change.fromA)
|
|
254
|
+
marks.push(removedWord.range(lineStarts[r] + change.fromA, lineStarts[r] + change.toA));
|
|
255
|
+
if (change.toB > change.fromB)
|
|
256
|
+
marks.push(addedWord.range(lineStarts[a] + change.fromB, lineStarts[a] + change.toB));
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return marks.length ? EditorView.decorations.of(Decoration.set(marks, true)) : [];
|
|
260
|
+
}
|
|
261
|
+
//# sourceMappingURL=code-viewer.diff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-viewer.diff.js","sourceRoot":"","sources":["../../../../src/components/content/code-viewer/code-viewer.diff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,eAAe,EAAkB,MAAM,kBAAkB,CAAC;AAC7H,OAAO,EAAE,QAAQ,EAA8B,MAAM,mBAAmB,CAAC;AA2BzE,MAAM,OAAO,GAAG,6CAA6C,CAAC;AAC9D,MAAM,cAAc,GAAG,0FAA0F,CAAC;AAElH;;;8BAG8B;AAC9B,SAAS,wBAAwB,CAAC,MAAgB;IACjD,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,OAAO,GAAG,GAAG,MAAM,CAAC,MAAM,IAAI,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAAE,GAAG,EAAE,CAAC;IACtE,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAClC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE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AC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC3E,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC1E,IAAI,aAAa,GAAG,YAAY,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,eAAe;YAAE,SAAS;QAC9F,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC9B,IAAI,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,KAAK;gBAAE,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YACvH,IAAI,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,KAAK;gBAAE,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QACtH,CAAC;IACF,CAAC;IACD,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACnF,CAAC"}
|
|
@@ -3,6 +3,11 @@ export declare const nlddCodeViewerTranslations: {
|
|
|
3
3
|
'components.code-viewer.copy-action': string;
|
|
4
4
|
'components.code-viewer.copy-success-text': string;
|
|
5
5
|
'components.code-viewer.copy-failure-text': string;
|
|
6
|
+
'components.code-viewer.diff-summary-text': string;
|
|
7
|
+
'components.code-viewer.line-singular-lowercase': string;
|
|
8
|
+
'components.code-viewer.line-plural-lowercase': string;
|
|
9
|
+
'components.code-viewer.added-line-label': string;
|
|
10
|
+
'components.code-viewer.removed-line-label': string;
|
|
6
11
|
};
|
|
7
12
|
export type NLDDCodeViewerTranslations = typeof nlddCodeViewerTranslations;
|
|
8
13
|
//# sourceMappingURL=code-viewer.i18n.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-viewer.i18n.d.ts","sourceRoot":"","sources":["../../../../src/components/content/code-viewer/code-viewer.i18n.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,0BAA0B
|
|
1
|
+
{"version":3,"file":"code-viewer.i18n.d.ts","sourceRoot":"","sources":["../../../../src/components/content/code-viewer/code-viewer.i18n.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,0BAA0B;;;;;;;;;;CActC,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG,OAAO,0BAA0B,CAAC"}
|
|
@@ -3,5 +3,14 @@ export const nlddCodeViewerTranslations = {
|
|
|
3
3
|
'components.code-viewer.copy-action': 'Kopieer',
|
|
4
4
|
'components.code-viewer.copy-success-text': 'Gekopieerd',
|
|
5
5
|
'components.code-viewer.copy-failure-text': 'Kopiëren mislukt',
|
|
6
|
+
// What a screen reader hears before a diff. {added} and {removed} are line
|
|
7
|
+
// counts, {addedNoun} and {removedNoun} the singular or plural noun below.
|
|
8
|
+
'components.code-viewer.diff-summary-text': '{added} {addedNoun} toegevoegd, {removed} {removedNoun} verwijderd',
|
|
9
|
+
'components.code-viewer.line-singular-lowercase': 'regel',
|
|
10
|
+
'components.code-viewer.line-plural-lowercase': 'regels',
|
|
11
|
+
// Before each changed line of a diff. {number} is its line number: the new
|
|
12
|
+
// one for an added line, the old one for a removed line.
|
|
13
|
+
'components.code-viewer.added-line-label': 'Toegevoegd, regel {number}',
|
|
14
|
+
'components.code-viewer.removed-line-label': 'Verwijderd, regel {number}',
|
|
6
15
|
};
|
|
7
16
|
//# sourceMappingURL=code-viewer.i18n.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-viewer.i18n.js","sourceRoot":"","sources":["../../../../src/components/content/code-viewer/code-viewer.i18n.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACzC,qCAAqC,EAAE,MAAM;IAC7C,oCAAoC,EAAE,SAAS;IAC/C,0CAA0C,EAAE,YAAY;IACxD,0CAA0C,EAAE,kBAAkB;
|
|
1
|
+
{"version":3,"file":"code-viewer.i18n.js","sourceRoot":"","sources":["../../../../src/components/content/code-viewer/code-viewer.i18n.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACzC,qCAAqC,EAAE,MAAM;IAC7C,oCAAoC,EAAE,SAAS;IAC/C,0CAA0C,EAAE,YAAY;IACxD,0CAA0C,EAAE,kBAAkB;IAC9D,2EAA2E;IAC3E,2EAA2E;IAC3E,0CAA0C,EAAE,oEAAoE;IAChH,gDAAgD,EAAE,OAAO;IACzD,8CAA8C,EAAE,QAAQ;IACxD,2EAA2E;IAC3E,yDAAyD;IACzD,yCAAyC,EAAE,4BAA4B;IACvE,2CAA2C,EAAE,4BAA4B;CACzE,CAAC"}
|
|
@@ -25,6 +25,20 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
25
25
|
* plain. Grammars are loaded lazily on first use, so a page that never sets
|
|
26
26
|
* `language` ships zero grammar code.
|
|
27
27
|
*
|
|
28
|
+
* ## Diff
|
|
29
|
+
* Set `diff` when the content is a unified diff, as git and pull request tools
|
|
30
|
+
* hand it out. The viewer shows the code it changes: an added line green and a
|
|
31
|
+
* removed line red, a column with the old and one with the new line number, a
|
|
32
|
+
* column with the `+` or `−`, and the `@@` header of each hunk between them.
|
|
33
|
+
* Within a removed line that is directly followed by an added one, the words
|
|
34
|
+
* that differ are marked, unless more than half of the line changed. File
|
|
35
|
+
* headers (`diff --git`, `---`, `+++`) are left out: name the file in the page
|
|
36
|
+
* around the viewer, and give each file of a multi-file diff a viewer of its
|
|
37
|
+
* own. `language` still highlights the code. A screen reader hears a
|
|
38
|
+
* summary first ("2 regels toegevoegd, 1 regel verwijderd") and "Toegevoegd" or
|
|
39
|
+
* "Verwijderd" with the line number before each changed line. A selection
|
|
40
|
+
* copies the code; the copy button copies the diff.
|
|
41
|
+
*
|
|
28
42
|
* ### Theming
|
|
29
43
|
* Token colors are the `--semantics-code-syntax-*` custom properties
|
|
30
44
|
* (shared with the editor via the CodeMirror highlight style). Override them
|
|
@@ -34,6 +48,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
34
48
|
*
|
|
35
49
|
* @attr {'box-tinted'|'box-base'|'simple'} appearance - Visual style. The two `box` values are a framed card with rounded corners, padding, fill, and a 1px border ring, and differ in which surface they fill with; `box-tinted` is the default. `simple` drops the entire frame — use when embedding inside a parent surface.
|
|
36
50
|
* @attr {string} language - Grammar to highlight with. Empty disables highlighting.
|
|
51
|
+
* @attr {boolean} diff - The content is a unified diff: shown with line colors, old and new line numbers, and the changed words marked.
|
|
37
52
|
* @attr {boolean} no-copy - Hide the copy-to-clipboard button (shown by default).
|
|
38
53
|
* @attr {boolean} wrap - Wrap long lines instead of horizontal scroll
|
|
39
54
|
* @attr {string} max-height - Tallest the block may get, as a CSS length (e.g. '400px', '50vh'). Beyond it the content scrolls vertically. Unset means no cap.
|
|
@@ -52,6 +67,7 @@ import { loadLanguage } from '../../../utilities/codemirror/languages.js';
|
|
|
52
67
|
import { codeViewerStyles } from './code-viewer.styles.js';
|
|
53
68
|
import { codeViewerTemplate } from './code-viewer.template.js';
|
|
54
69
|
import { nlddCodeViewerTranslations } from './code-viewer.i18n.js';
|
|
70
|
+
import { diffExtensions, parseUnifiedDiff, wordExtensions } from './code-viewer.diff.js';
|
|
55
71
|
import { onColorSchemeChange, forceScrollLayerRepaint } from '../../../utilities/color-scheme-repaint.js';
|
|
56
72
|
import '../../actions/icon-button/icon-button.js';
|
|
57
73
|
import '../tooltip/tooltip.js';
|
|
@@ -73,6 +89,8 @@ let NLDDCodeViewer = class NLDDCodeViewer extends NLDDCodeMirrorElement {
|
|
|
73
89
|
* fill with; `simple` drops the frame. */
|
|
74
90
|
this.appearance = 'box-tinted';
|
|
75
91
|
this.language = '';
|
|
92
|
+
/** The content is a unified diff. */
|
|
93
|
+
this.diff = false;
|
|
76
94
|
/** Hide the copy-to-clipboard button (shown by default). */
|
|
77
95
|
this.noCopy = false;
|
|
78
96
|
this.wrap = false;
|
|
@@ -87,7 +105,12 @@ let NLDDCodeViewer = class NLDDCodeViewer extends NLDDCodeMirrorElement {
|
|
|
87
105
|
this._copyState = 'idle';
|
|
88
106
|
this._languageCompartment = new Compartment();
|
|
89
107
|
this._wrapCompartment = new Compartment();
|
|
108
|
+
this._diffCompartment = new Compartment();
|
|
109
|
+
this._wordCompartment = new Compartment();
|
|
90
110
|
this._languagePending = Promise.resolve();
|
|
111
|
+
this._wordsPending = Promise.resolve();
|
|
112
|
+
/** The parsed diff on screen, or null without `diff`. */
|
|
113
|
+
this._parsedDiff = null;
|
|
91
114
|
}
|
|
92
115
|
/* The copy button only renders when the user hasn't opted out (no-copy) AND
|
|
93
116
|
* the Clipboard API can actually work here (secure context). Off https the
|
|
@@ -96,7 +119,7 @@ let NLDDCodeViewer = class NLDDCodeViewer extends NLDDCodeMirrorElement {
|
|
|
96
119
|
return !this.noCopy && isClipboardAvailable();
|
|
97
120
|
}
|
|
98
121
|
getEditorParent() {
|
|
99
|
-
return this.shadowRoot?.querySelector('.code-
|
|
122
|
+
return this.shadowRoot?.querySelector('.code-viewer__codemirror');
|
|
100
123
|
}
|
|
101
124
|
buildExtensions() {
|
|
102
125
|
return [
|
|
@@ -119,6 +142,8 @@ let NLDDCodeViewer = class NLDDCodeViewer extends NLDDCodeMirrorElement {
|
|
|
119
142
|
}),
|
|
120
143
|
this._wrapCompartment.of(this.wrap ? EditorView.lineWrapping : []),
|
|
121
144
|
this._languageCompartment.of([]),
|
|
145
|
+
this._diffCompartment.of(this._parsedDiff ? this._diffExtension(this._parsedDiff) : []),
|
|
146
|
+
this._wordCompartment.of([]),
|
|
122
147
|
];
|
|
123
148
|
}
|
|
124
149
|
render() {
|
|
@@ -139,7 +164,8 @@ let NLDDCodeViewer = class NLDDCodeViewer extends NLDDCodeMirrorElement {
|
|
|
139
164
|
* detach/reattach re-mount from the live slotted text so changed content
|
|
140
165
|
* (swapped while detached) shows, rather than the doc captured on disconnect. */
|
|
141
166
|
getRemountDoc() {
|
|
142
|
-
|
|
167
|
+
this._parsedDiff = this.diff ? parseUnifiedDiff(this._getRawText()) : null;
|
|
168
|
+
return this._parsedDiff?.doc ?? this._getRawText();
|
|
143
169
|
}
|
|
144
170
|
connectedCallback() {
|
|
145
171
|
super.connectedCallback();
|
|
@@ -167,7 +193,8 @@ let NLDDCodeViewer = class NLDDCodeViewer extends NLDDCodeMirrorElement {
|
|
|
167
193
|
// Suppress the copy button up front where the Clipboard API can't work, so
|
|
168
194
|
// the reserved actions space is dropped on the first paint too.
|
|
169
195
|
this._copyUnavailable = !this.noCopy && !isClipboardAvailable();
|
|
170
|
-
this.
|
|
196
|
+
this._parsedDiff = this.diff ? parseUnifiedDiff(this._getRawText()) : null;
|
|
197
|
+
this.mountEditor(this._parsedDiff?.doc ?? this._getRawText());
|
|
171
198
|
this.onEditorMounted();
|
|
172
199
|
}
|
|
173
200
|
/* slotchange fires when the slot's assigned nodes change, but a framework that
|
|
@@ -209,6 +236,7 @@ let NLDDCodeViewer = class NLDDCodeViewer extends NLDDCodeMirrorElement {
|
|
|
209
236
|
this._observeSlotText();
|
|
210
237
|
if (this.language)
|
|
211
238
|
this._applyLanguage();
|
|
239
|
+
this._applyWords();
|
|
212
240
|
this._updateScrollable();
|
|
213
241
|
}
|
|
214
242
|
updated(changed) {
|
|
@@ -234,6 +262,12 @@ let NLDDCodeViewer = class NLDDCodeViewer extends NLDDCodeMirrorElement {
|
|
|
234
262
|
this.view.scrollDOM.setAttribute('aria-label', this._t('components.code-viewer.region-label'));
|
|
235
263
|
if (changed.has('language'))
|
|
236
264
|
this._applyLanguage();
|
|
265
|
+
if (changed.has('diff') && changed.get('diff') !== undefined)
|
|
266
|
+
this._applyContent();
|
|
267
|
+
// The line labels follow a language switch of the texts.
|
|
268
|
+
if (changed.has('translations') && changed.get('translations') !== undefined && this._parsedDiff) {
|
|
269
|
+
this.reconfigure(this._diffCompartment, this._diffExtension(this._parsedDiff));
|
|
270
|
+
}
|
|
237
271
|
if (changed.has('wrap')) {
|
|
238
272
|
this.reconfigure(this._wrapCompartment, this.wrap ? EditorView.lineWrapping : []);
|
|
239
273
|
this._updateScrollable();
|
|
@@ -250,11 +284,65 @@ let NLDDCodeViewer = class NLDDCodeViewer extends NLDDCodeMirrorElement {
|
|
|
250
284
|
}
|
|
251
285
|
}
|
|
252
286
|
_onSlotChange() {
|
|
253
|
-
this.
|
|
287
|
+
this._applyContent();
|
|
288
|
+
}
|
|
289
|
+
/* The slot holds the source. Without `diff` it is the document; with it, the
|
|
290
|
+
* document is the code the diff changes, and the diff decorations come along
|
|
291
|
+
* in the same transaction, so no line is ever drawn against the wrong text. */
|
|
292
|
+
_applyContent() {
|
|
293
|
+
const view = this.view;
|
|
294
|
+
if (!view)
|
|
295
|
+
return;
|
|
296
|
+
const raw = this._getRawText();
|
|
297
|
+
this._parsedDiff = this.diff ? parseUnifiedDiff(raw) : null;
|
|
298
|
+
const doc = this._parsedDiff?.doc ?? raw;
|
|
299
|
+
view.dispatch({
|
|
300
|
+
changes: view.state.doc.toString() === doc ? undefined : { from: 0, to: view.state.doc.length, insert: doc },
|
|
301
|
+
effects: [
|
|
302
|
+
this._diffCompartment.reconfigure(this._parsedDiff ? this._diffExtension(this._parsedDiff) : []),
|
|
303
|
+
this._wordCompartment.reconfigure([]),
|
|
304
|
+
],
|
|
305
|
+
});
|
|
306
|
+
this._applyWords();
|
|
254
307
|
this._updateScrollable();
|
|
308
|
+
this.requestUpdate();
|
|
255
309
|
}
|
|
256
|
-
|
|
257
|
-
return
|
|
310
|
+
_diffExtension(parsed) {
|
|
311
|
+
return diffExtensions(parsed, {
|
|
312
|
+
addedLine: (number) => this._t('components.code-viewer.added-line-label', { number }),
|
|
313
|
+
removedLine: (number) => this._t('components.code-viewer.removed-line-label', { number }),
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
_applyWords() {
|
|
317
|
+
const parsed = this._parsedDiff;
|
|
318
|
+
if (!parsed)
|
|
319
|
+
return;
|
|
320
|
+
this._wordsPending = wordExtensions(parsed).then((words) => {
|
|
321
|
+
// The content may have changed while the diff module was loading.
|
|
322
|
+
if (this._parsedDiff === parsed)
|
|
323
|
+
this.reconfigure(this._wordCompartment, words);
|
|
324
|
+
},
|
|
325
|
+
// The diff still shows without them, so a failed load is no error.
|
|
326
|
+
(error) => {
|
|
327
|
+
if (import.meta.env?.DEV)
|
|
328
|
+
console.warn('<nldd-code-viewer>: the word marks of a diff need @codemirror/merge, which did not load, so the diff shows without them.', error);
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
/** The summary a screen reader hears before a diff. */
|
|
332
|
+
get _diffSummary() {
|
|
333
|
+
const parsed = this._parsedDiff;
|
|
334
|
+
if (!parsed)
|
|
335
|
+
return '';
|
|
336
|
+
const noun = (count) => this._t(count === 1 ? 'components.code-viewer.line-singular-lowercase' : 'components.code-viewer.line-plural-lowercase');
|
|
337
|
+
return this._t('components.code-viewer.diff-summary-text', {
|
|
338
|
+
added: parsed.added,
|
|
339
|
+
addedNoun: noun(parsed.added),
|
|
340
|
+
removed: parsed.removed,
|
|
341
|
+
removedNoun: noun(parsed.removed),
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
_t(key, vars) {
|
|
345
|
+
return translate(this.translations, nlddCodeViewerTranslations, key, vars);
|
|
258
346
|
}
|
|
259
347
|
/* Lazy grammar loading is async; surface the in-flight load through
|
|
260
348
|
* updateComplete so consumers (and tests) can await el.updateComplete and
|
|
@@ -262,6 +350,7 @@ let NLDDCodeViewer = class NLDDCodeViewer extends NLDDCodeMirrorElement {
|
|
|
262
350
|
async getUpdateComplete() {
|
|
263
351
|
const result = await super.getUpdateComplete();
|
|
264
352
|
await this._languagePending;
|
|
353
|
+
await this._wordsPending;
|
|
265
354
|
return result;
|
|
266
355
|
}
|
|
267
356
|
_applyLanguage() {
|
|
@@ -386,6 +475,9 @@ __decorate([
|
|
|
386
475
|
__decorate([
|
|
387
476
|
property({ reflect: true, converter: reflectNonDefault('') })
|
|
388
477
|
], NLDDCodeViewer.prototype, "language", void 0);
|
|
478
|
+
__decorate([
|
|
479
|
+
property({ type: Boolean, reflect: true })
|
|
480
|
+
], NLDDCodeViewer.prototype, "diff", void 0);
|
|
389
481
|
__decorate([
|
|
390
482
|
property({ type: Boolean, reflect: true, attribute: 'no-copy' })
|
|
391
483
|
], NLDDCodeViewer.prototype, "noCopy", void 0);
|