@contentstorage/core 0.3.39 → 0.3.41

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,6 @@
1
+ import { AppConfig } from '../types.js';
2
+ /**
3
+ * Helper function to define your application configuration.
4
+ * Provides autocompletion and type-checking for contentstorage.config.js files.
5
+ */
6
+ export declare function defineConfig(config: AppConfig): AppConfig;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Helper function to define your application configuration.
3
+ * Provides autocompletion and type-checking for contentstorage.config.js files.
4
+ */
5
+ export function defineConfig(config) {
6
+ // You can add basic runtime validation here if desired,
7
+ // e.g., check if contentUrl is a valid URL format,
8
+ // or if languageCodes is not empty.
9
+ if (!config.languageCodes || config.languageCodes.length === 0) {
10
+ console.warn('Warning: languageCodes array is empty or missing in the configuration.');
11
+ }
12
+ if (!config.contentDir) {
13
+ // This would typically be a hard error, but defineConfig is more for type safety at edit time.
14
+ // Runtime validation (see point 3) is better for hard errors.
15
+ console.warn('Warning: contentDir is missing in the configuration.');
16
+ }
17
+ // ... other checks
18
+ return config;
19
+ }
@@ -1,6 +1,10 @@
1
1
  import { populateTextWithVariables } from '../helpers/populateTextWithVariables.js';
2
2
  export let activeContent = null;
3
3
  export let appConfig = null;
4
+ /**
5
+ * NB! Only used when live editor mode is on
6
+ */
7
+ window.memoryMap = new Map();
4
8
  /**
5
9
  * Loads and sets the content for a specific language.
6
10
  * It will internally ensure the application configuration (for contentDir) is loaded.
@@ -67,6 +71,15 @@ export function getText(contentKey, variables) {
67
71
  }
68
72
  }
69
73
  if (typeof current === 'string') {
74
+ if (window.parent && window.parent !== window) {
75
+ const key = current;
76
+ const existingEntry = window.memoryMap.get(key);
77
+ const idSet = existingEntry ? existingEntry.ids : new Set();
78
+ idSet.add(contentKey); // Add the current ID to the set.
79
+ window.memoryMap.set(key, {
80
+ ids: idSet,
81
+ });
82
+ }
70
83
  if (!variables || Object.keys(variables).length === 0) {
71
84
  return {
72
85
  contentKey,
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.39",
5
+ "version": "0.3.41",
6
6
  "type": "module",
7
7
  "description": "Fetch content from contentstorage and generate TypeScript types",
8
8
  "module": "dist/index.js",
@@ -1 +0,0 @@
1
- export declare const setKeyToHtmlTag: (contentKey: string) => void;
@@ -1,5 +0,0 @@
1
- const htmlElem = document.documentElement;
2
- export const setKeyToHtmlTag = (contentKey) => {
3
- const dataKey = `data-contentstorage-key-${contentKey}`;
4
- htmlElem.setAttribute(dataKey, 'true');
5
- };