Skip to content

Commit c14ea6e

Browse files
committed
add playground
1 parent a5ebd3f commit c14ea6e

22 files changed

+6468
-491
lines changed

package-lock.json

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

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@
2525
"private": false,
2626
"license": "MIT",
2727
"workspaces": [
28-
"packages/*"
28+
"packages/*",
29+
"playgrounds/*"
2930
],
31+
"scripts": {
32+
"build": "npm run build:react",
33+
"build:react": "cd packages/react && npm run build"
34+
},
3035
"peerDependencies": {
3136
"react": "^17 || ^18 || ^19",
3237
"react-dom": "^17 || ^18 || ^19"

packages/react/package.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,18 @@
2424
"files": [
2525
"dist"
2626
],
27-
"type": "module",
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+
},
2837
"private": false,
2938
"license": "MIT",
30-
"workspaces": [
31-
"packages/*"
32-
],
3339
"scripts": {
3440
"build": "tsup src/index.ts --format cjs,esm --dts"
3541
},

packages/react/src/index.ts

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,47 @@ import {loadLocalessSync, LocalessClient, localessClient} from "@localess/js-cli
33
import {FONT_BOLD, FONT_NORMAL} from "./console";
44
import {LocalessOptions} from "./models";
55

6-
let client: LocalessClient | undefined = undefined
7-
let components: Record<string, React.ElementType> = {};
8-
let fallbackComponent: React.ElementType | undefined = undefined;
9-
let enableSync: boolean = false;
10-
11-
export function localessInit(options: LocalessOptions) {
12-
client = localessClient(options);
13-
14-
components = options.components || {};
15-
fallbackComponent = options.fallbackComponent;
16-
if (options.enableSync) {
17-
enableSync = true;
18-
loadLocalessSync(options.origin)
6+
let _client: LocalessClient | undefined = undefined
7+
let _components: Record<string, React.ElementType> = {};
8+
let _fallbackComponent: React.ElementType | undefined = undefined;
9+
let _enableSync: boolean = false;
10+
11+
export function localessInit(options: LocalessOptions): LocalessClient {
12+
console.log("localessInit", options);
13+
const {components, fallbackComponent, enableSync, ...restOptions} = options;
14+
_client = localessClient(restOptions);
15+
16+
_components = components || {};
17+
_fallbackComponent = fallbackComponent;
18+
if (enableSync) {
19+
_enableSync = true;
20+
loadLocalessSync(restOptions.origin)
1921
}
22+
return _client;
2023
}
2124

2225
export function getLocalessClient(): LocalessClient {
23-
if (!client) {
26+
if (!_client) {
2427
console.error('[Localess] No client found. Please check if the Localess is initialized.');
2528
throw new Error('[Localess] No client found.');
2629
}
27-
return client;
30+
return _client;
2831
}
2932

3033
export function getComponent(key: string): React.ElementType | undefined {
31-
if (Object.hasOwn(components, key)) {
34+
if (Object.hasOwn(_components, key)) {
3235
console.error(`[Localess] component %c${key}%c can't be found.`, FONT_BOLD, FONT_NORMAL)
3336
return undefined;
3437
}
35-
return components[key];
38+
return _components[key];
3639
}
3740

3841
export function getFallbackComponent(): React.ElementType | undefined {
39-
return fallbackComponent;
42+
return _fallbackComponent;
4043
}
4144

4245
export function isSyncEnabled(): boolean {
43-
return enableSync;
46+
return _enableSync;
4447
}
4548

4649
// Client + Edit
@@ -49,3 +52,5 @@ export {llEditable, LocalessClient} from '@localess/js-client'
4952
export {LocalessSync, EventToApp, EventCallback, EventToAppType} from '@localess/js-client'
5053
// Models
5154
export type * from './models';
55+
// Component
56+
export * from './localess-componenet';

packages/react/src/localess-componenet.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type LocalessComponentProps = {
88
links?: Links
99
}
1010

11-
const LocalessComponent = forwardRef<HTMLElement, LocalessComponentProps>(({data, links, ...restProps}, ref) => {
11+
export const LocalessComponent = forwardRef<HTMLElement, LocalessComponentProps>(({data, links, ...restProps}, ref) => {
1212
if (!data) {
1313
console.error('LocalessComponent property %cdata%c is not provided.', FONT_BOLD, FONT_NORMAL)
1414
return <div>LocalessComponent property <b>data</b> is not provided.</div>
@@ -32,5 +32,3 @@ const LocalessComponent = forwardRef<HTMLElement, LocalessComponentProps>(({data
3232
</p>
3333
);
3434
});
35-
36-
export default LocalessComponent;

packages/react/src/models/options.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,7 @@
11
import type React from "react";
2+
import {LocalessClientOptions} from "@localess/js-client";
23

3-
export type LocalessOptions = {
4-
/**
5-
* A fully qualified domain name with protocol (http/https) and port.
6-
*
7-
* Example: https://my-localess.web.app
8-
*/
9-
origin: string;
10-
/**
11-
* Localess space ID, cna be found in the Localess Space settings
12-
*/
13-
spaceId: string;
14-
/**
15-
* Localess API token, can be found in the Localess Space settings
16-
*/
17-
token: string;
18-
/**
19-
* Content version to fetch, leave empty for 'published' or 'draft' for the latest draft
20-
*/
21-
version?: 'draft' | string;
22-
/**
23-
* Enable debug mode
24-
*/
25-
debug?: boolean;
26-
4+
export type LocalessOptions = LocalessClientOptions & {
275
/**
286
* Components mapping for Localess Component integration
297
*/

playgrounds/next15/.gitignore

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.*
7+
.yarn/*
8+
!.yarn/patches
9+
!.yarn/plugins
10+
!.yarn/releases
11+
!.yarn/versions
12+
13+
# testing
14+
/coverage
15+
16+
# next.js
17+
/.next/
18+
/out/
19+
20+
# production
21+
/build
22+
23+
# misc
24+
.DS_Store
25+
*.pem
26+
27+
# debug
28+
npm-debug.log*
29+
yarn-debug.log*
30+
yarn-error.log*
31+
.pnpm-debug.log*
32+
33+
# env files (can opt-in for committing if needed)
34+
.env*
35+
36+
# vercel
37+
.vercel
38+
39+
# typescript
40+
*.tsbuildinfo
41+
next-env.d.ts

playgrounds/next15/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
2+
3+
## Getting Started
4+
5+
First, run the development server:
6+
7+
```bash
8+
npm run dev
9+
# or
10+
yarn dev
11+
# or
12+
pnpm dev
13+
# or
14+
bun dev
15+
```
16+
17+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
18+
19+
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
20+
21+
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
22+
23+
## Learn More
24+
25+
To learn more about Next.js, take a look at the following resources:
26+
27+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
28+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
29+
30+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
31+
32+
## Deploy on Vercel
33+
34+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
35+
36+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { dirname } from "path";
2+
import { fileURLToPath } from "url";
3+
import { FlatCompat } from "@eslint/eslintrc";
4+
5+
const __filename = fileURLToPath(import.meta.url);
6+
const __dirname = dirname(__filename);
7+
8+
const compat = new FlatCompat({
9+
baseDirectory: __dirname,
10+
});
11+
12+
const eslintConfig = [
13+
...compat.extends("next/core-web-vitals", "next/typescript"),
14+
];
15+
16+
export default eslintConfig;

playgrounds/next15/next.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { NextConfig } from "next";
2+
3+
const nextConfig: NextConfig = {
4+
/* config options here */
5+
};
6+
7+
export default nextConfig;

0 commit comments

Comments
 (0)