@atlaskit/editor-plugin-expand 7.2.5 → 7.3.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,17 @@
1
1
  # @atlaskit/editor-plugin-expand
2
2
 
3
+ ## 7.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`236d9310035ae`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/236d9310035ae) -
8
+ [https://product-fabric.atlassian.net/browse/ED-29205](ED-29205) - use native DOM element for
9
+ editor expand icon
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
3
15
  ## 7.2.5
4
16
 
5
17
  ### Patch Changes
@@ -15,6 +15,7 @@ var _utils = require("@atlaskit/editor-common/utils");
15
15
  var _state2 = require("@atlaskit/editor-prosemirror/state");
16
16
  var _utils2 = require("@atlaskit/editor-prosemirror/utils");
17
17
  var _utils3 = require("@atlaskit/editor-tables/utils");
18
+ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
18
19
  var _utils4 = require("../utils");
19
20
  var _pluginFactory = require("./pm-plugins/plugin-factory");
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; }
@@ -207,8 +208,8 @@ var focusIcon = exports.focusIcon = function focusIcon(expand) {
207
208
  return false;
208
209
  }
209
210
 
210
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
211
- var iconContainer = expand.querySelector(".".concat(_styles.expandClassNames.iconContainer));
211
+ // TODO: ED-29205 - During platform_editor_native_expand_button cleanup, rename `iconContainer` to `iconButton`.
212
+ var iconContainer = (0, _expValEquals.expValEquals)('platform_editor_native_expand_button', 'isEnabled', true) ? expand.querySelector(".".concat(_styles.expandClassNames.iconButton)) : expand.querySelector(".".concat(_styles.expandClassNames.iconContainer));
212
213
  if (iconContainer && iconContainer.focus) {
213
214
  var tr = state.tr;
214
215
  var pos = state.selection.from;
@@ -21,6 +21,7 @@ var _state = require("@atlaskit/editor-prosemirror/state");
21
21
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
22
22
  var _prosemirrorHistory = require("@atlaskit/prosemirror-history");
23
23
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
24
+ var _renderExpandButton = require("../../ui/renderExpandButton");
24
25
  var _commands = require("../commands");
25
26
  var _ExpandIconButton = require("../ui/ExpandIconButton");
26
27
  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; }
@@ -450,7 +451,11 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
450
451
  this.titleContainer = this.dom.querySelector(".".concat(_styles.expandClassNames.titleContainer));
451
452
  this.content = this.dom.querySelector(".".concat(_styles.expandClassNames.content));
452
453
  this.renderKey = (0, _v.default)();
453
- this.renderIcon(this.intl);
454
+ if ((0, _expValEquals.expValEquals)('platform_editor_native_expand_button', 'isEnabled', true)) {
455
+ this.renderNativeIcon(this.node);
456
+ } else {
457
+ this.renderIcon(this.intl);
458
+ }
454
459
  this.initHandlers();
455
460
  }
456
461
  return (0, _createClass2.default)(ExpandNodeView, [{
@@ -498,6 +503,19 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
498
503
  });
499
504
  }
500
505
  }
506
+ }, {
507
+ key: "renderNativeIcon",
508
+ value: function renderNativeIcon(node) {
509
+ if (!this.icon) {
510
+ return;
511
+ }
512
+ var __expanded = node.attrs.__expanded;
513
+ (0, _renderExpandButton.renderExpandButton)(this.icon, {
514
+ expanded: this.__livePage ? !__expanded : __expanded,
515
+ allowInteractiveExpand: this.allowInteractiveExpand,
516
+ intl: this.intl
517
+ });
518
+ }
501
519
  }, {
502
520
  key: "renderIcon",
503
521
  value: function renderIcon(intl, node) {
@@ -546,7 +564,11 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
546
564
  // we toggle a class name to hide the content and animate the chevron.
547
565
  if (this.dom) {
548
566
  this.dom.classList.toggle(_styles.expandClassNames.expanded);
549
- this.renderIcon(this && this.intl, node);
567
+ if ((0, _expValEquals.expValEquals)('platform_editor_native_expand_button', 'isEnabled', true)) {
568
+ this.renderNativeIcon(node);
569
+ } else {
570
+ this.renderIcon(this && this.intl, node);
571
+ }
550
572
  }
551
573
  if (this.content) {
552
574
  // Disallow interaction/selection inside when collapsed.
@@ -241,8 +241,8 @@ var focusIcon = exports.focusIcon = function focusIcon(expand) {
241
241
  return false;
242
242
  }
243
243
 
244
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
245
- var iconContainer = expand.querySelector(".".concat(_styles.expandClassNames.iconContainer));
244
+ // TODO: ED-29205 - During platform_editor_native_expand_button cleanup, rename `iconContainer` to `iconButton`.
245
+ var iconContainer = (0, _expValEquals.expValEquals)('platform_editor_native_expand_button', 'isEnabled', true) ? expand.querySelector(".".concat(_styles.expandClassNames.iconButton)) : expand.querySelector(".".concat(_styles.expandClassNames.iconContainer));
246
246
  if (iconContainer && iconContainer.focus) {
247
247
  var tr = state.tr;
248
248
  var pos = state.selection.from;
@@ -21,6 +21,7 @@ var _state = require("@atlaskit/editor-prosemirror/state");
21
21
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
22
22
  var _prosemirrorHistory = require("@atlaskit/prosemirror-history");
23
23
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
24
+ var _renderExpandButton = require("../../ui/renderExpandButton");
24
25
  var _commands = require("../commands");
25
26
  var _ExpandButton = require("../ui/ExpandButton");
26
27
  var _NodeView = require("../ui/NodeView");
@@ -420,7 +421,11 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
420
421
  if (!_expand.expandedState.has(this.node)) {
421
422
  _expand.expandedState.set(this.node, false);
422
423
  }
423
- this.renderIcon(this.icon, !(0, _expand.isExpandCollapsed)(this.node));
424
+ if ((0, _expValEquals.expValEquals)('platform_editor_native_expand_button', 'isEnabled', true)) {
425
+ this.renderNativeIcon(this.node);
426
+ } else {
427
+ this.renderIcon(this.icon, !(0, _expand.isExpandCollapsed)(this.node));
428
+ }
424
429
  if (!this.input || !this.titleContainer || !this.icon) {
425
430
  return;
426
431
  }
@@ -518,7 +523,6 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
518
523
  value: function updateExpandToggleIcon(node) {
519
524
  var expanded = _expand.expandedState.get(node) ? _expand.expandedState.get(node) : false;
520
525
  if (this.dom && expanded !== undefined) {
521
- var _expandedState$get;
522
526
  if ((0, _expValEquals.expValEquals)('platform_editor_find_and_replace_improvements', 'isEnabled', true)) {
523
527
  var classes = this.dom.className.split(' ');
524
528
  // find & replace styles might be applied to the expand title and we need to keep them
@@ -530,7 +534,12 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
530
534
  this.dom.className = (0, _NodeView.buildExpandClassName)(node.type.name, expanded);
531
535
  }
532
536
  // Re-render the icon to update the aria-expanded attribute
533
- this.renderIcon(this.icon ? this.icon : null, (_expandedState$get = _expand.expandedState.get(node)) !== null && _expandedState$get !== void 0 ? _expandedState$get : false);
537
+ if ((0, _expValEquals.expValEquals)('platform_editor_native_expand_button', 'isEnabled', true)) {
538
+ this.renderNativeIcon(node);
539
+ } else {
540
+ var _expandedState$get;
541
+ this.renderIcon(this.icon ? this.icon : null, (_expandedState$get = _expand.expandedState.get(node)) !== null && _expandedState$get !== void 0 ? _expandedState$get : false);
542
+ }
534
543
  }
535
544
  this.updateExpandBodyContentEditable();
536
545
  if ((0, _expValEquals.expValEquals)('platform_editor_toggle_expand_on_match_found', 'isEnabled', true)) {
@@ -545,6 +554,18 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
545
554
  this.content.setAttribute('contenteditable', this.getContentEditable(this.node) ? 'true' : 'false');
546
555
  }
547
556
  }
557
+ }, {
558
+ key: "renderNativeIcon",
559
+ value: function renderNativeIcon(node) {
560
+ if (!this.icon) {
561
+ return;
562
+ }
563
+ (0, _renderExpandButton.renderExpandButton)(this.icon, {
564
+ expanded: !(0, _expand.isExpandCollapsed)(node),
565
+ allowInteractiveExpand: this.allowInteractiveExpand,
566
+ intl: this.intl
567
+ });
568
+ }
548
569
  }, {
549
570
  key: "destroy",
550
571
  value: function destroy() {
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.renderExpandButton = renderExpandButton;
7
+ var _browserApis = require("@atlaskit/browser-apis");
8
+ var _styles = require("@atlaskit/editor-common/styles");
9
+ var _ui = require("@atlaskit/editor-common/ui");
10
+ /**
11
+ * Renders or updates the expand/collapse button inside the provided container element.
12
+ *
13
+ * @param container - The HTML element that will contain the expand/collapse button.
14
+ * @param buttonProps - Properties for configuring the button's behavior and appearance.
15
+ */
16
+ function renderExpandButton(container, buttonProps) {
17
+ var allowInteractiveExpand = buttonProps.allowInteractiveExpand,
18
+ expanded = buttonProps.expanded,
19
+ intl = buttonProps.intl;
20
+
21
+ // Update existing button attributes
22
+ var label = intl.formatMessage(expanded ? _ui.expandMessages.collapseNode : _ui.expandMessages.expandNode);
23
+ var existingButton = container.querySelector(".".concat(_styles.expandClassNames.iconButton));
24
+ if (existingButton) {
25
+ existingButton.setAttribute('aria-label', label);
26
+ existingButton.setAttribute('aria-expanded', String(expanded));
27
+ if (allowInteractiveExpand) {
28
+ existingButton.setAttribute('title', label);
29
+ existingButton.removeAttribute('disabled');
30
+ } else {
31
+ existingButton.removeAttribute('title');
32
+ existingButton.setAttribute('disabled', 'true');
33
+ }
34
+ } else {
35
+ var doc = (0, _browserApis.getDocument)();
36
+ if (!doc) {
37
+ return;
38
+ }
39
+ var button = doc.createElement('button');
40
+ button.className = _styles.expandClassNames.iconButton;
41
+ button.setAttribute('aria-label', label);
42
+ button.setAttribute('aria-expanded', String(expanded));
43
+ if (allowInteractiveExpand) {
44
+ button.setAttribute('title', label);
45
+ } else {
46
+ button.setAttribute('disabled', 'true');
47
+ }
48
+ container.appendChild(button);
49
+ var svgIcon = doc.createElementNS('http://www.w3.org/2000/svg', 'svg');
50
+ svgIcon.setAttribute('class', _styles.expandClassNames.iconSvg);
51
+ svgIcon.setAttribute('width', '12');
52
+ svgIcon.setAttribute('height', '12');
53
+ svgIcon.setAttribute('viewBox', '0 0 16 16');
54
+ svgIcon.setAttribute('role', 'presentation');
55
+ var path = doc.createElementNS('http://www.w3.org/2000/svg', 'path');
56
+ path.setAttribute('fill', 'currentcolor');
57
+ path.setAttribute('d', 'm6.03 1.47 6 6a.75.75 0 0 1 .052 1.004l-.052.056-6 6-1.06-1.06L10.44 8 4.97 2.53z');
58
+ svgIcon.appendChild(path);
59
+ button.appendChild(svgIcon);
60
+ }
61
+ }
@@ -7,6 +7,7 @@ import { createWrapSelectionTransaction } from '@atlaskit/editor-common/utils';
7
7
  import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
8
8
  import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
9
9
  import { findTable } from '@atlaskit/editor-tables/utils';
10
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
10
11
  import { isNestedInExpand } from '../utils';
11
12
  import { createCommand } from './pm-plugins/plugin-factory';
12
13
  export const setExpandRef = ref => createCommand({
@@ -187,8 +188,8 @@ export const focusIcon = expand => (state, dispatch, editorView) => {
187
188
  return false;
188
189
  }
189
190
 
190
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
191
- const iconContainer = expand.querySelector(`.${expandClassNames.iconContainer}`);
191
+ // TODO: ED-29205 - During platform_editor_native_expand_button cleanup, rename `iconContainer` to `iconButton`.
192
+ const iconContainer = expValEquals('platform_editor_native_expand_button', 'isEnabled', true) ? expand.querySelector(`.${expandClassNames.iconButton}`) : expand.querySelector(`.${expandClassNames.iconContainer}`);
192
193
  if (iconContainer && iconContainer.focus) {
193
194
  const {
194
195
  tr
@@ -11,6 +11,7 @@ import { NodeSelection, Selection } from '@atlaskit/editor-prosemirror/state';
11
11
  import { fg } from '@atlaskit/platform-feature-flags';
12
12
  import { redo, undo } from '@atlaskit/prosemirror-history';
13
13
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
14
+ import { renderExpandButton } from '../../ui/renderExpandButton';
14
15
  import { deleteExpandAtPos, setSelectionInsideExpand, toggleExpandExpanded, updateExpandTitle } from '../commands';
15
16
  import { ExpandIconButton } from '../ui/ExpandIconButton';
16
17
  function buildExpandClassName(type, expanded) {
@@ -451,7 +452,11 @@ export class ExpandNodeView {
451
452
  this.titleContainer = this.dom.querySelector(`.${expandClassNames.titleContainer}`);
452
453
  this.content = this.dom.querySelector(`.${expandClassNames.content}`);
453
454
  this.renderKey = uuid();
454
- this.renderIcon(this.intl);
455
+ if (expValEquals('platform_editor_native_expand_button', 'isEnabled', true)) {
456
+ this.renderNativeIcon(this.node);
457
+ } else {
458
+ this.renderIcon(this.intl);
459
+ }
455
460
  this.initHandlers();
456
461
  }
457
462
  initHandlers() {
@@ -496,6 +501,19 @@ export class ExpandNodeView {
496
501
  });
497
502
  }
498
503
  }
504
+ renderNativeIcon(node) {
505
+ if (!this.icon) {
506
+ return;
507
+ }
508
+ const {
509
+ __expanded
510
+ } = node.attrs;
511
+ renderExpandButton(this.icon, {
512
+ expanded: this.__livePage ? !__expanded : __expanded,
513
+ allowInteractiveExpand: this.allowInteractiveExpand,
514
+ intl: this.intl
515
+ });
516
+ }
499
517
  renderIcon(intl, node) {
500
518
  if (!this.icon) {
501
519
  return;
@@ -533,7 +551,11 @@ export class ExpandNodeView {
533
551
  // we toggle a class name to hide the content and animate the chevron.
534
552
  if (this.dom) {
535
553
  this.dom.classList.toggle(expandClassNames.expanded);
536
- this.renderIcon(this && this.intl, node);
554
+ if (expValEquals('platform_editor_native_expand_button', 'isEnabled', true)) {
555
+ this.renderNativeIcon(node);
556
+ } else {
557
+ this.renderIcon(this && this.intl, node);
558
+ }
537
559
  }
538
560
  if (this.content) {
539
561
  // Disallow interaction/selection inside when collapsed.
@@ -220,8 +220,8 @@ export const focusIcon = expand => (state, dispatch, editorView) => {
220
220
  return false;
221
221
  }
222
222
 
223
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
224
- const iconContainer = expand.querySelector(`.${expandClassNames.iconContainer}`);
223
+ // TODO: ED-29205 - During platform_editor_native_expand_button cleanup, rename `iconContainer` to `iconButton`.
224
+ const iconContainer = expValEquals('platform_editor_native_expand_button', 'isEnabled', true) ? expand.querySelector(`.${expandClassNames.iconButton}`) : expand.querySelector(`.${expandClassNames.iconContainer}`);
225
225
  if (iconContainer && iconContainer.focus) {
226
226
  const {
227
227
  tr
@@ -11,6 +11,7 @@ import { NodeSelection, Selection } from '@atlaskit/editor-prosemirror/state';
11
11
  import { fg } from '@atlaskit/platform-feature-flags';
12
12
  import { redo, undo } from '@atlaskit/prosemirror-history';
13
13
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
14
+ import { renderExpandButton } from '../../ui/renderExpandButton';
14
15
  import { deleteExpand, setSelectionInsideExpand, toggleExpandExpanded, updateExpandTitle } from '../commands';
15
16
  import { ExpandButton } from '../ui/ExpandButton';
16
17
  import { buildExpandClassName, toDOM } from '../ui/NodeView';
@@ -419,7 +420,11 @@ export class ExpandNodeView {
419
420
  if (!expandedState.has(this.node)) {
420
421
  expandedState.set(this.node, false);
421
422
  }
422
- this.renderIcon(this.icon, !isExpandCollapsed(this.node));
423
+ if (expValEquals('platform_editor_native_expand_button', 'isEnabled', true)) {
424
+ this.renderNativeIcon(this.node);
425
+ } else {
426
+ this.renderIcon(this.icon, !isExpandCollapsed(this.node));
427
+ }
423
428
  if (!this.input || !this.titleContainer || !this.icon) {
424
429
  return;
425
430
  }
@@ -508,7 +513,6 @@ export class ExpandNodeView {
508
513
  updateExpandToggleIcon(node) {
509
514
  const expanded = expandedState.get(node) ? expandedState.get(node) : false;
510
515
  if (this.dom && expanded !== undefined) {
511
- var _expandedState$get;
512
516
  if (expValEquals('platform_editor_find_and_replace_improvements', 'isEnabled', true)) {
513
517
  const classes = this.dom.className.split(' ');
514
518
  // find & replace styles might be applied to the expand title and we need to keep them
@@ -518,7 +522,12 @@ export class ExpandNodeView {
518
522
  this.dom.className = buildExpandClassName(node.type.name, expanded);
519
523
  }
520
524
  // Re-render the icon to update the aria-expanded attribute
521
- this.renderIcon(this.icon ? this.icon : null, (_expandedState$get = expandedState.get(node)) !== null && _expandedState$get !== void 0 ? _expandedState$get : false);
525
+ if (expValEquals('platform_editor_native_expand_button', 'isEnabled', true)) {
526
+ this.renderNativeIcon(node);
527
+ } else {
528
+ var _expandedState$get;
529
+ this.renderIcon(this.icon ? this.icon : null, (_expandedState$get = expandedState.get(node)) !== null && _expandedState$get !== void 0 ? _expandedState$get : false);
530
+ }
522
531
  }
523
532
  this.updateExpandBodyContentEditable();
524
533
  if (expValEquals('platform_editor_toggle_expand_on_match_found', 'isEnabled', true)) {
@@ -531,6 +540,16 @@ export class ExpandNodeView {
531
540
  this.content.setAttribute('contenteditable', this.getContentEditable(this.node) ? 'true' : 'false');
532
541
  }
533
542
  }
543
+ renderNativeIcon(node) {
544
+ if (!this.icon) {
545
+ return;
546
+ }
547
+ renderExpandButton(this.icon, {
548
+ expanded: !isExpandCollapsed(node),
549
+ allowInteractiveExpand: this.allowInteractiveExpand,
550
+ intl: this.intl
551
+ });
552
+ }
534
553
  destroy() {
535
554
  var _this$decorationClean2;
536
555
  if (!this.dom || !this.input || !this.titleContainer || !this.icon) {
@@ -0,0 +1,57 @@
1
+ import { getDocument } from '@atlaskit/browser-apis';
2
+ import { expandClassNames } from '@atlaskit/editor-common/styles';
3
+ import { expandMessages } from '@atlaskit/editor-common/ui';
4
+ /**
5
+ * Renders or updates the expand/collapse button inside the provided container element.
6
+ *
7
+ * @param container - The HTML element that will contain the expand/collapse button.
8
+ * @param buttonProps - Properties for configuring the button's behavior and appearance.
9
+ */
10
+ export function renderExpandButton(container, buttonProps) {
11
+ const {
12
+ allowInteractiveExpand,
13
+ expanded,
14
+ intl
15
+ } = buttonProps;
16
+
17
+ // Update existing button attributes
18
+ const label = intl.formatMessage(expanded ? expandMessages.collapseNode : expandMessages.expandNode);
19
+ const existingButton = container.querySelector(`.${expandClassNames.iconButton}`);
20
+ if (existingButton) {
21
+ existingButton.setAttribute('aria-label', label);
22
+ existingButton.setAttribute('aria-expanded', String(expanded));
23
+ if (allowInteractiveExpand) {
24
+ existingButton.setAttribute('title', label);
25
+ existingButton.removeAttribute('disabled');
26
+ } else {
27
+ existingButton.removeAttribute('title');
28
+ existingButton.setAttribute('disabled', 'true');
29
+ }
30
+ } else {
31
+ const doc = getDocument();
32
+ if (!doc) {
33
+ return;
34
+ }
35
+ const button = doc.createElement('button');
36
+ button.className = expandClassNames.iconButton;
37
+ button.setAttribute('aria-label', label);
38
+ button.setAttribute('aria-expanded', String(expanded));
39
+ if (allowInteractiveExpand) {
40
+ button.setAttribute('title', label);
41
+ } else {
42
+ button.setAttribute('disabled', 'true');
43
+ }
44
+ container.appendChild(button);
45
+ const svgIcon = doc.createElementNS('http://www.w3.org/2000/svg', 'svg');
46
+ svgIcon.setAttribute('class', expandClassNames.iconSvg);
47
+ svgIcon.setAttribute('width', '12');
48
+ svgIcon.setAttribute('height', '12');
49
+ svgIcon.setAttribute('viewBox', '0 0 16 16');
50
+ svgIcon.setAttribute('role', 'presentation');
51
+ const path = doc.createElementNS('http://www.w3.org/2000/svg', 'path');
52
+ path.setAttribute('fill', 'currentcolor');
53
+ path.setAttribute('d', 'm6.03 1.47 6 6a.75.75 0 0 1 .052 1.004l-.052.056-6 6-1.06-1.06L10.44 8 4.97 2.53z');
54
+ svgIcon.appendChild(path);
55
+ button.appendChild(svgIcon);
56
+ }
57
+ }
@@ -10,6 +10,7 @@ import { createWrapSelectionTransaction } from '@atlaskit/editor-common/utils';
10
10
  import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
11
11
  import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
12
12
  import { findTable } from '@atlaskit/editor-tables/utils';
13
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
13
14
  import { isNestedInExpand } from '../utils';
14
15
  import { createCommand } from './pm-plugins/plugin-factory';
15
16
  export var setExpandRef = function setExpandRef(ref) {
@@ -200,8 +201,8 @@ export var focusIcon = function focusIcon(expand) {
200
201
  return false;
201
202
  }
202
203
 
203
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
204
- var iconContainer = expand.querySelector(".".concat(expandClassNames.iconContainer));
204
+ // TODO: ED-29205 - During platform_editor_native_expand_button cleanup, rename `iconContainer` to `iconButton`.
205
+ var iconContainer = expValEquals('platform_editor_native_expand_button', 'isEnabled', true) ? expand.querySelector(".".concat(expandClassNames.iconButton)) : expand.querySelector(".".concat(expandClassNames.iconContainer));
205
206
  if (iconContainer && iconContainer.focus) {
206
207
  var tr = state.tr;
207
208
  var pos = state.selection.from;
@@ -15,6 +15,7 @@ import { NodeSelection, Selection } from '@atlaskit/editor-prosemirror/state';
15
15
  import { fg } from '@atlaskit/platform-feature-flags';
16
16
  import { redo, undo } from '@atlaskit/prosemirror-history';
17
17
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
18
+ import { renderExpandButton } from '../../ui/renderExpandButton';
18
19
  import { deleteExpandAtPos, setSelectionInsideExpand, toggleExpandExpanded, updateExpandTitle } from '../commands';
19
20
  import { ExpandIconButton } from '../ui/ExpandIconButton';
20
21
  function buildExpandClassName(type, expanded) {
@@ -442,7 +443,11 @@ export var ExpandNodeView = /*#__PURE__*/function () {
442
443
  this.titleContainer = this.dom.querySelector(".".concat(expandClassNames.titleContainer));
443
444
  this.content = this.dom.querySelector(".".concat(expandClassNames.content));
444
445
  this.renderKey = uuid();
445
- this.renderIcon(this.intl);
446
+ if (expValEquals('platform_editor_native_expand_button', 'isEnabled', true)) {
447
+ this.renderNativeIcon(this.node);
448
+ } else {
449
+ this.renderIcon(this.intl);
450
+ }
446
451
  this.initHandlers();
447
452
  }
448
453
  return _createClass(ExpandNodeView, [{
@@ -490,6 +495,19 @@ export var ExpandNodeView = /*#__PURE__*/function () {
490
495
  });
491
496
  }
492
497
  }
498
+ }, {
499
+ key: "renderNativeIcon",
500
+ value: function renderNativeIcon(node) {
501
+ if (!this.icon) {
502
+ return;
503
+ }
504
+ var __expanded = node.attrs.__expanded;
505
+ renderExpandButton(this.icon, {
506
+ expanded: this.__livePage ? !__expanded : __expanded,
507
+ allowInteractiveExpand: this.allowInteractiveExpand,
508
+ intl: this.intl
509
+ });
510
+ }
493
511
  }, {
494
512
  key: "renderIcon",
495
513
  value: function renderIcon(intl, node) {
@@ -538,7 +556,11 @@ export var ExpandNodeView = /*#__PURE__*/function () {
538
556
  // we toggle a class name to hide the content and animate the chevron.
539
557
  if (this.dom) {
540
558
  this.dom.classList.toggle(expandClassNames.expanded);
541
- this.renderIcon(this && this.intl, node);
559
+ if (expValEquals('platform_editor_native_expand_button', 'isEnabled', true)) {
560
+ this.renderNativeIcon(node);
561
+ } else {
562
+ this.renderIcon(this && this.intl, node);
563
+ }
542
564
  }
543
565
  if (this.content) {
544
566
  // Disallow interaction/selection inside when collapsed.
@@ -235,8 +235,8 @@ export var focusIcon = function focusIcon(expand) {
235
235
  return false;
236
236
  }
237
237
 
238
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
239
- var iconContainer = expand.querySelector(".".concat(expandClassNames.iconContainer));
238
+ // TODO: ED-29205 - During platform_editor_native_expand_button cleanup, rename `iconContainer` to `iconButton`.
239
+ var iconContainer = expValEquals('platform_editor_native_expand_button', 'isEnabled', true) ? expand.querySelector(".".concat(expandClassNames.iconButton)) : expand.querySelector(".".concat(expandClassNames.iconContainer));
240
240
  if (iconContainer && iconContainer.focus) {
241
241
  var tr = state.tr;
242
242
  var pos = state.selection.from;
@@ -13,6 +13,7 @@ import { NodeSelection, Selection } from '@atlaskit/editor-prosemirror/state';
13
13
  import { fg } from '@atlaskit/platform-feature-flags';
14
14
  import { redo, undo } from '@atlaskit/prosemirror-history';
15
15
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
16
+ import { renderExpandButton } from '../../ui/renderExpandButton';
16
17
  import { deleteExpand, setSelectionInsideExpand, toggleExpandExpanded, updateExpandTitle } from '../commands';
17
18
  import { ExpandButton } from '../ui/ExpandButton';
18
19
  import { buildExpandClassName, toDOM } from '../ui/NodeView';
@@ -412,7 +413,11 @@ export var ExpandNodeView = /*#__PURE__*/function () {
412
413
  if (!expandedState.has(this.node)) {
413
414
  expandedState.set(this.node, false);
414
415
  }
415
- this.renderIcon(this.icon, !isExpandCollapsed(this.node));
416
+ if (expValEquals('platform_editor_native_expand_button', 'isEnabled', true)) {
417
+ this.renderNativeIcon(this.node);
418
+ } else {
419
+ this.renderIcon(this.icon, !isExpandCollapsed(this.node));
420
+ }
416
421
  if (!this.input || !this.titleContainer || !this.icon) {
417
422
  return;
418
423
  }
@@ -510,7 +515,6 @@ export var ExpandNodeView = /*#__PURE__*/function () {
510
515
  value: function updateExpandToggleIcon(node) {
511
516
  var expanded = expandedState.get(node) ? expandedState.get(node) : false;
512
517
  if (this.dom && expanded !== undefined) {
513
- var _expandedState$get;
514
518
  if (expValEquals('platform_editor_find_and_replace_improvements', 'isEnabled', true)) {
515
519
  var classes = this.dom.className.split(' ');
516
520
  // find & replace styles might be applied to the expand title and we need to keep them
@@ -522,7 +526,12 @@ export var ExpandNodeView = /*#__PURE__*/function () {
522
526
  this.dom.className = buildExpandClassName(node.type.name, expanded);
523
527
  }
524
528
  // Re-render the icon to update the aria-expanded attribute
525
- this.renderIcon(this.icon ? this.icon : null, (_expandedState$get = expandedState.get(node)) !== null && _expandedState$get !== void 0 ? _expandedState$get : false);
529
+ if (expValEquals('platform_editor_native_expand_button', 'isEnabled', true)) {
530
+ this.renderNativeIcon(node);
531
+ } else {
532
+ var _expandedState$get;
533
+ this.renderIcon(this.icon ? this.icon : null, (_expandedState$get = expandedState.get(node)) !== null && _expandedState$get !== void 0 ? _expandedState$get : false);
534
+ }
526
535
  }
527
536
  this.updateExpandBodyContentEditable();
528
537
  if (expValEquals('platform_editor_toggle_expand_on_match_found', 'isEnabled', true)) {
@@ -537,6 +546,18 @@ export var ExpandNodeView = /*#__PURE__*/function () {
537
546
  this.content.setAttribute('contenteditable', this.getContentEditable(this.node) ? 'true' : 'false');
538
547
  }
539
548
  }
549
+ }, {
550
+ key: "renderNativeIcon",
551
+ value: function renderNativeIcon(node) {
552
+ if (!this.icon) {
553
+ return;
554
+ }
555
+ renderExpandButton(this.icon, {
556
+ expanded: !isExpandCollapsed(node),
557
+ allowInteractiveExpand: this.allowInteractiveExpand,
558
+ intl: this.intl
559
+ });
560
+ }
540
561
  }, {
541
562
  key: "destroy",
542
563
  value: function destroy() {
@@ -0,0 +1,55 @@
1
+ import { getDocument } from '@atlaskit/browser-apis';
2
+ import { expandClassNames } from '@atlaskit/editor-common/styles';
3
+ import { expandMessages } from '@atlaskit/editor-common/ui';
4
+ /**
5
+ * Renders or updates the expand/collapse button inside the provided container element.
6
+ *
7
+ * @param container - The HTML element that will contain the expand/collapse button.
8
+ * @param buttonProps - Properties for configuring the button's behavior and appearance.
9
+ */
10
+ export function renderExpandButton(container, buttonProps) {
11
+ var allowInteractiveExpand = buttonProps.allowInteractiveExpand,
12
+ expanded = buttonProps.expanded,
13
+ intl = buttonProps.intl;
14
+
15
+ // Update existing button attributes
16
+ var label = intl.formatMessage(expanded ? expandMessages.collapseNode : expandMessages.expandNode);
17
+ var existingButton = container.querySelector(".".concat(expandClassNames.iconButton));
18
+ if (existingButton) {
19
+ existingButton.setAttribute('aria-label', label);
20
+ existingButton.setAttribute('aria-expanded', String(expanded));
21
+ if (allowInteractiveExpand) {
22
+ existingButton.setAttribute('title', label);
23
+ existingButton.removeAttribute('disabled');
24
+ } else {
25
+ existingButton.removeAttribute('title');
26
+ existingButton.setAttribute('disabled', 'true');
27
+ }
28
+ } else {
29
+ var doc = getDocument();
30
+ if (!doc) {
31
+ return;
32
+ }
33
+ var button = doc.createElement('button');
34
+ button.className = expandClassNames.iconButton;
35
+ button.setAttribute('aria-label', label);
36
+ button.setAttribute('aria-expanded', String(expanded));
37
+ if (allowInteractiveExpand) {
38
+ button.setAttribute('title', label);
39
+ } else {
40
+ button.setAttribute('disabled', 'true');
41
+ }
42
+ container.appendChild(button);
43
+ var svgIcon = doc.createElementNS('http://www.w3.org/2000/svg', 'svg');
44
+ svgIcon.setAttribute('class', expandClassNames.iconSvg);
45
+ svgIcon.setAttribute('width', '12');
46
+ svgIcon.setAttribute('height', '12');
47
+ svgIcon.setAttribute('viewBox', '0 0 16 16');
48
+ svgIcon.setAttribute('role', 'presentation');
49
+ var path = doc.createElementNS('http://www.w3.org/2000/svg', 'path');
50
+ path.setAttribute('fill', 'currentcolor');
51
+ path.setAttribute('d', 'm6.03 1.47 6 6a.75.75 0 0 1 .052 1.004l-.052.056-6 6-1.06-1.06L10.44 8 4.97 2.53z');
52
+ svgIcon.appendChild(path);
53
+ button.appendChild(svgIcon);
54
+ }
55
+ }
@@ -29,6 +29,7 @@ export declare class ExpandNodeView implements NodeView {
29
29
  private initHandlers;
30
30
  private focusTitle;
31
31
  private handleIconKeyDown;
32
+ private renderNativeIcon;
32
33
  private renderIcon;
33
34
  private handleClick;
34
35
  private handleInput;
@@ -54,6 +54,7 @@ export declare class ExpandNodeView implements NodeView {
54
54
  update(node: PmNode, _decorations: readonly Decoration[]): boolean;
55
55
  updateExpandToggleIcon(node: PmNode): void;
56
56
  updateExpandBodyContentEditable(): void;
57
+ private renderNativeIcon;
57
58
  renderIcon: (icon: HTMLElement | null, expanded: boolean) => void;
58
59
  destroy(): void;
59
60
  }
@@ -0,0 +1,17 @@
1
+ import type { IntlShape } from 'react-intl-next';
2
+ interface ButtonProps {
3
+ /** Indicates whether interactive expand is allowed */
4
+ allowInteractiveExpand: boolean;
5
+ /** Indicates whether the expand is currently expanded */
6
+ expanded: boolean;
7
+ /** Internationalization object for formatting messages */
8
+ intl: IntlShape;
9
+ }
10
+ /**
11
+ * Renders or updates the expand/collapse button inside the provided container element.
12
+ *
13
+ * @param container - The HTML element that will contain the expand/collapse button.
14
+ * @param buttonProps - Properties for configuring the button's behavior and appearance.
15
+ */
16
+ export declare function renderExpandButton(container: HTMLElement, buttonProps: ButtonProps): void;
17
+ export {};
@@ -29,6 +29,7 @@ export declare class ExpandNodeView implements NodeView {
29
29
  private initHandlers;
30
30
  private focusTitle;
31
31
  private handleIconKeyDown;
32
+ private renderNativeIcon;
32
33
  private renderIcon;
33
34
  private handleClick;
34
35
  private handleInput;
@@ -54,6 +54,7 @@ export declare class ExpandNodeView implements NodeView {
54
54
  update(node: PmNode, _decorations: readonly Decoration[]): boolean;
55
55
  updateExpandToggleIcon(node: PmNode): void;
56
56
  updateExpandBodyContentEditable(): void;
57
+ private renderNativeIcon;
57
58
  renderIcon: (icon: HTMLElement | null, expanded: boolean) => void;
58
59
  destroy(): void;
59
60
  }
@@ -0,0 +1,17 @@
1
+ import type { IntlShape } from 'react-intl-next';
2
+ interface ButtonProps {
3
+ /** Indicates whether interactive expand is allowed */
4
+ allowInteractiveExpand: boolean;
5
+ /** Indicates whether the expand is currently expanded */
6
+ expanded: boolean;
7
+ /** Internationalization object for formatting messages */
8
+ intl: IntlShape;
9
+ }
10
+ /**
11
+ * Renders or updates the expand/collapse button inside the provided container element.
12
+ *
13
+ * @param container - The HTML element that will contain the expand/collapse button.
14
+ * @param buttonProps - Properties for configuring the button's behavior and appearance.
15
+ */
16
+ export declare function renderExpandButton(container: HTMLElement, buttonProps: ButtonProps): void;
17
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-expand",
3
- "version": "7.2.5",
3
+ "version": "7.3.0",
4
4
  "description": "Expand plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -30,6 +30,7 @@
30
30
  "atlaskit:src": "src/index.ts",
31
31
  "dependencies": {
32
32
  "@atlaskit/adf-schema": "^51.3.2",
33
+ "@atlaskit/browser-apis": "^0.0.1",
33
34
  "@atlaskit/button": "^23.5.0",
34
35
  "@atlaskit/editor-plugin-analytics": "^6.2.0",
35
36
  "@atlaskit/editor-plugin-block-menu": "^5.0.0",
@@ -46,8 +47,9 @@
46
47
  "@atlaskit/icon": "^28.5.0",
47
48
  "@atlaskit/icon-lab": "^5.11.0",
48
49
  "@atlaskit/platform-feature-flags": "^1.1.0",
49
- "@atlaskit/tmp-editor-statsig": "^13.22.0",
50
- "@atlaskit/tokens": "^7.0.0",
50
+ "@atlaskit/prosemirror-history": "^0.2.0",
51
+ "@atlaskit/tmp-editor-statsig": "^13.30.0",
52
+ "@atlaskit/tokens": "^7.1.0",
51
53
  "@atlaskit/tooltip": "^20.7.0",
52
54
  "@babel/runtime": "^7.0.0",
53
55
  "@emotion/react": "^11.7.1",
@@ -55,7 +57,7 @@
55
57
  "w3c-keyname": "^2.1.8"
56
58
  },
57
59
  "peerDependencies": {
58
- "@atlaskit/editor-common": "^110.19.0",
60
+ "@atlaskit/editor-common": "^110.23.0",
59
61
  "react": "^18.2.0",
60
62
  "react-dom": "^18.2.0",
61
63
  "react-intl-next": "npm:react-intl@^5.18.1"
@@ -68,7 +70,6 @@
68
70
  "@atlaskit/editor-plugin-table": "^15.3.0",
69
71
  "@atlaskit/editor-plugin-type-ahead": "^6.5.0",
70
72
  "@atlaskit/editor-plugin-width": "^7.0.0",
71
- "@atlaskit/prosemirror-history": "^0.2.0",
72
73
  "@testing-library/react": "^13.4.0",
73
74
  "react-test-renderer": "^18.2.0"
74
75
  },