@localess/react 3.0.1-dev.20260410070330 → 3.0.1-dev.20260411012947

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,218 @@
1
+ import react__default from 'react';
2
+ import { LocalessClientOptions, LocalessClient, ContentAsset, Links, ContentLink, ContentRichText } from '@localess/client';
3
+
4
+ /**
5
+ * Initialization options for {@link localessInit}.
6
+ *
7
+ * Extends {@link LocalessClientOptions} (origin, spaceId, token, version, debug, cacheTTL)
8
+ * with React-specific settings for component mapping and Visual Editor sync.
9
+ */
10
+ type LocalessOptions = LocalessClientOptions & {
11
+ /**
12
+ * Map of schema keys to React components used by {@link LocalessComponent} and
13
+ * {@link LocalessServerComponent} to render content blocks.
14
+ *
15
+ * Keys must match the `_schema` field of your Localess content objects.
16
+ * Use lowercase hyphenated names by convention (e.g. `'hero-section'`).
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * components: {
21
+ * 'page': PageComponent,
22
+ * 'hero-section': HeroSection,
23
+ * 'nav-menu': NavMenu,
24
+ * }
25
+ * ```
26
+ */
27
+ components?: Record<string, react__default.ElementType>;
28
+ /**
29
+ * Fallback React component rendered when `_schema` has no match in the registry.
30
+ * Receives the same `data`, `links`, and `references` props as any registered component.
31
+ * If omitted, an inline error message is rendered instead.
32
+ */
33
+ fallbackComponent?: react__default.ElementType;
34
+ /**
35
+ * When `true`, injects the Localess Visual Editor sync script (`sync-v1.js`) into
36
+ * `<head>` so that `input` and `change` events from the editor reach the app.
37
+ * Only takes effect when the page is running inside the Visual Editor iframe.
38
+ * Set to `false` (or omit) in production builds to avoid loading the script.
39
+ *
40
+ * @default false
41
+ */
42
+ enableSync?: boolean;
43
+ };
44
+
45
+ /**
46
+ * Initialize the Localess SDK.
47
+ *
48
+ * Must be called **once** at application startup (e.g. root layout, `_app.tsx`) before any
49
+ * other SDK function is used. Calling it again overwrites the existing client and state.
50
+ *
51
+ * - Creates the underlying {@link LocalessClient} with the supplied API options.
52
+ * - Registers the component map and optional fallback component.
53
+ * - When `enableSync` is `true` and the page is running inside the Visual Editor iframe,
54
+ * injects the Localess sync script into `<head>` to enable live editing events.
55
+ *
56
+ * @param options - Initialization options. Extends {@link LocalessClientOptions} with
57
+ * `components`, `fallbackComponent`, and `enableSync`.
58
+ * @returns The initialized {@link LocalessClient} instance.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * import { localessInit } from '@localess/react';
63
+ * import { Page, Header, Teaser } from '@/components';
64
+ *
65
+ * localessInit({
66
+ * origin: 'https://my-localess.web.app',
67
+ * spaceId: 'YOUR_SPACE_ID',
68
+ * token: 'YOUR_API_TOKEN', // keep server-side only
69
+ * enableSync: process.env.NODE_ENV !== 'production',
70
+ * components: { page: Page, header: Header, teaser: Teaser },
71
+ * });
72
+ * ```
73
+ */
74
+ declare function localessInit(options: LocalessOptions): LocalessClient;
75
+ /**
76
+ * Returns the initialized {@link LocalessClient} instance.
77
+ *
78
+ * Throws an error if called before {@link localessInit}. Use this in server components,
79
+ * API routes, or server-side data fetching functions to make API calls.
80
+ *
81
+ * @throws {Error} If `localessInit` has not been called yet.
82
+ * @returns The active {@link LocalessClient}.
83
+ *
84
+ * @example
85
+ * ```ts
86
+ * const content = await getLocalessClient().getContentBySlug<MyPage>('home', { locale: 'en' });
87
+ * ```
88
+ */
89
+ declare function getLocalessClient(): LocalessClient;
90
+ /**
91
+ * Adds a single component to the registry under the given schema key.
92
+ *
93
+ * The key must match the `_schema` field of the content objects you want to render.
94
+ * Overwrites any previously registered component for the same key.
95
+ *
96
+ * @param key - The schema key (e.g. `'hero-section'`).
97
+ * @param component - The React component to render for this schema key.
98
+ */
99
+ declare function registerComponent(key: string, component: react__default.ElementType): void;
100
+ /**
101
+ * Removes a component from the registry by schema key.
102
+ * No-op if the key does not exist.
103
+ *
104
+ * @param key - The schema key to remove.
105
+ */
106
+ declare function unregisterComponent(key: string): void;
107
+ /**
108
+ * Replaces the entire component registry with the supplied map.
109
+ *
110
+ * Useful when you need to swap all components at once (e.g. lazy-loaded registry).
111
+ * Any previously registered components (including those set via `localessInit`) are discarded.
112
+ *
113
+ * @param components - A record mapping schema keys to React components.
114
+ */
115
+ declare function setComponents(components: Record<string, react__default.ElementType>): void;
116
+ /**
117
+ * Looks up a React component by its schema key.
118
+ *
119
+ * Returns `undefined` and logs a console error when the key is not found.
120
+ * Called internally by {@link LocalessComponent} and {@link LocalessServerComponent}.
121
+ *
122
+ * @param key - The schema key to look up (matches `content._schema`).
123
+ * @returns The registered React component, or `undefined` if not found.
124
+ */
125
+ declare function getComponent(key: string): react__default.ElementType | undefined;
126
+ /**
127
+ * Sets the fallback component rendered when no registry match is found for a schema key.
128
+ *
129
+ * The fallback receives the same `data`, `links`, and `references` props as any
130
+ * registered component, so it can render a generic placeholder or log the unknown schema.
131
+ *
132
+ * @param fallbackComponent - The React component to use as the fallback.
133
+ */
134
+ declare function setFallbackComponent(fallbackComponent: react__default.ElementType): void;
135
+ /**
136
+ * Returns the currently registered fallback component, or `undefined` if none is set.
137
+ *
138
+ * Called internally by {@link LocalessComponent} and {@link LocalessServerComponent}
139
+ * when a schema key has no matching component in the registry.
140
+ *
141
+ * @returns The fallback React component, or `undefined`.
142
+ */
143
+ declare function getFallbackComponent(): react__default.ElementType | undefined;
144
+ /**
145
+ * Returns `true` when Visual Editor sync was enabled via `enableSync: true` in `localessInit`.
146
+ *
147
+ * Used internally by {@link LocalessComponent}, {@link LocalessDocument}, and {@link useLocaless}
148
+ * to decide whether to inject editable attributes and subscribe to sync events.
149
+ *
150
+ * @returns `true` if sync is enabled, `false` otherwise.
151
+ */
152
+ declare function isSyncEnabled(): boolean;
153
+ /**
154
+ * Resolves a {@link ContentAsset} to its full URL string.
155
+ *
156
+ * Constructs the URL using the `origin` and `spaceId` from `localessInit`:
157
+ * `{origin}/api/v1/spaces/{spaceId}/assets/{asset.uri}`
158
+ *
159
+ * @param asset - The asset reference object containing a `uri` field.
160
+ * @returns The fully qualified asset URL string.
161
+ *
162
+ * @example
163
+ * ```tsx
164
+ * <img src={resolveAsset(data.heroImage)} alt={data.heroImage.alt} />
165
+ * ```
166
+ */
167
+ declare function resolveAsset(asset: ContentAsset): string;
168
+
169
+ /**
170
+ * Resolves a {@link ContentLink} reference to a navigable URL string.
171
+ *
172
+ * Resolution rules by `link.type`:
173
+ * - `'content'` — looks up `link.uri` in the `links` map and returns `'/' + fullSlug`.
174
+ * Returns `'/not-found'` when `links` is undefined or the URI is not in the map.
175
+ * - `'url'` — returns `link.uri` directly (external or absolute URL).
176
+ * - anything else — returns `'no-type'` (indicates a misconfigured link field).
177
+ *
178
+ * @param links - The links map from `content.links` (keyed by link URI). May be `undefined`.
179
+ * @param link - The content link reference to resolve.
180
+ * @returns A URL string ready to use in an `<a href>` or Next.js `<Link href>`.
181
+ *
182
+ * @example
183
+ * ```tsx
184
+ * import { findLink } from '@localess/react';
185
+ *
186
+ * function NavItem({ data, links }) {
187
+ * return <a href={findLink(links, data.url)}>{data.label}</a>;
188
+ * }
189
+ * ```
190
+ */
191
+ declare function findLink(links: Links | undefined, link: ContentLink): string;
192
+
193
+ /**
194
+ * Renders a Localess rich text field to a React node tree.
195
+ *
196
+ * Converts a {@link ContentRichText} value (TipTap ProseMirror document JSON) into
197
+ * `React.ReactNode` using TipTap's static renderer. No browser APIs are required —
198
+ * safe to call in React Server Components and SSR.
199
+ *
200
+ * Supported TipTap extensions: Document, Text, Paragraph, Heading (h1–h6), Bold,
201
+ * Italic, Strike, Underline, History, ListItem, OrderedList, BulletList, Code,
202
+ * CodeBlockLowlight, Link.
203
+ *
204
+ * @param content - The rich text value from a Localess content field (type `ContentRichText`).
205
+ * @returns A `React.ReactNode` ready to render inside JSX.
206
+ *
207
+ * @example
208
+ * ```tsx
209
+ * import { renderRichTextToReact } from '@localess/react';
210
+ *
211
+ * export function Article({ data }: { data: MyContent }) {
212
+ * return <article>{renderRichTextToReact(data.body)}</article>;
213
+ * }
214
+ * ```
215
+ */
216
+ declare function renderRichTextToReact(content: ContentRichText): react__default.ReactNode;
217
+
218
+ export { type LocalessOptions as L, getFallbackComponent as a, getLocalessClient as b, renderRichTextToReact as c, resolveAsset as d, setFallbackComponent as e, findLink as f, getComponent as g, isSyncEnabled as i, localessInit as l, registerComponent as r, setComponents as s, unregisterComponent as u };
@@ -0,0 +1,218 @@
1
+ import react__default from 'react';
2
+ import { LocalessClientOptions, LocalessClient, ContentAsset, Links, ContentLink, ContentRichText } from '@localess/client';
3
+
4
+ /**
5
+ * Initialization options for {@link localessInit}.
6
+ *
7
+ * Extends {@link LocalessClientOptions} (origin, spaceId, token, version, debug, cacheTTL)
8
+ * with React-specific settings for component mapping and Visual Editor sync.
9
+ */
10
+ type LocalessOptions = LocalessClientOptions & {
11
+ /**
12
+ * Map of schema keys to React components used by {@link LocalessComponent} and
13
+ * {@link LocalessServerComponent} to render content blocks.
14
+ *
15
+ * Keys must match the `_schema` field of your Localess content objects.
16
+ * Use lowercase hyphenated names by convention (e.g. `'hero-section'`).
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * components: {
21
+ * 'page': PageComponent,
22
+ * 'hero-section': HeroSection,
23
+ * 'nav-menu': NavMenu,
24
+ * }
25
+ * ```
26
+ */
27
+ components?: Record<string, react__default.ElementType>;
28
+ /**
29
+ * Fallback React component rendered when `_schema` has no match in the registry.
30
+ * Receives the same `data`, `links`, and `references` props as any registered component.
31
+ * If omitted, an inline error message is rendered instead.
32
+ */
33
+ fallbackComponent?: react__default.ElementType;
34
+ /**
35
+ * When `true`, injects the Localess Visual Editor sync script (`sync-v1.js`) into
36
+ * `<head>` so that `input` and `change` events from the editor reach the app.
37
+ * Only takes effect when the page is running inside the Visual Editor iframe.
38
+ * Set to `false` (or omit) in production builds to avoid loading the script.
39
+ *
40
+ * @default false
41
+ */
42
+ enableSync?: boolean;
43
+ };
44
+
45
+ /**
46
+ * Initialize the Localess SDK.
47
+ *
48
+ * Must be called **once** at application startup (e.g. root layout, `_app.tsx`) before any
49
+ * other SDK function is used. Calling it again overwrites the existing client and state.
50
+ *
51
+ * - Creates the underlying {@link LocalessClient} with the supplied API options.
52
+ * - Registers the component map and optional fallback component.
53
+ * - When `enableSync` is `true` and the page is running inside the Visual Editor iframe,
54
+ * injects the Localess sync script into `<head>` to enable live editing events.
55
+ *
56
+ * @param options - Initialization options. Extends {@link LocalessClientOptions} with
57
+ * `components`, `fallbackComponent`, and `enableSync`.
58
+ * @returns The initialized {@link LocalessClient} instance.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * import { localessInit } from '@localess/react';
63
+ * import { Page, Header, Teaser } from '@/components';
64
+ *
65
+ * localessInit({
66
+ * origin: 'https://my-localess.web.app',
67
+ * spaceId: 'YOUR_SPACE_ID',
68
+ * token: 'YOUR_API_TOKEN', // keep server-side only
69
+ * enableSync: process.env.NODE_ENV !== 'production',
70
+ * components: { page: Page, header: Header, teaser: Teaser },
71
+ * });
72
+ * ```
73
+ */
74
+ declare function localessInit(options: LocalessOptions): LocalessClient;
75
+ /**
76
+ * Returns the initialized {@link LocalessClient} instance.
77
+ *
78
+ * Throws an error if called before {@link localessInit}. Use this in server components,
79
+ * API routes, or server-side data fetching functions to make API calls.
80
+ *
81
+ * @throws {Error} If `localessInit` has not been called yet.
82
+ * @returns The active {@link LocalessClient}.
83
+ *
84
+ * @example
85
+ * ```ts
86
+ * const content = await getLocalessClient().getContentBySlug<MyPage>('home', { locale: 'en' });
87
+ * ```
88
+ */
89
+ declare function getLocalessClient(): LocalessClient;
90
+ /**
91
+ * Adds a single component to the registry under the given schema key.
92
+ *
93
+ * The key must match the `_schema` field of the content objects you want to render.
94
+ * Overwrites any previously registered component for the same key.
95
+ *
96
+ * @param key - The schema key (e.g. `'hero-section'`).
97
+ * @param component - The React component to render for this schema key.
98
+ */
99
+ declare function registerComponent(key: string, component: react__default.ElementType): void;
100
+ /**
101
+ * Removes a component from the registry by schema key.
102
+ * No-op if the key does not exist.
103
+ *
104
+ * @param key - The schema key to remove.
105
+ */
106
+ declare function unregisterComponent(key: string): void;
107
+ /**
108
+ * Replaces the entire component registry with the supplied map.
109
+ *
110
+ * Useful when you need to swap all components at once (e.g. lazy-loaded registry).
111
+ * Any previously registered components (including those set via `localessInit`) are discarded.
112
+ *
113
+ * @param components - A record mapping schema keys to React components.
114
+ */
115
+ declare function setComponents(components: Record<string, react__default.ElementType>): void;
116
+ /**
117
+ * Looks up a React component by its schema key.
118
+ *
119
+ * Returns `undefined` and logs a console error when the key is not found.
120
+ * Called internally by {@link LocalessComponent} and {@link LocalessServerComponent}.
121
+ *
122
+ * @param key - The schema key to look up (matches `content._schema`).
123
+ * @returns The registered React component, or `undefined` if not found.
124
+ */
125
+ declare function getComponent(key: string): react__default.ElementType | undefined;
126
+ /**
127
+ * Sets the fallback component rendered when no registry match is found for a schema key.
128
+ *
129
+ * The fallback receives the same `data`, `links`, and `references` props as any
130
+ * registered component, so it can render a generic placeholder or log the unknown schema.
131
+ *
132
+ * @param fallbackComponent - The React component to use as the fallback.
133
+ */
134
+ declare function setFallbackComponent(fallbackComponent: react__default.ElementType): void;
135
+ /**
136
+ * Returns the currently registered fallback component, or `undefined` if none is set.
137
+ *
138
+ * Called internally by {@link LocalessComponent} and {@link LocalessServerComponent}
139
+ * when a schema key has no matching component in the registry.
140
+ *
141
+ * @returns The fallback React component, or `undefined`.
142
+ */
143
+ declare function getFallbackComponent(): react__default.ElementType | undefined;
144
+ /**
145
+ * Returns `true` when Visual Editor sync was enabled via `enableSync: true` in `localessInit`.
146
+ *
147
+ * Used internally by {@link LocalessComponent}, {@link LocalessDocument}, and {@link useLocaless}
148
+ * to decide whether to inject editable attributes and subscribe to sync events.
149
+ *
150
+ * @returns `true` if sync is enabled, `false` otherwise.
151
+ */
152
+ declare function isSyncEnabled(): boolean;
153
+ /**
154
+ * Resolves a {@link ContentAsset} to its full URL string.
155
+ *
156
+ * Constructs the URL using the `origin` and `spaceId` from `localessInit`:
157
+ * `{origin}/api/v1/spaces/{spaceId}/assets/{asset.uri}`
158
+ *
159
+ * @param asset - The asset reference object containing a `uri` field.
160
+ * @returns The fully qualified asset URL string.
161
+ *
162
+ * @example
163
+ * ```tsx
164
+ * <img src={resolveAsset(data.heroImage)} alt={data.heroImage.alt} />
165
+ * ```
166
+ */
167
+ declare function resolveAsset(asset: ContentAsset): string;
168
+
169
+ /**
170
+ * Resolves a {@link ContentLink} reference to a navigable URL string.
171
+ *
172
+ * Resolution rules by `link.type`:
173
+ * - `'content'` — looks up `link.uri` in the `links` map and returns `'/' + fullSlug`.
174
+ * Returns `'/not-found'` when `links` is undefined or the URI is not in the map.
175
+ * - `'url'` — returns `link.uri` directly (external or absolute URL).
176
+ * - anything else — returns `'no-type'` (indicates a misconfigured link field).
177
+ *
178
+ * @param links - The links map from `content.links` (keyed by link URI). May be `undefined`.
179
+ * @param link - The content link reference to resolve.
180
+ * @returns A URL string ready to use in an `<a href>` or Next.js `<Link href>`.
181
+ *
182
+ * @example
183
+ * ```tsx
184
+ * import { findLink } from '@localess/react';
185
+ *
186
+ * function NavItem({ data, links }) {
187
+ * return <a href={findLink(links, data.url)}>{data.label}</a>;
188
+ * }
189
+ * ```
190
+ */
191
+ declare function findLink(links: Links | undefined, link: ContentLink): string;
192
+
193
+ /**
194
+ * Renders a Localess rich text field to a React node tree.
195
+ *
196
+ * Converts a {@link ContentRichText} value (TipTap ProseMirror document JSON) into
197
+ * `React.ReactNode` using TipTap's static renderer. No browser APIs are required —
198
+ * safe to call in React Server Components and SSR.
199
+ *
200
+ * Supported TipTap extensions: Document, Text, Paragraph, Heading (h1–h6), Bold,
201
+ * Italic, Strike, Underline, History, ListItem, OrderedList, BulletList, Code,
202
+ * CodeBlockLowlight, Link.
203
+ *
204
+ * @param content - The rich text value from a Localess content field (type `ContentRichText`).
205
+ * @returns A `React.ReactNode` ready to render inside JSX.
206
+ *
207
+ * @example
208
+ * ```tsx
209
+ * import { renderRichTextToReact } from '@localess/react';
210
+ *
211
+ * export function Article({ data }: { data: MyContent }) {
212
+ * return <article>{renderRichTextToReact(data.body)}</article>;
213
+ * }
214
+ * ```
215
+ */
216
+ declare function renderRichTextToReact(content: ContentRichText): react__default.ReactNode;
217
+
218
+ export { type LocalessOptions as L, getFallbackComponent as a, getLocalessClient as b, renderRichTextToReact as c, resolveAsset as d, setFallbackComponent as e, findLink as f, getComponent as g, isSyncEnabled as i, localessInit as l, registerComponent as r, setComponents as s, unregisterComponent as u };
package/dist/rsc.d.mts CHANGED
@@ -1,15 +1,61 @@
1
- export { L as LocalessOptions, f as findLink, g as getComponent, a as getFallbackComponent, b as getLocalessClient, i as isSyncEnabled, l as localessInit, r as registerComponent, c as renderRichTextToReact, d as resolveAsset, u as unregisterComponent } from './richtext-XH7pH80J.mjs';
1
+ export { L as LocalessOptions, f as findLink, g as getComponent, a as getFallbackComponent, b as getLocalessClient, i as isSyncEnabled, l as localessInit, r as registerComponent, c as renderRichTextToReact, d as resolveAsset, u as unregisterComponent } from './richtext-D6tBmv-7.mjs';
2
2
  export { LocalessServerComponent, LocalessServerComponentProps, LocalessServerDocument, LocalessServerDocumentProps } from './ssr.mjs';
3
- import { ContentData, Links, References } from '@localess/client';
3
+ import { ContentData, Content } from '@localess/client';
4
4
  export { Content, ContentAsset, ContentData, ContentDataField, ContentDataSchema, ContentLink, ContentMetadata, ContentReference, ContentRichText, EventCallback, EventToApp, EventToAppType, Links, LocalessClient, LocalessSync, References, Translations, isBrowser, isIframe, isServer, localessEditable, localessEditableField } from '@localess/client';
5
- export { LocalessComponent, LocalessComponentProps, UseLocalessOptions, useLocaless } from './index.mjs';
6
- import * as React from 'react';
5
+ export { L as LocalessComponent, a as LocalessComponentProps } from './localess-component-DikkO35Z.mjs';
6
+ import * as react from 'react';
7
7
 
8
+ /**
9
+ * Props for {@link LocalessDocument}.
10
+ *
11
+ * @template T - The content data shape. Defaults to the base {@link ContentData} type.
12
+ */
8
13
  type LocalessDocumentProps<T extends ContentData = ContentData> = {
9
- data: T;
10
- links?: Links;
11
- references?: References;
14
+ /**
15
+ * The full content response object as returned by `getContentBySlug` or `getContentById`.
16
+ * Must contain a `data` field with a valid `_schema` key.
17
+ */
18
+ document: Content<T>;
12
19
  };
13
- declare const LocalessDocument: React.ForwardRefExoticComponent<LocalessDocumentProps<ContentData> & React.RefAttributes<HTMLElement>>;
20
+ /**
21
+ * Client Component that renders content and automatically subscribes to Visual Editor sync events.
22
+ *
23
+ * Wraps {@link LocalessComponent} with local state so that live `input` and `change` events
24
+ * from the Localess Visual Editor update the rendered content without a full page reload.
25
+ *
26
+ * **Recommended pattern for Next.js App Router:** fetch data in a Server Component and pass it
27
+ * as props. The page renders immediately with server data; once the client hydrates, live editing
28
+ * activates on top — no loading state needed.
29
+ *
30
+ * Sync only activates when `enableSync: true` was passed to `localessInit` **and** the page
31
+ * is running inside the Visual Editor iframe (`isIframe()` is true).
32
+ *
33
+ * **Requires `'use client'`** — must be used inside a Client Component boundary in Next.js
34
+ * App Router. Available from `@localess/react` (SPA) and `@localess/react/rsc` (RSC).
35
+ * Not available from `@localess/react/ssr`.
36
+ *
37
+ * @template T - The content data shape. Defaults to {@link ContentData}.
38
+ *
39
+ * @example Server Component passes data; Client Component renders with live sync
40
+ * ```tsx
41
+ * // app/[locale]/page.tsx (Server Component)
42
+ * import { getLocalessClient } from '@localess/react/rsc';
43
+ * import PageClient from './page-client';
44
+ *
45
+ * export default async function Page({ params }) {
46
+ * const content = await getLocalessClient().getContentBySlug('home', { locale: params.locale });
47
+ * return <PageClient data={content.data} links={content.links} references={content.references} />;
48
+ * }
49
+ *
50
+ * // app/[locale]/page-client.tsx (Client Component)
51
+ * 'use client';
52
+ * import { LocalessDocument } from '@localess/react/rsc';
53
+ *
54
+ * export default function PageClient({ data, links, references }) {
55
+ * return <LocalessDocument data={data} links={links} references={references} />;
56
+ * }
57
+ * ```
58
+ */
59
+ declare const LocalessDocument: react.ForwardRefExoticComponent<LocalessDocumentProps<ContentData> & react.RefAttributes<HTMLElement>>;
14
60
 
15
61
  export { LocalessDocument, type LocalessDocumentProps };
package/dist/rsc.d.ts CHANGED
@@ -1,15 +1,61 @@
1
- export { L as LocalessOptions, f as findLink, g as getComponent, a as getFallbackComponent, b as getLocalessClient, i as isSyncEnabled, l as localessInit, r as registerComponent, c as renderRichTextToReact, d as resolveAsset, u as unregisterComponent } from './richtext-XH7pH80J.js';
1
+ export { L as LocalessOptions, f as findLink, g as getComponent, a as getFallbackComponent, b as getLocalessClient, i as isSyncEnabled, l as localessInit, r as registerComponent, c as renderRichTextToReact, d as resolveAsset, u as unregisterComponent } from './richtext-D6tBmv-7.js';
2
2
  export { LocalessServerComponent, LocalessServerComponentProps, LocalessServerDocument, LocalessServerDocumentProps } from './ssr.js';
3
- import { ContentData, Links, References } from '@localess/client';
3
+ import { ContentData, Content } from '@localess/client';
4
4
  export { Content, ContentAsset, ContentData, ContentDataField, ContentDataSchema, ContentLink, ContentMetadata, ContentReference, ContentRichText, EventCallback, EventToApp, EventToAppType, Links, LocalessClient, LocalessSync, References, Translations, isBrowser, isIframe, isServer, localessEditable, localessEditableField } from '@localess/client';
5
- export { LocalessComponent, LocalessComponentProps, UseLocalessOptions, useLocaless } from './index.js';
6
- import * as React from 'react';
5
+ export { L as LocalessComponent, a as LocalessComponentProps } from './localess-component-DikkO35Z.js';
6
+ import * as react from 'react';
7
7
 
8
+ /**
9
+ * Props for {@link LocalessDocument}.
10
+ *
11
+ * @template T - The content data shape. Defaults to the base {@link ContentData} type.
12
+ */
8
13
  type LocalessDocumentProps<T extends ContentData = ContentData> = {
9
- data: T;
10
- links?: Links;
11
- references?: References;
14
+ /**
15
+ * The full content response object as returned by `getContentBySlug` or `getContentById`.
16
+ * Must contain a `data` field with a valid `_schema` key.
17
+ */
18
+ document: Content<T>;
12
19
  };
13
- declare const LocalessDocument: React.ForwardRefExoticComponent<LocalessDocumentProps<ContentData> & React.RefAttributes<HTMLElement>>;
20
+ /**
21
+ * Client Component that renders content and automatically subscribes to Visual Editor sync events.
22
+ *
23
+ * Wraps {@link LocalessComponent} with local state so that live `input` and `change` events
24
+ * from the Localess Visual Editor update the rendered content without a full page reload.
25
+ *
26
+ * **Recommended pattern for Next.js App Router:** fetch data in a Server Component and pass it
27
+ * as props. The page renders immediately with server data; once the client hydrates, live editing
28
+ * activates on top — no loading state needed.
29
+ *
30
+ * Sync only activates when `enableSync: true` was passed to `localessInit` **and** the page
31
+ * is running inside the Visual Editor iframe (`isIframe()` is true).
32
+ *
33
+ * **Requires `'use client'`** — must be used inside a Client Component boundary in Next.js
34
+ * App Router. Available from `@localess/react` (SPA) and `@localess/react/rsc` (RSC).
35
+ * Not available from `@localess/react/ssr`.
36
+ *
37
+ * @template T - The content data shape. Defaults to {@link ContentData}.
38
+ *
39
+ * @example Server Component passes data; Client Component renders with live sync
40
+ * ```tsx
41
+ * // app/[locale]/page.tsx (Server Component)
42
+ * import { getLocalessClient } from '@localess/react/rsc';
43
+ * import PageClient from './page-client';
44
+ *
45
+ * export default async function Page({ params }) {
46
+ * const content = await getLocalessClient().getContentBySlug('home', { locale: params.locale });
47
+ * return <PageClient data={content.data} links={content.links} references={content.references} />;
48
+ * }
49
+ *
50
+ * // app/[locale]/page-client.tsx (Client Component)
51
+ * 'use client';
52
+ * import { LocalessDocument } from '@localess/react/rsc';
53
+ *
54
+ * export default function PageClient({ data, links, references }) {
55
+ * return <LocalessDocument data={data} links={links} references={references} />;
56
+ * }
57
+ * ```
58
+ */
59
+ declare const LocalessDocument: react.ForwardRefExoticComponent<LocalessDocumentProps<ContentData> & react.RefAttributes<HTMLElement>>;
14
60
 
15
61
  export { LocalessDocument, type LocalessDocumentProps };
package/dist/rsc.js CHANGED
@@ -38,8 +38,7 @@ __export(rsc_exports, {
38
38
  registerComponent: () => registerComponent,
39
39
  renderRichTextToReact: () => renderRichTextToReact,
40
40
  resolveAsset: () => resolveAsset,
41
- unregisterComponent: () => unregisterComponent,
42
- useLocaless: () => useLocaless
41
+ unregisterComponent: () => unregisterComponent
43
42
  });
44
43
  module.exports = __toCommonJS(rsc_exports);
45
44
 
@@ -133,7 +132,7 @@ var LocalessServerComponent = (0, import_react.forwardRef)(({ data, links, refer
133
132
  var import_react2 = require("react");
134
133
  var import_jsx_runtime2 = require("react/jsx-runtime");
135
134
  var LocalessServerDocument = (0, import_react2.forwardRef)(({ document }, ref) => {
136
- if (!document || !document.data) {
135
+ if (!document.data) {
137
136
  console.error("LocalessServerDocument property %cdocument.data%c is not provided.", FONT_BOLD, FONT_NORMAL);
138
137
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
139
138
  "LocalessServerDocument property ",
@@ -245,51 +244,18 @@ var LocalessComponent = (0, import_react4.forwardRef)(
245
244
 
246
245
  // src/rsc/localess-document.tsx
247
246
  var import_react5 = require("react");
248
- var import_client3 = require("@localess/client");
249
247
  var import_jsx_runtime4 = require("react/jsx-runtime");
250
- var LocalessDocument = (0, import_react5.forwardRef)(({ data, links, references, ...restProps }, ref) => {
251
- const [contentData, setContentData] = (0, import_react5.useState)(data);
252
- (0, import_react5.useEffect)(() => {
253
- if (isSyncEnabled() && (0, import_client3.isBrowser)()) {
254
- window.localess?.on(["input", "change"], (event) => {
255
- console.log("Localess:event", event);
256
- if (event.type === "change" || event.type === "input") {
257
- setContentData(event.data);
258
- }
259
- });
260
- }
261
- });
262
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(LocalessComponent, { ref, data: contentData, links, references, ...restProps });
263
- });
264
-
265
- // src/core/hooks/use-localess.ts
266
- var import_react6 = require("react");
267
- var import_client4 = require("@localess/client");
268
- var useLocaless = (slug, options = {}) => {
269
- const [document, setDocument] = (0, import_react6.useState)();
270
- const client = getLocalessClient();
271
- let normalizedSlug;
272
- if (Array.isArray(slug)) {
273
- normalizedSlug = slug.join("/");
274
- } else {
275
- normalizedSlug = slug;
248
+ var LocalessDocument = (0, import_react5.forwardRef)(({ document }, ref) => {
249
+ if (!document.data) {
250
+ console.error("LocalessDocument property %cdocument.data%c is not provided.", FONT_BOLD, FONT_NORMAL);
251
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { children: [
252
+ "LocalessDocument property ",
253
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("b", { children: "document.data" }),
254
+ " is not provided."
255
+ ] });
276
256
  }
277
- (0, import_react6.useEffect)(() => {
278
- async function loadDocument() {
279
- const document2 = await client.getContentBySlug(normalizedSlug, options);
280
- setDocument(document2);
281
- if (isSyncEnabled() && (0, import_client4.isBrowser)()) {
282
- window.localess?.on(["input", "change"], (event) => {
283
- if (event.type === "change" || event.type === "input") {
284
- setDocument({ ...document2, data: event.data });
285
- }
286
- });
287
- }
288
- }
289
- loadDocument();
290
- }, [slug, options, client]);
291
- return document;
292
- };
257
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(LocalessComponent, { ref, data: document.data, links: document.links, references: document.references }) });
258
+ });
293
259
  // Annotate the CommonJS export names for ESM import in node:
294
260
  0 && (module.exports = {
295
261
  LocalessComponent,
@@ -310,6 +276,5 @@ var useLocaless = (slug, options = {}) => {
310
276
  registerComponent,
311
277
  renderRichTextToReact,
312
278
  resolveAsset,
313
- unregisterComponent,
314
- useLocaless
279
+ unregisterComponent
315
280
  });