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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/blockTypePlugin.js +3 -0
  3. package/dist/cjs/pm-plugins/block-types.js +3 -1
  4. package/dist/cjs/pm-plugins/commands/block-type.js +65 -11
  5. package/dist/cjs/pm-plugins/commands/clear-formatting.js +58 -0
  6. package/dist/cjs/pm-plugins/input-rule.js +18 -2
  7. package/dist/cjs/pm-plugins/keymap.js +26 -2
  8. package/dist/cjs/pm-plugins/main.js +14 -4
  9. package/dist/cjs/pm-plugins/ui/FloatingToolbarComponent.js +9 -1
  10. package/dist/cjs/pm-plugins/ui/PrimaryToolbarComponent.js +8 -0
  11. package/dist/cjs/pm-plugins/ui/ToolbarBlockType/blocktype-button.js +4 -1
  12. package/dist/cjs/pm-plugins/ui/ToolbarBlockType/index.js +83 -46
  13. package/dist/cjs/pm-plugins/ui/ToolbarBlockType/styled.js +15 -1
  14. package/dist/cjs/pm-plugins/utils.js +61 -7
  15. package/dist/es2019/blockTypePlugin.js +4 -1
  16. package/dist/es2019/pm-plugins/block-types.js +2 -0
  17. package/dist/es2019/pm-plugins/commands/block-type.js +57 -2
  18. package/dist/es2019/pm-plugins/commands/clear-formatting.js +50 -0
  19. package/dist/es2019/pm-plugins/input-rule.js +18 -2
  20. package/dist/es2019/pm-plugins/keymap.js +25 -2
  21. package/dist/es2019/pm-plugins/main.js +15 -5
  22. package/dist/es2019/pm-plugins/ui/FloatingToolbarComponent.js +9 -1
  23. package/dist/es2019/pm-plugins/ui/PrimaryToolbarComponent.js +8 -0
  24. package/dist/es2019/pm-plugins/ui/ToolbarBlockType/blocktype-button.js +4 -1
  25. package/dist/es2019/pm-plugins/ui/ToolbarBlockType/index.js +84 -49
  26. package/dist/es2019/pm-plugins/ui/ToolbarBlockType/styled.js +14 -0
  27. package/dist/es2019/pm-plugins/utils.js +63 -7
  28. package/dist/esm/blockTypePlugin.js +4 -1
  29. package/dist/esm/pm-plugins/block-types.js +2 -0
  30. package/dist/esm/pm-plugins/commands/block-type.js +62 -10
  31. package/dist/esm/pm-plugins/commands/clear-formatting.js +50 -0
  32. package/dist/esm/pm-plugins/input-rule.js +18 -2
  33. package/dist/esm/pm-plugins/keymap.js +25 -2
  34. package/dist/esm/pm-plugins/main.js +15 -5
  35. package/dist/esm/pm-plugins/ui/FloatingToolbarComponent.js +9 -1
  36. package/dist/esm/pm-plugins/ui/PrimaryToolbarComponent.js +8 -0
  37. package/dist/esm/pm-plugins/ui/ToolbarBlockType/blocktype-button.js +4 -1
  38. package/dist/esm/pm-plugins/ui/ToolbarBlockType/index.js +85 -48
  39. package/dist/esm/pm-plugins/ui/ToolbarBlockType/styled.js +14 -0
  40. package/dist/esm/pm-plugins/utils.js +61 -7
  41. package/dist/types/blockTypePluginType.d.ts +1 -0
  42. package/dist/types/pm-plugins/block-types.d.ts +2 -0
  43. package/dist/types/pm-plugins/commands/block-type.d.ts +1 -0
  44. package/dist/types/pm-plugins/commands/clear-formatting.d.ts +8 -0
  45. package/dist/types/pm-plugins/main.d.ts +2 -7
  46. package/dist/types/pm-plugins/ui/ToolbarBlockType/index.d.ts +1 -0
  47. package/dist/types/pm-plugins/ui/ToolbarBlockType/styled.d.ts +1 -0
  48. package/dist/types/pm-plugins/utils.d.ts +3 -0
  49. package/dist/types-ts4.5/blockTypePluginType.d.ts +1 -0
  50. package/dist/types-ts4.5/pm-plugins/block-types.d.ts +2 -0
  51. package/dist/types-ts4.5/pm-plugins/commands/block-type.d.ts +1 -0
  52. package/dist/types-ts4.5/pm-plugins/commands/clear-formatting.d.ts +8 -0
  53. package/dist/types-ts4.5/pm-plugins/main.d.ts +2 -7
  54. package/dist/types-ts4.5/pm-plugins/ui/ToolbarBlockType/index.d.ts +1 -0
  55. package/dist/types-ts4.5/pm-plugins/ui/ToolbarBlockType/styled.d.ts +1 -0
  56. package/dist/types-ts4.5/pm-plugins/utils.d.ts +3 -0
  57. package/package.json +3 -3
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.wrapperSmallStyle = exports.keyboardShortcutSelect = exports.keyboardShortcut = exports.expandIconWrapperStyle = exports.blockTypeMenuItemStyle = void 0;
6
+ exports.wrapperSmallStyle = exports.keyboardShortcutSelect = exports.keyboardShortcut = exports.floatingToolbarWrapperStyle = exports.expandIconWrapperStyle = exports.blockTypeMenuItemStyle = void 0;
7
7
  var _react = require("@emotion/react");
8
8
  var _styles = require("@atlaskit/editor-common/styles");
9
9
  var _shortcut = require("@atlaskit/editor-shared-styles/shortcut");
@@ -26,6 +26,12 @@ var blockTypeMenuItemStyle = exports.blockTypeMenuItemStyle = function blockType
26
26
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766
27
27
  'h1, h2, h3, h4, h5, h6': {
28
28
  marginTop: 0
29
+ },
30
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766
31
+ blockquote: {
32
+ paddingTop: 0,
33
+ paddingBottom: 0,
34
+ marginTop: 0
29
35
  }
30
36
  }
31
37
  },
@@ -54,4 +60,12 @@ var wrapperSmallStyle = exports.wrapperSmallStyle = (0, _react.css)({
54
60
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-exported-styles -- Ignored via go/DSP-18766
55
61
  var expandIconWrapperStyle = exports.expandIconWrapperStyle = (0, _react.css)({
56
62
  marginLeft: "var(--ds-space-negative-100, -8px)"
63
+ });
64
+
65
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-exported-styles
66
+ var floatingToolbarWrapperStyle = exports.floatingToolbarWrapperStyle = (0, _react.css)({
67
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors
68
+ "[data-role='droplistContent']": {
69
+ maxHeight: '90vh'
70
+ }
57
71
  });
@@ -4,7 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.areBlockTypesDisabled = areBlockTypesDisabled;
7
- exports.isNodeAWrappingBlockNode = exports.createWrappingTextBlockRule = exports.createJoinNodesRule = void 0;
7
+ exports.isNodeAWrappingBlockNode = exports.hasBlockQuoteInOptions = exports.createWrappingTextBlockRule = exports.createJoinNodesRule = exports.checkFormattingIsPresent = void 0;
8
+ var _mark = require("@atlaskit/editor-common/mark");
8
9
  var _utils = require("@atlaskit/editor-common/utils");
9
10
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
10
11
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
@@ -31,7 +32,10 @@ var createWrappingTextBlockRule = exports.createWrappingTextBlockRule = function
31
32
  var match = _ref.match,
32
33
  nodeType = _ref.nodeType,
33
34
  getAttrs = _ref.getAttrs;
34
- var handler = function handler(state, match, start, end) {
35
+ var handler = function handler(state, match, start, end
36
+ // Ignored via go/ees005
37
+ // eslint-disable-next-line @typescript-eslint/max-params
38
+ ) {
35
39
  var fixedStart = Math.max(start, 1);
36
40
  var $start = state.doc.resolve(fixedStart);
37
41
  var attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs;
@@ -85,21 +89,71 @@ function areBlockTypesDisabled(state) {
85
89
  var nodesTypes = getSelectedWrapperNodes(state);
86
90
  var _state$schema$nodes2 = state.schema.nodes,
87
91
  panel = _state$schema$nodes2.panel,
88
- blockquote = _state$schema$nodes2.blockquote;
92
+ blockquote = _state$schema$nodes2.blockquote,
93
+ bulletList = _state$schema$nodes2.bulletList,
94
+ orderedList = _state$schema$nodes2.orderedList;
89
95
  if ((0, _experiments.editorExperiment)('platform_editor_blockquote_in_text_formatting_menu', true)) {
90
96
  var hasQuote = false;
97
+ var hasNestedListInQuote = false;
91
98
  var _state$selection2 = state.selection,
92
99
  $from = _state$selection2.$from,
93
100
  $to = _state$selection2.$to;
94
101
  state.doc.nodesBetween($from.pos, $to.pos, function (node) {
95
- hasQuote = node.type === blockquote;
96
- return !hasQuote;
102
+ if (node.type === blockquote) {
103
+ hasQuote = true;
104
+ node.descendants(function (child) {
105
+ if (child.type === bulletList || child.type === orderedList) {
106
+ hasNestedListInQuote = true;
107
+ return false;
108
+ }
109
+ return true;
110
+ });
111
+ }
112
+ return !hasNestedListInQuote;
97
113
  });
98
114
  return nodesTypes.filter(function (type) {
99
115
  return type !== panel;
100
- }).length > 0 || hasQuote;
116
+ }).length > 0 && (!hasQuote || hasNestedListInQuote);
101
117
  }
102
118
  return nodesTypes.filter(function (type) {
103
119
  return type !== panel;
104
120
  }).length > 0;
105
- }
121
+ }
122
+ var blockStylingIsPresent = function blockStylingIsPresent(state) {
123
+ var _state$selection3 = state.selection,
124
+ from = _state$selection3.from,
125
+ to = _state$selection3.to;
126
+ var isBlockStyling = false;
127
+ state.doc.nodesBetween(from, to, function (node) {
128
+ if (_blockTypes.FORMATTING_NODE_TYPES.indexOf(node.type.name) !== -1) {
129
+ isBlockStyling = true;
130
+ return false;
131
+ }
132
+ return true;
133
+ });
134
+ return isBlockStyling;
135
+ };
136
+ var marksArePresent = function marksArePresent(state) {
137
+ var activeMarkTypes = _blockTypes.FORMATTING_MARK_TYPES.filter(function (mark) {
138
+ if (!!state.schema.marks[mark]) {
139
+ var _state$selection4 = state.selection,
140
+ $from = _state$selection4.$from,
141
+ empty = _state$selection4.empty;
142
+ var marks = state.schema.marks;
143
+ if (empty) {
144
+ return !!marks[mark].isInSet(state.storedMarks || $from.marks());
145
+ }
146
+ return (0, _mark.anyMarkActive)(state, marks[mark]);
147
+ }
148
+ return false;
149
+ });
150
+ return activeMarkTypes.length > 0;
151
+ };
152
+ var checkFormattingIsPresent = exports.checkFormattingIsPresent = function checkFormattingIsPresent(state) {
153
+ return marksArePresent(state) || blockStylingIsPresent(state);
154
+ };
155
+ var hasBlockQuoteInOptions = exports.hasBlockQuoteInOptions = function hasBlockQuoteInOptions(dropdownOptions) {
156
+ return !!dropdownOptions.find(function (blockType) {
157
+ return blockType.name === 'blockquote';
158
+ });
159
+ };
@@ -7,7 +7,7 @@ import { IconHeading, IconQuote } from '@atlaskit/editor-common/quick-insert';
7
7
  import { ToolbarSize } from '@atlaskit/editor-common/types';
8
8
  import { fg } from '@atlaskit/platform-feature-flags';
9
9
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
10
- import { setBlockTypeWithAnalytics, insertBlockQuoteWithAnalytics, insertBlockQuoteWithAnalyticsCommand } from './pm-plugins/commands/block-type';
10
+ import { setBlockTypeWithAnalytics, insertBlockQuoteWithAnalytics, insertBlockQuoteWithAnalyticsCommand, clearFormatting } from './pm-plugins/commands/block-type';
11
11
  import inputRulePlugin from './pm-plugins/input-rule';
12
12
  import keymapPlugin from './pm-plugins/keymap';
13
13
  import { createPlugin, pluginKey } from './pm-plugins/main';
@@ -181,6 +181,9 @@ const blockTypePlugin = ({
181
181
  insertBlockQuote(inputMethod) {
182
182
  var _api$analytics5;
183
183
  return insertBlockQuoteWithAnalyticsCommand(inputMethod, api === null || api === void 0 ? void 0 : (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions);
184
+ },
185
+ clearFormatting() {
186
+ return clearFormatting();
184
187
  }
185
188
  },
186
189
  getSharedState(editorState) {
@@ -70,6 +70,8 @@ export const OTHER = {
70
70
  nodeName: ''
71
71
  };
72
72
  export const TEXT_BLOCK_TYPES = [NORMAL_TEXT, HEADING_1, HEADING_2, HEADING_3, HEADING_4, HEADING_5, HEADING_6];
73
+ export const FORMATTING_NODE_TYPES = ['heading', 'blockquote'];
74
+ export const FORMATTING_MARK_TYPES = ['em', 'code', 'strike', 'strong', 'underline', 'textColor', 'subsup', 'backgroundColor'];
73
75
  export const WRAPPER_BLOCK_TYPES = [BLOCK_QUOTE, CODE_BLOCK, PANEL];
74
76
  export const ALL_BLOCK_TYPES = TEXT_BLOCK_TYPES.concat(WRAPPER_BLOCK_TYPES);
75
77
  export const getBlockTypesInDropdown = includeBlockQuoteAsTextstyleOption => {
@@ -4,6 +4,7 @@ import { filterChildrenBetween, wrapSelectionIn } from '@atlaskit/editor-common/
4
4
  import { Slice, Fragment } from '@atlaskit/editor-prosemirror/model';
5
5
  import { CellSelection } from '@atlaskit/editor-tables';
6
6
  import { HEADINGS_BY_NAME, NORMAL_TEXT } from '../block-types';
7
+ import { FORMATTING_NODE_TYPES, FORMATTING_MARK_TYPES, cellSelectionNodesBetween, formatTypes, clearNodeFormattingOnSelection } from './clear-formatting';
7
8
  import { wrapSelectionInBlockType } from './wrapSelectionIn';
8
9
  export function setBlockType(name) {
9
10
  return ({
@@ -63,6 +64,9 @@ export function setHeading(level, fromBlockQuote) {
63
64
  return tr;
64
65
  };
65
66
  }
67
+
68
+ // Ignored via go/ees005
69
+ // eslint-disable-next-line @typescript-eslint/max-params
66
70
  export function setBlockTypeWithAnalytics(name, inputMethod, editorAnalyticsApi, fromBlockQuote) {
67
71
  return ({
68
72
  tr
@@ -114,6 +118,54 @@ export function setNormalText(fromBlockQuote) {
114
118
  return tr;
115
119
  };
116
120
  }
121
+ export function clearFormatting() {
122
+ return function ({
123
+ tr
124
+ }) {
125
+ const formattingCleared = [];
126
+ const schema = tr.doc.type.schema;
127
+ FORMATTING_MARK_TYPES.forEach(mark => {
128
+ const {
129
+ from,
130
+ to
131
+ } = tr.selection;
132
+ const markType = schema.marks[mark];
133
+ if (!markType) {
134
+ return;
135
+ }
136
+ if (tr.selection instanceof CellSelection) {
137
+ cellSelectionNodesBetween(tr.selection, tr.doc, (node, pos) => {
138
+ const isTableCell = node.type === schema.nodes.tableCell || node.type === schema.nodes.tableHeader;
139
+ if (!isTableCell) {
140
+ return true;
141
+ }
142
+ if (tr.doc.rangeHasMark(pos, pos + node.nodeSize, markType)) {
143
+ formattingCleared.push(formatTypes[mark]);
144
+ tr.removeMark(pos, pos + node.nodeSize, markType);
145
+ }
146
+ return false;
147
+ });
148
+ } else if (tr.doc.rangeHasMark(from, to, markType)) {
149
+ formattingCleared.push(formatTypes[mark]);
150
+ tr.removeMark(from, to, markType);
151
+ }
152
+ });
153
+ FORMATTING_NODE_TYPES.forEach(nodeName => {
154
+ const formattedNodeType = schema.nodes[nodeName];
155
+ const {
156
+ $from,
157
+ $to
158
+ } = tr.selection;
159
+ if (tr.selection instanceof CellSelection) {
160
+ cellSelectionNodesBetween(tr.selection, tr.doc, clearNodeFormattingOnSelection(schema, tr, formattedNodeType, nodeName, formattingCleared));
161
+ } else {
162
+ tr.doc.nodesBetween($from.pos, $to.pos, clearNodeFormattingOnSelection(schema, tr, formattedNodeType, nodeName, formattingCleared));
163
+ }
164
+ });
165
+ tr.setStoredMarks([]);
166
+ return tr;
167
+ };
168
+ }
117
169
  function withCurrentHeadingLevel(fn) {
118
170
  return ({
119
171
  tr
@@ -129,7 +181,7 @@ function withCurrentHeadingLevel(fn) {
129
181
 
130
182
  // Check each paragraph and/or heading and check for consistent level
131
183
  let level;
132
- for (let node of nodes) {
184
+ for (const node of nodes) {
133
185
  const nodeLevel = node.node.type === heading ? node.node.attrs.level : 0;
134
186
  if (!level) {
135
187
  level = nodeLevel;
@@ -164,7 +216,10 @@ export function setNormalTextWithAnalytics(inputMethod, editorAnalyticsApi, from
164
216
  });
165
217
  });
166
218
  }
167
- export const setHeadingWithAnalytics = (newHeadingLevel, inputMethod, editorAnalyticsApi, fromBlockQuote) => {
219
+ export const setHeadingWithAnalytics = (newHeadingLevel, inputMethod, editorAnalyticsApi, fromBlockQuote
220
+ // Ignored via go/ees005
221
+ // eslint-disable-next-line @typescript-eslint/max-params
222
+ ) => {
168
223
  return withCurrentHeadingLevel(previousHeadingLevel => ({
169
224
  tr
170
225
  }) => {
@@ -0,0 +1,50 @@
1
+ import { ACTION_SUBJECT_ID } from '@atlaskit/editor-common/analytics';
2
+ import { liftTarget } from '@atlaskit/editor-prosemirror/transform';
3
+ // Functions duplicated from platform/packages/editor/editor-plugin-text-formatting/src/editor-commands/clear-formatting.ts
4
+ // TODO: Refactor to avoid duplication if platform_editor_blockquote_in_text_formatting_menu experiment is productionalised
5
+ export const FORMATTING_NODE_TYPES = ['heading', 'blockquote'];
6
+ export const FORMATTING_MARK_TYPES = ['em', 'code', 'strike', 'strong', 'underline', 'textColor', 'subsup', 'backgroundColor'];
7
+ export const formatTypes = {
8
+ em: ACTION_SUBJECT_ID.FORMAT_ITALIC,
9
+ code: ACTION_SUBJECT_ID.FORMAT_CODE,
10
+ strike: ACTION_SUBJECT_ID.FORMAT_STRIKE,
11
+ strong: ACTION_SUBJECT_ID.FORMAT_STRONG,
12
+ underline: ACTION_SUBJECT_ID.FORMAT_UNDERLINE,
13
+ textColor: ACTION_SUBJECT_ID.FORMAT_COLOR,
14
+ subsup: 'subsup',
15
+ backgroundColor: ACTION_SUBJECT_ID.FORMAT_BACKGROUND_COLOR
16
+ };
17
+ export const cellSelectionNodesBetween = (selection, doc, f, startPos
18
+ // eslint-disable-next-line @typescript-eslint/max-params
19
+ ) => {
20
+ selection.forEachCell((cell, cellPos) => {
21
+ doc.nodesBetween(cellPos, cellPos + cell.nodeSize, f, startPos);
22
+ });
23
+ };
24
+
25
+ // eslint-disable-next-line @typescript-eslint/max-params
26
+ export function clearNodeFormattingOnSelection(schema, tr, formattedNodeType, nodeName, formattingCleared) {
27
+ return function (node, pos) {
28
+ if (node.type === formattedNodeType) {
29
+ if (formattedNodeType.isTextblock) {
30
+ tr.setNodeMarkup(pos, schema.nodes.paragraph);
31
+ formattingCleared.push(nodeName);
32
+ return false;
33
+ } else {
34
+ // In case of panel or blockquote
35
+ const fromPos = tr.doc.resolve(pos + 1);
36
+ const toPos = tr.doc.resolve(pos + node.nodeSize - 1);
37
+ const nodeRange = fromPos.blockRange(toPos);
38
+ if (nodeRange) {
39
+ const targetLiftDepth = liftTarget(nodeRange);
40
+ if (targetLiftDepth || targetLiftDepth === 0) {
41
+ formattingCleared.push(nodeName);
42
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
43
+ tr.lift(nodeRange, targetLiftDepth);
44
+ }
45
+ }
46
+ }
47
+ }
48
+ return true;
49
+ };
50
+ }
@@ -12,12 +12,16 @@ function getHeadingLevel(match) {
12
12
  }
13
13
  function headingRule(nodeType, maxLevel) {
14
14
  return createWrappingTextBlockRule({
15
+ // Ignored via go/ees005
16
+ // eslint-disable-next-line require-unicode-regexp
15
17
  match: new RegExp('^(#{1,' + maxLevel + '})\\s$'),
16
18
  nodeType,
17
19
  getAttrs: getHeadingLevel
18
20
  });
19
21
  }
20
22
  function blockQuoteRule(nodeType) {
23
+ // Ignored via go/ees005
24
+ // eslint-disable-next-line require-unicode-regexp
21
25
  return createJoinNodesRule(/^\s*>\s$/, nodeType);
22
26
  }
23
27
 
@@ -30,7 +34,13 @@ function blockQuoteRule(nodeType) {
30
34
  function getHeadingRules(editorAnalyticsAPI, schema) {
31
35
  // '# ' for h1, '## ' for h2 and etc
32
36
  const hashRule = headingRule(schema.nodes.heading, MAX_HEADING_LEVEL);
33
- const leftNodeReplacementHashRule = createRule(new RegExp(`${leafNodeReplacementCharacter}(#{1,6})\\s$`), (state, match, start, end) => {
37
+ const leftNodeReplacementHashRule = createRule(
38
+ // Ignored via go/ees005
39
+ // eslint-disable-next-line require-unicode-regexp
40
+ new RegExp(`${leafNodeReplacementCharacter}(#{1,6})\\s$`),
41
+ // Ignored via go/ees005
42
+ // eslint-disable-next-line @typescript-eslint/max-params
43
+ (state, match, start, end) => {
34
44
  const level = match[1].length;
35
45
  return insertBlock(state, schema.nodes.heading, start, end, {
36
46
  level
@@ -60,7 +70,13 @@ function getHeadingRules(editorAnalyticsAPI, schema) {
60
70
  function getBlockQuoteRules(editorAnalyticsAPI, schema) {
61
71
  // '> ' for blockquote
62
72
  const greatherThanRule = blockQuoteRule(schema.nodes.blockquote);
63
- const leftNodeReplacementGreatherRule = createRule(new RegExp(`${leafNodeReplacementCharacter}\\s*>\\s$`), (state, _match, start, end) => {
73
+ const leftNodeReplacementGreatherRule = createRule(
74
+ // Ignored via go/ees005
75
+ // eslint-disable-next-line require-unicode-regexp
76
+ new RegExp(`${leafNodeReplacementCharacter}\\s*>\\s$`),
77
+ // Ignored via go/ees005
78
+ // eslint-disable-next-line @typescript-eslint/max-params
79
+ (state, _match, start, end) => {
64
80
  return insertBlock(state, schema.nodes.blockquote, start, end);
65
81
  });
66
82
 
@@ -3,6 +3,8 @@ import { backspace, bindKeymapWithCommand, deleteKey, findKeyMapForBrowser, find
3
3
  import { createNewParagraphAbove, createNewParagraphBelow, deleteEmptyParagraphAndMoveBlockUp, insertNewLineWithAnalytics } from '@atlaskit/editor-common/utils';
4
4
  import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
5
5
  import { redo, undo } from '@atlaskit/editor-prosemirror/history';
6
+ // Ignored via go/ees005
7
+ // eslint-disable-next-line import/no-namespace
6
8
  import * as blockTypes from './block-types';
7
9
  import { cleanUpAtTheStartOfDocument, insertBlockQuoteWithAnalytics } from './commands/block-type';
8
10
  import { deleteAndMoveCursor } from './commands/delete-and-move-cursor';
@@ -12,16 +14,37 @@ const backspaceCommand = chainCommands(cleanUpAtTheStartOfDocument, deleteBlockC
12
14
  const del = chainCommands(deleteEmptyParagraphAndMoveBlockUp(isNodeAWrappingBlockNode), deleteBlockContent(isNodeAWrappingBlockNode), deleteAndMoveCursor);
13
15
  export default function keymapPlugin(editorAnalyticsApi, schema, _featureFlags) {
14
16
  const list = {};
15
- bindKeymapWithCommand(insertNewLine.common, insertNewLineWithAnalytics(editorAnalyticsApi), list);
17
+ bindKeymapWithCommand(
18
+ // Ignored via go/ees005
19
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
20
+ insertNewLine.common, insertNewLineWithAnalytics(editorAnalyticsApi), list);
21
+ // Ignored via go/ees005
22
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
16
23
  bindKeymapWithCommand(moveUp.common, createNewParagraphAbove, list);
24
+ // Ignored via go/ees005
25
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
17
26
  bindKeymapWithCommand(moveDown.common, createNewParagraphBelow, list);
27
+ // Ignored via go/ees005
28
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
18
29
  bindKeymapWithCommand(findKeyMapForBrowser(redoKeymap), redo, list);
30
+
31
+ // Ignored via go/ees005
32
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
19
33
  bindKeymapWithCommand(undoKeymap.common, undo, list);
34
+
35
+ // Ignored via go/ees005
36
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
20
37
  bindKeymapWithCommand(backspace.common, backspaceCommand, list);
38
+
39
+ // Ignored via go/ees005
40
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
21
41
  bindKeymapWithCommand(deleteKey.common, del, list);
22
42
  bindKeymapWithCommand(forwardDelete.mac, del, list);
23
43
  if (schema.nodes[blockTypes.BLOCK_QUOTE.nodeName]) {
24
- bindKeymapWithCommand(findShortcutByKeymap(toggleBlockQuote), insertBlockQuoteWithAnalytics(INPUT_METHOD.KEYBOARD, editorAnalyticsApi), list);
44
+ bindKeymapWithCommand(
45
+ // Ignored via go/ees005
46
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
47
+ findShortcutByKeymap(toggleBlockQuote), insertBlockQuoteWithAnalytics(INPUT_METHOD.KEYBOARD, editorAnalyticsApi), list);
25
48
  }
26
49
  return keymap(list);
27
50
  }
@@ -6,7 +6,7 @@ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
6
6
  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';
7
7
  import { setHeadingWithAnalytics, setNormalTextWithAnalytics } from './commands/block-type';
8
8
  import { HEADING_KEYS } from './consts';
9
- import { areBlockTypesDisabled } from './utils';
9
+ import { areBlockTypesDisabled, checkFormattingIsPresent, hasBlockQuoteInOptions } from './utils';
10
10
  const blockTypeForNode = (node, schema) => {
11
11
  if (node.type === schema.nodes.heading) {
12
12
  const maybeNode = HEADINGS_BY_LEVEL[node.attrs['level']];
@@ -70,7 +70,10 @@ const autoformatHeading = (headingLevel, editorAnalyticsApi) => {
70
70
  return setHeadingWithAnalytics(headingLevel, INPUT_METHOD.FORMATTING, editorAnalyticsApi);
71
71
  };
72
72
  export const pluginKey = new PluginKey('blockTypePlugin');
73
- export const createPlugin = (editorAPI, dispatch, lastNodeMustBeParagraph, includeBlockQuoteAsTextstyleOption) => {
73
+ export const createPlugin = (editorAPI, dispatch, lastNodeMustBeParagraph, includeBlockQuoteAsTextstyleOption
74
+ // Ignored via go/ees005
75
+ // eslint-disable-next-line @typescript-eslint/max-params
76
+ ) => {
74
77
  var _editorAPI$analytics;
75
78
  const editorAnalyticsApi = editorAPI === null || editorAPI === void 0 ? void 0 : (_editorAPI$analytics = editorAPI.analytics) === null || _editorAPI$analytics === void 0 ? void 0 : _editorAPI$analytics.actions;
76
79
  let altKeyLocation = 0;
@@ -93,21 +96,26 @@ export const createPlugin = (editorAPI, dispatch, lastNodeMustBeParagraph, inclu
93
96
  const availableWrapperBlockTypes = WRAPPER_BLOCK_TYPES.filter(blockType => isBlockTypeSchemaSupported(blockType, state));
94
97
  const BLOCK_TYPES_IN_DROPDOWN = getBlockTypesInDropdown(includeBlockQuoteAsTextstyleOption);
95
98
  const availableBlockTypesInDropdown = BLOCK_TYPES_IN_DROPDOWN.filter(blockType => isBlockTypeSchemaSupported(blockType, state));
99
+ const formattingIsPresent = hasBlockQuoteInOptions(availableBlockTypesInDropdown) ? checkFormattingIsPresent(state) : undefined;
96
100
  return {
97
101
  currentBlockType: detectBlockType(availableBlockTypesInDropdown, state),
98
102
  blockTypesDisabled: areBlockTypesDisabled(state),
99
103
  availableBlockTypes,
100
104
  availableWrapperBlockTypes,
101
- availableBlockTypesInDropdown
105
+ availableBlockTypesInDropdown,
106
+ formattingIsPresent
102
107
  };
103
108
  },
109
+ // Ignored via go/ees005
110
+ // eslint-disable-next-line @typescript-eslint/max-params
104
111
  apply(_tr, oldPluginState, _oldState, newState) {
105
112
  const newPluginState = {
106
113
  ...oldPluginState,
107
114
  currentBlockType: detectBlockType(oldPluginState.availableBlockTypesInDropdown, newState),
108
- blockTypesDisabled: areBlockTypesDisabled(newState)
115
+ blockTypesDisabled: areBlockTypesDisabled(newState),
116
+ formattingIsPresent: hasBlockQuoteInOptions(oldPluginState.availableBlockTypesInDropdown) ? checkFormattingIsPresent(newState) : undefined
109
117
  };
110
- if (newPluginState.currentBlockType !== oldPluginState.currentBlockType || newPluginState.blockTypesDisabled !== oldPluginState.blockTypesDisabled) {
118
+ if (newPluginState.currentBlockType !== oldPluginState.currentBlockType || newPluginState.blockTypesDisabled !== oldPluginState.blockTypesDisabled || newPluginState.formattingIsPresent !== oldPluginState.formattingIsPresent) {
111
119
  dispatch(pluginKey, newPluginState);
112
120
  }
113
121
  return newPluginState;
@@ -141,6 +149,8 @@ export const createPlugin = (editorAPI, dispatch, lastNodeMustBeParagraph, inclu
141
149
  }
142
150
  return false;
143
151
  },
152
+ // Ignored via go/ees005
153
+ // eslint-disable-next-line @typescript-eslint/max-params
144
154
  handleDrop(view, event, slice, moved) {
145
155
  return handleBlockQuoteDND(view, event, slice);
146
156
  }
@@ -22,13 +22,21 @@ export function FloatingToolbarComponent({
22
22
  var _api$core2, _api$blockType2, _api$blockType2$comma;
23
23
  return api === null || api === void 0 ? void 0 : (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions.execute(api === null || api === void 0 ? void 0 : (_api$blockType2 = api.blockType) === null || _api$blockType2 === void 0 ? void 0 : (_api$blockType2$comma = _api$blockType2.commands) === null || _api$blockType2$comma === void 0 ? void 0 : _api$blockType2$comma.insertBlockQuote(INPUT_METHOD.TOOLBAR));
24
24
  }, [api]);
25
+ const clearFormatting = useCallback(() => {
26
+ var _api$core3, _api$blockType3, _api$blockType3$comma;
27
+ return api === null || api === void 0 ? void 0 : (_api$core3 = api.core) === null || _api$core3 === void 0 ? void 0 : _api$core3.actions.execute(api === null || api === void 0 ? void 0 : (_api$blockType3 = api.blockType) === null || _api$blockType3 === void 0 ? void 0 : (_api$blockType3$comma = _api$blockType3.commands) === null || _api$blockType3$comma === void 0 ? void 0 : _api$blockType3$comma.clearFormatting());
28
+ }, [api]);
25
29
  return /*#__PURE__*/React.createElement(ToolbarBlockType, {
26
30
  isSmall: FloatingToolbarSettings.isSmall,
27
31
  isDisabled: FloatingToolbarSettings.disabled,
28
32
  isReducedSpacing: FloatingToolbarSettings.isToolbarReducedSpacing,
29
- setTextLevel: boundSetBlockType,
33
+ setTextLevel: boundSetBlockType
34
+ // Ignored via go/ees005
35
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
36
+ ,
30
37
  pluginState: blockTypeState,
31
38
  wrapBlockQuote: wrapBlockQuote,
39
+ clearFormatting: clearFormatting,
32
40
  shouldUseDefaultRole: FloatingToolbarSettings.shouldUseDefaultRole,
33
41
  api: api
34
42
  });
@@ -23,12 +23,20 @@ export function PrimaryToolbarComponent({
23
23
  var _api$core2, _api$blockType2, _api$blockType2$comma;
24
24
  return api === null || api === void 0 ? void 0 : (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions.execute(api === null || api === void 0 ? void 0 : (_api$blockType2 = api.blockType) === null || _api$blockType2 === void 0 ? void 0 : (_api$blockType2$comma = _api$blockType2.commands) === null || _api$blockType2$comma === void 0 ? void 0 : _api$blockType2$comma.insertBlockQuote(INPUT_METHOD.TOOLBAR));
25
25
  };
26
+ const clearFormatting = () => {
27
+ var _api$core3, _api$blockType3, _api$blockType3$comma;
28
+ return api === null || api === void 0 ? void 0 : (_api$core3 = api.core) === null || _api$core3 === void 0 ? void 0 : _api$core3.actions.execute(api === null || api === void 0 ? void 0 : (_api$blockType3 = api.blockType) === null || _api$blockType3 === void 0 ? void 0 : (_api$blockType3$comma = _api$blockType3.commands) === null || _api$blockType3$comma === void 0 ? void 0 : _api$blockType3$comma.clearFormatting());
29
+ };
26
30
  return /*#__PURE__*/React.createElement(ToolbarBlockType, {
27
31
  isSmall: isSmall,
28
32
  isDisabled: disabled,
29
33
  isReducedSpacing: isToolbarReducedSpacing,
30
34
  setTextLevel: boundSetBlockType,
31
35
  wrapBlockQuote: wrapBlockQuote,
36
+ clearFormatting: clearFormatting
37
+ // Ignored via go/ees005
38
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
39
+ ,
32
40
  pluginState: blockTypeState,
33
41
  popupsMountPoint: popupsMountPoint,
34
42
  popupsBoundariesElement: popupsBoundariesElement,
@@ -63,5 +63,8 @@ export const BlockTypeButton = props => {
63
63
  }))))
64
64
  }, !props.isSmall && jsx(Box, {
65
65
  xcss: [buttonContentStyle, props.isReducedSpacing && buttonContentReducedSpacingStyle]
66
- }, jsx(FormattedMessage, props.title || NORMAL_TEXT.title)));
66
+ }, jsx(FormattedMessage
67
+ // Ignored via go/ees005
68
+ // eslint-disable-next-line react/jsx-props-no-spreading
69
+ , props.title || NORMAL_TEXT.title)));
67
70
  };