@atlaskit/editor-plugin-block-type 2.0.0 → 3.0.1

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 (36) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/dist/cjs/i18n/nl.js +6 -6
  3. package/dist/cjs/plugin/commands/block-type.js +91 -53
  4. package/dist/cjs/plugin/commands/index.js +1 -8
  5. package/dist/cjs/plugin/index.js +17 -16
  6. package/dist/cjs/plugin/pm-plugins/main.js +10 -8
  7. package/dist/cjs/plugin/ui/ToolbarBlockType/index.js +1 -1
  8. package/dist/es2019/i18n/nl.js +6 -6
  9. package/dist/es2019/plugin/commands/block-type.js +101 -46
  10. package/dist/es2019/plugin/commands/index.js +1 -6
  11. package/dist/es2019/plugin/index.js +17 -18
  12. package/dist/es2019/plugin/pm-plugins/main.js +10 -8
  13. package/dist/es2019/plugin/ui/ToolbarBlockType/index.js +1 -1
  14. package/dist/esm/i18n/nl.js +6 -6
  15. package/dist/esm/plugin/commands/block-type.js +90 -53
  16. package/dist/esm/plugin/commands/index.js +1 -6
  17. package/dist/esm/plugin/index.js +17 -16
  18. package/dist/esm/plugin/pm-plugins/main.js +10 -8
  19. package/dist/esm/plugin/ui/ToolbarBlockType/index.js +1 -1
  20. package/dist/types/index.d.ts +1 -0
  21. package/dist/types/plugin/block-types.d.ts +1 -0
  22. package/dist/types/plugin/commands/block-type.d.ts +8 -6
  23. package/dist/types/plugin/commands/index.d.ts +0 -5
  24. package/dist/types/plugin/index.d.ts +5 -2
  25. package/dist/types/plugin/pm-plugins/main.d.ts +3 -2
  26. package/dist/types/plugin/ui/ToolbarBlockType/index.d.ts +2 -1
  27. package/dist/types-ts4.5/index.d.ts +1 -0
  28. package/dist/types-ts4.5/plugin/block-types.d.ts +1 -0
  29. package/dist/types-ts4.5/plugin/commands/block-type.d.ts +8 -6
  30. package/dist/types-ts4.5/plugin/commands/index.d.ts +0 -5
  31. package/dist/types-ts4.5/plugin/index.d.ts +5 -2
  32. package/dist/types-ts4.5/plugin/pm-plugins/main.d.ts +3 -2
  33. package/dist/types-ts4.5/plugin/ui/ToolbarBlockType/index.d.ts +2 -1
  34. package/package.json +4 -4
  35. package/report.api.md +17 -1
  36. package/tmp/api-report-tmp.d.ts +7 -1
@@ -1,8 +1,3 @@
1
1
  export { cleanUpAtTheStartOfDocument, insertBlockQuoteWithAnalytics, setBlockType, setBlockTypeWithAnalytics, setHeadingWithAnalytics, setNormalText, setNormalTextWithAnalytics } from './block-type';
2
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';
3
+ export { deleteBlockContent } from './delete-block-content';
@@ -112,18 +112,15 @@ const blockTypePlugin = ({
112
112
  name: 'blockType',
113
113
  plugin: ({
114
114
  dispatch
115
- }) => {
116
- var _api$analytics;
117
- 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);
118
- }
115
+ }) => createPlugin(api, dispatch, options && options.lastNodeMustBeParagraph)
119
116
  }, {
120
117
  name: 'blockTypeInputRule',
121
118
  plugin: ({
122
119
  schema,
123
120
  featureFlags
124
121
  }) => {
125
- var _api$analytics2;
126
- 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);
122
+ var _api$analytics;
123
+ return inputRulePlugin(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, schema, featureFlags);
127
124
  }
128
125
  },
129
126
  // Needs to be lower priority than editor-tables.tableEditing
@@ -134,19 +131,21 @@ const blockTypePlugin = ({
134
131
  schema,
135
132
  featureFlags
136
133
  }) => {
137
- var _api$analytics3;
138
- 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);
134
+ var _api$analytics2;
135
+ return keymapPlugin(api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, schema, featureFlags);
139
136
  }
140
137
  }];
141
138
  },
142
139
  actions: {
143
140
  insertBlockQuote(inputMethod) {
141
+ var _api$analytics3;
142
+ return insertBlockQuoteWithAnalytics(inputMethod, api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions);
143
+ }
144
+ },
145
+ commands: {
146
+ setTextLevel(level, inputMethod) {
144
147
  var _api$analytics4;
145
- return insertBlockQuoteWithAnalytics(inputMethod, api === null || api === void 0 ? void 0 : (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions);
146
- },
147
- setBlockType(name, inputMethod) {
148
- var _api$analytics5;
149
- 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);
148
+ return setBlockTypeWithAnalytics(level, inputMethod, api === null || api === void 0 ? void 0 : (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions);
150
149
  }
151
150
  },
152
151
  getSharedState(editorState) {
@@ -167,8 +166,8 @@ const blockTypePlugin = ({
167
166
  }) {
168
167
  const isSmall = options && options.isUndoRedoButtonsEnabled ? toolbarSize < ToolbarSize.XXL : toolbarSize < ToolbarSize.XL;
169
168
  const boundSetBlockType = name => {
170
- var _api$analytics6;
171
- 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);
169
+ var _api$analytics5;
170
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(setBlockTypeWithAnalytics(name, INPUT_METHOD.TOOLBAR, api === null || api === void 0 ? void 0 : (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions));
172
171
  };
173
172
  return /*#__PURE__*/React.createElement(WithPluginState, {
174
173
  editorView: editorView,
@@ -183,7 +182,7 @@ const blockTypePlugin = ({
183
182
  isSmall: isSmall,
184
183
  isDisabled: disabled,
185
184
  isReducedSpacing: isToolbarReducedSpacing,
186
- setBlockType: boundSetBlockType,
185
+ setTextLevel: boundSetBlockType,
187
186
  pluginState: pluginState,
188
187
  popupsMountPoint: popupsMountPoint,
189
188
  popupsBoundariesElement: popupsBoundariesElement,
@@ -194,9 +193,9 @@ const blockTypePlugin = ({
194
193
  },
195
194
  pluginsOptions: {
196
195
  quickInsert: intl => {
197
- var _api$analytics7, _api$analytics8;
196
+ var _api$analytics6, _api$analytics7;
198
197
  const exclude = options && options.allowBlockType && options.allowBlockType.exclude ? options.allowBlockType.exclude : [];
199
- return [...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), ...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)];
198
+ return [...blockquotePluginOptions(intl, exclude.indexOf('blockquote') === -1, api === null || api === void 0 ? void 0 : (_api$analytics6 = api.analytics) === null || _api$analytics6 === void 0 ? void 0 : _api$analytics6.actions), ...headingPluginOptions(intl, exclude.indexOf('heading') === -1, api === null || api === void 0 ? void 0 : (_api$analytics7 = api.analytics) === null || _api$analytics7 === void 0 ? void 0 : _api$analytics7.actions)];
200
199
  }
201
200
  }
202
201
  });
@@ -59,16 +59,16 @@ const detectBlockType = (availableBlockTypes, state) => {
59
59
  });
60
60
  return blockType || OTHER;
61
61
  };
62
- const autoformatHeading = (headingLevel, view, editorAnalyticsApi) => {
62
+ const autoformatHeading = (headingLevel, editorAnalyticsApi) => {
63
63
  if (headingLevel === 0) {
64
- setNormalTextWithAnalytics(INPUT_METHOD.FORMATTING, editorAnalyticsApi)(view.state, view.dispatch);
65
- } else {
66
- setHeadingWithAnalytics(headingLevel, INPUT_METHOD.FORMATTING, editorAnalyticsApi)(view.state, view.dispatch);
64
+ return setNormalTextWithAnalytics(INPUT_METHOD.FORMATTING, editorAnalyticsApi);
67
65
  }
68
- return true;
66
+ return setHeadingWithAnalytics(headingLevel, INPUT_METHOD.FORMATTING, editorAnalyticsApi);
69
67
  };
70
68
  export const pluginKey = new PluginKey('blockTypePlugin');
71
- export const createPlugin = (editorAnalyticsApi, dispatch, lastNodeMustBeParagraph) => {
69
+ export const createPlugin = (editorAPI, dispatch, lastNodeMustBeParagraph) => {
70
+ var _editorAPI$analytics;
71
+ const editorAnalyticsApi = editorAPI === null || editorAPI === void 0 ? void 0 : (_editorAPI$analytics = editorAPI.analytics) === null || _editorAPI$analytics === void 0 ? void 0 : _editorAPI$analytics.actions;
72
72
  let altKeyLocation = 0;
73
73
  return new SafePlugin({
74
74
  appendTransaction(_transactions, _oldState, newState) {
@@ -118,9 +118,11 @@ export const createPlugin = (editorAnalyticsApi, dispatch, lastNodeMustBeParagra
118
118
  const headingLevel = HEADING_KEYS.indexOf(event.keyCode);
119
119
  if (headingLevel > -1 && event.altKey) {
120
120
  if (browser.mac && event.metaKey) {
121
- return autoformatHeading(headingLevel, view, editorAnalyticsApi);
121
+ var _editorAPI$core$actio;
122
+ return (_editorAPI$core$actio = editorAPI === null || editorAPI === void 0 ? void 0 : editorAPI.core.actions.execute(autoformatHeading(headingLevel, editorAnalyticsApi))) !== null && _editorAPI$core$actio !== void 0 ? _editorAPI$core$actio : false;
122
123
  } else if (!browser.mac && event.ctrlKey && altKeyLocation !== event.DOM_KEY_LOCATION_RIGHT) {
123
- return autoformatHeading(headingLevel, view, editorAnalyticsApi);
124
+ var _editorAPI$core$actio2;
125
+ return (_editorAPI$core$actio2 = editorAPI === null || editorAPI === void 0 ? void 0 : editorAPI.core.actions.execute(autoformatHeading(headingLevel, editorAnalyticsApi))) !== null && _editorAPI$core$actio2 !== void 0 ? _editorAPI$core$actio2 : false;
124
126
  }
125
127
  } else if (event.key === 'Alt') {
126
128
  // event.location is for the current key only; when a user hits Ctrl-Alt-1 the
@@ -83,7 +83,7 @@ class ToolbarBlockType extends React.PureComponent {
83
83
  shouldCloseMenu = true
84
84
  }) => {
85
85
  const blockType = item.value;
86
- this.props.setBlockType(blockType.name);
86
+ this.props.setTextLevel(blockType.name);
87
87
  if (shouldCloseMenu) {
88
88
  this.setState({
89
89
  ...this.state,
@@ -16,17 +16,17 @@ export default {
16
16
  'fabric.editor.errorPanel': 'Foutpaneel',
17
17
  'fabric.editor.errorPanel.description': 'Bijschrift voor fouten maken in een gekleurd paneel',
18
18
  'fabric.editor.heading1': 'Koptekst 1',
19
- 'fabric.editor.heading1Description': 'Dit gebruiken voor een kop op het hoogste niveau',
19
+ 'fabric.editor.heading1Description': 'Gebruik dit voor een kop op het hoogste niveau',
20
20
  'fabric.editor.heading2': 'Koptekst 2',
21
- 'fabric.editor.heading2Description': 'Dit gebruiken voor belangrijke gedeelten',
21
+ 'fabric.editor.heading2Description': 'Gebruik dit voor belangrijke gedeelten',
22
22
  'fabric.editor.heading3': 'Koptekst 3',
23
- 'fabric.editor.heading3Description': 'Dit gebruiken voor subsecties en groepskoppen',
23
+ 'fabric.editor.heading3Description': 'Gebruik dit voor subsecties en groepskoppen',
24
24
  'fabric.editor.heading4': 'Koptekst 4',
25
- 'fabric.editor.heading4Description': 'Dit gebruiken voor diepe koppen',
25
+ 'fabric.editor.heading4Description': 'Gebruik dit voor diepe koppen',
26
26
  'fabric.editor.heading5': 'Koptekst 5',
27
- 'fabric.editor.heading5Description': 'Dit gebruiken voor het groeperen van lijstitems',
27
+ 'fabric.editor.heading5Description': 'Gebruik dit voor het groeperen van lijstitems',
28
28
  'fabric.editor.heading6': 'Koptekst 6',
29
- 'fabric.editor.heading6Description': 'Dit gebruiken voor koppen op laag niveau',
29
+ 'fabric.editor.heading6Description': 'Gebruik dit voor koppen op laag niveau',
30
30
  'fabric.editor.infoPanel': 'Infopaneel',
31
31
  'fabric.editor.infoPanel.description': 'Informatie markeren in een gekleurd paneel',
32
32
  'fabric.editor.normal': 'Normale tekst',
@@ -2,61 +2,84 @@ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol
2
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
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
4
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
5
- import { setHeading } from '@atlaskit/editor-common/commands';
6
5
  import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
7
6
  import { filterChildrenBetween, wrapSelectionIn } from '@atlaskit/editor-common/utils';
8
7
  import { CellSelection } from '@atlaskit/editor-tables';
9
8
  import { HEADINGS_BY_NAME, NORMAL_TEXT } from '../block-types';
10
9
  export function setBlockType(name) {
11
- return function (state, dispatch) {
12
- var nodes = state.schema.nodes;
10
+ return function (_ref) {
11
+ var tr = _ref.tr;
12
+ var nodes = tr.doc.type.schema.nodes;
13
13
  if (name === NORMAL_TEXT.name && nodes.paragraph) {
14
- return setNormalText()(state, dispatch);
14
+ return setNormalText()({
15
+ tr: tr
16
+ });
15
17
  }
16
18
  var headingBlockType = HEADINGS_BY_NAME[name];
17
19
  if (headingBlockType && nodes.heading && headingBlockType.level) {
18
- return setHeading(headingBlockType.level)(state, dispatch);
20
+ return setHeading(headingBlockType.level)({
21
+ tr: tr
22
+ });
19
23
  }
20
- return false;
24
+ return null;
25
+ };
26
+ }
27
+ export function setHeading(level) {
28
+ return function (_ref2) {
29
+ var tr = _ref2.tr;
30
+ var selection = tr.selection,
31
+ schema = tr.doc.type.schema;
32
+ var ranges = selection instanceof CellSelection ? selection.ranges : [selection];
33
+ ranges.forEach(function (_ref3) {
34
+ var $from = _ref3.$from,
35
+ $to = _ref3.$to;
36
+ tr.setBlockType($from.pos, $to.pos, schema.nodes.heading, {
37
+ level: level
38
+ });
39
+ });
40
+ return tr;
21
41
  };
22
42
  }
23
43
  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);
44
+ return function (_ref4) {
45
+ var tr = _ref4.tr;
46
+ var nodes = tr.doc.type.schema.nodes;
47
+ if (name === 'normal' && nodes.paragraph) {
48
+ return setNormalTextWithAnalytics(inputMethod, editorAnalyticsApi)({
49
+ tr: tr
50
+ });
28
51
  }
29
52
  var headingBlockType = HEADINGS_BY_NAME[name];
30
53
  if (headingBlockType && nodes.heading && headingBlockType.level) {
31
- return setHeadingWithAnalytics(headingBlockType.level, inputMethod, editorAnalyticsApi)(state, dispatch);
54
+ return setHeadingWithAnalytics(headingBlockType.level, inputMethod, editorAnalyticsApi)({
55
+ tr: tr
56
+ });
32
57
  }
33
- return false;
58
+ return null;
34
59
  };
35
60
  }
36
61
  export function setNormalText() {
37
- return function (state, dispatch) {
38
- var selection = state.selection,
39
- schema = state.schema,
40
- tr = state.tr;
62
+ return function (_ref5) {
63
+ var tr = _ref5.tr;
64
+ var selection = tr.selection,
65
+ schema = tr.doc.type.schema;
41
66
  var ranges = selection instanceof CellSelection ? selection.ranges : [selection];
42
- ranges.forEach(function (_ref) {
43
- var $from = _ref.$from,
44
- $to = _ref.$to;
67
+ ranges.forEach(function (_ref6) {
68
+ var $from = _ref6.$from,
69
+ $to = _ref6.$to;
45
70
  tr.setBlockType($from.pos, $to.pos, schema.nodes.paragraph);
46
71
  });
47
- if (dispatch) {
48
- dispatch(tr);
49
- }
50
- return true;
72
+ return tr;
51
73
  };
52
74
  }
53
75
  function withCurrentHeadingLevel(fn) {
54
- return function (state, dispatch, view) {
76
+ return function (_ref7) {
77
+ var tr = _ref7.tr;
55
78
  // 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) {
79
+ var _tr$doc$type$schema$n = tr.doc.type.schema.nodes,
80
+ heading = _tr$doc$type$schema$n.heading,
81
+ paragraph = _tr$doc$type$schema$n.paragraph;
82
+ var nodes = filterChildrenBetween(tr.doc, tr.selection.from, tr.selection.to, function (node) {
60
83
  return node.type === heading || node.type === paragraph;
61
84
  });
62
85
 
@@ -81,37 +104,51 @@ function withCurrentHeadingLevel(fn) {
81
104
  } finally {
82
105
  _iterator.f();
83
106
  }
84
- return fn(level)(state, dispatch, view);
107
+ return fn(level)({
108
+ tr: tr
109
+ });
85
110
  };
86
111
  }
87
112
  export function setNormalTextWithAnalytics(inputMethod, editorAnalyticsApi) {
88
113
  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());
114
+ return function (_ref8) {
115
+ var tr = _ref8.tr;
116
+ editorAnalyticsApi === null || editorAnalyticsApi === void 0 || editorAnalyticsApi.attachAnalyticsEvent({
117
+ action: ACTION.FORMATTED,
118
+ actionSubject: ACTION_SUBJECT.TEXT,
119
+ eventType: EVENT_TYPE.TRACK,
120
+ actionSubjectId: ACTION_SUBJECT_ID.FORMAT_HEADING,
121
+ attributes: {
122
+ inputMethod: inputMethod,
123
+ newHeadingLevel: 0,
124
+ previousHeadingLevel: previousHeadingLevel
125
+ }
126
+ })(tr);
127
+ return setNormalText()({
128
+ tr: tr
129
+ });
130
+ };
100
131
  });
101
132
  }
102
133
  export var setHeadingWithAnalytics = function setHeadingWithAnalytics(newHeadingLevel, inputMethod, editorAnalyticsApi) {
103
134
  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));
135
+ return function (_ref9) {
136
+ var tr = _ref9.tr;
137
+ editorAnalyticsApi === null || editorAnalyticsApi === void 0 || editorAnalyticsApi.attachAnalyticsEvent({
138
+ action: ACTION.FORMATTED,
139
+ actionSubject: ACTION_SUBJECT.TEXT,
140
+ eventType: EVENT_TYPE.TRACK,
141
+ actionSubjectId: ACTION_SUBJECT_ID.FORMAT_HEADING,
142
+ attributes: {
143
+ inputMethod: inputMethod,
144
+ newHeadingLevel: newHeadingLevel,
145
+ previousHeadingLevel: previousHeadingLevel
146
+ }
147
+ })(tr);
148
+ return setHeading(newHeadingLevel)({
149
+ tr: tr
150
+ });
151
+ };
115
152
  });
116
153
  };
117
154
  function insertBlockQuote() {
@@ -144,8 +181,8 @@ export var insertBlockQuoteWithAnalytics = function insertBlockQuoteWithAnalytic
144
181
  })(insertBlockQuote());
145
182
  };
146
183
  export var cleanUpAtTheStartOfDocument = function cleanUpAtTheStartOfDocument(state, dispatch) {
147
- var _ref2 = state.selection,
148
- $cursor = _ref2.$cursor;
184
+ var _ref10 = state.selection,
185
+ $cursor = _ref10.$cursor;
149
186
  if ($cursor && !$cursor.nodeBefore && !$cursor.nodeAfter && $cursor.pos === 1) {
150
187
  var tr = state.tr,
151
188
  schema = state.schema;
@@ -1,8 +1,3 @@
1
1
  export { cleanUpAtTheStartOfDocument, insertBlockQuoteWithAnalytics, setBlockType, setBlockTypeWithAnalytics, setHeadingWithAnalytics, setNormalText, setNormalTextWithAnalytics } from './block-type';
2
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';
3
+ export { deleteBlockContent } from './delete-block-content';
@@ -116,17 +116,16 @@ var blockTypePlugin = function blockTypePlugin(_ref3) {
116
116
  return [{
117
117
  name: 'blockType',
118
118
  plugin: function plugin(_ref4) {
119
- var _api$analytics;
120
119
  var dispatch = _ref4.dispatch;
121
- return createPlugin(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, dispatch, options && options.lastNodeMustBeParagraph);
120
+ return createPlugin(api, dispatch, options && options.lastNodeMustBeParagraph);
122
121
  }
123
122
  }, {
124
123
  name: 'blockTypeInputRule',
125
124
  plugin: function plugin(_ref5) {
126
- var _api$analytics2;
125
+ var _api$analytics;
127
126
  var schema = _ref5.schema,
128
127
  featureFlags = _ref5.featureFlags;
129
- return inputRulePlugin(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, schema, featureFlags);
128
+ return inputRulePlugin(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, schema, featureFlags);
130
129
  }
131
130
  },
132
131
  // Needs to be lower priority than editor-tables.tableEditing
@@ -134,21 +133,23 @@ var blockTypePlugin = function blockTypePlugin(_ref3) {
134
133
  {
135
134
  name: 'blockTypeKeyMap',
136
135
  plugin: function plugin(_ref6) {
137
- var _api$analytics3;
136
+ var _api$analytics2;
138
137
  var schema = _ref6.schema,
139
138
  featureFlags = _ref6.featureFlags;
140
- return keymapPlugin(api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions, schema, featureFlags);
139
+ return keymapPlugin(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, schema, featureFlags);
141
140
  }
142
141
  }];
143
142
  },
144
143
  actions: {
145
144
  insertBlockQuote: function insertBlockQuote(inputMethod) {
145
+ var _api$analytics3;
146
+ return insertBlockQuoteWithAnalytics(inputMethod, api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions);
147
+ }
148
+ },
149
+ commands: {
150
+ setTextLevel: function setTextLevel(level, inputMethod) {
146
151
  var _api$analytics4;
147
- return insertBlockQuoteWithAnalytics(inputMethod, api === null || api === 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 || (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions);
152
+ return setBlockTypeWithAnalytics(level, inputMethod, api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions);
152
153
  }
153
154
  },
154
155
  getSharedState: function getSharedState(editorState) {
@@ -168,8 +169,8 @@ var blockTypePlugin = function blockTypePlugin(_ref3) {
168
169
  eventDispatcher = _ref7.eventDispatcher;
169
170
  var isSmall = options && options.isUndoRedoButtonsEnabled ? toolbarSize < ToolbarSize.XXL : toolbarSize < ToolbarSize.XL;
170
171
  var boundSetBlockType = function boundSetBlockType(name) {
171
- var _api$analytics6;
172
- return setBlockTypeWithAnalytics(name, INPUT_METHOD.TOOLBAR, api === null || api === void 0 || (_api$analytics6 = api.analytics) === null || _api$analytics6 === void 0 ? void 0 : _api$analytics6.actions)(editorView.state, editorView.dispatch);
172
+ var _api$analytics5;
173
+ api === null || api === void 0 || api.core.actions.execute(setBlockTypeWithAnalytics(name, INPUT_METHOD.TOOLBAR, api === null || api === void 0 || (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions));
173
174
  };
174
175
  return /*#__PURE__*/React.createElement(WithPluginState, {
175
176
  editorView: editorView,
@@ -183,7 +184,7 @@ var blockTypePlugin = function blockTypePlugin(_ref3) {
183
184
  isSmall: isSmall,
184
185
  isDisabled: disabled,
185
186
  isReducedSpacing: isToolbarReducedSpacing,
186
- setBlockType: boundSetBlockType,
187
+ setTextLevel: boundSetBlockType,
187
188
  pluginState: pluginState,
188
189
  popupsMountPoint: popupsMountPoint,
189
190
  popupsBoundariesElement: popupsBoundariesElement,
@@ -194,9 +195,9 @@ var blockTypePlugin = function blockTypePlugin(_ref3) {
194
195
  },
195
196
  pluginsOptions: {
196
197
  quickInsert: function quickInsert(intl) {
197
- var _api$analytics7, _api$analytics8;
198
+ var _api$analytics6, _api$analytics7;
198
199
  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 || (_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 || (_api$analytics8 = api.analytics) === null || _api$analytics8 === void 0 ? void 0 : _api$analytics8.actions)));
200
+ return [].concat(_toConsumableArray(blockquotePluginOptions(intl, exclude.indexOf('blockquote') === -1, api === null || api === void 0 || (_api$analytics6 = api.analytics) === null || _api$analytics6 === void 0 ? void 0 : _api$analytics6.actions)), _toConsumableArray(headingPluginOptions(intl, exclude.indexOf('heading') === -1, api === null || api === void 0 || (_api$analytics7 = api.analytics) === null || _api$analytics7 === void 0 ? void 0 : _api$analytics7.actions)));
200
201
  }
201
202
  }
202
203
  };
@@ -63,16 +63,16 @@ var detectBlockType = function detectBlockType(availableBlockTypes, state) {
63
63
  });
64
64
  return blockType || OTHER;
65
65
  };
66
- var autoformatHeading = function autoformatHeading(headingLevel, view, editorAnalyticsApi) {
66
+ var autoformatHeading = function autoformatHeading(headingLevel, editorAnalyticsApi) {
67
67
  if (headingLevel === 0) {
68
- setNormalTextWithAnalytics(INPUT_METHOD.FORMATTING, editorAnalyticsApi)(view.state, view.dispatch);
69
- } else {
70
- setHeadingWithAnalytics(headingLevel, INPUT_METHOD.FORMATTING, editorAnalyticsApi)(view.state, view.dispatch);
68
+ return setNormalTextWithAnalytics(INPUT_METHOD.FORMATTING, editorAnalyticsApi);
71
69
  }
72
- return true;
70
+ return setHeadingWithAnalytics(headingLevel, INPUT_METHOD.FORMATTING, editorAnalyticsApi);
73
71
  };
74
72
  export var pluginKey = new PluginKey('blockTypePlugin');
75
- export var createPlugin = function createPlugin(editorAnalyticsApi, dispatch, lastNodeMustBeParagraph) {
73
+ export var createPlugin = function createPlugin(editorAPI, dispatch, lastNodeMustBeParagraph) {
74
+ var _editorAPI$analytics;
75
+ var editorAnalyticsApi = editorAPI === null || editorAPI === void 0 || (_editorAPI$analytics = editorAPI.analytics) === null || _editorAPI$analytics === void 0 ? void 0 : _editorAPI$analytics.actions;
76
76
  var altKeyLocation = 0;
77
77
  return new SafePlugin({
78
78
  appendTransaction: function appendTransaction(_transactions, _oldState, newState) {
@@ -123,9 +123,11 @@ export var createPlugin = function createPlugin(editorAnalyticsApi, dispatch, la
123
123
  var headingLevel = HEADING_KEYS.indexOf(event.keyCode);
124
124
  if (headingLevel > -1 && event.altKey) {
125
125
  if (browser.mac && event.metaKey) {
126
- return autoformatHeading(headingLevel, view, editorAnalyticsApi);
126
+ var _editorAPI$core$actio;
127
+ return (_editorAPI$core$actio = editorAPI === null || editorAPI === void 0 ? void 0 : editorAPI.core.actions.execute(autoformatHeading(headingLevel, editorAnalyticsApi))) !== null && _editorAPI$core$actio !== void 0 ? _editorAPI$core$actio : false;
127
128
  } else if (!browser.mac && event.ctrlKey && altKeyLocation !== event.DOM_KEY_LOCATION_RIGHT) {
128
- return autoformatHeading(headingLevel, view, editorAnalyticsApi);
129
+ var _editorAPI$core$actio2;
130
+ return (_editorAPI$core$actio2 = editorAPI === null || editorAPI === void 0 ? void 0 : editorAPI.core.actions.execute(autoformatHeading(headingLevel, editorAnalyticsApi))) !== null && _editorAPI$core$actio2 !== void 0 ? _editorAPI$core$actio2 : false;
129
131
  }
130
132
  } else if (event.key === 'Alt') {
131
133
  // event.location is for the current key only; when a user hits Ctrl-Alt-1 the
@@ -94,7 +94,7 @@ var ToolbarBlockType = /*#__PURE__*/function (_React$PureComponent) {
94
94
  _ref$shouldCloseMenu = _ref.shouldCloseMenu,
95
95
  shouldCloseMenu = _ref$shouldCloseMenu === void 0 ? true : _ref$shouldCloseMenu;
96
96
  var blockType = item.value;
97
- _this.props.setBlockType(blockType.name);
97
+ _this.props.setTextLevel(blockType.name);
98
98
  if (shouldCloseMenu) {
99
99
  _this.setState(_objectSpread(_objectSpread({}, _this.state), {}, {
100
100
  active: false
@@ -4,3 +4,4 @@ export type { BlockTypePluginOptions, BlockType } from './plugin/types';
4
4
  export type { BlockTypeState } from './plugin/pm-plugins/main';
5
5
  export type { InputMethod } from './plugin/commands';
6
6
  export type { DropdownItem } from './plugin/ui/ToolbarBlockType';
7
+ export type { TextBlockTypes } from './plugin/block-types';
@@ -11,6 +11,7 @@ export declare const CODE_BLOCK: BlockType;
11
11
  export declare const PANEL: BlockType;
12
12
  export declare const OTHER: BlockType;
13
13
  export declare const TEXT_BLOCK_TYPES: BlockType[];
14
+ export type TextBlockTypes = 'normal' | 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6';
14
15
  export declare const WRAPPER_BLOCK_TYPES: BlockType[];
15
16
  export declare const ALL_BLOCK_TYPES: BlockType[];
16
17
  export declare const HEADINGS_BY_LEVEL: Record<number, BlockType>;
@@ -1,11 +1,13 @@
1
1
  import type { EditorAnalyticsAPI, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
- import type { Command, HeadingLevelsAndNormalText } from '@atlaskit/editor-common/types';
2
+ import type { Command, EditorCommand, HeadingLevelsAndNormalText } from '@atlaskit/editor-common/types';
3
+ import type { TextBlockTypes } from '../block-types';
3
4
  export type InputMethod = INPUT_METHOD.TOOLBAR | INPUT_METHOD.INSERT_MENU | INPUT_METHOD.SHORTCUT | INPUT_METHOD.FORMATTING | INPUT_METHOD.KEYBOARD;
4
- export declare function setBlockType(name: string): Command;
5
- export declare function setBlockTypeWithAnalytics(name: string, inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined): Command;
6
- export declare function setNormalText(): Command;
7
- export declare function setNormalTextWithAnalytics(inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined): Command;
8
- export declare const setHeadingWithAnalytics: (newHeadingLevel: HeadingLevelsAndNormalText, inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined) => Command;
5
+ export declare function setBlockType(name: TextBlockTypes): EditorCommand;
6
+ export declare function setHeading(level: HeadingLevelsAndNormalText): EditorCommand;
7
+ export declare function setBlockTypeWithAnalytics(name: TextBlockTypes, inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined): EditorCommand;
8
+ export declare function setNormalText(): EditorCommand;
9
+ export declare function setNormalTextWithAnalytics(inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined): EditorCommand;
10
+ export declare const setHeadingWithAnalytics: (newHeadingLevel: HeadingLevelsAndNormalText, inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined) => EditorCommand;
9
11
  /**
10
12
  *
11
13
  * @param name - block type name
@@ -2,8 +2,3 @@ export { cleanUpAtTheStartOfDocument, insertBlockQuoteWithAnalytics, setBlockTyp
2
2
  export type { InputMethod } from './block-type';
3
3
  export { deleteAndMoveCursor } from './delete-and-move-cursor';
4
4
  export { deleteBlockContent } from './delete-block-content';
5
- /**
6
- * @private
7
- * @deprecated use import from @atlaskit/editor-common/commands
8
- */
9
- export { setHeading } from '@atlaskit/editor-common/commands';
@@ -1,5 +1,6 @@
1
- import type { Command, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
1
+ import type { Command, EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
2
2
  import type { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
3
+ import type { TextBlockTypes } from './block-types';
3
4
  import type { InputMethod } from './commands/block-type';
4
5
  import type { BlockTypeState } from './pm-plugins/main';
5
6
  import type { BlockTypePluginOptions } from './types';
@@ -9,7 +10,9 @@ export type BlockTypePlugin = NextEditorPlugin<'blockType', {
9
10
  sharedState: BlockTypeState | undefined;
10
11
  actions: {
11
12
  insertBlockQuote: (inputMethod: InputMethod) => Command;
12
- setBlockType: (name: string, inputMethod: InputMethod) => Command;
13
+ };
14
+ commands: {
15
+ setTextLevel: (level: TextBlockTypes, inputMethod: InputMethod) => EditorCommand;
13
16
  };
14
17
  }>;
15
18
  declare const blockTypePlugin: BlockTypePlugin;
@@ -1,6 +1,7 @@
1
- import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
3
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
+ import type { BlockTypePlugin } from '../index';
4
5
  import type { BlockType } from '../types';
5
6
  export type BlockTypeState = {
6
7
  currentBlockType: BlockType;
@@ -9,7 +10,7 @@ export type BlockTypeState = {
9
10
  availableWrapperBlockTypes: BlockType[];
10
11
  };
11
12
  export declare const pluginKey: PluginKey<BlockTypeState>;
12
- export declare const createPlugin: (editorAnalyticsApi: EditorAnalyticsAPI | undefined, dispatch: (eventName: string | PluginKey, data: any) => void, lastNodeMustBeParagraph?: boolean) => SafePlugin<{
13
+ export declare const createPlugin: (editorAPI: ExtractInjectionAPI<BlockTypePlugin> | undefined, dispatch: (eventName: string | PluginKey, data: any) => void, lastNodeMustBeParagraph?: boolean) => SafePlugin<{
13
14
  currentBlockType: BlockType;
14
15
  blockTypesDisabled: boolean;
15
16
  availableBlockTypes: BlockType[];
@@ -3,6 +3,7 @@ import React from 'react';
3
3
  import type { WrappedComponentProps } from 'react-intl-next';
4
4
  import type { MenuItem } from '@atlaskit/editor-common/ui-menu';
5
5
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
6
+ import type { TextBlockTypes } from '../../block-types';
6
7
  import type { BlockTypeState } from '../../pm-plugins/main';
7
8
  import type { BlockType } from '../../types';
8
9
  export type DropdownItem = MenuItem & {
@@ -17,7 +18,7 @@ export interface Props {
17
18
  popupsBoundariesElement?: HTMLElement;
18
19
  popupsScrollableElement?: HTMLElement;
19
20
  editorView?: EditorView;
20
- setBlockType: (type: string) => void;
21
+ setTextLevel: (type: TextBlockTypes) => void;
21
22
  }
22
23
  export interface State {
23
24
  active: boolean;
@@ -4,3 +4,4 @@ export type { BlockTypePluginOptions, BlockType } from './plugin/types';
4
4
  export type { BlockTypeState } from './plugin/pm-plugins/main';
5
5
  export type { InputMethod } from './plugin/commands';
6
6
  export type { DropdownItem } from './plugin/ui/ToolbarBlockType';
7
+ export type { TextBlockTypes } from './plugin/block-types';
@@ -11,6 +11,7 @@ export declare const CODE_BLOCK: BlockType;
11
11
  export declare const PANEL: BlockType;
12
12
  export declare const OTHER: BlockType;
13
13
  export declare const TEXT_BLOCK_TYPES: BlockType[];
14
+ export type TextBlockTypes = 'normal' | 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6';
14
15
  export declare const WRAPPER_BLOCK_TYPES: BlockType[];
15
16
  export declare const ALL_BLOCK_TYPES: BlockType[];
16
17
  export declare const HEADINGS_BY_LEVEL: Record<number, BlockType>;