/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ // @generated by scripts/generate-node-json.mjs from each class's `json` // schema. Run `pnpm run generate-node-json` to regenerate; do not edit. // Keys are emitted in the order the schema-driven walk writes them, so the two // produce byte-identical JSON. That order is the schema's, not alphabetical. /* eslint-disable sort-keys-fix/sort-keys-fix */ import type {TableCellNode} from './LexicalTableCellNode'; import type {TableNode} from './LexicalTableNode'; import type {TableRowNode} from './LexicalTableRowNode'; import { type GeneratedJSONFactory, getterTableOf, setterDefaultOf, setterTableOf, } from 'lexical'; // The JSON number grammar, anchored, matching numberValue: `Number()` alone // reads '0x10' as 16 and '' as 0, and neither is a shape a JSON encoder // produces. Emitted from the same source the codegen verified against, so the // two cannot be different functions. const JSON_NUMBER = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/; function num(v: unknown, d: number): number { if (typeof v === 'number') { return Number.isFinite(v) ? v : d; } if (typeof v !== 'string' || !JSON_NUMBER.test(v)) { return d; } const n = Number(v); return Number.isFinite(n) ? n : d; } function numC( v: unknown, d: number, min: number, max: number, integer: boolean, ): number { const n = num(v, d); return n >= min && n <= max && (!integer || Number.isInteger(n)) ? n : d; } /** * TableNode's schema-declared fields, for a clone. Generated from that * schema; do not edit by hand. * * @internal */ export function afterCloneTableNode( node: TableNode, prevNode: TableNode, ): void { node.__colWidths = prevNode.__colWidths; node.__frozenColumnCount = prevNode.__frozenColumnCount; node.__frozenRowCount = prevNode.__frozenRowCount; node.__rowStriping = prevNode.__rowStriping; } /** TableNode's generated implementations, for its `$config`. @internal */ export const GENERATED_TABLE: GeneratedJSONFactory = fields => { const TABLE_FORMAT_GETTER = getterTableOf(fields, 'format') as { readonly [key: string]: | '' | 'center' | 'end' | 'justify' | 'left' | 'right' | 'start'; }; const TABLE_FORMAT_SETTER = setterTableOf(fields, 'format') as { readonly [key: string]: 0 | 1 | 2 | 3 | 4 | 5 | 6; }; const TABLE_FORMAT_SETTER_DEFAULT = setterDefaultOf(fields, 'format') as | 0 | 1 | 2 | 3 | 4 | 5 | 6; /** Generated from TableNode's serialization schema. Do not edit by hand. */ function exportTableNode(node: TableNode): {[key: string]: unknown} { const textFormat = node.__textFormat; const textStyle = node.__textStyle; const shouldSerializeTextStyles = (textFormat !== 0 || textStyle !== '') && node.shouldSerializeTextStyles(); return { children: [], colWidths: node.__colWidths, frozenColumnCount: node.getSerializedFrozenColumnCount(), frozenRowCount: node.getSerializedFrozenRowCount(), rowStriping: node.getSerializedRowStriping(), direction: node.__dir, format: TABLE_FORMAT_GETTER[node.__format], indent: node.__indent, textFormat: textFormat !== 0 && shouldSerializeTextStyles ? textFormat : undefined, textStyle: textStyle !== '' && shouldSerializeTextStyles ? textStyle : undefined, type: node.__type, version: 1, }; } /** Generated from TableNode's serialization schema. Do not edit by hand. */ function exportCompactTableNode(node: TableNode): {[key: string]: unknown} { const textFormat = node.__textFormat; const textStyle = node.__textStyle; const shouldSerializeTextStyles = (textFormat !== 0 || textStyle !== '') && node.shouldSerializeTextStyles(); const json: {[key: string]: unknown} = {type: node.__type, children: []}; const colWidths = node.__colWidths; if (colWidths !== undefined) { json.colWidths = colWidths; } const frozenColumnCount = node.getSerializedFrozenColumnCount(); if (frozenColumnCount !== undefined && frozenColumnCount !== 0) { json.frozenColumnCount = frozenColumnCount; } const frozenRowCount = node.getSerializedFrozenRowCount(); if (frozenRowCount !== undefined && frozenRowCount !== 0) { json.frozenRowCount = frozenRowCount; } const rowStriping = node.getSerializedRowStriping(); if (rowStriping !== undefined && rowStriping !== false) { json.rowStriping = rowStriping; } const direction = node.__dir; if (direction != null) { json.direction = direction; } const format = TABLE_FORMAT_GETTER[node.__format]; if (format !== undefined && format !== '') { json.format = format; } const indent = node.__indent; if (indent !== undefined && indent !== 0) { json.indent = indent; } if ( textFormat !== undefined && textFormat !== 0 && shouldSerializeTextStyles ) { json.textFormat = textFormat; } if ( textStyle !== undefined && textStyle !== '' && shouldSerializeTextStyles ) { json.textStyle = textStyle; } return json; } /** Generated from TableNode's serialization schema. Do not edit by hand. */ function updateTableNode( node: TableNode, json: {readonly [key: string]: unknown}, ): TableNode { const direction = json.direction; node.__dir = direction === null || direction === 'ltr' || direction === 'rtl' ? direction : null; const format = json.format; node.__format = typeof format === 'string' && format in TABLE_FORMAT_SETTER ? TABLE_FORMAT_SETTER[format] : TABLE_FORMAT_SETTER_DEFAULT; node.__indent = numC(json.indent, 0, 0, Infinity, true); node.__textFormat = num(json.textFormat, 0); const textStyle = json.textStyle; node.__textStyle = typeof textStyle === 'string' ? textStyle : ''; const colWidths = json.colWidths; node.setColWidths( colWidths === undefined ? undefined : Array.isArray(colWidths) ? Array.from(colWidths, e0 => num(e0, 0)) : [], ); node.__frozenColumnCount = num(json.frozenColumnCount, 0); node.__frozenRowCount = num(json.frozenRowCount, 0); const rowStriping = json.rowStriping; node.__rowStriping = typeof rowStriping === 'boolean' ? rowStriping : false; return node; } return { exportJSON: exportTableNode, exportCompactJSON: exportCompactTableNode, updateFromJSON: updateTableNode, afterCloneFrom: afterCloneTableNode, }; }; /** * TableRowNode's schema-declared fields, for a clone. Generated from that * schema; do not edit by hand. * * @internal */ export function afterCloneTableRowNode( node: TableRowNode, prevNode: TableRowNode, ): void { node.__height = prevNode.__height; } /** TableRowNode's generated implementations, for its `$config`. @internal */ export const GENERATED_TABLEROW: GeneratedJSONFactory = fields => { const TABLEROW_FORMAT_GETTER = getterTableOf(fields, 'format') as { readonly [key: string]: | '' | 'center' | 'end' | 'justify' | 'left' | 'right' | 'start'; }; const TABLEROW_FORMAT_SETTER = setterTableOf(fields, 'format') as { readonly [key: string]: 0 | 1 | 2 | 3 | 4 | 5 | 6; }; const TABLEROW_FORMAT_SETTER_DEFAULT = setterDefaultOf(fields, 'format') as | 0 | 1 | 2 | 3 | 4 | 5 | 6; /** Generated from TableRowNode's serialization schema. Do not edit by hand. */ function exportTableRowNode(node: TableRowNode): {[key: string]: unknown} { const textFormat = node.__textFormat; const textStyle = node.__textStyle; const shouldSerializeTextStyles = (textFormat !== 0 || textStyle !== '') && node.shouldSerializeTextStyles(); return { children: [], height: node.__height, direction: node.__dir, format: TABLEROW_FORMAT_GETTER[node.__format], indent: node.__indent, textFormat: textFormat !== 0 && shouldSerializeTextStyles ? textFormat : undefined, textStyle: textStyle !== '' && shouldSerializeTextStyles ? textStyle : undefined, type: node.__type, version: 1, }; } /** Generated from TableRowNode's serialization schema. Do not edit by hand. */ function exportCompactTableRowNode(node: TableRowNode): { [key: string]: unknown; } { const textFormat = node.__textFormat; const textStyle = node.__textStyle; const shouldSerializeTextStyles = (textFormat !== 0 || textStyle !== '') && node.shouldSerializeTextStyles(); const json: {[key: string]: unknown} = {type: node.__type, children: []}; const height = node.__height; if (height !== undefined) { json.height = height; } const direction = node.__dir; if (direction != null) { json.direction = direction; } const format = TABLEROW_FORMAT_GETTER[node.__format]; if (format !== undefined && format !== '') { json.format = format; } const indent = node.__indent; if (indent !== undefined && indent !== 0) { json.indent = indent; } if ( textFormat !== undefined && textFormat !== 0 && shouldSerializeTextStyles ) { json.textFormat = textFormat; } if ( textStyle !== undefined && textStyle !== '' && shouldSerializeTextStyles ) { json.textStyle = textStyle; } return json; } /** Generated from TableRowNode's serialization schema. Do not edit by hand. */ function updateTableRowNode( node: TableRowNode, json: {readonly [key: string]: unknown}, ): TableRowNode { const direction = json.direction; node.__dir = direction === null || direction === 'ltr' || direction === 'rtl' ? direction : null; const format = json.format; node.__format = typeof format === 'string' && format in TABLEROW_FORMAT_SETTER ? TABLEROW_FORMAT_SETTER[format] : TABLEROW_FORMAT_SETTER_DEFAULT; node.__indent = numC(json.indent, 0, 0, Infinity, true); node.__textFormat = num(json.textFormat, 0); const textStyle = json.textStyle; node.__textStyle = typeof textStyle === 'string' ? textStyle : ''; const height = json.height; node.__height = height === undefined ? undefined : num(height, 0); return node; } return { exportJSON: exportTableRowNode, exportCompactJSON: exportCompactTableRowNode, updateFromJSON: updateTableRowNode, afterCloneFrom: afterCloneTableRowNode, }; }; /** * TableCellNode's schema-declared fields, for a clone. Generated from that * schema; do not edit by hand. * * @internal */ export function afterCloneTableCellNode( node: TableCellNode, prevNode: TableCellNode, ): void { node.__backgroundColor = prevNode.__backgroundColor; node.__colSpan = prevNode.__colSpan; node.__headerState = prevNode.__headerState; node.__rowSpan = prevNode.__rowSpan; node.__verticalAlign = prevNode.__verticalAlign; node.__width = prevNode.__width; } /** TableCellNode's generated implementations, for its `$config`. @internal */ export const GENERATED_TABLECELL: GeneratedJSONFactory = fields => { const TABLECELL_FORMAT_GETTER = getterTableOf(fields, 'format') as { readonly [key: string]: | '' | 'center' | 'end' | 'justify' | 'left' | 'right' | 'start'; }; const TABLECELL_FORMAT_SETTER = setterTableOf(fields, 'format') as { readonly [key: string]: 0 | 1 | 2 | 3 | 4 | 5 | 6; }; const TABLECELL_FORMAT_SETTER_DEFAULT = setterDefaultOf(fields, 'format') as | 0 | 1 | 2 | 3 | 4 | 5 | 6; /** Generated from TableCellNode's serialization schema. Do not edit by hand. */ function exportTableCellNode(node: TableCellNode): {[key: string]: unknown} { const textFormat = node.__textFormat; const textStyle = node.__textStyle; const shouldSerializeTextStyles = (textFormat !== 0 || textStyle !== '') && node.shouldSerializeTextStyles(); return { children: [], backgroundColor: node.__backgroundColor, colSpan: node.__colSpan, headerState: node.__headerState, rowSpan: node.__rowSpan, verticalAlign: node.getSerializedVerticalAlign(), width: node.__width, direction: node.__dir, format: TABLECELL_FORMAT_GETTER[node.__format], indent: node.__indent, textFormat: textFormat !== 0 && shouldSerializeTextStyles ? textFormat : undefined, textStyle: textStyle !== '' && shouldSerializeTextStyles ? textStyle : undefined, type: node.__type, version: 1, }; } /** Generated from TableCellNode's serialization schema. Do not edit by hand. */ function exportCompactTableCellNode(node: TableCellNode): { [key: string]: unknown; } { const textFormat = node.__textFormat; const textStyle = node.__textStyle; const shouldSerializeTextStyles = (textFormat !== 0 || textStyle !== '') && node.shouldSerializeTextStyles(); const json: {[key: string]: unknown} = {type: node.__type, children: []}; const backgroundColor = node.__backgroundColor; if (backgroundColor != null) { json.backgroundColor = backgroundColor; } const colSpan = node.__colSpan; if (colSpan !== undefined && colSpan !== 1) { json.colSpan = colSpan; } const headerState = node.__headerState; if (headerState !== undefined && headerState !== 0) { json.headerState = headerState; } const rowSpan = node.__rowSpan; if (rowSpan !== undefined && rowSpan !== 1) { json.rowSpan = rowSpan; } const verticalAlign = node.getSerializedVerticalAlign(); if (verticalAlign !== undefined) { json.verticalAlign = verticalAlign; } const width = node.__width; if (width !== undefined) { json.width = width; } const direction = node.__dir; if (direction != null) { json.direction = direction; } const format = TABLECELL_FORMAT_GETTER[node.__format]; if (format !== undefined && format !== '') { json.format = format; } const indent = node.__indent; if (indent !== undefined && indent !== 0) { json.indent = indent; } if ( textFormat !== undefined && textFormat !== 0 && shouldSerializeTextStyles ) { json.textFormat = textFormat; } if ( textStyle !== undefined && textStyle !== '' && shouldSerializeTextStyles ) { json.textStyle = textStyle; } return json; } /** Generated from TableCellNode's serialization schema. Do not edit by hand. */ function updateTableCellNode( node: TableCellNode, json: {readonly [key: string]: unknown}, ): TableCellNode { const direction = json.direction; node.__dir = direction === null || direction === 'ltr' || direction === 'rtl' ? direction : null; const format = json.format; node.__format = typeof format === 'string' && format in TABLECELL_FORMAT_SETTER ? TABLECELL_FORMAT_SETTER[format] : TABLECELL_FORMAT_SETTER_DEFAULT; node.__indent = numC(json.indent, 0, 0, Infinity, true); node.__textFormat = num(json.textFormat, 0); const textStyle = json.textStyle; node.__textStyle = typeof textStyle === 'string' ? textStyle : ''; const backgroundColor = json.backgroundColor; node.__backgroundColor = typeof backgroundColor === 'string' && backgroundColor !== '' ? backgroundColor : null; node.__colSpan = numC(json.colSpan, 1, 1, Infinity, true); node.setHeaderStyles(num(json.headerState, 0)); node.__rowSpan = numC(json.rowSpan, 1, 1, Infinity, true); const verticalAlign = json.verticalAlign; node.__verticalAlign = verticalAlign === 'middle' || verticalAlign === 'bottom' ? verticalAlign : undefined; const width = json.width; node.__width = width === undefined || num(width, 0) === 0 ? undefined : num(width, 0); return node; } return { exportJSON: exportTableCellNode, exportCompactJSON: exportCompactTableCellNode, updateFromJSON: updateTableCellNode, afterCloneFrom: afterCloneTableCellNode, }; };