@atlaskit/editor-plugin-alignment 31.0.4 → 31.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @atlaskit/editor-plugin-alignment
2
2
 
3
+ ## 31.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`34b177e64e741`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/34b177e64e741) -
8
+ Avoid building discarded alignment transactions and visiting every selected cell to locate the
9
+ final cell when checking alignment eligibility behind platform_editor_improve_inp_batch_2. Stop
10
+ scanning that cell after the first eligible block, and declare the experiment runtime dependency.
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies
15
+
16
+ ## 31.0.5
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies
21
+
3
22
  ## 31.0.4
4
23
 
5
24
  ### Patch Changes
@@ -8,6 +8,8 @@ var _enums = require("@atlaskit/editor-common/analytics/types/enums");
8
8
  var _commands = require("@atlaskit/editor-common/commands");
9
9
  var _withAnalytics = require("@atlaskit/editor-common/withAnalytics");
10
10
  var _state = require("@atlaskit/editor-prosemirror/state");
11
+ var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
12
+ var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
11
13
  /**
12
14
  * Iterates over the commands one after the other,
13
15
  * passes the tr through and dispatches the cumulated transaction
@@ -41,6 +43,37 @@ var isAlignable = exports.isAlignable = function isAlignable(align) {
41
43
  paragraph = _state$schema$nodes.paragraph,
42
44
  heading = _state$schema$nodes.heading,
43
45
  alignment = _state$schema.marks.alignment;
46
+ if (!dispatch && state.selection instanceof _cellSelection.CellSelection && (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_improve_inp_batch_2')) {
47
+ if (!align) {
48
+ return false;
49
+ }
50
+
51
+ // toggleBlockMark returns the result of the last cell, rather than
52
+ // combining results. Preserve that behavior without building a transaction.
53
+ // CellSelection moves the head range first, leaving the rest in document
54
+ // order. Compare both ends to find the final cell visited by forEachCell.
55
+ var ranges = state.selection.ranges;
56
+ var firstRange = ranges[0];
57
+ var lastRange = ranges[ranges.length - 1];
58
+ var lastCellRange = firstRange.$from.pos > lastRange.$from.pos ? firstRange : lastRange;
59
+ var lastCell = lastCellRange.$from.parent;
60
+ var _hasAlignableBlock = function hasAlignableBlock(parent) {
61
+ for (var index = 0; index < parent.childCount; index++) {
62
+ var node = parent.child(index);
63
+ if (!node.isBlock) {
64
+ continue;
65
+ }
66
+ if ((node.type === paragraph || node.type === heading) && parent.type.allowsMarkType(alignment)) {
67
+ return true;
68
+ }
69
+ if (_hasAlignableBlock(node)) {
70
+ return true;
71
+ }
72
+ }
73
+ return false;
74
+ };
75
+ return _hasAlignableBlock(lastCell);
76
+ }
44
77
  return (0, _commands.toggleBlockMark)(alignment, function () {
45
78
  return !align ? undefined : align === 'start' ? false : {
46
79
  align: align
@@ -2,6 +2,8 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit
2
2
  import { changeImageAlignment, changeImageAlignmentNext, toggleBlockMark, toggleBlockMarkNext } from '@atlaskit/editor-common/commands';
3
3
  import { withAnalytics } from '@atlaskit/editor-common/withAnalytics';
4
4
  import { Selection } from '@atlaskit/editor-prosemirror/state';
5
+ import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
6
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
5
7
  /**
6
8
  * Iterates over the commands one after the other,
7
9
  * passes the tr through and dispatches the cumulated transaction
@@ -38,6 +40,39 @@ export const isAlignable = align => (state, dispatch) => {
38
40
  alignment
39
41
  }
40
42
  } = state.schema;
43
+ if (!dispatch && state.selection instanceof CellSelection && isExperimentEnabled('platform_editor_improve_inp_batch_2')) {
44
+ if (!align) {
45
+ return false;
46
+ }
47
+
48
+ // toggleBlockMark returns the result of the last cell, rather than
49
+ // combining results. Preserve that behavior without building a transaction.
50
+ // CellSelection moves the head range first, leaving the rest in document
51
+ // order. Compare both ends to find the final cell visited by forEachCell.
52
+ const {
53
+ ranges
54
+ } = state.selection;
55
+ const firstRange = ranges[0];
56
+ const lastRange = ranges[ranges.length - 1];
57
+ const lastCellRange = firstRange.$from.pos > lastRange.$from.pos ? firstRange : lastRange;
58
+ const lastCell = lastCellRange.$from.parent;
59
+ const hasAlignableBlock = parent => {
60
+ for (let index = 0; index < parent.childCount; index++) {
61
+ const node = parent.child(index);
62
+ if (!node.isBlock) {
63
+ continue;
64
+ }
65
+ if ((node.type === paragraph || node.type === heading) && parent.type.allowsMarkType(alignment)) {
66
+ return true;
67
+ }
68
+ if (hasAlignableBlock(node)) {
69
+ return true;
70
+ }
71
+ }
72
+ return false;
73
+ };
74
+ return hasAlignableBlock(lastCell);
75
+ }
41
76
  return toggleBlockMark(alignment, () => !align ? undefined : align === 'start' ? false : {
42
77
  align
43
78
  }, [paragraph, heading])(state, dispatch);
@@ -2,6 +2,8 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit
2
2
  import { changeImageAlignment, changeImageAlignmentNext, toggleBlockMark, toggleBlockMarkNext } from '@atlaskit/editor-common/commands';
3
3
  import { withAnalytics } from '@atlaskit/editor-common/withAnalytics';
4
4
  import { Selection } from '@atlaskit/editor-prosemirror/state';
5
+ import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
6
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
5
7
  /**
6
8
  * Iterates over the commands one after the other,
7
9
  * passes the tr through and dispatches the cumulated transaction
@@ -35,6 +37,37 @@ export var isAlignable = function isAlignable(align) {
35
37
  paragraph = _state$schema$nodes.paragraph,
36
38
  heading = _state$schema$nodes.heading,
37
39
  alignment = _state$schema.marks.alignment;
40
+ if (!dispatch && state.selection instanceof CellSelection && isExperimentEnabled('platform_editor_improve_inp_batch_2')) {
41
+ if (!align) {
42
+ return false;
43
+ }
44
+
45
+ // toggleBlockMark returns the result of the last cell, rather than
46
+ // combining results. Preserve that behavior without building a transaction.
47
+ // CellSelection moves the head range first, leaving the rest in document
48
+ // order. Compare both ends to find the final cell visited by forEachCell.
49
+ var ranges = state.selection.ranges;
50
+ var firstRange = ranges[0];
51
+ var lastRange = ranges[ranges.length - 1];
52
+ var lastCellRange = firstRange.$from.pos > lastRange.$from.pos ? firstRange : lastRange;
53
+ var lastCell = lastCellRange.$from.parent;
54
+ var _hasAlignableBlock = function hasAlignableBlock(parent) {
55
+ for (var index = 0; index < parent.childCount; index++) {
56
+ var node = parent.child(index);
57
+ if (!node.isBlock) {
58
+ continue;
59
+ }
60
+ if ((node.type === paragraph || node.type === heading) && parent.type.allowsMarkType(alignment)) {
61
+ return true;
62
+ }
63
+ if (_hasAlignableBlock(node)) {
64
+ return true;
65
+ }
66
+ }
67
+ return false;
68
+ };
69
+ return _hasAlignableBlock(lastCell);
70
+ }
38
71
  return toggleBlockMark(alignment, function () {
39
72
  return !align ? undefined : align === 'start' ? false : {
40
73
  align: align
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-alignment",
3
- "version": "31.0.4",
3
+ "version": "31.1.0",
4
4
  "description": "Alignment plugin for @atlaskit/editor-core",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -32,13 +32,14 @@
32
32
  "@atlaskit/editor-tables": "^3.2.0",
33
33
  "@atlaskit/editor-toolbar": "^2.8.0",
34
34
  "@atlaskit/icon": "^38.0.0",
35
- "@atlaskit/tmp-editor-statsig": "^249.0.0",
36
- "@atlaskit/tokens": "^20.8.0",
35
+ "@atlaskit/platform-feature-experiments": "^0.3.0",
36
+ "@atlaskit/tmp-editor-statsig": "^250.0.0",
37
+ "@atlaskit/tokens": "^20.9.0",
37
38
  "@babel/runtime": "^7.0.0",
38
39
  "@compiled/react": "^1.0.2"
39
40
  },
40
41
  "peerDependencies": {
41
- "@atlaskit/editor-common": "^134.2.0",
42
+ "@atlaskit/editor-common": "^134.4.0",
42
43
  "react": "^18.2.0 || ^19.2.0",
43
44
  "react-dom": "^18.2.0 || ^19.2.0",
44
45
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"