diff options
| author | Akshay Nair <phenax5@gmail.com> | 2023-08-11 20:42:02 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2023-08-11 20:42:02 +0530 |
| commit | 695365fa359fb98f14d06c205159739077f67fed (patch) | |
| tree | 6b99fa9a2f18c30ab784f6f9890a409337c9dbf0 /src/eval.ts | |
| parent | e7d02fc16d4b814c44752a49bca5e7854fed719f (diff) | |
| download | css-everything-695365fa359fb98f14d06c205159739077f67fed.tar.gz css-everything-695365fa359fb98f14d06c205159739077f67fed.zip | |
feat: complets form submit example
Diffstat (limited to 'src/eval.ts')
| -rw-r--r-- | src/eval.ts | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/eval.ts b/src/eval.ts index 466cafd..191a76b 100644 --- a/src/eval.ts +++ b/src/eval.ts @@ -9,6 +9,10 @@ export type EvalActions = { loadCssx(id: string, url: string): Promise<string> getVariable(name: string): Promise<string | undefined> updateVariable(id: string, varName: string, value: string): Promise<void> + setAttribute(name: string, value: string): Promise<void> + withEvent(fn: (e: any) => void): Promise<void> + getFormData(): Promise<FormData | undefined> + sendRequest(_: { method: string, url: string, data: FormData | undefined }): Promise<void> // calculate ?? } @@ -47,6 +51,7 @@ const getFunctions = (name: string, args: Expr[], actions: EvalActions) => await actions.removeClass(id, classes) } }, + delay: async () => { const num = await evalExpr(args[0], actions) console.log(num) @@ -56,6 +61,7 @@ const getFunctions = (name: string, args: Expr[], actions: EvalActions) => const js = await evalExpr(args[0], actions) js && (await actions.jsEval(js)) }, + 'load-cssx': async () => { const id = await evalExpr(args[0], actions) const url = await evalExpr(args[1], actions) @@ -63,6 +69,7 @@ const getFunctions = (name: string, args: Expr[], actions: EvalActions) => await actions.loadCssx(id, url) } }, + var: async () => { const varName = await evalExpr(args[0], actions) const defaultValue = await evalExpr(args[1], actions) @@ -76,5 +83,25 @@ const getFunctions = (name: string, args: Expr[], actions: EvalActions) => actions.updateVariable(id, varName, value) } }, + + 'set-attr': async () => { + const name = await evalExpr(args[0], actions) + const value = await evalExpr(args[1], actions) + if (name && value) { + actions.setAttribute(name, value) + } + }, + 'prevent-default': async () => actions.withEvent(e => e.preventDefault()), + + 'request': async () => { + const url = await evalExpr(args[0], actions) + const method = args[1] ? (await evalExpr(args[1], actions) ?? 'post') : 'post' + + if (url) { + const data = await actions.getFormData() + await actions.sendRequest({ method, url, data }) + } + }, + _: () => Promise.reject(new Error('not supposed to be here')), }) |
