@tiptap/extension-table 3.21.0 → 3.22.0

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.
@@ -26,6 +26,36 @@ module.exports = __toCommonJS(index_exports);
26
26
 
27
27
  // src/cell/table-cell.ts
28
28
  var import_core = require("@tiptap/core");
29
+
30
+ // src/utilities/parseAlign.ts
31
+ function normalizeTableCellAlign(value) {
32
+ if (value === "left" /* Left */ || value === "right" /* Right */ || value === "center" /* Center */) {
33
+ return value;
34
+ }
35
+ return null;
36
+ }
37
+ function parseAlign(element) {
38
+ const styleAlign = (element.style.textAlign || "").trim().toLowerCase();
39
+ const attrAlign = (element.getAttribute("align") || "").trim().toLowerCase();
40
+ const align = styleAlign || attrAlign;
41
+ return normalizeTableCellAlign(align);
42
+ }
43
+ function createAlignAttribute() {
44
+ return {
45
+ default: null,
46
+ parseHTML: (element) => parseAlign(element),
47
+ renderHTML: (attributes) => {
48
+ if (!attributes.align) {
49
+ return {};
50
+ }
51
+ return {
52
+ style: `text-align: ${attributes.align}`
53
+ };
54
+ }
55
+ };
56
+ }
57
+
58
+ // src/cell/table-cell.ts
29
59
  var TableCell = import_core.Node.create({
30
60
  name: "tableCell",
31
61
  addOptions() {
@@ -58,7 +88,8 @@ var TableCell = import_core.Node.create({
58
88
  }
59
89
  return value;
60
90
  }
61
- }
91
+ },
92
+ align: createAlignAttribute()
62
93
  };
63
94
  },
64
95
  tableRole: "cell",
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cell/index.ts","../../src/cell/table-cell.ts"],"sourcesContent":["export * from './table-cell.js'\n","import '../types.js'\n\nimport { mergeAttributes, Node } from '@tiptap/core'\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 }\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,kBAAsC;AAe/B,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,aAAW;AAtC9B;AAuCU,gBAAM,WAAW,QAAQ,aAAa,UAAU;AAChD,gBAAM,QAAQ,WAAW,SAAS,MAAM,GAAG,EAAE,IAAI,WAAS,SAAS,OAAO,EAAE,CAAC,IAAI;AAGjF,cAAI,CAAC,OAAO;AACV,kBAAM,QAAO,aAAQ,QAAQ,OAAO,MAAvB,mBAA0B,iBAAiB;AACxD,kBAAM,YAAY,MAAM,OAAK,aAAQ,kBAAR,mBAAuB,aAAY,CAAC,CAAC,EAAE,QAAQ,OAAO;AAEnF,gBAAI,aAAa,YAAY,MAAM,QAAQ,KAAK,SAAS,GAAG;AAC1D,oBAAM,WAAW,KAAK,SAAS,EAAE,aAAa,OAAO;AACrD,qBAAO,WAAW,CAAC,SAAS,UAAU,EAAE,CAAC,IAAI;AAAA,YAC/C;AAAA,UACF;AAEA,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,IACF;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/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 (value === TableCellAlign.Left || value === TableCellAlign.Right || value === TableCellAlign.Center) {\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,MAAI,UAAU,qBAAuB,UAAU,uBAAwB,UAAU,uBAAuB;AACtG,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;;;ADtDO,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,aAAW;AAxC9B;AAyCU,gBAAM,WAAW,QAAQ,aAAa,UAAU;AAChD,gBAAM,QAAQ,WAAW,SAAS,MAAM,GAAG,EAAE,IAAI,WAAS,SAAS,OAAO,EAAE,CAAC,IAAI;AAGjF,cAAI,CAAC,OAAO;AACV,kBAAM,QAAO,aAAQ,QAAQ,OAAO,MAAvB,mBAA0B,iBAAiB;AACxD,kBAAM,YAAY,MAAM,OAAK,aAAQ,kBAAR,mBAAuB,aAAY,CAAC,CAAC,EAAE,QAAQ,OAAO;AAEnF,gBAAI,aAAa,YAAY,MAAM,QAAQ,KAAK,SAAS,GAAG;AAC1D,oBAAM,WAAW,KAAK,SAAS,EAAE,aAAa,OAAO;AACrD,qBAAO,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,5 +1,35 @@
1
1
  // src/cell/table-cell.ts
2
2
  import { mergeAttributes, Node } from "@tiptap/core";
3
+
4
+ // src/utilities/parseAlign.ts
5
+ function normalizeTableCellAlign(value) {
6
+ if (value === "left" /* Left */ || value === "right" /* Right */ || value === "center" /* Center */) {
7
+ return value;
8
+ }
9
+ return null;
10
+ }
11
+ function parseAlign(element) {
12
+ const styleAlign = (element.style.textAlign || "").trim().toLowerCase();
13
+ const attrAlign = (element.getAttribute("align") || "").trim().toLowerCase();
14
+ const align = styleAlign || attrAlign;
15
+ return normalizeTableCellAlign(align);
16
+ }
17
+ function createAlignAttribute() {
18
+ return {
19
+ default: null,
20
+ parseHTML: (element) => parseAlign(element),
21
+ renderHTML: (attributes) => {
22
+ if (!attributes.align) {
23
+ return {};
24
+ }
25
+ return {
26
+ style: `text-align: ${attributes.align}`
27
+ };
28
+ }
29
+ };
30
+ }
31
+
32
+ // src/cell/table-cell.ts
3
33
  var TableCell = Node.create({
4
34
  name: "tableCell",
5
35
  addOptions() {
@@ -32,7 +62,8 @@ var TableCell = Node.create({
32
62
  }
33
63
  return value;
34
64
  }
35
- }
65
+ },
66
+ align: createAlignAttribute()
36
67
  };
37
68
  },
38
69
  tableRole: "cell",
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cell/table-cell.ts"],"sourcesContent":["import '../types.js'\n\nimport { mergeAttributes, Node } from '@tiptap/core'\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 }\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"],"mappings":";AAEA,SAAS,iBAAiB,YAAY;AAe/B,IAAM,YAAY,KAAK,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,aAAW;AAtC9B;AAuCU,gBAAM,WAAW,QAAQ,aAAa,UAAU;AAChD,gBAAM,QAAQ,WAAW,SAAS,MAAM,GAAG,EAAE,IAAI,WAAS,SAAS,OAAO,EAAE,CAAC,IAAI;AAGjF,cAAI,CAAC,OAAO;AACV,kBAAM,QAAO,aAAQ,QAAQ,OAAO,MAAvB,mBAA0B,iBAAiB;AACxD,kBAAM,YAAY,MAAM,OAAK,aAAQ,kBAAR,mBAAuB,aAAY,CAAC,CAAC,EAAE,QAAQ,OAAO;AAEnF,gBAAI,aAAa,YAAY,MAAM,QAAQ,KAAK,SAAS,GAAG;AAC1D,oBAAM,WAAW,KAAK,SAAS,EAAE,aAAa,OAAO;AACrD,qBAAO,WAAW,CAAC,SAAS,UAAU,EAAE,CAAC,IAAI;AAAA,YAC/C;AAAA,UACF;AAEA,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,IACF;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/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 (value === TableCellAlign.Left || value === TableCellAlign.Right || value === TableCellAlign.Center) {\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,MAAI,UAAU,qBAAuB,UAAU,uBAAwB,UAAU,uBAAuB;AACtG,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;;;ADtDO,IAAM,YAAY,KAAK,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,aAAW;AAxC9B;AAyCU,gBAAM,WAAW,QAAQ,aAAa,UAAU;AAChD,gBAAM,QAAQ,WAAW,SAAS,MAAM,GAAG,EAAE,IAAI,WAAS,SAAS,OAAO,EAAE,CAAC,IAAI;AAGjF,cAAI,CAAC,OAAO;AACV,kBAAM,QAAO,aAAQ,QAAQ,OAAO,MAAvB,mBAA0B,iBAAiB;AACxD,kBAAM,YAAY,MAAM,OAAK,aAAQ,kBAAR,mBAAuB,aAAY,CAAC,CAAC,EAAE,QAAQ,OAAO;AAEnF,gBAAI,aAAa,YAAY,MAAM,QAAQ,KAAK,SAAS,GAAG;AAC1D,oBAAM,WAAW,KAAK,SAAS,EAAE,aAAa,OAAO;AACrD,qBAAO,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,MAAM,gBAAgB,KAAK,QAAQ,gBAAgB,cAAc,GAAG,CAAC;AAAA,EAC/E;AACF,CAAC;","names":[]}
@@ -26,6 +26,36 @@ module.exports = __toCommonJS(index_exports);
26
26
 
27
27
  // src/header/table-header.ts
28
28
  var import_core = require("@tiptap/core");
29
+
30
+ // src/utilities/parseAlign.ts
31
+ function normalizeTableCellAlign(value) {
32
+ if (value === "left" /* Left */ || value === "right" /* Right */ || value === "center" /* Center */) {
33
+ return value;
34
+ }
35
+ return null;
36
+ }
37
+ function parseAlign(element) {
38
+ const styleAlign = (element.style.textAlign || "").trim().toLowerCase();
39
+ const attrAlign = (element.getAttribute("align") || "").trim().toLowerCase();
40
+ const align = styleAlign || attrAlign;
41
+ return normalizeTableCellAlign(align);
42
+ }
43
+ function createAlignAttribute() {
44
+ return {
45
+ default: null,
46
+ parseHTML: (element) => parseAlign(element),
47
+ renderHTML: (attributes) => {
48
+ if (!attributes.align) {
49
+ return {};
50
+ }
51
+ return {
52
+ style: `text-align: ${attributes.align}`
53
+ };
54
+ }
55
+ };
56
+ }
57
+
58
+ // src/header/table-header.ts
29
59
  var TableHeader = import_core.Node.create({
30
60
  name: "tableHeader",
31
61
  addOptions() {
@@ -49,7 +79,8 @@ var TableHeader = import_core.Node.create({
49
79
  const value = colwidth ? colwidth.split(",").map((width) => parseInt(width, 10)) : null;
50
80
  return value;
51
81
  }
52
- }
82
+ },
83
+ align: createAlignAttribute()
53
84
  };
54
85
  },
55
86
  tableRole: "header_cell",
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/header/index.ts","../../src/header/table-header.ts"],"sourcesContent":["export * from './table-header.js'\n","import '../types.js'\n\nimport { mergeAttributes, Node } from '@tiptap/core'\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 }\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,kBAAsC;AAe/B,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,IACF;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/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 (value === TableCellAlign.Left || value === TableCellAlign.Right || value === TableCellAlign.Center) {\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,MAAI,UAAU,qBAAuB,UAAU,uBAAwB,UAAU,uBAAuB;AACtG,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;;;ADtDO,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,5 +1,35 @@
1
1
  // src/header/table-header.ts
2
2
  import { mergeAttributes, Node } from "@tiptap/core";
3
+
4
+ // src/utilities/parseAlign.ts
5
+ function normalizeTableCellAlign(value) {
6
+ if (value === "left" /* Left */ || value === "right" /* Right */ || value === "center" /* Center */) {
7
+ return value;
8
+ }
9
+ return null;
10
+ }
11
+ function parseAlign(element) {
12
+ const styleAlign = (element.style.textAlign || "").trim().toLowerCase();
13
+ const attrAlign = (element.getAttribute("align") || "").trim().toLowerCase();
14
+ const align = styleAlign || attrAlign;
15
+ return normalizeTableCellAlign(align);
16
+ }
17
+ function createAlignAttribute() {
18
+ return {
19
+ default: null,
20
+ parseHTML: (element) => parseAlign(element),
21
+ renderHTML: (attributes) => {
22
+ if (!attributes.align) {
23
+ return {};
24
+ }
25
+ return {
26
+ style: `text-align: ${attributes.align}`
27
+ };
28
+ }
29
+ };
30
+ }
31
+
32
+ // src/header/table-header.ts
3
33
  var TableHeader = Node.create({
4
34
  name: "tableHeader",
5
35
  addOptions() {
@@ -23,7 +53,8 @@ var TableHeader = Node.create({
23
53
  const value = colwidth ? colwidth.split(",").map((width) => parseInt(width, 10)) : null;
24
54
  return value;
25
55
  }
26
- }
56
+ },
57
+ align: createAlignAttribute()
27
58
  };
28
59
  },
29
60
  tableRole: "header_cell",
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/header/table-header.ts"],"sourcesContent":["import '../types.js'\n\nimport { mergeAttributes, Node } from '@tiptap/core'\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 }\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"],"mappings":";AAEA,SAAS,iBAAiB,YAAY;AAe/B,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,IACF;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/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 (value === TableCellAlign.Left || value === TableCellAlign.Right || value === TableCellAlign.Center) {\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,MAAI,UAAU,qBAAuB,UAAU,uBAAwB,UAAU,uBAAuB;AACtG,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;;;ADtDO,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":[]}
package/dist/index.cjs CHANGED
@@ -36,6 +36,39 @@ module.exports = __toCommonJS(index_exports);
36
36
 
37
37
  // src/cell/table-cell.ts
38
38
  var import_core = require("@tiptap/core");
39
+
40
+ // src/utilities/parseAlign.ts
41
+ function normalizeTableCellAlign(value) {
42
+ if (value === "left" /* Left */ || value === "right" /* Right */ || value === "center" /* Center */) {
43
+ return value;
44
+ }
45
+ return null;
46
+ }
47
+ function parseAlign(element) {
48
+ const styleAlign = (element.style.textAlign || "").trim().toLowerCase();
49
+ const attrAlign = (element.getAttribute("align") || "").trim().toLowerCase();
50
+ const align = styleAlign || attrAlign;
51
+ return normalizeTableCellAlign(align);
52
+ }
53
+ function normalizeTableCellAlignFromAttributes(attributes) {
54
+ return normalizeTableCellAlign(attributes == null ? void 0 : attributes.align);
55
+ }
56
+ function createAlignAttribute() {
57
+ return {
58
+ default: null,
59
+ parseHTML: (element) => parseAlign(element),
60
+ renderHTML: (attributes) => {
61
+ if (!attributes.align) {
62
+ return {};
63
+ }
64
+ return {
65
+ style: `text-align: ${attributes.align}`
66
+ };
67
+ }
68
+ };
69
+ }
70
+
71
+ // src/cell/table-cell.ts
39
72
  var TableCell = import_core.Node.create({
40
73
  name: "tableCell",
41
74
  addOptions() {
@@ -68,7 +101,8 @@ var TableCell = import_core.Node.create({
68
101
  }
69
102
  return value;
70
103
  }
71
- }
104
+ },
105
+ align: createAlignAttribute()
72
106
  };
73
107
  },
74
108
  tableRole: "cell",
@@ -106,7 +140,8 @@ var TableHeader = import_core2.Node.create({
106
140
  const value = colwidth ? colwidth.split(",").map((width) => parseInt(width, 10)) : null;
107
141
  return value;
108
142
  }
109
- }
143
+ },
144
+ align: createAlignAttribute()
110
145
  };
111
146
  },
112
147
  tableRole: "header_cell",
@@ -370,7 +405,8 @@ function renderTableToMarkdown(node, h, options = {}) {
370
405
  }
371
406
  const text = collapseWhitespace(raw);
372
407
  const isHeader = cellNode.type === "tableHeader";
373
- cells.push({ text, isHeader });
408
+ const align = normalizeTableCellAlignFromAttributes(cellNode.attrs);
409
+ cells.push({ text, isHeader, align });
374
410
  });
375
411
  }
376
412
  rows.push(cells);
@@ -396,11 +432,33 @@ function renderTableToMarkdown(node, h, options = {}) {
396
432
  const pad = (s, width) => s + " ".repeat(Math.max(0, width - s.length));
397
433
  const headerRow = rows[0];
398
434
  const hasHeader = headerRow.some((c) => c.isHeader);
435
+ const colAlignments = new Array(columnCount).fill(null);
436
+ rows.forEach((r) => {
437
+ var _a2;
438
+ for (let i = 0; i < columnCount; i += 1) {
439
+ if (!colAlignments[i] && ((_a2 = r[i]) == null ? void 0 : _a2.align)) {
440
+ colAlignments[i] = r[i].align;
441
+ }
442
+ }
443
+ });
399
444
  let out = "\n";
400
445
  const headerTexts = new Array(columnCount).fill(0).map((_, i) => hasHeader ? headerRow[i] && headerRow[i].text || "" : "");
401
446
  out += `| ${headerTexts.map((t, i) => pad(t, colWidths[i])).join(" | ")} |
402
447
  `;
403
- out += `| ${colWidths.map((w) => "-".repeat(Math.max(3, w))).join(" | ")} |
448
+ out += `| ${colWidths.map((w, index) => {
449
+ const dashCount = Math.max(3, w);
450
+ const alignment = colAlignments[index];
451
+ if (alignment === "left" /* Left */) {
452
+ return `:${"-".repeat(dashCount)}`;
453
+ }
454
+ if (alignment === "right" /* Right */) {
455
+ return `${"-".repeat(dashCount)}:`;
456
+ }
457
+ if (alignment === "center" /* Center */) {
458
+ return `:${"-".repeat(dashCount)}:`;
459
+ }
460
+ return "-".repeat(dashCount);
461
+ }).join(" | ")} |
404
462
  `;
405
463
  const body = hasHeader ? rows.slice(1) : rows;
406
464
  body.forEach((r) => {
@@ -456,18 +514,27 @@ var Table = import_core5.Node.create({
456
514
  },
457
515
  parseMarkdown: (token, h) => {
458
516
  const rows = [];
517
+ const alignments = Array.isArray(token.align) ? token.align : [];
459
518
  if (token.header) {
460
519
  const headerCells = [];
461
- token.header.forEach((cell) => {
462
- headerCells.push(h.createNode("tableHeader", {}, [{ type: "paragraph", content: h.parseInline(cell.tokens) }]));
520
+ token.header.forEach((cell, index) => {
521
+ var _a;
522
+ const align = normalizeTableCellAlign((_a = alignments[index]) != null ? _a : cell.align);
523
+ const attrs = align ? { align } : {};
524
+ headerCells.push(
525
+ h.createNode("tableHeader", attrs, [{ type: "paragraph", content: h.parseInline(cell.tokens) }])
526
+ );
463
527
  });
464
528
  rows.push(h.createNode("tableRow", {}, headerCells));
465
529
  }
466
530
  if (token.rows) {
467
531
  token.rows.forEach((row) => {
468
532
  const bodyCells = [];
469
- row.forEach((cell) => {
470
- bodyCells.push(h.createNode("tableCell", {}, [{ type: "paragraph", content: h.parseInline(cell.tokens) }]));
533
+ row.forEach((cell, index) => {
534
+ var _a;
535
+ const align = normalizeTableCellAlign((_a = alignments[index]) != null ? _a : cell.align);
536
+ const attrs = align ? { align } : {};
537
+ bodyCells.push(h.createNode("tableCell", attrs, [{ type: "paragraph", content: h.parseInline(cell.tokens) }]));
471
538
  });
472
539
  rows.push(h.createNode("tableRow", {}, bodyCells));
473
540
  });