@atlaskit/editor-plugin-table 7.16.12 → 7.16.13
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 +8 -0
- package/dist/cjs/nodeviews/TableContainer.js +44 -23
- package/dist/cjs/nodeviews/TableResizer.js +33 -12
- package/dist/cjs/utils/guidelines.js +7 -4
- package/dist/cjs/utils/snapping.js +7 -8
- package/dist/es2019/nodeviews/TableContainer.js +27 -4
- package/dist/es2019/nodeviews/TableResizer.js +35 -14
- package/dist/es2019/utils/guidelines.js +5 -2
- package/dist/es2019/utils/snapping.js +5 -6
- package/dist/esm/nodeviews/TableContainer.js +45 -24
- package/dist/esm/nodeviews/TableResizer.js +35 -14
- package/dist/esm/utils/guidelines.js +6 -3
- package/dist/esm/utils/snapping.js +6 -7
- package/dist/types/nodeviews/TableResizer.d.ts +2 -1
- package/dist/types/utils/guidelines.d.ts +2 -1
- package/dist/types/utils/snapping.d.ts +3 -2
- package/dist/types-ts4.5/nodeviews/TableResizer.d.ts +2 -1
- package/dist/types-ts4.5/utils/guidelines.d.ts +2 -1
- package/dist/types-ts4.5/utils/snapping.d.ts +3 -2
- package/package.json +2 -2
- package/src/nodeviews/TableContainer.tsx +27 -7
- package/src/nodeviews/TableResizer.tsx +93 -12
- package/src/utils/guidelines.ts +7 -1
- package/src/utils/snapping.ts +5 -5
|
@@ -18,6 +18,7 @@ import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
|
|
|
18
18
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
19
19
|
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
20
20
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
21
|
+
import { akEditorGutterPadding } from '@atlaskit/editor-shared-styles';
|
|
21
22
|
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
22
23
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
23
24
|
import { token } from '@atlaskit/tokens';
|
|
@@ -45,11 +46,16 @@ import {
|
|
|
45
46
|
generateResizeFrameRatePayloads,
|
|
46
47
|
useMeasureFramerate,
|
|
47
48
|
} from '../utils/analytics';
|
|
48
|
-
import {
|
|
49
|
+
import {
|
|
50
|
+
defaultGuidelines,
|
|
51
|
+
defaultGuidelinesForPreserveTable,
|
|
52
|
+
PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET,
|
|
53
|
+
} from '../utils/guidelines';
|
|
49
54
|
import {
|
|
50
55
|
defaultSnappingWidths,
|
|
51
56
|
defaultTablePreserveSnappingWidths,
|
|
52
57
|
findClosestSnap,
|
|
58
|
+
PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET,
|
|
53
59
|
} from '../utils/snapping';
|
|
54
60
|
|
|
55
61
|
interface TableResizerProps {
|
|
@@ -69,6 +75,7 @@ interface TableResizerProps {
|
|
|
69
75
|
isTableScalingEnabled?: boolean;
|
|
70
76
|
isTableAlignmentEnabled?: boolean;
|
|
71
77
|
isWholeTableInDanger?: boolean;
|
|
78
|
+
isFullWidthModeEnabled?: boolean;
|
|
72
79
|
}
|
|
73
80
|
|
|
74
81
|
export interface TableResizerImprovementProps extends TableResizerProps {
|
|
@@ -126,14 +133,39 @@ const getResizerMinWidth = (node: PMNode) => {
|
|
|
126
133
|
* So the guideline container won't make the fabric-editor-popup-scroll-parent overflow
|
|
127
134
|
* @param guidelines
|
|
128
135
|
* @param containerWidth editorWidth
|
|
136
|
+
* @param lineLength
|
|
137
|
+
* @param isTableScalingEnabled
|
|
138
|
+
* @param isFullWidthModeEnabled
|
|
129
139
|
*/
|
|
130
|
-
const getVisibleGuidelines = (
|
|
140
|
+
const getVisibleGuidelines = (
|
|
141
|
+
guidelines: GuidelineConfig[],
|
|
142
|
+
containerWidth: number,
|
|
143
|
+
lineLength: number,
|
|
144
|
+
isTableScalingEnabled: boolean,
|
|
145
|
+
isFullWidthModeEnabled: boolean,
|
|
146
|
+
) => {
|
|
147
|
+
let guidelineVisibleAdjustment = TABLE_GUIDELINE_VISIBLE_ADJUSTMENT;
|
|
148
|
+
if (isTableScalingEnabled) {
|
|
149
|
+
// Notes:
|
|
150
|
+
// Example: containerWidth = 1244, lineLength = 1180 (used for when editor full width mode is enabled)
|
|
151
|
+
// Full width/dynamic x coordinate can be float number.
|
|
152
|
+
// Ex: guideline.position.x can be 590.5. So 590.5 * 2 = 1181 (not 1180).
|
|
153
|
+
// For PTW we need to ensure that dynamic guideline never gets excluded: 1181 should be > width + guidelineVisibleAdjustment
|
|
154
|
+
// guidelineVisibleAdjustment is set as a negative value, so we making it positive and adding + 1
|
|
155
|
+
const preserve_table_widths_adjustment = -1 * PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET + 1;
|
|
156
|
+
|
|
157
|
+
guidelineVisibleAdjustment = isFullWidthModeEnabled
|
|
158
|
+
? preserve_table_widths_adjustment // guidelineVisibleAdjustment = -2, if lineLength = 1180, 1181 < 1180 + 2 is true.
|
|
159
|
+
: -2 * akEditorGutterPadding + preserve_table_widths_adjustment; // guidelineVisibleAdjustment = -62, if containerWidth is 1244, 1181 < 1244 - 62 = 1182 is true.
|
|
160
|
+
}
|
|
161
|
+
const width = isTableScalingEnabled && isFullWidthModeEnabled ? lineLength : containerWidth;
|
|
162
|
+
|
|
131
163
|
return guidelines.filter((guideline) => {
|
|
132
164
|
return (
|
|
133
165
|
guideline.position &&
|
|
134
166
|
guideline.position.x !== undefined &&
|
|
135
167
|
typeof guideline.position.x === 'number' &&
|
|
136
|
-
Math.abs(guideline.position.x * 2) <
|
|
168
|
+
Math.abs(guideline.position.x * 2) < width + guidelineVisibleAdjustment
|
|
137
169
|
);
|
|
138
170
|
});
|
|
139
171
|
};
|
|
@@ -158,6 +190,7 @@ export const TableResizer = ({
|
|
|
158
190
|
isTableAlignmentEnabled,
|
|
159
191
|
isWholeTableInDanger,
|
|
160
192
|
pluginInjectionApi,
|
|
193
|
+
isFullWidthModeEnabled,
|
|
161
194
|
}: PropsWithChildren<TableResizerImprovementProps>) => {
|
|
162
195
|
const currentGap = useRef(0);
|
|
163
196
|
// track resizing state - use ref over state to avoid re-render
|
|
@@ -194,15 +227,28 @@ export const TableResizer = ({
|
|
|
194
227
|
currentGap.current = gap;
|
|
195
228
|
const visibleGuidelines = getVisibleGuidelines(
|
|
196
229
|
isTableScalingEnabled
|
|
197
|
-
? defaultGuidelinesForPreserveTable(
|
|
230
|
+
? defaultGuidelinesForPreserveTable(
|
|
231
|
+
PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET,
|
|
232
|
+
isFullWidthModeEnabled ? lineLength + 2 * akEditorGutterPadding : containerWidth,
|
|
233
|
+
excludeGuidelineConfig,
|
|
234
|
+
)
|
|
198
235
|
: defaultGuidelines,
|
|
199
236
|
containerWidth,
|
|
237
|
+
lineLength,
|
|
238
|
+
Boolean(isTableScalingEnabled),
|
|
239
|
+
Boolean(isFullWidthModeEnabled),
|
|
200
240
|
);
|
|
201
|
-
|
|
202
241
|
displayGuideline(getGuidelinesWithHighlights(gap, TABLE_SNAP_GAP, keys, visibleGuidelines));
|
|
203
242
|
}
|
|
204
243
|
},
|
|
205
|
-
[
|
|
244
|
+
[
|
|
245
|
+
isTableScalingEnabled,
|
|
246
|
+
excludeGuidelineConfig,
|
|
247
|
+
containerWidth,
|
|
248
|
+
displayGuideline,
|
|
249
|
+
lineLength,
|
|
250
|
+
isFullWidthModeEnabled,
|
|
251
|
+
],
|
|
206
252
|
);
|
|
207
253
|
|
|
208
254
|
const guidelineSnaps = useMemo(
|
|
@@ -210,11 +256,22 @@ export const TableResizer = ({
|
|
|
210
256
|
snappingEnabled
|
|
211
257
|
? {
|
|
212
258
|
x: isTableScalingEnabled
|
|
213
|
-
? defaultTablePreserveSnappingWidths(
|
|
259
|
+
? defaultTablePreserveSnappingWidths(
|
|
260
|
+
PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET, // was hardcoded to 0, using PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET instead.
|
|
261
|
+
isFullWidthModeEnabled ? lineLength + 2 * akEditorGutterPadding : containerWidth,
|
|
262
|
+
excludeGuidelineConfig,
|
|
263
|
+
)
|
|
214
264
|
: defaultSnappingWidths,
|
|
215
265
|
}
|
|
216
266
|
: undefined,
|
|
217
|
-
[
|
|
267
|
+
[
|
|
268
|
+
snappingEnabled,
|
|
269
|
+
isTableScalingEnabled,
|
|
270
|
+
excludeGuidelineConfig,
|
|
271
|
+
containerWidth,
|
|
272
|
+
lineLength,
|
|
273
|
+
isFullWidthModeEnabled,
|
|
274
|
+
],
|
|
218
275
|
);
|
|
219
276
|
|
|
220
277
|
const switchToCenterAlignment = useCallback(
|
|
@@ -285,9 +342,16 @@ export const TableResizer = ({
|
|
|
285
342
|
|
|
286
343
|
const visibleGuidelines = getVisibleGuidelines(
|
|
287
344
|
isTableScalingEnabled
|
|
288
|
-
? defaultGuidelinesForPreserveTable(
|
|
345
|
+
? defaultGuidelinesForPreserveTable(
|
|
346
|
+
PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET,
|
|
347
|
+
isFullWidthModeEnabled ? lineLength + 2 * akEditorGutterPadding : containerWidth,
|
|
348
|
+
excludeGuidelineConfig,
|
|
349
|
+
)
|
|
289
350
|
: defaultGuidelines,
|
|
290
351
|
containerWidth,
|
|
352
|
+
lineLength,
|
|
353
|
+
Boolean(isTableScalingEnabled),
|
|
354
|
+
Boolean(isFullWidthModeEnabled),
|
|
291
355
|
);
|
|
292
356
|
|
|
293
357
|
setSnappingEnabled(displayGuideline(visibleGuidelines));
|
|
@@ -303,8 +367,10 @@ export const TableResizer = ({
|
|
|
303
367
|
isTableScalingEnabled,
|
|
304
368
|
excludeGuidelineConfig,
|
|
305
369
|
containerWidth,
|
|
370
|
+
lineLength,
|
|
306
371
|
displayGuideline,
|
|
307
372
|
onResizeStart,
|
|
373
|
+
isFullWidthModeEnabled,
|
|
308
374
|
]);
|
|
309
375
|
|
|
310
376
|
const handleResize = useCallback(
|
|
@@ -333,13 +399,25 @@ export const TableResizer = ({
|
|
|
333
399
|
isTableScalingEnabled,
|
|
334
400
|
);
|
|
335
401
|
|
|
402
|
+
const editorContainerWidth = isFullWidthModeEnabled
|
|
403
|
+
? lineLength + 2 * akEditorGutterPadding
|
|
404
|
+
: containerWidth;
|
|
405
|
+
|
|
336
406
|
const closestSnap = findClosestSnap(
|
|
337
407
|
newWidth,
|
|
338
408
|
isTableScalingEnabled
|
|
339
|
-
? defaultTablePreserveSnappingWidths(
|
|
409
|
+
? defaultTablePreserveSnappingWidths(
|
|
410
|
+
PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET,
|
|
411
|
+
editorContainerWidth,
|
|
412
|
+
excludeGuidelineConfig,
|
|
413
|
+
)
|
|
340
414
|
: defaultSnappingWidths,
|
|
341
415
|
isTableScalingEnabled
|
|
342
|
-
? defaultGuidelinesForPreserveTable(
|
|
416
|
+
? defaultGuidelinesForPreserveTable(
|
|
417
|
+
PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET,
|
|
418
|
+
editorContainerWidth,
|
|
419
|
+
excludeGuidelineConfig,
|
|
420
|
+
)
|
|
343
421
|
: defaultGuidelines,
|
|
344
422
|
TABLE_HIGHLIGHT_GAP,
|
|
345
423
|
TABLE_HIGHLIGHT_TOLERANCE,
|
|
@@ -352,7 +430,8 @@ export const TableResizer = ({
|
|
|
352
430
|
const currentTableNodeLocalId = node?.attrs?.localId ?? '';
|
|
353
431
|
|
|
354
432
|
const fullWidthGuideline = defaultGuidelinesForPreserveTable(
|
|
355
|
-
|
|
433
|
+
PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET,
|
|
434
|
+
editorContainerWidth,
|
|
356
435
|
excludeGuidelineConfig,
|
|
357
436
|
).filter((guideline) => guideline.isFullWidth)[0];
|
|
358
437
|
|
|
@@ -375,12 +454,14 @@ export const TableResizer = ({
|
|
|
375
454
|
[
|
|
376
455
|
countFrames,
|
|
377
456
|
isTableScalingEnabled,
|
|
457
|
+
isFullWidthModeEnabled,
|
|
378
458
|
excludeGuidelineConfig,
|
|
379
459
|
tableRef,
|
|
380
460
|
node,
|
|
381
461
|
editorView,
|
|
382
462
|
updateActiveGuidelines,
|
|
383
463
|
containerWidth,
|
|
464
|
+
lineLength,
|
|
384
465
|
updateWidth,
|
|
385
466
|
getPos,
|
|
386
467
|
switchToCenterAlignment,
|
package/src/utils/guidelines.ts
CHANGED
|
@@ -11,14 +11,20 @@ export const defaultGuidelines = createFixedGuidelinesFromLengths([
|
|
|
11
11
|
...calculateDefaultSnappings(-1),
|
|
12
12
|
]) as GuidelineConfig[];
|
|
13
13
|
|
|
14
|
+
export const PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET = -1;
|
|
14
15
|
export const defaultGuidelinesForPreserveTable = (
|
|
16
|
+
lengthOffset: number,
|
|
15
17
|
editorContainerWidth: number,
|
|
16
18
|
exclude: GuidelineExcludeConfig = {
|
|
17
19
|
innerGuidelines: false,
|
|
18
20
|
breakoutPoints: false,
|
|
19
21
|
},
|
|
20
22
|
) => {
|
|
21
|
-
const lengths = calculateDefaultTablePreserveSnappings(
|
|
23
|
+
const lengths = calculateDefaultTablePreserveSnappings(
|
|
24
|
+
lengthOffset, // was hardcoded to -1 here, created PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET instead.
|
|
25
|
+
editorContainerWidth,
|
|
26
|
+
exclude,
|
|
27
|
+
);
|
|
22
28
|
|
|
23
29
|
return createFixedGuidelinesFromLengths(lengths, undefined, true) as GuidelineConfig[];
|
|
24
30
|
};
|
package/src/utils/snapping.ts
CHANGED
|
@@ -7,8 +7,6 @@ import {
|
|
|
7
7
|
akEditorGutterPadding,
|
|
8
8
|
} from '@atlaskit/editor-shared-styles';
|
|
9
9
|
|
|
10
|
-
import { tableResizerWidth } from '../ui/consts';
|
|
11
|
-
|
|
12
10
|
const numberOfLanesInDefaultLayoutWidth = 12;
|
|
13
11
|
|
|
14
12
|
const calculateSubSnappingWidths = (totalLanes: number, totalWidth: number) =>
|
|
@@ -43,7 +41,7 @@ export const calculateDefaultTablePreserveSnappings = (
|
|
|
43
41
|
const dynamicFullWidthLine =
|
|
44
42
|
editorContainerWith - akEditorGutterPadding * 2 >= akEditorFullWidthLayoutWidth
|
|
45
43
|
? akEditorFullWidthLayoutWidth
|
|
46
|
-
: editorContainerWith - akEditorGutterPadding * 2
|
|
44
|
+
: editorContainerWith - akEditorGutterPadding * 2;
|
|
47
45
|
|
|
48
46
|
const guides = [dynamicFullWidthLine - lengthOffset];
|
|
49
47
|
|
|
@@ -69,8 +67,10 @@ export const calculateDefaultTablePreserveSnappings = (
|
|
|
69
67
|
|
|
70
68
|
export const defaultSnappingWidths = calculateDefaultSnappings();
|
|
71
69
|
|
|
70
|
+
export const PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET = 0;
|
|
72
71
|
// FF TablePreserve for defaultSnappingWidths
|
|
73
72
|
export const defaultTablePreserveSnappingWidths = (
|
|
73
|
+
lengthOffset: number,
|
|
74
74
|
editorContainerWidth: number,
|
|
75
75
|
exclude: GuidelineExcludeConfig = {
|
|
76
76
|
innerGuidelines: false,
|
|
@@ -79,11 +79,11 @@ export const defaultTablePreserveSnappingWidths = (
|
|
|
79
79
|
) => {
|
|
80
80
|
return editorContainerWidth - akEditorGutterPadding * 2 > akEditorFullWidthLayoutWidth
|
|
81
81
|
? calculateDefaultSnappings()
|
|
82
|
-
: calculateDefaultTablePreserveSnappings(
|
|
82
|
+
: calculateDefaultTablePreserveSnappings(lengthOffset, editorContainerWidth, exclude); // lengthOffset was hardcoded 0 here, created PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET instead.
|
|
83
83
|
};
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
|
-
* Returns keys of guidelines that are closest to the table and
|
|
86
|
+
* Returns keys of guidelines that are closest to the table and within the snapGap
|
|
87
87
|
*/
|
|
88
88
|
export const findClosestSnap = (
|
|
89
89
|
currentWidth: number,
|