@atlaskit/editor-plugin-code-bidi-warning 7.0.0 → 7.0.2

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,19 @@
1
1
  # @atlaskit/editor-plugin-code-bidi-warning
2
2
 
3
+ ## 7.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`d5b15f4306afb`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/d5b15f4306afb) -
8
+ Remove redundant vanilla codebidi warning experiment
9
+ - Updated dependencies
10
+
11
+ ## 7.0.1
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies
16
+
3
17
  ## 7.0.0
4
18
 
5
19
  ### Patch Changes
@@ -7,11 +7,9 @@ exports.createPlugin = void 0;
7
7
  var _messages = require("@atlaskit/editor-common/messages");
8
8
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
9
9
  var _view = require("@atlaskit/editor-prosemirror/view");
10
- var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
11
10
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
12
11
  var _pluginKey = require("./plugin-key");
13
12
  var _reactPluginFactory = require("./react-plugin-factory");
14
- var _vanillaPluginFactory = require("./vanilla-plugin-factory");
15
13
  var createPlugin = exports.createPlugin = function createPlugin(api, _ref, _ref2) {
16
14
  var dispatch = _ref.dispatch,
17
15
  getIntl = _ref.getIntl,
@@ -19,9 +17,9 @@ var createPlugin = exports.createPlugin = function createPlugin(api, _ref, _ref2
19
17
  var appearance = _ref2.appearance;
20
18
  var intl = getIntl();
21
19
  var codeBidiWarningLabel = intl.formatMessage(_messages.codeBidiWarningMessages.label);
22
- var _ref3 = (0, _platformFeatureFlags.fg)('platform_editor_vanilla_codebidi_warning') ? (0, _vanillaPluginFactory.pluginFactoryCreator)() : (0, _reactPluginFactory.pluginFactoryCreator)(nodeViewPortalProviderAPI),
23
- createPluginState = _ref3.createPluginState,
24
- getPluginState = _ref3.getPluginState;
20
+ var _reactPluginFactoryCr = (0, _reactPluginFactory.pluginFactoryCreator)(nodeViewPortalProviderAPI),
21
+ createPluginState = _reactPluginFactoryCr.createPluginState,
22
+ getPluginState = _reactPluginFactoryCr.getPluginState;
25
23
  return new _safePlugin.SafePlugin({
26
24
  key: _pluginKey.codeBidiWarningPluginKey,
27
25
  state: createPluginState(dispatch, function (state) {
@@ -41,11 +39,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, _ref, _ref2
41
39
  };
42
40
  }
43
41
  return {
44
- decorationSet: (0, _platformFeatureFlags.fg)('platform_editor_vanilla_codebidi_warning') ? (0, _vanillaPluginFactory.createBidiWarningsDecorationSetFromDoc)({
45
- doc: state.doc,
46
- codeBidiWarningLabel: codeBidiWarningLabel,
47
- tooltipEnabled: true
48
- }) : (0, _reactPluginFactory.createBidiWarningsDecorationSetFromDoc)({
42
+ decorationSet: (0, _reactPluginFactory.createBidiWarningsDecorationSetFromDoc)({
49
43
  doc: state.doc,
50
44
  codeBidiWarningLabel: codeBidiWarningLabel,
51
45
  tooltipEnabled: true,
@@ -1,11 +1,9 @@
1
1
  import { codeBidiWarningMessages } from '@atlaskit/editor-common/messages';
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
3
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
- import { fg } from '@atlaskit/platform-feature-flags';
5
4
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
6
5
  import { codeBidiWarningPluginKey } from './plugin-key';
7
6
  import { createBidiWarningsDecorationSetFromDoc as reactCreateBidiWarningsDecorationSetFromDoc, pluginFactoryCreator as reactPluginFactoryCreator } from './react-plugin-factory';
8
- import { createBidiWarningsDecorationSetFromDoc as vanillaCreateBidiWarningsDecorationSetFromDoc, pluginFactoryCreator as vanillaPluginFactoryCreator } from './vanilla-plugin-factory';
9
7
  export const createPlugin = (api, {
10
8
  dispatch,
11
9
  getIntl,
@@ -18,7 +16,7 @@ export const createPlugin = (api, {
18
16
  const {
19
17
  createPluginState,
20
18
  getPluginState
21
- } = fg('platform_editor_vanilla_codebidi_warning') ? vanillaPluginFactoryCreator() : reactPluginFactoryCreator(nodeViewPortalProviderAPI);
19
+ } = reactPluginFactoryCreator(nodeViewPortalProviderAPI);
22
20
  return new SafePlugin({
23
21
  key: codeBidiWarningPluginKey,
24
22
  state: createPluginState(dispatch, state => {
@@ -38,11 +36,7 @@ export const createPlugin = (api, {
38
36
  };
39
37
  }
40
38
  return {
41
- decorationSet: fg('platform_editor_vanilla_codebidi_warning') ? vanillaCreateBidiWarningsDecorationSetFromDoc({
42
- doc: state.doc,
43
- codeBidiWarningLabel,
44
- tooltipEnabled: true
45
- }) : reactCreateBidiWarningsDecorationSetFromDoc({
39
+ decorationSet: reactCreateBidiWarningsDecorationSetFromDoc({
46
40
  doc: state.doc,
47
41
  codeBidiWarningLabel,
48
42
  tooltipEnabled: true,
@@ -1,11 +1,9 @@
1
1
  import { codeBidiWarningMessages } from '@atlaskit/editor-common/messages';
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
3
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
- import { fg } from '@atlaskit/platform-feature-flags';
5
4
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
6
5
  import { codeBidiWarningPluginKey } from './plugin-key';
7
6
  import { createBidiWarningsDecorationSetFromDoc as reactCreateBidiWarningsDecorationSetFromDoc, pluginFactoryCreator as reactPluginFactoryCreator } from './react-plugin-factory';
8
- import { createBidiWarningsDecorationSetFromDoc as vanillaCreateBidiWarningsDecorationSetFromDoc, pluginFactoryCreator as vanillaPluginFactoryCreator } from './vanilla-plugin-factory';
9
7
  export var createPlugin = function createPlugin(api, _ref, _ref2) {
10
8
  var dispatch = _ref.dispatch,
11
9
  getIntl = _ref.getIntl,
@@ -13,9 +11,9 @@ export var createPlugin = function createPlugin(api, _ref, _ref2) {
13
11
  var appearance = _ref2.appearance;
14
12
  var intl = getIntl();
15
13
  var codeBidiWarningLabel = intl.formatMessage(codeBidiWarningMessages.label);
16
- var _ref3 = fg('platform_editor_vanilla_codebidi_warning') ? vanillaPluginFactoryCreator() : reactPluginFactoryCreator(nodeViewPortalProviderAPI),
17
- createPluginState = _ref3.createPluginState,
18
- getPluginState = _ref3.getPluginState;
14
+ var _reactPluginFactoryCr = reactPluginFactoryCreator(nodeViewPortalProviderAPI),
15
+ createPluginState = _reactPluginFactoryCr.createPluginState,
16
+ getPluginState = _reactPluginFactoryCr.getPluginState;
19
17
  return new SafePlugin({
20
18
  key: codeBidiWarningPluginKey,
21
19
  state: createPluginState(dispatch, function (state) {
@@ -35,11 +33,7 @@ export var createPlugin = function createPlugin(api, _ref, _ref2) {
35
33
  };
36
34
  }
37
35
  return {
38
- decorationSet: fg('platform_editor_vanilla_codebidi_warning') ? vanillaCreateBidiWarningsDecorationSetFromDoc({
39
- doc: state.doc,
40
- codeBidiWarningLabel: codeBidiWarningLabel,
41
- tooltipEnabled: true
42
- }) : reactCreateBidiWarningsDecorationSetFromDoc({
36
+ decorationSet: reactCreateBidiWarningsDecorationSetFromDoc({
43
37
  doc: state.doc,
44
38
  codeBidiWarningLabel: codeBidiWarningLabel,
45
39
  tooltipEnabled: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-code-bidi-warning",
3
- "version": "7.0.0",
3
+ "version": "7.0.2",
4
4
  "description": "Code bidi warning plugin for @atlaskit/editor-core.",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -31,12 +31,12 @@
31
31
  "@atlaskit/editor-plugin-limited-mode": "^4.0.0",
32
32
  "@atlaskit/editor-prosemirror": "^7.2.0",
33
33
  "@atlaskit/platform-feature-flags": "^1.1.0",
34
- "@atlaskit/tmp-editor-statsig": "^16.3.0",
34
+ "@atlaskit/tmp-editor-statsig": "^17.9.0",
35
35
  "@babel/runtime": "^7.0.0",
36
36
  "uuid": "^3.1.0"
37
37
  },
38
38
  "peerDependencies": {
39
- "@atlaskit/editor-common": "^111.0.0",
39
+ "@atlaskit/editor-common": "^111.11.0",
40
40
  "react": "^18.2.0",
41
41
  "react-dom": "^18.2.0"
42
42
  },
@@ -79,10 +79,5 @@
79
79
  "import-no-extraneous-disable-for-examples-and-docs"
80
80
  ]
81
81
  }
82
- },
83
- "platform-feature-flags": {
84
- "platform_editor_vanilla_codebidi_warning": {
85
- "type": "boolean"
86
- }
87
82
  }
88
83
  }
@@ -1,32 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.getCodeBidiWarningDomSpec = getCodeBidiWarningDomSpec;
8
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
- function getCodeBidiWarningDomSpec(bidiCharacter, codeBidiWarningLabel, tooltipEnabled) {
10
- var _bidiCharacter$codePo;
11
- var bidiCharacterCode = "U+".concat((_bidiCharacter$codePo = bidiCharacter.codePointAt(0)) === null || _bidiCharacter$codePo === void 0 || (_bidiCharacter$codePo = _bidiCharacter$codePo.toString(16)) === null || _bidiCharacter$codePo === void 0 ? void 0 : _bidiCharacter$codePo.toUpperCase());
12
- return ['span', {
13
- 'data-prosemirror-node-name': 'code-bidi-warning',
14
- dir: 'ltr'
15
- },
16
- // Code Bidi Warning Decorator
17
- ['span', {
18
- 'data-bidi-component': 'code-bidi-warning-decorator',
19
- 'data-testid': 'code-bidi-warning-decorator',
20
- 'data-bidi-character-code': bidiCharacterCode,
21
- role: 'mark'
22
- },
23
- // Mark the < and > characters as visually hidden for screen readers
24
- ['span', {
25
- 'aria-hidden': 'true'
26
- }, '<'], bidiCharacterCode, ['span', {
27
- 'aria-hidden': 'true'
28
- }, '>']]].concat((0, _toConsumableArray2.default)(tooltipEnabled ? [['span', {
29
- 'data-bidi-component': 'code-bidi-warning-tooltip',
30
- role: 'tooltip'
31
- }, codeBidiWarningLabel]] : []));
32
- }
@@ -1,115 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.createBidiWarningsDecorationSetFromDoc = createBidiWarningsDecorationSetFromDoc;
8
- exports.pluginFactoryCreator = void 0;
9
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
- var _bidiWarningDecorator = _interopRequireDefault(require("@atlaskit/code/bidi-warning-decorator"));
11
- var _utils = require("@atlaskit/editor-common/utils");
12
- var _model = require("@atlaskit/editor-prosemirror/model");
13
- var _view = require("@atlaskit/editor-prosemirror/view");
14
- var _codeBidiWarningDomSpec = require("./codeBidiWarningDomSpec");
15
- var _pluginKey = require("./plugin-key");
16
- var _reducer = _interopRequireDefault(require("./reducer"));
17
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
18
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
19
- var pluginFactoryCreator = exports.pluginFactoryCreator = function pluginFactoryCreator() {
20
- return (0, _utils.pluginFactory)(_pluginKey.codeBidiWarningPluginKey, _reducer.default, {
21
- onDocChanged: function onDocChanged(tr, pluginState) {
22
- if (!tr.steps.find(_utils.stepHasSlice)) {
23
- return pluginState;
24
- }
25
- var newBidiWarningsDecorationSet = createBidiWarningsDecorationSetFromDoc({
26
- doc: tr.doc,
27
- codeBidiWarningLabel: pluginState.codeBidiWarningLabel,
28
- tooltipEnabled: pluginState.tooltipEnabled
29
- });
30
- return _objectSpread(_objectSpread({}, pluginState), {}, {
31
- decorationSet: newBidiWarningsDecorationSet
32
- });
33
- }
34
- });
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
- */
51
- function createBidiWarningsDecorationSetFromDoc(_ref) {
52
- var doc = _ref.doc,
53
- codeBidiWarningLabel = _ref.codeBidiWarningLabel,
54
- tooltipEnabled = _ref.tooltipEnabled;
55
- var bidiCharactersAndTheirPositions = [];
56
- doc.descendants(function (node, pos) {
57
- var isTextWithCodeMark = node.type.name === 'text' && node.marks && node.marks.some(function (mark) {
58
- return mark.type.name === 'code';
59
- });
60
- if (isTextWithCodeMark) {
61
- (0, _bidiWarningDecorator.default)(node.textContent, function (_ref2) {
62
- var bidiCharacter = _ref2.bidiCharacter,
63
- index = _ref2.index;
64
- bidiCharactersAndTheirPositions.push({
65
- // Ignored via go/ees005
66
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
67
- position: pos + index,
68
- bidiCharacter: bidiCharacter
69
- });
70
- });
71
- return false;
72
- }
73
- var isCodeBlock = node.type.name === 'codeBlock';
74
- if (isCodeBlock) {
75
- (0, _bidiWarningDecorator.default)(node.textContent, function (_ref3) {
76
- var bidiCharacter = _ref3.bidiCharacter,
77
- index = _ref3.index;
78
- bidiCharactersAndTheirPositions.push({
79
- // Ignored via go/ees005
80
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
81
- position: pos + index + 1,
82
- bidiCharacter: bidiCharacter
83
- });
84
- });
85
- }
86
- });
87
-
88
- // Bidi characters are not expected to commonly appear in code snippets, so recreating the decoration set
89
- // for documents rather than reusing existing decorations seems a reasonable performance/complexity tradeoff.
90
-
91
- if (bidiCharactersAndTheirPositions.length === 0) {
92
- return _view.DecorationSet.empty;
93
- }
94
- return _view.DecorationSet.create(doc, bidiCharactersAndTheirPositions.map(function (_ref4) {
95
- var position = _ref4.position,
96
- bidiCharacter = _ref4.bidiCharacter;
97
- return _view.Decoration.widget(position, function () {
98
- return renderDOM(bidiCharacter, codeBidiWarningLabel, tooltipEnabled);
99
- }, {
100
- destroy: function destroy(node) {
101
- assertIsElement(node);
102
- node.remove();
103
- }
104
- });
105
- }));
106
- }
107
- function renderDOM(bidiCharacter, codeBidiWarningLabel, tooltipEnabled) {
108
- var spec = (0, _codeBidiWarningDomSpec.getCodeBidiWarningDomSpec)(bidiCharacter, codeBidiWarningLabel, tooltipEnabled);
109
- var _DOMSerializer$render = _model.DOMSerializer.renderSpec(document, spec),
110
- dom = _DOMSerializer$render.dom;
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);
114
- return dom;
115
- }
@@ -1,26 +0,0 @@
1
- export function getCodeBidiWarningDomSpec(bidiCharacter, codeBidiWarningLabel, tooltipEnabled) {
2
- var _bidiCharacter$codePo, _bidiCharacter$codePo2;
3
- const bidiCharacterCode = `U+${(_bidiCharacter$codePo = bidiCharacter.codePointAt(0)) === null || _bidiCharacter$codePo === void 0 ? void 0 : (_bidiCharacter$codePo2 = _bidiCharacter$codePo.toString(16)) === null || _bidiCharacter$codePo2 === void 0 ? void 0 : _bidiCharacter$codePo2.toUpperCase()}`;
4
- return ['span', {
5
- 'data-prosemirror-node-name': 'code-bidi-warning',
6
- dir: 'ltr'
7
- },
8
- // Code Bidi Warning Decorator
9
- ['span', {
10
- 'data-bidi-component': 'code-bidi-warning-decorator',
11
- 'data-testid': 'code-bidi-warning-decorator',
12
- 'data-bidi-character-code': bidiCharacterCode,
13
- role: 'mark'
14
- },
15
- // Mark the < and > characters as visually hidden for screen readers
16
- ['span', {
17
- 'aria-hidden': 'true'
18
- }, '<'], bidiCharacterCode, ['span', {
19
- 'aria-hidden': 'true'
20
- }, '>']],
21
- // Code Bidi Warning Tooltip
22
- ...(tooltipEnabled ? [['span', {
23
- 'data-bidi-component': 'code-bidi-warning-tooltip',
24
- role: 'tooltip'
25
- }, codeBidiWarningLabel]] : [])];
26
- }
@@ -1,104 +0,0 @@
1
- import codeBidiWarningDecorator from '@atlaskit/code/bidi-warning-decorator';
2
- import { pluginFactory, stepHasSlice } from '@atlaskit/editor-common/utils';
3
- import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
4
- import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
5
- import { getCodeBidiWarningDomSpec } from './codeBidiWarningDomSpec';
6
- import { codeBidiWarningPluginKey } from './plugin-key';
7
- import reducer from './reducer';
8
- export const pluginFactoryCreator = () => pluginFactory(codeBidiWarningPluginKey, reducer, {
9
- onDocChanged: (tr, pluginState) => {
10
- if (!tr.steps.find(stepHasSlice)) {
11
- return pluginState;
12
- }
13
- const newBidiWarningsDecorationSet = createBidiWarningsDecorationSetFromDoc({
14
- doc: tr.doc,
15
- codeBidiWarningLabel: pluginState.codeBidiWarningLabel,
16
- tooltipEnabled: pluginState.tooltipEnabled
17
- });
18
- return {
19
- ...pluginState,
20
- decorationSet: newBidiWarningsDecorationSet
21
- };
22
- }
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
- */
39
- export function createBidiWarningsDecorationSetFromDoc({
40
- doc,
41
- codeBidiWarningLabel,
42
- tooltipEnabled
43
- }) {
44
- const bidiCharactersAndTheirPositions = [];
45
- doc.descendants((node, pos) => {
46
- const isTextWithCodeMark = node.type.name === 'text' && node.marks && node.marks.some(mark => mark.type.name === 'code');
47
- if (isTextWithCodeMark) {
48
- codeBidiWarningDecorator(node.textContent, ({
49
- bidiCharacter,
50
- index
51
- }) => {
52
- bidiCharactersAndTheirPositions.push({
53
- // Ignored via go/ees005
54
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
55
- position: pos + index,
56
- bidiCharacter
57
- });
58
- });
59
- return false;
60
- }
61
- const isCodeBlock = node.type.name === 'codeBlock';
62
- if (isCodeBlock) {
63
- codeBidiWarningDecorator(node.textContent, ({
64
- bidiCharacter,
65
- index
66
- }) => {
67
- bidiCharactersAndTheirPositions.push({
68
- // Ignored via go/ees005
69
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
70
- position: pos + index + 1,
71
- bidiCharacter
72
- });
73
- });
74
- }
75
- });
76
-
77
- // Bidi characters are not expected to commonly appear in code snippets, so recreating the decoration set
78
- // for documents rather than reusing existing decorations seems a reasonable performance/complexity tradeoff.
79
-
80
- if (bidiCharactersAndTheirPositions.length === 0) {
81
- return DecorationSet.empty;
82
- }
83
- return DecorationSet.create(doc, bidiCharactersAndTheirPositions.map(({
84
- position,
85
- bidiCharacter
86
- }) => {
87
- return Decoration.widget(position, () => renderDOM(bidiCharacter, codeBidiWarningLabel, tooltipEnabled), {
88
- destroy: node => {
89
- assertIsElement(node);
90
- node.remove();
91
- }
92
- });
93
- }));
94
- }
95
- function renderDOM(bidiCharacter, codeBidiWarningLabel, tooltipEnabled) {
96
- const spec = getCodeBidiWarningDomSpec(bidiCharacter, codeBidiWarningLabel, tooltipEnabled);
97
- const {
98
- dom
99
- } = DOMSerializer.renderSpec(document, spec);
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);
103
- return dom;
104
- }
@@ -1,25 +0,0 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
- export function getCodeBidiWarningDomSpec(bidiCharacter, codeBidiWarningLabel, tooltipEnabled) {
3
- var _bidiCharacter$codePo;
4
- var bidiCharacterCode = "U+".concat((_bidiCharacter$codePo = bidiCharacter.codePointAt(0)) === null || _bidiCharacter$codePo === void 0 || (_bidiCharacter$codePo = _bidiCharacter$codePo.toString(16)) === null || _bidiCharacter$codePo === void 0 ? void 0 : _bidiCharacter$codePo.toUpperCase());
5
- return ['span', {
6
- 'data-prosemirror-node-name': 'code-bidi-warning',
7
- dir: 'ltr'
8
- },
9
- // Code Bidi Warning Decorator
10
- ['span', {
11
- 'data-bidi-component': 'code-bidi-warning-decorator',
12
- 'data-testid': 'code-bidi-warning-decorator',
13
- 'data-bidi-character-code': bidiCharacterCode,
14
- role: 'mark'
15
- },
16
- // Mark the < and > characters as visually hidden for screen readers
17
- ['span', {
18
- 'aria-hidden': 'true'
19
- }, '<'], bidiCharacterCode, ['span', {
20
- 'aria-hidden': 'true'
21
- }, '>']]].concat(_toConsumableArray(tooltipEnabled ? [['span', {
22
- 'data-bidi-component': 'code-bidi-warning-tooltip',
23
- role: 'tooltip'
24
- }, codeBidiWarningLabel]] : []));
25
- }
@@ -1,107 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
- import codeBidiWarningDecorator from '@atlaskit/code/bidi-warning-decorator';
5
- import { pluginFactory, stepHasSlice } from '@atlaskit/editor-common/utils';
6
- import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
7
- import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
8
- import { getCodeBidiWarningDomSpec } from './codeBidiWarningDomSpec';
9
- import { codeBidiWarningPluginKey } from './plugin-key';
10
- import reducer from './reducer';
11
- export var pluginFactoryCreator = function pluginFactoryCreator() {
12
- return pluginFactory(codeBidiWarningPluginKey, reducer, {
13
- onDocChanged: function onDocChanged(tr, pluginState) {
14
- if (!tr.steps.find(stepHasSlice)) {
15
- return pluginState;
16
- }
17
- var newBidiWarningsDecorationSet = createBidiWarningsDecorationSetFromDoc({
18
- doc: tr.doc,
19
- codeBidiWarningLabel: pluginState.codeBidiWarningLabel,
20
- tooltipEnabled: pluginState.tooltipEnabled
21
- });
22
- return _objectSpread(_objectSpread({}, pluginState), {}, {
23
- decorationSet: newBidiWarningsDecorationSet
24
- });
25
- }
26
- });
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
- */
43
- export function createBidiWarningsDecorationSetFromDoc(_ref) {
44
- var doc = _ref.doc,
45
- codeBidiWarningLabel = _ref.codeBidiWarningLabel,
46
- tooltipEnabled = _ref.tooltipEnabled;
47
- var bidiCharactersAndTheirPositions = [];
48
- doc.descendants(function (node, pos) {
49
- var isTextWithCodeMark = node.type.name === 'text' && node.marks && node.marks.some(function (mark) {
50
- return mark.type.name === 'code';
51
- });
52
- if (isTextWithCodeMark) {
53
- codeBidiWarningDecorator(node.textContent, function (_ref2) {
54
- var bidiCharacter = _ref2.bidiCharacter,
55
- index = _ref2.index;
56
- bidiCharactersAndTheirPositions.push({
57
- // Ignored via go/ees005
58
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
59
- position: pos + index,
60
- bidiCharacter: bidiCharacter
61
- });
62
- });
63
- return false;
64
- }
65
- var isCodeBlock = node.type.name === 'codeBlock';
66
- if (isCodeBlock) {
67
- codeBidiWarningDecorator(node.textContent, function (_ref3) {
68
- var bidiCharacter = _ref3.bidiCharacter,
69
- index = _ref3.index;
70
- bidiCharactersAndTheirPositions.push({
71
- // Ignored via go/ees005
72
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
73
- position: pos + index + 1,
74
- bidiCharacter: bidiCharacter
75
- });
76
- });
77
- }
78
- });
79
-
80
- // Bidi characters are not expected to commonly appear in code snippets, so recreating the decoration set
81
- // for documents rather than reusing existing decorations seems a reasonable performance/complexity tradeoff.
82
-
83
- if (bidiCharactersAndTheirPositions.length === 0) {
84
- return DecorationSet.empty;
85
- }
86
- return DecorationSet.create(doc, bidiCharactersAndTheirPositions.map(function (_ref4) {
87
- var position = _ref4.position,
88
- bidiCharacter = _ref4.bidiCharacter;
89
- return Decoration.widget(position, function () {
90
- return renderDOM(bidiCharacter, codeBidiWarningLabel, tooltipEnabled);
91
- }, {
92
- destroy: function destroy(node) {
93
- assertIsElement(node);
94
- node.remove();
95
- }
96
- });
97
- }));
98
- }
99
- function renderDOM(bidiCharacter, codeBidiWarningLabel, tooltipEnabled) {
100
- var spec = getCodeBidiWarningDomSpec(bidiCharacter, codeBidiWarningLabel, tooltipEnabled);
101
- var _DOMSerializer$render = DOMSerializer.renderSpec(document, spec),
102
- dom = _DOMSerializer$render.dom;
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);
106
- return dom;
107
- }
@@ -1,2 +0,0 @@
1
- import { type DOMOutputSpec } from '@atlaskit/editor-prosemirror/model';
2
- export declare function getCodeBidiWarningDomSpec(bidiCharacter: string, codeBidiWarningLabel: string, tooltipEnabled: boolean): DOMOutputSpec;
@@ -1,20 +0,0 @@
1
- import { type Node as PmNode } from '@atlaskit/editor-prosemirror/model';
2
- import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
3
- export declare const pluginFactoryCreator: () => {
4
- createCommand: <A = unknown>(action: A | ((state: Readonly<import("prosemirror-state").EditorState>) => false | A), transform?: (tr: import("prosemirror-state").Transaction, state: import("prosemirror-state").EditorState) => import("prosemirror-state").Transaction) => import("@atlaskit/editor-common/types").Command;
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
- getPluginState: (state: import("prosemirror-state").EditorState) => import("./types").CodeBidiWarningPluginState;
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
- */
16
- export declare function createBidiWarningsDecorationSetFromDoc({ doc, codeBidiWarningLabel, tooltipEnabled, }: {
17
- codeBidiWarningLabel: string;
18
- doc: PmNode;
19
- tooltipEnabled: boolean;
20
- }): DecorationSet;
@@ -1,2 +0,0 @@
1
- import { type DOMOutputSpec } from '@atlaskit/editor-prosemirror/model';
2
- export declare function getCodeBidiWarningDomSpec(bidiCharacter: string, codeBidiWarningLabel: string, tooltipEnabled: boolean): DOMOutputSpec;
@@ -1,20 +0,0 @@
1
- import { type Node as PmNode } from '@atlaskit/editor-prosemirror/model';
2
- import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
3
- export declare const pluginFactoryCreator: () => {
4
- createCommand: <A = unknown>(action: A | ((state: Readonly<import("prosemirror-state").EditorState>) => false | A), transform?: (tr: import("prosemirror-state").Transaction, state: import("prosemirror-state").EditorState) => import("prosemirror-state").Transaction) => import("@atlaskit/editor-common/types").Command;
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
- getPluginState: (state: import("prosemirror-state").EditorState) => import("./types").CodeBidiWarningPluginState;
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
- */
16
- export declare function createBidiWarningsDecorationSetFromDoc({ doc, codeBidiWarningLabel, tooltipEnabled, }: {
17
- codeBidiWarningLabel: string;
18
- doc: PmNode;
19
- tooltipEnabled: boolean;
20
- }): DecorationSet;