@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.mjs CHANGED
@@ -5041,7 +5041,9 @@ var BaseLegacyFigure = Image3.extend({
5041
5041
  isolating: true,
5042
5042
  selectable: false,
5043
5043
  addOptions() {
5044
+ const parentOptions = this.parent?.() || {};
5044
5045
  return {
5046
+ ...parentOptions,
5045
5047
  HTMLAttributes: {},
5046
5048
  getImageById: void 0
5047
5049
  };
@@ -6110,40 +6112,25 @@ import Superscript from "@tiptap/extension-superscript";
6110
6112
  import TextAlign from "@tiptap/extension-text-align";
6111
6113
 
6112
6114
  // node_modules/@tiptap/extension-text-style/dist/index.js
6113
- import { Mark as Mark2, mergeAttributes as mergeAttributes8 } from "@tiptap/core";
6114
- import { Extension as Extension2, getStyleProperty } from "@tiptap/core";
6115
- import { Extension as Extension22, getStyleProperty as getStyleProperty2 } from "@tiptap/core";
6116
- import { Extension as Extension3, getStyleProperty as getStyleProperty3 } from "@tiptap/core";
6117
- import { Extension as Extension4, getStyleProperty as getStyleProperty4 } from "@tiptap/core";
6118
- import { Extension as Extension5, getStyleProperty as getStyleProperty5 } from "@tiptap/core";
6119
- import { Extension as Extension6 } from "@tiptap/core";
6115
+ import { Extension as Extension2, Mark as Mark2, getStyleProperty, mergeAttributes as mergeAttributes8 } from "@tiptap/core";
6120
6116
  var MAX_FIND_CHILD_SPAN_DEPTH = 20;
6121
6117
  var findChildSpans = (element, depth = 0) => {
6122
6118
  const childSpans = [];
6123
- if (!element.children.length || depth > MAX_FIND_CHILD_SPAN_DEPTH) {
6124
- return childSpans;
6125
- }
6119
+ if (!element.children.length || depth > MAX_FIND_CHILD_SPAN_DEPTH) return childSpans;
6126
6120
  Array.from(element.children).forEach((child) => {
6127
- if (child.tagName === "SPAN") {
6128
- childSpans.push(child);
6129
- } else if (child.children.length) {
6130
- childSpans.push(...findChildSpans(child, depth + 1));
6131
- }
6121
+ if (child.tagName === "SPAN") childSpans.push(child);
6122
+ else if (child.children.length) childSpans.push(...findChildSpans(child, depth + 1));
6132
6123
  });
6133
6124
  return childSpans;
6134
6125
  };
6135
6126
  var mergeNestedSpanStyles = (element) => {
6136
- if (!element.children.length) {
6137
- return;
6138
- }
6127
+ if (!element.children.length) return;
6139
6128
  const childSpans = findChildSpans(element);
6140
- if (!childSpans) {
6141
- return;
6142
- }
6129
+ if (!childSpans) return;
6143
6130
  childSpans.forEach((childSpan) => {
6144
- var _a, _b;
6131
+ var _childSpan$parentElem;
6145
6132
  const childStyle = childSpan.getAttribute("style");
6146
- const closestParentSpanStyleOfChild = (_b = (_a = childSpan.parentElement) == null ? void 0 : _a.closest("span")) == null ? void 0 : _b.getAttribute("style");
6133
+ 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");
6147
6134
  childSpan.setAttribute("style", `${closestParentSpanStyleOfChild};${childStyle}`);
6148
6135
  });
6149
6136
  };
@@ -6157,25 +6144,22 @@ var TextStyle = Mark2.create({
6157
6144
  };
6158
6145
  },
6159
6146
  parseHTML() {
6160
- return [
6161
- {
6162
- tag: "span",
6163
- consuming: false,
6164
- getAttrs: (element) => {
6165
- const hasStyles = element.hasAttribute("style");
6166
- if (!hasStyles) {
6167
- return false;
6168
- }
6169
- if (this.options.mergeNestedSpanStyles) {
6170
- mergeNestedSpanStyles(element);
6171
- }
6172
- return {};
6173
- }
6147
+ return [{
6148
+ tag: "span",
6149
+ consuming: false,
6150
+ getAttrs: (element) => {
6151
+ if (!element.hasAttribute("style")) return false;
6152
+ if (this.options.mergeNestedSpanStyles) mergeNestedSpanStyles(element);
6153
+ return {};
6174
6154
  }
6175
- ];
6155
+ }];
6176
6156
  },
6177
6157
  renderHTML({ HTMLAttributes }) {
6178
- return ["span", mergeAttributes8(this.options.HTMLAttributes, HTMLAttributes), 0];
6158
+ return [
6159
+ "span",
6160
+ mergeAttributes8(this.options.HTMLAttributes, HTMLAttributes),
6161
+ 0
6162
+ ];
6179
6163
  },
6180
6164
  addCommands() {
6181
6165
  return {
@@ -6185,12 +6169,8 @@ var TextStyle = Mark2.create({
6185
6169
  removeEmptyTextStyle: () => ({ tr: tr2 }) => {
6186
6170
  const { selection } = tr2;
6187
6171
  tr2.doc.nodesBetween(selection.from, selection.to, (node, pos) => {
6188
- if (node.isTextblock) {
6189
- return true;
6190
- }
6191
- if (!node.marks.filter((mark) => mark.type === this.type).some((mark) => Object.values(mark.attrs).some((value) => !!value))) {
6192
- tr2.removeMark(pos, pos + node.nodeSize, this.type);
6193
- }
6172
+ if (!node.isInline) return true;
6173
+ 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);
6194
6174
  });
6195
6175
  return true;
6196
6176
  }
@@ -6200,34 +6180,24 @@ var TextStyle = Mark2.create({
6200
6180
  var BackgroundColor = Extension2.create({
6201
6181
  name: "backgroundColor",
6202
6182
  addOptions() {
6203
- return {
6204
- types: ["textStyle"]
6205
- };
6183
+ return { types: ["textStyle"] };
6206
6184
  },
6207
6185
  addGlobalAttributes() {
6208
- return [
6209
- {
6210
- types: this.options.types,
6211
- attributes: {
6212
- backgroundColor: {
6213
- default: null,
6214
- parseHTML: (element) => {
6215
- var _a;
6216
- const value = (_a = getStyleProperty(element, "background-color")) != null ? _a : element.style.backgroundColor;
6217
- return value == null ? void 0 : value.replace(/['"]+/g, "");
6218
- },
6219
- renderHTML: (attributes) => {
6220
- if (!attributes.backgroundColor) {
6221
- return {};
6222
- }
6223
- return {
6224
- style: `background-color: ${attributes.backgroundColor}`
6225
- };
6226
- }
6227
- }
6186
+ return [{
6187
+ types: this.options.types,
6188
+ attributes: { backgroundColor: {
6189
+ default: null,
6190
+ parseHTML: (element) => {
6191
+ var _getStyleProperty;
6192
+ const value = (_getStyleProperty = getStyleProperty(element, "background-color")) !== null && _getStyleProperty !== void 0 ? _getStyleProperty : element.style.backgroundColor;
6193
+ return value === null || value === void 0 ? void 0 : value.replace(/['"]+/g, "");
6194
+ },
6195
+ renderHTML: (attributes) => {
6196
+ if (!attributes.backgroundColor) return {};
6197
+ return { style: `background-color: ${attributes.backgroundColor}` };
6228
6198
  }
6229
- }
6230
- ];
6199
+ } }
6200
+ }];
6231
6201
  },
6232
6202
  addCommands() {
6233
6203
  return {
@@ -6240,37 +6210,27 @@ var BackgroundColor = Extension2.create({
6240
6210
  };
6241
6211
  }
6242
6212
  });
6243
- var Color = Extension22.create({
6213
+ var Color = Extension2.create({
6244
6214
  name: "color",
6245
6215
  addOptions() {
6246
- return {
6247
- types: ["textStyle"]
6248
- };
6216
+ return { types: ["textStyle"] };
6249
6217
  },
6250
6218
  addGlobalAttributes() {
6251
- return [
6252
- {
6253
- types: this.options.types,
6254
- attributes: {
6255
- color: {
6256
- default: null,
6257
- parseHTML: (element) => {
6258
- var _a;
6259
- const value = (_a = getStyleProperty2(element, "color")) != null ? _a : element.style.color;
6260
- return value == null ? void 0 : value.replace(/['"]+/g, "");
6261
- },
6262
- renderHTML: (attributes) => {
6263
- if (!attributes.color) {
6264
- return {};
6265
- }
6266
- return {
6267
- style: `color: ${attributes.color}`
6268
- };
6269
- }
6270
- }
6219
+ return [{
6220
+ types: this.options.types,
6221
+ attributes: { color: {
6222
+ default: null,
6223
+ parseHTML: (element) => {
6224
+ var _getStyleProperty;
6225
+ const value = (_getStyleProperty = getStyleProperty(element, "color")) !== null && _getStyleProperty !== void 0 ? _getStyleProperty : element.style.color;
6226
+ return value === null || value === void 0 ? void 0 : value.replace(/['"]+/g, "");
6227
+ },
6228
+ renderHTML: (attributes) => {
6229
+ if (!attributes.color) return {};
6230
+ return { style: `color: ${attributes.color}` };
6271
6231
  }
6272
- }
6273
- ];
6232
+ } }
6233
+ }];
6274
6234
  },
6275
6235
  addCommands() {
6276
6236
  return {
@@ -6283,40 +6243,26 @@ var Color = Extension22.create({
6283
6243
  };
6284
6244
  }
6285
6245
  });
6286
- var FontFamily = Extension3.create({
6246
+ var FontFamily = Extension2.create({
6287
6247
  name: "fontFamily",
6288
6248
  addOptions() {
6289
- return {
6290
- types: ["textStyle"]
6291
- };
6249
+ return { types: ["textStyle"] };
6292
6250
  },
6293
6251
  addGlobalAttributes() {
6294
- return [
6295
- {
6296
- types: this.options.types,
6297
- attributes: {
6298
- fontFamily: {
6299
- default: null,
6300
- // Prefer the raw inline `style` attribute so unquoted or
6301
- // single-quoted multi-word names are preserved instead of being
6302
- // canonicalized by `element.style.fontFamily`, which forces double
6303
- // quotes that then get HTML-encoded to `"` on serialization.
6304
- parseHTML: (element) => {
6305
- var _a;
6306
- return (_a = getStyleProperty3(element, "font-family")) != null ? _a : element.style.fontFamily;
6307
- },
6308
- renderHTML: (attributes) => {
6309
- if (!attributes.fontFamily) {
6310
- return {};
6311
- }
6312
- return {
6313
- style: `font-family: ${attributes.fontFamily}`
6314
- };
6315
- }
6316
- }
6252
+ return [{
6253
+ types: this.options.types,
6254
+ attributes: { fontFamily: {
6255
+ default: null,
6256
+ parseHTML: (element) => {
6257
+ var _getStyleProperty;
6258
+ return (_getStyleProperty = getStyleProperty(element, "font-family")) !== null && _getStyleProperty !== void 0 ? _getStyleProperty : element.style.fontFamily;
6259
+ },
6260
+ renderHTML: (attributes) => {
6261
+ if (!attributes.fontFamily) return {};
6262
+ return { style: `font-family: ${attributes.fontFamily}` };
6317
6263
  }
6318
- }
6319
- ];
6264
+ } }
6265
+ }];
6320
6266
  },
6321
6267
  addCommands() {
6322
6268
  return {
@@ -6329,39 +6275,26 @@ var FontFamily = Extension3.create({
6329
6275
  };
6330
6276
  }
6331
6277
  });
6332
- var FontSize = Extension4.create({
6278
+ var FontSize = Extension2.create({
6333
6279
  name: "fontSize",
6334
6280
  addOptions() {
6335
- return {
6336
- types: ["textStyle"]
6337
- };
6281
+ return { types: ["textStyle"] };
6338
6282
  },
6339
6283
  addGlobalAttributes() {
6340
- return [
6341
- {
6342
- types: this.options.types,
6343
- attributes: {
6344
- fontSize: {
6345
- default: null,
6346
- // Prefer the raw inline `style` attribute so the original format
6347
- // is preserved instead of the canonicalized value returned by
6348
- // `element.style.fontSize`.
6349
- parseHTML: (element) => {
6350
- var _a;
6351
- return (_a = getStyleProperty4(element, "font-size")) != null ? _a : element.style.fontSize;
6352
- },
6353
- renderHTML: (attributes) => {
6354
- if (!attributes.fontSize) {
6355
- return {};
6356
- }
6357
- return {
6358
- style: `font-size: ${attributes.fontSize}`
6359
- };
6360
- }
6361
- }
6284
+ return [{
6285
+ types: this.options.types,
6286
+ attributes: { fontSize: {
6287
+ default: null,
6288
+ parseHTML: (element) => {
6289
+ var _getStyleProperty;
6290
+ return (_getStyleProperty = getStyleProperty(element, "font-size")) !== null && _getStyleProperty !== void 0 ? _getStyleProperty : element.style.fontSize;
6291
+ },
6292
+ renderHTML: (attributes) => {
6293
+ if (!attributes.fontSize) return {};
6294
+ return { style: `font-size: ${attributes.fontSize}` };
6362
6295
  }
6363
- }
6364
- ];
6296
+ } }
6297
+ }];
6365
6298
  },
6366
6299
  addCommands() {
6367
6300
  return {
@@ -6374,39 +6307,26 @@ var FontSize = Extension4.create({
6374
6307
  };
6375
6308
  }
6376
6309
  });
6377
- var LineHeight = Extension5.create({
6310
+ var LineHeight = Extension2.create({
6378
6311
  name: "lineHeight",
6379
6312
  addOptions() {
6380
- return {
6381
- types: ["textStyle"]
6382
- };
6313
+ return { types: ["textStyle"] };
6383
6314
  },
6384
6315
  addGlobalAttributes() {
6385
- return [
6386
- {
6387
- types: this.options.types,
6388
- attributes: {
6389
- lineHeight: {
6390
- default: null,
6391
- // Prefer the raw inline `style` attribute so the original format
6392
- // is preserved instead of the canonicalized value returned by
6393
- // `element.style.lineHeight`.
6394
- parseHTML: (element) => {
6395
- var _a;
6396
- return (_a = getStyleProperty5(element, "line-height")) != null ? _a : element.style.lineHeight;
6397
- },
6398
- renderHTML: (attributes) => {
6399
- if (!attributes.lineHeight) {
6400
- return {};
6401
- }
6402
- return {
6403
- style: `line-height: ${attributes.lineHeight}`
6404
- };
6405
- }
6406
- }
6316
+ return [{
6317
+ types: this.options.types,
6318
+ attributes: { lineHeight: {
6319
+ default: null,
6320
+ parseHTML: (element) => {
6321
+ var _getStyleProperty;
6322
+ return (_getStyleProperty = getStyleProperty(element, "line-height")) !== null && _getStyleProperty !== void 0 ? _getStyleProperty : element.style.lineHeight;
6323
+ },
6324
+ renderHTML: (attributes) => {
6325
+ if (!attributes.lineHeight) return {};
6326
+ return { style: `line-height: ${attributes.lineHeight}` };
6407
6327
  }
6408
- }
6409
- ];
6328
+ } }
6329
+ }];
6410
6330
  },
6411
6331
  addCommands() {
6412
6332
  return {
@@ -6419,28 +6339,16 @@ var LineHeight = Extension5.create({
6419
6339
  };
6420
6340
  }
6421
6341
  });
6422
- var TextStyleKit = Extension6.create({
6342
+ var TextStyleKit = Extension2.create({
6423
6343
  name: "textStyleKit",
6424
6344
  addExtensions() {
6425
6345
  const extensions = [];
6426
- if (this.options.backgroundColor !== false) {
6427
- extensions.push(BackgroundColor.configure(this.options.backgroundColor));
6428
- }
6429
- if (this.options.color !== false) {
6430
- extensions.push(Color.configure(this.options.color));
6431
- }
6432
- if (this.options.fontFamily !== false) {
6433
- extensions.push(FontFamily.configure(this.options.fontFamily));
6434
- }
6435
- if (this.options.fontSize !== false) {
6436
- extensions.push(FontSize.configure(this.options.fontSize));
6437
- }
6438
- if (this.options.lineHeight !== false) {
6439
- extensions.push(LineHeight.configure(this.options.lineHeight));
6440
- }
6441
- if (this.options.textStyle !== false) {
6442
- extensions.push(TextStyle.configure(this.options.textStyle));
6443
- }
6346
+ if (this.options.backgroundColor !== false) extensions.push(BackgroundColor.configure(this.options.backgroundColor));
6347
+ if (this.options.color !== false) extensions.push(Color.configure(this.options.color));
6348
+ if (this.options.fontFamily !== false) extensions.push(FontFamily.configure(this.options.fontFamily));
6349
+ if (this.options.fontSize !== false) extensions.push(FontSize.configure(this.options.fontSize));
6350
+ if (this.options.lineHeight !== false) extensions.push(LineHeight.configure(this.options.lineHeight));
6351
+ if (this.options.textStyle !== false) extensions.push(TextStyle.configure(this.options.textStyle));
6444
6352
  return extensions;
6445
6353
  }
6446
6354
  });