@atlaskit/editor-plugin-expand 11.0.0 → 11.0.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @atlaskit/editor-plugin-expand
2
2
 
3
+ ## 11.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`c50b6810de5a3`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/c50b6810de5a3) -
8
+ Fix `toggleExpandRange` to set a `forceExpandOpen` node decoration via transaction meta (gated by
9
+ `platform_editor_expand_force_open_decoration`) so `ExpandNodeView.update()` correctly opens
10
+ expands visually regardless of whether the `platform_editor_aifc_expand_collapses_oncreate_fix`
11
+ experiment is active. Also returns `null` when no expand nodes are found or no state changes, and
12
+ removes stray debug `console.log` statements.
13
+
3
14
  ## 11.0.0
4
15
 
5
16
  ### Major Changes
@@ -3,9 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.toggleExpandRange = void 0;
6
+ exports.toggleExpandRange = exports.TOGGLE_EXPAND_RANGE_META_KEY = void 0;
7
7
  var _expand = require("@atlaskit/editor-common/expand");
8
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
8
9
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
10
+ var TOGGLE_EXPAND_RANGE_META_KEY = exports.TOGGLE_EXPAND_RANGE_META_KEY = 'toggleExpandRange';
9
11
  var toggleExpandRange = exports.toggleExpandRange = function toggleExpandRange(from, to) {
10
12
  var open = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
11
13
  return function (_ref) {
@@ -15,11 +17,28 @@ var toggleExpandRange = exports.toggleExpandRange = function toggleExpandRange(f
15
17
  nestedExpand = _tr$doc$type$schema$n.nestedExpand;
16
18
  var fromClamped = from && from >= 0 ? from : 0;
17
19
  var toClamped = to && to <= tr.doc.content.size ? to : tr.doc.content.size;
18
- tr.doc.nodesBetween(fromClamped, toClamped, function (node) {
20
+ var positions = [];
21
+ tr.doc.nodesBetween(fromClamped, toClamped, function (node, pos) {
19
22
  if ([expand, nestedExpand].includes(node.type)) {
20
23
  _expand.expandedState.set(node, open);
24
+ positions.push(pos);
21
25
  }
22
26
  });
27
+ if ((0, _platformFeatureFlags.fg)('platform_editor_show_diff_scroll_navigation')) {
28
+ if (positions.length === 0) {
29
+ // No expand nodes found in the range — nothing to dispatch.
30
+ return null;
31
+ }
32
+
33
+ // Set meta so the expand PM plugin can add node decorations.
34
+ // This ensures ExpandNodeView.update() receives the decoration and visually
35
+ // opens or closes the expand, even when the experiment below is disabled.
36
+ tr.setMeta(TOGGLE_EXPAND_RANGE_META_KEY, {
37
+ positions: positions,
38
+ open: open
39
+ });
40
+ return tr;
41
+ }
23
42
  if ((0, _expValEquals.expValEquals)('platform_editor_aifc_expand_collapses_oncreate_fix', 'isEnabled', true)) {
24
43
  return tr;
25
44
  }
@@ -13,6 +13,9 @@ var _selection = require("@atlaskit/editor-common/selection");
13
13
  var _styles = require("@atlaskit/editor-common/styles");
14
14
  var _transforms = require("@atlaskit/editor-common/transforms");
15
15
  var _state = require("@atlaskit/editor-prosemirror/state");
16
+ var _view2 = require("@atlaskit/editor-prosemirror/view");
17
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
18
+ var _toggleExpandRange = require("../../editor-commands/toggleExpandRange");
16
19
  var _nodeViews = _interopRequireDefault(require("../node-views"));
17
20
  // Ignored via go/ees005
18
21
  // eslint-disable-next-line import/no-named-as-default
@@ -32,7 +35,44 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, getInt
32
35
  var isMobile = false;
33
36
  return new _safePlugin.SafePlugin({
34
37
  key: pluginKey,
38
+ state: {
39
+ init: function init() {
40
+ return _view2.DecorationSet.empty;
41
+ },
42
+ apply: function apply(tr, decorationSet) {
43
+ if (!(0, _platformFeatureFlags.fg)('platform_editor_show_diff_scroll_navigation')) {
44
+ return _view2.DecorationSet.empty;
45
+ }
46
+ var meta = tr.getMeta(_toggleExpandRange.TOGGLE_EXPAND_RANGE_META_KEY);
47
+ if (meta && meta.positions.length > 0) {
48
+ // Add node decorations for each expand node that was toggled.
49
+ // ExpandNodeView.update() uses these decorations to detect it needs to
50
+ // visually open or close, even when expandedState was set before the
51
+ // transaction replaced the node objects.
52
+ // We do NOT map or carry forward existing decorations — we start fresh
53
+ // each time the meta is present.
54
+ var decorations = meta.positions.map(function (pos) {
55
+ var _tr$doc$nodeAt$nodeSi, _tr$doc$nodeAt;
56
+ return _view2.Decoration.node(pos, pos + ((_tr$doc$nodeAt$nodeSi = (_tr$doc$nodeAt = tr.doc.nodeAt(pos)) === null || _tr$doc$nodeAt === void 0 ? void 0 : _tr$doc$nodeAt.nodeSize) !== null && _tr$doc$nodeAt$nodeSi !== void 0 ? _tr$doc$nodeAt$nodeSi : 0), {}, {
57
+ forceExpandOpen: meta.open
58
+ });
59
+ });
60
+ return _view2.DecorationSet.create(tr.doc, decorations);
61
+ }
62
+
63
+ // Map existing decorations through document changes.
64
+ // They will be naturally cleared when they no longer match any node
65
+ // (e.g. if the expand is deleted), or on the next toggleExpandRange call.
66
+ return decorationSet.map(tr.mapping, tr.doc);
67
+ }
68
+ },
35
69
  props: {
70
+ decorations: function decorations(state) {
71
+ if (!(0, _platformFeatureFlags.fg)('platform_editor_show_diff_scroll_navigation')) {
72
+ return undefined;
73
+ }
74
+ return pluginKey.getState(state);
75
+ },
36
76
  nodeViews: {
37
77
  expand: (0, _nodeViews.default)({
38
78
  getIntl: getIntl,
@@ -1,5 +1,7 @@
1
1
  import { expandedState } from '@atlaskit/editor-common/expand';
2
+ import { fg } from '@atlaskit/platform-feature-flags';
2
3
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
4
+ export const TOGGLE_EXPAND_RANGE_META_KEY = 'toggleExpandRange';
3
5
  export const toggleExpandRange = (from, to, open = true) => ({
4
6
  tr
5
7
  }) => {
@@ -9,11 +11,28 @@ export const toggleExpandRange = (from, to, open = true) => ({
9
11
  } = tr.doc.type.schema.nodes;
10
12
  const fromClamped = from && from >= 0 ? from : 0;
11
13
  const toClamped = to && to <= tr.doc.content.size ? to : tr.doc.content.size;
12
- tr.doc.nodesBetween(fromClamped, toClamped, node => {
14
+ const positions = [];
15
+ tr.doc.nodesBetween(fromClamped, toClamped, (node, pos) => {
13
16
  if ([expand, nestedExpand].includes(node.type)) {
14
17
  expandedState.set(node, open);
18
+ positions.push(pos);
15
19
  }
16
20
  });
21
+ if (fg('platform_editor_show_diff_scroll_navigation')) {
22
+ if (positions.length === 0) {
23
+ // No expand nodes found in the range — nothing to dispatch.
24
+ return null;
25
+ }
26
+
27
+ // Set meta so the expand PM plugin can add node decorations.
28
+ // This ensures ExpandNodeView.update() receives the decoration and visually
29
+ // opens or closes the expand, even when the experiment below is disabled.
30
+ tr.setMeta(TOGGLE_EXPAND_RANGE_META_KEY, {
31
+ positions,
32
+ open
33
+ });
34
+ return tr;
35
+ }
17
36
  if (expValEquals('platform_editor_aifc_expand_collapses_oncreate_fix', 'isEnabled', true)) {
18
37
  return tr;
19
38
  }
@@ -3,6 +3,9 @@ import { createSelectionClickHandler } from '@atlaskit/editor-common/selection';
3
3
  import { expandClassNames } from '@atlaskit/editor-common/styles';
4
4
  import { transformSliceExpandToNestedExpand, transformSliceNestedExpandToExpand } from '@atlaskit/editor-common/transforms';
5
5
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
6
+ import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
7
+ import { fg } from '@atlaskit/platform-feature-flags';
8
+ import { TOGGLE_EXPAND_RANGE_META_KEY } from '../../editor-commands/toggleExpandRange';
6
9
  // Ignored via go/ees005
7
10
  // eslint-disable-next-line import/no-named-as-default
8
11
  import ExpandNodeView from '../node-views';
@@ -15,7 +18,44 @@ export const createPlugin = (dispatch, getIntl, appearance = 'full-page', useLon
15
18
  const isMobile = false;
16
19
  return new SafePlugin({
17
20
  key: pluginKey,
21
+ state: {
22
+ init() {
23
+ return DecorationSet.empty;
24
+ },
25
+ apply(tr, decorationSet) {
26
+ if (!fg('platform_editor_show_diff_scroll_navigation')) {
27
+ return DecorationSet.empty;
28
+ }
29
+ const meta = tr.getMeta(TOGGLE_EXPAND_RANGE_META_KEY);
30
+ if (meta && meta.positions.length > 0) {
31
+ // Add node decorations for each expand node that was toggled.
32
+ // ExpandNodeView.update() uses these decorations to detect it needs to
33
+ // visually open or close, even when expandedState was set before the
34
+ // transaction replaced the node objects.
35
+ // We do NOT map or carry forward existing decorations — we start fresh
36
+ // each time the meta is present.
37
+ const decorations = meta.positions.map(pos => {
38
+ var _tr$doc$nodeAt$nodeSi, _tr$doc$nodeAt;
39
+ return Decoration.node(pos, pos + ((_tr$doc$nodeAt$nodeSi = (_tr$doc$nodeAt = tr.doc.nodeAt(pos)) === null || _tr$doc$nodeAt === void 0 ? void 0 : _tr$doc$nodeAt.nodeSize) !== null && _tr$doc$nodeAt$nodeSi !== void 0 ? _tr$doc$nodeAt$nodeSi : 0), {}, {
40
+ forceExpandOpen: meta.open
41
+ });
42
+ });
43
+ return DecorationSet.create(tr.doc, decorations);
44
+ }
45
+
46
+ // Map existing decorations through document changes.
47
+ // They will be naturally cleared when they no longer match any node
48
+ // (e.g. if the expand is deleted), or on the next toggleExpandRange call.
49
+ return decorationSet.map(tr.mapping, tr.doc);
50
+ }
51
+ },
18
52
  props: {
53
+ decorations(state) {
54
+ if (!fg('platform_editor_show_diff_scroll_navigation')) {
55
+ return undefined;
56
+ }
57
+ return pluginKey.getState(state);
58
+ },
19
59
  nodeViews: {
20
60
  expand: ExpandNodeView({
21
61
  getIntl,
@@ -1,5 +1,7 @@
1
1
  import { expandedState } from '@atlaskit/editor-common/expand';
2
+ import { fg } from '@atlaskit/platform-feature-flags';
2
3
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
4
+ export var TOGGLE_EXPAND_RANGE_META_KEY = 'toggleExpandRange';
3
5
  export var toggleExpandRange = function toggleExpandRange(from, to) {
4
6
  var open = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
5
7
  return function (_ref) {
@@ -9,11 +11,28 @@ export var toggleExpandRange = function toggleExpandRange(from, to) {
9
11
  nestedExpand = _tr$doc$type$schema$n.nestedExpand;
10
12
  var fromClamped = from && from >= 0 ? from : 0;
11
13
  var toClamped = to && to <= tr.doc.content.size ? to : tr.doc.content.size;
12
- tr.doc.nodesBetween(fromClamped, toClamped, function (node) {
14
+ var positions = [];
15
+ tr.doc.nodesBetween(fromClamped, toClamped, function (node, pos) {
13
16
  if ([expand, nestedExpand].includes(node.type)) {
14
17
  expandedState.set(node, open);
18
+ positions.push(pos);
15
19
  }
16
20
  });
21
+ if (fg('platform_editor_show_diff_scroll_navigation')) {
22
+ if (positions.length === 0) {
23
+ // No expand nodes found in the range — nothing to dispatch.
24
+ return null;
25
+ }
26
+
27
+ // Set meta so the expand PM plugin can add node decorations.
28
+ // This ensures ExpandNodeView.update() receives the decoration and visually
29
+ // opens or closes the expand, even when the experiment below is disabled.
30
+ tr.setMeta(TOGGLE_EXPAND_RANGE_META_KEY, {
31
+ positions: positions,
32
+ open: open
33
+ });
34
+ return tr;
35
+ }
17
36
  if (expValEquals('platform_editor_aifc_expand_collapses_oncreate_fix', 'isEnabled', true)) {
18
37
  return tr;
19
38
  }
@@ -3,6 +3,9 @@ import { createSelectionClickHandler } from '@atlaskit/editor-common/selection';
3
3
  import { expandClassNames } from '@atlaskit/editor-common/styles';
4
4
  import { transformSliceExpandToNestedExpand, transformSliceNestedExpandToExpand } from '@atlaskit/editor-common/transforms';
5
5
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
6
+ import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
7
+ import { fg } from '@atlaskit/platform-feature-flags';
8
+ import { TOGGLE_EXPAND_RANGE_META_KEY } from '../../editor-commands/toggleExpandRange';
6
9
  // Ignored via go/ees005
7
10
  // eslint-disable-next-line import/no-named-as-default
8
11
  import ExpandNodeView from '../node-views';
@@ -21,7 +24,44 @@ export var createPlugin = function createPlugin(dispatch, getIntl) {
21
24
  var isMobile = false;
22
25
  return new SafePlugin({
23
26
  key: pluginKey,
27
+ state: {
28
+ init: function init() {
29
+ return DecorationSet.empty;
30
+ },
31
+ apply: function apply(tr, decorationSet) {
32
+ if (!fg('platform_editor_show_diff_scroll_navigation')) {
33
+ return DecorationSet.empty;
34
+ }
35
+ var meta = tr.getMeta(TOGGLE_EXPAND_RANGE_META_KEY);
36
+ if (meta && meta.positions.length > 0) {
37
+ // Add node decorations for each expand node that was toggled.
38
+ // ExpandNodeView.update() uses these decorations to detect it needs to
39
+ // visually open or close, even when expandedState was set before the
40
+ // transaction replaced the node objects.
41
+ // We do NOT map or carry forward existing decorations — we start fresh
42
+ // each time the meta is present.
43
+ var decorations = meta.positions.map(function (pos) {
44
+ var _tr$doc$nodeAt$nodeSi, _tr$doc$nodeAt;
45
+ return Decoration.node(pos, pos + ((_tr$doc$nodeAt$nodeSi = (_tr$doc$nodeAt = tr.doc.nodeAt(pos)) === null || _tr$doc$nodeAt === void 0 ? void 0 : _tr$doc$nodeAt.nodeSize) !== null && _tr$doc$nodeAt$nodeSi !== void 0 ? _tr$doc$nodeAt$nodeSi : 0), {}, {
46
+ forceExpandOpen: meta.open
47
+ });
48
+ });
49
+ return DecorationSet.create(tr.doc, decorations);
50
+ }
51
+
52
+ // Map existing decorations through document changes.
53
+ // They will be naturally cleared when they no longer match any node
54
+ // (e.g. if the expand is deleted), or on the next toggleExpandRange call.
55
+ return decorationSet.map(tr.mapping, tr.doc);
56
+ }
57
+ },
24
58
  props: {
59
+ decorations: function decorations(state) {
60
+ if (!fg('platform_editor_show_diff_scroll_navigation')) {
61
+ return undefined;
62
+ }
63
+ return pluginKey.getState(state);
64
+ },
25
65
  nodeViews: {
26
66
  expand: ExpandNodeView({
27
67
  getIntl: getIntl,
@@ -1,2 +1,3 @@
1
1
  import type { EditorCommand } from '@atlaskit/editor-common/types';
2
+ export declare const TOGGLE_EXPAND_RANGE_META_KEY = "toggleExpandRange";
2
3
  export declare const toggleExpandRange: (from?: number, to?: number, open?: boolean) => EditorCommand;
@@ -1,2 +1,3 @@
1
1
  import type { EditorCommand } from '@atlaskit/editor-common/types';
2
+ export declare const TOGGLE_EXPAND_RANGE_META_KEY = "toggleExpandRange";
2
3
  export declare const toggleExpandRange: (from?: number, to?: number, open?: boolean) => EditorCommand;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-expand",
3
- "version": "11.0.0",
3
+ "version": "11.0.1",
4
4
  "description": "Expand plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -109,6 +109,9 @@
109
109
  },
110
110
  "platform_editor_block_menu_v2_patch_3": {
111
111
  "type": "boolean"
112
+ },
113
+ "platform_editor_show_diff_scroll_navigation": {
114
+ "type": "boolean"
112
115
  }
113
116
  }
114
117
  }