File tree Expand file tree Collapse file tree 5 files changed +54
-0
lines changed
designer-extension-typings Expand file tree Collapse file tree 5 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ export const permissionsMap: PermissionsMap = {
5353 getAllComponents : { permissions : [ 'canAccessCanvas' ] } ,
5454 getComponentByName : { permissions : [ 'canAccessCanvas' ] } ,
5555 getComponentByNameAndGroup : { permissions : [ 'canAccessCanvas' ] } ,
56+ getCurrentComponent : { permissions : [ 'canAccessCanvas' ] } ,
5657 searchComponents : { permissions : [ 'canAccessCanvas' ] } ,
5758 getInstanceCount : { permissions : [ 'canAccessCanvas' ] } ,
5859 getVariants : { permissions : [ 'canAccessCanvas' ] } ,
@@ -97,6 +98,7 @@ export const permissionsMap: PermissionsMap = {
9798 getAllElements : { permissions : [ 'canAccessCanvas' ] } ,
9899 getRootElement : { permissions : [ 'canAccessCanvas' ] } ,
99100 remove : { permissions : [ 'canDesign' ] } ,
101+ getParentComponent : { permissions : [ 'canAccessCanvas' ] } ,
100102 } ,
101103
102104 // Image Elements
Original file line number Diff line number Diff line change @@ -185,6 +185,21 @@ interface WebflowApi {
185185 * ```
186186 */
187187 getComponentByName ( a : string , b ?: string ) : Promise < Component > ;
188+ /**
189+ * Retrieves the component that is currently being edited.
190+ * @returns A Promise that resolves to the current component, or null if no component is currently being edited.
191+ * @example
192+ * ```ts
193+ * const component = await webflow.getCurrentComponent();
194+ * if (component) {
195+ * const name = await component.getName();
196+ * console.log(`Currently editing component: ${name}`);
197+ * } else {
198+ * console.log('Not currently editing a component.');
199+ * }
200+ * ```
201+ */
202+ getCurrentComponent ( ) : Promise < Component | null > ;
188203 /**
189204 * Searches for Components by name
190205 * @returns A Promise that resolves to an array or objects with information about matching Components, not the `Component` objects themselves.
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ interface WebflowElement {
2222 remove ( this : { id : FullElementId } ) : Promise < null > ;
2323 readonly before : InsertOrMoveElement ;
2424 readonly after : InsertOrMoveElement ;
25+ getParentComponent ( this : { id : FullElementId } ) : Promise < Component | null > ;
2526}
2627
2728interface CustomAttributes {
Original file line number Diff line number Diff line change @@ -64,6 +64,23 @@ export const Components = {
6464 console . log ( marketingHero . id ) ;
6565 } ,
6666
67+ getCurrentComponent : async ( ) => {
68+ // Get the component currently being edited
69+ const component = await webflow . getCurrentComponent ( ) ;
70+
71+ if ( component ) {
72+ const name = await component . getName ( ) ;
73+ console . log ( `Currently editing component: ${ name } ` ) ;
74+
75+ // Get all elements inside the active component
76+ const root = await component . getRootElement ( ) ;
77+ const children = await root . getChildren ( ) ;
78+ console . log ( `Root has ${ children . length } child element(s)` ) ;
79+ } else {
80+ console . log ( 'Not currently editing a component.' ) ;
81+ }
82+ } ,
83+
6784 searchComponents : async ( ) => {
6885 const heroes = await webflow . searchComponents ( { q : 'Hero' } ) ;
6986 console . log ( heroes ) ;
Original file line number Diff line number Diff line change @@ -79,6 +79,25 @@ export const Elements = {
7979 // Remove the selected element
8080 await el ?. remove ( )
8181 } ,
82+
83+ getParentComponent : async ( ) => {
84+ // Get Selected Element
85+ const element = await webflow . getSelectedElement ( )
86+
87+ if ( element ) {
88+ // Get the component that directly contains the element
89+ const parentComponent = await element . getParentComponent ( )
90+
91+ if ( parentComponent ) {
92+ const name = await parentComponent . getName ( )
93+ console . log ( `Element is inside component: ${ name } ` )
94+ } else {
95+ console . log ( 'Element is not inside a component.' )
96+ }
97+ } else {
98+ console . log ( 'No element is currently selected.' )
99+ }
100+ } ,
82101 } ,
83102
84103 // Element Creation
You can’t perform that action at this time.
0 commit comments