Skip to content
This repository was archived by the owner on Mar 13, 2026. It is now read-only.

Commit 354fc03

Browse files
committed
Add Asset Path Resolver
1 parent eb5c926 commit 354fc03

5 files changed

Lines changed: 23 additions & 6 deletions

File tree

‎package-lock.json‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@localess/react",
3-
"version": "0.8.6",
3+
"version": "0.8.7",
44
"description": "ReactJS JavaScript/TypeScript SDK for Localess's API.",
55
"keywords": [
66
"localess",

‎packages/react/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@localess/react",
3-
"version": "0.8.6",
3+
"version": "0.8.7",
44
"description": "ReactJS JavaScript/TypeScript SDK for Localess's API.",
55
"keywords": [
66
"localess",

‎packages/react/src/index.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import type React from 'react';
22
import {loadLocalessSync, type LocalessClient, localessClient} from "@localess/js-client";
33
import {FONT_BOLD, FONT_NORMAL} from "./console";
4-
import {type LocalessOptions} from "./models";
4+
import {type LocalessOptions, type ContentAsset} from "./models";
55

66
let _client: LocalessClient | undefined = undefined
77
let _components: Record<string, React.ElementType> = {};
88
let _fallbackComponent: React.ElementType | undefined = undefined;
99
let _enableSync: boolean = false;
10+
let _assetPathPrefix = '';
1011

1112
/**
1213
* Initialize Localess Client
@@ -18,6 +19,8 @@ export function localessInit(options: LocalessOptions): LocalessClient {
1819
const {components, fallbackComponent, enableSync, ...restOptions} = options;
1920
_client = localessClient(restOptions);
2021

22+
_assetPathPrefix = `${options.origin}/api/v1/spaces/${options.spaceId}/assets/`;
23+
2124
_components = components || {};
2225
_fallbackComponent = fallbackComponent;
2326
if (enableSync) {
@@ -100,6 +103,15 @@ export function isSyncEnabled(): boolean {
100103
return _enableSync;
101104
}
102105

106+
/**
107+
* Resolve Asset URL
108+
* @param asset - ContentAsset
109+
* @returns Asset URL
110+
*/
111+
export function resolveAsset(asset: ContentAsset) {
112+
return `${_assetPathPrefix}${asset.uri}`;
113+
}
114+
103115
// Client + Edit
104116
export {llEditable, llEditableField, localessEditable, localessEditableField, isBrowser, isServer, isIframe} from '@localess/js-client'
105117
export type {LocalessClient} from '@localess/js-client'

‎packages/react/src/richtext.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ import {Code} from "@tiptap/extension-code";
1717
import {CodeBlockLowlight} from "@tiptap/extension-code-block-lowlight";
1818
import {Link} from "@tiptap/extension-link";
1919

20+
/**
21+
* Render Localess Rich Text content to React elements
22+
* @param content - The Rich Text content to render
23+
* @returns React.ReactNode - The rendered React elements
24+
*/
2025
export function renderRichTextToReact(content: ContentRichText): React.ReactNode {
2126
return renderToReactElement({
2227
content,

0 commit comments

Comments
 (0)