@ni/nimble-components 35.12.0 → 35.12.1

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.
@@ -392,6 +392,89 @@
392
392
  }
393
393
  ]
394
394
  },
395
+ {
396
+ "kind": "javascript-module",
397
+ "path": "src/anchor-tab/index.ts",
398
+ "declarations": [
399
+ {
400
+ "kind": "class",
401
+ "description": "A nimble-styled link tab",
402
+ "name": "AnchorTab",
403
+ "members": [
404
+ {
405
+ "kind": "field",
406
+ "name": "disabled",
407
+ "type": {
408
+ "text": "boolean"
409
+ },
410
+ "privacy": "public",
411
+ "default": "false",
412
+ "description": "When true, the control will be immutable by user interaction. See https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/disabled | disabled HTML attribute for more information."
413
+ },
414
+ {
415
+ "kind": "field",
416
+ "name": "ariaSelected",
417
+ "type": {
418
+ "text": "string"
419
+ },
420
+ "privacy": "public",
421
+ "default": "'false'",
422
+ "description": "Indicates the current \"selected\" state of various widgets.\nhttps://www.w3.org/TR/wai-aria-1.1/#aria-selected"
423
+ }
424
+ ],
425
+ "attributes": [
426
+ {
427
+ "name": "disabled",
428
+ "type": {
429
+ "text": "boolean"
430
+ },
431
+ "default": "false",
432
+ "description": "When true, the control will be immutable by user interaction. See https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/disabled | disabled HTML attribute for more information.",
433
+ "fieldName": "disabled"
434
+ },
435
+ {
436
+ "name": "aria-selected",
437
+ "type": {
438
+ "text": "string"
439
+ },
440
+ "default": "'false'",
441
+ "description": "Indicates the current \"selected\" state of various widgets.\nhttps://www.w3.org/TR/wai-aria-1.1/#aria-selected",
442
+ "fieldName": "ariaSelected"
443
+ }
444
+ ],
445
+ "superclass": {
446
+ "name": "AnchorBase",
447
+ "module": "/src/anchor-base"
448
+ }
449
+ },
450
+ {
451
+ "kind": "variable",
452
+ "name": "anchorTabTag",
453
+ "type": {
454
+ "text": "string"
455
+ },
456
+ "default": "'nimble-anchor-tab'"
457
+ }
458
+ ],
459
+ "exports": [
460
+ {
461
+ "kind": "js",
462
+ "name": "AnchorTab",
463
+ "declaration": {
464
+ "name": "AnchorTab",
465
+ "module": "src/anchor-tab/index.ts"
466
+ }
467
+ },
468
+ {
469
+ "kind": "js",
470
+ "name": "anchorTabTag",
471
+ "declaration": {
472
+ "name": "anchorTabTag",
473
+ "module": "src/anchor-tab/index.ts"
474
+ }
475
+ }
476
+ ]
477
+ },
395
478
  {
396
479
  "kind": "javascript-module",
397
480
  "path": "src/anchor-step/index.ts",
@@ -576,89 +659,6 @@
576
659
  }
577
660
  ]
578
661
  },
579
- {
580
- "kind": "javascript-module",
581
- "path": "src/anchor-tab/index.ts",
582
- "declarations": [
583
- {
584
- "kind": "class",
585
- "description": "A nimble-styled link tab",
586
- "name": "AnchorTab",
587
- "members": [
588
- {
589
- "kind": "field",
590
- "name": "disabled",
591
- "type": {
592
- "text": "boolean"
593
- },
594
- "privacy": "public",
595
- "default": "false",
596
- "description": "When true, the control will be immutable by user interaction. See https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/disabled | disabled HTML attribute for more information."
597
- },
598
- {
599
- "kind": "field",
600
- "name": "ariaSelected",
601
- "type": {
602
- "text": "string"
603
- },
604
- "privacy": "public",
605
- "default": "'false'",
606
- "description": "Indicates the current \"selected\" state of various widgets.\nhttps://www.w3.org/TR/wai-aria-1.1/#aria-selected"
607
- }
608
- ],
609
- "attributes": [
610
- {
611
- "name": "disabled",
612
- "type": {
613
- "text": "boolean"
614
- },
615
- "default": "false",
616
- "description": "When true, the control will be immutable by user interaction. See https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/disabled | disabled HTML attribute for more information.",
617
- "fieldName": "disabled"
618
- },
619
- {
620
- "name": "aria-selected",
621
- "type": {
622
- "text": "string"
623
- },
624
- "default": "'false'",
625
- "description": "Indicates the current \"selected\" state of various widgets.\nhttps://www.w3.org/TR/wai-aria-1.1/#aria-selected",
626
- "fieldName": "ariaSelected"
627
- }
628
- ],
629
- "superclass": {
630
- "name": "AnchorBase",
631
- "module": "/src/anchor-base"
632
- }
633
- },
634
- {
635
- "kind": "variable",
636
- "name": "anchorTabTag",
637
- "type": {
638
- "text": "string"
639
- },
640
- "default": "'nimble-anchor-tab'"
641
- }
642
- ],
643
- "exports": [
644
- {
645
- "kind": "js",
646
- "name": "AnchorTab",
647
- "declaration": {
648
- "name": "AnchorTab",
649
- "module": "src/anchor-tab/index.ts"
650
- }
651
- },
652
- {
653
- "kind": "js",
654
- "name": "anchorTabTag",
655
- "declaration": {
656
- "name": "anchorTabTag",
657
- "module": "src/anchor-tab/index.ts"
658
- }
659
- }
660
- ]
661
- },
662
662
  {
663
663
  "kind": "javascript-module",
664
664
  "path": "src/anchor-tabs/index.ts",
@@ -93,6 +93,30 @@
93
93
 
94
94
  <hr/>
95
95
 
96
+ ## class: `AnchorTab`
97
+
98
+ ### Superclass
99
+
100
+ | Name | Module | Package |
101
+ | ------------ | ---------------- | ------- |
102
+ | `AnchorBase` | /src/anchor-base | |
103
+
104
+ ### Fields
105
+
106
+ | Name | Privacy | Type | Default | Description | Inherited From |
107
+ | -------------- | ------- | --------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- |
108
+ | `disabled` | public | `boolean` | `false` | When true, the control will be immutable by user interaction. See https\://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/disabled \| disabled HTML attribute for more information. | |
109
+ | `ariaSelected` | public | `string` | `'false'` | Indicates the current "selected" state of various widgets.&#xA;https\://www\.w3.org/TR/wai-aria-1.1/#aria-selected | |
110
+
111
+ ### Attributes
112
+
113
+ | Name | Field | Inherited From |
114
+ | --------------- | ------------ | -------------- |
115
+ | `disabled` | disabled | |
116
+ | `aria-selected` | ariaSelected | |
117
+
118
+ <hr/>
119
+
96
120
  ## class: `AnchorStep`
97
121
 
98
122
  ### Superclass
@@ -125,30 +149,6 @@
125
149
 
126
150
  <hr/>
127
151
 
128
- ## class: `AnchorTab`
129
-
130
- ### Superclass
131
-
132
- | Name | Module | Package |
133
- | ------------ | ---------------- | ------- |
134
- | `AnchorBase` | /src/anchor-base | |
135
-
136
- ### Fields
137
-
138
- | Name | Privacy | Type | Default | Description | Inherited From |
139
- | -------------- | ------- | --------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- |
140
- | `disabled` | public | `boolean` | `false` | When true, the control will be immutable by user interaction. See https\://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/disabled \| disabled HTML attribute for more information. | |
141
- | `ariaSelected` | public | `string` | `'false'` | Indicates the current "selected" state of various widgets.&#xA;https\://www\.w3.org/TR/wai-aria-1.1/#aria-selected | |
142
-
143
- ### Attributes
144
-
145
- | Name | Field | Inherited From |
146
- | --------------- | ------------ | -------------- |
147
- | `disabled` | disabled | |
148
- | `aria-selected` | ariaSelected | |
149
-
150
- <hr/>
151
-
152
152
  ## class: `AnchorTabs`
153
153
 
154
154
  ### Superclass
@@ -188,6 +188,18 @@ function createCustomMentionExtension(config, activeMentionCharacterEmitter, act
188
188
  allowSpaces: true,
189
189
  render: () => {
190
190
  let inSuggestionMode = false;
191
+ // Tracks the query for which a `mention-update` event was last emitted.
192
+ // The tiptap suggestion plugin invokes `onStart`/`onUpdate` multiple times
193
+ // for a single query change (e.g. an initial render plus loading and resolved
194
+ // states of its async item fetch). We only want to emit `mention-update` once
195
+ // per distinct query, so we deduplicate against the last emitted query.
196
+ let lastEmittedQuery;
197
+ const emitMentionUpdateIfQueryChanged = (query) => {
198
+ if (query !== lastEmittedQuery) {
199
+ lastEmittedQuery = query;
200
+ config.mentionUpdateEmitter(query);
201
+ }
202
+ };
191
203
  return {
192
204
  onStart: (props) => {
193
205
  /**
@@ -200,7 +212,7 @@ function createCustomMentionExtension(config, activeMentionCharacterEmitter, act
200
212
  return;
201
213
  }
202
214
  inSuggestionMode = true;
203
- config.mentionUpdateEmitter(props.query);
215
+ emitMentionUpdateIfQueryChanged(props.query);
204
216
  activeMentionCharacterEmitter(props.text.slice(0, 1));
205
217
  activeMentionCommandEmitter(props.command);
206
218
  mentionListbox?.show({
@@ -212,7 +224,7 @@ function createCustomMentionExtension(config, activeMentionCharacterEmitter, act
212
224
  if (!inSuggestionMode) {
213
225
  return;
214
226
  }
215
- config.mentionUpdateEmitter(props.query);
227
+ emitMentionUpdateIfQueryChanged(props.query);
216
228
  activeMentionCommandEmitter(props.command);
217
229
  mentionListbox?.show({
218
230
  filter: props.query,
@@ -229,6 +241,8 @@ function createCustomMentionExtension(config, activeMentionCharacterEmitter, act
229
241
  return (mentionListbox?.keydownHandler(props.event) ?? false);
230
242
  },
231
243
  onExit: () => {
244
+ inSuggestionMode = false;
245
+ lastEmittedQuery = undefined;
232
246
  activeMentionCharacterEmitter('');
233
247
  activeMentionCommandEmitter(undefined);
234
248
  mentionListbox?.close();
@@ -1 +1 @@
1
- {"version":3,"file":"create-tiptap-editor.js","sourceRoot":"","sources":["../../../../../src/rich-text/editor/models/create-tiptap-editor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,IAAI,MAAM,wBAAwB,CAAC;AAC1C,OAAO,QAAQ,MAAM,4BAA4B,CAAC;AAClD,OAAO,SAAS,MAAM,8BAA8B,CAAC;AACrD,OAAO,MAAM,MAAM,0BAA0B,CAAC;AAC9C,OAAO,IAAI,MAAM,wBAAwB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAAO,OAAO,MAAM,2BAA2B,CAAC;AAChD,OAAO,SAAS,MAAM,6BAA6B,CAAC;AACpD,OAAO,IAAI,MAAM,wBAAwB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,IAAI,YAAY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AQ,CAAC,KAAK,CAAC,IAAc,EAC7B,IAAI,CAAC,KAAK,CACb,CACJ,CAAC;gBACN,CAAC;qBAAM,CAAC;oBACJ,uGAAuG;oBACvG,YAAY,CAAC,IAAI,CACb,YAAY,CAAC,MAAM,CAAC,IAAI,CACpB,IAAI,CAAC,WAAW,EAChB,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CACrC,CACJ,CAAC;gBACN,CAAC;YACL,CAAC;iBAAM,CAAC;gBACJ,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC5B,CAAC;QACL,CAAC;aAAM,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,EAAE,CAAC;YACxD,YAAY,CAAC,IAAI,CACb,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAe,CAAC,CACvD,CAAC;QACN,CAAC;aAAM,CAAC;YACJ,MAAM,cAAc,GAAG,yBAAyB,CAC5C,YAAY,EACZ,IAAI,CAAC,OAAO,CACf,CAAC;YACF,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC;QACjD,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;AAC5C,CAAC","sourcesContent":["import { Editor, Mark, Node, mergeAttributes } from '@tiptap/core';\nimport Bold from '@tiptap/extension-bold';\nimport Document from '@tiptap/extension-document';\nimport HardBreak from '@tiptap/extension-hard-break';\nimport Italic from '@tiptap/extension-italic';\nimport Link from '@tiptap/extension-link';\nimport { BulletList, ListItem, OrderedList } from '@tiptap/extension-list';\nimport Mention from '@tiptap/extension-mention';\nimport Paragraph from '@tiptap/extension-paragraph';\nimport Text from '@tiptap/extension-text';\nimport { Placeholder, UndoRedo } from '@tiptap/extensions';\nimport { Slice, Fragment, Node as FragmentNode } from 'prosemirror-model';\nimport { PluginKey } from 'prosemirror-state';\n\nimport { keyEscape } from '@ni/fast-web-utilities';\nimport {\n type ActiveMentionCommandEmitter,\n type ActiveMentionCharacterEmitter,\n mentionPluginPrefix\n} from '../types';\n\nimport { anchorTag } from '../../../anchor';\nimport type { MentionExtensionConfiguration } from '../../models/mention-extension-configuration';\nimport type { RichTextMentionListbox } from '../../mention-listbox';\n\nconst validAbsoluteLinkRegex = /^https?:\\/\\//i;\n\nexport function createTiptapEditor(\n activeMentionCharacterEmitter: ActiveMentionCharacterEmitter,\n activeMentionCommandEmitter: ActiveMentionCommandEmitter,\n editor: HTMLDivElement,\n mentionExtensionConfig: MentionExtensionConfiguration[],\n mentionListbox?: RichTextMentionListbox,\n placeholder?: string\n): Editor {\n const customLink = createCustomLinkExtension();\n const mentionExtensions = mentionExtensionConfig.map(config => createCustomMentionExtension(\n config,\n activeMentionCharacterEmitter,\n activeMentionCommandEmitter,\n mentionListbox\n ));\n\n /**\n * For more information on the extensions for the supported formatting options, refer to the links below.\n * Tiptap marks: https://tiptap.dev/api/marks\n * Tiptap nodes: https://tiptap.dev/api/nodes\n */\n const tipTapEditor = new Editor({\n element: editor,\n // The editor will detect markdown syntax for an input only for these items\n // https://tiptap.dev/api/editor#enable-input-rules\n enableInputRules: [BulletList, OrderedList],\n // The editor will not detect markdown syntax when pasting content in any supported items\n // Lists do not have any default paste rules, they have only input rules, so disabled paste rules\n // https://tiptap.dev/api/editor#enable-paste-rules\n enablePasteRules: false,\n editorProps: {\n // Validating whether the links in the pasted content belongs to the supported scheme (HTTPS/HTTP),\n // and rendering it as a link in the editor. If not, rendering it as a plain text.\n // Also, updating the link text content with its href as we support only the absolute link.\n\n // `transformPasted` can be updated/removed when hyperlink support added\n // See: https://github.com/ni/nimble/issues/1527\n transformPasted\n },\n extensions: [\n Document,\n Paragraph,\n Text,\n BulletList,\n OrderedList,\n ListItem,\n Bold,\n Italic,\n UndoRedo,\n Placeholder.configure({\n placeholder,\n showOnlyWhenEditable: false\n }),\n HardBreak,\n customLink,\n ...mentionExtensions\n ]\n });\n\n /**\n * @param slice contains the Fragment of the copied content. If the content is a link, the slice contains Text node with Link mark.\n * ProseMirror reference for `transformPasted`: https://prosemirror.net/docs/ref/#view.EditorProps.transformPasted\n */\n function transformPasted(slice: Slice): Slice {\n const modifiedFragment = updateLinkAndMentionNodes(\n tipTapEditor,\n slice.content\n );\n return new Slice(modifiedFragment, slice.openStart, slice.openEnd);\n }\n\n return tipTapEditor;\n}\n\n/**\n * Extending the default link mark schema defined in the TipTap.\n *\n * \"excludes\": https://prosemirror.net/docs/ref/#model.MarkSpec.excludes\n * \"inclusive\": https://prosemirror.net/docs/ref/#model.MarkSpec.inclusive\n * \"parseHTML\": https://tiptap.dev/guide/custom-extensions#parse-html\n * \"renderHTML\": https://tiptap.dev/guide/custom-extensions/#render-html\n */\nfunction createCustomLinkExtension(): Mark {\n return Link.extend({\n // Excludes can be removed/enabled when hyperlink support added\n // See: https://github.com/ni/nimble/issues/1527\n excludes: '_',\n // Inclusive can be updated when hyperlink support added\n // See: https://github.com/ni/nimble/issues/1527\n inclusive: false,\n parseHTML() {\n return [\n // To load the `nimble-anchor` from the HTML parsed content by markdown-parser as links in the Tiptap editor, the `parseHTML`\n // of Link extension should return nimble `anchorTag`.\n // This is because the link mark schema in `markdown-parser.ts` file uses `<nimble-anchor>` as anchor tag and not `<a>`.\n {\n tag: anchorTag\n },\n // `<a>` tag is added here to support when pasting a link from external source.\n {\n tag: 'a'\n }\n ];\n },\n // HTMLAttribute cannot be in camelCase as we want to match it with the name in Tiptap\n renderHTML({\n // eslint-disable-next-line @typescript-eslint/naming-convention\n HTMLAttributes\n }: {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n HTMLAttributes: { [key: string]: string }\n }) {\n // The below 'a' tag should be replaced with 'nimble-anchor' once the below issue is fixed.\n // https://github.com/ni/nimble/issues/1516\n return ['a', HTMLAttributes];\n }\n }).configure({\n // HTMLAttribute cannot be in camelCase as we want to match it with the name in Tiptap\n // eslint-disable-next-line @typescript-eslint/naming-convention\n HTMLAttributes: {\n rel: 'noopener noreferrer',\n target: null,\n // Adding `class` here is a workaround to render two mentions without a whitespace as display names\n // For more details on this behavior, refer to the issue below:\n // https://github.com/ni/nimble/issues/1707\n class: ''\n },\n autolink: true,\n openOnClick: false,\n // linkOnPaste can be enabled when hyperlink support added\n // See: https://github.com/ni/nimble/issues/1527\n linkOnPaste: false,\n shouldAutoLink: href => validAbsoluteLinkRegex.test(href)\n });\n}\n\nfunction createCustomMentionExtension(\n config: MentionExtensionConfiguration,\n activeMentionCharacterEmitter: ActiveMentionCharacterEmitter,\n activeMentionCommandEmitter: ActiveMentionCommandEmitter,\n mentionListbox?: RichTextMentionListbox\n): Node {\n return Mention.extend({\n name: config.name,\n parseHTML() {\n return [\n {\n tag: config.viewElement\n }\n ];\n },\n addAttributes() {\n return {\n href: {\n default: null,\n parseHTML: (element: HTMLElement) => element.getAttribute('mention-href'),\n renderHTML: (attributes: { [key: string]: string }) => {\n return {\n 'mention-href': attributes.href\n };\n }\n },\n label: {\n default: null,\n parseHTML: (element: HTMLElement) => element.getAttribute('mention-label'),\n renderHTML: (attributes: { [key: string]: string }) => {\n return {\n 'mention-label': attributes.label\n };\n }\n },\n disabled: {\n default: null,\n parseHTML: (element: HTMLElement) => element.getAttribute('disabled'),\n renderHTML: (attributes: { [key: string]: string }) => {\n return {\n disabled: attributes.disabled\n };\n }\n }\n };\n },\n renderHTML({\n node,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n HTMLAttributes\n }: {\n node: FragmentNode,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n HTMLAttributes: { [key: string]: string }\n }) {\n return [\n config.viewElement,\n mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),\n this.options.renderText({\n options: this.options,\n node,\n suggestion: null\n })\n ];\n }\n }).configure({\n suggestion: {\n char: config.character,\n decorationClass: 'nimble-mention-view-edit',\n pluginKey: new PluginKey(config.key),\n allowSpaces: true,\n render: () => {\n let inSuggestionMode = false;\n return {\n onStart: (props): void => {\n /**\n * If the cursor position moves to outside of the mention and configuration element changes,\n * the setMarkdown() will trigger this `onStart` without a decoration node because the cursor\n * position is temporarily moved out of the suggestion decoration. Ignore `onStart` in that case\n * and don't show the mention list box since it doesn't have anything to anchor to.\n */\n if (props.decorationNode === null) {\n return;\n }\n inSuggestionMode = true;\n config.mentionUpdateEmitter(props.query);\n activeMentionCharacterEmitter(props.text.slice(0, 1));\n activeMentionCommandEmitter(props.command);\n mentionListbox?.show({\n filter: props.query,\n anchorNode: props.decorationNode as HTMLElement\n });\n },\n onUpdate: (props): void => {\n if (!inSuggestionMode) {\n return;\n }\n config.mentionUpdateEmitter(props.query);\n activeMentionCommandEmitter(props.command);\n mentionListbox?.show({\n filter: props.query,\n anchorNode: props.decorationNode as HTMLElement\n });\n },\n onKeyDown: (props): boolean => {\n if (!inSuggestionMode) {\n return false;\n }\n if (props.event.key === keyEscape) {\n inSuggestionMode = false;\n }\n return (\n mentionListbox?.keydownHandler(props.event) ?? false\n );\n },\n onExit: (): void => {\n activeMentionCharacterEmitter('');\n activeMentionCommandEmitter(undefined);\n mentionListbox?.close();\n }\n };\n }\n }\n });\n}\n\n/**\n * This method finds the Link mark in the pasted content and update its Text node.\n * If there is no text node, pass the node's fragment recursively and updates only node containing Link mark.\n * If the Text node does not contains Link mark, push the same node to `updatedNodes`.\n *\n * @param fragment Fragment containing the pasted content. [Fragment](https://prosemirror.net/docs/ref/#model.Fragment)\n * @returns modified fragment from the `updatedNode` after updating the valid link text with its href value.\n */\nfunction updateLinkAndMentionNodes(\n tiptapEditor: Editor,\n fragment: Fragment\n): Fragment {\n const updatedNodes: FragmentNode[] = [];\n\n fragment.forEach(node => {\n if (node.isText && node.marks.length > 0) {\n const linkMark = node.marks.find(\n mark => mark.type.name === 'link'\n );\n if (linkMark) {\n // Checks if the link is valid link or not\n // Needing to separately validate the link on paste is a workaround for a tiptap issue\n // See: https://github.com/ni/nimble/issues/1527\n if (\n validAbsoluteLinkRegex.test(linkMark.attrs.href as string)\n ) {\n // The below lines of code is responsible for updating the text content with its href value and creates a new updated text node.\n // This code needs an update when the hyperlink support is added.\n // See: https://github.com/ni/nimble/issues/1527\n updatedNodes.push(\n tiptapEditor.schema.text(\n linkMark.attrs.href as string,\n node.marks\n )\n );\n } else {\n // If it is a invalid link, creates a new Text node with the same text content and without a Link mark.\n updatedNodes.push(\n tiptapEditor.schema.text(\n node.textContent,\n linkMark.removeFromSet(node.marks)\n )\n );\n }\n } else {\n updatedNodes.push(node);\n }\n } else if (node.type.name.startsWith(mentionPluginPrefix)) {\n updatedNodes.push(\n tiptapEditor.schema.text(node.attrs.label as string)\n );\n } else {\n const updatedContent = updateLinkAndMentionNodes(\n tiptapEditor,\n node.content\n );\n updatedNodes.push(node.copy(updatedContent));\n }\n });\n\n return Fragment.fromArray(updatedNodes);\n}\n"]}
1
+ {"version":3,"file":"create-tiptap-editor.js","sourceRoot":"","sources":["../../../../../src/rich-text/editor/models/create-tiptap-editor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,IAAI,MAAM,wBAAwB,CAAC;AAC1C,OAAO,QAAQ,MAAM,4BAA4B,CAAC;AAClD,OAAO,SAAS,MAAM,8BAA8B,CAAC;AACrD,OAAO,MAAM,MAAM,0BAA0B,CAAC;AAC9C,OAAO,IAAI,MAAM,wBAAwB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAAO,OAAO,MAAM,2BAA2B,CAAC;AAChD,OAAO,SAAS,MAAM,6BAA6B,CAAC;AACpD,OAAO,IAAI,MAAM,wBAAwB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,QAAQ,EA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AAC,CAAC;AAC5C,CAAC","sourcesContent":["import { Editor, Mark, Node, mergeAttributes } from '@tiptap/core';\nimport Bold from '@tiptap/extension-bold';\nimport Document from '@tiptap/extension-document';\nimport HardBreak from '@tiptap/extension-hard-break';\nimport Italic from '@tiptap/extension-italic';\nimport Link from '@tiptap/extension-link';\nimport { BulletList, ListItem, OrderedList } from '@tiptap/extension-list';\nimport Mention from '@tiptap/extension-mention';\nimport Paragraph from '@tiptap/extension-paragraph';\nimport Text from '@tiptap/extension-text';\nimport { Placeholder, UndoRedo } from '@tiptap/extensions';\nimport { Slice, Fragment, Node as FragmentNode } from 'prosemirror-model';\nimport { PluginKey } from 'prosemirror-state';\n\nimport { keyEscape } from '@ni/fast-web-utilities';\nimport {\n type ActiveMentionCommandEmitter,\n type ActiveMentionCharacterEmitter,\n mentionPluginPrefix\n} from '../types';\n\nimport { anchorTag } from '../../../anchor';\nimport type { MentionExtensionConfiguration } from '../../models/mention-extension-configuration';\nimport type { RichTextMentionListbox } from '../../mention-listbox';\n\nconst validAbsoluteLinkRegex = /^https?:\\/\\//i;\n\nexport function createTiptapEditor(\n activeMentionCharacterEmitter: ActiveMentionCharacterEmitter,\n activeMentionCommandEmitter: ActiveMentionCommandEmitter,\n editor: HTMLDivElement,\n mentionExtensionConfig: MentionExtensionConfiguration[],\n mentionListbox?: RichTextMentionListbox,\n placeholder?: string\n): Editor {\n const customLink = createCustomLinkExtension();\n const mentionExtensions = mentionExtensionConfig.map(config => createCustomMentionExtension(\n config,\n activeMentionCharacterEmitter,\n activeMentionCommandEmitter,\n mentionListbox\n ));\n\n /**\n * For more information on the extensions for the supported formatting options, refer to the links below.\n * Tiptap marks: https://tiptap.dev/api/marks\n * Tiptap nodes: https://tiptap.dev/api/nodes\n */\n const tipTapEditor = new Editor({\n element: editor,\n // The editor will detect markdown syntax for an input only for these items\n // https://tiptap.dev/api/editor#enable-input-rules\n enableInputRules: [BulletList, OrderedList],\n // The editor will not detect markdown syntax when pasting content in any supported items\n // Lists do not have any default paste rules, they have only input rules, so disabled paste rules\n // https://tiptap.dev/api/editor#enable-paste-rules\n enablePasteRules: false,\n editorProps: {\n // Validating whether the links in the pasted content belongs to the supported scheme (HTTPS/HTTP),\n // and rendering it as a link in the editor. If not, rendering it as a plain text.\n // Also, updating the link text content with its href as we support only the absolute link.\n\n // `transformPasted` can be updated/removed when hyperlink support added\n // See: https://github.com/ni/nimble/issues/1527\n transformPasted\n },\n extensions: [\n Document,\n Paragraph,\n Text,\n BulletList,\n OrderedList,\n ListItem,\n Bold,\n Italic,\n UndoRedo,\n Placeholder.configure({\n placeholder,\n showOnlyWhenEditable: false\n }),\n HardBreak,\n customLink,\n ...mentionExtensions\n ]\n });\n\n /**\n * @param slice contains the Fragment of the copied content. If the content is a link, the slice contains Text node with Link mark.\n * ProseMirror reference for `transformPasted`: https://prosemirror.net/docs/ref/#view.EditorProps.transformPasted\n */\n function transformPasted(slice: Slice): Slice {\n const modifiedFragment = updateLinkAndMentionNodes(\n tipTapEditor,\n slice.content\n );\n return new Slice(modifiedFragment, slice.openStart, slice.openEnd);\n }\n\n return tipTapEditor;\n}\n\n/**\n * Extending the default link mark schema defined in the TipTap.\n *\n * \"excludes\": https://prosemirror.net/docs/ref/#model.MarkSpec.excludes\n * \"inclusive\": https://prosemirror.net/docs/ref/#model.MarkSpec.inclusive\n * \"parseHTML\": https://tiptap.dev/guide/custom-extensions#parse-html\n * \"renderHTML\": https://tiptap.dev/guide/custom-extensions/#render-html\n */\nfunction createCustomLinkExtension(): Mark {\n return Link.extend({\n // Excludes can be removed/enabled when hyperlink support added\n // See: https://github.com/ni/nimble/issues/1527\n excludes: '_',\n // Inclusive can be updated when hyperlink support added\n // See: https://github.com/ni/nimble/issues/1527\n inclusive: false,\n parseHTML() {\n return [\n // To load the `nimble-anchor` from the HTML parsed content by markdown-parser as links in the Tiptap editor, the `parseHTML`\n // of Link extension should return nimble `anchorTag`.\n // This is because the link mark schema in `markdown-parser.ts` file uses `<nimble-anchor>` as anchor tag and not `<a>`.\n {\n tag: anchorTag\n },\n // `<a>` tag is added here to support when pasting a link from external source.\n {\n tag: 'a'\n }\n ];\n },\n // HTMLAttribute cannot be in camelCase as we want to match it with the name in Tiptap\n renderHTML({\n // eslint-disable-next-line @typescript-eslint/naming-convention\n HTMLAttributes\n }: {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n HTMLAttributes: { [key: string]: string }\n }) {\n // The below 'a' tag should be replaced with 'nimble-anchor' once the below issue is fixed.\n // https://github.com/ni/nimble/issues/1516\n return ['a', HTMLAttributes];\n }\n }).configure({\n // HTMLAttribute cannot be in camelCase as we want to match it with the name in Tiptap\n // eslint-disable-next-line @typescript-eslint/naming-convention\n HTMLAttributes: {\n rel: 'noopener noreferrer',\n target: null,\n // Adding `class` here is a workaround to render two mentions without a whitespace as display names\n // For more details on this behavior, refer to the issue below:\n // https://github.com/ni/nimble/issues/1707\n class: ''\n },\n autolink: true,\n openOnClick: false,\n // linkOnPaste can be enabled when hyperlink support added\n // See: https://github.com/ni/nimble/issues/1527\n linkOnPaste: false,\n shouldAutoLink: href => validAbsoluteLinkRegex.test(href)\n });\n}\n\nfunction createCustomMentionExtension(\n config: MentionExtensionConfiguration,\n activeMentionCharacterEmitter: ActiveMentionCharacterEmitter,\n activeMentionCommandEmitter: ActiveMentionCommandEmitter,\n mentionListbox?: RichTextMentionListbox\n): Node {\n return Mention.extend({\n name: config.name,\n parseHTML() {\n return [\n {\n tag: config.viewElement\n }\n ];\n },\n addAttributes() {\n return {\n href: {\n default: null,\n parseHTML: (element: HTMLElement) => element.getAttribute('mention-href'),\n renderHTML: (attributes: { [key: string]: string }) => {\n return {\n 'mention-href': attributes.href\n };\n }\n },\n label: {\n default: null,\n parseHTML: (element: HTMLElement) => element.getAttribute('mention-label'),\n renderHTML: (attributes: { [key: string]: string }) => {\n return {\n 'mention-label': attributes.label\n };\n }\n },\n disabled: {\n default: null,\n parseHTML: (element: HTMLElement) => element.getAttribute('disabled'),\n renderHTML: (attributes: { [key: string]: string }) => {\n return {\n disabled: attributes.disabled\n };\n }\n }\n };\n },\n renderHTML({\n node,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n HTMLAttributes\n }: {\n node: FragmentNode,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n HTMLAttributes: { [key: string]: string }\n }) {\n return [\n config.viewElement,\n mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),\n this.options.renderText({\n options: this.options,\n node,\n suggestion: null\n })\n ];\n }\n }).configure({\n suggestion: {\n char: config.character,\n decorationClass: 'nimble-mention-view-edit',\n pluginKey: new PluginKey(config.key),\n allowSpaces: true,\n render: () => {\n let inSuggestionMode = false;\n // Tracks the query for which a `mention-update` event was last emitted.\n // The tiptap suggestion plugin invokes `onStart`/`onUpdate` multiple times\n // for a single query change (e.g. an initial render plus loading and resolved\n // states of its async item fetch). We only want to emit `mention-update` once\n // per distinct query, so we deduplicate against the last emitted query.\n let lastEmittedQuery: string | undefined;\n const emitMentionUpdateIfQueryChanged = (query: string): void => {\n if (query !== lastEmittedQuery) {\n lastEmittedQuery = query;\n config.mentionUpdateEmitter(query);\n }\n };\n return {\n onStart: (props): void => {\n /**\n * If the cursor position moves to outside of the mention and configuration element changes,\n * the setMarkdown() will trigger this `onStart` without a decoration node because the cursor\n * position is temporarily moved out of the suggestion decoration. Ignore `onStart` in that case\n * and don't show the mention list box since it doesn't have anything to anchor to.\n */\n if (props.decorationNode === null) {\n return;\n }\n inSuggestionMode = true;\n emitMentionUpdateIfQueryChanged(props.query);\n activeMentionCharacterEmitter(props.text.slice(0, 1));\n activeMentionCommandEmitter(props.command);\n mentionListbox?.show({\n filter: props.query,\n anchorNode: props.decorationNode as HTMLElement\n });\n },\n onUpdate: (props): void => {\n if (!inSuggestionMode) {\n return;\n }\n emitMentionUpdateIfQueryChanged(props.query);\n activeMentionCommandEmitter(props.command);\n mentionListbox?.show({\n filter: props.query,\n anchorNode: props.decorationNode as HTMLElement\n });\n },\n onKeyDown: (props): boolean => {\n if (!inSuggestionMode) {\n return false;\n }\n if (props.event.key === keyEscape) {\n inSuggestionMode = false;\n }\n return (\n mentionListbox?.keydownHandler(props.event) ?? false\n );\n },\n onExit: (): void => {\n inSuggestionMode = false;\n lastEmittedQuery = undefined;\n activeMentionCharacterEmitter('');\n activeMentionCommandEmitter(undefined);\n mentionListbox?.close();\n }\n };\n }\n }\n });\n}\n\n/**\n * This method finds the Link mark in the pasted content and update its Text node.\n * If there is no text node, pass the node's fragment recursively and updates only node containing Link mark.\n * If the Text node does not contains Link mark, push the same node to `updatedNodes`.\n *\n * @param fragment Fragment containing the pasted content. [Fragment](https://prosemirror.net/docs/ref/#model.Fragment)\n * @returns modified fragment from the `updatedNode` after updating the valid link text with its href value.\n */\nfunction updateLinkAndMentionNodes(\n tiptapEditor: Editor,\n fragment: Fragment\n): Fragment {\n const updatedNodes: FragmentNode[] = [];\n\n fragment.forEach(node => {\n if (node.isText && node.marks.length > 0) {\n const linkMark = node.marks.find(\n mark => mark.type.name === 'link'\n );\n if (linkMark) {\n // Checks if the link is valid link or not\n // Needing to separately validate the link on paste is a workaround for a tiptap issue\n // See: https://github.com/ni/nimble/issues/1527\n if (\n validAbsoluteLinkRegex.test(linkMark.attrs.href as string)\n ) {\n // The below lines of code is responsible for updating the text content with its href value and creates a new updated text node.\n // This code needs an update when the hyperlink support is added.\n // See: https://github.com/ni/nimble/issues/1527\n updatedNodes.push(\n tiptapEditor.schema.text(\n linkMark.attrs.href as string,\n node.marks\n )\n );\n } else {\n // If it is a invalid link, creates a new Text node with the same text content and without a Link mark.\n updatedNodes.push(\n tiptapEditor.schema.text(\n node.textContent,\n linkMark.removeFromSet(node.marks)\n )\n );\n }\n } else {\n updatedNodes.push(node);\n }\n } else if (node.type.name.startsWith(mentionPluginPrefix)) {\n updatedNodes.push(\n tiptapEditor.schema.text(node.attrs.label as string)\n );\n } else {\n const updatedContent = updateLinkAndMentionNodes(\n tiptapEditor,\n node.content\n );\n updatedNodes.push(node.copy(updatedContent));\n }\n });\n\n return Fragment.fromArray(updatedNodes);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ni/nimble-components",
3
- "version": "35.12.0",
3
+ "version": "35.12.1",
4
4
  "description": "Styled web components for the NI Nimble Design System",
5
5
  "scripts": {
6
6
  "build": "npm run build:icons && npm run build:workers && npm run build:components && npm run build:scss && npm run build:cem",
@@ -53,18 +53,18 @@
53
53
  "@ni/unit-format": "^1.0.5",
54
54
  "@tanstack/table-core": "^8.19.3",
55
55
  "@tanstack/virtual-core": "^3.14.0",
56
- "@tiptap/core": "^3.22.5",
57
- "@tiptap/extension-bold": "^3.22.5",
58
- "@tiptap/extension-document": "^3.22.5",
59
- "@tiptap/extension-hard-break": "^3.22.5",
60
- "@tiptap/extension-italic": "^3.22.5",
61
- "@tiptap/extension-link": "^3.22.5",
62
- "@tiptap/extension-list": "^3.22.5",
63
- "@tiptap/extension-mention": "^3.22.5",
64
- "@tiptap/extension-paragraph": "^3.22.5",
65
- "@tiptap/extension-text": "^3.22.5",
66
- "@tiptap/extensions": "^3.22.5",
67
- "@tiptap/suggestion": "^3.22.5",
56
+ "@tiptap/core": "^3.27.1",
57
+ "@tiptap/extension-bold": "^3.27.1",
58
+ "@tiptap/extension-document": "^3.27.1",
59
+ "@tiptap/extension-hard-break": "^3.27.1",
60
+ "@tiptap/extension-italic": "^3.27.1",
61
+ "@tiptap/extension-link": "^3.27.1",
62
+ "@tiptap/extension-list": "^3.27.1",
63
+ "@tiptap/extension-mention": "^3.27.1",
64
+ "@tiptap/extension-paragraph": "^3.27.1",
65
+ "@tiptap/extension-text": "^3.27.1",
66
+ "@tiptap/extensions": "^3.27.1",
67
+ "@tiptap/suggestion": "^3.27.1",
68
68
  "@types/d3-array": "^3.0.4",
69
69
  "@types/d3-random": "^3.0.1",
70
70
  "@types/d3-scale": "^4.0.2",