@plenary/react 0.2.0 → 0.2.2

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/dist/context.js DELETED
@@ -1,20 +0,0 @@
1
- "use client";
2
- import { jsx } from "react/jsx-runtime";
3
- import { createContext, useContext, useMemo } from "react";
4
- import { createClient } from "@plenary/client";
5
- const PlenaryClientContext = createContext(null);
6
- function PlenaryProvider({ client, config, children }) {
7
- const value = useMemo(
8
- () => client ?? (config ? createClient(config) : null),
9
- [client, config?.baseUrl, config?.siteKey, config?.apiKey, config?.locale, config?.fetch]
10
- );
11
- return /* @__PURE__ */ jsx(PlenaryClientContext.Provider, { value, children });
12
- }
13
- function usePlenaryClient() {
14
- return useContext(PlenaryClientContext);
15
- }
16
- export {
17
- PlenaryProvider,
18
- usePlenaryClient
19
- };
20
- //# sourceMappingURL=context.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/context.tsx"],"sourcesContent":["\"use client\";\n\nimport { createContext, useContext, useMemo, type ReactNode } from \"react\";\nimport { createClient, type ClientConfig, type PlenaryClient } from \"@plenary/client\";\n\nconst PlenaryClientContext = createContext<PlenaryClient | null>(null);\n\nexport interface PlenaryProviderProps {\n /** An already-created client (client-rendered apps). */\n client?: PlenaryClient;\n /**\n * Or the client config, from which the provider creates one. This is the\n * RSC-safe path: a client instance cannot cross a server/client component\n * boundary, but plain config can (the API key is a public delivery key, so\n * shipping it to the browser is by design).\n */\n config?: ClientConfig;\n children?: ReactNode;\n}\n\n/**\n * Provides a `PlenaryClient` to components that act at runtime in the browser —\n * today the built-in Form block, which submits through it. Rendering content\n * does not require the provider; only interactive blocks do.\n */\nexport function PlenaryProvider({ client, config, children }: PlenaryProviderProps) {\n // Keyed on config fields, not object identity — an inline config literal\n // must not rebuild the client (and re-render every consumer) each render.\n const value = useMemo(\n () => client ?? (config ? createClient(config) : null),\n [client, config?.baseUrl, config?.siteKey, config?.apiKey, config?.locale, config?.fetch],\n );\n return <PlenaryClientContext.Provider value={value}>{children}</PlenaryClientContext.Provider>;\n}\n\n/** The nearest provided client, or `null` outside a {@link PlenaryProvider}. */\nexport function usePlenaryClient(): PlenaryClient | null {\n return useContext(PlenaryClientContext);\n}\n"],"mappings":";AAgCS;AA9BT,SAAS,eAAe,YAAY,eAA+B;AACnE,SAAS,oBAA2D;AAEpE,MAAM,uBAAuB,cAAoC,IAAI;AAoB9D,SAAS,gBAAgB,EAAE,QAAQ,QAAQ,SAAS,GAAyB;AAGlF,QAAM,QAAQ;AAAA,IACZ,MAAM,WAAW,SAAS,aAAa,MAAM,IAAI;AAAA,IACjD,CAAC,QAAQ,QAAQ,SAAS,QAAQ,SAAS,QAAQ,QAAQ,QAAQ,QAAQ,QAAQ,KAAK;AAAA,EAC1F;AACA,SAAO,oBAAC,qBAAqB,UAArB,EAA8B,OAAe,UAAS;AAChE;AAGO,SAAS,mBAAyC;AACvD,SAAO,WAAW,oBAAoB;AACxC;","names":[]}
package/dist/form.d.ts DELETED
@@ -1,25 +0,0 @@
1
- import { PublicFormDefinition } from '@plenary/client';
2
-
3
- /** The raw value a `form` prop holds in the dom: a pointer to a form by key. */
4
- interface FormValue {
5
- form_key?: string;
6
- /** Present when the value was already resolved (the preview inlines it). */
7
- definition?: PublicFormDefinition | null;
8
- }
9
- /**
10
- * The shape a component sees after resolution. `definition` is `null` when the
11
- * form could not be fetched (deleted, inactive, not on this site, no client).
12
- */
13
- interface ResolvedForm {
14
- form_key: string;
15
- definition: PublicFormDefinition | null;
16
- }
17
- /**
18
- * Merge a form prop value with its (optional) fetched definition into the
19
- * resolved shape a component sees. Pure and synchronous — the renderer calls it
20
- * after a batch definition fetch. A value that already carries a definition
21
- * (the preview inlines one) is used as-is.
22
- */
23
- declare function toResolvedForm(value: FormValue | null | undefined, definition?: PublicFormDefinition | null): ResolvedForm | null;
24
-
25
- export { type FormValue, type ResolvedForm, toResolvedForm };
package/dist/form.js DELETED
@@ -1,11 +0,0 @@
1
- function toResolvedForm(value, definition) {
2
- if (!value || !value.form_key) return null;
3
- return {
4
- form_key: value.form_key,
5
- definition: value.definition !== void 0 ? value.definition : definition ?? null
6
- };
7
- }
8
- export {
9
- toResolvedForm
10
- };
11
- //# sourceMappingURL=form.js.map
package/dist/form.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/form.ts"],"sourcesContent":["import type { PublicFormDefinition } from \"@plenary/client\";\n\n/** The raw value a `form` prop holds in the dom: a pointer to a form by key. */\nexport interface FormValue {\n form_key?: string;\n /** Present when the value was already resolved (the preview inlines it). */\n definition?: PublicFormDefinition | null;\n}\n\n/**\n * The shape a component sees after resolution. `definition` is `null` when the\n * form could not be fetched (deleted, inactive, not on this site, no client).\n */\nexport interface ResolvedForm {\n form_key: string;\n definition: PublicFormDefinition | null;\n}\n\n/**\n * Merge a form prop value with its (optional) fetched definition into the\n * resolved shape a component sees. Pure and synchronous — the renderer calls it\n * after a batch definition fetch. A value that already carries a definition\n * (the preview inlines one) is used as-is.\n */\nexport function toResolvedForm(\n value: FormValue | null | undefined,\n definition?: PublicFormDefinition | null,\n): ResolvedForm | null {\n if (!value || !value.form_key) return null;\n return {\n form_key: value.form_key,\n definition: value.definition !== undefined ? value.definition : (definition ?? null),\n };\n}\n"],"mappings":"AAwBO,SAAS,eACd,OACA,YACqB;AACrB,MAAI,CAAC,SAAS,CAAC,MAAM,SAAU,QAAO;AACtC,SAAO;AAAA,IACL,UAAU,MAAM;AAAA,IAChB,YAAY,MAAM,eAAe,SAAY,MAAM,aAAc,cAAc;AAAA,EACjF;AACF;","names":[]}