@omegagrid/form 0.10.2 → 0.10.4

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 (101) hide show
  1. package/dist/constants.d.ts +52 -0
  2. package/dist/constants.d.ts.map +1 -0
  3. package/dist/constants.js +15 -0
  4. package/dist/constants.js.map +1 -0
  5. package/dist/index.d.ts +4 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +4 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/model/formAdapter.d.ts +14 -0
  10. package/dist/model/formAdapter.d.ts.map +1 -0
  11. package/dist/model/formAdapter.js +21 -0
  12. package/dist/model/formAdapter.js.map +1 -0
  13. package/dist/model/formControlModel.d.ts +9 -0
  14. package/dist/model/formControlModel.d.ts.map +1 -0
  15. package/dist/model/formControlModel.js +9 -0
  16. package/dist/model/formControlModel.js.map +1 -0
  17. package/dist/model/formModel.d.ts +17 -0
  18. package/dist/model/formModel.d.ts.map +1 -0
  19. package/dist/model/formModel.js +42 -0
  20. package/dist/model/formModel.js.map +1 -0
  21. package/dist/model/index.d.ts +4 -0
  22. package/dist/model/index.d.ts.map +1 -0
  23. package/dist/model/index.js +4 -0
  24. package/dist/model/index.js.map +1 -0
  25. package/dist/options.d.ts +3 -0
  26. package/dist/options.d.ts.map +1 -0
  27. package/dist/options.js +17 -0
  28. package/dist/options.js.map +1 -0
  29. package/dist/types.d.ts +99 -0
  30. package/dist/types.d.ts.map +1 -0
  31. package/dist/types.js +14 -0
  32. package/dist/types.js.map +1 -0
  33. package/dist/ui/controls/baseControl.d.ts +32 -0
  34. package/dist/ui/controls/baseControl.d.ts.map +1 -0
  35. package/dist/ui/controls/baseControl.js +97 -0
  36. package/dist/ui/controls/baseControl.js.map +1 -0
  37. package/dist/ui/controls/button.d.ts +16 -0
  38. package/dist/ui/controls/button.d.ts.map +1 -0
  39. package/dist/ui/controls/button.js +80 -0
  40. package/dist/ui/controls/button.js.map +1 -0
  41. package/dist/ui/controls/calendarDateInput.d.ts +11 -0
  42. package/dist/ui/controls/calendarDateInput.d.ts.map +1 -0
  43. package/dist/ui/controls/calendarDateInput.js +67 -0
  44. package/dist/ui/controls/calendarDateInput.js.map +1 -0
  45. package/dist/ui/controls/checkbox.d.ts +8 -0
  46. package/dist/ui/controls/checkbox.d.ts.map +1 -0
  47. package/dist/ui/controls/checkbox.js +38 -0
  48. package/dist/ui/controls/checkbox.js.map +1 -0
  49. package/dist/ui/controls/colorInput.d.ts +9 -0
  50. package/dist/ui/controls/colorInput.d.ts.map +1 -0
  51. package/dist/ui/controls/colorInput.js +48 -0
  52. package/dist/ui/controls/colorInput.js.map +1 -0
  53. package/dist/ui/controls/dateInput.d.ts +11 -0
  54. package/dist/ui/controls/dateInput.d.ts.map +1 -0
  55. package/dist/ui/controls/dateInput.js +80 -0
  56. package/dist/ui/controls/dateInput.js.map +1 -0
  57. package/dist/ui/controls/fileInput.d.ts +6 -0
  58. package/dist/ui/controls/fileInput.d.ts.map +1 -0
  59. package/dist/ui/controls/fileInput.js +28 -0
  60. package/dist/ui/controls/fileInput.js.map +1 -0
  61. package/dist/ui/controls/index.d.ts +11 -0
  62. package/dist/ui/controls/index.d.ts.map +1 -0
  63. package/dist/ui/controls/index.js +11 -0
  64. package/dist/ui/controls/index.js.map +1 -0
  65. package/dist/ui/controls/label.d.ts +6 -0
  66. package/dist/ui/controls/label.d.ts.map +1 -0
  67. package/dist/ui/controls/label.js +53 -0
  68. package/dist/ui/controls/label.js.map +1 -0
  69. package/dist/ui/controls/list.d.ts +17 -0
  70. package/dist/ui/controls/list.d.ts.map +1 -0
  71. package/dist/ui/controls/list.js +83 -0
  72. package/dist/ui/controls/list.js.map +1 -0
  73. package/dist/ui/controls/numericInput.d.ts +14 -0
  74. package/dist/ui/controls/numericInput.d.ts.map +1 -0
  75. package/dist/ui/controls/numericInput.js +81 -0
  76. package/dist/ui/controls/numericInput.js.map +1 -0
  77. package/dist/ui/controls/textInput.d.ts +11 -0
  78. package/dist/ui/controls/textInput.d.ts.map +1 -0
  79. package/dist/ui/controls/textInput.js +67 -0
  80. package/dist/ui/controls/textInput.js.map +1 -0
  81. package/dist/ui/form.d.ts +38 -0
  82. package/dist/ui/form.d.ts.map +1 -0
  83. package/dist/ui/form.js +201 -0
  84. package/dist/ui/form.js.map +1 -0
  85. package/dist/ui/form.style.d.ts +2 -0
  86. package/dist/ui/form.style.d.ts.map +1 -0
  87. package/dist/ui/form.style.js +45 -0
  88. package/dist/ui/form.style.js.map +1 -0
  89. package/dist/ui/formContainer.d.ts +31 -0
  90. package/dist/ui/formContainer.d.ts.map +1 -0
  91. package/dist/ui/formContainer.js +197 -0
  92. package/dist/ui/formContainer.js.map +1 -0
  93. package/dist/ui/formContainer.style.d.ts +2 -0
  94. package/dist/ui/formContainer.style.d.ts.map +1 -0
  95. package/dist/ui/formContainer.style.js +39 -0
  96. package/dist/ui/formContainer.style.js.map +1 -0
  97. package/dist/ui/index.d.ts +4 -0
  98. package/dist/ui/index.d.ts.map +1 -0
  99. package/dist/ui/index.js +4 -0
  100. package/dist/ui/index.js.map +1 -0
  101. package/package.json +5 -5
@@ -0,0 +1,31 @@
1
+ import { LitElement } from 'lit';
2
+ import { Overlay } from '@omegagrid/core';
3
+ import { FormAlert, FormButtonConfig, FormButtonType, FormContainerOptions, FormSettings, FormValues } from '../types';
4
+ import { FormAdapter } from '../model';
5
+ import { Form } from './form';
6
+ export declare class FormContainer extends LitElement {
7
+ static styles: import("lit").CSSResult[];
8
+ config: FormSettings[];
9
+ options: FormContainerOptions;
10
+ collapsibleForms: boolean;
11
+ adapter: FormAdapter;
12
+ alerts: FormAlert[];
13
+ overlay: Overlay;
14
+ forms: NodeListOf<Form>;
15
+ private _saving;
16
+ constructor();
17
+ connectedCallback(): void;
18
+ showOverlay: () => void;
19
+ hideOverlay: () => HTMLElement;
20
+ get values(): Map<string | number, FormValues>;
21
+ setSourceData(config: FormSettings[], options?: Partial<FormContainerOptions>): void;
22
+ reset(dispatchEvent?: boolean): void;
23
+ isValid(): boolean;
24
+ save(dispatchEvent?: boolean): Promise<boolean>;
25
+ _onButtonClick: (btn: FormButtonConfig) => void;
26
+ initAdapter(): Promise<void>;
27
+ updated(changedProps: Map<PropertyKey, unknown>): Promise<void>;
28
+ renderButton: (type: FormButtonType) => import("lit-html").TemplateResult<1>;
29
+ render: () => import("lit-html").TemplateResult<1>;
30
+ }
31
+ //# sourceMappingURL=formContainer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formContainer.d.ts","sourceRoot":"","sources":["../../src/ui/formContainer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,UAAU,EAAE,MAAM,KAAK,CAAC;AAGvC,OAAO,EAAuB,OAAO,EAAS,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,cAAc,EAAE,oBAAoB,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACvH,OAAO,EAAE,WAAW,EAAa,MAAM,UAAU,CAAC;AAGlD,OAAO,EAAE,IAAI,EAAa,MAAM,QAAQ,CAAC;AAGzC,qBACa,aAAc,SAAQ,UAAU;IAE5C,MAAM,CAAC,MAAM,4BAAW;IAGxB,MAAM,EAAE,YAAY,EAAE,CAAC;IAGvB,OAAO,EAAE,oBAAoB,CAAiB;IAG9C,gBAAgB,UAAS;IAGzB,OAAO,EAAE,WAAW,CAAC;IAGrB,MAAM,EAAE,SAAS,EAAE,CAAC;IAGpB,OAAO,EAAE,OAAO,CAAC;IAGjB,KAAK,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;IAExB,OAAO,CAAC,OAAO,CAAS;;IASxB,iBAAiB;IAKjB,WAAW,aAAkC;IAC7C,WAAW,oBAA8B;IAEzC,IAAI,MAAM,qCAIT;IAED,aAAa,CAAC,MAAM,EAAE,YAAY,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC;IAK7E,KAAK,CAAC,aAAa,UAAO;IAK1B,OAAO;IAID,IAAI,CAAC,aAAa,UAAO;IA6B/B,cAAc,GAAI,KAAK,gBAAgB,UActC;IAEK,WAAW;IAOX,OAAO,CAAC,YAAY,EAAE,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC;IAMrD,YAAY,GAAI,MAAM,cAAc,0CAalC;IAEF,MAAM,6CAyCL;CAED"}
@@ -0,0 +1,197 @@
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 { html, LitElement } from 'lit';
8
+ import { customElement, property, query, queryAll } from "lit/decorators.js";
9
+ import { map } from "lit/directives/map.js";
10
+ import { actions, ColorTypes, utils } from '@omegagrid/core';
11
+ import { FormModel } from '../model';
12
+ import constants from '../constants';
13
+ import { initOptions } from '../options';
14
+ import { FormEvent } from './form';
15
+ import { style } from './formContainer.style';
16
+ let FormContainer = class FormContainer extends LitElement {
17
+ constructor() {
18
+ super();
19
+ this.options = initOptions();
20
+ this.collapsibleForms = false;
21
+ this._saving = false;
22
+ this.showOverlay = () => this.overlay?.show(this);
23
+ this.hideOverlay = () => this.overlay?.hide();
24
+ this._onButtonClick = (btn) => {
25
+ switch (btn.key) {
26
+ case 'save':
27
+ this.save();
28
+ break;
29
+ case 'reset':
30
+ this.reset();
31
+ break;
32
+ case 'close':
33
+ this.dispatchEvent(new Event('close'));
34
+ break;
35
+ default:
36
+ this.adapter?.onAction(btn.key);
37
+ this.dispatchEvent(new actions.ActionEvent('form', { key: btn.key }, null, {
38
+ bubbles: true,
39
+ composed: true,
40
+ common: true
41
+ }));
42
+ break;
43
+ }
44
+ };
45
+ this.renderButton = (type) => {
46
+ const btn = utils.isObject(type) ? type : constants.BUTTON_CONFIG.get(type);
47
+ btn.key = btn.key ?? (utils.isString(type) ? type : null);
48
+ btn.color = btn.color || ColorTypes.Gray;
49
+ return html `
50
+ <og-button
51
+ .text="${btn.text}"
52
+ .color="${btn.color}"
53
+ .icon="${btn.icon}"
54
+ @click="${() => this._onButtonClick(btn)}"
55
+ ?default="${btn.default}">
56
+ </og-button>
57
+ `;
58
+ };
59
+ this.render = () => {
60
+ const buttons = this.options.buttons.length > 0
61
+ ? html `<div class="buttons">${map(this.options.buttons, type => this.renderButton(type))}</div>`
62
+ : null;
63
+ const alerts = map(this.alerts, alert => html `
64
+ <og-alert .text="${alert.text}" .type="${alert.type}"></og-alert>
65
+ `);
66
+ return html `
67
+ ${this.options.caption ? html `<div class="title">${this.options.caption}</div>` : ``}
68
+ ${this.options.buttonsPosition == 'top' ? buttons : ``}
69
+ ${this.options.alertsPosition == 'top' ? alerts : ``}
70
+ <og-overlay defaultLoader></og-overlay>
71
+ <og-container>
72
+ <div slot="content">
73
+ ${map(this.config, (f, index) => {
74
+ const form = html `
75
+ <og-form
76
+ slot="body"
77
+ key=${f.key ?? index.toString()}
78
+ .adapter=${this.adapter}
79
+ .model=${this.adapter == null ? new FormModel(f) : null}
80
+ .rows=${f.rows}
81
+ .columns=${f.columns}>
82
+ </og-form>
83
+ `;
84
+ return f.caption ? html `
85
+ <og-panel ?collapsible="${this.collapsibleForms}">
86
+ ${f.caption ? html `<div slot="header">${f.caption}</div>` : ``}
87
+ ${form}
88
+ </og-panel>
89
+ ` : html `
90
+ <div>${form}</div>
91
+ `;
92
+ })}
93
+ </div>
94
+ </og-container>
95
+ ${this.options.alertsPosition == 'bottom' ? alerts : ``}
96
+ ${this.options.buttonsPosition == 'bottom' ? buttons : ``}
97
+ `;
98
+ };
99
+ this.addEventListener('keydown', (e) => {
100
+ if (e.key == 'Enter')
101
+ this.save();
102
+ });
103
+ }
104
+ connectedCallback() {
105
+ super.connectedCallback();
106
+ this.tabIndex = 0;
107
+ }
108
+ get values() {
109
+ const values = new Map();
110
+ this.forms.forEach((f, i) => values.set(this.config[i].key ?? i, f.values));
111
+ return values;
112
+ }
113
+ setSourceData(config, options) {
114
+ this.config = config;
115
+ this.options = initOptions(options, this.options);
116
+ }
117
+ reset(dispatchEvent = true) {
118
+ this.forms.forEach(f => f.reset());
119
+ if (dispatchEvent)
120
+ this.dispatchEvent(new FormEvent('reset'));
121
+ }
122
+ isValid() {
123
+ return Array.from(this.forms.values()).every(f => f.isValid());
124
+ }
125
+ async save(dispatchEvent = true) {
126
+ if (this._saving)
127
+ return false;
128
+ if (!this.isValid())
129
+ return false;
130
+ this._saving = true;
131
+ if (this.adapter) {
132
+ this.showOverlay();
133
+ let success = true;
134
+ try {
135
+ const result = await this.adapter.save(this.values);
136
+ if (result === false) {
137
+ success = false;
138
+ }
139
+ else if (Array.isArray(result)) {
140
+ this.alerts = result;
141
+ }
142
+ }
143
+ catch (error) {
144
+ success = false;
145
+ this.alerts = [{ text: error.message, type: 'danger' }];
146
+ }
147
+ this.hideOverlay();
148
+ if (dispatchEvent && success) {
149
+ this.dispatchEvent(new FormEvent('save'));
150
+ if (this.options.closeAfterSave)
151
+ this.dispatchEvent(new Event('close'));
152
+ }
153
+ }
154
+ else if (dispatchEvent)
155
+ this.dispatchEvent(new FormEvent('save'));
156
+ this._saving = false;
157
+ return true;
158
+ }
159
+ async initAdapter() {
160
+ this.showOverlay();
161
+ this.config = await this.adapter.getForms();
162
+ this.options = initOptions(await this.adapter.getOptions(), this.options);
163
+ this.hideOverlay();
164
+ }
165
+ async updated(changedProps) {
166
+ if (changedProps.has('adapter')) {
167
+ await this.initAdapter();
168
+ }
169
+ }
170
+ };
171
+ FormContainer.styles = [style];
172
+ __decorate([
173
+ property({ type: Array })
174
+ ], FormContainer.prototype, "config", void 0);
175
+ __decorate([
176
+ property({ type: Object })
177
+ ], FormContainer.prototype, "options", void 0);
178
+ __decorate([
179
+ property({ type: Boolean })
180
+ ], FormContainer.prototype, "collapsibleForms", void 0);
181
+ __decorate([
182
+ property({ type: Object })
183
+ ], FormContainer.prototype, "adapter", void 0);
184
+ __decorate([
185
+ property({ type: Array })
186
+ ], FormContainer.prototype, "alerts", void 0);
187
+ __decorate([
188
+ query('og-overlay')
189
+ ], FormContainer.prototype, "overlay", void 0);
190
+ __decorate([
191
+ queryAll('og-form')
192
+ ], FormContainer.prototype, "forms", void 0);
193
+ FormContainer = __decorate([
194
+ customElement('og-form-container')
195
+ ], FormContainer);
196
+ export { FormContainer };
197
+ //# sourceMappingURL=formContainer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formContainer.js","sourceRoot":"","sources":["../../src/ui/formContainer.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,UAAU,EAAW,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAEtE,OAAO,EAAe,SAAS,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAQ,SAAS,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAGvC,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,UAAU;IA2B5C;QACC,KAAK,EAAE,CAAC;QApBT,YAAO,GAAyB,WAAW,EAAE,CAAC;QAG9C,qBAAgB,GAAG,KAAK,CAAC;QAcjB,YAAO,GAAG,KAAK,CAAC;QAcxB,gBAAW,GAAG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AC;QAC1B,CAAC;IACF,CAAC;;AApHM,oBAAM,GAAG,CAAC,KAAK,CAAC,AAAV,CAAW;AAGxB;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,KAAK,EAAC,CAAC;6CACD;AAGvB;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;8CACqB;AAG9C;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAC,CAAC;uDACD;AAGzB;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;8CACJ;AAGrB;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,KAAK,EAAC,CAAC;6CACJ;AAGpB;IADC,KAAK,CAAC,YAAY,CAAC;8CACH;AAGjB;IADC,QAAQ,CAAC,SAAS,CAAC;4CACI;AAvBZ,aAAa;IADzB,aAAa,CAAC,mBAAmB,CAAC;GACtB,aAAa,CAkLzB","sourcesContent":["import { html, LitElement } from 'lit';\nimport { customElement, property, query, queryAll } from \"lit/decorators.js\";\nimport { map } from \"lit/directives/map.js\";\nimport { actions, ColorTypes, Overlay, utils } from '@omegagrid/core';\nimport { FormAlert, FormButtonConfig, FormButtonType, FormContainerOptions, FormSettings, FormValues } from '../types';\nimport { FormAdapter, FormModel } from '../model';\nimport constants from '../constants';\nimport { initOptions } from '../options';\nimport { Form, FormEvent } from './form'; \nimport { style } from './formContainer.style';\n\n@customElement('og-form-container')\nexport class FormContainer extends LitElement {\n\n\tstatic styles = [style];\n\n\t@property({type: Array})\n\tconfig: FormSettings[];\n\n\t@property({type: Object})\n\toptions: FormContainerOptions = initOptions();\n\n\t@property({type: Boolean})\n\tcollapsibleForms = false;\n\n\t@property({type: Object})\n\tadapter: FormAdapter;\n\n\t@property({type: Array})\n\talerts: FormAlert[];\n\n\t@query('og-overlay')\n\toverlay: Overlay;\n\n\t@queryAll('og-form')\n\tforms: NodeListOf<Form>;\n\n\tprivate _saving = false;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.addEventListener('keydown', (e: KeyboardEvent) => {\n\t\t\tif (e.key == 'Enter') this.save();\n\t\t});\n\t}\n\n\tconnectedCallback() {\n\t\tsuper.connectedCallback();\n\t\tthis.tabIndex = 0;\n\t}\n\n\tshowOverlay = () => this.overlay?.show(this);\n\thideOverlay = () => this.overlay?.hide();\n\n\tget values() {\n\t\tconst values = new Map<string|number, FormValues>(); \n\t\tthis.forms.forEach((f, i) => values.set(this.config[i].key ?? i, f.values));\n\t\treturn values;\n\t}\n\t\n\tsetSourceData(config: FormSettings[], options?: Partial<FormContainerOptions>) {\n\t\tthis.config = config;\n\t\tthis.options = initOptions(options, this.options);\n\t}\n\n\treset(dispatchEvent = true) {\n\t\tthis.forms.forEach(f => f.reset());\n\t\tif (dispatchEvent) this.dispatchEvent(new FormEvent('reset'));\n\t}\n\t\n\tisValid() {\n\t\treturn Array.from(this.forms.values()).every(f => f.isValid());\n\t}\n\n\tasync save(dispatchEvent = true) {\n\t\tif (this._saving) return false;\n\t\tif (!this.isValid()) return false;\n\t\tthis._saving = true;\n\t\tif (this.adapter) {\n\t\t\tthis.showOverlay();\n\t\t\tlet success = true;\n\t\t\ttry {\n\t\t\t\tconst result = await this.adapter.save(this.values);\n\t\t\t\tif (result === false) {\n\t\t\t\t\tsuccess = false;\n\t\t\t\t} else if (Array.isArray(result)) {\n\t\t\t\t\tthis.alerts = result;\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tsuccess = false;\n\t\t\t\tthis.alerts = [{text: error.message, type: 'danger'}];\n\t\t\t}\n\t\t\t\n\t\t\tthis.hideOverlay();\n\t\t\tif (dispatchEvent && success) {\n\t\t\t\tthis.dispatchEvent(new FormEvent('save'));\n\t\t\t\tif (this.options.closeAfterSave) this.dispatchEvent(new Event('close'));\n\t\t\t}\n\t\t} else if (dispatchEvent) this.dispatchEvent(new FormEvent('save'));\n\t\tthis._saving = false\n\t\treturn true;\n\t}\n\n\t_onButtonClick = (btn: FormButtonConfig) => {\n\t\tswitch (btn.key) {\n\t\t\tcase 'save': this.save(); break;\n\t\t\tcase 'reset': this.reset(); break;\n\t\t\tcase 'close': this.dispatchEvent(new Event('close')); break;\n\t\t\tdefault:\n\t\t\t\tthis.adapter?.onAction(btn.key);\n\t\t\t\tthis.dispatchEvent(new actions.ActionEvent('form', {key: btn.key}, null, {\n\t\t\t\t\tbubbles: true, \n\t\t\t\t\tcomposed: true,\n\t\t\t\t\tcommon: true\n\t\t\t\t}));\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tasync initAdapter() {\n\t\tthis.showOverlay();\n\t\tthis.config = await this.adapter.getForms();\n\t\tthis.options = initOptions(await this.adapter.getOptions(), this.options);\n\t\tthis.hideOverlay();\n\t}\n\n\tasync updated(changedProps: Map<PropertyKey, unknown>) {\n\t\tif (changedProps.has('adapter')) {\n\t\t\tawait this.initAdapter();\n\t\t}\n\t}\n\n\trenderButton = (type: FormButtonType) => {\n\t\tconst btn = utils.isObject(type) ? (type as FormButtonConfig) : constants.BUTTON_CONFIG.get(type);\n\t\tbtn.key = btn.key ?? (utils.isString(type) ? (type as string) : null);\n\t\tbtn.color = btn.color || ColorTypes.Gray;\n\t\treturn html`\n\t\t\t<og-button \n\t\t\t\t.text=\"${btn.text}\"\n\t\t\t\t.color=\"${btn.color}\"\n\t\t\t\t.icon=\"${btn.icon}\"\n\t\t\t\t@click=\"${() => this._onButtonClick(btn)}\"\n\t\t\t\t?default=\"${btn.default}\">\n\t\t\t</og-button>\n\t\t`;\n\t};\n\n\trender = () => {\n\t\tconst buttons = this.options.buttons.length > 0\n\t\t\t? html`<div class=\"buttons\">${map(this.options.buttons, type => this.renderButton(type))}</div>`\n\t\t\t: null;\n\n\t\tconst alerts = map(this.alerts, alert => html`\n\t\t\t<og-alert .text=\"${alert.text}\" .type=\"${alert.type}\"></og-alert>\n\t\t`);\n\n\t\treturn html`\n\t\t\t${this.options.caption ? html`<div class=\"title\">${this.options.caption}</div>`: ``}\n\t\t\t${this.options.buttonsPosition == 'top' ? buttons : ``}\n\t\t\t${this.options.alertsPosition == 'top' ? alerts : ``}\n\t\t\t<og-overlay defaultLoader></og-overlay>\n\t\t\t<og-container>\n\t\t\t\t<div slot=\"content\">\n\t\t\t\t\t${map(this.config, (f, index) => {\n\t\t\t\t\t\tconst form = html`\n\t\t\t\t\t\t\t<og-form\n\t\t\t\t\t\t\t\tslot=\"body\"\n\t\t\t\t\t\t\t\tkey=${f.key ?? index.toString()}\n\t\t\t\t\t\t\t\t.adapter=${this.adapter}\n\t\t\t\t\t\t\t\t.model=${this.adapter == null ? new FormModel(f) : null}\n\t\t\t\t\t\t\t\t.rows=${f.rows}\n\t\t\t\t\t\t\t\t.columns=${f.columns}>\n\t\t\t\t\t\t\t</og-form>\n\t\t\t\t\t\t`;\n\t\t\t\t\t\treturn f.caption ? html`\n\t\t\t\t\t\t\t<og-panel ?collapsible=\"${this.collapsibleForms}\">\n\t\t\t\t\t\t\t\t${f.caption ? html`<div slot=\"header\">${f.caption}</div>` : ``}\n\t\t\t\t\t\t\t\t${form}\n\t\t\t\t\t\t\t</og-panel>\n\t\t\t\t\t\t` : html`\n\t\t\t\t\t\t\t<div>${form}</div>\n\t\t\t\t\t\t`;\n\t\t\t\t\t})}\n\t\t\t\t</div>\n\t\t\t</og-container>\n\t\t\t${this.options.alertsPosition == 'bottom' ? alerts : ``}\n\t\t\t${this.options.buttonsPosition == 'bottom' ? buttons : ``}\n\t\t`;\n\t}\n\n}"]}
@@ -0,0 +1,2 @@
1
+ export declare const style: import("lit").CSSResult;
2
+ //# sourceMappingURL=formContainer.style.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formContainer.style.d.ts","sourceRoot":"","sources":["../../src/ui/formContainer.style.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,KAAK,yBAoCjB,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { css } from "lit";
2
+ export const style = css `
3
+ * {
4
+ box-sizing: border-box;
5
+ }
6
+
7
+ :host {
8
+ display: flex;
9
+ flex-direction: column;
10
+ position: relative;
11
+ border-radius: var(--og-base-radius);
12
+ }
13
+
14
+ .title {
15
+ background-color: var(--og-accent-color);
16
+ padding: 5px;
17
+ color: var(--og-text-color-reversed);
18
+ flex: 0;
19
+ }
20
+
21
+ og-container {
22
+ flex: 1;
23
+ }
24
+
25
+ .buttons {
26
+ display: flex;
27
+ flex-direction: row;
28
+ gap: 4px;
29
+ justify-content: flex-end;
30
+ border-top: 1px solid var(--og-border-color);
31
+ padding: 4px;
32
+ }
33
+
34
+ .buttons og-button {
35
+ min-width: 80px;
36
+ text-align: center;
37
+ }
38
+ `;
39
+ //# sourceMappingURL=formContainer.style.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formContainer.style.js","sourceRoot":"","sources":["../../src/ui/formContainer.style.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,MAAM,CAAC,MAAM,KAAK,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoCvB,CAAC","sourcesContent":["import { css } from \"lit\";\n\nexport const style = css`\n\t* {\n\t\tbox-sizing: border-box;\n\t}\n\n\t:host {\n\t\tdisplay: flex;\n\t\tflex-direction: column;\n\t\tposition: relative;\n\t\tborder-radius: var(--og-base-radius);\n\t}\n\n\t.title {\n\t\tbackground-color: var(--og-accent-color);\n\t\tpadding: 5px;\n\t\tcolor: var(--og-text-color-reversed);\n\t\tflex: 0;\n\t}\n\n\tog-container {\n\t\tflex: 1;\n\t}\n\n\t.buttons {\n\t\tdisplay: flex;\n\t\tflex-direction: row;\n\t\tgap: 4px;\n\t\tjustify-content: flex-end;\n\t\tborder-top: 1px solid var(--og-border-color);\n\t\tpadding: 4px;\n\t}\n\n\t.buttons og-button {\n\t\tmin-width: 80px;\n\t\ttext-align: center;\n\t}\n`;"]}
@@ -0,0 +1,4 @@
1
+ export * from './form';
2
+ export * from './formContainer';
3
+ export * from './controls';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ui/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './form';
2
+ export * from './formContainer';
3
+ export * from './controls';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ui/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC","sourcesContent":["export * from './form';\nexport * from './formContainer';\nexport * from './controls';"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omegagrid/form",
3
- "version": "0.10.2",
3
+ "version": "0.10.4",
4
4
  "license": "UNLICENSED",
5
5
  "description": "Universal form component",
6
6
  "main": "./dist/index.js",
@@ -27,10 +27,10 @@
27
27
  "_prepublish": "yarn test && yarn lint"
28
28
  },
29
29
  "dependencies": {
30
- "@omegagrid/calendar": "^0.10.2",
31
- "@omegagrid/core": "^0.10.2",
32
- "@omegagrid/localize": "^0.10.2",
33
- "@omegagrid/tree": "^0.10.2",
30
+ "@omegagrid/calendar": "^0.10.4",
31
+ "@omegagrid/core": "^0.10.4",
32
+ "@omegagrid/localize": "^0.10.4",
33
+ "@omegagrid/tree": "^0.10.4",
34
34
  "lit": "^3.1.1",
35
35
  "lit-html": "^3.1.1",
36
36
  "ts-debounce": "^4.0.0"