@atlaskit/editor-plugin-table 12.1.15 → 12.2.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.
Files changed (61) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/afm-cc/tsconfig.json +3 -0
  3. package/afm-dev-agents/tsconfig.json +3 -0
  4. package/afm-jira/tsconfig.json +3 -0
  5. package/afm-passionfruit/tsconfig.json +3 -0
  6. package/afm-post-office/tsconfig.json +3 -0
  7. package/afm-rovo-extension/tsconfig.json +3 -0
  8. package/afm-townsquare/tsconfig.json +3 -0
  9. package/dist/cjs/nodeviews/TableComponent.js +73 -22
  10. package/dist/cjs/nodeviews/TableContainer.js +270 -10
  11. package/dist/cjs/nodeviews/TableResizer.js +9 -2
  12. package/dist/cjs/nodeviews/table.js +12 -2
  13. package/dist/cjs/nodeviews/toDOM.js +23 -7
  14. package/dist/cjs/pm-plugins/main.js +57 -23
  15. package/dist/cjs/pm-plugins/table-resizing/utils/colgroup.js +72 -1
  16. package/dist/cjs/pm-plugins/table-resizing/utils/misc.js +70 -1
  17. package/dist/cjs/tablePlugin.js +17 -3
  18. package/dist/es2019/nodeviews/TableComponent.js +76 -22
  19. package/dist/es2019/nodeviews/TableContainer.js +256 -2
  20. package/dist/es2019/nodeviews/TableResizer.js +9 -2
  21. package/dist/es2019/nodeviews/table.js +12 -2
  22. package/dist/es2019/nodeviews/toDOM.js +24 -8
  23. package/dist/es2019/pm-plugins/main.js +57 -23
  24. package/dist/es2019/pm-plugins/table-resizing/utils/colgroup.js +72 -3
  25. package/dist/es2019/pm-plugins/table-resizing/utils/misc.js +70 -1
  26. package/dist/es2019/tablePlugin.js +17 -3
  27. package/dist/esm/nodeviews/TableComponent.js +73 -22
  28. package/dist/esm/nodeviews/TableContainer.js +270 -10
  29. package/dist/esm/nodeviews/TableResizer.js +9 -2
  30. package/dist/esm/nodeviews/table.js +12 -2
  31. package/dist/esm/nodeviews/toDOM.js +24 -8
  32. package/dist/esm/pm-plugins/main.js +57 -23
  33. package/dist/esm/pm-plugins/table-resizing/utils/colgroup.js +74 -3
  34. package/dist/esm/pm-plugins/table-resizing/utils/misc.js +70 -1
  35. package/dist/esm/tablePlugin.js +17 -3
  36. package/dist/types/nodeviews/TableContainer.d.ts +7 -2
  37. package/dist/types/nodeviews/TableResizer.d.ts +1 -1
  38. package/dist/types/nodeviews/toDOM.d.ts +5 -0
  39. package/dist/types/nodeviews/types.d.ts +1 -0
  40. package/dist/types/pm-plugins/table-resizing/utils/colgroup.d.ts +1 -0
  41. package/dist/types/pm-plugins/table-resizing/utils/misc.d.ts +41 -0
  42. package/dist/types-ts4.5/nodeviews/TableContainer.d.ts +7 -2
  43. package/dist/types-ts4.5/nodeviews/TableResizer.d.ts +1 -1
  44. package/dist/types-ts4.5/nodeviews/toDOM.d.ts +5 -0
  45. package/dist/types-ts4.5/nodeviews/types.d.ts +1 -0
  46. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/colgroup.d.ts +1 -0
  47. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/misc.d.ts +41 -0
  48. package/package.json +8 -7
  49. package/src/nodeviews/TableComponent.tsx +105 -19
  50. package/src/nodeviews/TableContainer.tsx +331 -2
  51. package/src/nodeviews/TableResizer.tsx +10 -5
  52. package/src/nodeviews/table.tsx +14 -0
  53. package/src/nodeviews/toDOM.ts +75 -9
  54. package/src/nodeviews/types.ts +1 -0
  55. package/src/pm-plugins/main.ts +41 -18
  56. package/src/pm-plugins/table-resizing/utils/colgroup.ts +139 -6
  57. package/src/pm-plugins/table-resizing/utils/misc.ts +87 -0
  58. package/src/tablePlugin.tsx +21 -0
  59. package/tsconfig.app.json +3 -0
  60. package/types/package.json +1 -1
  61. package/ui/common-styles/package.json +1 -1
@@ -11,14 +11,17 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
11
11
  var _react = _interopRequireWildcard(require("react"));
12
12
  var _classnames = _interopRequireDefault(require("classnames"));
13
13
  var _analytics = require("@atlaskit/editor-common/analytics");
14
+ var _coreUtils = require("@atlaskit/editor-common/core-utils");
14
15
  var _hooks = require("@atlaskit/editor-common/hooks");
15
16
  var _nodeWidth = require("@atlaskit/editor-common/node-width");
16
17
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
17
18
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
19
+ var _platformFeatureFlagsReact = require("@atlaskit/platform-feature-flags-react");
18
20
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
19
21
  var _commandsWithAnalytics = require("../pm-plugins/commands/commands-with-analytics");
20
22
  var _pluginFactory = require("../pm-plugins/plugin-factory");
21
23
  var _consts = require("../pm-plugins/table-resizing/utils/consts");
24
+ var _misc = require("../pm-plugins/table-resizing/utils/misc");
22
25
  var _alignment = require("../pm-plugins/utils/alignment");
23
26
  var _types = require("../types");
24
27
  var _tableContainerStyles = require("./table-container-styles");
@@ -161,7 +164,7 @@ var useSharedState = (0, _hooks.sharedPluginStateHookMigratorFactory)(function (
161
164
  var getPadding = function getPadding(containerWidth) {
162
165
  return containerWidth <= _editorSharedStyles.akEditorFullPageNarrowBreakout && (0, _expValEquals.expValEquals)('platform_editor_preview_panel_responsiveness', 'isEnabled', true) ? _editorSharedStyles.akEditorGutterPaddingReduced : (0, _editorSharedStyles.akEditorGutterPaddingDynamic)();
163
166
  };
164
- var ResizableTableContainer = exports.ResizableTableContainer = /*#__PURE__*/_react.default.memo(function (_ref4) {
167
+ var ResizableTableContainerLegacy = /*#__PURE__*/_react.default.memo(function (_ref4) {
165
168
  var children = _ref4.children,
166
169
  className = _ref4.className,
167
170
  node = _ref4.node,
@@ -355,28 +358,283 @@ var ResizableTableContainer = exports.ResizableTableContainer = /*#__PURE__*/_re
355
358
  node: node
356
359
  }, children)) : null));
357
360
  });
358
- var TableContainer = exports.TableContainer = function TableContainer(_ref5) {
361
+ var ResizableTableContainerNext = /*#__PURE__*/_react.default.memo(function (_ref5) {
359
362
  var children = _ref5.children,
360
- node = _ref5.node,
361
363
  className = _ref5.className,
362
- _ref5$containerWidth = _ref5.containerWidth,
363
- editorWidth = _ref5$containerWidth.width,
364
- lineLength = _ref5$containerWidth.lineLength,
364
+ node = _ref5.node,
365
+ containerWidth = _ref5.containerWidth,
366
+ lineLength = _ref5.lineLength,
365
367
  editorView = _ref5.editorView,
366
368
  getPos = _ref5.getPos,
367
369
  tableRef = _ref5.tableRef,
368
- isNested = _ref5.isNested,
369
- tableWrapperHeight = _ref5.tableWrapperHeight,
370
370
  isResizing = _ref5.isResizing,
371
+ isWindowResized = _ref5.isWindowResized,
371
372
  pluginInjectionApi = _ref5.pluginInjectionApi,
373
+ tableWrapperHeight = _ref5.tableWrapperHeight,
372
374
  isWholeTableInDanger = _ref5.isWholeTableInDanger,
373
- isTableResizingEnabled = _ref5.isTableResizingEnabled,
374
375
  isTableScalingEnabled = _ref5.isTableScalingEnabled,
375
376
  isTableWithFixedColumnWidthsOptionEnabled = _ref5.isTableWithFixedColumnWidthsOptionEnabled,
376
377
  isTableAlignmentEnabled = _ref5.isTableAlignmentEnabled,
377
378
  shouldUseIncreasedScalingPercent = _ref5.shouldUseIncreasedScalingPercent,
378
379
  isCommentEditor = _ref5.isCommentEditor,
379
380
  isChromelessEditor = _ref5.isChromelessEditor;
381
+ var tableWidth = (0, _nodeWidth.getTableContainerWidth)(node);
382
+ var containerRef = (0, _react.useRef)(null);
383
+ var tableWidthRef = (0, _react.useRef)(_editorSharedStyles.akEditorDefaultLayoutWidth);
384
+ var _useState3 = (0, _react.useState)(false),
385
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
386
+ resizing = _useState4[0],
387
+ setIsResizing = _useState4[1];
388
+ var _useState5 = (0, _react.useState)(tableWidth),
389
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
390
+ tableMaxWidthForFullPageOnLoad = _useState6[0],
391
+ setTableMaxWidthForFullPageOnLoad = _useState6[1];
392
+ var _useSharedState2 = useSharedState(pluginInjectionApi),
393
+ tableState = _useSharedState2.tableState,
394
+ editorViewModeState = _useSharedState2.editorViewModeState;
395
+ var isFullWidthModeEnabled = tableState === null || tableState === void 0 ? void 0 : tableState.isFullWidthModeEnabled;
396
+ var mode = editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode;
397
+ var updateContainerHeight = (0, _react.useCallback)(function (height) {
398
+ var _containerRef$current3;
399
+ // current StickyHeader State is not stable to be fetch.
400
+ // we need to update stickyHeader plugin to make sure state can be
401
+ // consistently fetch and refactor below
402
+ var stickyHeaders = (_containerRef$current3 = containerRef.current) === null || _containerRef$current3 === void 0 ? void 0 : _containerRef$current3.getElementsByClassName('pm-table-sticky');
403
+ if (!stickyHeaders || stickyHeaders.length < 1) {
404
+ // when starting to drag, we need to keep the original space,
405
+ // -- When sticky header not appear, margin top(24px) and margin bottom(16px), should be 40px,
406
+ // 1px is border width but collapse make it 0.5.
407
+ // -- When sticky header appear, we should add first row height but reduce
408
+ // collapsed border
409
+ return typeof height === 'number' ? "".concat(height + 40.5, "px") : 'auto';
410
+ } else {
411
+ var _containerRef$current4;
412
+ var stickyHeaderHeight = ((_containerRef$current4 = containerRef.current) === null || _containerRef$current4 === void 0 ? void 0 : _containerRef$current4.getElementsByTagName('th')[0].getBoundingClientRect().height) || 0;
413
+ return typeof height === 'number' ? "".concat(height + stickyHeaderHeight + 39.5, "px") : 'auto';
414
+ }
415
+ }, []);
416
+ var onResizeStart = (0, _react.useCallback)(function () {
417
+ setIsResizing(true);
418
+ }, []);
419
+ var onResizeStop = (0, _react.useCallback)(function () {
420
+ setIsResizing(false);
421
+ }, []);
422
+ var updateWidth = (0, _react.useCallback)(function (width) {
423
+ if (!containerRef.current) {
424
+ return;
425
+ }
426
+
427
+ // make sure during resizing
428
+ // the pm-table-resizer-container width is the same as its child div resizer-item
429
+ // otherwise when resize table from wider to narrower , pm-table-resizer-container stays wider
430
+ // and cause the fabric-editor-popup-scroll-parent to overflow
431
+ if (containerRef.current.style.width !== "".concat(width, "px")) {
432
+ containerRef.current.style.width = "".concat(width, "px");
433
+ }
434
+ }, []);
435
+ var displayGuideline = (0, _react.useCallback)(function (guidelines) {
436
+ var _pluginInjectionApi$g3, _pluginInjectionApi$g4;
437
+ return (_pluginInjectionApi$g3 = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$g4 = pluginInjectionApi.guideline) === null || _pluginInjectionApi$g4 === void 0 || (_pluginInjectionApi$g4 = _pluginInjectionApi$g4.actions) === null || _pluginInjectionApi$g4 === void 0 ? void 0 : _pluginInjectionApi$g4.displayGuideline(editorView)({
438
+ guidelines: guidelines
439
+ })) !== null && _pluginInjectionApi$g3 !== void 0 ? _pluginInjectionApi$g3 : false;
440
+ }, [pluginInjectionApi, editorView]);
441
+ var attachAnalyticsEvent = (0, _react.useCallback)(function (payload) {
442
+ var _pluginInjectionApi$a3;
443
+ return pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a3 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a3 === void 0 ? void 0 : _pluginInjectionApi$a3.actions.attachAnalyticsEvent(payload);
444
+ }, [pluginInjectionApi]);
445
+ var displayGapCursor = (0, _react.useCallback)(function (toggle) {
446
+ var _pluginInjectionApi$c3, _pluginInjectionApi$c4, _pluginInjectionApi$s2;
447
+ return (_pluginInjectionApi$c3 = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c4 = pluginInjectionApi.core) === null || _pluginInjectionApi$c4 === void 0 ? void 0 : _pluginInjectionApi$c4.actions.execute(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$s2 = pluginInjectionApi.selection) === null || _pluginInjectionApi$s2 === void 0 ? void 0 : _pluginInjectionApi$s2.commands.displayGapCursor(toggle))) !== null && _pluginInjectionApi$c3 !== void 0 ? _pluginInjectionApi$c3 : false;
448
+ }, [pluginInjectionApi]);
449
+ var isFullPageAppearance = !isCommentEditor && !isChromelessEditor;
450
+ var responsiveContainerWidth = 0;
451
+ var resizeHandleSpacing = 12;
452
+ var padding = getPadding(containerWidth);
453
+ // When Full width editor enabled, a Mac OS user can change "ak-editor-content-area" width by
454
+ // updating Settings -> Appearance -> Show scroll bars from "When scrolling" to "Always". It causes
455
+ // issues when viwport width is less than full width Editor's width. To detect avoid them
456
+ // we need to use lineLength to defined responsiveWidth instead of containerWidth
457
+ // (which does not get updated when Mac setting changes) in Full-width editor.
458
+ if (isFullWidthModeEnabled) {
459
+ // When: Show scroll bars -> containerWidth = akEditorGutterPadding * 2 + lineLength;
460
+ // When: Always -> containerWidth = akEditorGutterPadding * 2 + lineLength + scrollbarWidth;
461
+ // scrollbarWidth can vary. Values can be 14, 15, 16 and up to 20px;
462
+ responsiveContainerWidth = isTableScalingEnabled ? lineLength : containerWidth - padding * 2 - resizeHandleSpacing;
463
+
464
+ // platform_editor_table_fw_numcol_overflow_fix:
465
+ // lineLength is undefined on first paint → width: NaN → wrapper expands to page
466
+ // width. rAF col-sizing then runs before the number-column padding and
467
+ // the final shrink, so column widths are locked in wrong.
468
+ // With the flag ON, if the value isn’t finite we fall back to gutterWidth
469
+ // for that first frame—no flash, no premature rAF.
470
+ //
471
+ // Type clean-up comes later:
472
+ // 1) ship this runtime guard (quick fix, no breakage);
473
+ // 2) TODO: widen lineLength to `number|undefined` and remove this block.
474
+ if ((0, _platformFeatureFlags.fg)('platform_editor_table_fw_numcol_overflow_fix')) {
475
+ if (isTableScalingEnabled && !Number.isFinite(responsiveContainerWidth)) {
476
+ responsiveContainerWidth = containerWidth - padding * 2 - resizeHandleSpacing;
477
+ }
478
+ }
479
+ } else if (isCommentEditor) {
480
+ responsiveContainerWidth = containerWidth - _consts.TABLE_OFFSET_IN_COMMENT_EDITOR;
481
+ } else {
482
+ // 76 is currently an accepted padding value considering the spacing for resizer handle
483
+ // containerWidth = width of a DIV with test id="ak-editor-fp-content-area". It is a parent of
484
+ // a DIV with className="ak-editor-content-area". This DIV has padding left and padding right.
485
+ // padding left = padding right = akEditorGutterPadding = 32
486
+ responsiveContainerWidth = isTableScalingEnabled ? containerWidth - padding * 2 : containerWidth - padding * 2 - resizeHandleSpacing;
487
+ }
488
+ var width = !node.attrs.width && isCommentEditor ? responsiveContainerWidth : Math.min(tableWidth, responsiveContainerWidth);
489
+ if (!isResizing) {
490
+ tableWidthRef.current = width;
491
+ }
492
+ var maxResizerWidth = isCommentEditor ? responsiveContainerWidth : Math.min(responsiveContainerWidth, _consts.TABLE_MAX_WIDTH);
493
+
494
+ // CSS solution for table resizer item width
495
+ // The `width` is used for .resizer-item in <TableResizer>, and it has to be a number
496
+ // So we can't use min(var(--ak-editor-table-width), ${tableWidth}px) here
497
+ // We get the correct width from CSS value on page load
498
+ // After window resize, we use the width from plugin state
499
+ // After table resize, the table width attribute is used
500
+ var tableResizerItemWidth = (0, _react.useMemo)(function () {
501
+ // if not on full page editor, we just rely on the width calculated from plugin state
502
+ // if on full page editor and after window resize, we use the width from plugin state
503
+ if (!isFullPageAppearance || isFullPageAppearance && isWindowResized) {
504
+ return width;
505
+ }
506
+ if (isResizing) {
507
+ return tableWidth;
508
+ }
509
+ // if on full page editor and on page load, we use the computed value from CSS
510
+ return Math.min(tableWidth, tableMaxWidthForFullPageOnLoad);
511
+ }, [isWindowResized, isResizing, isFullPageAppearance, tableMaxWidthForFullPageOnLoad, tableWidth, width]);
512
+
513
+ // CSS Solution for table resizer container width
514
+ var tableResizerContainerWidth = (0, _react.useMemo)(function () {
515
+ return (0, _misc.getTableResizerContainerForFullPageWidthInCSS)(node, isTableScalingEnabled);
516
+ }, [node, isTableScalingEnabled]);
517
+
518
+ // CSS Solution for table resizer max width
519
+ var tableResizerMaxWidth = _react.default.useMemo(function () {
520
+ var isFullPageAppearance = !isCommentEditor && !isChromelessEditor;
521
+ var nonResizingMaxWidth = isFullPageAppearance ? (0, _misc.getTableResizerContainerMaxWidthInCSS)(isCommentEditor, isChromelessEditor, isTableScalingEnabled) : maxResizerWidth;
522
+ // isResizing is needed, otherwise we can't resize table.
523
+ // when not resizing, maxWidth is calculated based on the container width via CSS
524
+ return !isResizing ? nonResizingMaxWidth : maxResizerWidth;
525
+ }, [isCommentEditor, isChromelessEditor, isTableScalingEnabled, isResizing, maxResizerWidth]);
526
+
527
+ // on SSR, the width would be the default state, which is tableWidth
528
+ // but because we have maxWidth set to the editor container width via CSS
529
+ // So it would work just fine
530
+ (0, _react.useEffect)(function () {
531
+ var _containerRef$current5;
532
+ if (!(0, _coreUtils.isSSR)() && isFullPageAppearance && (_containerRef$current5 = containerRef.current) !== null && _containerRef$current5 !== void 0 && _containerRef$current5.firstElementChild) {
533
+ // get the computed value of max-width from '.resizer-item', because it uses `cqw` unit in CSS
534
+ var computedStyle = window.getComputedStyle(containerRef.current.firstElementChild);
535
+ var _containerWidth = computedStyle.maxWidth ? parseFloat(computedStyle.maxWidth) : tableWidth;
536
+ setTableMaxWidthForFullPageOnLoad(Math.min(_containerWidth, tableWidth));
537
+ }
538
+ }, [tableWidthRef, tableWidth, isFullPageAppearance]);
539
+ var tableResizerProps = {
540
+ width: tableResizerItemWidth,
541
+ maxWidth: tableResizerMaxWidth,
542
+ containerWidth: containerWidth,
543
+ lineLength: lineLength,
544
+ updateWidth: updateWidth,
545
+ editorView: editorView,
546
+ getPos: getPos,
547
+ node: node,
548
+ tableRef: tableRef,
549
+ displayGuideline: displayGuideline,
550
+ attachAnalyticsEvent: attachAnalyticsEvent,
551
+ displayGapCursor: displayGapCursor,
552
+ isTableAlignmentEnabled: isTableAlignmentEnabled,
553
+ isFullWidthModeEnabled: isFullWidthModeEnabled,
554
+ isTableScalingEnabled: isTableScalingEnabled,
555
+ isTableWithFixedColumnWidthsOptionEnabled: isTableWithFixedColumnWidthsOptionEnabled,
556
+ isWholeTableInDanger: isWholeTableInDanger,
557
+ shouldUseIncreasedScalingPercent: shouldUseIncreasedScalingPercent,
558
+ pluginInjectionApi: pluginInjectionApi,
559
+ onResizeStart: onResizeStart,
560
+ onResizeStop: onResizeStop,
561
+ isCommentEditor: isCommentEditor
562
+ };
563
+ var isLivePageViewMode = mode === 'view';
564
+ return /*#__PURE__*/_react.default.createElement(AlignmentTableContainerWrapper, {
565
+ isTableAlignmentEnabled: isTableAlignmentEnabled,
566
+ node: node,
567
+ pluginInjectionApi: pluginInjectionApi,
568
+ getPos: getPos,
569
+ editorView: editorView
570
+ }, /*#__PURE__*/_react.default.createElement("div", {
571
+ style: {
572
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
573
+ '--ak-editor-table-gutter-padding': 'calc(var(--ak-editor--large-gutter-padding) * 2)',
574
+ '--ak-editor-table-width': isFullPageAppearance ? tableResizerContainerWidth : "".concat(tableWidthRef.current, "px"),
575
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
576
+ width: 'var(--ak-editor-table-width)',
577
+ height: resizing ? updateContainerHeight(tableWrapperHeight !== null && tableWrapperHeight !== void 0 ? tableWrapperHeight : 'auto') : 'auto',
578
+ position: isLivePageViewMode ? 'relative' : 'unset'
579
+ }
580
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
581
+ ,
582
+ className: _types.TableCssClassName.TABLE_RESIZER_CONTAINER,
583
+ ref: containerRef
584
+ }, (0, _platformFeatureFlags.fg)('platform_editor_live_page_prevent_table_recreation') ? null : isLivePageViewMode ? /*#__PURE__*/_react.default.createElement(InnerContainer
585
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
586
+ , {
587
+ className: className,
588
+ node: node
589
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
590
+ ,
591
+ style: {
592
+ width: 'inherit'
593
+ }
594
+ }, children) :
595
+ /*#__PURE__*/
596
+ // Ignored via go/ees005
597
+ // eslint-disable-next-line react/jsx-props-no-spreading
598
+ _react.default.createElement(_TableResizer.TableResizer, tableResizerProps, /*#__PURE__*/_react.default.createElement(InnerContainer, {
599
+ className: className,
600
+ node: node
601
+ }, children)), (0, _platformFeatureFlags.fg)('platform_editor_live_page_prevent_table_recreation') ?
602
+ /*#__PURE__*/
603
+ // Ignored via go/ees005
604
+ // eslint-disable-next-line react/jsx-props-no-spreading
605
+ _react.default.createElement(_TableResizer.TableResizer, (0, _extends2.default)({}, tableResizerProps, {
606
+ disabled: isLivePageViewMode
607
+ }), /*#__PURE__*/_react.default.createElement(InnerContainer, {
608
+ className: className,
609
+ node: node
610
+ }, children)) : null));
611
+ });
612
+ var ResizableTableContainer = exports.ResizableTableContainer = (0, _platformFeatureFlagsReact.componentWithCondition)(function () {
613
+ return (0, _expValEquals.expValEquals)('platform_editor_tables_scaling_css', 'isEnabled', true);
614
+ }, ResizableTableContainerNext, ResizableTableContainerLegacy);
615
+ var TableContainer = exports.TableContainer = function TableContainer(_ref6) {
616
+ var children = _ref6.children,
617
+ node = _ref6.node,
618
+ className = _ref6.className,
619
+ _ref6$containerWidth = _ref6.containerWidth,
620
+ editorWidth = _ref6$containerWidth.width,
621
+ lineLength = _ref6$containerWidth.lineLength,
622
+ editorView = _ref6.editorView,
623
+ getPos = _ref6.getPos,
624
+ tableRef = _ref6.tableRef,
625
+ isNested = _ref6.isNested,
626
+ tableWrapperHeight = _ref6.tableWrapperHeight,
627
+ isResizing = _ref6.isResizing,
628
+ isWindowResized = _ref6.isWindowResized,
629
+ pluginInjectionApi = _ref6.pluginInjectionApi,
630
+ isWholeTableInDanger = _ref6.isWholeTableInDanger,
631
+ isTableResizingEnabled = _ref6.isTableResizingEnabled,
632
+ isTableScalingEnabled = _ref6.isTableScalingEnabled,
633
+ isTableWithFixedColumnWidthsOptionEnabled = _ref6.isTableWithFixedColumnWidthsOptionEnabled,
634
+ isTableAlignmentEnabled = _ref6.isTableAlignmentEnabled,
635
+ shouldUseIncreasedScalingPercent = _ref6.shouldUseIncreasedScalingPercent,
636
+ isCommentEditor = _ref6.isCommentEditor,
637
+ isChromelessEditor = _ref6.isChromelessEditor;
380
638
  if (isTableResizingEnabled && !isNested) {
381
639
  return /*#__PURE__*/_react.default.createElement(ResizableTableContainer
382
640
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
@@ -396,13 +654,15 @@ var TableContainer = exports.TableContainer = function TableContainer(_ref5) {
396
654
  tableRef: tableRef,
397
655
  tableWrapperHeight: tableWrapperHeight,
398
656
  isResizing: isResizing,
657
+ isWindowResized: isWindowResized,
399
658
  pluginInjectionApi: pluginInjectionApi,
400
659
  isTableScalingEnabled: isTableScalingEnabled,
401
660
  isTableWithFixedColumnWidthsOptionEnabled: isTableWithFixedColumnWidthsOptionEnabled,
402
661
  isWholeTableInDanger: isWholeTableInDanger,
403
662
  isTableAlignmentEnabled: isTableAlignmentEnabled,
404
663
  shouldUseIncreasedScalingPercent: shouldUseIncreasedScalingPercent,
405
- isCommentEditor: isCommentEditor
664
+ isCommentEditor: isCommentEditor,
665
+ isChromelessEditor: isChromelessEditor
406
666
  }, children);
407
667
  }
408
668
  var _getPluginState = (0, _pluginFactory.getPluginState)(editorView.state),
@@ -406,8 +406,15 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
406
406
  }, [editorView, getPos, node, isCommentEditor, widthToWidest, endMeasure, displayGapCursor, displayGuideline, updateWidth, scheduleResize, onResizeStop, attachAnalyticsEvent, tableRef, pluginInjectionApi, isTableScalingEnabled, shouldUseIncreasedScalingPercent, formatMessage]);
407
407
  var handleTableSizeChangeOnKeypress = (0, _react.useCallback)(function (step) {
408
408
  var newWidth = width + step;
409
- if (newWidth > maxWidth || newWidth < resizerMinWidth) {
410
- return;
409
+ if ((0, _expValEquals.expValEquals)('platform_editor_tables_scaling_css', 'isEnabled', true)) {
410
+ if (newWidth < resizerMinWidth) {
411
+ return;
412
+ }
413
+ } else {
414
+ // maxWidth when platform_editor_tables_scaling_css off is always a number
415
+ if (newWidth > maxWidth || newWidth < resizerMinWidth) {
416
+ return;
417
+ }
411
418
  }
412
419
  handleResizeStop({
413
420
  width: width,
@@ -89,10 +89,17 @@ var TableView = exports.default = /*#__PURE__*/function (_ReactNodeView) {
89
89
  return (0, _createClass2.default)(TableView, [{
90
90
  key: "getContentDOM",
91
91
  value: function getContentDOM() {
92
+ var _this$reactComponentP, _this$reactComponentP2, _this$reactComponentP3, _this$reactComponentP4;
93
+ var isNested = (0, _nodes.isTableNested)(this.view.state, this.getPos());
92
94
  var tableDOMStructure = (0, _toDOM.tableNodeSpecWithFixedToDOM)({
93
95
  allowColumnResizing: !!this.reactComponentProps.allowColumnResizing,
94
96
  tableResizingEnabled: !!this.reactComponentProps.allowTableResizing,
95
- getEditorContainerWidth: this.reactComponentProps.getEditorContainerWidth
97
+ getEditorContainerWidth: this.reactComponentProps.getEditorContainerWidth,
98
+ isTableScalingEnabled: (_this$reactComponentP = this.reactComponentProps.options) === null || _this$reactComponentP === void 0 ? void 0 : _this$reactComponentP.isTableScalingEnabled,
99
+ shouldUseIncreasedScalingPercent: (_this$reactComponentP2 = this.reactComponentProps.options) === null || _this$reactComponentP2 === void 0 ? void 0 : _this$reactComponentP2.shouldUseIncreasedScalingPercent,
100
+ isCommentEditor: (_this$reactComponentP3 = this.reactComponentProps.options) === null || _this$reactComponentP3 === void 0 ? void 0 : _this$reactComponentP3.isCommentEditor,
101
+ isChromelessEditor: (_this$reactComponentP4 = this.reactComponentProps.options) === null || _this$reactComponentP4 === void 0 ? void 0 : _this$reactComponentP4.isChromelessEditor,
102
+ isNested: isNested
96
103
  }).toDOM(this.node);
97
104
  var rendered = _model.DOMSerializer.renderSpec(document, tableDOMStructure);
98
105
  if (rendered.dom) {
@@ -409,6 +416,8 @@ var createTableView = exports.createTableView = function createTableView(node, v
409
416
  allowControls = _getPluginConfig.allowControls,
410
417
  allowTableResizing = _getPluginConfig.allowTableResizing,
411
418
  allowTableAlignment = _getPluginConfig.allowTableAlignment;
419
+ var isTableFixedColumnWidthsOptionEnabled = (getEditorFeatureFlags === null || getEditorFeatureFlags === void 0 ? void 0 : getEditorFeatureFlags().tableWithFixedColumnWidthsOption) || false;
420
+ var shouldUseIncreasedScalingPercent = isTableScalingEnabled && (isTableFixedColumnWidthsOptionEnabled || isCommentEditor);
412
421
  return new TableView({
413
422
  node: node,
414
423
  view: view,
@@ -426,7 +435,8 @@ var createTableView = exports.createTableView = function createTableView(node, v
426
435
  isTableScalingEnabled: isTableScalingEnabled,
427
436
  // same as options.isTableScalingEnabled
428
437
  isCommentEditor: isCommentEditor,
429
- isChromelessEditor: isChromelessEditor
438
+ isChromelessEditor: isChromelessEditor,
439
+ shouldUseIncreasedScalingPercent: shouldUseIncreasedScalingPercent
430
440
  },
431
441
  getEditorContainerWidth: getEditorContainerWidth,
432
442
  getEditorFeatureFlags: getEditorFeatureFlags,
@@ -15,6 +15,7 @@ var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
15
15
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
16
16
  var _colgroup = require("../pm-plugins/table-resizing/utils/colgroup");
17
17
  var _consts = require("../pm-plugins/table-resizing/utils/consts");
18
+ var _misc = require("../pm-plugins/table-resizing/utils/misc");
18
19
  var _tableContainerStyles = require("./table-container-styles");
19
20
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
20
21
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -22,6 +23,7 @@ var tableNodeSpecWithFixedToDOM = exports.tableNodeSpecWithFixedToDOM = function
22
23
  var tableNode = config.isNestingSupported ? _adfSchema.tableWithNestedTable : _adfSchema.table;
23
24
  return _objectSpread(_objectSpread({}, tableNode), {}, {
24
25
  toDOM: function toDOM(node) {
26
+ var _node$attrs$width;
25
27
  var gutterPadding = function gutterPadding() {
26
28
  if ((0, _expValEquals.expValEquals)('platform_editor_preview_panel_responsiveness', 'isEnabled', true)) {
27
29
  return 'calc(var(--ak-editor--large-gutter-padding) * 2)';
@@ -36,6 +38,8 @@ var tableNodeSpecWithFixedToDOM = exports.tableNodeSpecWithFixedToDOM = function
36
38
  return "".concat((0, _kebabCase.default)(k), ": ").concat((0, _kebabCase.default)(v));
37
39
  }).join(';');
38
40
  var tableMinWidth = (0, _colgroup.getResizerMinWidth)(node);
41
+ var tableWidthAttribute = node.attrs.width ? "".concat(node.attrs.width, "px") : "100%";
42
+ var isFullPageEditor = !config.isChromelessEditor && !config.isCommentEditor;
39
43
  var attrs = {
40
44
  'data-number-column': node.attrs.isNumberColumnEnabled,
41
45
  'data-layout': node.attrs.layout,
@@ -43,10 +47,20 @@ var tableNodeSpecWithFixedToDOM = exports.tableNodeSpecWithFixedToDOM = function
43
47
  'data-table-local-id': node.attrs.localId,
44
48
  'data-table-width': node.attrs.width
45
49
  };
50
+
51
+ // This would be used for table scaling in colgroup CSS
52
+ // cqw, or px is well supported
53
+ var resizableTableWidth = (0, _expValEquals.expValEquals)('platform_editor_tables_scaling_css', 'isEnabled', true) ? isFullPageEditor ? (0, _misc.getTableResizerContainerForFullPageWidthInCSS)(node, config.isTableScalingEnabled) : "calc(100cqw - calc(var(--ak-editor--large-gutter-padding) * 2))" : "min(calc(100cqw - calc(var(--ak-editor--large-gutter-padding) * 2)), ".concat((_node$attrs$width = node.attrs.width) !== null && _node$attrs$width !== void 0 ? _node$attrs$width : '100%', ")");
46
54
  var colgroup = '';
47
55
  if (config.allowColumnResizing) {
48
- colgroup = ['colgroup', {}].concat((0, _toConsumableArray2.default)((0, _colgroup.generateColgroup)(node)));
56
+ if ((0, _expValEquals.expValEquals)('platform_editor_tables_scaling_css', 'isEnabled', true)) {
57
+ colgroup = ['colgroup', {}].concat((0, _toConsumableArray2.default)((0, _colgroup.generateColgroupFromNode)(node, config.isCommentEditor, config.isChromelessEditor, config.isNested, config.isTableScalingEnabled, config.shouldUseIncreasedScalingPercent)));
58
+ } else {
59
+ colgroup = ['colgroup', {}].concat((0, _toConsumableArray2.default)((0, _colgroup.generateColgroup)(node)));
60
+ }
49
61
  }
62
+
63
+ // For Chromeless editor, and nested tables in full page editor
50
64
  var tableContainerDiv = ['div', {
51
65
  class: 'pm-table-container',
52
66
  'data-number-column': node.attrs.isNumberColumnEnabled,
@@ -73,31 +87,33 @@ var tableNodeSpecWithFixedToDOM = exports.tableNodeSpecWithFixedToDOM = function
73
87
  class: 'pm-table-sticky-sentinel-bottom',
74
88
  'data-testid': 'sticky-sentinel-bottom'
75
89
  }]];
76
- if (!config.tableResizingEnabled) {
90
+ if (!config.tableResizingEnabled || (0, _expValEquals.expValEquals)('platform_editor_tables_scaling_css', 'isEnabled', true) && config.isNested) {
77
91
  return ['div', {
78
92
  class: 'tableView-content-wrap',
79
93
  'data-prosemirror-initial-toDOM-render': 'true'
80
94
  }, tableContainerDiv];
81
95
  }
82
- var tableWidthAttribute = node.attrs.width ? "".concat(node.attrs.width, "px") : "100%";
83
96
  var tableResizingDiv = ['div', {
84
97
  'data-testid': 'table-alignment-container',
85
98
  style: alignmentStyle
86
99
  }, ['div', {
87
100
  class: 'pm-table-resizer-container',
88
- style: "width: min(calc(100cqw - ".concat(gutterPadding(), "), ").concat(tableWidthAttribute, ");")
101
+ style: (0, _lazyNodeView.convertToInlineCss)({
102
+ '--ak-editor-table-gutter-padding': config.isTableScalingEnabled ? 'calc(var(--ak-editor--large-gutter-padding) * 2)' : 'calc(var(--ak-editor--large-gutter-padding) * 2 - var(--ak-editor-resizer-handle-spacing))',
103
+ '--ak-editor-table-width': resizableTableWidth,
104
+ width: (0, _expValEquals.expValEquals)('platform_editor_tables_scaling_css', 'isEnabled', true) ? "var(--ak-editor-table-width)" : "min(calc(100cqw - ".concat(gutterPadding(), "), ").concat(tableWidthAttribute, ")")
105
+ })
89
106
  }, ['div', {
90
107
  class: 'resizer-item display-handle',
91
108
  style: (0, _lazyNodeView.convertToInlineCss)({
92
109
  position: 'relative',
93
110
  userSelect: 'auto',
94
111
  boxSizing: 'border-box',
95
- '--ak-editor-table-gutter-padding': "".concat(gutterPadding()),
96
112
  '--ak-editor-table-max-width': "".concat(_consts.TABLE_MAX_WIDTH, "px"),
97
113
  '--ak-editor-table-min-width': "".concat(tableMinWidth, "px"),
98
114
  minWidth: 'var(--ak-editor-table-min-width)',
99
- maxWidth: "min(calc(100cqw - var(--ak-editor-table-gutter-padding)), var(--ak-editor-table-max-width))",
100
- width: "min(calc(100cqw - var(--ak-editor-table-gutter-padding)), ".concat(tableWidthAttribute, ")")
115
+ maxWidth: (0, _expValEquals.expValEquals)('platform_editor_tables_scaling_css', 'isEnabled', true) ? (0, _misc.getTableResizerContainerMaxWidthInCSS)(config.isCommentEditor, config.isChromelessEditor, config.isTableScalingEnabled) : "min(calc(100cqw - var(--ak-editor-table-gutter-padding)), var(--ak-editor-table-max-width))",
116
+ width: (0, _expValEquals.expValEquals)('platform_editor_tables_scaling_css', 'isEnabled', true) ? (0, _misc.getTableResizerItemWidthInCSS)(node, config.isCommentEditor, config.isChromelessEditor) : "min(calc(100cqw - var(--ak-editor-table-gutter-padding)), ".concat(tableWidthAttribute, ")")
101
117
  })
102
118
  }, ['span', {
103
119
  class: 'resizer-hover-zone'
@@ -15,6 +15,7 @@ var _utils2 = require("@atlaskit/editor-prosemirror/utils");
15
15
  var _editorTables = require("@atlaskit/editor-tables");
16
16
  var _utils3 = require("@atlaskit/editor-tables/utils");
17
17
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
18
+ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
18
19
  var _tableNodeViews = require("../nodeviews/table-node-views");
19
20
  var _plugin = require("../pm-plugins/decorations/plugin");
20
21
  var _types = require("../types");
@@ -59,30 +60,63 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatchAnalytic
59
60
  }
60
61
  return editorView.state;
61
62
  };
62
- var nodeViews = (0, _coreUtils.isSSR)() && (0, _platformFeatureFlags.fg)('platform_editor_table_fallback_to_dom_on_ssr') ? undefined : {
63
- table: (0, _tableNodeViews.tableView)({
64
- portalProviderAPI: portalProviderAPI,
65
- eventDispatcher: eventDispatcher,
66
- getEditorContainerWidth: getEditorContainerWidth,
67
- getEditorFeatureFlags: getEditorFeatureFlags,
68
- dispatchAnalyticsEvent: dispatchAnalyticsEvent,
69
- pluginInjectionApi: pluginInjectionApi,
70
- isCommentEditor: isCommentEditor,
71
- isChromelessEditor: isChromelessEditor
72
- }),
73
- tableRow: (0, _tableNodeViews.tableRowView)({
74
- eventDispatcher: eventDispatcher,
75
- pluginInjectionApi: pluginInjectionApi
76
- }),
77
- tableCell: (0, _tableNodeViews.tableCellView)({
78
- eventDispatcher: eventDispatcher,
79
- pluginInjectionApi: pluginInjectionApi
80
- }),
81
- tableHeader: (0, _tableNodeViews.tableHeaderView)({
82
- eventDispatcher: eventDispatcher,
83
- pluginInjectionApi: pluginInjectionApi
84
- })
63
+ var getNodeView = function getNodeView() {
64
+ // Because the layout shift issues has been fixed under experiment platform_editor_tables_scaling_css, so still want to load nodeview on SSR if experiment is enabled
65
+ if ((0, _expValEquals.expValEquals)('platform_editor_tables_scaling_css', 'isEnabled', true)) {
66
+ return {
67
+ table: (0, _tableNodeViews.tableView)({
68
+ portalProviderAPI: portalProviderAPI,
69
+ eventDispatcher: eventDispatcher,
70
+ getEditorContainerWidth: getEditorContainerWidth,
71
+ getEditorFeatureFlags: getEditorFeatureFlags,
72
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
73
+ pluginInjectionApi: pluginInjectionApi,
74
+ isCommentEditor: isCommentEditor,
75
+ isChromelessEditor: isChromelessEditor
76
+ }),
77
+ tableRow: (0, _tableNodeViews.tableRowView)({
78
+ eventDispatcher: eventDispatcher,
79
+ pluginInjectionApi: pluginInjectionApi
80
+ }),
81
+ tableCell: (0, _tableNodeViews.tableCellView)({
82
+ eventDispatcher: eventDispatcher,
83
+ pluginInjectionApi: pluginInjectionApi
84
+ }),
85
+ tableHeader: (0, _tableNodeViews.tableHeaderView)({
86
+ eventDispatcher: eventDispatcher,
87
+ pluginInjectionApi: pluginInjectionApi
88
+ })
89
+ };
90
+ }
91
+ if ((0, _coreUtils.isSSR)() && (0, _platformFeatureFlags.fg)('platform_editor_table_fallback_to_dom_on_ssr')) {
92
+ return undefined;
93
+ }
94
+ return {
95
+ table: (0, _tableNodeViews.tableView)({
96
+ portalProviderAPI: portalProviderAPI,
97
+ eventDispatcher: eventDispatcher,
98
+ getEditorContainerWidth: getEditorContainerWidth,
99
+ getEditorFeatureFlags: getEditorFeatureFlags,
100
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
101
+ pluginInjectionApi: pluginInjectionApi,
102
+ isCommentEditor: isCommentEditor,
103
+ isChromelessEditor: isChromelessEditor
104
+ }),
105
+ tableRow: (0, _tableNodeViews.tableRowView)({
106
+ eventDispatcher: eventDispatcher,
107
+ pluginInjectionApi: pluginInjectionApi
108
+ }),
109
+ tableCell: (0, _tableNodeViews.tableCellView)({
110
+ eventDispatcher: eventDispatcher,
111
+ pluginInjectionApi: pluginInjectionApi
112
+ }),
113
+ tableHeader: (0, _tableNodeViews.tableHeaderView)({
114
+ eventDispatcher: eventDispatcher,
115
+ pluginInjectionApi: pluginInjectionApi
116
+ })
117
+ };
85
118
  };
119
+ var nodeViews = getNodeView();
86
120
  return new _safePlugin.SafePlugin({
87
121
  state: state,
88
122
  key: _pluginKey.pluginKey,