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