@atlaskit/editor-plugin-block-type 1.0.3 → 3.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 (90) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/dist/cjs/i18n/cs.js +2 -3
  3. package/dist/cjs/i18n/da.js +2 -3
  4. package/dist/cjs/i18n/de.js +2 -3
  5. package/dist/cjs/i18n/en.js +2 -3
  6. package/dist/cjs/i18n/en_GB.js +2 -3
  7. package/dist/cjs/i18n/en_ZZ.js +2 -3
  8. package/dist/cjs/i18n/es.js +2 -3
  9. package/dist/cjs/i18n/fi.js +2 -3
  10. package/dist/cjs/i18n/fr.js +2 -3
  11. package/dist/cjs/i18n/hu.js +2 -3
  12. package/dist/cjs/i18n/it.js +2 -3
  13. package/dist/cjs/i18n/ja.js +2 -3
  14. package/dist/cjs/i18n/ko.js +2 -3
  15. package/dist/cjs/i18n/nb.js +2 -3
  16. package/dist/cjs/i18n/nl.js +8 -9
  17. package/dist/cjs/i18n/pl.js +2 -3
  18. package/dist/cjs/i18n/pt_BR.js +2 -3
  19. package/dist/cjs/i18n/ru.js +2 -3
  20. package/dist/cjs/i18n/sv.js +2 -3
  21. package/dist/cjs/i18n/th.js +2 -3
  22. package/dist/cjs/i18n/tr.js +2 -3
  23. package/dist/cjs/i18n/uk.js +2 -3
  24. package/dist/cjs/i18n/vi.js +2 -3
  25. package/dist/cjs/i18n/zh.js +2 -3
  26. package/dist/cjs/i18n/zh_TW.js +2 -3
  27. package/dist/cjs/plugin/block-types.js +29 -45
  28. package/dist/cjs/plugin/commands/block-type.js +95 -60
  29. package/dist/cjs/plugin/commands/delete-and-move-cursor.js +2 -3
  30. package/dist/cjs/plugin/commands/index.js +1 -8
  31. package/dist/cjs/plugin/consts.js +1 -2
  32. package/dist/cjs/plugin/index.js +26 -26
  33. package/dist/cjs/plugin/pm-plugins/input-rule.js +1 -2
  34. package/dist/cjs/plugin/pm-plugins/main.js +12 -12
  35. package/dist/cjs/plugin/styles.js +2 -3
  36. package/dist/cjs/plugin/ui/ToolbarBlockType/blocktype-button.js +5 -13
  37. package/dist/cjs/plugin/ui/ToolbarBlockType/index.js +2 -3
  38. package/dist/cjs/plugin/ui/ToolbarBlockType/styled.js +7 -14
  39. package/dist/cjs/plugin/utils.js +3 -6
  40. package/dist/es2019/i18n/nl.js +6 -6
  41. package/dist/es2019/plugin/block-types.js +1 -1
  42. package/dist/es2019/plugin/commands/block-type.js +101 -46
  43. package/dist/es2019/plugin/commands/index.js +1 -6
  44. package/dist/es2019/plugin/index.js +18 -19
  45. package/dist/es2019/plugin/pm-plugins/main.js +10 -8
  46. package/dist/es2019/plugin/ui/ToolbarBlockType/blocktype-button.js +3 -9
  47. package/dist/es2019/plugin/ui/ToolbarBlockType/index.js +1 -1
  48. package/dist/esm/i18n/nl.js +6 -6
  49. package/dist/esm/plugin/block-types.js +1 -1
  50. package/dist/esm/plugin/commands/block-type.js +90 -53
  51. package/dist/esm/plugin/commands/index.js +1 -6
  52. package/dist/esm/plugin/index.js +20 -19
  53. package/dist/esm/plugin/pm-plugins/main.js +10 -8
  54. package/dist/esm/plugin/ui/ToolbarBlockType/blocktype-button.js +3 -9
  55. package/dist/esm/plugin/ui/ToolbarBlockType/index.js +1 -1
  56. package/dist/types/index.d.ts +1 -0
  57. package/dist/types/plugin/block-types.d.ts +1 -0
  58. package/dist/types/plugin/commands/block-type.d.ts +8 -6
  59. package/dist/types/plugin/commands/index.d.ts +0 -5
  60. package/dist/types/plugin/index.d.ts +5 -2
  61. package/dist/types/plugin/pm-plugins/main.d.ts +3 -2
  62. package/dist/types/plugin/ui/ToolbarBlockType/blocktype-button.d.ts +0 -7
  63. package/dist/types/plugin/ui/ToolbarBlockType/index.d.ts +2 -1
  64. package/dist/types-ts4.5/index.d.ts +1 -0
  65. package/dist/types-ts4.5/plugin/block-types.d.ts +1 -0
  66. package/dist/types-ts4.5/plugin/commands/block-type.d.ts +8 -6
  67. package/dist/types-ts4.5/plugin/commands/index.d.ts +0 -5
  68. package/dist/types-ts4.5/plugin/index.d.ts +5 -2
  69. package/dist/types-ts4.5/plugin/pm-plugins/main.d.ts +3 -2
  70. package/dist/types-ts4.5/plugin/ui/ToolbarBlockType/blocktype-button.d.ts +0 -7
  71. package/dist/types-ts4.5/plugin/ui/ToolbarBlockType/index.d.ts +2 -1
  72. package/package.json +3 -4
  73. package/report.api.md +17 -1
  74. package/tmp/api-report-tmp.d.ts +7 -1
  75. package/dist/cjs/messages.js +0 -19
  76. package/dist/cjs/plugin/messages.js +0 -160
  77. package/dist/cjs/plugin/ui/ToolbarBlockType/toolbar-messages.js +0 -15
  78. package/dist/es2019/messages.js +0 -2
  79. package/dist/es2019/plugin/messages.js +0 -153
  80. package/dist/es2019/plugin/ui/ToolbarBlockType/toolbar-messages.js +0 -8
  81. package/dist/esm/messages.js +0 -2
  82. package/dist/esm/plugin/messages.js +0 -153
  83. package/dist/esm/plugin/ui/ToolbarBlockType/toolbar-messages.js +0 -8
  84. package/dist/types/messages.d.ts +0 -2
  85. package/dist/types/plugin/messages.d.ts +0 -152
  86. package/dist/types/plugin/ui/ToolbarBlockType/toolbar-messages.d.ts +0 -7
  87. package/dist/types-ts4.5/messages.d.ts +0 -2
  88. package/dist/types-ts4.5/plugin/messages.d.ts +0 -152
  89. package/dist/types-ts4.5/plugin/ui/ToolbarBlockType/toolbar-messages.d.ts +0 -7
  90. package/messages/package.json +0 -15
@@ -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',
@@ -1,4 +1,4 @@
1
- import { messages } from './messages';
1
+ import { blockTypeMessages as messages } from '@atlaskit/editor-common/messages';
2
2
  export const NORMAL_TEXT = {
3
3
  name: 'normal',
4
4
  title: messages.normal,
@@ -1,46 +1,86 @@
1
1
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
2
- import { setHeading } from '@atlaskit/editor-common/commands';
3
2
  import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
4
3
  import { filterChildrenBetween, wrapSelectionIn } from '@atlaskit/editor-common/utils';
5
4
  import { CellSelection } from '@atlaskit/editor-tables';
6
5
  import { HEADINGS_BY_NAME, NORMAL_TEXT } from '../block-types';
7
6
  export function setBlockType(name) {
8
- return (state, dispatch) => {
7
+ return ({
8
+ tr
9
+ }) => {
9
10
  const {
10
11
  nodes
11
- } = state.schema;
12
+ } = tr.doc.type.schema;
12
13
  if (name === NORMAL_TEXT.name && nodes.paragraph) {
13
- return setNormalText()(state, dispatch);
14
+ return setNormalText()({
15
+ tr
16
+ });
14
17
  }
15
18
  const headingBlockType = HEADINGS_BY_NAME[name];
16
19
  if (headingBlockType && nodes.heading && headingBlockType.level) {
17
- return setHeading(headingBlockType.level)(state, dispatch);
20
+ return setHeading(headingBlockType.level)({
21
+ tr
22
+ });
18
23
  }
19
- return false;
24
+ return null;
25
+ };
26
+ }
27
+ export function setHeading(level) {
28
+ return function ({
29
+ tr
30
+ }) {
31
+ const {
32
+ selection,
33
+ doc: {
34
+ type: {
35
+ schema
36
+ }
37
+ }
38
+ } = tr;
39
+ const ranges = selection instanceof CellSelection ? selection.ranges : [selection];
40
+ ranges.forEach(({
41
+ $from,
42
+ $to
43
+ }) => {
44
+ tr.setBlockType($from.pos, $to.pos, schema.nodes.heading, {
45
+ level
46
+ });
47
+ });
48
+ return tr;
20
49
  };
21
50
  }
22
51
  export function setBlockTypeWithAnalytics(name, inputMethod, editorAnalyticsApi) {
23
- return (state, dispatch) => {
52
+ return ({
53
+ tr
54
+ }) => {
24
55
  const {
25
56
  nodes
26
- } = state.schema;
27
- if (name === NORMAL_TEXT.name && nodes.paragraph) {
28
- return setNormalTextWithAnalytics(inputMethod, editorAnalyticsApi)(state, dispatch);
57
+ } = tr.doc.type.schema;
58
+ if (name === 'normal' && nodes.paragraph) {
59
+ return setNormalTextWithAnalytics(inputMethod, editorAnalyticsApi)({
60
+ tr
61
+ });
29
62
  }
30
63
  const headingBlockType = HEADINGS_BY_NAME[name];
31
64
  if (headingBlockType && nodes.heading && headingBlockType.level) {
32
- return setHeadingWithAnalytics(headingBlockType.level, inputMethod, editorAnalyticsApi)(state, dispatch);
65
+ return setHeadingWithAnalytics(headingBlockType.level, inputMethod, editorAnalyticsApi)({
66
+ tr
67
+ });
33
68
  }
34
- return false;
69
+ return null;
35
70
  };
36
71
  }
37
72
  export function setNormalText() {
38
- return function (state, dispatch) {
73
+ return function ({
74
+ tr
75
+ }) {
39
76
  const {
40
77
  selection,
41
- schema,
42
- tr
43
- } = state;
78
+ doc: {
79
+ type: {
80
+ schema
81
+ }
82
+ }
83
+ } = tr;
44
84
  const ranges = selection instanceof CellSelection ? selection.ranges : [selection];
45
85
  ranges.forEach(({
46
86
  $from,
@@ -48,20 +88,19 @@ export function setNormalText() {
48
88
  }) => {
49
89
  tr.setBlockType($from.pos, $to.pos, schema.nodes.paragraph);
50
90
  });
51
- if (dispatch) {
52
- dispatch(tr);
53
- }
54
- return true;
91
+ return tr;
55
92
  };
56
93
  }
57
94
  function withCurrentHeadingLevel(fn) {
58
- return (state, dispatch, view) => {
95
+ return ({
96
+ tr
97
+ }) => {
59
98
  // Find all headings and paragraphs of text
60
99
  const {
61
100
  heading,
62
101
  paragraph
63
- } = state.schema.nodes;
64
- const nodes = filterChildrenBetween(state.doc, state.selection.from, state.selection.to, node => {
102
+ } = tr.doc.type.schema.nodes;
103
+ const nodes = filterChildrenBetween(tr.doc, tr.selection.from, tr.selection.to, node => {
65
104
  return node.type === heading || node.type === paragraph;
66
105
  });
67
106
 
@@ -77,34 +116,50 @@ function withCurrentHeadingLevel(fn) {
77
116
  break;
78
117
  }
79
118
  }
80
- return fn(level)(state, dispatch, view);
119
+ return fn(level)({
120
+ tr
121
+ });
81
122
  };
82
123
  }
83
124
  export function setNormalTextWithAnalytics(inputMethod, editorAnalyticsApi) {
84
- return withCurrentHeadingLevel(previousHeadingLevel => withAnalytics(editorAnalyticsApi, {
85
- action: ACTION.FORMATTED,
86
- actionSubject: ACTION_SUBJECT.TEXT,
87
- eventType: EVENT_TYPE.TRACK,
88
- actionSubjectId: ACTION_SUBJECT_ID.FORMAT_HEADING,
89
- attributes: {
90
- inputMethod,
91
- newHeadingLevel: 0,
92
- previousHeadingLevel
93
- }
94
- })(setNormalText()));
125
+ return withCurrentHeadingLevel(previousHeadingLevel => ({
126
+ tr
127
+ }) => {
128
+ editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent({
129
+ action: ACTION.FORMATTED,
130
+ actionSubject: ACTION_SUBJECT.TEXT,
131
+ eventType: EVENT_TYPE.TRACK,
132
+ actionSubjectId: ACTION_SUBJECT_ID.FORMAT_HEADING,
133
+ attributes: {
134
+ inputMethod,
135
+ newHeadingLevel: 0,
136
+ previousHeadingLevel
137
+ }
138
+ })(tr);
139
+ return setNormalText()({
140
+ tr
141
+ });
142
+ });
95
143
  }
96
144
  export const setHeadingWithAnalytics = (newHeadingLevel, inputMethod, editorAnalyticsApi) => {
97
- return withCurrentHeadingLevel(previousHeadingLevel => withAnalytics(editorAnalyticsApi, {
98
- action: ACTION.FORMATTED,
99
- actionSubject: ACTION_SUBJECT.TEXT,
100
- eventType: EVENT_TYPE.TRACK,
101
- actionSubjectId: ACTION_SUBJECT_ID.FORMAT_HEADING,
102
- attributes: {
103
- inputMethod,
104
- newHeadingLevel,
105
- previousHeadingLevel
106
- }
107
- })(setHeading(newHeadingLevel)));
145
+ return withCurrentHeadingLevel(previousHeadingLevel => ({
146
+ tr
147
+ }) => {
148
+ editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent({
149
+ action: ACTION.FORMATTED,
150
+ actionSubject: ACTION_SUBJECT.TEXT,
151
+ eventType: EVENT_TYPE.TRACK,
152
+ actionSubjectId: ACTION_SUBJECT_ID.FORMAT_HEADING,
153
+ attributes: {
154
+ inputMethod,
155
+ newHeadingLevel,
156
+ previousHeadingLevel
157
+ }
158
+ })(tr);
159
+ return setHeading(newHeadingLevel)({
160
+ tr
161
+ });
162
+ });
108
163
  };
109
164
  function insertBlockQuote() {
110
165
  return function (state, dispatch) {
@@ -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';
@@ -2,12 +2,12 @@ import React from 'react';
2
2
  import { blockquote, hardBreak, heading } from '@atlaskit/adf-schema';
3
3
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
4
  import { keymap, toggleBlockQuote, tooltip } from '@atlaskit/editor-common/keymaps';
5
+ import { blockTypeMessages as messages } from '@atlaskit/editor-common/messages';
5
6
  import { IconHeading, IconQuote } from '@atlaskit/editor-common/quick-insert';
6
7
  import { ToolbarSize } from '@atlaskit/editor-common/types';
7
8
  import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
8
9
  import { setBlockTypeWithAnalytics } from './commands';
9
10
  import { insertBlockQuoteWithAnalytics } from './commands/block-type';
10
- import { messages } from './messages';
11
11
  import inputRulePlugin from './pm-plugins/input-rule';
12
12
  import keymapPlugin from './pm-plugins/keymap';
13
13
  import { createPlugin, pluginKey } from './pm-plugins/main';
@@ -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
@@ -1,22 +1,16 @@
1
1
  /** @jsx jsx */
2
2
  import React from 'react';
3
3
  import { jsx } from '@emotion/react';
4
- import { defineMessages, FormattedMessage } from 'react-intl-next';
4
+ import { FormattedMessage } from 'react-intl-next';
5
+ import { toolbarMessages } from '@atlaskit/editor-common/messages';
5
6
  import { wrapperStyle } from '@atlaskit/editor-common/styles';
6
7
  import { ToolbarButton } from '@atlaskit/editor-common/ui-menu';
7
8
  import ExpandIcon from '@atlaskit/icon/glyph/chevron-down';
8
9
  import TextStyleIcon from '@atlaskit/icon/glyph/editor/text-style';
9
10
  import { NORMAL_TEXT } from '../../block-types';
10
11
  import { buttonContentReducedSpacingStyle, buttonContentStyle, expandIconWrapperStyle, wrapperSmallStyle } from './styled';
11
- export const messages = defineMessages({
12
- textStyles: {
13
- id: 'fabric.editor.textStyles',
14
- defaultMessage: 'Text styles',
15
- description: 'Menu provides access to various heading styles or normal text'
16
- }
17
- });
18
12
  export const BlockTypeButton = props => {
19
- const labelTextStyles = props.formatMessage(messages.textStyles);
13
+ const labelTextStyles = props.formatMessage(toolbarMessages.textStyles);
20
14
  return jsx(ToolbarButton, {
21
15
  spacing: props.isReducedSpacing ? 'none' : 'default',
22
16
  selected: props.selected,
@@ -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',
@@ -1,4 +1,4 @@
1
- import { messages } from './messages';
1
+ import { blockTypeMessages as messages } from '@atlaskit/editor-common/messages';
2
2
  export var NORMAL_TEXT = {
3
3
  name: 'normal',
4
4
  title: messages.normal,
@@ -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;