@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.
@@ -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 var isNodeAWrappingBlockNode = function isNodeAWrappingBlockNode(node) {
@@ -73,12 +74,19 @@ function getSelectedWrapperNodes(state) {
73
74
  * Function will check if changing block types: Paragraph, Heading is enabled.
74
75
  */
75
76
  export function areBlockTypesDisabled(state) {
77
+ var allowFontSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
76
78
  var nodesTypes = getSelectedWrapperNodes(state);
77
79
  var _state$schema$nodes2 = state.schema.nodes,
78
80
  panel = _state$schema$nodes2.panel,
79
81
  blockquote = _state$schema$nodes2.blockquote,
80
82
  bulletList = _state$schema$nodes2.bulletList,
81
- orderedList = _state$schema$nodes2.orderedList;
83
+ orderedList = _state$schema$nodes2.orderedList,
84
+ listItem = _state$schema$nodes2.listItem;
85
+
86
+ // When the small font size experiment is enabled, allow block type changes inside lists
87
+ // so that users can toggle between Normal text and Small text within list contexts.
88
+ // Note: taskList/taskItem are not excluded here until blockTaskItem conversion is implemented (WI 4).
89
+ var excludedTypes = allowFontSize && expValEquals('platform_editor_small_font_size', 'isEnabled', true) ? [panel, bulletList, orderedList, listItem] : [panel];
82
90
  if (editorExperiment('platform_editor_blockquote_in_text_formatting_menu', true)) {
83
91
  var hasQuote = false;
84
92
  var hasNestedListInQuote = false;
@@ -99,17 +107,44 @@ export function areBlockTypesDisabled(state) {
99
107
  return !hasNestedListInQuote;
100
108
  });
101
109
  return nodesTypes.filter(function (type) {
102
- return type !== panel;
110
+ return !excludedTypes.includes(type);
103
111
  }).length > 0 && (!hasQuote || hasNestedListInQuote);
104
112
  }
105
113
  return nodesTypes.filter(function (type) {
106
- return type !== panel;
114
+ return !excludedTypes.includes(type);
107
115
  }).length > 0;
108
116
  }
109
- var blockStylingIsPresent = function blockStylingIsPresent(state) {
117
+
118
+ /**
119
+ * Checks if the current selection is inside a list node (bulletList, orderedList, or taskList).
120
+ * Used to determine which text styles should be enabled when the small font size experiment is active.
121
+ */
122
+ export function isSelectionInsideListNode(state) {
123
+ if (!state.selection) {
124
+ return false;
125
+ }
110
126
  var _state$selection3 = state.selection,
111
- from = _state$selection3.from,
112
- to = _state$selection3.to;
127
+ $from = _state$selection3.$from,
128
+ $to = _state$selection3.$to;
129
+ var _state$schema$nodes3 = state.schema.nodes,
130
+ bulletList = _state$schema$nodes3.bulletList,
131
+ orderedList = _state$schema$nodes3.orderedList,
132
+ taskList = _state$schema$nodes3.taskList;
133
+ var listNodeTypes = [bulletList, orderedList, taskList];
134
+ var insideList = false;
135
+ state.doc.nodesBetween($from.pos, $to.pos, function (node) {
136
+ if (node.isBlock && listNodeTypes.indexOf(node.type) >= 0) {
137
+ insideList = true;
138
+ return false;
139
+ }
140
+ return true;
141
+ });
142
+ return insideList;
143
+ }
144
+ var blockStylingIsPresent = function blockStylingIsPresent(state) {
145
+ var _state$selection4 = state.selection,
146
+ from = _state$selection4.from,
147
+ to = _state$selection4.to;
113
148
  var isBlockStyling = false;
114
149
  state.doc.nodesBetween(from, to, function (node) {
115
150
  if (FORMATTING_NODE_TYPES.indexOf(node.type.name) !== -1) {
@@ -123,9 +158,9 @@ var blockStylingIsPresent = function blockStylingIsPresent(state) {
123
158
  var marksArePresent = function marksArePresent(state) {
124
159
  var activeMarkTypes = FORMATTING_MARK_TYPES.filter(function (mark) {
125
160
  if (!!state.schema.marks[mark]) {
126
- var _state$selection4 = state.selection,
127
- $from = _state$selection4.$from,
128
- empty = _state$selection4.empty;
161
+ var _state$selection5 = state.selection,
162
+ $from = _state$selection5.$from,
163
+ empty = _state$selection5.empty;
129
164
  var marks = state.schema.marks;
130
165
  if (empty) {
131
166
  return !!marks[mark].isInSet(state.storedMarks || $from.marks());
@@ -143,4 +178,40 @@ export var hasBlockQuoteInOptions = function hasBlockQuoteInOptions(dropdownOpti
143
178
  return !!dropdownOptions.find(function (blockType) {
144
179
  return blockType.name === 'blockquote';
145
180
  });
146
- };
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
+ var selection = tr.selection;
192
+ var _tr$doc$type$schema$n = tr.doc.type.schema.nodes,
193
+ bulletList = _tr$doc$type$schema$n.bulletList,
194
+ orderedList = _tr$doc$type$schema$n.orderedList,
195
+ taskList = _tr$doc$type$schema$n.taskList;
196
+ var listNodeTypes = [bulletList, orderedList, taskList];
197
+ var from = selection.from;
198
+ var to = selection.to;
199
+ for (var depth = selection.$from.depth; depth > 0; depth--) {
200
+ var node = selection.$from.node(depth);
201
+ if (listNodeTypes.indexOf(node.type) >= 0) {
202
+ from = selection.$from.before(depth);
203
+ break;
204
+ }
205
+ }
206
+ for (var _depth = selection.$to.depth; _depth > 0; _depth--) {
207
+ var _node = selection.$to.node(_depth);
208
+ if (listNodeTypes.indexOf(_node.type) >= 0) {
209
+ to = selection.$to.after(_depth);
210
+ break;
211
+ }
212
+ }
213
+ return {
214
+ from: from,
215
+ to: to
216
+ };
217
+ }
@@ -12,4 +12,4 @@ export type BlockTypeState = {
12
12
  formattingIsPresent?: boolean;
13
13
  };
14
14
  export declare const pluginKey: PluginKey<BlockTypeState>;
15
- export declare const createPlugin: (editorAPI: ExtractInjectionAPI<BlockTypePlugin> | undefined, dispatch: (eventName: string | PluginKey, data: any) => void, lastNodeMustBeParagraph?: boolean, includeBlockQuoteAsTextstyleOption?: boolean) => SafePlugin<BlockTypeState>;
15
+ export declare const createPlugin: (editorAPI: ExtractInjectionAPI<BlockTypePlugin> | undefined, dispatch: (eventName: string | PluginKey, data: any) => void, lastNodeMustBeParagraph?: boolean, includeBlockQuoteAsTextstyleOption?: boolean, allowFontSize?: boolean) => SafePlugin<BlockTypeState>;
@@ -1,6 +1,6 @@
1
1
  import type { InputRuleWrapper } from '@atlaskit/editor-common/types';
2
2
  import type { NodeType, Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
- import type { EditorState } from '@atlaskit/editor-prosemirror/state';
3
+ import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
4
4
  import type { BlockType } from './types';
5
5
  export declare const isNodeAWrappingBlockNode: (node?: PMNode | null) => boolean;
6
6
  export declare const createJoinNodesRule: (match: RegExp, nodeType: NodeType) => InputRuleWrapper;
@@ -13,7 +13,23 @@ export declare const createWrappingTextBlockRule: ({ match, nodeType, getAttrs,
13
13
  /**
14
14
  * Function will check if changing block types: Paragraph, Heading is enabled.
15
15
  */
16
- export declare function areBlockTypesDisabled(state: EditorState): boolean;
16
+ export declare function areBlockTypesDisabled(state: EditorState, allowFontSize?: boolean): boolean;
17
+ /**
18
+ * Checks if the current selection is inside a list node (bulletList, orderedList, or taskList).
19
+ * Used to determine which text styles should be enabled when the small font size experiment is active.
20
+ */
21
+ export declare function isSelectionInsideListNode(state: EditorState): boolean;
17
22
  export declare const checkFormattingIsPresent: (state: EditorState) => boolean;
18
23
  export declare const hasBlockQuoteInOptions: (dropdownOptions: BlockType[]) => boolean;
24
+ /**
25
+ * Returns a { from, to } range that extends the selection boundaries outward
26
+ * to include the entirety of any list nodes at either end. If the selection
27
+ * start is inside a list, `from` is pulled back to the list's start; if the
28
+ * selection end is inside a list, `to` is pushed forward to the list's end.
29
+ * Non-list content in the middle is included as-is.
30
+ */
31
+ export declare function getSelectionRangeExpandedToLists(tr: Transaction): {
32
+ from: number;
33
+ to: number;
34
+ };
19
35
  export {};
@@ -12,4 +12,4 @@ export type BlockTypeState = {
12
12
  formattingIsPresent?: boolean;
13
13
  };
14
14
  export declare const pluginKey: PluginKey<BlockTypeState>;
15
- export declare const createPlugin: (editorAPI: ExtractInjectionAPI<BlockTypePlugin> | undefined, dispatch: (eventName: string | PluginKey, data: any) => void, lastNodeMustBeParagraph?: boolean, includeBlockQuoteAsTextstyleOption?: boolean) => SafePlugin<BlockTypeState>;
15
+ export declare const createPlugin: (editorAPI: ExtractInjectionAPI<BlockTypePlugin> | undefined, dispatch: (eventName: string | PluginKey, data: any) => void, lastNodeMustBeParagraph?: boolean, includeBlockQuoteAsTextstyleOption?: boolean, allowFontSize?: boolean) => SafePlugin<BlockTypeState>;
@@ -1,6 +1,6 @@
1
1
  import type { InputRuleWrapper } from '@atlaskit/editor-common/types';
2
2
  import type { NodeType, Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
- import type { EditorState } from '@atlaskit/editor-prosemirror/state';
3
+ import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
4
4
  import type { BlockType } from './types';
5
5
  export declare const isNodeAWrappingBlockNode: (node?: PMNode | null) => boolean;
6
6
  export declare const createJoinNodesRule: (match: RegExp, nodeType: NodeType) => InputRuleWrapper;
@@ -13,7 +13,23 @@ export declare const createWrappingTextBlockRule: ({ match, nodeType, getAttrs,
13
13
  /**
14
14
  * Function will check if changing block types: Paragraph, Heading is enabled.
15
15
  */
16
- export declare function areBlockTypesDisabled(state: EditorState): boolean;
16
+ export declare function areBlockTypesDisabled(state: EditorState, allowFontSize?: boolean): boolean;
17
+ /**
18
+ * Checks if the current selection is inside a list node (bulletList, orderedList, or taskList).
19
+ * Used to determine which text styles should be enabled when the small font size experiment is active.
20
+ */
21
+ export declare function isSelectionInsideListNode(state: EditorState): boolean;
17
22
  export declare const checkFormattingIsPresent: (state: EditorState) => boolean;
18
23
  export declare const hasBlockQuoteInOptions: (dropdownOptions: BlockType[]) => boolean;
24
+ /**
25
+ * Returns a { from, to } range that extends the selection boundaries outward
26
+ * to include the entirety of any list nodes at either end. If the selection
27
+ * start is inside a list, `from` is pulled back to the list's start; if the
28
+ * selection end is inside a list, `to` is pushed forward to the list's end.
29
+ * Non-list content in the middle is included as-is.
30
+ */
31
+ export declare function getSelectionRangeExpandedToLists(tr: Transaction): {
32
+ from: number;
33
+ to: number;
34
+ };
19
35
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-type",
3
- "version": "12.1.2",
3
+ "version": "12.1.4",
4
4
  "description": "BlockType plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -50,14 +50,14 @@
50
50
  "@atlaskit/prosemirror-history": "^0.2.0",
51
51
  "@atlaskit/prosemirror-input-rules": "^3.6.0",
52
52
  "@atlaskit/theme": "^22.0.0",
53
- "@atlaskit/tmp-editor-statsig": "^40.3.0",
53
+ "@atlaskit/tmp-editor-statsig": "^41.0.0",
54
54
  "@atlaskit/tokens": "^11.1.0",
55
55
  "@babel/runtime": "^7.0.0",
56
56
  "@compiled/react": "^0.20.0",
57
57
  "@emotion/react": "^11.7.1"
58
58
  },
59
59
  "peerDependencies": {
60
- "@atlaskit/editor-common": "^112.5.0",
60
+ "@atlaskit/editor-common": "^112.6.0",
61
61
  "react": "^18.2.0",
62
62
  "react-dom": "^18.2.0",
63
63
  "react-intl-next": "npm:react-intl@^5.18.1"