effect-start 0.23.1 → 0.26.0
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/package.json +18 -86
- package/src/Development.ts +3 -1
- package/src/Entity.ts +17 -0
- package/src/Fetch.ts +271 -0
- package/src/SqlIntrospect.ts +64 -70
- package/src/Start.ts +21 -24
- package/src/StartApp.ts +1 -1
- package/src/bun/BunServer.ts +42 -10
- package/src/hyper/HyperHtml.ts +0 -1
- package/src/sql/bun/index.ts +1 -1
- package/src/sql/index.ts +1 -0
- package/src/sql/libsql/index.ts +173 -0
- package/src/sql/libsql/libsql.d.ts +39 -0
- package/src/sql/mssql/index.ts +1 -1
- package/dist/BlobStore.d.ts +0 -80
- package/dist/BlobStore.js +0 -19
- package/dist/ChildProcess.d.ts +0 -60
- package/dist/ChildProcess.js +0 -30
- package/dist/Commander.d.ts +0 -100
- package/dist/Commander.js +0 -326
- package/dist/ContentNegotiation.d.ts +0 -12
- package/dist/ContentNegotiation.js +0 -359
- package/dist/Cookies.d.ts +0 -47
- package/dist/Cookies.js +0 -302
- package/dist/Development.d.ts +0 -39
- package/dist/Development.js +0 -58
- package/dist/Effectify.d.ts +0 -209
- package/dist/Effectify.js +0 -19
- package/dist/Entity.d.ts +0 -47
- package/dist/Entity.js +0 -224
- package/dist/FilePathPattern.d.ts +0 -29
- package/dist/FilePathPattern.js +0 -86
- package/dist/FileRouter.d.ts +0 -56
- package/dist/FileRouter.js +0 -148
- package/dist/FileRouterCodegen.d.ts +0 -18
- package/dist/FileRouterCodegen.js +0 -227
- package/dist/FileRouterPattern.d.ts +0 -9
- package/dist/FileRouterPattern.js +0 -35
- package/dist/FileSystem.d.ts +0 -158
- package/dist/FileSystem.js +0 -70
- package/dist/Http.d.ts +0 -37
- package/dist/Http.js +0 -88
- package/dist/HttpAppExtra.d.ts +0 -7
- package/dist/HttpAppExtra.js +0 -320
- package/dist/HttpUtils.d.ts +0 -3
- package/dist/HttpUtils.js +0 -11
- package/dist/PathPattern.d.ts +0 -134
- package/dist/PathPattern.js +0 -413
- package/dist/PlatformError.d.ts +0 -38
- package/dist/PlatformError.js +0 -25
- package/dist/PlatformRuntime.d.ts +0 -27
- package/dist/PlatformRuntime.js +0 -46
- package/dist/Route.d.ts +0 -97
- package/dist/Route.js +0 -100
- package/dist/RouteBody.d.ts +0 -47
- package/dist/RouteBody.js +0 -67
- package/dist/RouteError.d.ts +0 -98
- package/dist/RouteError.js +0 -55
- package/dist/RouteHook.d.ts +0 -12
- package/dist/RouteHook.js +0 -40
- package/dist/RouteHttp.d.ts +0 -21
- package/dist/RouteHttp.js +0 -258
- package/dist/RouteHttpTracer.d.ts +0 -10
- package/dist/RouteHttpTracer.js +0 -62
- package/dist/RouteMount.d.ts +0 -86
- package/dist/RouteMount.js +0 -63
- package/dist/RouteSchema.d.ts +0 -86
- package/dist/RouteSchema.js +0 -188
- package/dist/RouteSse.d.ts +0 -21
- package/dist/RouteSse.js +0 -79
- package/dist/RouteTree.d.ts +0 -57
- package/dist/RouteTree.js +0 -93
- package/dist/RouteTrie.d.ts +0 -20
- package/dist/RouteTrie.js +0 -152
- package/dist/RouterPattern.d.ts +0 -118
- package/dist/RouterPattern.js +0 -269
- package/dist/SchemaExtra.d.ts +0 -7
- package/dist/SchemaExtra.js +0 -74
- package/dist/Socket.d.ts +0 -27
- package/dist/Socket.js +0 -29
- package/dist/Sql.d.ts +0 -34
- package/dist/Sql.js +0 -5
- package/dist/SqlIntrospect.d.ts +0 -91
- package/dist/SqlIntrospect.js +0 -466
- package/dist/Start.d.ts +0 -44
- package/dist/Start.js +0 -49
- package/dist/StartApp.d.ts +0 -19
- package/dist/StartApp.js +0 -21
- package/dist/StreamExtra.d.ts +0 -28
- package/dist/StreamExtra.js +0 -100
- package/dist/System.d.ts +0 -7
- package/dist/System.js +0 -22
- package/dist/TuplePathPattern.d.ts +0 -9
- package/dist/TuplePathPattern.js +0 -68
- package/dist/Unique.d.ts +0 -50
- package/dist/Unique.js +0 -187
- package/dist/Values.d.ts +0 -27
- package/dist/Values.js +0 -36
- package/dist/bun/BunBlobStoreDisk.d.ts +0 -6
- package/dist/bun/BunBlobStoreDisk.js +0 -116
- package/dist/bun/BunBlobStoreS3.d.ts +0 -11
- package/dist/bun/BunBlobStoreS3.js +0 -89
- package/dist/bun/BunBlobWatcherDisk.d.ts +0 -6
- package/dist/bun/BunBlobWatcherDisk.js +0 -60
- package/dist/bun/BunBlobWatcherQueue.d.ts +0 -6
- package/dist/bun/BunBlobWatcherQueue.js +0 -17
- package/dist/bun/BunBundle.d.ts +0 -11
- package/dist/bun/BunBundle.js +0 -137
- package/dist/bun/BunChildProcessSpawner.d.ts +0 -3
- package/dist/bun/BunChildProcessSpawner.js +0 -103
- package/dist/bun/BunHttpServer.d.ts +0 -44
- package/dist/bun/BunHttpServer.js +0 -186
- package/dist/bun/BunHttpServer_web.d.ts +0 -60
- package/dist/bun/BunHttpServer_web.js +0 -252
- package/dist/bun/BunImportTrackerPlugin.d.ts +0 -13
- package/dist/bun/BunImportTrackerPlugin.js +0 -69
- package/dist/bun/BunPlatformHttpServer.d.ts +0 -10
- package/dist/bun/BunPlatformHttpServer.js +0 -53
- package/dist/bun/BunRoute.d.ts +0 -48
- package/dist/bun/BunRoute.js +0 -121
- package/dist/bun/BunRuntime.d.ts +0 -2
- package/dist/bun/BunRuntime.js +0 -31
- package/dist/bun/BunServer.d.ts +0 -40
- package/dist/bun/BunServer.js +0 -157
- package/dist/bun/BunServerRequest.d.ts +0 -60
- package/dist/bun/BunServerRequest.js +0 -252
- package/dist/bun/BunSql.d.ts +0 -4
- package/dist/bun/BunSql.js +0 -81
- package/dist/bun/BunVirtualFilesPlugin.d.ts +0 -4
- package/dist/bun/BunVirtualFilesPlugin.js +0 -40
- package/dist/bun/_BunEnhancedResolve.d.ts +0 -45
- package/dist/bun/_BunEnhancedResolve.js +0 -102
- package/dist/bun/index.d.ts +0 -5
- package/dist/bun/index.js +0 -5
- package/dist/bundler/Bundle.d.ts +0 -61
- package/dist/bundler/Bundle.js +0 -48
- package/dist/bundler/BundleFiles.d.ts +0 -13
- package/dist/bundler/BundleFiles.js +0 -96
- package/dist/bundler/BundleHttp.d.ts +0 -45
- package/dist/bundler/BundleHttp.js +0 -176
- package/dist/bundler/BundleRoute.d.ts +0 -27
- package/dist/bundler/BundleRoute.js +0 -51
- package/dist/client/Overlay.d.ts +0 -2
- package/dist/client/Overlay.js +0 -32
- package/dist/client/ScrollState.d.ts +0 -6
- package/dist/client/ScrollState.js +0 -94
- package/dist/client/index.d.ts +0 -6
- package/dist/client/index.js +0 -79
- package/dist/console/Console.d.ts +0 -6
- package/dist/console/Console.js +0 -26
- package/dist/console/ConsoleErrors.d.ts +0 -3
- package/dist/console/ConsoleErrors.js +0 -200
- package/dist/console/ConsoleLogger.d.ts +0 -3
- package/dist/console/ConsoleLogger.js +0 -47
- package/dist/console/ConsoleMetrics.d.ts +0 -3
- package/dist/console/ConsoleMetrics.js +0 -61
- package/dist/console/ConsoleProcess.d.ts +0 -3
- package/dist/console/ConsoleProcess.js +0 -49
- package/dist/console/ConsoleStore.d.ts +0 -144
- package/dist/console/ConsoleStore.js +0 -61
- package/dist/console/ConsoleTracer.d.ts +0 -3
- package/dist/console/ConsoleTracer.js +0 -94
- package/dist/console/Simulation.d.ts +0 -2
- package/dist/console/Simulation.js +0 -633
- package/dist/console/index.d.ts +0 -3
- package/dist/console/index.js +0 -3
- package/dist/console/routes/errors/route.d.ts +0 -10
- package/dist/console/routes/errors/route.js +0 -47
- package/dist/console/routes/fiberDetail.d.ts +0 -16
- package/dist/console/routes/fiberDetail.js +0 -38
- package/dist/console/routes/fibers/route.d.ts +0 -10
- package/dist/console/routes/fibers/route.js +0 -19
- package/dist/console/routes/git/route.d.ts +0 -11
- package/dist/console/routes/git/route.js +0 -33
- package/dist/console/routes/layout.d.ts +0 -9
- package/dist/console/routes/layout.js +0 -3
- package/dist/console/routes/logs/route.d.ts +0 -10
- package/dist/console/routes/logs/route.js +0 -32
- package/dist/console/routes/metrics/route.d.ts +0 -10
- package/dist/console/routes/metrics/route.js +0 -17
- package/dist/console/routes/route.d.ts +0 -6
- package/dist/console/routes/route.js +0 -5
- package/dist/console/routes/routes/route.d.ts +0 -6
- package/dist/console/routes/routes/route.js +0 -20
- package/dist/console/routes/services/route.d.ts +0 -6
- package/dist/console/routes/services/route.js +0 -12
- package/dist/console/routes/system/route.d.ts +0 -10
- package/dist/console/routes/system/route.js +0 -18
- package/dist/console/routes/traceDetail.d.ts +0 -16
- package/dist/console/routes/traceDetail.js +0 -14
- package/dist/console/routes/traces/route.d.ts +0 -10
- package/dist/console/routes/traces/route.js +0 -39
- package/dist/console/routes/tree.d.ts +0 -153
- package/dist/console/routes/tree.js +0 -29
- package/dist/console/ui/Errors.d.ts +0 -4
- package/dist/console/ui/Errors.js +0 -15
- package/dist/console/ui/Fibers.d.ts +0 -24
- package/dist/console/ui/Fibers.js +0 -121
- package/dist/console/ui/Git.d.ts +0 -20
- package/dist/console/ui/Git.js +0 -95
- package/dist/console/ui/Logs.d.ts +0 -4
- package/dist/console/ui/Logs.js +0 -25
- package/dist/console/ui/Metrics.d.ts +0 -4
- package/dist/console/ui/Metrics.js +0 -26
- package/dist/console/ui/Routes.d.ts +0 -8
- package/dist/console/ui/Routes.js +0 -70
- package/dist/console/ui/Services.d.ts +0 -10
- package/dist/console/ui/Services.js +0 -246
- package/dist/console/ui/Shell.d.ts +0 -10
- package/dist/console/ui/Shell.js +0 -7
- package/dist/console/ui/System.d.ts +0 -4
- package/dist/console/ui/System.js +0 -35
- package/dist/console/ui/Traces.d.ts +0 -12
- package/dist/console/ui/Traces.js +0 -179
- package/dist/datastar/actions/fetch.d.ts +0 -30
- package/dist/datastar/actions/fetch.js +0 -403
- package/dist/datastar/actions/peek.d.ts +0 -1
- package/dist/datastar/actions/peek.js +0 -13
- package/dist/datastar/actions/setAll.d.ts +0 -1
- package/dist/datastar/actions/setAll.js +0 -12
- package/dist/datastar/actions/toggleAll.d.ts +0 -1
- package/dist/datastar/actions/toggleAll.js +0 -12
- package/dist/datastar/attributes/attr.d.ts +0 -1
- package/dist/datastar/attributes/attr.js +0 -48
- package/dist/datastar/attributes/bind.d.ts +0 -1
- package/dist/datastar/attributes/bind.js +0 -175
- package/dist/datastar/attributes/class.d.ts +0 -1
- package/dist/datastar/attributes/class.js +0 -47
- package/dist/datastar/attributes/computed.d.ts +0 -1
- package/dist/datastar/attributes/computed.js +0 -26
- package/dist/datastar/attributes/effect.d.ts +0 -1
- package/dist/datastar/attributes/effect.js +0 -9
- package/dist/datastar/attributes/indicator.d.ts +0 -1
- package/dist/datastar/attributes/indicator.js +0 -30
- package/dist/datastar/attributes/init.d.ts +0 -1
- package/dist/datastar/attributes/init.js +0 -26
- package/dist/datastar/attributes/jsonSignals.d.ts +0 -1
- package/dist/datastar/attributes/jsonSignals.js +0 -30
- package/dist/datastar/attributes/on.d.ts +0 -1
- package/dist/datastar/attributes/on.js +0 -78
- package/dist/datastar/attributes/onIntersect.d.ts +0 -1
- package/dist/datastar/attributes/onIntersect.js +0 -53
- package/dist/datastar/attributes/onInterval.d.ts +0 -1
- package/dist/datastar/attributes/onInterval.js +0 -30
- package/dist/datastar/attributes/onSignalPatch.d.ts +0 -1
- package/dist/datastar/attributes/onSignalPatch.js +0 -42
- package/dist/datastar/attributes/ref.d.ts +0 -1
- package/dist/datastar/attributes/ref.js +0 -10
- package/dist/datastar/attributes/show.d.ts +0 -1
- package/dist/datastar/attributes/show.js +0 -31
- package/dist/datastar/attributes/signals.d.ts +0 -1
- package/dist/datastar/attributes/signals.js +0 -17
- package/dist/datastar/attributes/style.d.ts +0 -1
- package/dist/datastar/attributes/style.js +0 -50
- package/dist/datastar/attributes/text.d.ts +0 -1
- package/dist/datastar/attributes/text.js +0 -26
- package/dist/datastar/engine.d.ts +0 -162
- package/dist/datastar/engine.js +0 -999
- package/dist/datastar/happydom.d.ts +0 -1
- package/dist/datastar/happydom.js +0 -8
- package/dist/datastar/index.d.ts +0 -24
- package/dist/datastar/index.js +0 -24
- package/dist/datastar/load.d.ts +0 -24
- package/dist/datastar/load.js +0 -24
- package/dist/datastar/utils.d.ts +0 -51
- package/dist/datastar/utils.js +0 -202
- package/dist/datastar/watchers/patchElements.d.ts +0 -1
- package/dist/datastar/watchers/patchElements.js +0 -399
- package/dist/datastar/watchers/patchSignals.d.ts +0 -1
- package/dist/datastar/watchers/patchSignals.js +0 -14
- package/dist/experimental/EncryptedCookies.d.ts +0 -48
- package/dist/experimental/EncryptedCookies.js +0 -212
- package/dist/experimental/SseHttpResponse.d.ts +0 -7
- package/dist/experimental/SseHttpResponse.js +0 -28
- package/dist/experimental/index.d.ts +0 -1
- package/dist/experimental/index.js +0 -1
- package/dist/hyper/Hyper.d.ts +0 -25
- package/dist/hyper/Hyper.js +0 -23
- package/dist/hyper/HyperHtml.d.ts +0 -23
- package/dist/hyper/HyperHtml.js +0 -150
- package/dist/hyper/HyperHtml.test.d.ts +0 -1
- package/dist/hyper/HyperHtml.test.js +0 -197
- package/dist/hyper/HyperNode.d.ts +0 -14
- package/dist/hyper/HyperNode.js +0 -11
- package/dist/hyper/HyperRoute.d.ts +0 -8
- package/dist/hyper/HyperRoute.js +0 -32
- package/dist/hyper/HyperRoute.test.d.ts +0 -1
- package/dist/hyper/HyperRoute.test.js +0 -83
- package/dist/hyper/html.d.ts +0 -11
- package/dist/hyper/html.js +0 -30
- package/dist/hyper/index.d.ts +0 -6
- package/dist/hyper/index.js +0 -5
- package/dist/hyper/jsx-runtime.d.ts +0 -7
- package/dist/hyper/jsx-runtime.js +0 -8
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -8
- package/dist/inference_check.d.ts +0 -1
- package/dist/inference_check.js +0 -15
- package/dist/lint/plugin.d.ts +0 -86
- package/dist/lint/plugin.js +0 -341
- package/dist/middlewares/BasicAuthMiddleware.d.ts +0 -8
- package/dist/middlewares/BasicAuthMiddleware.js +0 -22
- package/dist/middlewares/index.d.ts +0 -1
- package/dist/middlewares/index.js +0 -1
- package/dist/node/Effectify.d.ts +0 -209
- package/dist/node/Effectify.js +0 -19
- package/dist/node/FileSystem.d.ts +0 -7
- package/dist/node/FileSystem.js +0 -420
- package/dist/node/NodeFileSystem.d.ts +0 -7
- package/dist/node/NodeFileSystem.js +0 -410
- package/dist/node/NodeUtils.d.ts +0 -2
- package/dist/node/NodeUtils.js +0 -20
- package/dist/node/PlatformError.d.ts +0 -46
- package/dist/node/PlatformError.js +0 -43
- package/dist/node/Utils.d.ts +0 -1
- package/dist/node/Utils.js +0 -19
- package/dist/repro_fail.d.ts +0 -1
- package/dist/repro_fail.js +0 -14
- package/dist/sql/bun/index.d.ts +0 -3
- package/dist/sql/bun/index.js +0 -75
- package/dist/sql/mssql/docker.d.ts +0 -2
- package/dist/sql/mssql/docker.js +0 -67
- package/dist/sql/mssql/index.d.ts +0 -21
- package/dist/sql/mssql/index.js +0 -113
- package/dist/testing/TestHttpClient.d.ts +0 -13
- package/dist/testing/TestHttpClient.js +0 -68
- package/dist/testing/TestLogger.d.ts +0 -13
- package/dist/testing/TestLogger.js +0 -32
- package/dist/testing/index.d.ts +0 -2
- package/dist/testing/index.js +0 -2
- package/dist/testing/utils.d.ts +0 -9
- package/dist/testing/utils.js +0 -39
- package/dist/x/cloudflare/CloudflareTunnel.d.ts +0 -10
- package/dist/x/cloudflare/CloudflareTunnel.js +0 -30
- package/dist/x/cloudflare/index.d.ts +0 -1
- package/dist/x/cloudflare/index.js +0 -1
- package/dist/x/datastar/Datastar.d.ts +0 -6
- package/dist/x/datastar/Datastar.js +0 -47
- package/dist/x/datastar/index.d.ts +0 -1
- package/dist/x/datastar/index.js +0 -1
- package/dist/x/tailscale/TailscaleTunnel.d.ts +0 -15
- package/dist/x/tailscale/TailscaleTunnel.js +0 -68
- package/dist/x/tailscale/index.d.ts +0 -1
- package/dist/x/tailscale/index.js +0 -1
- package/dist/x/tailwind/TailwindPlugin.d.ts +0 -23
- package/dist/x/tailwind/TailwindPlugin.js +0 -219
- package/dist/x/tailwind/compile.d.ts +0 -19
- package/dist/x/tailwind/compile.js +0 -154
- package/dist/x/tailwind/plugin.d.ts +0 -2
- package/dist/x/tailwind/plugin.js +0 -15
- /package/src/{Sql.ts → sql/Sql.ts} +0 -0
|
@@ -1,403 +0,0 @@
|
|
|
1
|
-
import { action, DATASTAR_FETCH_EVENT, filtered, startPeeking, stopPeeking, } from "../engine.js";
|
|
2
|
-
import { kebab } from "../utils.js";
|
|
3
|
-
const createHttpMethod = (name, method, openWhenHiddenDefault = true) => action({
|
|
4
|
-
name,
|
|
5
|
-
apply: async ({ el, evt, error, cleanups }, url, { selector, headers: userHeaders, contentType = "json", filterSignals: { include = /.*/, exclude = /(^|\.)_/ } = {}, openWhenHidden = openWhenHiddenDefault, payload, requestCancellation = "auto", retry = "auto", retryInterval = 1_000, retryScaler = 2, retryMaxWaitMs = 30_000, retryMaxCount = 10, } = {}) => {
|
|
6
|
-
const controller = requestCancellation instanceof AbortController ? requestCancellation : new AbortController();
|
|
7
|
-
if (requestCancellation === "auto") {
|
|
8
|
-
cleanups.get(`@${name}`)?.();
|
|
9
|
-
cleanups.set(`@${name}`, async () => {
|
|
10
|
-
controller.abort();
|
|
11
|
-
await Promise.resolve();
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
let cleanupFn = null;
|
|
15
|
-
try {
|
|
16
|
-
if (!url?.length) {
|
|
17
|
-
throw error("FetchNoUrlProvided", { action });
|
|
18
|
-
}
|
|
19
|
-
const initialHeaders = {
|
|
20
|
-
Accept: "text/event-stream, text/html, application/json",
|
|
21
|
-
"Datastar-Request": true,
|
|
22
|
-
};
|
|
23
|
-
if (contentType === "json") {
|
|
24
|
-
initialHeaders["Content-Type"] = "application/json";
|
|
25
|
-
}
|
|
26
|
-
const headers = Object.assign({}, initialHeaders, userHeaders);
|
|
27
|
-
const req = {
|
|
28
|
-
method,
|
|
29
|
-
headers,
|
|
30
|
-
openWhenHidden,
|
|
31
|
-
retry,
|
|
32
|
-
retryInterval,
|
|
33
|
-
retryScaler,
|
|
34
|
-
retryMaxWaitMs,
|
|
35
|
-
retryMaxCount,
|
|
36
|
-
signal: controller.signal,
|
|
37
|
-
onopen: async (response) => {
|
|
38
|
-
if (response.status >= 400) {
|
|
39
|
-
dispatchFetch(ERROR, el, { status: response.status.toString() });
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
onmessage: (evt) => {
|
|
43
|
-
if (!evt.event.startsWith("datastar"))
|
|
44
|
-
return;
|
|
45
|
-
const type = evt.event;
|
|
46
|
-
const argsRawLines = {};
|
|
47
|
-
for (const line of evt.data.split("\n")) {
|
|
48
|
-
const i = line.indexOf(" ");
|
|
49
|
-
const k = line.slice(0, i);
|
|
50
|
-
const v = line.slice(i + 1);
|
|
51
|
-
(argsRawLines[k] ||= []).push(v);
|
|
52
|
-
}
|
|
53
|
-
const argsRaw = Object.fromEntries(Object.entries(argsRawLines).map(([k, v]) => [k, v.join("\n")]));
|
|
54
|
-
dispatchFetch(type, el, argsRaw);
|
|
55
|
-
},
|
|
56
|
-
onerror: (error) => {
|
|
57
|
-
if (isWrongContent(error)) {
|
|
58
|
-
throw error("FetchExpectedTextEventStream", { url });
|
|
59
|
-
}
|
|
60
|
-
if (error) {
|
|
61
|
-
console.error(error.message);
|
|
62
|
-
dispatchFetch(RETRYING, el, { message: error.message });
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
const urlInstance = new URL(url, document.baseURI);
|
|
67
|
-
const queryParams = new URLSearchParams(urlInstance.search);
|
|
68
|
-
if (contentType === "json") {
|
|
69
|
-
startPeeking();
|
|
70
|
-
payload = payload !== undefined ? payload : filtered({ include, exclude });
|
|
71
|
-
stopPeeking();
|
|
72
|
-
const body = JSON.stringify(payload);
|
|
73
|
-
if (method === "GET") {
|
|
74
|
-
queryParams.set("datastar", body);
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
req.body = body;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
else if (contentType === "form") {
|
|
81
|
-
const formEl = (selector ? document.querySelector(selector) : el.closest("form"));
|
|
82
|
-
if (!formEl) {
|
|
83
|
-
throw error("FetchFormNotFound", { action, selector });
|
|
84
|
-
}
|
|
85
|
-
if (!formEl.noValidate && !formEl.checkValidity()) {
|
|
86
|
-
formEl.reportValidity();
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
const formData = new FormData(formEl);
|
|
90
|
-
let submitter = el;
|
|
91
|
-
if (el === formEl && evt instanceof SubmitEvent) {
|
|
92
|
-
submitter = evt.submitter;
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
const preventDefault = (evt) => evt.preventDefault();
|
|
96
|
-
formEl.addEventListener("submit", preventDefault);
|
|
97
|
-
cleanupFn = () => {
|
|
98
|
-
formEl.removeEventListener("submit", preventDefault);
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
if (submitter instanceof HTMLButtonElement) {
|
|
102
|
-
const name = submitter.getAttribute("name");
|
|
103
|
-
if (name)
|
|
104
|
-
formData.append(name, submitter.value);
|
|
105
|
-
}
|
|
106
|
-
const multipart = formEl.getAttribute("enctype") === "multipart/form-data";
|
|
107
|
-
if (!multipart) {
|
|
108
|
-
headers["Content-Type"] = "application/x-www-form-urlencoded";
|
|
109
|
-
}
|
|
110
|
-
const formParams = new URLSearchParams(formData);
|
|
111
|
-
if (method === "GET") {
|
|
112
|
-
for (const [key, value] of formParams) {
|
|
113
|
-
queryParams.append(key, value);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
else if (multipart) {
|
|
117
|
-
req.body = formData;
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
req.body = formParams;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
throw error("FetchInvalidContentType", { action, contentType });
|
|
125
|
-
}
|
|
126
|
-
dispatchFetch(STARTED, el, {});
|
|
127
|
-
urlInstance.search = queryParams.toString();
|
|
128
|
-
try {
|
|
129
|
-
await fetchEventSource(urlInstance.toString(), el, req);
|
|
130
|
-
}
|
|
131
|
-
catch (e) {
|
|
132
|
-
if (!isWrongContent(e)) {
|
|
133
|
-
throw error("FetchFailed", { method, url, error: e.message });
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
finally {
|
|
138
|
-
dispatchFetch(FINISHED, el, {});
|
|
139
|
-
cleanupFn?.();
|
|
140
|
-
cleanups.delete(`@${name}`);
|
|
141
|
-
}
|
|
142
|
-
},
|
|
143
|
-
});
|
|
144
|
-
createHttpMethod("get", "GET", false);
|
|
145
|
-
createHttpMethod("patch", "PATCH");
|
|
146
|
-
createHttpMethod("post", "POST");
|
|
147
|
-
createHttpMethod("put", "PUT");
|
|
148
|
-
createHttpMethod("delete", "DELETE");
|
|
149
|
-
export const STARTED = "started";
|
|
150
|
-
export const FINISHED = "finished";
|
|
151
|
-
export const ERROR = "error";
|
|
152
|
-
export const RETRYING = "retrying";
|
|
153
|
-
export const RETRIES_FAILED = "retries-failed";
|
|
154
|
-
const dispatchFetch = (type, el, argsRaw) => document.dispatchEvent(new CustomEvent(DATASTAR_FETCH_EVENT, {
|
|
155
|
-
detail: { type, el, argsRaw },
|
|
156
|
-
}));
|
|
157
|
-
const isWrongContent = (err) => `${err}`.includes("text/event-stream");
|
|
158
|
-
const getBytes = async (stream, onChunk) => {
|
|
159
|
-
const reader = stream.getReader();
|
|
160
|
-
let result = await reader.read();
|
|
161
|
-
while (!result.done) {
|
|
162
|
-
onChunk(result.value);
|
|
163
|
-
result = await reader.read();
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
const getLines = (onLine) => {
|
|
167
|
-
let buffer;
|
|
168
|
-
let position;
|
|
169
|
-
let fieldLength;
|
|
170
|
-
let discardTrailingNewline = false;
|
|
171
|
-
return (arr) => {
|
|
172
|
-
if (!buffer) {
|
|
173
|
-
buffer = arr;
|
|
174
|
-
position = 0;
|
|
175
|
-
fieldLength = -1;
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
buffer = concat(buffer, arr);
|
|
179
|
-
}
|
|
180
|
-
const bufLength = buffer.length;
|
|
181
|
-
let lineStart = 0;
|
|
182
|
-
while (position < bufLength) {
|
|
183
|
-
if (discardTrailingNewline) {
|
|
184
|
-
if (buffer[position] === 10)
|
|
185
|
-
lineStart = ++position;
|
|
186
|
-
discardTrailingNewline = false;
|
|
187
|
-
}
|
|
188
|
-
let lineEnd = -1;
|
|
189
|
-
for (; position < bufLength && lineEnd === -1; ++position) {
|
|
190
|
-
switch (buffer[position]) {
|
|
191
|
-
case 58:
|
|
192
|
-
if (fieldLength === -1) {
|
|
193
|
-
fieldLength = position - lineStart;
|
|
194
|
-
}
|
|
195
|
-
break;
|
|
196
|
-
// @ts-expect-error:7029
|
|
197
|
-
case 13:
|
|
198
|
-
discardTrailingNewline = true;
|
|
199
|
-
case 10:
|
|
200
|
-
lineEnd = position;
|
|
201
|
-
break;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
if (lineEnd === -1)
|
|
205
|
-
break;
|
|
206
|
-
onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
|
|
207
|
-
lineStart = position;
|
|
208
|
-
fieldLength = -1;
|
|
209
|
-
}
|
|
210
|
-
if (lineStart === bufLength)
|
|
211
|
-
buffer = undefined;
|
|
212
|
-
else if (lineStart) {
|
|
213
|
-
buffer = buffer.subarray(lineStart);
|
|
214
|
-
position -= lineStart;
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
};
|
|
218
|
-
const getMessages = (onId, onRetry, onMessage) => {
|
|
219
|
-
let message = newMessage();
|
|
220
|
-
const decoder = new TextDecoder();
|
|
221
|
-
return (line, fieldLength) => {
|
|
222
|
-
if (!line.length) {
|
|
223
|
-
onMessage?.(message);
|
|
224
|
-
message = newMessage();
|
|
225
|
-
}
|
|
226
|
-
else if (fieldLength > 0) {
|
|
227
|
-
const field = decoder.decode(line.subarray(0, fieldLength));
|
|
228
|
-
const valueOffset = fieldLength + (line[fieldLength + 1] === 32 ? 2 : 1);
|
|
229
|
-
const value = decoder.decode(line.subarray(valueOffset));
|
|
230
|
-
switch (field) {
|
|
231
|
-
case "data":
|
|
232
|
-
message.data = message.data ? `${message.data}\n${value}` : value;
|
|
233
|
-
break;
|
|
234
|
-
case "event":
|
|
235
|
-
message.event = value;
|
|
236
|
-
break;
|
|
237
|
-
case "id":
|
|
238
|
-
onId((message.id = value));
|
|
239
|
-
break;
|
|
240
|
-
case "retry": {
|
|
241
|
-
const retry = +value;
|
|
242
|
-
if (!Number.isNaN(retry)) {
|
|
243
|
-
onRetry((message.retry = retry));
|
|
244
|
-
}
|
|
245
|
-
break;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
};
|
|
250
|
-
};
|
|
251
|
-
const concat = (a, b) => {
|
|
252
|
-
const res = new Uint8Array(a.length + b.length);
|
|
253
|
-
res.set(a);
|
|
254
|
-
res.set(b, a.length);
|
|
255
|
-
return res;
|
|
256
|
-
};
|
|
257
|
-
const newMessage = () => ({
|
|
258
|
-
data: "",
|
|
259
|
-
event: "",
|
|
260
|
-
id: "",
|
|
261
|
-
retry: undefined,
|
|
262
|
-
});
|
|
263
|
-
const fetchEventSource = (input, el, { signal: inputSignal, headers: inputHeaders, onopen: inputOnOpen, onmessage, onclose, onerror, openWhenHidden, fetch: inputFetch, retry = "auto", retryInterval = 1_000, retryScaler = 2, retryMaxWaitMs = 30_000, retryMaxCount = 10, responseOverrides, ...rest }) => {
|
|
264
|
-
return new Promise((resolve, reject) => {
|
|
265
|
-
const headers = {
|
|
266
|
-
...inputHeaders,
|
|
267
|
-
};
|
|
268
|
-
let curRequestController;
|
|
269
|
-
const onVisibilityChange = () => {
|
|
270
|
-
curRequestController.abort();
|
|
271
|
-
if (!document.hidden)
|
|
272
|
-
create();
|
|
273
|
-
};
|
|
274
|
-
if (!openWhenHidden) {
|
|
275
|
-
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
276
|
-
}
|
|
277
|
-
let retryTimer;
|
|
278
|
-
const dispose = () => {
|
|
279
|
-
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
280
|
-
clearTimeout(retryTimer);
|
|
281
|
-
curRequestController.abort();
|
|
282
|
-
};
|
|
283
|
-
inputSignal?.addEventListener("abort", () => {
|
|
284
|
-
dispose();
|
|
285
|
-
resolve();
|
|
286
|
-
});
|
|
287
|
-
const fetch = inputFetch || window.fetch;
|
|
288
|
-
const onopen = inputOnOpen || (() => { });
|
|
289
|
-
let retries = 0;
|
|
290
|
-
let baseRetryInterval = retryInterval;
|
|
291
|
-
const create = async () => {
|
|
292
|
-
curRequestController = new AbortController();
|
|
293
|
-
const curRequestSignal = curRequestController.signal;
|
|
294
|
-
try {
|
|
295
|
-
const response = await fetch(input, {
|
|
296
|
-
...rest,
|
|
297
|
-
headers,
|
|
298
|
-
signal: curRequestSignal,
|
|
299
|
-
});
|
|
300
|
-
await onopen(response);
|
|
301
|
-
const dispatchNonSSE = async (dispatchType, response, name, responseOverrides, ...argNames) => {
|
|
302
|
-
const argsRaw = {
|
|
303
|
-
[name]: await response.text(),
|
|
304
|
-
};
|
|
305
|
-
for (const n of argNames) {
|
|
306
|
-
let v = response.headers.get(`datastar-${kebab(n)}`);
|
|
307
|
-
if (responseOverrides) {
|
|
308
|
-
const o = responseOverrides[n];
|
|
309
|
-
if (o)
|
|
310
|
-
v = typeof o === "string" ? o : JSON.stringify(o);
|
|
311
|
-
}
|
|
312
|
-
if (v)
|
|
313
|
-
argsRaw[n] = v;
|
|
314
|
-
}
|
|
315
|
-
dispatchFetch(dispatchType, el, argsRaw);
|
|
316
|
-
dispose();
|
|
317
|
-
resolve();
|
|
318
|
-
};
|
|
319
|
-
const status = response.status;
|
|
320
|
-
const isNoContentStatus = status === 204;
|
|
321
|
-
const isRedirectStatus = status >= 300 && status < 400;
|
|
322
|
-
const isErrorStatus = status >= 400 && status < 600;
|
|
323
|
-
if (status !== 200) {
|
|
324
|
-
onclose?.();
|
|
325
|
-
if (retry !== "never" &&
|
|
326
|
-
!isNoContentStatus &&
|
|
327
|
-
!isRedirectStatus &&
|
|
328
|
-
(retry === "always" || (retry === "error" && isErrorStatus))) {
|
|
329
|
-
clearTimeout(retryTimer);
|
|
330
|
-
retryTimer = setTimeout(create, retryInterval);
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
dispose();
|
|
334
|
-
resolve();
|
|
335
|
-
return;
|
|
336
|
-
}
|
|
337
|
-
retries = 0;
|
|
338
|
-
retryInterval = baseRetryInterval;
|
|
339
|
-
const ct = response.headers.get("Content-Type");
|
|
340
|
-
if (ct?.includes("text/html")) {
|
|
341
|
-
return await dispatchNonSSE("datastar-patch-elements", response, "elements", responseOverrides, "selector", "mode", "namespace", "useViewTransition", "namespace");
|
|
342
|
-
}
|
|
343
|
-
if (ct?.includes("application/json")) {
|
|
344
|
-
return await dispatchNonSSE("datastar-patch-signals", response, "signals", responseOverrides, "onlyIfMissing");
|
|
345
|
-
}
|
|
346
|
-
if (ct?.includes("text/javascript")) {
|
|
347
|
-
const script = document.createElement("script");
|
|
348
|
-
const scriptAttributesHeader = response.headers.get("datastar-script-attributes");
|
|
349
|
-
if (scriptAttributesHeader) {
|
|
350
|
-
for (const [name, value] of Object.entries(JSON.parse(scriptAttributesHeader))) {
|
|
351
|
-
script.setAttribute(name, value);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
script.textContent = await response.text();
|
|
355
|
-
document.head.appendChild(script);
|
|
356
|
-
dispose();
|
|
357
|
-
return;
|
|
358
|
-
}
|
|
359
|
-
await getBytes(response.body, getLines(getMessages((id) => {
|
|
360
|
-
if (id) {
|
|
361
|
-
headers["last-event-id"] = id;
|
|
362
|
-
}
|
|
363
|
-
else {
|
|
364
|
-
delete headers["last-event-id"];
|
|
365
|
-
}
|
|
366
|
-
}, (retry) => {
|
|
367
|
-
baseRetryInterval = retryInterval = retry;
|
|
368
|
-
}, onmessage)));
|
|
369
|
-
onclose?.();
|
|
370
|
-
if (retry === "always" && !isRedirectStatus) {
|
|
371
|
-
clearTimeout(retryTimer);
|
|
372
|
-
retryTimer = setTimeout(create, retryInterval);
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
dispose();
|
|
376
|
-
resolve();
|
|
377
|
-
}
|
|
378
|
-
catch (err) {
|
|
379
|
-
if (!curRequestSignal.aborted) {
|
|
380
|
-
try {
|
|
381
|
-
const interval = onerror?.(err) || retryInterval;
|
|
382
|
-
clearTimeout(retryTimer);
|
|
383
|
-
retryTimer = setTimeout(create, interval);
|
|
384
|
-
retryInterval = Math.min(retryInterval * retryScaler, retryMaxWaitMs);
|
|
385
|
-
if (++retries >= retryMaxCount) {
|
|
386
|
-
dispatchFetch(RETRIES_FAILED, el, {});
|
|
387
|
-
dispose();
|
|
388
|
-
reject("Max retries reached.");
|
|
389
|
-
}
|
|
390
|
-
else {
|
|
391
|
-
console.error(`Datastar failed to reach ${input.toString()} retrying in ${interval}ms.`);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
catch (innerErr) {
|
|
395
|
-
dispose();
|
|
396
|
-
reject(innerErr);
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
};
|
|
401
|
-
create();
|
|
402
|
-
});
|
|
403
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { action, filtered, mergePatch, startPeeking, stopPeeking, } from "../engine.js";
|
|
2
|
-
import { updateLeaves } from "../utils.js";
|
|
3
|
-
action({
|
|
4
|
-
name: "setAll",
|
|
5
|
-
apply(_, value, filter) {
|
|
6
|
-
startPeeking();
|
|
7
|
-
const masked = filtered(filter);
|
|
8
|
-
updateLeaves(masked, () => value);
|
|
9
|
-
mergePatch(masked);
|
|
10
|
-
stopPeeking();
|
|
11
|
-
},
|
|
12
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { action, filtered, mergePatch, startPeeking, stopPeeking, } from "../engine.js";
|
|
2
|
-
import { updateLeaves } from "../utils.js";
|
|
3
|
-
action({
|
|
4
|
-
name: "toggleAll",
|
|
5
|
-
apply(_, filter) {
|
|
6
|
-
startPeeking();
|
|
7
|
-
const masked = filtered(filter);
|
|
8
|
-
updateLeaves(masked, (oldValue) => !oldValue);
|
|
9
|
-
mergePatch(masked);
|
|
10
|
-
stopPeeking();
|
|
11
|
-
},
|
|
12
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { attribute, effect } from "../engine.js";
|
|
2
|
-
attribute({
|
|
3
|
-
name: "attr",
|
|
4
|
-
requirement: { value: "must" },
|
|
5
|
-
returnsValue: true,
|
|
6
|
-
apply({ el, key, rx }) {
|
|
7
|
-
const syncAttr = (key, val) => {
|
|
8
|
-
if (val === "" || val === true) {
|
|
9
|
-
el.setAttribute(key, "");
|
|
10
|
-
}
|
|
11
|
-
else if (val === false || val == null) {
|
|
12
|
-
el.removeAttribute(key);
|
|
13
|
-
}
|
|
14
|
-
else if (typeof val === "string") {
|
|
15
|
-
el.setAttribute(key, val);
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
el.setAttribute(key, JSON.stringify(val));
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
const update = key
|
|
22
|
-
? () => {
|
|
23
|
-
observer.disconnect();
|
|
24
|
-
const val = rx();
|
|
25
|
-
syncAttr(key, val);
|
|
26
|
-
observer.observe(el, {
|
|
27
|
-
attributeFilter: [key],
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
: () => {
|
|
31
|
-
observer.disconnect();
|
|
32
|
-
const obj = rx();
|
|
33
|
-
const attributeFilter = Object.keys(obj);
|
|
34
|
-
for (const key of attributeFilter) {
|
|
35
|
-
syncAttr(key, obj[key]);
|
|
36
|
-
}
|
|
37
|
-
observer.observe(el, {
|
|
38
|
-
attributeFilter,
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
const observer = new MutationObserver(update);
|
|
42
|
-
const cleanup = effect(update);
|
|
43
|
-
return () => {
|
|
44
|
-
observer.disconnect();
|
|
45
|
-
cleanup();
|
|
46
|
-
};
|
|
47
|
-
},
|
|
48
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { attribute, effect, getPath, mergePaths } from "../engine.js";
|
|
2
|
-
import { aliasify, modifyCasing } from "../utils.js";
|
|
3
|
-
const dataURIRegex = /^data:(?<mime>[^;]+);base64,(?<contents>.*)$/;
|
|
4
|
-
const empty = Symbol("empty");
|
|
5
|
-
const aliasedBind = aliasify("bind");
|
|
6
|
-
attribute({
|
|
7
|
-
name: "bind",
|
|
8
|
-
requirement: "exclusive",
|
|
9
|
-
apply({ el, key, mods, value, error }) {
|
|
10
|
-
const signalName = key != null ? modifyCasing(key, mods) : value;
|
|
11
|
-
let get = (el, type) => (type === "number" ? +el.value : el.value);
|
|
12
|
-
let set = (value) => {
|
|
13
|
-
;
|
|
14
|
-
el.value = `${value}`;
|
|
15
|
-
};
|
|
16
|
-
if (el instanceof HTMLInputElement) {
|
|
17
|
-
switch (el.type) {
|
|
18
|
-
case "range":
|
|
19
|
-
case "number":
|
|
20
|
-
get = (el, type) => (type === "string" ? el.value : +el.value);
|
|
21
|
-
break;
|
|
22
|
-
case "checkbox":
|
|
23
|
-
get = (el, type) => {
|
|
24
|
-
if (el.value !== "on") {
|
|
25
|
-
if (type === "boolean") {
|
|
26
|
-
return el.checked;
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
return el.checked ? el.value : "";
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
if (type === "string") {
|
|
34
|
-
return el.checked ? el.value : "";
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
return el.checked;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
set = (value) => {
|
|
42
|
-
el.checked = typeof value === "string" ? value === el.value : value;
|
|
43
|
-
};
|
|
44
|
-
break;
|
|
45
|
-
case "radio":
|
|
46
|
-
if (!el.getAttribute("name")?.length) {
|
|
47
|
-
el.setAttribute("name", signalName);
|
|
48
|
-
}
|
|
49
|
-
get = (el, type) => el.checked ? (type === "number" ? +el.value : el.value) : empty;
|
|
50
|
-
set = (value) => {
|
|
51
|
-
el.checked = value === (typeof value === "number" ? +el.value : el.value);
|
|
52
|
-
};
|
|
53
|
-
break;
|
|
54
|
-
case "file": {
|
|
55
|
-
const syncSignal = () => {
|
|
56
|
-
const files = [...(el.files || [])];
|
|
57
|
-
const signalFiles = [];
|
|
58
|
-
Promise.all(files.map((f) => new Promise((resolve) => {
|
|
59
|
-
const reader = new FileReader();
|
|
60
|
-
reader.onload = () => {
|
|
61
|
-
if (typeof reader.result !== "string") {
|
|
62
|
-
throw error("InvalidFileResultType", {
|
|
63
|
-
resultType: typeof reader.result,
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
const match = reader.result.match(dataURIRegex);
|
|
67
|
-
if (!match?.groups) {
|
|
68
|
-
throw error("InvalidDataUri", {
|
|
69
|
-
result: reader.result,
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
signalFiles.push({
|
|
73
|
-
name: f.name,
|
|
74
|
-
contents: match.groups.contents,
|
|
75
|
-
mime: match.groups.mime,
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
reader.onloadend = () => resolve();
|
|
79
|
-
reader.readAsDataURL(f);
|
|
80
|
-
}))).then(() => {
|
|
81
|
-
mergePaths([[signalName, signalFiles]]);
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
|
-
el.addEventListener("change", syncSignal);
|
|
85
|
-
el.addEventListener("input", syncSignal);
|
|
86
|
-
return () => {
|
|
87
|
-
el.removeEventListener("change", syncSignal);
|
|
88
|
-
el.removeEventListener("input", syncSignal);
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
else if (el instanceof HTMLSelectElement) {
|
|
94
|
-
if (el.multiple) {
|
|
95
|
-
const typeMap = new Map();
|
|
96
|
-
get = (el) => [...el.selectedOptions].map((option) => {
|
|
97
|
-
const type = typeMap.get(option.value);
|
|
98
|
-
return type === "string" || type == null ? option.value : +option.value;
|
|
99
|
-
});
|
|
100
|
-
set = (value) => {
|
|
101
|
-
for (const option of el.options) {
|
|
102
|
-
if (value.includes(option.value)) {
|
|
103
|
-
typeMap.set(option.value, "string");
|
|
104
|
-
option.selected = true;
|
|
105
|
-
}
|
|
106
|
-
else if (value.includes(+option.value)) {
|
|
107
|
-
typeMap.set(option.value, "number");
|
|
108
|
-
option.selected = true;
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
option.selected = false;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
else if (el instanceof HTMLTextAreaElement) {
|
|
118
|
-
// default case
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
// web component
|
|
122
|
-
get = (el) => ("value" in el ? el.value : el.getAttribute("value"));
|
|
123
|
-
set = (value) => {
|
|
124
|
-
if ("value" in el) {
|
|
125
|
-
el.value = value;
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
el.setAttribute("value", value);
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
const initialValue = getPath(signalName);
|
|
133
|
-
const type = typeof initialValue;
|
|
134
|
-
let path = signalName;
|
|
135
|
-
if (Array.isArray(initialValue) && !(el instanceof HTMLSelectElement && el.multiple)) {
|
|
136
|
-
const signalNameKebab = key ? key : value;
|
|
137
|
-
const inputs = document.querySelectorAll(`[${aliasedBind}\\:${CSS.escape(signalNameKebab)}],[${aliasedBind}="${CSS.escape(signalNameKebab)}"]`);
|
|
138
|
-
const paths = [];
|
|
139
|
-
let i = 0;
|
|
140
|
-
for (const input of inputs) {
|
|
141
|
-
paths.push([`${path}.${i}`, get(input, "none")]);
|
|
142
|
-
if (el === input) {
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
|
-
i++;
|
|
146
|
-
}
|
|
147
|
-
mergePaths(paths, { ifMissing: true });
|
|
148
|
-
path = `${path}.${i}`;
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
mergePaths([[path, get(el, type)]], {
|
|
152
|
-
ifMissing: true,
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
const syncSignal = () => {
|
|
156
|
-
const signalValue = getPath(path);
|
|
157
|
-
if (signalValue != null) {
|
|
158
|
-
const value = get(el, typeof signalValue);
|
|
159
|
-
if (value !== empty) {
|
|
160
|
-
mergePaths([[path, value]]);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
el.addEventListener("input", syncSignal);
|
|
165
|
-
el.addEventListener("change", syncSignal);
|
|
166
|
-
const cleanup = effect(() => {
|
|
167
|
-
set(getPath(path));
|
|
168
|
-
});
|
|
169
|
-
return () => {
|
|
170
|
-
cleanup();
|
|
171
|
-
el.removeEventListener("input", syncSignal);
|
|
172
|
-
el.removeEventListener("change", syncSignal);
|
|
173
|
-
};
|
|
174
|
-
},
|
|
175
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|