@tiptap/extension-table 3.27.3 → 3.27.4

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.
@@ -27,7 +27,7 @@ module.exports = __toCommonJS(index_exports);
27
27
  // src/cell/table-cell.ts
28
28
  var import_core = require("@tiptap/core");
29
29
 
30
- // src/utilities/parseAlign.ts
30
+ // src/utils/parseAlign.ts
31
31
  function normalizeTableCellAlign(value) {
32
32
  if (value === "left" /* Left */ || value === "right" /* Right */ || value === "center" /* Center */) {
33
33
  return value;
@@ -55,6 +55,26 @@ function createAlignAttribute() {
55
55
  };
56
56
  }
57
57
 
58
+ // src/utils/parseColwidth.ts
59
+ function parseColgroupWidth(element) {
60
+ var _a;
61
+ const row = element.parentElement;
62
+ const table = element.closest("table");
63
+ if (!row || !table) {
64
+ return null;
65
+ }
66
+ const cellIndex = Array.from(row.children).indexOf(element);
67
+ const width = (_a = table.querySelectorAll("colgroup > col")[cellIndex]) == null ? void 0 : _a.getAttribute("width");
68
+ return width ? [parseInt(width, 10)] : null;
69
+ }
70
+ function parseColwidth(element) {
71
+ const colwidth = element.getAttribute("colwidth");
72
+ if (colwidth) {
73
+ return colwidth.split(",").map((width) => parseInt(width, 10));
74
+ }
75
+ return parseColgroupWidth(element);
76
+ }
77
+
58
78
  // src/cell/table-cell.ts
59
79
  var TableCell = import_core.Node.create({
60
80
  name: "tableCell",
@@ -74,20 +94,7 @@ var TableCell = import_core.Node.create({
74
94
  },
75
95
  colwidth: {
76
96
  default: null,
77
- parseHTML: (element) => {
78
- var _a, _b;
79
- const colwidth = element.getAttribute("colwidth");
80
- const value = colwidth ? colwidth.split(",").map((width) => parseInt(width, 10)) : null;
81
- if (!value) {
82
- const cols = (_a = element.closest("table")) == null ? void 0 : _a.querySelectorAll("colgroup > col");
83
- const cellIndex = Array.from(((_b = element.parentElement) == null ? void 0 : _b.children) || []).indexOf(element);
84
- if (cellIndex && cellIndex > -1 && cols && cols[cellIndex]) {
85
- const colWidth = cols[cellIndex].getAttribute("width");
86
- return colWidth ? [parseInt(colWidth, 10)] : null;
87
- }
88
- }
89
- return value;
90
- }
97
+ parseHTML: parseColwidth
91
98
  },
92
99
  align: createAlignAttribute()
93
100
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cell/index.ts","../../src/cell/table-cell.ts","../../src/utilities/parseAlign.ts"],"sourcesContent":["export * from './table-cell.js'\n","import '../types.js'\n\nimport { mergeAttributes, Node } from '@tiptap/core'\n\nimport { createAlignAttribute } from '../utilities/parseAlign.js'\n\nexport interface TableCellOptions {\n /**\n * The HTML attributes for a table cell node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n}\n\n/**\n * This extension allows you to create table cells.\n * @see https://www.tiptap.dev/api/nodes/table-cell\n */\nexport const TableCell = Node.create<TableCellOptions>({\n name: 'tableCell',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n }\n },\n\n content: 'block+',\n\n addAttributes() {\n return {\n colspan: {\n default: 1,\n },\n rowspan: {\n default: 1,\n },\n colwidth: {\n default: null,\n parseHTML: element => {\n const colwidth = element.getAttribute('colwidth')\n const value = colwidth ? colwidth.split(',').map(width => parseInt(width, 10)) : null\n\n // if there is no colwidth attribute on the cell, try to get it from the colgroup\n if (!value) {\n const cols = element.closest('table')?.querySelectorAll('colgroup > col')\n const cellIndex = Array.from(element.parentElement?.children || []).indexOf(element)\n\n if (cellIndex && cellIndex > -1 && cols && cols[cellIndex]) {\n const colWidth = cols[cellIndex].getAttribute('width')\n return colWidth ? [parseInt(colWidth, 10)] : null\n }\n }\n\n return value\n },\n },\n align: createAlignAttribute(),\n }\n },\n\n tableRole: 'cell',\n\n isolating: true,\n\n parseHTML() {\n return [{ tag: 'td' }]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['td', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n})\n","import type { Attribute } from '@tiptap/core'\n\n/**\n * Supported table cell alignment values\n */\nexport enum TableCellAlign {\n Left = 'left',\n Right = 'right',\n Center = 'center',\n}\n\n/**\n * Normalize unknown input into a supported table alignment\n *\n * @param value - A potential alignment value\n * @returns A valid TableCellAlign value or null\n */\nexport function normalizeTableCellAlign(value: unknown): TableCellAlign | null {\n if (\n value === TableCellAlign.Left ||\n value === TableCellAlign.Right ||\n value === TableCellAlign.Center\n ) {\n return value\n }\n\n return null\n}\n\n/**\n * Parse table cell alignment from an HTML element\n *\n * Prefers inline style (${\"`\"}text-align${\"`\"}) and falls back to the legacy\n * ${\"`\"}align${\"`\"} attribute.\n *\n * @param element - The table cell/header DOM element\n * @returns A valid TableCellAlign value or null\n */\nexport function parseAlign(element: HTMLElement): TableCellAlign | null {\n const styleAlign = (element.style.textAlign || '').trim().toLowerCase()\n const attrAlign = (element.getAttribute('align') || '').trim().toLowerCase()\n const align = styleAlign || attrAlign\n\n return normalizeTableCellAlign(align)\n}\n\n/**\n * Normalize alignment from a generic attrs object that may include an align field\n *\n * @param attributes - A node attrs-like object with an optional align field\n * @returns A valid TableCellAlign value or null.\n */\nexport function normalizeTableCellAlignFromAttributes(\n attributes: { align?: TableCellAlign } | null | undefined,\n): TableCellAlign | null {\n return normalizeTableCellAlign(attributes?.align)\n}\n\n/**\n * Create a reusable Tiptap attribute config for table alignment\n *\n * @returns A Tiptap Attribute definition that parses and renders table alignment\n */\nexport function createAlignAttribute(): Attribute {\n return {\n default: null,\n parseHTML: (element: HTMLElement) => parseAlign(element),\n renderHTML: (attributes: { align?: TableCellAlign | null }) => {\n if (!attributes.align) {\n return {}\n }\n\n return {\n style: `text-align: ${attributes.align}`,\n }\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,kBAAsC;;;ACe/B,SAAS,wBAAwB,OAAuC;AAC7E,MACE,UAAU,qBACV,UAAU,uBACV,UAAU,uBACV;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAWO,SAAS,WAAW,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WAAW,CAAC,SAAS,UAAU,EAAE,CAAC,IAAI;AAAA,YAC/C;AAAA,UACF;AAEA,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,MACA,OAAO,qBAAqB;AAAA,IAC9B;AAAA,EACF;AAAA,EAEA,WAAW;AAAA,EAEX,WAAW;AAAA,EAEX,YAAY;AACV,WAAO,CAAC,EAAE,KAAK,KAAK,CAAC;AAAA,EACvB;AAAA,EAEA,WAAW,EAAE,eAAe,GAAG;AAC7B,WAAO,CAAC,UAAM,6BAAgB,KAAK,QAAQ,gBAAgB,cAAc,GAAG,CAAC;AAAA,EAC/E;AACF,CAAC;","names":[]}
1
+ {"version":3,"sources":["../../src/cell/index.ts","../../src/cell/table-cell.ts","../../src/utils/parseAlign.ts","../../src/utils/parseColwidth.ts"],"sourcesContent":["export * from './table-cell.js'\n","import '../types.js'\n\nimport { mergeAttributes, Node } from '@tiptap/core'\n\nimport { createAlignAttribute } from '../utils/parseAlign.js'\nimport { parseColwidth } from '../utils/parseColwidth.js'\n\nexport interface TableCellOptions {\n /**\n * The HTML attributes for a table cell node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n}\n\n/**\n * This extension allows you to create table cells.\n * @see https://www.tiptap.dev/api/nodes/table-cell\n */\nexport const TableCell = Node.create<TableCellOptions>({\n name: 'tableCell',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n }\n },\n\n content: 'block+',\n\n addAttributes() {\n return {\n colspan: {\n default: 1,\n },\n rowspan: {\n default: 1,\n },\n colwidth: {\n default: null,\n parseHTML: parseColwidth,\n },\n align: createAlignAttribute(),\n }\n },\n\n tableRole: 'cell',\n\n isolating: true,\n\n parseHTML() {\n return [{ tag: 'td' }]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['td', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n})\n","import type { Attribute } from '@tiptap/core'\n\n/**\n * Supported table cell alignment values\n */\nexport enum TableCellAlign {\n Left = 'left',\n Right = 'right',\n Center = 'center',\n}\n\n/**\n * Normalize unknown input into a supported table alignment\n *\n * @param value - A potential alignment value\n * @returns A valid TableCellAlign value or null\n */\nexport function normalizeTableCellAlign(value: unknown): TableCellAlign | null {\n if (\n value === TableCellAlign.Left ||\n value === TableCellAlign.Right ||\n value === TableCellAlign.Center\n ) {\n return value\n }\n\n return null\n}\n\n/**\n * Parse table cell alignment from an HTML element\n *\n * Prefers inline style (${\"`\"}text-align${\"`\"}) and falls back to the legacy\n * ${\"`\"}align${\"`\"} attribute.\n *\n * @param element - The table cell/header DOM element\n * @returns A valid TableCellAlign value or null\n */\nexport function parseAlign(element: HTMLElement): TableCellAlign | null {\n const styleAlign = (element.style.textAlign || '').trim().toLowerCase()\n const attrAlign = (element.getAttribute('align') || '').trim().toLowerCase()\n const align = styleAlign || attrAlign\n\n return normalizeTableCellAlign(align)\n}\n\n/**\n * Normalize alignment from a generic attrs object that may include an align field\n *\n * @param attributes - A node attrs-like object with an optional align field\n * @returns A valid TableCellAlign value or null.\n */\nexport function normalizeTableCellAlignFromAttributes(\n attributes: { align?: TableCellAlign } | null | undefined,\n): TableCellAlign | null {\n return normalizeTableCellAlign(attributes?.align)\n}\n\n/**\n * Create a reusable Tiptap attribute config for table alignment\n *\n * @returns A Tiptap Attribute definition that parses and renders table alignment\n */\nexport function createAlignAttribute(): Attribute {\n return {\n default: null,\n parseHTML: (element: HTMLElement) => parseAlign(element),\n renderHTML: (attributes: { align?: TableCellAlign | null }) => {\n if (!attributes.align) {\n return {}\n }\n\n return {\n style: `text-align: ${attributes.align}`,\n }\n },\n }\n}\n","/**\n * reads the width of the `<col>` element matching a cell's column from the table's `<colgroup>`\n *\n * @param element - The table cell/header DOM element\n * @returns - An array with the column width in pixels or null\n */\nfunction parseColgroupWidth(element: HTMLElement): number[] | null {\n const row = element.parentElement\n const table = element.closest('table')\n\n if (!row || !table) {\n return null\n }\n\n const cellIndex = Array.from(row.children).indexOf(element)\n const width = table.querySelectorAll('colgroup > col')[cellIndex]?.getAttribute('width')\n\n return width ? [parseInt(width, 10)] : null\n}\n\n/**\n * Parse the column width/s of a table cell/header from an HTML element.\n * it prefers the `colwidth` attribute and if not-provided falls back to the `width` attribute\n * of the matching `<col>` element in the table's `<colgroup>`.\n *\n * @param element - The table cell/header DOM element\n * @returns - An array of column widths in pixels or null\n */\nexport function parseColwidth(element: HTMLElement): number[] | null {\n const colwidth = element.getAttribute('colwidth')\n\n if (colwidth) {\n return colwidth.split(',').map(width => parseInt(width, 10))\n }\n\n return parseColgroupWidth(element)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,kBAAsC;;;ACe/B,SAAS,wBAAwB,OAAuC;AAC7E,MACE,UAAU,qBACV,UAAU,uBACV,UAAU,uBACV;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAWO,SAAS,WAAW,SAA6C;AACtE,QAAM,cAAc,QAAQ,MAAM,aAAa,IAAI,KAAK,EAAE,YAAY;AACtE,QAAM,aAAa,QAAQ,aAAa,OAAO,KAAK,IAAI,KAAK,EAAE,YAAY;AAC3E,QAAM,QAAQ,cAAc;AAE5B,SAAO,wBAAwB,KAAK;AACtC;AAmBO,SAAS,uBAAkC;AAChD,SAAO;AAAA,IACL,SAAS;AAAA,IACT,WAAW,CAAC,YAAyB,WAAW,OAAO;AAAA,IACvD,YAAY,CAAC,eAAkD;AAC7D,UAAI,CAAC,WAAW,OAAO;AACrB,eAAO,CAAC;AAAA,MACV;AAEA,aAAO;AAAA,QACL,OAAO,eAAe,WAAW,KAAK;AAAA,MACxC;AAAA,IACF;AAAA,EACF;AACF;;;ACvEA,SAAS,mBAAmB,SAAuC;AANnE;AAOE,QAAM,MAAM,QAAQ;AACpB,QAAM,QAAQ,QAAQ,QAAQ,OAAO;AAErC,MAAI,CAAC,OAAO,CAAC,OAAO;AAClB,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,MAAM,KAAK,IAAI,QAAQ,EAAE,QAAQ,OAAO;AAC1D,QAAM,SAAQ,WAAM,iBAAiB,gBAAgB,EAAE,SAAS,MAAlD,mBAAqD,aAAa;AAEhF,SAAO,QAAQ,CAAC,SAAS,OAAO,EAAE,CAAC,IAAI;AACzC;AAUO,SAAS,cAAc,SAAuC;AACnE,QAAM,WAAW,QAAQ,aAAa,UAAU;AAEhD,MAAI,UAAU;AACZ,WAAO,SAAS,MAAM,GAAG,EAAE,IAAI,WAAS,SAAS,OAAO,EAAE,CAAC;AAAA,EAC7D;AAEA,SAAO,mBAAmB,OAAO;AACnC;;;AFhBO,IAAM,YAAY,iBAAK,OAAyB;AAAA,EACrD,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,gBAAgB,CAAC;AAAA,IACnB;AAAA,EACF;AAAA,EAEA,SAAS;AAAA,EAET,gBAAgB;AACd,WAAO;AAAA,MACL,SAAS;AAAA,QACP,SAAS;AAAA,MACX;AAAA,MACA,SAAS;AAAA,QACP,SAAS;AAAA,MACX;AAAA,MACA,UAAU;AAAA,QACR,SAAS;AAAA,QACT,WAAW;AAAA,MACb;AAAA,MACA,OAAO,qBAAqB;AAAA,IAC9B;AAAA,EACF;AAAA,EAEA,WAAW;AAAA,EAEX,WAAW;AAAA,EAEX,YAAY;AACV,WAAO,CAAC,EAAE,KAAK,KAAK,CAAC;AAAA,EACvB;AAAA,EAEA,WAAW,EAAE,eAAe,GAAG;AAC7B,WAAO,CAAC,UAAM,6BAAgB,KAAK,QAAQ,gBAAgB,cAAc,GAAG,CAAC;AAAA,EAC/E;AACF,CAAC;","names":[]}
@@ -1,7 +1,7 @@
1
1
  // src/cell/table-cell.ts
2
2
  import { mergeAttributes, Node } from "@tiptap/core";
3
3
 
4
- // src/utilities/parseAlign.ts
4
+ // src/utils/parseAlign.ts
5
5
  function normalizeTableCellAlign(value) {
6
6
  if (value === "left" /* Left */ || value === "right" /* Right */ || value === "center" /* Center */) {
7
7
  return value;
@@ -29,6 +29,26 @@ function createAlignAttribute() {
29
29
  };
30
30
  }
31
31
 
32
+ // src/utils/parseColwidth.ts
33
+ function parseColgroupWidth(element) {
34
+ var _a;
35
+ const row = element.parentElement;
36
+ const table = element.closest("table");
37
+ if (!row || !table) {
38
+ return null;
39
+ }
40
+ const cellIndex = Array.from(row.children).indexOf(element);
41
+ const width = (_a = table.querySelectorAll("colgroup > col")[cellIndex]) == null ? void 0 : _a.getAttribute("width");
42
+ return width ? [parseInt(width, 10)] : null;
43
+ }
44
+ function parseColwidth(element) {
45
+ const colwidth = element.getAttribute("colwidth");
46
+ if (colwidth) {
47
+ return colwidth.split(",").map((width) => parseInt(width, 10));
48
+ }
49
+ return parseColgroupWidth(element);
50
+ }
51
+
32
52
  // src/cell/table-cell.ts
33
53
  var TableCell = Node.create({
34
54
  name: "tableCell",
@@ -48,20 +68,7 @@ var TableCell = Node.create({
48
68
  },
49
69
  colwidth: {
50
70
  default: null,
51
- parseHTML: (element) => {
52
- var _a, _b;
53
- const colwidth = element.getAttribute("colwidth");
54
- const value = colwidth ? colwidth.split(",").map((width) => parseInt(width, 10)) : null;
55
- if (!value) {
56
- const cols = (_a = element.closest("table")) == null ? void 0 : _a.querySelectorAll("colgroup > col");
57
- const cellIndex = Array.from(((_b = element.parentElement) == null ? void 0 : _b.children) || []).indexOf(element);
58
- if (cellIndex && cellIndex > -1 && cols && cols[cellIndex]) {
59
- const colWidth = cols[cellIndex].getAttribute("width");
60
- return colWidth ? [parseInt(colWidth, 10)] : null;
61
- }
62
- }
63
- return value;
64
- }
71
+ parseHTML: parseColwidth
65
72
  },
66
73
  align: createAlignAttribute()
67
74
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cell/table-cell.ts","../../src/utilities/parseAlign.ts"],"sourcesContent":["import '../types.js'\n\nimport { mergeAttributes, Node } from '@tiptap/core'\n\nimport { createAlignAttribute } from '../utilities/parseAlign.js'\n\nexport interface TableCellOptions {\n /**\n * The HTML attributes for a table cell node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n}\n\n/**\n * This extension allows you to create table cells.\n * @see https://www.tiptap.dev/api/nodes/table-cell\n */\nexport const TableCell = Node.create<TableCellOptions>({\n name: 'tableCell',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n }\n },\n\n content: 'block+',\n\n addAttributes() {\n return {\n colspan: {\n default: 1,\n },\n rowspan: {\n default: 1,\n },\n colwidth: {\n default: null,\n parseHTML: element => {\n const colwidth = element.getAttribute('colwidth')\n const value = colwidth ? colwidth.split(',').map(width => parseInt(width, 10)) : null\n\n // if there is no colwidth attribute on the cell, try to get it from the colgroup\n if (!value) {\n const cols = element.closest('table')?.querySelectorAll('colgroup > col')\n const cellIndex = Array.from(element.parentElement?.children || []).indexOf(element)\n\n if (cellIndex && cellIndex > -1 && cols && cols[cellIndex]) {\n const colWidth = cols[cellIndex].getAttribute('width')\n return colWidth ? [parseInt(colWidth, 10)] : null\n }\n }\n\n return value\n },\n },\n align: createAlignAttribute(),\n }\n },\n\n tableRole: 'cell',\n\n isolating: true,\n\n parseHTML() {\n return [{ tag: 'td' }]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['td', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n})\n","import type { Attribute } from '@tiptap/core'\n\n/**\n * Supported table cell alignment values\n */\nexport enum TableCellAlign {\n Left = 'left',\n Right = 'right',\n Center = 'center',\n}\n\n/**\n * Normalize unknown input into a supported table alignment\n *\n * @param value - A potential alignment value\n * @returns A valid TableCellAlign value or null\n */\nexport function normalizeTableCellAlign(value: unknown): TableCellAlign | null {\n if (\n value === TableCellAlign.Left ||\n value === TableCellAlign.Right ||\n value === TableCellAlign.Center\n ) {\n return value\n }\n\n return null\n}\n\n/**\n * Parse table cell alignment from an HTML element\n *\n * Prefers inline style (${\"`\"}text-align${\"`\"}) and falls back to the legacy\n * ${\"`\"}align${\"`\"} attribute.\n *\n * @param element - The table cell/header DOM element\n * @returns A valid TableCellAlign value or null\n */\nexport function parseAlign(element: HTMLElement): TableCellAlign | null {\n const styleAlign = (element.style.textAlign || '').trim().toLowerCase()\n const attrAlign = (element.getAttribute('align') || '').trim().toLowerCase()\n const align = styleAlign || attrAlign\n\n return normalizeTableCellAlign(align)\n}\n\n/**\n * Normalize alignment from a generic attrs object that may include an align field\n *\n * @param attributes - A node attrs-like object with an optional align field\n * @returns A valid TableCellAlign value or null.\n */\nexport function normalizeTableCellAlignFromAttributes(\n attributes: { align?: TableCellAlign } | null | undefined,\n): TableCellAlign | null {\n return normalizeTableCellAlign(attributes?.align)\n}\n\n/**\n * Create a reusable Tiptap attribute config for table alignment\n *\n * @returns A Tiptap Attribute definition that parses and renders table alignment\n */\nexport function createAlignAttribute(): Attribute {\n return {\n default: null,\n parseHTML: (element: HTMLElement) => parseAlign(element),\n renderHTML: (attributes: { align?: TableCellAlign | null }) => {\n if (!attributes.align) {\n return {}\n }\n\n return {\n style: `text-align: ${attributes.align}`,\n }\n },\n }\n}\n"],"mappings":";AAEA,SAAS,iBAAiB,YAAY;;;ACe/B,SAAS,wBAAwB,OAAuC;AAC7E,MACE,UAAU,qBACV,UAAU,uBACV,UAAU,uBACV;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAWO,SAAS,WAAW,SAA6C;AACtE,QAAM,cAAc,QAAQ,MAAM,aAAa,IAAI,KAAK,EAAE,YAAY;AACtE,QAAM,aAAa,QAAQ,aAAa,OAAO,KAAK,IAAI,KAAK,EAAE,YAAY;AAC3E,QAAM,QAAQ,cAAc;AAE5B,SAAO,wBAAwB,KAAK;AACtC;AAmBO,SAAS,uBAAkC;AAChD,SAAO;AAAA,IACL,SAAS;AAAA,IACT,WAAW,CAAC,YAAyB,WAAW,OAAO;AAAA,IACvD,YAAY,CAAC,eAAkD;AAC7D,UAAI,CAAC,WAAW,OAAO;AACrB,eAAO,CAAC;AAAA,MACV;AAEA,aAAO;AAAA,QACL,OAAO,eAAe,WAAW,KAAK;AAAA,MACxC;AAAA,IACF;AAAA,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src/utils/parseColwidth.ts"],"sourcesContent":["import '../types.js'\n\nimport { mergeAttributes, Node } from '@tiptap/core'\n\nimport { createAlignAttribute } from '../utils/parseAlign.js'\nimport { parseColwidth } from '../utils/parseColwidth.js'\n\nexport interface TableCellOptions {\n /**\n * The HTML attributes for a table cell node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n}\n\n/**\n * This extension allows you to create table cells.\n * @see https://www.tiptap.dev/api/nodes/table-cell\n */\nexport const TableCell = Node.create<TableCellOptions>({\n name: 'tableCell',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n }\n },\n\n content: 'block+',\n\n addAttributes() {\n return {\n colspan: {\n default: 1,\n },\n rowspan: {\n default: 1,\n },\n colwidth: {\n default: null,\n parseHTML: parseColwidth,\n },\n align: createAlignAttribute(),\n }\n },\n\n tableRole: 'cell',\n\n isolating: true,\n\n parseHTML() {\n return [{ tag: 'td' }]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['td', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n})\n","import type { Attribute } from '@tiptap/core'\n\n/**\n * Supported table cell alignment values\n */\nexport enum TableCellAlign {\n Left = 'left',\n Right = 'right',\n Center = 'center',\n}\n\n/**\n * Normalize unknown input into a supported table alignment\n *\n * @param value - A potential alignment value\n * @returns A valid TableCellAlign value or null\n */\nexport function normalizeTableCellAlign(value: unknown): TableCellAlign | null {\n if (\n value === TableCellAlign.Left ||\n value === TableCellAlign.Right ||\n value === TableCellAlign.Center\n ) {\n return value\n }\n\n return null\n}\n\n/**\n * Parse table cell alignment from an HTML element\n *\n * Prefers inline style (${\"`\"}text-align${\"`\"}) and falls back to the legacy\n * ${\"`\"}align${\"`\"} attribute.\n *\n * @param element - The table cell/header DOM element\n * @returns A valid TableCellAlign value or null\n */\nexport function parseAlign(element: HTMLElement): TableCellAlign | null {\n const styleAlign = (element.style.textAlign || '').trim().toLowerCase()\n const attrAlign = (element.getAttribute('align') || '').trim().toLowerCase()\n const align = styleAlign || attrAlign\n\n return normalizeTableCellAlign(align)\n}\n\n/**\n * Normalize alignment from a generic attrs object that may include an align field\n *\n * @param attributes - A node attrs-like object with an optional align field\n * @returns A valid TableCellAlign value or null.\n */\nexport function normalizeTableCellAlignFromAttributes(\n attributes: { align?: TableCellAlign } | null | undefined,\n): TableCellAlign | null {\n return normalizeTableCellAlign(attributes?.align)\n}\n\n/**\n * Create a reusable Tiptap attribute config for table alignment\n *\n * @returns A Tiptap Attribute definition that parses and renders table alignment\n */\nexport function createAlignAttribute(): Attribute {\n return {\n default: null,\n parseHTML: (element: HTMLElement) => parseAlign(element),\n renderHTML: (attributes: { align?: TableCellAlign | null }) => {\n if (!attributes.align) {\n return {}\n }\n\n return {\n style: `text-align: ${attributes.align}`,\n }\n },\n }\n}\n","/**\n * reads the width of the `<col>` element matching a cell's column from the table's `<colgroup>`\n *\n * @param element - The table cell/header DOM element\n * @returns - An array with the column width in pixels or null\n */\nfunction parseColgroupWidth(element: HTMLElement): number[] | null {\n const row = element.parentElement\n const table = element.closest('table')\n\n if (!row || !table) {\n return null\n }\n\n const cellIndex = Array.from(row.children).indexOf(element)\n const width = table.querySelectorAll('colgroup > col')[cellIndex]?.getAttribute('width')\n\n return width ? [parseInt(width, 10)] : null\n}\n\n/**\n * Parse the column width/s of a table cell/header from an HTML element.\n * it prefers the `colwidth` attribute and if not-provided falls back to the `width` attribute\n * of the matching `<col>` element in the table's `<colgroup>`.\n *\n * @param element - The table cell/header DOM element\n * @returns - An array of column widths in pixels or null\n */\nexport function parseColwidth(element: HTMLElement): number[] | null {\n const colwidth = element.getAttribute('colwidth')\n\n if (colwidth) {\n return colwidth.split(',').map(width => parseInt(width, 10))\n }\n\n return parseColgroupWidth(element)\n}\n"],"mappings":";AAEA,SAAS,iBAAiB,YAAY;;;ACe/B,SAAS,wBAAwB,OAAuC;AAC7E,MACE,UAAU,qBACV,UAAU,uBACV,UAAU,uBACV;AACA,WAAO;AAAA,EACT;AAEA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AAO;AAAA,MACL,SAAS;AAAA,QACP,SAAS;AAAA,MACX;AAAA,MACA,SAAS;AAAA,QACP,SAAS;AAAA,MACX;AAAA,MACA,UAAU;AAAA,QACR,SAAS;AAAA,QACT,WAAW;AAAA,MACb;AAAA,MACA,OAAO,qBAAqB;AAAA,IAC9B;AAAA,EACF;AAAA,EAEA,WAAW;AAAA,EAEX,WAAW;AAAA,EAEX,YAAY;AACV,WAAO,CAAC,EAAE,KAAK,KAAK,CAAC;AAAA,EACvB;AAAA,EAEA,WAAW,EAAE,eAAe,GAAG;AAC7B,WAAO,CAAC,MAAM,gBAAgB,KAAK,QAAQ,gBAAgB,cAAc,GAAG,CAAC;AAAA,EAC/E;AACF,CAAC;","names":[]}
@@ -27,7 +27,7 @@ module.exports = __toCommonJS(index_exports);
27
27
  // src/header/table-header.ts
28
28
  var import_core = require("@tiptap/core");
29
29
 
30
- // src/utilities/parseAlign.ts
30
+ // src/utils/parseAlign.ts
31
31
  function normalizeTableCellAlign(value) {
32
32
  if (value === "left" /* Left */ || value === "right" /* Right */ || value === "center" /* Center */) {
33
33
  return value;
@@ -55,6 +55,26 @@ function createAlignAttribute() {
55
55
  };
56
56
  }
57
57
 
58
+ // src/utils/parseColwidth.ts
59
+ function parseColgroupWidth(element) {
60
+ var _a;
61
+ const row = element.parentElement;
62
+ const table = element.closest("table");
63
+ if (!row || !table) {
64
+ return null;
65
+ }
66
+ const cellIndex = Array.from(row.children).indexOf(element);
67
+ const width = (_a = table.querySelectorAll("colgroup > col")[cellIndex]) == null ? void 0 : _a.getAttribute("width");
68
+ return width ? [parseInt(width, 10)] : null;
69
+ }
70
+ function parseColwidth(element) {
71
+ const colwidth = element.getAttribute("colwidth");
72
+ if (colwidth) {
73
+ return colwidth.split(",").map((width) => parseInt(width, 10));
74
+ }
75
+ return parseColgroupWidth(element);
76
+ }
77
+
58
78
  // src/header/table-header.ts
59
79
  var TableHeader = import_core.Node.create({
60
80
  name: "tableHeader",
@@ -74,11 +94,7 @@ var TableHeader = import_core.Node.create({
74
94
  },
75
95
  colwidth: {
76
96
  default: null,
77
- parseHTML: (element) => {
78
- const colwidth = element.getAttribute("colwidth");
79
- const value = colwidth ? colwidth.split(",").map((width) => parseInt(width, 10)) : null;
80
- return value;
81
- }
97
+ parseHTML: parseColwidth
82
98
  },
83
99
  align: createAlignAttribute()
84
100
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/header/index.ts","../../src/header/table-header.ts","../../src/utilities/parseAlign.ts"],"sourcesContent":["export * from './table-header.js'\n","import '../types.js'\n\nimport { mergeAttributes, Node } from '@tiptap/core'\n\nimport { createAlignAttribute } from '../utilities/parseAlign.js'\n\nexport interface TableHeaderOptions {\n /**\n * The HTML attributes for a table header node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n}\n\n/**\n * This extension allows you to create table headers.\n * @see https://www.tiptap.dev/api/nodes/table-header\n */\nexport const TableHeader = Node.create<TableHeaderOptions>({\n name: 'tableHeader',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n }\n },\n\n content: 'block+',\n\n addAttributes() {\n return {\n colspan: {\n default: 1,\n },\n rowspan: {\n default: 1,\n },\n colwidth: {\n default: null,\n parseHTML: element => {\n const colwidth = element.getAttribute('colwidth')\n const value = colwidth ? colwidth.split(',').map(width => parseInt(width, 10)) : null\n\n return value\n },\n },\n align: createAlignAttribute(),\n }\n },\n\n tableRole: 'header_cell',\n\n isolating: true,\n\n parseHTML() {\n return [{ tag: 'th' }]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['th', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n})\n","import type { Attribute } from '@tiptap/core'\n\n/**\n * Supported table cell alignment values\n */\nexport enum TableCellAlign {\n Left = 'left',\n Right = 'right',\n Center = 'center',\n}\n\n/**\n * Normalize unknown input into a supported table alignment\n *\n * @param value - A potential alignment value\n * @returns A valid TableCellAlign value or null\n */\nexport function normalizeTableCellAlign(value: unknown): TableCellAlign | null {\n if (\n value === TableCellAlign.Left ||\n value === TableCellAlign.Right ||\n value === TableCellAlign.Center\n ) {\n return value\n }\n\n return null\n}\n\n/**\n * Parse table cell alignment from an HTML element\n *\n * Prefers inline style (${\"`\"}text-align${\"`\"}) and falls back to the legacy\n * ${\"`\"}align${\"`\"} attribute.\n *\n * @param element - The table cell/header DOM element\n * @returns A valid TableCellAlign value or null\n */\nexport function parseAlign(element: HTMLElement): TableCellAlign | null {\n const styleAlign = (element.style.textAlign || '').trim().toLowerCase()\n const attrAlign = (element.getAttribute('align') || '').trim().toLowerCase()\n const align = styleAlign || attrAlign\n\n return normalizeTableCellAlign(align)\n}\n\n/**\n * Normalize alignment from a generic attrs object that may include an align field\n *\n * @param attributes - A node attrs-like object with an optional align field\n * @returns A valid TableCellAlign value or null.\n */\nexport function normalizeTableCellAlignFromAttributes(\n attributes: { align?: TableCellAlign } | null | undefined,\n): TableCellAlign | null {\n return normalizeTableCellAlign(attributes?.align)\n}\n\n/**\n * Create a reusable Tiptap attribute config for table alignment\n *\n * @returns A Tiptap Attribute definition that parses and renders table alignment\n */\nexport function createAlignAttribute(): Attribute {\n return {\n default: null,\n parseHTML: (element: HTMLElement) => parseAlign(element),\n renderHTML: (attributes: { align?: TableCellAlign | null }) => {\n if (!attributes.align) {\n return {}\n }\n\n return {\n style: `text-align: ${attributes.align}`,\n }\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,kBAAsC;;;ACe/B,SAAS,wBAAwB,OAAuC;AAC7E,MACE,UAAU,qBACV,UAAU,uBACV,UAAU,uBACV;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAWO,SAAS,WAAW,SAA6C;AACtE,QAAM,cAAc,QAAQ,MAAM,aAAa,IAAI,KAAK,EAAE,YAAY;AACtE,QAAM,aAAa,QAAQ,aAAa,OAAO,KAAK,IAAI,KAAK,EAAE,YAAY;AAC3E,QAAM,QAAQ,cAAc;AAE5B,SAAO,wBAAwB,KAAK;AACtC;AAmBO,SAAS,uBAAkC;AAChD,SAAO;AAAA,IACL,SAAS;AAAA,IACT,WAAW,CAAC,YAAyB,WAAW,OAAO;AAAA,IACvD,YAAY,CAAC,eAAkD;AAC7D,UAAI,CAAC,WAAW,OAAO;AACrB,eAAO,CAAC;AAAA,MACV;AAEA,aAAO;AAAA,QACL,OAAO,eAAe,WAAW,KAAK;AAAA,MACxC;AAAA,IACF;AAAA,EACF;AACF;;;AD1DO,IAAM,cAAc,iBAAK,OAA2B;AAAA,EACzD,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,gBAAgB,CAAC;AAAA,IACnB;AAAA,EACF;AAAA,EAEA,SAAS;AAAA,EAET,gBAAgB;AACd,WAAO;AAAA,MACL,SAAS;AAAA,QACP,SAAS;AAAA,MACX;AAAA,MACA,SAAS;AAAA,QACP,SAAS;AAAA,MACX;AAAA,MACA,UAAU;AAAA,QACR,SAAS;AAAA,QACT,WAAW,aAAW;AACpB,gBAAM,WAAW,QAAQ,aAAa,UAAU;AAChD,gBAAM,QAAQ,WAAW,SAAS,MAAM,GAAG,EAAE,IAAI,WAAS,SAAS,OAAO,EAAE,CAAC,IAAI;AAEjF,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,MACA,OAAO,qBAAqB;AAAA,IAC9B;AAAA,EACF;AAAA,EAEA,WAAW;AAAA,EAEX,WAAW;AAAA,EAEX,YAAY;AACV,WAAO,CAAC,EAAE,KAAK,KAAK,CAAC;AAAA,EACvB;AAAA,EAEA,WAAW,EAAE,eAAe,GAAG;AAC7B,WAAO,CAAC,UAAM,6BAAgB,KAAK,QAAQ,gBAAgB,cAAc,GAAG,CAAC;AAAA,EAC/E;AACF,CAAC;","names":[]}
1
+ {"version":3,"sources":["../../src/header/index.ts","../../src/header/table-header.ts","../../src/utils/parseAlign.ts","../../src/utils/parseColwidth.ts"],"sourcesContent":["export * from './table-header.js'\n","import '../types.js'\n\nimport { mergeAttributes, Node } from '@tiptap/core'\n\nimport { createAlignAttribute } from '../utils/parseAlign.js'\nimport { parseColwidth } from '../utils/parseColwidth.js'\n\nexport interface TableHeaderOptions {\n /**\n * The HTML attributes for a table header node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n}\n\n/**\n * This extension allows you to create table headers.\n * @see https://www.tiptap.dev/api/nodes/table-header\n */\nexport const TableHeader = Node.create<TableHeaderOptions>({\n name: 'tableHeader',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n }\n },\n\n content: 'block+',\n\n addAttributes() {\n return {\n colspan: {\n default: 1,\n },\n rowspan: {\n default: 1,\n },\n colwidth: {\n default: null,\n parseHTML: parseColwidth,\n },\n align: createAlignAttribute(),\n }\n },\n\n tableRole: 'header_cell',\n\n isolating: true,\n\n parseHTML() {\n return [{ tag: 'th' }]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['th', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n})\n","import type { Attribute } from '@tiptap/core'\n\n/**\n * Supported table cell alignment values\n */\nexport enum TableCellAlign {\n Left = 'left',\n Right = 'right',\n Center = 'center',\n}\n\n/**\n * Normalize unknown input into a supported table alignment\n *\n * @param value - A potential alignment value\n * @returns A valid TableCellAlign value or null\n */\nexport function normalizeTableCellAlign(value: unknown): TableCellAlign | null {\n if (\n value === TableCellAlign.Left ||\n value === TableCellAlign.Right ||\n value === TableCellAlign.Center\n ) {\n return value\n }\n\n return null\n}\n\n/**\n * Parse table cell alignment from an HTML element\n *\n * Prefers inline style (${\"`\"}text-align${\"`\"}) and falls back to the legacy\n * ${\"`\"}align${\"`\"} attribute.\n *\n * @param element - The table cell/header DOM element\n * @returns A valid TableCellAlign value or null\n */\nexport function parseAlign(element: HTMLElement): TableCellAlign | null {\n const styleAlign = (element.style.textAlign || '').trim().toLowerCase()\n const attrAlign = (element.getAttribute('align') || '').trim().toLowerCase()\n const align = styleAlign || attrAlign\n\n return normalizeTableCellAlign(align)\n}\n\n/**\n * Normalize alignment from a generic attrs object that may include an align field\n *\n * @param attributes - A node attrs-like object with an optional align field\n * @returns A valid TableCellAlign value or null.\n */\nexport function normalizeTableCellAlignFromAttributes(\n attributes: { align?: TableCellAlign } | null | undefined,\n): TableCellAlign | null {\n return normalizeTableCellAlign(attributes?.align)\n}\n\n/**\n * Create a reusable Tiptap attribute config for table alignment\n *\n * @returns A Tiptap Attribute definition that parses and renders table alignment\n */\nexport function createAlignAttribute(): Attribute {\n return {\n default: null,\n parseHTML: (element: HTMLElement) => parseAlign(element),\n renderHTML: (attributes: { align?: TableCellAlign | null }) => {\n if (!attributes.align) {\n return {}\n }\n\n return {\n style: `text-align: ${attributes.align}`,\n }\n },\n }\n}\n","/**\n * reads the width of the `<col>` element matching a cell's column from the table's `<colgroup>`\n *\n * @param element - The table cell/header DOM element\n * @returns - An array with the column width in pixels or null\n */\nfunction parseColgroupWidth(element: HTMLElement): number[] | null {\n const row = element.parentElement\n const table = element.closest('table')\n\n if (!row || !table) {\n return null\n }\n\n const cellIndex = Array.from(row.children).indexOf(element)\n const width = table.querySelectorAll('colgroup > col')[cellIndex]?.getAttribute('width')\n\n return width ? [parseInt(width, 10)] : null\n}\n\n/**\n * Parse the column width/s of a table cell/header from an HTML element.\n * it prefers the `colwidth` attribute and if not-provided falls back to the `width` attribute\n * of the matching `<col>` element in the table's `<colgroup>`.\n *\n * @param element - The table cell/header DOM element\n * @returns - An array of column widths in pixels or null\n */\nexport function parseColwidth(element: HTMLElement): number[] | null {\n const colwidth = element.getAttribute('colwidth')\n\n if (colwidth) {\n return colwidth.split(',').map(width => parseInt(width, 10))\n }\n\n return parseColgroupWidth(element)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,kBAAsC;;;ACe/B,SAAS,wBAAwB,OAAuC;AAC7E,MACE,UAAU,qBACV,UAAU,uBACV,UAAU,uBACV;AACA,WAAO;AAAA,EACT;AAEA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WAAO;AAAA,MACL,SAAS;AAAA,QACP,SAAS;AAAA,MACX;AAAA,MACA,SAAS;AAAA,QACP,SAAS;AAAA,MACX;AAAA,MACA,UAAU;AAAA,QACR,SAAS;AAAA,QACT,WAAW;AAAA,MACb;AAAA,MACA,OAAO,qBAAqB;AAAA,IAC9B;AAAA,EACF;AAAA,EAEA,WAAW;AAAA,EAEX,WAAW;AAAA,EAEX,YAAY;AACV,WAAO,CAAC,EAAE,KAAK,KAAK,CAAC;AAAA,EACvB;AAAA,EAEA,WAAW,EAAE,eAAe,GAAG;AAC7B,WAAO,CAAC,UAAM,6BAAgB,KAAK,QAAQ,gBAAgB,cAAc,GAAG,CAAC;AAAA,EAC/E;AACF,CAAC;","names":[]}
@@ -1,7 +1,7 @@
1
1
  // src/header/table-header.ts
2
2
  import { mergeAttributes, Node } from "@tiptap/core";
3
3
 
4
- // src/utilities/parseAlign.ts
4
+ // src/utils/parseAlign.ts
5
5
  function normalizeTableCellAlign(value) {
6
6
  if (value === "left" /* Left */ || value === "right" /* Right */ || value === "center" /* Center */) {
7
7
  return value;
@@ -29,6 +29,26 @@ function createAlignAttribute() {
29
29
  };
30
30
  }
31
31
 
32
+ // src/utils/parseColwidth.ts
33
+ function parseColgroupWidth(element) {
34
+ var _a;
35
+ const row = element.parentElement;
36
+ const table = element.closest("table");
37
+ if (!row || !table) {
38
+ return null;
39
+ }
40
+ const cellIndex = Array.from(row.children).indexOf(element);
41
+ const width = (_a = table.querySelectorAll("colgroup > col")[cellIndex]) == null ? void 0 : _a.getAttribute("width");
42
+ return width ? [parseInt(width, 10)] : null;
43
+ }
44
+ function parseColwidth(element) {
45
+ const colwidth = element.getAttribute("colwidth");
46
+ if (colwidth) {
47
+ return colwidth.split(",").map((width) => parseInt(width, 10));
48
+ }
49
+ return parseColgroupWidth(element);
50
+ }
51
+
32
52
  // src/header/table-header.ts
33
53
  var TableHeader = Node.create({
34
54
  name: "tableHeader",
@@ -48,11 +68,7 @@ var TableHeader = Node.create({
48
68
  },
49
69
  colwidth: {
50
70
  default: null,
51
- parseHTML: (element) => {
52
- const colwidth = element.getAttribute("colwidth");
53
- const value = colwidth ? colwidth.split(",").map((width) => parseInt(width, 10)) : null;
54
- return value;
55
- }
71
+ parseHTML: parseColwidth
56
72
  },
57
73
  align: createAlignAttribute()
58
74
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/header/table-header.ts","../../src/utilities/parseAlign.ts"],"sourcesContent":["import '../types.js'\n\nimport { mergeAttributes, Node } from '@tiptap/core'\n\nimport { createAlignAttribute } from '../utilities/parseAlign.js'\n\nexport interface TableHeaderOptions {\n /**\n * The HTML attributes for a table header node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n}\n\n/**\n * This extension allows you to create table headers.\n * @see https://www.tiptap.dev/api/nodes/table-header\n */\nexport const TableHeader = Node.create<TableHeaderOptions>({\n name: 'tableHeader',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n }\n },\n\n content: 'block+',\n\n addAttributes() {\n return {\n colspan: {\n default: 1,\n },\n rowspan: {\n default: 1,\n },\n colwidth: {\n default: null,\n parseHTML: element => {\n const colwidth = element.getAttribute('colwidth')\n const value = colwidth ? colwidth.split(',').map(width => parseInt(width, 10)) : null\n\n return value\n },\n },\n align: createAlignAttribute(),\n }\n },\n\n tableRole: 'header_cell',\n\n isolating: true,\n\n parseHTML() {\n return [{ tag: 'th' }]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['th', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n})\n","import type { Attribute } from '@tiptap/core'\n\n/**\n * Supported table cell alignment values\n */\nexport enum TableCellAlign {\n Left = 'left',\n Right = 'right',\n Center = 'center',\n}\n\n/**\n * Normalize unknown input into a supported table alignment\n *\n * @param value - A potential alignment value\n * @returns A valid TableCellAlign value or null\n */\nexport function normalizeTableCellAlign(value: unknown): TableCellAlign | null {\n if (\n value === TableCellAlign.Left ||\n value === TableCellAlign.Right ||\n value === TableCellAlign.Center\n ) {\n return value\n }\n\n return null\n}\n\n/**\n * Parse table cell alignment from an HTML element\n *\n * Prefers inline style (${\"`\"}text-align${\"`\"}) and falls back to the legacy\n * ${\"`\"}align${\"`\"} attribute.\n *\n * @param element - The table cell/header DOM element\n * @returns A valid TableCellAlign value or null\n */\nexport function parseAlign(element: HTMLElement): TableCellAlign | null {\n const styleAlign = (element.style.textAlign || '').trim().toLowerCase()\n const attrAlign = (element.getAttribute('align') || '').trim().toLowerCase()\n const align = styleAlign || attrAlign\n\n return normalizeTableCellAlign(align)\n}\n\n/**\n * Normalize alignment from a generic attrs object that may include an align field\n *\n * @param attributes - A node attrs-like object with an optional align field\n * @returns A valid TableCellAlign value or null.\n */\nexport function normalizeTableCellAlignFromAttributes(\n attributes: { align?: TableCellAlign } | null | undefined,\n): TableCellAlign | null {\n return normalizeTableCellAlign(attributes?.align)\n}\n\n/**\n * Create a reusable Tiptap attribute config for table alignment\n *\n * @returns A Tiptap Attribute definition that parses and renders table alignment\n */\nexport function createAlignAttribute(): Attribute {\n return {\n default: null,\n parseHTML: (element: HTMLElement) => parseAlign(element),\n renderHTML: (attributes: { align?: TableCellAlign | null }) => {\n if (!attributes.align) {\n return {}\n }\n\n return {\n style: `text-align: ${attributes.align}`,\n }\n },\n }\n}\n"],"mappings":";AAEA,SAAS,iBAAiB,YAAY;;;ACe/B,SAAS,wBAAwB,OAAuC;AAC7E,MACE,UAAU,qBACV,UAAU,uBACV,UAAU,uBACV;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAWO,SAAS,WAAW,SAA6C;AACtE,QAAM,cAAc,QAAQ,MAAM,aAAa,IAAI,KAAK,EAAE,YAAY;AACtE,QAAM,aAAa,QAAQ,aAAa,OAAO,KAAK,IAAI,KAAK,EAAE,YAAY;AAC3E,QAAM,QAAQ,cAAc;AAE5B,SAAO,wBAAwB,KAAK;AACtC;AAmBO,SAAS,uBAAkC;AAChD,SAAO;AAAA,IACL,SAAS;AAAA,IACT,WAAW,CAAC,YAAyB,WAAW,OAAO;AAAA,IACvD,YAAY,CAAC,eAAkD;AAC7D,UAAI,CAAC,WAAW,OAAO;AACrB,eAAO,CAAC;AAAA,MACV;AAEA,aAAO;AAAA,QACL,OAAO,eAAe,WAAW,KAAK;AAAA,MACxC;AAAA,IACF;AAAA,EACF;AACF;;;AD1DO,IAAM,cAAc,KAAK,OAA2B;AAAA,EACzD,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,gBAAgB,CAAC;AAAA,IACnB;AAAA,EACF;AAAA,EAEA,SAAS;AAAA,EAET,gBAAgB;AACd,WAAO;AAAA,MACL,SAAS;AAAA,QACP,SAAS;AAAA,MACX;AAAA,MACA,SAAS;AAAA,QACP,SAAS;AAAA,MACX;AAAA,MACA,UAAU;AAAA,QACR,SAAS;AAAA,QACT,WAAW,aAAW;AACpB,gBAAM,WAAW,QAAQ,aAAa,UAAU;AAChD,gBAAM,QAAQ,WAAW,SAAS,MAAM,GAAG,EAAE,IAAI,WAAS,SAAS,OAAO,EAAE,CAAC,IAAI;AAEjF,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,MACA,OAAO,qBAAqB;AAAA,IAC9B;AAAA,EACF;AAAA,EAEA,WAAW;AAAA,EAEX,WAAW;AAAA,EAEX,YAAY;AACV,WAAO,CAAC,EAAE,KAAK,KAAK,CAAC;AAAA,EACvB;AAAA,EAEA,WAAW,EAAE,eAAe,GAAG;AAC7B,WAAO,CAAC,MAAM,gBAAgB,KAAK,QAAQ,gBAAgB,cAAc,GAAG,CAAC;AAAA,EAC/E;AACF,CAAC;","names":[]}
1
+ {"version":3,"sources":["../../src/header/table-header.ts","../../src/utils/parseAlign.ts","../../src/utils/parseColwidth.ts"],"sourcesContent":["import '../types.js'\n\nimport { mergeAttributes, Node } from '@tiptap/core'\n\nimport { createAlignAttribute } from '../utils/parseAlign.js'\nimport { parseColwidth } from '../utils/parseColwidth.js'\n\nexport interface TableHeaderOptions {\n /**\n * The HTML attributes for a table header node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n}\n\n/**\n * This extension allows you to create table headers.\n * @see https://www.tiptap.dev/api/nodes/table-header\n */\nexport const TableHeader = Node.create<TableHeaderOptions>({\n name: 'tableHeader',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n }\n },\n\n content: 'block+',\n\n addAttributes() {\n return {\n colspan: {\n default: 1,\n },\n rowspan: {\n default: 1,\n },\n colwidth: {\n default: null,\n parseHTML: parseColwidth,\n },\n align: createAlignAttribute(),\n }\n },\n\n tableRole: 'header_cell',\n\n isolating: true,\n\n parseHTML() {\n return [{ tag: 'th' }]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['th', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n})\n","import type { Attribute } from '@tiptap/core'\n\n/**\n * Supported table cell alignment values\n */\nexport enum TableCellAlign {\n Left = 'left',\n Right = 'right',\n Center = 'center',\n}\n\n/**\n * Normalize unknown input into a supported table alignment\n *\n * @param value - A potential alignment value\n * @returns A valid TableCellAlign value or null\n */\nexport function normalizeTableCellAlign(value: unknown): TableCellAlign | null {\n if (\n value === TableCellAlign.Left ||\n value === TableCellAlign.Right ||\n value === TableCellAlign.Center\n ) {\n return value\n }\n\n return null\n}\n\n/**\n * Parse table cell alignment from an HTML element\n *\n * Prefers inline style (${\"`\"}text-align${\"`\"}) and falls back to the legacy\n * ${\"`\"}align${\"`\"} attribute.\n *\n * @param element - The table cell/header DOM element\n * @returns A valid TableCellAlign value or null\n */\nexport function parseAlign(element: HTMLElement): TableCellAlign | null {\n const styleAlign = (element.style.textAlign || '').trim().toLowerCase()\n const attrAlign = (element.getAttribute('align') || '').trim().toLowerCase()\n const align = styleAlign || attrAlign\n\n return normalizeTableCellAlign(align)\n}\n\n/**\n * Normalize alignment from a generic attrs object that may include an align field\n *\n * @param attributes - A node attrs-like object with an optional align field\n * @returns A valid TableCellAlign value or null.\n */\nexport function normalizeTableCellAlignFromAttributes(\n attributes: { align?: TableCellAlign } | null | undefined,\n): TableCellAlign | null {\n return normalizeTableCellAlign(attributes?.align)\n}\n\n/**\n * Create a reusable Tiptap attribute config for table alignment\n *\n * @returns A Tiptap Attribute definition that parses and renders table alignment\n */\nexport function createAlignAttribute(): Attribute {\n return {\n default: null,\n parseHTML: (element: HTMLElement) => parseAlign(element),\n renderHTML: (attributes: { align?: TableCellAlign | null }) => {\n if (!attributes.align) {\n return {}\n }\n\n return {\n style: `text-align: ${attributes.align}`,\n }\n },\n }\n}\n","/**\n * reads the width of the `<col>` element matching a cell's column from the table's `<colgroup>`\n *\n * @param element - The table cell/header DOM element\n * @returns - An array with the column width in pixels or null\n */\nfunction parseColgroupWidth(element: HTMLElement): number[] | null {\n const row = element.parentElement\n const table = element.closest('table')\n\n if (!row || !table) {\n return null\n }\n\n const cellIndex = Array.from(row.children).indexOf(element)\n const width = table.querySelectorAll('colgroup > col')[cellIndex]?.getAttribute('width')\n\n return width ? [parseInt(width, 10)] : null\n}\n\n/**\n * Parse the column width/s of a table cell/header from an HTML element.\n * it prefers the `colwidth` attribute and if not-provided falls back to the `width` attribute\n * of the matching `<col>` element in the table's `<colgroup>`.\n *\n * @param element - The table cell/header DOM element\n * @returns - An array of column widths in pixels or null\n */\nexport function parseColwidth(element: HTMLElement): number[] | null {\n const colwidth = element.getAttribute('colwidth')\n\n if (colwidth) {\n return colwidth.split(',').map(width => parseInt(width, 10))\n }\n\n return parseColgroupWidth(element)\n}\n"],"mappings":";AAEA,SAAS,iBAAiB,YAAY;;;ACe/B,SAAS,wBAAwB,OAAuC;AAC7E,MACE,UAAU,qBACV,UAAU,uBACV,UAAU,uBACV;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAWO,SAAS,WAAW,SAA6C;AACtE,QAAM,cAAc,QAAQ,MAAM,aAAa,IAAI,KAAK,EAAE,YAAY;AACtE,QAAM,aAAa,QAAQ,aAAa,OAAO,KAAK,IAAI,KAAK,EAAE,YAAY;A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AAO,qBAAqB;AAAA,IAC9B;AAAA,EACF;AAAA,EAEA,WAAW;AAAA,EAEX,WAAW;AAAA,EAEX,YAAY;AACV,WAAO,CAAC,EAAE,KAAK,KAAK,CAAC;AAAA,EACvB;AAAA,EAEA,WAAW,EAAE,eAAe,GAAG;AAC7B,WAAO,CAAC,MAAM,gBAAgB,KAAK,QAAQ,gBAAgB,cAAc,GAAG,CAAC;AAAA,EAC/E;AACF,CAAC;","names":[]}
package/dist/index.cjs CHANGED
@@ -29,6 +29,8 @@ __export(index_exports, {
29
29
  TableView: () => TableView,
30
30
  createColGroup: () => createColGroup,
31
31
  createTable: () => createTable,
32
+ escapeTableCellPipes: () => escapeTableCellPipes,
33
+ preprocessTablePipes: () => preprocessTablePipes,
32
34
  renderTableToMarkdown: () => renderTableToMarkdown,
33
35
  updateColumns: () => updateColumns
34
36
  });
@@ -37,7 +39,7 @@ module.exports = __toCommonJS(index_exports);
37
39
  // src/cell/table-cell.ts
38
40
  var import_core = require("@tiptap/core");
39
41
 
40
- // src/utilities/parseAlign.ts
42
+ // src/utils/parseAlign.ts
41
43
  function normalizeTableCellAlign(value) {
42
44
  if (value === "left" /* Left */ || value === "right" /* Right */ || value === "center" /* Center */) {
43
45
  return value;
@@ -68,6 +70,26 @@ function createAlignAttribute() {
68
70
  };
69
71
  }
70
72
 
73
+ // src/utils/parseColwidth.ts
74
+ function parseColgroupWidth(element) {
75
+ var _a;
76
+ const row = element.parentElement;
77
+ const table = element.closest("table");
78
+ if (!row || !table) {
79
+ return null;
80
+ }
81
+ const cellIndex = Array.from(row.children).indexOf(element);
82
+ const width = (_a = table.querySelectorAll("colgroup > col")[cellIndex]) == null ? void 0 : _a.getAttribute("width");
83
+ return width ? [parseInt(width, 10)] : null;
84
+ }
85
+ function parseColwidth(element) {
86
+ const colwidth = element.getAttribute("colwidth");
87
+ if (colwidth) {
88
+ return colwidth.split(",").map((width) => parseInt(width, 10));
89
+ }
90
+ return parseColgroupWidth(element);
91
+ }
92
+
71
93
  // src/cell/table-cell.ts
72
94
  var TableCell = import_core.Node.create({
73
95
  name: "tableCell",
@@ -87,20 +109,7 @@ var TableCell = import_core.Node.create({
87
109
  },
88
110
  colwidth: {
89
111
  default: null,
90
- parseHTML: (element) => {
91
- var _a, _b;
92
- const colwidth = element.getAttribute("colwidth");
93
- const value = colwidth ? colwidth.split(",").map((width) => parseInt(width, 10)) : null;
94
- if (!value) {
95
- const cols = (_a = element.closest("table")) == null ? void 0 : _a.querySelectorAll("colgroup > col");
96
- const cellIndex = Array.from(((_b = element.parentElement) == null ? void 0 : _b.children) || []).indexOf(element);
97
- if (cellIndex && cellIndex > -1 && cols && cols[cellIndex]) {
98
- const colWidth = cols[cellIndex].getAttribute("width");
99
- return colWidth ? [parseInt(colWidth, 10)] : null;
100
- }
101
- }
102
- return value;
103
- }
112
+ parseHTML: parseColwidth
104
113
  },
105
114
  align: createAlignAttribute()
106
115
  };
@@ -135,11 +144,7 @@ var TableHeader = import_core2.Node.create({
135
144
  },
136
145
  colwidth: {
137
146
  default: null,
138
- parseHTML: (element) => {
139
- const colwidth = element.getAttribute("colwidth");
140
- const value = colwidth ? colwidth.split(",").map((width) => parseInt(width, 10)) : null;
141
- return value;
142
- }
147
+ parseHTML: parseColwidth
143
148
  },
144
149
  align: createAlignAttribute()
145
150
  };
@@ -391,6 +396,52 @@ var deleteTableWhenAllCellsSelected = ({ editor }) => {
391
396
 
392
397
  // src/table/utilities/markdown.ts
393
398
  var DEFAULT_CELL_LINE_SEPARATOR = "";
399
+ function escapeTableCellPipes(line) {
400
+ let result = "";
401
+ let i = 0;
402
+ while (i < line.length) {
403
+ if (line[i] === "\\" && i + 1 < line.length) {
404
+ result += line[i] + line[i + 1];
405
+ i += 2;
406
+ continue;
407
+ }
408
+ if (line[i] !== "`") {
409
+ result += line[i++];
410
+ continue;
411
+ }
412
+ let runLen = 0;
413
+ while (i + runLen < line.length && line[i + runLen] === "`") runLen += 1;
414
+ let j = i + runLen;
415
+ let found = false;
416
+ while (j < line.length) {
417
+ if (line[j] !== "`") {
418
+ j += 1;
419
+ continue;
420
+ }
421
+ let closeLen = 0;
422
+ while (j + closeLen < line.length && line[j + closeLen] === "`") closeLen += 1;
423
+ if (closeLen === runLen) {
424
+ const spanContent = line.slice(i + runLen, j);
425
+ result += line.slice(i, i + runLen) + spanContent.replace(/(?<!\\)\|/g, "\\|") + line.slice(j, j + runLen);
426
+ i = j + runLen;
427
+ found = true;
428
+ break;
429
+ }
430
+ j += closeLen;
431
+ }
432
+ if (!found) {
433
+ result += line.slice(i, i + runLen);
434
+ i += runLen;
435
+ }
436
+ }
437
+ return result;
438
+ }
439
+ function preprocessTablePipes(src) {
440
+ return src.split("\n").map((line) => {
441
+ if (!line.includes("|") || !line.includes("`")) return line;
442
+ return escapeTableCellPipes(line);
443
+ }).join("\n");
444
+ }
394
445
  function collapseWhitespace(s) {
395
446
  return (s || "").replace(/\s+/g, " ").trim();
396
447
  }
@@ -565,6 +616,33 @@ var Table = import_core5.Node.create({
565
616
  renderMarkdown: (node, h) => {
566
617
  return markdown_default(node, h);
567
618
  },
619
+ markdownTokenizer: {
620
+ name: "table",
621
+ level: "block",
622
+ start: (src) => {
623
+ const lines = src.split("\n");
624
+ if (lines.length < 2) return -1;
625
+ const sep = lines[1];
626
+ if (!/^[ \t|:]*-[ \t|:-]*$/.test(sep) || !sep.includes("|")) return -1;
627
+ return lines[0].includes("|") ? 0 : -1;
628
+ },
629
+ tokenize(src, _tokens, helper) {
630
+ const blankLineIndex = src.indexOf("\n\n");
631
+ const candidate = blankLineIndex >= 0 ? src.slice(0, blankLineIndex) : src;
632
+ const candidateLines = candidate.split("\n");
633
+ if (candidateLines.length < 2) return void 0;
634
+ const sep = candidateLines[1];
635
+ if (!/^[ \t|:]*-[ \t|:-]*$/.test(sep) || !sep.includes("|")) return void 0;
636
+ const preprocessed = preprocessTablePipes(candidate);
637
+ if (preprocessed === candidate) return void 0;
638
+ const block = helper.blockTokens(preprocessed);
639
+ const tableToken = block[0];
640
+ if ((tableToken == null ? void 0 : tableToken.type) !== "table" || !tableToken.raw) return void 0;
641
+ const lineCount = tableToken.raw.split("\n").length;
642
+ const raw = src.split("\n").slice(0, lineCount).join("\n");
643
+ return { ...tableToken, raw };
644
+ }
645
+ },
568
646
  addCommands() {
569
647
  return {
570
648
  insertTable: ({ rows = 3, cols = 3, withHeaderRow = true } = {}) => ({ tr, dispatch, editor }) => {
@@ -730,6 +808,8 @@ var TableKit = import_core6.Extension.create({
730
808
  TableView,
731
809
  createColGroup,
732
810
  createTable,
811
+ escapeTableCellPipes,
812
+ preprocessTablePipes,
733
813
  renderTableToMarkdown,
734
814
  updateColumns
735
815
  });