@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,107 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
5
- import { browser } from '@atlaskit/editor-common/utils';
6
- import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
7
- import { codeBlockNodeView } from '../nodeviews/code-block';
8
- import { createSelectionClickHandler } from '@atlaskit/editor-common/selection';
9
- import { pluginKey } from '../plugin-key';
10
- import { ACTIONS } from './actions';
11
- import { ignoreFollowingMutations, resetShouldIgnoreFollowingMutations } from '../actions';
12
- import { findCodeBlock } from '../utils';
13
- import { codeBlockClassNames } from '../ui/class-names';
14
- export var createPlugin = function createPlugin(_ref) {
15
- var _ref$useLongPressSele = _ref.useLongPressSelection,
16
- useLongPressSelection = _ref$useLongPressSele === void 0 ? false : _ref$useLongPressSele,
17
- getIntl = _ref.getIntl,
18
- appearance = _ref.appearance,
19
- _ref$allowComposition = _ref.allowCompositionInputOverride,
20
- allowCompositionInputOverride = _ref$allowComposition === void 0 ? false : _ref$allowComposition;
21
- var handleDOMEvents = {};
22
-
23
- // ME-1599: Composition on mobile was causing the DOM observer to mutate the code block
24
- // incorrecly and lose content when pressing enter in the middle of a code block line.
25
- if (allowCompositionInputOverride) {
26
- handleDOMEvents.beforeinput = function (view, event) {
27
- var keyEvent = event;
28
- var eventInputType = keyEvent.inputType;
29
- var eventText = keyEvent.data;
30
- if (browser.ios && event.composed &&
31
- // insertParagraph will be the input type when the enter key is pressed.
32
- eventInputType === 'insertParagraph' && findCodeBlock(view.state, view.state.selection)) {
33
- event.preventDefault();
34
- return true;
35
- } else if (browser.android && event.composed && eventInputType === 'insertCompositionText' && eventText[(eventText === null || eventText === void 0 ? void 0 : eventText.length) - 1] === '\n' && findCodeBlock(view.state, view.state.selection)) {
36
- var resultingText = event.target.outerText + '\n';
37
- if (resultingText.endsWith(eventText)) {
38
- // End of paragraph
39
- setTimeout(function () {
40
- view.someProp('handleKeyDown', function (f) {
41
- return f(view, new KeyboardEvent('keydown', {
42
- bubbles: true,
43
- cancelable: true,
44
- key: 'Enter',
45
- code: 'Enter'
46
- }));
47
- });
48
- }, 0);
49
- } else {
50
- // Middle of paragraph, end of line
51
- ignoreFollowingMutations(view.state, view.dispatch);
52
- }
53
- return true;
54
- }
55
- if (browser.android) {
56
- resetShouldIgnoreFollowingMutations(view.state, view.dispatch);
57
- }
58
- return false;
59
- };
60
- }
61
- return new SafePlugin({
62
- state: {
63
- init: function init(_, state) {
64
- var node = findCodeBlock(state, state.selection);
65
- return {
66
- pos: node ? node.pos : null,
67
- contentCopied: false,
68
- isNodeSelected: false,
69
- shouldIgnoreFollowingMutations: false
70
- };
71
- },
72
- apply: function apply(tr, pluginState, _oldState, newState) {
73
- if (tr.docChanged || tr.selectionSet) {
74
- var node = findCodeBlock(newState, tr.selection);
75
- var newPluginState = _objectSpread(_objectSpread({}, pluginState), {}, {
76
- pos: node ? node.pos : null,
77
- isNodeSelected: tr.selection instanceof NodeSelection
78
- });
79
- return newPluginState;
80
- }
81
- var meta = tr.getMeta(pluginKey);
82
- if ((meta === null || meta === void 0 ? void 0 : meta.type) === ACTIONS.SET_COPIED_TO_CLIPBOARD) {
83
- return _objectSpread(_objectSpread({}, pluginState), {}, {
84
- contentCopied: meta.data
85
- });
86
- } else if ((meta === null || meta === void 0 ? void 0 : meta.type) === ACTIONS.SET_SHOULD_IGNORE_FOLLOWING_MUTATIONS) {
87
- return _objectSpread(_objectSpread({}, pluginState), {}, {
88
- shouldIgnoreFollowingMutations: meta.data
89
- });
90
- }
91
- return pluginState;
92
- }
93
- },
94
- key: pluginKey,
95
- props: {
96
- nodeViews: {
97
- codeBlock: codeBlockNodeView
98
- },
99
- handleClickOn: createSelectionClickHandler(['codeBlock'], function (target) {
100
- return !!(target.closest(".".concat(codeBlockClassNames.gutter)) || target.classList.contains(codeBlockClassNames.content));
101
- }, {
102
- useLongPressSelection: useLongPressSelection
103
- }),
104
- handleDOMEvents: handleDOMEvents
105
- }
106
- });
107
- };
@@ -1,25 +0,0 @@
1
- import { browser } from '@atlaskit/editor-common/utils';
2
- import { pluginKey } from './plugin-key';
3
-
4
- // Workaround for a firefox issue where dom selection is off sync
5
- // https://product-fabric.atlassian.net/browse/ED-12442
6
- var refreshBrowserSelection = function refreshBrowserSelection() {
7
- var domSelection = window.getSelection();
8
- if (domSelection) {
9
- var domRange = domSelection && domSelection.rangeCount === 1 && domSelection.getRangeAt(0).cloneRange();
10
- if (domRange) {
11
- domSelection.removeAllRanges();
12
- domSelection.addRange(domRange);
13
- }
14
- }
15
- };
16
- var refreshBrowserSelectionOnChange = function refreshBrowserSelectionOnChange(transaction, editorState) {
17
- var _pluginKey$getState;
18
- if (browser.gecko && transaction.docChanged &&
19
- // codeblockState.pos should be set if current selection is in a codeblock.
20
- typeof ((_pluginKey$getState = pluginKey.getState(editorState)) === null || _pluginKey$getState === void 0 ? void 0 : _pluginKey$getState.pos) === 'number') {
21
- refreshBrowserSelection();
22
- }
23
- };
24
- export default refreshBrowserSelectionOnChange;
25
- export { refreshBrowserSelection };
@@ -1,121 +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 var 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
- var languageList = createLanguageList(DEFAULT_LANGUAGES);
18
- export var getToolbarConfig = function getToolbarConfig() {
19
- var allowCopyToClipboard = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
20
- var api = arguments.length > 1 ? arguments[1] : undefined;
21
- return function (state, _ref) {
22
- var _api$decorations$acti, _api$analytics, _codeBlockState$pos, _node$attrs;
23
- var formatMessage = _ref.formatMessage;
24
- var _ref2 = (_api$decorations$acti = api === null || api === void 0 ? void 0 : api.decorations.actions) !== null && _api$decorations$acti !== void 0 ? _api$decorations$acti : {},
25
- hoverDecoration = _ref2.hoverDecoration;
26
- var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
27
- var codeBlockState = pluginKey.getState(state);
28
- var pos = (_codeBlockState$pos = codeBlockState === null || codeBlockState === void 0 ? void 0 : codeBlockState.pos) !== null && _codeBlockState$pos !== void 0 ? _codeBlockState$pos : null;
29
- if (!codeBlockState || pos === null) {
30
- return;
31
- }
32
- var node = state.doc.nodeAt(pos);
33
- var nodeType = state.schema.nodes.codeBlock;
34
- if ((node === null || node === void 0 ? void 0 : node.type) !== nodeType) {
35
- return;
36
- }
37
- var language = node === null || node === void 0 || (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.language;
38
- var options = languageList.map(function (lang) {
39
- return {
40
- label: lang.name,
41
- value: getLanguageIdentifier(lang),
42
- alias: lang.alias
43
- };
44
- });
45
-
46
- // If language is not undefined search for it in the value and then search in the aliases
47
- var defaultValue = language ? options.find(function (option) {
48
- return option.value === language;
49
- }) || options.find(function (option) {
50
- return option.alias.includes(language);
51
- }) : null;
52
- var languageSelect = {
53
- id: 'editor.codeBlock.languageOptions',
54
- type: 'select',
55
- selectType: 'list',
56
- onChange: function onChange(option) {
57
- return changeLanguage(editorAnalyticsAPI)(option.value);
58
- },
59
- defaultValue: defaultValue,
60
- placeholder: formatMessage(messages.selectLanguage),
61
- options: options,
62
- filterOption: languageListFilter
63
- };
64
- var separator = {
65
- type: 'separator'
66
- };
67
- var copyToClipboardItems = !allowCopyToClipboard ? [] : [{
68
- id: 'editor.codeBlock.copy',
69
- type: 'button',
70
- appearance: 'subtle',
71
- icon: CopyIcon,
72
- // note: copyContentToClipboard contains logic that also removes the
73
- // visual feedback for the copy button
74
- onClick: copyContentToClipboard,
75
- title: formatMessage(codeBlockState.contentCopied ? codeBlockButtonMessages.copiedCodeToClipboard : codeBlockButtonMessages.copyCodeToClipboard),
76
- onMouseEnter: provideVisualFeedbackForCopyButton,
77
- // note: resetCopiedState contains logic that also removes the
78
- // visual feedback for the copy button
79
- onMouseLeave: resetCopiedState,
80
- onFocus: provideVisualFeedbackForCopyButton,
81
- onBlur: removeVisualFeedbackForCopyButton,
82
- hideTooltipOnClick: false,
83
- disabled: codeBlockState.isNodeSelected,
84
- tabIndex: null
85
- }, separator];
86
- var deleteButton = {
87
- id: 'editor.codeBlock.delete',
88
- type: 'button',
89
- appearance: 'danger',
90
- icon: RemoveIcon,
91
- onMouseEnter: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(nodeType, true),
92
- onMouseLeave: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(nodeType, false),
93
- onFocus: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(nodeType, true),
94
- onBlur: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(nodeType, false),
95
- onClick: removeCodeBlock,
96
- title: formatMessage(commonMessages.remove),
97
- tabIndex: null
98
- };
99
- return {
100
- title: 'CodeBlock floating controls',
101
- getDomRef: function getDomRef(view) {
102
- return findDomRefAtPos(pos, view.domAtPos.bind(view));
103
- },
104
- nodeType: nodeType,
105
- items: [languageSelect, separator].concat(copyToClipboardItems, [deleteButton]),
106
- scrollable: true
107
- };
108
- };
109
- };
110
-
111
- /**
112
- * Filters language list based on both name and alias properties.
113
- */
114
- export var languageListFilter = function languageListFilter(option, rawInput) {
115
- var _ref3 = option,
116
- data = _ref3.data;
117
- var searchString = rawInput.toLowerCase();
118
- return data.label.toLowerCase().includes(searchString) || data.alias.some(function (alias) {
119
- return alias.toLowerCase() === searchString;
120
- });
121
- };
@@ -1,77 +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
- var startOfCodeBlockText = state.selection.$from;
7
- var endPosition = state.selection.empty && !(state.selection instanceof GapCursorSelection) ? startOfCodeBlockText.end() : state.selection.$to.pos;
8
- var startLinePosition = startOfCodeBlockText.start();
9
- //when cmd+A is used to select the content. start position should be 0.
10
- var parentStartPosition = startOfCodeBlockText.depth === 0 ? 0 : startOfCodeBlockText.before();
11
- var contentSlice = state.doc.slice(startOfCodeBlockText.pos, endPosition);
12
- var codeBlockSlice = mapSlice(contentSlice, function (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
- var 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
- var tr = state.tr;
48
-
49
- // Replace current block node
50
- var startMapped = startLinePosition === start ? parentStartPosition : start;
51
- var codeBlock = state.schema.nodes.codeBlock;
52
- var 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
- var mapped = tr.doc.resolve(tr.mapping.map(startMapped) + 1);
57
- var 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
- var $from = state.selection.$from;
69
- var node = $from.parent;
70
- if (!node.isTextblock || node.type === state.schema.nodes.codeBlock) {
71
- return false;
72
- }
73
- var parentDepth = $from.depth - 1;
74
- var parentNode = $from.node(parentDepth);
75
- var index = $from.index(parentDepth);
76
- return parentNode.canReplaceWith(index, index + 1, state.schema.nodes.codeBlock);
77
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,9 +0,0 @@
1
- import { CodeBlockSharedCssClassName } from '@atlaskit/editor-common/styles';
2
- export var 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,18 +0,0 @@
1
- import type { EditorState } from '@atlaskit/editor-prosemirror/state';
2
- import type { Command } from '@atlaskit/editor-common/types';
3
- import type { INPUT_METHOD, EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
4
- export declare const removeCodeBlock: Command;
5
- export declare const changeLanguage: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (language: string) => Command;
6
- export declare const copyContentToClipboard: Command;
7
- export declare const resetCopiedState: Command;
8
- export declare const ignoreFollowingMutations: Command;
9
- export declare const resetShouldIgnoreFollowingMutations: Command;
10
- /**
11
- * This function creates a new transaction that inserts a code block,
12
- * if there is text selected it will wrap the current selection if not it will
13
- * append the codeblock to the end of the document.
14
- */
15
- export declare function createInsertCodeBlockTransaction({ state, }: {
16
- state: EditorState;
17
- }): import("prosemirror-state").Transaction;
18
- export declare function insertCodeBlockWithAnalytics(inputMethod: INPUT_METHOD, analyticsAPI?: EditorAnalyticsAPI): Command;
@@ -1,12 +0,0 @@
1
- export declare const BRACKET_MAP: {
2
- '{': string;
3
- '[': string;
4
- '(': string;
5
- };
6
- export type BracketMapKey = keyof typeof BRACKET_MAP;
7
- export declare const shouldAutoCloseBracket: (before: string, after: string) => boolean;
8
- export declare const getAutoClosingBracketInfo: (before: string, after: string) => {
9
- left: "{" | "[" | "(" | undefined;
10
- right: string | undefined;
11
- hasTrailingMatchingBracket: boolean;
12
- };
@@ -1,7 +0,0 @@
1
- import type { EditorState } from '@atlaskit/editor-prosemirror/state';
2
- import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
3
- import type { CommandDispatch } from '@atlaskit/editor-common/types';
4
- export declare const indent: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (state: EditorState, dispatch?: CommandDispatch) => boolean;
5
- export declare const outdent: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (state: EditorState, dispatch?: CommandDispatch) => boolean;
6
- export declare function insertIndent(state: EditorState, dispatch: CommandDispatch): boolean;
7
- export declare function insertNewlineWithIndent(state: EditorState, dispatch?: CommandDispatch): boolean;
@@ -1,25 +0,0 @@
1
- import type { EditorState } from '@atlaskit/editor-prosemirror/state';
2
- export declare const isSelectionEntirelyInsideCodeBlock: (state: EditorState) => boolean;
3
- export declare const isCursorInsideCodeBlock: (state: EditorState) => boolean;
4
- export declare const getStartOfCurrentLine: (state: EditorState) => {
5
- text: string;
6
- pos: number;
7
- };
8
- export declare const getEndOfCurrentLine: (state: EditorState) => {
9
- text: string;
10
- pos: number;
11
- };
12
- export declare function getLinesFromSelection(state: EditorState): {
13
- text: string;
14
- start: number;
15
- end: number;
16
- };
17
- export declare const forEachLine: (text: string, callback: (line: string, offset: number) => void) => void;
18
- export declare const getLineInfo: (line: string) => {
19
- indentToken: {
20
- token: string;
21
- size: number;
22
- regex: RegExp;
23
- };
24
- indentText: string;
25
- };
@@ -1,2 +0,0 @@
1
- export declare const isCursorBeforeClosingCharacter: (after: string) => boolean;
2
- export declare const isClosingCharacter: (text: string) => boolean;
@@ -1,12 +0,0 @@
1
- export declare const QUOTE_MAP: {
2
- "'": string;
3
- '"': string;
4
- '`': string;
5
- };
6
- export type QuoteMapKey = keyof typeof QUOTE_MAP;
7
- export declare const shouldAutoCloseQuote: (before: string, after: string) => boolean;
8
- export declare const getAutoClosingQuoteInfo: (before: string, after: string) => {
9
- left: "`" | "'" | "\"" | undefined;
10
- right: string | undefined;
11
- hasTrailingMatchingQuote: boolean;
12
- };
@@ -1,19 +0,0 @@
1
- import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
- import type { NextEditorPlugin, OptionalPlugin, Command } from '@atlaskit/editor-common/types';
3
- import type { CodeBlockOptions } from './types';
4
- import type { decorationsPlugin } from '@atlaskit/editor-plugin-decorations';
5
- import type { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
6
- import type { compositionPlugin } from '@atlaskit/editor-plugin-composition';
7
- export type CodeBlockPlugin = NextEditorPlugin<'codeBlock', {
8
- pluginConfiguration: CodeBlockOptions;
9
- dependencies: [
10
- typeof decorationsPlugin,
11
- typeof compositionPlugin,
12
- OptionalPlugin<typeof analyticsPlugin>
13
- ];
14
- actions: {
15
- insertCodeBlock: (inputMethod: INPUT_METHOD) => Command;
16
- };
17
- }>;
18
- declare const codeBlockPlugin: CodeBlockPlugin;
19
- export default codeBlockPlugin;