-
Notifications
You must be signed in to change notification settings - Fork 177
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
TypeScript: story-editor
config provider
#12619
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3fa14b8
Typings for useConfig of story-editor package
miina 1e88a47
Lint
miina faf4f5e
More updates
miina c9b29d0
Type config state
miina e8047b5
Start typing callbacks.
miina d8e2b81
More types.
miina fd9d4cd
Type taxonomies
miina 5fc0b56
Fix
miina 6dcb96d
Remove WP-specific types
miina 058b89e
Remove api from config value in story-editor.
miina d82c876
Lint
miina 2e22e74
Remove comment
miina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
File renamed without changes.
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,306 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import type { | ||
Font, | ||
MediaElement, | ||
Page, | ||
Product, | ||
Resource, | ||
ResourceId, | ||
Story, | ||
TrimData, | ||
VideoResource, | ||
} from '@googleforcreators/types'; | ||
|
||
export interface Capabilities { | ||
/** If the user has permissions to upload files. */ | ||
hasUploadMediaAction?: boolean; | ||
/** If the user has permissions to manage site settings. */ | ||
canManageSettings?: boolean; | ||
} | ||
|
||
export interface MimeTypes { | ||
audio?: string[]; | ||
image?: string[]; | ||
caption?: string[]; | ||
vector?: string[]; | ||
video?: string[]; | ||
} | ||
|
||
export interface Locale { | ||
locale?: string; | ||
dateFormat?: string; | ||
timeFormat?: string; | ||
gmtOffset?: number; | ||
timeZone?: string; | ||
months?: string[]; | ||
monthsShort?: string[]; | ||
weekdays?: string[]; | ||
weekdaysShort?: string[]; | ||
weekdaysInitials?: string[]; | ||
weekStartsOn?: number; | ||
timezoneAbbr?: string; | ||
} | ||
|
||
export interface MetaData { | ||
publisher?: string; | ||
} | ||
|
||
export interface API { | ||
users: string; | ||
currentUser: string; | ||
stories: string; | ||
pageTemplates: string; | ||
media: string; | ||
hotlink: string; | ||
publisherLogos: string; | ||
products: string; | ||
proxy: string; | ||
link: string; | ||
statusCheck: string; | ||
taxonomies: string; | ||
fonts: string; | ||
metaBoxes: string; | ||
storyLocking: string; | ||
} | ||
|
||
export interface MetaBoxes { | ||
normal: string[]; | ||
advanced: string[]; | ||
side: string[]; | ||
} | ||
|
||
export interface Tip { | ||
title: string; | ||
figureSrcImg: string; | ||
figureAlt: string; | ||
description: string[]; | ||
href: string; | ||
} | ||
|
||
interface PageTemplate extends Page { | ||
version: string; | ||
} | ||
interface TemplateData { | ||
story_data: PageTemplate; | ||
featured_media: number; | ||
title?: string; | ||
} | ||
|
||
type Term = { | ||
id: number; | ||
name: string; | ||
slug: string; | ||
taxonomy: string; | ||
}; | ||
|
||
type Author = { | ||
id: number; | ||
name: string; | ||
url?: string; | ||
description?: string; | ||
slug: string; | ||
link: string; | ||
avatarUrls?: Record<number, string>; | ||
}; | ||
|
||
type User = { | ||
id: number; | ||
mediaOptimization: boolean; | ||
onboarding: Record<string, boolean>; | ||
trackingOptin: boolean; | ||
}; | ||
|
||
type GetFontProps = { | ||
service?: string; | ||
include?: string; | ||
search?: string; | ||
}; | ||
|
||
type HotlinkInfo = { | ||
ext?: string; | ||
fileName?: string; | ||
fileSize?: number; | ||
mimeType?: string; | ||
type?: string; | ||
width?: number; | ||
height?: number; | ||
}; | ||
|
||
type LinkMetaData = { | ||
title: string; | ||
image: string; | ||
}; | ||
|
||
type UploadMediaProps = { | ||
onUploadSuccess?: (media: MediaElement) => void; | ||
onUploadProgress?: (media: MediaElement) => void; | ||
onUploadError?: (media: MediaElement) => void; | ||
cropVideo?: boolean; | ||
additionalData: { | ||
originalId?: number; | ||
mediaId?: number; | ||
storyId?: number; | ||
templateId?: number; | ||
optimizedId?: number; | ||
cropOriginId?: number; | ||
mutedId?: number; | ||
posterId?: number; | ||
isMuted?: boolean; | ||
mediaSource?: string; | ||
trimData?: TrimData; | ||
baseColor?: string; | ||
blurHash?: string; | ||
isGif?: boolean; | ||
altText?: string; | ||
}; | ||
originalResourceId: ResourceId; | ||
resource: Resource; | ||
}; | ||
|
||
export type Taxonomy = { | ||
name: string; | ||
slug: string; | ||
capabilities: Record<string, string>; | ||
description?: string; | ||
labels: Record<string, string>; | ||
types: string[]; | ||
showCloud?: boolean; | ||
hierarchical: boolean; | ||
restBase: string; | ||
restNamespace: string; | ||
visibility: Record<string, boolean>; | ||
restPath: string; | ||
}; | ||
|
||
export interface APICallbacks { | ||
addPageTemplate?: (data: TemplateData) => Promise<PageTemplate>; | ||
autoSaveById?: (story: Story) => Promise<Story>; | ||
createTaxonomyTerm?: ( | ||
endpoint: string, | ||
term: { | ||
name: string; | ||
parent?: number; | ||
slug?: string; | ||
} | ||
) => Promise<Term>; | ||
deleteMedia?: (id: number) => Promise<boolean>; | ||
deletePageTemplate?: (id: number) => Promise<boolean>; | ||
getAuthors?: () => Promise<Author[]>; | ||
getCurrentUser?: () => Promise<User>; | ||
getCustomPageTemplates?: (page: number | boolean) => Promise<{ | ||
hasMore: boolean; | ||
templates: PageTemplate[]; | ||
}>; | ||
getFonts?: (props: GetFontProps) => Promise<Font[]>; | ||
getHotlinkInfo?: (link: string) => Promise<HotlinkInfo>; | ||
getLinkMetadata?: (link: string) => Promise<LinkMetaData>; | ||
getMedia?: (props: { | ||
mediaType: string; | ||
searchTerm: string; | ||
pagingNum: number; | ||
}) => Promise<{ | ||
data: Resource[]; | ||
headers: Record<string, string>; | ||
}>; | ||
getMediaById?: (id: number) => Promise<Resource>; | ||
// @todo Not certain if correct. | ||
getMediaForCorsCheck?: () => Promise<Resource[]>; | ||
getMutedMediaById?: (id: number) => Promise<VideoResource>; | ||
getOptimizedMediaById?: (id: number) => Promise<Resource>; | ||
getPageTemplates?: () => Promise<PageTemplate[]>; | ||
getPosterMediaById?: (id: number) => Promise<Resource>; | ||
getProducts?: () => Promise<Product[]>; | ||
getProxyUrl?: (src: string) => string; | ||
getStoryById?: (id: number) => Promise<Story>; | ||
getTaxonomies?: () => Promise<Taxonomy[]>; | ||
getTaxonomyTerm?: (props: { | ||
search?: string; | ||
per_page?: number; | ||
}) => Promise<Term>; | ||
saveStoryById?: (data: Story) => Promise<Story>; | ||
updateCurrentUser?: (data: { | ||
mediaOptimization?: boolean; | ||
onboarding?: Record<string, boolean>; | ||
trackingOptin?: boolean; | ||
}) => Promise<User>; | ||
updateMedia?: (id: number, data: Partial<Resource>) => Promise<Resource>; | ||
updatePageTemplate?: ( | ||
id: number, | ||
data: Partial<PageTemplate> | ||
) => Promise<PageTemplate>; | ||
uploadMedia?: (files: string[], props: UploadMediaProps) => Promise<Resource>; | ||
} | ||
|
||
export interface PostLock { | ||
interval: number; | ||
showLockedDialog: boolean; | ||
} | ||
|
||
export interface ConfigState { | ||
miina marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** Interval in seconds. */ | ||
autoSaveInterval: number | null; | ||
/** Interval in seconds. */ | ||
localAutoSaveInterval: number; | ||
autoSaveLink: string; | ||
isRTL: boolean; | ||
locale?: Locale; | ||
allowedMimeTypes: MimeTypes; | ||
storyId: number | null; | ||
dashboardLink: string; | ||
dashboardSettingsLink: string; | ||
generalSettingsLink: string; | ||
cdnURL: string; | ||
/** Max allowed upload in bytes */ | ||
maxUpload: number; | ||
capabilities: Capabilities; | ||
metaData: MetaData; | ||
canViewDefaultTemplates: boolean; | ||
/** If to show the 3rd party media in the library */ | ||
showMedia3p: boolean; | ||
encodeMarkup: boolean; | ||
ffmpegCoreUrl: string; | ||
apiCallbacks: APICallbacks; | ||
styleConstants: { | ||
topOffset: number; | ||
leftOffset: number; | ||
}; | ||
/** Data for when a user tries to edit a story that's already being edited */ | ||
postLock?: PostLock; | ||
postType?: string; | ||
revisionLink?: string; | ||
// @todo Is this used at all? | ||
isDemo?: boolean; | ||
miina marked this conversation as resolved.
Show resolved
Hide resolved
|
||
api?: API; | ||
miina marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** Plugin version */ | ||
version: string; | ||
nonce?: string; | ||
/** If true, the story advances automatically */ | ||
globalAutoAdvance?: boolean; | ||
/** Page duration in seconds in case of auto-advancing */ | ||
globalPageDuration?: number; | ||
shoppingProvider: string; | ||
/** Enabled meta-boxes that are displayed in the editor */ | ||
metaBoxes?: MetaBoxes; | ||
mediainfoUrl: string; | ||
/** Feature flags */ | ||
flags: Record<string, boolean>; | ||
additionalTips: Record<string, Tip>; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useConfig()
is actually only used like this line here, it seems (without using props).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, because the state never changes anyway.