@wordpress/block-editor 12.3.12 → 12.3.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/block-controls/use-has-block-controls.js +52 -0
- package/build/components/block-controls/use-has-block-controls.js.map +1 -0
- package/build/components/block-tools/block-contextual-toolbar.js +50 -5
- package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build/components/copy-handler/index.js +2 -0
- package/build/components/copy-handler/index.js.map +1 -1
- package/build/components/global-styles/typography-utils.js +3 -2
- package/build/components/global-styles/typography-utils.js.map +1 -1
- package/build/components/link-control/index.js +47 -6
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/rich-text/index.js +8 -1
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/use-format-types.js +3 -2
- package/build/components/rich-text/use-format-types.js.map +1 -1
- package/build-module/components/block-controls/use-has-block-controls.js +38 -0
- package/build-module/components/block-controls/use-has-block-controls.js.map +1 -0
- package/build-module/components/block-tools/block-contextual-toolbar.js +49 -5
- package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build-module/components/copy-handler/index.js +2 -0
- package/build-module/components/copy-handler/index.js.map +1 -1
- package/build-module/components/global-styles/typography-utils.js +4 -3
- package/build-module/components/global-styles/typography-utils.js.map +1 -1
- package/build-module/components/link-control/index.js +45 -6
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/rich-text/index.js +8 -1
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/use-format-types.js +3 -2
- package/build-module/components/rich-text/use-format-types.js.map +1 -1
- package/build-style/content-rtl.css +5 -7
- package/build-style/content.css +5 -7
- package/build-style/style-rtl.css +28 -6
- package/build-style/style.css +28 -6
- package/package.json +5 -5
- package/src/components/block-controls/use-has-block-controls.js +35 -0
- package/src/components/block-list/content.scss +2 -3
- package/src/components/block-toolbar/style.scss +10 -0
- package/src/components/block-tools/block-contextual-toolbar.js +86 -7
- package/src/components/block-tools/style.scss +34 -10
- package/src/components/copy-handler/index.js +1 -0
- package/src/components/global-styles/test/typography-utils.js +10 -0
- package/src/components/global-styles/typography-utils.js +11 -3
- package/src/components/link-control/README.md +12 -3
- package/src/components/link-control/index.js +43 -6
- package/src/components/link-control/test/index.js +2 -1
- package/src/components/rich-text/index.js +7 -0
- package/src/components/rich-text/use-format-types.js +3 -3
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.useHasAnyBlockControls = useHasAnyBlockControls;
|
|
9
|
+
exports.useHasBlockControls = useHasBlockControls;
|
|
10
|
+
|
|
11
|
+
var _components = require("@wordpress/components");
|
|
12
|
+
|
|
13
|
+
var _warning = _interopRequireDefault(require("@wordpress/warning"));
|
|
14
|
+
|
|
15
|
+
var _groups = _interopRequireDefault(require("./groups"));
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* WordPress dependencies
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Internal dependencies
|
|
23
|
+
*/
|
|
24
|
+
function useHasAnyBlockControls() {
|
|
25
|
+
let hasAnyBlockControls = false;
|
|
26
|
+
|
|
27
|
+
for (const group in _groups.default) {
|
|
28
|
+
// It is safe to violate the rules of hooks here as the `groups` object
|
|
29
|
+
// is static and will not change length between renders. Do not return
|
|
30
|
+
// early as that will cause the hook to be called a different number of
|
|
31
|
+
// times between renders.
|
|
32
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
33
|
+
if (useHasBlockControls(group)) {
|
|
34
|
+
hasAnyBlockControls = true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return hasAnyBlockControls;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function useHasBlockControls(group = 'default') {
|
|
42
|
+
const Slot = _groups.default[group]?.Slot;
|
|
43
|
+
const fills = (0, _components.__experimentalUseSlotFills)(Slot?.__unstableName);
|
|
44
|
+
|
|
45
|
+
if (!Slot) {
|
|
46
|
+
typeof process !== "undefined" && process.env && process.env.NODE_ENV !== "production" ? (0, _warning.default)(`Unknown BlockControls group "${group}" provided.`) : void 0;
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return !!fills?.length;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=use-has-block-controls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/block-controls/use-has-block-controls.js"],"names":["useHasAnyBlockControls","hasAnyBlockControls","group","groups","useHasBlockControls","Slot","fills","__unstableName","length"],"mappings":";;;;;;;;;;AAGA;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;AAGO,SAASA,sBAAT,GAAkC;AACxC,MAAIC,mBAAmB,GAAG,KAA1B;;AACA,OAAM,MAAMC,KAAZ,IAAqBC,eAArB,EAA8B;AAC7B;AACA;AACA;AACA;AACA;AACA,QAAKC,mBAAmB,CAAEF,KAAF,CAAxB,EAAoC;AACnCD,MAAAA,mBAAmB,GAAG,IAAtB;AACA;AACD;;AACD,SAAOA,mBAAP;AACA;;AAEM,SAASG,mBAAT,CAA8BF,KAAK,GAAG,SAAtC,EAAkD;AACxD,QAAMG,IAAI,GAAGF,gBAAQD,KAAR,GAAiBG,IAA9B;AACA,QAAMC,KAAK,GAAG,4CAAcD,IAAI,EAAEE,cAApB,CAAd;;AACA,MAAK,CAAEF,IAAP,EAAc;AACb,mHAAU,gCAAgCH,KAAO,aAAjD;AACA,WAAO,IAAP;AACA;;AACD,SAAO,CAAC,CAAEI,KAAK,EAAEE,MAAjB;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __experimentalUseSlotFills as useSlotFills } from '@wordpress/components';\nimport warning from '@wordpress/warning';\n\n/**\n * Internal dependencies\n */\nimport groups from './groups';\n\nexport function useHasAnyBlockControls() {\n\tlet hasAnyBlockControls = false;\n\tfor ( const group in groups ) {\n\t\t// It is safe to violate the rules of hooks here as the `groups` object\n\t\t// is static and will not change length between renders. Do not return\n\t\t// early as that will cause the hook to be called a different number of\n\t\t// times between renders.\n\t\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\t\tif ( useHasBlockControls( group ) ) {\n\t\t\thasAnyBlockControls = true;\n\t\t}\n\t}\n\treturn hasAnyBlockControls;\n}\n\nexport function useHasBlockControls( group = 'default' ) {\n\tconst Slot = groups[ group ]?.Slot;\n\tconst fills = useSlotFills( Slot?.__unstableName );\n\tif ( ! Slot ) {\n\t\twarning( `Unknown BlockControls group \"${ group }\" provided.` );\n\t\treturn null;\n\t}\n\treturn !! fills?.length;\n}\n"]}
|
|
@@ -31,6 +31,8 @@ var _store = require("../../store");
|
|
|
31
31
|
|
|
32
32
|
var _lockUnlock = require("../../lock-unlock");
|
|
33
33
|
|
|
34
|
+
var _useHasBlockControls = require("../block-controls/use-has-block-controls");
|
|
35
|
+
|
|
34
36
|
/**
|
|
35
37
|
* External dependencies
|
|
36
38
|
*/
|
|
@@ -53,10 +55,10 @@ function BlockContextualToolbar({
|
|
|
53
55
|
const isLargeViewport = (0, _compose.useViewportMatch)('medium');
|
|
54
56
|
const {
|
|
55
57
|
blockType,
|
|
58
|
+
blockEditingMode,
|
|
56
59
|
hasParents,
|
|
57
60
|
showParentSelector,
|
|
58
|
-
selectedBlockClientId
|
|
59
|
-
isContentOnly
|
|
61
|
+
selectedBlockClientId
|
|
60
62
|
} = (0, _data.useSelect)(select => {
|
|
61
63
|
const {
|
|
62
64
|
getBlockName,
|
|
@@ -76,16 +78,59 @@ function BlockContextualToolbar({
|
|
|
76
78
|
return {
|
|
77
79
|
selectedBlockClientId: _selectedBlockClientId,
|
|
78
80
|
blockType: _selectedBlockClientId && getBlockType(getBlockName(_selectedBlockClientId)),
|
|
81
|
+
blockEditingMode: getBlockEditingMode(_selectedBlockClientId),
|
|
79
82
|
hasParents: parents.length,
|
|
80
|
-
isContentOnly: getBlockEditingMode(_selectedBlockClientId) === 'contentOnly',
|
|
81
83
|
showParentSelector: parentBlockType && getBlockEditingMode(firstParentClientId) === 'default' && (0, _blocks.hasBlockSupport)(parentBlockType, '__experimentalParentSelector', true) && selectedBlockClientIds.length <= 1 && getBlockEditingMode(_selectedBlockClientId) === 'default'
|
|
82
84
|
};
|
|
83
85
|
}, []);
|
|
84
86
|
(0, _element.useEffect)(() => {
|
|
85
87
|
setIsCollapsed(false);
|
|
86
88
|
}, [selectedBlockClientId]);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
+
const isLargerThanTabletViewport = (0, _compose.useViewportMatch)('large', '>=');
|
|
90
|
+
const isFullscreen = document.body.classList.contains('is-fullscreen-mode');
|
|
91
|
+
(0, _element.useLayoutEffect)(() => {
|
|
92
|
+
// don't do anything if not fixed toolbar
|
|
93
|
+
if (!isFixed || !blockType) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const blockToolbar = document.querySelector('.block-editor-block-contextual-toolbar');
|
|
98
|
+
|
|
99
|
+
if (!blockToolbar) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (!isLargerThanTabletViewport) {
|
|
104
|
+
// set the width of the toolbar to auto
|
|
105
|
+
blockToolbar.style = {};
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (isCollapsed) {
|
|
110
|
+
// set the width of the toolbar to auto
|
|
111
|
+
blockToolbar.style.width = 'auto';
|
|
112
|
+
return;
|
|
113
|
+
} // get the width of the pinned items in the post editor
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
const pinnedItems = document.querySelector('.edit-post-header__settings'); // get the width of the left header in the site editor
|
|
117
|
+
|
|
118
|
+
const leftHeader = document.querySelector('.edit-site-header-edit-mode__end');
|
|
119
|
+
const computedToolbarStyle = window.getComputedStyle(blockToolbar);
|
|
120
|
+
const computedPinnedItemsStyle = pinnedItems ? window.getComputedStyle(pinnedItems) : false;
|
|
121
|
+
const computedLeftHeaderStyle = leftHeader ? window.getComputedStyle(leftHeader) : false;
|
|
122
|
+
const marginLeft = parseFloat(computedToolbarStyle.marginLeft);
|
|
123
|
+
const pinnedItemsWidth = computedPinnedItemsStyle ? parseFloat(computedPinnedItemsStyle.width) + 10 // 10 is the pinned items padding
|
|
124
|
+
: 0;
|
|
125
|
+
const leftHeaderWidth = computedLeftHeaderStyle ? parseFloat(computedLeftHeaderStyle.width) : 0; // set the new witdth of the toolbar
|
|
126
|
+
|
|
127
|
+
blockToolbar.style.width = `calc(100% - ${leftHeaderWidth + pinnedItemsWidth + marginLeft + (isFullscreen ? 0 : 160) // the width of the admin sidebar expanded
|
|
128
|
+
}px)`;
|
|
129
|
+
}, [isFixed, isLargerThanTabletViewport, isCollapsed, isFullscreen, blockType]);
|
|
130
|
+
const isToolbarEnabled = !blockType || (0, _blocks.hasBlockSupport)(blockType, '__experimentalToolbar', true);
|
|
131
|
+
const hasAnyBlockControls = (0, _useHasBlockControls.useHasAnyBlockControls)();
|
|
132
|
+
|
|
133
|
+
if (!isToolbarEnabled || blockEditingMode !== 'default' && !hasAnyBlockControls) {
|
|
89
134
|
return null;
|
|
90
135
|
} // Shifts the toolbar to make room for the parent block selector.
|
|
91
136
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/block-tools/block-contextual-toolbar.js"],"names":["BlockContextualToolbar","focusOnMount","isFixed","props","isCollapsed","setIsCollapsed","toolbarButtonRef","isLargeViewport","blockType","hasParents","showParentSelector","selectedBlockClientId","isContentOnly","select","getBlockName","getBlockParents","getSelectedBlockClientIds","getBlockEditingMode","blockEditorStore","getBlockType","blocksStore","selectedBlockClientIds","_selectedBlockClientId","parents","firstParentClientId","length","parentBlockName","parentBlockType","classes","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AGF,WAAW,GAAG0B,WAAH,GAAUC,eAH7B;AAIC,IAAA,OAAO,EAAG,MAAM;AACf1B,MAAAA,cAAc,CAAI2B,SAAF,IAAiB,CAAEA,SAArB,CAAd;AACA1B,MAAAA,gBAAgB,CAAC2B,OAAjB,CAAyBC,KAAzB;AACA,KAPF;AAQC,IAAA,KAAK,EACJ9B,WAAW,GACR,cAAI,kBAAJ,CADQ,GAER,cAAI,kBAAJ;AAXL,IAPD,CATF,CADD;AAmCA;;eAEcJ,sB","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useEffect, useRef, useState } from '@wordpress/element';\nimport { hasBlockSupport, store as blocksStore } from '@wordpress/blocks';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tToolbarItem,\n\tToolbarButton,\n\tToolbarGroup,\n} from '@wordpress/components';\nimport { next, previous } from '@wordpress/icons';\nimport { useViewportMatch } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport NavigableToolbar from '../navigable-toolbar';\nimport BlockToolbar from '../block-toolbar';\nimport { store as blockEditorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\nfunction BlockContextualToolbar( { focusOnMount, isFixed, ...props } ) {\n\t// When the toolbar is fixed it can be collapsed\n\tconst [ isCollapsed, setIsCollapsed ] = useState( false );\n\tconst toolbarButtonRef = useRef();\n\n\tconst isLargeViewport = useViewportMatch( 'medium' );\n\tconst {\n\t\tblockType,\n\t\thasParents,\n\t\tshowParentSelector,\n\t\tselectedBlockClientId,\n\t\tisContentOnly,\n\t} = useSelect( ( select ) => {\n\t\tconst {\n\t\t\tgetBlockName,\n\t\t\tgetBlockParents,\n\t\t\tgetSelectedBlockClientIds,\n\t\t\tgetBlockEditingMode,\n\t\t} = unlock( select( blockEditorStore ) );\n\t\tconst { getBlockType } = select( blocksStore );\n\t\tconst selectedBlockClientIds = getSelectedBlockClientIds();\n\t\tconst _selectedBlockClientId = selectedBlockClientIds[ 0 ];\n\t\tconst parents = getBlockParents( _selectedBlockClientId );\n\t\tconst firstParentClientId = parents[ parents.length - 1 ];\n\t\tconst parentBlockName = getBlockName( firstParentClientId );\n\t\tconst parentBlockType = getBlockType( parentBlockName );\n\n\t\treturn {\n\t\t\tselectedBlockClientId: _selectedBlockClientId,\n\t\t\tblockType:\n\t\t\t\t_selectedBlockClientId &&\n\t\t\t\tgetBlockType( getBlockName( _selectedBlockClientId ) ),\n\t\t\thasParents: parents.length,\n\t\t\tisContentOnly:\n\t\t\t\tgetBlockEditingMode( _selectedBlockClientId ) === 'contentOnly',\n\t\t\tshowParentSelector:\n\t\t\t\tparentBlockType &&\n\t\t\t\tgetBlockEditingMode( firstParentClientId ) === 'default' &&\n\t\t\t\thasBlockSupport(\n\t\t\t\t\tparentBlockType,\n\t\t\t\t\t'__experimentalParentSelector',\n\t\t\t\t\ttrue\n\t\t\t\t) &&\n\t\t\t\tselectedBlockClientIds.length <= 1 &&\n\t\t\t\tgetBlockEditingMode( _selectedBlockClientId ) === 'default',\n\t\t};\n\t}, [] );\n\n\tuseEffect( () => {\n\t\tsetIsCollapsed( false );\n\t}, [ selectedBlockClientId ] );\n\n\tif (\n\t\tisContentOnly ||\n\t\t( blockType &&\n\t\t\t! hasBlockSupport( blockType, '__experimentalToolbar', true ) )\n\t) {\n\t\treturn null;\n\t}\n\n\t// Shifts the toolbar to make room for the parent block selector.\n\tconst classes = classnames( 'block-editor-block-contextual-toolbar', {\n\t\t'has-parent': hasParents && showParentSelector,\n\t\t'is-fixed': isFixed,\n\t\t'is-collapsed': isCollapsed,\n\t} );\n\n\treturn (\n\t\t<NavigableToolbar\n\t\t\tfocusOnMount={ focusOnMount }\n\t\t\tclassName={ classes }\n\t\t\t/* translators: accessibility text for the block toolbar */\n\t\t\taria-label={ __( 'Block tools' ) }\n\t\t\t{ ...props }\n\t\t>\n\t\t\t{ ! isCollapsed && <BlockToolbar hideDragHandle={ isFixed } /> }\n\t\t\t{ isFixed && isLargeViewport && blockType && (\n\t\t\t\t<ToolbarGroup\n\t\t\t\t\tclassName={\n\t\t\t\t\t\tisCollapsed\n\t\t\t\t\t\t\t? 'block-editor-block-toolbar__group-expand-fixed-toolbar'\n\t\t\t\t\t\t\t: 'block-editor-block-toolbar__group-collapse-fixed-toolbar'\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t<ToolbarItem\n\t\t\t\t\t\tas={ ToolbarButton }\n\t\t\t\t\t\tref={ toolbarButtonRef }\n\t\t\t\t\t\ticon={ isCollapsed ? next : previous }\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tsetIsCollapsed( ( collapsed ) => ! collapsed );\n\t\t\t\t\t\t\ttoolbarButtonRef.current.focus();\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tlabel={\n\t\t\t\t\t\t\tisCollapsed\n\t\t\t\t\t\t\t\t? __( 'Show block tools' )\n\t\t\t\t\t\t\t\t: __( 'Hide block tools' )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</ToolbarGroup>\n\t\t\t) }\n\t\t</NavigableToolbar>\n\t);\n}\n\nexport default BlockContextualToolbar;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/block-tools/block-contextual-toolbar.js"],"names":["BlockContextualToolbar","focusOnMount","isFixed","props","isCollapsed","setIsCollapsed","toolbarButtonRef","isLargeViewport","blockType","blockEditingMode","hasParents","showParentSelector","selectedBlockClientId","select","getBlockName","getBlockParents","getSelectedBlockClientIds","getBlockEditingMode","blockEditorStore","getBlockType","blocksStore","selectedBlockClientIds","_selectedBlockClientId","parents","firstParentClientId","length","parentBlockName","parentBlockType","isLargerThanTabletViewport","isFullscreen","document","body","classList","contains","blockToolbar","querySelector","style","width","pinnedItems","leftHeader","computedToolbarStyle","window","getComputedStyle","computedPinnedItemsStyle","computedLeftHeaderStyle","marginLeft","parseFloat","pinnedItemsWidth","leftHeaderWidth","isToolbarEnabled","hasAnyBlockControls","classes","ToolbarButton","next","previous","collapsed","current","focus"],"mappings":";;;;;;;;;AASA;;AANA;;AAKA;;AAOA;;AACA;;AACA;;AAKA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AAhCA;AACA;AACA;;AAGA;AACA;AACA;;AAkBA;AACA;AACA;AAOA,SAASA,sBAAT,CAAiC;AAAEC,EAAAA,YAAF;AAAgBC,EAAAA,OAAhB;AAAyB,KAAGC;AAA5B,CAAjC,EAAuE;AACtE;AACA,QAAM,CAAEC,WAAF,EAAeC,cAAf,IAAkC,uBAAU,KAAV,CAAxC;AACA,QAAMC,gBAAgB,GAAG,sBAAzB;AAEA,QAAMC,eAAe,GAAG,+BAAkB,QAAlB,CAAxB;AACA,QAAM;AACLC,IAAAA,SADK;AAELC,IAAAA,gBAFK;AAGLC,IAAAA,UAHK;AAILC,IAAAA,kBAJK;AAKLC,IAAAA;AALK,MAMF,qBAAaC,MAAF,IAAc;AAC5B,UAAM;AACLC,MAAAA,YADK;AAELC,MAAAA,eAFK;AAGLC,MAAAA,yBAHK;AAILC,MAAAA;AAJK,QAKF,wBAAQJ,MAAM,CAAEK,YAAF,CAAd,CALJ;AAMA,UAAM;AAAEC,MAAAA;AAAF,QAAmBN,MAAM,CAAEO,aAAF,CAA/B;AACA,UAAMC,sBAAsB,GAAGL,yBAAyB,EAAxD;AACA,UAAMM,sBAAsB,GAAGD,sBAAsB,CAAE,CAAF,CAArD;AACA,UAAME,OAAO,GAAGR,eAAe,CAAEO,sBAAF,CAA/B;AACA,UAAME,mBAAmB,GAAGD,OAAO,CAAEA,OAAO,CAACE,MAAR,GAAiB,CAAnB,CAAnC;AACA,UAAMC,eAAe,GAAGZ,YAAY,CAAEU,mBAAF,CAApC;AACA,UAAMG,eAAe,GAAGR,YAAY,CAAEO,eAAF,CAApC;AAEA,WAAO;AACNd,MAAAA,qBAAqB,EAAEU,sBADjB;AAENd,MAAAA,SAAS,EACRc,sBAAsB,IACtBH,YAAY,CAAEL,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;AAMA,SACC,4BAAC,yBAAD;AACC,IAAA,YAAY,EAAGH,YADhB;AAEC,IAAA,SAAS,EAAGkD;AACZ;AAHD;AAIC,kBAAa,cAAI,aAAJ,CAJd;AAAA,OAKMhD;AALN,KAOG,CAAEC,WAAF,IAAiB,4BAAC,qBAAD;AAAc,IAAA,cAAc,EAAGF;AAA/B,IAPpB,EAQGA,OAAO,IAAIK,eAAX,IAA8BC,SAA9B,IACD,4BAAC,wBAAD;AACC,IAAA,SAAS,EACRJ,WAAW,GACR,wDADQ,GAER;AAJL,KAOC,4BAAC,uBAAD;AACC,IAAA,EAAE,EAAGgD,yBADN;AAEC,IAAA,GAAG,EAAG9C,gBAFP;AAGC,IAAA,IAAI,EAAGF,WAAW,GAAGiD,WAAH,GAAUC,eAH7B;AAIC,IAAA,OAAO,EAAG,MAAM;AACfjD,MAAAA,cAAc,CAAIkD,SAAF,IAAiB,CAAEA,SAArB,CAAd;AACAjD,MAAAA,gBAAgB,CAACkD,OAAjB,CAAyBC,KAAzB;AACA,KAPF;AAQC,IAAA,KAAK,EACJrD,WAAW,GACR,cAAI,kBAAJ,CADQ,GAER,cAAI,kBAAJ;AAXL,IAPD,CATF,CADD;AAmCA;;eAEcJ,sB","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\tuseLayoutEffect,\n\tuseEffect,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport { hasBlockSupport, store as blocksStore } from '@wordpress/blocks';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tToolbarItem,\n\tToolbarButton,\n\tToolbarGroup,\n} from '@wordpress/components';\nimport { next, previous } from '@wordpress/icons';\nimport { useViewportMatch } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport NavigableToolbar from '../navigable-toolbar';\nimport BlockToolbar from '../block-toolbar';\nimport { store as blockEditorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\nimport { useHasAnyBlockControls } from '../block-controls/use-has-block-controls';\n\nfunction BlockContextualToolbar( { focusOnMount, isFixed, ...props } ) {\n\t// When the toolbar is fixed it can be collapsed\n\tconst [ isCollapsed, setIsCollapsed ] = useState( false );\n\tconst toolbarButtonRef = useRef();\n\n\tconst isLargeViewport = useViewportMatch( 'medium' );\n\tconst {\n\t\tblockType,\n\t\tblockEditingMode,\n\t\thasParents,\n\t\tshowParentSelector,\n\t\tselectedBlockClientId,\n\t} = useSelect( ( select ) => {\n\t\tconst {\n\t\t\tgetBlockName,\n\t\t\tgetBlockParents,\n\t\t\tgetSelectedBlockClientIds,\n\t\t\tgetBlockEditingMode,\n\t\t} = unlock( select( blockEditorStore ) );\n\t\tconst { getBlockType } = select( blocksStore );\n\t\tconst selectedBlockClientIds = getSelectedBlockClientIds();\n\t\tconst _selectedBlockClientId = selectedBlockClientIds[ 0 ];\n\t\tconst parents = getBlockParents( _selectedBlockClientId );\n\t\tconst firstParentClientId = parents[ parents.length - 1 ];\n\t\tconst parentBlockName = getBlockName( firstParentClientId );\n\t\tconst parentBlockType = getBlockType( parentBlockName );\n\n\t\treturn {\n\t\t\tselectedBlockClientId: _selectedBlockClientId,\n\t\t\tblockType:\n\t\t\t\t_selectedBlockClientId &&\n\t\t\t\tgetBlockType( getBlockName( _selectedBlockClientId ) ),\n\t\t\tblockEditingMode: getBlockEditingMode( _selectedBlockClientId ),\n\t\t\thasParents: parents.length,\n\t\t\tshowParentSelector:\n\t\t\t\tparentBlockType &&\n\t\t\t\tgetBlockEditingMode( firstParentClientId ) === 'default' &&\n\t\t\t\thasBlockSupport(\n\t\t\t\t\tparentBlockType,\n\t\t\t\t\t'__experimentalParentSelector',\n\t\t\t\t\ttrue\n\t\t\t\t) &&\n\t\t\t\tselectedBlockClientIds.length <= 1 &&\n\t\t\t\tgetBlockEditingMode( _selectedBlockClientId ) === 'default',\n\t\t};\n\t}, [] );\n\n\tuseEffect( () => {\n\t\tsetIsCollapsed( false );\n\t}, [ selectedBlockClientId ] );\n\n\tconst isLargerThanTabletViewport = useViewportMatch( 'large', '>=' );\n\tconst isFullscreen =\n\t\tdocument.body.classList.contains( 'is-fullscreen-mode' );\n\n\tuseLayoutEffect( () => {\n\t\t// don't do anything if not fixed toolbar\n\t\tif ( ! isFixed || ! blockType ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst blockToolbar = document.querySelector(\n\t\t\t'.block-editor-block-contextual-toolbar'\n\t\t);\n\n\t\tif ( ! blockToolbar ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! isLargerThanTabletViewport ) {\n\t\t\t// set the width of the toolbar to auto\n\t\t\tblockToolbar.style = {};\n\t\t\treturn;\n\t\t}\n\n\t\tif ( isCollapsed ) {\n\t\t\t// set the width of the toolbar to auto\n\t\t\tblockToolbar.style.width = 'auto';\n\t\t\treturn;\n\t\t}\n\n\t\t// get the width of the pinned items in the post editor\n\t\tconst pinnedItems = document.querySelector(\n\t\t\t'.edit-post-header__settings'\n\t\t);\n\n\t\t// get the width of the left header in the site editor\n\t\tconst leftHeader = document.querySelector(\n\t\t\t'.edit-site-header-edit-mode__end'\n\t\t);\n\n\t\tconst computedToolbarStyle = window.getComputedStyle( blockToolbar );\n\t\tconst computedPinnedItemsStyle = pinnedItems\n\t\t\t? window.getComputedStyle( pinnedItems )\n\t\t\t: false;\n\t\tconst computedLeftHeaderStyle = leftHeader\n\t\t\t? window.getComputedStyle( leftHeader )\n\t\t\t: false;\n\n\t\tconst marginLeft = parseFloat( computedToolbarStyle.marginLeft );\n\t\tconst pinnedItemsWidth = computedPinnedItemsStyle\n\t\t\t? parseFloat( computedPinnedItemsStyle.width ) + 10 // 10 is the pinned items padding\n\t\t\t: 0;\n\t\tconst leftHeaderWidth = computedLeftHeaderStyle\n\t\t\t? parseFloat( computedLeftHeaderStyle.width )\n\t\t\t: 0;\n\n\t\t// set the new witdth of the toolbar\n\t\tblockToolbar.style.width = `calc(100% - ${\n\t\t\tleftHeaderWidth +\n\t\t\tpinnedItemsWidth +\n\t\t\tmarginLeft +\n\t\t\t( isFullscreen ? 0 : 160 ) // the width of the admin sidebar expanded\n\t\t}px)`;\n\t}, [\n\t\tisFixed,\n\t\tisLargerThanTabletViewport,\n\t\tisCollapsed,\n\t\tisFullscreen,\n\t\tblockType,\n\t] );\n\n\tconst isToolbarEnabled =\n\t\t! blockType ||\n\t\thasBlockSupport( blockType, '__experimentalToolbar', true );\n\tconst hasAnyBlockControls = useHasAnyBlockControls();\n\tif (\n\t\t! isToolbarEnabled ||\n\t\t( blockEditingMode !== 'default' && ! hasAnyBlockControls )\n\t) {\n\t\treturn null;\n\t}\n\n\t// Shifts the toolbar to make room for the parent block selector.\n\tconst classes = classnames( 'block-editor-block-contextual-toolbar', {\n\t\t'has-parent': hasParents && showParentSelector,\n\t\t'is-fixed': isFixed,\n\t\t'is-collapsed': isCollapsed,\n\t} );\n\n\treturn (\n\t\t<NavigableToolbar\n\t\t\tfocusOnMount={ focusOnMount }\n\t\t\tclassName={ classes }\n\t\t\t/* translators: accessibility text for the block toolbar */\n\t\t\taria-label={ __( 'Block tools' ) }\n\t\t\t{ ...props }\n\t\t>\n\t\t\t{ ! isCollapsed && <BlockToolbar hideDragHandle={ isFixed } /> }\n\t\t\t{ isFixed && isLargeViewport && blockType && (\n\t\t\t\t<ToolbarGroup\n\t\t\t\t\tclassName={\n\t\t\t\t\t\tisCollapsed\n\t\t\t\t\t\t\t? 'block-editor-block-toolbar__group-expand-fixed-toolbar'\n\t\t\t\t\t\t\t: 'block-editor-block-toolbar__group-collapse-fixed-toolbar'\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t<ToolbarItem\n\t\t\t\t\t\tas={ ToolbarButton }\n\t\t\t\t\t\tref={ toolbarButtonRef }\n\t\t\t\t\t\ticon={ isCollapsed ? next : previous }\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tsetIsCollapsed( ( collapsed ) => ! collapsed );\n\t\t\t\t\t\t\ttoolbarButtonRef.current.focus();\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tlabel={\n\t\t\t\t\t\t\tisCollapsed\n\t\t\t\t\t\t\t\t? __( 'Show block tools' )\n\t\t\t\t\t\t\t\t: __( 'Hide block tools' )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</ToolbarGroup>\n\t\t\t) }\n\t\t</NavigableToolbar>\n\t);\n}\n\nexport default BlockContextualToolbar;\n"]}
|
|
@@ -167,6 +167,8 @@ function useClipboardHandler() {
|
|
|
167
167
|
if (shouldHandleWholeBlocks && !expandSelectionIsNeeded) {
|
|
168
168
|
removeBlocks(selectedBlockClientIds);
|
|
169
169
|
} else {
|
|
170
|
+
event.target.ownerDocument.activeElement.contentEditable = false;
|
|
171
|
+
|
|
170
172
|
__unstableDeleteSelection();
|
|
171
173
|
}
|
|
172
174
|
} else if (event.type === 'paste') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/copy-handler/index.js"],"names":["useNotifyCopy","getBlockName","blockEditorStore","getBlockType","blocksStore","createSuccessNotice","noticesStore","eventType","selectedBlockClientIds","notice","length","clientId","title","type","useClipboardHandler","getBlocksByClientId","getSelectedBlockClientIds","hasMultiSelection","getSettings","__unstableIsFullySelected","__unstableIsSelectionCollapsed","__unstableIsSelectionMergeable","__unstableGetSelectedBlocksWithPartialSelection","canInsertBlockType","flashBlock","removeBlocks","replaceBlocks","__unstableDeleteSelection","__unstableExpandSelection","insertBlocks","notifyCopy","node","handler","event","defaultPrevented","target","ownerDocument","hasSelection","contains","activeElement","preventDefault","isSelectionMergeable","shouldHandleWholeBlocks","expandSelectionIsNeeded","blocks","head","tail","inBetweenBlocks","slice","wrapperBlockName","clipboardData","getData","JSON","parse","serialized","setData","toPlainText","__experimentalCanUserUseUnfilteredHTML","canUserUseUnfilteredHTML","plainText","html","files","fromTransforms","reduce","accumulator","file","transformation","transform","isMatch","push","flat","HTML","mode","selectedBlockClientId","every","block","name","undefined","addEventListener","removeEventListener","CopyHandler","children","replace","trim"],"mappings":";;;;;;;;;AAGA;;AACA;;AAQA;;AAKA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AA1BA;AACA;AACA;;AAoBA;AACA;AACA;AAIO,SAASA,aAAT,GAAyB;AAC/B,QAAM;AAAEC,IAAAA;AAAF,MAAmB,qBAAWC,YAAX,CAAzB;AACA,QAAM;AAAEC,IAAAA;AAAF,MAAmB,qBAAWC,aAAX,CAAzB;AACA,QAAM;AAAEC,IAAAA;AAAF,MAA0B,uBAAaC,cAAb,CAAhC;AAEA,SAAO,0BAAa,CAAEC,SAAF,EAAaC,sBAAb,KAAyC;AAC5D,QAAIC,MAAM,GAAG,EAAb;;AACA,QAAKD,sBAAsB,CAACE,MAAvB,KAAkC,CAAvC,EAA2C;AAC1C,YAAMC,QAAQ,GAAGH,sBAAsB,CAAE,CAAF,CAAvC;AACA,YAAMI,KAAK,GAAGT,YAAY,CAAEF,YAAY,CAAEU,QAAF,CAAd,CAAZ,EAA0CC,KAAxD;AACAH,MAAAA,MAAM,GACLF,SAAS,KAAK,MAAd,GACG,oBACA;AACA,oBAAI,2BAAJ,CAFA,EAGAK,KAHA,CADH,GAMG,oBACA;AACA,oBAAI,0BAAJ,CAFA,EAGAA,KAHA,CAPJ;AAYA,KAfD,MAeO;AACNH,MAAAA,MAAM,GACLF,SAAS,KAAK,MAAd,GACG,oBACA;AACA,oBACC,+BADD,EAEC,gCAFD,EAGCC,sBAAsB,CAACE,MAHxB,CAFA,EAOAF,sBAAsB,CAACE,MAPvB,CADH,GAUG,oBACA;AACA,oBACC,8BADD,EAEC,+BAFD,EAGCF,sBAAsB,CAACE,MAHxB,CAFA,EAOAF,sBAAsB,CAACE,MAPvB,CAXJ;AAoBA;;AACDL,IAAAA,mBAAmB,CAAEI,MAAF,EAAU;AAC5BI,MAAAA,IAAI,EAAE;AADsB,KAAV,CAAnB;AAGA,GA1CM,EA0CJ,EA1CI,CAAP;AA2CA;;AAEM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EAAAA;AAAF,CAAtB,EAAqC;AACpC,SAAO;AAAK,IAAA,GAAG,EAAGnE,mBAAmB;AAA9B,KAAqCmE,QAArC,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASzB,WAAT,CAAsBI,IAAtB,EAA6B;AAC5B;AACAA,EAAAA,IAAI,GAAGA,IAAI,CAACsB,OAAL,CAAc,OAAd,EAAuB,IAAvB,CAAP;AAEA,QAAMvB,SAAS,GAAG,8BAAWC,IAAX,EAAkBuB,IAAlB,EAAlB,CAJ4B,CAM5B;;AACA,SAAOxB,SAAS,CAACuB,OAAV,CAAmB,QAAnB,EAA6B,MAA7B,CAAP;AACA;AAED;AACA;AACA;;;eACeF,W","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback } from '@wordpress/element';\nimport {\n\tserialize,\n\tpasteHandler,\n\tstore as blocksStore,\n\tcreateBlock,\n\tfindTransform,\n\tgetBlockTransforms,\n} from '@wordpress/blocks';\nimport {\n\tdocumentHasSelection,\n\tdocumentHasUncollapsedSelection,\n\t__unstableStripHTML as stripHTML,\n} from '@wordpress/dom';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __, _n, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { getPasteEventData } from '../../utils/pasting';\nimport { store as blockEditorStore } from '../../store';\n\nexport function useNotifyCopy() {\n\tconst { getBlockName } = useSelect( blockEditorStore );\n\tconst { getBlockType } = useSelect( blocksStore );\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\n\treturn useCallback( ( eventType, selectedBlockClientIds ) => {\n\t\tlet notice = '';\n\t\tif ( selectedBlockClientIds.length === 1 ) {\n\t\t\tconst clientId = selectedBlockClientIds[ 0 ];\n\t\t\tconst title = getBlockType( getBlockName( clientId ) )?.title;\n\t\t\tnotice =\n\t\t\t\teventType === 'copy'\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t// Translators: Name of the block being copied, e.g. \"Paragraph\".\n\t\t\t\t\t\t\t__( 'Copied \"%s\" to clipboard.' ),\n\t\t\t\t\t\t\ttitle\n\t\t\t\t\t )\n\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t// Translators: Name of the block being cut, e.g. \"Paragraph\".\n\t\t\t\t\t\t\t__( 'Moved \"%s\" to clipboard.' ),\n\t\t\t\t\t\t\ttitle\n\t\t\t\t\t );\n\t\t} else {\n\t\t\tnotice =\n\t\t\t\teventType === 'copy'\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t// Translators: %d: Number of blocks being copied.\n\t\t\t\t\t\t\t_n(\n\t\t\t\t\t\t\t\t'Copied %d block to clipboard.',\n\t\t\t\t\t\t\t\t'Copied %d blocks to clipboard.',\n\t\t\t\t\t\t\t\tselectedBlockClientIds.length\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tselectedBlockClientIds.length\n\t\t\t\t\t )\n\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t// Translators: %d: Number of blocks being cut.\n\t\t\t\t\t\t\t_n(\n\t\t\t\t\t\t\t\t'Moved %d block to clipboard.',\n\t\t\t\t\t\t\t\t'Moved %d blocks to clipboard.',\n\t\t\t\t\t\t\t\tselectedBlockClientIds.length\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tselectedBlockClientIds.length\n\t\t\t\t\t );\n\t\t}\n\t\tcreateSuccessNotice( notice, {\n\t\t\ttype: 'snackbar',\n\t\t} );\n\t}, [] );\n}\n\nexport function useClipboardHandler() {\n\tconst {\n\t\tgetBlocksByClientId,\n\t\tgetSelectedBlockClientIds,\n\t\thasMultiSelection,\n\t\tgetSettings,\n\t\t__unstableIsFullySelected,\n\t\t__unstableIsSelectionCollapsed,\n\t\t__unstableIsSelectionMergeable,\n\t\t__unstableGetSelectedBlocksWithPartialSelection,\n\t\tcanInsertBlockType,\n\t} = useSelect( blockEditorStore );\n\tconst {\n\t\tflashBlock,\n\t\tremoveBlocks,\n\t\treplaceBlocks,\n\t\t__unstableDeleteSelection,\n\t\t__unstableExpandSelection,\n\t\tinsertBlocks,\n\t} = useDispatch( blockEditorStore );\n\tconst notifyCopy = useNotifyCopy();\n\n\treturn useRefEffect( ( node ) => {\n\t\tfunction handler( event ) {\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\t// This was likely already handled in rich-text/use-paste-handler.js.\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst selectedBlockClientIds = getSelectedBlockClientIds();\n\n\t\t\tif ( selectedBlockClientIds.length === 0 ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Always handle multiple selected blocks.\n\t\t\tif ( ! hasMultiSelection() ) {\n\t\t\t\tconst { target } = event;\n\t\t\t\tconst { ownerDocument } = target;\n\t\t\t\t// If copying, only consider actual text selection as selection.\n\t\t\t\t// Otherwise, any focus on an input field is considered.\n\t\t\t\tconst hasSelection =\n\t\t\t\t\tevent.type === 'copy' || event.type === 'cut'\n\t\t\t\t\t\t? documentHasUncollapsedSelection( ownerDocument )\n\t\t\t\t\t\t: documentHasSelection( ownerDocument );\n\n\t\t\t\t// Let native copy behaviour take over in input fields.\n\t\t\t\tif ( hasSelection ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( ! node.contains( event.target.ownerDocument.activeElement ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tevent.preventDefault();\n\n\t\t\tconst isSelectionMergeable = __unstableIsSelectionMergeable();\n\t\t\tconst shouldHandleWholeBlocks =\n\t\t\t\t__unstableIsSelectionCollapsed() || __unstableIsFullySelected();\n\t\t\tconst expandSelectionIsNeeded =\n\t\t\t\t! shouldHandleWholeBlocks && ! isSelectionMergeable;\n\t\t\tif ( event.type === 'copy' || event.type === 'cut' ) {\n\t\t\t\tif ( selectedBlockClientIds.length === 1 ) {\n\t\t\t\t\tflashBlock( selectedBlockClientIds[ 0 ] );\n\t\t\t\t}\n\t\t\t\t// If we have a partial selection that is not mergeable, just\n\t\t\t\t// expand the selection to the whole blocks.\n\t\t\t\tif ( expandSelectionIsNeeded ) {\n\t\t\t\t\t__unstableExpandSelection();\n\t\t\t\t} else {\n\t\t\t\t\tnotifyCopy( event.type, selectedBlockClientIds );\n\t\t\t\t\tlet blocks;\n\t\t\t\t\t// Check if we have partial selection.\n\t\t\t\t\tif ( shouldHandleWholeBlocks ) {\n\t\t\t\t\t\tblocks = getBlocksByClientId( selectedBlockClientIds );\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst [ head, tail ] =\n\t\t\t\t\t\t\t__unstableGetSelectedBlocksWithPartialSelection();\n\t\t\t\t\t\tconst inBetweenBlocks = getBlocksByClientId(\n\t\t\t\t\t\t\tselectedBlockClientIds.slice(\n\t\t\t\t\t\t\t\t1,\n\t\t\t\t\t\t\t\tselectedBlockClientIds.length - 1\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t\tblocks = [ head, ...inBetweenBlocks, tail ];\n\t\t\t\t\t}\n\n\t\t\t\t\tconst wrapperBlockName = event.clipboardData.getData(\n\t\t\t\t\t\t'__unstableWrapperBlockName'\n\t\t\t\t\t);\n\n\t\t\t\t\tif ( wrapperBlockName ) {\n\t\t\t\t\t\tblocks = createBlock(\n\t\t\t\t\t\t\twrapperBlockName,\n\t\t\t\t\t\t\tJSON.parse(\n\t\t\t\t\t\t\t\tevent.clipboardData.getData(\n\t\t\t\t\t\t\t\t\t'__unstableWrapperBlockAttributes'\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tblocks\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst serialized = serialize( blocks );\n\n\t\t\t\t\tevent.clipboardData.setData(\n\t\t\t\t\t\t'text/plain',\n\t\t\t\t\t\ttoPlainText( serialized )\n\t\t\t\t\t);\n\t\t\t\t\tevent.clipboardData.setData( 'text/html', serialized );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( event.type === 'cut' ) {\n\t\t\t\t// We need to also check if at the start we needed to\n\t\t\t\t// expand the selection, as in this point we might have\n\t\t\t\t// programmatically fully selected the blocks above.\n\t\t\t\tif ( shouldHandleWholeBlocks && ! expandSelectionIsNeeded ) {\n\t\t\t\t\tremoveBlocks( selectedBlockClientIds );\n\t\t\t\t} else {\n\t\t\t\t\t__unstableDeleteSelection();\n\t\t\t\t}\n\t\t\t} else if ( event.type === 'paste' ) {\n\t\t\t\tconst {\n\t\t\t\t\t__experimentalCanUserUseUnfilteredHTML:\n\t\t\t\t\t\tcanUserUseUnfilteredHTML,\n\t\t\t\t} = getSettings();\n\t\t\t\tconst { plainText, html, files } = getPasteEventData( event );\n\t\t\t\tlet blocks = [];\n\n\t\t\t\tif ( files.length ) {\n\t\t\t\t\tconst fromTransforms = getBlockTransforms( 'from' );\n\t\t\t\t\tblocks = files\n\t\t\t\t\t\t.reduce( ( accumulator, file ) => {\n\t\t\t\t\t\t\tconst transformation = findTransform(\n\t\t\t\t\t\t\t\tfromTransforms,\n\t\t\t\t\t\t\t\t( transform ) =>\n\t\t\t\t\t\t\t\t\ttransform.type === 'files' &&\n\t\t\t\t\t\t\t\t\ttransform.isMatch( [ file ] )\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tif ( transformation ) {\n\t\t\t\t\t\t\t\taccumulator.push(\n\t\t\t\t\t\t\t\t\ttransformation.transform( [ file ] )\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn accumulator;\n\t\t\t\t\t\t}, [] )\n\t\t\t\t\t\t.flat();\n\t\t\t\t} else {\n\t\t\t\t\tblocks = pasteHandler( {\n\t\t\t\t\t\tHTML: html,\n\t\t\t\t\t\tplainText,\n\t\t\t\t\t\tmode: 'BLOCKS',\n\t\t\t\t\t\tcanUserUseUnfilteredHTML,\n\t\t\t\t\t} );\n\t\t\t\t}\n\n\t\t\t\tif ( selectedBlockClientIds.length === 1 ) {\n\t\t\t\t\tconst [ selectedBlockClientId ] = selectedBlockClientIds;\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tblocks.every( ( block ) =>\n\t\t\t\t\t\t\tcanInsertBlockType(\n\t\t\t\t\t\t\t\tblock.name,\n\t\t\t\t\t\t\t\tselectedBlockClientId\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\tinsertBlocks(\n\t\t\t\t\t\t\tblocks,\n\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\tselectedBlockClientId\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treplaceBlocks(\n\t\t\t\t\tselectedBlockClientIds,\n\t\t\t\t\tblocks,\n\t\t\t\t\tblocks.length - 1,\n\t\t\t\t\t-1\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tnode.ownerDocument.addEventListener( 'copy', handler );\n\t\tnode.ownerDocument.addEventListener( 'cut', handler );\n\t\tnode.ownerDocument.addEventListener( 'paste', handler );\n\n\t\treturn () => {\n\t\t\tnode.ownerDocument.removeEventListener( 'copy', handler );\n\t\t\tnode.ownerDocument.removeEventListener( 'cut', handler );\n\t\t\tnode.ownerDocument.removeEventListener( 'paste', handler );\n\t\t};\n\t}, [] );\n}\n\nfunction CopyHandler( { children } ) {\n\treturn <div ref={ useClipboardHandler() }>{ children }</div>;\n}\n\n/**\n * Given a string of HTML representing serialized blocks, returns the plain\n * text extracted after stripping the HTML of any tags and fixing line breaks.\n *\n * @param {string} html Serialized blocks.\n * @return {string} The plain-text content with any html removed.\n */\nfunction toPlainText( html ) {\n\t// Manually handle BR tags as line breaks prior to `stripHTML` call\n\thtml = html.replace( /<br>/g, '\\n' );\n\n\tconst plainText = stripHTML( html ).trim();\n\n\t// Merge any consecutive line breaks\n\treturn plainText.replace( /\\n\\n+/g, '\\n\\n' );\n}\n\n/**\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/copy-handler/README.md\n */\nexport default CopyHandler;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/copy-handler/index.js"],"names":["useNotifyCopy","getBlockName","blockEditorStore","getBlockType","blocksStore","createSuccessNotice","noticesStore","eventType","selectedBlockClientIds","notice","length","clientId","title","type","useClipboardHandler","getBlocksByClientId","getSelectedBlockClientIds","hasMultiSelection","getSettings","__unstableIsFullySelected","__unstableIsSelectionCollapsed","__unstableIsSelectionMergeable","__unstableGetSelectedBlocksWithPartialSelection","canInsertBlockType","flashBlock","removeBlocks","replaceBlocks","__unstableDeleteSelection","__unstableExpandSelection","insertBlocks","notifyCopy","node","handler","event","defaultPrevented","target","ownerDocument","hasSelection","contains","activeElement","preventDefault","isSelectionMergeable","shouldHandleWholeBlocks","expandSelectionIsNeeded","blocks","head","tail","inBetweenBlocks","slice","wrapperBlockName","clipboardData","getData","JSON","parse","serialized","setData","toPlainText","contentEditable","__experimentalCanUserUseUnfilteredHTML","canUserUseUnfilteredHTML","plainText","html","files","fromTransforms","reduce","accumulator","file","transformation","transform","isMatch","push","flat","HTML","mode","selectedBlockClientId","every","block","name","undefined","addEventListener","removeEventListener","CopyHandler","children","replace","trim"],"mappings":";;;;;;;;;AAGA;;AACA;;AAQA;;AAKA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AA1BA;AACA;AACA;;AAoBA;AACA;AACA;AAIO,SAASA,aAAT,GAAyB;AAC/B,QAAM;AAAEC,IAAAA;AAAF,MAAmB,qBAAWC,YAAX,CAAzB;AACA,QAAM;AAAEC,IAAAA;AAAF,MAAmB,qBAAWC,aAAX,CAAzB;AACA,QAAM;AAAEC,IAAAA;AAAF,MAA0B,uBAAaC,cAAb,CAAhC;AAEA,SAAO,0BAAa,CAAEC,SAAF,EAAaC,sBAAb,KAAyC;AAC5D,QAAIC,MAAM,GAAG,EAAb;;AACA,QAAKD,sBAAsB,CAACE,MAAv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AAV,CAAmB,QAAnB,EAA6B,MAA7B,CAAP;AACA;AAED;AACA;AACA;;;eACeF,W","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback } from '@wordpress/element';\nimport {\n\tserialize,\n\tpasteHandler,\n\tstore as blocksStore,\n\tcreateBlock,\n\tfindTransform,\n\tgetBlockTransforms,\n} from '@wordpress/blocks';\nimport {\n\tdocumentHasSelection,\n\tdocumentHasUncollapsedSelection,\n\t__unstableStripHTML as stripHTML,\n} from '@wordpress/dom';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __, _n, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { getPasteEventData } from '../../utils/pasting';\nimport { store as blockEditorStore } from '../../store';\n\nexport function useNotifyCopy() {\n\tconst { getBlockName } = useSelect( blockEditorStore );\n\tconst { getBlockType } = useSelect( blocksStore );\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\n\treturn useCallback( ( eventType, selectedBlockClientIds ) => {\n\t\tlet notice = '';\n\t\tif ( selectedBlockClientIds.length === 1 ) {\n\t\t\tconst clientId = selectedBlockClientIds[ 0 ];\n\t\t\tconst title = getBlockType( getBlockName( clientId ) )?.title;\n\t\t\tnotice =\n\t\t\t\teventType === 'copy'\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t// Translators: Name of the block being copied, e.g. \"Paragraph\".\n\t\t\t\t\t\t\t__( 'Copied \"%s\" to clipboard.' ),\n\t\t\t\t\t\t\ttitle\n\t\t\t\t\t )\n\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t// Translators: Name of the block being cut, e.g. \"Paragraph\".\n\t\t\t\t\t\t\t__( 'Moved \"%s\" to clipboard.' ),\n\t\t\t\t\t\t\ttitle\n\t\t\t\t\t );\n\t\t} else {\n\t\t\tnotice =\n\t\t\t\teventType === 'copy'\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t// Translators: %d: Number of blocks being copied.\n\t\t\t\t\t\t\t_n(\n\t\t\t\t\t\t\t\t'Copied %d block to clipboard.',\n\t\t\t\t\t\t\t\t'Copied %d blocks to clipboard.',\n\t\t\t\t\t\t\t\tselectedBlockClientIds.length\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tselectedBlockClientIds.length\n\t\t\t\t\t )\n\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t// Translators: %d: Number of blocks being cut.\n\t\t\t\t\t\t\t_n(\n\t\t\t\t\t\t\t\t'Moved %d block to clipboard.',\n\t\t\t\t\t\t\t\t'Moved %d blocks to clipboard.',\n\t\t\t\t\t\t\t\tselectedBlockClientIds.length\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tselectedBlockClientIds.length\n\t\t\t\t\t );\n\t\t}\n\t\tcreateSuccessNotice( notice, {\n\t\t\ttype: 'snackbar',\n\t\t} );\n\t}, [] );\n}\n\nexport function useClipboardHandler() {\n\tconst {\n\t\tgetBlocksByClientId,\n\t\tgetSelectedBlockClientIds,\n\t\thasMultiSelection,\n\t\tgetSettings,\n\t\t__unstableIsFullySelected,\n\t\t__unstableIsSelectionCollapsed,\n\t\t__unstableIsSelectionMergeable,\n\t\t__unstableGetSelectedBlocksWithPartialSelection,\n\t\tcanInsertBlockType,\n\t} = useSelect( blockEditorStore );\n\tconst {\n\t\tflashBlock,\n\t\tremoveBlocks,\n\t\treplaceBlocks,\n\t\t__unstableDeleteSelection,\n\t\t__unstableExpandSelection,\n\t\tinsertBlocks,\n\t} = useDispatch( blockEditorStore );\n\tconst notifyCopy = useNotifyCopy();\n\n\treturn useRefEffect( ( node ) => {\n\t\tfunction handler( event ) {\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\t// This was likely already handled in rich-text/use-paste-handler.js.\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst selectedBlockClientIds = getSelectedBlockClientIds();\n\n\t\t\tif ( selectedBlockClientIds.length === 0 ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Always handle multiple selected blocks.\n\t\t\tif ( ! hasMultiSelection() ) {\n\t\t\t\tconst { target } = event;\n\t\t\t\tconst { ownerDocument } = target;\n\t\t\t\t// If copying, only consider actual text selection as selection.\n\t\t\t\t// Otherwise, any focus on an input field is considered.\n\t\t\t\tconst hasSelection =\n\t\t\t\t\tevent.type === 'copy' || event.type === 'cut'\n\t\t\t\t\t\t? documentHasUncollapsedSelection( ownerDocument )\n\t\t\t\t\t\t: documentHasSelection( ownerDocument );\n\n\t\t\t\t// Let native copy behaviour take over in input fields.\n\t\t\t\tif ( hasSelection ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( ! node.contains( event.target.ownerDocument.activeElement ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tevent.preventDefault();\n\n\t\t\tconst isSelectionMergeable = __unstableIsSelectionMergeable();\n\t\t\tconst shouldHandleWholeBlocks =\n\t\t\t\t__unstableIsSelectionCollapsed() || __unstableIsFullySelected();\n\t\t\tconst expandSelectionIsNeeded =\n\t\t\t\t! shouldHandleWholeBlocks && ! isSelectionMergeable;\n\t\t\tif ( event.type === 'copy' || event.type === 'cut' ) {\n\t\t\t\tif ( selectedBlockClientIds.length === 1 ) {\n\t\t\t\t\tflashBlock( selectedBlockClientIds[ 0 ] );\n\t\t\t\t}\n\t\t\t\t// If we have a partial selection that is not mergeable, just\n\t\t\t\t// expand the selection to the whole blocks.\n\t\t\t\tif ( expandSelectionIsNeeded ) {\n\t\t\t\t\t__unstableExpandSelection();\n\t\t\t\t} else {\n\t\t\t\t\tnotifyCopy( event.type, selectedBlockClientIds );\n\t\t\t\t\tlet blocks;\n\t\t\t\t\t// Check if we have partial selection.\n\t\t\t\t\tif ( shouldHandleWholeBlocks ) {\n\t\t\t\t\t\tblocks = getBlocksByClientId( selectedBlockClientIds );\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst [ head, tail ] =\n\t\t\t\t\t\t\t__unstableGetSelectedBlocksWithPartialSelection();\n\t\t\t\t\t\tconst inBetweenBlocks = getBlocksByClientId(\n\t\t\t\t\t\t\tselectedBlockClientIds.slice(\n\t\t\t\t\t\t\t\t1,\n\t\t\t\t\t\t\t\tselectedBlockClientIds.length - 1\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t\tblocks = [ head, ...inBetweenBlocks, tail ];\n\t\t\t\t\t}\n\n\t\t\t\t\tconst wrapperBlockName = event.clipboardData.getData(\n\t\t\t\t\t\t'__unstableWrapperBlockName'\n\t\t\t\t\t);\n\n\t\t\t\t\tif ( wrapperBlockName ) {\n\t\t\t\t\t\tblocks = createBlock(\n\t\t\t\t\t\t\twrapperBlockName,\n\t\t\t\t\t\t\tJSON.parse(\n\t\t\t\t\t\t\t\tevent.clipboardData.getData(\n\t\t\t\t\t\t\t\t\t'__unstableWrapperBlockAttributes'\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tblocks\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst serialized = serialize( blocks );\n\n\t\t\t\t\tevent.clipboardData.setData(\n\t\t\t\t\t\t'text/plain',\n\t\t\t\t\t\ttoPlainText( serialized )\n\t\t\t\t\t);\n\t\t\t\t\tevent.clipboardData.setData( 'text/html', serialized );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( event.type === 'cut' ) {\n\t\t\t\t// We need to also check if at the start we needed to\n\t\t\t\t// expand the selection, as in this point we might have\n\t\t\t\t// programmatically fully selected the blocks above.\n\t\t\t\tif ( shouldHandleWholeBlocks && ! expandSelectionIsNeeded ) {\n\t\t\t\t\tremoveBlocks( selectedBlockClientIds );\n\t\t\t\t} else {\n\t\t\t\t\tevent.target.ownerDocument.activeElement.contentEditable = false;\n\t\t\t\t\t__unstableDeleteSelection();\n\t\t\t\t}\n\t\t\t} else if ( event.type === 'paste' ) {\n\t\t\t\tconst {\n\t\t\t\t\t__experimentalCanUserUseUnfilteredHTML:\n\t\t\t\t\t\tcanUserUseUnfilteredHTML,\n\t\t\t\t} = getSettings();\n\t\t\t\tconst { plainText, html, files } = getPasteEventData( event );\n\t\t\t\tlet blocks = [];\n\n\t\t\t\tif ( files.length ) {\n\t\t\t\t\tconst fromTransforms = getBlockTransforms( 'from' );\n\t\t\t\t\tblocks = files\n\t\t\t\t\t\t.reduce( ( accumulator, file ) => {\n\t\t\t\t\t\t\tconst transformation = findTransform(\n\t\t\t\t\t\t\t\tfromTransforms,\n\t\t\t\t\t\t\t\t( transform ) =>\n\t\t\t\t\t\t\t\t\ttransform.type === 'files' &&\n\t\t\t\t\t\t\t\t\ttransform.isMatch( [ file ] )\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tif ( transformation ) {\n\t\t\t\t\t\t\t\taccumulator.push(\n\t\t\t\t\t\t\t\t\ttransformation.transform( [ file ] )\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn accumulator;\n\t\t\t\t\t\t}, [] )\n\t\t\t\t\t\t.flat();\n\t\t\t\t} else {\n\t\t\t\t\tblocks = pasteHandler( {\n\t\t\t\t\t\tHTML: html,\n\t\t\t\t\t\tplainText,\n\t\t\t\t\t\tmode: 'BLOCKS',\n\t\t\t\t\t\tcanUserUseUnfilteredHTML,\n\t\t\t\t\t} );\n\t\t\t\t}\n\n\t\t\t\tif ( selectedBlockClientIds.length === 1 ) {\n\t\t\t\t\tconst [ selectedBlockClientId ] = selectedBlockClientIds;\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tblocks.every( ( block ) =>\n\t\t\t\t\t\t\tcanInsertBlockType(\n\t\t\t\t\t\t\t\tblock.name,\n\t\t\t\t\t\t\t\tselectedBlockClientId\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\tinsertBlocks(\n\t\t\t\t\t\t\tblocks,\n\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\tselectedBlockClientId\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treplaceBlocks(\n\t\t\t\t\tselectedBlockClientIds,\n\t\t\t\t\tblocks,\n\t\t\t\t\tblocks.length - 1,\n\t\t\t\t\t-1\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tnode.ownerDocument.addEventListener( 'copy', handler );\n\t\tnode.ownerDocument.addEventListener( 'cut', handler );\n\t\tnode.ownerDocument.addEventListener( 'paste', handler );\n\n\t\treturn () => {\n\t\t\tnode.ownerDocument.removeEventListener( 'copy', handler );\n\t\t\tnode.ownerDocument.removeEventListener( 'cut', handler );\n\t\t\tnode.ownerDocument.removeEventListener( 'paste', handler );\n\t\t};\n\t}, [] );\n}\n\nfunction CopyHandler( { children } ) {\n\treturn <div ref={ useClipboardHandler() }>{ children }</div>;\n}\n\n/**\n * Given a string of HTML representing serialized blocks, returns the plain\n * text extracted after stripping the HTML of any tags and fixing line breaks.\n *\n * @param {string} html Serialized blocks.\n * @return {string} The plain-text content with any html removed.\n */\nfunction toPlainText( html ) {\n\t// Manually handle BR tags as line breaks prior to `stripHTML` call\n\thtml = html.replace( /<br>/g, '\\n' );\n\n\tconst plainText = stripHTML( html ).trim();\n\n\t// Merge any consecutive line breaks\n\treturn plainText.replace( /\\n\\n+/g, '\\n\\n' );\n}\n\n/**\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/copy-handler/README.md\n */\nexport default CopyHandler;\n"]}
|
|
@@ -103,9 +103,10 @@ function isFluidTypographyEnabled(typographySettings) {
|
|
|
103
103
|
function getFluidTypographyOptionsFromSettings(settings) {
|
|
104
104
|
const typographySettings = settings?.typography;
|
|
105
105
|
const layoutSettings = settings?.layout;
|
|
106
|
-
|
|
106
|
+
const defaultMaxViewportWidth = (0, _fluidUtils.getTypographyValueAndUnit)(layoutSettings?.wideSize) ? layoutSettings?.wideSize : null;
|
|
107
|
+
return isFluidTypographyEnabled(typographySettings) && defaultMaxViewportWidth ? {
|
|
107
108
|
fluid: {
|
|
108
|
-
maxViewPortWidth:
|
|
109
|
+
maxViewPortWidth: defaultMaxViewportWidth,
|
|
109
110
|
...typographySettings.fluid
|
|
110
111
|
}
|
|
111
112
|
} : {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/global-styles/typography-utils.js"],"names":["getTypographyFontSizeValue","preset","typographyOptions","size","defaultSize","isFluidTypographyEnabled","fluid","fluidTypographySettings","fluidFontSizeValue","minimumFontSize","min","maximumFontSize","max","fontSize","minimumFontSizeLimit","minFontSize","maximumViewPortWidth","maxViewPortWidth","typographySettings","fluidSettings","Object","keys","length","getFluidTypographyOptionsFromSettings","settings","typography","layoutSettings","layout","wideSize"],"mappings":";;;;;;;;AASA;;AATA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/global-styles/typography-utils.js"],"names":["getTypographyFontSizeValue","preset","typographyOptions","size","defaultSize","isFluidTypographyEnabled","fluid","fluidTypographySettings","fluidFontSizeValue","minimumFontSize","min","maximumFontSize","max","fontSize","minimumFontSizeLimit","minFontSize","maximumViewPortWidth","maxViewPortWidth","typographySettings","fluidSettings","Object","keys","length","getFluidTypographyOptionsFromSettings","settings","typography","layoutSettings","layout","defaultMaxViewportWidth","wideSize"],"mappings":";;;;;;;;AASA;;AATA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,0BAAT,CAAqCC,MAArC,EAA6CC,iBAA7C,EAAiE;AACvE,QAAM;AAAEC,IAAAA,IAAI,EAAEC;AAAR,MAA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EAAEG,QAHa,GAI7B,IAJH;AAKA,SAAOxB,wBAAwB,CAAEa,kBAAF,CAAxB,IACNU,uBADM,GAEJ;AACAtB,IAAAA,KAAK,EAAE;AACNW,MAAAA,gBAAgB,EAAEW,uBADZ;AAEN,SAAGV,kBAAkB,CAACZ;AAFhB;AADP,GAFI,GAQJ;AACAA,IAAAA,KAAK,EAAEY,kBAAkB,EAAEZ;AAD3B,GARH;AAWA","sourcesContent":["/**\n * The fluid utilities must match the backend equivalent.\n * See: gutenberg_get_typography_font_size_value() in lib/block-supports/typography.php\n * ---------------------------------------------------------------\n */\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetComputedFluidTypographyValue,\n\tgetTypographyValueAndUnit,\n} from '../font-sizes/fluid-utils';\n\n/**\n * @typedef {Object} FluidPreset\n * @property {string|undefined} max A maximum font size value.\n * @property {?string|undefined} min A minimum font size value.\n */\n\n/**\n * @typedef {Object} Preset\n * @property {?string|?number} size A default font size.\n * @property {string} name A font size name, displayed in the UI.\n * @property {string} slug A font size slug\n * @property {boolean|FluidPreset|undefined} fluid Specifies the minimum and maximum font size value of a fluid font size.\n */\n\n/**\n * @typedef {Object} TypographySettings\n * @property {?string} minViewPortWidth Minimum viewport size from which type will have fluidity. Optional if size is specified.\n * @property {?string} maxViewPortWidth Maximum size up to which type will have fluidity. Optional if size is specified.\n * @property {?number} scaleFactor A scale factor to determine how fast a font scales within boundaries. Optional.\n * @property {?number} minFontSizeFactor How much to scale defaultFontSize by to derive minimumFontSize. Optional.\n * @property {?string} minFontSize The smallest a calculated font size may be. Optional.\n */\n\n/**\n * Returns a font-size value based on a given font-size preset.\n * Takes into account fluid typography parameters and attempts to return a css formula depending on available, valid values.\n *\n * @param {Preset} preset\n * @param {Object} typographyOptions\n * @param {boolean|TypographySettings} typographyOptions.fluid Whether fluid typography is enabled, and, optionally, fluid font size options.\n *\n * @return {string|*} A font-size value or the value of preset.size.\n */\nexport function getTypographyFontSizeValue( preset, typographyOptions ) {\n\tconst { size: defaultSize } = preset;\n\n\tif ( ! isFluidTypographyEnabled( typographyOptions ) ) {\n\t\treturn defaultSize;\n\t}\n\t/*\n\t * Checks whether a font size has explicitly bypassed fluid calculations.\n\t * Also catches falsy values and 0/'0'.\n\t * Fluid calculations cannot be performed on `0`.\n\t */\n\tif ( ! defaultSize || '0' === defaultSize || false === preset?.fluid ) {\n\t\treturn defaultSize;\n\t}\n\n\tconst fluidTypographySettings =\n\t\ttypeof typographyOptions?.fluid === 'object'\n\t\t\t? typographyOptions?.fluid\n\t\t\t: {};\n\n\tconst fluidFontSizeValue = getComputedFluidTypographyValue( {\n\t\tminimumFontSize: preset?.fluid?.min,\n\t\tmaximumFontSize: preset?.fluid?.max,\n\t\tfontSize: defaultSize,\n\t\tminimumFontSizeLimit: fluidTypographySettings?.minFontSize,\n\t\tmaximumViewPortWidth: fluidTypographySettings?.maxViewPortWidth,\n\t} );\n\n\tif ( !! fluidFontSizeValue ) {\n\t\treturn fluidFontSizeValue;\n\t}\n\n\treturn defaultSize;\n}\n\nfunction isFluidTypographyEnabled( typographySettings ) {\n\tconst fluidSettings = typographySettings?.fluid;\n\treturn (\n\t\ttrue === fluidSettings ||\n\t\t( fluidSettings &&\n\t\t\ttypeof fluidSettings === 'object' &&\n\t\t\tObject.keys( fluidSettings ).length > 0 )\n\t);\n}\n\n/**\n * Returns fluid typography settings from theme.json setting object.\n *\n * @param {Object} settings Theme.json settings\n * @param {Object} settings.typography Theme.json typography settings\n * @param {Object} settings.layout Theme.json layout settings\n * @return {TypographySettings} Fluid typography settings\n */\nexport function getFluidTypographyOptionsFromSettings( settings ) {\n\tconst typographySettings = settings?.typography;\n\tconst layoutSettings = settings?.layout;\n\tconst defaultMaxViewportWidth = getTypographyValueAndUnit(\n\t\tlayoutSettings?.wideSize\n\t)\n\t\t? layoutSettings?.wideSize\n\t\t: null;\n\treturn isFluidTypographyEnabled( typographySettings ) &&\n\t\tdefaultMaxViewportWidth\n\t\t? {\n\t\t\t\tfluid: {\n\t\t\t\t\tmaxViewPortWidth: defaultMaxViewportWidth,\n\t\t\t\t\t...typographySettings.fluid,\n\t\t\t\t},\n\t\t }\n\t\t: {\n\t\t\t\tfluid: typographySettings?.fluid,\n\t\t };\n}\n"]}
|
|
@@ -21,6 +21,10 @@ var _keycodes = require("@wordpress/keycodes");
|
|
|
21
21
|
|
|
22
22
|
var _isShallowEqual = require("@wordpress/is-shallow-equal");
|
|
23
23
|
|
|
24
|
+
var _data = require("@wordpress/data");
|
|
25
|
+
|
|
26
|
+
var _preferences = require("@wordpress/preferences");
|
|
27
|
+
|
|
24
28
|
var _settingsDrawer = _interopRequireDefault(require("./settings-drawer"));
|
|
25
29
|
|
|
26
30
|
var _searchInput = _interopRequireDefault(require("./search-input"));
|
|
@@ -125,6 +129,9 @@ var _constants = require("./constants");
|
|
|
125
129
|
* @property {Function} renderControlBottom Optional controls to be rendered at the bottom of the component.
|
|
126
130
|
*/
|
|
127
131
|
const noop = () => {};
|
|
132
|
+
|
|
133
|
+
const PREFERENCE_SCOPE = 'core/block-editor';
|
|
134
|
+
const PREFERENCE_KEY = 'linkControlSettingsDrawer';
|
|
128
135
|
/**
|
|
129
136
|
* Renders a link control. A link control is a controlled input which maintains
|
|
130
137
|
* a value associated with a link (HTML anchor element) and relevant settings
|
|
@@ -133,7 +140,6 @@ const noop = () => {};
|
|
|
133
140
|
* @param {WPLinkControlProps} props Component props.
|
|
134
141
|
*/
|
|
135
142
|
|
|
136
|
-
|
|
137
143
|
function LinkControl({
|
|
138
144
|
searchInputPlaceholder,
|
|
139
145
|
value,
|
|
@@ -159,6 +165,43 @@ function LinkControl({
|
|
|
159
165
|
withCreateSuggestion = true;
|
|
160
166
|
}
|
|
161
167
|
|
|
168
|
+
const [settingsOpen, setSettingsOpen] = (0, _element.useState)(false);
|
|
169
|
+
const {
|
|
170
|
+
advancedSettingsPreference
|
|
171
|
+
} = (0, _data.useSelect)(select => {
|
|
172
|
+
var _prefsStore$get;
|
|
173
|
+
|
|
174
|
+
const prefsStore = select(_preferences.store);
|
|
175
|
+
return {
|
|
176
|
+
advancedSettingsPreference: (_prefsStore$get = prefsStore.get(PREFERENCE_SCOPE, PREFERENCE_KEY)) !== null && _prefsStore$get !== void 0 ? _prefsStore$get : false
|
|
177
|
+
};
|
|
178
|
+
}, []);
|
|
179
|
+
const {
|
|
180
|
+
set: setPreference
|
|
181
|
+
} = (0, _data.useDispatch)(_preferences.store);
|
|
182
|
+
/**
|
|
183
|
+
* Sets the open/closed state of the Advanced Settings Drawer,
|
|
184
|
+
* optionlly persisting the state to the user's preferences.
|
|
185
|
+
*
|
|
186
|
+
* Note that Block Editor components can be consumed by non-WordPress
|
|
187
|
+
* environments which may not have preferences setup.
|
|
188
|
+
* Therefore a local state is also used as a fallback.
|
|
189
|
+
*
|
|
190
|
+
* @param {boolean} prefVal the open/closed state of the Advanced Settings Drawer.
|
|
191
|
+
*/
|
|
192
|
+
|
|
193
|
+
const setSettingsOpenWithPreference = prefVal => {
|
|
194
|
+
if (setPreference) {
|
|
195
|
+
setPreference(PREFERENCE_SCOPE, PREFERENCE_KEY, prefVal);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
setSettingsOpen(prefVal);
|
|
199
|
+
}; // Block Editor components can be consumed by non-WordPress environments
|
|
200
|
+
// which may not have these preferences setup.
|
|
201
|
+
// Therefore a local state is used as a fallback.
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
const isSettingsOpen = advancedSettingsPreference || settingsOpen;
|
|
162
205
|
const isMounting = (0, _element.useRef)(true);
|
|
163
206
|
const wrapperNode = (0, _element.useRef)();
|
|
164
207
|
const textInputRef = (0, _element.useRef)();
|
|
@@ -166,7 +209,6 @@ function LinkControl({
|
|
|
166
209
|
const settingsKeys = settings.map(({
|
|
167
210
|
id
|
|
168
211
|
}) => id);
|
|
169
|
-
const [settingsOpen, setSettingsOpen] = (0, _element.useState)(false);
|
|
170
212
|
const [internalControlValue, setInternalControlValue, setInternalURLInputValue, setInternalTextInputValue, createSetInternalSettingValueHandler] = (0, _useInternalValue.default)(value);
|
|
171
213
|
const valueHasChanges = value && !(0, _isShallowEqual.isShallowEqualObjects)(internalControlValue, value);
|
|
172
214
|
const [isEditingLink, setIsEditingLink] = (0, _element.useState)(forceIsEditingLink !== undefined ? forceIsEditingLink : !value || !value.url);
|
|
@@ -208,7 +250,6 @@ function LinkControl({
|
|
|
208
250
|
|
|
209
251
|
const stopEditing = () => {
|
|
210
252
|
isEndingEditWithFocus.current = !!wrapperNode.current?.contains(wrapperNode.current.ownerDocument.activeElement);
|
|
211
|
-
setSettingsOpen(false);
|
|
212
253
|
setIsEditingLink(false);
|
|
213
254
|
};
|
|
214
255
|
|
|
@@ -282,7 +323,6 @@ function LinkControl({
|
|
|
282
323
|
const currentUrlInputValue = propInputValue || internalControlValue?.url || '';
|
|
283
324
|
const currentInputIsEmpty = !currentUrlInputValue?.trim()?.length;
|
|
284
325
|
const shownUnlinkControl = onRemove && value && !isEditingLink && !isCreatingPage;
|
|
285
|
-
const showSettings = !!settings?.length && isEditingLink && hasLinkValue;
|
|
286
326
|
const showActions = isEditingLink && hasLinkValue; // Only show text control once a URL value has been committed
|
|
287
327
|
// and it isn't just empty whitespace.
|
|
288
328
|
// See https://github.com/WordPress/gutenberg/pull/33849/#issuecomment-932194927.
|
|
@@ -290,6 +330,7 @@ function LinkControl({
|
|
|
290
330
|
const showTextControl = hasLinkValue && hasTextControl;
|
|
291
331
|
const isEditing = (isEditingLink || !value) && !isCreatingPage;
|
|
292
332
|
const isDisabled = !valueHasChanges || currentInputIsEmpty;
|
|
333
|
+
const showSettings = !!settings?.length && isEditingLink && hasLinkValue;
|
|
293
334
|
return (0, _element.createElement)("div", {
|
|
294
335
|
tabIndex: -1,
|
|
295
336
|
ref: wrapperNode,
|
|
@@ -341,8 +382,8 @@ function LinkControl({
|
|
|
341
382
|
}), showSettings && (0, _element.createElement)("div", {
|
|
342
383
|
className: "block-editor-link-control__tools"
|
|
343
384
|
}, !currentInputIsEmpty && (0, _element.createElement)(_settingsDrawer.default, {
|
|
344
|
-
settingsOpen:
|
|
345
|
-
setSettingsOpen:
|
|
385
|
+
settingsOpen: isSettingsOpen,
|
|
386
|
+
setSettingsOpen: setSettingsOpenWithPreference
|
|
346
387
|
}, (0, _element.createElement)(_settings.default, {
|
|
347
388
|
value: internalControlValue,
|
|
348
389
|
settings: settings,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/link-control/index.js"],"names":["noop","LinkControl","searchInputPlaceholder","value","settings","DEFAULT_LINK_SETTINGS","onChange","onRemove","onCancel","noDirectEntry","showSuggestions","showInitialSuggestions","forceIsEditingLink","createSuggestion","withCreateSuggestion","inputValue","propInputValue","suggestionsQuery","noURLSuggestion","createSuggestionButtonText","hasRichPreviews","hasTextControl","renderControlBottom","undefined","isMounting","wrapperNode","textInputRef","isEndingEditWithFocus","settingsKeys","map","id","settingsOpen","setSettingsOpen","internalControlValue","setInternalControlValue","setInternalURLInputValue","setInternalTextInputValue","createSetInternalSettingValueHandler","valueHasChanges","isEditingLink","setIsEditingLink","url","createPage","isCreatingPage","errorMessage","current","nextFocusTarget","focus","focusable","find","hasLinkValue","trim","length","stopEditing","contains","ownerDocument","activeElement","handleSelectSuggestion","updatedValue","nonSettingsChanges","Object","keys","reduce","acc","key","includes","title","handleSubmit","currentUrlInputValue","handleSubmitWithEnter","event","keyCode","ENTER","currentInputIsEmpty","preventDefault","resetInternalValues","handleCancel","stopPropagation","shownUnlinkControl","showSettings","showActions","showTextControl","isEditing","isDisabled","ViewerFill"],"mappings":";;;;;;;;;AAUA;;AAPA;;AAKA;;AACA;;AAEA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAzBA;AACA;AACA;;AAGA;AACA;AACA;;AAQA;AACA;AACA;;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AACA;AACA;AACA;AACA;AACA;;AACA;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';\n\n/**\n * WordPress dependencies\n */\nimport { Button, Spinner, Notice, TextControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useRef, useState, useEffect } from '@wordpress/element';\nimport { focus } from '@wordpress/dom';\nimport { ENTER } from '@wordpress/keycodes';\nimport { isShallowEqualObjects } from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport LinkControlSettingsDrawer from './settings-drawer';\nimport LinkControlSearchInput from './search-input';\nimport LinkPreview from './link-preview';\nimport LinkSettings from './settings';\nimport useCreatePage from './use-create-page';\nimport useInternalValue from './use-internal-value';\nimport { ViewerFill } from './viewer-slot';\nimport { DEFAULT_LINK_SETTINGS } from './constants';\n\n/**\n * Default properties associated with a link control value.\n *\n * @typedef WPLinkControlDefaultValue\n *\n * @property {string} url Link URL.\n * @property {string=} title Link title.\n * @property {boolean=} opensInNewTab Whether link should open in a new browser\n * tab. This value is only assigned if not\n * providing a custom `settings` prop.\n */\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * Custom settings values associated with a link.\n *\n * @typedef {{[setting:string]:any}} WPLinkControlSettingsValue\n */\n/* eslint-enable */\n\n/**\n * Custom settings values associated with a link.\n *\n * @typedef WPLinkControlSetting\n *\n * @property {string} id Identifier to use as property for setting value.\n * @property {string} title Human-readable label to show in user interface.\n */\n\n/**\n * Properties associated with a link control value, composed as a union of the\n * default properties and any custom settings values.\n *\n * @typedef {WPLinkControlDefaultValue&WPLinkControlSettingsValue} WPLinkControlValue\n */\n\n/** @typedef {(nextValue:WPLinkControlValue)=>void} WPLinkControlOnChangeProp */\n\n/**\n * Properties associated with a search suggestion used within the LinkControl.\n *\n * @typedef WPLinkControlSuggestion\n *\n * @property {string} id Identifier to use to uniquely identify the suggestion.\n * @property {string} type Identifies the type of the suggestion (eg: `post`,\n * `page`, `url`...etc)\n * @property {string} title Human-readable label to show in user interface.\n * @property {string} url A URL for the suggestion.\n */\n\n/** @typedef {(title:string)=>WPLinkControlSuggestion} WPLinkControlCreateSuggestionProp */\n\n/**\n * @typedef WPLinkControlProps\n *\n * @property {(WPLinkControlSetting[])=} settings An array of settings objects. Each object will used to\n * render a `ToggleControl` for that setting.\n * @property {boolean=} forceIsEditingLink If passed as either `true` or `false`, controls the\n * internal editing state of the component to respective\n * show or not show the URL input field.\n * @property {WPLinkControlValue=} value Current link value.\n * @property {WPLinkControlOnChangeProp=} onChange Value change handler, called with the updated value if\n * the user selects a new link or updates settings.\n * @property {boolean=} noDirectEntry Whether to allow turning a URL-like search query directly into a link.\n * @property {boolean=} showSuggestions Whether to present suggestions when typing the URL.\n * @property {boolean=} showInitialSuggestions Whether to present initial suggestions immediately.\n * @property {boolean=} withCreateSuggestion Whether to allow creation of link value from suggestion.\n * @property {Object=} suggestionsQuery Query parameters to pass along to wp.blockEditor.__experimentalFetchLinkSuggestions.\n * @property {boolean=} noURLSuggestion Whether to add a fallback suggestion which treats the search query as a URL.\n * @property {boolean=} hasTextControl Whether to add a text field to the UI to update the value.title.\n * @property {string|Function|undefined} createSuggestionButtonText The text to use in the button that calls createSuggestion.\n * @property {Function} renderControlBottom Optional controls to be rendered at the bottom of the component.\n */\n\nconst noop = () => {};\n\n/**\n * Renders a link control. A link control is a controlled input which maintains\n * a value associated with a link (HTML anchor element) and relevant settings\n * for how that link is expected to behave.\n *\n * @param {WPLinkControlProps} props Component props.\n */\nfunction LinkControl( {\n\tsearchInputPlaceholder,\n\tvalue,\n\tsettings = DEFAULT_LINK_SETTINGS,\n\tonChange = noop,\n\tonRemove,\n\tonCancel,\n\tnoDirectEntry = false,\n\tshowSuggestions = true,\n\tshowInitialSuggestions,\n\tforceIsEditingLink,\n\tcreateSuggestion,\n\twithCreateSuggestion,\n\tinputValue: propInputValue = '',\n\tsuggestionsQuery = {},\n\tnoURLSuggestion = false,\n\tcreateSuggestionButtonText,\n\thasRichPreviews = false,\n\thasTextControl = false,\n\trenderControlBottom = null,\n} ) {\n\tif ( withCreateSuggestion === undefined && createSuggestion ) {\n\t\twithCreateSuggestion = true;\n\t}\n\n\tconst isMounting = useRef( true );\n\tconst wrapperNode = useRef();\n\tconst textInputRef = useRef();\n\tconst isEndingEditWithFocus = useRef( false );\n\n\tconst settingsKeys = settings.map( ( { id } ) => id );\n\n\tconst [ settingsOpen, setSettingsOpen ] = useState( false );\n\n\tconst [\n\t\tinternalControlValue,\n\t\tsetInternalControlValue,\n\t\tsetInternalURLInputValue,\n\t\tsetInternalTextInputValue,\n\t\tcreateSetInternalSettingValueHandler,\n\t] = useInternalValue( value );\n\n\tconst valueHasChanges =\n\t\tvalue && ! isShallowEqualObjects( internalControlValue, value );\n\n\tconst [ isEditingLink, setIsEditingLink ] = useState(\n\t\tforceIsEditingLink !== undefined\n\t\t\t? forceIsEditingLink\n\t\t\t: ! value || ! value.url\n\t);\n\n\tconst { createPage, isCreatingPage, errorMessage } =\n\t\tuseCreatePage( createSuggestion );\n\n\tuseEffect( () => {\n\t\tif (\n\t\t\tforceIsEditingLink !== undefined &&\n\t\t\tforceIsEditingLink !== isEditingLink\n\t\t) {\n\t\t\tsetIsEditingLink( forceIsEditingLink );\n\t\t}\n\t\t// Todo: bug if the missing dep is introduced. Will need a fix.\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [ forceIsEditingLink ] );\n\n\tuseEffect( () => {\n\t\t// We don't auto focus into the Link UI on mount\n\t\t// because otherwise using the keyboard to select text\n\t\t// *within* the link format is not possible.\n\t\tif ( isMounting.current ) {\n\t\t\tisMounting.current = false;\n\t\t\treturn;\n\t\t}\n\n\t\t// Scenario - when:\n\t\t// - switching between editable and non editable LinkControl\n\t\t// - clicking on a link\n\t\t// ...then move focus to the *first* element to avoid focus loss\n\t\t// and to ensure focus is *within* the Link UI.\n\t\tconst nextFocusTarget =\n\t\t\tfocus.focusable.find( wrapperNode.current )[ 0 ] ||\n\t\t\twrapperNode.current;\n\n\t\tnextFocusTarget.focus();\n\n\t\tisEndingEditWithFocus.current = false;\n\t}, [ isEditingLink, isCreatingPage ] );\n\n\tconst hasLinkValue = value?.url?.trim()?.length > 0;\n\n\t/**\n\t * Cancels editing state and marks that focus may need to be restored after\n\t * the next render, if focus was within the wrapper when editing finished.\n\t */\n\tconst stopEditing = () => {\n\t\tisEndingEditWithFocus.current = !! wrapperNode.current?.contains(\n\t\t\twrapperNode.current.ownerDocument.activeElement\n\t\t);\n\n\t\tsetSettingsOpen( false );\n\t\tsetIsEditingLink( false );\n\t};\n\n\tconst handleSelectSuggestion = ( updatedValue ) => {\n\t\t// Suggestions may contains \"settings\" values (e.g. `opensInNewTab`)\n\t\t// which should not overide any existing settings values set by the\n\t\t// user. This filters out any settings values from the suggestion.\n\t\tconst nonSettingsChanges = Object.keys( updatedValue ).reduce(\n\t\t\t( acc, key ) => {\n\t\t\t\tif ( ! settingsKeys.includes( key ) ) {\n\t\t\t\t\tacc[ key ] = updatedValue[ key ];\n\t\t\t\t}\n\t\t\t\treturn acc;\n\t\t\t},\n\t\t\t{}\n\t\t);\n\n\t\tonChange( {\n\t\t\t...internalControlValue,\n\t\t\t...nonSettingsChanges,\n\t\t\t// As title is not a setting, it must be manually applied\n\t\t\t// in such a way as to preserve the users changes over\n\t\t\t// any \"title\" value provided by the \"suggestion\".\n\t\t\ttitle: internalControlValue?.title || updatedValue?.title,\n\t\t} );\n\n\t\tstopEditing();\n\t};\n\n\tconst handleSubmit = () => {\n\t\tif ( valueHasChanges ) {\n\t\t\t// Submit the original value with new stored values applied\n\t\t\t// on top. URL is a special case as it may also be a prop.\n\t\t\tonChange( {\n\t\t\t\t...value,\n\t\t\t\t...internalControlValue,\n\t\t\t\turl: currentUrlInputValue,\n\t\t\t} );\n\t\t}\n\t\tstopEditing();\n\t};\n\n\tconst handleSubmitWithEnter = ( event ) => {\n\t\tconst { keyCode } = event;\n\n\t\tif (\n\t\t\tkeyCode === ENTER &&\n\t\t\t! currentInputIsEmpty // Disallow submitting empty values.\n\t\t) {\n\t\t\tevent.preventDefault();\n\t\t\thandleSubmit();\n\t\t}\n\t};\n\n\tconst resetInternalValues = () => {\n\t\tsetInternalControlValue( value );\n\t};\n\n\tconst handleCancel = ( event ) => {\n\t\tevent.preventDefault();\n\t\tevent.stopPropagation();\n\n\t\t// Ensure that any unsubmitted input changes are reset.\n\t\tresetInternalValues();\n\n\t\tif ( hasLinkValue ) {\n\t\t\t// If there is a link then exist editing mode and show preview.\n\t\t\tstopEditing();\n\t\t} else {\n\t\t\t// If there is no link value, then remove the link entirely.\n\t\t\tonRemove?.();\n\t\t}\n\n\t\tonCancel?.();\n\t};\n\n\tconst currentUrlInputValue =\n\t\tpropInputValue || internalControlValue?.url || '';\n\n\tconst currentInputIsEmpty = ! currentUrlInputValue?.trim()?.length;\n\n\tconst shownUnlinkControl =\n\t\tonRemove && value && ! isEditingLink && ! isCreatingPage;\n\n\tconst showSettings = !! settings?.length && isEditingLink && hasLinkValue;\n\tconst showActions = isEditingLink && hasLinkValue;\n\n\t// Only show text control once a URL value has been committed\n\t// and it isn't just empty whitespace.\n\t// See https://github.com/WordPress/gutenberg/pull/33849/#issuecomment-932194927.\n\tconst showTextControl = hasLinkValue && hasTextControl;\n\n\tconst isEditing = ( isEditingLink || ! value ) && ! isCreatingPage;\n\tconst isDisabled = ! valueHasChanges || currentInputIsEmpty;\n\n\treturn (\n\t\t<div\n\t\t\ttabIndex={ -1 }\n\t\t\tref={ wrapperNode }\n\t\t\tclassName=\"block-editor-link-control\"\n\t\t>\n\t\t\t{ isCreatingPage && (\n\t\t\t\t<div className=\"block-editor-link-control__loading\">\n\t\t\t\t\t<Spinner /> { __( 'Creating' ) }…\n\t\t\t\t</div>\n\t\t\t) }\n\n\t\t\t{ isEditing && (\n\t\t\t\t<>\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName={ classnames( {\n\t\t\t\t\t\t\t'block-editor-link-control__search-input-wrapper': true,\n\t\t\t\t\t\t\t'has-text-control': showTextControl,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ showTextControl && (\n\t\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\tref={ textInputRef }\n\t\t\t\t\t\t\t\tclassName=\"block-editor-link-control__field block-editor-link-control__text-content\"\n\t\t\t\t\t\t\t\tlabel={ __( 'Text' ) }\n\t\t\t\t\t\t\t\tvalue={ internalControlValue?.title }\n\t\t\t\t\t\t\t\tonChange={ setInternalTextInputValue }\n\t\t\t\t\t\t\t\tonKeyDown={ handleSubmitWithEnter }\n\t\t\t\t\t\t\t\tsize=\"__unstable-large\"\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<LinkControlSearchInput\n\t\t\t\t\t\t\tcurrentLink={ value }\n\t\t\t\t\t\t\tclassName=\"block-editor-link-control__field block-editor-link-control__search-input\"\n\t\t\t\t\t\t\tplaceholder={ searchInputPlaceholder }\n\t\t\t\t\t\t\tvalue={ currentUrlInputValue }\n\t\t\t\t\t\t\twithCreateSuggestion={ withCreateSuggestion }\n\t\t\t\t\t\t\tonCreateSuggestion={ createPage }\n\t\t\t\t\t\t\tonChange={ setInternalURLInputValue }\n\t\t\t\t\t\t\tonSelect={ handleSelectSuggestion }\n\t\t\t\t\t\t\tshowInitialSuggestions={ showInitialSuggestions }\n\t\t\t\t\t\t\tallowDirectEntry={ ! noDirectEntry }\n\t\t\t\t\t\t\tshowSuggestions={ showSuggestions }\n\t\t\t\t\t\t\tsuggestionsQuery={ suggestionsQuery }\n\t\t\t\t\t\t\twithURLSuggestion={ ! noURLSuggestion }\n\t\t\t\t\t\t\tcreateSuggestionButtonText={\n\t\t\t\t\t\t\t\tcreateSuggestionButtonText\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\thideLabelFromVision={ ! showTextControl }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t\t{ errorMessage && (\n\t\t\t\t\t\t<Notice\n\t\t\t\t\t\t\tclassName=\"block-editor-link-control__search-error\"\n\t\t\t\t\t\t\tstatus=\"error\"\n\t\t\t\t\t\t\tisDismissible={ false }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ errorMessage }\n\t\t\t\t\t\t</Notice>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t) }\n\n\t\t\t{ value && ! isEditingLink && ! isCreatingPage && (\n\t\t\t\t<LinkPreview\n\t\t\t\t\tkey={ value?.url } // force remount when URL changes to avoid race conditions for rich previews\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonEditClick={ () => setIsEditingLink( true ) }\n\t\t\t\t\thasRichPreviews={ hasRichPreviews }\n\t\t\t\t\thasUnlinkControl={ shownUnlinkControl }\n\t\t\t\t\tonRemove={ onRemove }\n\t\t\t\t/>\n\t\t\t) }\n\n\t\t\t{ showSettings && (\n\t\t\t\t<div className=\"block-editor-link-control__tools\">\n\t\t\t\t\t{ ! currentInputIsEmpty && (\n\t\t\t\t\t\t<LinkControlSettingsDrawer\n\t\t\t\t\t\t\tsettingsOpen={ settingsOpen }\n\t\t\t\t\t\t\tsetSettingsOpen={ setSettingsOpen }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<LinkSettings\n\t\t\t\t\t\t\t\tvalue={ internalControlValue }\n\t\t\t\t\t\t\t\tsettings={ settings }\n\t\t\t\t\t\t\t\tonChange={ createSetInternalSettingValueHandler(\n\t\t\t\t\t\t\t\t\tsettingsKeys\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</LinkControlSettingsDrawer>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t) }\n\n\t\t\t{ showActions && (\n\t\t\t\t<div className=\"block-editor-link-control__search-actions\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\tonClick={ isDisabled ? noop : handleSubmit }\n\t\t\t\t\t\tclassName=\"block-editor-link-control__search-submit\"\n\t\t\t\t\t\taria-disabled={ isDisabled }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Save' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button variant=\"tertiary\" onClick={ handleCancel }>\n\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</div>\n\t\t\t) }\n\n\t\t\t{ renderControlBottom && renderControlBottom() }\n\t\t</div>\n\t);\n}\n\nLinkControl.ViewerFill = ViewerFill;\n\nexport default LinkControl;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/link-control/index.js"],"names":["noop","PREFERENCE_SCOPE","PREFERENCE_KEY","LinkControl","searchInputPlaceholder","value","settings","DEFAULT_LINK_SETTINGS","onChange","onRemove","onCancel","noDirectEntry","showSuggestions","showInitialSuggestions","forceIsEditingLink","createSuggestion","withCreateSuggestion","inputValue","propInputValue","suggestionsQuery","noURLSuggestion","createSuggestionButtonText","hasRichPreviews","hasTextControl","renderControlBottom","undefined","settingsOpen","setSettingsOpen","advancedSettingsPreference","select","prefsStore","preferencesStore","get","set","setPreference","setSettingsOpenWithPreference","prefVal","isSettingsOpen","isMounting","wrapperNode","textInputRef","isEndingEditWithFocus","settingsKeys","map","id","internalControlValue","setInternalControlValue","setInternalURLInputValue","setInternalTextInputValue","createSetInternalSettingValueHandler","valueHasChanges","isEditingLink","setIsEditingLink","url","createPage","isCreatingPage","errorMessage","current","nextFocusTarget","focus","focusable","find","hasLinkValue","trim","length","stopEditing","contains","ownerDocument","activeElement","handleSelectSuggestion","updatedValue","nonSettingsChanges","Object","keys","reduce","acc","key","includes","title","handleSubmit","currentUrlInputValue","handleSubmitWithEnter","event","keyCode","ENTER","currentInputIsEmpty","preventDefault","resetInternalValues","handleCancel","stopPropagation","shownUnlinkControl","showActions","showTextControl","isEditing","isDisabled","showSettings","ViewerFill"],"mappings":";;;;;;;;;AAUA;;AAPA;;AAKA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA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;AANZ,IAhEF,EA0EGsF,YAAY,IACb;AAAK,IAAA,SAAS,EAAC;AAAf,KACG,CAAEV,mBAAF,IACD,4BAAC,uBAAD;AACC,IAAA,YAAY,EAAGhD,cADhB;AAEC,IAAA,eAAe,EAAGF;AAFnB,KAIC,4BAAC,iBAAD;AACC,IAAA,KAAK,EAAGU,oBADT;AAEC,IAAA,QAAQ,EAAGvC,QAFZ;AAGC,IAAA,QAAQ,EAAG2C,oCAAoC,CAC9CP,YAD8C;AAHhD,IAJD,CAFF,CA3EF,EA6FGiD,WAAW,IACZ;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,4BAAC,kBAAD;AACC,IAAA,OAAO,EAAC,SADT;AAEC,IAAA,OAAO,EAAGG,UAAU,GAAG9F,IAAH,GAAU+E,YAF/B;AAGC,IAAA,SAAS,EAAC,0CAHX;AAIC,qBAAgBe;AAJjB,KAMG,cAAI,MAAJ,CANH,CADD,EASC,4BAAC,kBAAD;AAAQ,IAAA,OAAO,EAAC,UAAhB;AAA2B,IAAA,OAAO,EAAGN;AAArC,KACG,cAAI,QAAJ,CADH,CATD,CA9FF,EA6GGhE,mBAAmB,IAAIA,mBAAmB,EA7G7C,CADD;AAiHA;;AAEDrB,WAAW,CAAC6F,UAAZ,GAAyBA,sBAAzB;eAEe7F,W","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { Button, Spinner, Notice, TextControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useRef, useState, useEffect } from '@wordpress/element';\nimport { focus } from '@wordpress/dom';\nimport { ENTER } from '@wordpress/keycodes';\nimport { isShallowEqualObjects } from '@wordpress/is-shallow-equal';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as preferencesStore } from '@wordpress/preferences';\n\n/**\n * Internal dependencies\n */\nimport LinkControlSettingsDrawer from './settings-drawer';\nimport LinkControlSearchInput from './search-input';\nimport LinkPreview from './link-preview';\nimport LinkSettings from './settings';\nimport useCreatePage from './use-create-page';\nimport useInternalValue from './use-internal-value';\nimport { ViewerFill } from './viewer-slot';\nimport { DEFAULT_LINK_SETTINGS } from './constants';\n\n/**\n * Default properties associated with a link control value.\n *\n * @typedef WPLinkControlDefaultValue\n *\n * @property {string} url Link URL.\n * @property {string=} title Link title.\n * @property {boolean=} opensInNewTab Whether link should open in a new browser\n * tab. This value is only assigned if not\n * providing a custom `settings` prop.\n */\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * Custom settings values associated with a link.\n *\n * @typedef {{[setting:string]:any}} WPLinkControlSettingsValue\n */\n/* eslint-enable */\n\n/**\n * Custom settings values associated with a link.\n *\n * @typedef WPLinkControlSetting\n *\n * @property {string} id Identifier to use as property for setting value.\n * @property {string} title Human-readable label to show in user interface.\n */\n\n/**\n * Properties associated with a link control value, composed as a union of the\n * default properties and any custom settings values.\n *\n * @typedef {WPLinkControlDefaultValue&WPLinkControlSettingsValue} WPLinkControlValue\n */\n\n/** @typedef {(nextValue:WPLinkControlValue)=>void} WPLinkControlOnChangeProp */\n\n/**\n * Properties associated with a search suggestion used within the LinkControl.\n *\n * @typedef WPLinkControlSuggestion\n *\n * @property {string} id Identifier to use to uniquely identify the suggestion.\n * @property {string} type Identifies the type of the suggestion (eg: `post`,\n * `page`, `url`...etc)\n * @property {string} title Human-readable label to show in user interface.\n * @property {string} url A URL for the suggestion.\n */\n\n/** @typedef {(title:string)=>WPLinkControlSuggestion} WPLinkControlCreateSuggestionProp */\n\n/**\n * @typedef WPLinkControlProps\n *\n * @property {(WPLinkControlSetting[])=} settings An array of settings objects. Each object will used to\n * render a `ToggleControl` for that setting.\n * @property {boolean=} forceIsEditingLink If passed as either `true` or `false`, controls the\n * internal editing state of the component to respective\n * show or not show the URL input field.\n * @property {WPLinkControlValue=} value Current link value.\n * @property {WPLinkControlOnChangeProp=} onChange Value change handler, called with the updated value if\n * the user selects a new link or updates settings.\n * @property {boolean=} noDirectEntry Whether to allow turning a URL-like search query directly into a link.\n * @property {boolean=} showSuggestions Whether to present suggestions when typing the URL.\n * @property {boolean=} showInitialSuggestions Whether to present initial suggestions immediately.\n * @property {boolean=} withCreateSuggestion Whether to allow creation of link value from suggestion.\n * @property {Object=} suggestionsQuery Query parameters to pass along to wp.blockEditor.__experimentalFetchLinkSuggestions.\n * @property {boolean=} noURLSuggestion Whether to add a fallback suggestion which treats the search query as a URL.\n * @property {boolean=} hasTextControl Whether to add a text field to the UI to update the value.title.\n * @property {string|Function|undefined} createSuggestionButtonText The text to use in the button that calls createSuggestion.\n * @property {Function} renderControlBottom Optional controls to be rendered at the bottom of the component.\n */\n\nconst noop = () => {};\n\nconst PREFERENCE_SCOPE = 'core/block-editor';\nconst PREFERENCE_KEY = 'linkControlSettingsDrawer';\n\n/**\n * Renders a link control. A link control is a controlled input which maintains\n * a value associated with a link (HTML anchor element) and relevant settings\n * for how that link is expected to behave.\n *\n * @param {WPLinkControlProps} props Component props.\n */\nfunction LinkControl( {\n\tsearchInputPlaceholder,\n\tvalue,\n\tsettings = DEFAULT_LINK_SETTINGS,\n\tonChange = noop,\n\tonRemove,\n\tonCancel,\n\tnoDirectEntry = false,\n\tshowSuggestions = true,\n\tshowInitialSuggestions,\n\tforceIsEditingLink,\n\tcreateSuggestion,\n\twithCreateSuggestion,\n\tinputValue: propInputValue = '',\n\tsuggestionsQuery = {},\n\tnoURLSuggestion = false,\n\tcreateSuggestionButtonText,\n\thasRichPreviews = false,\n\thasTextControl = false,\n\trenderControlBottom = null,\n} ) {\n\tif ( withCreateSuggestion === undefined && createSuggestion ) {\n\t\twithCreateSuggestion = true;\n\t}\n\n\tconst [ settingsOpen, setSettingsOpen ] = useState( false );\n\n\tconst { advancedSettingsPreference } = useSelect( ( select ) => {\n\t\tconst prefsStore = select( preferencesStore );\n\n\t\treturn {\n\t\t\tadvancedSettingsPreference:\n\t\t\t\tprefsStore.get( PREFERENCE_SCOPE, PREFERENCE_KEY ) ?? false,\n\t\t};\n\t}, [] );\n\n\tconst { set: setPreference } = useDispatch( preferencesStore );\n\n\t/**\n\t * Sets the open/closed state of the Advanced Settings Drawer,\n\t * optionlly persisting the state to the user's preferences.\n\t *\n\t * Note that Block Editor components can be consumed by non-WordPress\n\t * environments which may not have preferences setup.\n\t * Therefore a local state is also used as a fallback.\n\t *\n\t * @param {boolean} prefVal the open/closed state of the Advanced Settings Drawer.\n\t */\n\tconst setSettingsOpenWithPreference = ( prefVal ) => {\n\t\tif ( setPreference ) {\n\t\t\tsetPreference( PREFERENCE_SCOPE, PREFERENCE_KEY, prefVal );\n\t\t}\n\t\tsetSettingsOpen( prefVal );\n\t};\n\n\t// Block Editor components can be consumed by non-WordPress environments\n\t// which may not have these preferences setup.\n\t// Therefore a local state is used as a fallback.\n\tconst isSettingsOpen = advancedSettingsPreference || settingsOpen;\n\n\tconst isMounting = useRef( true );\n\tconst wrapperNode = useRef();\n\tconst textInputRef = useRef();\n\tconst isEndingEditWithFocus = useRef( false );\n\n\tconst settingsKeys = settings.map( ( { id } ) => id );\n\n\tconst [\n\t\tinternalControlValue,\n\t\tsetInternalControlValue,\n\t\tsetInternalURLInputValue,\n\t\tsetInternalTextInputValue,\n\t\tcreateSetInternalSettingValueHandler,\n\t] = useInternalValue( value );\n\n\tconst valueHasChanges =\n\t\tvalue && ! isShallowEqualObjects( internalControlValue, value );\n\n\tconst [ isEditingLink, setIsEditingLink ] = useState(\n\t\tforceIsEditingLink !== undefined\n\t\t\t? forceIsEditingLink\n\t\t\t: ! value || ! value.url\n\t);\n\n\tconst { createPage, isCreatingPage, errorMessage } =\n\t\tuseCreatePage( createSuggestion );\n\n\tuseEffect( () => {\n\t\tif (\n\t\t\tforceIsEditingLink !== undefined &&\n\t\t\tforceIsEditingLink !== isEditingLink\n\t\t) {\n\t\t\tsetIsEditingLink( forceIsEditingLink );\n\t\t}\n\t\t// Todo: bug if the missing dep is introduced. Will need a fix.\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [ forceIsEditingLink ] );\n\n\tuseEffect( () => {\n\t\t// We don't auto focus into the Link UI on mount\n\t\t// because otherwise using the keyboard to select text\n\t\t// *within* the link format is not possible.\n\t\tif ( isMounting.current ) {\n\t\t\tisMounting.current = false;\n\t\t\treturn;\n\t\t}\n\n\t\t// Scenario - when:\n\t\t// - switching between editable and non editable LinkControl\n\t\t// - clicking on a link\n\t\t// ...then move focus to the *first* element to avoid focus loss\n\t\t// and to ensure focus is *within* the Link UI.\n\t\tconst nextFocusTarget =\n\t\t\tfocus.focusable.find( wrapperNode.current )[ 0 ] ||\n\t\t\twrapperNode.current;\n\n\t\tnextFocusTarget.focus();\n\n\t\tisEndingEditWithFocus.current = false;\n\t}, [ isEditingLink, isCreatingPage ] );\n\n\tconst hasLinkValue = value?.url?.trim()?.length > 0;\n\n\t/**\n\t * Cancels editing state and marks that focus may need to be restored after\n\t * the next render, if focus was within the wrapper when editing finished.\n\t */\n\tconst stopEditing = () => {\n\t\tisEndingEditWithFocus.current = !! wrapperNode.current?.contains(\n\t\t\twrapperNode.current.ownerDocument.activeElement\n\t\t);\n\n\t\tsetIsEditingLink( false );\n\t};\n\n\tconst handleSelectSuggestion = ( updatedValue ) => {\n\t\t// Suggestions may contains \"settings\" values (e.g. `opensInNewTab`)\n\t\t// which should not overide any existing settings values set by the\n\t\t// user. This filters out any settings values from the suggestion.\n\t\tconst nonSettingsChanges = Object.keys( updatedValue ).reduce(\n\t\t\t( acc, key ) => {\n\t\t\t\tif ( ! settingsKeys.includes( key ) ) {\n\t\t\t\t\tacc[ key ] = updatedValue[ key ];\n\t\t\t\t}\n\t\t\t\treturn acc;\n\t\t\t},\n\t\t\t{}\n\t\t);\n\n\t\tonChange( {\n\t\t\t...internalControlValue,\n\t\t\t...nonSettingsChanges,\n\t\t\t// As title is not a setting, it must be manually applied\n\t\t\t// in such a way as to preserve the users changes over\n\t\t\t// any \"title\" value provided by the \"suggestion\".\n\t\t\ttitle: internalControlValue?.title || updatedValue?.title,\n\t\t} );\n\n\t\tstopEditing();\n\t};\n\n\tconst handleSubmit = () => {\n\t\tif ( valueHasChanges ) {\n\t\t\t// Submit the original value with new stored values applied\n\t\t\t// on top. URL is a special case as it may also be a prop.\n\t\t\tonChange( {\n\t\t\t\t...value,\n\t\t\t\t...internalControlValue,\n\t\t\t\turl: currentUrlInputValue,\n\t\t\t} );\n\t\t}\n\t\tstopEditing();\n\t};\n\n\tconst handleSubmitWithEnter = ( event ) => {\n\t\tconst { keyCode } = event;\n\n\t\tif (\n\t\t\tkeyCode === ENTER &&\n\t\t\t! currentInputIsEmpty // Disallow submitting empty values.\n\t\t) {\n\t\t\tevent.preventDefault();\n\t\t\thandleSubmit();\n\t\t}\n\t};\n\n\tconst resetInternalValues = () => {\n\t\tsetInternalControlValue( value );\n\t};\n\n\tconst handleCancel = ( event ) => {\n\t\tevent.preventDefault();\n\t\tevent.stopPropagation();\n\n\t\t// Ensure that any unsubmitted input changes are reset.\n\t\tresetInternalValues();\n\n\t\tif ( hasLinkValue ) {\n\t\t\t// If there is a link then exist editing mode and show preview.\n\t\t\tstopEditing();\n\t\t} else {\n\t\t\t// If there is no link value, then remove the link entirely.\n\t\t\tonRemove?.();\n\t\t}\n\n\t\tonCancel?.();\n\t};\n\n\tconst currentUrlInputValue =\n\t\tpropInputValue || internalControlValue?.url || '';\n\n\tconst currentInputIsEmpty = ! currentUrlInputValue?.trim()?.length;\n\n\tconst shownUnlinkControl =\n\t\tonRemove && value && ! isEditingLink && ! isCreatingPage;\n\n\tconst showActions = isEditingLink && hasLinkValue;\n\n\t// Only show text control once a URL value has been committed\n\t// and it isn't just empty whitespace.\n\t// See https://github.com/WordPress/gutenberg/pull/33849/#issuecomment-932194927.\n\tconst showTextControl = hasLinkValue && hasTextControl;\n\n\tconst isEditing = ( isEditingLink || ! value ) && ! isCreatingPage;\n\tconst isDisabled = ! valueHasChanges || currentInputIsEmpty;\n\tconst showSettings = !! settings?.length && isEditingLink && hasLinkValue;\n\n\treturn (\n\t\t<div\n\t\t\ttabIndex={ -1 }\n\t\t\tref={ wrapperNode }\n\t\t\tclassName=\"block-editor-link-control\"\n\t\t>\n\t\t\t{ isCreatingPage && (\n\t\t\t\t<div className=\"block-editor-link-control__loading\">\n\t\t\t\t\t<Spinner /> { __( 'Creating' ) }…\n\t\t\t\t</div>\n\t\t\t) }\n\n\t\t\t{ isEditing && (\n\t\t\t\t<>\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName={ classnames( {\n\t\t\t\t\t\t\t'block-editor-link-control__search-input-wrapper': true,\n\t\t\t\t\t\t\t'has-text-control': showTextControl,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ showTextControl && (\n\t\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\tref={ textInputRef }\n\t\t\t\t\t\t\t\tclassName=\"block-editor-link-control__field block-editor-link-control__text-content\"\n\t\t\t\t\t\t\t\tlabel={ __( 'Text' ) }\n\t\t\t\t\t\t\t\tvalue={ internalControlValue?.title }\n\t\t\t\t\t\t\t\tonChange={ setInternalTextInputValue }\n\t\t\t\t\t\t\t\tonKeyDown={ handleSubmitWithEnter }\n\t\t\t\t\t\t\t\tsize=\"__unstable-large\"\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<LinkControlSearchInput\n\t\t\t\t\t\t\tcurrentLink={ value }\n\t\t\t\t\t\t\tclassName=\"block-editor-link-control__field block-editor-link-control__search-input\"\n\t\t\t\t\t\t\tplaceholder={ searchInputPlaceholder }\n\t\t\t\t\t\t\tvalue={ currentUrlInputValue }\n\t\t\t\t\t\t\twithCreateSuggestion={ withCreateSuggestion }\n\t\t\t\t\t\t\tonCreateSuggestion={ createPage }\n\t\t\t\t\t\t\tonChange={ setInternalURLInputValue }\n\t\t\t\t\t\t\tonSelect={ handleSelectSuggestion }\n\t\t\t\t\t\t\tshowInitialSuggestions={ showInitialSuggestions }\n\t\t\t\t\t\t\tallowDirectEntry={ ! noDirectEntry }\n\t\t\t\t\t\t\tshowSuggestions={ showSuggestions }\n\t\t\t\t\t\t\tsuggestionsQuery={ suggestionsQuery }\n\t\t\t\t\t\t\twithURLSuggestion={ ! noURLSuggestion }\n\t\t\t\t\t\t\tcreateSuggestionButtonText={\n\t\t\t\t\t\t\t\tcreateSuggestionButtonText\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\thideLabelFromVision={ ! showTextControl }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t\t{ errorMessage && (\n\t\t\t\t\t\t<Notice\n\t\t\t\t\t\t\tclassName=\"block-editor-link-control__search-error\"\n\t\t\t\t\t\t\tstatus=\"error\"\n\t\t\t\t\t\t\tisDismissible={ false }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ errorMessage }\n\t\t\t\t\t\t</Notice>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t) }\n\n\t\t\t{ value && ! isEditingLink && ! isCreatingPage && (\n\t\t\t\t<LinkPreview\n\t\t\t\t\tkey={ value?.url } // force remount when URL changes to avoid race conditions for rich previews\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonEditClick={ () => setIsEditingLink( true ) }\n\t\t\t\t\thasRichPreviews={ hasRichPreviews }\n\t\t\t\t\thasUnlinkControl={ shownUnlinkControl }\n\t\t\t\t\tonRemove={ onRemove }\n\t\t\t\t/>\n\t\t\t) }\n\n\t\t\t{ showSettings && (\n\t\t\t\t<div className=\"block-editor-link-control__tools\">\n\t\t\t\t\t{ ! currentInputIsEmpty && (\n\t\t\t\t\t\t<LinkControlSettingsDrawer\n\t\t\t\t\t\t\tsettingsOpen={ isSettingsOpen }\n\t\t\t\t\t\t\tsetSettingsOpen={ setSettingsOpenWithPreference }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<LinkSettings\n\t\t\t\t\t\t\t\tvalue={ internalControlValue }\n\t\t\t\t\t\t\t\tsettings={ settings }\n\t\t\t\t\t\t\t\tonChange={ createSetInternalSettingValueHandler(\n\t\t\t\t\t\t\t\t\tsettingsKeys\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</LinkControlSettingsDrawer>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t) }\n\n\t\t\t{ showActions && (\n\t\t\t\t<div className=\"block-editor-link-control__search-actions\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\tonClick={ isDisabled ? noop : handleSubmit }\n\t\t\t\t\t\tclassName=\"block-editor-link-control__search-submit\"\n\t\t\t\t\t\taria-disabled={ isDisabled }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Save' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button variant=\"tertiary\" onClick={ handleCancel }>\n\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</div>\n\t\t\t) }\n\n\t\t\t{ renderControlBottom && renderControlBottom() }\n\t\t</div>\n\t);\n}\n\nLinkControl.ViewerFill = ViewerFill;\n\nexport default LinkControl;\n"]}
|
|
@@ -424,7 +424,14 @@ function RichTextWrapper({
|
|
|
424
424
|
}), anchorRef]),
|
|
425
425
|
contentEditable: true,
|
|
426
426
|
suppressContentEditableWarning: true,
|
|
427
|
-
className: (0, _classnames.default)('block-editor-rich-text__editable', props.className, 'rich-text')
|
|
427
|
+
className: (0, _classnames.default)('block-editor-rich-text__editable', props.className, 'rich-text') // Setting tabIndex to 0 is unnecessary, the element is already
|
|
428
|
+
// focusable because it's contentEditable. This also fixes a
|
|
429
|
+
// Safari bug where it's not possible to Shift+Click multi
|
|
430
|
+
// select blocks when Shift Clicking into an element with
|
|
431
|
+
// tabIndex because Safari will focus the element. However,
|
|
432
|
+
// Safari will correctly ignore nested contentEditable elements.
|
|
433
|
+
,
|
|
434
|
+
tabIndex: props.tabIndex === 0 ? null : props.tabIndex
|
|
428
435
|
}));
|
|
429
436
|
}
|
|
430
437
|
|