@sealcode/sealgen 0.18.0 → 0.18.1
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.
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
import { curryImportPath } from "../utils/import-path.js";
|
|
2
|
+
import { formatWithPrettier } from "../utils/prettier.js";
|
|
2
3
|
async function statefulPageTemplate(action_name, newfilefullpath) {
|
|
3
4
|
const rel = curryImportPath(newfilefullpath);
|
|
4
|
-
return `import { TempstreamJSX, Templatable } from "tempstream";
|
|
5
|
+
return formatWithPrettier(`import { TempstreamJSX, Templatable } from "tempstream";
|
|
5
6
|
import { Context } from "koa";
|
|
6
|
-
import { StatefulPage } from "@sealcode/sealgen";
|
|
7
|
+
import { StatefulPage, StatefulPageActionArgument } from "@sealcode/sealgen";
|
|
7
8
|
import html from "${rel("src/back/html.js")}";
|
|
8
9
|
|
|
9
10
|
export const actionName = "${action_name}";
|
|
10
11
|
|
|
11
12
|
const actions = {
|
|
12
|
-
add: (state
|
|
13
|
+
add: ({ state, inputs }: StatefulPageActionArgument<State>) => {
|
|
13
14
|
return {
|
|
14
15
|
...state,
|
|
15
16
|
elements: [...state.elements, inputs.element_to_add || "new element"],
|
|
16
17
|
};
|
|
17
18
|
},
|
|
18
|
-
remove: (
|
|
19
|
+
remove: ({
|
|
20
|
+
state,
|
|
21
|
+
args: [index_to_remove],
|
|
22
|
+
}: StatefulPageActionArgument<State, [number]>) => {
|
|
19
23
|
return {
|
|
20
24
|
...state,
|
|
21
25
|
elements: state.elements.filter((_, index) => index != index_to_remove),
|
|
@@ -35,7 +39,7 @@ export default new (class ${action_name}Page extends StatefulPage<State, typeof
|
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
wrapInLayout(ctx: Context, content: Templatable): Templatable {
|
|
38
|
-
return html(ctx, "${action_name}", content);
|
|
42
|
+
return html({ctx, title: "${action_name}", body: <>{content}</>, description: "${action_name}"});
|
|
39
43
|
}
|
|
40
44
|
|
|
41
45
|
render(ctx: Context, state: State, inputs: Record<string, string>) {
|
|
@@ -60,7 +64,7 @@ export default new (class ${action_name}Page extends StatefulPage<State, typeof
|
|
|
60
64
|
);
|
|
61
65
|
}
|
|
62
66
|
})();
|
|
63
|
-
|
|
67
|
+
`);
|
|
64
68
|
}
|
|
65
69
|
export {
|
|
66
70
|
statefulPageTemplate
|
package/package.json
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
import { curryImportPath } from "../utils/import-path.js";
|
|
2
|
+
import { formatWithPrettier } from "../utils/prettier.js";
|
|
2
3
|
|
|
3
4
|
export async function statefulPageTemplate(
|
|
4
5
|
action_name: string,
|
|
5
6
|
newfilefullpath: string
|
|
6
7
|
): Promise<string> {
|
|
7
8
|
const rel = curryImportPath(newfilefullpath);
|
|
8
|
-
return `import { TempstreamJSX, Templatable } from "tempstream";
|
|
9
|
+
return formatWithPrettier(`import { TempstreamJSX, Templatable } from "tempstream";
|
|
9
10
|
import { Context } from "koa";
|
|
10
|
-
import { StatefulPage } from "@sealcode/sealgen";
|
|
11
|
+
import { StatefulPage, StatefulPageActionArgument } from "@sealcode/sealgen";
|
|
11
12
|
import html from "${rel("src/back/html.js")}";
|
|
12
13
|
|
|
13
14
|
export const actionName = "${action_name}";
|
|
14
15
|
|
|
15
16
|
const actions = {
|
|
16
|
-
add: (state
|
|
17
|
+
add: ({ state, inputs }: StatefulPageActionArgument<State>) => {
|
|
17
18
|
return {
|
|
18
19
|
...state,
|
|
19
20
|
elements: [...state.elements, inputs.element_to_add || "new element"],
|
|
20
21
|
};
|
|
21
22
|
},
|
|
22
|
-
remove: (
|
|
23
|
+
remove: ({
|
|
24
|
+
state,
|
|
25
|
+
args: [index_to_remove],
|
|
26
|
+
}: StatefulPageActionArgument<State, [number]>) => {
|
|
23
27
|
return {
|
|
24
28
|
...state,
|
|
25
29
|
elements: state.elements.filter((_, index) => index != index_to_remove),
|
|
@@ -39,7 +43,7 @@ export default new (class ${action_name}Page extends StatefulPage<State, typeof
|
|
|
39
43
|
}
|
|
40
44
|
|
|
41
45
|
wrapInLayout(ctx: Context, content: Templatable): Templatable {
|
|
42
|
-
return html(ctx, "${action_name}", content);
|
|
46
|
+
return html({ctx, title: "${action_name}", body: <>{content}</>, description: "${action_name}"});
|
|
43
47
|
}
|
|
44
48
|
|
|
45
49
|
render(ctx: Context, state: State, inputs: Record<string, string>) {
|
|
@@ -64,5 +68,5 @@ export default new (class ${action_name}Page extends StatefulPage<State, typeof
|
|
|
64
68
|
);
|
|
65
69
|
}
|
|
66
70
|
})();
|
|
67
|
-
|
|
71
|
+
`);
|
|
68
72
|
}
|