-
Notifications
You must be signed in to change notification settings - Fork 83
feat(table): add configurable table width export mode #888
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
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 |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| '@wangeditor-next/core': patch | ||
| '@wangeditor-next/editor': patch | ||
| '@wangeditor-next/table-module': patch | ||
| --- | ||
|
|
||
| feat(table): add configurable width export mode for table html | ||
|
|
||
| - Added `insertTable.widthExportMode` with `adaptive | explicit`. | ||
| - Default mode remains `explicit` for backward compatibility. | ||
| - `adaptive` mode can be enabled to keep `width:auto` on table export. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,8 @@ import { Element } from 'slate' | |
|
|
||
| import { TableCellElement, TableElement, TableRowElement } from './custom-types' | ||
|
|
||
| type TableWidthExportMode = 'adaptive' | 'explicit' | ||
|
|
||
| function escapeHtml(raw: string): string { | ||
| return raw | ||
| .replace(/&/g, '&') | ||
|
|
@@ -17,13 +19,31 @@ function escapeHtml(raw: string): string { | |
| .replace(/'/g, ''') | ||
| } | ||
|
|
||
| function getExportTableWidth(tableNode: TableElement): string { | ||
| function getTableWidthExportMode(editor?: IDomEditor): TableWidthExportMode { | ||
| if (!editor || typeof editor.getMenuConfig !== 'function') { | ||
| return 'explicit' | ||
| } | ||
|
|
||
| const menuConf = editor.getMenuConfig('insertTable') as { widthExportMode?: TableWidthExportMode } | ||
|
|
||
| return menuConf?.widthExportMode === 'explicit' ? 'explicit' : 'adaptive' | ||
|
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.
Treat missing/unknown Useful? React with 👍 / 👎. |
||
| } | ||
|
Comment on lines
+22
to
+30
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. Default fallback is inverted to This function currently defaults to Suggested fix- return menuConf?.widthExportMode === 'explicit' ? 'explicit' : 'adaptive'
+ return menuConf?.widthExportMode === 'adaptive' ? 'adaptive' : 'explicit'🤖 Prompt for AI Agents |
||
|
|
||
| function getExportTableWidth(tableNode: TableElement, editor?: IDomEditor): string { | ||
| const { width = 'auto', columnWidths = [] } = tableNode | ||
|
|
||
| if (width && width !== 'auto') { | ||
| return width | ||
| } | ||
|
|
||
| const widthExportMode = getTableWidthExportMode(editor) | ||
|
|
||
| // In adaptive mode, keep imported or generated auto-width tables as auto | ||
| // and only persist explicit fixed widths when width is not auto. | ||
| if (widthExportMode === 'adaptive') { | ||
| return 'auto' | ||
| } | ||
|
|
||
| const totalWidth = columnWidths.reduce((sum, columnWidth) => { | ||
| if (!Number.isFinite(columnWidth)) { return sum } | ||
| if (columnWidth <= 0) { return sum } | ||
|
|
@@ -48,7 +68,7 @@ function tableToHtml(elemNode: Element, childrenHtml: string, editor?: IDomEdito | |
|
|
||
| const captionStr = caption ? `<caption>${escapeHtml(caption)}</caption>` : '' | ||
| const colgroupStr = cols ? `<colgroup contentEditable="false">${cols}</colgroup>` : '' | ||
| const exportedWidth = getExportTableWidth(tableNode) | ||
| const exportedWidth = getExportTableWidth(tableNode, editor) | ||
| const textStyleMode = getTextStyleMode(editor) | ||
|
|
||
| if (textStyleMode === 'class') { | ||
|
|
||
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.
widthExportModeis typed on the wrong menu config contract key.widthExportModewas added toIInsertTableConfig, butIMenuConfigcurrently binds that type toinsertTableRow, while runtime/test usage readsMENU_CONF.insertTable. This makes the new publictype contract inaccurate and hides the real config shape behind
ISingleMenuConfig’s index signature.Suggested contract alignment
interface IMenuConfig { - insertTable: ISingleMenuConfig; + insertTable: IInsertTableConfig; deleteTable: ISingleMenuConfig; - insertTableRow: IInsertTableConfig; + insertTableRow: ISingleMenuConfig; deleteTableRow: ISingleMenuConfig; ... }🤖 Prompt for AI Agents