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

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 (64) 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/core/components/localess-component.d.ts +54 -0
  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} +6 -25
  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 -257
  33. package/dist/index.mjs +8 -44
  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} +6 -25
  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 +12 -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-AJP75NRT.mjs +0 -56
  54. package/dist/chunk-ETSLIILF.mjs +0 -149
  55. package/dist/chunk-V6JSXN66.mjs +0 -76
  56. package/dist/index.d.mts +0 -104
  57. package/dist/richtext-l2BRZFEP.d.mts +0 -218
  58. package/dist/richtext-l2BRZFEP.d.ts +0 -218
  59. package/dist/rsc.js +0 -322
  60. package/dist/rsc.mjs +0 -73
  61. package/dist/ssr.d.mts +0 -96
  62. package/dist/ssr.d.ts +0 -96
  63. package/dist/ssr.js +0 -223
  64. package/dist/ssr.mjs +0 -38
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @localess/react/ssr
3
+ *
4
+ * Server-side rendering export — safe for SSR and Next.js static site generation (`output: 'export'`).
5
+ * Does NOT include live Visual Editor editing, client-side hooks, or any browser-only utilities.
6
+ * This is the smallest bundle of the three exports.
7
+ *
8
+ * Use this export when:
9
+ * - Using Next.js with `output: 'export'` (static site generation)
10
+ * - Server-side rendering where live editing is not required
11
+ * - You want to minimise bundle size by excluding all sync/bridge code
12
+ *
13
+ * For the default SPA export use `@localess/react`.
14
+ * For React Server Components with live editing use `@localess/react/rsc`.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { localessInit, LocalessServerComponent } from '@localess/react/ssr';
19
+ * ```
20
+ *
21
+ * NOT available in this export:
22
+ * - LocalessDocument (requires 'use client')
23
+ * - useLocaless (requires 'use client')
24
+ * - localessEditable / localessEditableField / isBrowser / isIframe (browser-only)
25
+ * - isSyncEnabled (not meaningful without live editing)
26
+ * - Sync event types (LocalessSync, EventToApp, EventCallback, EventToAppType)
27
+ */
28
+ export { localessInit, getLocalessClient, registerComponent, unregisterComponent, getComponent, getFallbackComponent, resolveAsset, } from '../core/state';
29
+ export * from './localess-component';
30
+ export * from './localess-document';
31
+ export { renderRichTextToReact } from '../core/richtext';
32
+ export * from '../core/utils';
33
+ export type * from '../core/models';
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../core/state.js`),t=require(`../core/utils/link.util.js`),n=require(`../core/richtext.js`),r=require(`./localess-component.js`),i=require(`./localess-document.js`);let a=require(`@localess/client`);exports.LocalessServerComponent=r.LocalessServerComponent,exports.LocalessServerDocument=i.LocalessServerDocument,exports.findLink=t.findLink,exports.getComponent=e.getComponent,exports.getFallbackComponent=e.getFallbackComponent,exports.getLocalessClient=e.getLocalessClient,Object.defineProperty(exports,`isBrowser`,{enumerable:!0,get:function(){return a.isBrowser}}),Object.defineProperty(exports,`isIframe`,{enumerable:!0,get:function(){return a.isIframe}}),Object.defineProperty(exports,`isServer`,{enumerable:!0,get:function(){return a.isServer}}),Object.defineProperty(exports,`localessEditable`,{enumerable:!0,get:function(){return a.localessEditable}}),Object.defineProperty(exports,`localessEditableField`,{enumerable:!0,get:function(){return a.localessEditableField}}),exports.localessInit=e.localessInit,exports.registerComponent=e.registerComponent,exports.renderRichTextToReact=n.renderRichTextToReact,exports.resolveAsset=e.resolveAsset,exports.unregisterComponent=e.unregisterComponent;
@@ -0,0 +1,7 @@
1
+ import { getComponent as e, getFallbackComponent as t, getLocalessClient as n, localessInit as r, registerComponent as i, resolveAsset as a, unregisterComponent as o } from "../core/state.mjs";
2
+ import { findLink as s } from "../core/utils/link.util.mjs";
3
+ import { isBrowser as c, isIframe as l, isServer as u, localessEditable as d, localessEditableField as f } from "../core/utils/index.mjs";
4
+ import { renderRichTextToReact as p } from "../core/richtext.mjs";
5
+ import { LocalessServerComponent as m } from "./localess-component.mjs";
6
+ import { LocalessServerDocument as h } from "./localess-document.mjs";
7
+ export { m as LocalessServerComponent, h as LocalessServerDocument, s as findLink, e as getComponent, t as getFallbackComponent, n as getLocalessClient, c as isBrowser, l as isIframe, u as isServer, d as localessEditable, f as localessEditableField, r as localessInit, i as registerComponent, p as renderRichTextToReact, a as resolveAsset, o as unregisterComponent };
@@ -0,0 +1,48 @@
1
+ import { ContentData, Links, References } from '../core/models';
2
+ /**
3
+ * Props for {@link LocalessServerComponent}.
4
+ *
5
+ * @template T - The content data shape. Defaults to the base {@link ContentData} type.
6
+ */
7
+ export type LocalessServerComponentProps<T extends ContentData = ContentData> = {
8
+ /**
9
+ * The content data object to render. Must have a `_schema` field that matches a key
10
+ * in the component registry configured via `localessInit`.
11
+ */
12
+ data: T;
13
+ /**
14
+ * Optional map of content links keyed by link ID.
15
+ * Pass through to child components so they can resolve {@link ContentLink} values with `findLink`.
16
+ */
17
+ links?: Links;
18
+ /**
19
+ * Optional map of resolved content references keyed by reference ID.
20
+ * Pass through to child components that consume referenced content.
21
+ */
22
+ references?: References;
23
+ };
24
+ /**
25
+ * Server-safe dynamic schema-to-component renderer for SSR and static-export environments.
26
+ *
27
+ * Equivalent to {@link LocalessComponent} but intentionally omits Visual Editor sync
28
+ * attribute injection (`localessEditable`), making it safe for:
29
+ * - Next.js static exports (`output: 'export'`)
30
+ * - Server-side rendering where live editing is not needed
31
+ *
32
+ * Looks up `data._schema` in the component registry, renders the matched component,
33
+ * falls back to the `fallbackComponent` if registered, or renders an inline error.
34
+ *
35
+ * **No `'use client'` directive** — safe to render in React Server Components.
36
+ * If you need live Visual Editor editing use {@link LocalessComponent} from
37
+ * `@localess/react` or `@localess/react/rsc` instead.
38
+ *
39
+ * @template T - The content data shape. Defaults to {@link ContentData}.
40
+ *
41
+ * @example
42
+ * ```tsx
43
+ * import { LocalessServerComponent } from '@localess/react/ssr';
44
+ *
45
+ * <LocalessServerComponent data={content.data} links={content.links} references={content.references} />
46
+ * ```
47
+ */
48
+ export declare const LocalessServerComponent: import('react').ForwardRefExoticComponent<LocalessServerComponentProps<ContentData> & import('react').RefAttributes<HTMLElement>>;
@@ -0,0 +1 @@
1
+ const e=require(`../console.js`),t=require(`../core/state.js`);let n=require(`react`),r=require(`react/jsx-runtime`);var i=(0,n.forwardRef)(({data:n,links:i,references:a,...o},s)=>{if(!n)return console.error(`LocalessServerComponent property %cdata%c is not provided.`,e.FONT_BOLD,e.FONT_NORMAL),(0,r.jsxs)(`div`,{children:[`LocalessServerComponent property `,(0,r.jsx)(`b`,{children:`data`}),` is not provided.`]});let c=t.getComponent(n._schema);if(c)return(0,r.jsx)(c,{ref:s,data:n,links:i,references:a,...o});let l=t.getFallbackComponent();return l?(0,r.jsx)(l,{ref:s,data:n,links:i,references:a,...o}):(0,r.jsxs)(`p`,{children:[(0,r.jsx)(`b`,{children:`LocalessServerComponent`}),` 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.LocalessServerComponent=i;
@@ -0,0 +1,37 @@
1
+ import { FONT_BOLD as e, FONT_NORMAL as t } from "../console.mjs";
2
+ import { getComponent as n, getFallbackComponent as r } from "../core/state.mjs";
3
+ import { forwardRef as i } from "react";
4
+ import { jsx as a, jsxs as o } from "react/jsx-runtime";
5
+ //#region src/ssr/localess-component.tsx
6
+ var s = i(({ data: i, links: s, references: c, ...l }, u) => {
7
+ if (!i) return console.error("LocalessServerComponent property %cdata%c is not provided.", e, t), /* @__PURE__ */ o("div", { children: [
8
+ "LocalessServerComponent property ",
9
+ /* @__PURE__ */ a("b", { children: "data" }),
10
+ " is not provided."
11
+ ] });
12
+ let d = n(i._schema);
13
+ if (d) return /* @__PURE__ */ a(d, {
14
+ ref: u,
15
+ data: i,
16
+ links: s,
17
+ references: c,
18
+ ...l
19
+ });
20
+ let f = r();
21
+ return f ? /* @__PURE__ */ a(f, {
22
+ ref: u,
23
+ data: i,
24
+ links: s,
25
+ references: c,
26
+ ...l
27
+ }) : /* @__PURE__ */ o("p", { children: [
28
+ /* @__PURE__ */ a("b", { children: "LocalessServerComponent" }),
29
+ " could not found component with key ",
30
+ /* @__PURE__ */ a("b", { children: i._schema }),
31
+ ". ",
32
+ /* @__PURE__ */ a("br", {}),
33
+ "Please check if your configuration is correct."
34
+ ] });
35
+ });
36
+ //#endregion
37
+ export { s as LocalessServerComponent };
@@ -0,0 +1,42 @@
1
+ import { Content, ContentData } from '../core/models';
2
+ /**
3
+ * Props for {@link LocalessServerDocument}.
4
+ *
5
+ * @template T - The content data shape. Defaults to the base {@link ContentData} type.
6
+ */
7
+ export type LocalessServerDocumentProps<T extends ContentData = ContentData> = {
8
+ /**
9
+ * The full content response object as returned by `getContentBySlug` or `getContentById`.
10
+ * Must contain a `data` field with a valid `_schema` key.
11
+ */
12
+ document: Content<T>;
13
+ };
14
+ /**
15
+ * Server-safe document renderer for SSR and static-export environments.
16
+ *
17
+ * Accepts the full {@link Content} wrapper (as returned by `getContentBySlug` /
18
+ * `getContentById`) and delegates to {@link LocalessServerComponent}, automatically
19
+ * passing `data`, `links`, and `references` through.
20
+ *
21
+ * This is a convenience wrapper — use it when you want to render a fetched
22
+ * `Content<T>` object without manually destructuring it.
23
+ *
24
+ * **No live editing** — does not subscribe to Visual Editor sync events.
25
+ * For live Visual Editor editing use {@link LocalessDocument} from `@localess/react/rsc`.
26
+ *
27
+ * **No `'use client'` directive** — safe to render in React Server Components
28
+ * and Next.js static export pages.
29
+ *
30
+ * @template T - The content data shape. Defaults to {@link ContentData}.
31
+ *
32
+ * @example
33
+ * ```tsx
34
+ * import { LocalessServerDocument } from '@localess/react/ssr';
35
+ *
36
+ * // Server Component or getServerSideProps
37
+ * const content = await getLocalessClient().getContentBySlug<MyPage>('home', { locale: 'en' });
38
+ *
39
+ * return <LocalessServerDocument document={content} />;
40
+ * ```
41
+ */
42
+ export declare const LocalessServerDocument: import('react').ForwardRefExoticComponent<LocalessServerDocumentProps<ContentData> & import('react').RefAttributes<HTMLElement>>;
@@ -0,0 +1 @@
1
+ const e=require(`../console.js`),t=require(`./localess-component.js`);let n=require(`react`),r=require(`react/jsx-runtime`);var i=(0,n.forwardRef)(({document:n},i)=>n.data?(0,r.jsx)(t.LocalessServerComponent,{ref:i,data:n.data,links:n.links,references:n.references}):(console.error(`LocalessServerDocument property %cdocument.data%c is not provided.`,e.FONT_BOLD,e.FONT_NORMAL),(0,r.jsxs)(`div`,{children:[`LocalessServerDocument property `,(0,r.jsx)(`b`,{children:`document.data`}),` is not provided.`]})));exports.LocalessServerDocument=i;
@@ -0,0 +1,17 @@
1
+ import { FONT_BOLD as e, FONT_NORMAL as t } from "../console.mjs";
2
+ import { LocalessServerComponent as n } from "./localess-component.mjs";
3
+ import { forwardRef as r } from "react";
4
+ import { jsx as i, jsxs as a } from "react/jsx-runtime";
5
+ //#region src/ssr/localess-document.tsx
6
+ var o = r(({ document: r }, o) => r.data ? /* @__PURE__ */ i(n, {
7
+ ref: o,
8
+ data: r.data,
9
+ links: r.links,
10
+ references: r.references
11
+ }) : (console.error("LocalessServerDocument property %cdocument.data%c is not provided.", e, t), /* @__PURE__ */ a("div", { children: [
12
+ "LocalessServerDocument property ",
13
+ /* @__PURE__ */ i("b", { children: "document.data" }),
14
+ " is not provided."
15
+ ] })));
16
+ //#endregion
17
+ export { o as LocalessServerDocument };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@localess/react",
3
- "version": "3.0.1-dev.20260410071322",
3
+ "version": "3.0.1-dev.20260412201733",
4
4
  "description": "ReactJS JavaScript/TypeScript SDK for Localess's API.",
5
5
  "keywords": [
6
6
  "localess",
@@ -36,52 +36,60 @@
36
36
  "require": "./dist/index.js"
37
37
  },
38
38
  "./ssr": {
39
- "types": "./dist/ssr.d.ts",
40
- "import": "./dist/ssr.mjs",
41
- "require": "./dist/ssr.js"
39
+ "types": "./dist/ssr/index.d.ts",
40
+ "import": "./dist/ssr/index.mjs",
41
+ "require": "./dist/ssr/index.js"
42
42
  },
43
43
  "./rsc": {
44
- "types": "./dist/rsc.d.ts",
45
- "import": "./dist/rsc.mjs",
46
- "require": "./dist/rsc.js"
44
+ "types": "./dist/rsc/index.d.ts",
45
+ "import": "./dist/rsc/index.mjs",
46
+ "require": "./dist/rsc/index.js"
47
+ },
48
+ "./rsc/client": {
49
+ "types": "./dist/rsc/client.d.ts",
50
+ "import": "./dist/rsc/client.mjs",
51
+ "require": "./dist/rsc/client.js"
47
52
  }
48
53
  },
49
54
  "private": false,
50
55
  "license": "MIT",
51
56
  "scripts": {
52
- "build": "tsup"
57
+ "build": "vite build"
53
58
  },
54
59
  "peerDependencies": {
55
60
  "react": "^17 || ^18 || ^19",
56
61
  "react-dom": "^17 || ^18 || ^19"
57
62
  },
58
63
  "dependencies": {
59
- "@localess/client": "3.0.1-dev.20260410071322",
60
- "@tiptap/static-renderer": "^3.20.1",
61
- "@tiptap/html": "^3.20.1",
64
+ "@localess/client": "3.0.1-dev.20260412201733",
62
65
  "@tiptap/extension-bold": "^3.20.1",
63
- "@tiptap/extension-italic": "^3.20.1",
64
- "@tiptap/extension-strike": "^3.20.1",
65
- "@tiptap/extension-underline": "^3.20.1",
66
- "@tiptap/extension-document": "^3.20.1",
67
- "@tiptap/extension-text": "^3.20.1",
68
- "@tiptap/extension-paragraph": "^3.20.1",
69
- "@tiptap/extension-history": "^3.20.1",
70
- "@tiptap/extension-list-item": "^3.20.1",
71
66
  "@tiptap/extension-bullet-list": "^3.20.1",
72
- "@tiptap/extension-ordered-list": "^3.20.1",
73
67
  "@tiptap/extension-code": "^3.20.1",
74
68
  "@tiptap/extension-code-block-lowlight": "^3.20.1",
69
+ "@tiptap/extension-document": "^3.20.1",
70
+ "@tiptap/extension-heading": "^3.20.1",
71
+ "@tiptap/extension-history": "^3.20.1",
72
+ "@tiptap/extension-italic": "^3.20.1",
75
73
  "@tiptap/extension-link": "^3.20.1",
76
- "@tiptap/extension-heading": "^3.20.1"
74
+ "@tiptap/extension-list-item": "^3.20.1",
75
+ "@tiptap/extension-ordered-list": "^3.20.1",
76
+ "@tiptap/extension-paragraph": "^3.20.1",
77
+ "@tiptap/extension-strike": "^3.20.1",
78
+ "@tiptap/extension-text": "^3.20.1",
79
+ "@tiptap/extension-underline": "^3.20.1",
80
+ "@tiptap/html": "^3.20.1",
81
+ "@tiptap/static-renderer": "^3.20.1"
77
82
  },
78
83
  "devDependencies": {
79
- "@types/react": "^19.0.0",
80
84
  "@types/node": "^20",
85
+ "@types/react": "^19.0.0",
86
+ "@vitejs/plugin-react": "^6.0.1",
81
87
  "react": "^19.0.0",
82
88
  "react-dom": "^19.0.0",
83
- "tsup": "^8.5.1",
84
- "typescript": "^5.9.3"
89
+ "rollup-preserve-directives": "^1.1.3",
90
+ "typescript": "^5.9.3",
91
+ "vite": "^8.0.8",
92
+ "vite-plugin-dts": "^4.5.4"
85
93
  },
86
94
  "engines": {
87
95
  "node": ">= 20.0.0"
@@ -1,56 +0,0 @@
1
- import {
2
- FONT_BOLD,
3
- FONT_NORMAL,
4
- getComponent,
5
- getFallbackComponent
6
- } from "./chunk-ETSLIILF.mjs";
7
-
8
- // src/ssr/localess-component.tsx
9
- import { forwardRef } from "react";
10
- import { jsx, jsxs } from "react/jsx-runtime";
11
- var LocalessServerComponent = forwardRef(({ data, links, references, ...restProps }, ref) => {
12
- if (!data) {
13
- console.error("LocalessServerComponent property %cdata%c is not provided.", FONT_BOLD, FONT_NORMAL);
14
- return /* @__PURE__ */ jsxs("div", { children: [
15
- "LocalessServerComponent property ",
16
- /* @__PURE__ */ jsx("b", { children: "data" }),
17
- " is not provided."
18
- ] });
19
- }
20
- const Comp = getComponent(data._schema);
21
- if (Comp) {
22
- return /* @__PURE__ */ jsx(Comp, { ref, data, links, references, ...restProps });
23
- }
24
- const FallbackComponent = getFallbackComponent();
25
- if (FallbackComponent) {
26
- return /* @__PURE__ */ jsx(FallbackComponent, { ref, data, links, references, ...restProps });
27
- }
28
- return /* @__PURE__ */ jsxs("p", { children: [
29
- /* @__PURE__ */ jsx("b", { children: "LocalessServerComponent" }),
30
- " could not found component with key ",
31
- /* @__PURE__ */ jsx("b", { children: data._schema }),
32
- ". ",
33
- /* @__PURE__ */ jsx("br", {}),
34
- "Please check if your configuration is correct."
35
- ] });
36
- });
37
-
38
- // src/ssr/localess-document.tsx
39
- import { forwardRef as forwardRef2 } from "react";
40
- import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
41
- var LocalessServerDocument = forwardRef2(({ document }, ref) => {
42
- if (!document || !document.data) {
43
- console.error("LocalessServerDocument property %cdocument.data%c is not provided.", FONT_BOLD, FONT_NORMAL);
44
- return /* @__PURE__ */ jsxs2("div", { children: [
45
- "LocalessServerDocument property ",
46
- /* @__PURE__ */ jsx2("b", { children: "document.data" }),
47
- " is not provided."
48
- ] });
49
- }
50
- return /* @__PURE__ */ jsx2(LocalessServerComponent, { ref, data: document.data, links: document.links, references: document.references });
51
- });
52
-
53
- export {
54
- LocalessServerComponent,
55
- LocalessServerDocument
56
- };
@@ -1,149 +0,0 @@
1
- // src/core/state.ts
2
- import { loadLocalessSync, localessClient } from "@localess/client";
3
-
4
- // src/console.ts
5
- var FONT_BOLD = "font-weight: bold";
6
- var FONT_NORMAL = "font-weight: normal";
7
-
8
- // src/core/state.ts
9
- var _client = void 0;
10
- var _components = {};
11
- var _fallbackComponent = void 0;
12
- var _enableSync = false;
13
- var _assetPathPrefix = "";
14
- function localessInit(options) {
15
- console.log("localessInit", options);
16
- const { components, fallbackComponent, enableSync, ...restOptions } = options;
17
- _client = localessClient(restOptions);
18
- _assetPathPrefix = `${options.origin}/api/v1/spaces/${options.spaceId}/assets/`;
19
- _components = components || {};
20
- _fallbackComponent = fallbackComponent;
21
- if (enableSync) {
22
- _enableSync = true;
23
- loadLocalessSync(restOptions.origin);
24
- }
25
- return _client;
26
- }
27
- function getLocalessClient() {
28
- if (!_client) {
29
- console.error("[Localess] No client found. Please check if the Localess is initialized.");
30
- throw new Error("[Localess] No client found.");
31
- }
32
- return _client;
33
- }
34
- function registerComponent(key, component) {
35
- _components[key] = component;
36
- }
37
- function unregisterComponent(key) {
38
- delete _components[key];
39
- }
40
- function setComponents(components) {
41
- _components = components;
42
- }
43
- function getComponent(key) {
44
- if (Object.hasOwn(_components, key)) {
45
- return _components[key];
46
- }
47
- console.error(`[Localess] component %c${key}%c can't be found.`, FONT_BOLD, FONT_NORMAL);
48
- return void 0;
49
- }
50
- function setFallbackComponent(fallbackComponent) {
51
- _fallbackComponent = fallbackComponent;
52
- }
53
- function getFallbackComponent() {
54
- return _fallbackComponent;
55
- }
56
- function isSyncEnabled() {
57
- return _enableSync;
58
- }
59
- function resolveAsset(asset) {
60
- return `${_assetPathPrefix}${asset.uri}`;
61
- }
62
-
63
- // src/core/utils/link.util.ts
64
- function findLink(links, link) {
65
- switch (link.type) {
66
- case "content": {
67
- if (links) {
68
- const path = links[link.uri];
69
- if (path) {
70
- return "/" + path.fullSlug;
71
- } else {
72
- return "/not-found";
73
- }
74
- }
75
- return "/not-found";
76
- }
77
- case "url":
78
- return link.uri;
79
- default:
80
- return "no-type";
81
- }
82
- }
83
-
84
- // src/core/utils/index.ts
85
- import { localessEditable, localessEditableField, isBrowser, isServer, isIframe } from "@localess/client";
86
-
87
- // src/core/richtext.ts
88
- import { renderToReactElement } from "@tiptap/static-renderer/pm/react";
89
- import { Document } from "@tiptap/extension-document";
90
- import { Text } from "@tiptap/extension-text";
91
- import { Paragraph } from "@tiptap/extension-paragraph";
92
- import { Heading } from "@tiptap/extension-heading";
93
- import { Bold } from "@tiptap/extension-bold";
94
- import { Italic } from "@tiptap/extension-italic";
95
- import { Strike } from "@tiptap/extension-strike";
96
- import { Underline } from "@tiptap/extension-underline";
97
- import { History } from "@tiptap/extension-history";
98
- import { ListItem } from "@tiptap/extension-list-item";
99
- import { OrderedList } from "@tiptap/extension-ordered-list";
100
- import { BulletList } from "@tiptap/extension-bullet-list";
101
- import { Code } from "@tiptap/extension-code";
102
- import { CodeBlockLowlight } from "@tiptap/extension-code-block-lowlight";
103
- import { Link } from "@tiptap/extension-link";
104
- function renderRichTextToReact(content) {
105
- return renderToReactElement({
106
- content,
107
- extensions: [
108
- Document,
109
- Text,
110
- Paragraph,
111
- Heading.configure({
112
- levels: [1, 2, 3, 4, 5, 6]
113
- }),
114
- Bold,
115
- Italic,
116
- Strike,
117
- Underline,
118
- History,
119
- ListItem,
120
- OrderedList,
121
- BulletList,
122
- Code,
123
- CodeBlockLowlight,
124
- Link
125
- ]
126
- });
127
- }
128
-
129
- export {
130
- FONT_BOLD,
131
- FONT_NORMAL,
132
- localessInit,
133
- getLocalessClient,
134
- registerComponent,
135
- unregisterComponent,
136
- setComponents,
137
- getComponent,
138
- setFallbackComponent,
139
- getFallbackComponent,
140
- isSyncEnabled,
141
- resolveAsset,
142
- findLink,
143
- localessEditable,
144
- localessEditableField,
145
- isBrowser,
146
- isServer,
147
- isIframe,
148
- renderRichTextToReact
149
- };
@@ -1,76 +0,0 @@
1
- import {
2
- FONT_BOLD,
3
- FONT_NORMAL,
4
- getComponent,
5
- getFallbackComponent,
6
- getLocalessClient,
7
- isSyncEnabled,
8
- localessEditable
9
- } from "./chunk-ETSLIILF.mjs";
10
-
11
- // src/core/components/localess-component.tsx
12
- import { forwardRef } from "react";
13
- import { jsx, jsxs } from "react/jsx-runtime";
14
- var LocalessComponent = forwardRef(
15
- ({ data, links, references, ...restProps }, ref) => {
16
- if (!data) {
17
- console.error("LocalessComponent property %cdata%c is not provided.", FONT_BOLD, FONT_NORMAL);
18
- return /* @__PURE__ */ jsxs("div", { children: [
19
- "LocalessComponent property ",
20
- /* @__PURE__ */ jsx("b", { children: "data" }),
21
- " is not provided."
22
- ] });
23
- }
24
- const Comp = getComponent(data._schema);
25
- if (Comp) {
26
- const attr = isSyncEnabled() ? localessEditable(data) : {};
27
- return /* @__PURE__ */ jsx(Comp, { ref, data, links, references, ...attr, ...restProps });
28
- }
29
- const FallbackComponent = getFallbackComponent();
30
- if (FallbackComponent) {
31
- return /* @__PURE__ */ jsx(FallbackComponent, { ref, data, links, references, ...restProps });
32
- }
33
- return /* @__PURE__ */ jsxs("p", { children: [
34
- /* @__PURE__ */ jsx("b", { children: "LocalessComponent" }),
35
- " could not found component with key ",
36
- /* @__PURE__ */ jsx("b", { children: data._schema }),
37
- ". ",
38
- /* @__PURE__ */ jsx("br", {}),
39
- "Please check if your configuration is correct."
40
- ] });
41
- }
42
- );
43
-
44
- // src/core/hooks/use-localess.ts
45
- import { useEffect, useState } from "react";
46
- import { isBrowser } from "@localess/client";
47
- var useLocaless = (slug, options = {}) => {
48
- const [document, setDocument] = useState();
49
- const client = getLocalessClient();
50
- let normalizedSlug;
51
- if (Array.isArray(slug)) {
52
- normalizedSlug = slug.join("/");
53
- } else {
54
- normalizedSlug = slug;
55
- }
56
- useEffect(() => {
57
- async function loadDocument() {
58
- const document2 = await client.getContentBySlug(normalizedSlug, options);
59
- setDocument(document2);
60
- if (isSyncEnabled() && isBrowser()) {
61
- window.localess?.on(["input", "change"], (event) => {
62
- if (event.type === "change" || event.type === "input") {
63
- setDocument({ ...document2, data: event.data });
64
- }
65
- });
66
- }
67
- }
68
- loadDocument();
69
- }, [slug, options, client]);
70
- return document;
71
- };
72
-
73
- export {
74
- LocalessComponent,
75
- useLocaless
76
- };