revojs 0.0.16 → 0.0.18
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 +5 -5
- package/dist/index.js +14 -20
- package/dist/jsx/index.js +3 -3
- package/dist/signals/index.d.ts +10 -9
- package/package.json +1 -1
package/dist/html/index.d.ts
CHANGED
|
@@ -45,13 +45,13 @@ export interface ComponentOptions<TEvents extends Events, TAttributes extends At
|
|
|
45
45
|
export interface Component<TEvents extends Events, TAttributes extends Attributes> {
|
|
46
46
|
readonly scope: Scope;
|
|
47
47
|
readonly hooks: Hooks;
|
|
48
|
-
readonly context: Map<
|
|
48
|
+
readonly context: Map<symbol, unknown>;
|
|
49
49
|
readonly events: EventOutput<TEvents>;
|
|
50
50
|
readonly attributes: State<AttributeOutput<TAttributes>>;
|
|
51
51
|
readonly shadowRoot: false | ShadowRootInit;
|
|
52
52
|
readonly host?: CustomElement<TEvents, TAttributes>;
|
|
53
|
-
getContext: <T>(input:
|
|
54
|
-
setContext: <T>(input:
|
|
53
|
+
getContext: <T>(input: Descriptor<T>) => T;
|
|
54
|
+
setContext: <T>(input: Descriptor<T>, value: T) => void;
|
|
55
55
|
onMounted: (invoke: (input: HTMLElement) => void | Promise<void>) => void;
|
|
56
56
|
setup: () => Slot | Promise<Slot>;
|
|
57
57
|
}
|
|
@@ -59,7 +59,7 @@ export interface ComponentConstructor<TEvents extends Events, TAttributes extend
|
|
|
59
59
|
$name: string;
|
|
60
60
|
$events: TEvents;
|
|
61
61
|
$attributes: TAttributes;
|
|
62
|
-
new (input?: Input<TEvents, TAttributes>, context?: Map<
|
|
62
|
+
new (input?: Input<TEvents, TAttributes>, context?: Map<symbol, unknown>, host?: CustomElement<TEvents, TAttributes>): Component<TEvents, TAttributes>;
|
|
63
63
|
}
|
|
64
64
|
export interface CustomElement<TEvents extends Events, TAttributes extends Attributes> extends HTMLElement {
|
|
65
65
|
readonly component: Component<TEvents, TAttributes>;
|
|
@@ -71,7 +71,7 @@ export declare const isTemplate: (value: object) => value is Template;
|
|
|
71
71
|
export declare const createElement: <TEvents extends Events, TAttributes extends Attributes>(input: string | Template | ComponentConstructor<TEvents, TAttributes>, attributes?: AttributeInput<TAttributes>, ...children: Array<Slot>) => Slot;
|
|
72
72
|
export declare const toString: (slot: Slot) => string;
|
|
73
73
|
export declare const toFragment: (nodes: Array<Node>) => DocumentFragment;
|
|
74
|
-
export declare const renderToString: (slot: Slot, context: Map<
|
|
74
|
+
export declare const renderToString: (slot: Slot, context: Map<symbol, unknown>) => Promise<string>;
|
|
75
75
|
export declare const renderToNode: (scope: Scope, slot: Slot) => Promise<Node>;
|
|
76
76
|
export declare const defineComponent: <TEvents extends Events = {}, TAttributes extends Attributes = {}>(options: ComponentOptions<TEvents, TAttributes>) => ComponentConstructor<TEvents, TAttributes>;
|
|
77
77
|
export declare const toCustomElement: <TEvents extends Events = {}, TAttributes extends Attributes = {}>(component: ComponentConstructor<TEvents, TAttributes>) => CustomElementConstructor<TEvents, TAttributes>;
|
package/dist/index.js
CHANGED
|
@@ -113,14 +113,13 @@ var Hooks = class {
|
|
|
113
113
|
this.hooks = new Map();
|
|
114
114
|
}
|
|
115
115
|
on = (scope, input, invoke) => {
|
|
116
|
-
const
|
|
117
|
-
const invokes = this.hooks.get(key) ?? new Set();
|
|
116
|
+
const invokes = this.hooks.get(input) ?? new Set();
|
|
118
117
|
invokes.add(invoke);
|
|
119
|
-
this.hooks.set(
|
|
118
|
+
this.hooks.set(input, invokes);
|
|
120
119
|
return scope.dispose.push(() => invokes.delete(invoke));
|
|
121
120
|
};
|
|
122
121
|
dispatch = (input, value) => {
|
|
123
|
-
const invokes = this.hooks.get(
|
|
122
|
+
const invokes = this.hooks.get(input);
|
|
124
123
|
if (invokes) for (const invoke of invokes) invoke(value);
|
|
125
124
|
};
|
|
126
125
|
};
|
|
@@ -198,14 +197,11 @@ function fromValue(value) {
|
|
|
198
197
|
if (value instanceof Function) return fromValue(value());
|
|
199
198
|
return value;
|
|
200
199
|
}
|
|
201
|
-
function
|
|
202
|
-
return (
|
|
200
|
+
function defineHook() {
|
|
201
|
+
return Symbol();
|
|
203
202
|
}
|
|
204
|
-
function
|
|
205
|
-
return
|
|
206
|
-
}
|
|
207
|
-
function defineContext(description) {
|
|
208
|
-
return { key: Symbol(description) };
|
|
203
|
+
function defineContext() {
|
|
204
|
+
return Symbol();
|
|
209
205
|
}
|
|
210
206
|
let activeCompute;
|
|
211
207
|
const targets = new WeakMap();
|
|
@@ -319,7 +315,7 @@ const renderToNode = async (scope, slot) => {
|
|
|
319
315
|
const children = await Promise.all(slot.map((child) => renderToNode(scope, child)));
|
|
320
316
|
return toFragment(children);
|
|
321
317
|
}
|
|
322
|
-
return document.
|
|
318
|
+
return document.createDocumentFragment();
|
|
323
319
|
}
|
|
324
320
|
if (isTemplate(slot)) {
|
|
325
321
|
const element = document.createElementNS(namespace(slot.tag), slot.tag);
|
|
@@ -368,10 +364,10 @@ const defineComponent = (options) => {
|
|
|
368
364
|
this.host = host;
|
|
369
365
|
}
|
|
370
366
|
getContext = (input) => {
|
|
371
|
-
return this.context.get(
|
|
367
|
+
return this.context.get(input) ?? {};
|
|
372
368
|
};
|
|
373
369
|
setContext = (input, value) => {
|
|
374
|
-
this.context.set(
|
|
370
|
+
this.context.set(input, value);
|
|
375
371
|
};
|
|
376
372
|
onMounted = (invoke) => {
|
|
377
373
|
return this.hooks.on(this.scope, MOUNTED_HOOK, invoke);
|
|
@@ -458,7 +454,7 @@ const isServer = () => typeof window === "undefined";
|
|
|
458
454
|
const preventDefault = (event) => event.preventDefault();
|
|
459
455
|
const stopPropagation = (event) => event.stopPropagation();
|
|
460
456
|
const stopImmediatePropagation = (event) => event.stopImmediatePropagation();
|
|
461
|
-
const MOUNTED_HOOK = defineHook(
|
|
457
|
+
const MOUNTED_HOOK = defineHook();
|
|
462
458
|
const components = new Map();
|
|
463
459
|
|
|
464
460
|
//#endregion
|
|
@@ -709,9 +705,7 @@ const createRuntime = async () => {
|
|
|
709
705
|
if (typeof route === "object") return route.fetch(event);
|
|
710
706
|
if (route) {
|
|
711
707
|
const slot = await import("#virtual/client").then((module) => module.index);
|
|
712
|
-
|
|
713
|
-
context.set(descriptor(RUNTIME_CONTEXT), { event });
|
|
714
|
-
return sendHtml(event, await renderToString(slot, context));
|
|
708
|
+
return sendHtml(event, await renderToString(slot, new Map().set(RUNTIME_CONTEXT, { event })));
|
|
715
709
|
}
|
|
716
710
|
} }));
|
|
717
711
|
}
|
|
@@ -746,7 +740,7 @@ const createRuntime = async () => {
|
|
|
746
740
|
}
|
|
747
741
|
};
|
|
748
742
|
};
|
|
749
|
-
const RUNTIME_CONTEXT = defineContext(
|
|
743
|
+
const RUNTIME_CONTEXT = defineContext();
|
|
750
744
|
|
|
751
745
|
//#endregion
|
|
752
746
|
//#region src/router/index.tsx
|
|
@@ -787,4 +781,4 @@ const anchorNavigate = (event) => {
|
|
|
787
781
|
};
|
|
788
782
|
|
|
789
783
|
//#endregion
|
|
790
|
-
export { $fetch, Compute, Handler, Hooks, MOUNTED_HOOK, Outlet, RUNTIME_CONTEXT, Radix, Scope, activeCompute, anchorNavigate, components, createApp, createCompute, createElement, createEvent, createMemo, createRuntime, createState, defineComponent, defineContext, defineHook, defineRoute,
|
|
784
|
+
export { $fetch, Compute, Handler, Hooks, MOUNTED_HOOK, Outlet, RUNTIME_CONTEXT, Radix, Scope, activeCompute, anchorNavigate, components, createApp, createCompute, createElement, createEvent, createMemo, createRuntime, createState, defineComponent, defineContext, defineHook, 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 };
|
package/dist/jsx/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
//#region src/signals/index.ts
|
|
3
|
-
function defineHook(
|
|
4
|
-
return
|
|
3
|
+
function defineHook() {
|
|
4
|
+
return Symbol();
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
//#endregion
|
|
@@ -14,7 +14,7 @@ const createElement = (input, attributes, ...children) => {
|
|
|
14
14
|
children
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
|
-
const MOUNTED_HOOK = defineHook(
|
|
17
|
+
const MOUNTED_HOOK = defineHook();
|
|
18
18
|
|
|
19
19
|
//#endregion
|
|
20
20
|
//#region src/jsx/index.ts
|
package/dist/signals/index.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
+
declare const descriptor: unique symbol;
|
|
1
2
|
export type Value<T> = T | (() => Value<T>);
|
|
3
|
+
export type Descriptor<T> = symbol & {
|
|
4
|
+
[descriptor]: T;
|
|
5
|
+
};
|
|
2
6
|
export interface State<T> {
|
|
3
7
|
value: T;
|
|
4
8
|
}
|
|
5
|
-
export type Descriptor<T> = {
|
|
6
|
-
key: symbol;
|
|
7
|
-
};
|
|
8
9
|
export declare class Hooks {
|
|
9
|
-
readonly hooks: Map<
|
|
10
|
+
readonly hooks: Map<symbol, Set<(value: any) => unknown>>;
|
|
10
11
|
constructor();
|
|
11
|
-
on: <T>(scope: Scope, input:
|
|
12
|
-
dispatch: <T>(input:
|
|
12
|
+
on: <T>(scope: Scope, input: Descriptor<T>, invoke: (value: T) => unknown) => number;
|
|
13
|
+
dispatch: <T>(input: Descriptor<T>, value: T) => void;
|
|
13
14
|
}
|
|
14
15
|
export declare class Scope {
|
|
15
16
|
readonly dispose: Array<(scope: Scope) => void>;
|
|
@@ -31,8 +32,8 @@ export declare function createState<T>(value: T): State<T>;
|
|
|
31
32
|
export declare function createCompute<T>(scope: Scope, invoke: (scope: Scope) => T): T;
|
|
32
33
|
export declare function createMemo<T>(scope: Scope, invoke: () => T): State<T>;
|
|
33
34
|
export declare function fromValue<T>(value: Value<T>): T;
|
|
34
|
-
export declare function
|
|
35
|
-
export declare function
|
|
36
|
-
export declare function defineContext<T>(description?: string | number): Descriptor<T>;
|
|
35
|
+
export declare function defineHook<T>(): Descriptor<T>;
|
|
36
|
+
export declare function defineContext<T>(): Descriptor<T>;
|
|
37
37
|
export declare let activeCompute: Compute | undefined;
|
|
38
38
|
export declare const targets: WeakMap<object, Map<string | symbol, Set<Compute<void>>>>;
|
|
39
|
+
export {};
|