@sealcode/sealgen 0.12.0 → 0.12.3

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 (268) hide show
  1. package/dist/notifier.js +1 -1
  2. package/package.json +2 -2
  3. package/src/notifier.ts +1 -1
  4. package/.madgerc +0 -7
  5. package/coverage/.tmp/coverage-15.json +0 -1
  6. package/coverage/.tmp/coverage-16.json +0 -1
  7. package/coverage/.tmp/coverage-17.json +0 -1
  8. package/coverage/.tmp/coverage-18.json +0 -1
  9. package/coverage/.tmp/coverage-19.json +0 -1
  10. package/coverage/.tmp/coverage-20.json +0 -1
  11. package/coverage/.tmp/coverage-21.json +0 -1
  12. package/coverage/.tmp/coverage-22.json +0 -1
  13. package/coverage/.tmp/coverage-23.json +0 -1
  14. package/coverage/.tmp/coverage-24.json +0 -1
  15. package/coverage/.tmp/coverage-25.json +0 -1
  16. package/coverage/.tmp/coverage-26.json +0 -1
  17. package/lib/add-collection.js +0 -24
  18. package/lib/add-jdd-component.js +0 -27
  19. package/lib/add-route.js +0 -65
  20. package/lib/add-route.test.js +0 -60
  21. package/lib/build.js +0 -187
  22. package/lib/cli.js +0 -35
  23. package/lib/components/components.js +0 -3
  24. package/lib/components/tabs.js +0 -88
  25. package/lib/components/toggle-modal.js +0 -46
  26. package/lib/example.test.js +0 -5
  27. package/lib/find-css-includes.js +0 -23
  28. package/lib/forms/controls/array.js +0 -140
  29. package/lib/forms/controls/autocomplete.js +0 -23
  30. package/lib/forms/controls/big-radio-group.js +0 -34
  31. package/lib/forms/controls/checkbox-group.js +0 -29
  32. package/lib/forms/controls/checkbox.js +0 -24
  33. package/lib/forms/controls/checkboxed-list-input.js +0 -35
  34. package/lib/forms/controls/collapsible-checkbox-group.js +0 -13
  35. package/lib/forms/controls/collapsible-field-group.js +0 -78
  36. package/lib/forms/controls/controls.js +0 -31
  37. package/lib/forms/controls/derived-frame.js +0 -52
  38. package/lib/forms/controls/derived.js +0 -77
  39. package/lib/forms/controls/dropdown.js +0 -55
  40. package/lib/forms/controls/editable-collection-subset.js +0 -68
  41. package/lib/forms/controls/field-group.js +0 -53
  42. package/lib/forms/controls/file.js +0 -35
  43. package/lib/forms/controls/form-control.js +0 -14
  44. package/lib/forms/controls/form-field-control.js +0 -9
  45. package/lib/forms/controls/form-header.js +0 -14
  46. package/lib/forms/controls/form-paragraph.js +0 -12
  47. package/lib/forms/controls/frame.js +0 -25
  48. package/lib/forms/controls/hidden-input.js +0 -14
  49. package/lib/forms/controls/html.js +0 -23
  50. package/lib/forms/controls/multiple-files.js +0 -160
  51. package/lib/forms/controls/multiple-photos.js +0 -33
  52. package/lib/forms/controls/number.js +0 -25
  53. package/lib/forms/controls/photo.js +0 -57
  54. package/lib/forms/controls/radio.js +0 -25
  55. package/lib/forms/controls/reverse-single-reference.js +0 -47
  56. package/lib/forms/controls/simple-input.js +0 -78
  57. package/lib/forms/controls/textarea.js +0 -33
  58. package/lib/forms/controls/tickable.js +0 -75
  59. package/lib/forms/fields/boolean.js +0 -51
  60. package/lib/forms/fields/boolean.test.js +0 -32
  61. package/lib/forms/fields/checkboxed-list.js +0 -40
  62. package/lib/forms/fields/collection-field.js +0 -29
  63. package/lib/forms/fields/email.js +0 -11
  64. package/lib/forms/fields/email.test.js +0 -20
  65. package/lib/forms/fields/enum-multiple.js +0 -47
  66. package/lib/forms/fields/enum-multiple.test.js +0 -27
  67. package/lib/forms/fields/enum.js +0 -39
  68. package/lib/forms/fields/enum.test.js +0 -21
  69. package/lib/forms/fields/existing-sealious-value.js +0 -16
  70. package/lib/forms/fields/field.js +0 -81
  71. package/lib/forms/fields/file.js +0 -53
  72. package/lib/forms/fields/multiple-files.js +0 -15
  73. package/lib/forms/fields/number.js +0 -45
  74. package/lib/forms/fields/number.test.js +0 -30
  75. package/lib/forms/fields/pick-from-list.js +0 -31
  76. package/lib/forms/fields/pick-from-list.test.js +0 -17
  77. package/lib/forms/fields/proxy-field.js +0 -20
  78. package/lib/forms/fields/regexp.js +0 -40
  79. package/lib/forms/fields/regexp.test.js +0 -21
  80. package/lib/forms/fields/reverse-single-reference.js +0 -14
  81. package/lib/forms/fields/simple-form-field.js +0 -20
  82. package/lib/forms/fields/structured-array.js +0 -18
  83. package/lib/forms/form.js +0 -176
  84. package/lib/forms/form.test.js +0 -1
  85. package/lib/forms/multiform.js +0 -174
  86. package/lib/forms/multiform.test.js +0 -426
  87. package/lib/generate-collections.js +0 -52
  88. package/lib/generate-components.js +0 -33
  89. package/lib/generate-routes.js +0 -75
  90. package/lib/index.js +0 -17
  91. package/lib/make-env.js +0 -14
  92. package/lib/make-hidden-inputs.js +0 -14
  93. package/lib/mount.js +0 -70
  94. package/lib/notifier.js +0 -19
  95. package/lib/page/access-control.js +0 -16
  96. package/lib/page/default-list-filters.js +0 -40
  97. package/lib/page/list.js +0 -183
  98. package/lib/page/mountable-with-fields.js +0 -85
  99. package/lib/page/mountable.js +0 -5
  100. package/lib/page/page.js +0 -26
  101. package/lib/page/props-parser.js +0 -23
  102. package/lib/page/sealious-list.js +0 -59
  103. package/lib/page/stateful-page.js +0 -97
  104. package/lib/remove-named-imports.js +0 -47
  105. package/lib/run.js +0 -2
  106. package/lib/sanitize.js +0 -10
  107. package/lib/src/add-collection.js +0 -24
  108. package/lib/src/add-jdd-component.js +0 -27
  109. package/lib/src/add-route.js +0 -65
  110. package/lib/src/add-route.test.js +0 -72
  111. package/lib/src/build.js +0 -142
  112. package/lib/src/cli.js +0 -37
  113. package/lib/src/components/components.js +0 -3
  114. package/lib/src/components/tabs.js +0 -88
  115. package/lib/src/components/toggle-modal.js +0 -46
  116. package/lib/src/example.test.js +0 -5
  117. package/lib/src/find-css-includes.js +0 -23
  118. package/lib/src/forms/controls/array.js +0 -141
  119. package/lib/src/forms/controls/autocomplete.js +0 -23
  120. package/lib/src/forms/controls/big-radio-group.js +0 -34
  121. package/lib/src/forms/controls/checkbox-group.js +0 -30
  122. package/lib/src/forms/controls/checkbox.js +0 -24
  123. package/lib/src/forms/controls/checkboxed-list-input.js +0 -35
  124. package/lib/src/forms/controls/collapsible-checkbox-group.js +0 -13
  125. package/lib/src/forms/controls/collapsible-field-group.js +0 -78
  126. package/lib/src/forms/controls/controls.js +0 -31
  127. package/lib/src/forms/controls/derived-frame.js +0 -52
  128. package/lib/src/forms/controls/derived.js +0 -77
  129. package/lib/src/forms/controls/dropdown.js +0 -55
  130. package/lib/src/forms/controls/editable-collection-subset.js +0 -68
  131. package/lib/src/forms/controls/field-group.js +0 -53
  132. package/lib/src/forms/controls/file.js +0 -35
  133. package/lib/src/forms/controls/form-control.js +0 -14
  134. package/lib/src/forms/controls/form-field-control.js +0 -9
  135. package/lib/src/forms/controls/form-header.js +0 -14
  136. package/lib/src/forms/controls/form-paragraph.js +0 -12
  137. package/lib/src/forms/controls/frame.js +0 -25
  138. package/lib/src/forms/controls/hidden-input.js +0 -14
  139. package/lib/src/forms/controls/html.js +0 -23
  140. package/lib/src/forms/controls/multiple-files.js +0 -160
  141. package/lib/src/forms/controls/multiple-photos.js +0 -33
  142. package/lib/src/forms/controls/number.js +0 -25
  143. package/lib/src/forms/controls/photo.js +0 -57
  144. package/lib/src/forms/controls/radio.js +0 -25
  145. package/lib/src/forms/controls/reverse-single-reference.js +0 -47
  146. package/lib/src/forms/controls/simple-input.js +0 -78
  147. package/lib/src/forms/controls/textarea.js +0 -33
  148. package/lib/src/forms/controls/tickable.js +0 -75
  149. package/lib/src/forms/fields/boolean.js +0 -51
  150. package/lib/src/forms/fields/boolean.test.js +0 -33
  151. package/lib/src/forms/fields/checkboxed-list.js +0 -40
  152. package/lib/src/forms/fields/collection-field.js +0 -29
  153. package/lib/src/forms/fields/email.js +0 -11
  154. package/lib/src/forms/fields/email.test.js +0 -20
  155. package/lib/src/forms/fields/enum-multiple.js +0 -47
  156. package/lib/src/forms/fields/enum-multiple.test.js +0 -27
  157. package/lib/src/forms/fields/enum.js +0 -39
  158. package/lib/src/forms/fields/enum.test.js +0 -21
  159. package/lib/src/forms/fields/existing-sealious-value.js +0 -16
  160. package/lib/src/forms/fields/field.js +0 -66
  161. package/lib/src/forms/fields/fields.js +0 -16
  162. package/lib/src/forms/fields/file.js +0 -53
  163. package/lib/src/forms/fields/multiple-files.js +0 -15
  164. package/lib/src/forms/fields/number.js +0 -45
  165. package/lib/src/forms/fields/number.test.js +0 -31
  166. package/lib/src/forms/fields/pick-from-list.js +0 -31
  167. package/lib/src/forms/fields/pick-from-list.test.js +0 -17
  168. package/lib/src/forms/fields/proxy-field.js +0 -20
  169. package/lib/src/forms/fields/regexp.js +0 -40
  170. package/lib/src/forms/fields/regexp.test.js +0 -21
  171. package/lib/src/forms/fields/reverse-single-reference.js +0 -14
  172. package/lib/src/forms/fields/simple-form-field.js +0 -19
  173. package/lib/src/forms/fields/structured-array.js +0 -18
  174. package/lib/src/forms/form-types.js +0 -2
  175. package/lib/src/forms/form.js +0 -176
  176. package/lib/src/forms/form.test.js +0 -271
  177. package/lib/src/forms/multiform.js +0 -174
  178. package/lib/src/forms/multiform.test.js +0 -430
  179. package/lib/src/generate-collections.js +0 -52
  180. package/lib/src/generate-components.js +0 -33
  181. package/lib/src/generate-routes.js +0 -75
  182. package/lib/src/hehe.test.js +0 -7
  183. package/lib/src/index.js +0 -19
  184. package/lib/src/make-env.js +0 -14
  185. package/lib/src/make-hidden-inputs.js +0 -14
  186. package/lib/src/mount.js +0 -70
  187. package/lib/src/notifier.js +0 -19
  188. package/lib/src/page/access-control.js +0 -16
  189. package/lib/src/page/default-list-filters.js +0 -40
  190. package/lib/src/page/list.js +0 -184
  191. package/lib/src/page/mountable-with-fields.js +0 -85
  192. package/lib/src/page/mountable.js +0 -5
  193. package/lib/src/page/page.js +0 -26
  194. package/lib/src/page/props-parser.js +0 -23
  195. package/lib/src/page/sealious-list.js +0 -59
  196. package/lib/src/page/stateful-page.js +0 -97
  197. package/lib/src/run.js +0 -2
  198. package/lib/src/sample-index.js +0 -3
  199. package/lib/src/sample-lib.js +0 -6
  200. package/lib/src/sanitize.js +0 -10
  201. package/lib/src/templates/collection.js +0 -12
  202. package/lib/src/templates/form.js +0 -57
  203. package/lib/src/templates/jdd-component.js +0 -39
  204. package/lib/src/templates/list.js +0 -139
  205. package/lib/src/templates/long-running-process.js +0 -60
  206. package/lib/src/templates/multiform.js +0 -55
  207. package/lib/src/templates/page.js +0 -23
  208. package/lib/src/templates/post.js +0 -22
  209. package/lib/src/templates/redirect.js +0 -23
  210. package/lib/src/templates/route-test.js +0 -54
  211. package/lib/src/templates/stateful-page.js +0 -66
  212. package/lib/src/templates/templates.js +0 -21
  213. package/lib/src/test_utils/locator_is_visible.js +0 -11
  214. package/lib/src/utils/assert-throws.js +0 -17
  215. package/lib/src/utils/base64.js +0 -7
  216. package/lib/src/utils/browser-creator.js +0 -10
  217. package/lib/src/utils/escape-url-params.js +0 -14
  218. package/lib/src/utils/exec.js +0 -22
  219. package/lib/src/utils/extract-fields-from-collection.js +0 -26
  220. package/lib/src/utils/format-external-url.js +0 -11
  221. package/lib/src/utils/import-path.js +0 -16
  222. package/lib/src/utils/input-wrapper.js +0 -15
  223. package/lib/src/utils/list-collections.js +0 -13
  224. package/lib/src/utils/make-slug.js +0 -6
  225. package/lib/src/utils/natural-numbers.js +0 -6
  226. package/lib/src/utils/prettier.js +0 -10
  227. package/lib/src/utils/question.js +0 -19
  228. package/lib/src/utils/render-attributes.js +0 -19
  229. package/lib/src/utils/sleep.js +0 -4
  230. package/lib/src/utils/translate.js +0 -6
  231. package/lib/src/utils/url-with-new-params.js +0 -5
  232. package/lib/src/utils/utils.js +0 -16
  233. package/lib/src/utils/walk.js +0 -23
  234. package/lib/src/vitest.config.js +0 -20
  235. package/lib/templates/collection.js +0 -12
  236. package/lib/templates/form.js +0 -57
  237. package/lib/templates/jdd-component.js +0 -39
  238. package/lib/templates/list.js +0 -139
  239. package/lib/templates/long-running-process.js +0 -60
  240. package/lib/templates/multiform.js +0 -55
  241. package/lib/templates/page.js +0 -23
  242. package/lib/templates/post.js +0 -22
  243. package/lib/templates/redirect.js +0 -23
  244. package/lib/templates/route-test.js +0 -54
  245. package/lib/templates/stateful-page.js +0 -66
  246. package/lib/templates/templates.js +0 -21
  247. package/lib/test_utils/locator_is_visible.js +0 -11
  248. package/lib/utils/assert-throws.js +0 -17
  249. package/lib/utils/base64.js +0 -7
  250. package/lib/utils/browser-creator.js +0 -10
  251. package/lib/utils/escape-url-params.js +0 -14
  252. package/lib/utils/exec.js +0 -22
  253. package/lib/utils/extract-fields-from-collection.js +0 -26
  254. package/lib/utils/format-external-url.js +0 -11
  255. package/lib/utils/import-path.js +0 -16
  256. package/lib/utils/input-wrapper.js +0 -15
  257. package/lib/utils/list-collections.js +0 -13
  258. package/lib/utils/make-slug.js +0 -6
  259. package/lib/utils/natural-numbers.js +0 -6
  260. package/lib/utils/prettier.js +0 -10
  261. package/lib/utils/question.js +0 -19
  262. package/lib/utils/render-attributes.js +0 -19
  263. package/lib/utils/sleep.js +0 -4
  264. package/lib/utils/translate.js +0 -6
  265. package/lib/utils/url-with-new-params.js +0 -5
  266. package/lib/utils/utils.js +0 -16
  267. package/lib/utils/walk.js +0 -23
  268. package/lib/vitest.config.js +0 -22
@@ -1,141 +0,0 @@
1
- import { hasShape, predicates } from "@sealcode/ts-predicates";
2
- import qs from "qs";
3
- import { tempstream } from "tempstream";
4
- import { SimpleFormField } from "../fields/simple-form-field.js";
5
- import { Derived } from "./derived.js";
6
- import { FormFieldControl } from "./form-field-control.js";
7
- export function UnboundControl(controlClass, arbitrary_field_name, params) {
8
- return [controlClass, arbitrary_field_name, params];
9
- }
10
- export class StructuredArray extends FormFieldControl {
11
- constructor(field, item_controls) {
12
- super([field]);
13
- this.field = field;
14
- this.item_controls = item_controls;
15
- }
16
- getFrameID() {
17
- return `array-frame-${this.field.name}`;
18
- }
19
- getInnerFormID() {
20
- return this.getFrameID() + "-form";
21
- }
22
- getActionURL(form_id, action) {
23
- return `${this.getFrameID()}${form_id || action ? "?" : ""}${qs.stringify({ form_id, action })}`;
24
- }
25
- async getDefaultItemBody() {
26
- return {};
27
- }
28
- makeSubfield(_field_name) {
29
- const fields = this;
30
- return new SimpleFormField(false);
31
- }
32
- async renderItemControl(ctx, form_id, control, item, index) {
33
- const fctx = {
34
- ctx,
35
- data: {},
36
- messages: [],
37
- field_name_prefix: "",
38
- form_id,
39
- validate: false,
40
- };
41
- if (Array.isArray(control)) {
42
- const [constructor, field_name, params] = control;
43
- const field = this.makeSubfield(field_name);
44
- if (!field) {
45
- console.warn(`makeSubfield returned null for field ${field_name}`);
46
- return "";
47
- }
48
- await field.init(`${this.field.name}[data][${index}][${field_name}]`);
49
- const hidden_shadow = new Derived([field], async (values, { inner_form_id, field_name }) => /* HTML */ `<input
50
- name="${field_name}"
51
- type="hidden"
52
- value="${values[field_name] || ""}"
53
- form="${inner_form_id}"
54
- />`, async () => ({
55
- inner_form_id: this.getInnerFormID(),
56
- field_name: field.name,
57
- }));
58
- return tempstream `${new constructor(field, params).render({
59
- ...fctx,
60
- data: { [field.name]: item[field_name] },
61
- })}${hidden_shadow.render({
62
- ...fctx,
63
- data: { [field.name]: item[field_name] },
64
- form_id: this.getInnerFormID(),
65
- })}`;
66
- }
67
- else {
68
- return control.render(fctx);
69
- }
70
- }
71
- async renderItem(ctx, form_id, item, index) {
72
- return tempstream /* HTML */ `<div>
73
- ${this.item_controls.map((control) => this.renderItemControl(ctx, form_id, control, item, index))}
74
- <input
75
- type="submit"
76
- value="remove"
77
- form="${this.getInnerFormID()}"
78
- formaction="${this.getActionURL(form_id, {
79
- remove: index,
80
- })}"
81
- />
82
- </div>`;
83
- }
84
- async getItems(ctx, raw_values) {
85
- return (await this.field.getValue(ctx, raw_values)).parsed;
86
- }
87
- async _render(ctx, form_id, raw_values) {
88
- const items = await this.getItems(ctx, raw_values);
89
- return tempstream /* HTML */ `<turbo-frame id="${this.getFrameID()}">
90
- Reverse Single Reference
91
- ${items.map((item, index) => this.renderItem(ctx, form_id, item, index))}
92
- <form id="${this.getInnerFormID()}" method="POST"></form>
93
- <input
94
- type="submit"
95
- value="add"
96
- form="${this.getInnerFormID()}"
97
- formaction="${this.getActionURL(form_id, {
98
- insert: { index: items.length, value: {} },
99
- })}"
100
- />
101
- </turbo-frame>`;
102
- }
103
- render(fctx) {
104
- return this._render(fctx.ctx, fctx.form_id, fctx.data);
105
- }
106
- async getTargetItemID(ctx) {
107
- return ctx.params.id;
108
- }
109
- mount(router) {
110
- console.log("mounting!", this.getActionURL());
111
- router.post(this.getActionURL(), async (ctx) => {
112
- let form_id = ctx.query.form_id;
113
- if (typeof form_id != "string") {
114
- throw new Error("Missing form_id query param");
115
- }
116
- const item = await this.field.sealious_field.collection.getByID(ctx.$context, await this.getTargetItemID(ctx));
117
- if (!hasShape({ action: predicates.object }, ctx.$body)) {
118
- throw new Error("Missing action param");
119
- }
120
- const field_data = ctx.$body[this.field.name] || { data: [] };
121
- console.log({ action: field_data });
122
- if (!hasShape({
123
- data: predicates.array(this.field.sealious_field.value_predicate),
124
- }, field_data)) {
125
- throw new Error("missing data atribute in action description");
126
- }
127
- item.set(this.field.name, {
128
- ...ctx.$body.action,
129
- data: field_data.data || [],
130
- });
131
- console.log("ACTION", {
132
- ...ctx.$body.action,
133
- data: field_data.data || [],
134
- });
135
- await item.save(ctx.$context);
136
- console.log(await item.getDecodedBody(ctx.$context, {}));
137
- ctx.body = this._render(ctx, form_id, await item.getDecodedBody(ctx.$context, {}));
138
- });
139
- }
140
- }
141
- //# sourceMappingURL=array.js.map
@@ -1,23 +0,0 @@
1
- import { SimpleInput } from "./simple-input.js";
2
- export class Autocomplete extends SimpleInput {
3
- constructor(field, options) {
4
- super(field);
5
- this.field = field;
6
- this.options = options;
7
- }
8
- getListID() {
9
- return this.getID() + "_list";
10
- }
11
- async getInputAttributes(fctx) {
12
- return {
13
- ...(await super.getInputAttributes(fctx)),
14
- list: this.getListID(),
15
- };
16
- }
17
- async postInput(ctx) {
18
- return /* HTML */ `<datalist id="${this.getListID()}">
19
- ${(await this.field.generateOptions(ctx)).map(({ value }) => /* HTML */ `<option>${value}</option>`)}
20
- </datalist>`;
21
- }
22
- }
23
- //# sourceMappingURL=autocomplete.js.map
@@ -1,34 +0,0 @@
1
- import { tempstream } from "tempstream";
2
- import { FormFieldControl } from "./form-field-control.js";
3
- export class BigRadioGroup extends FormFieldControl {
4
- constructor(field, options) {
5
- super([field]);
6
- this.field = field;
7
- this.options = options;
8
- }
9
- async render(fctx) {
10
- const { raw: current_value } = await this.field.getValue(fctx.ctx, fctx.data);
11
- return tempstream /* HTML */ `<div class="bigradios">
12
- ${Object.entries(this.options).map(([key, { description }]) => {
13
- const id = `${this.field.name}-radio-${key}`;
14
- return tempstream /* HTML */ `<input
15
- type="radio"
16
- name="${this.field.name}"
17
- value="${key}"
18
- id="${id}"
19
- style="display: none"
20
- ${fctx.form_id ? `form=${fctx.form_id}` : ""}
21
- ${this.field.required ? "required" : ""}
22
- ${key == current_value ? "checked" : ""}
23
- />
24
- <div class="bigradio">
25
- ${typeof description == "function"
26
- ? description(fctx)
27
- : description}
28
- <label class="bigradio__cta" for="${id}">Wybierz</label>
29
- </div>`;
30
- })}
31
- </div>`;
32
- }
33
- }
34
- //# sourceMappingURL=big-radio-group.js.map
@@ -1,30 +0,0 @@
1
- import { ProxyFormField } from "../fields/proxy-field.js";
2
- import { CheckboxWithValue } from "./checkbox.js";
3
- import { FieldGroup } from "./field-group.js";
4
- import { FormFieldControl } from "./form-field-control.js";
5
- export class CheckboxGroup extends FormFieldControl {
6
- constructor(field, options = {}) {
7
- super([field]);
8
- this.field = field;
9
- this.options = options;
10
- }
11
- wrapGroup(fctx, checkboxes) {
12
- return new FieldGroup(checkboxes, {
13
- label: this.options.label,
14
- classes: [
15
- ...(this.options.classes || []),
16
- "field-group--checkboxes",
17
- ],
18
- }).render(fctx);
19
- }
20
- async render(fctx) {
21
- const { parsed: values } = await this.field.getValue(fctx.ctx, fctx.data);
22
- const checkboxes = this.field.options.map((option) => new CheckboxWithValue(new ProxyFormField(false, this.field.name, false, values.includes(option)), {
23
- id: this.field.name + "__" + option,
24
- label: (this.options.checkboxNameToLabel ||
25
- ((s) => s))(option),
26
- }, option));
27
- return this.wrapGroup(fctx, checkboxes);
28
- }
29
- }
30
- //# sourceMappingURL=checkbox-group.js.map
@@ -1,24 +0,0 @@
1
- import { Tickable } from "./tickable.js";
2
- export class Checkbox extends Tickable {
3
- constructor() {
4
- super(...arguments);
5
- this.type = "checkbox";
6
- }
7
- isChecked(_ctx, _data, value) {
8
- return value;
9
- }
10
- getValueAttribute() {
11
- return "";
12
- }
13
- }
14
- export class CheckboxWithValue extends Checkbox {
15
- constructor(field, options, value) {
16
- super(field, options);
17
- this.field = field;
18
- this.value = value;
19
- }
20
- getValueAttribute() {
21
- return this.value;
22
- }
23
- }
24
- //# sourceMappingURL=checkbox.js.map
@@ -1,35 +0,0 @@
1
- import { is, predicates } from "@sealcode/ts-predicates";
2
- import { tempstream } from "tempstream";
3
- import { getRequiredClass, inputWrapper } from "../../utils/input-wrapper.js";
4
- import { FormFieldControl } from "./form-field-control.js";
5
- export class CheckboxedListInput extends FormFieldControl {
6
- constructor(field, options = { label: field.name }) {
7
- super([field]);
8
- this.field = field;
9
- this.options = options;
10
- }
11
- async render(fctx) {
12
- const { parsed: pickedValues } = await this.field.getValue(fctx.ctx, fctx.data);
13
- if (!is(pickedValues, predicates.array(predicates.string))) {
14
- throw new Error("picked values is not an array of strings");
15
- }
16
- const [options, isVisible] = await Promise.all([
17
- this.field.generateOptions(fctx.ctx),
18
- this.field.isVisible(fctx.ctx),
19
- ]);
20
- const { name, required } = this.field;
21
- return tempstream /* HTML */ `${isVisible
22
- ? Object.entries(options).map(([value, text]) => inputWrapper([name, getRequiredClass(required)],
23
- /* HTML */ `
24
- <input
25
- type="checkbox"
26
- id="${name}.${value}"
27
- name="${name}.${value}"
28
- ${pickedValues.includes(value) ? "checked" : ""}
29
- />
30
- <label for="${name}.${value}">${text}</label>
31
- `))
32
- : ""}`;
33
- }
34
- }
35
- //# sourceMappingURL=checkboxed-list-input.js.map
@@ -1,13 +0,0 @@
1
- import { CheckboxGroup } from "./checkbox-group.js";
2
- import { CollapsibleFieldGroup } from "./collapsible-field-group.js";
3
- export class CollapsibleCheckboxGroup extends CheckboxGroup {
4
- wrapGroup(fctx, checkboxes) {
5
- return new CollapsibleFieldGroup(checkboxes, {
6
- label: this.options.label,
7
- textWhenOpen: this.options.textWhenOpen,
8
- textWhenClosed: this.options.textWhenClosed,
9
- groupID: this.options.groupID,
10
- }).render(fctx);
11
- }
12
- }
13
- //# sourceMappingURL=collapsible-checkbox-group.js.map
@@ -1,78 +0,0 @@
1
- import { FieldGroup } from "./field-group.js";
2
- import { randomUUID } from "crypto";
3
- export class CollapsibleFieldGroup extends FieldGroup {
4
- constructor(controls, options = {}) {
5
- super([]);
6
- this.controls = controls;
7
- this.options = options;
8
- if (this.options.groupID == undefined) {
9
- this.options.groupID = "A" + randomUUID(); // "A" is needed as ids always have to start with a letter
10
- }
11
- this.collapseID = this.options.groupID + "collapse";
12
- }
13
- getGroupLabelProps() {
14
- return super.getGroupLabelProps() + ` for="${this.collapseID}"`;
15
- }
16
- preLabelContainer() {
17
- return /* HTML */ `<style>
18
- input#${this.collapseID} {
19
- display: none;
20
- }
21
-
22
- input#${this.collapseID} ~ .field-group__fields {
23
- display: none;
24
- }
25
-
26
- input#${this.collapseID}:checked ~ .field-group__fields {
27
- display: block;
28
- }
29
-
30
- input#${this.collapseID}
31
- ~ .field-group__label-container
32
- .field-group__collapse-label-text--open {
33
- display: none;
34
- }
35
-
36
- input#${this.collapseID}:checked
37
- ~ .field-group__label-container
38
- .field-group__collapse-label-text--open {
39
- display: inline-block;
40
- }
41
-
42
- input#${this.collapseID}
43
- ~ .field-group__label-container
44
- .field-group__collapse-label-text--closed {
45
- display: inline-block;
46
- }
47
-
48
- input#${this.collapseID}:checked
49
- ~ .field-group__label-container
50
- .field-group__collapse-label-text--closed {
51
- display: none;
52
- }
53
- </style>
54
- <input
55
- type="checkbox"
56
- id="${this.collapseID}"
57
- ${this.options.openOnStart ? "checked" : ""}
58
- />`;
59
- }
60
- postLabel() {
61
- return /* HTML */ `<label
62
- class="field-group__collapse-label"
63
- for="${this.collapseID}"
64
- >
65
- <span
66
- class="field-group__collapse-label-text field-group__collapse-label-text--open"
67
- >
68
- ${this.options.textWhenOpen || "close"}
69
- </span>
70
- <span
71
- class="field-group__collapse-label-text field-group__collapse-label-text--closed"
72
- >
73
- ${this.options.textWhenClosed || "open"}
74
- </span>
75
- </label>`;
76
- }
77
- }
78
- //# sourceMappingURL=collapsible-field-group.js.map
@@ -1,31 +0,0 @@
1
- export { FormControl } from "./form-control.js";
2
- export { FormFieldControl } from "./form-field-control.js";
3
- export { EditableCollectionSubset } from "./editable-collection-subset.js";
4
- export { Frame } from "./frame.js";
5
- export { CheckboxedListInput } from "./checkboxed-list-input.js";
6
- export * from "./dropdown.js";
7
- export { SimpleInput } from "./simple-input.js";
8
- export { FormHeader } from "./form-header.js";
9
- export { FormParagraph } from "./form-paragraph.js";
10
- export { HTML } from "./html.js";
11
- export { HiddenInput } from "./hidden-input.js";
12
- export { Textarea } from "./textarea.js";
13
- export { FieldGroup } from "./field-group.js";
14
- export * from "./derived.js";
15
- export * from "./derived-frame.js";
16
- export * from "./tickable.js";
17
- export * from "./checkbox.js";
18
- export * from "./radio.js";
19
- export * from "./big-radio-group.js";
20
- export * from "./checkbox-group.js";
21
- export * from "./collapsible-field-group.js";
22
- export * from "./collapsible-checkbox-group.js";
23
- export * from "./autocomplete.js";
24
- export * from "./file.js";
25
- export * from "./photo.js";
26
- export * from "./multiple-files.js";
27
- export * from "./number.js";
28
- export * from "./multiple-photos.js";
29
- // export * from "./reverse-single-reference";
30
- export * from "./array.js";
31
- //# sourceMappingURL=controls.js.map
@@ -1,52 +0,0 @@
1
- import { hasShape, predicates } from "@sealcode/ts-predicates";
2
- import { tempstream } from "tempstream";
3
- import { makeSlug } from "../../utils/make-slug.js";
4
- import { Derived } from "./derived.js";
5
- import { FormControlContext } from "./form-control.js";
6
- export class DerivedFrame extends Derived {
7
- constructor(frame_name, fields, generateFrameContent,
8
- // "a" is to make it a valid DOM id
9
- frame_id = "a" + makeSlug(frame_name)) {
10
- super(fields, async (values, consts) => /* HTML */ `<turbo-frame
11
- id="${consts.frame_id}"
12
- src="./${consts.frame_id}?${Object.entries({
13
- ...consts,
14
- ...(values || {}),
15
- })
16
- .map(([key, value]) => `${key}=${value}`)
17
- .join("&")}"
18
- ></turbo-frame>`, async (fctx) => ({
19
- form_id: fctx.form_id,
20
- field_name_prefix: fctx.field_name_prefix,
21
- frame_id,
22
- validate: fctx.validate,
23
- }));
24
- this.frame_name = frame_name;
25
- this.generateFrameContent = generateFrameContent;
26
- this.frame_id = frame_id;
27
- }
28
- renderBackendResponseFrame(_ctx, content) {
29
- return tempstream /* HTML */ `<turbo-frame
30
- id="${this.frame_id}"
31
- target="_top"
32
- >
33
- ${content || ""}
34
- </turbo-frame>`;
35
- }
36
- mount(router) {
37
- router.get(this.frame_id, async (ctx) => {
38
- const query = ctx.query;
39
- if (!hasShape({
40
- field_name_prefix: predicates.string,
41
- form_id: predicates.string,
42
- validate: predicates.string,
43
- }, query)) {
44
- ctx.body = this.renderBackendResponseFrame(ctx, "Missing query params");
45
- return;
46
- }
47
- ctx.body = this.renderBackendResponseFrame(ctx, await this.generateFrameContent(new FormControlContext(ctx, ctx.query, [], query.field_name_prefix, query.form_id, query.validate === "true" ? true : false), ctx.query));
48
- });
49
- return;
50
- }
51
- }
52
- //# sourceMappingURL=derived-frame.js.map
@@ -1,77 +0,0 @@
1
- import { randomUUID } from "crypto";
2
- import { tempstream } from "tempstream";
3
- import { FormControl } from "./form-control.js";
4
- export class Derived extends FormControl {
5
- constructor(fields, _render, getConsts = async () => ({})) {
6
- super();
7
- this.fields = fields;
8
- this._render = _render;
9
- this.getConsts = getConsts;
10
- this.role = "decoration";
11
- }
12
- async getBackendValues(fctx) {
13
- const fieldnames = this.fields.map((f) => f.name);
14
- const result = Object.fromEntries(Object.entries(fctx.data).filter(([key]) => fieldnames.includes(key)));
15
- return result;
16
- }
17
- async render(fctx) {
18
- // the A makes it always a valid id, as it cannot start with a number
19
- const id = "A" + randomUUID();
20
- const consts = this.getConsts(fctx);
21
- const frontend_side_refresh_code = (values_code = "getValues()") => `render(${values_code}, consts)
22
- .then(result=>document.querySelector("#${id}").innerHTML=result)`;
23
- return tempstream /* HTML */ `<div>
24
- <script>
25
- (function () {
26
- const consts = ${"{" +
27
- Object.entries((await consts) || {})
28
- .map(([key, value]) => {
29
- return `"${key}": ${typeof value === "object"
30
- ? JSON.stringify(value)
31
- : typeof value == "string"
32
- ? '"' + value.toString() + '"'
33
- : value.toString()}`;
34
- })
35
- .join(",") +
36
- "}"};
37
- const form_container =
38
- document.currentScript.closest(".form-container");
39
- const render = ${this._render.toString()};
40
- function getValues() {
41
- return Object.fromEntries(
42
- ${JSON.stringify(this.fields.map((field) => field.name))}.map((field_name) => {
43
- let input = form_container.querySelector(
44
- \`input[name="\${field_name}"]\`
45
- );
46
- if (!input) {
47
- return [field_name, ""];
48
- }
49
- if (input.type === "radio") {
50
- input = form_container.querySelector(
51
- \`input[name="\${field_name}"]:checked\`
52
- );
53
- }
54
- return [field_name, input.value];
55
- })
56
- );
57
- }
58
- function setupWatcher(field_name) {
59
- form_container
60
- .querySelectorAll(\`input[name="\${field_name}"]\`)
61
- .forEach((input) => {
62
- input.addEventListener("change", () => {
63
- ${frontend_side_refresh_code()};
64
- });
65
- });
66
- }
67
- ${JSON.stringify(this.fields.map((field) => field.name))}.forEach(setupWatcher);
68
- setTimeout(() => {
69
- ${frontend_side_refresh_code(JSON.stringify(await this.getBackendValues(fctx)))};
70
- }, 0);
71
- })();
72
- </script>
73
- <div id="${id}">${this._render({}, await consts)}</div>
74
- </div>`;
75
- }
76
- }
77
- //# sourceMappingURL=derived.js.map
@@ -1,55 +0,0 @@
1
- import { tempstream } from "tempstream";
2
- import { attribute } from "../../sanitize.js";
3
- import { SimpleInput } from "./simple-input.js";
4
- export class FreeformDropdown extends SimpleInput {
5
- constructor(field, _generateOptions, options = {
6
- label: field.name,
7
- autosubmit: false,
8
- autocomplete: true,
9
- }) {
10
- super(field, options);
11
- this.field = field;
12
- this._generateOptions = _generateOptions;
13
- this.options = options;
14
- }
15
- async generateOptions(ctx) {
16
- return this._generateOptions(ctx);
17
- }
18
- async getInputAttributes(fctx) {
19
- const original = await super.getInputAttributes(fctx);
20
- return {
21
- ...original,
22
- ...Object.fromEntries([
23
- ...(this.options.autosubmit
24
- ? [
25
- [
26
- "onchange",
27
- (original.onchange || "") +
28
- ";this.form.submit();",
29
- ],
30
- ]
31
- : []),
32
- ]),
33
- };
34
- }
35
- async renderInput(ctx, attributes_str, data) {
36
- const { parsed: picked_value } = await this.field.getValue(ctx, data);
37
- return /* HTML */ tempstream `<select ${attributes_str}>
38
- ${
39
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
40
- Promise.resolve(this.generateOptions(ctx)).then((options) => options.map(({ value, label }) => `<option value="${attribute(value)}" ${(value || "") == picked_value ? "selected" : ""}>${label}</option>`))}
41
- </select>`;
42
- }
43
- }
44
- export class Dropdown extends FreeformDropdown {
45
- constructor(field, options = {
46
- label: field.name,
47
- autosubmit: false,
48
- autocomplete: true,
49
- }) {
50
- super(field, (ctx) => field.generateOptions(ctx), options);
51
- this.field = field;
52
- this.options = options;
53
- }
54
- }
55
- //# sourceMappingURL=dropdown.js.map
@@ -1,68 +0,0 @@
1
- import { tempstream } from "tempstream";
2
- import { attribute } from "../../sanitize.js";
3
- import { FormFieldControl } from "./form-field-control.js";
4
- /**
5
- * This control has own forms in it so if you want to use it you
6
- * probably shouldn't use `await super.render(ctx, data, path)` in
7
- * render method of you from implementation and you should write
8
- * your own implementation of this method. See forms that uses
9
- * this control for reference.
10
- */
11
- export class EditableCollectionSubset extends FormFieldControl {
12
- constructor(field, actionname, listLabel, selectLabel) {
13
- super([field]);
14
- this.field = field;
15
- this.actionname = actionname;
16
- this.listLabel = listLabel;
17
- this.selectLabel = selectLabel;
18
- this.role = "input";
19
- }
20
- async render(fctx) {
21
- const { parsed: values } = await this.field.getValue(fctx.ctx, fctx.data);
22
- return tempstream /* HTML */ `<div>
23
- <ul>
24
- ${Promise.resolve(this.field.generateOptions(fctx.ctx)).then((options) => Object.entries(options)
25
- .filter(([value]) => (values || []).includes(value))
26
- .map(([value, text]) => /* HTML */ `
27
- <li>
28
- <form
29
- method="POST"
30
- action="${fctx.ctx.path}"
31
- >
32
- <span>${text}</span>
33
- <input
34
- type="hidden"
35
- name="${this.field.name}"
36
- value="${attribute(value)}"
37
- />
38
- <input
39
- type="hidden"
40
- name="${this.actionname}"
41
- value="list"
42
- />
43
- <input
44
- type="submit"
45
- ${this.listLabel
46
- ? `value="${this.listLabel}"`
47
- : ""}
48
- />
49
- </form>
50
- </li>
51
- `))}
52
- </ul>
53
- <form method="POST" action="${fctx.ctx.path}">
54
- <select name="${this.field.name}">
55
- ${Promise.resolve(this.field.generateOptions(fctx.ctx)).then((options) => Object.entries(options)
56
- .filter(([value]) => !(values || []).includes(value))
57
- .map(([value, text]) => `<option value="${attribute(value)}">${text}</option>`))}
58
- </select>
59
- <input type="hidden" name="${this.actionname}" value="select" />
60
- <input
61
- type="submit"
62
- ${this.selectLabel ? `value="${this.selectLabel}"` : ""}
63
- />
64
- </form>
65
- </div>`;
66
- }
67
- }
68
- //# sourceMappingURL=editable-collection-subset.js.map