@atlaskit/editor-tables 2.7.2 → 2.7.4

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,23 @@
1
1
  # @atlaskit/editor-tables
2
2
 
3
+ ## 2.7.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#102210](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/102210)
8
+ [`fe0d7aa7668a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/fe0d7aa7668a) -
9
+ Set layout attribute for tables to align-left when inserted in full width editor
10
+
11
+ ## 2.7.3
12
+
13
+ ### Patch Changes
14
+
15
+ - [#94829](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/94829)
16
+ [`815fda434fe7`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/815fda434fe7) -
17
+ [ED-22849] Align add column and row behaviour behind
18
+ platform_editor_table_duplicate_cell_colouring flag so that adding a column will copy cell
19
+ background from the left and adding a row will copy background colour from row above
20
+
3
21
  ## 2.7.2
4
22
 
5
23
  ### Patch Changes
@@ -9,7 +9,7 @@ var _addColumn = require("./add-column");
9
9
  var _cloneTr = require("./clone-tr");
10
10
  var _find = require("./find");
11
11
  // Returns a new transaction that adds a new column at index `columnIndex`.
12
- var addColumnAt = exports.addColumnAt = function addColumnAt(columnIndex) {
12
+ var addColumnAt = exports.addColumnAt = function addColumnAt(columnIndex, isCellBackgroundDuplicated) {
13
13
  return function (tr) {
14
14
  var table = (0, _find.findTable)(tr.selection);
15
15
  if (table) {
@@ -19,7 +19,7 @@ var addColumnAt = exports.addColumnAt = function addColumnAt(columnIndex) {
19
19
  map: map,
20
20
  tableStart: table.start,
21
21
  table: table.node
22
- }, columnIndex));
22
+ }, columnIndex, isCellBackgroundDuplicated));
23
23
  }
24
24
  }
25
25
  return tr;
@@ -19,7 +19,7 @@ function columnIsHeader(map, table, col) {
19
19
  }
20
20
 
21
21
  // Add a column at the given position in a table.
22
- function addColumn(tr, _ref, col) {
22
+ function addColumn(tr, _ref, col, isCellBackgroundDuplicated) {
23
23
  var map = _ref.map,
24
24
  tableStart = _ref.tableStart,
25
25
  table = _ref.table;
@@ -44,6 +44,7 @@ function addColumn(tr, _ref, col) {
44
44
  row += attributes.rowspan - 1;
45
45
  } else {
46
46
  var type = void 0;
47
+ var attrs = {};
47
48
  if (refColumn === null) {
48
49
  type = (0, _tableNodeTypes.tableNodeTypes)(table.type.schema).cell;
49
50
  } else {
@@ -53,9 +54,14 @@ function addColumn(tr, _ref, col) {
53
54
  throw new Error("addColumn: invalid node at mapped pos ".concat(mappedPos));
54
55
  }
55
56
  type = _cell.type;
57
+ if (_cell.attrs.background && isCellBackgroundDuplicated) {
58
+ attrs = {
59
+ background: _cell.attrs.background
60
+ };
61
+ }
56
62
  }
57
63
  var _pos = map.positionAt(row, col, table);
58
- tr.insert(tr.mapping.map(tableStart + _pos), type.createAndFill());
64
+ tr.insert(tr.mapping.map(tableStart + _pos), type.createAndFill(attrs));
59
65
  }
60
66
  }
61
67
  return tr;
@@ -88,7 +88,7 @@ var cloneRowAt = exports.cloneRowAt = function cloneRowAt(rowIndex) {
88
88
  };
89
89
 
90
90
  // Returns a new transaction that adds a new row at index `rowIndex`. Optionally clone the previous row.
91
- var addRowAt = exports.addRowAt = function addRowAt(rowIndex, clonePreviousRow) {
91
+ var addRowAt = exports.addRowAt = function addRowAt(rowIndex, clonePreviousRow, isCellBackgroundDuplicated) {
92
92
  return function (tr) {
93
93
  var table = (0, _find.findTable)(tr.selection);
94
94
  if (table) {
@@ -102,7 +102,7 @@ var addRowAt = exports.addRowAt = function addRowAt(rowIndex, clonePreviousRow)
102
102
  map: map,
103
103
  tableStart: table.start,
104
104
  table: table.node
105
- }, rowIndex));
105
+ }, rowIndex, isCellBackgroundDuplicated));
106
106
  }
107
107
  }
108
108
  return tr;
@@ -19,7 +19,7 @@ function rowIsHeader(map, table, row) {
19
19
  }
20
20
  return true;
21
21
  }
22
- function addRow(tr, _ref, row) {
22
+ function addRow(tr, _ref, row, isCellBackgroundDuplicated) {
23
23
  var map = _ref.map,
24
24
  tableStart = _ref.tableStart,
25
25
  table = _ref.table;
@@ -47,6 +47,7 @@ function addRow(tr, _ref, row) {
47
47
  col += attrs.colspan - 1;
48
48
  } else {
49
49
  var type = void 0;
50
+ var _attrs = {};
50
51
  if (refRow == null) {
51
52
  type = (0, _tableNodeTypes.tableNodeTypes)(table.type.schema).cell;
52
53
  } else {
@@ -56,8 +57,13 @@ function addRow(tr, _ref, row) {
56
57
  throw new Error("addRow: invalid node at mapped pos ".concat(mappedPos));
57
58
  }
58
59
  type = cell.type;
60
+ if (cell.attrs.background && isCellBackgroundDuplicated) {
61
+ _attrs = {
62
+ background: cell.attrs.background
63
+ };
64
+ }
59
65
  }
60
- cells.push(type.createAndFill());
66
+ cells.push(type.createAndFill(_attrs));
61
67
  }
62
68
  }
63
69
  var rowType = (0, _tableNodeTypes.tableNodeTypes)(table.type.schema).row;
@@ -26,7 +26,9 @@ var createTable = exports.createTable = function createTable(_ref) {
26
26
  _ref$withHeaderRow = _ref.withHeaderRow,
27
27
  withHeaderRow = _ref$withHeaderRow === void 0 ? true : _ref$withHeaderRow,
28
28
  cellContent = _ref.cellContent,
29
- tableWidth = _ref.tableWidth;
29
+ tableWidth = _ref.tableWidth,
30
+ _ref$layout = _ref.layout,
31
+ layout = _ref$layout === void 0 ? undefined : _ref$layout;
30
32
  var _tableNodeTypes = (0, _tableNodeTypes2.tableNodeTypes)(schema),
31
33
  tableCell = _tableNodeTypes.cell,
32
34
  tableHeader = _tableNodeTypes.header_cell,
@@ -52,6 +54,7 @@ var createTable = exports.createTable = function createTable(_ref) {
52
54
  }
53
55
  return table.createChecked({
54
56
  localId: _uuid.uuid.generate(),
55
- width: tableWidth !== null && tableWidth !== void 0 ? tableWidth : 760
57
+ width: tableWidth !== null && tableWidth !== void 0 ? tableWidth : 760,
58
+ layout: layout
56
59
  }, rows);
57
60
  };
@@ -4,7 +4,7 @@ import { cloneTr } from './clone-tr';
4
4
  import { findTable } from './find';
5
5
 
6
6
  // Returns a new transaction that adds a new column at index `columnIndex`.
7
- export const addColumnAt = columnIndex => tr => {
7
+ export const addColumnAt = (columnIndex, isCellBackgroundDuplicated) => tr => {
8
8
  const table = findTable(tr.selection);
9
9
  if (table) {
10
10
  const map = TableMap.get(table.node);
@@ -13,7 +13,7 @@ export const addColumnAt = columnIndex => tr => {
13
13
  map,
14
14
  tableStart: table.start,
15
15
  table: table.node
16
- }, columnIndex));
16
+ }, columnIndex, isCellBackgroundDuplicated));
17
17
  }
18
18
  }
19
19
  return tr;
@@ -16,7 +16,7 @@ export function addColumn(tr, {
16
16
  map,
17
17
  tableStart,
18
18
  table
19
- }, col) {
19
+ }, col, isCellBackgroundDuplicated) {
20
20
  let refColumn = col > 0 ? -1 : 0;
21
21
  if (columnIsHeader(map, table, col + refColumn)) {
22
22
  refColumn = col === 0 || col === map.width ? null : 0;
@@ -38,6 +38,7 @@ export function addColumn(tr, {
38
38
  row += attributes.rowspan - 1;
39
39
  } else {
40
40
  let type;
41
+ let attrs = {};
41
42
  if (refColumn === null) {
42
43
  type = tableNodeTypes(table.type.schema).cell;
43
44
  } else {
@@ -47,9 +48,14 @@ export function addColumn(tr, {
47
48
  throw new Error(`addColumn: invalid node at mapped pos ${mappedPos}`);
48
49
  }
49
50
  type = cell.type;
51
+ if (cell.attrs.background && isCellBackgroundDuplicated) {
52
+ attrs = {
53
+ background: cell.attrs.background
54
+ };
55
+ }
50
56
  }
51
57
  const pos = map.positionAt(row, col, table);
52
- tr.insert(tr.mapping.map(tableStart + pos), type.createAndFill());
58
+ tr.insert(tr.mapping.map(tableStart + pos), type.createAndFill(attrs));
53
59
  }
54
60
  }
55
61
  return tr;
@@ -73,7 +73,7 @@ export const cloneRowAt = rowIndex => tr => {
73
73
  };
74
74
 
75
75
  // Returns a new transaction that adds a new row at index `rowIndex`. Optionally clone the previous row.
76
- export const addRowAt = (rowIndex, clonePreviousRow) => tr => {
76
+ export const addRowAt = (rowIndex, clonePreviousRow, isCellBackgroundDuplicated) => tr => {
77
77
  const table = findTable(tr.selection);
78
78
  if (table) {
79
79
  const map = TableMap.get(table.node);
@@ -86,7 +86,7 @@ export const addRowAt = (rowIndex, clonePreviousRow) => tr => {
86
86
  map,
87
87
  tableStart: table.start,
88
88
  table: table.node
89
- }, rowIndex));
89
+ }, rowIndex, isCellBackgroundDuplicated));
90
90
  }
91
91
  }
92
92
  return tr;
@@ -13,7 +13,7 @@ export function addRow(tr, {
13
13
  map,
14
14
  tableStart,
15
15
  table
16
- }, row) {
16
+ }, row, isCellBackgroundDuplicated) {
17
17
  let rowPos = tableStart;
18
18
  for (let i = 0; i < row; i++) {
19
19
  rowPos += table.child(i).nodeSize;
@@ -41,6 +41,7 @@ export function addRow(tr, {
41
41
  col += attrs.colspan - 1;
42
42
  } else {
43
43
  let type;
44
+ let attrs = {};
44
45
  if (refRow == null) {
45
46
  type = tableNodeTypes(table.type.schema).cell;
46
47
  } else {
@@ -50,8 +51,13 @@ export function addRow(tr, {
50
51
  throw new Error(`addRow: invalid node at mapped pos ${mappedPos}`);
51
52
  }
52
53
  type = cell.type;
54
+ if (cell.attrs.background && isCellBackgroundDuplicated) {
55
+ attrs = {
56
+ background: cell.attrs.background
57
+ };
58
+ }
53
59
  }
54
- cells.push(type.createAndFill());
60
+ cells.push(type.createAndFill(attrs));
55
61
  }
56
62
  }
57
63
  const rowType = tableNodeTypes(table.type.schema).row;
@@ -17,7 +17,9 @@ export const createTable = ({
17
17
  colsCount = 3,
18
18
  withHeaderRow = true,
19
19
  cellContent,
20
- tableWidth
20
+ tableWidth,
21
+ // default to undefined so PM will use default value defined in schema
22
+ layout = undefined
21
23
  }) => {
22
24
  const {
23
25
  cell: tableCell,
@@ -45,6 +47,7 @@ export const createTable = ({
45
47
  }
46
48
  return table.createChecked({
47
49
  localId: uuid.generate(),
48
- width: tableWidth !== null && tableWidth !== void 0 ? tableWidth : 760
50
+ width: tableWidth !== null && tableWidth !== void 0 ? tableWidth : 760,
51
+ layout
49
52
  }, rows);
50
53
  };
@@ -4,7 +4,7 @@ import { cloneTr } from './clone-tr';
4
4
  import { findTable } from './find';
5
5
 
6
6
  // Returns a new transaction that adds a new column at index `columnIndex`.
7
- export var addColumnAt = function addColumnAt(columnIndex) {
7
+ export var addColumnAt = function addColumnAt(columnIndex, isCellBackgroundDuplicated) {
8
8
  return function (tr) {
9
9
  var table = findTable(tr.selection);
10
10
  if (table) {
@@ -14,7 +14,7 @@ export var addColumnAt = function addColumnAt(columnIndex) {
14
14
  map: map,
15
15
  tableStart: table.start,
16
16
  table: table.node
17
- }, columnIndex));
17
+ }, columnIndex, isCellBackgroundDuplicated));
18
18
  }
19
19
  }
20
20
  return tr;
@@ -12,7 +12,7 @@ export function columnIsHeader(map, table, col) {
12
12
  }
13
13
 
14
14
  // Add a column at the given position in a table.
15
- export function addColumn(tr, _ref, col) {
15
+ export function addColumn(tr, _ref, col, isCellBackgroundDuplicated) {
16
16
  var map = _ref.map,
17
17
  tableStart = _ref.tableStart,
18
18
  table = _ref.table;
@@ -37,6 +37,7 @@ export function addColumn(tr, _ref, col) {
37
37
  row += attributes.rowspan - 1;
38
38
  } else {
39
39
  var type = void 0;
40
+ var attrs = {};
40
41
  if (refColumn === null) {
41
42
  type = tableNodeTypes(table.type.schema).cell;
42
43
  } else {
@@ -46,9 +47,14 @@ export function addColumn(tr, _ref, col) {
46
47
  throw new Error("addColumn: invalid node at mapped pos ".concat(mappedPos));
47
48
  }
48
49
  type = _cell.type;
50
+ if (_cell.attrs.background && isCellBackgroundDuplicated) {
51
+ attrs = {
52
+ background: _cell.attrs.background
53
+ };
54
+ }
49
55
  }
50
56
  var _pos = map.positionAt(row, col, table);
51
- tr.insert(tr.mapping.map(tableStart + _pos), type.createAndFill());
57
+ tr.insert(tr.mapping.map(tableStart + _pos), type.createAndFill(attrs));
52
58
  }
53
59
  }
54
60
  return tr;
@@ -81,7 +81,7 @@ export var cloneRowAt = function cloneRowAt(rowIndex) {
81
81
  };
82
82
 
83
83
  // Returns a new transaction that adds a new row at index `rowIndex`. Optionally clone the previous row.
84
- export var addRowAt = function addRowAt(rowIndex, clonePreviousRow) {
84
+ export var addRowAt = function addRowAt(rowIndex, clonePreviousRow, isCellBackgroundDuplicated) {
85
85
  return function (tr) {
86
86
  var table = findTable(tr.selection);
87
87
  if (table) {
@@ -95,7 +95,7 @@ export var addRowAt = function addRowAt(rowIndex, clonePreviousRow) {
95
95
  map: map,
96
96
  tableStart: table.start,
97
97
  table: table.node
98
- }, rowIndex));
98
+ }, rowIndex, isCellBackgroundDuplicated));
99
99
  }
100
100
  }
101
101
  return tr;
@@ -12,7 +12,7 @@ function rowIsHeader(map, table, row) {
12
12
  }
13
13
  return true;
14
14
  }
15
- export function addRow(tr, _ref, row) {
15
+ export function addRow(tr, _ref, row, isCellBackgroundDuplicated) {
16
16
  var map = _ref.map,
17
17
  tableStart = _ref.tableStart,
18
18
  table = _ref.table;
@@ -40,6 +40,7 @@ export function addRow(tr, _ref, row) {
40
40
  col += attrs.colspan - 1;
41
41
  } else {
42
42
  var type = void 0;
43
+ var _attrs = {};
43
44
  if (refRow == null) {
44
45
  type = tableNodeTypes(table.type.schema).cell;
45
46
  } else {
@@ -49,8 +50,13 @@ export function addRow(tr, _ref, row) {
49
50
  throw new Error("addRow: invalid node at mapped pos ".concat(mappedPos));
50
51
  }
51
52
  type = cell.type;
53
+ if (cell.attrs.background && isCellBackgroundDuplicated) {
54
+ _attrs = {
55
+ background: cell.attrs.background
56
+ };
57
+ }
52
58
  }
53
- cells.push(type.createAndFill());
59
+ cells.push(type.createAndFill(_attrs));
54
60
  }
55
61
  }
56
62
  var rowType = tableNodeTypes(table.type.schema).row;
@@ -20,7 +20,9 @@ export var createTable = function createTable(_ref) {
20
20
  _ref$withHeaderRow = _ref.withHeaderRow,
21
21
  withHeaderRow = _ref$withHeaderRow === void 0 ? true : _ref$withHeaderRow,
22
22
  cellContent = _ref.cellContent,
23
- tableWidth = _ref.tableWidth;
23
+ tableWidth = _ref.tableWidth,
24
+ _ref$layout = _ref.layout,
25
+ layout = _ref$layout === void 0 ? undefined : _ref$layout;
24
26
  var _tableNodeTypes = tableNodeTypes(schema),
25
27
  tableCell = _tableNodeTypes.cell,
26
28
  tableHeader = _tableNodeTypes.header_cell,
@@ -46,6 +48,7 @@ export var createTable = function createTable(_ref) {
46
48
  }
47
49
  return table.createChecked({
48
50
  localId: uuid.generate(),
49
- width: tableWidth !== null && tableWidth !== void 0 ? tableWidth : 760
51
+ width: tableWidth !== null && tableWidth !== void 0 ? tableWidth : 760,
52
+ layout: layout
50
53
  }, rows);
51
54
  };
@@ -1,2 +1,2 @@
1
- import { Transaction } from '@atlaskit/editor-prosemirror/state';
2
- export declare const addColumnAt: (columnIndex: number) => (tr: Transaction) => Transaction;
1
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ export declare const addColumnAt: (columnIndex: number, isCellBackgroundDuplicated?: boolean) => (tr: Transaction) => Transaction;
@@ -1,5 +1,5 @@
1
- import { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
- import { Transaction } from '@atlaskit/editor-prosemirror/state';
3
- import { TableContext, TableMap } from '../table-map';
1
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
3
+ import type { TableContext, TableMap } from '../table-map';
4
4
  export declare function columnIsHeader(map: TableMap, table: PMNode, col: number): boolean;
5
- export declare function addColumn(tr: Transaction, { map, tableStart, table }: TableContext, col: number): Transaction;
5
+ export declare function addColumn(tr: Transaction, { map, tableStart, table }: TableContext, col: number, isCellBackgroundDuplicated?: boolean): Transaction;
@@ -1,3 +1,3 @@
1
- import { Transaction } from '@atlaskit/editor-prosemirror/state';
1
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
2
2
  export declare const cloneRowAt: (rowIndex: number) => (tr: Transaction) => Transaction;
3
- export declare const addRowAt: (rowIndex: number, clonePreviousRow?: boolean) => (tr: Transaction) => Transaction;
3
+ export declare const addRowAt: (rowIndex: number, clonePreviousRow?: boolean, isCellBackgroundDuplicated?: boolean) => (tr: Transaction) => Transaction;
@@ -1,3 +1,3 @@
1
- import { Transaction } from '@atlaskit/editor-prosemirror/state';
2
- import { TableContext } from '../table-map';
3
- export declare function addRow(tr: Transaction, { map, tableStart, table }: TableContext, row: number): Transaction;
1
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ import type { TableContext } from '../table-map';
3
+ export declare function addRow(tr: Transaction, { map, tableStart, table }: TableContext, row: number, isCellBackgroundDuplicated?: boolean): Transaction;
@@ -6,6 +6,7 @@ type CreateTableProps = {
6
6
  withHeaderRow?: boolean;
7
7
  cellContent?: PMNode;
8
8
  tableWidth?: number;
9
+ layout?: string;
9
10
  };
10
- export declare const createTable: ({ schema, rowsCount, colsCount, withHeaderRow, cellContent, tableWidth, }: CreateTableProps) => PMNode;
11
+ export declare const createTable: ({ schema, rowsCount, colsCount, withHeaderRow, cellContent, tableWidth, layout }: CreateTableProps) => PMNode;
11
12
  export {};
@@ -1,2 +1,2 @@
1
- import { Transaction } from '@atlaskit/editor-prosemirror/state';
2
- export declare const addColumnAt: (columnIndex: number) => (tr: Transaction) => Transaction;
1
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ export declare const addColumnAt: (columnIndex: number, isCellBackgroundDuplicated?: boolean) => (tr: Transaction) => Transaction;
@@ -1,5 +1,5 @@
1
- import { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
- import { Transaction } from '@atlaskit/editor-prosemirror/state';
3
- import { TableContext, TableMap } from '../table-map';
1
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
3
+ import type { TableContext, TableMap } from '../table-map';
4
4
  export declare function columnIsHeader(map: TableMap, table: PMNode, col: number): boolean;
5
- export declare function addColumn(tr: Transaction, { map, tableStart, table }: TableContext, col: number): Transaction;
5
+ export declare function addColumn(tr: Transaction, { map, tableStart, table }: TableContext, col: number, isCellBackgroundDuplicated?: boolean): Transaction;
@@ -1,3 +1,3 @@
1
- import { Transaction } from '@atlaskit/editor-prosemirror/state';
1
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
2
2
  export declare const cloneRowAt: (rowIndex: number) => (tr: Transaction) => Transaction;
3
- export declare const addRowAt: (rowIndex: number, clonePreviousRow?: boolean) => (tr: Transaction) => Transaction;
3
+ export declare const addRowAt: (rowIndex: number, clonePreviousRow?: boolean, isCellBackgroundDuplicated?: boolean) => (tr: Transaction) => Transaction;
@@ -1,3 +1,3 @@
1
- import { Transaction } from '@atlaskit/editor-prosemirror/state';
2
- import { TableContext } from '../table-map';
3
- export declare function addRow(tr: Transaction, { map, tableStart, table }: TableContext, row: number): Transaction;
1
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ import type { TableContext } from '../table-map';
3
+ export declare function addRow(tr: Transaction, { map, tableStart, table }: TableContext, row: number, isCellBackgroundDuplicated?: boolean): Transaction;
@@ -6,6 +6,7 @@ type CreateTableProps = {
6
6
  withHeaderRow?: boolean;
7
7
  cellContent?: PMNode;
8
8
  tableWidth?: number;
9
+ layout?: string;
9
10
  };
10
- export declare const createTable: ({ schema, rowsCount, colsCount, withHeaderRow, cellContent, tableWidth, }: CreateTableProps) => PMNode;
11
+ export declare const createTable: ({ schema, rowsCount, colsCount, withHeaderRow, cellContent, tableWidth, layout }: CreateTableProps) => PMNode;
11
12
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-tables",
3
- "version": "2.7.2",
3
+ "version": "2.7.4",
4
4
  "description": "A package that contains common classes and utility functions for editor tables",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"