@sealcode/sealgen 0.12.0 → 0.12.2

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 (266) hide show
  1. package/package.json +2 -2
  2. package/.madgerc +0 -7
  3. package/coverage/.tmp/coverage-15.json +0 -1
  4. package/coverage/.tmp/coverage-16.json +0 -1
  5. package/coverage/.tmp/coverage-17.json +0 -1
  6. package/coverage/.tmp/coverage-18.json +0 -1
  7. package/coverage/.tmp/coverage-19.json +0 -1
  8. package/coverage/.tmp/coverage-20.json +0 -1
  9. package/coverage/.tmp/coverage-21.json +0 -1
  10. package/coverage/.tmp/coverage-22.json +0 -1
  11. package/coverage/.tmp/coverage-23.json +0 -1
  12. package/coverage/.tmp/coverage-24.json +0 -1
  13. package/coverage/.tmp/coverage-25.json +0 -1
  14. package/coverage/.tmp/coverage-26.json +0 -1
  15. package/lib/add-collection.js +0 -24
  16. package/lib/add-jdd-component.js +0 -27
  17. package/lib/add-route.js +0 -65
  18. package/lib/add-route.test.js +0 -60
  19. package/lib/build.js +0 -187
  20. package/lib/cli.js +0 -35
  21. package/lib/components/components.js +0 -3
  22. package/lib/components/tabs.js +0 -88
  23. package/lib/components/toggle-modal.js +0 -46
  24. package/lib/example.test.js +0 -5
  25. package/lib/find-css-includes.js +0 -23
  26. package/lib/forms/controls/array.js +0 -140
  27. package/lib/forms/controls/autocomplete.js +0 -23
  28. package/lib/forms/controls/big-radio-group.js +0 -34
  29. package/lib/forms/controls/checkbox-group.js +0 -29
  30. package/lib/forms/controls/checkbox.js +0 -24
  31. package/lib/forms/controls/checkboxed-list-input.js +0 -35
  32. package/lib/forms/controls/collapsible-checkbox-group.js +0 -13
  33. package/lib/forms/controls/collapsible-field-group.js +0 -78
  34. package/lib/forms/controls/controls.js +0 -31
  35. package/lib/forms/controls/derived-frame.js +0 -52
  36. package/lib/forms/controls/derived.js +0 -77
  37. package/lib/forms/controls/dropdown.js +0 -55
  38. package/lib/forms/controls/editable-collection-subset.js +0 -68
  39. package/lib/forms/controls/field-group.js +0 -53
  40. package/lib/forms/controls/file.js +0 -35
  41. package/lib/forms/controls/form-control.js +0 -14
  42. package/lib/forms/controls/form-field-control.js +0 -9
  43. package/lib/forms/controls/form-header.js +0 -14
  44. package/lib/forms/controls/form-paragraph.js +0 -12
  45. package/lib/forms/controls/frame.js +0 -25
  46. package/lib/forms/controls/hidden-input.js +0 -14
  47. package/lib/forms/controls/html.js +0 -23
  48. package/lib/forms/controls/multiple-files.js +0 -160
  49. package/lib/forms/controls/multiple-photos.js +0 -33
  50. package/lib/forms/controls/number.js +0 -25
  51. package/lib/forms/controls/photo.js +0 -57
  52. package/lib/forms/controls/radio.js +0 -25
  53. package/lib/forms/controls/reverse-single-reference.js +0 -47
  54. package/lib/forms/controls/simple-input.js +0 -78
  55. package/lib/forms/controls/textarea.js +0 -33
  56. package/lib/forms/controls/tickable.js +0 -75
  57. package/lib/forms/fields/boolean.js +0 -51
  58. package/lib/forms/fields/boolean.test.js +0 -32
  59. package/lib/forms/fields/checkboxed-list.js +0 -40
  60. package/lib/forms/fields/collection-field.js +0 -29
  61. package/lib/forms/fields/email.js +0 -11
  62. package/lib/forms/fields/email.test.js +0 -20
  63. package/lib/forms/fields/enum-multiple.js +0 -47
  64. package/lib/forms/fields/enum-multiple.test.js +0 -27
  65. package/lib/forms/fields/enum.js +0 -39
  66. package/lib/forms/fields/enum.test.js +0 -21
  67. package/lib/forms/fields/existing-sealious-value.js +0 -16
  68. package/lib/forms/fields/field.js +0 -81
  69. package/lib/forms/fields/file.js +0 -53
  70. package/lib/forms/fields/multiple-files.js +0 -15
  71. package/lib/forms/fields/number.js +0 -45
  72. package/lib/forms/fields/number.test.js +0 -30
  73. package/lib/forms/fields/pick-from-list.js +0 -31
  74. package/lib/forms/fields/pick-from-list.test.js +0 -17
  75. package/lib/forms/fields/proxy-field.js +0 -20
  76. package/lib/forms/fields/regexp.js +0 -40
  77. package/lib/forms/fields/regexp.test.js +0 -21
  78. package/lib/forms/fields/reverse-single-reference.js +0 -14
  79. package/lib/forms/fields/simple-form-field.js +0 -20
  80. package/lib/forms/fields/structured-array.js +0 -18
  81. package/lib/forms/form.js +0 -176
  82. package/lib/forms/form.test.js +0 -1
  83. package/lib/forms/multiform.js +0 -174
  84. package/lib/forms/multiform.test.js +0 -426
  85. package/lib/generate-collections.js +0 -52
  86. package/lib/generate-components.js +0 -33
  87. package/lib/generate-routes.js +0 -75
  88. package/lib/index.js +0 -17
  89. package/lib/make-env.js +0 -14
  90. package/lib/make-hidden-inputs.js +0 -14
  91. package/lib/mount.js +0 -70
  92. package/lib/notifier.js +0 -19
  93. package/lib/page/access-control.js +0 -16
  94. package/lib/page/default-list-filters.js +0 -40
  95. package/lib/page/list.js +0 -183
  96. package/lib/page/mountable-with-fields.js +0 -85
  97. package/lib/page/mountable.js +0 -5
  98. package/lib/page/page.js +0 -26
  99. package/lib/page/props-parser.js +0 -23
  100. package/lib/page/sealious-list.js +0 -59
  101. package/lib/page/stateful-page.js +0 -97
  102. package/lib/remove-named-imports.js +0 -47
  103. package/lib/run.js +0 -2
  104. package/lib/sanitize.js +0 -10
  105. package/lib/src/add-collection.js +0 -24
  106. package/lib/src/add-jdd-component.js +0 -27
  107. package/lib/src/add-route.js +0 -65
  108. package/lib/src/add-route.test.js +0 -72
  109. package/lib/src/build.js +0 -142
  110. package/lib/src/cli.js +0 -37
  111. package/lib/src/components/components.js +0 -3
  112. package/lib/src/components/tabs.js +0 -88
  113. package/lib/src/components/toggle-modal.js +0 -46
  114. package/lib/src/example.test.js +0 -5
  115. package/lib/src/find-css-includes.js +0 -23
  116. package/lib/src/forms/controls/array.js +0 -141
  117. package/lib/src/forms/controls/autocomplete.js +0 -23
  118. package/lib/src/forms/controls/big-radio-group.js +0 -34
  119. package/lib/src/forms/controls/checkbox-group.js +0 -30
  120. package/lib/src/forms/controls/checkbox.js +0 -24
  121. package/lib/src/forms/controls/checkboxed-list-input.js +0 -35
  122. package/lib/src/forms/controls/collapsible-checkbox-group.js +0 -13
  123. package/lib/src/forms/controls/collapsible-field-group.js +0 -78
  124. package/lib/src/forms/controls/controls.js +0 -31
  125. package/lib/src/forms/controls/derived-frame.js +0 -52
  126. package/lib/src/forms/controls/derived.js +0 -77
  127. package/lib/src/forms/controls/dropdown.js +0 -55
  128. package/lib/src/forms/controls/editable-collection-subset.js +0 -68
  129. package/lib/src/forms/controls/field-group.js +0 -53
  130. package/lib/src/forms/controls/file.js +0 -35
  131. package/lib/src/forms/controls/form-control.js +0 -14
  132. package/lib/src/forms/controls/form-field-control.js +0 -9
  133. package/lib/src/forms/controls/form-header.js +0 -14
  134. package/lib/src/forms/controls/form-paragraph.js +0 -12
  135. package/lib/src/forms/controls/frame.js +0 -25
  136. package/lib/src/forms/controls/hidden-input.js +0 -14
  137. package/lib/src/forms/controls/html.js +0 -23
  138. package/lib/src/forms/controls/multiple-files.js +0 -160
  139. package/lib/src/forms/controls/multiple-photos.js +0 -33
  140. package/lib/src/forms/controls/number.js +0 -25
  141. package/lib/src/forms/controls/photo.js +0 -57
  142. package/lib/src/forms/controls/radio.js +0 -25
  143. package/lib/src/forms/controls/reverse-single-reference.js +0 -47
  144. package/lib/src/forms/controls/simple-input.js +0 -78
  145. package/lib/src/forms/controls/textarea.js +0 -33
  146. package/lib/src/forms/controls/tickable.js +0 -75
  147. package/lib/src/forms/fields/boolean.js +0 -51
  148. package/lib/src/forms/fields/boolean.test.js +0 -33
  149. package/lib/src/forms/fields/checkboxed-list.js +0 -40
  150. package/lib/src/forms/fields/collection-field.js +0 -29
  151. package/lib/src/forms/fields/email.js +0 -11
  152. package/lib/src/forms/fields/email.test.js +0 -20
  153. package/lib/src/forms/fields/enum-multiple.js +0 -47
  154. package/lib/src/forms/fields/enum-multiple.test.js +0 -27
  155. package/lib/src/forms/fields/enum.js +0 -39
  156. package/lib/src/forms/fields/enum.test.js +0 -21
  157. package/lib/src/forms/fields/existing-sealious-value.js +0 -16
  158. package/lib/src/forms/fields/field.js +0 -66
  159. package/lib/src/forms/fields/fields.js +0 -16
  160. package/lib/src/forms/fields/file.js +0 -53
  161. package/lib/src/forms/fields/multiple-files.js +0 -15
  162. package/lib/src/forms/fields/number.js +0 -45
  163. package/lib/src/forms/fields/number.test.js +0 -31
  164. package/lib/src/forms/fields/pick-from-list.js +0 -31
  165. package/lib/src/forms/fields/pick-from-list.test.js +0 -17
  166. package/lib/src/forms/fields/proxy-field.js +0 -20
  167. package/lib/src/forms/fields/regexp.js +0 -40
  168. package/lib/src/forms/fields/regexp.test.js +0 -21
  169. package/lib/src/forms/fields/reverse-single-reference.js +0 -14
  170. package/lib/src/forms/fields/simple-form-field.js +0 -19
  171. package/lib/src/forms/fields/structured-array.js +0 -18
  172. package/lib/src/forms/form-types.js +0 -2
  173. package/lib/src/forms/form.js +0 -176
  174. package/lib/src/forms/form.test.js +0 -271
  175. package/lib/src/forms/multiform.js +0 -174
  176. package/lib/src/forms/multiform.test.js +0 -430
  177. package/lib/src/generate-collections.js +0 -52
  178. package/lib/src/generate-components.js +0 -33
  179. package/lib/src/generate-routes.js +0 -75
  180. package/lib/src/hehe.test.js +0 -7
  181. package/lib/src/index.js +0 -19
  182. package/lib/src/make-env.js +0 -14
  183. package/lib/src/make-hidden-inputs.js +0 -14
  184. package/lib/src/mount.js +0 -70
  185. package/lib/src/notifier.js +0 -19
  186. package/lib/src/page/access-control.js +0 -16
  187. package/lib/src/page/default-list-filters.js +0 -40
  188. package/lib/src/page/list.js +0 -184
  189. package/lib/src/page/mountable-with-fields.js +0 -85
  190. package/lib/src/page/mountable.js +0 -5
  191. package/lib/src/page/page.js +0 -26
  192. package/lib/src/page/props-parser.js +0 -23
  193. package/lib/src/page/sealious-list.js +0 -59
  194. package/lib/src/page/stateful-page.js +0 -97
  195. package/lib/src/run.js +0 -2
  196. package/lib/src/sample-index.js +0 -3
  197. package/lib/src/sample-lib.js +0 -6
  198. package/lib/src/sanitize.js +0 -10
  199. package/lib/src/templates/collection.js +0 -12
  200. package/lib/src/templates/form.js +0 -57
  201. package/lib/src/templates/jdd-component.js +0 -39
  202. package/lib/src/templates/list.js +0 -139
  203. package/lib/src/templates/long-running-process.js +0 -60
  204. package/lib/src/templates/multiform.js +0 -55
  205. package/lib/src/templates/page.js +0 -23
  206. package/lib/src/templates/post.js +0 -22
  207. package/lib/src/templates/redirect.js +0 -23
  208. package/lib/src/templates/route-test.js +0 -54
  209. package/lib/src/templates/stateful-page.js +0 -66
  210. package/lib/src/templates/templates.js +0 -21
  211. package/lib/src/test_utils/locator_is_visible.js +0 -11
  212. package/lib/src/utils/assert-throws.js +0 -17
  213. package/lib/src/utils/base64.js +0 -7
  214. package/lib/src/utils/browser-creator.js +0 -10
  215. package/lib/src/utils/escape-url-params.js +0 -14
  216. package/lib/src/utils/exec.js +0 -22
  217. package/lib/src/utils/extract-fields-from-collection.js +0 -26
  218. package/lib/src/utils/format-external-url.js +0 -11
  219. package/lib/src/utils/import-path.js +0 -16
  220. package/lib/src/utils/input-wrapper.js +0 -15
  221. package/lib/src/utils/list-collections.js +0 -13
  222. package/lib/src/utils/make-slug.js +0 -6
  223. package/lib/src/utils/natural-numbers.js +0 -6
  224. package/lib/src/utils/prettier.js +0 -10
  225. package/lib/src/utils/question.js +0 -19
  226. package/lib/src/utils/render-attributes.js +0 -19
  227. package/lib/src/utils/sleep.js +0 -4
  228. package/lib/src/utils/translate.js +0 -6
  229. package/lib/src/utils/url-with-new-params.js +0 -5
  230. package/lib/src/utils/utils.js +0 -16
  231. package/lib/src/utils/walk.js +0 -23
  232. package/lib/src/vitest.config.js +0 -20
  233. package/lib/templates/collection.js +0 -12
  234. package/lib/templates/form.js +0 -57
  235. package/lib/templates/jdd-component.js +0 -39
  236. package/lib/templates/list.js +0 -139
  237. package/lib/templates/long-running-process.js +0 -60
  238. package/lib/templates/multiform.js +0 -55
  239. package/lib/templates/page.js +0 -23
  240. package/lib/templates/post.js +0 -22
  241. package/lib/templates/redirect.js +0 -23
  242. package/lib/templates/route-test.js +0 -54
  243. package/lib/templates/stateful-page.js +0 -66
  244. package/lib/templates/templates.js +0 -21
  245. package/lib/test_utils/locator_is_visible.js +0 -11
  246. package/lib/utils/assert-throws.js +0 -17
  247. package/lib/utils/base64.js +0 -7
  248. package/lib/utils/browser-creator.js +0 -10
  249. package/lib/utils/escape-url-params.js +0 -14
  250. package/lib/utils/exec.js +0 -22
  251. package/lib/utils/extract-fields-from-collection.js +0 -26
  252. package/lib/utils/format-external-url.js +0 -11
  253. package/lib/utils/import-path.js +0 -16
  254. package/lib/utils/input-wrapper.js +0 -15
  255. package/lib/utils/list-collections.js +0 -13
  256. package/lib/utils/make-slug.js +0 -6
  257. package/lib/utils/natural-numbers.js +0 -6
  258. package/lib/utils/prettier.js +0 -10
  259. package/lib/utils/question.js +0 -19
  260. package/lib/utils/render-attributes.js +0 -19
  261. package/lib/utils/sleep.js +0 -4
  262. package/lib/utils/translate.js +0 -6
  263. package/lib/utils/url-with-new-params.js +0 -5
  264. package/lib/utils/utils.js +0 -16
  265. package/lib/utils/walk.js +0 -23
  266. package/lib/vitest.config.js +0 -22
@@ -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 "./controls.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
@@ -1,75 +0,0 @@
1
- import { attribute } from "../../sanitize.js";
2
- import { getRequiredClass, inputWrapper } from "../../utils/input-wrapper.js";
3
- import { FormFieldControl } from "./controls.js";
4
- export class Tickable extends FormFieldControl {
5
- constructor(field, options = {}) {
6
- super([field]);
7
- this.field = field;
8
- this.options = options;
9
- }
10
- makeInputID(ctx, data, value) {
11
- const value_attr = this.getValueAttribute(ctx, data, value);
12
- return (this.options.id ||
13
- this.field.name + (value_attr ? "--" + value_attr : ""));
14
- }
15
- getWrapperClasses(ctx, data, value) {
16
- return [
17
- this.makeInputID(ctx, data, value),
18
- this.type,
19
- this.field.name.replaceAll(/\W/g, "-"),
20
- getRequiredClass(this.field.required),
21
- ...(this.isChecked(ctx, data, value) ? ["checked"] : []),
22
- ];
23
- }
24
- async render(fctx) {
25
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
26
- const { parsed, valid, message } = await this.field.getValue(fctx.ctx, fctx.data);
27
- const value = this.getValueAttribute(fctx.ctx, fctx.data, parsed);
28
- const id = this.makeInputID(fctx.ctx, fctx.data, parsed);
29
- const label = this.options.label != undefined
30
- ? this.options.label
31
- : this.field.name;
32
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
33
- const readonly = this.options.readonly || false;
34
- const required = this.field.required;
35
- return inputWrapper(this.getWrapperClasses(fctx.ctx, fctx.data, parsed),
36
- /* HTML */ `
37
- <input
38
- id="${id}"
39
- type="${this.type}"
40
- name="${fctx.field_name_prefix}${this.options.name ||
41
- this.field.name}"
42
- ${value ? `value="${attribute(value)}"` : ""}
43
- ${fctx.form_id ? `form="${fctx.form_id}"` : ""}
44
- ${this.isChecked(fctx.ctx, fctx.data, parsed)
45
- ? "checked"
46
- : ""}
47
- ${readonly ? "readonly" : ""}
48
- ${required ? "required" : ""}
49
- autocomplete="off"
50
- onchange="this.closest('.form-container').querySelectorAll('.form-input__wrapper--${this
51
- .field
52
- .name}').forEach(e=>e.setAttribute('data-checked','false'));
53
- this.closest('.form-input__wrapper').setAttribute('data-checked',this.checked);"
54
- />
55
-
56
- <label for="${id}">${label}</label>
57
- <script>
58
- (function () {
59
- let wrapper = document.currentScript.closest(
60
- ".form-input__wrapper"
61
- );
62
- wrapper.setAttribute(
63
- "data-checked",
64
- wrapper.querySelector("input").checked.toString()
65
- );
66
- })();
67
- </script>
68
-
69
- ${~valid && !this.options.hide_errors && fctx.validate
70
- ? `<div class="input__error">${message}</div>`
71
- : ""}
72
- `);
73
- }
74
- }
75
- //# sourceMappingURL=tickable.js.map
@@ -1,51 +0,0 @@
1
- import { is, predicates } from "@sealcode/ts-predicates";
2
- import { FormField } from "./field.js";
3
- const truthy = ["true", "on", "yes", "1"];
4
- const falsy = ["false", "off", "no", "0"];
5
- export class Boolean extends FormField {
6
- constructor(required, error_message = "") {
7
- super(required);
8
- this.error_message = error_message;
9
- this.predicate = predicates.boolean;
10
- }
11
- async isValueValid(_, value) {
12
- if (this.required && !value) {
13
- return { valid: false, message: this.error_message };
14
- }
15
- return { valid: true, message: "" };
16
- }
17
- async parse(_, value) {
18
- if (is(value, predicates.boolean)) {
19
- return { parsable: true, parsed_value: value, error: null };
20
- }
21
- else if (is(value, predicates.string) &&
22
- [...truthy, ...falsy].includes(value)) {
23
- return {
24
- parsable: true,
25
- parsed_value: truthy.includes(value),
26
- error: null,
27
- };
28
- }
29
- else if (is(value, predicates.undefined)) {
30
- return {
31
- parsable: true,
32
- parsed_value: false,
33
- error: null,
34
- };
35
- }
36
- else if (value === null) {
37
- return { parsable: true, parsed_value: false, error: null };
38
- }
39
- else {
40
- return {
41
- parsable: false,
42
- parsed_value: null,
43
- error: "Please enter a boolean",
44
- };
45
- }
46
- }
47
- getEmptyValue() {
48
- return false;
49
- }
50
- }
51
- //# sourceMappingURL=boolean.js.map
@@ -1,32 +0,0 @@
1
- import assert from "assert";
2
- import { Fields } from "../../index.js";
3
- describe("boolean field", () => {
4
- const ctx = {};
5
- it("validation logic", async () => {
6
- const required = new Fields.Boolean(true);
7
- const not_required = new Fields.Boolean(false);
8
- assert.strictEqual((await required.isValueValid(ctx, true)).valid, true);
9
- assert.strictEqual((await required.isValueValid(ctx, false)).valid, false);
10
- assert.strictEqual((await not_required.isValueValid(ctx, true)).valid, true);
11
- assert.strictEqual((await not_required.isValueValid(ctx, false)).valid, true);
12
- });
13
- it("parse function", async () => {
14
- const field = new Fields.Boolean(true);
15
- const true_response = await field.parse(ctx, true);
16
- const null_response = await field.parse(ctx, null);
17
- const true_as_string_response = await field.parse(ctx, "true");
18
- const undefined_response = await field.parse(ctx, undefined);
19
- const number_response = await field.parse(ctx, 42);
20
- assert.strictEqual(true_response.parsable, true);
21
- assert.strictEqual(true_response.parsed_value, true);
22
- assert.strictEqual(null_response.parsable, true);
23
- assert.strictEqual(null_response.parsed_value, false);
24
- assert.strictEqual(true_as_string_response.parsable, true);
25
- assert.strictEqual(true_as_string_response.parsed_value, true);
26
- assert.strictEqual(undefined_response.parsable, true);
27
- assert.strictEqual(undefined_response.parsed_value, false);
28
- assert.strictEqual(number_response.parsable, false);
29
- assert.strictEqual(number_response.error, "Please enter a boolean");
30
- });
31
- });
32
- //# sourceMappingURL=boolean.test.js.map
@@ -1,40 +0,0 @@
1
- import { is, predicates } from "@sealcode/ts-predicates";
2
- import { FormField, } from "./field.js";
3
- export class ChekboxedListField extends FormField {
4
- constructor(required, generateOptions, isVisible = () => Promise.resolve(true)) {
5
- super(required);
6
- this.required = required;
7
- this.generateOptions = generateOptions;
8
- this.isVisible = isVisible;
9
- this.predicate = predicates.array(predicates.string); // TODO: this is probably wrong
10
- }
11
- async isValueValid(_, value) {
12
- if (is(value, predicates.string)) {
13
- return { valid: false, message: "you need an array" };
14
- }
15
- if (is(value, predicates.null)) {
16
- return { valid: false, message: "you need an array" };
17
- }
18
- return { valid: true, message: "" };
19
- }
20
- async parse(_, raw_value) {
21
- if (is(raw_value, predicates.object)) {
22
- return {
23
- parsable: true,
24
- parsed_value: Object.fromEntries(Object.entries(raw_value).filter(([, value]) => value === "on")),
25
- error: null,
26
- };
27
- }
28
- else {
29
- return {
30
- parsed_value: null,
31
- parsable: false,
32
- error: "Expected an object",
33
- };
34
- }
35
- }
36
- getEmptyValue() {
37
- return {};
38
- }
39
- }
40
- //# sourceMappingURL=checkboxed-list.js.map