@atlaskit/editor-plugin-table 23.1.1 → 23.1.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 23.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`cac6bd11a2e56`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/cac6bd11a2e56) -
8
+ CCI-16976 Fixed position out of range error coming from table behind feature gate
9
+ platform_editor_ai_table_ai_streaming_pos_fix
10
+
3
11
  ## 23.1.1
4
12
 
5
13
  ### Patch Changes
@@ -17,6 +17,7 @@ var _nesting = require("@atlaskit/editor-common/nesting");
17
17
  var _nodeVisibility = require("@atlaskit/editor-common/node-visibility");
18
18
  var _ui = require("@atlaskit/editor-common/ui");
19
19
  var _utils = require("@atlaskit/editor-prosemirror/utils");
20
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
20
21
  var _pluginFactory = require("../pm-plugins/plugin-factory");
21
22
  var _pluginKey = require("../pm-plugins/plugin-key");
22
23
  var _commands = require("../pm-plugins/sticky-headers/commands");
@@ -476,17 +477,38 @@ var TableRow = exports.default = /*#__PURE__*/function (_TableNodeView) {
476
477
  navigator.userAgent.includes('AppleWebKit') && !navigator.userAgent.includes('Chrome')) {
477
478
  var pos = this.getPos();
478
479
  if (typeof pos === 'number') {
479
- var $tableRowPos = this.view.state.doc.resolve(pos);
480
-
481
- // layout -> layout column -> table -> table row
482
- if ($tableRowPos.depth >= 3) {
483
- var _findParentNodeCloses;
484
- var isInsideLayout = (_findParentNodeCloses = (0, _utils.findParentNodeClosestToPos)($tableRowPos, function (node) {
485
- return node.type.name === 'layoutColumn';
486
- })) === null || _findParentNodeCloses === void 0 ? void 0 : _findParentNodeCloses.node;
487
- if (isInsideLayout) {
480
+ if ((0, _platformFeatureFlags.fg)('platform_editor_ai_table_ai_streaming_pos_fix')) {
481
+ try {
482
+ // getPos can return stale positions during AI streaming which cannot be resolved
483
+ var $tableRowPos = this.view.state.doc.resolve(pos);
484
+
485
+ // layout -> layout column -> table -> table row
486
+ if ($tableRowPos.depth >= 3) {
487
+ var _findParentNodeCloses;
488
+ var isInsideLayout = (_findParentNodeCloses = (0, _utils.findParentNodeClosestToPos)($tableRowPos, function (node) {
489
+ return node.type.name === 'layoutColumn';
490
+ })) === null || _findParentNodeCloses === void 0 ? void 0 : _findParentNodeCloses.node;
491
+ if (isInsideLayout) {
492
+ return false;
493
+ }
494
+ }
495
+ } catch (_unused2) {
496
+ // getPos can return stale positions during AI streaming — fall back to non-sticky
488
497
  return false;
489
498
  }
499
+ } else {
500
+ var _$tableRowPos = this.view.state.doc.resolve(pos);
501
+
502
+ // layout -> layout column -> table -> table row
503
+ if (_$tableRowPos.depth >= 3) {
504
+ var _findParentNodeCloses2;
505
+ var _isInsideLayout = (_findParentNodeCloses2 = (0, _utils.findParentNodeClosestToPos)(_$tableRowPos, function (node) {
506
+ return node.type.name === 'layoutColumn';
507
+ })) === null || _findParentNodeCloses2 === void 0 ? void 0 : _findParentNodeCloses2.node;
508
+ if (_isInsideLayout) {
509
+ return false;
510
+ }
511
+ }
490
512
  }
491
513
  }
492
514
  }
@@ -121,8 +121,22 @@ var TableRowNativeStickyWithFallback = exports.default = /*#__PURE__*/function (
121
121
  }
122
122
  var pos = _this.getPos();
123
123
  _this.isInNestedTable = false;
124
- if (pos) {
125
- _this.isInNestedTable = (0, _nesting.getParentOfTypeCount)(view.state.schema.nodes.table)(view.state.doc.resolve(pos)) > 1;
124
+ if ((0, _platformFeatureFlags.fg)('platform_editor_ai_table_ai_streaming_pos_fix')) {
125
+ try {
126
+ // We cannot trust that the value from getPos will be defined
127
+ // https://discuss.prosemirror.net/t/getpos-is-undefined-in-nodeview-constructor/1246/4
128
+ // There are also scenarios where the value it brings back does not tally with the current doc
129
+ // E.g. when AI streaming brings in new content, this position brings back incorrect values that cannot be resolved
130
+ if (pos) {
131
+ _this.isInNestedTable = (0, _nesting.getParentOfTypeCount)(view.state.schema.nodes.table)(view.state.doc.resolve(pos)) > 1;
132
+ }
133
+ } catch (_unused) {
134
+ // Intentionally swallowed — getPos can return stale positions during AI streaming
135
+ }
136
+ } else {
137
+ if (pos) {
138
+ _this.isInNestedTable = (0, _nesting.getParentOfTypeCount)(view.state.schema.nodes.table)(view.state.doc.resolve(pos)) > 1;
139
+ }
126
140
  }
127
141
  if (_this.isHeaderRow) {
128
142
  _this.dom.setAttribute('data-vc-nvs', 'true');
@@ -711,17 +725,38 @@ var TableRowNativeStickyWithFallback = exports.default = /*#__PURE__*/function (
711
725
  navigator.userAgent.includes('AppleWebKit') && !navigator.userAgent.includes('Chrome')) {
712
726
  var pos = this.getPos();
713
727
  if (typeof pos === 'number') {
714
- var $tableRowPos = this.view.state.doc.resolve(pos);
715
-
716
- // layout -> layout column -> table -> table row
717
- if ($tableRowPos.depth >= 3) {
718
- var _findParentNodeCloses;
719
- var isInsideLayout = (_findParentNodeCloses = (0, _utils.findParentNodeClosestToPos)($tableRowPos, function (node) {
720
- return node.type.name === 'layoutColumn';
721
- })) === null || _findParentNodeCloses === void 0 ? void 0 : _findParentNodeCloses.node;
722
- if (isInsideLayout) {
728
+ if ((0, _platformFeatureFlags.fg)('platform_editor_ai_table_ai_streaming_pos_fix')) {
729
+ try {
730
+ // getPos can return stale positions during AI streaming which cannot be resolved
731
+ var $tableRowPos = this.view.state.doc.resolve(pos);
732
+
733
+ // layout -> layout column -> table -> table row
734
+ if ($tableRowPos.depth >= 3) {
735
+ var _findParentNodeCloses;
736
+ var isInsideLayout = (_findParentNodeCloses = (0, _utils.findParentNodeClosestToPos)($tableRowPos, function (node) {
737
+ return node.type.name === 'layoutColumn';
738
+ })) === null || _findParentNodeCloses === void 0 ? void 0 : _findParentNodeCloses.node;
739
+ if (isInsideLayout) {
740
+ return false;
741
+ }
742
+ }
743
+ } catch (_unused2) {
744
+ // getPos can return stale positions during AI streaming — fall back to non-sticky
723
745
  return false;
724
746
  }
747
+ } else {
748
+ var _$tableRowPos = this.view.state.doc.resolve(pos);
749
+
750
+ // layout -> layout column -> table -> table row
751
+ if (_$tableRowPos.depth >= 3) {
752
+ var _findParentNodeCloses2;
753
+ var _isInsideLayout = (_findParentNodeCloses2 = (0, _utils.findParentNodeClosestToPos)(_$tableRowPos, function (node) {
754
+ return node.type.name === 'layoutColumn';
755
+ })) === null || _findParentNodeCloses2 === void 0 ? void 0 : _findParentNodeCloses2.node;
756
+ if (_isInsideLayout) {
757
+ return false;
758
+ }
759
+ }
725
760
  }
726
761
  }
727
762
  }
@@ -5,6 +5,7 @@ import { getParentOfTypeCount } from '@atlaskit/editor-common/nesting';
5
5
  import { nodeVisibilityManager } from '@atlaskit/editor-common/node-visibility';
6
6
  import { findOverflowScrollParent } from '@atlaskit/editor-common/ui';
7
7
  import { findParentNodeClosestToPos } from '@atlaskit/editor-prosemirror/utils';
8
+ import { fg } from '@atlaskit/platform-feature-flags';
8
9
  import { getPluginState } from '../pm-plugins/plugin-factory';
9
10
  import { pluginKey as tablePluginKey } from '../pm-plugins/plugin-key';
10
11
  import { updateStickyState } from '../pm-plugins/sticky-headers/commands';
@@ -437,17 +438,38 @@ export default class TableRow extends TableNodeView {
437
438
  navigator.userAgent.includes('AppleWebKit') && !navigator.userAgent.includes('Chrome')) {
438
439
  const pos = this.getPos();
439
440
  if (typeof pos === 'number') {
440
- const $tableRowPos = this.view.state.doc.resolve(pos);
441
-
442
- // layout -> layout column -> table -> table row
443
- if ($tableRowPos.depth >= 3) {
444
- var _findParentNodeCloses;
445
- const isInsideLayout = (_findParentNodeCloses = findParentNodeClosestToPos($tableRowPos, node => {
446
- return node.type.name === 'layoutColumn';
447
- })) === null || _findParentNodeCloses === void 0 ? void 0 : _findParentNodeCloses.node;
448
- if (isInsideLayout) {
441
+ if (fg('platform_editor_ai_table_ai_streaming_pos_fix')) {
442
+ try {
443
+ // getPos can return stale positions during AI streaming which cannot be resolved
444
+ const $tableRowPos = this.view.state.doc.resolve(pos);
445
+
446
+ // layout -> layout column -> table -> table row
447
+ if ($tableRowPos.depth >= 3) {
448
+ var _findParentNodeCloses;
449
+ const isInsideLayout = (_findParentNodeCloses = findParentNodeClosestToPos($tableRowPos, node => {
450
+ return node.type.name === 'layoutColumn';
451
+ })) === null || _findParentNodeCloses === void 0 ? void 0 : _findParentNodeCloses.node;
452
+ if (isInsideLayout) {
453
+ return false;
454
+ }
455
+ }
456
+ } catch {
457
+ // getPos can return stale positions during AI streaming — fall back to non-sticky
449
458
  return false;
450
459
  }
460
+ } else {
461
+ const $tableRowPos = this.view.state.doc.resolve(pos);
462
+
463
+ // layout -> layout column -> table -> table row
464
+ if ($tableRowPos.depth >= 3) {
465
+ var _findParentNodeCloses2;
466
+ const isInsideLayout = (_findParentNodeCloses2 = findParentNodeClosestToPos($tableRowPos, node => {
467
+ return node.type.name === 'layoutColumn';
468
+ })) === null || _findParentNodeCloses2 === void 0 ? void 0 : _findParentNodeCloses2.node;
469
+ if (isInsideLayout) {
470
+ return false;
471
+ }
472
+ }
451
473
  }
452
474
  }
453
475
  }
@@ -106,8 +106,22 @@ export default class TableRowNativeStickyWithFallback extends TableNodeView {
106
106
  }
107
107
  const pos = this.getPos();
108
108
  this.isInNestedTable = false;
109
- if (pos) {
110
- this.isInNestedTable = getParentOfTypeCount(view.state.schema.nodes.table)(view.state.doc.resolve(pos)) > 1;
109
+ if (fg('platform_editor_ai_table_ai_streaming_pos_fix')) {
110
+ try {
111
+ // We cannot trust that the value from getPos will be defined
112
+ // https://discuss.prosemirror.net/t/getpos-is-undefined-in-nodeview-constructor/1246/4
113
+ // There are also scenarios where the value it brings back does not tally with the current doc
114
+ // E.g. when AI streaming brings in new content, this position brings back incorrect values that cannot be resolved
115
+ if (pos) {
116
+ this.isInNestedTable = getParentOfTypeCount(view.state.schema.nodes.table)(view.state.doc.resolve(pos)) > 1;
117
+ }
118
+ } catch {
119
+ // Intentionally swallowed — getPos can return stale positions during AI streaming
120
+ }
121
+ } else {
122
+ if (pos) {
123
+ this.isInNestedTable = getParentOfTypeCount(view.state.schema.nodes.table)(view.state.doc.resolve(pos)) > 1;
124
+ }
111
125
  }
112
126
  if (this.isHeaderRow) {
113
127
  this.dom.setAttribute('data-vc-nvs', 'true');
@@ -663,17 +677,38 @@ export default class TableRowNativeStickyWithFallback extends TableNodeView {
663
677
  navigator.userAgent.includes('AppleWebKit') && !navigator.userAgent.includes('Chrome')) {
664
678
  const pos = this.getPos();
665
679
  if (typeof pos === 'number') {
666
- const $tableRowPos = this.view.state.doc.resolve(pos);
667
-
668
- // layout -> layout column -> table -> table row
669
- if ($tableRowPos.depth >= 3) {
670
- var _findParentNodeCloses;
671
- const isInsideLayout = (_findParentNodeCloses = findParentNodeClosestToPos($tableRowPos, node => {
672
- return node.type.name === 'layoutColumn';
673
- })) === null || _findParentNodeCloses === void 0 ? void 0 : _findParentNodeCloses.node;
674
- if (isInsideLayout) {
680
+ if (fg('platform_editor_ai_table_ai_streaming_pos_fix')) {
681
+ try {
682
+ // getPos can return stale positions during AI streaming which cannot be resolved
683
+ const $tableRowPos = this.view.state.doc.resolve(pos);
684
+
685
+ // layout -> layout column -> table -> table row
686
+ if ($tableRowPos.depth >= 3) {
687
+ var _findParentNodeCloses;
688
+ const isInsideLayout = (_findParentNodeCloses = findParentNodeClosestToPos($tableRowPos, node => {
689
+ return node.type.name === 'layoutColumn';
690
+ })) === null || _findParentNodeCloses === void 0 ? void 0 : _findParentNodeCloses.node;
691
+ if (isInsideLayout) {
692
+ return false;
693
+ }
694
+ }
695
+ } catch {
696
+ // getPos can return stale positions during AI streaming — fall back to non-sticky
675
697
  return false;
676
698
  }
699
+ } else {
700
+ const $tableRowPos = this.view.state.doc.resolve(pos);
701
+
702
+ // layout -> layout column -> table -> table row
703
+ if ($tableRowPos.depth >= 3) {
704
+ var _findParentNodeCloses2;
705
+ const isInsideLayout = (_findParentNodeCloses2 = findParentNodeClosestToPos($tableRowPos, node => {
706
+ return node.type.name === 'layoutColumn';
707
+ })) === null || _findParentNodeCloses2 === void 0 ? void 0 : _findParentNodeCloses2.node;
708
+ if (isInsideLayout) {
709
+ return false;
710
+ }
711
+ }
677
712
  }
678
713
  }
679
714
  }
@@ -12,6 +12,7 @@ import { getParentOfTypeCount } from '@atlaskit/editor-common/nesting';
12
12
  import { nodeVisibilityManager } from '@atlaskit/editor-common/node-visibility';
13
13
  import { findOverflowScrollParent } from '@atlaskit/editor-common/ui';
14
14
  import { findParentNodeClosestToPos } from '@atlaskit/editor-prosemirror/utils';
15
+ import { fg } from '@atlaskit/platform-feature-flags';
15
16
  import { getPluginState } from '../pm-plugins/plugin-factory';
16
17
  import { pluginKey as tablePluginKey } from '../pm-plugins/plugin-key';
17
18
  import { updateStickyState } from '../pm-plugins/sticky-headers/commands';
@@ -469,17 +470,38 @@ var TableRow = /*#__PURE__*/function (_TableNodeView) {
469
470
  navigator.userAgent.includes('AppleWebKit') && !navigator.userAgent.includes('Chrome')) {
470
471
  var pos = this.getPos();
471
472
  if (typeof pos === 'number') {
472
- var $tableRowPos = this.view.state.doc.resolve(pos);
473
-
474
- // layout -> layout column -> table -> table row
475
- if ($tableRowPos.depth >= 3) {
476
- var _findParentNodeCloses;
477
- var isInsideLayout = (_findParentNodeCloses = findParentNodeClosestToPos($tableRowPos, function (node) {
478
- return node.type.name === 'layoutColumn';
479
- })) === null || _findParentNodeCloses === void 0 ? void 0 : _findParentNodeCloses.node;
480
- if (isInsideLayout) {
473
+ if (fg('platform_editor_ai_table_ai_streaming_pos_fix')) {
474
+ try {
475
+ // getPos can return stale positions during AI streaming which cannot be resolved
476
+ var $tableRowPos = this.view.state.doc.resolve(pos);
477
+
478
+ // layout -> layout column -> table -> table row
479
+ if ($tableRowPos.depth >= 3) {
480
+ var _findParentNodeCloses;
481
+ var isInsideLayout = (_findParentNodeCloses = findParentNodeClosestToPos($tableRowPos, function (node) {
482
+ return node.type.name === 'layoutColumn';
483
+ })) === null || _findParentNodeCloses === void 0 ? void 0 : _findParentNodeCloses.node;
484
+ if (isInsideLayout) {
485
+ return false;
486
+ }
487
+ }
488
+ } catch (_unused2) {
489
+ // getPos can return stale positions during AI streaming — fall back to non-sticky
481
490
  return false;
482
491
  }
492
+ } else {
493
+ var _$tableRowPos = this.view.state.doc.resolve(pos);
494
+
495
+ // layout -> layout column -> table -> table row
496
+ if (_$tableRowPos.depth >= 3) {
497
+ var _findParentNodeCloses2;
498
+ var _isInsideLayout = (_findParentNodeCloses2 = findParentNodeClosestToPos(_$tableRowPos, function (node) {
499
+ return node.type.name === 'layoutColumn';
500
+ })) === null || _findParentNodeCloses2 === void 0 ? void 0 : _findParentNodeCloses2.node;
501
+ if (_isInsideLayout) {
502
+ return false;
503
+ }
504
+ }
483
505
  }
484
506
  }
485
507
  }
@@ -114,8 +114,22 @@ var TableRowNativeStickyWithFallback = /*#__PURE__*/function (_TableNodeView) {
114
114
  }
115
115
  var pos = _this.getPos();
116
116
  _this.isInNestedTable = false;
117
- if (pos) {
118
- _this.isInNestedTable = getParentOfTypeCount(view.state.schema.nodes.table)(view.state.doc.resolve(pos)) > 1;
117
+ if (fg('platform_editor_ai_table_ai_streaming_pos_fix')) {
118
+ try {
119
+ // We cannot trust that the value from getPos will be defined
120
+ // https://discuss.prosemirror.net/t/getpos-is-undefined-in-nodeview-constructor/1246/4
121
+ // There are also scenarios where the value it brings back does not tally with the current doc
122
+ // E.g. when AI streaming brings in new content, this position brings back incorrect values that cannot be resolved
123
+ if (pos) {
124
+ _this.isInNestedTable = getParentOfTypeCount(view.state.schema.nodes.table)(view.state.doc.resolve(pos)) > 1;
125
+ }
126
+ } catch (_unused) {
127
+ // Intentionally swallowed — getPos can return stale positions during AI streaming
128
+ }
129
+ } else {
130
+ if (pos) {
131
+ _this.isInNestedTable = getParentOfTypeCount(view.state.schema.nodes.table)(view.state.doc.resolve(pos)) > 1;
132
+ }
119
133
  }
120
134
  if (_this.isHeaderRow) {
121
135
  _this.dom.setAttribute('data-vc-nvs', 'true');
@@ -704,17 +718,38 @@ var TableRowNativeStickyWithFallback = /*#__PURE__*/function (_TableNodeView) {
704
718
  navigator.userAgent.includes('AppleWebKit') && !navigator.userAgent.includes('Chrome')) {
705
719
  var pos = this.getPos();
706
720
  if (typeof pos === 'number') {
707
- var $tableRowPos = this.view.state.doc.resolve(pos);
708
-
709
- // layout -> layout column -> table -> table row
710
- if ($tableRowPos.depth >= 3) {
711
- var _findParentNodeCloses;
712
- var isInsideLayout = (_findParentNodeCloses = findParentNodeClosestToPos($tableRowPos, function (node) {
713
- return node.type.name === 'layoutColumn';
714
- })) === null || _findParentNodeCloses === void 0 ? void 0 : _findParentNodeCloses.node;
715
- if (isInsideLayout) {
721
+ if (fg('platform_editor_ai_table_ai_streaming_pos_fix')) {
722
+ try {
723
+ // getPos can return stale positions during AI streaming which cannot be resolved
724
+ var $tableRowPos = this.view.state.doc.resolve(pos);
725
+
726
+ // layout -> layout column -> table -> table row
727
+ if ($tableRowPos.depth >= 3) {
728
+ var _findParentNodeCloses;
729
+ var isInsideLayout = (_findParentNodeCloses = findParentNodeClosestToPos($tableRowPos, function (node) {
730
+ return node.type.name === 'layoutColumn';
731
+ })) === null || _findParentNodeCloses === void 0 ? void 0 : _findParentNodeCloses.node;
732
+ if (isInsideLayout) {
733
+ return false;
734
+ }
735
+ }
736
+ } catch (_unused2) {
737
+ // getPos can return stale positions during AI streaming — fall back to non-sticky
716
738
  return false;
717
739
  }
740
+ } else {
741
+ var _$tableRowPos = this.view.state.doc.resolve(pos);
742
+
743
+ // layout -> layout column -> table -> table row
744
+ if (_$tableRowPos.depth >= 3) {
745
+ var _findParentNodeCloses2;
746
+ var _isInsideLayout = (_findParentNodeCloses2 = findParentNodeClosestToPos(_$tableRowPos, function (node) {
747
+ return node.type.name === 'layoutColumn';
748
+ })) === null || _findParentNodeCloses2 === void 0 ? void 0 : _findParentNodeCloses2.node;
749
+ if (_isInsideLayout) {
750
+ return false;
751
+ }
752
+ }
718
753
  }
719
754
  }
720
755
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "23.1.1",
3
+ "version": "23.1.2",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -62,7 +62,7 @@
62
62
  "@atlaskit/primitives": "^19.0.0",
63
63
  "@atlaskit/tmp-editor-statsig": "^89.1.0",
64
64
  "@atlaskit/toggle": "^16.1.0",
65
- "@atlaskit/tokens": "^13.1.0",
65
+ "@atlaskit/tokens": "^13.2.0",
66
66
  "@atlaskit/tooltip": "^22.6.0",
67
67
  "@babel/runtime": "^7.0.0",
68
68
  "@compiled/react": "^0.20.0",
@@ -170,6 +170,9 @@
170
170
  },
171
171
  "platform_editor_max_width_default_width": {
172
172
  "type": "boolean"
173
+ },
174
+ "platform_editor_ai_table_ai_streaming_pos_fix": {
175
+ "type": "boolean"
173
176
  }
174
177
  },
175
178
  "devDependencies": {