sigpro 2.1.3 → 2.1.4
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 +1 -6
- package/src/sigpro.js +10 -1
- package/src/sigpro.router.js +38 -14
- package/src/sigpro.vite.js +25 -23
- package/src/sigpro.hmr.js +0 -47
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sigpro",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -36,11 +36,6 @@
|
|
|
36
36
|
"types": "./sigpro.d.ts",
|
|
37
37
|
"import": "./src/sigpro.vite.js",
|
|
38
38
|
"default": "./src/sigpro.vite.js"
|
|
39
|
-
},
|
|
40
|
-
"./hmr": {
|
|
41
|
-
"types": "./sigpro.d.ts",
|
|
42
|
-
"import": "./src/sigpro.hmr.js",
|
|
43
|
-
"default": "./src/sigpro.hmr.js"
|
|
44
39
|
}
|
|
45
40
|
},
|
|
46
41
|
"files": [
|
package/src/sigpro.js
CHANGED
|
@@ -91,7 +91,16 @@ function setAttr(el, key, res, isSVG) {
|
|
|
91
91
|
else el.setAttribute(key, res === true ? '' : res);
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
function cleanupNode(n) {
|
|
95
|
+
const stack = [n];
|
|
96
|
+
while (stack.length) {
|
|
97
|
+
const node = stack.pop();
|
|
98
|
+
if (node._stopScope) { node._stopScope(); node._stopScope = null; }
|
|
99
|
+
if (node._cln) { for (const f of node._cln) f(); node._cln = null; }
|
|
100
|
+
const children = node.childNodes;
|
|
101
|
+
for (let i = 0, len = children.length; i < len; i++) stack.push(children[i]);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
95
104
|
|
|
96
105
|
export function h(tag, props = {}, ...children) {
|
|
97
106
|
if (tag == null) {
|
package/src/sigpro.router.js
CHANGED
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
// sigpro.router.js
|
|
2
2
|
import { signal, effect } from 'sigpro';
|
|
3
3
|
|
|
4
|
-
export const currentPath = signal(
|
|
4
|
+
export const currentPath = signal(
|
|
5
|
+
typeof window !== 'undefined' ? location.hash.slice(1) || '/' : '/'
|
|
6
|
+
);
|
|
5
7
|
export const routerParams = signal({});
|
|
6
8
|
|
|
7
9
|
if (typeof window !== 'undefined') {
|
|
8
10
|
addEventListener('hashchange', () => currentPath(location.hash.slice(1) || '/'));
|
|
9
11
|
}
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
const hmrRegistry = new Map();
|
|
13
|
-
window.__sigpro_hmr_page__ = (url, component) => { hmrRegistry.set(url, component); hmrTick(hmrTick() + 1); };
|
|
13
|
+
let hmrTick, hmrRegistry;
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
if (import.meta.hot) {
|
|
16
|
+
hmrTick = signal(0);
|
|
17
|
+
hmrRegistry = new Map();
|
|
18
|
+
|
|
19
|
+
window.__sigpro_hmr_page__ = (url, component) => {
|
|
20
|
+
hmrRegistry.set(url, component);
|
|
21
|
+
hmrTick(hmrTick() + 1);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const router = (routes) => {
|
|
26
|
+
const sorted = [...routes].sort((a, b) =>
|
|
27
|
+
a.path.split('/').filter(p => p[0] === ':').length -
|
|
28
|
+
b.path.split('/').filter(p => p[0] === ':').length ||
|
|
29
|
+
(b.path === '*') - (a.path === '*')
|
|
30
|
+
);
|
|
18
31
|
|
|
19
32
|
const hook = document.createElement('div');
|
|
20
33
|
hook.classList.add('router-hook');
|
|
@@ -32,37 +45,48 @@ export const router = routes => {
|
|
|
32
45
|
};
|
|
33
46
|
|
|
34
47
|
const effectStop = effect(() => {
|
|
35
|
-
hmrTick();
|
|
48
|
+
if (import.meta.hot) hmrTick();
|
|
49
|
+
|
|
36
50
|
const hash = currentPath().split(/[?#]/)[0];
|
|
37
51
|
const p2 = hash.split('/').filter(Boolean);
|
|
38
52
|
|
|
39
|
-
let route = sorted.find(r =>
|
|
40
|
-
r.path.split('/').
|
|
53
|
+
let route = sorted.find(r =>
|
|
54
|
+
r.path.split('/').filter(Boolean).length === p2.length &&
|
|
55
|
+
r.path.split('/').every((p, i) => p[0] === ':' || p === p2[i])
|
|
56
|
+
);
|
|
41
57
|
if (!route) route = sorted[sorted.length - 1];
|
|
42
58
|
|
|
43
59
|
const params = {};
|
|
44
60
|
route.path.split('/').filter(Boolean).reduce((acc, p, i) => {
|
|
45
|
-
if (p[0] === ':')
|
|
61
|
+
if (p[0] === ':') {
|
|
62
|
+
try { params[p.slice(1)] = decodeURIComponent(p2[i]); }
|
|
63
|
+
catch { params[p.slice(1)] = p2[i]; }
|
|
64
|
+
}
|
|
46
65
|
return acc;
|
|
47
66
|
}, null);
|
|
48
67
|
|
|
49
|
-
const component = hmrRegistry.get(route.path)
|
|
68
|
+
const component = (import.meta.hot && hmrRegistry.get(route.path)) || route.component;
|
|
69
|
+
|
|
50
70
|
if (hash === lastPath && component === lastComponent) return;
|
|
51
71
|
lastPath = hash; lastComponent = component;
|
|
52
72
|
|
|
53
73
|
if (scopeStop) { scopeStop(); scopeStop = undefined; }
|
|
54
74
|
clearHook();
|
|
55
75
|
routerParams(params);
|
|
76
|
+
|
|
56
77
|
scopeStop = effect(() => {
|
|
57
78
|
const node = typeof component === 'function' ? component(params) : component;
|
|
58
79
|
hook.replaceChildren(...(node == null ? [] : Array.isArray(node) ? node : [node]));
|
|
59
80
|
});
|
|
60
81
|
});
|
|
61
82
|
|
|
62
|
-
hook._stopScope = () => {
|
|
83
|
+
hook._stopScope = () => {
|
|
84
|
+
if (scopeStop) { scopeStop(); scopeStop = undefined; }
|
|
85
|
+
effectStop();
|
|
86
|
+
};
|
|
63
87
|
return hook;
|
|
64
88
|
};
|
|
65
89
|
|
|
66
90
|
router.to = path => location.hash = '#/' + path.replace(/^\//, '');
|
|
67
91
|
router.back = () => history.back();
|
|
68
|
-
router.path = () => currentPath();
|
|
92
|
+
router.path = () => currentPath();
|
package/src/sigpro.vite.js
CHANGED
|
@@ -12,7 +12,9 @@ export function sigproRouter({ pagesDir = "src/pages" } = {}) {
|
|
|
12
12
|
const pagesRootPosix = pagesRoot.split(path.sep).join("/");
|
|
13
13
|
|
|
14
14
|
const isPage = (f) =>
|
|
15
|
-
/\.(js|jsx)$/.test(f) &&
|
|
15
|
+
/\.(js|jsx|ts|tsx)$/.test(f) &&
|
|
16
|
+
!path.basename(f).startsWith("_") &&
|
|
17
|
+
!f.includes(".store.");
|
|
16
18
|
|
|
17
19
|
const getFiles = (dir) => {
|
|
18
20
|
if (!fs.existsSync(dir)) return [];
|
|
@@ -26,7 +28,7 @@ export function sigproRouter({ pagesDir = "src/pages" } = {}) {
|
|
|
26
28
|
const relative = path
|
|
27
29
|
.relative(dir, filePath)
|
|
28
30
|
.replace(/\\/g, "/")
|
|
29
|
-
.replace(/\.(js|jsx)$/, "")
|
|
31
|
+
.replace(/\.(js|jsx|ts|tsx)$/, "")
|
|
30
32
|
.replace(/\/index$/, "")
|
|
31
33
|
.replace(/^index$/, "");
|
|
32
34
|
return (
|
|
@@ -40,8 +42,7 @@ export function sigproRouter({ pagesDir = "src/pages" } = {}) {
|
|
|
40
42
|
|
|
41
43
|
const sortRoutes = (dir, files) =>
|
|
42
44
|
files.slice().sort((a, b) => {
|
|
43
|
-
const ua = pathToUrl(dir, a),
|
|
44
|
-
ub = pathToUrl(dir, b);
|
|
45
|
+
const ua = pathToUrl(dir, a), ub = pathToUrl(dir, b);
|
|
45
46
|
const wa = ua.includes(":") || ua.includes("*");
|
|
46
47
|
const wb = ub.includes(":") || ub.includes("*");
|
|
47
48
|
if (wa !== wb) return wa ? 1 : -1;
|
|
@@ -57,8 +58,7 @@ export function sigproRouter({ pagesDir = "src/pages" } = {}) {
|
|
|
57
58
|
|
|
58
59
|
files.forEach((fullPath, i) => {
|
|
59
60
|
const url = pathToUrl(dir, fullPath);
|
|
60
|
-
const importPath =
|
|
61
|
-
"/" + path.relative(root, fullPath).replace(/\\/g, "/");
|
|
61
|
+
const importPath = "/" + path.relative(root, fullPath).replace(/\\/g, "/");
|
|
62
62
|
const name = `Page${i}`;
|
|
63
63
|
imports += `import ${name} from '${importPath}';\n`;
|
|
64
64
|
routes += ` { path: '${url}', component: ${name} },\n`;
|
|
@@ -71,23 +71,19 @@ export function sigproRouter({ pagesDir = "src/pages" } = {}) {
|
|
|
71
71
|
|
|
72
72
|
return {
|
|
73
73
|
name: "sigpro-router",
|
|
74
|
-
|
|
75
74
|
resolveId(id) {
|
|
76
75
|
if (id === virtualModuleId) return resolvedVirtualModuleId;
|
|
77
76
|
},
|
|
78
|
-
|
|
79
77
|
load(id) {
|
|
80
78
|
if (id !== resolvedVirtualModuleId) return;
|
|
81
79
|
return generateModule();
|
|
82
80
|
},
|
|
83
|
-
|
|
84
81
|
transform(code, id) {
|
|
85
82
|
const clean = id.split("?")[0];
|
|
86
83
|
const cleanPosix = clean.split(path.sep).join("/");
|
|
87
84
|
|
|
88
85
|
if (!cleanPosix.startsWith(pagesRootPosix + "/")) return;
|
|
89
|
-
if (
|
|
90
|
-
if (path.basename(cleanPosix).startsWith("_")) return;
|
|
86
|
+
if (!isPage(cleanPosix)) return;
|
|
91
87
|
|
|
92
88
|
const url = pathToUrl(pagesRoot, clean);
|
|
93
89
|
|
|
@@ -96,22 +92,25 @@ export function sigproRouter({ pagesDir = "src/pages" } = {}) {
|
|
|
96
92
|
if (import.meta.hot) {
|
|
97
93
|
import.meta.hot.accept((newMod) => {
|
|
98
94
|
if (newMod && typeof window !== 'undefined' && window.__sigpro_hmr_page__) {
|
|
99
|
-
|
|
95
|
+
Promise.resolve().then(() => {
|
|
96
|
+
window.__sigpro_hmr_page__(${JSON.stringify(url)}, newMod.default ?? newMod);
|
|
97
|
+
});
|
|
100
98
|
}
|
|
101
99
|
});
|
|
102
100
|
}
|
|
103
101
|
`;
|
|
104
102
|
return { code: code + hmr, map: null };
|
|
105
103
|
},
|
|
106
|
-
|
|
107
104
|
configureServer(server) {
|
|
108
105
|
const onChange = (file) => {
|
|
109
106
|
const posix = file.split(path.sep).join("/");
|
|
110
107
|
if (!posix.startsWith(pagesRootPosix + "/")) return;
|
|
111
108
|
if (!isPage(posix)) return;
|
|
112
109
|
const vm = server.moduleGraph.getModuleById(resolvedVirtualModuleId);
|
|
113
|
-
if (vm)
|
|
114
|
-
|
|
110
|
+
if (vm) {
|
|
111
|
+
server.moduleGraph.invalidateModule(vm);
|
|
112
|
+
server.ws.send({ type: "full-reload" });
|
|
113
|
+
}
|
|
115
114
|
};
|
|
116
115
|
server.watcher.on("add", onChange);
|
|
117
116
|
server.watcher.on("unlink", onChange);
|
|
@@ -119,28 +118,31 @@ if (import.meta.hot) {
|
|
|
119
118
|
};
|
|
120
119
|
}
|
|
121
120
|
|
|
121
|
+
|
|
122
122
|
/* Vite Config
|
|
123
123
|
|
|
124
124
|
import { defineConfig } from "vite";
|
|
125
|
-
import
|
|
126
|
-
import { sigproRouter } from "./sigpro.vite.js";
|
|
125
|
+
import { sigproRouter } from "sigpro/vite";
|
|
127
126
|
|
|
128
127
|
const dev = process.env.NODE_ENV === "development";
|
|
129
128
|
|
|
130
129
|
export default defineConfig({
|
|
131
130
|
plugins: [sigproRouter({ pagesDir: "src/pages" }), tailwindcss()],
|
|
132
|
-
base: dev ? "/absproxy/5173/" : "/",
|
|
133
|
-
server: { host: "0.0.0.0", allowedHosts: true, port: 5173 },
|
|
134
|
-
build: { chunkSizeWarningLimit: 1500 },
|
|
135
131
|
});
|
|
136
132
|
|
|
137
133
|
*/
|
|
138
134
|
|
|
139
135
|
/* main.js
|
|
136
|
+
|
|
137
|
+
import { mount } from 'sigpro'
|
|
138
|
+
import App from './pages/App.js'
|
|
139
|
+
|
|
140
|
+
let dispose = mount(App, '#root')
|
|
141
|
+
|
|
140
142
|
if (import.meta.hot) {
|
|
141
|
-
import.meta.hot.accept(
|
|
143
|
+
import.meta.hot.accept('./pages/App.js', (newModule) => {
|
|
142
144
|
dispose?.();
|
|
143
|
-
dispose = mount(
|
|
145
|
+
dispose = mount(newModule.default, '#root');
|
|
144
146
|
});
|
|
145
147
|
}
|
|
146
|
-
*/
|
|
148
|
+
*/
|
package/src/sigpro.hmr.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// sigpro.hmr.js
|
|
2
|
-
|
|
3
|
-
import path from "path";
|
|
4
|
-
|
|
5
|
-
const PAGES = path.resolve(import.meta.dir, "src/pages") + path.sep;
|
|
6
|
-
const isDev = process.env.NODE_ENV === "development";
|
|
7
|
-
|
|
8
|
-
export const hmr = {
|
|
9
|
-
name: "sigpro-hmr",
|
|
10
|
-
setup(build) {
|
|
11
|
-
build.onLoad({ filter: /\.js$/ }, async (args) => {
|
|
12
|
-
if (!args.path.startsWith(PAGES)) return;
|
|
13
|
-
|
|
14
|
-
let source;
|
|
15
|
-
try {
|
|
16
|
-
source = await Bun.file(args.path).text();
|
|
17
|
-
} catch {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (isDev) {
|
|
22
|
-
const rel = path
|
|
23
|
-
.relative(PAGES, args.path)
|
|
24
|
-
.replace(/\\/g, "/")
|
|
25
|
-
.replace(/\.js$/, "");
|
|
26
|
-
|
|
27
|
-
const routePath =
|
|
28
|
-
rel === "index"
|
|
29
|
-
? "/"
|
|
30
|
-
: "/" +
|
|
31
|
-
rel.replace(/\/index$/, "").replace(/\[([^\]]+)\]/g, ":$1");
|
|
32
|
-
|
|
33
|
-
source += `
|
|
34
|
-
if (import.meta.hot) {
|
|
35
|
-
import.meta.hot.accept((newMod) => {
|
|
36
|
-
const component = newMod && newMod.default;
|
|
37
|
-
if (typeof component === 'function' && typeof window !== 'undefined' && window.__sigpro_hmr_page__) {
|
|
38
|
-
window.__sigpro_hmr_page__(${JSON.stringify(routePath)}, component);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
}`;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return { contents: source, loader: "js" };
|
|
45
|
-
});
|
|
46
|
-
},
|
|
47
|
-
};
|