@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,201 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.copyContentToClipboard = exports.changeLanguage = void 0;
7
- exports.createInsertCodeBlockTransaction = createInsertCodeBlockTransaction;
8
- exports.ignoreFollowingMutations = void 0;
9
- exports.insertCodeBlockWithAnalytics = insertCodeBlockWithAnalytics;
10
- exports.resetShouldIgnoreFollowingMutations = exports.resetCopiedState = exports.removeCodeBlock = void 0;
11
- var _utils = require("@atlaskit/editor-prosemirror/utils");
12
- var _state = require("@atlaskit/editor-prosemirror/state");
13
- var _pluginKey = require("./plugin-key");
14
- var _codeBlockCopySelectionPlugin = require("./pm-plugins/codeBlockCopySelectionPlugin");
15
- var _actions = require("./pm-plugins/actions");
16
- var _clipboard = require("@atlaskit/editor-common/clipboard");
17
- var _insert = require("@atlaskit/editor-common/insert");
18
- var _transformToCodeBlock = require("./transform-to-code-block");
19
- var _editorAnalytics = require("@atlaskit/editor-common/editor-analytics");
20
- var _analytics = require("@atlaskit/editor-common/analytics");
21
- var removeCodeBlock = exports.removeCodeBlock = function removeCodeBlock(state, dispatch) {
22
- var nodes = state.schema.nodes,
23
- tr = state.tr;
24
- if (dispatch) {
25
- var removeTr = tr;
26
- if ((0, _utils.findSelectedNodeOfType)(nodes.codeBlock)(tr.selection)) {
27
- removeTr = (0, _utils.removeSelectedNode)(tr);
28
- } else {
29
- removeTr = (0, _utils.removeParentNodeOfType)(nodes.codeBlock)(tr);
30
- }
31
- dispatch(removeTr);
32
- }
33
- return true;
34
- };
35
- var changeLanguage = exports.changeLanguage = function changeLanguage(editorAnalyticsAPI) {
36
- return function (language) {
37
- return function (state, dispatch) {
38
- var _pluginKey$getState;
39
- var codeBlock = state.schema.nodes.codeBlock;
40
- var pos = (_pluginKey$getState = _pluginKey.pluginKey.getState(state)) === null || _pluginKey$getState === void 0 ? void 0 : _pluginKey$getState.pos;
41
- if (typeof pos !== 'number') {
42
- return false;
43
- }
44
- var tr = state.tr.setNodeMarkup(pos, codeBlock, {
45
- language: language
46
- }).setMeta('scrollIntoView', false);
47
- var selection = (0, _utils.isNodeSelection)(state.selection) ? _state.NodeSelection.create(tr.doc, pos) : tr.selection;
48
- var result = tr.setSelection(selection);
49
- if (dispatch) {
50
- editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
51
- action: _analytics.ACTION.LANGUAGE_SELECTED,
52
- actionSubject: _analytics.ACTION_SUBJECT.CODE_BLOCK,
53
- attributes: {
54
- language: language
55
- },
56
- eventType: _analytics.EVENT_TYPE.TRACK
57
- })(result);
58
- dispatch(result);
59
- }
60
- return true;
61
- };
62
- };
63
- };
64
- var copyContentToClipboard = exports.copyContentToClipboard = function copyContentToClipboard(state, dispatch) {
65
- var nodes = state.schema.nodes,
66
- tr = state.tr;
67
- var codeBlock = (0, _utils.findParentNodeOfType)(nodes.codeBlock)(tr.selection);
68
- var textContent = codeBlock && codeBlock.node.textContent;
69
- if (textContent) {
70
- (0, _clipboard.copyToClipboard)(textContent);
71
- var copyToClipboardTr = tr;
72
- copyToClipboardTr.setMeta(_pluginKey.pluginKey, {
73
- type: _actions.ACTIONS.SET_COPIED_TO_CLIPBOARD,
74
- data: true
75
- });
76
- copyToClipboardTr.setMeta(_codeBlockCopySelectionPlugin.copySelectionPluginKey, 'remove-selection');
77
- if (dispatch) {
78
- dispatch(copyToClipboardTr);
79
- }
80
- }
81
- return true;
82
- };
83
- var resetCopiedState = exports.resetCopiedState = function resetCopiedState(state, dispatch) {
84
- var tr = state.tr;
85
- var codeBlockState = _pluginKey.pluginKey.getState(state);
86
- var resetCopiedStateTr = tr;
87
- if (codeBlockState && codeBlockState.contentCopied) {
88
- resetCopiedStateTr.setMeta(_pluginKey.pluginKey, {
89
- type: _actions.ACTIONS.SET_COPIED_TO_CLIPBOARD,
90
- data: false
91
- });
92
- resetCopiedStateTr.setMeta(_codeBlockCopySelectionPlugin.copySelectionPluginKey, 'remove-selection');
93
- if (dispatch) {
94
- dispatch(resetCopiedStateTr);
95
- }
96
- } else {
97
- var clearSelectionStateTransaction = state.tr;
98
- clearSelectionStateTransaction.setMeta(_codeBlockCopySelectionPlugin.copySelectionPluginKey, 'remove-selection');
99
- // note: dispatch should always be defined when called from the
100
- // floating toolbar. Howver the Command type which floating toolbar uses
101
- // (and resetCopiedState) uses suggests it's optional.
102
- if (dispatch) {
103
- dispatch(clearSelectionStateTransaction);
104
- }
105
- }
106
- return true;
107
- };
108
- var ignoreFollowingMutations = exports.ignoreFollowingMutations = function ignoreFollowingMutations(state, dispatch) {
109
- var tr = state.tr;
110
- var ignoreFollowingMutationsTr = tr;
111
- ignoreFollowingMutationsTr.setMeta(_pluginKey.pluginKey, {
112
- type: _actions.ACTIONS.SET_SHOULD_IGNORE_FOLLOWING_MUTATIONS,
113
- data: true
114
- });
115
- if (dispatch) {
116
- dispatch(ignoreFollowingMutationsTr);
117
- }
118
- return true;
119
- };
120
- var resetShouldIgnoreFollowingMutations = exports.resetShouldIgnoreFollowingMutations = function resetShouldIgnoreFollowingMutations(state, dispatch) {
121
- var tr = state.tr;
122
- var ignoreFollowingMutationsTr = tr;
123
- ignoreFollowingMutationsTr.setMeta(_pluginKey.pluginKey, {
124
- type: _actions.ACTIONS.SET_SHOULD_IGNORE_FOLLOWING_MUTATIONS,
125
- data: false
126
- });
127
- if (dispatch) {
128
- dispatch(ignoreFollowingMutationsTr);
129
- }
130
- return true;
131
- };
132
-
133
- /**
134
- * This function creates a new transaction that inserts a code block,
135
- * if there is text selected it will wrap the current selection if not it will
136
- * append the codeblock to the end of the document.
137
- */
138
- function createInsertCodeBlockTransaction(_ref) {
139
- var _state$selection$$fro;
140
- var state = _ref.state;
141
- var tr = state.tr;
142
- var from = state.selection.from;
143
- var codeBlock = state.schema.nodes.codeBlock;
144
- var grandParentNodeType = (_state$selection$$fro = state.selection.$from.node(-1)) === null || _state$selection$$fro === void 0 ? void 0 : _state$selection$$fro.type;
145
- var parentNodeType = state.selection.$from.parent.type;
146
-
147
- /** We always want to append a codeBlock unless we're inserting into a paragraph
148
- * AND it's a valid child of the grandparent node.
149
- * Insert the current selection as codeBlock content unless it contains nodes other
150
- * than paragraphs and inline.
151
- */
152
- var canInsertCodeBlock = (0, _insert.shouldSplitSelectedNodeOnNodeInsertion)({
153
- parentNodeType: parentNodeType,
154
- grandParentNodeType: grandParentNodeType,
155
- content: codeBlock.createAndFill()
156
- }) && contentAllowedInCodeBlock(state);
157
- if (canInsertCodeBlock) {
158
- tr = (0, _transformToCodeBlock.transformToCodeBlockAction)(state, from);
159
- } else {
160
- (0, _utils.safeInsert)(codeBlock.createAndFill())(tr).scrollIntoView();
161
- }
162
- return tr;
163
- }
164
-
165
- /**
166
- * Check if the current selection contains any nodes that are not permitted
167
- * as codeBlock child nodes. Note that this allows paragraphs and inline nodes
168
- * as we extract their text content.
169
- */
170
- function contentAllowedInCodeBlock(state) {
171
- var _state$selection = state.selection,
172
- $from = _state$selection.$from,
173
- $to = _state$selection.$to;
174
- var isAllowedChild = true;
175
- state.doc.nodesBetween($from.pos, $to.pos, function (node) {
176
- if (!isAllowedChild) {
177
- return false;
178
- }
179
- return isAllowedChild = node.type === state.schema.nodes.listItem || node.type === state.schema.nodes.bulletList || node.type === state.schema.nodes.orderedList || node.type === state.schema.nodes.paragraph || node.isInline || node.isText;
180
- });
181
- return isAllowedChild;
182
- }
183
- function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI) {
184
- return (0, _editorAnalytics.withAnalytics)(analyticsAPI, {
185
- action: _analytics.ACTION.INSERTED,
186
- actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
187
- actionSubjectId: _analytics.ACTION_SUBJECT_ID.CODE_BLOCK,
188
- attributes: {
189
- inputMethod: inputMethod
190
- },
191
- eventType: _analytics.EVENT_TYPE.TRACK
192
- })(function (state, dispatch) {
193
- var tr = createInsertCodeBlockTransaction({
194
- state: state
195
- });
196
- if (dispatch) {
197
- dispatch(tr);
198
- }
199
- return true;
200
- });
201
- }
@@ -1,35 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.shouldAutoCloseBracket = exports.getAutoClosingBracketInfo = exports.BRACKET_MAP = void 0;
7
- var BRACKET_MAP = exports.BRACKET_MAP = {
8
- '{': '}',
9
- '[': ']',
10
- '(': ')'
11
- };
12
- var shouldAutoCloseBracket = exports.shouldAutoCloseBracket = function shouldAutoCloseBracket(before, after) {
13
- // when directly before a closing bracket
14
- if (/^[}\])]/.test(after)) {
15
- return true;
16
- }
17
-
18
- // exclusion: when directly before a non-whitespace character
19
- if (/^[^\s]/.test(after)) {
20
- return false;
21
- }
22
- return true;
23
- };
24
- var getAutoClosingBracketInfo = exports.getAutoClosingBracketInfo = function getAutoClosingBracketInfo(before, after) {
25
- var left = Object.keys(BRACKET_MAP).find(function (item) {
26
- return before.endsWith(item);
27
- });
28
- var right = left ? BRACKET_MAP[left] : undefined;
29
- var hasTrailingMatchingBracket = right ? after.startsWith(right) : false;
30
- return {
31
- left: left,
32
- right: right,
33
- hasTrailingMatchingBracket: hasTrailingMatchingBracket
34
- };
35
- };
@@ -1,115 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.indent = void 0;
7
- exports.insertIndent = insertIndent;
8
- exports.insertNewlineWithIndent = insertNewlineWithIndent;
9
- exports.outdent = void 0;
10
- var _state = require("@atlaskit/editor-prosemirror/state");
11
- var _lineHandling = require("./line-handling");
12
- var _analytics = require("@atlaskit/editor-common/analytics");
13
- /**
14
- * Return the current indentation level
15
- * @param indentText - Text in the code block that represent an indentation
16
- * @param indentSize - Size of the indentation token in a string
17
- */
18
- function getIndentLevel(indentText, indentSize) {
19
- if (indentSize === 0 || indentText.length === 0) {
20
- return 0;
21
- }
22
- return indentText.length / indentSize;
23
- }
24
- var indent = exports.indent = function indent(editorAnalyticsAPI) {
25
- return function (state, dispatch) {
26
- var _getLinesFromSelectio = (0, _lineHandling.getLinesFromSelection)(state),
27
- text = _getLinesFromSelectio.text,
28
- start = _getLinesFromSelectio.start;
29
- var tr = state.tr,
30
- selection = state.selection;
31
- (0, _lineHandling.forEachLine)(text, function (line, offset) {
32
- var _getLineInfo = (0, _lineHandling.getLineInfo)(line),
33
- indentText = _getLineInfo.indentText,
34
- indentToken = _getLineInfo.indentToken;
35
- var indentLevel = getIndentLevel(indentText, indentToken.size);
36
- var indentToAdd = indentToken.token.repeat(indentToken.size - indentText.length % indentToken.size || indentToken.size);
37
- tr.insertText(indentToAdd, tr.mapping.map(start + offset, -1));
38
- editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
39
- action: _analytics.ACTION.FORMATTED,
40
- actionSubject: _analytics.ACTION_SUBJECT.TEXT,
41
- actionSubjectId: _analytics.ACTION_SUBJECT_ID.FORMAT_INDENT,
42
- eventType: _analytics.EVENT_TYPE.TRACK,
43
- attributes: {
44
- inputMethod: _analytics.INPUT_METHOD.KEYBOARD,
45
- previousIndentationLevel: indentLevel,
46
- newIndentLevel: indentLevel + 1,
47
- direction: _analytics.INDENT_DIRECTION.INDENT,
48
- indentType: _analytics.INDENT_TYPE.CODE_BLOCK
49
- }
50
- })(tr);
51
- if (!selection.empty) {
52
- tr.setSelection(_state.TextSelection.create(tr.doc, tr.mapping.map(selection.from, -1), tr.selection.to));
53
- }
54
- });
55
- if (dispatch) {
56
- dispatch(tr);
57
- }
58
- return true;
59
- };
60
- };
61
- var outdent = exports.outdent = function outdent(editorAnalyticsAPI) {
62
- return function (state, dispatch) {
63
- var _getLinesFromSelectio2 = (0, _lineHandling.getLinesFromSelection)(state),
64
- text = _getLinesFromSelectio2.text,
65
- start = _getLinesFromSelectio2.start;
66
- var tr = state.tr;
67
- (0, _lineHandling.forEachLine)(text, function (line, offset) {
68
- var _getLineInfo2 = (0, _lineHandling.getLineInfo)(line),
69
- indentText = _getLineInfo2.indentText,
70
- indentToken = _getLineInfo2.indentToken;
71
- if (indentText) {
72
- var indentLevel = getIndentLevel(indentText, indentToken.size);
73
- var unindentLength = indentText.length % indentToken.size || indentToken.size;
74
- tr.delete(tr.mapping.map(start + offset), tr.mapping.map(start + offset + unindentLength));
75
- editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
76
- action: _analytics.ACTION.FORMATTED,
77
- actionSubject: _analytics.ACTION_SUBJECT.TEXT,
78
- actionSubjectId: _analytics.ACTION_SUBJECT_ID.FORMAT_INDENT,
79
- eventType: _analytics.EVENT_TYPE.TRACK,
80
- attributes: {
81
- inputMethod: _analytics.INPUT_METHOD.KEYBOARD,
82
- previousIndentationLevel: indentLevel,
83
- newIndentLevel: indentLevel - 1,
84
- direction: _analytics.INDENT_DIRECTION.OUTDENT,
85
- indentType: _analytics.INDENT_TYPE.CODE_BLOCK
86
- }
87
- })(tr);
88
- }
89
- });
90
- if (dispatch) {
91
- dispatch(tr);
92
- }
93
- return true;
94
- };
95
- };
96
- function insertIndent(state, dispatch) {
97
- var _getStartOfCurrentLin = (0, _lineHandling.getStartOfCurrentLine)(state),
98
- textAtStartOfLine = _getStartOfCurrentLin.text;
99
- var _getLineInfo3 = (0, _lineHandling.getLineInfo)(textAtStartOfLine),
100
- indentToken = _getLineInfo3.indentToken;
101
- var indentToAdd = indentToken.token.repeat(indentToken.size - textAtStartOfLine.length % indentToken.size || indentToken.size);
102
- dispatch(state.tr.insertText(indentToAdd));
103
- return true;
104
- }
105
- function insertNewlineWithIndent(state, dispatch) {
106
- var _getStartOfCurrentLin2 = (0, _lineHandling.getStartOfCurrentLine)(state),
107
- textAtStartOfLine = _getStartOfCurrentLin2.text;
108
- var _getLineInfo4 = (0, _lineHandling.getLineInfo)(textAtStartOfLine),
109
- indentText = _getLineInfo4.indentText;
110
- if (indentText && dispatch) {
111
- dispatch(state.tr.insertText('\n' + indentText));
112
- return true;
113
- }
114
- return false;
115
- }
@@ -1,81 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getLineInfo = exports.getEndOfCurrentLine = exports.forEachLine = void 0;
7
- exports.getLinesFromSelection = getLinesFromSelection;
8
- exports.isSelectionEntirelyInsideCodeBlock = exports.isCursorInsideCodeBlock = exports.getStartOfCurrentLine = void 0;
9
- var _utils = require("../utils");
10
- var isSelectionEntirelyInsideCodeBlock = exports.isSelectionEntirelyInsideCodeBlock = function isSelectionEntirelyInsideCodeBlock(state) {
11
- return state.selection.$from.sameParent(state.selection.$to) && state.selection.$from.parent.type === state.schema.nodes.codeBlock;
12
- };
13
- var isCursorInsideCodeBlock = exports.isCursorInsideCodeBlock = function isCursorInsideCodeBlock(state) {
14
- return !!(0, _utils.getCursor)(state.selection) && isSelectionEntirelyInsideCodeBlock(state);
15
- };
16
- var getStartOfCurrentLine = exports.getStartOfCurrentLine = function getStartOfCurrentLine(state) {
17
- var $from = state.selection.$from;
18
- if ($from.nodeBefore && $from.nodeBefore.isText) {
19
- var prevNewLineIndex = $from.nodeBefore.text.lastIndexOf('\n');
20
- return {
21
- text: $from.nodeBefore.text.substring(prevNewLineIndex + 1),
22
- pos: $from.start() + prevNewLineIndex + 1
23
- };
24
- }
25
- return {
26
- text: '',
27
- pos: $from.pos
28
- };
29
- };
30
- var getEndOfCurrentLine = exports.getEndOfCurrentLine = function getEndOfCurrentLine(state) {
31
- var $to = state.selection.$to;
32
- if ($to.nodeAfter && $to.nodeAfter.isText) {
33
- var nextNewLineIndex = $to.nodeAfter.text.indexOf('\n');
34
- return {
35
- text: $to.nodeAfter.text.substring(0, nextNewLineIndex >= 0 ? nextNewLineIndex : undefined),
36
- pos: nextNewLineIndex >= 0 ? $to.pos + nextNewLineIndex : $to.end()
37
- };
38
- }
39
- return {
40
- text: '',
41
- pos: $to.pos
42
- };
43
- };
44
- function getLinesFromSelection(state) {
45
- var _getStartOfCurrentLin = getStartOfCurrentLine(state),
46
- start = _getStartOfCurrentLin.pos;
47
- var _getEndOfCurrentLine = getEndOfCurrentLine(state),
48
- end = _getEndOfCurrentLine.pos;
49
- var text = state.doc.textBetween(start, end);
50
- return {
51
- text: text,
52
- start: start,
53
- end: end
54
- };
55
- }
56
- var forEachLine = exports.forEachLine = function forEachLine(text, callback) {
57
- var offset = 0;
58
- text.split('\n').forEach(function (line) {
59
- callback(line, offset);
60
- offset += line.length + 1;
61
- });
62
- };
63
- var SPACE = {
64
- token: ' ',
65
- size: 2,
66
- regex: /[^ ]/
67
- };
68
- var TAB = {
69
- token: '\t',
70
- size: 1,
71
- regex: /[^\t]/
72
- };
73
- var getLineInfo = exports.getLineInfo = function getLineInfo(line) {
74
- var indentToken = line.startsWith('\t') ? TAB : SPACE;
75
- var indentLength = line.search(indentToken.regex);
76
- var indentText = line.substring(0, indentLength >= 0 ? indentLength : line.length);
77
- return {
78
- indentToken: indentToken,
79
- indentText: indentText
80
- };
81
- };
@@ -1,23 +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.isCursorBeforeClosingCharacter = exports.isClosingCharacter = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
- var _bracketHandling = require("./bracket-handling");
10
- var _quoteHandling = require("./quote-handling");
11
- 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; }
12
- 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; }
13
- var PAIRED_CHARACTER_MAP = _objectSpread(_objectSpread({}, _bracketHandling.BRACKET_MAP), _quoteHandling.QUOTE_MAP);
14
- var isCursorBeforeClosingCharacter = exports.isCursorBeforeClosingCharacter = function isCursorBeforeClosingCharacter(after) {
15
- return Object.keys(PAIRED_CHARACTER_MAP).some(function (leftCharacter) {
16
- return after.startsWith(PAIRED_CHARACTER_MAP[leftCharacter]);
17
- });
18
- };
19
- var isClosingCharacter = exports.isClosingCharacter = function isClosingCharacter(text) {
20
- return Object.keys(PAIRED_CHARACTER_MAP).some(function (leftCharacter) {
21
- return text === PAIRED_CHARACTER_MAP[leftCharacter];
22
- });
23
- };
@@ -1,40 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.shouldAutoCloseQuote = exports.getAutoClosingQuoteInfo = exports.QUOTE_MAP = void 0;
7
- var QUOTE_MAP = exports.QUOTE_MAP = {
8
- "'": "'",
9
- '"': '"',
10
- '`': '`'
11
- };
12
- var shouldAutoCloseQuote = exports.shouldAutoCloseQuote = function shouldAutoCloseQuote(before, after) {
13
- // when directly before a closing bracket
14
- if (/^[}\])]/.test(after)) {
15
- return true;
16
- }
17
-
18
- // exclusion: when directly before a non-whitespace character
19
- if (/^[^\s]/.test(after)) {
20
- return false;
21
- }
22
-
23
- // exclusion: when directly after a letter or quote
24
- if (/[A-Za-z0-9]$/.test(before) || /[\'\"\`]$/.test(before)) {
25
- return false;
26
- }
27
- return true;
28
- };
29
- var getAutoClosingQuoteInfo = exports.getAutoClosingQuoteInfo = function getAutoClosingQuoteInfo(before, after) {
30
- var left = Object.keys(QUOTE_MAP).find(function (item) {
31
- return before.endsWith(item);
32
- });
33
- var right = left ? QUOTE_MAP[left] : undefined;
34
- var hasTrailingMatchingQuote = right ? after.startsWith(right) : false;
35
- return {
36
- left: left,
37
- right: right,
38
- hasTrailingMatchingQuote: hasTrailingMatchingQuote
39
- };
40
- };
@@ -1,120 +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.default = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
- var _react = _interopRequireDefault(require("react"));
10
- var _adfSchema = require("@atlaskit/adf-schema");
11
- var _main = require("./pm-plugins/main");
12
- var _toolbar = require("./toolbar");
13
- var _keymaps = _interopRequireDefault(require("./pm-plugins/keymaps"));
14
- var _ideUx = _interopRequireDefault(require("./pm-plugins/ide-ux"));
15
- var _codeBlockCopySelectionPlugin = require("./pm-plugins/codeBlockCopySelectionPlugin");
16
- var _analytics = require("@atlaskit/editor-common/analytics");
17
- var _quickInsert = require("@atlaskit/editor-common/quick-insert");
18
- var _messages = require("@atlaskit/editor-common/messages");
19
- var _refreshBrowserSelection = _interopRequireDefault(require("./refresh-browser-selection"));
20
- var _actions = require("./actions");
21
- var _inputRule = require("./pm-plugins/input-rule");
22
- 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; }
23
- 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; }
24
- var codeBlockPlugin = function codeBlockPlugin(_ref) {
25
- var options = _ref.config,
26
- api = _ref.api;
27
- return {
28
- name: 'codeBlock',
29
- nodes: function nodes() {
30
- return [{
31
- name: 'codeBlock',
32
- node: _adfSchema.codeBlock
33
- }];
34
- },
35
- pmPlugins: function pmPlugins() {
36
- return [{
37
- name: 'codeBlock',
38
- plugin: function plugin(_ref2) {
39
- var _options$appearance;
40
- var getIntl = _ref2.getIntl;
41
- return (0, _main.createPlugin)(_objectSpread(_objectSpread({}, options), {}, {
42
- getIntl: getIntl,
43
- appearance: (_options$appearance = options === null || options === void 0 ? void 0 : options.appearance) !== null && _options$appearance !== void 0 ? _options$appearance : 'comment'
44
- }));
45
- }
46
- }, {
47
- name: 'codeBlockInputRule',
48
- plugin: function plugin(_ref3) {
49
- var _api$analytics;
50
- var schema = _ref3.schema;
51
- return (0, _inputRule.createCodeBlockInputRule)(schema, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
52
- }
53
- }, {
54
- name: 'codeBlockIDEKeyBindings',
55
- plugin: function plugin() {
56
- return (0, _ideUx.default)(api);
57
- }
58
- }, {
59
- name: 'codeBlockKeyMap',
60
- plugin: function plugin(_ref4) {
61
- var schema = _ref4.schema;
62
- return (0, _keymaps.default)(schema);
63
- }
64
- }, {
65
- name: 'codeBlockCopySelection',
66
- plugin: function plugin() {
67
- return (0, _codeBlockCopySelectionPlugin.codeBlockCopySelectionPlugin)();
68
- }
69
- }];
70
- },
71
- // Workaround for a firefox issue where dom selection is off sync
72
- // https://product-fabric.atlassian.net/browse/ED-12442
73
- onEditorViewStateUpdated: function onEditorViewStateUpdated(props) {
74
- (0, _refreshBrowserSelection.default)(props.originalTransaction, props.newEditorState);
75
- },
76
- actions: {
77
- /*
78
- * Function will insert code block at current selection if block is empty or below current selection and set focus on it.
79
- */
80
- insertCodeBlock: function insertCodeBlock(inputMethod) {
81
- var _api$analytics2;
82
- return (0, _actions.insertCodeBlockWithAnalytics)(inputMethod, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
83
- }
84
- },
85
- pluginsOptions: {
86
- quickInsert: function quickInsert(_ref5) {
87
- var formatMessage = _ref5.formatMessage;
88
- return [{
89
- id: 'codeblock',
90
- title: formatMessage(_messages.blockTypeMessages.codeblock),
91
- description: formatMessage(_messages.blockTypeMessages.codeblockDescription),
92
- keywords: ['code block'],
93
- priority: 700,
94
- keyshortcut: '```',
95
- icon: function icon() {
96
- return /*#__PURE__*/_react.default.createElement(_quickInsert.IconCode, null);
97
- },
98
- action: function action(_insert, state) {
99
- var _api$analytics3;
100
- var tr = (0, _actions.createInsertCodeBlockTransaction)({
101
- state: state
102
- });
103
- api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 || _api$analytics3.actions.attachAnalyticsEvent({
104
- action: _analytics.ACTION.INSERTED,
105
- actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
106
- actionSubjectId: _analytics.ACTION_SUBJECT_ID.CODE_BLOCK,
107
- attributes: {
108
- inputMethod: _analytics.INPUT_METHOD.QUICK_INSERT
109
- },
110
- eventType: _analytics.EVENT_TYPE.TRACK
111
- })(tr);
112
- return tr;
113
- }
114
- }];
115
- },
116
- floatingToolbar: (0, _toolbar.getToolbarConfig)(options === null || options === void 0 ? void 0 : options.allowCopyToClipboard, api)
117
- }
118
- };
119
- };
120
- var _default = exports.default = codeBlockPlugin;
@@ -1,62 +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.DEFAULT_LANGUAGES = void 0;
8
- exports.createLanguageList = createLanguageList;
9
- exports.filterSupportedLanguages = filterSupportedLanguages;
10
- exports.findMatchedLanguage = findMatchedLanguage;
11
- exports.getLanguageIdentifier = getLanguageIdentifier;
12
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
- var _constants = require("@atlaskit/code/constants");
14
- // We expect alias[0] to be used for the ADF attribute, see ED-2813
15
- var DEFAULT_LANGUAGES = exports.DEFAULT_LANGUAGES = [{
16
- name: '(None)',
17
- alias: ['none'],
18
- value: 'none'
19
- }].concat((0, _toConsumableArray2.default)(_constants.SUPPORTED_LANGUAGES));
20
- function findMatchedLanguage(supportedLanguages, language) {
21
- if (!language) {
22
- return undefined;
23
- }
24
- var matches = supportedLanguages.filter(function (supportedLanguage) {
25
- return supportedLanguage.alias.indexOf(language.toLowerCase()) !== -1;
26
- });
27
- if (matches.length > 0) {
28
- return matches[0];
29
- }
30
- return undefined;
31
- }
32
- function filterSupportedLanguages(supportedLanguages) {
33
- if (!supportedLanguages || !supportedLanguages.length) {
34
- return DEFAULT_LANGUAGES;
35
- }
36
- return DEFAULT_LANGUAGES.filter(function (language) {
37
- var i = language.alias.length;
38
- while (i--) {
39
- if (supportedLanguages.indexOf(language.alias[i]) > -1) {
40
- return true;
41
- }
42
- }
43
- return false;
44
- });
45
- }
46
- function getLanguageIdentifier(language) {
47
- return language.alias[0];
48
- }
49
- function createLanguageList(supportedLanguages) {
50
- return supportedLanguages.sort(function (left, right) {
51
- if (left.alias[0] === 'none') {
52
- return -1;
53
- }
54
- if (left.name.toLowerCase() > right.name.toLowerCase()) {
55
- return 1;
56
- }
57
- if (left.name.toLowerCase() < right.name.toLowerCase()) {
58
- return -1;
59
- }
60
- return 0;
61
- });
62
- }