@openremote/or-json-forms 1.13.1 → 1.14.0-snapshot

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.
package/README.md CHANGED
@@ -1,113 +1,126 @@
1
- # @openremote/or-map \<or-map\>
1
+ # @openremote/or-json-forms \<or-json-forms\>
2
2
  [![NPM Version][npm-image]][npm-url]
3
3
  [![Linux Build][travis-image]][travis-url]
4
4
  [![Test Coverage][coveralls-image]][coveralls-url]
5
5
 
6
- Web Component for displaying a Mapbox map; either raster or vector (default). This component requires an OpenRemote
7
- Manager to retrieve map settings and tiles.
6
+ Web Component for generating forms based on JSON Schema. This can be useful for creating forms for complex data structures and validating user input.
7
+
8
+ This component expects the JSON Schemas to be formatted as described in [Usage](#usage).
8
9
 
9
10
  ## Install
10
11
  ```bash
11
- npm i @openremote/or-map
12
- yarn add @openremote/or-map
12
+ npm i @openremote/or-json-forms
13
+ yarn add @openremote/or-json-forms
13
14
  ```
14
15
 
15
16
  ## Usage
16
- For a full list of properties, methods and options refer to the TypeDoc generated [documentation]().
17
+ <!--For a full list of properties, methods and options refer to the TypeDoc generated [documentation]().-->
17
18
 
18
- ```$html
19
- <or-map center="5.454250, 51.445990" zoom="5" style="height: 500px; width: 100%;" />
20
- ```
19
+ The JSON Forms expects [Draft-07](http://json-schema.org/draft-07) schemas.
21
20
 
22
- For a raster map (raster tile serving in the OpenRemote Manager must be properly configured):
21
+ ### Unsupported keywords
23
22
 
24
- ```$html
25
- <or-map type="RASTER" center="5.454250, 51.445990" zoom="5" style="height: 500px; width: 100%;" />
26
- ```
23
+ The following keywords are not (fully) supported:
27
24
 
28
- The center and zoom are optional overrides for the defaults that will be defined in the `mapsettings` loaded from the
29
- OpenRemote Manager; each realm can have different `mapsettings` with a fallback to the default.
25
+ - `anyOf`: ???
26
+ - `allOf`: ???
27
+ - `$ref`: will only resolve the reference if it is in the schema.
28
+ - `examples`: planned
30
29
 
31
- Markers can be added via markup as children:
30
+ ### Behavior Specification
32
31
 
33
- ```$html
34
- <or-map id="vectorMap" center="5.454250, 51.445990" zoom="5" style="height: 500px; width: 100%;">
35
- <or-map-marker id="demo-marker" lng="5.454250" class="marker" icon="or:logo-plain"></or-map-marker>
36
- </or-map>
37
- ```
32
+ - `{ "type": "string" }` - Displays a text input field.
33
+ - `{ "type": "number" }` - Displays a number input field.
34
+ - `{ "type": "integer" }` - Displays a number input field.
35
+ - `{ "type": "array" }` - Displays a wrapper with a button to add items.
36
+ - `{ "type": "object" }` - Displays a wrapper with a button to add properties.
38
37
 
39
- Or programmatically:
38
+ #### Renderers & Testers
40
39
 
41
- ```$typescript
42
- const vectorMap = docuemnt.getElementById("vectorMap");
43
- const assetMarker = document.createElement("or-map-marker-asset");
44
- assetMarker.setAttribute("asset", apartment1.id!);
45
- vectorMap.appendChild(assetMarker);
46
- ```
40
+ <!--#### Polymorphism-->
41
+
42
+ <!--'oneOf', 'anyOf', 'allOf'-->
43
+
44
+ #### Default values
45
+
46
+ The JSON Forms will resolve default values from the schema based on the `default` property or infer it from the type.
47
47
 
48
- There are two types of built in markers:
48
+ It derives the type from the schema's `type` property, or from properties that are characteristic of the type.
49
49
 
50
- ### \<or-map-marker\>
51
- This is a basic marker and the base class for any other markers and it has the following attributes:
50
+ | property | type |
51
+ | ----------------------- | ------------------ |
52
+ | `type` | The specified type |
53
+ | `properties` | object |
54
+ | `additionalProperties` | object |
55
+ | `items` | array |
52
56
 
53
- * lat*
54
- * lng*
55
- * visible (show/hide the marker)
56
- * icon (uses `or-icon` to render an icon inside the default marker)
57
- * interactive (sets pointer events for the marker)
57
+ <!--CombinatorKeyword[] = ['oneOf', 'anyOf', 'allOf']-->
58
58
 
59
- *required
59
+ <!-- See `doCreateDefaultValue` in node_modules/@jsonforms/core/src/mappers/renderer.ts -->
60
60
 
61
- The visual content of the marker can be controlled by adding child content to the `or-map-marker` element; any child
62
- content is rendered inside a `div`. If no children are specified then the default marker will be used. Subclasses can
63
- override the `createMarkerContent()` method to control the look of the marker.
61
+ Depending on the type, it derives the default value as follows:
64
62
 
65
- ### \<or-map-marker-asset\>
66
- This links the marker to an Asset in the OpenRemote Manager by using the `asset-mixin` and adds the following attribute:
63
+ | type | value | formats | Formatted default |
64
+ | ----------------------- | ----- | ------- | ------- |
65
+ | [...] (array of values) | [...] | | |
66
+ | string | `""` | date-time, date, time | `new Date()` |
67
+ | integer, number | `0` | | |
68
+ | boolean | `false` | |
69
+ | array | `[]` | |
70
+ | object | An object with the required properties, otherwise an empty object | |
71
+ | null | `null` | |
67
72
 
68
- * asset* (ID of the Asset to link)
73
+ ### Example usage
69
74
 
70
- *required
75
+ ```typescript
76
+ import { html } from 'lit';
77
+ import { ErrorObject, StandardRenderers } from "@openremote/or-json-forms";
78
+ import "@openremote/or-json-forms";
79
+
80
+ public class MyJsonForms extends LitElement {
81
+ private static schema = {
82
+ $schema: "http://json-schema.org/draft-07/schema#",
83
+ title: "MyObject",
84
+ type: "object",
85
+ properties: {
86
+ firstname: { type: "string" },
87
+ lastname: { type: "string" },
88
+ birthday: { type: "integer", minimum: 0 },
89
+ },
90
+ };
91
+ // Apply a custom UI schema to remove the outer VerticalLayout
92
+ private static uiSchema: any = { type: "Control", scope: "#" };
93
+
94
+ render() {
95
+ return html`<or-json-forms .renderers="${jsonFormsAttributeRenderers}" .schema="${schema}" .uischema="${uiSchema}" .onChange="${onChanged}"></or-json-forms>`
96
+ }
97
+
98
+ onChanged(dataAndErrors: { errors: ErrorObject[] | undefined, data: any }) {
99
+ // Do something with the data and errors
100
+ }
101
+ };
102
+ ```
103
+
104
+ ### Custom renderers
71
105
 
72
- The Asset must be valid, accessible and must have a valid `location` attribute otherwise no marker will be shown. By
73
- default the `AssetType` is used to set the icon of the marker but this can be controlled by setting the `assetTypeAsIcon`
74
- property.
75
-
76
106
  ### Styling
77
107
  All styling is done through CSS, the following CSS variables can be used:
78
108
 
79
- ```$css
80
- --or-map-marker-fill (default: #1D5632)
81
- --or-map-marker-stroke (default: none)
82
- --or-map-marker-width (default: 48px)
83
- --or-map-marker-height (default: 48px)
84
- --or-map-marker-transform (default: translate(-24px, -45px))
85
-
86
- --or-map-marker-icon-fill (default: #FFF)
87
- --or-map-marker-icon-stroke (default: none)
88
- --or-map-marker-icon-width (default: 24px)
89
- --or-map-marker-icon-height (default: 24px)
90
- --or-map-marker-icon-transform (default: translate(-50%, -19px))
109
+ ```css
110
+ --or-app-color3 /* Change text colors */
111
+ --or-app-color4 /* Change border colors */
112
+ --or-app-color5 /* Change border colors */
113
+ --or-icon-fill
91
114
  ```
92
115
 
93
- ### Events
94
- The following DOM events may be fired by the component and markers:
95
-
96
- * `click` - Standard click event is fired when the map itself is clicked
97
- * `OrMapMarkerEvent.CLICKED` - A map marker has been clicked; details contains the clicked `marker`
98
- * `OrMapMarkerEvent.CHANGED` - A map marker has been modified; details contains the changed `marker` and name of changed
99
- `property`
100
-
101
116
  ## Supported Browsers
102
- The last 2 versions of all modern browsers are supported, including Chrome, Safari, Opera, Firefox, Edge. In addition,
103
- Internet Explorer 11 is also supported.
104
-
117
+ The last 2 versions of all modern browsers are supported, including Chrome, Safari, Opera, Firefox, Edge.
105
118
 
106
119
  ## License
107
120
  [GNU AGPL](https://www.gnu.org/licenses/agpl-3.0.en.html)
108
121
 
109
122
  [npm-image]: https://img.shields.io/npm/v/live-xxx.svg
110
- [npm-url]: https://npmjs.org/package/@openremote/or-map
123
+ [npm-url]: https://npmjs.org/package/@openremote/or-json-forms
111
124
  [travis-image]: https://img.shields.io/travis/live-js/live-xxx/master.svg
112
125
  [travis-url]: https://travis-ci.org/live-js/live-xxx
113
126
  [coveralls-image]: https://img.shields.io/coveralls/live-js/live-xxx/master.svg
@@ -1,6 +1,10 @@
1
-
2
1
  import type { BaseElement } from "./lib/base-element.d.ts";
3
- import type { *, ErrorObject, StandardRenderers, getTemplateWrapper, OrJSONForms } from "./lib/index.d.ts";
2
+ import type {
3
+ ErrorObject,
4
+ StandardRenderers,
5
+ getTemplateWrapper,
6
+ OrJSONForms,
7
+ } from "./lib/index.d.ts";
4
8
 
5
9
  /**
6
10
  * This type can be used to create scoped tags for your components.
@@ -28,7 +32,6 @@ export type ScopedElements<
28
32
  };
29
33
 
30
34
  type BaseProps<T extends HTMLElement> = {
31
-
32
35
  /** Content added between the opening and closing tags of the element */
33
36
  children?: any;
34
37
  /** Used for declaratively styling one or more elements using CSS (Cascading Stylesheets) */
@@ -51,6 +54,8 @@ type BaseProps<T extends HTMLElement> = {
51
54
  key?: string | number;
52
55
  /** Specifies the language of the element. */
53
56
  lang?: string;
57
+ /** Defines the element's semantic role for accessibility APIs. */
58
+ role?: string;
54
59
  /** Contains a space-separated list of the part names of the element. Part names allows CSS to select and style specific elements in a shadow tree via the ::part pseudo-element. */
55
60
  part?: string;
56
61
  /** Use the ref attribute with a variable to assign a DOM element to the variable once the element is rendered. */
@@ -71,120 +76,179 @@ type BaseProps<T extends HTMLElement> = {
71
76
  popovertarget?: "top" | "bottom" | "left" | "right" | "auto";
72
77
  /** Specifies the action to be performed on a popover element being controlled by a control element. */
73
78
  popovertargetaction?: "show" | "hide" | "toggle";
74
-
75
- } ;
76
-
77
- type BaseEvents = {
78
-
79
-
80
79
  };
81
80
 
82
-
83
-
81
+ type BaseEvents = {};
84
82
 
85
83
  export type OrJSONFormsProps = {
86
84
  /** */
87
- "uischema"?: OrJSONForms['uischema'];
85
+ uischema?: OrJSONForms["uischema"];
88
86
  /** */
89
- "schema"?: OrJSONForms['schema'];
87
+ schema?: OrJSONForms["schema"];
90
88
  /** */
91
- "renderers"?: OrJSONForms['renderers'];
89
+ renderers?: OrJSONForms["renderers"];
92
90
  /** */
93
- "cells"?: OrJSONForms['cells'];
91
+ cells?: OrJSONForms["cells"];
94
92
  /** */
95
- "uischemas"?: OrJSONForms['uischemas'];
93
+ uischemas?: OrJSONForms["uischemas"];
96
94
  /** */
97
- "readonly"?: OrJSONForms['readonly'];
95
+ readonly?: OrJSONForms["readonly"];
98
96
  /** */
99
- "label"?: OrJSONForms['label'];
97
+ label?: OrJSONForms["label"];
100
98
  /** */
101
- "required"?: OrJSONForms['required'];
99
+ required?: OrJSONForms["required"];
102
100
  /** */
103
- "data"?: OrJSONForms['data'];
101
+ data?: OrJSONForms["data"];
104
102
  /** */
105
- "onChange"?: OrJSONForms['onChange'];
103
+ onChange?: OrJSONForms["onChange"];
106
104
  /** */
107
- "config"?: OrJSONForms['config'];
108
-
109
-
110
- }
105
+ config?: OrJSONForms["config"];
106
+ };
111
107
 
112
- export type CustomElements = {
108
+ export type OrJSONFormsSolidJsProps = {
109
+ /** */
110
+ "prop:uischema"?: OrJSONForms["uischema"];
111
+ /** */
112
+ "prop:schema"?: OrJSONForms["schema"];
113
+ /** */
114
+ "prop:renderers"?: OrJSONForms["renderers"];
115
+ /** */
116
+ "prop:cells"?: OrJSONForms["cells"];
117
+ /** */
118
+ "prop:uischemas"?: OrJSONForms["uischemas"];
119
+ /** */
120
+ "prop:readonly"?: OrJSONForms["readonly"];
121
+ /** */
122
+ "prop:label"?: OrJSONForms["label"];
123
+ /** */
124
+ "prop:required"?: OrJSONForms["required"];
125
+ /** */
126
+ "prop:data"?: OrJSONForms["data"];
127
+ /** */
128
+ "prop:onChange"?: OrJSONForms["onChange"];
129
+ /** */
130
+ "prop:config"?: OrJSONForms["config"];
113
131
 
132
+ /** Set the innerHTML of the element */
133
+ innerHTML?: string;
134
+ /** Set the textContent of the element */
135
+ textContent?: string | number;
136
+ };
114
137
 
138
+ export type CustomElements = {
139
+ /**
140
+ *
141
+ *
142
+ * ## Attributes & Properties
143
+ *
144
+ * Component attributes and properties that can be applied to the element or by using JavaScript.
145
+ *
146
+ * - `uischema`: undefined
147
+ * - `schema`: undefined
148
+ * - `renderers`: undefined
149
+ * - `cells`: undefined
150
+ * - `uischemas`: undefined
151
+ * - `readonly`: undefined
152
+ * - `label`: undefined
153
+ * - `required`: undefined
154
+ * - `data`: undefined (property only)
155
+ * - `onChange`: undefined (property only)
156
+ * - `config`: undefined (property only)
157
+ *
158
+ * ## Methods
159
+ *
160
+ * Methods that can be called to access component functionality.
161
+ *
162
+ * - `checkValidity() => void`: undefined
163
+ * - `updateCore(coreAction: T) => T`: undefined
164
+ */
165
+ "or-json-forms": Partial<
166
+ OrJSONFormsProps & BaseProps<OrJSONForms> & BaseEvents
167
+ >;
168
+ };
115
169
 
170
+ export type CustomElementsSolidJs = {
116
171
  /**
117
- *
118
- *
119
- * ## Attributes & Properties
120
- *
121
- * Component attributes and properties that can be applied to the element or by using JavaScript.
122
- *
123
- * - `uischema`: undefined
124
- * - `schema`: undefined
125
- * - `renderers`: undefined
126
- * - `cells`: undefined
127
- * - `uischemas`: undefined
128
- * - `readonly`: undefined
129
- * - `label`: undefined
130
- * - `required`: undefined
131
- * - `data`: undefined (property only)
132
- * - `onChange`: undefined (property only)
133
- * - `config`: undefined (property only)
134
- *
135
- * ## Methods
136
- *
137
- * Methods that can be called to access component functionality.
138
- *
139
- * - `checkValidity() => void`: undefined
140
- * - `updateCore(coreAction: T) => T`: undefined
141
- */
142
- "or-json-forms": Partial<OrJSONFormsProps & BaseProps<OrJSONForms> & BaseEvents>;
143
- }
172
+ *
173
+ *
174
+ * ## Attributes & Properties
175
+ *
176
+ * Component attributes and properties that can be applied to the element or by using JavaScript.
177
+ *
178
+ * - `uischema`: undefined
179
+ * - `schema`: undefined
180
+ * - `renderers`: undefined
181
+ * - `cells`: undefined
182
+ * - `uischemas`: undefined
183
+ * - `readonly`: undefined
184
+ * - `label`: undefined
185
+ * - `required`: undefined
186
+ * - `data`: undefined (property only)
187
+ * - `onChange`: undefined (property only)
188
+ * - `config`: undefined (property only)
189
+ *
190
+ * ## Methods
191
+ *
192
+ * Methods that can be called to access component functionality.
193
+ *
194
+ * - `checkValidity() => void`: undefined
195
+ * - `updateCore(coreAction: T) => T`: undefined
196
+ */
197
+ "or-json-forms": Partial<
198
+ OrJSONFormsProps &
199
+ OrJSONFormsSolidJsProps &
200
+ BaseProps<OrJSONForms> &
201
+ BaseEvents
202
+ >;
203
+ };
144
204
 
145
- export type CustomCssProperties = {
205
+ export type CustomCssProperties = {};
146
206
 
207
+ declare module "react" {
208
+ namespace JSX {
209
+ interface IntrinsicElements extends CustomElements {}
210
+ }
211
+ export interface CSSProperties extends CustomCssProperties {}
147
212
  }
148
213
 
149
-
150
- declare module 'react' {
214
+ declare module "preact" {
151
215
  namespace JSX {
152
216
  interface IntrinsicElements extends CustomElements {}
153
217
  }
154
218
  export interface CSSProperties extends CustomCssProperties {}
155
219
  }
156
220
 
157
- declare module 'preact' {
221
+ declare module "@builder.io/qwik" {
158
222
  namespace JSX {
159
223
  interface IntrinsicElements extends CustomElements {}
160
224
  }
161
225
  export interface CSSProperties extends CustomCssProperties {}
162
226
  }
163
227
 
164
- declare module '@builder.io/qwik' {
228
+ declare module "@stencil/core" {
165
229
  namespace JSX {
166
230
  interface IntrinsicElements extends CustomElements {}
167
231
  }
168
232
  export interface CSSProperties extends CustomCssProperties {}
169
233
  }
170
234
 
171
- declare module '@stencil/core' {
235
+ declare module "hono/jsx" {
172
236
  namespace JSX {
173
237
  interface IntrinsicElements extends CustomElements {}
174
238
  }
175
239
  export interface CSSProperties extends CustomCssProperties {}
176
240
  }
177
241
 
178
- declare module 'hono/jsx' {
242
+ declare module "react-native" {
179
243
  namespace JSX {
180
244
  interface IntrinsicElements extends CustomElements {}
181
245
  }
182
246
  export interface CSSProperties extends CustomCssProperties {}
183
247
  }
184
248
 
185
- declare module 'react-native' {
249
+ declare module "solid-js" {
186
250
  namespace JSX {
187
- interface IntrinsicElements extends CustomElements {}
251
+ interface IntrinsicElements extends CustomElementsSolidJs {}
188
252
  }
189
253
  export interface CSSProperties extends CustomCssProperties {}
190
254
  }
@@ -499,7 +499,7 @@
499
499
  "name": "*",
500
500
  "declaration": {
501
501
  "name": "*",
502
- "package": "\"@jsonforms/core\""
502
+ "package": "@jsonforms/core"
503
503
  }
504
504
  },
505
505
  {
@@ -921,12 +921,12 @@
921
921
  {
922
922
  "kind": "variable",
923
923
  "name": "baseStyle",
924
- "default": "css` :host { flex: 1; } .item-container { display: flex; } .delete-container, .drag-container { width: 30px; display: flex; vertical-align: middle; } .item-container:hover .button-clear, .item-wrapper:hover .button-clear { visibility: visible; } .no-match-container { align-items: center; } .no-match-container > *:not(:last-child) { margin-right: 10px; } .button-clear { background: none; color: ${unsafeCSS(DefaultColor5)}; --or-icon-fill: ${unsafeCSS(DefaultColor5)}; visibility: hidden; display: inline-block; border: none; padding: 0 0 0 5px; cursor: pointer; } .button-clear:hover { --or-icon-fill: ${unsafeCSS(DefaultColor4)}; } .button-clear:focus { outline: 0; } .button-clear.hidden { visibility: hidden; } .any-of-picker { width: 100%; min-width: 200px; } #errors { color: red; margin-right: 10px; flex: 1; display: flex; align-items: center; } #errors > or-icon { margin-right: 5px; } `"
924
+ "default": "css` :host { flex: 1; } .item-container { display: flex; } .delete-container, .drag-container { width: 30px; display: flex; vertical-align: middle; } .item-container:hover .button-clear, .item-wrapper:hover .button-clear { visibility: visible; } .no-match-container { align-items: center; } .no-match-container > *:not(:last-child) { margin-right: 10px; } .button-clear { background: none; color: ${unsafeCSS(DefaultColor5)}; --or-icon-fill: ${unsafeCSS(DefaultColor5)}; visibility: hidden; display: inline-block; border: none; padding: 0 0 0 5px; cursor: pointer; } .button-clear:hover { --or-icon-fill: ${unsafeCSS(DefaultColor4)}; } .button-clear:focus { outline: 0; } .button-clear.hidden { visibility: hidden; } .any-of-picker { width: 100%; } #errors { color: red; margin-right: 10px; flex: 1; display: flex; align-items: center; } #errors > or-icon { margin-right: 5px; } `"
925
925
  },
926
926
  {
927
927
  "kind": "variable",
928
928
  "name": "panelStyle",
929
- "default": "css` #header-description { flex: 1; display: flex; flex-direction: row; } #type-label { border: 1px solid green; border-radius: 3px; padding: 3px; margin-left: 10px; } #header-buttons { flex: 0; } #content-wrapper { flex: 1; padding: 0 4px 14px 24px; } #content { display: flex; flex-direction: column; } #content > * { flex: 1; } .item-container + .item-container { padding-top: 10px; } #footer { margin-top: 10px; } `"
929
+ "default": "css` #header-description { flex: 1; display: flex; flex-direction: row; } #type-label { border: 1px solid var(--or-app-color4, green); border-radius: 3px; padding: 3px; margin-left: 10px; } #header-buttons { flex: 0; } #content-wrapper { flex: 1; padding: 0 4px 14px 24px; } #content { display: flex; flex-direction: column; } #content > * { flex: 1; } .item-container + .item-container { padding-top: 10px; } #footer { margin-top: 10px; } `"
930
930
  },
931
931
  {
932
932
  "kind": "variable",
@@ -1045,21 +1045,9 @@
1045
1045
  }
1046
1046
  },
1047
1047
  {
1048
- "name": "resolvedSchema",
1048
+ "name": "resolvedSchemas",
1049
1049
  "type": {
1050
- "text": "JsonSchema"
1051
- }
1052
- },
1053
- {
1054
- "name": "path",
1055
- "type": {
1056
- "text": "string"
1057
- }
1058
- },
1059
- {
1060
- "name": "keyword",
1061
- "type": {
1062
- "text": "\"anyOf\" | \"oneOf\""
1050
+ "text": "JsonSchema[]"
1063
1051
  }
1064
1052
  },
1065
1053
  {
@@ -1123,7 +1111,7 @@
1123
1111
  {
1124
1112
  "name": "schema",
1125
1113
  "type": {
1126
- "text": "JsonSchema"
1114
+ "text": "JsonSchema & { discriminator?: { propertyName?: string } }"
1127
1115
  }
1128
1116
  },
1129
1117
  {
@@ -1133,7 +1121,7 @@
1133
1121
  }
1134
1122
  }
1135
1123
  ],
1136
- "description": "TODO: when updating to jsonforms/core 4.0 use `getCombinatorIndexOfFittingSchema` from jsonform/core instead"
1124
+ "description": "TODO: when updating to jsonforms/core 4.0 consider using `getCombinatorIndexOfFittingSchema` from jsonforms/core instead"
1137
1125
  },
1138
1126
  {
1139
1127
  "kind": "function",