@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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @atlaskit/editor-plugin-block-type
2
2
 
3
+ ## 12.1.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 12.1.3
10
+
11
+ ### Patch Changes
12
+
13
+ - [`4cac24cfac09d`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/4cac24cfac09d) -
14
+ Add support for text styles menu inside lists (bullet, ordered) when
15
+ platform_editor_small_font_size experiment is enabled. Enables Normal text and Small text options
16
+ while disabling other items (headings, quote). Applies fontSize mark to entire list when toggling
17
+ small/normal text.
18
+ - Updated dependencies
19
+
3
20
  ## 12.1.2
4
21
 
5
22
  ### Patch Changes
@@ -178,7 +178,7 @@ var blockTypePlugin = exports.blockTypePlugin = function blockTypePlugin(_ref3)
178
178
  name: 'blockType',
179
179
  plugin: function plugin(_ref5) {
180
180
  var dispatch = _ref5.dispatch;
181
- return (0, _main.createPlugin)(api, dispatch, options && options.lastNodeMustBeParagraph, options === null || options === void 0 ? void 0 : options.includeBlockQuoteAsTextstyleOption);
181
+ return (0, _main.createPlugin)(api, dispatch, options && options.lastNodeMustBeParagraph, options === null || options === void 0 ? void 0 : options.includeBlockQuoteAsTextstyleOption, options === null || options === void 0 ? void 0 : options.allowFontSize);
182
182
  }
183
183
  }, {
184
184
  name: 'blockTypeInputRule',
@@ -23,6 +23,7 @@ var _transform = require("@atlaskit/editor-prosemirror/transform");
23
23
  var _editorTables = require("@atlaskit/editor-tables");
24
24
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
25
25
  var _blockTypes = require("../block-types");
26
+ var _utils2 = require("../utils");
26
27
  var _clearFormatting = require("./clear-formatting");
27
28
  var _wrapSelectionIn = require("./wrapSelectionIn");
28
29
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
@@ -85,11 +86,25 @@ function setHeading(level, fromBlockQuote) {
85
86
  });
86
87
  }
87
88
  });
89
+
90
+ // Remove fontSize mark from transformed content in range
91
+ // List content stays as paragraphs (headings aren't allowed in list items),
92
+ // but non-list content has been converted to headings by setBlockType above.
88
93
  var fontSize = schema.marks.fontSize;
89
94
  if (fontSize && (0, _expValEquals.expValEquals)('platform_editor_small_font_size', 'isEnabled', true)) {
90
- (0, _commands.toggleBlockMarkNext)(fontSize, function () {
91
- return false;
92
- }, [schema.nodes.heading])(tr);
95
+ var allowedBlocks = [schema.nodes.paragraph, schema.nodes.heading];
96
+ if (selection instanceof _editorTables.CellSelection) {
97
+ selection.forEachCell(function (cell, pos) {
98
+ (0, _commands.createToggleBlockMarkOnRangeNext)(fontSize, function () {
99
+ return false;
100
+ }, allowedBlocks)(pos, pos + cell.nodeSize, tr);
101
+ });
102
+ } else {
103
+ var expandedRange = (0, _utils2.getSelectionRangeExpandedToLists)(tr);
104
+ (0, _commands.createToggleBlockMarkOnRangeNext)(fontSize, function () {
105
+ return false;
106
+ }, allowedBlocks)(expandedRange.from, expandedRange.to, tr);
107
+ }
93
108
  }
94
109
  return tr;
95
110
  };
@@ -97,13 +112,15 @@ function setHeading(level, fromBlockQuote) {
97
112
  function setBlockTypeWithAnalytics(name, inputMethod, editorAnalyticsApi, fromBlockQuote) {
98
113
  return function (_ref4) {
99
114
  var tr = _ref4.tr;
100
- var nodes = tr.doc.type.schema.nodes;
115
+ var _tr$doc$type$schema = tr.doc.type.schema,
116
+ nodes = _tr$doc$type$schema.nodes,
117
+ marks = _tr$doc$type$schema.marks;
101
118
  if (name === 'normal' && nodes.paragraph) {
102
119
  return setNormalTextWithAnalytics(inputMethod, editorAnalyticsApi, fromBlockQuote)({
103
120
  tr: tr
104
121
  });
105
122
  }
106
- if (name === 'smallText' && (0, _expValEquals.expValEquals)('platform_editor_small_font_size', 'isEnabled', true)) {
123
+ if (name === 'smallText' && marks.fontSize && (0, _expValEquals.expValEquals)('platform_editor_small_font_size', 'isEnabled', true)) {
107
124
  return setSmallTextWithAnalytics(inputMethod, editorAnalyticsApi)({
108
125
  tr: tr
109
126
  });
@@ -120,31 +137,38 @@ function setBlockTypeWithAnalytics(name, inputMethod, editorAnalyticsApi, fromBl
120
137
  function setSmallText() {
121
138
  return function (_ref5) {
122
139
  var tr = _ref5.tr;
123
- var _tr$doc$type$schema = tr.doc.type.schema,
124
- fontSize = _tr$doc$type$schema.marks.fontSize,
125
- paragraph = _tr$doc$type$schema.nodes.paragraph;
140
+ var _tr$doc$type$schema2 = tr.doc.type.schema,
141
+ fontSize = _tr$doc$type$schema2.marks.fontSize,
142
+ paragraph = _tr$doc$type$schema2.nodes.paragraph;
126
143
  if (!fontSize) {
127
144
  return null;
128
145
  }
129
146
  var selection = tr.selection;
130
- var ranges = selection instanceof _editorTables.CellSelection ? selection.ranges : [selection];
131
- ranges.forEach(function (_ref6) {
132
- var $from = _ref6.$from,
133
- $to = _ref6.$to;
134
- tr.setBlockType($from.pos, $to.pos, paragraph);
135
- });
136
- (0, _commands.toggleBlockMarkNext)(fontSize, function () {
137
- return {
138
- fontSize: 'small'
139
- };
140
- }, [paragraph])(tr);
147
+ if (selection instanceof _editorTables.CellSelection) {
148
+ selection.forEachCell(function (cell, pos) {
149
+ tr.setBlockType(pos, pos + cell.nodeSize, paragraph);
150
+ (0, _commands.createToggleBlockMarkOnRangeNext)(fontSize, function () {
151
+ return {
152
+ fontSize: 'small'
153
+ };
154
+ }, [paragraph])(pos, pos + cell.nodeSize, tr);
155
+ });
156
+ } else {
157
+ tr.setBlockType(selection.from, selection.to, paragraph);
158
+ var expandedRange = (0, _utils2.getSelectionRangeExpandedToLists)(tr);
159
+ (0, _commands.createToggleBlockMarkOnRangeNext)(fontSize, function () {
160
+ return {
161
+ fontSize: 'small'
162
+ };
163
+ }, [paragraph])(expandedRange.from, expandedRange.to, tr);
164
+ }
141
165
  return tr;
142
166
  };
143
167
  }
144
168
  function setSmallTextWithAnalytics(inputMethod, editorAnalyticsApi) {
145
169
  return withCurrentHeadingLevel(function (previousHeadingLevel) {
146
- return function (_ref7) {
147
- var tr = _ref7.tr;
170
+ return function (_ref6) {
171
+ var tr = _ref6.tr;
148
172
  editorAnalyticsApi === null || editorAnalyticsApi === void 0 || editorAnalyticsApi.attachAnalyticsEvent({
149
173
  action: _analytics.ACTION.FORMATTED,
150
174
  actionSubject: _analytics.ACTION_SUBJECT.TEXT,
@@ -162,14 +186,16 @@ function setSmallTextWithAnalytics(inputMethod, editorAnalyticsApi) {
162
186
  });
163
187
  }
164
188
  function setNormalText(fromBlockQuote) {
165
- return function (_ref8) {
166
- var tr = _ref8.tr;
189
+ return function (_ref7) {
190
+ var tr = _ref7.tr;
167
191
  var selection = tr.selection,
168
192
  schema = tr.doc.type.schema;
193
+
194
+ // Apply normal text to the selection range (handles non-list content)
169
195
  var ranges = selection instanceof _editorTables.CellSelection ? selection.ranges : [selection];
170
- ranges.forEach(function (_ref9) {
171
- var $from = _ref9.$from,
172
- $to = _ref9.$to;
196
+ ranges.forEach(function (_ref8) {
197
+ var $from = _ref8.$from,
198
+ $to = _ref8.$to;
173
199
  if (fromBlockQuote) {
174
200
  var range = $from.blockRange($to);
175
201
  if (!range) {
@@ -189,19 +215,28 @@ function setNormalText(fromBlockQuote) {
189
215
  }
190
216
  });
191
217
 
192
- // Remove fontSize mark if present in schema
218
+ // Remove fontSize mark from any lists the selection touches
193
219
  var fontSize = schema.marks.fontSize;
194
220
  if (fontSize && (0, _expValEquals.expValEquals)('platform_editor_small_font_size', 'isEnabled', true)) {
195
- (0, _commands.toggleBlockMarkNext)(fontSize, function () {
196
- return false;
197
- }, [schema.nodes.paragraph])(tr);
221
+ if (selection instanceof _editorTables.CellSelection) {
222
+ selection.forEachCell(function (cell, pos) {
223
+ (0, _commands.createToggleBlockMarkOnRangeNext)(fontSize, function () {
224
+ return false;
225
+ }, [schema.nodes.paragraph])(pos, pos + cell.nodeSize, tr);
226
+ });
227
+ } else {
228
+ var expandedRange = (0, _utils2.getSelectionRangeExpandedToLists)(tr);
229
+ (0, _commands.createToggleBlockMarkOnRangeNext)(fontSize, function () {
230
+ return false;
231
+ }, [schema.nodes.paragraph])(expandedRange.from, expandedRange.to, tr);
232
+ }
198
233
  }
199
234
  return tr;
200
235
  };
201
236
  }
202
237
  function clearFormatting(inputMethod, editorAnalyticsApi) {
203
- return function (_ref0) {
204
- var tr = _ref0.tr;
238
+ return function (_ref9) {
239
+ var tr = _ref9.tr;
205
240
  var formattingCleared = [];
206
241
  var schema = tr.doc.type.schema;
207
242
  _clearFormatting.FORMATTING_MARK_TYPES.forEach(function (mark) {
@@ -258,8 +293,8 @@ function clearFormatting(inputMethod, editorAnalyticsApi) {
258
293
  };
259
294
  }
260
295
  function withCurrentHeadingLevel(fn) {
261
- return function (_ref1) {
262
- var tr = _ref1.tr;
296
+ return function (_ref0) {
297
+ var tr = _ref0.tr;
263
298
  // Find all headings and paragraphs of text
264
299
  var _tr$doc$type$schema$n = tr.doc.type.schema.nodes,
265
300
  heading = _tr$doc$type$schema$n.heading,
@@ -296,8 +331,8 @@ function withCurrentHeadingLevel(fn) {
296
331
  }
297
332
  function setNormalTextWithAnalytics(inputMethod, editorAnalyticsApi, fromBlockQuote) {
298
333
  return withCurrentHeadingLevel(function (previousHeadingLevel) {
299
- return function (_ref10) {
300
- var tr = _ref10.tr;
334
+ return function (_ref1) {
335
+ var tr = _ref1.tr;
301
336
  editorAnalyticsApi === null || editorAnalyticsApi === void 0 || editorAnalyticsApi.attachAnalyticsEvent({
302
337
  action: _analytics.ACTION.FORMATTED,
303
338
  actionSubject: _analytics.ACTION_SUBJECT.TEXT,
@@ -317,8 +352,8 @@ function setNormalTextWithAnalytics(inputMethod, editorAnalyticsApi, fromBlockQu
317
352
  }
318
353
  var setHeadingWithAnalytics = exports.setHeadingWithAnalytics = function setHeadingWithAnalytics(newHeadingLevel, inputMethod, editorAnalyticsApi, fromBlockQuote) {
319
354
  return withCurrentHeadingLevel(function (previousHeadingLevel) {
320
- return function (_ref11) {
321
- var tr = _ref11.tr;
355
+ return function (_ref10) {
356
+ var tr = _ref10.tr;
322
357
  editorAnalyticsApi === null || editorAnalyticsApi === void 0 || editorAnalyticsApi.attachAnalyticsEvent({
323
358
  action: _analytics.ACTION.FORMATTED,
324
359
  actionSubject: _analytics.ACTION_SUBJECT.TEXT,
@@ -367,8 +402,8 @@ var insertBlockQuoteWithAnalytics = exports.insertBlockQuoteWithAnalytics = func
367
402
  };
368
403
  function insertBlockQuoteWithAnalyticsCommand(inputMethod, editorAnalyticsApi) {
369
404
  return withCurrentHeadingLevel(function () {
370
- return function (_ref12) {
371
- var tr = _ref12.tr;
405
+ return function (_ref11) {
406
+ var tr = _ref11.tr;
372
407
  var nodes = tr.doc.type.schema.nodes;
373
408
  editorAnalyticsApi === null || editorAnalyticsApi === void 0 || editorAnalyticsApi.attachAnalyticsEvent({
374
409
  action: _analytics.ACTION.FORMATTED,
@@ -386,8 +421,8 @@ function insertBlockQuoteWithAnalyticsCommand(inputMethod, editorAnalyticsApi) {
386
421
  });
387
422
  }
388
423
  var cleanUpAtTheStartOfDocument = exports.cleanUpAtTheStartOfDocument = function cleanUpAtTheStartOfDocument(state, dispatch) {
389
- var _ref13 = state.selection,
390
- $cursor = _ref13.$cursor;
424
+ var _ref12 = state.selection,
425
+ $cursor = _ref12.$cursor;
391
426
  if ($cursor && !$cursor.nodeBefore && !$cursor.nodeAfter && $cursor.pos === 1) {
392
427
  var tr = state.tr,
393
428
  schema = state.schema;
@@ -88,7 +88,7 @@ var autoformatHeading = function autoformatHeading(headingLevel, editorAnalytics
88
88
  return (0, _blockType.setHeadingWithAnalytics)(headingLevel, _analytics.INPUT_METHOD.FORMATTING, editorAnalyticsApi);
89
89
  };
90
90
  var pluginKey = exports.pluginKey = new _state.PluginKey('blockTypePlugin');
91
- var createPlugin = exports.createPlugin = function createPlugin(editorAPI, dispatch, lastNodeMustBeParagraph, includeBlockQuoteAsTextstyleOption) {
91
+ var createPlugin = exports.createPlugin = function createPlugin(editorAPI, dispatch, lastNodeMustBeParagraph, includeBlockQuoteAsTextstyleOption, allowFontSize) {
92
92
  var _editorAPI$analytics;
93
93
  var editorAnalyticsApi = editorAPI === null || editorAPI === void 0 || (_editorAPI$analytics = editorAPI.analytics) === null || _editorAPI$analytics === void 0 ? void 0 : _editorAPI$analytics.actions;
94
94
  var altKeyLocation = 0;
@@ -122,7 +122,7 @@ var createPlugin = exports.createPlugin = function createPlugin(editorAPI, dispa
122
122
  var formattingIsPresent = (0, _utils.hasBlockQuoteInOptions)(availableBlockTypesInDropdown) ? (0, _utils.checkFormattingIsPresent)(state) : undefined;
123
123
  return {
124
124
  currentBlockType: detectBlockType(availableBlockTypesInDropdown, state),
125
- blockTypesDisabled: (0, _utils.areBlockTypesDisabled)(state),
125
+ blockTypesDisabled: (0, _utils.areBlockTypesDisabled)(state, allowFontSize),
126
126
  availableBlockTypes: availableBlockTypes,
127
127
  availableWrapperBlockTypes: availableWrapperBlockTypes,
128
128
  availableBlockTypesInDropdown: availableBlockTypesInDropdown,
@@ -132,7 +132,7 @@ var createPlugin = exports.createPlugin = function createPlugin(editorAPI, dispa
132
132
  apply: function apply(_tr, oldPluginState, _oldState, newState) {
133
133
  var newPluginState = _objectSpread(_objectSpread({}, oldPluginState), {}, {
134
134
  currentBlockType: detectBlockType(oldPluginState.availableBlockTypesInDropdown, newState),
135
- blockTypesDisabled: (0, _utils.areBlockTypesDisabled)(newState),
135
+ blockTypesDisabled: (0, _utils.areBlockTypesDisabled)(newState, allowFontSize),
136
136
  formattingIsPresent: (0, _utils.hasBlockQuoteInOptions)(oldPluginState.availableBlockTypesInDropdown) ? (0, _utils.checkFormattingIsPresent)(newState) : undefined
137
137
  });
138
138
  if (newPluginState.currentBlockType !== oldPluginState.currentBlockType || newPluginState.blockTypesDisabled !== oldPluginState.blockTypesDisabled || newPluginState.formattingIsPresent !== oldPluginState.formattingIsPresent) {
@@ -14,11 +14,13 @@ var _runtime = require("@compiled/react/runtime");
14
14
  var _reactIntlNext = require("react-intl-next");
15
15
  var _analytics = require("@atlaskit/editor-common/analytics");
16
16
  var _keymaps = require("@atlaskit/editor-common/keymaps");
17
+ var _toolbar = require("@atlaskit/editor-common/toolbar");
17
18
  var _ugcTokens = require("@atlaskit/editor-common/ugc-tokens");
18
19
  var _useSharedPluginStateSelector = require("@atlaskit/editor-common/use-shared-plugin-state-selector");
19
20
  var _editorToolbar = require("@atlaskit/editor-toolbar");
20
21
  var _compiled = require("@atlaskit/primitives/compiled");
21
22
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
23
+ var _utils = require("../../utils");
22
24
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
23
25
  var smallTextStyle = null;
24
26
  var normalStyle = null;
@@ -115,6 +117,12 @@ var shortcuts = {
115
117
  heading5: _keymaps.toggleHeading5,
116
118
  heading6: _keymaps.toggleHeading6
117
119
  };
120
+ var shouldDisableHeadingButton = function shouldDisableHeadingButton(state, blockType) {
121
+ if (!state) {
122
+ return false;
123
+ }
124
+ return (0, _utils.isSelectionInsideListNode)(state) && blockType.name !== 'normal' && blockType.name !== 'smallText';
125
+ };
118
126
  var HeadingButton = exports.HeadingButton = function HeadingButton(_ref2) {
119
127
  var blockType = _ref2.blockType,
120
128
  api = _ref2.api;
@@ -122,14 +130,20 @@ var HeadingButton = exports.HeadingButton = function HeadingButton(_ref2) {
122
130
  formatMessage = _useIntl.formatMessage;
123
131
  var currentBlockType = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'blockType.currentBlockType');
124
132
  var availableBlockTypesInDropdown = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'blockType.availableBlockTypesInDropdown');
133
+ var _useEditorToolbar = (0, _toolbar.useEditorToolbar)(),
134
+ editorView = _useEditorToolbar.editorView;
125
135
  if (!(availableBlockTypesInDropdown !== null && availableBlockTypesInDropdown !== void 0 && availableBlockTypesInDropdown.some(function (availableBlockType) {
126
136
  return availableBlockType.name === blockType.name;
127
137
  }))) {
128
138
  return null;
129
139
  }
140
+ var isDisabled = (0, _expValEquals.expValEquals)('platform_editor_small_font_size', 'isEnabled', true) ? shouldDisableHeadingButton(editorView === null || editorView === void 0 ? void 0 : editorView.state, blockType) : false;
130
141
  var fromBlockQuote = (currentBlockType === null || currentBlockType === void 0 ? void 0 : currentBlockType.name) === 'blockquote';
131
142
  var onClick = function onClick() {
132
143
  var _api$core, _api$blockType;
144
+ if (isDisabled) {
145
+ return;
146
+ }
133
147
  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, _analytics.INPUT_METHOD.TOOLBAR, fromBlockQuote));
134
148
  };
135
149
  var shortcut = (0, _keymaps.formatShortcut)(shortcuts[blockType.name]);
@@ -141,6 +155,7 @@ var HeadingButton = exports.HeadingButton = function HeadingButton(_ref2) {
141
155
  }) : undefined,
142
156
  onClick: onClick,
143
157
  isSelected: isSelected,
158
+ isDisabled: isDisabled,
144
159
  ariaKeyshortcuts: shortcut
145
160
  }, (0, _expValEquals.expValEquals)('platform_editor_toolbar_aifc_use_editor_typography', 'isEnabled', true) ? /*#__PURE__*/React.createElement(HeadingText, {
146
161
  headingType: blockType.name
@@ -9,8 +9,17 @@ var _react = _interopRequireDefault(require("react"));
9
9
  var _reactIntlNext = require("react-intl-next");
10
10
  var _analytics = require("@atlaskit/editor-common/analytics");
11
11
  var _keymaps = require("@atlaskit/editor-common/keymaps");
12
+ var _toolbar = require("@atlaskit/editor-common/toolbar");
12
13
  var _useSharedPluginStateSelector = require("@atlaskit/editor-common/use-shared-plugin-state-selector");
13
14
  var _editorToolbar = require("@atlaskit/editor-toolbar");
15
+ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
16
+ var _utils = require("../../utils");
17
+ var shouldDisableQuoteButton = function shouldDisableQuoteButton(state) {
18
+ if (!state) {
19
+ return false;
20
+ }
21
+ return (0, _utils.isSelectionInsideListNode)(state);
22
+ };
14
23
  var QuoteButton = exports.QuoteButton = function QuoteButton(_ref) {
15
24
  var blockType = _ref.blockType,
16
25
  api = _ref.api;
@@ -18,13 +27,19 @@ var QuoteButton = exports.QuoteButton = function QuoteButton(_ref) {
18
27
  formatMessage = _useIntl.formatMessage;
19
28
  var availableBlockTypesInDropdown = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'blockType.availableBlockTypesInDropdown');
20
29
  var currentBlockType = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'blockType.currentBlockType');
30
+ var _useEditorToolbar = (0, _toolbar.useEditorToolbar)(),
31
+ editorView = _useEditorToolbar.editorView;
21
32
  if (!(availableBlockTypesInDropdown !== null && availableBlockTypesInDropdown !== void 0 && availableBlockTypesInDropdown.some(function (availableBlockType) {
22
33
  return availableBlockType.name === blockType.name;
23
34
  }))) {
24
35
  return null;
25
36
  }
37
+ var isDisabled = (0, _expValEquals.expValEquals)('platform_editor_small_font_size', 'isEnabled', true) ? shouldDisableQuoteButton(editorView === null || editorView === void 0 ? void 0 : editorView.state) : false;
26
38
  var onClick = function onClick() {
27
39
  var _api$core, _api$blockType;
40
+ if (isDisabled) {
41
+ return;
42
+ }
28
43
  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(_analytics.INPUT_METHOD.TOOLBAR));
29
44
  };
30
45
  var shortcut = (0, _keymaps.formatShortcut)(_keymaps.toggleBlockQuote);
@@ -35,6 +50,7 @@ var QuoteButton = exports.QuoteButton = function QuoteButton(_ref) {
35
50
  }) : undefined,
36
51
  onClick: onClick,
37
52
  isSelected: currentBlockType === blockType,
53
+ isDisabled: isDisabled,
38
54
  ariaKeyshortcuts: shortcut
39
55
  }, formatMessage(blockType.title));
40
56
  };
@@ -4,9 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.areBlockTypesDisabled = areBlockTypesDisabled;
7
- exports.isNodeAWrappingBlockNode = exports.hasBlockQuoteInOptions = exports.createWrappingTextBlockRule = exports.createJoinNodesRule = exports.checkFormattingIsPresent = void 0;
7
+ exports.createWrappingTextBlockRule = exports.createJoinNodesRule = exports.checkFormattingIsPresent = void 0;
8
+ exports.getSelectionRangeExpandedToLists = getSelectionRangeExpandedToLists;
9
+ exports.isNodeAWrappingBlockNode = exports.hasBlockQuoteInOptions = void 0;
10
+ exports.isSelectionInsideListNode = isSelectionInsideListNode;
8
11
  var _mark = require("@atlaskit/editor-common/mark");
9
12
  var _utils = require("@atlaskit/editor-common/utils");
13
+ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
10
14
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
11
15
  var _blockTypes = require("./block-types");
12
16
  var isNodeAWrappingBlockNode = exports.isNodeAWrappingBlockNode = function isNodeAWrappingBlockNode(node) {
@@ -80,12 +84,19 @@ function getSelectedWrapperNodes(state) {
80
84
  * Function will check if changing block types: Paragraph, Heading is enabled.
81
85
  */
82
86
  function areBlockTypesDisabled(state) {
87
+ var allowFontSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
83
88
  var nodesTypes = getSelectedWrapperNodes(state);
84
89
  var _state$schema$nodes2 = state.schema.nodes,
85
90
  panel = _state$schema$nodes2.panel,
86
91
  blockquote = _state$schema$nodes2.blockquote,
87
92
  bulletList = _state$schema$nodes2.bulletList,
88
- orderedList = _state$schema$nodes2.orderedList;
93
+ orderedList = _state$schema$nodes2.orderedList,
94
+ listItem = _state$schema$nodes2.listItem;
95
+
96
+ // When the small font size experiment is enabled, allow block type changes inside lists
97
+ // so that users can toggle between Normal text and Small text within list contexts.
98
+ // Note: taskList/taskItem are not excluded here until blockTaskItem conversion is implemented (WI 4).
99
+ var excludedTypes = allowFontSize && (0, _expValEquals.expValEquals)('platform_editor_small_font_size', 'isEnabled', true) ? [panel, bulletList, orderedList, listItem] : [panel];
89
100
  if ((0, _experiments.editorExperiment)('platform_editor_blockquote_in_text_formatting_menu', true)) {
90
101
  var hasQuote = false;
91
102
  var hasNestedListInQuote = false;
@@ -106,17 +117,44 @@ function areBlockTypesDisabled(state) {
106
117
  return !hasNestedListInQuote;
107
118
  });
108
119
  return nodesTypes.filter(function (type) {
109
- return type !== panel;
120
+ return !excludedTypes.includes(type);
110
121
  }).length > 0 && (!hasQuote || hasNestedListInQuote);
111
122
  }
112
123
  return nodesTypes.filter(function (type) {
113
- return type !== panel;
124
+ return !excludedTypes.includes(type);
114
125
  }).length > 0;
115
126
  }
116
- var blockStylingIsPresent = function blockStylingIsPresent(state) {
127
+
128
+ /**
129
+ * Checks if the current selection is inside a list node (bulletList, orderedList, or taskList).
130
+ * Used to determine which text styles should be enabled when the small font size experiment is active.
131
+ */
132
+ function isSelectionInsideListNode(state) {
133
+ if (!state.selection) {
134
+ return false;
135
+ }
117
136
  var _state$selection3 = state.selection,
118
- from = _state$selection3.from,
119
- to = _state$selection3.to;
137
+ $from = _state$selection3.$from,
138
+ $to = _state$selection3.$to;
139
+ var _state$schema$nodes3 = state.schema.nodes,
140
+ bulletList = _state$schema$nodes3.bulletList,
141
+ orderedList = _state$schema$nodes3.orderedList,
142
+ taskList = _state$schema$nodes3.taskList;
143
+ var listNodeTypes = [bulletList, orderedList, taskList];
144
+ var insideList = false;
145
+ state.doc.nodesBetween($from.pos, $to.pos, function (node) {
146
+ if (node.isBlock && listNodeTypes.indexOf(node.type) >= 0) {
147
+ insideList = true;
148
+ return false;
149
+ }
150
+ return true;
151
+ });
152
+ return insideList;
153
+ }
154
+ var blockStylingIsPresent = function blockStylingIsPresent(state) {
155
+ var _state$selection4 = state.selection,
156
+ from = _state$selection4.from,
157
+ to = _state$selection4.to;
120
158
  var isBlockStyling = false;
121
159
  state.doc.nodesBetween(from, to, function (node) {
122
160
  if (_blockTypes.FORMATTING_NODE_TYPES.indexOf(node.type.name) !== -1) {
@@ -130,9 +168,9 @@ var blockStylingIsPresent = function blockStylingIsPresent(state) {
130
168
  var marksArePresent = function marksArePresent(state) {
131
169
  var activeMarkTypes = _blockTypes.FORMATTING_MARK_TYPES.filter(function (mark) {
132
170
  if (!!state.schema.marks[mark]) {
133
- var _state$selection4 = state.selection,
134
- $from = _state$selection4.$from,
135
- empty = _state$selection4.empty;
171
+ var _state$selection5 = state.selection,
172
+ $from = _state$selection5.$from,
173
+ empty = _state$selection5.empty;
136
174
  var marks = state.schema.marks;
137
175
  if (empty) {
138
176
  return !!marks[mark].isInSet(state.storedMarks || $from.marks());
@@ -150,4 +188,40 @@ var hasBlockQuoteInOptions = exports.hasBlockQuoteInOptions = function hasBlockQ
150
188
  return !!dropdownOptions.find(function (blockType) {
151
189
  return blockType.name === 'blockquote';
152
190
  });
153
- };
191
+ };
192
+
193
+ /**
194
+ * Returns a { from, to } range that extends the selection boundaries outward
195
+ * to include the entirety of any list nodes at either end. If the selection
196
+ * start is inside a list, `from` is pulled back to the list's start; if the
197
+ * selection end is inside a list, `to` is pushed forward to the list's end.
198
+ * Non-list content in the middle is included as-is.
199
+ */
200
+ function getSelectionRangeExpandedToLists(tr) {
201
+ var selection = tr.selection;
202
+ var _tr$doc$type$schema$n = tr.doc.type.schema.nodes,
203
+ bulletList = _tr$doc$type$schema$n.bulletList,
204
+ orderedList = _tr$doc$type$schema$n.orderedList,
205
+ taskList = _tr$doc$type$schema$n.taskList;
206
+ var listNodeTypes = [bulletList, orderedList, taskList];
207
+ var from = selection.from;
208
+ var to = selection.to;
209
+ for (var depth = selection.$from.depth; depth > 0; depth--) {
210
+ var node = selection.$from.node(depth);
211
+ if (listNodeTypes.indexOf(node.type) >= 0) {
212
+ from = selection.$from.before(depth);
213
+ break;
214
+ }
215
+ }
216
+ for (var _depth = selection.$to.depth; _depth > 0; _depth--) {
217
+ var _node = selection.$to.node(_depth);
218
+ if (listNodeTypes.indexOf(_node.type) >= 0) {
219
+ to = selection.$to.after(_depth);
220
+ break;
221
+ }
222
+ }
223
+ return {
224
+ from: from,
225
+ to: to
226
+ };
227
+ }
@@ -165,7 +165,7 @@ const blockTypePlugin = ({
165
165
  name: 'blockType',
166
166
  plugin: ({
167
167
  dispatch
168
- }) => createPlugin(api, dispatch, options && options.lastNodeMustBeParagraph, options === null || options === void 0 ? void 0 : options.includeBlockQuoteAsTextstyleOption)
168
+ }) => createPlugin(api, dispatch, options && options.lastNodeMustBeParagraph, options === null || options === void 0 ? void 0 : options.includeBlockQuoteAsTextstyleOption, options === null || options === void 0 ? void 0 : options.allowFontSize)
169
169
  }, {
170
170
  name: 'blockTypeInputRule',
171
171
  plugin: ({
@@ -1,11 +1,12 @@
1
1
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
2
- import { toggleBlockMarkNext } from '@atlaskit/editor-common/commands';
2
+ import { createToggleBlockMarkOnRangeNext } from '@atlaskit/editor-common/commands';
3
3
  import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
4
4
  import { filterChildrenBetween, wrapSelectionIn } from '@atlaskit/editor-common/utils';
5
5
  import { liftTarget } from '@atlaskit/editor-prosemirror/transform';
6
6
  import { CellSelection } from '@atlaskit/editor-tables';
7
7
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
8
8
  import { HEADINGS_BY_NAME, NORMAL_TEXT } from '../block-types';
9
+ import { getSelectionRangeExpandedToLists } from '../utils';
9
10
  import { FORMATTING_NODE_TYPES, FORMATTING_MARK_TYPES, cellSelectionNodesBetween, formatTypes, clearNodeFormattingOnSelection } from './clear-formatting';
10
11
  import { wrapSelectionInBlockType } from './wrapSelectionIn';
11
12
  export function setBlockType(name) {
@@ -76,11 +77,23 @@ export function setHeading(level, fromBlockQuote) {
76
77
  });
77
78
  }
78
79
  });
80
+
81
+ // Remove fontSize mark from transformed content in range
82
+ // List content stays as paragraphs (headings aren't allowed in list items),
83
+ // but non-list content has been converted to headings by setBlockType above.
79
84
  const {
80
85
  fontSize
81
86
  } = schema.marks;
82
87
  if (fontSize && expValEquals('platform_editor_small_font_size', 'isEnabled', true)) {
83
- toggleBlockMarkNext(fontSize, () => false, [schema.nodes.heading])(tr);
88
+ const allowedBlocks = [schema.nodes.paragraph, schema.nodes.heading];
89
+ if (selection instanceof CellSelection) {
90
+ selection.forEachCell((cell, pos) => {
91
+ createToggleBlockMarkOnRangeNext(fontSize, () => false, allowedBlocks)(pos, pos + cell.nodeSize, tr);
92
+ });
93
+ } else {
94
+ const expandedRange = getSelectionRangeExpandedToLists(tr);
95
+ createToggleBlockMarkOnRangeNext(fontSize, () => false, allowedBlocks)(expandedRange.from, expandedRange.to, tr);
96
+ }
84
97
  }
85
98
  return tr;
86
99
  };
@@ -90,14 +103,15 @@ export function setBlockTypeWithAnalytics(name, inputMethod, editorAnalyticsApi,
90
103
  tr
91
104
  }) => {
92
105
  const {
93
- nodes
106
+ nodes,
107
+ marks
94
108
  } = tr.doc.type.schema;
95
109
  if (name === 'normal' && nodes.paragraph) {
96
110
  return setNormalTextWithAnalytics(inputMethod, editorAnalyticsApi, fromBlockQuote)({
97
111
  tr
98
112
  });
99
113
  }
100
- if (name === 'smallText' && expValEquals('platform_editor_small_font_size', 'isEnabled', true)) {
114
+ if (name === 'smallText' && marks.fontSize && expValEquals('platform_editor_small_font_size', 'isEnabled', true)) {
101
115
  return setSmallTextWithAnalytics(inputMethod, editorAnalyticsApi)({
102
116
  tr
103
117
  });
@@ -129,16 +143,20 @@ export function setSmallText() {
129
143
  const {
130
144
  selection
131
145
  } = tr;
132
- const ranges = selection instanceof CellSelection ? selection.ranges : [selection];
133
- ranges.forEach(({
134
- $from,
135
- $to
136
- }) => {
137
- tr.setBlockType($from.pos, $to.pos, paragraph);
138
- });
139
- toggleBlockMarkNext(fontSize, () => ({
140
- fontSize: 'small'
141
- }), [paragraph])(tr);
146
+ if (selection instanceof CellSelection) {
147
+ selection.forEachCell((cell, pos) => {
148
+ tr.setBlockType(pos, pos + cell.nodeSize, paragraph);
149
+ createToggleBlockMarkOnRangeNext(fontSize, () => ({
150
+ fontSize: 'small'
151
+ }), [paragraph])(pos, pos + cell.nodeSize, tr);
152
+ });
153
+ } else {
154
+ tr.setBlockType(selection.from, selection.to, paragraph);
155
+ const expandedRange = getSelectionRangeExpandedToLists(tr);
156
+ createToggleBlockMarkOnRangeNext(fontSize, () => ({
157
+ fontSize: 'small'
158
+ }), [paragraph])(expandedRange.from, expandedRange.to, tr);
159
+ }
142
160
  return tr;
143
161
  };
144
162
  }
@@ -173,6 +191,8 @@ export function setNormalText(fromBlockQuote) {
173
191
  }
174
192
  }
175
193
  } = tr;
194
+
195
+ // Apply normal text to the selection range (handles non-list content)
176
196
  const ranges = selection instanceof CellSelection ? selection.ranges : [selection];
177
197
  ranges.forEach(({
178
198
  $from,
@@ -197,12 +217,19 @@ export function setNormalText(fromBlockQuote) {
197
217
  }
198
218
  });
199
219
 
200
- // Remove fontSize mark if present in schema
220
+ // Remove fontSize mark from any lists the selection touches
201
221
  const {
202
222
  fontSize
203
223
  } = schema.marks;
204
224
  if (fontSize && expValEquals('platform_editor_small_font_size', 'isEnabled', true)) {
205
- toggleBlockMarkNext(fontSize, () => false, [schema.nodes.paragraph])(tr);
225
+ if (selection instanceof CellSelection) {
226
+ selection.forEachCell((cell, pos) => {
227
+ createToggleBlockMarkOnRangeNext(fontSize, () => false, [schema.nodes.paragraph])(pos, pos + cell.nodeSize, tr);
228
+ });
229
+ } else {
230
+ const expandedRange = getSelectionRangeExpandedToLists(tr);
231
+ createToggleBlockMarkOnRangeNext(fontSize, () => false, [schema.nodes.paragraph])(expandedRange.from, expandedRange.to, tr);
232
+ }
206
233
  }
207
234
  return tr;
208
235
  };