@innovastudio/contentbox 1.6.133 → 1.6.135

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
@@ -364,6 +364,16 @@ interface ContentBoxOptions {
364
364
  //---
365
365
  }
366
366
 
367
+ interface OpenModalOptions {
368
+ w?: string; // modal width (e.g. "500px", "100%")
369
+ maxW?: string; // max width
370
+ h?: string; // modal height
371
+ extraStyle?: string; // inline extra styles
372
+ ariaLabel?: string; // accessibility label
373
+ onOpen?: (modal: HTMLElement, iframe: HTMLIFrameElement) => void; // callback when opened
374
+ onClose?: (modal: HTMLElement, iframe: HTMLIFrameElement) => void; // callback when closed
375
+ }
376
+
367
377
  declare class ContentBox {
368
378
  constructor(options: ContentBoxOptions);
369
379
 
@@ -390,7 +400,7 @@ declare class ContentBox {
390
400
  viewHtml(): void;
391
401
  toggleEditPanel(): void;
392
402
  getWrapper(): HTMLElement;
393
-
403
+ openModal(url: string, options?: OpenModalOptions): void;
394
404
  screenMode: string;
395
405
  }
396
406
  export default ContentBox;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@innovastudio/contentbox",
3
3
  "type": "module",
4
- "version": "1.6.133",
4
+ "version": "1.6.135",
5
5
  "description": "",
6
6
  "main": "public/contentbox/contentbox.esm.js",
7
7
  "types": "index.d.ts",
@@ -59,7 +59,7 @@
59
59
  "ws": "^8.13.0"
60
60
  },
61
61
  "dependencies": {
62
- "@innovastudio/contentbuilder": "^1.5.124",
62
+ "@innovastudio/contentbuilder": "^1.5.125",
63
63
  "js-beautify": "^1.14.0",
64
64
  "sortablejs": "^1.15.2"
65
65
  }
@@ -3174,6 +3174,17 @@ body.fullview.topspace .is-content-view iframe {
3174
3174
  transition: none !important;
3175
3175
  }
3176
3176
 
3177
+ /* Custom Model for openModal() */
3178
+ #_cbhtml .is-modal.custom-modal button.modal-close {
3179
+ position: absolute;
3180
+ top: 4px;
3181
+ right: 10px;
3182
+ width: 30px;
3183
+ height: 30px;
3184
+ font-size: 23px;
3185
+ background: transparent !important;
3186
+ }
3187
+
3177
3188
  /* content.css */
3178
3189
  #_cbhtml {
3179
3190
  /* Text Formatting */
@@ -113586,11 +113586,29 @@ ${answer}
113586
113586
  data = await response.json();
113587
113587
  }
113588
113588
  if (data.error) {
113589
+ let errorMessage = '';
113590
+ if (typeof data.error === 'string') {
113591
+ errorMessage = data.error;
113592
+ } else if (typeof data.error === 'object') {
113593
+ // Target deeply nested error messages
113594
+ if (data.error.error && data.error.error.message) {
113595
+ errorMessage = data.error.error.message;
113596
+ } else if (data.error.message) {
113597
+ errorMessage = data.error.message;
113598
+ } else {
113599
+ // Fallback for other objects
113600
+ errorMessage = JSON.stringify(data.error);
113601
+ }
113602
+ } else {
113603
+ // Fallback for unexpected types
113604
+ errorMessage = String(data.error);
113605
+ }
113606
+
113589
113607
  // Error response from OpenAI goes here.
113590
- console.log('Error:\n' + data.error);
113608
+ console.log('Error:\n' + errorMessage);
113591
113609
 
113592
113610
  // ex. wrong API Key => Request failed with status code 401
113593
- this.util.showMessage(this.util.out('Request failed.'));
113611
+ this.util.showMessage(this.util.out('Request failed. ' + errorMessage));
113594
113612
  this.dictation.finish(); // Must be called after finished
113595
113613
  return;
113596
113614
  }
@@ -164269,6 +164287,52 @@ Add an image for each feature.`, 'Create a new block showcasing a photo gallery
164269
164287
  }, 400);
164270
164288
  }
164271
164289
 
164290
+ openModal(url, prop = {}) {
164291
+ const defaults = {
164292
+ w: '88vw',
164293
+ maxW: '1600px',
164294
+ h: '88vh',
164295
+ extraStyle: '',
164296
+ ariaLabel: 'Modal',
164297
+ showCloseButton: false
164298
+ };
164299
+ const config = { ...defaults,
164300
+ ...prop
164301
+ };
164302
+ const html = `
164303
+ <div class="is-modal custom-modal" style="z-index:10005" tabindex="-1" role="dialog" aria-modal="true" aria-hidden="true">
164304
+ <div style="width:${config.w};max-width:${config.maxW};height:${config.h};padding:0;${config.extraStyle}">
164305
+ <iframe tabindex="0" style="width:100%;height:100%;border: none;display: block;" src="about:blank"></iframe>
164306
+ </div>
164307
+ </div>
164308
+ `;
164309
+ const oldModal = this.builderStuff.querySelector('.is-modal.custom-modal');
164310
+ if (oldModal) oldModal.remove();
164311
+ this.builderStuff.insertAdjacentHTML('beforeend', html);
164312
+ const modal = this.builderStuff.querySelector('.is-modal.custom-modal');
164313
+ modal.setAttribute('aria-label', config.ariaLabel);
164314
+ const iframe = modal.querySelector('iframe');
164315
+ iframe.src = url;
164316
+
164317
+ if (config.showCloseButton) {
164318
+ const closeBtn = document.createElement('button');
164319
+ closeBtn.innerHTML = `
164320
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-x"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M18 6l-12 12" /><path d="M6 6l12 12" /></svg>
164321
+ `;
164322
+ closeBtn.className = 'modal-close';
164323
+ closeBtn.addEventListener('click', () => {
164324
+ modal.remove();
164325
+ if (typeof config.onClose === 'function') config.onClose(modal, iframe);
164326
+ });
164327
+ modal.querySelector('div').prepend(closeBtn);
164328
+ }
164329
+
164330
+ if (typeof config.onOpen === 'function') config.onOpen(modal, iframe);
164331
+ this.editor.util.showModal(modal, false, () => {
164332
+ if (typeof config.onClose === 'function') config.onClose(modal, iframe);
164333
+ });
164334
+ }
164335
+
164272
164336
  boxImage(url, err) {
164273
164337
  if (!this.controlPanel) {
164274
164338
  this.editbox.boxImage(url, err);