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
package/dist/datastar/engine.js
DELETED
|
@@ -1,999 +0,0 @@
|
|
|
1
|
-
import { aliasify, hasOwn, isHTMLOrSVG, isPojo, pathToObj, snake } from "./utils.js";
|
|
2
|
-
/*********
|
|
3
|
-
* consts.ts
|
|
4
|
-
*********/
|
|
5
|
-
const lol = /🖕JS_DS🚀/.source;
|
|
6
|
-
export const DSP = lol.slice(0, 5);
|
|
7
|
-
export const DSS = lol.slice(4);
|
|
8
|
-
export const DATASTAR_FETCH_EVENT = "datastar-fetch";
|
|
9
|
-
export const DATASTAR_SIGNAL_PATCH_EVENT = "datastar-signal-patch";
|
|
10
|
-
const ReactiveFlags = {
|
|
11
|
-
None: 0,
|
|
12
|
-
Mutable: 1 << 0,
|
|
13
|
-
Watching: 1 << 1,
|
|
14
|
-
RecursedCheck: 1 << 2,
|
|
15
|
-
Recursed: 1 << 3,
|
|
16
|
-
Dirty: 1 << 4,
|
|
17
|
-
Pending: 1 << 5,
|
|
18
|
-
};
|
|
19
|
-
const EffectFlags = {
|
|
20
|
-
Queued: 1 << 6,
|
|
21
|
-
};
|
|
22
|
-
const currentPatch = [];
|
|
23
|
-
const queuedEffects = [];
|
|
24
|
-
let batchDepth = 0;
|
|
25
|
-
let notifyIndex = 0;
|
|
26
|
-
let queuedEffectsLength = 0;
|
|
27
|
-
let prevSub;
|
|
28
|
-
let activeSub;
|
|
29
|
-
let version = 0;
|
|
30
|
-
export const beginBatch = () => {
|
|
31
|
-
batchDepth++;
|
|
32
|
-
};
|
|
33
|
-
export const endBatch = () => {
|
|
34
|
-
if (!--batchDepth) {
|
|
35
|
-
flush();
|
|
36
|
-
dispatch();
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
export const startPeeking = (sub) => {
|
|
40
|
-
prevSub = activeSub;
|
|
41
|
-
activeSub = sub;
|
|
42
|
-
};
|
|
43
|
-
export const stopPeeking = () => {
|
|
44
|
-
activeSub = prevSub;
|
|
45
|
-
prevSub = undefined;
|
|
46
|
-
};
|
|
47
|
-
export const signal = (initialValue) => {
|
|
48
|
-
return signalOper.bind(0, {
|
|
49
|
-
previousValue: initialValue,
|
|
50
|
-
value_: initialValue,
|
|
51
|
-
flags_: 1,
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
const computedSymbol = Symbol("computed");
|
|
55
|
-
export const computed = (getter) => {
|
|
56
|
-
const c = computedOper.bind(0, {
|
|
57
|
-
flags_: 17,
|
|
58
|
-
getter,
|
|
59
|
-
});
|
|
60
|
-
// @ts-ignore
|
|
61
|
-
c[computedSymbol] = 1;
|
|
62
|
-
return c;
|
|
63
|
-
};
|
|
64
|
-
export const effect = (fn) => {
|
|
65
|
-
const e = {
|
|
66
|
-
fn_: fn,
|
|
67
|
-
flags_: 2,
|
|
68
|
-
};
|
|
69
|
-
if (activeSub) {
|
|
70
|
-
link(e, activeSub);
|
|
71
|
-
}
|
|
72
|
-
startPeeking(e);
|
|
73
|
-
beginBatch();
|
|
74
|
-
try {
|
|
75
|
-
e.fn_();
|
|
76
|
-
}
|
|
77
|
-
finally {
|
|
78
|
-
endBatch();
|
|
79
|
-
stopPeeking();
|
|
80
|
-
}
|
|
81
|
-
return effectOper.bind(0, e);
|
|
82
|
-
};
|
|
83
|
-
const flush = () => {
|
|
84
|
-
while (notifyIndex < queuedEffectsLength) {
|
|
85
|
-
const effect = queuedEffects[notifyIndex];
|
|
86
|
-
queuedEffects[notifyIndex++] = undefined;
|
|
87
|
-
run(effect, (effect.flags_ &= ~EffectFlags.Queued));
|
|
88
|
-
}
|
|
89
|
-
notifyIndex = 0;
|
|
90
|
-
queuedEffectsLength = 0;
|
|
91
|
-
};
|
|
92
|
-
const update = (signal) => {
|
|
93
|
-
if ("getter" in signal) {
|
|
94
|
-
return updateComputed(signal);
|
|
95
|
-
}
|
|
96
|
-
return updateSignal(signal, signal.value_);
|
|
97
|
-
};
|
|
98
|
-
const updateComputed = (c) => {
|
|
99
|
-
startPeeking(c);
|
|
100
|
-
startTracking(c);
|
|
101
|
-
try {
|
|
102
|
-
const oldValue = c.value_;
|
|
103
|
-
return oldValue !== (c.value_ = c.getter(oldValue));
|
|
104
|
-
}
|
|
105
|
-
finally {
|
|
106
|
-
stopPeeking();
|
|
107
|
-
endTracking(c);
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
const updateSignal = (s, value) => {
|
|
111
|
-
s.flags_ = 1;
|
|
112
|
-
return s.previousValue !== (s.previousValue = value);
|
|
113
|
-
};
|
|
114
|
-
const notify = (e) => {
|
|
115
|
-
const flags = e.flags_;
|
|
116
|
-
if (!(flags & EffectFlags.Queued)) {
|
|
117
|
-
e.flags_ = flags | EffectFlags.Queued;
|
|
118
|
-
const subs = e.subs_;
|
|
119
|
-
if (subs) {
|
|
120
|
-
notify(subs.sub_);
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
queuedEffects[queuedEffectsLength++] = e;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
const run = (e, flags) => {
|
|
128
|
-
if (flags & 16 ||
|
|
129
|
-
(flags & 32 && checkDirty(e.deps_, e))) {
|
|
130
|
-
startPeeking(e);
|
|
131
|
-
startTracking(e);
|
|
132
|
-
beginBatch();
|
|
133
|
-
try {
|
|
134
|
-
e.fn_();
|
|
135
|
-
}
|
|
136
|
-
finally {
|
|
137
|
-
endBatch();
|
|
138
|
-
stopPeeking();
|
|
139
|
-
endTracking(e);
|
|
140
|
-
}
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
if (flags & 32) {
|
|
144
|
-
e.flags_ = flags & ~32;
|
|
145
|
-
}
|
|
146
|
-
let link = e.deps_;
|
|
147
|
-
while (link) {
|
|
148
|
-
const dep = link.dep_;
|
|
149
|
-
const depFlags = dep.flags_;
|
|
150
|
-
if (depFlags & EffectFlags.Queued) {
|
|
151
|
-
run(dep, (dep.flags_ = depFlags & ~EffectFlags.Queued));
|
|
152
|
-
}
|
|
153
|
-
link = link.nextDep_;
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
const signalOper = (s, ...value) => {
|
|
157
|
-
if (value.length) {
|
|
158
|
-
if (s.value_ !== (s.value_ = value[0])) {
|
|
159
|
-
s.flags_ = 17;
|
|
160
|
-
const subs = s.subs_;
|
|
161
|
-
if (subs) {
|
|
162
|
-
propagate(subs);
|
|
163
|
-
if (!batchDepth) {
|
|
164
|
-
flush();
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return true;
|
|
168
|
-
}
|
|
169
|
-
return false;
|
|
170
|
-
}
|
|
171
|
-
const currentValue = s.value_;
|
|
172
|
-
if (s.flags_ & 16) {
|
|
173
|
-
if (updateSignal(s, currentValue)) {
|
|
174
|
-
const subs_ = s.subs_;
|
|
175
|
-
if (subs_) {
|
|
176
|
-
shallowPropagate(subs_);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
if (activeSub) {
|
|
181
|
-
link(s, activeSub);
|
|
182
|
-
}
|
|
183
|
-
return currentValue;
|
|
184
|
-
};
|
|
185
|
-
const computedOper = (c) => {
|
|
186
|
-
const flags = c.flags_;
|
|
187
|
-
if (flags & 16 ||
|
|
188
|
-
(flags & 32 && checkDirty(c.deps_, c))) {
|
|
189
|
-
if (updateComputed(c)) {
|
|
190
|
-
const subs = c.subs_;
|
|
191
|
-
if (subs) {
|
|
192
|
-
shallowPropagate(subs);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
else if (flags & 32) {
|
|
197
|
-
c.flags_ = flags & ~32;
|
|
198
|
-
}
|
|
199
|
-
if (activeSub) {
|
|
200
|
-
link(c, activeSub);
|
|
201
|
-
}
|
|
202
|
-
return c.value_;
|
|
203
|
-
};
|
|
204
|
-
const effectOper = (e) => {
|
|
205
|
-
let dep = e.deps_;
|
|
206
|
-
while (dep) {
|
|
207
|
-
dep = unlink(dep, e);
|
|
208
|
-
}
|
|
209
|
-
const sub = e.subs_;
|
|
210
|
-
if (sub) {
|
|
211
|
-
unlink(sub);
|
|
212
|
-
}
|
|
213
|
-
e.flags_ = 0;
|
|
214
|
-
};
|
|
215
|
-
const link = (dep, sub) => {
|
|
216
|
-
const prevDep = sub.depsTail_;
|
|
217
|
-
if (prevDep && prevDep.dep_ === dep) {
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
const nextDep = prevDep ? prevDep.nextDep_ : sub.deps_;
|
|
221
|
-
if (nextDep && nextDep.dep_ === dep) {
|
|
222
|
-
nextDep.version_ = version;
|
|
223
|
-
sub.depsTail_ = nextDep;
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
const prevSub = dep.subsTail_;
|
|
227
|
-
if (prevSub && prevSub.version_ === version && prevSub.sub_ === sub) {
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
const newLink = (sub.depsTail_ =
|
|
231
|
-
dep.subsTail_ =
|
|
232
|
-
{
|
|
233
|
-
version_: version,
|
|
234
|
-
dep_: dep,
|
|
235
|
-
sub_: sub,
|
|
236
|
-
prevDep_: prevDep,
|
|
237
|
-
nextDep_: nextDep,
|
|
238
|
-
prevSub_: prevSub,
|
|
239
|
-
});
|
|
240
|
-
if (nextDep) {
|
|
241
|
-
nextDep.prevDep_ = newLink;
|
|
242
|
-
}
|
|
243
|
-
if (prevDep) {
|
|
244
|
-
prevDep.nextDep_ = newLink;
|
|
245
|
-
}
|
|
246
|
-
else {
|
|
247
|
-
sub.deps_ = newLink;
|
|
248
|
-
}
|
|
249
|
-
if (prevSub) {
|
|
250
|
-
prevSub.nextSub_ = newLink;
|
|
251
|
-
}
|
|
252
|
-
else {
|
|
253
|
-
dep.subs_ = newLink;
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
const unlink = (link, sub = link.sub_) => {
|
|
257
|
-
const dep_ = link.dep_;
|
|
258
|
-
const prevDep_ = link.prevDep_;
|
|
259
|
-
const nextDep_ = link.nextDep_;
|
|
260
|
-
const nextSub_ = link.nextSub_;
|
|
261
|
-
const prevSub_ = link.prevSub_;
|
|
262
|
-
if (nextDep_) {
|
|
263
|
-
nextDep_.prevDep_ = prevDep_;
|
|
264
|
-
}
|
|
265
|
-
else {
|
|
266
|
-
sub.depsTail_ = prevDep_;
|
|
267
|
-
}
|
|
268
|
-
if (prevDep_) {
|
|
269
|
-
prevDep_.nextDep_ = nextDep_;
|
|
270
|
-
}
|
|
271
|
-
else {
|
|
272
|
-
sub.deps_ = nextDep_;
|
|
273
|
-
}
|
|
274
|
-
if (nextSub_) {
|
|
275
|
-
nextSub_.prevSub_ = prevSub_;
|
|
276
|
-
}
|
|
277
|
-
else {
|
|
278
|
-
dep_.subsTail_ = prevSub_;
|
|
279
|
-
}
|
|
280
|
-
if (prevSub_) {
|
|
281
|
-
prevSub_.nextSub_ = nextSub_;
|
|
282
|
-
}
|
|
283
|
-
else if (!(dep_.subs_ = nextSub_)) {
|
|
284
|
-
if ("getter" in dep_) {
|
|
285
|
-
let toRemove = dep_.deps_;
|
|
286
|
-
if (toRemove) {
|
|
287
|
-
dep_.flags_ = 17;
|
|
288
|
-
do {
|
|
289
|
-
toRemove = unlink(toRemove, dep_);
|
|
290
|
-
} while (toRemove);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
else if (!("previousValue" in dep_)) {
|
|
294
|
-
effectOper(dep_);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
return nextDep_;
|
|
298
|
-
};
|
|
299
|
-
const propagate = (link) => {
|
|
300
|
-
let next = link.nextSub_;
|
|
301
|
-
let stack;
|
|
302
|
-
top: while (true) {
|
|
303
|
-
const sub = link.sub_;
|
|
304
|
-
let flags = sub.flags_;
|
|
305
|
-
if (!(flags &
|
|
306
|
-
60)) {
|
|
307
|
-
sub.flags_ = flags | 32;
|
|
308
|
-
}
|
|
309
|
-
else if (!(flags & 12)) {
|
|
310
|
-
flags = 0;
|
|
311
|
-
}
|
|
312
|
-
else if (!(flags & 4)) {
|
|
313
|
-
sub.flags_ =
|
|
314
|
-
(flags & ~8) | 32;
|
|
315
|
-
}
|
|
316
|
-
else if (!(flags & 48) &&
|
|
317
|
-
isValidLink(link, sub)) {
|
|
318
|
-
sub.flags_ = flags | 40;
|
|
319
|
-
flags &= 1;
|
|
320
|
-
}
|
|
321
|
-
else {
|
|
322
|
-
flags = 0;
|
|
323
|
-
}
|
|
324
|
-
if (flags & 2) {
|
|
325
|
-
notify(sub);
|
|
326
|
-
}
|
|
327
|
-
if (flags & 1) {
|
|
328
|
-
const subSubs = sub.subs_;
|
|
329
|
-
if (subSubs) {
|
|
330
|
-
const nextSub = (link = subSubs).nextSub_;
|
|
331
|
-
if (nextSub) {
|
|
332
|
-
stack = { value_: next, prev_: stack };
|
|
333
|
-
next = nextSub;
|
|
334
|
-
}
|
|
335
|
-
continue;
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
if ((link = next)) {
|
|
339
|
-
next = link.nextSub_;
|
|
340
|
-
continue;
|
|
341
|
-
}
|
|
342
|
-
while (stack) {
|
|
343
|
-
link = stack.value_;
|
|
344
|
-
stack = stack.prev_;
|
|
345
|
-
if (link) {
|
|
346
|
-
next = link.nextSub_;
|
|
347
|
-
continue top;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
break;
|
|
351
|
-
}
|
|
352
|
-
};
|
|
353
|
-
const startTracking = (sub) => {
|
|
354
|
-
version++;
|
|
355
|
-
sub.depsTail_ = undefined;
|
|
356
|
-
sub.flags_ =
|
|
357
|
-
(sub.flags_ & ~56) |
|
|
358
|
-
4;
|
|
359
|
-
};
|
|
360
|
-
const endTracking = (sub) => {
|
|
361
|
-
const depsTail_ = sub.depsTail_;
|
|
362
|
-
let toRemove = depsTail_ ? depsTail_.nextDep_ : sub.deps_;
|
|
363
|
-
while (toRemove) {
|
|
364
|
-
toRemove = unlink(toRemove, sub);
|
|
365
|
-
}
|
|
366
|
-
sub.flags_ &= ~4;
|
|
367
|
-
};
|
|
368
|
-
const checkDirty = (link, sub) => {
|
|
369
|
-
let stack;
|
|
370
|
-
let checkDepth = 0;
|
|
371
|
-
let dirty = false;
|
|
372
|
-
top: while (true) {
|
|
373
|
-
const dep = link.dep_;
|
|
374
|
-
const flags = dep.flags_;
|
|
375
|
-
if (sub.flags_ & 16) {
|
|
376
|
-
dirty = true;
|
|
377
|
-
}
|
|
378
|
-
else if ((flags & 17) ===
|
|
379
|
-
17) {
|
|
380
|
-
if (update(dep)) {
|
|
381
|
-
const subs = dep.subs_;
|
|
382
|
-
if (subs.nextSub_) {
|
|
383
|
-
shallowPropagate(subs);
|
|
384
|
-
}
|
|
385
|
-
dirty = true;
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
else if ((flags & 33) ===
|
|
389
|
-
33) {
|
|
390
|
-
if (link.nextSub_ || link.prevSub_) {
|
|
391
|
-
stack = { value_: link, prev_: stack };
|
|
392
|
-
}
|
|
393
|
-
link = dep.deps_;
|
|
394
|
-
sub = dep;
|
|
395
|
-
++checkDepth;
|
|
396
|
-
continue;
|
|
397
|
-
}
|
|
398
|
-
if (!dirty) {
|
|
399
|
-
const nextDep = link.nextDep_;
|
|
400
|
-
if (nextDep) {
|
|
401
|
-
link = nextDep;
|
|
402
|
-
continue;
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
while (checkDepth--) {
|
|
406
|
-
const firstSub = sub.subs_;
|
|
407
|
-
const hasMultipleSubs = firstSub.nextSub_;
|
|
408
|
-
if (hasMultipleSubs) {
|
|
409
|
-
link = stack.value_;
|
|
410
|
-
stack = stack.prev_;
|
|
411
|
-
}
|
|
412
|
-
else {
|
|
413
|
-
link = firstSub;
|
|
414
|
-
}
|
|
415
|
-
if (dirty) {
|
|
416
|
-
if (update(sub)) {
|
|
417
|
-
if (hasMultipleSubs) {
|
|
418
|
-
shallowPropagate(firstSub);
|
|
419
|
-
}
|
|
420
|
-
sub = link.sub_;
|
|
421
|
-
continue;
|
|
422
|
-
}
|
|
423
|
-
dirty = false;
|
|
424
|
-
}
|
|
425
|
-
else {
|
|
426
|
-
sub.flags_ &= ~32;
|
|
427
|
-
}
|
|
428
|
-
sub = link.sub_;
|
|
429
|
-
if (link.nextDep_) {
|
|
430
|
-
link = link.nextDep_;
|
|
431
|
-
continue top;
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
return dirty;
|
|
435
|
-
}
|
|
436
|
-
};
|
|
437
|
-
const shallowPropagate = (link) => {
|
|
438
|
-
do {
|
|
439
|
-
const sub = link.sub_;
|
|
440
|
-
const flags = sub.flags_;
|
|
441
|
-
if ((flags & 48) ===
|
|
442
|
-
32) {
|
|
443
|
-
sub.flags_ = flags | 16;
|
|
444
|
-
if (flags & 2) {
|
|
445
|
-
notify(sub);
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
} while ((link = link.nextSub_));
|
|
449
|
-
};
|
|
450
|
-
const isValidLink = (checkLink, sub) => {
|
|
451
|
-
let link = sub.depsTail_;
|
|
452
|
-
while (link) {
|
|
453
|
-
if (link === checkLink) {
|
|
454
|
-
return true;
|
|
455
|
-
}
|
|
456
|
-
link = link.prevDep_;
|
|
457
|
-
}
|
|
458
|
-
return false;
|
|
459
|
-
};
|
|
460
|
-
export const getPath = (path) => {
|
|
461
|
-
let result = root;
|
|
462
|
-
const split = path.split(".");
|
|
463
|
-
for (const path of split) {
|
|
464
|
-
if (result == null || !hasOwn(result, path)) {
|
|
465
|
-
return;
|
|
466
|
-
}
|
|
467
|
-
result = result[path];
|
|
468
|
-
}
|
|
469
|
-
return result;
|
|
470
|
-
};
|
|
471
|
-
const deep = (value, prefix = "") => {
|
|
472
|
-
const isArr = Array.isArray(value);
|
|
473
|
-
if (isArr || isPojo(value)) {
|
|
474
|
-
const deepObj = (isArr ? [] : {});
|
|
475
|
-
for (const key in value) {
|
|
476
|
-
deepObj[key] = signal(deep(value[key], `${prefix + key}.`));
|
|
477
|
-
}
|
|
478
|
-
const keys = signal(0);
|
|
479
|
-
return new Proxy(deepObj, {
|
|
480
|
-
get(_, prop) {
|
|
481
|
-
if (!(prop === "toJSON" && !hasOwn(deepObj, prop))) {
|
|
482
|
-
if (isArr && prop in Array.prototype) {
|
|
483
|
-
keys();
|
|
484
|
-
return deepObj[prop];
|
|
485
|
-
}
|
|
486
|
-
if (typeof prop === "symbol") {
|
|
487
|
-
return deepObj[prop];
|
|
488
|
-
}
|
|
489
|
-
if (!hasOwn(deepObj, prop) || deepObj[prop]() == null) {
|
|
490
|
-
deepObj[prop] = signal("");
|
|
491
|
-
dispatch(prefix + prop, "");
|
|
492
|
-
keys(keys() + 1);
|
|
493
|
-
}
|
|
494
|
-
return deepObj[prop]();
|
|
495
|
-
}
|
|
496
|
-
},
|
|
497
|
-
set(_, prop, newValue) {
|
|
498
|
-
const path = prefix + prop;
|
|
499
|
-
if (isArr && prop === "length") {
|
|
500
|
-
const diff = deepObj[prop] - newValue;
|
|
501
|
-
deepObj[prop] = newValue;
|
|
502
|
-
if (diff > 0) {
|
|
503
|
-
const patch = {};
|
|
504
|
-
for (let i = newValue; i < deepObj[prop]; i++) {
|
|
505
|
-
patch[i] = null;
|
|
506
|
-
}
|
|
507
|
-
dispatch(prefix.slice(0, -1), patch);
|
|
508
|
-
keys(keys() + 1);
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
else if (hasOwn(deepObj, prop)) {
|
|
512
|
-
if (newValue == null) {
|
|
513
|
-
delete deepObj[prop];
|
|
514
|
-
}
|
|
515
|
-
else if (hasOwn(newValue, computedSymbol)) {
|
|
516
|
-
deepObj[prop] = newValue;
|
|
517
|
-
dispatch(path, "");
|
|
518
|
-
}
|
|
519
|
-
else {
|
|
520
|
-
const currentValue = deepObj[prop]();
|
|
521
|
-
const pathStr = `${path}.`;
|
|
522
|
-
if (isPojo(currentValue) && isPojo(newValue)) {
|
|
523
|
-
for (const key in currentValue) {
|
|
524
|
-
if (!hasOwn(newValue, key)) {
|
|
525
|
-
delete currentValue[key];
|
|
526
|
-
dispatch(pathStr + key, null);
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
for (const key in newValue) {
|
|
530
|
-
const nextVal = newValue[key];
|
|
531
|
-
if (currentValue[key] !== nextVal) {
|
|
532
|
-
currentValue[key] = nextVal;
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
else if (deepObj[prop](deep(newValue, pathStr))) {
|
|
537
|
-
dispatch(path, newValue);
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
else if (newValue != null) {
|
|
542
|
-
if (hasOwn(newValue, computedSymbol)) {
|
|
543
|
-
deepObj[prop] = newValue;
|
|
544
|
-
dispatch(path, "");
|
|
545
|
-
}
|
|
546
|
-
else {
|
|
547
|
-
deepObj[prop] = signal(deep(newValue, `${path}.`));
|
|
548
|
-
dispatch(path, newValue);
|
|
549
|
-
}
|
|
550
|
-
keys(keys() + 1);
|
|
551
|
-
}
|
|
552
|
-
return true;
|
|
553
|
-
},
|
|
554
|
-
deleteProperty(_, prop) {
|
|
555
|
-
delete deepObj[prop];
|
|
556
|
-
keys(keys() + 1);
|
|
557
|
-
return true;
|
|
558
|
-
},
|
|
559
|
-
ownKeys() {
|
|
560
|
-
keys();
|
|
561
|
-
return Reflect.ownKeys(deepObj);
|
|
562
|
-
},
|
|
563
|
-
has(_, prop) {
|
|
564
|
-
keys();
|
|
565
|
-
return prop in deepObj;
|
|
566
|
-
},
|
|
567
|
-
});
|
|
568
|
-
}
|
|
569
|
-
return value;
|
|
570
|
-
};
|
|
571
|
-
const dispatch = (path, value) => {
|
|
572
|
-
if (path !== undefined && value !== undefined) {
|
|
573
|
-
currentPatch.push([path, value]);
|
|
574
|
-
}
|
|
575
|
-
if (!batchDepth && currentPatch.length) {
|
|
576
|
-
const detail = pathToObj(currentPatch);
|
|
577
|
-
currentPatch.length = 0;
|
|
578
|
-
document.dispatchEvent(new CustomEvent(DATASTAR_SIGNAL_PATCH_EVENT, {
|
|
579
|
-
detail,
|
|
580
|
-
}));
|
|
581
|
-
}
|
|
582
|
-
};
|
|
583
|
-
export const mergePatch = (patch, { ifMissing } = {}) => {
|
|
584
|
-
beginBatch();
|
|
585
|
-
for (const key in patch) {
|
|
586
|
-
if (patch[key] == null) {
|
|
587
|
-
if (!ifMissing) {
|
|
588
|
-
delete root[key];
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
else {
|
|
592
|
-
mergeInner(patch[key], key, root, "", ifMissing);
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
endBatch();
|
|
596
|
-
};
|
|
597
|
-
export const mergePaths = (paths, options) => mergePatch(pathToObj(paths), options);
|
|
598
|
-
const mergeInner = (patch, target, targetParent, prefix, ifMissing) => {
|
|
599
|
-
if (isPojo(patch)) {
|
|
600
|
-
if (!(hasOwn(targetParent, target) &&
|
|
601
|
-
(isPojo(targetParent[target]) || Array.isArray(targetParent[target])))) {
|
|
602
|
-
targetParent[target] = {};
|
|
603
|
-
}
|
|
604
|
-
for (const key in patch) {
|
|
605
|
-
if (patch[key] == null) {
|
|
606
|
-
if (!ifMissing) {
|
|
607
|
-
delete targetParent[target][key];
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
else {
|
|
611
|
-
mergeInner(patch[key], key, targetParent[target], `${prefix + target}.`, ifMissing);
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
else if (!(ifMissing && hasOwn(targetParent, target))) {
|
|
616
|
-
targetParent[target] = patch;
|
|
617
|
-
}
|
|
618
|
-
};
|
|
619
|
-
const toRegExp = (val) => typeof val === "string" ? RegExp(val.replace(/^\/|\/$/g, "")) : val;
|
|
620
|
-
export const filtered = ({ include = /.*/, exclude = /(?!)/ } = {}, obj = root) => {
|
|
621
|
-
const includeRe = toRegExp(include);
|
|
622
|
-
const excludeRe = toRegExp(exclude);
|
|
623
|
-
const paths = [];
|
|
624
|
-
const stack = [[obj, ""]];
|
|
625
|
-
while (stack.length) {
|
|
626
|
-
const [node, prefix] = stack.pop();
|
|
627
|
-
for (const key in node) {
|
|
628
|
-
const path = prefix + key;
|
|
629
|
-
if (isPojo(node[key])) {
|
|
630
|
-
stack.push([node[key], `${path}.`]);
|
|
631
|
-
}
|
|
632
|
-
else if (includeRe.test(path) && !excludeRe.test(path)) {
|
|
633
|
-
paths.push([path, getPath(path)]);
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
return pathToObj(paths);
|
|
638
|
-
};
|
|
639
|
-
export const root = deep({});
|
|
640
|
-
/*********
|
|
641
|
-
* engine.ts (plugin system)
|
|
642
|
-
*********/
|
|
643
|
-
const url = "https://data-star.dev/errors";
|
|
644
|
-
const error = (ctx, reason, metadata = {}) => {
|
|
645
|
-
Object.assign(metadata, ctx);
|
|
646
|
-
const e = new Error();
|
|
647
|
-
const r = snake(reason);
|
|
648
|
-
const q = new URLSearchParams({
|
|
649
|
-
metadata: JSON.stringify(metadata),
|
|
650
|
-
}).toString();
|
|
651
|
-
const c = JSON.stringify(metadata, null, 2);
|
|
652
|
-
e.message = `${reason}\nMore info: ${url}/${r}?${q}\nContext: ${c}`;
|
|
653
|
-
return e;
|
|
654
|
-
};
|
|
655
|
-
const actionPlugins = new Map();
|
|
656
|
-
const attributePlugins = new Map();
|
|
657
|
-
const watcherPlugins = new Map();
|
|
658
|
-
export const actions = new Proxy({}, {
|
|
659
|
-
get: (_, prop) => actionPlugins.get(prop)?.apply,
|
|
660
|
-
has: (_, prop) => actionPlugins.has(prop),
|
|
661
|
-
ownKeys: () => Reflect.ownKeys(actionPlugins),
|
|
662
|
-
set: () => false,
|
|
663
|
-
deleteProperty: () => false,
|
|
664
|
-
});
|
|
665
|
-
const removals = new Map();
|
|
666
|
-
const queuedAttributes = [];
|
|
667
|
-
const queuedAttributeNames = new Set();
|
|
668
|
-
const observedRoots = new WeakSet();
|
|
669
|
-
export const attribute = (plugin) => {
|
|
670
|
-
queuedAttributes.push(plugin);
|
|
671
|
-
if (queuedAttributes.length === 1) {
|
|
672
|
-
setTimeout(() => {
|
|
673
|
-
for (const attribute of queuedAttributes) {
|
|
674
|
-
queuedAttributeNames.add(attribute.name);
|
|
675
|
-
attributePlugins.set(attribute.name, attribute);
|
|
676
|
-
}
|
|
677
|
-
queuedAttributes.length = 0;
|
|
678
|
-
apply();
|
|
679
|
-
queuedAttributeNames.clear();
|
|
680
|
-
});
|
|
681
|
-
}
|
|
682
|
-
};
|
|
683
|
-
export const action = (plugin) => {
|
|
684
|
-
actionPlugins.set(plugin.name, plugin);
|
|
685
|
-
};
|
|
686
|
-
document.addEventListener(DATASTAR_FETCH_EVENT, ((evt) => {
|
|
687
|
-
const plugin = watcherPlugins.get(evt.detail.type);
|
|
688
|
-
if (plugin) {
|
|
689
|
-
plugin.apply({
|
|
690
|
-
error: error.bind(0, {
|
|
691
|
-
plugin: { type: "watcher", name: plugin.name },
|
|
692
|
-
element: {
|
|
693
|
-
id: evt.target.id,
|
|
694
|
-
tag: evt.target.tagName,
|
|
695
|
-
},
|
|
696
|
-
}),
|
|
697
|
-
}, evt.detail.argsRaw);
|
|
698
|
-
}
|
|
699
|
-
}));
|
|
700
|
-
export const watcher = (plugin) => {
|
|
701
|
-
watcherPlugins.set(plugin.name, plugin);
|
|
702
|
-
};
|
|
703
|
-
const cleanupEls = (els) => {
|
|
704
|
-
for (const el of els) {
|
|
705
|
-
const elCleanups = removals.get(el);
|
|
706
|
-
if (elCleanups && removals.delete(el)) {
|
|
707
|
-
for (const attrCleanups of elCleanups.values()) {
|
|
708
|
-
for (const cleanup of attrCleanups.values()) {
|
|
709
|
-
cleanup();
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
};
|
|
715
|
-
const aliasedIgnore = aliasify("ignore");
|
|
716
|
-
const aliasedIgnoreAttr = `[${aliasedIgnore}]`;
|
|
717
|
-
const shouldIgnore = (el) => el.hasAttribute(`${aliasedIgnore}__self`) || !!el.closest(aliasedIgnoreAttr);
|
|
718
|
-
const applyEls = (els, onlyNew) => {
|
|
719
|
-
for (const el of els) {
|
|
720
|
-
if (!shouldIgnore(el)) {
|
|
721
|
-
for (const key in el.dataset) {
|
|
722
|
-
applyAttributePlugin(el, key.replace(/[A-Z]/g, "-$&").toLowerCase(), el.dataset[key], onlyNew);
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
};
|
|
727
|
-
const observe = (mutations) => {
|
|
728
|
-
for (const { target, type, attributeName, addedNodes, removedNodes } of mutations) {
|
|
729
|
-
if (type === "childList") {
|
|
730
|
-
for (const node of removedNodes) {
|
|
731
|
-
if (isHTMLOrSVG(node)) {
|
|
732
|
-
cleanupEls([node]);
|
|
733
|
-
cleanupEls(node.querySelectorAll("*"));
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
for (const node of addedNodes) {
|
|
737
|
-
if (isHTMLOrSVG(node)) {
|
|
738
|
-
applyEls([node]);
|
|
739
|
-
applyEls(node.querySelectorAll("*"));
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
else if (type === "attributes" &&
|
|
744
|
-
attributeName.startsWith("data-") &&
|
|
745
|
-
isHTMLOrSVG(target) &&
|
|
746
|
-
!shouldIgnore(target)) {
|
|
747
|
-
const key = attributeName.slice(5);
|
|
748
|
-
const value = target.getAttribute(attributeName);
|
|
749
|
-
if (value === null) {
|
|
750
|
-
const elCleanups = removals.get(target);
|
|
751
|
-
if (elCleanups) {
|
|
752
|
-
const attrCleanups = elCleanups.get(key);
|
|
753
|
-
if (attrCleanups) {
|
|
754
|
-
for (const cleanup of attrCleanups.values()) {
|
|
755
|
-
cleanup();
|
|
756
|
-
}
|
|
757
|
-
elCleanups.delete(key);
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
else {
|
|
762
|
-
applyAttributePlugin(target, key, value);
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
};
|
|
767
|
-
const mutationObserver = new MutationObserver(observe);
|
|
768
|
-
export const parseAttributeKey = (rawKey) => {
|
|
769
|
-
const [namePart, ...rawModifiers] = rawKey.split("__");
|
|
770
|
-
const [pluginName, key] = namePart.split(/:(.+)/);
|
|
771
|
-
const mods = new Map();
|
|
772
|
-
for (const rawMod of rawModifiers) {
|
|
773
|
-
const [label, ...mod] = rawMod.split(".");
|
|
774
|
-
mods.set(label, new Set(mod));
|
|
775
|
-
}
|
|
776
|
-
return { pluginName, key, mods };
|
|
777
|
-
};
|
|
778
|
-
export const isDocumentObserverActive = () => observedRoots.has(document.documentElement);
|
|
779
|
-
export const apply = (root = document.documentElement, observeRoot = true) => {
|
|
780
|
-
if (isHTMLOrSVG(root)) {
|
|
781
|
-
applyEls([root], true);
|
|
782
|
-
}
|
|
783
|
-
applyEls(root.querySelectorAll("*"), true);
|
|
784
|
-
if (observeRoot) {
|
|
785
|
-
mutationObserver.observe(root, {
|
|
786
|
-
subtree: true,
|
|
787
|
-
childList: true,
|
|
788
|
-
attributes: true,
|
|
789
|
-
});
|
|
790
|
-
observedRoots.add(root);
|
|
791
|
-
}
|
|
792
|
-
};
|
|
793
|
-
const applyAttributePlugin = (el, attrKey, value, onlyNew) => {
|
|
794
|
-
const rawKey = attrKey;
|
|
795
|
-
const { pluginName, key, mods } = parseAttributeKey(rawKey);
|
|
796
|
-
const plugin = attributePlugins.get(pluginName);
|
|
797
|
-
if ((!onlyNew || queuedAttributeNames.has(pluginName)) && plugin) {
|
|
798
|
-
const ctx = {
|
|
799
|
-
el,
|
|
800
|
-
rawKey,
|
|
801
|
-
mods,
|
|
802
|
-
error: error.bind(0, {
|
|
803
|
-
plugin: { type: "attribute", name: plugin.name },
|
|
804
|
-
element: { id: el.id, tag: el.tagName },
|
|
805
|
-
expression: { rawKey, key, value },
|
|
806
|
-
}),
|
|
807
|
-
key,
|
|
808
|
-
value,
|
|
809
|
-
loadedPluginNames: {
|
|
810
|
-
actions: new Set(actionPlugins.keys()),
|
|
811
|
-
attributes: new Set(attributePlugins.keys()),
|
|
812
|
-
},
|
|
813
|
-
rx: undefined,
|
|
814
|
-
};
|
|
815
|
-
const keyReq = (plugin.requirement &&
|
|
816
|
-
(typeof plugin.requirement === "string" ? plugin.requirement : plugin.requirement.key)) ||
|
|
817
|
-
"allowed";
|
|
818
|
-
const valueReq = (plugin.requirement &&
|
|
819
|
-
(typeof plugin.requirement === "string" ? plugin.requirement : plugin.requirement.value)) ||
|
|
820
|
-
"allowed";
|
|
821
|
-
const keyProvided = key !== undefined && key !== null && key !== "";
|
|
822
|
-
const valueProvided = value !== undefined && value !== null && value !== "";
|
|
823
|
-
if (keyProvided) {
|
|
824
|
-
if (keyReq === "denied") {
|
|
825
|
-
throw ctx.error("KeyNotAllowed");
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
else if (keyReq === "must") {
|
|
829
|
-
throw ctx.error("KeyRequired");
|
|
830
|
-
}
|
|
831
|
-
if (valueProvided) {
|
|
832
|
-
if (valueReq === "denied") {
|
|
833
|
-
throw ctx.error("ValueNotAllowed");
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
else if (valueReq === "must") {
|
|
837
|
-
throw ctx.error("ValueRequired");
|
|
838
|
-
}
|
|
839
|
-
if (keyReq === "exclusive" || valueReq === "exclusive") {
|
|
840
|
-
if (keyProvided && valueProvided) {
|
|
841
|
-
throw ctx.error("KeyAndValueProvided");
|
|
842
|
-
}
|
|
843
|
-
if (!keyProvided && !valueProvided) {
|
|
844
|
-
throw ctx.error("KeyOrValueRequired");
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
const cleanups = new Map();
|
|
848
|
-
if (valueProvided) {
|
|
849
|
-
let cachedRx;
|
|
850
|
-
ctx.rx = (...args) => {
|
|
851
|
-
if (!cachedRx) {
|
|
852
|
-
cachedRx = genRx(value, {
|
|
853
|
-
returnsValue: plugin.returnsValue,
|
|
854
|
-
argNames: plugin.argNames,
|
|
855
|
-
cleanups,
|
|
856
|
-
});
|
|
857
|
-
}
|
|
858
|
-
return cachedRx(el, ...args);
|
|
859
|
-
};
|
|
860
|
-
}
|
|
861
|
-
const cleanup = plugin.apply(ctx);
|
|
862
|
-
if (cleanup) {
|
|
863
|
-
cleanups.set("attribute", cleanup);
|
|
864
|
-
}
|
|
865
|
-
let elCleanups = removals.get(el);
|
|
866
|
-
if (elCleanups) {
|
|
867
|
-
const attrCleanups = elCleanups.get(rawKey);
|
|
868
|
-
if (attrCleanups) {
|
|
869
|
-
for (const oldCleanup of attrCleanups.values()) {
|
|
870
|
-
oldCleanup();
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
else {
|
|
875
|
-
elCleanups = new Map();
|
|
876
|
-
removals.set(el, elCleanups);
|
|
877
|
-
}
|
|
878
|
-
elCleanups.set(rawKey, cleanups);
|
|
879
|
-
}
|
|
880
|
-
};
|
|
881
|
-
const genRx = (value, { returnsValue = false, argNames = [], cleanups = new Map() } = {}) => {
|
|
882
|
-
if (/^\s*(?:async\s+)?(?:\(.*?\)\s*=>|[\w$]+\s*=>|function\s*[\w$]*\s*\()/.test(value)) {
|
|
883
|
-
const userFn = Function(`return (${value.trim()})`)();
|
|
884
|
-
return (el, ...args) => {
|
|
885
|
-
const actionsProxy = new Proxy({}, {
|
|
886
|
-
get: (_, name) => (...actionArgs) => {
|
|
887
|
-
const err = error.bind(0, {
|
|
888
|
-
plugin: { type: "action", name },
|
|
889
|
-
element: { id: el.id, tag: el.tagName },
|
|
890
|
-
expression: { fnContent: value, value },
|
|
891
|
-
});
|
|
892
|
-
const fn = actions[name];
|
|
893
|
-
if (fn)
|
|
894
|
-
return fn({ el, evt: undefined, error: err, cleanups }, ...actionArgs);
|
|
895
|
-
throw err("UndefinedAction");
|
|
896
|
-
},
|
|
897
|
-
});
|
|
898
|
-
const dataEvt = args[0] instanceof Event ? args[0] : new Event("datastar:expression");
|
|
899
|
-
Object.defineProperties(dataEvt, {
|
|
900
|
-
target: { value: el },
|
|
901
|
-
signals: { value: root },
|
|
902
|
-
actions: { value: actionsProxy },
|
|
903
|
-
window: { value: window },
|
|
904
|
-
});
|
|
905
|
-
try {
|
|
906
|
-
return userFn(dataEvt);
|
|
907
|
-
}
|
|
908
|
-
catch (e) {
|
|
909
|
-
console.error(e);
|
|
910
|
-
throw error({
|
|
911
|
-
element: { id: el.id, tag: el.tagName },
|
|
912
|
-
expression: { fnContent: value, value },
|
|
913
|
-
error: e.message,
|
|
914
|
-
}, "ExecuteExpression");
|
|
915
|
-
}
|
|
916
|
-
};
|
|
917
|
-
}
|
|
918
|
-
let expr = "";
|
|
919
|
-
if (returnsValue) {
|
|
920
|
-
const statementRe = /(\/(\\\/|[^/])*\/|"(\\"|[^"])*"|'(\\'|[^'])*'|`(\\`|[^`])*`|\(\s*((function)\s*\(\s*\)|(\(\s*\))\s*=>)\s*(?:\{[\s\S]*?\}|[^;){]*)\s*\)\s*\(\s*\)|[^;])+/gm;
|
|
921
|
-
const statements = value.trim().match(statementRe);
|
|
922
|
-
if (statements) {
|
|
923
|
-
const lastIdx = statements.length - 1;
|
|
924
|
-
const last = statements[lastIdx].trim();
|
|
925
|
-
if (!last.startsWith("return")) {
|
|
926
|
-
statements[lastIdx] = `return (${last});`;
|
|
927
|
-
}
|
|
928
|
-
expr = statements.join(";\n");
|
|
929
|
-
}
|
|
930
|
-
}
|
|
931
|
-
else {
|
|
932
|
-
expr = value.trim();
|
|
933
|
-
}
|
|
934
|
-
const escaped = new Map();
|
|
935
|
-
const escapeRe = RegExp(`(?:${DSP})(.*?)(?:${DSS})`, "gm");
|
|
936
|
-
let counter = 0;
|
|
937
|
-
for (const match of expr.matchAll(escapeRe)) {
|
|
938
|
-
const k = match[1];
|
|
939
|
-
const v = `__escaped${counter++}`;
|
|
940
|
-
escaped.set(v, k);
|
|
941
|
-
expr = expr.replace(DSP + k + DSS, v);
|
|
942
|
-
}
|
|
943
|
-
expr = expr
|
|
944
|
-
.replace(/\$\['([a-zA-Z_$\d][\w$]*)'\]/g, "$$$1")
|
|
945
|
-
.replace(/\$([a-zA-Z_\d]\w*(?:[.-]\w+)*)/g, (_, signalName) => signalName.split(".").reduce((acc, part) => `${acc}['${part}']`, "$"));
|
|
946
|
-
expr = expr.replaceAll(/@([A-Za-z_$][\w$]*)\(/g, '__action("$1",evt,');
|
|
947
|
-
for (const [k, v] of escaped) {
|
|
948
|
-
expr = expr.replace(k, v);
|
|
949
|
-
}
|
|
950
|
-
try {
|
|
951
|
-
const fn = Function("el", "$", "__action", "evt", ...argNames, expr);
|
|
952
|
-
return (el, ...args) => {
|
|
953
|
-
const action = (name, evt, ...args) => {
|
|
954
|
-
const err = error.bind(0, {
|
|
955
|
-
plugin: { type: "action", name },
|
|
956
|
-
element: { id: el.id, tag: el.tagName },
|
|
957
|
-
expression: {
|
|
958
|
-
fnContent: expr,
|
|
959
|
-
value,
|
|
960
|
-
},
|
|
961
|
-
});
|
|
962
|
-
const fn = actions[name];
|
|
963
|
-
if (fn) {
|
|
964
|
-
return fn({
|
|
965
|
-
el,
|
|
966
|
-
evt,
|
|
967
|
-
error: err,
|
|
968
|
-
cleanups,
|
|
969
|
-
}, ...args);
|
|
970
|
-
}
|
|
971
|
-
throw err("UndefinedAction");
|
|
972
|
-
};
|
|
973
|
-
try {
|
|
974
|
-
return fn(el, root, action, undefined, ...args);
|
|
975
|
-
}
|
|
976
|
-
catch (e) {
|
|
977
|
-
console.error(e);
|
|
978
|
-
throw error({
|
|
979
|
-
element: { id: el.id, tag: el.tagName },
|
|
980
|
-
expression: {
|
|
981
|
-
fnContent: expr,
|
|
982
|
-
value,
|
|
983
|
-
},
|
|
984
|
-
error: e.message,
|
|
985
|
-
}, "ExecuteExpression");
|
|
986
|
-
}
|
|
987
|
-
};
|
|
988
|
-
}
|
|
989
|
-
catch (e) {
|
|
990
|
-
console.error(e);
|
|
991
|
-
throw error({
|
|
992
|
-
expression: {
|
|
993
|
-
fnContent: expr,
|
|
994
|
-
value,
|
|
995
|
-
},
|
|
996
|
-
error: e.message,
|
|
997
|
-
}, "GenerateExpression");
|
|
998
|
-
}
|
|
999
|
-
};
|