@webflow/designer-extension-typings 2.0.29 → 2.0.31

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/components.d.ts CHANGED
@@ -44,10 +44,214 @@ interface Component {
44
44
  * ```
45
45
  */
46
46
  getInstanceCount(): Promise<number>;
47
+
48
+ /**
49
+ * Get all variants for this component, including the base variant.
50
+ * Variants are returned in display order: base variant first (always `id: 'base'`),
51
+ * followed by style variants in the order they appear in the component's variant field.
52
+ *
53
+ * @returns A Promise resolving to an array of Variant objects. Each variant includes:
54
+ * - `id`: The unique identifier for the variant
55
+ * - `name`: The display name of the variant
56
+ * - `isSelected`: Indicates which variant is currently active in the Designer's editing context.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const component = (await webflow.getAllComponents())[0];
61
+ * const variants = await component.getVariants();
62
+ * console.log(variants);
63
+ * // [{ id: 'base', name: 'Primary', isSelected: true }, { id: 'xxxx', name: 'Secondary', isSelected: false }]
64
+ *
65
+ * // Find which variant is currently being edited
66
+ * const activeVariant = variants.find(v => v.isSelected);
67
+ * console.log(`Currently editing: ${activeVariant.name}`);
68
+ * ```
69
+ */
70
+ getVariants(): Promise<Variant[]>;
71
+
72
+ /**
73
+ * Create a new variant for this component.
74
+ * @param options - The name for the new variant and optional selection behavior
75
+ * @returns A promise that resolves to the newly created Variant.
76
+ * @example
77
+ * ```ts
78
+ * const variant = await heroComponent.createVariant({ name: "Dark Mode" });
79
+ * console.log(variant.name); // "Dark Mode"
80
+ * ```
81
+ */
82
+ createVariant(options: CreateVariantOptions): Promise<Variant>;
83
+
84
+ /**
85
+ * Duplicate an existing variant. Overload: pass sourceVariantId as second argument.
86
+ * @param options - Options for the duplicate (name base, isSelected)
87
+ * @param sourceVariantId - The variant ID to duplicate, or 'base' to duplicate the base variant
88
+ * @returns A promise that resolves to the newly created duplicate Variant.
89
+ * @example
90
+ * ```ts
91
+ * const duplicate = await heroComponent.createVariant({ name: "Copy" }, variants[1].id);
92
+ * const baseCopy = await heroComponent.createVariant({ name: "Base Copy" }, "base");
93
+ * ```
94
+ */
95
+ createVariant(
96
+ options: CreateVariantOptions,
97
+ sourceVariantId: string
98
+ ): Promise<Variant>;
99
+
100
+ /**
101
+ * Get the currently selected variant for this component.
102
+ * The selected variant reflects the Designer's current editing
103
+ * context (which variant frame is active in Component Canvas).
104
+ *
105
+ * @returns A promise that resolves to the currently selected Variant.
106
+ * If no variant is explicitly selected, returns the base variant.
107
+ * Note: The returned variant will always have `isSelected: true`
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * const variant = await heroComponent.getSelectedVariant();
112
+ * console.log(variant.name); // "Primary"
113
+ * console.log(variant.isSelected); // always true
114
+ * ```
115
+ */
116
+ getSelectedVariant(): Promise<Variant>;
117
+
118
+ /**
119
+ * Set the selected variant for this component in the Designer.
120
+ * Accepts an options object ({ name } or { id }) or a string shorthand for variant ID.
121
+ * Use 'base' or { id: 'base' } to select the base variant.
122
+ * @param options - Variant to select by name, by id, or string shorthand for id
123
+ * @returns A promise that resolves when the variant is selected.
124
+ * @example
125
+ * ```ts
126
+ * await heroComponent.setSelectedVariant('variant-dark');
127
+ * await heroComponent.setSelectedVariant({ name: 'Dark Mode' });
128
+ * await heroComponent.setSelectedVariant({ id: 'base' });
129
+ * ```
130
+ */
131
+ setSelectedVariant(
132
+ options: SetSelectedVariantOptions | string
133
+ ): Promise<null>;
134
+
135
+ /**
136
+ * Get the settings (name, group, description) of a component.
137
+ * @returns A Promise resolving to the component's settings.
138
+ * @example
139
+ * ```ts
140
+ * const settings = await component.getSettings();
141
+ * console.log(settings.name); // 'Hero Section'
142
+ * console.log(settings.group); // 'Sections'
143
+ * console.log(settings.description); // 'A reusable hero'
144
+ * ```
145
+ */
146
+ getSettings(): Promise<ComponentSettings>;
147
+
148
+ /**
149
+ * Update one or more settings on a component. All fields are optional.
150
+ * Updates happen immediately without requiring an explicit save().
151
+ * @param settings - A partial object of settings to update.
152
+ * @returns A Promise that resolves when the update is complete.
153
+ * @example
154
+ * ```ts
155
+ * await component.setSettings({ group: 'Legacy' }); // Set the group
156
+ * await component.setSettings({ name: 'Hero v2', description: 'Redesigned hero' }); // Set the name and description
157
+ * ```
158
+ */
159
+ setSettings(settings: Partial<ComponentSettings>): Promise<null>;
160
+ }
161
+
162
+ /**
163
+ * Options for creating a new variant or duplicating an existing one.
164
+ */
165
+ interface CreateVariantOptions {
166
+ /** The name for the new variant (required for create, optional base for duplicate) */
167
+ name: string;
168
+ /** Whether to select this variant after creation (optional, defaults to false) */
169
+ isSelected?: boolean;
170
+ }
171
+
172
+ /** Select variant by display name. */
173
+ interface SetSelectedVariantByName {
174
+ name: string;
175
+ }
176
+
177
+ /** Select variant by ID. */
178
+ interface SetSelectedVariantById {
179
+ id: string;
180
+ }
181
+
182
+ /** Options for setSelectedVariant — select by name or by id. */
183
+ type SetSelectedVariantOptions =
184
+ | SetSelectedVariantByName
185
+ | SetSelectedVariantById;
186
+
187
+ interface Variant {
188
+ /** The variant ID. The base variant always has id 'base'. */
189
+ readonly id: string;
190
+ /** The display name of the variant. */
191
+ readonly name: string;
192
+ /**
193
+ * Indicates which variant is currently active in the Designer's editing context.
194
+ * This reflects global Designer state (which variant frame is selected in Component Canvas),
195
+ * not the component definition.
196
+ * The base variant has `isSelected: true` when no variant is active.
197
+ */
198
+ readonly isSelected: boolean;
199
+ }
200
+
201
+ /**
202
+ * Settings for a component, including name, group, and description.
203
+ */
204
+ interface ComponentSettings {
205
+ /** The name of the component */
206
+ name: string;
207
+ /** The group/folder the component belongs to (empty string if not set) */
208
+ group: string;
209
+ /** The description of the component (empty string if not set) */
210
+ description: string;
47
211
  }
48
212
 
49
213
  type ComponentId = string;
50
214
 
215
+ /** Library info for an imported library component. */
216
+ interface ComponentLibraryInfo {
217
+ /** The library's display name. */
218
+ name: string | null;
219
+ /** The library's identifier. */
220
+ id: string;
221
+ }
222
+
223
+ /** A single result returned by {@link webflow.searchComponents}. */
224
+ interface ComponentSearchResult {
225
+ /** The component's unique identifier. */
226
+ id: ComponentId;
227
+ /** Display name of the component. */
228
+ name: string;
229
+ /** Group/folder the component belongs to. */
230
+ group: string;
231
+ /** Component description. */
232
+ description: string;
233
+ /** Number of instances used across the site. */
234
+ instances: number;
235
+ /**
236
+ * Whether the current user can edit this component.
237
+ * Always `false` for library and code components.
238
+ * For site components, depends on the user's `canModifyComponents` permission.
239
+ */
240
+ canEdit: boolean;
241
+ /** Library info if this is an imported library component, otherwise `null`. */
242
+ library: ComponentLibraryInfo | null;
243
+ }
244
+
245
+ /** Options for {@link webflow.searchComponents}. */
246
+ interface SearchComponentsOptions {
247
+ /**
248
+ * Optional search query.
249
+ * Uses the same fuzzy search (FlexSearch, `tokenize: 'full'`) as the Components panel.
250
+ * When omitted, all components are returned in panel order.
251
+ */
252
+ q?: string;
253
+ }
254
+
51
255
  /**
52
256
  * Options for creating a blank component.
53
257
  */
@@ -58,4 +262,11 @@ interface ComponentOptions {
58
262
  group?: string;
59
263
  /** A description for the component (optional) */
60
264
  description?: string;
265
+ /**
266
+ * Determines if the source element is replaced in the canvas by a
267
+ * new instance of the created component after conversion.
268
+ * Only applies when a canvas element is supplied as the `root` argument.
269
+ * @default true
270
+ */
271
+ replace?: boolean;
61
272
  }
@@ -37,6 +37,7 @@ type ElementPresets = {
37
37
  CommerceCheckoutAdditionalInfoSummaryWrapper: ElementPreset<CommerceCheckoutAdditionalInfoSummaryWrapperElement>;
38
38
  CommerceDownloadsWrapper: ElementPreset<CommerceDownloadsWrapperElement>;
39
39
  DropdownWrapper: ElementPreset<DropdownWrapperElement>;
40
+ DropTarget: ElementPreset<DropTargetElement>;
40
41
  DynamoWrapper: ElementPreset<DynamoWrapperElement>;
41
42
  HtmlEmbed: ElementPreset<HtmlEmbedElement>;
42
43
  Video: ElementPreset<VideoElement>;
@@ -104,4 +105,5 @@ type ElementPresets = {
104
105
  LayoutFooterDark: ElementPreset<SectionElement>;
105
106
  LayoutFooterLight: ElementPreset<SectionElement>;
106
107
  LayoutFooterSubscribe: ElementPreset<SectionElement>;
108
+ Slot: ElementPreset<SlotElement>;
107
109
  };
@@ -0,0 +1,68 @@
1
+ // This file was automatically generated. See designer-extensions docs.
2
+
3
+ type BindableValueType =
4
+ | 'string'
5
+ | 'textContent'
6
+ | 'richText'
7
+ | 'boolean'
8
+ | 'color'
9
+ | 'date'
10
+ | 'link'
11
+ | 'url'
12
+ | 'email'
13
+ | 'phone'
14
+ | 'file'
15
+ | 'videoUrl'
16
+ | 'video'
17
+ | 'image'
18
+ | 'imageAsset'
19
+ | 'cmsImage'
20
+ | 'imageSet'
21
+ | 'number'
22
+ | 'enum'
23
+ | 'option'
24
+ | 'slot'
25
+ | 'reference'
26
+ | 'referenceSet'
27
+ | 'variant'
28
+ | 'filter'
29
+ | 'sort'
30
+ | 'selectedItems'
31
+ | 'visibility'
32
+ | 'booleanFilter'
33
+ | 'altText'
34
+ | 'id';
35
+
36
+ type PropType =
37
+ | 'textContent'
38
+ | 'string'
39
+ | 'richText'
40
+ | 'link'
41
+ | 'image'
42
+ | 'video'
43
+ | 'number'
44
+ | 'boolean'
45
+ | 'variant'
46
+ | 'slot'
47
+ | 'id'
48
+ | 'altText'
49
+ | 'booleanFilter'
50
+ | 'visibility'
51
+ | 'filter'
52
+ | 'sort'
53
+ | 'selectedItems';
54
+
55
+ type CmsFieldType =
56
+ | 'plainText'
57
+ | 'email'
58
+ | 'phone'
59
+ | 'url'
60
+ | 'date'
61
+ | 'option'
62
+ | 'number'
63
+ | 'color'
64
+ | 'boolean'
65
+ | 'image'
66
+ | 'file'
67
+ | 'video'
68
+ | 'richText';
@@ -0,0 +1,60 @@
1
+ interface PropBindableSource {
2
+ sourceType: 'prop';
3
+ propId: string;
4
+ propName: string;
5
+ propGroup: string | null;
6
+ valueType: BindableValueType;
7
+ bindableTo: readonly BindableValueType[];
8
+ }
9
+
10
+ interface CmsBindableSource {
11
+ sourceType: 'cms';
12
+ collectionId: string;
13
+ collectionName: string;
14
+ fieldId: string;
15
+ fieldName: string;
16
+ fieldGroup: string | null;
17
+ fieldType: CmsFieldType;
18
+ valueType: BindableValueType;
19
+ bindableTo: readonly BindableValueType[];
20
+ }
21
+
22
+ interface PageBindableSource {
23
+ sourceType: 'page';
24
+ fieldKey: string;
25
+ fieldName: string;
26
+ valueType: BindableValueType;
27
+ bindableTo: readonly BindableValueType[];
28
+ }
29
+
30
+ interface LocaleBindableSource {
31
+ sourceType: 'locale';
32
+ fieldKey: string;
33
+ fieldName: string;
34
+ fieldType: 'string';
35
+ valueType: BindableValueType;
36
+ bindableTo: readonly BindableValueType[];
37
+ }
38
+
39
+ interface LocaleItemBindableSource {
40
+ sourceType: 'localeItem';
41
+ fieldKey: string;
42
+ fieldName: string;
43
+ fieldType: 'string';
44
+ valueType: BindableValueType;
45
+ bindableTo: readonly BindableValueType[];
46
+ }
47
+
48
+ type BindableSource =
49
+ | PropBindableSource
50
+ | CmsBindableSource
51
+ | PageBindableSource
52
+ | LocaleBindableSource
53
+ | LocaleItemBindableSource;
54
+
55
+ interface SearchBindableSourcesOptions {
56
+ /** Filter to sources compatible with a specific element setting key (e.g., "altText", "src", "domId") */
57
+ settingKey?: string;
58
+ /** Filter to sources that produce a specific value type (e.g., "string", "imageAsset") */
59
+ valueType?: BindableValueType;
60
+ }