@doist/typist 9.0.0 → 9.0.1

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [9.0.1](https://github.com/Doist/typist/compare/v9.0.0...v9.0.1) (2026-01-13)
2
+
3
+ ### Bug Fixes
4
+
5
+ - **paste-html-table-as-string:** preserve surrounding content when pasting HTML tables ([#1189](https://github.com/Doist/typist/issues/1189)) ([6588f4f](https://github.com/Doist/typist/commit/6588f4f59e0b5bc81a3b09ea195a09896a7ba951))
6
+
1
7
  ## [9.0.0](https://github.com/Doist/typist/compare/v8.0.8...v9.0.0) (2025-11-19)
2
8
 
3
9
  ### ⚠ BREAKING CHANGES
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2022-2025 Doist Inc.
3
+ Copyright (c) 2022-2026 Doist Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,4 +1,8 @@
1
1
  import { Extension } from '@tiptap/core';
2
+ /**
3
+ * Transforms pasted HTML by converting tables to paragraphs while preserving surrounding content.
4
+ */
5
+ declare function transformPastedHTML(html: string): string;
2
6
  /**
3
7
  * The `PasteHTMLTableAsString` extension adds the ability to paste a table copied from a spreadsheet
4
8
  * web app (e.g., Google Sheets, Microsoft Excel), along with tables rendered by GitHub Flavored
@@ -12,5 +16,5 @@ import { Extension } from '@tiptap/core';
12
16
  * Microsoft Excel, because unfortunately, these apps style the cell contents using CSS.
13
17
  */
14
18
  declare const PasteHTMLTableAsString: Extension<any, any>;
15
- export { PasteHTMLTableAsString };
19
+ export { PasteHTMLTableAsString, transformPastedHTML };
16
20
  //# sourceMappingURL=paste-html-table-as-string.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"paste-html-table-as-string.d.ts","sourceRoot":"","sources":["../../../src/extensions/shared/paste-html-table-as-string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAMxC;;;;;;;;;;;GAWG;AACH,QAAA,MAAM,sBAAsB,qBAwD1B,CAAA;AAEF,OAAO,EAAE,sBAAsB,EAAE,CAAA"}
1
+ {"version":3,"file":"paste-html-table-as-string.d.ts","sourceRoot":"","sources":["../../../src/extensions/shared/paste-html-table-as-string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAMxC;;GAEG;AACH,iBAAS,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAwCjD;AAED;;;;;;;;;;;GAWG;AACH,QAAA,MAAM,sBAAsB,qBAa1B,CAAA;AAEF,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,CAAA"}
@@ -2,6 +2,41 @@ import { Extension } from '@tiptap/core';
2
2
  import { Plugin, PluginKey } from '@tiptap/pm/state';
3
3
  import { PASTE_HTML_TABLE_AS_STRING_EXTENSION_PRIORITY } from '../../constants/extension-priorities';
4
4
  import { parseHtmlToElement } from '../../helpers/dom';
5
+ /**
6
+ * Transforms pasted HTML by converting tables to paragraphs while preserving surrounding content.
7
+ */
8
+ function transformPastedHTML(html) {
9
+ const body = parseHtmlToElement(html);
10
+ const tables = body.querySelectorAll('table');
11
+ if (tables.length === 0) {
12
+ return html;
13
+ }
14
+ for (const table of Array.from(tables)) {
15
+ if (!table.rows) {
16
+ continue;
17
+ }
18
+ // Convert table rows to paragraphs (using innerHTML to preserve formatting)
19
+ const paragraphs = Array.from(table.rows)
20
+ .map((row) => Array.from(row.cells)
21
+ .map((cell) => {
22
+ // Unwrap paragraphs but preserve inline formatting
23
+ const paragraphs = cell.querySelectorAll('p');
24
+ for (const p of Array.from(paragraphs)) {
25
+ p.replaceWith(...Array.from(p.childNodes));
26
+ }
27
+ return cell.innerHTML;
28
+ })
29
+ .join(' '))
30
+ .filter((row) => row.trim().length > 0)
31
+ .map((row) => {
32
+ const p = document.createElement('p');
33
+ p.innerHTML = row;
34
+ return p;
35
+ });
36
+ table.replaceWith(...paragraphs);
37
+ }
38
+ return body.innerHTML;
39
+ }
5
40
  /**
6
41
  * The `PasteHTMLTableAsString` extension adds the ability to paste a table copied from a spreadsheet
7
42
  * web app (e.g., Google Sheets, Microsoft Excel), along with tables rendered by GitHub Flavored
@@ -22,45 +57,10 @@ const PasteHTMLTableAsString = Extension.create({
22
57
  new Plugin({
23
58
  key: new PluginKey('pasteHTMLTableAsString'),
24
59
  props: {
25
- transformPastedHTML(html) {
26
- // Attempt to extract table(s) HTML from the pasted HTML
27
- const tableHTML = html.match(/<table[^>]+>[\s\S]*?<\/table>/gi);
28
- // Do not handle the event if no table HTML was found
29
- if (!tableHTML) {
30
- return html;
31
- }
32
- // Concatenate all tables into a single string of paragraphs
33
- return tableHTML.reduce((result, table) => {
34
- const { firstElementChild: tableElement } = parseHtmlToElement(table);
35
- if (!tableElement ||
36
- !(tableElement instanceof HTMLTableElement) ||
37
- !tableElement.rows) {
38
- return result;
39
- }
40
- // Transform the table element into a string of paragraphs
41
- return (result +
42
- Array.from(tableElement.rows)
43
- // Join each cell into a single string for each row
44
- .reduce((acc, row) => {
45
- return [
46
- ...acc,
47
- // Use `innerHTML` instead of `innerText` to preserve
48
- // potential formatting (e.g., GFM) within each cell
49
- Array.from(row.cells)
50
- .map((cell) => cell.innerHTML)
51
- .join(' '),
52
- ];
53
- }, [])
54
- // Discard rows that are completely empty
55
- .filter((row) => row.trim().length > 0)
56
- // Wrap each row in a paragraph
57
- .map((row) => `<p>${row}</p>`)
58
- .join(''));
59
- }, '');
60
- },
60
+ transformPastedHTML,
61
61
  },
62
62
  }),
63
63
  ];
64
64
  },
65
65
  });
66
- export { PasteHTMLTableAsString };
66
+ export { PasteHTMLTableAsString, transformPastedHTML };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@doist/typist",
3
3
  "description": "The mighty Tiptap-based rich-text editor React component that powers Doist products.",
4
- "version": "9.0.0",
4
+ "version": "9.0.1",
5
5
  "license": "MIT",
6
6
  "homepage": "https://typist.doist.dev/",
7
7
  "repository": "https://github.com/Doist/typist",
@@ -82,30 +82,30 @@
82
82
  "devDependencies": {
83
83
  "@doist/eslint-config": "12.0.0",
84
84
  "@doist/prettier-config": "4.0.1",
85
- "@doist/reactist": "29.1.0",
85
+ "@doist/reactist": "29.1.1",
86
86
  "@mdx-js/react": "3.1.1",
87
87
  "@semantic-release/changelog": "6.0.3",
88
88
  "@semantic-release/exec": "7.1.0",
89
89
  "@semantic-release/git": "10.0.1",
90
- "@storybook/addon-a11y": "8.6.14",
90
+ "@storybook/addon-a11y": "8.6.15",
91
91
  "@storybook/addon-essentials": "8.6.14",
92
92
  "@storybook/blocks": "8.6.14",
93
93
  "@storybook/csf": "0.1.13",
94
94
  "@storybook/manager-api": "8.6.14",
95
95
  "@storybook/mdx2-csf": "1.1.0",
96
- "@storybook/react": "8.6.14",
97
- "@storybook/react-vite": "8.6.14",
96
+ "@storybook/react": "8.6.15",
97
+ "@storybook/react-vite": "8.6.15",
98
98
  "@testing-library/dom": "10.4.1",
99
99
  "@testing-library/jest-dom": "6.9.1",
100
- "@testing-library/react": "16.3.0",
100
+ "@testing-library/react": "16.3.1",
101
101
  "@types/hast": "3.0.4",
102
102
  "@types/lodash-es": "4.17.12",
103
- "@types/react": "18.3.26",
103
+ "@types/react": "18.3.27",
104
104
  "@types/react-dom": "18.3.7",
105
105
  "@types/react-syntax-highlighter": "15.5.13",
106
106
  "@types/turndown": "5.0.6",
107
107
  "@types/unist": "3.0.3",
108
- "@vitejs/plugin-react": "5.1.1",
108
+ "@vitejs/plugin-react": "5.1.2",
109
109
  "boring-avatars": "2.0.4",
110
110
  "classnames": "2.5.1",
111
111
  "conventional-changelog-conventionalcommits": "9.1.0",
@@ -122,8 +122,8 @@
122
122
  "husky": "9.1.7",
123
123
  "ignore-sync": "8.0.0",
124
124
  "is-ci": "4.1.0",
125
- "jsdom": "27.2.0",
126
- "lint-staged": "16.2.6",
125
+ "jsdom": "27.4.0",
126
+ "lint-staged": "16.2.7",
127
127
  "npm-run-all-next": "1.1.1",
128
128
  "prettier": "3.6.2",
129
129
  "react": "18.3.1",
@@ -134,15 +134,15 @@
134
134
  "react-use-event-hook": "0.9.6",
135
135
  "rehype-raw": "7.0.0",
136
136
  "remark-gfm": "4.0.1",
137
- "rimraf": "6.1.0",
137
+ "rimraf": "6.1.2",
138
138
  "semantic-release": "25.0.2",
139
- "storybook": "8.6.14",
139
+ "storybook": "8.6.15",
140
140
  "storybook-css-modules": "1.0.8",
141
141
  "tippy.js": "6.3.7",
142
- "type-fest": "5.2.0",
142
+ "type-fest": "5.3.1",
143
143
  "typescript": "5.9.3",
144
144
  "typescript-plugin-css-modules": "5.2.0",
145
- "vitest": "4.0.9"
145
+ "vitest": "4.0.16"
146
146
  },
147
147
  "peerDependencies": {
148
148
  "emoji-regex": "^10.2.1",