@atlaskit/editor-plugin-block-type 12.1.2 → 12.1.4

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.
@@ -75,7 +75,7 @@ const autoformatHeading = (headingLevel, editorAnalyticsApi) => {
75
75
  return setHeadingWithAnalytics(headingLevel, INPUT_METHOD.FORMATTING, editorAnalyticsApi);
76
76
  };
77
77
  export const pluginKey = new PluginKey('blockTypePlugin');
78
- export const createPlugin = (editorAPI, dispatch, lastNodeMustBeParagraph, includeBlockQuoteAsTextstyleOption) => {
78
+ export const createPlugin = (editorAPI, dispatch, lastNodeMustBeParagraph, includeBlockQuoteAsTextstyleOption, allowFontSize) => {
79
79
  var _editorAPI$analytics;
80
80
  const editorAnalyticsApi = editorAPI === null || editorAPI === void 0 ? void 0 : (_editorAPI$analytics = editorAPI.analytics) === null || _editorAPI$analytics === void 0 ? void 0 : _editorAPI$analytics.actions;
81
81
  let altKeyLocation = 0;
@@ -105,7 +105,7 @@ export const createPlugin = (editorAPI, dispatch, lastNodeMustBeParagraph, inclu
105
105
  const formattingIsPresent = hasBlockQuoteInOptions(availableBlockTypesInDropdown) ? checkFormattingIsPresent(state) : undefined;
106
106
  return {
107
107
  currentBlockType: detectBlockType(availableBlockTypesInDropdown, state),
108
- blockTypesDisabled: areBlockTypesDisabled(state),
108
+ blockTypesDisabled: areBlockTypesDisabled(state, allowFontSize),
109
109
  availableBlockTypes,
110
110
  availableWrapperBlockTypes,
111
111
  availableBlockTypesInDropdown,
@@ -116,7 +116,7 @@ export const createPlugin = (editorAPI, dispatch, lastNodeMustBeParagraph, inclu
116
116
  const newPluginState = {
117
117
  ...oldPluginState,
118
118
  currentBlockType: detectBlockType(oldPluginState.availableBlockTypesInDropdown, newState),
119
- blockTypesDisabled: areBlockTypesDisabled(newState),
119
+ blockTypesDisabled: areBlockTypesDisabled(newState, allowFontSize),
120
120
  formattingIsPresent: hasBlockQuoteInOptions(oldPluginState.availableBlockTypesInDropdown) ? checkFormattingIsPresent(newState) : undefined
121
121
  };
122
122
  if (newPluginState.currentBlockType !== oldPluginState.currentBlockType || newPluginState.blockTypesDisabled !== oldPluginState.blockTypesDisabled || newPluginState.formattingIsPresent !== oldPluginState.formattingIsPresent) {
@@ -7,11 +7,13 @@ import { ax, ix } from "@compiled/react/runtime";
7
7
  import { useIntl } from 'react-intl-next';
8
8
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
9
9
  import { formatShortcut, setNormalText, toggleHeading1, toggleHeading2, toggleHeading3, toggleHeading4, toggleHeading5, toggleHeading6 } from '@atlaskit/editor-common/keymaps';
10
+ import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
10
11
  import { editorUGCToken } from '@atlaskit/editor-common/ugc-tokens';
11
12
  import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
12
13
  import { ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar';
13
14
  import { Box } from '@atlaskit/primitives/compiled';
14
15
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
16
+ import { isSelectionInsideListNode } from '../../utils';
15
17
  const smallTextStyle = null;
16
18
  const normalStyle = null;
17
19
  const heading1Style = null;
@@ -108,6 +110,12 @@ const shortcuts = {
108
110
  heading5: toggleHeading5,
109
111
  heading6: toggleHeading6
110
112
  };
113
+ const shouldDisableHeadingButton = (state, blockType) => {
114
+ if (!state) {
115
+ return false;
116
+ }
117
+ return isSelectionInsideListNode(state) && blockType.name !== 'normal' && blockType.name !== 'smallText';
118
+ };
111
119
  export const HeadingButton = ({
112
120
  blockType,
113
121
  api
@@ -117,12 +125,19 @@ export const HeadingButton = ({
117
125
  } = useIntl();
118
126
  const currentBlockType = useSharedPluginStateSelector(api, 'blockType.currentBlockType');
119
127
  const availableBlockTypesInDropdown = useSharedPluginStateSelector(api, 'blockType.availableBlockTypesInDropdown');
128
+ const {
129
+ editorView
130
+ } = useEditorToolbar();
120
131
  if (!(availableBlockTypesInDropdown !== null && availableBlockTypesInDropdown !== void 0 && availableBlockTypesInDropdown.some(availableBlockType => availableBlockType.name === blockType.name))) {
121
132
  return null;
122
133
  }
134
+ const isDisabled = expValEquals('platform_editor_small_font_size', 'isEnabled', true) ? shouldDisableHeadingButton(editorView === null || editorView === void 0 ? void 0 : editorView.state, blockType) : false;
123
135
  const fromBlockQuote = (currentBlockType === null || currentBlockType === void 0 ? void 0 : currentBlockType.name) === 'blockquote';
124
136
  const onClick = () => {
125
137
  var _api$core, _api$blockType, _api$blockType$comman;
138
+ if (isDisabled) {
139
+ return;
140
+ }
126
141
  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));
127
142
  };
128
143
  const shortcut = formatShortcut(shortcuts[blockType.name]);
@@ -134,6 +149,7 @@ export const HeadingButton = ({
134
149
  }) : undefined,
135
150
  onClick: onClick,
136
151
  isSelected: isSelected,
152
+ isDisabled: isDisabled,
137
153
  ariaKeyshortcuts: shortcut
138
154
  }, expValEquals('platform_editor_toolbar_aifc_use_editor_typography', 'isEnabled', true) ? /*#__PURE__*/React.createElement(HeadingText, {
139
155
  headingType: blockType.name
@@ -2,8 +2,17 @@ import React from 'react';
2
2
  import { useIntl } from 'react-intl-next';
3
3
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
4
  import { formatShortcut, toggleBlockQuote } from '@atlaskit/editor-common/keymaps';
5
+ import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
5
6
  import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
6
7
  import { ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar';
8
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
9
+ import { isSelectionInsideListNode } from '../../utils';
10
+ const shouldDisableQuoteButton = state => {
11
+ if (!state) {
12
+ return false;
13
+ }
14
+ return isSelectionInsideListNode(state);
15
+ };
7
16
  export const QuoteButton = ({
8
17
  blockType,
9
18
  api
@@ -13,11 +22,18 @@ export const QuoteButton = ({
13
22
  } = useIntl();
14
23
  const availableBlockTypesInDropdown = useSharedPluginStateSelector(api, 'blockType.availableBlockTypesInDropdown');
15
24
  const currentBlockType = useSharedPluginStateSelector(api, 'blockType.currentBlockType');
25
+ const {
26
+ editorView
27
+ } = useEditorToolbar();
16
28
  if (!(availableBlockTypesInDropdown !== null && availableBlockTypesInDropdown !== void 0 && availableBlockTypesInDropdown.some(availableBlockType => availableBlockType.name === blockType.name))) {
17
29
  return null;
18
30
  }
31
+ const isDisabled = expValEquals('platform_editor_small_font_size', 'isEnabled', true) ? shouldDisableQuoteButton(editorView === null || editorView === void 0 ? void 0 : editorView.state) : false;
19
32
  const onClick = () => {
20
33
  var _api$core, _api$blockType, _api$blockType$comman;
34
+ if (isDisabled) {
35
+ return;
36
+ }
21
37
  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
38
  };
23
39
  const shortcut = formatShortcut(toggleBlockQuote);
@@ -28,6 +44,7 @@ export const QuoteButton = ({
28
44
  }) : undefined,
29
45
  onClick: onClick,
30
46
  isSelected: currentBlockType === blockType,
47
+ isDisabled: isDisabled,
31
48
  ariaKeyshortcuts: shortcut
32
49
  }, formatMessage(blockType.title));
33
50
  };
@@ -1,5 +1,6 @@
1
1
  import { anyMarkActive } from '@atlaskit/editor-common/mark';
2
2
  import { createRule, createWrappingJoinRule } from '@atlaskit/editor-common/utils';
3
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
3
4
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
4
5
  import { WRAPPER_BLOCK_TYPES, FORMATTING_NODE_TYPES, FORMATTING_MARK_TYPES } from './block-types';
5
6
  export const isNodeAWrappingBlockNode = node => {
@@ -71,14 +72,20 @@ function getSelectedWrapperNodes(state) {
71
72
  /**
72
73
  * Function will check if changing block types: Paragraph, Heading is enabled.
73
74
  */
74
- export function areBlockTypesDisabled(state) {
75
+ export function areBlockTypesDisabled(state, allowFontSize = false) {
75
76
  const nodesTypes = getSelectedWrapperNodes(state);
76
77
  const {
77
78
  panel,
78
79
  blockquote,
79
80
  bulletList,
80
- orderedList
81
+ orderedList,
82
+ listItem
81
83
  } = state.schema.nodes;
84
+
85
+ // When the small font size experiment is enabled, allow block type changes inside lists
86
+ // so that users can toggle between Normal text and Small text within list contexts.
87
+ // Note: taskList/taskItem are not excluded here until blockTaskItem conversion is implemented (WI 4).
88
+ const excludedTypes = allowFontSize && expValEquals('platform_editor_small_font_size', 'isEnabled', true) ? [panel, bulletList, orderedList, listItem] : [panel];
82
89
  if (editorExperiment('platform_editor_blockquote_in_text_formatting_menu', true)) {
83
90
  let hasQuote = false;
84
91
  let hasNestedListInQuote = false;
@@ -99,9 +106,38 @@ export function areBlockTypesDisabled(state) {
99
106
  }
100
107
  return !hasNestedListInQuote;
101
108
  });
102
- return nodesTypes.filter(type => type !== panel).length > 0 && (!hasQuote || hasNestedListInQuote);
109
+ return nodesTypes.filter(type => !excludedTypes.includes(type)).length > 0 && (!hasQuote || hasNestedListInQuote);
110
+ }
111
+ return nodesTypes.filter(type => !excludedTypes.includes(type)).length > 0;
112
+ }
113
+
114
+ /**
115
+ * Checks if the current selection is inside a list node (bulletList, orderedList, or taskList).
116
+ * Used to determine which text styles should be enabled when the small font size experiment is active.
117
+ */
118
+ export function isSelectionInsideListNode(state) {
119
+ if (!state.selection) {
120
+ return false;
103
121
  }
104
- return nodesTypes.filter(type => type !== panel).length > 0;
122
+ const {
123
+ $from,
124
+ $to
125
+ } = state.selection;
126
+ const {
127
+ bulletList,
128
+ orderedList,
129
+ taskList
130
+ } = state.schema.nodes;
131
+ const listNodeTypes = [bulletList, orderedList, taskList];
132
+ let insideList = false;
133
+ state.doc.nodesBetween($from.pos, $to.pos, node => {
134
+ if (node.isBlock && listNodeTypes.indexOf(node.type) >= 0) {
135
+ insideList = true;
136
+ return false;
137
+ }
138
+ return true;
139
+ });
140
+ return insideList;
105
141
  }
106
142
  const blockStylingIsPresent = state => {
107
143
  const {
@@ -142,4 +178,43 @@ export const checkFormattingIsPresent = state => {
142
178
  };
143
179
  export const hasBlockQuoteInOptions = dropdownOptions => {
144
180
  return !!dropdownOptions.find(blockType => blockType.name === 'blockquote');
145
- };
181
+ };
182
+
183
+ /**
184
+ * Returns a { from, to } range that extends the selection boundaries outward
185
+ * to include the entirety of any list nodes at either end. If the selection
186
+ * start is inside a list, `from` is pulled back to the list's start; if the
187
+ * selection end is inside a list, `to` is pushed forward to the list's end.
188
+ * Non-list content in the middle is included as-is.
189
+ */
190
+ export function getSelectionRangeExpandedToLists(tr) {
191
+ const {
192
+ selection
193
+ } = tr;
194
+ const {
195
+ bulletList,
196
+ orderedList,
197
+ taskList
198
+ } = tr.doc.type.schema.nodes;
199
+ const listNodeTypes = [bulletList, orderedList, taskList];
200
+ let from = selection.from;
201
+ let to = selection.to;
202
+ for (let depth = selection.$from.depth; depth > 0; depth--) {
203
+ const node = selection.$from.node(depth);
204
+ if (listNodeTypes.indexOf(node.type) >= 0) {
205
+ from = selection.$from.before(depth);
206
+ break;
207
+ }
208
+ }
209
+ for (let depth = selection.$to.depth; depth > 0; depth--) {
210
+ const node = selection.$to.node(depth);
211
+ if (listNodeTypes.indexOf(node.type) >= 0) {
212
+ to = selection.$to.after(depth);
213
+ break;
214
+ }
215
+ }
216
+ return {
217
+ from,
218
+ to
219
+ };
220
+ }
@@ -171,7 +171,7 @@ var blockTypePlugin = function blockTypePlugin(_ref3) {
171
171
  name: 'blockType',
172
172
  plugin: function plugin(_ref5) {
173
173
  var dispatch = _ref5.dispatch;
174
- return createPlugin(api, dispatch, options && options.lastNodeMustBeParagraph, options === null || options === void 0 ? void 0 : options.includeBlockQuoteAsTextstyleOption);
174
+ return createPlugin(api, dispatch, options && options.lastNodeMustBeParagraph, options === null || options === void 0 ? void 0 : options.includeBlockQuoteAsTextstyleOption, options === null || options === void 0 ? void 0 : options.allowFontSize);
175
175
  }
176
176
  }, {
177
177
  name: 'blockTypeInputRule',
@@ -2,13 +2,14 @@ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol
2
2
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
3
3
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
4
4
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
5
- import { toggleBlockMarkNext } from '@atlaskit/editor-common/commands';
5
+ import { createToggleBlockMarkOnRangeNext } from '@atlaskit/editor-common/commands';
6
6
  import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
7
7
  import { filterChildrenBetween, wrapSelectionIn } from '@atlaskit/editor-common/utils';
8
8
  import { liftTarget } from '@atlaskit/editor-prosemirror/transform';
9
9
  import { CellSelection } from '@atlaskit/editor-tables';
10
10
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
11
11
  import { HEADINGS_BY_NAME, NORMAL_TEXT } from '../block-types';
12
+ import { getSelectionRangeExpandedToLists } from '../utils';
12
13
  import { FORMATTING_NODE_TYPES, FORMATTING_MARK_TYPES, cellSelectionNodesBetween, formatTypes, clearNodeFormattingOnSelection } from './clear-formatting';
13
14
  import { wrapSelectionInBlockType } from './wrapSelectionIn';
14
15
  export function setBlockType(name) {
@@ -68,11 +69,25 @@ export function setHeading(level, fromBlockQuote) {
68
69
  });
69
70
  }
70
71
  });
72
+
73
+ // Remove fontSize mark from transformed content in range
74
+ // List content stays as paragraphs (headings aren't allowed in list items),
75
+ // but non-list content has been converted to headings by setBlockType above.
71
76
  var fontSize = schema.marks.fontSize;
72
77
  if (fontSize && expValEquals('platform_editor_small_font_size', 'isEnabled', true)) {
73
- toggleBlockMarkNext(fontSize, function () {
74
- return false;
75
- }, [schema.nodes.heading])(tr);
78
+ var allowedBlocks = [schema.nodes.paragraph, schema.nodes.heading];
79
+ if (selection instanceof CellSelection) {
80
+ selection.forEachCell(function (cell, pos) {
81
+ createToggleBlockMarkOnRangeNext(fontSize, function () {
82
+ return false;
83
+ }, allowedBlocks)(pos, pos + cell.nodeSize, tr);
84
+ });
85
+ } else {
86
+ var expandedRange = getSelectionRangeExpandedToLists(tr);
87
+ createToggleBlockMarkOnRangeNext(fontSize, function () {
88
+ return false;
89
+ }, allowedBlocks)(expandedRange.from, expandedRange.to, tr);
90
+ }
76
91
  }
77
92
  return tr;
78
93
  };
@@ -80,13 +95,15 @@ export function setHeading(level, fromBlockQuote) {
80
95
  export function setBlockTypeWithAnalytics(name, inputMethod, editorAnalyticsApi, fromBlockQuote) {
81
96
  return function (_ref4) {
82
97
  var tr = _ref4.tr;
83
- var nodes = tr.doc.type.schema.nodes;
98
+ var _tr$doc$type$schema = tr.doc.type.schema,
99
+ nodes = _tr$doc$type$schema.nodes,
100
+ marks = _tr$doc$type$schema.marks;
84
101
  if (name === 'normal' && nodes.paragraph) {
85
102
  return setNormalTextWithAnalytics(inputMethod, editorAnalyticsApi, fromBlockQuote)({
86
103
  tr: tr
87
104
  });
88
105
  }
89
- if (name === 'smallText' && expValEquals('platform_editor_small_font_size', 'isEnabled', true)) {
106
+ if (name === 'smallText' && marks.fontSize && expValEquals('platform_editor_small_font_size', 'isEnabled', true)) {
90
107
  return setSmallTextWithAnalytics(inputMethod, editorAnalyticsApi)({
91
108
  tr: tr
92
109
  });
@@ -103,31 +120,38 @@ export function setBlockTypeWithAnalytics(name, inputMethod, editorAnalyticsApi,
103
120
  export function setSmallText() {
104
121
  return function (_ref5) {
105
122
  var tr = _ref5.tr;
106
- var _tr$doc$type$schema = tr.doc.type.schema,
107
- fontSize = _tr$doc$type$schema.marks.fontSize,
108
- paragraph = _tr$doc$type$schema.nodes.paragraph;
123
+ var _tr$doc$type$schema2 = tr.doc.type.schema,
124
+ fontSize = _tr$doc$type$schema2.marks.fontSize,
125
+ paragraph = _tr$doc$type$schema2.nodes.paragraph;
109
126
  if (!fontSize) {
110
127
  return null;
111
128
  }
112
129
  var selection = tr.selection;
113
- var ranges = selection instanceof CellSelection ? selection.ranges : [selection];
114
- ranges.forEach(function (_ref6) {
115
- var $from = _ref6.$from,
116
- $to = _ref6.$to;
117
- tr.setBlockType($from.pos, $to.pos, paragraph);
118
- });
119
- toggleBlockMarkNext(fontSize, function () {
120
- return {
121
- fontSize: 'small'
122
- };
123
- }, [paragraph])(tr);
130
+ if (selection instanceof CellSelection) {
131
+ selection.forEachCell(function (cell, pos) {
132
+ tr.setBlockType(pos, pos + cell.nodeSize, paragraph);
133
+ createToggleBlockMarkOnRangeNext(fontSize, function () {
134
+ return {
135
+ fontSize: 'small'
136
+ };
137
+ }, [paragraph])(pos, pos + cell.nodeSize, tr);
138
+ });
139
+ } else {
140
+ tr.setBlockType(selection.from, selection.to, paragraph);
141
+ var expandedRange = getSelectionRangeExpandedToLists(tr);
142
+ createToggleBlockMarkOnRangeNext(fontSize, function () {
143
+ return {
144
+ fontSize: 'small'
145
+ };
146
+ }, [paragraph])(expandedRange.from, expandedRange.to, tr);
147
+ }
124
148
  return tr;
125
149
  };
126
150
  }
127
151
  export function setSmallTextWithAnalytics(inputMethod, editorAnalyticsApi) {
128
152
  return withCurrentHeadingLevel(function (previousHeadingLevel) {
129
- return function (_ref7) {
130
- var tr = _ref7.tr;
153
+ return function (_ref6) {
154
+ var tr = _ref6.tr;
131
155
  editorAnalyticsApi === null || editorAnalyticsApi === void 0 || editorAnalyticsApi.attachAnalyticsEvent({
132
156
  action: ACTION.FORMATTED,
133
157
  actionSubject: ACTION_SUBJECT.TEXT,
@@ -145,14 +169,16 @@ export function setSmallTextWithAnalytics(inputMethod, editorAnalyticsApi) {
145
169
  });
146
170
  }
147
171
  export function setNormalText(fromBlockQuote) {
148
- return function (_ref8) {
149
- var tr = _ref8.tr;
172
+ return function (_ref7) {
173
+ var tr = _ref7.tr;
150
174
  var selection = tr.selection,
151
175
  schema = tr.doc.type.schema;
176
+
177
+ // Apply normal text to the selection range (handles non-list content)
152
178
  var ranges = selection instanceof CellSelection ? selection.ranges : [selection];
153
- ranges.forEach(function (_ref9) {
154
- var $from = _ref9.$from,
155
- $to = _ref9.$to;
179
+ ranges.forEach(function (_ref8) {
180
+ var $from = _ref8.$from,
181
+ $to = _ref8.$to;
156
182
  if (fromBlockQuote) {
157
183
  var range = $from.blockRange($to);
158
184
  if (!range) {
@@ -172,19 +198,28 @@ export function setNormalText(fromBlockQuote) {
172
198
  }
173
199
  });
174
200
 
175
- // Remove fontSize mark if present in schema
201
+ // Remove fontSize mark from any lists the selection touches
176
202
  var fontSize = schema.marks.fontSize;
177
203
  if (fontSize && expValEquals('platform_editor_small_font_size', 'isEnabled', true)) {
178
- toggleBlockMarkNext(fontSize, function () {
179
- return false;
180
- }, [schema.nodes.paragraph])(tr);
204
+ if (selection instanceof CellSelection) {
205
+ selection.forEachCell(function (cell, pos) {
206
+ createToggleBlockMarkOnRangeNext(fontSize, function () {
207
+ return false;
208
+ }, [schema.nodes.paragraph])(pos, pos + cell.nodeSize, tr);
209
+ });
210
+ } else {
211
+ var expandedRange = getSelectionRangeExpandedToLists(tr);
212
+ createToggleBlockMarkOnRangeNext(fontSize, function () {
213
+ return false;
214
+ }, [schema.nodes.paragraph])(expandedRange.from, expandedRange.to, tr);
215
+ }
181
216
  }
182
217
  return tr;
183
218
  };
184
219
  }
185
220
  export function clearFormatting(inputMethod, editorAnalyticsApi) {
186
- return function (_ref0) {
187
- var tr = _ref0.tr;
221
+ return function (_ref9) {
222
+ var tr = _ref9.tr;
188
223
  var formattingCleared = [];
189
224
  var schema = tr.doc.type.schema;
190
225
  FORMATTING_MARK_TYPES.forEach(function (mark) {
@@ -241,8 +276,8 @@ export function clearFormatting(inputMethod, editorAnalyticsApi) {
241
276
  };
242
277
  }
243
278
  function withCurrentHeadingLevel(fn) {
244
- return function (_ref1) {
245
- var tr = _ref1.tr;
279
+ return function (_ref0) {
280
+ var tr = _ref0.tr;
246
281
  // Find all headings and paragraphs of text
247
282
  var _tr$doc$type$schema$n = tr.doc.type.schema.nodes,
248
283
  heading = _tr$doc$type$schema$n.heading,
@@ -279,8 +314,8 @@ function withCurrentHeadingLevel(fn) {
279
314
  }
280
315
  export function setNormalTextWithAnalytics(inputMethod, editorAnalyticsApi, fromBlockQuote) {
281
316
  return withCurrentHeadingLevel(function (previousHeadingLevel) {
282
- return function (_ref10) {
283
- var tr = _ref10.tr;
317
+ return function (_ref1) {
318
+ var tr = _ref1.tr;
284
319
  editorAnalyticsApi === null || editorAnalyticsApi === void 0 || editorAnalyticsApi.attachAnalyticsEvent({
285
320
  action: ACTION.FORMATTED,
286
321
  actionSubject: ACTION_SUBJECT.TEXT,
@@ -300,8 +335,8 @@ export function setNormalTextWithAnalytics(inputMethod, editorAnalyticsApi, from
300
335
  }
301
336
  export var setHeadingWithAnalytics = function setHeadingWithAnalytics(newHeadingLevel, inputMethod, editorAnalyticsApi, fromBlockQuote) {
302
337
  return withCurrentHeadingLevel(function (previousHeadingLevel) {
303
- return function (_ref11) {
304
- var tr = _ref11.tr;
338
+ return function (_ref10) {
339
+ var tr = _ref10.tr;
305
340
  editorAnalyticsApi === null || editorAnalyticsApi === void 0 || editorAnalyticsApi.attachAnalyticsEvent({
306
341
  action: ACTION.FORMATTED,
307
342
  actionSubject: ACTION_SUBJECT.TEXT,
@@ -350,8 +385,8 @@ export var insertBlockQuoteWithAnalytics = function insertBlockQuoteWithAnalytic
350
385
  };
351
386
  export function insertBlockQuoteWithAnalyticsCommand(inputMethod, editorAnalyticsApi) {
352
387
  return withCurrentHeadingLevel(function () {
353
- return function (_ref12) {
354
- var tr = _ref12.tr;
388
+ return function (_ref11) {
389
+ var tr = _ref11.tr;
355
390
  var nodes = tr.doc.type.schema.nodes;
356
391
  editorAnalyticsApi === null || editorAnalyticsApi === void 0 || editorAnalyticsApi.attachAnalyticsEvent({
357
392
  action: ACTION.FORMATTED,
@@ -369,8 +404,8 @@ export function insertBlockQuoteWithAnalyticsCommand(inputMethod, editorAnalytic
369
404
  });
370
405
  }
371
406
  export var cleanUpAtTheStartOfDocument = function cleanUpAtTheStartOfDocument(state, dispatch) {
372
- var _ref13 = state.selection,
373
- $cursor = _ref13.$cursor;
407
+ var _ref12 = state.selection,
408
+ $cursor = _ref12.$cursor;
374
409
  if ($cursor && !$cursor.nodeBefore && !$cursor.nodeAfter && $cursor.pos === 1) {
375
410
  var tr = state.tr,
376
411
  schema = state.schema;
@@ -81,7 +81,7 @@ var autoformatHeading = function autoformatHeading(headingLevel, editorAnalytics
81
81
  return setHeadingWithAnalytics(headingLevel, INPUT_METHOD.FORMATTING, editorAnalyticsApi);
82
82
  };
83
83
  export var pluginKey = new PluginKey('blockTypePlugin');
84
- export var createPlugin = function createPlugin(editorAPI, dispatch, lastNodeMustBeParagraph, includeBlockQuoteAsTextstyleOption) {
84
+ export var createPlugin = function createPlugin(editorAPI, dispatch, lastNodeMustBeParagraph, includeBlockQuoteAsTextstyleOption, allowFontSize) {
85
85
  var _editorAPI$analytics;
86
86
  var editorAnalyticsApi = editorAPI === null || editorAPI === void 0 || (_editorAPI$analytics = editorAPI.analytics) === null || _editorAPI$analytics === void 0 ? void 0 : _editorAPI$analytics.actions;
87
87
  var altKeyLocation = 0;
@@ -115,7 +115,7 @@ export var createPlugin = function createPlugin(editorAPI, dispatch, lastNodeMus
115
115
  var formattingIsPresent = hasBlockQuoteInOptions(availableBlockTypesInDropdown) ? checkFormattingIsPresent(state) : undefined;
116
116
  return {
117
117
  currentBlockType: detectBlockType(availableBlockTypesInDropdown, state),
118
- blockTypesDisabled: areBlockTypesDisabled(state),
118
+ blockTypesDisabled: areBlockTypesDisabled(state, allowFontSize),
119
119
  availableBlockTypes: availableBlockTypes,
120
120
  availableWrapperBlockTypes: availableWrapperBlockTypes,
121
121
  availableBlockTypesInDropdown: availableBlockTypesInDropdown,
@@ -125,7 +125,7 @@ export var createPlugin = function createPlugin(editorAPI, dispatch, lastNodeMus
125
125
  apply: function apply(_tr, oldPluginState, _oldState, newState) {
126
126
  var newPluginState = _objectSpread(_objectSpread({}, oldPluginState), {}, {
127
127
  currentBlockType: detectBlockType(oldPluginState.availableBlockTypesInDropdown, newState),
128
- blockTypesDisabled: areBlockTypesDisabled(newState),
128
+ blockTypesDisabled: areBlockTypesDisabled(newState, allowFontSize),
129
129
  formattingIsPresent: hasBlockQuoteInOptions(oldPluginState.availableBlockTypesInDropdown) ? checkFormattingIsPresent(newState) : undefined
130
130
  });
131
131
  if (newPluginState.currentBlockType !== oldPluginState.currentBlockType || newPluginState.blockTypesDisabled !== oldPluginState.blockTypesDisabled || newPluginState.formattingIsPresent !== oldPluginState.formattingIsPresent) {
@@ -7,11 +7,13 @@ import { ax, ix } from "@compiled/react/runtime";
7
7
  import { useIntl } from 'react-intl-next';
8
8
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
9
9
  import { formatShortcut, setNormalText, toggleHeading1, toggleHeading2, toggleHeading3, toggleHeading4, toggleHeading5, toggleHeading6 } from '@atlaskit/editor-common/keymaps';
10
+ import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
10
11
  import { editorUGCToken } from '@atlaskit/editor-common/ugc-tokens';
11
12
  import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
12
13
  import { ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar';
13
14
  import { Box } from '@atlaskit/primitives/compiled';
14
15
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
16
+ import { isSelectionInsideListNode } from '../../utils';
15
17
  var smallTextStyle = null;
16
18
  var normalStyle = null;
17
19
  var heading1Style = null;
@@ -107,6 +109,12 @@ var shortcuts = {
107
109
  heading5: toggleHeading5,
108
110
  heading6: toggleHeading6
109
111
  };
112
+ var shouldDisableHeadingButton = function shouldDisableHeadingButton(state, blockType) {
113
+ if (!state) {
114
+ return false;
115
+ }
116
+ return isSelectionInsideListNode(state) && blockType.name !== 'normal' && blockType.name !== 'smallText';
117
+ };
110
118
  export var HeadingButton = function HeadingButton(_ref2) {
111
119
  var blockType = _ref2.blockType,
112
120
  api = _ref2.api;
@@ -114,14 +122,20 @@ export var HeadingButton = function HeadingButton(_ref2) {
114
122
  formatMessage = _useIntl.formatMessage;
115
123
  var currentBlockType = useSharedPluginStateSelector(api, 'blockType.currentBlockType');
116
124
  var availableBlockTypesInDropdown = useSharedPluginStateSelector(api, 'blockType.availableBlockTypesInDropdown');
125
+ var _useEditorToolbar = useEditorToolbar(),
126
+ editorView = _useEditorToolbar.editorView;
117
127
  if (!(availableBlockTypesInDropdown !== null && availableBlockTypesInDropdown !== void 0 && availableBlockTypesInDropdown.some(function (availableBlockType) {
118
128
  return availableBlockType.name === blockType.name;
119
129
  }))) {
120
130
  return null;
121
131
  }
132
+ var isDisabled = expValEquals('platform_editor_small_font_size', 'isEnabled', true) ? shouldDisableHeadingButton(editorView === null || editorView === void 0 ? void 0 : editorView.state, blockType) : false;
122
133
  var fromBlockQuote = (currentBlockType === null || currentBlockType === void 0 ? void 0 : currentBlockType.name) === 'blockquote';
123
134
  var onClick = function onClick() {
124
135
  var _api$core, _api$blockType;
136
+ if (isDisabled) {
137
+ return;
138
+ }
125
139
  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));
126
140
  };
127
141
  var shortcut = formatShortcut(shortcuts[blockType.name]);
@@ -133,6 +147,7 @@ export var HeadingButton = function HeadingButton(_ref2) {
133
147
  }) : undefined,
134
148
  onClick: onClick,
135
149
  isSelected: isSelected,
150
+ isDisabled: isDisabled,
136
151
  ariaKeyshortcuts: shortcut
137
152
  }, expValEquals('platform_editor_toolbar_aifc_use_editor_typography', 'isEnabled', true) ? /*#__PURE__*/React.createElement(HeadingText, {
138
153
  headingType: blockType.name
@@ -2,8 +2,17 @@ import React from 'react';
2
2
  import { useIntl } from 'react-intl-next';
3
3
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
4
  import { formatShortcut, toggleBlockQuote } from '@atlaskit/editor-common/keymaps';
5
+ import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
5
6
  import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
6
7
  import { ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar';
8
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
9
+ import { isSelectionInsideListNode } from '../../utils';
10
+ var shouldDisableQuoteButton = function shouldDisableQuoteButton(state) {
11
+ if (!state) {
12
+ return false;
13
+ }
14
+ return isSelectionInsideListNode(state);
15
+ };
7
16
  export var QuoteButton = function QuoteButton(_ref) {
8
17
  var blockType = _ref.blockType,
9
18
  api = _ref.api;
@@ -11,13 +20,19 @@ export var QuoteButton = function QuoteButton(_ref) {
11
20
  formatMessage = _useIntl.formatMessage;
12
21
  var availableBlockTypesInDropdown = useSharedPluginStateSelector(api, 'blockType.availableBlockTypesInDropdown');
13
22
  var currentBlockType = useSharedPluginStateSelector(api, 'blockType.currentBlockType');
23
+ var _useEditorToolbar = useEditorToolbar(),
24
+ editorView = _useEditorToolbar.editorView;
14
25
  if (!(availableBlockTypesInDropdown !== null && availableBlockTypesInDropdown !== void 0 && availableBlockTypesInDropdown.some(function (availableBlockType) {
15
26
  return availableBlockType.name === blockType.name;
16
27
  }))) {
17
28
  return null;
18
29
  }
30
+ var isDisabled = expValEquals('platform_editor_small_font_size', 'isEnabled', true) ? shouldDisableQuoteButton(editorView === null || editorView === void 0 ? void 0 : editorView.state) : false;
19
31
  var onClick = function onClick() {
20
32
  var _api$core, _api$blockType;
33
+ if (isDisabled) {
34
+ return;
35
+ }
21
36
  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
37
  };
23
38
  var shortcut = formatShortcut(toggleBlockQuote);
@@ -28,6 +43,7 @@ export var QuoteButton = function QuoteButton(_ref) {
28
43
  }) : undefined,
29
44
  onClick: onClick,
30
45
  isSelected: currentBlockType === blockType,
46
+ isDisabled: isDisabled,
31
47
  ariaKeyshortcuts: shortcut
32
48
  }, formatMessage(blockType.title));
33
49
  };