@atlaskit/editor-plugin-code-bidi-warning 0.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 (39) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/LICENSE.md +13 -0
  3. package/README.md +39 -0
  4. package/dist/cjs/index.js +12 -0
  5. package/dist/cjs/plugin-key.js +8 -0
  6. package/dist/cjs/plugin.js +21 -0
  7. package/dist/cjs/pm-plugins/main.js +44 -0
  8. package/dist/cjs/pm-plugins/plugin-factory.js +104 -0
  9. package/dist/cjs/pm-plugins/reducer.js +9 -0
  10. package/dist/cjs/pm-plugins/types.js +5 -0
  11. package/dist/es2019/index.js +1 -0
  12. package/dist/es2019/plugin-key.js +2 -0
  13. package/dist/es2019/plugin.js +14 -0
  14. package/dist/es2019/pm-plugins/main.js +41 -0
  15. package/dist/es2019/pm-plugins/plugin-factory.js +96 -0
  16. package/dist/es2019/pm-plugins/reducer.js +3 -0
  17. package/dist/es2019/pm-plugins/types.js +1 -0
  18. package/dist/esm/index.js +1 -0
  19. package/dist/esm/plugin-key.js +2 -0
  20. package/dist/esm/plugin.js +15 -0
  21. package/dist/esm/pm-plugins/main.js +38 -0
  22. package/dist/esm/pm-plugins/plugin-factory.js +97 -0
  23. package/dist/esm/pm-plugins/reducer.js +3 -0
  24. package/dist/esm/pm-plugins/types.js +1 -0
  25. package/dist/types/index.d.ts +2 -0
  26. package/dist/types/plugin-key.d.ts +2 -0
  27. package/dist/types/plugin.d.ts +9 -0
  28. package/dist/types/pm-plugins/main.d.ts +5 -0
  29. package/dist/types/pm-plugins/plugin-factory.d.ts +8 -0
  30. package/dist/types/pm-plugins/reducer.d.ts +3 -0
  31. package/dist/types/pm-plugins/types.d.ts +6 -0
  32. package/dist/types-ts4.5/index.d.ts +2 -0
  33. package/dist/types-ts4.5/plugin-key.d.ts +2 -0
  34. package/dist/types-ts4.5/plugin.d.ts +9 -0
  35. package/dist/types-ts4.5/pm-plugins/main.d.ts +5 -0
  36. package/dist/types-ts4.5/pm-plugins/plugin-factory.d.ts +8 -0
  37. package/dist/types-ts4.5/pm-plugins/reducer.d.ts +3 -0
  38. package/dist/types-ts4.5/pm-plugins/types.d.ts +6 -0
  39. package/package.json +91 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1 @@
1
+ # @atlaskit/editor-plugin-code-bidi-warning
package/LICENSE.md ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2023 Atlassian Pty Ltd
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Editor plugin code bidi warning
2
+
3
+ Code bidi warning plugin for @atlaskit/editor-core
4
+
5
+ **Note:** This component is designed for internal Atlassian development.
6
+ External contributors will be able to use this component but will not be able to submit issues.
7
+
8
+ ## Install
9
+
10
+ ---
11
+
12
+ - **Install** - _yarn add @atlaskit/editor-plugin-code-bidi-warning_
13
+ - **npm** - [@atlaskit/editor-plugin-code-bidi-warning](https://www.npmjs.com/package/@atlaskit/editor-plugin-code-bidi-warning)
14
+ - **Source** - [Bitbucket](https://bitbucket.org/atlassian/atlassian-frontend/src/master/packages/editor/editor-plugin-code-bidi-warning)
15
+ - **Bundle** - [unpkg.com](https://unpkg.com/@atlaskit/editor-plugin-code-bidi-warning/dist/)
16
+
17
+ ## Usage
18
+
19
+ ---
20
+
21
+ **Internal use only**
22
+
23
+ @atlaskit/editor-plugin-code-bidi-warning is intended for internal use by the @atlaskit/editor-core and as a plugin dependency of the Editor within your product.
24
+
25
+ Direct use of this component is not supported.
26
+
27
+ Please see [Atlaskit - Editor plugin code bidi warning](https://atlaskit.atlassian.com/packages/editor/editor-plugin-code-bidi-warning) for documentation and examples for this package.
28
+
29
+ ## Support
30
+
31
+ ---
32
+
33
+ For internal Atlassian, visit the slack channel [#help-editor](https://atlassian.slack.com/archives/CFG3PSQ9E) for support or visit [go/editor-help](https://go/editor-help) to submit a bug.
34
+
35
+ ## License
36
+
37
+ ---
38
+
39
+ Please see [Atlassian Frontend - License](https://hello.atlassian.net/wiki/spaces/AF/pages/2589099144/Documentation#License) for more licensing information.
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "codeBidiWarningPlugin", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _plugin.codeBidiWarningPlugin;
10
+ }
11
+ });
12
+ var _plugin = require("./plugin");
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.codeBidiWarningPluginKey = void 0;
7
+ var _state = require("@atlaskit/editor-prosemirror/state");
8
+ var codeBidiWarningPluginKey = exports.codeBidiWarningPluginKey = new _state.PluginKey('codeBidiWarningPlugin');
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.codeBidiWarningPlugin = void 0;
7
+ var _main = require("./pm-plugins/main");
8
+ var codeBidiWarningPlugin = exports.codeBidiWarningPlugin = function codeBidiWarningPlugin(_ref) {
9
+ var config = _ref.config;
10
+ return {
11
+ name: 'codeBidiWarning',
12
+ pmPlugins: function pmPlugins() {
13
+ return [{
14
+ name: 'codeBidiWarning',
15
+ plugin: function plugin(options) {
16
+ return (0, _main.createPlugin)(options, config !== null && config !== void 0 ? config : {});
17
+ }
18
+ }];
19
+ }
20
+ };
21
+ };
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createPlugin = void 0;
7
+ var _messages = require("@atlaskit/editor-common/messages");
8
+ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
9
+ var _pluginKey = require("../plugin-key");
10
+ var _pluginFactory = require("./plugin-factory");
11
+ var createPlugin = exports.createPlugin = function createPlugin(_ref, _ref2) {
12
+ var dispatch = _ref.dispatch,
13
+ getIntl = _ref.getIntl;
14
+ var appearance = _ref2.appearance;
15
+ var intl = getIntl();
16
+ var codeBidiWarningLabel = intl.formatMessage(_messages.codeBidiWarningMessages.label);
17
+ return new _safePlugin.SafePlugin({
18
+ key: _pluginKey.codeBidiWarningPluginKey,
19
+ state: (0, _pluginFactory.createPluginState)(dispatch, function (state) {
20
+ // The appearance being mobile indicates we are in an editor being
21
+ // rendered by mobile bridge in a web view.
22
+ // The tooltip is likely to have unexpected behaviour there, with being cut
23
+ // off, so we disable it. This is also to keep the behaviour consistent with
24
+ // the rendering in the mobile Native Renderer.
25
+ var tooltipEnabled = appearance !== 'mobile';
26
+ return {
27
+ decorationSet: (0, _pluginFactory.createBidiWarningsDecorationSetFromDoc)({
28
+ doc: state.doc,
29
+ codeBidiWarningLabel: codeBidiWarningLabel,
30
+ tooltipEnabled: tooltipEnabled
31
+ }),
32
+ codeBidiWarningLabel: codeBidiWarningLabel,
33
+ tooltipEnabled: tooltipEnabled
34
+ };
35
+ }),
36
+ props: {
37
+ decorations: function decorations(state) {
38
+ var _getPluginState = (0, _pluginFactory.getPluginState)(state),
39
+ decorationSet = _getPluginState.decorationSet;
40
+ return decorationSet;
41
+ }
42
+ }
43
+ });
44
+ };
@@ -0,0 +1,104 @@
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.getPluginState = exports.createPluginState = void 0;
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _react = _interopRequireDefault(require("react"));
11
+ var _reactDom = _interopRequireDefault(require("react-dom"));
12
+ var _bidiWarning = _interopRequireDefault(require("@atlaskit/code/bidi-warning"));
13
+ var _bidiWarningDecorator = _interopRequireDefault(require("@atlaskit/code/bidi-warning-decorator"));
14
+ var _utils = require("@atlaskit/editor-common/utils");
15
+ var _view = require("@atlaskit/editor-prosemirror/view");
16
+ var _pluginKey = require("../plugin-key");
17
+ var _reducer = _interopRequireDefault(require("./reducer"));
18
+ 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; }
19
+ 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; }
20
+ var _pluginFactory = (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
+ createPluginState = exports.createPluginState = _pluginFactory.createPluginState,
36
+ getPluginState = exports.getPluginState = _pluginFactory.getPluginState;
37
+ function createBidiWarningsDecorationSetFromDoc(_ref) {
38
+ var doc = _ref.doc,
39
+ codeBidiWarningLabel = _ref.codeBidiWarningLabel,
40
+ tooltipEnabled = _ref.tooltipEnabled;
41
+ var bidiCharactersAndTheirPositions = [];
42
+ doc.descendants(function (node, pos) {
43
+ var isTextWithCodeMark = node.type.name === 'text' && node.marks && node.marks.some(function (mark) {
44
+ return mark.type.name === 'code';
45
+ });
46
+ if (isTextWithCodeMark) {
47
+ (0, _bidiWarningDecorator.default)(node.textContent, function (_ref2) {
48
+ var bidiCharacter = _ref2.bidiCharacter,
49
+ index = _ref2.index;
50
+ bidiCharactersAndTheirPositions.push({
51
+ position: pos + index,
52
+ bidiCharacter: bidiCharacter
53
+ });
54
+ });
55
+ return false;
56
+ }
57
+ var isCodeBlock = node.type.name === 'codeBlock';
58
+ if (isCodeBlock) {
59
+ (0, _bidiWarningDecorator.default)(node.textContent, function (_ref3) {
60
+ var bidiCharacter = _ref3.bidiCharacter,
61
+ index = _ref3.index;
62
+ bidiCharactersAndTheirPositions.push({
63
+ position: pos + index + 1,
64
+ bidiCharacter: bidiCharacter
65
+ });
66
+ });
67
+ }
68
+ });
69
+
70
+ // Bidi characters are not expected to commonly appear in code snippets, so recreating the decoration set
71
+ // for documents rather than reusing existing decorations seems a reasonable performance/complexity tradeoff.
72
+
73
+ if (bidiCharactersAndTheirPositions.length === 0) {
74
+ return _view.DecorationSet.empty;
75
+ }
76
+ var newBidiWarningsDecorationSet = _view.DecorationSet.create(doc, bidiCharactersAndTheirPositions.map(function (_ref4) {
77
+ var position = _ref4.position,
78
+ bidiCharacter = _ref4.bidiCharacter;
79
+ return _view.Decoration.widget(position, function () {
80
+ return renderDOM({
81
+ bidiCharacter: bidiCharacter,
82
+ codeBidiWarningLabel: codeBidiWarningLabel,
83
+ tooltipEnabled: tooltipEnabled
84
+ });
85
+ });
86
+ }));
87
+ return newBidiWarningsDecorationSet;
88
+ }
89
+ function renderDOM(_ref5) {
90
+ var bidiCharacter = _ref5.bidiCharacter,
91
+ codeBidiWarningLabel = _ref5.codeBidiWarningLabel,
92
+ tooltipEnabled = _ref5.tooltipEnabled;
93
+ var element = document.createElement('span');
94
+
95
+ // Note: we use this pattern elsewhere (see highlighting code block, and drop cursor widget decoration)
96
+ // we should investigate if there is a memory leak with such usage.
97
+ _reactDom.default.render( /*#__PURE__*/_react.default.createElement(_bidiWarning.default, {
98
+ bidiCharacter: bidiCharacter,
99
+ skipChildren: true,
100
+ label: codeBidiWarningLabel,
101
+ tooltipEnabled: tooltipEnabled
102
+ }), element);
103
+ return element;
104
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _default = exports.default = function _default(pluginState, action) {
8
+ return pluginState;
9
+ };
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1 @@
1
+ export { codeBidiWarningPlugin } from './plugin';
@@ -0,0 +1,2 @@
1
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
+ export const codeBidiWarningPluginKey = new PluginKey('codeBidiWarningPlugin');
@@ -0,0 +1,14 @@
1
+ import { createPlugin } from './pm-plugins/main';
2
+ export const codeBidiWarningPlugin = ({
3
+ config
4
+ }) => ({
5
+ name: 'codeBidiWarning',
6
+ pmPlugins() {
7
+ return [{
8
+ name: 'codeBidiWarning',
9
+ plugin: options => {
10
+ return createPlugin(options, config !== null && config !== void 0 ? config : {});
11
+ }
12
+ }];
13
+ }
14
+ });
@@ -0,0 +1,41 @@
1
+ import { codeBidiWarningMessages } from '@atlaskit/editor-common/messages';
2
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ import { codeBidiWarningPluginKey } from '../plugin-key';
4
+ import { createBidiWarningsDecorationSetFromDoc, createPluginState, getPluginState } from './plugin-factory';
5
+ export const createPlugin = ({
6
+ dispatch,
7
+ getIntl
8
+ }, {
9
+ appearance
10
+ }) => {
11
+ const intl = getIntl();
12
+ const codeBidiWarningLabel = intl.formatMessage(codeBidiWarningMessages.label);
13
+ return new SafePlugin({
14
+ key: codeBidiWarningPluginKey,
15
+ state: createPluginState(dispatch, state => {
16
+ // The appearance being mobile indicates we are in an editor being
17
+ // rendered by mobile bridge in a web view.
18
+ // The tooltip is likely to have unexpected behaviour there, with being cut
19
+ // off, so we disable it. This is also to keep the behaviour consistent with
20
+ // the rendering in the mobile Native Renderer.
21
+ const tooltipEnabled = appearance !== 'mobile';
22
+ return {
23
+ decorationSet: createBidiWarningsDecorationSetFromDoc({
24
+ doc: state.doc,
25
+ codeBidiWarningLabel,
26
+ tooltipEnabled
27
+ }),
28
+ codeBidiWarningLabel,
29
+ tooltipEnabled
30
+ };
31
+ }),
32
+ props: {
33
+ decorations: state => {
34
+ const {
35
+ decorationSet
36
+ } = getPluginState(state);
37
+ return decorationSet;
38
+ }
39
+ }
40
+ });
41
+ };
@@ -0,0 +1,96 @@
1
+ import React from 'react';
2
+ import ReactDOM from 'react-dom';
3
+ import CodeBidiWarning from '@atlaskit/code/bidi-warning';
4
+ import codeBidiWarningDecorator from '@atlaskit/code/bidi-warning-decorator';
5
+ import { pluginFactory, stepHasSlice } from '@atlaskit/editor-common/utils';
6
+ import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
7
+ import { codeBidiWarningPluginKey } from '../plugin-key';
8
+ import reducer from './reducer';
9
+ export const {
10
+ createPluginState,
11
+ getPluginState
12
+ } = pluginFactory(codeBidiWarningPluginKey, reducer, {
13
+ onDocChanged: (tr, pluginState) => {
14
+ if (!tr.steps.find(stepHasSlice)) {
15
+ return pluginState;
16
+ }
17
+ const newBidiWarningsDecorationSet = createBidiWarningsDecorationSetFromDoc({
18
+ doc: tr.doc,
19
+ codeBidiWarningLabel: pluginState.codeBidiWarningLabel,
20
+ tooltipEnabled: pluginState.tooltipEnabled
21
+ });
22
+ return {
23
+ ...pluginState,
24
+ decorationSet: newBidiWarningsDecorationSet
25
+ };
26
+ }
27
+ });
28
+ export function createBidiWarningsDecorationSetFromDoc({
29
+ doc,
30
+ codeBidiWarningLabel,
31
+ tooltipEnabled
32
+ }) {
33
+ const bidiCharactersAndTheirPositions = [];
34
+ doc.descendants((node, pos) => {
35
+ const isTextWithCodeMark = node.type.name === 'text' && node.marks && node.marks.some(mark => mark.type.name === 'code');
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
+ const isCodeBlock = node.type.name === 'codeBlock';
49
+ if (isCodeBlock) {
50
+ codeBidiWarningDecorator(node.textContent, ({
51
+ bidiCharacter,
52
+ index
53
+ }) => {
54
+ bidiCharactersAndTheirPositions.push({
55
+ position: pos + index + 1,
56
+ bidiCharacter
57
+ });
58
+ });
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
+ const newBidiWarningsDecorationSet = DecorationSet.create(doc, bidiCharactersAndTheirPositions.map(({
69
+ position,
70
+ bidiCharacter
71
+ }) => {
72
+ return Decoration.widget(position, () => renderDOM({
73
+ bidiCharacter,
74
+ codeBidiWarningLabel,
75
+ tooltipEnabled
76
+ }));
77
+ }));
78
+ return newBidiWarningsDecorationSet;
79
+ }
80
+ function renderDOM({
81
+ bidiCharacter,
82
+ codeBidiWarningLabel,
83
+ tooltipEnabled
84
+ }) {
85
+ const element = document.createElement('span');
86
+
87
+ // Note: we use this pattern elsewhere (see highlighting code block, and drop cursor widget decoration)
88
+ // we should investigate if there is a memory leak with such usage.
89
+ ReactDOM.render( /*#__PURE__*/React.createElement(CodeBidiWarning, {
90
+ bidiCharacter: bidiCharacter,
91
+ skipChildren: true,
92
+ label: codeBidiWarningLabel,
93
+ tooltipEnabled: tooltipEnabled
94
+ }), element);
95
+ return element;
96
+ }
@@ -0,0 +1,3 @@
1
+ export default ((pluginState, action) => {
2
+ return pluginState;
3
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export { codeBidiWarningPlugin } from './plugin';
@@ -0,0 +1,2 @@
1
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
+ export var codeBidiWarningPluginKey = new PluginKey('codeBidiWarningPlugin');
@@ -0,0 +1,15 @@
1
+ import { createPlugin } from './pm-plugins/main';
2
+ export var codeBidiWarningPlugin = function codeBidiWarningPlugin(_ref) {
3
+ var config = _ref.config;
4
+ return {
5
+ name: 'codeBidiWarning',
6
+ pmPlugins: function pmPlugins() {
7
+ return [{
8
+ name: 'codeBidiWarning',
9
+ plugin: function plugin(options) {
10
+ return createPlugin(options, config !== null && config !== void 0 ? config : {});
11
+ }
12
+ }];
13
+ }
14
+ };
15
+ };
@@ -0,0 +1,38 @@
1
+ import { codeBidiWarningMessages } from '@atlaskit/editor-common/messages';
2
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ import { codeBidiWarningPluginKey } from '../plugin-key';
4
+ import { createBidiWarningsDecorationSetFromDoc, createPluginState, getPluginState } from './plugin-factory';
5
+ export var createPlugin = function createPlugin(_ref, _ref2) {
6
+ var dispatch = _ref.dispatch,
7
+ getIntl = _ref.getIntl;
8
+ var appearance = _ref2.appearance;
9
+ var intl = getIntl();
10
+ var codeBidiWarningLabel = intl.formatMessage(codeBidiWarningMessages.label);
11
+ return new SafePlugin({
12
+ key: codeBidiWarningPluginKey,
13
+ state: createPluginState(dispatch, function (state) {
14
+ // The appearance being mobile indicates we are in an editor being
15
+ // rendered by mobile bridge in a web view.
16
+ // The tooltip is likely to have unexpected behaviour there, with being cut
17
+ // off, so we disable it. This is also to keep the behaviour consistent with
18
+ // the rendering in the mobile Native Renderer.
19
+ var tooltipEnabled = appearance !== 'mobile';
20
+ return {
21
+ decorationSet: createBidiWarningsDecorationSetFromDoc({
22
+ doc: state.doc,
23
+ codeBidiWarningLabel: codeBidiWarningLabel,
24
+ tooltipEnabled: tooltipEnabled
25
+ }),
26
+ codeBidiWarningLabel: codeBidiWarningLabel,
27
+ tooltipEnabled: tooltipEnabled
28
+ };
29
+ }),
30
+ props: {
31
+ decorations: function decorations(state) {
32
+ var _getPluginState = getPluginState(state),
33
+ decorationSet = _getPluginState.decorationSet;
34
+ return decorationSet;
35
+ }
36
+ }
37
+ });
38
+ };
@@ -0,0 +1,97 @@
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 React from 'react';
5
+ import ReactDOM from 'react-dom';
6
+ import CodeBidiWarning from '@atlaskit/code/bidi-warning';
7
+ import codeBidiWarningDecorator from '@atlaskit/code/bidi-warning-decorator';
8
+ import { pluginFactory, stepHasSlice } from '@atlaskit/editor-common/utils';
9
+ import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
10
+ import { codeBidiWarningPluginKey } from '../plugin-key';
11
+ import reducer from './reducer';
12
+ var _pluginFactory = 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
+ createPluginState = _pluginFactory.createPluginState,
28
+ getPluginState = _pluginFactory.getPluginState;
29
+ export { createPluginState, getPluginState };
30
+ export function createBidiWarningsDecorationSetFromDoc(_ref) {
31
+ var doc = _ref.doc,
32
+ codeBidiWarningLabel = _ref.codeBidiWarningLabel,
33
+ tooltipEnabled = _ref.tooltipEnabled;
34
+ var bidiCharactersAndTheirPositions = [];
35
+ doc.descendants(function (node, pos) {
36
+ var isTextWithCodeMark = node.type.name === 'text' && node.marks && node.marks.some(function (mark) {
37
+ return mark.type.name === 'code';
38
+ });
39
+ if (isTextWithCodeMark) {
40
+ codeBidiWarningDecorator(node.textContent, function (_ref2) {
41
+ var bidiCharacter = _ref2.bidiCharacter,
42
+ index = _ref2.index;
43
+ bidiCharactersAndTheirPositions.push({
44
+ position: pos + index,
45
+ bidiCharacter: bidiCharacter
46
+ });
47
+ });
48
+ return false;
49
+ }
50
+ var isCodeBlock = node.type.name === 'codeBlock';
51
+ if (isCodeBlock) {
52
+ codeBidiWarningDecorator(node.textContent, function (_ref3) {
53
+ var bidiCharacter = _ref3.bidiCharacter,
54
+ index = _ref3.index;
55
+ bidiCharactersAndTheirPositions.push({
56
+ position: pos + index + 1,
57
+ bidiCharacter: bidiCharacter
58
+ });
59
+ });
60
+ }
61
+ });
62
+
63
+ // Bidi characters are not expected to commonly appear in code snippets, so recreating the decoration set
64
+ // for documents rather than reusing existing decorations seems a reasonable performance/complexity tradeoff.
65
+
66
+ if (bidiCharactersAndTheirPositions.length === 0) {
67
+ return DecorationSet.empty;
68
+ }
69
+ var newBidiWarningsDecorationSet = DecorationSet.create(doc, bidiCharactersAndTheirPositions.map(function (_ref4) {
70
+ var position = _ref4.position,
71
+ bidiCharacter = _ref4.bidiCharacter;
72
+ return Decoration.widget(position, function () {
73
+ return renderDOM({
74
+ bidiCharacter: bidiCharacter,
75
+ codeBidiWarningLabel: codeBidiWarningLabel,
76
+ tooltipEnabled: tooltipEnabled
77
+ });
78
+ });
79
+ }));
80
+ return newBidiWarningsDecorationSet;
81
+ }
82
+ function renderDOM(_ref5) {
83
+ var bidiCharacter = _ref5.bidiCharacter,
84
+ codeBidiWarningLabel = _ref5.codeBidiWarningLabel,
85
+ tooltipEnabled = _ref5.tooltipEnabled;
86
+ var element = document.createElement('span');
87
+
88
+ // Note: we use this pattern elsewhere (see highlighting code block, and drop cursor widget decoration)
89
+ // we should investigate if there is a memory leak with such usage.
90
+ ReactDOM.render( /*#__PURE__*/React.createElement(CodeBidiWarning, {
91
+ bidiCharacter: bidiCharacter,
92
+ skipChildren: true,
93
+ label: codeBidiWarningLabel,
94
+ tooltipEnabled: tooltipEnabled
95
+ }), element);
96
+ return element;
97
+ }
@@ -0,0 +1,3 @@
1
+ export default (function (pluginState, action) {
2
+ return pluginState;
3
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export { codeBidiWarningPlugin } from './plugin';
2
+ export type { CodeBidiWarningPlugin } from './plugin';
@@ -0,0 +1,2 @@
1
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
+ export declare const codeBidiWarningPluginKey: PluginKey<any>;
@@ -0,0 +1,9 @@
1
+ import type { EditorAppearance, NextEditorPlugin } from '@atlaskit/editor-common/types';
2
+ type Config = {
3
+ appearance?: EditorAppearance;
4
+ };
5
+ export type CodeBidiWarningPlugin = NextEditorPlugin<'codeBidiWarning', {
6
+ pluginConfiguration: Config | undefined;
7
+ }>;
8
+ export declare const codeBidiWarningPlugin: CodeBidiWarningPlugin;
9
+ export {};
@@ -0,0 +1,5 @@
1
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ import type { EditorAppearance, PMPluginFactoryParams } from '@atlaskit/editor-common/types';
3
+ export declare const createPlugin: ({ dispatch, getIntl }: PMPluginFactoryParams, { appearance }: {
4
+ appearance?: EditorAppearance | undefined;
5
+ }) => SafePlugin<import("./types").CodeBidiWarningPluginState>;
@@ -0,0 +1,8 @@
1
+ import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
2
+ import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
3
+ export declare const createPluginState: (dispatch: import("@atlaskit/editor-common/event-dispatcher").Dispatch<any>, initialState: import("./types").CodeBidiWarningPluginState | ((state: import("prosemirror-state").EditorState) => import("./types").CodeBidiWarningPluginState)) => import("prosemirror-state").SafeStateField<import("./types").CodeBidiWarningPluginState>, getPluginState: (state: import("prosemirror-state").EditorState) => import("./types").CodeBidiWarningPluginState;
4
+ export declare function createBidiWarningsDecorationSetFromDoc({ doc, codeBidiWarningLabel, tooltipEnabled, }: {
5
+ doc: PmNode;
6
+ codeBidiWarningLabel: string;
7
+ tooltipEnabled: boolean;
8
+ }): DecorationSet;
@@ -0,0 +1,3 @@
1
+ import type { CodeBidiWarningPluginState } from './types';
2
+ declare const _default: (pluginState: CodeBidiWarningPluginState, action: unknown) => CodeBidiWarningPluginState;
3
+ export default _default;
@@ -0,0 +1,6 @@
1
+ import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
2
+ export type CodeBidiWarningPluginState = {
3
+ decorationSet: DecorationSet;
4
+ codeBidiWarningLabel: string;
5
+ tooltipEnabled: boolean;
6
+ };
@@ -0,0 +1,2 @@
1
+ export { codeBidiWarningPlugin } from './plugin';
2
+ export type { CodeBidiWarningPlugin } from './plugin';
@@ -0,0 +1,2 @@
1
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
+ export declare const codeBidiWarningPluginKey: PluginKey<any>;
@@ -0,0 +1,9 @@
1
+ import type { EditorAppearance, NextEditorPlugin } from '@atlaskit/editor-common/types';
2
+ type Config = {
3
+ appearance?: EditorAppearance;
4
+ };
5
+ export type CodeBidiWarningPlugin = NextEditorPlugin<'codeBidiWarning', {
6
+ pluginConfiguration: Config | undefined;
7
+ }>;
8
+ export declare const codeBidiWarningPlugin: CodeBidiWarningPlugin;
9
+ export {};
@@ -0,0 +1,5 @@
1
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ import type { EditorAppearance, PMPluginFactoryParams } from '@atlaskit/editor-common/types';
3
+ export declare const createPlugin: ({ dispatch, getIntl }: PMPluginFactoryParams, { appearance }: {
4
+ appearance?: EditorAppearance | undefined;
5
+ }) => SafePlugin<import("./types").CodeBidiWarningPluginState>;
@@ -0,0 +1,8 @@
1
+ import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
2
+ import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
3
+ export declare const createPluginState: (dispatch: import("@atlaskit/editor-common/event-dispatcher").Dispatch<any>, initialState: import("./types").CodeBidiWarningPluginState | ((state: import("prosemirror-state").EditorState) => import("./types").CodeBidiWarningPluginState)) => import("prosemirror-state").SafeStateField<import("./types").CodeBidiWarningPluginState>, getPluginState: (state: import("prosemirror-state").EditorState) => import("./types").CodeBidiWarningPluginState;
4
+ export declare function createBidiWarningsDecorationSetFromDoc({ doc, codeBidiWarningLabel, tooltipEnabled, }: {
5
+ doc: PmNode;
6
+ codeBidiWarningLabel: string;
7
+ tooltipEnabled: boolean;
8
+ }): DecorationSet;
@@ -0,0 +1,3 @@
1
+ import type { CodeBidiWarningPluginState } from './types';
2
+ declare const _default: (pluginState: CodeBidiWarningPluginState, action: unknown) => CodeBidiWarningPluginState;
3
+ export default _default;
@@ -0,0 +1,6 @@
1
+ import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
2
+ export type CodeBidiWarningPluginState = {
3
+ decorationSet: DecorationSet;
4
+ codeBidiWarningLabel: string;
5
+ tooltipEnabled: boolean;
6
+ };
package/package.json ADDED
@@ -0,0 +1,91 @@
1
+ {
2
+ "name": "@atlaskit/editor-plugin-code-bidi-warning",
3
+ "version": "0.1.0",
4
+ "description": "Code bidi warning plugin for @atlaskit/editor-core.",
5
+ "author": "Atlassian Pty Ltd",
6
+ "license": "Apache-2.0",
7
+ "publishConfig": {
8
+ "registry": "https://registry.npmjs.org/"
9
+ },
10
+ "atlassian": {
11
+ "team": "Editor: Scarlet",
12
+ "inPublicMirror": false,
13
+ "releaseModel": "continuous"
14
+ },
15
+ "repository": "https://bitbucket.org/atlassian/atlassian-frontend",
16
+ "main": "dist/cjs/index.js",
17
+ "module": "dist/esm/index.js",
18
+ "module:es2019": "dist/es2019/index.js",
19
+ "types": "dist/types/index.d.ts",
20
+ "typesVersions": {
21
+ ">=4.5 <4.9": {
22
+ "*": [
23
+ "dist/types-ts4.5/*",
24
+ "dist/types-ts4.5/index.d.ts"
25
+ ]
26
+ }
27
+ },
28
+ "sideEffects": false,
29
+ "atlaskit:src": "src/index.ts",
30
+ "af:exports": {
31
+ ".": "./src/index.ts"
32
+ },
33
+ "dependencies": {
34
+ "@atlaskit/code": "^15.1.0",
35
+ "@atlaskit/editor-common": "^76.24.0",
36
+ "@atlaskit/editor-prosemirror": "1.1.0",
37
+ "@babel/runtime": "^7.0.0"
38
+ },
39
+ "peerDependencies": {
40
+ "react": "^16.8.0",
41
+ "react-dom": "^16.8.0"
42
+ },
43
+ "devDependencies": {
44
+ "@af/integration-testing": "*",
45
+ "@af/visual-regression": "*",
46
+ "@atlaskit/ssr": "*",
47
+ "@atlaskit/visual-regression": "*",
48
+ "@atlaskit/webdriver-runner": "*",
49
+ "@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0",
50
+ "@testing-library/react": "^12.1.5",
51
+ "react-dom": "^16.8.0",
52
+ "typescript": "~4.9.5",
53
+ "wait-for-expect": "^1.2.0"
54
+ },
55
+ "techstack": {
56
+ "@atlassian/frontend": {
57
+ "import-structure": [
58
+ "atlassian-conventions"
59
+ ],
60
+ "circular-dependencies": [
61
+ "file-and-folder-level"
62
+ ]
63
+ },
64
+ "@repo/internal": {
65
+ "dom-events": "use-bind-event-listener",
66
+ "analytics": [
67
+ "analytics-next"
68
+ ],
69
+ "design-tokens": [
70
+ "color"
71
+ ],
72
+ "theming": [
73
+ "react-context"
74
+ ],
75
+ "ui-components": [
76
+ "lite-mode"
77
+ ],
78
+ "deprecation": [
79
+ "no-deprecated-imports"
80
+ ],
81
+ "styling": [
82
+ "static",
83
+ "emotion"
84
+ ],
85
+ "imports": [
86
+ "import-no-extraneous-disable-for-examples-and-docs"
87
+ ]
88
+ }
89
+ },
90
+ "prettier": "@atlassian/atlassian-frontend-prettier-config-1.0.0"
91
+ }