@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,40 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.shouldAutoCloseQuote = exports.getAutoClosingQuoteInfo = exports.QUOTE_MAP = void 0;
7
- var QUOTE_MAP = exports.QUOTE_MAP = {
8
- "'": "'",
9
- '"': '"',
10
- '`': '`'
11
- };
12
- var shouldAutoCloseQuote = exports.shouldAutoCloseQuote = function shouldAutoCloseQuote(before, after) {
13
- // when directly before a closing bracket
14
- if (/^[}\])]/.test(after)) {
15
- return true;
16
- }
17
-
18
- // exclusion: when directly before a non-whitespace character
19
- if (/^[^\s]/.test(after)) {
20
- return false;
21
- }
22
-
23
- // exclusion: when directly after a letter or quote
24
- if (/[A-Za-z0-9]$/.test(before) || /[\'\"\`]$/.test(before)) {
25
- return false;
26
- }
27
- return true;
28
- };
29
- var getAutoClosingQuoteInfo = exports.getAutoClosingQuoteInfo = function getAutoClosingQuoteInfo(before, after) {
30
- var left = Object.keys(QUOTE_MAP).find(function (item) {
31
- return before.endsWith(item);
32
- });
33
- var right = left ? QUOTE_MAP[left] : undefined;
34
- var hasTrailingMatchingQuote = right ? after.startsWith(right) : false;
35
- return {
36
- left: left,
37
- right: right,
38
- hasTrailingMatchingQuote: hasTrailingMatchingQuote
39
- };
40
- };
@@ -1,120 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
- var _react = _interopRequireDefault(require("react"));
10
- var _adfSchema = require("@atlaskit/adf-schema");
11
- var _main = require("./pm-plugins/main");
12
- var _toolbar = require("./toolbar");
13
- var _keymaps = _interopRequireDefault(require("./pm-plugins/keymaps"));
14
- var _ideUx = _interopRequireDefault(require("./pm-plugins/ide-ux"));
15
- var _codeBlockCopySelectionPlugin = require("./pm-plugins/codeBlockCopySelectionPlugin");
16
- var _analytics = require("@atlaskit/editor-common/analytics");
17
- var _quickInsert = require("@atlaskit/editor-common/quick-insert");
18
- var _messages = require("@atlaskit/editor-common/messages");
19
- var _refreshBrowserSelection = _interopRequireDefault(require("./refresh-browser-selection"));
20
- var _actions = require("./actions");
21
- var _inputRule = require("./pm-plugins/input-rule");
22
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
23
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
24
- var codeBlockPlugin = function codeBlockPlugin(_ref) {
25
- var options = _ref.config,
26
- api = _ref.api;
27
- return {
28
- name: 'codeBlock',
29
- nodes: function nodes() {
30
- return [{
31
- name: 'codeBlock',
32
- node: _adfSchema.codeBlock
33
- }];
34
- },
35
- pmPlugins: function pmPlugins() {
36
- return [{
37
- name: 'codeBlock',
38
- plugin: function plugin(_ref2) {
39
- var _options$appearance;
40
- var getIntl = _ref2.getIntl;
41
- return (0, _main.createPlugin)(_objectSpread(_objectSpread({}, options), {}, {
42
- getIntl: getIntl,
43
- appearance: (_options$appearance = options === null || options === void 0 ? void 0 : options.appearance) !== null && _options$appearance !== void 0 ? _options$appearance : 'comment'
44
- }));
45
- }
46
- }, {
47
- name: 'codeBlockInputRule',
48
- plugin: function plugin(_ref3) {
49
- var _api$analytics;
50
- var schema = _ref3.schema;
51
- return (0, _inputRule.createCodeBlockInputRule)(schema, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
52
- }
53
- }, {
54
- name: 'codeBlockIDEKeyBindings',
55
- plugin: function plugin() {
56
- return (0, _ideUx.default)(api);
57
- }
58
- }, {
59
- name: 'codeBlockKeyMap',
60
- plugin: function plugin(_ref4) {
61
- var schema = _ref4.schema;
62
- return (0, _keymaps.default)(schema);
63
- }
64
- }, {
65
- name: 'codeBlockCopySelection',
66
- plugin: function plugin() {
67
- return (0, _codeBlockCopySelectionPlugin.codeBlockCopySelectionPlugin)();
68
- }
69
- }];
70
- },
71
- // Workaround for a firefox issue where dom selection is off sync
72
- // https://product-fabric.atlassian.net/browse/ED-12442
73
- onEditorViewStateUpdated: function onEditorViewStateUpdated(props) {
74
- (0, _refreshBrowserSelection.default)(props.originalTransaction, props.newEditorState);
75
- },
76
- actions: {
77
- /*
78
- * Function will insert code block at current selection if block is empty or below current selection and set focus on it.
79
- */
80
- insertCodeBlock: function insertCodeBlock(inputMethod) {
81
- var _api$analytics2;
82
- return (0, _actions.insertCodeBlockWithAnalytics)(inputMethod, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
83
- }
84
- },
85
- pluginsOptions: {
86
- quickInsert: function quickInsert(_ref5) {
87
- var formatMessage = _ref5.formatMessage;
88
- return [{
89
- id: 'codeblock',
90
- title: formatMessage(_messages.blockTypeMessages.codeblock),
91
- description: formatMessage(_messages.blockTypeMessages.codeblockDescription),
92
- keywords: ['code block'],
93
- priority: 700,
94
- keyshortcut: '```',
95
- icon: function icon() {
96
- return /*#__PURE__*/_react.default.createElement(_quickInsert.IconCode, null);
97
- },
98
- action: function action(_insert, state) {
99
- var _api$analytics3;
100
- var tr = (0, _actions.createInsertCodeBlockTransaction)({
101
- state: state
102
- });
103
- api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 || _api$analytics3.actions.attachAnalyticsEvent({
104
- action: _analytics.ACTION.INSERTED,
105
- actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
106
- actionSubjectId: _analytics.ACTION_SUBJECT_ID.CODE_BLOCK,
107
- attributes: {
108
- inputMethod: _analytics.INPUT_METHOD.QUICK_INSERT
109
- },
110
- eventType: _analytics.EVENT_TYPE.TRACK
111
- })(tr);
112
- return tr;
113
- }
114
- }];
115
- },
116
- floatingToolbar: (0, _toolbar.getToolbarConfig)(options === null || options === void 0 ? void 0 : options.allowCopyToClipboard, api)
117
- }
118
- };
119
- };
120
- var _default = exports.default = codeBlockPlugin;
@@ -1,62 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.DEFAULT_LANGUAGES = void 0;
8
- exports.createLanguageList = createLanguageList;
9
- exports.filterSupportedLanguages = filterSupportedLanguages;
10
- exports.findMatchedLanguage = findMatchedLanguage;
11
- exports.getLanguageIdentifier = getLanguageIdentifier;
12
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
- var _constants = require("@atlaskit/code/constants");
14
- // We expect alias[0] to be used for the ADF attribute, see ED-2813
15
- var DEFAULT_LANGUAGES = exports.DEFAULT_LANGUAGES = [{
16
- name: '(None)',
17
- alias: ['none'],
18
- value: 'none'
19
- }].concat((0, _toConsumableArray2.default)(_constants.SUPPORTED_LANGUAGES));
20
- function findMatchedLanguage(supportedLanguages, language) {
21
- if (!language) {
22
- return undefined;
23
- }
24
- var matches = supportedLanguages.filter(function (supportedLanguage) {
25
- return supportedLanguage.alias.indexOf(language.toLowerCase()) !== -1;
26
- });
27
- if (matches.length > 0) {
28
- return matches[0];
29
- }
30
- return undefined;
31
- }
32
- function filterSupportedLanguages(supportedLanguages) {
33
- if (!supportedLanguages || !supportedLanguages.length) {
34
- return DEFAULT_LANGUAGES;
35
- }
36
- return DEFAULT_LANGUAGES.filter(function (language) {
37
- var i = language.alias.length;
38
- while (i--) {
39
- if (supportedLanguages.indexOf(language.alias[i]) > -1) {
40
- return true;
41
- }
42
- }
43
- return false;
44
- });
45
- }
46
- function getLanguageIdentifier(language) {
47
- return language.alias[0];
48
- }
49
- function createLanguageList(supportedLanguages) {
50
- return supportedLanguages.sort(function (left, right) {
51
- if (left.alias[0] === 'none') {
52
- return -1;
53
- }
54
- if (left.name.toLowerCase() > right.name.toLowerCase()) {
55
- return 1;
56
- }
57
- if (left.name.toLowerCase() < right.name.toLowerCase()) {
58
- return -1;
59
- }
60
- return 0;
61
- });
62
- }
@@ -1,153 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.codeBlockNodeView = exports.CodeBlockView = void 0;
8
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
12
- var _rafSchd = _interopRequireDefault(require("raf-schd"));
13
- var _utils = require("@atlaskit/editor-common/utils");
14
- var _model = require("@atlaskit/editor-prosemirror/model");
15
- var _classNames = require("../ui/class-names");
16
- var _actions = require("../actions");
17
- var _mainState = require("../pm-plugins/main-state");
18
- var MATCH_NEWLINES = new RegExp('\n', 'g');
19
- var toDOM = function toDOM(node) {
20
- return ['div', {
21
- class: 'code-block'
22
- }, ['div', {
23
- class: _classNames.codeBlockClassNames.start,
24
- contenteditable: 'false'
25
- }], ['div', {
26
- class: _classNames.codeBlockClassNames.contentWrapper
27
- }, ['div', {
28
- class: _classNames.codeBlockClassNames.gutter,
29
- contenteditable: 'false'
30
- }], ['div', {
31
- class: _classNames.codeBlockClassNames.content
32
- }, ['code', {
33
- 'data-language': node.attrs.language || '',
34
- spellcheck: 'false',
35
- contenteditable: 'true',
36
- 'data-testid': 'code-block--code'
37
- }, 0]]], ['div', {
38
- class: _classNames.codeBlockClassNames.end,
39
- contenteditable: 'false'
40
- }]];
41
- };
42
- var CodeBlockView = exports.CodeBlockView = /*#__PURE__*/function () {
43
- function CodeBlockView(_node, view, getPos) {
44
- var _this = this;
45
- (0, _classCallCheck2.default)(this, CodeBlockView);
46
- (0, _defineProperty2.default)(this, "ensureLineNumbers", (0, _rafSchd.default)(function () {
47
- var lines = 1;
48
- _this.node.forEach(function (node) {
49
- var text = node.text;
50
- if (text) {
51
- lines += (node.text.match(MATCH_NEWLINES) || []).length;
52
- }
53
- });
54
- while (_this.lineNumberGutter.childElementCount < lines) {
55
- _this.lineNumberGutter.appendChild(document.createElement('span'));
56
- }
57
- while (_this.lineNumberGutter.childElementCount > lines) {
58
- _this.lineNumberGutter.removeChild(_this.lineNumberGutter.lastChild);
59
- }
60
- }));
61
- var _DOMSerializer$render = _model.DOMSerializer.renderSpec(document, toDOM(_node)),
62
- dom = _DOMSerializer$render.dom,
63
- contentDOM = _DOMSerializer$render.contentDOM;
64
- this.getPos = getPos;
65
- this.view = view;
66
- this.node = _node;
67
- this.dom = dom;
68
- this.contentDOM = contentDOM;
69
- this.lineNumberGutter = this.dom.querySelector(".".concat(_classNames.codeBlockClassNames.gutter));
70
- this.ensureLineNumbers();
71
- }
72
- (0, _createClass2.default)(CodeBlockView, [{
73
- key: "updateDOMAndSelection",
74
- value: function updateDOMAndSelection(savedInnerHTML, newCursorPosition) {
75
- var _this$dom;
76
- if ((_this$dom = this.dom) !== null && _this$dom !== void 0 && _this$dom.childNodes && this.dom.childNodes.length > 1) {
77
- var _contentView$childNod;
78
- var contentWrapper = this.dom.childNodes[1];
79
- var contentView = contentWrapper === null || contentWrapper === void 0 ? void 0 : contentWrapper.childNodes[1];
80
- if ((contentView === null || contentView === void 0 || (_contentView$childNod = contentView.childNodes) === null || _contentView$childNod === void 0 ? void 0 : _contentView$childNod.length) > 0) {
81
- var codeElement = contentView.firstChild;
82
- codeElement.innerHTML = savedInnerHTML;
83
-
84
- // We need to set cursor for the DOM update
85
- var textElement = (0, _toConsumableArray2.default)(codeElement.childNodes).find(function (child) {
86
- return child.nodeName === '#text';
87
- });
88
- var sel = window.getSelection();
89
- var range = document.createRange();
90
- range.setStart(textElement, newCursorPosition);
91
- range.collapse(true);
92
- sel === null || sel === void 0 || sel.removeAllRanges();
93
- sel === null || sel === void 0 || sel.addRange(range);
94
- }
95
- }
96
- }
97
- }, {
98
- key: "coalesceDOMElements",
99
- value: function coalesceDOMElements() {
100
- var _this$dom2;
101
- if ((_this$dom2 = this.dom) !== null && _this$dom2 !== void 0 && _this$dom2.childNodes && this.dom.childNodes.length > 1) {
102
- var contentWrapper = this.dom.childNodes[1];
103
- var contentView = contentWrapper === null || contentWrapper === void 0 ? void 0 : contentWrapper.childNodes[1];
104
- if (contentView !== null && contentView !== void 0 && contentView.childNodes && contentView.childNodes.length > 1) {
105
- var savedInnerHTML = '';
106
- while (contentView.childNodes.length > 1) {
107
- var lastChild = contentView.lastChild;
108
- savedInnerHTML = lastChild.innerHTML + savedInnerHTML;
109
- contentView.removeChild(lastChild);
110
- }
111
- var firstChild = contentView.firstChild;
112
- savedInnerHTML = firstChild.innerHTML + '\n' + savedInnerHTML;
113
- var newCursorPosition = firstChild.innerHTML.length + 1;
114
- setTimeout(this.updateDOMAndSelection.bind(this, savedInnerHTML, newCursorPosition), 20);
115
- }
116
- }
117
- }
118
- }, {
119
- key: "update",
120
- value: function update(node) {
121
- if (node.type !== this.node.type) {
122
- return false;
123
- }
124
- if (node !== this.node) {
125
- if (node.attrs.language !== this.node.attrs.language) {
126
- this.contentDOM.setAttribute('data-language', node.attrs.language || '');
127
- }
128
- this.node = node;
129
- this.ensureLineNumbers();
130
- if (_utils.browser.android) {
131
- this.coalesceDOMElements();
132
- (0, _actions.resetShouldIgnoreFollowingMutations)(this.view.state, this.view.dispatch);
133
- }
134
- }
135
- return true;
136
- }
137
- }, {
138
- key: "ignoreMutation",
139
- value: function ignoreMutation(record) {
140
- var pluginState = (0, _mainState.getPluginState)(this.view.state);
141
- if (pluginState !== null && pluginState !== void 0 && pluginState.shouldIgnoreFollowingMutations) {
142
- return true;
143
- }
144
-
145
- // Ensure updating the line-number gutter doesn't trigger reparsing the codeblock
146
- return record.target === this.lineNumberGutter || record.target.parentNode === this.lineNumberGutter;
147
- }
148
- }]);
149
- return CodeBlockView;
150
- }();
151
- var codeBlockNodeView = exports.codeBlockNodeView = function codeBlockNodeView(node, view, getPos) {
152
- return new CodeBlockView(node, view, getPos);
153
- };
@@ -1,8 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.pluginKey = void 0;
7
- var _state = require("@atlaskit/editor-prosemirror/state");
8
- var pluginKey = exports.pluginKey = new _state.PluginKey('codeBlockPlugin');
@@ -1,10 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ACTIONS = void 0;
7
- var ACTIONS = exports.ACTIONS = {
8
- SET_COPIED_TO_CLIPBOARD: 'SET_COPIED_TO_CLIPBOARD',
9
- SET_SHOULD_IGNORE_FOLLOWING_MUTATIONS: 'SET_SHOULD_IGNORE_FOLLOWING_MUTATIONS'
10
- };
@@ -1,113 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.codeBlockCopySelectionPlugin = codeBlockCopySelectionPlugin;
8
- exports.copySelectionPluginKey = void 0;
9
- exports.provideVisualFeedbackForCopyButton = provideVisualFeedbackForCopyButton;
10
- exports.removeVisualFeedbackForCopyButton = removeVisualFeedbackForCopyButton;
11
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
12
- var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
13
- var _state = require("@atlaskit/editor-prosemirror/state");
14
- var _view = require("@atlaskit/editor-prosemirror/view");
15
- var _copyButton = require("@atlaskit/editor-common/copy-button");
16
- var copySelectionPluginKey = exports.copySelectionPluginKey = new _state.PluginKey('codeBlockCopySelectionPlugin');
17
- function getSelectionDecorationStartAndEnd(_ref) {
18
- var state = _ref.state,
19
- transaction = _ref.transaction;
20
- var codeBlockNode = (0, _copyButton.getSelectedNodeOrNodeParentByNodeType)({
21
- nodeType: state.schema.nodes.codeBlock,
22
- selection: transaction.selection
23
- });
24
- if (!codeBlockNode) {
25
- return {
26
- decorationStartAndEnd: undefined
27
- };
28
- }
29
- var decorationStartAndEnd = [codeBlockNode.start, codeBlockNode.start + codeBlockNode.node.nodeSize];
30
- return {
31
- decorationStartAndEnd: decorationStartAndEnd
32
- };
33
- }
34
- function codeBlockCopySelectionPlugin() {
35
- return new _safePlugin.SafePlugin({
36
- key: copySelectionPluginKey,
37
- state: {
38
- init: function init() {
39
- return {
40
- decorationStartAndEnd: undefined
41
- };
42
- },
43
- apply: function apply(transaction, currentCodeBlockCopySelectionPluginState, _oldState, newState) {
44
- switch (transaction.getMeta(copySelectionPluginKey)) {
45
- case 'show-selection':
46
- {
47
- return getSelectionDecorationStartAndEnd({
48
- state: newState,
49
- transaction: transaction
50
- });
51
- }
52
- case 'remove-selection':
53
- return {
54
- decorationStartAndEnd: undefined
55
- };
56
- default:
57
- // The contents of the code block can change while the selection is being shown
58
- // (either from collab edits -- or from the user continuing to type while hovering
59
- // the mouse over the copy button).
60
- // This ensures the selection is updated in these cases.
61
- if (currentCodeBlockCopySelectionPluginState.decorationStartAndEnd !== undefined) {
62
- return getSelectionDecorationStartAndEnd({
63
- state: newState,
64
- transaction: transaction
65
- });
66
- }
67
- return currentCodeBlockCopySelectionPluginState;
68
- }
69
- }
70
- },
71
- props: {
72
- decorations: function decorations(state) {
73
- if (copySelectionPluginKey.getState(state).decorationStartAndEnd) {
74
- var _copySelectionPluginK = (0, _slicedToArray2.default)(copySelectionPluginKey.getState(state).decorationStartAndEnd, 2),
75
- _start = _copySelectionPluginK[0],
76
- _end = _copySelectionPluginK[1];
77
- return _view.DecorationSet.create(state.doc, [_view.Decoration.inline(_start, _end, {
78
- class: 'ProseMirror-fake-text-selection'
79
- })]);
80
- }
81
- return _view.DecorationSet.empty;
82
- }
83
- }
84
- });
85
- }
86
- function provideVisualFeedbackForCopyButton(state, dispatch) {
87
- var tr = state.tr;
88
- tr.setMeta(copySelectionPluginKey, 'show-selection');
89
-
90
- // note: dispatch should always be defined when called from the
91
- // floating toolbar. Howver the Command type which the floating toolbar
92
- // uses suggests it's optional.
93
- // Using the type here to protect against future refactors of the
94
- // floating toolbar
95
- if (dispatch) {
96
- dispatch(tr);
97
- }
98
- return true;
99
- }
100
- function removeVisualFeedbackForCopyButton(state, dispatch) {
101
- var tr = state.tr;
102
- tr.setMeta(copySelectionPluginKey, 'remove-selection');
103
-
104
- // note: dispatch should always be defined when called from the
105
- // floating toolbar. Howver the Command type which the floating toolbar
106
- // uses suggests it's optional.
107
- // Using the type here to protect against future refactors of the
108
- // floating toolbar
109
- if (dispatch) {
110
- dispatch(tr);
111
- }
112
- return true;
113
- }
@@ -1,132 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
8
- var _state = require("@atlaskit/editor-prosemirror/state");
9
- var _keymap = require("@atlaskit/editor-prosemirror/keymap");
10
- var _utils = require("@atlaskit/editor-prosemirror/utils");
11
- var _utils2 = require("../utils");
12
- var _utils3 = require("@atlaskit/editor-common/utils");
13
- var _pairedCharacterHandling = require("../ide-ux/paired-character-handling");
14
- var _bracketHandling = require("../ide-ux/bracket-handling");
15
- var _quoteHandling = require("../ide-ux/quote-handling");
16
- var _lineHandling = require("../ide-ux/line-handling");
17
- var _commands = require("../ide-ux/commands");
18
- var ideUX = function ideUX(pluginInjectionApi) {
19
- var _pluginInjectionApi$a;
20
- var editorAnalyticsAPI = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions;
21
- return new _safePlugin.SafePlugin({
22
- props: {
23
- handleTextInput: function handleTextInput(view, from, to, text) {
24
- var _pluginInjectionApi$c;
25
- var state = view.state,
26
- dispatch = view.dispatch;
27
- var compositionPluginState = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c = pluginInjectionApi.composition) === null || _pluginInjectionApi$c === void 0 ? void 0 : _pluginInjectionApi$c.sharedState.currentState();
28
- if ((0, _lineHandling.isCursorInsideCodeBlock)(state) && !(compositionPluginState !== null && compositionPluginState !== void 0 && compositionPluginState.isComposing)) {
29
- var beforeText = (0, _lineHandling.getStartOfCurrentLine)(state).text;
30
- var afterText = (0, _lineHandling.getEndOfCurrentLine)(state).text;
31
-
32
- // If text is a closing bracket/quote and we've already inserted it, move the selection after
33
- if ((0, _pairedCharacterHandling.isCursorBeforeClosingCharacter)(afterText) && (0, _pairedCharacterHandling.isClosingCharacter)(text) && afterText.startsWith(text)) {
34
- dispatch((0, _utils.setTextSelection)(to + text.length)(state.tr));
35
- return true;
36
- }
37
-
38
- // Automatically add right-hand side bracket when user types the left bracket
39
- if ((0, _bracketHandling.shouldAutoCloseBracket)(beforeText, afterText)) {
40
- var _getAutoClosingBracke = (0, _bracketHandling.getAutoClosingBracketInfo)(beforeText + text, afterText),
41
- left = _getAutoClosingBracke.left,
42
- right = _getAutoClosingBracke.right;
43
- if (left && right) {
44
- var bracketPair = state.schema.text(text + right);
45
- var tr = state.tr.replaceWith(from, to, bracketPair);
46
- dispatch((0, _utils.setTextSelection)(from + text.length)(tr));
47
- return true;
48
- }
49
- }
50
-
51
- // Automatically add closing quote when user types a starting quote
52
- if ((0, _quoteHandling.shouldAutoCloseQuote)(beforeText, afterText)) {
53
- var _getAutoClosingQuoteI = (0, _quoteHandling.getAutoClosingQuoteInfo)(beforeText + text, afterText),
54
- leftQuote = _getAutoClosingQuoteI.left,
55
- rightQuote = _getAutoClosingQuoteI.right;
56
- if (leftQuote && rightQuote) {
57
- var quotePair = state.schema.text(text + rightQuote);
58
- var _tr = state.tr.replaceWith(from, to, quotePair);
59
- dispatch((0, _utils.setTextSelection)(from + text.length)(_tr));
60
- return true;
61
- }
62
- }
63
- }
64
- return false;
65
- },
66
- handleKeyDown: (0, _keymap.keydownHandler)({
67
- Backspace: function Backspace(state, dispatch) {
68
- if ((0, _lineHandling.isCursorInsideCodeBlock)(state)) {
69
- var $cursor = (0, _utils2.getCursor)(state.selection);
70
- var beforeText = (0, _lineHandling.getStartOfCurrentLine)(state).text;
71
- var afterText = (0, _lineHandling.getEndOfCurrentLine)(state).text;
72
- var _getAutoClosingBracke2 = (0, _bracketHandling.getAutoClosingBracketInfo)(beforeText, afterText),
73
- leftBracket = _getAutoClosingBracke2.left,
74
- rightBracket = _getAutoClosingBracke2.right,
75
- hasTrailingMatchingBracket = _getAutoClosingBracke2.hasTrailingMatchingBracket;
76
- if (leftBracket && rightBracket && hasTrailingMatchingBracket && dispatch) {
77
- dispatch(state.tr.delete($cursor.pos - leftBracket.length, $cursor.pos + rightBracket.length));
78
- return true;
79
- }
80
- var _getAutoClosingQuoteI2 = (0, _quoteHandling.getAutoClosingQuoteInfo)(beforeText, afterText),
81
- leftQuote = _getAutoClosingQuoteI2.left,
82
- rightQuote = _getAutoClosingQuoteI2.right,
83
- hasTrailingMatchingQuote = _getAutoClosingQuoteI2.hasTrailingMatchingQuote;
84
- if (leftQuote && rightQuote && hasTrailingMatchingQuote && dispatch) {
85
- dispatch(state.tr.delete($cursor.pos - leftQuote.length, $cursor.pos + rightQuote.length));
86
- return true;
87
- }
88
- var _getLineInfo = (0, _lineHandling.getLineInfo)(beforeText),
89
- _getLineInfo$indentTo = _getLineInfo.indentToken,
90
- size = _getLineInfo$indentTo.size,
91
- token = _getLineInfo$indentTo.token,
92
- indentText = _getLineInfo.indentText;
93
- if (beforeText === indentText) {
94
- if (indentText.endsWith(token.repeat(size)) && dispatch) {
95
- dispatch(state.tr.delete($cursor.pos - (size - indentText.length % size || size), $cursor.pos));
96
- return true;
97
- }
98
- }
99
- }
100
- return false;
101
- },
102
- Enter: (0, _utils3.filterCommand)(_lineHandling.isSelectionEntirelyInsideCodeBlock, _commands.insertNewlineWithIndent),
103
- 'Mod-]': (0, _utils3.filterCommand)(_lineHandling.isSelectionEntirelyInsideCodeBlock, (0, _commands.indent)(editorAnalyticsAPI)),
104
- 'Mod-[': (0, _utils3.filterCommand)(_lineHandling.isSelectionEntirelyInsideCodeBlock, (0, _commands.outdent)(editorAnalyticsAPI)),
105
- Tab: (0, _utils3.filterCommand)(_lineHandling.isSelectionEntirelyInsideCodeBlock, function (state, dispatch) {
106
- if (!dispatch) {
107
- return false;
108
- }
109
- if ((0, _lineHandling.isCursorInsideCodeBlock)(state)) {
110
- return (0, _commands.insertIndent)(state, dispatch);
111
- }
112
- return (0, _commands.indent)(editorAnalyticsAPI)(state, dispatch);
113
- }),
114
- 'Shift-Tab': (0, _utils3.filterCommand)(_lineHandling.isSelectionEntirelyInsideCodeBlock, (0, _commands.outdent)(editorAnalyticsAPI)),
115
- 'Mod-a': function ModA(state, dispatch) {
116
- if ((0, _lineHandling.isSelectionEntirelyInsideCodeBlock)(state)) {
117
- var _state$selection = state.selection,
118
- $from = _state$selection.$from,
119
- $to = _state$selection.$to;
120
- var isFullCodeBlockSelection = $from.parentOffset === 0 && $to.parentOffset === $to.parent.nodeSize - 2;
121
- if (!isFullCodeBlockSelection && dispatch) {
122
- dispatch(state.tr.setSelection(_state.TextSelection.create(state.doc, $from.start(), $to.end())));
123
- return true;
124
- }
125
- }
126
- return false;
127
- }
128
- })
129
- }
130
- });
131
- };
132
- var _default = exports.default = ideUX;