@usenagi/core 0.2.0 → 0.4.0
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/README.ja.md +78 -50
- package/README.md +73 -45
- package/dist/addons/scheduler.cjs.js +1 -1
- package/dist/addons/scheduler.es.js +77 -19
- package/dist/main.es.js +152 -160
- package/dist/main.umd.js +1 -1
- package/package.json +4 -4
- package/types/addons/scheduler/_internal/pending.d.ts +11 -0
- package/types/addons/scheduler/_internal/schedule.d.ts +11 -0
- package/types/addons/scheduler/index.d.ts +9 -3
- package/types/core/_internal/addonRegistry.d.ts +10 -0
- package/types/core/_internal/component.d.ts +24 -0
- package/types/core/_internal/registry.d.ts +5 -0
- package/types/core/addon.d.ts +28 -0
- package/types/core/app.d.ts +6 -24
- package/types/core/component.d.ts +14 -27
- package/types/core/error.d.ts +2 -3
- package/types/core/props.d.ts +2 -0
- package/types/core/runtime.d.ts +4 -3
- package/types/hooks/{useDomRef.d.ts → core/useDomRef.d.ts} +1 -1
- package/types/hooks/core/useSlot.d.ts +5 -0
- package/types/main.d.ts +8 -6
- package/types/types.d.ts +11 -9
- package/types/addons/scheduler/task.d.ts +0 -2
- package/types/core/internal/pending.d.ts +0 -11
- package/types/core/internal/registry.d.ts +0 -4
- package/types/hooks/domRefs.d.ts +0 -2
- package/types/hooks/useSlot.d.ts +0 -6
- package/types/utils/isAbortError.d.ts +0 -1
- /package/types/{hooks/createContext.d.ts → core/context.d.ts} +0 -0
|
@@ -1,28 +1,15 @@
|
|
|
1
|
-
import type { ComponentSetup, RefElement } from "../types";
|
|
2
|
-
export declare
|
|
3
|
-
MOUNTED = "Mounted",
|
|
4
|
-
UNMOUNTED = "Unmounted"
|
|
5
|
-
}
|
|
6
|
-
export declare class ComponentContext<T = any> {
|
|
7
|
-
#private;
|
|
8
|
-
private [LifecycleHooks.MOUNTED];
|
|
9
|
-
private [LifecycleHooks.UNMOUNTED];
|
|
10
|
-
parent: ComponentContext<T> | null;
|
|
11
|
-
readonly uid: string;
|
|
12
|
-
readonly name: string;
|
|
13
|
-
current: ReturnType<ComponentSetup<T>["setup"]>;
|
|
14
|
-
props: Parameters<ComponentSetup<T>["setup"]>[1];
|
|
15
|
-
element: RefElement;
|
|
16
|
-
provides: Map<symbol, unknown>;
|
|
17
|
-
constructor(element: RefElement, name: string);
|
|
18
|
-
onMount: () => void;
|
|
19
|
-
onUnmount: () => void;
|
|
20
|
-
addChild: (child: ComponentContext) => void;
|
|
21
|
-
removeChild: (child: ComponentContext) => void;
|
|
22
|
-
get childElements(): RefElement[];
|
|
23
|
-
}
|
|
24
|
-
export declare function defineComponent<Context extends Record<string, unknown>>(): <SetupResult extends Record<string, unknown> | void>(opts: {
|
|
1
|
+
import type { ComponentProps, ComponentSetup, RefElement } from "../types";
|
|
2
|
+
export declare function defineComponent<SetupResult extends Record<string, unknown> | void, Props extends Record<string, unknown>>(opts: {
|
|
25
3
|
name: string;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
4
|
+
props: Props;
|
|
5
|
+
setup(el: RefElement, props: ComponentProps<Props>): SetupResult;
|
|
6
|
+
}): ComponentSetup<SetupResult, Props>;
|
|
7
|
+
export declare function defineComponent<SetupResult extends Record<string, unknown> | void, Props extends Record<string, unknown>>(opts: {
|
|
8
|
+
name: string;
|
|
9
|
+
setup(el: RefElement, props: ComponentProps<Props>): SetupResult;
|
|
10
|
+
}): ComponentSetup<SetupResult, Props>;
|
|
11
|
+
export declare function defineComponent<SetupResult extends Record<string, unknown> | void>(opts: {
|
|
12
|
+
name: string;
|
|
13
|
+
setup(el: RefElement): SetupResult;
|
|
14
|
+
}): ComponentSetup<SetupResult, Record<string, never>>;
|
|
15
|
+
export declare function defineComponent(opts: ComponentSetup): ComponentSetup;
|
package/types/core/error.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RefElement } from "../types";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ComponentContextImpl } from "./_internal/component";
|
|
3
3
|
export type LifecycleErrorDetails = {
|
|
4
4
|
phase: "setup" | "mount" | "unmount" | "removeChild";
|
|
5
5
|
name: string;
|
|
@@ -11,10 +11,9 @@ export type LifecycleErrorDetails = {
|
|
|
11
11
|
props?: unknown;
|
|
12
12
|
cause: unknown;
|
|
13
13
|
};
|
|
14
|
-
export declare function traceComponentTree(context: ComponentContext): string;
|
|
15
14
|
export declare class LifecycleError extends Error {
|
|
16
15
|
readonly details: LifecycleErrorDetails;
|
|
17
16
|
constructor(details: LifecycleErrorDetails);
|
|
18
|
-
static create(phase: LifecycleErrorDetails["phase"], target:
|
|
17
|
+
static create(phase: LifecycleErrorDetails["phase"], target: ComponentContextImpl, cause: unknown, parent?: ComponentContextImpl | null | undefined, extra?: Partial<LifecycleErrorDetails>): LifecycleError;
|
|
19
18
|
}
|
|
20
19
|
export declare function isLifecycleError(error: unknown): error is LifecycleError;
|
package/types/core/runtime.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ComponentContextImpl } from "./_internal/component";
|
|
2
2
|
import type { ComponentSetup, RefElement } from "../types";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
declare function getCurrentComponent(hookName: string): ComponentContextImpl;
|
|
4
|
+
declare function createComponent<S extends ComponentSetup>(wrap: S, root: RefElement, props?: Record<string, any>): ComponentContextImpl<ReturnType<S["setup"]>>;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ComponentContext, ComponentSetup, ExposedSetup, RefElement } from "../../types";
|
|
2
|
+
export declare function useSlot(): {
|
|
3
|
+
addChild<Child extends ComponentSetup>(targetOrTargets: RefElement | RefElement[], child: Child, props?: Partial<Parameters<Child["setup"]>[1]>): ComponentContext<ExposedSetup<ReturnType<Child["setup"]>>>[];
|
|
4
|
+
removeChild(children: ComponentContext[]): void;
|
|
5
|
+
};
|
package/types/main.d.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
+
export { defineAddon } from "./core/addon";
|
|
1
2
|
export { create } from "./core/app";
|
|
2
3
|
export { defineComponent } from "./core/component";
|
|
4
|
+
export { createContext, withContext } from "./core/context";
|
|
3
5
|
export { isLifecycleError, LifecycleError } from "./core/error";
|
|
4
6
|
export { useMount, useUnmount } from "./core/lifecycle";
|
|
7
|
+
export { propTypes } from "./core/props";
|
|
5
8
|
export { readonly, signal, useComputed, useWatch } from "./core/reactivity";
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
9
|
+
export { useDomRef } from "./hooks/core/useDomRef";
|
|
10
|
+
export { useSlot } from "./hooks/core/useSlot";
|
|
8
11
|
export { useEvent } from "./hooks/useEvent";
|
|
9
12
|
export { useIntersectionWatch } from "./hooks/useIntersectionWatch";
|
|
10
13
|
export { useMediaQuery } from "./hooks/useMediaQuery";
|
|
11
|
-
export {
|
|
12
|
-
export type {
|
|
14
|
+
export type { Addon, AddonContext, MountOptions } from "./core/addon";
|
|
15
|
+
export type { Provider } from "./core/context";
|
|
13
16
|
export type { LifecycleErrorDetails } from "./core/error";
|
|
14
17
|
export type { ReadonlySignal, Signal } from "./core/reactivity";
|
|
15
|
-
export type {
|
|
16
|
-
export type { ComponentSetup, Cue, IComponent, RefElement, SchedulePriority, Scheduler, } from "./types";
|
|
18
|
+
export type { Cleanup, ComponentContext, ComponentSetup, Cue, RefElement, SchedulePriority, } from "./types";
|
package/types/types.d.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
export type RefElement = HTMLElement | SVGElement;
|
|
2
2
|
export type ComponentProps<Props> = Readonly<Props>;
|
|
3
|
-
|
|
3
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
4
|
+
/** Normalize the return value of setup to the type stored in `current` (void / undefined → empty object). */
|
|
5
|
+
export type ExposedSetup<T> = IsAny<T> extends true ? Record<string, unknown> : [T] extends [void | undefined] ? Record<string, never> : T extends Record<string, unknown> ? T : Record<string, never>;
|
|
6
|
+
export type ComponentSetup<SetupResult = void | Record<string, unknown>, Props extends Record<string, unknown> = Record<string, unknown>> = {
|
|
4
7
|
name: string;
|
|
5
8
|
setup(el: RefElement, props: ComponentProps<Props>): SetupResult;
|
|
6
9
|
};
|
|
7
|
-
/**
|
|
8
|
-
export type
|
|
10
|
+
/** Mounted component instance exposed to app / hook callers. */
|
|
11
|
+
export type ComponentContext<Exposed extends Record<string, unknown> = Record<string, never>> = {
|
|
12
|
+
readonly current: Exposed;
|
|
13
|
+
readonly element: RefElement;
|
|
14
|
+
readonly name: string;
|
|
15
|
+
};
|
|
9
16
|
export type Cleanup = () => void;
|
|
10
17
|
export type LifecycleHandler = () => void | Cleanup;
|
|
11
18
|
export type SchedulePriority = "user-blocking" | "user-visible" | "background";
|
|
12
|
-
export type Scheduler = {
|
|
13
|
-
schedule(task: () => void, options?: {
|
|
14
|
-
priority?: SchedulePriority;
|
|
15
|
-
signal?: AbortSignal;
|
|
16
|
-
}): void;
|
|
17
|
-
};
|
|
18
19
|
export type Cue = (el: RefElement, signal: AbortSignal) => Promise<void>;
|
|
20
|
+
export {};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { RefElement } from "../../types";
|
|
2
|
-
export type PendingMountTask = {
|
|
3
|
-
readonly signal: AbortSignal;
|
|
4
|
-
complete(): boolean;
|
|
5
|
-
abort(): void;
|
|
6
|
-
};
|
|
7
|
-
export type PendingMountTasks = {
|
|
8
|
-
add(el: RefElement): PendingMountTask;
|
|
9
|
-
abort(el: RefElement): void;
|
|
10
|
-
};
|
|
11
|
-
export declare function createPendingMountTasks(): PendingMountTasks;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { RefElement } from "../../types";
|
|
2
|
-
import type { ComponentContext } from "../component";
|
|
3
|
-
export declare const DOM_COMPONENT_INSTANCE: WeakMap<RefElement, ComponentContext<any>>;
|
|
4
|
-
export declare function bindDOMNodeToComponent(el: RefElement, component: ComponentContext): void;
|
package/types/hooks/domRefs.d.ts
DELETED
package/types/hooks/useSlot.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { ComponentContext } from "../core/component";
|
|
2
|
-
import type { ComponentSetup, RefElement } from "../types";
|
|
3
|
-
export declare function useSlot(): {
|
|
4
|
-
addChild<Child extends ComponentSetup>(targetOrTargets: RefElement | RefElement[], child: Child, props?: Parameters<Child["setup"]>[1]): ComponentContext<ReturnType<Child["setup"]>>[];
|
|
5
|
-
removeChild(children: ComponentContext[]): void;
|
|
6
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isAbortError(error: unknown): boolean;
|
|
File without changes
|