@capacms/sdk 1.0.0-next.0 → 1.0.0-next.10

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.
Files changed (92) hide show
  1. package/CHANGELOG.md +450 -0
  2. package/README.md +1754 -156
  3. package/bin/capa-codegen.js +192 -5
  4. package/bin/capa.js +235 -0
  5. package/bin/graphql-project.js +142 -0
  6. package/bin/project-env.js +58 -0
  7. package/dist/client.d.ts +5 -0
  8. package/dist/client.js +17 -0
  9. package/dist/codegen.d.ts +55 -0
  10. package/dist/codegen.js +320 -39
  11. package/dist/config.d.ts +5 -36
  12. package/dist/config.js +47 -1
  13. package/dist/esm/image/index.d.ts +120 -0
  14. package/dist/esm/image/index.js +250 -0
  15. package/dist/esm/image/shared-params.generated.d.ts +190 -0
  16. package/dist/esm/image/shared-params.generated.js +461 -0
  17. package/dist/esm/nextjs/image-loader.d.ts +60 -0
  18. package/dist/esm/nextjs/image-loader.js +67 -0
  19. package/dist/esm/nextjs/overlay.d.ts +30 -0
  20. package/dist/esm/nextjs/overlay.js +75 -0
  21. package/dist/esm/overlay/index.d.ts +32 -0
  22. package/dist/esm/overlay/index.js +576 -0
  23. package/dist/esm/overlay/protocol.d.ts +187 -0
  24. package/dist/esm/overlay/protocol.js +240 -0
  25. package/dist/esm/package.json +4 -0
  26. package/dist/graphql-codegen.d.ts +117 -0
  27. package/dist/graphql-codegen.js +705 -0
  28. package/dist/http.js +1 -1
  29. package/dist/image/index.d.ts +120 -0
  30. package/dist/image/index.js +257 -0
  31. package/dist/image/shared-params.generated.d.ts +190 -0
  32. package/dist/image/shared-params.generated.js +471 -0
  33. package/dist/index.d.ts +2 -2
  34. package/dist/index.js +2 -1
  35. package/dist/next/attrs.d.ts +98 -0
  36. package/dist/next/attrs.js +125 -0
  37. package/dist/next/client.d.ts +176 -32
  38. package/dist/next/client.js +212 -90
  39. package/dist/next/entry-fields.d.ts +162 -0
  40. package/dist/next/entry-fields.js +2 -0
  41. package/dist/next/errors.d.ts +136 -0
  42. package/dist/next/errors.js +214 -0
  43. package/dist/next/field-names.d.ts +37 -0
  44. package/dist/next/field-names.js +145 -0
  45. package/dist/next/graphql/build.d.ts +27 -0
  46. package/dist/next/graphql/build.js +98 -0
  47. package/dist/next/graphql/documents.d.ts +67 -0
  48. package/dist/next/graphql/documents.js +35 -0
  49. package/dist/next/graphql/edit-mode.d.ts +16 -0
  50. package/dist/next/graphql/edit-mode.js +93 -0
  51. package/dist/next/graphql/filter-values.d.ts +34 -0
  52. package/dist/next/graphql/filter-values.js +96 -0
  53. package/dist/next/graphql/introspection.d.ts +89 -0
  54. package/dist/next/graphql/introspection.js +102 -0
  55. package/dist/next/graphql/plan.d.ts +115 -0
  56. package/dist/next/graphql/plan.js +531 -0
  57. package/dist/next/graphql/request.d.ts +228 -0
  58. package/dist/next/graphql/request.js +283 -0
  59. package/dist/next/graphql/rest.d.ts +66 -0
  60. package/dist/next/graphql/rest.js +502 -0
  61. package/dist/next/graphql/selection.d.ts +55 -0
  62. package/dist/next/graphql/selection.js +212 -0
  63. package/dist/next/graphql/sha256.d.ts +13 -0
  64. package/dist/next/graphql/sha256.js +86 -0
  65. package/dist/next/graphql/summary.d.ts +83 -0
  66. package/dist/next/graphql/summary.js +151 -0
  67. package/dist/next/graphql/tree-layout.d.ts +36 -0
  68. package/dist/next/graphql/tree-layout.js +20 -0
  69. package/dist/next/graphql/tree.d.ts +171 -0
  70. package/dist/next/graphql/tree.js +249 -0
  71. package/dist/next/graphql/typed.d.ts +261 -0
  72. package/dist/next/graphql/typed.js +146 -0
  73. package/dist/next/index.d.ts +30 -3
  74. package/dist/next/index.js +34 -1
  75. package/dist/next/inflate.d.ts +51 -0
  76. package/dist/next/inflate.js +243 -0
  77. package/dist/next/key-family.d.ts +31 -0
  78. package/dist/next/key-family.js +66 -0
  79. package/dist/next/select-types.d.ts +58 -5
  80. package/dist/next/system-keys.d.ts +27 -0
  81. package/dist/next/system-keys.js +42 -0
  82. package/dist/nextjs/image-loader.d.ts +60 -0
  83. package/dist/nextjs/image-loader.js +71 -0
  84. package/dist/nextjs/index.d.ts +484 -5
  85. package/dist/nextjs/index.js +704 -9
  86. package/dist/nextjs/overlay.d.ts +30 -0
  87. package/dist/nextjs/overlay.js +78 -0
  88. package/dist/overlay/index.d.ts +32 -0
  89. package/dist/overlay/index.js +596 -0
  90. package/dist/overlay/protocol.d.ts +187 -0
  91. package/dist/overlay/protocol.js +253 -0
  92. package/package.json +70 -15
@@ -0,0 +1,30 @@
1
+ export interface CapaOverlayProps {
2
+ /** The Capa admin origins allowed to drive the overlay. */
3
+ adminOrigins: string[];
4
+ /**
5
+ * How a save shows. `"in-place"` (the default) re-renders the draft with
6
+ * `router.refresh()`, and reloads the page only if that has not landed
7
+ * within `refreshTimeoutMs`. `"reload"` reloads the page on every save.
8
+ * The scroll position is kept either way.
9
+ */
10
+ refresh?: "in-place" | "reload";
11
+ /** How long an in-place refresh may take before the page reloads instead. 10 seconds. */
12
+ refreshTimeoutMs?: number;
13
+ }
14
+ /**
15
+ * The refresh runs in a transition, so `isPending` says when the new draft
16
+ * has been committed to the screen, and the overlay settles the refresh
17
+ * then: it puts the scroll position back, and a refresh that has not
18
+ * committed within `refreshTimeoutMs` reloads.
19
+ *
20
+ * While the transition is pending the overlay makes a no-op state update
21
+ * every `REFRESH_NUDGE_MS`. React 19.2 under Next 15.5 can leave a draft
22
+ * refresh suspended after every part of its streamed response has arrived:
23
+ * the page suspends inside an already visible Suspense boundary (a root
24
+ * `loading.tsx` makes one around every page), and the signal that its data
25
+ * is ready is lost, so nothing commits until some other state update. Any
26
+ * state update makes React retry the suspended render, which then completes.
27
+ * A refresh that commits on its own stops the nudges at once. Draft mode
28
+ * only: a visitor never runs this component.
29
+ */
30
+ export declare function CapaOverlay({ adminOrigins, refresh, refreshTimeoutMs }: CapaOverlayProps): null;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ "use client";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.CapaOverlay = CapaOverlay;
5
+ /**
6
+ * `<CapaOverlay />`: Capa's live preview overlay as one Next.js client
7
+ * component (M6).
8
+ *
9
+ * // app/layout.tsx (a server component)
10
+ * import { CapaOverlay } from "@capacms/sdk/nextjs/overlay";
11
+ * {edit ? <CapaOverlay adminOrigins={["https://app.capacms.com"]} /> : null}
12
+ *
13
+ * Render it only in edit mode (`editMode()` from `@capacms/sdk/nextjs`), so a
14
+ * visitor never downloads it. Inside the Capa editor it outlines the focused
15
+ * field, reports clicks back, and on a save re-renders the page with
16
+ * `router.refresh()`, keeping the scroll position. Outside a Capa frame it does
17
+ * nothing at all.
18
+ *
19
+ * Its own entry point, apart from `@capacms/sdk/nextjs`, because it imports
20
+ * `react` and `next/navigation` and is a client module: the server helpers must
21
+ * stay free of both. A bundler that imports it gets an ES module, so it sees
22
+ * that only `useRouter` is used from `next/navigation` and leaves the chunks a
23
+ * visitor loads as they were.
24
+ */
25
+ const react_1 = require("react");
26
+ const navigation_1 = require("next/navigation");
27
+ const index_js_1 = require("../overlay/index.js");
28
+ /**
29
+ * While a refresh is pending, the overlay updates its own unused state this
30
+ * often. See `CapaOverlay` for why.
31
+ */
32
+ const REFRESH_NUDGE_MS = 300;
33
+ /**
34
+ * The refresh runs in a transition, so `isPending` says when the new draft
35
+ * has been committed to the screen, and the overlay settles the refresh
36
+ * then: it puts the scroll position back, and a refresh that has not
37
+ * committed within `refreshTimeoutMs` reloads.
38
+ *
39
+ * While the transition is pending the overlay makes a no-op state update
40
+ * every `REFRESH_NUDGE_MS`. React 19.2 under Next 15.5 can leave a draft
41
+ * refresh suspended after every part of its streamed response has arrived:
42
+ * the page suspends inside an already visible Suspense boundary (a root
43
+ * `loading.tsx` makes one around every page), and the signal that its data
44
+ * is ready is lost, so nothing commits until some other state update. Any
45
+ * state update makes React retry the suspended render, which then completes.
46
+ * A refresh that commits on its own stops the nudges at once. Draft mode
47
+ * only: a visitor never runs this component.
48
+ */
49
+ function CapaOverlay({ adminOrigins, refresh = "in-place", refreshTimeoutMs }) {
50
+ const router = (0, navigation_1.useRouter)();
51
+ const [refreshing, startRefresh] = (0, react_1.useTransition)();
52
+ const [, nudge] = (0, react_1.useState)(0);
53
+ /** One resolver per refresh waiting for its transition to commit. */
54
+ const waiting = (0, react_1.useRef)([]);
55
+ // A string, so a new array with the same origins does not restart it.
56
+ const origins = adminOrigins.join(",");
57
+ (0, react_1.useEffect)(() => (0, index_js_1.startOverlay)({
58
+ adminOrigins: origins.split(",").filter(Boolean),
59
+ onRefresh: refresh === "reload"
60
+ ? undefined
61
+ : () => new Promise((resolve) => {
62
+ waiting.current.push(resolve);
63
+ startRefresh(() => router.refresh());
64
+ }),
65
+ refreshTimeoutMs,
66
+ }), [origins, router, refresh, refreshTimeoutMs]);
67
+ (0, react_1.useEffect)(() => {
68
+ if (!refreshing) {
69
+ // Committed: every refresh started before now is on screen.
70
+ for (const settle of waiting.current.splice(0))
71
+ settle();
72
+ return;
73
+ }
74
+ const timer = window.setInterval(() => nudge((n) => n + 1), REFRESH_NUDGE_MS);
75
+ return () => window.clearInterval(timer);
76
+ }, [refreshing]);
77
+ return null;
78
+ }
@@ -0,0 +1,32 @@
1
+ export { acceptMessage, hoverMessage, normaliseOrigins, patchedText, pickCentred, readyMessage, scrollEdge, selectMessage, textAround, visibleMessage, ADMIN_SOURCE, PATCH_MAX_FIELDS, PATCH_MAX_LENGTH, PROTOCOL_VERSION, SITE_FEATURES, SITE_SOURCE, } from "./protocol.js";
2
+ export type { AdminMessage, MessageLike, PatchField, SiteMessage, TaggedBox } from "./protocol.js";
3
+ export interface OverlayOptions {
4
+ /**
5
+ * The Capa admin origins allowed to drive this page, for example
6
+ * `["https://app.capacms.com"]`. A message from anywhere else is ignored.
7
+ */
8
+ adminOrigins: string[];
9
+ /**
10
+ * How to re-render the draft after the editor saves. `router.refresh()` in a
11
+ * Next app. Without it the page reloads. Scroll position is kept either way.
12
+ *
13
+ * Return a promise that settles once the new draft is on screen, and the
14
+ * overlay waits for it: a promise that rejects, or is still pending after
15
+ * `refreshTimeoutMs`, falls back to a reload, which keeps the scroll
16
+ * position too. A function that returns nothing counts as done at once.
17
+ */
18
+ onRefresh?: () => void | Promise<void>;
19
+ /**
20
+ * How long `onRefresh`'s promise may stay pending before the page reloads
21
+ * instead. 10 seconds.
22
+ */
23
+ refreshTimeoutMs?: number;
24
+ }
25
+ /** How long an in-place refresh may take before the page reloads instead. */
26
+ export declare const REFRESH_TIMEOUT_MS = 10000;
27
+ /**
28
+ * Start the overlay. Returns a disposer that removes every listener and the
29
+ * drawing layer. Calling it again while it runs updates the options and returns
30
+ * the same disposer, so a React effect that runs twice does not listen twice.
31
+ */
32
+ export declare function startOverlay(options: OverlayOptions): () => void;