@innovastudio/contentbuilder 1.5.133 → 1.5.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
@@ -285,7 +285,11 @@ declare class ContentBuilder {
285
285
  constructor(options?: ContentBuilderOptions);
286
286
 
287
287
  html(element?: HTMLElement): void;
288
- loadSnippets(snippetFile: string, snippetOpen?: boolean): void;
288
+ // loadSnippets(snippetFile: string, snippetOpen?: boolean): void;
289
+
290
+ loadSnippets(path: string, snippetOpen?: boolean): Promise<void>;
291
+ loadSnippets(source: { snippets: string; style?: string }, snippetOpen?: boolean): Promise<void>;
292
+
289
293
  viewSnippets(): void;
290
294
  saveImages(handler?: string, onComplete?: () => void, onBase64Upload?: () => void): void;
291
295
  applyBehavior(): void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@innovastudio/contentbuilder",
3
3
  "type": "module",
4
- "version": "1.5.133",
4
+ "version": "1.5.135",
5
5
  "description": "",
6
6
  "main": "public/contentbuilder/contentbuilder.esm.js",
7
7
  "types": "index.d.ts",
@@ -96745,6 +96745,8 @@ Add an image for each feature.`, 'Create a new content showcasing a photo galler
96745
96745
  destroy() {
96746
96746
  const snippetData = document.querySelector('#_snippet_data');
96747
96747
  if (snippetData) snippetData.remove();
96748
+ const linkStyle = document.head.querySelector('#_snippet_style');
96749
+ if (linkStyle) linkStyle.remove();
96748
96750
  if (this.eb) this.eb.destroy();
96749
96751
  this.doc.body.classList.remove('data-editor');
96750
96752
  document.removeEventListener('click', this.doDocumentClick, false);
@@ -97829,7 +97831,7 @@ Add an image for each feature.`, 'Create a new content showcasing a photo galler
97829
97831
  viewZoom() {
97830
97832
  this.rte.viewZoom();
97831
97833
  }
97832
- loadSnippets(snippetFile, snippetOpen) {
97834
+ async loadSnippets(source, snippetOpen) {
97833
97835
  if (this.preview) return;
97834
97836
  if (this.opts.snippetList === '#divSnippetList') {
97835
97837
  let snippetPanel = document.querySelector(this.opts.snippetList);
@@ -97839,31 +97841,78 @@ Add an image for each feature.`, 'Create a new content showcasing a photo galler
97839
97841
  }
97840
97842
  }
97841
97843
 
97842
- if (this.isScriptAlreadyIncluded(snippetFile)) return;
97843
- const script = document.createElement('script');
97844
- script.src = snippetFile;
97845
- script.id = '_snippet_data';
97846
- script.async = true;
97847
- script.onload = () => {
97848
- if (!document.body.contains(this.builderStuff)) return; // in case the instance is destroyed
97844
+ let snippetFile;
97845
+ if (typeof source === 'string') {
97846
+ snippetFile = source;
97847
+ } else {
97848
+ snippetFile = source.snippets;
97849
+ let linkStyle = document.head.querySelector('#_snippet_style');
97850
+ if (linkStyle) linkStyle.remove();
97851
+ const link = document.createElement('link');
97852
+ link.id = '_snippet_style';
97853
+ link.rel = 'stylesheet';
97854
+ // link.href = source.style;
97855
+ link.href = source.style || source.snippets.replace(/\.js$/, '.css');
97849
97856
 
97850
- this.opts.snippetJSON = window.data_basic;
97851
- if (!this.canvas) for (let i = this.opts.snippetJSON.snippets.length - 1; i >= 0; i--) {
97852
- if (this.opts.snippetJSON.snippets[i].mode === 'canvas') {
97853
- this.opts.snippetJSON.snippets.splice(i, 1);
97857
+ // Find the last stylesheet <link> in <head>
97858
+ const lastCss = [...document.head.querySelectorAll('link[rel="stylesheet"]')].pop();
97859
+ if (lastCss) {
97860
+ lastCss.after(link);
97861
+ } else {
97862
+ // No linked CSS → look for first embedded <style>
97863
+ const firstStyle = document.head.querySelector('style');
97864
+ if (firstStyle) {
97865
+ document.head.insertBefore(link, firstStyle);
97866
+ } else {
97867
+ document.head.appendChild(link);
97854
97868
  }
97855
97869
  }
97856
97870
 
97857
- // if snippetPath is specified (not empty), then use the specified. Otherwise, use the one generated from snippet file (_snippets_path)
97858
- if (this.opts.snippetPath === '') {
97859
- this.opts.snippetPath = window._snippets_path;
97860
- }
97861
- if (this.opts.snippetJSON.snippets.length > 0) {
97862
- renderSnippetPanel(this, snippetOpen); // Render Snippet Panel
97863
- }
97864
- };
97871
+ // Then wait for it to load
97872
+ await new Promise((resolve, reject) => {
97873
+ link.onload = resolve;
97874
+ link.onerror = reject;
97875
+ });
97876
+ }
97877
+ let includeScript = document.body.querySelector('#_snippet_data');
97878
+ if (!includeScript) {
97879
+ const script = document.createElement('script');
97880
+ script.src = snippetFile;
97881
+ script.id = '_snippet_data';
97882
+ script.async = true;
97883
+ script.onload = () => {
97884
+ if (!document.body.contains(this.builderStuff)) return; // in case the instance is destroyed
97885
+
97886
+ this.opts.snippetJSON = window.data_basic;
97887
+ if (!this.canvas) for (let i = this.opts.snippetJSON.snippets.length - 1; i >= 0; i--) {
97888
+ if (this.opts.snippetJSON.snippets[i].mode === 'canvas') {
97889
+ this.opts.snippetJSON.snippets.splice(i, 1);
97890
+ }
97891
+ }
97892
+
97893
+ // if snippetPath is specified (not empty), then use the specified. Otherwise, use the one generated from snippet file (_snippets_path)
97894
+ if (this.opts.snippetPath === '') {
97895
+ this.opts.snippetPath = window._snippets_path;
97896
+ }
97897
+ if (this.opts.snippetJSON.snippets.length > 0) {
97898
+ renderSnippetPanel(this, snippetOpen); // Render Snippet Panel
97899
+ }
97865
97900
 
97866
- document.body.appendChild(script);
97901
+ if (this.opts.snippetJSON.target === 'ContentBuilder') {
97902
+ console.log(`
97903
+ ContentBuilder is a commercial library.
97904
+ Please obtain a license at: https://innovastudio.com/contentbuilder
97905
+ `);
97906
+ }
97907
+ if (this.opts.snippetJSON.target === 'ContentBox') {
97908
+ console.log(`
97909
+ ContentBox is a commercial library.
97910
+ Please obtain a license at: https://innovastudio.com/contentbox
97911
+ `);
97912
+ }
97913
+ };
97914
+ document.body.appendChild(script);
97915
+ }
97867
97916
  }
97868
97917
  isScriptAlreadyIncluded(src) {
97869
97918
  const scripts = document.getElementsByTagName('script');