@atlaskit/editor-plugin-expand 4.0.0 → 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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @atlaskit/editor-plugin-expand
2
2
 
3
+ ## 4.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#179798](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/179798)
8
+ [`b74544d17393f`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b74544d17393f) -
9
+ [ux] [ED-27963] this change is creating a new Editor Command inside expandPlugin to toggle open
10
+ expands with active matches from Find&Replace
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies
15
+
16
+ ## 4.0.1
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies
21
+
3
22
  ## 4.0.0
4
23
 
5
24
  ### Major Changes
@@ -4,11 +4,11 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.updateExpandTitle = exports.toggleExpandExpanded = exports.setSelectionInsideExpand = exports.setExpandRef = exports.insertExpandWithInputMethod = exports.insertExpand = exports.focusTitle = exports.focusIcon = exports.deleteExpandAtPos = exports.deleteExpand = exports.createExpandNode = void 0;
7
+ exports.updateExpandTitle = exports.toggleExpandWithMatch = exports.toggleExpandExpanded = exports.setSelectionInsideExpand = exports.setExpandRef = 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
9
  var _steps = require("@atlaskit/adf-schema/steps");
10
10
  var _analytics = require("@atlaskit/editor-common/analytics");
11
- var _selection = require("@atlaskit/editor-common/selection");
11
+ var _selection2 = require("@atlaskit/editor-common/selection");
12
12
  var _styles = require("@atlaskit/editor-common/styles");
13
13
  var _transforms = require("@atlaskit/editor-common/transforms");
14
14
  var _utils = require("@atlaskit/editor-common/utils");
@@ -115,7 +115,7 @@ var toggleExpandExpanded = exports.toggleExpandExpanded = function toggleExpandE
115
115
  // Move to a right gap cursor, if the toolbar is interacted (or an API),
116
116
  // it will insert below rather than inside (which will be invisible).
117
117
  if (__livePage ? isExpandedNext === true : isExpandedNext === false && (0, _transforms.findExpand)(state)) {
118
- tr.setSelection(new _selection.GapCursorSelection(tr.doc.resolve(pos + node.nodeSize), _selection.Side.RIGHT));
118
+ tr.setSelection(new _selection2.GapCursorSelection(tr.doc.resolve(pos + node.nodeSize), _selection2.Side.RIGHT));
119
119
  }
120
120
 
121
121
  // log when people open/close expands
@@ -239,4 +239,13 @@ var setSelectionInsideExpand = exports.setSelectionInsideExpand = function setSe
239
239
  }
240
240
  return false;
241
241
  };
242
+ };
243
+ var toggleExpandWithMatch = exports.toggleExpandWithMatch = function toggleExpandWithMatch(_selection) {
244
+ return function (_ref3) {
245
+ var tr = _ref3.tr;
246
+ // this action exists so that we can keep the plugin types consistent across the
247
+ // the legacy expand plugin and the single player expand plugin until
248
+ // we will remove the legacy expand plugin
249
+ return null;
250
+ };
242
251
  };
@@ -37,6 +37,11 @@ var expandPlugin = exports.expandPlugin = function expandPlugin(_ref) {
37
37
  insertExpand: (0, _commands.insertExpand)(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions),
38
38
  insertExpandWithInputMethod: (0, _commands.insertExpandWithInputMethod)(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
39
39
  },
40
+ commands: {
41
+ toggleExpandWithMatch: function toggleExpandWithMatch(selection) {
42
+ return (0, _commands.toggleExpandWithMatch)(selection);
43
+ }
44
+ },
40
45
  pmPlugins: function pmPlugins() {
41
46
  return [{
42
47
  name: 'expand',
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.updateExpandTitle = exports.toggleExpandExpanded = exports.setSelectionInsideExpand = exports.insertExpandWithInputMethod = exports.insertExpand = exports.focusTitle = exports.focusIcon = exports.deleteExpandAtPos = exports.deleteExpand = exports.createExpandNode = void 0;
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;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _steps = require("@atlaskit/adf-schema/steps");
10
10
  var _analytics = require("@atlaskit/editor-common/analytics");
@@ -16,6 +16,7 @@ var _utils = require("@atlaskit/editor-common/utils");
16
16
  var _state2 = require("@atlaskit/editor-prosemirror/state");
17
17
  var _utils2 = require("@atlaskit/editor-prosemirror/utils");
18
18
  var _utils3 = require("@atlaskit/editor-tables/utils");
19
+ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
19
20
  var _utils4 = require("../utils");
20
21
  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; }
21
22
  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) { (0, _defineProperty2.default)(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; }
@@ -229,4 +230,31 @@ var focusIcon = exports.focusIcon = function focusIcon(expand) {
229
230
  }
230
231
  return false;
231
232
  };
233
+ };
234
+ var toggleExpandWithMatch = exports.toggleExpandWithMatch = function toggleExpandWithMatch(selection) {
235
+ return function (_ref3) {
236
+ var tr = _ref3.tr;
237
+ var _tr$doc$type$schema$n = tr.doc.type.schema.nodes,
238
+ expand = _tr$doc$type$schema$n.expand,
239
+ nestedExpand = _tr$doc$type$schema$n.nestedExpand;
240
+ // if match is inside a nested expand, open the nested expand
241
+ var nestedExpandNode = (0, _utils2.findParentNodeOfType)(nestedExpand)(selection);
242
+ if (nestedExpandNode && (0, _expValEquals.expValEquals)('platform_editor_toggle_expand_on_match_found', 'isEnabled', true)) {
243
+ var _expandedState$get2;
244
+ var expanded = (_expandedState$get2 = _expand.expandedState.get(nestedExpandNode.node)) !== null && _expandedState$get2 !== void 0 ? _expandedState$get2 : false;
245
+ if (!expanded) {
246
+ _expand.expandedState.set(nestedExpandNode.node, true);
247
+ }
248
+ }
249
+ // if match is (also) inside an expand, open the expand
250
+ var expandNode = (0, _utils2.findParentNodeOfType)(expand)(selection);
251
+ if (expandNode && (0, _expValEquals.expValEquals)('platform_editor_toggle_expand_on_match_found', 'isEnabled', true)) {
252
+ var _expandedState$get3;
253
+ var _expanded = (_expandedState$get3 = _expand.expandedState.get(expandNode.node)) !== null && _expandedState$get3 !== void 0 ? _expandedState$get3 : false;
254
+ if (!_expanded) {
255
+ _expand.expandedState.set(expandNode.node, true);
256
+ }
257
+ }
258
+ return tr;
259
+ };
232
260
  };
@@ -33,6 +33,7 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
33
33
  var allowInteractiveExpand = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : true;
34
34
  var __livePage = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : false;
35
35
  var cleanUpEditorDisabledOnChange = arguments.length > 10 ? arguments[10] : undefined;
36
+ var isExpanded = arguments.length > 11 && arguments[11] !== undefined ? arguments[11] : false;
36
37
  (0, _classCallCheck2.default)(this, ExpandNodeView);
37
38
  (0, _defineProperty2.default)(this, "allowInteractiveExpand", true);
38
39
  (0, _defineProperty2.default)(this, "isMobile", false);
@@ -393,6 +394,7 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
393
394
  this.selectNearNode = selectNearNode;
394
395
  this.__livePage = __livePage;
395
396
  this.cleanUpEditorDisabledOnChange = cleanUpEditorDisabledOnChange;
397
+ this.isExpanded = isExpanded;
396
398
  this.intl = getIntl();
397
399
  this.nodeViewPortalProviderAPI = nodeViewPortalProviderAPI;
398
400
  this.allowInteractiveExpand = allowInteractiveExpand;
@@ -495,9 +497,17 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
495
497
  _expand.expandedState.set(node, wasExpanded);
496
498
  }
497
499
  }
498
- this.node = node;
499
- if (!(0, _platformFeatureFlags.fg)('platform_editor_disable_unnecessary_expand_renders')) {
500
- this.updateExpandToggleIcon(this.node);
500
+ if ((0, _expValEquals.expValEquals)('platform_editor_toggle_expand_on_match_found', 'isEnabled', true)) {
501
+ this.node = node;
502
+ var hasChanged = this.isExpanded !== _expand.expandedState.get(node);
503
+ if (hasChanged) {
504
+ this.updateExpandToggleIcon(node);
505
+ }
506
+ } else {
507
+ this.node = node;
508
+ if (!(0, _platformFeatureFlags.fg)('platform_editor_disable_unnecessary_expand_renders')) {
509
+ this.updateExpandToggleIcon(this.node);
510
+ }
501
511
  }
502
512
  return true;
503
513
  }
@@ -523,6 +533,9 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
523
533
  this.renderIcon(this.icon ? this.icon : null, (_expandedState$get = _expand.expandedState.get(node)) !== null && _expandedState$get !== void 0 ? _expandedState$get : false);
524
534
  }
525
535
  this.updateExpandBodyContentEditable();
536
+ if ((0, _expValEquals.expValEquals)('platform_editor_toggle_expand_on_match_found', 'isEnabled', true)) {
537
+ this.isExpanded = expanded;
538
+ }
526
539
  }
527
540
  }, {
528
541
  key: "updateExpandBodyContentEditable",
@@ -37,6 +37,11 @@ var expandPlugin = exports.expandPlugin = function expandPlugin(_ref) {
37
37
  insertExpand: (0, _commands.insertExpand)(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions),
38
38
  insertExpandWithInputMethod: (0, _commands.insertExpandWithInputMethod)(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
39
39
  },
40
+ commands: {
41
+ toggleExpandWithMatch: function toggleExpandWithMatch(selection) {
42
+ return (0, _commands.toggleExpandWithMatch)(selection);
43
+ }
44
+ },
40
45
  pmPlugins: function pmPlugins() {
41
46
  return [{
42
47
  name: 'expand',
@@ -4,9 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.findReplaceExpandDecorations = exports.findParentExpandNode = void 0;
7
- var _styles = require("@atlaskit/editor-plugin-find-replace/styles");
8
7
  var _utils = require("@atlaskit/editor-prosemirror/utils");
8
+ // from platform/packages/editor/editor-plugin-find-replace/src/ui/styles.ts
9
+ var darkModeSearchMatchClass = 'search-match-dark';
10
+ var searchMatchExpandTitleClass = 'search-match-expand-title';
11
+ var selectedSearchMatchClass = 'selected-search-match';
9
12
  var findParentExpandNode = exports.findParentExpandNode = function findParentExpandNode(state) {
10
13
  return (0, _utils.findParentNodeOfType)(state.schema.nodes.nestedExpand)(state.selection) || (0, _utils.findParentNodeOfType)(state.schema.nodes.expand)(state.selection);
11
14
  };
12
- var findReplaceExpandDecorations = exports.findReplaceExpandDecorations = [_styles.darkModeSearchMatchClass, _styles.searchMatchExpandTitleClass, _styles.selectedSearchMatchClass];
15
+ var findReplaceExpandDecorations = exports.findReplaceExpandDecorations = [darkModeSearchMatchClass, searchMatchExpandTitleClass, selectedSearchMatchClass];
@@ -218,4 +218,12 @@ export const setSelectionInsideExpand = expandPos => (_state, dispatch, editorVi
218
218
  return true;
219
219
  }
220
220
  return false;
221
+ };
222
+ export const toggleExpandWithMatch = _selection => ({
223
+ tr
224
+ }) => {
225
+ // this action exists so that we can keep the plugin types consistent across the
226
+ // the legacy expand plugin and the single player expand plugin until
227
+ // we will remove the legacy expand plugin
228
+ return null;
221
229
  };
@@ -4,7 +4,7 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } f
4
4
  import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
5
5
  import { IconExpand } from '@atlaskit/editor-common/quick-insert';
6
6
  import { createWrapSelectionTransaction } from '@atlaskit/editor-common/utils';
7
- import { createExpandNode, insertExpand, insertExpandWithInputMethod } from './commands';
7
+ import { createExpandNode, insertExpand, insertExpandWithInputMethod, toggleExpandWithMatch } from './commands';
8
8
  import { expandKeymap } from './pm-plugins/keymap';
9
9
  import { createPlugin } from './pm-plugins/main';
10
10
  import { getToolbarConfig } from './toolbar';
@@ -31,6 +31,9 @@ export let expandPlugin = ({
31
31
  insertExpand: insertExpand(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions),
32
32
  insertExpandWithInputMethod: insertExpandWithInputMethod(api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
33
33
  },
34
+ commands: {
35
+ toggleExpandWithMatch: selection => toggleExpandWithMatch(selection)
36
+ },
34
37
  pmPlugins() {
35
38
  return [{
36
39
  name: 'expand',
@@ -8,6 +8,7 @@ import { createWrapSelectionTransaction } from '@atlaskit/editor-common/utils';
8
8
  import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
9
9
  import { findParentNodeOfType, safeInsert } from '@atlaskit/editor-prosemirror/utils';
10
10
  import { findTable } from '@atlaskit/editor-tables/utils';
11
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
11
12
  import { isNestedInExpand } from '../utils';
12
13
 
13
14
  // Creates either an expand or a nestedExpand node based on the current selection
@@ -209,4 +210,31 @@ export const focusIcon = expand => (state, dispatch, editorView) => {
209
210
  return true;
210
211
  }
211
212
  return false;
213
+ };
214
+ export const toggleExpandWithMatch = selection => ({
215
+ tr
216
+ }) => {
217
+ const {
218
+ expand,
219
+ nestedExpand
220
+ } = tr.doc.type.schema.nodes;
221
+ // if match is inside a nested expand, open the nested expand
222
+ const nestedExpandNode = findParentNodeOfType(nestedExpand)(selection);
223
+ if (nestedExpandNode && expValEquals('platform_editor_toggle_expand_on_match_found', 'isEnabled', true)) {
224
+ var _expandedState$get2;
225
+ const expanded = (_expandedState$get2 = expandedState.get(nestedExpandNode.node)) !== null && _expandedState$get2 !== void 0 ? _expandedState$get2 : false;
226
+ if (!expanded) {
227
+ expandedState.set(nestedExpandNode.node, true);
228
+ }
229
+ }
230
+ // if match is (also) inside an expand, open the expand
231
+ const expandNode = findParentNodeOfType(expand)(selection);
232
+ if (expandNode && expValEquals('platform_editor_toggle_expand_on_match_found', 'isEnabled', true)) {
233
+ var _expandedState$get3;
234
+ const expanded = (_expandedState$get3 = expandedState.get(expandNode.node)) !== null && _expandedState$get3 !== void 0 ? _expandedState$get3 : false;
235
+ if (!expanded) {
236
+ expandedState.set(expandNode.node, true);
237
+ }
238
+ }
239
+ return tr;
212
240
  };
@@ -16,7 +16,7 @@ import { ExpandButton } from '../ui/ExpandButton';
16
16
  import { buildExpandClassName, toDOM } from '../ui/NodeView';
17
17
  import { findReplaceExpandDecorations } from '../utils';
18
18
  export class ExpandNodeView {
19
- constructor(_node, view, getPos, getIntl, isMobile, selectNearNode, api, nodeViewPortalProviderAPI, allowInteractiveExpand = true, __livePage = false, cleanUpEditorDisabledOnChange) {
19
+ constructor(_node, view, getPos, getIntl, isMobile, selectNearNode, api, nodeViewPortalProviderAPI, allowInteractiveExpand = true, __livePage = false, cleanUpEditorDisabledOnChange, isExpanded = false) {
20
20
  var _api$editorDisabled, _api$editorDisabled$s, _this$api6;
21
21
  _defineProperty(this, "allowInteractiveExpand", true);
22
22
  _defineProperty(this, "isMobile", false);
@@ -392,6 +392,7 @@ export class ExpandNodeView {
392
392
  this.selectNearNode = selectNearNode;
393
393
  this.__livePage = __livePage;
394
394
  this.cleanUpEditorDisabledOnChange = cleanUpEditorDisabledOnChange;
395
+ this.isExpanded = isExpanded;
395
396
  this.intl = getIntl();
396
397
  this.nodeViewPortalProviderAPI = nodeViewPortalProviderAPI;
397
398
  this.allowInteractiveExpand = allowInteractiveExpand;
@@ -488,9 +489,17 @@ export class ExpandNodeView {
488
489
  expandedState.set(node, wasExpanded);
489
490
  }
490
491
  }
491
- this.node = node;
492
- if (!fg('platform_editor_disable_unnecessary_expand_renders')) {
493
- this.updateExpandToggleIcon(this.node);
492
+ if (expValEquals('platform_editor_toggle_expand_on_match_found', 'isEnabled', true)) {
493
+ this.node = node;
494
+ const hasChanged = this.isExpanded !== expandedState.get(node);
495
+ if (hasChanged) {
496
+ this.updateExpandToggleIcon(node);
497
+ }
498
+ } else {
499
+ this.node = node;
500
+ if (!fg('platform_editor_disable_unnecessary_expand_renders')) {
501
+ this.updateExpandToggleIcon(this.node);
502
+ }
494
503
  }
495
504
  return true;
496
505
  }
@@ -512,6 +521,9 @@ export class ExpandNodeView {
512
521
  this.renderIcon(this.icon ? this.icon : null, (_expandedState$get = expandedState.get(node)) !== null && _expandedState$get !== void 0 ? _expandedState$get : false);
513
522
  }
514
523
  this.updateExpandBodyContentEditable();
524
+ if (expValEquals('platform_editor_toggle_expand_on_match_found', 'isEnabled', true)) {
525
+ this.isExpanded = expanded;
526
+ }
515
527
  }
516
528
  updateExpandBodyContentEditable() {
517
529
  // Disallow interaction/selection inside expand body when collapsed.
@@ -4,7 +4,7 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } f
4
4
  import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
5
5
  import { IconExpand } from '@atlaskit/editor-common/quick-insert';
6
6
  import { createWrapSelectionTransaction } from '@atlaskit/editor-common/utils';
7
- import { createExpandNode, insertExpand, insertExpandWithInputMethod } from './commands';
7
+ import { createExpandNode, insertExpand, insertExpandWithInputMethod, toggleExpandWithMatch } from './commands';
8
8
  import { expandKeymap } from './pm-plugins/keymap';
9
9
  import { createPlugin } from './pm-plugins/main';
10
10
  import { getToolbarConfig } from './toolbar';
@@ -31,6 +31,9 @@ export let expandPlugin = ({
31
31
  insertExpand: insertExpand(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions),
32
32
  insertExpandWithInputMethod: insertExpandWithInputMethod(api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
33
33
  },
34
+ commands: {
35
+ toggleExpandWithMatch: selection => toggleExpandWithMatch(selection)
36
+ },
34
37
  pmPlugins() {
35
38
  return [{
36
39
  name: 'expand',
@@ -1,5 +1,9 @@
1
- import { darkModeSearchMatchClass, searchMatchExpandTitleClass, selectedSearchMatchClass } from '@atlaskit/editor-plugin-find-replace/styles';
2
1
  import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
2
+
3
+ // from platform/packages/editor/editor-plugin-find-replace/src/ui/styles.ts
4
+ const darkModeSearchMatchClass = 'search-match-dark';
5
+ const searchMatchExpandTitleClass = 'search-match-expand-title';
6
+ const selectedSearchMatchClass = 'selected-search-match';
3
7
  export const findParentExpandNode = state => {
4
8
  return findParentNodeOfType(state.schema.nodes.nestedExpand)(state.selection) || findParentNodeOfType(state.schema.nodes.expand)(state.selection);
5
9
  };
@@ -232,4 +232,13 @@ export var setSelectionInsideExpand = function setSelectionInsideExpand(expandPo
232
232
  }
233
233
  return false;
234
234
  };
235
+ };
236
+ export var toggleExpandWithMatch = function toggleExpandWithMatch(_selection) {
237
+ return function (_ref3) {
238
+ var tr = _ref3.tr;
239
+ // this action exists so that we can keep the plugin types consistent across the
240
+ // the legacy expand plugin and the single player expand plugin until
241
+ // we will remove the legacy expand plugin
242
+ return null;
243
+ };
235
244
  };
@@ -4,7 +4,7 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } f
4
4
  import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
5
5
  import { IconExpand } from '@atlaskit/editor-common/quick-insert';
6
6
  import { createWrapSelectionTransaction } from '@atlaskit/editor-common/utils';
7
- import { createExpandNode, insertExpand, insertExpandWithInputMethod } from './commands';
7
+ import { createExpandNode, insertExpand, insertExpandWithInputMethod, toggleExpandWithMatch as _toggleExpandWithMatch } from './commands';
8
8
  import { expandKeymap } from './pm-plugins/keymap';
9
9
  import { createPlugin } from './pm-plugins/main';
10
10
  import { getToolbarConfig } from './toolbar';
@@ -31,6 +31,11 @@ export var expandPlugin = function expandPlugin(_ref) {
31
31
  insertExpand: insertExpand(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions),
32
32
  insertExpandWithInputMethod: insertExpandWithInputMethod(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
33
33
  },
34
+ commands: {
35
+ toggleExpandWithMatch: function toggleExpandWithMatch(selection) {
36
+ return _toggleExpandWithMatch(selection);
37
+ }
38
+ },
34
39
  pmPlugins: function pmPlugins() {
35
40
  return [{
36
41
  name: 'expand',
@@ -11,6 +11,7 @@ import { createWrapSelectionTransaction } from '@atlaskit/editor-common/utils';
11
11
  import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
12
12
  import { findParentNodeOfType, safeInsert } from '@atlaskit/editor-prosemirror/utils';
13
13
  import { findTable } from '@atlaskit/editor-tables/utils';
14
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
14
15
  import { isNestedInExpand } from '../utils';
15
16
 
16
17
  // Creates either an expand or a nestedExpand node based on the current selection
@@ -223,4 +224,31 @@ export var focusIcon = function focusIcon(expand) {
223
224
  }
224
225
  return false;
225
226
  };
227
+ };
228
+ export var toggleExpandWithMatch = function toggleExpandWithMatch(selection) {
229
+ return function (_ref3) {
230
+ var tr = _ref3.tr;
231
+ var _tr$doc$type$schema$n = tr.doc.type.schema.nodes,
232
+ expand = _tr$doc$type$schema$n.expand,
233
+ nestedExpand = _tr$doc$type$schema$n.nestedExpand;
234
+ // if match is inside a nested expand, open the nested expand
235
+ var nestedExpandNode = findParentNodeOfType(nestedExpand)(selection);
236
+ if (nestedExpandNode && expValEquals('platform_editor_toggle_expand_on_match_found', 'isEnabled', true)) {
237
+ var _expandedState$get2;
238
+ var expanded = (_expandedState$get2 = expandedState.get(nestedExpandNode.node)) !== null && _expandedState$get2 !== void 0 ? _expandedState$get2 : false;
239
+ if (!expanded) {
240
+ expandedState.set(nestedExpandNode.node, true);
241
+ }
242
+ }
243
+ // if match is (also) inside an expand, open the expand
244
+ var expandNode = findParentNodeOfType(expand)(selection);
245
+ if (expandNode && expValEquals('platform_editor_toggle_expand_on_match_found', 'isEnabled', true)) {
246
+ var _expandedState$get3;
247
+ var _expanded = (_expandedState$get3 = expandedState.get(expandNode.node)) !== null && _expandedState$get3 !== void 0 ? _expandedState$get3 : false;
248
+ if (!_expanded) {
249
+ expandedState.set(expandNode.node, true);
250
+ }
251
+ }
252
+ return tr;
253
+ };
226
254
  };
@@ -25,6 +25,7 @@ export var ExpandNodeView = /*#__PURE__*/function () {
25
25
  var allowInteractiveExpand = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : true;
26
26
  var __livePage = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : false;
27
27
  var cleanUpEditorDisabledOnChange = arguments.length > 10 ? arguments[10] : undefined;
28
+ var isExpanded = arguments.length > 11 && arguments[11] !== undefined ? arguments[11] : false;
28
29
  _classCallCheck(this, ExpandNodeView);
29
30
  _defineProperty(this, "allowInteractiveExpand", true);
30
31
  _defineProperty(this, "isMobile", false);
@@ -385,6 +386,7 @@ export var ExpandNodeView = /*#__PURE__*/function () {
385
386
  this.selectNearNode = selectNearNode;
386
387
  this.__livePage = __livePage;
387
388
  this.cleanUpEditorDisabledOnChange = cleanUpEditorDisabledOnChange;
389
+ this.isExpanded = isExpanded;
388
390
  this.intl = getIntl();
389
391
  this.nodeViewPortalProviderAPI = nodeViewPortalProviderAPI;
390
392
  this.allowInteractiveExpand = allowInteractiveExpand;
@@ -487,9 +489,17 @@ export var ExpandNodeView = /*#__PURE__*/function () {
487
489
  expandedState.set(node, wasExpanded);
488
490
  }
489
491
  }
490
- this.node = node;
491
- if (!fg('platform_editor_disable_unnecessary_expand_renders')) {
492
- this.updateExpandToggleIcon(this.node);
492
+ if (expValEquals('platform_editor_toggle_expand_on_match_found', 'isEnabled', true)) {
493
+ this.node = node;
494
+ var hasChanged = this.isExpanded !== expandedState.get(node);
495
+ if (hasChanged) {
496
+ this.updateExpandToggleIcon(node);
497
+ }
498
+ } else {
499
+ this.node = node;
500
+ if (!fg('platform_editor_disable_unnecessary_expand_renders')) {
501
+ this.updateExpandToggleIcon(this.node);
502
+ }
493
503
  }
494
504
  return true;
495
505
  }
@@ -515,6 +525,9 @@ export var ExpandNodeView = /*#__PURE__*/function () {
515
525
  this.renderIcon(this.icon ? this.icon : null, (_expandedState$get = expandedState.get(node)) !== null && _expandedState$get !== void 0 ? _expandedState$get : false);
516
526
  }
517
527
  this.updateExpandBodyContentEditable();
528
+ if (expValEquals('platform_editor_toggle_expand_on_match_found', 'isEnabled', true)) {
529
+ this.isExpanded = expanded;
530
+ }
518
531
  }
519
532
  }, {
520
533
  key: "updateExpandBodyContentEditable",
@@ -4,7 +4,7 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } f
4
4
  import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
5
5
  import { IconExpand } from '@atlaskit/editor-common/quick-insert';
6
6
  import { createWrapSelectionTransaction } from '@atlaskit/editor-common/utils';
7
- import { createExpandNode, insertExpand, insertExpandWithInputMethod } from './commands';
7
+ import { createExpandNode, insertExpand, insertExpandWithInputMethod, toggleExpandWithMatch as _toggleExpandWithMatch } from './commands';
8
8
  import { expandKeymap } from './pm-plugins/keymap';
9
9
  import { createPlugin } from './pm-plugins/main';
10
10
  import { getToolbarConfig } from './toolbar';
@@ -31,6 +31,11 @@ export var expandPlugin = function expandPlugin(_ref) {
31
31
  insertExpand: insertExpand(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions),
32
32
  insertExpandWithInputMethod: insertExpandWithInputMethod(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
33
33
  },
34
+ commands: {
35
+ toggleExpandWithMatch: function toggleExpandWithMatch(selection) {
36
+ return _toggleExpandWithMatch(selection);
37
+ }
38
+ },
34
39
  pmPlugins: function pmPlugins() {
35
40
  return [{
36
41
  name: 'expand',
@@ -1,5 +1,9 @@
1
- import { darkModeSearchMatchClass, searchMatchExpandTitleClass, selectedSearchMatchClass } from '@atlaskit/editor-plugin-find-replace/styles';
2
1
  import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
2
+
3
+ // from platform/packages/editor/editor-plugin-find-replace/src/ui/styles.ts
4
+ var darkModeSearchMatchClass = 'search-match-dark';
5
+ var searchMatchExpandTitleClass = 'search-match-expand-title';
6
+ var selectedSearchMatchClass = 'selected-search-match';
3
7
  export var findParentExpandNode = function findParentExpandNode(state) {
4
8
  return findParentNodeOfType(state.schema.nodes.nestedExpand)(state.selection) || findParentNodeOfType(state.schema.nodes.expand)(state.selection);
5
9
  };
@@ -1,6 +1,7 @@
1
1
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
- import type { Command } from '@atlaskit/editor-common/types';
2
+ import type { Command, EditorCommand } from '@atlaskit/editor-common/types';
3
3
  import type { NodeType, Node as PMNode } from '@atlaskit/editor-prosemirror/model';
4
+ import { Selection } from '@atlaskit/editor-prosemirror/state';
4
5
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
5
6
  import type { InsertMethod } from '../types';
6
7
  export declare const setExpandRef: (ref?: HTMLDivElement | null) => Command;
@@ -24,3 +25,4 @@ export declare const insertExpand: (editorAnalyticsAPI: EditorAnalyticsAPI | und
24
25
  export declare const focusTitle: (pos: number) => Command;
25
26
  export declare const focusIcon: (expand: Node) => Command;
26
27
  export declare const setSelectionInsideExpand: (expandPos: number) => Command;
28
+ export declare const toggleExpandWithMatch: (_selection: Selection) => EditorCommand;
@@ -1,7 +1,8 @@
1
1
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
- import type { Command } from '@atlaskit/editor-common/types';
2
+ import type { Command, EditorCommand } from '@atlaskit/editor-common/types';
3
3
  import type { NodeType, Node as PMNode } from '@atlaskit/editor-prosemirror/model';
4
4
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
5
+ import { Selection } from '@atlaskit/editor-prosemirror/state';
5
6
  import type { InsertMethod } from '../types';
6
7
  export declare const createExpandNode: (state: EditorState, setExpandedState?: boolean) => PMNode | null;
7
8
  export declare const insertExpandWithInputMethod: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (inputMethod: InsertMethod) => Command;
@@ -21,3 +22,4 @@ export declare const updateExpandTitle: ({ title, nodeType, pos }: {
21
22
  }) => Command;
22
23
  export declare const focusTitle: (pos: number) => Command;
23
24
  export declare const focusIcon: (expand: Node) => Command;
25
+ export declare const toggleExpandWithMatch: (selection: Selection) => EditorCommand;
@@ -9,6 +9,7 @@ export declare class ExpandNodeView implements NodeView {
9
9
  private selectNearNode;
10
10
  private __livePage;
11
11
  private cleanUpEditorDisabledOnChange?;
12
+ private isExpanded;
12
13
  node: PmNode;
13
14
  view: EditorView;
14
15
  dom: HTMLElement;
@@ -25,7 +26,7 @@ export declare class ExpandNodeView implements NodeView {
25
26
  nodeViewPortalProviderAPI: PortalProviderAPI;
26
27
  decorationCleanup?: () => boolean | undefined;
27
28
  renderKey: string;
28
- constructor(node: PmNode, view: EditorView, getPos: getPosHandlerNode, getIntl: () => IntlShape, isMobile: boolean, selectNearNode: SetSelectionRelativeToNode | undefined, api: ExtractInjectionAPI<ExpandPlugin> | undefined, nodeViewPortalProviderAPI: PortalProviderAPI, allowInteractiveExpand?: boolean, __livePage?: boolean, cleanUpEditorDisabledOnChange?: (() => void) | undefined);
29
+ constructor(node: PmNode, view: EditorView, getPos: getPosHandlerNode, getIntl: () => IntlShape, isMobile: boolean, selectNearNode: SetSelectionRelativeToNode | undefined, api: ExtractInjectionAPI<ExpandPlugin> | undefined, nodeViewPortalProviderAPI: PortalProviderAPI, allowInteractiveExpand?: boolean, __livePage?: boolean, cleanUpEditorDisabledOnChange?: (() => void) | undefined, isExpanded?: boolean | undefined);
29
30
  private focusTitle;
30
31
  private handleIconKeyDown;
31
32
  private handleClick;
@@ -1,5 +1,5 @@
1
1
  import { type INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
- import type { EditorAppearance, LongPressSelectionPluginOptions, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
2
+ import type { EditorAppearance, EditorCommand, LongPressSelectionPluginOptions, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
3
3
  import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
4
4
  import type { DecorationsPlugin } from '@atlaskit/editor-plugin-decorations';
5
5
  import type { EditorDisabledPlugin } from '@atlaskit/editor-plugin-editor-disabled';
@@ -7,6 +7,7 @@ import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmo
7
7
  import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
8
8
  import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
9
9
  import type { SelectionMarkerPlugin } from '@atlaskit/editor-plugin-selection-marker';
10
+ import type { Selection } from '@atlaskit/editor-prosemirror/state';
10
11
  import type { insertExpand, insertExpandWithInputMethod } from './legacyExpand/commands';
11
12
  export interface ExpandPluginState {
12
13
  expandRef?: HTMLDivElement | null;
@@ -60,4 +61,10 @@ export type ExpandPlugin = NextEditorPlugin<'expand', {
60
61
  */
61
62
  insertExpandWithInputMethod: ReturnType<typeof insertExpandWithInputMethod>;
62
63
  };
64
+ commands: {
65
+ /**
66
+ * Toggle the expand or nested expand node open
67
+ */
68
+ toggleExpandWithMatch: (selection: Selection) => EditorCommand;
69
+ };
63
70
  }>;
@@ -1,6 +1,7 @@
1
1
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
- import type { Command } from '@atlaskit/editor-common/types';
2
+ import type { Command, EditorCommand } from '@atlaskit/editor-common/types';
3
3
  import type { NodeType, Node as PMNode } from '@atlaskit/editor-prosemirror/model';
4
+ import { Selection } from '@atlaskit/editor-prosemirror/state';
4
5
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
5
6
  import type { InsertMethod } from '../types';
6
7
  export declare const setExpandRef: (ref?: HTMLDivElement | null) => Command;
@@ -24,3 +25,4 @@ export declare const insertExpand: (editorAnalyticsAPI: EditorAnalyticsAPI | und
24
25
  export declare const focusTitle: (pos: number) => Command;
25
26
  export declare const focusIcon: (expand: Node) => Command;
26
27
  export declare const setSelectionInsideExpand: (expandPos: number) => Command;
28
+ export declare const toggleExpandWithMatch: (_selection: Selection) => EditorCommand;
@@ -1,7 +1,8 @@
1
1
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
- import type { Command } from '@atlaskit/editor-common/types';
2
+ import type { Command, EditorCommand } from '@atlaskit/editor-common/types';
3
3
  import type { NodeType, Node as PMNode } from '@atlaskit/editor-prosemirror/model';
4
4
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
5
+ import { Selection } from '@atlaskit/editor-prosemirror/state';
5
6
  import type { InsertMethod } from '../types';
6
7
  export declare const createExpandNode: (state: EditorState, setExpandedState?: boolean) => PMNode | null;
7
8
  export declare const insertExpandWithInputMethod: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (inputMethod: InsertMethod) => Command;
@@ -21,3 +22,4 @@ export declare const updateExpandTitle: ({ title, nodeType, pos }: {
21
22
  }) => Command;
22
23
  export declare const focusTitle: (pos: number) => Command;
23
24
  export declare const focusIcon: (expand: Node) => Command;
25
+ export declare const toggleExpandWithMatch: (selection: Selection) => EditorCommand;
@@ -9,6 +9,7 @@ export declare class ExpandNodeView implements NodeView {
9
9
  private selectNearNode;
10
10
  private __livePage;
11
11
  private cleanUpEditorDisabledOnChange?;
12
+ private isExpanded;
12
13
  node: PmNode;
13
14
  view: EditorView;
14
15
  dom: HTMLElement;
@@ -25,7 +26,7 @@ export declare class ExpandNodeView implements NodeView {
25
26
  nodeViewPortalProviderAPI: PortalProviderAPI;
26
27
  decorationCleanup?: () => boolean | undefined;
27
28
  renderKey: string;
28
- constructor(node: PmNode, view: EditorView, getPos: getPosHandlerNode, getIntl: () => IntlShape, isMobile: boolean, selectNearNode: SetSelectionRelativeToNode | undefined, api: ExtractInjectionAPI<ExpandPlugin> | undefined, nodeViewPortalProviderAPI: PortalProviderAPI, allowInteractiveExpand?: boolean, __livePage?: boolean, cleanUpEditorDisabledOnChange?: (() => void) | undefined);
29
+ constructor(node: PmNode, view: EditorView, getPos: getPosHandlerNode, getIntl: () => IntlShape, isMobile: boolean, selectNearNode: SetSelectionRelativeToNode | undefined, api: ExtractInjectionAPI<ExpandPlugin> | undefined, nodeViewPortalProviderAPI: PortalProviderAPI, allowInteractiveExpand?: boolean, __livePage?: boolean, cleanUpEditorDisabledOnChange?: (() => void) | undefined, isExpanded?: boolean | undefined);
29
30
  private focusTitle;
30
31
  private handleIconKeyDown;
31
32
  private handleClick;
@@ -1,5 +1,5 @@
1
1
  import { type INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
- import type { EditorAppearance, LongPressSelectionPluginOptions, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
2
+ import type { EditorAppearance, EditorCommand, LongPressSelectionPluginOptions, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
3
3
  import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
4
4
  import type { DecorationsPlugin } from '@atlaskit/editor-plugin-decorations';
5
5
  import type { EditorDisabledPlugin } from '@atlaskit/editor-plugin-editor-disabled';
@@ -7,6 +7,7 @@ import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmo
7
7
  import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
8
8
  import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
9
9
  import type { SelectionMarkerPlugin } from '@atlaskit/editor-plugin-selection-marker';
10
+ import type { Selection } from '@atlaskit/editor-prosemirror/state';
10
11
  import type { insertExpand, insertExpandWithInputMethod } from './legacyExpand/commands';
11
12
  export interface ExpandPluginState {
12
13
  expandRef?: HTMLDivElement | null;
@@ -60,4 +61,10 @@ export type ExpandPlugin = NextEditorPlugin<'expand', {
60
61
  */
61
62
  insertExpandWithInputMethod: ReturnType<typeof insertExpandWithInputMethod>;
62
63
  };
64
+ commands: {
65
+ /**
66
+ * Toggle the expand or nested expand node open
67
+ */
68
+ toggleExpandWithMatch: (selection: Selection) => EditorCommand;
69
+ };
63
70
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-expand",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "Expand plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -38,15 +38,14 @@
38
38
  "@atlaskit/editor-plugin-decorations": "^3.0.0",
39
39
  "@atlaskit/editor-plugin-editor-disabled": "^3.0.0",
40
40
  "@atlaskit/editor-plugin-editor-viewmode": "^5.0.0",
41
- "@atlaskit/editor-plugin-find-replace": "^3.0.0",
42
41
  "@atlaskit/editor-plugin-selection": "^3.0.0",
43
42
  "@atlaskit/editor-plugin-selection-marker": "^3.0.0",
44
43
  "@atlaskit/editor-prosemirror": "7.0.0",
45
44
  "@atlaskit/editor-shared-styles": "^3.4.0",
46
45
  "@atlaskit/editor-tables": "^2.9.0",
47
- "@atlaskit/icon": "^27.2.0",
46
+ "@atlaskit/icon": "^27.3.0",
48
47
  "@atlaskit/platform-feature-flags": "^1.1.0",
49
- "@atlaskit/tmp-editor-statsig": "^8.7.0",
48
+ "@atlaskit/tmp-editor-statsig": "^9.1.0",
50
49
  "@atlaskit/tokens": "^5.4.0",
51
50
  "@atlaskit/tooltip": "^20.3.0",
52
51
  "@babel/runtime": "^7.0.0",
@@ -55,7 +54,7 @@
55
54
  "w3c-keyname": "^2.1.8"
56
55
  },
57
56
  "peerDependencies": {
58
- "@atlaskit/editor-common": "^107.6.0",
57
+ "@atlaskit/editor-common": "^107.7.0",
59
58
  "react": "^18.2.0",
60
59
  "react-dom": "^18.2.0",
61
60
  "react-intl-next": "npm:react-intl@^5.18.1"