@atlaskit/editor-plugin-expand 1.4.0 → 1.4.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.
Files changed (25) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/legacyExpand/nodeviews/index.js +11 -5
  3. package/dist/cjs/singlePlayerExpand/commands.js +47 -6
  4. package/dist/cjs/singlePlayerExpand/node-views/index.js +77 -35
  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 +11 -5
  8. package/dist/es2019/singlePlayerExpand/commands.js +44 -2
  9. package/dist/es2019/singlePlayerExpand/node-views/index.js +64 -23
  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 +11 -5
  13. package/dist/esm/singlePlayerExpand/commands.js +47 -6
  14. package/dist/esm/singlePlayerExpand/node-views/index.js +79 -37
  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 +1 -0
  18. package/dist/types/singlePlayerExpand/commands.d.ts +5 -0
  19. package/dist/types/singlePlayerExpand/node-views/index.d.ts +3 -0
  20. package/dist/types/singlePlayerExpand/ui/NodeView.d.ts +1 -1
  21. package/dist/types-ts4.5/legacyExpand/nodeviews/index.d.ts +1 -0
  22. package/dist/types-ts4.5/singlePlayerExpand/commands.d.ts +5 -0
  23. package/dist/types-ts4.5/singlePlayerExpand/node-views/index.d.ts +3 -0
  24. package/dist/types-ts4.5/singlePlayerExpand/ui/NodeView.d.ts +1 -1
  25. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/editor-plugin-expand
2
2
 
3
+ ## 1.4.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#91886](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/91886) [`5c0443e007d9`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/5c0443e007d9) - [ux] Fix bug where selection marker shows when focussing on the expand title with the keyboard.
8
+
9
+ ## 1.4.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [#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.
14
+
3
15
  ## 1.4.0
4
16
 
5
17
  ### Minor Changes
@@ -67,7 +67,6 @@ 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;
71
70
  var _this$view = _this.view,
72
71
  state = _this$view.state,
73
72
  dispatch = _this$view.dispatch;
@@ -83,7 +82,6 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
83
82
  if (typeof pos === 'number') {
84
83
  (0, _commands.setSelectionInsideExpand)(pos)(state, dispatch, _this.view);
85
84
  }
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();
87
85
  _this.input.focus();
88
86
  }
89
87
  });
@@ -109,7 +107,7 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
109
107
  state = _this$view2.state,
110
108
  dispatch = _this$view2.dispatch;
111
109
  if ((0, _utils.closestElement)(target, ".".concat(_styles.expandClassNames.icon))) {
112
- var _this$api2;
110
+ var _this$api;
113
111
  if (!_this.allowInteractiveExpand) {
114
112
  return;
115
113
  }
@@ -121,7 +119,7 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
121
119
  _this.view.dom.blur();
122
120
  }
123
121
  (0, _commands.toggleExpandExpanded)({
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,
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,
125
123
  pos: pos,
126
124
  nodeType: _this.node.type,
127
125
  __livePage: _this.__livePage
@@ -156,7 +154,11 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
156
154
  (0, _defineProperty2.default)(this, "handleFocus", function (event) {
157
155
  event.stopImmediatePropagation();
158
156
  });
159
- (0, _defineProperty2.default)(this, "handleBlur", function (event) {
157
+ (0, _defineProperty2.default)(this, "handleInputFocus", function () {
158
+ var _this$api2;
159
+ _this.decorationCleanup = (_this$api2 = _this.api) === null || _this$api2 === void 0 || (_this$api2 = _this$api2.selectionMarker) === null || _this$api2 === void 0 || (_this$api2 = _this$api2.actions) === null || _this$api2 === void 0 ? void 0 : _this$api2.hideDecoration();
160
+ });
161
+ (0, _defineProperty2.default)(this, "handleBlur", function () {
160
162
  var _this$decorationClean;
161
163
  (_this$decorationClean = _this.decorationCleanup) === null || _this$decorationClean === void 0 || _this$decorationClean.call(_this);
162
164
  });
@@ -399,6 +401,8 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
399
401
  this.input.addEventListener('keydown', this.handleTitleKeydown);
400
402
  // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
401
403
  this.input.addEventListener('blur', this.handleBlur);
404
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
405
+ this.input.addEventListener('focus', this.handleInputFocus);
402
406
  }
403
407
  if (this.titleContainer) {
404
408
  // If the user interacts in our title bar (either toggle or input)
@@ -490,6 +494,8 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
490
494
  this.input.removeEventListener('keydown', this.handleTitleKeydown);
491
495
  // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
492
496
  this.input.removeEventListener('blur', this.handleBlur);
497
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
498
+ this.input.removeEventListener('focus', this.handleInputFocus);
493
499
  }
494
500
  if (this.titleContainer) {
495
501
  // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
@@ -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,7 +29,6 @@ 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) {
31
- var _this$api;
32
32
  var _this$view = _this.view,
33
33
  state = _this$view.state,
34
34
  dispatch = _this$view.dispatch;
@@ -44,7 +44,6 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
44
44
  if (typeof pos === 'number') {
45
45
  (0, _commands.setSelectionInsideExpand)(pos)(state, dispatch, _this.view);
46
46
  }
47
- _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();
48
47
  _this.input.focus();
49
48
  }
50
49
  });
@@ -67,6 +66,7 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
67
66
  }
68
67
  var target = event.target;
69
68
  if ((0, _utils.closestElement)(target, ".".concat(_styles.expandClassNames.icon))) {
69
+ var _this$api;
70
70
  if (!_this.allowInteractiveExpand) {
71
71
  return;
72
72
  }
@@ -77,10 +77,12 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
77
77
  if (_this.view.dom instanceof HTMLElement) {
78
78
  _this.view.dom.blur();
79
79
  }
80
-
81
- // TODO https://product-fabric.atlassian.net/browse/ED-22841
82
- // call toggleExpandExpanded
83
-
80
+ (0, _commands.toggleExpandExpanded)({
81
+ 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,
82
+ pos: pos,
83
+ node: _this.node
84
+ })(_this.view.state, _this.view.dispatch);
85
+ _this.updateExpandClassName();
84
86
  return;
85
87
  }
86
88
  if (target === _this.input) {
@@ -110,14 +112,18 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
110
112
  (0, _defineProperty2.default)(this, "handleFocus", function (event) {
111
113
  event.stopImmediatePropagation();
112
114
  });
113
- (0, _defineProperty2.default)(this, "handleBlur", function (event) {
115
+ (0, _defineProperty2.default)(this, "handleInputFocus", function () {
116
+ var _this$api2;
117
+ _this.decorationCleanup = (_this$api2 = _this.api) === null || _this$api2 === void 0 || (_this$api2 = _this$api2.selectionMarker) === null || _this$api2 === void 0 || (_this$api2 = _this$api2.actions) === null || _this$api2 === void 0 ? void 0 : _this$api2.hideDecoration();
118
+ });
119
+ (0, _defineProperty2.default)(this, "handleBlur", function () {
114
120
  var _this$decorationClean;
115
121
  (_this$decorationClean = _this.decorationCleanup) === null || _this$decorationClean === void 0 || _this$decorationClean.call(_this);
116
122
  });
117
123
  (0, _defineProperty2.default)(this, "handleTitleKeydown", function (event) {
118
124
  switch ((0, _w3cKeyname.keyName)(event)) {
119
125
  case 'Enter':
120
- // TO-DO
126
+ _this.toggleExpand();
121
127
  break;
122
128
  case 'Tab':
123
129
  case 'ArrowDown':
@@ -150,15 +156,33 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
150
156
  return;
151
157
  }
152
158
  if (expandNode && (0, _utils.isEmptyNode)(state.schema)(expandNode)) {
153
- var _this$api2;
154
- (0, _commands.deleteExpand)((_this$api2 = _this.api) === null || _this$api2 === void 0 || (_this$api2 = _this$api2.analytics) === null || _this$api2 === void 0 ? void 0 : _this$api2.actions)(state, _this.view.dispatch);
159
+ var _this$api3;
160
+ (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);
161
+ }
162
+ });
163
+ (0, _defineProperty2.default)(this, "toggleExpand", function () {
164
+ var pos = _this.getPos();
165
+ if (typeof pos !== 'number') {
166
+ return;
167
+ }
168
+ if (_this.allowInteractiveExpand) {
169
+ var _this$api4;
170
+ var _this$view3 = _this.view,
171
+ state = _this$view3.state,
172
+ dispatch = _this$view3.dispatch;
173
+ (0, _commands.toggleExpandExpanded)({
174
+ 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,
175
+ pos: pos,
176
+ node: _this.node
177
+ })(state, dispatch);
178
+ _this.updateExpandClassName();
155
179
  }
156
180
  });
157
181
  (0, _defineProperty2.default)(this, "moveToOutsideOfTitle", function (event) {
158
182
  event.preventDefault();
159
- var _this$view3 = _this.view,
160
- state = _this$view3.state,
161
- dispatch = _this$view3.dispatch;
183
+ var _this$view4 = _this.view,
184
+ state = _this$view4.state,
185
+ dispatch = _this$view4.dispatch;
162
186
  var expandPos = _this.getPos();
163
187
  if (typeof expandPos !== 'number') {
164
188
  return;
@@ -182,9 +206,8 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
182
206
  dispatch(state.tr.setSelection(sel));
183
207
  }
184
208
  });
185
- // TODO: https://product-fabric.atlassian.net/browse/ED-22841
186
209
  (0, _defineProperty2.default)(this, "isCollapsed", function () {
187
- return false;
210
+ return !_expand.expandedState.get(_this.node);
188
211
  });
189
212
  (0, _defineProperty2.default)(this, "setRightGapCursor", function (event) {
190
213
  if (!_this.input) {
@@ -199,9 +222,9 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
199
222
  selectionStart = _this$input2.selectionStart,
200
223
  selectionEnd = _this$input2.selectionEnd;
201
224
  if (selectionStart === selectionEnd && selectionStart === value.length) {
202
- var _this$view4 = _this.view,
203
- state = _this$view4.state,
204
- dispatch = _this$view4.dispatch;
225
+ var _this$view5 = _this.view,
226
+ state = _this$view5.state,
227
+ dispatch = _this$view5.dispatch;
205
228
  event.preventDefault();
206
229
  _this.view.focus();
207
230
  dispatch(state.tr.setSelection(new _selection.GapCursorSelection(state.doc.resolve(_this.node.nodeSize + pos), _selection.Side.RIGHT)));
@@ -220,9 +243,9 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
220
243
  selectionEnd = _this$input3.selectionEnd;
221
244
  if (selectionStart === selectionEnd && selectionStart === 0) {
222
245
  event.preventDefault();
223
- var _this$view5 = _this.view,
224
- state = _this$view5.state,
225
- dispatch = _this$view5.dispatch;
246
+ var _this$view6 = _this.view,
247
+ state = _this$view6.state,
248
+ dispatch = _this$view6.dispatch;
226
249
  _this.view.focus();
227
250
  dispatch(state.tr.setSelection(new _selection.GapCursorSelection(state.doc.resolve(pos), _selection.Side.LEFT)));
228
251
  }
@@ -241,9 +264,9 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
241
264
  selectionEnd = _this$input4.selectionEnd;
242
265
  if (selectionStart === selectionEnd && selectionStart === value.length) {
243
266
  event.preventDefault();
244
- var _this$view6 = _this.view,
245
- state = _this$view6.state,
246
- dispatch = _this$view6.dispatch;
267
+ var _this$view7 = _this.view,
268
+ state = _this$view7.state,
269
+ dispatch = _this$view7.dispatch;
247
270
  _this.view.focus();
248
271
  var tr = _this.selectNearNode({
249
272
  selectionRelativeToNode: _selection.RelativeSelectionPos.End,
@@ -266,13 +289,13 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
266
289
  selectionStart = _this$input5.selectionStart,
267
290
  selectionEnd = _this$input5.selectionEnd;
268
291
  if (selectionStart === selectionEnd && selectionStart === 0) {
269
- var _this$api3;
292
+ var _this$api5;
270
293
  event.preventDefault();
271
- var _this$view7 = _this.view,
272
- state = _this$view7.state,
273
- dispatch = _this$view7.dispatch;
294
+ var _this$view8 = _this.view,
295
+ state = _this$view8.state,
296
+ dispatch = _this$view8.dispatch;
274
297
  _this.view.focus();
275
- var selectionSharedState = ((_this$api3 = _this.api) === null || _this$api3 === void 0 || (_this$api3 = _this$api3.selection) === null || _this$api3 === void 0 ? void 0 : _this$api3.sharedState.currentState()) || {};
298
+ 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()) || {};
276
299
  // selectionRelativeToNode is undefined when user clicked to select node, then hit left to get focus in title
277
300
  // This is a special case where we want to bypass node selection and jump straight to gap cursor
278
301
  if ((selectionSharedState === null || selectionSharedState === void 0 ? void 0 : selectionSharedState.selectionRelativeToNode) === undefined) {
@@ -297,13 +320,13 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
297
320
  this.selectNearNode = selectNearNode;
298
321
  this.__livePage = __livePage;
299
322
  this.intl = getIntl();
300
- var _DOMSerializer$render = _model.DOMSerializer.renderSpec(document, (0, _NodeView.toDOM)(node, this.__livePage, this.intl)),
301
- dom = _DOMSerializer$render.dom,
302
- contentDOM = _DOMSerializer$render.contentDOM;
303
323
  this.allowInteractiveExpand = allowInteractiveExpand;
304
324
  this.getPos = getPos;
305
325
  this.view = view;
306
326
  this.node = node;
327
+ var _DOMSerializer$render = _model.DOMSerializer.renderSpec(document, (0, _NodeView.toDOM)(node, this.__livePage, this.intl)),
328
+ dom = _DOMSerializer$render.dom,
329
+ contentDOM = _DOMSerializer$render.contentDOM;
307
330
  this.dom = dom;
308
331
  this.contentDOM = contentDOM;
309
332
  this.isMobile = isMobile;
@@ -312,6 +335,9 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
312
335
  this.input = this.dom.querySelector(".".concat(_styles.expandClassNames.titleInput));
313
336
  this.titleContainer = this.dom.querySelector(".".concat(_styles.expandClassNames.titleContainer));
314
337
  (0, _NodeView.renderIcon)(this.icon, this.allowInteractiveExpand, this.intl);
338
+ if (!_expand.expandedState.has(this.node)) {
339
+ _expand.expandedState.set(this.node, false);
340
+ }
315
341
  if (!this.input || !this.titleContainer || !this.icon) {
316
342
  return;
317
343
  }
@@ -322,6 +348,7 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
322
348
  this.dom.addEventListener('input', this.handleInput);
323
349
  this.input.addEventListener('keydown', this.handleTitleKeydown);
324
350
  this.input.addEventListener('blur', this.handleBlur);
351
+ this.input.addEventListener('focus', this.handleInputFocus);
325
352
  // If the user interacts in our title bar (either toggle or input)
326
353
  // Prevent ProseMirror from getting a focus event (causes weird selection issues).
327
354
  this.titleContainer.addEventListener('focus', this.handleFocus);
@@ -351,9 +378,6 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
351
378
  value: function update(node, _decorations) {
352
379
  var _this2 = this;
353
380
  if (this.node.type === node.type) {
354
- // TODO: https://product-fabric.atlassian.net/browse/ED-22841
355
- // Handle toggling of the expand on update here
356
-
357
381
  // During a collab session the title doesn't sync with other users
358
382
  // since we're intentionally being less aggressive about re-rendering.
359
383
  // We also apply a rAF to avoid abrupt continuous replacement of the title.
@@ -362,11 +386,27 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
362
386
  _this2.input.value = _this2.node.attrs.title;
363
387
  }
364
388
  });
389
+ if (this.node !== node) {
390
+ var previousExpandedState = _expand.expandedState.get(this.node);
391
+ if (previousExpandedState === undefined) {
392
+ previousExpandedState = true;
393
+ }
394
+ _expand.expandedState.set(node, previousExpandedState);
395
+ _expand.expandedState.delete(this.node);
396
+ }
365
397
  this.node = node;
366
398
  return true;
367
399
  }
368
400
  return false;
369
401
  }
402
+ }, {
403
+ key: "updateExpandClassName",
404
+ value: function updateExpandClassName() {
405
+ var expanded = _expand.expandedState.get(this.node) ? _expand.expandedState.get(this.node) : false;
406
+ if (this.dom && expanded !== undefined) {
407
+ this.dom.className = (0, _NodeView.buildExpandClassName)(this.node.type.name, expanded);
408
+ }
409
+ }
370
410
  }, {
371
411
  key: "destroy",
372
412
  value: function destroy() {
@@ -378,10 +418,12 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
378
418
  this.dom.removeEventListener('input', this.handleInput);
379
419
  this.input.removeEventListener('keydown', this.handleTitleKeydown);
380
420
  this.input.removeEventListener('blur', this.handleBlur);
421
+ this.input.removeEventListener('focus', this.handleInputFocus);
381
422
  this.titleContainer.removeEventListener('focus', this.handleFocus);
382
423
  this.icon.removeEventListener('keydown', this.handleIconKeyDown);
383
424
  (_this$decorationClean2 = this.decorationCleanup) === null || _this$decorationClean2 === void 0 || _this$decorationClean2.call(this);
384
425
  _reactDom.default.unmountComponentAtNode(this.icon);
426
+ _expand.expandedState.delete(this.node);
385
427
  }
386
428
  }]);
387
429
  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
  };
@@ -51,7 +51,6 @@ export class ExpandNodeView {
51
51
  _defineProperty(this, "isMobile", false);
52
52
  _defineProperty(this, "focusTitle", () => {
53
53
  if (this.input) {
54
- var _this$api, _this$api$selectionMa, _this$api$selectionMa2;
55
54
  const {
56
55
  state,
57
56
  dispatch
@@ -68,7 +67,6 @@ export class ExpandNodeView {
68
67
  if (typeof pos === 'number') {
69
68
  setSelectionInsideExpand(pos)(state, dispatch, this.view);
70
69
  }
71
- this.decorationCleanup = (_this$api = this.api) === null || _this$api === void 0 ? void 0 : (_this$api$selectionMa = _this$api.selectionMarker) === null || _this$api$selectionMa === void 0 ? void 0 : (_this$api$selectionMa2 = _this$api$selectionMa.actions) === null || _this$api$selectionMa2 === void 0 ? void 0 : _this$api$selectionMa2.hideDecoration();
72
70
  this.input.focus();
73
71
  }
74
72
  });
@@ -95,7 +93,7 @@ export class ExpandNodeView {
95
93
  dispatch
96
94
  } = this.view;
97
95
  if (closestElement(target, `.${expandClassNames.icon}`)) {
98
- var _this$api2, _this$api2$analytics;
96
+ var _this$api, _this$api$analytics;
99
97
  if (!this.allowInteractiveExpand) {
100
98
  return;
101
99
  }
@@ -107,7 +105,7 @@ export class ExpandNodeView {
107
105
  this.view.dom.blur();
108
106
  }
109
107
  toggleExpandExpanded({
110
- editorAnalyticsAPI: (_this$api2 = this.api) === null || _this$api2 === void 0 ? void 0 : (_this$api2$analytics = _this$api2.analytics) === null || _this$api2$analytics === void 0 ? void 0 : _this$api2$analytics.actions,
108
+ editorAnalyticsAPI: (_this$api = this.api) === null || _this$api === void 0 ? void 0 : (_this$api$analytics = _this$api.analytics) === null || _this$api$analytics === void 0 ? void 0 : _this$api$analytics.actions,
111
109
  pos,
112
110
  nodeType: this.node.type,
113
111
  __livePage: this.__livePage
@@ -143,7 +141,11 @@ export class ExpandNodeView {
143
141
  _defineProperty(this, "handleFocus", event => {
144
142
  event.stopImmediatePropagation();
145
143
  });
146
- _defineProperty(this, "handleBlur", event => {
144
+ _defineProperty(this, "handleInputFocus", () => {
145
+ var _this$api2, _this$api2$selectionM, _this$api2$selectionM2;
146
+ this.decorationCleanup = (_this$api2 = this.api) === null || _this$api2 === void 0 ? void 0 : (_this$api2$selectionM = _this$api2.selectionMarker) === null || _this$api2$selectionM === void 0 ? void 0 : (_this$api2$selectionM2 = _this$api2$selectionM.actions) === null || _this$api2$selectionM2 === void 0 ? void 0 : _this$api2$selectionM2.hideDecoration();
147
+ });
148
+ _defineProperty(this, "handleBlur", () => {
147
149
  var _this$decorationClean;
148
150
  (_this$decorationClean = this.decorationCleanup) === null || _this$decorationClean === void 0 ? void 0 : _this$decorationClean.call(this);
149
151
  });
@@ -398,6 +400,8 @@ export class ExpandNodeView {
398
400
  this.input.addEventListener('keydown', this.handleTitleKeydown);
399
401
  // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
400
402
  this.input.addEventListener('blur', this.handleBlur);
403
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
404
+ this.input.addEventListener('focus', this.handleInputFocus);
401
405
  }
402
406
  if (this.titleContainer) {
403
407
  // If the user interacts in our title bar (either toggle or input)
@@ -479,6 +483,8 @@ export class ExpandNodeView {
479
483
  this.input.removeEventListener('keydown', this.handleTitleKeydown);
480
484
  // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
481
485
  this.input.removeEventListener('blur', this.handleBlur);
486
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
487
+ this.input.removeEventListener('focus', this.handleInputFocus);
482
488
  }
483
489
  if (this.titleContainer) {
484
490
  // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
@@ -1,5 +1,7 @@
1
1
  import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
2
- import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD, MODE, PLATFORMS } from '@atlaskit/editor-common/analytics';
3
+ import { expandedState } from '@atlaskit/editor-common/expand';
4
+ import { GapCursorSelection, Side } from '@atlaskit/editor-common/selection';
3
5
  import { findExpand } from '@atlaskit/editor-common/transforms';
4
6
  import { createWrapSelectionTransaction } from '@atlaskit/editor-common/utils';
5
7
  import { Selection } from '@atlaskit/editor-prosemirror/state';
@@ -13,7 +15,9 @@ export const createExpandNode = state => {
13
15
  nestedExpand
14
16
  } = state.schema.nodes;
15
17
  const expandType = findTable(state.selection) ? nestedExpand : expand;
16
- return expandType.createAndFill({});
18
+ const expandNode = expandType.createAndFill({});
19
+ expandedState.set(expandNode, true);
20
+ return expandNode;
17
21
  };
18
22
  export const insertExpand = editorAnalyticsAPI => (state, dispatch) => {
19
23
  const expandNode = createExpandNode(state);
@@ -83,6 +87,44 @@ export const setSelectionInsideExpand = expandPos => (state, dispatch, editorVie
83
87
  }
84
88
  return false;
85
89
  };
90
+ export const toggleExpandExpanded = ({
91
+ editorAnalyticsAPI,
92
+ pos,
93
+ node
94
+ }) => (state, dispatch) => {
95
+ if (node && dispatch) {
96
+ var _expandedState$get;
97
+ const {
98
+ tr
99
+ } = state;
100
+ const expanded = (_expandedState$get = expandedState.get(node)) !== null && _expandedState$get !== void 0 ? _expandedState$get : false;
101
+ const isExpandedNext = !expanded;
102
+ expandedState.set(node, isExpandedNext);
103
+
104
+ // If we're going to collapse the expand and our cursor is currently inside
105
+ // Move to a right gap cursor, if the toolbar is interacted (or an API),
106
+ // it will insert below rather than inside (which will be invisible).
107
+ if (isExpandedNext === true) {
108
+ tr.setSelection(new GapCursorSelection(tr.doc.resolve(pos + node.nodeSize), Side.RIGHT));
109
+ }
110
+
111
+ // log when people open/close expands
112
+ // TODO: ED-8523 make platform/mode global attributes?
113
+ const payload = {
114
+ action: ACTION.TOGGLE_EXPAND,
115
+ actionSubject: node.type === state.schema.nodes.expand ? ACTION_SUBJECT.EXPAND : ACTION_SUBJECT.NESTED_EXPAND,
116
+ attributes: {
117
+ platform: PLATFORMS.WEB,
118
+ mode: MODE.EDITOR,
119
+ expanded: isExpandedNext
120
+ },
121
+ eventType: EVENT_TYPE.TRACK
122
+ };
123
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent(payload)(tr);
124
+ dispatch(tr);
125
+ }
126
+ return true;
127
+ };
86
128
  export const updateExpandTitle = ({
87
129
  title,
88
130
  nodeType,