1234567891011121314151617181920212223242526272829303132333435363738 |
- async function handleCreateElement(block, { refData }) {
- if (!this.activeTab.id) throw new Error('no-tab');
- const { data } = block;
- const preloadScriptsPromise = await Promise.allSettled(
- data.preloadScripts.map((item) => {
- if (!item.src.startsWith('http'))
- return Promise.reject(new Error('Invalid URL'));
- return fetch(item.src)
- .then((response) => response.text())
- .then((result) => ({ type: item.type, script: result }));
- })
- );
- const preloadScripts = preloadScriptsPromise.reduce((acc, item) => {
- if (item.status === 'rejected') return acc;
- acc.push(item.value);
- return acc;
- }, []);
- data.preloadScripts = preloadScripts;
- const payload = { ...block, data, refData: { variables: {} } };
- if (data.javascript.includes('automaRefData')) {
- payload.refData = { ...refData, secrets: {} };
- }
- await this._sendMessageToTab(payload, {}, data.runBeforeLoad ?? false);
- return {
- data: '',
- nextBlockId: this.getBlockConnections(block.id),
- };
- }
- export default handleCreateElement;
|