@contentstack/studio-client 1.5.1 → 1.7.0

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.
@@ -1,47 +1,87 @@
1
- import { JSONRTERegistry } from '@contentstack/studio-registry';
2
-
3
- const jsonRTERegistryInstance = /* #__PURE__ */ new JSONRTERegistry();
1
+ let _rteConfig = {};
4
2
  /**
5
- * Registers a config for JSON RTE
6
- * @param config - The config to register. This should have the following format:
7
- * {
8
- * customElementTypes: {
9
- * [elementName]: {
10
- * parse: (node: any) => any,
11
- * render: (node: any) => any,
12
- * },
13
- * },
14
- * }
15
- * For more details, check the docs here: https://github.com/contentstack/json-rte-serializer/blob/main/README.md#custom-element-types
16
- * @throws If the config is not provided
17
- * @example
18
- * registerJSONRTE({
3
+ * Unified RTE registration. Covers both embedded entry rendering and custom
4
+ * JSON RTE node types in a single call. Replaces the full config on each call.
5
+ *
6
+ * @example — embedded entries only
7
+ * registerRTERenderer({
8
+ * embeddedEntry: ({ entry, contentTypeUid, displayType }) => {
9
+ * if (displayType === "block") return `<div><h3>${entry.full_name ?? entry.title}</h3></div>`;
10
+ * if (displayType === "link") return `<a href="${entry.url}">${entry.title}</a>`;
11
+ * return `<span>${entry.title}</span>`;
12
+ * },
13
+ * });
14
+ *
15
+ * @example — JSON RTE custom node types only
16
+ * registerRTERenderer({
17
+ * customElementTypes: {
18
+ * "code-block": (attrs, child) => `<pre><code>${child}</code></pre>`,
19
+ * "my-table": (attrs, child) => `<table>${child}</table>`,
20
+ * },
21
+ * allowNonStandardTypes: true,
22
+ * });
23
+ *
24
+ * @example — both together
25
+ * registerRTERenderer({
26
+ * embeddedEntry: ({ entry, contentTypeUid, displayType }) => {
27
+ * const label = entry.full_name ?? entry.title ?? entry.uid;
28
+ * if (displayType === "block") return `<div><h1>${label}</h1><p>${entry.short_bio ?? ""}</p></div>`;
29
+ * if (displayType === "link") return `<a href="${entry.url ?? "#"}">${label}</a>`;
30
+ * return `<span>${label}</span>`;
31
+ * },
19
32
  * customElementTypes: {
20
- * myComponent: {
21
- * parse: (node) => node,
22
- * render: (node) => (
23
- * <div>
24
- * <h3>My Component</h3>
25
- * <p>{node.children[0].text}</p>
26
- * </div>
27
- * ),
28
- * },
33
+ * "code-block": (attrs, child) => `<pre><code>${child}</code></pre>`,
29
34
  * },
30
35
  * });
31
36
  */
37
+ function registerRTERenderer(config) {
38
+ if (!config)
39
+ throw new Error("Please provide a config to configure RTE");
40
+ _rteConfig = { ...config };
41
+ }
42
+ // ─── Backwards-compat aliases (one-version deprecation window) ──────────────
43
+ /**
44
+ * @deprecated Use `registerRTERenderer` instead. Preserves any previously
45
+ * registered `embeddedEntry` / `embeddedAsset` renderers; only replaces the
46
+ * JSON RTE serializer options.
47
+ */
32
48
  function registerJSONRTE(config) {
33
- if (!config) {
49
+ if (!config)
34
50
  throw new Error("Please provide a config to configure JSON RTE");
35
- }
36
- jsonRTERegistryInstance.registerJSONRTE(config);
51
+ const { embeddedEntry, embeddedAsset } = _rteConfig;
52
+ _rteConfig = { ...config, embeddedEntry, embeddedAsset };
37
53
  }
38
54
  /**
39
- * Gets the current config for JSON RTE
40
- * @returns The current config for JSON RTE
55
+ * @deprecated Use `registerRTERenderer` instead. Registers embedded entry
56
+ * renderer only — does not clear existing `customElementTypes` or `embeddedAsset`.
57
+ */
58
+ function registerEmbeddedEntryRenderer(render) {
59
+ _rteConfig = { ..._rteConfig, embeddedEntry: render };
60
+ }
61
+ // ─── Internal readers (used by hooks / components) ───────────────────────────
62
+ /**
63
+ * Returns the current JSON RTE serializer options (without embeddedEntry / embeddedAsset).
64
+ * Used internally by the RichText / CollapsibleText hooks.
41
65
  */
42
66
  function getJSONRTE() {
43
- return jsonRTERegistryInstance.getJSONRTE();
67
+ const { embeddedEntry: _e, embeddedAsset: _a, ...rest } = _rteConfig;
68
+ return rest;
69
+ }
70
+ /**
71
+ * Returns the registered embedded entry renderer, or null if none registered.
72
+ * Used internally by the RichText / CollapsibleText hooks.
73
+ */
74
+ function getEmbeddedEntryRenderer() {
75
+ return _rteConfig.embeddedEntry ?? null;
76
+ }
77
+ /**
78
+ * Returns the registered embedded asset renderer, or null if none registered.
79
+ * Used internally by the RichText / CollapsibleText hooks. When null, the
80
+ * hook falls back to `defaultAssetRender` so canvas never shows blank assets.
81
+ */
82
+ function getEmbeddedAssetRenderer() {
83
+ return _rteConfig.embeddedAsset ?? null;
44
84
  }
45
85
 
46
- export { getJSONRTE, registerJSONRTE };
86
+ export { getEmbeddedAssetRenderer, getEmbeddedEntryRenderer, getJSONRTE, registerEmbeddedEntryRenderer, registerJSONRTE, registerRTERenderer };
47
87
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/json-rte-registry/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAGA,MAAM,uBAAuB,mBAAmB,IAAI,eAAe,EAAE;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BG;AACG,SAAU,eAAe,CAAC,MAA0B,EAAA;IACxD,IAAI,CAAC,MAAM,EAAE;AACX,QAAA,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC;IAClE;AACA,IAAA,uBAAuB,CAAC,eAAe,CAAC,MAAM,CAAC;AACjD;AAEA;;;AAGG;SACa,UAAU,GAAA;AACxB,IAAA,OAAO,uBAAuB,CAAC,UAAU,EAAE;AAC7C;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/json-rte-registry/index.ts"],"sourcesContent":[null],"names":[],"mappings":"AAoDA,IAAI,UAAU,GAAc,EAAE;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCG;AACG,SAAU,mBAAmB,CAAC,MAAiB,EAAA;AACnD,IAAA,IAAI,CAAC,MAAM;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC;AACxE,IAAA,UAAU,GAAG,EAAE,GAAG,MAAM,EAAE;AAC5B;AAEA;AAEA;;;;AAIG;AACG,SAAU,eAAe,CAAC,MAA0B,EAAA;AACxD,IAAA,IAAI,CAAC,MAAM;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC;AAC7E,IAAA,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,GAAG,UAAU;IACnD,UAAU,GAAG,EAAE,GAAG,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE;AAC1D;AAEA;;;AAGG;AACG,SAAU,6BAA6B,CAC3C,MAAiD,EAAA;IAEjD,UAAU,GAAG,EAAE,GAAG,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE;AACvD;AAEA;AAEA;;;AAGG;SACa,UAAU,GAAA;AACxB,IAAA,MAAM,EAAE,aAAa,EAAE,EAAE,EAAE,aAAa,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,UAAU;AACpE,IAAA,OAAO,IAAI;AACb;AAEA;;;AAGG;SACa,wBAAwB,GAAA;AAGtC,IAAA,OAAO,UAAU,CAAC,aAAa,IAAI,IAAI;AACzC;AAEA;;;;AAIG;SACa,wBAAwB,GAAA;AAGtC,IAAA,OAAO,UAAU,CAAC,aAAa,IAAI,IAAI;AACzC;;;;"}
@@ -0,0 +1,10 @@
1
+ let _instance = null;
2
+ function setStackSdkInstance(sdk) {
3
+ _instance = sdk;
4
+ }
5
+ function getStackSdkInstance() {
6
+ return _instance;
7
+ }
8
+
9
+ export { getStackSdkInstance, setStackSdkInstance };
10
+ //# sourceMappingURL=stack-sdk-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stack-sdk-store.js","sources":["../../src/json-rte-registry/stack-sdk-store.ts"],"sourcesContent":[null],"names":[],"mappings":"AAEA,IAAI,SAAS,GAAoB,IAAI;AAE/B,SAAU,mBAAmB,CAAC,GAAa,EAAA;IAC/C,SAAS,GAAG,GAAG;AACjB;SAEgB,mBAAmB,GAAA;AACjC,IAAA,OAAO,SAAS;AAClB;;;;"}
@@ -151,7 +151,7 @@ var ec = [
151
151
  'invalid distance',
152
152
  'stream finished',
153
153
  'no stream handler',
154
- ,
154
+ , // determined by compression function
155
155
  'no callback',
156
156
  'invalid UTF-8 data',
157
157
  'extra field too long',
@@ -361,12 +361,6 @@ var zls = function (d, dict) {
361
361
  err(6, 'invalid zlib data: ' + (d[1] & 32 ? 'need' : 'unexpected') + ' dictionary');
362
362
  return (d[1] >> 3 & 4) + 2;
363
363
  };
364
- /**
365
- * Expands Zlib data
366
- * @param data The data to decompress
367
- * @param opts The decompression options
368
- * @returns The decompressed version of the data
369
- */
370
364
  function unzlibSync(data, opts) {
371
365
  return inflt(data.subarray(zls(data), -4), { i: 2 }, opts, opts);
372
366
  }