UNPKG

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