@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,108 +0,0 @@
1
- import { defineMessages } from 'react-intl-next';
2
- import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
3
- import CopyIcon from '@atlaskit/icon/glyph/copy';
4
- import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
5
- import { removeCodeBlock, changeLanguage, copyContentToClipboard, resetCopiedState } from './actions';
6
- import commonMessages, { codeBlockButtonMessages } from '@atlaskit/editor-common/messages';
7
- import { provideVisualFeedbackForCopyButton, removeVisualFeedbackForCopyButton } from './pm-plugins/codeBlockCopySelectionPlugin';
8
- import { pluginKey } from './plugin-key';
9
- import { createLanguageList, getLanguageIdentifier, DEFAULT_LANGUAGES } from './language-list';
10
- export const messages = defineMessages({
11
- selectLanguage: {
12
- id: 'fabric.editor.selectLanguage',
13
- defaultMessage: 'Select language',
14
- description: 'Code blocks display software code. A prompt to select the software language the code is written in.'
15
- }
16
- });
17
- const languageList = createLanguageList(DEFAULT_LANGUAGES);
18
- export const getToolbarConfig = (allowCopyToClipboard = false, api) => (state, {
19
- formatMessage
20
- }) => {
21
- var _api$decorations$acti, _api$analytics, _codeBlockState$pos, _node$attrs;
22
- const {
23
- hoverDecoration
24
- } = (_api$decorations$acti = api === null || api === void 0 ? void 0 : api.decorations.actions) !== null && _api$decorations$acti !== void 0 ? _api$decorations$acti : {};
25
- const editorAnalyticsAPI = api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
26
- const codeBlockState = pluginKey.getState(state);
27
- const pos = (_codeBlockState$pos = codeBlockState === null || codeBlockState === void 0 ? void 0 : codeBlockState.pos) !== null && _codeBlockState$pos !== void 0 ? _codeBlockState$pos : null;
28
- if (!codeBlockState || pos === null) {
29
- return;
30
- }
31
- const node = state.doc.nodeAt(pos);
32
- const nodeType = state.schema.nodes.codeBlock;
33
- if ((node === null || node === void 0 ? void 0 : node.type) !== nodeType) {
34
- return;
35
- }
36
- const language = node === null || node === void 0 ? void 0 : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.language;
37
- const options = languageList.map(lang => ({
38
- label: lang.name,
39
- value: getLanguageIdentifier(lang),
40
- alias: lang.alias
41
- }));
42
-
43
- // If language is not undefined search for it in the value and then search in the aliases
44
- const defaultValue = language ? options.find(option => option.value === language) || options.find(option => option.alias.includes(language)) : null;
45
- const languageSelect = {
46
- id: 'editor.codeBlock.languageOptions',
47
- type: 'select',
48
- selectType: 'list',
49
- onChange: option => changeLanguage(editorAnalyticsAPI)(option.value),
50
- defaultValue,
51
- placeholder: formatMessage(messages.selectLanguage),
52
- options,
53
- filterOption: languageListFilter
54
- };
55
- const separator = {
56
- type: 'separator'
57
- };
58
- const copyToClipboardItems = !allowCopyToClipboard ? [] : [{
59
- id: 'editor.codeBlock.copy',
60
- type: 'button',
61
- appearance: 'subtle',
62
- icon: CopyIcon,
63
- // note: copyContentToClipboard contains logic that also removes the
64
- // visual feedback for the copy button
65
- onClick: copyContentToClipboard,
66
- title: formatMessage(codeBlockState.contentCopied ? codeBlockButtonMessages.copiedCodeToClipboard : codeBlockButtonMessages.copyCodeToClipboard),
67
- onMouseEnter: provideVisualFeedbackForCopyButton,
68
- // note: resetCopiedState contains logic that also removes the
69
- // visual feedback for the copy button
70
- onMouseLeave: resetCopiedState,
71
- onFocus: provideVisualFeedbackForCopyButton,
72
- onBlur: removeVisualFeedbackForCopyButton,
73
- hideTooltipOnClick: false,
74
- disabled: codeBlockState.isNodeSelected,
75
- tabIndex: null
76
- }, separator];
77
- const deleteButton = {
78
- id: 'editor.codeBlock.delete',
79
- type: 'button',
80
- appearance: 'danger',
81
- icon: RemoveIcon,
82
- onMouseEnter: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(nodeType, true),
83
- onMouseLeave: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(nodeType, false),
84
- onFocus: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(nodeType, true),
85
- onBlur: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(nodeType, false),
86
- onClick: removeCodeBlock,
87
- title: formatMessage(commonMessages.remove),
88
- tabIndex: null
89
- };
90
- return {
91
- title: 'CodeBlock floating controls',
92
- getDomRef: view => findDomRefAtPos(pos, view.domAtPos.bind(view)),
93
- nodeType,
94
- items: [languageSelect, separator, ...copyToClipboardItems, deleteButton],
95
- scrollable: true
96
- };
97
- };
98
-
99
- /**
100
- * Filters language list based on both name and alias properties.
101
- */
102
- export const languageListFilter = (option, rawInput) => {
103
- const {
104
- data
105
- } = option;
106
- const searchString = rawInput.toLowerCase();
107
- return data.label.toLowerCase().includes(searchString) || data.alias.some(alias => alias.toLowerCase() === searchString);
108
- };
@@ -1,79 +0,0 @@
1
- import { TextSelection } from '@atlaskit/editor-prosemirror/state';
2
- import { Fragment } from '@atlaskit/editor-prosemirror/model';
3
- import { GapCursorSelection } from '@atlaskit/editor-common/selection';
4
- import { timestampToString, mapSlice } from '@atlaskit/editor-common/utils';
5
- export function transformToCodeBlockAction(state, start, attrs) {
6
- const startOfCodeBlockText = state.selection.$from;
7
- const endPosition = state.selection.empty && !(state.selection instanceof GapCursorSelection) ? startOfCodeBlockText.end() : state.selection.$to.pos;
8
- const startLinePosition = startOfCodeBlockText.start();
9
- //when cmd+A is used to select the content. start position should be 0.
10
- const parentStartPosition = startOfCodeBlockText.depth === 0 ? 0 : startOfCodeBlockText.before();
11
- const contentSlice = state.doc.slice(startOfCodeBlockText.pos, endPosition);
12
- const codeBlockSlice = mapSlice(contentSlice, (node, parent, index) => {
13
- if (node.type === state.schema.nodes.hardBreak) {
14
- return state.schema.text('\n');
15
- }
16
- if (node.isText) {
17
- return node.mark([]);
18
- }
19
- if (node.isInline) {
20
- // Convert dates
21
- if (node.attrs.timestamp) {
22
- return state.schema.text(timestampToString(node.attrs.timestamp, null));
23
- }
24
- // Convert links
25
- if (node.attrs.url) {
26
- return state.schema.text(node.attrs.url);
27
- }
28
- return node.attrs.text ? state.schema.text(node.attrs.text) : null;
29
- }
30
-
31
- // if the current node is the last child of the Slice exit early to prevent
32
- // adding additional line breaks
33
- if (contentSlice.content.childCount - 1 === index) {
34
- return node.content;
35
- }
36
-
37
- //useful to decide whether to append line breaks when the content has list items.
38
- const isParentLastChild = parent && contentSlice.content.childCount - 1 === index;
39
-
40
- // add line breaks at the end of each paragraph to mimic layout of selected content
41
- // do not add line breaks when the 'paragraph' parent is last child.
42
- if (node.content.childCount && node.type === state.schema.nodes.paragraph && !isParentLastChild) {
43
- return node.content.append(Fragment.from(state.schema.text('\n\n')));
44
- }
45
- return node.content.childCount ? node.content : null;
46
- });
47
- const tr = state.tr;
48
-
49
- // Replace current block node
50
- const startMapped = startLinePosition === start ? parentStartPosition : start;
51
- const codeBlock = state.schema.nodes.codeBlock;
52
- const codeBlockNode = codeBlock.createChecked(attrs, codeBlockSlice.content);
53
- tr.replaceWith(startMapped, Math.min(endPosition, tr.doc.content.size), codeBlockNode);
54
-
55
- // Reposition cursor when inserting into layouts or table headers
56
- const mapped = tr.doc.resolve(tr.mapping.map(startMapped) + 1);
57
- const selection = TextSelection.findFrom(mapped, state.selection instanceof GapCursorSelection ? -1 : 1, true);
58
- if (selection) {
59
- return tr.setSelection(selection);
60
- }
61
- return tr.setSelection(TextSelection.create(tr.doc, Math.min(start + startOfCodeBlockText.node().nodeSize - 1, tr.doc.content.size)));
62
- }
63
- export function isConvertableToCodeBlock(state) {
64
- // Before a document is loaded, there is no selection.
65
- if (!state.selection) {
66
- return false;
67
- }
68
- const {
69
- $from
70
- } = state.selection;
71
- const node = $from.parent;
72
- if (!node.isTextblock || node.type === state.schema.nodes.codeBlock) {
73
- return false;
74
- }
75
- const parentDepth = $from.depth - 1;
76
- const parentNode = $from.node(parentDepth);
77
- const index = $from.index(parentDepth);
78
- return parentNode.canReplaceWith(index, index + 1, state.schema.nodes.codeBlock);
79
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,9 +0,0 @@
1
- import { CodeBlockSharedCssClassName } from '@atlaskit/editor-common/styles';
2
- export const codeBlockClassNames = {
3
- container: CodeBlockSharedCssClassName.CODEBLOCK_CONTAINER,
4
- start: CodeBlockSharedCssClassName.CODEBLOCK_START,
5
- end: CodeBlockSharedCssClassName.CODEBLOCK_END,
6
- contentWrapper: CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_WRAPPER,
7
- gutter: CodeBlockSharedCssClassName.CODEBLOCK_LINE_NUMBER_GUTTER,
8
- content: CodeBlockSharedCssClassName.CODEBLOCK_CONTENT
9
- };
@@ -1,4 +0,0 @@
1
- export { findCodeBlock, transformSliceToJoinAdjacentCodeBlocks, transformSingleLineCodeBlockToCodeMark } from '@atlaskit/editor-common/transforms';
2
- export function getCursor(selection) {
3
- return selection.$cursor || undefined;
4
- }
@@ -1,191 +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 var removeCodeBlock = function removeCodeBlock(state, dispatch) {
12
- var nodes = state.schema.nodes,
13
- tr = state.tr;
14
- if (dispatch) {
15
- var removeTr = tr;
16
- if (findSelectedNodeOfType(nodes.codeBlock)(tr.selection)) {
17
- removeTr = removeSelectedNode(tr);
18
- } else {
19
- removeTr = removeParentNodeOfType(nodes.codeBlock)(tr);
20
- }
21
- dispatch(removeTr);
22
- }
23
- return true;
24
- };
25
- export var changeLanguage = function changeLanguage(editorAnalyticsAPI) {
26
- return function (language) {
27
- return function (state, dispatch) {
28
- var _pluginKey$getState;
29
- var codeBlock = state.schema.nodes.codeBlock;
30
- var pos = (_pluginKey$getState = pluginKey.getState(state)) === null || _pluginKey$getState === void 0 ? void 0 : _pluginKey$getState.pos;
31
- if (typeof pos !== 'number') {
32
- return false;
33
- }
34
- var tr = state.tr.setNodeMarkup(pos, codeBlock, {
35
- language: language
36
- }).setMeta('scrollIntoView', false);
37
- var selection = isNodeSelection(state.selection) ? NodeSelection.create(tr.doc, pos) : tr.selection;
38
- var result = tr.setSelection(selection);
39
- if (dispatch) {
40
- editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
41
- action: ACTION.LANGUAGE_SELECTED,
42
- actionSubject: ACTION_SUBJECT.CODE_BLOCK,
43
- attributes: {
44
- language: language
45
- },
46
- eventType: EVENT_TYPE.TRACK
47
- })(result);
48
- dispatch(result);
49
- }
50
- return true;
51
- };
52
- };
53
- };
54
- export var copyContentToClipboard = function copyContentToClipboard(state, dispatch) {
55
- var nodes = state.schema.nodes,
56
- tr = state.tr;
57
- var codeBlock = findParentNodeOfType(nodes.codeBlock)(tr.selection);
58
- var textContent = codeBlock && codeBlock.node.textContent;
59
- if (textContent) {
60
- copyToClipboard(textContent);
61
- var copyToClipboardTr = tr;
62
- copyToClipboardTr.setMeta(pluginKey, {
63
- type: ACTIONS.SET_COPIED_TO_CLIPBOARD,
64
- data: true
65
- });
66
- copyToClipboardTr.setMeta(copySelectionPluginKey, 'remove-selection');
67
- if (dispatch) {
68
- dispatch(copyToClipboardTr);
69
- }
70
- }
71
- return true;
72
- };
73
- export var resetCopiedState = function resetCopiedState(state, dispatch) {
74
- var tr = state.tr;
75
- var codeBlockState = pluginKey.getState(state);
76
- var resetCopiedStateTr = tr;
77
- if (codeBlockState && codeBlockState.contentCopied) {
78
- resetCopiedStateTr.setMeta(pluginKey, {
79
- type: ACTIONS.SET_COPIED_TO_CLIPBOARD,
80
- data: false
81
- });
82
- resetCopiedStateTr.setMeta(copySelectionPluginKey, 'remove-selection');
83
- if (dispatch) {
84
- dispatch(resetCopiedStateTr);
85
- }
86
- } else {
87
- var clearSelectionStateTransaction = state.tr;
88
- clearSelectionStateTransaction.setMeta(copySelectionPluginKey, 'remove-selection');
89
- // note: dispatch should always be defined when called from the
90
- // floating toolbar. Howver the Command type which floating toolbar uses
91
- // (and resetCopiedState) uses suggests it's optional.
92
- if (dispatch) {
93
- dispatch(clearSelectionStateTransaction);
94
- }
95
- }
96
- return true;
97
- };
98
- export var ignoreFollowingMutations = function ignoreFollowingMutations(state, dispatch) {
99
- var tr = state.tr;
100
- var ignoreFollowingMutationsTr = tr;
101
- ignoreFollowingMutationsTr.setMeta(pluginKey, {
102
- type: ACTIONS.SET_SHOULD_IGNORE_FOLLOWING_MUTATIONS,
103
- data: true
104
- });
105
- if (dispatch) {
106
- dispatch(ignoreFollowingMutationsTr);
107
- }
108
- return true;
109
- };
110
- export var resetShouldIgnoreFollowingMutations = function resetShouldIgnoreFollowingMutations(state, dispatch) {
111
- var tr = state.tr;
112
- var ignoreFollowingMutationsTr = tr;
113
- ignoreFollowingMutationsTr.setMeta(pluginKey, {
114
- type: ACTIONS.SET_SHOULD_IGNORE_FOLLOWING_MUTATIONS,
115
- data: false
116
- });
117
- if (dispatch) {
118
- dispatch(ignoreFollowingMutationsTr);
119
- }
120
- return true;
121
- };
122
-
123
- /**
124
- * This function creates a new transaction that inserts a code block,
125
- * if there is text selected it will wrap the current selection if not it will
126
- * append the codeblock to the end of the document.
127
- */
128
- export function createInsertCodeBlockTransaction(_ref) {
129
- var _state$selection$$fro;
130
- var state = _ref.state;
131
- var tr = state.tr;
132
- var from = state.selection.from;
133
- var codeBlock = state.schema.nodes.codeBlock;
134
- var grandParentNodeType = (_state$selection$$fro = state.selection.$from.node(-1)) === null || _state$selection$$fro === void 0 ? void 0 : _state$selection$$fro.type;
135
- var parentNodeType = state.selection.$from.parent.type;
136
-
137
- /** We always want to append a codeBlock unless we're inserting into a paragraph
138
- * AND it's a valid child of the grandparent node.
139
- * Insert the current selection as codeBlock content unless it contains nodes other
140
- * than paragraphs and inline.
141
- */
142
- var canInsertCodeBlock = shouldSplitSelectedNodeOnNodeInsertion({
143
- parentNodeType: parentNodeType,
144
- grandParentNodeType: grandParentNodeType,
145
- content: codeBlock.createAndFill()
146
- }) && contentAllowedInCodeBlock(state);
147
- if (canInsertCodeBlock) {
148
- tr = transformToCodeBlockAction(state, from);
149
- } else {
150
- safeInsert(codeBlock.createAndFill())(tr).scrollIntoView();
151
- }
152
- return tr;
153
- }
154
-
155
- /**
156
- * Check if the current selection contains any nodes that are not permitted
157
- * as codeBlock child nodes. Note that this allows paragraphs and inline nodes
158
- * as we extract their text content.
159
- */
160
- function contentAllowedInCodeBlock(state) {
161
- var _state$selection = state.selection,
162
- $from = _state$selection.$from,
163
- $to = _state$selection.$to;
164
- var isAllowedChild = true;
165
- state.doc.nodesBetween($from.pos, $to.pos, function (node) {
166
- if (!isAllowedChild) {
167
- return false;
168
- }
169
- 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;
170
- });
171
- return isAllowedChild;
172
- }
173
- export function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI) {
174
- return withAnalytics(analyticsAPI, {
175
- action: ACTION.INSERTED,
176
- actionSubject: ACTION_SUBJECT.DOCUMENT,
177
- actionSubjectId: ACTION_SUBJECT_ID.CODE_BLOCK,
178
- attributes: {
179
- inputMethod: inputMethod
180
- },
181
- eventType: EVENT_TYPE.TRACK
182
- })(function (state, dispatch) {
183
- var tr = createInsertCodeBlockTransaction({
184
- state: state
185
- });
186
- if (dispatch) {
187
- dispatch(tr);
188
- }
189
- return true;
190
- });
191
- }
@@ -1,29 +0,0 @@
1
- export var BRACKET_MAP = {
2
- '{': '}',
3
- '[': ']',
4
- '(': ')'
5
- };
6
- export var shouldAutoCloseBracket = function 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 var getAutoClosingBracketInfo = function getAutoClosingBracketInfo(before, after) {
19
- var left = Object.keys(BRACKET_MAP).find(function (item) {
20
- return before.endsWith(item);
21
- });
22
- var right = left ? BRACKET_MAP[left] : undefined;
23
- var hasTrailingMatchingBracket = right ? after.startsWith(right) : false;
24
- return {
25
- left: left,
26
- right: right,
27
- hasTrailingMatchingBracket: hasTrailingMatchingBracket
28
- };
29
- };
@@ -1,106 +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 var indent = function indent(editorAnalyticsAPI) {
16
- return function (state, dispatch) {
17
- var _getLinesFromSelectio = getLinesFromSelection(state),
18
- text = _getLinesFromSelectio.text,
19
- start = _getLinesFromSelectio.start;
20
- var tr = state.tr,
21
- selection = state.selection;
22
- forEachLine(text, function (line, offset) {
23
- var _getLineInfo = getLineInfo(line),
24
- indentText = _getLineInfo.indentText,
25
- indentToken = _getLineInfo.indentToken;
26
- var indentLevel = getIndentLevel(indentText, indentToken.size);
27
- var indentToAdd = indentToken.token.repeat(indentToken.size - indentText.length % indentToken.size || indentToken.size);
28
- tr.insertText(indentToAdd, tr.mapping.map(start + offset, -1));
29
- editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
30
- action: ACTION.FORMATTED,
31
- actionSubject: ACTION_SUBJECT.TEXT,
32
- actionSubjectId: ACTION_SUBJECT_ID.FORMAT_INDENT,
33
- eventType: EVENT_TYPE.TRACK,
34
- attributes: {
35
- inputMethod: INPUT_METHOD.KEYBOARD,
36
- previousIndentationLevel: indentLevel,
37
- newIndentLevel: indentLevel + 1,
38
- direction: INDENT_DIRECTION.INDENT,
39
- indentType: INDENT_TYPE.CODE_BLOCK
40
- }
41
- })(tr);
42
- if (!selection.empty) {
43
- tr.setSelection(TextSelection.create(tr.doc, tr.mapping.map(selection.from, -1), tr.selection.to));
44
- }
45
- });
46
- if (dispatch) {
47
- dispatch(tr);
48
- }
49
- return true;
50
- };
51
- };
52
- export var outdent = function outdent(editorAnalyticsAPI) {
53
- return function (state, dispatch) {
54
- var _getLinesFromSelectio2 = getLinesFromSelection(state),
55
- text = _getLinesFromSelectio2.text,
56
- start = _getLinesFromSelectio2.start;
57
- var tr = state.tr;
58
- forEachLine(text, function (line, offset) {
59
- var _getLineInfo2 = getLineInfo(line),
60
- indentText = _getLineInfo2.indentText,
61
- indentToken = _getLineInfo2.indentToken;
62
- if (indentText) {
63
- var indentLevel = getIndentLevel(indentText, indentToken.size);
64
- var unindentLength = indentText.length % indentToken.size || indentToken.size;
65
- tr.delete(tr.mapping.map(start + offset), tr.mapping.map(start + offset + unindentLength));
66
- editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
67
- action: ACTION.FORMATTED,
68
- actionSubject: ACTION_SUBJECT.TEXT,
69
- actionSubjectId: ACTION_SUBJECT_ID.FORMAT_INDENT,
70
- eventType: EVENT_TYPE.TRACK,
71
- attributes: {
72
- inputMethod: INPUT_METHOD.KEYBOARD,
73
- previousIndentationLevel: indentLevel,
74
- newIndentLevel: indentLevel - 1,
75
- direction: INDENT_DIRECTION.OUTDENT,
76
- indentType: INDENT_TYPE.CODE_BLOCK
77
- }
78
- })(tr);
79
- }
80
- });
81
- if (dispatch) {
82
- dispatch(tr);
83
- }
84
- return true;
85
- };
86
- };
87
- export function insertIndent(state, dispatch) {
88
- var _getStartOfCurrentLin = getStartOfCurrentLine(state),
89
- textAtStartOfLine = _getStartOfCurrentLin.text;
90
- var _getLineInfo3 = getLineInfo(textAtStartOfLine),
91
- indentToken = _getLineInfo3.indentToken;
92
- var indentToAdd = indentToken.token.repeat(indentToken.size - textAtStartOfLine.length % indentToken.size || indentToken.size);
93
- dispatch(state.tr.insertText(indentToAdd));
94
- return true;
95
- }
96
- export function insertNewlineWithIndent(state, dispatch) {
97
- var _getStartOfCurrentLin2 = getStartOfCurrentLine(state),
98
- textAtStartOfLine = _getStartOfCurrentLin2.text;
99
- var _getLineInfo4 = getLineInfo(textAtStartOfLine),
100
- indentText = _getLineInfo4.indentText;
101
- if (indentText && dispatch) {
102
- dispatch(state.tr.insertText('\n' + indentText));
103
- return true;
104
- }
105
- return false;
106
- }
@@ -1,73 +0,0 @@
1
- import { getCursor } from '../utils';
2
- export var isSelectionEntirelyInsideCodeBlock = function isSelectionEntirelyInsideCodeBlock(state) {
3
- return state.selection.$from.sameParent(state.selection.$to) && state.selection.$from.parent.type === state.schema.nodes.codeBlock;
4
- };
5
- export var isCursorInsideCodeBlock = function isCursorInsideCodeBlock(state) {
6
- return !!getCursor(state.selection) && isSelectionEntirelyInsideCodeBlock(state);
7
- };
8
- export var getStartOfCurrentLine = function getStartOfCurrentLine(state) {
9
- var $from = state.selection.$from;
10
- if ($from.nodeBefore && $from.nodeBefore.isText) {
11
- var prevNewLineIndex = $from.nodeBefore.text.lastIndexOf('\n');
12
- return {
13
- text: $from.nodeBefore.text.substring(prevNewLineIndex + 1),
14
- pos: $from.start() + prevNewLineIndex + 1
15
- };
16
- }
17
- return {
18
- text: '',
19
- pos: $from.pos
20
- };
21
- };
22
- export var getEndOfCurrentLine = function getEndOfCurrentLine(state) {
23
- var $to = state.selection.$to;
24
- if ($to.nodeAfter && $to.nodeAfter.isText) {
25
- var 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
- var _getStartOfCurrentLin = getStartOfCurrentLine(state),
38
- start = _getStartOfCurrentLin.pos;
39
- var _getEndOfCurrentLine = getEndOfCurrentLine(state),
40
- end = _getEndOfCurrentLine.pos;
41
- var text = state.doc.textBetween(start, end);
42
- return {
43
- text: text,
44
- start: start,
45
- end: end
46
- };
47
- }
48
- export var forEachLine = function forEachLine(text, callback) {
49
- var offset = 0;
50
- text.split('\n').forEach(function (line) {
51
- callback(line, offset);
52
- offset += line.length + 1;
53
- });
54
- };
55
- var SPACE = {
56
- token: ' ',
57
- size: 2,
58
- regex: /[^ ]/
59
- };
60
- var TAB = {
61
- token: '\t',
62
- size: 1,
63
- regex: /[^\t]/
64
- };
65
- export var getLineInfo = function getLineInfo(line) {
66
- var indentToken = line.startsWith('\t') ? TAB : SPACE;
67
- var indentLength = line.search(indentToken.regex);
68
- var indentText = line.substring(0, indentLength >= 0 ? indentLength : line.length);
69
- return {
70
- indentToken: indentToken,
71
- indentText: indentText
72
- };
73
- };
@@ -1,16 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
- import { BRACKET_MAP } from './bracket-handling';
5
- import { QUOTE_MAP } from './quote-handling';
6
- var PAIRED_CHARACTER_MAP = _objectSpread(_objectSpread({}, BRACKET_MAP), QUOTE_MAP);
7
- export var isCursorBeforeClosingCharacter = function isCursorBeforeClosingCharacter(after) {
8
- return Object.keys(PAIRED_CHARACTER_MAP).some(function (leftCharacter) {
9
- return after.startsWith(PAIRED_CHARACTER_MAP[leftCharacter]);
10
- });
11
- };
12
- export var isClosingCharacter = function isClosingCharacter(text) {
13
- return Object.keys(PAIRED_CHARACTER_MAP).some(function (leftCharacter) {
14
- return text === PAIRED_CHARACTER_MAP[leftCharacter];
15
- });
16
- };
@@ -1,34 +0,0 @@
1
- export var QUOTE_MAP = {
2
- "'": "'",
3
- '"': '"',
4
- '`': '`'
5
- };
6
- export var shouldAutoCloseQuote = function 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 var getAutoClosingQuoteInfo = function getAutoClosingQuoteInfo(before, after) {
24
- var left = Object.keys(QUOTE_MAP).find(function (item) {
25
- return before.endsWith(item);
26
- });
27
- var right = left ? QUOTE_MAP[left] : undefined;
28
- var hasTrailingMatchingQuote = right ? after.startsWith(right) : false;
29
- return {
30
- left: left,
31
- right: right,
32
- hasTrailingMatchingQuote: hasTrailingMatchingQuote
33
- };
34
- };