forked from onlook-dev/onlook
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/onlook-dev/onlook into tran…
…slation_zh * 'main' of https://github.com/onlook-dev/onlook: Fix port taken appearing on error (onlook-dev#1457) feat: Add properties panel (onlook-dev#1276) Show layers for selected window only (onlook-dev#1446) Update import warning (onlook-dev#1456) feat: Improve port conflict handling (onlook-dev#1397) Verifying and adding custom domain pt.3 (onlook-dev#1455) Support custom domain pt.2 (onlook-dev#1454) Support publishing to custom domain (onlook-dev#1453) Clean up custom domains (onlook-dev#1452) Handle creating custom domains (onlook-dev#1447)
- Loading branch information
Showing
63 changed files
with
3,586 additions
and
1,438 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import * as t from '@babel/types'; | ||
import { | ||
type NodeProps, | ||
type PropsParsingResult, | ||
PropsType, | ||
type TemplateNode, | ||
} from '@onlook/models/element'; | ||
import { readCodeBlock } from '.'; | ||
import { parseJsxCodeBlock } from './helpers'; | ||
|
||
export async function getTemplateNodeProps( | ||
templateNode: TemplateNode, | ||
): Promise<PropsParsingResult> { | ||
const codeBlock = await readCodeBlock(templateNode); | ||
if (codeBlock == null) { | ||
console.error(`Failed to read code block: ${templateNode.path}`); | ||
return { type: 'error', reason: 'Code block could not be read.' }; | ||
} | ||
const ast = parseJsxCodeBlock(codeBlock); | ||
|
||
if (!ast) { | ||
return { type: 'error', reason: 'AST could not be parsed.' }; | ||
} | ||
|
||
return getNodeAttributes(ast); | ||
} | ||
|
||
function getNodeAttributes(node: t.JSXElement): PropsParsingResult { | ||
try { | ||
const openingElement = node.openingElement; | ||
const props: NodeProps[] = []; | ||
|
||
openingElement.attributes.forEach((attr) => { | ||
if ( | ||
!t.isJSXAttribute(attr) || | ||
attr.name.name === 'className' || | ||
attr.name.name === 'data-oid' | ||
) { | ||
return; | ||
} | ||
|
||
const attrName = attr.name.name; | ||
let attrValue: boolean | string | number = true; | ||
let attrType: PropsType = PropsType.Code; | ||
|
||
if (attr.value) { | ||
if (t.isStringLiteral(attr.value)) { | ||
attrValue = attr.value.value; | ||
attrType = PropsType.String; | ||
} else if (t.isJSXExpressionContainer(attr.value)) { | ||
const expr = attr.value.expression; | ||
if (t.isBooleanLiteral(expr)) { | ||
attrValue = expr.value; | ||
attrType = PropsType.Boolean; | ||
} else if (t.isStringLiteral(expr)) { | ||
attrValue = expr.value; | ||
attrType = PropsType.String; | ||
} else if (t.isNumericLiteral(expr)) { | ||
attrValue = expr.value; | ||
attrType = PropsType.Number; | ||
} else { | ||
attrValue = `{${expr.type}}`; | ||
attrType = PropsType.Code; | ||
} | ||
} else { | ||
attrValue = `Unsupported type: ${attr.value.type}`; | ||
attrType = PropsType.Code; | ||
} | ||
} else { | ||
attrType = PropsType.Boolean; | ||
} | ||
|
||
props.push({ key: attrName, value: attrValue, type: attrType }); | ||
}); | ||
|
||
return { | ||
type: 'props', | ||
props, | ||
}; | ||
} catch (error) { | ||
console.error('Failed to parse component props:', error); | ||
return { | ||
type: 'error', | ||
reason: 'Failed to parse component props.', | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,47 @@ | ||
import { MainChannels } from '@onlook/models/constants'; | ||
import type { PublishRequest, PublishResponse, UnpublishRequest } from '@onlook/models/hosting'; | ||
import { ipcMain } from 'electron'; | ||
import hostingManager from '../hosting'; | ||
import { | ||
createDomainVerification, | ||
getCustomDomains, | ||
getOwnedDomains, | ||
verifyDomain, | ||
} from '../hosting/domains'; | ||
|
||
export function listenForHostingMessages() { | ||
ipcMain.handle(MainChannels.START_DEPLOYMENT, async (e: Electron.IpcMainInvokeEvent, args) => { | ||
const { folderPath, buildScript, urls, skipBuild } = args; | ||
return await hostingManager.deploy(folderPath, buildScript, urls, skipBuild); | ||
}); | ||
|
||
ipcMain.handle( | ||
MainChannels.GET_CUSTOM_DOMAINS, | ||
async (e: Electron.IpcMainInvokeEvent, args) => { | ||
return await hostingManager.getCustomDomains(); | ||
MainChannels.PUBLISH_TO_DOMAIN, | ||
async (_e: Electron.IpcMainInvokeEvent, args: PublishRequest): Promise<PublishResponse> => { | ||
return await hostingManager.publish(args); | ||
}, | ||
); | ||
|
||
ipcMain.handle( | ||
MainChannels.UNPUBLISH_HOSTING_ENV, | ||
async (e: Electron.IpcMainInvokeEvent, args) => { | ||
MainChannels.UNPUBLISH_DOMAIN, | ||
async ( | ||
e: Electron.IpcMainInvokeEvent, | ||
args: UnpublishRequest, | ||
): Promise<PublishResponse> => { | ||
const { urls } = args; | ||
return await hostingManager.unpublish(urls); | ||
}, | ||
); | ||
|
||
ipcMain.handle( | ||
MainChannels.CREATE_DOMAIN_VERIFICATION, | ||
async (_e: Electron.IpcMainInvokeEvent, args) => { | ||
const { domain } = args; | ||
return await createDomainVerification(domain); | ||
}, | ||
); | ||
|
||
ipcMain.handle(MainChannels.VERIFY_DOMAIN, async (_e: Electron.IpcMainInvokeEvent, args) => { | ||
const { domain } = args; | ||
return await verifyDomain(domain); | ||
}); | ||
|
||
ipcMain.handle(MainChannels.GET_OWNED_DOMAINS, async (_e: Electron.IpcMainInvokeEvent) => { | ||
return await getOwnedDomains(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.