@sealcode/sealgen 0.19.14 → 0.19.16
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/controllers/password-generate-button.stimulus.d.ts +5 -0
- package/@types/forms/controls/controls.d.ts +22 -21
- package/@types/forms/controls/password-with-generator.d.ts +6 -0
- package/lib/controllers/password-generate-button.stimulus.js +24 -0
- package/lib/forms/controls/controls.js +22 -21
- package/lib/forms/controls/password-with-generator.js +21 -0
- package/lib/forms/controls/tickable.js +4 -1
- package/lib/forms/form.js +6 -1
- package/lib/templates/form.js +1 -1
- package/package.json +1 -1
- package/src/controllers/password-generate-button.stimulus.ts +25 -0
- package/src/forms/controls/controls.ts +22 -21
- package/src/forms/controls/password-with-generator.ts +17 -0
- package/src/forms/controls/tickable.ts +14 -9
- package/src/forms/form.ts +11 -4
- package/src/templates/form.ts +1 -1
- package/src/utils/translate.ts +7 -5
|
@@ -1,31 +1,32 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
1
|
+
export * from "./autocomplete.js";
|
|
2
|
+
export * from "./big-radio-group.js";
|
|
3
|
+
export * from "./checkbox-group.js";
|
|
4
|
+
export * from "./checkbox.js";
|
|
5
5
|
export { CheckboxedListInput } from "./checkboxed-list-input.js";
|
|
6
|
+
export * from "./collapsible-checkbox-group.js";
|
|
7
|
+
export * from "./collapsible-field-group.js";
|
|
8
|
+
export * from "./derived-frame.js";
|
|
9
|
+
export * from "./derived.js";
|
|
6
10
|
export * from "./dropdown.js";
|
|
7
|
-
export
|
|
8
|
-
export {
|
|
11
|
+
export { EditableCollectionSubset } from "./editable-collection-subset.js";
|
|
12
|
+
export { FieldGroup } from "./field-group.js";
|
|
13
|
+
export * from "./file.js";
|
|
14
|
+
export { FormControl } from "./form-control.js";
|
|
15
|
+
export { FormFieldControl } from "./form-field-control.js";
|
|
9
16
|
export { FormHeader } from "./form-header.js";
|
|
10
17
|
export { FormParagraph } from "./form-paragraph.js";
|
|
11
|
-
export {
|
|
18
|
+
export { Frame } from "./frame.js";
|
|
12
19
|
export { HiddenInput } from "./hidden-input.js";
|
|
13
|
-
export {
|
|
14
|
-
export { FieldGroup } from "./field-group.js";
|
|
15
|
-
export * from "./derived.js";
|
|
16
|
-
export * from "./derived-frame.js";
|
|
17
|
-
export * from "./tickable.js";
|
|
18
|
-
export * from "./checkbox.js";
|
|
19
|
-
export * from "./radio.js";
|
|
20
|
-
export * from "./big-radio-group.js";
|
|
21
|
-
export * from "./checkbox-group.js";
|
|
22
|
-
export * from "./collapsible-field-group.js";
|
|
23
|
-
export * from "./collapsible-checkbox-group.js";
|
|
24
|
-
export * from "./autocomplete.js";
|
|
25
|
-
export * from "./file.js";
|
|
20
|
+
export { HTML } from "./html.js";
|
|
26
21
|
export * from "./image.js";
|
|
27
22
|
export * from "./multiple-files.js";
|
|
28
|
-
export * from "./number.js";
|
|
29
23
|
export * from "./multiple-images.js";
|
|
24
|
+
export * from "./number.js";
|
|
25
|
+
export * from "./password-with-generator.js";
|
|
26
|
+
export * from "./radio.js";
|
|
27
|
+
export { SimpleInput } from "./simple-input.js";
|
|
28
|
+
export * from "./single-reference.js";
|
|
29
|
+
export { Textarea } from "./textarea.js";
|
|
30
|
+
export * from "./tickable.js";
|
|
30
31
|
export * from "./array.js";
|
|
31
32
|
export * from "./table.js";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Controller } from "stimulus";
|
|
2
|
+
function generatePassword() {
|
|
3
|
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";
|
|
4
|
+
let password = "";
|
|
5
|
+
for (let i = 0; i < 8; i++) {
|
|
6
|
+
password += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
7
|
+
}
|
|
8
|
+
return password;
|
|
9
|
+
}
|
|
10
|
+
class password_generate_button_stimulus_default extends Controller {
|
|
11
|
+
getInput() {
|
|
12
|
+
return this.element.parentElement.querySelector(
|
|
13
|
+
"input"
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
generate() {
|
|
17
|
+
this.getInput().value = generatePassword();
|
|
18
|
+
this.getInput().setAttribute("type", "text");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
password_generate_button_stimulus_default as default
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=password-generate-button.stimulus.js.map
|
|
@@ -1,32 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export * from "./autocomplete.js";
|
|
2
|
+
export * from "./big-radio-group.js";
|
|
3
|
+
export * from "./checkbox-group.js";
|
|
4
|
+
export * from "./checkbox.js";
|
|
5
5
|
import { CheckboxedListInput } from "./checkboxed-list-input.js";
|
|
6
|
+
export * from "./collapsible-checkbox-group.js";
|
|
7
|
+
export * from "./collapsible-field-group.js";
|
|
8
|
+
export * from "./derived-frame.js";
|
|
9
|
+
export * from "./derived.js";
|
|
6
10
|
export * from "./dropdown.js";
|
|
7
|
-
|
|
8
|
-
import {
|
|
11
|
+
import { EditableCollectionSubset } from "./editable-collection-subset.js";
|
|
12
|
+
import { FieldGroup } from "./field-group.js";
|
|
13
|
+
export * from "./file.js";
|
|
14
|
+
import { FormControl } from "./form-control.js";
|
|
15
|
+
import { FormFieldControl } from "./form-field-control.js";
|
|
9
16
|
import { FormHeader } from "./form-header.js";
|
|
10
17
|
import { FormParagraph } from "./form-paragraph.js";
|
|
11
|
-
import {
|
|
18
|
+
import { Frame } from "./frame.js";
|
|
12
19
|
import { HiddenInput } from "./hidden-input.js";
|
|
13
|
-
import {
|
|
14
|
-
import { FieldGroup } from "./field-group.js";
|
|
15
|
-
export * from "./derived.js";
|
|
16
|
-
export * from "./derived-frame.js";
|
|
17
|
-
export * from "./tickable.js";
|
|
18
|
-
export * from "./checkbox.js";
|
|
19
|
-
export * from "./radio.js";
|
|
20
|
-
export * from "./big-radio-group.js";
|
|
21
|
-
export * from "./checkbox-group.js";
|
|
22
|
-
export * from "./collapsible-field-group.js";
|
|
23
|
-
export * from "./collapsible-checkbox-group.js";
|
|
24
|
-
export * from "./autocomplete.js";
|
|
25
|
-
export * from "./file.js";
|
|
20
|
+
import { HTML } from "./html.js";
|
|
26
21
|
export * from "./image.js";
|
|
27
22
|
export * from "./multiple-files.js";
|
|
28
|
-
export * from "./number.js";
|
|
29
23
|
export * from "./multiple-images.js";
|
|
24
|
+
export * from "./number.js";
|
|
25
|
+
export * from "./password-with-generator.js";
|
|
26
|
+
export * from "./radio.js";
|
|
27
|
+
import { SimpleInput } from "./simple-input.js";
|
|
28
|
+
export * from "./single-reference.js";
|
|
29
|
+
import { Textarea } from "./textarea.js";
|
|
30
|
+
export * from "./tickable.js";
|
|
30
31
|
export * from "./array.js";
|
|
31
32
|
export * from "./table.js";
|
|
32
33
|
export {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SimpleInput } from "./simple-input.js";
|
|
2
|
+
class PasswordWithGenerator extends SimpleInput {
|
|
3
|
+
constructor(field) {
|
|
4
|
+
super(field, { type: "password" });
|
|
5
|
+
}
|
|
6
|
+
async preInput() {
|
|
7
|
+
return (
|
|
8
|
+
/* HTML */
|
|
9
|
+
`<button
|
|
10
|
+
data-controller="password-generate-button"
|
|
11
|
+
data-action="password-generate-button#generate"
|
|
12
|
+
>
|
|
13
|
+
Generate
|
|
14
|
+
</button>`
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
PasswordWithGenerator
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=password-with-generator.js.map
|
|
@@ -21,6 +21,7 @@ class Tickable extends FormFieldControl {
|
|
|
21
21
|
];
|
|
22
22
|
}
|
|
23
23
|
async render(fctx) {
|
|
24
|
+
console.log("!! Rendering checkbox", this.field.name);
|
|
24
25
|
const {
|
|
25
26
|
parsed: _parsed,
|
|
26
27
|
valid,
|
|
@@ -30,6 +31,8 @@ class Tickable extends FormFieldControl {
|
|
|
30
31
|
fctx.data.raw_values,
|
|
31
32
|
true
|
|
32
33
|
);
|
|
34
|
+
const field_message = fctx.data.field_messages[this.field.name];
|
|
35
|
+
console.log(this.field.name, fctx.data.field_messages, field_message);
|
|
33
36
|
const parsed = _parsed === null ? this.options.default_value : _parsed;
|
|
34
37
|
const value = this.getValueAttribute(
|
|
35
38
|
fctx.ctx,
|
|
@@ -72,7 +75,7 @@ class Tickable extends FormFieldControl {
|
|
|
72
75
|
})();
|
|
73
76
|
</script>
|
|
74
77
|
|
|
75
|
-
${~valid && !this.options.hide_errors && fctx.validate ? `<div class="input__error">${message}</div>` : ""}
|
|
78
|
+
${(~valid || !!field_message) && !this.options.hide_errors && fctx.validate ? `<div class="input__error">${Array.from(new Set([message, field_message].filter((e) => !!e))).join(" \u2022 ")}</div>` : ""}
|
|
76
79
|
`
|
|
77
80
|
);
|
|
78
81
|
}
|
package/lib/forms/form.js
CHANGED
|
@@ -83,11 +83,16 @@ class Form extends MountableWithFields {
|
|
|
83
83
|
}
|
|
84
84
|
if (error instanceof SealiousErrors.FieldsError) {
|
|
85
85
|
field_messages = Object.fromEntries(
|
|
86
|
-
Object.entries(error.field_messages).map(([key, value]) => {
|
|
86
|
+
Object.entries(error.field_messages).filter(([key]) => key in this.fields).map(([key, value]) => {
|
|
87
87
|
const message = value?.message || "";
|
|
88
88
|
return [key, { type: "error", message }];
|
|
89
89
|
})
|
|
90
90
|
);
|
|
91
|
+
for (const [key, value] of Object.entries(error.field_messages)) {
|
|
92
|
+
if (!(key in this.fields)) {
|
|
93
|
+
error_message += " \xB7 " + value?.message;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
91
96
|
}
|
|
92
97
|
const messages = [{ type: "error", text: error_message }];
|
|
93
98
|
return {
|
package/lib/templates/form.js
CHANGED
|
@@ -5,7 +5,7 @@ const defaults = {
|
|
|
5
5
|
import type {FormDataValue} from "@sealcode/sealgen";`,
|
|
6
6
|
get_fields: `()=>(<const>{ password: new Fields.Password(true) })`,
|
|
7
7
|
get_controls: `
|
|
8
|
-
()
|
|
8
|
+
(fields: ReturnType<typeof getFields>)=>[new Controls.SimpleInput(fields.password, {
|
|
9
9
|
label: "Password:",
|
|
10
10
|
type: "password",
|
|
11
11
|
})]`,
|
package/package.json
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
import { Controller } from "stimulus";
|
|
3
|
+
|
|
4
|
+
function generatePassword() {
|
|
5
|
+
const chars =
|
|
6
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";
|
|
7
|
+
let password = "";
|
|
8
|
+
for (let i = 0; i < 8; i++) {
|
|
9
|
+
password += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
10
|
+
}
|
|
11
|
+
return password;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default class extends Controller<HTMLButtonElement> {
|
|
15
|
+
getInput(): HTMLInputElement {
|
|
16
|
+
return this.element.parentElement!.querySelector(
|
|
17
|
+
"input"
|
|
18
|
+
) as HTMLInputElement;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
generate() {
|
|
22
|
+
this.getInput().value = generatePassword();
|
|
23
|
+
this.getInput().setAttribute("type", "text");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -1,32 +1,33 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
1
|
+
export * from "./autocomplete.js";
|
|
2
|
+
export * from "./big-radio-group.js";
|
|
3
|
+
export * from "./checkbox-group.js";
|
|
4
|
+
export * from "./checkbox.js";
|
|
5
5
|
export { CheckboxedListInput } from "./checkboxed-list-input.js";
|
|
6
|
+
export * from "./collapsible-checkbox-group.js";
|
|
7
|
+
export * from "./collapsible-field-group.js";
|
|
8
|
+
export * from "./derived-frame.js";
|
|
9
|
+
export * from "./derived.js";
|
|
6
10
|
export * from "./dropdown.js";
|
|
7
|
-
export
|
|
8
|
-
export {
|
|
11
|
+
export { EditableCollectionSubset } from "./editable-collection-subset.js";
|
|
12
|
+
export { FieldGroup } from "./field-group.js";
|
|
13
|
+
export * from "./file.js";
|
|
14
|
+
export { FormControl } from "./form-control.js";
|
|
15
|
+
export { FormFieldControl } from "./form-field-control.js";
|
|
9
16
|
export { FormHeader } from "./form-header.js";
|
|
10
17
|
export { FormParagraph } from "./form-paragraph.js";
|
|
11
|
-
export {
|
|
18
|
+
export { Frame } from "./frame.js";
|
|
12
19
|
export { HiddenInput } from "./hidden-input.js";
|
|
13
|
-
export {
|
|
14
|
-
export { FieldGroup } from "./field-group.js";
|
|
15
|
-
export * from "./derived.js";
|
|
16
|
-
export * from "./derived-frame.js";
|
|
17
|
-
export * from "./tickable.js";
|
|
18
|
-
export * from "./checkbox.js";
|
|
19
|
-
export * from "./radio.js";
|
|
20
|
-
export * from "./big-radio-group.js";
|
|
21
|
-
export * from "./checkbox-group.js";
|
|
22
|
-
export * from "./collapsible-field-group.js";
|
|
23
|
-
export * from "./collapsible-checkbox-group.js";
|
|
24
|
-
export * from "./autocomplete.js";
|
|
25
|
-
export * from "./file.js";
|
|
20
|
+
export { HTML } from "./html.js";
|
|
26
21
|
export * from "./image.js";
|
|
27
22
|
export * from "./multiple-files.js";
|
|
28
|
-
export * from "./number.js";
|
|
29
23
|
export * from "./multiple-images.js";
|
|
24
|
+
export * from "./number.js";
|
|
25
|
+
export * from "./password-with-generator.js";
|
|
26
|
+
export * from "./radio.js";
|
|
27
|
+
export { SimpleInput } from "./simple-input.js";
|
|
28
|
+
export * from "./single-reference.js";
|
|
29
|
+
export { Textarea } from "./textarea.js";
|
|
30
|
+
export * from "./tickable.js";
|
|
30
31
|
// export * from "./reverse-single-reference";
|
|
31
32
|
export * from "./array.js";
|
|
32
33
|
export * from "./table.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { FormField } from "../../index.js";
|
|
2
|
+
import { SimpleInput } from "./simple-input.js";
|
|
3
|
+
|
|
4
|
+
export class PasswordWithGenerator extends SimpleInput {
|
|
5
|
+
constructor(field: FormField) {
|
|
6
|
+
super(field, { type: "password" });
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async preInput() {
|
|
10
|
+
return /* HTML */ `<button
|
|
11
|
+
data-controller="password-generate-button"
|
|
12
|
+
data-action="password-generate-button#generate"
|
|
13
|
+
>
|
|
14
|
+
Generate
|
|
15
|
+
</button>`;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -74,6 +74,7 @@ export abstract class Tickable<T> extends FormFieldControl {
|
|
|
74
74
|
fctx.data.raw_values,
|
|
75
75
|
true
|
|
76
76
|
);
|
|
77
|
+
const field_message = fctx.data.field_messages[this.field.name];
|
|
77
78
|
const parsed = _parsed === null ? this.options.default_value : _parsed;
|
|
78
79
|
|
|
79
80
|
const value = this.getValueAttribute(
|
|
@@ -83,9 +84,9 @@ export abstract class Tickable<T> extends FormFieldControl {
|
|
|
83
84
|
);
|
|
84
85
|
const id = this.makeInputID(fctx.ctx, fctx.data.raw_values, parsed);
|
|
85
86
|
const label =
|
|
86
|
-
this.options.label != undefined
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
this.options.label != undefined ?
|
|
88
|
+
this.options.label
|
|
89
|
+
: this.field.name;
|
|
89
90
|
|
|
90
91
|
const readonly = this.options.readonly || false;
|
|
91
92
|
const required = this.field.required;
|
|
@@ -102,9 +103,9 @@ export abstract class Tickable<T> extends FormFieldControl {
|
|
|
102
103
|
this.field.name}"
|
|
103
104
|
${value ? `value="${attribute(value)}"` : ""}
|
|
104
105
|
${fctx.form_id ? `form="${fctx.form_id}"` : ""}
|
|
105
|
-
${this.isChecked(fctx.ctx, fctx.data.raw_values, parsed)
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
${this.isChecked(fctx.ctx, fctx.data.raw_values, parsed) ?
|
|
107
|
+
"checked"
|
|
108
|
+
: ""}
|
|
108
109
|
${readonly ? "readonly" : ""}
|
|
109
110
|
${required ? "required" : ""}
|
|
110
111
|
autocomplete="off"
|
|
@@ -127,9 +128,13 @@ export abstract class Tickable<T> extends FormFieldControl {
|
|
|
127
128
|
})();
|
|
128
129
|
</script>
|
|
129
130
|
|
|
130
|
-
${
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
${(
|
|
132
|
+
(~valid || !!field_message) &&
|
|
133
|
+
!this.options.hide_errors &&
|
|
134
|
+
fctx.validate
|
|
135
|
+
) ?
|
|
136
|
+
`<div class="input__error">${Array.from(new Set([message, field_message.message].filter((e) => !!e))).join(" • ")}</div>`
|
|
137
|
+
: ""}
|
|
133
138
|
`
|
|
134
139
|
);
|
|
135
140
|
}
|
package/src/forms/form.ts
CHANGED
|
@@ -136,11 +136,18 @@ export abstract class Form<
|
|
|
136
136
|
}
|
|
137
137
|
if (error instanceof SealiousErrors.FieldsError) {
|
|
138
138
|
field_messages = Object.fromEntries(
|
|
139
|
-
Object.entries(error.field_messages)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
139
|
+
Object.entries(error.field_messages)
|
|
140
|
+
.filter(([key]) => key in this.fields)
|
|
141
|
+
.map(([key, value]) => {
|
|
142
|
+
const message = value?.message || "";
|
|
143
|
+
return [key, { type: "error", message }];
|
|
144
|
+
})
|
|
143
145
|
);
|
|
146
|
+
for (const [key, value] of Object.entries(error.field_messages)) {
|
|
147
|
+
if (!(key in this.fields)) {
|
|
148
|
+
error_message += " · " + value?.message;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
144
151
|
}
|
|
145
152
|
const messages = [<const>{ type: "error", text: error_message }];
|
|
146
153
|
return {
|
package/src/templates/form.ts
CHANGED
|
@@ -6,7 +6,7 @@ const defaults = {
|
|
|
6
6
|
import type {FormDataValue} from "@sealcode/sealgen";`,
|
|
7
7
|
get_fields: `()=>(<const>{ password: new Fields.Password(true) })`,
|
|
8
8
|
get_controls: `
|
|
9
|
-
()
|
|
9
|
+
(fields: ReturnType<typeof getFields>)=>[new Controls.SimpleInput(fields.password, {
|
|
10
10
|
label: "Password:",
|
|
11
11
|
type: "password",
|
|
12
12
|
})]`,
|
package/src/utils/translate.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
/* eslint @typescript-eslint/no-unsafe-call: off, @typescript-eslint/no-unnecessary-type-assertion: off */
|
|
1
2
|
import { Context } from "koa";
|
|
2
3
|
import { Translation } from "sealious";
|
|
3
4
|
|
|
5
|
+
/** deprecated */
|
|
4
6
|
export function t(
|
|
5
7
|
ctx: Context,
|
|
6
8
|
key: string,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
_props: unknown[],
|
|
10
|
+
_default_translation: Translation
|
|
9
11
|
) {
|
|
10
|
-
return /* HTML */ `<span translation-key="${key.replace('"', '\\"')}"
|
|
11
|
-
|
|
12
|
-
>`;
|
|
12
|
+
return /* HTML */ `<span translation-key="${key.replace('"', '\\"')}">
|
|
13
|
+
${ctx.i18n`${key}`}
|
|
14
|
+
</span>`;
|
|
13
15
|
}
|