@innovastudio/contentbuilder 1.5.229 → 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.
@@ -961,40 +961,40 @@ const quickAddActions = builder => {
961
961
  }
962
962
  util.addContent(html, mode);
963
963
  };
964
- actions['video'] = mode => {
965
- const videoSrc = builder.opts.snippetSampleVideo ? builder.opts.snippetSampleVideo : `${builder.opts.snippetPath}example.mp4`;
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}" type="video/mp4">
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}" type="video/mp4"></video>`;
983
+ <source src="${videoSrc}"${videoType}></video>`;
980
984
  }
981
985
  util.addContent(html, mode);
982
986
  };
983
- actions['audio'] = mode => {
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, '&quot;') : 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="${builder.opts.snippetPath}example.mp3" type="audio/mpeg">
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
- const CLAIMS_FOCUS = '[data-cb-panel], .is-pop, .is-rte-pop, .is-modal, .is-tool, .is-rte-tool, .is-elementrte-tool, .is-side';
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 first = objectSelected && chain.find(tool => (tool._toolbarLevel || 0) >= 30) || chain[0];
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
- this.builder.util.restoreSelection();
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)) target.focus();
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
  });
@@ -19698,12 +19995,23 @@ const OWN_NAV = 'li, td, th';
19698
19995
  const hasText = el => {
19699
19996
  const walker = el.ownerDocument.createTreeWalker(el, 4);
19700
19997
  for (let n = walker.nextNode(); n; n = walker.nextNode()) {
19701
- if (n.parentElement && n.parentElement.closest('svg')) continue;
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;
19702
20001
  if (n.nodeValue.replace(/\u200B/g, '').trim() !== '') return true;
19703
20002
  }
19704
20003
  return false;
19705
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"]');
19706
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]');
19707
20015
  const isPicture = el => !!el && el.nodeType === 1 && (el.tagName === 'IMG' || el.nodeName.toLowerCase() === 'svg' && !(el.parentElement && el.parentElement.closest('svg')));
19708
20016
  class CaretNav {
19709
20017
  constructor(builder) {
@@ -19727,6 +20035,8 @@ class CaretNav {
19727
20035
  if (!this.host(el)) return false;
19728
20036
  if (el.closest('[data-cb-code], .is-row-tool, .is-col-tool, .is-rowadd-tool, [data-cb-ui]')) return false;
19729
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;
19730
20040
  const r = el.getBoundingClientRect();
19731
20041
  if (!r.width && !r.height) return false;
19732
20042
  // A leaf: no other text element inside (a wrapper is not a place).
@@ -19742,10 +20052,16 @@ class CaretNav {
19742
20052
  const b = this.builder;
19743
20053
  const out = [];
19744
20054
  b.doc.querySelectorAll(b.opts.container).forEach(area => {
19745
- 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 => {
19746
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
19747
20062
  if (el.nodeName.toLowerCase() === 'svg' && !isPicture(el)) return;
19748
- if (isPicture(el) || el.getAttribute('contenteditable') === 'false') {
20063
+ if (isMedia(el) && !this.isObject(el)) return;
20064
+ if (isPicture(el) || isMedia(el) || el.getAttribute('contenteditable') === 'false') {
19749
20065
  if (this.isObject(el)) out.push(el);
19750
20066
  return;
19751
20067
  }
@@ -19768,7 +20084,9 @@ class CaretNav {
19768
20084
  // past it; in a line of text the caret passes it and Shift+Arrow selects
19769
20085
  // it (contentbuilder.js, handleCellKeydown).
19770
20086
  isObject(el) {
19771
- if (isPicture(el)) return this.isPictureLine(el);
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);
19772
20090
  if (!el || el.getAttribute('contenteditable') !== 'false') return false;
19773
20091
  if (el.querySelector('[contenteditable="true"]')) return false;
19774
20092
  const host = el.parentElement && this.host(el.parentElement);
@@ -19803,15 +20121,38 @@ class CaretNav {
19803
20121
  selectedObject(range) {
19804
20122
  const icon = this.builder.activeIcon;
19805
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;
19806
20128
  if (!range || range.collapsed || range.startContainer !== range.endContainer || range.startContainer.nodeType !== 1) return null;
19807
20129
  if (range.endOffset - range.startOffset !== 1) return null;
19808
20130
  const el = range.startContainer.childNodes[range.startOffset];
19809
20131
  return el && el.nodeType === 1 && this.isObject(el) ? el : null;
19810
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
+ }
19811
20143
  columnOf(el) {
19812
- let h = this.host(el);
19813
- while (h && !this.isColumn(h)) h = this.host(h.parentElement);
19814
- return h;
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;
19815
20156
  }
19816
20157
  selectObject(el) {
19817
20158
  const b = this.builder;
@@ -19825,7 +20166,8 @@ class CaretNav {
19825
20166
  });
19826
20167
  const select = () => {
19827
20168
  const region = col && b.editingEngine && b.editingEngine.regionFor(col);
19828
- if (region && region.ed && region.ed.selectNode(el)) return;
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;
19829
20171
  const r = b.doc.createRange();
19830
20172
  r.selectNode(el);
19831
20173
  const sel = b.win.getSelection();
@@ -19848,14 +20190,17 @@ class CaretNav {
19848
20190
  // The click last: selecting a picture again after it would make the
19849
20191
  // editor hide the picture's tool. Selected again only if the click
19850
20192
  // let go of it (Delete and Enter need it selected).
19851
- if (b.util && b.util.clickElement) b.util.clickElement(el, {
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, {
19852
20197
  tools: true
19853
20198
  });
19854
20199
  // A drawing is now the selected icon, as after a click.
19855
20200
  if (drawing) return;
19856
20201
  if (this.selectedObject(this.range()) !== el) {
19857
20202
  select();
19858
- if (isPicture(el) && b.util && b.util.clickElement) b.util.clickElement(el, {
20203
+ if ((isPicture(el) || isMedia(el)) && b.util && b.util.clickElement) b.util.clickElement(target, {
19859
20204
  tools: true
19860
20205
  });
19861
20206
  }
@@ -20022,11 +20367,12 @@ class CaretNav {
20022
20367
  }
20023
20368
  go(target, how) {
20024
20369
  this.pending = null;
20025
- // Leaving a selected object: its tools go, as a click elsewhere does.
20026
- const from = this.selectedObject(this.range());
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();
20027
20373
  if (from && this.builder.util && this.builder.util.hideControls) this.builder.util.hideControls();
20028
20374
  if (from) this.dropIcon();
20029
- if (isPicture(target) || target.getAttribute('contenteditable') === 'false') {
20375
+ if (isPicture(target) || isMedia(target) || isIconLink(target) || target.getAttribute('contenteditable') === 'false') {
20030
20376
  this.selectObject(target);
20031
20377
  return;
20032
20378
  }
@@ -20107,7 +20453,7 @@ class CaretNav {
20107
20453
  removeObject(e, forward) {
20108
20454
  const b = this.builder;
20109
20455
  const obj = this.selectedObject(this.range());
20110
- if (!obj || isPicture(obj) || obj.getAttribute('contenteditable') !== 'false') return false;
20456
+ if (!obj || isPicture(obj) || !isMedia(obj) && obj.getAttribute('contenteditable') !== 'false' && !obj.matches('[data-cb-object]')) return false;
20111
20457
  const col = this.columnOf(obj.parentElement);
20112
20458
  if (!col) return false;
20113
20459
  e.preventDefault();
@@ -20122,8 +20468,10 @@ class CaretNav {
20122
20468
  this.dropIcon();
20123
20469
  this.pending = null;
20124
20470
  b.uo.saveForUndo();
20125
- const parent = obj.parentElement;
20126
- obj.remove();
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();
20127
20475
  // An emptied wrapper goes too; an emptied column keeps a line to type on.
20128
20476
  if (parent !== col && !parent.children.length && !hasText(parent)) parent.remove();
20129
20477
  if (!col.children.length) {
@@ -20218,8 +20566,8 @@ class CaretNav {
20218
20566
  enter(e) {
20219
20567
  const b = this.builder;
20220
20568
  const range = this.range();
20221
- if (!range) return;
20222
- const obj = this.selectedObject(range);
20569
+ const obj = this.selectedObject(range) || this.clickedSpacer();
20570
+ if (!range && !obj) return;
20223
20571
  if (obj) {
20224
20572
  e.preventDefault();
20225
20573
  e.stopImmediatePropagation();
@@ -20227,7 +20575,7 @@ class CaretNav {
20227
20575
  const p = b.doc.createElement('p');
20228
20576
  p.appendChild(b.doc.createElement('br'));
20229
20577
  // A picture is in a line of its own: the paragraph goes after the line.
20230
- (isPicture(obj) ? this.lineOf(obj) || obj : obj).after(p);
20578
+ (isPicture(obj) || isMedia(obj) ? this.lineOf(obj) || obj : obj).after(p);
20231
20579
  this.go(p, {
20232
20580
  end: false,
20233
20581
  changed: true
@@ -34573,9 +34921,7 @@ class ButtonEditor {
34573
34921
  if (!el) return;
34574
34922
  this.builder.uo.saveForUndo(true); // checkLater
34575
34923
 
34576
- const dom = this.dom;
34577
- let current = '';
34578
- 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);
34579
34925
  btn.setAttribute('data-focus', true);
34580
34926
  this.builder.colorPicker.open(color => {
34581
34927
  const el = this.getButton();
@@ -34728,7 +35074,6 @@ class ButtonEditor {
34728
35074
  realtime() {
34729
35075
  const el = this.getButton();
34730
35076
  if (!el) return;
34731
- const dom = this.dom;
34732
35077
  const modal = this.buttonModal;
34733
35078
  const r = readButton(el);
34734
35079
  this.syncSeg('size', r.sizeKey);
@@ -34753,14 +35098,21 @@ class ButtonEditor {
34753
35098
  if (href && document.activeElement !== href) href.value = r.href;
34754
35099
  const newtab = modal.querySelector('[data-cmd="newtab"]');
34755
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
+ }
34756
35103
 
34757
- // Normal colours from computed style, so a bg-*/text-* class previews too.
34758
- this.paintSwatch('color-bg', dom.getStyle(el, 'background-color'));
34759
- this.paintSwatch('color-text', dom.getStyle(el, 'color'));
34760
- // Hover colours straight from the model.
34761
- this.paintSwatch('hover-bg', resolveColor(el, r.hoverBg, '--cb-hover-bg'));
34762
- this.paintSwatch('hover-text', resolveColor(el, r.hoverColor, '--cb-hover-color'));
34763
- this.paintSwatch('hover-border', resolveColor(el, r.hoverBorder, '--cb-hover-border'));
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 '';
34764
35116
  }
34765
35117
  syncSeg(cmd, value) {
34766
35118
  this.buttonModal.querySelectorAll(`[data-cmd="${cmd}"]`).forEach(b => {
@@ -35131,11 +35483,7 @@ class Hyperlink {
35131
35483
 
35132
35484
  // https://stackoverflow.com/questions/29908261/prevent-text-selection-on-mouse-drag
35133
35485
  // prevent text selection
35134
- if (this.builder.doc.selection) {
35135
- this.builder.doc.selection.empty();
35136
- } else {
35137
- window.getSelection().removeAllRanges();
35138
- }
35486
+ this.builder.win.getSelection().removeAllRanges(); // the content's window (ContentBox: a frame)
35139
35487
  }
35140
35488
  } else {
35141
35489
  const selectionText = this.builder.selectionText;
@@ -35488,6 +35836,9 @@ class Hyperlink {
35488
35836
  const util = this.builder.util;
35489
35837
  const dom = this.builder.dom;
35490
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;
35491
35842
  let modal = builderStuff.querySelector('.is-modal.createlink');
35492
35843
  let icon = link.querySelector('i');
35493
35844
  modal.querySelector('#lblCreateLinkText').style.display = '';
@@ -35817,12 +36168,9 @@ class Spacer {
35817
36168
  if (dom.hasClass(elm, 'spacer')) {
35818
36169
  this.builder.activeSpacer = elm;
35819
36170
 
35820
- // prevent text selection
35821
- if (document.selection) {
35822
- document.selection.empty();
35823
- } else {
35824
- window.getSelection().removeAllRanges();
35825
- }
36171
+ // prevent text selection (in the content's window: ContentBox's
36172
+ // content is in a frame)
36173
+ this.builder.win.getSelection().removeAllRanges();
35826
36174
  this.showTool(elm);
35827
36175
  } else {
35828
36176
  this.hideTool();
@@ -39122,12 +39470,9 @@ class Svg {
39122
39470
  if (svg) {
39123
39471
  this.builder.activeSvg = svg;
39124
39472
 
39125
- // prevent text selection
39126
- if (document.selection) {
39127
- document.selection.empty();
39128
- } else {
39129
- window.getSelection().removeAllRanges();
39130
- }
39473
+ // prevent text selection (in the content's window: ContentBox's
39474
+ // content is in a frame)
39475
+ this.builder.win.getSelection().removeAllRanges();
39131
39476
 
39132
39477
  // Use the current icon-active class
39133
39478
  this.builder.doc.querySelectorAll('.icon-active').forEach(elm => elm.classList.remove('icon-active'));
@@ -39140,7 +39485,14 @@ class Svg {
39140
39485
  }
39141
39486
  showTool() {
39142
39487
  // Add-on buttons show only for the drawings they are for.
39143
- if (this.builder.addonHost) this.builder.addonHost.updateTool('svg', this.builder.activeSvg);
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
+ }
39144
39496
  this.svgTool.style.display = 'flex';
39145
39497
  this.repositionModuleTool();
39146
39498
  }
@@ -60888,10 +61240,21 @@ function stripZwsp(scope, keep) {
60888
61240
  if (t !== keep && t.data.indexOf(ZWSP) !== -1) dirty.push(t);
60889
61241
  }
60890
61242
  for (const node of dirty) {
60891
- node.data = node.data.split(ZWSP).join('');
61243
+ const held = holdsDrawing(node);
61244
+ node.data = (held ? ZWSP : '') + (held ? node.data.slice(1) : node.data).split(ZWSP).join('');
60892
61245
  }
60893
61246
  }
60894
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
+
60895
61258
  /*
60896
61259
  widgets.js — non-editable islands (contenteditable="false").
60897
61260
 
@@ -65150,6 +65513,30 @@ const FORMAT_INPUT_TYPES = {
65150
65513
  formatUnderline: 'underline',
65151
65514
  formatStrikeThrough: 'strike'
65152
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
+ }
65153
65540
  class Inscribe {
65154
65541
  static instances = new Set();
65155
65542
  static active = null;
@@ -67106,6 +67493,16 @@ class Inscribe {
67106
67493
  return;
67107
67494
  }
67108
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
+ }
67109
67506
  if (it === 'insertParagraph') {
67110
67507
  e.preventDefault();
67111
67508
  this._enter(range);
@@ -67140,6 +67537,7 @@ class Inscribe {
67140
67537
  return; /* consumed: a magic conversion, its own history step */
67141
67538
  }
67142
67539
 
67540
+ if (!range.collapsed && this._keepDrawings(e, range, it)) return;
67143
67541
  this.history.record('typing');
67144
67542
  return;
67145
67543
  }
@@ -67183,11 +67581,115 @@ class Inscribe {
67183
67581
  return;
67184
67582
  }
67185
67583
  }
67584
+ if (this._keepDrawings(e, range, it)) return;
67186
67585
  this.history.record('deleting');
67187
67586
  return;
67188
67587
  }
67189
67588
  this.history.record('command');
67190
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
+ }
67191
67693
  _enter(range) {
67192
67694
  this.history.record('command');
67193
67695
 
@@ -67456,6 +67958,8 @@ class Inscribe {
67456
67958
  _handleKeyDown(e) {
67457
67959
  if (this._readOnly) return;
67458
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;
67459
67963
  /* Cell region: Escape clears it; caret navigation drops it first
67460
67964
  and then behaves normally from the anchor cell. */
67461
67965
  if (this.tableUI.active) {
@@ -67799,6 +68303,7 @@ function dataUrlToFile(dataUrl, baseName) {
67799
68303
  leaves to the host to paint (without these the cell selection
67800
68304
  is invisible — nothing to see when you drag across cells).
67801
68305
  No Inscribe code is modified. */
68306
+ const ZWSP_CHAR = '\u200B'; // see InscribeEngine.holdDrawings()
67802
68307
  const INSCRIBE_STYLE_ID = 'cb-inscribe-styles';
67803
68308
  function ensureInscribeStyles(doc) {
67804
68309
  if (!doc || doc.getElementById(INSCRIBE_STYLE_ID)) return;
@@ -68808,8 +69313,99 @@ class InscribeEngine {
68808
69313
  this.regions.set(el, region);
68809
69314
  }
68810
69315
  region.attach();
69316
+ this._watchRemovals(el.ownerDocument);
69317
+ this.holdDrawings(el);
68811
69318
  return region;
68812
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
+ }
68813
69409
  destroyRegion(el) {
68814
69410
  const region = this.regions.get(el);
68815
69411
  if (region) {
@@ -69285,9 +69881,31 @@ class TableTool {
69285
69881
  this._openSettings();
69286
69882
  break;
69287
69883
  case 'deltable':
69288
- ed.deleteTable();
69289
- this.hide();
69290
- break;
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
+ }
69291
69909
  }
69292
69910
  }
69293
69911
 
@@ -80179,8 +80797,6 @@ class ContentStuff {
80179
80797
  /* Works on any button colour: a white ring at the edge, a dark ring inside
80180
80798
  it. A single hue cannot stay legible over the green, yellow and orange
80181
80799
  tools. */
80182
- .is-section-tool button:focus-visible,
80183
- .is-box-tool button:focus-visible,
80184
80800
  .is-rowadd-tool button:focus-visible,
80185
80801
  /* A canvas block is a stop in the tab order, so which one has the keyboard
80186
80802
  has to be visible. Mouse selection has its own look already. */
@@ -80194,8 +80810,12 @@ class ContentStuff {
80194
80810
  .is-rowadd-tool button:focus-visible {
80195
80811
  outline-offset: -1px;
80196
80812
  }
80813
+ /* Inside the button: a strip that clips (the box tool, the section
80814
+ tool) cannot cut it off. */
80197
80815
  .is-tool button:focus-visible,
80198
80816
  .is-tool [role="button"]:focus-visible,
80817
+ .is-section-tool button:focus-visible,
80818
+ .is-box-tool button:focus-visible,
80199
80819
  .is-rte-tool button:focus-visible,
80200
80820
  .is-elementrte-tool button:focus-visible {
80201
80821
  outline: 2px solid var(--cb-tool-focus-ring, #111);
@@ -98153,6 +98773,18 @@ function openPopover(builder, opts = {}) {
98153
98773
  // For an element the spot wins: a double-click may have left the
98154
98774
  // selection inside it.
98155
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;
98156
98788
  const pop = document.createElement('div');
98157
98789
  pop.className = 'cb-addon-pop';
98158
98790
  // A window opened from the panel goes back here when it closes (util.hideModal).
@@ -98229,6 +98861,24 @@ function openPopover(builder, opts = {}) {
98229
98861
  if (typeof opts.onClose === 'function') opts.onClose(reason);
98230
98862
  // Escape: back to the text, where the caret was (unless the add-on
98231
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
+ }
98232
98882
  if (reason === 'escape' && caret) setTimeout(() => {
98233
98883
  // After an element: there, whatever the selection was (a
98234
98884
  // double-click leaves it inside the element).
@@ -98324,6 +98974,10 @@ const ELEMENT_TOOLS = {
98324
98974
  style: '.image-style'
98325
98975
  },
98326
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,
98327
98981
  buttons: new Map()
98328
98982
  },
98329
98983
  svg: {
@@ -98339,6 +98993,22 @@ const ELEMENT_TOOLS = {
98339
98993
  };
98340
98994
  const SKIP = '[data-cb-type],[data-html],[contenteditable="false"],pre,code,kbd,samp,script,style,textarea';
98341
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
+
98342
99012
  /* Drawing elements an inserted SVG may hold (lower case: the HTML parser's
98343
99013
  names). Anything else (script, foreignObject, image...) is removed. */
98344
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']);
@@ -98432,6 +99102,21 @@ const ICON_PICKER_CSS = `
98432
99102
  body[data-cb-icon-picker] :is(.is-rte-tool, .rte-more-options) .rte-for-text .rte-icon:not(#_cbi) {
98433
99103
  display: none !important;
98434
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
+ }
98435
99120
  class AddonHost {
98436
99121
  constructor(builder) {
98437
99122
  this.builder = builder;
@@ -98690,6 +99375,14 @@ class AddonHost {
98690
99375
  return fn;
98691
99376
  };
98692
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
+ };
98693
99386
  const regionAt = r => {
98694
99387
  if (!r) return null;
98695
99388
  let el = r.startContainer.nodeType === 1 ? r.startContainer : r.startContainer.parentElement;
@@ -98730,8 +99423,30 @@ class AddonHost {
98730
99423
  const doc = builder.doc;
98731
99424
  const sel = doc.getSelection();
98732
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
+ }
98733
99448
  const r = doc.createRange();
98734
- if (offset === 'after') r.setStartAfter(node);else r.setStart(node, offset);
99449
+ if (offset === 'after') caretAfterDrawing(r, node);else r.setStart(node, offset);
98735
99450
  r.collapse(true);
98736
99451
  sel.removeAllRanges();
98737
99452
  sel.addRange(r);
@@ -98972,6 +99687,33 @@ class AddonHost {
98972
99687
  host.setQuiet(on, !!(opts && opts.all));
98973
99688
  if (on && !record.quietCleanup) record.quietCleanup = track(() => host.setQuiet(false));
98974
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)),
98975
99717
  /** Hide the element tool (the small tool beside a clicked element: add,
98976
99718
  more, delete, settings), for an add-on that offers the same another way.
98977
99719
  As the Preferences' "hide element tool". Returns a function that shows
@@ -98998,7 +99740,8 @@ class AddonHost {
98998
99740
  isQuiet: () => !!host.quiet,
98999
99741
  /** The editor's own icon, as markup, so an add-on's buttons look like
99000
99742
  the editor's: 'bold', 'italic', 'underline', 'strikethrough', 'clean',
99001
- 'link', 'unlink', 'up', 'down', 'duplicate', 'delete', 'settings'. '' for another name. */
99743
+ 'link', 'unlink', 'code', 'up', 'down', 'duplicate', 'delete', 'settings',
99744
+ 'align-left', 'align-center', 'align-right', 'align-justify'. '' for another name. */
99002
99745
  icon: name => {
99003
99746
  const letter = (style, ch) => `<span aria-hidden="true" style="font-family:serif;${style}">${ch}</span>`;
99004
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>`;
@@ -99015,6 +99758,8 @@ class AddonHost {
99015
99758
  return sprite('icon-eraser', 16);
99016
99759
  case 'link':
99017
99760
  return sprite('ion-link', 14);
99761
+ case 'code':
99762
+ return sprite('icon-code', 16);
99018
99763
  case 'unlink':
99019
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>';
99020
99765
  case 'up':
@@ -99027,18 +99772,35 @@ class AddonHost {
99027
99772
  return sprite('icon-trash2', 15);
99028
99773
  case 'settings':
99029
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);
99030
99783
  default:
99031
99784
  return '';
99032
99785
  }
99033
99786
  },
99034
- /** The editor's colour picker. { color, onPick(color), onClose() };
99035
- 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). */
99036
99791
  pickColor: ({
99037
99792
  color = '',
99038
99793
  onPick,
99039
- onClose
99794
+ onClose,
99795
+ anchor
99040
99796
  } = {}) => {
99041
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);
99042
99804
  builder.colorPicker.open(c => {
99043
99805
  try {
99044
99806
  if (onPick) onPick(c);
@@ -99051,7 +99813,7 @@ class AddonHost {
99051
99813
  } catch (e) {
99052
99814
  log(record.name, 'pickColor close failed.', e);
99053
99815
  }
99054
- });
99816
+ }, at);
99055
99817
  return true;
99056
99818
  }
99057
99819
  }),
@@ -99292,6 +100054,11 @@ class AddonHost {
99292
100054
  if (!nav) return null;
99293
100055
  const r = this.selection();
99294
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;
99295
100062
  if (!el) {
99296
100063
  const a = builder.activeElement;
99297
100064
  if (a && a.isConnected && (a.matches('[data-cb-type], [data-cb-code]') || nav.isObject(a))) {
@@ -99321,12 +100088,13 @@ class AddonHost {
99321
100088
  return true;
99322
100089
  },
99323
100090
  /** Format the selected text as the text toolbar does: 'bold', 'italic',
99324
- 'underline', 'strikethrough', 'clean' (clear formatting; links stay),
99325
- 'unlink', or 'link' (opens the editor's link window). One undo step.
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.
99326
100094
  Returns false when the selection is not in editable text. */
99327
100095
  format(command) {
99328
100096
  const r = this.selection();
99329
- if (!r || !regionAt(r) || !this.isEditable(r.startContainer)) return false;
100097
+ if (!r || !regionAt(r) || !this.isEditable(outOfInlineCode(r.startContainer))) return false;
99330
100098
  builder.util.saveSelection(); // the editor's commands restore the saved selection
99331
100099
  if (command === 'link') {
99332
100100
  builder.element.hyperlink.createLink();
@@ -99335,7 +100103,8 @@ class AddonHost {
99335
100103
  const region = builder.editingEngine.active;
99336
100104
  if (!region) return false;
99337
100105
  builder.uo.saveForUndo();
99338
- if (command === 'unlink') region.unlink();else builder.rte.formatText(command);
100106
+ if (command === 'unlink') region.unlink();else if (command === 'code') region.toggleStyle('code'); // inline code: <code>
100107
+ else builder.rte.formatText(command);
99339
100108
  builder.util.saveSelection();
99340
100109
  builder.opts.onChange();
99341
100110
  if (builder.rte.getState) builder.rte.getState();
@@ -99343,7 +100112,9 @@ class AddonHost {
99343
100112
  },
99344
100113
  /** What the selected text is: { bold, italic, underline, strikethrough,
99345
100114
  link (inside a link), block ('p', 'h2', ... the first line's tag),
99346
- list ('ul', 'ol' or null) }, or null outside editable text. */
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. */
99347
100118
  formatState() {
99348
100119
  const r = this.selection();
99349
100120
  const region = r && regionAt(r);
@@ -99358,18 +100129,34 @@ class AddonHost {
99358
100129
  italic: !!st.italic,
99359
100130
  underline: !!st.underline,
99360
100131
  strikethrough: !!st.strike,
100132
+ code: !!st.code,
99361
100133
  link: !!st.link || a(r.startContainer) || a(r.endContainer),
99362
100134
  block: st.block || null,
99363
- list: st.list || null
100135
+ list: st.list || null,
100136
+ align: st.align || null
99364
100137
  };
99365
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
+ },
99366
100153
  /** Turn the selected lines into another kind, keeping their text:
99367
100154
  'p', 'h1' to 'h6', 'blockquote', 'pre', or 'ul' / 'ol' (a list).
99368
100155
  One undo step. Returns false when nothing changed. */
99369
100156
  setBlock(kind) {
99370
100157
  const r = this.selection();
99371
100158
  const region = r && regionAt(r);
99372
- if (!region || !this.isEditable(r.startContainer)) return false;
100159
+ if (!region || !this.isEditable(outOfInlineCode(r.startContainer))) return false;
99373
100160
  const doc = builder.doc;
99374
100161
  const lines = () => {
99375
100162
  const out = [];
@@ -99441,6 +100228,22 @@ class AddonHost {
99441
100228
  hasImagePicker() {
99442
100229
  return typeof builder.hasFilePicker === 'function' && !!builder.hasFilePicker('image');
99443
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
+ },
99444
100247
  /** Whether the site set an image upload (onImageUpload), so
99445
100248
  uploadImages() really uploads; without one an embedded image
99446
100249
  stays in the page. */
@@ -99483,7 +100286,7 @@ class AddonHost {
99483
100286
  });
99484
100287
  const sel = builder.doc.getSelection();
99485
100288
  const after = builder.doc.createRange();
99486
- after.setStartAfter(placed);
100289
+ caretAfterDrawing(after, placed);
99487
100290
  after.collapse(true);
99488
100291
  sel.removeAllRanges();
99489
100292
  sel.addRange(after);
@@ -99529,8 +100332,9 @@ class AddonHost {
99529
100332
  /** Insert what the quick add panel's item `id` inserts (see blocks()),
99530
100333
  right after `after`, an element in a column, as one undo step.
99531
100334
  Returns the new elements in order (some items add two), or an
99532
- empty list ('more' opens the snippets window). */
99533
- addBlock(id, after) {
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 = {}) {
99534
100338
  const actions = host.quickAdd();
99535
100339
  if (!actions[id] || !this.blocks().includes(id)) return [];
99536
100340
  if (id === 'more') {
@@ -99541,8 +100345,10 @@ class AddonHost {
99541
100345
  const parent = after.parentNode;
99542
100346
  const old = new Set(parent.children);
99543
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.
99544
100350
  try {
99545
- actions[id]('elm');
100351
+ actions[id]('elm', opts && opts.src ? String(opts.src) : undefined);
99546
100352
  } catch (e) {
99547
100353
  log(record.name, 'addBlock failed.', e);
99548
100354
  return [];
@@ -99645,6 +100451,46 @@ class AddonHost {
99645
100451
  const region = regionAt(range || this.selection());
99646
100452
  return builder.preparePasteHtml(String(text), String(html || text), region);
99647
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
+ },
99648
100494
  /** Upload the embedded (data:) images in or at an element of the
99649
100495
  content through the editor's upload, as pasted images are.
99650
100496
  For content an add-on changed itself, e.g. a new image src. */
@@ -99846,6 +100692,10 @@ class AddonHost {
99846
100692
  title: def.menuTitle ? this.builder.util.out(def.menuTitle) : menuTitleOf(title, this.builder.util.out(menuDef.label))
99847
100693
  } : null;
99848
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
+
99849
100699
  // A place the host (ContentBox) provides wins.
99850
100700
  const hostPlaces = this.builder.opts.addonPlaces;
99851
100701
  if (hostPlaces && typeof hostPlaces[place] === 'function') {
@@ -99860,7 +100710,7 @@ class AddonHost {
99860
100710
  }) || null;
99861
100711
  }
99862
100712
  if (place === 'text') return this.addTextButton(id, title, def.html || '', onClick, on, menu);
99863
- 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);
99864
100714
  console.warn(`[ContentBuilder] add-on "${record.name}": button place "${place}" is not available here.`);
99865
100715
  return null;
99866
100716
  }
@@ -100149,13 +100999,14 @@ class AddonHost {
100149
100999
  accepts; the click gets the element. hides: the tool's own buttons to
100150
101000
  hide for those elements (image: 'edit', 'change', 'link'; svg:
100151
101001
  'settings'), e.g. ones that would break what the add-on made. */
100152
- addToolButton(kind, id, title, html, onClick, when, hides) {
101002
+ addToolButton(kind, id, title, html, onClick, when, hides, record) {
100153
101003
  const spec = ELEMENT_TOOLS[kind];
100154
101004
  const owner = {
100155
101005
  host: this,
100156
101006
  onClick,
100157
101007
  when: typeof when === 'function' ? when : null,
100158
- hides: Array.isArray(hides) ? hides : []
101008
+ hides: Array.isArray(hides) ? hides : [],
101009
+ record
100159
101010
  };
100160
101011
  let btn = spec.buttons.get(id);
100161
101012
  if (btn) {
@@ -100189,6 +101040,44 @@ class AddonHost {
100189
101040
  if (tool) this.placeToolButton(tool, btn, spec);
100190
101041
  return btn;
100191
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
+ }
100192
101081
  placeToolButton(tool, btn, spec) {
100193
101082
  // Add-on buttons keep the order they were added in.
100194
101083
  const own = spec.first ? Array.from(tool.children).find(c => !c.hasAttribute('data-addon')) : null;
@@ -100222,24 +101111,27 @@ class AddonHost {
100222
101111
  show = false;
100223
101112
  }
100224
101113
  }
100225
- btn.style.display = show ? '' : 'none';
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';
100226
101117
  if (show) o.hides.forEach(name => hide.add(name));
100227
- });
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
+ }
100228
101132
  Object.entries(spec.own).forEach(([name, selector]) => {
100229
101133
  const b = tool.querySelector(selector);
100230
- if (!b) return;
100231
- // Restored to what it was: a button the editor's options hide
100232
- // (e.g. imageEmbed: false) stays hidden.
100233
- if (hide.has(name)) {
100234
- if (!b._cbAddonHidden) {
100235
- b._cbAddonPrev = b.style.display;
100236
- b._cbAddonHidden = true;
100237
- }
100238
- b.style.display = 'none';
100239
- } else if (b._cbAddonHidden) {
100240
- b.style.display = b._cbAddonPrev || '';
100241
- b._cbAddonHidden = false;
100242
- }
101134
+ if (b) b.toggleAttribute('data-cb-addon-hidden', hide.has(name));
100243
101135
  });
100244
101136
  }
100245
101137
 
@@ -103305,7 +104197,10 @@ class ContentBuilder {
103305
104197
  // In Inscribe mode a media-only column (just an image/
103306
104198
  // figure/video, no text) is still editable — Inscribe
103307
104199
  // manages image selection, resize, and figures there.
103308
- const hasMedia = this.opts.engine === 'inscribe' && col.querySelector('img,figure,picture,video');
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');
103309
104204
  if (elms.length > 0 || _text !== '' || hasMedia) {
103310
104205
  // EVERY column is an Inscribe region (ContentBuilder's
103311
104206
  // rule: all columns are editable). A plugin/module inside
@@ -104450,6 +105345,7 @@ class ContentBuilder {
104450
105345
  this.addonHost.destroy();
104451
105346
  this.addonHost = null;
104452
105347
  }
105348
+ if (this.toolbarKeys) this.toolbarKeys.destroy();
104453
105349
  const snippetData = document.querySelector('#_snippet_data');
104454
105350
  if (snippetData) snippetData.remove();
104455
105351
  const linkStyle = document.head.querySelector('#_snippet_style');
@@ -104864,8 +105760,9 @@ class ContentBuilder {
104864
105760
  inpFile.remove();
104865
105761
  return;
104866
105762
  }
105763
+ // A failed or cancelled upload returns no URL, and the field keeps what it had
104867
105764
  this.onAssetUpload = url => {
104868
- if (callback) callback(url);
105765
+ if (callback && url) callback(url);
104869
105766
  };
104870
105767
  await handler(e);
104871
105768
  inpFile.remove();
@@ -107330,7 +108227,8 @@ Please obtain a license at: https://innovastudio.com/contentbox`);
107330
108227
  // If column only has spacer, locked or unlocked,
107331
108228
  // the text should not be able to edit (cursor should not be able to be placed)
107332
108229
  // So, make the column uneditable (text) if only has a spacer.
107333
- if (col.childElementCount === 1) {
108230
+ // (Not with Inscribe: the column stays editable, see applyBehavior.)
108231
+ if (col.childElementCount === 1 && this.opts.engine !== 'inscribe') {
107334
108232
  let elm = col.children[0];
107335
108233
  if (elm) if (this.dom.hasClass(elm, 'spacer')) {
107336
108234
  col.contentEditable = false;
@@ -107482,7 +108380,10 @@ Please obtain a license at: https://innovastudio.com/contentbox`);
107482
108380
  const off = sel.focusOffset;
107483
108381
  let next = null;
107484
108382
  if (node.nodeType === 3) {
107485
- if (forward && off === node.length) next = node.nextSibling;else if (!forward && off === 0) next = node.previousSibling;
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;
107486
108387
  } else {
107487
108388
  next = forward ? node.childNodes[off] : node.childNodes[off - 1];
107488
108389
  }
@@ -107498,6 +108399,12 @@ Please obtain a license at: https://innovastudio.com/contentbox`);
107498
108399
  e.stopPropagation();
107499
108400
  return;
107500
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
+ }
107501
108408
 
107502
108409
  // The keyboard way to select an SVG drawing or a picture in the text
107503
108410
  // (what a click does, see elements.js): the caret skips over it, so
@@ -107529,7 +108436,7 @@ Please obtain a license at: https://innovastudio.com/contentbox`);
107529
108436
  this.element.svg.hideTool();
107530
108437
  }
107531
108438
  const range = this.doc.createRange();
107532
- if (forward) range.setStartAfter(icon);else range.setStartBefore(icon);
108439
+ if (forward) caretAfterDrawing(range, icon);else range.setStartBefore(icon);
107533
108440
  range.collapse(true);
107534
108441
  const sel = this.win.getSelection();
107535
108442
  sel.removeAllRanges();
@@ -107967,7 +108874,13 @@ Please obtain a license at: https://innovastudio.com/contentbox`);
107967
108874
  // console.log('typing');
107968
108875
  if (this.timeoutId) clearTimeout(this.timeoutId);
107969
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';
107970
108882
  this.opts.onChange();
108883
+ if (shown) this.element.image.repositionImageTool();
107971
108884
  }, 2000);
107972
108885
  }
107973
108886
 
@@ -108580,6 +109493,9 @@ Please obtain a license at: https://innovastudio.com/contentbox`);
108580
109493
  builderActive = scope.querySelector('.is-builder');
108581
109494
  if (builderActive) this.applyBehaviorOn(builderActive);
108582
109495
  }
109496
+
109497
+ // Mount the plugin blocks the snippet brought, as dropping one in does
109498
+ if (builderActive) this.reinitPlugins(builderActive);
108583
109499
  let cellElement = rowElement.querySelector('div');
108584
109500
  if (cellElement) cellElement.click(); //change active block to the newly created
108585
109501