From 08331a0e655a3b238ed06accfd05419aebe03368 Mon Sep 17 00:00:00 2001 From: Derek Sifford Date: Mon, 15 Jul 2019 18:38:33 -0400 Subject: [PATCH] [@wordpress/edit-post] add new definitions (#36875) --- .../plugin-block-settings-menu-item.d.ts | 51 +++++ .../header/plugin-more-menu-item.d.ts | 45 ++++ .../header/plugin-sidebar-more-menu-item.d.ts | 41 ++++ .../plugin-document-setting-panel.d.ts | 49 +++++ .../sidebar/plugin-post-publish-panel.d.ts | 48 +++++ .../sidebar/plugin-post-status-info.d.ts | 35 +++ .../sidebar/plugin-pre-publish-panel.d.ts | 48 +++++ .../components/sidebar/plugin-sidebar.d.ts | 63 ++++++ types/wordpress__edit-post/index.d.ts | 199 ++++++++++++++++++ types/wordpress__edit-post/store/actions.d.ts | 111 ++++++++++ .../wordpress__edit-post/store/selectors.d.ts | 136 ++++++++++++ types/wordpress__edit-post/tsconfig.json | 38 ++++ types/wordpress__edit-post/tslint.json | 1 + .../wordpress__edit-post-tests.tsx | 129 ++++++++++++ 14 files changed, 994 insertions(+) create mode 100644 types/wordpress__edit-post/components/block-settings-menu/plugin-block-settings-menu-item.d.ts create mode 100644 types/wordpress__edit-post/components/header/plugin-more-menu-item.d.ts create mode 100644 types/wordpress__edit-post/components/header/plugin-sidebar-more-menu-item.d.ts create mode 100644 types/wordpress__edit-post/components/sidebar/plugin-document-setting-panel.d.ts create mode 100644 types/wordpress__edit-post/components/sidebar/plugin-post-publish-panel.d.ts create mode 100644 types/wordpress__edit-post/components/sidebar/plugin-post-status-info.d.ts create mode 100644 types/wordpress__edit-post/components/sidebar/plugin-pre-publish-panel.d.ts create mode 100644 types/wordpress__edit-post/components/sidebar/plugin-sidebar.d.ts create mode 100644 types/wordpress__edit-post/index.d.ts create mode 100644 types/wordpress__edit-post/store/actions.d.ts create mode 100644 types/wordpress__edit-post/store/selectors.d.ts create mode 100644 types/wordpress__edit-post/tsconfig.json create mode 100644 types/wordpress__edit-post/tslint.json create mode 100644 types/wordpress__edit-post/wordpress__edit-post-tests.tsx diff --git a/types/wordpress__edit-post/components/block-settings-menu/plugin-block-settings-menu-item.d.ts b/types/wordpress__edit-post/components/block-settings-menu/plugin-block-settings-menu-item.d.ts new file mode 100644 index 0000000000..fdf9ea57c2 --- /dev/null +++ b/types/wordpress__edit-post/components/block-settings-menu/plugin-block-settings-menu-item.d.ts @@ -0,0 +1,51 @@ +import { ComponentType, MouseEventHandler } from '@wordpress/element'; +import { Dashicon } from '@wordpress/components'; + +declare namespace PluginBlockSettingsMenuItem { + interface Props { + /** + * An array containing a list of block names for which the item should be shown. If not present, + * it'll be rendered for any block. If multiple blocks are selected, it'll be shown if and only if + * all of them are in the whitelist. + */ + allowedBlocks?: string[]; + /** + * A dashicon slug, or a custom JSX element. + * @defaultValue `"admin-plugins"` + */ + icon?: JSX.Element | Dashicon.Icon; + /** + * The menu item text. + */ + label: string; + /** + * Callback function to be executed when the user click the menu item. + */ + onClick: MouseEventHandler; + /** + * If it should be rendered smaller. (This is undocumented). + */ + small?: boolean; + } +} + +/** + * Renders a new item in the block settings menu. + * + * @example + * ```jsx + * import { PluginBlockSettingsMenuItem } from wp.editPost; + * + * const MyPluginBlockSettingsMenuItem = () => ( + * console.log('clicked')} + * /> + * ); + * ``` + */ +declare const PluginBlockSettingsMenuItem: ComponentType; + +export default PluginBlockSettingsMenuItem; diff --git a/types/wordpress__edit-post/components/header/plugin-more-menu-item.d.ts b/types/wordpress__edit-post/components/header/plugin-more-menu-item.d.ts new file mode 100644 index 0000000000..9d258a0d62 --- /dev/null +++ b/types/wordpress__edit-post/components/header/plugin-more-menu-item.d.ts @@ -0,0 +1,45 @@ +import { Dashicon, MenuItem } from '@wordpress/components'; +import { ComponentType, ReactNode } from '@wordpress/element'; + +declare namespace PluginMoreMenuItem { + interface Props extends Omit { + children: ReactNode; + /** + * When `href` is provided then the menu item is represented as an anchor rather than + * button. It corresponds to the `href` attribute of the anchor. + */ + href?: string; + /** + * A Dashicon slug or a custom JSX element to be rendered to the left of the menu item + * label. + */ + icon?: Dashicon.Icon | JSX.Element; + /** + * The callback function to be executed when the user clicks the menu item. + */ + onClick?(): void; + } +} + +/** + * Renders a menu item in `Plugins` group in `More Menu` drop down, and can be used to as a button + * or link depending on the props provided. The text within the component appears as the menu item + * label. + * + * @example + * ```jsx + * const { PluginMoreMenuItem } = wp.editPost; + * + * const MyButtonMoreMenuItem = () => ( + * console.log('clicked!')} + * > + * My button title + * + * ); + * ``` + */ +declare const PluginMoreMenuItem: ComponentType; + +export default PluginMoreMenuItem; diff --git a/types/wordpress__edit-post/components/header/plugin-sidebar-more-menu-item.d.ts b/types/wordpress__edit-post/components/header/plugin-sidebar-more-menu-item.d.ts new file mode 100644 index 0000000000..41fa12e54d --- /dev/null +++ b/types/wordpress__edit-post/components/header/plugin-sidebar-more-menu-item.d.ts @@ -0,0 +1,41 @@ +import { Dashicon } from '@wordpress/components'; +import { ComponentType, ReactNode } from '@wordpress/element'; + +declare namespace PluginSidebarMoreMenuItem { + interface Props { + children: ReactNode; + /** + * A string identifying the target sidebar you wish to be activated by this menu item. Must + * be the same as the `name` prop you have given to that sidebar. + */ + target: string; + /** + * A Dashicon slug or a custom JSX element to be rendered to the left of the menu item + * label. + */ + icon?: Dashicon.Icon | JSX.Element; + } +} + +/** + * Renders a menu item in `Plugins` group in `More Menu` drop down, and can be used to activate the + * corresponding `PluginSidebar` component. The text within the component appears as the menu item + * label. + * + * @example + * ```jsx + * const { PluginSidebarMoreMenuItem } = wp.editPost; + * + * const MySidebarMoreMenuItem = () => ( + * + * My sidebar title + * + * ); + * ``` + */ +declare const PluginSidebarMoreMenuItem: ComponentType; + +export default PluginSidebarMoreMenuItem; diff --git a/types/wordpress__edit-post/components/sidebar/plugin-document-setting-panel.d.ts b/types/wordpress__edit-post/components/sidebar/plugin-document-setting-panel.d.ts new file mode 100644 index 0000000000..50186e5e9a --- /dev/null +++ b/types/wordpress__edit-post/components/sidebar/plugin-document-setting-panel.d.ts @@ -0,0 +1,49 @@ +import { Dashicon, Slot } from '@wordpress/components'; +import { FC, ReactNode } from '@wordpress/element'; + +declare namespace PluginDocumentSettingPanel { + interface Props { + children: ReactNode; + /** + * The machine-friendly name for the panel. + */ + name?: string; + /** + * An optional class name added to the row. + */ + className?: string; + /** + * The title of the panel. + */ + title?: string; + /** + * A Dashicon slug or a custom JSX element to be rendered when the sidebar is pinned to + * toolbar. + */ + icon?: Dashicon.Icon | JSX.Element; + } +} + +/** + * Renders items below the Status & Availability panel in the Document Sidebar. + * + * @example + * ```jsx + * const { registerPlugin } = wp.plugins; + * const { PluginDocumentSettingPanel } = wp.editPost; + * + * const MyDocumentSettingTest = () => ( + * + *

My Document Setting Panel

+ *
+ * ); + * + * registerPlugin( 'document-setting-test', { render: MyDocumentSettingTest } ); + * ``` + */ +declare const PluginDocumentSettingPanel: { + (props: PluginDocumentSettingPanel.Props): JSX.Element; + Slot: FC>; +}; + +export default PluginDocumentSettingPanel; diff --git a/types/wordpress__edit-post/components/sidebar/plugin-post-publish-panel.d.ts b/types/wordpress__edit-post/components/sidebar/plugin-post-publish-panel.d.ts new file mode 100644 index 0000000000..3b095887de --- /dev/null +++ b/types/wordpress__edit-post/components/sidebar/plugin-post-publish-panel.d.ts @@ -0,0 +1,48 @@ +import { Slot } from '@wordpress/components'; +import { FC, ReactNode } from '@wordpress/element'; + +declare namespace PluginPostPublishPanel { + interface Props { + children: ReactNode; + /** + * An optional class name added to the panel. + */ + className?: string; + /** + * Title displayed at the top of the panel. + */ + title?: string; + /** + * Whether to have the panel initially opened. When no title is provided it is always + * opened. + * @defaultValue `false` + */ + initialOpen?: boolean; + } +} + +/** + * Renders provided content to the post-publish panel in the publish flow (side panel that opens + * after a user publishes the post). + * + * @example + * ```jsx + * const { PluginPostPublishPanel } = wp.editPost; + * + * const MyPluginPostPublishPanel = () => ( + * + * My panel content + * + * ); + * ``` + */ +declare const PluginPostPublishPanel: { + (props: PluginPostPublishPanel.Props): JSX.Element; + Slot: FC>; +}; + +export default PluginPostPublishPanel; diff --git a/types/wordpress__edit-post/components/sidebar/plugin-post-status-info.d.ts b/types/wordpress__edit-post/components/sidebar/plugin-post-status-info.d.ts new file mode 100644 index 0000000000..8c0fca2c30 --- /dev/null +++ b/types/wordpress__edit-post/components/sidebar/plugin-post-status-info.d.ts @@ -0,0 +1,35 @@ +import { Slot } from '@wordpress/components'; +import { FC, ReactNode } from '@wordpress/element'; + +declare namespace PluginPostStatusInfo { + interface Props { + children: ReactNode; + /** + * An optional class name added to the row. + */ + className?: string; + } +} + +/** + * Renders a row in the Status & Visibility panel of the Document sidebar. + * It should be noted that this is named and implemented around the function it serves + * and not its location, which may change in future iterations. + * + * @example + * ```jsx + * const { PluginPostStatusInfo } = wp.editPost; + * + * const MyPluginPostStatusInfo = () => ( + * + * My post status info + * + * ); + * ``` + */ +declare const PluginPostStatusInfo: { + (props: PluginPostStatusInfo.Props): JSX.Element; + Slot: FC>; +}; + +export default PluginPostStatusInfo; diff --git a/types/wordpress__edit-post/components/sidebar/plugin-pre-publish-panel.d.ts b/types/wordpress__edit-post/components/sidebar/plugin-pre-publish-panel.d.ts new file mode 100644 index 0000000000..b0ed4a1273 --- /dev/null +++ b/types/wordpress__edit-post/components/sidebar/plugin-pre-publish-panel.d.ts @@ -0,0 +1,48 @@ +import { Slot } from '@wordpress/components'; +import { FC, ReactNode } from '@wordpress/element'; + +declare namespace PluginPrePublishPanel { + interface Props { + children: ReactNode; + /** + * An optional class name added to the panel. + */ + className?: string; + /** + * Whether to have the panel initially opened. When no title is provided it is always + * opened. + * @defaultValue `false` + */ + initialOpen?: boolean; + /** + * Title displayed at the top of the panel. + */ + title?: string; + } +} + +/** + * Renders provided content to the pre-publish side panel in the publish flow (side panel that opens + * when a user first pushes "Publish" from the main editor). + * + * @example + * ```jsx + * const { PluginPrePublishPanel } = wp.editPost; + * + * const MyPluginPrePublishPanel = () => ( + * + * My panel content + * + * ); + * ``` + */ +declare const PluginPrePublishPanel: { + (props: PluginPrePublishPanel.Props): JSX.Element; + Slot: FC>; +}; + +export default PluginPrePublishPanel; diff --git a/types/wordpress__edit-post/components/sidebar/plugin-sidebar.d.ts b/types/wordpress__edit-post/components/sidebar/plugin-sidebar.d.ts new file mode 100644 index 0000000000..0678f7d6ec --- /dev/null +++ b/types/wordpress__edit-post/components/sidebar/plugin-sidebar.d.ts @@ -0,0 +1,63 @@ +import { Dashicon } from '@wordpress/components'; +import { ComponentType, ReactNode } from '@wordpress/element'; + +declare namespace PluginSidebar { + interface Props { + children: ReactNode; + /** + * An optional class name added to the sidebar body. + */ + className?: string; + /** + * A Dashicon slug or a custom JSX element to be rendered when the sidebar is pinned to + * toolbar. + */ + icon?: Dashicon.Icon | JSX.Element; + /** + * Whether to allow to pin sidebar to toolbar. + * @defaultValue `true` + */ + isPinnable?: boolean; + /** + * A string identifying the sidebar. Must be unique for every sidebar registered within the + * scope of your plugin. + */ + name: string; + /** + * Title displayed at the top of the sidebar. + */ + title: string; + } +} + +/** + * Renders a sidebar when activated. The contents within the `PluginSidebar` will appear as content + * within the sidebar. + * + * @see {@link PluginSidebarMoreMenuItem } + * + * @example + * ```jsx + * const { PanelBody } = wp.components; + * const { PluginSidebar } = wp.editPost; + * + * const MyPluginSidebar = () => ( + * + * + * My sidebar content + * + * + * ); + * + * // If you wish to display the sidebar, you can with use the + * // `PluginSidebarMoreMenuItem` component or the `wp.data.dispatch` API + * wp.data.dispatch('core/edit-post').openGeneralSidebar('plugin-name/my-sidebar'); + * ``` + */ +declare const PluginSidebar: ComponentType; + +export default PluginSidebar; diff --git a/types/wordpress__edit-post/index.d.ts b/types/wordpress__edit-post/index.d.ts new file mode 100644 index 0000000000..6e9ec3f935 --- /dev/null +++ b/types/wordpress__edit-post/index.d.ts @@ -0,0 +1,199 @@ +// Type definitions for @wordpress/edit-post 3.5 +// Project: https://github.com/WordPress/gutenberg/tree/master/packages/edit-post/README.md +// Definitions by: Derek Sifford +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.5 + +import { dispatch, select } from '@wordpress/data'; + +declare module '@wordpress/data' { + function dispatch(key: 'core/edit-post'): typeof import('./store/actions'); + function select(key: 'core/edit-post'): typeof import('./store/selectors'); +} + +export type MetaboxLocation = 'advanced' | 'normal' | 'side'; + +// FIXME: move this to @wordpress/block-editor when types are created for that package. +export type EditorMode = 'text' | 'visual'; + +// FIXME: move this to @wordpress/block-editor when types are created for that package. +export interface EditorSettings { + /** + * Enable/Disable Wide/Full Alignments + * @defaultValue `false` + */ + alignWide: boolean; + /** + * Array of allowed block types, `true` for all blocks, or `false` for no blocks. + * @defaultValue `true` + */ + allowedBlockTypes: string[] | boolean; + /** + * Mapping of extension:mimetype + * @example + * ```js + * { + * "jpg|jpeg|jpe": "image/jpeg", + * } + * ``` + */ + allowedMimeTypes: Record | null; + autosaveInterval: number; + /** + * Array of objects representing the legacy widgets available. + */ + availableLegacyWidgets: Array<{ + description: string; + isCallbackWidget: boolean; + isHidden: boolean; + name: string; + }>; + // FIXME: it is unclear what this value should be. + availableTemplates: any[]; + /** + * Empty post placeholder. + * @defaultValue `"Start writing or type / to choose a block"` + */ + bodyPlaceholder: string; + /** + * Whether or not the user can switch to the code editor. + */ + codeEditingEnabled: boolean; + /** + * Palette colors. + */ + colors: Array<{ + color: string; + name: string; + slug: string; + }>; + /** + * Whether or not the custom colors are disabled. + */ + disableCustomColors: boolean; + /** + * Whether or not the custom font sizes are disabled. + */ + disableCustomFontSizes: boolean; + /** + * Whether or not the custom post formats are disabled. + */ + disablePostFormats: boolean; + /** + * Whether or not the custom fields are enabled. + */ + enableCustomFields: boolean; + /** + * Whether the focus mode is enabled or not. + */ + focusMode: boolean; + /** + * Array of available font sizes. + */ + fontSizes: Array<{ + name: string; + size: number; + slug: string; + }>; + /** + * Whether or not the editor toolbar is fixed. + */ + hasFixedToolbar: boolean; + /** + * Whether or not the user is able to manage widgets. + */ + hasPermissionsToManageWidgets: boolean; + /** + * Available image sizes. + */ + imageSizes: Array<{ + name: string; + slug: string; + }>; + /** + * Whether the editor is in RTL mode. + */ + isRTL: boolean; + maxUploadFileSize: number; + /** + * Max width to constraint resizing. + */ + maxWidth: number; + postLock: { + isLocked: boolean; + user: null | string; + }; + postLockUtils: { + nonce: string; + unlockNonce: string; + ajaxUrl: string; + }; + richEditingEnabled: boolean; + styles: Array<{ + css: string; + }>; + /** + * Empty title placeholder. + * @defaultValue `"Add title"` + */ + titlePlaceholder: string; +} + +export interface MetaboxDescriptor { + id: string; + title: string; +} + +/** + * Initializes and returns an instance of Editor. + * + * The return value of this function is not necessary if we change where we + * call initializeEditor(). This is due to metaBox timing. + * + * @param id - Unique identifier for editor instance. + * @param postType - Post type of the post to edit. + * @param postId - ID of the post to edit. + * @param settings - Editor settings object. + * @param initialEdits - Programmatic edits to apply initially, to be considered as + * non-user-initiated (bypass for unsaved changes prompt). + */ +export function initializeEditor( + id: string, + postType: string, + postId: string | number, + settings?: Partial, + // FIXME: it is unclear what this is + initialEdits?: object +): void; + +/** + * Reinitializes the editor after the user chooses to reboot the editor after + * an unhandled error occurs, replacing previously mounted editor element using + * an initial state from prior to the crash. + * + * @param postType - Post type of the post to edit. + * @param postId - ID of the post to edit. + * @param target - DOM node in which editor is rendered. + * @param settings - Editor settings object. + * @param initialEdits - Programmatic edits to apply initially, to be considered as + * non-user-initiated (bypass for unsaved changes prompt). + */ +export function reinitializeEditor( + postType: string, + postId: string | number, + target: Element, + settings?: Partial, + // FIXME: it is unclear what this is + initialEdits?: object +): void; + +export { + default as PluginBlockSettingsMenuItem, +} from './components/block-settings-menu/plugin-block-settings-menu-item'; +export { default as PluginDocumentSettingPanel } from './components/sidebar/plugin-document-setting-panel'; +export { default as PluginMoreMenuItem } from './components/header/plugin-more-menu-item'; +export { default as PluginPostPublishPanel } from './components/sidebar/plugin-post-publish-panel'; +export { default as PluginPostStatusInfo } from './components/sidebar/plugin-post-status-info'; +export { default as PluginPrePublishPanel } from './components/sidebar/plugin-pre-publish-panel'; +export { default as PluginSidebar } from './components/sidebar/plugin-sidebar'; +export { default as PluginSidebarMoreMenuItem } from './components/header/plugin-sidebar-more-menu-item'; diff --git a/types/wordpress__edit-post/store/actions.d.ts b/types/wordpress__edit-post/store/actions.d.ts new file mode 100644 index 0000000000..f852f7dabb --- /dev/null +++ b/types/wordpress__edit-post/store/actions.d.ts @@ -0,0 +1,111 @@ +/** + * Signals that the user closed the sidebar. + */ +export function closeGeneralSidebar(): void; + +/** + * Signals that the user closed a modal. + */ +export function closeModal(): void; + +/** + * Signals that the user closed the publish sidebar. + */ +export function closePublishSidebar(): void; + +/** + * Signals that block types by the given name(s) should be hidden. + * + * @param blockNames - Names of block types to hide. + */ +export function hideBlockTypes(blockNames: string | string[]): void; + +/** + * Signals a successful meta box update. + */ +export function metaBoxUpdatesSuccess(): void; + +/** + * Signals that the user opened an editor sidebar. + * + * @param name - Sidebar name to be opened. + */ +export function openGeneralSidebar(name: string): void; + +/** + * Signals that the user opened a modal. + * + * @param name - A string that uniquely identifies the modal. + */ +export function openModal(name: string): void; + +/** + * Signals that the user opened the publish sidebar. + */ +export function openPublishSidebar(): void; + +/** + * Remove a panel from the editor. + * + * @param panelName - A string that identifies the panel to remove. + */ +export function removeEditorPanel(panelName: string): void; + +/** + * Request meta box updates. + */ +export function requestMetaBoxUpdates(): void; + +/** + * Signals what Meta boxes are available in which location. + * + * @param metaBoxesPerLocation - Meta boxes per location. + */ +export function setAvailableMetaBoxesPerLocation(metaBoxesPerLocation: object): void; + +/** + * Signals that block types by the given name(s) should be shown. + * + * @param blockNames - Names of block types to show. + */ +export function showBlockTypes(blockNames: string | string[]): void; + +/** + * Switches editor mode. + * + * @param mode - The mode to switch to. + */ +export function switchEditorMode(mode: 'text' | 'visual'): void; + +/** + * Enables or disables a panel in the editor. + * + * @param panelName - A string that identifies the panel to enable or disable. + */ +export function toggleEditorPanelEnabled(panelName: string): void; + +/** + * Opens or closes a panel in the editor. + * + * @param panelName - A string that identifies the panel to open or close. + */ +export function toggleEditorPanelOpened(panelName: string): void; + +/** + * Toggles a feature flag. + * + * @param feature - Feature name. + */ +export function toggleFeature(feature: string): void; + +/** + * Toggles a pinned plugin item. + * + * @param pluginName - Plugin name. + */ +export function togglePinnedPluginItem(pluginName: string): void; + +/** + * Signals that the user toggled the publish sidebar. + */ +export function togglePublishSidebar(): void; diff --git a/types/wordpress__edit-post/store/selectors.d.ts b/types/wordpress__edit-post/store/selectors.d.ts new file mode 100644 index 0000000000..9aa220c4bf --- /dev/null +++ b/types/wordpress__edit-post/store/selectors.d.ts @@ -0,0 +1,136 @@ +import { EditorMode, MetaboxDescriptor, MetaboxLocation } from '../'; + +/** + * Returns the current active general sidebar name, or `null` if there is no general sidebar active. + * + * @remarks + * The active general sidebar is a unique name to identify either an editor or plugin sidebar. + * + * Examples: + * - `edit-post/document` + * - `my-plugin/insert-image-sidebar` + */ +export function getActiveGeneralSidebarName(): string | null; + +/** + * Returns an array of active meta box locations. + */ +export function getActiveMetaBoxLocations(): MetaboxLocation[]; + +/** + * Returns the list of all the available meta boxes. + */ +export function getAllMetaBoxes(): MetaboxDescriptor[]; + +/** + * Returns the current editing mode. + */ +export function getEditorMode(): EditorMode; + +/** + * Returns the list of all the available meta boxes for a given location. + * + * @param location - Meta box location to test. + */ +export function getMetaBoxesPerLocation(location: MetaboxLocation): MetaboxDescriptor[] | undefined; + +/** + * Returns the value of a given preference. + * + * @param preferenceKey - Preference Key. + * @param [defaultValue] - Default Value. + */ +export function getPreference(preferenceKey: string): T | undefined; // tslint:disable-line:no-unnecessary-generics +export function getPreference( + preferenceKey: string, + defaultValue: T +): T extends string ? string : T extends number ? number : T; + +/** + * Returns the preferences (these preferences are persisted locally). + */ +export function getPreferences(): Record; + +/** + * Returns `true` if the post is using Meta Boxes, `false` otherwise. + */ +export function hasMetaBoxes(): boolean; + +/** + * Returns `true` if the given panel is enabled, or `false` otherwise. Panels are enabled by + * default. + * + * @param panelName - A string that identifies the panel. + */ +export function isEditorPanelEnabled(panelName: string): boolean; + +/** + * Returns `true` if the given panel is open, or `false` otherwise. Panels are closed by default. + * + * @param panelName - A string that identifies the panel. + */ +export function isEditorPanelOpened(panelName: string): boolean; + +/** + * Returns `true` if the given panel was programmatically removed, or `false` otherwise. All panels + * are not removed by default. + * + * @param panelName - A string that identifies the panel. + */ +export function isEditorPanelRemoved(panelName: string): boolean; + +/** + * Returns `true` if the editor sidebar is opened, `false` otherwise. + */ +export function isEditorSidebarOpened(): boolean; + +/** + * Returns whether the given feature is enabled or not. + * + * @param feature - Feature slug. + */ +export function isFeatureActive(feature: string): boolean; + +/** + * Returns `true` if there is an active meta box in the given location, or `false` otherwise. + * + * @param location - Meta box location to test. + */ +export function isMetaBoxLocationActive(location: MetaboxLocation): boolean; + +/** + * Returns `true` if a metabox location is active and visible, `false` otherwise. + * + * @param location - Meta box location to test. + */ +export function isMetaBoxLocationVisible(location: MetaboxLocation): boolean; + +/** + * Returns `true` if a modal is active, or `false` otherwise. + * + * @param modalName - A string that uniquely identifies the modal. + */ +export function isModalActive(modalName: string): boolean; + +/** + * Returns `true` if the plugin item is pinned to the header. When the value is not set it defaults + * to `true`. + * + * @param pluginName - Plugin item name. + */ +export function isPluginItemPinned(pluginName: string): boolean; + +/** + * Returns `true` if the plugin sidebar is opened, `false` otherwise. + */ +export function isPluginSidebarOpened(): boolean; + +/** + * Returns `true` if the publish sidebar is opened, `false` otherwise. + */ +export function isPublishSidebarOpened(): boolean; + +/** + * Returns `true` if the Meta Boxes are being saved, `false` otherwise. + */ +export function isSavingMetaBoxes(): boolean; diff --git a/types/wordpress__edit-post/tsconfig.json b/types/wordpress__edit-post/tsconfig.json new file mode 100644 index 0000000000..24a09c28dc --- /dev/null +++ b/types/wordpress__edit-post/tsconfig.json @@ -0,0 +1,38 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["dom", "es6"], + "jsx": "preserve", + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "paths": { + "@wordpress/data": ["wordpress__data"], + "@wordpress/components": ["wordpress__components"], + "@wordpress/edit-post": ["wordpress__edit-post"], + "@wordpress/element": ["wordpress__element"], + "@wordpress/notices": ["wordpress__notices"], + "@wordpress/rich-text": ["wordpress__rich-text"] + } + }, + "files": [ + "components/block-settings-menu/plugin-block-settings-menu-item.d.ts", + "components/header/plugin-more-menu-item.d.ts", + "components/header/plugin-sidebar-more-menu-item.d.ts", + "components/sidebar/plugin-document-setting-panel.d.ts", + "components/sidebar/plugin-post-publish-panel.d.ts", + "components/sidebar/plugin-post-status-info.d.ts", + "components/sidebar/plugin-pre-publish-panel.d.ts", + "components/sidebar/plugin-sidebar.d.ts", + "index.d.ts", + "store/actions.d.ts", + "store/selectors.d.ts", + "wordpress__edit-post-tests.tsx" + ] +} diff --git a/types/wordpress__edit-post/tslint.json b/types/wordpress__edit-post/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/wordpress__edit-post/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/wordpress__edit-post/wordpress__edit-post-tests.tsx b/types/wordpress__edit-post/wordpress__edit-post-tests.tsx new file mode 100644 index 0000000000..a2301889a1 --- /dev/null +++ b/types/wordpress__edit-post/wordpress__edit-post-tests.tsx @@ -0,0 +1,129 @@ +import { dispatch, select } from '@wordpress/data'; +import * as ep from '@wordpress/edit-post'; + +// $ExpectType void +ep.initializeEditor('abc', 'post', '123'); + +// $ExpectType void +ep.initializeEditor('abc', 'post', 123, {}); + +// $ExpectType void +ep.initializeEditor('abc', 'post', '123', { alignWide: true, disableCustomColors: true }, { foo: 'bar' }); + +// $ExpectType void +ep.reinitializeEditor('post', '123', document.createElement('div')); + +// $ExpectType void +ep.reinitializeEditor('post', 123, document.createElement('div'), {}); + +// $ExpectType void +ep.reinitializeEditor('post', 123, document.createElement('div'), { codeEditingEnabled: true }); + +// +// PluginBlockSettingsMenuItem +// + console.log('clicked')} +/>; + + console.log('clicked')} />; + +// +// PluginDocumentSettingPanel +// + +

My Document Setting Panel

+
; + + +

My Document Setting Panel

+
; + +// +// PluginMoreMenuItem +// + console.log('clicked!')}> + My button title +; + +My anchor title; + +// +// PluginPostPublishPanel +// + + My panel content +; +My panel content; + +// +// PluginPostStatusInfo +// +My post status info; +My post status info; + +// +// PluginPrePublishPanel +// + + My panel content +; +My panel content; + +// +// PluginSidebar +// +foo}> + My sidebar content +; + + My sidebar content +; + +// +// PluginSidebarMoreMenuItem +// + + My sidebar title +; +My sidebar title; + +// +// store +// + +// $ExpectType void +dispatch('core/edit-post').hideBlockTypes('foo'); + +// $ExpectType void +dispatch('core/edit-post').hideBlockTypes(['foo', 'bar']); + +// $ExpectType void +dispatch('core/edit-post').switchEditorMode('visual'); + +// $ExpectType void +dispatch('core/edit-post').toggleFeature('foo'); + +// $ExpectType string | null +select('core/edit-post').getActiveGeneralSidebarName(); + +// $ExpectType MetaboxLocation[] +select('core/edit-post').getActiveMetaBoxLocations(); + +// $ExpectType unknown +select('core/edit-post').getPreference('foo'); + +// $ExpectType string | undefined +select('core/edit-post').getPreference('foo'); + +// $ExpectType number +select('core/edit-post').getPreference('foo', 123); + +// $ExpectType boolean +select('core/edit-post').isMetaBoxLocationActive('advanced'); + +// $ExpectType MetaboxDescriptor[] +select('core/edit-post').getAllMetaBoxes();