@innovastudio/contentbuilder 1.5.228 → 1.5.230
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.
|
@@ -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);
|
|
@@ -961,40 +961,40 @@ const quickAddActions = builder => {
|
|
|
961
961
|
}
|
|
962
962
|
util.addContent(html, mode);
|
|
963
963
|
};
|
|
964
|
-
|
|
965
|
-
|
|
964
|
+
|
|
965
|
+
// src: the video's address (an add-on's own panel); the sample without it.
|
|
966
|
+
actions['video'] = (mode, src) => {
|
|
967
|
+
const videoSrc = src ? String(src).replace(/"/g, '"') : builder.opts.snippetSampleVideo ? builder.opts.snippetSampleVideo : `${builder.opts.snippetPath}example.mp4`;
|
|
968
|
+
// A given file may be WebM or MOV: no type, so the browser reads the file itself.
|
|
969
|
+
const videoType = src ? '' : ' type="video/mp4"';
|
|
966
970
|
let html = '';
|
|
967
971
|
const runtime = builder.win.builderRuntime;
|
|
968
972
|
if (runtime) {
|
|
969
973
|
html = `<div data-cb-type="video-embed" data-cb-autoplay="true" data-cb-loop="true" data-cb-muted="false" data-cb-controls="true" data-cb-plays-inline="true" data-cb-aspect-ratio="16/9" data-cb-object-fit="cover" data-cb-border-radius="8" style="--border-radius: 8px; --ve-controls-alpha: 0.50;" data-cb-hover-shadow="true" data-cb-controls-overlay="50">
|
|
970
974
|
<div class="video-wrapper">
|
|
971
975
|
<video>
|
|
972
|
-
<source src="${videoSrc}"
|
|
976
|
+
<source src="${videoSrc}"${videoType}>
|
|
973
977
|
Your browser does not support the video tag.
|
|
974
978
|
</video>
|
|
975
979
|
</div>
|
|
976
980
|
</div>`;
|
|
977
981
|
} else {
|
|
978
982
|
html = `<video style="width: 100%;" loop="" playsinline="" muted="" autoplay="">
|
|
979
|
-
<source src="${videoSrc}"
|
|
983
|
+
<source src="${videoSrc}"${videoType}></video>`;
|
|
980
984
|
}
|
|
981
985
|
util.addContent(html, mode);
|
|
982
986
|
};
|
|
983
|
-
|
|
987
|
+
|
|
988
|
+
// src: the sound file's address (an add-on's own panel); the sample without it.
|
|
989
|
+
actions['audio'] = (mode, src) => {
|
|
990
|
+
const audioSrc = src ? String(src).replace(/"/g, '"') : builder.opts.snippetSampleAudio || `${builder.opts.snippetPath}example.mp3`;
|
|
991
|
+
const audioType = src ? '' : ' type="audio/mpeg"';
|
|
984
992
|
let html = `<div style="display:flex;width:100%;position:relative;margin:15px 0;background:transparent;">
|
|
985
993
|
<audio controls="" style="width:100%">
|
|
986
|
-
<source src="${
|
|
994
|
+
<source src="${audioSrc}"${audioType}>
|
|
987
995
|
Your browser does not support the audio element.
|
|
988
996
|
</audio>
|
|
989
997
|
</div>`;
|
|
990
|
-
if (builder.opts.snippetSampleAudio) {
|
|
991
|
-
html = `<div style="display:flex;width:100%;position:relative;margin:15px 0;background:transparent;">
|
|
992
|
-
<audio controls="" style="width:100%">
|
|
993
|
-
<source src="${builder.opts.snippetSampleAudio}" type="audio/mpeg">
|
|
994
|
-
Your browser does not support the audio element.
|
|
995
|
-
</audio>
|
|
996
|
-
</div>`;
|
|
997
|
-
}
|
|
998
998
|
util.addContent(html, mode);
|
|
999
999
|
};
|
|
1000
1000
|
const snippets = new Snippets(builder);
|
|
@@ -5623,6 +5623,13 @@ const BUTTON_PRESETS = [
|
|
|
5623
5623
|
* kept because it is the convention even though macOS takes Option+F10 unless the
|
|
5624
5624
|
* user remaps their function keys.
|
|
5625
5625
|
*
|
|
5626
|
+
* F6 moves between the page's regions, as in Google Docs, Word or a browser: from
|
|
5627
|
+
* the content (or its tools) to the first region (ContentBuilder: the snippets
|
|
5628
|
+
* panel; ContentBox names its own: the panel on the right, the top bar, the side
|
|
5629
|
+
* bar), on to the next, and past the
|
|
5630
|
+
* last back to the caret. Shift+F6 goes the other way. Escape in a region, when
|
|
5631
|
+
* nothing in it took the key, is back to the caret too.
|
|
5632
|
+
*
|
|
5626
5633
|
* Within a strip the arrow keys move along it, Home and End jump to its ends, and
|
|
5627
5634
|
* exactly one button carries the tab stop ("roving tabindex"), the standard toolbar
|
|
5628
5635
|
* pattern. That stop exists only while focus is inside, so the page's tab order
|
|
@@ -5634,7 +5641,8 @@ const BUTTON_PRESETS = [
|
|
|
5634
5641
|
const ARROW_KEYS = ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Home', 'End'];
|
|
5635
5642
|
|
|
5636
5643
|
/** Places that take the focus on purpose, and should keep it. */
|
|
5637
|
-
|
|
5644
|
+
// A window an add-on opened (its popover, a full-page board) keeps the focus too.
|
|
5645
|
+
const CLAIMS_FOCUS = '[data-cb-panel], .is-pop, .is-rte-pop, .is-modal, .is-tool, .is-rte-tool, .is-elementrte-tool, .is-side, [role="dialog"], [aria-modal="true"]';
|
|
5638
5646
|
|
|
5639
5647
|
/**
|
|
5640
5648
|
* Things a mouse user selects by clicking the thing itself rather than the text
|
|
@@ -5708,6 +5716,80 @@ class ToolbarKeys {
|
|
|
5708
5716
|
// column strips are not here: there is a pair per row, so they are added to
|
|
5709
5717
|
// the walk from the row in hand.
|
|
5710
5718
|
this.strips = [];
|
|
5719
|
+
|
|
5720
|
+
// F6 and Escape in the page's regions (the content and its strips catch
|
|
5721
|
+
// F6 themselves: handleCellKeydown, _onKeydown).
|
|
5722
|
+
this._onRegionKey = e => this.regionKey(e);
|
|
5723
|
+
document.addEventListener('keydown', this._onRegionKey, true);
|
|
5724
|
+
document.addEventListener('keydown', this._onRegionKey);
|
|
5725
|
+
}
|
|
5726
|
+
destroy() {
|
|
5727
|
+
document.removeEventListener('keydown', this._onRegionKey, true);
|
|
5728
|
+
document.removeEventListener('keydown', this._onRegionKey);
|
|
5729
|
+
}
|
|
5730
|
+
|
|
5731
|
+
/** F6 or Shift+F6, nothing else held. */
|
|
5732
|
+
isRegionKey(e) {
|
|
5733
|
+
return e.key === 'F6' && !e.ctrlKey && !e.metaKey && !e.altKey;
|
|
5734
|
+
}
|
|
5735
|
+
|
|
5736
|
+
/** The regions F6 steps through, in order: the host names them (builder.keyRegions), only those on screen with something to use count. */
|
|
5737
|
+
regions() {
|
|
5738
|
+
// ContentBuilder's own: the snippets panel when it is docked open.
|
|
5739
|
+
const own = () => [this.builder.builderStuff && this.builder.builderStuff.querySelector('.is-modal.snippetwindow.active')];
|
|
5740
|
+
const list = typeof this.builder.keyRegions === 'function' ? this.builder.keyRegions() : own();
|
|
5741
|
+
// A docked region is position: fixed, which has no offsetParent: on screen is having a box.
|
|
5742
|
+
return list.filter(el => el && el.isConnected && el.getClientRects().length && getComputedStyle(el).visibility !== 'hidden' && controls(el).length);
|
|
5743
|
+
}
|
|
5744
|
+
|
|
5745
|
+
/**
|
|
5746
|
+
* F6 from somewhere (the content, a strip, a region): the next region, or past
|
|
5747
|
+
* the last one back to the caret. `col` is the column when it is pressed in
|
|
5748
|
+
* the content: where the caret goes back to.
|
|
5749
|
+
*/
|
|
5750
|
+
stepRegion(from, forward, col = null) {
|
|
5751
|
+
const list = this.regions();
|
|
5752
|
+
if (!list.length) return false;
|
|
5753
|
+
const at = list.findIndex(r => r.contains(from));
|
|
5754
|
+
let next;
|
|
5755
|
+
if (at === -1) {
|
|
5756
|
+
// Leaving the content: remember where, as Escape does.
|
|
5757
|
+
if (col) {
|
|
5758
|
+
this.origin = col;
|
|
5759
|
+
this.builder.util.saveSelection();
|
|
5760
|
+
this.originObject = this.activeDrawing(col) || this.clickedSpacer(col);
|
|
5761
|
+
this.originField = null;
|
|
5762
|
+
}
|
|
5763
|
+
next = forward ? 0 : list.length - 1;
|
|
5764
|
+
} else {
|
|
5765
|
+
next = at + (forward ? 1 : -1);
|
|
5766
|
+
if (next < 0 || next >= list.length) return this.exit();
|
|
5767
|
+
}
|
|
5768
|
+
// Where in the region: the host may say (the panel's first setting rather than its Close), else its first control.
|
|
5769
|
+
const start = typeof this.builder.keyRegionStart === 'function' ? this.builder.keyRegionStart(list[next]) : null;
|
|
5770
|
+
const stop = start || controls(list[next]).find(el => !el.matches('.is-modal-close, .btn-close')) || controls(list[next])[0];
|
|
5771
|
+
if (!stop) return false;
|
|
5772
|
+
stop.focus();
|
|
5773
|
+
return true;
|
|
5774
|
+
}
|
|
5775
|
+
|
|
5776
|
+
/** The page-level keys in a region: F6 moves on, Escape nobody took goes back to the caret. */
|
|
5777
|
+
regionKey(e) {
|
|
5778
|
+
const list = this.regions();
|
|
5779
|
+
if (!list.length || !list.some(r => r.contains(e.target))) return;
|
|
5780
|
+
if (e.eventPhase === Event.CAPTURING_PHASE) {
|
|
5781
|
+
if (!this.isRegionKey(e)) return;
|
|
5782
|
+
if (this.stepRegion(e.target, !e.shiftKey)) {
|
|
5783
|
+
e.preventDefault();
|
|
5784
|
+
e.stopPropagation();
|
|
5785
|
+
}
|
|
5786
|
+
return;
|
|
5787
|
+
}
|
|
5788
|
+
// Bubbling: Escape that closed nothing (a menu, a dialog take it first).
|
|
5789
|
+
if (e.key !== 'Escape' || e.defaultPrevented || e.shiftKey) return;
|
|
5790
|
+
const inner = e.target.closest && e.target.closest('.is-pop, .is-rte-pop, .is-modal, [role="dialog"], [role="menu"], [role="listbox"]');
|
|
5791
|
+
if (inner && !list.includes(inner)) return;
|
|
5792
|
+
if (this.exit()) e.preventDefault();
|
|
5711
5793
|
}
|
|
5712
5794
|
|
|
5713
5795
|
/** The content columns of a row, in order. */
|
|
@@ -5961,14 +6043,61 @@ class ToolbarKeys {
|
|
|
5961
6043
|
* or a click (activeIcon), or a selection that is exactly one picture,
|
|
5962
6044
|
* video, table, plugin or locked block?
|
|
5963
6045
|
*/
|
|
6046
|
+
/** The add-on block or drawing the drawing tool is on, in this column. */
|
|
6047
|
+
activeDrawing(col) {
|
|
6048
|
+
const el = this.builder.activeSvg;
|
|
6049
|
+
return el && el.isConnected && col.contains(el) && (el.matches('[data-cb-object]') || el.nodeName.toLowerCase() === 'svg') ? el : null;
|
|
6050
|
+
}
|
|
6051
|
+
|
|
6052
|
+
/** The plugin block holding the caret or the focused field, in this column. */
|
|
6053
|
+
pluginAtCaret(col) {
|
|
6054
|
+
const doc = this.builder.doc;
|
|
6055
|
+
let n = doc.activeElement && doc.activeElement !== col && col.contains(doc.activeElement) ? doc.activeElement : null;
|
|
6056
|
+
if (!n) {
|
|
6057
|
+
const sel = this.builder.win.getSelection();
|
|
6058
|
+
n = sel && sel.rangeCount ? sel.anchorNode : null;
|
|
6059
|
+
if (n && n.nodeType !== 1) n = n.parentElement;
|
|
6060
|
+
}
|
|
6061
|
+
const plugin = n && n.closest ? n.closest('[data-cb-type]') : null;
|
|
6062
|
+
return plugin && col.contains(plugin) ? plugin : null;
|
|
6063
|
+
}
|
|
6064
|
+
|
|
6065
|
+
/** A spacer a click selected (it clears the text selection), in this column. */
|
|
6066
|
+
clickedSpacer(col) {
|
|
6067
|
+
const el = this.builder.activeSpacer;
|
|
6068
|
+
const sel = this.builder.win.getSelection();
|
|
6069
|
+
if (!el || !el.isConnected || !col.contains(el)) return null;
|
|
6070
|
+
if (sel && sel.rangeCount && !sel.isCollapsed) return null; // something else is selected since
|
|
6071
|
+
// Still the one clicked: its tool shows (a click in the text hides it).
|
|
6072
|
+
const tool = this.builder.doc.querySelector('.is-spacer-tool');
|
|
6073
|
+
if (!tool || tool.getClientRects().length === 0 || getComputedStyle(tool).display === 'none') return null;
|
|
6074
|
+
return el;
|
|
6075
|
+
}
|
|
6076
|
+
|
|
6077
|
+
/** The element selected whole in this column, if any (see objectSelected). */
|
|
6078
|
+
selectedElement(col) {
|
|
6079
|
+
const drawing = this.activeDrawing(col);
|
|
6080
|
+
if (drawing) return drawing;
|
|
6081
|
+
const spacer = this.clickedSpacer(col);
|
|
6082
|
+
if (spacer) return spacer;
|
|
6083
|
+
const selection = this.builder.win.getSelection();
|
|
6084
|
+
const r = selection && selection.rangeCount ? selection.getRangeAt(0) : null;
|
|
6085
|
+
if (!r || r.collapsed || r.startContainer !== r.endContainer || r.endOffset - r.startOffset !== 1) return null;
|
|
6086
|
+
const el = r.startContainer.childNodes[r.startOffset];
|
|
6087
|
+
return el && el.nodeType === 1 && col.contains(el) ? el : null;
|
|
6088
|
+
}
|
|
5964
6089
|
objectSelected(col) {
|
|
5965
6090
|
const icon = this.builder.activeIcon;
|
|
5966
6091
|
if (icon && icon.isConnected && col.contains(icon)) return true;
|
|
6092
|
+
// An add-on's block or drawing selected as a click selects it (a timeline,
|
|
6093
|
+
// a chart): the drawing tool's element, with no text selection.
|
|
6094
|
+
if (this.activeDrawing(col)) return true;
|
|
6095
|
+
if (this.clickedSpacer(col)) return true;
|
|
5967
6096
|
const selection = this.builder.win.getSelection();
|
|
5968
6097
|
const r = selection && selection.rangeCount ? selection.getRangeAt(0) : null;
|
|
5969
6098
|
if (!r || r.collapsed || r.startContainer !== r.endContainer || r.endOffset - r.startOffset !== 1) return false;
|
|
5970
6099
|
const el = r.startContainer.childNodes[r.startOffset];
|
|
5971
|
-
return !!(el && el.nodeType === 1 && col.contains(el) && (el.matches(ATOMIC) || el.getAttribute('contenteditable') === 'false'));
|
|
6100
|
+
return !!(el && el.nodeType === 1 && col.contains(el) && (el.matches(ATOMIC) || el.getAttribute('contenteditable') === 'false' || el.tagName === 'A' && !!el.parentElement && !!el.parentElement.closest('[contenteditable="false"]')));
|
|
5972
6101
|
}
|
|
5973
6102
|
|
|
5974
6103
|
/**
|
|
@@ -6033,6 +6162,13 @@ class ToolbarKeys {
|
|
|
6033
6162
|
* False if there is nothing to go to, so the caller can leave the key alone.
|
|
6034
6163
|
*/
|
|
6035
6164
|
enter(col) {
|
|
6165
|
+
// A column reached with no click (Tab into the content) is not the
|
|
6166
|
+
// editor's active one yet, so its strips are hidden and there would be
|
|
6167
|
+
// nothing to go to: it is made active as a click would.
|
|
6168
|
+
if (col !== this.builder.activeCol && typeof this.builder.activateColumnAndRte === 'function') {
|
|
6169
|
+
this.builder.activateColumnAndRte(col);
|
|
6170
|
+
}
|
|
6171
|
+
|
|
6036
6172
|
// An object selected whole (a picture, a drawing, a spacer, a plugin:
|
|
6037
6173
|
// by Shift+Arrow, the arrow keys or a click) is what the user is on, so
|
|
6038
6174
|
// the walk starts at its own tool (level 30) rather than the text
|
|
@@ -6042,11 +6178,65 @@ class ToolbarKeys {
|
|
|
6042
6178
|
// the picture tool (the editor's own selection path does).
|
|
6043
6179
|
const objectSelected = this.objectSelected(col);
|
|
6044
6180
|
if (!objectSelected) this.selectElementAtCaret(col);
|
|
6181
|
+
|
|
6182
|
+
// A host whose side panel is the element's tools (ContentBox: video,
|
|
6183
|
+
// YouTube, map, audio and other plugins have no tool of their own):
|
|
6184
|
+
// Escape goes to the panel's first field, and Escape there brings the
|
|
6185
|
+
// caret back here (the host keeps where it was).
|
|
6186
|
+
// The host says whether its panel is the element's tools (it is for media,
|
|
6187
|
+
// plugins and add-on blocks; not for a picture, which has its own tool).
|
|
6188
|
+
// The caret in a plugin's own field or editable part (a form's input, a
|
|
6189
|
+
// FAQ's text): the plugin is what the user is on, as a click on it shows.
|
|
6190
|
+
const plugin = objectSelected ? null : this.pluginAtCaret(col);
|
|
6191
|
+
// The plugin's field the caret is in (a form's input): where Escape
|
|
6192
|
+
// comes back to, before showing the plugin's tools moves the focus.
|
|
6193
|
+
const field0 = this.builder.doc.activeElement;
|
|
6194
|
+
this.originField = plugin && field0 && field0 !== col && col.contains(field0) ? field0 : null;
|
|
6195
|
+
if (plugin) {
|
|
6196
|
+
// Its tools on show, as a click on it does (ContentBuilder: the
|
|
6197
|
+
// plugin tool; ContentBox: the plugin's part of the side panel).
|
|
6198
|
+
const event = {
|
|
6199
|
+
target: plugin,
|
|
6200
|
+
cbShowTools: true,
|
|
6201
|
+
preventDefault() {},
|
|
6202
|
+
stopPropagation() {}
|
|
6203
|
+
};
|
|
6204
|
+
this.builder.element.click(col, event);
|
|
6205
|
+
this.builder.elmTool.click(col, event);
|
|
6206
|
+
const panel = this.builder.controlpanel;
|
|
6207
|
+
if (panel && typeof panel.openPluginPanel === 'function') panel.openPluginPanel(plugin);
|
|
6208
|
+
}
|
|
6045
6209
|
const chain = this.chain(col.parentNode);
|
|
6046
|
-
const
|
|
6210
|
+
const own = objectSelected || plugin ? chain.find(tool => (tool._toolbarLevel || 0) >= 30) : null;
|
|
6211
|
+
this.panelNext = null;
|
|
6212
|
+
this.panelEnds = false;
|
|
6213
|
+
if (objectSelected || plugin) {
|
|
6214
|
+
const host = this.builder.controlpanel;
|
|
6215
|
+
const el = plugin || this.selectedElement(col);
|
|
6216
|
+
const hasPanel = el && this.builder.panelOwnsTools && this.builder.panelOwnsTools() && host && typeof host.focusSettings === 'function';
|
|
6217
|
+
// Both a tool beside it and its panel (a picture): the tool, then
|
|
6218
|
+
// Escape to the panel, then Escape back to the caret. The panel first
|
|
6219
|
+
// when an add-on made it (its edit is there) or it has no tool.
|
|
6220
|
+
if (hasPanel && (!own || typeof host.panelLeads === 'function' && host.panelLeads(el))) {
|
|
6221
|
+
this.origin = col;
|
|
6222
|
+
this.builder.util.saveSelection();
|
|
6223
|
+
this.originObject = this.activeDrawing(col) || this.clickedSpacer(col);
|
|
6224
|
+
const toTool = own ? () => {
|
|
6225
|
+
this.panelEnds = true;
|
|
6226
|
+
return this.focusStrip(own);
|
|
6227
|
+
} : null;
|
|
6228
|
+
if (host.focusSettings(el, toTool)) return true;
|
|
6229
|
+
} else if (hasPanel) {
|
|
6230
|
+
this.panelNext = el;
|
|
6231
|
+
}
|
|
6232
|
+
}
|
|
6233
|
+
const first = own || chain[0];
|
|
6047
6234
|
if (!first) return false;
|
|
6048
6235
|
this.origin = col;
|
|
6049
6236
|
this.builder.util.saveSelection(); // so Escape can put it back exactly
|
|
6237
|
+
// An add-on's block or a drawing selected whole has no text selection to
|
|
6238
|
+
// save (the browser's would be the column's start): it is what comes back.
|
|
6239
|
+
this.originObject = this.activeDrawing(col) || this.clickedSpacer(col);
|
|
6050
6240
|
return this.focusStrip(first);
|
|
6051
6241
|
}
|
|
6052
6242
|
|
|
@@ -6129,17 +6319,39 @@ class ToolbarKeys {
|
|
|
6129
6319
|
* element ones even though the user was editing text.
|
|
6130
6320
|
*/
|
|
6131
6321
|
exit() {
|
|
6322
|
+
this.panelNext = null;
|
|
6323
|
+
this.panelEnds = false;
|
|
6324
|
+
// Back in the plugin's field the walk started from (a form's input).
|
|
6325
|
+
const field = this.originField;
|
|
6326
|
+
this.originField = null;
|
|
6327
|
+
if (field && field.isConnected && field.getClientRects().length) {
|
|
6328
|
+
if (this.builder.win !== window) this.builder.win.focus();
|
|
6329
|
+
field.focus({
|
|
6330
|
+
preventScroll: true
|
|
6331
|
+
});
|
|
6332
|
+
return true;
|
|
6333
|
+
}
|
|
6132
6334
|
const col = this.origin && this.origin.isConnected ? this.origin : this._somewhereUsable();
|
|
6133
6335
|
if (!col) return false;
|
|
6134
6336
|
|
|
6135
6337
|
// A canvas block holds no caret, so there is no selection to put back.
|
|
6338
|
+
// Focused without scrolling: on a tall column the browser brought its top
|
|
6339
|
+
// into view and the page jumped. Only what holds the caret is shown.
|
|
6136
6340
|
if (col.classList.contains('is-block')) {
|
|
6137
|
-
col.focus(
|
|
6341
|
+
col.focus({
|
|
6342
|
+
preventScroll: true
|
|
6343
|
+
});
|
|
6138
6344
|
this.origin = null;
|
|
6139
6345
|
return true;
|
|
6140
6346
|
}
|
|
6141
|
-
col.focus(
|
|
6142
|
-
|
|
6347
|
+
col.focus({
|
|
6348
|
+
preventScroll: true
|
|
6349
|
+
});
|
|
6350
|
+
const obj = this.originObject;
|
|
6351
|
+
this.originObject = null;
|
|
6352
|
+
const nav = this.builder.caretNav;
|
|
6353
|
+
if (obj && obj.isConnected && col.contains(obj) && nav && typeof nav.selectObject === 'function') nav.selectObject(obj);else this.builder.util.restoreSelection();
|
|
6354
|
+
this.showSelection(col);
|
|
6143
6355
|
|
|
6144
6356
|
// The toolbars follow the selection, and nothing has moved a pointer or a
|
|
6145
6357
|
// key in the content, so say so to bring the right one back.
|
|
@@ -6150,6 +6362,17 @@ class ToolbarKeys {
|
|
|
6150
6362
|
return true;
|
|
6151
6363
|
}
|
|
6152
6364
|
|
|
6365
|
+
/** Scroll just enough to show where the caret (or the selected element) is. */
|
|
6366
|
+
showSelection(col) {
|
|
6367
|
+
const sel = this.builder.win.getSelection();
|
|
6368
|
+
const r = sel && sel.rangeCount ? sel.getRangeAt(0) : null;
|
|
6369
|
+
let el = r ? r.startContainer.nodeType === 1 ? r.startContainer.childNodes[r.startOffset] || r.startContainer : r.startContainer.parentElement : null;
|
|
6370
|
+
if (!el || el.nodeType !== 1 || !col.contains(el)) el = this.builder.activeSvg && col.contains(this.builder.activeSvg) ? this.builder.activeSvg : null;
|
|
6371
|
+
if (el && el.scrollIntoView) el.scrollIntoView({
|
|
6372
|
+
block: 'nearest'
|
|
6373
|
+
});
|
|
6374
|
+
}
|
|
6375
|
+
|
|
6153
6376
|
/**
|
|
6154
6377
|
* Say, on a column, that the tools are a key away. Screen readers announce the
|
|
6155
6378
|
* note on entering the column; both attributes are stripped on save (html.js).
|
|
@@ -6201,12 +6424,34 @@ class ToolbarKeys {
|
|
|
6201
6424
|
const at = chain.indexOf(tool);
|
|
6202
6425
|
if (at === -1) return false;
|
|
6203
6426
|
if (!outward) return at === 0 ? true : this.focusStrip(chain[at - 1]);
|
|
6427
|
+
|
|
6428
|
+
// From the element's own tool: its panel next (ContentBox), or, having
|
|
6429
|
+
// come from the panel, back to the caret.
|
|
6430
|
+
if ((tool._toolbarLevel || 0) >= 30) {
|
|
6431
|
+
if (this.panelEnds) {
|
|
6432
|
+
this.panelEnds = false;
|
|
6433
|
+
return this.exit();
|
|
6434
|
+
}
|
|
6435
|
+
const el = this.panelNext;
|
|
6436
|
+
this.panelNext = null;
|
|
6437
|
+
const host = this.builder.controlpanel;
|
|
6438
|
+
if (el && el.isConnected && host && typeof host.focusSettings === 'function' && host.focusSettings(el)) return true;
|
|
6439
|
+
}
|
|
6204
6440
|
const next = chain[at + 1];
|
|
6205
6441
|
return next ? this.focusStrip(next) : this.exit();
|
|
6206
6442
|
}
|
|
6207
6443
|
_onKeydown(e, tool, axis, isDragging) {
|
|
6208
6444
|
const dragging = isDragging && isDragging();
|
|
6209
6445
|
|
|
6446
|
+
// F6: on to the page's regions (the caret's place is kept from the walk).
|
|
6447
|
+
if (this.isRegionKey(e) && !dragging) {
|
|
6448
|
+
if (this.stepRegion(e.target, !e.shiftKey)) {
|
|
6449
|
+
e.preventDefault();
|
|
6450
|
+
e.stopPropagation();
|
|
6451
|
+
}
|
|
6452
|
+
return;
|
|
6453
|
+
}
|
|
6454
|
+
|
|
6210
6455
|
// Tab and Shift+Tab leave the tools for the content: back where the caret
|
|
6211
6456
|
// was (or the object that was selected), where a full Escape walk ends.
|
|
6212
6457
|
// Left to the browser, Tab went on to whatever came next in the page (a
|
|
@@ -7545,6 +7790,19 @@ class Util {
|
|
|
7545
7790
|
host: active
|
|
7546
7791
|
};
|
|
7547
7792
|
}
|
|
7793
|
+
contentSelection() {
|
|
7794
|
+
const doc = this.builder.doc;
|
|
7795
|
+
const sel = doc && doc.getSelection();
|
|
7796
|
+
if (!sel || !sel.rangeCount) return null;
|
|
7797
|
+
const range = sel.getRangeAt(0);
|
|
7798
|
+
const n = range.startContainer.nodeType === 1 ? range.startContainer : range.startContainer.parentElement;
|
|
7799
|
+
const host = n && n.closest && n.closest('[contenteditable="true"]');
|
|
7800
|
+
if (!host || !host.closest(this.builder.opts.container)) return null;
|
|
7801
|
+
return {
|
|
7802
|
+
range: range.cloneRange(),
|
|
7803
|
+
host
|
|
7804
|
+
};
|
|
7805
|
+
}
|
|
7548
7806
|
|
|
7549
7807
|
/* Put the caret back in the text after a modal opened from it closes, unless
|
|
7550
7808
|
the focus already went somewhere on purpose (another modal, a panel, the
|
|
@@ -7595,6 +7853,11 @@ class Util {
|
|
|
7595
7853
|
// from a button: there is no control to go back to, so remember where
|
|
7596
7854
|
// the caret was and put it back when the modal closes (hideModal).
|
|
7597
7855
|
modal._caret = modal._opener ? null : this.textCaret();
|
|
7856
|
+
// Where the content's selection is (a picture selected, a caret), whatever
|
|
7857
|
+
// has the focus: used when the button that opened the window is gone when
|
|
7858
|
+
// it closes (the picture tool hides after a link is added), so the user
|
|
7859
|
+
// is back on the content rather than nowhere.
|
|
7860
|
+
modal._content = this.contentSelection();
|
|
7598
7861
|
// Opened right after another window closed (an add-on's "Working..."
|
|
7599
7862
|
// window, then its result): nothing has the focus yet, as the closed
|
|
7600
7863
|
// one gives it back on the next tick. This one takes over where to go
|
|
@@ -7790,6 +8053,9 @@ class Util {
|
|
|
7790
8053
|
|
|
7791
8054
|
hideModal(modal) {
|
|
7792
8055
|
if (!modal) return;
|
|
8056
|
+
// Already closed (a click-out handler left behind by an Escape close fires on
|
|
8057
|
+
// the caret's next move): nothing to close, and the caret stays where it is.
|
|
8058
|
+
if (!modal.classList.contains('active')) return;
|
|
7793
8059
|
this.builder.doc.activeElement.blur();
|
|
7794
8060
|
document.activeElement.blur();
|
|
7795
8061
|
|
|
@@ -7799,6 +8065,8 @@ class Util {
|
|
|
7799
8065
|
modal._opener = null;
|
|
7800
8066
|
const caret = modal._caret;
|
|
7801
8067
|
modal._caret = null;
|
|
8068
|
+
const content = modal._content;
|
|
8069
|
+
modal._content = null;
|
|
7802
8070
|
// Taken over by a window opened before the next tick (showModal).
|
|
7803
8071
|
const pending = {
|
|
7804
8072
|
opener,
|
|
@@ -7814,6 +8082,15 @@ class Util {
|
|
|
7814
8082
|
if (pending.taken) return;
|
|
7815
8083
|
this.returnToText(caret);
|
|
7816
8084
|
}, 0);
|
|
8085
|
+
// Neither (opened from the text by an add-on, an insert just made): the
|
|
8086
|
+
// text, where the content's selection now is, or where it was at opening.
|
|
8087
|
+
if (!caret && !opener) setTimeout(() => {
|
|
8088
|
+
if (pending.taken) return;
|
|
8089
|
+
this.returnToText(content || {
|
|
8090
|
+
range: null,
|
|
8091
|
+
host: null
|
|
8092
|
+
});
|
|
8093
|
+
}, 0);
|
|
7817
8094
|
if (opener) setTimeout(() => {
|
|
7818
8095
|
if (pending.taken) return;
|
|
7819
8096
|
const usable = el => el && el.isConnected && el.offsetParent !== null;
|
|
@@ -7827,11 +8104,31 @@ class Util {
|
|
|
7827
8104
|
pop = opener.closest('.is-pop, .is-rte-pop, .cb-addon-pop');
|
|
7828
8105
|
target = pop ? pop._opener : null;
|
|
7829
8106
|
}
|
|
7830
|
-
if (usable(target))
|
|
8107
|
+
if (usable(target)) {
|
|
8108
|
+
target.focus();
|
|
8109
|
+
// Its tool can hide right after (the element changed, as an
|
|
8110
|
+
// add-on's Apply does): then back to the content.
|
|
8111
|
+
setTimeout(() => {
|
|
8112
|
+
if (target.isConnected && target.offsetParent !== null) return;
|
|
8113
|
+
let a = document.activeElement;
|
|
8114
|
+
if (a && a.tagName === 'IFRAME') {
|
|
8115
|
+
try {
|
|
8116
|
+
a = a.contentDocument.activeElement;
|
|
8117
|
+
} catch (e) {
|
|
8118
|
+
return;
|
|
8119
|
+
}
|
|
8120
|
+
}
|
|
8121
|
+
if (a && a !== document.body && a !== this.builder.doc.body) return;
|
|
8122
|
+
this.returnToText(content || {
|
|
8123
|
+
range: null,
|
|
8124
|
+
host: null
|
|
8125
|
+
});
|
|
8126
|
+
}, 400);
|
|
8127
|
+
}
|
|
7831
8128
|
// Nothing left to go back to (an add-on's small panel or a menu
|
|
7832
8129
|
// that closed to open this): back to the text, at the caret the
|
|
7833
8130
|
// panel was opened at, or where the content's selection still is.
|
|
7834
|
-
else this.returnToText(pop && pop._caret || {
|
|
8131
|
+
else this.returnToText(pop && pop._caret || content || {
|
|
7835
8132
|
range: null,
|
|
7836
8133
|
host: null
|
|
7837
8134
|
});
|
|
@@ -18313,6 +18610,67 @@ class UndoRedo {
|
|
|
18313
18610
|
}
|
|
18314
18611
|
this.builder.opts.onRender();
|
|
18315
18612
|
}
|
|
18613
|
+
|
|
18614
|
+
/* The caret, kept with each step as a place that survives the content
|
|
18615
|
+
being written again: which editable area (its order on the page) and
|
|
18616
|
+
how many characters into it. Undo and Redo put it back, so the keyboard
|
|
18617
|
+
goes on where the change was (the content is replaced, which dropped
|
|
18618
|
+
the caret and the focus). */
|
|
18619
|
+
editableAreas() {
|
|
18620
|
+
return Array.from(this.builder.doc.querySelectorAll('.is-builder [contenteditable="true"]'));
|
|
18621
|
+
}
|
|
18622
|
+
caret() {
|
|
18623
|
+
const doc = this.builder.doc;
|
|
18624
|
+
const sel = doc.getSelection ? doc.getSelection() : null;
|
|
18625
|
+
if (!sel || !sel.rangeCount || !sel.focusNode) return null;
|
|
18626
|
+
const n = sel.focusNode;
|
|
18627
|
+
const el = n.nodeType === 1 ? n : n.parentElement;
|
|
18628
|
+
const area = el && el.closest('[contenteditable="true"]');
|
|
18629
|
+
const i = area ? this.editableAreas().indexOf(area) : -1;
|
|
18630
|
+
if (i < 0) return null;
|
|
18631
|
+
const r = doc.createRange();
|
|
18632
|
+
r.selectNodeContents(area);
|
|
18633
|
+
try {
|
|
18634
|
+
r.setEnd(sel.focusNode, sel.focusOffset);
|
|
18635
|
+
} catch (e) {
|
|
18636
|
+
return null;
|
|
18637
|
+
}
|
|
18638
|
+
return {
|
|
18639
|
+
area: i,
|
|
18640
|
+
offset: r.toString().length
|
|
18641
|
+
};
|
|
18642
|
+
}
|
|
18643
|
+
restoreCaret(mark) {
|
|
18644
|
+
if (!mark) return;
|
|
18645
|
+
const area = this.editableAreas()[mark.area];
|
|
18646
|
+
if (!area) return;
|
|
18647
|
+
const doc = this.builder.doc;
|
|
18648
|
+
const nav = this.builder.caretNav;
|
|
18649
|
+
if (nav) nav.focusPlace(area);else area.focus({
|
|
18650
|
+
preventScroll: true
|
|
18651
|
+
});
|
|
18652
|
+
let left = mark.offset,
|
|
18653
|
+
node = null,
|
|
18654
|
+
offset = 0;
|
|
18655
|
+
const walker = doc.createTreeWalker(area, NodeFilter.SHOW_TEXT);
|
|
18656
|
+
for (let t = walker.nextNode(); t; t = walker.nextNode()) {
|
|
18657
|
+
if (left <= t.length) {
|
|
18658
|
+
node = t;
|
|
18659
|
+
offset = left;
|
|
18660
|
+
break;
|
|
18661
|
+
}
|
|
18662
|
+
left -= t.length;
|
|
18663
|
+
}
|
|
18664
|
+
const r = doc.createRange();
|
|
18665
|
+
if (node) r.setStart(node, offset);else {
|
|
18666
|
+
r.selectNodeContents(area);
|
|
18667
|
+
r.collapse(false);
|
|
18668
|
+
}
|
|
18669
|
+
r.collapse(true);
|
|
18670
|
+
const sel = doc.getSelection();
|
|
18671
|
+
sel.removeAllRanges();
|
|
18672
|
+
sel.addRange(r);
|
|
18673
|
+
}
|
|
18316
18674
|
saveForUndo(checkLater) {
|
|
18317
18675
|
if (this.builder.onBeforeSaveForUndo) this.builder.onBeforeSaveForUndo();
|
|
18318
18676
|
if (this.builder.undoRedoStyles) {
|
|
@@ -18376,9 +18734,9 @@ class UndoRedo {
|
|
|
18376
18734
|
let styles = this.readStyles();
|
|
18377
18735
|
let html = this.readHtml();
|
|
18378
18736
|
let saves = ' ' + styles + '###$###' + html;
|
|
18379
|
-
this.undoList[120] = [saves,
|
|
18737
|
+
this.undoList[120] = [saves, this.caret()];
|
|
18380
18738
|
} else {
|
|
18381
|
-
this.undoList[120] = [this.readHtml(),
|
|
18739
|
+
this.undoList[120] = [this.readHtml(), this.caret()];
|
|
18382
18740
|
}
|
|
18383
18741
|
}
|
|
18384
18742
|
async doUndo() {
|
|
@@ -18389,6 +18747,11 @@ class UndoRedo {
|
|
|
18389
18747
|
// console.log('undo');
|
|
18390
18748
|
|
|
18391
18749
|
this.builder.undoRedoInProcess = true;
|
|
18750
|
+
|
|
18751
|
+
// The caret: where it is now (for Redo), and where it was when the step
|
|
18752
|
+
// being restored was saved (put back after it).
|
|
18753
|
+
const here = this.caret();
|
|
18754
|
+
const back = this.undoList[120][1];
|
|
18392
18755
|
this.undoList[99] = this.undoList[100];
|
|
18393
18756
|
this.undoList[100] = this.undoList[101];
|
|
18394
18757
|
this.undoList[101] = this.undoList[102];
|
|
@@ -18413,7 +18776,7 @@ class UndoRedo {
|
|
|
18413
18776
|
let styles = this.readStyles();
|
|
18414
18777
|
let html = this.readHtml();
|
|
18415
18778
|
let saves = ' ' + styles + '###$###' + html;
|
|
18416
|
-
this.undoList[119] = [saves,
|
|
18779
|
+
this.undoList[119] = [saves, here];
|
|
18417
18780
|
|
|
18418
18781
|
// -
|
|
18419
18782
|
|
|
@@ -18423,7 +18786,7 @@ class UndoRedo {
|
|
|
18423
18786
|
this.writeStyles(styles);
|
|
18424
18787
|
this.writeHtml(html);
|
|
18425
18788
|
} else {
|
|
18426
|
-
this.undoList[119] = [this.readHtml(),
|
|
18789
|
+
this.undoList[119] = [this.readHtml(), here];
|
|
18427
18790
|
let html = this.undoList[120][0];
|
|
18428
18791
|
this.writeHtml(html);
|
|
18429
18792
|
}
|
|
@@ -18477,6 +18840,7 @@ class UndoRedo {
|
|
|
18477
18840
|
this.builder.opts.onUndo();
|
|
18478
18841
|
}
|
|
18479
18842
|
this.builder.undoRedoInProcess = false;
|
|
18843
|
+
this.restoreCaret(back);
|
|
18480
18844
|
}
|
|
18481
18845
|
async doRedo() {
|
|
18482
18846
|
const dom = this.dom;
|
|
@@ -18486,6 +18850,11 @@ class UndoRedo {
|
|
|
18486
18850
|
// console.log('redo');
|
|
18487
18851
|
|
|
18488
18852
|
this.builder.undoRedoInProcess = true;
|
|
18853
|
+
|
|
18854
|
+
// The caret: where it is now (for Undo), and where it was when the step
|
|
18855
|
+
// being restored was left.
|
|
18856
|
+
const here = this.caret();
|
|
18857
|
+
const back = this.undoList[119][1];
|
|
18489
18858
|
this.undoList[141] = this.undoList[140];
|
|
18490
18859
|
this.undoList[140] = this.undoList[139];
|
|
18491
18860
|
this.undoList[139] = this.undoList[138];
|
|
@@ -18511,7 +18880,7 @@ class UndoRedo {
|
|
|
18511
18880
|
let styles = this.readStyles();
|
|
18512
18881
|
let html = this.readHtml();
|
|
18513
18882
|
let saves = ' ' + styles + '###$###' + html;
|
|
18514
|
-
this.undoList[120] = [saves,
|
|
18883
|
+
this.undoList[120] = [saves, here];
|
|
18515
18884
|
|
|
18516
18885
|
// -
|
|
18517
18886
|
|
|
@@ -18521,7 +18890,7 @@ class UndoRedo {
|
|
|
18521
18890
|
this.writeStyles(styles);
|
|
18522
18891
|
this.writeHtml(html);
|
|
18523
18892
|
} else {
|
|
18524
|
-
this.undoList[120] = [this.readHtml(),
|
|
18893
|
+
this.undoList[120] = [this.readHtml(), here];
|
|
18525
18894
|
let html = this.undoList[119][0];
|
|
18526
18895
|
this.writeHtml(html);
|
|
18527
18896
|
}
|
|
@@ -18575,6 +18944,7 @@ class UndoRedo {
|
|
|
18575
18944
|
this.builder.opts.onRedo();
|
|
18576
18945
|
}
|
|
18577
18946
|
this.builder.undoRedoInProcess = false;
|
|
18947
|
+
this.restoreCaret(back);
|
|
18578
18948
|
}
|
|
18579
18949
|
}
|
|
18580
18950
|
|
|
@@ -19625,12 +19995,23 @@ const OWN_NAV = 'li, td, th';
|
|
|
19625
19995
|
const hasText = el => {
|
|
19626
19996
|
const walker = el.ownerDocument.createTreeWalker(el, 4);
|
|
19627
19997
|
for (let n = walker.nextNode(); n; n = walker.nextNode()) {
|
|
19628
|
-
|
|
19998
|
+
// Not text on the line: a drawing's labels, a player's fallback line
|
|
19999
|
+
// ("Your browser does not support..."), an editing overlay.
|
|
20000
|
+
if (n.parentElement && n.parentElement.closest('svg, audio, video, iframe, object, .ovl')) continue;
|
|
19629
20001
|
if (n.nodeValue.replace(/\u200B/g, '').trim() !== '') return true;
|
|
19630
20002
|
}
|
|
19631
20003
|
return false;
|
|
19632
20004
|
};
|
|
20005
|
+
/* An audio or video player or an embed (a YouTube video, a map) in the
|
|
20006
|
+
content itself, not in a plugin or a locked block: stopped on and selected
|
|
20007
|
+
whole like a picture. */
|
|
20008
|
+
const isMedia = el => !!el && el.nodeType === 1 && /^(AUDIO|VIDEO|IFRAME)$/.test(el.tagName) && !el.closest('[data-cb-type], [contenteditable="false"]');
|
|
19633
20009
|
/* A picture or a drawing in the text (an <svg> not inside another one). */
|
|
20010
|
+
// A link that is only an icon, in a locked block (Social Links): a stop of its
|
|
20011
|
+
// own for the arrows, selected whole, its link tool reached with Escape, as a
|
|
20012
|
+
// click on the icon shows it.
|
|
20013
|
+
const isIconLink = el => !!el && el.nodeType === 1 && el.tagName === 'A' && !!el.parentElement && !!el.parentElement.closest('[contenteditable="false"]') && !el.textContent.trim() && !!el.querySelector('i, svg, img');
|
|
20014
|
+
const holdsIconLinks = el => !!el && el.nodeType === 1 && el.getAttribute('contenteditable') === 'false' && Array.from(el.querySelectorAll('a')).some(isIconLink) && !el.closest('[data-cb-type]');
|
|
19634
20015
|
const isPicture = el => !!el && el.nodeType === 1 && (el.tagName === 'IMG' || el.nodeName.toLowerCase() === 'svg' && !(el.parentElement && el.parentElement.closest('svg')));
|
|
19635
20016
|
class CaretNav {
|
|
19636
20017
|
constructor(builder) {
|
|
@@ -19654,6 +20035,8 @@ class CaretNav {
|
|
|
19654
20035
|
if (!this.host(el)) return false;
|
|
19655
20036
|
if (el.closest('[data-cb-code], .is-row-tool, .is-col-tool, .is-rowadd-tool, [data-cb-ui]')) return false;
|
|
19656
20037
|
if (el.matches('.spacer, hr')) return false;
|
|
20038
|
+
// A player's or an embed's editing overlay is not a line to type on.
|
|
20039
|
+
if (el.matches('.ovl')) return false;
|
|
19657
20040
|
const r = el.getBoundingClientRect();
|
|
19658
20041
|
if (!r.width && !r.height) return false;
|
|
19659
20042
|
// A leaf: no other text element inside (a wrapper is not a place).
|
|
@@ -19669,10 +20052,16 @@ class CaretNav {
|
|
|
19669
20052
|
const b = this.builder;
|
|
19670
20053
|
const out = [];
|
|
19671
20054
|
b.doc.querySelectorAll(b.opts.container).forEach(area => {
|
|
19672
|
-
area.querySelectorAll(TEXT + ', [contenteditable="true"], [contenteditable="false"], img, svg').forEach(el => {
|
|
20055
|
+
area.querySelectorAll(TEXT + ', [contenteditable="true"], [contenteditable="false"], img, svg, audio, video, iframe, a').forEach(el => {
|
|
19673
20056
|
if (el.matches(b.opts.container)) return;
|
|
20057
|
+
if (el.tagName === 'A') {
|
|
20058
|
+
if (isIconLink(el) && this.isObject(el)) out.push(el);
|
|
20059
|
+
return;
|
|
20060
|
+
}
|
|
20061
|
+
if (holdsIconLinks(el)) return; // its links are the stops
|
|
19674
20062
|
if (el.nodeName.toLowerCase() === 'svg' && !isPicture(el)) return;
|
|
19675
|
-
if (
|
|
20063
|
+
if (isMedia(el) && !this.isObject(el)) return;
|
|
20064
|
+
if (isPicture(el) || isMedia(el) || el.getAttribute('contenteditable') === 'false') {
|
|
19676
20065
|
if (this.isObject(el)) out.push(el);
|
|
19677
20066
|
return;
|
|
19678
20067
|
}
|
|
@@ -19695,7 +20084,9 @@ class CaretNav {
|
|
|
19695
20084
|
// past it; in a line of text the caret passes it and Shift+Arrow selects
|
|
19696
20085
|
// it (contentbuilder.js, handleCellKeydown).
|
|
19697
20086
|
isObject(el) {
|
|
19698
|
-
if (
|
|
20087
|
+
if (isIconLink(el)) return !el.closest('[data-cb-type]') && !!this.host(el.closest('[contenteditable="false"]').parentElement);
|
|
20088
|
+
if (holdsIconLinks(el)) return false;
|
|
20089
|
+
if (isPicture(el) || isMedia(el)) return this.isPictureLine(el);
|
|
19699
20090
|
if (!el || el.getAttribute('contenteditable') !== 'false') return false;
|
|
19700
20091
|
if (el.querySelector('[contenteditable="true"]')) return false;
|
|
19701
20092
|
const host = el.parentElement && this.host(el.parentElement);
|
|
@@ -19730,15 +20121,38 @@ class CaretNav {
|
|
|
19730
20121
|
selectedObject(range) {
|
|
19731
20122
|
const icon = this.builder.activeIcon;
|
|
19732
20123
|
if (icon && icon.isConnected && isPicture(icon) && this.isObject(icon)) return icon;
|
|
20124
|
+
// An add-on's block selected by a click (a timeline, a calendar: the
|
|
20125
|
+
// drawing tool's block), as the arrows select it.
|
|
20126
|
+
const block = this.builder.activeSvg;
|
|
20127
|
+
if (block && block.isConnected && block.matches && block.matches('[data-cb-object]') && this.columnOf(block.parentElement)) return block;
|
|
19733
20128
|
if (!range || range.collapsed || range.startContainer !== range.endContainer || range.startContainer.nodeType !== 1) return null;
|
|
19734
20129
|
if (range.endOffset - range.startOffset !== 1) return null;
|
|
19735
20130
|
const el = range.startContainer.childNodes[range.startOffset];
|
|
19736
20131
|
return el && el.nodeType === 1 && this.isObject(el) ? el : null;
|
|
19737
20132
|
}
|
|
20133
|
+
|
|
20134
|
+
// A spacer clicked (its tool still showing, nothing selected since): Enter
|
|
20135
|
+
// adds a line after it, as after the arrows selected it.
|
|
20136
|
+
clickedSpacer() {
|
|
20137
|
+
const spacer = this.builder.activeSpacer;
|
|
20138
|
+
const tk = this.builder.toolbarKeys;
|
|
20139
|
+
if (!spacer || !tk || typeof tk.clickedSpacer !== 'function') return null;
|
|
20140
|
+
const col = this.columnOf(spacer);
|
|
20141
|
+
return col && tk.clickedSpacer(col) === spacer && this.isObject(spacer) ? spacer : null;
|
|
20142
|
+
}
|
|
19738
20143
|
columnOf(el) {
|
|
19739
|
-
|
|
19740
|
-
|
|
19741
|
-
|
|
20144
|
+
// Past a locked block too: a button's label is an editable island in a
|
|
20145
|
+
// locked wrapper, and its column is the one around that wrapper (without
|
|
20146
|
+
// it, Tab in a label was left to the browser and went out of the editor).
|
|
20147
|
+
let n = el && (el.nodeType === 1 ? el : el.parentElement);
|
|
20148
|
+
while (n) {
|
|
20149
|
+
const h = this.host(n);
|
|
20150
|
+
if (h && this.isColumn(h)) return h;
|
|
20151
|
+
const ce = n.closest('[contenteditable]');
|
|
20152
|
+
if (!ce) return null;
|
|
20153
|
+
n = ce.parentElement;
|
|
20154
|
+
}
|
|
20155
|
+
return null;
|
|
19742
20156
|
}
|
|
19743
20157
|
selectObject(el) {
|
|
19744
20158
|
const b = this.builder;
|
|
@@ -19752,7 +20166,8 @@ class CaretNav {
|
|
|
19752
20166
|
});
|
|
19753
20167
|
const select = () => {
|
|
19754
20168
|
const region = col && b.editingEngine && b.editingEngine.regionFor(col);
|
|
19755
|
-
|
|
20169
|
+
// An icon link: the text engine would put a caret in it, not select it.
|
|
20170
|
+
if (!isIconLink(el) && region && region.ed && region.ed.selectNode(el)) return;
|
|
19756
20171
|
const r = b.doc.createRange();
|
|
19757
20172
|
r.selectNode(el);
|
|
19758
20173
|
const sel = b.win.getSelection();
|
|
@@ -19775,14 +20190,17 @@ class CaretNav {
|
|
|
19775
20190
|
// The click last: selecting a picture again after it would make the
|
|
19776
20191
|
// editor hide the picture's tool. Selected again only if the click
|
|
19777
20192
|
// let go of it (Delete and Enter need it selected).
|
|
19778
|
-
|
|
20193
|
+
// A player is clicked through its editing overlay, as a mouse click lands
|
|
20194
|
+
// (the audio and video tools show for a click there).
|
|
20195
|
+
const target = isIconLink(el) ? el.querySelector('i, svg, img') || el : isMedia(el) && el.parentElement ? el.parentElement.querySelector(':scope > .ovl') || el : el;
|
|
20196
|
+
if (b.util && b.util.clickElement) b.util.clickElement(target, {
|
|
19779
20197
|
tools: true
|
|
19780
20198
|
});
|
|
19781
20199
|
// A drawing is now the selected icon, as after a click.
|
|
19782
20200
|
if (drawing) return;
|
|
19783
20201
|
if (this.selectedObject(this.range()) !== el) {
|
|
19784
20202
|
select();
|
|
19785
|
-
if (isPicture(el) && b.util && b.util.clickElement) b.util.clickElement(
|
|
20203
|
+
if ((isPicture(el) || isMedia(el)) && b.util && b.util.clickElement) b.util.clickElement(target, {
|
|
19786
20204
|
tools: true
|
|
19787
20205
|
});
|
|
19788
20206
|
}
|
|
@@ -19949,16 +20367,20 @@ class CaretNav {
|
|
|
19949
20367
|
}
|
|
19950
20368
|
go(target, how) {
|
|
19951
20369
|
this.pending = null;
|
|
19952
|
-
// Leaving a selected object: its tools go, as a
|
|
19953
|
-
|
|
20370
|
+
// Leaving a selected object (or a spacer clicked): its tools go, as a
|
|
20371
|
+
// click elsewhere does.
|
|
20372
|
+
const from = this.selectedObject(this.range()) || this.clickedSpacer();
|
|
19954
20373
|
if (from && this.builder.util && this.builder.util.hideControls) this.builder.util.hideControls();
|
|
19955
20374
|
if (from) this.dropIcon();
|
|
19956
|
-
if (isPicture(target) || target.getAttribute('contenteditable') === 'false') {
|
|
20375
|
+
if (isPicture(target) || isMedia(target) || isIconLink(target) || target.getAttribute('contenteditable') === 'false') {
|
|
19957
20376
|
this.selectObject(target);
|
|
19958
20377
|
return;
|
|
19959
20378
|
}
|
|
19960
20379
|
this.focusPlace(target);
|
|
19961
20380
|
if (how.x != null) this.caretAtX(target, how.x, how.last);else this.caretAtEdge(target, how.end);
|
|
20381
|
+
// Back in text from an object: what a click on the text shows (the
|
|
20382
|
+
// object's tool goes; ContentBox's panel turns back to the text's).
|
|
20383
|
+
if (from && this.builder.util && this.builder.util.clickElement) this.builder.util.clickElement(target);
|
|
19962
20384
|
if (this.builder.opts.onChange && how.changed) this.builder.opts.onChange();
|
|
19963
20385
|
}
|
|
19964
20386
|
|
|
@@ -19975,6 +20397,10 @@ class CaretNav {
|
|
|
19975
20397
|
this.tab(e);
|
|
19976
20398
|
return;
|
|
19977
20399
|
}
|
|
20400
|
+
if ((key === 'Backspace' || key === 'Delete') && !e.shiftKey) {
|
|
20401
|
+
if (!this.removeObject(e, key === 'Delete')) this.removeEmptyLine(e, key === 'Delete');
|
|
20402
|
+
return;
|
|
20403
|
+
}
|
|
19978
20404
|
if (e.shiftKey || !/^Arrow(Up|Down|Left|Right)$/.test(key)) return;
|
|
19979
20405
|
const range = this.range();
|
|
19980
20406
|
const forward0 = key === 'ArrowDown' || key === 'ArrowRight';
|
|
@@ -20019,6 +20445,72 @@ class CaretNav {
|
|
|
20019
20445
|
});
|
|
20020
20446
|
}
|
|
20021
20447
|
|
|
20448
|
+
/* Backspace or Delete with a locked block selected whole (a video, a
|
|
20449
|
+
plugin, a spacer): only the block goes, as the element tool's Delete
|
|
20450
|
+
does, and the caret goes to the text before it (Backspace) or after it
|
|
20451
|
+
(Delete). Left to the text engine, the selection around the block was
|
|
20452
|
+
deleted like text across two paragraphs, which joined them. */
|
|
20453
|
+
removeObject(e, forward) {
|
|
20454
|
+
const b = this.builder;
|
|
20455
|
+
const obj = this.selectedObject(this.range());
|
|
20456
|
+
if (!obj || isPicture(obj) || !isMedia(obj) && obj.getAttribute('contenteditable') !== 'false' && !obj.matches('[data-cb-object]')) return false;
|
|
20457
|
+
const col = this.columnOf(obj.parentElement);
|
|
20458
|
+
if (!col) return false;
|
|
20459
|
+
e.preventDefault();
|
|
20460
|
+
e.stopImmediatePropagation();
|
|
20461
|
+
const all = this.places();
|
|
20462
|
+
const i = all.indexOf(obj);
|
|
20463
|
+
const before = all[i - 1],
|
|
20464
|
+
after = all[i + 1];
|
|
20465
|
+
let target = forward ? after || before : before || after;
|
|
20466
|
+
if (target && this.isObject(target)) target = null;
|
|
20467
|
+
if (b.util && b.util.hideControls) b.util.hideControls();
|
|
20468
|
+
this.dropIcon();
|
|
20469
|
+
this.pending = null;
|
|
20470
|
+
b.uo.saveForUndo();
|
|
20471
|
+
// A player or an embed goes with its line (its wrapper and overlay).
|
|
20472
|
+
const gone = isMedia(obj) ? this.lineOf(obj) || obj : obj;
|
|
20473
|
+
const parent = gone.parentElement;
|
|
20474
|
+
gone.remove();
|
|
20475
|
+
// An emptied wrapper goes too; an emptied column keeps a line to type on.
|
|
20476
|
+
if (parent !== col && !parent.children.length && !hasText(parent)) parent.remove();
|
|
20477
|
+
if (!col.children.length) {
|
|
20478
|
+
const line = b.doc.createElement('p');
|
|
20479
|
+
line.appendChild(b.doc.createElement('br'));
|
|
20480
|
+
col.appendChild(line);
|
|
20481
|
+
target = line;
|
|
20482
|
+
}
|
|
20483
|
+
if (b.opts.onChange) b.opts.onChange();
|
|
20484
|
+
if (target && target.isConnected) {
|
|
20485
|
+
this.focusPlace(target);
|
|
20486
|
+
this.caretAtEdge(target, target === before);
|
|
20487
|
+
if (b.util && b.util.clickElement) b.util.clickElement(target);
|
|
20488
|
+
}
|
|
20489
|
+
return true;
|
|
20490
|
+
}
|
|
20491
|
+
|
|
20492
|
+
/* Backspace on an empty line just after an object (a video, a spacer, a
|
|
20493
|
+
plugin), or Delete on one just before it: the line goes and the object
|
|
20494
|
+
is selected, so the next Backspace / Delete removes it. The engine
|
|
20495
|
+
cannot join an empty line with a locked block, and did nothing. */
|
|
20496
|
+
removeEmptyLine(e, forward) {
|
|
20497
|
+
const b = this.builder;
|
|
20498
|
+
const range = this.range();
|
|
20499
|
+
if (!range || !range.collapsed) return;
|
|
20500
|
+
const place = this.placeOf(range.startContainer);
|
|
20501
|
+
if (!place || place.closest(OWN_NAV) || this.isObject(place) || hasText(place) || place.querySelector('img, svg, iframe, video')) return;
|
|
20502
|
+
const all = this.places();
|
|
20503
|
+
const i = all.indexOf(place);
|
|
20504
|
+
const obj = all[forward ? i + 1 : i - 1];
|
|
20505
|
+
if (!obj || !this.isObject(obj) || this.columnOf(obj.parentElement) !== this.columnOf(place)) return;
|
|
20506
|
+
e.preventDefault();
|
|
20507
|
+
e.stopImmediatePropagation();
|
|
20508
|
+
b.uo.saveForUndo();
|
|
20509
|
+
place.remove();
|
|
20510
|
+
if (b.opts.onChange) b.opts.onChange();
|
|
20511
|
+
this.selectObject(obj);
|
|
20512
|
+
}
|
|
20513
|
+
|
|
20022
20514
|
// In a list or a table, a move that leaves it (to the next block) is ours
|
|
20023
20515
|
// too: the browser left the caret between the blocks, in no text.
|
|
20024
20516
|
leavesGroup(place, key) {
|
|
@@ -20074,8 +20566,8 @@ class CaretNav {
|
|
|
20074
20566
|
enter(e) {
|
|
20075
20567
|
const b = this.builder;
|
|
20076
20568
|
const range = this.range();
|
|
20077
|
-
|
|
20078
|
-
|
|
20569
|
+
const obj = this.selectedObject(range) || this.clickedSpacer();
|
|
20570
|
+
if (!range && !obj) return;
|
|
20079
20571
|
if (obj) {
|
|
20080
20572
|
e.preventDefault();
|
|
20081
20573
|
e.stopImmediatePropagation();
|
|
@@ -20083,7 +20575,7 @@ class CaretNav {
|
|
|
20083
20575
|
const p = b.doc.createElement('p');
|
|
20084
20576
|
p.appendChild(b.doc.createElement('br'));
|
|
20085
20577
|
// A picture is in a line of its own: the paragraph goes after the line.
|
|
20086
|
-
(isPicture(obj) ? this.lineOf(obj) || obj : obj).after(p);
|
|
20578
|
+
(isPicture(obj) || isMedia(obj) ? this.lineOf(obj) || obj : obj).after(p);
|
|
20087
20579
|
this.go(p, {
|
|
20088
20580
|
end: false,
|
|
20089
20581
|
changed: true
|
|
@@ -34429,9 +34921,7 @@ class ButtonEditor {
|
|
|
34429
34921
|
if (!el) return;
|
|
34430
34922
|
this.builder.uo.saveForUndo(true); // checkLater
|
|
34431
34923
|
|
|
34432
|
-
const
|
|
34433
|
-
let current = '';
|
|
34434
|
-
if (cmd === 'color-bg') current = resolveColor(el, el.style.backgroundColor, 'backgroundColor') || dom.getStyle(el, 'background-color');else if (cmd === 'color-text') current = resolveColor(el, el.style.color, 'color') || dom.getStyle(el, 'color');else if (cmd === 'hover-bg') current = resolveColor(el, readButton(el).hoverBg, '--cb-hover-bg');else if (cmd === 'hover-text') current = resolveColor(el, readButton(el).hoverColor, '--cb-hover-color');else if (cmd === 'hover-border') current = resolveColor(el, readButton(el).hoverBorder, '--cb-hover-border');
|
|
34924
|
+
const current = this.swatchColor(el, cmd);
|
|
34435
34925
|
btn.setAttribute('data-focus', true);
|
|
34436
34926
|
this.builder.colorPicker.open(color => {
|
|
34437
34927
|
const el = this.getButton();
|
|
@@ -34584,7 +35074,6 @@ class ButtonEditor {
|
|
|
34584
35074
|
realtime() {
|
|
34585
35075
|
const el = this.getButton();
|
|
34586
35076
|
if (!el) return;
|
|
34587
|
-
const dom = this.dom;
|
|
34588
35077
|
const modal = this.buttonModal;
|
|
34589
35078
|
const r = readButton(el);
|
|
34590
35079
|
this.syncSeg('size', r.sizeKey);
|
|
@@ -34609,14 +35098,21 @@ class ButtonEditor {
|
|
|
34609
35098
|
if (href && document.activeElement !== href) href.value = r.href;
|
|
34610
35099
|
const newtab = modal.querySelector('[data-cmd="newtab"]');
|
|
34611
35100
|
if (newtab) newtab.checked = r.newTab;
|
|
35101
|
+
['color-bg', 'color-text', 'hover-bg', 'hover-text', 'hover-border'].forEach(cmd => this.paintSwatch(cmd, this.swatchColor(el, cmd)));
|
|
35102
|
+
}
|
|
34612
35103
|
|
|
34613
|
-
|
|
34614
|
-
|
|
34615
|
-
|
|
34616
|
-
|
|
34617
|
-
|
|
34618
|
-
|
|
34619
|
-
|
|
35104
|
+
// The colour a swatch shows and its picker starts from. Normal colours come
|
|
35105
|
+
// from the style attribute first: a selected button has focus, so its
|
|
35106
|
+
// computed colours are its :focus-visible hover colours. The computed style
|
|
35107
|
+
// is only the fallback, so a bg-*/text-* class still previews.
|
|
35108
|
+
swatchColor(el, cmd) {
|
|
35109
|
+
const r = readButton(el);
|
|
35110
|
+
if (cmd === 'color-bg') return resolveColor(el, r.bg, 'backgroundColor') || this.dom.getStyle(el, 'background-color');
|
|
35111
|
+
if (cmd === 'color-text') return resolveColor(el, r.color, 'color') || this.dom.getStyle(el, 'color');
|
|
35112
|
+
if (cmd === 'hover-bg') return resolveColor(el, r.hoverBg, '--cb-hover-bg');
|
|
35113
|
+
if (cmd === 'hover-text') return resolveColor(el, r.hoverColor, '--cb-hover-color');
|
|
35114
|
+
if (cmd === 'hover-border') return resolveColor(el, r.hoverBorder, '--cb-hover-border');
|
|
35115
|
+
return '';
|
|
34620
35116
|
}
|
|
34621
35117
|
syncSeg(cmd, value) {
|
|
34622
35118
|
this.buttonModal.querySelectorAll(`[data-cmd="${cmd}"]`).forEach(b => {
|
|
@@ -34987,11 +35483,7 @@ class Hyperlink {
|
|
|
34987
35483
|
|
|
34988
35484
|
// https://stackoverflow.com/questions/29908261/prevent-text-selection-on-mouse-drag
|
|
34989
35485
|
// prevent text selection
|
|
34990
|
-
|
|
34991
|
-
this.builder.doc.selection.empty();
|
|
34992
|
-
} else {
|
|
34993
|
-
window.getSelection().removeAllRanges();
|
|
34994
|
-
}
|
|
35486
|
+
this.builder.win.getSelection().removeAllRanges(); // the content's window (ContentBox: a frame)
|
|
34995
35487
|
}
|
|
34996
35488
|
} else {
|
|
34997
35489
|
const selectionText = this.builder.selectionText;
|
|
@@ -35344,6 +35836,9 @@ class Hyperlink {
|
|
|
35344
35836
|
const util = this.builder.util;
|
|
35345
35837
|
const dom = this.builder.dom;
|
|
35346
35838
|
let link = this.builder.activeLink;
|
|
35839
|
+
// The tool still on show for a link that is gone (the content was
|
|
35840
|
+
// replaced, by Undo or a reload): nothing to edit.
|
|
35841
|
+
if (!link || !link.isConnected) return;
|
|
35347
35842
|
let modal = builderStuff.querySelector('.is-modal.createlink');
|
|
35348
35843
|
let icon = link.querySelector('i');
|
|
35349
35844
|
modal.querySelector('#lblCreateLinkText').style.display = '';
|
|
@@ -35673,12 +36168,9 @@ class Spacer {
|
|
|
35673
36168
|
if (dom.hasClass(elm, 'spacer')) {
|
|
35674
36169
|
this.builder.activeSpacer = elm;
|
|
35675
36170
|
|
|
35676
|
-
// prevent text selection
|
|
35677
|
-
|
|
35678
|
-
|
|
35679
|
-
} else {
|
|
35680
|
-
window.getSelection().removeAllRanges();
|
|
35681
|
-
}
|
|
36171
|
+
// prevent text selection (in the content's window: ContentBox's
|
|
36172
|
+
// content is in a frame)
|
|
36173
|
+
this.builder.win.getSelection().removeAllRanges();
|
|
35682
36174
|
this.showTool(elm);
|
|
35683
36175
|
} else {
|
|
35684
36176
|
this.hideTool();
|
|
@@ -38978,12 +39470,9 @@ class Svg {
|
|
|
38978
39470
|
if (svg) {
|
|
38979
39471
|
this.builder.activeSvg = svg;
|
|
38980
39472
|
|
|
38981
|
-
// prevent text selection
|
|
38982
|
-
|
|
38983
|
-
|
|
38984
|
-
} else {
|
|
38985
|
-
window.getSelection().removeAllRanges();
|
|
38986
|
-
}
|
|
39473
|
+
// prevent text selection (in the content's window: ContentBox's
|
|
39474
|
+
// content is in a frame)
|
|
39475
|
+
this.builder.win.getSelection().removeAllRanges();
|
|
38987
39476
|
|
|
38988
39477
|
// Use the current icon-active class
|
|
38989
39478
|
this.builder.doc.querySelectorAll('.icon-active').forEach(elm => elm.classList.remove('icon-active'));
|
|
@@ -38996,7 +39485,14 @@ class Svg {
|
|
|
38996
39485
|
}
|
|
38997
39486
|
showTool() {
|
|
38998
39487
|
// Add-on buttons show only for the drawings they are for.
|
|
38999
|
-
|
|
39488
|
+
const host = this.builder.addonHost;
|
|
39489
|
+
if (host) host.updateTool('svg', this.builder.activeSvg);
|
|
39490
|
+
// A host whose side panel has the add-on's edit button for this block or
|
|
39491
|
+
// drawing (ContentBox): the panel is its tools, so none beside it.
|
|
39492
|
+
if (host && host.panelHasTools(this.builder.activeSvg)) {
|
|
39493
|
+
this.svgTool.style.display = '';
|
|
39494
|
+
return;
|
|
39495
|
+
}
|
|
39000
39496
|
this.svgTool.style.display = 'flex';
|
|
39001
39497
|
this.repositionModuleTool();
|
|
39002
39498
|
}
|
|
@@ -60744,10 +61240,21 @@ function stripZwsp(scope, keep) {
|
|
|
60744
61240
|
if (t !== keep && t.data.indexOf(ZWSP) !== -1) dirty.push(t);
|
|
60745
61241
|
}
|
|
60746
61242
|
for (const node of dirty) {
|
|
60747
|
-
|
|
61243
|
+
const held = holdsDrawing(node);
|
|
61244
|
+
node.data = (held ? ZWSP : '') + (held ? node.data.slice(1) : node.data).split(ZWSP).join('');
|
|
60748
61245
|
}
|
|
60749
61246
|
}
|
|
60750
61247
|
|
|
61248
|
+
/* The ZWSP right after a drawing in a line of text (an icon, an equation in
|
|
61249
|
+
a sentence): without it, the browser has no caret place after the <svg>
|
|
61250
|
+
and draws the caret before it (ContentBuilder's editingengine.js keeps
|
|
61251
|
+
one there while editing). Not stripped while editing; the saved HTML
|
|
61252
|
+
drops it with the others. */
|
|
61253
|
+
function holdsDrawing(t) {
|
|
61254
|
+
const prev = t && t.previousSibling;
|
|
61255
|
+
return !!prev && prev.nodeType === 1 && prev.nodeName.toLowerCase() === 'svg' && t.data.charAt(0) === ZWSP;
|
|
61256
|
+
}
|
|
61257
|
+
|
|
60751
61258
|
/*
|
|
60752
61259
|
widgets.js — non-editable islands (contenteditable="false").
|
|
60753
61260
|
|
|
@@ -65006,6 +65513,30 @@ const FORMAT_INPUT_TYPES = {
|
|
|
65006
65513
|
formatUnderline: 'underline',
|
|
65007
65514
|
formatStrikeThrough: 'strike'
|
|
65008
65515
|
};
|
|
65516
|
+
|
|
65517
|
+
/* After a delete done by hand (see _keepDrawings): a space left at an
|
|
65518
|
+
edge of the line, or two in a row (also across two text nodes), would
|
|
65519
|
+
not show, so it becomes a non-breaking one, as the browser's own delete
|
|
65520
|
+
writes it. Same length, so a caret offset holds. */
|
|
65521
|
+
function keepSpacesAt(node, off) {
|
|
65522
|
+
const nb = '\u00a0';
|
|
65523
|
+
const fix = t => {
|
|
65524
|
+
if (!t || t.nodeType !== 3) return;
|
|
65525
|
+
let s = t.data.replace(/ {2}/g, ' ' + nb);
|
|
65526
|
+
const prev = t.previousSibling;
|
|
65527
|
+
if (s[0] === ' ' && (!prev || / $/.test(prev.textContent || ''))) s = nb + s.slice(1);
|
|
65528
|
+
if (s[s.length - 1] === ' ' && !t.nextSibling) s = s.slice(0, -1) + nb;
|
|
65529
|
+
if (s !== t.data) t.data = s;
|
|
65530
|
+
};
|
|
65531
|
+
if (node.nodeType === 3) {
|
|
65532
|
+
fix(node.previousSibling);
|
|
65533
|
+
fix(node);
|
|
65534
|
+
fix(node.nextSibling);
|
|
65535
|
+
} else {
|
|
65536
|
+
fix(node.childNodes[off - 1]);
|
|
65537
|
+
fix(node.childNodes[off]);
|
|
65538
|
+
}
|
|
65539
|
+
}
|
|
65009
65540
|
class Inscribe {
|
|
65010
65541
|
static instances = new Set();
|
|
65011
65542
|
static active = null;
|
|
@@ -66962,6 +67493,16 @@ class Inscribe {
|
|
|
66962
67493
|
return;
|
|
66963
67494
|
}
|
|
66964
67495
|
}
|
|
67496
|
+
|
|
67497
|
+
/* Safari on a Mac sends Return's insertNewline: for Shift+Enter, a new
|
|
67498
|
+
paragraph, as macOS binds insertLineBreak: to Control+Return. Both
|
|
67499
|
+
engines' Shift+Enter becomes the same <br>. */
|
|
67500
|
+
if ((it === 'insertParagraph' || it === 'insertLineBreak') && this._shiftEnter && range.collapsed) {
|
|
67501
|
+
e.preventDefault();
|
|
67502
|
+
this._shiftEnter = false;
|
|
67503
|
+
this._lineBreak(range);
|
|
67504
|
+
return;
|
|
67505
|
+
}
|
|
66965
67506
|
if (it === 'insertParagraph') {
|
|
66966
67507
|
e.preventDefault();
|
|
66967
67508
|
this._enter(range);
|
|
@@ -66996,6 +67537,7 @@ class Inscribe {
|
|
|
66996
67537
|
return; /* consumed: a magic conversion, its own history step */
|
|
66997
67538
|
}
|
|
66998
67539
|
|
|
67540
|
+
if (!range.collapsed && this._keepDrawings(e, range, it)) return;
|
|
66999
67541
|
this.history.record('typing');
|
|
67000
67542
|
return;
|
|
67001
67543
|
}
|
|
@@ -67039,11 +67581,115 @@ class Inscribe {
|
|
|
67039
67581
|
return;
|
|
67040
67582
|
}
|
|
67041
67583
|
}
|
|
67584
|
+
if (this._keepDrawings(e, range, it)) return;
|
|
67042
67585
|
this.history.record('deleting');
|
|
67043
67586
|
return;
|
|
67044
67587
|
}
|
|
67045
67588
|
this.history.record('command');
|
|
67046
67589
|
}
|
|
67590
|
+
|
|
67591
|
+
/* Chrome's and Safari's own delete sweeps away an inline <svg> (an
|
|
67592
|
+
icon, an equation in a sentence) along with the text next to it:
|
|
67593
|
+
Backspace just before an icon, or the space beside it selected and
|
|
67594
|
+
deleted, lost the icon too. When the block holds a drawing the
|
|
67595
|
+
delete does not reach, the text is deleted here instead (typing
|
|
67596
|
+
over a selection too). A delete that takes the drawing itself is
|
|
67597
|
+
left to the browser, which removes it correctly. */
|
|
67598
|
+
_keepDrawings(e, range, it) {
|
|
67599
|
+
const block = closestBlock(caretNode(range), this.root);
|
|
67600
|
+
if (!block || !block.querySelector('svg')) return false;
|
|
67601
|
+
/* Right beside one, on the key's side: the key removes it. (The
|
|
67602
|
+
browser does not see it as there and deletes the character
|
|
67603
|
+
beyond it instead.) */
|
|
67604
|
+
if (range.collapsed && it.indexOf('delete') === 0) {
|
|
67605
|
+
const back = /Backward/.test(it);
|
|
67606
|
+
const n = range.startContainer,
|
|
67607
|
+
o = range.startOffset;
|
|
67608
|
+
let beside = null;
|
|
67609
|
+
/* a drawing's zero-width caret place (dom.js holdsDrawing) is no character */
|
|
67610
|
+
const zw = t => t.split(ZWSP).join('') === '';
|
|
67611
|
+
if (n.nodeType === 3) beside = back ? zw(n.data.slice(0, o)) ? n.previousSibling : null : zw(n.data.slice(o)) ? n.nextSibling : null;else beside = back ? n.childNodes[o - 1] : n.childNodes[o];
|
|
67612
|
+
if (beside && beside.nodeType === 1 && beside.tagName.toLowerCase() === 'svg' && block.contains(beside) && !isSealed(beside, this.root)) {
|
|
67613
|
+
e.preventDefault();
|
|
67614
|
+
this.history.record('deleting');
|
|
67615
|
+
const r = this.doc.createRange();
|
|
67616
|
+
r.setStartBefore(beside);
|
|
67617
|
+
r.collapse(true);
|
|
67618
|
+
beside.remove();
|
|
67619
|
+
keepSpacesAt(r.startContainer, r.startOffset);
|
|
67620
|
+
this._setCaret(r.startContainer, r.startOffset);
|
|
67621
|
+
this._afterEdit();
|
|
67622
|
+
const Ev0 = this.doc.defaultView && this.doc.defaultView.InputEvent || InputEvent;
|
|
67623
|
+
this.root.dispatchEvent(new Ev0('input', {
|
|
67624
|
+
bubbles: true,
|
|
67625
|
+
inputType: it,
|
|
67626
|
+
data: null
|
|
67627
|
+
}));
|
|
67628
|
+
return true;
|
|
67629
|
+
}
|
|
67630
|
+
}
|
|
67631
|
+
const targets = typeof e.getTargetRanges === 'function' ? e.getTargetRanges() : [];
|
|
67632
|
+
let target = null;
|
|
67633
|
+
if (targets.length) {
|
|
67634
|
+
target = this.doc.createRange();
|
|
67635
|
+
target.setStart(targets[0].startContainer, targets[0].startOffset);
|
|
67636
|
+
target.setEnd(targets[0].endContainer, targets[0].endOffset);
|
|
67637
|
+
} else if (!range.collapsed) {
|
|
67638
|
+
target = range.cloneRange();
|
|
67639
|
+
}
|
|
67640
|
+
if (!target || target.collapsed || !block.contains(target.commonAncestorContainer)) return false;
|
|
67641
|
+
/* Only a drawing's zero-width caret place in it: that is no character,
|
|
67642
|
+
the delete takes the next real one (else the key did nothing). */
|
|
67643
|
+
if (target.toString().split(ZWSP).join('') === '' && /^delete/.test(it) && target.startContainer === target.endContainer && target.startContainer.nodeType === 3) {
|
|
67644
|
+
const t = target.startContainer;
|
|
67645
|
+
if (/Backward/.test(it) && target.startOffset > 0) target.setStart(t, target.startOffset - 1);else if (/Forward/.test(it) && target.endOffset < t.length) target.setEnd(t, target.endOffset + 1);
|
|
67646
|
+
}
|
|
67647
|
+
if (target.cloneContents().querySelector('svg')) return false;
|
|
67648
|
+
e.preventDefault();
|
|
67649
|
+
const text = it.indexOf('insert') === 0 ? e.data || '' : '';
|
|
67650
|
+
this.history.record(text ? 'typing' : 'deleting');
|
|
67651
|
+
target.deleteContents();
|
|
67652
|
+
let node = target.startContainer;
|
|
67653
|
+
let off = target.startOffset;
|
|
67654
|
+
if (text) {
|
|
67655
|
+
if (node.nodeType === 3) {
|
|
67656
|
+
node.insertData(off, text);
|
|
67657
|
+
off += text.length;
|
|
67658
|
+
} else {
|
|
67659
|
+
const t = this.doc.createTextNode(text);
|
|
67660
|
+
target.insertNode(t);
|
|
67661
|
+
node = t;
|
|
67662
|
+
off = text.length;
|
|
67663
|
+
}
|
|
67664
|
+
}
|
|
67665
|
+
keepSpacesAt(node, off);
|
|
67666
|
+
this._setCaret(node, off);
|
|
67667
|
+
this._afterEdit();
|
|
67668
|
+
/* No native input follows a prevented one: listeners for typing
|
|
67669
|
+
(a slash menu filtering as you type) still hear it. */
|
|
67670
|
+
const Ev = this.doc.defaultView && this.doc.defaultView.InputEvent || InputEvent;
|
|
67671
|
+
this.root.dispatchEvent(new Ev('input', {
|
|
67672
|
+
bubbles: true,
|
|
67673
|
+
inputType: it,
|
|
67674
|
+
data: e.data || null
|
|
67675
|
+
}));
|
|
67676
|
+
return true;
|
|
67677
|
+
}
|
|
67678
|
+
|
|
67679
|
+
/* A <br> at the caret, with a second one at the end of a block, where a
|
|
67680
|
+
lone trailing <br> shows no new line */
|
|
67681
|
+
_lineBreak(range) {
|
|
67682
|
+
this.history.record('command');
|
|
67683
|
+
const block = closestBlock(caretNode(range), this.root);
|
|
67684
|
+
const atEnd = block && atBlockEnd(block, range);
|
|
67685
|
+
const br = this.doc.createElement('br');
|
|
67686
|
+
range.insertNode(br);
|
|
67687
|
+
if (atEnd && !(br.nextSibling && br.nextSibling.nodeName === 'BR')) {
|
|
67688
|
+
br.after(this.doc.createElement('br'));
|
|
67689
|
+
}
|
|
67690
|
+
this._setCaretAfter(br);
|
|
67691
|
+
this._afterEdit();
|
|
67692
|
+
}
|
|
67047
67693
|
_enter(range) {
|
|
67048
67694
|
this.history.record('command');
|
|
67049
67695
|
|
|
@@ -67312,6 +67958,8 @@ class Inscribe {
|
|
|
67312
67958
|
_handleKeyDown(e) {
|
|
67313
67959
|
if (this._readOnly) return;
|
|
67314
67960
|
if (this._foreignCaret()) return; // belongs to a nested editable island
|
|
67961
|
+
/* Shift+Enter is a line break in every browser (see _handleBeforeInput) */
|
|
67962
|
+
this._shiftEnter = e.key === 'Enter' && e.shiftKey && !e.metaKey && !e.ctrlKey && !e.altKey && !e.isComposing && e.keyCode !== 229;
|
|
67315
67963
|
/* Cell region: Escape clears it; caret navigation drops it first
|
|
67316
67964
|
and then behaves normally from the anchor cell. */
|
|
67317
67965
|
if (this.tableUI.active) {
|
|
@@ -67655,6 +68303,7 @@ function dataUrlToFile(dataUrl, baseName) {
|
|
|
67655
68303
|
leaves to the host to paint (without these the cell selection
|
|
67656
68304
|
is invisible — nothing to see when you drag across cells).
|
|
67657
68305
|
No Inscribe code is modified. */
|
|
68306
|
+
const ZWSP_CHAR = '\u200B'; // see InscribeEngine.holdDrawings()
|
|
67658
68307
|
const INSCRIBE_STYLE_ID = 'cb-inscribe-styles';
|
|
67659
68308
|
function ensureInscribeStyles(doc) {
|
|
67660
68309
|
if (!doc || doc.getElementById(INSCRIBE_STYLE_ID)) return;
|
|
@@ -68664,8 +69313,99 @@ class InscribeEngine {
|
|
|
68664
69313
|
this.regions.set(el, region);
|
|
68665
69314
|
}
|
|
68666
69315
|
region.attach();
|
|
69316
|
+
this._watchRemovals(el.ownerDocument);
|
|
69317
|
+
this.holdDrawings(el);
|
|
68667
69318
|
return region;
|
|
68668
69319
|
}
|
|
69320
|
+
|
|
69321
|
+
// A drawing in a line of text (an icon, an equation in a sentence) gets a
|
|
69322
|
+
// zero-width space right after it. Chrome and Safari have no caret place
|
|
69323
|
+
// after an inline <svg>: the arrow went from before it to past the next
|
|
69324
|
+
// letter, and the caret was drawn before it while it was after it. The
|
|
69325
|
+
// character gives that place. Not on a drawing alone on its line (the
|
|
69326
|
+
// arrows select that one whole, caretnav.js). Inscribe keeps it while
|
|
69327
|
+
// editing (dom.js holdsDrawing); the saved HTML drops it (html.js).
|
|
69328
|
+
holdDrawings(scope) {
|
|
69329
|
+
if (!scope || !scope.querySelectorAll) return;
|
|
69330
|
+
const nav = this.builder.caretNav;
|
|
69331
|
+
scope.querySelectorAll('svg').forEach(svg => {
|
|
69332
|
+
if (svg.parentElement && svg.parentElement.closest('svg')) return;
|
|
69333
|
+
if (svg.closest('[data-cb-type],[contenteditable="false"]') || !svg.closest('[contenteditable="true"]')) return;
|
|
69334
|
+
if (nav && nav.isPictureLine(svg)) return;
|
|
69335
|
+
const next = svg.nextSibling;
|
|
69336
|
+
if (next && next.nodeType === 3 && next.data.charAt(0) === ZWSP_CHAR) return;
|
|
69337
|
+
if (next && next.nodeType === 3) next.insertData(0, ZWSP_CHAR);else svg.after(svg.ownerDocument.createTextNode(ZWSP_CHAR));
|
|
69338
|
+
});
|
|
69339
|
+
}
|
|
69340
|
+
|
|
69341
|
+
// A picture removed by anything other than typing (the element tool's or
|
|
69342
|
+
// an add-on's Remove, a block deleted with it) is not an edit the region
|
|
69343
|
+
// sees, and its resize handles stayed on screen with nothing under them.
|
|
69344
|
+
// One watch per document: handles whose picture has gone are hidden.
|
|
69345
|
+
_watchRemovals(doc) {
|
|
69346
|
+
if (!doc || !doc.body) return;
|
|
69347
|
+
this._watched = this._watched || new WeakSet();
|
|
69348
|
+
if (this._watched.has(doc)) return;
|
|
69349
|
+
this._watched.add(doc);
|
|
69350
|
+
const win = doc.defaultView || window;
|
|
69351
|
+
const mo = new win.MutationObserver(records => {
|
|
69352
|
+
// A drawing put in a line, or text typed beside one: its caret place
|
|
69353
|
+
// (holdDrawings), in the columns that changed.
|
|
69354
|
+
const cols = new Set();
|
|
69355
|
+
for (const rec of records) {
|
|
69356
|
+
const at = rec.target.nodeType === 1 ? rec.target : rec.target.parentElement;
|
|
69357
|
+
const col = at && at.closest && at.closest('[contenteditable="true"]');
|
|
69358
|
+
if (col && this.regions.has(col)) cols.add(col);
|
|
69359
|
+
}
|
|
69360
|
+
cols.forEach(col => this.holdDrawings(col));
|
|
69361
|
+
// A drawing removed (Delete, its tool's Remove, an add-on): its caret
|
|
69362
|
+
// place goes with it, else an arrow there would seem to do nothing.
|
|
69363
|
+
for (const rec of records) {
|
|
69364
|
+
if (!Array.from(rec.removedNodes).some(x => x.nodeType === 1 && x.nodeName.toLowerCase() === 'svg')) continue;
|
|
69365
|
+
const z = rec.nextSibling;
|
|
69366
|
+
if (z && z.nodeType === 3 && z.isConnected && z.data.charAt(0) === ZWSP_CHAR && !(z.previousSibling && z.previousSibling.nodeType === 1 && z.previousSibling.nodeName.toLowerCase() === 'svg')) {
|
|
69367
|
+
z.deleteData(0, 1);
|
|
69368
|
+
if (!z.data.length && z.parentNode) z.remove();
|
|
69369
|
+
}
|
|
69370
|
+
}
|
|
69371
|
+
if (!records.some(r => r.removedNodes.length)) return;
|
|
69372
|
+
for (const r of this.regions.values()) {
|
|
69373
|
+
const ui = r.ed && r.ed.imageUI;
|
|
69374
|
+
if (ui && ui.img && !ui.img.isConnected) ui._hide();
|
|
69375
|
+
}
|
|
69376
|
+
// The element the toolbar (and ContentBox's panel) is for has gone
|
|
69377
|
+
// (a selected picture, drawing or block deleted with the keyboard, its
|
|
69378
|
+
// panel's Remove, an add-on). Nothing clicked, so they stayed on it,
|
|
69379
|
+
// with the caret back in the text. A click where the caret is, as the
|
|
69380
|
+
// keyboard walk does (toolbarkeys.js), brings back the ones for it.
|
|
69381
|
+
const b = this.builder;
|
|
69382
|
+
const gone = b.inspectedElement && !b.inspectedElement.isConnected;
|
|
69383
|
+
if (gone && !this._refreshing) {
|
|
69384
|
+
this._refreshing = true;
|
|
69385
|
+
setTimeout(() => {
|
|
69386
|
+
this._refreshing = false;
|
|
69387
|
+
if (b.inspectedElement && b.inspectedElement.isConnected) return;
|
|
69388
|
+
const sel = doc.getSelection();
|
|
69389
|
+
const n = sel && sel.rangeCount ? sel.focusNode : null;
|
|
69390
|
+
const el = n && (n.nodeType === 1 ? n : n.parentElement);
|
|
69391
|
+
const col = el && el.closest('[contenteditable="true"]');
|
|
69392
|
+
if (!col || !this.regions.has(col)) return;
|
|
69393
|
+
const a = doc.activeElement;
|
|
69394
|
+
if (!a || !(a === col || col.contains(a))) return;
|
|
69395
|
+
el.dispatchEvent(new win.MouseEvent('click', {
|
|
69396
|
+
bubbles: true,
|
|
69397
|
+
cancelable: true,
|
|
69398
|
+
view: win
|
|
69399
|
+
}));
|
|
69400
|
+
}, 0);
|
|
69401
|
+
}
|
|
69402
|
+
});
|
|
69403
|
+
mo.observe(doc.body, {
|
|
69404
|
+
childList: true,
|
|
69405
|
+
subtree: true,
|
|
69406
|
+
characterData: true
|
|
69407
|
+
});
|
|
69408
|
+
}
|
|
68669
69409
|
destroyRegion(el) {
|
|
68670
69410
|
const region = this.regions.get(el);
|
|
68671
69411
|
if (region) {
|
|
@@ -69141,9 +69881,31 @@ class TableTool {
|
|
|
69141
69881
|
this._openSettings();
|
|
69142
69882
|
break;
|
|
69143
69883
|
case 'deltable':
|
|
69144
|
-
|
|
69145
|
-
|
|
69146
|
-
|
|
69884
|
+
{
|
|
69885
|
+
// The caret goes to where the table was (the line after it, else the
|
|
69886
|
+
// one before), so typing carries on; the button it was on is gone.
|
|
69887
|
+
const table = this.table;
|
|
69888
|
+
const next = table && table.nextElementSibling;
|
|
69889
|
+
const prev = table && table.previousElementSibling;
|
|
69890
|
+
const col = table && table.closest('[contenteditable="true"]');
|
|
69891
|
+
ed.deleteTable();
|
|
69892
|
+
this.hide();
|
|
69893
|
+
if (col && col.isConnected) {
|
|
69894
|
+
const doc = this.builder.doc;
|
|
69895
|
+
const at = next && next.isConnected && next || prev && prev.isConnected && prev || col;
|
|
69896
|
+
const r = doc.createRange();
|
|
69897
|
+
r.selectNodeContents(at);
|
|
69898
|
+
r.collapse(at !== prev);
|
|
69899
|
+
if (this.builder.win !== window) this.builder.win.focus();
|
|
69900
|
+
col.focus({
|
|
69901
|
+
preventScroll: true
|
|
69902
|
+
});
|
|
69903
|
+
const sel = doc.getSelection();
|
|
69904
|
+
sel.removeAllRanges();
|
|
69905
|
+
sel.addRange(r);
|
|
69906
|
+
}
|
|
69907
|
+
break;
|
|
69908
|
+
}
|
|
69147
69909
|
}
|
|
69148
69910
|
}
|
|
69149
69911
|
|
|
@@ -80035,8 +80797,6 @@ class ContentStuff {
|
|
|
80035
80797
|
/* Works on any button colour: a white ring at the edge, a dark ring inside
|
|
80036
80798
|
it. A single hue cannot stay legible over the green, yellow and orange
|
|
80037
80799
|
tools. */
|
|
80038
|
-
.is-section-tool button:focus-visible,
|
|
80039
|
-
.is-box-tool button:focus-visible,
|
|
80040
80800
|
.is-rowadd-tool button:focus-visible,
|
|
80041
80801
|
/* A canvas block is a stop in the tab order, so which one has the keyboard
|
|
80042
80802
|
has to be visible. Mouse selection has its own look already. */
|
|
@@ -80050,8 +80810,12 @@ class ContentStuff {
|
|
|
80050
80810
|
.is-rowadd-tool button:focus-visible {
|
|
80051
80811
|
outline-offset: -1px;
|
|
80052
80812
|
}
|
|
80813
|
+
/* Inside the button: a strip that clips (the box tool, the section
|
|
80814
|
+
tool) cannot cut it off. */
|
|
80053
80815
|
.is-tool button:focus-visible,
|
|
80054
80816
|
.is-tool [role="button"]:focus-visible,
|
|
80817
|
+
.is-section-tool button:focus-visible,
|
|
80818
|
+
.is-box-tool button:focus-visible,
|
|
80055
80819
|
.is-rte-tool button:focus-visible,
|
|
80056
80820
|
.is-elementrte-tool button:focus-visible {
|
|
80057
80821
|
outline: 2px solid var(--cb-tool-focus-ring, #111);
|
|
@@ -98009,6 +98773,18 @@ function openPopover(builder, opts = {}) {
|
|
|
98009
98773
|
// For an element the spot wins: a double-click may have left the
|
|
98010
98774
|
// selection inside it.
|
|
98011
98775
|
const caret = anchor && !anchor.startContainer ? spot() : builder.util.textCaret() || spot();
|
|
98776
|
+
|
|
98777
|
+
// Opened from a button (an element's tool, ContentBox's panel): Escape goes
|
|
98778
|
+
// back to that button, as for a dialog, not to the text.
|
|
98779
|
+
let opener = document.activeElement;
|
|
98780
|
+
if (opener && opener.tagName === 'IFRAME') {
|
|
98781
|
+
try {
|
|
98782
|
+
opener = opener.contentDocument.activeElement;
|
|
98783
|
+
} catch (e) {
|
|
98784
|
+
opener = null;
|
|
98785
|
+
}
|
|
98786
|
+
}
|
|
98787
|
+
opener = opener && opener.closest ? opener.closest('button, [role="button"]') : null;
|
|
98012
98788
|
const pop = document.createElement('div');
|
|
98013
98789
|
pop.className = 'cb-addon-pop';
|
|
98014
98790
|
// A window opened from the panel goes back here when it closes (util.hideModal).
|
|
@@ -98085,6 +98861,24 @@ function openPopover(builder, opts = {}) {
|
|
|
98085
98861
|
if (typeof opts.onClose === 'function') opts.onClose(reason);
|
|
98086
98862
|
// Escape: back to the text, where the caret was (unless the add-on
|
|
98087
98863
|
// already moved the focus on).
|
|
98864
|
+
if (reason === 'escape' && opener && opener.isConnected) {
|
|
98865
|
+
const visible = () => opener.isConnected && opener.getClientRects().length > 0 && getComputedStyle(opener).display !== 'none';
|
|
98866
|
+
if (visible()) {
|
|
98867
|
+
setTimeout(() => opener.focus(), 0);
|
|
98868
|
+
return;
|
|
98869
|
+
}
|
|
98870
|
+
// Its tool went while the panel was open (an equation's): the
|
|
98871
|
+
// element is selected again, as the arrows select it, which brings
|
|
98872
|
+
// the tool back, and the focus goes to the button there.
|
|
98873
|
+
const nav = builder.caretNav;
|
|
98874
|
+
if (anchor && !anchor.startContainer && anchor.isConnected && nav && typeof nav.selectObject === 'function') {
|
|
98875
|
+
nav.selectObject(anchor);
|
|
98876
|
+
setTimeout(() => {
|
|
98877
|
+
if (visible()) opener.focus();
|
|
98878
|
+
}, 650);
|
|
98879
|
+
return;
|
|
98880
|
+
}
|
|
98881
|
+
}
|
|
98088
98882
|
if (reason === 'escape' && caret) setTimeout(() => {
|
|
98089
98883
|
// After an element: there, whatever the selection was (a
|
|
98090
98884
|
// double-click leaves it inside the element).
|
|
@@ -98180,6 +98974,10 @@ const ELEMENT_TOOLS = {
|
|
|
98180
98974
|
style: '.image-style'
|
|
98181
98975
|
},
|
|
98182
98976
|
size: '40px',
|
|
98977
|
+
// First, as on the drawing tool: on a picture an add-on made (a drawing,
|
|
98978
|
+
// a diagram) its edit is the main tool, the one Esc lands on. Add-on
|
|
98979
|
+
// buttons do not show on other pictures, so theirs keep their order.
|
|
98980
|
+
first: true,
|
|
98183
98981
|
buttons: new Map()
|
|
98184
98982
|
},
|
|
98185
98983
|
svg: {
|
|
@@ -98195,6 +98993,22 @@ const ELEMENT_TOOLS = {
|
|
|
98195
98993
|
};
|
|
98196
98994
|
const SKIP = '[data-cb-type],[data-html],[contenteditable="false"],pre,code,kbd,samp,script,style,textarea';
|
|
98197
98995
|
|
|
98996
|
+
/* The caret right after a drawing in the text: past the zero-width space
|
|
98997
|
+
that is its caret place (editingengine.js holdDrawings), else the browser
|
|
98998
|
+
draws the caret before the drawing and the next arrow skips a letter. */
|
|
98999
|
+
function caretAfterDrawing(range, el) {
|
|
99000
|
+
let next = el.nextSibling;
|
|
99001
|
+
// Just put in (the engine adds the place a moment later): added now, so
|
|
99002
|
+
// what is typed next goes after the drawing, not before it.
|
|
99003
|
+
if (el.nodeName.toLowerCase() === 'svg' && !(next && next.nodeType === 3 && next.data.charAt(0) === '\u200B')) {
|
|
99004
|
+
if (next && next.nodeType === 3) next.insertData(0, '\u200B');else {
|
|
99005
|
+
next = el.ownerDocument.createTextNode('\u200B');
|
|
99006
|
+
el.after(next);
|
|
99007
|
+
}
|
|
99008
|
+
}
|
|
99009
|
+
if (next && next.nodeType === 3 && next.data.charAt(0) === '\u200B') range.setStart(next, 1);else range.setStartAfter(el);
|
|
99010
|
+
}
|
|
99011
|
+
|
|
98198
99012
|
/* Drawing elements an inserted SVG may hold (lower case: the HTML parser's
|
|
98199
99013
|
names). Anything else (script, foreignObject, image...) is removed. */
|
|
98200
99014
|
const SVG_TAGS = new Set(['svg', 'g', 'path', 'circle', 'ellipse', 'line', 'polyline', 'polygon', 'rect', 'defs', 'clippath', 'mask', 'lineargradient', 'radialgradient', 'stop', 'symbol', 'use', 'title', 'desc', 'text', 'tspan']);
|
|
@@ -98288,6 +99102,21 @@ const ICON_PICKER_CSS = `
|
|
|
98288
99102
|
body[data-cb-icon-picker] :is(.is-rte-tool, .rte-more-options) .rte-for-text .rte-icon:not(#_cbi) {
|
|
98289
99103
|
display: none !important;
|
|
98290
99104
|
}`;
|
|
99105
|
+
|
|
99106
|
+
/* The last control pressed in the editor's window (a clicked button has no
|
|
99107
|
+
focus in Safari): where ui.pickColor() opens when no anchor is given. */
|
|
99108
|
+
let lastPress = null;
|
|
99109
|
+
/* content.upload(): one at a time. */
|
|
99110
|
+
let uploads = Promise.resolve();
|
|
99111
|
+
if (typeof document !== 'undefined') {
|
|
99112
|
+
document.addEventListener('pointerdown', e => {
|
|
99113
|
+
const el = e.target && e.target.closest ? e.target.closest('button, [role="button"], [role="radio"], input, select') : null;
|
|
99114
|
+
if (el) lastPress = {
|
|
99115
|
+
el,
|
|
99116
|
+
at: Date.now()
|
|
99117
|
+
};
|
|
99118
|
+
}, true);
|
|
99119
|
+
}
|
|
98291
99120
|
class AddonHost {
|
|
98292
99121
|
constructor(builder) {
|
|
98293
99122
|
this.builder = builder;
|
|
@@ -98546,6 +99375,14 @@ class AddonHost {
|
|
|
98546
99375
|
return fn;
|
|
98547
99376
|
};
|
|
98548
99377
|
// The editable region a range is in, or null.
|
|
99378
|
+
/* Text marked as inline code (<code> in a sentence, not a code block)
|
|
99379
|
+
is still the sentence's text for the formatting calls, so marking
|
|
99380
|
+
can be undone: the check is made on the sentence. */
|
|
99381
|
+
const outOfInlineCode = n => {
|
|
99382
|
+
const el = n && (n.nodeType === 1 ? n : n.parentElement);
|
|
99383
|
+
const c = el && el.closest('code');
|
|
99384
|
+
return c && !c.closest('pre') ? c.parentElement : n;
|
|
99385
|
+
};
|
|
98549
99386
|
const regionAt = r => {
|
|
98550
99387
|
if (!r) return null;
|
|
98551
99388
|
let el = r.startContainer.nodeType === 1 ? r.startContainer : r.startContainer.parentElement;
|
|
@@ -98586,8 +99423,30 @@ class AddonHost {
|
|
|
98586
99423
|
const doc = builder.doc;
|
|
98587
99424
|
const sel = doc.getSelection();
|
|
98588
99425
|
const put = (node, offset) => {
|
|
99426
|
+
// The focus lost on the way (the add-on's own window closed, in
|
|
99427
|
+
// ContentBox's frame), or handed back to the button the window
|
|
99428
|
+
// opened from (the toolbar's Insert menu): back to the content,
|
|
99429
|
+
// so typing and the arrow keys go on in the text. Left alone
|
|
99430
|
+
// when a window or panel still open holds it.
|
|
99431
|
+
const a = document.activeElement;
|
|
99432
|
+
const lost = !a || a === document.body || a.tagName === 'IFRAME' && (!doc.activeElement || doc.activeElement === doc.body);
|
|
99433
|
+
const inner = a && a.tagName === 'IFRAME' ? doc.activeElement : a;
|
|
99434
|
+
const inText = !!inner && before.host.contains(inner);
|
|
99435
|
+
const open = !lost && !inText && inner.closest && inner.closest('[role="dialog"], .is-modal, [data-cb-panel]');
|
|
99436
|
+
const holds = !!open && open.getClientRects().length > 0 && !open.closest('.is-rte-tool, .is-elementrte-tool');
|
|
99437
|
+
// A window that has just closed hands the focus back to its
|
|
99438
|
+
// button on the next tick (util.hideModal): the insert it made
|
|
99439
|
+
// decides where the focus goes instead.
|
|
99440
|
+
const back = builder.util._pendingReturn;
|
|
99441
|
+
if (back && !back.done && !holds) back.taken = true;
|
|
99442
|
+
if (lost || !inText && !holds) {
|
|
99443
|
+
if (builder.win !== window) builder.win.focus();
|
|
99444
|
+
before.host.focus({
|
|
99445
|
+
preventScroll: true
|
|
99446
|
+
});
|
|
99447
|
+
}
|
|
98589
99448
|
const r = doc.createRange();
|
|
98590
|
-
if (offset === 'after') r
|
|
99449
|
+
if (offset === 'after') caretAfterDrawing(r, node);else r.setStart(node, offset);
|
|
98591
99450
|
r.collapse(true);
|
|
98592
99451
|
sel.removeAllRanges();
|
|
98593
99452
|
sel.addRange(r);
|
|
@@ -98828,6 +99687,33 @@ class AddonHost {
|
|
|
98828
99687
|
host.setQuiet(on, !!(opts && opts.all));
|
|
98829
99688
|
if (on && !record.quietCleanup) record.quietCleanup = track(() => host.setQuiet(false));
|
|
98830
99689
|
},
|
|
99690
|
+
/** Add an action for selected text, for an add-on that shows a panel beside
|
|
99691
|
+
a selection (Slash Commands) to offer: { id, group (actions of one group
|
|
99692
|
+
are shown together), title, html (optional, an icon), run() }. run() is called
|
|
99693
|
+
with the selection back in place. Returns a function that removes it;
|
|
99694
|
+
removed with the add-on too. */
|
|
99695
|
+
addSelectionAction: def => {
|
|
99696
|
+
if (!def || typeof def.run !== 'function') return () => {};
|
|
99697
|
+
host.selectionActions = host.selectionActions || [];
|
|
99698
|
+
const item = {
|
|
99699
|
+
id: String(def.id || ''),
|
|
99700
|
+
addon: record.name,
|
|
99701
|
+
group: String(def.group || ''),
|
|
99702
|
+
title: String(def.title || ''),
|
|
99703
|
+
html: String(def.html || ''),
|
|
99704
|
+
run: def.run
|
|
99705
|
+
};
|
|
99706
|
+
host.selectionActions.push(item);
|
|
99707
|
+
const remove = () => {
|
|
99708
|
+
const i = host.selectionActions.indexOf(item);
|
|
99709
|
+
if (i >= 0) host.selectionActions.splice(i, 1);
|
|
99710
|
+
};
|
|
99711
|
+
track(remove);
|
|
99712
|
+
return remove;
|
|
99713
|
+
},
|
|
99714
|
+
/** The actions add-ons gave for selected text (addSelectionAction), in the
|
|
99715
|
+
order added: [{ id, addon, group, title, html, run }]. */
|
|
99716
|
+
selectionActions: () => (host.selectionActions || []).map(a => Object.assign({}, a)),
|
|
98831
99717
|
/** Hide the element tool (the small tool beside a clicked element: add,
|
|
98832
99718
|
more, delete, settings), for an add-on that offers the same another way.
|
|
98833
99719
|
As the Preferences' "hide element tool". Returns a function that shows
|
|
@@ -98854,7 +99740,8 @@ class AddonHost {
|
|
|
98854
99740
|
isQuiet: () => !!host.quiet,
|
|
98855
99741
|
/** The editor's own icon, as markup, so an add-on's buttons look like
|
|
98856
99742
|
the editor's: 'bold', 'italic', 'underline', 'strikethrough', 'clean',
|
|
98857
|
-
'link', 'unlink', 'up', 'down', 'duplicate', 'delete', 'settings'
|
|
99743
|
+
'link', 'unlink', 'code', 'up', 'down', 'duplicate', 'delete', 'settings',
|
|
99744
|
+
'align-left', 'align-center', 'align-right', 'align-justify'. '' for another name. */
|
|
98858
99745
|
icon: name => {
|
|
98859
99746
|
const letter = (style, ch) => `<span aria-hidden="true" style="font-family:serif;${style}">${ch}</span>`;
|
|
98860
99747
|
const sprite = (id, size) => `<svg class="is-icon-flex" aria-hidden="true" style="width:${size}px;height:${size}px;"><use xlink:href="#${id}"></use></svg>`;
|
|
@@ -98871,6 +99758,8 @@ class AddonHost {
|
|
|
98871
99758
|
return sprite('icon-eraser', 16);
|
|
98872
99759
|
case 'link':
|
|
98873
99760
|
return sprite('ion-link', 14);
|
|
99761
|
+
case 'code':
|
|
99762
|
+
return sprite('icon-code', 16);
|
|
98874
99763
|
case 'unlink':
|
|
98875
99764
|
return '<svg class="is-icon-flex" aria-hidden="true" viewBox="0 0 24 24" style="width:14px;height:14px;"><use xlink:href="#ion-link"></use><path d="M3 3l18 18" stroke="currentColor" stroke-width="2" stroke-linecap="round" fill="none"/></svg>';
|
|
98876
99765
|
case 'up':
|
|
@@ -98883,18 +99772,35 @@ class AddonHost {
|
|
|
98883
99772
|
return sprite('icon-trash2', 15);
|
|
98884
99773
|
case 'settings':
|
|
98885
99774
|
return sprite('ion-ios-gear', 16);
|
|
99775
|
+
case 'align-left':
|
|
99776
|
+
return sprite('icon-align-left', 14);
|
|
99777
|
+
case 'align-center':
|
|
99778
|
+
return sprite('icon-align-center', 14);
|
|
99779
|
+
case 'align-right':
|
|
99780
|
+
return sprite('icon-align-right', 14);
|
|
99781
|
+
case 'align-justify':
|
|
99782
|
+
return sprite('icon-align-full', 14);
|
|
98886
99783
|
default:
|
|
98887
99784
|
return '';
|
|
98888
99785
|
}
|
|
98889
99786
|
},
|
|
98890
|
-
/** The editor's colour picker. { color, onPick(color), onClose() };
|
|
98891
|
-
onPick runs on every change ('' = no colour).
|
|
99787
|
+
/** The editor's colour picker. { color, onPick(color), onClose(), anchor };
|
|
99788
|
+
onPick runs on every change ('' = no colour). anchor: the button
|
|
99789
|
+
it opens beside (default: the focused control of the editor's
|
|
99790
|
+
window; a clicked button has no focus in Safari, so pass it). */
|
|
98892
99791
|
pickColor: ({
|
|
98893
99792
|
color = '',
|
|
98894
99793
|
onPick,
|
|
98895
|
-
onClose
|
|
99794
|
+
onClose,
|
|
99795
|
+
anchor
|
|
98896
99796
|
} = {}) => {
|
|
98897
99797
|
if (!builder.colorPicker) return false;
|
|
99798
|
+
// Beside the add-on's button: the one given, else the control
|
|
99799
|
+
// just clicked or focused in the editor's window (not the
|
|
99800
|
+
// page frame's focus, which the picker would otherwise use).
|
|
99801
|
+
const active = document.activeElement;
|
|
99802
|
+
const pressed = lastPress && Date.now() - lastPress.at < 1000 && lastPress.el.isConnected ? lastPress.el : null;
|
|
99803
|
+
const at = anchor && anchor.isConnected ? anchor : pressed || (active && active !== document.body && active.tagName !== 'IFRAME' ? active : undefined);
|
|
98898
99804
|
builder.colorPicker.open(c => {
|
|
98899
99805
|
try {
|
|
98900
99806
|
if (onPick) onPick(c);
|
|
@@ -98907,7 +99813,7 @@ class AddonHost {
|
|
|
98907
99813
|
} catch (e) {
|
|
98908
99814
|
log(record.name, 'pickColor close failed.', e);
|
|
98909
99815
|
}
|
|
98910
|
-
});
|
|
99816
|
+
}, at);
|
|
98911
99817
|
return true;
|
|
98912
99818
|
}
|
|
98913
99819
|
}),
|
|
@@ -99139,6 +100045,32 @@ class AddonHost {
|
|
|
99139
100045
|
const el = node.nodeType === 1 ? node : node.parentElement;
|
|
99140
100046
|
return el && el.closest(REGIONS) ? range : null;
|
|
99141
100047
|
},
|
|
100048
|
+
/** The block the user selected whole, by a click or the arrow keys, that is
|
|
100049
|
+
not text: a plugin, a video, a spacer, a picture or drawing on its own
|
|
100050
|
+
line. Returns the column's child that holds it (what moving or removing
|
|
100051
|
+
acts on), or null. */
|
|
100052
|
+
selectedBlock() {
|
|
100053
|
+
const nav = builder.caretNav;
|
|
100054
|
+
if (!nav) return null;
|
|
100055
|
+
const r = this.selection();
|
|
100056
|
+
let el = nav.selectedObject(r);
|
|
100057
|
+
// The drawing the user clicked (a chart, a diagram, an add-on's block
|
|
100058
|
+
// with the drawing tool: a calendar, a timeline), unless it is an icon
|
|
100059
|
+
// in a line of text.
|
|
100060
|
+
const drawing = builder.activeSvg;
|
|
100061
|
+
if (!el && drawing && drawing.isConnected && (drawing.nodeName.toLowerCase() !== 'svg' || nav.isObject(drawing))) el = drawing;
|
|
100062
|
+
if (!el) {
|
|
100063
|
+
const a = builder.activeElement;
|
|
100064
|
+
if (a && a.isConnected && (a.matches('[data-cb-type], [data-cb-code]') || nav.isObject(a))) {
|
|
100065
|
+
// A caret in the block's own text (a plugin's editable part) is text.
|
|
100066
|
+
const n = r && r.collapsed ? r.startContainer : null;
|
|
100067
|
+
const ne = n && (n.nodeType === 1 ? n : n.parentElement);
|
|
100068
|
+
if (!(ne && a.contains(ne) && ne.closest('[contenteditable="true"]') && a.contains(ne.closest('[contenteditable="true"]')))) el = a;
|
|
100069
|
+
}
|
|
100070
|
+
}
|
|
100071
|
+
if (!el || !el.closest(REGIONS)) return null;
|
|
100072
|
+
return nav.lineOf(el) || el;
|
|
100073
|
+
},
|
|
99142
100074
|
/** Whether the editor has an element settings window (the element
|
|
99143
100075
|
tool's Settings; the elementEditor option). */
|
|
99144
100076
|
hasElementSettings() {
|
|
@@ -99147,18 +100079,22 @@ class AddonHost {
|
|
|
99147
100079
|
/** Open the element settings window for el (a line in the content),
|
|
99148
100080
|
as the element tool's Settings does. False when there is none. */
|
|
99149
100081
|
elementSettings(el) {
|
|
99150
|
-
|
|
100082
|
+
// A line of text, or a block without text (a spacer, a picture's line);
|
|
100083
|
+
// not a plugin (it has its own settings) or a part of a locked block.
|
|
100084
|
+
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"]'));
|
|
100085
|
+
if (!this.hasElementSettings() || !ok) return false;
|
|
99151
100086
|
builder.activeElement = el;
|
|
99152
100087
|
builder.elmTool.elementPanel.showPanel();
|
|
99153
100088
|
return true;
|
|
99154
100089
|
},
|
|
99155
100090
|
/** Format the selected text as the text toolbar does: 'bold', 'italic',
|
|
99156
|
-
'underline', 'strikethrough', '
|
|
99157
|
-
'unlink', or 'link' (opens the editor's link
|
|
100091
|
+
'underline', 'strikethrough', 'code' (inline code), 'clean' (clear
|
|
100092
|
+
formatting; links stay), 'unlink', or 'link' (opens the editor's link
|
|
100093
|
+
window). One undo step.
|
|
99158
100094
|
Returns false when the selection is not in editable text. */
|
|
99159
100095
|
format(command) {
|
|
99160
100096
|
const r = this.selection();
|
|
99161
|
-
if (!r || !regionAt(r) || !this.isEditable(r.startContainer)) return false;
|
|
100097
|
+
if (!r || !regionAt(r) || !this.isEditable(outOfInlineCode(r.startContainer))) return false;
|
|
99162
100098
|
builder.util.saveSelection(); // the editor's commands restore the saved selection
|
|
99163
100099
|
if (command === 'link') {
|
|
99164
100100
|
builder.element.hyperlink.createLink();
|
|
@@ -99167,7 +100103,8 @@ class AddonHost {
|
|
|
99167
100103
|
const region = builder.editingEngine.active;
|
|
99168
100104
|
if (!region) return false;
|
|
99169
100105
|
builder.uo.saveForUndo();
|
|
99170
|
-
if (command === 'unlink') region.unlink();else
|
|
100106
|
+
if (command === 'unlink') region.unlink();else if (command === 'code') region.toggleStyle('code'); // inline code: <code>
|
|
100107
|
+
else builder.rte.formatText(command);
|
|
99171
100108
|
builder.util.saveSelection();
|
|
99172
100109
|
builder.opts.onChange();
|
|
99173
100110
|
if (builder.rte.getState) builder.rte.getState();
|
|
@@ -99175,7 +100112,9 @@ class AddonHost {
|
|
|
99175
100112
|
},
|
|
99176
100113
|
/** What the selected text is: { bold, italic, underline, strikethrough,
|
|
99177
100114
|
link (inside a link), block ('p', 'h2', ... the first line's tag),
|
|
99178
|
-
list ('ul', 'ol' or null)
|
|
100115
|
+
list ('ul', 'ol' or null), align ('left', 'center', 'right',
|
|
100116
|
+
'justify', or null when the line has none of its own) }, or null
|
|
100117
|
+
outside editable text. */
|
|
99179
100118
|
formatState() {
|
|
99180
100119
|
const r = this.selection();
|
|
99181
100120
|
const region = r && regionAt(r);
|
|
@@ -99190,18 +100129,34 @@ class AddonHost {
|
|
|
99190
100129
|
italic: !!st.italic,
|
|
99191
100130
|
underline: !!st.underline,
|
|
99192
100131
|
strikethrough: !!st.strike,
|
|
100132
|
+
code: !!st.code,
|
|
99193
100133
|
link: !!st.link || a(r.startContainer) || a(r.endContainer),
|
|
99194
100134
|
block: st.block || null,
|
|
99195
|
-
list: st.list || null
|
|
100135
|
+
list: st.list || null,
|
|
100136
|
+
align: st.align || null
|
|
99196
100137
|
};
|
|
99197
100138
|
},
|
|
100139
|
+
/** Align the lines the selection is in, as the text toolbar's Align
|
|
100140
|
+
does: 'left', 'center', 'right' or 'justify'. One undo step.
|
|
100141
|
+
Returns false outside editable text. */
|
|
100142
|
+
align(value) {
|
|
100143
|
+
if (!['left', 'center', 'right', 'justify'].includes(value)) return false;
|
|
100144
|
+
const r = this.selection();
|
|
100145
|
+
const region = r && regionAt(r);
|
|
100146
|
+
if (!region || !this.isEditable(outOfInlineCode(r.startContainer))) return false;
|
|
100147
|
+
builder.uo.saveForUndo();
|
|
100148
|
+
region.align(value);
|
|
100149
|
+
builder.util.saveSelection();
|
|
100150
|
+
builder.opts.onChange();
|
|
100151
|
+
return true;
|
|
100152
|
+
},
|
|
99198
100153
|
/** Turn the selected lines into another kind, keeping their text:
|
|
99199
100154
|
'p', 'h1' to 'h6', 'blockquote', 'pre', or 'ul' / 'ol' (a list).
|
|
99200
100155
|
One undo step. Returns false when nothing changed. */
|
|
99201
100156
|
setBlock(kind) {
|
|
99202
100157
|
const r = this.selection();
|
|
99203
100158
|
const region = r && regionAt(r);
|
|
99204
|
-
if (!region || !this.isEditable(r.startContainer)) return false;
|
|
100159
|
+
if (!region || !this.isEditable(outOfInlineCode(r.startContainer))) return false;
|
|
99205
100160
|
const doc = builder.doc;
|
|
99206
100161
|
const lines = () => {
|
|
99207
100162
|
const out = [];
|
|
@@ -99273,6 +100228,22 @@ class AddonHost {
|
|
|
99273
100228
|
hasImagePicker() {
|
|
99274
100229
|
return typeof builder.hasFilePicker === 'function' && !!builder.hasFilePicker('image');
|
|
99275
100230
|
},
|
|
100231
|
+
/** Whether the site set a file picker for this kind of file:
|
|
100232
|
+
'image' (as hasImagePicker), 'video' (videoSelect,
|
|
100233
|
+
onVideoSelectClick) or 'audio' (audioSelect, onAudioSelectClick). */
|
|
100234
|
+
hasFilePicker(type = 'image') {
|
|
100235
|
+
return typeof builder.hasFilePicker === 'function' && !!builder.hasFilePicker(type);
|
|
100236
|
+
},
|
|
100237
|
+
/** Open the site's file picker for 'image', 'video' or 'audio';
|
|
100238
|
+
callback(url) gets the chosen file's address. False when the
|
|
100239
|
+
site set no picker for that kind. */
|
|
100240
|
+
pickFile(type, callback) {
|
|
100241
|
+
if (!this.hasFilePicker(type) || typeof builder.openFilePicker !== 'function') return false;
|
|
100242
|
+
builder.openFilePicker(type, url => {
|
|
100243
|
+
if (url && callback) callback(url);
|
|
100244
|
+
});
|
|
100245
|
+
return true;
|
|
100246
|
+
},
|
|
99276
100247
|
/** Whether the site set an image upload (onImageUpload), so
|
|
99277
100248
|
uploadImages() really uploads; without one an embedded image
|
|
99278
100249
|
stays in the page. */
|
|
@@ -99315,7 +100286,7 @@ class AddonHost {
|
|
|
99315
100286
|
});
|
|
99316
100287
|
const sel = builder.doc.getSelection();
|
|
99317
100288
|
const after = builder.doc.createRange();
|
|
99318
|
-
after
|
|
100289
|
+
caretAfterDrawing(after, placed);
|
|
99319
100290
|
after.collapse(true);
|
|
99320
100291
|
sel.removeAllRanges();
|
|
99321
100292
|
sel.addRange(after);
|
|
@@ -99361,8 +100332,9 @@ class AddonHost {
|
|
|
99361
100332
|
/** Insert what the quick add panel's item `id` inserts (see blocks()),
|
|
99362
100333
|
right after `after`, an element in a column, as one undo step.
|
|
99363
100334
|
Returns the new elements in order (some items add two), or an
|
|
99364
|
-
empty list ('more' opens the snippets window).
|
|
99365
|
-
|
|
100335
|
+
empty list ('more' opens the snippets window). opts.src: the
|
|
100336
|
+
address of the video or sound file for 'video' and 'audio'. */
|
|
100337
|
+
addBlock(id, after, opts = {}) {
|
|
99366
100338
|
const actions = host.quickAdd();
|
|
99367
100339
|
if (!actions[id] || !this.blocks().includes(id)) return [];
|
|
99368
100340
|
if (id === 'more') {
|
|
@@ -99373,8 +100345,10 @@ class AddonHost {
|
|
|
99373
100345
|
const parent = after.parentNode;
|
|
99374
100346
|
const old = new Set(parent.children);
|
|
99375
100347
|
builder.activeElement = after;
|
|
100348
|
+
// 'video' and 'audio' take the file's address (opts.src) in
|
|
100349
|
+
// place of the sample, in the same undo step.
|
|
99376
100350
|
try {
|
|
99377
|
-
actions[id]('elm');
|
|
100351
|
+
actions[id]('elm', opts && opts.src ? String(opts.src) : undefined);
|
|
99378
100352
|
} catch (e) {
|
|
99379
100353
|
log(record.name, 'addBlock failed.', e);
|
|
99380
100354
|
return [];
|
|
@@ -99477,6 +100451,46 @@ class AddonHost {
|
|
|
99477
100451
|
const region = regionAt(range || this.selection());
|
|
99478
100452
|
return builder.preparePasteHtml(String(text), String(html || text), region);
|
|
99479
100453
|
},
|
|
100454
|
+
/** Upload a file through the editor's upload (the site's handler,
|
|
100455
|
+
after the beforeUpload hook) and get its address: a Promise of
|
|
100456
|
+
the URL, or null when there is no upload or it failed. Uploads
|
|
100457
|
+
wait for each other (the handler has one return slot). A video
|
|
100458
|
+
or a sound file goes through the site's video or audio upload
|
|
100459
|
+
(onVideoUpload, onAudioUpload) when it set one. */
|
|
100460
|
+
upload(file) {
|
|
100461
|
+
const kind = file && /^(video|audio)\//.exec(file.type || '');
|
|
100462
|
+
const byType = kind ? kind[1] === 'video' ? builder.onVideoUpload : builder.onAudioUpload : null;
|
|
100463
|
+
const fn = byType || builder.onImageUpload || builder.opts && builder.opts.onImageUpload;
|
|
100464
|
+
if (!fn || !file) return Promise.resolve(null);
|
|
100465
|
+
const run = () => new Promise(resolve => {
|
|
100466
|
+
let done = false;
|
|
100467
|
+
const finish = url => {
|
|
100468
|
+
if (done) return;
|
|
100469
|
+
done = true;
|
|
100470
|
+
clearTimeout(limit);
|
|
100471
|
+
// after returnUrl() has cleared its slot, so the next upload can use it
|
|
100472
|
+
setTimeout(() => resolve(url || null), 0);
|
|
100473
|
+
};
|
|
100474
|
+
const limit = setTimeout(() => {
|
|
100475
|
+
if (builder.onAssetUpload === finish) builder.onAssetUpload = null;
|
|
100476
|
+
finish(null);
|
|
100477
|
+
}, 120000);
|
|
100478
|
+
builder.onAssetUpload = finish;
|
|
100479
|
+
try {
|
|
100480
|
+
const r = fn({
|
|
100481
|
+
target: {
|
|
100482
|
+
files: [file]
|
|
100483
|
+
}
|
|
100484
|
+
});
|
|
100485
|
+
if (r && typeof r.catch === 'function') r.catch(() => finish(null));
|
|
100486
|
+
} catch (e) {
|
|
100487
|
+
builder.onAssetUpload = null;
|
|
100488
|
+
finish(null);
|
|
100489
|
+
}
|
|
100490
|
+
});
|
|
100491
|
+
uploads = uploads.then(run, run);
|
|
100492
|
+
return uploads;
|
|
100493
|
+
},
|
|
99480
100494
|
/** Upload the embedded (data:) images in or at an element of the
|
|
99481
100495
|
content through the editor's upload, as pasted images are.
|
|
99482
100496
|
For content an add-on changed itself, e.g. a new image src. */
|
|
@@ -99678,6 +100692,10 @@ class AddonHost {
|
|
|
99678
100692
|
title: def.menuTitle ? this.builder.util.out(def.menuTitle) : menuTitleOf(title, this.builder.util.out(menuDef.label))
|
|
99679
100693
|
} : null;
|
|
99680
100694
|
|
|
100695
|
+
// The add-on's name as people see it: the title of its button in the
|
|
100696
|
+
// Insert menu (Timeline), shown where its blocks are described.
|
|
100697
|
+
if (place === 'text' && def.group === 'insert' && !record._title) record._title = menu ? menu.title : title;
|
|
100698
|
+
|
|
99681
100699
|
// A place the host (ContentBox) provides wins.
|
|
99682
100700
|
const hostPlaces = this.builder.opts.addonPlaces;
|
|
99683
100701
|
if (hostPlaces && typeof hostPlaces[place] === 'function') {
|
|
@@ -99692,7 +100710,7 @@ class AddonHost {
|
|
|
99692
100710
|
}) || null;
|
|
99693
100711
|
}
|
|
99694
100712
|
if (place === 'text') return this.addTextButton(id, title, def.html || '', onClick, on, menu);
|
|
99695
|
-
if (ELEMENT_TOOLS[place]) return this.addToolButton(place, id, title, def.html || '', onClick, def.when, def.hides);
|
|
100713
|
+
if (ELEMENT_TOOLS[place]) return this.addToolButton(place, id, title, def.html || '', onClick, def.when, def.hides, record);
|
|
99696
100714
|
console.warn(`[ContentBuilder] add-on "${record.name}": button place "${place}" is not available here.`);
|
|
99697
100715
|
return null;
|
|
99698
100716
|
}
|
|
@@ -99981,13 +100999,14 @@ class AddonHost {
|
|
|
99981
100999
|
accepts; the click gets the element. hides: the tool's own buttons to
|
|
99982
101000
|
hide for those elements (image: 'edit', 'change', 'link'; svg:
|
|
99983
101001
|
'settings'), e.g. ones that would break what the add-on made. */
|
|
99984
|
-
addToolButton(kind, id, title, html, onClick, when, hides) {
|
|
101002
|
+
addToolButton(kind, id, title, html, onClick, when, hides, record) {
|
|
99985
101003
|
const spec = ELEMENT_TOOLS[kind];
|
|
99986
101004
|
const owner = {
|
|
99987
101005
|
host: this,
|
|
99988
101006
|
onClick,
|
|
99989
101007
|
when: typeof when === 'function' ? when : null,
|
|
99990
|
-
hides: Array.isArray(hides) ? hides : []
|
|
101008
|
+
hides: Array.isArray(hides) ? hides : [],
|
|
101009
|
+
record
|
|
99991
101010
|
};
|
|
99992
101011
|
let btn = spec.buttons.get(id);
|
|
99993
101012
|
if (btn) {
|
|
@@ -100021,6 +101040,44 @@ class AddonHost {
|
|
|
100021
101040
|
if (tool) this.placeToolButton(tool, btn, spec);
|
|
100022
101041
|
return btn;
|
|
100023
101042
|
}
|
|
101043
|
+
|
|
101044
|
+
/* What add-ons offer for an element they made (a timeline, a drawing): the
|
|
101045
|
+
add-on's name and the actions of its element tool buttons, for a host
|
|
101046
|
+
that describes the selected element (ContentBox's side panel). */
|
|
101047
|
+
toolsFor(el) {
|
|
101048
|
+
const out = {
|
|
101049
|
+
name: '',
|
|
101050
|
+
tools: []
|
|
101051
|
+
};
|
|
101052
|
+
if (!el) return out;
|
|
101053
|
+
['svg', 'image'].forEach(kind => ELEMENT_TOOLS[kind].buttons.forEach(btn => {
|
|
101054
|
+
const owners = btn._cbAddonOwners || [];
|
|
101055
|
+
const o = owners[owners.length - 1];
|
|
101056
|
+
if (!o || o.host !== this || !o.when) return;
|
|
101057
|
+
let ok = false;
|
|
101058
|
+
try {
|
|
101059
|
+
ok = !!o.when(el);
|
|
101060
|
+
} catch (e) {
|
|
101061
|
+
ok = false;
|
|
101062
|
+
}
|
|
101063
|
+
if (!ok) return;
|
|
101064
|
+
out.tools.push({
|
|
101065
|
+
title: btn.getAttribute('aria-label') || '',
|
|
101066
|
+
html: btn.innerHTML,
|
|
101067
|
+
run: e => o.onClick(e, el)
|
|
101068
|
+
});
|
|
101069
|
+
if (!out.name && o.record) out.name = o.record._title || o.record.name;
|
|
101070
|
+
}));
|
|
101071
|
+
return out;
|
|
101072
|
+
}
|
|
101073
|
+
|
|
101074
|
+
/* Whether the host's side panel shows an add-on's edit buttons for this
|
|
101075
|
+
element (ContentBox, its panel open): then they are not shown again
|
|
101076
|
+
beside the element. */
|
|
101077
|
+
panelHasTools(el) {
|
|
101078
|
+
const b = this.builder;
|
|
101079
|
+
return !!(el && b.controlpanel && typeof b.controlpanel.showAddonPart === 'function' && b.panelOwnsTools && b.panelOwnsTools() && this.toolsFor(el).tools.length);
|
|
101080
|
+
}
|
|
100024
101081
|
placeToolButton(tool, btn, spec) {
|
|
100025
101082
|
// Add-on buttons keep the order they were added in.
|
|
100026
101083
|
const own = spec.first ? Array.from(tool.children).find(c => !c.hasAttribute('data-addon')) : null;
|
|
@@ -100054,24 +101111,27 @@ class AddonHost {
|
|
|
100054
101111
|
show = false;
|
|
100055
101112
|
}
|
|
100056
101113
|
}
|
|
100057
|
-
|
|
101114
|
+
// In the host's side panel instead (an add-on's picture: Edit Drawing);
|
|
101115
|
+
// what it hides stays hidden.
|
|
101116
|
+
btn.style.display = show && !this.panelHasTools(el) ? '' : 'none';
|
|
100058
101117
|
if (show) o.hides.forEach(name => hide.add(name));
|
|
100059
|
-
|
|
101118
|
+
// A button that takes the place of the element's own Edit or Change
|
|
101119
|
+
// (Edit Drawing) is its main tool: first, where Escape lands.
|
|
101120
|
+
if (show && o.hides.some(name => name === 'edit' || name === 'change') && tool.firstElementChild !== btn) tool.insertBefore(btn, tool.firstElementChild);
|
|
101121
|
+
});
|
|
101122
|
+
// Hidden by a mark, not by its style: the editor sets these buttons'
|
|
101123
|
+
// own display each time it shows the tool (e.g. Edit, shown for every
|
|
101124
|
+
// picture but an SVG), after this runs, and must not bring them back.
|
|
101125
|
+
const doc = tool.ownerDocument;
|
|
101126
|
+
if (!doc.getElementById('_cb_addon_hides_css')) {
|
|
101127
|
+
const st = doc.createElement('style');
|
|
101128
|
+
st.id = '_cb_addon_hides_css';
|
|
101129
|
+
st.textContent = '[data-cb-addon-hidden]:not(#_cbi) { display: none !important; }';
|
|
101130
|
+
doc.head.appendChild(st);
|
|
101131
|
+
}
|
|
100060
101132
|
Object.entries(spec.own).forEach(([name, selector]) => {
|
|
100061
101133
|
const b = tool.querySelector(selector);
|
|
100062
|
-
if (
|
|
100063
|
-
// Restored to what it was: a button the editor's options hide
|
|
100064
|
-
// (e.g. imageEmbed: false) stays hidden.
|
|
100065
|
-
if (hide.has(name)) {
|
|
100066
|
-
if (!b._cbAddonHidden) {
|
|
100067
|
-
b._cbAddonPrev = b.style.display;
|
|
100068
|
-
b._cbAddonHidden = true;
|
|
100069
|
-
}
|
|
100070
|
-
b.style.display = 'none';
|
|
100071
|
-
} else if (b._cbAddonHidden) {
|
|
100072
|
-
b.style.display = b._cbAddonPrev || '';
|
|
100073
|
-
b._cbAddonHidden = false;
|
|
100074
|
-
}
|
|
101134
|
+
if (b) b.toggleAttribute('data-cb-addon-hidden', hide.has(name));
|
|
100075
101135
|
});
|
|
100076
101136
|
}
|
|
100077
101137
|
|
|
@@ -103137,7 +104197,10 @@ class ContentBuilder {
|
|
|
103137
104197
|
// In Inscribe mode a media-only column (just an image/
|
|
103138
104198
|
// figure/video, no text) is still editable — Inscribe
|
|
103139
104199
|
// manages image selection, resize, and figures there.
|
|
103140
|
-
|
|
104200
|
+
// A spacer or a line alone too: the arrow keys select it,
|
|
104201
|
+
// Enter adds a line after it (caretnav.js) and its tools
|
|
104202
|
+
// work from the keyboard; locked, nothing could follow it.
|
|
104203
|
+
const hasMedia = this.opts.engine === 'inscribe' && col.querySelector('img,figure,picture,video,.spacer,hr');
|
|
103141
104204
|
if (elms.length > 0 || _text !== '' || hasMedia) {
|
|
103142
104205
|
// EVERY column is an Inscribe region (ContentBuilder's
|
|
103143
104206
|
// rule: all columns are editable). A plugin/module inside
|
|
@@ -104282,6 +105345,7 @@ class ContentBuilder {
|
|
|
104282
105345
|
this.addonHost.destroy();
|
|
104283
105346
|
this.addonHost = null;
|
|
104284
105347
|
}
|
|
105348
|
+
if (this.toolbarKeys) this.toolbarKeys.destroy();
|
|
104285
105349
|
const snippetData = document.querySelector('#_snippet_data');
|
|
104286
105350
|
if (snippetData) snippetData.remove();
|
|
104287
105351
|
const linkStyle = document.head.querySelector('#_snippet_style');
|
|
@@ -104696,8 +105760,9 @@ class ContentBuilder {
|
|
|
104696
105760
|
inpFile.remove();
|
|
104697
105761
|
return;
|
|
104698
105762
|
}
|
|
105763
|
+
// A failed or cancelled upload returns no URL, and the field keeps what it had
|
|
104699
105764
|
this.onAssetUpload = url => {
|
|
104700
|
-
if (callback) callback(url);
|
|
105765
|
+
if (callback && url) callback(url);
|
|
104701
105766
|
};
|
|
104702
105767
|
await handler(e);
|
|
104703
105768
|
inpFile.remove();
|
|
@@ -107162,7 +108227,8 @@ Please obtain a license at: https://innovastudio.com/contentbox`);
|
|
|
107162
108227
|
// If column only has spacer, locked or unlocked,
|
|
107163
108228
|
// the text should not be able to edit (cursor should not be able to be placed)
|
|
107164
108229
|
// So, make the column uneditable (text) if only has a spacer.
|
|
107165
|
-
|
|
108230
|
+
// (Not with Inscribe: the column stays editable, see applyBehavior.)
|
|
108231
|
+
if (col.childElementCount === 1 && this.opts.engine !== 'inscribe') {
|
|
107166
108232
|
let elm = col.children[0];
|
|
107167
108233
|
if (elm) if (this.dom.hasClass(elm, 'spacer')) {
|
|
107168
108234
|
col.contentEditable = false;
|
|
@@ -107314,7 +108380,10 @@ Please obtain a license at: https://innovastudio.com/contentbox`);
|
|
|
107314
108380
|
const off = sel.focusOffset;
|
|
107315
108381
|
let next = null;
|
|
107316
108382
|
if (node.nodeType === 3) {
|
|
107317
|
-
|
|
108383
|
+
// A zero-width space next to a drawing is its caret place
|
|
108384
|
+
// (editingengine.js holdDrawings): the caret is still beside it.
|
|
108385
|
+
const zw = t => t.replace(/\u200B/g, '') === '';
|
|
108386
|
+
if (forward && zw(node.data.slice(off))) next = node.nextSibling;else if (!forward && zw(node.data.slice(0, off))) next = node.previousSibling;
|
|
107318
108387
|
} else {
|
|
107319
108388
|
next = forward ? node.childNodes[off] : node.childNodes[off - 1];
|
|
107320
108389
|
}
|
|
@@ -107330,6 +108399,12 @@ Please obtain a license at: https://innovastudio.com/contentbox`);
|
|
|
107330
108399
|
e.stopPropagation();
|
|
107331
108400
|
return;
|
|
107332
108401
|
}
|
|
108402
|
+
// F6: the page's regions (the panel, the top bar...), see toolbarkeys.js.
|
|
108403
|
+
if (this.toolbarKeys.isRegionKey(e) && this.toolbarKeys.stepRegion(e.target, !e.shiftKey, col)) {
|
|
108404
|
+
e.preventDefault();
|
|
108405
|
+
e.stopPropagation();
|
|
108406
|
+
return;
|
|
108407
|
+
}
|
|
107333
108408
|
|
|
107334
108409
|
// The keyboard way to select an SVG drawing or a picture in the text
|
|
107335
108410
|
// (what a click does, see elements.js): the caret skips over it, so
|
|
@@ -107361,7 +108436,7 @@ Please obtain a license at: https://innovastudio.com/contentbox`);
|
|
|
107361
108436
|
this.element.svg.hideTool();
|
|
107362
108437
|
}
|
|
107363
108438
|
const range = this.doc.createRange();
|
|
107364
|
-
if (forward) range
|
|
108439
|
+
if (forward) caretAfterDrawing(range, icon);else range.setStartBefore(icon);
|
|
107365
108440
|
range.collapse(true);
|
|
107366
108441
|
const sel = this.win.getSelection();
|
|
107367
108442
|
sel.removeAllRanges();
|
|
@@ -107799,7 +108874,13 @@ Please obtain a license at: https://innovastudio.com/contentbox`);
|
|
|
107799
108874
|
// console.log('typing');
|
|
107800
108875
|
if (this.timeoutId) clearTimeout(this.timeoutId);
|
|
107801
108876
|
this.timeoutId = setTimeout(() => {
|
|
108877
|
+
// The save after typing. A picture clicked since then keeps its
|
|
108878
|
+
// tool (onChange hides it, which would leave the picture without one).
|
|
108879
|
+
const img = this.activeImage;
|
|
108880
|
+
const tool = this.element && this.element.image && this.element.image.imageTool;
|
|
108881
|
+
const shown = img && img.isConnected && tool && tool.style.display === 'flex';
|
|
107802
108882
|
this.opts.onChange();
|
|
108883
|
+
if (shown) this.element.image.repositionImageTool();
|
|
107803
108884
|
}, 2000);
|
|
107804
108885
|
}
|
|
107805
108886
|
|
|
@@ -108412,6 +109493,9 @@ Please obtain a license at: https://innovastudio.com/contentbox`);
|
|
|
108412
109493
|
builderActive = scope.querySelector('.is-builder');
|
|
108413
109494
|
if (builderActive) this.applyBehaviorOn(builderActive);
|
|
108414
109495
|
}
|
|
109496
|
+
|
|
109497
|
+
// Mount the plugin blocks the snippet brought, as dropping one in does
|
|
109498
|
+
if (builderActive) this.reinitPlugins(builderActive);
|
|
108415
109499
|
let cellElement = rowElement.querySelector('div');
|
|
108416
109500
|
if (cellElement) cellElement.click(); //change active block to the newly created
|
|
108417
109501
|
|