@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,53 +0,0 @@
1
- import { tempstream } from "tempstream";
2
- import { FormFieldControl } from "./form-field-control.js";
3
- export class FieldGroup extends FormFieldControl {
4
- constructor(controls, options = {}) {
5
- super([]);
6
- this.controls = controls;
7
- this.options = options;
8
- }
9
- preLabel() {
10
- return "";
11
- }
12
- preLabelContainer() {
13
- return "";
14
- }
15
- postLabel() {
16
- return "";
17
- }
18
- preFields() {
19
- return "";
20
- }
21
- postFields() {
22
- return "";
23
- }
24
- getGroupLabelProps() {
25
- return `class="field-group__label"`;
26
- }
27
- async render(fctx) {
28
- const { label, classes } = this.options;
29
- return tempstream /* HTML */ `
30
- <div
31
- class="field-group ${(classes || []).join(" ")}"
32
- ${this.options.containerID
33
- ? `id="${this.options.containerID}"`
34
- : ""}
35
- >
36
- ${this.preLabelContainer()}
37
- <div class="field-group__label-container">
38
- ${this.preLabel()}
39
- ${label
40
- ? `<label ${this.getGroupLabelProps()}>${label}</label>`
41
- : ""}
42
- ${this.postLabel()}
43
- </div>
44
- ${this.preFields()}
45
- <div class="field-group__fields">
46
- ${this.controls.map((control) => control.render(fctx))}
47
- </div>
48
- ${this.postFields()}
49
- </div>
50
- `;
51
- }
52
- }
53
- //# sourceMappingURL=field-group.js.map
@@ -1,35 +0,0 @@
1
- import { tempstream } from "tempstream";
2
- import { SimpleInput } from "./simple-input.js";
3
- export class File extends SimpleInput {
4
- getType() {
5
- return "file";
6
- }
7
- async renderFilePreview(_ctx, file_data) {
8
- return file_data?.filename || "";
9
- }
10
- async preInput(ctx, data) {
11
- const { parsed } = await this.field.getValue(ctx, data);
12
- return tempstream /* HTML */ `${this.renderFilePreview(ctx, parsed.old)}
13
- <input
14
- type="hidden"
15
- name="${this.field.name}[old][id]"
16
- value="${parsed.old?.id || ""}"
17
- />
18
- <input
19
- type="hidden"
20
- name="${this.field.name}[old][filename]"
21
- value="${parsed.old?.filename || ""}"
22
- />`;
23
- }
24
- async getInputAttributes(fctx) {
25
- const original = await super.getInputAttributes(fctx);
26
- const { parsed } = await this.field.getValue(fctx.ctx, fctx.data);
27
- return {
28
- ...original,
29
- name: this.field.name + "[new]",
30
- required: original.required && !parsed.old,
31
- value: false,
32
- };
33
- }
34
- }
35
- //# sourceMappingURL=file.js.map
@@ -1,14 +0,0 @@
1
- export class FormControlContext {
2
- constructor(ctx, data, messages, field_name_prefix, form_id, validate) {
3
- this.ctx = ctx;
4
- this.data = data;
5
- this.messages = messages;
6
- this.field_name_prefix = field_name_prefix;
7
- this.form_id = form_id;
8
- this.validate = validate;
9
- }
10
- }
11
- export class FormControl {
12
- mount(router) { }
13
- }
14
- //# sourceMappingURL=form-control.js.map
@@ -1,9 +0,0 @@
1
- import { FormControl } from "./form-control.js";
2
- export class FormFieldControl extends FormControl {
3
- constructor(fields) {
4
- super();
5
- this.fields = fields;
6
- this.role = "input";
7
- }
8
- }
9
- //# sourceMappingURL=form-field-control.js.map
@@ -1,14 +0,0 @@
1
- import { FormControl } from "./form-control.js";
2
- export class FormHeader extends FormControl {
3
- constructor(text, isVisible = async () => true) {
4
- super();
5
- this.text = text;
6
- this.isVisible = isVisible;
7
- this.role = "decoration";
8
- }
9
- async render(fctx) {
10
- const isVsbl = await this.isVisible(fctx);
11
- return isVsbl ? `<h2>${this.text}</h2>` : "";
12
- }
13
- }
14
- //# sourceMappingURL=form-header.js.map
@@ -1,12 +0,0 @@
1
- import { FormControl } from "./form-control.js";
2
- export class FormParagraph extends FormControl {
3
- constructor(text) {
4
- super();
5
- this.text = text;
6
- this.role = "decoration";
7
- }
8
- render() {
9
- return `<p>${this.text}</p>`;
10
- }
11
- }
12
- //# sourceMappingURL=form-paragraph.js.map
@@ -1,25 +0,0 @@
1
- import { FormControl } from "./form-control.js";
2
- /**
3
- * This class will render `turbo-frame` tag so that u can
4
- * embed other route inside your form. This will require
5
- * to add value to `data: FormData` (inside your master form
6
- * render function) with key `Frame.FRAME_PATH_KEY`. Value
7
- * needs to be url to route that you want to embed. If you
8
- * this value wont be provided frame will redner empty string.
9
- * See `src/back/routes/profile/[id].form.ts` for an example.
10
- */
11
- export class Frame extends FormControl {
12
- constructor(src) {
13
- super();
14
- this.src = src;
15
- this.role = "decoration";
16
- }
17
- render() {
18
- return /* HTML */ `<turbo-frame
19
- id="contrahents"
20
- loading="lazy"
21
- src="${this.src}"
22
- ></turbo-frame>`;
23
- }
24
- }
25
- //# sourceMappingURL=frame.js.map
@@ -1,14 +0,0 @@
1
- import { tempstream } from "tempstream";
2
- import { attribute } from "../../sanitize.js";
3
- import { FormFieldControl } from "./form-field-control.js";
4
- export class HiddenInput extends FormFieldControl {
5
- constructor(field) {
6
- super([field]);
7
- this.field = field;
8
- }
9
- async render(fctx) {
10
- const { raw } = await this.field.getValue(fctx.ctx, fctx.data);
11
- return tempstream `<input type="hidden" name="${this.field.name}" value="${attribute((raw || "").toString())}" form="${fctx.form_id}">`;
12
- }
13
- }
14
- //# sourceMappingURL=hidden-input.js.map
@@ -1,23 +0,0 @@
1
- import { FormControl } from "./form-control.js";
2
- export class HTML extends FormControl {
3
- constructor(role_or_renderer, renderer_or_undefined) {
4
- super();
5
- this.role = "decoration";
6
- if (arguments.length == 2) {
7
- this.role = role_or_renderer;
8
- this.renderer = renderer_or_undefined;
9
- }
10
- else {
11
- this.renderer = role_or_renderer;
12
- }
13
- }
14
- async render(fctx) {
15
- if (typeof this.renderer === "string") {
16
- return this.renderer;
17
- }
18
- return typeof this.renderer == "function"
19
- ? this.renderer(fctx)
20
- : this.renderer;
21
- }
22
- }
23
- //# sourceMappingURL=html.js.map
@@ -1,160 +0,0 @@
1
- import { File as SealiousFile, } from "sealious";
2
- import { inputWrapper } from "../../utils/input-wrapper.js";
3
- import { tempstream } from "tempstream";
4
- import { FormFieldControl } from "./form-field-control.js";
5
- import { is, predicates } from "@sealcode/ts-predicates";
6
- import { renderAttributes } from "../../utils/render-attributes.js";
7
- export class MultipleFiles extends FormFieldControl {
8
- constructor(field, options) {
9
- super([field]);
10
- this.field = field;
11
- this.options = { getAdditionalFields: async () => ({}), ...options };
12
- }
13
- getClassModifiers() {
14
- return [];
15
- }
16
- mount(router) {
17
- router.get(this.getFrameRelativeURL(), async (ctx) => {
18
- ctx.body = this.renderFrame(ctx, await this.renderFrameContent(ctx));
19
- });
20
- router.post(this.getFrameRelativeURL() + "/delete/:file_item_id", async (ctx) => {
21
- await this.deleteFileAssociation(ctx, ctx.params.file_item_id);
22
- ctx.body = this.renderFrame(ctx, await this.renderFrameContent(ctx));
23
- });
24
- router.post(this.getFrameRelativeURL() + "/add", async (ctx) => {
25
- let files = ctx.$body.files;
26
- if (!files || !is(files, predicates.object)) {
27
- ctx.body = "Missing files";
28
- return;
29
- }
30
- if (!Array.isArray(files)) {
31
- files = [files];
32
- }
33
- await Promise.all(files.map((file) => this.addFileAssociation(ctx, file)));
34
- ctx.body = this.renderFrame(ctx, await this.renderFrameContent(ctx));
35
- });
36
- }
37
- async deleteFileAssociation(ctx, file_item_id) {
38
- await ctx.$app.collections[this.field.collection_field.referencing_collection].removeByID(ctx.$context, file_item_id);
39
- }
40
- async addFileAssociation(ctx, file) {
41
- const file_field = this.getFileField();
42
- if (!file_field) {
43
- throw new Error("No file field in referencing collection");
44
- }
45
- const body = {
46
- ...(await this.options.getAdditionalFields(ctx, file)),
47
- [this.field.collection_field.referencing_field]: await this.field.getItemId(ctx),
48
- [file_field.name]: file,
49
- };
50
- await ctx.$app.collections[this.field.collection_field.referencing_collection].create(ctx.$context, body);
51
- }
52
- getFrameRelativeURL() {
53
- return `${this.field.name}_files`;
54
- }
55
- getFrameID() {
56
- // the "A" is necessary here
57
- return `A${this.field.name}__multiple-fields-control`;
58
- }
59
- renderFrame(ctx, content) {
60
- return tempstream /* HTML */ `<turbo-frame
61
- ${content ? "" : `src="./${this.getFrameRelativeURL()}"`}
62
- id="${this.getFrameID()}"
63
- target="_top"
64
- >
65
- ${content || ""}
66
- </turbo-frame>`;
67
- }
68
- render(fctx) {
69
- return this.renderFrame(fctx.ctx, "");
70
- }
71
- getReferencingCollection() {
72
- const result = this.field.collection_field.app.collections[this.field.collection_field.referencing_collection];
73
- return result;
74
- }
75
- getFileField() {
76
- for (const [_, field] of Object.entries(this.getReferencingCollection().fields)) {
77
- if (field.handles_large_data) {
78
- return field;
79
- }
80
- }
81
- return null;
82
- }
83
- async extractFileFromItem(item) {
84
- const sealious_field = this.getFileField();
85
- if (!sealious_field) {
86
- return null;
87
- }
88
- return await SealiousFile.fromID(item.collection.app, item.get(sealious_field.name).id);
89
- }
90
- async renderFileItemPreview(_fileItem, file) {
91
- return file.filename || "no filename";
92
- }
93
- async renderFileItem(fileItem, file) {
94
- return tempstream /* HTML */ `<li class="file-list-item">
95
- <a
96
- class="file-list-item__preview"
97
- href="${file.getURL()}"
98
- data-turbo="false"
99
- >
100
- ${this.renderFileItemPreview(fileItem, file)}
101
- </a>
102
- ${this.renderFileRemoveButton(fileItem)}
103
- </li>`;
104
- }
105
- renderFileRemoveButton(fileItem) {
106
- return /* HTML */ ` <form
107
- data-turbo-frame="${this.getFrameID()}"
108
- action="${this.getFrameRelativeURL()}/delete/${fileItem.id}"
109
- method="POST"
110
- >
111
- <input
112
- type="submit"
113
- value="X"
114
- class="file-list-action file-list-item__button file-list-item__button--delete"
115
- />
116
- </form>`;
117
- }
118
- async getFileItems(ctx) {
119
- const item_id = await this.field.getItemId(ctx);
120
- const { items: [item], } = await this.field.collection_field.collection
121
- .list(ctx.$context)
122
- .ids([item_id])
123
- .attach({ [this.field.collection_field.name]: true })
124
- .fetch();
125
- return item
126
- .getAttachments(this.field.collection_field.name)
127
- .filter((f) => f);
128
- }
129
- getInputAttributes() {
130
- return { type: "file", name: "files", multiple: true };
131
- }
132
- async renderFrameContent(ctx) {
133
- const files = (await Promise.all((await this.getFileItems(ctx))
134
- .filter((item) => item) // filter out undefineds
135
- .map(async (item) => [
136
- item,
137
- await this.extractFileFromItem(item),
138
- ]))).filter(([_, f]) => f !== null);
139
- return inputWrapper(["multiple-files", this.field.name, ...this.getClassModifiers()], tempstream /* HTML */ `
140
- <label>${this.options.label || this.field.name}</label>
141
- <ul class="multiple-files__list">
142
- ${files.map(([item, file]) => this.renderFileItem(item, file))}
143
- </ul>
144
- <form
145
- action="${this.getFrameRelativeURL()}/add"
146
- method="POST"
147
- enctype="multipart/form-data"
148
- data-turbo-frame="${this.getFrameID()}"
149
- >
150
- <input ${renderAttributes(this.getInputAttributes())} />
151
- <input
152
- type="submit"
153
- value="${this.options.uploadLabel || "Upload"}"
154
- class="file-list-action"
155
- />
156
- </form>
157
- `);
158
- }
159
- }
160
- //# sourceMappingURL=multiple-files.js.map
@@ -1,33 +0,0 @@
1
- import { tempstream } from "tempstream";
2
- import { MultipleFiles } from "./multiple-files.js";
3
- export class MultiplePhotos extends MultipleFiles {
4
- constructor(field, imageRouter, options) {
5
- super(field, options);
6
- this.field = field;
7
- this.imageRouter = imageRouter;
8
- }
9
- getClassModifiers() {
10
- return ["multiple-files--photos"];
11
- }
12
- getInputAttributes() {
13
- return { ...super.getInputAttributes(), accept: "image/*" };
14
- }
15
- async renderFileItem(fileItem, file) {
16
- const path = file.getDataPath();
17
- if (!path) {
18
- return "missing file";
19
- }
20
- return tempstream /* HTML */ `<li>
21
- <a href="${file.getURL()}" data-turbo="false">
22
- ${this.imageRouter.image({
23
- path,
24
- resolutions: [150, 300],
25
- sizes_attr: "150px",
26
- })}
27
- </a>
28
- <span class="filename"> ${file.filename || "no filename"}</span>
29
- ${this.renderFileRemoveButton(fileItem)}
30
- </li>`;
31
- }
32
- }
33
- //# sourceMappingURL=multiple-photos.js.map
@@ -1,25 +0,0 @@
1
- import { SimpleInput } from "./simple-input.js";
2
- export class Number extends SimpleInput {
3
- constructor(field, options) {
4
- super(field, options);
5
- }
6
- getType() {
7
- return "number";
8
- }
9
- async getInputAttributes(fctx) {
10
- const original = await super.getInputAttributes(fctx);
11
- return {
12
- ...original,
13
- ...Object.fromEntries([
14
- ...(this.field.options.min
15
- ? [["min", this.field.options.min]]
16
- : []),
17
- ...(this.field.options.max
18
- ? [["max", this.field.options.max]]
19
- : []),
20
- ...(this.options.step ? [["step", this.options.step]] : []),
21
- ]),
22
- };
23
- }
24
- }
25
- //# sourceMappingURL=number.js.map
@@ -1,57 +0,0 @@
1
- import { tempstream } from "tempstream";
2
- import { File } from "./file.js";
3
- import { File as SealiousFile } from "sealious";
4
- export class Photo extends File {
5
- constructor(field, imageRouter, options) {
6
- super(field, options);
7
- this.field = field;
8
- this.imageRouter = imageRouter;
9
- }
10
- async getImgStyle() {
11
- return "width: 100px; height: 100px; object-fit: contain";
12
- }
13
- async renderFilePreview(ctx, file_data) {
14
- const class_name = "file_preview";
15
- const empty_container = `<div class="${class_name}"></div>`;
16
- if (!file_data) {
17
- return empty_container;
18
- }
19
- const { id } = file_data;
20
- if (!id) {
21
- return empty_container;
22
- }
23
- const file = await SealiousFile.fromID(ctx.$app, id);
24
- return tempstream /* HTML */ `<div class="${class_name}">
25
- ${this.imageRouter.image({
26
- resolutions: [100],
27
- sizes_attr: "100px",
28
- path: file.getDataPath(),
29
- img_style: await this.getImgStyle(),
30
- })}
31
- </div>`;
32
- }
33
- async getInputAttributes(fctx) {
34
- const original = (await super.getInputAttributes(fctx));
35
- const { parsed } = await this.field.getValue(fctx.ctx, fctx.data);
36
- return {
37
- ...original,
38
- accept: "image/*",
39
- onchange: (original.onchange || "") +
40
- ";" +
41
- `
42
- const file = this.files[0];
43
- const preview_container = this.parentElement.querySelector(".file_preview");
44
- const target = this;
45
- if (file) {
46
- const fileReader = new FileReader();
47
- fileReader.readAsDataURL(file);
48
- fileReader.addEventListener("load", function () {
49
- preview_container.innerHTML = \`<img src="\${this.result}" style="${await this.getImgStyle()}" />\`;
50
- });
51
- }`
52
- .replaceAll("\n", " ")
53
- .replaceAll(`"`, "'"),
54
- };
55
- }
56
- }
57
- //# sourceMappingURL=photo.js.map
@@ -1,25 +0,0 @@
1
- import { Tickable } from "./tickable.js";
2
- export class Radio extends Tickable {
3
- constructor(field, value, options) {
4
- super(field, options);
5
- this.field = field;
6
- this.value = value;
7
- this.type = "radio";
8
- }
9
- makeInputID() {
10
- return this.field.name + "-" + this.value.replaceAll(/\W/g, "-");
11
- }
12
- getValueAttribute() {
13
- return this.value;
14
- }
15
- getWrapperClasses(ctx, data, value) {
16
- return [
17
- ...super.getWrapperClasses(ctx, data, value),
18
- this.value.replaceAll(/\W/g, "-"),
19
- ];
20
- }
21
- isChecked(_ctx, _data, value) {
22
- return this.value === value;
23
- }
24
- }
25
- //# sourceMappingURL=radio.js.map
@@ -1,47 +0,0 @@
1
- // import { FormControl } from "./form-control";
2
- // import { FormFieldControl } from "./form-field-control";
3
- // import { ReverseSingleReference as ReverseSingleReferenceField } from "../fields/field";
4
- // import { Context } from "koa";
5
- // import { Fields } from "../..";
6
- // import { ArrayControl } from "./array";
7
- export {};
8
- // export class ReverseSingleReference extends ArrayControl {
9
- // //
10
- // //
11
- // // this isn't finished yet
12
- // //
13
- // //
14
- // constructor(
15
- // public field: ReverseSingleReferenceField,
16
- // public item_controls: Array<FormControl | UnboundControlStorage>
17
- // ) {
18
- // super(field, item_controls);
19
- // }
20
- // async getItems(ctx: Context) {
21
- // const target_id = await this.getTargetItemID(ctx);
22
- // const { items } = await this.field.sealious_field
23
- // .getReferencingCollection()
24
- // .list(ctx.$context)
25
- // .filter({
26
- // [this.field.sealious_field.referencing_field]: target_id,
27
- // })
28
- // .fetch();
29
- // return items;
30
- // }
31
- // makeSubfield(fieldname: string) {
32
- // const collection = this.field.sealious_field.getReferencingCollection();
33
- // if (!collection.fields[fieldname]) {
34
- // return null;
35
- // }
36
- // return new Fields.CollectionField(false, collection.fields[fieldname]);
37
- // }
38
- // async add(ctx: Context): Promise<void> {
39
- // const collection = this.field.sealious_field.getReferencingCollection();
40
- // await collection.create(ctx.$context, {
41
- // [this.field.sealious_field.referencing_field]:
42
- // await this.getTargetItemID(ctx),
43
- // ...(await this.getDefaultItemBody()),
44
- // });
45
- // }
46
- // }
47
- //# sourceMappingURL=reverse-single-reference.js.map
@@ -1,78 +0,0 @@
1
- import { tempstream } from "tempstream";
2
- import { getRequiredClass, inputWrapper } from "../../utils/input-wrapper.js";
3
- import { renderAttributes } from "../../utils/render-attributes.js";
4
- import { FormFieldControl } from "./form-field-control.js";
5
- export class SimpleInput extends FormFieldControl {
6
- constructor(field, options) {
7
- super([field]);
8
- this.field = field;
9
- this.options = options || {};
10
- }
11
- async preInput(_ctx, _data) {
12
- return "";
13
- }
14
- getType() {
15
- return this.options.type || "text";
16
- }
17
- getLabel() {
18
- return this.options.label != undefined
19
- ? this.options.label
20
- : this.field.name;
21
- }
22
- getID() {
23
- return this.options.id || this.field.name;
24
- }
25
- getPlaceholder() {
26
- return this.options.placeholder === ""
27
- ? ""
28
- : this.options.placeholder || this.getType();
29
- }
30
- async getInputAttributes(fctx) {
31
- const readonly = this.options.readonly || false;
32
- const required = this.field.required;
33
- const { parsed, raw, valid } = await this.field.getValue(fctx.ctx, fctx.data);
34
- return Object.fromEntries([
35
- ["id", this.getID()],
36
- ["type", this.getType()],
37
- ["name", `${fctx.field_name_prefix}${this.field.name}`],
38
- [
39
- "value",
40
- !valid && raw
41
- ? raw.toString()
42
- : parsed !== undefined && parsed !== null
43
- ? parsed?.toString() || ""
44
- : "",
45
- ],
46
- ...(fctx.form_id ? [["form", fctx.form_id]] : []),
47
- ["placeholder", this.getPlaceholder()],
48
- ...(readonly ? [["readonly", true]] : []),
49
- ...(required ? [["required", true]] : []),
50
- ...(!this.options.autocomplete ? [["autocomplete", "off"]] : []),
51
- ...(this.options.step ? [["step", this.options.step]] : []),
52
- ]);
53
- }
54
- async postInput(_) {
55
- return this.options.suffix
56
- ? /* HTML */ `<span class="suffix">${this.options.suffix}</span>`
57
- : "";
58
- }
59
- async renderInput(_ctx, attributes_str, _data) {
60
- return `<input ${attributes_str} />`;
61
- }
62
- async render(fctx) {
63
- const id = this.getID();
64
- const label = this.getLabel();
65
- const type = this.getType();
66
- const { valid, message } = await this.field.getValue(fctx.ctx, fctx.data);
67
- return inputWrapper([id, type, getRequiredClass(this.field.required)], tempstream /* HTML */ `
68
- ${label ? `<label for="${id}">${label}</label>` : ""}
69
- ${await this.preInput(fctx.ctx, fctx.data)}
70
- ${this.renderInput(fctx.ctx, renderAttributes(await this.getInputAttributes(fctx)), fctx.data)}
71
- ${this.postInput(fctx.ctx)}
72
- ${~valid && !this.options.hide_errors && fctx.validate
73
- ? `<div class="input__error">${message}</div>`
74
- : ""}
75
- `);
76
- }
77
- }
78
- //# sourceMappingURL=simple-input.js.map
@@ -1,33 +0,0 @@
1
- import { SimpleInput } from "./simple-input.js";
2
- export class Textarea extends SimpleInput {
3
- constructor(field, options = {}) {
4
- super(field, options);
5
- this.field = field;
6
- this.options = options;
7
- }
8
- renderDescription() {
9
- return this.options.description
10
- ? /* HTML */ `<div class="form-input__description">
11
- ${this.options.description}
12
- </div>`
13
- : "";
14
- }
15
- async getInputAttributes(fctx) {
16
- const original = (await super.getInputAttributes(fctx));
17
- let onkeydown = original.onkeydown || "";
18
- if (this.options.autogrow) {
19
- onkeydown += `;this.style.height = '5px';this.style.height = Math.max((this.scrollHeight)+32, ${((this.options.rows || 2) + 1) * 16} )+'px';`;
20
- }
21
- return {
22
- ...original,
23
- rows: this.options.rows ? this.options.rows.toString() : false,
24
- cols: this.options.cols ? this.options.cols.toString() : false,
25
- onkeydown,
26
- };
27
- }
28
- async renderInput(ctx, attributes, data) {
29
- const { parsed: value } = await this.field.getValue(ctx, data);
30
- return /* HTML */ `<textarea ${attributes}>${value}</textarea>`;
31
- }
32
- }
33
- //# sourceMappingURL=textarea.js.map