revojs 0.0.24 → 0.0.25
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/html/index.d.ts +4 -3
- package/dist/index.js +20 -35
- package/dist/jsx/index.js +0 -7
- package/dist/signals/index.d.ts +9 -8
- package/package.json +1 -1
package/dist/html/index.d.ts
CHANGED
|
@@ -67,7 +67,7 @@ export interface CustomElementConstructor<TEvents extends Events, TAttributes ex
|
|
|
67
67
|
new (): CustomElement<TEvents, TAttributes>;
|
|
68
68
|
}
|
|
69
69
|
export declare class MountedEvent extends Event {
|
|
70
|
-
constructor(
|
|
70
|
+
constructor();
|
|
71
71
|
}
|
|
72
72
|
export declare const isTemplate: (value: object) => value is Template;
|
|
73
73
|
export declare const createElement: <TEvents extends Events, TAttributes extends Attributes>(input: string | ComponentConstructor<TEvents, TAttributes>, attributes?: AttributeInput<TAttributes>, ...children: Array<Slot>) => Slot;
|
|
@@ -79,14 +79,15 @@ export declare const defineComponent: <TEvents extends Events = {}, TAttributes
|
|
|
79
79
|
export declare const toCustomElement: <TEvents extends Events = {}, TAttributes extends Attributes = {}>(component: ComponentConstructor<TEvents, TAttributes>) => CustomElementConstructor<TEvents, TAttributes>;
|
|
80
80
|
export declare const registerComponent: <TEvents extends Events = {}, TAttributes extends Attributes = {}>(component: ComponentConstructor<TEvents, TAttributes>) => ComponentConstructor<TEvents, TAttributes>;
|
|
81
81
|
export declare const getGlobalStyles: () => CSSStyleSheet[];
|
|
82
|
-
export declare
|
|
82
|
+
export declare function useEvent<T extends keyof ElementEventMap>(scope: Scope, target: EventTarget | undefined, event: T, input: EventListener<ElementEventMap[T]>, options?: AddEventListenerOptions): void;
|
|
83
|
+
export declare function useEvent<T extends keyof WindowEventMap>(scope: Scope, target: Window | undefined, event: T, input: EventListener<WindowEventMap[T]>, options?: AddEventListenerOptions): void;
|
|
84
|
+
export declare function useEvent<T extends keyof HTMLElementEventMap>(scope: Scope, target: HTMLElement | undefined, event: T, input: EventListener<HTMLElementEventMap[T]>, options?: AddEventListenerOptions): void;
|
|
83
85
|
export declare const getCustomElement: (node: Node | null) => CustomElement<Events, Attributes> | undefined;
|
|
84
86
|
export declare const isClient: () => boolean;
|
|
85
87
|
export declare const isServer: () => boolean;
|
|
86
88
|
export declare const preventDefault: (event: Event) => void;
|
|
87
89
|
export declare const stopPropagation: (event: Event) => void;
|
|
88
90
|
export declare const stopImmediatePropagation: (event: Event) => void;
|
|
89
|
-
export declare const MOUNTED_HOOK: Descriptor<HTMLElement>;
|
|
90
91
|
export declare const components: Map<string, ComponentConstructor<Events, Attributes>>;
|
|
91
92
|
declare global {
|
|
92
93
|
interface HTMLElementEventMap {
|
package/dist/index.js
CHANGED
|
@@ -107,29 +107,20 @@ const namespace = (tag) => {
|
|
|
107
107
|
|
|
108
108
|
//#endregion
|
|
109
109
|
//#region src/signals/index.ts
|
|
110
|
-
var
|
|
111
|
-
hooks;
|
|
110
|
+
var StopEvent = class extends Event {
|
|
112
111
|
constructor() {
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
on(scope, input, invoke) {
|
|
116
|
-
const invokes = this.hooks.get(input) ?? new Set();
|
|
117
|
-
invokes.add(invoke);
|
|
118
|
-
this.hooks.set(input, invokes);
|
|
119
|
-
return scope.dispose.push(() => invokes.delete(invoke));
|
|
120
|
-
}
|
|
121
|
-
dispatch(input, value) {
|
|
122
|
-
const invokes = this.hooks.get(input);
|
|
123
|
-
if (invokes) for (const invoke of invokes) invoke(value);
|
|
112
|
+
super("stop");
|
|
124
113
|
}
|
|
125
114
|
};
|
|
126
|
-
var Scope = class {
|
|
127
|
-
dispose;
|
|
115
|
+
var Scope = class extends EventTarget {
|
|
128
116
|
constructor() {
|
|
129
|
-
|
|
117
|
+
super();
|
|
118
|
+
}
|
|
119
|
+
onStop(input) {
|
|
120
|
+
this.addEventListener("stop", input, { once: true });
|
|
130
121
|
}
|
|
131
122
|
stop() {
|
|
132
|
-
|
|
123
|
+
return this.dispatchEvent(new StopEvent());
|
|
133
124
|
}
|
|
134
125
|
};
|
|
135
126
|
var Compute = class extends Scope {
|
|
@@ -153,7 +144,7 @@ var Handler = class Handler {
|
|
|
153
144
|
const set = computes.get(key) ?? new Set();
|
|
154
145
|
computes.set(key, set.add(compute));
|
|
155
146
|
targets.set(target, computes);
|
|
156
|
-
compute.scope.
|
|
147
|
+
compute.scope.onStop(() => {
|
|
157
148
|
compute.stop();
|
|
158
149
|
set.delete(compute);
|
|
159
150
|
});
|
|
@@ -197,9 +188,6 @@ function fromValue(value) {
|
|
|
197
188
|
if (value instanceof Function) return fromValue(value());
|
|
198
189
|
return value;
|
|
199
190
|
}
|
|
200
|
-
function defineHook(key) {
|
|
201
|
-
return key;
|
|
202
|
-
}
|
|
203
191
|
function defineContext(key) {
|
|
204
192
|
return key;
|
|
205
193
|
}
|
|
@@ -209,8 +197,8 @@ const targets = new WeakMap();
|
|
|
209
197
|
//#endregion
|
|
210
198
|
//#region src/html/index.ts
|
|
211
199
|
var MountedEvent = class extends Event {
|
|
212
|
-
constructor(
|
|
213
|
-
super("mounted"
|
|
200
|
+
constructor() {
|
|
201
|
+
super("mounted");
|
|
214
202
|
}
|
|
215
203
|
};
|
|
216
204
|
const isTemplate = (value) => {
|
|
@@ -325,8 +313,10 @@ const renderToNode = async (scope, slot) => {
|
|
|
325
313
|
const element = document.createElementNS(namespace(slot.tag), slot.tag);
|
|
326
314
|
for (const name in slot.attributes) {
|
|
327
315
|
const value = slot.attributes[name];
|
|
328
|
-
if (name.startsWith("on"))
|
|
329
|
-
|
|
316
|
+
if (name.startsWith("on")) {
|
|
317
|
+
const event = name.substring(2).toLowerCase();
|
|
318
|
+
useEvent(scope, element, event, value);
|
|
319
|
+
} else createCompute(scope, () => {
|
|
330
320
|
const set = toString(value);
|
|
331
321
|
if (set === "" || set === "false") return element.removeAttribute(name);
|
|
332
322
|
return element.setAttribute(name, set);
|
|
@@ -442,7 +432,7 @@ const getGlobalStyles = () => {
|
|
|
442
432
|
return sheet;
|
|
443
433
|
});
|
|
444
434
|
};
|
|
445
|
-
|
|
435
|
+
function useEvent(scope, target, event, input, options) {
|
|
446
436
|
const controller = new AbortController();
|
|
447
437
|
target?.addEventListener(event, (event$1) => {
|
|
448
438
|
if (Array.isArray(input)) for (const target$1 of input) target$1?.(event$1);
|
|
@@ -451,8 +441,8 @@ const useEvent = (scope, target, event, input, options) => {
|
|
|
451
441
|
signal: controller.signal,
|
|
452
442
|
...options
|
|
453
443
|
});
|
|
454
|
-
|
|
455
|
-
}
|
|
444
|
+
scope.onStop(() => controller.abort());
|
|
445
|
+
}
|
|
456
446
|
const getCustomElement = (node) => {
|
|
457
447
|
if (node) {
|
|
458
448
|
if ("component" in node) return node;
|
|
@@ -464,7 +454,6 @@ const isServer = () => typeof window === "undefined";
|
|
|
464
454
|
const preventDefault = (event) => event.preventDefault();
|
|
465
455
|
const stopPropagation = (event) => event.stopPropagation();
|
|
466
456
|
const stopImmediatePropagation = (event) => event.stopImmediatePropagation();
|
|
467
|
-
const MOUNTED_HOOK = defineHook("MOUNTED_HOOK");
|
|
468
457
|
const components = new Map();
|
|
469
458
|
|
|
470
459
|
//#endregion
|
|
@@ -766,11 +755,7 @@ const Outlet = defineComponent({
|
|
|
766
755
|
if (name) radix.insert(name, routes[path]);
|
|
767
756
|
}
|
|
768
757
|
const url = createState(new URL(event ? event.request.url : window.location.href));
|
|
769
|
-
if (isClient())
|
|
770
|
-
const controller = new AbortController();
|
|
771
|
-
window.addEventListener("popstate", () => url.value = new URL(window.location.href), { signal: controller.signal });
|
|
772
|
-
scope.dispose.push(() => controller.abort());
|
|
773
|
-
}
|
|
758
|
+
if (isClient()) useEvent(scope, window, "popstate", () => url.value = new URL(window.location.href));
|
|
774
759
|
return async () => {
|
|
775
760
|
const { value, inputs } = radix.match(url.value.pathname);
|
|
776
761
|
const Page = await value?.();
|
|
@@ -791,4 +776,4 @@ const anchorNavigate = (event) => {
|
|
|
791
776
|
};
|
|
792
777
|
|
|
793
778
|
//#endregion
|
|
794
|
-
export { $fetch, Compute, Handler,
|
|
779
|
+
export { $fetch, Compute, Handler, MountedEvent, Outlet, RUNTIME_CONTEXT, Radix, Scope, StopEvent, activeCompute, anchorNavigate, components, createApp, createCompute, createElement, createEvent, createMemo, createRuntime, createState, defineComponent, defineContext, defineRoute, fileName, fromValue, getAssets, getCookies, getCustomElement, getGlobalStyles, getMimeType, getRequestUrl, getRoutes, getSetCookies, getVariables, isClient, isServer, isTemplate, markdownToSlot, navigate, preventDefault, registerComponent, renderToNode, renderToString, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, stopImmediatePropagation, stopPropagation, targets, toCustomElement, toFragment, toPath, toString, useEvent };
|
package/dist/jsx/index.js
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
|
|
2
|
-
//#region src/signals/index.ts
|
|
3
|
-
function defineHook(key) {
|
|
4
|
-
return key;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
//#endregion
|
|
8
2
|
//#region src/html/index.ts
|
|
9
3
|
const createElement = (input, attributes, ...children) => {
|
|
10
4
|
return {
|
|
@@ -13,7 +7,6 @@ const createElement = (input, attributes, ...children) => {
|
|
|
13
7
|
children
|
|
14
8
|
};
|
|
15
9
|
};
|
|
16
|
-
const MOUNTED_HOOK = defineHook("MOUNTED_HOOK");
|
|
17
10
|
|
|
18
11
|
//#endregion
|
|
19
12
|
//#region src/jsx/index.ts
|
package/dist/signals/index.d.ts
CHANGED
|
@@ -6,16 +6,13 @@ export type Descriptor<T> = string & {
|
|
|
6
6
|
export interface State<T> {
|
|
7
7
|
value: T;
|
|
8
8
|
}
|
|
9
|
-
export declare class
|
|
10
|
-
readonly hooks: Map<string, Set<(value: any) => unknown>>;
|
|
9
|
+
export declare class StopEvent extends Event {
|
|
11
10
|
constructor();
|
|
12
|
-
on<T>(scope: Scope, input: Descriptor<T>, invoke: (value: T) => unknown): number;
|
|
13
|
-
dispatch<T>(input: Descriptor<T>, value: T): void;
|
|
14
11
|
}
|
|
15
|
-
export declare class Scope {
|
|
16
|
-
readonly dispose: Array<(scope: Scope) => void>;
|
|
12
|
+
export declare class Scope extends EventTarget {
|
|
17
13
|
constructor();
|
|
18
|
-
|
|
14
|
+
onStop(input: (event: StopEvent) => void): void;
|
|
15
|
+
stop(): boolean;
|
|
19
16
|
}
|
|
20
17
|
export declare class Compute<T = void> extends Scope {
|
|
21
18
|
readonly scope: Scope;
|
|
@@ -32,8 +29,12 @@ export declare function createState<T>(value: T): State<T>;
|
|
|
32
29
|
export declare function createCompute<T>(scope: Scope, invoke: (scope: Scope) => T): T;
|
|
33
30
|
export declare function createMemo<T>(scope: Scope, invoke: (scope: Scope) => T): State<T>;
|
|
34
31
|
export declare function fromValue<T>(value: Value<T>): T;
|
|
35
|
-
export declare function defineHook<T>(key: string): Descriptor<T>;
|
|
36
32
|
export declare function defineContext<T>(key: string): Descriptor<T>;
|
|
37
33
|
export declare let activeCompute: Compute | undefined;
|
|
38
34
|
export declare const targets: WeakMap<object, Map<string | symbol, Set<Compute<void>>>>;
|
|
35
|
+
declare global {
|
|
36
|
+
interface ElementEventMap {
|
|
37
|
+
stop: StopEvent;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
39
40
|
export {};
|