@atlaskit/editor-plugin-block-type 1.0.0

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 (120) hide show
  1. package/.eslintrc.js +14 -0
  2. package/CHANGELOG.md +1 -0
  3. package/LICENSE.md +13 -0
  4. package/README.md +32 -0
  5. package/consts/package.json +15 -0
  6. package/dist/cjs/consts.js +66 -0
  7. package/dist/cjs/index.js +12 -0
  8. package/dist/cjs/messages.js +19 -0
  9. package/dist/cjs/plugin/block-types.js +106 -0
  10. package/dist/cjs/plugin/commands/block-type.js +183 -0
  11. package/dist/cjs/plugin/commands/delete-and-move-cursor.js +56 -0
  12. package/dist/cjs/plugin/commands/delete-block-content.js +45 -0
  13. package/dist/cjs/plugin/commands/index.js +69 -0
  14. package/dist/cjs/plugin/consts.js +15 -0
  15. package/dist/cjs/plugin/index.js +217 -0
  16. package/dist/cjs/plugin/messages.js +160 -0
  17. package/dist/cjs/plugin/pm-plugins/input-rule.js +104 -0
  18. package/dist/cjs/plugin/pm-plugins/keymap.js +34 -0
  19. package/dist/cjs/plugin/pm-plugins/main.js +151 -0
  20. package/dist/cjs/plugin/styles.js +15 -0
  21. package/dist/cjs/plugin/types.js +5 -0
  22. package/dist/cjs/plugin/ui/ToolbarBlockType/blocktype-button.js +60 -0
  23. package/dist/cjs/plugin/ui/ToolbarBlockType/index.js +208 -0
  24. package/dist/cjs/plugin/ui/ToolbarBlockType/styled.js +34 -0
  25. package/dist/cjs/plugin/ui/ToolbarBlockType/toolbar-messages.js +15 -0
  26. package/dist/cjs/plugin/utils.js +87 -0
  27. package/dist/cjs/styles.js +12 -0
  28. package/dist/es2019/consts.js +1 -0
  29. package/dist/es2019/index.js +1 -0
  30. package/dist/es2019/messages.js +2 -0
  31. package/dist/es2019/plugin/block-types.js +84 -0
  32. package/dist/es2019/plugin/commands/block-type.js +170 -0
  33. package/dist/es2019/plugin/commands/delete-and-move-cursor.js +55 -0
  34. package/dist/es2019/plugin/commands/delete-block-content.js +42 -0
  35. package/dist/es2019/plugin/commands/index.js +8 -0
  36. package/dist/es2019/plugin/consts.js +8 -0
  37. package/dist/es2019/plugin/index.js +204 -0
  38. package/dist/es2019/plugin/messages.js +153 -0
  39. package/dist/es2019/plugin/pm-plugins/input-rule.js +93 -0
  40. package/dist/es2019/plugin/pm-plugins/keymap.js +25 -0
  41. package/dist/es2019/plugin/pm-plugins/main.js +137 -0
  42. package/dist/es2019/plugin/styles.js +8 -0
  43. package/dist/es2019/plugin/types.js +1 -0
  44. package/dist/es2019/plugin/ui/ToolbarBlockType/blocktype-button.js +50 -0
  45. package/dist/es2019/plugin/ui/ToolbarBlockType/index.js +185 -0
  46. package/dist/es2019/plugin/ui/ToolbarBlockType/styled.js +49 -0
  47. package/dist/es2019/plugin/ui/ToolbarBlockType/toolbar-messages.js +8 -0
  48. package/dist/es2019/plugin/utils.js +76 -0
  49. package/dist/es2019/styles.js +1 -0
  50. package/dist/esm/consts.js +1 -0
  51. package/dist/esm/index.js +1 -0
  52. package/dist/esm/messages.js +2 -0
  53. package/dist/esm/plugin/block-types.js +84 -0
  54. package/dist/esm/plugin/commands/block-type.js +169 -0
  55. package/dist/esm/plugin/commands/delete-and-move-cursor.js +50 -0
  56. package/dist/esm/plugin/commands/delete-block-content.js +39 -0
  57. package/dist/esm/plugin/commands/index.js +8 -0
  58. package/dist/esm/plugin/consts.js +8 -0
  59. package/dist/esm/plugin/index.js +205 -0
  60. package/dist/esm/plugin/messages.js +153 -0
  61. package/dist/esm/plugin/pm-plugins/input-rule.js +96 -0
  62. package/dist/esm/plugin/pm-plugins/keymap.js +25 -0
  63. package/dist/esm/plugin/pm-plugins/main.js +142 -0
  64. package/dist/esm/plugin/styles.js +7 -0
  65. package/dist/esm/plugin/types.js +1 -0
  66. package/dist/esm/plugin/ui/ToolbarBlockType/blocktype-button.js +50 -0
  67. package/dist/esm/plugin/ui/ToolbarBlockType/index.js +201 -0
  68. package/dist/esm/plugin/ui/ToolbarBlockType/styled.js +20 -0
  69. package/dist/esm/plugin/ui/ToolbarBlockType/toolbar-messages.js +8 -0
  70. package/dist/esm/plugin/utils.js +77 -0
  71. package/dist/esm/styles.js +1 -0
  72. package/dist/types/consts.d.ts +1 -0
  73. package/dist/types/index.d.ts +6 -0
  74. package/dist/types/messages.d.ts +2 -0
  75. package/dist/types/plugin/block-types.d.ts +19 -0
  76. package/dist/types/plugin/commands/block-type.d.ts +18 -0
  77. package/dist/types/plugin/commands/delete-and-move-cursor.d.ts +12 -0
  78. package/dist/types/plugin/commands/delete-block-content.d.ts +10 -0
  79. package/dist/types/plugin/commands/index.d.ts +9 -0
  80. package/dist/types/plugin/consts.d.ts +1 -0
  81. package/dist/types/plugin/index.d.ts +18 -0
  82. package/dist/types/plugin/messages.d.ts +152 -0
  83. package/dist/types/plugin/pm-plugins/input-rule.d.ts +6 -0
  84. package/dist/types/plugin/pm-plugins/keymap.d.ts +5 -0
  85. package/dist/types/plugin/pm-plugins/main.d.ts +17 -0
  86. package/dist/types/plugin/styles.d.ts +2 -0
  87. package/dist/types/plugin/types.d.ts +22 -0
  88. package/dist/types/plugin/ui/ToolbarBlockType/blocktype-button.d.ts +22 -0
  89. package/dist/types/plugin/ui/ToolbarBlockType/index.d.ts +29 -0
  90. package/dist/types/plugin/ui/ToolbarBlockType/styled.d.ts +8 -0
  91. package/dist/types/plugin/ui/ToolbarBlockType/toolbar-messages.d.ts +7 -0
  92. package/dist/types/plugin/utils.d.ts +16 -0
  93. package/dist/types/styles.d.ts +1 -0
  94. package/dist/types-ts4.5/consts.d.ts +1 -0
  95. package/dist/types-ts4.5/index.d.ts +6 -0
  96. package/dist/types-ts4.5/messages.d.ts +2 -0
  97. package/dist/types-ts4.5/plugin/block-types.d.ts +19 -0
  98. package/dist/types-ts4.5/plugin/commands/block-type.d.ts +18 -0
  99. package/dist/types-ts4.5/plugin/commands/delete-and-move-cursor.d.ts +12 -0
  100. package/dist/types-ts4.5/plugin/commands/delete-block-content.d.ts +10 -0
  101. package/dist/types-ts4.5/plugin/commands/index.d.ts +9 -0
  102. package/dist/types-ts4.5/plugin/consts.d.ts +1 -0
  103. package/dist/types-ts4.5/plugin/index.d.ts +20 -0
  104. package/dist/types-ts4.5/plugin/messages.d.ts +152 -0
  105. package/dist/types-ts4.5/plugin/pm-plugins/input-rule.d.ts +6 -0
  106. package/dist/types-ts4.5/plugin/pm-plugins/keymap.d.ts +5 -0
  107. package/dist/types-ts4.5/plugin/pm-plugins/main.d.ts +17 -0
  108. package/dist/types-ts4.5/plugin/styles.d.ts +2 -0
  109. package/dist/types-ts4.5/plugin/types.d.ts +22 -0
  110. package/dist/types-ts4.5/plugin/ui/ToolbarBlockType/blocktype-button.d.ts +22 -0
  111. package/dist/types-ts4.5/plugin/ui/ToolbarBlockType/index.d.ts +29 -0
  112. package/dist/types-ts4.5/plugin/ui/ToolbarBlockType/styled.d.ts +8 -0
  113. package/dist/types-ts4.5/plugin/ui/ToolbarBlockType/toolbar-messages.d.ts +7 -0
  114. package/dist/types-ts4.5/plugin/utils.d.ts +16 -0
  115. package/dist/types-ts4.5/styles.d.ts +1 -0
  116. package/messages/package.json +15 -0
  117. package/package.json +105 -0
  118. package/report.api.md +108 -0
  119. package/styles/package.json +15 -0
  120. package/tmp/api-report-tmp.d.ts +75 -0
package/.eslintrc.js ADDED
@@ -0,0 +1,14 @@
1
+ module.exports = {
2
+ rules: {
3
+ '@typescript-eslint/no-duplicate-imports': 'error',
4
+ '@typescript-eslint/no-explicit-any': 'error',
5
+ },
6
+ overrides: [
7
+ {
8
+ files: ['**/__tests__/**/*.{js,ts,tsx}', '**/examples/**/*.{js,ts,tsx}'],
9
+ rules: {
10
+ '@typescript-eslint/no-explicit-any': 'off',
11
+ },
12
+ },
13
+ ],
14
+ };
package/CHANGELOG.md ADDED
@@ -0,0 +1 @@
1
+ # @atlaskit/editor-plugin-block-type
package/LICENSE.md ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2023 Atlassian Pty Ltd
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # Editor plugin block-type
2
+
3
+ Block type plugin for @atlaskit/editor-core
4
+
5
+ **Note:** This component is designed for internal Atlassian development.
6
+ External contributors will be able to use this component but will not be able to submit issues.
7
+
8
+ ## Install
9
+ ---
10
+ - **Install** - *yarn add @atlaskit/editor-plugin-block-type*
11
+ - **npm** - [@atlaskit/editor-plugin-block-type](https://www.npmjs.com/package/@atlaskit/editor-plugin-block-type)
12
+ - **Source** - [Bitbucket](https://bitbucket.org/atlassian/atlassian-frontend/src/master/packages/editor/editor-plugin-block-type)
13
+ - **Bundle** - [unpkg.com](https://unpkg.com/@atlaskit/editor-plugin-block-type/dist/)
14
+
15
+ ## Usage
16
+ ---
17
+ **Internal use only**
18
+
19
+ @atlaskit/editor-plugin-block-type is intended for internal use by the @atlaskit/editor-core and as a plugin dependency of the Editor within your product.
20
+
21
+ Direct use of this component is not supported.
22
+
23
+ Please see [Atlaskit - Editor plugin block-type](https://atlaskit.atlassian.com/packages/editor/editor-plugin-block-type) for documentation and examples for this package.
24
+
25
+ ## Support
26
+ ---
27
+ For internal Atlassian, visit the slack channel [#help-editor](https://atlassian.slack.com/archives/CFG3PSQ9E) for support or visit [go/editor-help](https://go/editor-help) to submit a bug.
28
+
29
+ ## License
30
+ ---
31
+ Please see [Atlassian Frontend - License](https://developer.atlassian.com/cloud/framework/atlassian-frontend/#license) for more licensing information.
32
+
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@atlaskit/editor-plugin-block-type/consts",
3
+ "main": "../dist/cjs/consts.js",
4
+ "module": "../dist/esm/consts.js",
5
+ "module:es2019": "../dist/es2019/consts.js",
6
+ "sideEffects": false,
7
+ "types": "../dist/types/consts.d.ts",
8
+ "typesVersions": {
9
+ ">=4.5 <4.9": {
10
+ "*": [
11
+ "../dist/types-ts4.5/consts.d.ts"
12
+ ]
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "BLOCK_QUOTE", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _blockTypes.BLOCK_QUOTE;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "CODE_BLOCK", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _blockTypes.CODE_BLOCK;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "HEADING_1", {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return _blockTypes.HEADING_1;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "HEADING_2", {
25
+ enumerable: true,
26
+ get: function get() {
27
+ return _blockTypes.HEADING_2;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "HEADING_3", {
31
+ enumerable: true,
32
+ get: function get() {
33
+ return _blockTypes.HEADING_3;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "HEADING_4", {
37
+ enumerable: true,
38
+ get: function get() {
39
+ return _blockTypes.HEADING_4;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "HEADING_5", {
43
+ enumerable: true,
44
+ get: function get() {
45
+ return _blockTypes.HEADING_5;
46
+ }
47
+ });
48
+ Object.defineProperty(exports, "HEADING_6", {
49
+ enumerable: true,
50
+ get: function get() {
51
+ return _blockTypes.HEADING_6;
52
+ }
53
+ });
54
+ Object.defineProperty(exports, "NORMAL_TEXT", {
55
+ enumerable: true,
56
+ get: function get() {
57
+ return _blockTypes.NORMAL_TEXT;
58
+ }
59
+ });
60
+ Object.defineProperty(exports, "PANEL", {
61
+ enumerable: true,
62
+ get: function get() {
63
+ return _blockTypes.PANEL;
64
+ }
65
+ });
66
+ var _blockTypes = require("./plugin/block-types");
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "blockTypePlugin", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _plugin.blockTypePlugin;
10
+ }
11
+ });
12
+ var _plugin = require("./plugin");
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "messages", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _messages.messages;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "toolbarMessages", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _toolbarMessages.toolbarMessages;
16
+ }
17
+ });
18
+ var _messages = require("./plugin/messages");
19
+ var _toolbarMessages = require("./plugin/ui/ToolbarBlockType/toolbar-messages");
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.WRAPPER_BLOCK_TYPES = exports.TEXT_BLOCK_TYPES = exports.PANEL = exports.OTHER = exports.NORMAL_TEXT = exports.HEADING_6 = exports.HEADING_5 = exports.HEADING_4 = exports.HEADING_3 = exports.HEADING_2 = exports.HEADING_1 = exports.HEADINGS_BY_NAME = exports.HEADINGS_BY_LEVEL = exports.CODE_BLOCK = exports.BLOCK_QUOTE = exports.ALL_BLOCK_TYPES = void 0;
7
+ var _messages = require("./messages");
8
+ var NORMAL_TEXT = {
9
+ name: 'normal',
10
+ title: _messages.messages.normal,
11
+ nodeName: 'paragraph',
12
+ tagName: 'p'
13
+ };
14
+ exports.NORMAL_TEXT = NORMAL_TEXT;
15
+ var HEADING_1 = {
16
+ name: 'heading1',
17
+ title: _messages.messages.heading1,
18
+ nodeName: 'heading',
19
+ tagName: 'h1',
20
+ level: 1
21
+ };
22
+ exports.HEADING_1 = HEADING_1;
23
+ var HEADING_2 = {
24
+ name: 'heading2',
25
+ title: _messages.messages.heading2,
26
+ nodeName: 'heading',
27
+ tagName: 'h2',
28
+ level: 2
29
+ };
30
+ exports.HEADING_2 = HEADING_2;
31
+ var HEADING_3 = {
32
+ name: 'heading3',
33
+ title: _messages.messages.heading3,
34
+ nodeName: 'heading',
35
+ tagName: 'h3',
36
+ level: 3
37
+ };
38
+ exports.HEADING_3 = HEADING_3;
39
+ var HEADING_4 = {
40
+ name: 'heading4',
41
+ title: _messages.messages.heading4,
42
+ nodeName: 'heading',
43
+ tagName: 'h4',
44
+ level: 4
45
+ };
46
+ exports.HEADING_4 = HEADING_4;
47
+ var HEADING_5 = {
48
+ name: 'heading5',
49
+ title: _messages.messages.heading5,
50
+ nodeName: 'heading',
51
+ tagName: 'h5',
52
+ level: 5
53
+ };
54
+ exports.HEADING_5 = HEADING_5;
55
+ var HEADING_6 = {
56
+ name: 'heading6',
57
+ title: _messages.messages.heading6,
58
+ nodeName: 'heading',
59
+ tagName: 'h6',
60
+ level: 6
61
+ };
62
+ exports.HEADING_6 = HEADING_6;
63
+ var BLOCK_QUOTE = {
64
+ name: 'blockquote',
65
+ title: _messages.messages.blockquote,
66
+ nodeName: 'blockquote'
67
+ };
68
+ exports.BLOCK_QUOTE = BLOCK_QUOTE;
69
+ var CODE_BLOCK = {
70
+ name: 'codeblock',
71
+ title: _messages.messages.codeblock,
72
+ nodeName: 'codeBlock'
73
+ };
74
+ exports.CODE_BLOCK = CODE_BLOCK;
75
+ var PANEL = {
76
+ name: 'panel',
77
+ title: _messages.messages.infoPanel,
78
+ nodeName: 'panel'
79
+ };
80
+ exports.PANEL = PANEL;
81
+ var OTHER = {
82
+ name: 'other',
83
+ title: _messages.messages.other,
84
+ nodeName: ''
85
+ };
86
+ exports.OTHER = OTHER;
87
+ var TEXT_BLOCK_TYPES = [NORMAL_TEXT, HEADING_1, HEADING_2, HEADING_3, HEADING_4, HEADING_5, HEADING_6];
88
+ exports.TEXT_BLOCK_TYPES = TEXT_BLOCK_TYPES;
89
+ var WRAPPER_BLOCK_TYPES = [BLOCK_QUOTE, CODE_BLOCK, PANEL];
90
+ exports.WRAPPER_BLOCK_TYPES = WRAPPER_BLOCK_TYPES;
91
+ var ALL_BLOCK_TYPES = TEXT_BLOCK_TYPES.concat(WRAPPER_BLOCK_TYPES);
92
+ exports.ALL_BLOCK_TYPES = ALL_BLOCK_TYPES;
93
+ var HEADINGS_BY_LEVEL = TEXT_BLOCK_TYPES.reduce(function (acc, blockType) {
94
+ if (blockType.level && blockType.nodeName === 'heading') {
95
+ acc[blockType.level] = blockType;
96
+ }
97
+ return acc;
98
+ }, {});
99
+ exports.HEADINGS_BY_LEVEL = HEADINGS_BY_LEVEL;
100
+ var HEADINGS_BY_NAME = TEXT_BLOCK_TYPES.reduce(function (acc, blockType) {
101
+ if (blockType.level && blockType.nodeName === 'heading') {
102
+ acc[blockType.name] = blockType;
103
+ }
104
+ return acc;
105
+ }, {});
106
+ exports.HEADINGS_BY_NAME = HEADINGS_BY_NAME;
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.insertBlockQuoteWithAnalytics = exports.cleanUpAtTheStartOfDocument = void 0;
7
+ exports.setBlockType = setBlockType;
8
+ exports.setBlockTypeWithAnalytics = setBlockTypeWithAnalytics;
9
+ exports.setHeadingWithAnalytics = void 0;
10
+ exports.setNormalText = setNormalText;
11
+ exports.setNormalTextWithAnalytics = setNormalTextWithAnalytics;
12
+ var _analytics = require("@atlaskit/editor-common/analytics");
13
+ var _commands = require("@atlaskit/editor-common/commands");
14
+ var _editorAnalytics = require("@atlaskit/editor-common/editor-analytics");
15
+ var _utils = require("@atlaskit/editor-common/utils");
16
+ var _editorTables = require("@atlaskit/editor-tables");
17
+ var _blockTypes = require("../block-types");
18
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
19
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
20
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
21
+ function setBlockType(name) {
22
+ return function (state, dispatch) {
23
+ var nodes = state.schema.nodes;
24
+ if (name === _blockTypes.NORMAL_TEXT.name && nodes.paragraph) {
25
+ return setNormalText()(state, dispatch);
26
+ }
27
+ var headingBlockType = _blockTypes.HEADINGS_BY_NAME[name];
28
+ if (headingBlockType && nodes.heading && headingBlockType.level) {
29
+ return (0, _commands.setHeading)(headingBlockType.level)(state, dispatch);
30
+ }
31
+ return false;
32
+ };
33
+ }
34
+ function setBlockTypeWithAnalytics(name, inputMethod, editorAnalyticsApi) {
35
+ return function (state, dispatch) {
36
+ var nodes = state.schema.nodes;
37
+ if (name === _blockTypes.NORMAL_TEXT.name && nodes.paragraph) {
38
+ return setNormalTextWithAnalytics(inputMethod, editorAnalyticsApi)(state, dispatch);
39
+ }
40
+ var headingBlockType = _blockTypes.HEADINGS_BY_NAME[name];
41
+ if (headingBlockType && nodes.heading && headingBlockType.level) {
42
+ return setHeadingWithAnalytics(headingBlockType.level, inputMethod, editorAnalyticsApi)(state, dispatch);
43
+ }
44
+ return false;
45
+ };
46
+ }
47
+ function setNormalText() {
48
+ return function (state, dispatch) {
49
+ var selection = state.selection,
50
+ schema = state.schema,
51
+ tr = state.tr;
52
+ var ranges = selection instanceof _editorTables.CellSelection ? selection.ranges : [selection];
53
+ ranges.forEach(function (_ref) {
54
+ var $from = _ref.$from,
55
+ $to = _ref.$to;
56
+ tr.setBlockType($from.pos, $to.pos, schema.nodes.paragraph);
57
+ });
58
+ if (dispatch) {
59
+ dispatch(tr);
60
+ }
61
+ return true;
62
+ };
63
+ }
64
+ function withCurrentHeadingLevel(fn) {
65
+ return function (state, dispatch, view) {
66
+ // Find all headings and paragraphs of text
67
+ var _state$schema$nodes = state.schema.nodes,
68
+ heading = _state$schema$nodes.heading,
69
+ paragraph = _state$schema$nodes.paragraph;
70
+ var nodes = (0, _utils.filterChildrenBetween)(state.doc, state.selection.from, state.selection.to, function (node) {
71
+ return node.type === heading || node.type === paragraph;
72
+ });
73
+
74
+ // Check each paragraph and/or heading and check for consistent level
75
+ var level;
76
+ var _iterator = _createForOfIteratorHelper(nodes),
77
+ _step;
78
+ try {
79
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
80
+ var node = _step.value;
81
+ var nodeLevel = node.node.type === heading ? node.node.attrs.level : 0;
82
+ if (!level) {
83
+ level = nodeLevel;
84
+ } else if (nodeLevel !== level) {
85
+ // Conflict in level, therefore inconsistent and undefined
86
+ level = undefined;
87
+ break;
88
+ }
89
+ }
90
+ } catch (err) {
91
+ _iterator.e(err);
92
+ } finally {
93
+ _iterator.f();
94
+ }
95
+ return fn(level)(state, dispatch, view);
96
+ };
97
+ }
98
+ function setNormalTextWithAnalytics(inputMethod, editorAnalyticsApi) {
99
+ return withCurrentHeadingLevel(function (previousHeadingLevel) {
100
+ return (0, _editorAnalytics.withAnalytics)(editorAnalyticsApi, {
101
+ action: _analytics.ACTION.FORMATTED,
102
+ actionSubject: _analytics.ACTION_SUBJECT.TEXT,
103
+ eventType: _analytics.EVENT_TYPE.TRACK,
104
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.FORMAT_HEADING,
105
+ attributes: {
106
+ inputMethod: inputMethod,
107
+ newHeadingLevel: 0,
108
+ previousHeadingLevel: previousHeadingLevel
109
+ }
110
+ })(setNormalText());
111
+ });
112
+ }
113
+ var setHeadingWithAnalytics = function setHeadingWithAnalytics(newHeadingLevel, inputMethod, editorAnalyticsApi) {
114
+ return withCurrentHeadingLevel(function (previousHeadingLevel) {
115
+ return (0, _editorAnalytics.withAnalytics)(editorAnalyticsApi, {
116
+ action: _analytics.ACTION.FORMATTED,
117
+ actionSubject: _analytics.ACTION_SUBJECT.TEXT,
118
+ eventType: _analytics.EVENT_TYPE.TRACK,
119
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.FORMAT_HEADING,
120
+ attributes: {
121
+ inputMethod: inputMethod,
122
+ newHeadingLevel: newHeadingLevel,
123
+ previousHeadingLevel: previousHeadingLevel
124
+ }
125
+ })((0, _commands.setHeading)(newHeadingLevel));
126
+ });
127
+ };
128
+ exports.setHeadingWithAnalytics = setHeadingWithAnalytics;
129
+ function insertBlockQuote() {
130
+ return function (state, dispatch) {
131
+ var nodes = state.schema.nodes;
132
+ if (nodes.paragraph && nodes.blockquote) {
133
+ return (0, _utils.wrapSelectionIn)(nodes.blockquote)(state, dispatch);
134
+ }
135
+ return false;
136
+ };
137
+ }
138
+
139
+ /**
140
+ *
141
+ * @param name - block type name
142
+ * @param inputMethod - input method
143
+ * @param editorAnalyticsApi - analytics api, undefined if not available either because it failed to load or wasn't added
144
+ * otherwise Editor becomes very sad and crashes
145
+ * @returns - command that inserts block type
146
+ */
147
+ var insertBlockQuoteWithAnalytics = function insertBlockQuoteWithAnalytics(inputMethod, editorAnalyticsApi) {
148
+ return (0, _editorAnalytics.withAnalytics)(editorAnalyticsApi, {
149
+ action: _analytics.ACTION.FORMATTED,
150
+ actionSubject: _analytics.ACTION_SUBJECT.TEXT,
151
+ eventType: _analytics.EVENT_TYPE.TRACK,
152
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.FORMAT_BLOCK_QUOTE,
153
+ attributes: {
154
+ inputMethod: inputMethod
155
+ }
156
+ })(insertBlockQuote());
157
+ };
158
+ exports.insertBlockQuoteWithAnalytics = insertBlockQuoteWithAnalytics;
159
+ var cleanUpAtTheStartOfDocument = function cleanUpAtTheStartOfDocument(state, dispatch) {
160
+ var _ref2 = state.selection,
161
+ $cursor = _ref2.$cursor;
162
+ if ($cursor && !$cursor.nodeBefore && !$cursor.nodeAfter && $cursor.pos === 1) {
163
+ var tr = state.tr,
164
+ schema = state.schema;
165
+ var paragraph = schema.nodes.paragraph;
166
+ var parent = $cursor.parent;
167
+
168
+ /**
169
+ * Use cases:
170
+ * 1. Change `heading` to `paragraph`
171
+ * 2. Remove block marks
172
+ *
173
+ * NOTE: We already know it's an empty doc so it's safe to use 0
174
+ */
175
+ tr.setNodeMarkup(0, paragraph, parent.attrs, []);
176
+ if (dispatch) {
177
+ dispatch(tr);
178
+ }
179
+ return true;
180
+ }
181
+ return false;
182
+ };
183
+ exports.cleanUpAtTheStartOfDocument = cleanUpAtTheStartOfDocument;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.deleteAndMoveCursor = void 0;
7
+ var _state = require("@atlaskit/editor-prosemirror/state");
8
+ // We should override default behaviour when selection spans node depths or
9
+ // ends at a node junction
10
+ var shouldMoveCursorAfterDelete = function shouldMoveCursorAfterDelete(state) {
11
+ var _state$selection = state.selection,
12
+ $from = _state$selection.$from,
13
+ $to = _state$selection.$to;
14
+ var nodeRange = $from.blockRange($to);
15
+ if (!nodeRange) {
16
+ return false;
17
+ }
18
+ var hasSameAncestor = $from.depth === $to.depth && $from.depth - 1 === nodeRange.depth;
19
+ var toPositionHasNodeAfter = !!$to.nodeAfter;
20
+ if (hasSameAncestor || toPositionHasNodeAfter) {
21
+ return false;
22
+ }
23
+ return true;
24
+ };
25
+
26
+ /**
27
+ * Fixes cursor position after delete for list/task in panel and table
28
+ *
29
+ * ED-13873 fixes a bug where after deleting a list the cursor would move
30
+ * to the cell to the right. Uses setSelection to position the cursor as expected after deleting.
31
+ *
32
+ * @param state EditorState
33
+ * @param dispatch CommandDispatch
34
+ * @returns boolean
35
+ */
36
+ var deleteAndMoveCursor = function deleteAndMoveCursor(state, dispatch) {
37
+ if (state.selection.empty || !(state.selection instanceof _state.TextSelection)) {
38
+ return false;
39
+ }
40
+ if (!shouldMoveCursorAfterDelete(state)) {
41
+ return false;
42
+ }
43
+ var tr = state.tr;
44
+ tr.deleteSelection();
45
+
46
+ // Make sure the next position is not out of boundaries
47
+ var previousPosition = Math.min(Math.max(state.selection.$from.pos, 0), tr.doc.content.size);
48
+ // Override default delete behaviour that moves the cursor to first suitable position after selection (postive bias).
49
+ // See. selectionToInsertionEnd. We will override behavior with negative bias (search for suitable cursor position backwards).
50
+ tr.setSelection(_state.Selection.near(tr.doc.resolve(previousPosition), -1));
51
+ if (dispatch) {
52
+ dispatch(tr.scrollIntoView());
53
+ }
54
+ return true;
55
+ };
56
+ exports.deleteAndMoveCursor = deleteAndMoveCursor;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.deleteBlockContent = deleteBlockContent;
7
+ /**
8
+ * Prevent removing the block when deleting block content
9
+ *
10
+ * @param state EditorState
11
+ * @param dispatch CommandDispatch
12
+ * @returns boolean
13
+ */
14
+ function deleteBlockContent(isNodeAWrappingBlockNode) {
15
+ return function (state, dispatch) {
16
+ var tr = state.tr,
17
+ _state$selection = state.selection,
18
+ $from = _state$selection.$from,
19
+ $to = _state$selection.$to,
20
+ doc = state.doc;
21
+ if ($from.pos === $to.pos) {
22
+ return false;
23
+ }
24
+ var selectionCrossesWrappingBlockNode = false;
25
+ doc.nodesBetween($from.pos, $to.pos, function (node, pos) {
26
+ // Optimisation. If selection crosses wrapping block node
27
+ // short circuit the loop by returning false
28
+ if (selectionCrossesWrappingBlockNode) {
29
+ return false;
30
+ }
31
+ if (isNodeAWrappingBlockNode(node)) {
32
+ selectionCrossesWrappingBlockNode = true;
33
+ return false;
34
+ }
35
+ });
36
+ if (!selectionCrossesWrappingBlockNode) {
37
+ return false;
38
+ }
39
+ tr.delete($from.pos, $to.pos);
40
+ if (dispatch) {
41
+ dispatch(tr);
42
+ }
43
+ return true;
44
+ };
45
+ }
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "cleanUpAtTheStartOfDocument", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _blockType.cleanUpAtTheStartOfDocument;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "deleteAndMoveCursor", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _deleteAndMoveCursor.deleteAndMoveCursor;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "deleteBlockContent", {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return _deleteBlockContent.deleteBlockContent;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "insertBlockQuoteWithAnalytics", {
25
+ enumerable: true,
26
+ get: function get() {
27
+ return _blockType.insertBlockQuoteWithAnalytics;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "setBlockType", {
31
+ enumerable: true,
32
+ get: function get() {
33
+ return _blockType.setBlockType;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "setBlockTypeWithAnalytics", {
37
+ enumerable: true,
38
+ get: function get() {
39
+ return _blockType.setBlockTypeWithAnalytics;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "setHeading", {
43
+ enumerable: true,
44
+ get: function get() {
45
+ return _commands.setHeading;
46
+ }
47
+ });
48
+ Object.defineProperty(exports, "setHeadingWithAnalytics", {
49
+ enumerable: true,
50
+ get: function get() {
51
+ return _blockType.setHeadingWithAnalytics;
52
+ }
53
+ });
54
+ Object.defineProperty(exports, "setNormalText", {
55
+ enumerable: true,
56
+ get: function get() {
57
+ return _blockType.setNormalText;
58
+ }
59
+ });
60
+ Object.defineProperty(exports, "setNormalTextWithAnalytics", {
61
+ enumerable: true,
62
+ get: function get() {
63
+ return _blockType.setNormalTextWithAnalytics;
64
+ }
65
+ });
66
+ var _blockType = require("./block-type");
67
+ var _deleteAndMoveCursor = require("./delete-and-move-cursor");
68
+ var _deleteBlockContent = require("./delete-block-content");
69
+ var _commands = require("@atlaskit/editor-common/commands");
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.HEADING_KEYS = void 0;
7
+ var KEY_0 = 48;
8
+ var KEY_1 = 49;
9
+ var KEY_2 = 50;
10
+ var KEY_3 = 51;
11
+ var KEY_4 = 52;
12
+ var KEY_5 = 53;
13
+ var KEY_6 = 54;
14
+ var HEADING_KEYS = [KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6];
15
+ exports.HEADING_KEYS = HEADING_KEYS;