valyrian.js 7.2.11 → 7.2.12
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/dist/dataset/index.d.ts +2 -2
- package/dist/dataset/index.d.ts.map +1 -1
- package/dist/dataset/index.js +21 -21
- package/dist/dataset/index.js.map +2 -2
- package/dist/dataset/index.mjs +22 -22
- package/dist/dataset/index.mjs.map +2 -2
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +17 -32
- package/dist/hooks/index.js.map +3 -3
- package/dist/hooks/index.mjs +17 -32
- package/dist/hooks/index.mjs.map +3 -3
- package/dist/index.d.ts +49 -53
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +378 -326
- package/dist/index.js.map +3 -3
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/index.mjs +378 -326
- package/dist/index.mjs.map +3 -3
- package/dist/node/index.js +101 -78
- package/dist/node/index.js.map +2 -2
- package/dist/node/index.mjs +101 -78
- package/dist/node/index.mjs.map +2 -2
- package/dist/node/utils/tree-adapter.d.ts +5 -0
- package/dist/node/utils/tree-adapter.d.ts.map +1 -1
- package/dist/proxy-signal/index.js +10 -10
- package/dist/proxy-signal/index.js.map +2 -2
- package/dist/proxy-signal/index.mjs +10 -10
- package/dist/proxy-signal/index.mjs.map +2 -2
- package/dist/request/index.js +16 -16
- package/dist/request/index.js.map +2 -2
- package/dist/request/index.mjs +16 -16
- package/dist/request/index.mjs.map +2 -2
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js +21 -20
- package/dist/router/index.js.map +2 -2
- package/dist/router/index.mjs +21 -20
- package/dist/router/index.mjs.map +2 -2
- package/dist/signal/index.d.ts +7 -18
- package/dist/signal/index.d.ts.map +1 -1
- package/dist/signal/index.js +29 -48
- package/dist/signal/index.js.map +3 -3
- package/dist/signal/index.mjs +31 -50
- package/dist/signal/index.mjs.map +3 -3
- package/dist/store/index.js +2 -2
- package/dist/store/index.js.map +2 -2
- package/dist/store/index.mjs +2 -2
- package/dist/store/index.mjs.map +2 -2
- package/lib/dataset/index.ts +25 -25
- package/lib/hooks/index.ts +25 -54
- package/lib/index.ts +465 -715
- package/lib/node/index.ts +2 -2
- package/lib/node/utils/icons.ts +5 -5
- package/lib/node/utils/inline.ts +17 -17
- package/lib/node/utils/sw.ts +3 -3
- package/lib/node/utils/tree-adapter.ts +81 -52
- package/lib/proxy-signal/index.ts +10 -10
- package/lib/request/index.ts +16 -16
- package/lib/router/index.ts +21 -20
- package/lib/signal/index.ts +56 -131
- package/lib/store/index.ts +2 -2
- package/package.json +10 -3
- package/lib/index.d.ts +0 -0
- package/lib/interfaces.ts.bak +0 -141
package/dist/router/index.mjs
CHANGED
|
@@ -30,9 +30,9 @@ var addPath = ({
|
|
|
30
30
|
if (!method || !path || !Array.isArray(middlewares) || middlewares.length === 0) {
|
|
31
31
|
throw new Error(`Invalid route input: ${method} ${path} ${middlewares}`);
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
const realpath = path.replace(/(\S)(\/+)$/, "$1");
|
|
34
|
+
const params = (realpath.match(/:(\w+)?/gi) || []).map((param) => param.slice(1));
|
|
35
|
+
const regexpPath = "^" + realpath.replace(/:(\w+)/gi, "([^\\/\\s]+)") + "$";
|
|
36
36
|
router.paths.push({
|
|
37
37
|
method,
|
|
38
38
|
path: realpath,
|
|
@@ -42,24 +42,24 @@ var addPath = ({
|
|
|
42
42
|
});
|
|
43
43
|
};
|
|
44
44
|
function parseQuery(queryParts) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
for (
|
|
48
|
-
|
|
45
|
+
const parts = queryParts ? queryParts.split("&") : [];
|
|
46
|
+
const query = {};
|
|
47
|
+
for (const nameValue of parts) {
|
|
48
|
+
const [name, value] = nameValue.split("=", 2);
|
|
49
49
|
query[name] = value || "";
|
|
50
50
|
}
|
|
51
51
|
return query;
|
|
52
52
|
}
|
|
53
53
|
function searchMiddlewares(router, path) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
for (
|
|
58
|
-
|
|
54
|
+
const middlewares = [];
|
|
55
|
+
const params = {};
|
|
56
|
+
const matches = [];
|
|
57
|
+
for (const item of router.paths) {
|
|
58
|
+
const match = item.regexp.exec(path);
|
|
59
59
|
if (Array.isArray(match)) {
|
|
60
60
|
middlewares.push(...item.middlewares);
|
|
61
61
|
match.shift();
|
|
62
|
-
for (
|
|
62
|
+
for (const [index, key] of item.params.entries()) {
|
|
63
63
|
params[key] = match[index];
|
|
64
64
|
}
|
|
65
65
|
matches.push(...match);
|
|
@@ -110,12 +110,12 @@ var Router = class _Router {
|
|
|
110
110
|
this.pathPrefix = pathPrefix;
|
|
111
111
|
}
|
|
112
112
|
add(path, ...middlewares) {
|
|
113
|
-
|
|
113
|
+
const pathWithoutLastSlash = getPathWithoutLastSlash(`${this.pathPrefix}${path}`);
|
|
114
114
|
addPath({ router: this, method: "add", path: pathWithoutLastSlash, middlewares });
|
|
115
115
|
return this;
|
|
116
116
|
}
|
|
117
117
|
use(...middlewares) {
|
|
118
|
-
|
|
118
|
+
const path = getPathWithoutLastSlash(
|
|
119
119
|
`${this.pathPrefix}${typeof middlewares[0] === "string" ? middlewares.shift() : "/"}`
|
|
120
120
|
);
|
|
121
121
|
for (const item of middlewares) {
|
|
@@ -144,7 +144,7 @@ var Router = class _Router {
|
|
|
144
144
|
if (!path) {
|
|
145
145
|
throw new Error("router.url.required");
|
|
146
146
|
}
|
|
147
|
-
|
|
147
|
+
const constructedPath = getPathWithoutLastSlash(`${this.pathPrefix}${path}`);
|
|
148
148
|
const parts = constructedPath.split("?", 2);
|
|
149
149
|
this.url = constructedPath;
|
|
150
150
|
this.query = parseQuery(parts[1]);
|
|
@@ -193,16 +193,17 @@ function mountRouter(elementContainer, router) {
|
|
|
193
193
|
localRedirect = router.go.bind(router);
|
|
194
194
|
if (!isNodeJs) {
|
|
195
195
|
let onPopStateGoToRoute2 = function() {
|
|
196
|
-
|
|
196
|
+
const pathWithoutPrefix = getPathWithoutPrefix(document.location.pathname, router.pathPrefix);
|
|
197
197
|
router.go(pathWithoutPrefix, void 0, true);
|
|
198
198
|
};
|
|
199
199
|
var onPopStateGoToRoute = onPopStateGoToRoute2;
|
|
200
200
|
window.addEventListener("popstate", onPopStateGoToRoute2, false);
|
|
201
201
|
onPopStateGoToRoute2();
|
|
202
202
|
}
|
|
203
|
-
directive("route", (
|
|
204
|
-
|
|
205
|
-
setAttribute("
|
|
203
|
+
directive("route", (vnode) => {
|
|
204
|
+
const url = vnode.props["v-route"];
|
|
205
|
+
setAttribute("href", url, vnode);
|
|
206
|
+
setAttribute("onclick", router.getOnClickHandler(url), vnode);
|
|
206
207
|
});
|
|
207
208
|
}
|
|
208
209
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../lib/router/index.ts"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable no-use-before-define */\nimport {\n Component,\n POJOComponent,\n VnodeComponentInterface,\n VnodeWithDom,\n directive,\n isComponent,\n isNodeJs,\n isVnodeComponent,\n mount,\n setAttribute,\n v\n} from \"valyrian.js\";\n\ninterface Request {\n params: Record<string, any>;\n query: Record<string, any>;\n url: string;\n path: string;\n matches: string[];\n // eslint-disable-next-line no-unused-vars\n redirect: (path: string, parentComponent?: Component | POJOComponent | VnodeComponentInterface) => false;\n}\n\ninterface Middleware {\n // eslint-disable-next-line no-unused-vars\n (req: Request, res?: any):\n | Promise<any | Component | POJOComponent | VnodeComponentInterface>\n | any\n | Component\n | POJOComponent\n | VnodeComponentInterface;\n}\n\ninterface Middlewares extends Array<Middleware> {}\n\ninterface Path {\n method: string;\n path: string;\n middlewares: Middlewares;\n params: string[];\n regexp: RegExp;\n}\n\ninterface RouterInterface {\n paths: Path[];\n container: Element | string | null;\n query: Record<string, string | number>;\n options: Record<string, any>;\n url: string;\n path: string;\n params: Record<string, string | number | any>;\n matches: string[];\n pathPrefix: string;\n // eslint-disable-next-line no-unused-vars\n add(method: string, ...args: Middlewares): Router;\n // eslint-disable-next-line no-unused-vars\n use(...args: (string | Middleware | Router)[]): Router;\n\n routes(): string[];\n // eslint-disable-next-line no-unused-vars\n go(path: string, parentComponent?: Component | POJOComponent | VnodeComponentInterface): Promise<string | void>;\n}\n\ninterface RedirectFunction {\n // eslint-disable-next-line no-unused-vars\n (\n path: string,\n parentComponent?: Component | POJOComponent | VnodeComponentInterface,\n preventPushState?: boolean\n ): Promise<string | void>;\n}\n\nfunction flat(array: any) {\n return Array.isArray(array) ? array.flat(Infinity) : [array];\n}\n\nfunction getPathWithoutPrefix(path: string, prefix: string) {\n return getPathWithoutLastSlash(path.replace(new RegExp(`^${prefix}`), \"\"));\n}\n\nfunction getPathWithoutLastSlash(path: string) {\n let pathWithoutLastSlash = path.replace(/\\/$/, \"\");\n if (pathWithoutLastSlash === \"\") {\n pathWithoutLastSlash = \"/\";\n }\n return pathWithoutLastSlash;\n}\n\nconst addPath = ({\n router,\n method,\n path,\n middlewares\n}: {\n router: Router;\n method: string;\n path: string;\n middlewares: Middleware[];\n}): void => {\n if (!method || !path || !Array.isArray(middlewares) || middlewares.length === 0) {\n throw new Error(`Invalid route input: ${method} ${path} ${middlewares}`);\n }\n\n // Trim trailing slashes from the path\n let realpath = path.replace(/(\\S)(\\/+)$/, \"$1\");\n\n // Find the express-like params in the path\n let params = (realpath.match(/:(\\w+)?/gi) || [])\n // Set the names of the params found\n .map((param) => param.slice(1));\n\n // Generate a regular expression to match the path\n let regexpPath = \"^\" + realpath.replace(/:(\\w+)/gi, \"([^\\\\/\\\\s]+)\") + \"$\";\n\n router.paths.push({\n method,\n path: realpath,\n middlewares: flat(middlewares),\n params,\n regexp: new RegExp(regexpPath, \"i\")\n });\n};\n\n// Parse a query string into an object\nfunction parseQuery(queryParts?: string): Record<string, string> {\n // Split the query string into an array of name-value pairs\n let parts = queryParts ? queryParts.split(\"&\") : [];\n let query: Record<string, string> = {};\n\n // Iterate over the name-value pairs and add them to the query object\n for (let nameValue of parts) {\n let [name, value] = nameValue.split(\"=\", 2);\n query[name] = value || \"\";\n }\n\n return query;\n}\n\n// Search for middlewares that match a given path\nfunction searchMiddlewares(router: RouterInterface, path: string): Middlewares {\n let middlewares: Middlewares = [];\n let params: Record<string, any> = {};\n let matches = [];\n\n // Search for middlewares\n for (let item of router.paths) {\n let match = item.regexp.exec(path);\n\n // If we found middlewares\n if (Array.isArray(match)) {\n middlewares.push(...item.middlewares);\n match.shift();\n\n // Parse params\n for (let [index, key] of item.params.entries()) {\n params[key] = match[index];\n }\n\n // Add remaining matches to the array\n matches.push(...match);\n\n if (item.method === \"add\") {\n router.path = getPathWithoutPrefix(item.path, router.pathPrefix);\n break;\n }\n }\n }\n\n router.params = params;\n router.matches = matches;\n\n return middlewares;\n}\n\nasync function searchComponent(\n router: RouterInterface,\n middlewares: Middlewares\n): Promise<Component | VnodeComponentInterface | false | void> {\n // Define request object with default values\n const request: Request = {\n params: router.params,\n query: router.query,\n url: router.url,\n path: router.path,\n matches: router.matches,\n redirect: (path: string, parentComponent?: Component | POJOComponent | VnodeComponentInterface) => {\n router.go(path, parentComponent);\n // Return false to stop the middleware chain\n return false;\n }\n };\n\n // Initialize response variable\n let response;\n\n // Iterate through middlewares\n for (const middleware of middlewares) {\n // Invoke middleware and update response\n response = await middleware(request, response);\n\n // Return response if it's a valid component\n if (response !== undefined && (isComponent(response) || isVnodeComponent(response))) {\n return response;\n }\n\n // Return false if response is explicitly false to stop the middleware chain\n if (response === false) {\n return false;\n }\n }\n}\n\nexport class Router implements RouterInterface {\n paths: Path[] = [];\n container: Element | string | null = null;\n query: Record<string, string | number> = {};\n options: Record<string, any> = {};\n url: string = \"\";\n path: string = \"\";\n params: Record<string, string | number | any> = {};\n matches: string[] = [];\n pathPrefix: string = \"\";\n\n constructor(pathPrefix: string = \"\") {\n this.pathPrefix = pathPrefix;\n }\n\n add(path: string, ...middlewares: Middlewares): Router {\n let pathWithoutLastSlash = getPathWithoutLastSlash(`${this.pathPrefix}${path}`);\n addPath({ router: this, method: \"add\", path: pathWithoutLastSlash, middlewares });\n return this;\n }\n\n use(...middlewares: Middlewares | Router[] | string[]): Router {\n let path = getPathWithoutLastSlash(\n `${this.pathPrefix}${typeof middlewares[0] === \"string\" ? middlewares.shift() : \"/\"}`\n );\n\n for (const item of middlewares) {\n if (item instanceof Router) {\n const subrouter = item as Router;\n for (const subpath of subrouter.paths) {\n addPath({\n router: this,\n method: subpath.method,\n path: `${path}${subpath.path}`.replace(/^\\/\\//, \"/\"),\n middlewares: subpath.middlewares\n });\n }\n continue;\n }\n\n if (typeof item === \"function\") {\n addPath({ router: this, method: \"use\", path: `${path}.*`, middlewares: [item as Middleware] });\n }\n }\n\n return this;\n }\n\n routes(): string[] {\n return this.paths.filter((path) => path.method === \"add\").map((path) => path.path);\n }\n\n async go(\n path: string,\n parentComponent?: Component | POJOComponent | VnodeComponentInterface,\n preventPushState = false\n ): Promise<string | void> {\n if (!path) {\n throw new Error(\"router.url.required\");\n }\n\n let constructedPath = getPathWithoutLastSlash(`${this.pathPrefix}${path}`);\n const parts = constructedPath.split(\"?\", 2);\n this.url = constructedPath;\n this.query = parseQuery(parts[1]);\n\n const middlewares = searchMiddlewares(this as RouterInterface, parts[0].replace(/(.+)\\/$/, \"$1\").split(\"#\")[0]);\n let component = await searchComponent(this as RouterInterface, middlewares);\n\n if (component === false) {\n return;\n }\n\n if (!component) {\n throw new Error(`The url ${constructedPath} requested wasn't found`);\n }\n\n if (isComponent(parentComponent) || isVnodeComponent(parentComponent)) {\n const childComponent = isVnodeComponent(component) ? component : v(component as Component, {});\n if (isVnodeComponent(parentComponent)) {\n parentComponent.children.push(childComponent);\n component = parentComponent;\n } else {\n component = v(parentComponent, {}, childComponent) as VnodeComponentInterface;\n }\n }\n\n if (!isNodeJs && !preventPushState) {\n window.history.pushState(null, \"\", constructedPath);\n }\n\n if (this.container) {\n return mount(this.container, component);\n }\n }\n\n getOnClickHandler(url: string) {\n return (e: MouseEvent) => {\n if (typeof url === \"string\" && url.length > 0) {\n this.go(url);\n }\n e.preventDefault();\n };\n }\n}\n\nlet localRedirect: RedirectFunction;\n\nexport function redirect(\n url: string,\n parentComponent?: Component | POJOComponent | VnodeComponentInterface,\n preventPushState = false\n): Promise<string | void> {\n if (!localRedirect) {\n throw new Error(\"router.redirect.not.found\");\n }\n return localRedirect(url, parentComponent, preventPushState);\n}\n\nexport function mountRouter(elementContainer: string | any, router: Router): void {\n router.container = elementContainer;\n localRedirect = router.go.bind(router);\n\n if (!isNodeJs) {\n function onPopStateGoToRoute(): void {\n let pathWithoutPrefix = getPathWithoutPrefix(document.location.pathname, router.pathPrefix);\n (router as unknown as Router).go(pathWithoutPrefix, undefined, true);\n }\n window.addEventListener(\"popstate\", onPopStateGoToRoute, false);\n onPopStateGoToRoute();\n }\n\n directive(\"route\", (url: string, vnode: VnodeWithDom, oldnode?: VnodeWithDom): void => {\n setAttribute(\"href\", url, vnode, oldnode);\n setAttribute(\"onclick\", router.getOnClickHandler(url), vnode, oldnode);\n });\n}\n"],
|
|
5
|
-
"mappings": ";AACA;AAAA,EAKE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA6DP,SAAS,KAAK,OAAY;AACxB,SAAO,MAAM,QAAQ,KAAK,IAAI,MAAM,KAAK,QAAQ,IAAI,CAAC,KAAK;AAC7D;AAEA,SAAS,qBAAqB,MAAc,QAAgB;AAC1D,SAAO,wBAAwB,KAAK,QAAQ,IAAI,OAAO,IAAI,MAAM,EAAE,GAAG,EAAE,CAAC;AAC3E;AAEA,SAAS,wBAAwB,MAAc;AAC7C,MAAI,uBAAuB,KAAK,QAAQ,OAAO,EAAE;AACjD,MAAI,yBAAyB,IAAI;AAC/B,2BAAuB;AAAA,EACzB;AACA,SAAO;AACT;AAEA,IAAM,UAAU,CAAC;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAKY;AACV,MAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,QAAQ,WAAW,KAAK,YAAY,WAAW,GAAG;AAC/E,UAAM,IAAI,MAAM,wBAAwB,MAAM,IAAI,IAAI,IAAI,WAAW,EAAE;AAAA,EACzE;AAGA,
|
|
4
|
+
"sourcesContent": ["/* eslint-disable no-use-before-define */\nimport {\n Component,\n POJOComponent,\n VnodeComponentInterface,\n VnodeWithDom,\n directive,\n isComponent,\n isNodeJs,\n isVnodeComponent,\n mount,\n setAttribute,\n v\n} from \"valyrian.js\";\n\ninterface Request {\n params: Record<string, any>;\n query: Record<string, any>;\n url: string;\n path: string;\n matches: string[];\n // eslint-disable-next-line no-unused-vars\n redirect: (path: string, parentComponent?: Component | POJOComponent | VnodeComponentInterface) => false;\n}\n\ninterface Middleware {\n // eslint-disable-next-line no-unused-vars\n (req: Request, res?: any):\n | Promise<any | Component | POJOComponent | VnodeComponentInterface>\n | any\n | Component\n | POJOComponent\n | VnodeComponentInterface;\n}\n\ninterface Middlewares extends Array<Middleware> {}\n\ninterface Path {\n method: string;\n path: string;\n middlewares: Middlewares;\n params: string[];\n regexp: RegExp;\n}\n\ninterface RouterInterface {\n paths: Path[];\n container: Element | string | null;\n query: Record<string, string | number>;\n options: Record<string, any>;\n url: string;\n path: string;\n params: Record<string, string | number | any>;\n matches: string[];\n pathPrefix: string;\n // eslint-disable-next-line no-unused-vars\n add(method: string, ...args: Middlewares): Router;\n // eslint-disable-next-line no-unused-vars\n use(...args: (string | Middleware | Router)[]): Router;\n\n routes(): string[];\n // eslint-disable-next-line no-unused-vars\n go(path: string, parentComponent?: Component | POJOComponent | VnodeComponentInterface): Promise<string | void>;\n}\n\ninterface RedirectFunction {\n // eslint-disable-next-line no-unused-vars\n (\n path: string,\n parentComponent?: Component | POJOComponent | VnodeComponentInterface,\n preventPushState?: boolean\n ): Promise<string | void>;\n}\n\nfunction flat(array: any) {\n return Array.isArray(array) ? array.flat(Infinity) : [array];\n}\n\nfunction getPathWithoutPrefix(path: string, prefix: string) {\n return getPathWithoutLastSlash(path.replace(new RegExp(`^${prefix}`), \"\"));\n}\n\nfunction getPathWithoutLastSlash(path: string) {\n let pathWithoutLastSlash = path.replace(/\\/$/, \"\");\n if (pathWithoutLastSlash === \"\") {\n pathWithoutLastSlash = \"/\";\n }\n return pathWithoutLastSlash;\n}\n\nconst addPath = ({\n router,\n method,\n path,\n middlewares\n}: {\n router: Router;\n method: string;\n path: string;\n middlewares: Middleware[];\n}): void => {\n if (!method || !path || !Array.isArray(middlewares) || middlewares.length === 0) {\n throw new Error(`Invalid route input: ${method} ${path} ${middlewares}`);\n }\n\n // Trim trailing slashes from the path\n const realpath = path.replace(/(\\S)(\\/+)$/, \"$1\");\n\n // Find the express-like params in the path\n const params = (realpath.match(/:(\\w+)?/gi) || [])\n // Set the names of the params found\n .map((param) => param.slice(1));\n\n // Generate a regular expression to match the path\n const regexpPath = \"^\" + realpath.replace(/:(\\w+)/gi, \"([^\\\\/\\\\s]+)\") + \"$\";\n\n router.paths.push({\n method,\n path: realpath,\n middlewares: flat(middlewares),\n params,\n regexp: new RegExp(regexpPath, \"i\")\n });\n};\n\n// Parse a query string into an object\nfunction parseQuery(queryParts?: string): Record<string, string> {\n // Split the query string into an array of name-value pairs\n const parts = queryParts ? queryParts.split(\"&\") : [];\n const query: Record<string, string> = {};\n\n // Iterate over the name-value pairs and add them to the query object\n for (const nameValue of parts) {\n const [name, value] = nameValue.split(\"=\", 2);\n query[name] = value || \"\";\n }\n\n return query;\n}\n\n// Search for middlewares that match a given path\nfunction searchMiddlewares(router: RouterInterface, path: string): Middlewares {\n const middlewares: Middlewares = [];\n const params: Record<string, any> = {};\n const matches = [];\n\n // Search for middlewares\n for (const item of router.paths) {\n const match = item.regexp.exec(path);\n\n // If we found middlewares\n if (Array.isArray(match)) {\n middlewares.push(...item.middlewares);\n match.shift();\n\n // Parse params\n for (const [index, key] of item.params.entries()) {\n params[key] = match[index];\n }\n\n // Add remaining matches to the array\n matches.push(...match);\n\n if (item.method === \"add\") {\n router.path = getPathWithoutPrefix(item.path, router.pathPrefix);\n break;\n }\n }\n }\n\n router.params = params;\n router.matches = matches;\n\n return middlewares;\n}\n\nasync function searchComponent(\n router: RouterInterface,\n middlewares: Middlewares\n): Promise<Component | VnodeComponentInterface | false | void> {\n // Define request object with default values\n const request: Request = {\n params: router.params,\n query: router.query,\n url: router.url,\n path: router.path,\n matches: router.matches,\n redirect: (path: string, parentComponent?: Component | POJOComponent | VnodeComponentInterface) => {\n router.go(path, parentComponent);\n // Return false to stop the middleware chain\n return false;\n }\n };\n\n // Initialize response variable\n let response;\n\n // Iterate through middlewares\n for (const middleware of middlewares) {\n // Invoke middleware and update response\n response = await middleware(request, response);\n\n // Return response if it's a valid component\n if (response !== undefined && (isComponent(response) || isVnodeComponent(response))) {\n return response;\n }\n\n // Return false if response is explicitly false to stop the middleware chain\n if (response === false) {\n return false;\n }\n }\n}\n\nexport class Router implements RouterInterface {\n paths: Path[] = [];\n container: Element | string | null = null;\n query: Record<string, string | number> = {};\n options: Record<string, any> = {};\n url: string = \"\";\n path: string = \"\";\n params: Record<string, string | number | any> = {};\n matches: string[] = [];\n pathPrefix: string = \"\";\n\n constructor(pathPrefix: string = \"\") {\n this.pathPrefix = pathPrefix;\n }\n\n add(path: string, ...middlewares: Middlewares): Router {\n const pathWithoutLastSlash = getPathWithoutLastSlash(`${this.pathPrefix}${path}`);\n addPath({ router: this, method: \"add\", path: pathWithoutLastSlash, middlewares });\n return this;\n }\n\n use(...middlewares: Middlewares | Router[] | string[]): Router {\n const path = getPathWithoutLastSlash(\n `${this.pathPrefix}${typeof middlewares[0] === \"string\" ? middlewares.shift() : \"/\"}`\n );\n\n for (const item of middlewares) {\n if (item instanceof Router) {\n const subrouter = item as Router;\n for (const subpath of subrouter.paths) {\n addPath({\n router: this,\n method: subpath.method,\n path: `${path}${subpath.path}`.replace(/^\\/\\//, \"/\"),\n middlewares: subpath.middlewares\n });\n }\n continue;\n }\n\n if (typeof item === \"function\") {\n addPath({ router: this, method: \"use\", path: `${path}.*`, middlewares: [item as Middleware] });\n }\n }\n\n return this;\n }\n\n routes(): string[] {\n return this.paths.filter((path) => path.method === \"add\").map((path) => path.path);\n }\n\n async go(\n path: string,\n parentComponent?: Component | POJOComponent | VnodeComponentInterface,\n preventPushState = false\n ): Promise<string | void> {\n if (!path) {\n throw new Error(\"router.url.required\");\n }\n\n const constructedPath = getPathWithoutLastSlash(`${this.pathPrefix}${path}`);\n const parts = constructedPath.split(\"?\", 2);\n this.url = constructedPath;\n this.query = parseQuery(parts[1]);\n\n const middlewares = searchMiddlewares(this as RouterInterface, parts[0].replace(/(.+)\\/$/, \"$1\").split(\"#\")[0]);\n let component = await searchComponent(this as RouterInterface, middlewares);\n\n if (component === false) {\n return;\n }\n\n if (!component) {\n throw new Error(`The url ${constructedPath} requested wasn't found`);\n }\n\n if (isComponent(parentComponent) || isVnodeComponent(parentComponent)) {\n const childComponent = isVnodeComponent(component) ? component : v(component as Component, {});\n if (isVnodeComponent(parentComponent)) {\n parentComponent.children.push(childComponent);\n component = parentComponent;\n } else {\n component = v(parentComponent, {}, childComponent) as VnodeComponentInterface;\n }\n }\n\n if (!isNodeJs && !preventPushState) {\n window.history.pushState(null, \"\", constructedPath);\n }\n\n if (this.container) {\n return mount(this.container, component);\n }\n }\n\n getOnClickHandler(url: string) {\n return (e: MouseEvent) => {\n if (typeof url === \"string\" && url.length > 0) {\n this.go(url);\n }\n e.preventDefault();\n };\n }\n}\n\nlet localRedirect: RedirectFunction;\n\nexport function redirect(\n url: string,\n parentComponent?: Component | POJOComponent | VnodeComponentInterface,\n preventPushState = false\n): Promise<string | void> {\n if (!localRedirect) {\n throw new Error(\"router.redirect.not.found\");\n }\n return localRedirect(url, parentComponent, preventPushState);\n}\n\nexport function mountRouter(elementContainer: string | any, router: Router): void {\n router.container = elementContainer;\n localRedirect = router.go.bind(router);\n\n if (!isNodeJs) {\n function onPopStateGoToRoute(): void {\n const pathWithoutPrefix = getPathWithoutPrefix(document.location.pathname, router.pathPrefix);\n (router as unknown as Router).go(pathWithoutPrefix, undefined, true);\n }\n window.addEventListener(\"popstate\", onPopStateGoToRoute, false);\n onPopStateGoToRoute();\n }\n\n directive(\"route\", (vnode: VnodeWithDom): void => {\n const url = vnode.props[\"v-route\"];\n setAttribute(\"href\", url, vnode);\n setAttribute(\"onclick\", router.getOnClickHandler(url), vnode);\n });\n}\n"],
|
|
5
|
+
"mappings": ";AACA;AAAA,EAKE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA6DP,SAAS,KAAK,OAAY;AACxB,SAAO,MAAM,QAAQ,KAAK,IAAI,MAAM,KAAK,QAAQ,IAAI,CAAC,KAAK;AAC7D;AAEA,SAAS,qBAAqB,MAAc,QAAgB;AAC1D,SAAO,wBAAwB,KAAK,QAAQ,IAAI,OAAO,IAAI,MAAM,EAAE,GAAG,EAAE,CAAC;AAC3E;AAEA,SAAS,wBAAwB,MAAc;AAC7C,MAAI,uBAAuB,KAAK,QAAQ,OAAO,EAAE;AACjD,MAAI,yBAAyB,IAAI;AAC/B,2BAAuB;AAAA,EACzB;AACA,SAAO;AACT;AAEA,IAAM,UAAU,CAAC;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAKY;AACV,MAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,QAAQ,WAAW,KAAK,YAAY,WAAW,GAAG;AAC/E,UAAM,IAAI,MAAM,wBAAwB,MAAM,IAAI,IAAI,IAAI,WAAW,EAAE;AAAA,EACzE;AAGA,QAAM,WAAW,KAAK,QAAQ,cAAc,IAAI;AAGhD,QAAM,UAAU,SAAS,MAAM,WAAW,KAAK,CAAC,GAE7C,IAAI,CAAC,UAAU,MAAM,MAAM,CAAC,CAAC;AAGhC,QAAM,aAAa,MAAM,SAAS,QAAQ,YAAY,cAAc,IAAI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AAAA,IACpD;AAEA,QAAI,KAAK,WAAW;AAClB,aAAO,MAAM,KAAK,WAAW,SAAS;AAAA,IACxC;AAAA,EACF;AAAA,EAEA,kBAAkB,KAAa;AAC7B,WAAO,CAAC,MAAkB;AACxB,UAAI,OAAO,QAAQ,YAAY,IAAI,SAAS,GAAG;AAC7C,aAAK,GAAG,GAAG;AAAA,MACb;AACA,QAAE,eAAe;AAAA,IACnB;AAAA,EACF;AACF;AAEA,IAAI;AAEG,SAAS,SACd,KACA,iBACA,mBAAmB,OACK;AACxB,MAAI,CAAC,eAAe;AAClB,UAAM,IAAI,MAAM,2BAA2B;AAAA,EAC7C;AACA,SAAO,cAAc,KAAK,iBAAiB,gBAAgB;AAC7D;AAEO,SAAS,YAAY,kBAAgC,QAAsB;AAChF,SAAO,YAAY;AACnB,kBAAgB,OAAO,GAAG,KAAK,MAAM;AAErC,MAAI,CAAC,UAAU;AACb,QAASA,uBAAT,WAAqC;AACnC,YAAM,oBAAoB,qBAAqB,SAAS,SAAS,UAAU,OAAO,UAAU;AAC5F,MAAC,OAA6B,GAAG,mBAAmB,QAAW,IAAI;AAAA,IACrE;AAHS,8BAAAA;AAIT,WAAO,iBAAiB,YAAYA,sBAAqB,KAAK;AAC9D,IAAAA,qBAAoB;AAAA,EACtB;AAEA,YAAU,SAAS,CAAC,UAA8B;AAChD,UAAM,MAAM,MAAM,MAAM,SAAS;AACjC,iBAAa,QAAQ,KAAK,KAAK;AAC/B,iBAAa,WAAW,OAAO,kBAAkB,GAAG,GAAG,KAAK;AAAA,EAC9D,CAAC;AACH;",
|
|
6
6
|
"names": ["onPopStateGoToRoute"]
|
|
7
7
|
}
|
package/dist/signal/index.d.ts
CHANGED
|
@@ -1,20 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
(callback: Function): void;
|
|
9
|
-
}
|
|
10
|
-
interface SubscriptionsInterface extends Array<Function> {
|
|
11
|
-
}
|
|
12
|
-
export interface SignalInterface extends Array<any> {
|
|
13
|
-
0: GetterInterface;
|
|
14
|
-
1: SetterInterface;
|
|
15
|
-
2: SubscribeInterface;
|
|
16
|
-
3: SubscriptionsInterface;
|
|
17
|
-
}
|
|
18
|
-
export declare function Signal(initialValue: any): SignalInterface;
|
|
1
|
+
type getter = () => any;
|
|
2
|
+
type setter = (newValue: any) => void;
|
|
3
|
+
type unsubscribe = () => void;
|
|
4
|
+
type subscribe = (callback: () => void) => unsubscribe;
|
|
5
|
+
type subscriptions = Set<() => void>;
|
|
6
|
+
type signal = [getter, setter, subscribe, subscriptions];
|
|
7
|
+
export declare function Signal<T>(initialValue: T): signal;
|
|
19
8
|
export {};
|
|
20
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/signal/index.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/signal/index.ts"],"names":[],"mappings":"AAEA,KAAK,MAAM,GAAG,MAAM,GAAG,CAAC;AACxB,KAAK,MAAM,GAAG,CAAC,QAAQ,EAAE,GAAG,KAAK,IAAI,CAAC;AACtC,KAAK,WAAW,GAAG,MAAM,IAAI,CAAC;AAC9B,KAAK,SAAS,GAAG,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,WAAW,CAAC;AACvD,KAAK,aAAa,GAAG,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC;AACrC,KAAK,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;AAUzD,wBAAgB,MAAM,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,MAAM,CAoEjD"}
|
package/dist/signal/index.js
CHANGED
|
@@ -24,72 +24,53 @@ __export(signal_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(signal_exports);
|
|
26
26
|
var import_valyrian = require("valyrian.js");
|
|
27
|
+
var componentToSignalsWeakMap = /* @__PURE__ */ new WeakMap();
|
|
27
28
|
function Signal(initialValue) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
if (import_valyrian.current.component) {
|
|
30
|
+
if (componentToSignalsWeakMap.has(import_valyrian.current.component) === false) {
|
|
31
|
+
const SignalCalls2 = { signals: [], signal_calls: -1 };
|
|
32
|
+
componentToSignalsWeakMap.set(import_valyrian.current.component, SignalCalls2);
|
|
33
|
+
(0, import_valyrian.onUnmount)(() => componentToSignalsWeakMap.delete(import_valyrian.current.component));
|
|
32
34
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (!component.signals) {
|
|
37
|
-
component.signals = [];
|
|
38
|
-
(0, import_valyrian.onUnmount)(() => Reflect.deleteProperty(component, "signals"));
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
let signal2 = component.signals[++vnode.signal_calls];
|
|
35
|
+
const SignalCalls = componentToSignalsWeakMap.get(import_valyrian.current.component);
|
|
36
|
+
(0, import_valyrian.onCleanup)(() => SignalCalls.signal_calls = -1);
|
|
37
|
+
const signal2 = SignalCalls.signals[++SignalCalls.signal_calls];
|
|
42
38
|
if (signal2) {
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
const fakeSubscribe = () => {
|
|
40
|
+
};
|
|
41
|
+
return [signal2[0], signal2[1], fakeSubscribe, signal2[3]];
|
|
45
42
|
}
|
|
46
43
|
}
|
|
47
44
|
let value = initialValue;
|
|
48
|
-
const
|
|
45
|
+
const subscribers = /* @__PURE__ */ new Set();
|
|
49
46
|
const subscribe = (callback) => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
let vnodesToUpdate = [];
|
|
55
|
-
const updateVnodes = () => {
|
|
56
|
-
let vnodesToUpdateCopy = vnodesToUpdate.filter((vnode2, index, self) => {
|
|
57
|
-
return self.findIndex((v2) => v2.dom === vnode2.dom) === index;
|
|
58
|
-
});
|
|
59
|
-
for (let i = 0, l = vnodesToUpdateCopy.length; i < l; i++) {
|
|
60
|
-
const vnode2 = vnodesToUpdateCopy[i];
|
|
61
|
-
let newVnode = (0, import_valyrian.v)(vnode2.tag, vnode2.props, ...vnode2.initialChildren);
|
|
62
|
-
newVnode.dom = vnode2.dom;
|
|
63
|
-
newVnode.isSVG = vnode2.isSVG;
|
|
64
|
-
(0, import_valyrian.updateVnode)(newVnode, vnode2);
|
|
65
|
-
}
|
|
47
|
+
subscribers.add(callback);
|
|
48
|
+
return () => subscribers.delete(callback);
|
|
66
49
|
};
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
vnodesToUpdate.push(vnode2);
|
|
50
|
+
const domToVnodesToUpdate = /* @__PURE__ */ new Map();
|
|
51
|
+
const updateVnodes = () => domToVnodesToUpdate.forEach((vnode) => (0, import_valyrian.updateVnode)(vnode));
|
|
52
|
+
const getValue = () => {
|
|
53
|
+
if (import_valyrian.current.vnode) {
|
|
54
|
+
const vnode = import_valyrian.current.vnode;
|
|
55
|
+
domToVnodesToUpdate.set(vnode.dom, vnode);
|
|
74
56
|
subscribe(updateVnodes);
|
|
75
57
|
}
|
|
76
58
|
return value;
|
|
77
|
-
}
|
|
78
|
-
const
|
|
59
|
+
};
|
|
60
|
+
const setValue = (newValue) => {
|
|
79
61
|
if (import_valyrian.current.event) {
|
|
80
62
|
import_valyrian.current.event.preventDefault();
|
|
81
63
|
}
|
|
82
|
-
if (
|
|
64
|
+
if (value === newValue) {
|
|
83
65
|
return;
|
|
84
66
|
}
|
|
85
67
|
value = newValue;
|
|
86
|
-
|
|
87
|
-
subscriptions[i](value);
|
|
88
|
-
}
|
|
68
|
+
subscribers.forEach((subscriber) => subscriber());
|
|
89
69
|
};
|
|
90
|
-
|
|
91
|
-
if (
|
|
92
|
-
|
|
70
|
+
const signal = [getValue, setValue, subscribe, subscribers];
|
|
71
|
+
if (import_valyrian.current.component) {
|
|
72
|
+
const SignalCalls = componentToSignalsWeakMap.get(import_valyrian.current.component);
|
|
73
|
+
SignalCalls.signals.push(signal);
|
|
93
74
|
}
|
|
94
75
|
return signal;
|
|
95
76
|
}
|
package/dist/signal/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../lib/signal/index.ts"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["import { updateVnode, current, VnodeWithDom, onCleanup, POJOComponent, Component, onUnmount } from \"valyrian.js\";\n\ntype getter = () => any;\ntype setter = (newValue: any) => void;\ntype unsubscribe = () => void;\ntype subscribe = (callback: () => void) => unsubscribe;\ntype subscriptions = Set<() => void>;\ntype signal = [getter, setter, subscribe, subscriptions];\n\ntype SignalCalls = {\n signals: signal[];\n signal_calls: number;\n};\n\nconst componentToSignalsWeakMap = new WeakMap<Component | POJOComponent, SignalCalls>();\n\n// Signal is a generic function that creates a reactive state with a getter, setter, and subscribe mechanism.\nexport function Signal<T>(initialValue: T): signal {\n if (current.component) {\n if (componentToSignalsWeakMap.has(current.component) === false) {\n const SignalCalls = { signals: [], signal_calls: -1 };\n componentToSignalsWeakMap.set(current.component, SignalCalls);\n onUnmount(() => componentToSignalsWeakMap.delete(current.component as Component | POJOComponent));\n }\n\n const SignalCalls = componentToSignalsWeakMap.get(current.component) as SignalCalls;\n onCleanup(() => (SignalCalls.signal_calls = -1));\n\n const signal = SignalCalls.signals[++SignalCalls.signal_calls];\n\n if (signal) {\n // Return the signal if it already exists.\n // But without the subscribe function. This is to prevent the subscribe function from being called multiple times.\n const fakeSubscribe = (() => {}) as unknown as subscribe;\n return [signal[0], signal[1], fakeSubscribe, signal[3]];\n }\n }\n\n // The current value of the signal is stored in a closure to maintain state.\n let value: T = initialValue;\n // Subscribers is a Set of functions to be called whenever the value changes.\n const subscribers: subscriptions = new Set();\n\n // subscribe is a function that allows a subscriber to listen to changes in the signal's value.\n // It returns an unsubscribe function to stop listening to changes.\n const subscribe = (callback: () => void) => {\n subscribers.add(callback);\n return () => subscribers.delete(callback);\n };\n\n const domToVnodesToUpdate: Map<Node, VnodeWithDom> = new Map();\n const updateVnodes = () => domToVnodesToUpdate.forEach((vnode) => updateVnode(vnode));\n\n // getValue is a function that returns the current value of the signal.\n const getValue = () => {\n if (current.vnode) {\n const vnode = current.vnode as VnodeWithDom;\n domToVnodesToUpdate.set(vnode.dom, vnode);\n subscribe(updateVnodes);\n }\n return value;\n };\n\n // setValue is a function that updates the value of the signal and notifies subscribers.\n const setValue = (newValue: any) => {\n if (current.event) {\n current.event.preventDefault();\n }\n\n if (value === newValue) {\n return;\n }\n value = newValue;\n // Notify all subscribers by invoking their callback functions.\n subscribers.forEach((subscriber) => subscriber());\n };\n\n const signal: signal = [getValue, setValue, subscribe, subscribers];\n\n if (current.component) {\n const SignalCalls = componentToSignalsWeakMap.get(current.component) as SignalCalls;\n SignalCalls.signals.push(signal);\n }\n\n return signal;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAmG;AAcnG,IAAM,4BAA4B,oBAAI,QAAgD;AAG/E,SAAS,OAAU,cAAyB;AACjD,MAAI,wBAAQ,WAAW;AACrB,QAAI,0BAA0B,IAAI,wBAAQ,SAAS,MAAM,OAAO;AAC9D,YAAMA,eAAc,EAAE,SAAS,CAAC,GAAG,cAAc,GAAG;AACpD,gCAA0B,IAAI,wBAAQ,WAAWA,YAAW;AAC5D,qCAAU,MAAM,0BAA0B,OAAO,wBAAQ,SAAsC,CAAC;AAAA,IAClG;AAEA,UAAM,cAAc,0BAA0B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
|
2
|
-
import {
|
|
2
|
+
import { updateVnode, current, onCleanup, onUnmount } from "valyrian.js";
|
|
3
|
+
var componentToSignalsWeakMap = /* @__PURE__ */ new WeakMap();
|
|
3
4
|
function Signal(initialValue) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
component.signals = [];
|
|
14
|
-
onUnmount(() => Reflect.deleteProperty(component, "signals"));
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
let signal2 = component.signals[++vnode.signal_calls];
|
|
5
|
+
if (current.component) {
|
|
6
|
+
if (componentToSignalsWeakMap.has(current.component) === false) {
|
|
7
|
+
const SignalCalls2 = { signals: [], signal_calls: -1 };
|
|
8
|
+
componentToSignalsWeakMap.set(current.component, SignalCalls2);
|
|
9
|
+
onUnmount(() => componentToSignalsWeakMap.delete(current.component));
|
|
10
|
+
}
|
|
11
|
+
const SignalCalls = componentToSignalsWeakMap.get(current.component);
|
|
12
|
+
onCleanup(() => SignalCalls.signal_calls = -1);
|
|
13
|
+
const signal2 = SignalCalls.signals[++SignalCalls.signal_calls];
|
|
18
14
|
if (signal2) {
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
const fakeSubscribe = () => {
|
|
16
|
+
};
|
|
17
|
+
return [signal2[0], signal2[1], fakeSubscribe, signal2[3]];
|
|
21
18
|
}
|
|
22
19
|
}
|
|
23
20
|
let value = initialValue;
|
|
24
|
-
const
|
|
21
|
+
const subscribers = /* @__PURE__ */ new Set();
|
|
25
22
|
const subscribe = (callback) => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
let vnodesToUpdate = [];
|
|
31
|
-
const updateVnodes = () => {
|
|
32
|
-
let vnodesToUpdateCopy = vnodesToUpdate.filter((vnode2, index, self) => {
|
|
33
|
-
return self.findIndex((v2) => v2.dom === vnode2.dom) === index;
|
|
34
|
-
});
|
|
35
|
-
for (let i = 0, l = vnodesToUpdateCopy.length; i < l; i++) {
|
|
36
|
-
const vnode2 = vnodesToUpdateCopy[i];
|
|
37
|
-
let newVnode = v(vnode2.tag, vnode2.props, ...vnode2.initialChildren);
|
|
38
|
-
newVnode.dom = vnode2.dom;
|
|
39
|
-
newVnode.isSVG = vnode2.isSVG;
|
|
40
|
-
updateVnode(newVnode, vnode2);
|
|
41
|
-
}
|
|
23
|
+
subscribers.add(callback);
|
|
24
|
+
return () => subscribers.delete(callback);
|
|
42
25
|
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
vnodesToUpdate.push(vnode2);
|
|
26
|
+
const domToVnodesToUpdate = /* @__PURE__ */ new Map();
|
|
27
|
+
const updateVnodes = () => domToVnodesToUpdate.forEach((vnode) => updateVnode(vnode));
|
|
28
|
+
const getValue = () => {
|
|
29
|
+
if (current.vnode) {
|
|
30
|
+
const vnode = current.vnode;
|
|
31
|
+
domToVnodesToUpdate.set(vnode.dom, vnode);
|
|
50
32
|
subscribe(updateVnodes);
|
|
51
33
|
}
|
|
52
34
|
return value;
|
|
53
|
-
}
|
|
54
|
-
const
|
|
35
|
+
};
|
|
36
|
+
const setValue = (newValue) => {
|
|
55
37
|
if (current.event) {
|
|
56
38
|
current.event.preventDefault();
|
|
57
39
|
}
|
|
58
|
-
if (
|
|
40
|
+
if (value === newValue) {
|
|
59
41
|
return;
|
|
60
42
|
}
|
|
61
43
|
value = newValue;
|
|
62
|
-
|
|
63
|
-
subscriptions[i](value);
|
|
64
|
-
}
|
|
44
|
+
subscribers.forEach((subscriber) => subscriber());
|
|
65
45
|
};
|
|
66
|
-
|
|
67
|
-
if (
|
|
68
|
-
|
|
46
|
+
const signal = [getValue, setValue, subscribe, subscribers];
|
|
47
|
+
if (current.component) {
|
|
48
|
+
const SignalCalls = componentToSignalsWeakMap.get(current.component);
|
|
49
|
+
SignalCalls.signals.push(signal);
|
|
69
50
|
}
|
|
70
51
|
return signal;
|
|
71
52
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../lib/signal/index.ts"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": ";AAAA,
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["import { updateVnode, current, VnodeWithDom, onCleanup, POJOComponent, Component, onUnmount } from \"valyrian.js\";\n\ntype getter = () => any;\ntype setter = (newValue: any) => void;\ntype unsubscribe = () => void;\ntype subscribe = (callback: () => void) => unsubscribe;\ntype subscriptions = Set<() => void>;\ntype signal = [getter, setter, subscribe, subscriptions];\n\ntype SignalCalls = {\n signals: signal[];\n signal_calls: number;\n};\n\nconst componentToSignalsWeakMap = new WeakMap<Component | POJOComponent, SignalCalls>();\n\n// Signal is a generic function that creates a reactive state with a getter, setter, and subscribe mechanism.\nexport function Signal<T>(initialValue: T): signal {\n if (current.component) {\n if (componentToSignalsWeakMap.has(current.component) === false) {\n const SignalCalls = { signals: [], signal_calls: -1 };\n componentToSignalsWeakMap.set(current.component, SignalCalls);\n onUnmount(() => componentToSignalsWeakMap.delete(current.component as Component | POJOComponent));\n }\n\n const SignalCalls = componentToSignalsWeakMap.get(current.component) as SignalCalls;\n onCleanup(() => (SignalCalls.signal_calls = -1));\n\n const signal = SignalCalls.signals[++SignalCalls.signal_calls];\n\n if (signal) {\n // Return the signal if it already exists.\n // But without the subscribe function. This is to prevent the subscribe function from being called multiple times.\n const fakeSubscribe = (() => {}) as unknown as subscribe;\n return [signal[0], signal[1], fakeSubscribe, signal[3]];\n }\n }\n\n // The current value of the signal is stored in a closure to maintain state.\n let value: T = initialValue;\n // Subscribers is a Set of functions to be called whenever the value changes.\n const subscribers: subscriptions = new Set();\n\n // subscribe is a function that allows a subscriber to listen to changes in the signal's value.\n // It returns an unsubscribe function to stop listening to changes.\n const subscribe = (callback: () => void) => {\n subscribers.add(callback);\n return () => subscribers.delete(callback);\n };\n\n const domToVnodesToUpdate: Map<Node, VnodeWithDom> = new Map();\n const updateVnodes = () => domToVnodesToUpdate.forEach((vnode) => updateVnode(vnode));\n\n // getValue is a function that returns the current value of the signal.\n const getValue = () => {\n if (current.vnode) {\n const vnode = current.vnode as VnodeWithDom;\n domToVnodesToUpdate.set(vnode.dom, vnode);\n subscribe(updateVnodes);\n }\n return value;\n };\n\n // setValue is a function that updates the value of the signal and notifies subscribers.\n const setValue = (newValue: any) => {\n if (current.event) {\n current.event.preventDefault();\n }\n\n if (value === newValue) {\n return;\n }\n value = newValue;\n // Notify all subscribers by invoking their callback functions.\n subscribers.forEach((subscriber) => subscriber());\n };\n\n const signal: signal = [getValue, setValue, subscribe, subscribers];\n\n if (current.component) {\n const SignalCalls = componentToSignalsWeakMap.get(current.component) as SignalCalls;\n SignalCalls.signals.push(signal);\n }\n\n return signal;\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,aAAa,SAAuB,WAAqC,iBAAiB;AAcnG,IAAM,4BAA4B,oBAAI,QAAgD;AAG/E,SAAS,OAAU,cAAyB;AACjD,MAAI,QAAQ,WAAW;AACrB,QAAI,0BAA0B,IAAI,QAAQ,SAAS,MAAM,OAAO;AAC9D,YAAMA,eAAc,EAAE,SAAS,CAAC,GAAG,cAAc,GAAG;AACpD,gCAA0B,IAAI,QAAQ,WAAWA,YAAW;AAC5D,gBAAU,MAAM,0BAA0B,OAAO,QAAQ,SAAsC,CAAC;AAAA,IAClG;AAEA,UAAM,cAAc,0BAA0B,IAAI,QAAQ,SAAS;AACnE,cAAU,MAAO,YAAY,eAAe,EAAG;AAE/C,UAAMC,UAAS,YAAY,QAAQ,EAAE,YAAY,YAAY;AAE7D,QAAIA,SAAQ;AAGV,YAAM,gBAAiB,MAAM;AAAA,MAAC;AAC9B,aAAO,CAACA,QAAO,CAAC,GAAGA,QAAO,CAAC,GAAG,eAAeA,QAAO,CAAC,CAAC;AAAA,IACxD;AAAA,EACF;AAGA,MAAI,QAAW;AAEf,QAAM,cAA6B,oBAAI,IAAI;AAI3C,QAAM,YAAY,CAAC,aAAyB;AAC1C,gBAAY,IAAI,QAAQ;AACxB,WAAO,MAAM,YAAY,OAAO,QAAQ;AAAA,EAC1C;AAEA,QAAM,sBAA+C,oBAAI,IAAI;AAC7D,QAAM,eAAe,MAAM,oBAAoB,QAAQ,CAAC,UAAU,YAAY,KAAK,CAAC;AAGpF,QAAM,WAAW,MAAM;AACrB,QAAI,QAAQ,OAAO;AACjB,YAAM,QAAQ,QAAQ;AACtB,0BAAoB,IAAI,MAAM,KAAK,KAAK;AACxC,gBAAU,YAAY;AAAA,IACxB;AACA,WAAO;AAAA,EACT;AAGA,QAAM,WAAW,CAAC,aAAkB;AAClC,QAAI,QAAQ,OAAO;AACjB,cAAQ,MAAM,eAAe;AAAA,IAC/B;AAEA,QAAI,UAAU,UAAU;AACtB;AAAA,IACF;AACA,YAAQ;AAER,gBAAY,QAAQ,CAAC,eAAe,WAAW,CAAC;AAAA,EAClD;AAEA,QAAM,SAAiB,CAAC,UAAU,UAAU,WAAW,WAAW;AAElE,MAAI,QAAQ,WAAW;AACrB,UAAM,cAAc,0BAA0B,IAAI,QAAQ,SAAS;AACnE,gBAAY,QAAQ,KAAK,MAAM;AAAA,EACjC;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": ["SignalCalls", "signal"]
|
|
7
7
|
}
|
package/dist/store/index.js
CHANGED
|
@@ -36,7 +36,7 @@ function deepFreeze(obj) {
|
|
|
36
36
|
deepFreeze(obj[i]);
|
|
37
37
|
}
|
|
38
38
|
} else {
|
|
39
|
-
|
|
39
|
+
const props = Reflect.ownKeys(obj);
|
|
40
40
|
for (let i = 0, l = props.length; i < l; i++) {
|
|
41
41
|
deepFreeze(obj[props[i]]);
|
|
42
42
|
}
|
|
@@ -57,7 +57,7 @@ var Store = function Store2({ state = {}, getters = {}, actions = {}, mutations
|
|
|
57
57
|
throw new Error("You need to commit a mutation to change the state");
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
|
|
60
|
+
const localState = typeof state === "function" ? state() : state;
|
|
61
61
|
this.state = new Proxy(localState || {}, {
|
|
62
62
|
get: (state2, prop) => deepFreeze(state2[prop]),
|
|
63
63
|
set: (state2, prop, value) => {
|
package/dist/store/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../lib/store/index.ts"],
|
|
4
|
-
"sourcesContent": ["import { update } from \"valyrian.js\";\n\ninterface StoreOptions {\n state?: Record<string, unknown> | (() => Record<string, unknown>);\n getters?: Record<string, Function>;\n mutations?: Record<string, Function>;\n actions?: Record<string, Function>;\n}\n\ninterface StoreInstance {\n // eslint-disable-next-line no-unused-vars\n new (options: StoreOptions): StoreInstance;\n state: Record<string, any>;\n getters?: Record<string, any>;\n // eslint-disable-next-line no-unused-vars\n commit: (type: string, ...payload: any[]) => void;\n // eslint-disable-next-line no-unused-vars\n dispatch: (type: string, ...payload: any[]) => void;\n}\n\nfunction keyExists(typeOfKey: string, object: Record<string, unknown>, key: string) {\n if (key in object === false) {\n throw new Error(`The ${typeOfKey} \"${key}\" does not exists.`);\n }\n}\n\nfunction deepFreeze(obj: any) {\n if (typeof obj === \"object\" && obj !== null && !Object.isFrozen(obj)) {\n if (Array.isArray(obj)) {\n for (let i = 0, l = obj.length; i < l; i++) {\n deepFreeze(obj[i]);\n }\n } else {\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAuB;AAoBvB,SAAS,UAAU,WAAmB,QAAiC,KAAa;AAClF,MAAI,OAAO,WAAW,OAAO;AAC3B,UAAM,IAAI,MAAM,OAAO,SAAS,KAAK,GAAG,oBAAoB;AAAA,EAC9D;AACF;AAEA,SAAS,WAAW,KAAU;AAC5B,MAAI,OAAO,QAAQ,YAAY,QAAQ,QAAQ,CAAC,OAAO,SAAS,GAAG,GAAG;AACpE,QAAI,MAAM,QAAQ,GAAG,GAAG;AACtB,eAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,IAAI,GAAG,KAAK;AAC1C,mBAAW,IAAI,CAAC,CAAC;AAAA,MACnB;AAAA,IACF,OAAO;AACL,
|
|
4
|
+
"sourcesContent": ["import { update } from \"valyrian.js\";\n\ninterface StoreOptions {\n state?: Record<string, unknown> | (() => Record<string, unknown>);\n getters?: Record<string, Function>;\n mutations?: Record<string, Function>;\n actions?: Record<string, Function>;\n}\n\ninterface StoreInstance {\n // eslint-disable-next-line no-unused-vars\n new (options: StoreOptions): StoreInstance;\n state: Record<string, any>;\n getters?: Record<string, any>;\n // eslint-disable-next-line no-unused-vars\n commit: (type: string, ...payload: any[]) => void;\n // eslint-disable-next-line no-unused-vars\n dispatch: (type: string, ...payload: any[]) => void;\n}\n\nfunction keyExists(typeOfKey: string, object: Record<string, unknown>, key: string) {\n if (key in object === false) {\n throw new Error(`The ${typeOfKey} \"${key}\" does not exists.`);\n }\n}\n\nfunction deepFreeze(obj: any) {\n if (typeof obj === \"object\" && obj !== null && !Object.isFrozen(obj)) {\n if (Array.isArray(obj)) {\n for (let i = 0, l = obj.length; i < l; i++) {\n deepFreeze(obj[i]);\n }\n } else {\n const props = Reflect.ownKeys(obj);\n for (let i = 0, l = props.length; i < l; i++) {\n deepFreeze(obj[props[i]]);\n }\n }\n Object.freeze(obj);\n }\n\n return obj;\n}\n\nlet updateTimeout: any;\nfunction delayedUpdate() {\n clearTimeout(updateTimeout);\n updateTimeout = setTimeout(update);\n}\n\nexport const Store = function Store(\n this: StoreInstance,\n { state = {}, getters = {}, actions = {}, mutations = {} }: StoreOptions = {}\n) {\n let frozen = true;\n\n function isUnfrozen() {\n if (frozen) {\n throw new Error(\"You need to commit a mutation to change the state\");\n }\n }\n\n const localState = typeof state === \"function\" ? state() : state;\n\n this.state = new Proxy(localState || {}, {\n get: (state, prop: string) => deepFreeze(state[prop]),\n set: (state, prop: string, value: any) => {\n isUnfrozen();\n state[prop] = value;\n return true;\n },\n deleteProperty: (state, prop: string) => {\n isUnfrozen();\n Reflect.deleteProperty(state, prop);\n return true;\n }\n });\n\n this.getters = new Proxy(getters, {\n get: (getters, getter: string) => {\n try {\n return getters[getter](this.state, this.getters);\n } catch (e) {\n // Getters should fail silently\n }\n }\n });\n\n this.commit = (mutation, ...args) => {\n keyExists(\"mutation\", mutations, mutation);\n frozen = false;\n mutations[mutation](this.state, ...args);\n frozen = true;\n delayedUpdate();\n };\n\n this.dispatch = (action, ...args) => {\n keyExists(\"action\", actions, action);\n return Promise.resolve(actions[action](this, ...args));\n };\n} as unknown as StoreInstance;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAuB;AAoBvB,SAAS,UAAU,WAAmB,QAAiC,KAAa;AAClF,MAAI,OAAO,WAAW,OAAO;AAC3B,UAAM,IAAI,MAAM,OAAO,SAAS,KAAK,GAAG,oBAAoB;AAAA,EAC9D;AACF;AAEA,SAAS,WAAW,KAAU;AAC5B,MAAI,OAAO,QAAQ,YAAY,QAAQ,QAAQ,CAAC,OAAO,SAAS,GAAG,GAAG;AACpE,QAAI,MAAM,QAAQ,GAAG,GAAG;AACtB,eAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,IAAI,GAAG,KAAK;AAC1C,mBAAW,IAAI,CAAC,CAAC;AAAA,MACnB;AAAA,IACF,OAAO;AACL,YAAM,QAAQ,QAAQ,QAAQ,GAAG;AACjC,eAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,IAAI,GAAG,KAAK;AAC5C,mBAAW,IAAI,MAAM,CAAC,CAAC,CAAC;AAAA,MAC1B;AAAA,IACF;AACA,WAAO,OAAO,GAAG;AAAA,EACnB;AAEA,SAAO;AACT;AAEA,IAAI;AACJ,SAAS,gBAAgB;AACvB,eAAa,aAAa;AAC1B,kBAAgB,WAAW,sBAAM;AACnC;A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12,7 +12,7 @@ function deepFreeze(obj) {
|
|
|
12
12
|
deepFreeze(obj[i]);
|
|
13
13
|
}
|
|
14
14
|
} else {
|
|
15
|
-
|
|
15
|
+
const props = Reflect.ownKeys(obj);
|
|
16
16
|
for (let i = 0, l = props.length; i < l; i++) {
|
|
17
17
|
deepFreeze(obj[props[i]]);
|
|
18
18
|
}
|
|
@@ -33,7 +33,7 @@ var Store = function Store2({ state = {}, getters = {}, actions = {}, mutations
|
|
|
33
33
|
throw new Error("You need to commit a mutation to change the state");
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
const localState = typeof state === "function" ? state() : state;
|
|
37
37
|
this.state = new Proxy(localState || {}, {
|
|
38
38
|
get: (state2, prop) => deepFreeze(state2[prop]),
|
|
39
39
|
set: (state2, prop, value) => {
|