@ni/nimble-components 20.5.3 → 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 Fri, 22 Sep 2023 13:55:43 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
@@ -65664,11 +65728,11 @@ img.ProseMirror-separator {
65664
65728
  function getTanStackSortingFunction(sortOperation) {
65665
65729
  switch (sortOperation) {
65666
65730
  case TableColumnSortOperation.basic:
65667
- return sortingFns.basic;
65731
+ return basicSortFunction;
65668
65732
  case TableColumnSortOperation.localeAwareCaseSensitive:
65669
65733
  return localeAwareCaseSensitiveSortFunction;
65670
65734
  default:
65671
- return sortingFns.basic;
65735
+ return basicSortFunction;
65672
65736
  }
65673
65737
  }
65674
65738
  /**
@@ -65690,6 +65754,40 @@ img.ProseMirror-separator {
65690
65754
  }
65691
65755
  return 1;
65692
65756
  }
65757
+ /**
65758
+ * A function to perform a basic sort of two rows from TanStack for a given column.
65759
+ * The function sorts `undefined` followed by `null` before all other values.
65760
+ */
65761
+ function basicSortFunction(rowA, rowB, columnId) {
65762
+ const valueA = rowA.getValue(columnId);
65763
+ const valueB = rowB.getValue(columnId);
65764
+ if (Object.is(valueA, valueB)) {
65765
+ return 0;
65766
+ }
65767
+ if (valueA === undefined) {
65768
+ return -1;
65769
+ }
65770
+ if (valueB === undefined) {
65771
+ return 1;
65772
+ }
65773
+ if (valueA === null) {
65774
+ return -1;
65775
+ }
65776
+ if (valueB === null) {
65777
+ return 1;
65778
+ }
65779
+ if (Number.isNaN(valueA)) {
65780
+ return -1;
65781
+ }
65782
+ if (Number.isNaN(valueB)) {
65783
+ return 1;
65784
+ }
65785
+ if (valueA === 0 && valueB === 0) {
65786
+ // Both values equal 0, but one is -0 and one is +0 because Object.is(valueA, valueB) returned false.
65787
+ return Object.is(valueA, -0) ? -1 : 1;
65788
+ }
65789
+ return valueA > valueB ? 1 : -1;
65790
+ }
65693
65791
 
65694
65792
  /**
65695
65793
  * This class manages the layout of columns within a Table.