@atlaskit/editor-plugin-table 10.5.6 → 10.5.7

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,11 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 10.5.7
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
3
9
  ## 10.5.6
4
10
 
5
11
  ### Patch Changes
@@ -12,6 +12,7 @@ var _nesting = require("@atlaskit/editor-common/nesting");
12
12
  var _utils = require("@atlaskit/editor-common/utils");
13
13
  var _model = require("@atlaskit/editor-prosemirror/model");
14
14
  var _utils2 = require("@atlaskit/editor-prosemirror/utils");
15
+ var _editorTables = require("@atlaskit/editor-tables");
15
16
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
16
17
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
17
18
  var _pluginFactory = require("../plugin-factory");
@@ -81,16 +82,19 @@ var transformSliceToRemoveNestedTables = exports.transformSliceToRemoveNestedTab
81
82
  tableHeader = _schema$nodes2.tableHeader;
82
83
  var openEnd = slice.openEnd;
83
84
  var newFragment = (0, _utils.flatmap)(slice.content, function (node, i, fragment) {
85
+ var _slice$content$firstC;
84
86
  // if pasted content is a node that supports nesting a table
85
87
  // such as layoutSection or expand allow 1 level by default
86
88
  var allowedTableNesting = 1;
87
- if (isNestingAllowed) {
88
- var _slice$content$firstC, _slice$content$lastCh;
89
- var isPasteInTable = (0, _utils2.hasParentNodeOfType)([table, tableCell, tableHeader])(selection);
90
- var isPasteInNestedTable = (0, _nesting.getParentOfTypeCount)(schema.nodes.table)(selection.$from) > 1;
91
- var isPasteFullTableInsideEmptyCellEnabled = (0, _platformFeatureFlags.fg)('platform_editor_paste_full_table_inside_empty_cell');
92
- var isCellPaste = isPasteInTable && slice.content.childCount === 1 && ((_slice$content$firstC = slice.content.firstChild) === null || _slice$content$firstC === void 0 ? void 0 : _slice$content$firstC.type) === table && (!isPasteFullTableInsideEmptyCellEnabled || slice.openStart !== 0 && slice.openEnd !== 0);
89
+ var isCellSelection = selection instanceof _editorTables.CellSelection;
90
+ var isPasteInTable = (0, _utils2.hasParentNodeOfType)([table, tableCell, tableHeader])(selection);
91
+ var isPasteInNestedTable = (0, _nesting.getParentOfTypeCount)(schema.nodes.table)(selection.$from) > 1;
92
+ var isPasteFullTableInsideEmptyCellEnabled = (0, _platformFeatureFlags.fg)('platform_editor_paste_full_table_inside_empty_cell');
93
93
 
94
+ // Pasted content only contains a table and no other content
95
+ var isCellPaste = isPasteInTable && slice.content.childCount === 1 && ((_slice$content$firstC = slice.content.firstChild) === null || _slice$content$firstC === void 0 ? void 0 : _slice$content$firstC.type) === table && (!isPasteFullTableInsideEmptyCellEnabled || slice.openStart !== 0 && slice.openEnd !== 0);
96
+ if (isNestingAllowed) {
97
+ var _slice$content$lastCh;
94
98
  // if nesting is allowed we bump up the default nesting allowance to 2 to support
95
99
  // two levels of nesting in nodes that support table nesting already such as layoutSection and expands
96
100
  allowedTableNesting = 2;
@@ -112,7 +116,7 @@ var transformSliceToRemoveNestedTables = exports.transformSliceToRemoveNestedTab
112
116
 
113
117
  // paste of table cells into a table cell - content is spread across multiple cells
114
118
  // by editor-tables so needs to be treated a little differently
115
- if (isCellPaste) {
119
+ if (isCellPaste || isCellSelection && (0, _platformFeatureFlags.fg)('platform_editor_nested_tables_cellselection_paste')) {
116
120
  allowedTableNesting = 1;
117
121
  if (isPasteInNestedTable) {
118
122
  allowedTableNesting = 0;
@@ -138,10 +142,14 @@ var transformSliceToRemoveNestedTables = exports.transformSliceToRemoveNestedTab
138
142
  allowedTableNesting = 0;
139
143
  }
140
144
  }
141
-
142
- // after we've worked out what the allowed nesting depth is, unwrap nested tables
143
- var newChildren = _unwrapNestedTables(node.content, schema, allowedTableNesting);
144
- return node.copy(_model.Fragment.fromArray(newChildren));
145
+ if (isCellSelection && !isCellPaste && (0, _platformFeatureFlags.fg)('platform_editor_nested_tables_cellselection_paste')) {
146
+ // if pasting into a cell selection, we need to flatten the parent table as well
147
+ return _unwrapNestedTables(_model.Fragment.fromArray([node]), schema, allowedTableNesting);
148
+ } else {
149
+ // after we've worked out what the allowed nesting depth is, unwrap nested tables
150
+ var newChildren = _unwrapNestedTables(node.content, schema, allowedTableNesting);
151
+ return node.copy(_model.Fragment.fromArray(newChildren));
152
+ }
145
153
  });
146
154
  return new _model.Slice(newFragment, slice.openStart, openEnd);
147
155
  };
@@ -2,6 +2,7 @@ import { getParentOfTypeCount } from '@atlaskit/editor-common/nesting';
2
2
  import { flatmap, mapChildren, mapSlice } from '@atlaskit/editor-common/utils';
3
3
  import { Slice, Fragment } from '@atlaskit/editor-prosemirror/model';
4
4
  import { flatten, hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
5
+ import { CellSelection } from '@atlaskit/editor-tables';
5
6
  import { fg } from '@atlaskit/platform-feature-flags';
6
7
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
7
8
  import { getPluginState } from '../plugin-factory';
@@ -71,16 +72,19 @@ export const transformSliceToRemoveNestedTables = (slice, schema, selection) =>
71
72
  } = schema.nodes;
72
73
  let openEnd = slice.openEnd;
73
74
  const newFragment = flatmap(slice.content, (node, i, fragment) => {
75
+ var _slice$content$firstC;
74
76
  // if pasted content is a node that supports nesting a table
75
77
  // such as layoutSection or expand allow 1 level by default
76
78
  let allowedTableNesting = 1;
77
- if (isNestingAllowed) {
78
- var _slice$content$firstC, _slice$content$lastCh;
79
- const isPasteInTable = hasParentNodeOfType([table, tableCell, tableHeader])(selection);
80
- const isPasteInNestedTable = getParentOfTypeCount(schema.nodes.table)(selection.$from) > 1;
81
- const isPasteFullTableInsideEmptyCellEnabled = fg('platform_editor_paste_full_table_inside_empty_cell');
82
- const isCellPaste = isPasteInTable && slice.content.childCount === 1 && ((_slice$content$firstC = slice.content.firstChild) === null || _slice$content$firstC === void 0 ? void 0 : _slice$content$firstC.type) === table && (!isPasteFullTableInsideEmptyCellEnabled || slice.openStart !== 0 && slice.openEnd !== 0);
79
+ const isCellSelection = selection instanceof CellSelection;
80
+ const isPasteInTable = hasParentNodeOfType([table, tableCell, tableHeader])(selection);
81
+ const isPasteInNestedTable = getParentOfTypeCount(schema.nodes.table)(selection.$from) > 1;
82
+ const isPasteFullTableInsideEmptyCellEnabled = fg('platform_editor_paste_full_table_inside_empty_cell');
83
83
 
84
+ // Pasted content only contains a table and no other content
85
+ const isCellPaste = isPasteInTable && slice.content.childCount === 1 && ((_slice$content$firstC = slice.content.firstChild) === null || _slice$content$firstC === void 0 ? void 0 : _slice$content$firstC.type) === table && (!isPasteFullTableInsideEmptyCellEnabled || slice.openStart !== 0 && slice.openEnd !== 0);
86
+ if (isNestingAllowed) {
87
+ var _slice$content$lastCh;
84
88
  // if nesting is allowed we bump up the default nesting allowance to 2 to support
85
89
  // two levels of nesting in nodes that support table nesting already such as layoutSection and expands
86
90
  allowedTableNesting = 2;
@@ -102,7 +106,7 @@ export const transformSliceToRemoveNestedTables = (slice, schema, selection) =>
102
106
 
103
107
  // paste of table cells into a table cell - content is spread across multiple cells
104
108
  // by editor-tables so needs to be treated a little differently
105
- if (isCellPaste) {
109
+ if (isCellPaste || isCellSelection && fg('platform_editor_nested_tables_cellselection_paste')) {
106
110
  allowedTableNesting = 1;
107
111
  if (isPasteInNestedTable) {
108
112
  allowedTableNesting = 0;
@@ -128,10 +132,14 @@ export const transformSliceToRemoveNestedTables = (slice, schema, selection) =>
128
132
  allowedTableNesting = 0;
129
133
  }
130
134
  }
131
-
132
- // after we've worked out what the allowed nesting depth is, unwrap nested tables
133
- const newChildren = unwrapNestedTables(node.content, schema, allowedTableNesting);
134
- return node.copy(Fragment.fromArray(newChildren));
135
+ if (isCellSelection && !isCellPaste && fg('platform_editor_nested_tables_cellselection_paste')) {
136
+ // if pasting into a cell selection, we need to flatten the parent table as well
137
+ return unwrapNestedTables(Fragment.fromArray([node]), schema, allowedTableNesting);
138
+ } else {
139
+ // after we've worked out what the allowed nesting depth is, unwrap nested tables
140
+ const newChildren = unwrapNestedTables(node.content, schema, allowedTableNesting);
141
+ return node.copy(Fragment.fromArray(newChildren));
142
+ }
135
143
  });
136
144
  return new Slice(newFragment, slice.openStart, openEnd);
137
145
  };
@@ -6,6 +6,7 @@ import { getParentOfTypeCount } from '@atlaskit/editor-common/nesting';
6
6
  import { flatmap, mapChildren, mapSlice } from '@atlaskit/editor-common/utils';
7
7
  import { Slice, Fragment } from '@atlaskit/editor-prosemirror/model';
8
8
  import { flatten, hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
9
+ import { CellSelection } from '@atlaskit/editor-tables';
9
10
  import { fg } from '@atlaskit/platform-feature-flags';
10
11
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
11
12
  import { getPluginState } from '../plugin-factory';
@@ -74,16 +75,19 @@ export var transformSliceToRemoveNestedTables = function transformSliceToRemoveN
74
75
  tableHeader = _schema$nodes2.tableHeader;
75
76
  var openEnd = slice.openEnd;
76
77
  var newFragment = flatmap(slice.content, function (node, i, fragment) {
78
+ var _slice$content$firstC;
77
79
  // if pasted content is a node that supports nesting a table
78
80
  // such as layoutSection or expand allow 1 level by default
79
81
  var allowedTableNesting = 1;
80
- if (isNestingAllowed) {
81
- var _slice$content$firstC, _slice$content$lastCh;
82
- var isPasteInTable = hasParentNodeOfType([table, tableCell, tableHeader])(selection);
83
- var isPasteInNestedTable = getParentOfTypeCount(schema.nodes.table)(selection.$from) > 1;
84
- var isPasteFullTableInsideEmptyCellEnabled = fg('platform_editor_paste_full_table_inside_empty_cell');
85
- var isCellPaste = isPasteInTable && slice.content.childCount === 1 && ((_slice$content$firstC = slice.content.firstChild) === null || _slice$content$firstC === void 0 ? void 0 : _slice$content$firstC.type) === table && (!isPasteFullTableInsideEmptyCellEnabled || slice.openStart !== 0 && slice.openEnd !== 0);
82
+ var isCellSelection = selection instanceof CellSelection;
83
+ var isPasteInTable = hasParentNodeOfType([table, tableCell, tableHeader])(selection);
84
+ var isPasteInNestedTable = getParentOfTypeCount(schema.nodes.table)(selection.$from) > 1;
85
+ var isPasteFullTableInsideEmptyCellEnabled = fg('platform_editor_paste_full_table_inside_empty_cell');
86
86
 
87
+ // Pasted content only contains a table and no other content
88
+ var isCellPaste = isPasteInTable && slice.content.childCount === 1 && ((_slice$content$firstC = slice.content.firstChild) === null || _slice$content$firstC === void 0 ? void 0 : _slice$content$firstC.type) === table && (!isPasteFullTableInsideEmptyCellEnabled || slice.openStart !== 0 && slice.openEnd !== 0);
89
+ if (isNestingAllowed) {
90
+ var _slice$content$lastCh;
87
91
  // if nesting is allowed we bump up the default nesting allowance to 2 to support
88
92
  // two levels of nesting in nodes that support table nesting already such as layoutSection and expands
89
93
  allowedTableNesting = 2;
@@ -105,7 +109,7 @@ export var transformSliceToRemoveNestedTables = function transformSliceToRemoveN
105
109
 
106
110
  // paste of table cells into a table cell - content is spread across multiple cells
107
111
  // by editor-tables so needs to be treated a little differently
108
- if (isCellPaste) {
112
+ if (isCellPaste || isCellSelection && fg('platform_editor_nested_tables_cellselection_paste')) {
109
113
  allowedTableNesting = 1;
110
114
  if (isPasteInNestedTable) {
111
115
  allowedTableNesting = 0;
@@ -131,10 +135,14 @@ export var transformSliceToRemoveNestedTables = function transformSliceToRemoveN
131
135
  allowedTableNesting = 0;
132
136
  }
133
137
  }
134
-
135
- // after we've worked out what the allowed nesting depth is, unwrap nested tables
136
- var newChildren = _unwrapNestedTables(node.content, schema, allowedTableNesting);
137
- return node.copy(Fragment.fromArray(newChildren));
138
+ if (isCellSelection && !isCellPaste && fg('platform_editor_nested_tables_cellselection_paste')) {
139
+ // if pasting into a cell selection, we need to flatten the parent table as well
140
+ return _unwrapNestedTables(Fragment.fromArray([node]), schema, allowedTableNesting);
141
+ } else {
142
+ // after we've worked out what the allowed nesting depth is, unwrap nested tables
143
+ var newChildren = _unwrapNestedTables(node.content, schema, allowedTableNesting);
144
+ return node.copy(Fragment.fromArray(newChildren));
145
+ }
138
146
  });
139
147
  return new Slice(newFragment, slice.openStart, openEnd);
140
148
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "10.5.6",
3
+ "version": "10.5.7",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -32,14 +32,14 @@
32
32
  "@atlaskit/adf-schema": "^47.6.0",
33
33
  "@atlaskit/button": "^22.0.0",
34
34
  "@atlaskit/custom-steps": "^0.11.0",
35
- "@atlaskit/editor-common": "^102.14.0",
35
+ "@atlaskit/editor-common": "^102.15.0",
36
36
  "@atlaskit/editor-palette": "^2.1.0",
37
37
  "@atlaskit/editor-plugin-accessibility-utils": "^2.0.0",
38
38
  "@atlaskit/editor-plugin-analytics": "^2.2.0",
39
39
  "@atlaskit/editor-plugin-batch-attribute-updates": "^2.1.0",
40
40
  "@atlaskit/editor-plugin-content-insertion": "^2.1.0",
41
41
  "@atlaskit/editor-plugin-editor-viewmode": "^3.0.0",
42
- "@atlaskit/editor-plugin-extension": "5.0.11",
42
+ "@atlaskit/editor-plugin-extension": "5.1.0",
43
43
  "@atlaskit/editor-plugin-guideline": "^2.0.0",
44
44
  "@atlaskit/editor-plugin-selection": "^2.1.0",
45
45
  "@atlaskit/editor-plugin-width": "^3.0.0",
@@ -54,7 +54,7 @@
54
54
  "@atlaskit/pragmatic-drag-and-drop-hitbox": "^1.0.0",
55
55
  "@atlaskit/primitives": "^14.2.0",
56
56
  "@atlaskit/theme": "^18.0.0",
57
- "@atlaskit/tmp-editor-statsig": "^4.4.0",
57
+ "@atlaskit/tmp-editor-statsig": "^4.5.0",
58
58
  "@atlaskit/toggle": "^15.0.0",
59
59
  "@atlaskit/tokens": "^4.5.0",
60
60
  "@atlaskit/tooltip": "^20.0.0",
@@ -191,6 +191,9 @@
191
191
  },
192
192
  "platform_editor_numbered_column_misalignment": {
193
193
  "type": "boolean"
194
+ },
195
+ "platform_editor_nested_tables_cellselection_paste": {
196
+ "type": "boolean"
194
197
  }
195
198
  }
196
199
  }
@@ -4,6 +4,7 @@ import type { Schema } from '@atlaskit/editor-prosemirror/model';
4
4
  import { Slice, Fragment, Node as PMNode } from '@atlaskit/editor-prosemirror/model';
5
5
  import type { EditorState, Selection } from '@atlaskit/editor-prosemirror/state';
6
6
  import { flatten, hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
7
+ import { CellSelection } from '@atlaskit/editor-tables';
7
8
  import { fg } from '@atlaskit/platform-feature-flags';
8
9
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
9
10
 
@@ -100,19 +101,21 @@ export const transformSliceToRemoveNestedTables = (
100
101
  // if pasted content is a node that supports nesting a table
101
102
  // such as layoutSection or expand allow 1 level by default
102
103
  let allowedTableNesting = 1;
104
+ const isCellSelection = selection instanceof CellSelection;
105
+ const isPasteInTable = hasParentNodeOfType([table, tableCell, tableHeader])(selection);
106
+ const isPasteInNestedTable = getParentOfTypeCount(schema.nodes.table)(selection.$from) > 1;
107
+ const isPasteFullTableInsideEmptyCellEnabled = fg(
108
+ 'platform_editor_paste_full_table_inside_empty_cell',
109
+ );
103
110
 
104
- if (isNestingAllowed) {
105
- const isPasteInTable = hasParentNodeOfType([table, tableCell, tableHeader])(selection);
106
- const isPasteInNestedTable = getParentOfTypeCount(schema.nodes.table)(selection.$from) > 1;
107
- const isPasteFullTableInsideEmptyCellEnabled = fg(
108
- 'platform_editor_paste_full_table_inside_empty_cell',
109
- );
110
- const isCellPaste =
111
- isPasteInTable &&
112
- slice.content.childCount === 1 &&
113
- slice.content.firstChild?.type === table &&
114
- (!isPasteFullTableInsideEmptyCellEnabled || (slice.openStart !== 0 && slice.openEnd !== 0));
111
+ // Pasted content only contains a table and no other content
112
+ const isCellPaste =
113
+ isPasteInTable &&
114
+ slice.content.childCount === 1 &&
115
+ slice.content.firstChild?.type === table &&
116
+ (!isPasteFullTableInsideEmptyCellEnabled || (slice.openStart !== 0 && slice.openEnd !== 0));
115
117
 
118
+ if (isNestingAllowed) {
116
119
  // if nesting is allowed we bump up the default nesting allowance to 2 to support
117
120
  // two levels of nesting in nodes that support table nesting already such as layoutSection and expands
118
121
  allowedTableNesting = 2;
@@ -134,7 +137,10 @@ export const transformSliceToRemoveNestedTables = (
134
137
 
135
138
  // paste of table cells into a table cell - content is spread across multiple cells
136
139
  // by editor-tables so needs to be treated a little differently
137
- if (isCellPaste) {
140
+ if (
141
+ isCellPaste ||
142
+ (isCellSelection && fg('platform_editor_nested_tables_cellselection_paste'))
143
+ ) {
138
144
  allowedTableNesting = 1;
139
145
  if (isPasteInNestedTable) {
140
146
  allowedTableNesting = 0;
@@ -164,9 +170,18 @@ export const transformSliceToRemoveNestedTables = (
164
170
  }
165
171
  }
166
172
 
167
- // after we've worked out what the allowed nesting depth is, unwrap nested tables
168
- const newChildren = unwrapNestedTables(node.content, schema, allowedTableNesting);
169
- return node.copy(Fragment.fromArray(newChildren));
173
+ if (
174
+ isCellSelection &&
175
+ !isCellPaste &&
176
+ fg('platform_editor_nested_tables_cellselection_paste')
177
+ ) {
178
+ // if pasting into a cell selection, we need to flatten the parent table as well
179
+ return unwrapNestedTables(Fragment.fromArray([node]), schema, allowedTableNesting);
180
+ } else {
181
+ // after we've worked out what the allowed nesting depth is, unwrap nested tables
182
+ const newChildren = unwrapNestedTables(node.content, schema, allowedTableNesting);
183
+ return node.copy(Fragment.fromArray(newChildren));
184
+ }
170
185
  });
171
186
 
172
187
  return new Slice(newFragment, slice.openStart, openEnd);
@@ -1146,14 +1146,16 @@ export const baseTableStyles = (props: { featureFlags?: FeatureFlags }) => css`
1146
1146
  .${ClassName.ROW_CONTROLS_WRAPPER} {
1147
1147
  position: absolute;
1148
1148
  /* this is to fix the misalignment of the numbered column in live page view mode */
1149
- ${props.featureFlags?.tableDragAndDrop && fg('platform_editor_numbered_column_misalignment') ? `
1149
+ ${props.featureFlags?.tableDragAndDrop && fg('platform_editor_numbered_column_misalignment')
1150
+ ? `
1150
1151
  margin-top: ${tableMarginTop}px;
1151
1152
  left: -${tableToolbarSize + 1}px;
1152
- ` : `
1153
+ `
1154
+ : `
1153
1155
  /* top of corner control is table margin top - corner control height + 1 pixel of table border. */
1154
1156
  top: ${tableMarginTop - cornerControlHeight + 1}px;
1155
1157
  left: -${tableToolbarSize}px;
1156
- ` }
1158
+ `}
1157
1159
  }
1158
1160
 
1159
1161
  .${ClassName.DRAG_ROW_CONTROLS_WRAPPER}.${ClassName.TABLE_LEFT_SHADOW},