@templatical/core 0.0.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/dist/cloud/index.cjs +2692 -0
- package/dist/cloud/index.cjs.map +1 -0
- package/dist/cloud/index.d.cts +465 -0
- package/dist/cloud/index.d.ts +465 -0
- package/dist/cloud/index.js +2631 -0
- package/dist/cloud/index.js.map +1 -0
- package/dist/index.cjs +512 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +148 -0
- package/dist/index.d.ts +148 -0
- package/dist/index.js +484 -0
- package/dist/index.js.map +1 -0
- package/package.json +42 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { TemplateContent, ViewportSize, TemplateDefaults, Block, TemplateSettings, BlockDefaults, BlockType, CustomBlockDefinition, CustomBlock } from '@templatical/types';
|
|
2
|
+
import { Ref, DeepReadonly, ComputedRef } from '@vue/reactivity';
|
|
3
|
+
|
|
4
|
+
interface EditorState {
|
|
5
|
+
content: TemplateContent;
|
|
6
|
+
selectedBlockId: string | null;
|
|
7
|
+
viewport: ViewportSize;
|
|
8
|
+
darkMode: boolean;
|
|
9
|
+
previewMode: boolean;
|
|
10
|
+
isDirty: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface UseEditorOptions {
|
|
13
|
+
content: TemplateContent;
|
|
14
|
+
defaultFontFamily?: string;
|
|
15
|
+
templateDefaults?: TemplateDefaults;
|
|
16
|
+
lockedBlocks?: Ref<Map<string, unknown>>;
|
|
17
|
+
}
|
|
18
|
+
interface UseEditorReturn {
|
|
19
|
+
state: DeepReadonly<EditorState>;
|
|
20
|
+
content: Ref<TemplateContent>;
|
|
21
|
+
selectedBlock: Ref<Block | null>;
|
|
22
|
+
setContent: (content: TemplateContent, markDirty?: boolean) => void;
|
|
23
|
+
selectBlock: (blockId: string | null) => void;
|
|
24
|
+
setViewport: (viewport: ViewportSize) => void;
|
|
25
|
+
setDarkMode: (darkMode: boolean) => void;
|
|
26
|
+
setPreviewMode: (previewMode: boolean) => void;
|
|
27
|
+
updateBlock: (blockId: string, updates: Partial<Block>) => void;
|
|
28
|
+
updateSettings: (updates: Partial<TemplateSettings>) => void;
|
|
29
|
+
addBlock: (block: Block, targetSectionId?: string, columnIndex?: number, index?: number) => void;
|
|
30
|
+
removeBlock: (blockId: string) => void;
|
|
31
|
+
moveBlock: (blockId: string, newIndex: number, targetSectionId?: string, columnIndex?: number) => void;
|
|
32
|
+
isBlockLocked: (blockId: string) => boolean;
|
|
33
|
+
markDirty: () => void;
|
|
34
|
+
}
|
|
35
|
+
declare function useEditor(options: UseEditorOptions): UseEditorReturn;
|
|
36
|
+
|
|
37
|
+
interface UseHistoryOptions {
|
|
38
|
+
content: Ref<TemplateContent>;
|
|
39
|
+
setContent: (content: TemplateContent, markDirty?: boolean) => void;
|
|
40
|
+
isRemoteOperation?: () => boolean;
|
|
41
|
+
maxSize?: number;
|
|
42
|
+
}
|
|
43
|
+
interface UseHistoryReturn {
|
|
44
|
+
canUndo: ComputedRef<boolean>;
|
|
45
|
+
canRedo: ComputedRef<boolean>;
|
|
46
|
+
isNavigating: Ref<boolean>;
|
|
47
|
+
undo: () => void;
|
|
48
|
+
redo: () => void;
|
|
49
|
+
record: () => void;
|
|
50
|
+
recordDebounced: (blockId: string) => void;
|
|
51
|
+
clear: () => void;
|
|
52
|
+
destroy: () => void;
|
|
53
|
+
}
|
|
54
|
+
declare function useHistory(options: UseHistoryOptions): UseHistoryReturn;
|
|
55
|
+
|
|
56
|
+
interface UseBlockActionsOptions {
|
|
57
|
+
addBlock: (block: Block, targetSectionId?: string, columnIndex?: number) => void;
|
|
58
|
+
removeBlock: (blockId: string) => void;
|
|
59
|
+
updateBlock: (blockId: string, updates: Partial<Block>) => void;
|
|
60
|
+
selectBlock: (blockId: string | null) => void;
|
|
61
|
+
blockDefaults?: BlockDefaults;
|
|
62
|
+
}
|
|
63
|
+
interface UseBlockActionsReturn {
|
|
64
|
+
createAndAddBlock: (type: BlockType, targetSectionId?: string, columnIndex?: number) => Block;
|
|
65
|
+
duplicateBlock: (block: Block, targetSectionId?: string, columnIndex?: number) => Block;
|
|
66
|
+
deleteBlock: (blockId: string) => void;
|
|
67
|
+
updateBlockProperty: <K extends keyof Block>(blockId: string, key: K, value: Block[K]) => void;
|
|
68
|
+
}
|
|
69
|
+
declare function useBlockActions(options: UseBlockActionsOptions): UseBlockActionsReturn;
|
|
70
|
+
|
|
71
|
+
interface UseAutoSaveOptions {
|
|
72
|
+
content: Ref<TemplateContent>;
|
|
73
|
+
isDirty: () => boolean;
|
|
74
|
+
onChange: (content: TemplateContent) => void;
|
|
75
|
+
debounce?: number;
|
|
76
|
+
enabled?: boolean | (() => boolean);
|
|
77
|
+
}
|
|
78
|
+
interface UseAutoSaveReturn {
|
|
79
|
+
flush: () => void;
|
|
80
|
+
cancel: () => void;
|
|
81
|
+
pause: () => void;
|
|
82
|
+
resume: () => void;
|
|
83
|
+
destroy: () => void;
|
|
84
|
+
}
|
|
85
|
+
declare function useAutoSave(options: UseAutoSaveOptions): UseAutoSaveReturn;
|
|
86
|
+
|
|
87
|
+
interface UseConditionPreviewReturn {
|
|
88
|
+
isHidden: (blockId: string) => boolean;
|
|
89
|
+
toggleBlock: (blockId: string) => void;
|
|
90
|
+
reset: () => void;
|
|
91
|
+
hasHiddenBlocks: ComputedRef<boolean>;
|
|
92
|
+
}
|
|
93
|
+
declare function useConditionPreview(editor: UseEditorReturn): UseConditionPreviewReturn;
|
|
94
|
+
|
|
95
|
+
declare function useDataSourceFetch(options: {
|
|
96
|
+
definition: ComputedRef<CustomBlockDefinition | undefined>;
|
|
97
|
+
block: ComputedRef<CustomBlock>;
|
|
98
|
+
onUpdate: (fieldValues: Record<string, unknown>, fetched: boolean) => void;
|
|
99
|
+
}): {
|
|
100
|
+
isFetching: Ref<boolean>;
|
|
101
|
+
fetchError: Ref<boolean>;
|
|
102
|
+
fetch: () => Promise<void>;
|
|
103
|
+
hasDataSource: ComputedRef<boolean>;
|
|
104
|
+
needsFetch: ComputedRef<boolean>;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
interface EditorPlugin {
|
|
108
|
+
name: string;
|
|
109
|
+
install(context: EditorPluginContext): void | Promise<void>;
|
|
110
|
+
destroy?(): void;
|
|
111
|
+
}
|
|
112
|
+
interface EditorPluginContext {
|
|
113
|
+
readonly state: DeepReadonly<EditorState>;
|
|
114
|
+
readonly content: Ref<TemplateContent>;
|
|
115
|
+
readonly selectedBlockId: DeepReadonly<EditorState>["selectedBlockId"];
|
|
116
|
+
readonly viewport: DeepReadonly<EditorState>["viewport"];
|
|
117
|
+
addBlock(block: Block, targetSectionId?: string, columnIndex?: number, index?: number): void;
|
|
118
|
+
updateBlock(blockId: string, updates: Partial<Block>): void;
|
|
119
|
+
removeBlock(blockId: string): void;
|
|
120
|
+
moveBlock(blockId: string, newIndex: number, targetSectionId?: string, columnIndex?: number): void;
|
|
121
|
+
updateSettings(updates: Partial<TemplateSettings>): void;
|
|
122
|
+
selectBlock(blockId: string | null): void;
|
|
123
|
+
registerToolbarAction(action: ToolbarAction): void;
|
|
124
|
+
registerSidebarPanel(panel: SidebarPanel): void;
|
|
125
|
+
registerBlockAction(action: BlockContextAction): void;
|
|
126
|
+
}
|
|
127
|
+
interface ToolbarAction {
|
|
128
|
+
id: string;
|
|
129
|
+
icon: string;
|
|
130
|
+
label: string;
|
|
131
|
+
onClick: () => void;
|
|
132
|
+
position?: "left" | "right";
|
|
133
|
+
}
|
|
134
|
+
interface SidebarPanel {
|
|
135
|
+
id: string;
|
|
136
|
+
icon: string;
|
|
137
|
+
label: string;
|
|
138
|
+
component: unknown;
|
|
139
|
+
position?: "left" | "right";
|
|
140
|
+
}
|
|
141
|
+
interface BlockContextAction {
|
|
142
|
+
id: string;
|
|
143
|
+
icon: string;
|
|
144
|
+
label: string;
|
|
145
|
+
onClick: (blockId: string) => void;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export { type BlockContextAction, type EditorPlugin, type EditorPluginContext, type EditorState, type SidebarPanel, type ToolbarAction, type UseAutoSaveOptions, type UseAutoSaveReturn, type UseBlockActionsOptions, type UseBlockActionsReturn, type UseConditionPreviewReturn, type UseEditorOptions, type UseEditorReturn, type UseHistoryOptions, type UseHistoryReturn, useAutoSave, useBlockActions, useConditionPreview, useDataSourceFetch, useEditor, useHistory };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { TemplateContent, ViewportSize, TemplateDefaults, Block, TemplateSettings, BlockDefaults, BlockType, CustomBlockDefinition, CustomBlock } from '@templatical/types';
|
|
2
|
+
import { Ref, DeepReadonly, ComputedRef } from '@vue/reactivity';
|
|
3
|
+
|
|
4
|
+
interface EditorState {
|
|
5
|
+
content: TemplateContent;
|
|
6
|
+
selectedBlockId: string | null;
|
|
7
|
+
viewport: ViewportSize;
|
|
8
|
+
darkMode: boolean;
|
|
9
|
+
previewMode: boolean;
|
|
10
|
+
isDirty: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface UseEditorOptions {
|
|
13
|
+
content: TemplateContent;
|
|
14
|
+
defaultFontFamily?: string;
|
|
15
|
+
templateDefaults?: TemplateDefaults;
|
|
16
|
+
lockedBlocks?: Ref<Map<string, unknown>>;
|
|
17
|
+
}
|
|
18
|
+
interface UseEditorReturn {
|
|
19
|
+
state: DeepReadonly<EditorState>;
|
|
20
|
+
content: Ref<TemplateContent>;
|
|
21
|
+
selectedBlock: Ref<Block | null>;
|
|
22
|
+
setContent: (content: TemplateContent, markDirty?: boolean) => void;
|
|
23
|
+
selectBlock: (blockId: string | null) => void;
|
|
24
|
+
setViewport: (viewport: ViewportSize) => void;
|
|
25
|
+
setDarkMode: (darkMode: boolean) => void;
|
|
26
|
+
setPreviewMode: (previewMode: boolean) => void;
|
|
27
|
+
updateBlock: (blockId: string, updates: Partial<Block>) => void;
|
|
28
|
+
updateSettings: (updates: Partial<TemplateSettings>) => void;
|
|
29
|
+
addBlock: (block: Block, targetSectionId?: string, columnIndex?: number, index?: number) => void;
|
|
30
|
+
removeBlock: (blockId: string) => void;
|
|
31
|
+
moveBlock: (blockId: string, newIndex: number, targetSectionId?: string, columnIndex?: number) => void;
|
|
32
|
+
isBlockLocked: (blockId: string) => boolean;
|
|
33
|
+
markDirty: () => void;
|
|
34
|
+
}
|
|
35
|
+
declare function useEditor(options: UseEditorOptions): UseEditorReturn;
|
|
36
|
+
|
|
37
|
+
interface UseHistoryOptions {
|
|
38
|
+
content: Ref<TemplateContent>;
|
|
39
|
+
setContent: (content: TemplateContent, markDirty?: boolean) => void;
|
|
40
|
+
isRemoteOperation?: () => boolean;
|
|
41
|
+
maxSize?: number;
|
|
42
|
+
}
|
|
43
|
+
interface UseHistoryReturn {
|
|
44
|
+
canUndo: ComputedRef<boolean>;
|
|
45
|
+
canRedo: ComputedRef<boolean>;
|
|
46
|
+
isNavigating: Ref<boolean>;
|
|
47
|
+
undo: () => void;
|
|
48
|
+
redo: () => void;
|
|
49
|
+
record: () => void;
|
|
50
|
+
recordDebounced: (blockId: string) => void;
|
|
51
|
+
clear: () => void;
|
|
52
|
+
destroy: () => void;
|
|
53
|
+
}
|
|
54
|
+
declare function useHistory(options: UseHistoryOptions): UseHistoryReturn;
|
|
55
|
+
|
|
56
|
+
interface UseBlockActionsOptions {
|
|
57
|
+
addBlock: (block: Block, targetSectionId?: string, columnIndex?: number) => void;
|
|
58
|
+
removeBlock: (blockId: string) => void;
|
|
59
|
+
updateBlock: (blockId: string, updates: Partial<Block>) => void;
|
|
60
|
+
selectBlock: (blockId: string | null) => void;
|
|
61
|
+
blockDefaults?: BlockDefaults;
|
|
62
|
+
}
|
|
63
|
+
interface UseBlockActionsReturn {
|
|
64
|
+
createAndAddBlock: (type: BlockType, targetSectionId?: string, columnIndex?: number) => Block;
|
|
65
|
+
duplicateBlock: (block: Block, targetSectionId?: string, columnIndex?: number) => Block;
|
|
66
|
+
deleteBlock: (blockId: string) => void;
|
|
67
|
+
updateBlockProperty: <K extends keyof Block>(blockId: string, key: K, value: Block[K]) => void;
|
|
68
|
+
}
|
|
69
|
+
declare function useBlockActions(options: UseBlockActionsOptions): UseBlockActionsReturn;
|
|
70
|
+
|
|
71
|
+
interface UseAutoSaveOptions {
|
|
72
|
+
content: Ref<TemplateContent>;
|
|
73
|
+
isDirty: () => boolean;
|
|
74
|
+
onChange: (content: TemplateContent) => void;
|
|
75
|
+
debounce?: number;
|
|
76
|
+
enabled?: boolean | (() => boolean);
|
|
77
|
+
}
|
|
78
|
+
interface UseAutoSaveReturn {
|
|
79
|
+
flush: () => void;
|
|
80
|
+
cancel: () => void;
|
|
81
|
+
pause: () => void;
|
|
82
|
+
resume: () => void;
|
|
83
|
+
destroy: () => void;
|
|
84
|
+
}
|
|
85
|
+
declare function useAutoSave(options: UseAutoSaveOptions): UseAutoSaveReturn;
|
|
86
|
+
|
|
87
|
+
interface UseConditionPreviewReturn {
|
|
88
|
+
isHidden: (blockId: string) => boolean;
|
|
89
|
+
toggleBlock: (blockId: string) => void;
|
|
90
|
+
reset: () => void;
|
|
91
|
+
hasHiddenBlocks: ComputedRef<boolean>;
|
|
92
|
+
}
|
|
93
|
+
declare function useConditionPreview(editor: UseEditorReturn): UseConditionPreviewReturn;
|
|
94
|
+
|
|
95
|
+
declare function useDataSourceFetch(options: {
|
|
96
|
+
definition: ComputedRef<CustomBlockDefinition | undefined>;
|
|
97
|
+
block: ComputedRef<CustomBlock>;
|
|
98
|
+
onUpdate: (fieldValues: Record<string, unknown>, fetched: boolean) => void;
|
|
99
|
+
}): {
|
|
100
|
+
isFetching: Ref<boolean>;
|
|
101
|
+
fetchError: Ref<boolean>;
|
|
102
|
+
fetch: () => Promise<void>;
|
|
103
|
+
hasDataSource: ComputedRef<boolean>;
|
|
104
|
+
needsFetch: ComputedRef<boolean>;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
interface EditorPlugin {
|
|
108
|
+
name: string;
|
|
109
|
+
install(context: EditorPluginContext): void | Promise<void>;
|
|
110
|
+
destroy?(): void;
|
|
111
|
+
}
|
|
112
|
+
interface EditorPluginContext {
|
|
113
|
+
readonly state: DeepReadonly<EditorState>;
|
|
114
|
+
readonly content: Ref<TemplateContent>;
|
|
115
|
+
readonly selectedBlockId: DeepReadonly<EditorState>["selectedBlockId"];
|
|
116
|
+
readonly viewport: DeepReadonly<EditorState>["viewport"];
|
|
117
|
+
addBlock(block: Block, targetSectionId?: string, columnIndex?: number, index?: number): void;
|
|
118
|
+
updateBlock(blockId: string, updates: Partial<Block>): void;
|
|
119
|
+
removeBlock(blockId: string): void;
|
|
120
|
+
moveBlock(blockId: string, newIndex: number, targetSectionId?: string, columnIndex?: number): void;
|
|
121
|
+
updateSettings(updates: Partial<TemplateSettings>): void;
|
|
122
|
+
selectBlock(blockId: string | null): void;
|
|
123
|
+
registerToolbarAction(action: ToolbarAction): void;
|
|
124
|
+
registerSidebarPanel(panel: SidebarPanel): void;
|
|
125
|
+
registerBlockAction(action: BlockContextAction): void;
|
|
126
|
+
}
|
|
127
|
+
interface ToolbarAction {
|
|
128
|
+
id: string;
|
|
129
|
+
icon: string;
|
|
130
|
+
label: string;
|
|
131
|
+
onClick: () => void;
|
|
132
|
+
position?: "left" | "right";
|
|
133
|
+
}
|
|
134
|
+
interface SidebarPanel {
|
|
135
|
+
id: string;
|
|
136
|
+
icon: string;
|
|
137
|
+
label: string;
|
|
138
|
+
component: unknown;
|
|
139
|
+
position?: "left" | "right";
|
|
140
|
+
}
|
|
141
|
+
interface BlockContextAction {
|
|
142
|
+
id: string;
|
|
143
|
+
icon: string;
|
|
144
|
+
label: string;
|
|
145
|
+
onClick: (blockId: string) => void;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export { type BlockContextAction, type EditorPlugin, type EditorPluginContext, type EditorState, type SidebarPanel, type ToolbarAction, type UseAutoSaveOptions, type UseAutoSaveReturn, type UseBlockActionsOptions, type UseBlockActionsReturn, type UseConditionPreviewReturn, type UseEditorOptions, type UseEditorReturn, type UseHistoryOptions, type UseHistoryReturn, useAutoSave, useBlockActions, useConditionPreview, useDataSourceFetch, useEditor, useHistory };
|