Skip to content

Commit

Permalink
Update @wordpress/editor and remove @types/wordpress__editor (#40291)
Browse files Browse the repository at this point in the history
* Update @wordpress/editor to the latest version

* Remove @types/wordpress__editor as it's no longer needed

* Update pnpm-lock.yaml

* Fix TS errors following the update

* Add changelog

* Fix TS error in PluginDocumentSettingPanelAiExcerpt

* Restore file
  • Loading branch information
manzoorwanijk authored Nov 21, 2024
1 parent 2bc0e23 commit 080a900
Show file tree
Hide file tree
Showing 18 changed files with 53 additions and 98 deletions.
62 changes: 13 additions & 49 deletions pnpm-lock.yaml

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
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Fixed TS errors following @wordpress/editor update
3 changes: 1 addition & 2 deletions projects/js-packages/publicize-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@wordpress/dataviews": "4.7.0",
"@wordpress/date": "5.11.0",
"@wordpress/edit-post": "8.11.0",
"@wordpress/editor": "14.11.0",
"@wordpress/editor": "14.12.0",
"@wordpress/element": "6.11.0",
"@wordpress/hooks": "4.11.0",
"@wordpress/html-entities": "4.11.0",
Expand All @@ -63,7 +63,6 @@
"@testing-library/user-event": "14.5.2",
"@types/jest": "29.5.12",
"@types/react": "18.3.12",
"@types/wordpress__editor": "13.6.8",
"@wordpress/babel-plugin-import-jsx-pragma": "5.11.0",
"babel-jest": "29.4.3",
"jest": "29.7.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { useCallback } from '@wordpress/element';
* @return {Function} Function to handle autosaving and redirecting.
*/
export function useAutoSaveAndRedirect(): React.DOMAttributes< HTMLAnchorElement >[ 'onClick' ] {
// @ts-expect-error -- `@wordpress/editor` is a nightmare to work with TypeScript
const { isEditedPostDirty } = useSelect( editorStore, [] );
const { autosave } = useDispatch( editorStore );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export function PostPublishShareStatus() {
const _editorStore = select( editorStore );

return {
// @ts-expect-error -- `@wordpress/editor` is a nightmare to work with TypeScript
isPostPublished: _editorStore.isCurrentPostPublished(),
};
}, [] );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useSelect } from '@wordpress/data';
import { store as editorStore } from '@wordpress/editor';
import { useCallback } from '@wordpress/element';
import { usePostMeta } from '../../hooks/use-post-meta';

Expand All @@ -11,9 +12,7 @@ export function useShareButtonText() {
const { shareMessage } = usePostMeta();
const { message, link } = useSelect(
select => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const getEditedPostAttribute = ( select( 'core/editor' ) as any )
.getEditedPostAttribute satisfies ( attribute: string ) => unknown;
const { getEditedPostAttribute } = select( editorStore );

return {
link: getEditedPostAttribute( 'link' ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export type RetryProps = {
*/
export function Retry( { shareItem }: RetryProps ) {
const { recordEvent } = useAnalytics();
// @ts-expect-error -- `@wordpress/editor` is badly typed, causes issue in CI
const postId = useSelect( select => select( editorStore ).getCurrentPostId(), [] );
const connections = useSelect( select => select( socialStore ).getConnections(), [] );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { store, CONNECTION_SERVICE_BLUESKY } from '../../social-store';
const BlueskyPreview = props => {
const { message } = useSocialMediaMessage();
const { content, siteName } = useSelect( select => {
// @ts-expect-error -- `@wordpress/editor` is a nightmare to work with TypeScript
const { getEditedPostAttribute } = select( editorStore );
// @ts-expect-error -- It says, "Property 'getUnstableBase' does not exist..." but it does
const { getUnstableBase } = select( coreStore );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import { features } from '../../utils/constants';
*/
export function usePostCanUseSig() {
const isJetpackSocialNote = useSelect( select => {
const currentPostType = select( editorStore )
// @ts-expect-error -- `@wordpress/editor` is a nightmare to work with TypeScript - getCurrentPostType exists on the editor store
.getCurrentPostType();
const currentPostType = select( editorStore ).getCurrentPostType();

return 'jetpack-social-note' === currentPostType;
}, [] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ import { useEffect, useRef, useState } from '@wordpress/element';
* @return {V} The preserved value.
*/
export function usePostPrePublishValue< V >( value: V ) {
const isPublishing = useSelect(
// @ts-expect-error -- `@wordpress/editor` is a nightmare to work with TypeScript
select => select( editorStore ).isPublishingPost(),
[]
);
const isPublishing = useSelect( select => select( editorStore ).isPublishingPost(), [] );

const [ currentValue, setCurrentValue ] = useState( value );

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Fixed TS errors following @wordpress/editor update
2 changes: 1 addition & 1 deletion projects/packages/videopress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"@wordpress/data": "10.11.0",
"@wordpress/date": "5.11.0",
"@wordpress/dom-ready": "4.11.0",
"@wordpress/editor": "14.11.0",
"@wordpress/editor": "14.12.0",
"@wordpress/element": "6.11.0",
"@wordpress/html-entities": "4.11.0",
"@wordpress/i18n": "5.11.0",
Expand Down
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/changelog/update-wordpress-editor
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Fixed TS errors following @wordpress/editor update
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ThemeProvider } from '@automattic/jetpack-components';
import { useAnalytics } from '@automattic/jetpack-shared-extension-utils';
import { Button, Modal, Icon } from '@wordpress/components';
import { useDispatch, useSelect } from '@wordpress/data';
import { store as editorStore } from '@wordpress/editor';
import { useCallback, useEffect, useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { external } from '@wordpress/icons';
Expand All @@ -24,7 +25,6 @@ import useTranscriptionInserter from './hooks/use-transcription-inserter';
/**
* Types
*/
import type { Block } from '@automattic/jetpack-ai-client';
import type {
RecordingState,
TranscriptionState,
Expand Down Expand Up @@ -62,9 +62,7 @@ export default function VoiceToContentEdit( { clientId } ) {
removeBlock: ( id: string ) => void;
};

const { getBlocks } = useSelect( select => select( 'core/editor' ), [] ) as {
getBlocks: () => Block[];
};
const { getBlocks } = useSelect( select => select( editorStore ), [] );

const destroyBlock = useCallback( () => {
// Remove the block from the editor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import './style.scss';
* Types
*/
import type { CoreSelect, JetpackSettingsContentProps } from './types';
import type * as EditorSelectors from '@wordpress/editor/store/selectors';

const debug = debugFactory( 'jetpack-ai-assistant-plugin:sidebar' );
/**
Expand Down Expand Up @@ -163,7 +162,7 @@ export default function AiAssistantPluginSidebar() {
const { tracks } = useAnalytics();

const isViewable = useSelect( select => {
const postTypeName = ( select( editorStore ) as typeof EditorSelectors ).getCurrentPostType();
const postTypeName = select( editorStore ).getCurrentPostType();
// The coreStore select type lacks the getPostType method, so we need to cast it to the correct type
const postTypeObject = ( select( coreStore ) as unknown as CoreSelect ).getPostType(
postTypeName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useAiSuggestions } from '@automattic/jetpack-ai-client';
import { useAnalytics } from '@automattic/jetpack-shared-extension-utils';
import { Button } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { store as editorStore } from '@wordpress/editor';
import { useCallback, useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import React from 'react';
Expand All @@ -14,10 +15,6 @@ import React from 'react';
import usePostContent from '../../hooks/use-post-content';
import AiAssistantModal from '../modal';
import './style.scss';
/**
* Types
*/
import type * as EditorSelectors from '@wordpress/editor/store/selectors';

export default function Feedback( {
disabled = false,
Expand All @@ -32,10 +29,7 @@ export default function Feedback( {
const [ suggestion, setSuggestion ] = useState< Array< React.JSX.Element | null > >( [ null ] );
const { tracks } = useAnalytics();

const postId = useSelect(
select => ( select( 'core/editor' ) as typeof EditorSelectors ).getCurrentPostId(),
[]
);
const postId = useSelect( select => select( editorStore ).getCurrentPostId(), [] );
const postContent = usePostContent();

const toggleFeedbackModal = () => {
Expand Down
Loading

0 comments on commit 080a900

Please sign in to comment.