@atlaskit/editor-plugin-block-type 4.0.11 → 4.0.13

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 (46) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cjs/blockTypePlugin.js +9 -4
  3. package/dist/cjs/pm-plugins/block-types.js +9 -2
  4. package/dist/cjs/pm-plugins/commands/block-type.js +64 -15
  5. package/dist/cjs/pm-plugins/commands/wrapSelectionIn.js +61 -0
  6. package/dist/cjs/pm-plugins/main.js +12 -4
  7. package/dist/cjs/pm-plugins/ui/FloatingToolbarComponent.js +5 -0
  8. package/dist/cjs/pm-plugins/ui/PrimaryToolbarComponent.js +7 -2
  9. package/dist/cjs/pm-plugins/ui/ToolbarBlockType/index.js +22 -19
  10. package/dist/cjs/pm-plugins/ui/ToolbarBlockType/styled.js +1 -1
  11. package/dist/cjs/pm-plugins/utils.js +17 -1
  12. package/dist/es2019/blockTypePlugin.js +10 -6
  13. package/dist/es2019/pm-plugins/block-types.js +8 -1
  14. package/dist/es2019/pm-plugins/commands/block-type.js +61 -13
  15. package/dist/es2019/pm-plugins/commands/wrapSelectionIn.js +54 -0
  16. package/dist/es2019/pm-plugins/main.js +11 -5
  17. package/dist/es2019/pm-plugins/ui/FloatingToolbarComponent.js +5 -0
  18. package/dist/es2019/pm-plugins/ui/PrimaryToolbarComponent.js +7 -2
  19. package/dist/es2019/pm-plugins/ui/ToolbarBlockType/index.js +12 -6
  20. package/dist/es2019/pm-plugins/ui/ToolbarBlockType/styled.js +2 -2
  21. package/dist/es2019/pm-plugins/utils.js +15 -1
  22. package/dist/esm/blockTypePlugin.js +10 -5
  23. package/dist/esm/pm-plugins/block-types.js +8 -1
  24. package/dist/esm/pm-plugins/commands/block-type.js +62 -15
  25. package/dist/esm/pm-plugins/commands/wrapSelectionIn.js +55 -0
  26. package/dist/esm/pm-plugins/main.js +13 -5
  27. package/dist/esm/pm-plugins/ui/FloatingToolbarComponent.js +5 -0
  28. package/dist/esm/pm-plugins/ui/PrimaryToolbarComponent.js +7 -2
  29. package/dist/esm/pm-plugins/ui/ToolbarBlockType/index.js +22 -19
  30. package/dist/esm/pm-plugins/ui/ToolbarBlockType/styled.js +2 -2
  31. package/dist/esm/pm-plugins/utils.js +17 -1
  32. package/dist/types/blockTypePluginType.d.ts +2 -1
  33. package/dist/types/pm-plugins/block-types.d.ts +1 -0
  34. package/dist/types/pm-plugins/commands/block-type.d.ts +6 -4
  35. package/dist/types/pm-plugins/commands/wrapSelectionIn.d.ts +3 -0
  36. package/dist/types/pm-plugins/main.d.ts +3 -1
  37. package/dist/types/pm-plugins/types.d.ts +1 -0
  38. package/dist/types/pm-plugins/ui/ToolbarBlockType/index.d.ts +2 -1
  39. package/dist/types-ts4.5/blockTypePluginType.d.ts +2 -1
  40. package/dist/types-ts4.5/pm-plugins/block-types.d.ts +1 -0
  41. package/dist/types-ts4.5/pm-plugins/commands/block-type.d.ts +6 -4
  42. package/dist/types-ts4.5/pm-plugins/commands/wrapSelectionIn.d.ts +3 -0
  43. package/dist/types-ts4.5/pm-plugins/main.d.ts +3 -1
  44. package/dist/types-ts4.5/pm-plugins/types.d.ts +1 -0
  45. package/dist/types-ts4.5/pm-plugins/ui/ToolbarBlockType/index.d.ts +2 -1
  46. package/package.json +5 -5
@@ -0,0 +1,55 @@
1
+ import { Slice, Fragment } from '@atlaskit/editor-prosemirror/model';
2
+ import { findWrapping } from '@atlaskit/editor-prosemirror/transform';
3
+ export function wrapSelectionInBlockType(nodeType) {
4
+ return function (_ref) {
5
+ var tr = _ref.tr;
6
+ var nodes = tr.doc.type.schema.nodes;
7
+ var _tr$doc$type$schema$m = tr.doc.type.schema.marks,
8
+ alignment = _tr$doc$type$schema$m.alignment,
9
+ indentation = _tr$doc$type$schema$m.indentation;
10
+ if (nodes.paragraph && nodes.blockquote) {
11
+ /**Remove alignment and indentation marks from the selection */
12
+ var marksToRemove = [alignment, indentation];
13
+ var hasMark = function hasMark(mark) {
14
+ return marksToRemove.indexOf(mark.type) > -1;
15
+ };
16
+ var not = function not(fn) {
17
+ return function (arg) {
18
+ return !fn(arg);
19
+ };
20
+ };
21
+
22
+ /**
23
+ * When you need to toggle the selection
24
+ * when another type which does not allow alignment is applied
25
+ */
26
+ tr.doc.nodesBetween(tr.selection.from, tr.selection.to, function (node, pos) {
27
+ if (node.type === nodes.paragraph && node.marks.some(hasMark)) {
28
+ var resolvedPos = tr.doc.resolve(pos);
29
+ var withoutBlockMarks = node.marks.filter(not(hasMark));
30
+ tr = tr.setNodeMarkup(resolvedPos.pos, undefined, node.attrs, withoutBlockMarks);
31
+ }
32
+ });
33
+
34
+ /** Get range and wrapping needed for the selection */
35
+ var _tr$selection = tr.selection,
36
+ $from = _tr$selection.$from,
37
+ $to = _tr$selection.$to;
38
+ var range = $from.blockRange($to);
39
+ var wrapping = range && findWrapping(range, nodes.blockquote);
40
+ if (wrapping) {
41
+ /** Wrap the selection */
42
+ tr.wrap(range, wrapping).scrollIntoView();
43
+ } else {
44
+ /** If wrapping is not possible, replace with a blockquote */
45
+ var start = $from.start();
46
+ var end = $to.end();
47
+ var content = $from.node().content;
48
+ var blockquote = nodes.blockquote.create({}, nodes.paragraph.create({}, content));
49
+ var slice = new Slice(Fragment.from(blockquote), 0, 0);
50
+ tr.replaceRange(start, end, slice).scrollIntoView();
51
+ }
52
+ }
53
+ return tr;
54
+ };
55
+ }
@@ -6,7 +6,7 @@ import { browser } from '@atlaskit/editor-common/browser';
6
6
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
7
7
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
8
8
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
9
- import { BLOCK_QUOTE, CODE_BLOCK, HEADING_1, HEADING_2, HEADING_3, HEADING_4, HEADING_5, HEADING_6, HEADINGS_BY_LEVEL, NORMAL_TEXT, OTHER, PANEL, TEXT_BLOCK_TYPES, WRAPPER_BLOCK_TYPES } from './block-types';
9
+ import { BLOCK_QUOTE, CODE_BLOCK, HEADING_1, HEADING_2, HEADING_3, HEADING_4, HEADING_5, HEADING_6, HEADINGS_BY_LEVEL, NORMAL_TEXT, OTHER, PANEL, TEXT_BLOCK_TYPES, WRAPPER_BLOCK_TYPES, getBlockTypesInDropdown } from './block-types';
10
10
  import { setHeadingWithAnalytics, setNormalTextWithAnalytics } from './commands/block-type';
11
11
  import { HEADING_KEYS } from './consts';
12
12
  import { areBlockTypesDisabled } from './utils';
@@ -18,6 +18,8 @@ var blockTypeForNode = function blockTypeForNode(node, schema) {
18
18
  }
19
19
  } else if (node.type === schema.nodes.paragraph) {
20
20
  return NORMAL_TEXT;
21
+ } else if (node.type === schema.nodes.blockquote) {
22
+ return BLOCK_QUOTE;
21
23
  }
22
24
  return OTHER;
23
25
  };
@@ -60,6 +62,7 @@ var detectBlockType = function detectBlockType(availableBlockTypes, state) {
60
62
  } else if (blockType !== OTHER && blockType !== nodeBlockType[0]) {
61
63
  blockType = OTHER;
62
64
  }
65
+ return false;
63
66
  }
64
67
  });
65
68
  return blockType || OTHER;
@@ -71,7 +74,7 @@ var autoformatHeading = function autoformatHeading(headingLevel, editorAnalytics
71
74
  return setHeadingWithAnalytics(headingLevel, INPUT_METHOD.FORMATTING, editorAnalyticsApi);
72
75
  };
73
76
  export var pluginKey = new PluginKey('blockTypePlugin');
74
- export var createPlugin = function createPlugin(editorAPI, dispatch, lastNodeMustBeParagraph) {
77
+ export var createPlugin = function createPlugin(editorAPI, dispatch, lastNodeMustBeParagraph, includeBlockQuoteAsTextstyleOption) {
75
78
  var _editorAPI$analytics;
76
79
  var editorAnalyticsApi = editorAPI === null || editorAPI === void 0 || (_editorAPI$analytics = editorAPI.analytics) === null || _editorAPI$analytics === void 0 ? void 0 : _editorAPI$analytics.actions;
77
80
  var altKeyLocation = 0;
@@ -94,16 +97,21 @@ export var createPlugin = function createPlugin(editorAPI, dispatch, lastNodeMus
94
97
  var availableWrapperBlockTypes = WRAPPER_BLOCK_TYPES.filter(function (blockType) {
95
98
  return isBlockTypeSchemaSupported(blockType, state);
96
99
  });
100
+ var BLOCK_TYPES_IN_DROPDOWN = getBlockTypesInDropdown(includeBlockQuoteAsTextstyleOption);
101
+ var availableBlockTypesInDropdown = BLOCK_TYPES_IN_DROPDOWN.filter(function (blockType) {
102
+ return isBlockTypeSchemaSupported(blockType, state);
103
+ });
97
104
  return {
98
- currentBlockType: detectBlockType(availableBlockTypes, state),
105
+ currentBlockType: detectBlockType(availableBlockTypesInDropdown, state),
99
106
  blockTypesDisabled: areBlockTypesDisabled(state),
100
107
  availableBlockTypes: availableBlockTypes,
101
- availableWrapperBlockTypes: availableWrapperBlockTypes
108
+ availableWrapperBlockTypes: availableWrapperBlockTypes,
109
+ availableBlockTypesInDropdown: availableBlockTypesInDropdown
102
110
  };
103
111
  },
104
112
  apply: function apply(_tr, oldPluginState, _oldState, newState) {
105
113
  var newPluginState = _objectSpread(_objectSpread({}, oldPluginState), {}, {
106
- currentBlockType: detectBlockType(oldPluginState.availableBlockTypes, newState),
114
+ currentBlockType: detectBlockType(oldPluginState.availableBlockTypesInDropdown, newState),
107
115
  blockTypesDisabled: areBlockTypesDisabled(newState)
108
116
  });
109
117
  if (newPluginState.currentBlockType !== oldPluginState.currentBlockType || newPluginState.blockTypesDisabled !== oldPluginState.blockTypesDisabled) {
@@ -16,12 +16,17 @@ export function FloatingToolbarComponent(_ref) {
16
16
  var _api$core, _api$blockType;
17
17
  return api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 ? 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(name, INPUT_METHOD.FLOATING_TB));
18
18
  }, [api]);
19
+ var wrapBlockQuote = useCallback(function () {
20
+ var _api$core2, _api$blockType2;
21
+ return api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions.execute(api === null || api === void 0 || (_api$blockType2 = api.blockType) === null || _api$blockType2 === void 0 || (_api$blockType2 = _api$blockType2.commands) === null || _api$blockType2 === void 0 ? void 0 : _api$blockType2.insertBlockQuote(INPUT_METHOD.TOOLBAR));
22
+ }, [api]);
19
23
  return /*#__PURE__*/React.createElement(ToolbarBlockType, {
20
24
  isSmall: FloatingToolbarSettings.isSmall,
21
25
  isDisabled: FloatingToolbarSettings.disabled,
22
26
  isReducedSpacing: FloatingToolbarSettings.isToolbarReducedSpacing,
23
27
  setTextLevel: boundSetBlockType,
24
28
  pluginState: blockTypeState,
29
+ wrapBlockQuote: wrapBlockQuote,
25
30
  shouldUseDefaultRole: FloatingToolbarSettings.shouldUseDefaultRole,
26
31
  api: api
27
32
  });
@@ -13,15 +13,20 @@ export function PrimaryToolbarComponent(_ref) {
13
13
  shouldUseDefaultRole = _ref.shouldUseDefaultRole;
14
14
  var _useSharedPluginState = useSharedPluginState(api, ['blockType']),
15
15
  blockTypeState = _useSharedPluginState.blockTypeState;
16
- var boundSetBlockType = function boundSetBlockType(name) {
16
+ var boundSetBlockType = function boundSetBlockType(name, fromBlockQuote) {
17
17
  var _api$core, _api$blockType;
18
- return api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 ? 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(name, INPUT_METHOD.TOOLBAR));
18
+ return api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 ? 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(name, INPUT_METHOD.TOOLBAR, fromBlockQuote));
19
+ };
20
+ var wrapBlockQuote = function wrapBlockQuote() {
21
+ var _api$core2, _api$blockType2;
22
+ return api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions.execute(api === null || api === void 0 || (_api$blockType2 = api.blockType) === null || _api$blockType2 === void 0 || (_api$blockType2 = _api$blockType2.commands) === null || _api$blockType2 === void 0 ? void 0 : _api$blockType2.insertBlockQuote(INPUT_METHOD.TOOLBAR));
19
23
  };
20
24
  return /*#__PURE__*/React.createElement(ToolbarBlockType, {
21
25
  isSmall: isSmall,
22
26
  isDisabled: disabled,
23
27
  isReducedSpacing: isToolbarReducedSpacing,
24
28
  setTextLevel: boundSetBlockType,
29
+ wrapBlockQuote: wrapBlockQuote,
25
30
  pluginState: blockTypeState,
26
31
  popupsMountPoint: popupsMountPoint,
27
32
  popupsBoundariesElement: popupsBoundariesElement,
@@ -1,13 +1,12 @@
1
1
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
2
  import _createClass from "@babel/runtime/helpers/createClass";
3
- import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
4
- import _inherits from "@babel/runtime/helpers/inherits";
5
3
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
4
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
5
+ import _inherits from "@babel/runtime/helpers/inherits";
7
6
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
7
  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; }
9
8
  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; }
10
- function _createSuper(t) { var r = _isNativeReflectConstruct(); return function () { var e, o = _getPrototypeOf(t); if (r) { var s = _getPrototypeOf(this).constructor; e = Reflect.construct(o, arguments, s); } else e = o.apply(this, arguments); return _possibleConstructorReturn(this, e); }; }
9
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
11
10
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
12
11
  /**
13
12
  * @jsxRuntime classic
@@ -27,35 +26,33 @@ import { BlockTypeButton } from './blocktype-button';
27
26
  import { blockTypeMenuItemStyle, keyboardShortcut, keyboardShortcutSelect } from './styled';
28
27
  // eslint-disable-next-line @repo/internal/react/no-class-components
29
28
  var ToolbarBlockType = /*#__PURE__*/function (_React$PureComponent) {
30
- _inherits(ToolbarBlockType, _React$PureComponent);
31
- var _super = _createSuper(ToolbarBlockType);
32
29
  function ToolbarBlockType() {
33
30
  var _this;
34
31
  _classCallCheck(this, ToolbarBlockType);
35
32
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
36
33
  args[_key] = arguments[_key];
37
34
  }
38
- _this = _super.call.apply(_super, [this].concat(args));
39
- _defineProperty(_assertThisInitialized(_this), "state", {
35
+ _this = _callSuper(this, ToolbarBlockType, [].concat(args));
36
+ _defineProperty(_this, "state", {
40
37
  active: false,
41
38
  isOpenedByKeyboard: false,
42
39
  typographyTheme: undefined,
43
40
  observer: null
44
41
  });
45
42
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
46
- _defineProperty(_assertThisInitialized(_this), "onOpenChange", function (attrs) {
43
+ _defineProperty(_this, "onOpenChange", function (attrs) {
47
44
  _this.setState(_objectSpread(_objectSpread({}, _this.state), {}, {
48
45
  active: attrs.isOpen,
49
46
  isOpenedByKeyboard: attrs.isOpenedByKeyboard
50
47
  }));
51
48
  });
52
- _defineProperty(_assertThisInitialized(_this), "handleTriggerClick", function () {
49
+ _defineProperty(_this, "handleTriggerClick", function () {
53
50
  _this.onOpenChange({
54
51
  isOpen: !_this.state.active,
55
52
  isOpenedByKeyboard: false
56
53
  });
57
54
  });
58
- _defineProperty(_assertThisInitialized(_this), "handleTriggerByKeyboard", function (event) {
55
+ _defineProperty(_this, "handleTriggerByKeyboard", function (event) {
59
56
  if (event.key === 'Enter' || event.key === ' ') {
60
57
  event.preventDefault();
61
58
  _this.onOpenChange({
@@ -64,12 +61,12 @@ var ToolbarBlockType = /*#__PURE__*/function (_React$PureComponent) {
64
61
  });
65
62
  }
66
63
  });
67
- _defineProperty(_assertThisInitialized(_this), "createItems", function () {
64
+ _defineProperty(_this, "createItems", function () {
68
65
  var formatMessage = _this.props.intl.formatMessage;
69
66
  var _this$props$pluginSta = _this.props.pluginState,
70
67
  currentBlockType = _this$props$pluginSta.currentBlockType,
71
- availableBlockTypes = _this$props$pluginSta.availableBlockTypes;
72
- var items = availableBlockTypes.map(function (blockType, index) {
68
+ availableBlockTypesInDropdown = _this$props$pluginSta.availableBlockTypesInDropdown;
69
+ var items = availableBlockTypesInDropdown.map(function (blockType, index) {
73
70
  var isActive = currentBlockType === blockType;
74
71
  var tagName = blockType.tagName || 'p';
75
72
  var Tag = tagName;
@@ -97,12 +94,17 @@ var ToolbarBlockType = /*#__PURE__*/function (_React$PureComponent) {
97
94
  items: items
98
95
  }];
99
96
  });
100
- _defineProperty(_assertThisInitialized(_this), "handleSelectBlockType", function (_ref) {
97
+ _defineProperty(_this, "handleSelectBlockType", function (_ref) {
101
98
  var item = _ref.item,
102
99
  _ref$shouldCloseMenu = _ref.shouldCloseMenu,
103
100
  shouldCloseMenu = _ref$shouldCloseMenu === void 0 ? true : _ref$shouldCloseMenu;
104
101
  var blockType = item.value;
105
- _this.props.setTextLevel(blockType.name);
102
+ if (blockType.name === 'blockquote') {
103
+ _this.props.wrapBlockQuote(blockType.name);
104
+ } else {
105
+ var fromBlockQuote = _this.props.pluginState.currentBlockType.name === 'blockquote';
106
+ _this.props.setTextLevel(blockType.name, fromBlockQuote);
107
+ }
106
108
  if (shouldCloseMenu) {
107
109
  _this.setState(_objectSpread(_objectSpread({}, _this.state), {}, {
108
110
  active: false
@@ -111,7 +113,8 @@ var ToolbarBlockType = /*#__PURE__*/function (_React$PureComponent) {
111
113
  });
112
114
  return _this;
113
115
  }
114
- _createClass(ToolbarBlockType, [{
116
+ _inherits(ToolbarBlockType, _React$PureComponent);
117
+ return _createClass(ToolbarBlockType, [{
115
118
  key: "componentDidMount",
116
119
  value: function componentDidMount() {
117
120
  var _this2 = this;
@@ -151,6 +154,7 @@ var ToolbarBlockType = /*#__PURE__*/function (_React$PureComponent) {
151
154
  currentBlockType = _this$props$pluginSta2.currentBlockType,
152
155
  blockTypesDisabled = _this$props$pluginSta2.blockTypesDisabled,
153
156
  availableBlockTypes = _this$props$pluginSta2.availableBlockTypes,
157
+ availableBlockTypesInDropdown = _this$props$pluginSta2.availableBlockTypesInDropdown,
154
158
  shouldUseDefaultRole = _this$props.shouldUseDefaultRole,
155
159
  formatMessage = _this$props.intl.formatMessage,
156
160
  api = _this$props.api;
@@ -160,12 +164,12 @@ var ToolbarBlockType = /*#__PURE__*/function (_React$PureComponent) {
160
164
  if (isHeadingDisabled) {
161
165
  return null;
162
166
  }
163
- var blockTypeTitles = availableBlockTypes.filter(function (blockType) {
167
+ var blockTypeTitles = availableBlockTypesInDropdown.filter(function (blockType) {
164
168
  return blockType.name === currentBlockType.name;
165
169
  }).map(function (blockType) {
166
170
  return blockType.title;
167
171
  });
168
- if (!this.props.isDisabled && !blockTypesDisabled) {
172
+ if (!this.props.isDisabled && (!blockTypesDisabled || currentBlockType.name === 'blockquote')) {
169
173
  var items = this.createItems();
170
174
  return (
171
175
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage, @atlaskit/ui-styling-standard/no-imported-style-values -- Ignored via go/DSP-18766
@@ -231,6 +235,5 @@ var ToolbarBlockType = /*#__PURE__*/function (_React$PureComponent) {
231
235
  );
232
236
  }
233
237
  }]);
234
- return ToolbarBlockType;
235
238
  }(React.PureComponent);
236
239
  export default injectIntl(ToolbarBlockType);
@@ -4,7 +4,7 @@
4
4
  */
5
5
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
6
6
  import { css } from '@emotion/react';
7
- import { headingsSharedStyles } from '@atlaskit/editor-common/styles';
7
+ import { headingsSharedStyles, blockquoteSharedStyles } from '@atlaskit/editor-common/styles';
8
8
  import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
9
9
  import { N400 } from '@atlaskit/theme/colors';
10
10
  export var blockTypeMenuItemStyle = function blockTypeMenuItemStyle(tagName, selected, typographyTheme) {
@@ -13,7 +13,7 @@ export var blockTypeMenuItemStyle = function blockTypeMenuItemStyle(tagName, sel
13
13
  return function () {
14
14
  return css(
15
15
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
16
- headingsSharedStyles(typographyTheme), {
16
+ tagName === 'blockquote' ? blockquoteSharedStyles : headingsSharedStyles(typographyTheme), {
17
17
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766
18
18
  '>': {
19
19
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766
@@ -1,5 +1,6 @@
1
1
  import { createRule, createWrappingJoinRule } from '@atlaskit/editor-common/utils';
2
2
  import { fg } from '@atlaskit/platform-feature-flags';
3
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
3
4
  import { WRAPPER_BLOCK_TYPES } from './block-types';
4
5
  export var isNodeAWrappingBlockNode = function isNodeAWrappingBlockNode(node) {
5
6
  if (!node) {
@@ -75,7 +76,22 @@ function getSelectedWrapperNodes(state) {
75
76
  */
76
77
  export function areBlockTypesDisabled(state) {
77
78
  var nodesTypes = getSelectedWrapperNodes(state);
78
- var panel = state.schema.nodes.panel;
79
+ var _state$schema$nodes2 = state.schema.nodes,
80
+ panel = _state$schema$nodes2.panel,
81
+ blockquote = _state$schema$nodes2.blockquote;
82
+ if (editorExperiment('platform_editor_blockquote_in_text_formatting_menu', true)) {
83
+ var hasQuote = false;
84
+ var _state$selection2 = state.selection,
85
+ $from = _state$selection2.$from,
86
+ $to = _state$selection2.$to;
87
+ state.doc.nodesBetween($from.pos, $to.pos, function (node) {
88
+ hasQuote = node.type === blockquote;
89
+ return !hasQuote;
90
+ });
91
+ return nodesTypes.filter(function (type) {
92
+ return type !== panel;
93
+ }).length > 0 || hasQuote;
94
+ }
79
95
  return nodesTypes.filter(function (type) {
80
96
  return type !== panel;
81
97
  }).length > 0;
@@ -13,6 +13,7 @@ export type BlockTypePlugin = NextEditorPlugin<'blockType', {
13
13
  insertBlockQuote: (inputMethod: InputMethod) => Command;
14
14
  };
15
15
  commands: {
16
- setTextLevel: (level: TextBlockTypes, inputMethod: InputMethod) => EditorCommand;
16
+ setTextLevel: (level: TextBlockTypes, inputMethod: InputMethod, fromBlockQuote?: boolean) => EditorCommand;
17
+ insertBlockQuote: (inputMethod: InputMethod) => EditorCommand;
17
18
  };
18
19
  }>;
@@ -14,6 +14,7 @@ export declare const TEXT_BLOCK_TYPES: BlockType[];
14
14
  export type TextBlockTypes = 'normal' | 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6';
15
15
  export declare const WRAPPER_BLOCK_TYPES: BlockType[];
16
16
  export declare const ALL_BLOCK_TYPES: BlockType[];
17
+ export declare const getBlockTypesInDropdown: (includeBlockQuoteAsTextstyleOption?: boolean) => BlockType[];
17
18
  export declare const HEADINGS_BY_LEVEL: Record<number, BlockType>;
18
19
  export declare const HEADINGS_BY_NAME: {
19
20
  [blockType: string]: BlockType;
@@ -3,10 +3,11 @@ import type { Command, EditorCommand, HeadingLevelsAndNormalText } from '@atlask
3
3
  import type { TextBlockTypes } from '../block-types';
4
4
  export type InputMethod = INPUT_METHOD.TOOLBAR | INPUT_METHOD.INSERT_MENU | INPUT_METHOD.SHORTCUT | INPUT_METHOD.FORMATTING | INPUT_METHOD.KEYBOARD | INPUT_METHOD.FLOATING_TB;
5
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 setNormalTextWithAnalytics(inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined): EditorCommand;
9
- export declare const setHeadingWithAnalytics: (newHeadingLevel: HeadingLevelsAndNormalText, inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined) => EditorCommand;
6
+ export declare function setHeading(level: HeadingLevelsAndNormalText, fromBlockQuote?: boolean): EditorCommand;
7
+ export declare function setBlockTypeWithAnalytics(name: TextBlockTypes, inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined, fromBlockQuote?: boolean): EditorCommand;
8
+ export declare function setNormalText(fromBlockQuote?: boolean): EditorCommand;
9
+ export declare function setNormalTextWithAnalytics(inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined, fromBlockQuote?: boolean): EditorCommand;
10
+ export declare const setHeadingWithAnalytics: (newHeadingLevel: HeadingLevelsAndNormalText, inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined, fromBlockQuote?: boolean) => EditorCommand;
10
11
  /**
11
12
  *
12
13
  * @param name - block type name
@@ -16,4 +17,5 @@ export declare const setHeadingWithAnalytics: (newHeadingLevel: HeadingLevelsAnd
16
17
  * @returns - command that inserts block type
17
18
  */
18
19
  export declare const insertBlockQuoteWithAnalytics: (inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined) => Command;
20
+ export declare function insertBlockQuoteWithAnalyticsCommand(inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined): EditorCommand;
19
21
  export declare const cleanUpAtTheStartOfDocument: Command;
@@ -0,0 +1,3 @@
1
+ import { type EditorCommand } from '@atlaskit/editor-common/types';
2
+ import type { NodeType } from '@atlaskit/editor-prosemirror/model';
3
+ export declare function wrapSelectionInBlockType(nodeType: NodeType): EditorCommand;
@@ -10,12 +10,14 @@ export type BlockTypeState = {
10
10
  blockTypesDisabled: boolean;
11
11
  availableBlockTypes: BlockType[];
12
12
  availableWrapperBlockTypes: BlockType[];
13
+ availableBlockTypesInDropdown: BlockType[];
13
14
  };
14
15
  export declare const pluginKey: PluginKey<BlockTypeState>;
15
- export declare const createPlugin: (editorAPI: ExtractInjectionAPI<BlockTypePlugin> | undefined, dispatch: (eventName: string | PluginKey, data: any) => void, lastNodeMustBeParagraph?: boolean) => SafePlugin<{
16
+ export declare const createPlugin: (editorAPI: ExtractInjectionAPI<BlockTypePlugin> | undefined, dispatch: (eventName: string | PluginKey, data: any) => void, lastNodeMustBeParagraph?: boolean, includeBlockQuoteAsTextstyleOption?: boolean) => SafePlugin<{
16
17
  currentBlockType: BlockType;
17
18
  blockTypesDisabled: boolean;
18
19
  availableBlockTypes: BlockType[];
19
20
  availableWrapperBlockTypes: BlockType[];
21
+ availableBlockTypesInDropdown: BlockType[];
20
22
  }>;
21
23
  export declare const handleBlockQuoteDND: (view: EditorView, event: DragEvent, slice: Slice) => boolean;
@@ -19,4 +19,5 @@ export interface BlockTypePluginOptions {
19
19
  exclude?: Array<AllowedBlockTypes>;
20
20
  };
21
21
  isUndoRedoButtonsEnabled?: boolean;
22
+ includeBlockQuoteAsTextstyleOption?: boolean;
22
23
  }
@@ -24,7 +24,8 @@ export interface Props {
24
24
  popupsBoundariesElement?: HTMLElement;
25
25
  popupsScrollableElement?: HTMLElement;
26
26
  editorView?: EditorView;
27
- setTextLevel: (type: TextBlockTypes) => void;
27
+ setTextLevel: (type: TextBlockTypes, fromBlockQuote?: boolean) => void;
28
+ wrapBlockQuote: (type: TextBlockTypes) => void;
28
29
  shouldUseDefaultRole?: boolean;
29
30
  api: ExtractInjectionAPI<BlockTypePlugin> | undefined;
30
31
  }
@@ -16,6 +16,7 @@ export type BlockTypePlugin = NextEditorPlugin<'blockType', {
16
16
  insertBlockQuote: (inputMethod: InputMethod) => Command;
17
17
  };
18
18
  commands: {
19
- setTextLevel: (level: TextBlockTypes, inputMethod: InputMethod) => EditorCommand;
19
+ setTextLevel: (level: TextBlockTypes, inputMethod: InputMethod, fromBlockQuote?: boolean) => EditorCommand;
20
+ insertBlockQuote: (inputMethod: InputMethod) => EditorCommand;
20
21
  };
21
22
  }>;
@@ -14,6 +14,7 @@ export declare const TEXT_BLOCK_TYPES: BlockType[];
14
14
  export type TextBlockTypes = 'normal' | 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6';
15
15
  export declare const WRAPPER_BLOCK_TYPES: BlockType[];
16
16
  export declare const ALL_BLOCK_TYPES: BlockType[];
17
+ export declare const getBlockTypesInDropdown: (includeBlockQuoteAsTextstyleOption?: boolean) => BlockType[];
17
18
  export declare const HEADINGS_BY_LEVEL: Record<number, BlockType>;
18
19
  export declare const HEADINGS_BY_NAME: {
19
20
  [blockType: string]: BlockType;
@@ -3,10 +3,11 @@ import type { Command, EditorCommand, HeadingLevelsAndNormalText } from '@atlask
3
3
  import type { TextBlockTypes } from '../block-types';
4
4
  export type InputMethod = INPUT_METHOD.TOOLBAR | INPUT_METHOD.INSERT_MENU | INPUT_METHOD.SHORTCUT | INPUT_METHOD.FORMATTING | INPUT_METHOD.KEYBOARD | INPUT_METHOD.FLOATING_TB;
5
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 setNormalTextWithAnalytics(inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined): EditorCommand;
9
- export declare const setHeadingWithAnalytics: (newHeadingLevel: HeadingLevelsAndNormalText, inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined) => EditorCommand;
6
+ export declare function setHeading(level: HeadingLevelsAndNormalText, fromBlockQuote?: boolean): EditorCommand;
7
+ export declare function setBlockTypeWithAnalytics(name: TextBlockTypes, inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined, fromBlockQuote?: boolean): EditorCommand;
8
+ export declare function setNormalText(fromBlockQuote?: boolean): EditorCommand;
9
+ export declare function setNormalTextWithAnalytics(inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined, fromBlockQuote?: boolean): EditorCommand;
10
+ export declare const setHeadingWithAnalytics: (newHeadingLevel: HeadingLevelsAndNormalText, inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined, fromBlockQuote?: boolean) => EditorCommand;
10
11
  /**
11
12
  *
12
13
  * @param name - block type name
@@ -16,4 +17,5 @@ export declare const setHeadingWithAnalytics: (newHeadingLevel: HeadingLevelsAnd
16
17
  * @returns - command that inserts block type
17
18
  */
18
19
  export declare const insertBlockQuoteWithAnalytics: (inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined) => Command;
20
+ export declare function insertBlockQuoteWithAnalyticsCommand(inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined): EditorCommand;
19
21
  export declare const cleanUpAtTheStartOfDocument: Command;
@@ -0,0 +1,3 @@
1
+ import { type EditorCommand } from '@atlaskit/editor-common/types';
2
+ import type { NodeType } from '@atlaskit/editor-prosemirror/model';
3
+ export declare function wrapSelectionInBlockType(nodeType: NodeType): EditorCommand;
@@ -10,12 +10,14 @@ export type BlockTypeState = {
10
10
  blockTypesDisabled: boolean;
11
11
  availableBlockTypes: BlockType[];
12
12
  availableWrapperBlockTypes: BlockType[];
13
+ availableBlockTypesInDropdown: BlockType[];
13
14
  };
14
15
  export declare const pluginKey: PluginKey<BlockTypeState>;
15
- export declare const createPlugin: (editorAPI: ExtractInjectionAPI<BlockTypePlugin> | undefined, dispatch: (eventName: string | PluginKey, data: any) => void, lastNodeMustBeParagraph?: boolean) => SafePlugin<{
16
+ export declare const createPlugin: (editorAPI: ExtractInjectionAPI<BlockTypePlugin> | undefined, dispatch: (eventName: string | PluginKey, data: any) => void, lastNodeMustBeParagraph?: boolean, includeBlockQuoteAsTextstyleOption?: boolean) => SafePlugin<{
16
17
  currentBlockType: BlockType;
17
18
  blockTypesDisabled: boolean;
18
19
  availableBlockTypes: BlockType[];
19
20
  availableWrapperBlockTypes: BlockType[];
21
+ availableBlockTypesInDropdown: BlockType[];
20
22
  }>;
21
23
  export declare const handleBlockQuoteDND: (view: EditorView, event: DragEvent, slice: Slice) => boolean;
@@ -19,4 +19,5 @@ export interface BlockTypePluginOptions {
19
19
  exclude?: Array<AllowedBlockTypes>;
20
20
  };
21
21
  isUndoRedoButtonsEnabled?: boolean;
22
+ includeBlockQuoteAsTextstyleOption?: boolean;
22
23
  }
@@ -24,7 +24,8 @@ export interface Props {
24
24
  popupsBoundariesElement?: HTMLElement;
25
25
  popupsScrollableElement?: HTMLElement;
26
26
  editorView?: EditorView;
27
- setTextLevel: (type: TextBlockTypes) => void;
27
+ setTextLevel: (type: TextBlockTypes, fromBlockQuote?: boolean) => void;
28
+ wrapBlockQuote: (type: TextBlockTypes) => void;
28
29
  shouldUseDefaultRole?: boolean;
29
30
  api: ExtractInjectionAPI<BlockTypePlugin> | undefined;
30
31
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-type",
3
- "version": "4.0.11",
3
+ "version": "4.0.13",
4
4
  "description": "BlockType plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -34,9 +34,9 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@atlaskit/adf-schema": "^46.1.0",
37
- "@atlaskit/editor-common": "^96.3.0",
37
+ "@atlaskit/editor-common": "^97.0.0",
38
38
  "@atlaskit/editor-plugin-analytics": "^1.10.0",
39
- "@atlaskit/editor-plugin-primary-toolbar": "^2.0.0",
39
+ "@atlaskit/editor-plugin-primary-toolbar": "^2.1.0",
40
40
  "@atlaskit/editor-prosemirror": "6.2.1",
41
41
  "@atlaskit/editor-shared-styles": "^3.2.0",
42
42
  "@atlaskit/editor-tables": "^2.8.0",
@@ -45,8 +45,8 @@
45
45
  "@atlaskit/primitives": "^13.3.0",
46
46
  "@atlaskit/prosemirror-input-rules": "^3.2.0",
47
47
  "@atlaskit/theme": "^14.0.0",
48
- "@atlaskit/tmp-editor-statsig": "^2.25.0",
49
- "@atlaskit/tokens": "^2.4.0",
48
+ "@atlaskit/tmp-editor-statsig": "^2.29.0",
49
+ "@atlaskit/tokens": "^2.5.0",
50
50
  "@babel/runtime": "^7.0.0",
51
51
  "@emotion/react": "^11.7.1"
52
52
  },