@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.
- package/dist/console.d.ts +2 -0
- package/dist/console.js +1 -0
- package/dist/console.mjs +4 -0
- package/dist/core/components/index.d.ts +8 -0
- package/dist/core/components/localess-component.d.ts +54 -0
- package/dist/core/components/localess-component.js +1 -0
- package/dist/core/components/localess-component.mjs +39 -0
- package/dist/{rsc.d.ts → core/components/localess-document.d.ts} +6 -25
- package/dist/core/components/localess-document.js +1 -0
- package/dist/core/components/localess-document.mjs +26 -0
- package/dist/core/hooks/index.d.ts +9 -0
- package/dist/core/hooks/use-localess.d.ts +45 -0
- package/dist/core/hooks/use-localess.js +1 -0
- package/dist/core/hooks/use-localess.mjs +25 -0
- package/dist/core/models/client.d.ts +43 -0
- package/dist/core/models/content.d.ts +1 -0
- package/dist/core/models/index.d.ts +33 -0
- package/dist/core/models/sync.d.ts +1 -0
- package/dist/core/models/translation.d.ts +1 -0
- package/dist/core/richtext.d.ts +26 -0
- package/dist/core/richtext.js +1 -0
- package/dist/core/richtext.mjs +48 -0
- package/dist/core/state.d.ts +127 -0
- package/dist/core/state.js +1 -0
- package/dist/core/state.mjs +43 -0
- package/dist/core/utils/index.d.ts +19 -0
- package/dist/core/utils/index.mjs +3 -0
- package/dist/core/utils/link.util.d.ts +24 -0
- package/dist/core/utils/link.util.js +1 -0
- package/dist/core/utils/link.util.mjs +15 -0
- package/dist/index.d.ts +19 -97
- package/dist/index.js +1 -257
- package/dist/index.mjs +8 -44
- package/dist/rsc/index.d.ts +30 -0
- package/dist/rsc/index.js +1 -0
- package/dist/rsc/index.mjs +9 -0
- package/dist/{rsc.d.mts → rsc/localess-document.d.ts} +6 -25
- package/dist/rsc/localess-document.js +1 -0
- package/dist/rsc/localess-document.mjs +23 -0
- package/dist/rsc/localess-sync.d.ts +7 -0
- package/dist/rsc/localess-sync.js +1 -0
- package/dist/rsc/localess-sync.mjs +12 -0
- package/dist/ssr/index.d.ts +33 -0
- package/dist/ssr/index.js +1 -0
- package/dist/ssr/index.mjs +7 -0
- package/dist/ssr/localess-component.d.ts +48 -0
- package/dist/ssr/localess-component.js +1 -0
- package/dist/ssr/localess-component.mjs +37 -0
- package/dist/ssr/localess-document.d.ts +42 -0
- package/dist/ssr/localess-document.js +1 -0
- package/dist/ssr/localess-document.mjs +17 -0
- package/package.json +32 -24
- package/dist/chunk-AJP75NRT.mjs +0 -56
- package/dist/chunk-ETSLIILF.mjs +0 -149
- package/dist/chunk-V6JSXN66.mjs +0 -76
- package/dist/index.d.mts +0 -104
- package/dist/richtext-l2BRZFEP.d.mts +0 -218
- package/dist/richtext-l2BRZFEP.d.ts +0 -218
- package/dist/rsc.js +0 -322
- package/dist/rsc.mjs +0 -73
- package/dist/ssr.d.mts +0 -96
- package/dist/ssr.d.ts +0 -96
- package/dist/ssr.js +0 -223
- package/dist/ssr.mjs +0 -38
|
@@ -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;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/core/utils/link.util.ts
|
|
2
|
+
function e(e, t) {
|
|
3
|
+
switch (t.type) {
|
|
4
|
+
case "content":
|
|
5
|
+
if (e) {
|
|
6
|
+
let n = e[t.uri];
|
|
7
|
+
return n ? "/" + n.fullSlug : "/not-found";
|
|
8
|
+
}
|
|
9
|
+
return "/not-found";
|
|
10
|
+
case "url": return t.uri;
|
|
11
|
+
default: return "no-type";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { e as findLink };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,104 +1,26 @@
|
|
|
1
|
-
export { L as LocalessOptions, f as findLink, g as getComponent, a as getFallbackComponent, b as getLocalessClient, i as isSyncEnabled, l as localessInit, r as registerComponent, c as renderRichTextToReact, d as resolveAsset, s as setComponents, e as setFallbackComponent, u as unregisterComponent } from './richtext-l2BRZFEP.js';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { ContentData, Links, References, ContentFetchParams, 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
|
-
|
|
6
1
|
/**
|
|
7
|
-
*
|
|
2
|
+
* @localess/react
|
|
8
3
|
*
|
|
9
|
-
*
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* The content data object to render. Must have a `_schema` field that matches a key
|
|
14
|
-
* in the component registry configured via `localessInit`.
|
|
15
|
-
*/
|
|
16
|
-
data: T;
|
|
17
|
-
/**
|
|
18
|
-
* Optional map of content links keyed by link ID.
|
|
19
|
-
* Pass through to child components so they can resolve {@link ContentLink} values with `findLink`.
|
|
20
|
-
*/
|
|
21
|
-
links?: Links;
|
|
22
|
-
/**
|
|
23
|
-
* Optional map of resolved content references keyed by reference ID.
|
|
24
|
-
* Pass through to child components that consume referenced content.
|
|
25
|
-
*/
|
|
26
|
-
references?: References;
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* Dynamic schema-to-component renderer for use in SPA and client-side contexts.
|
|
30
|
-
*
|
|
31
|
-
* Looks up `data._schema` in the component registry (set via `localessInit` or `setComponents`),
|
|
32
|
-
* renders the matched component, and — when Visual Editor sync is active — automatically
|
|
33
|
-
* spreads `localessEditable` attributes on the root element for live targeting.
|
|
34
|
-
*
|
|
35
|
-
* Falls back to the `fallbackComponent` (if registered) when the schema key is not found,
|
|
36
|
-
* or renders an inline error message as a last resort.
|
|
37
|
-
*
|
|
38
|
-
* **Server-safe** — does not include a `'use client'` directive and can be used in
|
|
39
|
-
* React Server Components. For SSR / static-export environments use {@link LocalessServerComponent}
|
|
40
|
-
* from `@localess/react/ssr` instead, which omits the sync attribute injection.
|
|
41
|
-
*
|
|
42
|
-
* @template T - The content data shape. Defaults to {@link ContentData}.
|
|
43
|
-
*
|
|
44
|
-
* @example Basic usage
|
|
45
|
-
* ```tsx
|
|
46
|
-
* import { LocalessComponent } from '@localess/react';
|
|
47
|
-
*
|
|
48
|
-
* <LocalessComponent data={content.data} links={content.links} references={content.references} />
|
|
49
|
-
* ```
|
|
50
|
-
*
|
|
51
|
-
* @example Rendering a list of nested blocks
|
|
52
|
-
* ```tsx
|
|
53
|
-
* {data.body.map(item => (
|
|
54
|
-
* <LocalessComponent key={item._id} data={item} links={content.links} references={content.references} />
|
|
55
|
-
* ))}
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
declare const LocalessComponent: React.ForwardRefExoticComponent<LocalessComponentProps<ContentData> & React.RefAttributes<HTMLElement>>;
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Options for {@link useLocaless}.
|
|
62
|
-
* Extends {@link ContentFetchParams} with any future hook-specific settings.
|
|
63
|
-
*/
|
|
64
|
-
type UseLocalessOptions = ContentFetchParams & {};
|
|
65
|
-
/**
|
|
66
|
-
* React hook for fetching Localess content by slug inside a Client Component.
|
|
67
|
-
*
|
|
68
|
-
* Fetches content on mount using `getLocalessClient().getContentBySlug`, stores it in local state,
|
|
69
|
-
* and — when `enableSync` is active and the page is running inside the Visual Editor iframe —
|
|
70
|
-
* automatically subscribes to `input` and `change` events so content updates live without a reload.
|
|
4
|
+
* Default export — Single Page Applications (SPA) and fully client-rendered React apps.
|
|
5
|
+
* Includes the complete API: initialization, component registry, components, hooks,
|
|
6
|
+
* Visual Editor live editing helpers, rich text rendering, and all TypeScript types.
|
|
71
7
|
*
|
|
72
|
-
*
|
|
8
|
+
* Use this export when:
|
|
9
|
+
* - Building a Single Page Application (SPA) or client-rendered React app
|
|
10
|
+
* - All code runs in the browser (no server components)
|
|
11
|
+
* - You need live Visual Editor editing in browser-based applications
|
|
73
12
|
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* ```tsx
|
|
77
|
-
* const content = useLocaless('home', { locale }) ?? initialContent;
|
|
78
|
-
* ```
|
|
79
|
-
*
|
|
80
|
-
* @template T - The content data shape. Defaults to {@link ContentData}.
|
|
81
|
-
*
|
|
82
|
-
* @param slug - Content slug string, or an array of path segments that will be joined with `/`.
|
|
83
|
-
* @param options - Optional fetch parameters (locale, version, resolveReference, resolveLink).
|
|
84
|
-
* @returns The fetched {@link Content}<T> object, or `undefined` while the initial fetch is in flight.
|
|
85
|
-
*
|
|
86
|
-
* @example Basic usage
|
|
87
|
-
* ```tsx
|
|
88
|
-
* 'use client';
|
|
89
|
-
* import { useLocaless } from '@localess/react/rsc';
|
|
90
|
-
*
|
|
91
|
-
* export function PageClient({ initialContent, locale }) {
|
|
92
|
-
* const content = useLocaless('home', { locale }) ?? initialContent;
|
|
93
|
-
* return <LocalessComponent data={content.data} links={content.links} />;
|
|
94
|
-
* }
|
|
95
|
-
* ```
|
|
13
|
+
* For server-rendering without live editing use `@localess/react/ssr`.
|
|
14
|
+
* For React Server Components with live editing use `@localess/react/rsc`.
|
|
96
15
|
*
|
|
97
|
-
* @example
|
|
98
|
-
* ```
|
|
99
|
-
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { localessInit, LocalessComponent, useLocaless, localessEditable } from '@localess/react';
|
|
100
19
|
* ```
|
|
101
20
|
*/
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
export
|
|
21
|
+
export * from './core/state';
|
|
22
|
+
export * from './core/components';
|
|
23
|
+
export * from './core/hooks';
|
|
24
|
+
export * from './core/utils';
|
|
25
|
+
export * from './core/richtext';
|
|
26
|
+
export type * from './core/models';
|
package/dist/index.js
CHANGED
|
@@ -1,257 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
LocalessComponent: () => LocalessComponent,
|
|
24
|
-
findLink: () => findLink,
|
|
25
|
-
getComponent: () => getComponent,
|
|
26
|
-
getFallbackComponent: () => getFallbackComponent,
|
|
27
|
-
getLocalessClient: () => getLocalessClient,
|
|
28
|
-
isBrowser: () => import_client2.isBrowser,
|
|
29
|
-
isIframe: () => import_client2.isIframe,
|
|
30
|
-
isServer: () => import_client2.isServer,
|
|
31
|
-
isSyncEnabled: () => isSyncEnabled,
|
|
32
|
-
localessEditable: () => import_client2.localessEditable,
|
|
33
|
-
localessEditableField: () => import_client2.localessEditableField,
|
|
34
|
-
localessInit: () => localessInit,
|
|
35
|
-
registerComponent: () => registerComponent,
|
|
36
|
-
renderRichTextToReact: () => renderRichTextToReact,
|
|
37
|
-
resolveAsset: () => resolveAsset,
|
|
38
|
-
setComponents: () => setComponents,
|
|
39
|
-
setFallbackComponent: () => setFallbackComponent,
|
|
40
|
-
unregisterComponent: () => unregisterComponent,
|
|
41
|
-
useLocaless: () => useLocaless
|
|
42
|
-
});
|
|
43
|
-
module.exports = __toCommonJS(src_exports);
|
|
44
|
-
|
|
45
|
-
// src/core/state.ts
|
|
46
|
-
var import_client = require("@localess/client");
|
|
47
|
-
|
|
48
|
-
// src/console.ts
|
|
49
|
-
var FONT_BOLD = "font-weight: bold";
|
|
50
|
-
var FONT_NORMAL = "font-weight: normal";
|
|
51
|
-
|
|
52
|
-
// src/core/state.ts
|
|
53
|
-
var _client = void 0;
|
|
54
|
-
var _components = {};
|
|
55
|
-
var _fallbackComponent = void 0;
|
|
56
|
-
var _enableSync = false;
|
|
57
|
-
var _assetPathPrefix = "";
|
|
58
|
-
function localessInit(options) {
|
|
59
|
-
console.log("localessInit", options);
|
|
60
|
-
const { components, fallbackComponent, enableSync, ...restOptions } = options;
|
|
61
|
-
_client = (0, import_client.localessClient)(restOptions);
|
|
62
|
-
_assetPathPrefix = `${options.origin}/api/v1/spaces/${options.spaceId}/assets/`;
|
|
63
|
-
_components = components || {};
|
|
64
|
-
_fallbackComponent = fallbackComponent;
|
|
65
|
-
if (enableSync) {
|
|
66
|
-
_enableSync = true;
|
|
67
|
-
(0, import_client.loadLocalessSync)(restOptions.origin);
|
|
68
|
-
}
|
|
69
|
-
return _client;
|
|
70
|
-
}
|
|
71
|
-
function getLocalessClient() {
|
|
72
|
-
if (!_client) {
|
|
73
|
-
console.error("[Localess] No client found. Please check if the Localess is initialized.");
|
|
74
|
-
throw new Error("[Localess] No client found.");
|
|
75
|
-
}
|
|
76
|
-
return _client;
|
|
77
|
-
}
|
|
78
|
-
function registerComponent(key, component) {
|
|
79
|
-
_components[key] = component;
|
|
80
|
-
}
|
|
81
|
-
function unregisterComponent(key) {
|
|
82
|
-
delete _components[key];
|
|
83
|
-
}
|
|
84
|
-
function setComponents(components) {
|
|
85
|
-
_components = components;
|
|
86
|
-
}
|
|
87
|
-
function getComponent(key) {
|
|
88
|
-
if (Object.hasOwn(_components, key)) {
|
|
89
|
-
return _components[key];
|
|
90
|
-
}
|
|
91
|
-
console.error(`[Localess] component %c${key}%c can't be found.`, FONT_BOLD, FONT_NORMAL);
|
|
92
|
-
return void 0;
|
|
93
|
-
}
|
|
94
|
-
function setFallbackComponent(fallbackComponent) {
|
|
95
|
-
_fallbackComponent = fallbackComponent;
|
|
96
|
-
}
|
|
97
|
-
function getFallbackComponent() {
|
|
98
|
-
return _fallbackComponent;
|
|
99
|
-
}
|
|
100
|
-
function isSyncEnabled() {
|
|
101
|
-
return _enableSync;
|
|
102
|
-
}
|
|
103
|
-
function resolveAsset(asset) {
|
|
104
|
-
return `${_assetPathPrefix}${asset.uri}`;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// src/core/components/localess-component.tsx
|
|
108
|
-
var import_react = require("react");
|
|
109
|
-
|
|
110
|
-
// src/core/utils/index.ts
|
|
111
|
-
var import_client2 = require("@localess/client");
|
|
112
|
-
|
|
113
|
-
// src/core/utils/link.util.ts
|
|
114
|
-
function findLink(links, link) {
|
|
115
|
-
switch (link.type) {
|
|
116
|
-
case "content": {
|
|
117
|
-
if (links) {
|
|
118
|
-
const path = links[link.uri];
|
|
119
|
-
if (path) {
|
|
120
|
-
return "/" + path.fullSlug;
|
|
121
|
-
} else {
|
|
122
|
-
return "/not-found";
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return "/not-found";
|
|
126
|
-
}
|
|
127
|
-
case "url":
|
|
128
|
-
return link.uri;
|
|
129
|
-
default:
|
|
130
|
-
return "no-type";
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// src/core/components/localess-component.tsx
|
|
135
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
136
|
-
var LocalessComponent = (0, import_react.forwardRef)(
|
|
137
|
-
({ data, links, references, ...restProps }, ref) => {
|
|
138
|
-
if (!data) {
|
|
139
|
-
console.error("LocalessComponent property %cdata%c is not provided.", FONT_BOLD, FONT_NORMAL);
|
|
140
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
|
|
141
|
-
"LocalessComponent property ",
|
|
142
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("b", { children: "data" }),
|
|
143
|
-
" is not provided."
|
|
144
|
-
] });
|
|
145
|
-
}
|
|
146
|
-
const Comp = getComponent(data._schema);
|
|
147
|
-
if (Comp) {
|
|
148
|
-
const attr = isSyncEnabled() ? (0, import_client2.localessEditable)(data) : {};
|
|
149
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Comp, { ref, data, links, references, ...attr, ...restProps });
|
|
150
|
-
}
|
|
151
|
-
const FallbackComponent = getFallbackComponent();
|
|
152
|
-
if (FallbackComponent) {
|
|
153
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FallbackComponent, { ref, data, links, references, ...restProps });
|
|
154
|
-
}
|
|
155
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { children: [
|
|
156
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("b", { children: "LocalessComponent" }),
|
|
157
|
-
" could not found component with key ",
|
|
158
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("b", { children: data._schema }),
|
|
159
|
-
". ",
|
|
160
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("br", {}),
|
|
161
|
-
"Please check if your configuration is correct."
|
|
162
|
-
] });
|
|
163
|
-
}
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
// src/core/hooks/use-localess.ts
|
|
167
|
-
var import_react2 = require("react");
|
|
168
|
-
var import_client3 = require("@localess/client");
|
|
169
|
-
var useLocaless = (slug, options = {}) => {
|
|
170
|
-
const [document, setDocument] = (0, import_react2.useState)();
|
|
171
|
-
const client = getLocalessClient();
|
|
172
|
-
let normalizedSlug;
|
|
173
|
-
if (Array.isArray(slug)) {
|
|
174
|
-
normalizedSlug = slug.join("/");
|
|
175
|
-
} else {
|
|
176
|
-
normalizedSlug = slug;
|
|
177
|
-
}
|
|
178
|
-
(0, import_react2.useEffect)(() => {
|
|
179
|
-
async function loadDocument() {
|
|
180
|
-
const document2 = await client.getContentBySlug(normalizedSlug, options);
|
|
181
|
-
setDocument(document2);
|
|
182
|
-
if (isSyncEnabled() && (0, import_client3.isBrowser)()) {
|
|
183
|
-
window.localess?.on(["input", "change"], (event) => {
|
|
184
|
-
if (event.type === "change" || event.type === "input") {
|
|
185
|
-
setDocument({ ...document2, data: event.data });
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
loadDocument();
|
|
191
|
-
}, [slug, options, client]);
|
|
192
|
-
return document;
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
// src/core/richtext.ts
|
|
196
|
-
var import_react3 = require("@tiptap/static-renderer/pm/react");
|
|
197
|
-
var import_extension_document = require("@tiptap/extension-document");
|
|
198
|
-
var import_extension_text = require("@tiptap/extension-text");
|
|
199
|
-
var import_extension_paragraph = require("@tiptap/extension-paragraph");
|
|
200
|
-
var import_extension_heading = require("@tiptap/extension-heading");
|
|
201
|
-
var import_extension_bold = require("@tiptap/extension-bold");
|
|
202
|
-
var import_extension_italic = require("@tiptap/extension-italic");
|
|
203
|
-
var import_extension_strike = require("@tiptap/extension-strike");
|
|
204
|
-
var import_extension_underline = require("@tiptap/extension-underline");
|
|
205
|
-
var import_extension_history = require("@tiptap/extension-history");
|
|
206
|
-
var import_extension_list_item = require("@tiptap/extension-list-item");
|
|
207
|
-
var import_extension_ordered_list = require("@tiptap/extension-ordered-list");
|
|
208
|
-
var import_extension_bullet_list = require("@tiptap/extension-bullet-list");
|
|
209
|
-
var import_extension_code = require("@tiptap/extension-code");
|
|
210
|
-
var import_extension_code_block_lowlight = require("@tiptap/extension-code-block-lowlight");
|
|
211
|
-
var import_extension_link = require("@tiptap/extension-link");
|
|
212
|
-
function renderRichTextToReact(content) {
|
|
213
|
-
return (0, import_react3.renderToReactElement)({
|
|
214
|
-
content,
|
|
215
|
-
extensions: [
|
|
216
|
-
import_extension_document.Document,
|
|
217
|
-
import_extension_text.Text,
|
|
218
|
-
import_extension_paragraph.Paragraph,
|
|
219
|
-
import_extension_heading.Heading.configure({
|
|
220
|
-
levels: [1, 2, 3, 4, 5, 6]
|
|
221
|
-
}),
|
|
222
|
-
import_extension_bold.Bold,
|
|
223
|
-
import_extension_italic.Italic,
|
|
224
|
-
import_extension_strike.Strike,
|
|
225
|
-
import_extension_underline.Underline,
|
|
226
|
-
import_extension_history.History,
|
|
227
|
-
import_extension_list_item.ListItem,
|
|
228
|
-
import_extension_ordered_list.OrderedList,
|
|
229
|
-
import_extension_bullet_list.BulletList,
|
|
230
|
-
import_extension_code.Code,
|
|
231
|
-
import_extension_code_block_lowlight.CodeBlockLowlight,
|
|
232
|
-
import_extension_link.Link
|
|
233
|
-
]
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
237
|
-
0 && (module.exports = {
|
|
238
|
-
LocalessComponent,
|
|
239
|
-
findLink,
|
|
240
|
-
getComponent,
|
|
241
|
-
getFallbackComponent,
|
|
242
|
-
getLocalessClient,
|
|
243
|
-
isBrowser,
|
|
244
|
-
isIframe,
|
|
245
|
-
isServer,
|
|
246
|
-
isSyncEnabled,
|
|
247
|
-
localessEditable,
|
|
248
|
-
localessEditableField,
|
|
249
|
-
localessInit,
|
|
250
|
-
registerComponent,
|
|
251
|
-
renderRichTextToReact,
|
|
252
|
-
resolveAsset,
|
|
253
|
-
setComponents,
|
|
254
|
-
setFallbackComponent,
|
|
255
|
-
unregisterComponent,
|
|
256
|
-
useLocaless
|
|
257
|
-
});
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./core/state.js`),t=require(`./core/utils/link.util.js`),n=require(`./core/components/localess-component.js`),r=require(`./core/components/localess-document.js`),i=require(`./core/hooks/use-localess.js`),a=require(`./core/richtext.js`);let o=require(`@localess/client`);exports.LocalessComponent=n.LocalessComponent,exports.LocalessDocument=r.LocalessDocument,exports.findLink=t.findLink,exports.getComponent=e.getComponent,exports.getFallbackComponent=e.getFallbackComponent,exports.getLocalessClient=e.getLocalessClient,exports.getOrigin=e.getOrigin,Object.defineProperty(exports,`isBrowser`,{enumerable:!0,get:function(){return o.isBrowser}}),Object.defineProperty(exports,`isIframe`,{enumerable:!0,get:function(){return o.isIframe}}),Object.defineProperty(exports,`isServer`,{enumerable:!0,get:function(){return o.isServer}}),exports.isSyncEnabled=e.isSyncEnabled,Object.defineProperty(exports,`localessEditable`,{enumerable:!0,get:function(){return o.localessEditable}}),Object.defineProperty(exports,`localessEditableField`,{enumerable:!0,get:function(){return o.localessEditableField}}),exports.localessInit=e.localessInit,exports.registerComponent=e.registerComponent,exports.renderRichTextToReact=a.renderRichTextToReact,exports.resolveAsset=e.resolveAsset,exports.setComponents=e.setComponents,exports.setFallbackComponent=e.setFallbackComponent,exports.unregisterComponent=e.unregisterComponent,exports.useLocaless=i.useLocaless;
|
package/dist/index.mjs
CHANGED
|
@@ -1,44 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "./
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
getLocalessClient,
|
|
10
|
-
isBrowser,
|
|
11
|
-
isIframe,
|
|
12
|
-
isServer,
|
|
13
|
-
isSyncEnabled,
|
|
14
|
-
localessEditable,
|
|
15
|
-
localessEditableField,
|
|
16
|
-
localessInit,
|
|
17
|
-
registerComponent,
|
|
18
|
-
renderRichTextToReact,
|
|
19
|
-
resolveAsset,
|
|
20
|
-
setComponents,
|
|
21
|
-
setFallbackComponent,
|
|
22
|
-
unregisterComponent
|
|
23
|
-
} from "./chunk-ETSLIILF.mjs";
|
|
24
|
-
export {
|
|
25
|
-
LocalessComponent,
|
|
26
|
-
findLink,
|
|
27
|
-
getComponent,
|
|
28
|
-
getFallbackComponent,
|
|
29
|
-
getLocalessClient,
|
|
30
|
-
isBrowser,
|
|
31
|
-
isIframe,
|
|
32
|
-
isServer,
|
|
33
|
-
isSyncEnabled,
|
|
34
|
-
localessEditable,
|
|
35
|
-
localessEditableField,
|
|
36
|
-
localessInit,
|
|
37
|
-
registerComponent,
|
|
38
|
-
renderRichTextToReact,
|
|
39
|
-
resolveAsset,
|
|
40
|
-
setComponents,
|
|
41
|
-
setFallbackComponent,
|
|
42
|
-
unregisterComponent,
|
|
43
|
-
useLocaless
|
|
44
|
-
};
|
|
1
|
+
import { getComponent as e, getFallbackComponent as t, getLocalessClient as n, getOrigin as r, isSyncEnabled as i, localessInit as a, registerComponent as o, resolveAsset as s, setComponents as c, setFallbackComponent as l, unregisterComponent as u } from "./core/state.mjs";
|
|
2
|
+
import { findLink as d } from "./core/utils/link.util.mjs";
|
|
3
|
+
import { isBrowser as f, isIframe as p, isServer as m, localessEditable as h, localessEditableField as g } from "./core/utils/index.mjs";
|
|
4
|
+
import { LocalessComponent as _ } from "./core/components/localess-component.mjs";
|
|
5
|
+
import { LocalessDocument as v } from "./core/components/localess-document.mjs";
|
|
6
|
+
import { useLocaless as y } from "./core/hooks/use-localess.mjs";
|
|
7
|
+
import { renderRichTextToReact as b } from "./core/richtext.mjs";
|
|
8
|
+
export { _ as LocalessComponent, v as LocalessDocument, d as findLink, e as getComponent, t as getFallbackComponent, n as getLocalessClient, r as getOrigin, f as isBrowser, p as isIframe, m as isServer, i as isSyncEnabled, h as localessEditable, g as localessEditableField, a as localessInit, o as registerComponent, b as renderRichTextToReact, s as resolveAsset, c as setComponents, l as setFallbackComponent, u as unregisterComponent, y as useLocaless };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @localess/react/rsc
|
|
3
|
+
*
|
|
4
|
+
* React Server Components export — use in Next.js App Router and other RSC-capable frameworks.
|
|
5
|
+
* Extends the SSR export with client-side components and hooks for Visual Editor live editing.
|
|
6
|
+
*
|
|
7
|
+
* Use this export when:
|
|
8
|
+
* - Using Next.js App Router with React Server Components
|
|
9
|
+
* - You need live Visual Editor editing alongside server-rendered components
|
|
10
|
+
* - Building modern React apps with a clear server / client component boundary
|
|
11
|
+
*
|
|
12
|
+
* For the default SPA export use `@localess/react`.
|
|
13
|
+
* For SSR without live editing (static exports) use `@localess/react/ssr`.
|
|
14
|
+
*
|
|
15
|
+
* Typical pattern — import path is the same for both server and client files:
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* // Server Component (Next.js App Router)
|
|
19
|
+
* import { localessInit, getLocalessClient, LocalessServerComponent } from '@localess/react/rsc';
|
|
20
|
+
*
|
|
21
|
+
* // Client Component ('use client')
|
|
22
|
+
* import { LocalessDocument, useLocaless, localessEditable } from '@localess/react/rsc';
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* NOT compatible with Next.js `output: 'export'` — use `@localess/react/ssr` for static exports.
|
|
26
|
+
*/
|
|
27
|
+
export * from '../ssr';
|
|
28
|
+
export * from '../core/components/localess-component';
|
|
29
|
+
export * from './localess-document';
|
|
30
|
+
export { isSyncEnabled } from '../core/state';
|
|
@@ -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/components/localess-component.js`),r=require(`../core/richtext.js`),i=require(`../ssr/localess-component.js`),a=require(`../ssr/localess-document.js`),o=require(`./localess-document.js`);let s=require(`@localess/client`);exports.LocalessComponent=n.LocalessComponent,exports.LocalessDocument=o.LocalessDocument,exports.LocalessServerComponent=i.LocalessServerComponent,exports.LocalessServerDocument=a.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 s.isBrowser}}),Object.defineProperty(exports,`isIframe`,{enumerable:!0,get:function(){return s.isIframe}}),Object.defineProperty(exports,`isServer`,{enumerable:!0,get:function(){return s.isServer}}),exports.isSyncEnabled=e.isSyncEnabled,Object.defineProperty(exports,`localessEditable`,{enumerable:!0,get:function(){return s.localessEditable}}),Object.defineProperty(exports,`localessEditableField`,{enumerable:!0,get:function(){return s.localessEditableField}}),exports.localessInit=e.localessInit,exports.registerComponent=e.registerComponent,exports.renderRichTextToReact=r.renderRichTextToReact,exports.resolveAsset=e.resolveAsset,exports.unregisterComponent=e.unregisterComponent;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { getComponent as e, getFallbackComponent as t, getLocalessClient as n, isSyncEnabled as r, localessInit as i, registerComponent as a, resolveAsset as o, unregisterComponent as s } from "../core/state.mjs";
|
|
2
|
+
import { findLink as c } from "../core/utils/link.util.mjs";
|
|
3
|
+
import { isBrowser as l, isIframe as u, isServer as d, localessEditable as f, localessEditableField as p } from "../core/utils/index.mjs";
|
|
4
|
+
import { LocalessComponent as m } from "../core/components/localess-component.mjs";
|
|
5
|
+
import { renderRichTextToReact as h } from "../core/richtext.mjs";
|
|
6
|
+
import { LocalessServerComponent as g } from "../ssr/localess-component.mjs";
|
|
7
|
+
import { LocalessServerDocument as _ } from "../ssr/localess-document.mjs";
|
|
8
|
+
import { LocalessDocument as v } from "./localess-document.mjs";
|
|
9
|
+
export { m as LocalessComponent, v as LocalessDocument, g as LocalessServerComponent, _ as LocalessServerDocument, c as findLink, e as getComponent, t as getFallbackComponent, n as getLocalessClient, l as isBrowser, u as isIframe, d as isServer, r as isSyncEnabled, f as localessEditable, p as localessEditableField, i as localessInit, a as registerComponent, h as renderRichTextToReact, o as resolveAsset, s as unregisterComponent };
|
|
@@ -1,32 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
export { LocalessServerComponent, LocalessServerComponentProps, LocalessServerDocument, LocalessServerDocumentProps } from './ssr.mjs';
|
|
3
|
-
import { ContentData, Links, References } 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 { LocalessComponent, LocalessComponentProps, UseLocalessOptions, useLocaless } from './index.mjs';
|
|
6
|
-
import * as React from 'react';
|
|
7
|
-
|
|
1
|
+
import { Content, ContentData } from '../core/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
|
-
* The content
|
|
16
|
-
*
|
|
17
|
-
* without a loading flash.
|
|
9
|
+
* The full content response object as returned by `getContentBySlug` or `getContentById`.
|
|
10
|
+
* Must contain a `data` field with a valid `_schema` key.
|
|
18
11
|
*/
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Optional map of content links keyed by link ID.
|
|
22
|
-
* Passed through to child components for resolving {@link ContentLink} values with `findLink`.
|
|
23
|
-
*/
|
|
24
|
-
links?: Links;
|
|
25
|
-
/**
|
|
26
|
-
* Optional map of resolved content references keyed by reference ID.
|
|
27
|
-
* Passed through to child components that consume referenced content.
|
|
28
|
-
*/
|
|
29
|
-
references?: References;
|
|
12
|
+
document: Content<T>;
|
|
30
13
|
};
|
|
31
14
|
/**
|
|
32
15
|
* Client Component that renders content and automatically subscribes to Visual Editor sync events.
|
|
@@ -67,6 +50,4 @@ type LocalessDocumentProps<T extends ContentData = ContentData> = {
|
|
|
67
50
|
* }
|
|
68
51
|
* ```
|
|
69
52
|
*/
|
|
70
|
-
declare const LocalessDocument:
|
|
71
|
-
|
|
72
|
-
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(`../core/state.js`),n=require(`../core/components/localess-component.js`),r=require(`./localess-sync.js`);let i=require(`react`),a=require(`react/jsx-runtime`);var o=(0,i.forwardRef)(({document:i},o)=>i.data?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(n.LocalessComponent,{ref:o,data:i.data,links:i.links,references:i.references}),(0,a.jsx)(r.LocalessSync,{document:i,origin:t.getOrigin(),enableSync:t.isSyncEnabled()})]}):(console.error(`LocalessDocument property %cdocument.data%c is not provided.`,e.FONT_BOLD,e.FONT_NORMAL),(0,a.jsxs)(`div`,{children:[`LocalessDocument property `,(0,a.jsx)(`b`,{children:`document.data`}),` is not provided.`]})));exports.LocalessDocument=o;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { FONT_BOLD as e, FONT_NORMAL as t } from "../console.mjs";
|
|
2
|
+
import { getOrigin as n, isSyncEnabled as r } from "../core/state.mjs";
|
|
3
|
+
import { LocalessComponent as i } from "../core/components/localess-component.mjs";
|
|
4
|
+
import { LocalessSync as a } from "./localess-sync.mjs";
|
|
5
|
+
import { forwardRef as o } from "react";
|
|
6
|
+
import { Fragment as s, jsx as c, jsxs as l } from "react/jsx-runtime";
|
|
7
|
+
//#region src/rsc/localess-document.tsx
|
|
8
|
+
var u = o(({ document: o }, u) => o.data ? /* @__PURE__ */ l(s, { children: [/* @__PURE__ */ c(i, {
|
|
9
|
+
ref: u,
|
|
10
|
+
data: o.data,
|
|
11
|
+
links: o.links,
|
|
12
|
+
references: o.references
|
|
13
|
+
}), /* @__PURE__ */ c(a, {
|
|
14
|
+
document: o,
|
|
15
|
+
origin: n(),
|
|
16
|
+
enableSync: r()
|
|
17
|
+
})] }) : (console.error("LocalessDocument property %cdocument.data%c is not provided.", e, t), /* @__PURE__ */ l("div", { children: [
|
|
18
|
+
"LocalessDocument property ",
|
|
19
|
+
/* @__PURE__ */ c("b", { children: "document.data" }),
|
|
20
|
+
" is not provided."
|
|
21
|
+
] })));
|
|
22
|
+
//#endregion
|
|
23
|
+
export { u as LocalessDocument };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Content, ContentData } from '@localess/client';
|
|
2
|
+
export type LocalessSyncProps<T extends ContentData = ContentData> = {
|
|
3
|
+
document: Content<T>;
|
|
4
|
+
origin: string;
|
|
5
|
+
enableSync: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare const LocalessSync: (props: LocalessSyncProps) => null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";let e=require(`@localess/client`),t=require(`react`);var n=(n=>(console.info(`LocalessSync:init`),(0,t.useEffect)(()=>{console.info(`LocalessSync:effect`,n.enableSync,(0,e.isBrowser)(),(0,e.isIframe)()),n.enableSync&&(0,e.isBrowser)()&&(0,e.isIframe)()&&((0,e.loadLocalessSync)(n.origin),window.localess?.on([`input`,`change`],e=>{console.info(`LocalessSync:change:`,e),(e.type===`change`||e.type===`input`)&&(n.document.data=e.data)}))},[]),null));exports.LocalessSync=n;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { isBrowser as e, isIframe as t } from "../core/utils/index.mjs";
|
|
3
|
+
import { loadLocalessSync as n } from "@localess/client";
|
|
4
|
+
import { useEffect as r } from "react";
|
|
5
|
+
//#region src/rsc/localess-sync.tsx
|
|
6
|
+
var i = ((i) => (console.info("LocalessSync:init"), r(() => {
|
|
7
|
+
console.info("LocalessSync:effect", i.enableSync, e(), t()), i.enableSync && e() && t() && (n(i.origin), window.localess?.on(["input", "change"], (e) => {
|
|
8
|
+
console.info("LocalessSync:change:", e), (e.type === "change" || e.type === "input") && (i.document.data = e.data);
|
|
9
|
+
}));
|
|
10
|
+
}, []), null));
|
|
11
|
+
//#endregion
|
|
12
|
+
export { i as LocalessSync };
|