@nuforge/editor 0.1.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.
@@ -0,0 +1,128 @@
1
+ import * as t from '@nuforge/types';
2
+ import { Nu } from '@nuforge/core';
3
+ import { MutationEntry } from '@nuforge/reactivity';
4
+
5
+ interface PropSchemaField {
6
+ name: string;
7
+ type: 'string' | 'number' | 'boolean' | 'expression' | 'enum';
8
+ label?: string;
9
+ default?: string | number | boolean;
10
+ options?: string[];
11
+ }
12
+ interface Block {
13
+ id: string;
14
+ label: string;
15
+ icon?: string;
16
+ category?: string;
17
+ create: () => t.Template;
18
+ props?: PropSchemaField[];
19
+ }
20
+ declare function defineBlock(block: Block): Block;
21
+ declare class BlockRegistry {
22
+ private readonly blocks;
23
+ constructor(initial?: Block[]);
24
+ register(block: Block): void;
25
+ get(id: string): Block | undefined;
26
+ all(): Block[];
27
+ byCategory(): Record<string, Block[]>;
28
+ }
29
+ declare const DEFAULT_BLOCKS: Block[];
30
+
31
+ declare function lit(value: string | number | boolean): t.Literal;
32
+ declare function text(value: string): t.TagTemplate;
33
+ declare function el(tag: string, props?: Record<string, t.Expression>, children?: t.Template[]): t.TagTemplate;
34
+
35
+ type DropPosition = 'before' | 'after' | 'inside';
36
+ declare function dropPositionFromPointer(clientY: number, rect: {
37
+ top: number;
38
+ height: number;
39
+ }, opts?: {
40
+ allowInside?: boolean;
41
+ }): DropPosition;
42
+ declare function templateLabel(node: t.Template): string;
43
+ declare function templateChildren(node: t.Template): t.Template[];
44
+ declare function isTextTemplate(node: t.Template): boolean;
45
+ declare function textPreview(node: t.Template): string | null;
46
+ declare function canHaveChildren(node: t.Template | null): boolean;
47
+ declare function isAncestorOf(nu: Nu, ancestor: t.Template, node: t.Template): boolean;
48
+
49
+ interface CreateEditorOptions {
50
+ blocks?: Block[];
51
+ defaultBlocks?: boolean;
52
+ }
53
+ declare class Editor {
54
+ readonly nu: Nu;
55
+ readonly blocks: BlockRegistry;
56
+ readonly commands: CommandRegistry;
57
+ constructor(nu: Nu, opts?: CreateEditorOptions);
58
+ insertNode(parent: t.Template, child: t.Template, index?: number): void;
59
+ removeNode(node: t.Template): boolean;
60
+ moveNode(dragged: t.Template, target: t.Template, position: DropPosition): boolean;
61
+ private clipboardNode;
62
+ copyNode(node: t.Template): void;
63
+ cutNode(node: t.Template): boolean;
64
+ canPaste(): boolean;
65
+ pasteNode(target: t.Template, position?: DropPosition): t.Template | null;
66
+ duplicateNode(node: t.Template): t.Template | null;
67
+ insertNodeAt(node: t.Template, target: t.Template, position: DropPosition): t.Template | null;
68
+ insertBlockAt(blockId: string, target: t.Template, position: DropPosition): t.Template | null;
69
+ private insertCloneRelativeTo;
70
+ updateProps(node: t.Template, props: Record<string, t.Expression>): void;
71
+ setProp(node: t.Template, key: string, expr: t.Expression): void;
72
+ removeProp(node: t.Template, key: string): void;
73
+ setExpression(node: t.Template, key: string, source: string): boolean;
74
+ setText(node: t.Template, value: string): boolean;
75
+ setTag(node: t.TagTemplate, tag: string): void;
76
+ addClass(node: t.Template, name: string): void;
77
+ setClassCondition(node: t.Template, name: string, source: string): boolean;
78
+ removeClass(node: t.Template, name: string): void;
79
+ setCondition(node: t.Template, source: string): boolean;
80
+ clearCondition(node: t.Template): void;
81
+ setEach(node: t.Template, iterator: string, alias?: string, indexName?: string): boolean;
82
+ clearEach(node: t.Template): void;
83
+ addState(component: t.NuComponent, name?: string, init?: string): t.Val;
84
+ removeState(component: t.NuComponent, val: t.Val): void;
85
+ setStateInit(val: t.Val, source: string): boolean;
86
+ addComponentProp(component: t.NuComponent, name?: string, init?: string): t.ComponentProp;
87
+ removeComponentProp(component: t.NuComponent, prop: t.ComponentProp): void;
88
+ setComponentPropInit(prop: t.ComponentProp, source: string): boolean;
89
+ insertBlock(blockId: string, parent: t.Template, index?: number): t.Template | null;
90
+ private uniqueName;
91
+ addComponent(name?: string): t.NuComponent;
92
+ renameComponent(component: t.NuComponent, name: string): boolean;
93
+ removeComponent(component: t.NuComponent): boolean;
94
+ duplicateComponent(component: t.NuComponent): t.NuComponent;
95
+ private walkTemplates;
96
+ getComponents(): t.NuComponent[];
97
+ getComponent(name: string): t.NuComponent | undefined;
98
+ getRootTemplate(name: string): t.Template | null;
99
+ getChildren(node: t.Template): t.Template[];
100
+ getSiblings(node: t.Template): t.Template[];
101
+ getNodeIndex(node: t.Template): number;
102
+ getNodePath(node: t.Type): Array<string | number>;
103
+ onChange(cb: (entries: MutationEntry[]) => void): () => void;
104
+ onStructureChange(cb: () => void): () => void;
105
+ private spliceFromParent;
106
+ private applyMove;
107
+ private insertRelativeTo;
108
+ }
109
+ declare function createEditor(nu: Nu, opts?: CreateEditorOptions): Editor;
110
+
111
+ interface Command {
112
+ id: string;
113
+ label: string;
114
+ shortcut?: string;
115
+ run: (editor: Editor) => void;
116
+ }
117
+ declare class CommandRegistry {
118
+ private readonly editor;
119
+ private readonly commands;
120
+ constructor(editor: Editor);
121
+ register(command: Command): void;
122
+ get(id: string): Command | undefined;
123
+ all(): Command[];
124
+ run(id: string): void;
125
+ }
126
+
127
+ export { BlockRegistry, CommandRegistry, DEFAULT_BLOCKS, Editor, canHaveChildren, createEditor, defineBlock, dropPositionFromPointer, el, isAncestorOf, isTextTemplate, lit, templateChildren, templateLabel, text, textPreview };
128
+ export type { Block, Command, CreateEditorOptions, DropPosition, PropSchemaField };