fusee-framework 1.3.0 → 1.4.1
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 +1 -1
- package/app/composables/demo.js +29 -0
- package/app/composables/demo.ts +30 -0
- package/app/composables/useFetch.js +53 -0
- package/app/composables/useFetch.ts +63 -0
- package/app/composables/useLocalStorage.js +31 -0
- package/app/composables/useLocalStorage.ts +26 -0
- package/app/main.js +35 -12
- package/app/main.ts +27 -4
- package/app/routes/TestComposables.js +158 -0
- package/app/routes/TestComposables.ts +158 -0
- package/app/routes/TestFor.js +35 -8
- package/app/routes/TestFor.ts +34 -8
- package/auto-imports.d.ts +1 -0
- package/framework/auto-import-preset.js +1 -0
- package/framework/core/component.js +7 -21
- package/framework/core/composable.js +27 -0
- package/framework/core/directives.js +69 -1
- package/framework/core/signal.js +92 -5
- package/framework/index.js +4 -2
- package/framework/router/router.js +4 -4
- package/framework/types/composable.d.ts +14 -0
- package/framework/types/directives.d.ts +15 -0
- package/framework/types/index.d.ts +5 -4
- package/framework/types/signal.d.ts +38 -3
- package/index.html +134 -0
- package/package.json +1 -1
|
@@ -22,9 +22,9 @@ export function createRouter(routes) {
|
|
|
22
22
|
window.removeEventListener('hashchange', handler)
|
|
23
23
|
window.removeEventListener('DOMContentLoaded', handler)
|
|
24
24
|
if (_currentInstance) {
|
|
25
|
-
try {
|
|
26
|
-
_currentInstance.unmount()
|
|
27
|
-
} catch {}
|
|
25
|
+
try {
|
|
26
|
+
_currentInstance.unmount()
|
|
27
|
+
} catch { }
|
|
28
28
|
}
|
|
29
29
|
_routes = []
|
|
30
30
|
_outlet = null
|
|
@@ -58,7 +58,7 @@ function _resolve() {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
if (_currentInstance) {
|
|
61
|
-
try { _currentInstance.unmount() } catch {}
|
|
61
|
+
try { _currentInstance.unmount() } catch { }
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
_outlet.innerHTML = ''
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface Composable<T = any> {
|
|
2
|
+
(...args: any[]): T
|
|
3
|
+
readonly _isComposable: true
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
declare global {
|
|
7
|
+
interface Composable<T = any> {
|
|
8
|
+
(...args: any[]): T
|
|
9
|
+
readonly _isComposable: true
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function defineComposable<T>(fn: (...args: any[]) => T): Composable<T>
|
|
14
|
+
export function assertSetupContext(name?: string): any
|
|
@@ -37,3 +37,18 @@ export function processHtml(root: HTMLElement, context: ComponentResult, effects
|
|
|
37
37
|
export function processText(root: HTMLElement, context: ComponentResult, effects: (() => void)[]): void
|
|
38
38
|
export function processEvents(root: HTMLElement, context: ComponentResult): void
|
|
39
39
|
export function processCloak(root: HTMLElement): void
|
|
40
|
+
|
|
41
|
+
export interface DirectiveBinding<V = any> {
|
|
42
|
+
value: V
|
|
43
|
+
expression: string
|
|
44
|
+
arg: string | null
|
|
45
|
+
modifiers: string[]
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface DirectiveHooks<V = any> {
|
|
49
|
+
mounted?: (el: HTMLElement, binding: DirectiveBinding<V>) => void
|
|
50
|
+
updated?: (el: HTMLElement, binding: DirectiveBinding<V>) => void
|
|
51
|
+
unmounted?: (el: HTMLElement, binding: DirectiveBinding<V>) => void
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function directive<V = any>(name: string, hooks: DirectiveHooks<V>): void
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
// ─── Fusée Framework Types ───────────────────────────────────────────────────
|
|
2
|
-
|
|
3
|
-
// Public API
|
|
4
1
|
export * from './signal'
|
|
5
2
|
export * from './component'
|
|
3
|
+
export * from './composable'
|
|
6
4
|
export * from './router'
|
|
7
5
|
export * from './compiler'
|
|
6
|
+
export * from './directives'
|
|
8
7
|
|
|
9
8
|
declare global {
|
|
10
9
|
type Signal<T = any> = import('./signal').Signal<T>
|
|
11
10
|
type Computed<T = any> = import('./signal').Computed<T>
|
|
12
11
|
type SignalAccessor<T> = import('./signal').SignalAccessor<T>
|
|
12
|
+
type Composable<T extends (...args: any[]) => any> = import('./composable').Composable<T>
|
|
13
|
+
type DirectiveBinding<V = any> = import('./directives').DirectiveBinding<V>
|
|
14
|
+
type DirectiveHooks<V = any> = import('./directives').DirectiveHooks<V>
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
// Re-export as namespace for convenience
|
|
16
17
|
export as namespace Fusee
|
|
@@ -6,13 +6,47 @@ export type SignalAccessor<T> = {
|
|
|
6
6
|
isSignal: boolean;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
export interface ReactiveArrayMethods<T> {
|
|
10
|
+
map<U>(callbackfn: (value: T, index: number, array: T[]) => U): Computed<U[]>;
|
|
11
|
+
filter(predicate: (value: T, index: number, array: T[]) => boolean): Computed<T[]>;
|
|
12
|
+
slice(start?: number, end?: number): Computed<T[]>;
|
|
13
|
+
reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): Computed<U>;
|
|
14
|
+
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): Computed<T>;
|
|
15
|
+
find(predicate: (value: T, index: number, obj: T[]) => boolean): Computed<T | undefined>;
|
|
16
|
+
findLast(predicate: (value: T, index: number, obj: T[]) => boolean): Computed<T | undefined>;
|
|
17
|
+
findIndex(predicate: (value: T, index: number, obj: T[]) => boolean): Computed<number>;
|
|
18
|
+
findLastIndex(predicate: (value: T, index: number, obj: T[]) => boolean): Computed<number>;
|
|
19
|
+
every(predicate: (value: T, index: number, array: T[]) => boolean): Computed<boolean>;
|
|
20
|
+
some(predicate: (value: T, index: number, array: T[]) => boolean): Computed<boolean>;
|
|
21
|
+
includes(searchElement: T, fromIndex?: number): Computed<boolean>;
|
|
22
|
+
indexOf(searchElement: T, fromIndex?: number): Computed<number>;
|
|
23
|
+
lastIndexOf(searchElement: T, fromIndex?: number): Computed<number>;
|
|
24
|
+
at(index: number): Computed<T | undefined>;
|
|
25
|
+
concat(...items: (T | T[])[]): Computed<T[]>;
|
|
26
|
+
flat<depth extends number = 1>(depth?: depth): Computed<any[]>;
|
|
27
|
+
flatMap<U>(callback: (value: T, index: number, array: T[]) => U | U[]): Computed<U[]>;
|
|
28
|
+
join(separator?: string): Computed<string>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type ArraySignalAccessor<T extends any[]> = SignalAccessor<T> & ReactiveArrayMethods<T[number]> & {
|
|
32
|
+
push(...items: T[number][]): number;
|
|
33
|
+
pop(): T[number] | undefined;
|
|
34
|
+
shift(): T[number] | undefined;
|
|
35
|
+
unshift(...items: T[number][]): number;
|
|
36
|
+
splice(start: number, deleteCount: number, ...items: T[number][]): T[number][];
|
|
37
|
+
remove(predicate: (item: T[number], index: number) => boolean): void;
|
|
38
|
+
clear(): void;
|
|
39
|
+
sort(compareFn?: (a: T[number], b: T[number]) => number): ArraySignalAccessor<T>;
|
|
40
|
+
reverse(): ArraySignalAccessor<T>;
|
|
41
|
+
}
|
|
42
|
+
|
|
9
43
|
export type ComputedAccessor<T> = {
|
|
10
44
|
(): T;
|
|
11
45
|
isSignal: boolean;
|
|
12
46
|
readonly: true;
|
|
13
|
-
}
|
|
47
|
+
} & (T extends any[] ? ReactiveArrayMethods<T[number]> : {})
|
|
14
48
|
|
|
15
|
-
export type Signal<T = any> = SignalAccessor<T>
|
|
49
|
+
export type Signal<T = any> = T extends any[] ? ArraySignalAccessor<T> : SignalAccessor<T>
|
|
16
50
|
export type Computed<T = any> = ComputedAccessor<T>
|
|
17
51
|
|
|
18
52
|
type EffectRunner = {
|
|
@@ -20,7 +54,8 @@ type EffectRunner = {
|
|
|
20
54
|
deps: Set<Set<EffectRunner>>;
|
|
21
55
|
}
|
|
22
56
|
|
|
23
|
-
export declare function signal<T>(initialValue: T):
|
|
57
|
+
export declare function signal<T extends any[]>(initialValue: T): ArraySignalAccessor<T>
|
|
58
|
+
export declare function signal<T>(initialValue: T): SignalAccessor<T>
|
|
24
59
|
export declare function effect(fn: () => void): () => void
|
|
25
60
|
export declare function computed<T>(fn: () => T): Computed<T>
|
|
26
61
|
export declare function batch<T>(fn: () => T): T
|
package/index.html
CHANGED
|
@@ -160,6 +160,139 @@
|
|
|
160
160
|
opacity: 0.3;
|
|
161
161
|
cursor: not-allowed;
|
|
162
162
|
}
|
|
163
|
+
|
|
164
|
+
/* ── Composables demo ──────────────────────────────────────────── */
|
|
165
|
+
.demo-card {
|
|
166
|
+
background: #13131d;
|
|
167
|
+
border: 1px solid #2a2a3a;
|
|
168
|
+
border-radius: 12px;
|
|
169
|
+
padding: 1.5rem;
|
|
170
|
+
margin-bottom: 1.5rem;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
.demo-card h2 {
|
|
174
|
+
font-size: 1rem;
|
|
175
|
+
font-weight: 600;
|
|
176
|
+
color: #e8e8f0;
|
|
177
|
+
margin-bottom: 0.35rem;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
.demo-desc {
|
|
181
|
+
font-size: 0.8rem;
|
|
182
|
+
color: #555 !important;
|
|
183
|
+
margin-bottom: 1rem !important;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.counter-display {
|
|
187
|
+
display: flex;
|
|
188
|
+
flex-direction: column;
|
|
189
|
+
align-items: center;
|
|
190
|
+
margin-bottom: 1rem;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.big-num {
|
|
194
|
+
font-size: 3.5rem;
|
|
195
|
+
font-weight: 700;
|
|
196
|
+
line-height: 1;
|
|
197
|
+
transition: color 0.2s;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
.big-num.even {
|
|
201
|
+
color: #8b8bff;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.big-num.odd {
|
|
205
|
+
color: #ff3333;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.derived-label {
|
|
209
|
+
font-size: 0.8rem;
|
|
210
|
+
color: #555;
|
|
211
|
+
margin-top: 0.25rem;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
.btn-row {
|
|
215
|
+
display: flex;
|
|
216
|
+
gap: 0.5rem;
|
|
217
|
+
justify-content: center;
|
|
218
|
+
margin-bottom: 0.75rem;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
.cmp-btn {
|
|
222
|
+
padding: 0.45rem 1.1rem;
|
|
223
|
+
border-radius: 6px;
|
|
224
|
+
border: 1px solid #2a2a3a;
|
|
225
|
+
background: #0f0f1a;
|
|
226
|
+
color: #e8e8f0;
|
|
227
|
+
cursor: pointer;
|
|
228
|
+
font-size: 1rem;
|
|
229
|
+
transition: background 0.15s;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
.cmp-btn:hover {
|
|
233
|
+
background: #1f1f30;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
.cmp-btn.plus {
|
|
237
|
+
border-color: #8b8bff;
|
|
238
|
+
color: #8b8bff;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
.cmp-btn.minus {
|
|
242
|
+
border-color: #ff3333;
|
|
243
|
+
color: #ff3333;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
.cmp-btn.reset {
|
|
247
|
+
border-color: #555;
|
|
248
|
+
color: #888;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
.badge {
|
|
252
|
+
display: inline-block;
|
|
253
|
+
padding: 0.2rem 0.65rem;
|
|
254
|
+
border-radius: 999px;
|
|
255
|
+
font-size: 0.75rem;
|
|
256
|
+
font-weight: 600;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
.badge-blue {
|
|
260
|
+
background: rgba(139, 139, 255, 0.15);
|
|
261
|
+
color: #8b8bff;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
.badge-red {
|
|
265
|
+
background: rgba(255, 51, 51, 0.12);
|
|
266
|
+
color: #ff3333;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
.mouse-display {
|
|
270
|
+
display: flex;
|
|
271
|
+
gap: 2rem;
|
|
272
|
+
font-size: 1.1rem;
|
|
273
|
+
color: #aaa;
|
|
274
|
+
margin-bottom: 0.5rem;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
.mouse-display strong {
|
|
278
|
+
color: #e8e8f0;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
.cmp-input {
|
|
282
|
+
width: 100%;
|
|
283
|
+
padding: 0.5rem 0.75rem;
|
|
284
|
+
background: #0f0f1a;
|
|
285
|
+
border: 1px solid #2a2a3a;
|
|
286
|
+
border-radius: 6px;
|
|
287
|
+
color: #e8e8f0;
|
|
288
|
+
font-size: 0.95rem;
|
|
289
|
+
outline: none;
|
|
290
|
+
transition: border-color 0.15s;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
.cmp-input:focus {
|
|
294
|
+
border-color: #8b8bff;
|
|
295
|
+
}
|
|
163
296
|
</style>
|
|
164
297
|
</head>
|
|
165
298
|
|
|
@@ -169,6 +302,7 @@
|
|
|
169
302
|
<a href="#/about">About</a>
|
|
170
303
|
<a href="#/test-for">Loops Test</a>
|
|
171
304
|
<a href="#/dynamic" style="color: #ec4899;">Dynamic Components</a>
|
|
305
|
+
<a href="#/composables" style="color: #34d399;">Composables</a>
|
|
172
306
|
</nav>
|
|
173
307
|
<div id="app"></div>
|
|
174
308
|
<script type="module" src="./app/main.js"></script>
|