@sealcode/sealgen 0.8.52 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@types/forms/controls/array.d.ts +1 -1
- package/@types/forms/controls/checkbox-group.d.ts +1 -1
- package/@types/forms/controls/collapsible-field-group.d.ts +1 -1
- package/@types/forms/controls/derived-frame.d.ts +1 -0
- package/@types/forms/controls/dropdown.d.ts +2 -2
- package/@types/forms/controls/form-field-control.d.ts +1 -1
- package/@types/forms/controls/html.d.ts +1 -1
- package/@types/forms/controls/multiple-files.d.ts +1 -1
- package/@types/forms/controls/number.d.ts +1 -1
- package/@types/forms/controls/simple-input.d.ts +1 -1
- package/@types/forms/controls/tickable.d.ts +1 -1
- package/@types/forms/fields/field.d.ts +6 -6
- package/@types/forms/fields/file.d.ts +1 -1
- package/@types/forms/form.d.ts +7 -7
- package/@types/index.d.ts +1 -0
- package/@types/page/list.d.ts +13 -17
- package/@types/page/mountable-with-fields.d.ts +2 -2
- package/@types/page/props-parser.d.ts +1 -1
- package/@types/page/sealious-list.d.ts +18 -0
- package/@types/utils/utils.d.ts +3 -3
- package/lib/add-collection.js +7 -7
- package/lib/add-route.js +8 -8
- package/lib/add-route.test.js +4 -4
- package/lib/build.js +44 -11
- package/lib/components/components.js +5 -1
- package/lib/components/tabs.js +2 -2
- package/lib/components/toggle-modal.js +2 -2
- package/lib/find-scss-includes.js +3 -3
- package/lib/forms/controls/array.js +5 -5
- package/lib/forms/controls/big-radio-group.js +2 -2
- package/lib/forms/controls/checkboxed-list-input.js +3 -3
- package/lib/forms/controls/collapsible-field-group.js +1 -1
- package/lib/forms/controls/controls.js +5 -1
- package/lib/forms/controls/derived-frame.js +3 -3
- package/lib/forms/controls/derived.js +2 -2
- package/lib/forms/controls/dropdown.js +2 -2
- package/lib/forms/controls/editable-collection-subset.js +3 -3
- package/lib/forms/controls/field-group.js +1 -1
- package/lib/forms/controls/file.js +1 -1
- package/lib/forms/controls/hidden-input.js +1 -1
- package/lib/forms/controls/multiple-files.js +5 -5
- package/lib/forms/controls/multiple-photos.js +1 -1
- package/lib/forms/controls/photo.js +1 -1
- package/lib/forms/controls/simple-input.js +2 -2
- package/lib/forms/controls/tickable.js +3 -3
- package/lib/forms/fields/boolean.js +3 -3
- package/lib/forms/fields/checkboxed-list.js +3 -3
- package/lib/forms/fields/enum-multiple.js +3 -3
- package/lib/forms/fields/enum.js +2 -2
- package/lib/forms/fields/field.js +6 -2
- package/lib/forms/fields/file.js +6 -6
- package/lib/forms/fields/number.js +5 -5
- package/lib/forms/fields/pick-from-list.js +1 -1
- package/lib/forms/fields/regexp.js +2 -2
- package/lib/forms/fields/simple-form-field.js +4 -4
- package/lib/forms/form.js +9 -9
- package/lib/forms/form.test.js +12 -12
- package/lib/forms/multiform.js +5 -5
- package/lib/forms/multiform.test.js +26 -26
- package/lib/generate-collections.js +9 -5
- package/lib/generate-routes.js +13 -9
- package/lib/index.js +6 -1
- package/lib/make-env.js +1 -1
- package/lib/make-hidden-inputs.js +3 -3
- package/lib/page/list.js +85 -65
- package/lib/page/mountable-with-fields.js +2 -2
- package/lib/page/page.js +1 -1
- package/lib/page/sealious-list.js +53 -0
- package/lib/page/stateful-page.js +9 -9
- package/lib/templates/form.js +1 -1
- package/lib/templates/list.js +10 -9
- package/lib/templates/multiform.js +1 -1
- package/lib/templates/page.js +1 -1
- package/lib/templates/route-test.js +1 -1
- package/lib/templates/stateful-page.js +1 -1
- package/lib/test_utils/locator_is_visible.js +1 -1
- package/lib/utils/exec.js +1 -1
- package/lib/utils/import-path.js +2 -2
- package/lib/utils/input-wrapper.js +1 -1
- package/lib/utils/list-collections.js +2 -2
- package/lib/utils/prettier.js +6 -2
- package/lib/utils/question.js +1 -1
- package/lib/utils/render-attributes.js +1 -1
- package/lib/utils/utils.js +5 -1
- package/lib/utils/walk.js +1 -1
- package/package.json +2 -2
- package/src/add-route.ts +1 -1
- package/src/build.ts +56 -1
- package/src/generate-collections.ts +1 -1
- package/src/generate-routes.ts +1 -1
- package/src/index.ts +1 -0
- package/src/page/list.ts +106 -96
- package/src/page/sealious-list.ts +76 -0
- package/src/templates/list.ts +8 -7
- package/src/utils/import-path.ts +1 -1
|
@@ -11,10 +11,10 @@ class BigRadioGroup extends form_field_control_1.FormFieldControl {
|
|
|
11
11
|
}
|
|
12
12
|
async render(fctx) {
|
|
13
13
|
const { raw: current_value } = await this.field.getValue(fctx.ctx, fctx.data);
|
|
14
|
-
return tempstream_1.tempstream /* HTML */ `<div class="bigradios">
|
|
14
|
+
return (0, tempstream_1.tempstream /* HTML */) `<div class="bigradios">
|
|
15
15
|
${Object.entries(this.options).map(([key, { description }]) => {
|
|
16
16
|
const id = `${this.field.name}-radio-${key}`;
|
|
17
|
-
return tempstream_1.tempstream /* HTML */ `<input
|
|
17
|
+
return (0, tempstream_1.tempstream /* HTML */) `<input
|
|
18
18
|
type="radio"
|
|
19
19
|
name="${this.field.name}"
|
|
20
20
|
value="${key}"
|
|
@@ -13,7 +13,7 @@ class CheckboxedListInput extends controls_1.FormFieldControl {
|
|
|
13
13
|
}
|
|
14
14
|
async render(fctx) {
|
|
15
15
|
const { parsed: pickedValues } = await this.field.getValue(fctx.ctx, fctx.data);
|
|
16
|
-
if (!ts_predicates_1.is(pickedValues, ts_predicates_1.predicates.array(ts_predicates_1.predicates.string))) {
|
|
16
|
+
if (!(0, ts_predicates_1.is)(pickedValues, ts_predicates_1.predicates.array(ts_predicates_1.predicates.string))) {
|
|
17
17
|
throw new Error("picked values is not an array of strings");
|
|
18
18
|
}
|
|
19
19
|
const [options, isVisible] = await Promise.all([
|
|
@@ -21,8 +21,8 @@ class CheckboxedListInput extends controls_1.FormFieldControl {
|
|
|
21
21
|
this.field.isVisible(fctx.ctx),
|
|
22
22
|
]);
|
|
23
23
|
const { name, required } = this.field;
|
|
24
|
-
return tempstream_1.tempstream /* HTML */ `${isVisible
|
|
25
|
-
? Object.entries(options).map(([value, text]) => input_wrapper_1.inputWrapper([name, input_wrapper_1.getRequiredClass(required)],
|
|
24
|
+
return (0, tempstream_1.tempstream /* HTML */) `${isVisible
|
|
25
|
+
? Object.entries(options).map(([value, text]) => (0, input_wrapper_1.inputWrapper)([name, (0, input_wrapper_1.getRequiredClass)(required)],
|
|
26
26
|
/* HTML */ `
|
|
27
27
|
<input
|
|
28
28
|
type="checkbox"
|
|
@@ -9,7 +9,7 @@ class CollapsibleFieldGroup extends field_group_1.FieldGroup {
|
|
|
9
9
|
this.controls = controls;
|
|
10
10
|
this.options = options;
|
|
11
11
|
if (this.options.groupID == undefined) {
|
|
12
|
-
this.options.groupID = "A" + crypto_1.randomUUID(); // "A" is needed as ids always have to start with a letter
|
|
12
|
+
this.options.groupID = "A" + (0, crypto_1.randomUUID)(); // "A" is needed as ids always have to start with a letter
|
|
13
13
|
}
|
|
14
14
|
this.collapseID = this.options.groupID + "collapse";
|
|
15
15
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -9,7 +9,7 @@ const form_control_1 = require("./form-control");
|
|
|
9
9
|
class DerivedFrame extends derived_1.Derived {
|
|
10
10
|
constructor(frame_name, fields, generateFrameContent,
|
|
11
11
|
// "a" is to make it a valid DOM id
|
|
12
|
-
frame_id = "a" + make_slug_1.makeSlug(frame_name)) {
|
|
12
|
+
frame_id = "a" + (0, make_slug_1.makeSlug)(frame_name)) {
|
|
13
13
|
super(fields, async (values, consts) => /* HTML */ `<turbo-frame
|
|
14
14
|
id="${consts.frame_id}"
|
|
15
15
|
src="./${consts.frame_id}?${Object.entries({
|
|
@@ -29,7 +29,7 @@ class DerivedFrame extends derived_1.Derived {
|
|
|
29
29
|
this.frame_id = frame_id;
|
|
30
30
|
}
|
|
31
31
|
renderBackendResponseFrame(_ctx, content) {
|
|
32
|
-
return tempstream_1.tempstream /* HTML */ `<turbo-frame
|
|
32
|
+
return (0, tempstream_1.tempstream /* HTML */) `<turbo-frame
|
|
33
33
|
id="${this.frame_id}"
|
|
34
34
|
target="_top"
|
|
35
35
|
>
|
|
@@ -39,7 +39,7 @@ class DerivedFrame extends derived_1.Derived {
|
|
|
39
39
|
mount(router) {
|
|
40
40
|
router.get(this.frame_id, async (ctx) => {
|
|
41
41
|
const query = ctx.query;
|
|
42
|
-
if (!ts_predicates_1.hasShape({
|
|
42
|
+
if (!(0, ts_predicates_1.hasShape)({
|
|
43
43
|
field_name_prefix: ts_predicates_1.predicates.string,
|
|
44
44
|
form_id: ts_predicates_1.predicates.string,
|
|
45
45
|
validate: ts_predicates_1.predicates.string,
|
|
@@ -19,11 +19,11 @@ class Derived extends form_control_1.FormControl {
|
|
|
19
19
|
}
|
|
20
20
|
async render(fctx) {
|
|
21
21
|
// the A makes it always a valid id, as it cannot start with a number
|
|
22
|
-
const id = "A" + crypto_1.randomUUID();
|
|
22
|
+
const id = "A" + (0, crypto_1.randomUUID)();
|
|
23
23
|
const consts = this.getConsts(fctx);
|
|
24
24
|
const frontend_side_refresh_code = (values_code = "getValues()") => `render(${values_code}, consts)
|
|
25
25
|
.then(result=>document.querySelector("#${id}").innerHTML=result)`;
|
|
26
|
-
return tempstream_1.tempstream /* HTML */ `<div>
|
|
26
|
+
return (0, tempstream_1.tempstream /* HTML */) `<div>
|
|
27
27
|
<script>
|
|
28
28
|
(function () {
|
|
29
29
|
const consts = ${"{" +
|
|
@@ -37,10 +37,10 @@ class FreeformDropdown extends simple_input_1.SimpleInput {
|
|
|
37
37
|
}
|
|
38
38
|
async renderInput(ctx, attributes_str, data) {
|
|
39
39
|
const { parsed: picked_value } = await this.field.getValue(ctx, data);
|
|
40
|
-
return /* HTML */ tempstream_1.tempstream `<select ${attributes_str}>
|
|
40
|
+
return /* HTML */ (0, tempstream_1.tempstream) `<select ${attributes_str}>
|
|
41
41
|
${
|
|
42
42
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
43
|
-
Promise.resolve(this.generateOptions(ctx)).then((options) => options.map(({ value, label }) => `<option value="${sanitize_1.attribute(value)}" ${(value || "") == picked_value ? "selected" : ""}>${label}</option>`))}
|
|
43
|
+
Promise.resolve(this.generateOptions(ctx)).then((options) => options.map(({ value, label }) => `<option value="${(0, sanitize_1.attribute)(value)}" ${(value || "") == picked_value ? "selected" : ""}>${label}</option>`))}
|
|
44
44
|
</select>`;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -22,7 +22,7 @@ class EditableCollectionSubset extends controls_1.FormFieldControl {
|
|
|
22
22
|
}
|
|
23
23
|
async render(fctx) {
|
|
24
24
|
const { parsed: values } = await this.field.getValue(fctx.ctx, fctx.data);
|
|
25
|
-
return tempstream_1.tempstream /* HTML */ `<div>
|
|
25
|
+
return (0, tempstream_1.tempstream /* HTML */) `<div>
|
|
26
26
|
<ul>
|
|
27
27
|
${Promise.resolve(this.field.generateOptions(fctx.ctx)).then((options) => Object.entries(options)
|
|
28
28
|
.filter(([value]) => (values || []).includes(value))
|
|
@@ -36,7 +36,7 @@ class EditableCollectionSubset extends controls_1.FormFieldControl {
|
|
|
36
36
|
<input
|
|
37
37
|
type="hidden"
|
|
38
38
|
name="${this.field.name}"
|
|
39
|
-
value="${sanitize_1.attribute(value)}"
|
|
39
|
+
value="${(0, sanitize_1.attribute)(value)}"
|
|
40
40
|
/>
|
|
41
41
|
<input
|
|
42
42
|
type="hidden"
|
|
@@ -57,7 +57,7 @@ class EditableCollectionSubset extends controls_1.FormFieldControl {
|
|
|
57
57
|
<select name="${this.field.name}">
|
|
58
58
|
${Promise.resolve(this.field.generateOptions(fctx.ctx)).then((options) => Object.entries(options)
|
|
59
59
|
.filter(([value]) => !(values || []).includes(value))
|
|
60
|
-
.map(([value, text]) => `<option value="${sanitize_1.attribute(value)}">${text}</option>`))}
|
|
60
|
+
.map(([value, text]) => `<option value="${(0, sanitize_1.attribute)(value)}">${text}</option>`))}
|
|
61
61
|
</select>
|
|
62
62
|
<input type="hidden" name="${this.actionname}" value="select" />
|
|
63
63
|
<input
|
|
@@ -29,7 +29,7 @@ class FieldGroup extends form_field_control_1.FormFieldControl {
|
|
|
29
29
|
}
|
|
30
30
|
async render(fctx) {
|
|
31
31
|
const { label, classes } = this.options;
|
|
32
|
-
return tempstream_1.tempstream /* HTML */ `
|
|
32
|
+
return (0, tempstream_1.tempstream /* HTML */) `
|
|
33
33
|
<div
|
|
34
34
|
class="field-group ${(classes || []).join(" ")}"
|
|
35
35
|
${this.options.containerID
|
|
@@ -12,7 +12,7 @@ class File extends simple_input_1.SimpleInput {
|
|
|
12
12
|
}
|
|
13
13
|
async preInput(ctx, data) {
|
|
14
14
|
const { parsed } = await this.field.getValue(ctx, data);
|
|
15
|
-
return tempstream_1.tempstream /* HTML */ `${this.renderFilePreview(ctx, parsed.old)}
|
|
15
|
+
return (0, tempstream_1.tempstream /* HTML */) `${this.renderFilePreview(ctx, parsed.old)}
|
|
16
16
|
<input
|
|
17
17
|
type="hidden"
|
|
18
18
|
name="${this.field.name}[old][id]"
|
|
@@ -11,7 +11,7 @@ class HiddenInput extends form_field_control_1.FormFieldControl {
|
|
|
11
11
|
}
|
|
12
12
|
async render(fctx) {
|
|
13
13
|
const { raw } = await this.field.getValue(fctx.ctx, fctx.data);
|
|
14
|
-
return tempstream_1.tempstream `<input type="hidden" name="${this.field.name}" value="${sanitize_1.attribute((raw || "").toString())}" form="${fctx.form_id}">`;
|
|
14
|
+
return (0, tempstream_1.tempstream) `<input type="hidden" name="${this.field.name}" value="${(0, sanitize_1.attribute)((raw || "").toString())}" form="${fctx.form_id}">`;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
exports.HiddenInput = HiddenInput;
|
|
@@ -26,7 +26,7 @@ class MultipleFiles extends form_field_control_1.FormFieldControl {
|
|
|
26
26
|
});
|
|
27
27
|
router.post(this.getFrameRelativeURL() + "/add", async (ctx) => {
|
|
28
28
|
let files = ctx.$body.files;
|
|
29
|
-
if (!files || !ts_predicates_1.is(files, ts_predicates_1.predicates.object)) {
|
|
29
|
+
if (!files || !(0, ts_predicates_1.is)(files, ts_predicates_1.predicates.object)) {
|
|
30
30
|
ctx.body = "Missing files";
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
@@ -60,7 +60,7 @@ class MultipleFiles extends form_field_control_1.FormFieldControl {
|
|
|
60
60
|
return `A${this.field.name}__multiple-fields-control`;
|
|
61
61
|
}
|
|
62
62
|
renderFrame(ctx, content) {
|
|
63
|
-
return tempstream_1.tempstream /* HTML */ `<turbo-frame
|
|
63
|
+
return (0, tempstream_1.tempstream /* HTML */) `<turbo-frame
|
|
64
64
|
${content ? "" : `src="./${this.getFrameRelativeURL()}"`}
|
|
65
65
|
id="${this.getFrameID()}"
|
|
66
66
|
target="_top"
|
|
@@ -94,7 +94,7 @@ class MultipleFiles extends form_field_control_1.FormFieldControl {
|
|
|
94
94
|
return file.filename || "no filename";
|
|
95
95
|
}
|
|
96
96
|
async renderFileItem(fileItem, file) {
|
|
97
|
-
return tempstream_1.tempstream /* HTML */ `<li class="file-list-item">
|
|
97
|
+
return (0, tempstream_1.tempstream /* HTML */) `<li class="file-list-item">
|
|
98
98
|
<a
|
|
99
99
|
class="file-list-item__preview"
|
|
100
100
|
href="${file.getURL()}"
|
|
@@ -139,7 +139,7 @@ class MultipleFiles extends form_field_control_1.FormFieldControl {
|
|
|
139
139
|
item,
|
|
140
140
|
await this.extractFileFromItem(item),
|
|
141
141
|
]))).filter(([_, f]) => f !== null);
|
|
142
|
-
return input_wrapper_1.inputWrapper(["multiple-files", this.field.name, ...this.getClassModifiers()], tempstream_1.tempstream /* HTML */ `
|
|
142
|
+
return (0, input_wrapper_1.inputWrapper)(["multiple-files", this.field.name, ...this.getClassModifiers()], (0, tempstream_1.tempstream /* HTML */) `
|
|
143
143
|
<label>${this.options.label || this.field.name}</label>
|
|
144
144
|
<ul class="multiple-files__list">
|
|
145
145
|
${files.map(([item, file]) => this.renderFileItem(item, file))}
|
|
@@ -150,7 +150,7 @@ class MultipleFiles extends form_field_control_1.FormFieldControl {
|
|
|
150
150
|
enctype="multipart/form-data"
|
|
151
151
|
data-turbo-frame="${this.getFrameID()}"
|
|
152
152
|
>
|
|
153
|
-
<input ${render_attributes_1.renderAttributes(this.getInputAttributes())} />
|
|
153
|
+
<input ${(0, render_attributes_1.renderAttributes)(this.getInputAttributes())} />
|
|
154
154
|
<input
|
|
155
155
|
type="submit"
|
|
156
156
|
value="${this.options.uploadLabel || "Upload"}"
|
|
@@ -20,7 +20,7 @@ class MultiplePhotos extends multiple_files_1.MultipleFiles {
|
|
|
20
20
|
if (!path) {
|
|
21
21
|
return "missing file";
|
|
22
22
|
}
|
|
23
|
-
return tempstream_1.tempstream /* HTML */ `<li>
|
|
23
|
+
return (0, tempstream_1.tempstream /* HTML */) `<li>
|
|
24
24
|
<a href="${file.getURL()}" data-turbo="false">
|
|
25
25
|
${this.imageRouter.image({
|
|
26
26
|
path,
|
|
@@ -24,7 +24,7 @@ class Photo extends file_1.File {
|
|
|
24
24
|
return empty_container;
|
|
25
25
|
}
|
|
26
26
|
const file = await sealious_1.File.fromID(ctx.$app, id);
|
|
27
|
-
return tempstream_1.tempstream /* HTML */ `<div class="${class_name}">
|
|
27
|
+
return (0, tempstream_1.tempstream /* HTML */) `<div class="${class_name}">
|
|
28
28
|
${this.imageRouter.image({
|
|
29
29
|
resolutions: [100],
|
|
30
30
|
sizes_attr: "100px",
|
|
@@ -67,10 +67,10 @@ class SimpleInput extends controls_1.FormFieldControl {
|
|
|
67
67
|
const label = this.getLabel();
|
|
68
68
|
const type = this.getType();
|
|
69
69
|
const { valid, message } = await this.field.getValue(fctx.ctx, fctx.data);
|
|
70
|
-
return input_wrapper_1.inputWrapper([id, type, input_wrapper_1.getRequiredClass(this.field.required)], tempstream_1.tempstream /* HTML */ `
|
|
70
|
+
return (0, input_wrapper_1.inputWrapper)([id, type, (0, input_wrapper_1.getRequiredClass)(this.field.required)], (0, tempstream_1.tempstream /* HTML */) `
|
|
71
71
|
${label ? `<label for="${id}">${label}</label>` : ""}
|
|
72
72
|
${await this.preInput(fctx.ctx, fctx.data)}
|
|
73
|
-
${this.renderInput(fctx.ctx, render_attributes_1.renderAttributes(await this.getInputAttributes(fctx)), fctx.data)}
|
|
73
|
+
${this.renderInput(fctx.ctx, (0, render_attributes_1.renderAttributes)(await this.getInputAttributes(fctx)), fctx.data)}
|
|
74
74
|
${this.postInput(fctx.ctx)}
|
|
75
75
|
${~valid && !this.options.hide_errors && fctx.validate
|
|
76
76
|
? `<div class="input__error">${message}</div>`
|
|
@@ -20,7 +20,7 @@ class Tickable extends controls_1.FormFieldControl {
|
|
|
20
20
|
this.makeInputID(ctx, data, value),
|
|
21
21
|
this.type,
|
|
22
22
|
this.field.name.replaceAll(/\W/g, "-"),
|
|
23
|
-
input_wrapper_1.getRequiredClass(this.field.required),
|
|
23
|
+
(0, input_wrapper_1.getRequiredClass)(this.field.required),
|
|
24
24
|
...(this.isChecked(ctx, data, value) ? ["checked"] : []),
|
|
25
25
|
];
|
|
26
26
|
}
|
|
@@ -35,14 +35,14 @@ class Tickable extends controls_1.FormFieldControl {
|
|
|
35
35
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
36
36
|
const readonly = this.options.readonly || false;
|
|
37
37
|
const required = this.field.required;
|
|
38
|
-
return input_wrapper_1.inputWrapper(this.getWrapperClasses(fctx.ctx, fctx.data, parsed),
|
|
38
|
+
return (0, input_wrapper_1.inputWrapper)(this.getWrapperClasses(fctx.ctx, fctx.data, parsed),
|
|
39
39
|
/* HTML */ `
|
|
40
40
|
<input
|
|
41
41
|
id="${id}"
|
|
42
42
|
type="${this.type}"
|
|
43
43
|
name="${fctx.field_name_prefix}${this.options.name ||
|
|
44
44
|
this.field.name}"
|
|
45
|
-
${value ? `value="${sanitize_1.attribute(value)}"` : ""}
|
|
45
|
+
${value ? `value="${(0, sanitize_1.attribute)(value)}"` : ""}
|
|
46
46
|
${fctx.form_id ? `form="${fctx.form_id}"` : ""}
|
|
47
47
|
${this.isChecked(fctx.ctx, fctx.data, parsed)
|
|
48
48
|
? "checked"
|
|
@@ -18,10 +18,10 @@ class Boolean extends field_1.FormField {
|
|
|
18
18
|
return { valid: true, message: "" };
|
|
19
19
|
}
|
|
20
20
|
async parse(_, value) {
|
|
21
|
-
if (ts_predicates_1.is(value, ts_predicates_1.predicates.boolean)) {
|
|
21
|
+
if ((0, ts_predicates_1.is)(value, ts_predicates_1.predicates.boolean)) {
|
|
22
22
|
return { parsable: true, parsed_value: value, error: null };
|
|
23
23
|
}
|
|
24
|
-
else if (ts_predicates_1.is(value, ts_predicates_1.predicates.string) &&
|
|
24
|
+
else if ((0, ts_predicates_1.is)(value, ts_predicates_1.predicates.string) &&
|
|
25
25
|
[...truthy, ...falsy].includes(value)) {
|
|
26
26
|
return {
|
|
27
27
|
parsable: true,
|
|
@@ -29,7 +29,7 @@ class Boolean extends field_1.FormField {
|
|
|
29
29
|
error: null,
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
-
else if (ts_predicates_1.is(value, ts_predicates_1.predicates.undefined)) {
|
|
32
|
+
else if ((0, ts_predicates_1.is)(value, ts_predicates_1.predicates.undefined)) {
|
|
33
33
|
return {
|
|
34
34
|
parsable: true,
|
|
35
35
|
parsed_value: false,
|
|
@@ -12,16 +12,16 @@ class ChekboxedListField extends field_1.FormField {
|
|
|
12
12
|
this.predicate = ts_predicates_1.predicates.array(ts_predicates_1.predicates.string); // TODO: this is probably wrong
|
|
13
13
|
}
|
|
14
14
|
async isValueValid(_, value) {
|
|
15
|
-
if (ts_predicates_1.is(value, ts_predicates_1.predicates.string)) {
|
|
15
|
+
if ((0, ts_predicates_1.is)(value, ts_predicates_1.predicates.string)) {
|
|
16
16
|
return { valid: false, message: "you need an array" };
|
|
17
17
|
}
|
|
18
|
-
if (ts_predicates_1.is(value, ts_predicates_1.predicates.null)) {
|
|
18
|
+
if ((0, ts_predicates_1.is)(value, ts_predicates_1.predicates.null)) {
|
|
19
19
|
return { valid: false, message: "you need an array" };
|
|
20
20
|
}
|
|
21
21
|
return { valid: true, message: "" };
|
|
22
22
|
}
|
|
23
23
|
async parse(_, raw_value) {
|
|
24
|
-
if (ts_predicates_1.is(raw_value, ts_predicates_1.predicates.object)) {
|
|
24
|
+
if ((0, ts_predicates_1.is)(raw_value, ts_predicates_1.predicates.object)) {
|
|
25
25
|
return {
|
|
26
26
|
parsable: true,
|
|
27
27
|
parsed_value: Object.fromEntries(Object.entries(raw_value).filter(([, value]) => value === "on")),
|
|
@@ -12,7 +12,7 @@ class EnumMultipleField extends field_1.FormField {
|
|
|
12
12
|
}
|
|
13
13
|
async isValueValid(_, values) {
|
|
14
14
|
for (const value of values) {
|
|
15
|
-
if (!ts_predicates_1.is(value, ts_predicates_1.predicates.string)) {
|
|
15
|
+
if (!(0, ts_predicates_1.is)(value, ts_predicates_1.predicates.string)) {
|
|
16
16
|
return { valid: false, message: "expected a string" };
|
|
17
17
|
}
|
|
18
18
|
if (!this.options.includes(value)) {
|
|
@@ -22,10 +22,10 @@ class EnumMultipleField extends field_1.FormField {
|
|
|
22
22
|
return { valid: true, message: "" };
|
|
23
23
|
}
|
|
24
24
|
async parse(_, value) {
|
|
25
|
-
if (ts_predicates_1.is(value, ts_predicates_1.predicates.string)) {
|
|
25
|
+
if ((0, ts_predicates_1.is)(value, ts_predicates_1.predicates.string)) {
|
|
26
26
|
return { parsable: true, parsed_value: [value], error: null };
|
|
27
27
|
}
|
|
28
|
-
else if (ts_predicates_1.is(value, ts_predicates_1.predicates.array(ts_predicates_1.predicates.string))) {
|
|
28
|
+
else if ((0, ts_predicates_1.is)(value, ts_predicates_1.predicates.array(ts_predicates_1.predicates.string))) {
|
|
29
29
|
return {
|
|
30
30
|
parsable: true,
|
|
31
31
|
parsed_value: value,
|
package/lib/forms/fields/enum.js
CHANGED
|
@@ -11,7 +11,7 @@ class EnumField extends field_1.FormField {
|
|
|
11
11
|
this.predicate = ts_predicates_1.predicates.enum(this.options);
|
|
12
12
|
}
|
|
13
13
|
async isValueValid(_, value) {
|
|
14
|
-
if (!ts_predicates_1.is(value, ts_predicates_1.predicates.string)) {
|
|
14
|
+
if (!(0, ts_predicates_1.is)(value, ts_predicates_1.predicates.string)) {
|
|
15
15
|
return { valid: false, message: "expected a string" };
|
|
16
16
|
}
|
|
17
17
|
if (this.options.includes(value)) {
|
|
@@ -20,7 +20,7 @@ class EnumField extends field_1.FormField {
|
|
|
20
20
|
return { valid: false, message: this.error_message(this.options) };
|
|
21
21
|
}
|
|
22
22
|
async parse(_, value) {
|
|
23
|
-
if (ts_predicates_1.is(value, ts_predicates_1.predicates.string)) {
|
|
23
|
+
if ((0, ts_predicates_1.is)(value, ts_predicates_1.predicates.string)) {
|
|
24
24
|
return {
|
|
25
25
|
parsable: true,
|
|
26
26
|
parsed_value: value,
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -31,7 +35,7 @@ class FormField {
|
|
|
31
35
|
(value === "" || value === null || value === undefined)) {
|
|
32
36
|
return {
|
|
33
37
|
valid: false,
|
|
34
|
-
message: translate_1.t(ctx, "field_is_required", [], "This field is required"),
|
|
38
|
+
message: (0, translate_1.t)(ctx, "field_is_required", [], "This field is required"),
|
|
35
39
|
};
|
|
36
40
|
}
|
|
37
41
|
return this.isValueValid(ctx, value);
|
package/lib/forms/fields/file.js
CHANGED
|
@@ -8,8 +8,8 @@ class File extends field_1.FormField {
|
|
|
8
8
|
async parse(ctx, raw_value) {
|
|
9
9
|
let result;
|
|
10
10
|
if (raw_value instanceof sealious_1.File ||
|
|
11
|
-
(ts_predicates_1.is(raw_value, ts_predicates_1.predicates.object) &&
|
|
12
|
-
ts_predicates_1.hasShape({
|
|
11
|
+
((0, ts_predicates_1.is)(raw_value, ts_predicates_1.predicates.object) &&
|
|
12
|
+
(0, ts_predicates_1.hasShape)({
|
|
13
13
|
filename: ts_predicates_1.predicates.string,
|
|
14
14
|
id: ts_predicates_1.predicates.string,
|
|
15
15
|
}, raw_value) &&
|
|
@@ -21,7 +21,7 @@ class File extends field_1.FormField {
|
|
|
21
21
|
parsable: true,
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
else if (!ts_predicates_1.is(raw_value, ts_predicates_1.predicates.object)) {
|
|
24
|
+
else if (!(0, ts_predicates_1.is)(raw_value, ts_predicates_1.predicates.object)) {
|
|
25
25
|
result = {
|
|
26
26
|
parsed_value: null,
|
|
27
27
|
error: "Expected a field with old.id:string, old.filename:string and new?:File",
|
|
@@ -29,12 +29,12 @@ class File extends field_1.FormField {
|
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
else {
|
|
32
|
-
const old_file = ts_predicates_1.hasFieldOfType(raw_value, "old", ts_predicates_1.predicates.object) &&
|
|
33
|
-
ts_predicates_1.hasShape({ id: ts_predicates_1.predicates.string, filename: ts_predicates_1.predicates.string }, raw_value.old) &&
|
|
32
|
+
const old_file = (0, ts_predicates_1.hasFieldOfType)(raw_value, "old", ts_predicates_1.predicates.object) &&
|
|
33
|
+
(0, ts_predicates_1.hasShape)({ id: ts_predicates_1.predicates.string, filename: ts_predicates_1.predicates.string }, raw_value.old) &&
|
|
34
34
|
raw_value.old.id
|
|
35
35
|
? await sealious_1.File.fromID(ctx.$app, raw_value.old.id)
|
|
36
36
|
: null;
|
|
37
|
-
const new_file = ts_predicates_1.hasFieldOfType(raw_value, "new", ts_predicates_1.predicates.array(ts_predicates_1.predicates.object)) && raw_value.new[0] instanceof sealious_1.File
|
|
37
|
+
const new_file = (0, ts_predicates_1.hasFieldOfType)(raw_value, "new", ts_predicates_1.predicates.array(ts_predicates_1.predicates.object)) && raw_value.new[0] instanceof sealious_1.File
|
|
38
38
|
? raw_value.new[0]
|
|
39
39
|
: null;
|
|
40
40
|
result = {
|
|
@@ -11,20 +11,20 @@ class NumberField extends field_1.FormField {
|
|
|
11
11
|
this.predicate = ts_predicates_1.predicates.number;
|
|
12
12
|
}
|
|
13
13
|
async isValueValid(_, value) {
|
|
14
|
-
if ((ts_predicates_1.is(value, ts_predicates_1.predicates.string) &&
|
|
14
|
+
if (((0, ts_predicates_1.is)(value, ts_predicates_1.predicates.string) &&
|
|
15
15
|
!isNaN(parseFloat(value)) &&
|
|
16
16
|
parseFloat(value).toString() == value.trim()) ||
|
|
17
|
-
ts_predicates_1.is(value, ts_predicates_1.predicates.number) ||
|
|
18
|
-
((ts_predicates_1.is(value, ts_predicates_1.predicates.undefined) || value == "") && !this.required)) {
|
|
17
|
+
(0, ts_predicates_1.is)(value, ts_predicates_1.predicates.number) ||
|
|
18
|
+
(((0, ts_predicates_1.is)(value, ts_predicates_1.predicates.undefined) || value == "") && !this.required)) {
|
|
19
19
|
return { valid: true, message: "" };
|
|
20
20
|
}
|
|
21
21
|
return { valid: false, message: "Proszę wprowadzić liczbę" };
|
|
22
22
|
}
|
|
23
23
|
async parse(_, value) {
|
|
24
|
-
if ((ts_predicates_1.is(value, ts_predicates_1.predicates.string) &&
|
|
24
|
+
if (((0, ts_predicates_1.is)(value, ts_predicates_1.predicates.string) &&
|
|
25
25
|
!isNaN(parseFloat(value)) &&
|
|
26
26
|
parseFloat(value).toString() == value.trim()) ||
|
|
27
|
-
ts_predicates_1.is(value, ts_predicates_1.predicates.number)) {
|
|
27
|
+
(0, ts_predicates_1.is)(value, ts_predicates_1.predicates.number)) {
|
|
28
28
|
return {
|
|
29
29
|
parsable: true,
|
|
30
30
|
parsed_value: this.options.decimalDigits
|
|
@@ -16,7 +16,7 @@ class PickFromListField extends simple_form_field_1.SimpleFormField {
|
|
|
16
16
|
}
|
|
17
17
|
async valueInList(ctx, value) {
|
|
18
18
|
const options = await this.generateOptions(ctx);
|
|
19
|
-
if (!ts_predicates_1.is(value, ts_predicates_1.predicates.string)) {
|
|
19
|
+
if (!(0, ts_predicates_1.is)(value, ts_predicates_1.predicates.string)) {
|
|
20
20
|
return { valid: false, message: "not a string" };
|
|
21
21
|
}
|
|
22
22
|
if (this.required && !options.map((o) => o.value).includes(value)) {
|
|
@@ -12,7 +12,7 @@ class RegExpField extends field_1.FormField {
|
|
|
12
12
|
this.predicate = ts_predicates_1.predicates.string;
|
|
13
13
|
}
|
|
14
14
|
async isValueValid(_, value) {
|
|
15
|
-
if (!ts_predicates_1.is(value, ts_predicates_1.predicates.string)) {
|
|
15
|
+
if (!(0, ts_predicates_1.is)(value, ts_predicates_1.predicates.string)) {
|
|
16
16
|
return { valid: false, message: "expected a string" };
|
|
17
17
|
}
|
|
18
18
|
if (this.regexp.exec(value)) {
|
|
@@ -21,7 +21,7 @@ class RegExpField extends field_1.FormField {
|
|
|
21
21
|
return { valid: false, message: this.error_message };
|
|
22
22
|
}
|
|
23
23
|
async parse(_, value) {
|
|
24
|
-
if (ts_predicates_1.is(value, ts_predicates_1.predicates.string)) {
|
|
24
|
+
if ((0, ts_predicates_1.is)(value, ts_predicates_1.predicates.string)) {
|
|
25
25
|
return {
|
|
26
26
|
parsable: true,
|
|
27
27
|
parsed_value: value,
|
|
@@ -4,10 +4,6 @@ exports.SimpleFormField = void 0;
|
|
|
4
4
|
const field_1 = require("./field");
|
|
5
5
|
const ts_predicates_1 = require("@sealcode/ts-predicates");
|
|
6
6
|
class SimpleFormField extends field_1.FormField {
|
|
7
|
-
constructor(required) {
|
|
8
|
-
super(required);
|
|
9
|
-
this.predicate = ts_predicates_1.predicates.string;
|
|
10
|
-
}
|
|
11
7
|
async parse(_, raw_value) {
|
|
12
8
|
return {
|
|
13
9
|
parsed_value: (raw_value || "").toString(),
|
|
@@ -18,6 +14,10 @@ class SimpleFormField extends field_1.FormField {
|
|
|
18
14
|
getEmptyValue() {
|
|
19
15
|
return "";
|
|
20
16
|
}
|
|
17
|
+
constructor(required) {
|
|
18
|
+
super(required);
|
|
19
|
+
this.predicate = ts_predicates_1.predicates.string;
|
|
20
|
+
}
|
|
21
21
|
}
|
|
22
22
|
exports.SimpleFormField = SimpleFormField;
|
|
23
23
|
//# sourceMappingURL=simple-form-field.js.map
|
package/lib/forms/form.js
CHANGED
|
@@ -16,7 +16,7 @@ class Form extends mountable_with_fields_1.MountableWithFields {
|
|
|
16
16
|
this.submitButtonText = "Wyślij";
|
|
17
17
|
this.action = "./";
|
|
18
18
|
this.useTurbo = true;
|
|
19
|
-
this.form_id = crypto_1.randomUUID();
|
|
19
|
+
this.form_id = (0, crypto_1.randomUUID)();
|
|
20
20
|
}
|
|
21
21
|
async canAccess(
|
|
22
22
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -24,7 +24,7 @@ class Form extends mountable_with_fields_1.MountableWithFields {
|
|
|
24
24
|
return { canAccess: true, message: "" };
|
|
25
25
|
}
|
|
26
26
|
async renderError(_, error) {
|
|
27
|
-
return tempstream_1.tempstream /* HTML */ `<div>${error.message}</div>`;
|
|
27
|
+
return (0, tempstream_1.tempstream /* HTML */) `<div>${error.message}</div>`;
|
|
28
28
|
}
|
|
29
29
|
makeSubmitButton() {
|
|
30
30
|
return /* HTML */ `<input
|
|
@@ -35,7 +35,7 @@ class Form extends mountable_with_fields_1.MountableWithFields {
|
|
|
35
35
|
/>`;
|
|
36
36
|
}
|
|
37
37
|
async render(ctx, data, show_field_errors) {
|
|
38
|
-
return tempstream_1.tempstream /* HTML */ `<div class="form-container">
|
|
38
|
+
return (0, tempstream_1.tempstream /* HTML */) `<div class="form-container">
|
|
39
39
|
${this.makeOpenFormTag(ctx)}
|
|
40
40
|
${!this.controls.some((control) => control.role == "messages")
|
|
41
41
|
? this.renderMessages(ctx, data)
|
|
@@ -52,7 +52,7 @@ class Form extends mountable_with_fields_1.MountableWithFields {
|
|
|
52
52
|
return [];
|
|
53
53
|
}
|
|
54
54
|
makeOpenFormTag(ctx) {
|
|
55
|
-
return tempstream_1.tempstream `<form enctype="multipart/form-data" method="POST" id="${this.form_id}" action="${this.action}" class="${this.makeFormClasses(ctx).then((classes) => classes.join(" "))}" ${this.useTurbo ? "" : `data-turbo="false"`}></form><div class="form">`;
|
|
55
|
+
return (0, tempstream_1.tempstream) `<form enctype="multipart/form-data" method="POST" id="${this.form_id}" action="${this.action}" class="${this.makeFormClasses(ctx).then((classes) => classes.join(" "))}" ${this.useTurbo ? "" : `data-turbo="false"`}></form><div class="form">`;
|
|
56
56
|
}
|
|
57
57
|
makeCloseFormTag() {
|
|
58
58
|
return `</div>`;
|
|
@@ -72,8 +72,8 @@ class Form extends mountable_with_fields_1.MountableWithFields {
|
|
|
72
72
|
}
|
|
73
73
|
async onError(ctx, data, error) {
|
|
74
74
|
let error_message = "Unknown error has occured";
|
|
75
|
-
if (ts_predicates_1.is(error, ts_predicates_1.predicates.object) &&
|
|
76
|
-
ts_predicates_1.hasShape({ message: ts_predicates_1.predicates.string }, error)) {
|
|
75
|
+
if ((0, ts_predicates_1.is)(error, ts_predicates_1.predicates.object) &&
|
|
76
|
+
(0, ts_predicates_1.hasShape)({ message: ts_predicates_1.predicates.string }, error)) {
|
|
77
77
|
error_message = error.message;
|
|
78
78
|
}
|
|
79
79
|
const messages = [{ type: "error", text: error_message }];
|
|
@@ -121,10 +121,10 @@ class Form extends mountable_with_fields_1.MountableWithFields {
|
|
|
121
121
|
catch (e) {
|
|
122
122
|
// eslint-disable-next-line no-console
|
|
123
123
|
console.dir(e, { depth: 5 });
|
|
124
|
-
const message = ts_predicates_1.is(e, ts_predicates_1.predicates.object) &&
|
|
125
|
-
ts_predicates_1.hasFieldOfType(e, "message", ts_predicates_1.predicates.string)
|
|
124
|
+
const message = (0, ts_predicates_1.is)(e, ts_predicates_1.predicates.object) &&
|
|
125
|
+
(0, ts_predicates_1.hasFieldOfType)(e, "message", ts_predicates_1.predicates.string)
|
|
126
126
|
? e?.message
|
|
127
|
-
: ts_predicates_1.is(e, ts_predicates_1.predicates.string)
|
|
127
|
+
: (0, ts_predicates_1.is)(e, ts_predicates_1.predicates.string)
|
|
128
128
|
? e
|
|
129
129
|
: "Wystąpił błąd";
|
|
130
130
|
return this.onError(ctx, {
|