@atlaskit/editor-plugin-block-type 6.1.2 → 6.2.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 (37) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/cjs/blockTypePlugin.js +14 -7
  3. package/dist/cjs/pm-plugins/block-types.js +56 -1
  4. package/dist/cjs/pm-plugins/ui/ToolbarBlockType/HeadingButton.compiled.css +7 -0
  5. package/dist/cjs/pm-plugins/ui/ToolbarBlockType/HeadingButton.js +66 -0
  6. package/dist/cjs/pm-plugins/ui/ToolbarBlockType/QuoteButton.js +40 -0
  7. package/dist/cjs/pm-plugins/ui/ToolbarBlockType/TextStylesMenuButton.js +35 -0
  8. package/dist/cjs/pm-plugins/ui/ToolbarComponents.js +72 -0
  9. package/dist/es2019/blockTypePlugin.js +40 -31
  10. package/dist/es2019/pm-plugins/block-types.js +58 -0
  11. package/dist/es2019/pm-plugins/ui/ToolbarBlockType/HeadingButton.compiled.css +7 -0
  12. package/dist/es2019/pm-plugins/ui/ToolbarBlockType/HeadingButton.js +59 -0
  13. package/dist/es2019/pm-plugins/ui/ToolbarBlockType/QuoteButton.js +33 -0
  14. package/dist/es2019/pm-plugins/ui/ToolbarBlockType/TextStylesMenuButton.js +28 -0
  15. package/dist/es2019/pm-plugins/ui/ToolbarComponents.js +60 -0
  16. package/dist/esm/blockTypePlugin.js +14 -7
  17. package/dist/esm/pm-plugins/block-types.js +55 -0
  18. package/dist/esm/pm-plugins/ui/ToolbarBlockType/HeadingButton.compiled.css +7 -0
  19. package/dist/esm/pm-plugins/ui/ToolbarBlockType/HeadingButton.js +59 -0
  20. package/dist/esm/pm-plugins/ui/ToolbarBlockType/QuoteButton.js +33 -0
  21. package/dist/esm/pm-plugins/ui/ToolbarBlockType/TextStylesMenuButton.js +28 -0
  22. package/dist/esm/pm-plugins/ui/ToolbarComponents.js +65 -0
  23. package/dist/types/blockTypePluginType.d.ts +3 -1
  24. package/dist/types/pm-plugins/block-types.d.ts +13 -1
  25. package/dist/types/pm-plugins/types.d.ts +4 -0
  26. package/dist/types/pm-plugins/ui/ToolbarBlockType/HeadingButton.d.ts +10 -0
  27. package/dist/types/pm-plugins/ui/ToolbarBlockType/QuoteButton.d.ts +10 -0
  28. package/dist/types/pm-plugins/ui/ToolbarBlockType/TextStylesMenuButton.d.ts +9 -0
  29. package/dist/types/pm-plugins/ui/ToolbarComponents.d.ts +4 -0
  30. package/dist/types-ts4.5/blockTypePluginType.d.ts +3 -1
  31. package/dist/types-ts4.5/pm-plugins/block-types.d.ts +13 -1
  32. package/dist/types-ts4.5/pm-plugins/types.d.ts +4 -0
  33. package/dist/types-ts4.5/pm-plugins/ui/ToolbarBlockType/HeadingButton.d.ts +10 -0
  34. package/dist/types-ts4.5/pm-plugins/ui/ToolbarBlockType/QuoteButton.d.ts +10 -0
  35. package/dist/types-ts4.5/pm-plugins/ui/ToolbarBlockType/TextStylesMenuButton.d.ts +9 -0
  36. package/dist/types-ts4.5/pm-plugins/ui/ToolbarComponents.d.ts +4 -0
  37. package/package.json +13 -10
@@ -0,0 +1,59 @@
1
+ /* HeadingButton.tsx generated by @compiled/babel-plugin v0.36.1 */
2
+ import "./HeadingButton.compiled.css";
3
+ import { ax, ix } from "@compiled/react/runtime";
4
+ import React from 'react';
5
+ import { useIntl } from 'react-intl-next';
6
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
7
+ import { formatShortcut, setNormalText, toggleHeading1, toggleHeading2, toggleHeading3, toggleHeading4, toggleHeading5, toggleHeading6 } from '@atlaskit/editor-common/keymaps';
8
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
9
+ import { ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar';
10
+ import { Box } from '@atlaskit/primitives/compiled';
11
+ const headingSizeStylesMap = {
12
+ normal: "_11c82smr",
13
+ heading1: "_11c81c04",
14
+ heading2: "_11c8nf1z",
15
+ heading3: "_11c8lodh",
16
+ heading4: "_11c8nbxd",
17
+ heading5: "_11c8140y",
18
+ heading6: "_11c81vhk"
19
+ };
20
+ const shortcuts = {
21
+ 'normal': setNormalText,
22
+ 'heading1': toggleHeading1,
23
+ 'heading2': toggleHeading2,
24
+ 'heading3': toggleHeading3,
25
+ 'heading4': toggleHeading4,
26
+ 'heading5': toggleHeading5,
27
+ 'heading6': toggleHeading6
28
+ };
29
+ export const HeadingButton = ({
30
+ blockType,
31
+ api
32
+ }) => {
33
+ const {
34
+ formatMessage
35
+ } = useIntl();
36
+ const currentBlockType = useSharedPluginStateSelector(api, 'blockType.currentBlockType');
37
+ const availableBlockTypesInDropdown = useSharedPluginStateSelector(api, 'blockType.availableBlockTypesInDropdown');
38
+ if (!(availableBlockTypesInDropdown !== null && availableBlockTypesInDropdown !== void 0 && availableBlockTypesInDropdown.some(availableBlockType => availableBlockType.name === blockType.name))) {
39
+ return null;
40
+ }
41
+ const fromBlockQuote = (currentBlockType === null || currentBlockType === void 0 ? void 0 : currentBlockType.name) === 'blockquote';
42
+ const onClick = () => {
43
+ var _api$core, _api$blockType, _api$blockType$comman;
44
+ api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(api === null || api === void 0 ? void 0 : (_api$blockType = api.blockType) === null || _api$blockType === void 0 ? void 0 : (_api$blockType$comman = _api$blockType.commands) === null || _api$blockType$comman === void 0 ? void 0 : _api$blockType$comman.setTextLevel(blockType.name, INPUT_METHOD.TOOLBAR, fromBlockQuote));
45
+ };
46
+ const shortcut = formatShortcut(shortcuts[blockType.name]);
47
+ const isSelected = currentBlockType === blockType;
48
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
49
+ elemBefore: blockType.icon,
50
+ elemAfter: shortcut ? /*#__PURE__*/React.createElement(ToolbarKeyboardShortcutHint, {
51
+ shortcut: shortcut
52
+ }) : undefined,
53
+ onClick: onClick,
54
+ isSelected: isSelected,
55
+ ariaKeyshortcuts: shortcut
56
+ }, /*#__PURE__*/React.createElement(Box, {
57
+ xcss: headingSizeStylesMap[blockType.name]
58
+ }, formatMessage(blockType.title)));
59
+ };
@@ -0,0 +1,33 @@
1
+ import React from 'react';
2
+ import { useIntl } from 'react-intl-next';
3
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
+ import { formatShortcut, toggleBlockQuote } from '@atlaskit/editor-common/keymaps';
5
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
6
+ import { ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar';
7
+ export const QuoteButton = ({
8
+ blockType,
9
+ api
10
+ }) => {
11
+ const {
12
+ formatMessage
13
+ } = useIntl();
14
+ const availableBlockTypesInDropdown = useSharedPluginStateSelector(api, 'blockType.availableBlockTypesInDropdown');
15
+ const currentBlockType = useSharedPluginStateSelector(api, 'blockType.currentBlockType');
16
+ if (!(availableBlockTypesInDropdown !== null && availableBlockTypesInDropdown !== void 0 && availableBlockTypesInDropdown.some(availableBlockType => availableBlockType.name === blockType.name))) {
17
+ return null;
18
+ }
19
+ const onClick = () => {
20
+ var _api$core, _api$blockType, _api$blockType$comman;
21
+ api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(api === null || api === void 0 ? void 0 : (_api$blockType = api.blockType) === null || _api$blockType === void 0 ? void 0 : (_api$blockType$comman = _api$blockType.commands) === null || _api$blockType$comman === void 0 ? void 0 : _api$blockType$comman.insertBlockQuote(INPUT_METHOD.TOOLBAR));
22
+ };
23
+ const shortcut = formatShortcut(toggleBlockQuote);
24
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
25
+ elemBefore: blockType.icon,
26
+ elemAfter: shortcut ? /*#__PURE__*/React.createElement(ToolbarKeyboardShortcutHint, {
27
+ shortcut: shortcut
28
+ }) : undefined,
29
+ onClick: onClick,
30
+ isSelected: currentBlockType === blockType,
31
+ ariaKeyshortcuts: shortcut
32
+ }, formatMessage(blockType.title));
33
+ };
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import { useIntl } from 'react-intl-next';
3
+ import { toolbarMessages } from '@atlaskit/editor-common/messages';
4
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
5
+ import { ToolbarDropdownMenu, ToolbarTooltip, TextIcon } from "@atlaskit/editor-toolbar";
6
+ import { toolbarBlockTypesWithRank } from '../../block-types';
7
+ export const TextStylesMenuButton = ({
8
+ api,
9
+ children
10
+ }) => {
11
+ var _Object$values$find, _Object$values$find$i;
12
+ const {
13
+ formatMessage
14
+ } = useIntl();
15
+ const blockTypesDisabled = useSharedPluginStateSelector(api, 'blockType.blockTypesDisabled');
16
+ const currentBlockType = useSharedPluginStateSelector(api, 'blockType.currentBlockType');
17
+ const CurrentIcon = (_Object$values$find = Object.values(toolbarBlockTypesWithRank()).find(blockType => blockType.name === (currentBlockType === null || currentBlockType === void 0 ? void 0 : currentBlockType.name))) === null || _Object$values$find === void 0 ? void 0 : (_Object$values$find$i = _Object$values$find.icon) === null || _Object$values$find$i === void 0 ? void 0 : _Object$values$find$i.type;
18
+ return /*#__PURE__*/React.createElement(ToolbarTooltip, {
19
+ content: formatMessage(toolbarMessages.textStylesTooltip)
20
+ }, /*#__PURE__*/React.createElement(ToolbarDropdownMenu, {
21
+ isDisabled: blockTypesDisabled,
22
+ iconBefore: CurrentIcon ? /*#__PURE__*/React.createElement(CurrentIcon, {
23
+ label: `${currentBlockType === null || currentBlockType === void 0 ? void 0 : currentBlockType.name} ${formatMessage(toolbarMessages.textStylesTooltip)}`
24
+ }) : /*#__PURE__*/React.createElement(TextIcon, {
25
+ label: formatMessage(toolbarMessages.textStylesTooltip)
26
+ })
27
+ }, children));
28
+ };
@@ -0,0 +1,60 @@
1
+ import React from 'react';
2
+ import { TEXT_STYLES_GROUP, TEXT_SECTION_RANK, TEXT_SECTION, TEXT_STYLES_MENU, TEXT_STYLES_GROUP_RANK, TEXT_STYLES_MENU_SECTION, TEXT_STYLES_MENU_RANK } from '@atlaskit/editor-common/toolbar';
3
+ import { toolbarBlockTypesWithRank } from '../block-types';
4
+ import { HeadingButton } from './ToolbarBlockType/HeadingButton';
5
+ import { QuoteButton } from './ToolbarBlockType/QuoteButton';
6
+ import { TextStylesMenuButton } from './ToolbarBlockType/TextStylesMenuButton';
7
+ export const getToolbarComponents = api => {
8
+ const toolbarComponents = [{
9
+ type: TEXT_STYLES_GROUP.type,
10
+ key: TEXT_STYLES_GROUP.key,
11
+ parents: [{
12
+ type: TEXT_SECTION.type,
13
+ key: TEXT_SECTION.key,
14
+ rank: TEXT_SECTION_RANK[TEXT_STYLES_GROUP.key]
15
+ }]
16
+ }, {
17
+ type: TEXT_STYLES_MENU.type,
18
+ key: TEXT_STYLES_MENU.key,
19
+ parents: [{
20
+ type: TEXT_STYLES_GROUP.type,
21
+ key: TEXT_STYLES_GROUP.key,
22
+ rank: TEXT_STYLES_GROUP_RANK[TEXT_STYLES_MENU.key]
23
+ }],
24
+ component: ({
25
+ children
26
+ }) => /*#__PURE__*/React.createElement(TextStylesMenuButton, {
27
+ api: api
28
+ }, children)
29
+ }, {
30
+ type: TEXT_STYLES_MENU_SECTION.type,
31
+ key: TEXT_STYLES_MENU_SECTION.key,
32
+ parents: [{
33
+ type: TEXT_STYLES_MENU.type,
34
+ key: TEXT_STYLES_MENU.key,
35
+ rank: TEXT_STYLES_MENU_RANK[TEXT_STYLES_MENU_SECTION.key]
36
+ }]
37
+ }];
38
+ Object.values(toolbarBlockTypesWithRank()).forEach(blockType => {
39
+ if (blockType.toolbarKey) {
40
+ const menuItem = {
41
+ type: 'menu-item',
42
+ key: blockType.toolbarKey,
43
+ parents: [{
44
+ type: TEXT_STYLES_MENU_SECTION.type,
45
+ key: TEXT_STYLES_MENU_SECTION.key,
46
+ rank: blockType.toolbarRank
47
+ }],
48
+ component: blockType.name === 'blockquote' ? () => /*#__PURE__*/React.createElement(QuoteButton, {
49
+ blockType: blockType,
50
+ api: api
51
+ }) : () => /*#__PURE__*/React.createElement(HeadingButton, {
52
+ blockType: blockType,
53
+ api: api
54
+ })
55
+ };
56
+ toolbarComponents.push(menuItem);
57
+ }
58
+ });
59
+ return toolbarComponents;
60
+ };
@@ -10,6 +10,7 @@ import { blockTypeMessages as messages } from '@atlaskit/editor-common/messages'
10
10
  import { IconHeading, IconQuote } from '@atlaskit/editor-common/quick-insert';
11
11
  import { ToolbarSize } from '@atlaskit/editor-common/types';
12
12
  import { fg } from '@atlaskit/platform-feature-flags';
13
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
13
14
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
14
15
  import { clearFormatting as _clearFormatting, insertBlockQuoteWithAnalytics, insertBlockQuoteWithAnalyticsCommand, setBlockTypeWithAnalytics } from './pm-plugins/commands/block-type';
15
16
  import inputRulePlugin from './pm-plugins/input-rule';
@@ -17,6 +18,7 @@ import keymapPlugin from './pm-plugins/keymap';
17
18
  import { createPlugin, pluginKey } from './pm-plugins/main';
18
19
  import { FloatingToolbarComponent } from './pm-plugins/ui/FloatingToolbarComponent';
19
20
  import { PrimaryToolbarComponent } from './pm-plugins/ui/PrimaryToolbarComponent';
21
+ import { getToolbarComponents } from './pm-plugins/ui/ToolbarComponents';
20
22
  var headingPluginOptions = function headingPluginOptions(_ref, isAllowed, editorAnalyticsApi) {
21
23
  var formatMessage = _ref.formatMessage;
22
24
  if (!isAllowed) {
@@ -93,7 +95,6 @@ var blockquotePluginOptions = function blockquotePluginOptions(_ref2, isAllowed,
93
95
  }];
94
96
  };
95
97
  var blockTypePlugin = function blockTypePlugin(_ref3) {
96
- var _api$primaryToolbar;
97
98
  var options = _ref3.config,
98
99
  api = _ref3.api;
99
100
  var primaryToolbarComponent = function primaryToolbarComponent(_ref4) {
@@ -118,10 +119,16 @@ var blockTypePlugin = function blockTypePlugin(_ref3) {
118
119
  shouldUseDefaultRole: false
119
120
  });
120
121
  };
121
- api === null || api === void 0 || (_api$primaryToolbar = api.primaryToolbar) === null || _api$primaryToolbar === void 0 || _api$primaryToolbar.actions.registerComponent({
122
- name: 'blockType',
123
- component: primaryToolbarComponent
124
- });
122
+ if (expValEquals('platform_editor_toolbar_aifc', 'isEnabled', true)) {
123
+ var _api$toolbar;
124
+ api === null || api === void 0 || (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 || _api$toolbar.actions.registerComponents(getToolbarComponents(api));
125
+ } else {
126
+ var _api$primaryToolbar;
127
+ api === null || api === void 0 || (_api$primaryToolbar = api.primaryToolbar) === null || _api$primaryToolbar === void 0 || _api$primaryToolbar.actions.registerComponent({
128
+ name: 'blockType',
129
+ component: primaryToolbarComponent
130
+ });
131
+ }
125
132
  return {
126
133
  name: 'blockType',
127
134
  nodes: function nodes() {
@@ -199,7 +206,7 @@ var blockTypePlugin = function blockTypePlugin(_ref3) {
199
206
  return pluginKey.getState(editorState);
200
207
  },
201
208
  primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) ? primaryToolbarComponent : undefined,
202
- pluginsOptions: _objectSpread({
209
+ pluginsOptions: _objectSpread(_objectSpread({}, !expValEquals('platform_editor_toolbar_aifc', 'isEnabled', true) && {
203
210
  selectionToolbar: function selectionToolbar() {
204
211
  var _api$userPreferences, _api$selectionToolbar;
205
212
  var toolbarDocking = fg('platform_editor_use_preferences_plugin') ? api === null || api === void 0 || (_api$userPreferences = api.userPreferences) === null || _api$userPreferences === void 0 || (_api$userPreferences = _api$userPreferences.sharedState.currentState()) === null || _api$userPreferences === void 0 || (_api$userPreferences = _api$userPreferences.preferences) === null || _api$userPreferences === void 0 ? void 0 : _api$userPreferences.toolbarDockingPosition : api === null || api === void 0 || (_api$selectionToolbar = api.selectionToolbar) === null || _api$selectionToolbar === void 0 || (_api$selectionToolbar = _api$selectionToolbar.sharedState) === null || _api$selectionToolbar === void 0 || (_api$selectionToolbar = _api$selectionToolbar.currentState()) === null || _api$selectionToolbar === void 0 ? void 0 : _api$selectionToolbar.toolbarDocking;
@@ -227,7 +234,7 @@ var blockTypePlugin = function blockTypePlugin(_ref3) {
227
234
  return undefined;
228
235
  }
229
236
  }
230
- }, editorExperiment('platform_editor_insertion', 'control') && {
237
+ }), editorExperiment('platform_editor_insertion', 'control') && {
231
238
  quickInsert: function quickInsert(intl) {
232
239
  var _api$analytics7, _api$analytics8;
233
240
  var exclude = options && options.allowBlockType && options.allowBlockType.exclude ? options.allowBlockType.exclude : [];
@@ -1,5 +1,10 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1
4
  import React from 'react';
2
5
  import { blockTypeMessages as messages } from '@atlaskit/editor-common/messages';
6
+ import { BLOCK_QUOTE_MENU_ITEM, HEADING_1_MENU_ITEM, HEADING_2_MENU_ITEM, HEADING_3_MENU_ITEM, HEADING_4_MENU_ITEM, HEADING_5_MENU_ITEM, HEADING_6_MENU_ITEM, NORMAL_TEXT_MENU_ITEM, TEXT_STYLES_MENU_SECTION_RANK } from '@atlaskit/editor-common/toolbar';
7
+ import { QuoteIcon } from '@atlaskit/editor-toolbar';
3
8
  import TextHeadingFiveIcon from '@atlaskit/icon-lab/core/text-heading-five';
4
9
  import TextHeadingFourIcon from '@atlaskit/icon-lab/core/text-heading-four';
5
10
  import TextHeadingOneIcon from '@atlaskit/icon-lab/core/text-heading-one';
@@ -107,6 +112,56 @@ export var OTHER = {
107
112
  nodeName: ''
108
113
  };
109
114
  export var TEXT_BLOCK_TYPES = [NORMAL_TEXT, HEADING_1, HEADING_2, HEADING_3, HEADING_4, HEADING_5, HEADING_6];
115
+ var ToolbarBlockTypes = /*#__PURE__*/function (ToolbarBlockTypes) {
116
+ ToolbarBlockTypes["normal"] = "normal";
117
+ ToolbarBlockTypes["heading1"] = "heading1";
118
+ ToolbarBlockTypes["heading2"] = "heading2";
119
+ ToolbarBlockTypes["heading3"] = "heading3";
120
+ ToolbarBlockTypes["heading4"] = "heading4";
121
+ ToolbarBlockTypes["heading5"] = "heading5";
122
+ ToolbarBlockTypes["heading6"] = "heading6";
123
+ ToolbarBlockTypes["blockquote"] = "blockquote";
124
+ return ToolbarBlockTypes;
125
+ }(ToolbarBlockTypes || {});
126
+ export var toolbarBlockTypesWithRank = function toolbarBlockTypesWithRank() {
127
+ return {
128
+ normal: _objectSpread(_objectSpread({}, NORMAL_TEXT), {}, {
129
+ toolbarRank: TEXT_STYLES_MENU_SECTION_RANK[NORMAL_TEXT_MENU_ITEM.key],
130
+ toolbarKey: NORMAL_TEXT_MENU_ITEM.key
131
+ }),
132
+ heading1: _objectSpread(_objectSpread({}, HEADING_1), {}, {
133
+ toolbarRank: TEXT_STYLES_MENU_SECTION_RANK[HEADING_1_MENU_ITEM.key],
134
+ toolbarKey: HEADING_1_MENU_ITEM.key
135
+ }),
136
+ heading2: _objectSpread(_objectSpread({}, HEADING_2), {}, {
137
+ toolbarRank: TEXT_STYLES_MENU_SECTION_RANK[HEADING_2_MENU_ITEM.key],
138
+ toolbarKey: HEADING_2_MENU_ITEM.key
139
+ }),
140
+ heading3: _objectSpread(_objectSpread({}, HEADING_3), {}, {
141
+ toolbarRank: TEXT_STYLES_MENU_SECTION_RANK[HEADING_3_MENU_ITEM.key],
142
+ toolbarKey: HEADING_3_MENU_ITEM.key
143
+ }),
144
+ heading4: _objectSpread(_objectSpread({}, HEADING_4), {}, {
145
+ toolbarRank: TEXT_STYLES_MENU_SECTION_RANK[HEADING_4_MENU_ITEM.key],
146
+ toolbarKey: HEADING_4_MENU_ITEM.key
147
+ }),
148
+ heading5: _objectSpread(_objectSpread({}, HEADING_5), {}, {
149
+ toolbarRank: TEXT_STYLES_MENU_SECTION_RANK[HEADING_5_MENU_ITEM.key],
150
+ toolbarKey: HEADING_5_MENU_ITEM.key
151
+ }),
152
+ heading6: _objectSpread(_objectSpread({}, HEADING_6), {}, {
153
+ toolbarRank: TEXT_STYLES_MENU_SECTION_RANK[HEADING_6_MENU_ITEM.key],
154
+ toolbarKey: HEADING_6_MENU_ITEM.key
155
+ }),
156
+ blockquote: _objectSpread(_objectSpread({}, BLOCK_QUOTE), {}, {
157
+ icon: /*#__PURE__*/React.createElement(QuoteIcon, {
158
+ label: ""
159
+ }),
160
+ toolbarRank: TEXT_STYLES_MENU_SECTION_RANK[BLOCK_QUOTE_MENU_ITEM.key],
161
+ toolbarKey: BLOCK_QUOTE_MENU_ITEM.key
162
+ })
163
+ };
164
+ };
110
165
  export var FORMATTING_NODE_TYPES = ['heading', 'blockquote'];
111
166
  export var FORMATTING_MARK_TYPES = ['em', 'code', 'strike', 'strong', 'underline', 'textColor', 'subsup', 'backgroundColor'];
112
167
  export var WRAPPER_BLOCK_TYPES = [BLOCK_QUOTE, CODE_BLOCK, PANEL];
@@ -0,0 +1,7 @@
1
+ ._11c8140y{font:var(--ds-font-heading-xsmall,normal 600 14px/1pc ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
2
+ ._11c81c04{font:var(--ds-font-heading-xlarge,normal 600 29px/2pc ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
3
+ ._11c81vhk{font:var(--ds-font-heading-xxsmall,normal 600 9pt/1pc ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
4
+ ._11c82smr{font:var(--ds-font-body,normal 400 14px/20px ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
5
+ ._11c8lodh{font:var(--ds-font-heading-medium,normal 500 20px/24px ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
6
+ ._11c8nbxd{font:var(--ds-font-heading-small,normal 600 1pc/20px ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
7
+ ._11c8nf1z{font:var(--ds-font-heading-large,normal 500 24px/28px ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
@@ -0,0 +1,59 @@
1
+ /* HeadingButton.tsx generated by @compiled/babel-plugin v0.36.1 */
2
+ import "./HeadingButton.compiled.css";
3
+ import { ax, ix } from "@compiled/react/runtime";
4
+ import React from 'react';
5
+ import { useIntl } from 'react-intl-next';
6
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
7
+ import { formatShortcut, setNormalText, toggleHeading1, toggleHeading2, toggleHeading3, toggleHeading4, toggleHeading5, toggleHeading6 } from '@atlaskit/editor-common/keymaps';
8
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
9
+ import { ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar';
10
+ import { Box } from '@atlaskit/primitives/compiled';
11
+ var headingSizeStylesMap = {
12
+ normal: "_11c82smr",
13
+ heading1: "_11c81c04",
14
+ heading2: "_11c8nf1z",
15
+ heading3: "_11c8lodh",
16
+ heading4: "_11c8nbxd",
17
+ heading5: "_11c8140y",
18
+ heading6: "_11c81vhk"
19
+ };
20
+ var shortcuts = {
21
+ 'normal': setNormalText,
22
+ 'heading1': toggleHeading1,
23
+ 'heading2': toggleHeading2,
24
+ 'heading3': toggleHeading3,
25
+ 'heading4': toggleHeading4,
26
+ 'heading5': toggleHeading5,
27
+ 'heading6': toggleHeading6
28
+ };
29
+ export var HeadingButton = function HeadingButton(_ref) {
30
+ var blockType = _ref.blockType,
31
+ api = _ref.api;
32
+ var _useIntl = useIntl(),
33
+ formatMessage = _useIntl.formatMessage;
34
+ var currentBlockType = useSharedPluginStateSelector(api, 'blockType.currentBlockType');
35
+ var availableBlockTypesInDropdown = useSharedPluginStateSelector(api, 'blockType.availableBlockTypesInDropdown');
36
+ if (!(availableBlockTypesInDropdown !== null && availableBlockTypesInDropdown !== void 0 && availableBlockTypesInDropdown.some(function (availableBlockType) {
37
+ return availableBlockType.name === blockType.name;
38
+ }))) {
39
+ return null;
40
+ }
41
+ var fromBlockQuote = (currentBlockType === null || currentBlockType === void 0 ? void 0 : currentBlockType.name) === 'blockquote';
42
+ var onClick = function onClick() {
43
+ var _api$core, _api$blockType;
44
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$blockType = api.blockType) === null || _api$blockType === void 0 || (_api$blockType = _api$blockType.commands) === null || _api$blockType === void 0 ? void 0 : _api$blockType.setTextLevel(blockType.name, INPUT_METHOD.TOOLBAR, fromBlockQuote));
45
+ };
46
+ var shortcut = formatShortcut(shortcuts[blockType.name]);
47
+ var isSelected = currentBlockType === blockType;
48
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
49
+ elemBefore: blockType.icon,
50
+ elemAfter: shortcut ? /*#__PURE__*/React.createElement(ToolbarKeyboardShortcutHint, {
51
+ shortcut: shortcut
52
+ }) : undefined,
53
+ onClick: onClick,
54
+ isSelected: isSelected,
55
+ ariaKeyshortcuts: shortcut
56
+ }, /*#__PURE__*/React.createElement(Box, {
57
+ xcss: headingSizeStylesMap[blockType.name]
58
+ }, formatMessage(blockType.title)));
59
+ };
@@ -0,0 +1,33 @@
1
+ import React from 'react';
2
+ import { useIntl } from 'react-intl-next';
3
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
+ import { formatShortcut, toggleBlockQuote } from '@atlaskit/editor-common/keymaps';
5
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
6
+ import { ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar';
7
+ export var QuoteButton = function QuoteButton(_ref) {
8
+ var blockType = _ref.blockType,
9
+ api = _ref.api;
10
+ var _useIntl = useIntl(),
11
+ formatMessage = _useIntl.formatMessage;
12
+ var availableBlockTypesInDropdown = useSharedPluginStateSelector(api, 'blockType.availableBlockTypesInDropdown');
13
+ var currentBlockType = useSharedPluginStateSelector(api, 'blockType.currentBlockType');
14
+ if (!(availableBlockTypesInDropdown !== null && availableBlockTypesInDropdown !== void 0 && availableBlockTypesInDropdown.some(function (availableBlockType) {
15
+ return availableBlockType.name === blockType.name;
16
+ }))) {
17
+ return null;
18
+ }
19
+ var onClick = function onClick() {
20
+ var _api$core, _api$blockType;
21
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$blockType = api.blockType) === null || _api$blockType === void 0 || (_api$blockType = _api$blockType.commands) === null || _api$blockType === void 0 ? void 0 : _api$blockType.insertBlockQuote(INPUT_METHOD.TOOLBAR));
22
+ };
23
+ var shortcut = formatShortcut(toggleBlockQuote);
24
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
25
+ elemBefore: blockType.icon,
26
+ elemAfter: shortcut ? /*#__PURE__*/React.createElement(ToolbarKeyboardShortcutHint, {
27
+ shortcut: shortcut
28
+ }) : undefined,
29
+ onClick: onClick,
30
+ isSelected: currentBlockType === blockType,
31
+ ariaKeyshortcuts: shortcut
32
+ }, formatMessage(blockType.title));
33
+ };
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import { useIntl } from 'react-intl-next';
3
+ import { toolbarMessages } from '@atlaskit/editor-common/messages';
4
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
5
+ import { ToolbarDropdownMenu, ToolbarTooltip, TextIcon } from "@atlaskit/editor-toolbar";
6
+ import { toolbarBlockTypesWithRank } from '../../block-types';
7
+ export var TextStylesMenuButton = function TextStylesMenuButton(_ref) {
8
+ var _Object$values$find;
9
+ var api = _ref.api,
10
+ children = _ref.children;
11
+ var _useIntl = useIntl(),
12
+ formatMessage = _useIntl.formatMessage;
13
+ var blockTypesDisabled = useSharedPluginStateSelector(api, 'blockType.blockTypesDisabled');
14
+ var currentBlockType = useSharedPluginStateSelector(api, 'blockType.currentBlockType');
15
+ var CurrentIcon = (_Object$values$find = Object.values(toolbarBlockTypesWithRank()).find(function (blockType) {
16
+ return blockType.name === (currentBlockType === null || currentBlockType === void 0 ? void 0 : currentBlockType.name);
17
+ })) === null || _Object$values$find === void 0 || (_Object$values$find = _Object$values$find.icon) === null || _Object$values$find === void 0 ? void 0 : _Object$values$find.type;
18
+ return /*#__PURE__*/React.createElement(ToolbarTooltip, {
19
+ content: formatMessage(toolbarMessages.textStylesTooltip)
20
+ }, /*#__PURE__*/React.createElement(ToolbarDropdownMenu, {
21
+ isDisabled: blockTypesDisabled,
22
+ iconBefore: CurrentIcon ? /*#__PURE__*/React.createElement(CurrentIcon, {
23
+ label: "".concat(currentBlockType === null || currentBlockType === void 0 ? void 0 : currentBlockType.name, " ").concat(formatMessage(toolbarMessages.textStylesTooltip))
24
+ }) : /*#__PURE__*/React.createElement(TextIcon, {
25
+ label: formatMessage(toolbarMessages.textStylesTooltip)
26
+ })
27
+ }, children));
28
+ };
@@ -0,0 +1,65 @@
1
+ import React from 'react';
2
+ import { TEXT_STYLES_GROUP, TEXT_SECTION_RANK, TEXT_SECTION, TEXT_STYLES_MENU, TEXT_STYLES_GROUP_RANK, TEXT_STYLES_MENU_SECTION, TEXT_STYLES_MENU_RANK } from '@atlaskit/editor-common/toolbar';
3
+ import { toolbarBlockTypesWithRank } from '../block-types';
4
+ import { HeadingButton } from './ToolbarBlockType/HeadingButton';
5
+ import { QuoteButton } from './ToolbarBlockType/QuoteButton';
6
+ import { TextStylesMenuButton } from './ToolbarBlockType/TextStylesMenuButton';
7
+ export var getToolbarComponents = function getToolbarComponents(api) {
8
+ var toolbarComponents = [{
9
+ type: TEXT_STYLES_GROUP.type,
10
+ key: TEXT_STYLES_GROUP.key,
11
+ parents: [{
12
+ type: TEXT_SECTION.type,
13
+ key: TEXT_SECTION.key,
14
+ rank: TEXT_SECTION_RANK[TEXT_STYLES_GROUP.key]
15
+ }]
16
+ }, {
17
+ type: TEXT_STYLES_MENU.type,
18
+ key: TEXT_STYLES_MENU.key,
19
+ parents: [{
20
+ type: TEXT_STYLES_GROUP.type,
21
+ key: TEXT_STYLES_GROUP.key,
22
+ rank: TEXT_STYLES_GROUP_RANK[TEXT_STYLES_MENU.key]
23
+ }],
24
+ component: function component(_ref) {
25
+ var children = _ref.children;
26
+ return /*#__PURE__*/React.createElement(TextStylesMenuButton, {
27
+ api: api
28
+ }, children);
29
+ }
30
+ }, {
31
+ type: TEXT_STYLES_MENU_SECTION.type,
32
+ key: TEXT_STYLES_MENU_SECTION.key,
33
+ parents: [{
34
+ type: TEXT_STYLES_MENU.type,
35
+ key: TEXT_STYLES_MENU.key,
36
+ rank: TEXT_STYLES_MENU_RANK[TEXT_STYLES_MENU_SECTION.key]
37
+ }]
38
+ }];
39
+ Object.values(toolbarBlockTypesWithRank()).forEach(function (blockType) {
40
+ if (blockType.toolbarKey) {
41
+ var menuItem = {
42
+ type: 'menu-item',
43
+ key: blockType.toolbarKey,
44
+ parents: [{
45
+ type: TEXT_STYLES_MENU_SECTION.type,
46
+ key: TEXT_STYLES_MENU_SECTION.key,
47
+ rank: blockType.toolbarRank
48
+ }],
49
+ component: blockType.name === 'blockquote' ? function () {
50
+ return /*#__PURE__*/React.createElement(QuoteButton, {
51
+ blockType: blockType,
52
+ api: api
53
+ });
54
+ } : function () {
55
+ return /*#__PURE__*/React.createElement(HeadingButton, {
56
+ blockType: blockType,
57
+ api: api
58
+ });
59
+ }
60
+ };
61
+ toolbarComponents.push(menuItem);
62
+ }
63
+ });
64
+ return toolbarComponents;
65
+ };
@@ -2,6 +2,7 @@ import type { Command, EditorCommand, NextEditorPlugin, OptionalPlugin } from '@
2
2
  import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
3
3
  import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
4
4
  import type { SelectionToolbarPlugin } from '@atlaskit/editor-plugin-selection-toolbar';
5
+ import type { ToolbarPlugin } from '@atlaskit/editor-plugin-toolbar';
5
6
  import type { UserPreferencesPlugin } from '@atlaskit/editor-plugin-user-preferences';
6
7
  import type { TextBlockTypes } from './pm-plugins/block-types';
7
8
  import type { ClearFormattingInputMethod, InputMethod } from './pm-plugins/commands/block-type';
@@ -13,7 +14,8 @@ export type BlockTypePlugin = NextEditorPlugin<'blockType', {
13
14
  OptionalPlugin<AnalyticsPlugin>,
14
15
  OptionalPlugin<PrimaryToolbarPlugin>,
15
16
  OptionalPlugin<SelectionToolbarPlugin>,
16
- OptionalPlugin<UserPreferencesPlugin>
17
+ OptionalPlugin<UserPreferencesPlugin>,
18
+ OptionalPlugin<ToolbarPlugin>
17
19
  ];
18
20
  sharedState: BlockTypeState | undefined;
19
21
  actions: {
@@ -1,4 +1,4 @@
1
- import type { BlockType } from './types';
1
+ import type { BlockType, BlockTypeWithRank } from './types';
2
2
  export declare const NORMAL_TEXT: BlockType;
3
3
  export declare const HEADING_1: BlockType;
4
4
  export declare const HEADING_2: BlockType;
@@ -11,6 +11,17 @@ 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
+ declare enum ToolbarBlockTypes {
15
+ normal = "normal",
16
+ heading1 = "heading1",
17
+ heading2 = "heading2",
18
+ heading3 = "heading3",
19
+ heading4 = "heading4",
20
+ heading5 = "heading5",
21
+ heading6 = "heading6",
22
+ blockquote = "blockquote"
23
+ }
24
+ export declare const toolbarBlockTypesWithRank: () => Record<ToolbarBlockTypes, BlockTypeWithRank>;
14
25
  export type TextBlockTypes = 'normal' | 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6';
15
26
  export declare const FORMATTING_NODE_TYPES: string[];
16
27
  export declare const FORMATTING_MARK_TYPES: string[];
@@ -21,3 +32,4 @@ export declare const HEADINGS_BY_LEVEL: Record<number, BlockType>;
21
32
  export declare const HEADINGS_BY_NAME: {
22
33
  [blockType: string]: BlockType;
23
34
  };
35
+ export {};
@@ -12,6 +12,10 @@ export interface BlockType {
12
12
  icon?: ReactElement;
13
13
  LEGACY_icon?: ReactElement;
14
14
  }
15
+ export interface BlockTypeWithRank extends BlockType {
16
+ toolbarRank: number;
17
+ toolbarKey: string;
18
+ }
15
19
  export interface BlockTypeNode {
16
20
  name: AllowedBlockTypes;
17
21
  node: NodeSpec;
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { BlockTypePlugin } from '../../../blockTypePluginType';
4
+ import type { BlockTypeWithRank } from '../../types';
5
+ type HeadingButtonProps = {
6
+ blockType: BlockTypeWithRank;
7
+ api?: ExtractInjectionAPI<BlockTypePlugin>;
8
+ };
9
+ export declare const HeadingButton: ({ blockType, api }: HeadingButtonProps) => React.JSX.Element | null;
10
+ export {};
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { BlockTypePlugin } from '../../../blockTypePluginType';
4
+ import type { BlockTypeWithRank } from '../../types';
5
+ type QuoteButtonProps = {
6
+ blockType: BlockTypeWithRank;
7
+ api?: ExtractInjectionAPI<BlockTypePlugin>;
8
+ };
9
+ export declare const QuoteButton: ({ blockType, api }: QuoteButtonProps) => React.JSX.Element | null;
10
+ export {};
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { BlockTypePlugin } from '../../../blockTypePluginType';
4
+ type TextStylesMenuButtonProps = {
5
+ api?: ExtractInjectionAPI<BlockTypePlugin>;
6
+ children: React.ReactNode;
7
+ };
8
+ export declare const TextStylesMenuButton: ({ api, children }: TextStylesMenuButtonProps) => React.JSX.Element;
9
+ export {};
@@ -0,0 +1,4 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { RegisterComponent } from '@atlaskit/editor-toolbar-model';
3
+ import type { BlockTypePlugin } from '../../blockTypePluginType';
4
+ export declare const getToolbarComponents: (api?: ExtractInjectionAPI<BlockTypePlugin>) => RegisterComponent[];
@@ -2,6 +2,7 @@ import type { Command, EditorCommand, NextEditorPlugin, OptionalPlugin } from '@
2
2
  import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
3
3
  import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
4
4
  import type { SelectionToolbarPlugin } from '@atlaskit/editor-plugin-selection-toolbar';
5
+ import type { ToolbarPlugin } from '@atlaskit/editor-plugin-toolbar';
5
6
  import type { UserPreferencesPlugin } from '@atlaskit/editor-plugin-user-preferences';
6
7
  import type { TextBlockTypes } from './pm-plugins/block-types';
7
8
  import type { ClearFormattingInputMethod, InputMethod } from './pm-plugins/commands/block-type';
@@ -13,7 +14,8 @@ export type BlockTypePlugin = NextEditorPlugin<'blockType', {
13
14
  OptionalPlugin<AnalyticsPlugin>,
14
15
  OptionalPlugin<PrimaryToolbarPlugin>,
15
16
  OptionalPlugin<SelectionToolbarPlugin>,
16
- OptionalPlugin<UserPreferencesPlugin>
17
+ OptionalPlugin<UserPreferencesPlugin>,
18
+ OptionalPlugin<ToolbarPlugin>
17
19
  ];
18
20
  sharedState: BlockTypeState | undefined;
19
21
  actions: {