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

Synced ComponentInfo to the current state of Component interface in gen1 builder.class.ts #2886

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/sdks/src/functions/is-server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { getBuilderGlobals } from './evaluate/helpers';

export function isServer(): boolean {
return Boolean(getBuilderGlobals().isServer);
}
2 changes: 2 additions & 0 deletions packages/sdks/src/server-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ export type { RegisteredComponent } from './context/types.js';
export type { ComponentInfo } from './types/components.js';

export { fetchBuilderProps } from './functions/fetch-builder-props.js';
export { isBrowser } from './functions/is-browser.js';
export { isServer } from './functions/is-server.js';
Comment on lines +30 to +31
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to export these in the new SDKs. It makes little sense to provide our users with helpers like these: they have nothing to do with SDK functionality.

What is the use case for adding them here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have exposed these helpers before in Gen1 and they are widely used in client code, example - in our site. Migrating to gen2 will require users with a substitute, thus exporting them

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand, and that's the way to go. I would rather users rely on their own isBrowser/isServer helpers than reuse ours. The Builder SDK shouldn't be exporting generic helpers such as these: they are unrelated to the Builder SDK's purpose.

49 changes: 48 additions & 1 deletion packages/sdks/src/types/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,70 @@ export interface ComponentInfo {
* by registering a component with the same name, e.g. 'Text', to replace the built-in text component
*/
name: string;
/** @hidden @deprecated */
description?: string;
/**
* Link to a documentation page for this component
*/
docsLink?: string;
/**
* Link to an image to be used as an icon for this component in Builder's editor
*
* @example
* ```js
* image: 'https://some-cdn.com/my-icon-for-this-component.png'
* ```
*/
image?: string;

// TODO (murtaza): Implement 'screenshot' related stuff
/**
* Link to a screenshot shown when user hovers over the component in Builder's editor
* use https://builder.io/upload to upload your screeshot, for easier resizing by Builder.
*/
screenshot?: string;

// TODO (murtaza): Implement 'override' related stuff
/**
* When overriding built-in components, if you don't want any special behavior that
* the original has, set this to `true` to skip the default behavior
*
* Default behaviors include special "virtual options", such as a custom
* aspect ratio editor for Images, or a special column editor for Columns
*
* Learn more about overriding built-in components here: https://www.builder.io/c/docs/custom-components-overriding
*/
override?: boolean;

/**
* Input schema for your component for users to fill in the options
*/
inputs?: Input[];
/** @hidden @deprecated */
class?: any;
/** @hidden @deprecated */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding these tags. We will want to go ahead and completely remove any deprecated attributes in gen2 SDKs before we bump to v1, as this is our big chance to remove deprecated features.

They can stay here for now though, and these tags will help us know what to remove in the near future 👍🏽

type?: 'angular' | 'webcomponent' | 'react' | 'vue';
/**
* Default styles to apply when dropped into the Builder.io editor
*
* @example
* ```js
* defaultStyles: {
* // large (default) breakpoint
* large: {
* backgroundColor: 'black'
* },
* }
* ```
*/
defaultStyles?: { [key: string]: string };
/**
* Turn on if your component can accept children. Be sure to use in combination with
* withChildren(YourComponent) like here
* github.com/BuilderIO/builder/blob/master/examples/react-design-system/src/components/HeroWithChildren/HeroWithChildren.builder.js#L5
*/
canHaveChildren?: boolean;
/** @hidden */
fragment?: boolean;
/**
* Do not wrap a component in a dom element. Be sure to use {...props.attributes} with this option
Expand All @@ -45,14 +90,16 @@ export interface ComponentInfo {
*/
defaultChildren?: BuilderElement[];
defaults?: Partial<BuilderElement>;
/** @hidden @deprecated */
// eslint-disable-next-line @typescript-eslint/ban-types
hooks?: { [key: string]: string | Function };
/**
* Hide your component in editor, useful for gradually deprecating components
*/
hideFromInsertMenu?: boolean;
// For webcomponents
/** Custom tag name (for custom webcomponents only) */
tag?: string;
/** @hidden @deprecated */
static?: boolean;
/**
* Passing a list of model names will restrict using the component to only the models listed here, otherwise it'll be available for all models
Expand Down