vue-editify 0.2.13 → 0.2.14

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.
@@ -267,7 +267,7 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<{
267
267
  };
268
268
  $forceUpdate: () => void;
269
269
  $nextTick: typeof import('vue').nextTick;
270
- $watch<T extends string | ((...args: any) => any)>(source: T, cb: T extends (...args: any) => infer R ? (args_0: R, args_1: R) => any : (...args: any) => any, options?: import('vue').WatchOptions<boolean> | undefined): import('vue').WatchStopHandle;
270
+ $watch<T extends string | ((...args: any) => any)>(source: T, cb: T extends (...args: any) => infer R ? (args_0: R, args_1: R, args_2: (cleanupFn: () => void) => void) => any : (args_0: any, args_1: any, args_2: (cleanupFn: () => void) => void) => any, options?: import('vue').WatchOptions<boolean> | undefined): import('vue').WatchStopHandle;
271
271
  } & Omit<Readonly<import('vue').ExtractPropTypes<{
272
272
  modelValue: {
273
273
  type: BooleanConstructor;
@@ -241,7 +241,7 @@ declare const _default: import('vue').DefineComponent<{
241
241
  };
242
242
  $forceUpdate: () => void;
243
243
  $nextTick: typeof import('vue').nextTick;
244
- $watch<T extends string | ((...args: any) => any)>(source: T, cb: T extends (...args: any) => infer R ? (args_0: R, args_1: R) => any : (...args: any) => any, options?: import('vue').WatchOptions<boolean> | undefined): import('vue').WatchStopHandle;
244
+ $watch<T extends string | ((...args: any) => any)>(source: T, cb: T extends (...args: any) => infer R ? (args_0: R, args_1: R, args_2: (cleanupFn: () => void) => void) => any : (args_0: any, args_1: any, args_2: (cleanupFn: () => void) => void) => any, options?: import('vue').WatchOptions<boolean> | undefined): import('vue').WatchStopHandle;
245
245
  } & Omit<Readonly<import('vue').ExtractPropTypes<{
246
246
  modelValue: {
247
247
  type: BooleanConstructor;
@@ -151,8 +151,8 @@ declare const _default: import('vue').DefineComponent<{
151
151
  key: number;
152
152
  type: import('alex-editor').AlexElementType;
153
153
  parsedom: string | null;
154
- marks: import('alex-editor/lib/core/tool').ObjectType | null;
155
- styles: import('alex-editor/lib/core/tool').ObjectType | null;
154
+ marks: import('alex-editor').ObjectType | null;
155
+ styles: import('alex-editor').ObjectType | null;
156
156
  textContent: string | null;
157
157
  children: any[] | null;
158
158
  parent: any | null;
@@ -171,7 +171,7 @@ declare const _default: import('vue').DefineComponent<{
171
171
  getUneditableElement: () => AlexElement | null;
172
172
  isEqual: (element: AlexElement) => boolean;
173
173
  isContains: (element: AlexElement) => boolean;
174
- isOnlyHasBreak: () => boolean;
174
+ isOnlyHasBreak: () => boolean | 0;
175
175
  isPreStyle: () => boolean;
176
176
  hasMarks: () => boolean;
177
177
  hasStyles: () => boolean;
@@ -196,8 +196,8 @@ declare const _default: import('vue').DefineComponent<{
196
196
  key: number;
197
197
  type: import('alex-editor').AlexElementType;
198
198
  parsedom: string | null;
199
- marks: import('alex-editor/lib/core/tool').ObjectType | null;
200
- styles: import('alex-editor/lib/core/tool').ObjectType | null;
199
+ marks: import('alex-editor').ObjectType | null;
200
+ styles: import('alex-editor').ObjectType | null;
201
201
  textContent: string | null;
202
202
  children: any[] | null;
203
203
  parent: any | null;
@@ -216,7 +216,7 @@ declare const _default: import('vue').DefineComponent<{
216
216
  getUneditableElement: () => AlexElement | null;
217
217
  isEqual: (element: AlexElement) => boolean;
218
218
  isContains: (element: AlexElement) => boolean;
219
- isOnlyHasBreak: () => boolean;
219
+ isOnlyHasBreak: () => boolean | 0;
220
220
  isPreStyle: () => boolean;
221
221
  hasMarks: () => boolean;
222
222
  hasStyles: () => boolean;
@@ -245,8 +245,8 @@ declare const _default: import('vue').DefineComponent<{
245
245
  key: number;
246
246
  type: import('alex-editor').AlexElementType;
247
247
  parsedom: string | null;
248
- marks: import('alex-editor/lib/core/tool').ObjectType | null;
249
- styles: import('alex-editor/lib/core/tool').ObjectType | null;
248
+ marks: import('alex-editor').ObjectType | null;
249
+ styles: import('alex-editor').ObjectType | null;
250
250
  textContent: string | null;
251
251
  children: any[] | null;
252
252
  parent: any | null;
@@ -265,7 +265,7 @@ declare const _default: import('vue').DefineComponent<{
265
265
  getUneditableElement: () => AlexElement | null;
266
266
  isEqual: (element: AlexElement) => boolean;
267
267
  isContains: (element: AlexElement) => boolean;
268
- isOnlyHasBreak: () => boolean;
268
+ isOnlyHasBreak: () => boolean | 0;
269
269
  isPreStyle: () => boolean;
270
270
  hasMarks: () => boolean;
271
271
  hasStyles: () => boolean;
@@ -301,8 +301,8 @@ declare const _default: import('vue').DefineComponent<{
301
301
  key: number;
302
302
  type: import('alex-editor').AlexElementType;
303
303
  parsedom: string | null;
304
- marks: import('alex-editor/lib/core/tool').ObjectType | null;
305
- styles: import('alex-editor/lib/core/tool').ObjectType | null;
304
+ marks: import('alex-editor').ObjectType | null;
305
+ styles: import('alex-editor').ObjectType | null;
306
306
  textContent: string | null;
307
307
  children: any[] | null;
308
308
  parent: any | null;
@@ -321,7 +321,7 @@ declare const _default: import('vue').DefineComponent<{
321
321
  getUneditableElement: () => AlexElement | null;
322
322
  isEqual: (element: AlexElement) => boolean;
323
323
  isContains: (element: AlexElement) => boolean;
324
- isOnlyHasBreak: () => boolean;
324
+ isOnlyHasBreak: () => boolean | 0;
325
325
  isPreStyle: () => boolean;
326
326
  hasMarks: () => boolean;
327
327
  hasStyles: () => boolean;
@@ -346,8 +346,8 @@ declare const _default: import('vue').DefineComponent<{
346
346
  key: number;
347
347
  type: import('alex-editor').AlexElementType;
348
348
  parsedom: string | null;
349
- marks: import('alex-editor/lib/core/tool').ObjectType | null;
350
- styles: import('alex-editor/lib/core/tool').ObjectType | null;
349
+ marks: import('alex-editor').ObjectType | null;
350
+ styles: import('alex-editor').ObjectType | null;
351
351
  textContent: string | null;
352
352
  children: any[] | null;
353
353
  parent: any | null;
@@ -366,7 +366,7 @@ declare const _default: import('vue').DefineComponent<{
366
366
  getUneditableElement: () => AlexElement | null;
367
367
  isEqual: (element: AlexElement) => boolean;
368
368
  isContains: (element: AlexElement) => boolean;
369
- isOnlyHasBreak: () => boolean;
369
+ isOnlyHasBreak: () => boolean | 0;
370
370
  isPreStyle: () => boolean;
371
371
  hasMarks: () => boolean;
372
372
  hasStyles: () => boolean;
@@ -395,8 +395,8 @@ declare const _default: import('vue').DefineComponent<{
395
395
  key: number;
396
396
  type: import('alex-editor').AlexElementType;
397
397
  parsedom: string | null;
398
- marks: import('alex-editor/lib/core/tool').ObjectType | null;
399
- styles: import('alex-editor/lib/core/tool').ObjectType | null;
398
+ marks: import('alex-editor').ObjectType | null;
399
+ styles: import('alex-editor').ObjectType | null;
400
400
  textContent: string | null;
401
401
  children: any[] | null;
402
402
  parent: any | null;
@@ -415,7 +415,7 @@ declare const _default: import('vue').DefineComponent<{
415
415
  getUneditableElement: () => AlexElement | null;
416
416
  isEqual: (element: AlexElement) => boolean;
417
417
  isContains: (element: AlexElement) => boolean;
418
- isOnlyHasBreak: () => boolean;
418
+ isOnlyHasBreak: () => boolean | 0;
419
419
  isPreStyle: () => boolean;
420
420
  hasMarks: () => boolean;
421
421
  hasStyles: () => boolean;
@@ -441,8 +441,50 @@ declare const _default: import('vue').DefineComponent<{
441
441
  };
442
442
  } | null;
443
443
  __guid: number;
444
- __events: import('alex-editor/lib/core/tool').ObjectType;
445
- __firstRender: boolean;
444
+ __events: import('alex-editor').ObjectType;
445
+ __oldStack: {
446
+ key: number;
447
+ type: import('alex-editor').AlexElementType;
448
+ parsedom: string | null;
449
+ marks: import('alex-editor').ObjectType | null;
450
+ styles: import('alex-editor').ObjectType | null;
451
+ textContent: string | null;
452
+ children: any[] | null;
453
+ parent: any | null;
454
+ behavior: "default" | "block";
455
+ namespace: string | null;
456
+ locked: boolean;
457
+ elm: HTMLElement | null;
458
+ isBlock: () => boolean;
459
+ isInblock: () => boolean;
460
+ isInline: () => boolean;
461
+ isClosed: () => boolean;
462
+ isText: () => boolean;
463
+ isBreak: () => boolean;
464
+ isEmpty: () => boolean;
465
+ isSpaceText: () => boolean;
466
+ getUneditableElement: () => AlexElement | null;
467
+ isEqual: (element: AlexElement) => boolean;
468
+ isContains: (element: AlexElement) => boolean;
469
+ isOnlyHasBreak: () => boolean | 0;
470
+ isPreStyle: () => boolean;
471
+ hasMarks: () => boolean;
472
+ hasStyles: () => boolean;
473
+ hasChildren: () => boolean;
474
+ hasContains: (element: AlexElement) => boolean;
475
+ clone: (deep?: boolean | undefined) => AlexElement;
476
+ convertToBlock: () => void;
477
+ toEmpty: () => void;
478
+ getBlock: () => AlexElement;
479
+ getInblock: () => AlexElement | null;
480
+ getInline: () => AlexElement | null;
481
+ isEqualStyles: (element: AlexElement) => boolean;
482
+ isEqualMarks: (element: AlexElement) => boolean;
483
+ isFirst: (element: AlexElement) => boolean;
484
+ isLast: (element: AlexElement) => boolean;
485
+ __render: () => void;
486
+ __fullClone: () => AlexElement;
487
+ }[];
446
488
  __isInputChinese: boolean;
447
489
  __innerSelectionChange: boolean;
448
490
  __chineseInputTimer: any;
@@ -483,8 +525,8 @@ declare const _default: import('vue').DefineComponent<{
483
525
  key: number;
484
526
  type: import('alex-editor').AlexElementType;
485
527
  parsedom: string | null;
486
- marks: import('alex-editor/lib/core/tool').ObjectType | null;
487
- styles: import('alex-editor/lib/core/tool').ObjectType | null;
528
+ marks: import('alex-editor').ObjectType | null;
529
+ styles: import('alex-editor').ObjectType | null;
488
530
  textContent: string | null;
489
531
  children: any[] | null;
490
532
  parent: any | null;
@@ -503,7 +545,7 @@ declare const _default: import('vue').DefineComponent<{
503
545
  getUneditableElement: () => AlexElement | null;
504
546
  isEqual: (element: AlexElement) => boolean;
505
547
  isContains: (element: AlexElement) => boolean;
506
- isOnlyHasBreak: () => boolean;
548
+ isOnlyHasBreak: () => boolean | 0;
507
549
  isPreStyle: () => boolean;
508
550
  hasMarks: () => boolean;
509
551
  hasStyles: () => boolean;
@@ -529,8 +571,8 @@ declare const _default: import('vue').DefineComponent<{
529
571
  key: number;
530
572
  type: import('alex-editor').AlexElementType;
531
573
  parsedom: string | null;
532
- marks: import('alex-editor/lib/core/tool').ObjectType | null;
533
- styles: import('alex-editor/lib/core/tool').ObjectType | null;
574
+ marks: import('alex-editor').ObjectType | null;
575
+ styles: import('alex-editor').ObjectType | null;
534
576
  textContent: string | null;
535
577
  children: any[] | null;
536
578
  parent: any | null;
@@ -549,7 +591,7 @@ declare const _default: import('vue').DefineComponent<{
549
591
  getUneditableElement: () => AlexElement | null;
550
592
  isEqual: (element: AlexElement) => boolean;
551
593
  isContains: (element: AlexElement) => boolean;
552
- isOnlyHasBreak: () => boolean;
594
+ isOnlyHasBreak: () => boolean | 0;
553
595
  isPreStyle: () => boolean;
554
596
  hasMarks: () => boolean;
555
597
  hasStyles: () => boolean;
package/lib/editify.es.js CHANGED
@@ -736,18 +736,18 @@ const element$1 = {
736
736
  },
737
737
  /**
738
738
  * 字符串转dom
739
- * @param {Object} str
739
+ * @param {Object} html
740
740
  */
741
- string2dom(str, parentTag) {
742
- if (!str || typeof str != "string") {
741
+ string2dom(html) {
742
+ if (!html || typeof html != "string") {
743
743
  throw new TypeError("The argument must be an HTML string");
744
744
  }
745
- let parentEle = document.createElement(parentTag || "div");
746
- parentEle.innerHTML = str;
747
- if (parentEle.children.length == 1) {
748
- return parentEle.children[0];
745
+ const template = document.createElement("template");
746
+ template.innerHTML = html;
747
+ if (template.content.children.length == 1) {
748
+ return template.content.children[0];
749
749
  } else {
750
- return Array.from(parentEle.children);
750
+ return Array.from(template.content.children);
751
751
  }
752
752
  }
753
753
  };
@@ -14973,18 +14973,18 @@ const element = {
14973
14973
  },
14974
14974
  /**
14975
14975
  * 字符串转dom
14976
- * @param {Object} str
14976
+ * @param {Object} html
14977
14977
  */
14978
- string2dom(str, parentTag) {
14979
- if (!str || typeof str != "string") {
14978
+ string2dom(html) {
14979
+ if (!html || typeof html != "string") {
14980
14980
  throw new TypeError("The argument must be an HTML string");
14981
14981
  }
14982
- let parentEle = document.createElement(parentTag || "div");
14983
- parentEle.innerHTML = str;
14984
- if (parentEle.children.length == 1) {
14985
- return parentEle.children[0];
14982
+ const template = document.createElement("template");
14983
+ template.innerHTML = html;
14984
+ if (template.content.children.length == 1) {
14985
+ return template.content.children[0];
14986
14986
  } else {
14987
- return Array.from(parentEle.children);
14987
+ return Array.from(template.content.children);
14988
14988
  }
14989
14989
  }
14990
14990
  };
@@ -15891,10 +15891,7 @@ const _AlexElement = class _AlexElement2 {
15891
15891
  if (!this.hasChildren()) {
15892
15892
  return true;
15893
15893
  }
15894
- const allEmpty = this.children.every((el) => {
15895
- return el.isEmpty();
15896
- });
15897
- return allEmpty;
15894
+ return this.children.every((el) => el.isEmpty());
15898
15895
  }
15899
15896
  return false;
15900
15897
  }
@@ -15903,7 +15900,7 @@ const _AlexElement = class _AlexElement2 {
15903
15900
  * @returns
15904
15901
  */
15905
15902
  isSpaceText() {
15906
- return this.isText() && !this.isEmpty() && isSpaceText(this.textContent);
15903
+ return !this.isEmpty() && this.isText() && isSpaceText(this.textContent);
15907
15904
  }
15908
15905
  /**
15909
15906
  * 获取不可编辑的元素,如果是null,说明元素是可编辑的
@@ -15949,13 +15946,8 @@ const _AlexElement = class _AlexElement2 {
15949
15946
  */
15950
15947
  isOnlyHasBreak() {
15951
15948
  if (this.hasChildren()) {
15952
- const hasBreak = this.children.some((item) => {
15953
- return item.isBreak();
15954
- });
15955
- const isAll = this.children.every((item) => {
15956
- return item.isBreak() || item.isEmpty();
15957
- });
15958
- return hasBreak && isAll;
15949
+ const elements = this.children.filter((el) => !el.isEmpty());
15950
+ return elements.length && elements.every((el) => el.isBreak());
15959
15951
  }
15960
15952
  return false;
15961
15953
  }
@@ -15964,25 +15956,14 @@ const _AlexElement = class _AlexElement2 {
15964
15956
  * @returns
15965
15957
  */
15966
15958
  isPreStyle() {
15967
- const block = this.getBlock();
15968
- const inblock = this.getInblock();
15969
- if (inblock) {
15970
- if (inblock.parsedom == "pre") {
15971
- return true;
15972
- }
15973
- if (inblock.hasStyles() && (inblock.styles["white-space"] == "pre" || inblock.styles["white-space"] == "pre-wrap")) {
15974
- return true;
15975
- }
15976
- return inblock.parent.isPreStyle();
15977
- } else {
15978
- if (block.parsedom == "pre") {
15979
- return true;
15980
- }
15981
- if (block.hasStyles() && (block.styles["white-space"] == "pre" || block.styles["white-space"] == "pre-wrap")) {
15982
- return true;
15983
- }
15984
- return false;
15959
+ const block = this.getInblock() || this.getBlock();
15960
+ if (block.parsedom == "pre") {
15961
+ return true;
15962
+ }
15963
+ if (block.hasStyles() && ["pre", "pre-wrap"].includes(block.styles["white-space"])) {
15964
+ return true;
15985
15965
  }
15966
+ return block.parent ? block.parent.isPreStyle() : false;
15986
15967
  }
15987
15968
  /**
15988
15969
  * 是否含有标记
@@ -16185,9 +16166,7 @@ const _AlexElement = class _AlexElement2 {
16185
16166
  return false;
16186
16167
  }
16187
16168
  if (element2.isContains(this)) {
16188
- const elements = _AlexElement2.flatElements(element2.children).filter((el) => {
16189
- return el.isText() || el.isClosed();
16190
- });
16169
+ const elements = _AlexElement2.flatElements(element2.children).filter((el) => el.isText() || el.isClosed());
16191
16170
  return this.isEqual(elements[0]);
16192
16171
  }
16193
16172
  return false;
@@ -16205,11 +16184,8 @@ const _AlexElement = class _AlexElement2 {
16205
16184
  return false;
16206
16185
  }
16207
16186
  if (element2.isContains(this)) {
16208
- const elements = _AlexElement2.flatElements(element2.children).filter((el) => {
16209
- return el.isText() || el.isClosed();
16210
- });
16211
- const length = elements.length;
16212
- return this.isEqual(elements[length - 1]);
16187
+ const elements = _AlexElement2.flatElements(element2.children).filter((el) => el.isText() || el.isClosed());
16188
+ return this.isEqual(elements[elements.length - 1]);
16213
16189
  }
16214
16190
  return false;
16215
16191
  }
@@ -17496,7 +17472,7 @@ class AlexEditor {
17496
17472
  __publicField(this, "range", null);
17497
17473
  __publicField(this, "__guid", createGuid());
17498
17474
  __publicField(this, "__events", {});
17499
- __publicField(this, "__firstRender", true);
17475
+ __publicField(this, "__oldStack", []);
17500
17476
  __publicField(this, "__isInputChinese", false);
17501
17477
  __publicField(this, "__innerSelectionChange", false);
17502
17478
  __publicField(this, "__chineseInputTimer", null);
@@ -18169,26 +18145,25 @@ class AlexEditor {
18169
18145
  */
18170
18146
  domRender(unPushHistory = false) {
18171
18147
  this.emit("beforeRender");
18148
+ const firstRender = !this.__oldStack.length;
18149
+ const oldValue = this.value;
18150
+ this.$el.innerHTML = "";
18172
18151
  const fragment = document.createDocumentFragment();
18173
18152
  this.stack.forEach((element2) => {
18174
18153
  element2.__render();
18175
18154
  fragment.appendChild(element2.elm);
18176
18155
  });
18177
- this.$el.innerHTML = "";
18178
18156
  this.$el.appendChild(fragment);
18179
- const oldValue = this.value;
18180
18157
  this.value = this.$el.innerHTML;
18181
- if (this.__firstRender || oldValue != this.value) {
18182
- if (!this.__firstRender) {
18158
+ this.__oldStack = this.stack.map((ele) => ele.__fullClone());
18159
+ if (firstRender || oldValue != this.value) {
18160
+ if (!firstRender) {
18183
18161
  this.emit("change", this.value, oldValue);
18184
18162
  }
18185
18163
  if (!unPushHistory) {
18186
18164
  this.history.push(this.stack, this.range);
18187
18165
  }
18188
18166
  }
18189
- if (this.__firstRender) {
18190
- this.__firstRender = false;
18191
- }
18192
18167
  this.emit("afterRender");
18193
18168
  }
18194
18169
  /**
@@ -18198,8 +18173,7 @@ class AlexEditor {
18198
18173
  rangeRender() {
18199
18174
  return new Promise((resolve) => {
18200
18175
  if (this.disabled) {
18201
- resolve();
18202
- return;
18176
+ return resolve();
18203
18177
  }
18204
18178
  if (this.range) {
18205
18179
  const handler = (point) => {
@@ -18250,10 +18224,10 @@ class AlexEditor {
18250
18224
  if (!html) {
18251
18225
  throw new Error("You need to give an html content to convert");
18252
18226
  }
18253
- const node = document.createElement("div");
18254
- node.innerHTML = html;
18227
+ const template = document.createElement("template");
18228
+ template.innerHTML = html;
18255
18229
  let elements = [];
18256
- Array.from(node.childNodes).forEach((el) => {
18230
+ template.content.childNodes.forEach((el) => {
18257
18231
  if (el.nodeType == 1 || el.nodeType == 3) {
18258
18232
  const element2 = this.parseNode(el);
18259
18233
  elements.push(element2);
@@ -18911,7 +18885,7 @@ class AlexEditor {
18911
18885
  event.off(this.$el, "beforeinput.alex_editor compositionstart.alex_editor compositionupdate.alex_editor compositionend.alex_editor keydown.alex_editor cut.alex_editor paste.alex_editor copy.alex_editor dragstart.alex_editor drop.alex_editor focus.alex_editor blur.alex_editor");
18912
18886
  }
18913
18887
  }
18914
- const version$1 = "1.4.14";
18888
+ const version$1 = "1.4.20";
18915
18889
  console.log(`%c alex-editor %c v${version$1} `, "padding: 2px 1px; border-radius: 3px 0 0 3px; color: #fff; background: #606060; font-weight: bold;", "padding: 2px 1px; border-radius: 0 3px 3px 0; color: #fff; background: #42c02e; font-weight: bold;");
18916
18890
  const setTableCellMerged = (cell) => {
18917
18891
  const breakEl = AlexElement.create({
@@ -42737,7 +42711,7 @@ const Editify = withInstall(editify);
42737
42711
  const install = (app) => {
42738
42712
  app.component(Editify.name, Editify);
42739
42713
  };
42740
- const version = "0.2.13";
42714
+ const version = "0.2.14";
42741
42715
  console.log(`%c vue-editify %c v${version} `, "padding: 2px 1px; border-radius: 3px 0 0 3px; color: #fff; background: #606060; font-weight: bold;", "padding: 2px 1px; border-radius: 0 3px 3px 0; color: #fff; background: #42c02e; font-weight: bold;");
42742
42716
  export {
42743
42717
  AlexElement,