@golemui/lit 0.13.3 → 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 CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.14.0 (2026-05-21)
2
+
3
+ This was a version bump only for lit to align it with other projects, there were no code changes.
4
+
5
+ ## 0.13.3 (2026-05-19)
6
+
7
+ This was a version bump only for lit to align it with other projects, there were no code changes.
8
+
1
9
  ## 0.13.2 (2026-05-19)
2
10
 
3
11
  This was a version bump only for lit to align it with other projects, there were no code changes.
package/index.js CHANGED
@@ -1,11 +1,11 @@
1
- import { createContext as h, consume as m, provide as I, ContextProvider as W } from "@lit/context";
2
- import { FormContext as A, calculatedWidgetsByUid$ as S, assertNoPropCollisions as O, dataByPath$ as N, validationByPath$ as R, injectedValidationByPath$ as P, touchedControlsByPath$ as L, calculatedLayoutChildrenByUid$ as j, makeRepeaterItemConfig as T, cloneObject as _, errorCodes as $, shortUUID as F, getDirectionFromLanguage as v, formHealth as U } from "@golemui/core";
3
- import { Subject as E, takeUntil as p, combineLatest as M } from "rxjs";
4
- import { LitElement as y, nothing as V, html as b } from "lit";
5
- import { property as n, customElement as f, state as B } from "lit/decorators.js";
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 w = h("guiFormContext");
8
- class z extends A {
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$), S(this.widget.uid)).subscribe((t) => {
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((e) => this.setTemplateData({ value: e }));
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
- P(t.path)
87
+ L(t.path)
88
88
  );
89
- M([o, r]).subscribe(
90
- ([e, i]) => {
89
+ j([o, r]).subscribe(
90
+ ([i, s]) => {
91
91
  this.setTemplateData({
92
- errors: [...e ?? [], ...i ?? []]
92
+ errors: [...i ?? [], ...s ?? []]
93
93
  });
94
94
  }
95
- ), this.context.store.state$.pipe(p(this.destroy$), L(t.path)).subscribe((e) => this.setTemplateData({ touched: e })), this.context.emitEvent("load", this.widget);
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(j(this.widget.uid)).pipe(p(this.destroy$)).subscribe((o) => {
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 = (s, t, o, r) => {
145
- for (var e = void 0, i = s.length - 1, a; i >= 0; i--)
146
- (a = s[i]) && (e = a(t, o, e) || e);
147
- return e && G(t, o, e), e;
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 = (s) => {
150
- class t extends s {
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), e = new r(), i = this.repeaterIndexes ?? [];
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 = [...i, this.repeaterIndex] : a = i, e.widget = a.length > 0 ? T(_(this.widget), a) : this.widget, e.id = `host-${this.widget.uid}`, this.replaceWith(e);
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 e = $.widgetCouldNotBeLoaded;
165
+ const i = $.widgetCouldNotBeLoaded;
166
166
  this.dispatchEvent(
167
167
  new CustomEvent("formHealth", {
168
168
  detail: {
169
169
  status: "errored",
170
- message: `[${e}] Widget "${this.widget.type}" could not be loaded`,
171
- code: e
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: w }),
185
- n({ attribute: !1 })
184
+ m({ context: v }),
185
+ d({ attribute: !1 })
186
186
  ], t.prototype, "formContext"), l([
187
- n({ type: Object })
187
+ d({ type: Object })
188
188
  ], t.prototype, "widget"), l([
189
- n({ type: Number })
189
+ d({ type: Number })
190
190
  ], t.prototype, "repeaterIndex"), l([
191
191
  m({ context: x, subscribe: !0 }),
192
- n({ attribute: !1 })
192
+ d({ attribute: !1 })
193
193
  ], t.prototype, "repeaterIndexes"), t;
194
194
  };
195
- var q = Object.getOwnPropertyDescriptor, J = (s, t, o, r) => {
196
- for (var e = r > 1 ? void 0 : r ? q(t, o) : t, i = s.length - 1, a; i >= 0; i--)
197
- (a = s[i]) && (e = a(e) || e);
198
- return e;
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 C = class extends k(y) {
200
+ let T = class extends k(f) {
201
201
  };
202
- C = J([
203
- f("gui-widget")
204
- ], C);
205
- var Z = Object.defineProperty, Q = Object.getOwnPropertyDescriptor, c = (s, t, o, r) => {
206
- for (var e = r > 1 ? void 0 : r ? Q(t, o) : t, i = s.length - 1, a; i >= 0; i--)
207
- (a = s[i]) && (e = (r ? a(t, o, e) : a(e)) || e);
208
- return r && e && Z(t, o, e), e;
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 d = class extends y {
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 = F();
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.eventSub = this.context.events$.subscribe(
217
- (s) => this.dispatchEvent(
218
- new CustomEvent(d.FORM_EVENT, { detail: s, bubbles: !0 })
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(s) {
223
- super.updated(s), s.has("config") && this.config && this._reinitialize(this.config);
240
+ updated(e) {
241
+ super.updated(e), e.has("config") && this.config && this._reinitialize(this.config);
224
242
  }
225
- _reinitialize(s) {
243
+ _reinitialize(e) {
226
244
  this.unsubscribeI18n(), this.stateSub?.unsubscribe(), this.healthSub?.unsubscribe(), this.context.initialize(
227
- s.widgetLoaders,
228
- s.middlewares ?? [],
245
+ e.widgetLoaders,
246
+ e.middlewares ?? [],
229
247
  this.validators,
230
- s.validateOn ?? "eager",
231
- s.itemRenderers ?? {},
232
- s.localization,
233
- s.dependencies ?? {}
234
- ), this.direction = v(this.context.localization.lang), this.stateSub = this.context.store.state$.subscribe((t) => {
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(d.FORM_HEALTH_EVENT, {
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: s.formName ?? this._defaultFormName, formDef: s.formDef }
246
- }), this.context.store.dispatch({ type: "SET_DATA", payload: { data: s.data ?? {} } }), this.context.store.dispatch({ type: "SET_META", payload: { meta: s.meta ?? {} } }), this.unsubscribeI18n = this.context.localization.subscribe((t) => {
247
- this.direction = v(t), this.context.store.dispatch({ type: "SET_LANGUAGE", payload: { lang: t } });
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 s = this.formState?.formDef && this.context.widgetRegistry.ready, t = this.config?.formName ?? this._defaultFormName;
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
- s,
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
- setData(s) {
271
- this.context.store.dispatch({ type: "SET_DATA", payload: { data: s } });
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(s) {
274
- this.context.store.dispatch({ type: "SET_META", payload: { meta: s } });
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?.unsubscribe(), this.unsubscribeI18n();
299
+ super.disconnectedCallback(), this.stateSub?.unsubscribe(), this.healthSub?.unsubscribe(), this.eventSub.map((e) => e.unsubscribe()), this.unsubscribeI18n();
278
300
  }
279
301
  };
280
- d.FORM_HEALTH_EVENT = "formHealth";
281
- d.FORM_EVENT = "formEvent";
302
+ n.FORM_SUBMIT_EVENT = "formSubmit";
303
+ n.FORM_HEALTH_EVENT = "formHealth";
304
+ n.FORM_EVENT = "formEvent";
282
305
  c([
283
- I({ context: w })
284
- ], d.prototype, "context", 2);
306
+ I({ context: v })
307
+ ], n.prototype, "context", 2);
285
308
  c([
286
- n({ attribute: !1 })
287
- ], d.prototype, "config", 2);
309
+ d({ attribute: !1 })
310
+ ], n.prototype, "config", 2);
288
311
  c([
289
- n({ attribute: !1 })
290
- ], d.prototype, "validators", 2);
312
+ d({ attribute: !1 })
313
+ ], n.prototype, "validators", 2);
291
314
  c([
292
- n({ type: String })
293
- ], d.prototype, "autocomplete", 2);
315
+ d({ type: String })
316
+ ], n.prototype, "autocomplete", 2);
294
317
  c([
295
318
  B()
296
- ], d.prototype, "direction", 2);
297
- d = c([
298
- f("gui-core-form")
299
- ], d);
300
- var X = Object.defineProperty, u = (s, t, o, r) => {
301
- for (var e = void 0, i = s.length - 1, a; i >= 0; i--)
302
- (a = s[i]) && (e = a(t, o, e) || e);
303
- return e && X(t, o, e), e;
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 = (s) => {
306
- class t extends s {
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 e = await this.formContext.widgetRegistry.loadWidget(this.widget.type), i = new e(), a = [...this.parentRepeaterIndexes ?? [], r];
317
- new W(i, {
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
- }), i.widget = T(
321
- _(this.widget),
343
+ }), s.widget = C(
344
+ D(this.widget),
322
345
  a
323
- ), i.id = `host-${this.widget.uid}`, this.replaceWith(i);
324
- } catch (e) {
325
- console.error(`Widget "${this.widget.type}" could not be loaded`, e);
326
- const i = $.widgetCouldNotBeLoaded;
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: `[${i}] Widget "${this.widget.type}" could not be loaded`,
332
- code: i
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: w }),
346
- n({ attribute: !1 })
368
+ m({ context: v }),
369
+ d({ attribute: !1 })
347
370
  ], t.prototype, "formContext"), u([
348
- n({ type: Object })
371
+ d({ type: Object })
349
372
  ], t.prototype, "widget"), u([
350
- n({ type: Number })
373
+ d({ type: Number })
351
374
  ], t.prototype, "repeaterIndex"), u([
352
375
  m({ context: x, subscribe: !0 }),
353
- n({ attribute: !1 })
376
+ d({ attribute: !1 })
354
377
  ], t.prototype, "parentRepeaterIndexes"), t;
355
378
  };
356
- var K = Object.getOwnPropertyDescriptor, tt = (s, t, o, r) => {
357
- for (var e = r > 1 ? void 0 : r ? K(t, o) : t, i = s.length - 1, a; i >= 0; i--)
358
- (a = s[i]) && (e = a(e) || e);
359
- return e;
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 D = class extends Y(y) {
384
+ let _ = class extends Y(f) {
362
385
  };
363
- D = tt([
364
- f("gui-repeater-widget")
365
- ], D);
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
- d as FormElement,
393
+ n as FormElement,
371
394
  lt as InputWidgetAdapter,
372
395
  mt as LayoutWidgetAdapter,
373
396
  z as LitFormContext,
374
- D as RepeaterWidgetElement,
375
- C as WidgetElement,
397
+ _ as RepeaterWidgetElement,
398
+ T as WidgetElement,
376
399
  nt as actionContext,
377
400
  pt as displayWidgetContext,
378
- w as formContext,
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,c,h,x){"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 C 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 v=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,a])=>{this.setTemplateData({errors:[...e??[],...a??[]]})}),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 W=p.createContext("guiLayoutWidgetAdapter");class I 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 y=p.createContext("guiRepeaterIndexesContext");var A=Object.defineProperty,b=(n,t,s,r)=>{for(var e=void 0,a=n.length-1,o;a>=0;a--)(o=n[a])&&(e=o(t,s,e)||e);return e&&A(t,s,e),e};const _=n=>{class t extends n{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,a=this.repeaterIndexes??[];let o;this.repeaterIndex!==void 0?o=[...a,this.repeaterIndex]:o=a,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 b([p.consume({context:g}),h.property({attribute:!1})],t.prototype,"formContext"),b([h.property({type:Object})],t.prototype,"widget"),b([h.property({type:Number})],t.prototype,"repeaterIndex"),b([p.consume({context:y,subscribe:!0}),h.property({attribute:!1})],t.prototype,"repeaterIndexes"),t};var S=Object.getOwnPropertyDescriptor,F=(n,t,s,r)=>{for(var e=r>1?void 0:r?S(t,s):t,a=n.length-1,o;a>=0;a--)(o=n[a])&&(e=o(e)||e);return e};i.WidgetElement=class extends _(c.LitElement){},i.WidgetElement=F([h.customElement("gui-widget")],i.WidgetElement);var R=Object.defineProperty,O=Object.getOwnPropertyDescriptor,u=(n,t,s,r)=>{for(var e=r>1?void 0:r?O(t,s):t,a=n.length-1,o;a>=0;a--)(o=n[a])&&(e=(r?o(t,s,e):o(e))||e);return r&&e&&R(t,s,e),e};i.FormElement=class extends c.LitElement{constructor(){super(...arguments),this.context=new E,this.autocomplete=void 0,this.direction="ltr",this.unsubscribeI18n=()=>{},this._defaultFormName=d.shortUUID()}connectedCallback(){super.connectedCallback(),this.classList.add("gui-form"),this.eventSub=this.context.events$.subscribe(t=>this.dispatchEvent(new CustomEvent(i.FormElement.FORM_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 c.html`
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||c.nothing}
6
+ autocomplete=${this.autocomplete||u.nothing}
7
+ @submit=${this.onFormSubmit}
7
8
  >
8
- ${x.when(t,()=>c.html` <gui-widget .widget=${this.formState?.formDef.form}></gui-widget>`,()=>c.html` <div>Loading form...</div>`)}
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?.unsubscribe(),this.unsubscribeI18n()}},i.FormElement.FORM_HEALTH_EVENT="formHealth",i.FormElement.FORM_EVENT="formEvent",u([p.provide({context:g})],i.FormElement.prototype,"context",2),u([h.property({attribute:!1})],i.FormElement.prototype,"config",2),u([h.property({attribute:!1})],i.FormElement.prototype,"validators",2),u([h.property({type:String})],i.FormElement.prototype,"autocomplete",2),u([h.state()],i.FormElement.prototype,"direction",2),i.FormElement=u([h.customElement("gui-core-form")],i.FormElement);var L=Object.defineProperty,f=(n,t,s,r)=>{for(var e=void 0,a=n.length-1,o;a>=0;a--)(o=n[a])&&(e=o(t,s,e)||e);return e&&L(t,s,e),e};const N=n=>{class t extends n{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),a=new e,o=[...this.parentRepeaterIndexes??[],r];new p.ContextProvider(a,{context:y,initialValue:o}),a.widget=d.makeRepeaterItemConfig(d.cloneObject(this.widget),o),a.id=`host-${this.widget.uid}`,this.replaceWith(a)}catch(e){console.error(`Widget "${this.widget.type}" could not be loaded`,e);const a=d.errorCodes.widgetCouldNotBeLoaded;this.dispatchEvent(new CustomEvent("formHealth",{detail:{status:"errored",message:`[${a}] Widget "${this.widget.type}" could not be loaded`,code:a},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:y,subscribe:!0}),h.property({attribute:!1})],t.prototype,"parentRepeaterIndexes"),t};var P=Object.getOwnPropertyDescriptor,U=(n,t,s,r)=>{for(var e=r>1?void 0:r?P(t,s):t,a=n.length-1,o;a>=0;a--)(o=n[a])&&(e=o(e)||e);return e};i.RepeaterWidgetElement=class extends N(c.LitElement){},i.RepeaterWidgetElement=U([h.customElement("gui-repeater-widget")],i.RepeaterWidgetElement),i.ActionWidgetAdapter=C,i.BaseWidgetAdapter=m,i.DisplayWidgetAdapter=T,i.InputWidgetAdapter=$,i.LayoutWidgetAdapter=I,i.LitFormContext=E,i.actionContext=w,i.displayWidgetContext=v,i.formContext=g,i.inputContext=D,i.layoutContext=W,i.repeaterIndexesContext=y,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}));
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.13.3",
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.13.3",
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"