@wordpress/core-commands 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.4.0 (2023-06-07)
6
+
5
7
  ## 0.3.0 (2023-05-24)
6
8
 
7
9
  ## 0.2.0 (2023-05-10)
@@ -40,10 +40,9 @@ const icons = {
40
40
  wp_template_part: _icons.symbolFilled
41
41
  };
42
42
 
43
- const getNavigationCommandLoaderPerPostType = postType => function useNavigationCommandLoader(_ref) {
44
- let {
45
- search
46
- } = _ref;
43
+ const getNavigationCommandLoaderPerPostType = postType => function useNavigationCommandLoader({
44
+ search
45
+ }) {
47
46
  const history = useHistory();
48
47
  const supportsSearch = !['wp_template', 'wp_template_part'].includes(postType);
49
48
  const {
@@ -71,21 +70,18 @@ const getNavigationCommandLoaderPerPostType = postType => function useNavigation
71
70
  }, [supportsSearch, search]);
72
71
  const commands = (0, _element.useMemo)(() => {
73
72
  return (records !== null && records !== void 0 ? records : []).slice(0, 10).map(record => {
74
- var _getPath, _record$title, _record$title2, _record$title3;
75
-
76
- const isSiteEditor = (_getPath = (0, _url.getPath)(window.location.href)) === null || _getPath === void 0 ? void 0 : _getPath.includes('site-editor.php');
73
+ const isSiteEditor = (0, _url.getPath)(window.location.href)?.includes('site-editor.php');
77
74
  const extraArgs = isSiteEditor ? {
78
75
  canvas: (0, _url.getQueryArg)(window.location.href, 'canvas')
79
76
  } : {};
80
77
  return {
81
78
  name: postType + '-' + record.id,
82
- searchLabel: ((_record$title = record.title) === null || _record$title === void 0 ? void 0 : _record$title.rendered) + ' ' + record.id,
83
- label: (_record$title2 = record.title) !== null && _record$title2 !== void 0 && _record$title2.rendered ? (_record$title3 = record.title) === null || _record$title3 === void 0 ? void 0 : _record$title3.rendered : (0, _i18n.__)('(no title)'),
79
+ searchLabel: record.title?.rendered + ' ' + record.id,
80
+ label: record.title?.rendered ? record.title?.rendered : (0, _i18n.__)('(no title)'),
84
81
  icon: icons[postType],
85
- callback: _ref2 => {
86
- let {
87
- close
88
- } = _ref2;
82
+ callback: ({
83
+ close
84
+ }) => {
89
85
  const args = {
90
86
  postType,
91
87
  postId: record.id,
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-commands/src/site-editor-navigation-commands.js"],"names":["useHistory","routerPrivateApis","icons","post","page","wp_template","layout","wp_template_part","symbolFilled","getNavigationCommandLoaderPerPostType","postType","useNavigationCommandLoader","search","history","supportsSearch","includes","records","isLoading","select","getEntityRecords","coreStore","query","undefined","per_page","orderby","hasFinishedResolution","isSiteEditor","commands","slice","map","record","window","location","href","extraArgs","canvas","name","id","searchLabel","title","rendered","label","icon","callback","close","args","postId","targetUrl","push","document","usePageNavigationCommandLoader","usePostNavigationCommandLoader","useTemplateNavigationCommandLoader","useTemplatePartNavigationCommandLoader","useSiteEditorNavigationCommands","hook"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AAfA;AACA;AACA;;AAUA;AACA;AACA;AAGA,MAAM;AAAEA,EAAAA;AAAF,IAAiB,wBAAQC,mBAAR,CAAvB;AAEA,MAAMC,KAAK,GAAG;AACbC,EAAAA,IAAI,EAAJA,WADa;AAEbC,EAAAA,IAAI,EAAJA,WAFa;AAGbC,EAAAA,WAAW,EAAEC,aAHA;AAIbC,EAAAA,gBAAgB,EAAEC;AAJL,CAAd;;AAOA,MAAMC,qCAAqC,GAAKC,QAAF,IAC7C,SAASC,0BAAT,OAAkD;AAAA,MAAb;AAAEC,IAAAA;AAAF,GAAa;AACjD,QAAMC,OAAO,GAAGb,UAAU,EAA1B;AACA,QAAMc,cAAc,GAAG,CAAE,CAAE,aAAF,EAAiB,kBAAjB,EAAsCC,QAAtC,CACxBL,QADwB,CAAzB;AAGA,QAAM;AAAEM,IAAAA,OAAF;AAAWC,IAAAA;AAAX,MA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;AACjBlB,IAAAA,IAAI,EAAE,+BADW;AAEjBmB,IAAAA,IAAI,EAAEL;AAFW,GAAlB;AAIA,kCAAkB;AACjBd,IAAAA,IAAI,EAAE,+BADW;AAEjBmB,IAAAA,IAAI,EAAEJ;AAFW,GAAlB;AAIA,kCAAkB;AACjBf,IAAAA,IAAI,EAAE,mCADW;AAEjBmB,IAAAA,IAAI,EAAEH;AAFW,GAAlB;AAIA,kCAAkB;AACjBhB,IAAAA,IAAI,EAAE,wCADW;AAEjBmB,IAAAA,IAAI,EAAEF;AAFW,GAAlB;AAIA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCommandLoader } from '@wordpress/commands';\nimport { __ } from '@wordpress/i18n';\nimport { useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { post, page, layout, symbolFilled } from '@wordpress/icons';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { getQueryArg, addQueryArgs, getPath } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from './lock-unlock';\n\nconst { useHistory } = unlock( routerPrivateApis );\n\nconst icons = {\n\tpost,\n\tpage,\n\twp_template: layout,\n\twp_template_part: symbolFilled,\n};\n\nconst getNavigationCommandLoaderPerPostType = ( postType ) =>\n\tfunction useNavigationCommandLoader( { search } ) {\n\t\tconst history = useHistory();\n\t\tconst supportsSearch = ! [ 'wp_template', 'wp_template_part' ].includes(\n\t\t\tpostType\n\t\t);\n\t\tconst { records, isLoading } = useSelect(\n\t\t\t( select ) => {\n\t\t\t\tconst { getEntityRecords } = select( coreStore );\n\t\t\t\tconst query = supportsSearch\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tsearch: !! search ? search : undefined,\n\t\t\t\t\t\t\tper_page: 10,\n\t\t\t\t\t\t\torderby: search ? 'relevance' : 'date',\n\t\t\t\t\t }\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tper_page: -1,\n\t\t\t\t\t };\n\t\t\t\treturn {\n\t\t\t\t\trecords: getEntityRecords( 'postType', postType, query ),\n\t\t\t\t\tisLoading: ! select( coreStore ).hasFinishedResolution(\n\t\t\t\t\t\t'getEntityRecords',\n\t\t\t\t\t\t[ 'postType', postType, query ]\n\t\t\t\t\t),\n\t\t\t\t\t// We're using the string literal to check whether we're in the site editor.\n\t\t\t\t\t/* eslint-disable-next-line @wordpress/data-no-store-string-literals */\n\t\t\t\t\tisSiteEditor: !! select( 'edit-site' ),\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ supportsSearch, search ]\n\t\t);\n\n\t\tconst commands = useMemo( () => {\n\t\t\treturn ( records ?? [] ).slice( 0, 10 ).map( ( record ) => {\n\t\t\t\tconst isSiteEditor = getPath( window.location.href )?.includes(\n\t\t\t\t\t'site-editor.php'\n\t\t\t\t);\n\t\t\t\tconst extraArgs = isSiteEditor\n\t\t\t\t\t? { canvas: getQueryArg( window.location.href, 'canvas' ) }\n\t\t\t\t\t: {};\n\t\t\t\treturn {\n\t\t\t\t\tname: postType + '-' + record.id,\n\t\t\t\t\tsearchLabel: record.title?.rendered + ' ' + record.id,\n\t\t\t\t\tlabel: record.title?.rendered\n\t\t\t\t\t\t? record.title?.rendered\n\t\t\t\t\t\t: __( '(no title)' ),\n\t\t\t\t\ticon: icons[ postType ],\n\t\t\t\t\tcallback: ( { close } ) => {\n\t\t\t\t\t\tconst args = {\n\t\t\t\t\t\t\tpostType,\n\t\t\t\t\t\t\tpostId: record.id,\n\t\t\t\t\t\t\t...extraArgs,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst targetUrl = addQueryArgs(\n\t\t\t\t\t\t\t'site-editor.php',\n\t\t\t\t\t\t\targs\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\t\t\thistory.push( args );\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tclose();\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} );\n\t\t}, [ records, history ] );\n\n\t\treturn {\n\t\t\tcommands,\n\t\t\tisLoading,\n\t\t};\n\t};\n\nconst usePageNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'page' );\nconst usePostNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'post' );\nconst useTemplateNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'wp_template' );\nconst useTemplatePartNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'wp_template_part' );\n\nexport function useSiteEditorNavigationCommands() {\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-pages',\n\t\thook: usePageNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-posts',\n\t\thook: usePostNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-templates',\n\t\thook: useTemplateNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-template-parts',\n\t\thook: useTemplatePartNavigationCommandLoader,\n\t} );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/core-commands/src/site-editor-navigation-commands.js"],"names":["useHistory","routerPrivateApis","icons","post","page","wp_template","layout","wp_template_part","symbolFilled","getNavigationCommandLoaderPerPostType","postType","useNavigationCommandLoader","search","history","supportsSearch","includes","records","isLoading","select","getEntityRecords","coreStore","query","undefined","per_page","orderby","hasFinishedResolution","isSiteEditor","commands","slice","map","record","window","location","href","extraArgs","canvas","name","id","searchLabel","title","rendered","label","icon","callback","close","args","postId","targetUrl","push","document","usePageNavigationCommandLoader","usePostNavigationCommandLoader","useTemplateNavigationCommandLoader","useTemplatePartNavigationCommandLoader","useSiteEditorNavigationCommands","hook"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AAfA;AACA;AACA;;AAUA;AACA;AACA;AAGA,MAAM;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ACL;AAvBK,OAAP;AAyBA,KAhCM,CAAP;AAiCA,GAlCgB,EAkCd,CAAE5B,OAAF,EAAWH,OAAX,CAlCc,CAAjB;AAoCA,SAAO;AACNc,IAAAA,QADM;AAENV,IAAAA;AAFM,GAAP;AAIA,CAxEF;;AA0EA,MAAMiC,8BAA8B,GACnCzC,qCAAqC,CAAE,MAAF,CADtC;AAEA,MAAM0C,8BAA8B,GACnC1C,qCAAqC,CAAE,MAAF,CADtC;AAEA,MAAM2C,kCAAkC,GACvC3C,qCAAqC,CAAE,aAAF,CADtC;AAEA,MAAM4C,sCAAsC,GAC3C5C,qCAAqC,CAAE,kBAAF,CADtC;;AAGO,SAAS6C,+BAAT,GAA2C;AACjD,kCAAkB;AACjBlB,IAAAA,IAAI,EAAE,+BADW;AAEjBmB,IAAAA,IAAI,EAAEL;AAFW,GAAlB;AAIA,kCAAkB;AACjBd,IAAAA,IAAI,EAAE,+BADW;AAEjBmB,IAAAA,IAAI,EAAEJ;AAFW,GAAlB;AAIA,kCAAkB;AACjBf,IAAAA,IAAI,EAAE,mCADW;AAEjBmB,IAAAA,IAAI,EAAEH;AAFW,GAAlB;AAIA,kCAAkB;AACjBhB,IAAAA,IAAI,EAAE,wCADW;AAEjBmB,IAAAA,IAAI,EAAEF;AAFW,GAAlB;AAIA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCommandLoader } from '@wordpress/commands';\nimport { __ } from '@wordpress/i18n';\nimport { useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { post, page, layout, symbolFilled } from '@wordpress/icons';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { getQueryArg, addQueryArgs, getPath } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from './lock-unlock';\n\nconst { useHistory } = unlock( routerPrivateApis );\n\nconst icons = {\n\tpost,\n\tpage,\n\twp_template: layout,\n\twp_template_part: symbolFilled,\n};\n\nconst getNavigationCommandLoaderPerPostType = ( postType ) =>\n\tfunction useNavigationCommandLoader( { search } ) {\n\t\tconst history = useHistory();\n\t\tconst supportsSearch = ! [ 'wp_template', 'wp_template_part' ].includes(\n\t\t\tpostType\n\t\t);\n\t\tconst { records, isLoading } = useSelect(\n\t\t\t( select ) => {\n\t\t\t\tconst { getEntityRecords } = select( coreStore );\n\t\t\t\tconst query = supportsSearch\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tsearch: !! search ? search : undefined,\n\t\t\t\t\t\t\tper_page: 10,\n\t\t\t\t\t\t\torderby: search ? 'relevance' : 'date',\n\t\t\t\t\t }\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tper_page: -1,\n\t\t\t\t\t };\n\t\t\t\treturn {\n\t\t\t\t\trecords: getEntityRecords( 'postType', postType, query ),\n\t\t\t\t\tisLoading: ! select( coreStore ).hasFinishedResolution(\n\t\t\t\t\t\t'getEntityRecords',\n\t\t\t\t\t\t[ 'postType', postType, query ]\n\t\t\t\t\t),\n\t\t\t\t\t// We're using the string literal to check whether we're in the site editor.\n\t\t\t\t\t/* eslint-disable-next-line @wordpress/data-no-store-string-literals */\n\t\t\t\t\tisSiteEditor: !! select( 'edit-site' ),\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ supportsSearch, search ]\n\t\t);\n\n\t\tconst commands = useMemo( () => {\n\t\t\treturn ( records ?? [] ).slice( 0, 10 ).map( ( record ) => {\n\t\t\t\tconst isSiteEditor = getPath( window.location.href )?.includes(\n\t\t\t\t\t'site-editor.php'\n\t\t\t\t);\n\t\t\t\tconst extraArgs = isSiteEditor\n\t\t\t\t\t? { canvas: getQueryArg( window.location.href, 'canvas' ) }\n\t\t\t\t\t: {};\n\t\t\t\treturn {\n\t\t\t\t\tname: postType + '-' + record.id,\n\t\t\t\t\tsearchLabel: record.title?.rendered + ' ' + record.id,\n\t\t\t\t\tlabel: record.title?.rendered\n\t\t\t\t\t\t? record.title?.rendered\n\t\t\t\t\t\t: __( '(no title)' ),\n\t\t\t\t\ticon: icons[ postType ],\n\t\t\t\t\tcallback: ( { close } ) => {\n\t\t\t\t\t\tconst args = {\n\t\t\t\t\t\t\tpostType,\n\t\t\t\t\t\t\tpostId: record.id,\n\t\t\t\t\t\t\t...extraArgs,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst targetUrl = addQueryArgs(\n\t\t\t\t\t\t\t'site-editor.php',\n\t\t\t\t\t\t\targs\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\t\t\thistory.push( args );\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tclose();\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} );\n\t\t}, [ records, history ] );\n\n\t\treturn {\n\t\t\tcommands,\n\t\t\tisLoading,\n\t\t};\n\t};\n\nconst usePageNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'page' );\nconst usePostNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'post' );\nconst useTemplateNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'wp_template' );\nconst useTemplatePartNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'wp_template_part' );\n\nexport function useSiteEditorNavigationCommands() {\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-pages',\n\t\thook: usePageNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-posts',\n\t\thook: usePostNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-templates',\n\t\thook: useTemplateNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-template-parts',\n\t\thook: useTemplatePartNavigationCommandLoader,\n\t} );\n}\n"]}
@@ -24,10 +24,9 @@ const icons = {
24
24
  wp_template_part: symbolFilled
25
25
  };
26
26
 
27
- const getNavigationCommandLoaderPerPostType = postType => function useNavigationCommandLoader(_ref) {
28
- let {
29
- search
30
- } = _ref;
27
+ const getNavigationCommandLoaderPerPostType = postType => function useNavigationCommandLoader({
28
+ search
29
+ }) {
31
30
  const history = useHistory();
32
31
  const supportsSearch = !['wp_template', 'wp_template_part'].includes(postType);
33
32
  const {
@@ -55,21 +54,18 @@ const getNavigationCommandLoaderPerPostType = postType => function useNavigation
55
54
  }, [supportsSearch, search]);
56
55
  const commands = useMemo(() => {
57
56
  return (records !== null && records !== void 0 ? records : []).slice(0, 10).map(record => {
58
- var _getPath, _record$title, _record$title2, _record$title3;
59
-
60
- const isSiteEditor = (_getPath = getPath(window.location.href)) === null || _getPath === void 0 ? void 0 : _getPath.includes('site-editor.php');
57
+ const isSiteEditor = getPath(window.location.href)?.includes('site-editor.php');
61
58
  const extraArgs = isSiteEditor ? {
62
59
  canvas: getQueryArg(window.location.href, 'canvas')
63
60
  } : {};
64
61
  return {
65
62
  name: postType + '-' + record.id,
66
- searchLabel: ((_record$title = record.title) === null || _record$title === void 0 ? void 0 : _record$title.rendered) + ' ' + record.id,
67
- label: (_record$title2 = record.title) !== null && _record$title2 !== void 0 && _record$title2.rendered ? (_record$title3 = record.title) === null || _record$title3 === void 0 ? void 0 : _record$title3.rendered : __('(no title)'),
63
+ searchLabel: record.title?.rendered + ' ' + record.id,
64
+ label: record.title?.rendered ? record.title?.rendered : __('(no title)'),
68
65
  icon: icons[postType],
69
- callback: _ref2 => {
70
- let {
71
- close
72
- } = _ref2;
66
+ callback: ({
67
+ close
68
+ }) => {
73
69
  const args = {
74
70
  postType,
75
71
  postId: record.id,
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-commands/src/site-editor-navigation-commands.js"],"names":["useCommandLoader","__","useMemo","useSelect","store","coreStore","post","page","layout","symbolFilled","privateApis","routerPrivateApis","getQueryArg","addQueryArgs","getPath","unlock","useHistory","icons","wp_template","wp_template_part","getNavigationCommandLoaderPerPostType","postType","useNavigationCommandLoader","search","history","supportsSearch","includes","records","isLoading","select","getEntityRecords","query","undefined","per_page","orderby","hasFinishedResolution","isSiteEditor","commands","slice","map","record","window","location","href","extraArgs","canvas","name","id","searchLabel","title","rendered","label","icon","callback","close","args","postId","targetUrl","push","document","usePageNavigationCommandLoader","usePostNavigationCommandLoader","useTemplateNavigationCommandLoader","useTemplatePartNavigationCommandLoader","useSiteEditorNavigationCommands","hook"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gBAAT,QAAiC,qBAAjC;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,OAAT,QAAwB,oBAAxB;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AACA,SAASC,IAAT,EAAeC,IAAf,EAAqBC,MAArB,EAA6BC,YAA7B,QAAiD,kBAAjD;AACA,SAASC,WAAW,IAAIC,iBAAxB,QAAiD,mBAAjD;AACA,SAASC,WAAT,EAAsBC,YAAtB,EAAoCC,OAApC,QAAmD,gBAAnD;AAEA;AACA;AACA;;AACA,SAASC,MAAT,QAAuB,eAAvB;AAEA,MAAM;AAAEC,EAAAA;AAAF,IAAiBD,MAAM,CAAEJ,iBAAF,CAA7B;AAEA,MAAMM,KAAK,GAAG;AACbX,EAAAA,IADa;AAEbC,EAAAA,IAFa;AAGbW,EAAAA,WAAW,EAAEV,MAHA;AAIbW,EAAAA,gBAAgB,EAAEV;AAJL,CAAd;;AAOA,MAAMW,qCAAqC,GAAKC,QAAF,IAC7C,SAASC,0BAAT,OAAkD;AAAA,MAAb;AAAEC,IAAAA;AAAF,GAAa;AACjD,QAAMC,OAAO,GAAGR,UAAU,EAA1B;AACA,QAAMS,cAAc,GAAG,CAAE,CAAE,aAAF,EAAiB,kBAAjB,EAAsCC,QAAtC,CACxBL,QADwB,CAAzB;AAGA,QAAM;AAAEM,IAAAA,OAAF;AAAWC,IAAAA;AAAX,MAAyBzB,SAAS,CACrC0B,MAAF,IAAc;AAC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AAT,GAA2C;AACjDhE,EAAAA,gBAAgB,CAAE;AACjB8C,IAAAA,IAAI,EAAE,+BADW;AAEjBmB,IAAAA,IAAI,EAAEL;AAFW,GAAF,CAAhB;AAIA5D,EAAAA,gBAAgB,CAAE;AACjB8C,IAAAA,IAAI,EAAE,+BADW;AAEjBmB,IAAAA,IAAI,EAAEJ;AAFW,GAAF,CAAhB;AAIA7D,EAAAA,gBAAgB,CAAE;AACjB8C,IAAAA,IAAI,EAAE,mCADW;AAEjBmB,IAAAA,IAAI,EAAEH;AAFW,GAAF,CAAhB;AAIA9D,EAAAA,gBAAgB,CAAE;AACjB8C,IAAAA,IAAI,EAAE,wCADW;AAEjBmB,IAAAA,IAAI,EAAEF;AAFW,GAAF,CAAhB;AAIA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCommandLoader } from '@wordpress/commands';\nimport { __ } from '@wordpress/i18n';\nimport { useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { post, page, layout, symbolFilled } from '@wordpress/icons';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { getQueryArg, addQueryArgs, getPath } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from './lock-unlock';\n\nconst { useHistory } = unlock( routerPrivateApis );\n\nconst icons = {\n\tpost,\n\tpage,\n\twp_template: layout,\n\twp_template_part: symbolFilled,\n};\n\nconst getNavigationCommandLoaderPerPostType = ( postType ) =>\n\tfunction useNavigationCommandLoader( { search } ) {\n\t\tconst history = useHistory();\n\t\tconst supportsSearch = ! [ 'wp_template', 'wp_template_part' ].includes(\n\t\t\tpostType\n\t\t);\n\t\tconst { records, isLoading } = useSelect(\n\t\t\t( select ) => {\n\t\t\t\tconst { getEntityRecords } = select( coreStore );\n\t\t\t\tconst query = supportsSearch\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tsearch: !! search ? search : undefined,\n\t\t\t\t\t\t\tper_page: 10,\n\t\t\t\t\t\t\torderby: search ? 'relevance' : 'date',\n\t\t\t\t\t }\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tper_page: -1,\n\t\t\t\t\t };\n\t\t\t\treturn {\n\t\t\t\t\trecords: getEntityRecords( 'postType', postType, query ),\n\t\t\t\t\tisLoading: ! select( coreStore ).hasFinishedResolution(\n\t\t\t\t\t\t'getEntityRecords',\n\t\t\t\t\t\t[ 'postType', postType, query ]\n\t\t\t\t\t),\n\t\t\t\t\t// We're using the string literal to check whether we're in the site editor.\n\t\t\t\t\t/* eslint-disable-next-line @wordpress/data-no-store-string-literals */\n\t\t\t\t\tisSiteEditor: !! select( 'edit-site' ),\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ supportsSearch, search ]\n\t\t);\n\n\t\tconst commands = useMemo( () => {\n\t\t\treturn ( records ?? [] ).slice( 0, 10 ).map( ( record ) => {\n\t\t\t\tconst isSiteEditor = getPath( window.location.href )?.includes(\n\t\t\t\t\t'site-editor.php'\n\t\t\t\t);\n\t\t\t\tconst extraArgs = isSiteEditor\n\t\t\t\t\t? { canvas: getQueryArg( window.location.href, 'canvas' ) }\n\t\t\t\t\t: {};\n\t\t\t\treturn {\n\t\t\t\t\tname: postType + '-' + record.id,\n\t\t\t\t\tsearchLabel: record.title?.rendered + ' ' + record.id,\n\t\t\t\t\tlabel: record.title?.rendered\n\t\t\t\t\t\t? record.title?.rendered\n\t\t\t\t\t\t: __( '(no title)' ),\n\t\t\t\t\ticon: icons[ postType ],\n\t\t\t\t\tcallback: ( { close } ) => {\n\t\t\t\t\t\tconst args = {\n\t\t\t\t\t\t\tpostType,\n\t\t\t\t\t\t\tpostId: record.id,\n\t\t\t\t\t\t\t...extraArgs,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst targetUrl = addQueryArgs(\n\t\t\t\t\t\t\t'site-editor.php',\n\t\t\t\t\t\t\targs\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\t\t\thistory.push( args );\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tclose();\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} );\n\t\t}, [ records, history ] );\n\n\t\treturn {\n\t\t\tcommands,\n\t\t\tisLoading,\n\t\t};\n\t};\n\nconst usePageNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'page' );\nconst usePostNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'post' );\nconst useTemplateNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'wp_template' );\nconst useTemplatePartNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'wp_template_part' );\n\nexport function useSiteEditorNavigationCommands() {\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-pages',\n\t\thook: usePageNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-posts',\n\t\thook: usePostNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-templates',\n\t\thook: useTemplateNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-template-parts',\n\t\thook: useTemplatePartNavigationCommandLoader,\n\t} );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/core-commands/src/site-editor-navigation-commands.js"],"names":["useCommandLoader","__","useMemo","useSelect","store","coreStore","post","page","layout","symbolFilled","privateApis","routerPrivateApis","getQueryArg","addQueryArgs","getPath","unlock","useHistory","icons","wp_template","wp_template_part","getNavigationCommandLoaderPerPostType","postType","useNavigationCommandLoader","search","history","supportsSearch","includes","records","isLoading","select","getEntityRecords","query","undefined","per_page","orderby","hasFinishedResolution","isSiteEditor","commands","slice","map","record","window","location","href","extraArgs","canvas","name","id","searchLabel","title","rendered","label","icon","callback","close","args","postId","targetUrl","push","document","usePageNavigationCommandLoader","usePostNavigationCommandLoader","useTemplateNavigationCommandLoader","useTemplatePartNavigationCommandLoader","useSiteEditorNavigationCommands","hook"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gBAAT,QAAiC,qBAAjC;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,OAAT,QAAwB,oBAAxB;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AACA,SAASC,IAAT,EAAeC,IAAf,EAAqBC,MAArB,EAA6BC,YAA7B,QAAiD,kBAAjD;AACA,SAASC,WAAW,IAAIC,iBAAxB,QAAiD,mBAAjD;AACA,SAASC,WAAT,EAAsBC,YAAtB,EAAoCC,OAApC,QAAmD,gBAAnD;AAEA;AACA;AACA;;AACA,SAASC,MAAT,QAAuB,eAAvB;AAEA,MAAM;AAAEC,EAAAA;AAAF,IAAiBD,MAAM,CAAEJ,iBAAF,CAA7B;AAEA,MAAMM,KAAK,GAAG;AACbX,EAAAA,IADa;AAEbC,EAAAA,IAFa;AAGbW,EAAAA,WAAW,EAAEV,MAHA;AAIbW,EAAAA,gBAAgB,EAAEV;AAJL,CAAd;;AAOA,MAAMW,qCAAqC,GAAKC,QAAF,IAC7C,SAASC,0BAAT,CAAqC;AAAEC,EAAAA;AAAF,CAArC,EAAkD;AACjD,QAAMC,OAAO,GAAGR,UAAU,EAA1B;AACA,QAAMS,cAAc,GAAG,CAAE,CAAE,aAAF,EAAiB,kBAAjB,EAAsCC,QAAtC,CACxBL,QADwB,CAAzB;AAGA,QAAM;AAAEM,IAAAA,OAAF;AAAWC,IAAAA;AAAX,MAAyBzB,SAAS,CACrC0B,MAAF,IAAc;AACb,UAAM;AAAEC,MAAAA;AAAF,QAAuBD,MAAM,CAAExB,SAAF,CAAnC;AACA,UAAM0B,KAAK,GAAGN,cAAc,GACzB;AACAF,MAAAA,MAAM,EAAE,CAAC,CAAEA,MAAH,GAAYA,MAAZ,GAAqBS,SAD7B;AAEAC,MAAAA,QAAQ,EAAE,E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AA,gBAAgB,CAAE;AACjB8C,IAAAA,IAAI,EAAE,mCADW;AAEjBmB,IAAAA,IAAI,EAAEH;AAFW,GAAF,CAAhB;AAIA9D,EAAAA,gBAAgB,CAAE;AACjB8C,IAAAA,IAAI,EAAE,wCADW;AAEjBmB,IAAAA,IAAI,EAAEF;AAFW,GAAF,CAAhB;AAIA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCommandLoader } from '@wordpress/commands';\nimport { __ } from '@wordpress/i18n';\nimport { useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { post, page, layout, symbolFilled } from '@wordpress/icons';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { getQueryArg, addQueryArgs, getPath } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from './lock-unlock';\n\nconst { useHistory } = unlock( routerPrivateApis );\n\nconst icons = {\n\tpost,\n\tpage,\n\twp_template: layout,\n\twp_template_part: symbolFilled,\n};\n\nconst getNavigationCommandLoaderPerPostType = ( postType ) =>\n\tfunction useNavigationCommandLoader( { search } ) {\n\t\tconst history = useHistory();\n\t\tconst supportsSearch = ! [ 'wp_template', 'wp_template_part' ].includes(\n\t\t\tpostType\n\t\t);\n\t\tconst { records, isLoading } = useSelect(\n\t\t\t( select ) => {\n\t\t\t\tconst { getEntityRecords } = select( coreStore );\n\t\t\t\tconst query = supportsSearch\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tsearch: !! search ? search : undefined,\n\t\t\t\t\t\t\tper_page: 10,\n\t\t\t\t\t\t\torderby: search ? 'relevance' : 'date',\n\t\t\t\t\t }\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tper_page: -1,\n\t\t\t\t\t };\n\t\t\t\treturn {\n\t\t\t\t\trecords: getEntityRecords( 'postType', postType, query ),\n\t\t\t\t\tisLoading: ! select( coreStore ).hasFinishedResolution(\n\t\t\t\t\t\t'getEntityRecords',\n\t\t\t\t\t\t[ 'postType', postType, query ]\n\t\t\t\t\t),\n\t\t\t\t\t// We're using the string literal to check whether we're in the site editor.\n\t\t\t\t\t/* eslint-disable-next-line @wordpress/data-no-store-string-literals */\n\t\t\t\t\tisSiteEditor: !! select( 'edit-site' ),\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ supportsSearch, search ]\n\t\t);\n\n\t\tconst commands = useMemo( () => {\n\t\t\treturn ( records ?? [] ).slice( 0, 10 ).map( ( record ) => {\n\t\t\t\tconst isSiteEditor = getPath( window.location.href )?.includes(\n\t\t\t\t\t'site-editor.php'\n\t\t\t\t);\n\t\t\t\tconst extraArgs = isSiteEditor\n\t\t\t\t\t? { canvas: getQueryArg( window.location.href, 'canvas' ) }\n\t\t\t\t\t: {};\n\t\t\t\treturn {\n\t\t\t\t\tname: postType + '-' + record.id,\n\t\t\t\t\tsearchLabel: record.title?.rendered + ' ' + record.id,\n\t\t\t\t\tlabel: record.title?.rendered\n\t\t\t\t\t\t? record.title?.rendered\n\t\t\t\t\t\t: __( '(no title)' ),\n\t\t\t\t\ticon: icons[ postType ],\n\t\t\t\t\tcallback: ( { close } ) => {\n\t\t\t\t\t\tconst args = {\n\t\t\t\t\t\t\tpostType,\n\t\t\t\t\t\t\tpostId: record.id,\n\t\t\t\t\t\t\t...extraArgs,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst targetUrl = addQueryArgs(\n\t\t\t\t\t\t\t'site-editor.php',\n\t\t\t\t\t\t\targs\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\t\t\thistory.push( args );\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tclose();\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} );\n\t\t}, [ records, history ] );\n\n\t\treturn {\n\t\t\tcommands,\n\t\t\tisLoading,\n\t\t};\n\t};\n\nconst usePageNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'page' );\nconst usePostNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'post' );\nconst useTemplateNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'wp_template' );\nconst useTemplatePartNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'wp_template_part' );\n\nexport function useSiteEditorNavigationCommands() {\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-pages',\n\t\thook: usePageNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-posts',\n\t\thook: usePostNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-templates',\n\t\thook: useTemplateNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-template-parts',\n\t\thook: useTemplatePartNavigationCommandLoader,\n\t} );\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/core-commands",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "WordPress core reusable commands.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -27,15 +27,15 @@
27
27
  "sideEffects": false,
28
28
  "dependencies": {
29
29
  "@babel/runtime": "^7.16.0",
30
- "@wordpress/commands": "^0.5.0",
31
- "@wordpress/core-data": "^6.11.0",
32
- "@wordpress/data": "^9.4.0",
33
- "@wordpress/element": "^5.11.0",
34
- "@wordpress/i18n": "^4.34.0",
35
- "@wordpress/icons": "^9.25.0",
36
- "@wordpress/private-apis": "^0.16.0",
37
- "@wordpress/router": "^0.3.0",
38
- "@wordpress/url": "^3.35.0"
30
+ "@wordpress/commands": "^0.6.0",
31
+ "@wordpress/core-data": "^6.12.0",
32
+ "@wordpress/data": "^9.5.0",
33
+ "@wordpress/element": "^5.12.0",
34
+ "@wordpress/i18n": "^4.35.0",
35
+ "@wordpress/icons": "^9.26.0",
36
+ "@wordpress/private-apis": "^0.17.0",
37
+ "@wordpress/router": "^0.4.0",
38
+ "@wordpress/url": "^3.36.0"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "react": "^18.0.0"
@@ -43,5 +43,5 @@
43
43
  "publishConfig": {
44
44
  "access": "public"
45
45
  },
46
- "gitHead": "c7c79cb11b677adcbf06cf5f8cfb6c5ec1699f19"
46
+ "gitHead": "a92f606309b1541b834ff9b0a76ed2a466fc45ed"
47
47
  }