@localess/react 0.8.0

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.
@@ -0,0 +1,33 @@
1
+ import * as React from 'react';
2
+ import React__default from 'react';
3
+ import { LocalessClientOptions, ContentData, Links, LocalessClient } from '@localess/js-client';
4
+ export { Content, ContentAsset, ContentData, ContentDataField, ContentDataSchema, ContentLink, ContentMetadata, ContentReference, ContentRichText, EventCallback, EventToApp, EventToAppType, Links, LocalessClient, LocalessSync, Translations, llEditable } from '@localess/js-client';
5
+
6
+ type LocalessOptions = LocalessClientOptions & {
7
+ /**
8
+ * Components mapping for Localess Component integration
9
+ */
10
+ components?: Record<string, React__default.ElementType>;
11
+ /**
12
+ * Component used if expected key didn't return anything
13
+ */
14
+ fallbackComponent?: React__default.ElementType;
15
+ /**
16
+ * Load Sync Script, for Visual Editor integration
17
+ */
18
+ enableSync?: boolean;
19
+ };
20
+
21
+ type LocalessComponentProps = {
22
+ data: ContentData;
23
+ links?: Links;
24
+ };
25
+ declare const LocalessComponent: React.ForwardRefExoticComponent<LocalessComponentProps & React.RefAttributes<HTMLElement>>;
26
+
27
+ declare function localessInit(options: LocalessOptions): LocalessClient;
28
+ declare function getLocalessClient(): LocalessClient;
29
+ declare function getComponent(key: string): React__default.ElementType | undefined;
30
+ declare function getFallbackComponent(): React__default.ElementType | undefined;
31
+ declare function isSyncEnabled(): boolean;
32
+
33
+ export { LocalessComponent, type LocalessComponentProps, type LocalessOptions, getComponent, getFallbackComponent, getLocalessClient, isSyncEnabled, localessInit };
@@ -0,0 +1,33 @@
1
+ import * as React from 'react';
2
+ import React__default from 'react';
3
+ import { LocalessClientOptions, ContentData, Links, LocalessClient } from '@localess/js-client';
4
+ export { Content, ContentAsset, ContentData, ContentDataField, ContentDataSchema, ContentLink, ContentMetadata, ContentReference, ContentRichText, EventCallback, EventToApp, EventToAppType, Links, LocalessClient, LocalessSync, Translations, llEditable } from '@localess/js-client';
5
+
6
+ type LocalessOptions = LocalessClientOptions & {
7
+ /**
8
+ * Components mapping for Localess Component integration
9
+ */
10
+ components?: Record<string, React__default.ElementType>;
11
+ /**
12
+ * Component used if expected key didn't return anything
13
+ */
14
+ fallbackComponent?: React__default.ElementType;
15
+ /**
16
+ * Load Sync Script, for Visual Editor integration
17
+ */
18
+ enableSync?: boolean;
19
+ };
20
+
21
+ type LocalessComponentProps = {
22
+ data: ContentData;
23
+ links?: Links;
24
+ };
25
+ declare const LocalessComponent: React.ForwardRefExoticComponent<LocalessComponentProps & React.RefAttributes<HTMLElement>>;
26
+
27
+ declare function localessInit(options: LocalessOptions): LocalessClient;
28
+ declare function getLocalessClient(): LocalessClient;
29
+ declare function getComponent(key: string): React__default.ElementType | undefined;
30
+ declare function getFallbackComponent(): React__default.ElementType | undefined;
31
+ declare function isSyncEnabled(): boolean;
32
+
33
+ export { LocalessComponent, type LocalessComponentProps, type LocalessOptions, getComponent, getFallbackComponent, getLocalessClient, isSyncEnabled, localessInit };
package/dist/index.js ADDED
@@ -0,0 +1,119 @@
1
+ "use strict";
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 index_exports = {};
22
+ __export(index_exports, {
23
+ LocalessComponent: () => LocalessComponent,
24
+ getComponent: () => getComponent,
25
+ getFallbackComponent: () => getFallbackComponent,
26
+ getLocalessClient: () => getLocalessClient,
27
+ isSyncEnabled: () => isSyncEnabled,
28
+ llEditable: () => import_js_client3.llEditable,
29
+ localessInit: () => localessInit
30
+ });
31
+ module.exports = __toCommonJS(index_exports);
32
+ var import_js_client2 = require("@localess/js-client");
33
+
34
+ // src/console.ts
35
+ var FONT_BOLD = "font-weight: bold";
36
+ var FONT_NORMAL = "font-weight: normal";
37
+
38
+ // src/index.ts
39
+ var import_js_client3 = require("@localess/js-client");
40
+
41
+ // src/localess-componenet.tsx
42
+ var import_react = require("react");
43
+ var import_js_client = require("@localess/js-client");
44
+ var import_jsx_runtime = require("react/jsx-runtime");
45
+ var LocalessComponent = (0, import_react.forwardRef)(({ data, links, ...restProps }, ref) => {
46
+ if (!data) {
47
+ console.error("LocalessComponent property %cdata%c is not provided.", FONT_BOLD, FONT_NORMAL);
48
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
49
+ "LocalessComponent property ",
50
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("b", { children: "data" }),
51
+ " is not provided."
52
+ ] });
53
+ }
54
+ const Comp = getComponent(data._schema || data.schema);
55
+ if (Comp) {
56
+ const attr = isSyncEnabled() ? (0, import_js_client.llEditable)(data) : {};
57
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Comp, { ref, data, links, ...attr, ...restProps });
58
+ }
59
+ const FallbackComponent = getFallbackComponent();
60
+ if (FallbackComponent) {
61
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FallbackComponent, { ref, data, links, ...restProps });
62
+ }
63
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { children: [
64
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("b", { children: "LocalessComponent" }),
65
+ " could not found component with key ",
66
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("b", { children: data._schema || data.schema }),
67
+ ". ",
68
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("br", {}),
69
+ "Please check if your configuration is correct."
70
+ ] });
71
+ });
72
+
73
+ // src/index.ts
74
+ var _client = void 0;
75
+ var _components = {};
76
+ var _fallbackComponent = void 0;
77
+ var _enableSync = false;
78
+ function localessInit(options) {
79
+ console.log("localessInit", options);
80
+ const { components, fallbackComponent, enableSync, ...restOptions } = options;
81
+ _client = (0, import_js_client2.localessClient)(restOptions);
82
+ _components = components || {};
83
+ _fallbackComponent = fallbackComponent;
84
+ if (enableSync) {
85
+ _enableSync = true;
86
+ (0, import_js_client2.loadLocalessSync)(restOptions.origin);
87
+ }
88
+ return _client;
89
+ }
90
+ function getLocalessClient() {
91
+ if (!_client) {
92
+ console.error("[Localess] No client found. Please check if the Localess is initialized.");
93
+ throw new Error("[Localess] No client found.");
94
+ }
95
+ return _client;
96
+ }
97
+ function getComponent(key) {
98
+ if (Object.hasOwn(_components, key)) {
99
+ console.error(`[Localess] component %c${key}%c can't be found.`, FONT_BOLD, FONT_NORMAL);
100
+ return void 0;
101
+ }
102
+ return _components[key];
103
+ }
104
+ function getFallbackComponent() {
105
+ return _fallbackComponent;
106
+ }
107
+ function isSyncEnabled() {
108
+ return _enableSync;
109
+ }
110
+ // Annotate the CommonJS export names for ESM import in node:
111
+ 0 && (module.exports = {
112
+ LocalessComponent,
113
+ getComponent,
114
+ getFallbackComponent,
115
+ getLocalessClient,
116
+ isSyncEnabled,
117
+ llEditable,
118
+ localessInit
119
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,88 @@
1
+ // src/index.ts
2
+ import { loadLocalessSync, localessClient } from "@localess/js-client";
3
+
4
+ // src/console.ts
5
+ var FONT_BOLD = "font-weight: bold";
6
+ var FONT_NORMAL = "font-weight: normal";
7
+
8
+ // src/index.ts
9
+ import { llEditable as llEditable2 } from "@localess/js-client";
10
+
11
+ // src/localess-componenet.tsx
12
+ import { forwardRef } from "react";
13
+ import { llEditable } from "@localess/js-client";
14
+ import { jsx, jsxs } from "react/jsx-runtime";
15
+ var LocalessComponent = forwardRef(({ data, links, ...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 || data.schema);
25
+ if (Comp) {
26
+ const attr = isSyncEnabled() ? llEditable(data) : {};
27
+ return /* @__PURE__ */ jsx(Comp, { ref, data, links, ...attr, ...restProps });
28
+ }
29
+ const FallbackComponent = getFallbackComponent();
30
+ if (FallbackComponent) {
31
+ return /* @__PURE__ */ jsx(FallbackComponent, { ref, data, links, ...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 || data.schema }),
37
+ ". ",
38
+ /* @__PURE__ */ jsx("br", {}),
39
+ "Please check if your configuration is correct."
40
+ ] });
41
+ });
42
+
43
+ // src/index.ts
44
+ var _client = void 0;
45
+ var _components = {};
46
+ var _fallbackComponent = void 0;
47
+ var _enableSync = false;
48
+ function localessInit(options) {
49
+ console.log("localessInit", options);
50
+ const { components, fallbackComponent, enableSync, ...restOptions } = options;
51
+ _client = localessClient(restOptions);
52
+ _components = components || {};
53
+ _fallbackComponent = fallbackComponent;
54
+ if (enableSync) {
55
+ _enableSync = true;
56
+ loadLocalessSync(restOptions.origin);
57
+ }
58
+ return _client;
59
+ }
60
+ function getLocalessClient() {
61
+ if (!_client) {
62
+ console.error("[Localess] No client found. Please check if the Localess is initialized.");
63
+ throw new Error("[Localess] No client found.");
64
+ }
65
+ return _client;
66
+ }
67
+ function getComponent(key) {
68
+ if (Object.hasOwn(_components, key)) {
69
+ console.error(`[Localess] component %c${key}%c can't be found.`, FONT_BOLD, FONT_NORMAL);
70
+ return void 0;
71
+ }
72
+ return _components[key];
73
+ }
74
+ function getFallbackComponent() {
75
+ return _fallbackComponent;
76
+ }
77
+ function isSyncEnabled() {
78
+ return _enableSync;
79
+ }
80
+ export {
81
+ LocalessComponent,
82
+ getComponent,
83
+ getFallbackComponent,
84
+ getLocalessClient,
85
+ isSyncEnabled,
86
+ llEditable2 as llEditable,
87
+ localessInit
88
+ };
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@localess/react",
3
+ "version": "0.8.0",
4
+ "description": "ReactJS JavaScript/TypeScript SDK for Localess's API.",
5
+ "keywords": [
6
+ "localess",
7
+ "sdk",
8
+ "api",
9
+ "client",
10
+ "react",
11
+ "javascript",
12
+ "typescript"
13
+ ],
14
+ "author": "Lessify",
15
+ "homepage": "https://github.com/Lessify/localess-react",
16
+ "sideEffects": false,
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/Lessify/localess-react.git"
20
+ },
21
+ "bugs": {
22
+ "url": "https://github.com/Lessify/localess-react/issues"
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "main": "dist/index.js",
28
+ "module": "dist/index.mjs",
29
+ "types": "dist/index.d.ts",
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.mjs",
34
+ "require": "./dist/index.js"
35
+ }
36
+ },
37
+ "private": false,
38
+ "license": "MIT",
39
+ "scripts": {
40
+ "build": "tsup src/index.ts --format cjs,esm --dts"
41
+ },
42
+ "peerDependencies": {
43
+ "react": "^17 || ^18 || ^19",
44
+ "react-dom": "^17 || ^18 || ^19"
45
+ },
46
+ "dependencies": {
47
+ "@localess/js-client": "0.8.0"
48
+ },
49
+ "devDependencies": {
50
+ "@types/react": "18.3.12",
51
+ "@types/node": "^20.12.12",
52
+ "react": "^18.3.1",
53
+ "react-dom": "^18.3.1",
54
+ "tsup": "^8.4.0",
55
+ "typescript": "^5.8.3"
56
+ },
57
+ "engines": {
58
+ "node": ">= 18.0.0"
59
+ }
60
+ }