fusee-framework 1.5.3 → 1.7.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/README.md +30 -13
- package/app/benchmark/benchmark.js +633 -0
- package/app/benchmark/index.html +102 -0
- package/app/benchmark/styles.css +249 -0
- package/app/components/Counter.js +17 -7
- package/app/components/Counter.ts +1 -1
- package/app/components/CounterSection.js +3 -4
- package/app/main.js +29 -62
- package/app/main.ts +72 -63
- package/app/pages/404.js +16 -0
- package/app/pages/[...all].js +35 -0
- package/app/pages/[...all].ts +35 -0
- package/app/pages/_layout.js +26 -0
- package/app/pages/_layout.ts +26 -0
- package/app/pages/about.js +23 -0
- package/app/pages/about.ts +29 -0
- package/app/pages/composables.js +158 -0
- package/app/pages/composables.ts +158 -0
- package/app/pages/dynamic.js +40 -0
- package/app/pages/dynamic.ts +40 -0
- package/app/pages/index.js +117 -0
- package/app/pages/index.ts +78 -0
- package/app/pages/login.ts +21 -0
- package/app/pages/objects/[id].js +56 -0
- package/app/pages/objects/[id].ts +56 -0
- package/app/pages/posts/[category]/[slug].js +56 -0
- package/app/pages/posts/[category]/[slug].ts +56 -0
- package/app/pages/router-example.js +56 -0
- package/app/pages/router-example.ts +56 -0
- package/app/pages/test-for.js +65 -0
- package/app/pages/test-for.ts +80 -0
- package/app/pages/users/[id].js +24 -0
- package/app/pages/users/[id].ts +46 -0
- package/app/pages/users/index.js +22 -0
- package/app/pages/users/index.ts +29 -0
- package/app/pages/users.js +43 -0
- package/app/pages/users.ts +78 -0
- package/app/routes/About.js +1 -1
- package/app/routes/About.ts +1 -1
- package/app/routes/AuthRoutes.ts +41 -0
- package/app/routes/Home.js +9 -0
- package/app/routes/NotFound.js +16 -0
- package/app/routes/NotFound.ts +16 -0
- package/app/routes/RouterExample.js +56 -0
- package/app/routes/RouterExample.ts +56 -0
- package/app/routes/WildcardDemo.js +35 -0
- package/app/routes/WildcardDemo.ts +35 -0
- package/auto-imports.d.ts +1 -0
- package/bin/create-fusee-linux +0 -0
- package/bin/create-fusee-mac-arm64 +0 -0
- package/bin/create-fusee-mac-intel +0 -0
- package/bin/create-fusee-win.exe +0 -0
- package/bin/create-fusee.exe +0 -0
- package/bin/index.js +38 -0
- package/create-fusee-go/cmd/generate.go +72 -0
- package/create-fusee-go/cmd/init.go +38 -0
- package/create-fusee-go/cmd/root.go +121 -0
- package/create-fusee-go/go.mod +10 -0
- package/create-fusee-go/go.sum +10 -0
- package/create-fusee-go/internal/assets/assets.go +78 -0
- package/create-fusee-go/internal/assets/embed/framework/auto-import-preset.js +9 -0
- package/create-fusee-go/internal/assets/embed/framework/core/compiler.js +253 -0
- package/create-fusee-go/internal/assets/embed/framework/core/component.js +266 -0
- package/create-fusee-go/internal/assets/embed/framework/core/composable.js +27 -0
- package/create-fusee-go/internal/assets/embed/framework/core/directives.js +875 -0
- package/create-fusee-go/internal/assets/embed/framework/core/evaluator.js +153 -0
- package/create-fusee-go/internal/assets/embed/framework/core/event-delegation.js +191 -0
- package/create-fusee-go/internal/assets/embed/framework/core/signal.js +412 -0
- package/create-fusee-go/internal/assets/embed/framework/core/store.js +81 -0
- package/create-fusee-go/internal/assets/embed/framework/index.d.ts +3 -0
- package/create-fusee-go/internal/assets/embed/framework/index.js +10 -0
- package/create-fusee-go/internal/assets/embed/framework/router/file-router.js +177 -0
- package/create-fusee-go/internal/assets/embed/framework/router/router.js +462 -0
- package/create-fusee-go/internal/assets/embed/framework/types/compiler.d.ts +15 -0
- package/create-fusee-go/internal/assets/embed/framework/types/component.d.ts +88 -0
- package/create-fusee-go/internal/assets/embed/framework/types/composable.d.ts +14 -0
- package/create-fusee-go/internal/assets/embed/framework/types/directives.d.ts +55 -0
- package/create-fusee-go/internal/assets/embed/framework/types/evaluator.d.ts +13 -0
- package/create-fusee-go/internal/assets/embed/framework/types/event-delegation.d.ts +32 -0
- package/create-fusee-go/internal/assets/embed/framework/types/index.d.ts +22 -0
- package/create-fusee-go/internal/assets/embed/framework/types/router.d.ts +32 -0
- package/create-fusee-go/internal/assets/embed/framework/types/signal.d.ts +79 -0
- package/create-fusee-go/internal/assets/embed/framework/types/store.d.ts +8 -0
- package/create-fusee-go/internal/assets/templates/Counter.tmpl +26 -0
- package/create-fusee-go/internal/assets/templates/component.tmpl +11 -0
- package/create-fusee-go/internal/assets/templates/components/Loading.tmpl +24 -0
- package/create-fusee-go/internal/assets/templates/index.html.tmpl +15 -0
- package/create-fusee-go/internal/assets/templates/main.tmpl +14 -0
- package/create-fusee-go/internal/assets/templates/package.json.tmpl +14 -0
- package/create-fusee-go/internal/assets/templates/page.tmpl +12 -0
- package/create-fusee-go/internal/assets/templates/pages/about.tmpl +20 -0
- package/create-fusee-go/internal/assets/templates/pages/index.tmpl +22 -0
- package/create-fusee-go/internal/assets/templates/pages/layout.tmpl +18 -0
- package/create-fusee-go/internal/assets/templates/tsconfig.json.tmpl +14 -0
- package/create-fusee-go/internal/assets/templates/vite.config.js.tmpl +18 -0
- package/create-fusee-go/main.go +7 -0
- package/framework/auto-import-preset.js +1 -1
- package/framework/core/compiler.js +252 -249
- package/framework/core/component.js +265 -260
- package/framework/core/directives.js +875 -632
- package/framework/core/evaluator.js +153 -70
- package/framework/core/event-delegation.js +191 -0
- package/framework/core/signal.js +412 -404
- package/framework/index.js +10 -11
- package/framework/router/file-router.js +177 -0
- package/framework/router/router.js +462 -80
- package/framework/types/component.d.ts +0 -4
- package/framework/types/event-delegation.d.ts +32 -0
- package/framework/types/index.d.ts +3 -0
- package/framework/types/router.d.ts +32 -15
- package/framework/types/signal.d.ts +1 -0
- package/index.html +638 -563
- package/package.json +5 -3
- package/tsconfig.json +1 -0
- /package/{framework → create-fusee-go/internal/assets/embed/framework}/bin/create-fusee.js +0 -0
package/framework/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
// ─── Framework Public API ─────────────────────────────────────────────────────
|
|
2
|
-
export { signal, computed, effect, batch, untrack, inspect, watch } from './core/signal.js'
|
|
3
|
-
export { defineComponent, defineAsyncComponent, onMount, onUnmount, parseSlots, provide, inject, getCurrentInstance } from './core/component.js'
|
|
4
|
-
export { createRouter, navigate, mountOutlet } from './router/router.js'
|
|
5
|
-
export {
|
|
6
|
-
|
|
7
|
-
export { defineComposable, assertSetupContext } from './core/composable.js'
|
|
8
|
-
export { defineStore, resetStore, clearStores, registerStorePlugin } from './core/store.js'
|
|
9
|
-
export { directive } from './core/directives.js'
|
|
10
|
-
|
|
11
|
-
export const emit = () => console.warn('[framework] emit() can only be used inside component setup()')
|
|
1
|
+
// ─── Framework Public API ─────────────────────────────────────────────────────
|
|
2
|
+
export { signal, computed, effect, batch, untrack, inspect, watch, onCleanup } from './core/signal.js'
|
|
3
|
+
export { defineComponent, defineAsyncComponent, onMount, onUnmount, parseSlots, provide, inject, getCurrentInstance } from './core/component.js'
|
|
4
|
+
export { createRouter, navigate, mountOutlet, currentRoute, routeParams, matchedRoutes } from './router/router.js'
|
|
5
|
+
export { generateRoutes } from './router/file-router.js'
|
|
6
|
+
export { mountTemplate } from './core/compiler.js'
|
|
7
|
+
export { defineComposable, assertSetupContext } from './core/composable.js'
|
|
8
|
+
export { defineStore, resetStore, clearStores, registerStorePlugin } from './core/store.js'
|
|
9
|
+
export { directive } from './core/directives.js'
|
|
10
|
+
export const emit = () => console.warn('[framework] emit() can only be used inside component setup()')
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { defineAsyncComponent } from '../core/component.js';
|
|
2
|
+
|
|
3
|
+
export function generateRoutes(globResults, options = {}) {
|
|
4
|
+
const entries = _parseGlobEntries(globResults, options);
|
|
5
|
+
const tree = _buildRouteTree(entries, false);
|
|
6
|
+
_sortRoutesRecursive(tree);
|
|
7
|
+
return tree;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function _parseGlobEntries(globResults, options) {
|
|
11
|
+
const entries = [];
|
|
12
|
+
|
|
13
|
+
for (const filePath of Object.keys(globResults)) {
|
|
14
|
+
const loader = globResults[filePath];
|
|
15
|
+
|
|
16
|
+
let cleanPath = filePath
|
|
17
|
+
.replace(/^\.?\/?app\/pages\//, '')
|
|
18
|
+
.replace(/^\.?\/?pages\//, '')
|
|
19
|
+
.replace(/\.[jt]sx?$/, '');
|
|
20
|
+
|
|
21
|
+
const parts = cleanPath.split('/');
|
|
22
|
+
const rawFileName = parts.pop();
|
|
23
|
+
const rawDirSegments = parts;
|
|
24
|
+
|
|
25
|
+
const dirSegments = rawDirSegments.map(_transformSegment);
|
|
26
|
+
const fileName = _transformSegment(rawFileName);
|
|
27
|
+
|
|
28
|
+
const isIndex = rawFileName === 'index';
|
|
29
|
+
const isCatchAll = /^\[\.\.\./.test(rawFileName);
|
|
30
|
+
|
|
31
|
+
entries.push({
|
|
32
|
+
filePath,
|
|
33
|
+
loader,
|
|
34
|
+
dirSegments,
|
|
35
|
+
fileName,
|
|
36
|
+
isIndex,
|
|
37
|
+
isCatchAll,
|
|
38
|
+
component: defineAsyncComponent({
|
|
39
|
+
loader,
|
|
40
|
+
loadingComponent: options.loadingComponent
|
|
41
|
+
})
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return entries;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function _transformSegment(seg) {
|
|
49
|
+
return seg
|
|
50
|
+
.replace(/\[\.\.\.([^\]]+)\]/g, '*')
|
|
51
|
+
.replace(/\[([^\]]+)\]/g, ':$1');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function _buildRouteTree(entries, isChild) {
|
|
55
|
+
const filesHere = new Map();
|
|
56
|
+
const grouped = new Map();
|
|
57
|
+
|
|
58
|
+
for (const entry of entries) {
|
|
59
|
+
if (entry.dirSegments.length === 0) {
|
|
60
|
+
filesHere.set(entry.fileName, entry);
|
|
61
|
+
} else {
|
|
62
|
+
const firstDir = entry.dirSegments[0];
|
|
63
|
+
if (!grouped.has(firstDir)) grouped.set(firstDir, []);
|
|
64
|
+
grouped.get(firstDir).push(entry);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let rootLayoutEntry = null;
|
|
69
|
+
if (filesHere.has('_layout')) {
|
|
70
|
+
rootLayoutEntry = filesHere.get('_layout');
|
|
71
|
+
filesHere.delete('_layout');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const routes = [];
|
|
75
|
+
const usedAsLayout = new Set();
|
|
76
|
+
|
|
77
|
+
for (const [dirName, dirEntries] of grouped) {
|
|
78
|
+
const layoutEntry = filesHere.get(dirName);
|
|
79
|
+
|
|
80
|
+
if (layoutEntry) {
|
|
81
|
+
usedAsLayout.add(dirName);
|
|
82
|
+
|
|
83
|
+
const childEntries = dirEntries.map(e => ({
|
|
84
|
+
...e,
|
|
85
|
+
dirSegments: e.dirSegments.slice(1)
|
|
86
|
+
}));
|
|
87
|
+
|
|
88
|
+
const children = _buildRouteTree(childEntries, true);
|
|
89
|
+
|
|
90
|
+
routes.push({
|
|
91
|
+
path: isChild ? dirName : '/' + dirName,
|
|
92
|
+
component: layoutEntry.component,
|
|
93
|
+
children
|
|
94
|
+
});
|
|
95
|
+
} else {
|
|
96
|
+
for (const entry of dirEntries) {
|
|
97
|
+
const segments = [...entry.dirSegments];
|
|
98
|
+
if (!entry.isIndex) segments.push(entry.fileName);
|
|
99
|
+
|
|
100
|
+
const routePath = isChild
|
|
101
|
+
? segments.join('/')
|
|
102
|
+
: '/' + segments.join('/');
|
|
103
|
+
|
|
104
|
+
routes.push({
|
|
105
|
+
path: routePath,
|
|
106
|
+
component: entry.component
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
for (const [name, entry] of filesHere) {
|
|
113
|
+
if (usedAsLayout.has(name)) continue;
|
|
114
|
+
|
|
115
|
+
if (entry.isIndex) {
|
|
116
|
+
routes.push({ path: isChild ? '' : '/', component: entry.component });
|
|
117
|
+
} else if (entry.isCatchAll || name === '*') {
|
|
118
|
+
routes.push({ path: '*', component: entry.component });
|
|
119
|
+
} else {
|
|
120
|
+
routes.push({
|
|
121
|
+
path: isChild ? name : '/' + name,
|
|
122
|
+
component: entry.component
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (rootLayoutEntry) {
|
|
128
|
+
return [{
|
|
129
|
+
path: '',
|
|
130
|
+
component: rootLayoutEntry.component,
|
|
131
|
+
children: routes
|
|
132
|
+
}];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return routes;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function _sortRoutesRecursive(routes) {
|
|
139
|
+
routes.sort(_compareRoutes);
|
|
140
|
+
for (const route of routes) {
|
|
141
|
+
if (route.children) _sortRoutesRecursive(route.children);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function _getPathArray(path) {
|
|
146
|
+
return Array.isArray(path) ? path : [path];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function _compareRoutes(a, b) {
|
|
150
|
+
const aPaths = _getPathArray(a.path);
|
|
151
|
+
const bPaths = _getPathArray(b.path);
|
|
152
|
+
|
|
153
|
+
const aPath = aPaths[0];
|
|
154
|
+
const bPath = bPaths[0];
|
|
155
|
+
|
|
156
|
+
if (aPath === '*' && bPath !== '*') return 1;
|
|
157
|
+
if (aPath !== '*' && bPath === '*') return -1;
|
|
158
|
+
|
|
159
|
+
const aWild = aPath.endsWith('/*');
|
|
160
|
+
const bWild = bPath.endsWith('/*');
|
|
161
|
+
if (aWild && !bWild) return 1;
|
|
162
|
+
if (!aWild && bWild) return -1;
|
|
163
|
+
|
|
164
|
+
const aDynamic = aPath.includes(':');
|
|
165
|
+
const bDynamic = bPath.includes(':');
|
|
166
|
+
if (aDynamic && !bDynamic) return 1;
|
|
167
|
+
if (!aDynamic && bDynamic) return -1;
|
|
168
|
+
|
|
169
|
+
if (a.children && !b.children) return -1;
|
|
170
|
+
if (!a.children && b.children) return 1;
|
|
171
|
+
|
|
172
|
+
const aSegs = aPath.split('/').filter(Boolean).length;
|
|
173
|
+
const bSegs = bPath.split('/').filter(Boolean).length;
|
|
174
|
+
if (aSegs !== bSegs) return bSegs - aSegs;
|
|
175
|
+
|
|
176
|
+
return bPath.length - aPath.length;
|
|
177
|
+
}
|