@localess/react 3.0.1-dev.20260410065141 → 3.0.1-dev.20260410071322

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/index.d.mts CHANGED
@@ -1,16 +1,104 @@
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, s as setComponents, e as setFallbackComponent, 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, s as setComponents, e as setFallbackComponent, u as unregisterComponent } from './richtext-l2BRZFEP.mjs';
2
2
  import * as React from 'react';
3
3
  import { ContentData, Links, References, ContentFetchParams, 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
5
 
6
+ /**
7
+ * Props for {@link LocalessComponent}.
8
+ *
9
+ * @template T - The content data shape. Defaults to the base {@link ContentData} type.
10
+ */
6
11
  type LocalessComponentProps<T extends ContentData = ContentData> = {
12
+ /**
13
+ * The content data object to render. Must have a `_schema` field that matches a key
14
+ * in the component registry configured via `localessInit`.
15
+ */
7
16
  data: T;
17
+ /**
18
+ * Optional map of content links keyed by link ID.
19
+ * Pass through to child components so they can resolve {@link ContentLink} values with `findLink`.
20
+ */
8
21
  links?: Links;
22
+ /**
23
+ * Optional map of resolved content references keyed by reference ID.
24
+ * Pass through to child components that consume referenced content.
25
+ */
9
26
  references?: References;
10
27
  };
28
+ /**
29
+ * Dynamic schema-to-component renderer for use in SPA and client-side contexts.
30
+ *
31
+ * Looks up `data._schema` in the component registry (set via `localessInit` or `setComponents`),
32
+ * renders the matched component, and — when Visual Editor sync is active — automatically
33
+ * spreads `localessEditable` attributes on the root element for live targeting.
34
+ *
35
+ * Falls back to the `fallbackComponent` (if registered) when the schema key is not found,
36
+ * or renders an inline error message as a last resort.
37
+ *
38
+ * **Server-safe** — does not include a `'use client'` directive and can be used in
39
+ * React Server Components. For SSR / static-export environments use {@link LocalessServerComponent}
40
+ * from `@localess/react/ssr` instead, which omits the sync attribute injection.
41
+ *
42
+ * @template T - The content data shape. Defaults to {@link ContentData}.
43
+ *
44
+ * @example Basic usage
45
+ * ```tsx
46
+ * import { LocalessComponent } from '@localess/react';
47
+ *
48
+ * <LocalessComponent data={content.data} links={content.links} references={content.references} />
49
+ * ```
50
+ *
51
+ * @example Rendering a list of nested blocks
52
+ * ```tsx
53
+ * {data.body.map(item => (
54
+ * <LocalessComponent key={item._id} data={item} links={content.links} references={content.references} />
55
+ * ))}
56
+ * ```
57
+ */
11
58
  declare const LocalessComponent: React.ForwardRefExoticComponent<LocalessComponentProps<ContentData> & React.RefAttributes<HTMLElement>>;
12
59
 
60
+ /**
61
+ * Options for {@link useLocaless}.
62
+ * Extends {@link ContentFetchParams} with any future hook-specific settings.
63
+ */
13
64
  type UseLocalessOptions = ContentFetchParams & {};
65
+ /**
66
+ * React hook for fetching Localess content by slug inside a Client Component.
67
+ *
68
+ * Fetches content on mount using `getLocalessClient().getContentBySlug`, stores it in local state,
69
+ * and — when `enableSync` is active and the page is running inside the Visual Editor iframe —
70
+ * automatically subscribes to `input` and `change` events so content updates live without a reload.
71
+ *
72
+ * **Requires `'use client'`** — must be called inside a Client Component.
73
+ *
74
+ * **Recommended pattern:** fetch data server-side and pass it as `initialContent`, then use the
75
+ * hook result with `?? initialContent` to avoid a loading flash:
76
+ * ```tsx
77
+ * const content = useLocaless('home', { locale }) ?? initialContent;
78
+ * ```
79
+ *
80
+ * @template T - The content data shape. Defaults to {@link ContentData}.
81
+ *
82
+ * @param slug - Content slug string, or an array of path segments that will be joined with `/`.
83
+ * @param options - Optional fetch parameters (locale, version, resolveReference, resolveLink).
84
+ * @returns The fetched {@link Content}<T> object, or `undefined` while the initial fetch is in flight.
85
+ *
86
+ * @example Basic usage
87
+ * ```tsx
88
+ * 'use client';
89
+ * import { useLocaless } from '@localess/react/rsc';
90
+ *
91
+ * export function PageClient({ initialContent, locale }) {
92
+ * const content = useLocaless('home', { locale }) ?? initialContent;
93
+ * return <LocalessComponent data={content.data} links={content.links} />;
94
+ * }
95
+ * ```
96
+ *
97
+ * @example Array slug (joined as 'blog/my-post')
98
+ * ```tsx
99
+ * const content = useLocaless(['blog', 'my-post'], { locale: 'en' });
100
+ * ```
101
+ */
14
102
  declare const useLocaless: <T extends ContentData = ContentData>(slug: string | string[], options?: UseLocalessOptions) => Content<T> | undefined;
15
103
 
16
104
  export { LocalessComponent, type LocalessComponentProps, type UseLocalessOptions, useLocaless };
package/dist/index.d.ts CHANGED
@@ -1,16 +1,104 @@
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, s as setComponents, e as setFallbackComponent, 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, s as setComponents, e as setFallbackComponent, u as unregisterComponent } from './richtext-l2BRZFEP.js';
2
2
  import * as React from 'react';
3
3
  import { ContentData, Links, References, ContentFetchParams, 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
5
 
6
+ /**
7
+ * Props for {@link LocalessComponent}.
8
+ *
9
+ * @template T - The content data shape. Defaults to the base {@link ContentData} type.
10
+ */
6
11
  type LocalessComponentProps<T extends ContentData = ContentData> = {
12
+ /**
13
+ * The content data object to render. Must have a `_schema` field that matches a key
14
+ * in the component registry configured via `localessInit`.
15
+ */
7
16
  data: T;
17
+ /**
18
+ * Optional map of content links keyed by link ID.
19
+ * Pass through to child components so they can resolve {@link ContentLink} values with `findLink`.
20
+ */
8
21
  links?: Links;
22
+ /**
23
+ * Optional map of resolved content references keyed by reference ID.
24
+ * Pass through to child components that consume referenced content.
25
+ */
9
26
  references?: References;
10
27
  };
28
+ /**
29
+ * Dynamic schema-to-component renderer for use in SPA and client-side contexts.
30
+ *
31
+ * Looks up `data._schema` in the component registry (set via `localessInit` or `setComponents`),
32
+ * renders the matched component, and — when Visual Editor sync is active — automatically
33
+ * spreads `localessEditable` attributes on the root element for live targeting.
34
+ *
35
+ * Falls back to the `fallbackComponent` (if registered) when the schema key is not found,
36
+ * or renders an inline error message as a last resort.
37
+ *
38
+ * **Server-safe** — does not include a `'use client'` directive and can be used in
39
+ * React Server Components. For SSR / static-export environments use {@link LocalessServerComponent}
40
+ * from `@localess/react/ssr` instead, which omits the sync attribute injection.
41
+ *
42
+ * @template T - The content data shape. Defaults to {@link ContentData}.
43
+ *
44
+ * @example Basic usage
45
+ * ```tsx
46
+ * import { LocalessComponent } from '@localess/react';
47
+ *
48
+ * <LocalessComponent data={content.data} links={content.links} references={content.references} />
49
+ * ```
50
+ *
51
+ * @example Rendering a list of nested blocks
52
+ * ```tsx
53
+ * {data.body.map(item => (
54
+ * <LocalessComponent key={item._id} data={item} links={content.links} references={content.references} />
55
+ * ))}
56
+ * ```
57
+ */
11
58
  declare const LocalessComponent: React.ForwardRefExoticComponent<LocalessComponentProps<ContentData> & React.RefAttributes<HTMLElement>>;
12
59
 
60
+ /**
61
+ * Options for {@link useLocaless}.
62
+ * Extends {@link ContentFetchParams} with any future hook-specific settings.
63
+ */
13
64
  type UseLocalessOptions = ContentFetchParams & {};
65
+ /**
66
+ * React hook for fetching Localess content by slug inside a Client Component.
67
+ *
68
+ * Fetches content on mount using `getLocalessClient().getContentBySlug`, stores it in local state,
69
+ * and — when `enableSync` is active and the page is running inside the Visual Editor iframe —
70
+ * automatically subscribes to `input` and `change` events so content updates live without a reload.
71
+ *
72
+ * **Requires `'use client'`** — must be called inside a Client Component.
73
+ *
74
+ * **Recommended pattern:** fetch data server-side and pass it as `initialContent`, then use the
75
+ * hook result with `?? initialContent` to avoid a loading flash:
76
+ * ```tsx
77
+ * const content = useLocaless('home', { locale }) ?? initialContent;
78
+ * ```
79
+ *
80
+ * @template T - The content data shape. Defaults to {@link ContentData}.
81
+ *
82
+ * @param slug - Content slug string, or an array of path segments that will be joined with `/`.
83
+ * @param options - Optional fetch parameters (locale, version, resolveReference, resolveLink).
84
+ * @returns The fetched {@link Content}<T> object, or `undefined` while the initial fetch is in flight.
85
+ *
86
+ * @example Basic usage
87
+ * ```tsx
88
+ * 'use client';
89
+ * import { useLocaless } from '@localess/react/rsc';
90
+ *
91
+ * export function PageClient({ initialContent, locale }) {
92
+ * const content = useLocaless('home', { locale }) ?? initialContent;
93
+ * return <LocalessComponent data={content.data} links={content.links} />;
94
+ * }
95
+ * ```
96
+ *
97
+ * @example Array slug (joined as 'blog/my-post')
98
+ * ```tsx
99
+ * const content = useLocaless(['blog', 'my-post'], { locale: 'en' });
100
+ * ```
101
+ */
14
102
  declare const useLocaless: <T extends ContentData = ContentData>(slug: string | string[], options?: UseLocalessOptions) => Content<T> | undefined;
15
103
 
16
104
  export { LocalessComponent, type LocalessComponentProps, type UseLocalessOptions, useLocaless };
@@ -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,5 +1,72 @@
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-l2BRZFEP.mjs';
2
2
  export { LocalessServerComponent, LocalessServerComponentProps, LocalessServerDocument, LocalessServerDocumentProps } from './ssr.mjs';
3
+ import { ContentData, Links, References } from '@localess/client';
3
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';
4
5
  export { LocalessComponent, LocalessComponentProps, UseLocalessOptions, useLocaless } from './index.mjs';
5
- import 'react';
6
+ import * as React from 'react';
7
+
8
+ /**
9
+ * Props for {@link LocalessDocument}.
10
+ *
11
+ * @template T - The content data shape. Defaults to the base {@link ContentData} type.
12
+ */
13
+ type LocalessDocumentProps<T extends ContentData = ContentData> = {
14
+ /**
15
+ * The content data object to render — typically `content.data` from `getContentBySlug`.
16
+ * Should be fetched server-side and passed as a prop so the page renders immediately
17
+ * without a loading flash.
18
+ */
19
+ data: T;
20
+ /**
21
+ * Optional map of content links keyed by link ID.
22
+ * Passed through to child components for resolving {@link ContentLink} values with `findLink`.
23
+ */
24
+ links?: Links;
25
+ /**
26
+ * Optional map of resolved content references keyed by reference ID.
27
+ * Passed through to child components that consume referenced content.
28
+ */
29
+ references?: References;
30
+ };
31
+ /**
32
+ * Client Component that renders content and automatically subscribes to Visual Editor sync events.
33
+ *
34
+ * Wraps {@link LocalessComponent} with local state so that live `input` and `change` events
35
+ * from the Localess Visual Editor update the rendered content without a full page reload.
36
+ *
37
+ * **Recommended pattern for Next.js App Router:** fetch data in a Server Component and pass it
38
+ * as props. The page renders immediately with server data; once the client hydrates, live editing
39
+ * activates on top — no loading state needed.
40
+ *
41
+ * Sync only activates when `enableSync: true` was passed to `localessInit` **and** the page
42
+ * is running inside the Visual Editor iframe (`isIframe()` is true).
43
+ *
44
+ * **Requires `'use client'`** — must be used inside a Client Component boundary in Next.js
45
+ * App Router. Available from `@localess/react` (SPA) and `@localess/react/rsc` (RSC).
46
+ * Not available from `@localess/react/ssr`.
47
+ *
48
+ * @template T - The content data shape. Defaults to {@link ContentData}.
49
+ *
50
+ * @example Server Component passes data; Client Component renders with live sync
51
+ * ```tsx
52
+ * // app/[locale]/page.tsx (Server Component)
53
+ * import { getLocalessClient } from '@localess/react/rsc';
54
+ * import PageClient from './page-client';
55
+ *
56
+ * export default async function Page({ params }) {
57
+ * const content = await getLocalessClient().getContentBySlug('home', { locale: params.locale });
58
+ * return <PageClient data={content.data} links={content.links} references={content.references} />;
59
+ * }
60
+ *
61
+ * // app/[locale]/page-client.tsx (Client Component)
62
+ * 'use client';
63
+ * import { LocalessDocument } from '@localess/react/rsc';
64
+ *
65
+ * export default function PageClient({ data, links, references }) {
66
+ * return <LocalessDocument data={data} links={links} references={references} />;
67
+ * }
68
+ * ```
69
+ */
70
+ declare const LocalessDocument: React.ForwardRefExoticComponent<LocalessDocumentProps<ContentData> & React.RefAttributes<HTMLElement>>;
71
+
72
+ export { LocalessDocument, type LocalessDocumentProps };
package/dist/rsc.d.ts CHANGED
@@ -1,5 +1,72 @@
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-l2BRZFEP.js';
2
2
  export { LocalessServerComponent, LocalessServerComponentProps, LocalessServerDocument, LocalessServerDocumentProps } from './ssr.js';
3
+ import { ContentData, Links, References } from '@localess/client';
3
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';
4
5
  export { LocalessComponent, LocalessComponentProps, UseLocalessOptions, useLocaless } from './index.js';
5
- import 'react';
6
+ import * as React from 'react';
7
+
8
+ /**
9
+ * Props for {@link LocalessDocument}.
10
+ *
11
+ * @template T - The content data shape. Defaults to the base {@link ContentData} type.
12
+ */
13
+ type LocalessDocumentProps<T extends ContentData = ContentData> = {
14
+ /**
15
+ * The content data object to render — typically `content.data` from `getContentBySlug`.
16
+ * Should be fetched server-side and passed as a prop so the page renders immediately
17
+ * without a loading flash.
18
+ */
19
+ data: T;
20
+ /**
21
+ * Optional map of content links keyed by link ID.
22
+ * Passed through to child components for resolving {@link ContentLink} values with `findLink`.
23
+ */
24
+ links?: Links;
25
+ /**
26
+ * Optional map of resolved content references keyed by reference ID.
27
+ * Passed through to child components that consume referenced content.
28
+ */
29
+ references?: References;
30
+ };
31
+ /**
32
+ * Client Component that renders content and automatically subscribes to Visual Editor sync events.
33
+ *
34
+ * Wraps {@link LocalessComponent} with local state so that live `input` and `change` events
35
+ * from the Localess Visual Editor update the rendered content without a full page reload.
36
+ *
37
+ * **Recommended pattern for Next.js App Router:** fetch data in a Server Component and pass it
38
+ * as props. The page renders immediately with server data; once the client hydrates, live editing
39
+ * activates on top — no loading state needed.
40
+ *
41
+ * Sync only activates when `enableSync: true` was passed to `localessInit` **and** the page
42
+ * is running inside the Visual Editor iframe (`isIframe()` is true).
43
+ *
44
+ * **Requires `'use client'`** — must be used inside a Client Component boundary in Next.js
45
+ * App Router. Available from `@localess/react` (SPA) and `@localess/react/rsc` (RSC).
46
+ * Not available from `@localess/react/ssr`.
47
+ *
48
+ * @template T - The content data shape. Defaults to {@link ContentData}.
49
+ *
50
+ * @example Server Component passes data; Client Component renders with live sync
51
+ * ```tsx
52
+ * // app/[locale]/page.tsx (Server Component)
53
+ * import { getLocalessClient } from '@localess/react/rsc';
54
+ * import PageClient from './page-client';
55
+ *
56
+ * export default async function Page({ params }) {
57
+ * const content = await getLocalessClient().getContentBySlug('home', { locale: params.locale });
58
+ * return <PageClient data={content.data} links={content.links} references={content.references} />;
59
+ * }
60
+ *
61
+ * // app/[locale]/page-client.tsx (Client Component)
62
+ * 'use client';
63
+ * import { LocalessDocument } from '@localess/react/rsc';
64
+ *
65
+ * export default function PageClient({ data, links, references }) {
66
+ * return <LocalessDocument data={data} links={links} references={references} />;
67
+ * }
68
+ * ```
69
+ */
70
+ declare const LocalessDocument: React.ForwardRefExoticComponent<LocalessDocumentProps<ContentData> & React.RefAttributes<HTMLElement>>;
71
+
72
+ export { LocalessDocument, type LocalessDocumentProps };
package/dist/rsc.js CHANGED
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var rsc_exports = {};
22
22
  __export(rsc_exports, {
23
23
  LocalessComponent: () => LocalessComponent,
24
+ LocalessDocument: () => LocalessDocument,
24
25
  LocalessServerComponent: () => LocalessServerComponent,
25
26
  LocalessServerDocument: () => LocalessServerDocument,
26
27
  findLink: () => findLink,
@@ -242,11 +243,37 @@ var LocalessComponent = (0, import_react4.forwardRef)(
242
243
  }
243
244
  );
244
245
 
245
- // src/core/hooks/use-localess.ts
246
+ // src/rsc/localess-document.tsx
246
247
  var import_react5 = require("react");
248
+ var import_jsx_runtime4 = require("react/jsx-runtime");
249
+ var LocalessDocument = (0, import_react5.forwardRef)(({
250
+ data,
251
+ links,
252
+ references,
253
+ ...restProps
254
+ }, ref) => {
255
+ const [contentData, setContentData] = (0, import_react5.useState)(data);
256
+ (0, import_react5.useEffect)(() => {
257
+ console.log("LocalessDocument isSyncEnabled:", isSyncEnabled());
258
+ console.log("LocalessDocument isBrowser:", (0, import_client2.isBrowser)());
259
+ console.log("LocalessDocument isBrowser:", (0, import_client2.isBrowser)());
260
+ if (isSyncEnabled() && (0, import_client2.isBrowser)() && (0, import_client2.isIframe)()) {
261
+ window.localess?.on(["input", "change"], (event) => {
262
+ console.log("Localess:event", event);
263
+ if (event.type === "change" || event.type === "input") {
264
+ setContentData(event.data);
265
+ }
266
+ });
267
+ }
268
+ }, []);
269
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(LocalessComponent, { ref, data: contentData, links, references, ...restProps });
270
+ });
271
+
272
+ // src/core/hooks/use-localess.ts
273
+ var import_react6 = require("react");
247
274
  var import_client3 = require("@localess/client");
248
275
  var useLocaless = (slug, options = {}) => {
249
- const [document, setDocument] = (0, import_react5.useState)();
276
+ const [document, setDocument] = (0, import_react6.useState)();
250
277
  const client = getLocalessClient();
251
278
  let normalizedSlug;
252
279
  if (Array.isArray(slug)) {
@@ -254,7 +281,7 @@ var useLocaless = (slug, options = {}) => {
254
281
  } else {
255
282
  normalizedSlug = slug;
256
283
  }
257
- (0, import_react5.useEffect)(() => {
284
+ (0, import_react6.useEffect)(() => {
258
285
  async function loadDocument() {
259
286
  const document2 = await client.getContentBySlug(normalizedSlug, options);
260
287
  setDocument(document2);
@@ -273,6 +300,7 @@ var useLocaless = (slug, options = {}) => {
273
300
  // Annotate the CommonJS export names for ESM import in node:
274
301
  0 && (module.exports = {
275
302
  LocalessComponent,
303
+ LocalessDocument,
276
304
  LocalessServerComponent,
277
305
  LocalessServerDocument,
278
306
  findLink,
package/dist/rsc.mjs CHANGED
@@ -23,8 +23,35 @@ import {
23
23
  resolveAsset,
24
24
  unregisterComponent
25
25
  } from "./chunk-ETSLIILF.mjs";
26
+
27
+ // src/rsc/localess-document.tsx
28
+ import { forwardRef, useEffect, useState } from "react";
29
+ import { jsx } from "react/jsx-runtime";
30
+ var LocalessDocument = forwardRef(({
31
+ data,
32
+ links,
33
+ references,
34
+ ...restProps
35
+ }, ref) => {
36
+ const [contentData, setContentData] = useState(data);
37
+ useEffect(() => {
38
+ console.log("LocalessDocument isSyncEnabled:", isSyncEnabled());
39
+ console.log("LocalessDocument isBrowser:", isBrowser());
40
+ console.log("LocalessDocument isBrowser:", isBrowser());
41
+ if (isSyncEnabled() && isBrowser() && isIframe()) {
42
+ window.localess?.on(["input", "change"], (event) => {
43
+ console.log("Localess:event", event);
44
+ if (event.type === "change" || event.type === "input") {
45
+ setContentData(event.data);
46
+ }
47
+ });
48
+ }
49
+ }, []);
50
+ return /* @__PURE__ */ jsx(LocalessComponent, { ref, data: contentData, links, references, ...restProps });
51
+ });
26
52
  export {
27
53
  LocalessComponent,
54
+ LocalessDocument,
28
55
  LocalessServerComponent,
29
56
  LocalessServerDocument,
30
57
  findLink,
package/dist/ssr.d.mts CHANGED
@@ -1,18 +1,96 @@
1
- export { L as LocalessOptions, f as findLink, g as getComponent, a as getFallbackComponent, b as getLocalessClient, 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, l as localessInit, r as registerComponent, c as renderRichTextToReact, d as resolveAsset, u as unregisterComponent } from './richtext-l2BRZFEP.mjs';
2
2
  import * as React from 'react';
3
3
  import { ContentData, Links, References, 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
5
 
6
+ /**
7
+ * Props for {@link LocalessServerComponent}.
8
+ *
9
+ * @template T - The content data shape. Defaults to the base {@link ContentData} type.
10
+ */
6
11
  type LocalessServerComponentProps<T extends ContentData = ContentData> = {
12
+ /**
13
+ * The content data object to render. Must have a `_schema` field that matches a key
14
+ * in the component registry configured via `localessInit`.
15
+ */
7
16
  data: T;
17
+ /**
18
+ * Optional map of content links keyed by link ID.
19
+ * Pass through to child components so they can resolve {@link ContentLink} values with `findLink`.
20
+ */
8
21
  links?: Links;
22
+ /**
23
+ * Optional map of resolved content references keyed by reference ID.
24
+ * Pass through to child components that consume referenced content.
25
+ */
9
26
  references?: References;
10
27
  };
28
+ /**
29
+ * Server-safe dynamic schema-to-component renderer for SSR and static-export environments.
30
+ *
31
+ * Equivalent to {@link LocalessComponent} but intentionally omits Visual Editor sync
32
+ * attribute injection (`localessEditable`), making it safe for:
33
+ * - Next.js static exports (`output: 'export'`)
34
+ * - Server-side rendering where live editing is not needed
35
+ *
36
+ * Looks up `data._schema` in the component registry, renders the matched component,
37
+ * falls back to the `fallbackComponent` if registered, or renders an inline error.
38
+ *
39
+ * **No `'use client'` directive** — safe to render in React Server Components.
40
+ * If you need live Visual Editor editing use {@link LocalessComponent} from
41
+ * `@localess/react` or `@localess/react/rsc` instead.
42
+ *
43
+ * @template T - The content data shape. Defaults to {@link ContentData}.
44
+ *
45
+ * @example
46
+ * ```tsx
47
+ * import { LocalessServerComponent } from '@localess/react/ssr';
48
+ *
49
+ * <LocalessServerComponent data={content.data} links={content.links} references={content.references} />
50
+ * ```
51
+ */
11
52
  declare const LocalessServerComponent: React.ForwardRefExoticComponent<LocalessServerComponentProps<ContentData> & React.RefAttributes<HTMLElement>>;
12
53
 
54
+ /**
55
+ * Props for {@link LocalessServerDocument}.
56
+ *
57
+ * @template T - The content data shape. Defaults to the base {@link ContentData} type.
58
+ */
13
59
  type LocalessServerDocumentProps<T extends ContentData = ContentData> = {
60
+ /**
61
+ * The full content response object as returned by `getContentBySlug` or `getContentById`.
62
+ * Must contain a `data` field with a valid `_schema` key.
63
+ */
14
64
  document: Content<T>;
15
65
  };
66
+ /**
67
+ * Server-safe document renderer for SSR and static-export environments.
68
+ *
69
+ * Accepts the full {@link Content} wrapper (as returned by `getContentBySlug` /
70
+ * `getContentById`) and delegates to {@link LocalessServerComponent}, automatically
71
+ * passing `data`, `links`, and `references` through.
72
+ *
73
+ * This is a convenience wrapper — use it when you want to render a fetched
74
+ * `Content<T>` object without manually destructuring it.
75
+ *
76
+ * **No live editing** — does not subscribe to Visual Editor sync events.
77
+ * For live Visual Editor editing use {@link LocalessDocument} from `@localess/react/rsc`.
78
+ *
79
+ * **No `'use client'` directive** — safe to render in React Server Components
80
+ * and Next.js static export pages.
81
+ *
82
+ * @template T - The content data shape. Defaults to {@link ContentData}.
83
+ *
84
+ * @example
85
+ * ```tsx
86
+ * import { LocalessServerDocument } from '@localess/react/ssr';
87
+ *
88
+ * // Server Component or getServerSideProps
89
+ * const content = await getLocalessClient().getContentBySlug<MyPage>('home', { locale: 'en' });
90
+ *
91
+ * return <LocalessServerDocument document={content} />;
92
+ * ```
93
+ */
16
94
  declare const LocalessServerDocument: React.ForwardRefExoticComponent<LocalessServerDocumentProps<ContentData> & React.RefAttributes<HTMLElement>>;
17
95
 
18
96
  export { LocalessServerComponent, type LocalessServerComponentProps, LocalessServerDocument, type LocalessServerDocumentProps };
package/dist/ssr.d.ts CHANGED
@@ -1,18 +1,96 @@
1
- export { L as LocalessOptions, f as findLink, g as getComponent, a as getFallbackComponent, b as getLocalessClient, 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, l as localessInit, r as registerComponent, c as renderRichTextToReact, d as resolveAsset, u as unregisterComponent } from './richtext-l2BRZFEP.js';
2
2
  import * as React from 'react';
3
3
  import { ContentData, Links, References, 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
5
 
6
+ /**
7
+ * Props for {@link LocalessServerComponent}.
8
+ *
9
+ * @template T - The content data shape. Defaults to the base {@link ContentData} type.
10
+ */
6
11
  type LocalessServerComponentProps<T extends ContentData = ContentData> = {
12
+ /**
13
+ * The content data object to render. Must have a `_schema` field that matches a key
14
+ * in the component registry configured via `localessInit`.
15
+ */
7
16
  data: T;
17
+ /**
18
+ * Optional map of content links keyed by link ID.
19
+ * Pass through to child components so they can resolve {@link ContentLink} values with `findLink`.
20
+ */
8
21
  links?: Links;
22
+ /**
23
+ * Optional map of resolved content references keyed by reference ID.
24
+ * Pass through to child components that consume referenced content.
25
+ */
9
26
  references?: References;
10
27
  };
28
+ /**
29
+ * Server-safe dynamic schema-to-component renderer for SSR and static-export environments.
30
+ *
31
+ * Equivalent to {@link LocalessComponent} but intentionally omits Visual Editor sync
32
+ * attribute injection (`localessEditable`), making it safe for:
33
+ * - Next.js static exports (`output: 'export'`)
34
+ * - Server-side rendering where live editing is not needed
35
+ *
36
+ * Looks up `data._schema` in the component registry, renders the matched component,
37
+ * falls back to the `fallbackComponent` if registered, or renders an inline error.
38
+ *
39
+ * **No `'use client'` directive** — safe to render in React Server Components.
40
+ * If you need live Visual Editor editing use {@link LocalessComponent} from
41
+ * `@localess/react` or `@localess/react/rsc` instead.
42
+ *
43
+ * @template T - The content data shape. Defaults to {@link ContentData}.
44
+ *
45
+ * @example
46
+ * ```tsx
47
+ * import { LocalessServerComponent } from '@localess/react/ssr';
48
+ *
49
+ * <LocalessServerComponent data={content.data} links={content.links} references={content.references} />
50
+ * ```
51
+ */
11
52
  declare const LocalessServerComponent: React.ForwardRefExoticComponent<LocalessServerComponentProps<ContentData> & React.RefAttributes<HTMLElement>>;
12
53
 
54
+ /**
55
+ * Props for {@link LocalessServerDocument}.
56
+ *
57
+ * @template T - The content data shape. Defaults to the base {@link ContentData} type.
58
+ */
13
59
  type LocalessServerDocumentProps<T extends ContentData = ContentData> = {
60
+ /**
61
+ * The full content response object as returned by `getContentBySlug` or `getContentById`.
62
+ * Must contain a `data` field with a valid `_schema` key.
63
+ */
14
64
  document: Content<T>;
15
65
  };
66
+ /**
67
+ * Server-safe document renderer for SSR and static-export environments.
68
+ *
69
+ * Accepts the full {@link Content} wrapper (as returned by `getContentBySlug` /
70
+ * `getContentById`) and delegates to {@link LocalessServerComponent}, automatically
71
+ * passing `data`, `links`, and `references` through.
72
+ *
73
+ * This is a convenience wrapper — use it when you want to render a fetched
74
+ * `Content<T>` object without manually destructuring it.
75
+ *
76
+ * **No live editing** — does not subscribe to Visual Editor sync events.
77
+ * For live Visual Editor editing use {@link LocalessDocument} from `@localess/react/rsc`.
78
+ *
79
+ * **No `'use client'` directive** — safe to render in React Server Components
80
+ * and Next.js static export pages.
81
+ *
82
+ * @template T - The content data shape. Defaults to {@link ContentData}.
83
+ *
84
+ * @example
85
+ * ```tsx
86
+ * import { LocalessServerDocument } from '@localess/react/ssr';
87
+ *
88
+ * // Server Component or getServerSideProps
89
+ * const content = await getLocalessClient().getContentBySlug<MyPage>('home', { locale: 'en' });
90
+ *
91
+ * return <LocalessServerDocument document={content} />;
92
+ * ```
93
+ */
16
94
  declare const LocalessServerDocument: React.ForwardRefExoticComponent<LocalessServerDocumentProps<ContentData> & React.RefAttributes<HTMLElement>>;
17
95
 
18
96
  export { LocalessServerComponent, type LocalessServerComponentProps, LocalessServerDocument, type LocalessServerDocumentProps };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@localess/react",
3
- "version": "3.0.1-dev.20260410065141",
3
+ "version": "3.0.1-dev.20260410071322",
4
4
  "description": "ReactJS JavaScript/TypeScript SDK for Localess's API.",
5
5
  "keywords": [
6
6
  "localess",
@@ -56,7 +56,7 @@
56
56
  "react-dom": "^17 || ^18 || ^19"
57
57
  },
58
58
  "dependencies": {
59
- "@localess/client": "3.0.1-dev.20260410065141",
59
+ "@localess/client": "3.0.1-dev.20260410071322",
60
60
  "@tiptap/static-renderer": "^3.20.1",
61
61
  "@tiptap/html": "^3.20.1",
62
62
  "@tiptap/extension-bold": "^3.20.1",
@@ -1,82 +0,0 @@
1
- import React__default from 'react';
2
- import { LocalessClientOptions, LocalessClient, ContentAsset, Links, ContentLink, ContentRichText } from '@localess/client';
3
-
4
- type LocalessOptions = LocalessClientOptions & {
5
- /**
6
- * Components mapping for Localess Component integration
7
- */
8
- components?: Record<string, React__default.ElementType>;
9
- /**
10
- * Component used if expected key didn't return anything
11
- */
12
- fallbackComponent?: React__default.ElementType;
13
- /**
14
- * Load Sync Script, for Visual Editor integration
15
- */
16
- enableSync?: boolean;
17
- };
18
-
19
- /**
20
- * Initialize Localess Client
21
- * @param options
22
- * @returns LocalessClient
23
- */
24
- declare function localessInit(options: LocalessOptions): LocalessClient;
25
- /**
26
- * Get Localess Client
27
- * @returns LocalessClient
28
- */
29
- declare function getLocalessClient(): LocalessClient;
30
- /**
31
- * Register Component
32
- * @param key - component key
33
- * @param component - React Component
34
- */
35
- declare function registerComponent(key: string, component: React__default.ElementType): void;
36
- /**
37
- * Unregister Component
38
- * @param key - component key
39
- */
40
- declare function unregisterComponent(key: string): void;
41
- /**
42
- * Set Components
43
- * @param components - Record of components
44
- */
45
- declare function setComponents(components: Record<string, React__default.ElementType>): void;
46
- /**
47
- * Get Component
48
- * @param key - component key
49
- * @returns React Component
50
- */
51
- declare function getComponent(key: string): React__default.ElementType | undefined;
52
- /**
53
- * Set Fallback Component
54
- * @param fallbackComponent
55
- */
56
- declare function setFallbackComponent(fallbackComponent: React__default.ElementType): void;
57
- /**
58
- * Get Fallback Component
59
- * @returns React Component
60
- */
61
- declare function getFallbackComponent(): React__default.ElementType | undefined;
62
- /**
63
- * Check if Sync is enabled
64
- */
65
- declare function isSyncEnabled(): boolean;
66
- /**
67
- * Resolve Asset URL
68
- * @param asset - ContentAsset
69
- * @returns Asset URL
70
- */
71
- declare function resolveAsset(asset: ContentAsset): string;
72
-
73
- declare function findLink(links: Links | undefined, link: ContentLink): string;
74
-
75
- /**
76
- * Render Localess Rich Text content to React elements
77
- * @param content - The Rich Text content to render
78
- * @returns React.ReactNode - The rendered React elements
79
- */
80
- declare function renderRichTextToReact(content: ContentRichText): React__default.ReactNode;
81
-
82
- 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 };
@@ -1,82 +0,0 @@
1
- import React__default from 'react';
2
- import { LocalessClientOptions, LocalessClient, ContentAsset, Links, ContentLink, ContentRichText } from '@localess/client';
3
-
4
- type LocalessOptions = LocalessClientOptions & {
5
- /**
6
- * Components mapping for Localess Component integration
7
- */
8
- components?: Record<string, React__default.ElementType>;
9
- /**
10
- * Component used if expected key didn't return anything
11
- */
12
- fallbackComponent?: React__default.ElementType;
13
- /**
14
- * Load Sync Script, for Visual Editor integration
15
- */
16
- enableSync?: boolean;
17
- };
18
-
19
- /**
20
- * Initialize Localess Client
21
- * @param options
22
- * @returns LocalessClient
23
- */
24
- declare function localessInit(options: LocalessOptions): LocalessClient;
25
- /**
26
- * Get Localess Client
27
- * @returns LocalessClient
28
- */
29
- declare function getLocalessClient(): LocalessClient;
30
- /**
31
- * Register Component
32
- * @param key - component key
33
- * @param component - React Component
34
- */
35
- declare function registerComponent(key: string, component: React__default.ElementType): void;
36
- /**
37
- * Unregister Component
38
- * @param key - component key
39
- */
40
- declare function unregisterComponent(key: string): void;
41
- /**
42
- * Set Components
43
- * @param components - Record of components
44
- */
45
- declare function setComponents(components: Record<string, React__default.ElementType>): void;
46
- /**
47
- * Get Component
48
- * @param key - component key
49
- * @returns React Component
50
- */
51
- declare function getComponent(key: string): React__default.ElementType | undefined;
52
- /**
53
- * Set Fallback Component
54
- * @param fallbackComponent
55
- */
56
- declare function setFallbackComponent(fallbackComponent: React__default.ElementType): void;
57
- /**
58
- * Get Fallback Component
59
- * @returns React Component
60
- */
61
- declare function getFallbackComponent(): React__default.ElementType | undefined;
62
- /**
63
- * Check if Sync is enabled
64
- */
65
- declare function isSyncEnabled(): boolean;
66
- /**
67
- * Resolve Asset URL
68
- * @param asset - ContentAsset
69
- * @returns Asset URL
70
- */
71
- declare function resolveAsset(asset: ContentAsset): string;
72
-
73
- declare function findLink(links: Links | undefined, link: ContentLink): string;
74
-
75
- /**
76
- * Render Localess Rich Text content to React elements
77
- * @param content - The Rich Text content to render
78
- * @returns React.ReactNode - The rendered React elements
79
- */
80
- declare function renderRichTextToReact(content: ContentRichText): React__default.ReactNode;
81
-
82
- 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 };