@nldd/design-system 0.11.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.
Files changed (142) hide show
  1. package/custom-elements.json +2188 -621
  2. package/dist/components/components.js +2475 -1602
  3. package/dist/components/content/code-viewer/code-viewer.d.ts +14 -1
  4. package/dist/components/content/code-viewer/code-viewer.d.ts.map +1 -1
  5. package/dist/components/content/code-viewer/code-viewer.diff.d.ts +40 -0
  6. package/dist/components/content/code-viewer/code-viewer.diff.d.ts.map +1 -0
  7. package/dist/components/content/code-viewer/code-viewer.diff.js +261 -0
  8. package/dist/components/content/code-viewer/code-viewer.diff.js.map +1 -0
  9. package/dist/components/content/code-viewer/code-viewer.i18n.d.ts +5 -0
  10. package/dist/components/content/code-viewer/code-viewer.i18n.d.ts.map +1 -1
  11. package/dist/components/content/code-viewer/code-viewer.i18n.js +9 -0
  12. package/dist/components/content/code-viewer/code-viewer.i18n.js.map +1 -1
  13. package/dist/components/content/code-viewer/code-viewer.js +98 -6
  14. package/dist/components/content/code-viewer/code-viewer.js.map +1 -1
  15. package/dist/components/content/code-viewer/code-viewer.styles.d.ts.map +1 -1
  16. package/dist/components/content/code-viewer/code-viewer.styles.js +134 -1
  17. package/dist/components/content/code-viewer/code-viewer.styles.js.map +1 -1
  18. package/dist/components/content/code-viewer/code-viewer.template.d.ts.map +1 -1
  19. package/dist/components/content/code-viewer/code-viewer.template.js +5 -4
  20. package/dist/components/content/code-viewer/code-viewer.template.js.map +1 -1
  21. package/dist/components/content/icon/icon-aliases.d.ts.map +1 -1
  22. package/dist/components/content/icon/icon-aliases.js +13 -4
  23. package/dist/components/content/icon/icon-aliases.js.map +1 -1
  24. package/dist/components/content/icon/icon-gallery-status.d.ts.map +1 -1
  25. package/dist/components/content/icon/icon-gallery-status.js +9 -0
  26. package/dist/components/content/icon/icon-gallery-status.js.map +1 -1
  27. package/dist/components/content/icon/icon-registry.d.ts.map +1 -1
  28. package/dist/components/content/icon/icon-registry.js +9 -2
  29. package/dist/components/content/icon/icon-registry.js.map +1 -1
  30. package/dist/components/content/rich-text/rich-text.d.ts +10 -0
  31. package/dist/components/content/rich-text/rich-text.d.ts.map +1 -1
  32. package/dist/components/content/rich-text/rich-text.js +10 -0
  33. package/dist/components/content/rich-text/rich-text.js.map +1 -1
  34. package/dist/components/{dist-Bo5Jeyfn.js → dist-B5E3q-ea.js} +2 -1
  35. package/dist/components/{dist-DbNhCpS5.js → dist-BFw_yEMS.js} +2 -1
  36. package/dist/components/{dist-DnZmcpbQ.js → dist-BNLAXAyO.js} +2 -1
  37. package/dist/components/{dist-DkqAbJH8.js → dist-BOVSVPSz.js} +1 -1
  38. package/dist/components/{dist-Ch3gNAuT.js → dist-BPB3rWnd.js} +2 -1
  39. package/dist/components/{dist-Bud_7w5g.js → dist-BWlUmyq3.js} +34 -2869
  40. package/dist/components/dist-CC8oiVtm.js +366 -0
  41. package/dist/components/dist-COKR0tYU.js +2860 -0
  42. package/dist/components/{dist-CaxHkqR2.js → dist-Co-tsc9S.js} +4 -3
  43. package/dist/components/{dist-iC2RTM0V.js → dist-D_9ZyZ5v.js} +3 -2
  44. package/dist/components/{dist-BB5mlo7D.js → dist-Dn9pjiud.js} +3 -2
  45. package/dist/components/{dist-B2QcygzG.js → dist-Dz28se9B.js} +2 -1
  46. package/dist/components/{dist-CA0yDFIt.js → dist-IPm8ilWf.js} +3 -2
  47. package/dist/components/{icon-zNX9A6d3.js → icon-DFhgRf3P.js} +18 -6
  48. package/dist/components/{icon-button-Cntrg4_E.js → icon-button-Sxkh5cVr.js} +1 -1
  49. package/dist/components/inputs/code-editor/code-editor.d.ts +4 -54
  50. package/dist/components/inputs/code-editor/code-editor.d.ts.map +1 -1
  51. package/dist/components/inputs/code-editor/code-editor.js +22 -262
  52. package/dist/components/inputs/code-editor/code-editor.js.map +1 -1
  53. package/dist/components/inputs/code-editor/code-editor.styles.d.ts.map +1 -1
  54. package/dist/components/inputs/code-editor/code-editor.styles.js +7 -0
  55. package/dist/components/inputs/code-editor/code-editor.styles.js.map +1 -1
  56. package/dist/components/inputs/text-editor/text-editor.annotation-sentinels.d.ts.map +1 -1
  57. package/dist/components/inputs/text-editor/text-editor.annotation-sentinels.js +9 -7
  58. package/dist/components/inputs/text-editor/text-editor.annotation-sentinels.js.map +1 -1
  59. package/dist/components/inputs/text-editor/text-editor.annotations.js +1 -1
  60. package/dist/components/inputs/text-editor/text-editor.annotations.js.map +1 -1
  61. package/dist/components/inputs/text-editor/text-editor.clipboard.d.ts +16 -0
  62. package/dist/components/inputs/text-editor/text-editor.clipboard.d.ts.map +1 -0
  63. package/dist/components/inputs/text-editor/text-editor.clipboard.js +50 -0
  64. package/dist/components/inputs/text-editor/text-editor.clipboard.js.map +1 -0
  65. package/dist/components/inputs/text-editor/text-editor.commands.d.ts.map +1 -1
  66. package/dist/components/inputs/text-editor/text-editor.commands.js +31 -58
  67. package/dist/components/inputs/text-editor/text-editor.commands.js.map +1 -1
  68. package/dist/components/inputs/text-editor/text-editor.d.ts +17 -64
  69. package/dist/components/inputs/text-editor/text-editor.d.ts.map +1 -1
  70. package/dist/components/inputs/text-editor/text-editor.drag.d.ts.map +1 -1
  71. package/dist/components/inputs/text-editor/text-editor.drag.js +2 -1
  72. package/dist/components/inputs/text-editor/text-editor.drag.js.map +1 -1
  73. package/dist/components/inputs/text-editor/text-editor.focus-selection.d.ts +3 -0
  74. package/dist/components/inputs/text-editor/text-editor.focus-selection.d.ts.map +1 -0
  75. package/dist/components/inputs/text-editor/text-editor.focus-selection.js +55 -0
  76. package/dist/components/inputs/text-editor/text-editor.focus-selection.js.map +1 -0
  77. package/dist/components/inputs/text-editor/text-editor.hidden-syntax.d.ts +6 -0
  78. package/dist/components/inputs/text-editor/text-editor.hidden-syntax.d.ts.map +1 -0
  79. package/dist/components/inputs/text-editor/text-editor.hidden-syntax.js +257 -0
  80. package/dist/components/inputs/text-editor/text-editor.hidden-syntax.js.map +1 -0
  81. package/dist/components/inputs/text-editor/text-editor.js +93 -313
  82. package/dist/components/inputs/text-editor/text-editor.js.map +1 -1
  83. package/dist/components/inputs/text-editor/text-editor.keymap.d.ts +6 -0
  84. package/dist/components/inputs/text-editor/text-editor.keymap.d.ts.map +1 -0
  85. package/dist/components/inputs/text-editor/text-editor.keymap.js +38 -0
  86. package/dist/components/inputs/text-editor/text-editor.keymap.js.map +1 -0
  87. package/dist/components/inputs/text-editor/text-editor.links.d.ts.map +1 -1
  88. package/dist/components/inputs/text-editor/text-editor.links.js +11 -9
  89. package/dist/components/inputs/text-editor/text-editor.links.js.map +1 -1
  90. package/dist/components/inputs/text-editor/text-editor.markdown.d.ts +1 -17
  91. package/dist/components/inputs/text-editor/text-editor.markdown.d.ts.map +1 -1
  92. package/dist/components/inputs/text-editor/text-editor.markdown.js +26 -186
  93. package/dist/components/inputs/text-editor/text-editor.markdown.js.map +1 -1
  94. package/dist/components/inputs/text-editor/text-editor.mention.d.ts +52 -0
  95. package/dist/components/inputs/text-editor/text-editor.mention.d.ts.map +1 -0
  96. package/dist/components/inputs/text-editor/text-editor.mention.js +186 -0
  97. package/dist/components/inputs/text-editor/text-editor.mention.js.map +1 -0
  98. package/dist/components/inputs/text-editor/text-editor.mentions.d.ts +0 -16
  99. package/dist/components/inputs/text-editor/text-editor.mentions.d.ts.map +1 -1
  100. package/dist/components/inputs/text-editor/text-editor.mentions.js +1 -41
  101. package/dist/components/inputs/text-editor/text-editor.mentions.js.map +1 -1
  102. package/dist/components/inputs/text-editor/text-editor.selection.d.ts +13 -0
  103. package/dist/components/inputs/text-editor/text-editor.selection.d.ts.map +1 -0
  104. package/dist/components/inputs/text-editor/text-editor.selection.js +62 -0
  105. package/dist/components/inputs/text-editor/text-editor.selection.js.map +1 -0
  106. package/dist/components/inputs/text-editor/text-editor.spellcheck.d.ts.map +1 -1
  107. package/dist/components/inputs/text-editor/text-editor.spellcheck.js +4 -6
  108. package/dist/components/inputs/text-editor/text-editor.spellcheck.js.map +1 -1
  109. package/dist/components/inputs/text-editor/text-editor.styles.d.ts.map +1 -1
  110. package/dist/components/inputs/text-editor/text-editor.styles.js +172 -54
  111. package/dist/components/inputs/text-editor/text-editor.styles.js.map +1 -1
  112. package/dist/components/inputs/text-editor/text-editor.syntax.d.ts +22 -0
  113. package/dist/components/inputs/text-editor/text-editor.syntax.d.ts.map +1 -1
  114. package/dist/components/inputs/text-editor/text-editor.syntax.js +44 -0
  115. package/dist/components/inputs/text-editor/text-editor.syntax.js.map +1 -1
  116. package/dist/components/status-and-feedback/notification/notification.d.ts +2 -1
  117. package/dist/components/status-and-feedback/notification/notification.d.ts.map +1 -1
  118. package/dist/components/status-and-feedback/notification/notification.js +5 -2
  119. package/dist/components/status-and-feedback/notification/notification.js.map +1 -1
  120. package/dist/components/status-and-feedback/notification/notification.styles.d.ts.map +1 -1
  121. package/dist/components/status-and-feedback/notification/notification.styles.js +18 -0
  122. package/dist/components/status-and-feedback/notification/notification.styles.js.map +1 -1
  123. package/dist/components/status-and-feedback/notification/notifications-area.d.ts.map +1 -1
  124. package/dist/components/status-and-feedback/notification/notifications-area.js +14 -0
  125. package/dist/components/status-and-feedback/notification/notifications-area.js.map +1 -1
  126. package/dist/css/rich-text.css +61 -1
  127. package/dist/css/themes/donkergeel.css +7 -3
  128. package/dist/css/themes/geel.css +7 -3
  129. package/dist/css/themes.css +14 -6
  130. package/dist/css/variables.css +10 -4
  131. package/dist/nldd.min.js +853 -557
  132. package/dist/translations/en-US.d.ts.map +1 -1
  133. package/dist/translations/en-US.js +5 -0
  134. package/dist/translations/en-US.js.map +1 -1
  135. package/dist/translations/nl.generated.d.ts +5 -0
  136. package/dist/translations/nl.generated.d.ts.map +1 -1
  137. package/dist/types/vue.d.ts +34 -30
  138. package/dist/utilities/codemirror/codemirror-input.d.ts +90 -0
  139. package/dist/utilities/codemirror/codemirror-input.d.ts.map +1 -0
  140. package/dist/utilities/codemirror/codemirror-input.js +250 -0
  141. package/dist/utilities/codemirror/codemirror-input.js.map +1 -0
  142. package/package.json +2 -1
@@ -33,8 +33,14 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
33
33
  * text) writes at the same clean offsets getSelection() reads. An @-mention typeahead
34
34
  * (mentionSource) collapses to an atomic token, further typeahead lists on their
35
35
  * own trigger (typeaheads) write what you tell them to, and a W3C-style annotation overlay
36
- * (annotations) marks ranges with a dashed underline, light tint and a count badge
37
- * without touching the underlying text.
36
+ * (annotations) marks ranges with a light tint and a count badge without touching
37
+ * the underlying text.
38
+ *
39
+ * To show the value, render the markdown into nldd-rich-text, which uses the
40
+ * same type, bold and code as the editor. A mention is stored as
41
+ * `[@Name](user:id)`: turn it into `<a href="…" data-mention>Name</a>` (or a
42
+ * `span` when there is no page for the person), without the `@`. A link reads
43
+ * as the same token there; a span keeps the color and the icon without the tint.
38
44
  *
39
45
  * @element nldd-text-editor
40
46
  *
@@ -50,6 +56,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
50
56
  * @attr {number} rows - Minimum visible rows (the floor in every resize mode). Default: 6.
51
57
  * @attr {string} resize - 'none' (fixed) | 'vertical' (drag) | 'auto' (grow, default)
52
58
  * @attr {string} appearance - 'simple' (default, bare) | 'input-field' (framed surface)
59
+ * @attr {string} syntax - 'visible' (default): every formatting mark stays in view, dimmed, a bullet as the character you typed (`-`, `*` or `+`). 'hidden': the marks of bold, italic, strikethrough, inline code, links and the `#` of a heading are hidden and come back where the caret or the selection touches that construct, so the text reads closer to the result while what you edit is still the markdown. A bullet reads as a dot, and shows its character on the line the caret is on. A quote reads as a line on the left; with the caret anywhere in it, its `>` marks show instead, in the same place. A `---` line reads as a divider until the caret is on it, and a code block loses its ``` fence lines until the caret is in it, since its own tint and edge already say what it is. The numbers of a numbered list stay: they are content. Read-only and disabled hide every mark, which makes a clean read view. The value is plain markdown either way.
53
60
  * @attr {string} accessible-label - Accessible label forwarded to the editor. Set automatically by nldd-form-field.
54
61
  *
55
62
  * @prop {MentionSource} mentionSource - Consumer-supplied @-mention candidate source (property only). Without it, @-typeahead is inert.
@@ -69,52 +76,44 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
69
76
  * @fires nldd-text-editor-annotation-click - When an annotation's count badge is clicked (detail: { ids: string[], rect: DOMRect }); rect is the badge's viewport box so a consumer can anchor its own note UI to it
70
77
  */
71
78
  import { relabel } from './text-editor.labels.js';
72
- import { LitElement } from 'lit';
73
79
  import { customElement, property, query } from 'lit/decorators.js';
74
- import { FormAssociated } from '../../../utilities/form-associated-mixin.js';
75
80
  import { reflectNonDefault } from '../../../utilities/reflect-non-default.js';
76
- import { EditorView, keymap, drawSelection, dropCursor, placeholder as cmPlaceholder, } from '@codemirror/view';
77
- import { Compartment, EditorState, Prec, Transaction } from '@codemirror/state';
78
- import { defaultKeymap, deleteCharBackward, deleteCharForward, history, historyKeymap, undo as cmUndo, redo as cmRedo, undoDepth, redoDepth } from '@codemirror/commands';
79
- import { NLDDCodeMirrorElement } from '../../../utilities/codemirror/codemirror-element.js';
81
+ import { EditorView, drawSelection, dropCursor } from '@codemirror/view';
82
+ import { Compartment, Prec, Transaction } from '@codemirror/state';
83
+ import { history, undo as cmUndo, redo as cmRedo, undoDepth, redoDepth } from '@codemirror/commands';
84
+ import { NLDDCodeMirrorInput } from '../../../utilities/codemirror/codemirror-input.js';
80
85
  import { nlddCodeMirrorTheme } from '../../../utilities/codemirror/theme.js';
81
- import { markdownEditing, mentionRangeAt, mentionRangeEndingAt, mentionRangeStartingAt } from './text-editor.markdown.js';
82
- import { typeaheads as typeaheadExtension, mentionInsert, mentionToken, } from './text-editor.mentions.js';
86
+ import { markdownEditing } from './text-editor.markdown.js';
87
+ import { mentionInsert, mentionToken, mentionRangeAt } from './text-editor.mention.js';
88
+ import { typeaheads as typeaheadExtension, } from './text-editor.mentions.js';
83
89
  import { repairHeldEmphasis } from './text-editor.emphasis.js';
84
- import { spellcheck, leaveDeletionToBrowser } from './text-editor.spellcheck.js';
85
- import { annotations as annotationExtension, setAnnotations, pasteAnnotations, currentAnnotations } from './text-editor.annotations.js';
90
+ import { spellcheck } from './text-editor.spellcheck.js';
91
+ import { annotations as annotationExtension, setAnnotations, currentAnnotations } from './text-editor.annotations.js';
92
+ import { AnnotationClipboard } from './text-editor.clipboard.js';
93
+ import { textEditorKeymap } from './text-editor.keymap.js';
86
94
  import { orderedListRenumber } from './text-editor.ordered-list.js';
87
95
  import { dragToMove, dragMovePlugin } from './text-editor.drag.js';
88
96
  import { linkOpenBadge } from './text-editor.links.js';
89
97
  import { stableCursor } from './text-editor.cursor.js';
90
- import { toggleInlineWrap, indentListItems as cmIndentListItems, outdentListItems as cmOutdentListItems, canIndentListItem as cmCanIndent, canOutdentListItem as cmCanOutdent, toggleHeading as cmToggleHeading, setHeading as cmSetHeading, toggleBulletList as cmToggleBulletList, toggleTaskList as cmToggleTaskList, setList as cmSetList, toggleQuote as cmToggleQuote, toggleLink as cmToggleLink, toggleCodeBlock as cmToggleCodeBlock, clearListMarkerBackward, readActiveFormats, EMPTY_FORMATS, } from './text-editor.commands.js';
98
+ import { focusSelectionGuard } from './text-editor.focus-selection.js';
99
+ import { hiddenSyntax } from './text-editor.hidden-syntax.js';
100
+ import { lineHighSelection } from './text-editor.selection.js';
101
+ import { toggleInlineWrap, indentListItems as cmIndentListItems, outdentListItems as cmOutdentListItems, canIndentListItem as cmCanIndent, canOutdentListItem as cmCanOutdent, toggleHeading as cmToggleHeading, setHeading as cmSetHeading, toggleBulletList as cmToggleBulletList, toggleTaskList as cmToggleTaskList, setList as cmSetList, toggleQuote as cmToggleQuote, toggleLink as cmToggleLink, toggleCodeBlock as cmToggleCodeBlock, readActiveFormats, EMPTY_FORMATS, } from './text-editor.commands.js';
91
102
  import { textEditorStyles } from './text-editor.styles.js';
92
103
  import { textEditorTemplate } from './text-editor.template.js';
93
104
  import { stripSentinels, docToClean, cleanToDoc, sentinelPositions } from './text-editor.annotation-sentinels.js';
94
105
  import { nlddTextEditorTranslations } from './text-editor.i18n.js';
95
- import { DescribedBy } from '../../../utilities/described-by-mixin.js';
96
106
  import { translate } from '../../../utilities/translations.js';
97
107
  export { DEFAULT_TYPEAHEAD_QUERY } from './text-editor.mentions.js';
98
- let NLDDTextEditor = class NLDDTextEditor extends DescribedBy(FormAssociated(NLDDCodeMirrorElement)) {
108
+ let NLDDTextEditor = class NLDDTextEditor extends NLDDCodeMirrorInput {
99
109
  constructor() {
100
110
  super(...arguments);
101
- this._initialValue = '';
102
- this._valueAtFocus = '';
103
- this._accessibleLabelWarned = false;
104
- this.value = '';
105
- this.inputId = '';
106
- this.placeholder = '';
107
- this.disabled = false;
108
- this.name = '';
109
- this.readonly = false;
110
- this.required = false;
111
111
  /** Turns spellchecking off. On by default, without code, URLs and mentions. */
112
112
  this.noSpellcheck = false;
113
113
  this.wrap = true;
114
- this.rows = 6;
115
114
  this.resize = 'auto';
116
115
  this.appearance = 'simple';
117
- this.accessibleLabel = '';
116
+ this.syntax = 'visible';
118
117
  /** Your own typeahead lists next to the @-mention, each on its own trigger
119
118
  * character. Property only. Read on every keystroke, so a new array takes
120
119
  * effect at once. */
@@ -152,42 +151,20 @@ let NLDDTextEditor = class NLDDTextEditor extends DescribedBy(FormAssociated(NLD
152
151
  * open-in-new-tab link badge and the annotation count badge). Unset keys fall
153
152
  * back to Dutch. */
154
153
  this.translations = {};
155
- this._editableCompartment = new Compartment();
154
+ this.rowsProperty = '--_text-editor-rows';
156
155
  this._wrapCompartment = new Compartment();
157
- this._placeholderCompartment = new Compartment();
158
- this._attrsCompartment = new Compartment();
159
156
  this._spellcheckCompartment = new Compartment();
160
157
  this._historyCompartment = new Compartment();
161
- /**
162
- * Marks the control as invalid.
163
- *
164
- * Announced and not drawn. What is wrong belongs in an
165
- * nldd-validation-list, in words: a red ring around a single
166
- * checkbox or radio would say the option is wrong, while it is the question
167
- * that is unanswered. `aria-invalid` still goes on the control, because
168
- * choosing not to show something is not a reason to keep quiet about it.
169
- */
170
- this.invalid = false;
158
+ this._syntaxCompartment = new Compartment();
171
159
  this._labels = null;
172
- /** Text and annotations of the last cut, so a same-editor paste can move the
173
- * annotations along with their text. Cleared by copy and by a matching paste. */
174
- this._cutBuffer = null;
160
+ /** Carries the annotations of a cut along to a paste of the same text. */
161
+ this._clipboard = new AnnotationClipboard();
175
162
  /** The last state handed out, to keep from repeating it. The event drives a
176
163
  * toolbar's toggles, and moving the caret within one paragraph leaves every
177
164
  * one of them where it was: a consumer would re-render its whole bar on every
178
165
  * arrow key for nothing. */
179
166
  this._lastState = null;
180
167
  /* # Internals */
181
- this._onScrollerPointerDown = (event) => {
182
- if (event.target !== this.view?.scrollDOM)
183
- return;
184
- // No caret to move on a read-only/disabled view — leave the press alone, like
185
- // the drag path (which early-returns on state.readOnly).
186
- if (this.view.state.readOnly)
187
- return;
188
- this.focusFromPoint(event.clientX, event.clientY);
189
- event.preventDefault();
190
- };
191
168
  this._onMentionPointerDown = (event) => {
192
169
  const token = event.target?.closest?.('.cm-md-mention-token');
193
170
  if (!token || !this.view)
@@ -271,60 +248,27 @@ let NLDDTextEditor = class NLDDTextEditor extends DescribedBy(FormAssociated(NLD
271
248
  Prec.highest(linkOpenBadge((url) => this._t('components.text-editor.open-in-new-tab-label', { url }))),
272
249
  this._historyCompartment.of(history()),
273
250
  drawSelection(),
251
+ // As tall as the line, like the tokens. See text-editor.selection.ts.
252
+ lineHighSelection,
274
253
  // Draws the caret in drawSelection's place, on a side that does not depend on
275
254
  // the direction it arrived from unless that direction means something (a
276
255
  // widget, a line wrap). See text-editor.cursor.ts.
277
256
  stableCursor,
257
+ // Safari can stretch the selection to the start when focus comes back
258
+ // from a toolbar. See text-editor.focus-selection.ts.
259
+ focusSelectionGuard(),
278
260
  dropCursor(),
279
261
  dragToMove,
280
- // Prec.highest so this beats the markdown language's deleteMarkupBackward,
281
- // which would otherwise leave alignment whitespace when a non-first list
282
- // marker is backspaced. Falls through (returns false) off a list marker.
283
- Prec.highest(keymap.of([{ key: 'Backspace', run: clearListMarkerBackward }])),
284
- keymap.of([
285
- { key: 'Mod-b', run: (view) => { toggleInlineWrap(view, '**', 'StrongEmphasis'); return true; } },
286
- { key: 'Mod-i', run: (view) => { toggleInlineWrap(view, '*', 'Emphasis'); return true; } },
287
- { key: 'Mod-e', run: (view) => { toggleInlineWrap(view, '`', 'InlineCode'); return true; } },
288
- { key: 'Mod-k', run: (view) => { cmToggleLink(view); return true; } },
289
- // A mention deletes in two steps: the first Backspace/Delete next to it
290
- // selects the whole token, the second removes it.
291
- { key: 'Backspace', run: (view) => this._selectMentionBeforeDelete(view, -1) },
292
- { key: 'Delete', run: (view) => this._selectMentionBeforeDelete(view, 1) },
293
- // Cmd/Ctrl+] and +[ nest and un-nest list items. defaultKeymap binds them
294
- // to indentMore/indentLess, whose four-space indent turns plain text into
295
- // an indented code block. Consumed here in every case: off a list item
296
- // they do nothing, which beats a code block nobody asked for.
297
- { key: 'Mod-]', run: (view) => { cmIndentListItems(view); return true; } },
298
- { key: 'Mod-[', run: (view) => { cmOutdentListItems(view); return true; } },
299
- // The browser deletes where the editor has nothing to add, so the
300
- // spelling marks on the line stay (see leaveDeletionToBrowser).
301
- { key: 'Backspace', run: (view) => !leaveDeletionToBrowser(view, 'Backspace') && deleteCharBackward(view), shift: deleteCharBackward },
302
- { key: 'Delete', run: (view) => !leaveDeletionToBrowser(view, 'Delete') && deleteCharForward(view) },
303
- ...defaultKeymap.filter((binding) => binding.key !== 'Backspace' && binding.key !== 'Delete'),
304
- ...historyKeymap,
305
- ]),
306
- this._placeholderCompartment.of(this._placeholderExtension()),
262
+ textEditorKeymap,
263
+ ...this.inputExtensions(),
307
264
  this._wrapCompartment.of(this.wrap ? EditorView.lineWrapping : []),
308
- this._editableCompartment.of(this._editableExtension()),
309
- this._attrsCompartment.of(this._attrsExtension()),
310
265
  this._spellcheckCompartment.of(this.noSpellcheck ? [] : spellcheck()),
266
+ this._syntaxCompartment.of(this.syntax === 'hidden' ? hiddenSyntax() : []),
311
267
  EditorView.updateListener.of((u) => {
312
- if (u.docChanged)
313
- this._onDocChanged();
314
268
  if (u.docChanged || u.selectionSet)
315
269
  this._emitState();
316
270
  }),
317
271
  EditorView.domEventHandlers({
318
- focus: () => {
319
- this._valueAtFocus = this.value;
320
- },
321
- blur: (_event, view) => {
322
- // An emphasis held together while it was being typed is closed
323
- // properly first, so the committed value renders the way it looked.
324
- repairHeldEmphasis(view);
325
- if (this.value !== this._valueAtFocus)
326
- this._emitChange();
327
- },
328
272
  // Triple-click selects the whole paragraph (the doc line), like macOS.
329
273
  // CM's own triple-click stops at the visual line, which under wrapping is
330
274
  // just one wrapped row.
@@ -342,35 +286,24 @@ let NLDDTextEditor = class NLDDTextEditor extends DescribedBy(FormAssociated(NLD
342
286
  // Native Cmd/Ctrl+X/C/V go through these DOM events, not the toolbar's
343
287
  // methods, so mirror the annotation-carrying logic here too.
344
288
  cut: (_event, view) => {
345
- const { from, to } = view.state.selection.main;
346
- this._cutBuffer = from === to
347
- ? null
348
- : { text: stripSentinels(view.state.sliceDoc(from, to)), anns: this._annotationsInSelection() };
289
+ this._clipboard.rememberCut(view);
349
290
  return false; // let CodeMirror perform the actual cut (clipboard + delete)
350
291
  },
351
292
  copy: () => {
352
- this._cutBuffer = null; // a plain copy must not carry a pending cut's annotations
293
+ this._clipboard.forget();
353
294
  return false;
354
295
  },
355
- paste: (event) => {
296
+ paste: (event, view) => {
356
297
  const raw = event.clipboardData?.getData('text/plain');
357
298
  if (raw === undefined)
358
299
  return false; // no clipboard data — let CodeMirror handle it
359
- this._pasteText(stripSentinels(raw));
300
+ this._clipboard.paste(view, raw);
360
301
  event.preventDefault();
361
302
  return true;
362
303
  },
363
304
  }),
364
305
  ];
365
306
  }
366
- _editableExtension() {
367
- const editable = !this.disabled;
368
- const readOnly = this.disabled || this.readonly;
369
- return [EditorView.editable.of(editable), EditorState.readOnly.of(readOnly)];
370
- }
371
- _placeholderExtension() {
372
- return this.placeholder ? cmPlaceholder(this.placeholder) : [];
373
- }
374
307
  /**
375
308
  * A browser checks text when it changes, not when `spellcheck` does: turned
376
309
  * off, the red underlines stayed until the text under them was edited, and
@@ -387,34 +320,30 @@ let NLDDTextEditor = class NLDDTextEditor extends DescribedBy(FormAssociated(NLD
387
320
  if (focused)
388
321
  view.focus();
389
322
  }
390
- _attrsExtension() {
391
- // Autocorrect and autocapitalize follow the user's own settings, as on an
392
- // <input> or a <textarea>, also with no-spellcheck: CodeMirror's "off" is
393
- // not what a text field does. And with them off, CodeMirror turns the
394
- // period macOS puts after a double space back into a space by writing the
395
- // line anew, which cost the spelling marks on it.
396
- const attrs = { autocorrect: 'on', autocapitalize: 'sentences' };
397
- if (this.accessibleLabel)
398
- attrs['aria-label'] = this.accessibleLabel;
399
- if (this.inputId)
400
- attrs['id'] = this.inputId;
401
- return EditorView.contentAttributes.of(attrs);
402
- }
403
- firstUpdated() {
404
- this._initialValue = this.value;
405
- this.style.setProperty('--_text-editor-rows', String(this.rows));
406
- // The sentinels are the overlay's own; a value that carries one (an editor
407
- // whose text was round-tripped through another) hands it back stripped.
408
- this.mountEditor(stripSentinels(this.value));
409
- this.onEditorMounted();
323
+ // Autocorrect and autocapitalize follow the user's own settings, as on an
324
+ // <input> or a <textarea>, also with no-spellcheck: CodeMirror's "off" is
325
+ // not what a text field does. And with them off, CodeMirror turns the
326
+ // period macOS puts after a double space back into a space by writing the
327
+ // line anew, which cost the spelling marks on it.
328
+ contentAttributes() {
329
+ return { autocorrect: 'on', autocapitalize: 'sentences' };
330
+ }
331
+ /** The document carries annotation sentinels; the value never does. A value
332
+ * that carries one (text round-tripped through another editor) hands it
333
+ * back stripped, too. */
334
+ docToValue(doc) {
335
+ return stripSentinels(doc);
336
+ }
337
+ /** An emphasis held together while it was being typed is closed properly
338
+ * first, so the committed value renders the way it looked. */
339
+ beforeChangeCheck(view) {
340
+ repairHeldEmphasis(view);
410
341
  }
411
342
  /* Runs on the initial mount and on every re-mount after a detach/reattach
412
343
  * (e.g. Vue <KeepAlive>): the view — with its scroller and content DOM — is
413
344
  * rebuilt, so the click forwarders and annotation state must be (re)applied. */
414
345
  onEditorMounted() {
415
- // A press on the scroller's own padding (outside .cm-content) doesn't
416
- // place a caret; forward it to the nearest line.
417
- this.view?.scrollDOM.addEventListener('pointerdown', this._onScrollerPointerDown);
346
+ super.onEditorMounted();
418
347
  // Clicking a mention selects the whole token (capture, to beat CM's own
419
348
  // caret placement).
420
349
  this.view?.contentDOM.addEventListener('pointerdown', this._onMentionPointerDown, true);
@@ -422,55 +351,36 @@ let NLDDTextEditor = class NLDDTextEditor extends DescribedBy(FormAssociated(NLD
422
351
  // the tinted text itself stays plain-clickable for caret placement.
423
352
  this.view?.contentDOM.addEventListener('click', this._onAnnotationBadgeClick);
424
353
  this._syncAnnotations();
425
- this.commitFormValue();
426
- this._checkAccessibleLabel();
427
354
  // Emit one state snapshot on mount so a consumer's toolbar initializes to the
428
355
  // real state (e.g. undo/redo disabled with no history yet) instead of its
429
356
  // default, without waiting for the first edit or selection change.
430
357
  this._emitState();
431
358
  }
432
359
  updated(changed) {
433
- if (changed.has('rows')) {
434
- this.style.setProperty('--_text-editor-rows', String(this.rows));
360
+ super.updated(changed);
361
+ if (!this.view)
362
+ return;
363
+ // A render after setTranslations() or a new `translations`: the labels
364
+ // drawn inside the document follow when their text changed.
365
+ const labels = this._labelSignature();
366
+ if (labels !== this._labels) {
367
+ if (this._labels !== null)
368
+ this.view.dispatch({ effects: relabel.of(null) });
369
+ this._labels = labels;
435
370
  }
436
- if (this.view) {
437
- // A render after setTranslations() or a new `translations`: the labels
438
- // drawn inside the document follow when their text changed.
439
- const labels = this._labelSignature();
440
- if (labels !== this._labels) {
441
- if (this._labels !== null)
442
- this.view.dispatch({ effects: relabel.of(null) });
443
- this._labels = labels;
444
- }
445
- if (changed.has('value')) {
446
- // Only push an external value change into the document; a value that just
447
- // mirrors the current (sentinel-stripped) doc must not trigger a rewrite,
448
- // which would strip the sentinels the filter then re-adds (caret churn).
449
- if (stripSentinels(this.doc) !== this.value)
450
- this.setDoc(stripSentinels(this.value));
451
- this.commitFormValue();
452
- }
453
- if (changed.has('disabled') || changed.has('readonly')) {
454
- this.reconfigure(this._editableCompartment, this._editableExtension());
455
- }
456
- if (changed.has('wrap')) {
457
- this.reconfigure(this._wrapCompartment, this.wrap ? EditorView.lineWrapping : []);
458
- }
459
- if (changed.has('placeholder')) {
460
- this.reconfigure(this._placeholderCompartment, this._placeholderExtension());
461
- }
462
- if (changed.has('accessibleLabel') || changed.has('inputId')) {
463
- this.reconfigure(this._attrsCompartment, this._attrsExtension());
464
- }
465
- if (changed.has('noSpellcheck')) {
466
- this.reconfigure(this._spellcheckCompartment, this.noSpellcheck ? [] : spellcheck());
467
- this._redrawForSpellcheck();
468
- }
469
- if (changed.has('annotations') || changed.has('annotatable')) {
470
- this._syncAnnotations();
471
- }
371
+ if (changed.has('wrap')) {
372
+ this.reconfigure(this._wrapCompartment, this.wrap ? EditorView.lineWrapping : []);
373
+ }
374
+ if (changed.has('syntax')) {
375
+ this.reconfigure(this._syntaxCompartment, this.syntax === 'hidden' ? hiddenSyntax() : []);
376
+ }
377
+ if (changed.has('noSpellcheck')) {
378
+ this.reconfigure(this._spellcheckCompartment, this.noSpellcheck ? [] : spellcheck());
379
+ this._redrawForSpellcheck();
380
+ }
381
+ if (changed.has('annotations') || changed.has('annotatable')) {
382
+ this._syncAnnotations();
472
383
  }
473
- this._checkAccessibleLabel();
474
384
  }
475
385
  _syncAnnotations() {
476
386
  // Annotations only render when the consumer opts in via `annotatable`.
@@ -482,20 +392,6 @@ let NLDDTextEditor = class NLDDTextEditor extends DescribedBy(FormAssociated(NLD
482
392
  annotations: Transaction.addToHistory.of(false),
483
393
  });
484
394
  }
485
- // Two-step mention deletion: select the token on the first key, remove on the
486
- // second. dir -1 = Backspace (token ends at the caret), +1 = Delete (starts).
487
- _selectMentionBeforeDelete(view, dir) {
488
- const sel = view.state.selection.main;
489
- // A non-empty selection (e.g. an already-selected mention) → let the default
490
- // command delete it.
491
- if (!sel.empty)
492
- return false;
493
- const range = dir < 0 ? mentionRangeEndingAt(view.state, sel.head) : mentionRangeStartingAt(view.state, sel.head);
494
- if (!range)
495
- return false; // not next to a mention → normal backspace/delete
496
- view.dispatch({ selection: { anchor: range.from, head: range.to } });
497
- return true;
498
- }
499
395
  /* # Headless command API */
500
396
  toggleBold() {
501
397
  if (this.view)
@@ -590,31 +486,15 @@ let NLDDTextEditor = class NLDDTextEditor extends DescribedBy(FormAssociated(NLD
590
486
  view.dispatch({ effects: this._historyCompartment.reconfigure(history()) });
591
487
  this._emitState();
592
488
  }
593
- /** The annotations lying fully inside the current selection, offset relative to
594
- * the selection's clean start. */
595
- _annotationsInSelection() {
596
- if (!this.view)
597
- return [];
598
- const { from, to } = this.view.state.selection.main;
599
- const doc = this.view.state.doc.toString();
600
- const cleanFrom = docToClean(doc, from);
601
- const cleanTo = docToClean(doc, to);
602
- return currentAnnotations(this.view.state)
603
- .filter((a) => a.from >= cleanFrom && a.to <= cleanTo)
604
- .map((a) => ({ id: a.id, from: a.from - cleanFrom, to: a.to - cleanFrom }));
605
- }
606
489
  /** Copy the current selection to the clipboard, sentinel-free. No-op when the
607
490
  * selection is empty or the clipboard is unavailable (e.g. permission denied). */
608
491
  async copy() {
609
492
  if (!this.view)
610
493
  return;
611
- const { from, to } = this.view.state.selection.main;
612
- if (from === to)
494
+ if (this.view.state.selection.main.empty)
613
495
  return;
614
- const text = stripSentinels(this.view.state.sliceDoc(from, to));
615
- // A copy is a plain-text copy: forget any pending cut so its annotations don't
616
- // bleed onto the next paste.
617
- this._cutBuffer = null;
496
+ const text = this._clipboard.selectedText(this.view);
497
+ this._clipboard.forget();
618
498
  try {
619
499
  await navigator.clipboard.writeText(text);
620
500
  }
@@ -629,11 +509,10 @@ let NLDDTextEditor = class NLDDTextEditor extends DescribedBy(FormAssociated(NLD
629
509
  // Cut mutates (it removes the selection), so it's a no-op on a read-only editor.
630
510
  if (!this.view || this.view.state.readOnly)
631
511
  return;
632
- const { from, to } = this.view.state.selection.main;
633
- if (from === to)
512
+ if (this.view.state.selection.main.empty)
634
513
  return;
635
- const text = stripSentinels(this.view.state.sliceDoc(from, to));
636
- this._cutBuffer = { text, anns: this._annotationsInSelection() };
514
+ const text = this._clipboard.selectedText(this.view);
515
+ this._clipboard.rememberCut(this.view);
637
516
  try {
638
517
  await navigator.clipboard.writeText(text);
639
518
  }
@@ -657,7 +536,8 @@ let NLDDTextEditor = class NLDDTextEditor extends DescribedBy(FormAssociated(NLD
657
536
  catch {
658
537
  return; /* clipboard blocked */
659
538
  }
660
- this._pasteText(stripSentinels(raw));
539
+ if (this.view)
540
+ this._clipboard.paste(this.view, raw);
661
541
  this.view?.focus();
662
542
  }
663
543
  /** Puts `text` at the caret, in place of the selection when there is one, and
@@ -695,29 +575,6 @@ let NLDDTextEditor = class NLDDTextEditor extends DescribedBy(FormAssociated(NLD
695
575
  });
696
576
  this.view.focus();
697
577
  }
698
- /** Insert `text` at the selection, re-attaching the cut annotations when it matches
699
- * a cut made in this editor (a move, one-shot). Shared by the toolbar's paste()
700
- * and the native Cmd/Ctrl+V handler. */
701
- _pasteText(text) {
702
- // Paste mutates; refuse it on a read-only editor (covers the toolbar paste()
703
- // and the native Cmd/Ctrl+V handler that both funnel through here).
704
- if (!this.view || !text || this.view.state.readOnly)
705
- return;
706
- const buffer = this._cutBuffer;
707
- // Normalize line endings on both sides: a Windows/other-app clipboard may hand
708
- // back CRLF where the cut buffer holds LF, and an exact compare would then miss
709
- // the match and silently drop the carried annotations.
710
- const sameText = (a, b) => a.replace(/\r\n/g, '\n') === b.replace(/\r\n/g, '\n');
711
- const carry = !!(buffer && sameText(buffer.text, text) && buffer.anns.length > 0);
712
- const at = docToClean(this.view.state.doc.toString(), this.view.state.selection.main.from);
713
- // input.paste, like CodeMirror's own paste: history groups it as one step and
714
- // a transaction filter can tell a paste from typing.
715
- const spec = { ...this.view.state.replaceSelection(text), userEvent: 'input.paste' };
716
- this.view.dispatch(carry ? { ...spec, effects: pasteAnnotations.of({ at, anns: buffer.anns }) } : spec);
717
- // One-shot: a second paste of the same cut would duplicate the ids, so drop it.
718
- if (carry)
719
- this._cutBuffer = null;
720
- }
721
578
  /** Escape hatch: run a command by name, so a toolbar can carry the name in its
722
579
  * markup instead of a method reference. Every method above is reachable.
723
580
  *
@@ -894,91 +751,17 @@ let NLDDTextEditor = class NLDDTextEditor extends DescribedBy(FormAssociated(NLD
894
751
  composed: true,
895
752
  }));
896
753
  }
897
- _onDocChanged() {
898
- // The document carries annotation sentinels; the exposed value never does.
899
- const text = stripSentinels(this.doc);
900
- if (text === this.value)
901
- return;
902
- this.value = text;
903
- this.commitFormValue();
904
- this.dispatchEvent(new CustomEvent('input', {
905
- detail: { value: text },
906
- bubbles: true,
907
- composed: true,
908
- }));
909
- }
910
- _emitChange() {
911
- this.commitFormValue();
912
- this.dispatchEvent(new CustomEvent('change', {
913
- detail: { value: this.value },
914
- bubbles: true,
915
- composed: true,
916
- }));
917
- }
918
- _checkAccessibleLabel() {
919
- if (this._accessibleLabelWarned)
920
- return;
921
- if (this.accessibleLabel || this.inputId)
922
- return;
923
- this._accessibleLabelWarned = true;
924
- console.warn('<nldd-text-editor>: No accessible-label or input-id provided. Use nldd-form-field for labeled usage, or set accessible-label for screen reader accessibility (WCAG SC 4.1.2).');
925
- }
926
- formValue() {
927
- return this.value;
928
- }
929
- formResetCallback() {
930
- this.value = this._initialValue;
931
- }
932
- formStateRestoreCallback(state) {
933
- if (typeof state === 'string')
934
- this.value = state;
935
- }
936
- /** CodeMirror builds the textbox; the host is only its container. */
937
- describedTarget() {
938
- return this.shadowRoot?.querySelector('.cm-content') ?? null;
939
- }
940
754
  render() {
941
755
  return textEditorTemplate(this);
942
756
  }
943
757
  };
944
- NLDDTextEditor.shadowRootOptions = {
945
- ...LitElement.shadowRootOptions,
946
- delegatesFocus: true,
947
- };
948
758
  NLDDTextEditor.styles = textEditorStyles;
949
- /** Says this is the control an nldd-form-field is about, so the field can
950
- * find it, name it and move focus into it. See nldd-form-field. */
951
- NLDDTextEditor.isFormInput = true;
952
- __decorate([
953
- property({ type: String })
954
- ], NLDDTextEditor.prototype, "value", void 0);
955
- __decorate([
956
- property({ type: String, attribute: 'input-id' })
957
- ], NLDDTextEditor.prototype, "inputId", void 0);
958
- __decorate([
959
- property({ reflect: true, converter: reflectNonDefault('') })
960
- ], NLDDTextEditor.prototype, "placeholder", void 0);
961
- __decorate([
962
- property({ type: Boolean, reflect: true })
963
- ], NLDDTextEditor.prototype, "disabled", void 0);
964
- __decorate([
965
- property({ reflect: true, converter: reflectNonDefault('') })
966
- ], NLDDTextEditor.prototype, "name", void 0);
967
- __decorate([
968
- property({ type: Boolean, reflect: true })
969
- ], NLDDTextEditor.prototype, "readonly", void 0);
970
- __decorate([
971
- property({ type: Boolean, reflect: true })
972
- ], NLDDTextEditor.prototype, "required", void 0);
973
759
  __decorate([
974
760
  property({ type: Boolean, reflect: true, attribute: 'no-spellcheck' })
975
761
  ], NLDDTextEditor.prototype, "noSpellcheck", void 0);
976
762
  __decorate([
977
763
  property({ type: Boolean, reflect: true })
978
764
  ], NLDDTextEditor.prototype, "wrap", void 0);
979
- __decorate([
980
- property({ type: Number })
981
- ], NLDDTextEditor.prototype, "rows", void 0);
982
765
  __decorate([
983
766
  property({ reflect: true, converter: reflectNonDefault('auto') })
984
767
  ], NLDDTextEditor.prototype, "resize", void 0);
@@ -986,8 +769,8 @@ __decorate([
986
769
  property({ reflect: true, converter: reflectNonDefault('simple') })
987
770
  ], NLDDTextEditor.prototype, "appearance", void 0);
988
771
  __decorate([
989
- property({ type: String, attribute: 'accessible-label' })
990
- ], NLDDTextEditor.prototype, "accessibleLabel", void 0);
772
+ property({ reflect: true, converter: reflectNonDefault('visible') })
773
+ ], NLDDTextEditor.prototype, "syntax", void 0);
991
774
  __decorate([
992
775
  property({ attribute: false })
993
776
  ], NLDDTextEditor.prototype, "mentionSource", void 0);
@@ -1012,9 +795,6 @@ __decorate([
1012
795
  __decorate([
1013
796
  query('.text-editor')
1014
797
  ], NLDDTextEditor.prototype, "_container", void 0);
1015
- __decorate([
1016
- property({ type: Boolean, reflect: true })
1017
- ], NLDDTextEditor.prototype, "invalid", void 0);
1018
798
  NLDDTextEditor = __decorate([
1019
799
  customElement('nldd-text-editor')
1020
800
  ], NLDDTextEditor);