UNPKG

@atlaskit/editor-common

Version:

A package that contains common classes and components for editor and renderer

62 lines (59 loc) 2.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isTableInContentMode = exports.hasTableColumnBeenResized = exports.hasTableBeenResized = void 0; var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure"); /** * Returns true if any cell in the first row of the table has a colwidth attribute set. * * Used by both the editor (as `hasTableColumnBeenResized`) and the renderer (as `hasColWidths`) * to determine whether a table has had its columns manually resized. */ var hasTableColumnBeenResized = exports.hasTableColumnBeenResized = function hasTableColumnBeenResized(tableNode) { var firstRow = tableNode.content.firstChild; if (!firstRow) { return false; } for (var i = 0; i < firstRow.childCount; i++) { if (firstRow.child(i).attrs.colwidth) { return true; } } return false; }; /** * Returns true if the table has been explicitly resized — either the table itself has a width * attribute set, or any column has been individually resized (colwidth present on cells). */ var hasTableBeenResized = exports.hasTableBeenResized = function hasTableBeenResized(tableNode) { return tableNode.attrs.width !== null || hasTableColumnBeenResized(tableNode); }; /** * Determines whether a table should render in content mode. * * Content mode tables have no fixed column widths — the browser sizes columns to fit their * content (`table-layout: auto`). This is the shared core predicate used by both the editor * and the renderer. Each consumer is responsible for computing `isSupported` from its own * feature flags / props before calling this function. * * A table is in content mode when ALL of the following are true: * 1. The `platform_editor_table_fit_to_content_auto_convert` experiment is enabled * 2. `isSupported` is true (caller has verified resizing is allowed and appearance is full-page) * 3. The table is not nested inside another table or block node * 4. The table node exists * 5. The table has not been explicitly resized (`width === null` and no `colwidth` on cells) * 6. The table's layout is `'align-start'` */ var isTableInContentMode = exports.isTableInContentMode = function isTableInContentMode(_ref) { var tableNode = _ref.tableNode, isSupported = _ref.isSupported, isTableNested = _ref.isTableNested; if (!(0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_table_fit_to_content_auto_convert', 'isEnabled', true)) { return false; } if (!tableNode || isTableNested) { return false; } return isSupported && !hasTableBeenResized(tableNode) && tableNode.attrs.layout === 'align-start'; };