@sealcode/sealgen 0.14.14 → 0.14.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.
@@ -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 * as KoaResponsiveImageRouter from "koa-responsive-image-router";
5
+ import { KoaResponsiveImageRouter } from "koa-responsive-image-router";
6
6
  export declare class MultiplePhotos extends MultipleFiles {
7
7
  field: MultipleFilesField;
8
- imageRouter: KoaResponsiveImageRouter.default;
9
- constructor(field: MultipleFilesField, imageRouter: KoaResponsiveImageRouter.default, options?: Partial<MultipleFilesOptions>);
8
+ imageRouter: KoaResponsiveImageRouter;
9
+ constructor(field: MultipleFilesField, imageRouter: KoaResponsiveImageRouter, options?: Partial<MultipleFilesOptions>);
10
10
  getClassModifiers(): string[];
11
11
  getInputAttributes(): {
12
12
  accept: string;
@@ -4,17 +4,18 @@ 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.default;
12
- constructor(field: FormField<boolean, FileContainer>, imageRouter: KoaResponsiveImageRouter.default, options?: SimpleInputOptions);
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;
16
16
  filename?: string;
17
17
  } | null): Promise<FlatTemplatable>;
18
+ getWrapperModifiers(): string[];
18
19
  getInputAttributes(fctx: FormControlContext): Promise<{
19
20
  accept: string;
20
21
  onchange: string;
@@ -28,5 +28,6 @@ export declare class SimpleInput<ParsedValue, Options extends SimpleInputOptions
28
28
  getInputAttributes(fctx: FormControlContext): Promise<Record<string, string | boolean>>;
29
29
  postInput(_: Context): Promise<FlatTemplatable>;
30
30
  renderInput(_ctx: Context, attributes_str: string, _data: Record<string, FormDataValue>): Promise<FlatTemplatable>;
31
+ getWrapperModifiers(): string[];
31
32
  render<Fields extends Record<string, FormField>>(fctx: FormControlContext): Promise<FlatTemplatable>;
32
33
  }
@@ -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
- sizes_attr: "150px"
24
+ sizesAttr: "150px"
26
25
  })}
27
26
  </a>
28
27
  <span class="filename"> ${file.filename || "no filename"}</span>
@@ -22,17 +22,22 @@ 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
- sizes_attr: "100px",
28
- path: file.getDataPath(),
29
- img_style: await this.getImgStyle()
27
+ sizesAttr: "100px",
28
+ imgStyle: await this.getImgStyle()
30
29
  })}
31
30
  </div>`;
32
31
  }
32
+ getWrapperModifiers() {
33
+ return [
34
+ ...super.getWrapperModifiers(),
35
+ "control-type__image",
36
+ "control-type__photo"
37
+ ];
38
+ }
33
39
  async getInputAttributes(fctx) {
34
40
  const original = await super.getInputAttributes(fctx);
35
- const { parsed } = await this.field.getValue(fctx.ctx, fctx.data);
36
41
  return {
37
42
  ...original,
38
43
  accept: "image/*",
@@ -55,16 +55,23 @@ class SimpleInput extends FormFieldControl {
55
55
  async renderInput(_ctx, attributes_str, _data) {
56
56
  return `<input ${attributes_str} />`;
57
57
  }
58
+ getWrapperModifiers() {
59
+ return [
60
+ this.getID(),
61
+ this.getType(),
62
+ "type__" + this.getType(),
63
+ getRequiredClass(this.field.required)
64
+ ];
65
+ }
58
66
  async render(fctx) {
59
67
  const id = this.getID();
60
68
  const label = this.getLabel();
61
- const type = this.getType();
62
69
  const { valid, message } = await this.field.getValue(
63
70
  fctx.ctx,
64
71
  fctx.data
65
72
  );
66
73
  return inputWrapper(
67
- [id, type, getRequiredClass(this.field.required)],
74
+ this.getWrapperModifiers(),
68
75
  tempstream`
69
76
  ${label ? `<label for="${id}">${label}</label>` : ""}
70
77
  ${await this.preInput(fctx.ctx, fctx.data)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sealcode/sealgen",
3
- "version": "0.14.14",
3
+ "version": "0.14.16",
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.6",
73
+ "koa-responsive-image-router": "^0.2.24",
74
74
  "sealious": "^0.18.1"
75
75
  }
76
76
  }
@@ -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 * as KoaResponsiveImageRouter from "koa-responsive-image-router";
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.default,
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
- sizes_attr: "150px",
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.default,
14
+ public imageRouter: KoaResponsiveImageRouter,
15
15
  options?: SimpleInputOptions
16
16
  ) {
17
17
  super(field, options);
@@ -36,21 +36,27 @@ 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
- sizes_attr: "100px",
42
- path: file.getDataPath(),
43
- img_style: await this.getImgStyle(),
41
+ sizesAttr: "100px",
42
+ imgStyle: await this.getImgStyle(),
44
43
  })}
45
44
  </div>`;
46
45
  }
47
46
 
47
+ getWrapperModifiers(): string[] {
48
+ return [
49
+ ...super.getWrapperModifiers(),
50
+ "control-type__image",
51
+ "control-type__photo",
52
+ ];
53
+ }
54
+
48
55
  async getInputAttributes(fctx: FormControlContext) {
49
56
  const original = (await super.getInputAttributes(fctx)) as Record<
50
57
  string,
51
58
  string | boolean
52
59
  >;
53
- const { parsed } = await this.field.getValue(fctx.ctx, fctx.data);
54
60
  return {
55
61
  ...original,
56
62
  accept: "image/*",
@@ -117,19 +117,27 @@ export class SimpleInput<
117
117
  return `<input ${attributes_str} />`;
118
118
  }
119
119
 
120
+ getWrapperModifiers(): string[] {
121
+ return [
122
+ this.getID(),
123
+ this.getType(),
124
+ "type__" + this.getType(),
125
+ getRequiredClass(this.field.required),
126
+ ];
127
+ }
128
+
120
129
  async render<Fields extends Record<string, FormField>>(
121
130
  fctx: FormControlContext
122
131
  ): Promise<FlatTemplatable> {
123
132
  const id = this.getID();
124
133
  const label = this.getLabel();
125
- const type = this.getType();
126
134
 
127
135
  const { valid, message } = await this.field.getValue(
128
136
  fctx.ctx,
129
137
  fctx.data
130
138
  );
131
139
  return inputWrapper(
132
- [id, type, getRequiredClass(this.field.required)],
140
+ this.getWrapperModifiers(),
133
141
  tempstream/* HTML */ `
134
142
  ${label ? `<label for="${id}">${label}</label>` : ""}
135
143
  ${await this.preInput(fctx.ctx, fctx.data)}