@webflow/designer-extension-typings 0.2.0-beta.1 → 0.2.0-beta.2

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/api.d.ts ADDED
@@ -0,0 +1,371 @@
1
+ /// <reference path="./brand.d.ts" />
2
+ /// <reference path="./styles.d.ts" />
3
+ /// <reference path="./pages.d.ts" />
4
+ /// <reference path="./elements.d.ts" />
5
+ /// <reference path="./element-presets.d.ts" />
6
+ /// <reference path="./components.d.ts" />
7
+ /// <reference path="./variables.d.ts" />
8
+
9
+ interface WebflowApi {
10
+ /**
11
+ * Get metadata about the current Site.
12
+ * @returns A Promise that resolves to a record containing information about the site that is open in the
13
+ * Designer, with the following properties:
14
+ * - siteId: the unique ID of the current Webflow site.
15
+ * - siteName: the name of the current Webflow site.
16
+ * - shortName: a shortened reference to the name of the current Webflow site.
17
+ * @example
18
+ * ```ts
19
+ * const siteInfo = await webflow.getSiteInfo();
20
+ * console.log('Site ID:', siteInfo.siteId);
21
+ * console.log('Site Name:', siteInfo.siteName);
22
+ * console.log('Shortened Site Name:', siteInfo.shortName);
23
+ * ```
24
+ */
25
+ getSiteInfo(): Promise<{siteId: string; siteName: string; shortName: string}>;
26
+ /**
27
+ * Get the currently selected element in the Webflow designer.
28
+ * @returns A promise that resolves to one of the following:
29
+ * - null: If no element is currently selected in the designer
30
+ * - AnyElement: an object representing the selected element, which can be of any type.
31
+ * @example
32
+ * ```ts
33
+ * const selectedElement = await webflow.getSelectedElement();
34
+ * if (selectedElement) {
35
+ * // Handle the selected element
36
+ * } else {
37
+ * // No element is currently selected
38
+ * }
39
+ * ```
40
+ */
41
+ getSelectedElement(): Promise<null | AnyElement>;
42
+ /**
43
+ * Get the current media query breakpoint ID.
44
+ * @returns A Promise that resolves to a BreakpointId which is a string representing the current media query
45
+ * breakpoint. A BreakpointId is one of 'tiny', 'small', 'medium', 'main', 'large', 'xl', 'xxl'.
46
+ * @example
47
+ * ```ts
48
+ * const breakpoint = await webflow.getMediaQuery();
49
+ * console.log('Current Media Query:', breakpoint);
50
+ * ```
51
+ */
52
+ getMediaQuery(): Promise<BreakpointId>;
53
+ /**
54
+ * Create a component by promoting a Root Element.
55
+ * @param name - The name of the component.
56
+ * @param rootElement - An Element that will become the Root Element of the Component.
57
+ * @returns A Promise resolving to an object containing the newly created Component - with the id property.
58
+ * @example
59
+ * ```ts
60
+ * const element = webflow.createDOM('div')
61
+ * await webflow.registerComponent('Hero-Component', element)
62
+ *
63
+ * // Example Response
64
+ * {id: '204d04de-bf48-5b5b-0ca8-6ec4c5364fd2'}
65
+ * ```
66
+ */
67
+ registerComponent(
68
+ name: string,
69
+ root: AnyElement | ElementPreset<AnyElement> | Component
70
+ ): Promise<Component>;
71
+ /**
72
+ * Delete a component from the Designer. If there are any instances of the Component within the site, they will
73
+ * be converted to regular Elements.
74
+ * @param component - The component object you wish to delete.
75
+ * @returns A Promise resolving that resolves when the Component is deleted.
76
+ * @example
77
+ * ```ts
78
+ * const element = webflow.createDOM('div')
79
+ * const heroComponent = await webflow.registerComponent('Hero-Component', element)
80
+ * await webflow.unregisterComponent(heroComponent)
81
+ * ```
82
+ */
83
+ unregisterComponent(component: Component): Promise<null>;
84
+ /**
85
+ * Fetch all Site-scoped components definitions. In order to edit a component, you’ll need to get a specific
86
+ * Component instance.
87
+ * @returns A Promise resolving to an array containing all Components from the currently open site in the
88
+ * Designer - with the id property.
89
+ * @example
90
+ * ```ts
91
+ * const fetchedComponents = await webflow.getAllComponents();
92
+ *
93
+ * // Example Response
94
+ * [
95
+ * {id: "4a669354-353a-97eb-795c-4471b406e043"}
96
+ * {id: 'd6e076e2-19a2-c4ae-9da3-ce3b0493b503'}
97
+ * ]
98
+ * ```
99
+ */
100
+ getAllComponents(): Promise<Array<Component>>;
101
+ /**
102
+ * Focus the designer on a Component. When a component is in focus, all Globals pertain specifically to that
103
+ * Component, not the entire Site.
104
+ * @param instance - A Component Instance that is present on the page. If there’s no current instance, you’ll
105
+ * need to create one first.
106
+ * @returns A Promise that resolves when the page switch is successful.
107
+ * @example
108
+ * ```ts
109
+ * await webflow.enterComponent(heroComponentInstance);
110
+ * ```
111
+ */
112
+ enterComponent(instance: ComponentElement): Promise<null>;
113
+ /**
114
+ * Return to the broader context of the entire site or page.
115
+ * @returns A Promise that resolves when the page switch is successful.
116
+ * @example
117
+ * ```ts
118
+ * await webflow.exitComponent();
119
+ * ```
120
+ */
121
+ exitComponent(): Promise<null>;
122
+ /**
123
+ * Get Root element. When the designer is focused or "entered" into a Component, this method will get the
124
+ * outermost element in the Component.
125
+ * @returns The outermost element of the Page or Component.
126
+ * @example
127
+ * ```ts
128
+ * // 🎉 Enter into Component 🎉
129
+ * await webflow.enterComponent(heroComponentInstance)
130
+ * const root = await webflow.getRootElement()
131
+ *
132
+ * // Example Response
133
+ * {id: '204d04de-bf48-5b5b-0ca8-6ec4c5364fd2'}
134
+ * ```
135
+ */
136
+ getRootElement(): Promise<null | AnyElement>;
137
+ /**
138
+ * Fetch an array of all elements present on the current page of the Designer. If the Designer is editing a
139
+ * component, the elements returned are those present in that Component.
140
+ * @returns A Promise that resolves to an array of AnyElement objects. AnyElement represents various element
141
+ * types available in a Webflow project. Each element type corresponds to different types of HTML elements or
142
+ * components that can be used within the designer. You can see a full list of supported elements in our
143
+ * designer extensions typing file.
144
+ * @example
145
+ * ```ts
146
+ * const allElements = await webflow.getAllElements()
147
+ * const paragraphs = allElements.flatMap(el => el.type === 'Paragraph' ? [el] : [])
148
+ * paragraphs.forEach(el => {
149
+ * el.setTextContent('Hello')
150
+ * el.save()
151
+ * })
152
+ * ```
153
+ */
154
+ getAllElements(): Promise<Array<AnyElement>>;
155
+
156
+ /**
157
+ * Creates a new style with the provided name.
158
+ * @param name - The name for the new style.
159
+ * @returns a Promise that resolves to the Style object representing the newly created style.
160
+ * @example
161
+ * ```ts
162
+ * const newStyle = await webflow.createStyle('myNewStyle');
163
+ * ```
164
+ */
165
+ createStyle(name: string): Promise<Style>;
166
+ /**
167
+ * Fetch a style by its name.
168
+ * @param name - The name of the style to retrieve.
169
+ * @returns A Promise that resolves to one of the following:
170
+ * - null if no style with the given name is found.
171
+ * - Style object representing the style with the specified name.
172
+ * @example
173
+ * ```ts
174
+ * const styleName = 'myStyle';
175
+ * const style = await webflow.getStyleByName(styleName);
176
+ * if (style) {
177
+ * // Style found, handle it
178
+ * } else {
179
+ * // Style not found
180
+ * }
181
+ * ```
182
+ */
183
+ getStyleByName(name: string): Promise<null | Style>;
184
+ /**
185
+ * Fetch an array of all styles available in the Webflow project.
186
+ * @returns A Promise that resolves to an array of Style objects representing all the styles present on the
187
+ * site that is open in the Designer.
188
+ * @example
189
+ * ```ts
190
+ * const allStyles = await webflow.getAllStyles();
191
+ * allStyles.forEach((style) => {
192
+ * // Process each style
193
+ * });
194
+ * ```
195
+ */
196
+ getAllStyles(): Promise<Array<Style>>;
197
+ /**
198
+ * Fetch the currently active page in the Webflow designer.
199
+ * @returns A Promise that resolves to a Page object representing the current page open in the Designer.
200
+ * @example
201
+ * ```ts
202
+ * const currentPage = await webflow.getCurrentPage();
203
+ * console.log('Current Page:', currentPage);
204
+ * ```
205
+ */
206
+ getCurrentPage(): Promise<Page>;
207
+ /**
208
+ * Fetch an array of all pages and folders in the Webflow project.
209
+ * @returns A Promise that resolves to an array of Page and Folder objects representing all the pages
210
+ * and folders of the site that is open in the Designer.
211
+ * @example
212
+ * ```ts
213
+ * const items = await webflow.getAllPagesAndFolders();
214
+ * items.forEach((item) => {
215
+ * // Process each page or folder
216
+ * });
217
+ * ```
218
+ */
219
+ getAllPagesAndFolders(): Promise<Array<Page | Folder>>;
220
+ /**
221
+ * Create a new page folder within the current Webflow project.
222
+ * @returns A Promise that resolves to a Folder object representing a newly created folder for the site open in
223
+ * the Designer.
224
+ * @example
225
+ * ```ts
226
+ * const newFolder = await webflow.createPageFolder();
227
+ * // Handle the new folder
228
+ * ```
229
+ */
230
+ createPageFolder(): Promise<Folder>;
231
+ /**
232
+ * Create a new Page within the current Webflow project.
233
+ * @returns A Promise that resolves to a Page object representing a newly created page for the site open in the Designer.
234
+ * @example
235
+ * ```ts
236
+ * const newPage = await webflow.createPage();
237
+ * // Handle the new page
238
+ * ```
239
+ */
240
+ createPage(): Promise<Page>;
241
+ /**
242
+ * @param page - The Page object representing the target page to switch to.
243
+ * @returns A Promise that resolves when the page switch is successful.
244
+ * @example
245
+ * ```ts
246
+ * const targetPage = <Get the target page>;
247
+ * await webflow.switchPage(targetPage);
248
+ * // Page switched successfully
249
+ * ```
250
+ */
251
+ switchPage(page: Page): Promise<void>;
252
+ /**
253
+ * Access the default variable collection.
254
+ * @returns A Promise that resolves into a Collection.
255
+ * @example
256
+ * ```ts
257
+ * const collection = webflow.getDefaultVariableCollection();
258
+ * // This collection object can now be used to create variables or access variables within it
259
+ * const variable = collection.getVariableByName('Space Cadet');
260
+ * ```
261
+ */
262
+ getDefaultVariableCollection(): Promise<null | VariableCollection>;
263
+ /**
264
+ * Sets the extension size to one of predefined sizes or a custom size. If the specified custom size is larger than
265
+ * the user's viewport size, the extension will default to the width/height of the browser's viewport.
266
+ * @param size - The size to set the extension window to. One of 'default', 'comfortable', 'large', or an object
267
+ * containing width and height keys.
268
+ * @example
269
+ * ```ts
270
+ * await webflow.setExtensionSize("large") ;
271
+ * // Perform actions for large window
272
+ *
273
+ * await webflow.setExtensionSize({width: 1000, height: 700}) ;
274
+ * //Perform actions for this window size
275
+ * ```
276
+ */
277
+ setExtensionSize(
278
+ size: 'default' | 'comfortable' | 'large' | {width: number; height: number}
279
+ ): Promise<null>;
280
+ /**
281
+ * Notifies the user with a message using a specific style. Error messages provide user's with the opportunity to
282
+ * close the Designer Extension.
283
+ * @param opts - An object containing the following notification options:
284
+ * - type: The type of notification to display. One of 'Error', 'Info', 'Success'.
285
+ * - message: The message to display in the notification.
286
+ * @returns A Promise that resolves when the notification is displayed to the user.
287
+ * @example
288
+ * ```ts
289
+ * webflow.notify({ type: 'Info', message: 'Great work!' }); // General notification
290
+ * webflow.notify({ type: 'Error', message: 'Something went wrong, try again!' }); // Error notification
291
+ * webflow.notify({ type: 'Success', message: 'Successfully did something!' }); // Success notification
292
+ * ```
293
+ */
294
+ notify(opts: {
295
+ type: 'Error' | 'Info' | 'Success';
296
+ message: string;
297
+ }): Promise<void>;
298
+ /**
299
+ * Allows you to register your custom functions (callbacks) to be executed when certain events happen. This event
300
+ * includes detecting a new Selected Element: You can subscribe to the 'selectedelement' event to be notified whenever a
301
+ * different element is selected in the Webflow designer. This is useful if you want to perform specific actions or
302
+ * updates based on the currently selected element. A null element signifies that no element is selected.
303
+ * @param event - The name of the event to subscribe to, specifically 'selectedelement'.
304
+ * @param callback - A callback function that will be invoked when the subscribed event is triggered. The specific
305
+ * parameters passed to the callback depend on the event.
306
+ * @returns An Unsubscribe function that can be used to unsubscribe from the event and stop receiving notifications.
307
+ * @example
308
+ * ```ts
309
+ * // Subscribe to changes in the selected element
310
+ * const selectedElementCallback = (element) => {
311
+ * if (element) {
312
+ * console.log('Selected Element:', element);
313
+ * } else {
314
+ * console.log('No element is currently selected.');
315
+ * }
316
+ * };
317
+ *
318
+ * const unsubscribeSelectedElement = webflow.subscribe('selectedelement', selectedElementCallback);
319
+ * ```
320
+ */
321
+ subscribe(
322
+ event: 'selectedelement',
323
+ callback: (element: null | AnyElement) => void
324
+ ): Unsubscribe;
325
+ /**
326
+ * Allows you to register your custom functions (callbacks) to be executed when certain events happen. This event
327
+ * includes detecting a Breakpoint Change: Use the ‘mediaquery’ event to stay informed as the designer switches between
328
+ * breakpoints for desktops, tablets, or smartphones.
329
+ * @param event - The name of the event to subscribe to, specifically 'mediaquery'.
330
+ * @param callback - A callback function that will be invoked when the subscribed event is triggered. The specific
331
+ * parameters passed to the callback depend on the event.
332
+ * @returns An Unsubscribe function that can be used to unsubscribe from the event and stop receiving notifications.
333
+ * @example
334
+ * ```ts
335
+ * // Subscribe to changes in the media query breakpoint
336
+ * const mediaQueryCallback = (breakpoint) => {
337
+ * console.log('Media Query Breakpoint:', breakpoint);
338
+ * };
339
+ *
340
+ * const unsubscribeMediaQuery = webflow.subscribe('mediaquery', mediaQueryCallback);
341
+ * ```
342
+ */
343
+ subscribe(
344
+ event: 'mediaquery',
345
+ callback: (breakpoint: BreakpointId) => void
346
+ ): Unsubscribe;
347
+ /**
348
+ * Allows you to register your custom functions (callbacks) to be executed when certain events happen. This event
349
+ * includes detecting a Page Change: The 'currentpage' event allows you to respond when the user switches to a different
350
+ * page in the Webflow designer. This can be handy if you want to load additional data or perform actions
351
+ * specific to the selected page.
352
+ * @param event - The name of the event to subscribe to, specifically 'currentpage'.
353
+ * @param callback - A callback function that will be invoked when the subscribed event is triggered. The specific
354
+ * parameters passed to the callback depend on the event.
355
+ * @returns An Unsubscribe function that can be used to unsubscribe from the event and stop receiving notifications.
356
+ * @example
357
+ * ```ts
358
+ * // Subscribe to changes in the currently active page
359
+ * const currentPageCallback = (page) => {
360
+ * console.log('Current Page:', page);
361
+ * };
362
+ *
363
+ * const unsubscribeCurrentPage = webflow.subscribe('currentpage', currentPageCallback);
364
+ * ```
365
+ */
366
+ subscribe(event: 'currentpage', callback: (page: Page) => void): Unsubscribe;
367
+ getIdToken(): Promise<string>;
368
+ elementPresets: ElementPresets;
369
+ }
370
+
371
+ type Unsubscribe = () => void;
package/components.d.ts CHANGED
@@ -30,7 +30,7 @@ interface Component {
30
30
  * await component.setName("She-ro Component")
31
31
  * ```
32
32
  */
33
- setName(name: string): Promise<undefined>;
33
+ setName(name: string): Promise<void>;
34
34
  getRootElement(): Promise<null | AnyElement>;
35
35
  }
36
36
 
package/index.d.ts CHANGED
@@ -1,425 +1,7 @@
1
- /// <reference path="./brand.d.ts" />
2
- /// <reference path="./styles.d.ts" />
3
- /// <reference path="./pages.d.ts" />
4
- /// <reference path="./elements.d.ts" />
5
- /// <reference path="./element-presets.d.ts" />
6
- /// <reference path="./components.d.ts" />
7
- /// <reference path="./variables.d.ts" />
1
+ /// <reference path="./api.d.ts" />
8
2
 
9
3
  declare global {
10
4
  const webflow: WebflowApi;
11
5
  }
12
6
 
13
- interface WebflowApi {
14
- /**
15
- * Get metadata about the current Site.
16
- * @returns A Promise that resolves to a record containing information about the site that is open in the
17
- * Designer, with the following properties:
18
- * - siteId: the unique ID of the current Webflow site.
19
- * - siteName: the name of the current Webflow site.
20
- * - shortName: a shortened reference to the name of the current Webflow site.
21
- * @example
22
- * ```ts
23
- * const siteInfo = await webflow.getSiteInfo();
24
- * console.log('Site ID:', siteInfo.siteId);
25
- * console.log('Site Name:', siteInfo.siteName);
26
- * console.log('Shortened Site Name:', siteInfo.shortName);
27
- * ```
28
- */
29
- getSiteInfo(): Promise<{siteId: string; siteName: string; shortName: string}>;
30
- /**
31
- * Get the currently selected element in the Webflow designer.
32
- * @returns A promise that resolves to one of the following:
33
- * - null: If no element is currently selected in the designer
34
- * - AnyElement: an object representing the selected element, which can be of any type.
35
- * @example
36
- * ```ts
37
- * const selectedElement = await webflow.getSelectedElement();
38
- * if (selectedElement) {
39
- * // Handle the selected element
40
- * } else {
41
- * // No element is currently selected
42
- * }
43
- * ```
44
- */
45
- getSelectedElement(): Promise<null | AnyElement>;
46
- /**
47
- * Get the current media query breakpoint ID.
48
- * @returns A Promise that resolves to a BreakpointId which is a string representing the current media query
49
- * breakpoint. A BreakpointId is one of 'tiny', 'small', 'medium', 'main', 'large', 'xl', 'xxl'.
50
- * @example
51
- * ```ts
52
- * const breakpoint = await webflow.getMediaQuery();
53
- * console.log('Current Media Query:', breakpoint);
54
- * ```
55
- */
56
- getMediaQuery(): Promise<BreakpointId>;
57
- /**
58
- * Create a component by promoting a Root Element.
59
- * @param name - The name of the component.
60
- * @param rootElement - An Element that will become the Root Element of the Component.
61
- * @returns A Promise resolving to an object containing the newly created Component - with the id property.
62
- * @example
63
- * ```ts
64
- * const element = webflow.createDOM('div')
65
- * await webflow.registerComponent('Hero-Component', element)
66
- *
67
- * // Example Response
68
- * {id: '204d04de-bf48-5b5b-0ca8-6ec4c5364fd2'}
69
- * ```
70
- */
71
- registerComponent(
72
- name: string,
73
- root: AnyElement | ElementPreset<AnyElement> | Component
74
- ): Promise<Component>;
75
- /**
76
- * Delete a component from the Designer. If there are any instances of the Component within the site, they will
77
- * be converted to regular Elements.
78
- * @param component - The component object you wish to delete.
79
- * @returns A Promise resolving that resolves when the Component is deleted.
80
- * @example
81
- * ```ts
82
- * const element = webflow.createDOM('div')
83
- * const heroComponent = await webflow.registerComponent('Hero-Component', element)
84
- * await webflow.unregisterComponent(heroComponent)
85
- * ```
86
- */
87
- unregisterComponent(component: Component): Promise<null>;
88
- /**
89
- * Fetch all Site-scoped components definitions. In order to edit a component, you’ll need to get a specific
90
- * Component instance.
91
- * @returns A Promise resolving to an array containing all Components from the currently open site in the
92
- * Designer - with the id property.
93
- * @example
94
- * ```ts
95
- * const fetchedComponents = await webflow.getAllComponents();
96
- *
97
- * // Example Response
98
- * [
99
- * {id: "4a669354-353a-97eb-795c-4471b406e043"}
100
- * {id: 'd6e076e2-19a2-c4ae-9da3-ce3b0493b503'}
101
- * ]
102
- * ```
103
- */
104
- getAllComponents(): Promise<Array<Component>>;
105
- /**
106
- * Focus the designer on a Component. When a component is in focus, all Globals pertain specifically to that
107
- * Component, not the entire Site.
108
- * @param instance - A Component Instance that is present on the page. If there’s no current instance, you’ll
109
- * need to create one first.
110
- * @returns A Promise that resolves when the page switch is successful.
111
- * @example
112
- * ```ts
113
- * await webflow.enterComponent(heroComponentInstance);
114
- * ```
115
- */
116
- enterComponent(instance: ComponentElement): Promise<null>;
117
- /**
118
- * Return to the broader context of the entire site or page.
119
- * @returns A Promise that resolves when the page switch is successful.
120
- * @example
121
- * ```ts
122
- * await webflow.exitComponent();
123
- * ```
124
- */
125
- exitComponent(): Promise<null>;
126
- /**
127
- * Get Root element. When the designer is focused or "entered" into a Component, this method will get the
128
- * outermost element in the Component.
129
- * @returns The outermost element of the Page or Component.
130
- * @example
131
- * ```ts
132
- * // 🎉 Enter into Component 🎉
133
- * await webflow.enterComponent(heroComponentInstance)
134
- * const root = await webflow.getRootElement()
135
- *
136
- * // Example Response
137
- * {id: '204d04de-bf48-5b5b-0ca8-6ec4c5364fd2'}
138
- * ```
139
- */
140
- getRootElement(): Promise<null | AnyElement>;
141
- /**
142
- * Fetch an array of all elements present on the current page of the Designer. If the Designer is editing a
143
- * component, the elements returned are those present in that Component.
144
- * @returns A Promise that resolves to an array of AnyElement objects. AnyElement represents various element
145
- * types available in a Webflow project. Each element type corresponds to different types of HTML elements or
146
- * components that can be used within the designer. You can see a full list of supported elements in our
147
- * designer extensions typing file.
148
- * @example
149
- * ```ts
150
- * const allElements = await webflow.getAllElements()
151
- * const paragraphs = allElements.flatMap(el => el.type === 'Paragraph' ? [el] : [])
152
- * paragraphs.forEach(el => {
153
- * el.setTextContent('Hello')
154
- * el.save()
155
- * })
156
- * ```
157
- */
158
- getAllElements(): Promise<Array<AnyElement>>;
159
-
160
- /**
161
- * Creates a new style with the provided name.
162
- * @param name - The name for the new style.
163
- * @returns a Promise that resolves to the Style object representing the newly created style.
164
- * @example
165
- * ```ts
166
- * const newStyle = await webflow.createStyle('myNewStyle');
167
- * ```
168
- */
169
- createStyle(name: string): Promise<Style>;
170
- /**
171
- * Fetch a style by its name.
172
- * @param name - The name of the style to retrieve.
173
- * @returns A Promise that resolves to one of the following:
174
- * - null if no style with the given name is found.
175
- * - Style object representing the style with the specified name.
176
- * @example
177
- * ```ts
178
- * const styleName = 'myStyle';
179
- * const style = await webflow.getStyleByName(styleName);
180
- * if (style) {
181
- * // Style found, handle it
182
- * } else {
183
- * // Style not found
184
- * }
185
- * ```
186
- */
187
- getStyleByName(name: string): Promise<null | Style>;
188
- /**
189
- * Fetch an array of all styles available in the Webflow project.
190
- * @returns A Promise that resolves to an array of Style objects representing all the styles present on the
191
- * site that is open in the Designer.
192
- * @example
193
- * ```ts
194
- * const allStyles = await webflow.getAllStyles();
195
- * allStyles.forEach((style) => {
196
- * // Process each style
197
- * });
198
- * ```
199
- */
200
- getAllStyles(): Promise<Array<Style>>;
201
- /**
202
- * Fetch the currently active page in the Webflow designer.
203
- * @returns A Promise that resolves to a Page object representing the current page open in the Designer.
204
- * @example
205
- * ```ts
206
- * const currentPage = await webflow.getCurrentPage();
207
- * console.log('Current Page:', currentPage);
208
- * ```
209
- */
210
- getCurrentPage(): Promise<Page>;
211
- /**
212
- * Fetch an array of all pages and folders in the Webflow project.
213
- * @returns A Promise that resolves to an array of Page and Folder objects representing all the pages
214
- * and folders of the site that is open in the Designer.
215
- * @example
216
- * ```ts
217
- * const items = await webflow.getAllPagesAndFolders();
218
- * items.forEach((item) => {
219
- * // Process each page or folder
220
- * });
221
- * ```
222
- */
223
- getAllPagesAndFolders(): Promise<Array<Page | Folder>>;
224
- /**
225
- * Create a new folder within the current Webflow project.
226
- * @returns A Promise that resolves to a Folder object representing a newly created folder for the site open in
227
- * the Designer.
228
- * @example
229
- * ```ts
230
- * const newFolder = await webflow.createFolder();
231
- * // Handle the new folder
232
- * ```
233
- */
234
- createFolder(): Promise<Folder>;
235
- /**
236
- * Create a new Page within the current Webflow project.
237
- * @returns A Promise that resolves to a Page object representing a newly created page for the site open in the Designer.
238
- * @example
239
- * ```ts
240
- * const newPage = await webflow.createPage();
241
- * // Handle the new page
242
- * ```
243
- */
244
- createPage(): Promise<Page>;
245
- /**
246
- * @param page - The Page object representing the target page to switch to.
247
- * @returns A Promise that resolves when the page switch is successful.
248
- * @example
249
- * ```ts
250
- * const targetPage = <Get the target page>;
251
- * await webflow.switchPage(targetPage);
252
- * // Page switched successfully
253
- * ```
254
- */
255
- switchPage(page: Page): Promise<void>;
256
- /**
257
- * Render an Instance of the Component on a page.
258
- * @param component - The Component object you’d like to create an Instance of.
259
- * @returns A ComponentElement object better known as a Component Instance.
260
- * @example
261
- * ```ts
262
- * // 🎉 Create Component 🎉
263
- * const element = webflow.createDOM('div')
264
- * const heroComponent = await webflow.registerComponent('Hero-Component', element)
265
- * // 🎉 Create Component instance 🎉
266
- * const heroComponentInstance = webflow.createInstance(heroComponent);
267
- * ```
268
- */
269
- createInstance(component: Component): ComponentElement;
270
- /**
271
- * Creates a new StringElement.
272
- * @param text - The string you'd like to create.
273
- * @returns A StringElement object representing the newly created string.
274
- * @example
275
- * ```ts
276
- * const stringElement = webflow.createString("Hello world");
277
- * // add the string to a parent element (eg. a <div>)
278
- * parentElement.setChildren([stringElement]);
279
- * ```
280
- */
281
- createString(text: string): StringElement;
282
- /**
283
- * Create a custom HTML element with the specified tag.
284
- * @param tag - The HTML tag for the custom element.
285
- * @returns A DOMElement object representing the newly created custom element.
286
- * @example
287
- * ```ts
288
- * const newDiv = webflow.createDOM('div')
289
- * // Use the newDiv object
290
- * ```
291
- */
292
- createDOM(tag: string): DOMElement;
293
- /**
294
- * Creates a new heading element with the provided level (h1-h6).
295
- * @param tag - (1 | 2 | 3 | 4 | 5 | 6) - The heading level for the new heading element.
296
- * @returns HeadingElement object representing the new heading element.
297
- * @example
298
- * ```ts
299
- * const newH1 = webflow.createHeading(1)
300
- * // Use the newH1 object
301
- * ```
302
- */
303
- createHeading(tag: 1 | 2 | 3 | 4 | 5 | 6): HeadingElement;
304
- /**
305
- * Access the default variable collection.
306
- * @returns A Promise that resolves into a Collection.
307
- * @example
308
- * ```ts
309
- * const collection = webflow.getDefaultVariableCollection();
310
- * // This collection object can now be used to create variables or access variables within it
311
- * const variable = collection.getVariableByName('Space Cadet');
312
- * ```
313
- */
314
- getDefaultVariableCollection(): Promise<null | VariableCollection>;
315
- /**
316
- * Sets the extension size to one of predefined sizes or a custom size. If the specified custom size is larger than
317
- * the user's viewport size, the extension will default to the width/height of the browser's viewport.
318
- * @param size - The size to set the extension window to. One of 'default', 'comfortable', 'large', or an object
319
- * containing width and height keys.
320
- * @example
321
- * ```ts
322
- * await webflow.setExtensionSize("large") ;
323
- * // Perform actions for large window
324
- *
325
- * await webflow.setExtensionSize({width: 1000, height: 700}) ;
326
- * //Perform actions for this window size
327
- * ```
328
- */
329
- setExtensionSize(
330
- size: 'default' | 'comfortable' | 'large' | {width: number; height: number}
331
- ): Promise<null>;
332
- /**
333
- * Notifies the user with a message using a specific style. Error messages provide user's with the opportunity to
334
- * close the Designer Extension.
335
- * @param opts - An object containing the following notification options:
336
- * - type: The type of notification to display. One of 'Error', 'Info', 'Success'.
337
- * - message: The message to display in the notification.
338
- * @returns A Promise that resolves when the notification is displayed to the user.
339
- * @example
340
- * ```ts
341
- * webflow.notify({ type: 'Info', message: 'Great work!' }); // General notification
342
- * webflow.notify({ type: 'Error', message: 'Something went wrong, try again!' }); // Error notification
343
- * webflow.notify({ type: 'Success', message: 'Successfully did something!' }); // Success notification
344
- * ```
345
- */
346
- notify(opts: {
347
- type: 'Error' | 'Info' | 'Success';
348
- message: string;
349
- }): Promise<void>;
350
- /**
351
- * Allows you to register your custom functions (callbacks) to be executed when certain events happen. This event
352
- * includes detecting a new Selected Element: You can subscribe to the 'selectedelement' event to be notified whenever a
353
- * different element is selected in the Webflow designer. This is useful if you want to perform specific actions or
354
- * updates based on the currently selected element. A null element signifies that no element is selected.
355
- * @param event - The name of the event to subscribe to, specifically 'selectedelement'.
356
- * @param callback - A callback function that will be invoked when the subscribed event is triggered. The specific
357
- * parameters passed to the callback depend on the event.
358
- * @returns An Unsubscribe function that can be used to unsubscribe from the event and stop receiving notifications.
359
- * @example
360
- * ```ts
361
- * // Subscribe to changes in the selected element
362
- * const selectedElementCallback = (element) => {
363
- * if (element) {
364
- * console.log('Selected Element:', element);
365
- * } else {
366
- * console.log('No element is currently selected.');
367
- * }
368
- * };
369
- *
370
- * const unsubscribeSelectedElement = webflow.subscribe('selectedelement', selectedElementCallback);
371
- * ```
372
- */
373
- subscribe(
374
- event: 'selectedelement',
375
- callback: (element: null | AnyElement) => void
376
- ): Unsubscribe;
377
- /**
378
- * Allows you to register your custom functions (callbacks) to be executed when certain events happen. This event
379
- * includes detecting a Breakpoint Change: Use the ‘mediaquery’ event to stay informed as the designer switches between
380
- * breakpoints for desktops, tablets, or smartphones.
381
- * @param event - The name of the event to subscribe to, specifically 'mediaquery'.
382
- * @param callback - A callback function that will be invoked when the subscribed event is triggered. The specific
383
- * parameters passed to the callback depend on the event.
384
- * @returns An Unsubscribe function that can be used to unsubscribe from the event and stop receiving notifications.
385
- * @example
386
- * ```ts
387
- * // Subscribe to changes in the media query breakpoint
388
- * const mediaQueryCallback = (breakpoint) => {
389
- * console.log('Media Query Breakpoint:', breakpoint);
390
- * };
391
- *
392
- * const unsubscribeMediaQuery = webflow.subscribe('mediaquery', mediaQueryCallback);
393
- * ```
394
- */
395
- subscribe(
396
- event: 'mediaquery',
397
- callback: (breakpoint: BreakpointId) => void
398
- ): Unsubscribe;
399
- /**
400
- * Allows you to register your custom functions (callbacks) to be executed when certain events happen. This event
401
- * includes detecting a Page Change: The 'currentpage' event allows you to respond when the user switches to a different
402
- * page in the Webflow designer. This can be handy if you want to load additional data or perform actions
403
- * specific to the selected page.
404
- * @param event - The name of the event to subscribe to, specifically 'currentpage'.
405
- * @param callback - A callback function that will be invoked when the subscribed event is triggered. The specific
406
- * parameters passed to the callback depend on the event.
407
- * @returns An Unsubscribe function that can be used to unsubscribe from the event and stop receiving notifications.
408
- * @example
409
- * ```ts
410
- * // Subscribe to changes in the currently active page
411
- * const currentPageCallback = (page) => {
412
- * console.log('Current Page:', page);
413
- * };
414
- *
415
- * const unsubscribeCurrentPage = webflow.subscribe('currentpage', currentPageCallback);
416
- * ```
417
- */
418
- subscribe(event: 'currentpage', callback: (page: Page) => void): Unsubscribe;
419
- getIdToken(): Promise<string>;
420
- elementPresets: ElementPresets;
421
- }
422
-
423
- type Unsubscribe = () => undefined;
424
-
425
7
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webflow/designer-extension-typings",
3
- "version": "0.2.0-beta.1",
3
+ "version": "0.2.0-beta.2",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "description": "Typings for the Webflow Designer Extension API",
6
6
  "main": "",
package/pages.d.ts CHANGED
@@ -181,7 +181,7 @@ interface Page {
181
181
  * await myPage.setOpenGraphTitle("New OG Title");
182
182
  * ```
183
183
  */
184
- setOpenGraphTitlegTitle(title: string): Promise<null>;
184
+ setOpenGraphTitle(title: string): Promise<null>;
185
185
  /**
186
186
  * Checks if the page uses its description as the Open Graph description.
187
187
  * @example
@@ -388,17 +388,6 @@ interface Page {
388
388
  * ```
389
389
  */
390
390
  isHomepage(): Promise<boolean>;
391
- /**
392
- * Retrieves the full page URL upon publish
393
- * @returns A Promise that resolves to a string representing the publish URL for a Page object
394
- * @example
395
- * ```ts
396
- * let currentPage = await webflow.getCurrentPage();
397
- * let currentPageUrl = await currentPage.getPublishUrl();
398
- * console.log("Publish URL for current page:", currentPageUrl);
399
- * ```
400
- */
401
- getPublishUrl(): Promise<string>;
402
391
  }
403
392
 
404
393
  type FolderId = string;
package/styles.d.ts CHANGED
@@ -34,11 +34,11 @@ interface Style {
34
34
  setProperties(
35
35
  props: PropertyMap,
36
36
  options?: BreakpointAndPseudo
37
- ): Promise<undefined>;
37
+ ): Promise<void>;
38
38
  removeProperties(
39
39
  props: Array<StyleProperty>,
40
40
  options?: BreakpointAndPseudo
41
- ): Promise<undefined>;
41
+ ): Promise<void>;
42
42
  /**
43
43
  * Retrieve the value of a specific property of the style.
44
44
  * @param prop - The name of the property to retrieve.
@@ -69,11 +69,11 @@ interface Style {
69
69
  prop: p,
70
70
  value: NonNullable<PropertyMap[p]>,
71
71
  options?: BreakpointAndPseudo
72
- ): Promise<undefined>;
72
+ ): Promise<void>;
73
73
  removeProperty(
74
74
  prop: StyleProperty,
75
75
  options?: BreakpointAndPseudo
76
- ): Promise<undefined>;
76
+ ): Promise<void>;
77
77
  /**
78
78
  * Removes all CSS properties from the Style.
79
79
  * @example
@@ -81,7 +81,7 @@ interface Style {
81
81
  * await myStyle.removeAllProperties();
82
82
  * ```
83
83
  */
84
- removeAllProperties(): Promise<undefined>;
84
+ removeAllProperties(): Promise<void>;
85
85
  }
86
86
 
87
87
  type StyleId = string;