-
Notifications
You must be signed in to change notification settings - Fork 53
feat: adaptive insert table column width #1533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,10 @@ | ||
| // @ts-check | ||
| export const createCell = (cellType, cellContent = null) => { | ||
| export const createCell = (cellType, cellContent = null, attrs = null) => { | ||
| if (cellContent) { | ||
| return cellType.createChecked(null, cellContent); | ||
| return cellType.createChecked(attrs, cellContent); | ||
| } | ||
| if (attrs) { | ||
| return cellType.createAndFill(attrs); | ||
| } | ||
| return cellType.createAndFill(); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,13 +12,16 @@ import { createTableBorders } from './createTableBorders.js'; | |
| * @param {number} colsCount - Number of columns | ||
| * @param {boolean} withHeaderRow - Create first row as header | ||
| * @param {Object} [cellContent=null] - Initial cell content | ||
| * @param {number[]} [columnWidths=null] - Array of pixel widths per column | ||
| * @returns {Object} Complete table node with borders | ||
| * @example | ||
| * const table = createTable(schema, 3, 3, true) | ||
| * @example | ||
| * const table = createTable(schema, 2, 4, false, paragraphNode) | ||
| * @example | ||
| * const table = createTable(schema, 3, 3, false, null, [200, 100, 200]) | ||
| */ | ||
| export const createTable = (schema, rowsCount, colsCount, withHeaderRow, cellContent = null) => { | ||
| export const createTable = (schema, rowsCount, colsCount, withHeaderRow, cellContent = null, columnWidths = null) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recommend changing function signature to take an object with named options, rather than an ordered list of positional arguments; with a long list of arguments, it's hard to look at a |
||
| const types = { | ||
| table: getNodeType('table', schema), | ||
| tableRow: getNodeType('tableRow', schema), | ||
|
|
@@ -30,10 +33,11 @@ export const createTable = (schema, rowsCount, colsCount, withHeaderRow, cellCon | |
| const cells = []; | ||
|
|
||
| for (let index = 0; index < colsCount; index++) { | ||
| const cell = createCell(types.tableCell, cellContent); | ||
| const cellAttrs = columnWidths ? { colwidth: [columnWidths[index]] } : null; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if |
||
| const cell = createCell(types.tableCell, cellContent, cellAttrs); | ||
| if (cell) cells.push(cell); | ||
| if (withHeaderRow) { | ||
| const headerCell = createCell(types.tableHeader, cellContent); | ||
| const headerCell = createCell(types.tableHeader, cellContent, cellAttrs); | ||
| if (headerCell) { | ||
| headerCells.push(headerCell); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
pixelsToIncheshelper