@localess/react 3.0.1-dev.20260405190914 → 3.0.1-dev.20260408172608
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +99 -25
- package/SKILL.md +91 -46
- package/dist/index.d.mts +13 -10
- package/dist/index.d.ts +13 -10
- package/dist/index.js +120 -89
- package/dist/index.mjs +112 -82
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -249,40 +249,92 @@ const Image = ({ data }) => (
|
|
|
249
249
|
|
|
250
250
|
---
|
|
251
251
|
|
|
252
|
+
## `useLocaless` Hook
|
|
253
|
+
|
|
254
|
+
`useLocaless<T>` fetches content by slug in a Client Component and automatically subscribes to Visual Editor live updates when `enableSync` is active.
|
|
255
|
+
|
|
256
|
+
```tsx
|
|
257
|
+
'use client';
|
|
258
|
+
|
|
259
|
+
import { useLocaless, LocalessComponent } from "@localess/react";
|
|
260
|
+
import type { Page } from "./.localess/localess";
|
|
261
|
+
|
|
262
|
+
export function PageView({ slug }: { slug: string }) {
|
|
263
|
+
const content = useLocaless<Page>(slug, { locale: 'en' });
|
|
264
|
+
|
|
265
|
+
if (!content) return <div>Loading…</div>;
|
|
266
|
+
|
|
267
|
+
return (
|
|
268
|
+
<main>
|
|
269
|
+
{content.data.body.map(item => (
|
|
270
|
+
<LocalessComponent key={item._id} data={item} links={content.links} />
|
|
271
|
+
))}
|
|
272
|
+
</main>
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Parameters
|
|
278
|
+
|
|
279
|
+
| Parameter | Type | Required | Description |
|
|
280
|
+
|-----------|------|----------|-------------|
|
|
281
|
+
| `slug` | `string \| string[]` | ✅ | Content slug. Arrays are joined with `/` — e.g. `['blog', 'post']` → `'blog/post'` |
|
|
282
|
+
| `options` | `ContentFetchParams` | ❌ | Same fetch options as `getContentBySlug` (locale, version, resolveReference, resolveLink) |
|
|
283
|
+
|
|
284
|
+
Returns `Content<T> | undefined` — `undefined` while the initial fetch is in progress.
|
|
285
|
+
|
|
286
|
+
When `enableSync` is active and the page is rendered inside the Localess Visual Editor iframe, the hook automatically subscribes to `input` / `change` events and updates the returned content in place.
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## Link Utilities
|
|
291
|
+
|
|
292
|
+
### `findLink(links, link)`
|
|
293
|
+
|
|
294
|
+
Resolves a `ContentLink` field to a URL string. Use it to build `href` values from Localess content links.
|
|
295
|
+
|
|
296
|
+
```tsx
|
|
297
|
+
import { findLink } from "@localess/react";
|
|
298
|
+
|
|
299
|
+
// type: 'content' → '/' + fullSlug, or '/not-found' if not in map
|
|
300
|
+
// type: 'url' → raw URI unchanged
|
|
301
|
+
const href = findLink(content.links, data.ctaLink);
|
|
302
|
+
|
|
303
|
+
const NavLink = ({ data, links }) => (
|
|
304
|
+
<a href={findLink(links, data.link)}>{data.label}</a>
|
|
305
|
+
);
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
---
|
|
309
|
+
|
|
252
310
|
## Visual Editor Events
|
|
253
311
|
|
|
254
|
-
When
|
|
312
|
+
When `enableSync: true` is set in `localessInit`, Visual Editor live-editing is handled **automatically** by the `useLocaless` hook — no manual event wiring needed.
|
|
255
313
|
|
|
256
314
|
```tsx
|
|
257
315
|
'use client';
|
|
258
316
|
|
|
259
|
-
import {
|
|
260
|
-
import {
|
|
261
|
-
import type { Content } from "@localess/react";
|
|
317
|
+
import { useLocaless, LocalessComponent, localessEditable } from "@localess/react";
|
|
318
|
+
import type { Page } from "./.localess/localess";
|
|
262
319
|
|
|
263
|
-
export function
|
|
264
|
-
|
|
320
|
+
export function PageView({ slug, locale }: { slug: string; locale?: string }) {
|
|
321
|
+
// Automatically subscribes to Visual Editor input/change events when enableSync is active
|
|
322
|
+
const content = useLocaless<Page>(slug, { locale });
|
|
265
323
|
|
|
266
|
-
|
|
267
|
-
if (window.localess) {
|
|
268
|
-
window.localess.on(['input', 'change'], (event) => {
|
|
269
|
-
if (event.type === 'input' || event.type === 'change') {
|
|
270
|
-
setPageData(event.data);
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
}, []);
|
|
324
|
+
if (!content) return null;
|
|
275
325
|
|
|
276
326
|
return (
|
|
277
|
-
<main {...localessEditable(
|
|
278
|
-
{
|
|
279
|
-
<LocalessComponent key={item._id} data={item} />
|
|
327
|
+
<main {...localessEditable(content.data)}>
|
|
328
|
+
{content.data?.body.map(item => (
|
|
329
|
+
<LocalessComponent key={item._id} data={item} links={content.links} references={content.references} />
|
|
280
330
|
))}
|
|
281
331
|
</main>
|
|
282
332
|
);
|
|
283
333
|
}
|
|
284
334
|
```
|
|
285
335
|
|
|
336
|
+
> `useLocaless` handles the full cycle: initial fetch + live sync updates when inside the editor iframe.
|
|
337
|
+
|
|
286
338
|
---
|
|
287
339
|
|
|
288
340
|
## Full Example (Next.js 15 App Router)
|
|
@@ -296,7 +348,7 @@ localessInit({
|
|
|
296
348
|
origin: process.env.LOCALESS_ORIGIN!,
|
|
297
349
|
spaceId: process.env.LOCALESS_SPACE_ID!,
|
|
298
350
|
token: process.env.LOCALESS_TOKEN!,
|
|
299
|
-
enableSync: process.env.NODE_ENV
|
|
351
|
+
enableSync: process.env.NODE_ENV !== 'production',
|
|
300
352
|
components: { Page, Header, Teaser, Footer },
|
|
301
353
|
});
|
|
302
354
|
|
|
@@ -306,19 +358,41 @@ export default function RootLayout({ children }) {
|
|
|
306
358
|
```
|
|
307
359
|
|
|
308
360
|
```tsx
|
|
309
|
-
// app/page.tsx (Server Component)
|
|
310
|
-
import { getLocalessClient
|
|
361
|
+
// app/[locale]/page.tsx (Server Component — fetches initial data)
|
|
362
|
+
import { getLocalessClient } from "@localess/react";
|
|
363
|
+
import { PageClient } from "./page-client";
|
|
311
364
|
import type { Page } from "./.localess/localess";
|
|
312
365
|
|
|
313
366
|
export default async function HomePage({
|
|
314
|
-
|
|
367
|
+
params,
|
|
315
368
|
}: {
|
|
316
|
-
|
|
369
|
+
params: Promise<{ locale?: string }>;
|
|
317
370
|
}) {
|
|
318
|
-
const { locale } = await
|
|
371
|
+
const { locale } = await params;
|
|
319
372
|
const client = getLocalessClient();
|
|
320
373
|
const content = await client.getContentBySlug<Page>('home', { locale });
|
|
321
374
|
|
|
375
|
+
return <PageClient initialContent={content} locale={locale} />;
|
|
376
|
+
}
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
```tsx
|
|
380
|
+
// app/[locale]/page-client.tsx (Client Component — renders + auto-syncs with Visual Editor)
|
|
381
|
+
'use client';
|
|
382
|
+
|
|
383
|
+
import { useLocaless, LocalessComponent, localessEditable } from "@localess/react";
|
|
384
|
+
import type { Content, Page } from "./.localess/localess";
|
|
385
|
+
|
|
386
|
+
export function PageClient({
|
|
387
|
+
initialContent,
|
|
388
|
+
locale,
|
|
389
|
+
}: {
|
|
390
|
+
initialContent: Content<Page>;
|
|
391
|
+
locale?: string;
|
|
392
|
+
}) {
|
|
393
|
+
// Handles initial fetch and Visual Editor live updates automatically
|
|
394
|
+
const content = useLocaless<Page>('home', { locale }) ?? initialContent;
|
|
395
|
+
|
|
322
396
|
return (
|
|
323
397
|
<main {...localessEditable(content.data)}>
|
|
324
398
|
{content.data?.body.map(item => (
|
|
@@ -342,7 +416,7 @@ The following are re-exported for convenience so you only need to import from `@
|
|
|
342
416
|
|
|
343
417
|
**Types:** `Content`, `ContentData`, `ContentMetadata`, `ContentDataSchema`, `ContentDataField`, `ContentAsset`, `ContentRichText`, `ContentLink`, `ContentReference`, `Links`, `References`, `Translations`, `LocalessClient`, `LocalessSync`, `EventToApp`, `EventCallback`, `EventToAppType`
|
|
344
418
|
|
|
345
|
-
**Functions:** `localessEditable`, `localessEditableField`, `llEditable` *(deprecated)*, `llEditableField` *(deprecated)*, `isBrowser`, `isServer`, `isIframe`
|
|
419
|
+
**Functions:** `localessEditable`, `localessEditableField`, `llEditable` *(deprecated)*, `llEditableField` *(deprecated)*, `isBrowser`, `isServer`, `isIframe`, `resolveAsset`, `findLink`, `useLocaless`, `renderRichTextToReact`, `localessInit`, `getLocalessClient`, `registerComponent`, `unregisterComponent`, `setComponents`, `getComponent`, `setFallbackComponent`, `getFallbackComponent`, `isSyncEnabled`
|
|
346
420
|
|
|
347
421
|
---
|
|
348
422
|
|
package/SKILL.md
CHANGED
|
@@ -176,37 +176,26 @@ localessInit({
|
|
|
176
176
|
|
|
177
177
|
### Receiving Real-time Editor Events
|
|
178
178
|
|
|
179
|
-
|
|
179
|
+
Use the `useLocaless` hook in a Client Component — it **automatically subscribes** to `input` / `change` events when `enableSync` is active. No manual `window.localess.on()` wiring needed.
|
|
180
180
|
|
|
181
181
|
```tsx
|
|
182
182
|
'use client';
|
|
183
183
|
|
|
184
|
-
import {
|
|
185
|
-
import { LocalessComponent, localessEditable } from "@localess/react";
|
|
184
|
+
import { useLocaless, LocalessComponent, localessEditable } from "@localess/react";
|
|
186
185
|
import type { Content, Page } from "./.localess/localess";
|
|
187
186
|
|
|
188
|
-
export function PageClient({ initialContent }: { initialContent: Content<Page
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
useEffect(() => {
|
|
192
|
-
if (window.localess) {
|
|
193
|
-
window.localess.on(['input', 'change'], (event) => {
|
|
194
|
-
if (event.type === 'input' || event.type === 'change') {
|
|
195
|
-
setPageData(event.data);
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
// No cleanup needed: window.localess has no .off() method
|
|
200
|
-
}, []);
|
|
187
|
+
export function PageClient({ initialContent, locale }: { initialContent: Content<Page>; locale?: string }) {
|
|
188
|
+
// Fetches content and auto-syncs with Visual Editor live updates
|
|
189
|
+
const content = useLocaless<Page>('home', { locale }) ?? initialContent;
|
|
201
190
|
|
|
202
191
|
return (
|
|
203
|
-
<main {...localessEditable(
|
|
204
|
-
{
|
|
192
|
+
<main {...localessEditable(content.data)}>
|
|
193
|
+
{content.data?.body?.map(item => (
|
|
205
194
|
<LocalessComponent
|
|
206
195
|
key={item._id}
|
|
207
196
|
data={item}
|
|
208
|
-
links={
|
|
209
|
-
references={
|
|
197
|
+
links={content.links}
|
|
198
|
+
references={content.references}
|
|
210
199
|
/>
|
|
211
200
|
))}
|
|
212
201
|
</main>
|
|
@@ -214,7 +203,7 @@ export function PageClient({ initialContent }: { initialContent: Content<Page> }
|
|
|
214
203
|
}
|
|
215
204
|
```
|
|
216
205
|
|
|
217
|
-
**Available events
|
|
206
|
+
**Available events (handled internally by `useLocaless`):**
|
|
218
207
|
|
|
219
208
|
| Event | When |
|
|
220
209
|
|---------------|-----------------------------------------------|
|
|
@@ -230,56 +219,45 @@ export function PageClient({ initialContent }: { initialContent: Content<Page> }
|
|
|
230
219
|
|
|
231
220
|
### Pattern: Split Server/Client Components (Next.js App Router)
|
|
232
221
|
|
|
233
|
-
|
|
222
|
+
Keep data fetching server-side and delegate rendering + sync to a Client Component using `useLocaless`:
|
|
234
223
|
|
|
235
224
|
```tsx
|
|
236
|
-
// app/[locale]/page.tsx — Server Component: fetches data
|
|
225
|
+
// app/[locale]/page.tsx — Server Component: fetches initial data
|
|
237
226
|
import { getLocalessClient } from "@localess/react";
|
|
238
227
|
import { PageClient } from "./page-client";
|
|
239
228
|
import type { Page } from "./.localess/localess";
|
|
240
229
|
|
|
241
230
|
export default async function HomePage({
|
|
242
|
-
|
|
231
|
+
params,
|
|
243
232
|
}: {
|
|
244
|
-
|
|
233
|
+
params: Promise<{ locale?: string }>;
|
|
245
234
|
}) {
|
|
246
|
-
const { locale } = await
|
|
235
|
+
const { locale } = await params;
|
|
247
236
|
const client = getLocalessClient();
|
|
248
237
|
const content = await client.getContentBySlug<Page>('home', { locale });
|
|
249
238
|
|
|
250
|
-
return <PageClient initialContent={content} />;
|
|
239
|
+
return <PageClient initialContent={content} locale={locale} />;
|
|
251
240
|
}
|
|
252
241
|
```
|
|
253
242
|
|
|
254
243
|
```tsx
|
|
255
|
-
// app/[locale]/page-client.tsx — Client Component: renders +
|
|
244
|
+
// app/[locale]/page-client.tsx — Client Component: renders + auto-syncs
|
|
256
245
|
'use client';
|
|
257
246
|
|
|
258
|
-
import {
|
|
259
|
-
import { LocalessComponent, localessEditable } from "@localess/react";
|
|
247
|
+
import { useLocaless, LocalessComponent, localessEditable } from "@localess/react";
|
|
260
248
|
import type { Content, Page } from "./.localess/localess";
|
|
261
249
|
|
|
262
|
-
export function PageClient({ initialContent }: { initialContent: Content<Page
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
useEffect(() => {
|
|
266
|
-
if (window.localess) {
|
|
267
|
-
window.localess.on(['input', 'change'], (event) => {
|
|
268
|
-
if (event.type === 'input' || event.type === 'change') {
|
|
269
|
-
setPageData(event.data);
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
}, []);
|
|
250
|
+
export function PageClient({ initialContent, locale }: { initialContent: Content<Page>; locale?: string }) {
|
|
251
|
+
const content = useLocaless<Page>('home', { locale }) ?? initialContent;
|
|
274
252
|
|
|
275
253
|
return (
|
|
276
|
-
<main {...localessEditable(
|
|
277
|
-
{
|
|
254
|
+
<main {...localessEditable(content.data)}>
|
|
255
|
+
{content.data?.body?.map(item => (
|
|
278
256
|
<LocalessComponent
|
|
279
257
|
key={item._id}
|
|
280
258
|
data={item}
|
|
281
|
-
links={
|
|
282
|
-
references={
|
|
259
|
+
links={content.links}
|
|
260
|
+
references={content.references}
|
|
283
261
|
/>
|
|
284
262
|
))}
|
|
285
263
|
</main>
|
|
@@ -289,6 +267,67 @@ export function PageClient({ initialContent }: { initialContent: Content<Page> }
|
|
|
289
267
|
|
|
290
268
|
---
|
|
291
269
|
|
|
270
|
+
## `useLocaless` Hook
|
|
271
|
+
|
|
272
|
+
`useLocaless<T>` fetches content by slug on the client side and automatically wires up Visual Editor live updates when `enableSync` is active.
|
|
273
|
+
|
|
274
|
+
```tsx
|
|
275
|
+
'use client';
|
|
276
|
+
|
|
277
|
+
import { useLocaless } from "@localess/react";
|
|
278
|
+
import type { Page } from "./.localess/localess";
|
|
279
|
+
|
|
280
|
+
export function PageView({ slug }: { slug: string }) {
|
|
281
|
+
const content = useLocaless<Page>(slug, { locale: 'en' });
|
|
282
|
+
|
|
283
|
+
if (!content) return <div>Loading…</div>;
|
|
284
|
+
|
|
285
|
+
return (
|
|
286
|
+
<main>
|
|
287
|
+
{content.data.body.map(item => (
|
|
288
|
+
<LocalessComponent key={item._id} data={item} links={content.links} />
|
|
289
|
+
))}
|
|
290
|
+
</main>
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### Signature
|
|
296
|
+
|
|
297
|
+
```typescript
|
|
298
|
+
useLocaless<T extends ContentData = ContentData>(
|
|
299
|
+
slug: string | string[], // string[] is joined with '/' — e.g. ['blog', 'post'] → 'blog/post'
|
|
300
|
+
options?: ContentFetchParams
|
|
301
|
+
): Content<T> | undefined
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
- Returns `undefined` while the initial fetch is in flight.
|
|
305
|
+
- When `enableSync` is active and the page is inside the Localess Visual Editor, automatically subscribes to `input` / `change` events and updates the returned value in place.
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
## Link Utilities
|
|
310
|
+
|
|
311
|
+
### `findLink(links, link)`
|
|
312
|
+
|
|
313
|
+
Resolves a `ContentLink` to a URL string. Use this to convert link fields from Localess content into href values.
|
|
314
|
+
|
|
315
|
+
```typescript
|
|
316
|
+
import { findLink } from "@localess/react";
|
|
317
|
+
|
|
318
|
+
const href = findLink(content.links, data.ctaLink);
|
|
319
|
+
// type: 'content' → '/' + fullSlug (e.g. '/blog/my-post'), or '/not-found' if not in links map
|
|
320
|
+
// type: 'url' → raw URI (e.g. 'https://example.com')
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
```tsx
|
|
324
|
+
const NavLink = ({ data, links }) => (
|
|
325
|
+
<a href={findLink(links, data.link)}>{data.label}</a>
|
|
326
|
+
);
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
---
|
|
330
|
+
|
|
292
331
|
## Rich Text Rendering
|
|
293
332
|
|
|
294
333
|
Converts Localess `ContentRichText` (Tiptap JSON) to a React node tree.
|
|
@@ -440,6 +479,12 @@ export { LocalessComponent } // Dynamic schema-to-component renderer
|
|
|
440
479
|
export { renderRichTextToReact } // Rich text → React nodes
|
|
441
480
|
export { resolveAsset } // ContentAsset → full URL
|
|
442
481
|
|
|
482
|
+
// Hooks
|
|
483
|
+
export { useLocaless } // Client-side content fetching with sync support
|
|
484
|
+
|
|
485
|
+
// Utilities
|
|
486
|
+
export { findLink } // ContentLink → URL string
|
|
487
|
+
|
|
443
488
|
// Visual editor (re-exported from @localess/client)
|
|
444
489
|
export { localessEditable, localessEditableField }
|
|
445
490
|
export { llEditable, llEditableField } // Deprecated
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
import { ContentData, Links, References, LocalessClientOptions, ContentFetchParams, Content, ContentLink, ContentRichText, LocalessClient, ContentAsset } from '@localess/client';
|
|
2
|
+
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';
|
|
1
3
|
import * as React from 'react';
|
|
2
4
|
import React__default from 'react';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
|
|
6
|
+
type LocalessComponentProps<T extends ContentData = ContentData> = {
|
|
7
|
+
data: T;
|
|
8
|
+
links?: Links;
|
|
9
|
+
references?: References;
|
|
10
|
+
};
|
|
11
|
+
declare const LocalessComponent: React.ForwardRefExoticComponent<LocalessComponentProps<ContentData> & React.RefAttributes<HTMLElement>>;
|
|
5
12
|
|
|
6
13
|
type LocalessOptions = LocalessClientOptions & {
|
|
7
14
|
/**
|
|
@@ -18,14 +25,10 @@ type LocalessOptions = LocalessClientOptions & {
|
|
|
18
25
|
enableSync?: boolean;
|
|
19
26
|
};
|
|
20
27
|
|
|
21
|
-
|
|
28
|
+
type UseLocalessOptions = ContentFetchParams & {};
|
|
29
|
+
declare const useLocaless: <T extends ContentData = ContentData>(slug: string | string[], options?: UseLocalessOptions) => Content<T> | undefined;
|
|
22
30
|
|
|
23
|
-
|
|
24
|
-
data: T;
|
|
25
|
-
links?: Links;
|
|
26
|
-
references?: References;
|
|
27
|
-
};
|
|
28
|
-
declare const LocalessComponent: React.ForwardRefExoticComponent<LocalessComponentProps<ContentData> & React.RefAttributes<HTMLElement>>;
|
|
31
|
+
declare function findLink(links: Links | undefined, link: ContentLink): string;
|
|
29
32
|
|
|
30
33
|
/**
|
|
31
34
|
* Render Localess Rich Text content to React elements
|
|
@@ -88,4 +91,4 @@ declare function isSyncEnabled(): boolean;
|
|
|
88
91
|
*/
|
|
89
92
|
declare function resolveAsset(asset: ContentAsset): string;
|
|
90
93
|
|
|
91
|
-
export { LocalessComponent, type LocalessComponentProps, type LocalessOptions, findLink, getComponent, getFallbackComponent, getLocalessClient, isSyncEnabled, localessInit, registerComponent, renderRichTextToReact, resolveAsset, setComponents, setFallbackComponent, unregisterComponent };
|
|
94
|
+
export { LocalessComponent, type LocalessComponentProps, type LocalessOptions, type UseLocalessOptions, findLink, getComponent, getFallbackComponent, getLocalessClient, isSyncEnabled, localessInit, registerComponent, renderRichTextToReact, resolveAsset, setComponents, setFallbackComponent, unregisterComponent, useLocaless };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
import { ContentData, Links, References, LocalessClientOptions, ContentFetchParams, Content, ContentLink, ContentRichText, LocalessClient, ContentAsset } from '@localess/client';
|
|
2
|
+
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';
|
|
1
3
|
import * as React from 'react';
|
|
2
4
|
import React__default from 'react';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
|
|
6
|
+
type LocalessComponentProps<T extends ContentData = ContentData> = {
|
|
7
|
+
data: T;
|
|
8
|
+
links?: Links;
|
|
9
|
+
references?: References;
|
|
10
|
+
};
|
|
11
|
+
declare const LocalessComponent: React.ForwardRefExoticComponent<LocalessComponentProps<ContentData> & React.RefAttributes<HTMLElement>>;
|
|
5
12
|
|
|
6
13
|
type LocalessOptions = LocalessClientOptions & {
|
|
7
14
|
/**
|
|
@@ -18,14 +25,10 @@ type LocalessOptions = LocalessClientOptions & {
|
|
|
18
25
|
enableSync?: boolean;
|
|
19
26
|
};
|
|
20
27
|
|
|
21
|
-
|
|
28
|
+
type UseLocalessOptions = ContentFetchParams & {};
|
|
29
|
+
declare const useLocaless: <T extends ContentData = ContentData>(slug: string | string[], options?: UseLocalessOptions) => Content<T> | undefined;
|
|
22
30
|
|
|
23
|
-
|
|
24
|
-
data: T;
|
|
25
|
-
links?: Links;
|
|
26
|
-
references?: References;
|
|
27
|
-
};
|
|
28
|
-
declare const LocalessComponent: React.ForwardRefExoticComponent<LocalessComponentProps<ContentData> & React.RefAttributes<HTMLElement>>;
|
|
31
|
+
declare function findLink(links: Links | undefined, link: ContentLink): string;
|
|
29
32
|
|
|
30
33
|
/**
|
|
31
34
|
* Render Localess Rich Text content to React elements
|
|
@@ -88,4 +91,4 @@ declare function isSyncEnabled(): boolean;
|
|
|
88
91
|
*/
|
|
89
92
|
declare function resolveAsset(asset: ContentAsset): string;
|
|
90
93
|
|
|
91
|
-
export { LocalessComponent, type LocalessComponentProps, type LocalessOptions, findLink, getComponent, getFallbackComponent, getLocalessClient, isSyncEnabled, localessInit, registerComponent, renderRichTextToReact, resolveAsset, setComponents, setFallbackComponent, unregisterComponent };
|
|
94
|
+
export { LocalessComponent, type LocalessComponentProps, type LocalessOptions, type UseLocalessOptions, findLink, getComponent, getFallbackComponent, getLocalessClient, isSyncEnabled, localessInit, registerComponent, renderRichTextToReact, resolveAsset, setComponents, setFallbackComponent, unregisterComponent, useLocaless };
|
package/dist/index.js
CHANGED
|
@@ -25,54 +25,89 @@ __export(index_exports, {
|
|
|
25
25
|
getComponent: () => getComponent,
|
|
26
26
|
getFallbackComponent: () => getFallbackComponent,
|
|
27
27
|
getLocalessClient: () => getLocalessClient,
|
|
28
|
-
isBrowser: () =>
|
|
29
|
-
isIframe: () =>
|
|
30
|
-
isServer: () =>
|
|
28
|
+
isBrowser: () => import_client4.isBrowser,
|
|
29
|
+
isIframe: () => import_client4.isIframe,
|
|
30
|
+
isServer: () => import_client4.isServer,
|
|
31
31
|
isSyncEnabled: () => isSyncEnabled,
|
|
32
|
-
localessEditable: () =>
|
|
33
|
-
localessEditableField: () =>
|
|
32
|
+
localessEditable: () => import_client4.localessEditable,
|
|
33
|
+
localessEditableField: () => import_client4.localessEditableField,
|
|
34
34
|
localessInit: () => localessInit,
|
|
35
35
|
registerComponent: () => registerComponent,
|
|
36
36
|
renderRichTextToReact: () => renderRichTextToReact,
|
|
37
37
|
resolveAsset: () => resolveAsset,
|
|
38
38
|
setComponents: () => setComponents,
|
|
39
39
|
setFallbackComponent: () => setFallbackComponent,
|
|
40
|
-
unregisterComponent: () => unregisterComponent
|
|
40
|
+
unregisterComponent: () => unregisterComponent,
|
|
41
|
+
useLocaless: () => useLocaless
|
|
41
42
|
});
|
|
42
43
|
module.exports = __toCommonJS(index_exports);
|
|
44
|
+
var import_client4 = require("@localess/client");
|
|
45
|
+
|
|
46
|
+
// src/components/localess-component.tsx
|
|
47
|
+
var import_react = require("react");
|
|
43
48
|
var import_client2 = require("@localess/client");
|
|
44
49
|
|
|
45
50
|
// src/console.ts
|
|
46
51
|
var FONT_BOLD = "font-weight: bold";
|
|
47
52
|
var FONT_NORMAL = "font-weight: normal";
|
|
48
53
|
|
|
49
|
-
// src/
|
|
50
|
-
var
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
54
|
+
// src/state.ts
|
|
55
|
+
var import_client = require("@localess/client");
|
|
56
|
+
var _client = void 0;
|
|
57
|
+
var _components = {};
|
|
58
|
+
var _fallbackComponent = void 0;
|
|
59
|
+
var _enableSync = false;
|
|
60
|
+
var _assetPathPrefix = "";
|
|
61
|
+
function localessInit(options) {
|
|
62
|
+
console.log("localessInit", options);
|
|
63
|
+
const { components, fallbackComponent, enableSync, ...restOptions } = options;
|
|
64
|
+
_client = (0, import_client.localessClient)(restOptions);
|
|
65
|
+
_assetPathPrefix = `${options.origin}/api/v1/spaces/${options.spaceId}/assets/`;
|
|
66
|
+
_components = components || {};
|
|
67
|
+
_fallbackComponent = fallbackComponent;
|
|
68
|
+
if (enableSync) {
|
|
69
|
+
_enableSync = true;
|
|
70
|
+
(0, import_client.loadLocalessSync)(restOptions.origin);
|
|
71
|
+
}
|
|
72
|
+
return _client;
|
|
73
|
+
}
|
|
74
|
+
function getLocalessClient() {
|
|
75
|
+
if (!_client) {
|
|
76
|
+
console.error("[Localess] No client found. Please check if the Localess is initialized.");
|
|
77
|
+
throw new Error("[Localess] No client found.");
|
|
70
78
|
}
|
|
79
|
+
return _client;
|
|
80
|
+
}
|
|
81
|
+
function registerComponent(key, component) {
|
|
82
|
+
_components[key] = component;
|
|
83
|
+
}
|
|
84
|
+
function unregisterComponent(key) {
|
|
85
|
+
delete _components[key];
|
|
86
|
+
}
|
|
87
|
+
function setComponents(components) {
|
|
88
|
+
_components = components;
|
|
89
|
+
}
|
|
90
|
+
function getComponent(key) {
|
|
91
|
+
if (Object.hasOwn(_components, key)) {
|
|
92
|
+
return _components[key];
|
|
93
|
+
}
|
|
94
|
+
console.error(`[Localess] component %c${key}%c can't be found.`, FONT_BOLD, FONT_NORMAL);
|
|
95
|
+
return void 0;
|
|
96
|
+
}
|
|
97
|
+
function setFallbackComponent(fallbackComponent) {
|
|
98
|
+
_fallbackComponent = fallbackComponent;
|
|
99
|
+
}
|
|
100
|
+
function getFallbackComponent() {
|
|
101
|
+
return _fallbackComponent;
|
|
102
|
+
}
|
|
103
|
+
function isSyncEnabled() {
|
|
104
|
+
return _enableSync;
|
|
105
|
+
}
|
|
106
|
+
function resolveAsset(asset) {
|
|
107
|
+
return `${_assetPathPrefix}${asset.uri}`;
|
|
71
108
|
}
|
|
72
109
|
|
|
73
|
-
// src/localess-
|
|
74
|
-
var import_react = require("react");
|
|
75
|
-
var import_client = require("@localess/client");
|
|
110
|
+
// src/components/localess-component.tsx
|
|
76
111
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
77
112
|
var LocalessComponent = (0, import_react.forwardRef)(({ data, links, references, ...restProps }, ref) => {
|
|
78
113
|
if (!data) {
|
|
@@ -85,7 +120,7 @@ var LocalessComponent = (0, import_react.forwardRef)(({ data, links, references,
|
|
|
85
120
|
}
|
|
86
121
|
const Comp = getComponent(data._schema);
|
|
87
122
|
if (Comp) {
|
|
88
|
-
const attr = isSyncEnabled() ? (0,
|
|
123
|
+
const attr = isSyncEnabled() ? (0, import_client2.localessEditable)(data) : {};
|
|
89
124
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Comp, { ref, data, links, references, ...attr, ...restProps });
|
|
90
125
|
}
|
|
91
126
|
const FallbackComponent = getFallbackComponent();
|
|
@@ -102,8 +137,58 @@ var LocalessComponent = (0, import_react.forwardRef)(({ data, links, references,
|
|
|
102
137
|
] });
|
|
103
138
|
});
|
|
104
139
|
|
|
140
|
+
// src/hooks/use-localess.ts
|
|
141
|
+
var import_react2 = require("react");
|
|
142
|
+
var import_client3 = require("@localess/client");
|
|
143
|
+
var useLocaless = (slug, options = {}) => {
|
|
144
|
+
const [document, setDocument] = (0, import_react2.useState)();
|
|
145
|
+
const client = getLocalessClient();
|
|
146
|
+
let normalizedSlug;
|
|
147
|
+
if (Array.isArray(slug)) {
|
|
148
|
+
normalizedSlug = slug.join("/");
|
|
149
|
+
} else {
|
|
150
|
+
normalizedSlug = slug;
|
|
151
|
+
}
|
|
152
|
+
(0, import_react2.useEffect)(() => {
|
|
153
|
+
async function loadDocument() {
|
|
154
|
+
const document2 = await client.getContentBySlug(normalizedSlug, options);
|
|
155
|
+
setDocument(document2);
|
|
156
|
+
if (isSyncEnabled() && (0, import_client3.isBrowser)()) {
|
|
157
|
+
window.localess?.on(["input", "change"], (event) => {
|
|
158
|
+
if (event.type === "change" || event.type === "input") {
|
|
159
|
+
setDocument({ ...document2, data: event.data });
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
loadDocument();
|
|
165
|
+
}, [slug, options, client]);
|
|
166
|
+
return document;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
// src/utils/link.util.ts
|
|
170
|
+
function findLink(links, link) {
|
|
171
|
+
switch (link.type) {
|
|
172
|
+
case "content": {
|
|
173
|
+
if (links) {
|
|
174
|
+
const path = links[link.uri];
|
|
175
|
+
if (path) {
|
|
176
|
+
return "/" + path.fullSlug;
|
|
177
|
+
} else {
|
|
178
|
+
return "/not-found";
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return "/not-found";
|
|
182
|
+
}
|
|
183
|
+
case "url":
|
|
184
|
+
return link.uri;
|
|
185
|
+
default:
|
|
186
|
+
return "no-type";
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
105
190
|
// src/richtext.ts
|
|
106
|
-
var
|
|
191
|
+
var import_react3 = require("@tiptap/static-renderer/pm/react");
|
|
107
192
|
var import_extension_document = require("@tiptap/extension-document");
|
|
108
193
|
var import_extension_text = require("@tiptap/extension-text");
|
|
109
194
|
var import_extension_paragraph = require("@tiptap/extension-paragraph");
|
|
@@ -120,7 +205,7 @@ var import_extension_code = require("@tiptap/extension-code");
|
|
|
120
205
|
var import_extension_code_block_lowlight = require("@tiptap/extension-code-block-lowlight");
|
|
121
206
|
var import_extension_link = require("@tiptap/extension-link");
|
|
122
207
|
function renderRichTextToReact(content) {
|
|
123
|
-
return (0,
|
|
208
|
+
return (0, import_react3.renderToReactElement)({
|
|
124
209
|
content,
|
|
125
210
|
extensions: [
|
|
126
211
|
import_extension_document.Document,
|
|
@@ -143,61 +228,6 @@ function renderRichTextToReact(content) {
|
|
|
143
228
|
]
|
|
144
229
|
});
|
|
145
230
|
}
|
|
146
|
-
|
|
147
|
-
// src/index.ts
|
|
148
|
-
var _client = void 0;
|
|
149
|
-
var _components = {};
|
|
150
|
-
var _fallbackComponent = void 0;
|
|
151
|
-
var _enableSync = false;
|
|
152
|
-
var _assetPathPrefix = "";
|
|
153
|
-
function localessInit(options) {
|
|
154
|
-
console.log("localessInit", options);
|
|
155
|
-
const { components, fallbackComponent, enableSync, ...restOptions } = options;
|
|
156
|
-
_client = (0, import_client2.localessClient)(restOptions);
|
|
157
|
-
_assetPathPrefix = `${options.origin}/api/v1/spaces/${options.spaceId}/assets/`;
|
|
158
|
-
_components = components || {};
|
|
159
|
-
_fallbackComponent = fallbackComponent;
|
|
160
|
-
if (enableSync) {
|
|
161
|
-
_enableSync = true;
|
|
162
|
-
(0, import_client2.loadLocalessSync)(restOptions.origin);
|
|
163
|
-
}
|
|
164
|
-
return _client;
|
|
165
|
-
}
|
|
166
|
-
function getLocalessClient() {
|
|
167
|
-
if (!_client) {
|
|
168
|
-
console.error("[Localess] No client found. Please check if the Localess is initialized.");
|
|
169
|
-
throw new Error("[Localess] No client found.");
|
|
170
|
-
}
|
|
171
|
-
return _client;
|
|
172
|
-
}
|
|
173
|
-
function registerComponent(key, component) {
|
|
174
|
-
_components[key] = component;
|
|
175
|
-
}
|
|
176
|
-
function unregisterComponent(key) {
|
|
177
|
-
delete _components[key];
|
|
178
|
-
}
|
|
179
|
-
function setComponents(components) {
|
|
180
|
-
_components = components;
|
|
181
|
-
}
|
|
182
|
-
function getComponent(key) {
|
|
183
|
-
if (Object.hasOwn(_components, key)) {
|
|
184
|
-
return _components[key];
|
|
185
|
-
}
|
|
186
|
-
console.error(`[Localess] component %c${key}%c can't be found.`, FONT_BOLD, FONT_NORMAL);
|
|
187
|
-
return void 0;
|
|
188
|
-
}
|
|
189
|
-
function setFallbackComponent(fallbackComponent) {
|
|
190
|
-
_fallbackComponent = fallbackComponent;
|
|
191
|
-
}
|
|
192
|
-
function getFallbackComponent() {
|
|
193
|
-
return _fallbackComponent;
|
|
194
|
-
}
|
|
195
|
-
function isSyncEnabled() {
|
|
196
|
-
return _enableSync;
|
|
197
|
-
}
|
|
198
|
-
function resolveAsset(asset) {
|
|
199
|
-
return `${_assetPathPrefix}${asset.uri}`;
|
|
200
|
-
}
|
|
201
231
|
// Annotate the CommonJS export names for ESM import in node:
|
|
202
232
|
0 && (module.exports = {
|
|
203
233
|
LocalessComponent,
|
|
@@ -217,5 +247,6 @@ function resolveAsset(asset) {
|
|
|
217
247
|
resolveAsset,
|
|
218
248
|
setComponents,
|
|
219
249
|
setFallbackComponent,
|
|
220
|
-
unregisterComponent
|
|
250
|
+
unregisterComponent,
|
|
251
|
+
useLocaless
|
|
221
252
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,37 +1,71 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import {
|
|
2
|
+
import { localessEditable as localessEditable2, localessEditableField, isBrowser as isBrowser2, isServer, isIframe } from "@localess/client";
|
|
3
|
+
|
|
4
|
+
// src/components/localess-component.tsx
|
|
5
|
+
import { forwardRef } from "react";
|
|
6
|
+
import { localessEditable } from "@localess/client";
|
|
3
7
|
|
|
4
8
|
// src/console.ts
|
|
5
9
|
var FONT_BOLD = "font-weight: bold";
|
|
6
10
|
var FONT_NORMAL = "font-weight: normal";
|
|
7
11
|
|
|
8
|
-
// src/
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
case "url":
|
|
26
|
-
return link.uri;
|
|
27
|
-
default:
|
|
28
|
-
return "no-type";
|
|
12
|
+
// src/state.ts
|
|
13
|
+
import { loadLocalessSync, localessClient } from "@localess/client";
|
|
14
|
+
var _client = void 0;
|
|
15
|
+
var _components = {};
|
|
16
|
+
var _fallbackComponent = void 0;
|
|
17
|
+
var _enableSync = false;
|
|
18
|
+
var _assetPathPrefix = "";
|
|
19
|
+
function localessInit(options) {
|
|
20
|
+
console.log("localessInit", options);
|
|
21
|
+
const { components, fallbackComponent, enableSync, ...restOptions } = options;
|
|
22
|
+
_client = localessClient(restOptions);
|
|
23
|
+
_assetPathPrefix = `${options.origin}/api/v1/spaces/${options.spaceId}/assets/`;
|
|
24
|
+
_components = components || {};
|
|
25
|
+
_fallbackComponent = fallbackComponent;
|
|
26
|
+
if (enableSync) {
|
|
27
|
+
_enableSync = true;
|
|
28
|
+
loadLocalessSync(restOptions.origin);
|
|
29
29
|
}
|
|
30
|
+
return _client;
|
|
31
|
+
}
|
|
32
|
+
function getLocalessClient() {
|
|
33
|
+
if (!_client) {
|
|
34
|
+
console.error("[Localess] No client found. Please check if the Localess is initialized.");
|
|
35
|
+
throw new Error("[Localess] No client found.");
|
|
36
|
+
}
|
|
37
|
+
return _client;
|
|
38
|
+
}
|
|
39
|
+
function registerComponent(key, component) {
|
|
40
|
+
_components[key] = component;
|
|
41
|
+
}
|
|
42
|
+
function unregisterComponent(key) {
|
|
43
|
+
delete _components[key];
|
|
44
|
+
}
|
|
45
|
+
function setComponents(components) {
|
|
46
|
+
_components = components;
|
|
47
|
+
}
|
|
48
|
+
function getComponent(key) {
|
|
49
|
+
if (Object.hasOwn(_components, key)) {
|
|
50
|
+
return _components[key];
|
|
51
|
+
}
|
|
52
|
+
console.error(`[Localess] component %c${key}%c can't be found.`, FONT_BOLD, FONT_NORMAL);
|
|
53
|
+
return void 0;
|
|
54
|
+
}
|
|
55
|
+
function setFallbackComponent(fallbackComponent) {
|
|
56
|
+
_fallbackComponent = fallbackComponent;
|
|
57
|
+
}
|
|
58
|
+
function getFallbackComponent() {
|
|
59
|
+
return _fallbackComponent;
|
|
60
|
+
}
|
|
61
|
+
function isSyncEnabled() {
|
|
62
|
+
return _enableSync;
|
|
63
|
+
}
|
|
64
|
+
function resolveAsset(asset) {
|
|
65
|
+
return `${_assetPathPrefix}${asset.uri}`;
|
|
30
66
|
}
|
|
31
67
|
|
|
32
|
-
// src/localess-
|
|
33
|
-
import { forwardRef } from "react";
|
|
34
|
-
import { localessEditable } from "@localess/client";
|
|
68
|
+
// src/components/localess-component.tsx
|
|
35
69
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
36
70
|
var LocalessComponent = forwardRef(({ data, links, references, ...restProps }, ref) => {
|
|
37
71
|
if (!data) {
|
|
@@ -61,6 +95,56 @@ var LocalessComponent = forwardRef(({ data, links, references, ...restProps }, r
|
|
|
61
95
|
] });
|
|
62
96
|
});
|
|
63
97
|
|
|
98
|
+
// src/hooks/use-localess.ts
|
|
99
|
+
import { useEffect, useState } from "react";
|
|
100
|
+
import { isBrowser } from "@localess/client";
|
|
101
|
+
var useLocaless = (slug, options = {}) => {
|
|
102
|
+
const [document, setDocument] = useState();
|
|
103
|
+
const client = getLocalessClient();
|
|
104
|
+
let normalizedSlug;
|
|
105
|
+
if (Array.isArray(slug)) {
|
|
106
|
+
normalizedSlug = slug.join("/");
|
|
107
|
+
} else {
|
|
108
|
+
normalizedSlug = slug;
|
|
109
|
+
}
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
async function loadDocument() {
|
|
112
|
+
const document2 = await client.getContentBySlug(normalizedSlug, options);
|
|
113
|
+
setDocument(document2);
|
|
114
|
+
if (isSyncEnabled() && isBrowser()) {
|
|
115
|
+
window.localess?.on(["input", "change"], (event) => {
|
|
116
|
+
if (event.type === "change" || event.type === "input") {
|
|
117
|
+
setDocument({ ...document2, data: event.data });
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
loadDocument();
|
|
123
|
+
}, [slug, options, client]);
|
|
124
|
+
return document;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// src/utils/link.util.ts
|
|
128
|
+
function findLink(links, link) {
|
|
129
|
+
switch (link.type) {
|
|
130
|
+
case "content": {
|
|
131
|
+
if (links) {
|
|
132
|
+
const path = links[link.uri];
|
|
133
|
+
if (path) {
|
|
134
|
+
return "/" + path.fullSlug;
|
|
135
|
+
} else {
|
|
136
|
+
return "/not-found";
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return "/not-found";
|
|
140
|
+
}
|
|
141
|
+
case "url":
|
|
142
|
+
return link.uri;
|
|
143
|
+
default:
|
|
144
|
+
return "no-type";
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
64
148
|
// src/richtext.ts
|
|
65
149
|
import { renderToReactElement } from "@tiptap/static-renderer/pm/react";
|
|
66
150
|
import { Document } from "@tiptap/extension-document";
|
|
@@ -102,68 +186,13 @@ function renderRichTextToReact(content) {
|
|
|
102
186
|
]
|
|
103
187
|
});
|
|
104
188
|
}
|
|
105
|
-
|
|
106
|
-
// src/index.ts
|
|
107
|
-
var _client = void 0;
|
|
108
|
-
var _components = {};
|
|
109
|
-
var _fallbackComponent = void 0;
|
|
110
|
-
var _enableSync = false;
|
|
111
|
-
var _assetPathPrefix = "";
|
|
112
|
-
function localessInit(options) {
|
|
113
|
-
console.log("localessInit", options);
|
|
114
|
-
const { components, fallbackComponent, enableSync, ...restOptions } = options;
|
|
115
|
-
_client = localessClient(restOptions);
|
|
116
|
-
_assetPathPrefix = `${options.origin}/api/v1/spaces/${options.spaceId}/assets/`;
|
|
117
|
-
_components = components || {};
|
|
118
|
-
_fallbackComponent = fallbackComponent;
|
|
119
|
-
if (enableSync) {
|
|
120
|
-
_enableSync = true;
|
|
121
|
-
loadLocalessSync(restOptions.origin);
|
|
122
|
-
}
|
|
123
|
-
return _client;
|
|
124
|
-
}
|
|
125
|
-
function getLocalessClient() {
|
|
126
|
-
if (!_client) {
|
|
127
|
-
console.error("[Localess] No client found. Please check if the Localess is initialized.");
|
|
128
|
-
throw new Error("[Localess] No client found.");
|
|
129
|
-
}
|
|
130
|
-
return _client;
|
|
131
|
-
}
|
|
132
|
-
function registerComponent(key, component) {
|
|
133
|
-
_components[key] = component;
|
|
134
|
-
}
|
|
135
|
-
function unregisterComponent(key) {
|
|
136
|
-
delete _components[key];
|
|
137
|
-
}
|
|
138
|
-
function setComponents(components) {
|
|
139
|
-
_components = components;
|
|
140
|
-
}
|
|
141
|
-
function getComponent(key) {
|
|
142
|
-
if (Object.hasOwn(_components, key)) {
|
|
143
|
-
return _components[key];
|
|
144
|
-
}
|
|
145
|
-
console.error(`[Localess] component %c${key}%c can't be found.`, FONT_BOLD, FONT_NORMAL);
|
|
146
|
-
return void 0;
|
|
147
|
-
}
|
|
148
|
-
function setFallbackComponent(fallbackComponent) {
|
|
149
|
-
_fallbackComponent = fallbackComponent;
|
|
150
|
-
}
|
|
151
|
-
function getFallbackComponent() {
|
|
152
|
-
return _fallbackComponent;
|
|
153
|
-
}
|
|
154
|
-
function isSyncEnabled() {
|
|
155
|
-
return _enableSync;
|
|
156
|
-
}
|
|
157
|
-
function resolveAsset(asset) {
|
|
158
|
-
return `${_assetPathPrefix}${asset.uri}`;
|
|
159
|
-
}
|
|
160
189
|
export {
|
|
161
190
|
LocalessComponent,
|
|
162
191
|
findLink,
|
|
163
192
|
getComponent,
|
|
164
193
|
getFallbackComponent,
|
|
165
194
|
getLocalessClient,
|
|
166
|
-
isBrowser,
|
|
195
|
+
isBrowser2 as isBrowser,
|
|
167
196
|
isIframe,
|
|
168
197
|
isServer,
|
|
169
198
|
isSyncEnabled,
|
|
@@ -175,5 +204,6 @@ export {
|
|
|
175
204
|
resolveAsset,
|
|
176
205
|
setComponents,
|
|
177
206
|
setFallbackComponent,
|
|
178
|
-
unregisterComponent
|
|
207
|
+
unregisterComponent,
|
|
208
|
+
useLocaless
|
|
179
209
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@localess/react",
|
|
3
|
-
"version": "3.0.1-dev.
|
|
3
|
+
"version": "3.0.1-dev.20260408172608",
|
|
4
4
|
"description": "ReactJS JavaScript/TypeScript SDK for Localess's API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"localess",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"react-dom": "^17 || ^18 || ^19"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@localess/client": "3.0.1-dev.
|
|
49
|
+
"@localess/client": "3.0.1-dev.20260408172608",
|
|
50
50
|
"@tiptap/static-renderer": "^3.20.1",
|
|
51
51
|
"@tiptap/html": "^3.20.1",
|
|
52
52
|
"@tiptap/extension-bold": "^3.20.1",
|