@cyberyozh/text-editor 0.1.8 → 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.css +12 -2
- package/dist/editor.css.map +1 -1
- package/dist/editor.d.mts +1 -0
- package/dist/editor.d.ts +1 -0
- package/dist/editor.js +231 -131
- package/dist/editor.js.map +1 -1
- package/dist/editor.mjs +175 -75
- package/dist/editor.mjs.map +1 -1
- package/dist/render.js +79 -6
- package/dist/render.js.map +1 -1
- package/dist/render.mjs +77 -4
- package/dist/render.mjs.map +1 -1
- package/dist/styles/index.css +12 -2
- package/package.json +2 -2
- package/src/editor/controls/bubble-menu-content.tsx +4 -8
- package/src/editor/controls/callout-menu.tsx +2 -0
- package/src/editor/controls/drag-handle.tsx +6 -1
- package/src/editor/dialogs/add-link-dialog/add-link-dialog.css +12 -4
- package/src/editor/dialogs/add-link-dialog/add-link-dialog.tsx +65 -28
- package/src/editor/dialogs/image-dialog/image-dialog.tsx +1 -0
- package/src/editor/editor.tsx +6 -10
- package/src/editor/handlers/dialog-handlers.ts +33 -32
- package/src/extensions/base/compatibility.ts +52 -0
- package/src/extensions/base/figure.ts +7 -0
- package/src/extensions/base/link.ts +3 -3
- package/src/extensions/views/components/table.tsx +34 -8
- package/src/extensions/views/node-views/figure.tsx +1 -1
- package/src/styles/editor/base.css +1 -1
- package/src/styles/extensions/callout.css +1 -1
- package/src/translations/en.json +5 -1
- package/src/translations/ru.json +5 -1
- package/src/types/image-handler.ts +2 -0
- package/src/types/link.ts +9 -0
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");
|
|
@@ -687,6 +687,13 @@ var BaseFigure = import_extension_image.default.extend({
|
|
|
687
687
|
caption: {
|
|
688
688
|
default: null,
|
|
689
689
|
parseHTML: (element) => element.querySelector("figcaption")?.textContent || null
|
|
690
|
+
},
|
|
691
|
+
storageKey: {
|
|
692
|
+
default: null,
|
|
693
|
+
parseHTML: (element) => element.getAttribute("data-storage-key"),
|
|
694
|
+
renderHTML: (attributes) => ({
|
|
695
|
+
"data-storage-key": attributes.storageKey
|
|
696
|
+
})
|
|
690
697
|
}
|
|
691
698
|
};
|
|
692
699
|
},
|
|
@@ -1128,6 +1135,32 @@ var BaseLegacyBookAlert = import_core15.Node.create({
|
|
|
1128
1135
|
return {
|
|
1129
1136
|
type: {
|
|
1130
1137
|
default: "error"
|
|
1138
|
+
},
|
|
1139
|
+
bgColor: {
|
|
1140
|
+
default: null,
|
|
1141
|
+
parseHTML: (element) => {
|
|
1142
|
+
if (typeof element === "string") return null;
|
|
1143
|
+
return element.getAttribute("data-bg-color");
|
|
1144
|
+
},
|
|
1145
|
+
renderHTML: (attributes) => {
|
|
1146
|
+
if (!attributes.bgColor) return {};
|
|
1147
|
+
return {
|
|
1148
|
+
"data-bg-color": attributes.bgColor
|
|
1149
|
+
};
|
|
1150
|
+
}
|
|
1151
|
+
},
|
|
1152
|
+
emoji: {
|
|
1153
|
+
default: null,
|
|
1154
|
+
parseHTML: (element) => {
|
|
1155
|
+
if (typeof element === "string") return null;
|
|
1156
|
+
return element.getAttribute("data-emoji");
|
|
1157
|
+
},
|
|
1158
|
+
renderHTML: (attributes) => {
|
|
1159
|
+
if (!attributes.emoji) return {};
|
|
1160
|
+
return {
|
|
1161
|
+
"data-emoji": attributes.emoji
|
|
1162
|
+
};
|
|
1163
|
+
}
|
|
1131
1164
|
}
|
|
1132
1165
|
};
|
|
1133
1166
|
},
|
|
@@ -1157,6 +1190,32 @@ var BaseLegacyBookTip = import_core15.Node.create({
|
|
|
1157
1190
|
return {
|
|
1158
1191
|
type: {
|
|
1159
1192
|
default: "info"
|
|
1193
|
+
},
|
|
1194
|
+
bgColor: {
|
|
1195
|
+
default: null,
|
|
1196
|
+
parseHTML: (element) => {
|
|
1197
|
+
if (typeof element === "string") return null;
|
|
1198
|
+
return element.getAttribute("data-bg-color");
|
|
1199
|
+
},
|
|
1200
|
+
renderHTML: (attributes) => {
|
|
1201
|
+
if (!attributes.bgColor) return {};
|
|
1202
|
+
return {
|
|
1203
|
+
"data-bg-color": attributes.bgColor
|
|
1204
|
+
};
|
|
1205
|
+
}
|
|
1206
|
+
},
|
|
1207
|
+
emoji: {
|
|
1208
|
+
default: null,
|
|
1209
|
+
parseHTML: (element) => {
|
|
1210
|
+
if (typeof element === "string") return null;
|
|
1211
|
+
return element.getAttribute("data-emoji");
|
|
1212
|
+
},
|
|
1213
|
+
renderHTML: (attributes) => {
|
|
1214
|
+
if (!attributes.emoji) return {};
|
|
1215
|
+
return {
|
|
1216
|
+
"data-emoji": attributes.emoji
|
|
1217
|
+
};
|
|
1218
|
+
}
|
|
1160
1219
|
}
|
|
1161
1220
|
};
|
|
1162
1221
|
},
|
|
@@ -2223,22 +2282,36 @@ var PromptContent = ({ children, isEmpty, placeholder }) => /* @__PURE__ */ (0,
|
|
|
2223
2282
|
) });
|
|
2224
2283
|
|
|
2225
2284
|
// src/extensions/views/components/table.tsx
|
|
2285
|
+
var import_react2 = require("react");
|
|
2226
2286
|
var import_jsx_runtime67 = require("react/jsx-runtime");
|
|
2227
2287
|
function Table({ children }) {
|
|
2288
|
+
const wrapperRef = (0, import_react2.useRef)(null);
|
|
2289
|
+
const [undefinedColWidth, setUndefinedColWidth] = (0, import_react2.useState)(void 0);
|
|
2228
2290
|
let colWidths = [];
|
|
2229
2291
|
if (Array.isArray(children) && children.length > 0) {
|
|
2230
2292
|
const firstRow = children[0];
|
|
2231
2293
|
if (firstRow?.props?.children) {
|
|
2232
2294
|
const cells = Array.isArray(firstRow.props.children) ? firstRow.props.children : [firstRow.props.children];
|
|
2233
|
-
colWidths = cells.map((cell) => cell?.props?.node?.attrs?.colwidth?.[0])
|
|
2295
|
+
colWidths = cells.map((cell) => cell?.props?.node?.attrs?.colwidth?.[0]);
|
|
2234
2296
|
}
|
|
2235
2297
|
}
|
|
2236
|
-
const
|
|
2237
|
-
|
|
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: [
|
|
2238
2311
|
colWidths.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime67.jsx)("colgroup", { children: colWidths.map((width, index) => /* @__PURE__ */ (0, import_jsx_runtime67.jsx)(
|
|
2239
2312
|
"col",
|
|
2240
2313
|
{
|
|
2241
|
-
style: { width: `${width}px` }
|
|
2314
|
+
style: width ? { width: `${width}px` } : undefinedColWidth ? { width: `${undefinedColWidth}px` } : void 0
|
|
2242
2315
|
},
|
|
2243
2316
|
index
|
|
2244
2317
|
)) }),
|
|
@@ -2533,7 +2606,7 @@ function renderTiptapToReact(content, getImageById) {
|
|
|
2533
2606
|
console.warn("Failed to parse Tiptap content:", error);
|
|
2534
2607
|
parsedContent = { type: "doc", content: [{ type: "paragraph" }] };
|
|
2535
2608
|
}
|
|
2536
|
-
const rendered = (0,
|
|
2609
|
+
const rendered = (0, import_react3.renderToReactElement)({
|
|
2537
2610
|
extensions: getRenderExtensions(),
|
|
2538
2611
|
content: parsedContent,
|
|
2539
2612
|
options: {
|