@cyberyozh/text-editor 0.5.1 → 0.5.2

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.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
1
+ import * as react from 'react';
2
2
  import { JSONContent } from '@tiptap/react';
3
3
  export { JSONContent } from '@tiptap/react';
4
4
  import { JSONContent as JSONContent$1 } from '@tiptap/core';
@@ -61,7 +61,7 @@ interface KatexDialogContextProps {
61
61
  latex?: string;
62
62
  pos?: number;
63
63
  }
64
- declare const Tiptap: (props: TiptapProps) => react_jsx_runtime.JSX.Element;
64
+ declare const Tiptap: (props: TiptapProps) => react.JSX.Element;
65
65
 
66
66
  interface SharedExtensionsOptions {
67
67
  /**
package/dist/editor.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
1
+ import * as react from 'react';
2
2
  import { JSONContent } from '@tiptap/react';
3
3
  export { JSONContent } from '@tiptap/react';
4
4
  import { JSONContent as JSONContent$1 } from '@tiptap/core';
@@ -61,7 +61,7 @@ interface KatexDialogContextProps {
61
61
  latex?: string;
62
62
  pos?: number;
63
63
  }
64
- declare const Tiptap: (props: TiptapProps) => react_jsx_runtime.JSX.Element;
64
+ declare const Tiptap: (props: TiptapProps) => react.JSX.Element;
65
65
 
66
66
  interface SharedExtensionsOptions {
67
67
  /**
package/dist/editor.js CHANGED
@@ -5078,7 +5078,9 @@ var BaseLegacyFigure = import_extension_image2.default.extend({
5078
5078
  isolating: true,
5079
5079
  selectable: false,
5080
5080
  addOptions() {
5081
+ const parentOptions = this.parent?.() || {};
5081
5082
  return {
5083
+ ...parentOptions,
5082
5084
  HTMLAttributes: {},
5083
5085
  getImageById: void 0
5084
5086
  };
@@ -6144,39 +6146,24 @@ var import_extension_text_align = __toESM(require("@tiptap/extension-text-align"
6144
6146
 
6145
6147
  // node_modules/@tiptap/extension-text-style/dist/index.js
6146
6148
  var import_core11 = require("@tiptap/core");
6147
- var import_core12 = require("@tiptap/core");
6148
- var import_core13 = require("@tiptap/core");
6149
- var import_core14 = require("@tiptap/core");
6150
- var import_core15 = require("@tiptap/core");
6151
- var import_core16 = require("@tiptap/core");
6152
- var import_core17 = require("@tiptap/core");
6153
6149
  var MAX_FIND_CHILD_SPAN_DEPTH = 20;
6154
6150
  var findChildSpans = (element, depth = 0) => {
6155
6151
  const childSpans = [];
6156
- if (!element.children.length || depth > MAX_FIND_CHILD_SPAN_DEPTH) {
6157
- return childSpans;
6158
- }
6152
+ if (!element.children.length || depth > MAX_FIND_CHILD_SPAN_DEPTH) return childSpans;
6159
6153
  Array.from(element.children).forEach((child) => {
6160
- if (child.tagName === "SPAN") {
6161
- childSpans.push(child);
6162
- } else if (child.children.length) {
6163
- childSpans.push(...findChildSpans(child, depth + 1));
6164
- }
6154
+ if (child.tagName === "SPAN") childSpans.push(child);
6155
+ else if (child.children.length) childSpans.push(...findChildSpans(child, depth + 1));
6165
6156
  });
6166
6157
  return childSpans;
6167
6158
  };
6168
6159
  var mergeNestedSpanStyles = (element) => {
6169
- if (!element.children.length) {
6170
- return;
6171
- }
6160
+ if (!element.children.length) return;
6172
6161
  const childSpans = findChildSpans(element);
6173
- if (!childSpans) {
6174
- return;
6175
- }
6162
+ if (!childSpans) return;
6176
6163
  childSpans.forEach((childSpan) => {
6177
- var _a, _b;
6164
+ var _childSpan$parentElem;
6178
6165
  const childStyle = childSpan.getAttribute("style");
6179
- const closestParentSpanStyleOfChild = (_b = (_a = childSpan.parentElement) == null ? void 0 : _a.closest("span")) == null ? void 0 : _b.getAttribute("style");
6166
+ const closestParentSpanStyleOfChild = (_childSpan$parentElem = childSpan.parentElement) === null || _childSpan$parentElem === void 0 || (_childSpan$parentElem = _childSpan$parentElem.closest("span")) === null || _childSpan$parentElem === void 0 ? void 0 : _childSpan$parentElem.getAttribute("style");
6180
6167
  childSpan.setAttribute("style", `${closestParentSpanStyleOfChild};${childStyle}`);
6181
6168
  });
6182
6169
  };
@@ -6190,25 +6177,22 @@ var TextStyle = import_core11.Mark.create({
6190
6177
  };
6191
6178
  },
6192
6179
  parseHTML() {
6193
- return [
6194
- {
6195
- tag: "span",
6196
- consuming: false,
6197
- getAttrs: (element) => {
6198
- const hasStyles = element.hasAttribute("style");
6199
- if (!hasStyles) {
6200
- return false;
6201
- }
6202
- if (this.options.mergeNestedSpanStyles) {
6203
- mergeNestedSpanStyles(element);
6204
- }
6205
- return {};
6206
- }
6180
+ return [{
6181
+ tag: "span",
6182
+ consuming: false,
6183
+ getAttrs: (element) => {
6184
+ if (!element.hasAttribute("style")) return false;
6185
+ if (this.options.mergeNestedSpanStyles) mergeNestedSpanStyles(element);
6186
+ return {};
6207
6187
  }
6208
- ];
6188
+ }];
6209
6189
  },
6210
6190
  renderHTML({ HTMLAttributes }) {
6211
- return ["span", (0, import_core11.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes), 0];
6191
+ return [
6192
+ "span",
6193
+ (0, import_core11.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes),
6194
+ 0
6195
+ ];
6212
6196
  },
6213
6197
  addCommands() {
6214
6198
  return {
@@ -6218,49 +6202,35 @@ var TextStyle = import_core11.Mark.create({
6218
6202
  removeEmptyTextStyle: () => ({ tr: tr2 }) => {
6219
6203
  const { selection } = tr2;
6220
6204
  tr2.doc.nodesBetween(selection.from, selection.to, (node, pos) => {
6221
- if (node.isTextblock) {
6222
- return true;
6223
- }
6224
- if (!node.marks.filter((mark) => mark.type === this.type).some((mark) => Object.values(mark.attrs).some((value) => !!value))) {
6225
- tr2.removeMark(pos, pos + node.nodeSize, this.type);
6226
- }
6205
+ if (!node.isInline) return true;
6206
+ if (!node.marks.filter((mark) => mark.type === this.type).some((mark) => Object.values(mark.attrs).some((value) => !!value))) tr2.removeMark(pos, pos + node.nodeSize, this.type);
6227
6207
  });
6228
6208
  return true;
6229
6209
  }
6230
6210
  };
6231
6211
  }
6232
6212
  });
6233
- var BackgroundColor = import_core12.Extension.create({
6213
+ var BackgroundColor = import_core11.Extension.create({
6234
6214
  name: "backgroundColor",
6235
6215
  addOptions() {
6236
- return {
6237
- types: ["textStyle"]
6238
- };
6216
+ return { types: ["textStyle"] };
6239
6217
  },
6240
6218
  addGlobalAttributes() {
6241
- return [
6242
- {
6243
- types: this.options.types,
6244
- attributes: {
6245
- backgroundColor: {
6246
- default: null,
6247
- parseHTML: (element) => {
6248
- var _a;
6249
- const value = (_a = (0, import_core12.getStyleProperty)(element, "background-color")) != null ? _a : element.style.backgroundColor;
6250
- return value == null ? void 0 : value.replace(/['"]+/g, "");
6251
- },
6252
- renderHTML: (attributes) => {
6253
- if (!attributes.backgroundColor) {
6254
- return {};
6255
- }
6256
- return {
6257
- style: `background-color: ${attributes.backgroundColor}`
6258
- };
6259
- }
6260
- }
6219
+ return [{
6220
+ types: this.options.types,
6221
+ attributes: { backgroundColor: {
6222
+ default: null,
6223
+ parseHTML: (element) => {
6224
+ var _getStyleProperty;
6225
+ const value = (_getStyleProperty = (0, import_core11.getStyleProperty)(element, "background-color")) !== null && _getStyleProperty !== void 0 ? _getStyleProperty : element.style.backgroundColor;
6226
+ return value === null || value === void 0 ? void 0 : value.replace(/['"]+/g, "");
6227
+ },
6228
+ renderHTML: (attributes) => {
6229
+ if (!attributes.backgroundColor) return {};
6230
+ return { style: `background-color: ${attributes.backgroundColor}` };
6261
6231
  }
6262
- }
6263
- ];
6232
+ } }
6233
+ }];
6264
6234
  },
6265
6235
  addCommands() {
6266
6236
  return {
@@ -6273,37 +6243,27 @@ var BackgroundColor = import_core12.Extension.create({
6273
6243
  };
6274
6244
  }
6275
6245
  });
6276
- var Color = import_core13.Extension.create({
6246
+ var Color = import_core11.Extension.create({
6277
6247
  name: "color",
6278
6248
  addOptions() {
6279
- return {
6280
- types: ["textStyle"]
6281
- };
6249
+ return { types: ["textStyle"] };
6282
6250
  },
6283
6251
  addGlobalAttributes() {
6284
- return [
6285
- {
6286
- types: this.options.types,
6287
- attributes: {
6288
- color: {
6289
- default: null,
6290
- parseHTML: (element) => {
6291
- var _a;
6292
- const value = (_a = (0, import_core13.getStyleProperty)(element, "color")) != null ? _a : element.style.color;
6293
- return value == null ? void 0 : value.replace(/['"]+/g, "");
6294
- },
6295
- renderHTML: (attributes) => {
6296
- if (!attributes.color) {
6297
- return {};
6298
- }
6299
- return {
6300
- style: `color: ${attributes.color}`
6301
- };
6302
- }
6303
- }
6252
+ return [{
6253
+ types: this.options.types,
6254
+ attributes: { color: {
6255
+ default: null,
6256
+ parseHTML: (element) => {
6257
+ var _getStyleProperty;
6258
+ const value = (_getStyleProperty = (0, import_core11.getStyleProperty)(element, "color")) !== null && _getStyleProperty !== void 0 ? _getStyleProperty : element.style.color;
6259
+ return value === null || value === void 0 ? void 0 : value.replace(/['"]+/g, "");
6260
+ },
6261
+ renderHTML: (attributes) => {
6262
+ if (!attributes.color) return {};
6263
+ return { style: `color: ${attributes.color}` };
6304
6264
  }
6305
- }
6306
- ];
6265
+ } }
6266
+ }];
6307
6267
  },
6308
6268
  addCommands() {
6309
6269
  return {
@@ -6316,40 +6276,26 @@ var Color = import_core13.Extension.create({
6316
6276
  };
6317
6277
  }
6318
6278
  });
6319
- var FontFamily = import_core14.Extension.create({
6279
+ var FontFamily = import_core11.Extension.create({
6320
6280
  name: "fontFamily",
6321
6281
  addOptions() {
6322
- return {
6323
- types: ["textStyle"]
6324
- };
6282
+ return { types: ["textStyle"] };
6325
6283
  },
6326
6284
  addGlobalAttributes() {
6327
- return [
6328
- {
6329
- types: this.options.types,
6330
- attributes: {
6331
- fontFamily: {
6332
- default: null,
6333
- // Prefer the raw inline `style` attribute so unquoted or
6334
- // single-quoted multi-word names are preserved instead of being
6335
- // canonicalized by `element.style.fontFamily`, which forces double
6336
- // quotes that then get HTML-encoded to `"` on serialization.
6337
- parseHTML: (element) => {
6338
- var _a;
6339
- return (_a = (0, import_core14.getStyleProperty)(element, "font-family")) != null ? _a : element.style.fontFamily;
6340
- },
6341
- renderHTML: (attributes) => {
6342
- if (!attributes.fontFamily) {
6343
- return {};
6344
- }
6345
- return {
6346
- style: `font-family: ${attributes.fontFamily}`
6347
- };
6348
- }
6349
- }
6285
+ return [{
6286
+ types: this.options.types,
6287
+ attributes: { fontFamily: {
6288
+ default: null,
6289
+ parseHTML: (element) => {
6290
+ var _getStyleProperty;
6291
+ return (_getStyleProperty = (0, import_core11.getStyleProperty)(element, "font-family")) !== null && _getStyleProperty !== void 0 ? _getStyleProperty : element.style.fontFamily;
6292
+ },
6293
+ renderHTML: (attributes) => {
6294
+ if (!attributes.fontFamily) return {};
6295
+ return { style: `font-family: ${attributes.fontFamily}` };
6350
6296
  }
6351
- }
6352
- ];
6297
+ } }
6298
+ }];
6353
6299
  },
6354
6300
  addCommands() {
6355
6301
  return {
@@ -6362,39 +6308,26 @@ var FontFamily = import_core14.Extension.create({
6362
6308
  };
6363
6309
  }
6364
6310
  });
6365
- var FontSize = import_core15.Extension.create({
6311
+ var FontSize = import_core11.Extension.create({
6366
6312
  name: "fontSize",
6367
6313
  addOptions() {
6368
- return {
6369
- types: ["textStyle"]
6370
- };
6314
+ return { types: ["textStyle"] };
6371
6315
  },
6372
6316
  addGlobalAttributes() {
6373
- return [
6374
- {
6375
- types: this.options.types,
6376
- attributes: {
6377
- fontSize: {
6378
- default: null,
6379
- // Prefer the raw inline `style` attribute so the original format
6380
- // is preserved instead of the canonicalized value returned by
6381
- // `element.style.fontSize`.
6382
- parseHTML: (element) => {
6383
- var _a;
6384
- return (_a = (0, import_core15.getStyleProperty)(element, "font-size")) != null ? _a : element.style.fontSize;
6385
- },
6386
- renderHTML: (attributes) => {
6387
- if (!attributes.fontSize) {
6388
- return {};
6389
- }
6390
- return {
6391
- style: `font-size: ${attributes.fontSize}`
6392
- };
6393
- }
6394
- }
6317
+ return [{
6318
+ types: this.options.types,
6319
+ attributes: { fontSize: {
6320
+ default: null,
6321
+ parseHTML: (element) => {
6322
+ var _getStyleProperty;
6323
+ return (_getStyleProperty = (0, import_core11.getStyleProperty)(element, "font-size")) !== null && _getStyleProperty !== void 0 ? _getStyleProperty : element.style.fontSize;
6324
+ },
6325
+ renderHTML: (attributes) => {
6326
+ if (!attributes.fontSize) return {};
6327
+ return { style: `font-size: ${attributes.fontSize}` };
6395
6328
  }
6396
- }
6397
- ];
6329
+ } }
6330
+ }];
6398
6331
  },
6399
6332
  addCommands() {
6400
6333
  return {
@@ -6407,39 +6340,26 @@ var FontSize = import_core15.Extension.create({
6407
6340
  };
6408
6341
  }
6409
6342
  });
6410
- var LineHeight = import_core16.Extension.create({
6343
+ var LineHeight = import_core11.Extension.create({
6411
6344
  name: "lineHeight",
6412
6345
  addOptions() {
6413
- return {
6414
- types: ["textStyle"]
6415
- };
6346
+ return { types: ["textStyle"] };
6416
6347
  },
6417
6348
  addGlobalAttributes() {
6418
- return [
6419
- {
6420
- types: this.options.types,
6421
- attributes: {
6422
- lineHeight: {
6423
- default: null,
6424
- // Prefer the raw inline `style` attribute so the original format
6425
- // is preserved instead of the canonicalized value returned by
6426
- // `element.style.lineHeight`.
6427
- parseHTML: (element) => {
6428
- var _a;
6429
- return (_a = (0, import_core16.getStyleProperty)(element, "line-height")) != null ? _a : element.style.lineHeight;
6430
- },
6431
- renderHTML: (attributes) => {
6432
- if (!attributes.lineHeight) {
6433
- return {};
6434
- }
6435
- return {
6436
- style: `line-height: ${attributes.lineHeight}`
6437
- };
6438
- }
6439
- }
6349
+ return [{
6350
+ types: this.options.types,
6351
+ attributes: { lineHeight: {
6352
+ default: null,
6353
+ parseHTML: (element) => {
6354
+ var _getStyleProperty;
6355
+ return (_getStyleProperty = (0, import_core11.getStyleProperty)(element, "line-height")) !== null && _getStyleProperty !== void 0 ? _getStyleProperty : element.style.lineHeight;
6356
+ },
6357
+ renderHTML: (attributes) => {
6358
+ if (!attributes.lineHeight) return {};
6359
+ return { style: `line-height: ${attributes.lineHeight}` };
6440
6360
  }
6441
- }
6442
- ];
6361
+ } }
6362
+ }];
6443
6363
  },
6444
6364
  addCommands() {
6445
6365
  return {
@@ -6452,28 +6372,16 @@ var LineHeight = import_core16.Extension.create({
6452
6372
  };
6453
6373
  }
6454
6374
  });
6455
- var TextStyleKit = import_core17.Extension.create({
6375
+ var TextStyleKit = import_core11.Extension.create({
6456
6376
  name: "textStyleKit",
6457
6377
  addExtensions() {
6458
6378
  const extensions = [];
6459
- if (this.options.backgroundColor !== false) {
6460
- extensions.push(BackgroundColor.configure(this.options.backgroundColor));
6461
- }
6462
- if (this.options.color !== false) {
6463
- extensions.push(Color.configure(this.options.color));
6464
- }
6465
- if (this.options.fontFamily !== false) {
6466
- extensions.push(FontFamily.configure(this.options.fontFamily));
6467
- }
6468
- if (this.options.fontSize !== false) {
6469
- extensions.push(FontSize.configure(this.options.fontSize));
6470
- }
6471
- if (this.options.lineHeight !== false) {
6472
- extensions.push(LineHeight.configure(this.options.lineHeight));
6473
- }
6474
- if (this.options.textStyle !== false) {
6475
- extensions.push(TextStyle.configure(this.options.textStyle));
6476
- }
6379
+ if (this.options.backgroundColor !== false) extensions.push(BackgroundColor.configure(this.options.backgroundColor));
6380
+ if (this.options.color !== false) extensions.push(Color.configure(this.options.color));
6381
+ if (this.options.fontFamily !== false) extensions.push(FontFamily.configure(this.options.fontFamily));
6382
+ if (this.options.fontSize !== false) extensions.push(FontSize.configure(this.options.fontSize));
6383
+ if (this.options.lineHeight !== false) extensions.push(LineHeight.configure(this.options.lineHeight));
6384
+ if (this.options.textStyle !== false) extensions.push(TextStyle.configure(this.options.textStyle));
6477
6385
  return extensions;
6478
6386
  }
6479
6387
  });
@@ -6544,7 +6452,7 @@ var LegacyPromptSEContent = BaseLegacyPromptSEContent.extend({
6544
6452
 
6545
6453
  // src/extensions/editor/figure.ts
6546
6454
  var import_react35 = require("@tiptap/react");
6547
- var import_core18 = require("@tiptap/core");
6455
+ var import_core12 = require("@tiptap/core");
6548
6456
  var Figure2 = BaseFigure.extend({
6549
6457
  addNodeView() {
6550
6458
  const resizeOptions = this.options.resize;
@@ -6632,7 +6540,7 @@ var Figure2 = BaseFigure.extend({
6632
6540
  });
6633
6541
  imageContainer.appendChild(editButton);
6634
6542
  }
6635
- const resizableView = new import_core18.ResizableNodeView({
6543
+ const resizableView = new import_core12.ResizableNodeView({
6636
6544
  element: imageContainer,
6637
6545
  editor,
6638
6546
  node,
@@ -7034,7 +6942,7 @@ function useInsertionHandlers(imageHandlers) {
7034
6942
 
7035
6943
  // src/editor/commands/suggestion.tsx
7036
6944
  var import_dom = require("@floating-ui/dom");
7037
- var import_core19 = require("@tiptap/core");
6945
+ var import_core13 = require("@tiptap/core");
7038
6946
  var import_react37 = require("@tiptap/react");
7039
6947
 
7040
6948
  // src/editor/commands/items.ts
@@ -7378,7 +7286,7 @@ var createSuggestions = (translations2, hasImageHandlers) => ({
7378
7286
  component.element.style.position = "absolute";
7379
7287
  document.body.appendChild(component.element);
7380
7288
  const virtualElement = {
7381
- getBoundingClientRect: () => (0, import_core19.posToDOMRect)(
7289
+ getBoundingClientRect: () => (0, import_core13.posToDOMRect)(
7382
7290
  props.editor.view,
7383
7291
  props.editor.state.selection.from,
7384
7292
  props.editor.state.selection.to
@@ -7405,7 +7313,7 @@ var createSuggestions = (translations2, hasImageHandlers) => ({
7405
7313
  return;
7406
7314
  }
7407
7315
  const virtualElement = {
7408
- getBoundingClientRect: () => (0, import_core19.posToDOMRect)(
7316
+ getBoundingClientRect: () => (0, import_core13.posToDOMRect)(
7409
7317
  props.editor.view,
7410
7318
  props.editor.state.selection.from,
7411
7319
  props.editor.state.selection.to
@@ -8016,7 +7924,7 @@ var Tiptap = (props) => {
8016
7924
  };
8017
7925
 
8018
7926
  // src/utils/html-to-tiptap-content.ts
8019
- var import_core20 = require("@tiptap/core");
7927
+ var import_core14 = require("@tiptap/core");
8020
7928
  var import_extension_table2 = require("@tiptap/extension-table");
8021
7929
  function isJSONContent(value) {
8022
7930
  return typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
@@ -8040,7 +7948,7 @@ function htmlToTiptapContent(content, options = {}) {
8040
7948
  const sharedExtensions = getSharedExtensions(options);
8041
7949
  const extensions = [...sharedExtensions, BaseFigure, import_extension_table2.TableKit, BaseCodeBlock];
8042
7950
  try {
8043
- return (0, import_core20.generateJSON)(content, extensions);
7951
+ return (0, import_core14.generateJSON)(content, extensions);
8044
7952
  } catch (error) {
8045
7953
  console.error("Failed to convert HTML to Tiptap content:", error);
8046
7954
  return { type: "doc", content: [{ type: "paragraph" }] };