Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/block-editor/src/components/link-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useRef, useState, useEffect } from '@wordpress/element';
import { focus } from '@wordpress/dom';
import { ENTER } from '@wordpress/keycodes';
import { isShallowEqualObjects } from '@wordpress/is-shallow-equal';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
Expand All @@ -24,6 +25,7 @@ import useCreatePage from './use-create-page';
import useInternalValue from './use-internal-value';
import { ViewerFill } from './viewer-slot';
import { DEFAULT_LINK_SETTINGS } from './constants';
import { store as blockEditorStore } from '../../store';

/**
* Default properties associated with a link control value.
Expand Down Expand Up @@ -133,14 +135,24 @@ function LinkControl( {
withCreateSuggestion = true;
}

// Preference is supplied by the relevant editor.
const settingsDrawerStatePreference = useSelect(
( select ) =>
select( blockEditorStore ).getSettings()
.linkControlAdvancedSettingsPreference,
[]
);

const isMounting = useRef( true );
const wrapperNode = useRef();
const textInputRef = useRef();
const isEndingEditWithFocus = useRef( false );

const settingsKeys = settings.map( ( { id } ) => id );

const [ settingsOpen, setSettingsOpen ] = useState( false );
const [ settingsOpen, setSettingsOpen ] = useState(
settingsDrawerStatePreference
);

const [
internalControlValue,
Expand Down
22 changes: 18 additions & 4 deletions packages/edit-post/src/components/preferences-modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { __ } from '@wordpress/i18n';
import { useViewportMatch } from '@wordpress/compose';
import { useSelect, useDispatch } from '@wordpress/data';
import { useMemo } from '@wordpress/element';
import { useMemo, useCallback } from '@wordpress/element';
import {
PostTaxonomies,
PostExcerptCheck,
Expand Down Expand Up @@ -69,12 +69,17 @@ export default function EditPostPreferencesModal() {

const { set: setPreference } = useDispatch( preferencesStore );

const toggleDistractionFree = () => {
const toggleDistractionFree = useCallback( () => {
setPreference( 'core/edit-post', 'fixedToolbar', false );
setIsInserterOpened( false );
setIsListViewOpened( false );
closeGeneralSidebar();
};
}, [
closeGeneralSidebar,
setIsInserterOpened,
setIsListViewOpened,
setPreference,
] );

const sections = useMemo(
() => [
Expand Down Expand Up @@ -152,6 +157,15 @@ export default function EditPostPreferencesModal() {
label={ __( 'Display block breadcrumbs' ) }
/>
) }
<EnableFeature
featureName="linkControlSettingsDrawer"
help={ __(
`Toggles advanced link creation settings.`
) }
label={ __(
'Always open advanced link settings'
) }
/>
</PreferencesModalSection>
</>
),
Expand Down Expand Up @@ -252,7 +266,7 @@ export default function EditPostPreferencesModal() {
),
},
],
[ isLargeViewport, showBlockBreadcrumbsOption ]
[ isLargeViewport, showBlockBreadcrumbsOption, toggleDistractionFree ]
);

if ( ! isModalActive ) {
Expand Down
12 changes: 11 additions & 1 deletion packages/edit-post/src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function Editor( { postId, postType, settings, initialEdits, ...props } ) {
keepCaretInsideBlock,
isTemplateMode,
template,
linkControlAdvancedSettingsPreference,
} = useSelect(
( select ) => {
const {
Expand Down Expand Up @@ -79,6 +80,8 @@ function Editor( { postId, postType, settings, initialEdits, ...props } ) {
const isViewable = getPostType( postType )?.viewable ?? false;
const canEditTemplate = canUser( 'create', 'templates' );

const prefsStore = select( preferencesStore );

return {
hasFixedToolbar:
isFeatureActive( 'fixedToolbar' ) ||
Expand All @@ -87,10 +90,15 @@ function Editor( { postId, postType, settings, initialEdits, ...props } ) {
isDistractionFree: isFeatureActive( 'distractionFree' ),
hasInlineToolbar: isFeatureActive( 'inlineToolbar' ),
hasThemeStyles: isFeatureActive( 'themeStyles' ),
preferredStyleVariations: select( preferencesStore ).get(
preferredStyleVariations: prefsStore.get(
'core/edit-post',
'preferredStyleVariations'
),
linkControlAdvancedSettingsPreference:
prefsStore.get(
'core/edit-post',
'linkControlSettingsDrawer'
) ?? false,
hiddenBlockTypes: getHiddenBlockTypes(),
blockTypes: getBlockTypes(),
keepCaretInsideBlock: isFeatureActive( 'keepCaretInsideBlock' ),
Expand Down Expand Up @@ -126,6 +134,7 @@ function Editor( { postId, postType, settings, initialEdits, ...props } ) {
// Keep a reference of the `allowedBlockTypes` from the server to handle use cases
// where we need to differentiate if a block is disabled by the user or some plugin.
defaultAllowedBlockTypes: settings.allowedBlockTypes,
linkControlAdvancedSettingsPreference,
};

// Omit hidden block types if exists and non-empty.
Expand Down Expand Up @@ -156,6 +165,7 @@ function Editor( { postId, postType, settings, initialEdits, ...props } ) {
setIsInserterOpened,
updatePreferredStyleVariations,
keepCaretInsideBlock,
linkControlAdvancedSettingsPreference,
] );

const styles = useMemo( () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { store as coreStore } from '@wordpress/core-data';
import { store as editSiteStore } from '../../store';
import { unlock } from '../../lock-unlock';
import inserterMediaCategories from './inserter-media-categories';
import { store as preferencesStore } from '@wordpress/preferences';

export default function useSiteEditorSettings( templateType ) {
const { storedSettings, canvasMode } = useSelect( ( select ) => {
Expand All @@ -22,6 +23,18 @@ export default function useSiteEditorSettings( templateType ) {
};
}, [] );

const { linkControlAdvancedSettingsPreference } = useSelect( ( select ) => {
const prefsStore = select( preferencesStore );

return {
linkControlAdvancedSettingsPreference:
prefsStore.get(
'core/edit-site',
'linkControlSettingsDrawer'
) ?? false,
};
}, [] );

const settingsBlockPatterns =
storedSettings.__experimentalAdditionalBlockPatterns ?? // WP 6.0
storedSettings.__experimentalBlockPatterns; // WP 5.9
Expand Down Expand Up @@ -82,6 +95,13 @@ export default function useSiteEditorSettings( templateType ) {
__experimentalBlockPatterns: blockPatterns,
__experimentalBlockPatternCategories: blockPatternCategories,
focusMode: canvasMode === 'view' && focusMode ? false : focusMode,
linkControlAdvancedSettingsPreference,
};
}, [ storedSettings, blockPatterns, blockPatternCategories, canvasMode ] );
}, [
storedSettings,
blockPatterns,
blockPatternCategories,
canvasMode,
linkControlAdvancedSettingsPreference,
] );
}
13 changes: 10 additions & 3 deletions packages/edit-site/src/components/preferences-modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
PreferencesModalSection,
store as interfaceStore,
} from '@wordpress/interface';
import { useMemo } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { useSelect, useDispatch, useRegistry } from '@wordpress/data';
import { store as preferencesStore } from '@wordpress/preferences';
Expand Down Expand Up @@ -41,7 +40,7 @@ export default function EditSitePreferencesModal() {
} );
};

const sections = useMemo( () => [
const sections = [
{
name: 'general',
tabLabel: __( 'General' ),
Expand Down Expand Up @@ -86,6 +85,13 @@ export default function EditSitePreferencesModal() {
) }
label={ __( 'Display block breadcrumbs' ) }
/>
<EnableFeature
featureName="linkControlSettingsDrawer"
help={ __(
`Toggle's default open/closed state of the link creation interface's settings drawer.`
) }
label={ __( 'Always open Link UI Settings Drawer' ) }
/>
</PreferencesModalSection>
),
},
Expand All @@ -109,7 +115,8 @@ export default function EditSitePreferencesModal() {
</PreferencesModalSection>
),
},
] );
];

if ( ! isModalActive ) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const BLOCK_EDITOR_SETTINGS = [
'__unstableResolvedAssets',
'__unstableIsBlockBasedTheme',
'behaviors',
'linkControlAdvancedSettingsPreference',
];

/**
Expand Down