@ni/nimble-components 20.5.4 → 20.5.5

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.
@@ -16288,7 +16288,7 @@
16288
16288
 
16289
16289
  /**
16290
16290
  * Do not edit directly
16291
- * Generated on Tue, 26 Sep 2023 20:58:04 GMT
16291
+ * Generated on Thu, 28 Sep 2023 03:20:14 GMT
16292
16292
  */
16293
16293
 
16294
16294
  const Information100DarkUi = "#a46eff";
@@ -58785,6 +58785,46 @@ img.ProseMirror-separator {
58785
58785
  this.scrollbarWidth = -1;
58786
58786
  this.updateScrollbarWidthQueued = false;
58787
58787
  this.xmlSerializer = new XMLSerializer();
58788
+ this.validAbsoluteLinkRegex = /^https?:\/\//i;
58789
+ /**
58790
+ * This method finds the Link mark in the pasted content and update its Text node.
58791
+ * If there is no text node, pass the node's fragment recursively and updates only node containing Link mark.
58792
+ * If the Text node does not contains Link mark, push the same node to `updatedNodes`.
58793
+ *
58794
+ * @param fragment Fragment containing the pasted content. [Fragment](https://prosemirror.net/docs/ref/#model.Fragment)
58795
+ * @returns modified fragment from the `updatedNode` after updating the valid link text with its href value.
58796
+ */
58797
+ this.updateLinkNodes = (fragment) => {
58798
+ const updatedNodes = [];
58799
+ fragment.forEach(node => {
58800
+ if (node.isText && node.marks.length > 0) {
58801
+ const linkMark = node.marks.find(mark => mark.type.name === 'link' && mark.attrs);
58802
+ if (linkMark) {
58803
+ // Checks if the link is valid link or not
58804
+ // Needing to separately validate the link on paste is a workaround for a tiptap issue
58805
+ // See: https://github.com/ni/nimble/issues/1527
58806
+ if (this.validAbsoluteLinkRegex.test(linkMark.attrs.href)) {
58807
+ // The below lines of code is responsible for updating the text content with its href value and creates a new updated text node.
58808
+ // This code needs an update when the hyperlink support is added.
58809
+ // See: https://github.com/ni/nimble/issues/1527
58810
+ updatedNodes.push(this.tiptapEditor.schema.text(linkMark.attrs.href, node.marks));
58811
+ }
58812
+ else {
58813
+ // If it is a invalid link, creates a new Text node with the same text content and without a Link mark.
58814
+ updatedNodes.push(this.tiptapEditor.schema.text(node.textContent, linkMark.removeFromSet(node.marks)));
58815
+ }
58816
+ }
58817
+ else {
58818
+ updatedNodes.push(node);
58819
+ }
58820
+ }
58821
+ else {
58822
+ const updatedContent = this.updateLinkNodes(node.content);
58823
+ updatedNodes.push(node.copy(updatedContent));
58824
+ }
58825
+ });
58826
+ return Fragment.fromArray(updatedNodes);
58827
+ };
58788
58828
  }
58789
58829
  /**
58790
58830
  * True if the editor is empty or contains only whitespace, false otherwise.
@@ -58956,6 +58996,14 @@ img.ProseMirror-separator {
58956
58996
  }
58957
58997
  createTiptapEditor() {
58958
58998
  const customLink = this.getCustomLinkExtension();
58999
+ /**
59000
+ * @param slice contains the Fragment of the copied content. If the content is a link, the slice contains Text node with Link mark.
59001
+ * ProseMirror reference for `transformPasted`: https://prosemirror.net/docs/ref/#view.EditorProps.transformPasted
59002
+ */
59003
+ const transformPasted = (slice) => {
59004
+ const modifiedFragment = this.updateLinkNodes(slice.content);
59005
+ return new Slice(modifiedFragment, slice.openStart, slice.openEnd);
59006
+ };
58959
59007
  /**
58960
59008
  * For more information on the extensions for the supported formatting options, refer to the links below.
58961
59009
  * Tiptap marks: https://tiptap.dev/api/marks
@@ -58970,6 +59018,14 @@ img.ProseMirror-separator {
58970
59018
  // Lists do not have any default paste rules, they have only input rules, so disabled paste rules
58971
59019
  // https://tiptap.dev/api/editor#enable-paste-rules
58972
59020
  enablePasteRules: false,
59021
+ editorProps: {
59022
+ // Validating whether the links in the pasted content belongs to the supported scheme (HTTPS/HTTP),
59023
+ // and rendering it as a link in the editor. If not, rendering it as a plain text.
59024
+ // Also, updating the link text content with its href as we support only the absolute link.
59025
+ // `transformPasted` can be updated/removed when hyperlink support added
59026
+ // See: https://github.com/ni/nimble/issues/1527
59027
+ transformPasted
59028
+ },
58973
59029
  extensions: [
58974
59030
  Document$1,
58975
59031
  Paragraph,
@@ -58997,7 +59053,7 @@ img.ProseMirror-separator {
58997
59053
  // linkOnPaste can be enabled when hyperlink support added
58998
59054
  // See: https://github.com/ni/nimble/issues/1527
58999
59055
  linkOnPaste: false,
59000
- validate: href => /^https?:\/\//i.test(href)
59056
+ validate: href => this.validAbsoluteLinkRegex.test(href)
59001
59057
  })
59002
59058
  ]
59003
59059
  });
@@ -59019,10 +59075,18 @@ img.ProseMirror-separator {
59019
59075
  // See: https://github.com/ni/nimble/issues/1527
59020
59076
  inclusive: false,
59021
59077
  parseHTML() {
59022
- // To load the `nimble-anchor` from the HTML parsed content by markdown-parser as links in the
59023
- // Tiptap editor, the `parseHTML` of Link extension should return `anchorTag`. This is because the
59024
- // link mark schema in `markdown-parser.ts` file uses `<nimble-anchor>` as anchor tag and not `<a>`.
59025
- return [{ tag: anchorTag }];
59078
+ return [
59079
+ // To load the `nimble-anchor` from the HTML parsed content by markdown-parser as links in the Tiptap editor, the `parseHTML`
59080
+ // of Link extension should return nimble `anchorTag`.
59081
+ // This is because the link mark schema in `markdown-parser.ts` file uses `<nimble-anchor>` as anchor tag and not `<a>`.
59082
+ {
59083
+ tag: anchorTag
59084
+ },
59085
+ // `<a>` tag is added here to support when pasting a link from external source.
59086
+ {
59087
+ tag: 'a'
59088
+ }
59089
+ ];
59026
59090
  },
59027
59091
  // HTMLAttribute cannot be in camelCase as we want to match it with the name in Tiptap
59028
59092
  // eslint-disable-next-line @typescript-eslint/naming-convention