@atlaskit/editor-plugin-expand 6.2.1 → 6.2.2

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,13 @@
1
1
  # @atlaskit/editor-plugin-expand
2
2
 
3
+ ## 6.2.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`e20238ac820ca`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/e20238ac820ca) -
8
+ EDITOR-1711: Fix expand state not defaulting to true while inserting when using local ids.
9
+ - Updated dependencies
10
+
3
11
  ## 6.2.1
4
12
 
5
13
  ### Patch Changes
@@ -4,8 +4,9 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.updateExpandTitle = exports.toggleExpandWithMatch = exports.toggleExpandExpanded = exports.setSelectionInsideExpand = exports.insertExpandWithInputMethod = exports.insertExpand = exports.focusTitle = exports.focusIcon = exports.deleteExpandAtPos = exports.deleteExpand = exports.createExpandNode = void 0;
7
+ exports.wrapSelectionAndSetExpandedState = exports.updateExpandTitle = exports.toggleExpandWithMatch = exports.toggleExpandExpanded = exports.setSelectionInsideExpand = exports.insertExpandWithInputMethod = exports.insertExpand = exports.focusTitle = exports.focusIcon = exports.deleteExpandAtPos = exports.deleteExpand = exports.createExpandNode = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _v = _interopRequireDefault(require("uuid/v4"));
9
10
  var _steps = require("@atlaskit/adf-schema/steps");
10
11
  var _analytics = require("@atlaskit/editor-common/analytics");
11
12
  var _expand = require("@atlaskit/editor-common/expand");
@@ -16,6 +17,7 @@ var _utils = require("@atlaskit/editor-common/utils");
16
17
  var _state2 = require("@atlaskit/editor-prosemirror/state");
17
18
  var _utils2 = require("@atlaskit/editor-prosemirror/utils");
18
19
  var _utils3 = require("@atlaskit/editor-tables/utils");
20
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
19
21
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
20
22
  var _utils4 = require("../utils");
21
23
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
@@ -23,13 +25,19 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
23
25
  // Creates either an expand or a nestedExpand node based on the current selection
24
26
  var createExpandNode = exports.createExpandNode = function createExpandNode(state) {
25
27
  var setExpandedState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
28
+ var addLocalId = arguments.length > 2 ? arguments[2] : undefined;
26
29
  var _state$schema$nodes = state.schema.nodes,
27
30
  expand = _state$schema$nodes.expand,
28
- nestedExpand = _state$schema$nodes.nestedExpand;
31
+ nestedExpand = _state$schema$nodes.nestedExpand,
32
+ paragraph = _state$schema$nodes.paragraph;
29
33
  var isSelectionInTable = !!(0, _utils3.findTable)(state.selection);
30
34
  var isSelectionInExpand = (0, _utils4.isNestedInExpand)(state);
31
35
  var expandType = isSelectionInTable || isSelectionInExpand ? nestedExpand : expand;
32
- var expandNode = expandType.createAndFill({});
36
+ var expandNode = (0, _platformFeatureFlags.fg)('platform_editor_adf_with_localid') ? expandType.createAndFill(addLocalId ? {
37
+ localId: (0, _v.default)()
38
+ } : {}, paragraph.createAndFill(addLocalId ? {
39
+ localId: (0, _v.default)()
40
+ } : {})) : expandType.createAndFill({});
33
41
  if (setExpandedState) {
34
42
  // Ignored via go/ees005
35
43
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -37,24 +45,41 @@ var createExpandNode = exports.createExpandNode = function createExpandNode(stat
37
45
  }
38
46
  return expandNode;
39
47
  };
40
- var insertExpandWithInputMethod = exports.insertExpandWithInputMethod = function insertExpandWithInputMethod(editorAnalyticsAPI) {
48
+
49
+ /**
50
+ * When cleaning up platform_editor_adf_with_localid we can reuse this function
51
+ * in insertExpandWithInputMethod.
52
+ */
53
+ var wrapSelectionAndSetExpandedState = exports.wrapSelectionAndSetExpandedState = function wrapSelectionAndSetExpandedState(state, node) {
54
+ var tr = (0, _utils.createWrapSelectionTransaction)({
55
+ state: state,
56
+ type: node.type,
57
+ nodeAttributes: node.attrs
58
+ });
59
+ var wrapperNode = (0, _utils2.findParentNodeOfType)(node.type)(tr.selection);
60
+ if (wrapperNode) {
61
+ _expand.expandedState.set(wrapperNode.node, true);
62
+ }
63
+ return tr;
64
+ };
65
+ var insertExpandWithInputMethod = exports.insertExpandWithInputMethod = function insertExpandWithInputMethod(api) {
41
66
  return function (inputMethod) {
42
67
  return function (state, dispatch) {
43
- var expandNode = createExpandNode(state, false);
68
+ var expandNode = createExpandNode(state, false, !!(api !== null && api !== void 0 && api.localId));
44
69
  if (!expandNode) {
45
70
  return false;
46
71
  }
47
72
  var tr;
48
73
  if (state.selection.empty) {
49
74
  tr = (0, _utils2.safeInsert)(expandNode)(state.tr).scrollIntoView();
50
- // Ignored via go/ees005
51
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
52
75
  _expand.expandedState.set(expandNode, true);
53
76
  } else {
54
- tr = (0, _utils.createWrapSelectionTransaction)({
77
+ tr = (0, _utils.createWrapSelectionTransaction)(_objectSpread({
55
78
  state: state,
56
79
  type: expandNode.type
57
- });
80
+ }, (0, _platformFeatureFlags.fg)('platform_editor_adf_with_localid') && {
81
+ nodeAttributes: expandNode.attrs
82
+ }));
58
83
  var wrapperNode = (0, _utils2.findParentNodeOfType)(expandNode.type)(tr.selection);
59
84
  if (wrapperNode) {
60
85
  _expand.expandedState.set(wrapperNode.node, true);
@@ -69,17 +94,18 @@ var insertExpandWithInputMethod = exports.insertExpandWithInputMethod = function
69
94
  },
70
95
  eventType: _analytics.EVENT_TYPE.TRACK
71
96
  };
72
- if (dispatch && expandNode) {
73
- editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(payload)(tr);
97
+ if (dispatch) {
98
+ var _api$analytics;
99
+ api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || (_api$analytics = _api$analytics.actions) === null || _api$analytics === void 0 || _api$analytics.attachAnalyticsEvent(payload)(tr);
74
100
  dispatch(tr);
75
101
  }
76
102
  return true;
77
103
  };
78
104
  };
79
105
  };
80
- var insertExpand = exports.insertExpand = function insertExpand(editorAnalyticsAPI) {
106
+ var insertExpand = exports.insertExpand = function insertExpand(api) {
81
107
  return function (state, dispatch) {
82
- return insertExpandWithInputMethod(editorAnalyticsAPI)(_analytics.INPUT_METHOD.INSERT_MENU)(state, dispatch);
108
+ return insertExpandWithInputMethod(api)(_analytics.INPUT_METHOD.INSERT_MENU)(state, dispatch);
83
109
  };
84
110
  };
85
111
  var deleteExpand = exports.deleteExpand = function deleteExpand(editorAnalyticsAPI) {
@@ -22,7 +22,6 @@ var _toolbar = require("./toolbar");
22
22
  // Ignored via go/ees005
23
23
  // eslint-disable-next-line prefer-const
24
24
  var expandPlugin = exports.expandPlugin = function expandPlugin(_ref) {
25
- var _api$analytics, _api$analytics2;
26
25
  var _ref$config = _ref.config,
27
26
  options = _ref$config === void 0 ? {} : _ref$config,
28
27
  api = _ref.api;
@@ -51,8 +50,8 @@ var expandPlugin = exports.expandPlugin = function expandPlugin(_ref) {
51
50
  }];
52
51
  },
53
52
  actions: {
54
- insertExpand: (0, _commands.insertExpand)(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions),
55
- insertExpandWithInputMethod: (0, _commands.insertExpandWithInputMethod)(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
53
+ insertExpand: (0, _commands.insertExpand)(api),
54
+ insertExpandWithInputMethod: (0, _commands.insertExpandWithInputMethod)(api)
56
55
  },
57
56
  commands: {
58
57
  toggleExpandWithMatch: function toggleExpandWithMatch(selection) {
@@ -95,16 +94,16 @@ var expandPlugin = exports.expandPlugin = function expandPlugin(_ref) {
95
94
  return /*#__PURE__*/_react.default.createElement(_quickInsert.IconExpand, null);
96
95
  },
97
96
  action: function action(insert, state) {
98
- var _api$analytics3;
99
- var node = (0, _commands.createExpandNode)(state, undefined);
97
+ var _api$analytics;
98
+ var node = (0, _commands.createExpandNode)(state, undefined, !!(api !== null && api !== void 0 && api.localId));
100
99
  if (!node) {
101
100
  return false;
102
101
  }
103
- var tr = state.selection.empty ? insert(node) : (0, _utils.createWrapSelectionTransaction)({
102
+ var tr = state.selection.empty ? insert(node) : (0, _platformFeatureFlags.fg)('platform_editor_adf_with_localid') ? (0, _commands.wrapSelectionAndSetExpandedState)(state, node) : (0, _utils.createWrapSelectionTransaction)({
104
103
  state: state,
105
104
  type: node.type
106
105
  });
107
- api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 || _api$analytics3.actions.attachAnalyticsEvent({
106
+ api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
108
107
  action: _analytics.ACTION.INSERTED,
109
108
  actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
110
109
  actionSubjectId: node.type === state.schema.nodes.nestedExpand ? _analytics.ACTION_SUBJECT_ID.NESTED_EXPAND : _analytics.ACTION_SUBJECT_ID.EXPAND,
@@ -1,3 +1,4 @@
1
+ import uuid from 'uuid/v4';
1
2
  import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
2
3
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD, MODE, PLATFORMS } from '@atlaskit/editor-common/analytics';
3
4
  import { expandedState } from '@atlaskit/editor-common/expand';
@@ -8,19 +9,25 @@ import { createWrapSelectionTransaction } from '@atlaskit/editor-common/utils';
8
9
  import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
9
10
  import { findParentNodeOfType, safeInsert } from '@atlaskit/editor-prosemirror/utils';
10
11
  import { findTable } from '@atlaskit/editor-tables/utils';
12
+ import { fg } from '@atlaskit/platform-feature-flags';
11
13
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
12
14
  import { isNestedInExpand } from '../utils';
13
15
 
14
16
  // Creates either an expand or a nestedExpand node based on the current selection
15
- export const createExpandNode = (state, setExpandedState = true) => {
17
+ export const createExpandNode = (state, setExpandedState = true, addLocalId) => {
16
18
  const {
17
19
  expand,
18
- nestedExpand
20
+ nestedExpand,
21
+ paragraph
19
22
  } = state.schema.nodes;
20
23
  const isSelectionInTable = !!findTable(state.selection);
21
24
  const isSelectionInExpand = isNestedInExpand(state);
22
25
  const expandType = isSelectionInTable || isSelectionInExpand ? nestedExpand : expand;
23
- const expandNode = expandType.createAndFill({});
26
+ const expandNode = fg('platform_editor_adf_with_localid') ? expandType.createAndFill(addLocalId ? {
27
+ localId: uuid()
28
+ } : {}, paragraph.createAndFill(addLocalId ? {
29
+ localId: uuid()
30
+ } : {})) : expandType.createAndFill({});
24
31
  if (setExpandedState) {
25
32
  // Ignored via go/ees005
26
33
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -28,21 +35,39 @@ export const createExpandNode = (state, setExpandedState = true) => {
28
35
  }
29
36
  return expandNode;
30
37
  };
31
- export const insertExpandWithInputMethod = editorAnalyticsAPI => inputMethod => (state, dispatch) => {
32
- const expandNode = createExpandNode(state, false);
38
+
39
+ /**
40
+ * When cleaning up platform_editor_adf_with_localid we can reuse this function
41
+ * in insertExpandWithInputMethod.
42
+ */
43
+ export const wrapSelectionAndSetExpandedState = (state, node) => {
44
+ const tr = createWrapSelectionTransaction({
45
+ state,
46
+ type: node.type,
47
+ nodeAttributes: node.attrs
48
+ });
49
+ const wrapperNode = findParentNodeOfType(node.type)(tr.selection);
50
+ if (wrapperNode) {
51
+ expandedState.set(wrapperNode.node, true);
52
+ }
53
+ return tr;
54
+ };
55
+ export const insertExpandWithInputMethod = api => inputMethod => (state, dispatch) => {
56
+ const expandNode = createExpandNode(state, false, !!(api !== null && api !== void 0 && api.localId));
33
57
  if (!expandNode) {
34
58
  return false;
35
59
  }
36
60
  let tr;
37
61
  if (state.selection.empty) {
38
62
  tr = safeInsert(expandNode)(state.tr).scrollIntoView();
39
- // Ignored via go/ees005
40
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
41
63
  expandedState.set(expandNode, true);
42
64
  } else {
43
65
  tr = createWrapSelectionTransaction({
44
66
  state,
45
- type: expandNode.type
67
+ type: expandNode.type,
68
+ ...(fg('platform_editor_adf_with_localid') && {
69
+ nodeAttributes: expandNode.attrs
70
+ })
46
71
  });
47
72
  const wrapperNode = findParentNodeOfType(expandNode.type)(tr.selection);
48
73
  if (wrapperNode) {
@@ -58,14 +83,15 @@ export const insertExpandWithInputMethod = editorAnalyticsAPI => inputMethod =>
58
83
  },
59
84
  eventType: EVENT_TYPE.TRACK
60
85
  };
61
- if (dispatch && expandNode) {
62
- editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent(payload)(tr);
86
+ if (dispatch) {
87
+ var _api$analytics, _api$analytics$action;
88
+ api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : (_api$analytics$action = _api$analytics.actions) === null || _api$analytics$action === void 0 ? void 0 : _api$analytics$action.attachAnalyticsEvent(payload)(tr);
63
89
  dispatch(tr);
64
90
  }
65
91
  return true;
66
92
  };
67
- export const insertExpand = editorAnalyticsAPI => (state, dispatch) => {
68
- return insertExpandWithInputMethod(editorAnalyticsAPI)(INPUT_METHOD.INSERT_MENU)(state, dispatch);
93
+ export const insertExpand = api => (state, dispatch) => {
94
+ return insertExpandWithInputMethod(api)(INPUT_METHOD.INSERT_MENU)(state, dispatch);
69
95
  };
70
96
  export const deleteExpand = editorAnalyticsAPI => (state, dispatch) => {
71
97
  const expandNode = findExpand(state);
@@ -8,7 +8,7 @@ import { createWrapSelectionTransaction } from '@atlaskit/editor-common/utils';
8
8
  import { fg } from '@atlaskit/platform-feature-flags';
9
9
  import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
10
10
  import { createExpandBlockMenuItem } from '../ui/ExpandBlockMenuItem';
11
- import { createExpandNode, insertExpand, insertExpandWithInputMethod, toggleExpandWithMatch } from './commands';
11
+ import { createExpandNode, insertExpand, insertExpandWithInputMethod, toggleExpandWithMatch, wrapSelectionAndSetExpandedState } from './commands';
12
12
  import { expandKeymap } from './pm-plugins/keymap';
13
13
  import { createPlugin } from './pm-plugins/main';
14
14
  import { getToolbarConfig } from './toolbar';
@@ -19,7 +19,6 @@ export let expandPlugin = ({
19
19
  config: options = {},
20
20
  api
21
21
  }) => {
22
- var _api$analytics, _api$analytics2;
23
22
  if (expValEqualsNoExposure('platform_editor_block_menu', 'isEnabled', true)) {
24
23
  var _api$blockMenu;
25
24
  api === null || api === void 0 ? void 0 : (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.actions.registerBlockMenuComponents([{
@@ -45,8 +44,8 @@ export let expandPlugin = ({
45
44
  }];
46
45
  },
47
46
  actions: {
48
- insertExpand: insertExpand(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions),
49
- insertExpandWithInputMethod: insertExpandWithInputMethod(api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
47
+ insertExpand: insertExpand(api),
48
+ insertExpandWithInputMethod: insertExpandWithInputMethod(api)
50
49
  },
51
50
  commands: {
52
51
  toggleExpandWithMatch: selection => toggleExpandWithMatch(selection)
@@ -85,16 +84,16 @@ export let expandPlugin = ({
85
84
  priority: 600,
86
85
  icon: () => /*#__PURE__*/React.createElement(IconExpand, null),
87
86
  action(insert, state) {
88
- var _api$analytics3;
89
- const node = createExpandNode(state, undefined);
87
+ var _api$analytics;
88
+ const node = createExpandNode(state, undefined, !!(api !== null && api !== void 0 && api.localId));
90
89
  if (!node) {
91
90
  return false;
92
91
  }
93
- const tr = state.selection.empty ? insert(node) : createWrapSelectionTransaction({
92
+ const tr = state.selection.empty ? insert(node) : fg('platform_editor_adf_with_localid') ? wrapSelectionAndSetExpandedState(state, node) : createWrapSelectionTransaction({
94
93
  state,
95
94
  type: node.type
96
95
  });
97
- api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions.attachAnalyticsEvent({
96
+ api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.attachAnalyticsEvent({
98
97
  action: ACTION.INSERTED,
99
98
  actionSubject: ACTION_SUBJECT.DOCUMENT,
100
99
  actionSubjectId: node.type === state.schema.nodes.nestedExpand ? ACTION_SUBJECT_ID.NESTED_EXPAND : ACTION_SUBJECT_ID.EXPAND,
@@ -1,6 +1,7 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
3
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ import uuid from 'uuid/v4';
4
5
  import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
5
6
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD, MODE, PLATFORMS } from '@atlaskit/editor-common/analytics';
6
7
  import { expandedState } from '@atlaskit/editor-common/expand';
@@ -11,19 +12,26 @@ import { createWrapSelectionTransaction } from '@atlaskit/editor-common/utils';
11
12
  import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
12
13
  import { findParentNodeOfType, safeInsert } from '@atlaskit/editor-prosemirror/utils';
13
14
  import { findTable } from '@atlaskit/editor-tables/utils';
15
+ import { fg } from '@atlaskit/platform-feature-flags';
14
16
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
15
17
  import { isNestedInExpand } from '../utils';
16
18
 
17
19
  // Creates either an expand or a nestedExpand node based on the current selection
18
20
  export var createExpandNode = function createExpandNode(state) {
19
21
  var setExpandedState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
22
+ var addLocalId = arguments.length > 2 ? arguments[2] : undefined;
20
23
  var _state$schema$nodes = state.schema.nodes,
21
24
  expand = _state$schema$nodes.expand,
22
- nestedExpand = _state$schema$nodes.nestedExpand;
25
+ nestedExpand = _state$schema$nodes.nestedExpand,
26
+ paragraph = _state$schema$nodes.paragraph;
23
27
  var isSelectionInTable = !!findTable(state.selection);
24
28
  var isSelectionInExpand = isNestedInExpand(state);
25
29
  var expandType = isSelectionInTable || isSelectionInExpand ? nestedExpand : expand;
26
- var expandNode = expandType.createAndFill({});
30
+ var expandNode = fg('platform_editor_adf_with_localid') ? expandType.createAndFill(addLocalId ? {
31
+ localId: uuid()
32
+ } : {}, paragraph.createAndFill(addLocalId ? {
33
+ localId: uuid()
34
+ } : {})) : expandType.createAndFill({});
27
35
  if (setExpandedState) {
28
36
  // Ignored via go/ees005
29
37
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -31,24 +39,41 @@ export var createExpandNode = function createExpandNode(state) {
31
39
  }
32
40
  return expandNode;
33
41
  };
34
- export var insertExpandWithInputMethod = function insertExpandWithInputMethod(editorAnalyticsAPI) {
42
+
43
+ /**
44
+ * When cleaning up platform_editor_adf_with_localid we can reuse this function
45
+ * in insertExpandWithInputMethod.
46
+ */
47
+ export var wrapSelectionAndSetExpandedState = function wrapSelectionAndSetExpandedState(state, node) {
48
+ var tr = createWrapSelectionTransaction({
49
+ state: state,
50
+ type: node.type,
51
+ nodeAttributes: node.attrs
52
+ });
53
+ var wrapperNode = findParentNodeOfType(node.type)(tr.selection);
54
+ if (wrapperNode) {
55
+ expandedState.set(wrapperNode.node, true);
56
+ }
57
+ return tr;
58
+ };
59
+ export var insertExpandWithInputMethod = function insertExpandWithInputMethod(api) {
35
60
  return function (inputMethod) {
36
61
  return function (state, dispatch) {
37
- var expandNode = createExpandNode(state, false);
62
+ var expandNode = createExpandNode(state, false, !!(api !== null && api !== void 0 && api.localId));
38
63
  if (!expandNode) {
39
64
  return false;
40
65
  }
41
66
  var tr;
42
67
  if (state.selection.empty) {
43
68
  tr = safeInsert(expandNode)(state.tr).scrollIntoView();
44
- // Ignored via go/ees005
45
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
46
69
  expandedState.set(expandNode, true);
47
70
  } else {
48
- tr = createWrapSelectionTransaction({
71
+ tr = createWrapSelectionTransaction(_objectSpread({
49
72
  state: state,
50
73
  type: expandNode.type
51
- });
74
+ }, fg('platform_editor_adf_with_localid') && {
75
+ nodeAttributes: expandNode.attrs
76
+ }));
52
77
  var wrapperNode = findParentNodeOfType(expandNode.type)(tr.selection);
53
78
  if (wrapperNode) {
54
79
  expandedState.set(wrapperNode.node, true);
@@ -63,17 +88,18 @@ export var insertExpandWithInputMethod = function insertExpandWithInputMethod(ed
63
88
  },
64
89
  eventType: EVENT_TYPE.TRACK
65
90
  };
66
- if (dispatch && expandNode) {
67
- editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(payload)(tr);
91
+ if (dispatch) {
92
+ var _api$analytics;
93
+ api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || (_api$analytics = _api$analytics.actions) === null || _api$analytics === void 0 || _api$analytics.attachAnalyticsEvent(payload)(tr);
68
94
  dispatch(tr);
69
95
  }
70
96
  return true;
71
97
  };
72
98
  };
73
99
  };
74
- export var insertExpand = function insertExpand(editorAnalyticsAPI) {
100
+ export var insertExpand = function insertExpand(api) {
75
101
  return function (state, dispatch) {
76
- return insertExpandWithInputMethod(editorAnalyticsAPI)(INPUT_METHOD.INSERT_MENU)(state, dispatch);
102
+ return insertExpandWithInputMethod(api)(INPUT_METHOD.INSERT_MENU)(state, dispatch);
77
103
  };
78
104
  };
79
105
  export var deleteExpand = function deleteExpand(editorAnalyticsAPI) {
@@ -8,7 +8,7 @@ import { createWrapSelectionTransaction } from '@atlaskit/editor-common/utils';
8
8
  import { fg } from '@atlaskit/platform-feature-flags';
9
9
  import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
10
10
  import { createExpandBlockMenuItem } from '../ui/ExpandBlockMenuItem';
11
- import { createExpandNode, insertExpand, insertExpandWithInputMethod, toggleExpandWithMatch as _toggleExpandWithMatch } from './commands';
11
+ import { createExpandNode, insertExpand, insertExpandWithInputMethod, toggleExpandWithMatch as _toggleExpandWithMatch, wrapSelectionAndSetExpandedState } from './commands';
12
12
  import { expandKeymap } from './pm-plugins/keymap';
13
13
  import { createPlugin } from './pm-plugins/main';
14
14
  import { getToolbarConfig } from './toolbar';
@@ -16,7 +16,6 @@ import { getToolbarConfig } from './toolbar';
16
16
  // Ignored via go/ees005
17
17
  // eslint-disable-next-line prefer-const
18
18
  export var expandPlugin = function expandPlugin(_ref) {
19
- var _api$analytics, _api$analytics2;
20
19
  var _ref$config = _ref.config,
21
20
  options = _ref$config === void 0 ? {} : _ref$config,
22
21
  api = _ref.api;
@@ -45,8 +44,8 @@ export var expandPlugin = function expandPlugin(_ref) {
45
44
  }];
46
45
  },
47
46
  actions: {
48
- insertExpand: insertExpand(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions),
49
- insertExpandWithInputMethod: insertExpandWithInputMethod(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
47
+ insertExpand: insertExpand(api),
48
+ insertExpandWithInputMethod: insertExpandWithInputMethod(api)
50
49
  },
51
50
  commands: {
52
51
  toggleExpandWithMatch: function toggleExpandWithMatch(selection) {
@@ -89,16 +88,16 @@ export var expandPlugin = function expandPlugin(_ref) {
89
88
  return /*#__PURE__*/React.createElement(IconExpand, null);
90
89
  },
91
90
  action: function action(insert, state) {
92
- var _api$analytics3;
93
- var node = createExpandNode(state, undefined);
91
+ var _api$analytics;
92
+ var node = createExpandNode(state, undefined, !!(api !== null && api !== void 0 && api.localId));
94
93
  if (!node) {
95
94
  return false;
96
95
  }
97
- var tr = state.selection.empty ? insert(node) : createWrapSelectionTransaction({
96
+ var tr = state.selection.empty ? insert(node) : fg('platform_editor_adf_with_localid') ? wrapSelectionAndSetExpandedState(state, node) : createWrapSelectionTransaction({
98
97
  state: state,
99
98
  type: node.type
100
99
  });
101
- api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 || _api$analytics3.actions.attachAnalyticsEvent({
100
+ api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
102
101
  action: ACTION.INSERTED,
103
102
  actionSubject: ACTION_SUBJECT.DOCUMENT,
104
103
  actionSubjectId: node.type === state.schema.nodes.nestedExpand ? ACTION_SUBJECT_ID.NESTED_EXPAND : ACTION_SUBJECT_ID.EXPAND,
@@ -1,12 +1,18 @@
1
1
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
2
  import type { Command, EditorCommand } from '@atlaskit/editor-common/types';
3
+ import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
4
  import type { NodeType, Node as PMNode } from '@atlaskit/editor-prosemirror/model';
4
5
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
5
6
  import { Selection } from '@atlaskit/editor-prosemirror/state';
6
- import type { InsertMethod } from '../types';
7
- export declare const createExpandNode: (state: EditorState, setExpandedState?: boolean) => PMNode | null;
8
- export declare const insertExpandWithInputMethod: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (inputMethod: InsertMethod) => Command;
9
- export declare const insertExpand: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Command;
7
+ import type { ExpandPlugin, InsertMethod } from '../types';
8
+ export declare const createExpandNode: (state: EditorState, setExpandedState?: boolean, addLocalId?: boolean) => PMNode | null;
9
+ /**
10
+ * When cleaning up platform_editor_adf_with_localid we can reuse this function
11
+ * in insertExpandWithInputMethod.
12
+ */
13
+ export declare const wrapSelectionAndSetExpandedState: (state: EditorState, node: PMNode) => import("prosemirror-state").Transaction;
14
+ export declare const insertExpandWithInputMethod: (api: ExtractInjectionAPI<ExpandPlugin> | undefined) => (inputMethod: InsertMethod) => Command;
15
+ export declare const insertExpand: (api: ExtractInjectionAPI<ExpandPlugin> | undefined) => Command;
10
16
  export declare const deleteExpand: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Command;
11
17
  export declare const deleteExpandAtPos: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (expandNodePos: number, expandNode: PMNode) => Command;
12
18
  export declare const setSelectionInsideExpand: (expandPos: number) => Command;
@@ -6,6 +6,7 @@ import type { DecorationsPlugin } from '@atlaskit/editor-plugin-decorations';
6
6
  import type { EditorDisabledPlugin } from '@atlaskit/editor-plugin-editor-disabled';
7
7
  import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode';
8
8
  import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
9
+ import type { LocalIdPlugin } from '@atlaskit/editor-plugin-local-id';
9
10
  import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
10
11
  import type { SelectionMarkerPlugin } from '@atlaskit/editor-plugin-selection-marker';
11
12
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
@@ -48,7 +49,8 @@ export type ExpandPluginDependencies = [
48
49
  OptionalPlugin<EditorDisabledPlugin>,
49
50
  OptionalPlugin<FeatureFlagsPlugin>,
50
51
  OptionalPlugin<EditorViewModePlugin>,
51
- OptionalPlugin<BlockMenuPlugin>
52
+ OptionalPlugin<BlockMenuPlugin>,
53
+ OptionalPlugin<LocalIdPlugin>
52
54
  ];
53
55
  export type ExpandPlugin = NextEditorPlugin<'expand', {
54
56
  actions: {
@@ -1,12 +1,18 @@
1
1
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
2
  import type { Command, EditorCommand } from '@atlaskit/editor-common/types';
3
+ import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
4
  import type { NodeType, Node as PMNode } from '@atlaskit/editor-prosemirror/model';
4
5
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
5
6
  import { Selection } from '@atlaskit/editor-prosemirror/state';
6
- import type { InsertMethod } from '../types';
7
- export declare const createExpandNode: (state: EditorState, setExpandedState?: boolean) => PMNode | null;
8
- export declare const insertExpandWithInputMethod: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (inputMethod: InsertMethod) => Command;
9
- export declare const insertExpand: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Command;
7
+ import type { ExpandPlugin, InsertMethod } from '../types';
8
+ export declare const createExpandNode: (state: EditorState, setExpandedState?: boolean, addLocalId?: boolean) => PMNode | null;
9
+ /**
10
+ * When cleaning up platform_editor_adf_with_localid we can reuse this function
11
+ * in insertExpandWithInputMethod.
12
+ */
13
+ export declare const wrapSelectionAndSetExpandedState: (state: EditorState, node: PMNode) => import("prosemirror-state").Transaction;
14
+ export declare const insertExpandWithInputMethod: (api: ExtractInjectionAPI<ExpandPlugin> | undefined) => (inputMethod: InsertMethod) => Command;
15
+ export declare const insertExpand: (api: ExtractInjectionAPI<ExpandPlugin> | undefined) => Command;
10
16
  export declare const deleteExpand: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Command;
11
17
  export declare const deleteExpandAtPos: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (expandNodePos: number, expandNode: PMNode) => Command;
12
18
  export declare const setSelectionInsideExpand: (expandPos: number) => Command;
@@ -6,6 +6,7 @@ import type { DecorationsPlugin } from '@atlaskit/editor-plugin-decorations';
6
6
  import type { EditorDisabledPlugin } from '@atlaskit/editor-plugin-editor-disabled';
7
7
  import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode';
8
8
  import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
9
+ import type { LocalIdPlugin } from '@atlaskit/editor-plugin-local-id';
9
10
  import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
10
11
  import type { SelectionMarkerPlugin } from '@atlaskit/editor-plugin-selection-marker';
11
12
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
@@ -48,7 +49,8 @@ export type ExpandPluginDependencies = [
48
49
  OptionalPlugin<EditorDisabledPlugin>,
49
50
  OptionalPlugin<FeatureFlagsPlugin>,
50
51
  OptionalPlugin<EditorViewModePlugin>,
51
- OptionalPlugin<BlockMenuPlugin>
52
+ OptionalPlugin<BlockMenuPlugin>,
53
+ OptionalPlugin<LocalIdPlugin>
52
54
  ];
53
55
  export type ExpandPlugin = NextEditorPlugin<'expand', {
54
56
  actions: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-expand",
3
- "version": "6.2.1",
3
+ "version": "6.2.2",
4
4
  "description": "Expand plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -32,20 +32,21 @@
32
32
  "@atlaskit/adf-schema": "^51.1.2",
33
33
  "@atlaskit/button": "^23.4.0",
34
34
  "@atlaskit/editor-plugin-analytics": "^5.2.0",
35
- "@atlaskit/editor-plugin-block-menu": "^3.1.0",
35
+ "@atlaskit/editor-plugin-block-menu": "^3.2.0",
36
36
  "@atlaskit/editor-plugin-decorations": "^5.0.0",
37
37
  "@atlaskit/editor-plugin-editor-disabled": "^5.0.0",
38
38
  "@atlaskit/editor-plugin-editor-viewmode": "^7.0.0",
39
+ "@atlaskit/editor-plugin-local-id": "^3.2.0",
39
40
  "@atlaskit/editor-plugin-selection": "^5.0.0",
40
41
  "@atlaskit/editor-plugin-selection-marker": "^5.0.0",
41
42
  "@atlaskit/editor-prosemirror": "7.0.0",
42
43
  "@atlaskit/editor-shared-styles": "^3.6.0",
43
44
  "@atlaskit/editor-tables": "^2.9.0",
44
45
  "@atlaskit/editor-toolbar": "^0.9.0",
45
- "@atlaskit/icon": "^28.1.0",
46
+ "@atlaskit/icon": "^28.2.0",
46
47
  "@atlaskit/icon-lab": "^5.7.0",
47
48
  "@atlaskit/platform-feature-flags": "^1.1.0",
48
- "@atlaskit/tmp-editor-statsig": "^12.21.0",
49
+ "@atlaskit/tmp-editor-statsig": "^12.26.0",
49
50
  "@atlaskit/tokens": "^6.3.0",
50
51
  "@atlaskit/tooltip": "^20.4.0",
51
52
  "@babel/runtime": "^7.0.0",
@@ -54,7 +55,7 @@
54
55
  "w3c-keyname": "^2.1.8"
55
56
  },
56
57
  "peerDependencies": {
57
- "@atlaskit/editor-common": "^109.6.0",
58
+ "@atlaskit/editor-common": "^109.11.0",
58
59
  "react": "^18.2.0",
59
60
  "react-dom": "^18.2.0",
60
61
  "react-intl-next": "npm:react-intl@^5.18.1"