@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.mjs
CHANGED
|
@@ -2246,22 +2246,36 @@ var PromptContent = ({ children, isEmpty, placeholder }) => /* @__PURE__ */ jsx6
|
|
|
2246
2246
|
) });
|
|
2247
2247
|
|
|
2248
2248
|
// src/extensions/views/components/table.tsx
|
|
2249
|
+
import { useEffect, useRef, useState } from "react";
|
|
2249
2250
|
import { jsx as jsx67, jsxs as jsxs21 } from "react/jsx-runtime";
|
|
2250
2251
|
function Table({ children }) {
|
|
2252
|
+
const wrapperRef = useRef(null);
|
|
2253
|
+
const [undefinedColWidth, setUndefinedColWidth] = useState(void 0);
|
|
2251
2254
|
let colWidths = [];
|
|
2252
2255
|
if (Array.isArray(children) && children.length > 0) {
|
|
2253
2256
|
const firstRow = children[0];
|
|
2254
2257
|
if (firstRow?.props?.children) {
|
|
2255
2258
|
const cells = Array.isArray(firstRow.props.children) ? firstRow.props.children : [firstRow.props.children];
|
|
2256
|
-
colWidths = cells.map((cell) => cell?.props?.node?.attrs?.colwidth?.[0])
|
|
2259
|
+
colWidths = cells.map((cell) => cell?.props?.node?.attrs?.colwidth?.[0]);
|
|
2257
2260
|
}
|
|
2258
2261
|
}
|
|
2259
|
-
const
|
|
2260
|
-
|
|
2262
|
+
const definedWidths = colWidths.filter((w) => w !== void 0);
|
|
2263
|
+
const totalDefinedWidth = definedWidths.reduce((total, width) => total + width, 0);
|
|
2264
|
+
const undefinedCount = colWidths.filter((w) => w === void 0).length;
|
|
2265
|
+
useEffect(() => {
|
|
2266
|
+
if (wrapperRef.current && undefinedCount > 0) {
|
|
2267
|
+
const containerWidth = wrapperRef.current.clientWidth;
|
|
2268
|
+
const remainingSpace = containerWidth - totalDefinedWidth;
|
|
2269
|
+
const calculatedWidth = Math.floor(remainingSpace / undefinedCount);
|
|
2270
|
+
setUndefinedColWidth(calculatedWidth > 0 ? calculatedWidth : void 0);
|
|
2271
|
+
}
|
|
2272
|
+
}, [totalDefinedWidth, undefinedCount]);
|
|
2273
|
+
const tableWidth = undefinedCount > 0 && undefinedColWidth ? totalDefinedWidth + undefinedColWidth * undefinedCount : totalDefinedWidth > 0 ? totalDefinedWidth : void 0;
|
|
2274
|
+
return /* @__PURE__ */ jsx67("div", { ref: wrapperRef, className: "tableWrapper", children: /* @__PURE__ */ jsxs21("table", { style: tableWidth ? { width: `${tableWidth}px` } : void 0, children: [
|
|
2261
2275
|
colWidths.length > 0 && /* @__PURE__ */ jsx67("colgroup", { children: colWidths.map((width, index) => /* @__PURE__ */ jsx67(
|
|
2262
2276
|
"col",
|
|
2263
2277
|
{
|
|
2264
|
-
style: { width: `${width}px` }
|
|
2278
|
+
style: width ? { width: `${width}px` } : undefinedColWidth ? { width: `${undefinedColWidth}px` } : void 0
|
|
2265
2279
|
},
|
|
2266
2280
|
index
|
|
2267
2281
|
)) }),
|