UNPKG

3.37 kBTypeScriptView Raw
1import {
2 SimpleElement,
3 SimpleNode,
4 SimpleText,
5 SimpleComment,
6 SimpleDocumentFragment,
7 AttrNamespace,
8} from '@simple-dom/interface';
9import { Option, Maybe } from '../core';
10import { Bounds, Cursor } from './bounds';
11import { ElementOperations, Environment, ModifierInstance } from '../runtime';
12import { GlimmerTreeConstruction, GlimmerTreeChanges } from './changes';
13import { Stack } from '../stack';
14import { InternalModifierManager } from '../managers';
15
16export interface LiveBlock extends Bounds {
17 openElement(element: SimpleElement): void;
18 closeElement(): void;
19 didAppendNode(node: SimpleNode): void;
20 didAppendBounds(bounds: Bounds): void;
21 finalize(stack: ElementBuilder): void;
22}
23
24export interface SimpleLiveBlock extends LiveBlock {
25 parentElement(): SimpleElement;
26 firstNode(): SimpleNode;
27 lastNode(): SimpleNode;
28}
29
30export interface RemoteLiveBlock extends SimpleLiveBlock {}
31
32export interface UpdatableBlock extends SimpleLiveBlock {
33 reset(env: Environment): Option<SimpleNode>;
34}
35
36export interface DOMStack {
37 pushRemoteElement(
38 element: SimpleElement,
39 guid: string,
40 insertBefore: Maybe<SimpleNode>
41 ): Option<RemoteLiveBlock>;
42 popRemoteElement(): void;
43 popElement(): void;
44 openElement(tag: string, _operations?: ElementOperations): SimpleElement;
45 flushElement(modifiers: Option<ModifierInstance[]>): void;
46 appendText(string: string): SimpleText;
47 appendComment(string: string): SimpleComment;
48
49 appendDynamicHTML(value: string): void;
50 appendDynamicText(value: string): SimpleText;
51 appendDynamicFragment(value: SimpleDocumentFragment): void;
52 appendDynamicNode(value: SimpleNode): void;
53
54 setStaticAttribute(name: string, value: string, namespace: Option<string>): void;
55 setDynamicAttribute(
56 name: string,
57 value: unknown,
58 isTrusting: boolean,
59 namespace: Option<string>
60 ): AttributeOperation;
61
62 closeElement(): Option<ModifierInstance[]>;
63}
64
65export interface TreeOperations {
66 __openElement(tag: string): SimpleElement;
67 __flushElement(parent: SimpleElement, constructing: SimpleElement): void;
68 __openBlock(): void;
69 __closeBlock(): void;
70 __appendText(text: string): SimpleText;
71 __appendComment(string: string): SimpleComment;
72 __appendNode(node: SimpleNode): SimpleNode;
73 __appendHTML(html: string): Bounds;
74 __setAttribute(name: string, value: string, namespace: Option<string>): void;
75 __setProperty(name: string, value: unknown): void;
76}
77
78declare const CURSOR_STACK: unique symbol;
79export type CursorStackSymbol = typeof CURSOR_STACK;
80
81export interface ElementBuilder extends Cursor, DOMStack, TreeOperations {
82 [CURSOR_STACK]: Stack<Cursor>;
83
84 nextSibling: Option<SimpleNode>;
85 dom: GlimmerTreeConstruction;
86 updateOperations: GlimmerTreeChanges;
87 constructing: Option<SimpleElement>;
88 element: SimpleElement;
89
90 hasBlocks: boolean;
91 debugBlocks(): LiveBlock[];
92
93 pushSimpleBlock(): LiveBlock;
94 pushUpdatableBlock(): UpdatableBlock;
95 pushBlockList(list: Bounds[]): LiveBlock;
96 popBlock(): LiveBlock;
97
98 didAppendBounds(bounds: Bounds): void;
99}
100
101export interface AttributeCursor {
102 element: SimpleElement;
103 name: string;
104 namespace: Option<AttrNamespace>;
105}
106
107export interface AttributeOperation {
108 attribute: AttributeCursor;
109 set(dom: ElementBuilder, value: unknown, env: Environment): void;
110 update(value: unknown, env: Environment): void;
111}