revojs 0.0.39 → 0.0.41
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 -6
- package/dist/index.js +10 -28
- package/package.json +1 -1
package/dist/html/index.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ export type AttributeOptions<T = unknown> = {
|
|
|
39
39
|
type: T;
|
|
40
40
|
default?: Infer<T>;
|
|
41
41
|
};
|
|
42
|
-
export type ShadowRootOptions =
|
|
42
|
+
export type ShadowRootOptions = ShadowRootInit & {
|
|
43
43
|
globalStyles?: boolean;
|
|
44
44
|
};
|
|
45
45
|
export type Events = Record<string, EventOptions>;
|
|
@@ -48,7 +48,7 @@ export interface ComponentOptions<TEvents extends Events, TAttributes extends At
|
|
|
48
48
|
name: string;
|
|
49
49
|
events?: TEvents;
|
|
50
50
|
attributes?: TAttributes;
|
|
51
|
-
shadowRoot?:
|
|
51
|
+
shadowRoot?: Partial<ShadowRootOptions>;
|
|
52
52
|
styles?: Array<string>;
|
|
53
53
|
setup: (component: Component<TEvents, TAttributes>) => Slot | Promise<Slot>;
|
|
54
54
|
}
|
|
@@ -56,7 +56,7 @@ export interface Component<TEvents extends Events, TAttributes extends Attribute
|
|
|
56
56
|
readonly scope: Scope;
|
|
57
57
|
readonly events: EventOutput<TEvents>;
|
|
58
58
|
readonly attributes: State<AttributeOutput<TAttributes>>;
|
|
59
|
-
readonly shadowRoot
|
|
59
|
+
readonly shadowRoot?: ShadowRootOptions;
|
|
60
60
|
setup: () => Slot | Promise<Slot>;
|
|
61
61
|
}
|
|
62
62
|
export interface ComponentConstructor<TEvents extends Events, TAttributes extends Attributes> {
|
|
@@ -79,9 +79,6 @@ export declare const isTemplate: (value?: any) => value is Template;
|
|
|
79
79
|
export declare const useHost: (scope: Scope) => HostContext;
|
|
80
80
|
export declare const createElement: <TEvents extends Events, TAttributes extends Attributes>(input: string | ComponentConstructor<TEvents, TAttributes>, attributes?: AttributeInput<TAttributes>, ...children: Array<Slot>) => Slot;
|
|
81
81
|
export declare const toString: (slot: Slot) => string;
|
|
82
|
-
export declare const isTextNode: (hydration?: Hydration) => hydration is Text;
|
|
83
|
-
export declare const isCommentNode: (hydration?: Hydration) => hydration is Comment;
|
|
84
|
-
export declare const isElementNode: (hydration?: Hydration, tagName?: string) => hydration is Element;
|
|
85
82
|
export declare const toArray: (hydration: Hydration) => Array<Node>;
|
|
86
83
|
export declare const toRange: (hydration: Hydration) => Range;
|
|
87
84
|
export declare const toFragment: (hydration: Hydration) => DocumentFragment;
|
package/dist/index.js
CHANGED
|
@@ -248,18 +248,6 @@ const toString = (slot) => {
|
|
|
248
248
|
default: return "";
|
|
249
249
|
}
|
|
250
250
|
};
|
|
251
|
-
const isTextNode = (hydration) => {
|
|
252
|
-
if (Array.isArray(hydration)) return false;
|
|
253
|
-
return hydration?.nodeType === Node.TEXT_NODE;
|
|
254
|
-
};
|
|
255
|
-
const isCommentNode = (hydration) => {
|
|
256
|
-
if (Array.isArray(hydration)) return false;
|
|
257
|
-
return hydration?.nodeType === Node.COMMENT_NODE;
|
|
258
|
-
};
|
|
259
|
-
const isElementNode = (hydration, tagName) => {
|
|
260
|
-
if (Array.isArray(hydration)) return false;
|
|
261
|
-
return hydration?.nodeType === Node.ELEMENT_NODE && hydration.nodeName.toUpperCase() === tagName?.toUpperCase();
|
|
262
|
-
};
|
|
263
251
|
const toArray = (hydration) => {
|
|
264
252
|
if (Array.isArray(hydration)) return hydration.reduce((items, child) => items.concat(toArray(child)), new Array());
|
|
265
253
|
else return [hydration];
|
|
@@ -283,9 +271,9 @@ const hydrate = async (scope, parentNode, slot, index, previous) => {
|
|
|
283
271
|
let hydration = parentNode.childNodes.item(index);
|
|
284
272
|
if (Array.isArray(slot)) {
|
|
285
273
|
const items = new Array();
|
|
286
|
-
for (const [index$1, childSlot] of slot.entries()) items.push(await hydrate(scope, parentNode, childSlot, index$1));
|
|
274
|
+
for (const [index$1, childSlot] of slot.entries()) items.push(await hydrate(scope, parentNode, childSlot, index$1, previous));
|
|
287
275
|
if (items.length) hydration = items;
|
|
288
|
-
else if (
|
|
276
|
+
else if (previous || !(hydration instanceof Comment)) hydration = document.createComment("");
|
|
289
277
|
}
|
|
290
278
|
if (typeof slot === "function") {
|
|
291
279
|
let previous$1;
|
|
@@ -306,20 +294,16 @@ const hydrate = async (scope, parentNode, slot, index, previous) => {
|
|
|
306
294
|
previous$1 = hydration;
|
|
307
295
|
});
|
|
308
296
|
}
|
|
309
|
-
if (slot === null || slot === void 0)
|
|
310
|
-
if (isCommentNode(hydration) === false) hydration = document.createComment("");
|
|
311
|
-
}
|
|
297
|
+
if ((slot === null || slot === void 0) && (previous || !(hydration instanceof Comment))) hydration = document.createComment("");
|
|
312
298
|
if (typeof slot === "number" || typeof slot === "bigint" || typeof slot === "boolean" || typeof slot === "string" || typeof slot === "symbol") {
|
|
313
299
|
const textContent = slot.toString();
|
|
314
|
-
if (
|
|
315
|
-
|
|
316
|
-
else if (textContent !== hydration.textContent) hydration = parentNode.replaceChild(document.createTextNode(textContent), hydration);
|
|
317
|
-
} else hydration = document.createTextNode(textContent);
|
|
300
|
+
if (previous || !(hydration instanceof Text)) hydration = document.createTextNode(textContent);
|
|
301
|
+
else if (textContent !== hydration.textContent) hydration = parentNode.replaceChild(document.createTextNode(textContent), hydration);
|
|
318
302
|
}
|
|
319
303
|
if (isTemplate(slot)) {
|
|
320
304
|
const Component = components.get(slot.tag);
|
|
321
305
|
if (Component) registerComponent(Component);
|
|
322
|
-
if (
|
|
306
|
+
if (previous || !(hydration instanceof Element && hydration.tagName.toUpperCase() === slot.tag.toUpperCase())) hydration = document.createElementNS(namespace(slot.tag), slot.tag);
|
|
323
307
|
for (const [name, value] of Object.entries(slot.attributes)) createCompute(scope, (childScope) => {
|
|
324
308
|
const target = hydration;
|
|
325
309
|
if (name.startsWith("on")) {
|
|
@@ -332,7 +316,7 @@ const hydrate = async (scope, parentNode, slot, index, previous) => {
|
|
|
332
316
|
}
|
|
333
317
|
scope.onStop(() => childScope.stop());
|
|
334
318
|
});
|
|
335
|
-
for (const [index$1, childSlot] of slot.children.entries()) await hydrate(scope, hydration, childSlot, index$1);
|
|
319
|
+
for (const [index$1, childSlot] of slot.children.entries()) await hydrate(scope, hydration, childSlot, index$1, previous);
|
|
336
320
|
}
|
|
337
321
|
hydration ??= document.createComment("");
|
|
338
322
|
if (parentNode.childNodes.item(index) === null) parentNode.appendChild(toFragment(hydration));
|
|
@@ -397,7 +381,7 @@ const defineComponent = (options) => {
|
|
|
397
381
|
Reflect.set(attributes.value, name, fromValue(input?.[name]) ?? attribute.default, attributes.value);
|
|
398
382
|
return attributes;
|
|
399
383
|
}, createState({}));
|
|
400
|
-
this.shadowRoot = options.shadowRoot
|
|
384
|
+
if (options.shadowRoot) this.shadowRoot = defu(options.shadowRoot, { mode: "open" });
|
|
401
385
|
}
|
|
402
386
|
setup = () => options.setup(this);
|
|
403
387
|
}
|
|
@@ -420,8 +404,7 @@ const toCustomElement = (Component) => {
|
|
|
420
404
|
const parentNode = findParent(this.parentNode);
|
|
421
405
|
if (parentNode) this.component.scope.parentScope = parentNode.component.scope;
|
|
422
406
|
if (this.component.shadowRoot) {
|
|
423
|
-
|
|
424
|
-
rootNode = this.shadowRoot ?? this.attachShadow(options);
|
|
407
|
+
rootNode = this.shadowRoot ?? this.attachShadow(this.component.shadowRoot);
|
|
425
408
|
if (this.component.shadowRoot.globalStyles) rootNode.adoptedStyleSheets = globalStyles;
|
|
426
409
|
}
|
|
427
410
|
for (const [name, event] of Object.entries(Component.$events)) Reflect.set(this.component.events, name, (value) => {
|
|
@@ -776,7 +759,6 @@ const useRouter = (scope, context) => {
|
|
|
776
759
|
};
|
|
777
760
|
const Page = defineComponent({
|
|
778
761
|
name: "x-page",
|
|
779
|
-
shadowRoot: false,
|
|
780
762
|
setup: ({ scope }) => {
|
|
781
763
|
const { route } = scope.getContext(ROUTER_CONTEXT);
|
|
782
764
|
return () => route.value;
|
|
@@ -925,4 +907,4 @@ const markdownToSlot = (input, options) => {
|
|
|
925
907
|
};
|
|
926
908
|
|
|
927
909
|
//#endregion
|
|
928
|
-
export { $fetch, Compute, HOST_CONTEXT, Handler, LOCALE_CONTEXT, MountedEvent, NavigateEvent, Page, ROUTER_CONTEXT, RUNTIME_CONTEXT, Radix, Scope, StopEvent, activeCompute, components, createApp, createCompute, createElement, createEvent, createLocale, createMemo, createRouter, createRuntime, createState, defineComponent, defineContext, defineRoute, fileName, fromValue, getAssets, getCookies, getCustomElement, getMimeType, getRequestUrl, getRoutes, getSetCookies, getVariables, globalStyles, hydrate, isClient,
|
|
910
|
+
export { $fetch, Compute, HOST_CONTEXT, Handler, LOCALE_CONTEXT, MountedEvent, NavigateEvent, Page, ROUTER_CONTEXT, RUNTIME_CONTEXT, Radix, Scope, StopEvent, activeCompute, components, createApp, createCompute, createElement, createEvent, createLocale, createMemo, createRouter, createRuntime, createState, defineComponent, defineContext, defineRoute, fileName, fromValue, getAssets, getCookies, getCustomElement, getMimeType, getRequestUrl, getRoutes, getSetCookies, getVariables, globalStyles, hydrate, isClient, isServer, isTemplate, markdownToSlot, preventDefault, registerComponent, renderToString, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, stopImmediatePropagation, stopPropagation, targets, toArray, toCustomElement, toFragment, toPath, toRange, toString, useEvent, useHost, useLocale, useRouter, useRuntime };
|