revojs 0.0.18 → 0.0.19
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 +3 -3
- package/dist/index.js +19 -15
- package/dist/jsx/index.js +3 -3
- package/dist/signals/index.d.ts +6 -6
- package/package.json +1 -1
package/dist/html/index.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ 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<string, unknown>;
|
|
49
49
|
readonly events: EventOutput<TEvents>;
|
|
50
50
|
readonly attributes: State<AttributeOutput<TAttributes>>;
|
|
51
51
|
readonly shadowRoot: false | ShadowRootInit;
|
|
@@ -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<string, 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<string, 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
|
@@ -112,16 +112,16 @@ var Hooks = class {
|
|
|
112
112
|
constructor() {
|
|
113
113
|
this.hooks = new Map();
|
|
114
114
|
}
|
|
115
|
-
on
|
|
115
|
+
on(scope, input, invoke) {
|
|
116
116
|
const invokes = this.hooks.get(input) ?? new Set();
|
|
117
117
|
invokes.add(invoke);
|
|
118
118
|
this.hooks.set(input, invokes);
|
|
119
119
|
return scope.dispose.push(() => invokes.delete(invoke));
|
|
120
|
-
}
|
|
121
|
-
dispatch
|
|
120
|
+
}
|
|
121
|
+
dispatch(input, value) {
|
|
122
122
|
const invokes = this.hooks.get(input);
|
|
123
123
|
if (invokes) for (const invoke of invokes) invoke(value);
|
|
124
|
-
}
|
|
124
|
+
}
|
|
125
125
|
};
|
|
126
126
|
var Scope = class {
|
|
127
127
|
dispose;
|
|
@@ -197,11 +197,11 @@ function fromValue(value) {
|
|
|
197
197
|
if (value instanceof Function) return fromValue(value());
|
|
198
198
|
return value;
|
|
199
199
|
}
|
|
200
|
-
function defineHook() {
|
|
201
|
-
return
|
|
200
|
+
function defineHook(key) {
|
|
201
|
+
return key;
|
|
202
202
|
}
|
|
203
|
-
function defineContext() {
|
|
204
|
-
return
|
|
203
|
+
function defineContext(key) {
|
|
204
|
+
return key;
|
|
205
205
|
}
|
|
206
206
|
let activeCompute;
|
|
207
207
|
const targets = new WeakMap();
|
|
@@ -321,12 +321,16 @@ const renderToNode = async (scope, slot) => {
|
|
|
321
321
|
const element = document.createElementNS(namespace(slot.tag), slot.tag);
|
|
322
322
|
for (const name in slot.attributes) {
|
|
323
323
|
const value = slot.attributes[name];
|
|
324
|
-
if (
|
|
324
|
+
if (name.startsWith("on")) {
|
|
325
325
|
const event = name.substring(2).toLowerCase();
|
|
326
326
|
const controller = new AbortController();
|
|
327
|
-
element.addEventListener(event, value, { signal: controller.signal });
|
|
327
|
+
element.addEventListener(event, (event$1) => typeof value === "function" ? value(event$1) : void 0, { signal: controller.signal });
|
|
328
328
|
scope.dispose.push(() => controller.abort());
|
|
329
|
-
} else createCompute(scope, () =>
|
|
329
|
+
} else createCompute(scope, () => {
|
|
330
|
+
const set = toString(value);
|
|
331
|
+
if (set === "" || set === "false") return element.removeAttribute(name);
|
|
332
|
+
return element.setAttribute(name, set);
|
|
333
|
+
});
|
|
330
334
|
}
|
|
331
335
|
element.replaceChildren(await renderToNode(scope, slot.children));
|
|
332
336
|
return element;
|
|
@@ -384,7 +388,7 @@ const toCustomElement = (component) => {
|
|
|
384
388
|
this.component = new component(void 0, void 0, this);
|
|
385
389
|
}
|
|
386
390
|
async connectedCallback() {
|
|
387
|
-
const
|
|
391
|
+
const rootNode = this.component.shadowRoot ? this.attachShadow(this.component.shadowRoot) : this;
|
|
388
392
|
const parentNode = getCustomElement(this.parentNode);
|
|
389
393
|
for (const [name, event] of Object.entries(component.$events)) Reflect.set(this.component.events, name, (value) => {
|
|
390
394
|
if (value instanceof Event) return;
|
|
@@ -394,7 +398,7 @@ const toCustomElement = (component) => {
|
|
|
394
398
|
}));
|
|
395
399
|
}, this.component.events);
|
|
396
400
|
if (parentNode) for (const [name, value] of parentNode.component.context) this.component.context.set(name, value);
|
|
397
|
-
|
|
401
|
+
rootNode.replaceChildren(await renderToNode(this.component.scope, await this.component.setup()));
|
|
398
402
|
this.component.hooks.dispatch(MOUNTED_HOOK, this);
|
|
399
403
|
}
|
|
400
404
|
attributeChangedCallback(name, oldValue, value) {
|
|
@@ -454,7 +458,7 @@ const isServer = () => typeof window === "undefined";
|
|
|
454
458
|
const preventDefault = (event) => event.preventDefault();
|
|
455
459
|
const stopPropagation = (event) => event.stopPropagation();
|
|
456
460
|
const stopImmediatePropagation = (event) => event.stopImmediatePropagation();
|
|
457
|
-
const MOUNTED_HOOK = defineHook();
|
|
461
|
+
const MOUNTED_HOOK = defineHook("MOUNTED_HOOK");
|
|
458
462
|
const components = new Map();
|
|
459
463
|
|
|
460
464
|
//#endregion
|
|
@@ -740,7 +744,7 @@ const createRuntime = async () => {
|
|
|
740
744
|
}
|
|
741
745
|
};
|
|
742
746
|
};
|
|
743
|
-
const RUNTIME_CONTEXT = defineContext();
|
|
747
|
+
const RUNTIME_CONTEXT = defineContext("RUNTIME_CONTEXT");
|
|
744
748
|
|
|
745
749
|
//#endregion
|
|
746
750
|
//#region src/router/index.tsx
|
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(key) {
|
|
4
|
+
return key;
|
|
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("MOUNTED_HOOK");
|
|
18
18
|
|
|
19
19
|
//#endregion
|
|
20
20
|
//#region src/jsx/index.ts
|
package/dist/signals/index.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
declare const descriptor: unique symbol;
|
|
2
2
|
export type Value<T> = T | (() => Value<T>);
|
|
3
|
-
export type Descriptor<T> =
|
|
3
|
+
export type Descriptor<T> = string & {
|
|
4
4
|
[descriptor]: T;
|
|
5
5
|
};
|
|
6
6
|
export interface State<T> {
|
|
7
7
|
value: T;
|
|
8
8
|
}
|
|
9
9
|
export declare class Hooks {
|
|
10
|
-
readonly hooks: Map<
|
|
10
|
+
readonly hooks: Map<string, Set<(value: any) => unknown>>;
|
|
11
11
|
constructor();
|
|
12
|
-
on
|
|
13
|
-
dispatch
|
|
12
|
+
on<T>(scope: Scope, input: Descriptor<T>, invoke: (value: T) => unknown): number;
|
|
13
|
+
dispatch<T>(input: Descriptor<T>, value: T): void;
|
|
14
14
|
}
|
|
15
15
|
export declare class Scope {
|
|
16
16
|
readonly dispose: Array<(scope: Scope) => void>;
|
|
@@ -32,8 +32,8 @@ export declare function createState<T>(value: T): State<T>;
|
|
|
32
32
|
export declare function createCompute<T>(scope: Scope, invoke: (scope: Scope) => T): T;
|
|
33
33
|
export declare function createMemo<T>(scope: Scope, invoke: () => T): State<T>;
|
|
34
34
|
export declare function fromValue<T>(value: Value<T>): T;
|
|
35
|
-
export declare function defineHook<T>(): Descriptor<T>;
|
|
36
|
-
export declare function defineContext<T>(): Descriptor<T>;
|
|
35
|
+
export declare function defineHook<T>(key: string): Descriptor<T>;
|
|
36
|
+
export declare function defineContext<T>(key: string): 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
39
|
export {};
|