@innovastudio/contentbuilder 1.5.230 → 1.5.232

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -689,6 +689,11 @@ interface ContentBuilderAddonApi {
689
689
  /** ContentBox: fn(box) runs each time the selected box changes (null when none is selected).
690
690
  * Never runs in ContentBuilder. Returns a function that stops it. */
691
691
  onSelectBox(fn: (box: HTMLElement | null) => void): () => void;
692
+ /** fn(doc) runs with the document the content lives in (ContentBox: its page frame; else the page),
693
+ * also when the page has no content yet: where to listen to the content or add styles for it.
694
+ * The function fn returns, if any, runs when the add-on is removed or the editor destroyed.
695
+ * Returns a function that does that now. */
696
+ onDocument(fn: (doc: Document) => void | (() => void)): () => void;
692
697
  /** Change the content as one undo step. Return false from fn when nothing changed. */
693
698
  edit<T>(fn: () => T): T;
694
699
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@innovastudio/contentbuilder",
4
- "version": "1.5.230",
4
+ "version": "1.5.232",
5
5
  "description": "",
6
6
  "main": "public/contentbuilder/contentbuilder.esm.js",
7
7
  "types": "index.d.ts",
@@ -62792,6 +62792,7 @@ function filterStyle(el, allowedProps) {
62792
62792
  for (const [p, v] of keep) el.style.setProperty(p, v);
62793
62793
  if (!el.getAttribute('style')) el.removeAttribute('style');
62794
62794
  }
62795
+ const MARKUP_DATA = /^data-(html(-\d+)?|settings|src|cb-original-content|cb-content|module-desc)$/;
62795
62796
  function sanitizeHTML(html, config = {}) {
62796
62797
  const conf = {
62797
62798
  tags: config.tags || DEFAULTS$1.tags,
@@ -62824,7 +62825,13 @@ function sanitizeHTML(html, config = {}) {
62824
62825
  if (attr.value !== 'false') el.removeAttribute(attr.name);
62825
62826
  continue;
62826
62827
  }
62827
- if (name.indexOf('data-') === 0) continue; /* widget state lives here */
62828
+ if (name.indexOf('data-') === 0) {
62829
+ /* Widget state lives here, except the attributes the editor turns
62830
+ back into markup or code (a module's source, a plugin's original
62831
+ content): from outside content they would bring in script. */
62832
+ if (MARKUP_DATA.test(name)) el.removeAttribute(attr.name);
62833
+ continue;
62834
+ }
62828
62835
  if (name === 'style') {
62829
62836
  filterStyle(el, conf.styleProps);
62830
62837
  continue;
@@ -68751,7 +68758,7 @@ class InscribeRegion {
68751
68758
  // keeps them (registered after the editor's own blur handler).
68752
68759
  this.ed.on('blur', () => {
68753
68760
  const img = this.builder.activeImage;
68754
- if (img && img.isConnected && this.el.contains(img) && !imageFillsBox(img)) imageUI._show(img);
68761
+ if (imageUI.enabled && img && img.isConnected && this.el.contains(img) && !imageFillsBox(img)) imageUI._show(img);
68755
68762
  });
68756
68763
  }
68757
68764
 
@@ -69441,7 +69448,7 @@ class InscribeEngine {
69441
69448
  for (const r of this.regions.values()) {
69442
69449
  const ui = r.ed && r.ed.imageUI;
69443
69450
  if (!ui) continue;
69444
- if (img && img.isConnected && r.el && r.el.contains(img) && !imageFillsBox(img)) ui._show(img);else ui._syncToSelection();
69451
+ if (ui.enabled && img && img.isConnected && r.el && r.el.contains(img) && !imageFillsBox(img)) ui._show(img);else ui._syncToSelection();
69445
69452
  }
69446
69453
  }
69447
69454
  hideImageHandles() {
@@ -89150,6 +89157,13 @@ ${singleModel ? '' : `
89150
89157
  // Block-level HTML is the answer itself — show it as code so
89151
89158
  // its line breaks survive. Inline HTML stays in the sentence.
89152
89159
  return token && token.block ? '<pre><code>' + esc.replace(/\n$/, '') + '</code></pre>' : esc;
89160
+ },
89161
+ // A javascript: (or data:) link in a reply would run in the
89162
+ // editor: shown as text. Every other link stays.
89163
+ link(token) {
89164
+ const href = Array.from(String(token.href || '')).filter(ch => ch.charCodeAt(0) > 32).join('');
89165
+ if (!/^(javascript|vbscript|data):/i.test(href)) return false;
89166
+ return this.parser.parseInline(token.tokens);
89153
89167
  }
89154
89168
  }
89155
89169
  });
@@ -92743,13 +92757,16 @@ ${this.buildHistoryContext()}`;
92743
92757
  <div class="message-header">${out('Generated Images')}</div>
92744
92758
  <div class="message-content" style="display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; padding: 12px;">
92745
92759
  `;
92760
+
92761
+ // A caption can be written by the AI: escaped, quotes too.
92762
+ const esc = s => String(s == null ? '' : s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
92746
92763
  images.forEach(img => {
92747
92764
  previewHTML += `
92748
92765
  <div style="border-radius: 6px; overflow: hidden; background: rgba(255,255,255,0.05);">
92749
- <img src="${img.url}" alt="${img.context || 'Generated image'}" style="width: 100%;" />
92766
+ <img src="${esc(img.url)}" alt="${esc(img.context || 'Generated image')}" style="width: 100%;" />
92750
92767
  <div style="padding: 8px; font-size: 11px; opacity: 0.8;">
92751
- ${img.context || ''}
92752
- <a href="${img.url}" target="_blank" rel="noopener noreferrer" style="display: block; margin-top: 4px;">View</a>
92768
+ ${esc(img.context || '')}
92769
+ <a href="${esc(img.url)}" target="_blank" rel="noopener noreferrer" style="display: block; margin-top: 4px;">View</a>
92753
92770
  </div>
92754
92771
  </div>
92755
92772
  `; // height: 150px; object-fit: cover;
@@ -93786,9 +93803,11 @@ ${this.buildHistoryContext()}`;
93786
93803
  <div class="message-header">${out('Assistant')}</div>
93787
93804
  <div class="loading">
93788
93805
  <div class="spinner"></div>
93789
- <span>${taskDescription || out('Processing...')}</span>
93806
+ <span></span>
93790
93807
  </div>
93791
93808
  `;
93809
+ // The step's text can be written by the AI: shown as text.
93810
+ loadingDiv.querySelector('.loading span').textContent = taskDescription || out('Processing...');
93792
93811
  this.messagesContainer.appendChild(loadingDiv);
93793
93812
  this.messagesContainer.scrollTop = this.messagesContainer.scrollHeight;
93794
93813
  return loadingId;
@@ -94746,8 +94765,10 @@ function createSectionTarget(engine) {
94746
94765
  */
94747
94766
  function normalize(html) {
94748
94767
  if (!html || typeof html !== 'string') return null;
94749
- const holder = document.createElement('div');
94750
- holder.innerHTML = html.replace(/```html\n?/g, '').replace(/```\n?/g, '').trim();
94768
+ // An inert template: nothing in the AI's markup loads or runs here.
94769
+ const tpl = document.createElement('template');
94770
+ tpl.innerHTML = html.replace(/```html\n?/g, '').replace(/```\n?/g, '').trim();
94771
+ const holder = tpl.content;
94751
94772
  const found = holder.querySelectorAll('.is-section');
94752
94773
  if (found.length !== 1) return null;
94753
94774
  const section = found[0];
@@ -95160,8 +95181,10 @@ function createRowTarget(engine) {
95160
95181
  */
95161
95182
  function normalize(html) {
95162
95183
  if (!html || typeof html !== 'string') return null;
95163
- const holder = document.createElement('div');
95164
- holder.innerHTML = html.replace(/```html\n?/g, '').replace(/```\n?/g, '').trim();
95184
+ // An inert template: nothing in the AI's markup loads or runs here.
95185
+ const tpl = document.createElement('template');
95186
+ tpl.innerHTML = html.replace(/```html\n?/g, '').replace(/```\n?/g, '').trim();
95187
+ const holder = tpl.content;
95165
95188
  const found = Array.from(holder.children).filter(el => el.classList.contains('row'));
95166
95189
  if (found.length !== 1) return null;
95167
95190
  repairButtons(found[0]);
@@ -95558,6 +95581,13 @@ const md = new B({
95558
95581
  // Block-level HTML is the answer itself — show it as code so its
95559
95582
  // line breaks survive. Inline HTML stays in the sentence.
95560
95583
  return token && token.block ? '<pre><code>' + esc.replace(/\n$/, '') + '</code></pre>' : esc;
95584
+ },
95585
+ // A javascript: (or data:) link in a reply would run in the editor:
95586
+ // shown as text. Every other link stays.
95587
+ link(token) {
95588
+ const href = Array.from(String(token.href || '')).filter(ch => ch.charCodeAt(0) > 32).join('');
95589
+ if (!/^(javascript|vbscript|data):/i.test(href)) return false;
95590
+ return this.parser.parseInline(token.tokens);
95561
95591
  }
95562
95592
  }
95563
95593
  });
@@ -100197,9 +100227,11 @@ class AddonHost {
100197
100227
  // Images that arrive inside the HTML (a Word file's) go
100198
100228
  // through the editor's upload, as pasted images do.
100199
100229
  if (html.indexOf('data:image/') !== -1) {
100200
- const tmp = document.createElement('div');
100230
+ // An inert template: nothing in it loads or runs
100231
+ // (the sanitizer only cleans it on insert).
100232
+ const tmp = document.createElement('template');
100201
100233
  tmp.innerHTML = html;
100202
- tmp.querySelectorAll('img[src^="data:image/"]').forEach(im => im.setAttribute('data-cb-paste-upload', ''));
100234
+ tmp.content.querySelectorAll('img[src^="data:image/"]').forEach(im => im.setAttribute('data-cb-paste-upload', ''));
100203
100235
  html = tmp.innerHTML;
100204
100236
  }
100205
100237
  const sel = builder.doc.getSelection();
@@ -100368,9 +100400,9 @@ class AddonHost {
100368
100400
  const r = range || this.selection();
100369
100401
  const region = regionAt(r);
100370
100402
  if (!region) return null;
100371
- const tmp = document.createElement('div');
100403
+ const tmp = document.createElement('template');
100372
100404
  tmp.innerHTML = String(svg);
100373
- const el = tmp.querySelector('svg');
100405
+ const el = tmp.content.querySelector('svg');
100374
100406
  if (!el) return null;
100375
100407
  cleanSvg(el);
100376
100408
  if (opts && opts.line) {
@@ -100420,6 +100452,34 @@ class AddonHost {
100420
100452
  host.boxHandlers = host.boxHandlers.filter(e => e !== entry);
100421
100453
  });
100422
100454
  },
100455
+ /** fn(doc) runs with the document the content lives in (in
100456
+ ContentBox its page frame, else the page), also when the
100457
+ page has no content yet: the place to listen to the content
100458
+ or add styles for it. The function fn returns, if any, runs
100459
+ when the add-on is removed or the editor destroyed. Returns
100460
+ a function that does that now. */
100461
+ onDocument(fn) {
100462
+ if (typeof fn !== 'function') return () => {};
100463
+ let undo = null;
100464
+ try {
100465
+ const r = fn(builder.doc);
100466
+ if (typeof r === 'function') undo = r;
100467
+ } catch (e) {
100468
+ log(record.name, 'onDocument failed.', e);
100469
+ }
100470
+ let done = false;
100471
+ return track(() => {
100472
+ if (done) return;
100473
+ done = true;
100474
+ if (undo) {
100475
+ try {
100476
+ undo();
100477
+ } catch (e) {
100478
+ log(record.name, 'onDocument cleanup failed.', e);
100479
+ }
100480
+ }
100481
+ });
100482
+ },
100423
100483
  /** The SVG drawing the user selected in the text by clicking it (an
100424
100484
  inserted icon or equation), or null. */
100425
100485
  selectedSvg() {
@@ -108946,7 +109006,7 @@ Please obtain a license at: https://innovastudio.com/contentbox`);
108946
109006
  // Auto-embed a pasted YouTube/Vimeo URL
108947
109007
  if (!this.opts.disableAutoEmbedVideo) {
108948
109008
  const src = contentword.innerText;
108949
- const youRegex = /^http[s]?:\/\/(((www.youtube.com\/watch\?(feature=player_detailpage&)?)v=)|(youtu.be\/))([^#&?]*)/;
109009
+ const youRegex = /^http[s]?:\/\/(((www.youtube.com\/watch\?(feature=player_detailpage&)?)v=)|(youtu.be\/))([\w-]+)/;
108950
109010
  const vimeoRegex = /^.*(vimeo\.com\/)((channels\/[A-z]+\/)|(groups\/[A-z]+\/videos\/)|(video\/))?([0-9]+)\/?/;
108951
109011
  const y = youRegex.exec(src),
108952
109012
  v = vimeoRegex.exec(src);
@@ -108954,6 +109014,7 @@ Please obtain a license at: https://innovastudio.com/contentbox`);
108954
109014
  let embedSrc = src;
108955
109015
  if (y && y.length >= 7) embedSrc = 'https://www.youtube.com/embed/' + y[6] + '?rel=0';
108956
109016
  if (v && v.length >= 7) embedSrc = 'https://player.vimeo.com/video/' + v[6];
109017
+ embedSrc = embedSrc.replace(/"/g, '%22').replace(/</g, '%3C').replace(/>/g, '%3E');
108957
109018
  return '<div class="embed-responsive embed-responsive-16by9"><iframe tabindex="0" width="560" height="315" src="' + embedSrc + '" frameborder="0" allowfullscreen=""></iframe></div>';
108958
109019
  }
108959
109020
  }