@atlaskit/editor-core 189.3.4 → 189.3.7

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 (140) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/plugins/index.js +0 -7
  3. package/dist/cjs/presets/default.js +2 -2
  4. package/dist/cjs/version-wrapper.js +1 -1
  5. package/dist/es2019/plugins/index.js +0 -1
  6. package/dist/es2019/presets/default.js +1 -1
  7. package/dist/es2019/version-wrapper.js +1 -1
  8. package/dist/esm/plugins/index.js +0 -1
  9. package/dist/esm/presets/default.js +1 -1
  10. package/dist/esm/version-wrapper.js +1 -1
  11. package/dist/types/plugins/index.d.ts +0 -1
  12. package/dist/types/plugins/insert-block/types.d.ts +1 -1
  13. package/dist/types/presets/default.d.ts +1 -1
  14. package/dist/types/types/editor-props.d.ts +1 -1
  15. package/dist/types/ui/Appearance/FullPage/StyledComponents.d.ts +1 -1
  16. package/dist/types/ui/ContentStyles/index.d.ts +2 -2
  17. package/dist/types-ts4.5/plugins/index.d.ts +0 -1
  18. package/dist/types-ts4.5/plugins/insert-block/types.d.ts +1 -1
  19. package/dist/types-ts4.5/presets/default.d.ts +1 -1
  20. package/dist/types-ts4.5/types/editor-props.d.ts +1 -1
  21. package/dist/types-ts4.5/ui/Appearance/FullPage/StyledComponents.d.ts +1 -1
  22. package/dist/types-ts4.5/ui/ContentStyles/index.d.ts +2 -2
  23. package/package.json +3 -2
  24. package/report.api.md +1 -11
  25. package/tmp/api-report-tmp.d.ts +1 -11
  26. package/dist/cjs/plugins/code-block/actions.js +0 -201
  27. package/dist/cjs/plugins/code-block/ide-ux/bracket-handling.js +0 -35
  28. package/dist/cjs/plugins/code-block/ide-ux/commands.js +0 -115
  29. package/dist/cjs/plugins/code-block/ide-ux/line-handling.js +0 -81
  30. package/dist/cjs/plugins/code-block/ide-ux/paired-character-handling.js +0 -23
  31. package/dist/cjs/plugins/code-block/ide-ux/quote-handling.js +0 -40
  32. package/dist/cjs/plugins/code-block/index.js +0 -120
  33. package/dist/cjs/plugins/code-block/language-list.js +0 -62
  34. package/dist/cjs/plugins/code-block/nodeviews/code-block.js +0 -153
  35. package/dist/cjs/plugins/code-block/plugin-key.js +0 -8
  36. package/dist/cjs/plugins/code-block/pm-plugins/actions.js +0 -10
  37. package/dist/cjs/plugins/code-block/pm-plugins/codeBlockCopySelectionPlugin.js +0 -113
  38. package/dist/cjs/plugins/code-block/pm-plugins/ide-ux.js +0 -132
  39. package/dist/cjs/plugins/code-block/pm-plugins/input-rule.js +0 -68
  40. package/dist/cjs/plugins/code-block/pm-plugins/keymaps.js +0 -66
  41. package/dist/cjs/plugins/code-block/pm-plugins/main-state.js +0 -10
  42. package/dist/cjs/plugins/code-block/pm-plugins/main.js +0 -114
  43. package/dist/cjs/plugins/code-block/refresh-browser-selection.js +0 -29
  44. package/dist/cjs/plugins/code-block/toolbar.js +0 -131
  45. package/dist/cjs/plugins/code-block/transform-to-code-block.js +0 -84
  46. package/dist/cjs/plugins/code-block/types.js +0 -5
  47. package/dist/cjs/plugins/code-block/ui/class-names.js +0 -15
  48. package/dist/cjs/plugins/code-block/utils.js +0 -28
  49. package/dist/es2019/plugins/code-block/actions.js +0 -211
  50. package/dist/es2019/plugins/code-block/ide-ux/bracket-handling.js +0 -27
  51. package/dist/es2019/plugins/code-block/ide-ux/commands.js +0 -114
  52. package/dist/es2019/plugins/code-block/ide-ux/line-handling.js +0 -75
  53. package/dist/es2019/plugins/code-block/ide-ux/paired-character-handling.js +0 -12
  54. package/dist/es2019/plugins/code-block/ide-ux/quote-handling.js +0 -32
  55. package/dist/es2019/plugins/code-block/index.js +0 -104
  56. package/dist/es2019/plugins/code-block/language-list.js +0 -51
  57. package/dist/es2019/plugins/code-block/nodeviews/code-block.js +0 -126
  58. package/dist/es2019/plugins/code-block/plugin-key.js +0 -2
  59. package/dist/es2019/plugins/code-block/pm-plugins/actions.js +0 -4
  60. package/dist/es2019/plugins/code-block/pm-plugins/codeBlockCopySelectionPlugin.js +0 -101
  61. package/dist/es2019/plugins/code-block/pm-plugins/ide-ux.js +0 -135
  62. package/dist/es2019/plugins/code-block/pm-plugins/input-rule.js +0 -60
  63. package/dist/es2019/plugins/code-block/pm-plugins/keymaps.js +0 -58
  64. package/dist/es2019/plugins/code-block/pm-plugins/main-state.js +0 -2
  65. package/dist/es2019/plugins/code-block/pm-plugins/main.js +0 -102
  66. package/dist/es2019/plugins/code-block/refresh-browser-selection.js +0 -25
  67. package/dist/es2019/plugins/code-block/toolbar.js +0 -108
  68. package/dist/es2019/plugins/code-block/transform-to-code-block.js +0 -79
  69. package/dist/es2019/plugins/code-block/types.js +0 -1
  70. package/dist/es2019/plugins/code-block/ui/class-names.js +0 -9
  71. package/dist/es2019/plugins/code-block/utils.js +0 -4
  72. package/dist/esm/plugins/code-block/actions.js +0 -191
  73. package/dist/esm/plugins/code-block/ide-ux/bracket-handling.js +0 -29
  74. package/dist/esm/plugins/code-block/ide-ux/commands.js +0 -106
  75. package/dist/esm/plugins/code-block/ide-ux/line-handling.js +0 -73
  76. package/dist/esm/plugins/code-block/ide-ux/paired-character-handling.js +0 -16
  77. package/dist/esm/plugins/code-block/ide-ux/quote-handling.js +0 -34
  78. package/dist/esm/plugins/code-block/index.js +0 -113
  79. package/dist/esm/plugins/code-block/language-list.js +0 -52
  80. package/dist/esm/plugins/code-block/nodeviews/code-block.js +0 -146
  81. package/dist/esm/plugins/code-block/plugin-key.js +0 -2
  82. package/dist/esm/plugins/code-block/pm-plugins/actions.js +0 -4
  83. package/dist/esm/plugins/code-block/pm-plugins/codeBlockCopySelectionPlugin.js +0 -103
  84. package/dist/esm/plugins/code-block/pm-plugins/ide-ux.js +0 -126
  85. package/dist/esm/plugins/code-block/pm-plugins/input-rule.js +0 -62
  86. package/dist/esm/plugins/code-block/pm-plugins/keymaps.js +0 -59
  87. package/dist/esm/plugins/code-block/pm-plugins/main-state.js +0 -4
  88. package/dist/esm/plugins/code-block/pm-plugins/main.js +0 -107
  89. package/dist/esm/plugins/code-block/refresh-browser-selection.js +0 -25
  90. package/dist/esm/plugins/code-block/toolbar.js +0 -121
  91. package/dist/esm/plugins/code-block/transform-to-code-block.js +0 -77
  92. package/dist/esm/plugins/code-block/types.js +0 -1
  93. package/dist/esm/plugins/code-block/ui/class-names.js +0 -9
  94. package/dist/esm/plugins/code-block/utils.js +0 -4
  95. package/dist/types/plugins/code-block/actions.d.ts +0 -18
  96. package/dist/types/plugins/code-block/ide-ux/bracket-handling.d.ts +0 -12
  97. package/dist/types/plugins/code-block/ide-ux/commands.d.ts +0 -7
  98. package/dist/types/plugins/code-block/ide-ux/line-handling.d.ts +0 -25
  99. package/dist/types/plugins/code-block/ide-ux/paired-character-handling.d.ts +0 -2
  100. package/dist/types/plugins/code-block/ide-ux/quote-handling.d.ts +0 -12
  101. package/dist/types/plugins/code-block/index.d.ts +0 -19
  102. package/dist/types/plugins/code-block/language-list.d.ts +0 -942
  103. package/dist/types/plugins/code-block/nodeviews/code-block.d.ts +0 -21
  104. package/dist/types/plugins/code-block/plugin-key.d.ts +0 -2
  105. package/dist/types/plugins/code-block/pm-plugins/actions.d.ts +0 -4
  106. package/dist/types/plugins/code-block/pm-plugins/codeBlockCopySelectionPlugin.d.ts +0 -11
  107. package/dist/types/plugins/code-block/pm-plugins/ide-ux.d.ts +0 -5
  108. package/dist/types/plugins/code-block/pm-plugins/input-rule.d.ts +0 -3
  109. package/dist/types/plugins/code-block/pm-plugins/keymaps.d.ts +0 -4
  110. package/dist/types/plugins/code-block/pm-plugins/main-state.d.ts +0 -8
  111. package/dist/types/plugins/code-block/pm-plugins/main.d.ts +0 -10
  112. package/dist/types/plugins/code-block/refresh-browser-selection.d.ts +0 -5
  113. package/dist/types/plugins/code-block/toolbar.d.ts +0 -14
  114. package/dist/types/plugins/code-block/transform-to-code-block.d.ts +0 -3
  115. package/dist/types/plugins/code-block/types.d.ts +0 -6
  116. package/dist/types/plugins/code-block/ui/class-names.d.ts +0 -8
  117. package/dist/types/plugins/code-block/utils.d.ts +0 -4
  118. package/dist/types-ts4.5/plugins/code-block/actions.d.ts +0 -18
  119. package/dist/types-ts4.5/plugins/code-block/ide-ux/bracket-handling.d.ts +0 -12
  120. package/dist/types-ts4.5/plugins/code-block/ide-ux/commands.d.ts +0 -7
  121. package/dist/types-ts4.5/plugins/code-block/ide-ux/line-handling.d.ts +0 -25
  122. package/dist/types-ts4.5/plugins/code-block/ide-ux/paired-character-handling.d.ts +0 -2
  123. package/dist/types-ts4.5/plugins/code-block/ide-ux/quote-handling.d.ts +0 -12
  124. package/dist/types-ts4.5/plugins/code-block/index.d.ts +0 -19
  125. package/dist/types-ts4.5/plugins/code-block/language-list.d.ts +0 -1641
  126. package/dist/types-ts4.5/plugins/code-block/nodeviews/code-block.d.ts +0 -21
  127. package/dist/types-ts4.5/plugins/code-block/plugin-key.d.ts +0 -2
  128. package/dist/types-ts4.5/plugins/code-block/pm-plugins/actions.d.ts +0 -4
  129. package/dist/types-ts4.5/plugins/code-block/pm-plugins/codeBlockCopySelectionPlugin.d.ts +0 -14
  130. package/dist/types-ts4.5/plugins/code-block/pm-plugins/ide-ux.d.ts +0 -5
  131. package/dist/types-ts4.5/plugins/code-block/pm-plugins/input-rule.d.ts +0 -3
  132. package/dist/types-ts4.5/plugins/code-block/pm-plugins/keymaps.d.ts +0 -4
  133. package/dist/types-ts4.5/plugins/code-block/pm-plugins/main-state.d.ts +0 -8
  134. package/dist/types-ts4.5/plugins/code-block/pm-plugins/main.d.ts +0 -10
  135. package/dist/types-ts4.5/plugins/code-block/refresh-browser-selection.d.ts +0 -5
  136. package/dist/types-ts4.5/plugins/code-block/toolbar.d.ts +0 -14
  137. package/dist/types-ts4.5/plugins/code-block/transform-to-code-block.d.ts +0 -3
  138. package/dist/types-ts4.5/plugins/code-block/types.d.ts +0 -6
  139. package/dist/types-ts4.5/plugins/code-block/ui/class-names.d.ts +0 -8
  140. package/dist/types-ts4.5/plugins/code-block/utils.d.ts +0 -4
@@ -1,146 +0,0 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/createClass";
4
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
5
- import rafSchedule from 'raf-schd';
6
- import { browser } from '@atlaskit/editor-common/utils';
7
- import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
8
- import { codeBlockClassNames } from '../ui/class-names';
9
- import { resetShouldIgnoreFollowingMutations } from '../actions';
10
- import { getPluginState } from '../pm-plugins/main-state';
11
- var MATCH_NEWLINES = new RegExp('\n', 'g');
12
- var toDOM = function toDOM(node) {
13
- return ['div', {
14
- class: 'code-block'
15
- }, ['div', {
16
- class: codeBlockClassNames.start,
17
- contenteditable: 'false'
18
- }], ['div', {
19
- class: codeBlockClassNames.contentWrapper
20
- }, ['div', {
21
- class: codeBlockClassNames.gutter,
22
- contenteditable: 'false'
23
- }], ['div', {
24
- class: codeBlockClassNames.content
25
- }, ['code', {
26
- 'data-language': node.attrs.language || '',
27
- spellcheck: 'false',
28
- contenteditable: 'true',
29
- 'data-testid': 'code-block--code'
30
- }, 0]]], ['div', {
31
- class: codeBlockClassNames.end,
32
- contenteditable: 'false'
33
- }]];
34
- };
35
- export var CodeBlockView = /*#__PURE__*/function () {
36
- function CodeBlockView(_node, view, getPos) {
37
- var _this = this;
38
- _classCallCheck(this, CodeBlockView);
39
- _defineProperty(this, "ensureLineNumbers", rafSchedule(function () {
40
- var lines = 1;
41
- _this.node.forEach(function (node) {
42
- var text = node.text;
43
- if (text) {
44
- lines += (node.text.match(MATCH_NEWLINES) || []).length;
45
- }
46
- });
47
- while (_this.lineNumberGutter.childElementCount < lines) {
48
- _this.lineNumberGutter.appendChild(document.createElement('span'));
49
- }
50
- while (_this.lineNumberGutter.childElementCount > lines) {
51
- _this.lineNumberGutter.removeChild(_this.lineNumberGutter.lastChild);
52
- }
53
- }));
54
- var _DOMSerializer$render = DOMSerializer.renderSpec(document, toDOM(_node)),
55
- dom = _DOMSerializer$render.dom,
56
- contentDOM = _DOMSerializer$render.contentDOM;
57
- this.getPos = getPos;
58
- this.view = view;
59
- this.node = _node;
60
- this.dom = dom;
61
- this.contentDOM = contentDOM;
62
- this.lineNumberGutter = this.dom.querySelector(".".concat(codeBlockClassNames.gutter));
63
- this.ensureLineNumbers();
64
- }
65
- _createClass(CodeBlockView, [{
66
- key: "updateDOMAndSelection",
67
- value: function updateDOMAndSelection(savedInnerHTML, newCursorPosition) {
68
- var _this$dom;
69
- if ((_this$dom = this.dom) !== null && _this$dom !== void 0 && _this$dom.childNodes && this.dom.childNodes.length > 1) {
70
- var _contentView$childNod;
71
- var contentWrapper = this.dom.childNodes[1];
72
- var contentView = contentWrapper === null || contentWrapper === void 0 ? void 0 : contentWrapper.childNodes[1];
73
- if ((contentView === null || contentView === void 0 || (_contentView$childNod = contentView.childNodes) === null || _contentView$childNod === void 0 ? void 0 : _contentView$childNod.length) > 0) {
74
- var codeElement = contentView.firstChild;
75
- codeElement.innerHTML = savedInnerHTML;
76
-
77
- // We need to set cursor for the DOM update
78
- var textElement = _toConsumableArray(codeElement.childNodes).find(function (child) {
79
- return child.nodeName === '#text';
80
- });
81
- var sel = window.getSelection();
82
- var range = document.createRange();
83
- range.setStart(textElement, newCursorPosition);
84
- range.collapse(true);
85
- sel === null || sel === void 0 || sel.removeAllRanges();
86
- sel === null || sel === void 0 || sel.addRange(range);
87
- }
88
- }
89
- }
90
- }, {
91
- key: "coalesceDOMElements",
92
- value: function coalesceDOMElements() {
93
- var _this$dom2;
94
- if ((_this$dom2 = this.dom) !== null && _this$dom2 !== void 0 && _this$dom2.childNodes && this.dom.childNodes.length > 1) {
95
- var contentWrapper = this.dom.childNodes[1];
96
- var contentView = contentWrapper === null || contentWrapper === void 0 ? void 0 : contentWrapper.childNodes[1];
97
- if (contentView !== null && contentView !== void 0 && contentView.childNodes && contentView.childNodes.length > 1) {
98
- var savedInnerHTML = '';
99
- while (contentView.childNodes.length > 1) {
100
- var lastChild = contentView.lastChild;
101
- savedInnerHTML = lastChild.innerHTML + savedInnerHTML;
102
- contentView.removeChild(lastChild);
103
- }
104
- var firstChild = contentView.firstChild;
105
- savedInnerHTML = firstChild.innerHTML + '\n' + savedInnerHTML;
106
- var newCursorPosition = firstChild.innerHTML.length + 1;
107
- setTimeout(this.updateDOMAndSelection.bind(this, savedInnerHTML, newCursorPosition), 20);
108
- }
109
- }
110
- }
111
- }, {
112
- key: "update",
113
- value: function update(node) {
114
- if (node.type !== this.node.type) {
115
- return false;
116
- }
117
- if (node !== this.node) {
118
- if (node.attrs.language !== this.node.attrs.language) {
119
- this.contentDOM.setAttribute('data-language', node.attrs.language || '');
120
- }
121
- this.node = node;
122
- this.ensureLineNumbers();
123
- if (browser.android) {
124
- this.coalesceDOMElements();
125
- resetShouldIgnoreFollowingMutations(this.view.state, this.view.dispatch);
126
- }
127
- }
128
- return true;
129
- }
130
- }, {
131
- key: "ignoreMutation",
132
- value: function ignoreMutation(record) {
133
- var pluginState = getPluginState(this.view.state);
134
- if (pluginState !== null && pluginState !== void 0 && pluginState.shouldIgnoreFollowingMutations) {
135
- return true;
136
- }
137
-
138
- // Ensure updating the line-number gutter doesn't trigger reparsing the codeblock
139
- return record.target === this.lineNumberGutter || record.target.parentNode === this.lineNumberGutter;
140
- }
141
- }]);
142
- return CodeBlockView;
143
- }();
144
- export var codeBlockNodeView = function codeBlockNodeView(node, view, getPos) {
145
- return new CodeBlockView(node, view, getPos);
146
- };
@@ -1,2 +0,0 @@
1
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
- export var pluginKey = new PluginKey('codeBlockPlugin');
@@ -1,4 +0,0 @@
1
- export var ACTIONS = {
2
- SET_COPIED_TO_CLIPBOARD: 'SET_COPIED_TO_CLIPBOARD',
3
- SET_SHOULD_IGNORE_FOLLOWING_MUTATIONS: 'SET_SHOULD_IGNORE_FOLLOWING_MUTATIONS'
4
- };
@@ -1,103 +0,0 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
- import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
5
- import { getSelectedNodeOrNodeParentByNodeType } from '@atlaskit/editor-common/copy-button';
6
- export var copySelectionPluginKey = new PluginKey('codeBlockCopySelectionPlugin');
7
- function getSelectionDecorationStartAndEnd(_ref) {
8
- var state = _ref.state,
9
- transaction = _ref.transaction;
10
- var codeBlockNode = getSelectedNodeOrNodeParentByNodeType({
11
- nodeType: state.schema.nodes.codeBlock,
12
- selection: transaction.selection
13
- });
14
- if (!codeBlockNode) {
15
- return {
16
- decorationStartAndEnd: undefined
17
- };
18
- }
19
- var decorationStartAndEnd = [codeBlockNode.start, codeBlockNode.start + codeBlockNode.node.nodeSize];
20
- return {
21
- decorationStartAndEnd: decorationStartAndEnd
22
- };
23
- }
24
- export function codeBlockCopySelectionPlugin() {
25
- return new SafePlugin({
26
- key: copySelectionPluginKey,
27
- state: {
28
- init: function init() {
29
- return {
30
- decorationStartAndEnd: undefined
31
- };
32
- },
33
- apply: function apply(transaction, currentCodeBlockCopySelectionPluginState, _oldState, newState) {
34
- switch (transaction.getMeta(copySelectionPluginKey)) {
35
- case 'show-selection':
36
- {
37
- return getSelectionDecorationStartAndEnd({
38
- state: newState,
39
- transaction: transaction
40
- });
41
- }
42
- case 'remove-selection':
43
- return {
44
- decorationStartAndEnd: undefined
45
- };
46
- default:
47
- // The contents of the code block can change while the selection is being shown
48
- // (either from collab edits -- or from the user continuing to type while hovering
49
- // the mouse over the copy button).
50
- // This ensures the selection is updated in these cases.
51
- if (currentCodeBlockCopySelectionPluginState.decorationStartAndEnd !== undefined) {
52
- return getSelectionDecorationStartAndEnd({
53
- state: newState,
54
- transaction: transaction
55
- });
56
- }
57
- return currentCodeBlockCopySelectionPluginState;
58
- }
59
- }
60
- },
61
- props: {
62
- decorations: function decorations(state) {
63
- if (copySelectionPluginKey.getState(state).decorationStartAndEnd) {
64
- var _copySelectionPluginK = _slicedToArray(copySelectionPluginKey.getState(state).decorationStartAndEnd, 2),
65
- _start = _copySelectionPluginK[0],
66
- _end = _copySelectionPluginK[1];
67
- return DecorationSet.create(state.doc, [Decoration.inline(_start, _end, {
68
- class: 'ProseMirror-fake-text-selection'
69
- })]);
70
- }
71
- return DecorationSet.empty;
72
- }
73
- }
74
- });
75
- }
76
- export function provideVisualFeedbackForCopyButton(state, dispatch) {
77
- var tr = state.tr;
78
- tr.setMeta(copySelectionPluginKey, 'show-selection');
79
-
80
- // note: dispatch should always be defined when called from the
81
- // floating toolbar. Howver the Command type which the floating toolbar
82
- // uses suggests it's optional.
83
- // Using the type here to protect against future refactors of the
84
- // floating toolbar
85
- if (dispatch) {
86
- dispatch(tr);
87
- }
88
- return true;
89
- }
90
- export function removeVisualFeedbackForCopyButton(state, dispatch) {
91
- var tr = state.tr;
92
- tr.setMeta(copySelectionPluginKey, 'remove-selection');
93
-
94
- // note: dispatch should always be defined when called from the
95
- // floating toolbar. Howver the Command type which the floating toolbar
96
- // uses suggests it's optional.
97
- // Using the type here to protect against future refactors of the
98
- // floating toolbar
99
- if (dispatch) {
100
- dispatch(tr);
101
- }
102
- return true;
103
- }
@@ -1,126 +0,0 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import { TextSelection } from '@atlaskit/editor-prosemirror/state';
3
- import { keydownHandler } from '@atlaskit/editor-prosemirror/keymap';
4
- import { setTextSelection } from '@atlaskit/editor-prosemirror/utils';
5
- import { getCursor } from '../utils';
6
- import { filterCommand as filter } from '@atlaskit/editor-common/utils';
7
- import { isCursorBeforeClosingCharacter, isClosingCharacter } from '../ide-ux/paired-character-handling';
8
- import { getAutoClosingBracketInfo, shouldAutoCloseBracket } from '../ide-ux/bracket-handling';
9
- import { getAutoClosingQuoteInfo, shouldAutoCloseQuote } from '../ide-ux/quote-handling';
10
- import { getEndOfCurrentLine, getStartOfCurrentLine, isCursorInsideCodeBlock, isSelectionEntirelyInsideCodeBlock, getLineInfo } from '../ide-ux/line-handling';
11
- import { insertIndent, outdent, indent, insertNewlineWithIndent } from '../ide-ux/commands';
12
- var ideUX = function ideUX(pluginInjectionApi) {
13
- var _pluginInjectionApi$a;
14
- var editorAnalyticsAPI = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions;
15
- return new SafePlugin({
16
- props: {
17
- handleTextInput: function handleTextInput(view, from, to, text) {
18
- var _pluginInjectionApi$c;
19
- var state = view.state,
20
- dispatch = view.dispatch;
21
- var compositionPluginState = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c = pluginInjectionApi.composition) === null || _pluginInjectionApi$c === void 0 ? void 0 : _pluginInjectionApi$c.sharedState.currentState();
22
- if (isCursorInsideCodeBlock(state) && !(compositionPluginState !== null && compositionPluginState !== void 0 && compositionPluginState.isComposing)) {
23
- var beforeText = getStartOfCurrentLine(state).text;
24
- var afterText = getEndOfCurrentLine(state).text;
25
-
26
- // If text is a closing bracket/quote and we've already inserted it, move the selection after
27
- if (isCursorBeforeClosingCharacter(afterText) && isClosingCharacter(text) && afterText.startsWith(text)) {
28
- dispatch(setTextSelection(to + text.length)(state.tr));
29
- return true;
30
- }
31
-
32
- // Automatically add right-hand side bracket when user types the left bracket
33
- if (shouldAutoCloseBracket(beforeText, afterText)) {
34
- var _getAutoClosingBracke = getAutoClosingBracketInfo(beforeText + text, afterText),
35
- left = _getAutoClosingBracke.left,
36
- right = _getAutoClosingBracke.right;
37
- if (left && right) {
38
- var bracketPair = state.schema.text(text + right);
39
- var tr = state.tr.replaceWith(from, to, bracketPair);
40
- dispatch(setTextSelection(from + text.length)(tr));
41
- return true;
42
- }
43
- }
44
-
45
- // Automatically add closing quote when user types a starting quote
46
- if (shouldAutoCloseQuote(beforeText, afterText)) {
47
- var _getAutoClosingQuoteI = getAutoClosingQuoteInfo(beforeText + text, afterText),
48
- leftQuote = _getAutoClosingQuoteI.left,
49
- rightQuote = _getAutoClosingQuoteI.right;
50
- if (leftQuote && rightQuote) {
51
- var quotePair = state.schema.text(text + rightQuote);
52
- var _tr = state.tr.replaceWith(from, to, quotePair);
53
- dispatch(setTextSelection(from + text.length)(_tr));
54
- return true;
55
- }
56
- }
57
- }
58
- return false;
59
- },
60
- handleKeyDown: keydownHandler({
61
- Backspace: function Backspace(state, dispatch) {
62
- if (isCursorInsideCodeBlock(state)) {
63
- var $cursor = getCursor(state.selection);
64
- var beforeText = getStartOfCurrentLine(state).text;
65
- var afterText = getEndOfCurrentLine(state).text;
66
- var _getAutoClosingBracke2 = getAutoClosingBracketInfo(beforeText, afterText),
67
- leftBracket = _getAutoClosingBracke2.left,
68
- rightBracket = _getAutoClosingBracke2.right,
69
- hasTrailingMatchingBracket = _getAutoClosingBracke2.hasTrailingMatchingBracket;
70
- if (leftBracket && rightBracket && hasTrailingMatchingBracket && dispatch) {
71
- dispatch(state.tr.delete($cursor.pos - leftBracket.length, $cursor.pos + rightBracket.length));
72
- return true;
73
- }
74
- var _getAutoClosingQuoteI2 = getAutoClosingQuoteInfo(beforeText, afterText),
75
- leftQuote = _getAutoClosingQuoteI2.left,
76
- rightQuote = _getAutoClosingQuoteI2.right,
77
- hasTrailingMatchingQuote = _getAutoClosingQuoteI2.hasTrailingMatchingQuote;
78
- if (leftQuote && rightQuote && hasTrailingMatchingQuote && dispatch) {
79
- dispatch(state.tr.delete($cursor.pos - leftQuote.length, $cursor.pos + rightQuote.length));
80
- return true;
81
- }
82
- var _getLineInfo = getLineInfo(beforeText),
83
- _getLineInfo$indentTo = _getLineInfo.indentToken,
84
- size = _getLineInfo$indentTo.size,
85
- token = _getLineInfo$indentTo.token,
86
- indentText = _getLineInfo.indentText;
87
- if (beforeText === indentText) {
88
- if (indentText.endsWith(token.repeat(size)) && dispatch) {
89
- dispatch(state.tr.delete($cursor.pos - (size - indentText.length % size || size), $cursor.pos));
90
- return true;
91
- }
92
- }
93
- }
94
- return false;
95
- },
96
- Enter: filter(isSelectionEntirelyInsideCodeBlock, insertNewlineWithIndent),
97
- 'Mod-]': filter(isSelectionEntirelyInsideCodeBlock, indent(editorAnalyticsAPI)),
98
- 'Mod-[': filter(isSelectionEntirelyInsideCodeBlock, outdent(editorAnalyticsAPI)),
99
- Tab: filter(isSelectionEntirelyInsideCodeBlock, function (state, dispatch) {
100
- if (!dispatch) {
101
- return false;
102
- }
103
- if (isCursorInsideCodeBlock(state)) {
104
- return insertIndent(state, dispatch);
105
- }
106
- return indent(editorAnalyticsAPI)(state, dispatch);
107
- }),
108
- 'Shift-Tab': filter(isSelectionEntirelyInsideCodeBlock, outdent(editorAnalyticsAPI)),
109
- 'Mod-a': function ModA(state, dispatch) {
110
- if (isSelectionEntirelyInsideCodeBlock(state)) {
111
- var _state$selection = state.selection,
112
- $from = _state$selection.$from,
113
- $to = _state$selection.$to;
114
- var isFullCodeBlockSelection = $from.parentOffset === 0 && $to.parentOffset === $to.parent.nodeSize - 2;
115
- if (!isFullCodeBlockSelection && dispatch) {
116
- dispatch(state.tr.setSelection(TextSelection.create(state.doc, $from.start(), $to.end())));
117
- return true;
118
- }
119
- }
120
- return false;
121
- }
122
- })
123
- }
124
- });
125
- };
126
- export default ideUX;
@@ -1,62 +0,0 @@
1
- import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
2
- import { createRule, createPlugin, leafNodeReplacementCharacter } from '@atlaskit/prosemirror-input-rules';
3
- import { INPUT_METHOD, ACTION, ACTION_SUBJECT, EVENT_TYPE, ACTION_SUBJECT_ID } from '@atlaskit/editor-common/analytics';
4
- import { inputRuleWithAnalytics } from '@atlaskit/editor-common/utils';
5
- import { isConvertableToCodeBlock, transformToCodeBlockAction } from '../transform-to-code-block';
6
- import { insertBlock } from '@atlaskit/editor-common/commands';
7
- export function createCodeBlockInputRule(schema, editorAnalyticsAPI) {
8
- var rules = getCodeBlockRules(editorAnalyticsAPI, schema);
9
- return createPlugin('code-block-input-rule', rules, {
10
- isBlockNodeRule: true
11
- });
12
- }
13
-
14
- /**
15
- * Get all code block input rules
16
- *
17
- * @param {Schema} schema
18
- * @returns {InputRuleWithHandler[]}
19
- */
20
- function getCodeBlockRules(editorAnalyticsAPI, schema) {
21
- var ruleAnalytics = inputRuleWithAnalytics({
22
- action: ACTION.INSERTED,
23
- actionSubject: ACTION_SUBJECT.DOCUMENT,
24
- actionSubjectId: ACTION_SUBJECT_ID.CODE_BLOCK,
25
- attributes: {
26
- inputMethod: INPUT_METHOD.FORMATTING
27
- },
28
- eventType: EVENT_TYPE.TRACK
29
- }, editorAnalyticsAPI);
30
- var validMatchLength = function validMatchLength(match) {
31
- return match.length > 0 && match[0].length === 3;
32
- };
33
- var threeTildeRule = createRule(/(?!\s)(`{3,})$/, function (state, match, start, end) {
34
- if (!validMatchLength(match)) {
35
- return null;
36
- }
37
- var attributes = {};
38
- if (match[4]) {
39
- attributes.language = match[4];
40
- }
41
- if (isConvertableToCodeBlock(state)) {
42
- return transformToCodeBlockAction(state, start, attributes);
43
- }
44
- var tr = state.tr;
45
- tr.delete(start, end);
46
- var codeBlock = tr.doc.type.schema.nodes.codeBlock.createChecked();
47
- safeInsert(codeBlock)(tr);
48
- return tr;
49
- });
50
- var leftNodeReplacementThreeTildeRule = createRule(new RegExp("((".concat(leafNodeReplacementCharacter, "`{3,})|^\\s(`{3,}))(\\S*)$")), function (state, match, start, end) {
51
- if (!validMatchLength(match)) {
52
- return null;
53
- }
54
- var attributes = {};
55
- if (match[4]) {
56
- attributes.language = match[4];
57
- }
58
- var inlineStart = Math.max(match.index + state.selection.$from.start(), 1);
59
- return insertBlock(state, schema.nodes.codeBlock, inlineStart, end, attributes);
60
- });
61
- return [ruleAnalytics(threeTildeRule), ruleAnalytics(leftNodeReplacementThreeTildeRule)];
62
- }
@@ -1,59 +0,0 @@
1
- import { keymap } from '@atlaskit/editor-prosemirror/keymap';
2
- import { Selection } from '@atlaskit/editor-prosemirror/state';
3
- import { findParentNodeOfTypeClosestToPos, hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
4
- import { getCursor } from '../utils';
5
- import { isEmptyNode } from '@atlaskit/editor-common/utils';
6
- var deleteCurrentItem = function deleteCurrentItem($from) {
7
- return function (tr) {
8
- return tr.delete($from.before($from.depth), $from.after($from.depth));
9
- };
10
- };
11
- var setTextSelection = function setTextSelection(pos) {
12
- return function (tr) {
13
- var newSelection = Selection.findFrom(tr.doc.resolve(pos), -1, true);
14
- if (newSelection) {
15
- tr.setSelection(newSelection);
16
- }
17
- return tr;
18
- };
19
- };
20
- export function keymapPlugin(schema) {
21
- return keymap({
22
- Backspace: function Backspace(state, dispatch) {
23
- var $cursor = getCursor(state.selection);
24
- var _state$schema$nodes = state.schema.nodes,
25
- paragraph = _state$schema$nodes.paragraph,
26
- codeBlock = _state$schema$nodes.codeBlock,
27
- listItem = _state$schema$nodes.listItem,
28
- table = _state$schema$nodes.table,
29
- layoutColumn = _state$schema$nodes.layoutColumn;
30
- if (!$cursor || $cursor.parent.type !== codeBlock || !dispatch) {
31
- return false;
32
- }
33
- if ($cursor.pos === 1 || hasParentNodeOfType(listItem)(state.selection) && $cursor.parentOffset === 0) {
34
- var node = findParentNodeOfTypeClosestToPos($cursor, codeBlock);
35
- if (!node) {
36
- return false;
37
- }
38
- dispatch(state.tr.setNodeMarkup(node.pos, node.node.type, node.node.attrs, []).setBlockType($cursor.pos, $cursor.pos, paragraph));
39
- return true;
40
- }
41
- if ($cursor.node && isEmptyNode(schema)($cursor.node()) && (hasParentNodeOfType(layoutColumn)(state.selection) || hasParentNodeOfType(table)(state.selection))) {
42
- var tr = state.tr;
43
- var insertPos = $cursor.pos;
44
- deleteCurrentItem($cursor)(tr);
45
- setTextSelection(insertPos)(tr);
46
- dispatch(tr.scrollIntoView());
47
- return true;
48
- }
49
-
50
- // Handle not nested empty code block
51
- if (isEmptyNode(schema)($cursor.node())) {
52
- dispatch(deleteCurrentItem($cursor)(state === null || state === void 0 ? void 0 : state.tr));
53
- return true;
54
- }
55
- return false;
56
- }
57
- });
58
- }
59
- export default keymapPlugin;
@@ -1,4 +0,0 @@
1
- import { pluginKey } from '../plugin-key';
2
- export var getPluginState = function getPluginState(state) {
3
- return pluginKey.getState(state);
4
- };
@@ -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 { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
5
- import { browser } from '@atlaskit/editor-common/utils';
6
- import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
7
- import { codeBlockNodeView } from '../nodeviews/code-block';
8
- import { createSelectionClickHandler } from '@atlaskit/editor-common/selection';
9
- import { pluginKey } from '../plugin-key';
10
- import { ACTIONS } from './actions';
11
- import { ignoreFollowingMutations, resetShouldIgnoreFollowingMutations } from '../actions';
12
- import { findCodeBlock } from '../utils';
13
- import { codeBlockClassNames } from '../ui/class-names';
14
- export var createPlugin = function createPlugin(_ref) {
15
- var _ref$useLongPressSele = _ref.useLongPressSelection,
16
- useLongPressSelection = _ref$useLongPressSele === void 0 ? false : _ref$useLongPressSele,
17
- getIntl = _ref.getIntl,
18
- appearance = _ref.appearance,
19
- _ref$allowComposition = _ref.allowCompositionInputOverride,
20
- allowCompositionInputOverride = _ref$allowComposition === void 0 ? false : _ref$allowComposition;
21
- var handleDOMEvents = {};
22
-
23
- // ME-1599: Composition on mobile was causing the DOM observer to mutate the code block
24
- // incorrecly and lose content when pressing enter in the middle of a code block line.
25
- if (allowCompositionInputOverride) {
26
- handleDOMEvents.beforeinput = function (view, event) {
27
- var keyEvent = event;
28
- var eventInputType = keyEvent.inputType;
29
- var eventText = keyEvent.data;
30
- if (browser.ios && event.composed &&
31
- // insertParagraph will be the input type when the enter key is pressed.
32
- eventInputType === 'insertParagraph' && findCodeBlock(view.state, view.state.selection)) {
33
- event.preventDefault();
34
- return true;
35
- } else if (browser.android && event.composed && eventInputType === 'insertCompositionText' && eventText[(eventText === null || eventText === void 0 ? void 0 : eventText.length) - 1] === '\n' && findCodeBlock(view.state, view.state.selection)) {
36
- var resultingText = event.target.outerText + '\n';
37
- if (resultingText.endsWith(eventText)) {
38
- // End of paragraph
39
- setTimeout(function () {
40
- view.someProp('handleKeyDown', function (f) {
41
- return f(view, new KeyboardEvent('keydown', {
42
- bubbles: true,
43
- cancelable: true,
44
- key: 'Enter',
45
- code: 'Enter'
46
- }));
47
- });
48
- }, 0);
49
- } else {
50
- // Middle of paragraph, end of line
51
- ignoreFollowingMutations(view.state, view.dispatch);
52
- }
53
- return true;
54
- }
55
- if (browser.android) {
56
- resetShouldIgnoreFollowingMutations(view.state, view.dispatch);
57
- }
58
- return false;
59
- };
60
- }
61
- return new SafePlugin({
62
- state: {
63
- init: function init(_, state) {
64
- var node = findCodeBlock(state, state.selection);
65
- return {
66
- pos: node ? node.pos : null,
67
- contentCopied: false,
68
- isNodeSelected: false,
69
- shouldIgnoreFollowingMutations: false
70
- };
71
- },
72
- apply: function apply(tr, pluginState, _oldState, newState) {
73
- if (tr.docChanged || tr.selectionSet) {
74
- var node = findCodeBlock(newState, tr.selection);
75
- var newPluginState = _objectSpread(_objectSpread({}, pluginState), {}, {
76
- pos: node ? node.pos : null,
77
- isNodeSelected: tr.selection instanceof NodeSelection
78
- });
79
- return newPluginState;
80
- }
81
- var meta = tr.getMeta(pluginKey);
82
- if ((meta === null || meta === void 0 ? void 0 : meta.type) === ACTIONS.SET_COPIED_TO_CLIPBOARD) {
83
- return _objectSpread(_objectSpread({}, pluginState), {}, {
84
- contentCopied: meta.data
85
- });
86
- } else if ((meta === null || meta === void 0 ? void 0 : meta.type) === ACTIONS.SET_SHOULD_IGNORE_FOLLOWING_MUTATIONS) {
87
- return _objectSpread(_objectSpread({}, pluginState), {}, {
88
- shouldIgnoreFollowingMutations: meta.data
89
- });
90
- }
91
- return pluginState;
92
- }
93
- },
94
- key: pluginKey,
95
- props: {
96
- nodeViews: {
97
- codeBlock: codeBlockNodeView
98
- },
99
- handleClickOn: createSelectionClickHandler(['codeBlock'], function (target) {
100
- return !!(target.closest(".".concat(codeBlockClassNames.gutter)) || target.classList.contains(codeBlockClassNames.content));
101
- }, {
102
- useLongPressSelection: useLongPressSelection
103
- }),
104
- handleDOMEvents: handleDOMEvents
105
- }
106
- });
107
- };
@@ -1,25 +0,0 @@
1
- import { browser } from '@atlaskit/editor-common/utils';
2
- import { pluginKey } from './plugin-key';
3
-
4
- // Workaround for a firefox issue where dom selection is off sync
5
- // https://product-fabric.atlassian.net/browse/ED-12442
6
- var refreshBrowserSelection = function refreshBrowserSelection() {
7
- var domSelection = window.getSelection();
8
- if (domSelection) {
9
- var domRange = domSelection && domSelection.rangeCount === 1 && domSelection.getRangeAt(0).cloneRange();
10
- if (domRange) {
11
- domSelection.removeAllRanges();
12
- domSelection.addRange(domRange);
13
- }
14
- }
15
- };
16
- var refreshBrowserSelectionOnChange = function refreshBrowserSelectionOnChange(transaction, editorState) {
17
- var _pluginKey$getState;
18
- if (browser.gecko && transaction.docChanged &&
19
- // codeblockState.pos should be set if current selection is in a codeblock.
20
- typeof ((_pluginKey$getState = pluginKey.getState(editorState)) === null || _pluginKey$getState === void 0 ? void 0 : _pluginKey$getState.pos) === 'number') {
21
- refreshBrowserSelection();
22
- }
23
- };
24
- export default refreshBrowserSelectionOnChange;
25
- export { refreshBrowserSelection };