@alpaca-headless/dynamic-renderings 1.0.4696 → 1.0.4697

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/README.md CHANGED
@@ -100,9 +100,11 @@ Whether the browser also loads the real component is decided per page:
100
100
 
101
101
  | Page | Client code |
102
102
  | --- | --- |
103
- | edit mode | never: the first paint only |
104
103
  | a sealed request (`requestAuth` recognised it) | every island loads, inside an opaque-origin frame only |
105
- | anything else | islands of renderings the CM reports as `approved` |
104
+ | anything else, edit mode included | islands of renderings the CM reports as `approved` |
105
+
106
+ A loaded component always gets `editing: false`, in the edit canvas too; the first paint renders
107
+ with `editing: true`.
106
108
 
107
109
  A bundle URL is `{prefix}/api/alpaca/renderings/client/{clientHash}-{compiledFormat}.js?id={renderingId}&database={db}`
108
110
  (plus `&page={pageId}` when sealed), where `clientHash` is the first 16 hex digits of the SHA-256
@@ -3,9 +3,11 @@ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
3
3
  // A component of a rendering's client code. It always shows the first paint the engine rendered
4
4
  // (static, sanitized) and replaces it with the real component once the browser bundle loaded.
5
5
  // The server passes this only where client code may run: `approved` for a rendering an
6
- // administrator approved (never in the edit canvas), `sealed` for an editor's isolated preview.
6
+ // administrator approved (the edit canvas included), `sealed` for an editor's isolated preview.
7
7
  // A sealed island also checks that it really runs in an opaque-origin document, where its code
8
- // cannot reach the editor, a CM response or any cookie.
8
+ // cannot reach the editor, a CM response or any cookie. The loaded component always gets
9
+ // `editing: false` and runs as on the live page, in the edit canvas too; `editing: true` is the
10
+ // first paint's (a static render).
9
11
  import { Component, useEffect, useState } from "react";
10
12
  class IslandBoundary extends Component {
11
13
  state = { failed: false };
@@ -22,7 +22,10 @@ export declare function ErrorBox({ title, detail }: {
22
22
  * which holds a token, it must fit the CM's URL length limit; the query has its own.
23
23
  */
24
24
  export declare function clientBundleUrl(state: Pick<DynamicPageState, "prefix" | "database" | "sealed" | "pageId">, renderingId: string, clientHash: string): string;
25
- /** Where this rendering's client code may run on this page, if anywhere. */
25
+ /**
26
+ * Where this rendering's client code may run on this page, if anywhere: approved code everywhere,
27
+ * the edit canvas included (the approval is the review), and any code in the sealed preview.
28
+ */
26
29
  export declare function clientLoading(state: DynamicPageState, prepared: PreparedComponent, editing: boolean): ConvertContext["client"];
27
30
  /**
28
31
  * Returns the component the SDK's Placeholder mounts for every component whose layout JSON
@@ -33,11 +33,14 @@ export function clientBundleUrl(state, renderingId, clientHash) {
33
33
  query.set("page", state.pageId);
34
34
  return `${state.prefix}/api/alpaca/renderings/client/${clientHash}-${protocol.compiledFormat}.js?${query}`;
35
35
  }
36
- /** Where this rendering's client code may run on this page, if anywhere. */
36
+ /**
37
+ * Where this rendering's client code may run on this page, if anywhere: approved code everywhere,
38
+ * the edit canvas included (the approval is the review), and any code in the sealed preview.
39
+ */
37
40
  export function clientLoading(state, prepared, editing) {
38
- if (editing || state.clientMode === "edit" || !prepared.clientHash)
41
+ if (!prepared.clientHash)
39
42
  return undefined;
40
- if (state.clientMode === "sealed")
43
+ if (state.clientMode === "sealed" && !editing)
41
44
  return { mode: "sealed", src: clientBundleUrl(state, prepared.renderingId, prepared.clientHash) };
42
45
  return prepared.approved ? { mode: "approved", src: clientBundleUrl(state, prepared.renderingId, prepared.clientHash) } : undefined;
43
46
  }
@@ -39,10 +39,10 @@ export type PreparedTheme = {
39
39
  rejected?: string;
40
40
  };
41
41
  /**
42
- * Which client code loads in the browser: none in edit mode (first paints only), all of it in a
43
- * sealed request, and otherwise only that of approved renderings.
42
+ * Which client code loads in the browser: all of it in a sealed request (never in edit mode), and
43
+ * otherwise only that of approved renderings, the edit canvas included.
44
44
  */
45
- export type ClientMode = "edit" | "sealed" | "approved";
45
+ export type ClientMode = "sealed" | "approved";
46
46
  export type DynamicPageState = {
47
47
  nonce: string;
48
48
  mode: string;
@@ -16,7 +16,7 @@ export function emptyDynamicPage(mode, prefix = "", { sealed = false, pageId = "
16
16
  editing,
17
17
  preview: mode === "preview",
18
18
  sealed,
19
- clientMode: editing ? "edit" : sealed ? "sealed" : "approved",
19
+ clientMode: sealed && !editing ? "sealed" : "approved",
20
20
  components: new Map(),
21
21
  prefix,
22
22
  pageId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alpaca-headless/dynamic-renderings",
3
- "version": "1.0.4696",
3
+ "version": "1.0.4697",
4
4
  "description": "Optional Alpaca Headless dynamic renderings: source client, safe React rendering, client code and Next.js integration.",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -79,7 +79,7 @@
79
79
  "acceptance": "node scripts/acceptance.mjs"
80
80
  },
81
81
  "dependencies": {
82
- "@alpaca-headless/dynamic-renderings-engine": "1.0.4696",
82
+ "@alpaca-headless/dynamic-renderings-engine": "1.0.4697",
83
83
  "lucide-react": "^1.38.0",
84
84
  "postcss": "^8.5.26",
85
85
  "postcss-selector-parser": "^7.1.6",