@atlaskit/editor-plugin-table 1.5.5 → 1.6.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 +10 -0
- package/dist/cjs/plugins/table/index.js +12 -11
- package/dist/cjs/plugins/table/nodeviews/TableComponent.js +37 -78
- package/dist/cjs/plugins/table/nodeviews/TableContainer.js +131 -0
- package/dist/cjs/plugins/table/nodeviews/TableResizer.js +65 -0
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/commands.js +4 -49
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/index.js +0 -7
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/index.js +12 -6
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/misc.js +3 -11
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +61 -2
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/table/index.js +12 -11
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +17 -64
- package/dist/es2019/plugins/table/nodeviews/TableContainer.js +124 -0
- package/dist/es2019/plugins/table/nodeviews/TableResizer.js +56 -0
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/commands.js +2 -48
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/index.js +0 -1
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/index.js +2 -2
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/misc.js +5 -10
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +61 -2
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/table/index.js +12 -11
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +39 -81
- package/dist/esm/plugins/table/nodeviews/TableContainer.js +119 -0
- package/dist/esm/plugins/table/nodeviews/TableResizer.js +57 -0
- package/dist/esm/plugins/table/pm-plugins/table-resizing/commands.js +4 -48
- package/dist/esm/plugins/table/pm-plugins/table-resizing/index.js +0 -1
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/index.js +2 -2
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/misc.js +5 -10
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +59 -2
- package/dist/esm/version.json +1 -1
- package/dist/types/plugins/table/nodeviews/TableComponent.d.ts +0 -3
- package/dist/types/plugins/table/nodeviews/TableContainer.d.ts +35 -0
- package/dist/types/plugins/table/nodeviews/TableResizer.d.ts +13 -0
- package/dist/types/plugins/table/pm-plugins/table-resizing/commands.d.ts +2 -4
- package/dist/types/plugins/table/pm-plugins/table-resizing/index.d.ts +0 -1
- package/dist/types/plugins/table/pm-plugins/table-resizing/utils/index.d.ts +2 -2
- package/dist/types/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +0 -1
- package/dist/types/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +3 -0
- package/dist/types/plugins/table/types.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/nodeviews/TableComponent.d.ts +0 -3
- package/dist/types-ts4.5/plugins/table/nodeviews/TableContainer.d.ts +35 -0
- package/dist/types-ts4.5/plugins/table/nodeviews/TableResizer.d.ts +13 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/commands.d.ts +2 -4
- package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/index.d.ts +0 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/index.d.ts +2 -2
- package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +0 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +3 -0
- package/dist/types-ts4.5/plugins/table/types.d.ts +1 -0
- package/package.json +3 -3
- package/src/__tests__/integration/sticky-header.ts +4 -1
- package/src/__tests__/unit/nodeviews/TableContainer.tsx +164 -0
- package/src/plugins/table/index.tsx +21 -18
- package/src/plugins/table/nodeviews/TableComponent.tsx +21 -78
- package/src/plugins/table/nodeviews/TableContainer.tsx +200 -0
- package/src/plugins/table/nodeviews/TableResizer.tsx +88 -0
- package/src/plugins/table/pm-plugins/table-resizing/commands.ts +3 -72
- package/src/plugins/table/pm-plugins/table-resizing/index.ts +0 -1
- package/src/plugins/table/pm-plugins/table-resizing/utils/index.ts +6 -2
- package/src/plugins/table/pm-plugins/table-resizing/utils/misc.ts +7 -12
- package/src/plugins/table/pm-plugins/table-resizing/utils/scale-table.ts +79 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Node as PMNode } from 'prosemirror-model';
|
|
2
|
+
import { Transaction } from 'prosemirror-state';
|
|
2
3
|
|
|
3
4
|
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
4
5
|
import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
|
|
@@ -12,8 +13,11 @@ import {
|
|
|
12
13
|
adjustColumnsWidths,
|
|
13
14
|
getResizeState,
|
|
14
15
|
getTotalWidth,
|
|
16
|
+
updateColgroup,
|
|
15
17
|
} from '../utils/resize-state';
|
|
16
18
|
import { ResizeState } from '../utils/types';
|
|
19
|
+
import { hasTableBeenResized, insertColgroupFromNode } from './colgroup';
|
|
20
|
+
import { updateColumnWidths } from '../../../transforms';
|
|
17
21
|
|
|
18
22
|
export interface ScaleOptions {
|
|
19
23
|
node: PMNode;
|
|
@@ -140,3 +144,78 @@ export function scaleTableTo(state: ResizeState, maxSize: number): ResizeState {
|
|
|
140
144
|
|
|
141
145
|
return adjustColumnsWidths(newState, maxSize);
|
|
142
146
|
}
|
|
147
|
+
|
|
148
|
+
export const previewScaleTable = (
|
|
149
|
+
tableRef: HTMLTableElement | null | undefined,
|
|
150
|
+
options: ScaleOptions,
|
|
151
|
+
domAtPos: DomAtPos,
|
|
152
|
+
) => {
|
|
153
|
+
const { node, start, parentWidth } = options;
|
|
154
|
+
|
|
155
|
+
if (!tableRef || !hasTableBeenResized(node)) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const resizeState = parentWidth
|
|
160
|
+
? scaleWithParent(tableRef, parentWidth, node, start, domAtPos)
|
|
161
|
+
: scale(tableRef, options, domAtPos);
|
|
162
|
+
|
|
163
|
+
if (resizeState) {
|
|
164
|
+
updateColgroup(resizeState, tableRef);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// Scale the table to meet new requirements (col, layout change etc)
|
|
169
|
+
export const scaleTable =
|
|
170
|
+
(
|
|
171
|
+
tableRef: HTMLTableElement | null | undefined,
|
|
172
|
+
options: ScaleOptions,
|
|
173
|
+
domAtPos: DomAtPos,
|
|
174
|
+
) =>
|
|
175
|
+
(tr: Transaction) => {
|
|
176
|
+
if (!tableRef) {
|
|
177
|
+
return tr;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const { node, start, parentWidth, layoutChanged } = options;
|
|
181
|
+
|
|
182
|
+
// If a table has not been resized yet, columns should be auto.
|
|
183
|
+
if (hasTableBeenResized(node) === false) {
|
|
184
|
+
// If its not a re-sized table, we still want to re-create cols
|
|
185
|
+
// To force reflow of columns upon delete.
|
|
186
|
+
insertColgroupFromNode(tableRef, node);
|
|
187
|
+
return tr;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
let resizeState;
|
|
191
|
+
if (parentWidth) {
|
|
192
|
+
resizeState = scaleWithParent(
|
|
193
|
+
tableRef,
|
|
194
|
+
parentWidth,
|
|
195
|
+
node,
|
|
196
|
+
start,
|
|
197
|
+
domAtPos,
|
|
198
|
+
);
|
|
199
|
+
} else {
|
|
200
|
+
resizeState = scale(tableRef, options, domAtPos);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (resizeState) {
|
|
204
|
+
tr = updateColumnWidths(resizeState, node, start)(tr);
|
|
205
|
+
|
|
206
|
+
if (tr.docChanged) {
|
|
207
|
+
tr.setMeta('scrollIntoView', false);
|
|
208
|
+
// TODO: ED-8995
|
|
209
|
+
// We need to do this check to reduce the number of race conditions when working with tables.
|
|
210
|
+
// This metadata is been used in the sendTransaction function in the Collab plugin
|
|
211
|
+
/* Added !layoutChanged check here to solve unnecessary scroll bar after publish when click on breakout button multiple times and publish
|
|
212
|
+
scaleTable is only called once every time a breakout button is clicked, so it is safe not to add the meta 'scaleTable' to the tr.
|
|
213
|
+
Leaving the tr.setMeta('scaleTable', true) here for race conditions that we aren't aware of.
|
|
214
|
+
*/
|
|
215
|
+
!layoutChanged && tr.setMeta('scaleTable', true);
|
|
216
|
+
return tr;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return tr;
|
|
221
|
+
};
|