@innovastudio/contentbuilder 1.5.228 → 1.5.229
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/index.d.ts
CHANGED
|
@@ -646,10 +646,14 @@ interface ContentBuilderAddonApi {
|
|
|
646
646
|
unmarkRows(): void;
|
|
647
647
|
/** The current selection inside the content, or null. */
|
|
648
648
|
selection(): Range | null;
|
|
649
|
+
/** The block the user selected whole (a click or the arrow keys) that is not text: a plugin,
|
|
650
|
+
* a video, a spacer, a picture or drawing on its own line. Returns the column's child that
|
|
651
|
+
* holds it (what moving or removing acts on), or null. */
|
|
652
|
+
selectedBlock(): HTMLElement | null;
|
|
649
653
|
/** Whether the editor has an element settings window (the element tool's Settings). */
|
|
650
654
|
hasElementSettings(): boolean;
|
|
651
|
-
/** Open the element settings window for el (a line
|
|
652
|
-
* tool's Settings does. False when there is none. */
|
|
655
|
+
/** Open the element settings window for el (a line of text, a spacer, a picture's line; not
|
|
656
|
+
* a plugin, which has its own), as the element tool's Settings does. False when there is none. */
|
|
653
657
|
elementSettings(el: Element): boolean;
|
|
654
658
|
/** Format the selected text as the text toolbar does: 'bold', 'italic', 'underline',
|
|
655
659
|
* 'strikethrough', 'clean' (clear formatting; links stay), 'unlink', or 'link' (opens
|
package/package.json
CHANGED
|
@@ -598,7 +598,7 @@ const quickAddActions = builder => {
|
|
|
598
598
|
util.addContent(html, mode);
|
|
599
599
|
};
|
|
600
600
|
actions['spacer'] = mode => {
|
|
601
|
-
const html = '<div class="spacer height-
|
|
601
|
+
const html = '<div class="spacer height-40"></div>';
|
|
602
602
|
|
|
603
603
|
// util.addContent(html, mode, 'data-noedit');
|
|
604
604
|
util.addContent(html, mode);
|
|
@@ -18313,6 +18313,67 @@ class UndoRedo {
|
|
|
18313
18313
|
}
|
|
18314
18314
|
this.builder.opts.onRender();
|
|
18315
18315
|
}
|
|
18316
|
+
|
|
18317
|
+
/* The caret, kept with each step as a place that survives the content
|
|
18318
|
+
being written again: which editable area (its order on the page) and
|
|
18319
|
+
how many characters into it. Undo and Redo put it back, so the keyboard
|
|
18320
|
+
goes on where the change was (the content is replaced, which dropped
|
|
18321
|
+
the caret and the focus). */
|
|
18322
|
+
editableAreas() {
|
|
18323
|
+
return Array.from(this.builder.doc.querySelectorAll('.is-builder [contenteditable="true"]'));
|
|
18324
|
+
}
|
|
18325
|
+
caret() {
|
|
18326
|
+
const doc = this.builder.doc;
|
|
18327
|
+
const sel = doc.getSelection ? doc.getSelection() : null;
|
|
18328
|
+
if (!sel || !sel.rangeCount || !sel.focusNode) return null;
|
|
18329
|
+
const n = sel.focusNode;
|
|
18330
|
+
const el = n.nodeType === 1 ? n : n.parentElement;
|
|
18331
|
+
const area = el && el.closest('[contenteditable="true"]');
|
|
18332
|
+
const i = area ? this.editableAreas().indexOf(area) : -1;
|
|
18333
|
+
if (i < 0) return null;
|
|
18334
|
+
const r = doc.createRange();
|
|
18335
|
+
r.selectNodeContents(area);
|
|
18336
|
+
try {
|
|
18337
|
+
r.setEnd(sel.focusNode, sel.focusOffset);
|
|
18338
|
+
} catch (e) {
|
|
18339
|
+
return null;
|
|
18340
|
+
}
|
|
18341
|
+
return {
|
|
18342
|
+
area: i,
|
|
18343
|
+
offset: r.toString().length
|
|
18344
|
+
};
|
|
18345
|
+
}
|
|
18346
|
+
restoreCaret(mark) {
|
|
18347
|
+
if (!mark) return;
|
|
18348
|
+
const area = this.editableAreas()[mark.area];
|
|
18349
|
+
if (!area) return;
|
|
18350
|
+
const doc = this.builder.doc;
|
|
18351
|
+
const nav = this.builder.caretNav;
|
|
18352
|
+
if (nav) nav.focusPlace(area);else area.focus({
|
|
18353
|
+
preventScroll: true
|
|
18354
|
+
});
|
|
18355
|
+
let left = mark.offset,
|
|
18356
|
+
node = null,
|
|
18357
|
+
offset = 0;
|
|
18358
|
+
const walker = doc.createTreeWalker(area, NodeFilter.SHOW_TEXT);
|
|
18359
|
+
for (let t = walker.nextNode(); t; t = walker.nextNode()) {
|
|
18360
|
+
if (left <= t.length) {
|
|
18361
|
+
node = t;
|
|
18362
|
+
offset = left;
|
|
18363
|
+
break;
|
|
18364
|
+
}
|
|
18365
|
+
left -= t.length;
|
|
18366
|
+
}
|
|
18367
|
+
const r = doc.createRange();
|
|
18368
|
+
if (node) r.setStart(node, offset);else {
|
|
18369
|
+
r.selectNodeContents(area);
|
|
18370
|
+
r.collapse(false);
|
|
18371
|
+
}
|
|
18372
|
+
r.collapse(true);
|
|
18373
|
+
const sel = doc.getSelection();
|
|
18374
|
+
sel.removeAllRanges();
|
|
18375
|
+
sel.addRange(r);
|
|
18376
|
+
}
|
|
18316
18377
|
saveForUndo(checkLater) {
|
|
18317
18378
|
if (this.builder.onBeforeSaveForUndo) this.builder.onBeforeSaveForUndo();
|
|
18318
18379
|
if (this.builder.undoRedoStyles) {
|
|
@@ -18376,9 +18437,9 @@ class UndoRedo {
|
|
|
18376
18437
|
let styles = this.readStyles();
|
|
18377
18438
|
let html = this.readHtml();
|
|
18378
18439
|
let saves = ' ' + styles + '###$###' + html;
|
|
18379
|
-
this.undoList[120] = [saves,
|
|
18440
|
+
this.undoList[120] = [saves, this.caret()];
|
|
18380
18441
|
} else {
|
|
18381
|
-
this.undoList[120] = [this.readHtml(),
|
|
18442
|
+
this.undoList[120] = [this.readHtml(), this.caret()];
|
|
18382
18443
|
}
|
|
18383
18444
|
}
|
|
18384
18445
|
async doUndo() {
|
|
@@ -18389,6 +18450,11 @@ class UndoRedo {
|
|
|
18389
18450
|
// console.log('undo');
|
|
18390
18451
|
|
|
18391
18452
|
this.builder.undoRedoInProcess = true;
|
|
18453
|
+
|
|
18454
|
+
// The caret: where it is now (for Redo), and where it was when the step
|
|
18455
|
+
// being restored was saved (put back after it).
|
|
18456
|
+
const here = this.caret();
|
|
18457
|
+
const back = this.undoList[120][1];
|
|
18392
18458
|
this.undoList[99] = this.undoList[100];
|
|
18393
18459
|
this.undoList[100] = this.undoList[101];
|
|
18394
18460
|
this.undoList[101] = this.undoList[102];
|
|
@@ -18413,7 +18479,7 @@ class UndoRedo {
|
|
|
18413
18479
|
let styles = this.readStyles();
|
|
18414
18480
|
let html = this.readHtml();
|
|
18415
18481
|
let saves = ' ' + styles + '###$###' + html;
|
|
18416
|
-
this.undoList[119] = [saves,
|
|
18482
|
+
this.undoList[119] = [saves, here];
|
|
18417
18483
|
|
|
18418
18484
|
// -
|
|
18419
18485
|
|
|
@@ -18423,7 +18489,7 @@ class UndoRedo {
|
|
|
18423
18489
|
this.writeStyles(styles);
|
|
18424
18490
|
this.writeHtml(html);
|
|
18425
18491
|
} else {
|
|
18426
|
-
this.undoList[119] = [this.readHtml(),
|
|
18492
|
+
this.undoList[119] = [this.readHtml(), here];
|
|
18427
18493
|
let html = this.undoList[120][0];
|
|
18428
18494
|
this.writeHtml(html);
|
|
18429
18495
|
}
|
|
@@ -18477,6 +18543,7 @@ class UndoRedo {
|
|
|
18477
18543
|
this.builder.opts.onUndo();
|
|
18478
18544
|
}
|
|
18479
18545
|
this.builder.undoRedoInProcess = false;
|
|
18546
|
+
this.restoreCaret(back);
|
|
18480
18547
|
}
|
|
18481
18548
|
async doRedo() {
|
|
18482
18549
|
const dom = this.dom;
|
|
@@ -18486,6 +18553,11 @@ class UndoRedo {
|
|
|
18486
18553
|
// console.log('redo');
|
|
18487
18554
|
|
|
18488
18555
|
this.builder.undoRedoInProcess = true;
|
|
18556
|
+
|
|
18557
|
+
// The caret: where it is now (for Undo), and where it was when the step
|
|
18558
|
+
// being restored was left.
|
|
18559
|
+
const here = this.caret();
|
|
18560
|
+
const back = this.undoList[119][1];
|
|
18489
18561
|
this.undoList[141] = this.undoList[140];
|
|
18490
18562
|
this.undoList[140] = this.undoList[139];
|
|
18491
18563
|
this.undoList[139] = this.undoList[138];
|
|
@@ -18511,7 +18583,7 @@ class UndoRedo {
|
|
|
18511
18583
|
let styles = this.readStyles();
|
|
18512
18584
|
let html = this.readHtml();
|
|
18513
18585
|
let saves = ' ' + styles + '###$###' + html;
|
|
18514
|
-
this.undoList[120] = [saves,
|
|
18586
|
+
this.undoList[120] = [saves, here];
|
|
18515
18587
|
|
|
18516
18588
|
// -
|
|
18517
18589
|
|
|
@@ -18521,7 +18593,7 @@ class UndoRedo {
|
|
|
18521
18593
|
this.writeStyles(styles);
|
|
18522
18594
|
this.writeHtml(html);
|
|
18523
18595
|
} else {
|
|
18524
|
-
this.undoList[120] = [this.readHtml(),
|
|
18596
|
+
this.undoList[120] = [this.readHtml(), here];
|
|
18525
18597
|
let html = this.undoList[119][0];
|
|
18526
18598
|
this.writeHtml(html);
|
|
18527
18599
|
}
|
|
@@ -18575,6 +18647,7 @@ class UndoRedo {
|
|
|
18575
18647
|
this.builder.opts.onRedo();
|
|
18576
18648
|
}
|
|
18577
18649
|
this.builder.undoRedoInProcess = false;
|
|
18650
|
+
this.restoreCaret(back);
|
|
18578
18651
|
}
|
|
18579
18652
|
}
|
|
18580
18653
|
|
|
@@ -19959,6 +20032,9 @@ class CaretNav {
|
|
|
19959
20032
|
}
|
|
19960
20033
|
this.focusPlace(target);
|
|
19961
20034
|
if (how.x != null) this.caretAtX(target, how.x, how.last);else this.caretAtEdge(target, how.end);
|
|
20035
|
+
// Back in text from an object: what a click on the text shows (the
|
|
20036
|
+
// object's tool goes; ContentBox's panel turns back to the text's).
|
|
20037
|
+
if (from && this.builder.util && this.builder.util.clickElement) this.builder.util.clickElement(target);
|
|
19962
20038
|
if (this.builder.opts.onChange && how.changed) this.builder.opts.onChange();
|
|
19963
20039
|
}
|
|
19964
20040
|
|
|
@@ -19975,6 +20051,10 @@ class CaretNav {
|
|
|
19975
20051
|
this.tab(e);
|
|
19976
20052
|
return;
|
|
19977
20053
|
}
|
|
20054
|
+
if ((key === 'Backspace' || key === 'Delete') && !e.shiftKey) {
|
|
20055
|
+
if (!this.removeObject(e, key === 'Delete')) this.removeEmptyLine(e, key === 'Delete');
|
|
20056
|
+
return;
|
|
20057
|
+
}
|
|
19978
20058
|
if (e.shiftKey || !/^Arrow(Up|Down|Left|Right)$/.test(key)) return;
|
|
19979
20059
|
const range = this.range();
|
|
19980
20060
|
const forward0 = key === 'ArrowDown' || key === 'ArrowRight';
|
|
@@ -20019,6 +20099,70 @@ class CaretNav {
|
|
|
20019
20099
|
});
|
|
20020
20100
|
}
|
|
20021
20101
|
|
|
20102
|
+
/* Backspace or Delete with a locked block selected whole (a video, a
|
|
20103
|
+
plugin, a spacer): only the block goes, as the element tool's Delete
|
|
20104
|
+
does, and the caret goes to the text before it (Backspace) or after it
|
|
20105
|
+
(Delete). Left to the text engine, the selection around the block was
|
|
20106
|
+
deleted like text across two paragraphs, which joined them. */
|
|
20107
|
+
removeObject(e, forward) {
|
|
20108
|
+
const b = this.builder;
|
|
20109
|
+
const obj = this.selectedObject(this.range());
|
|
20110
|
+
if (!obj || isPicture(obj) || obj.getAttribute('contenteditable') !== 'false') return false;
|
|
20111
|
+
const col = this.columnOf(obj.parentElement);
|
|
20112
|
+
if (!col) return false;
|
|
20113
|
+
e.preventDefault();
|
|
20114
|
+
e.stopImmediatePropagation();
|
|
20115
|
+
const all = this.places();
|
|
20116
|
+
const i = all.indexOf(obj);
|
|
20117
|
+
const before = all[i - 1],
|
|
20118
|
+
after = all[i + 1];
|
|
20119
|
+
let target = forward ? after || before : before || after;
|
|
20120
|
+
if (target && this.isObject(target)) target = null;
|
|
20121
|
+
if (b.util && b.util.hideControls) b.util.hideControls();
|
|
20122
|
+
this.dropIcon();
|
|
20123
|
+
this.pending = null;
|
|
20124
|
+
b.uo.saveForUndo();
|
|
20125
|
+
const parent = obj.parentElement;
|
|
20126
|
+
obj.remove();
|
|
20127
|
+
// An emptied wrapper goes too; an emptied column keeps a line to type on.
|
|
20128
|
+
if (parent !== col && !parent.children.length && !hasText(parent)) parent.remove();
|
|
20129
|
+
if (!col.children.length) {
|
|
20130
|
+
const line = b.doc.createElement('p');
|
|
20131
|
+
line.appendChild(b.doc.createElement('br'));
|
|
20132
|
+
col.appendChild(line);
|
|
20133
|
+
target = line;
|
|
20134
|
+
}
|
|
20135
|
+
if (b.opts.onChange) b.opts.onChange();
|
|
20136
|
+
if (target && target.isConnected) {
|
|
20137
|
+
this.focusPlace(target);
|
|
20138
|
+
this.caretAtEdge(target, target === before);
|
|
20139
|
+
if (b.util && b.util.clickElement) b.util.clickElement(target);
|
|
20140
|
+
}
|
|
20141
|
+
return true;
|
|
20142
|
+
}
|
|
20143
|
+
|
|
20144
|
+
/* Backspace on an empty line just after an object (a video, a spacer, a
|
|
20145
|
+
plugin), or Delete on one just before it: the line goes and the object
|
|
20146
|
+
is selected, so the next Backspace / Delete removes it. The engine
|
|
20147
|
+
cannot join an empty line with a locked block, and did nothing. */
|
|
20148
|
+
removeEmptyLine(e, forward) {
|
|
20149
|
+
const b = this.builder;
|
|
20150
|
+
const range = this.range();
|
|
20151
|
+
if (!range || !range.collapsed) return;
|
|
20152
|
+
const place = this.placeOf(range.startContainer);
|
|
20153
|
+
if (!place || place.closest(OWN_NAV) || this.isObject(place) || hasText(place) || place.querySelector('img, svg, iframe, video')) return;
|
|
20154
|
+
const all = this.places();
|
|
20155
|
+
const i = all.indexOf(place);
|
|
20156
|
+
const obj = all[forward ? i + 1 : i - 1];
|
|
20157
|
+
if (!obj || !this.isObject(obj) || this.columnOf(obj.parentElement) !== this.columnOf(place)) return;
|
|
20158
|
+
e.preventDefault();
|
|
20159
|
+
e.stopImmediatePropagation();
|
|
20160
|
+
b.uo.saveForUndo();
|
|
20161
|
+
place.remove();
|
|
20162
|
+
if (b.opts.onChange) b.opts.onChange();
|
|
20163
|
+
this.selectObject(obj);
|
|
20164
|
+
}
|
|
20165
|
+
|
|
20022
20166
|
// In a list or a table, a move that leaves it (to the next block) is ours
|
|
20023
20167
|
// too: the browser left the caret between the blocks, in no text.
|
|
20024
20168
|
leavesGroup(place, key) {
|
|
@@ -99139,6 +99283,27 @@ class AddonHost {
|
|
|
99139
99283
|
const el = node.nodeType === 1 ? node : node.parentElement;
|
|
99140
99284
|
return el && el.closest(REGIONS) ? range : null;
|
|
99141
99285
|
},
|
|
99286
|
+
/** The block the user selected whole, by a click or the arrow keys, that is
|
|
99287
|
+
not text: a plugin, a video, a spacer, a picture or drawing on its own
|
|
99288
|
+
line. Returns the column's child that holds it (what moving or removing
|
|
99289
|
+
acts on), or null. */
|
|
99290
|
+
selectedBlock() {
|
|
99291
|
+
const nav = builder.caretNav;
|
|
99292
|
+
if (!nav) return null;
|
|
99293
|
+
const r = this.selection();
|
|
99294
|
+
let el = nav.selectedObject(r);
|
|
99295
|
+
if (!el) {
|
|
99296
|
+
const a = builder.activeElement;
|
|
99297
|
+
if (a && a.isConnected && (a.matches('[data-cb-type], [data-cb-code]') || nav.isObject(a))) {
|
|
99298
|
+
// A caret in the block's own text (a plugin's editable part) is text.
|
|
99299
|
+
const n = r && r.collapsed ? r.startContainer : null;
|
|
99300
|
+
const ne = n && (n.nodeType === 1 ? n : n.parentElement);
|
|
99301
|
+
if (!(ne && a.contains(ne) && ne.closest('[contenteditable="true"]') && a.contains(ne.closest('[contenteditable="true"]')))) el = a;
|
|
99302
|
+
}
|
|
99303
|
+
}
|
|
99304
|
+
if (!el || !el.closest(REGIONS)) return null;
|
|
99305
|
+
return nav.lineOf(el) || el;
|
|
99306
|
+
},
|
|
99142
99307
|
/** Whether the editor has an element settings window (the element
|
|
99143
99308
|
tool's Settings; the elementEditor option). */
|
|
99144
99309
|
hasElementSettings() {
|
|
@@ -99147,7 +99312,10 @@ class AddonHost {
|
|
|
99147
99312
|
/** Open the element settings window for el (a line in the content),
|
|
99148
99313
|
as the element tool's Settings does. False when there is none. */
|
|
99149
99314
|
elementSettings(el) {
|
|
99150
|
-
|
|
99315
|
+
// A line of text, or a block without text (a spacer, a picture's line);
|
|
99316
|
+
// not a plugin (it has its own settings) or a part of a locked block.
|
|
99317
|
+
const ok = el && el.isConnected && el.closest(REGIONS) && !el.closest('[data-cb-type], [data-cb-code], [data-html]') && !(el.parentElement && el.parentElement.closest('[contenteditable="false"]'));
|
|
99318
|
+
if (!this.hasElementSettings() || !ok) return false;
|
|
99151
99319
|
builder.activeElement = el;
|
|
99152
99320
|
builder.elmTool.elementPanel.showPanel();
|
|
99153
99321
|
return true;
|