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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist/console.d.ts +2 -0
  2. package/dist/console.js +1 -0
  3. package/dist/console.mjs +4 -0
  4. package/dist/core/components/index.d.ts +8 -0
  5. package/dist/{localess-component-DikkO35Z.d.ts → core/components/localess-component.d.ts} +3 -7
  6. package/dist/core/components/localess-component.js +1 -0
  7. package/dist/core/components/localess-component.mjs +39 -0
  8. package/dist/{rsc.d.ts → core/components/localess-document.d.ts} +3 -11
  9. package/dist/core/components/localess-document.js +1 -0
  10. package/dist/core/components/localess-document.mjs +26 -0
  11. package/dist/core/hooks/index.d.ts +9 -0
  12. package/dist/core/hooks/use-localess.d.ts +45 -0
  13. package/dist/core/hooks/use-localess.js +1 -0
  14. package/dist/core/hooks/use-localess.mjs +25 -0
  15. package/dist/core/models/client.d.ts +43 -0
  16. package/dist/core/models/content.d.ts +1 -0
  17. package/dist/core/models/index.d.ts +33 -0
  18. package/dist/core/models/sync.d.ts +1 -0
  19. package/dist/core/models/translation.d.ts +1 -0
  20. package/dist/core/richtext.d.ts +26 -0
  21. package/dist/core/richtext.js +1 -0
  22. package/dist/core/richtext.mjs +48 -0
  23. package/dist/core/state.d.ts +127 -0
  24. package/dist/core/state.js +1 -0
  25. package/dist/core/state.mjs +43 -0
  26. package/dist/core/utils/index.d.ts +19 -0
  27. package/dist/core/utils/index.mjs +3 -0
  28. package/dist/core/utils/link.util.d.ts +24 -0
  29. package/dist/core/utils/link.util.js +1 -0
  30. package/dist/core/utils/link.util.mjs +15 -0
  31. package/dist/index.d.ts +19 -97
  32. package/dist/index.js +1 -284
  33. package/dist/index.mjs +8 -100
  34. package/dist/rsc/index.d.ts +30 -0
  35. package/dist/rsc/index.js +1 -0
  36. package/dist/rsc/index.mjs +9 -0
  37. package/dist/{rsc.d.mts → rsc/localess-document.d.ts} +3 -11
  38. package/dist/rsc/localess-document.js +1 -0
  39. package/dist/rsc/localess-document.mjs +23 -0
  40. package/dist/rsc/localess-sync.d.ts +7 -0
  41. package/dist/rsc/localess-sync.js +1 -0
  42. package/dist/rsc/localess-sync.mjs +15 -0
  43. package/dist/ssr/index.d.ts +33 -0
  44. package/dist/ssr/index.js +1 -0
  45. package/dist/ssr/index.mjs +7 -0
  46. package/dist/ssr/localess-component.d.ts +48 -0
  47. package/dist/ssr/localess-component.js +1 -0
  48. package/dist/ssr/localess-component.mjs +37 -0
  49. package/dist/ssr/localess-document.d.ts +42 -0
  50. package/dist/ssr/localess-document.js +1 -0
  51. package/dist/ssr/localess-document.mjs +17 -0
  52. package/package.json +32 -24
  53. package/dist/chunk-DD2NUMQJ.mjs +0 -56
  54. package/dist/chunk-ETSLIILF.mjs +0 -149
  55. package/dist/chunk-UW7OWE53.mjs +0 -45
  56. package/dist/index.d.mts +0 -104
  57. package/dist/localess-component-DikkO35Z.d.mts +0 -58
  58. package/dist/richtext-D6tBmv-7.d.mts +0 -218
  59. package/dist/richtext-D6tBmv-7.d.ts +0 -218
  60. package/dist/rsc.js +0 -280
  61. package/dist/rsc.mjs +0 -62
  62. package/dist/ssr.d.mts +0 -96
  63. package/dist/ssr.d.ts +0 -96
  64. package/dist/ssr.js +0 -223
  65. package/dist/ssr.mjs +0 -38
@@ -0,0 +1,2 @@
1
+ export declare const FONT_BOLD = "font-weight: bold";
2
+ export declare const FONT_NORMAL = "font-weight: normal";
@@ -0,0 +1 @@
1
+ var e=`font-weight: bold`,t=`font-weight: normal`;exports.FONT_BOLD=e,exports.FONT_NORMAL=t;
@@ -0,0 +1,4 @@
1
+ //#region src/console.ts
2
+ var e = "font-weight: bold", t = "font-weight: normal";
3
+ //#endregion
4
+ export { e as FONT_BOLD, t as FONT_NORMAL };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Core components barrel.
3
+ *
4
+ * LocalessComponent — maps content._schema to a registered React component.
5
+ * Server-safe (no 'use client'). Used in SPA and RSC flows.
6
+ */
7
+ export * from './localess-component';
8
+ export * from './localess-document';
@@ -1,12 +1,10 @@
1
- import * as react from 'react';
2
- import { ContentData, Links, References } from '@localess/client';
3
-
1
+ import { ContentData, Links, References } from '../models';
4
2
  /**
5
3
  * Props for {@link LocalessComponent}.
6
4
  *
7
5
  * @template T - The content data shape. Defaults to the base {@link ContentData} type.
8
6
  */
9
- type LocalessComponentProps<T extends ContentData = ContentData> = {
7
+ export type LocalessComponentProps<T extends ContentData = ContentData> = {
10
8
  /**
11
9
  * The content data object to render. Must have a `_schema` field that matches a key
12
10
  * in the component registry configured via `localessInit`.
@@ -53,6 +51,4 @@ type LocalessComponentProps<T extends ContentData = ContentData> = {
53
51
  * ))}
54
52
  * ```
55
53
  */
56
- declare const LocalessComponent: react.ForwardRefExoticComponent<LocalessComponentProps<ContentData> & react.RefAttributes<HTMLElement>>;
57
-
58
- export { LocalessComponent as L, type LocalessComponentProps as a };
54
+ export declare const LocalessComponent: import('react').ForwardRefExoticComponent<LocalessComponentProps<ContentData> & import('react').RefAttributes<HTMLElement>>;
@@ -0,0 +1 @@
1
+ const e=require(`../../console.js`),t=require(`../state.js`);let n=require(`react`),r=require(`react/jsx-runtime`),i=require(`@localess/client`);var a=(0,n.forwardRef)(({data:n,links:a,references:o,...s},c)=>{if(!n)return console.error(`LocalessComponent property %cdata%c is not provided.`,e.FONT_BOLD,e.FONT_NORMAL),(0,r.jsxs)(`div`,{children:[`LocalessComponent property `,(0,r.jsx)(`b`,{children:`data`}),` is not provided.`]});let l=t.getComponent(n._schema);if(l)return(0,r.jsx)(l,{ref:c,data:n,links:a,references:o,...(0,i.localessEditable)(n),...s});let u=t.getFallbackComponent();return u?(0,r.jsx)(u,{ref:c,data:n,links:a,references:o,...s}):(0,r.jsxs)(`p`,{children:[(0,r.jsx)(`b`,{children:`LocalessComponent`}),` could not found component with key `,(0,r.jsx)(`b`,{children:n._schema}),`. `,(0,r.jsx)(`br`,{}),`Please check if your configuration is correct.`]})});exports.LocalessComponent=a;
@@ -0,0 +1,39 @@
1
+ import { FONT_BOLD as e, FONT_NORMAL as t } from "../../console.mjs";
2
+ import { getComponent as n, getFallbackComponent as r } from "../state.mjs";
3
+ import { localessEditable as i } from "../utils/index.mjs";
4
+ import { forwardRef as a } from "react";
5
+ import { jsx as o, jsxs as s } from "react/jsx-runtime";
6
+ //#region src/core/components/localess-component.tsx
7
+ var c = a(({ data: a, links: c, references: l, ...u }, d) => {
8
+ if (!a) return console.error("LocalessComponent property %cdata%c is not provided.", e, t), /* @__PURE__ */ s("div", { children: [
9
+ "LocalessComponent property ",
10
+ /* @__PURE__ */ o("b", { children: "data" }),
11
+ " is not provided."
12
+ ] });
13
+ let f = n(a._schema);
14
+ if (f) return /* @__PURE__ */ o(f, {
15
+ ref: d,
16
+ data: a,
17
+ links: c,
18
+ references: l,
19
+ ...i(a),
20
+ ...u
21
+ });
22
+ let p = r();
23
+ return p ? /* @__PURE__ */ o(p, {
24
+ ref: d,
25
+ data: a,
26
+ links: c,
27
+ references: l,
28
+ ...u
29
+ }) : /* @__PURE__ */ s("p", { children: [
30
+ /* @__PURE__ */ o("b", { children: "LocalessComponent" }),
31
+ " could not found component with key ",
32
+ /* @__PURE__ */ o("b", { children: a._schema }),
33
+ ". ",
34
+ /* @__PURE__ */ o("br", {}),
35
+ "Please check if your configuration is correct."
36
+ ] });
37
+ });
38
+ //#endregion
39
+ export { c as LocalessComponent };
@@ -1,16 +1,10 @@
1
- export { L as LocalessOptions, f as findLink, g as getComponent, a as getFallbackComponent, b as getLocalessClient, i as isSyncEnabled, l as localessInit, r as registerComponent, c as renderRichTextToReact, d as resolveAsset, u as unregisterComponent } from './richtext-D6tBmv-7.js';
2
- export { LocalessServerComponent, LocalessServerComponentProps, LocalessServerDocument, LocalessServerDocumentProps } from './ssr.js';
3
- import { ContentData, Content } from '@localess/client';
4
- export { Content, ContentAsset, ContentData, ContentDataField, ContentDataSchema, ContentLink, ContentMetadata, ContentReference, ContentRichText, EventCallback, EventToApp, EventToAppType, Links, LocalessClient, LocalessSync, References, Translations, isBrowser, isIframe, isServer, localessEditable, localessEditableField } from '@localess/client';
5
- export { L as LocalessComponent, a as LocalessComponentProps } from './localess-component-DikkO35Z.js';
6
- import * as react from 'react';
7
-
1
+ import { Content, ContentData } from '../models';
8
2
  /**
9
3
  * Props for {@link LocalessDocument}.
10
4
  *
11
5
  * @template T - The content data shape. Defaults to the base {@link ContentData} type.
12
6
  */
13
- type LocalessDocumentProps<T extends ContentData = ContentData> = {
7
+ export type LocalessDocumentProps<T extends ContentData = ContentData> = {
14
8
  /**
15
9
  * The full content response object as returned by `getContentBySlug` or `getContentById`.
16
10
  * Must contain a `data` field with a valid `_schema` key.
@@ -56,6 +50,4 @@ type LocalessDocumentProps<T extends ContentData = ContentData> = {
56
50
  * }
57
51
  * ```
58
52
  */
59
- declare const LocalessDocument: react.ForwardRefExoticComponent<LocalessDocumentProps<ContentData> & react.RefAttributes<HTMLElement>>;
60
-
61
- export { LocalessDocument, type LocalessDocumentProps };
53
+ export declare const LocalessDocument: import('react').ForwardRefExoticComponent<LocalessDocumentProps<ContentData> & import('react').RefAttributes<HTMLElement>>;
@@ -0,0 +1 @@
1
+ const e=require(`../../console.js`),t=require(`../state.js`),n=require(`./localess-component.js`);let r=require(`react`),i=require(`react/jsx-runtime`),a=require(`@localess/client`);var o=(0,r.forwardRef)(({document:o},s)=>{let[c,l]=(0,r.useState)(o.data);return(0,r.useEffect)(()=>{t.isSyncEnabled()&&(0,a.isBrowser)()&&(0,a.isIframe)()&&window.localess?.on([`input`,`change`],e=>{(e.type===`change`||e.type===`input`)&&l(e.data)})},[]),c?(0,i.jsx)(n.LocalessComponent,{ref:s,data:c,links:o.links,references:o.references}):(console.error(`LocalessDocument property %cdocument.data%c is not provided.`,e.FONT_BOLD,e.FONT_NORMAL),(0,i.jsxs)(`div`,{children:[`LocalessDocument property `,(0,i.jsx)(`b`,{children:`document.data`}),` is not provided.`]}))});exports.LocalessDocument=o;
@@ -0,0 +1,26 @@
1
+ import { FONT_BOLD as e, FONT_NORMAL as t } from "../../console.mjs";
2
+ import { isSyncEnabled as n } from "../state.mjs";
3
+ import { isBrowser as r, isIframe as i } from "../utils/index.mjs";
4
+ import { LocalessComponent as a } from "./localess-component.mjs";
5
+ import { forwardRef as o, useEffect as s, useState as c } from "react";
6
+ import { jsx as l, jsxs as u } from "react/jsx-runtime";
7
+ //#region src/core/components/localess-document.tsx
8
+ var d = o(({ document: o }, d) => {
9
+ let [f, p] = c(o.data);
10
+ return s(() => {
11
+ n() && r() && i() && window.localess?.on(["input", "change"], (e) => {
12
+ (e.type === "change" || e.type === "input") && p(e.data);
13
+ });
14
+ }, []), f ? /* @__PURE__ */ l(a, {
15
+ ref: d,
16
+ data: f,
17
+ links: o.links,
18
+ references: o.references
19
+ }) : (console.error("LocalessDocument property %cdocument.data%c is not provided.", e, t), /* @__PURE__ */ u("div", { children: [
20
+ "LocalessDocument property ",
21
+ /* @__PURE__ */ l("b", { children: "document.data" }),
22
+ " is not provided."
23
+ ] }));
24
+ });
25
+ //#endregion
26
+ export { d as LocalessDocument };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Core hooks barrel.
3
+ *
4
+ * useLocaless<T>(slug, options?) — fetch content by slug inside a Client Component ('use client').
5
+ * Accepts a string or string[] slug (array joined with '/').
6
+ * Subscribes to Visual Editor sync events when isSyncEnabled() is true.
7
+ * Returns Content<T> | undefined.
8
+ */
9
+ export * from './use-localess';
@@ -0,0 +1,45 @@
1
+ import { ContentFetchParams } from '@localess/client';
2
+ import { Content, ContentData } from '../models';
3
+ /**
4
+ * Options for {@link useLocaless}.
5
+ * Extends {@link ContentFetchParams} with any future hook-specific settings.
6
+ */
7
+ export type UseLocalessOptions = ContentFetchParams & {};
8
+ /**
9
+ * React hook for fetching Localess content by slug inside a Client Component.
10
+ *
11
+ * Fetches content on mount using `getLocalessClient().getContentBySlug`, stores it in local state,
12
+ * and — when `enableSync` is active and the page is running inside the Visual Editor iframe —
13
+ * automatically subscribes to `input` and `change` events so content updates live without a reload.
14
+ *
15
+ * **Requires `'use client'`** — must be called inside a Client Component.
16
+ *
17
+ * **Recommended pattern:** fetch data server-side and pass it as `initialContent`, then use the
18
+ * hook result with `?? initialContent` to avoid a loading flash:
19
+ * ```tsx
20
+ * const content = useLocaless('home', { locale }) ?? initialContent;
21
+ * ```
22
+ *
23
+ * @template T - The content data shape. Defaults to {@link ContentData}.
24
+ *
25
+ * @param slug - Content slug string, or an array of path segments that will be joined with `/`.
26
+ * @param options - Optional fetch parameters (locale, version, resolveReference, resolveLink).
27
+ * @returns The fetched {@link Content}<T> object, or `undefined` while the initial fetch is in flight.
28
+ *
29
+ * @example Basic usage
30
+ * ```tsx
31
+ * 'use client';
32
+ * import { useLocaless } from '@localess/react/rsc';
33
+ *
34
+ * export function PageClient({ initialContent, locale }) {
35
+ * const content = useLocaless('home', { locale }) ?? initialContent;
36
+ * return <LocalessComponent data={content.data} links={content.links} />;
37
+ * }
38
+ * ```
39
+ *
40
+ * @example Array slug (joined as 'blog/my-post')
41
+ * ```tsx
42
+ * const content = useLocaless(['blog', 'my-post'], { locale: 'en' });
43
+ * ```
44
+ */
45
+ export declare const useLocaless: <T extends ContentData = ContentData>(slug: string | string[], options?: UseLocalessOptions) => Content<T> | undefined;
@@ -0,0 +1 @@
1
+ const e=require(`../state.js`);let t=require(`react`),n=require(`@localess/client`);var r=(r,i={})=>{let[a,o]=(0,t.useState)(),s=e.getLocalessClient(),c;return c=Array.isArray(r)?r.join(`/`):r,(0,t.useEffect)(()=>{async function t(){let t=await s.getContentBySlug(c,i);o(t),e.isSyncEnabled()&&(0,n.isBrowser)()&&(0,n.isIframe)()&&window.localess?.on([`input`,`change`],e=>{(e.type===`change`||e.type===`input`)&&o({...t,data:e.data})})}t()},[r,i,s]),a};exports.useLocaless=r;
@@ -0,0 +1,25 @@
1
+ import { getLocalessClient as e, isSyncEnabled as t } from "../state.mjs";
2
+ import { isBrowser as n, isIframe as r } from "../utils/index.mjs";
3
+ import { useEffect as i, useState as a } from "react";
4
+ //#region src/core/hooks/use-localess.ts
5
+ var o = (o, s = {}) => {
6
+ let [c, l] = a(), u = e(), d;
7
+ return d = Array.isArray(o) ? o.join("/") : o, i(() => {
8
+ async function e() {
9
+ let e = await u.getContentBySlug(d, s);
10
+ l(e), t() && n() && r() && window.localess?.on(["input", "change"], (t) => {
11
+ (t.type === "change" || t.type === "input") && l({
12
+ ...e,
13
+ data: t.data
14
+ });
15
+ });
16
+ }
17
+ e();
18
+ }, [
19
+ o,
20
+ s,
21
+ u
22
+ ]), c;
23
+ };
24
+ //#endregion
25
+ export { o as useLocaless };
@@ -0,0 +1,43 @@
1
+ import { default as React } from 'react';
2
+ import { LocalessClientOptions } from '@localess/client';
3
+ export type { LocalessClient } from '@localess/client';
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
+ export 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.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.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
+ };
@@ -0,0 +1 @@
1
+ export type { Content, ContentData, ContentMetadata, ContentDataSchema, ContentDataField, ContentAsset, ContentRichText, ContentLink, ContentReference, Links, References, } from '@localess/client';
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Core models barrel.
3
+ *
4
+ * Client & init types:
5
+ * LocalessClient — the client instance type returned by localessInit / getLocalessClient.
6
+ * LocalessOptions — full init options: LocalessClientOptions + components, fallbackComponent, enableSync.
7
+ *
8
+ * Content types:
9
+ * Content<T> — wrapper returned by getContentBySlug / getContentById: { data, links, references }.
10
+ * ContentData — base content shape with _id and _schema fields.
11
+ * ContentMetadata — content metadata (slug, name, locale, publishedAt, updatedAt, …).
12
+ * ContentDataSchema — minimal shape used by localessEditable: { _id, _schema }.
13
+ * ContentDataField — base shape for nested content fields.
14
+ * ContentAsset — asset reference with uri field; pass to resolveAsset() for a full URL.
15
+ * ContentRichText — TipTap document structure; pass to renderRichTextToReact() to render.
16
+ * ContentLink — link reference with type ('content' | 'url') and uri; pass to findLink() to resolve.
17
+ * ContentReference — resolved content reference.
18
+ * Links — Record<string, { fullSlug }> map of content links, keyed by link ID.
19
+ * References — Record<string, ContentData> map of resolved references, keyed by reference ID.
20
+ *
21
+ * Sync / Visual Editor types:
22
+ * LocalessSync — type of window.localess (exposes .on() and .onChange()).
23
+ * EventToApp — event payload sent from the Visual Editor to the app.
24
+ * EventCallback — callback signature for window.localess.on(events, callback).
25
+ * EventToAppType — union of Visual Editor event type strings ('input' | 'change' | 'pong' | …).
26
+ *
27
+ * Translation types:
28
+ * Translations — locale-keyed flat translation record.
29
+ */
30
+ export * from './client';
31
+ export * from './content';
32
+ export * from './sync';
33
+ export * from './translation';
@@ -0,0 +1 @@
1
+ export type { LocalessSync, EventToApp, EventCallback, EventToAppType } from '@localess/client';
@@ -0,0 +1 @@
1
+ export type { Translations } from '@localess/client';
@@ -0,0 +1,26 @@
1
+ import { default as React } from 'react';
2
+ import { ContentRichText } from '@localess/client';
3
+ /**
4
+ * Renders a Localess rich text field to a React node tree.
5
+ *
6
+ * Converts a {@link ContentRichText} value (TipTap ProseMirror document JSON) into
7
+ * `React.ReactNode` using TipTap's static renderer. No browser APIs are required —
8
+ * safe to call in React Server Components and SSR.
9
+ *
10
+ * Supported TipTap extensions: Document, Text, Paragraph, Heading (h1–h6), Bold,
11
+ * Italic, Strike, Underline, History, ListItem, OrderedList, BulletList, Code,
12
+ * CodeBlockLowlight, Link.
13
+ *
14
+ * @param content - The rich text value from a Localess content field (type `ContentRichText`).
15
+ * @returns A `React.ReactNode` ready to render inside JSX.
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * import { renderRichTextToReact } from '@localess/react';
20
+ *
21
+ * export function Article({ data }: { data: MyContent }) {
22
+ * return <article>{renderRichTextToReact(data.body)}</article>;
23
+ * }
24
+ * ```
25
+ */
26
+ export declare function renderRichTextToReact(content: ContentRichText): React.ReactNode;
@@ -0,0 +1 @@
1
+ let e=require(`@tiptap/static-renderer/pm/react`),t=require(`@tiptap/extension-document`),n=require(`@tiptap/extension-text`),r=require(`@tiptap/extension-paragraph`),i=require(`@tiptap/extension-heading`),a=require(`@tiptap/extension-bold`),o=require(`@tiptap/extension-italic`),s=require(`@tiptap/extension-strike`),c=require(`@tiptap/extension-underline`),l=require(`@tiptap/extension-history`),u=require(`@tiptap/extension-list-item`),d=require(`@tiptap/extension-ordered-list`),f=require(`@tiptap/extension-bullet-list`),p=require(`@tiptap/extension-code`),m=require(`@tiptap/extension-code-block-lowlight`),h=require(`@tiptap/extension-link`);function g(g){return(0,e.renderToReactElement)({content:g,extensions:[t.Document,n.Text,r.Paragraph,i.Heading.configure({levels:[1,2,3,4,5,6]}),a.Bold,o.Italic,s.Strike,c.Underline,l.History,u.ListItem,d.OrderedList,f.BulletList,p.Code,m.CodeBlockLowlight,h.Link]})}exports.renderRichTextToReact=g;
@@ -0,0 +1,48 @@
1
+ import { renderToReactElement as e } from "@tiptap/static-renderer/pm/react";
2
+ import { Document as t } from "@tiptap/extension-document";
3
+ import { Text as n } from "@tiptap/extension-text";
4
+ import { Paragraph as r } from "@tiptap/extension-paragraph";
5
+ import { Heading as i } from "@tiptap/extension-heading";
6
+ import { Bold as a } from "@tiptap/extension-bold";
7
+ import { Italic as o } from "@tiptap/extension-italic";
8
+ import { Strike as s } from "@tiptap/extension-strike";
9
+ import { Underline as c } from "@tiptap/extension-underline";
10
+ import { History as l } from "@tiptap/extension-history";
11
+ import { ListItem as u } from "@tiptap/extension-list-item";
12
+ import { OrderedList as d } from "@tiptap/extension-ordered-list";
13
+ import { BulletList as f } from "@tiptap/extension-bullet-list";
14
+ import { Code as p } from "@tiptap/extension-code";
15
+ import { CodeBlockLowlight as m } from "@tiptap/extension-code-block-lowlight";
16
+ import { Link as h } from "@tiptap/extension-link";
17
+ //#region src/core/richtext.ts
18
+ function g(g) {
19
+ return e({
20
+ content: g,
21
+ extensions: [
22
+ t,
23
+ n,
24
+ r,
25
+ i.configure({ levels: [
26
+ 1,
27
+ 2,
28
+ 3,
29
+ 4,
30
+ 5,
31
+ 6
32
+ ] }),
33
+ a,
34
+ o,
35
+ s,
36
+ c,
37
+ l,
38
+ u,
39
+ d,
40
+ f,
41
+ p,
42
+ m,
43
+ h
44
+ ]
45
+ });
46
+ }
47
+ //#endregion
48
+ export { g as renderRichTextToReact };
@@ -0,0 +1,127 @@
1
+ import { default as React } from 'react';
2
+ import { LocalessClient } from '@localess/client';
3
+ import { LocalessOptions, ContentAsset } from './models';
4
+ /**
5
+ * Initialize the Localess SDK.
6
+ *
7
+ * Must be called **once** at application startup (e.g. root layout, `_app.tsx`) before any
8
+ * other SDK function is used. Calling it again overwrites the existing client and state.
9
+ *
10
+ * - Creates the underlying {@link LocalessClient} with the supplied API options.
11
+ * - Registers the component map and optional fallback component.
12
+ * - When `enableSync` is `true` and the page is running inside the Visual Editor iframe,
13
+ * injects the Localess sync script into `<head>` to enable live editing events.
14
+ *
15
+ * @param options - Initialization options. Extends {@link LocalessClientOptions} with
16
+ * `components`, `fallbackComponent`, and `enableSync`.
17
+ * @returns The initialized {@link LocalessClient} instance.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { localessInit } from '@localess/react';
22
+ * import { Page, Header, Teaser } from '@/components';
23
+ *
24
+ * localessInit({
25
+ * origin: 'https://my-localess.web.app',
26
+ * spaceId: 'YOUR_SPACE_ID',
27
+ * token: 'YOUR_API_TOKEN', // keep server-side only
28
+ * enableSync: process.env.NODE_ENV !== 'production',
29
+ * components: { page: Page, header: Header, teaser: Teaser },
30
+ * });
31
+ * ```
32
+ */
33
+ export declare function localessInit(options: LocalessOptions): LocalessClient;
34
+ /**
35
+ * Returns the initialized {@link LocalessClient} instance.
36
+ *
37
+ * Throws an error if called before {@link localessInit}. Use this in server components,
38
+ * API routes, or server-side data fetching functions to make API calls.
39
+ *
40
+ * @throws {Error} If `localessInit` has not been called yet.
41
+ * @returns The active {@link LocalessClient}.
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * const content = await getLocalessClient().getContentBySlug<MyPage>('home', { locale: 'en' });
46
+ * ```
47
+ */
48
+ export declare function getLocalessClient(): LocalessClient;
49
+ /**
50
+ * Adds a single component to the registry under the given schema key.
51
+ *
52
+ * The key must match the `_schema` field of the content objects you want to render.
53
+ * Overwrites any previously registered component for the same key.
54
+ *
55
+ * @param key - The schema key (e.g. `'hero-section'`).
56
+ * @param component - The React component to render for this schema key.
57
+ */
58
+ export declare function registerComponent(key: string, component: React.ElementType): void;
59
+ /**
60
+ * Removes a component from the registry by schema key.
61
+ * No-op if the key does not exist.
62
+ *
63
+ * @param key - The schema key to remove.
64
+ */
65
+ export declare function unregisterComponent(key: string): void;
66
+ /**
67
+ * Replaces the entire component registry with the supplied map.
68
+ *
69
+ * Useful when you need to swap all components at once (e.g. lazy-loaded registry).
70
+ * Any previously registered components (including those set via `localessInit`) are discarded.
71
+ *
72
+ * @param components - A record mapping schema keys to React components.
73
+ */
74
+ export declare function setComponents(components: Record<string, React.ElementType>): void;
75
+ /**
76
+ * Looks up a React component by its schema key.
77
+ *
78
+ * Returns `undefined` and logs a console error when the key is not found.
79
+ * Called internally by {@link LocalessComponent} and {@link LocalessServerComponent}.
80
+ *
81
+ * @param key - The schema key to look up (matches `content._schema`).
82
+ * @returns The registered React component, or `undefined` if not found.
83
+ */
84
+ export declare function getComponent(key: string): React.ElementType | undefined;
85
+ /**
86
+ * Sets the fallback component rendered when no registry match is found for a schema key.
87
+ *
88
+ * The fallback receives the same `data`, `links`, and `references` props as any
89
+ * registered component, so it can render a generic placeholder or log the unknown schema.
90
+ *
91
+ * @param fallbackComponent - The React component to use as the fallback.
92
+ */
93
+ export declare function setFallbackComponent(fallbackComponent: React.ElementType): void;
94
+ /**
95
+ * Returns the currently registered fallback component, or `undefined` if none is set.
96
+ *
97
+ * Called internally by {@link LocalessComponent} and {@link LocalessServerComponent}
98
+ * when a schema key has no matching component in the registry.
99
+ *
100
+ * @returns The fallback React component, or `undefined`.
101
+ */
102
+ export declare function getFallbackComponent(): React.ElementType | undefined;
103
+ /**
104
+ * Returns `true` when Visual Editor sync was enabled via `enableSync: true` in `localessInit`.
105
+ *
106
+ * Used internally by {@link LocalessComponent}, {@link LocalessDocument}, and {@link useLocaless}
107
+ * to decide whether to inject editable attributes and subscribe to sync events.
108
+ *
109
+ * @returns `true` if sync is enabled, `false` otherwise.
110
+ */
111
+ export declare function isSyncEnabled(): boolean;
112
+ export declare function getOrigin(): string;
113
+ /**
114
+ * Resolves a {@link ContentAsset} to its full URL string.
115
+ *
116
+ * Constructs the URL using the `origin` and `spaceId` from `localessInit`:
117
+ * `{origin}/api/v1/spaces/{spaceId}/assets/{asset.uri}`
118
+ *
119
+ * @param asset - The asset reference object containing a `uri` field.
120
+ * @returns The fully qualified asset URL string.
121
+ *
122
+ * @example
123
+ * ```tsx
124
+ * <img src={resolveAsset(data.heroImage)} alt={data.heroImage.alt} />
125
+ * ```
126
+ */
127
+ export declare function resolveAsset(asset: ContentAsset): string;
@@ -0,0 +1 @@
1
+ const e=require(`../console.js`);let t=require(`@localess/client`);var n=void 0,r=void 0,i={},a=void 0,o=!1,s=``;function c(e){let{components:c,fallbackComponent:l,enableSync:u,...d}=e;return r=(0,t.localessClient)(d),n=d.origin,s=`${e.origin}/api/v1/spaces/${e.spaceId}/assets/`,i=c||{},a=l,u&&(o=!0,(0,t.loadLocalessSync)(d.origin)),r}function l(){if(!r)throw console.error(`[Localess] No client found. Please check if the Localess is initialized. Use localessInit function.`),Error(`[Localess] No client found.`);return r}function u(e,t){i[e]=t}function d(e){delete i[e]}function f(e){i=e}function p(t){if(Object.hasOwn(i,t))return i[t];console.error(`[Localess] component %c${t}%c can't be found.`,e.FONT_BOLD,e.FONT_NORMAL)}function m(e){a=e}function h(){return a}function g(){return o}function _(){if(!n)throw console.error(`[Localess] No origin found. Please check if the Localess is initialized. Use localessInit function.`),Error(`[Localess] No origin found.`);return n}function v(e){return`${s}${e.uri}`}exports.getComponent=p,exports.getFallbackComponent=h,exports.getLocalessClient=l,exports.getOrigin=_,exports.isSyncEnabled=g,exports.localessInit=c,exports.registerComponent=u,exports.resolveAsset=v,exports.setComponents=f,exports.setFallbackComponent=m,exports.unregisterComponent=d;
@@ -0,0 +1,43 @@
1
+ import { FONT_BOLD as e, FONT_NORMAL as t } from "../console.mjs";
2
+ import { loadLocalessSync as n, localessClient as r } from "@localess/client";
3
+ //#region src/core/state.ts
4
+ var i = void 0, a = void 0, o = {}, s = void 0, c = !1, l = "";
5
+ function u(e) {
6
+ let { components: t, fallbackComponent: u, enableSync: d, ...f } = e;
7
+ return a = r(f), i = f.origin, l = `${e.origin}/api/v1/spaces/${e.spaceId}/assets/`, o = t || {}, s = u, d && (c = !0, n(f.origin)), a;
8
+ }
9
+ function d() {
10
+ if (!a) throw console.error("[Localess] No client found. Please check if the Localess is initialized. Use localessInit function."), Error("[Localess] No client found.");
11
+ return a;
12
+ }
13
+ function f(e, t) {
14
+ o[e] = t;
15
+ }
16
+ function p(e) {
17
+ delete o[e];
18
+ }
19
+ function m(e) {
20
+ o = e;
21
+ }
22
+ function h(n) {
23
+ if (Object.hasOwn(o, n)) return o[n];
24
+ console.error(`[Localess] component %c${n}%c can't be found.`, e, t);
25
+ }
26
+ function g(e) {
27
+ s = e;
28
+ }
29
+ function _() {
30
+ return s;
31
+ }
32
+ function v() {
33
+ return c;
34
+ }
35
+ function y() {
36
+ if (!i) throw console.error("[Localess] No origin found. Please check if the Localess is initialized. Use localessInit function."), Error("[Localess] No origin found.");
37
+ return i;
38
+ }
39
+ function b(e) {
40
+ return `${l}${e.uri}`;
41
+ }
42
+ //#endregion
43
+ export { h as getComponent, _ as getFallbackComponent, d as getLocalessClient, y as getOrigin, v as isSyncEnabled, u as localessInit, f as registerComponent, b as resolveAsset, m as setComponents, g as setFallbackComponent, p as unregisterComponent };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Core utils barrel.
3
+ *
4
+ * From @localess/client:
5
+ * localessEditable(content) — returns { 'data-ll-id', 'data-ll-schema' } for Visual Editor targeting.
6
+ * Spread on a component's root element.
7
+ * localessEditableField<T>(fieldName) — returns { 'data-ll-field' } for field-level Visual Editor targeting.
8
+ * Generic type T restricts fieldName to valid content keys.
9
+ * isBrowser — true when running in a browser (window is defined).
10
+ * isServer — true when running in a Node.js / server environment.
11
+ * isIframe — true when the page is loaded inside an iframe (i.e. inside the Visual Editor).
12
+ *
13
+ * Local:
14
+ * findLink(links, link) — resolve a ContentLink to a URL string.
15
+ * Returns '/' + fullSlug for type:'content', raw uri for type:'url',
16
+ * '/not-found' when the link cannot be resolved.
17
+ */
18
+ export { localessEditable, localessEditableField, isBrowser, isServer, isIframe } from '@localess/client';
19
+ export * from './link.util';
@@ -0,0 +1,3 @@
1
+ import "./link.util.mjs";
2
+ import { isBrowser as e, isIframe as t, isServer as n, localessEditable as r, localessEditableField as i } from "@localess/client";
3
+ export { e as isBrowser, t as isIframe, n as isServer, r as localessEditable, i as localessEditableField };
@@ -0,0 +1,24 @@
1
+ import { ContentLink, Links } from '../models';
2
+ /**
3
+ * Resolves a {@link ContentLink} reference to a navigable URL string.
4
+ *
5
+ * Resolution rules by `link.type`:
6
+ * - `'content'` — looks up `link.uri` in the `links` map and returns `'/' + fullSlug`.
7
+ * Returns `'/not-found'` when `links` is undefined or the URI is not in the map.
8
+ * - `'url'` — returns `link.uri` directly (external or absolute URL).
9
+ * - anything else — returns `'no-type'` (indicates a misconfigured link field).
10
+ *
11
+ * @param links - The links map from `content.links` (keyed by link URI). May be `undefined`.
12
+ * @param link - The content link reference to resolve.
13
+ * @returns A URL string ready to use in an `<a href>` or Next.js `<Link href>`.
14
+ *
15
+ * @example
16
+ * ```tsx
17
+ * import { findLink } from '@localess/react';
18
+ *
19
+ * function NavItem({ data, links }) {
20
+ * return <a href={findLink(links, data.url)}>{data.label}</a>;
21
+ * }
22
+ * ```
23
+ */
24
+ export declare function findLink(links: Links | undefined, link: ContentLink): string;
@@ -0,0 +1 @@
1
+ function e(e,t){switch(t.type){case`content`:if(e){let n=e[t.uri];return n?`/`+n.fullSlug:`/not-found`}return`/not-found`;case`url`:return t.uri;default:return`no-type`}}exports.findLink=e;