@sealcode/sealgen 0.15.7 → 0.15.8
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.
|
@@ -37,12 +37,12 @@ export declare abstract class StatefulPage<State extends Record<string, unknown>
|
|
|
37
37
|
label: string;
|
|
38
38
|
content: string;
|
|
39
39
|
};
|
|
40
|
-
makeActionURL<ActionName extends keyof Actions>(action_description: StatefulPageActionDescription<ActionName>, ...args: ExtractTail<ExtractTail<Parameters<Actions[ActionName]
|
|
41
|
-
makeActionButton<ActionName extends keyof Actions>(_state: State, action_description: StatefulPageActionDescription<ActionName>, ...args: ExtractTail<ExtractTail<Parameters<Actions[ActionName]
|
|
40
|
+
makeActionURL<ActionName extends keyof Actions>(action_description: StatefulPageActionDescription<ActionName>, ...args: ExtractTail<ExtractTail<ExtractTail<Parameters<Actions[ActionName]>>>>): string;
|
|
41
|
+
makeActionButton<ActionName extends keyof Actions>(_state: State, action_description: StatefulPageActionDescription<ActionName>, ...args: ExtractTail<ExtractTail<ExtractTail<Parameters<Actions[ActionName]>>>>): string;
|
|
42
42
|
makeActionCallback<ActionName extends keyof Actions>(action_description: {
|
|
43
43
|
action: ActionName;
|
|
44
44
|
label?: string;
|
|
45
|
-
} | ActionName, ...args: ExtractTail<ExtractTail<Parameters<Actions[ActionName]
|
|
45
|
+
} | ActionName, ...args: ExtractTail<ExtractTail<ExtractTail<Parameters<Actions[ActionName]>>>>): string;
|
|
46
46
|
rerender(): string;
|
|
47
47
|
preprocessState(values: State): Promise<State>;
|
|
48
48
|
preprocessOverrides(_context: BaseContext, _state: State, values: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { tempstream } from "tempstream";
|
|
2
|
+
import { StatefulPage } from "./stateful-page.js";
|
|
3
|
+
describe("stateful page", () => {
|
|
4
|
+
it("handles a basic case with action buttons", () => {
|
|
5
|
+
const actions = {
|
|
6
|
+
some_action: async (_ctx, _state, _inputs, _arg1) => {
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
new class extends StatefulPage {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
this.actions = actions;
|
|
13
|
+
}
|
|
14
|
+
getInitialState(_ctx) {
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
wrapInLayout(_ctx, content, _state) {
|
|
18
|
+
return content;
|
|
19
|
+
}
|
|
20
|
+
render(_ctx, state) {
|
|
21
|
+
return tempstream`<div>${this.makeActionButton(state, "some_action", 2)}</div>`;
|
|
22
|
+
}
|
|
23
|
+
}();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
//# sourceMappingURL=stateful-page.test.js.map
|
package/package.json
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { BaseContext } from "koa";
|
|
2
|
+
import { Templatable, tempstream } from "tempstream";
|
|
3
|
+
import { StatefulPage } from "./stateful-page.js";
|
|
4
|
+
|
|
5
|
+
describe("stateful page", () => {
|
|
6
|
+
it("handles a basic case with action buttons", () => {
|
|
7
|
+
type TestState = {};
|
|
8
|
+
const actions = <const>{
|
|
9
|
+
some_action: async (
|
|
10
|
+
_ctx: BaseContext,
|
|
11
|
+
_state: TestState,
|
|
12
|
+
_inputs: Record<string, unknown>,
|
|
13
|
+
_arg1: number
|
|
14
|
+
) => {},
|
|
15
|
+
};
|
|
16
|
+
new (class extends StatefulPage<TestState, typeof actions> {
|
|
17
|
+
actions = actions;
|
|
18
|
+
|
|
19
|
+
getInitialState(_ctx: BaseContext) {
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
wrapInLayout(_ctx: BaseContext, content: Templatable, _state: TestState): Templatable {
|
|
24
|
+
return content;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
render(_ctx: BaseContext, state: TestState) {
|
|
28
|
+
return tempstream`<div>${this.makeActionButton(state, "some_action", 2)}</div>`;
|
|
29
|
+
}
|
|
30
|
+
})();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -119,7 +119,9 @@ export abstract class StatefulPage<
|
|
|
119
119
|
|
|
120
120
|
makeActionURL<ActionName extends keyof Actions>(
|
|
121
121
|
action_description: StatefulPageActionDescription<ActionName>,
|
|
122
|
-
...args: ExtractTail<
|
|
122
|
+
...args: ExtractTail<
|
|
123
|
+
ExtractTail<ExtractTail<Parameters<Actions[ActionName]>>>
|
|
124
|
+
>
|
|
123
125
|
) {
|
|
124
126
|
const { action } = this.extractActionAndLabel(action_description);
|
|
125
127
|
return `./?action=${action}&action_args=${encodeURIComponent(
|
|
@@ -131,7 +133,9 @@ export abstract class StatefulPage<
|
|
|
131
133
|
makeActionButton<ActionName extends keyof Actions>(
|
|
132
134
|
_state: State,
|
|
133
135
|
action_description: StatefulPageActionDescription<ActionName>,
|
|
134
|
-
...args: ExtractTail<
|
|
136
|
+
...args: ExtractTail<
|
|
137
|
+
ExtractTail<ExtractTail<Parameters<Actions[ActionName]>>>
|
|
138
|
+
>
|
|
135
139
|
) {
|
|
136
140
|
const { label, content } =
|
|
137
141
|
this.extractActionAndLabel(action_description);
|
|
@@ -153,7 +157,9 @@ export abstract class StatefulPage<
|
|
|
153
157
|
label?: string;
|
|
154
158
|
}
|
|
155
159
|
| ActionName,
|
|
156
|
-
...args: ExtractTail<
|
|
160
|
+
...args: ExtractTail<
|
|
161
|
+
ExtractTail<ExtractTail<Parameters<Actions[ActionName]>>>
|
|
162
|
+
>
|
|
157
163
|
) {
|
|
158
164
|
return `(()=>{const form = this.closest('form'); form.action='${this.makeActionURL(
|
|
159
165
|
action_description,
|