@cloudcannon/configuration-types 0.0.25 → 0.0.26

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/src/index.d.ts CHANGED
@@ -14,6 +14,7 @@ export type * from './snippets';
14
14
  export type * from './source-editor';
15
15
  export type * from './structures';
16
16
  export type * from './timezone';
17
+ export type * from './javascript-api';
17
18
 
18
19
  export type SsgKey =
19
20
  | 'hugo'
@@ -0,0 +1,180 @@
1
+ import type { Cascade } from './cascade';
2
+ import type { SnippetConfig } from './snippets';
3
+ import type { FileInput, ImageInput, RichTextInput } from './inputs';
4
+
5
+ export interface CloseCustomDataPanelOptions {
6
+ parentId: string;
7
+ id: string;
8
+ }
9
+
10
+ export interface OpenCustomDataPanelOptions extends CloseCustomDataPanelOptions {
11
+ data: Record<string, any> | any[] | undefined;
12
+ position?: DOMRect;
13
+ title: string;
14
+ inputConfig: Cascade & SnippetConfig;
15
+ allowFullDataCascade?: boolean;
16
+ }
17
+
18
+ /**
19
+ * Interface defining the public JavaScript API for interacting with CloudCannon's Visual Editor.
20
+ * This API provides methods for managing content, handling file operations, and controlling the editor's state.
21
+ */
22
+ export interface CloudCannonJavascriptAPI {
23
+ /** Whether event handling is currently enabled */
24
+ eventsEnabled: boolean;
25
+ /** Whether the API should be installed globally */
26
+ installGlobally: boolean;
27
+
28
+ /**
29
+ * Disables the global installation of the API
30
+ */
31
+ disableGlobalInstall(): void;
32
+
33
+ /**
34
+ * Enables event handling for the API
35
+ * This will also ensure the commit model is created
36
+ */
37
+ enableEvents(): void;
38
+
39
+ /**
40
+ * Disables event handling for the API
41
+ */
42
+ disableEvents(): void;
43
+
44
+ /**
45
+ * Refreshes the editor interface
46
+ * Note: This has been replaced with a MutationObserver in editor-overlays-view
47
+ */
48
+ refreshInterface(): void;
49
+
50
+ /**
51
+ * Triggers an update event for a specific file
52
+ * @param sourcePath - The path of the file to update
53
+ */
54
+ triggerUpdateEvent(sourcePath: string): void;
55
+
56
+ /**
57
+ * Sets the loading state of the editor
58
+ * @param loadingData - Optional loading state message
59
+ * @returns Promise that resolves when loading state is updated
60
+ */
61
+ setLoading(loadingData: string | undefined): Promise<any>;
62
+
63
+ /**
64
+ * Sets data for a specific field
65
+ * @param slug - The identifier of the field to set
66
+ * @param value - The value to set
67
+ * @returns Promise that resolves when the data is set
68
+ */
69
+ set(slug: string, value: any): Promise<any>;
70
+
71
+ /**
72
+ * Initiates editing of a specific field
73
+ * @param slug - The identifier of the field to edit
74
+ * @param style - Optional style information
75
+ * @param e - The mouse event that triggered the edit
76
+ */
77
+ edit(slug: string, style: string | null, e: MouseEvent): void;
78
+
79
+ /**
80
+ * Opens a custom data panel for editing
81
+ * @param options - Configuration options for the panel
82
+ * @returns Promise that resolves when the panel is opened
83
+ */
84
+ openCustomDataPanel(options: OpenCustomDataPanelOptions): Promise<void>;
85
+
86
+ /**
87
+ * Closes a custom data panel
88
+ * @param options - Configuration options for the panel to close
89
+ * @returns Promise that resolves when the panel is closed
90
+ */
91
+ closeCustomDataPanel(options: CloseCustomDataPanelOptions): Promise<void>;
92
+
93
+ /**
94
+ * Uploads a file to the editor
95
+ * @param file - The file to upload
96
+ * @param inputConfig - Optional configuration for the input
97
+ * @returns Promise that resolves with the path of the uploaded file
98
+ */
99
+ uploadFile(file: File, inputConfig: RichTextInput | ImageInput | FileInput | undefined): Promise<string | undefined>;
100
+
101
+ /**
102
+ * Adds an item to an array field
103
+ * @param slug - The identifier of the array field
104
+ * @param index - The position to insert at (null for end)
105
+ * @param value - The value to insert
106
+ * @param e - The mouse event that triggered the addition
107
+ * @returns Promise that resolves when the item is added
108
+ */
109
+ addArrayItem(slug: string, index: number | null, value: any, e: MouseEvent): Promise<void>;
110
+
111
+ /**
112
+ * Adds an item before a specific index in an array field
113
+ * @param slug - The identifier of the array field
114
+ * @param index - The index to insert before
115
+ * @param value - The value to insert
116
+ * @param e - The mouse event that triggered the addition
117
+ * @returns Promise that resolves when the item is added
118
+ */
119
+ addArrayItemBefore(slug: string, index: number, value: any, e: MouseEvent): Promise<void>;
120
+
121
+ /**
122
+ * Adds an item after a specific index in an array field
123
+ * @param slug - The identifier of the array field
124
+ * @param index - The index to insert after
125
+ * @param value - The value to insert
126
+ * @param e - The mouse event that triggered the addition
127
+ * @returns Promise that resolves when the item is added
128
+ */
129
+ addArrayItemAfter(slug: string, index: number, value: any, e: MouseEvent): Promise<void>;
130
+
131
+ /**
132
+ * Removes an item from an array field
133
+ * @param slug - The identifier of the array field
134
+ * @param index - The index of the item to remove
135
+ * @returns Promise that resolves when the item is removed
136
+ */
137
+ removeArrayItem(slug: string, index: number): Promise<void>;
138
+
139
+ /**
140
+ * Moves an item within an array field
141
+ * @param slug - The identifier of the array field
142
+ * @param index - The current index of the item
143
+ * @param toIndex - The target index for the item
144
+ * @returns Promise that resolves when the item is moved
145
+ */
146
+ moveArrayItem(slug: string, index: number, toIndex: number): Promise<void>;
147
+
148
+ /**
149
+ * Gets the current value of the editor
150
+ * @param options - Optional configuration for the value retrieval
151
+ * @returns Promise that resolves with the current value
152
+ */
153
+ value(options?: { keepMarkdownAsHTML?: boolean }): Promise<string>;
154
+
155
+ /**
156
+ * Claims a lock on a file
157
+ * @param sourcePath - Optional path of the file to lock
158
+ * @returns Promise that resolves with the lock status
159
+ */
160
+ claimLock(sourcePath?: string): Promise<{ readOnly: boolean }>;
161
+
162
+ /**
163
+ * Releases a lock on a file
164
+ * @param sourcePath - Optional path of the file to unlock
165
+ * @returns Promise that resolves with the lock status
166
+ */
167
+ releaseLock(sourcePath?: string): Promise<{ readOnly: boolean }>;
168
+
169
+ /**
170
+ * Gets prefetched files
171
+ * @returns Promise that resolves with a record of file blobs
172
+ */
173
+ prefetchedFiles(): Promise<Record<string, Blob>>;
174
+
175
+ /**
176
+ * Loads legacy Bookshop information
177
+ * @returns Promise that resolves with the Bookshop data
178
+ */
179
+ loadLegacyBookshopInfo(): Promise<any>;
180
+ }