mirror of
https://github.com/elementor/hello-theme.git
synced 2026-08-01 16:00:20 +08:00
Some checks failed
Build / Build theme (push) Failing after 1s
Lint / ESLint (push) Failing after 0s
PHPUnit / File Diff (push) Failing after 1s
Lint / PHPCS (push) Failing after 41s
PHPUnit / PHPUnit - WordPress 6.8 - PHP version 7.4 (push) Has been skipped
PHPUnit / PHPUnit - WordPress 6.9 - PHP version 7.4 (push) Has been skipped
PHPUnit / PHPUnit - WordPress latest - PHP version 7.4 (push) Has been skipped
PHPUnit / PHPUnit - WordPress nightly - PHP version 7.4 (push) Has been skipped
PHPUnit / PHPUnit - WordPress 6.8 - PHP version 8.0 (push) Has been skipped
PHPUnit / PHPUnit - WordPress 6.9 - PHP version 8.0 (push) Has been skipped
PHPUnit / PHPUnit - WordPress latest - PHP version 8.0 (push) Has been skipped
PHPUnit / PHPUnit - WordPress nightly - PHP version 8.0 (push) Has been skipped
PHPUnit / PHPUnit - WordPress 6.8 - PHP version 8.1 (push) Has been skipped
PHPUnit / PHPUnit - WordPress 6.9 - PHP version 8.1 (push) Has been skipped
PHPUnit / PHPUnit - WordPress latest - PHP version 8.1 (push) Has been skipped
PHPUnit / PHPUnit - WordPress nightly - PHP version 8.1 (push) Has been skipped
PHPUnit / PHPUnit - WordPress 6.8 - PHP version 8.2 (push) Has been skipped
PHPUnit / PHPUnit - WordPress 6.9 - PHP version 8.2 (push) Has been skipped
PHPUnit / PHPUnit - WordPress latest - PHP version 8.2 (push) Has been skipped
PHPUnit / PHPUnit - WordPress nightly - PHP version 8.2 (push) Has been skipped
PHPUnit / PHPUnit - WordPress 6.8 - PHP version 8.3 (push) Has been skipped
PHPUnit / PHPUnit - WordPress 6.9 - PHP version 8.3 (push) Has been skipped
PHPUnit / PHPUnit - WordPress latest - PHP version 8.3 (push) Has been skipped
PHPUnit / PHPUnit - WordPress nightly - PHP version 8.3 (push) Has been skipped
PHPUnit / PHPUnit - Test Results (push) Successful in 2s
* Setup prettier * Fix lint/format issues
65 lines
1.5 KiB
TypeScript
65 lines
1.5 KiB
TypeScript
import { $eType, ElementorType } from '../types/types.ts';
|
|
|
|
/**
|
|
* Add element to the page using model and parent container.
|
|
* @param {Object} props
|
|
* @param {Object} props.model
|
|
* @param {string | null} props.container
|
|
* @param {boolean} props.isContainerASection
|
|
* @return {string | undefined}
|
|
*/
|
|
|
|
let parent: unknown;
|
|
let elementor: ElementorType;
|
|
let $e: $eType;
|
|
export const addElement = (props: {
|
|
model: unknown;
|
|
container: null | string;
|
|
isContainerASection: boolean;
|
|
}): string | undefined => {
|
|
if (props.container) {
|
|
parent = elementor.getContainer(props.container);
|
|
} else {
|
|
// If a `container` isn't supplied - create a new Section.
|
|
parent = $e.run('document/elements/create', {
|
|
model: { elType: 'section' },
|
|
columns: 1,
|
|
container: elementor.getContainer('document'),
|
|
});
|
|
|
|
props.isContainerASection = true;
|
|
}
|
|
|
|
if (
|
|
props.isContainerASection &&
|
|
'object' === typeof parent &&
|
|
'children' in parent
|
|
) {
|
|
parent = parent.children[0];
|
|
}
|
|
|
|
const element = $e.run('document/elements/create', {
|
|
model: props.model,
|
|
container: parent,
|
|
});
|
|
|
|
if (
|
|
'object' === typeof element &&
|
|
'id' in element &&
|
|
'string' === typeof element.id
|
|
) {
|
|
return element.id;
|
|
}
|
|
return undefined;
|
|
};
|
|
|
|
/**
|
|
* Make an Elementor element CSS selector using Container ID.
|
|
*
|
|
* @param {string} id - Container ID.
|
|
*
|
|
* @return {string} css selector
|
|
*/
|
|
export const getElementSelector = (id: string) => {
|
|
return `[data-id = "${id}"]`;
|
|
};
|