@wordpress/block-editor 12.3.13 → 12.3.15

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.
Files changed (36) hide show
  1. package/build/components/block-controls/use-has-block-controls.js +52 -0
  2. package/build/components/block-controls/use-has-block-controls.js.map +1 -0
  3. package/build/components/block-tools/block-contextual-toolbar.js +50 -5
  4. package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
  5. package/build/components/global-styles/typography-utils.js +3 -2
  6. package/build/components/global-styles/typography-utils.js.map +1 -1
  7. package/build/components/link-control/index.js +47 -6
  8. package/build/components/link-control/index.js.map +1 -1
  9. package/build/components/rich-text/use-format-types.js +3 -2
  10. package/build/components/rich-text/use-format-types.js.map +1 -1
  11. package/build-module/components/block-controls/use-has-block-controls.js +38 -0
  12. package/build-module/components/block-controls/use-has-block-controls.js.map +1 -0
  13. package/build-module/components/block-tools/block-contextual-toolbar.js +49 -5
  14. package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
  15. package/build-module/components/global-styles/typography-utils.js +4 -3
  16. package/build-module/components/global-styles/typography-utils.js.map +1 -1
  17. package/build-module/components/link-control/index.js +45 -6
  18. package/build-module/components/link-control/index.js.map +1 -1
  19. package/build-module/components/rich-text/use-format-types.js +3 -2
  20. package/build-module/components/rich-text/use-format-types.js.map +1 -1
  21. package/build-style/content-rtl.css +5 -7
  22. package/build-style/content.css +5 -7
  23. package/build-style/style-rtl.css +28 -6
  24. package/build-style/style.css +28 -6
  25. package/package.json +31 -31
  26. package/src/components/block-controls/use-has-block-controls.js +35 -0
  27. package/src/components/block-list/content.scss +2 -3
  28. package/src/components/block-toolbar/style.scss +10 -0
  29. package/src/components/block-tools/block-contextual-toolbar.js +86 -7
  30. package/src/components/block-tools/style.scss +34 -10
  31. package/src/components/global-styles/test/typography-utils.js +10 -0
  32. package/src/components/global-styles/typography-utils.js +11 -3
  33. package/src/components/link-control/README.md +12 -3
  34. package/src/components/link-control/index.js +43 -6
  35. package/src/components/link-control/test/index.js +2 -1
  36. 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
- if (isContentOnly || blockType && !(0, _blocks.hasBlockSupport)(blockType, '__experimentalToolbar', true)) {
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","ToolbarButton","next","previous","collapsed","current","focus"],"mappings":";;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AACA;;AACA;;AAKA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AA1BA;AACA;AACA;;AAGA;AACA;AACA;;AAaA;AACA;AACA;AAMA,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,UAFK;AAGLC,IAAAA,kBAHK;AAILC,IAAAA,qBAJK;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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ADQ,GAER;AAJL,KAOC,4BAAC,uBAAD;AACC,IAAA,EAAE,EAAGyB,yBADN;AAEC,IAAA,GAAG,EAAGvB,gBAFP;AAGC,IAAA,IAAI,EAAGF,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,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AAY,uCAAZ,EAAqD;AACpE,kBAAczC,UAAU,IAAIC,kBADwC;AAEpE,gBAAYT,OAFwD;AAGpE,oBAAgBE;AAHoD,GAArD,CAAhB;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"]}
@@ -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
- return isFluidTypographyEnabled(typographySettings) && layoutSettings?.wideSize ? {
106
+ const defaultMaxViewportWidth = (0, _fluidUtils.getTypographyValueAndUnit)(layoutSettings?.wideSize) ? layoutSettings?.wideSize : null;
107
+ return isFluidTypographyEnabled(typographySettings) && defaultMaxViewportWidth ? {
107
108
  fluid: {
108
- maxViewPortWidth: layoutSettings.wideSize,
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;;AAGA;AACA;AACA;AACA;AACA;;AAEA;AACA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AACA;AACA;AACA;;;AACO,SAASC,qCAAT,CAAgDC,QAAhD,EAA2D;AACjE,QAAMN,kBAAkB,GAAGM,QAAQ,EAAEC,UAArC;AACA,QAAMC,cAAc,GAAGF,QAAQ,EAAEG,MAAjC;AACA,SAAOtB,wBAAwB,CAAEa,kBAAF,CAAxB,IACNQ,cAAc,EAAEE,QADV,GAEJ;AACAtB,IAAAA,KAAK,EAAE;AACNW,MAAAA,gBAAgB,EAAES,cAAc,CAACE,QAD3B;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 { getComputedFluidTypographyValue } 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\treturn isFluidTypographyEnabled( typographySettings ) &&\n\t\tlayoutSettings?.wideSize\n\t\t? {\n\t\t\t\tfluid: {\n\t\t\t\t\tmaxViewPortWidth: layoutSettings.wideSize,\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"]}
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,MAAwBH,MAA9B;;AAEA,MAAK,CAAEI,wBAAwB,CAAEH,iBAAF,CAA/B,EAAuD;AACtD,WAAOE,WAAP;AACA;AACD;AACD;AACA;AACA;AACA;;;AACC,MAAK,CAAEA,WAAF,IAAiB,QAAQA,WAAzB,IAAwC,UAAUH,MAAM,EAAEK,KAA/D,EAAuE;AACtE,WAAOF,WAAP;AACA;;AAED,QAAMG,uBAAuB,GAC5B,OAAOL,iBAAiB,EAAEI,KAA1B,KAAoC,QAApC,GACGJ,iBAAiB,EAAEI,KADtB,GAEG,EAHJ;AAKA,QAAME,kBAAkB,GAAG,iDAAiC;AAC3DC,IAAAA,eAAe,EAAER,MAAM,EAAEK,KAAR,EAAeI,GAD2B;AAE3DC,IAAAA,eAAe,EAAEV,MAAM,EAAEK,KAAR,EAAeM,GAF2B;AAG3DC,IAAAA,QAAQ,EAAET,WAHiD;AAI3DU,IAAAA,oBAAoB,EAAEP,uBAAuB,EAAEQ,WAJY;AAK3DC,IAAAA,oBAAoB,EAAET,uBAAuB,EAAEU;AALY,GAAjC,CAA3B;;AAQA,MAAK,CAAC,CAAET,kBAAR,EAA6B;AAC5B,WAAOA,kBAAP;AACA;;AAED,SAAOJ,WAAP;AACA;;AAED,SAASC,wBAAT,CAAmCa,kBAAnC,EAAwD;AACvD,QAAMC,aAAa,GAAGD,kBAAkB,EAAEZ,KAA1C;AACA,SACC,SAASa,aAAT,IACEA,aAAa,IACd,OAAOA,aAAP,KAAyB,QADxB,IAEDC,MAAM,CAACC,IAAP,CAAaF,aAAb,EAA6BG,MAA7B,GAAsC,CAJxC;AAMA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,qCAAT,CAAgDC,QAAhD,EAA2D;AACjE,QAAMN,kBAAkB,GAAGM,QAAQ,EAAEC,UAArC;AACA,QAAMC,cAAc,GAAGF,QAAQ,EAAEG,MAAjC;AACA,QAAMC,uBAAuB,GAAG,2CAC/BF,cAAc,EAAEG,QADe,IAG7BH,cAAc,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: settingsOpen,
345
- setSettingsOpen: 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;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ies\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';\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;;AAC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AAQ,EAAGjF;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"]}
@@ -62,19 +62,20 @@ function useFormatTypes({
62
62
  const formatTypes = (0, _element.useMemo)(() => {
63
63
  return allFormatTypes.filter(({
64
64
  name,
65
+ interactive,
65
66
  tagName
66
67
  }) => {
67
68
  if (allowedFormats && !allowedFormats.includes(name)) {
68
69
  return false;
69
70
  }
70
71
 
71
- if (withoutInteractiveFormatting && interactiveContentTags.has(tagName)) {
72
+ if (withoutInteractiveFormatting && (interactive || interactiveContentTags.has(tagName))) {
72
73
  return false;
73
74
  }
74
75
 
75
76
  return true;
76
77
  });
77
- }, [allFormatTypes, allowedFormats, interactiveContentTags]);
78
+ }, [allFormatTypes, allowedFormats, withoutInteractiveFormatting]);
78
79
  const keyedSelected = (0, _data.useSelect)(select => formatTypes.reduce((accumulator, type) => {
79
80
  if (!type.__experimentalGetPropsForEditableTreePreparation) {
80
81
  return accumulator;
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/use-format-types.js"],"names":["formatTypesSelector","select","richTextStore","getFormatTypes","interactiveContentTags","Set","prefixSelectKeys","selected","prefix","Object","fromEntries","entries","map","key","value","getPrefixedSelectKeys","keys","filter","startsWith","reduce","accumulator","slice","length","useFormatTypes","clientId","identifier","withoutInteractiveFormatting","allowedFormats","allFormatTypes","formatTypes","name","tagName","includes","has","keyedSelected","type","__experimentalGetPropsForEditableTreePreparation","richTextIdentifier","blockClientId","dispatch","prepareHandlers","valueHandlers","changeHandlers","dependencies","push","forEach","__experimentalCreatePrepareEditableTree","handler","__experimentalCreateOnChangeEditableValue","dispatchers","__experimentalGetPropsForEditableTreeChangeHandler"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AALA;AACA;AACA;AAKA,SAASA,mBAAT,CAA8BC,MAA9B,EAAuC;AACtC,SAAOA,MAAM,CAAEC,eAAF,CAAN,CAAwBC,cAAxB,EAAP;AACA;AAED;AACA;AACA;AACA;AACA;;;AACA,MAAMC,sBAAsB,GAAG,IAAIC,GAAJ,CAAS,CACvC,GADuC,EAEvC,OAFuC,EAGvC,QAHuC,EAIvC,SAJuC,EAKvC,OALuC,EAMvC,QANuC,EAOvC,OAPuC,EAQvC,OARuC,EASvC,QATuC,EAUvC,UAVuC,EAWvC,OAXuC,CAAT,CAA/B;;AAcA,SAASC,gBAAT,CAA2BC,QAA3B,EAAqCC,MAArC,EAA8C;AAC7C,MAAK,OAAOD,QAAP,KAAoB,QAAzB,EAAoC,OAAO;AAAE,KAAEC,MAAF,GAAYD;AAAd,GAAP;AACpC,SAAOE,MAAM,CAACC,WAAP,CACND,MAAM,CAACE,OAAP,CAAgBJ,QAAhB,EAA2BK,GAA3B,CAAgC,CAAE,CAAEC,GAAF,EAAOC,KAAP,CAAF,KAAsB,CACpD,GAAGN,MAAQ,IAAIK,GAAK,EADgC,EAErDC,KAFqD,CAAtD,CADM,CAAP;AA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QAAKZ,IAAI,CAACa,yCAAV,EAAsD;AACrD,UAAIC,WAAW,GAAG,EAAlB;;AAEA,UAAKd,IAAI,CAACe,kDAAV,EAA+D;AAC9DD,QAAAA,WAAW,GACVd,IAAI,CAACe,kDAAL,CACCX,QADD,EAEC;AACCF,UAAAA,kBAAkB,EAAEZ,UADrB;AAECa,UAAAA,aAAa,EAAEd;AAFhB,SAFD,CADD;AAQA;;AAED,YAAMjB,QAAQ,GAAGQ,qBAAqB,CAAEmB,aAAF,EAAiBC,IAAI,CAACL,IAAtB,CAAtC;AACAY,MAAAA,cAAc,CAACE,IAAf,CACCT,IAAI,CAACa,yCAAL,CACC,EACC,IAAK,OAAOzC,QAAP,KAAoB,QAApB,GAA+BA,QAA/B,GAA0C,EAA/C,CADD;AAEC,WAAG0C;AAFJ,OADD,EAKC;AACCZ,QAAAA,kBAAkB,EAAEZ,UADrB;AAECa,QAAAA,aAAa,EAAEd;AAFhB,OALD,CADD;AAYA;AACD,GA7CD;AA+CA,SAAO;AACNK,IAAAA,WADM;AAENW,IAAAA,eAFM;AAGNC,IAAAA,aAHM;AAINC,IAAAA,cAJM;AAKNC,IAAAA;AALM,GAAP;AAOA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as richTextStore } from '@wordpress/rich-text';\n\nfunction formatTypesSelector( select ) {\n\treturn select( richTextStore ).getFormatTypes();\n}\n\n/**\n * Set of all interactive content tags.\n *\n * @see https://html.spec.whatwg.org/multipage/dom.html#interactive-content\n */\nconst interactiveContentTags = new Set( [\n\t'a',\n\t'audio',\n\t'button',\n\t'details',\n\t'embed',\n\t'iframe',\n\t'input',\n\t'label',\n\t'select',\n\t'textarea',\n\t'video',\n] );\n\nfunction prefixSelectKeys( selected, prefix ) {\n\tif ( typeof selected !== 'object' ) return { [ prefix ]: selected };\n\treturn Object.fromEntries(\n\t\tObject.entries( selected ).map( ( [ key, value ] ) => [\n\t\t\t`${ prefix }.${ key }`,\n\t\t\tvalue,\n\t\t] )\n\t);\n}\n\nfunction getPrefixedSelectKeys( selected, prefix ) {\n\tif ( selected[ prefix ] ) return selected[ prefix ];\n\treturn Object.keys( selected )\n\t\t.filter( ( key ) => key.startsWith( prefix + '.' ) )\n\t\t.reduce( ( accumulator, key ) => {\n\t\t\taccumulator[ key.slice( prefix.length + 1 ) ] = selected[ key ];\n\t\t\treturn accumulator;\n\t\t}, {} );\n}\n\n/**\n * This hook provides RichText with the `formatTypes` and its derived props from\n * experimental format type settings.\n *\n * @param {Object} $0 Options\n * @param {string} $0.clientId Block client ID.\n * @param {string} $0.identifier Block attribute.\n * @param {boolean} $0.withoutInteractiveFormatting Whether to clean the interactive formattings or not.\n * @param {Array} $0.allowedFormats Allowed formats\n */\nexport function useFormatTypes( {\n\tclientId,\n\tidentifier,\n\twithoutInteractiveFormatting,\n\tallowedFormats,\n} ) {\n\tconst allFormatTypes = useSelect( formatTypesSelector, [] );\n\tconst formatTypes = useMemo( () => {\n\t\treturn allFormatTypes.filter( ( { name, tagName } ) => {\n\t\t\tif ( allowedFormats && ! allowedFormats.includes( name ) ) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\twithoutInteractiveFormatting &&\n\t\t\t\tinteractiveContentTags.has( tagName )\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t} );\n\t}, [ allFormatTypes, allowedFormats, interactiveContentTags ] );\n\tconst keyedSelected = useSelect(\n\t\t( select ) =>\n\t\t\tformatTypes.reduce( ( accumulator, type ) => {\n\t\t\t\tif ( ! type.__experimentalGetPropsForEditableTreePreparation ) {\n\t\t\t\t\treturn accumulator;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\t...accumulator,\n\t\t\t\t\t...prefixSelectKeys(\n\t\t\t\t\t\ttype.__experimentalGetPropsForEditableTreePreparation(\n\t\t\t\t\t\t\tselect,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\trichTextIdentifier: identifier,\n\t\t\t\t\t\t\t\tblockClientId: clientId,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t),\n\t\t\t\t\t\ttype.name\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t}, {} ),\n\t\t[ formatTypes, clientId, identifier ]\n\t);\n\tconst dispatch = useDispatch();\n\tconst prepareHandlers = [];\n\tconst valueHandlers = [];\n\tconst changeHandlers = [];\n\tconst dependencies = [];\n\n\tfor ( const key in keyedSelected ) {\n\t\tdependencies.push( keyedSelected[ key ] );\n\t}\n\n\tformatTypes.forEach( ( type ) => {\n\t\tif ( type.__experimentalCreatePrepareEditableTree ) {\n\t\t\tconst handler = type.__experimentalCreatePrepareEditableTree(\n\t\t\t\tgetPrefixedSelectKeys( keyedSelected, type.name ),\n\t\t\t\t{\n\t\t\t\t\trichTextIdentifier: identifier,\n\t\t\t\t\tblockClientId: clientId,\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tif ( type.__experimentalCreateOnChangeEditableValue ) {\n\t\t\t\tvalueHandlers.push( handler );\n\t\t\t} else {\n\t\t\t\tprepareHandlers.push( handler );\n\t\t\t}\n\t\t}\n\n\t\tif ( type.__experimentalCreateOnChangeEditableValue ) {\n\t\t\tlet dispatchers = {};\n\n\t\t\tif ( type.__experimentalGetPropsForEditableTreeChangeHandler ) {\n\t\t\t\tdispatchers =\n\t\t\t\t\ttype.__experimentalGetPropsForEditableTreeChangeHandler(\n\t\t\t\t\t\tdispatch,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\trichTextIdentifier: identifier,\n\t\t\t\t\t\t\tblockClientId: clientId,\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst selected = getPrefixedSelectKeys( keyedSelected, type.name );\n\t\t\tchangeHandlers.push(\n\t\t\t\ttype.__experimentalCreateOnChangeEditableValue(\n\t\t\t\t\t{\n\t\t\t\t\t\t...( typeof selected === 'object' ? selected : {} ),\n\t\t\t\t\t\t...dispatchers,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\trichTextIdentifier: identifier,\n\t\t\t\t\t\tblockClientId: clientId,\n\t\t\t\t\t}\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t} );\n\n\treturn {\n\t\tformatTypes,\n\t\tprepareHandlers,\n\t\tvalueHandlers,\n\t\tchangeHandlers,\n\t\tdependencies,\n\t};\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/use-format-types.js"],"names":["formatTypesSelector","select","richTextStore","getFormatTypes","interactiveContentTags","Set","prefixSelectKeys","selected","prefix","Object","fromEntries","entries","map","key","value","getPrefixedSelectKeys","keys","filter","startsWith","reduce","accumulator","slice","length","useFormatTypes","clientId","identifier","withoutInteractiveFormatting","allowedFormats","allFormatTypes","formatTypes","name","interactive","tagName","includes","has","keyedSelected","type","__experimentalGetPropsForEditableTreePreparation","richTextIdentifier","blockClientId","dispatch","prepareHandlers","valueHandlers","changeHandlers","dependencies","push","forEach","__experimentalCreatePrepareEditableTree","handler","__experimentalCreateOnChangeEditableValue","dispatchers","__experimentalGetPropsForEditableTreeChangeHandler"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AALA;AACA;AACA;AAKA,SAASA,mBAAT,CAA8BC,MAA9B,EAAuC;AACtC,SAAOA,MAAM,CAAEC,eAAF,CAAN,CAAwBC,cAAxB,EAAP;AACA;AAED;AACA;AACA;AACA;AACA;;;AACA,MAAMC,sBAAsB,GAAG,IAAIC,GAAJ,CAAS,CACvC,GADuC,EAEvC,OAFuC,EAGvC,QAHuC,EAIvC,SAJuC,EAKvC,OALuC,EAMvC,QANuC,EAOvC,OAPuC,EAQvC,OARuC,EASvC,QATuC,EAUvC,UAVuC,EAWvC,OAXuC,CAAT,CAA/B;;AAcA,SAASC,gBAAT,CAA2BC,QAA3B,EAAqCC,MAArC,EAA8C;AAC7C,MAAK,OAAOD,QAAP,KAAoB,QAAzB,E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CAAEoB,aAAF,EAAiBC,IAAI,CAACN,IAAtB,CADN,EAEf;AACCQ,QAAAA,kBAAkB,EAAEb,UADrB;AAECc,QAAAA,aAAa,EAAEf;AAFhB,OAFe,CAAhB;;AAQA,UAAKY,IAAI,CAACa,yCAAV,EAAsD;AACrDP,QAAAA,aAAa,CAACG,IAAd,CAAoBG,OAApB;AACA,OAFD,MAEO;AACNP,QAAAA,eAAe,CAACI,IAAhB,CAAsBG,OAAtB;AACA;AACD;;AAED,QAAKZ,IAAI,CAACa,yCAAV,EAAsD;AACrD,UAAIC,WAAW,GAAG,EAAlB;;AAEA,UAAKd,IAAI,CAACe,kDAAV,EAA+D;AAC9DD,QAAAA,WAAW,GACVd,IAAI,CAACe,kDAAL,CACCX,QADD,EAEC;AACCF,UAAAA,kBAAkB,EAAEb,UADrB;AAECc,UAAAA,aAAa,EAAEf;AAFhB,SAFD,CADD;AAQA;;AAED,YAAMjB,QAAQ,GAAGQ,qBAAqB,CAAEoB,aAAF,EAAiBC,IAAI,CAACN,IAAtB,CAAtC;AACAa,MAAAA,cAAc,CAACE,IAAf,CACCT,IAAI,CAACa,yCAAL,CACC,EACC,IAAK,OAAO1C,QAAP,KAAoB,QAApB,GAA+BA,QAA/B,GAA0C,EAA/C,CADD;AAEC,WAAG2C;AAFJ,OADD,EAKC;AACCZ,QAAAA,kBAAkB,EAAEb,UADrB;AAECc,QAAAA,aAAa,EAAEf;AAFhB,OALD,CADD;AAYA;AACD,GA7CD;AA+CA,SAAO;AACNK,IAAAA,WADM;AAENY,IAAAA,eAFM;AAGNC,IAAAA,aAHM;AAINC,IAAAA,cAJM;AAKNC,IAAAA;AALM,GAAP;AAOA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as richTextStore } from '@wordpress/rich-text';\n\nfunction formatTypesSelector( select ) {\n\treturn select( richTextStore ).getFormatTypes();\n}\n\n/**\n * Set of all interactive content tags.\n *\n * @see https://html.spec.whatwg.org/multipage/dom.html#interactive-content\n */\nconst interactiveContentTags = new Set( [\n\t'a',\n\t'audio',\n\t'button',\n\t'details',\n\t'embed',\n\t'iframe',\n\t'input',\n\t'label',\n\t'select',\n\t'textarea',\n\t'video',\n] );\n\nfunction prefixSelectKeys( selected, prefix ) {\n\tif ( typeof selected !== 'object' ) return { [ prefix ]: selected };\n\treturn Object.fromEntries(\n\t\tObject.entries( selected ).map( ( [ key, value ] ) => [\n\t\t\t`${ prefix }.${ key }`,\n\t\t\tvalue,\n\t\t] )\n\t);\n}\n\nfunction getPrefixedSelectKeys( selected, prefix ) {\n\tif ( selected[ prefix ] ) return selected[ prefix ];\n\treturn Object.keys( selected )\n\t\t.filter( ( key ) => key.startsWith( prefix + '.' ) )\n\t\t.reduce( ( accumulator, key ) => {\n\t\t\taccumulator[ key.slice( prefix.length + 1 ) ] = selected[ key ];\n\t\t\treturn accumulator;\n\t\t}, {} );\n}\n\n/**\n * This hook provides RichText with the `formatTypes` and its derived props from\n * experimental format type settings.\n *\n * @param {Object} $0 Options\n * @param {string} $0.clientId Block client ID.\n * @param {string} $0.identifier Block attribute.\n * @param {boolean} $0.withoutInteractiveFormatting Whether to clean the interactive formattings or not.\n * @param {Array} $0.allowedFormats Allowed formats\n */\nexport function useFormatTypes( {\n\tclientId,\n\tidentifier,\n\twithoutInteractiveFormatting,\n\tallowedFormats,\n} ) {\n\tconst allFormatTypes = useSelect( formatTypesSelector, [] );\n\tconst formatTypes = useMemo( () => {\n\t\treturn allFormatTypes.filter( ( { name, interactive, tagName } ) => {\n\t\t\tif ( allowedFormats && ! allowedFormats.includes( name ) ) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\twithoutInteractiveFormatting &&\n\t\t\t\t( interactive || interactiveContentTags.has( tagName ) )\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t} );\n\t}, [ allFormatTypes, allowedFormats, withoutInteractiveFormatting ] );\n\tconst keyedSelected = useSelect(\n\t\t( select ) =>\n\t\t\tformatTypes.reduce( ( accumulator, type ) => {\n\t\t\t\tif ( ! type.__experimentalGetPropsForEditableTreePreparation ) {\n\t\t\t\t\treturn accumulator;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\t...accumulator,\n\t\t\t\t\t...prefixSelectKeys(\n\t\t\t\t\t\ttype.__experimentalGetPropsForEditableTreePreparation(\n\t\t\t\t\t\t\tselect,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\trichTextIdentifier: identifier,\n\t\t\t\t\t\t\t\tblockClientId: clientId,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t),\n\t\t\t\t\t\ttype.name\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t}, {} ),\n\t\t[ formatTypes, clientId, identifier ]\n\t);\n\tconst dispatch = useDispatch();\n\tconst prepareHandlers = [];\n\tconst valueHandlers = [];\n\tconst changeHandlers = [];\n\tconst dependencies = [];\n\n\tfor ( const key in keyedSelected ) {\n\t\tdependencies.push( keyedSelected[ key ] );\n\t}\n\n\tformatTypes.forEach( ( type ) => {\n\t\tif ( type.__experimentalCreatePrepareEditableTree ) {\n\t\t\tconst handler = type.__experimentalCreatePrepareEditableTree(\n\t\t\t\tgetPrefixedSelectKeys( keyedSelected, type.name ),\n\t\t\t\t{\n\t\t\t\t\trichTextIdentifier: identifier,\n\t\t\t\t\tblockClientId: clientId,\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tif ( type.__experimentalCreateOnChangeEditableValue ) {\n\t\t\t\tvalueHandlers.push( handler );\n\t\t\t} else {\n\t\t\t\tprepareHandlers.push( handler );\n\t\t\t}\n\t\t}\n\n\t\tif ( type.__experimentalCreateOnChangeEditableValue ) {\n\t\t\tlet dispatchers = {};\n\n\t\t\tif ( type.__experimentalGetPropsForEditableTreeChangeHandler ) {\n\t\t\t\tdispatchers =\n\t\t\t\t\ttype.__experimentalGetPropsForEditableTreeChangeHandler(\n\t\t\t\t\t\tdispatch,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\trichTextIdentifier: identifier,\n\t\t\t\t\t\t\tblockClientId: clientId,\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst selected = getPrefixedSelectKeys( keyedSelected, type.name );\n\t\t\tchangeHandlers.push(\n\t\t\t\ttype.__experimentalCreateOnChangeEditableValue(\n\t\t\t\t\t{\n\t\t\t\t\t\t...( typeof selected === 'object' ? selected : {} ),\n\t\t\t\t\t\t...dispatchers,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\trichTextIdentifier: identifier,\n\t\t\t\t\t\tblockClientId: clientId,\n\t\t\t\t\t}\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t} );\n\n\treturn {\n\t\tformatTypes,\n\t\tprepareHandlers,\n\t\tvalueHandlers,\n\t\tchangeHandlers,\n\t\tdependencies,\n\t};\n}\n"]}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __experimentalUseSlotFills as useSlotFills } from '@wordpress/components';
5
+ import warning from '@wordpress/warning';
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+
10
+ import groups from './groups';
11
+ export function useHasAnyBlockControls() {
12
+ let hasAnyBlockControls = false;
13
+
14
+ for (const group in groups) {
15
+ // It is safe to violate the rules of hooks here as the `groups` object
16
+ // is static and will not change length between renders. Do not return
17
+ // early as that will cause the hook to be called a different number of
18
+ // times between renders.
19
+ // eslint-disable-next-line react-hooks/rules-of-hooks
20
+ if (useHasBlockControls(group)) {
21
+ hasAnyBlockControls = true;
22
+ }
23
+ }
24
+
25
+ return hasAnyBlockControls;
26
+ }
27
+ export function useHasBlockControls(group = 'default') {
28
+ const Slot = groups[group]?.Slot;
29
+ const fills = useSlotFills(Slot?.__unstableName);
30
+
31
+ if (!Slot) {
32
+ typeof process !== "undefined" && process.env && process.env.NODE_ENV !== "production" ? warning(`Unknown BlockControls group "${group}" provided.`) : void 0;
33
+ return null;
34
+ }
35
+
36
+ return !!fills?.length;
37
+ }
38
+ //# 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":["__experimentalUseSlotFills","useSlotFills","warning","groups","useHasAnyBlockControls","hasAnyBlockControls","group","useHasBlockControls","Slot","fills","__unstableName","length"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,0BAA0B,IAAIC,YAAvC,QAA2D,uBAA3D;AACA,OAAOC,OAAP,MAAoB,oBAApB;AAEA;AACA;AACA;;AACA,OAAOC,MAAP,MAAmB,UAAnB;AAEA,OAAO,SAASC,sBAAT,GAAkC;AACxC,MAAIC,mBAAmB,GAAG,KAA1B;;AACA,OAAM,MAAMC,KAAZ,IAAqBH,MAArB,EAA8B;AAC7B;AACA;AACA;AACA;AACA;AACA,QAAKI,mBAAmB,CAAED,KAAF,CAAxB,EAAoC;AACnCD,MAAAA,mBAAmB,GAAG,IAAtB;AACA;AACD;;AACD,SAAOA,mBAAP;AACA;AAED,OAAO,SAASE,mBAAT,CAA8BD,KAAK,GAAG,SAAtC,EAAkD;AACxD,QAAME,IAAI,GAAGL,MAAM,CAAEG,KAAF,CAAN,EAAiBE,IAA9B;AACA,QAAMC,KAAK,GAAGR,YAAY,CAAEO,IAAI,EAAEE,cAAR,CAA1B;;AACA,MAAK,CAAEF,IAAP,EAAc;AACb,6FAAAN,OAAO,CAAG,gCAAgCI,KAAO,aAA1C,CAAP;AACA,WAAO,IAAP;AACA;;AACD,SAAO,CAAC,CAAEG,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"]}