@contentstorage/core 0.3.35 → 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.
@@ -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,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,
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.35",
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",