Skip to content

Commit

Permalink
Reorganized data types to elements package
Browse files Browse the repository at this point in the history
  • Loading branch information
Morten Barklund committed Nov 10, 2022
1 parent 255d5f6 commit f1e7468
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 65 deletions.
4 changes: 2 additions & 2 deletions packages/dashboard/src/types/configProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* External dependencies
*/
import type { Template } from '@googleforcreators/templates';
import type { Product } from '@googleforcreators/element-library';
import type { ProductData } from '@googleforcreators/elements';

export interface Locale {
locale?: string;
Expand Down Expand Up @@ -101,7 +101,7 @@ export interface ApiCallbacks {
duplicateStory?: (story: DashboardStory) => Promise<DashboardStory>;
fetchStories?: () => Promise<DashboardStory[]>;
getAuthors?: (search: string) => Promise<Author[]>;
getProducts?: (search: string) => Promise<Product[]>;
getProducts?: (search: string) => Promise<ProductData[]>;
getTaxonomies?: (args: TaxonomiesArgs) => Promise<Taxonomy[]>;
getTaxonomyTerms?: (endpoint: string, args: TermArgs) => Promise<Term>;
trashStory?: (id: number) => Promise<DashboardStory>;
Expand Down
25 changes: 6 additions & 19 deletions packages/element-library/src/types/elements/productElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,13 @@
/**
* External dependencies
*/
import type { Element, ElementType } from '@googleforcreators/elements';

interface ProductImage {
alt: string;
url: string;
}

export interface Product {
productId: string;
productBrand: string;
productDetails: string;
productImages: ProductImage[];
productPrice: number;
productPriceCurrency: string;
productTitle: string;
productUrl: string;
type: ElementType.Product;
}
import type {
Element,
ElementType,
ProductData,
} from '@googleforcreators/elements';

export interface ProductElement extends Element {
type: ElementType.Product;
product: Product;
product: ProductData;
}
46 changes: 6 additions & 40 deletions packages/element-library/src/types/elements/textElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,11 @@
* External dependencies
*/
import type { Pattern } from '@googleforcreators/patterns';
import type { Element, ElementType } from '@googleforcreators/elements';

export type FontStyle = 'normal' | 'italic' | 'regular';
export enum FontVariantStyle {
Normal = 0,
Italic = 1,
}

export type FontWeight = 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;

export type FontVariant = [FontVariantStyle, FontWeight];

export interface Font {
family: string;
service?: string;
weights?: FontWeight[];
styles?: FontStyle[];
variants?: FontVariant[];
fallbacks?: string[];
metrics?: FontMetrics;
}
import type {
Element,
ElementType,
FontData,
} from '@googleforcreators/elements';

export interface Padding {
horizontal?: number;
Expand All @@ -50,28 +34,10 @@ export interface Padding {
export type TextAlign = 'left' | 'center' | 'right' | 'justify' | 'initial';
export type BackgroundTextMode = 'NONE' | 'FILL' | 'HIGHLIGHT';

export interface FontMetrics {
upm: number;
asc: number;
des: number;
tAsc: number;
tDes: number;
tLGap: number;
wAsc: number;
wDes: number;
xH: number;
capH: number;
yMin: number;
yMax: number;
hAsc: number;
hDes: number;
lGap: number;
}

export interface TextElement extends Element {
type: ElementType.Text;
content: string;
font: Font;
font: FontData;

backgroundTextMode?: BackgroundTextMode;
backgroundColor?: Pattern;
Expand Down
69 changes: 69 additions & 0 deletions packages/elements/src/types/data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export type FontStyle = 'normal' | 'italic' | 'regular';
export enum FontVariantStyle {
Normal = 0,
Italic = 1,
}

export type FontWeight = 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;

export type FontVariant = [FontVariantStyle, FontWeight];

export interface FontMetrics {
upm: number;
asc: number;
des: number;
tAsc: number;
tDes: number;
tLGap: number;
wAsc: number;
wDes: number;
xH: number;
capH: number;
yMin: number;
yMax: number;
hAsc: number;
hDes: number;
lGap: number;
}

export interface FontData {
family: string;
service?: string;
weights?: FontWeight[];
styles?: FontStyle[];
variants?: FontVariant[];
fallbacks?: string[];
metrics?: FontMetrics;
}

export interface ProductImage {
alt: string;
url: string;
}

export interface ProductData {
productId: string;
productBrand: string;
productDetails: string;
productImages: ProductImage[];
productPrice: number;
productPriceCurrency: string;
productTitle: string;
productUrl: string;
}
1 change: 1 addition & 0 deletions packages/elements/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/
export * from './animation';
export * from './data';
export * from './element';
export * from './elementType';
export * from './elementDefinition';
Expand Down
13 changes: 9 additions & 4 deletions packages/story-editor/src/types/configProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@
/**
* External dependencies
*/
import type { MediaElement, Page, Story } from '@googleforcreators/elements';
import type {
MediaElement,
Page,
Story,
FontData,
ProductData,
} from '@googleforcreators/elements';
import type {
Resource,
ResourceId,
TrimData,
VideoResource,
} from '@googleforcreators/media';
import type { Font, Product } from '@googleforcreators/element-library';

export interface Capabilities {
/** If the user has permissions to upload files. */
Expand Down Expand Up @@ -182,7 +187,7 @@ export interface APICallbacks {
hasMore: boolean;
templates: PageTemplate[];
}>;
getFonts?: (props: GetFontProps) => Promise<Font[]>;
getFonts?: (props: GetFontProps) => Promise<FontData[]>;
getHotlinkInfo?: (link: string) => Promise<HotlinkInfo>;
getLinkMetadata?: (link: string) => Promise<LinkMetaData>;
getMedia?: (props: {
Expand All @@ -199,7 +204,7 @@ export interface APICallbacks {
getOptimizedMediaById?: (id: number) => Promise<Resource>;
getPageTemplates?: () => Promise<PageTemplate[]>;
getPosterMediaById?: (id: number) => Promise<Resource>;
getProducts?: () => Promise<Product[]>;
getProducts?: () => Promise<ProductData[]>;
getProxyUrl?: (src: string) => string;
getStoryById?: (id: number) => Promise<Story>;
getTaxonomies?: () => Promise<Taxonomy[]>;
Expand Down

0 comments on commit f1e7468

Please sign in to comment.