@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/render.mjs CHANGED
@@ -2003,40 +2003,25 @@ import Superscript from "@tiptap/extension-superscript";
2003
2003
  import TextAlign from "@tiptap/extension-text-align";
2004
2004
 
2005
2005
  // node_modules/@tiptap/extension-text-style/dist/index.js
2006
- import { Mark as Mark2, mergeAttributes as mergeAttributes7 } from "@tiptap/core";
2007
- import { Extension, getStyleProperty } from "@tiptap/core";
2008
- import { Extension as Extension2, getStyleProperty as getStyleProperty2 } from "@tiptap/core";
2009
- import { Extension as Extension3, getStyleProperty as getStyleProperty3 } from "@tiptap/core";
2010
- import { Extension as Extension4, getStyleProperty as getStyleProperty4 } from "@tiptap/core";
2011
- import { Extension as Extension5, getStyleProperty as getStyleProperty5 } from "@tiptap/core";
2012
- import { Extension as Extension6 } from "@tiptap/core";
2006
+ import { Extension, Mark as Mark2, getStyleProperty, mergeAttributes as mergeAttributes7 } from "@tiptap/core";
2013
2007
  var MAX_FIND_CHILD_SPAN_DEPTH = 20;
2014
2008
  var findChildSpans = (element, depth = 0) => {
2015
2009
  const childSpans = [];
2016
- if (!element.children.length || depth > MAX_FIND_CHILD_SPAN_DEPTH) {
2017
- return childSpans;
2018
- }
2010
+ if (!element.children.length || depth > MAX_FIND_CHILD_SPAN_DEPTH) return childSpans;
2019
2011
  Array.from(element.children).forEach((child) => {
2020
- if (child.tagName === "SPAN") {
2021
- childSpans.push(child);
2022
- } else if (child.children.length) {
2023
- childSpans.push(...findChildSpans(child, depth + 1));
2024
- }
2012
+ if (child.tagName === "SPAN") childSpans.push(child);
2013
+ else if (child.children.length) childSpans.push(...findChildSpans(child, depth + 1));
2025
2014
  });
2026
2015
  return childSpans;
2027
2016
  };
2028
2017
  var mergeNestedSpanStyles = (element) => {
2029
- if (!element.children.length) {
2030
- return;
2031
- }
2018
+ if (!element.children.length) return;
2032
2019
  const childSpans = findChildSpans(element);
2033
- if (!childSpans) {
2034
- return;
2035
- }
2020
+ if (!childSpans) return;
2036
2021
  childSpans.forEach((childSpan) => {
2037
- var _a, _b;
2022
+ var _childSpan$parentElem;
2038
2023
  const childStyle = childSpan.getAttribute("style");
2039
- const closestParentSpanStyleOfChild = (_b = (_a = childSpan.parentElement) == null ? void 0 : _a.closest("span")) == null ? void 0 : _b.getAttribute("style");
2024
+ 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");
2040
2025
  childSpan.setAttribute("style", `${closestParentSpanStyleOfChild};${childStyle}`);
2041
2026
  });
2042
2027
  };
@@ -2050,25 +2035,22 @@ var TextStyle = Mark2.create({
2050
2035
  };
2051
2036
  },
2052
2037
  parseHTML() {
2053
- return [
2054
- {
2055
- tag: "span",
2056
- consuming: false,
2057
- getAttrs: (element) => {
2058
- const hasStyles = element.hasAttribute("style");
2059
- if (!hasStyles) {
2060
- return false;
2061
- }
2062
- if (this.options.mergeNestedSpanStyles) {
2063
- mergeNestedSpanStyles(element);
2064
- }
2065
- return {};
2066
- }
2038
+ return [{
2039
+ tag: "span",
2040
+ consuming: false,
2041
+ getAttrs: (element) => {
2042
+ if (!element.hasAttribute("style")) return false;
2043
+ if (this.options.mergeNestedSpanStyles) mergeNestedSpanStyles(element);
2044
+ return {};
2067
2045
  }
2068
- ];
2046
+ }];
2069
2047
  },
2070
2048
  renderHTML({ HTMLAttributes }) {
2071
- return ["span", mergeAttributes7(this.options.HTMLAttributes, HTMLAttributes), 0];
2049
+ return [
2050
+ "span",
2051
+ mergeAttributes7(this.options.HTMLAttributes, HTMLAttributes),
2052
+ 0
2053
+ ];
2072
2054
  },
2073
2055
  addCommands() {
2074
2056
  return {
@@ -2078,12 +2060,8 @@ var TextStyle = Mark2.create({
2078
2060
  removeEmptyTextStyle: () => ({ tr: tr2 }) => {
2079
2061
  const { selection } = tr2;
2080
2062
  tr2.doc.nodesBetween(selection.from, selection.to, (node, pos) => {
2081
- if (node.isTextblock) {
2082
- return true;
2083
- }
2084
- if (!node.marks.filter((mark) => mark.type === this.type).some((mark) => Object.values(mark.attrs).some((value) => !!value))) {
2085
- tr2.removeMark(pos, pos + node.nodeSize, this.type);
2086
- }
2063
+ if (!node.isInline) return true;
2064
+ 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);
2087
2065
  });
2088
2066
  return true;
2089
2067
  }
@@ -2093,34 +2071,24 @@ var TextStyle = Mark2.create({
2093
2071
  var BackgroundColor = Extension.create({
2094
2072
  name: "backgroundColor",
2095
2073
  addOptions() {
2096
- return {
2097
- types: ["textStyle"]
2098
- };
2074
+ return { types: ["textStyle"] };
2099
2075
  },
2100
2076
  addGlobalAttributes() {
2101
- return [
2102
- {
2103
- types: this.options.types,
2104
- attributes: {
2105
- backgroundColor: {
2106
- default: null,
2107
- parseHTML: (element) => {
2108
- var _a;
2109
- const value = (_a = getStyleProperty(element, "background-color")) != null ? _a : element.style.backgroundColor;
2110
- return value == null ? void 0 : value.replace(/['"]+/g, "");
2111
- },
2112
- renderHTML: (attributes) => {
2113
- if (!attributes.backgroundColor) {
2114
- return {};
2115
- }
2116
- return {
2117
- style: `background-color: ${attributes.backgroundColor}`
2118
- };
2119
- }
2120
- }
2077
+ return [{
2078
+ types: this.options.types,
2079
+ attributes: { backgroundColor: {
2080
+ default: null,
2081
+ parseHTML: (element) => {
2082
+ var _getStyleProperty;
2083
+ const value = (_getStyleProperty = getStyleProperty(element, "background-color")) !== null && _getStyleProperty !== void 0 ? _getStyleProperty : element.style.backgroundColor;
2084
+ return value === null || value === void 0 ? void 0 : value.replace(/['"]+/g, "");
2085
+ },
2086
+ renderHTML: (attributes) => {
2087
+ if (!attributes.backgroundColor) return {};
2088
+ return { style: `background-color: ${attributes.backgroundColor}` };
2121
2089
  }
2122
- }
2123
- ];
2090
+ } }
2091
+ }];
2124
2092
  },
2125
2093
  addCommands() {
2126
2094
  return {
@@ -2133,37 +2101,27 @@ var BackgroundColor = Extension.create({
2133
2101
  };
2134
2102
  }
2135
2103
  });
2136
- var Color = Extension2.create({
2104
+ var Color = Extension.create({
2137
2105
  name: "color",
2138
2106
  addOptions() {
2139
- return {
2140
- types: ["textStyle"]
2141
- };
2107
+ return { types: ["textStyle"] };
2142
2108
  },
2143
2109
  addGlobalAttributes() {
2144
- return [
2145
- {
2146
- types: this.options.types,
2147
- attributes: {
2148
- color: {
2149
- default: null,
2150
- parseHTML: (element) => {
2151
- var _a;
2152
- const value = (_a = getStyleProperty2(element, "color")) != null ? _a : element.style.color;
2153
- return value == null ? void 0 : value.replace(/['"]+/g, "");
2154
- },
2155
- renderHTML: (attributes) => {
2156
- if (!attributes.color) {
2157
- return {};
2158
- }
2159
- return {
2160
- style: `color: ${attributes.color}`
2161
- };
2162
- }
2163
- }
2110
+ return [{
2111
+ types: this.options.types,
2112
+ attributes: { color: {
2113
+ default: null,
2114
+ parseHTML: (element) => {
2115
+ var _getStyleProperty;
2116
+ const value = (_getStyleProperty = getStyleProperty(element, "color")) !== null && _getStyleProperty !== void 0 ? _getStyleProperty : element.style.color;
2117
+ return value === null || value === void 0 ? void 0 : value.replace(/['"]+/g, "");
2118
+ },
2119
+ renderHTML: (attributes) => {
2120
+ if (!attributes.color) return {};
2121
+ return { style: `color: ${attributes.color}` };
2164
2122
  }
2165
- }
2166
- ];
2123
+ } }
2124
+ }];
2167
2125
  },
2168
2126
  addCommands() {
2169
2127
  return {
@@ -2176,40 +2134,26 @@ var Color = Extension2.create({
2176
2134
  };
2177
2135
  }
2178
2136
  });
2179
- var FontFamily = Extension3.create({
2137
+ var FontFamily = Extension.create({
2180
2138
  name: "fontFamily",
2181
2139
  addOptions() {
2182
- return {
2183
- types: ["textStyle"]
2184
- };
2140
+ return { types: ["textStyle"] };
2185
2141
  },
2186
2142
  addGlobalAttributes() {
2187
- return [
2188
- {
2189
- types: this.options.types,
2190
- attributes: {
2191
- fontFamily: {
2192
- default: null,
2193
- // Prefer the raw inline `style` attribute so unquoted or
2194
- // single-quoted multi-word names are preserved instead of being
2195
- // canonicalized by `element.style.fontFamily`, which forces double
2196
- // quotes that then get HTML-encoded to `"` on serialization.
2197
- parseHTML: (element) => {
2198
- var _a;
2199
- return (_a = getStyleProperty3(element, "font-family")) != null ? _a : element.style.fontFamily;
2200
- },
2201
- renderHTML: (attributes) => {
2202
- if (!attributes.fontFamily) {
2203
- return {};
2204
- }
2205
- return {
2206
- style: `font-family: ${attributes.fontFamily}`
2207
- };
2208
- }
2209
- }
2143
+ return [{
2144
+ types: this.options.types,
2145
+ attributes: { fontFamily: {
2146
+ default: null,
2147
+ parseHTML: (element) => {
2148
+ var _getStyleProperty;
2149
+ return (_getStyleProperty = getStyleProperty(element, "font-family")) !== null && _getStyleProperty !== void 0 ? _getStyleProperty : element.style.fontFamily;
2150
+ },
2151
+ renderHTML: (attributes) => {
2152
+ if (!attributes.fontFamily) return {};
2153
+ return { style: `font-family: ${attributes.fontFamily}` };
2210
2154
  }
2211
- }
2212
- ];
2155
+ } }
2156
+ }];
2213
2157
  },
2214
2158
  addCommands() {
2215
2159
  return {
@@ -2222,39 +2166,26 @@ var FontFamily = Extension3.create({
2222
2166
  };
2223
2167
  }
2224
2168
  });
2225
- var FontSize = Extension4.create({
2169
+ var FontSize = Extension.create({
2226
2170
  name: "fontSize",
2227
2171
  addOptions() {
2228
- return {
2229
- types: ["textStyle"]
2230
- };
2172
+ return { types: ["textStyle"] };
2231
2173
  },
2232
2174
  addGlobalAttributes() {
2233
- return [
2234
- {
2235
- types: this.options.types,
2236
- attributes: {
2237
- fontSize: {
2238
- default: null,
2239
- // Prefer the raw inline `style` attribute so the original format
2240
- // is preserved instead of the canonicalized value returned by
2241
- // `element.style.fontSize`.
2242
- parseHTML: (element) => {
2243
- var _a;
2244
- return (_a = getStyleProperty4(element, "font-size")) != null ? _a : element.style.fontSize;
2245
- },
2246
- renderHTML: (attributes) => {
2247
- if (!attributes.fontSize) {
2248
- return {};
2249
- }
2250
- return {
2251
- style: `font-size: ${attributes.fontSize}`
2252
- };
2253
- }
2254
- }
2175
+ return [{
2176
+ types: this.options.types,
2177
+ attributes: { fontSize: {
2178
+ default: null,
2179
+ parseHTML: (element) => {
2180
+ var _getStyleProperty;
2181
+ return (_getStyleProperty = getStyleProperty(element, "font-size")) !== null && _getStyleProperty !== void 0 ? _getStyleProperty : element.style.fontSize;
2182
+ },
2183
+ renderHTML: (attributes) => {
2184
+ if (!attributes.fontSize) return {};
2185
+ return { style: `font-size: ${attributes.fontSize}` };
2255
2186
  }
2256
- }
2257
- ];
2187
+ } }
2188
+ }];
2258
2189
  },
2259
2190
  addCommands() {
2260
2191
  return {
@@ -2267,39 +2198,26 @@ var FontSize = Extension4.create({
2267
2198
  };
2268
2199
  }
2269
2200
  });
2270
- var LineHeight = Extension5.create({
2201
+ var LineHeight = Extension.create({
2271
2202
  name: "lineHeight",
2272
2203
  addOptions() {
2273
- return {
2274
- types: ["textStyle"]
2275
- };
2204
+ return { types: ["textStyle"] };
2276
2205
  },
2277
2206
  addGlobalAttributes() {
2278
- return [
2279
- {
2280
- types: this.options.types,
2281
- attributes: {
2282
- lineHeight: {
2283
- default: null,
2284
- // Prefer the raw inline `style` attribute so the original format
2285
- // is preserved instead of the canonicalized value returned by
2286
- // `element.style.lineHeight`.
2287
- parseHTML: (element) => {
2288
- var _a;
2289
- return (_a = getStyleProperty5(element, "line-height")) != null ? _a : element.style.lineHeight;
2290
- },
2291
- renderHTML: (attributes) => {
2292
- if (!attributes.lineHeight) {
2293
- return {};
2294
- }
2295
- return {
2296
- style: `line-height: ${attributes.lineHeight}`
2297
- };
2298
- }
2299
- }
2207
+ return [{
2208
+ types: this.options.types,
2209
+ attributes: { lineHeight: {
2210
+ default: null,
2211
+ parseHTML: (element) => {
2212
+ var _getStyleProperty;
2213
+ return (_getStyleProperty = getStyleProperty(element, "line-height")) !== null && _getStyleProperty !== void 0 ? _getStyleProperty : element.style.lineHeight;
2214
+ },
2215
+ renderHTML: (attributes) => {
2216
+ if (!attributes.lineHeight) return {};
2217
+ return { style: `line-height: ${attributes.lineHeight}` };
2300
2218
  }
2301
- }
2302
- ];
2219
+ } }
2220
+ }];
2303
2221
  },
2304
2222
  addCommands() {
2305
2223
  return {
@@ -2312,28 +2230,16 @@ var LineHeight = Extension5.create({
2312
2230
  };
2313
2231
  }
2314
2232
  });
2315
- var TextStyleKit = Extension6.create({
2233
+ var TextStyleKit = Extension.create({
2316
2234
  name: "textStyleKit",
2317
2235
  addExtensions() {
2318
2236
  const extensions = [];
2319
- if (this.options.backgroundColor !== false) {
2320
- extensions.push(BackgroundColor.configure(this.options.backgroundColor));
2321
- }
2322
- if (this.options.color !== false) {
2323
- extensions.push(Color.configure(this.options.color));
2324
- }
2325
- if (this.options.fontFamily !== false) {
2326
- extensions.push(FontFamily.configure(this.options.fontFamily));
2327
- }
2328
- if (this.options.fontSize !== false) {
2329
- extensions.push(FontSize.configure(this.options.fontSize));
2330
- }
2331
- if (this.options.lineHeight !== false) {
2332
- extensions.push(LineHeight.configure(this.options.lineHeight));
2333
- }
2334
- if (this.options.textStyle !== false) {
2335
- extensions.push(TextStyle.configure(this.options.textStyle));
2336
- }
2237
+ if (this.options.backgroundColor !== false) extensions.push(BackgroundColor.configure(this.options.backgroundColor));
2238
+ if (this.options.color !== false) extensions.push(Color.configure(this.options.color));
2239
+ if (this.options.fontFamily !== false) extensions.push(FontFamily.configure(this.options.fontFamily));
2240
+ if (this.options.fontSize !== false) extensions.push(FontSize.configure(this.options.fontSize));
2241
+ if (this.options.lineHeight !== false) extensions.push(LineHeight.configure(this.options.lineHeight));
2242
+ if (this.options.textStyle !== false) extensions.push(TextStyle.configure(this.options.textStyle));
2337
2243
  return extensions;
2338
2244
  }
2339
2245
  });
@@ -2671,7 +2577,9 @@ var BaseLegacyFigure = Image2.extend({
2671
2577
  isolating: true,
2672
2578
  selectable: false,
2673
2579
  addOptions() {
2580
+ const parentOptions = this.parent?.() || {};
2674
2581
  return {
2582
+ ...parentOptions,
2675
2583
  HTMLAttributes: {},
2676
2584
  getImageById: void 0
2677
2585
  };