@golemui/lit 0.14.0 → 0.15.0
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/CHANGELOG.md +4 -0
- package/index.js +140 -117
- package/index.umd.cjs +5 -4
- package/lib/components/form/form.element.d.ts +7 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { createContext as h, consume as m, provide as I, ContextProvider as
|
|
2
|
-
import { FormContext as
|
|
3
|
-
import { Subject as E, takeUntil as p, combineLatest as
|
|
4
|
-
import { LitElement as
|
|
5
|
-
import { property as
|
|
1
|
+
import { createContext as h, consume as m, provide as I, ContextProvider as S } from "@lit/context";
|
|
2
|
+
import { FormContext as W, calculatedWidgetsByUid$ as A, assertNoPropCollisions as O, dataByPath$ as N, validationByPath$ as R, injectedValidationByPath$ as L, touchedControlsByPath$ as P, calculatedLayoutChildrenByUid$ as F, makeRepeaterItemConfig as C, cloneObject as D, errorCodes as $, shortUUID as M, getDirectionFromLanguage as w, formHealth as U } from "@golemui/core";
|
|
3
|
+
import { Subject as E, takeUntil as p, combineLatest as j } from "rxjs";
|
|
4
|
+
import { LitElement as f, nothing as V, html as b } from "lit";
|
|
5
|
+
import { property as d, customElement as y, state as B } from "lit/decorators.js";
|
|
6
6
|
import { when as H } from "lit/directives/when.js";
|
|
7
|
-
const
|
|
8
|
-
class z extends
|
|
7
|
+
const v = h("guiFormContext");
|
|
8
|
+
class z extends W {
|
|
9
9
|
// Just a subclass to make Core.FormContext Injectable
|
|
10
10
|
}
|
|
11
11
|
class g {
|
|
@@ -23,7 +23,7 @@ class g {
|
|
|
23
23
|
}
|
|
24
24
|
// Listen to the calculated props stream and keep all widget props merged in a flattened object
|
|
25
25
|
templateDataUpdater() {
|
|
26
|
-
this.context.store.state$.pipe(p(this.destroy$),
|
|
26
|
+
this.context.store.state$.pipe(p(this.destroy$), A(this.widget.uid)).subscribe((t) => {
|
|
27
27
|
const o = {
|
|
28
28
|
...t,
|
|
29
29
|
lang: this.context.store.getState().lang,
|
|
@@ -78,21 +78,21 @@ class lt extends g {
|
|
|
78
78
|
this.widget = t, this.addWidgetToTheStore(t), this.templateDataUpdater(), this.context.store.dispatch({
|
|
79
79
|
type: "SET_WIDGET_INITIAL_DATA",
|
|
80
80
|
payload: { data: t.defaultValue, path: t.path }
|
|
81
|
-
}), this.context.store.state$.pipe(p(this.destroy$), N(t.path)).subscribe((
|
|
81
|
+
}), this.context.store.state$.pipe(p(this.destroy$), N(t.path)).subscribe((i) => this.setTemplateData({ value: i }));
|
|
82
82
|
const o = this.context.store.state$.pipe(
|
|
83
83
|
p(this.destroy$),
|
|
84
84
|
R(t.path)
|
|
85
85
|
), r = this.context.store.state$.pipe(
|
|
86
86
|
p(this.destroy$),
|
|
87
|
-
|
|
87
|
+
L(t.path)
|
|
88
88
|
);
|
|
89
|
-
|
|
90
|
-
([
|
|
89
|
+
j([o, r]).subscribe(
|
|
90
|
+
([i, s]) => {
|
|
91
91
|
this.setTemplateData({
|
|
92
|
-
errors: [...
|
|
92
|
+
errors: [...i ?? [], ...s ?? []]
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
|
-
), this.context.store.state$.pipe(p(this.destroy$),
|
|
95
|
+
), this.context.store.state$.pipe(p(this.destroy$), P(t.path)).subscribe((i) => this.setTemplateData({ touched: i })), this.context.emitEvent("load", this.widget);
|
|
96
96
|
}
|
|
97
97
|
valueChanged(t) {
|
|
98
98
|
this.context.store.dispatch({
|
|
@@ -130,7 +130,7 @@ class mt extends g {
|
|
|
130
130
|
init(t) {
|
|
131
131
|
this.widget = t, this.setTemplateData({
|
|
132
132
|
...this.widget.props
|
|
133
|
-
}), this.context.store.state$.pipe(
|
|
133
|
+
}), this.context.store.state$.pipe(F(this.widget.uid)).pipe(p(this.destroy$)).subscribe((o) => {
|
|
134
134
|
this.setTemplateData({
|
|
135
135
|
children: o
|
|
136
136
|
});
|
|
@@ -141,13 +141,13 @@ class mt extends g {
|
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
const x = h("guiRepeaterIndexesContext");
|
|
144
|
-
var G = Object.defineProperty, l = (
|
|
145
|
-
for (var
|
|
146
|
-
(a = s
|
|
147
|
-
return
|
|
144
|
+
var G = Object.defineProperty, l = (e, t, o, r) => {
|
|
145
|
+
for (var i = void 0, s = e.length - 1, a; s >= 0; s--)
|
|
146
|
+
(a = e[s]) && (i = a(t, o, i) || i);
|
|
147
|
+
return i && G(t, o, i), i;
|
|
148
148
|
};
|
|
149
|
-
const k = (
|
|
150
|
-
class t extends
|
|
149
|
+
const k = (e) => {
|
|
150
|
+
class t extends e {
|
|
151
151
|
constructor() {
|
|
152
152
|
super(...arguments), this.repeaterIndexes = [];
|
|
153
153
|
}
|
|
@@ -157,18 +157,18 @@ const k = (s) => {
|
|
|
157
157
|
async loadWidgetComponent() {
|
|
158
158
|
if (this.widget)
|
|
159
159
|
try {
|
|
160
|
-
const r = await this.formContext.widgetRegistry.loadWidget(this.widget.type),
|
|
160
|
+
const r = await this.formContext.widgetRegistry.loadWidget(this.widget.type), i = new r(), s = this.repeaterIndexes ?? [];
|
|
161
161
|
let a;
|
|
162
|
-
this.repeaterIndex !== void 0 ? a = [...
|
|
162
|
+
this.repeaterIndex !== void 0 ? a = [...s, this.repeaterIndex] : a = s, i.widget = a.length > 0 ? C(D(this.widget), a) : this.widget, i.id = `host-${this.widget.uid}`, this.replaceWith(i);
|
|
163
163
|
} catch (r) {
|
|
164
164
|
console.error(`Widget "${this.widget.type}" could not be loaded`, r);
|
|
165
|
-
const
|
|
165
|
+
const i = $.widgetCouldNotBeLoaded;
|
|
166
166
|
this.dispatchEvent(
|
|
167
167
|
new CustomEvent("formHealth", {
|
|
168
168
|
detail: {
|
|
169
169
|
status: "errored",
|
|
170
|
-
message: `[${
|
|
171
|
-
code:
|
|
170
|
+
message: `[${i}] Widget "${this.widget.type}" could not be loaded`,
|
|
171
|
+
code: i
|
|
172
172
|
},
|
|
173
173
|
bubbles: !0,
|
|
174
174
|
composed: !0
|
|
@@ -181,129 +181,152 @@ const k = (s) => {
|
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
return l([
|
|
184
|
-
m({ context:
|
|
185
|
-
|
|
184
|
+
m({ context: v }),
|
|
185
|
+
d({ attribute: !1 })
|
|
186
186
|
], t.prototype, "formContext"), l([
|
|
187
|
-
|
|
187
|
+
d({ type: Object })
|
|
188
188
|
], t.prototype, "widget"), l([
|
|
189
|
-
|
|
189
|
+
d({ type: Number })
|
|
190
190
|
], t.prototype, "repeaterIndex"), l([
|
|
191
191
|
m({ context: x, subscribe: !0 }),
|
|
192
|
-
|
|
192
|
+
d({ attribute: !1 })
|
|
193
193
|
], t.prototype, "repeaterIndexes"), t;
|
|
194
194
|
};
|
|
195
|
-
var q = Object.getOwnPropertyDescriptor, J = (
|
|
196
|
-
for (var
|
|
197
|
-
(a = s
|
|
198
|
-
return
|
|
195
|
+
var q = Object.getOwnPropertyDescriptor, J = (e, t, o, r) => {
|
|
196
|
+
for (var i = r > 1 ? void 0 : r ? q(t, o) : t, s = e.length - 1, a; s >= 0; s--)
|
|
197
|
+
(a = e[s]) && (i = a(i) || i);
|
|
198
|
+
return i;
|
|
199
199
|
};
|
|
200
|
-
let
|
|
200
|
+
let T = class extends k(f) {
|
|
201
201
|
};
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
],
|
|
205
|
-
var Z = Object.defineProperty, Q = Object.getOwnPropertyDescriptor, c = (
|
|
206
|
-
for (var
|
|
207
|
-
(a = s
|
|
208
|
-
return r &&
|
|
202
|
+
T = J([
|
|
203
|
+
y("gui-widget")
|
|
204
|
+
], T);
|
|
205
|
+
var Z = Object.defineProperty, Q = Object.getOwnPropertyDescriptor, c = (e, t, o, r) => {
|
|
206
|
+
for (var i = r > 1 ? void 0 : r ? Q(t, o) : t, s = e.length - 1, a; s >= 0; s--)
|
|
207
|
+
(a = e[s]) && (i = (r ? a(t, o, i) : a(i)) || i);
|
|
208
|
+
return r && i && Z(t, o, i), i;
|
|
209
209
|
};
|
|
210
|
-
let
|
|
210
|
+
let n = class extends f {
|
|
211
211
|
constructor() {
|
|
212
|
-
super(...arguments), this.context = new z(), this.autocomplete = void 0, this.direction = "ltr", this.unsubscribeI18n = () => {
|
|
213
|
-
}, this._defaultFormName =
|
|
212
|
+
super(...arguments), this.context = new z(), this.autocomplete = void 0, this.direction = "ltr", this.eventSub = [], this.unsubscribeI18n = () => {
|
|
213
|
+
}, this._defaultFormName = M();
|
|
214
214
|
}
|
|
215
215
|
connectedCallback() {
|
|
216
|
-
super.connectedCallback(), this.classList.add("gui-form"), this.
|
|
217
|
-
|
|
218
|
-
|
|
216
|
+
super.connectedCallback(), this.classList.add("gui-form"), this.configureLongLivedEvents();
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Stable events subscriptions.
|
|
220
|
+
* ( Stable events are those that survive store replacements )
|
|
221
|
+
*/
|
|
222
|
+
configureLongLivedEvents() {
|
|
223
|
+
this.eventSub.push(
|
|
224
|
+
this.context.events$.subscribe(
|
|
225
|
+
(e) => this.dispatchEvent(
|
|
226
|
+
new CustomEvent(n.FORM_EVENT, { detail: e, bubbles: !0 })
|
|
227
|
+
)
|
|
228
|
+
)
|
|
229
|
+
), this.eventSub.push(
|
|
230
|
+
this.context.submit$.subscribe(
|
|
231
|
+
(e) => this.dispatchEvent(
|
|
232
|
+
new CustomEvent(n.FORM_SUBMIT_EVENT, {
|
|
233
|
+
detail: e,
|
|
234
|
+
bubbles: !0
|
|
235
|
+
})
|
|
236
|
+
)
|
|
219
237
|
)
|
|
220
238
|
);
|
|
221
239
|
}
|
|
222
|
-
updated(
|
|
223
|
-
super.updated(
|
|
240
|
+
updated(e) {
|
|
241
|
+
super.updated(e), e.has("config") && this.config && this._reinitialize(this.config);
|
|
224
242
|
}
|
|
225
|
-
_reinitialize(
|
|
243
|
+
_reinitialize(e) {
|
|
226
244
|
this.unsubscribeI18n(), this.stateSub?.unsubscribe(), this.healthSub?.unsubscribe(), this.context.initialize(
|
|
227
|
-
|
|
228
|
-
|
|
245
|
+
e.widgetLoaders,
|
|
246
|
+
e.middlewares ?? [],
|
|
229
247
|
this.validators,
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
), this.direction =
|
|
248
|
+
e.validateOn ?? "eager",
|
|
249
|
+
e.itemRenderers ?? {},
|
|
250
|
+
e.localization,
|
|
251
|
+
e.dependencies ?? {}
|
|
252
|
+
), this.direction = w(this.context.localization.lang), this.stateSub = this.context.store.state$.subscribe((t) => {
|
|
235
253
|
this.formState = t, this.requestUpdate();
|
|
236
254
|
}), this.healthSub = U(this.context.store.state$).subscribe((t) => {
|
|
237
255
|
this.dispatchEvent(
|
|
238
|
-
new CustomEvent(
|
|
256
|
+
new CustomEvent(n.FORM_HEALTH_EVENT, {
|
|
239
257
|
detail: t,
|
|
240
258
|
bubbles: !0
|
|
241
259
|
})
|
|
242
260
|
);
|
|
243
261
|
}), this.context.store.dispatch({
|
|
244
262
|
type: "INITIALIZE",
|
|
245
|
-
payload: { formName:
|
|
246
|
-
}), this.context.store.dispatch({ type: "SET_DATA", payload: { data:
|
|
247
|
-
this.direction =
|
|
263
|
+
payload: { formName: e.formName ?? this._defaultFormName, formDef: e.formDef }
|
|
264
|
+
}), this.context.store.dispatch({ type: "SET_DATA", payload: { data: e.data ?? {} } }), this.context.store.dispatch({ type: "SET_META", payload: { meta: e.meta ?? {} } }), this.unsubscribeI18n = this.context.localization.subscribe((t) => {
|
|
265
|
+
this.direction = w(t), this.context.store.dispatch({ type: "SET_LANGUAGE", payload: { lang: t } });
|
|
248
266
|
});
|
|
249
267
|
}
|
|
250
268
|
createRenderRoot() {
|
|
251
269
|
return this;
|
|
252
270
|
}
|
|
253
271
|
render() {
|
|
254
|
-
const
|
|
272
|
+
const e = this.formState?.formDef && this.context.widgetRegistry.ready, t = this.config?.formName ?? this._defaultFormName;
|
|
255
273
|
return b`
|
|
256
274
|
<form
|
|
257
275
|
id=${t}
|
|
258
276
|
novalidate
|
|
259
277
|
dir=${this.direction}
|
|
260
278
|
autocomplete=${this.autocomplete || V}
|
|
279
|
+
@submit=${this.onFormSubmit}
|
|
261
280
|
>
|
|
262
281
|
${H(
|
|
263
|
-
|
|
282
|
+
e,
|
|
264
283
|
() => b` <gui-widget .widget=${this.formState?.formDef.form}></gui-widget>`,
|
|
265
284
|
() => b` <div>Loading form...</div>`
|
|
266
285
|
)}
|
|
267
286
|
</form>
|
|
268
287
|
`;
|
|
269
288
|
}
|
|
270
|
-
|
|
271
|
-
this.context.
|
|
289
|
+
onFormSubmit(e) {
|
|
290
|
+
e.preventDefault(), this.context.emitSubmitEvent();
|
|
291
|
+
}
|
|
292
|
+
setData(e) {
|
|
293
|
+
this.context.store.dispatch({ type: "SET_DATA", payload: { data: e } });
|
|
272
294
|
}
|
|
273
|
-
setMeta(
|
|
274
|
-
this.context.store.dispatch({ type: "SET_META", payload: { meta:
|
|
295
|
+
setMeta(e) {
|
|
296
|
+
this.context.store.dispatch({ type: "SET_META", payload: { meta: e } });
|
|
275
297
|
}
|
|
276
298
|
disconnectedCallback() {
|
|
277
|
-
super.disconnectedCallback(), this.stateSub?.unsubscribe(), this.healthSub?.unsubscribe(), this.eventSub
|
|
299
|
+
super.disconnectedCallback(), this.stateSub?.unsubscribe(), this.healthSub?.unsubscribe(), this.eventSub.map((e) => e.unsubscribe()), this.unsubscribeI18n();
|
|
278
300
|
}
|
|
279
301
|
};
|
|
280
|
-
|
|
281
|
-
|
|
302
|
+
n.FORM_SUBMIT_EVENT = "formSubmit";
|
|
303
|
+
n.FORM_HEALTH_EVENT = "formHealth";
|
|
304
|
+
n.FORM_EVENT = "formEvent";
|
|
282
305
|
c([
|
|
283
|
-
I({ context:
|
|
284
|
-
],
|
|
306
|
+
I({ context: v })
|
|
307
|
+
], n.prototype, "context", 2);
|
|
285
308
|
c([
|
|
286
|
-
|
|
287
|
-
],
|
|
309
|
+
d({ attribute: !1 })
|
|
310
|
+
], n.prototype, "config", 2);
|
|
288
311
|
c([
|
|
289
|
-
|
|
290
|
-
],
|
|
312
|
+
d({ attribute: !1 })
|
|
313
|
+
], n.prototype, "validators", 2);
|
|
291
314
|
c([
|
|
292
|
-
|
|
293
|
-
],
|
|
315
|
+
d({ type: String })
|
|
316
|
+
], n.prototype, "autocomplete", 2);
|
|
294
317
|
c([
|
|
295
318
|
B()
|
|
296
|
-
],
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
],
|
|
300
|
-
var X = Object.defineProperty, u = (
|
|
301
|
-
for (var
|
|
302
|
-
(a = s
|
|
303
|
-
return
|
|
319
|
+
], n.prototype, "direction", 2);
|
|
320
|
+
n = c([
|
|
321
|
+
y("gui-core-form")
|
|
322
|
+
], n);
|
|
323
|
+
var X = Object.defineProperty, u = (e, t, o, r) => {
|
|
324
|
+
for (var i = void 0, s = e.length - 1, a; s >= 0; s--)
|
|
325
|
+
(a = e[s]) && (i = a(t, o, i) || i);
|
|
326
|
+
return i && X(t, o, i), i;
|
|
304
327
|
};
|
|
305
|
-
const Y = (
|
|
306
|
-
class t extends
|
|
328
|
+
const Y = (e) => {
|
|
329
|
+
class t extends e {
|
|
307
330
|
constructor() {
|
|
308
331
|
super(...arguments), this.repeaterIndex = -1, this.parentRepeaterIndexes = [];
|
|
309
332
|
}
|
|
@@ -313,23 +336,23 @@ const Y = (s) => {
|
|
|
313
336
|
async loadWidgetComponent(r) {
|
|
314
337
|
if (this.widget)
|
|
315
338
|
try {
|
|
316
|
-
const
|
|
317
|
-
new
|
|
339
|
+
const i = await this.formContext.widgetRegistry.loadWidget(this.widget.type), s = new i(), a = [...this.parentRepeaterIndexes ?? [], r];
|
|
340
|
+
new S(s, {
|
|
318
341
|
context: x,
|
|
319
342
|
initialValue: a
|
|
320
|
-
}),
|
|
321
|
-
|
|
343
|
+
}), s.widget = C(
|
|
344
|
+
D(this.widget),
|
|
322
345
|
a
|
|
323
|
-
),
|
|
324
|
-
} catch (
|
|
325
|
-
console.error(`Widget "${this.widget.type}" could not be loaded`,
|
|
326
|
-
const
|
|
346
|
+
), s.id = `host-${this.widget.uid}`, this.replaceWith(s);
|
|
347
|
+
} catch (i) {
|
|
348
|
+
console.error(`Widget "${this.widget.type}" could not be loaded`, i);
|
|
349
|
+
const s = $.widgetCouldNotBeLoaded;
|
|
327
350
|
this.dispatchEvent(
|
|
328
351
|
new CustomEvent("formHealth", {
|
|
329
352
|
detail: {
|
|
330
353
|
status: "errored",
|
|
331
|
-
message: `[${
|
|
332
|
-
code:
|
|
354
|
+
message: `[${s}] Widget "${this.widget.type}" could not be loaded`,
|
|
355
|
+
code: s
|
|
333
356
|
},
|
|
334
357
|
bubbles: !0,
|
|
335
358
|
composed: !0
|
|
@@ -342,40 +365,40 @@ const Y = (s) => {
|
|
|
342
365
|
}
|
|
343
366
|
}
|
|
344
367
|
return u([
|
|
345
|
-
m({ context:
|
|
346
|
-
|
|
368
|
+
m({ context: v }),
|
|
369
|
+
d({ attribute: !1 })
|
|
347
370
|
], t.prototype, "formContext"), u([
|
|
348
|
-
|
|
371
|
+
d({ type: Object })
|
|
349
372
|
], t.prototype, "widget"), u([
|
|
350
|
-
|
|
373
|
+
d({ type: Number })
|
|
351
374
|
], t.prototype, "repeaterIndex"), u([
|
|
352
375
|
m({ context: x, subscribe: !0 }),
|
|
353
|
-
|
|
376
|
+
d({ attribute: !1 })
|
|
354
377
|
], t.prototype, "parentRepeaterIndexes"), t;
|
|
355
378
|
};
|
|
356
|
-
var K = Object.getOwnPropertyDescriptor, tt = (
|
|
357
|
-
for (var
|
|
358
|
-
(a = s
|
|
359
|
-
return
|
|
379
|
+
var K = Object.getOwnPropertyDescriptor, tt = (e, t, o, r) => {
|
|
380
|
+
for (var i = r > 1 ? void 0 : r ? K(t, o) : t, s = e.length - 1, a; s >= 0; s--)
|
|
381
|
+
(a = e[s]) && (i = a(i) || i);
|
|
382
|
+
return i;
|
|
360
383
|
};
|
|
361
|
-
let
|
|
384
|
+
let _ = class extends Y(f) {
|
|
362
385
|
};
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
],
|
|
386
|
+
_ = tt([
|
|
387
|
+
y("gui-repeater-widget")
|
|
388
|
+
], _);
|
|
366
389
|
export {
|
|
367
390
|
dt as ActionWidgetAdapter,
|
|
368
391
|
g as BaseWidgetAdapter,
|
|
369
392
|
ht as DisplayWidgetAdapter,
|
|
370
|
-
|
|
393
|
+
n as FormElement,
|
|
371
394
|
lt as InputWidgetAdapter,
|
|
372
395
|
mt as LayoutWidgetAdapter,
|
|
373
396
|
z as LitFormContext,
|
|
374
|
-
|
|
375
|
-
|
|
397
|
+
_ as RepeaterWidgetElement,
|
|
398
|
+
T as WidgetElement,
|
|
376
399
|
nt as actionContext,
|
|
377
400
|
pt as displayWidgetContext,
|
|
378
|
-
|
|
401
|
+
v as formContext,
|
|
379
402
|
ct as inputContext,
|
|
380
403
|
ut as layoutContext,
|
|
381
404
|
x as repeaterIndexesContext
|
package/index.umd.cjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
(function(i,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("@lit/context"),require("@golemui/core"),require("rxjs"),require("lit"),require("lit/decorators.js"),require("lit/directives/when.js")):typeof define=="function"&&define.amd?define(["exports","@lit/context","@golemui/core","rxjs","lit","lit/decorators.js","lit/directives/when.js"],p):(i=typeof globalThis<"u"?globalThis:i||self,p(i.lit={},i.context,i.core,i.rxjs,i.lit,i.decorators_js,i.when_js))})(this,(function(i,p,d,l,
|
|
1
|
+
(function(i,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("@lit/context"),require("@golemui/core"),require("rxjs"),require("lit"),require("lit/decorators.js"),require("lit/directives/when.js")):typeof define=="function"&&define.amd?define(["exports","@lit/context","@golemui/core","rxjs","lit","lit/decorators.js","lit/directives/when.js"],p):(i=typeof globalThis<"u"?globalThis:i||self,p(i.lit={},i.context,i.core,i.rxjs,i.lit,i.decorators_js,i.when_js))})(this,(function(i,p,d,l,u,h,v){"use strict";const g=p.createContext("guiFormContext");class E extends d.FormContext{}class m{constructor(){this.templateData={},this.destroy$=new l.Subject,this.templateDataChanged$=new l.Subject}setTemplateData(t){this.templateData={...this.templateData,...t},this.templateDataChanged$.next()}addWidgetToTheStore(t){this.context.store.dispatch({type:"ADD_WIDGET",payload:{widget:t}})}templateDataUpdater(){this.context.store.state$.pipe(l.takeUntil(this.destroy$),d.calculatedWidgetsByUid$(this.widget.uid)).subscribe(t=>{const s={...t,lang:this.context.store.getState().lang,deps:this.context.dependencies};d.assertNoPropCollisions(t.uid,t.props,s),this.setTemplateData({...s,...t.props})})}destroy(){this.context.store.dispatch({type:"REMOVE_WIDGET",payload:{uid:this.widget.uid}}),this.destroy$.next()}}const w=p.createContext("guiActionWidgetAdapter");class x extends m{constructor(){super(...arguments),this.templateData={}}init(t){this.widget=t,this.setTemplateData({label:this.widget.label,icon:this.widget.props?.icon,iconPosition:this.widget.props?.iconPosition}),this.addWidgetToTheStore(t),this.templateDataUpdater(),this.context.emitEvent("load",this.widget)}click(){this.context.emitEvent("click",this.widget)}}const C=p.createContext("guiDisplayWidgetAdapter");class T extends m{constructor(){super(...arguments),this.templateData={}}init(t){this.widget=t,this.setTemplateData({...this.widget.props}),this.addWidgetToTheStore(t),this.templateDataUpdater()}}const D=p.createContext("guiInputWidgetAdapter");class $ extends m{constructor(){super(...arguments),this.templateData={}}init(t){this.widget=t,this.addWidgetToTheStore(t),this.templateDataUpdater(),this.context.store.dispatch({type:"SET_WIDGET_INITIAL_DATA",payload:{data:t.defaultValue,path:t.path}}),this.context.store.state$.pipe(l.takeUntil(this.destroy$),d.dataByPath$(t.path)).subscribe(e=>this.setTemplateData({value:e}));const s=this.context.store.state$.pipe(l.takeUntil(this.destroy$),d.validationByPath$(t.path)),r=this.context.store.state$.pipe(l.takeUntil(this.destroy$),d.injectedValidationByPath$(t.path));l.combineLatest([s,r]).subscribe(([e,n])=>{this.setTemplateData({errors:[...e??[],...n??[]]})}),this.context.store.state$.pipe(l.takeUntil(this.destroy$),d.touchedControlsByPath$(t.path)).subscribe(e=>this.setTemplateData({touched:e})),this.context.emitEvent("load",this.widget)}valueChanged(t){this.context.store.dispatch({type:"SET_WIDGET_DATA",payload:{path:this.widget.path,data:t}}),this.context.emitEvent("change",this.widget)}filterChanged(t){this.context.emitEvent("filter",this.widget,t)}injectValidationIssues(t){this.context.store.dispatch({type:"INJECT_VALIDATION_ISSUES",payload:{path:this.widget.path,issues:t}})}getItemRenderer(t,s){return t?this.context.itemRenderers[t]:s}onBlur(){this.context.store.dispatch({type:"ATTEMPT_VALIDATION",payload:{reason:"blur",path:this.widget.path,uid:this.widget.uid}}),this.context.emitEvent("blur",this.widget)}}const I=p.createContext("guiLayoutWidgetAdapter");class W extends m{constructor(){super(...arguments),this.templateData={}}init(t){this.widget=t,this.setTemplateData({...this.widget.props}),this.context.store.state$.pipe(d.calculatedLayoutChildrenByUid$(this.widget.uid)).pipe(l.takeUntil(this.destroy$)).subscribe(s=>{this.setTemplateData({children:s})}),this.addWidgetToTheStore(t),this.templateDataUpdater()}change(t){this.context.emitEvent("change",this.widget,t)}}const b=p.createContext("guiRepeaterIndexesContext");var S=Object.defineProperty,y=(a,t,s,r)=>{for(var e=void 0,n=a.length-1,o;n>=0;n--)(o=a[n])&&(e=o(t,s,e)||e);return e&&S(t,s,e),e};const _=a=>{class t extends a{constructor(){super(...arguments),this.repeaterIndexes=[]}connectedCallback(){super.connectedCallback?.(),this.loadWidgetComponent()}async loadWidgetComponent(){if(this.widget)try{const r=await this.formContext.widgetRegistry.loadWidget(this.widget.type),e=new r,n=this.repeaterIndexes??[];let o;this.repeaterIndex!==void 0?o=[...n,this.repeaterIndex]:o=n,e.widget=o.length>0?d.makeRepeaterItemConfig(d.cloneObject(this.widget),o):this.widget,e.id=`host-${this.widget.uid}`,this.replaceWith(e)}catch(r){console.error(`Widget "${this.widget.type}" could not be loaded`,r);const e=d.errorCodes.widgetCouldNotBeLoaded;this.dispatchEvent(new CustomEvent("formHealth",{detail:{status:"errored",message:`[${e}] Widget "${this.widget.type}" could not be loaded`,code:e},bubbles:!0,composed:!0}))}}render(){return null}}return y([p.consume({context:g}),h.property({attribute:!1})],t.prototype,"formContext"),y([h.property({type:Object})],t.prototype,"widget"),y([h.property({type:Number})],t.prototype,"repeaterIndex"),y([p.consume({context:b,subscribe:!0}),h.property({attribute:!1})],t.prototype,"repeaterIndexes"),t};var A=Object.getOwnPropertyDescriptor,F=(a,t,s,r)=>{for(var e=r>1?void 0:r?A(t,s):t,n=a.length-1,o;n>=0;n--)(o=a[n])&&(e=o(e)||e);return e};i.WidgetElement=class extends _(u.LitElement){},i.WidgetElement=F([h.customElement("gui-widget")],i.WidgetElement);var L=Object.defineProperty,R=Object.getOwnPropertyDescriptor,c=(a,t,s,r)=>{for(var e=r>1?void 0:r?R(t,s):t,n=a.length-1,o;n>=0;n--)(o=a[n])&&(e=(r?o(t,s,e):o(e))||e);return r&&e&&L(t,s,e),e};i.FormElement=class extends u.LitElement{constructor(){super(...arguments),this.context=new E,this.autocomplete=void 0,this.direction="ltr",this.eventSub=[],this.unsubscribeI18n=()=>{},this._defaultFormName=d.shortUUID()}connectedCallback(){super.connectedCallback(),this.classList.add("gui-form"),this.configureLongLivedEvents()}configureLongLivedEvents(){this.eventSub.push(this.context.events$.subscribe(t=>this.dispatchEvent(new CustomEvent(i.FormElement.FORM_EVENT,{detail:t,bubbles:!0})))),this.eventSub.push(this.context.submit$.subscribe(t=>this.dispatchEvent(new CustomEvent(i.FormElement.FORM_SUBMIT_EVENT,{detail:t,bubbles:!0}))))}updated(t){super.updated(t),t.has("config")&&this.config&&this._reinitialize(this.config)}_reinitialize(t){this.unsubscribeI18n(),this.stateSub?.unsubscribe(),this.healthSub?.unsubscribe(),this.context.initialize(t.widgetLoaders,t.middlewares??[],this.validators,t.validateOn??"eager",t.itemRenderers??{},t.localization,t.dependencies??{}),this.direction=d.getDirectionFromLanguage(this.context.localization.lang),this.stateSub=this.context.store.state$.subscribe(s=>{this.formState=s,this.requestUpdate()}),this.healthSub=d.formHealth(this.context.store.state$).subscribe(s=>{this.dispatchEvent(new CustomEvent(i.FormElement.FORM_HEALTH_EVENT,{detail:s,bubbles:!0}))}),this.context.store.dispatch({type:"INITIALIZE",payload:{formName:t.formName??this._defaultFormName,formDef:t.formDef}}),this.context.store.dispatch({type:"SET_DATA",payload:{data:t.data??{}}}),this.context.store.dispatch({type:"SET_META",payload:{meta:t.meta??{}}}),this.unsubscribeI18n=this.context.localization.subscribe(s=>{this.direction=d.getDirectionFromLanguage(s),this.context.store.dispatch({type:"SET_LANGUAGE",payload:{lang:s}})})}createRenderRoot(){return this}render(){const t=this.formState?.formDef&&this.context.widgetRegistry.ready,s=this.config?.formName??this._defaultFormName;return u.html`
|
|
2
2
|
<form
|
|
3
3
|
id=${s}
|
|
4
4
|
novalidate
|
|
5
5
|
dir=${this.direction}
|
|
6
|
-
autocomplete=${this.autocomplete||
|
|
6
|
+
autocomplete=${this.autocomplete||u.nothing}
|
|
7
|
+
@submit=${this.onFormSubmit}
|
|
7
8
|
>
|
|
8
|
-
${
|
|
9
|
+
${v.when(t,()=>u.html` <gui-widget .widget=${this.formState?.formDef.form}></gui-widget>`,()=>u.html` <div>Loading form...</div>`)}
|
|
9
10
|
</form>
|
|
10
|
-
`}setData(t){this.context.store.dispatch({type:"SET_DATA",payload:{data:t}})}setMeta(t){this.context.store.dispatch({type:"SET_META",payload:{meta:t}})}disconnectedCallback(){super.disconnectedCallback(),this.stateSub?.unsubscribe(),this.healthSub?.unsubscribe(),this.eventSub
|
|
11
|
+
`}onFormSubmit(t){t.preventDefault(),this.context.emitSubmitEvent()}setData(t){this.context.store.dispatch({type:"SET_DATA",payload:{data:t}})}setMeta(t){this.context.store.dispatch({type:"SET_META",payload:{meta:t}})}disconnectedCallback(){super.disconnectedCallback(),this.stateSub?.unsubscribe(),this.healthSub?.unsubscribe(),this.eventSub.map(t=>t.unsubscribe()),this.unsubscribeI18n()}},i.FormElement.FORM_SUBMIT_EVENT="formSubmit",i.FormElement.FORM_HEALTH_EVENT="formHealth",i.FormElement.FORM_EVENT="formEvent",c([p.provide({context:g})],i.FormElement.prototype,"context",2),c([h.property({attribute:!1})],i.FormElement.prototype,"config",2),c([h.property({attribute:!1})],i.FormElement.prototype,"validators",2),c([h.property({type:String})],i.FormElement.prototype,"autocomplete",2),c([h.state()],i.FormElement.prototype,"direction",2),i.FormElement=c([h.customElement("gui-core-form")],i.FormElement);var O=Object.defineProperty,f=(a,t,s,r)=>{for(var e=void 0,n=a.length-1,o;n>=0;n--)(o=a[n])&&(e=o(t,s,e)||e);return e&&O(t,s,e),e};const N=a=>{class t extends a{constructor(){super(...arguments),this.repeaterIndex=-1,this.parentRepeaterIndexes=[]}connectedCallback(){super.connectedCallback(),this.loadWidgetComponent(this.repeaterIndex)}async loadWidgetComponent(r){if(this.widget)try{const e=await this.formContext.widgetRegistry.loadWidget(this.widget.type),n=new e,o=[...this.parentRepeaterIndexes??[],r];new p.ContextProvider(n,{context:b,initialValue:o}),n.widget=d.makeRepeaterItemConfig(d.cloneObject(this.widget),o),n.id=`host-${this.widget.uid}`,this.replaceWith(n)}catch(e){console.error(`Widget "${this.widget.type}" could not be loaded`,e);const n=d.errorCodes.widgetCouldNotBeLoaded;this.dispatchEvent(new CustomEvent("formHealth",{detail:{status:"errored",message:`[${n}] Widget "${this.widget.type}" could not be loaded`,code:n},bubbles:!0,composed:!0}))}}render(){return null}}return f([p.consume({context:g}),h.property({attribute:!1})],t.prototype,"formContext"),f([h.property({type:Object})],t.prototype,"widget"),f([h.property({type:Number})],t.prototype,"repeaterIndex"),f([p.consume({context:b,subscribe:!0}),h.property({attribute:!1})],t.prototype,"parentRepeaterIndexes"),t};var P=Object.getOwnPropertyDescriptor,U=(a,t,s,r)=>{for(var e=r>1?void 0:r?P(t,s):t,n=a.length-1,o;n>=0;n--)(o=a[n])&&(e=o(e)||e);return e};i.RepeaterWidgetElement=class extends N(u.LitElement){},i.RepeaterWidgetElement=U([h.customElement("gui-repeater-widget")],i.RepeaterWidgetElement),i.ActionWidgetAdapter=x,i.BaseWidgetAdapter=m,i.DisplayWidgetAdapter=T,i.InputWidgetAdapter=$,i.LayoutWidgetAdapter=W,i.LitFormContext=E,i.actionContext=w,i.displayWidgetContext=C,i.formContext=g,i.inputContext=D,i.layoutContext=I,i.repeaterIndexesContext=b,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}));
|
|
@@ -14,13 +14,20 @@ export declare class FormElement extends LitElement {
|
|
|
14
14
|
private eventSub;
|
|
15
15
|
private unsubscribeI18n;
|
|
16
16
|
private readonly _defaultFormName;
|
|
17
|
+
static FORM_SUBMIT_EVENT: string;
|
|
17
18
|
static FORM_HEALTH_EVENT: string;
|
|
18
19
|
static FORM_EVENT: string;
|
|
19
20
|
connectedCallback(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Stable events subscriptions.
|
|
23
|
+
* ( Stable events are those that survive store replacements )
|
|
24
|
+
*/
|
|
25
|
+
private configureLongLivedEvents;
|
|
20
26
|
updated(changed: Map<string, unknown>): void;
|
|
21
27
|
private _reinitialize;
|
|
22
28
|
createRenderRoot(): this;
|
|
23
29
|
render(): import('lit-html').TemplateResult<1>;
|
|
30
|
+
private onFormSubmit;
|
|
24
31
|
setData(data: Record<string, any>): void;
|
|
25
32
|
setMeta(meta: Record<string, any>): void;
|
|
26
33
|
disconnectedCallback(): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@golemui/lit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.umd.cjs",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"*.md"
|
|
21
21
|
],
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"@golemui/core": "0.
|
|
23
|
+
"@golemui/core": "0.15.0",
|
|
24
24
|
"@lit/context": "^1.1.6",
|
|
25
25
|
"lit": "^3.3.1",
|
|
26
26
|
"rxjs": "^7.8.0"
|