revojs 0.0.14 → 0.0.16
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 +7 -4
- package/dist/index.js +17 -17
- package/dist/jsx/index.d.ts +1 -1
- package/dist/jsx/index.js +2 -1
- package/dist/signals/index.d.ts +0 -3
- package/package.json +1 -1
package/dist/html/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type HtmlAttributes } from "../jsx";
|
|
2
|
-
import { Hooks, Scope, type State, type Value } from "../signals";
|
|
2
|
+
import { type Descriptor, Hooks, Scope, type State, type Value } from "../signals";
|
|
3
3
|
export type TypeOf<T> = {
|
|
4
4
|
(): T;
|
|
5
5
|
};
|
|
@@ -45,10 +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<string, unknown>;
|
|
48
49
|
readonly events: EventOutput<TEvents>;
|
|
49
50
|
readonly attributes: State<AttributeOutput<TAttributes>>;
|
|
50
51
|
readonly shadowRoot: false | ShadowRootInit;
|
|
51
52
|
readonly host?: CustomElement<TEvents, TAttributes>;
|
|
53
|
+
getContext: <T>(input: string | Descriptor<T>) => T;
|
|
54
|
+
setContext: <T>(input: string | Descriptor<T>, value: T) => void;
|
|
52
55
|
onMounted: (invoke: (input: HTMLElement) => void | Promise<void>) => void;
|
|
53
56
|
setup: () => Slot | Promise<Slot>;
|
|
54
57
|
}
|
|
@@ -56,7 +59,7 @@ export interface ComponentConstructor<TEvents extends Events, TAttributes extend
|
|
|
56
59
|
$name: string;
|
|
57
60
|
$events: TEvents;
|
|
58
61
|
$attributes: TAttributes;
|
|
59
|
-
new (input?: Input<TEvents, TAttributes>, host?: CustomElement<TEvents, TAttributes>): Component<TEvents, TAttributes>;
|
|
62
|
+
new (input?: Input<TEvents, TAttributes>, context?: Map<string, unknown>, host?: CustomElement<TEvents, TAttributes>): Component<TEvents, TAttributes>;
|
|
60
63
|
}
|
|
61
64
|
export interface CustomElement<TEvents extends Events, TAttributes extends Attributes> extends HTMLElement {
|
|
62
65
|
readonly component: Component<TEvents, TAttributes>;
|
|
@@ -65,7 +68,7 @@ export interface CustomElementConstructor<TEvents extends Events, TAttributes ex
|
|
|
65
68
|
new (): CustomElement<TEvents, TAttributes>;
|
|
66
69
|
}
|
|
67
70
|
export declare const isTemplate: (value: object) => value is Template;
|
|
68
|
-
export declare const createElement: <TEvents extends Events, TAttributes extends Attributes>(input: string | ComponentConstructor<TEvents, TAttributes>, attributes?: AttributeInput<TAttributes>, ...children: Array<Slot>) => Slot;
|
|
71
|
+
export declare const createElement: <TEvents extends Events, TAttributes extends Attributes>(input: string | Template | ComponentConstructor<TEvents, TAttributes>, attributes?: AttributeInput<TAttributes>, ...children: Array<Slot>) => Slot;
|
|
69
72
|
export declare const toString: (slot: Slot) => string;
|
|
70
73
|
export declare const toFragment: (nodes: Array<Node>) => DocumentFragment;
|
|
71
74
|
export declare const renderToString: (slot: Slot, context: Map<string, unknown>) => Promise<string>;
|
|
@@ -80,5 +83,5 @@ export declare const isServer: () => boolean;
|
|
|
80
83
|
export declare const preventDefault: (event: Event) => void;
|
|
81
84
|
export declare const stopPropagation: (event: Event) => void;
|
|
82
85
|
export declare const stopImmediatePropagation: (event: Event) => void;
|
|
83
|
-
export declare const MOUNTED_HOOK:
|
|
86
|
+
export declare const MOUNTED_HOOK: Descriptor<HTMLElement>;
|
|
84
87
|
export declare const components: Map<string, ComponentConstructor<Events, Attributes>>;
|
package/dist/index.js
CHANGED
|
@@ -125,10 +125,8 @@ var Hooks = class {
|
|
|
125
125
|
};
|
|
126
126
|
};
|
|
127
127
|
var Scope = class {
|
|
128
|
-
context;
|
|
129
128
|
dispose;
|
|
130
129
|
constructor() {
|
|
131
|
-
this.context = new Map();
|
|
132
130
|
this.dispose = new Array();
|
|
133
131
|
}
|
|
134
132
|
stop() {
|
|
@@ -209,12 +207,6 @@ function defineHook(description) {
|
|
|
209
207
|
function defineContext(description) {
|
|
210
208
|
return { key: Symbol(description) };
|
|
211
209
|
}
|
|
212
|
-
function getContext(scope, input) {
|
|
213
|
-
return scope.context.get(descriptor(input)) ?? {};
|
|
214
|
-
}
|
|
215
|
-
function setContext(scope, input, value) {
|
|
216
|
-
scope.context.set(descriptor(input), value);
|
|
217
|
-
}
|
|
218
210
|
let activeCompute;
|
|
219
211
|
const targets = new WeakMap();
|
|
220
212
|
|
|
@@ -224,7 +216,8 @@ const isTemplate = (value) => {
|
|
|
224
216
|
return "tag" in value && "attributes" in value && "children" in value;
|
|
225
217
|
};
|
|
226
218
|
const createElement = (input, attributes, ...children) => {
|
|
227
|
-
return
|
|
219
|
+
if (typeof input === "object") return input;
|
|
220
|
+
else return {
|
|
228
221
|
tag: typeof input === "function" ? input.$name : input,
|
|
229
222
|
attributes: attributes ?? {},
|
|
230
223
|
children
|
|
@@ -261,8 +254,7 @@ const renderToString = async (slot, context) => {
|
|
|
261
254
|
}, [slot.tag]).join(" ");
|
|
262
255
|
const children = await renderToString(slot.children, context);
|
|
263
256
|
if (customElement) {
|
|
264
|
-
const element = new customElement(slot.attributes);
|
|
265
|
-
for (const [input, value] of context) setContext(element.scope, input, value);
|
|
257
|
+
const element = new customElement(slot.attributes, context);
|
|
266
258
|
const template = await renderToString(await element.setup(), context);
|
|
267
259
|
if (element.shadowRoot) {
|
|
268
260
|
const shadow = await renderToString({
|
|
@@ -355,13 +347,15 @@ const defineComponent = (options) => {
|
|
|
355
347
|
static $attributes = options.attributes ?? {};
|
|
356
348
|
scope;
|
|
357
349
|
hooks;
|
|
350
|
+
context;
|
|
358
351
|
events;
|
|
359
352
|
attributes;
|
|
360
353
|
shadowRoot;
|
|
361
354
|
host;
|
|
362
|
-
constructor(input, host) {
|
|
355
|
+
constructor(input, context, host) {
|
|
363
356
|
this.scope = new Scope();
|
|
364
357
|
this.hooks = new Hooks();
|
|
358
|
+
this.context = context ?? new Map();
|
|
365
359
|
this.events = Object.keys(options.events ?? {}).reduce((output, name) => {
|
|
366
360
|
Reflect.set(output, name, input?.[name], output);
|
|
367
361
|
return output;
|
|
@@ -373,6 +367,12 @@ const defineComponent = (options) => {
|
|
|
373
367
|
this.shadowRoot = options.shadowRoot ?? { mode: "open" };
|
|
374
368
|
this.host = host;
|
|
375
369
|
}
|
|
370
|
+
getContext = (input) => {
|
|
371
|
+
return this.context.get(descriptor(input)) ?? {};
|
|
372
|
+
};
|
|
373
|
+
setContext = (input, value) => {
|
|
374
|
+
this.context.set(descriptor(input), value);
|
|
375
|
+
};
|
|
376
376
|
onMounted = (invoke) => {
|
|
377
377
|
return this.hooks.on(this.scope, MOUNTED_HOOK, invoke);
|
|
378
378
|
};
|
|
@@ -385,7 +385,7 @@ const toCustomElement = (component) => {
|
|
|
385
385
|
component;
|
|
386
386
|
constructor() {
|
|
387
387
|
super();
|
|
388
|
-
this.component = new component(void 0, this);
|
|
388
|
+
this.component = new component(void 0, void 0, this);
|
|
389
389
|
}
|
|
390
390
|
async connectedCallback() {
|
|
391
391
|
const shadow = this.component.shadowRoot ? this.attachShadow(this.component.shadowRoot) : this;
|
|
@@ -397,7 +397,7 @@ const toCustomElement = (component) => {
|
|
|
397
397
|
detail: value
|
|
398
398
|
}));
|
|
399
399
|
}, this.component.events);
|
|
400
|
-
if (parentNode) for (const [name, value] of parentNode.component.
|
|
400
|
+
if (parentNode) for (const [name, value] of parentNode.component.context) this.component.context.set(name, value);
|
|
401
401
|
shadow.replaceChildren(await renderToNode(this.component.scope, await this.component.setup()));
|
|
402
402
|
this.component.hooks.dispatch(MOUNTED_HOOK, this);
|
|
403
403
|
}
|
|
@@ -753,8 +753,8 @@ const RUNTIME_CONTEXT = defineContext("RUNTIME_CONTEXT");
|
|
|
753
753
|
const Outlet = defineComponent({
|
|
754
754
|
name: "x-outlet",
|
|
755
755
|
shadowRoot: false,
|
|
756
|
-
setup: async ({ scope }) => {
|
|
757
|
-
const { event } = getContext(
|
|
756
|
+
setup: async ({ scope, getContext }) => {
|
|
757
|
+
const { event } = getContext(RUNTIME_CONTEXT);
|
|
758
758
|
const radix = new Radix();
|
|
759
759
|
const routes = await getRoutes();
|
|
760
760
|
for (const path in routes) {
|
|
@@ -787,4 +787,4 @@ const anchorNavigate = (event) => {
|
|
|
787
787
|
};
|
|
788
788
|
|
|
789
789
|
//#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, descriptor, fileName, fromValue, getAssets,
|
|
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, descriptor, 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.d.ts
CHANGED
|
@@ -364,4 +364,4 @@ export declare namespace JSX {
|
|
|
364
364
|
}
|
|
365
365
|
export declare const svgElements: Set<string>;
|
|
366
366
|
export declare const namespace: (tag: string) => "http://www.w3.org/1999/xhtml" | "http://www.w3.org/2000/svg";
|
|
367
|
-
export declare const h: <TEvents extends import("..").Events, TAttributes extends import("..").Attributes>(input: string | import("..").ComponentConstructor<TEvents, TAttributes>, attributes?: import("..").AttributeInput<TAttributes>, ...children: Array<Slot>) => Slot;
|
|
367
|
+
export declare const h: <TEvents extends import("..").Events, TAttributes extends import("..").Attributes>(input: string | import("..").Template | import("..").ComponentConstructor<TEvents, TAttributes>, attributes?: import("..").AttributeInput<TAttributes>, ...children: Array<Slot>) => Slot;
|
package/dist/jsx/index.js
CHANGED
|
@@ -7,7 +7,8 @@ function defineHook(description) {
|
|
|
7
7
|
//#endregion
|
|
8
8
|
//#region src/html/index.ts
|
|
9
9
|
const createElement = (input, attributes, ...children) => {
|
|
10
|
-
return
|
|
10
|
+
if (typeof input === "object") return input;
|
|
11
|
+
else return {
|
|
11
12
|
tag: typeof input === "function" ? input.$name : input,
|
|
12
13
|
attributes: attributes ?? {},
|
|
13
14
|
children
|
package/dist/signals/index.d.ts
CHANGED
|
@@ -12,7 +12,6 @@ export declare class Hooks {
|
|
|
12
12
|
dispatch: <T>(input: string | Descriptor<T>, value: T) => void;
|
|
13
13
|
}
|
|
14
14
|
export declare class Scope {
|
|
15
|
-
readonly context: Map<string, unknown>;
|
|
16
15
|
readonly dispose: Array<(scope: Scope) => void>;
|
|
17
16
|
constructor();
|
|
18
17
|
stop(): void;
|
|
@@ -35,7 +34,5 @@ export declare function fromValue<T>(value: Value<T>): T;
|
|
|
35
34
|
export declare function descriptor<T>(descriptor: string | Descriptor<T>): string;
|
|
36
35
|
export declare function defineHook<T>(description?: string | number): Descriptor<T>;
|
|
37
36
|
export declare function defineContext<T>(description?: string | number): Descriptor<T>;
|
|
38
|
-
export declare function getContext<T>(scope: Scope, input: string | Descriptor<T>): T;
|
|
39
|
-
export declare function setContext<T>(scope: Scope, input: string | Descriptor<T>, value: T): void;
|
|
40
37
|
export declare let activeCompute: Compute | undefined;
|
|
41
38
|
export declare const targets: WeakMap<object, Map<string | symbol, Set<Compute<void>>>>;
|