@contentstorage/core 0.3.34 → 0.3.36
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/dist/helpers/setKeyToHtmlTag.d.ts +1 -0
- package/dist/helpers/setKeyToHtmlTag.js +19 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/lib/contentManagement.d.ts +2 -2
- package/dist/lib/contentManagement.js +5 -0
- package/dist/lib/functions/fetchContent.js +0 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const setKeyToHtmlTag: (contentKey: string) => void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const htmlElem = document.documentElement;
|
|
2
|
+
export const setKeyToHtmlTag = (contentKey) => {
|
|
3
|
+
const currentKeys = htmlElem.getAttribute('data-contentstorage-keys');
|
|
4
|
+
let storedKeys = [];
|
|
5
|
+
try {
|
|
6
|
+
storedKeys = JSON.parse(currentKeys || '');
|
|
7
|
+
if (!Array.isArray(storedKeys)) {
|
|
8
|
+
storedKeys = [];
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
console.error('Could not parse data-contentstorage-keys:', e);
|
|
13
|
+
storedKeys = [];
|
|
14
|
+
}
|
|
15
|
+
if (!storedKeys.includes(contentKey)) {
|
|
16
|
+
storedKeys.push(contentKey);
|
|
17
|
+
}
|
|
18
|
+
htmlElem.setAttribute('data-contentstorage-keys', JSON.stringify(storedKeys));
|
|
19
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -3,3 +3,4 @@ import { setContentLanguage, getText, getImage, getVariation, initContentStorage
|
|
|
3
3
|
import { fetchContent } from './lib/functions/fetchContent.js';
|
|
4
4
|
export { AppConfig, LanguageCode, ContentStructure };
|
|
5
5
|
export { initContentStorage, fetchContent, setContentLanguage, getText, getImage, getVariation, };
|
|
6
|
+
export declare let isInContentstorageIframe: boolean;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { setContentLanguage, getText, getImage, getVariation, initContentStorage, } from './lib/contentManagement.js';
|
|
2
2
|
import { fetchContent } from './lib/functions/fetchContent.js';
|
|
3
3
|
export { initContentStorage, fetchContent, setContentLanguage, getText, getImage, getVariation, };
|
|
4
|
+
export let isInContentstorageIframe = false;
|
|
4
5
|
async function isLiveEditorMode() {
|
|
5
6
|
try {
|
|
6
7
|
const inIframe = window.self !== window.top;
|
|
@@ -20,6 +21,7 @@ isLiveEditorMode().then(async (isLiveMode) => {
|
|
|
20
21
|
if (!isLiveMode) {
|
|
21
22
|
return;
|
|
22
23
|
}
|
|
24
|
+
isInContentstorageIframe = true;
|
|
23
25
|
const cdnScriptUrl = `https://your-cdn-domain.com/contentstorage-live-editor.js?contentstorage-live-editor=true`;
|
|
24
26
|
return new Promise((resolve, reject) => {
|
|
25
27
|
console.log(`Attempting to load script from: ${cdnScriptUrl}`);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { AppConfig, ContentStructure, GetImageReturn, GetTextReturn, GetVariationReturn } from '../types.js';
|
|
2
2
|
export declare let activeContent: object | null;
|
|
3
|
-
export declare let appConfig: AppConfig | null;
|
|
3
|
+
export declare let appConfig: Pick<AppConfig, 'contentKey' | 'languageCodes'> | null;
|
|
4
4
|
/**
|
|
5
5
|
* Loads and sets the content for a specific language.
|
|
6
6
|
* It will internally ensure the application configuration (for contentDir) is loaded.
|
|
7
7
|
* @param contentJson
|
|
8
8
|
*/
|
|
9
9
|
export declare function setContentLanguage(contentJson: object): void;
|
|
10
|
-
export declare function initContentStorage(config: AppConfig): void;
|
|
10
|
+
export declare function initContentStorage(config: Pick<AppConfig, 'contentKey' | 'languageCodes'>): void;
|
|
11
11
|
/**
|
|
12
12
|
* Retrieves the text string from the loaded JSON content for the given path.
|
|
13
13
|
* Autocompletion for pathString is enabled via module augmentation of CustomContentStructure.
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { populateTextWithVariables } from '../helpers/populateTextWithVariables.js';
|
|
2
|
+
import { isInContentstorageIframe } from '../index.js';
|
|
3
|
+
import { setKeyToHtmlTag } from '../helpers/setKeyToHtmlTag.js';
|
|
2
4
|
export let activeContent = null;
|
|
3
5
|
export let appConfig = null;
|
|
4
6
|
/**
|
|
@@ -68,6 +70,9 @@ export function getText(contentKey, variables) {
|
|
|
68
70
|
}
|
|
69
71
|
if (typeof current === 'string') {
|
|
70
72
|
if (!variables || Object.keys(variables).length === 0) {
|
|
73
|
+
if (isInContentstorageIframe) {
|
|
74
|
+
setKeyToHtmlTag(contentKey);
|
|
75
|
+
}
|
|
71
76
|
return {
|
|
72
77
|
contentKey,
|
|
73
78
|
text: current,
|
|
@@ -15,7 +15,6 @@ export async function fetchContent(language) {
|
|
|
15
15
|
// Fetch data for the current language
|
|
16
16
|
const response = await axios.get(fileUrl);
|
|
17
17
|
const jsonData = response.data;
|
|
18
|
-
// Basic check for data existence, although axios usually throws for non-2xx responses
|
|
19
18
|
if (jsonData === undefined || jsonData === null) {
|
|
20
19
|
throw new Error(`No data received from ${fileUrl} for language ${languageToFetch}.`);
|
|
21
20
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@contentstorage/core",
|
|
3
3
|
"author": "Kaido Hussar <kaidohus@gmail.com>",
|
|
4
4
|
"homepage": "https://contentstorage.app",
|
|
5
|
-
"version": "0.3.
|
|
5
|
+
"version": "0.3.36",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"description": "Fetch content from contentstorage and generate TypeScript types",
|
|
8
8
|
"module": "dist/index.js",
|