Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rectangle insertion now inserts a div. #6579

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion editor/src/components/editor/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ export function defaultRectangleElementStyle(): JSExpression {

export function defaultRectangleElement(uid: string): JSXElement {
return jsxElement(
jsxElementName('Rectangle', []),
jsxElementName('div', []),
uid,
jsxAttributesFromMap({
style: defaultRectangleElementStyle(),
'data-uid': jsExpressionValue(uid, emptyComments),
'data-label': jsExpressionValue('Rectangle', emptyComments),
}),
[],
)
Expand Down
4 changes: 1 addition & 3 deletions editor/src/components/editor/global-shortcuts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -653,9 +653,7 @@ export function handleKeyDown(
EditorActions.enableInsertModeForJSXElement(
defaultRectangleElement(newUID),
newUID,
{
'utopia-api': importDetails(null, [importAlias('Rectangle')], null),
},
{},
null,
),
modifiers,
Expand Down
39 changes: 38 additions & 1 deletion editor/src/core/third-party/utopia-api-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,43 @@ import {
jsxElementWithoutUID,
} from '../shared/element-template'

const IntrinsicComponentDescriptor = (
name: string,
insertMenuLabel: string,
supportsChildren: boolean,
styleProp: () => JSExpression,
): ComponentDescriptor => {
return {
properties: {
style: {
control: 'style-controls',
},
},
supportsChildren: supportsChildren,
preferredChildComponents: [],
variants: [
{
insertMenuLabel: insertMenuLabel,
importsToAdd: {},
elementToInsert: () =>
jsxElementWithoutUID(
name,
[
jsxAttributesEntry('style', styleProp(), emptyComments),
jsxAttributesEntry(
'data-label',
jsExpressionValue('Rectangle', emptyComments),
emptyComments,
),
],
[],
),
},
],
source: defaultComponentDescriptor(),
...ComponentDescriptorDefaults,
}
}
const BasicUtopiaComponentDescriptor = (
name: string,
supportsChildren: boolean,
Expand Down Expand Up @@ -106,7 +143,7 @@ const BasicUtopiaSceneDescriptor = (

export const UtopiaApiComponents: ComponentDescriptorsForFile = {
Ellipse: BasicUtopiaComponentDescriptor('Ellipse', false, defaultElementStyle),
Rectangle: BasicUtopiaComponentDescriptor('Rectangle', false, defaultRectangleElementStyle),
Rectangle: IntrinsicComponentDescriptor('div', 'Rectangle', false, defaultRectangleElementStyle),
View: BasicUtopiaComponentDescriptor('View', true, defaultElementStyle),
FlexRow: BasicUtopiaComponentDescriptor('FlexRow', true, defaultFlexRowOrColStyle),
FlexCol: BasicUtopiaComponentDescriptor('FlexCol', true, defaultFlexRowOrColStyle),
Expand Down
Loading