@sealcode/sealgen 0.14.13 → 0.14.15
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/src/forms/controls/multiple-photos.d.ts +3 -3
- package/@types/src/forms/controls/photo.d.ts +3 -3
- package/@types/src/page/mountable-with-fields.d.ts +2 -1
- package/dist/forms/controls/multiple-photos.js +2 -3
- package/dist/forms/controls/photo.js +3 -4
- package/dist/forms/form.js +1 -1
- package/dist/forms/form.test.js +40 -0
- package/dist/page/mountable-with-fields.js +4 -1
- package/package.json +2 -2
- package/src/forms/controls/checkboxed-list-input.test.ts +0 -1
- package/src/forms/controls/multiple-photos.ts +4 -5
- package/src/forms/controls/photo.ts +5 -6
- package/src/forms/form.test.ts +46 -1
- package/src/forms/form.ts +3 -1
- package/src/page/mountable-with-fields.ts +8 -2
|
@@ -2,11 +2,11 @@ import { File as SealiousFile, CollectionItem } from "sealious";
|
|
|
2
2
|
import { FlatTemplatable } from "tempstream";
|
|
3
3
|
import { MultipleFiles, MultipleFilesOptions } from "./multiple-files.js";
|
|
4
4
|
import { MultipleFiles as MultipleFilesField } from "../fields/multiple-files.js";
|
|
5
|
-
import
|
|
5
|
+
import { KoaResponsiveImageRouter } from "koa-responsive-image-router";
|
|
6
6
|
export declare class MultiplePhotos extends MultipleFiles {
|
|
7
7
|
field: MultipleFilesField;
|
|
8
|
-
imageRouter: KoaResponsiveImageRouter
|
|
9
|
-
constructor(field: MultipleFilesField, imageRouter: KoaResponsiveImageRouter
|
|
8
|
+
imageRouter: KoaResponsiveImageRouter;
|
|
9
|
+
constructor(field: MultipleFilesField, imageRouter: KoaResponsiveImageRouter, options?: Partial<MultipleFilesOptions>);
|
|
10
10
|
getClassModifiers(): string[];
|
|
11
11
|
getInputAttributes(): {
|
|
12
12
|
accept: string;
|
|
@@ -4,12 +4,12 @@ import { File } from "./file.js";
|
|
|
4
4
|
import { FormField } from "../fields/field.js";
|
|
5
5
|
import { SimpleInputOptions } from "./simple-input.js";
|
|
6
6
|
import { FormControlContext } from "./form-control.js";
|
|
7
|
-
import * as KoaResponsiveImageRouter from "koa-responsive-image-router";
|
|
8
7
|
import { FileContainer } from "../fields/file.js";
|
|
8
|
+
import { KoaResponsiveImageRouter } from "koa-responsive-image-router";
|
|
9
9
|
export declare class Photo extends File {
|
|
10
10
|
field: FormField<boolean, FileContainer>;
|
|
11
|
-
imageRouter: KoaResponsiveImageRouter
|
|
12
|
-
constructor(field: FormField<boolean, FileContainer>, imageRouter: KoaResponsiveImageRouter
|
|
11
|
+
imageRouter: KoaResponsiveImageRouter;
|
|
12
|
+
constructor(field: FormField<boolean, FileContainer>, imageRouter: KoaResponsiveImageRouter, options?: SimpleInputOptions);
|
|
13
13
|
getImgStyle(): Promise<string>;
|
|
14
14
|
renderFilePreview(ctx: Context, file_data: {
|
|
15
15
|
id?: string;
|
|
@@ -18,10 +18,11 @@ export declare abstract class MountableWithFields<F extends Fields = Fields> ext
|
|
|
18
18
|
constructor();
|
|
19
19
|
init(): void;
|
|
20
20
|
makeFormControlContext(ctx: Context, data: FormData, validate: boolean, field_name_prefix?: string, form_id?: string): FormControlContext;
|
|
21
|
-
validateValues(
|
|
21
|
+
validateValues(_ctx: Context, _data: Record<string, FormDataValue>): Promise<{
|
|
22
22
|
valid: boolean;
|
|
23
23
|
error: string;
|
|
24
24
|
}>;
|
|
25
|
+
getInitialValues(_ctx: Context): Promise<Record<string, FormDataValue>>;
|
|
25
26
|
validate(ctx: Context, values: Record<string, FormDataValue>): Promise<{
|
|
26
27
|
valid: boolean;
|
|
27
28
|
field_errors: Partial<Record<keyof Fields, string>>;
|
|
@@ -19,10 +19,9 @@ class MultiplePhotos extends MultipleFiles {
|
|
|
19
19
|
}
|
|
20
20
|
return tempstream`<li>
|
|
21
21
|
<a href="${file.getURL()}" data-turbo="false">
|
|
22
|
-
${this.imageRouter.image({
|
|
23
|
-
path,
|
|
22
|
+
${this.imageRouter.image(path, {
|
|
24
23
|
resolutions: [150, 300],
|
|
25
|
-
|
|
24
|
+
sizesAttr: "150px"
|
|
26
25
|
})}
|
|
27
26
|
</a>
|
|
28
27
|
<span class="filename"> ${file.filename || "no filename"}</span>
|
|
@@ -22,11 +22,10 @@ class Photo extends File {
|
|
|
22
22
|
}
|
|
23
23
|
const file = await SealiousFile.fromID(ctx.$app, id);
|
|
24
24
|
return tempstream`<div class="${class_name}">
|
|
25
|
-
${this.imageRouter.image({
|
|
25
|
+
${this.imageRouter.image(file.getDataPath(), {
|
|
26
26
|
resolutions: [100],
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
img_style: await this.getImgStyle()
|
|
27
|
+
sizesAttr: "100px",
|
|
28
|
+
imgStyle: await this.getImgStyle()
|
|
30
29
|
})}
|
|
31
30
|
</div>`;
|
|
32
31
|
}
|
package/dist/forms/form.js
CHANGED
|
@@ -194,7 +194,7 @@ class Form extends MountableWithFields {
|
|
|
194
194
|
router.use(path, subrouter.routes(), subrouter.allowedMethods());
|
|
195
195
|
}
|
|
196
196
|
async extractRawValues(ctx) {
|
|
197
|
-
return ctx.$body;
|
|
197
|
+
return Object.keys(ctx.$body).length ? ctx.$body : this.getInitialValues(ctx);
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
200
|
export {
|
package/dist/forms/form.test.js
CHANGED
|
@@ -8,6 +8,8 @@ import { locator_is_visible } from "../test_utils/locator_is_visible.js";
|
|
|
8
8
|
import { getBrowser } from "../utils/browser-creator.js";
|
|
9
9
|
import { assertThrowsAsync } from "../utils/utils.js";
|
|
10
10
|
import getPort from "get-port";
|
|
11
|
+
import { SimpleFormField } from "./fields/simple-form-field.js";
|
|
12
|
+
import { expect as PlaywritghtExpect } from "@playwright/test";
|
|
11
13
|
const fields = {
|
|
12
14
|
text: new Fields.SimpleFormField(true)
|
|
13
15
|
};
|
|
@@ -311,6 +313,44 @@ describe("form test", () => {
|
|
|
311
313
|
});
|
|
312
314
|
});
|
|
313
315
|
});
|
|
316
|
+
describe("getInitialValues tests", async () => {
|
|
317
|
+
let server;
|
|
318
|
+
afterEach(async () => {
|
|
319
|
+
server.close();
|
|
320
|
+
});
|
|
321
|
+
it("fills the form with values from getInitialValues", async () => {
|
|
322
|
+
const app = new Koa();
|
|
323
|
+
const router = new Router();
|
|
324
|
+
const fields2 = {
|
|
325
|
+
title: new SimpleFormField(true)
|
|
326
|
+
};
|
|
327
|
+
mount(
|
|
328
|
+
router,
|
|
329
|
+
"/",
|
|
330
|
+
new class extends Form {
|
|
331
|
+
constructor() {
|
|
332
|
+
super(...arguments);
|
|
333
|
+
this.fields = fields2;
|
|
334
|
+
this.controls = [new Controls.SimpleInput(fields2.title)];
|
|
335
|
+
}
|
|
336
|
+
async getInitialValues() {
|
|
337
|
+
return { title: "Hello" };
|
|
338
|
+
}
|
|
339
|
+
onSubmit() {
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
}(),
|
|
343
|
+
true
|
|
344
|
+
);
|
|
345
|
+
app.use(router.routes()).use(router.allowedMethods());
|
|
346
|
+
server = app.listen(port);
|
|
347
|
+
const response = await page.goto(`http://localhost:${port}`);
|
|
348
|
+
if (response?.status() != 200) {
|
|
349
|
+
throw new Error(`Should return 200 status and it returns ${response?.status()}`);
|
|
350
|
+
}
|
|
351
|
+
await PlaywritghtExpect(page.getByLabel("title")).toHaveValue("Hello");
|
|
352
|
+
});
|
|
353
|
+
});
|
|
314
354
|
});
|
|
315
355
|
export {
|
|
316
356
|
form_factory
|
|
@@ -28,12 +28,15 @@ class MountableWithFields extends Mountable {
|
|
|
28
28
|
);
|
|
29
29
|
}
|
|
30
30
|
// this one is meant to be overwritten
|
|
31
|
-
async validateValues(
|
|
31
|
+
async validateValues(_ctx, _data) {
|
|
32
32
|
return {
|
|
33
33
|
valid: true,
|
|
34
34
|
error: ""
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
+
async getInitialValues(_ctx) {
|
|
38
|
+
return {};
|
|
39
|
+
}
|
|
37
40
|
async validate(ctx, values) {
|
|
38
41
|
const field_errors = {};
|
|
39
42
|
let valid = true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sealcode/sealgen",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.15",
|
|
4
4
|
"description": "Module to automate adding routes and collections to a sealious application",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
72
|
"koa": "^2.13.0",
|
|
73
|
-
"koa-responsive-image-router": "^0.2.
|
|
73
|
+
"koa-responsive-image-router": "^0.2.24",
|
|
74
74
|
"sealious": "^0.18.1"
|
|
75
75
|
}
|
|
76
76
|
}
|
|
@@ -8,7 +8,6 @@ import { CheckboxedListField } from "../fields/checkboxed-list.js";
|
|
|
8
8
|
import { Form } from "../form.js";
|
|
9
9
|
import { CheckboxedListInput } from "./checkboxed-list-input.js";
|
|
10
10
|
import { getBrowser } from "../../utils/browser-creator.js";
|
|
11
|
-
import { sleep } from "../../utils/sleep.js";
|
|
12
11
|
|
|
13
12
|
describe.only("checkboxed-list", () => {
|
|
14
13
|
describe("basic tests", async () => {
|
|
@@ -2,12 +2,12 @@ import { File as SealiousFile, CollectionItem } from "sealious";
|
|
|
2
2
|
import { FlatTemplatable, tempstream } from "tempstream";
|
|
3
3
|
import { MultipleFiles, MultipleFilesOptions } from "./multiple-files.js";
|
|
4
4
|
import { MultipleFiles as MultipleFilesField } from "../fields/multiple-files.js";
|
|
5
|
-
import
|
|
5
|
+
import { KoaResponsiveImageRouter } from "koa-responsive-image-router";
|
|
6
6
|
|
|
7
7
|
export class MultiplePhotos extends MultipleFiles {
|
|
8
8
|
constructor(
|
|
9
9
|
public field: MultipleFilesField,
|
|
10
|
-
public imageRouter: KoaResponsiveImageRouter
|
|
10
|
+
public imageRouter: KoaResponsiveImageRouter,
|
|
11
11
|
options?: Partial<MultipleFilesOptions>
|
|
12
12
|
) {
|
|
13
13
|
super(field, options);
|
|
@@ -31,10 +31,9 @@ export class MultiplePhotos extends MultipleFiles {
|
|
|
31
31
|
}
|
|
32
32
|
return tempstream/* HTML */ `<li>
|
|
33
33
|
<a href="${file.getURL()}" data-turbo="false">
|
|
34
|
-
${this.imageRouter.image({
|
|
35
|
-
path,
|
|
34
|
+
${this.imageRouter.image(path, {
|
|
36
35
|
resolutions: [150, 300],
|
|
37
|
-
|
|
36
|
+
sizesAttr: "150px",
|
|
38
37
|
})}
|
|
39
38
|
</a>
|
|
40
39
|
<span class="filename"> ${file.filename || "no filename"}</span>
|
|
@@ -5,13 +5,13 @@ import { File as SealiousFile } from "sealious";
|
|
|
5
5
|
import { FormField } from "../fields/field.js";
|
|
6
6
|
import { SimpleInputOptions } from "./simple-input.js";
|
|
7
7
|
import { FormControlContext } from "./form-control.js";
|
|
8
|
-
import * as KoaResponsiveImageRouter from "koa-responsive-image-router";
|
|
9
8
|
import { FileContainer } from "../fields/file.js";
|
|
9
|
+
import { KoaResponsiveImageRouter } from "koa-responsive-image-router";
|
|
10
10
|
|
|
11
11
|
export class Photo extends File {
|
|
12
12
|
constructor(
|
|
13
13
|
public field: FormField<boolean, FileContainer>,
|
|
14
|
-
public imageRouter: KoaResponsiveImageRouter
|
|
14
|
+
public imageRouter: KoaResponsiveImageRouter,
|
|
15
15
|
options?: SimpleInputOptions
|
|
16
16
|
) {
|
|
17
17
|
super(field, options);
|
|
@@ -36,11 +36,10 @@ export class Photo extends File {
|
|
|
36
36
|
}
|
|
37
37
|
const file = await SealiousFile.fromID(ctx.$app, id);
|
|
38
38
|
return tempstream/* HTML */ `<div class="${class_name}">
|
|
39
|
-
${this.imageRouter.image({
|
|
39
|
+
${this.imageRouter.image(file.getDataPath(), {
|
|
40
40
|
resolutions: [100],
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
img_style: await this.getImgStyle(),
|
|
41
|
+
sizesAttr: "100px",
|
|
42
|
+
imgStyle: await this.getImgStyle(),
|
|
44
43
|
})}
|
|
45
44
|
</div>`;
|
|
46
45
|
}
|
package/src/forms/form.test.ts
CHANGED
|
@@ -7,9 +7,11 @@ import { Controls, Fields, Form, Mountable } from "../index.js";
|
|
|
7
7
|
import { mount } from "../mount.js";
|
|
8
8
|
import { locator_is_visible } from "../test_utils/locator_is_visible.js";
|
|
9
9
|
import { getBrowser } from "../utils/browser-creator.js";
|
|
10
|
-
import { assertThrowsAsync } from "../utils/utils.js";
|
|
10
|
+
import { assertThrowsAsync, sleep } from "../utils/utils.js";
|
|
11
11
|
import { FormDataValue } from "./form-types.js";
|
|
12
12
|
import getPort from "get-port";
|
|
13
|
+
import { SimpleFormField } from "./fields/simple-form-field.js";
|
|
14
|
+
import { expect as PlaywritghtExpect } from "@playwright/test";
|
|
13
15
|
|
|
14
16
|
const fields = {
|
|
15
17
|
text: new Fields.SimpleFormField(true),
|
|
@@ -355,4 +357,47 @@ describe("form test", () => {
|
|
|
355
357
|
});
|
|
356
358
|
});
|
|
357
359
|
});
|
|
360
|
+
|
|
361
|
+
describe("getInitialValues tests", async () => {
|
|
362
|
+
let server: ReturnType<Koa["listen"]>;
|
|
363
|
+
|
|
364
|
+
afterEach(async () => {
|
|
365
|
+
server.close();
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
it("fills the form with values from getInitialValues", async () => {
|
|
369
|
+
const app = new Koa();
|
|
370
|
+
const router = new Router();
|
|
371
|
+
|
|
372
|
+
const fields = {
|
|
373
|
+
title: new SimpleFormField(true),
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
mount(
|
|
377
|
+
router,
|
|
378
|
+
"/",
|
|
379
|
+
new (class extends Form<typeof fields, null> {
|
|
380
|
+
fields = fields;
|
|
381
|
+
controls = [new Controls.SimpleInput(fields.title)];
|
|
382
|
+
|
|
383
|
+
async getInitialValues() {
|
|
384
|
+
return { title: "Hello" };
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
onSubmit() {
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
390
|
+
})(),
|
|
391
|
+
true
|
|
392
|
+
);
|
|
393
|
+
|
|
394
|
+
app.use(router.routes()).use(router.allowedMethods());
|
|
395
|
+
server = app.listen(port);
|
|
396
|
+
const response = await page.goto(`http://localhost:${port}`);
|
|
397
|
+
if (response?.status() != 200) {
|
|
398
|
+
throw new Error(`Should return 200 status and it returns ${response?.status()}`);
|
|
399
|
+
}
|
|
400
|
+
await PlaywritghtExpect(page.getByLabel("title")).toHaveValue("Hello");
|
|
401
|
+
});
|
|
402
|
+
});
|
|
358
403
|
});
|
package/src/forms/form.ts
CHANGED
|
@@ -55,8 +55,8 @@ export abstract class MountableWithFields<
|
|
|
55
55
|
|
|
56
56
|
// this one is meant to be overwritten
|
|
57
57
|
async validateValues(
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
_ctx: Context,
|
|
59
|
+
_data: Record<string, FormDataValue>
|
|
60
60
|
): Promise<{ valid: boolean; error: string }> {
|
|
61
61
|
return {
|
|
62
62
|
valid: true,
|
|
@@ -64,6 +64,12 @@ export abstract class MountableWithFields<
|
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
async getInitialValues(
|
|
68
|
+
_ctx: Context
|
|
69
|
+
): Promise<Record<string, FormDataValue>> {
|
|
70
|
+
return {};
|
|
71
|
+
}
|
|
72
|
+
|
|
67
73
|
async validate(
|
|
68
74
|
ctx: Context,
|
|
69
75
|
values: Record<string, FormDataValue>
|