@openremote/or-json-forms 1.8.0-snapshot.20250725070921 → 1.8.0-snapshot.20250725120000

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.
@@ -1,21 +1,158 @@
1
- var __decorate=this&&this.__decorate||function(t,e,i,n){var r,o=arguments.length,s=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,i,n);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(s=(o<3?r(s):o>3?r(e,i,s):r(e,i))||s);return o>3&&s&&Object.defineProperty(e,i,s),s};import{InputType as t}from"@openremote/or-mwc-components/or-mwc-input";import{css as e,html as i}from"lit";import{customElement as n}from"lit/decorators.js";import{ControlBaseElement as r}from"./control-base-element";import{baseStyle as o}from"../styles";import{isBooleanControl as s,isEnumControl as a,isIntegerControl as p,isNumberControl as m,isOneOfEnumControl as l,isStringControl as h}from"@jsonforms/core";import{isEnumArray as u}from"../standard-renderers";let style=e`
2
- or-mwc-input {
3
- width: 100%;
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { InputType } from "@openremote/or-mwc-components/or-mwc-input";
8
+ import { css, html } from "lit";
9
+ import { customElement } from "lit/decorators.js";
10
+ import { ControlBaseElement } from "./control-base-element";
11
+ import { baseStyle } from "../styles";
12
+ import { isBooleanControl, isEnumControl, isIntegerControl, isNumberControl, isOneOfEnumControl, isStringControl } from "@jsonforms/core";
13
+ import { isEnumArray } from "../standard-renderers";
14
+ // language=CSS
15
+ const style = css `
16
+ or-mwc-input {
17
+ width: 100%;
18
+ }
19
+ `;
20
+ let ControlInputElement = class ControlInputElement extends ControlBaseElement {
21
+ static get styles() {
22
+ return [
23
+ baseStyle,
24
+ style
25
+ ];
4
26
  }
5
- `,ControlInputElement=class extends r{static get styles(){return[o,style]}render(){var e;let n,r,o,d,c,y,f,g=this.uischema,T=this.schema,E=this.schema.format,O={rootSchema:this.rootSchema,config:this.config};this.inputType=t.TEXT;let S=!1,v=null!=(e=this.data)?e:T.default;return Array.isArray(T.type)?this.inputType=t.JSON:s(g,T,O)?this.inputType=t.CHECKBOX:m(g,T,O)||p(g,T,O)?(n=m(g,T,O)?.1:1,this.inputType=t.NUMBER,r=T.minimum,d=T.maximum,n=T.multipleOf||n,void 0!==r&&void 0!==d&&"or-range"===E&&(d-r)/n<=200&&(this.inputType=t.RANGE)):a(g,T,O)||l(g,T,O)||u(g,T,O)?(this.inputType=t.SELECT,a(g,T,O)?f=T.enum.map(t=>[JSON.stringify(t),String(t)]):l(g,T,O)?f=T.oneOf.map(t=>[JSON.stringify(t.const),String(t.const)]):(S=!0,f=T.items.oneOf?T.items.oneOf.map(t=>[JSON.stringify(t.const),String(t.const)]):T.items.enum.map(t=>[JSON.stringify(t),String(t)])),v=S?Array.isArray(v)?v.map(t=>JSON.stringify(t)):void 0!==v?[JSON.stringify(v)]:void 0:void 0!==v?JSON.stringify(v):void 0):h(g,T,O)&&(o=T.minLength,c=T.maxLength,y=T.pattern,"date-time"===E?this.inputType=t.DATETIME:"date"===E?this.inputType=t.DATE:"time"===E?this.inputType=t.TIME:"email"===E?this.inputType=t.EMAIL:"tel"===E?this.inputType=t.TELEPHONE:"or-multiline"===E?this.inputType=t.TEXTAREA:("or-password"===E||T.writeOnly)&&(this.inputType=t.PASSWORD)),i`<or-mwc-input
6
- .label="${this.label}"
7
- .type="${this.inputType}"
8
- .disabled="${!this.enabled}"
9
- .required="${!!this.required}"
10
- .id="${this.id}"
11
- .options="${f}"
12
- .multiple="${S}"
13
- @or-mwc-input-changed="${t=>this.onValueChanged(t)}"
14
- .maxLength="${c}"
15
- .minLength="${o}"
16
- .pattern="${y}"
17
- .validationMessage="${this.errors}"
18
- .step="${n}"
19
- .max="${d}"
20
- .min="${r}"
21
- .value="${v}"></or-mwc-input>`}onValueChanged(e){this.inputType===t.SELECT?Array.isArray(e.detail.value)?this.handleChange(this.path,e.detail.value.map(t=>JSON.parse(t))):this.handleChange(this.path,JSON.parse(e.detail.value)):this.handleChange(this.path,e.detail.value)}};ControlInputElement=__decorate([n("or-json-forms-input-control")],ControlInputElement);export{ControlInputElement};
27
+ render() {
28
+ var _a;
29
+ const uischema = this.uischema;
30
+ const schema = this.schema;
31
+ const format = this.schema.format;
32
+ const context = { rootSchema: this.rootSchema, config: this.config };
33
+ this.inputType = InputType.TEXT;
34
+ let step;
35
+ let min;
36
+ let minLength;
37
+ let max;
38
+ let maxLength;
39
+ let pattern;
40
+ let options;
41
+ let multiple = false;
42
+ let value = (_a = this.data) !== null && _a !== void 0 ? _a : schema.default;
43
+ if (Array.isArray(schema.type)) {
44
+ this.inputType = InputType.JSON;
45
+ }
46
+ else if (isBooleanControl(uischema, schema, context)) {
47
+ this.inputType = InputType.CHECKBOX;
48
+ }
49
+ else if (isNumberControl(uischema, schema, context) || isIntegerControl(uischema, schema, context)) {
50
+ step = isNumberControl(uischema, schema, context) ? 0.1 : 1;
51
+ this.inputType = InputType.NUMBER;
52
+ min = schema.minimum;
53
+ max = schema.maximum;
54
+ step = schema.multipleOf || step;
55
+ if (min !== undefined && max !== undefined && format === "or-range") {
56
+ // Limit to 200 graduations
57
+ if ((max - min) / step <= 200) {
58
+ this.inputType = InputType.RANGE;
59
+ }
60
+ }
61
+ }
62
+ else if (isEnumControl(uischema, schema, context)
63
+ || isOneOfEnumControl(uischema, schema, context)
64
+ || isEnumArray(uischema, schema, context)) {
65
+ this.inputType = InputType.SELECT;
66
+ if (isEnumControl(uischema, schema, context)) {
67
+ options = schema.enum.map(enm => {
68
+ return [JSON.stringify(enm), String(enm)];
69
+ });
70
+ }
71
+ else if (isOneOfEnumControl(uischema, schema, context)) {
72
+ options = schema.oneOf.map(s => {
73
+ return [JSON.stringify(s.const), String(s.const)];
74
+ });
75
+ }
76
+ else {
77
+ multiple = true;
78
+ if (schema.items.oneOf) {
79
+ options = schema.items.oneOf.map(s => {
80
+ return [JSON.stringify(s.const), String(s.const)];
81
+ });
82
+ }
83
+ else {
84
+ options = schema.items.enum.map(enm => {
85
+ return [JSON.stringify(enm), String(enm)];
86
+ });
87
+ }
88
+ }
89
+ if (multiple) {
90
+ value = Array.isArray(value) ? value.map(v => JSON.stringify(v)) : value !== undefined ? [JSON.stringify(value)] : undefined;
91
+ }
92
+ else {
93
+ value = value !== undefined ? JSON.stringify(value) : undefined;
94
+ }
95
+ }
96
+ else if (isStringControl(uischema, schema, context)) {
97
+ minLength = schema.minLength;
98
+ maxLength = schema.maxLength;
99
+ pattern = schema.pattern;
100
+ if (format === "date-time") {
101
+ this.inputType = InputType.DATETIME;
102
+ }
103
+ else if (format === "date") {
104
+ this.inputType = InputType.DATE;
105
+ }
106
+ else if (format === "time") {
107
+ this.inputType = InputType.TIME;
108
+ }
109
+ else if (format === "email") {
110
+ this.inputType = InputType.EMAIL;
111
+ }
112
+ else if (format === "tel") {
113
+ this.inputType = InputType.TELEPHONE;
114
+ }
115
+ else if (format === "or-multiline") {
116
+ this.inputType = InputType.TEXTAREA;
117
+ }
118
+ else if (format === "or-password" || schema.writeOnly) {
119
+ this.inputType = InputType.PASSWORD;
120
+ }
121
+ }
122
+ return html `<or-mwc-input
123
+ .label="${this.label}"
124
+ .type="${this.inputType}"
125
+ .disabled="${!this.enabled}"
126
+ .required="${!!this.required}"
127
+ .id="${this.id}"
128
+ .options="${options}"
129
+ .multiple="${multiple}"
130
+ @or-mwc-input-changed="${(e) => this.onValueChanged(e)}"
131
+ .maxLength="${maxLength}"
132
+ .minLength="${minLength}"
133
+ .pattern="${pattern}"
134
+ .validationMessage="${this.errors}"
135
+ .step="${step}"
136
+ .max="${max}"
137
+ .min="${min}"
138
+ .value="${value}"></or-mwc-input>`;
139
+ }
140
+ onValueChanged(e) {
141
+ if (this.inputType === InputType.SELECT) {
142
+ if (Array.isArray(e.detail.value)) {
143
+ this.handleChange(this.path, e.detail.value.map((v) => JSON.parse(v)));
144
+ }
145
+ else {
146
+ this.handleChange(this.path, JSON.parse(e.detail.value));
147
+ }
148
+ }
149
+ else {
150
+ this.handleChange(this.path, e.detail.value);
151
+ }
152
+ }
153
+ };
154
+ ControlInputElement = __decorate([
155
+ customElement("or-json-forms-input-control")
156
+ ], ControlInputElement);
157
+ export { ControlInputElement };
158
+ //# sourceMappingURL=control-input-element.js.map
package/lib/index.js CHANGED
@@ -1,9 +1,143 @@
1
- var __decorate=this&&this.__decorate||function(e,t,r,o){var s,i=arguments.length,a=i<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,r):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,o);else for(var h=e.length-1;h>=0;h--)(s=e[h])&&(a=(i<3?s(a):i>3?s(t,r,a):s(t,r))||a);return i>3&&a&&Object.defineProperty(t,r,a),a};import{css as e,html as t,LitElement as r}from"lit";import{customElement as o,property as s,state as i}from"lit/decorators.js";import{Actions as a,configReducer as h,coreReducer as c,createAjv as d,generateDefaultUISchema as n,generateJsonSchema as p,mapStateToJsonFormsRendererProps as m,setConfig as l}from"@jsonforms/core";import{getTemplateWrapper as u,StandardRenderers as O}from"./standard-renderers";import{getLabel as y,getTemplateFromProps as _}from"./util";import{baseStyle as f}from"./styles";import{Util as v}from"@openremote/core";let styles=e`
2
- .delete-container {
3
- width: 0;
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { css, html, LitElement } from "lit";
8
+ import { customElement, property, state } from "lit/decorators.js";
9
+ import { Actions, configReducer, coreReducer, createAjv, generateDefaultUISchema, generateJsonSchema, mapStateToJsonFormsRendererProps, setConfig } from "@jsonforms/core";
10
+ import { getTemplateWrapper, StandardRenderers } from "./standard-renderers";
11
+ import { getLabel, getTemplateFromProps } from "./util";
12
+ import { baseStyle } from "./styles";
13
+ import { Util } from "@openremote/core";
14
+ export { StandardRenderers, getTemplateWrapper };
15
+ // language=CSS
16
+ const styles = css `
17
+ .delete-container {
18
+ width: 0;
19
+ }
20
+
21
+ .item-container {
22
+ margin: 0; /* Remove inherited margin */
23
+ }
24
+ `;
25
+ let OrJSONForms = class OrJSONForms extends LitElement {
26
+ constructor() {
27
+ super(...arguments);
28
+ this.renderers = StandardRenderers;
29
+ this.readonly = false;
30
+ this.required = false;
31
+ this.previousErrors = [];
4
32
  }
5
-
6
- .item-container {
7
- margin: 0; /* Remove inherited margin */
33
+ static get styles() {
34
+ return [
35
+ baseStyle,
36
+ styles
37
+ ];
8
38
  }
9
- `,OrJSONForms=class extends r{constructor(){super(...arguments),this.renderers=O,this.readonly=!1,this.required=!1,this.previousErrors=[]}static get styles(){return[f,styles]}checkValidity(){return 0===this.previousErrors.length}shouldUpdate(e){if(super.shouldUpdate(e),this.schema||(this.schema=void 0!==this.data?p(this.data):{}),this.uischema||(this.uischema=n(this.schema)),this.core||(this.core={ajv:d({useDefaults:!0,validateFormats:!1}),data:{},schema:this.schema,uischema:this.uischema},this.updateCore(a.init(this.data,this.schema,this.uischema)),this.config=h(void 0,l(this.config))),(e.has("data")||e.has("schema")||e.has("uischema"))&&this.updateCore(a.updateCore(this.data,this.schema,this.uischema)),(!this.contextValue||e.has("core")||e.has("renderers")||e.has("cells")||e.has("config")||e.has("readonly"))&&(this.contextValue={core:this.core,renderers:this.renderers,cells:this.cells,config:this.config,uischemas:this.uischemas,readonly:this.readonly,dispatch:e=>this.updateCore(e)}),e.has("core")){let e=this.core.data,t=this.core.errors;this.onChange&&(!v.objectsEqual(e,this.previousData,!0)||t&&!v.objectsEqual(t,this.previousErrors,!0))&&(this.previousErrors=t||[],this.previousData=e,this.onChange({data:e,errors:t}))}return!0}updateCore(e){let t=c(this.core,e);return t!==this.core&&(this.core=t),e}render(){if(!this.contextValue)return t``;let e=Object.assign(Object.assign({},m({jsonforms:Object.assign({},this.contextValue)},this)),{label:y(this.schema,this.uischema,this.label,void 0)||"",required:this.required});return _(this.contextValue,e)||t``}};__decorate([s({type:Object})],OrJSONForms.prototype,"uischema",void 0),__decorate([s({type:Object})],OrJSONForms.prototype,"schema",void 0),__decorate([s({type:Object,attribute:!1})],OrJSONForms.prototype,"data",void 0),__decorate([s({type:Array})],OrJSONForms.prototype,"renderers",void 0),__decorate([s({type:Array})],OrJSONForms.prototype,"cells",void 0),__decorate([s({type:String,attribute:!1})],OrJSONForms.prototype,"onChange",void 0),__decorate([s({type:String,attribute:!1})],OrJSONForms.prototype,"config",void 0),__decorate([s({type:Array})],OrJSONForms.prototype,"uischemas",void 0),__decorate([s({type:Boolean})],OrJSONForms.prototype,"readonly",void 0),__decorate([s({type:String})],OrJSONForms.prototype,"label",void 0),__decorate([s({type:Boolean})],OrJSONForms.prototype,"required",void 0),__decorate([i()],OrJSONForms.prototype,"core",void 0),__decorate([i()],OrJSONForms.prototype,"contextValue",void 0),OrJSONForms=__decorate([o("or-json-forms")],OrJSONForms);export{O as StandardRenderers,u as getTemplateWrapper,OrJSONForms};
39
+ checkValidity() {
40
+ return this.previousErrors.length === 0;
41
+ }
42
+ shouldUpdate(_changedProperties) {
43
+ super.shouldUpdate(_changedProperties);
44
+ if (!this.schema) {
45
+ this.schema = this.data !== undefined ? generateJsonSchema(this.data) : {};
46
+ }
47
+ if (!this.uischema) {
48
+ this.uischema = generateDefaultUISchema(this.schema);
49
+ }
50
+ if (!this.core) {
51
+ this.core = {
52
+ ajv: createAjv({ useDefaults: true, validateFormats: false }),
53
+ data: {},
54
+ schema: this.schema,
55
+ uischema: this.uischema
56
+ };
57
+ this.updateCore(Actions.init(this.data, this.schema, this.uischema));
58
+ this.config = configReducer(undefined, setConfig(this.config));
59
+ }
60
+ if (_changedProperties.has("data") || _changedProperties.has("schema") || _changedProperties.has("uischema")) {
61
+ this.updateCore(Actions.updateCore(this.data, this.schema, this.uischema));
62
+ }
63
+ if (!this.contextValue || _changedProperties.has("core") || _changedProperties.has("renderers") || _changedProperties.has("cells") || _changedProperties.has("config") || _changedProperties.has("readonly")) {
64
+ this.contextValue = {
65
+ core: this.core,
66
+ renderers: this.renderers,
67
+ cells: this.cells,
68
+ config: this.config,
69
+ uischemas: this.uischemas,
70
+ readonly: this.readonly,
71
+ dispatch: (action) => this.updateCore(action)
72
+ };
73
+ }
74
+ if (_changedProperties.has("core")) {
75
+ const data = this.core.data;
76
+ const errors = this.core.errors;
77
+ if (this.onChange && (!Util.objectsEqual(data, this.previousData, true) || (errors && !Util.objectsEqual(errors, this.previousErrors, true)))) {
78
+ this.previousErrors = errors || [];
79
+ this.previousData = data;
80
+ this.onChange({ data: data, errors: errors });
81
+ }
82
+ }
83
+ return true;
84
+ }
85
+ updateCore(coreAction) {
86
+ const coreState = coreReducer(this.core, coreAction);
87
+ if (coreState !== this.core) {
88
+ this.core = coreState;
89
+ }
90
+ return coreAction;
91
+ }
92
+ render() {
93
+ if (!this.contextValue) {
94
+ return html ``;
95
+ }
96
+ const props = Object.assign(Object.assign({}, mapStateToJsonFormsRendererProps({ jsonforms: Object.assign({}, this.contextValue) }, this)), { label: getLabel(this.schema, this.uischema, this.label, undefined) || "", required: this.required });
97
+ return getTemplateFromProps(this.contextValue, props) || html ``;
98
+ }
99
+ };
100
+ __decorate([
101
+ property({ type: Object })
102
+ ], OrJSONForms.prototype, "uischema", void 0);
103
+ __decorate([
104
+ property({ type: Object })
105
+ ], OrJSONForms.prototype, "schema", void 0);
106
+ __decorate([
107
+ property({ type: Object, attribute: false })
108
+ ], OrJSONForms.prototype, "data", void 0);
109
+ __decorate([
110
+ property({ type: Array })
111
+ ], OrJSONForms.prototype, "renderers", void 0);
112
+ __decorate([
113
+ property({ type: Array })
114
+ ], OrJSONForms.prototype, "cells", void 0);
115
+ __decorate([
116
+ property({ type: String, attribute: false })
117
+ ], OrJSONForms.prototype, "onChange", void 0);
118
+ __decorate([
119
+ property({ type: String, attribute: false })
120
+ ], OrJSONForms.prototype, "config", void 0);
121
+ __decorate([
122
+ property({ type: Array })
123
+ ], OrJSONForms.prototype, "uischemas", void 0);
124
+ __decorate([
125
+ property({ type: Boolean })
126
+ ], OrJSONForms.prototype, "readonly", void 0);
127
+ __decorate([
128
+ property({ type: String })
129
+ ], OrJSONForms.prototype, "label", void 0);
130
+ __decorate([
131
+ property({ type: Boolean })
132
+ ], OrJSONForms.prototype, "required", void 0);
133
+ __decorate([
134
+ state()
135
+ ], OrJSONForms.prototype, "core", void 0);
136
+ __decorate([
137
+ state()
138
+ ], OrJSONForms.prototype, "contextValue", void 0);
139
+ OrJSONForms = __decorate([
140
+ customElement("or-json-forms")
141
+ ], OrJSONForms);
142
+ export { OrJSONForms };
143
+ //# sourceMappingURL=index.js.map
@@ -1 +1,29 @@
1
- var __decorate=this&&this.__decorate||function(e,t,r,o){var s,i=arguments.length,c=i<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,r):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(e,t,r,o);else for(var a=e.length-1;a>=0;a--)(s=e[a])&&(c=(i<3?s(c):i>3?s(t,r,c):s(t,r))||c);return i>3&&c&&Object.defineProperty(t,r,c),c};import{property as e}from"lit/decorators.js";import{BaseElement as t}from"../base-element";export class LayoutBaseElement extends t{constructor(){super(...arguments),this.direction="column"}getChildProps(){return(this.uischema&&this.uischema.elements?this.uischema.elements:[]).map(e=>({renderers:this.renderers,uischema:e,schema:this.schema,path:this.path}))}}__decorate([e({type:String})],LayoutBaseElement.prototype,"direction",void 0);
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { property } from "lit/decorators.js";
8
+ import { BaseElement } from "../base-element";
9
+ export class LayoutBaseElement extends BaseElement {
10
+ constructor() {
11
+ super(...arguments);
12
+ this.direction = "column";
13
+ }
14
+ getChildProps() {
15
+ return (this.uischema && this.uischema.elements ? this.uischema.elements : []).map((el) => {
16
+ const props = {
17
+ renderers: this.renderers,
18
+ uischema: el,
19
+ schema: this.schema,
20
+ path: this.path
21
+ };
22
+ return props;
23
+ });
24
+ }
25
+ }
26
+ __decorate([
27
+ property({ type: String })
28
+ ], LayoutBaseElement.prototype, "direction", void 0);
29
+ //# sourceMappingURL=layout-base-element.js.map