@jsonui/react 0.0.6

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 (51) hide show
  1. package/README.md +206 -0
  2. package/dist/cjs/index.js +39105 -0
  3. package/dist/cjs/index.js.map +1 -0
  4. package/dist/cjs/types/ErrorBoundary.d.ts +21 -0
  5. package/dist/cjs/types/ReduxProviders.d.ts +5 -0
  6. package/dist/cjs/types/Renderer.d.ts +7 -0
  7. package/dist/cjs/types/ViewerWeb.d.ts +13 -0
  8. package/dist/cjs/types/Wrapper.d.ts +3 -0
  9. package/dist/cjs/types/index.d.ts +6 -0
  10. package/dist/cjs/types/indexModule.d.ts +6 -0
  11. package/dist/cjs/types/indexWeb.d.ts +1 -0
  12. package/dist/cjs/types/stock/components/Button.d.ts +3 -0
  13. package/dist/cjs/types/stock/components/FieldEdit.d.ts +3 -0
  14. package/dist/cjs/types/stock/components/FormResult.d.ts +5 -0
  15. package/dist/cjs/types/stock/components/Fragment.d.ts +4 -0
  16. package/dist/cjs/types/stock/components/HelperText.d.ts +3 -0
  17. package/dist/cjs/types/stock/components/Image.d.ts +3 -0
  18. package/dist/cjs/types/stock/components/Label.d.ts +9 -0
  19. package/dist/cjs/types/stock/components/PrimitiveProp.d.ts +5 -0
  20. package/dist/cjs/types/stock/components/Text.d.ts +3 -0
  21. package/dist/cjs/types/stock/components/Undefined.d.ts +3 -0
  22. package/dist/cjs/types/stock/components/View.d.ts +3 -0
  23. package/dist/cjs/types/stock/components.d.ts +20 -0
  24. package/dist/cjs/types/stock/stockToRenderer.d.ts +22 -0
  25. package/dist/cjs/types/store/store.d.ts +7 -0
  26. package/dist/esm/index.js +39097 -0
  27. package/dist/esm/index.js.map +1 -0
  28. package/dist/esm/types/ErrorBoundary.d.ts +21 -0
  29. package/dist/esm/types/ReduxProviders.d.ts +5 -0
  30. package/dist/esm/types/Renderer.d.ts +7 -0
  31. package/dist/esm/types/ViewerWeb.d.ts +13 -0
  32. package/dist/esm/types/Wrapper.d.ts +3 -0
  33. package/dist/esm/types/index.d.ts +6 -0
  34. package/dist/esm/types/indexModule.d.ts +6 -0
  35. package/dist/esm/types/indexWeb.d.ts +1 -0
  36. package/dist/esm/types/stock/components/Button.d.ts +3 -0
  37. package/dist/esm/types/stock/components/FieldEdit.d.ts +3 -0
  38. package/dist/esm/types/stock/components/FormResult.d.ts +5 -0
  39. package/dist/esm/types/stock/components/Fragment.d.ts +4 -0
  40. package/dist/esm/types/stock/components/HelperText.d.ts +3 -0
  41. package/dist/esm/types/stock/components/Image.d.ts +3 -0
  42. package/dist/esm/types/stock/components/Label.d.ts +9 -0
  43. package/dist/esm/types/stock/components/PrimitiveProp.d.ts +5 -0
  44. package/dist/esm/types/stock/components/Text.d.ts +3 -0
  45. package/dist/esm/types/stock/components/Undefined.d.ts +3 -0
  46. package/dist/esm/types/stock/components/View.d.ts +3 -0
  47. package/dist/esm/types/stock/components.d.ts +20 -0
  48. package/dist/esm/types/stock/stockToRenderer.d.ts +22 -0
  49. package/dist/esm/types/store/store.d.ts +7 -0
  50. package/dist/index.d.ts +16 -0
  51. package/package.json +102 -0
package/README.md ADDED
@@ -0,0 +1,206 @@
1
+ # JSONUI
2
+
3
+ This is a Json markup language to define User Interface as a canvas where you can draw with Json definition.
4
+
5
+ When you change the Json definition, the interface immediately reflects on what you defined/changed.
6
+
7
+ Actually JSONUI is available for **react** and **react-native**. It will be able to integrate to 99% of the cross-platform environments, thanks for reactjs ecosystem
8
+
9
+ The UI definition contains a layout definition and components configuration as well. The most important it has a built in **state management system**. Data can be **persistent** or not, depends on the name of the store.
10
+
11
+ ## Core concept
12
+
13
+ Build a data driven UI. The "definition" is changeable by developer anytime and any reason.
14
+ If you would like to build a remote controlled app or a form generator app, I hope you will love it.
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install @jsonui/react
20
+
21
+ yarn add @jsonui/react
22
+ ```
23
+
24
+ ## Basic Usage
25
+
26
+ The `JsonUI` Component is a canvas and the `viewDef` parameter contains the UI definition in Json format.
27
+
28
+ ```js
29
+ import {JsonUI} from '@jsonui/react';
30
+
31
+ const Canvas = () => <JsonUI viewDef={
32
+ { "$comp": "Text",
33
+ "$children": "Hello World",
34
+ "style": { "fontSize": 30 }
35
+ } />
36
+ ```
37
+
38
+ ### How it works
39
+
40
+ The Json Markup language has 3 important part
41
+
42
+ #### 1, Components
43
+
44
+ The `"$comp"` key represents the name of a predefined react component. The predefined components:
45
+
46
+ - **View:** it's a simple `div` html tag
47
+ - **Button:** it's a simple `button` html tag
48
+ - **Fragment:** it's a simple `React.Fragment` component
49
+ - **Image:** it's a simple `image` html tag
50
+ - **Text:** it's a simple `p` html tag
51
+
52
+ The props of the components are the same as in the normal react world.
53
+
54
+ The `"$children"` key represents the children of the component.
55
+ It can be array, object or primitive like text, number, boolean
56
+
57
+ ```json
58
+ { "$comp": "Text", "$children": "Hello World" }
59
+ { "$comp": "Text", "$children": 124 }
60
+ { "$comp": "Text", "$children": [1,2,3] }
61
+ { "$comp": "Text", "$children": null }
62
+ { "$comp": "View", "$children": [
63
+ { "$comp": "Text", "$children": "Hello World" }
64
+ ]
65
+ }
66
+ ```
67
+
68
+ #### 2, Actions
69
+
70
+ When the component has an interaction with user or a triggered event, the `"$action"` key will represent it, for example onClick, onChange or onPress
71
+
72
+ ```json
73
+ { "$comp": "Button", "$children": "Login", "onPress": { "$action": "navigate", "route": "LoginPage" } }
74
+ ```
75
+
76
+ The action is really a predefined function when it will fire, when the event has triggered.
77
+
78
+ #### 3, Modifiers
79
+
80
+ The `"$action"` can add a dynamic value for properties or components. It's a function which will be called at render time of the component. Depends on environment data. For example JSONUI contains a basic internalisation solution.
81
+
82
+ ```json
83
+ { "$comp": "Text", "$children": "Hello World" }
84
+ { "$comp": "Text", "$children": { "$modifier": "t", "key": "Helló Világ" } }
85
+ ```
86
+
87
+ ### How can you customise it?
88
+
89
+ Easily.
90
+
91
+ ```js
92
+
93
+ const Canvas = () => <JsonUI viewDef={jsonData}
94
+ "components"={
95
+ {
96
+ nagivate: ({route}) => navigate(route)
97
+ }
98
+ }
99
+ "functions"={
100
+ {
101
+ t: ({key}) => t(key)
102
+ }
103
+ }/>
104
+ ```
105
+
106
+ ### State management or data storage
107
+
108
+ The state management is another layer of the JSNOUI. It's represent a permissive and dynamic tree graf structure. Like a JSON file.
109
+ Each app has a separated data space, based on the `id` param of `JsonUI` component.
110
+ Each app has multiple `store` represent multiple data tree or separate storage.
111
+ Actually the `data` store is persistent. (it will be configurable soon if there is interest in it)
112
+ You can define unlimited data store. What you need is, just use a specific name in JSON Definition, and it will automatically create at the first use.
113
+ JSONUI use [json-pointer](https://www.npmjs.com/package/json-pointer) to tell the `path` what kind of data we need.
114
+
115
+ We have 2 built-in function which can help to read and write your state management.
116
+
117
+ Let's see some example
118
+
119
+ #### Read data
120
+
121
+ ##### Your data store Looks like:
122
+
123
+ ```json
124
+ { "users": [{ "username": "John Doe" }] }
125
+ ```
126
+
127
+ ##### Use _/username_ in text field
128
+
129
+ ```json
130
+ { "$comp": "Text", "$children": { "$modifier": "get", "store": "data", "path": "/users/0/username" } }
131
+ ```
132
+
133
+ #### Write data
134
+
135
+ ##### When the user click on the button, it will modify the data
136
+
137
+ ```json
138
+ { "$comp": "Button", "$children": "Change username", "onPress": { "$modifier": "set", "store": "data", "path": "/users/0/username", "value": "John Doe 2" } }
139
+ ```
140
+
141
+ ##### Data will be:
142
+
143
+ ```json
144
+ { "users": [{ "username": "John Doe2" }] }
145
+ ```
146
+
147
+ ##### A simple input field solution
148
+
149
+ ```json
150
+ {
151
+ "$comp": "Input",
152
+ "value": { "$name": "get", "store": "questionnaire1", "path": "/firstName" },
153
+ "onChange": { "$action": "set", "store": "questionnaire1", "path": "/firstName" }
154
+ }
155
+ ```
156
+
157
+ You can manipulate the data when read or write it with [jsonata](https://jsonata.org/).
158
+
159
+ ```json
160
+ { "$comp": "Text", "children": { "$modifier": "get", "store": "data", "path": "/prevNumber", "jsonataDef": "'Next Number: ' & (1+$)" } }
161
+ ```
162
+
163
+ ### Advanced technique
164
+
165
+ #### Relative, absolute
166
+
167
+ You can use absolute, relative path and ./ ../ still works.
168
+ few examples
169
+
170
+ ```json
171
+ { "path": "/prevNumber" }
172
+ { "path": "prevNumber" }
173
+ { "path": "../prevNumber" }
174
+ { "path": "../../prevNumber" }
175
+ ```
176
+
177
+ #### List
178
+
179
+ Somethimes we need to handle dynamic data for example a list.
180
+
181
+ ##### Your data store looks like:
182
+
183
+ ```json
184
+ { "subscribed": { "list": [{ "name": "John Doe" }] } }
185
+ ```
186
+
187
+ ```json
188
+ {
189
+ "$comp": "Fragment",
190
+ "isList": true,
191
+ "$pathModifiers": {
192
+ "data": { "path": "/subscribed/list" }
193
+ },
194
+ "listItem": {
195
+ "component": "Input",
196
+ "value": { "$modifier": "get", "store": "data", "path": "name" },
197
+ "onChange": { "$action": "set", "store": "data", "path": "name" }
198
+ }
199
+ }
200
+ ```
201
+
202
+ This little technique can change the relative path nestedly as well.
203
+
204
+ ## LICENSE [MIT](LICENSE)
205
+
206
+ Copyright (c) 2022 Istvan Fodor.