@atlaskit/editor-plugin-block-menu 3.1.5 → 3.2.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,24 @@
1
1
  # @atlaskit/editor-plugin-block-menu
2
2
 
3
+ ## 3.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`b610a8281f843`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b610a8281f843) -
8
+ Fix double format options highlight for selection with blockQuotes
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies
13
+
14
+ ## 3.1.6
15
+
16
+ ### Patch Changes
17
+
18
+ - [`f1e12e7cf00ba`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/f1e12e7cf00ba) -
19
+ ED-29083: Fixed copying code block only copy texts
20
+ - Updated dependencies
21
+
3
22
  ## 3.1.5
4
23
 
5
24
  ### Patch Changes
@@ -40,6 +40,20 @@ var blockMenuPlugin = exports.blockMenuPlugin = function blockMenuPlugin(_ref) {
40
40
  return (0, _formatNode2.formatNode)(targetType);
41
41
  }
42
42
  },
43
+ getSharedState: function getSharedState(editorState) {
44
+ var _api$blockControls;
45
+ if (!editorState) {
46
+ return {
47
+ currentSelectedNodeName: undefined
48
+ };
49
+ }
50
+
51
+ // Get the menuTriggerBy from blockControls plugin if available
52
+ var currentSelectedNodeName = 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.menuTriggerBy;
53
+ return {
54
+ currentSelectedNodeName: currentSelectedNodeName
55
+ };
56
+ },
43
57
  contentComponent: function contentComponent(_ref2) {
44
58
  var editorView = _ref2.editorView,
45
59
  popupsMountPoint = _ref2.popupsMountPoint,
@@ -33,7 +33,7 @@ var CopyBlockMenuItem = function CopyBlockMenuItem(_ref) {
33
33
  var schema = selection.$from.doc.type.schema;
34
34
  // for texts and inline nodes
35
35
  if (selection instanceof _state.TextSelection) {
36
- var _fragment;
36
+ var _fragment, _fragment2;
37
37
  var fragment = selection === null || selection === void 0 ? void 0 : selection.content().content;
38
38
  if (!fragment) {
39
39
  return;
@@ -46,6 +46,15 @@ var CopyBlockMenuItem = function CopyBlockMenuItem(_ref) {
46
46
  var layoutContent = layoutColumnNode === null || layoutColumnNode === void 0 ? void 0 : layoutColumnNode.firstChild;
47
47
  fragment = (layoutContent === null || layoutContent === void 0 ? void 0 : layoutContent.content) || _model.Fragment.empty;
48
48
  }
49
+
50
+ // if text is inside of an expand, the selection contains an expand for some reason
51
+ // the expandNode always and only have one child, no matter how much contents are inside the expand,
52
+ // and the one child is the line that is being selected, so we can use the .firstChild again
53
+ if ((_fragment2 = fragment) !== null && _fragment2 !== void 0 && _fragment2.firstChild && fragment.firstChild.type.name === 'expand') {
54
+ var expandNode = fragment.firstChild;
55
+ var actualNodeToCopy = expandNode.firstChild;
56
+ fragment = _model.Fragment.from(actualNodeToCopy) || _model.Fragment.empty;
57
+ }
49
58
  var domNode = toDOMFromFragment(fragment, schema);
50
59
  var div = document.createElement('div');
51
60
  div.appendChild(domNode);
@@ -66,6 +75,13 @@ var CopyBlockMenuItem = function CopyBlockMenuItem(_ref) {
66
75
  // for other nodes
67
76
  if (selection instanceof _state.NodeSelection) {
68
77
  var _nodeType = selection.node.type;
78
+
79
+ // code block is a special case where it is a block node but has inlineContent to true,
80
+ // When nodeType.inlineContent is true, it will be treated as an inline node in the copyDomNode function,
81
+ // but we want to treat it as a block node when copying, hence setting it to false here
82
+ if (selection.node.type.name === 'codeBlock') {
83
+ _nodeType.inlineContent = false;
84
+ }
69
85
  var _domNode2 = (0, _copyButton.toDOM)(selection.node, schema);
70
86
  (0, _copyButton.copyDomNode)(_domNode2, _nodeType, selection);
71
87
  }
@@ -34,6 +34,20 @@ export const blockMenuPlugin = ({
34
34
  return formatNode(targetType);
35
35
  }
36
36
  },
37
+ getSharedState(editorState) {
38
+ var _api$blockControls, _api$blockControls$sh;
39
+ if (!editorState) {
40
+ return {
41
+ currentSelectedNodeName: undefined
42
+ };
43
+ }
44
+
45
+ // Get the menuTriggerBy from blockControls plugin if available
46
+ const currentSelectedNodeName = 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.menuTriggerBy;
47
+ return {
48
+ currentSelectedNodeName
49
+ };
50
+ },
37
51
  contentComponent({
38
52
  editorView,
39
53
  popupsMountPoint,
@@ -28,7 +28,7 @@ const CopyBlockMenuItem = ({
28
28
  const schema = selection.$from.doc.type.schema;
29
29
  // for texts and inline nodes
30
30
  if (selection instanceof TextSelection) {
31
- var _fragment;
31
+ var _fragment, _fragment2;
32
32
  let fragment = selection === null || selection === void 0 ? void 0 : selection.content().content;
33
33
  if (!fragment) {
34
34
  return;
@@ -41,6 +41,15 @@ const CopyBlockMenuItem = ({
41
41
  const layoutContent = layoutColumnNode === null || layoutColumnNode === void 0 ? void 0 : layoutColumnNode.firstChild;
42
42
  fragment = (layoutContent === null || layoutContent === void 0 ? void 0 : layoutContent.content) || Fragment.empty;
43
43
  }
44
+
45
+ // if text is inside of an expand, the selection contains an expand for some reason
46
+ // the expandNode always and only have one child, no matter how much contents are inside the expand,
47
+ // and the one child is the line that is being selected, so we can use the .firstChild again
48
+ if ((_fragment2 = fragment) !== null && _fragment2 !== void 0 && _fragment2.firstChild && fragment.firstChild.type.name === 'expand') {
49
+ const expandNode = fragment.firstChild;
50
+ const actualNodeToCopy = expandNode.firstChild;
51
+ fragment = Fragment.from(actualNodeToCopy) || Fragment.empty;
52
+ }
44
53
  const domNode = toDOMFromFragment(fragment, schema);
45
54
  const div = document.createElement('div');
46
55
  div.appendChild(domNode);
@@ -61,6 +70,13 @@ const CopyBlockMenuItem = ({
61
70
  // for other nodes
62
71
  if (selection instanceof NodeSelection) {
63
72
  const nodeType = selection.node.type;
73
+
74
+ // code block is a special case where it is a block node but has inlineContent to true,
75
+ // When nodeType.inlineContent is true, it will be treated as an inline node in the copyDomNode function,
76
+ // but we want to treat it as a block node when copying, hence setting it to false here
77
+ if (selection.node.type.name === 'codeBlock') {
78
+ nodeType.inlineContent = false;
79
+ }
64
80
  const domNode = toDOM(selection.node, schema);
65
81
  copyDomNode(domNode, nodeType, selection);
66
82
  }
@@ -33,6 +33,20 @@ export var blockMenuPlugin = function blockMenuPlugin(_ref) {
33
33
  return _formatNode(targetType);
34
34
  }
35
35
  },
36
+ getSharedState: function getSharedState(editorState) {
37
+ var _api$blockControls;
38
+ if (!editorState) {
39
+ return {
40
+ currentSelectedNodeName: undefined
41
+ };
42
+ }
43
+
44
+ // Get the menuTriggerBy from blockControls plugin if available
45
+ var currentSelectedNodeName = 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.menuTriggerBy;
46
+ return {
47
+ currentSelectedNodeName: currentSelectedNodeName
48
+ };
49
+ },
36
50
  contentComponent: function contentComponent(_ref2) {
37
51
  var editorView = _ref2.editorView,
38
52
  popupsMountPoint = _ref2.popupsMountPoint,
@@ -26,7 +26,7 @@ var CopyBlockMenuItem = function CopyBlockMenuItem(_ref) {
26
26
  var schema = selection.$from.doc.type.schema;
27
27
  // for texts and inline nodes
28
28
  if (selection instanceof TextSelection) {
29
- var _fragment;
29
+ var _fragment, _fragment2;
30
30
  var fragment = selection === null || selection === void 0 ? void 0 : selection.content().content;
31
31
  if (!fragment) {
32
32
  return;
@@ -39,6 +39,15 @@ var CopyBlockMenuItem = function CopyBlockMenuItem(_ref) {
39
39
  var layoutContent = layoutColumnNode === null || layoutColumnNode === void 0 ? void 0 : layoutColumnNode.firstChild;
40
40
  fragment = (layoutContent === null || layoutContent === void 0 ? void 0 : layoutContent.content) || Fragment.empty;
41
41
  }
42
+
43
+ // if text is inside of an expand, the selection contains an expand for some reason
44
+ // the expandNode always and only have one child, no matter how much contents are inside the expand,
45
+ // and the one child is the line that is being selected, so we can use the .firstChild again
46
+ if ((_fragment2 = fragment) !== null && _fragment2 !== void 0 && _fragment2.firstChild && fragment.firstChild.type.name === 'expand') {
47
+ var expandNode = fragment.firstChild;
48
+ var actualNodeToCopy = expandNode.firstChild;
49
+ fragment = Fragment.from(actualNodeToCopy) || Fragment.empty;
50
+ }
42
51
  var domNode = toDOMFromFragment(fragment, schema);
43
52
  var div = document.createElement('div');
44
53
  div.appendChild(domNode);
@@ -59,6 +68,13 @@ var CopyBlockMenuItem = function CopyBlockMenuItem(_ref) {
59
68
  // for other nodes
60
69
  if (selection instanceof NodeSelection) {
61
70
  var _nodeType = selection.node.type;
71
+
72
+ // code block is a special case where it is a block node but has inlineContent to true,
73
+ // When nodeType.inlineContent is true, it will be treated as an inline node in the copyDomNode function,
74
+ // but we want to treat it as a block node when copying, hence setting it to false here
75
+ if (selection.node.type.name === 'codeBlock') {
76
+ _nodeType.inlineContent = false;
77
+ }
62
78
  var _domNode2 = toDOM(selection.node, schema);
63
79
  copyDomNode(_domNode2, _nodeType, selection);
64
80
  }
@@ -19,6 +19,7 @@ export type BlockMenuPlugin = NextEditorPlugin<'blockMenu', {
19
19
  OptionalPlugin<DecorationsPlugin>
20
20
  ];
21
21
  pluginConfiguration?: BlockMenuPluginOptions;
22
+ sharedState: BlockMenuSharedState;
22
23
  }>;
23
24
  export type BlockMenuPluginOptions = {
24
25
  /**
@@ -31,6 +32,13 @@ export type BlockMenuPluginOptions = {
31
32
  */
32
33
  getLinkPath?: () => string | null;
33
34
  };
35
+ export type BlockMenuSharedState = {
36
+ /**
37
+ * The name of the currently selected node type that triggered the block menu
38
+ * This exposes the menuTriggerBy value from blockControls plugin
39
+ */
40
+ currentSelectedNodeName: string | undefined;
41
+ } | undefined;
34
42
  type WithRank<T> = T & {
35
43
  rank: number;
36
44
  };
@@ -1,2 +1,2 @@
1
1
  export { blockMenuPlugin } from './blockMenuPlugin';
2
- export type { BlockMenuPlugin, RegisterBlockMenuComponent, Parent, BlockMenuPluginOptions, } from './blockMenuPluginType';
2
+ export type { BlockMenuPlugin, RegisterBlockMenuComponent, Parent, BlockMenuPluginOptions, BlockMenuSharedState, } from './blockMenuPluginType';
@@ -19,6 +19,7 @@ export type BlockMenuPlugin = NextEditorPlugin<'blockMenu', {
19
19
  OptionalPlugin<DecorationsPlugin>
20
20
  ];
21
21
  pluginConfiguration?: BlockMenuPluginOptions;
22
+ sharedState: BlockMenuSharedState;
22
23
  }>;
23
24
  export type BlockMenuPluginOptions = {
24
25
  /**
@@ -31,6 +32,13 @@ export type BlockMenuPluginOptions = {
31
32
  */
32
33
  getLinkPath?: () => string | null;
33
34
  };
35
+ export type BlockMenuSharedState = {
36
+ /**
37
+ * The name of the currently selected node type that triggered the block menu
38
+ * This exposes the menuTriggerBy value from blockControls plugin
39
+ */
40
+ currentSelectedNodeName: string | undefined;
41
+ } | undefined;
34
42
  type WithRank<T> = T & {
35
43
  rank: number;
36
44
  };
@@ -1,2 +1,2 @@
1
1
  export { blockMenuPlugin } from './blockMenuPlugin';
2
- export type { BlockMenuPlugin, RegisterBlockMenuComponent, Parent, BlockMenuPluginOptions, } from './blockMenuPluginType';
2
+ export type { BlockMenuPlugin, RegisterBlockMenuComponent, Parent, BlockMenuPluginOptions, BlockMenuSharedState, } from './blockMenuPluginType';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-menu",
3
- "version": "3.1.5",
3
+ "version": "3.2.0",
4
4
  "description": "BlockMenu plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -42,12 +42,12 @@
42
42
  "@atlaskit/icon-lab": "^5.7.0",
43
43
  "@atlaskit/platform-feature-flags": "^1.1.0",
44
44
  "@atlaskit/primitives": "^14.14.0",
45
- "@atlaskit/tmp-editor-statsig": "^12.22.0",
45
+ "@atlaskit/tmp-editor-statsig": "^12.25.0",
46
46
  "@atlaskit/tokens": "^6.3.0",
47
47
  "@babel/runtime": "^7.0.0"
48
48
  },
49
49
  "peerDependencies": {
50
- "@atlaskit/editor-common": "^109.7.0",
50
+ "@atlaskit/editor-common": "^109.10.0",
51
51
  "react": "^18.2.0",
52
52
  "react-intl-next": "npm:react-intl@^5.18.1"
53
53
  },