@atlaskit/editor-core 151.0.0 → 151.1.0

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/cjs/create-editor/create-plugins-list.js +4 -0
  3. package/dist/cjs/plugins/code-bidi-warning/index.js +25 -0
  4. package/dist/cjs/plugins/code-bidi-warning/plugin-key.js +11 -0
  5. package/dist/cjs/plugins/code-bidi-warning/pm-plugins/main.js +43 -0
  6. package/dist/cjs/plugins/code-bidi-warning/pm-plugins/plugin-factory.js +118 -0
  7. package/dist/cjs/plugins/code-bidi-warning/pm-plugins/reducer.js +12 -0
  8. package/dist/cjs/plugins/code-bidi-warning/pm-plugins/types.js +5 -0
  9. package/dist/cjs/plugins/code-block/index.js +10 -6
  10. package/dist/cjs/plugins/code-block/nodeviews/highlighting-code-block.js +16 -5
  11. package/dist/cjs/plugins/code-block/pm-plugins/main.js +12 -3
  12. package/dist/cjs/plugins/feature-flags-context/feature-flags-from-props.js +3 -2
  13. package/dist/cjs/plugins/index.js +8 -0
  14. package/dist/cjs/plugins/rank.js +1 -1
  15. package/dist/cjs/version-wrapper.js +1 -1
  16. package/dist/cjs/version.json +1 -1
  17. package/dist/es2019/create-editor/create-plugins-list.js +5 -1
  18. package/dist/es2019/plugins/code-bidi-warning/index.js +15 -0
  19. package/dist/es2019/plugins/code-bidi-warning/plugin-key.js +2 -0
  20. package/dist/es2019/plugins/code-bidi-warning/pm-plugins/main.js +31 -0
  21. package/dist/es2019/plugins/code-bidi-warning/pm-plugins/plugin-factory.js +88 -0
  22. package/dist/es2019/plugins/code-bidi-warning/pm-plugins/reducer.js +3 -0
  23. package/dist/es2019/plugins/code-bidi-warning/pm-plugins/types.js +1 -0
  24. package/dist/es2019/plugins/code-block/index.js +6 -1
  25. package/dist/es2019/plugins/code-block/nodeviews/highlighting-code-block.js +16 -4
  26. package/dist/es2019/plugins/code-block/pm-plugins/main.js +50 -39
  27. package/dist/es2019/plugins/feature-flags-context/feature-flags-from-props.js +3 -2
  28. package/dist/es2019/plugins/index.js +2 -1
  29. package/dist/es2019/plugins/rank.js +1 -1
  30. package/dist/es2019/version-wrapper.js +1 -1
  31. package/dist/es2019/version.json +1 -1
  32. package/dist/esm/create-editor/create-plugins-list.js +5 -1
  33. package/dist/esm/plugins/code-bidi-warning/index.js +17 -0
  34. package/dist/esm/plugins/code-bidi-warning/plugin-key.js +2 -0
  35. package/dist/esm/plugins/code-bidi-warning/pm-plugins/main.js +30 -0
  36. package/dist/esm/plugins/code-bidi-warning/pm-plugins/plugin-factory.js +96 -0
  37. package/dist/esm/plugins/code-bidi-warning/pm-plugins/reducer.js +3 -0
  38. package/dist/esm/plugins/code-bidi-warning/pm-plugins/types.js +1 -0
  39. package/dist/esm/plugins/code-block/index.js +10 -6
  40. package/dist/esm/plugins/code-block/nodeviews/highlighting-code-block.js +16 -5
  41. package/dist/esm/plugins/code-block/pm-plugins/main.js +11 -3
  42. package/dist/esm/plugins/feature-flags-context/feature-flags-from-props.js +3 -2
  43. package/dist/esm/plugins/index.js +2 -1
  44. package/dist/esm/plugins/rank.js +1 -1
  45. package/dist/esm/version-wrapper.js +1 -1
  46. package/dist/esm/version.json +1 -1
  47. package/dist/types/plugins/code-bidi-warning/index.d.ts +3 -0
  48. package/dist/types/plugins/code-bidi-warning/plugin-key.d.ts +2 -0
  49. package/dist/types/plugins/code-bidi-warning/pm-plugins/main.d.ts +3 -0
  50. package/dist/types/plugins/code-bidi-warning/pm-plugins/plugin-factory.d.ts +7 -0
  51. package/dist/types/plugins/code-bidi-warning/pm-plugins/reducer.d.ts +3 -0
  52. package/dist/types/plugins/code-bidi-warning/pm-plugins/types.d.ts +5 -0
  53. package/dist/types/plugins/code-block/nodeviews/highlighting-code-block.d.ts +11 -2
  54. package/dist/types/plugins/code-block/pm-plugins/main.d.ts +5 -1
  55. package/dist/types/plugins/feature-flags-context/get-enabled-feature-flag-keys.d.ts +1 -1
  56. package/dist/types/plugins/index.d.ts +1 -0
  57. package/dist/types/types/feature-flags.d.ts +9 -0
  58. package/package.json +5 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @atlaskit/editor-core
2
2
 
3
+ ## 151.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`c80c71b537d`](https://bitbucket.org/atlassian/atlassian-frontend/commits/c80c71b537d) - [ux] ED-13860 add bidi warning decorations to code components
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+
3
13
  ## 151.0.0
4
14
 
5
15
  ### Major Changes
@@ -413,6 +413,10 @@ function createPluginsList(props, prevProps, createAnalyticsEvent) {
413
413
  preset.add([_plugins.viewUpdateSubscriptionPlugin]);
414
414
  }
415
415
 
416
+ if (featureFlags.codeBidiWarnings) {
417
+ preset.add(_plugins.codeBidiWarningPlugin);
418
+ }
419
+
416
420
  var excludes = new Set();
417
421
 
418
422
  if (!isCodeBlockAllowed({
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _main = require("./pm-plugins/main");
9
+
10
+ var codeBidiWarning = function codeBidiWarning() {
11
+ return {
12
+ name: 'codeBidiWarning',
13
+ pmPlugins: function pmPlugins() {
14
+ return [{
15
+ name: 'codeBidiWarning',
16
+ plugin: function plugin(options) {
17
+ return (0, _main.createPlugin)(options);
18
+ }
19
+ }];
20
+ }
21
+ };
22
+ };
23
+
24
+ var _default = codeBidiWarning;
25
+ exports.default = _default;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.codeBidiWarningPluginKey = void 0;
7
+
8
+ var _prosemirrorState = require("prosemirror-state");
9
+
10
+ var codeBidiWarningPluginKey = new _prosemirrorState.PluginKey('codeBidiWarningPlugin');
11
+ exports.codeBidiWarningPluginKey = codeBidiWarningPluginKey;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createPlugin = void 0;
7
+
8
+ var _prosemirrorState = require("prosemirror-state");
9
+
10
+ var _messages = require("@atlaskit/editor-common/messages");
11
+
12
+ var _pluginKey = require("../plugin-key");
13
+
14
+ var _pluginFactory = require("./plugin-factory");
15
+
16
+ var createPlugin = function createPlugin(_ref) {
17
+ var dispatch = _ref.dispatch,
18
+ reactContext = _ref.reactContext;
19
+ var intl = reactContext().intl;
20
+ var codeBidiWarningLabel = intl.formatMessage(_messages.codeBidiWarningMessages.label);
21
+ return new _prosemirrorState.Plugin({
22
+ key: _pluginKey.codeBidiWarningPluginKey,
23
+ state: (0, _pluginFactory.createPluginState)(dispatch, function (state) {
24
+ return {
25
+ decorationSet: (0, _pluginFactory.createBidiWarningsDecorationSetFromDoc)({
26
+ doc: state.doc,
27
+ codeBidiWarningLabel: codeBidiWarningLabel
28
+ }),
29
+ codeBidiWarningLabel: codeBidiWarningLabel
30
+ };
31
+ }),
32
+ props: {
33
+ decorations: function decorations(state) {
34
+ var _getPluginState = (0, _pluginFactory.getPluginState)(state),
35
+ decorationSet = _getPluginState.decorationSet;
36
+
37
+ return decorationSet;
38
+ }
39
+ }
40
+ });
41
+ };
42
+
43
+ exports.createPlugin = createPlugin;
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.createBidiWarningsDecorationSetFromDoc = createBidiWarningsDecorationSetFromDoc;
9
+ exports.getPluginState = exports.createPluginState = void 0;
10
+
11
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
12
+
13
+ var _react = _interopRequireDefault(require("react"));
14
+
15
+ var _reactDom = _interopRequireDefault(require("react-dom"));
16
+
17
+ var _prosemirrorView = require("prosemirror-view");
18
+
19
+ var _bidiWarning = _interopRequireDefault(require("@atlaskit/code/bidi-warning"));
20
+
21
+ var _bidiWarningDecorator = _interopRequireDefault(require("@atlaskit/code/bidi-warning-decorator"));
22
+
23
+ var _pluginStateFactory = require("../../../utils/plugin-state-factory");
24
+
25
+ var _step = require("../../../utils/step");
26
+
27
+ var _pluginKey = require("../plugin-key");
28
+
29
+ var _reducer = _interopRequireDefault(require("./reducer"));
30
+
31
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
32
+
33
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
34
+
35
+ var _pluginFactory = (0, _pluginStateFactory.pluginFactory)(_pluginKey.codeBidiWarningPluginKey, _reducer.default, {
36
+ onDocChanged: function onDocChanged(tr, pluginState) {
37
+ if (!tr.steps.find(_step.stepHasSlice)) {
38
+ return pluginState;
39
+ }
40
+
41
+ var newBidiWarningsDecorationSet = createBidiWarningsDecorationSetFromDoc({
42
+ doc: tr.doc,
43
+ codeBidiWarningLabel: pluginState.codeBidiWarningLabel
44
+ });
45
+ return _objectSpread(_objectSpread({}, pluginState), {}, {
46
+ decorationSet: newBidiWarningsDecorationSet
47
+ });
48
+ }
49
+ }),
50
+ createPluginState = _pluginFactory.createPluginState,
51
+ getPluginState = _pluginFactory.getPluginState;
52
+
53
+ exports.getPluginState = getPluginState;
54
+ exports.createPluginState = createPluginState;
55
+
56
+ function createBidiWarningsDecorationSetFromDoc(_ref) {
57
+ var doc = _ref.doc,
58
+ codeBidiWarningLabel = _ref.codeBidiWarningLabel;
59
+ var bidiCharactersAndTheirPositions = [];
60
+ doc.descendants(function (node, pos) {
61
+ var isTextWithCodeMark = node.type.name === 'text' && node.marks && node.marks.some(function (mark) {
62
+ return mark.type.name === 'code';
63
+ });
64
+
65
+ if (isTextWithCodeMark) {
66
+ (0, _bidiWarningDecorator.default)(node.textContent, function (_ref2) {
67
+ var bidiCharacter = _ref2.bidiCharacter,
68
+ index = _ref2.index;
69
+ bidiCharactersAndTheirPositions.push({
70
+ position: pos + index,
71
+ bidiCharacter: bidiCharacter
72
+ });
73
+ });
74
+ return false;
75
+ }
76
+
77
+ var isCodeBlock = node.type.name === 'codeBlock';
78
+
79
+ if (isCodeBlock) {
80
+ (0, _bidiWarningDecorator.default)(node.textContent, function (_ref3) {
81
+ var bidiCharacter = _ref3.bidiCharacter,
82
+ index = _ref3.index;
83
+ bidiCharactersAndTheirPositions.push({
84
+ position: pos + index + 1,
85
+ bidiCharacter: bidiCharacter
86
+ });
87
+ });
88
+ }
89
+ }); // Bidi characters are not expected to commonly appear in code snippets, so recreating the decoration set
90
+ // for documents rather than reusing existing decorations seems a reasonable performance/complexity tradeoff.
91
+
92
+ if (bidiCharactersAndTheirPositions.length === 0) {
93
+ return _prosemirrorView.DecorationSet.empty;
94
+ }
95
+
96
+ var newBidiWarningsDecorationSet = _prosemirrorView.DecorationSet.create(doc, bidiCharactersAndTheirPositions.map(function (_ref4) {
97
+ var position = _ref4.position,
98
+ bidiCharacter = _ref4.bidiCharacter;
99
+ return _prosemirrorView.Decoration.widget(position, function () {
100
+ return renderDOM(bidiCharacter, codeBidiWarningLabel);
101
+ });
102
+ }));
103
+
104
+ return newBidiWarningsDecorationSet;
105
+ }
106
+
107
+ function renderDOM(bidiCharacter, codeBidiWarningLabel) {
108
+ var element = document.createElement('span'); // Note: we use this pattern elsewhere (see highlighting code block, and drop cursor widget decoration)
109
+ // we should investigate if there is a memory leak with such usage.
110
+
111
+ _reactDom.default.render( /*#__PURE__*/_react.default.createElement(_bidiWarning.default, {
112
+ bidiCharacter: bidiCharacter,
113
+ skipChildren: true,
114
+ label: codeBidiWarningLabel
115
+ }), element);
116
+
117
+ return element;
118
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _default = function _default(pluginState, action) {
9
+ return pluginState;
10
+ };
11
+
12
+ exports.default = _default;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -40,8 +40,12 @@ var codeBlockPlugin = function codeBlockPlugin() {
40
40
  pmPlugins: function pmPlugins() {
41
41
  return [{
42
42
  name: 'codeBlock',
43
- plugin: function plugin() {
44
- return (0, _main.createPlugin)(options.useLongPressSelection);
43
+ plugin: function plugin(_ref) {
44
+ var reactContext = _ref.reactContext;
45
+ return (0, _main.createPlugin)({
46
+ useLongPressSelection: options.useLongPressSelection,
47
+ reactContext: reactContext
48
+ });
45
49
  }
46
50
  }, {
47
51
  name: 'codeBlockIDEKeyBindings',
@@ -50,8 +54,8 @@ var codeBlockPlugin = function codeBlockPlugin() {
50
54
  }
51
55
  }, {
52
56
  name: 'codeBlockKeyMap',
53
- plugin: function plugin(_ref) {
54
- var schema = _ref.schema;
57
+ plugin: function plugin(_ref2) {
58
+ var schema = _ref2.schema;
55
59
  return (0, _keymaps.default)(schema);
56
60
  }
57
61
  }];
@@ -62,8 +66,8 @@ var codeBlockPlugin = function codeBlockPlugin() {
62
66
  (0, _refreshBrowserSelection.default)(props.originalTransaction, props.newEditorState);
63
67
  },
64
68
  pluginsOptions: {
65
- quickInsert: function quickInsert(_ref2) {
66
- var formatMessage = _ref2.formatMessage;
69
+ quickInsert: function quickInsert(_ref3) {
70
+ var formatMessage = _ref3.formatMessage;
67
71
  return [{
68
72
  id: 'codeblock',
69
73
  title: formatMessage(_messages.messages.codeblock),
@@ -50,7 +50,7 @@ var toDOM = function toDOM(node) {
50
50
  };
51
51
 
52
52
  var CodeBlockView = /*#__PURE__*/function () {
53
- function CodeBlockView(_node, view, getPos) {
53
+ function CodeBlockView(_node, view, getPos, codeBidiWarningOptions) {
54
54
  var _this = this;
55
55
 
56
56
  (0, _classCallCheck2.default)(this, CodeBlockView);
@@ -77,6 +77,7 @@ var CodeBlockView = /*#__PURE__*/function () {
77
77
  dom = _DOMSerializer$render.dom,
78
78
  contentDOM = _DOMSerializer$render.contentDOM;
79
79
 
80
+ this.codeBidiWarningOptions = codeBidiWarningOptions;
80
81
  this.getPos = getPos;
81
82
  this.view = view;
82
83
  this.node = _node;
@@ -130,7 +131,9 @@ var CodeBlockView = /*#__PURE__*/function () {
130
131
  _reactDom.default.render( /*#__PURE__*/_react.default.createElement(_code.CodeBlock, {
131
132
  text: node.textContent,
132
133
  language: node.attrs.language,
133
- showLineNumbers: false
134
+ showLineNumbers: false,
135
+ codeBidiWarnings: this.codeBidiWarningOptions.enabled,
136
+ codeBidiWarningLabel: this.codeBidiWarningOptions.label
134
137
  }), highlighting);
135
138
 
136
139
  this.measure(performance.now() - start);
@@ -164,7 +167,10 @@ var CodeBlockView = /*#__PURE__*/function () {
164
167
  value: function ignoreMutation(record) {
165
168
  var _this$highlighting$co, _this$highlighting;
166
169
 
167
- return record.target === this.lineNumberGutter || record.target.parentNode === this.lineNumberGutter || ((_this$highlighting$co = (_this$highlighting = this.highlighting) === null || _this$highlighting === void 0 ? void 0 : _this$highlighting.contains(record.target)) !== null && _this$highlighting$co !== void 0 ? _this$highlighting$co : false);
170
+ var lineNumberChanges = record.target === this.lineNumberGutter || record.target.parentNode === this.lineNumberGutter;
171
+ var outsideTheCodeBlockChanges = (_this$highlighting$co = (_this$highlighting = this.highlighting) === null || _this$highlighting === void 0 ? void 0 : _this$highlighting.contains(record.target)) !== null && _this$highlighting$co !== void 0 ? _this$highlighting$co : false;
172
+ var codeBidiWarningDecorationChanges = record.type === 'attributes' && record.attributeName === 'aria-describedby';
173
+ return lineNumberChanges || outsideTheCodeBlockChanges || codeBidiWarningDecorationChanges;
168
174
  }
169
175
  }]);
170
176
  return CodeBlockView;
@@ -172,9 +178,14 @@ var CodeBlockView = /*#__PURE__*/function () {
172
178
 
173
179
  exports.CodeBlockView = CodeBlockView;
174
180
 
175
- var highlightingCodeBlockNodeView = function highlightingCodeBlockNodeView() {
181
+ var highlightingCodeBlockNodeView = function highlightingCodeBlockNodeView(_ref) {
182
+ var codeBidiWarnings = _ref.codeBidiWarnings,
183
+ codeBidiWarningLabel = _ref.codeBidiWarningLabel;
176
184
  return function (node, view, getPos) {
177
- return new CodeBlockView(node, view, getPos);
185
+ return new CodeBlockView(node, view, getPos, {
186
+ enabled: codeBidiWarnings,
187
+ label: codeBidiWarningLabel
188
+ });
178
189
  };
179
190
  };
180
191
 
@@ -11,6 +11,8 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
11
11
 
12
12
  var _prosemirrorState = require("prosemirror-state");
13
13
 
14
+ var _messages = require("@atlaskit/editor-common/messages");
15
+
14
16
  var _codeBlock = require("../nodeviews/code-block");
15
17
 
16
18
  var _highlightingCodeBlock = require("../nodeviews/highlighting-code-block");
@@ -31,8 +33,12 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
31
33
 
32
34
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
33
35
 
34
- var createPlugin = function createPlugin() {
35
- var useLongPressSelection = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
36
+ var createPlugin = function createPlugin(_ref) {
37
+ var _ref$useLongPressSele = _ref.useLongPressSelection,
38
+ useLongPressSelection = _ref$useLongPressSele === void 0 ? false : _ref$useLongPressSele,
39
+ reactContext = _ref.reactContext;
40
+ var intl = reactContext().intl;
41
+ var codeBidiWarningLabel = intl.formatMessage(_messages.codeBidiWarningMessages.label);
36
42
  return new _prosemirrorState.Plugin({
37
43
  state: {
38
44
  init: function init(_, state) {
@@ -71,7 +77,10 @@ var createPlugin = function createPlugin() {
71
77
  nodeViews: {
72
78
  codeBlock: function codeBlock(node, view, getPos) {
73
79
  var featureFlags = (0, _featureFlagsContext.getFeatureFlags)(view.state);
74
- var createCodeBlockNodeView = featureFlags !== null && featureFlags !== void 0 && featureFlags.codeBlockSyntaxHighlighting ? (0, _highlightingCodeBlock.highlightingCodeBlockNodeView)() : (0, _codeBlock.codeBlockNodeView)();
80
+ var createCodeBlockNodeView = featureFlags !== null && featureFlags !== void 0 && featureFlags.codeBlockSyntaxHighlighting ? (0, _highlightingCodeBlock.highlightingCodeBlockNodeView)({
81
+ codeBidiWarnings: featureFlags === null || featureFlags === void 0 ? void 0 : featureFlags.codeBidiWarnings,
82
+ codeBidiWarningLabel: codeBidiWarningLabel
83
+ }) : (0, _codeBlock.codeBlockNodeView)();
75
84
  return createCodeBlockNodeView(node, view, getPos);
76
85
  }
77
86
  },
@@ -24,7 +24,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
24
24
  * which is used by both current and archv3 editors.
25
25
  */
26
26
  function createFeatureFlagsFromProps(props) {
27
- var _props$allowTextColor, _props$performanceTra, _props$performanceTra2, _props$featureFlags, _props$featureFlags2, _props$featureFlags3, _props$allowTables, _props$featureFlags4, _props$featureFlags5, _props$allowTables2, _props$featureFlags6, _props$featureFlags7, _props$allowTables3, _props$featureFlags8, _props$featureFlags9, _props$allowTables4, _props$featureFlags10, _props$featureFlags11, _props$allowTables5, _props$allowExtension, _props$featureFlags12, _props$featureFlags13, _props$featureFlags14, _props$featureFlags15, _props$featureFlags16, _props$featureFlags17, _props$featureFlags18, _props$featureFlags19, _props$featureFlags20, _props$featureFlags21, _props$featureFlags22, _props$featureFlags23, _props$featureFlags24, _props$featureFlags25, _props$featureFlags26, _props$featureFlags27;
27
+ var _props$allowTextColor, _props$performanceTra, _props$performanceTra2, _props$featureFlags, _props$featureFlags2, _props$featureFlags3, _props$allowTables, _props$featureFlags4, _props$featureFlags5, _props$allowTables2, _props$featureFlags6, _props$featureFlags7, _props$allowTables3, _props$featureFlags8, _props$featureFlags9, _props$allowTables4, _props$featureFlags10, _props$featureFlags11, _props$allowTables5, _props$allowExtension, _props$featureFlags12, _props$featureFlags13, _props$featureFlags14, _props$featureFlags15, _props$featureFlags16, _props$featureFlags17, _props$featureFlags18, _props$featureFlags19, _props$featureFlags20, _props$featureFlags21, _props$featureFlags22, _props$featureFlags23, _props$featureFlags24, _props$featureFlags25, _props$featureFlags26, _props$featureFlags27, _props$featureFlags28, _props$featureFlags29;
28
28
 
29
29
  var normalizedFeatureFlags = (0, _normalizeFeatureFlags.normalizeFeatureFlags)(props.featureFlags);
30
30
  return _objectSpread(_objectSpread({}, normalizedFeatureFlags), {}, {
@@ -54,6 +54,7 @@ function createFeatureFlagsFromProps(props) {
54
54
  enableViewUpdateSubscription: Boolean(typeof ((_props$featureFlags22 = props.featureFlags) === null || _props$featureFlags22 === void 0 ? void 0 : _props$featureFlags22.enableViewUpdateSubscription) === 'boolean' ? !!((_props$featureFlags23 = props.featureFlags) !== null && _props$featureFlags23 !== void 0 && _props$featureFlags23.enableViewUpdateSubscription) : false),
55
55
  collabAvatarScroll: Boolean(typeof ((_props$featureFlags24 = props.featureFlags) === null || _props$featureFlags24 === void 0 ? void 0 : _props$featureFlags24.collabAvatarScroll) === 'boolean' ? !!((_props$featureFlags25 = props.featureFlags) !== null && _props$featureFlags25 !== void 0 && _props$featureFlags25.collabAvatarScroll) : false),
56
56
  ufo: Boolean(typeof ((_props$featureFlags26 = props.featureFlags) === null || _props$featureFlags26 === void 0 ? void 0 : _props$featureFlags26.ufo) === 'boolean' ? !!((_props$featureFlags27 = props.featureFlags) !== null && _props$featureFlags27 !== void 0 && _props$featureFlags27.ufo) : false),
57
- codeBlockSyntaxHighlighting: Boolean(typeof normalizedFeatureFlags.codeBlockSyntaxHighlighting === 'boolean' ? !!normalizedFeatureFlags.codeBlockSyntaxHighlighting && !_editorCommon.browser.safari : false)
57
+ codeBlockSyntaxHighlighting: Boolean(typeof normalizedFeatureFlags.codeBlockSyntaxHighlighting === 'boolean' ? !!normalizedFeatureFlags.codeBlockSyntaxHighlighting && !_editorCommon.browser.safari : false),
58
+ codeBidiWarnings: Boolean(typeof ((_props$featureFlags28 = props.featureFlags) === null || _props$featureFlags28 === void 0 ? void 0 : _props$featureFlags28.codeBidiWarnings) === 'boolean' ? !!((_props$featureFlags29 = props.featureFlags) !== null && _props$featureFlags29 !== void 0 && _props$featureFlags29.codeBidiWarnings) : true)
58
59
  });
59
60
  }
@@ -391,6 +391,12 @@ Object.defineProperty(exports, "viewUpdateSubscriptionPlugin", {
391
391
  return _viewUpdateSubscription.default;
392
392
  }
393
393
  });
394
+ Object.defineProperty(exports, "codeBidiWarningPlugin", {
395
+ enumerable: true,
396
+ get: function get() {
397
+ return _codeBidiWarning.default;
398
+ }
399
+ });
394
400
 
395
401
  var _base = _interopRequireDefault(require("./base"));
396
402
 
@@ -516,6 +522,8 @@ var _avatarGroup = _interopRequireDefault(require("./avatar-group"));
516
522
 
517
523
  var _viewUpdateSubscription = _interopRequireDefault(require("./view-update-subscription"));
518
524
 
525
+ var _codeBidiWarning = _interopRequireDefault(require("./code-bidi-warning"));
526
+
519
527
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
520
528
 
521
529
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -12,7 +12,7 @@ var _default = {
12
12
  // https://product-fabric.atlassian.net/wiki/spaces/E/pages/1113098008/Selection+Guide#Special-Cases
13
13
  'expandKeymap', 'tableSelectionKeymap', 'tableKeymap', 'captionKeymap', // selection keymap needs to be above gap cursor keymap so it can set node selections from
14
14
  // left/right arrows
15
- 'selectionKeymap', 'gapCursorKeymap', 'gapCursor', 'syncUrlText', 'fakeCursorToolbarPlugin', 'hyperLink', 'table', 'tableDecorations', 'hyperlinkInputRule', 'tablePMColResizing', 'hyperlinkKeymap', 'tableColResizing', 'undoRedoKeyMap', 'blockTypeKeyMap', 'tableEditing', 'filterStepsPlugin', 'pmCollab', 'collab', 'ruleInputRule', 'ruleKeymap', 'panel', 'media', 'mediaKeymap', 'mediaSingleKeymap', 'mediaEditor', 'unsupportedContent', 'jiraIssue', 'fakeTextCursor', 'helpDialog', 'helpDialogKeymap', 'macro', 'expand', 'extension', 'layout', 'contextPanel', 'floatingToolbar', 'clearMarksOnChange', 'reactNodeView', 'history', 'undoRedoPlugin', 'codeBlockIndent', 'placeholder', 'width', 'maxContentSize', 'multilineContent', 'grid', 'mobileDimensions', 'scrollGutterPlugin', 'analytics', 'findReplace', 'selection', 'avatarGroup', 'viewUpdateSubscription'],
15
+ 'selectionKeymap', 'gapCursorKeymap', 'gapCursor', 'syncUrlText', 'fakeCursorToolbarPlugin', 'hyperLink', 'table', 'tableDecorations', 'hyperlinkInputRule', 'tablePMColResizing', 'hyperlinkKeymap', 'tableColResizing', 'undoRedoKeyMap', 'blockTypeKeyMap', 'tableEditing', 'filterStepsPlugin', 'pmCollab', 'collab', 'ruleInputRule', 'ruleKeymap', 'panel', 'media', 'mediaKeymap', 'mediaSingleKeymap', 'mediaEditor', 'unsupportedContent', 'jiraIssue', 'fakeTextCursor', 'helpDialog', 'helpDialogKeymap', 'macro', 'expand', 'extension', 'layout', 'contextPanel', 'floatingToolbar', 'clearMarksOnChange', 'reactNodeView', 'history', 'undoRedoPlugin', 'codeBlockIndent', 'placeholder', 'width', 'maxContentSize', 'multilineContent', 'grid', 'mobileDimensions', 'scrollGutterPlugin', 'analytics', 'findReplace', 'selection', 'avatarGroup', 'viewUpdateSubscription', 'inlineCode'],
16
16
  nodes: ['doc', 'paragraph', 'text', 'bulletList', 'orderedList', 'listItem', 'heading', 'blockquote', 'codeBlock', 'rule', 'panel', 'mention', 'confluenceUnsupportedBlock', 'confluenceUnsupportedInline', 'unsupportedBlock', 'unsupportedInline', 'confluenceJiraIssue', 'hardBreak', 'emoji', 'placeholder', 'mediaSingle', 'mediaGroup', 'table', 'expand', 'nestedExpand', 'media', 'tableHeader', 'decisionList', 'tableRow', 'decisionItem', 'tableCell', 'taskList', 'taskItem', 'extension', 'bodiedExtension', 'inlineExtension', 'layoutSection', 'layoutColumn', 'inlineCard', 'blockCard', 'embedCard'],
17
17
  marks: [// Inline marks
18
18
  'link', 'em', 'strong', 'textColor', 'strike', 'subsup', 'underline', 'code', 'typeAheadQuery', // Block marks
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.nextMajorVersion = exports.version = exports.name = void 0;
7
7
  var name = "@atlaskit/editor-core";
8
8
  exports.name = name;
9
- var version = "151.0.0";
9
+ var version = "151.1.0";
10
10
  exports.version = version;
11
11
 
12
12
  var nextMajorVersion = function nextMajorVersion() {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "151.0.0",
3
+ "version": "151.1.0",
4
4
  "sideEffects": false
5
5
  }
@@ -1,4 +1,4 @@
1
- import { breakoutPlugin, collabEditPlugin, dataConsumerMarkPlugin, datePlugin, emojiPlugin, extensionPlugin, helpDialogPlugin, imageUploadPlugin, insertBlockPlugin, jiraIssuePlugin, layoutPlugin, listPlugin, macroPlugin, maxContentSizePlugin, mediaPlugin, mentionsPlugin, panelPlugin, placeholderTextPlugin, rulePlugin, saveOnEnterPlugin, tablesPlugin, tasksAndDecisionsPlugin, textColorPlugin, cardPlugin, gridPlugin, statusPlugin, alignmentPlugin, indentationPlugin, analyticsPlugin, customAutoformatPlugin, feedbackDialogPlugin, historyPlugin, expandPlugin, isExpandInsertionEnabled, scrollIntoViewPlugin, mobileDimensionsPlugin, findReplacePlugin, contextPanelPlugin, mobileSelectionPlugin, annotationPlugin, captionPlugin, avatarGroupPlugin, viewUpdateSubscriptionPlugin } from '../plugins';
1
+ import { breakoutPlugin, collabEditPlugin, dataConsumerMarkPlugin, datePlugin, emojiPlugin, extensionPlugin, helpDialogPlugin, imageUploadPlugin, insertBlockPlugin, jiraIssuePlugin, layoutPlugin, listPlugin, macroPlugin, maxContentSizePlugin, mediaPlugin, mentionsPlugin, panelPlugin, placeholderTextPlugin, rulePlugin, saveOnEnterPlugin, tablesPlugin, tasksAndDecisionsPlugin, textColorPlugin, cardPlugin, gridPlugin, statusPlugin, alignmentPlugin, indentationPlugin, analyticsPlugin, customAutoformatPlugin, feedbackDialogPlugin, historyPlugin, expandPlugin, isExpandInsertionEnabled, scrollIntoViewPlugin, mobileDimensionsPlugin, findReplacePlugin, contextPanelPlugin, mobileSelectionPlugin, annotationPlugin, captionPlugin, avatarGroupPlugin, viewUpdateSubscriptionPlugin, codeBidiWarningPlugin } from '../plugins';
2
2
  import { isFullPage as fullPageCheck } from '../utils/is-full-page';
3
3
  import { GUTTER_SIZE_MOBILE_IN_PX } from '../plugins/base/pm-plugins/scroll-gutter';
4
4
  import { createFeatureFlagsFromProps } from '../plugins/feature-flags-context/feature-flags-from-props';
@@ -389,6 +389,10 @@ export default function createPluginsList(props, prevProps, createAnalyticsEvent
389
389
  preset.add([viewUpdateSubscriptionPlugin]);
390
390
  }
391
391
 
392
+ if (featureFlags.codeBidiWarnings) {
393
+ preset.add(codeBidiWarningPlugin);
394
+ }
395
+
392
396
  const excludes = new Set();
393
397
 
394
398
  if (!isCodeBlockAllowed({
@@ -0,0 +1,15 @@
1
+ import { createPlugin } from './pm-plugins/main';
2
+
3
+ const codeBidiWarning = () => ({
4
+ name: 'codeBidiWarning',
5
+
6
+ pmPlugins() {
7
+ return [{
8
+ name: 'codeBidiWarning',
9
+ plugin: options => createPlugin(options)
10
+ }];
11
+ }
12
+
13
+ });
14
+
15
+ export default codeBidiWarning;
@@ -0,0 +1,2 @@
1
+ import { PluginKey } from 'prosemirror-state';
2
+ export const codeBidiWarningPluginKey = new PluginKey('codeBidiWarningPlugin');
@@ -0,0 +1,31 @@
1
+ import { Plugin } from 'prosemirror-state';
2
+ import { codeBidiWarningMessages } from '@atlaskit/editor-common/messages';
3
+ import { codeBidiWarningPluginKey } from '../plugin-key';
4
+ import { createBidiWarningsDecorationSetFromDoc, createPluginState, getPluginState } from './plugin-factory';
5
+ export const createPlugin = ({
6
+ dispatch,
7
+ reactContext
8
+ }) => {
9
+ const intl = reactContext().intl;
10
+ const codeBidiWarningLabel = intl.formatMessage(codeBidiWarningMessages.label);
11
+ return new Plugin({
12
+ key: codeBidiWarningPluginKey,
13
+ state: createPluginState(dispatch, state => {
14
+ return {
15
+ decorationSet: createBidiWarningsDecorationSetFromDoc({
16
+ doc: state.doc,
17
+ codeBidiWarningLabel
18
+ }),
19
+ codeBidiWarningLabel
20
+ };
21
+ }),
22
+ props: {
23
+ decorations: state => {
24
+ const {
25
+ decorationSet
26
+ } = getPluginState(state);
27
+ return decorationSet;
28
+ }
29
+ }
30
+ });
31
+ };
@@ -0,0 +1,88 @@
1
+ import React from 'react';
2
+ import ReactDOM from 'react-dom';
3
+ import { Decoration, DecorationSet } from 'prosemirror-view';
4
+ import CodeBidiWarning from '@atlaskit/code/bidi-warning';
5
+ import codeBidiWarningDecorator from '@atlaskit/code/bidi-warning-decorator';
6
+ import { pluginFactory } from '../../../utils/plugin-state-factory';
7
+ import { stepHasSlice } from '../../../utils/step';
8
+ import { codeBidiWarningPluginKey } from '../plugin-key';
9
+ import reducer from './reducer';
10
+ export const {
11
+ createPluginState,
12
+ getPluginState
13
+ } = pluginFactory(codeBidiWarningPluginKey, reducer, {
14
+ onDocChanged: (tr, pluginState) => {
15
+ if (!tr.steps.find(stepHasSlice)) {
16
+ return pluginState;
17
+ }
18
+
19
+ const newBidiWarningsDecorationSet = createBidiWarningsDecorationSetFromDoc({
20
+ doc: tr.doc,
21
+ codeBidiWarningLabel: pluginState.codeBidiWarningLabel
22
+ });
23
+ return { ...pluginState,
24
+ decorationSet: newBidiWarningsDecorationSet
25
+ };
26
+ }
27
+ });
28
+ export function createBidiWarningsDecorationSetFromDoc({
29
+ doc,
30
+ codeBidiWarningLabel
31
+ }) {
32
+ const bidiCharactersAndTheirPositions = [];
33
+ doc.descendants((node, pos) => {
34
+ const isTextWithCodeMark = node.type.name === 'text' && node.marks && node.marks.some(mark => mark.type.name === 'code');
35
+
36
+ if (isTextWithCodeMark) {
37
+ codeBidiWarningDecorator(node.textContent, ({
38
+ bidiCharacter,
39
+ index
40
+ }) => {
41
+ bidiCharactersAndTheirPositions.push({
42
+ position: pos + index,
43
+ bidiCharacter
44
+ });
45
+ });
46
+ return false;
47
+ }
48
+
49
+ const isCodeBlock = node.type.name === 'codeBlock';
50
+
51
+ if (isCodeBlock) {
52
+ codeBidiWarningDecorator(node.textContent, ({
53
+ bidiCharacter,
54
+ index
55
+ }) => {
56
+ bidiCharactersAndTheirPositions.push({
57
+ position: pos + index + 1,
58
+ bidiCharacter
59
+ });
60
+ });
61
+ }
62
+ }); // Bidi characters are not expected to commonly appear in code snippets, so recreating the decoration set
63
+ // for documents rather than reusing existing decorations seems a reasonable performance/complexity tradeoff.
64
+
65
+ if (bidiCharactersAndTheirPositions.length === 0) {
66
+ return DecorationSet.empty;
67
+ }
68
+
69
+ const newBidiWarningsDecorationSet = DecorationSet.create(doc, bidiCharactersAndTheirPositions.map(({
70
+ position,
71
+ bidiCharacter
72
+ }) => {
73
+ return Decoration.widget(position, () => renderDOM(bidiCharacter, codeBidiWarningLabel));
74
+ }));
75
+ return newBidiWarningsDecorationSet;
76
+ }
77
+
78
+ function renderDOM(bidiCharacter, codeBidiWarningLabel) {
79
+ const element = document.createElement('span'); // Note: we use this pattern elsewhere (see highlighting code block, and drop cursor widget decoration)
80
+ // we should investigate if there is a memory leak with such usage.
81
+
82
+ ReactDOM.render( /*#__PURE__*/React.createElement(CodeBidiWarning, {
83
+ bidiCharacter: bidiCharacter,
84
+ skipChildren: true,
85
+ label: codeBidiWarningLabel
86
+ }), element);
87
+ return element;
88
+ }
@@ -0,0 +1,3 @@
1
+ export default ((pluginState, action) => {
2
+ return pluginState;
3
+ });
@@ -22,7 +22,12 @@ const codeBlockPlugin = (options = {}) => ({
22
22
  pmPlugins() {
23
23
  return [{
24
24
  name: 'codeBlock',
25
- plugin: () => createPlugin(options.useLongPressSelection)
25
+ plugin: ({
26
+ reactContext
27
+ }) => createPlugin({
28
+ useLongPressSelection: options.useLongPressSelection,
29
+ reactContext
30
+ })
26
31
  }, {
27
32
  name: 'codeBlockIDEKeyBindings',
28
33
  plugin: () => ideUX