@cyberyozh/text-editor 0.1.9 → 0.1.11

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/render.mjs CHANGED
@@ -2246,27 +2246,48 @@ 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]).filter((width) => width !== void 0);
2259
+ colWidths = cells.map((cell) => cell?.props?.node?.attrs?.colwidth?.[0]);
2257
2260
  }
2258
2261
  }
2259
- const tableWidth = colWidths.length > 0 ? colWidths.reduce((total, width) => total + width, 0) : null;
2260
- return /* @__PURE__ */ jsx67("div", { className: "tableWrapper", children: /* @__PURE__ */ jsxs21("table", { style: tableWidth ? { width: `${tableWidth}px` } : void 0, children: [
2261
- colWidths.length > 0 && /* @__PURE__ */ jsx67("colgroup", { children: colWidths.map((width, index) => /* @__PURE__ */ jsx67(
2262
- "col",
2263
- {
2264
- style: { width: `${width}px` }
2265
- },
2266
- index
2267
- )) }),
2268
- /* @__PURE__ */ jsx67("tbody", { children })
2269
- ] }) });
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 - 2;
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 + 2 : totalDefinedWidth > 0 ? totalDefinedWidth + 2 : void 0;
2274
+ return /* @__PURE__ */ jsx67(
2275
+ "div",
2276
+ {
2277
+ ref: wrapperRef,
2278
+ className: "tableWrapper",
2279
+ children: /* @__PURE__ */ jsxs21("table", { style: tableWidth ? { width: `${tableWidth}px` } : void 0, children: [
2280
+ colWidths.length > 0 && /* @__PURE__ */ jsx67("colgroup", { children: colWidths.map((width, index) => /* @__PURE__ */ jsx67(
2281
+ "col",
2282
+ {
2283
+ style: width ? { width: `${width}px` } : undefinedColWidth ? { width: `${undefinedColWidth}px` } : void 0
2284
+ },
2285
+ index
2286
+ )) }),
2287
+ /* @__PURE__ */ jsx67("tbody", { children })
2288
+ ] })
2289
+ }
2290
+ );
2270
2291
  }
2271
2292
 
2272
2293
  // src/utils/detect-video-hosting.ts