@cyberyozh/text-editor 0.1.9 → 0.1.10
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/dist/editor.js +71 -70
- package/dist/editor.js.map +1 -1
- package/dist/editor.mjs +15 -14
- package/dist/editor.mjs.map +1 -1
- package/dist/render.js +20 -6
- package/dist/render.js.map +1 -1
- package/dist/render.mjs +18 -4
- package/dist/render.mjs.map +1 -1
- package/package.json +1 -1
- package/src/extensions/views/components/table.tsx +34 -8
package/dist/render.js
CHANGED
|
@@ -35,7 +35,7 @@ __export(render_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(render_exports);
|
|
36
36
|
|
|
37
37
|
// src/render/tiptap-render.tsx
|
|
38
|
-
var
|
|
38
|
+
var import_react3 = require("@tiptap/static-renderer/pm/react");
|
|
39
39
|
|
|
40
40
|
// src/extensions/render/get-render-extensions.ts
|
|
41
41
|
var import_extension_mathematics = require("@tiptap/extension-mathematics");
|
|
@@ -2282,22 +2282,36 @@ var PromptContent = ({ children, isEmpty, placeholder }) => /* @__PURE__ */ (0,
|
|
|
2282
2282
|
) });
|
|
2283
2283
|
|
|
2284
2284
|
// src/extensions/views/components/table.tsx
|
|
2285
|
+
var import_react2 = require("react");
|
|
2285
2286
|
var import_jsx_runtime67 = require("react/jsx-runtime");
|
|
2286
2287
|
function Table({ children }) {
|
|
2288
|
+
const wrapperRef = (0, import_react2.useRef)(null);
|
|
2289
|
+
const [undefinedColWidth, setUndefinedColWidth] = (0, import_react2.useState)(void 0);
|
|
2287
2290
|
let colWidths = [];
|
|
2288
2291
|
if (Array.isArray(children) && children.length > 0) {
|
|
2289
2292
|
const firstRow = children[0];
|
|
2290
2293
|
if (firstRow?.props?.children) {
|
|
2291
2294
|
const cells = Array.isArray(firstRow.props.children) ? firstRow.props.children : [firstRow.props.children];
|
|
2292
|
-
colWidths = cells.map((cell) => cell?.props?.node?.attrs?.colwidth?.[0])
|
|
2295
|
+
colWidths = cells.map((cell) => cell?.props?.node?.attrs?.colwidth?.[0]);
|
|
2293
2296
|
}
|
|
2294
2297
|
}
|
|
2295
|
-
const
|
|
2296
|
-
|
|
2298
|
+
const definedWidths = colWidths.filter((w) => w !== void 0);
|
|
2299
|
+
const totalDefinedWidth = definedWidths.reduce((total, width) => total + width, 0);
|
|
2300
|
+
const undefinedCount = colWidths.filter((w) => w === void 0).length;
|
|
2301
|
+
(0, import_react2.useEffect)(() => {
|
|
2302
|
+
if (wrapperRef.current && undefinedCount > 0) {
|
|
2303
|
+
const containerWidth = wrapperRef.current.clientWidth;
|
|
2304
|
+
const remainingSpace = containerWidth - totalDefinedWidth;
|
|
2305
|
+
const calculatedWidth = Math.floor(remainingSpace / undefinedCount);
|
|
2306
|
+
setUndefinedColWidth(calculatedWidth > 0 ? calculatedWidth : void 0);
|
|
2307
|
+
}
|
|
2308
|
+
}, [totalDefinedWidth, undefinedCount]);
|
|
2309
|
+
const tableWidth = undefinedCount > 0 && undefinedColWidth ? totalDefinedWidth + undefinedColWidth * undefinedCount : totalDefinedWidth > 0 ? totalDefinedWidth : void 0;
|
|
2310
|
+
return /* @__PURE__ */ (0, import_jsx_runtime67.jsx)("div", { ref: wrapperRef, className: "tableWrapper", children: /* @__PURE__ */ (0, import_jsx_runtime67.jsxs)("table", { style: tableWidth ? { width: `${tableWidth}px` } : void 0, children: [
|
|
2297
2311
|
colWidths.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime67.jsx)("colgroup", { children: colWidths.map((width, index) => /* @__PURE__ */ (0, import_jsx_runtime67.jsx)(
|
|
2298
2312
|
"col",
|
|
2299
2313
|
{
|
|
2300
|
-
style: { width: `${width}px` }
|
|
2314
|
+
style: width ? { width: `${width}px` } : undefinedColWidth ? { width: `${undefinedColWidth}px` } : void 0
|
|
2301
2315
|
},
|
|
2302
2316
|
index
|
|
2303
2317
|
)) }),
|
|
@@ -2592,7 +2606,7 @@ function renderTiptapToReact(content, getImageById) {
|
|
|
2592
2606
|
console.warn("Failed to parse Tiptap content:", error);
|
|
2593
2607
|
parsedContent = { type: "doc", content: [{ type: "paragraph" }] };
|
|
2594
2608
|
}
|
|
2595
|
-
const rendered = (0,
|
|
2609
|
+
const rendered = (0, import_react3.renderToReactElement)({
|
|
2596
2610
|
extensions: getRenderExtensions(),
|
|
2597
2611
|
content: parsedContent,
|
|
2598
2612
|
options: {
|