@loadbare/widgets 0.4.0 → 0.6.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.
Files changed (54) hide show
  1. package/README.md +9 -5
  2. package/dist/control.d.ts +54 -0
  3. package/dist/control.d.ts.map +1 -0
  4. package/dist/control.js +100 -0
  5. package/dist/control.js.map +1 -0
  6. package/dist/index.d.ts +3 -0
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +3 -0
  9. package/dist/index.js.map +1 -1
  10. package/dist/lb-confirm.browser.d.ts +2 -0
  11. package/dist/lb-confirm.browser.d.ts.map +1 -0
  12. package/dist/lb-confirm.browser.js +36 -0
  13. package/dist/lb-confirm.browser.js.map +1 -0
  14. package/dist/lb-confirm.html +27 -0
  15. package/dist/lb-form.browser.d.ts +2 -0
  16. package/dist/lb-form.browser.d.ts.map +1 -0
  17. package/dist/lb-form.browser.js +28 -0
  18. package/dist/lb-form.browser.js.map +1 -0
  19. package/dist/lb-form.html +7 -0
  20. package/dist/lb-input.browser.js +9 -37
  21. package/dist/lb-input.browser.js.map +1 -1
  22. package/dist/lb-input.html +1 -1
  23. package/dist/lb-insert-dialog.browser.d.ts +2 -0
  24. package/dist/lb-insert-dialog.browser.d.ts.map +1 -0
  25. package/dist/lb-insert-dialog.browser.js +59 -0
  26. package/dist/lb-insert-dialog.browser.js.map +1 -0
  27. package/dist/lb-insert-dialog.html +25 -0
  28. package/dist/lb-master.html +51 -0
  29. package/dist/lb-options.browser.d.ts +38 -11
  30. package/dist/lb-options.browser.d.ts.map +1 -1
  31. package/dist/lb-options.browser.js +50 -80
  32. package/dist/lb-options.browser.js.map +1 -1
  33. package/dist/lb-options.html +1 -1
  34. package/dist/lb-picker.browser.js +9 -11
  35. package/dist/lb-picker.browser.js.map +1 -1
  36. package/dist/lb-picker.html +2 -2
  37. package/dist/lb-select.browser.js +7 -39
  38. package/dist/lb-select.browser.js.map +1 -1
  39. package/dist/lb-select.html +1 -1
  40. package/dist/lb-table.browser.js +63 -90
  41. package/dist/lb-table.browser.js.map +1 -1
  42. package/dist/lb-table.html +4 -3
  43. package/dist/lb-unknown-page.html +2 -4
  44. package/docs/lb-confirm.md +45 -0
  45. package/docs/lb-form.md +33 -0
  46. package/docs/lb-input.md +42 -40
  47. package/docs/lb-insert-dialog.md +50 -0
  48. package/docs/lb-master.md +53 -0
  49. package/docs/lb-options.md +54 -34
  50. package/docs/lb-picker.md +24 -24
  51. package/docs/lb-select.md +37 -19
  52. package/docs/lb-table.md +63 -29
  53. package/docs/lb-unknown-page.md +11 -13
  54. package/package.json +4 -4
package/README.md CHANGED
@@ -6,12 +6,16 @@ Inventory:
6
6
 
7
7
  | Widget | Is |
8
8
  | --- | --- |
9
- | [`lb-input`](docs/lb-input.md) | an editable cell wrapping an `<input>` |
10
- | [`lb-select`](docs/lb-select.md) | a `<select>` whose options the page writes |
11
- | [`lb-options`](docs/lb-options.md) | a `<select>` whose options come from a query |
9
+ | [`lb-input`](docs/lb-input.md) | a control wrapping an `<input>` |
10
+ | [`lb-select`](docs/lb-select.md) | a control wrapping a `<select>` whose options the page writes |
11
+ | [`lb-options`](docs/lb-options.md) | a control wrapping a `<select>` whose options come from a query |
12
12
  | [`lb-picker`](docs/lb-picker.md) | `lb-options` with the row template built in |
13
- | [`lb-table`](docs/lb-table.md) | a `<table>` supplying its own scaffolding |
13
+ | [`lb-table`](docs/lb-table.md) | a `<table>` supplying its own scaffolding and a ghost row |
14
14
  | [`lb-unknown-page`](docs/lb-unknown-page.md) | the chrome's dialog for a URL that names no page |
15
+ | [`lb-confirm`](docs/lb-confirm.md) | a button that asks before it sends |
16
+ | [`lb-form`](docs/lb-form.md) | a form over one row, which saves per control once the row is on record |
17
+ | [`lb-insert-dialog`](docs/lb-insert-dialog.md) | a row entered in a modal dialog, chosen in the picker that opened it |
18
+ | [`lb-master`](docs/lb-master.md) | a set, one of its rows, and the buttons that act on the set |
15
19
 
16
20
  ## Installing
17
21
 
@@ -26,7 +30,7 @@ Then list the package in the application's `imports.ts`:
26
30
  export default ["@loadbare/widgets"];
27
31
  ```
28
32
 
29
- You can now include the widgets in your HTML files.
33
+ The application's HTML files can then use the widgets.
30
34
 
31
35
  Apart from the line in `src/imports.ts`, no other import statements
32
36
  are required. The loadbare builder automatically bundles the HTML and
@@ -0,0 +1,54 @@
1
+ /**
2
+ * A form-associated custom element wrapping one native control, which makes
3
+ * the widget itself the control: the hub sets its `value` when a column
4
+ * lands, reads it back when a request gathers, and commits it on `change`
5
+ * when it carries `lb-request`. Nothing about a request is the widget's.
6
+ *
7
+ * The native control inside is an implementation detail. Its `change` is
8
+ * stopped and fired again on the widget, so a listener sees one control and
9
+ * one event per edit.
10
+ *
11
+ * Not a widget itself, so the file carries no `.browser` and no `lb-` name:
12
+ * a consumer's builder passes it over, and each widget that extends it
13
+ * brings it along.
14
+ */
15
+ export declare abstract class WrappedControl extends HTMLElement {
16
+ static formAssociated: boolean;
17
+ /** The tag of the native control this widget wraps. */
18
+ protected abstract inner: string;
19
+ /**
20
+ * Null where the DOM implementation offers no form value, which includes
21
+ * jsdom: the widget still works as a control, and a native form submission
22
+ * leaves it out.
23
+ */
24
+ private internals;
25
+ /** Whether the widget has connected once. */
26
+ private connected;
27
+ constructor();
28
+ /**
29
+ * A value that landed before this widget's definition did is only a
30
+ * stamp, since the hub sets `value` on a control and the element was not
31
+ * one yet. It is taken up the first time the widget connects, and never
32
+ * again: after that the hub sets `value` itself, and a later move must not
33
+ * undo an edit.
34
+ *
35
+ * The native control follows the widget's `form` attribute, so a form
36
+ * this widget joins by id resets the control inside it too.
37
+ */
38
+ connectedCallback(): void;
39
+ /** The native control this widget wraps, once it is there. */
40
+ protected get control(): HTMLInputElement | HTMLSelectElement | null;
41
+ get value(): string;
42
+ set value(value: string);
43
+ /**
44
+ * The native control is the form's too, and the form resets it by HTML's
45
+ * own algorithm. This widget comes first in tree order, so it tells the
46
+ * form its value once the control has been reset.
47
+ */
48
+ formResetCallback(): void;
49
+ /** The inner control changed, before the widget fires its own `change`. */
50
+ protected changed(): void;
51
+ /** Tell the form owner the value, where the implementation allows it. */
52
+ protected formValue(): void;
53
+ }
54
+ //# sourceMappingURL=control.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"control.d.ts","sourceRoot":"","sources":["../widgets/control.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;GAaG;AACH,8BAAsB,cAAe,SAAQ,WAAW;IACtD,MAAM,CAAC,cAAc,UAAQ;IAE7B,uDAAuD;IACvD,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEjC;;;;OAIG;IACH,OAAO,CAAC,SAAS,CAAqB;IAEtC,6CAA6C;IAC7C,OAAO,CAAC,SAAS,CAAS;;IAY1B;;;;;;;;;OASG;IACH,iBAAiB,IAAI,IAAI;IASzB,8DAA8D;IAC9D,SAAS,KAAK,OAAO,IAAI,gBAAgB,GAAG,iBAAiB,GAAG,IAAI,CAEnE;IAED,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,EAUtB;IAED;;;;OAIG;IACH,iBAAiB,IAAI,IAAI;IAIzB,2EAA2E;IAC3E,SAAS,CAAC,OAAO,IAAI,IAAI;IAIzB,yEAAyE;IACzE,SAAS,CAAC,SAAS,IAAI,IAAI;CAG5B"}
@@ -0,0 +1,100 @@
1
+ /// <reference lib="dom" />
2
+ import { ATTR_COLUMN_VALUE } from "@loadbare/app/constants";
3
+ /**
4
+ * A form-associated custom element wrapping one native control, which makes
5
+ * the widget itself the control: the hub sets its `value` when a column
6
+ * lands, reads it back when a request gathers, and commits it on `change`
7
+ * when it carries `lb-request`. Nothing about a request is the widget's.
8
+ *
9
+ * The native control inside is an implementation detail. Its `change` is
10
+ * stopped and fired again on the widget, so a listener sees one control and
11
+ * one event per edit.
12
+ *
13
+ * Not a widget itself, so the file carries no `.browser` and no `lb-` name:
14
+ * a consumer's builder passes it over, and each widget that extends it
15
+ * brings it along.
16
+ */
17
+ export class WrappedControl extends HTMLElement {
18
+ static formAssociated = true;
19
+ /**
20
+ * Null where the DOM implementation offers no form value, which includes
21
+ * jsdom: the widget still works as a control, and a native form submission
22
+ * leaves it out.
23
+ */
24
+ internals = internalsOf(this);
25
+ /** Whether the widget has connected once. */
26
+ connected = false;
27
+ constructor() {
28
+ super();
29
+ this.addEventListener("change", (e) => {
30
+ if (e.target === this || e.target !== this.control)
31
+ return;
32
+ e.stopPropagation();
33
+ this.changed();
34
+ this.dispatchEvent(new Event("change", { bubbles: true }));
35
+ });
36
+ }
37
+ /**
38
+ * A value that landed before this widget's definition did is only a
39
+ * stamp, since the hub sets `value` on a control and the element was not
40
+ * one yet. It is taken up the first time the widget connects, and never
41
+ * again: after that the hub sets `value` itself, and a later move must not
42
+ * undo an edit.
43
+ *
44
+ * The native control follows the widget's `form` attribute, so a form
45
+ * this widget joins by id resets the control inside it too.
46
+ */
47
+ connectedCallback() {
48
+ const form = this.getAttribute("form");
49
+ if (form !== null)
50
+ this.control?.setAttribute("form", form);
51
+ if (this.connected)
52
+ return;
53
+ this.connected = true;
54
+ const stamped = this.getAttribute(ATTR_COLUMN_VALUE);
55
+ if (stamped !== null)
56
+ this.value = stamped;
57
+ }
58
+ /** The native control this widget wraps, once it is there. */
59
+ get control() {
60
+ return this.querySelector(this.inner);
61
+ }
62
+ get value() {
63
+ return this.control?.value ?? "";
64
+ }
65
+ set value(value) {
66
+ const control = this.control;
67
+ if (!control) {
68
+ console.error(`${this.localName}: no <${this.inner}> to receive the value`);
69
+ return;
70
+ }
71
+ control.value = value ?? "";
72
+ this.formValue();
73
+ }
74
+ /**
75
+ * The native control is the form's too, and the form resets it by HTML's
76
+ * own algorithm. This widget comes first in tree order, so it tells the
77
+ * form its value once the control has been reset.
78
+ */
79
+ formResetCallback() {
80
+ queueMicrotask(() => this.formValue());
81
+ }
82
+ /** The inner control changed, before the widget fires its own `change`. */
83
+ changed() {
84
+ this.formValue();
85
+ }
86
+ /** Tell the form owner the value, where the implementation allows it. */
87
+ formValue() {
88
+ this.internals?.setFormValue(this.value);
89
+ }
90
+ }
91
+ function internalsOf(el) {
92
+ try {
93
+ const internals = el.attachInternals();
94
+ return typeof internals.setFormValue === "function" ? internals : null;
95
+ }
96
+ catch {
97
+ return null;
98
+ }
99
+ }
100
+ //# sourceMappingURL=control.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"control.js","sourceRoot":"","sources":["../widgets/control.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAE3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAgB,cAAe,SAAQ,WAAW;IACtD,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC;IAK7B;;;;OAIG;IACK,SAAS,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IAEtC,6CAA6C;IACrC,SAAS,GAAG,KAAK,CAAC;IAE1B;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE;YACpC,IAAI,CAAC,CAAC,MAAM,KAAK,IAAI,IAAI,CAAC,CAAC,MAAM,KAAK,IAAI,CAAC,OAAO;gBAAE,OAAO;YAC3D,CAAC,CAAC,eAAe,EAAE,CAAC;YACpB,IAAI,CAAC,OAAO,EAAE,CAAC;YACf,IAAI,CAAC,aAAa,CAAC,IAAI,KAAK,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAC7D,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;OASG;IACH,iBAAiB;QACf,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QACvC,IAAI,IAAI,KAAK,IAAI;YAAE,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC5D,IAAI,IAAI,CAAC,SAAS;YAAE,OAAO;QAC3B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC;QACrD,IAAI,OAAO,KAAK,IAAI;YAAE,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC;IAC7C,CAAC;IAED,8DAA8D;IAC9D,IAAc,OAAO;QACnB,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC;IACnC,CAAC;IAED,IAAI,KAAK,CAAC,KAAa;QACrB,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7B,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CACX,GAAG,IAAI,CAAC,SAAS,SAAS,IAAI,CAAC,KAAK,wBAAwB,CAC7D,CAAC;YACF,OAAO;QACT,CAAC;QACD,OAAO,CAAC,KAAK,GAAG,KAAK,IAAI,EAAE,CAAC;QAC5B,IAAI,CAAC,SAAS,EAAE,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACH,iBAAiB;QACf,cAAc,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;IACzC,CAAC;IAED,2EAA2E;IACjE,OAAO;QACf,IAAI,CAAC,SAAS,EAAE,CAAC;IACnB,CAAC;IAED,yEAAyE;IAC/D,SAAS;QACjB,IAAI,CAAC,SAAS,EAAE,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;;AAGH,SAAS,WAAW,CAAC,EAAe;IAClC,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,EAAE,CAAC,eAAe,EAAE,CAAC;QACvC,OAAO,OAAO,SAAS,CAAC,YAAY,KAAK,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;IACzE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["/// <reference lib=\"dom\" />\n\nimport { ATTR_COLUMN_VALUE } from \"@loadbare/app/constants\";\n\n/**\n * A form-associated custom element wrapping one native control, which makes\n * the widget itself the control: the hub sets its `value` when a column\n * lands, reads it back when a request gathers, and commits it on `change`\n * when it carries `lb-request`. Nothing about a request is the widget's.\n *\n * The native control inside is an implementation detail. Its `change` is\n * stopped and fired again on the widget, so a listener sees one control and\n * one event per edit.\n *\n * Not a widget itself, so the file carries no `.browser` and no `lb-` name:\n * a consumer's builder passes it over, and each widget that extends it\n * brings it along.\n */\nexport abstract class WrappedControl extends HTMLElement {\n static formAssociated = true;\n\n /** The tag of the native control this widget wraps. */\n protected abstract inner: string;\n\n /**\n * Null where the DOM implementation offers no form value, which includes\n * jsdom: the widget still works as a control, and a native form submission\n * leaves it out.\n */\n private internals = internalsOf(this);\n\n /** Whether the widget has connected once. */\n private connected = false;\n\n constructor() {\n super();\n this.addEventListener(\"change\", (e) => {\n if (e.target === this || e.target !== this.control) return;\n e.stopPropagation();\n this.changed();\n this.dispatchEvent(new Event(\"change\", { bubbles: true }));\n });\n }\n\n /**\n * A value that landed before this widget's definition did is only a\n * stamp, since the hub sets `value` on a control and the element was not\n * one yet. It is taken up the first time the widget connects, and never\n * again: after that the hub sets `value` itself, and a later move must not\n * undo an edit.\n *\n * The native control follows the widget's `form` attribute, so a form\n * this widget joins by id resets the control inside it too.\n */\n connectedCallback(): void {\n const form = this.getAttribute(\"form\");\n if (form !== null) this.control?.setAttribute(\"form\", form);\n if (this.connected) return;\n this.connected = true;\n const stamped = this.getAttribute(ATTR_COLUMN_VALUE);\n if (stamped !== null) this.value = stamped;\n }\n\n /** The native control this widget wraps, once it is there. */\n protected get control(): HTMLInputElement | HTMLSelectElement | null {\n return this.querySelector(this.inner);\n }\n\n get value(): string {\n return this.control?.value ?? \"\";\n }\n\n set value(value: string) {\n const control = this.control;\n if (!control) {\n console.error(\n `${this.localName}: no <${this.inner}> to receive the value`,\n );\n return;\n }\n control.value = value ?? \"\";\n this.formValue();\n }\n\n /**\n * The native control is the form's too, and the form resets it by HTML's\n * own algorithm. This widget comes first in tree order, so it tells the\n * form its value once the control has been reset.\n */\n formResetCallback(): void {\n queueMicrotask(() => this.formValue());\n }\n\n /** The inner control changed, before the widget fires its own `change`. */\n protected changed(): void {\n this.formValue();\n }\n\n /** Tell the form owner the value, where the implementation allows it. */\n protected formValue(): void {\n this.internals?.setFormValue(this.value);\n }\n}\n\nfunction internalsOf(el: HTMLElement): ElementInternals | null {\n try {\n const internals = el.attachInternals();\n return typeof internals.setFormValue === \"function\" ? internals : null;\n } catch {\n return null;\n }\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -3,4 +3,7 @@ import "./lb-select.browser.js";
3
3
  import "./lb-options.browser.js";
4
4
  import "./lb-table.browser.js";
5
5
  import "./lb-picker.browser.js";
6
+ import "./lb-confirm.browser.js";
7
+ import "./lb-form.browser.js";
8
+ import "./lb-insert-dialog.browser.js";
6
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../widgets/index.ts"],"names":[],"mappings":"AAAA,OAAO,uBAAuB,CAAC;AAC/B,OAAO,wBAAwB,CAAC;AAChC,OAAO,yBAAyB,CAAC;AACjC,OAAO,uBAAuB,CAAC;AAC/B,OAAO,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../widgets/index.ts"],"names":[],"mappings":"AAAA,OAAO,uBAAuB,CAAC;AAC/B,OAAO,wBAAwB,CAAC;AAChC,OAAO,yBAAyB,CAAC;AACjC,OAAO,uBAAuB,CAAC;AAC/B,OAAO,wBAAwB,CAAC;AAChC,OAAO,yBAAyB,CAAC;AACjC,OAAO,sBAAsB,CAAC;AAC9B,OAAO,+BAA+B,CAAC"}
package/dist/index.js CHANGED
@@ -3,4 +3,7 @@ import "./lb-select.browser.js";
3
3
  import "./lb-options.browser.js";
4
4
  import "./lb-table.browser.js";
5
5
  import "./lb-picker.browser.js";
6
+ import "./lb-confirm.browser.js";
7
+ import "./lb-form.browser.js";
8
+ import "./lb-insert-dialog.browser.js";
6
9
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../widgets/index.ts"],"names":[],"mappings":"AAAA,OAAO,uBAAuB,CAAC;AAC/B,OAAO,wBAAwB,CAAC;AAChC,OAAO,yBAAyB,CAAC;AACjC,OAAO,uBAAuB,CAAC;AAC/B,OAAO,wBAAwB,CAAC","sourcesContent":["import \"./lb-input.browser.js\";\nimport \"./lb-select.browser.js\";\nimport \"./lb-options.browser.js\";\nimport \"./lb-table.browser.js\";\nimport \"./lb-picker.browser.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../widgets/index.ts"],"names":[],"mappings":"AAAA,OAAO,uBAAuB,CAAC;AAC/B,OAAO,wBAAwB,CAAC;AAChC,OAAO,yBAAyB,CAAC;AACjC,OAAO,uBAAuB,CAAC;AAC/B,OAAO,wBAAwB,CAAC;AAChC,OAAO,yBAAyB,CAAC;AACjC,OAAO,sBAAsB,CAAC;AAC9B,OAAO,+BAA+B,CAAC","sourcesContent":["import \"./lb-input.browser.js\";\nimport \"./lb-select.browser.js\";\nimport \"./lb-options.browser.js\";\nimport \"./lb-table.browser.js\";\nimport \"./lb-picker.browser.js\";\nimport \"./lb-confirm.browser.js\";\nimport \"./lb-form.browser.js\";\nimport \"./lb-insert-dialog.browser.js\";\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=lb-confirm.browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lb-confirm.browser.d.ts","sourceRoot":"","sources":["../widgets/lb-confirm.browser.ts"],"names":[],"mappings":""}
@@ -0,0 +1,36 @@
1
+ /// <reference lib="dom" />
2
+ import { LB_DONE_EVENT_NAME } from "@loadbare/app/constants";
3
+ /**
4
+ * Opens and closes its own dialog, and nothing else.
5
+ *
6
+ * The dialog is found by position rather than by id, because ids repeat when
7
+ * the tag sits in a row template and the hub clones it once per row. HTML's
8
+ * own `commandfor` would open it with no script, but only by id.
9
+ *
10
+ * The confirm button carries `lb-request`, and the hub commits it. This code
11
+ * never touches the request; it closes the dialog when `lb-request-done` says
12
+ * the request succeeded. A refused request leaves the dialog open, with the
13
+ * hub's `lb-request-error` on the confirm button, so the user sees the
14
+ * refusal where they asked and can cancel or try again.
15
+ */
16
+ class LbConfirm extends HTMLElement {
17
+ constructor() {
18
+ super();
19
+ this.addEventListener("click", (e) => {
20
+ const target = e.target;
21
+ if (target.closest("[data-open]"))
22
+ this.dialog.showModal();
23
+ else if (target.closest("[data-close]"))
24
+ this.dialog.close();
25
+ });
26
+ this.addEventListener(LB_DONE_EVENT_NAME, (e) => {
27
+ if (!e.detail.error)
28
+ this.dialog.close();
29
+ });
30
+ }
31
+ get dialog() {
32
+ return this.querySelector("dialog");
33
+ }
34
+ }
35
+ customElements.define("lb-confirm", LbConfirm);
36
+ //# sourceMappingURL=lb-confirm.browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lb-confirm.browser.js","sourceRoot":"","sources":["../widgets/lb-confirm.browser.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAE3B,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG7D;;;;;;;;;;;;GAYG;AACH,MAAM,SAAU,SAAQ,WAAW;IACjC;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;YACnC,MAAM,MAAM,GAAG,CAAC,CAAC,MAAiB,CAAC;YACnC,IAAI,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC;gBAAE,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;iBACtD,IAAI,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC;gBAAE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAC/D,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,CAAC,CAAC,EAAE,EAAE;YAC9C,IAAI,CAAE,CAAiC,CAAC,MAAM,CAAC,KAAK;gBAAE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAC5E,CAAC,CAAC,CAAC;IACL,CAAC;IAED,IAAY,MAAM;QAChB,OAAO,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAE,CAAC;IACvC,CAAC;CACF;AAED,cAAc,CAAC,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC","sourcesContent":["/// <reference lib=\"dom\" />\n\nimport { LB_DONE_EVENT_NAME } from \"@loadbare/app/constants\";\nimport type { HubRequestDone } from \"@loadbare/app/types\";\n\n/**\n * Opens and closes its own dialog, and nothing else.\n *\n * The dialog is found by position rather than by id, because ids repeat when\n * the tag sits in a row template and the hub clones it once per row. HTML's\n * own `commandfor` would open it with no script, but only by id.\n *\n * The confirm button carries `lb-request`, and the hub commits it. This code\n * never touches the request; it closes the dialog when `lb-request-done` says\n * the request succeeded. A refused request leaves the dialog open, with the\n * hub's `lb-request-error` on the confirm button, so the user sees the\n * refusal where they asked and can cancel or try again.\n */\nclass LbConfirm extends HTMLElement {\n constructor() {\n super();\n this.addEventListener(\"click\", (e) => {\n const target = e.target as Element;\n if (target.closest(\"[data-open]\")) this.dialog.showModal();\n else if (target.closest(\"[data-close]\")) this.dialog.close();\n });\n this.addEventListener(LB_DONE_EVENT_NAME, (e) => {\n if (!(e as CustomEvent<HubRequestDone>).detail.error) this.dialog.close();\n });\n }\n\n private get dialog(): HTMLDialogElement {\n return this.querySelector(\"dialog\")!;\n }\n}\n\ncustomElements.define(\"lb-confirm\", LbConfirm);\n"]}
@@ -0,0 +1,27 @@
1
+ <!--
2
+ A button that asks before it sends. The request is on the dialog's confirm
3
+ button, never on the tag: nothing reaches the hub until the user says yes,
4
+ so there is no request to catch and send again.
5
+
6
+ The dialog is in the page like any other element, inside whatever row the
7
+ tag sits in, so the confirm button's query and key are that row's, and the
8
+ message written inside the tag can show the row's columns with lb-column.
9
+
10
+ Cancel comes first and takes focus, so Enter on a dialog opened by accident
11
+ does nothing harmful. The confirm button does not close the dialog; the
12
+ widget does, once the request has succeeded.
13
+ -->
14
+ <button type="button" class="lb-confirm-open" data-open>{{label}}</button>
15
+ <dialog class="lb-confirm-dialog">
16
+ <div class="lb-confirm-message" lb-exp-slot></div>
17
+ <div class="lb-confirm-buttons">
18
+ <button type="button" data-close autofocus>Cancel</button>
19
+ <button
20
+ type="button"
21
+ class="lb-confirm-yes"
22
+ lb-request="{{request}}"
23
+ >
24
+ {{confirm|Confirm}}
25
+ </button>
26
+ </div>
27
+ </dialog>
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=lb-form.browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lb-form.browser.d.ts","sourceRoot":"","sources":["../widgets/lb-form.browser.ts"],"names":[],"mappings":""}
@@ -0,0 +1,28 @@
1
+ /// <reference lib="dom" />
2
+ import { LB_EVENT_NAME, REQUEST_ROW_UPDATE } from "@loadbare/app/constants";
3
+ /**
4
+ * A form over one row, in one of two modes that the row decides.
5
+ *
6
+ * A row with a key is on record, and each control saves its own column on
7
+ * `change`: the page writes `lb-request="lb-row-update"` on every control.
8
+ * A row with an empty key is a new one not yet entered, and a change saves
9
+ * nothing, because there is nothing to update; the controls only hold what
10
+ * will be gathered when something submits the form.
11
+ *
12
+ * So the form stops an update whose key came back empty. The hub completes a
13
+ * request on the way down, before any ancestor sees it, so the key is already
14
+ * in `detail` when the event bubbles through here.
15
+ */
16
+ class LbForm extends HTMLElement {
17
+ constructor() {
18
+ super();
19
+ this.addEventListener(LB_EVENT_NAME, (e) => {
20
+ const request = e.detail;
21
+ if (request.name === REQUEST_ROW_UPDATE && request.key === "") {
22
+ e.stopPropagation();
23
+ }
24
+ });
25
+ }
26
+ }
27
+ customElements.define("lb-form", LbForm);
28
+ //# sourceMappingURL=lb-form.browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lb-form.browser.js","sourceRoot":"","sources":["../widgets/lb-form.browser.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAE3B,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG5E;;;;;;;;;;;;GAYG;AACH,MAAM,MAAO,SAAQ,WAAW;IAC9B;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,gBAAgB,CAAC,aAAa,EAAE,CAAC,CAAC,EAAE,EAAE;YACzC,MAAM,OAAO,GAAI,CAA6B,CAAC,MAAM,CAAC;YACtD,IAAI,OAAO,CAAC,IAAI,KAAK,kBAAkB,IAAI,OAAO,CAAC,GAAG,KAAK,EAAE,EAAE,CAAC;gBAC9D,CAAC,CAAC,eAAe,EAAE,CAAC;YACtB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,cAAc,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC","sourcesContent":["/// <reference lib=\"dom\" />\n\nimport { LB_EVENT_NAME, REQUEST_ROW_UPDATE } from \"@loadbare/app/constants\";\nimport type { HubRequest } from \"@loadbare/app/types\";\n\n/**\n * A form over one row, in one of two modes that the row decides.\n *\n * A row with a key is on record, and each control saves its own column on\n * `change`: the page writes `lb-request=\"lb-row-update\"` on every control.\n * A row with an empty key is a new one not yet entered, and a change saves\n * nothing, because there is nothing to update; the controls only hold what\n * will be gathered when something submits the form.\n *\n * So the form stops an update whose key came back empty. The hub completes a\n * request on the way down, before any ancestor sees it, so the key is already\n * in `detail` when the event bubbles through here.\n */\nclass LbForm extends HTMLElement {\n constructor() {\n super();\n this.addEventListener(LB_EVENT_NAME, (e) => {\n const request = (e as CustomEvent<HubRequest>).detail;\n if (request.name === REQUEST_ROW_UPDATE && request.key === \"\") {\n e.stopPropagation();\n }\n });\n }\n}\n\ncustomElements.define(\"lb-form\", LbForm);\n"]}
@@ -0,0 +1,7 @@
1
+ <!--
2
+ One row's controls, and nothing else. A button that acts on the row as a
3
+ whole adds a row to a set or takes one out, so it belongs to whatever holds
4
+ the set, and reaches the form from there the way HTML lets any button reach
5
+ any form: by `form="<id>"`.
6
+ -->
7
+ <form id="{{id}}" class="lb-form" lb-exp-slot></form>
@@ -1,45 +1,17 @@
1
1
  /// <reference lib="dom" />
2
- import { ATTR_ACTION, ATTR_VALUE, LB_EVENT_NAME, } from "@loadbare/app/constants";
2
+ import { WrappedControl } from "./control.js";
3
3
  /**
4
- * A leaf cell wrapping an <input>. The hub writes one attribute name for
5
- * every widget type, so the value lands in `lb-value` and the widget
6
- * forwards it to the control it owns.
4
+ * An `<input>` with its label, as one control. The hub sets its `value` from
5
+ * the column its `lb-column` names, and gathers it back under the same name.
7
6
  *
8
- * The other direction of the same cell: `lb-action` names what a change
9
- * sends, carrying the input's value. The hub scopes it like any request, so
10
- * the reserved `lb-row-update` reaches the server with the list and key this
11
- * input sits in, and `values` holding this input's cell alone. Without
12
- * `lb-action` a change sends nothing.
7
+ * Without `lb-request` a change commits nothing, which is what an input inside
8
+ * a form or a ghost row wants: the form gathers it on submit, and one that also
9
+ * sent its own request would write the same edit twice.
13
10
  *
14
- * The developer has to ask, because committing per field is one editing model
15
- * and not the only one. An input inside an `lb-row-insert` or `lb-row-update`
16
- * form is read again by the form on submit, so a widget that sent on its own
17
- * would write the same edit twice and defeat the batch the form is for.
11
+ * Its definition takes `exp-type`, the input's `type`, `text` when absent.
18
12
  */
19
- class LbInput extends HTMLElement {
20
- static observedAttributes = [ATTR_VALUE];
21
- attributeChangedCallback(_name, _old, value) {
22
- const input = this.querySelector("input");
23
- if (!input) {
24
- console.error(`lb-input: no <input> to receive the value`);
25
- return;
26
- }
27
- input.value = value;
28
- }
29
- connectedCallback() {
30
- this.addEventListener("change", () => {
31
- const action = this.getAttribute(ATTR_ACTION);
32
- if (!action)
33
- return;
34
- const input = this.querySelector("input");
35
- if (!input) {
36
- console.error(`lb-input: change with no <input>, ignoring`);
37
- return;
38
- }
39
- const detail = { action, value: input.value };
40
- this.dispatchEvent(new CustomEvent(LB_EVENT_NAME, { bubbles: true, detail }));
41
- });
42
- }
13
+ class LbInput extends WrappedControl {
14
+ inner = "input";
43
15
  }
44
16
  customElements.define("lb-input", LbInput);
45
17
  //# sourceMappingURL=lb-input.browser.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"lb-input.browser.js","sourceRoot":"","sources":["../widgets/lb-input.browser.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAE3B,OAAO,EACL,WAAW,EACX,UAAU,EACV,aAAa,GACd,MAAM,yBAAyB,CAAC;AAGjC;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,OAAQ,SAAQ,WAAW;IAC/B,MAAM,CAAC,kBAAkB,GAAG,CAAC,UAAU,CAAC,CAAC;IAEzC,wBAAwB,CAAC,KAAa,EAAE,IAAY,EAAE,KAAa;QACjE,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC1C,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;YAC3D,OAAO;QACT,CAAC;QACD,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,iBAAiB;QACf,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,GAAG,EAAE;YACnC,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;YAC9C,IAAI,CAAC,MAAM;gBAAE,OAAO;YACpB,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YAC1C,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,OAAO,CAAC,KAAK,CAAC,4CAA4C,CAAC,CAAC;gBAC5D,OAAO;YACT,CAAC;YACD,MAAM,MAAM,GAAe,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;YAC1D,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,aAAa,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAC1D,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;;AAGH,cAAc,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC","sourcesContent":["/// <reference lib=\"dom\" />\n\nimport {\n ATTR_ACTION,\n ATTR_VALUE,\n LB_EVENT_NAME,\n} from \"@loadbare/app/constants\";\nimport type { HubRequest } from \"@loadbare/app/types\";\n\n/**\n * A leaf cell wrapping an <input>. The hub writes one attribute name for\n * every widget type, so the value lands in `lb-value` and the widget\n * forwards it to the control it owns.\n *\n * The other direction of the same cell: `lb-action` names what a change\n * sends, carrying the input's value. The hub scopes it like any request, so\n * the reserved `lb-row-update` reaches the server with the list and key this\n * input sits in, and `values` holding this input's cell alone. Without\n * `lb-action` a change sends nothing.\n *\n * The developer has to ask, because committing per field is one editing model\n * and not the only one. An input inside an `lb-row-insert` or `lb-row-update`\n * form is read again by the form on submit, so a widget that sent on its own\n * would write the same edit twice and defeat the batch the form is for.\n */\n\nclass LbInput extends HTMLElement {\n static observedAttributes = [ATTR_VALUE];\n\n attributeChangedCallback(_name: string, _old: string, value: string) {\n const input = this.querySelector(\"input\");\n if (!input) {\n console.error(`lb-input: no <input> to receive the value`);\n return;\n }\n input.value = value;\n }\n\n connectedCallback() {\n this.addEventListener(\"change\", () => {\n const action = this.getAttribute(ATTR_ACTION);\n if (!action) return;\n const input = this.querySelector(\"input\");\n if (!input) {\n console.error(`lb-input: change with no <input>, ignoring`);\n return;\n }\n const detail: HubRequest = { action, value: input.value };\n this.dispatchEvent(\n new CustomEvent(LB_EVENT_NAME, { bubbles: true, detail }),\n );\n });\n }\n}\n\ncustomElements.define(\"lb-input\", LbInput);\n"]}
1
+ {"version":3,"file":"lb-input.browser.js","sourceRoot":"","sources":["../widgets/lb-input.browser.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAE3B,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C;;;;;;;;;GASG;AACH,MAAM,OAAQ,SAAQ,cAAc;IACxB,KAAK,GAAG,OAAO,CAAC;CAC3B;AAED,cAAc,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC","sourcesContent":["/// <reference lib=\"dom\" />\n\nimport { WrappedControl } from \"./control.js\";\n\n/**\n * An `<input>` with its label, as one control. The hub sets its `value` from\n * the column its `lb-column` names, and gathers it back under the same name.\n *\n * Without `lb-request` a change commits nothing, which is what an input inside\n * a form or a ghost row wants: the form gathers it on submit, and one that also\n * sent its own request would write the same edit twice.\n *\n * Its definition takes `exp-type`, the input's `type`, `text` when absent.\n */\nclass LbInput extends WrappedControl {\n protected inner = \"input\";\n}\n\ncustomElements.define(\"lb-input\", LbInput);\n"]}
@@ -1 +1 @@
1
- <label>{{label}} <input readonly="{{readonly}}" /></label>
1
+ <label>{{label}} <input type="{{type|text}}" readonly="{{readonly}}" /></label>
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=lb-insert-dialog.browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lb-insert-dialog.browser.d.ts","sourceRoot":"","sources":["../widgets/lb-insert-dialog.browser.ts"],"names":[],"mappings":""}
@@ -0,0 +1,59 @@
1
+ /// <reference lib="dom" />
2
+ import { LB_DONE_EVENT_NAME } from "@loadbare/app/constants";
3
+ /**
4
+ * Two rules. Closing the dialog resets the form, and the row the form creates
5
+ * is chosen in the picker the dialog was opened from.
6
+ *
7
+ * Save closes the dialog when `lb-request-done` says the insert succeeded,
8
+ * so there is a row to show for it, and a refusal leaves the entry open to
9
+ * correct. Cancel and Escape close it, and throw away what was typed.
10
+ *
11
+ * The picker is the nearest `lb-options` around the button that opened the
12
+ * dialog, which a `command` event names as its `source`. The new row's key is
13
+ * in the patch the insert answers with, and by the time `lb-request-done`
14
+ * reaches here that row is among the picker's options. Choosing it fires
15
+ * `change`, so a picker that saves its own column saves it, and one in a ghost
16
+ * row or a new record holds it until Save.
17
+ *
18
+ * `close` and `command` do not bubble, so they are heard in capture.
19
+ */
20
+ class LbInsertDialog extends HTMLElement {
21
+ /** The button that last opened the dialog. */
22
+ opener = null;
23
+ constructor() {
24
+ super();
25
+ this.addEventListener("close", () => this.querySelector("form")?.reset(), true);
26
+ this.addEventListener("command", (e) => {
27
+ this.opener = e.source ?? null;
28
+ }, true);
29
+ this.addEventListener(LB_DONE_EVENT_NAME, (e) => {
30
+ const { request, items, error } = e
31
+ .detail;
32
+ if (error)
33
+ return;
34
+ const item = items.find((i) => i.query === request.query);
35
+ const created = item?.patch?.rows?.[0];
36
+ if (created)
37
+ this.choose(String(created[item.key]));
38
+ this.querySelector("dialog")?.close();
39
+ });
40
+ }
41
+ choose(key) {
42
+ const picker = pickerNear(this.opener);
43
+ if (!picker)
44
+ return;
45
+ picker.value = key;
46
+ picker.dispatchEvent(new Event("change", { bubbles: true }));
47
+ }
48
+ }
49
+ /** The nearest `lb-options` around an element, searching outward. */
50
+ function pickerNear(el) {
51
+ for (let node = el?.parentElement; node; node = node.parentElement) {
52
+ const found = node.querySelector("lb-options");
53
+ if (found)
54
+ return found;
55
+ }
56
+ return null;
57
+ }
58
+ customElements.define("lb-insert-dialog", LbInsertDialog);
59
+ //# sourceMappingURL=lb-insert-dialog.browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lb-insert-dialog.browser.js","sourceRoot":"","sources":["../widgets/lb-insert-dialog.browser.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAE3B,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG7D;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,cAAe,SAAQ,WAAW;IACtC,8CAA8C;IACtC,MAAM,GAAmB,IAAI,CAAC;IAEtC;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,gBAAgB,CACnB,OAAO,EACP,GAAG,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EACzC,IAAI,CACL,CAAC;QACF,IAAI,CAAC,gBAAgB,CACnB,SAAS,EACT,CAAC,CAAC,EAAE,EAAE;YACJ,IAAI,CAAC,MAAM,GAAI,CAAyC,CAAC,MAAM,IAAI,IAAI,CAAC;QAC1E,CAAC,EACD,IAAI,CACL,CAAC;QACF,IAAI,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,CAAC,CAAC,EAAE,EAAE;YAC9C,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,GAAI,CAAiC;iBACjE,MAAM,CAAC;YACV,IAAI,KAAK;gBAAE,OAAO;YAClB,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,OAAO,CAAC,KAAK,CAAC,CAAC;YAC1D,MAAM,OAAO,GAAG,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YACvC,IAAI,OAAO;gBAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACrD,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAC;QACxC,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,MAAM,CAAC,GAAW;QACxB,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACvC,IAAI,CAAC,MAAM;YAAE,OAAO;QACpB,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC;QACnB,MAAM,CAAC,aAAa,CAAC,IAAI,KAAK,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAC/D,CAAC;CACF;AAED,qEAAqE;AACrE,SAAS,UAAU,CACjB,EAAkB;IAElB,KAAK,IAAI,IAAI,GAAG,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QACnE,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;QAC/C,IAAI,KAAK;YAAE,OAAO,KAAwC,CAAC;IAC7D,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,cAAc,CAAC,MAAM,CAAC,kBAAkB,EAAE,cAAc,CAAC,CAAC","sourcesContent":["/// <reference lib=\"dom\" />\n\nimport { LB_DONE_EVENT_NAME } from \"@loadbare/app/constants\";\nimport type { HubRequestDone } from \"@loadbare/app/types\";\n\n/**\n * Two rules. Closing the dialog resets the form, and the row the form creates\n * is chosen in the picker the dialog was opened from.\n *\n * Save closes the dialog when `lb-request-done` says the insert succeeded,\n * so there is a row to show for it, and a refusal leaves the entry open to\n * correct. Cancel and Escape close it, and throw away what was typed.\n *\n * The picker is the nearest `lb-options` around the button that opened the\n * dialog, which a `command` event names as its `source`. The new row's key is\n * in the patch the insert answers with, and by the time `lb-request-done`\n * reaches here that row is among the picker's options. Choosing it fires\n * `change`, so a picker that saves its own column saves it, and one in a ghost\n * row or a new record holds it until Save.\n *\n * `close` and `command` do not bubble, so they are heard in capture.\n */\nclass LbInsertDialog extends HTMLElement {\n /** The button that last opened the dialog. */\n private opener: Element | null = null;\n\n constructor() {\n super();\n this.addEventListener(\n \"close\",\n () => this.querySelector(\"form\")?.reset(),\n true,\n );\n this.addEventListener(\n \"command\",\n (e) => {\n this.opener = (e as Event & { source?: Element | null }).source ?? null;\n },\n true,\n );\n this.addEventListener(LB_DONE_EVENT_NAME, (e) => {\n const { request, items, error } = (e as CustomEvent<HubRequestDone>)\n .detail;\n if (error) return;\n const item = items.find((i) => i.query === request.query);\n const created = item?.patch?.rows?.[0];\n if (created) this.choose(String(created[item!.key]));\n this.querySelector(\"dialog\")?.close();\n });\n }\n\n private choose(key: string): void {\n const picker = pickerNear(this.opener);\n if (!picker) return;\n picker.value = key;\n picker.dispatchEvent(new Event(\"change\", { bubbles: true }));\n }\n}\n\n/** The nearest `lb-options` around an element, searching outward. */\nfunction pickerNear(\n el: Element | null,\n): (HTMLElement & { value: string }) | null {\n for (let node = el?.parentElement; node; node = node.parentElement) {\n const found = node.querySelector(\"lb-options\");\n if (found) return found as HTMLElement & { value: string };\n }\n return null;\n}\n\ncustomElements.define(\"lb-insert-dialog\", LbInsertDialog);\n"]}
@@ -0,0 +1,25 @@
1
+ <!--
2
+ A row entered in a modal dialog, for a set that is being chosen from
3
+ somewhere else on the page. The page writes the controls inside the tag and
4
+ names the query with exp-query; the dialog supplies the form and its two
5
+ buttons.
6
+
7
+ It is written once, outside every row, and opened by id with HTML's own
8
+ commandfor="{{id}}" command="show-modal" on as many buttons as want it. It
9
+ cannot sit beside the control it serves: a form inside another form is
10
+ dropped by the parser, and lb-table joins every control in a ghost row to
11
+ that row's form.
12
+
13
+ Save is the form's lb-row-insert. Cancel is HTML's close command, and
14
+ closing resets the form.
15
+ -->
16
+ <dialog id="{{id}}" class="lb-insert-dialog">
17
+ <h2>{{title}}</h2>
18
+ <form lb-query="{{query}}" lb-request="lb-row-insert">
19
+ <div class="lb-insert-dialog-controls" lb-exp-slot></div>
20
+ <div class="lb-insert-dialog-buttons">
21
+ <button type="button" commandfor="{{id}}" command="close">Cancel</button>
22
+ <button type="submit">{{save|Save}}</button>
23
+ </div>
24
+ </form>
25
+ </dialog>
@@ -0,0 +1,51 @@
1
+ <!--
2
+ A set on the left, one of its rows on the right, and the buttons that act on
3
+ the set. The page writes the picker into the "picker" template and the row's
4
+ controls inside the tag, and names the row's query with exp-row.
5
+
6
+ The row lands on the element around the form and the bar, so every button
7
+ there knows which row it means. A row with an empty key is a new one not
8
+ yet entered, and the stylesheet shows each button only in the mode it
9
+ belongs to.
10
+
11
+ The standard bar is [New] [Copy] [Delete] [Save new] [Cancel].
12
+ - New is not here: a button cannot write a query parm, only a control's
13
+ change can. Choosing the picker's blank does the same today.
14
+ - Copy is a request the page declares, `copy`. It goes to the server by
15
+ design rather than filling the form for Save new: a copy is a new row in
16
+ the set, and only the server can bring its children along. What comes
17
+ along is the page's to decide.
18
+ - Delete asks first. The page writes the question into the
19
+ "delete-message" template; it sits in the row, so lb-column can name
20
+ what is about to go.
21
+ - Cancel is HTML's reset: it throws away what was typed into a new row.
22
+ -->
23
+ <div class="lb-master">
24
+ <div class="lb-master-picker" lb-exp-template="picker"></div>
25
+ <div class="lb-master-row" lb-query="{{row}}">
26
+ <lb-form exp-id="{{form-id|master-form}}" lb-exp-slot></lb-form>
27
+ <div class="lb-master-buttons">
28
+ <button type="button" lb-request="copy" data-mode="on-record">Copy</button>
29
+ <lb-confirm
30
+ exp-label="Delete"
31
+ exp-request="lb-row-delete"
32
+ exp-confirm="Delete"
33
+ data-mode="on-record"
34
+ >
35
+ <div lb-exp-template="delete-message"></div>
36
+ </lb-confirm>
37
+ <button
38
+ type="submit"
39
+ form="{{form-id|master-form}}"
40
+ lb-request="lb-row-insert"
41
+ lb-url-push
42
+ data-mode="new"
43
+ >
44
+ Save new
45
+ </button>
46
+ <button type="reset" form="{{form-id|master-form}}" data-mode="new">
47
+ Cancel
48
+ </button>
49
+ </div>
50
+ </div>
51
+ </div>