@ea-lab/reactive-json 0.0.37 → 0.0.39

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 (2) hide show
  1. package/README.md +99 -43
  2. package/package.json +5 -4
package/README.md CHANGED
@@ -1,86 +1,142 @@
1
1
  # Reactive-JSON
2
2
 
3
- A REACT-based lib that transforms JSON (or YAML) into HTML markup.
3
+ A REACT-based lib that transforms JSON (or YAML) into interactive HTML markup.
4
4
 
5
5
  This lib lessens the need to write JS code for building frontend apps.
6
6
 
7
7
  With *reactive-json*, build your apps and forms frontend, embed them into your websites,
8
8
  and make them interactive with your backend.
9
9
 
10
- TODO: make and insert a descriptive image.
11
-
12
10
  ## How to use *reactive-json*
13
11
 
14
- The library can be:
15
-
16
- - used as a standalone lib: simply load the dist files in your web page
17
- and it will work on the `<reactive-json>` HTML tags.
18
- - included in your React project: use the provided `<ReactiveJsonRoot>` component
19
- in your React app. This is the way to go if you want to use reactive-json plugins.
12
+ Reactive-json must be included as an npm dependency in your React project. There are two main ways to use it:
20
13
 
21
- If you retrieved the source code of *reactive-json*, a demo app is available for use.
14
+ ### 1. Direct Integration in a React Application
22
15
 
23
- ```shell
24
- npm run dev
25
- ```
16
+ Use the `<ReactiveJsonRoot>` component directly in your React application. This is the recommended method if you're developing a complete React application.
26
17
 
27
- ## How to install *reactive-json*
18
+ ### 2. Automatic Association with HTML Tags
28
19
 
29
- ### Standalone mode
30
-
31
- This mode only needs you to download the `/dist` folder and load the JS and CSS assets
32
- in your web pages.
33
-
34
- If the `/dist` is not available (probably because you pulled the library from
35
- the source code repository), you will have to generate it:
36
-
37
- ```shell
38
- npm install && npm run build
39
- ```
20
+ To integrate reactive-json into an existing web page, you can use `<reactive-json>` tags and create an automatic association via ReactDOM. This approach is ideal for integrating interactive components into existing websites.
40
21
 
41
- ### Library mode
42
-
43
- This mode is when you have a React project, and you want to include *reactive-json*
44
- as a part of your project.
22
+ ## How to install *reactive-json*
45
23
 
46
- First, install the lib:
24
+ Install the library in your React project:
47
25
 
48
26
  ```shell
49
27
  npm install @ea-lab/reactive-json
50
28
  ```
51
29
 
52
- And that's all!
53
-
54
- You will have to use the `<ReactiveJsonRoot>` component, with the appropriate
55
- options.
30
+ ### Method 1: Direct Usage in React
56
31
 
57
32
  ```js
58
33
  import {ReactiveJsonRoot} from "@ea-lab/reactive-json";
59
34
 
60
- //...
61
-
62
35
  const YourComponent = () => {
63
36
  return (
64
37
  <div>
65
- <ReactiveJsonRoot dataUrl={"/path/to/build.json"}/>
38
+ <ReactiveJsonRoot
39
+ dataUrl={"/path/to/build.json"}
40
+ dataFetchMethod="GET" />
66
41
  </div>
67
42
  );
68
43
  };
69
44
  ```
70
45
 
46
+ ### Method 2: Automatic Association with HTML Tags
47
+
48
+ Create an initialization script that searches for `<reactive-json>` tags and automatically associates them:
49
+
50
+ ```js
51
+ import React from 'react';
52
+ import ReactDOM from 'react-dom/client';
53
+ import {ReactiveJsonRoot} from "@ea-lab/reactive-json";
54
+
55
+ // Find all <reactive-json> tags in the page
56
+ const appRootElements = document.querySelectorAll("reactive-json");
57
+
58
+ appRootElements.forEach(element => {
59
+ // Get the fetch method from data attribute
60
+ const maybeMethod = element.dataset?.method;
61
+
62
+ // Get headers for data requests
63
+ const headersForData_asElements = element.querySelectorAll("data-source-request-header");
64
+ const headersForData = headersForData_asElements.length ? {} : undefined;
65
+
66
+ headersForData_asElements.forEach((headerElement) => {
67
+ const headerField = headerElement?.dataset?.headerField;
68
+ const headerValue = headerElement?.dataset?.headerValue;
69
+
70
+ if (headerField && headerValue) {
71
+ headersForData[headerField] = headerValue;
72
+ }
73
+ });
74
+
75
+ // Create React root and mount the component
76
+ const root = ReactDOM.createRoot(element);
77
+
78
+ root.render(
79
+ <React.StrictMode>
80
+ <ReactiveJsonRoot
81
+ dataFetchMethod={maybeMethod}
82
+ dataUrl={element.dataset.url}
83
+ headersForData={headersForData}
84
+ />
85
+ </React.StrictMode>
86
+ );
87
+ });
88
+ ```
89
+
90
+ Then in your HTML:
91
+
92
+ ```html
93
+ <reactive-json data-url="/api/my-config.json" data-method="GET">
94
+ <!-- Optional headers for authentication -->
95
+ <data-source-request-header
96
+ data-header-field="Authorization"
97
+ data-header-value="Bearer your-token">
98
+ </data-source-request-header>
99
+ </reactive-json>
100
+ ```
101
+
102
+ ## ReactiveJsonRoot Properties
103
+
104
+ The `ReactiveJsonRoot` component accepts the following properties:
105
+
106
+ - `dataUrl`: The URL of the document containing the build data (JSON or YAML)
107
+ - `dataFetchMethod`: The fetch method for the data ("GET" or "POST", case-insensitive)
108
+ - `headersForData`: Headers for the data request (e.g., authentication info)
109
+ - `plugins`: Reactive-JSON plugins to extend functionality
110
+ - `debugMode`: Debug mode to show the data structure and debug info
111
+ - `maybeRawAppData`: A RjBuild configuration to initialize directly (string or object)
112
+
71
113
  ## How to extend *reactive-json*
72
114
 
73
- To add new components, you must be in library mode. Indeed, the
74
- standalone mode is a fixed set of functionality. This can be changed later if
75
- a plugin system can be implemented; do not hesitate to contribute in this
76
- project if you know how to make it, it would be really appreciated!
115
+ To add new components, consult the complete documentation:
116
+
117
+ **Online Documentation**: https://reactive-json.ea-lab.io
118
+
119
+ **Local Documentation** (install the docs package):
120
+ ```shell
121
+ npm install --save-dev @ea-lab/reactive-json-docs
122
+ ```
123
+
124
+ Documentation is available at:
125
+ - `node_modules/@ea-lab/reactive-json-docs/public/rjbuild/docs/extend/component-development.md`
126
+ - Main entry point: `node_modules/@ea-lab/reactive-json-docs/public/rjbuild/docs/index.yaml`
127
+
128
+ ## Demo Application
129
+
130
+ If you retrieved the source code of *reactive-json*, a demo app is available for use:
131
+
132
+ ```shell
133
+ npm run dev
134
+ ```
77
135
 
78
136
  ## Project structure
79
137
 
80
138
  This project was bootstrapped with [Vite](https://vite.dev/).
81
139
 
82
- The following is the specific documentation for the *reactive-json* project.
83
-
84
140
  ### Components `/lib/component`
85
141
 
86
142
  This is where the main component code is located.
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@ea-lab/reactive-json",
3
3
  "private": false,
4
- "version": "0.0.37",
4
+ "version": "0.0.39",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "git+https://bitbucket.org/ea-lab/reactive-json.git"
8
+ "url": "git+https://github.com/Ealab-collab/reactive-json.git"
9
9
  },
10
10
  "keywords": [
11
11
  "build",
@@ -21,9 +21,9 @@
21
21
  "author": "Quang-Minh DANG <quang-minh@ea-lab.io> (https://ea-lab.io/)",
22
22
  "license": "ISC",
23
23
  "bugs": {
24
- "url": "https://bitbucket.org/ea-lab/reactive-json/issues"
24
+ "url": "https://github.com/Ealab-collab/reactive-json/issues"
25
25
  },
26
- "homepage": "https://bitbucket.org/ea-lab/reactive-json#readme",
26
+ "homepage": "https://github.com/Ealab-collab/reactive-json#readme",
27
27
  "scripts": {
28
28
  "dev": "vite",
29
29
  "build": "tsc -b ./tsconfig.lib.json && vite build",
@@ -44,6 +44,7 @@
44
44
  "react-dom": "^19.1.0"
45
45
  },
46
46
  "devDependencies": {
47
+ "@ea-lab/reactive-json-docs": "^0.1.6",
47
48
  "@eslint/js": "^9.25.0",
48
49
  "@types/js-yaml": "^4.0.9",
49
50
  "@types/lodash": "^4.17.16",