@innovastudio/contentbuilder 1.5.133 → 1.5.134
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
@@ -97829,7 +97829,7 @@ Add an image for each feature.`, 'Create a new content showcasing a photo galler
|
|
97829
97829
|
viewZoom() {
|
97830
97830
|
this.rte.viewZoom();
|
97831
97831
|
}
|
97832
|
-
loadSnippets(
|
97832
|
+
async loadSnippets(source, snippetOpen) {
|
97833
97833
|
if (this.preview) return;
|
97834
97834
|
if (this.opts.snippetList === '#divSnippetList') {
|
97835
97835
|
let snippetPanel = document.querySelector(this.opts.snippetList);
|
@@ -97839,31 +97839,78 @@ Add an image for each feature.`, 'Create a new content showcasing a photo galler
|
|
97839
97839
|
}
|
97840
97840
|
}
|
97841
97841
|
|
97842
|
-
|
97843
|
-
|
97844
|
-
|
97845
|
-
|
97846
|
-
|
97847
|
-
|
97848
|
-
if (!
|
97849
|
-
|
97850
|
-
|
97851
|
-
|
97852
|
-
|
97853
|
-
|
97842
|
+
let snippetFile;
|
97843
|
+
if (typeof source === 'string') {
|
97844
|
+
snippetFile = source;
|
97845
|
+
} else {
|
97846
|
+
snippetFile = source.snippets;
|
97847
|
+
let linkStyle = document.head.querySelector('#_snippet_style');
|
97848
|
+
if (!linkStyle) {
|
97849
|
+
const link = document.createElement('link');
|
97850
|
+
link.id = '_snippet_style';
|
97851
|
+
link.rel = 'stylesheet';
|
97852
|
+
link.href = source.style;
|
97853
|
+
|
97854
|
+
// Find the last stylesheet <link> in <head>
|
97855
|
+
const lastCss = [...document.head.querySelectorAll('link[rel="stylesheet"]')].pop();
|
97856
|
+
if (lastCss) {
|
97857
|
+
lastCss.after(link);
|
97858
|
+
} else {
|
97859
|
+
// No linked CSS → look for first embedded <style>
|
97860
|
+
const firstStyle = document.head.querySelector('style');
|
97861
|
+
if (firstStyle) {
|
97862
|
+
document.head.insertBefore(link, firstStyle);
|
97863
|
+
} else {
|
97864
|
+
document.head.appendChild(link);
|
97865
|
+
}
|
97854
97866
|
}
|
97855
|
-
}
|
97856
97867
|
|
97857
|
-
|
97858
|
-
|
97859
|
-
|
97860
|
-
|
97861
|
-
|
97862
|
-
renderSnippetPanel(this, snippetOpen); // Render Snippet Panel
|
97868
|
+
// Then wait for it to load
|
97869
|
+
await new Promise((resolve, reject) => {
|
97870
|
+
link.onload = resolve;
|
97871
|
+
link.onerror = reject;
|
97872
|
+
});
|
97863
97873
|
}
|
97864
|
-
}
|
97874
|
+
}
|
97875
|
+
let includeScript = document.body.querySelector('#_snippet_data');
|
97876
|
+
if (!includeScript) {
|
97877
|
+
const script = document.createElement('script');
|
97878
|
+
script.src = snippetFile;
|
97879
|
+
script.id = '_snippet_data';
|
97880
|
+
script.async = true;
|
97881
|
+
script.onload = () => {
|
97882
|
+
if (!document.body.contains(this.builderStuff)) return; // in case the instance is destroyed
|
97883
|
+
|
97884
|
+
this.opts.snippetJSON = window.data_basic;
|
97885
|
+
if (!this.canvas) for (let i = this.opts.snippetJSON.snippets.length - 1; i >= 0; i--) {
|
97886
|
+
if (this.opts.snippetJSON.snippets[i].mode === 'canvas') {
|
97887
|
+
this.opts.snippetJSON.snippets.splice(i, 1);
|
97888
|
+
}
|
97889
|
+
}
|
97890
|
+
|
97891
|
+
// if snippetPath is specified (not empty), then use the specified. Otherwise, use the one generated from snippet file (_snippets_path)
|
97892
|
+
if (this.opts.snippetPath === '') {
|
97893
|
+
this.opts.snippetPath = window._snippets_path;
|
97894
|
+
}
|
97895
|
+
if (this.opts.snippetJSON.snippets.length > 0) {
|
97896
|
+
renderSnippetPanel(this, snippetOpen); // Render Snippet Panel
|
97897
|
+
}
|
97865
97898
|
|
97866
|
-
|
97899
|
+
if (this.opts.snippetJSON.target === 'ContentBuilder') {
|
97900
|
+
console.log(`
|
97901
|
+
ContentBuilder is a commercial library.
|
97902
|
+
Please obtain a license at: https://innovastudio.com/contentbuilder
|
97903
|
+
`);
|
97904
|
+
}
|
97905
|
+
if (this.opts.snippetJSON.target === 'ContentBox') {
|
97906
|
+
console.log(`
|
97907
|
+
ContentBox is a commercial library.
|
97908
|
+
Please obtain a license at: https://innovastudio.com/contentbox
|
97909
|
+
`);
|
97910
|
+
}
|
97911
|
+
};
|
97912
|
+
document.body.appendChild(script);
|
97913
|
+
}
|
97867
97914
|
}
|
97868
97915
|
isScriptAlreadyIncluded(src) {
|
97869
97916
|
const scripts = document.getElementsByTagName('script');
|