@wordpress/edit-post 6.14.0 → 6.14.1

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.
@@ -17,14 +17,18 @@ var _editor = require("@wordpress/editor");
17
17
  * WordPress dependencies
18
18
  */
19
19
  function PostSchedule() {
20
- const anchorRef = (0, _element.useRef)();
20
+ // Use internal state instead of a ref to make sure that the component
21
+ // re-renders when the popover's anchor updates.
22
+ const [popoverAnchor, setPopoverAnchor] = (0, _element.useState)(null); // Memoize popoverProps to avoid returning a new object every time.
23
+
24
+ const popoverProps = (0, _element.useMemo)(() => ({
25
+ anchor: popoverAnchor
26
+ }), [popoverAnchor]);
21
27
  return (0, _element.createElement)(_editor.PostScheduleCheck, null, (0, _element.createElement)(_components.PanelRow, {
22
28
  className: "edit-post-post-schedule",
23
- ref: anchorRef
29
+ ref: setPopoverAnchor
24
30
  }, (0, _element.createElement)("span", null, (0, _i18n.__)('Publish')), (0, _element.createElement)(_components.Dropdown, {
25
- popoverProps: {
26
- anchorRef
27
- },
31
+ popoverProps: popoverProps,
28
32
  position: "bottom left",
29
33
  contentClassName: "edit-post-post-schedule__dialog",
30
34
  focusOnMount: true,
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/post-schedule/index.js"],"names":["PostSchedule","anchorRef","isOpen","onToggle","onClose","PostScheduleToggle","onClick","label","fullLabel","full"],"mappings":";;;;;;;AAKA;;AAFA;;AACA;;AAEA;;AANA;AACA;AACA;AAUe,SAASA,YAAT,GAAwB;AACtC,QAAMC,SAAS,GAAG,sBAAlB;AACA,SACC,4BAAC,yBAAD,QACC,4BAAC,oBAAD;AAAU,IAAA,SAAS,EAAC,yBAApB;AAA8C,IAAA,GAAG,EAAGA;AAApD,KACC,0CAAQ,cAAI,SAAJ,CAAR,CADD,EAEC,4BAAC,oBAAD;AACC,IAAA,YAAY,EAAG;AAAEA,MAAAA;AAAF,KADhB;AAEC,IAAA,QAAQ,EAAC,aAFV;AAGC,IAAA,gBAAgB,EAAC,iCAHlB;AAIC,IAAA,YAAY,MAJb;AAKC,IAAA,YAAY,EAAG;AAAA,UAAE;AAAEC,QAAAA,MAAF;AAAUC,QAAAA;AAAV,OAAF;AAAA,aACd,4BAAC,kBAAD;AACC,QAAA,MAAM,EAAGD,MADV;AAEC,QAAA,OAAO,EAAGC;AAFX,QADc;AAAA,KALhB;AAWC,IAAA,aAAa,EAAG;AAAA,UAAE;AAAEC,QAAAA;AAAF,OAAF;AAAA,aACf,4BAAC,oBAAD;AAAkB,QAAA,OAAO,EAAGA;AAA5B,QADe;AAAA;AAXjB,IAFD,CADD,CADD;AAsBA;;AAED,SAASC,kBAAT,QAAmD;AAAA,MAAtB;AAAEH,IAAAA,MAAF;AAAUI,IAAAA;AAAV,GAAsB;AAClD,QAAMC,KAAK,GAAG,mCAAd;AACA,QAAMC,SAAS,GAAG,kCAAsB;AAAEC,IAAAA,IAAI,EAAE;AAAR,GAAtB,CAAlB;AACA,SACC,4BAAC,kBAAD;AACC,IAAA,SAAS,EAAC,iCADX;AAEC,IAAA,OAAO,EAAC,UAFT;AAGC,IAAA,KAAK,EAAGD,SAHT;AAIC,IAAA,WAAW,MAJZ;AAKC,qBAAgBN,MALjB,CAMC;AAND;AAOC,kBAAa,mBAAS,cAAI,iBAAJ,CAAT,EAAkCK,KAAlC,CAPd;AAQC,IAAA,OAAO,EAAGD;AARX,KAUGC,KAVH,CADD;AAcA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { PanelRow, Dropdown, Button } from '@wordpress/components';\nimport { useRef } from '@wordpress/element';\nimport {\n\tPostSchedule as PostScheduleForm,\n\tPostScheduleCheck,\n\tusePostScheduleLabel,\n} from '@wordpress/editor';\n\nexport default function PostSchedule() {\n\tconst anchorRef = useRef();\n\treturn (\n\t\t<PostScheduleCheck>\n\t\t\t<PanelRow className=\"edit-post-post-schedule\" ref={ anchorRef }>\n\t\t\t\t<span>{ __( 'Publish' ) }</span>\n\t\t\t\t<Dropdown\n\t\t\t\t\tpopoverProps={ { anchorRef } }\n\t\t\t\t\tposition=\"bottom left\"\n\t\t\t\t\tcontentClassName=\"edit-post-post-schedule__dialog\"\n\t\t\t\t\tfocusOnMount\n\t\t\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t\t\t<PostScheduleToggle\n\t\t\t\t\t\t\tisOpen={ isOpen }\n\t\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t\t\t<PostScheduleForm onClose={ onClose } />\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</PanelRow>\n\t\t</PostScheduleCheck>\n\t);\n}\n\nfunction PostScheduleToggle( { isOpen, onClick } ) {\n\tconst label = usePostScheduleLabel();\n\tconst fullLabel = usePostScheduleLabel( { full: true } );\n\treturn (\n\t\t<Button\n\t\t\tclassName=\"edit-post-post-schedule__toggle\"\n\t\t\tvariant=\"tertiary\"\n\t\t\tlabel={ fullLabel }\n\t\t\tshowTooltip\n\t\t\taria-expanded={ isOpen }\n\t\t\t// translators: %s: Current post date.\n\t\t\taria-label={ sprintf( __( 'Change date: %s' ), label ) }\n\t\t\tonClick={ onClick }\n\t\t>\n\t\t\t{ label }\n\t\t</Button>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/post-schedule/index.js"],"names":["PostSchedule","popoverAnchor","setPopoverAnchor","popoverProps","anchor","isOpen","onToggle","onClose","PostScheduleToggle","onClick","label","fullLabel","full"],"mappings":";;;;;;;AAKA;;AAFA;;AACA;;AAEA;;AANA;AACA;AACA;AAUe,SAASA,YAAT,GAAwB;AACtC;AACA;AACA,QAAM,CAAEC,aAAF,EAAiBC,gBAAjB,IAAsC,uBAAU,IAAV,CAA5C,CAHsC,CAItC;;AACA,QAAMC,YAAY,GAAG,sBACpB,OAA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\nimport { __, sprintf } from '@wordpress/i18n';\nimport { PanelRow, Dropdown, Button } from '@wordpress/components';\nimport { useState, useMemo } from '@wordpress/element';\nimport {\n\tPostSchedule as PostScheduleForm,\n\tPostScheduleCheck,\n\tusePostScheduleLabel,\n} from '@wordpress/editor';\n\nexport default function PostSchedule() {\n\t// Use internal state instead of a ref to make sure that the component\n\t// re-renders when the popover's anchor updates.\n\tconst [ popoverAnchor, setPopoverAnchor ] = useState( null );\n\t// Memoize popoverProps to avoid returning a new object every time.\n\tconst popoverProps = useMemo(\n\t\t() => ( { anchor: popoverAnchor } ),\n\t\t[ popoverAnchor ]\n\t);\n\n\treturn (\n\t\t<PostScheduleCheck>\n\t\t\t<PanelRow\n\t\t\t\tclassName=\"edit-post-post-schedule\"\n\t\t\t\tref={ setPopoverAnchor }\n\t\t\t>\n\t\t\t\t<span>{ __( 'Publish' ) }</span>\n\t\t\t\t<Dropdown\n\t\t\t\t\tpopoverProps={ popoverProps }\n\t\t\t\t\tposition=\"bottom left\"\n\t\t\t\t\tcontentClassName=\"edit-post-post-schedule__dialog\"\n\t\t\t\t\tfocusOnMount\n\t\t\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t\t\t<PostScheduleToggle\n\t\t\t\t\t\t\tisOpen={ isOpen }\n\t\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t\t\t<PostScheduleForm onClose={ onClose } />\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</PanelRow>\n\t\t</PostScheduleCheck>\n\t);\n}\n\nfunction PostScheduleToggle( { isOpen, onClick } ) {\n\tconst label = usePostScheduleLabel();\n\tconst fullLabel = usePostScheduleLabel( { full: true } );\n\treturn (\n\t\t<Button\n\t\t\tclassName=\"edit-post-post-schedule__toggle\"\n\t\t\tvariant=\"tertiary\"\n\t\t\tlabel={ fullLabel }\n\t\t\tshowTooltip\n\t\t\taria-expanded={ isOpen }\n\t\t\t// translators: %s: Current post date.\n\t\t\taria-label={ sprintf( __( 'Change date: %s' ), label ) }\n\t\t\tonClick={ onClick }\n\t\t>\n\t\t\t{ label }\n\t\t</Button>\n\t);\n}\n"]}
@@ -31,7 +31,13 @@ var _store = require("../../../store");
31
31
  * Internal dependencies
32
32
  */
33
33
  function PostTemplate() {
34
- const anchorRef = (0, _element.useRef)();
34
+ // Use internal state instead of a ref to make sure that the component
35
+ // re-renders when the popover's anchor updates.
36
+ const [popoverAnchor, setPopoverAnchor] = (0, _element.useState)(null); // Memoize popoverProps to avoid returning a new object every time.
37
+
38
+ const popoverProps = (0, _element.useMemo)(() => ({
39
+ anchor: popoverAnchor
40
+ }), [popoverAnchor]);
35
41
  const isVisible = (0, _data.useSelect)(select => {
36
42
  var _select$canUser;
37
43
 
@@ -63,11 +69,9 @@ function PostTemplate() {
63
69
 
64
70
  return (0, _element.createElement)(_components.PanelRow, {
65
71
  className: "edit-post-post-template",
66
- ref: anchorRef
72
+ ref: setPopoverAnchor
67
73
  }, (0, _element.createElement)("span", null, (0, _i18n.__)('Template')), (0, _element.createElement)(_components.Dropdown, {
68
- popoverProps: {
69
- anchorRef
70
- },
74
+ popoverProps: popoverProps,
71
75
  position: "bottom left",
72
76
  className: "edit-post-post-template__dropdown",
73
77
  contentClassName: "edit-post-post-template__dialog",
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/post-template/index.js"],"names":["PostTemplate","anchorRef","isVisible","select","postTypeSlug","editorStore","getCurrentPostType","postType","coreStore","getPostType","viewable","settings","getEditorSettings","hasTemplates","availableTemplates","Object","keys","length","supportsTemplateMode","canCreateTemplates","canUser","isOpen","onToggle","onClose","PostTemplateToggle","onClick","templateTitle","templateSlug","getEditedPostAttribute","template","editPostStore","getEditedPostTemplate","title","slug"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAdA;AACA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AAa,GACV,oBACA;AACA,kBAAI,qBAAJ,CAFA,EAGAA,aAHA,CADU,GAMV,cAAI,iBAAJ,CAXL;AAaC,IAAA,OAAO,EAAGD;AAbX,KAeGC,aAfH,aAeGA,aAfH,cAeGA,aAfH,GAeoB,cAAI,kBAAJ,CAfpB,CADD;AAmBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\nimport { PanelRow, Dropdown, Button } from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport { store as editorStore } from '@wordpress/editor';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport PostTemplateForm from './form';\nimport { store as editPostStore } from '../../../store';\n\nexport default function PostTemplate() {\n\tconst anchorRef = useRef();\n\n\tconst isVisible = useSelect( ( select ) => {\n\t\tconst postTypeSlug = select( editorStore ).getCurrentPostType();\n\t\tconst postType = select( coreStore ).getPostType( postTypeSlug );\n\t\tif ( ! postType?.viewable ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst settings = select( editorStore ).getEditorSettings();\n\t\tconst hasTemplates =\n\t\t\t!! settings.availableTemplates &&\n\t\t\tObject.keys( settings.availableTemplates ).length > 0;\n\t\tif ( hasTemplates ) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif ( ! settings.supportsTemplateMode ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst canCreateTemplates =\n\t\t\tselect( coreStore ).canUser( 'create', 'templates' ) ?? false;\n\t\treturn canCreateTemplates;\n\t}, [] );\n\n\tif ( ! isVisible ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<PanelRow className=\"edit-post-post-template\" ref={ anchorRef }>\n\t\t\t<span>{ __( 'Template' ) }</span>\n\t\t\t<Dropdown\n\t\t\t\tpopoverProps={ { anchorRef } }\n\t\t\t\tposition=\"bottom left\"\n\t\t\t\tclassName=\"edit-post-post-template__dropdown\"\n\t\t\t\tcontentClassName=\"edit-post-post-template__dialog\"\n\t\t\t\tfocusOnMount\n\t\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t\t<PostTemplateToggle\n\t\t\t\t\t\tisOpen={ isOpen }\n\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t\t<PostTemplateForm onClose={ onClose } />\n\t\t\t\t) }\n\t\t\t/>\n\t\t</PanelRow>\n\t);\n}\n\nfunction PostTemplateToggle( { isOpen, onClick } ) {\n\tconst templateTitle = useSelect( ( select ) => {\n\t\tconst templateSlug =\n\t\t\tselect( editorStore ).getEditedPostAttribute( 'template' );\n\n\t\tconst { supportsTemplateMode, availableTemplates } =\n\t\t\tselect( editorStore ).getEditorSettings();\n\t\tif ( ! supportsTemplateMode && availableTemplates[ templateSlug ] ) {\n\t\t\treturn availableTemplates[ templateSlug ];\n\t\t}\n\n\t\tconst template = select( editPostStore ).getEditedPostTemplate();\n\t\treturn template?.title ?? template?.slug;\n\t}, [] );\n\n\treturn (\n\t\t<Button\n\t\t\tclassName=\"edit-post-post-template__toggle\"\n\t\t\tvariant=\"tertiary\"\n\t\t\taria-expanded={ isOpen }\n\t\t\taria-label={\n\t\t\t\ttemplateTitle\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t// translators: %s: Name of the currently selected template.\n\t\t\t\t\t\t\t__( 'Select template: %s' ),\n\t\t\t\t\t\t\ttemplateTitle\n\t\t\t\t\t )\n\t\t\t\t\t: __( 'Select template' )\n\t\t\t}\n\t\t\tonClick={ onClick }\n\t\t>\n\t\t\t{ templateTitle ?? __( 'Default template' ) }\n\t\t</Button>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/post-template/index.js"],"names":["PostTemplate","popoverAnchor","setPopoverAnchor","popoverProps","anchor","isVisible","select","postTypeSlug","editorStore","getCurrentPostType","postType","coreStore","getPostType","viewable","settings","getEditorSettings","hasTemplates","availableTemplates","Object","keys","length","supportsTemplateMode","canCreateTemplates","canUser","isOpen","onToggle","onClose","PostTemplateToggle","onClick","templateTitle","templateSlug","getEditedPostAttribute","template","editPostStore","getEditedPostTemplate","title","slug"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAdA;AACA;AACA;;AAQA;AACA;AACA;AAIe,SAASA,YAAT,GAAwB;AACtC;AACA;AACA,QAAM,CAAEC,aAAF,EAAiBC,gBAAjB,IAAsC,uBAAU,IAAV,CAA5C,CAHsC,CAItC;;AACA,QAAMC,YAAY,GAAG,sBACpB,OAAQ;AAAEC,IAAAA,MAAM,EAAEH;AAAV,GAAR,CADoB,EAEpB,CAAEA,aAAF,CAFoB,CAArB;AAKA,QAAMI,SAAS,GAAG,qBAAaC,MAAF,IAAc;AAAA;;AAC1C,UAAMC,YAAY,GAAGD,MAAM,CAAEE,aAAF,CAAN,CAAsBC,kBAAtB,EAArB;AACA,UAAMC,QAAQ,GAAGJ,MAAM,CAAEK,eAAF,CAAN,CAAoBC,WAApB,CAAiCL,YAAjC,CAAjB;;AACA,QAAK,EAAEG,QAAF,aAAEA,QAAF,eAAEA,QAAQ,CAAEG,QAAZ,CAAL,EAA4B;AAC3B,aAAO,KAAP;AACA;;AAED,UAAMC,QAAQ,GAAGR,MAAM,CAAEE,aAAF,CAAN,CAAsBO,iBAAtB,EAAjB;AACA,UAAMC,YAAY,GACjB,CAAC,CAAEF,QAAQ,CAACG,kBAAZ,IACAC,MAAM,CAACC,IAAP,CAAaL,QAAQ,CAACG,kBAAtB,EAA2CG,MAA3C,GAAoD,CAFrD;;AAGA,QAAKJ,YAAL,EAAoB;AACnB,aAAO,IAAP;AACA;;AAED,QAAK,CAAEF,QAAQ,CAACO,oBAAhB,EAAuC;AACtC,aAAO,KAAP;AACA;;AAED,UAAMC,kBAAkB,sBACvBhB,MAAM,CAAEK,eAAF,CAAN,CAAoBY,OAApB,CAA6B,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B,CAAEa,YAAF,CAAzB;AACA;;AAED,UAAME,QAAQ,GAAG1B,MAAM,CAAE2B,YAAF,CAAN,CAAwBC,qBAAxB,EAAjB;AACA,8BAAOF,QAAP,aAAOA,QAAP,uBAAOA,QAAQ,CAAEG,KAAjB,6DAA0BH,QAA1B,aAA0BA,QAA1B,uBAA0BA,QAAQ,CAAEI,IAApC;AACA,GAZqB,EAYnB,EAZmB,CAAtB;AAcA,SACC,4BAAC,kBAAD;AACC,IAAA,SAAS,EAAC,iCADX;AAEC,IAAA,OAAO,EAAC,UAFT;AAGC,qBAAgBZ,MAHjB;AAIC,kBACCK,aAAa,GACV,oBACA;AACA,kBAAI,qBAAJ,CAFA,EAGAA,aAHA,CADU,GAMV,cAAI,iBAAJ,CAXL;AAaC,IAAA,OAAO,EAAGD;AAbX,KAeGC,aAfH,aAeGA,aAfH,cAeGA,aAfH,GAeoB,cAAI,kBAAJ,CAfpB,CADD;AAmBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useMemo } from '@wordpress/element';\nimport { PanelRow, Dropdown, Button } from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport { store as editorStore } from '@wordpress/editor';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport PostTemplateForm from './form';\nimport { store as editPostStore } from '../../../store';\n\nexport default function PostTemplate() {\n\t// Use internal state instead of a ref to make sure that the component\n\t// re-renders when the popover's anchor updates.\n\tconst [ popoverAnchor, setPopoverAnchor ] = useState( null );\n\t// Memoize popoverProps to avoid returning a new object every time.\n\tconst popoverProps = useMemo(\n\t\t() => ( { anchor: popoverAnchor } ),\n\t\t[ popoverAnchor ]\n\t);\n\n\tconst isVisible = useSelect( ( select ) => {\n\t\tconst postTypeSlug = select( editorStore ).getCurrentPostType();\n\t\tconst postType = select( coreStore ).getPostType( postTypeSlug );\n\t\tif ( ! postType?.viewable ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst settings = select( editorStore ).getEditorSettings();\n\t\tconst hasTemplates =\n\t\t\t!! settings.availableTemplates &&\n\t\t\tObject.keys( settings.availableTemplates ).length > 0;\n\t\tif ( hasTemplates ) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif ( ! settings.supportsTemplateMode ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst canCreateTemplates =\n\t\t\tselect( coreStore ).canUser( 'create', 'templates' ) ?? false;\n\t\treturn canCreateTemplates;\n\t}, [] );\n\n\tif ( ! isVisible ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<PanelRow className=\"edit-post-post-template\" ref={ setPopoverAnchor }>\n\t\t\t<span>{ __( 'Template' ) }</span>\n\t\t\t<Dropdown\n\t\t\t\tpopoverProps={ popoverProps }\n\t\t\t\tposition=\"bottom left\"\n\t\t\t\tclassName=\"edit-post-post-template__dropdown\"\n\t\t\t\tcontentClassName=\"edit-post-post-template__dialog\"\n\t\t\t\tfocusOnMount\n\t\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t\t<PostTemplateToggle\n\t\t\t\t\t\tisOpen={ isOpen }\n\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t\t<PostTemplateForm onClose={ onClose } />\n\t\t\t\t) }\n\t\t\t/>\n\t\t</PanelRow>\n\t);\n}\n\nfunction PostTemplateToggle( { isOpen, onClick } ) {\n\tconst templateTitle = useSelect( ( select ) => {\n\t\tconst templateSlug =\n\t\t\tselect( editorStore ).getEditedPostAttribute( 'template' );\n\n\t\tconst { supportsTemplateMode, availableTemplates } =\n\t\t\tselect( editorStore ).getEditorSettings();\n\t\tif ( ! supportsTemplateMode && availableTemplates[ templateSlug ] ) {\n\t\t\treturn availableTemplates[ templateSlug ];\n\t\t}\n\n\t\tconst template = select( editPostStore ).getEditedPostTemplate();\n\t\treturn template?.title ?? template?.slug;\n\t}, [] );\n\n\treturn (\n\t\t<Button\n\t\t\tclassName=\"edit-post-post-template__toggle\"\n\t\t\tvariant=\"tertiary\"\n\t\t\taria-expanded={ isOpen }\n\t\t\taria-label={\n\t\t\t\ttemplateTitle\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t// translators: %s: Name of the currently selected template.\n\t\t\t\t\t\t\t__( 'Select template: %s' ),\n\t\t\t\t\t\t\ttemplateTitle\n\t\t\t\t\t )\n\t\t\t\t\t: __( 'Select template' )\n\t\t\t}\n\t\t\tonClick={ onClick }\n\t\t>\n\t\t\t{ templateTitle ?? __( 'Default template' ) }\n\t\t</Button>\n\t);\n}\n"]}
@@ -17,14 +17,18 @@ var _editor = require("@wordpress/editor");
17
17
  * WordPress dependencies
18
18
  */
19
19
  function PostURL() {
20
- const anchorRef = (0, _element.useRef)();
20
+ // Use internal state instead of a ref to make sure that the component
21
+ // re-renders when the popover's anchor updates.
22
+ const [popoverAnchor, setPopoverAnchor] = (0, _element.useState)(null); // Memoize popoverProps to avoid returning a new object every time.
23
+
24
+ const popoverProps = (0, _element.useMemo)(() => ({
25
+ anchor: popoverAnchor
26
+ }), [popoverAnchor]);
21
27
  return (0, _element.createElement)(_editor.PostURLCheck, null, (0, _element.createElement)(_components.PanelRow, {
22
28
  className: "edit-post-post-url",
23
- ref: anchorRef
29
+ ref: setPopoverAnchor
24
30
  }, (0, _element.createElement)("span", null, (0, _i18n.__)('URL')), (0, _element.createElement)(_components.Dropdown, {
25
- popoverProps: {
26
- anchorRef
27
- },
31
+ popoverProps: popoverProps,
28
32
  position: "bottom left",
29
33
  className: "edit-post-post-url__dropdown",
30
34
  contentClassName: "edit-post-post-url__dialog",
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/post-url/index.js"],"names":["PostURL","anchorRef","isOpen","onToggle","onClose","PostURLToggle","onClick","label"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AACA;;AANA;AACA;AACA;AAUe,SAASA,OAAT,GAAmB;AACjC,QAAMC,SAAS,GAAG,sBAAlB;AACA,SACC,4BAAC,oBAAD,QACC,4BAAC,oBAAD;AAAU,IAAA,SAAS,EAAC,oBAApB;AAAyC,IAAA,GAAG,EAAGA;AAA/C,KACC,0CAAQ,cAAI,KAAJ,CAAR,CADD,EAEC,4BAAC,oBAAD;AACC,IAAA,YAAY,EAAG;AAAEA,MAAAA;AAAF,KADhB;AAEC,IAAA,QAAQ,EAAC,aAFV;AAGC,IAAA,SAAS,EAAC,8BAHX;AAIC,IAAA,gBAAgB,EAAC,4BAJlB;AAKC,IAAA,YAAY,MALb;AAMC,IAAA,YAAY,EAAG;AAAA,UAAE;AAAEC,QAAAA,MAAF;AAAUC,QAAAA;AAAV,OAAF;AAAA,aACd,4BAAC,aAAD;AAAe,QAAA,MAAM,EAAGD,MAAxB;AAAiC,QAAA,OAAO,EAAGC;AAA3C,QADc;AAAA,KANhB;AASC,IAAA,aAAa,EAAG;AAAA,UAAE;AAAEC,QAAAA;AAAF,OAAF;AAAA,aACf,4BAAC,eAAD;AAAa,QAAA,OAAO,EAAGA;AAAvB,QADe;AAAA;AATjB,IAFD,CADD,CADD;AAoBA;;AAED,SAASC,aAAT,QAA8C;AAAA,MAAtB;AAAEH,IAAAA,MAAF;AAAUI,IAAAA;AAAV,GAAsB;AAC7C,QAAMC,KAAK,GAAG,8BAAd;AACA,SACC,4BAAC,kBAAD;AACC,IAAA,SAAS,EAAC,4BADX;AAEC,IAAA,OAAO,EAAC,UAFT;AAGC,qBAAgBL,MAHjB,CAIC;AAJD;AAKC,kBAAa,mBAAS,cAAI,gBAAJ,CAAT,EAAiCK,KAAjC,CALd;AAMC,IAAA,OAAO,EAAGD;AANX,KAQGC,KARH,CADD;AAYA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\nimport { PanelRow, Dropdown, Button } from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tPostURLCheck,\n\tPostURL as PostURLForm,\n\tusePostURLLabel,\n} from '@wordpress/editor';\n\nexport default function PostURL() {\n\tconst anchorRef = useRef();\n\treturn (\n\t\t<PostURLCheck>\n\t\t\t<PanelRow className=\"edit-post-post-url\" ref={ anchorRef }>\n\t\t\t\t<span>{ __( 'URL' ) }</span>\n\t\t\t\t<Dropdown\n\t\t\t\t\tpopoverProps={ { anchorRef } }\n\t\t\t\t\tposition=\"bottom left\"\n\t\t\t\t\tclassName=\"edit-post-post-url__dropdown\"\n\t\t\t\t\tcontentClassName=\"edit-post-post-url__dialog\"\n\t\t\t\t\tfocusOnMount\n\t\t\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t\t\t<PostURLToggle isOpen={ isOpen } onClick={ onToggle } />\n\t\t\t\t\t) }\n\t\t\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t\t\t<PostURLForm onClose={ onClose } />\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</PanelRow>\n\t\t</PostURLCheck>\n\t);\n}\n\nfunction PostURLToggle( { isOpen, onClick } ) {\n\tconst label = usePostURLLabel();\n\treturn (\n\t\t<Button\n\t\t\tclassName=\"edit-post-post-url__toggle\"\n\t\t\tvariant=\"tertiary\"\n\t\t\taria-expanded={ isOpen }\n\t\t\t// translators: %s: Current post URL.\n\t\t\taria-label={ sprintf( __( 'Change URL: %s' ), label ) }\n\t\t\tonClick={ onClick }\n\t\t>\n\t\t\t{ label }\n\t\t</Button>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/post-url/index.js"],"names":["PostURL","popoverAnchor","setPopoverAnchor","popoverProps","anchor","isOpen","onToggle","onClose","PostURLToggle","onClick","label"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AACA;;AANA;AACA;AACA;AAUe,SAASA,OAAT,GAAmB;AACjC;AACA;AACA,QAAM,CAAEC,aAAF,EAAiBC,gBAAjB,IAAsC,uBAAU,IAAV,CAA5C,CAHiC,CAIjC;;AACA,QAAMC,YAAY,GAAG,sBACpB,OAAQ;AAAEC,IAAAA,MAAM,EAAEH;AAAV,GAAR,CADoB,EAEpB,CAAEA,aAAF,CAFoB,CAArB;AAKA,SACC,4BAAC,oBAAD,QACC,4BAAC,oBAAD;AAAU,IAAA,SAAS,EAAC,oBAApB;AAAyC,IAAA,GAAG,EAAGC;AAA/C,KACC,0CAAQ,cAAI,KAAJ,CAAR,CADD,EAEC,4BAAC,oBAAD;AACC,IAAA,YAAY,EAAGC,YADhB;AAEC,IAAA,QAAQ,EAAC,aAFV;AAGC,IAAA,SAAS,EAAC,8BAHX;AAIC,IAAA,gBAAgB,EAAC,4BAJlB;AAKC,IAAA,YAAY,MALb;AAMC,IAAA,YAAY,EAAG;AAAA,UAAE;AAAEE,QAAAA,MAAF;AAAUC,QAAAA;AAAV,OAAF;AAAA,aACd,4BAAC,aAAD;AAAe,QAAA,MAAM,EAAGD,MAAxB;AAAiC,QAAA,OAAO,EAAGC;AAA3C,QADc;AAAA,KANhB;AASC,IAAA,aAAa,EAAG;AAAA,UAAE;AAAEC,QAAAA;AAAF,OAAF;AAAA,aACf,4BAAC,eAAD;AAAa,QAAA,OAAO,EAAGA;AAAvB,QADe;AAAA;AATjB,IAFD,CADD,CADD;AAoBA;;AAED,SAASC,aAAT,QAA8C;AAAA,MAAtB;AAAEH,IAAAA,MAAF;AAAUI,IAAAA;AAAV,GAAsB;AAC7C,QAAMC,KAAK,GAAG,8BAAd;AACA,SACC,4BAAC,kBAAD;AACC,IAAA,SAAS,EAAC,4BADX;AAEC,IAAA,OAAO,EAAC,UAFT;AAGC,qBAAgBL,MAHjB,CAIC;AAJD;AAKC,kBAAa,mBAAS,cAAI,gBAAJ,CAAT,EAAiCK,KAAjC,CALd;AAMC,IAAA,OAAO,EAAGD;AANX,KAQGC,KARH,CADD;AAYA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useState } from '@wordpress/element';\nimport { PanelRow, Dropdown, Button } from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tPostURLCheck,\n\tPostURL as PostURLForm,\n\tusePostURLLabel,\n} from '@wordpress/editor';\n\nexport default function PostURL() {\n\t// Use internal state instead of a ref to make sure that the component\n\t// re-renders when the popover's anchor updates.\n\tconst [ popoverAnchor, setPopoverAnchor ] = useState( null );\n\t// Memoize popoverProps to avoid returning a new object every time.\n\tconst popoverProps = useMemo(\n\t\t() => ( { anchor: popoverAnchor } ),\n\t\t[ popoverAnchor ]\n\t);\n\n\treturn (\n\t\t<PostURLCheck>\n\t\t\t<PanelRow className=\"edit-post-post-url\" ref={ setPopoverAnchor }>\n\t\t\t\t<span>{ __( 'URL' ) }</span>\n\t\t\t\t<Dropdown\n\t\t\t\t\tpopoverProps={ popoverProps }\n\t\t\t\t\tposition=\"bottom left\"\n\t\t\t\t\tclassName=\"edit-post-post-url__dropdown\"\n\t\t\t\t\tcontentClassName=\"edit-post-post-url__dialog\"\n\t\t\t\t\tfocusOnMount\n\t\t\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t\t\t<PostURLToggle isOpen={ isOpen } onClick={ onToggle } />\n\t\t\t\t\t) }\n\t\t\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t\t\t<PostURLForm onClose={ onClose } />\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</PanelRow>\n\t\t</PostURLCheck>\n\t);\n}\n\nfunction PostURLToggle( { isOpen, onClick } ) {\n\tconst label = usePostURLLabel();\n\treturn (\n\t\t<Button\n\t\t\tclassName=\"edit-post-post-url__toggle\"\n\t\t\tvariant=\"tertiary\"\n\t\t\taria-expanded={ isOpen }\n\t\t\t// translators: %s: Current post URL.\n\t\t\taria-label={ sprintf( __( 'Change URL: %s' ), label ) }\n\t\t\tonClick={ onClick }\n\t\t>\n\t\t\t{ label }\n\t\t</Button>\n\t);\n}\n"]}
@@ -18,24 +18,27 @@ var _editor = require("@wordpress/editor");
18
18
  * WordPress dependencies
19
19
  */
20
20
  function PostVisibility() {
21
- const rowRef = (0, _element.useRef)();
21
+ // Use internal state instead of a ref to make sure that the component
22
+ // re-renders when the popover's anchor updates.
23
+ const [popoverAnchor, setPopoverAnchor] = (0, _element.useState)(null); // Memoize popoverProps to avoid returning a new object every time.
24
+
25
+ const popoverProps = (0, _element.useMemo)(() => ({
26
+ // Anchor the popover to the middle of the entire row so that it doesn't
27
+ // move around when the label changes.
28
+ anchor: popoverAnchor
29
+ }), [popoverAnchor]);
22
30
  return (0, _element.createElement)(_editor.PostVisibilityCheck, {
23
31
  render: _ref => {
24
32
  let {
25
33
  canEdit
26
34
  } = _ref;
27
35
  return (0, _element.createElement)(_components.PanelRow, {
28
- ref: rowRef,
36
+ ref: setPopoverAnchor,
29
37
  className: "edit-post-post-visibility"
30
38
  }, (0, _element.createElement)("span", null, (0, _i18n.__)('Visibility')), !canEdit && (0, _element.createElement)("span", null, (0, _element.createElement)(_editor.PostVisibilityLabel, null)), canEdit && (0, _element.createElement)(_components.Dropdown, {
31
39
  position: "bottom left",
32
40
  contentClassName: "edit-post-post-visibility__dialog",
33
- popoverProps: {
34
- // Anchor the popover to the middle of the
35
- // entire row so that it doesn't move around
36
- // when the label changes.
37
- anchorRef: rowRef.current
38
- },
41
+ popoverProps: popoverProps,
39
42
  focusOnMount: true,
40
43
  renderToggle: _ref2 => {
41
44
  let {
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/post-visibility/index.js"],"names":["PostVisibility","rowRef","canEdit","anchorRef","current","isOpen","onToggle","onClose","PostVisibilityToggle","onClick","label"],"mappings":";;;;;;;;AAWA;;AARA;;AACA;;AACA;;AALA;AACA;AACA;AAWO,SAASA,cAAT,GAA0B;AAChC,QAAMC,MAAM,GAAG,sBAAf;AACA,SACC,4BAAC,2BAAD;AACC,IAAA,MAAM,EAAG;AAAA,UAAE;AAAEC,QAAAA;AAAF,OAAF;AAAA,aACR,4BAAC,oBAAD;AAAU,QAAA,GAAG,EAAGD,MAAhB;AAAyB,QAAA,SAAS,EAAC;AAAnC,SACC,0CAAQ,cAAI,YAAJ,CAAR,CADD,EAEG,CAAEC,OAAF,IACD,0CACC,4BAAC,2BAAD,OADD,CAHF,EAOGA,OAAO,IACR,4BAAC,oBAAD;AACC,QAAA,QAAQ,EAAC,aADV;AAEC,QAAA,gBAAgB,EAAC,mCAFlB;AAGC,QAAA,YAAY,EAAG;AACd;AACA;AACA;AACAC,UAAAA,SAAS,EAAEF,MAAM,CAACG;AAJJ,SAHhB;AASC,QAAA,YAAY,MATb;AAUC,QAAA,YAAY,EAAG;AAAA,cAAE;AAAEC,YAAAA,MAAF;AAAUC,YAAAA;AAAV,WAAF;AAAA,iBACd,4BAAC,oBAAD;AACC,YAAA,MAAM,EAAGD,MADV;AAEC,YAAA,OAAO,EAAGC;AAFX,YADc;AAAA,SAVhB;AAgBC,QAAA,aAAa,EAAG;AAAA,cAAE;AAAEC,YAAAA;AAAF,WAAF;AAAA,iBACf,4BAAC,sBAAD;AAAoB,YAAA,OAAO,EAAGA;AAA9B,YADe;AAAA;AAhBjB,QARF,CADQ;AAAA;AADV,IADD;AAoCA;;AAED,SAASC,oBAAT,QAAqD;AAAA,MAAtB;AAAEH,IAAAA,MAAF;AAAUI,IAAAA;AAAV,GAAsB;AACpD,QAAMC,KAAK,GAAG,qCAAd;AACA,SACC,4BAAC,kBAAD;AACC,IAAA,SAAS,EAAC,mCADX;AAEC,IAAA,OAAO,EAAC,UAFT;AAGC,qBAAgBL,MAHjB,CAIC;AAJD;AAKC,kBAAa,mBAAS,cAAI,uBAAJ,CAAT,EAAwCK,KAAxC,CALd;AAMC,IAAA,OAAO,EAAGD;AANX,KAQGC,KARH,CADD;AAYA;;eAEcV,c","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { PanelRow, Dropdown, Button } from '@wordpress/components';\nimport {\n\tPostVisibility as PostVisibilityForm,\n\tPostVisibilityLabel,\n\tPostVisibilityCheck,\n\tusePostVisibilityLabel,\n} from '@wordpress/editor';\nimport { useRef } from '@wordpress/element';\n\nexport function PostVisibility() {\n\tconst rowRef = useRef();\n\treturn (\n\t\t<PostVisibilityCheck\n\t\t\trender={ ( { canEdit } ) => (\n\t\t\t\t<PanelRow ref={ rowRef } className=\"edit-post-post-visibility\">\n\t\t\t\t\t<span>{ __( 'Visibility' ) }</span>\n\t\t\t\t\t{ ! canEdit && (\n\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t<PostVisibilityLabel />\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) }\n\t\t\t\t\t{ canEdit && (\n\t\t\t\t\t\t<Dropdown\n\t\t\t\t\t\t\tposition=\"bottom left\"\n\t\t\t\t\t\t\tcontentClassName=\"edit-post-post-visibility__dialog\"\n\t\t\t\t\t\t\tpopoverProps={ {\n\t\t\t\t\t\t\t\t// Anchor the popover to the middle of the\n\t\t\t\t\t\t\t\t// entire row so that it doesn't move around\n\t\t\t\t\t\t\t\t// when the label changes.\n\t\t\t\t\t\t\t\tanchorRef: rowRef.current,\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tfocusOnMount\n\t\t\t\t\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t\t\t\t\t<PostVisibilityToggle\n\t\t\t\t\t\t\t\t\tisOpen={ isOpen }\n\t\t\t\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t\t\t\t\t<PostVisibilityForm onClose={ onClose } />\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</PanelRow>\n\t\t\t) }\n\t\t/>\n\t);\n}\n\nfunction PostVisibilityToggle( { isOpen, onClick } ) {\n\tconst label = usePostVisibilityLabel();\n\treturn (\n\t\t<Button\n\t\t\tclassName=\"edit-post-post-visibility__toggle\"\n\t\t\tvariant=\"tertiary\"\n\t\t\taria-expanded={ isOpen }\n\t\t\t// translators: %s: Current post visibility.\n\t\t\taria-label={ sprintf( __( 'Select visibility: %s' ), label ) }\n\t\t\tonClick={ onClick }\n\t\t>\n\t\t\t{ label }\n\t\t</Button>\n\t);\n}\n\nexport default PostVisibility;\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/post-visibility/index.js"],"names":["PostVisibility","popoverAnchor","setPopoverAnchor","popoverProps","anchor","canEdit","isOpen","onToggle","onClose","PostVisibilityToggle","onClick","label"],"mappings":";;;;;;;;AAWA;;AARA;;AACA;;AACA;;AALA;AACA;AACA;AAWO,SAASA,cAAT,GAA0B;AAChC;AACA;AACA,QAAM,CAAEC,aAAF,EAAiBC,gBAAjB,IAAsC,uBAAU,IAAV,CAA5C,CAHgC,CAIhC;;AACA,QAAMC,YAAY,GAAG,sBACpB,OAAQ;AACP;AACA;AACAC,IAAAA,MAAM,EAAEH;AAHD,GAAR,CADoB,EAMpB,CAAEA,aAAF,CANoB,CAArB;AASA,SACC,4BAAC,2BAAD;AACC,IAAA,MAAM,EAAG;AAAA,UAAE;AAAEI,QAAAA;AAAF,OAAF;AAAA,aACR,4BAAC,oBAAD;AACC,QAAA,GAAG,EAAGH,gBADP;AAEC,QAAA,SAAS,EAAC;AAFX,SAIC,0CAAQ,cAAI,YAAJ,CAAR,CAJD,EAKG,CAAEG,OAAF,IACD,0CACC,4BAAC,2BAAD,OADD,CANF,EAUGA,OAAO,IACR,4BAAC,oBAAD;AACC,QAAA,QAAQ,EAAC,aADV;AAEC,QAAA,gBAAgB,EAAC,mCAFlB;AAGC,QAAA,YAAY,EAAGF,YAHhB;AAIC,QAAA,YAAY,MAJb;AAKC,QAAA,YAAY,EAAG;AAAA,cAAE;AAAEG,YAAAA,MAAF;AAAUC,YAAAA;AAAV,WAAF;AAAA,iBACd,4BAAC,oBAAD;AACC,YAAA,MAAM,EAAGD,MADV;AAEC,YAAA,OAAO,EAAGC;AAFX,YADc;AAAA,SALhB;AAWC,QAAA,aAAa,EAAG;AAAA,cAAE;AAAEC,YAAAA;AAAF,WAAF;AAAA,iBACf,4BAAC,sBAAD;AAAoB,YAAA,OAAO,EAAGA;AAA9B,YADe;AAAA;AAXjB,QAXF,CADQ;AAAA;AADV,IADD;AAkCA;;AAED,SAASC,oBAAT,QAAqD;AAAA,MAAtB;AAAEH,IAAAA,MAAF;AAAUI,IAAAA;AAAV,GAAsB;AACpD,QAAMC,KAAK,GAAG,qCAAd;AACA,SACC,4BAAC,kBAAD;AACC,IAAA,SAAS,EAAC,mCADX;AAEC,IAAA,OAAO,EAAC,UAFT;AAGC,qBAAgBL,MAHjB,CAIC;AAJD;AAKC,kBAAa,mBAAS,cAAI,uBAAJ,CAAT,EAAwCK,KAAxC,CALd;AAMC,IAAA,OAAO,EAAGD;AANX,KAQGC,KARH,CADD;AAYA;;eAEcX,c","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { PanelRow, Dropdown, Button } from '@wordpress/components';\nimport {\n\tPostVisibility as PostVisibilityForm,\n\tPostVisibilityLabel,\n\tPostVisibilityCheck,\n\tusePostVisibilityLabel,\n} from '@wordpress/editor';\nimport { useMemo, useState } from '@wordpress/element';\n\nexport function PostVisibility() {\n\t// Use internal state instead of a ref to make sure that the component\n\t// re-renders when the popover's anchor updates.\n\tconst [ popoverAnchor, setPopoverAnchor ] = useState( null );\n\t// Memoize popoverProps to avoid returning a new object every time.\n\tconst popoverProps = useMemo(\n\t\t() => ( {\n\t\t\t// Anchor the popover to the middle of the entire row so that it doesn't\n\t\t\t// move around when the label changes.\n\t\t\tanchor: popoverAnchor,\n\t\t} ),\n\t\t[ popoverAnchor ]\n\t);\n\n\treturn (\n\t\t<PostVisibilityCheck\n\t\t\trender={ ( { canEdit } ) => (\n\t\t\t\t<PanelRow\n\t\t\t\t\tref={ setPopoverAnchor }\n\t\t\t\t\tclassName=\"edit-post-post-visibility\"\n\t\t\t\t>\n\t\t\t\t\t<span>{ __( 'Visibility' ) }</span>\n\t\t\t\t\t{ ! canEdit && (\n\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t<PostVisibilityLabel />\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) }\n\t\t\t\t\t{ canEdit && (\n\t\t\t\t\t\t<Dropdown\n\t\t\t\t\t\t\tposition=\"bottom left\"\n\t\t\t\t\t\t\tcontentClassName=\"edit-post-post-visibility__dialog\"\n\t\t\t\t\t\t\tpopoverProps={ popoverProps }\n\t\t\t\t\t\t\tfocusOnMount\n\t\t\t\t\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t\t\t\t\t<PostVisibilityToggle\n\t\t\t\t\t\t\t\t\tisOpen={ isOpen }\n\t\t\t\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t\t\t\t\t<PostVisibilityForm onClose={ onClose } />\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</PanelRow>\n\t\t\t) }\n\t\t/>\n\t);\n}\n\nfunction PostVisibilityToggle( { isOpen, onClick } ) {\n\tconst label = usePostVisibilityLabel();\n\treturn (\n\t\t<Button\n\t\t\tclassName=\"edit-post-post-visibility__toggle\"\n\t\t\tvariant=\"tertiary\"\n\t\t\taria-expanded={ isOpen }\n\t\t\t// translators: %s: Current post visibility.\n\t\t\taria-label={ sprintf( __( 'Select visibility: %s' ), label ) }\n\t\t\tonClick={ onClick }\n\t\t>\n\t\t\t{ label }\n\t\t</Button>\n\t);\n}\n\nexport default PostVisibility;\n"]}
@@ -5,17 +5,21 @@ import { createElement } from "@wordpress/element";
5
5
  */
6
6
  import { __, sprintf } from '@wordpress/i18n';
7
7
  import { PanelRow, Dropdown, Button } from '@wordpress/components';
8
- import { useRef } from '@wordpress/element';
8
+ import { useState, useMemo } from '@wordpress/element';
9
9
  import { PostSchedule as PostScheduleForm, PostScheduleCheck, usePostScheduleLabel } from '@wordpress/editor';
10
10
  export default function PostSchedule() {
11
- const anchorRef = useRef();
11
+ // Use internal state instead of a ref to make sure that the component
12
+ // re-renders when the popover's anchor updates.
13
+ const [popoverAnchor, setPopoverAnchor] = useState(null); // Memoize popoverProps to avoid returning a new object every time.
14
+
15
+ const popoverProps = useMemo(() => ({
16
+ anchor: popoverAnchor
17
+ }), [popoverAnchor]);
12
18
  return createElement(PostScheduleCheck, null, createElement(PanelRow, {
13
19
  className: "edit-post-post-schedule",
14
- ref: anchorRef
20
+ ref: setPopoverAnchor
15
21
  }, createElement("span", null, __('Publish')), createElement(Dropdown, {
16
- popoverProps: {
17
- anchorRef
18
- },
22
+ popoverProps: popoverProps,
19
23
  position: "bottom left",
20
24
  contentClassName: "edit-post-post-schedule__dialog",
21
25
  focusOnMount: true,
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/post-schedule/index.js"],"names":["__","sprintf","PanelRow","Dropdown","Button","useRef","PostSchedule","PostScheduleForm","PostScheduleCheck","usePostScheduleLabel","anchorRef","isOpen","onToggle","onClose","PostScheduleToggle","onClick","label","fullLabel","full"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,QAAT,EAAmBC,QAAnB,EAA6BC,MAA7B,QAA2C,uBAA3C;AACA,SAASC,MAAT,QAAuB,oBAAvB;AACA,SACCC,YAAY,IAAIC,gBADjB,EAECC,iBAFD,EAGCC,oBAHD,QAIO,mBAJP;AAMA,eAAe,SAASH,YAAT,GAAwB;AACtC,QAAMI,SAAS,GAAGL,MAAM,EAAxB;AACA,SACC,cAAC,iBAAD,QACC,cAAC,QAAD;AAAU,IAAA,SAAS,EAAC,yBAApB;AAA8C,IAAA,GAAG,EAAGK;AAApD,KACC,4BAAQV,EAAE,CAAE,SAAF,CAAV,CADD,EAEC,cAAC,QAAD;AACC,IAAA,YAAY,EAAG;AAAEU,MAAAA;AAAF,KADhB;AAEC,IAAA,QAAQ,EAAC,aAFV;AAGC,IAAA,gBAAgB,EAAC,iCAHlB;AAIC,IAAA,YAAY,MAJb;AAKC,IAAA,YAAY,EAAG;AAAA,UAAE;AAAEC,QAAAA,MAAF;AAAUC,QAAAA;AAAV,OAAF;AAAA,aACd,cAAC,kBAAD;AACC,QAAA,MAAM,EAAGD,MADV;AAEC,QAAA,OAAO,EAAGC;AAFX,QADc;AAAA,KALhB;AAWC,IAAA,aAAa,EAAG;AAAA,UAAE;AAAEC,QAAAA;AAAF,OAAF;AAAA,aACf,cAAC,gBAAD;AAAkB,QAAA,OAAO,EAAGA;AAA5B,QADe;AAAA;AAXjB,IAFD,CADD,CADD;AAsBA;;AAED,SAASC,kBAAT,QAAmD;AAAA,MAAtB;AAAEH,IAAAA,MAAF;AAAUI,IAAAA;AAAV,GAAsB;AAClD,QAAMC,KAAK,GAAGP,oBAAoB,EAAlC;AACA,QAAMQ,SAAS,GAAGR,oBAAoB,CAAE;AAAES,IAAAA,IAAI,EAAE;AAAR,GAAF,CAAtC;AACA,SACC,cAAC,MAAD;AACC,IAAA,SAAS,EAAC,iCADX;AAEC,IAAA,OAAO,EAAC,UAFT;AAGC,IAAA,KAAK,EAAGD,SAHT;AAIC,IAAA,WAAW,MAJZ;AAKC,qBAAgBN,MALjB,CAMC;AAND;AAOC,kBAAaV,OAAO,CAAED,EAAE,CAAE,iBAAF,CAAJ,EAA2BgB,KAA3B,CAPrB;AAQC,IAAA,OAAO,EAAGD;AARX,KAUGC,KAVH,CADD;AAcA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { PanelRow, Dropdown, Button } from '@wordpress/components';\nimport { useRef } from '@wordpress/element';\nimport {\n\tPostSchedule as PostScheduleForm,\n\tPostScheduleCheck,\n\tusePostScheduleLabel,\n} from '@wordpress/editor';\n\nexport default function PostSchedule() {\n\tconst anchorRef = useRef();\n\treturn (\n\t\t<PostScheduleCheck>\n\t\t\t<PanelRow className=\"edit-post-post-schedule\" ref={ anchorRef }>\n\t\t\t\t<span>{ __( 'Publish' ) }</span>\n\t\t\t\t<Dropdown\n\t\t\t\t\tpopoverProps={ { anchorRef } }\n\t\t\t\t\tposition=\"bottom left\"\n\t\t\t\t\tcontentClassName=\"edit-post-post-schedule__dialog\"\n\t\t\t\t\tfocusOnMount\n\t\t\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t\t\t<PostScheduleToggle\n\t\t\t\t\t\t\tisOpen={ isOpen }\n\t\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t\t\t<PostScheduleForm onClose={ onClose } />\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</PanelRow>\n\t\t</PostScheduleCheck>\n\t);\n}\n\nfunction PostScheduleToggle( { isOpen, onClick } ) {\n\tconst label = usePostScheduleLabel();\n\tconst fullLabel = usePostScheduleLabel( { full: true } );\n\treturn (\n\t\t<Button\n\t\t\tclassName=\"edit-post-post-schedule__toggle\"\n\t\t\tvariant=\"tertiary\"\n\t\t\tlabel={ fullLabel }\n\t\t\tshowTooltip\n\t\t\taria-expanded={ isOpen }\n\t\t\t// translators: %s: Current post date.\n\t\t\taria-label={ sprintf( __( 'Change date: %s' ), label ) }\n\t\t\tonClick={ onClick }\n\t\t>\n\t\t\t{ label }\n\t\t</Button>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/post-schedule/index.js"],"names":["__","sprintf","PanelRow","Dropdown","Button","useState","useMemo","PostSchedule","PostScheduleForm","PostScheduleCheck","usePostScheduleLabel","popoverAnchor","setPopoverAnchor","popoverProps","anchor","isOpen","onToggle","onClose","PostScheduleToggle","onClick","label","fullLabel","full"],"mappings":";;AAAA;AACA;AACA;AAC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oBAAoB,EAAlC;AACA,QAAMW,SAAS,GAAGX,oBAAoB,CAAE;AAAEY,IAAAA,IAAI,EAAE;AAAR,GAAF,CAAtC;AACA,SACC,cAAC,MAAD;AACC,IAAA,SAAS,EAAC,iCADX;AAEC,IAAA,OAAO,EAAC,UAFT;AAGC,IAAA,KAAK,EAAGD,SAHT;AAIC,IAAA,WAAW,MAJZ;AAKC,qBAAgBN,MALjB,CAMC;AAND;AAOC,kBAAad,OAAO,CAAED,EAAE,CAAE,iBAAF,CAAJ,EAA2BoB,KAA3B,CAPrB;AAQC,IAAA,OAAO,EAAGD;AARX,KAUGC,KAVH,CADD;AAcA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { PanelRow, Dropdown, Button } from '@wordpress/components';\nimport { useState, useMemo } from '@wordpress/element';\nimport {\n\tPostSchedule as PostScheduleForm,\n\tPostScheduleCheck,\n\tusePostScheduleLabel,\n} from '@wordpress/editor';\n\nexport default function PostSchedule() {\n\t// Use internal state instead of a ref to make sure that the component\n\t// re-renders when the popover's anchor updates.\n\tconst [ popoverAnchor, setPopoverAnchor ] = useState( null );\n\t// Memoize popoverProps to avoid returning a new object every time.\n\tconst popoverProps = useMemo(\n\t\t() => ( { anchor: popoverAnchor } ),\n\t\t[ popoverAnchor ]\n\t);\n\n\treturn (\n\t\t<PostScheduleCheck>\n\t\t\t<PanelRow\n\t\t\t\tclassName=\"edit-post-post-schedule\"\n\t\t\t\tref={ setPopoverAnchor }\n\t\t\t>\n\t\t\t\t<span>{ __( 'Publish' ) }</span>\n\t\t\t\t<Dropdown\n\t\t\t\t\tpopoverProps={ popoverProps }\n\t\t\t\t\tposition=\"bottom left\"\n\t\t\t\t\tcontentClassName=\"edit-post-post-schedule__dialog\"\n\t\t\t\t\tfocusOnMount\n\t\t\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t\t\t<PostScheduleToggle\n\t\t\t\t\t\t\tisOpen={ isOpen }\n\t\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t\t\t<PostScheduleForm onClose={ onClose } />\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</PanelRow>\n\t\t</PostScheduleCheck>\n\t);\n}\n\nfunction PostScheduleToggle( { isOpen, onClick } ) {\n\tconst label = usePostScheduleLabel();\n\tconst fullLabel = usePostScheduleLabel( { full: true } );\n\treturn (\n\t\t<Button\n\t\t\tclassName=\"edit-post-post-schedule__toggle\"\n\t\t\tvariant=\"tertiary\"\n\t\t\tlabel={ fullLabel }\n\t\t\tshowTooltip\n\t\t\taria-expanded={ isOpen }\n\t\t\t// translators: %s: Current post date.\n\t\t\taria-label={ sprintf( __( 'Change date: %s' ), label ) }\n\t\t\tonClick={ onClick }\n\t\t>\n\t\t\t{ label }\n\t\t</Button>\n\t);\n}\n"]}
@@ -3,7 +3,7 @@ import { createElement } from "@wordpress/element";
3
3
  /**
4
4
  * WordPress dependencies
5
5
  */
6
- import { useRef } from '@wordpress/element';
6
+ import { useState, useMemo } from '@wordpress/element';
7
7
  import { PanelRow, Dropdown, Button } from '@wordpress/components';
8
8
  import { __, sprintf } from '@wordpress/i18n';
9
9
  import { useSelect } from '@wordpress/data';
@@ -16,7 +16,13 @@ import { store as coreStore } from '@wordpress/core-data';
16
16
  import PostTemplateForm from './form';
17
17
  import { store as editPostStore } from '../../../store';
18
18
  export default function PostTemplate() {
19
- const anchorRef = useRef();
19
+ // Use internal state instead of a ref to make sure that the component
20
+ // re-renders when the popover's anchor updates.
21
+ const [popoverAnchor, setPopoverAnchor] = useState(null); // Memoize popoverProps to avoid returning a new object every time.
22
+
23
+ const popoverProps = useMemo(() => ({
24
+ anchor: popoverAnchor
25
+ }), [popoverAnchor]);
20
26
  const isVisible = useSelect(select => {
21
27
  var _select$canUser;
22
28
 
@@ -48,11 +54,9 @@ export default function PostTemplate() {
48
54
 
49
55
  return createElement(PanelRow, {
50
56
  className: "edit-post-post-template",
51
- ref: anchorRef
57
+ ref: setPopoverAnchor
52
58
  }, createElement("span", null, __('Template')), createElement(Dropdown, {
53
- popoverProps: {
54
- anchorRef
55
- },
59
+ popoverProps: popoverProps,
56
60
  position: "bottom left",
57
61
  className: "edit-post-post-template__dropdown",
58
62
  contentClassName: "edit-post-post-template__dialog",
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/post-template/index.js"],"names":["useRef","PanelRow","Dropdown","Button","__","sprintf","useSelect","store","editorStore","coreStore","PostTemplateForm","editPostStore","PostTemplate","anchorRef","isVisible","select","postTypeSlug","getCurrentPostType","postType","getPostType","viewable","settings","getEditorSettings","hasTemplates","availableTemplates","Object","keys","length","supportsTemplateMode","canCreateTemplates","canUser","isOpen","onToggle","onClose","PostTemplateToggle","onClick","templateTitle","templateSlug","getEditedPostAttribute","template","getEditedPostTemplate","title","slug"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,MAAT,QAAuB,oBAAvB;AACA,SAASC,QAAT,EAAmBC,QAAnB,EAA6BC,MAA7B,QAA2C,uBAA3C;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,KAAK,IAAIC,WAAlB,QAAqC,mBAArC;AACA,SAASD,KAAK,IAAIE,SAAlB,QAAmC,sBAAnC;AAEA;AACA;AACA;;AACA,OAAOC,gBAAP,MAA6B,QAA7B;AACA,SAASH,KAAK,IAAII,aAAlB,QAAuC,gBAAvC;AAEA,eAAe,SAASC,YAAT,GAAwB;AACtC,QAAMC,SAAS,GAAGb,MAAM,EAAxB;AAEA,QAAMc,SAAS,GAAGR,SAAS,CAAIS,MAAF,IAAc;AAAA;;AAC1C,UAAMC,YAAY,GAAGD,MAAM,CAAEP,WAAF,CAAN,CAAsBS,kBAAtB,EAArB;AACA,UAAMC,QAAQ,GAAGH,MAAM,CAAEN,S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n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\nimport { PanelRow, Dropdown, Button } from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport { store as editorStore } from '@wordpress/editor';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport PostTemplateForm from './form';\nimport { store as editPostStore } from '../../../store';\n\nexport default function PostTemplate() {\n\tconst anchorRef = useRef();\n\n\tconst isVisible = useSelect( ( select ) => {\n\t\tconst postTypeSlug = select( editorStore ).getCurrentPostType();\n\t\tconst postType = select( coreStore ).getPostType( postTypeSlug );\n\t\tif ( ! postType?.viewable ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst settings = select( editorStore ).getEditorSettings();\n\t\tconst hasTemplates =\n\t\t\t!! settings.availableTemplates &&\n\t\t\tObject.keys( settings.availableTemplates ).length > 0;\n\t\tif ( hasTemplates ) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif ( ! settings.supportsTemplateMode ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst canCreateTemplates =\n\t\t\tselect( coreStore ).canUser( 'create', 'templates' ) ?? false;\n\t\treturn canCreateTemplates;\n\t}, [] );\n\n\tif ( ! isVisible ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<PanelRow className=\"edit-post-post-template\" ref={ anchorRef }>\n\t\t\t<span>{ __( 'Template' ) }</span>\n\t\t\t<Dropdown\n\t\t\t\tpopoverProps={ { anchorRef } }\n\t\t\t\tposition=\"bottom left\"\n\t\t\t\tclassName=\"edit-post-post-template__dropdown\"\n\t\t\t\tcontentClassName=\"edit-post-post-template__dialog\"\n\t\t\t\tfocusOnMount\n\t\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t\t<PostTemplateToggle\n\t\t\t\t\t\tisOpen={ isOpen }\n\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t\t<PostTemplateForm onClose={ onClose } />\n\t\t\t\t) }\n\t\t\t/>\n\t\t</PanelRow>\n\t);\n}\n\nfunction PostTemplateToggle( { isOpen, onClick } ) {\n\tconst templateTitle = useSelect( ( select ) => {\n\t\tconst templateSlug =\n\t\t\tselect( editorStore ).getEditedPostAttribute( 'template' );\n\n\t\tconst { supportsTemplateMode, availableTemplates } =\n\t\t\tselect( editorStore ).getEditorSettings();\n\t\tif ( ! supportsTemplateMode && availableTemplates[ templateSlug ] ) {\n\t\t\treturn availableTemplates[ templateSlug ];\n\t\t}\n\n\t\tconst template = select( editPostStore ).getEditedPostTemplate();\n\t\treturn template?.title ?? template?.slug;\n\t}, [] );\n\n\treturn (\n\t\t<Button\n\t\t\tclassName=\"edit-post-post-template__toggle\"\n\t\t\tvariant=\"tertiary\"\n\t\t\taria-expanded={ isOpen }\n\t\t\taria-label={\n\t\t\t\ttemplateTitle\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t// translators: %s: Name of the currently selected template.\n\t\t\t\t\t\t\t__( 'Select template: %s' ),\n\t\t\t\t\t\t\ttemplateTitle\n\t\t\t\t\t )\n\t\t\t\t\t: __( 'Select template' )\n\t\t\t}\n\t\t\tonClick={ onClick }\n\t\t>\n\t\t\t{ templateTitle ?? __( 'Default template' ) }\n\t\t</Button>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/post-template/index.js"],"names":["useState","useMemo","PanelRow","Dropdown","Button","__","sprintf","useSelect","store","editorStore","coreStore","PostTemplateForm","editPostStore","PostTemplate","popoverAnchor","setPopoverAnchor","popoverProps","anchor","isVisible","select","postTypeSlug","getCurrentPostType","postType","getPostType","viewable","settings","getEditorSettings","hasTemplates","availableTemplates","Object","keys","length","supportsTemplateMode","canCreateTemplates","canUser","isOpen","onToggle","onClose","PostTemplateToggle","onClick","templateTitle","templateSlug","getEditedPostAttribute","template","getEditedPostTemplate","title","slug"],"mappings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AAA,oBAAF;AAAwBJ,MAAAA;AAAxB,QACLT,MAAM,CAAEV,WAAF,CAAN,CAAsBiB,iBAAtB,EADD;;AAEA,QAAK,CAAEM,oBAAF,IAA0BJ,kBAAkB,CAAEa,YAAF,CAAjD,EAAoE;AACnE,aAAOb,kBAAkB,CAAEa,YAAF,CAAzB;AACA;;AAED,UAAME,QAAQ,GAAGxB,MAAM,CAAEP,aAAF,CAAN,CAAwBgC,qBAAxB,EAAjB;AACA,8BAAOD,QAAP,aAAOA,QAAP,uBAAOA,QAAQ,CAAEE,KAAjB,6DAA0BF,QAA1B,aAA0BA,QAA1B,uBAA0BA,QAAQ,CAAEG,IAApC;AACA,GAZ8B,EAY5B,EAZ4B,CAA/B;AAcA,SACC,cAAC,MAAD;AACC,IAAA,SAAS,EAAC,iCADX;AAEC,IAAA,OAAO,EAAC,UAFT;AAGC,qBAAgBX,MAHjB;AAIC,kBACCK,aAAa,GACVlC,OAAO,EACP;AACAD,IAAAA,EAAE,CAAE,qBAAF,CAFK,EAGPmC,aAHO,CADG,GAMVnC,EAAE,CAAE,iBAAF,CAXP;AAaC,IAAA,OAAO,EAAGkC;AAbX,KAeGC,aAfH,aAeGA,aAfH,cAeGA,aAfH,GAeoBnC,EAAE,CAAE,kBAAF,CAftB,CADD;AAmBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useMemo } from '@wordpress/element';\nimport { PanelRow, Dropdown, Button } from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport { store as editorStore } from '@wordpress/editor';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport PostTemplateForm from './form';\nimport { store as editPostStore } from '../../../store';\n\nexport default function PostTemplate() {\n\t// Use internal state instead of a ref to make sure that the component\n\t// re-renders when the popover's anchor updates.\n\tconst [ popoverAnchor, setPopoverAnchor ] = useState( null );\n\t// Memoize popoverProps to avoid returning a new object every time.\n\tconst popoverProps = useMemo(\n\t\t() => ( { anchor: popoverAnchor } ),\n\t\t[ popoverAnchor ]\n\t);\n\n\tconst isVisible = useSelect( ( select ) => {\n\t\tconst postTypeSlug = select( editorStore ).getCurrentPostType();\n\t\tconst postType = select( coreStore ).getPostType( postTypeSlug );\n\t\tif ( ! postType?.viewable ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst settings = select( editorStore ).getEditorSettings();\n\t\tconst hasTemplates =\n\t\t\t!! settings.availableTemplates &&\n\t\t\tObject.keys( settings.availableTemplates ).length > 0;\n\t\tif ( hasTemplates ) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif ( ! settings.supportsTemplateMode ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst canCreateTemplates =\n\t\t\tselect( coreStore ).canUser( 'create', 'templates' ) ?? false;\n\t\treturn canCreateTemplates;\n\t}, [] );\n\n\tif ( ! isVisible ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<PanelRow className=\"edit-post-post-template\" ref={ setPopoverAnchor }>\n\t\t\t<span>{ __( 'Template' ) }</span>\n\t\t\t<Dropdown\n\t\t\t\tpopoverProps={ popoverProps }\n\t\t\t\tposition=\"bottom left\"\n\t\t\t\tclassName=\"edit-post-post-template__dropdown\"\n\t\t\t\tcontentClassName=\"edit-post-post-template__dialog\"\n\t\t\t\tfocusOnMount\n\t\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t\t<PostTemplateToggle\n\t\t\t\t\t\tisOpen={ isOpen }\n\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t\t<PostTemplateForm onClose={ onClose } />\n\t\t\t\t) }\n\t\t\t/>\n\t\t</PanelRow>\n\t);\n}\n\nfunction PostTemplateToggle( { isOpen, onClick } ) {\n\tconst templateTitle = useSelect( ( select ) => {\n\t\tconst templateSlug =\n\t\t\tselect( editorStore ).getEditedPostAttribute( 'template' );\n\n\t\tconst { supportsTemplateMode, availableTemplates } =\n\t\t\tselect( editorStore ).getEditorSettings();\n\t\tif ( ! supportsTemplateMode && availableTemplates[ templateSlug ] ) {\n\t\t\treturn availableTemplates[ templateSlug ];\n\t\t}\n\n\t\tconst template = select( editPostStore ).getEditedPostTemplate();\n\t\treturn template?.title ?? template?.slug;\n\t}, [] );\n\n\treturn (\n\t\t<Button\n\t\t\tclassName=\"edit-post-post-template__toggle\"\n\t\t\tvariant=\"tertiary\"\n\t\t\taria-expanded={ isOpen }\n\t\t\taria-label={\n\t\t\t\ttemplateTitle\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t// translators: %s: Name of the currently selected template.\n\t\t\t\t\t\t\t__( 'Select template: %s' ),\n\t\t\t\t\t\t\ttemplateTitle\n\t\t\t\t\t )\n\t\t\t\t\t: __( 'Select template' )\n\t\t\t}\n\t\t\tonClick={ onClick }\n\t\t>\n\t\t\t{ templateTitle ?? __( 'Default template' ) }\n\t\t</Button>\n\t);\n}\n"]}
@@ -3,19 +3,23 @@ import { createElement } from "@wordpress/element";
3
3
  /**
4
4
  * WordPress dependencies
5
5
  */
6
- import { useRef } from '@wordpress/element';
6
+ import { useMemo, useState } from '@wordpress/element';
7
7
  import { PanelRow, Dropdown, Button } from '@wordpress/components';
8
8
  import { __, sprintf } from '@wordpress/i18n';
9
9
  import { PostURLCheck, PostURL as PostURLForm, usePostURLLabel } from '@wordpress/editor';
10
10
  export default function PostURL() {
11
- const anchorRef = useRef();
11
+ // Use internal state instead of a ref to make sure that the component
12
+ // re-renders when the popover's anchor updates.
13
+ const [popoverAnchor, setPopoverAnchor] = useState(null); // Memoize popoverProps to avoid returning a new object every time.
14
+
15
+ const popoverProps = useMemo(() => ({
16
+ anchor: popoverAnchor
17
+ }), [popoverAnchor]);
12
18
  return createElement(PostURLCheck, null, createElement(PanelRow, {
13
19
  className: "edit-post-post-url",
14
- ref: anchorRef
20
+ ref: setPopoverAnchor
15
21
  }, createElement("span", null, __('URL')), createElement(Dropdown, {
16
- popoverProps: {
17
- anchorRef
18
- },
22
+ popoverProps: popoverProps,
19
23
  position: "bottom left",
20
24
  className: "edit-post-post-url__dropdown",
21
25
  contentClassName: "edit-post-post-url__dialog",
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/post-url/index.js"],"names":["useRef","PanelRow","Dropdown","Button","__","sprintf","PostURLCheck","PostURL","PostURLForm","usePostURLLabel","anchorRef","isOpen","onToggle","onClose","PostURLToggle","onClick","label"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,MAAT,QAAuB,oBAAvB;AACA,SAASC,QAAT,EAAmBC,QAAnB,EAA6BC,MAA7B,QAA2C,uBAA3C;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SACCC,YADD,EAECC,OAAO,IAAIC,WAFZ,EAGCC,eAHD,QAIO,mBAJP;AAMA,eAAe,SAASF,OAAT,GAAmB;AACjC,QAAMG,SAAS,GAAGV,MAAM,EAAxB;AACA,SACC,cAAC,YAAD,QACC,cAAC,QAAD;AAAU,IAAA,SAAS,EAAC,oBAApB;AAAyC,IAAA,GAAG,EAAGU;AAA/C,KACC,4BAAQN,EAAE,CAAE,KAAF,CAAV,CADD,EAEC,cAAC,QAAD;AACC,IAAA,YAAY,EAAG;AAAEM,MAAAA;AAAF,KADhB;AAEC,IAAA,QAAQ,EAAC,aAFV;AAGC,IAAA,SAAS,EAAC,8BAHX;AAIC,IAAA,gBAAgB,EAAC,4BAJlB;AAKC,IAAA,YAAY,MALb;AAMC,IAAA,YAAY,EAAG;AAAA,UAAE;AAAEC,QAAAA,MAAF;AAAUC,QAAAA;AAAV,OAAF;AAAA,aACd,cAAC,aAAD;AAAe,QAAA,MAAM,EAAGD,MAAxB;AAAiC,QAAA,OAAO,EAAGC;AAA3C,QADc;AAAA,KANhB;AASC,IAAA,aAAa,EAAG;AAAA,UAAE;AAAEC,QAAAA;AAAF,OAAF;AAAA,aACf,cAAC,WAAD;AAAa,QAAA,OAAO,EAAGA;AAAvB,QADe;AAAA;AATjB,IAFD,CADD,CADD;AAoBA;;AAED,SAASC,aAAT,QAA8C;AAAA,MAAtB;AAAEH,IAAAA,MAAF;AAAUI,IAAAA;AAAV,GAAsB;AAC7C,QAAMC,KAAK,GAAGP,eAAe,EAA7B;AACA,SACC,cAAC,MAAD;AACC,IAAA,SAAS,EAAC,4BADX;AAEC,IAAA,OAAO,EAAC,UAFT;AAGC,qBAAgBE,MAHjB,CAIC;AAJD;AAKC,kBAAaN,OAAO,CAAED,EAAE,CAAE,gBAAF,CAAJ,EAA0BY,KAA1B,CALrB;AAMC,IAAA,OAAO,EAAGD;AANX,KAQGC,KARH,CADD;AAYA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\nimport { PanelRow, Dropdown, Button } from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tPostURLCheck,\n\tPostURL as PostURLForm,\n\tusePostURLLabel,\n} from '@wordpress/editor';\n\nexport default function PostURL() {\n\tconst anchorRef = useRef();\n\treturn (\n\t\t<PostURLCheck>\n\t\t\t<PanelRow className=\"edit-post-post-url\" ref={ anchorRef }>\n\t\t\t\t<span>{ __( 'URL' ) }</span>\n\t\t\t\t<Dropdown\n\t\t\t\t\tpopoverProps={ { anchorRef } }\n\t\t\t\t\tposition=\"bottom left\"\n\t\t\t\t\tclassName=\"edit-post-post-url__dropdown\"\n\t\t\t\t\tcontentClassName=\"edit-post-post-url__dialog\"\n\t\t\t\t\tfocusOnMount\n\t\t\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t\t\t<PostURLToggle isOpen={ isOpen } onClick={ onToggle } />\n\t\t\t\t\t) }\n\t\t\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t\t\t<PostURLForm onClose={ onClose } />\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</PanelRow>\n\t\t</PostURLCheck>\n\t);\n}\n\nfunction PostURLToggle( { isOpen, onClick } ) {\n\tconst label = usePostURLLabel();\n\treturn (\n\t\t<Button\n\t\t\tclassName=\"edit-post-post-url__toggle\"\n\t\t\tvariant=\"tertiary\"\n\t\t\taria-expanded={ isOpen }\n\t\t\t// translators: %s: Current post URL.\n\t\t\taria-label={ sprintf( __( 'Change URL: %s' ), label ) }\n\t\t\tonClick={ onClick }\n\t\t>\n\t\t\t{ label }\n\t\t</Button>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/post-url/index.js"],"names":["useMemo","useState","PanelRow","Dropdown","Button","__","sprintf","PostURLCheck","PostURL","PostURLForm","usePostURLLabel","popoverAnchor","setPopoverAnchor","popoverProps","anchor","isOpen","onToggle","onClose","PostURLToggle","onClick","label"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,OAAT,EAAkBC,QAAlB,QAAkC,oBAAlC;AACA,SAASC,QAAT,EAAmBC,QAAnB,EAA6BC,MAA7B,QAA2C,uBAA3C;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SACCC,YADD,EAECC,OAAO,IAAIC,WAFZ,EAGCC,eAHD,QAIO,mBAJP;AAMA,eAAe,SAASF,OAAT,GAAmB;AACjC;AACA;AACA,QAAM,CAAEG,aAAF,EAAiBC,gBAAjB,IAAsCX,QAAQ,CAAE,IAAF,CAApD,CAHiC,CAIjC;;AACA,QAAMY,YAAY,GAAGb,OAAO,CAC3B,OAAQ;AAAEc,IAAAA,MAAM,EAAEH;AAAV,GAAR,CAD2B,EAE3B,CAAEA,aAAF,CAF2B,CAA5B;AAKA,SACC,cAAC,YAAD,QACC,cAAC,QAAD;AAAU,IAAA,SAAS,EAAC,oBAApB;AAAyC,IAAA,GAAG,EAAGC;AAA/C,KACC,4BAAQP,EAAE,CAAE,KAAF,CAAV,CADD,EAEC,cAAC,QAAD;AACC,IAAA,YAAY,EAAGQ,YADhB;AAEC,IAAA,QAAQ,EAAC,aAFV;AAGC,IAAA,SAAS,EAAC,8BAHX;AAIC,IAAA,gBAAgB,EAAC,4BAJlB;AAKC,IAAA,YAAY,MALb;AAMC,IAAA,YAAY,EAAG;AAAA,UAAE;AAAEE,QAAAA,MAAF;AAAUC,QAAAA;AAAV,OAAF;AAAA,aACd,cAAC,aAAD;AAAe,QAAA,MAAM,EAAGD,MAAxB;AAAiC,QAAA,OAAO,EAAGC;AAA3C,QADc;AAAA,KANhB;AASC,IAAA,aAAa,EAAG;AAAA,UAAE;AAAEC,QAAAA;AAAF,OAAF;AAAA,aACf,cAAC,WAAD;AAAa,QAAA,OAAO,EAAGA;AAAvB,QADe;AAAA;AATjB,IAFD,CADD,CADD;AAoBA;;AAED,SAASC,aAAT,QAA8C;AAAA,MAAtB;AAAEH,IAAAA,MAAF;AAAUI,IAAAA;AAAV,GAAsB;AAC7C,QAAMC,KAAK,GAAGV,eAAe,EAA7B;AACA,SACC,cAAC,MAAD;AACC,IAAA,SAAS,EAAC,4BADX;AAEC,IAAA,OAAO,EAAC,UAFT;AAGC,qBAAgBK,MAHjB,CAIC;AAJD;AAKC,kBAAaT,OAAO,CAAED,EAAE,CAAE,gBAAF,CAAJ,EAA0Be,KAA1B,CALrB;AAMC,IAAA,OAAO,EAAGD;AANX,KAQGC,KARH,CADD;AAYA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useState } from '@wordpress/element';\nimport { PanelRow, Dropdown, Button } from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tPostURLCheck,\n\tPostURL as PostURLForm,\n\tusePostURLLabel,\n} from '@wordpress/editor';\n\nexport default function PostURL() {\n\t// Use internal state instead of a ref to make sure that the component\n\t// re-renders when the popover's anchor updates.\n\tconst [ popoverAnchor, setPopoverAnchor ] = useState( null );\n\t// Memoize popoverProps to avoid returning a new object every time.\n\tconst popoverProps = useMemo(\n\t\t() => ( { anchor: popoverAnchor } ),\n\t\t[ popoverAnchor ]\n\t);\n\n\treturn (\n\t\t<PostURLCheck>\n\t\t\t<PanelRow className=\"edit-post-post-url\" ref={ setPopoverAnchor }>\n\t\t\t\t<span>{ __( 'URL' ) }</span>\n\t\t\t\t<Dropdown\n\t\t\t\t\tpopoverProps={ popoverProps }\n\t\t\t\t\tposition=\"bottom left\"\n\t\t\t\t\tclassName=\"edit-post-post-url__dropdown\"\n\t\t\t\t\tcontentClassName=\"edit-post-post-url__dialog\"\n\t\t\t\t\tfocusOnMount\n\t\t\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t\t\t<PostURLToggle isOpen={ isOpen } onClick={ onToggle } />\n\t\t\t\t\t) }\n\t\t\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t\t\t<PostURLForm onClose={ onClose } />\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</PanelRow>\n\t\t</PostURLCheck>\n\t);\n}\n\nfunction PostURLToggle( { isOpen, onClick } ) {\n\tconst label = usePostURLLabel();\n\treturn (\n\t\t<Button\n\t\t\tclassName=\"edit-post-post-url__toggle\"\n\t\t\tvariant=\"tertiary\"\n\t\t\taria-expanded={ isOpen }\n\t\t\t// translators: %s: Current post URL.\n\t\t\taria-label={ sprintf( __( 'Change URL: %s' ), label ) }\n\t\t\tonClick={ onClick }\n\t\t>\n\t\t\t{ label }\n\t\t</Button>\n\t);\n}\n"]}
@@ -6,26 +6,29 @@ import { createElement } from "@wordpress/element";
6
6
  import { __, sprintf } from '@wordpress/i18n';
7
7
  import { PanelRow, Dropdown, Button } from '@wordpress/components';
8
8
  import { PostVisibility as PostVisibilityForm, PostVisibilityLabel, PostVisibilityCheck, usePostVisibilityLabel } from '@wordpress/editor';
9
- import { useRef } from '@wordpress/element';
9
+ import { useMemo, useState } from '@wordpress/element';
10
10
  export function PostVisibility() {
11
- const rowRef = useRef();
11
+ // Use internal state instead of a ref to make sure that the component
12
+ // re-renders when the popover's anchor updates.
13
+ const [popoverAnchor, setPopoverAnchor] = useState(null); // Memoize popoverProps to avoid returning a new object every time.
14
+
15
+ const popoverProps = useMemo(() => ({
16
+ // Anchor the popover to the middle of the entire row so that it doesn't
17
+ // move around when the label changes.
18
+ anchor: popoverAnchor
19
+ }), [popoverAnchor]);
12
20
  return createElement(PostVisibilityCheck, {
13
21
  render: _ref => {
14
22
  let {
15
23
  canEdit
16
24
  } = _ref;
17
25
  return createElement(PanelRow, {
18
- ref: rowRef,
26
+ ref: setPopoverAnchor,
19
27
  className: "edit-post-post-visibility"
20
28
  }, createElement("span", null, __('Visibility')), !canEdit && createElement("span", null, createElement(PostVisibilityLabel, null)), canEdit && createElement(Dropdown, {
21
29
  position: "bottom left",
22
30
  contentClassName: "edit-post-post-visibility__dialog",
23
- popoverProps: {
24
- // Anchor the popover to the middle of the
25
- // entire row so that it doesn't move around
26
- // when the label changes.
27
- anchorRef: rowRef.current
28
- },
31
+ popoverProps: popoverProps,
29
32
  focusOnMount: true,
30
33
  renderToggle: _ref2 => {
31
34
  let {
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/post-visibility/index.js"],"names":["__","sprintf","PanelRow","Dropdown","Button","PostVisibility","PostVisibilityForm","PostVisibilityLabel","PostVisibilityCheck","usePostVisibilityLabel","useRef","rowRef","canEdit","anchorRef","current","isOpen","onToggle","onClose","PostVisibilityToggle","onClick","label"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,QAAT,EAAmBC,QAAnB,EAA6BC,MAA7B,QAA2C,uBAA3C;AACA,SACCC,cAAc,IAAIC,kBADnB,EAECC,mBAFD,EAGCC,mBAHD,EAICC,sBAJD,QAKO,mBALP;AAMA,SAASC,MAAT,QAAuB,oBAAvB;AAEA,OAAO,SAASL,cAAT,GAA0B;AAChC,QAAMM,MAAM,GAAGD,MAAM,EAArB;AACA,SACC,cAAC,mBAAD;AACC,IAAA,MAAM,EAAG;AAAA,UAAE;AAAEE,QAAAA;AAAF,OAAF;AAAA,aACR,cAAC,QAAD;AAAU,QAAA,GAAG,EAAGD,MAAhB;AAAyB,QAAA,SAAS,EAAC;AAAnC,SACC,4BAAQX,EAAE,CAAE,YAAF,CAAV,CADD,EAEG,CAAEY,OAAF,IACD,4BACC,cAAC,mBAAD,OADD,CAHF,EAOGA,OAAO,IACR,cAAC,QAAD;AACC,QAAA,QAAQ,EAAC,aADV;AAEC,QAAA,gBAAgB,EAAC,mCAFlB;AAGC,QAAA,YAAY,EAAG;AACd;AACA;AACA;AACAC,UAAAA,SAAS,EAAEF,MAAM,CAACG;AAJJ,SAHhB;AASC,QAAA,YAAY,MATb;AAUC,QAAA,YAAY,EAAG;AAAA,cAAE;AAAEC,YAAAA,MAAF;AAAUC,YAAAA;AAAV,WAAF;AAAA,iBACd,cAAC,oBAAD;AACC,YAAA,MAAM,EAAGD,MADV;AAEC,YAAA,OAAO,EAAGC;AAFX,YADc;AAAA,SAVhB;AAgBC,QAAA,aAAa,EAAG;AAAA,cAAE;AAAEC,YAAAA;AAAF,WAAF;AAAA,iBACf,cAAC,kBAAD;AAAoB,YAAA,OAAO,EAAGA;AAA9B,YADe;AAAA;AAhBjB,QARF,CADQ;AAAA;AADV,IADD;AAoCA;;AAED,SAASC,oBAAT,QAAqD;AAAA,MAAtB;AAAEH,IAAAA,MAAF;AAAUI,IAAAA;AAAV,GAAsB;AACpD,QAAMC,KAAK,GAAGX,sBAAsB,EAApC;AACA,SACC,cAAC,MAAD;AACC,IAAA,SAAS,EAAC,mCADX;AAEC,IAAA,OAAO,EAAC,UAFT;AAGC,qBAAgBM,MAHjB,CAIC;AAJD;AAKC,kBAAad,OAAO,CAAED,EAAE,CAAE,uBAAF,CAAJ,EAAiCoB,KAAjC,CALrB;AAMC,IAAA,OAAO,EAAGD;AANX,KAQGC,KARH,CADD;AAYA;;AAED,eAAef,cAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { PanelRow, Dropdown, Button } from '@wordpress/components';\nimport {\n\tPostVisibility as PostVisibilityForm,\n\tPostVisibilityLabel,\n\tPostVisibilityCheck,\n\tusePostVisibilityLabel,\n} from '@wordpress/editor';\nimport { useRef } from '@wordpress/element';\n\nexport function PostVisibility() {\n\tconst rowRef = useRef();\n\treturn (\n\t\t<PostVisibilityCheck\n\t\t\trender={ ( { canEdit } ) => (\n\t\t\t\t<PanelRow ref={ rowRef } className=\"edit-post-post-visibility\">\n\t\t\t\t\t<span>{ __( 'Visibility' ) }</span>\n\t\t\t\t\t{ ! canEdit && (\n\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t<PostVisibilityLabel />\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) }\n\t\t\t\t\t{ canEdit && (\n\t\t\t\t\t\t<Dropdown\n\t\t\t\t\t\t\tposition=\"bottom left\"\n\t\t\t\t\t\t\tcontentClassName=\"edit-post-post-visibility__dialog\"\n\t\t\t\t\t\t\tpopoverProps={ {\n\t\t\t\t\t\t\t\t// Anchor the popover to the middle of the\n\t\t\t\t\t\t\t\t// entire row so that it doesn't move around\n\t\t\t\t\t\t\t\t// when the label changes.\n\t\t\t\t\t\t\t\tanchorRef: rowRef.current,\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tfocusOnMount\n\t\t\t\t\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t\t\t\t\t<PostVisibilityToggle\n\t\t\t\t\t\t\t\t\tisOpen={ isOpen }\n\t\t\t\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t\t\t\t\t<PostVisibilityForm onClose={ onClose } />\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</PanelRow>\n\t\t\t) }\n\t\t/>\n\t);\n}\n\nfunction PostVisibilityToggle( { isOpen, onClick } ) {\n\tconst label = usePostVisibilityLabel();\n\treturn (\n\t\t<Button\n\t\t\tclassName=\"edit-post-post-visibility__toggle\"\n\t\t\tvariant=\"tertiary\"\n\t\t\taria-expanded={ isOpen }\n\t\t\t// translators: %s: Current post visibility.\n\t\t\taria-label={ sprintf( __( 'Select visibility: %s' ), label ) }\n\t\t\tonClick={ onClick }\n\t\t>\n\t\t\t{ label }\n\t\t</Button>\n\t);\n}\n\nexport default PostVisibility;\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/post-visibility/index.js"],"names":["__","sprintf","PanelRow","Dropdown","Button","PostVisibility","PostVisibilityForm","PostVisibilityLabel","PostVisibilityCheck","usePostVisibilityLabel","useMemo","useState","popoverAnchor","setPopoverAnchor","popoverProps","anchor","canEdit","isOpen","onToggle","onClose","PostVisibilityToggle","onClick","label"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,QAAT,EAAmBC,QAAnB,EAA6BC,MAA7B,QAA2C,uBAA3C;AACA,SACCC,cAAc,IAAIC,kBADnB,EAECC,mBAFD,EAGCC,mBAHD,EAICC,sBAJD,QAKO,mBALP;AAMA,SAASC,OAAT,EAAkBC,QAAlB,QAAkC,oBAAlC;AAEA,OAAO,SAASN,cAAT,GAA0B;AAChC;AACA;AACA,QAAM,CAAEO,aAAF,EAAiBC,gBAAjB,IAAsCF,QAAQ,CAAE,IAAF,CAApD,CAHgC,CAIhC;;AACA,QAAMG,YAAY,GAAGJ,OAAO,CAC3B,OAAQ;AACP;AACA;AACAK,IAAAA,MAAM,EAAEH;AAHD,GAAR,CAD2B,EAM3B,CAAEA,aAAF,CAN2B,CAA5B;AASA,SACC,cAAC,mBAAD;AACC,IAAA,MAAM,EAAG;AAAA,UAAE;AAAEI,QAAAA;AAAF,OAAF;AAAA,aACR,cAAC,QAAD;AACC,QAAA,GAAG,EAAGH,gBADP;AAEC,QAAA,SAAS,EAAC;AAFX,SAIC,4BAAQb,EAAE,CAAE,YAAF,CAAV,CAJD,EAKG,CAAEgB,OAAF,IACD,4BACC,cAAC,mBAAD,OADD,CANF,EAUGA,OAAO,IACR,cAAC,QAAD;AACC,QAAA,QAAQ,EAAC,aADV;AAEC,QAAA,gBAAgB,EAAC,mCAFlB;AAGC,QAAA,YAAY,EAAGF,YAHhB;AAIC,QAAA,YAAY,MAJb;AAKC,QAAA,YAAY,EAAG;AAAA,cAAE;AAAEG,YAAAA,MAAF;AAAUC,YAAAA;AAAV,WAAF;AAAA,iBACd,cAAC,oBAAD;AACC,YAAA,MAAM,EAAGD,MADV;AAEC,YAAA,OAAO,EAAGC;AAFX,YADc;AAAA,SALhB;AAWC,QAAA,aAAa,EAAG;AAAA,cAAE;AAAEC,YAAAA;AAAF,WAAF;AAAA,iBACf,cAAC,kBAAD;AAAoB,YAAA,OAAO,EAAGA;AAA9B,YADe;AAAA;AAXjB,QAXF,CADQ;AAAA;AADV,IADD;AAkCA;;AAED,SAASC,oBAAT,QAAqD;AAAA,MAAtB;AAAEH,IAAAA,MAAF;AAAUI,IAAAA;AAAV,GAAsB;AACpD,QAAMC,KAAK,GAAGb,sBAAsB,EAApC;AACA,SACC,cAAC,MAAD;AACC,IAAA,SAAS,EAAC,mCADX;AAEC,IAAA,OAAO,EAAC,UAFT;AAGC,qBAAgBQ,MAHjB,CAIC;AAJD;AAKC,kBAAahB,OAAO,CAAED,EAAE,CAAE,uBAAF,CAAJ,EAAiCsB,KAAjC,CALrB;AAMC,IAAA,OAAO,EAAGD;AANX,KAQGC,KARH,CADD;AAYA;;AAED,eAAejB,cAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { PanelRow, Dropdown, Button } from '@wordpress/components';\nimport {\n\tPostVisibility as PostVisibilityForm,\n\tPostVisibilityLabel,\n\tPostVisibilityCheck,\n\tusePostVisibilityLabel,\n} from '@wordpress/editor';\nimport { useMemo, useState } from '@wordpress/element';\n\nexport function PostVisibility() {\n\t// Use internal state instead of a ref to make sure that the component\n\t// re-renders when the popover's anchor updates.\n\tconst [ popoverAnchor, setPopoverAnchor ] = useState( null );\n\t// Memoize popoverProps to avoid returning a new object every time.\n\tconst popoverProps = useMemo(\n\t\t() => ( {\n\t\t\t// Anchor the popover to the middle of the entire row so that it doesn't\n\t\t\t// move around when the label changes.\n\t\t\tanchor: popoverAnchor,\n\t\t} ),\n\t\t[ popoverAnchor ]\n\t);\n\n\treturn (\n\t\t<PostVisibilityCheck\n\t\t\trender={ ( { canEdit } ) => (\n\t\t\t\t<PanelRow\n\t\t\t\t\tref={ setPopoverAnchor }\n\t\t\t\t\tclassName=\"edit-post-post-visibility\"\n\t\t\t\t>\n\t\t\t\t\t<span>{ __( 'Visibility' ) }</span>\n\t\t\t\t\t{ ! canEdit && (\n\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t<PostVisibilityLabel />\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) }\n\t\t\t\t\t{ canEdit && (\n\t\t\t\t\t\t<Dropdown\n\t\t\t\t\t\t\tposition=\"bottom left\"\n\t\t\t\t\t\t\tcontentClassName=\"edit-post-post-visibility__dialog\"\n\t\t\t\t\t\t\tpopoverProps={ popoverProps }\n\t\t\t\t\t\t\tfocusOnMount\n\t\t\t\t\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t\t\t\t\t<PostVisibilityToggle\n\t\t\t\t\t\t\t\t\tisOpen={ isOpen }\n\t\t\t\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t\t\t\t\t<PostVisibilityForm onClose={ onClose } />\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</PanelRow>\n\t\t\t) }\n\t\t/>\n\t);\n}\n\nfunction PostVisibilityToggle( { isOpen, onClick } ) {\n\tconst label = usePostVisibilityLabel();\n\treturn (\n\t\t<Button\n\t\t\tclassName=\"edit-post-post-visibility__toggle\"\n\t\t\tvariant=\"tertiary\"\n\t\t\taria-expanded={ isOpen }\n\t\t\t// translators: %s: Current post visibility.\n\t\t\taria-label={ sprintf( __( 'Select visibility: %s' ), label ) }\n\t\t\tonClick={ onClick }\n\t\t>\n\t\t\t{ label }\n\t\t</Button>\n\t);\n}\n\nexport default PostVisibility;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/edit-post",
3
- "version": "6.14.0",
3
+ "version": "6.14.1",
4
4
  "description": "Edit Post module for WordPress.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -29,28 +29,28 @@
29
29
  "@babel/runtime": "^7.16.0",
30
30
  "@wordpress/a11y": "^3.17.0",
31
31
  "@wordpress/api-fetch": "^6.14.0",
32
- "@wordpress/block-editor": "^10.0.0",
33
- "@wordpress/block-library": "^7.14.0",
34
- "@wordpress/blocks": "^11.16.0",
35
- "@wordpress/components": "^21.0.0",
36
- "@wordpress/compose": "^5.15.0",
37
- "@wordpress/core-data": "^5.0.0",
38
- "@wordpress/data": "^7.1.0",
32
+ "@wordpress/block-editor": "^10.0.1",
33
+ "@wordpress/block-library": "^7.14.1",
34
+ "@wordpress/blocks": "^11.16.1",
35
+ "@wordpress/components": "^21.0.1",
36
+ "@wordpress/compose": "^5.15.1",
37
+ "@wordpress/core-data": "^5.0.1",
38
+ "@wordpress/data": "^7.1.1",
39
39
  "@wordpress/deprecated": "^3.17.0",
40
- "@wordpress/editor": "^12.16.0",
40
+ "@wordpress/editor": "^12.16.1",
41
41
  "@wordpress/element": "^4.15.0",
42
42
  "@wordpress/hooks": "^3.17.0",
43
43
  "@wordpress/i18n": "^4.17.0",
44
44
  "@wordpress/icons": "^9.8.0",
45
- "@wordpress/interface": "^4.16.0",
46
- "@wordpress/keyboard-shortcuts": "^3.15.0",
45
+ "@wordpress/interface": "^4.16.1",
46
+ "@wordpress/keyboard-shortcuts": "^3.15.1",
47
47
  "@wordpress/keycodes": "^3.17.0",
48
48
  "@wordpress/media-utils": "^4.8.0",
49
- "@wordpress/notices": "^3.17.0",
50
- "@wordpress/plugins": "^4.15.0",
51
- "@wordpress/preferences": "^2.9.0",
49
+ "@wordpress/notices": "^3.17.1",
50
+ "@wordpress/plugins": "^4.15.1",
51
+ "@wordpress/preferences": "^2.9.1",
52
52
  "@wordpress/url": "^3.18.0",
53
- "@wordpress/viewport": "^4.15.0",
53
+ "@wordpress/viewport": "^4.15.1",
54
54
  "@wordpress/warning": "^2.17.0",
55
55
  "classnames": "^2.3.1",
56
56
  "lodash": "^4.17.21",
@@ -64,5 +64,5 @@
64
64
  "publishConfig": {
65
65
  "access": "public"
66
66
  },
67
- "gitHead": "0d732d4b184adcb28cc83087603e81b764390d4b"
67
+ "gitHead": "56ef3f5a754e44155ee79e827c7a1d0efc1ee5aa"
68
68
  }
@@ -3,7 +3,7 @@
3
3
  */
4
4
  import { __, sprintf } from '@wordpress/i18n';
5
5
  import { PanelRow, Dropdown, Button } from '@wordpress/components';
6
- import { useRef } from '@wordpress/element';
6
+ import { useState, useMemo } from '@wordpress/element';
7
7
  import {
8
8
  PostSchedule as PostScheduleForm,
9
9
  PostScheduleCheck,
@@ -11,13 +11,24 @@ import {
11
11
  } from '@wordpress/editor';
12
12
 
13
13
  export default function PostSchedule() {
14
- const anchorRef = useRef();
14
+ // Use internal state instead of a ref to make sure that the component
15
+ // re-renders when the popover's anchor updates.
16
+ const [ popoverAnchor, setPopoverAnchor ] = useState( null );
17
+ // Memoize popoverProps to avoid returning a new object every time.
18
+ const popoverProps = useMemo(
19
+ () => ( { anchor: popoverAnchor } ),
20
+ [ popoverAnchor ]
21
+ );
22
+
15
23
  return (
16
24
  <PostScheduleCheck>
17
- <PanelRow className="edit-post-post-schedule" ref={ anchorRef }>
25
+ <PanelRow
26
+ className="edit-post-post-schedule"
27
+ ref={ setPopoverAnchor }
28
+ >
18
29
  <span>{ __( 'Publish' ) }</span>
19
30
  <Dropdown
20
- popoverProps={ { anchorRef } }
31
+ popoverProps={ popoverProps }
21
32
  position="bottom left"
22
33
  contentClassName="edit-post-post-schedule__dialog"
23
34
  focusOnMount
@@ -15,7 +15,7 @@
15
15
  white-space: normal;
16
16
  height: auto;
17
17
 
18
- // This span is added by the Popover in Tooltip when no anchorRef is
18
+ // This span is added by the Popover in Tooltip when no anchor is
19
19
  // provided. We set its width to 0 so that it does not cause the button text
20
20
  // to wrap to a new line when displaying the tooltip. A better fix would be
21
21
  // to pass anchorRef and avoid the need for a span alltogether, which is
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { useRef } from '@wordpress/element';
4
+ import { useState, useMemo } from '@wordpress/element';
5
5
  import { PanelRow, Dropdown, Button } from '@wordpress/components';
6
6
  import { __, sprintf } from '@wordpress/i18n';
7
7
  import { useSelect } from '@wordpress/data';
@@ -15,7 +15,14 @@ import PostTemplateForm from './form';
15
15
  import { store as editPostStore } from '../../../store';
16
16
 
17
17
  export default function PostTemplate() {
18
- const anchorRef = useRef();
18
+ // Use internal state instead of a ref to make sure that the component
19
+ // re-renders when the popover's anchor updates.
20
+ const [ popoverAnchor, setPopoverAnchor ] = useState( null );
21
+ // Memoize popoverProps to avoid returning a new object every time.
22
+ const popoverProps = useMemo(
23
+ () => ( { anchor: popoverAnchor } ),
24
+ [ popoverAnchor ]
25
+ );
19
26
 
20
27
  const isVisible = useSelect( ( select ) => {
21
28
  const postTypeSlug = select( editorStore ).getCurrentPostType();
@@ -46,10 +53,10 @@ export default function PostTemplate() {
46
53
  }
47
54
 
48
55
  return (
49
- <PanelRow className="edit-post-post-template" ref={ anchorRef }>
56
+ <PanelRow className="edit-post-post-template" ref={ setPopoverAnchor }>
50
57
  <span>{ __( 'Template' ) }</span>
51
58
  <Dropdown
52
- popoverProps={ { anchorRef } }
59
+ popoverProps={ popoverProps }
53
60
  position="bottom left"
54
61
  className="edit-post-post-template__dropdown"
55
62
  contentClassName="edit-post-post-template__dialog"
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { useRef } from '@wordpress/element';
4
+ import { useMemo, useState } from '@wordpress/element';
5
5
  import { PanelRow, Dropdown, Button } from '@wordpress/components';
6
6
  import { __, sprintf } from '@wordpress/i18n';
7
7
  import {
@@ -11,13 +11,21 @@ import {
11
11
  } from '@wordpress/editor';
12
12
 
13
13
  export default function PostURL() {
14
- const anchorRef = useRef();
14
+ // Use internal state instead of a ref to make sure that the component
15
+ // re-renders when the popover's anchor updates.
16
+ const [ popoverAnchor, setPopoverAnchor ] = useState( null );
17
+ // Memoize popoverProps to avoid returning a new object every time.
18
+ const popoverProps = useMemo(
19
+ () => ( { anchor: popoverAnchor } ),
20
+ [ popoverAnchor ]
21
+ );
22
+
15
23
  return (
16
24
  <PostURLCheck>
17
- <PanelRow className="edit-post-post-url" ref={ anchorRef }>
25
+ <PanelRow className="edit-post-post-url" ref={ setPopoverAnchor }>
18
26
  <span>{ __( 'URL' ) }</span>
19
27
  <Dropdown
20
- popoverProps={ { anchorRef } }
28
+ popoverProps={ popoverProps }
21
29
  position="bottom left"
22
30
  className="edit-post-post-url__dropdown"
23
31
  contentClassName="edit-post-post-url__dialog"
@@ -9,14 +9,29 @@ import {
9
9
  PostVisibilityCheck,
10
10
  usePostVisibilityLabel,
11
11
  } from '@wordpress/editor';
12
- import { useRef } from '@wordpress/element';
12
+ import { useMemo, useState } from '@wordpress/element';
13
13
 
14
14
  export function PostVisibility() {
15
- const rowRef = useRef();
15
+ // Use internal state instead of a ref to make sure that the component
16
+ // re-renders when the popover's anchor updates.
17
+ const [ popoverAnchor, setPopoverAnchor ] = useState( null );
18
+ // Memoize popoverProps to avoid returning a new object every time.
19
+ const popoverProps = useMemo(
20
+ () => ( {
21
+ // Anchor the popover to the middle of the entire row so that it doesn't
22
+ // move around when the label changes.
23
+ anchor: popoverAnchor,
24
+ } ),
25
+ [ popoverAnchor ]
26
+ );
27
+
16
28
  return (
17
29
  <PostVisibilityCheck
18
30
  render={ ( { canEdit } ) => (
19
- <PanelRow ref={ rowRef } className="edit-post-post-visibility">
31
+ <PanelRow
32
+ ref={ setPopoverAnchor }
33
+ className="edit-post-post-visibility"
34
+ >
20
35
  <span>{ __( 'Visibility' ) }</span>
21
36
  { ! canEdit && (
22
37
  <span>
@@ -27,12 +42,7 @@ export function PostVisibility() {
27
42
  <Dropdown
28
43
  position="bottom left"
29
44
  contentClassName="edit-post-post-visibility__dialog"
30
- popoverProps={ {
31
- // Anchor the popover to the middle of the
32
- // entire row so that it doesn't move around
33
- // when the label changes.
34
- anchorRef: rowRef.current,
35
- } }
45
+ popoverProps={ popoverProps }
36
46
  focusOnMount
37
47
  renderToggle={ ( { isOpen, onToggle } ) => (
38
48
  <PostVisibilityToggle