@atlaskit/editor-core 189.3.4 → 189.3.6

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 +7 -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,153 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.codeBlockNodeView = exports.CodeBlockView = void 0;
8
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
12
- var _rafSchd = _interopRequireDefault(require("raf-schd"));
13
- var _utils = require("@atlaskit/editor-common/utils");
14
- var _model = require("@atlaskit/editor-prosemirror/model");
15
- var _classNames = require("../ui/class-names");
16
- var _actions = require("../actions");
17
- var _mainState = require("../pm-plugins/main-state");
18
- var MATCH_NEWLINES = new RegExp('\n', 'g');
19
- var toDOM = function toDOM(node) {
20
- return ['div', {
21
- class: 'code-block'
22
- }, ['div', {
23
- class: _classNames.codeBlockClassNames.start,
24
- contenteditable: 'false'
25
- }], ['div', {
26
- class: _classNames.codeBlockClassNames.contentWrapper
27
- }, ['div', {
28
- class: _classNames.codeBlockClassNames.gutter,
29
- contenteditable: 'false'
30
- }], ['div', {
31
- class: _classNames.codeBlockClassNames.content
32
- }, ['code', {
33
- 'data-language': node.attrs.language || '',
34
- spellcheck: 'false',
35
- contenteditable: 'true',
36
- 'data-testid': 'code-block--code'
37
- }, 0]]], ['div', {
38
- class: _classNames.codeBlockClassNames.end,
39
- contenteditable: 'false'
40
- }]];
41
- };
42
- var CodeBlockView = exports.CodeBlockView = /*#__PURE__*/function () {
43
- function CodeBlockView(_node, view, getPos) {
44
- var _this = this;
45
- (0, _classCallCheck2.default)(this, CodeBlockView);
46
- (0, _defineProperty2.default)(this, "ensureLineNumbers", (0, _rafSchd.default)(function () {
47
- var lines = 1;
48
- _this.node.forEach(function (node) {
49
- var text = node.text;
50
- if (text) {
51
- lines += (node.text.match(MATCH_NEWLINES) || []).length;
52
- }
53
- });
54
- while (_this.lineNumberGutter.childElementCount < lines) {
55
- _this.lineNumberGutter.appendChild(document.createElement('span'));
56
- }
57
- while (_this.lineNumberGutter.childElementCount > lines) {
58
- _this.lineNumberGutter.removeChild(_this.lineNumberGutter.lastChild);
59
- }
60
- }));
61
- var _DOMSerializer$render = _model.DOMSerializer.renderSpec(document, toDOM(_node)),
62
- dom = _DOMSerializer$render.dom,
63
- contentDOM = _DOMSerializer$render.contentDOM;
64
- this.getPos = getPos;
65
- this.view = view;
66
- this.node = _node;
67
- this.dom = dom;
68
- this.contentDOM = contentDOM;
69
- this.lineNumberGutter = this.dom.querySelector(".".concat(_classNames.codeBlockClassNames.gutter));
70
- this.ensureLineNumbers();
71
- }
72
- (0, _createClass2.default)(CodeBlockView, [{
73
- key: "updateDOMAndSelection",
74
- value: function updateDOMAndSelection(savedInnerHTML, newCursorPosition) {
75
- var _this$dom;
76
- if ((_this$dom = this.dom) !== null && _this$dom !== void 0 && _this$dom.childNodes && this.dom.childNodes.length > 1) {
77
- var _contentView$childNod;
78
- var contentWrapper = this.dom.childNodes[1];
79
- var contentView = contentWrapper === null || contentWrapper === void 0 ? void 0 : contentWrapper.childNodes[1];
80
- if ((contentView === null || contentView === void 0 || (_contentView$childNod = contentView.childNodes) === null || _contentView$childNod === void 0 ? void 0 : _contentView$childNod.length) > 0) {
81
- var codeElement = contentView.firstChild;
82
- codeElement.innerHTML = savedInnerHTML;
83
-
84
- // We need to set cursor for the DOM update
85
- var textElement = (0, _toConsumableArray2.default)(codeElement.childNodes).find(function (child) {
86
- return child.nodeName === '#text';
87
- });
88
- var sel = window.getSelection();
89
- var range = document.createRange();
90
- range.setStart(textElement, newCursorPosition);
91
- range.collapse(true);
92
- sel === null || sel === void 0 || sel.removeAllRanges();
93
- sel === null || sel === void 0 || sel.addRange(range);
94
- }
95
- }
96
- }
97
- }, {
98
- key: "coalesceDOMElements",
99
- value: function coalesceDOMElements() {
100
- var _this$dom2;
101
- if ((_this$dom2 = this.dom) !== null && _this$dom2 !== void 0 && _this$dom2.childNodes && this.dom.childNodes.length > 1) {
102
- var contentWrapper = this.dom.childNodes[1];
103
- var contentView = contentWrapper === null || contentWrapper === void 0 ? void 0 : contentWrapper.childNodes[1];
104
- if (contentView !== null && contentView !== void 0 && contentView.childNodes && contentView.childNodes.length > 1) {
105
- var savedInnerHTML = '';
106
- while (contentView.childNodes.length > 1) {
107
- var lastChild = contentView.lastChild;
108
- savedInnerHTML = lastChild.innerHTML + savedInnerHTML;
109
- contentView.removeChild(lastChild);
110
- }
111
- var firstChild = contentView.firstChild;
112
- savedInnerHTML = firstChild.innerHTML + '\n' + savedInnerHTML;
113
- var newCursorPosition = firstChild.innerHTML.length + 1;
114
- setTimeout(this.updateDOMAndSelection.bind(this, savedInnerHTML, newCursorPosition), 20);
115
- }
116
- }
117
- }
118
- }, {
119
- key: "update",
120
- value: function update(node) {
121
- if (node.type !== this.node.type) {
122
- return false;
123
- }
124
- if (node !== this.node) {
125
- if (node.attrs.language !== this.node.attrs.language) {
126
- this.contentDOM.setAttribute('data-language', node.attrs.language || '');
127
- }
128
- this.node = node;
129
- this.ensureLineNumbers();
130
- if (_utils.browser.android) {
131
- this.coalesceDOMElements();
132
- (0, _actions.resetShouldIgnoreFollowingMutations)(this.view.state, this.view.dispatch);
133
- }
134
- }
135
- return true;
136
- }
137
- }, {
138
- key: "ignoreMutation",
139
- value: function ignoreMutation(record) {
140
- var pluginState = (0, _mainState.getPluginState)(this.view.state);
141
- if (pluginState !== null && pluginState !== void 0 && pluginState.shouldIgnoreFollowingMutations) {
142
- return true;
143
- }
144
-
145
- // Ensure updating the line-number gutter doesn't trigger reparsing the codeblock
146
- return record.target === this.lineNumberGutter || record.target.parentNode === this.lineNumberGutter;
147
- }
148
- }]);
149
- return CodeBlockView;
150
- }();
151
- var codeBlockNodeView = exports.codeBlockNodeView = function codeBlockNodeView(node, view, getPos) {
152
- return new CodeBlockView(node, view, getPos);
153
- };
@@ -1,8 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.pluginKey = void 0;
7
- var _state = require("@atlaskit/editor-prosemirror/state");
8
- var pluginKey = exports.pluginKey = new _state.PluginKey('codeBlockPlugin');
@@ -1,10 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ACTIONS = void 0;
7
- var ACTIONS = exports.ACTIONS = {
8
- SET_COPIED_TO_CLIPBOARD: 'SET_COPIED_TO_CLIPBOARD',
9
- SET_SHOULD_IGNORE_FOLLOWING_MUTATIONS: 'SET_SHOULD_IGNORE_FOLLOWING_MUTATIONS'
10
- };
@@ -1,113 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.codeBlockCopySelectionPlugin = codeBlockCopySelectionPlugin;
8
- exports.copySelectionPluginKey = void 0;
9
- exports.provideVisualFeedbackForCopyButton = provideVisualFeedbackForCopyButton;
10
- exports.removeVisualFeedbackForCopyButton = removeVisualFeedbackForCopyButton;
11
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
12
- var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
13
- var _state = require("@atlaskit/editor-prosemirror/state");
14
- var _view = require("@atlaskit/editor-prosemirror/view");
15
- var _copyButton = require("@atlaskit/editor-common/copy-button");
16
- var copySelectionPluginKey = exports.copySelectionPluginKey = new _state.PluginKey('codeBlockCopySelectionPlugin');
17
- function getSelectionDecorationStartAndEnd(_ref) {
18
- var state = _ref.state,
19
- transaction = _ref.transaction;
20
- var codeBlockNode = (0, _copyButton.getSelectedNodeOrNodeParentByNodeType)({
21
- nodeType: state.schema.nodes.codeBlock,
22
- selection: transaction.selection
23
- });
24
- if (!codeBlockNode) {
25
- return {
26
- decorationStartAndEnd: undefined
27
- };
28
- }
29
- var decorationStartAndEnd = [codeBlockNode.start, codeBlockNode.start + codeBlockNode.node.nodeSize];
30
- return {
31
- decorationStartAndEnd: decorationStartAndEnd
32
- };
33
- }
34
- function codeBlockCopySelectionPlugin() {
35
- return new _safePlugin.SafePlugin({
36
- key: copySelectionPluginKey,
37
- state: {
38
- init: function init() {
39
- return {
40
- decorationStartAndEnd: undefined
41
- };
42
- },
43
- apply: function apply(transaction, currentCodeBlockCopySelectionPluginState, _oldState, newState) {
44
- switch (transaction.getMeta(copySelectionPluginKey)) {
45
- case 'show-selection':
46
- {
47
- return getSelectionDecorationStartAndEnd({
48
- state: newState,
49
- transaction: transaction
50
- });
51
- }
52
- case 'remove-selection':
53
- return {
54
- decorationStartAndEnd: undefined
55
- };
56
- default:
57
- // The contents of the code block can change while the selection is being shown
58
- // (either from collab edits -- or from the user continuing to type while hovering
59
- // the mouse over the copy button).
60
- // This ensures the selection is updated in these cases.
61
- if (currentCodeBlockCopySelectionPluginState.decorationStartAndEnd !== undefined) {
62
- return getSelectionDecorationStartAndEnd({
63
- state: newState,
64
- transaction: transaction
65
- });
66
- }
67
- return currentCodeBlockCopySelectionPluginState;
68
- }
69
- }
70
- },
71
- props: {
72
- decorations: function decorations(state) {
73
- if (copySelectionPluginKey.getState(state).decorationStartAndEnd) {
74
- var _copySelectionPluginK = (0, _slicedToArray2.default)(copySelectionPluginKey.getState(state).decorationStartAndEnd, 2),
75
- _start = _copySelectionPluginK[0],
76
- _end = _copySelectionPluginK[1];
77
- return _view.DecorationSet.create(state.doc, [_view.Decoration.inline(_start, _end, {
78
- class: 'ProseMirror-fake-text-selection'
79
- })]);
80
- }
81
- return _view.DecorationSet.empty;
82
- }
83
- }
84
- });
85
- }
86
- function provideVisualFeedbackForCopyButton(state, dispatch) {
87
- var tr = state.tr;
88
- tr.setMeta(copySelectionPluginKey, 'show-selection');
89
-
90
- // note: dispatch should always be defined when called from the
91
- // floating toolbar. Howver the Command type which the floating toolbar
92
- // uses suggests it's optional.
93
- // Using the type here to protect against future refactors of the
94
- // floating toolbar
95
- if (dispatch) {
96
- dispatch(tr);
97
- }
98
- return true;
99
- }
100
- function removeVisualFeedbackForCopyButton(state, dispatch) {
101
- var tr = state.tr;
102
- tr.setMeta(copySelectionPluginKey, 'remove-selection');
103
-
104
- // note: dispatch should always be defined when called from the
105
- // floating toolbar. Howver the Command type which the floating toolbar
106
- // uses suggests it's optional.
107
- // Using the type here to protect against future refactors of the
108
- // floating toolbar
109
- if (dispatch) {
110
- dispatch(tr);
111
- }
112
- return true;
113
- }
@@ -1,132 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
8
- var _state = require("@atlaskit/editor-prosemirror/state");
9
- var _keymap = require("@atlaskit/editor-prosemirror/keymap");
10
- var _utils = require("@atlaskit/editor-prosemirror/utils");
11
- var _utils2 = require("../utils");
12
- var _utils3 = require("@atlaskit/editor-common/utils");
13
- var _pairedCharacterHandling = require("../ide-ux/paired-character-handling");
14
- var _bracketHandling = require("../ide-ux/bracket-handling");
15
- var _quoteHandling = require("../ide-ux/quote-handling");
16
- var _lineHandling = require("../ide-ux/line-handling");
17
- var _commands = require("../ide-ux/commands");
18
- var ideUX = function ideUX(pluginInjectionApi) {
19
- var _pluginInjectionApi$a;
20
- var editorAnalyticsAPI = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions;
21
- return new _safePlugin.SafePlugin({
22
- props: {
23
- handleTextInput: function handleTextInput(view, from, to, text) {
24
- var _pluginInjectionApi$c;
25
- var state = view.state,
26
- dispatch = view.dispatch;
27
- var compositionPluginState = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c = pluginInjectionApi.composition) === null || _pluginInjectionApi$c === void 0 ? void 0 : _pluginInjectionApi$c.sharedState.currentState();
28
- if ((0, _lineHandling.isCursorInsideCodeBlock)(state) && !(compositionPluginState !== null && compositionPluginState !== void 0 && compositionPluginState.isComposing)) {
29
- var beforeText = (0, _lineHandling.getStartOfCurrentLine)(state).text;
30
- var afterText = (0, _lineHandling.getEndOfCurrentLine)(state).text;
31
-
32
- // If text is a closing bracket/quote and we've already inserted it, move the selection after
33
- if ((0, _pairedCharacterHandling.isCursorBeforeClosingCharacter)(afterText) && (0, _pairedCharacterHandling.isClosingCharacter)(text) && afterText.startsWith(text)) {
34
- dispatch((0, _utils.setTextSelection)(to + text.length)(state.tr));
35
- return true;
36
- }
37
-
38
- // Automatically add right-hand side bracket when user types the left bracket
39
- if ((0, _bracketHandling.shouldAutoCloseBracket)(beforeText, afterText)) {
40
- var _getAutoClosingBracke = (0, _bracketHandling.getAutoClosingBracketInfo)(beforeText + text, afterText),
41
- left = _getAutoClosingBracke.left,
42
- right = _getAutoClosingBracke.right;
43
- if (left && right) {
44
- var bracketPair = state.schema.text(text + right);
45
- var tr = state.tr.replaceWith(from, to, bracketPair);
46
- dispatch((0, _utils.setTextSelection)(from + text.length)(tr));
47
- return true;
48
- }
49
- }
50
-
51
- // Automatically add closing quote when user types a starting quote
52
- if ((0, _quoteHandling.shouldAutoCloseQuote)(beforeText, afterText)) {
53
- var _getAutoClosingQuoteI = (0, _quoteHandling.getAutoClosingQuoteInfo)(beforeText + text, afterText),
54
- leftQuote = _getAutoClosingQuoteI.left,
55
- rightQuote = _getAutoClosingQuoteI.right;
56
- if (leftQuote && rightQuote) {
57
- var quotePair = state.schema.text(text + rightQuote);
58
- var _tr = state.tr.replaceWith(from, to, quotePair);
59
- dispatch((0, _utils.setTextSelection)(from + text.length)(_tr));
60
- return true;
61
- }
62
- }
63
- }
64
- return false;
65
- },
66
- handleKeyDown: (0, _keymap.keydownHandler)({
67
- Backspace: function Backspace(state, dispatch) {
68
- if ((0, _lineHandling.isCursorInsideCodeBlock)(state)) {
69
- var $cursor = (0, _utils2.getCursor)(state.selection);
70
- var beforeText = (0, _lineHandling.getStartOfCurrentLine)(state).text;
71
- var afterText = (0, _lineHandling.getEndOfCurrentLine)(state).text;
72
- var _getAutoClosingBracke2 = (0, _bracketHandling.getAutoClosingBracketInfo)(beforeText, afterText),
73
- leftBracket = _getAutoClosingBracke2.left,
74
- rightBracket = _getAutoClosingBracke2.right,
75
- hasTrailingMatchingBracket = _getAutoClosingBracke2.hasTrailingMatchingBracket;
76
- if (leftBracket && rightBracket && hasTrailingMatchingBracket && dispatch) {
77
- dispatch(state.tr.delete($cursor.pos - leftBracket.length, $cursor.pos + rightBracket.length));
78
- return true;
79
- }
80
- var _getAutoClosingQuoteI2 = (0, _quoteHandling.getAutoClosingQuoteInfo)(beforeText, afterText),
81
- leftQuote = _getAutoClosingQuoteI2.left,
82
- rightQuote = _getAutoClosingQuoteI2.right,
83
- hasTrailingMatchingQuote = _getAutoClosingQuoteI2.hasTrailingMatchingQuote;
84
- if (leftQuote && rightQuote && hasTrailingMatchingQuote && dispatch) {
85
- dispatch(state.tr.delete($cursor.pos - leftQuote.length, $cursor.pos + rightQuote.length));
86
- return true;
87
- }
88
- var _getLineInfo = (0, _lineHandling.getLineInfo)(beforeText),
89
- _getLineInfo$indentTo = _getLineInfo.indentToken,
90
- size = _getLineInfo$indentTo.size,
91
- token = _getLineInfo$indentTo.token,
92
- indentText = _getLineInfo.indentText;
93
- if (beforeText === indentText) {
94
- if (indentText.endsWith(token.repeat(size)) && dispatch) {
95
- dispatch(state.tr.delete($cursor.pos - (size - indentText.length % size || size), $cursor.pos));
96
- return true;
97
- }
98
- }
99
- }
100
- return false;
101
- },
102
- Enter: (0, _utils3.filterCommand)(_lineHandling.isSelectionEntirelyInsideCodeBlock, _commands.insertNewlineWithIndent),
103
- 'Mod-]': (0, _utils3.filterCommand)(_lineHandling.isSelectionEntirelyInsideCodeBlock, (0, _commands.indent)(editorAnalyticsAPI)),
104
- 'Mod-[': (0, _utils3.filterCommand)(_lineHandling.isSelectionEntirelyInsideCodeBlock, (0, _commands.outdent)(editorAnalyticsAPI)),
105
- Tab: (0, _utils3.filterCommand)(_lineHandling.isSelectionEntirelyInsideCodeBlock, function (state, dispatch) {
106
- if (!dispatch) {
107
- return false;
108
- }
109
- if ((0, _lineHandling.isCursorInsideCodeBlock)(state)) {
110
- return (0, _commands.insertIndent)(state, dispatch);
111
- }
112
- return (0, _commands.indent)(editorAnalyticsAPI)(state, dispatch);
113
- }),
114
- 'Shift-Tab': (0, _utils3.filterCommand)(_lineHandling.isSelectionEntirelyInsideCodeBlock, (0, _commands.outdent)(editorAnalyticsAPI)),
115
- 'Mod-a': function ModA(state, dispatch) {
116
- if ((0, _lineHandling.isSelectionEntirelyInsideCodeBlock)(state)) {
117
- var _state$selection = state.selection,
118
- $from = _state$selection.$from,
119
- $to = _state$selection.$to;
120
- var isFullCodeBlockSelection = $from.parentOffset === 0 && $to.parentOffset === $to.parent.nodeSize - 2;
121
- if (!isFullCodeBlockSelection && dispatch) {
122
- dispatch(state.tr.setSelection(_state.TextSelection.create(state.doc, $from.start(), $to.end())));
123
- return true;
124
- }
125
- }
126
- return false;
127
- }
128
- })
129
- }
130
- });
131
- };
132
- var _default = exports.default = ideUX;
@@ -1,68 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createCodeBlockInputRule = createCodeBlockInputRule;
7
- var _utils = require("@atlaskit/editor-prosemirror/utils");
8
- var _prosemirrorInputRules = require("@atlaskit/prosemirror-input-rules");
9
- var _analytics = require("@atlaskit/editor-common/analytics");
10
- var _utils2 = require("@atlaskit/editor-common/utils");
11
- var _transformToCodeBlock = require("../transform-to-code-block");
12
- var _commands = require("@atlaskit/editor-common/commands");
13
- function createCodeBlockInputRule(schema, editorAnalyticsAPI) {
14
- var rules = getCodeBlockRules(editorAnalyticsAPI, schema);
15
- return (0, _prosemirrorInputRules.createPlugin)('code-block-input-rule', rules, {
16
- isBlockNodeRule: true
17
- });
18
- }
19
-
20
- /**
21
- * Get all code block input rules
22
- *
23
- * @param {Schema} schema
24
- * @returns {InputRuleWithHandler[]}
25
- */
26
- function getCodeBlockRules(editorAnalyticsAPI, schema) {
27
- var ruleAnalytics = (0, _utils2.inputRuleWithAnalytics)({
28
- action: _analytics.ACTION.INSERTED,
29
- actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
30
- actionSubjectId: _analytics.ACTION_SUBJECT_ID.CODE_BLOCK,
31
- attributes: {
32
- inputMethod: _analytics.INPUT_METHOD.FORMATTING
33
- },
34
- eventType: _analytics.EVENT_TYPE.TRACK
35
- }, editorAnalyticsAPI);
36
- var validMatchLength = function validMatchLength(match) {
37
- return match.length > 0 && match[0].length === 3;
38
- };
39
- var threeTildeRule = (0, _prosemirrorInputRules.createRule)(/(?!\s)(`{3,})$/, function (state, match, start, end) {
40
- if (!validMatchLength(match)) {
41
- return null;
42
- }
43
- var attributes = {};
44
- if (match[4]) {
45
- attributes.language = match[4];
46
- }
47
- if ((0, _transformToCodeBlock.isConvertableToCodeBlock)(state)) {
48
- return (0, _transformToCodeBlock.transformToCodeBlockAction)(state, start, attributes);
49
- }
50
- var tr = state.tr;
51
- tr.delete(start, end);
52
- var codeBlock = tr.doc.type.schema.nodes.codeBlock.createChecked();
53
- (0, _utils.safeInsert)(codeBlock)(tr);
54
- return tr;
55
- });
56
- var leftNodeReplacementThreeTildeRule = (0, _prosemirrorInputRules.createRule)(new RegExp("((".concat(_prosemirrorInputRules.leafNodeReplacementCharacter, "`{3,})|^\\s(`{3,}))(\\S*)$")), function (state, match, start, end) {
57
- if (!validMatchLength(match)) {
58
- return null;
59
- }
60
- var attributes = {};
61
- if (match[4]) {
62
- attributes.language = match[4];
63
- }
64
- var inlineStart = Math.max(match.index + state.selection.$from.start(), 1);
65
- return (0, _commands.insertBlock)(state, schema.nodes.codeBlock, inlineStart, end, attributes);
66
- });
67
- return [ruleAnalytics(threeTildeRule), ruleAnalytics(leftNodeReplacementThreeTildeRule)];
68
- }
@@ -1,66 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- exports.keymapPlugin = keymapPlugin;
8
- var _keymap = require("@atlaskit/editor-prosemirror/keymap");
9
- var _state = require("@atlaskit/editor-prosemirror/state");
10
- var _utils = require("@atlaskit/editor-prosemirror/utils");
11
- var _utils2 = require("../utils");
12
- var _utils3 = require("@atlaskit/editor-common/utils");
13
- var deleteCurrentItem = function deleteCurrentItem($from) {
14
- return function (tr) {
15
- return tr.delete($from.before($from.depth), $from.after($from.depth));
16
- };
17
- };
18
- var setTextSelection = function setTextSelection(pos) {
19
- return function (tr) {
20
- var newSelection = _state.Selection.findFrom(tr.doc.resolve(pos), -1, true);
21
- if (newSelection) {
22
- tr.setSelection(newSelection);
23
- }
24
- return tr;
25
- };
26
- };
27
- function keymapPlugin(schema) {
28
- return (0, _keymap.keymap)({
29
- Backspace: function Backspace(state, dispatch) {
30
- var $cursor = (0, _utils2.getCursor)(state.selection);
31
- var _state$schema$nodes = state.schema.nodes,
32
- paragraph = _state$schema$nodes.paragraph,
33
- codeBlock = _state$schema$nodes.codeBlock,
34
- listItem = _state$schema$nodes.listItem,
35
- table = _state$schema$nodes.table,
36
- layoutColumn = _state$schema$nodes.layoutColumn;
37
- if (!$cursor || $cursor.parent.type !== codeBlock || !dispatch) {
38
- return false;
39
- }
40
- if ($cursor.pos === 1 || (0, _utils.hasParentNodeOfType)(listItem)(state.selection) && $cursor.parentOffset === 0) {
41
- var node = (0, _utils.findParentNodeOfTypeClosestToPos)($cursor, codeBlock);
42
- if (!node) {
43
- return false;
44
- }
45
- dispatch(state.tr.setNodeMarkup(node.pos, node.node.type, node.node.attrs, []).setBlockType($cursor.pos, $cursor.pos, paragraph));
46
- return true;
47
- }
48
- if ($cursor.node && (0, _utils3.isEmptyNode)(schema)($cursor.node()) && ((0, _utils.hasParentNodeOfType)(layoutColumn)(state.selection) || (0, _utils.hasParentNodeOfType)(table)(state.selection))) {
49
- var tr = state.tr;
50
- var insertPos = $cursor.pos;
51
- deleteCurrentItem($cursor)(tr);
52
- setTextSelection(insertPos)(tr);
53
- dispatch(tr.scrollIntoView());
54
- return true;
55
- }
56
-
57
- // Handle not nested empty code block
58
- if ((0, _utils3.isEmptyNode)(schema)($cursor.node())) {
59
- dispatch(deleteCurrentItem($cursor)(state === null || state === void 0 ? void 0 : state.tr));
60
- return true;
61
- }
62
- return false;
63
- }
64
- });
65
- }
66
- var _default = exports.default = keymapPlugin;
@@ -1,10 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getPluginState = void 0;
7
- var _pluginKey = require("../plugin-key");
8
- var getPluginState = exports.getPluginState = function getPluginState(state) {
9
- return _pluginKey.pluginKey.getState(state);
10
- };