@atlaskit/editor-plugin-block-controls 12.2.6 → 12.3.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 12.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`293a0d6eaab12`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/293a0d6eaab12) -
8
+ Fix Remix block menu item visibility to match Improve formatting
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies
13
+
3
14
  ## 12.2.6
4
15
 
5
16
  ### Patch Changes
@@ -39,6 +39,22 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
39
39
  return {
40
40
  name: 'blockControls',
41
41
  actions: {
42
+ getTextLength: function getTextLength(editorView) {
43
+ var _api$blockControls, _blockControlsState$m;
44
+ var blockControlsState = api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState();
45
+ var preservedSelection = blockControlsState === null || blockControlsState === void 0 ? void 0 : blockControlsState.preservedSelection;
46
+ if (preservedSelection && preservedSelection.from !== preservedSelection.to) {
47
+ var from = preservedSelection.from,
48
+ to = preservedSelection.to;
49
+ return editorView.state.doc.textBetween(from, to, '\n').length;
50
+ }
51
+ var pos = blockControlsState === null || blockControlsState === void 0 || (_blockControlsState$m = blockControlsState.menuTriggerByNode) === null || _blockControlsState$m === void 0 ? void 0 : _blockControlsState$m.pos;
52
+ if (pos === null || pos === undefined) {
53
+ return null;
54
+ }
55
+ var node = editorView.state.doc.nodeAt(pos);
56
+ return node ? node.textContent.length : null;
57
+ },
42
58
  registerNodeDecoration: function registerNodeDecoration(factory) {
43
59
  nodeDecorationRegistry.push(factory);
44
60
  },
@@ -125,14 +141,14 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
125
141
  },
126
142
  toggleBlockMenu: function toggleBlockMenu(options) {
127
143
  return function (_ref6) {
128
- var _api$userIntent, _api$blockControls, _options$anchorName, _api$blockControls2;
144
+ var _api$userIntent, _api$blockControls2, _options$anchorName, _api$blockControls3;
129
145
  var tr = _ref6.tr;
130
146
  if (!(0, _experiments.editorExperiment)('platform_editor_block_menu', true)) {
131
147
  return tr;
132
148
  }
133
149
  var currMeta = tr.getMeta(_main.key);
134
150
  var currentUserIntent = api === null || api === void 0 || (_api$userIntent = api.userIntent) === null || _api$userIntent === void 0 || (_api$userIntent = _api$userIntent.sharedState.currentState()) === null || _api$userIntent === void 0 ? void 0 : _api$userIntent.currentUserIntent;
135
- var isMenuCurrentlyOpen = api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || (_api$blockControls = _api$blockControls.sharedState.currentState()) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.isMenuOpen;
151
+ var isMenuCurrentlyOpen = api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.sharedState.currentState()) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.isMenuOpen;
136
152
  if (options !== null && options !== void 0 && options.closeMenu) {
137
153
  tr.setMeta(_main.key, _objectSpread(_objectSpread({}, currMeta), {}, {
138
154
  closeMenu: true
@@ -179,7 +195,7 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
179
195
  anchorName: options === null || options === void 0 ? void 0 : options.anchorName,
180
196
  triggerByNode: options === null || options === void 0 ? void 0 : options.triggerByNode
181
197
  };
182
- var menuTriggerBy = api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.sharedState.currentState()) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.menuTriggerBy;
198
+ var menuTriggerBy = api === null || api === void 0 || (_api$blockControls3 = api.blockControls) === null || _api$blockControls3 === void 0 || (_api$blockControls3 = _api$blockControls3.sharedState.currentState()) === null || _api$blockControls3 === void 0 ? void 0 : _api$blockControls3.menuTriggerBy;
183
199
  if (options !== null && options !== void 0 && options.anchorName) {
184
200
  var _canMoveNodeUpOrDown = (0, _moveNodeUtils.canMoveNodeUpOrDown)(tr),
185
201
  moveUp = _canMoveNodeUpOrDown.moveUp,
@@ -30,6 +30,24 @@ export const blockControlsPlugin = ({
30
30
  return {
31
31
  name: 'blockControls',
32
32
  actions: {
33
+ getTextLength: editorView => {
34
+ var _api$blockControls, _blockControlsState$m;
35
+ const blockControlsState = api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState();
36
+ const preservedSelection = blockControlsState === null || blockControlsState === void 0 ? void 0 : blockControlsState.preservedSelection;
37
+ if (preservedSelection && preservedSelection.from !== preservedSelection.to) {
38
+ const {
39
+ from,
40
+ to
41
+ } = preservedSelection;
42
+ return editorView.state.doc.textBetween(from, to, '\n').length;
43
+ }
44
+ const pos = blockControlsState === null || blockControlsState === void 0 ? void 0 : (_blockControlsState$m = blockControlsState.menuTriggerByNode) === null || _blockControlsState$m === void 0 ? void 0 : _blockControlsState$m.pos;
45
+ if (pos === null || pos === undefined) {
46
+ return null;
47
+ }
48
+ const node = editorView.state.doc.nodeAt(pos);
49
+ return node ? node.textContent.length : null;
50
+ },
33
51
  registerNodeDecoration: factory => {
34
52
  nodeDecorationRegistry.push(factory);
35
53
  },
@@ -112,13 +130,13 @@ export const blockControlsPlugin = ({
112
130
  toggleBlockMenu: options => ({
113
131
  tr
114
132
  }) => {
115
- var _api$userIntent, _api$userIntent$share, _api$blockControls, _api$blockControls$sh, _options$anchorName, _api$blockControls2, _api$blockControls2$s;
133
+ var _api$userIntent, _api$userIntent$share, _api$blockControls2, _api$blockControls2$s, _options$anchorName, _api$blockControls3, _api$blockControls3$s;
116
134
  if (!editorExperiment('platform_editor_block_menu', true)) {
117
135
  return tr;
118
136
  }
119
137
  const currMeta = tr.getMeta(key);
120
138
  const currentUserIntent = api === null || api === void 0 ? void 0 : (_api$userIntent = api.userIntent) === null || _api$userIntent === void 0 ? void 0 : (_api$userIntent$share = _api$userIntent.sharedState.currentState()) === null || _api$userIntent$share === void 0 ? void 0 : _api$userIntent$share.currentUserIntent;
121
- const isMenuCurrentlyOpen = api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : (_api$blockControls$sh = _api$blockControls.sharedState.currentState()) === null || _api$blockControls$sh === void 0 ? void 0 : _api$blockControls$sh.isMenuOpen;
139
+ const isMenuCurrentlyOpen = api === null || api === void 0 ? void 0 : (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 ? void 0 : (_api$blockControls2$s = _api$blockControls2.sharedState.currentState()) === null || _api$blockControls2$s === void 0 ? void 0 : _api$blockControls2$s.isMenuOpen;
122
140
  if (options !== null && options !== void 0 && options.closeMenu) {
123
141
  tr.setMeta(key, {
124
142
  ...currMeta,
@@ -167,7 +185,7 @@ export const blockControlsPlugin = ({
167
185
  anchorName: options === null || options === void 0 ? void 0 : options.anchorName,
168
186
  triggerByNode: options === null || options === void 0 ? void 0 : options.triggerByNode
169
187
  };
170
- const menuTriggerBy = api === null || api === void 0 ? void 0 : (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 ? void 0 : (_api$blockControls2$s = _api$blockControls2.sharedState.currentState()) === null || _api$blockControls2$s === void 0 ? void 0 : _api$blockControls2$s.menuTriggerBy;
188
+ const menuTriggerBy = api === null || api === void 0 ? void 0 : (_api$blockControls3 = api.blockControls) === null || _api$blockControls3 === void 0 ? void 0 : (_api$blockControls3$s = _api$blockControls3.sharedState.currentState()) === null || _api$blockControls3$s === void 0 ? void 0 : _api$blockControls3$s.menuTriggerBy;
171
189
  if (options !== null && options !== void 0 && options.anchorName) {
172
190
  const {
173
191
  moveUp,
@@ -32,6 +32,22 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
32
32
  return {
33
33
  name: 'blockControls',
34
34
  actions: {
35
+ getTextLength: function getTextLength(editorView) {
36
+ var _api$blockControls, _blockControlsState$m;
37
+ var blockControlsState = api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState();
38
+ var preservedSelection = blockControlsState === null || blockControlsState === void 0 ? void 0 : blockControlsState.preservedSelection;
39
+ if (preservedSelection && preservedSelection.from !== preservedSelection.to) {
40
+ var from = preservedSelection.from,
41
+ to = preservedSelection.to;
42
+ return editorView.state.doc.textBetween(from, to, '\n').length;
43
+ }
44
+ var pos = blockControlsState === null || blockControlsState === void 0 || (_blockControlsState$m = blockControlsState.menuTriggerByNode) === null || _blockControlsState$m === void 0 ? void 0 : _blockControlsState$m.pos;
45
+ if (pos === null || pos === undefined) {
46
+ return null;
47
+ }
48
+ var node = editorView.state.doc.nodeAt(pos);
49
+ return node ? node.textContent.length : null;
50
+ },
35
51
  registerNodeDecoration: function registerNodeDecoration(factory) {
36
52
  nodeDecorationRegistry.push(factory);
37
53
  },
@@ -118,14 +134,14 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
118
134
  },
119
135
  toggleBlockMenu: function toggleBlockMenu(options) {
120
136
  return function (_ref6) {
121
- var _api$userIntent, _api$blockControls, _options$anchorName, _api$blockControls2;
137
+ var _api$userIntent, _api$blockControls2, _options$anchorName, _api$blockControls3;
122
138
  var tr = _ref6.tr;
123
139
  if (!editorExperiment('platform_editor_block_menu', true)) {
124
140
  return tr;
125
141
  }
126
142
  var currMeta = tr.getMeta(key);
127
143
  var currentUserIntent = api === null || api === void 0 || (_api$userIntent = api.userIntent) === null || _api$userIntent === void 0 || (_api$userIntent = _api$userIntent.sharedState.currentState()) === null || _api$userIntent === void 0 ? void 0 : _api$userIntent.currentUserIntent;
128
- var isMenuCurrentlyOpen = api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || (_api$blockControls = _api$blockControls.sharedState.currentState()) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.isMenuOpen;
144
+ var isMenuCurrentlyOpen = api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.sharedState.currentState()) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.isMenuOpen;
129
145
  if (options !== null && options !== void 0 && options.closeMenu) {
130
146
  tr.setMeta(key, _objectSpread(_objectSpread({}, currMeta), {}, {
131
147
  closeMenu: true
@@ -172,7 +188,7 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
172
188
  anchorName: options === null || options === void 0 ? void 0 : options.anchorName,
173
189
  triggerByNode: options === null || options === void 0 ? void 0 : options.triggerByNode
174
190
  };
175
- var menuTriggerBy = api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.sharedState.currentState()) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.menuTriggerBy;
191
+ var menuTriggerBy = api === null || api === void 0 || (_api$blockControls3 = api.blockControls) === null || _api$blockControls3 === void 0 || (_api$blockControls3 = _api$blockControls3.sharedState.currentState()) === null || _api$blockControls3 === void 0 ? void 0 : _api$blockControls3.menuTriggerBy;
176
192
  if (options !== null && options !== void 0 && options.anchorName) {
177
193
  var _canMoveNodeUpOrDown = canMoveNodeUpOrDown(tr),
178
194
  moveUp = _canMoveNodeUpOrDown.moveUp,
@@ -18,7 +18,7 @@ import type { UserIntentPlugin } from '@atlaskit/editor-plugin-user-intent';
18
18
  import type { WidthPlugin } from '@atlaskit/editor-plugin-width';
19
19
  import type { EditorState, Selection } from '@atlaskit/editor-prosemirror/state';
20
20
  import type { Mapping } from '@atlaskit/editor-prosemirror/transform';
21
- import type { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
21
+ import type { Decoration, DecorationSet, EditorView } from '@atlaskit/editor-prosemirror/view';
22
22
  export type ActiveNode = {
23
23
  anchorName: string;
24
24
  handleOptions?: HandleOptions;
@@ -161,6 +161,17 @@ export type BlockControlsPluginDependencies = [
161
161
  ];
162
162
  export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
163
163
  actions: {
164
+ /**
165
+ * Returns the text length of the block(s) that triggered the block menu.
166
+ *
167
+ * When a preserved (multi-block) selection exists the character count spans
168
+ * all selected blocks; otherwise the single node at `menuTriggerByNode.pos`
169
+ * is used.
170
+ *
171
+ * @param editorView – the current editor view.
172
+ * @returns The text length, or `null` when the context cannot be determined.
173
+ */
174
+ getTextLength: (editorView: EditorView) => number | null;
164
175
  registerNodeDecoration: (factory: NodeDecorationFactory) => void;
165
176
  unregisterNodeDecoration: (type: string) => void;
166
177
  };
@@ -18,7 +18,7 @@ import type { UserIntentPlugin } from '@atlaskit/editor-plugin-user-intent';
18
18
  import type { WidthPlugin } from '@atlaskit/editor-plugin-width';
19
19
  import type { EditorState, Selection } from '@atlaskit/editor-prosemirror/state';
20
20
  import type { Mapping } from '@atlaskit/editor-prosemirror/transform';
21
- import type { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
21
+ import type { Decoration, DecorationSet, EditorView } from '@atlaskit/editor-prosemirror/view';
22
22
  export type ActiveNode = {
23
23
  anchorName: string;
24
24
  handleOptions?: HandleOptions;
@@ -163,6 +163,17 @@ export type BlockControlsPluginDependencies = [
163
163
  ];
164
164
  export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
165
165
  actions: {
166
+ /**
167
+ * Returns the text length of the block(s) that triggered the block menu.
168
+ *
169
+ * When a preserved (multi-block) selection exists the character count spans
170
+ * all selected blocks; otherwise the single node at `menuTriggerByNode.pos`
171
+ * is used.
172
+ *
173
+ * @param editorView – the current editor view.
174
+ * @returns The text length, or `null` when the context cannot be determined.
175
+ */
176
+ getTextLength: (editorView: EditorView) => number | null;
166
177
  registerNodeDecoration: (factory: NodeDecorationFactory) => void;
167
178
  unregisterNodeDecoration: (type: string) => void;
168
179
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "12.2.6",
3
+ "version": "12.3.0",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -67,7 +67,7 @@
67
67
  "uuid": "^3.1.0"
68
68
  },
69
69
  "peerDependencies": {
70
- "@atlaskit/editor-common": "^115.8.0",
70
+ "@atlaskit/editor-common": "^115.10.0",
71
71
  "react": "^18.2.0",
72
72
  "react-dom": "^18.2.0",
73
73
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"