@atlaskit/editor-plugin-code-bidi-warning 5.0.0 → 5.0.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/editor-plugin-code-bidi-warning
2
2
 
3
+ ## 5.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`ff72875304f9a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/ff72875304f9a) -
8
+ Fix SSR bug in vanilla codebidi warning
9
+ - Updated dependencies
10
+
3
11
  ## 5.0.0
4
12
 
5
13
  ### Patch Changes
@@ -33,6 +33,21 @@ var pluginFactoryCreator = exports.pluginFactoryCreator = function pluginFactory
33
33
  }
34
34
  });
35
35
  };
36
+ function assertIsElement(node) {
37
+ // Using 1 instead of Node.ELEMENT_NODE just in case Node is not defined in some environments
38
+ if (node.nodeType !== 1) {
39
+ throw new Error('Code Bidi Warning DOM spec did not return an Element node');
40
+ }
41
+ }
42
+
43
+ /**
44
+ * Creates a DecorationSet containing widgets for each detected bidi character in code snippets within the document.
45
+ * @param props - The properties for creating the decoration set.
46
+ * @param props.doc - The ProseMirror document to scan for bidi characters.
47
+ * @param props.codeBidiWarningLabel - The label to use for the warning tooltip.
48
+ * @param props.tooltipEnabled - Whether tooltips are enabled for the warnings.
49
+ * @returns A DecorationSet with widgets at the positions of detected bidi characters.
50
+ */
36
51
  function createBidiWarningsDecorationSetFromDoc(_ref) {
37
52
  var doc = _ref.doc,
38
53
  codeBidiWarningLabel = _ref.codeBidiWarningLabel,
@@ -76,28 +91,25 @@ function createBidiWarningsDecorationSetFromDoc(_ref) {
76
91
  if (bidiCharactersAndTheirPositions.length === 0) {
77
92
  return _view.DecorationSet.empty;
78
93
  }
79
- var newBidiWarningsDecorationSet = _view.DecorationSet.create(doc, bidiCharactersAndTheirPositions.map(function (_ref4) {
94
+ return _view.DecorationSet.create(doc, bidiCharactersAndTheirPositions.map(function (_ref4) {
80
95
  var position = _ref4.position,
81
96
  bidiCharacter = _ref4.bidiCharacter;
82
- return _view.Decoration.widget(position, function (el) {
97
+ return _view.Decoration.widget(position, function () {
83
98
  return renderDOM(bidiCharacter, codeBidiWarningLabel, tooltipEnabled);
84
99
  }, {
85
- destroy: function destroy(el) {
86
- if (!(el instanceof HTMLElement)) {
87
- throw new Error('Code Bidi Warning DOM spec did not return an HTMLElement');
88
- }
89
- el.remove();
100
+ destroy: function destroy(node) {
101
+ assertIsElement(node);
102
+ node.remove();
90
103
  }
91
104
  });
92
105
  }));
93
- return newBidiWarningsDecorationSet;
94
106
  }
95
107
  function renderDOM(bidiCharacter, codeBidiWarningLabel, tooltipEnabled) {
96
108
  var spec = (0, _codeBidiWarningDomSpec.getCodeBidiWarningDomSpec)(bidiCharacter, codeBidiWarningLabel, tooltipEnabled);
97
109
  var _DOMSerializer$render = _model.DOMSerializer.renderSpec(document, spec),
98
110
  dom = _DOMSerializer$render.dom;
99
- if (!(dom instanceof HTMLElement)) {
100
- throw new Error('Code Bidi Warning DOM spec did not return an HTMLElement');
101
- }
111
+ // In SSR or non-browser DOM implementations, HTMLElement may not be present or cross-realm.
112
+ // Accept any Element node (nodeType === Node.ELEMENT_NODE) instead of relying on instanceof checks.
113
+ assertIsElement(dom);
102
114
  return dom;
103
115
  }
@@ -21,6 +21,21 @@ export const pluginFactoryCreator = () => pluginFactory(codeBidiWarningPluginKey
21
21
  };
22
22
  }
23
23
  });
24
+ function assertIsElement(node) {
25
+ // Using 1 instead of Node.ELEMENT_NODE just in case Node is not defined in some environments
26
+ if (node.nodeType !== 1) {
27
+ throw new Error('Code Bidi Warning DOM spec did not return an Element node');
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Creates a DecorationSet containing widgets for each detected bidi character in code snippets within the document.
33
+ * @param props - The properties for creating the decoration set.
34
+ * @param props.doc - The ProseMirror document to scan for bidi characters.
35
+ * @param props.codeBidiWarningLabel - The label to use for the warning tooltip.
36
+ * @param props.tooltipEnabled - Whether tooltips are enabled for the warnings.
37
+ * @returns A DecorationSet with widgets at the positions of detected bidi characters.
38
+ */
24
39
  export function createBidiWarningsDecorationSetFromDoc({
25
40
  doc,
26
41
  codeBidiWarningLabel,
@@ -65,28 +80,25 @@ export function createBidiWarningsDecorationSetFromDoc({
65
80
  if (bidiCharactersAndTheirPositions.length === 0) {
66
81
  return DecorationSet.empty;
67
82
  }
68
- const newBidiWarningsDecorationSet = DecorationSet.create(doc, bidiCharactersAndTheirPositions.map(({
83
+ return DecorationSet.create(doc, bidiCharactersAndTheirPositions.map(({
69
84
  position,
70
85
  bidiCharacter
71
86
  }) => {
72
- return Decoration.widget(position, el => renderDOM(bidiCharacter, codeBidiWarningLabel, tooltipEnabled), {
73
- destroy: el => {
74
- if (!(el instanceof HTMLElement)) {
75
- throw new Error('Code Bidi Warning DOM spec did not return an HTMLElement');
76
- }
77
- el.remove();
87
+ return Decoration.widget(position, () => renderDOM(bidiCharacter, codeBidiWarningLabel, tooltipEnabled), {
88
+ destroy: node => {
89
+ assertIsElement(node);
90
+ node.remove();
78
91
  }
79
92
  });
80
93
  }));
81
- return newBidiWarningsDecorationSet;
82
94
  }
83
95
  function renderDOM(bidiCharacter, codeBidiWarningLabel, tooltipEnabled) {
84
96
  const spec = getCodeBidiWarningDomSpec(bidiCharacter, codeBidiWarningLabel, tooltipEnabled);
85
97
  const {
86
98
  dom
87
99
  } = DOMSerializer.renderSpec(document, spec);
88
- if (!(dom instanceof HTMLElement)) {
89
- throw new Error('Code Bidi Warning DOM spec did not return an HTMLElement');
90
- }
100
+ // In SSR or non-browser DOM implementations, HTMLElement may not be present or cross-realm.
101
+ // Accept any Element node (nodeType === Node.ELEMENT_NODE) instead of relying on instanceof checks.
102
+ assertIsElement(dom);
91
103
  return dom;
92
104
  }
@@ -25,6 +25,21 @@ export var pluginFactoryCreator = function pluginFactoryCreator() {
25
25
  }
26
26
  });
27
27
  };
28
+ function assertIsElement(node) {
29
+ // Using 1 instead of Node.ELEMENT_NODE just in case Node is not defined in some environments
30
+ if (node.nodeType !== 1) {
31
+ throw new Error('Code Bidi Warning DOM spec did not return an Element node');
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Creates a DecorationSet containing widgets for each detected bidi character in code snippets within the document.
37
+ * @param props - The properties for creating the decoration set.
38
+ * @param props.doc - The ProseMirror document to scan for bidi characters.
39
+ * @param props.codeBidiWarningLabel - The label to use for the warning tooltip.
40
+ * @param props.tooltipEnabled - Whether tooltips are enabled for the warnings.
41
+ * @returns A DecorationSet with widgets at the positions of detected bidi characters.
42
+ */
28
43
  export function createBidiWarningsDecorationSetFromDoc(_ref) {
29
44
  var doc = _ref.doc,
30
45
  codeBidiWarningLabel = _ref.codeBidiWarningLabel,
@@ -68,28 +83,25 @@ export function createBidiWarningsDecorationSetFromDoc(_ref) {
68
83
  if (bidiCharactersAndTheirPositions.length === 0) {
69
84
  return DecorationSet.empty;
70
85
  }
71
- var newBidiWarningsDecorationSet = DecorationSet.create(doc, bidiCharactersAndTheirPositions.map(function (_ref4) {
86
+ return DecorationSet.create(doc, bidiCharactersAndTheirPositions.map(function (_ref4) {
72
87
  var position = _ref4.position,
73
88
  bidiCharacter = _ref4.bidiCharacter;
74
- return Decoration.widget(position, function (el) {
89
+ return Decoration.widget(position, function () {
75
90
  return renderDOM(bidiCharacter, codeBidiWarningLabel, tooltipEnabled);
76
91
  }, {
77
- destroy: function destroy(el) {
78
- if (!(el instanceof HTMLElement)) {
79
- throw new Error('Code Bidi Warning DOM spec did not return an HTMLElement');
80
- }
81
- el.remove();
92
+ destroy: function destroy(node) {
93
+ assertIsElement(node);
94
+ node.remove();
82
95
  }
83
96
  });
84
97
  }));
85
- return newBidiWarningsDecorationSet;
86
98
  }
87
99
  function renderDOM(bidiCharacter, codeBidiWarningLabel, tooltipEnabled) {
88
100
  var spec = getCodeBidiWarningDomSpec(bidiCharacter, codeBidiWarningLabel, tooltipEnabled);
89
101
  var _DOMSerializer$render = DOMSerializer.renderSpec(document, spec),
90
102
  dom = _DOMSerializer$render.dom;
91
- if (!(dom instanceof HTMLElement)) {
92
- throw new Error('Code Bidi Warning DOM spec did not return an HTMLElement');
93
- }
103
+ // In SSR or non-browser DOM implementations, HTMLElement may not be present or cross-realm.
104
+ // Accept any Element node (nodeType === Node.ELEMENT_NODE) instead of relying on instanceof checks.
105
+ assertIsElement(dom);
94
106
  return dom;
95
107
  }
@@ -5,6 +5,14 @@ export declare const pluginFactoryCreator: () => {
5
5
  createPluginState: (dispatch: import("@atlaskit/editor-common/event-dispatcher").Dispatch, initialState: import("./types").CodeBidiWarningPluginState | ((state: import("prosemirror-state").EditorState) => import("./types").CodeBidiWarningPluginState)) => import("prosemirror-state").SafeStateField<import("./types").CodeBidiWarningPluginState>;
6
6
  getPluginState: (state: import("prosemirror-state").EditorState) => import("./types").CodeBidiWarningPluginState;
7
7
  };
8
+ /**
9
+ * Creates a DecorationSet containing widgets for each detected bidi character in code snippets within the document.
10
+ * @param props - The properties for creating the decoration set.
11
+ * @param props.doc - The ProseMirror document to scan for bidi characters.
12
+ * @param props.codeBidiWarningLabel - The label to use for the warning tooltip.
13
+ * @param props.tooltipEnabled - Whether tooltips are enabled for the warnings.
14
+ * @returns A DecorationSet with widgets at the positions of detected bidi characters.
15
+ */
8
16
  export declare function createBidiWarningsDecorationSetFromDoc({ doc, codeBidiWarningLabel, tooltipEnabled, }: {
9
17
  codeBidiWarningLabel: string;
10
18
  doc: PmNode;
@@ -5,6 +5,14 @@ export declare const pluginFactoryCreator: () => {
5
5
  createPluginState: (dispatch: import("@atlaskit/editor-common/event-dispatcher").Dispatch, initialState: import("./types").CodeBidiWarningPluginState | ((state: import("prosemirror-state").EditorState) => import("./types").CodeBidiWarningPluginState)) => import("prosemirror-state").SafeStateField<import("./types").CodeBidiWarningPluginState>;
6
6
  getPluginState: (state: import("prosemirror-state").EditorState) => import("./types").CodeBidiWarningPluginState;
7
7
  };
8
+ /**
9
+ * Creates a DecorationSet containing widgets for each detected bidi character in code snippets within the document.
10
+ * @param props - The properties for creating the decoration set.
11
+ * @param props.doc - The ProseMirror document to scan for bidi characters.
12
+ * @param props.codeBidiWarningLabel - The label to use for the warning tooltip.
13
+ * @param props.tooltipEnabled - Whether tooltips are enabled for the warnings.
14
+ * @returns A DecorationSet with widgets at the positions of detected bidi characters.
15
+ */
8
16
  export declare function createBidiWarningsDecorationSetFromDoc({ doc, codeBidiWarningLabel, tooltipEnabled, }: {
9
17
  codeBidiWarningLabel: string;
10
18
  doc: PmNode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-code-bidi-warning",
3
- "version": "5.0.0",
3
+ "version": "5.0.1",
4
4
  "description": "Code bidi warning plugin for @atlaskit/editor-core.",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -35,7 +35,7 @@
35
35
  "uuid": "^3.1.0"
36
36
  },
37
37
  "peerDependencies": {
38
- "@atlaskit/editor-common": "^109.0.0",
38
+ "@atlaskit/editor-common": "^109.4.0",
39
39
  "react": "^18.2.0",
40
40
  "react-dom": "^18.2.0"
41
41
  },