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

Reworking the elements package #12557

Merged
merged 26 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e573e07
Moved types around and converted elements package
Oct 12, 2022
cb1e0f4
WIP: convert element-library package
Oct 13, 2022
9ec518c
Merge branch 'main' into code/12126-ts-elements
Oct 26, 2022
7630dd8
Re-moved types to relevant packages and untyped the element-library
Oct 28, 2022
494346a
Updating package.json
Oct 28, 2022
991345d
Merge branch 'main' into code/12126-ts-elements
Oct 31, 2022
28b0c3b
Feedback improvements
Oct 31, 2022
9b477f0
Fixed more from PR feedback
Oct 31, 2022
97c27ad
Merge branch 'main' into code/12126-ts-elements
Oct 31, 2022
fd60e59
Fix lint error
Oct 31, 2022
f3453d3
Merge branch 'main' into code/12126-ts-elements
Nov 1, 2022
0167906
Moved element definitions to element library package and updated depe…
Nov 1, 2022
1e3577e
Fixed React-17 React.FC issue and resource id reference
Nov 2, 2022
e2d875a
Removed Page.type property as it is redundant
Nov 2, 2022
b6b027e
Fix imports of background audio prop type
Nov 2, 2022
0ad2e73
Fixed a karma test
Nov 2, 2022
14e9261
Finally fixed that annoying bg-shape-element copy thingy
Nov 2, 2022
fadc9c0
Added a comment to make sense of it
Nov 2, 2022
677a1c6
Fix eyedropper
merapi Nov 3, 2022
eab2ba6
Target correct element
merapi Nov 3, 2022
8fc7db7
Merge branch 'main' into code/12126-ts-elements
Nov 7, 2022
64d50de
Merge remote-tracking branch 'origin/code/12126-ts-elements' into cod…
Nov 7, 2022
c72cc07
Updated type references for config providers
Nov 7, 2022
1d951d0
Missing types in package.json?
Nov 7, 2022
255d5f6
Merge branch 'main' into code/12126-ts-elements
Nov 10, 2022
f1e7468
Reorganized data types to elements package
Nov 10, 2022
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
32 changes: 3 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
*/

/**
* Internal dependencies
* External dependencies
*/
import type { GifResource } from '../resource';
import type { MediaElement } from './mediaElement';
import type { ElementType } from './element';
import type { GifResource } from '@googleforcreators/media';
import type {
SequenceMediaElement,
ElementType,
} from '@googleforcreators/elements';

export interface GifElement extends MediaElement {
export interface GifElement extends SequenceMediaElement {
resource: GifResource;
type: ElementType.Gif;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
*/

/**
* Internal dependencies
* External dependencies
*/
import type { MediaElement } from './mediaElement';
import type { ElementType } from './element';
import type { Pattern } from './pattern';
import type { Resource } from '@googleforcreators/media';
import type { Pattern } from '@googleforcreators/patterns';
import type { MediaElement, ElementType } from '@googleforcreators/elements';

export type ImageElement = MediaElement & {
type: ElementType.Image;
resource: Resource;

// TODO(#12437): Figure out why some images have this property.
backgroundColor?: Pattern;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@
* limitations under the License.
*/

export * from './element';
export * from './elementBox';
export * from './gifElement';
export * from './imageElement';
export * from './mediaElement';
export * from './pattern';
export * from './productElement';
export * from './shapeElement';
export * from './stickerElement';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/

/**
* Internal dependencies
* External dependencies
*/
import type { Element, ElementType } from './element';
import type { Element, ElementType } from '@googleforcreators/elements';

interface ProductImage {
alt: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/

/**
* Internal dependencies
* External dependencies
*/
import type { Element, ElementType } from './element';
import type { Pattern } from './pattern';
import type { Pattern } from '@googleforcreators/patterns';
import type { Element, ElementType } from '@googleforcreators/elements';

export interface ShapeElement extends Element {
backgroundColor?: Pattern;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/

/**
* Internal dependencies
* External dependencies
*/
import type { Element, ElementType } from './element';
import type { Element, ElementType } from '@googleforcreators/elements';

export interface Sticker {
type: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/

/**
* Internal dependencies
* External dependencies
*/
import type { Element, ElementType } from './element';
import type { Pattern } from './pattern';
import type { Pattern } from '@googleforcreators/patterns';
import type { Element, ElementType } from '@googleforcreators/elements';

export type FontStyle = 'normal' | 'italic' | 'regular';
export enum FontVariantStyle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
*/

/**
* Internal dependencies
* External dependencies
*/
import type { VideoResource } from '../resource';
import type { MediaElement } from './mediaElement';
import type { ElementType } from './element';
import type { VideoResource } from '@googleforcreators/media';
import type {
SequenceMediaElement,
ElementType,
} from '@googleforcreators/elements';

export interface VideoTrack {
id: string;
Expand All @@ -31,7 +33,7 @@ export interface VideoTrack {
needsProxy?: boolean;
}

export interface VideoElement extends MediaElement {
export interface VideoElement extends SequenceMediaElement {
resource: VideoResource;
poster?: string;
tracks?: VideoTrack[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@
* limitations under the License.
*/

export * from './animation';
export * from './page';
export * from './story';
export * from './elements';
22 changes: 22 additions & 0 deletions packages/element-library/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "../../tsconfig.shared.json",
"compilerOptions": {
"rootDir": "src",
"declarationDir": "dist-types"
},
"references": [
{ "path": "../dom" },
{ "path": "../elements" },
{ "path": "../i18n" },
{ "path": "../masks" },
{ "path": "../media" },
{ "path": "../moveable" },
{ "path": "../patterns" },
{ "path": "../react" },
{ "path": "../rich-text" },
{ "path": "../stickers" },
{ "path": "../transform" },
{ "path": "../units" }
],
"include": ["src/types/**/*"]
}
1 change: 0 additions & 1 deletion packages/elements/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"@googleforcreators/i18n": "*",
"@googleforcreators/media": "*",
"@googleforcreators/patterns": "*",
"@googleforcreators/types": "*",
"@googleforcreators/units": "*",
"prop-types": "^15.7.2",
"uuid": "^9.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/elements/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ export const ELEMENT_TYPES = {
GIF: 'gif',
STICKER: 'sticker',
PRODUCT: 'product',
};
} as const;

export const MEDIA_ELEMENT_TYPES = [
ELEMENT_TYPES.IMAGE,
ELEMENT_TYPES.VIDEO,
ELEMENT_TYPES.GIF,
ELEMENT_TYPES.PRODUCT,
];
] as const;

export const MULTIPLE_VALUE = '((MULTIPLE))';

Expand Down
54 changes: 4 additions & 50 deletions packages/elements/src/elementType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,60 +15,14 @@
*/

/**
* External dependencies
* Internal dependencies
*/
import type { ElementType, Element } from '@googleforcreators/types';
import type { FunctionComponent } from 'react';

interface BaseDefinition {
type: string;
name: string;
defaultAttributes: Record<string, unknown>;
}

export interface PageElementDefinition extends BaseDefinition {
type: 'page';
defaultAttributes: Record<string, never>;
}

export interface ElementDefinition extends BaseDefinition {
type: ElementType;
name: string;
defaultAttributes: Record<string, unknown>;
Display: FunctionComponent;
Edit: FunctionComponent;
Frame: FunctionComponent;
Output: FunctionComponent;
TextContent: FunctionComponent;
canFlip: boolean;
isMedia: boolean;
isMaskable: boolean;
isAspectAlwaysLocked: boolean;
hasDesignMenu: boolean;
hasDuplicateMenu: boolean;
hasEditMode: boolean;
hasEditModeIfLocked: boolean;
hasEditModeMoveable: boolean;
editModeGrayout: boolean;
resizeRules: {
vertical: boolean;
horizontal: boolean;
diagonal: boolean;
minWidth: number;
minHeight: number;
};
panels: string[];
getLayerText: (element: Element) => string;
onDropHandler?: (dropTargetId: string) => void;
}

export type ElementTypeDefinition = PageElementDefinition | ElementDefinition;
import type { ElementDefinition, ElementTypes } from './types';

// @todo Create a custom hook to manage state.
const elementTypes: Partial<ElementTypes> = {};

const elementTypes: Record<string, ElementTypeDefinition> = {};

function registerElementType(elementType: ElementTypeDefinition) {
function registerElementType(elementType: ElementDefinition) {
elementTypes[elementType.type] = elementType;
}

Expand Down