@atlaskit/editor-plugin-expand 1.3.5 → 1.4.1

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.
Files changed (27) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/legacyExpand/nodeviews/index.js +20 -8
  3. package/dist/cjs/singlePlayerExpand/commands.js +47 -6
  4. package/dist/cjs/singlePlayerExpand/node-views/index.js +80 -32
  5. package/dist/cjs/singlePlayerExpand/pm-plugins/keymap.js +8 -4
  6. package/dist/cjs/singlePlayerExpand/ui/NodeView.js +11 -6
  7. package/dist/es2019/legacyExpand/nodeviews/index.js +20 -8
  8. package/dist/es2019/singlePlayerExpand/commands.js +44 -2
  9. package/dist/es2019/singlePlayerExpand/node-views/index.js +67 -20
  10. package/dist/es2019/singlePlayerExpand/pm-plugins/keymap.js +8 -4
  11. package/dist/es2019/singlePlayerExpand/ui/NodeView.js +40 -35
  12. package/dist/esm/legacyExpand/nodeviews/index.js +20 -8
  13. package/dist/esm/singlePlayerExpand/commands.js +47 -6
  14. package/dist/esm/singlePlayerExpand/node-views/index.js +82 -34
  15. package/dist/esm/singlePlayerExpand/pm-plugins/keymap.js +8 -4
  16. package/dist/esm/singlePlayerExpand/ui/NodeView.js +11 -7
  17. package/dist/types/legacyExpand/nodeviews/index.d.ts +2 -0
  18. package/dist/types/singlePlayerExpand/commands.d.ts +5 -0
  19. package/dist/types/singlePlayerExpand/node-views/index.d.ts +4 -0
  20. package/dist/types/singlePlayerExpand/ui/NodeView.d.ts +1 -1
  21. package/dist/types/types.d.ts +3 -1
  22. package/dist/types-ts4.5/legacyExpand/nodeviews/index.d.ts +2 -0
  23. package/dist/types-ts4.5/singlePlayerExpand/commands.d.ts +5 -0
  24. package/dist/types-ts4.5/singlePlayerExpand/node-views/index.d.ts +4 -0
  25. package/dist/types-ts4.5/singlePlayerExpand/ui/NodeView.d.ts +1 -1
  26. package/dist/types-ts4.5/types.d.ts +3 -1
  27. package/package.json +3 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/editor-plugin-expand
2
2
 
3
+ ## 1.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#90897](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/90897) [`6a1d609df65e`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/6a1d609df65e) - [ux] [ED-22841] Implement new state management for the single player expand and handle the expanding behaviour based on this. Single player expand will only be used if `platform.editor.single-player-expand` is true and livePage is enabled.
8
+
9
+ ## 1.4.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#90925](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/90925) [`431c0d17e3e3`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/431c0d17e3e3) - [ux] Improve the selection marker by hiding it when in an expand and improving styling by making it more subtle.
14
+
3
15
  ## 1.3.5
4
16
 
5
17
  ### Patch Changes
@@ -67,6 +67,7 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
67
67
  (0, _defineProperty2.default)(this, "isMobile", false);
68
68
  (0, _defineProperty2.default)(this, "focusTitle", function () {
69
69
  if (_this.input) {
70
+ var _this$api;
70
71
  var _this$view = _this.view,
71
72
  state = _this$view.state,
72
73
  dispatch = _this$view.dispatch;
@@ -82,6 +83,7 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
82
83
  if (typeof pos === 'number') {
83
84
  (0, _commands.setSelectionInsideExpand)(pos)(state, dispatch, _this.view);
84
85
  }
86
+ _this.decorationCleanup = (_this$api = _this.api) === null || _this$api === void 0 || (_this$api = _this$api.selectionMarker) === null || _this$api === void 0 || (_this$api = _this$api.actions) === null || _this$api === void 0 ? void 0 : _this$api.hideDecoration();
85
87
  _this.input.focus();
86
88
  }
87
89
  });
@@ -107,7 +109,7 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
107
109
  state = _this$view2.state,
108
110
  dispatch = _this$view2.dispatch;
109
111
  if ((0, _utils.closestElement)(target, ".".concat(_styles.expandClassNames.icon))) {
110
- var _this$api;
112
+ var _this$api2;
111
113
  if (!_this.allowInteractiveExpand) {
112
114
  return;
113
115
  }
@@ -119,7 +121,7 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
119
121
  _this.view.dom.blur();
120
122
  }
121
123
  (0, _commands.toggleExpandExpanded)({
122
- editorAnalyticsAPI: (_this$api = _this.api) === null || _this$api === void 0 || (_this$api = _this$api.analytics) === null || _this$api === void 0 ? void 0 : _this$api.actions,
124
+ editorAnalyticsAPI: (_this$api2 = _this.api) === null || _this$api2 === void 0 || (_this$api2 = _this$api2.analytics) === null || _this$api2 === void 0 ? void 0 : _this$api2.actions,
123
125
  pos: pos,
124
126
  nodeType: _this.node.type,
125
127
  __livePage: _this.__livePage
@@ -154,6 +156,10 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
154
156
  (0, _defineProperty2.default)(this, "handleFocus", function (event) {
155
157
  event.stopImmediatePropagation();
156
158
  });
159
+ (0, _defineProperty2.default)(this, "handleBlur", function (event) {
160
+ var _this$decorationClean;
161
+ (_this$decorationClean = _this.decorationCleanup) === null || _this$decorationClean === void 0 || _this$decorationClean.call(_this);
162
+ });
157
163
  (0, _defineProperty2.default)(this, "handleTitleKeydown", function (event) {
158
164
  switch ((0, _w3cKeyname.keyName)(event)) {
159
165
  case 'Enter':
@@ -194,8 +200,8 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
194
200
  var state = _this.view.state;
195
201
  var expandNode = _this.node;
196
202
  if (expandNode && (0, _utils.isEmptyNode)(state.schema)(expandNode)) {
197
- var _this$api2;
198
- (0, _commands.deleteExpandAtPos)((_this$api2 = _this.api) === null || _this$api2 === void 0 || (_this$api2 = _this$api2.analytics) === null || _this$api2 === void 0 ? void 0 : _this$api2.actions)(pos, expandNode)(state, _this.view.dispatch);
203
+ var _this$api3;
204
+ (0, _commands.deleteExpandAtPos)((_this$api3 = _this.api) === null || _this$api3 === void 0 || (_this$api3 = _this$api3.analytics) === null || _this$api3 === void 0 ? void 0 : _this$api3.actions)(pos, expandNode)(state, _this.view.dispatch);
199
205
  }
200
206
  });
201
207
  (0, _defineProperty2.default)(this, "toggleExpand", function () {
@@ -204,12 +210,12 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
204
210
  return;
205
211
  }
206
212
  if (_this.allowInteractiveExpand) {
207
- var _this$api3;
213
+ var _this$api4;
208
214
  var _this$view4 = _this.view,
209
215
  state = _this$view4.state,
210
216
  dispatch = _this$view4.dispatch;
211
217
  (0, _commands.toggleExpandExpanded)({
212
- editorAnalyticsAPI: (_this$api3 = _this.api) === null || _this$api3 === void 0 || (_this$api3 = _this$api3.analytics) === null || _this$api3 === void 0 ? void 0 : _this$api3.actions,
218
+ editorAnalyticsAPI: (_this$api4 = _this.api) === null || _this$api4 === void 0 || (_this$api4 = _this$api4.analytics) === null || _this$api4 === void 0 ? void 0 : _this$api4.actions,
213
219
  pos: pos,
214
220
  nodeType: _this.node.type,
215
221
  __livePage: _this.__livePage
@@ -330,13 +336,13 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
330
336
  selectionStart = _this$input5.selectionStart,
331
337
  selectionEnd = _this$input5.selectionEnd;
332
338
  if (selectionStart === selectionEnd && selectionStart === 0) {
333
- var _this$api4;
339
+ var _this$api5;
334
340
  event.preventDefault();
335
341
  var _this$view9 = _this.view,
336
342
  state = _this$view9.state,
337
343
  dispatch = _this$view9.dispatch;
338
344
  _this.view.focus();
339
- var selectionSharedState = ((_this$api4 = _this.api) === null || _this$api4 === void 0 || (_this$api4 = _this$api4.selection) === null || _this$api4 === void 0 ? void 0 : _this$api4.sharedState.currentState()) || {};
345
+ var selectionSharedState = ((_this$api5 = _this.api) === null || _this$api5 === void 0 || (_this$api5 = _this$api5.selection) === null || _this$api5 === void 0 ? void 0 : _this$api5.sharedState.currentState()) || {};
340
346
  // selectionRelativeToNode is undefined when user clicked to select node, then hit left to get focus in title
341
347
  // This is a special case where we want to bypass node selection and jump straight to gap cursor
342
348
  if ((selectionSharedState === null || selectionSharedState === void 0 ? void 0 : selectionSharedState.selectionRelativeToNode) === undefined) {
@@ -391,6 +397,8 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
391
397
  if (this.input) {
392
398
  // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
393
399
  this.input.addEventListener('keydown', this.handleTitleKeydown);
400
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
401
+ this.input.addEventListener('blur', this.handleBlur);
394
402
  }
395
403
  if (this.titleContainer) {
396
404
  // If the user interacts in our title bar (either toggle or input)
@@ -470,6 +478,7 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
470
478
  }, {
471
479
  key: "destroy",
472
480
  value: function destroy() {
481
+ var _this$decorationClean2;
473
482
  if (this.dom) {
474
483
  // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
475
484
  this.dom.removeEventListener('click', this.handleClick);
@@ -479,6 +488,8 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
479
488
  if (this.input) {
480
489
  // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
481
490
  this.input.removeEventListener('keydown', this.handleTitleKeydown);
491
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
492
+ this.input.removeEventListener('blur', this.handleBlur);
482
493
  }
483
494
  if (this.titleContainer) {
484
495
  // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
@@ -489,6 +500,7 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
489
500
  this.icon.removeEventListener('keydown', this.handleIconKeyDown);
490
501
  _reactDom.default.unmountComponentAtNode(this.icon);
491
502
  }
503
+ (_this$decorationClean2 = this.decorationCleanup) === null || _this$decorationClean2 === void 0 || _this$decorationClean2.call(this);
492
504
 
493
505
  // @ts-ignore - [unblock prosemirror bump] reset non optional prop to undefined to clear reference
494
506
  this.dom = undefined;
@@ -4,10 +4,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.updateExpandTitle = exports.setSelectionInsideExpand = exports.insertExpand = exports.focusTitle = exports.deleteExpandAtPos = exports.deleteExpand = exports.createExpandNode = void 0;
7
+ exports.updateExpandTitle = exports.toggleExpandExpanded = exports.setSelectionInsideExpand = exports.insertExpand = exports.focusTitle = 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 _expand = require("@atlaskit/editor-common/expand");
12
+ var _selection = require("@atlaskit/editor-common/selection");
11
13
  var _transforms = require("@atlaskit/editor-common/transforms");
12
14
  var _utils = require("@atlaskit/editor-common/utils");
13
15
  var _state = require("@atlaskit/editor-prosemirror/state");
@@ -21,7 +23,9 @@ var createExpandNode = exports.createExpandNode = function createExpandNode(stat
21
23
  expand = _state$schema$nodes.expand,
22
24
  nestedExpand = _state$schema$nodes.nestedExpand;
23
25
  var expandType = (0, _utils3.findTable)(state.selection) ? nestedExpand : expand;
24
- return expandType.createAndFill({});
26
+ var expandNode = expandType.createAndFill({});
27
+ _expand.expandedState.set(expandNode, true);
28
+ return expandNode;
25
29
  };
26
30
  var insertExpand = exports.insertExpand = function insertExpand(editorAnalyticsAPI) {
27
31
  return function (state, dispatch) {
@@ -99,10 +103,47 @@ var setSelectionInsideExpand = exports.setSelectionInsideExpand = function setSe
99
103
  return false;
100
104
  };
101
105
  };
102
- var updateExpandTitle = exports.updateExpandTitle = function updateExpandTitle(_ref) {
103
- var title = _ref.title,
104
- nodeType = _ref.nodeType,
105
- pos = _ref.pos;
106
+ var toggleExpandExpanded = exports.toggleExpandExpanded = function toggleExpandExpanded(_ref) {
107
+ var editorAnalyticsAPI = _ref.editorAnalyticsAPI,
108
+ pos = _ref.pos,
109
+ node = _ref.node;
110
+ return function (state, dispatch) {
111
+ if (node && dispatch) {
112
+ var _expandedState$get;
113
+ var tr = state.tr;
114
+ var expanded = (_expandedState$get = _expand.expandedState.get(node)) !== null && _expandedState$get !== void 0 ? _expandedState$get : false;
115
+ var isExpandedNext = !expanded;
116
+ _expand.expandedState.set(node, isExpandedNext);
117
+
118
+ // If we're going to collapse the expand and our cursor is currently inside
119
+ // Move to a right gap cursor, if the toolbar is interacted (or an API),
120
+ // it will insert below rather than inside (which will be invisible).
121
+ if (isExpandedNext === true) {
122
+ tr.setSelection(new _selection.GapCursorSelection(tr.doc.resolve(pos + node.nodeSize), _selection.Side.RIGHT));
123
+ }
124
+
125
+ // log when people open/close expands
126
+ // TODO: ED-8523 make platform/mode global attributes?
127
+ var payload = {
128
+ action: _analytics.ACTION.TOGGLE_EXPAND,
129
+ actionSubject: node.type === state.schema.nodes.expand ? _analytics.ACTION_SUBJECT.EXPAND : _analytics.ACTION_SUBJECT.NESTED_EXPAND,
130
+ attributes: {
131
+ platform: _analytics.PLATFORMS.WEB,
132
+ mode: _analytics.MODE.EDITOR,
133
+ expanded: isExpandedNext
134
+ },
135
+ eventType: _analytics.EVENT_TYPE.TRACK
136
+ };
137
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(payload)(tr);
138
+ dispatch(tr);
139
+ }
140
+ return true;
141
+ };
142
+ };
143
+ var updateExpandTitle = exports.updateExpandTitle = function updateExpandTitle(_ref2) {
144
+ var title = _ref2.title,
145
+ nodeType = _ref2.nodeType,
146
+ pos = _ref2.pos;
106
147
  return function (state, dispatch) {
107
148
  var node = state.doc.nodeAt(pos);
108
149
  if (node && node.type === nodeType && dispatch) {
@@ -11,6 +11,7 @@ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/creat
11
11
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
12
12
  var _reactDom = _interopRequireDefault(require("react-dom"));
13
13
  var _w3cKeyname = require("w3c-keyname");
14
+ var _expand = require("@atlaskit/editor-common/expand");
14
15
  var _selection = require("@atlaskit/editor-common/selection");
15
16
  var _styles = require("@atlaskit/editor-common/styles");
16
17
  var _utils = require("@atlaskit/editor-common/utils");
@@ -28,6 +29,7 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
28
29
  (0, _defineProperty2.default)(this, "isMobile", false);
29
30
  (0, _defineProperty2.default)(this, "focusTitle", function () {
30
31
  if (_this.input) {
32
+ var _this$api;
31
33
  var _this$view = _this.view,
32
34
  state = _this$view.state,
33
35
  dispatch = _this$view.dispatch;
@@ -43,6 +45,7 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
43
45
  if (typeof pos === 'number') {
44
46
  (0, _commands.setSelectionInsideExpand)(pos)(state, dispatch, _this.view);
45
47
  }
48
+ _this.decorationCleanup = (_this$api = _this.api) === null || _this$api === void 0 || (_this$api = _this$api.selectionMarker) === null || _this$api === void 0 || (_this$api = _this$api.actions) === null || _this$api === void 0 ? void 0 : _this$api.hideDecoration();
46
49
  _this.input.focus();
47
50
  }
48
51
  });
@@ -65,6 +68,7 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
65
68
  }
66
69
  var target = event.target;
67
70
  if ((0, _utils.closestElement)(target, ".".concat(_styles.expandClassNames.icon))) {
71
+ var _this$api2;
68
72
  if (!_this.allowInteractiveExpand) {
69
73
  return;
70
74
  }
@@ -75,10 +79,12 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
75
79
  if (_this.view.dom instanceof HTMLElement) {
76
80
  _this.view.dom.blur();
77
81
  }
78
-
79
- // TODO https://product-fabric.atlassian.net/browse/ED-22841
80
- // call toggleExpandExpanded
81
-
82
+ (0, _commands.toggleExpandExpanded)({
83
+ editorAnalyticsAPI: (_this$api2 = _this.api) === null || _this$api2 === void 0 || (_this$api2 = _this$api2.analytics) === null || _this$api2 === void 0 ? void 0 : _this$api2.actions,
84
+ pos: pos,
85
+ node: _this.node
86
+ })(_this.view.state, _this.view.dispatch);
87
+ _this.updateExpandClassName();
82
88
  return;
83
89
  }
84
90
  if (target === _this.input) {
@@ -108,10 +114,14 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
108
114
  (0, _defineProperty2.default)(this, "handleFocus", function (event) {
109
115
  event.stopImmediatePropagation();
110
116
  });
117
+ (0, _defineProperty2.default)(this, "handleBlur", function (event) {
118
+ var _this$decorationClean;
119
+ (_this$decorationClean = _this.decorationCleanup) === null || _this$decorationClean === void 0 || _this$decorationClean.call(_this);
120
+ });
111
121
  (0, _defineProperty2.default)(this, "handleTitleKeydown", function (event) {
112
122
  switch ((0, _w3cKeyname.keyName)(event)) {
113
123
  case 'Enter':
114
- // TO-DO
124
+ _this.toggleExpand();
115
125
  break;
116
126
  case 'Tab':
117
127
  case 'ArrowDown':
@@ -144,15 +154,33 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
144
154
  return;
145
155
  }
146
156
  if (expandNode && (0, _utils.isEmptyNode)(state.schema)(expandNode)) {
147
- var _this$api;
148
- (0, _commands.deleteExpand)((_this$api = _this.api) === null || _this$api === void 0 || (_this$api = _this$api.analytics) === null || _this$api === void 0 ? void 0 : _this$api.actions)(state, _this.view.dispatch);
157
+ var _this$api3;
158
+ (0, _commands.deleteExpand)((_this$api3 = _this.api) === null || _this$api3 === void 0 || (_this$api3 = _this$api3.analytics) === null || _this$api3 === void 0 ? void 0 : _this$api3.actions)(state, _this.view.dispatch);
159
+ }
160
+ });
161
+ (0, _defineProperty2.default)(this, "toggleExpand", function () {
162
+ var pos = _this.getPos();
163
+ if (typeof pos !== 'number') {
164
+ return;
165
+ }
166
+ if (_this.allowInteractiveExpand) {
167
+ var _this$api4;
168
+ var _this$view3 = _this.view,
169
+ state = _this$view3.state,
170
+ dispatch = _this$view3.dispatch;
171
+ (0, _commands.toggleExpandExpanded)({
172
+ editorAnalyticsAPI: (_this$api4 = _this.api) === null || _this$api4 === void 0 || (_this$api4 = _this$api4.analytics) === null || _this$api4 === void 0 ? void 0 : _this$api4.actions,
173
+ pos: pos,
174
+ node: _this.node
175
+ })(state, dispatch);
176
+ _this.updateExpandClassName();
149
177
  }
150
178
  });
151
179
  (0, _defineProperty2.default)(this, "moveToOutsideOfTitle", function (event) {
152
180
  event.preventDefault();
153
- var _this$view3 = _this.view,
154
- state = _this$view3.state,
155
- dispatch = _this$view3.dispatch;
181
+ var _this$view4 = _this.view,
182
+ state = _this$view4.state,
183
+ dispatch = _this$view4.dispatch;
156
184
  var expandPos = _this.getPos();
157
185
  if (typeof expandPos !== 'number') {
158
186
  return;
@@ -176,9 +204,8 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
176
204
  dispatch(state.tr.setSelection(sel));
177
205
  }
178
206
  });
179
- // TODO: https://product-fabric.atlassian.net/browse/ED-22841
180
207
  (0, _defineProperty2.default)(this, "isCollapsed", function () {
181
- return false;
208
+ return !_expand.expandedState.get(_this.node);
182
209
  });
183
210
  (0, _defineProperty2.default)(this, "setRightGapCursor", function (event) {
184
211
  if (!_this.input) {
@@ -193,9 +220,9 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
193
220
  selectionStart = _this$input2.selectionStart,
194
221
  selectionEnd = _this$input2.selectionEnd;
195
222
  if (selectionStart === selectionEnd && selectionStart === value.length) {
196
- var _this$view4 = _this.view,
197
- state = _this$view4.state,
198
- dispatch = _this$view4.dispatch;
223
+ var _this$view5 = _this.view,
224
+ state = _this$view5.state,
225
+ dispatch = _this$view5.dispatch;
199
226
  event.preventDefault();
200
227
  _this.view.focus();
201
228
  dispatch(state.tr.setSelection(new _selection.GapCursorSelection(state.doc.resolve(_this.node.nodeSize + pos), _selection.Side.RIGHT)));
@@ -214,9 +241,9 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
214
241
  selectionEnd = _this$input3.selectionEnd;
215
242
  if (selectionStart === selectionEnd && selectionStart === 0) {
216
243
  event.preventDefault();
217
- var _this$view5 = _this.view,
218
- state = _this$view5.state,
219
- dispatch = _this$view5.dispatch;
244
+ var _this$view6 = _this.view,
245
+ state = _this$view6.state,
246
+ dispatch = _this$view6.dispatch;
220
247
  _this.view.focus();
221
248
  dispatch(state.tr.setSelection(new _selection.GapCursorSelection(state.doc.resolve(pos), _selection.Side.LEFT)));
222
249
  }
@@ -235,9 +262,9 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
235
262
  selectionEnd = _this$input4.selectionEnd;
236
263
  if (selectionStart === selectionEnd && selectionStart === value.length) {
237
264
  event.preventDefault();
238
- var _this$view6 = _this.view,
239
- state = _this$view6.state,
240
- dispatch = _this$view6.dispatch;
265
+ var _this$view7 = _this.view,
266
+ state = _this$view7.state,
267
+ dispatch = _this$view7.dispatch;
241
268
  _this.view.focus();
242
269
  var tr = _this.selectNearNode({
243
270
  selectionRelativeToNode: _selection.RelativeSelectionPos.End,
@@ -260,13 +287,13 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
260
287
  selectionStart = _this$input5.selectionStart,
261
288
  selectionEnd = _this$input5.selectionEnd;
262
289
  if (selectionStart === selectionEnd && selectionStart === 0) {
263
- var _this$api2;
290
+ var _this$api5;
264
291
  event.preventDefault();
265
- var _this$view7 = _this.view,
266
- state = _this$view7.state,
267
- dispatch = _this$view7.dispatch;
292
+ var _this$view8 = _this.view,
293
+ state = _this$view8.state,
294
+ dispatch = _this$view8.dispatch;
268
295
  _this.view.focus();
269
- var selectionSharedState = ((_this$api2 = _this.api) === null || _this$api2 === void 0 || (_this$api2 = _this$api2.selection) === null || _this$api2 === void 0 ? void 0 : _this$api2.sharedState.currentState()) || {};
296
+ var selectionSharedState = ((_this$api5 = _this.api) === null || _this$api5 === void 0 || (_this$api5 = _this$api5.selection) === null || _this$api5 === void 0 ? void 0 : _this$api5.sharedState.currentState()) || {};
270
297
  // selectionRelativeToNode is undefined when user clicked to select node, then hit left to get focus in title
271
298
  // This is a special case where we want to bypass node selection and jump straight to gap cursor
272
299
  if ((selectionSharedState === null || selectionSharedState === void 0 ? void 0 : selectionSharedState.selectionRelativeToNode) === undefined) {
@@ -291,13 +318,13 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
291
318
  this.selectNearNode = selectNearNode;
292
319
  this.__livePage = __livePage;
293
320
  this.intl = getIntl();
294
- var _DOMSerializer$render = _model.DOMSerializer.renderSpec(document, (0, _NodeView.toDOM)(node, this.__livePage, this.intl)),
295
- dom = _DOMSerializer$render.dom,
296
- contentDOM = _DOMSerializer$render.contentDOM;
297
321
  this.allowInteractiveExpand = allowInteractiveExpand;
298
322
  this.getPos = getPos;
299
323
  this.view = view;
300
324
  this.node = node;
325
+ var _DOMSerializer$render = _model.DOMSerializer.renderSpec(document, (0, _NodeView.toDOM)(node, this.__livePage, this.intl)),
326
+ dom = _DOMSerializer$render.dom,
327
+ contentDOM = _DOMSerializer$render.contentDOM;
301
328
  this.dom = dom;
302
329
  this.contentDOM = contentDOM;
303
330
  this.isMobile = isMobile;
@@ -306,6 +333,9 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
306
333
  this.input = this.dom.querySelector(".".concat(_styles.expandClassNames.titleInput));
307
334
  this.titleContainer = this.dom.querySelector(".".concat(_styles.expandClassNames.titleContainer));
308
335
  (0, _NodeView.renderIcon)(this.icon, this.allowInteractiveExpand, this.intl);
336
+ if (!_expand.expandedState.has(this.node)) {
337
+ _expand.expandedState.set(this.node, false);
338
+ }
309
339
  if (!this.input || !this.titleContainer || !this.icon) {
310
340
  return;
311
341
  }
@@ -315,6 +345,7 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
315
345
  this.dom.addEventListener('click', this.handleClick);
316
346
  this.dom.addEventListener('input', this.handleInput);
317
347
  this.input.addEventListener('keydown', this.handleTitleKeydown);
348
+ this.input.addEventListener('blur', this.handleBlur);
318
349
  // If the user interacts in our title bar (either toggle or input)
319
350
  // Prevent ProseMirror from getting a focus event (causes weird selection issues).
320
351
  this.titleContainer.addEventListener('focus', this.handleFocus);
@@ -344,9 +375,6 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
344
375
  value: function update(node, _decorations) {
345
376
  var _this2 = this;
346
377
  if (this.node.type === node.type) {
347
- // TODO: https://product-fabric.atlassian.net/browse/ED-22841
348
- // Handle toggling of the expand on update here
349
-
350
378
  // During a collab session the title doesn't sync with other users
351
379
  // since we're intentionally being less aggressive about re-rendering.
352
380
  // We also apply a rAF to avoid abrupt continuous replacement of the title.
@@ -355,23 +383,43 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
355
383
  _this2.input.value = _this2.node.attrs.title;
356
384
  }
357
385
  });
386
+ if (this.node !== node) {
387
+ var previousExpandedState = _expand.expandedState.get(this.node);
388
+ if (previousExpandedState === undefined) {
389
+ previousExpandedState = true;
390
+ }
391
+ _expand.expandedState.set(node, previousExpandedState);
392
+ _expand.expandedState.delete(this.node);
393
+ }
358
394
  this.node = node;
359
395
  return true;
360
396
  }
361
397
  return false;
362
398
  }
399
+ }, {
400
+ key: "updateExpandClassName",
401
+ value: function updateExpandClassName() {
402
+ var expanded = _expand.expandedState.get(this.node) ? _expand.expandedState.get(this.node) : false;
403
+ if (this.dom && expanded !== undefined) {
404
+ this.dom.className = (0, _NodeView.buildExpandClassName)(this.node.type.name, expanded);
405
+ }
406
+ }
363
407
  }, {
364
408
  key: "destroy",
365
409
  value: function destroy() {
410
+ var _this$decorationClean2;
366
411
  if (!this.dom || !this.input || !this.titleContainer || !this.icon) {
367
412
  return;
368
413
  }
369
414
  this.dom.removeEventListener('click', this.handleClick);
370
415
  this.dom.removeEventListener('input', this.handleInput);
371
416
  this.input.removeEventListener('keydown', this.handleTitleKeydown);
417
+ this.input.removeEventListener('blur', this.handleBlur);
372
418
  this.titleContainer.removeEventListener('focus', this.handleFocus);
373
419
  this.icon.removeEventListener('keydown', this.handleIconKeyDown);
420
+ (_this$decorationClean2 = this.decorationCleanup) === null || _this$decorationClean2 === void 0 || _this$decorationClean2.call(this);
374
421
  _reactDom.default.unmountComponentAtNode(this.icon);
422
+ _expand.expandedState.delete(this.node);
375
423
  }
376
424
  }]);
377
425
  return ExpandNodeView;
@@ -24,7 +24,8 @@ function expandKeymap(api, options) {
24
24
  schema = state.schema;
25
25
  var nodeBefore = selection.$from.nodeBefore;
26
26
  if (selection instanceof _selection.GapCursorSelection && selection.side === _selection.Side.RIGHT && nodeBefore && (nodeBefore.type === schema.nodes.expand || nodeBefore.type === schema.nodes.nestedExpand)
27
- // TO-DO: add back in expanded logic
27
+ // https://product-fabric.atlassian.net/browse/ED-22991
28
+ // TODO: add back in expanded logic
28
29
  ) {
29
30
  var _$from = selection.$from;
30
31
  return (0, _commands.focusTitle)(Math.max(_$from.pos - 1, 0))(state, dispatch, editorView);
@@ -50,7 +51,8 @@ function expandKeymap(api, options) {
50
51
  if (sel && expandBefore) {
51
52
  // moving cursor from outside of an expand to the title when it is collapsed
52
53
 
53
- // TO-DO: Bring back expanded logic
54
+ // https://product-fabric.atlassian.net/browse/ED-22991
55
+ // TODO: add back in expanded logic
54
56
  return (0, _commands.focusTitle)(expandBefore.start)(state, dispatch, editorView);
55
57
  }
56
58
  }
@@ -66,7 +68,8 @@ function expandKeymap(api, options) {
66
68
  var selection = state.selection;
67
69
  var nodeAfter = selection.$from.nodeAfter;
68
70
  if (selection instanceof _selection.GapCursorSelection && selection.side === _selection.Side.LEFT && nodeAfter && (nodeAfter.type === expand || nodeAfter.type === nestedExpand)
69
- // TO-DO: Bring back expanded logic
71
+ // https://product-fabric.atlassian.net/browse/ED-22991
72
+ // TODO: add back in expanded logic
70
73
  ) {
71
74
  var $from = selection.$from;
72
75
  return (0, _commands.focusTitle)($from.pos + 1)(state, dispatch, editorView);
@@ -98,7 +101,8 @@ function expandKeymap(api, options) {
98
101
  var sel = _state.Selection.findFrom(state.doc.resolve(Math.max(selection.$from.pos - 1, 0)), -1);
99
102
  var expandBefore = (0, _transforms.findExpand)(state, sel);
100
103
  if (expandBefore && (expandBefore.node.type === expand || expandBefore.node.type === nestedExpand)
101
- // TO-DO: Bring back expanded logic
104
+ // https://product-fabric.atlassian.net/browse/ED-22991
105
+ // TODO: add back in expanded logic
102
106
  ) {
103
107
  return (0, _commands.focusTitle)(expandBefore.start)(state, dispatch, editorView);
104
108
  }
@@ -7,17 +7,18 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.toDOM = exports.renderIcon = exports.buildExpandClassName = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _reactDom = _interopRequireDefault(require("react-dom"));
10
+ var _expand = require("@atlaskit/editor-common/expand");
10
11
  var _styles = require("@atlaskit/editor-common/styles");
11
12
  var _ui = require("@atlaskit/editor-common/ui");
12
13
  var _ExpandButton = require("../ui/ExpandButton");
13
- // TODO: https://product-fabric.atlassian.net/browse/ED-22841
14
- var buildExpandClassName = exports.buildExpandClassName = function buildExpandClassName(type) {
15
- return "".concat(_styles.expandClassNames.prefix, " ").concat(_styles.expandClassNames.type(type), "\n ").concat(_styles.expandClassNames.expanded);
14
+ var buildExpandClassName = exports.buildExpandClassName = function buildExpandClassName(type, expanded) {
15
+ return "".concat(_styles.expandClassNames.prefix, " ").concat(_styles.expandClassNames.type(type), " ").concat(expanded ? _styles.expandClassNames.expanded : '');
16
16
  };
17
17
  var toDOM = exports.toDOM = function toDOM(node, __livePage, intl) {
18
+ var _expandedState$get;
18
19
  return ['div', {
19
20
  // prettier-ignore
20
- 'class': buildExpandClassName(node.type.name),
21
+ 'class': buildExpandClassName(node.type.name, (_expandedState$get = _expand.expandedState.get(node)) !== null && _expandedState$get !== void 0 ? _expandedState$get : false),
21
22
  'data-node-type': node.type.name,
22
23
  'data-title': node.attrs.title
23
24
  }, ['div', {
@@ -39,7 +40,7 @@ var toDOM = exports.toDOM = function toDOM(node, __livePage, intl) {
39
40
  // prettier-ignore
40
41
  'class': _styles.expandClassNames.titleInput,
41
42
  value: node.attrs.title,
42
- placeholder: intl && intl.formatMessage(_ui.expandMessages.expandPlaceholderText) || _ui.expandMessages.expandPlaceholderText.defaultMessage,
43
+ placeholder: intl && typeof intl.formatMessage === 'function' && intl.formatMessage(_ui.expandMessages.expandPlaceholderText) || _ui.expandMessages.expandPlaceholderText.defaultMessage,
43
44
  type: 'text'
44
45
  }]]],
45
46
  // prettier-ignore
@@ -51,9 +52,13 @@ var renderIcon = exports.renderIcon = function renderIcon(icon, allowInteractive
51
52
  if (!icon) {
52
53
  return;
53
54
  }
55
+ var expanded = node ? _expand.expandedState.get(node) : true;
56
+ if (expanded === undefined) {
57
+ expanded = false;
58
+ }
54
59
  _reactDom.default.render( /*#__PURE__*/_react.default.createElement(_ExpandButton.ExpandButton, {
55
60
  intl: intl,
56
61
  allowInteractiveExpand: allowInteractiveExpand,
57
- expanded: true // TO-DO https://product-fabric.atlassian.net/browse/ED-22841
62
+ expanded: expanded
58
63
  }), icon);
59
64
  };