creo 0.1.0 → 0.2.1
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/LICENSE +21 -0
- package/README.md +349 -4
- package/dist/functional/lis.d.ts +11 -0
- package/dist/functional/maybe.d.ts +2 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +912 -905
- package/dist/index.js.map +16 -17
- package/dist/internal/engine.d.ts +14 -8
- package/dist/internal/internal_view.d.ts +23 -32
- package/dist/internal/orchestrator.d.ts +1 -1
- package/dist/public/primitives/primitives.d.ts +3 -2
- package/dist/public/view.d.ts +12 -9
- package/dist/render/html_render.d.ts +9 -22
- package/dist/render/json_render.d.ts +6 -4
- package/dist/render/render_interface.d.ts +6 -4
- package/dist/render/string_render.d.ts +14 -9
- package/package.json +3 -3
|
@@ -1,38 +1,29 @@
|
|
|
1
1
|
import type { Key } from "../functional/key";
|
|
2
|
-
import type {
|
|
3
|
-
import type { Engine } from "./engine";
|
|
4
|
-
import { IndexedList } from "../structures/indexed_list";
|
|
2
|
+
import type { SlotContent, ViewBody, ViewFn } from "../public/view";
|
|
5
3
|
import type { Maybe } from "../functional/maybe";
|
|
6
4
|
import type { Wildcard } from "./wildcard";
|
|
7
|
-
export type
|
|
5
|
+
export type BitFlags = number;
|
|
6
|
+
export declare const F_PENDING = 1;
|
|
7
|
+
export declare const F_DIRTY: number;
|
|
8
|
+
export declare const F_MOVED: number;
|
|
9
|
+
export declare const F_PRIMITIVE: number;
|
|
10
|
+
export declare const F_TEXT_CONTENT: number;
|
|
11
|
+
export declare const F_DISPOSED: number;
|
|
12
|
+
export type ViewRecord<Props = Wildcard, Api = Wildcard, RenderRef = Wildcard> = {
|
|
8
13
|
viewFn: ViewFn<Props, Api>;
|
|
9
|
-
props: Props;
|
|
10
|
-
slot: Maybe<Slot>;
|
|
11
14
|
userKey: Maybe<Key>;
|
|
12
|
-
};
|
|
13
|
-
export declare class View<Props = Wildcard, Api = Wildcard> implements Disposable {
|
|
14
|
-
#private;
|
|
15
|
-
viewFn: ViewFn<Props, Api>;
|
|
16
|
-
engine: Engine;
|
|
17
|
-
parent: Maybe<View>;
|
|
18
|
-
userKey: Maybe<Key>;
|
|
19
|
-
renderRef: unknown;
|
|
20
15
|
props: Props;
|
|
21
|
-
|
|
22
|
-
body: ViewBody<Props, Api
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
nextProps(nextProps: Props, nextSlot: Maybe<Slot>): void;
|
|
36
|
-
reconsile(): void;
|
|
37
|
-
[Symbol.dispose](): void;
|
|
38
|
-
}
|
|
16
|
+
slot: Maybe<SlotContent>;
|
|
17
|
+
body: Maybe<ViewBody<Props, Api>>;
|
|
18
|
+
sc: Maybe<ViewRecord[]>;
|
|
19
|
+
renderRef: Maybe<RenderRef>;
|
|
20
|
+
flags: BitFlags;
|
|
21
|
+
children: Maybe<ViewRecord[]>;
|
|
22
|
+
keyToView: Maybe<Map<Key, ViewRecord>>;
|
|
23
|
+
unsubscribe: Maybe<(() => void)[]>;
|
|
24
|
+
parent: Maybe<ViewRecord>;
|
|
25
|
+
/** The primitive whose .children contains the live sc items after reconcile. */
|
|
26
|
+
scHost: Maybe<ViewRecord>;
|
|
27
|
+
};
|
|
28
|
+
/** Structural change: viewFn, key, or count differs. Does NOT check props. */
|
|
29
|
+
export declare function hasScStructuralChange(prev: Maybe<ViewRecord[]>, next: Maybe<ViewRecord[]>): boolean;
|
|
@@ -9,7 +9,7 @@ import type { Engine } from "../internal/engine";
|
|
|
9
9
|
*/
|
|
10
10
|
declare class Orchestrator {
|
|
11
11
|
#private;
|
|
12
|
-
setCurrentEngine(engine: Engine): void;
|
|
12
|
+
setCurrentEngine(engine: Maybe<Engine>): void;
|
|
13
13
|
currentEngine(): Maybe<Engine>;
|
|
14
14
|
}
|
|
15
15
|
export declare const orchestrator: Orchestrator;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type EventHandlerProps } from "../primitive";
|
|
2
|
-
import { type PublicView } from "../view";
|
|
2
|
+
import { type PublicView, type ViewFn } from "../view";
|
|
3
3
|
export type BaseEventData = {
|
|
4
4
|
stopPropagation: () => void;
|
|
5
5
|
preventDefault: () => void;
|
|
@@ -45,7 +45,8 @@ export type HtmlAttrs = {
|
|
|
45
45
|
[attr: string]: unknown;
|
|
46
46
|
};
|
|
47
47
|
export declare function html<Attrs extends HtmlAttrs = HtmlAttrs, Events = ContainerEvents>(tag: string): PublicView<Attrs & EventHandlerProps<Events>, void>;
|
|
48
|
-
export declare const
|
|
48
|
+
export declare const textViewFn: ViewFn<string | number, void>;
|
|
49
|
+
export declare function text(content: string | number): void;
|
|
49
50
|
export declare const div: PublicView<HtmlAttrs & EventHandlerProps<ContainerEvents>, void>;
|
|
50
51
|
export declare const span: PublicView<HtmlAttrs & EventHandlerProps<ContainerEvents>, void>;
|
|
51
52
|
export declare const section: PublicView<HtmlAttrs & EventHandlerProps<ContainerEvents>, void>;
|
package/dist/public/view.d.ts
CHANGED
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
import type { Key } from "../functional/key";
|
|
2
|
-
import type { Maybe } from "../functional/maybe";
|
|
3
2
|
import type { Use } from "./state";
|
|
4
|
-
import type { PendingView } from "../internal/internal_view";
|
|
5
3
|
import type { $primitive } from "./primitive";
|
|
6
4
|
export type ViewBody<Props, Api> = Api extends void ? {
|
|
7
5
|
render: () => void;
|
|
8
6
|
onMount?: () => void;
|
|
9
7
|
shouldUpdate?: (nextProps: Props) => boolean;
|
|
10
8
|
onUpdateBefore?: () => void;
|
|
11
|
-
|
|
9
|
+
onUpdateAfter?: () => void;
|
|
12
10
|
} : {
|
|
13
11
|
render: () => void;
|
|
14
12
|
onMount?: () => void;
|
|
15
13
|
shouldUpdate?: (nextProps: Props) => boolean;
|
|
16
14
|
onUpdateBefore?: () => void;
|
|
17
|
-
|
|
15
|
+
onUpdateAfter?: () => void;
|
|
18
16
|
api: Api;
|
|
19
17
|
};
|
|
20
18
|
/** Slot callback — passed by the caller at the call site. */
|
|
21
19
|
export type Slot = () => void;
|
|
22
|
-
/**
|
|
23
|
-
export type
|
|
20
|
+
/** What callers may pass as a slot: a callback or a plain string (rendered as text). */
|
|
21
|
+
export type SlotContent = Slot | string;
|
|
24
22
|
export type ViewFn<Props, Api> = {
|
|
25
23
|
(ctx: {
|
|
26
24
|
props: () => Props;
|
|
@@ -29,9 +27,14 @@ export type ViewFn<Props, Api> = {
|
|
|
29
27
|
}): ViewBody<Props, Api>;
|
|
30
28
|
[$primitive]?: string;
|
|
31
29
|
};
|
|
32
|
-
|
|
30
|
+
/** Resolves to the caller-facing props type. Allows `void` when Props is void or all-optional. */
|
|
31
|
+
type ViewProps<Props> = Props extends void ? {
|
|
33
32
|
key?: Key;
|
|
34
|
-
} | void : Props & {
|
|
33
|
+
} | void : {} extends Props ? (Props & {
|
|
35
34
|
key?: Key;
|
|
36
|
-
}
|
|
35
|
+
}) | void : Props & {
|
|
36
|
+
key?: Key;
|
|
37
|
+
};
|
|
38
|
+
export declare function view<Props = void, Api = void>(body: ViewFn<Props, Api>): (props: ViewProps<Props>, slot?: SlotContent) => void;
|
|
37
39
|
export type PublicView<Props, Api> = ReturnType<typeof view<Props, Api>>;
|
|
40
|
+
export {};
|
|
@@ -1,35 +1,22 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ViewRecord } from "../internal/internal_view";
|
|
2
2
|
import type { IRender } from "./render_interface";
|
|
3
|
+
import type { Engine } from "../internal/engine";
|
|
3
4
|
export declare class HtmlRender implements IRender<HTMLElement | Text> {
|
|
5
|
+
#private;
|
|
4
6
|
private container;
|
|
7
|
+
engine: Engine;
|
|
5
8
|
constructor(container: HTMLElement);
|
|
6
|
-
render(view:
|
|
7
|
-
unmount(view:
|
|
8
|
-
private
|
|
9
|
-
private
|
|
10
|
-
private eventPropToCreoName;
|
|
9
|
+
render(view: ViewRecord): void;
|
|
10
|
+
unmount(view: ViewRecord): void;
|
|
11
|
+
private findParentDom;
|
|
12
|
+
private findInsertionPoint;
|
|
11
13
|
private setAttributes;
|
|
12
14
|
private diffAttributes;
|
|
13
15
|
private bindEvent;
|
|
14
16
|
private unbindEvent;
|
|
15
|
-
private mapEventData;
|
|
16
17
|
private setAttribute;
|
|
17
18
|
private removeAttribute;
|
|
18
|
-
/**
|
|
19
|
-
* Compute where a view's DOM node should be placed in its parent.
|
|
20
|
-
*
|
|
21
|
-
* Fast paths (O(1)):
|
|
22
|
-
* - Last child → endComment (composite) or null/appendChild (primitive)
|
|
23
|
-
* - Previous sibling rendered → nextSibling of prev's last DOM node
|
|
24
|
-
*
|
|
25
|
-
* Slow path (O(k)): walk backward through unrendered siblings.
|
|
26
|
-
*
|
|
27
|
-
* Composite parents always return endComment as fallback (never null),
|
|
28
|
-
* so insertBefore(node, result) is safe for all parent types.
|
|
29
|
-
*/
|
|
30
|
-
private fastInsertionPoint;
|
|
31
|
-
private getParentDomNode;
|
|
32
|
-
private moveDomNodes;
|
|
33
19
|
private getFirstDomNode;
|
|
20
|
+
private moveDomNodes;
|
|
34
21
|
private removeDomNodes;
|
|
35
22
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ViewRecord } from "../internal/internal_view";
|
|
2
2
|
import type { IRender } from "./render_interface";
|
|
3
3
|
import type { Maybe } from "../functional/maybe";
|
|
4
|
+
import type { Engine } from "../internal/engine";
|
|
4
5
|
export type JsonNode = {
|
|
5
6
|
type: string;
|
|
6
7
|
props: Record<string, unknown>;
|
|
@@ -10,8 +11,9 @@ export type JsonNode = {
|
|
|
10
11
|
export declare class JsonRender implements IRender<JsonNode> {
|
|
11
12
|
/** The root JSON node after mount. */
|
|
12
13
|
root: Maybe<JsonNode>;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
engine: Engine;
|
|
15
|
+
constructor();
|
|
16
|
+
render(view: ViewRecord): void;
|
|
17
|
+
unmount(view: ViewRecord): void;
|
|
16
18
|
private buildNode;
|
|
17
19
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ViewRecord } from "../internal/internal_view";
|
|
2
|
+
import type { Engine } from "../internal/engine";
|
|
2
3
|
export interface IRender<Output> {
|
|
4
|
+
engine: Engine;
|
|
3
5
|
/** Create output if view is new (no renderRef), or update if existing. */
|
|
4
|
-
render(view:
|
|
5
|
-
/** Remove a view's output artifacts.
|
|
6
|
-
unmount(view:
|
|
6
|
+
render(view: ViewRecord): void;
|
|
7
|
+
/** Remove a view's output artifacts. */
|
|
8
|
+
unmount(view: ViewRecord): void;
|
|
7
9
|
}
|
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ViewRecord } from "../internal/internal_view";
|
|
2
2
|
import type { IRender } from "./render_interface";
|
|
3
|
+
import type { Engine } from "../internal/engine";
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
5
|
+
* HtmlStringRender — pull-based string renderer.
|
|
6
|
+
* render/unmount are no-ops. Call renderToString() to
|
|
6
7
|
* get the current HTML string from the VDOM.
|
|
8
|
+
*
|
|
9
|
+
* Output matches HtmlRender's DOM serialization (innerHTML).
|
|
7
10
|
*/
|
|
8
|
-
export declare class
|
|
9
|
-
private
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
export declare class HtmlStringRender implements IRender<string> {
|
|
12
|
+
private root;
|
|
13
|
+
engine: Engine;
|
|
14
|
+
render(view: ViewRecord): void;
|
|
15
|
+
unmount(_view: ViewRecord): void;
|
|
13
16
|
renderToString(): string;
|
|
14
17
|
private buildString;
|
|
15
|
-
private
|
|
18
|
+
private buildAttrs;
|
|
16
19
|
private buildChildren;
|
|
17
20
|
}
|
|
21
|
+
/** @deprecated Use HtmlStringRender instead */
|
|
22
|
+
export declare const StringRender: typeof HtmlStringRender;
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "creo",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"files": [
|