@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
@@ -0,0 +1,84 @@
1
+ import { messages } from './messages';
2
+ export var NORMAL_TEXT = {
3
+ name: 'normal',
4
+ title: messages.normal,
5
+ nodeName: 'paragraph',
6
+ tagName: 'p'
7
+ };
8
+ export var HEADING_1 = {
9
+ name: 'heading1',
10
+ title: messages.heading1,
11
+ nodeName: 'heading',
12
+ tagName: 'h1',
13
+ level: 1
14
+ };
15
+ export var HEADING_2 = {
16
+ name: 'heading2',
17
+ title: messages.heading2,
18
+ nodeName: 'heading',
19
+ tagName: 'h2',
20
+ level: 2
21
+ };
22
+ export var HEADING_3 = {
23
+ name: 'heading3',
24
+ title: messages.heading3,
25
+ nodeName: 'heading',
26
+ tagName: 'h3',
27
+ level: 3
28
+ };
29
+ export var HEADING_4 = {
30
+ name: 'heading4',
31
+ title: messages.heading4,
32
+ nodeName: 'heading',
33
+ tagName: 'h4',
34
+ level: 4
35
+ };
36
+ export var HEADING_5 = {
37
+ name: 'heading5',
38
+ title: messages.heading5,
39
+ nodeName: 'heading',
40
+ tagName: 'h5',
41
+ level: 5
42
+ };
43
+ export var HEADING_6 = {
44
+ name: 'heading6',
45
+ title: messages.heading6,
46
+ nodeName: 'heading',
47
+ tagName: 'h6',
48
+ level: 6
49
+ };
50
+ export var BLOCK_QUOTE = {
51
+ name: 'blockquote',
52
+ title: messages.blockquote,
53
+ nodeName: 'blockquote'
54
+ };
55
+ export var CODE_BLOCK = {
56
+ name: 'codeblock',
57
+ title: messages.codeblock,
58
+ nodeName: 'codeBlock'
59
+ };
60
+ export var PANEL = {
61
+ name: 'panel',
62
+ title: messages.infoPanel,
63
+ nodeName: 'panel'
64
+ };
65
+ export var OTHER = {
66
+ name: 'other',
67
+ title: messages.other,
68
+ nodeName: ''
69
+ };
70
+ export var TEXT_BLOCK_TYPES = [NORMAL_TEXT, HEADING_1, HEADING_2, HEADING_3, HEADING_4, HEADING_5, HEADING_6];
71
+ export var WRAPPER_BLOCK_TYPES = [BLOCK_QUOTE, CODE_BLOCK, PANEL];
72
+ export var ALL_BLOCK_TYPES = TEXT_BLOCK_TYPES.concat(WRAPPER_BLOCK_TYPES);
73
+ export var HEADINGS_BY_LEVEL = TEXT_BLOCK_TYPES.reduce(function (acc, blockType) {
74
+ if (blockType.level && blockType.nodeName === 'heading') {
75
+ acc[blockType.level] = blockType;
76
+ }
77
+ return acc;
78
+ }, {});
79
+ export var HEADINGS_BY_NAME = TEXT_BLOCK_TYPES.reduce(function (acc, blockType) {
80
+ if (blockType.level && blockType.nodeName === 'heading') {
81
+ acc[blockType.name] = blockType;
82
+ }
83
+ return acc;
84
+ }, {});
@@ -0,0 +1,169 @@
1
+ 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; } } }; }
2
+ 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); }
3
+ 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; }
4
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
5
+ import { setHeading } from '@atlaskit/editor-common/commands';
6
+ import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
7
+ import { filterChildrenBetween, wrapSelectionIn } from '@atlaskit/editor-common/utils';
8
+ import { CellSelection } from '@atlaskit/editor-tables';
9
+ import { HEADINGS_BY_NAME, NORMAL_TEXT } from '../block-types';
10
+ export function setBlockType(name) {
11
+ return function (state, dispatch) {
12
+ var nodes = state.schema.nodes;
13
+ if (name === NORMAL_TEXT.name && nodes.paragraph) {
14
+ return setNormalText()(state, dispatch);
15
+ }
16
+ var headingBlockType = HEADINGS_BY_NAME[name];
17
+ if (headingBlockType && nodes.heading && headingBlockType.level) {
18
+ return setHeading(headingBlockType.level)(state, dispatch);
19
+ }
20
+ return false;
21
+ };
22
+ }
23
+ export function setBlockTypeWithAnalytics(name, inputMethod, editorAnalyticsApi) {
24
+ return function (state, dispatch) {
25
+ var nodes = state.schema.nodes;
26
+ if (name === NORMAL_TEXT.name && nodes.paragraph) {
27
+ return setNormalTextWithAnalytics(inputMethod, editorAnalyticsApi)(state, dispatch);
28
+ }
29
+ var headingBlockType = HEADINGS_BY_NAME[name];
30
+ if (headingBlockType && nodes.heading && headingBlockType.level) {
31
+ return setHeadingWithAnalytics(headingBlockType.level, inputMethod, editorAnalyticsApi)(state, dispatch);
32
+ }
33
+ return false;
34
+ };
35
+ }
36
+ export function setNormalText() {
37
+ return function (state, dispatch) {
38
+ var selection = state.selection,
39
+ schema = state.schema,
40
+ tr = state.tr;
41
+ var ranges = selection instanceof CellSelection ? selection.ranges : [selection];
42
+ ranges.forEach(function (_ref) {
43
+ var $from = _ref.$from,
44
+ $to = _ref.$to;
45
+ tr.setBlockType($from.pos, $to.pos, schema.nodes.paragraph);
46
+ });
47
+ if (dispatch) {
48
+ dispatch(tr);
49
+ }
50
+ return true;
51
+ };
52
+ }
53
+ function withCurrentHeadingLevel(fn) {
54
+ return function (state, dispatch, view) {
55
+ // Find all headings and paragraphs of text
56
+ var _state$schema$nodes = state.schema.nodes,
57
+ heading = _state$schema$nodes.heading,
58
+ paragraph = _state$schema$nodes.paragraph;
59
+ var nodes = filterChildrenBetween(state.doc, state.selection.from, state.selection.to, function (node) {
60
+ return node.type === heading || node.type === paragraph;
61
+ });
62
+
63
+ // Check each paragraph and/or heading and check for consistent level
64
+ var level;
65
+ var _iterator = _createForOfIteratorHelper(nodes),
66
+ _step;
67
+ try {
68
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
69
+ var node = _step.value;
70
+ var nodeLevel = node.node.type === heading ? node.node.attrs.level : 0;
71
+ if (!level) {
72
+ level = nodeLevel;
73
+ } else if (nodeLevel !== level) {
74
+ // Conflict in level, therefore inconsistent and undefined
75
+ level = undefined;
76
+ break;
77
+ }
78
+ }
79
+ } catch (err) {
80
+ _iterator.e(err);
81
+ } finally {
82
+ _iterator.f();
83
+ }
84
+ return fn(level)(state, dispatch, view);
85
+ };
86
+ }
87
+ export function setNormalTextWithAnalytics(inputMethod, editorAnalyticsApi) {
88
+ return withCurrentHeadingLevel(function (previousHeadingLevel) {
89
+ return withAnalytics(editorAnalyticsApi, {
90
+ action: ACTION.FORMATTED,
91
+ actionSubject: ACTION_SUBJECT.TEXT,
92
+ eventType: EVENT_TYPE.TRACK,
93
+ actionSubjectId: ACTION_SUBJECT_ID.FORMAT_HEADING,
94
+ attributes: {
95
+ inputMethod: inputMethod,
96
+ newHeadingLevel: 0,
97
+ previousHeadingLevel: previousHeadingLevel
98
+ }
99
+ })(setNormalText());
100
+ });
101
+ }
102
+ export var setHeadingWithAnalytics = function setHeadingWithAnalytics(newHeadingLevel, inputMethod, editorAnalyticsApi) {
103
+ return withCurrentHeadingLevel(function (previousHeadingLevel) {
104
+ return withAnalytics(editorAnalyticsApi, {
105
+ action: ACTION.FORMATTED,
106
+ actionSubject: ACTION_SUBJECT.TEXT,
107
+ eventType: EVENT_TYPE.TRACK,
108
+ actionSubjectId: ACTION_SUBJECT_ID.FORMAT_HEADING,
109
+ attributes: {
110
+ inputMethod: inputMethod,
111
+ newHeadingLevel: newHeadingLevel,
112
+ previousHeadingLevel: previousHeadingLevel
113
+ }
114
+ })(setHeading(newHeadingLevel));
115
+ });
116
+ };
117
+ function insertBlockQuote() {
118
+ return function (state, dispatch) {
119
+ var nodes = state.schema.nodes;
120
+ if (nodes.paragraph && nodes.blockquote) {
121
+ return wrapSelectionIn(nodes.blockquote)(state, dispatch);
122
+ }
123
+ return false;
124
+ };
125
+ }
126
+
127
+ /**
128
+ *
129
+ * @param name - block type name
130
+ * @param inputMethod - input method
131
+ * @param editorAnalyticsApi - analytics api, undefined if not available either because it failed to load or wasn't added
132
+ * otherwise Editor becomes very sad and crashes
133
+ * @returns - command that inserts block type
134
+ */
135
+ export var insertBlockQuoteWithAnalytics = function insertBlockQuoteWithAnalytics(inputMethod, editorAnalyticsApi) {
136
+ return withAnalytics(editorAnalyticsApi, {
137
+ action: ACTION.FORMATTED,
138
+ actionSubject: ACTION_SUBJECT.TEXT,
139
+ eventType: EVENT_TYPE.TRACK,
140
+ actionSubjectId: ACTION_SUBJECT_ID.FORMAT_BLOCK_QUOTE,
141
+ attributes: {
142
+ inputMethod: inputMethod
143
+ }
144
+ })(insertBlockQuote());
145
+ };
146
+ export var cleanUpAtTheStartOfDocument = function cleanUpAtTheStartOfDocument(state, dispatch) {
147
+ var _ref2 = state.selection,
148
+ $cursor = _ref2.$cursor;
149
+ if ($cursor && !$cursor.nodeBefore && !$cursor.nodeAfter && $cursor.pos === 1) {
150
+ var tr = state.tr,
151
+ schema = state.schema;
152
+ var paragraph = schema.nodes.paragraph;
153
+ var parent = $cursor.parent;
154
+
155
+ /**
156
+ * Use cases:
157
+ * 1. Change `heading` to `paragraph`
158
+ * 2. Remove block marks
159
+ *
160
+ * NOTE: We already know it's an empty doc so it's safe to use 0
161
+ */
162
+ tr.setNodeMarkup(0, paragraph, parent.attrs, []);
163
+ if (dispatch) {
164
+ dispatch(tr);
165
+ }
166
+ return true;
167
+ }
168
+ return false;
169
+ };
@@ -0,0 +1,50 @@
1
+ import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
2
+
3
+ // We should override default behaviour when selection spans node depths or
4
+ // ends at a node junction
5
+ var shouldMoveCursorAfterDelete = function shouldMoveCursorAfterDelete(state) {
6
+ var _state$selection = state.selection,
7
+ $from = _state$selection.$from,
8
+ $to = _state$selection.$to;
9
+ var nodeRange = $from.blockRange($to);
10
+ if (!nodeRange) {
11
+ return false;
12
+ }
13
+ var hasSameAncestor = $from.depth === $to.depth && $from.depth - 1 === nodeRange.depth;
14
+ var toPositionHasNodeAfter = !!$to.nodeAfter;
15
+ if (hasSameAncestor || toPositionHasNodeAfter) {
16
+ return false;
17
+ }
18
+ return true;
19
+ };
20
+
21
+ /**
22
+ * Fixes cursor position after delete for list/task in panel and table
23
+ *
24
+ * ED-13873 fixes a bug where after deleting a list the cursor would move
25
+ * to the cell to the right. Uses setSelection to position the cursor as expected after deleting.
26
+ *
27
+ * @param state EditorState
28
+ * @param dispatch CommandDispatch
29
+ * @returns boolean
30
+ */
31
+ export var deleteAndMoveCursor = function deleteAndMoveCursor(state, dispatch) {
32
+ if (state.selection.empty || !(state.selection instanceof TextSelection)) {
33
+ return false;
34
+ }
35
+ if (!shouldMoveCursorAfterDelete(state)) {
36
+ return false;
37
+ }
38
+ var tr = state.tr;
39
+ tr.deleteSelection();
40
+
41
+ // Make sure the next position is not out of boundaries
42
+ var previousPosition = Math.min(Math.max(state.selection.$from.pos, 0), tr.doc.content.size);
43
+ // Override default delete behaviour that moves the cursor to first suitable position after selection (postive bias).
44
+ // See. selectionToInsertionEnd. We will override behavior with negative bias (search for suitable cursor position backwards).
45
+ tr.setSelection(Selection.near(tr.doc.resolve(previousPosition), -1));
46
+ if (dispatch) {
47
+ dispatch(tr.scrollIntoView());
48
+ }
49
+ return true;
50
+ };
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Prevent removing the block when deleting block content
3
+ *
4
+ * @param state EditorState
5
+ * @param dispatch CommandDispatch
6
+ * @returns boolean
7
+ */
8
+ export function deleteBlockContent(isNodeAWrappingBlockNode) {
9
+ return function (state, dispatch) {
10
+ var tr = state.tr,
11
+ _state$selection = state.selection,
12
+ $from = _state$selection.$from,
13
+ $to = _state$selection.$to,
14
+ doc = state.doc;
15
+ if ($from.pos === $to.pos) {
16
+ return false;
17
+ }
18
+ var selectionCrossesWrappingBlockNode = false;
19
+ doc.nodesBetween($from.pos, $to.pos, function (node, pos) {
20
+ // Optimisation. If selection crosses wrapping block node
21
+ // short circuit the loop by returning false
22
+ if (selectionCrossesWrappingBlockNode) {
23
+ return false;
24
+ }
25
+ if (isNodeAWrappingBlockNode(node)) {
26
+ selectionCrossesWrappingBlockNode = true;
27
+ return false;
28
+ }
29
+ });
30
+ if (!selectionCrossesWrappingBlockNode) {
31
+ return false;
32
+ }
33
+ tr.delete($from.pos, $to.pos);
34
+ if (dispatch) {
35
+ dispatch(tr);
36
+ }
37
+ return true;
38
+ };
39
+ }
@@ -0,0 +1,8 @@
1
+ export { cleanUpAtTheStartOfDocument, insertBlockQuoteWithAnalytics, setBlockType, setBlockTypeWithAnalytics, setHeadingWithAnalytics, setNormalText, setNormalTextWithAnalytics } from './block-type';
2
+ export { deleteAndMoveCursor } from './delete-and-move-cursor';
3
+ export { deleteBlockContent } from './delete-block-content';
4
+ /**
5
+ * @private
6
+ * @deprecated use import from @atlaskit/editor-common/commands
7
+ */
8
+ export { setHeading } from '@atlaskit/editor-common/commands';
@@ -0,0 +1,8 @@
1
+ var KEY_0 = 48;
2
+ var KEY_1 = 49;
3
+ var KEY_2 = 50;
4
+ var KEY_3 = 51;
5
+ var KEY_4 = 52;
6
+ var KEY_5 = 53;
7
+ var KEY_6 = 54;
8
+ export var HEADING_KEYS = [KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6];
@@ -0,0 +1,205 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import React from 'react';
3
+ import { blockquote, hardBreak, heading } from '@atlaskit/adf-schema';
4
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
5
+ import { keymap, toggleBlockQuote, tooltip } from '@atlaskit/editor-common/keymaps';
6
+ import { IconHeading, IconQuote } from '@atlaskit/editor-common/quick-insert';
7
+ import { ToolbarSize } from '@atlaskit/editor-common/types';
8
+ import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
9
+ import { setBlockTypeWithAnalytics } from './commands';
10
+ import { insertBlockQuoteWithAnalytics } from './commands/block-type';
11
+ import { messages } from './messages';
12
+ import inputRulePlugin from './pm-plugins/input-rule';
13
+ import keymapPlugin from './pm-plugins/keymap';
14
+ import { createPlugin, pluginKey } from './pm-plugins/main';
15
+ import ToolbarBlockType from './ui/ToolbarBlockType';
16
+ var headingPluginOptions = function headingPluginOptions(_ref, isAllowed, editorAnalyticsApi) {
17
+ var formatMessage = _ref.formatMessage;
18
+ if (!isAllowed) {
19
+ return [];
20
+ }
21
+ return Array.from({
22
+ length: 6
23
+ }, function (_v, idx) {
24
+ var level = idx + 1;
25
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
+ var descriptionDescriptor = messages["heading".concat(level, "Description")];
27
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
+ var keyshortcut = tooltip(keymap["toggleHeading".concat(level)]);
29
+ var id = "heading".concat(level);
30
+ return {
31
+ id: id,
32
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
+ title: formatMessage(messages[id]),
34
+ description: formatMessage(descriptionDescriptor),
35
+ priority: 1300,
36
+ keywords: ["h".concat(level)],
37
+ keyshortcut: keyshortcut,
38
+ icon: function icon() {
39
+ return /*#__PURE__*/React.createElement(IconHeading, {
40
+ level: level
41
+ });
42
+ },
43
+ action: function action(insert, state) {
44
+ var tr = insert(state.schema.nodes.heading.createChecked({
45
+ level: level
46
+ }));
47
+ editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent({
48
+ action: ACTION.FORMATTED,
49
+ actionSubject: ACTION_SUBJECT.TEXT,
50
+ eventType: EVENT_TYPE.TRACK,
51
+ actionSubjectId: ACTION_SUBJECT_ID.FORMAT_HEADING,
52
+ attributes: {
53
+ inputMethod: INPUT_METHOD.QUICK_INSERT,
54
+ newHeadingLevel: level
55
+ }
56
+ })(tr);
57
+ return tr;
58
+ }
59
+ };
60
+ });
61
+ };
62
+ var blockquotePluginOptions = function blockquotePluginOptions(_ref2, isAllowed, editorAnalyticsApi) {
63
+ var formatMessage = _ref2.formatMessage;
64
+ if (!isAllowed) {
65
+ return [];
66
+ }
67
+ return [{
68
+ id: 'blockquote',
69
+ title: formatMessage(messages.blockquote),
70
+ description: formatMessage(messages.blockquoteDescription),
71
+ priority: 1300,
72
+ keyshortcut: tooltip(toggleBlockQuote),
73
+ icon: function icon() {
74
+ return /*#__PURE__*/React.createElement(IconQuote, null);
75
+ },
76
+ action: function action(insert, state) {
77
+ var tr = insert(state.schema.nodes.blockquote.createChecked({}, state.schema.nodes.paragraph.createChecked()));
78
+ editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent({
79
+ action: ACTION.FORMATTED,
80
+ actionSubject: ACTION_SUBJECT.TEXT,
81
+ eventType: EVENT_TYPE.TRACK,
82
+ actionSubjectId: ACTION_SUBJECT_ID.FORMAT_BLOCK_QUOTE,
83
+ attributes: {
84
+ inputMethod: INPUT_METHOD.QUICK_INSERT
85
+ }
86
+ })(tr);
87
+ return tr;
88
+ }
89
+ }];
90
+ };
91
+ var blockTypePlugin = function blockTypePlugin(_ref3) {
92
+ var options = _ref3.config,
93
+ api = _ref3.api;
94
+ return {
95
+ name: 'blockType',
96
+ nodes: function nodes() {
97
+ var nodes = [{
98
+ name: 'heading',
99
+ node: heading
100
+ }, {
101
+ name: 'blockquote',
102
+ node: blockquote
103
+ }, {
104
+ name: 'hardBreak',
105
+ node: hardBreak
106
+ }];
107
+ if (options && options.allowBlockType) {
108
+ var exclude = options.allowBlockType.exclude ? options.allowBlockType.exclude : [];
109
+ return nodes.filter(function (node) {
110
+ return exclude.indexOf(node.name) === -1;
111
+ });
112
+ }
113
+ return nodes;
114
+ },
115
+ pmPlugins: function pmPlugins() {
116
+ return [{
117
+ name: 'blockType',
118
+ plugin: function plugin(_ref4) {
119
+ var _api$analytics;
120
+ var dispatch = _ref4.dispatch;
121
+ return createPlugin(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, dispatch, options && options.lastNodeMustBeParagraph);
122
+ }
123
+ }, {
124
+ name: 'blockTypeInputRule',
125
+ plugin: function plugin(_ref5) {
126
+ var _api$analytics2;
127
+ var schema = _ref5.schema,
128
+ featureFlags = _ref5.featureFlags;
129
+ return inputRulePlugin(api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, schema, featureFlags);
130
+ }
131
+ },
132
+ // Needs to be lower priority than editor-tables.tableEditing
133
+ // plugin as it is currently swallowing right/down arrow events inside tables
134
+ {
135
+ name: 'blockTypeKeyMap',
136
+ plugin: function plugin(_ref6) {
137
+ var _api$analytics3;
138
+ var schema = _ref6.schema,
139
+ featureFlags = _ref6.featureFlags;
140
+ return keymapPlugin(api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions, schema, featureFlags);
141
+ }
142
+ }];
143
+ },
144
+ actions: {
145
+ insertBlockQuote: function insertBlockQuote(inputMethod) {
146
+ var _api$analytics4;
147
+ return insertBlockQuoteWithAnalytics(inputMethod, api === null || api === void 0 ? void 0 : (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions);
148
+ },
149
+ setBlockType: function setBlockType(name, inputMethod) {
150
+ var _api$analytics5;
151
+ return setBlockTypeWithAnalytics(name, inputMethod, api === null || api === void 0 ? void 0 : (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions);
152
+ }
153
+ },
154
+ getSharedState: function getSharedState(editorState) {
155
+ if (!editorState) {
156
+ return;
157
+ }
158
+ return pluginKey.getState(editorState);
159
+ },
160
+ primaryToolbarComponent: function primaryToolbarComponent(_ref7) {
161
+ var editorView = _ref7.editorView,
162
+ popupsMountPoint = _ref7.popupsMountPoint,
163
+ popupsBoundariesElement = _ref7.popupsBoundariesElement,
164
+ popupsScrollableElement = _ref7.popupsScrollableElement,
165
+ toolbarSize = _ref7.toolbarSize,
166
+ disabled = _ref7.disabled,
167
+ isToolbarReducedSpacing = _ref7.isToolbarReducedSpacing,
168
+ eventDispatcher = _ref7.eventDispatcher;
169
+ var isSmall = options && options.isUndoRedoButtonsEnabled ? toolbarSize < ToolbarSize.XXL : toolbarSize < ToolbarSize.XL;
170
+ var boundSetBlockType = function boundSetBlockType(name) {
171
+ var _api$analytics6;
172
+ return setBlockTypeWithAnalytics(name, INPUT_METHOD.TOOLBAR, api === null || api === void 0 ? void 0 : (_api$analytics6 = api.analytics) === null || _api$analytics6 === void 0 ? void 0 : _api$analytics6.actions)(editorView.state, editorView.dispatch);
173
+ };
174
+ return /*#__PURE__*/React.createElement(WithPluginState, {
175
+ editorView: editorView,
176
+ eventDispatcher: eventDispatcher,
177
+ plugins: {
178
+ pluginState: pluginKey
179
+ },
180
+ render: function render(_ref8) {
181
+ var pluginState = _ref8.pluginState;
182
+ return /*#__PURE__*/React.createElement(ToolbarBlockType, {
183
+ isSmall: isSmall,
184
+ isDisabled: disabled,
185
+ isReducedSpacing: isToolbarReducedSpacing,
186
+ setBlockType: boundSetBlockType,
187
+ pluginState: pluginState,
188
+ popupsMountPoint: popupsMountPoint,
189
+ popupsBoundariesElement: popupsBoundariesElement,
190
+ popupsScrollableElement: popupsScrollableElement
191
+ });
192
+ }
193
+ });
194
+ },
195
+ pluginsOptions: {
196
+ quickInsert: function quickInsert(intl) {
197
+ var _api$analytics7, _api$analytics8;
198
+ var exclude = options && options.allowBlockType && options.allowBlockType.exclude ? options.allowBlockType.exclude : [];
199
+ return [].concat(_toConsumableArray(blockquotePluginOptions(intl, exclude.indexOf('blockquote') === -1, api === null || api === void 0 ? void 0 : (_api$analytics7 = api.analytics) === null || _api$analytics7 === void 0 ? void 0 : _api$analytics7.actions)), _toConsumableArray(headingPluginOptions(intl, exclude.indexOf('heading') === -1, api === null || api === void 0 ? void 0 : (_api$analytics8 = api.analytics) === null || _api$analytics8 === void 0 ? void 0 : _api$analytics8.actions)));
200
+ }
201
+ }
202
+ };
203
+ };
204
+ export { blockTypePlugin };
205
+ export { pluginKey } from './pm-plugins/main';