@wordpress/edit-site 4.10.0 → 4.11.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 +2 -0
- package/build/components/add-new-template/add-custom-template-modal.js +22 -42
- package/build/components/add-new-template/add-custom-template-modal.js.map +1 -1
- package/build/components/add-new-template/new-template.js +17 -20
- package/build/components/add-new-template/new-template.js.map +1 -1
- package/build/components/add-new-template/utils.js +366 -239
- package/build/components/add-new-template/utils.js.map +1 -1
- package/build/components/block-editor/index.js +1 -3
- package/build/components/block-editor/index.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +183 -13
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/global-styles/hooks.js +1 -1
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +95 -17
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +31 -0
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/header/index.js +7 -6
- package/build/components/header/index.js.map +1 -1
- package/build/hooks/index.js +2 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/template-part-edit.js +86 -0
- package/build/hooks/template-part-edit.js.map +1 -0
- package/build-module/components/add-new-template/add-custom-template-modal.js +23 -43
- package/build-module/components/add-new-template/add-custom-template-modal.js.map +1 -1
- package/build-module/components/add-new-template/new-template.js +18 -21
- package/build-module/components/add-new-template/new-template.js.map +1 -1
- package/build-module/components/add-new-template/utils.js +365 -227
- package/build-module/components/add-new-template/utils.js.map +1 -1
- package/build-module/components/block-editor/index.js +1 -2
- package/build-module/components/block-editor/index.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +183 -14
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +1 -1
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +94 -22
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +29 -0
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/header/index.js +8 -6
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/template-part-edit.js +67 -0
- package/build-module/hooks/template-part-edit.js.map +1 -0
- package/build-style/style-rtl.css +25 -25
- package/build-style/style.css +25 -25
- package/package.json +29 -29
- package/src/components/add-new-template/add-custom-template-modal.js +27 -45
- package/src/components/add-new-template/new-template.js +27 -64
- package/src/components/add-new-template/style.scss +20 -8
- package/src/components/add-new-template/utils.js +398 -229
- package/src/components/block-editor/index.js +0 -2
- package/src/components/global-styles/dimensions-panel.js +207 -14
- package/src/components/global-styles/hooks.js +2 -0
- package/src/components/global-styles/test/use-global-styles-output.js +64 -1
- package/src/components/global-styles/use-global-styles-output.js +100 -8
- package/src/components/global-styles/utils.js +31 -0
- package/src/components/header/index.js +9 -10
- package/src/components/header/style.scss +5 -3
- package/src/components/sidebar/style.scss +4 -0
- package/src/hooks/index.js +1 -0
- package/src/hooks/template-part-edit.js +82 -0
- package/src/style.scss +0 -1
- package/build/components/edit-template-part-menu-button/index.js +0 -90
- package/build/components/edit-template-part-menu-button/index.js.map +0 -1
- package/build-module/components/edit-template-part-menu-button/index.js +0 -72
- package/build-module/components/edit-template-part-menu-button/index.js.map +0 -1
- package/src/components/edit-template-part-menu-button/index.js +0 -82
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/global-styles/utils.js"],"names":["ROOT_BLOCK_NAME","ROOT_BLOCK_SELECTOR","ROOT_BLOCK_SUPPORTS","PRESET_METADATA","path","valueKey","cssVarInfix","classes","classSuffix","propertyName","valueFunc","slug","STYLE_PATH_TO_CSS_VAR_INFIX","findInPresetsBy","features","blockName","presetPath","presetProperty","presetValueValue","orderedPresetsByOrigin","presetByOrigin","origins","origin","presets","presetObject","preset","highestPresetObjectWithSameSlug","undefined","getPresetVariableFromValue","variableStylePath","presetPropertyValue","metadata","getValueFromPresetVariable","variable","presetType","result","getValueFromVariable","getValueFromCustomVariable","USER_VALUE_PREFIX","THEME_VALUE_PREFIX","THEME_VALUE_SUFFIX","parsedVar","startsWith","slice","length","split","endsWith","type"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACO,MAAMA,eAAe,GAAG,MAAxB;;AACA,MAAMC,mBAAmB,GAAG,MAA5B;;AACA,MAAMC,mBAAmB,GAAG,CAClC,YADkC,EAElC,iBAFkC,EAGlC,OAHkC,EAIlC,WAJkC,EAKlC,aALkC,EAMlC,YANkC,EAOlC,UAPkC,EAQlC,WARkC,EASlC,YATkC,EAUlC,YAVkC,EAWlC,gBAXkC,EAYlC,eAZkC,EAalC,SAbkC,CAA5B;;AAgBA,MAAMC,eAAe,GAAG,CAC9B;AACCC,EAAAA,IAAI,EAAE,CAAE,OAAF,EAAW,SAAX,CADP;AAECC,EAAAA,QAAQ,EAAE,OAFX;AAGCC,EAAAA,WAAW,EAAE,OAHd;AAICC,EAAAA,OAAO,EAAE,CACR;AAAEC,IAAAA,WAAW,EAAE,OAAf;AAAwBC,IAAAA,YAAY,EAAE;AAAtC,GADQ,EAER;AACCD,IAAAA,WAAW,EAAE,kBADd;AAECC,IAAAA,YAAY,EAAE;AAFf,GAFQ,EAMR;AACCD,IAAAA,WAAW,EAAE,cADd;AAECC,IAAAA,YAAY,EAAE;AAFf,GANQ;AAJV,CAD8B,EAiB9B;AACCL,EAAAA,IAAI,EAAE,CAAE,OAAF,EAAW,WAAX,CADP;AAECC,EAAAA,QAAQ,EAAE,UAFX;AAGCC,EAAAA,WAAW,EAAE,UAHd;AAICC,EAAAA,OAAO,EAAE,CACR;AACCC,IAAAA,WAAW,EAAE,qBADd;AAECC,IAAAA,YAAY,EAAE;AAFf,GADQ;AAJV,CAjB8B,EA4B9B;AACCL,EAAAA,IAAI,EAAE,CAAE,O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C,oBAAT,CAA+BtB,QAA/B,EAAyCC,SAAzC,EAAoDkB,QAApD,EAA+D;AACrE,MAAK,CAAEA,QAAF,IAAc,OAAOA,QAAP,KAAoB,QAAvC,EAAkD;AACjD,WAAOA,QAAP;AACA;;AACD,QAAMK,iBAAiB,GAAG,MAA1B;AACA,QAAMC,kBAAkB,GAAG,YAA3B;AACA,QAAMC,kBAAkB,GAAG,GAA3B;AAEA,MAAIC,SAAJ;;AAEA,MAAKR,QAAQ,CAACS,UAAT,CAAqBJ,iBAArB,CAAL,EAAgD;AAC/CG,IAAAA,SAAS,GAAGR,QAAQ,CAACU,KAAT,CAAgBL,iBAAiB,CAACM,MAAlC,EAA2CC,KAA3C,CAAkD,GAAlD,CAAZ;AACA,GAFD,MAEO,IACNZ,QAAQ,CAACS,UAAT,CAAqBH,kBAArB,KACAN,QAAQ,CAACa,QAAT,CAAmBN,kBAAnB,CAFM,EAGL;AACDC,IAAAA,SAAS,GAAGR,QAAQ,CAClBU,KADU,CACHJ,kBAAkB,CAACK,MADhB,EACwB,CAACJ,kBAAkB,CAACI,MAD5C,EAEVC,KAFU,CAEH,IAFG,CAAZ;AAGA,GAPM,MAOA;AACN;AACA,WAAOZ,QAAP;AACA;;AAED,QAAM,CAAEc,IAAF,EAAQ,GAAG3C,IAAX,IAAoBqC,SAA1B;;AACA,MAAKM,IAAI,KAAK,QAAd,EAAyB;AACxB,WAAOf,0BAA0B,CAChClB,QADgC,EAEhCC,SAFgC,EAGhCkB,QAHgC,EAIhC7B,IAJgC,CAAjC;AAMA;;AACD,MAAK2C,IAAI,KAAK,QAAd,EAAyB;AACxB,WAAOV,0BAA0B,CAChCvB,QADgC,EAEhCC,SAFgC,EAGhCkB,QAHgC,EAIhC7B,IAJgC,CAAjC;AAMA;;AACD,SAAO6B,QAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { get, find } from 'lodash';\n\n/* Supporting data. */\nexport const ROOT_BLOCK_NAME = 'root';\nexport const ROOT_BLOCK_SELECTOR = 'body';\nexport const ROOT_BLOCK_SUPPORTS = [\n\t'background',\n\t'backgroundColor',\n\t'color',\n\t'linkColor',\n\t'buttonColor',\n\t'fontFamily',\n\t'fontSize',\n\t'fontStyle',\n\t'fontWeight',\n\t'lineHeight',\n\t'textDecoration',\n\t'textTransform',\n\t'padding',\n];\n\nexport const PRESET_METADATA = [\n\t{\n\t\tpath: [ 'color', 'palette' ],\n\t\tvalueKey: 'color',\n\t\tcssVarInfix: 'color',\n\t\tclasses: [\n\t\t\t{ classSuffix: 'color', propertyName: 'color' },\n\t\t\t{\n\t\t\t\tclassSuffix: 'background-color',\n\t\t\t\tpropertyName: 'background-color',\n\t\t\t},\n\t\t\t{\n\t\t\t\tclassSuffix: 'border-color',\n\t\t\t\tpropertyName: 'border-color',\n\t\t\t},\n\t\t],\n\t},\n\t{\n\t\tpath: [ 'color', 'gradients' ],\n\t\tvalueKey: 'gradient',\n\t\tcssVarInfix: 'gradient',\n\t\tclasses: [\n\t\t\t{\n\t\t\t\tclassSuffix: 'gradient-background',\n\t\t\t\tpropertyName: 'background',\n\t\t\t},\n\t\t],\n\t},\n\t{\n\t\tpath: [ 'color', 'duotone' ],\n\t\tcssVarInfix: 'duotone',\n\t\tvalueFunc: ( { slug } ) => `url( '#wp-duotone-${ slug }' )`,\n\t\tclasses: [],\n\t},\n\t{\n\t\tpath: [ 'typography', 'fontSizes' ],\n\t\tvalueKey: 'size',\n\t\tcssVarInfix: 'font-size',\n\t\tclasses: [ { classSuffix: 'font-size', propertyName: 'font-size' } ],\n\t},\n\t{\n\t\tpath: [ 'typography', 'fontFamilies' ],\n\t\tvalueKey: 'fontFamily',\n\t\tcssVarInfix: 'font-family',\n\t\tclasses: [\n\t\t\t{ classSuffix: 'font-family', propertyName: 'font-family' },\n\t\t],\n\t},\n];\n\nconst STYLE_PATH_TO_CSS_VAR_INFIX = {\n\t'color.background': 'color',\n\t'color.text': 'color',\n\t'elements.link.color.text': 'color',\n\t'elements.button.color.text': 'color',\n\t'elements.button.backgroundColor': 'background-color',\n\t'color.gradient': 'gradient',\n\t'typography.fontSize': 'font-size',\n\t'typography.fontFamily': 'font-family',\n};\n\nfunction findInPresetsBy(\n\tfeatures,\n\tblockName,\n\tpresetPath,\n\tpresetProperty,\n\tpresetValueValue\n) {\n\t// Block presets take priority above root level presets.\n\tconst orderedPresetsByOrigin = [\n\t\tget( features, [ 'blocks', blockName, ...presetPath ] ),\n\t\tget( features, presetPath ),\n\t];\n\n\tfor ( const presetByOrigin of orderedPresetsByOrigin ) {\n\t\tif ( presetByOrigin ) {\n\t\t\t// Preset origins ordered by priority.\n\t\t\tconst origins = [ 'custom', 'theme', 'default' ];\n\t\t\tfor ( const origin of origins ) {\n\t\t\t\tconst presets = presetByOrigin[ origin ];\n\t\t\t\tif ( presets ) {\n\t\t\t\t\tconst presetObject = find(\n\t\t\t\t\t\tpresets,\n\t\t\t\t\t\t( preset ) =>\n\t\t\t\t\t\t\tpreset[ presetProperty ] === presetValueValue\n\t\t\t\t\t);\n\t\t\t\t\tif ( presetObject ) {\n\t\t\t\t\t\tif ( presetProperty === 'slug' ) {\n\t\t\t\t\t\t\treturn presetObject;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// If there is a highest priority preset with the same slug but different value the preset we found was overwritten and should be ignored.\n\t\t\t\t\t\tconst highestPresetObjectWithSameSlug = findInPresetsBy(\n\t\t\t\t\t\t\tfeatures,\n\t\t\t\t\t\t\tblockName,\n\t\t\t\t\t\t\tpresetPath,\n\t\t\t\t\t\t\t'slug',\n\t\t\t\t\t\t\tpresetObject.slug\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\thighestPresetObjectWithSameSlug[\n\t\t\t\t\t\t\t\tpresetProperty\n\t\t\t\t\t\t\t] === presetObject[ presetProperty ]\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\treturn presetObject;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport function getPresetVariableFromValue(\n\tfeatures,\n\tblockName,\n\tvariableStylePath,\n\tpresetPropertyValue\n) {\n\tif ( ! presetPropertyValue ) {\n\t\treturn presetPropertyValue;\n\t}\n\n\tconst cssVarInfix = STYLE_PATH_TO_CSS_VAR_INFIX[ variableStylePath ];\n\n\tconst metadata = find( PRESET_METADATA, [ 'cssVarInfix', cssVarInfix ] );\n\n\tif ( ! metadata ) {\n\t\t// The property doesn't have preset data\n\t\t// so the value should be returned as it is.\n\t\treturn presetPropertyValue;\n\t}\n\tconst { valueKey, path } = metadata;\n\n\tconst presetObject = findInPresetsBy(\n\t\tfeatures,\n\t\tblockName,\n\t\tpath,\n\t\tvalueKey,\n\t\tpresetPropertyValue\n\t);\n\n\tif ( ! presetObject ) {\n\t\t// Value wasn't found in the presets,\n\t\t// so it must be a custom value.\n\t\treturn presetPropertyValue;\n\t}\n\n\treturn `var:preset|${ cssVarInfix }|${ presetObject.slug }`;\n}\n\nfunction getValueFromPresetVariable(\n\tfeatures,\n\tblockName,\n\tvariable,\n\t[ presetType, slug ]\n) {\n\tconst metadata = find( PRESET_METADATA, [ 'cssVarInfix', presetType ] );\n\tif ( ! metadata ) {\n\t\treturn variable;\n\t}\n\n\tconst presetObject = findInPresetsBy(\n\t\tfeatures,\n\t\tblockName,\n\t\tmetadata.path,\n\t\t'slug',\n\t\tslug\n\t);\n\n\tif ( presetObject ) {\n\t\tconst { valueKey } = metadata;\n\t\tconst result = presetObject[ valueKey ];\n\t\treturn getValueFromVariable( features, blockName, result );\n\t}\n\n\treturn variable;\n}\n\nfunction getValueFromCustomVariable( features, blockName, variable, path ) {\n\tconst result =\n\t\tget( features, [ 'blocks', blockName, 'custom', ...path ] ) ??\n\t\tget( features, [ 'custom', ...path ] );\n\tif ( ! result ) {\n\t\treturn variable;\n\t}\n\t// A variable may reference another variable so we need recursion until we find the value.\n\treturn getValueFromVariable( features, blockName, result );\n}\n\nexport function getValueFromVariable( features, blockName, variable ) {\n\tif ( ! variable || typeof variable !== 'string' ) {\n\t\treturn variable;\n\t}\n\tconst USER_VALUE_PREFIX = 'var:';\n\tconst THEME_VALUE_PREFIX = 'var(--wp--';\n\tconst THEME_VALUE_SUFFIX = ')';\n\n\tlet parsedVar;\n\n\tif ( variable.startsWith( USER_VALUE_PREFIX ) ) {\n\t\tparsedVar = variable.slice( USER_VALUE_PREFIX.length ).split( '|' );\n\t} else if (\n\t\tvariable.startsWith( THEME_VALUE_PREFIX ) &&\n\t\tvariable.endsWith( THEME_VALUE_SUFFIX )\n\t) {\n\t\tparsedVar = variable\n\t\t\t.slice( THEME_VALUE_PREFIX.length, -THEME_VALUE_SUFFIX.length )\n\t\t\t.split( '--' );\n\t} else {\n\t\t// We don't know how to parse the value: either is raw of uses complex CSS such as `calc(1px * var(--wp--variable) )`\n\t\treturn variable;\n\t}\n\n\tconst [ type, ...path ] = parsedVar;\n\tif ( type === 'preset' ) {\n\t\treturn getValueFromPresetVariable(\n\t\t\tfeatures,\n\t\t\tblockName,\n\t\t\tvariable,\n\t\t\tpath\n\t\t);\n\t}\n\tif ( type === 'custom' ) {\n\t\treturn getValueFromCustomVariable(\n\t\t\tfeatures,\n\t\t\tblockName,\n\t\t\tvariable,\n\t\t\tpath\n\t\t);\n\t}\n\treturn variable;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/global-styles/utils.js"],"names":["ROOT_BLOCK_NAME","ROOT_BLOCK_SELECTOR","ROOT_BLOCK_SUPPORTS","PRESET_METADATA","path","valueKey","cssVarInfix","classes","classSuffix","propertyName","valueFunc","slug","STYLE_PATH_TO_CSS_VAR_INFIX","findInPresetsBy","features","blockName","presetPath","presetProperty","presetValueValue","orderedPresetsByOrigin","presetByOrigin","origins","origin","presets","presetObject","preset","highestPresetObjectWithSameSlug","undefined","getPresetVariableFromValue","variableStylePath","presetPropertyValue","metadata","getValueFromPresetVariable","variable","presetType","result","getValueFromVariable","getValueFromCustomVariable","USER_VALUE_PREFIX","THEME_VALUE_PREFIX","THEME_VALUE_SUFFIX","parsedVar","startsWith","slice","length","split","endsWith","type","scopeSelector","scope","selector","scopes","selectors","selectorsScoped","forEach","outer","inner","push","trim","join"],"mappings":";;;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACO,MAAMA,eAAe,GAAG,MAAxB;;AACA,MAAMC,mBAAmB,GAAG,MAA5B;;AACA,MAAMC,mBAAmB,GAAG,CAClC,YADkC,EAElC,iBAFkC,EAGlC,OAHkC,EAIlC,WAJkC,EAKlC,aALkC,EAMlC,YANkC,EAOlC,UAPkC,EAQlC,WARkC,EASlC,YATkC,EAUlC,YAVkC,EAWlC,gBAXkC,EAYlC,eAZkC,EAalC,SAbkC,CAA5B;;AAgBA,MAAMC,eAAe,GAAG,CAC9B;AACCC,EAAAA,IAAI,EAAE,CAAE,OAAF,EAAW,SAAX,CADP;AAECC,EAAAA,QAAQ,EAAE,OAFX;AAGCC,EAAAA,WAAW,EAAE,OAHd;AAICC,EAAAA,OAAO,EAAE,CACR;AAAEC,IAAAA,WAAW,EAAE,OAAf;AAAwBC,IAAAA,YAAY,EAAE;AAAtC,GADQ,EAER;AACCD,IAAAA,WAAW,EAAE,kBADd;AAECC,IAAAA,YAAY,EAAE;AAFf,GAFQ,EAMR;AACCD,IAAAA,WAAW,EAAE,cADd;AAECC,IAAAA,YAAY,EAAE;AAFf,GANQ;AAJV,CAD8B,EAiB9B;AACCL,EAAAA,IAAI,EAAE,CAAE,OAAF,EAAW,WAAX,CADP;AAECC,EAAAA,QAAQ,EAAE,UAFX;AAGCC,EAAAA,WAAW,EAAE,UAHd;AAICC,EAAAA,OAAO,EAAE,CACR;AACCC,IAAAA,WAAW,EAAE,qBADd;AAECC,IAAAA,YAAY,EAAE;AAFf,GADQ;AAJV,CAjB8B,EA4B9B;AACCL,EAAAA,IAAI,EAAE,CAAE,OAAF,EAAW,SAAX,CADP;AAECE,EAAAA,WAAW,EAAE,SAFd;A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,KAAK,CAACJ,KAAN,CAAa,GAAb,CAAf;AACA,QAAMO,SAAS,GAAGF,QAAQ,CAACL,KAAT,CAAgB,GAAhB,CAAlB;AAEA,QAAMQ,eAAe,GAAG,EAAxB;AACAF,EAAAA,MAAM,CAACG,OAAP,CAAkBC,KAAF,IAAa;AAC5BH,IAAAA,SAAS,CAACE,OAAV,CAAqBE,KAAF,IAAa;AAC/BH,MAAAA,eAAe,CAACI,IAAhB,CAAuB,GAAGF,KAAK,CAACG,IAAN,EAAc,IAAIF,KAAK,CAACE,IAAN,EAAc,EAA1D;AACA,KAFD;AAGA,GAJD;AAMA,SAAOL,eAAe,CAACM,IAAhB,CAAsB,IAAtB,CAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { get, find } from 'lodash';\n\n/* Supporting data. */\nexport const ROOT_BLOCK_NAME = 'root';\nexport const ROOT_BLOCK_SELECTOR = 'body';\nexport const ROOT_BLOCK_SUPPORTS = [\n\t'background',\n\t'backgroundColor',\n\t'color',\n\t'linkColor',\n\t'buttonColor',\n\t'fontFamily',\n\t'fontSize',\n\t'fontStyle',\n\t'fontWeight',\n\t'lineHeight',\n\t'textDecoration',\n\t'textTransform',\n\t'padding',\n];\n\nexport const PRESET_METADATA = [\n\t{\n\t\tpath: [ 'color', 'palette' ],\n\t\tvalueKey: 'color',\n\t\tcssVarInfix: 'color',\n\t\tclasses: [\n\t\t\t{ classSuffix: 'color', propertyName: 'color' },\n\t\t\t{\n\t\t\t\tclassSuffix: 'background-color',\n\t\t\t\tpropertyName: 'background-color',\n\t\t\t},\n\t\t\t{\n\t\t\t\tclassSuffix: 'border-color',\n\t\t\t\tpropertyName: 'border-color',\n\t\t\t},\n\t\t],\n\t},\n\t{\n\t\tpath: [ 'color', 'gradients' ],\n\t\tvalueKey: 'gradient',\n\t\tcssVarInfix: 'gradient',\n\t\tclasses: [\n\t\t\t{\n\t\t\t\tclassSuffix: 'gradient-background',\n\t\t\t\tpropertyName: 'background',\n\t\t\t},\n\t\t],\n\t},\n\t{\n\t\tpath: [ 'color', 'duotone' ],\n\t\tcssVarInfix: 'duotone',\n\t\tvalueFunc: ( { slug } ) => `url( '#wp-duotone-${ slug }' )`,\n\t\tclasses: [],\n\t},\n\t{\n\t\tpath: [ 'typography', 'fontSizes' ],\n\t\tvalueKey: 'size',\n\t\tcssVarInfix: 'font-size',\n\t\tclasses: [ { classSuffix: 'font-size', propertyName: 'font-size' } ],\n\t},\n\t{\n\t\tpath: [ 'typography', 'fontFamilies' ],\n\t\tvalueKey: 'fontFamily',\n\t\tcssVarInfix: 'font-family',\n\t\tclasses: [\n\t\t\t{ classSuffix: 'font-family', propertyName: 'font-family' },\n\t\t],\n\t},\n];\n\nconst STYLE_PATH_TO_CSS_VAR_INFIX = {\n\t'color.background': 'color',\n\t'color.text': 'color',\n\t'elements.link.color.text': 'color',\n\t'elements.button.color.text': 'color',\n\t'elements.button.backgroundColor': 'background-color',\n\t'color.gradient': 'gradient',\n\t'typography.fontSize': 'font-size',\n\t'typography.fontFamily': 'font-family',\n};\n\nfunction findInPresetsBy(\n\tfeatures,\n\tblockName,\n\tpresetPath,\n\tpresetProperty,\n\tpresetValueValue\n) {\n\t// Block presets take priority above root level presets.\n\tconst orderedPresetsByOrigin = [\n\t\tget( features, [ 'blocks', blockName, ...presetPath ] ),\n\t\tget( features, presetPath ),\n\t];\n\n\tfor ( const presetByOrigin of orderedPresetsByOrigin ) {\n\t\tif ( presetByOrigin ) {\n\t\t\t// Preset origins ordered by priority.\n\t\t\tconst origins = [ 'custom', 'theme', 'default' ];\n\t\t\tfor ( const origin of origins ) {\n\t\t\t\tconst presets = presetByOrigin[ origin ];\n\t\t\t\tif ( presets ) {\n\t\t\t\t\tconst presetObject = find(\n\t\t\t\t\t\tpresets,\n\t\t\t\t\t\t( preset ) =>\n\t\t\t\t\t\t\tpreset[ presetProperty ] === presetValueValue\n\t\t\t\t\t);\n\t\t\t\t\tif ( presetObject ) {\n\t\t\t\t\t\tif ( presetProperty === 'slug' ) {\n\t\t\t\t\t\t\treturn presetObject;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// If there is a highest priority preset with the same slug but different value the preset we found was overwritten and should be ignored.\n\t\t\t\t\t\tconst highestPresetObjectWithSameSlug = findInPresetsBy(\n\t\t\t\t\t\t\tfeatures,\n\t\t\t\t\t\t\tblockName,\n\t\t\t\t\t\t\tpresetPath,\n\t\t\t\t\t\t\t'slug',\n\t\t\t\t\t\t\tpresetObject.slug\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\thighestPresetObjectWithSameSlug[\n\t\t\t\t\t\t\t\tpresetProperty\n\t\t\t\t\t\t\t] === presetObject[ presetProperty ]\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\treturn presetObject;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport function getPresetVariableFromValue(\n\tfeatures,\n\tblockName,\n\tvariableStylePath,\n\tpresetPropertyValue\n) {\n\tif ( ! presetPropertyValue ) {\n\t\treturn presetPropertyValue;\n\t}\n\n\tconst cssVarInfix = STYLE_PATH_TO_CSS_VAR_INFIX[ variableStylePath ];\n\n\tconst metadata = find( PRESET_METADATA, [ 'cssVarInfix', cssVarInfix ] );\n\n\tif ( ! metadata ) {\n\t\t// The property doesn't have preset data\n\t\t// so the value should be returned as it is.\n\t\treturn presetPropertyValue;\n\t}\n\tconst { valueKey, path } = metadata;\n\n\tconst presetObject = findInPresetsBy(\n\t\tfeatures,\n\t\tblockName,\n\t\tpath,\n\t\tvalueKey,\n\t\tpresetPropertyValue\n\t);\n\n\tif ( ! presetObject ) {\n\t\t// Value wasn't found in the presets,\n\t\t// so it must be a custom value.\n\t\treturn presetPropertyValue;\n\t}\n\n\treturn `var:preset|${ cssVarInfix }|${ presetObject.slug }`;\n}\n\nfunction getValueFromPresetVariable(\n\tfeatures,\n\tblockName,\n\tvariable,\n\t[ presetType, slug ]\n) {\n\tconst metadata = find( PRESET_METADATA, [ 'cssVarInfix', presetType ] );\n\tif ( ! metadata ) {\n\t\treturn variable;\n\t}\n\n\tconst presetObject = findInPresetsBy(\n\t\tfeatures,\n\t\tblockName,\n\t\tmetadata.path,\n\t\t'slug',\n\t\tslug\n\t);\n\n\tif ( presetObject ) {\n\t\tconst { valueKey } = metadata;\n\t\tconst result = presetObject[ valueKey ];\n\t\treturn getValueFromVariable( features, blockName, result );\n\t}\n\n\treturn variable;\n}\n\nfunction getValueFromCustomVariable( features, blockName, variable, path ) {\n\tconst result =\n\t\tget( features, [ 'blocks', blockName, 'custom', ...path ] ) ??\n\t\tget( features, [ 'custom', ...path ] );\n\tif ( ! result ) {\n\t\treturn variable;\n\t}\n\t// A variable may reference another variable so we need recursion until we find the value.\n\treturn getValueFromVariable( features, blockName, result );\n}\n\nexport function getValueFromVariable( features, blockName, variable ) {\n\tif ( ! variable || typeof variable !== 'string' ) {\n\t\treturn variable;\n\t}\n\tconst USER_VALUE_PREFIX = 'var:';\n\tconst THEME_VALUE_PREFIX = 'var(--wp--';\n\tconst THEME_VALUE_SUFFIX = ')';\n\n\tlet parsedVar;\n\n\tif ( variable.startsWith( USER_VALUE_PREFIX ) ) {\n\t\tparsedVar = variable.slice( USER_VALUE_PREFIX.length ).split( '|' );\n\t} else if (\n\t\tvariable.startsWith( THEME_VALUE_PREFIX ) &&\n\t\tvariable.endsWith( THEME_VALUE_SUFFIX )\n\t) {\n\t\tparsedVar = variable\n\t\t\t.slice( THEME_VALUE_PREFIX.length, -THEME_VALUE_SUFFIX.length )\n\t\t\t.split( '--' );\n\t} else {\n\t\t// We don't know how to parse the value: either is raw of uses complex CSS such as `calc(1px * var(--wp--variable) )`\n\t\treturn variable;\n\t}\n\n\tconst [ type, ...path ] = parsedVar;\n\tif ( type === 'preset' ) {\n\t\treturn getValueFromPresetVariable(\n\t\t\tfeatures,\n\t\t\tblockName,\n\t\t\tvariable,\n\t\t\tpath\n\t\t);\n\t}\n\tif ( type === 'custom' ) {\n\t\treturn getValueFromCustomVariable(\n\t\t\tfeatures,\n\t\t\tblockName,\n\t\t\tvariable,\n\t\t\tpath\n\t\t);\n\t}\n\treturn variable;\n}\n\n/**\n * Function that scopes a selector with another one. This works a bit like\n * SCSS nesting except the `&` operator isn't supported.\n *\n * @example\n * ```js\n * const scope = '.a, .b .c';\n * const selector = '> .x, .y';\n * const merged = scopeSelector( scope, selector );\n * // merged is '.a > .x, .a .y, .b .c > .x, .b .c .y'\n * ```\n *\n * @param {string} scope Selector to scope to.\n * @param {string} selector Original selector.\n *\n * @return {string} Scoped selector.\n */\nexport function scopeSelector( scope, selector ) {\n\tconst scopes = scope.split( ',' );\n\tconst selectors = selector.split( ',' );\n\n\tconst selectorsScoped = [];\n\tscopes.forEach( ( outer ) => {\n\t\tselectors.forEach( ( inner ) => {\n\t\t\tselectorsScoped.push( `${ outer.trim() } ${ inner.trim() }` );\n\t\t} );\n\t} );\n\n\treturn selectorsScoped.join( ', ' );\n}\n"]}
|
|
@@ -123,6 +123,10 @@ function Header(_ref) {
|
|
|
123
123
|
}, [isInserterOpen, setIsInserterOpened]);
|
|
124
124
|
const toggleListView = (0, _element.useCallback)(() => setIsListViewOpened(!isListViewOpen), [setIsListViewOpened, isListViewOpen]);
|
|
125
125
|
const isFocusMode = templateType === 'wp_template_part';
|
|
126
|
+
/* translators: button label text should, if possible, be under 16 characters. */
|
|
127
|
+
|
|
128
|
+
const longLabel = (0, _i18n._x)('Toggle block inserter', 'Generic label for block inserter button');
|
|
129
|
+
const shortLabel = !isInserterOpen ? (0, _i18n.__)('Add') : (0, _i18n.__)('Close');
|
|
126
130
|
return (0, _element.createElement)("div", {
|
|
127
131
|
className: "edit-site-header"
|
|
128
132
|
}, (0, _element.createElement)(_blockEditor.NavigableToolbar, {
|
|
@@ -139,13 +143,10 @@ function Header(_ref) {
|
|
|
139
143
|
onMouseDown: preventDefault,
|
|
140
144
|
onClick: openInserter,
|
|
141
145
|
disabled: !isVisualMode,
|
|
142
|
-
icon: _icons.plus
|
|
143
|
-
|
|
144
|
-
characters. */
|
|
145
|
-
,
|
|
146
|
-
label: (0, _i18n._x)('Toggle block inserter', 'Generic label for block inserter button'),
|
|
146
|
+
icon: _icons.plus,
|
|
147
|
+
label: showIconLabels ? shortLabel : longLabel,
|
|
147
148
|
showTooltip: !showIconLabels
|
|
148
|
-
}
|
|
149
|
+
}), isLargeViewport && (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_components.ToolbarItem, {
|
|
149
150
|
as: _blockEditor.ToolSelector,
|
|
150
151
|
showTooltip: !showIconLabels,
|
|
151
152
|
variant: showIconLabels ? 'tertiary' : undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/header/index.js"],"names":["preventDefault","event","Header","openEntitiesSavedStates","isEntitiesSavedStatesOpen","showIconLabels","inserterButton","deviceType","entityTitle","template","templateType","isInserterOpen","isListViewOpen","listViewShortcut","isLoaded","isVisualMode","select","__experimentalGetPreviewDeviceType","getEditedPostType","getEditedPostId","isInserterOpened","isListViewOpened","getEditorMode","editSiteStore","getEditedEntityRecord","coreStore","__experimentalGetTemplateInfo","getTemplateInfo","editorStore","getShortcutRepresentation","keyboardShortcutsStore","postType","postId","record","_isLoaded","title","__experimentalSetPreviewDeviceType","setPreviewDeviceType","setIsInserterOpened","setIsListViewOpened","isLargeViewport","openInserter","current","focus","toggleListView","isFocusMode","Button","plus","ToolSelector","undefined","UndoButton","RedoButton","listView","onClose"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AA5BA;AACA;AACA;;AAiBA;AACA;AACA;AASA,MAAMA,cAAc,GAAKC,KAAF,IAAa;AACnCA,EAAAA,KAAK,CAACD,cAAN;AACA,CAFD;;AAIe,SAASE,MAAT,OAIX;AAAA,M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,EAAGI,QAPZ;AAQC,IAAA,cAAc,EAAGT;AARlB,KAUG;AAAA,QAAE;AAAEgD,MAAAA;AAAF,KAAF;AAAA,WACD,4BAAC,wBAAD;AACC,MAAA,QAAQ,EAAG5C,QADZ;AAEC,MAAA,OAAO,EAAG4C;AAFX,MADC;AAAA,GAVH,CADD,CApED,EAwFC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC;AAAK,IAAA,SAAS,EAAC;AAAf,KACG,CAAER,WAAF,IACD,4BAAC,yCAAD;AACC,IAAA,UAAU,EAAGtC,UADd;AAEC,IAAA,aAAa,EAAG8B;AAFjB,IAFF,EAOC,4BAAC,mBAAD;AACC,IAAA,uBAAuB,EAAGlC,uBAD3B;AAEC,IAAA,yBAAyB,EAAGC;AAF7B,IAPD,EAWC,4BAAC,sBAAD,CAAa,IAAb;AAAkB,IAAA,KAAK,EAAC;AAAxB,IAXD,EAYC,4BAAC,iBAAD,OAZD,CADD,CAxFD,CADD;AA2GA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback, useRef } from '@wordpress/element';\nimport { useViewportMatch } from '@wordpress/compose';\nimport {\n\tToolSelector,\n\t__experimentalPreviewOptions as PreviewOptions,\n\tNavigableToolbar,\n} from '@wordpress/block-editor';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { PinnedItems } from '@wordpress/interface';\nimport { _x, __ } from '@wordpress/i18n';\nimport { listView, plus } from '@wordpress/icons';\nimport { Button, ToolbarItem } from '@wordpress/components';\nimport { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\nimport { store as editorStore } from '@wordpress/editor';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport MoreMenu from './more-menu';\nimport SaveButton from '../save-button';\nimport UndoButton from './undo-redo/undo';\nimport RedoButton from './undo-redo/redo';\nimport DocumentActions from './document-actions';\nimport TemplateDetails from '../template-details';\nimport { store as editSiteStore } from '../../store';\n\nconst preventDefault = ( event ) => {\n\tevent.preventDefault();\n};\n\nexport default function Header( {\n\topenEntitiesSavedStates,\n\tisEntitiesSavedStatesOpen,\n\tshowIconLabels,\n} ) {\n\tconst inserterButton = useRef();\n\tconst {\n\t\tdeviceType,\n\t\tentityTitle,\n\t\ttemplate,\n\t\ttemplateType,\n\t\tisInserterOpen,\n\t\tisListViewOpen,\n\t\tlistViewShortcut,\n\t\tisLoaded,\n\t\tisVisualMode,\n\t} = useSelect( ( select ) => {\n\t\tconst {\n\t\t\t__experimentalGetPreviewDeviceType,\n\t\t\tgetEditedPostType,\n\t\t\tgetEditedPostId,\n\t\t\tisInserterOpened,\n\t\t\tisListViewOpened,\n\t\t\tgetEditorMode,\n\t\t} = select( editSiteStore );\n\t\tconst { getEditedEntityRecord } = select( coreStore );\n\t\tconst { __experimentalGetTemplateInfo: getTemplateInfo } =\n\t\t\tselect( editorStore );\n\t\tconst { getShortcutRepresentation } = select( keyboardShortcutsStore );\n\n\t\tconst postType = getEditedPostType();\n\t\tconst postId = getEditedPostId();\n\t\tconst record = getEditedEntityRecord( 'postType', postType, postId );\n\t\tconst _isLoaded = !! postId;\n\n\t\treturn {\n\t\t\tdeviceType: __experimentalGetPreviewDeviceType(),\n\t\t\tentityTitle: getTemplateInfo( record ).title,\n\t\t\tisLoaded: _isLoaded,\n\t\t\ttemplate: record,\n\t\t\ttemplateType: postType,\n\t\t\tisInserterOpen: isInserterOpened(),\n\t\t\tisListViewOpen: isListViewOpened(),\n\t\t\tlistViewShortcut: getShortcutRepresentation(\n\t\t\t\t'core/edit-site/toggle-list-view'\n\t\t\t),\n\t\t\tisVisualMode: getEditorMode() === 'visual',\n\t\t};\n\t}, [] );\n\n\tconst {\n\t\t__experimentalSetPreviewDeviceType: setPreviewDeviceType,\n\t\tsetIsInserterOpened,\n\t\tsetIsListViewOpened,\n\t} = useDispatch( editSiteStore );\n\n\tconst isLargeViewport = useViewportMatch( 'medium' );\n\n\tconst openInserter = useCallback( () => {\n\t\tif ( isInserterOpen ) {\n\t\t\t// Focusing the inserter button closes the inserter popover.\n\t\t\tinserterButton.current.focus();\n\t\t} else {\n\t\t\tsetIsInserterOpened( true );\n\t\t}\n\t}, [ isInserterOpen, setIsInserterOpened ] );\n\n\tconst toggleListView = useCallback(\n\t\t() => setIsListViewOpened( ! isListViewOpen ),\n\t\t[ setIsListViewOpened, isListViewOpen ]\n\t);\n\n\tconst isFocusMode = templateType === 'wp_template_part';\n\n\treturn (\n\t\t<div className=\"edit-site-header\">\n\t\t\t<NavigableToolbar\n\t\t\t\tclassName=\"edit-site-header_start\"\n\t\t\t\taria-label={ __( 'Document tools' ) }\n\t\t\t>\n\t\t\t\t<div className=\"edit-site-header__toolbar\">\n\t\t\t\t\t<ToolbarItem\n\t\t\t\t\t\tref={ inserterButton }\n\t\t\t\t\t\tas={ Button }\n\t\t\t\t\t\tclassName=\"edit-site-header-toolbar__inserter-toggle\"\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\tisPressed={ isInserterOpen }\n\t\t\t\t\t\tonMouseDown={ preventDefault }\n\t\t\t\t\t\tonClick={ openInserter }\n\t\t\t\t\t\tdisabled={ ! isVisualMode }\n\t\t\t\t\t\ticon={ plus }\n\t\t\t\t\t\t/* translators: button label text should, if possible, be under 16\n\t\t\t\tcharacters. */\n\t\t\t\t\t\tlabel={ _x(\n\t\t\t\t\t\t\t'Toggle block inserter',\n\t\t\t\t\t\t\t'Generic label for block inserter button'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tshowTooltip={ ! showIconLabels }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ showIconLabels &&\n\t\t\t\t\t\t\t( ! isInserterOpen ? __( 'Add' ) : __( 'Close' ) ) }\n\t\t\t\t\t</ToolbarItem>\n\t\t\t\t\t{ isLargeViewport && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<ToolbarItem\n\t\t\t\t\t\t\t\tas={ ToolSelector }\n\t\t\t\t\t\t\t\tshowTooltip={ ! showIconLabels }\n\t\t\t\t\t\t\t\tvariant={\n\t\t\t\t\t\t\t\t\tshowIconLabels ? 'tertiary' : undefined\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tdisabled={ ! isVisualMode }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<ToolbarItem\n\t\t\t\t\t\t\t\tas={ UndoButton }\n\t\t\t\t\t\t\t\tshowTooltip={ ! showIconLabels }\n\t\t\t\t\t\t\t\tvariant={\n\t\t\t\t\t\t\t\t\tshowIconLabels ? 'tertiary' : undefined\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<ToolbarItem\n\t\t\t\t\t\t\t\tas={ RedoButton }\n\t\t\t\t\t\t\t\tshowTooltip={ ! showIconLabels }\n\t\t\t\t\t\t\t\tvariant={\n\t\t\t\t\t\t\t\t\tshowIconLabels ? 'tertiary' : undefined\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<ToolbarItem\n\t\t\t\t\t\t\t\tas={ Button }\n\t\t\t\t\t\t\t\tclassName=\"edit-site-header-toolbar__list-view-toggle\"\n\t\t\t\t\t\t\t\ticon={ listView }\n\t\t\t\t\t\t\t\tdisabled={ ! isVisualMode }\n\t\t\t\t\t\t\t\tisPressed={ isListViewOpen }\n\t\t\t\t\t\t\t\t/* translators: button label text should, if possible, be under 16 characters. */\n\t\t\t\t\t\t\t\tlabel={ __( 'List View' ) }\n\t\t\t\t\t\t\t\tonClick={ toggleListView }\n\t\t\t\t\t\t\t\tshortcut={ listViewShortcut }\n\t\t\t\t\t\t\t\tshowTooltip={ ! showIconLabels }\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</div>\n\t\t\t</NavigableToolbar>\n\n\t\t\t<div className=\"edit-site-header_center\">\n\t\t\t\t<DocumentActions\n\t\t\t\t\tentityTitle={ entityTitle }\n\t\t\t\t\tentityLabel={\n\t\t\t\t\t\ttemplateType === 'wp_template_part'\n\t\t\t\t\t\t\t? 'template part'\n\t\t\t\t\t\t\t: 'template'\n\t\t\t\t\t}\n\t\t\t\t\tisLoaded={ isLoaded }\n\t\t\t\t\tshowIconLabels={ showIconLabels }\n\t\t\t\t>\n\t\t\t\t\t{ ( { onClose } ) => (\n\t\t\t\t\t\t<TemplateDetails\n\t\t\t\t\t\t\ttemplate={ template }\n\t\t\t\t\t\t\tonClose={ onClose }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</DocumentActions>\n\t\t\t</div>\n\n\t\t\t<div className=\"edit-site-header_end\">\n\t\t\t\t<div className=\"edit-site-header__actions\">\n\t\t\t\t\t{ ! isFocusMode && (\n\t\t\t\t\t\t<PreviewOptions\n\t\t\t\t\t\t\tdeviceType={ deviceType }\n\t\t\t\t\t\t\tsetDeviceType={ setPreviewDeviceType }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t<SaveButton\n\t\t\t\t\t\topenEntitiesSavedStates={ openEntitiesSavedStates }\n\t\t\t\t\t\tisEntitiesSavedStatesOpen={ isEntitiesSavedStatesOpen }\n\t\t\t\t\t/>\n\t\t\t\t\t<PinnedItems.Slot scope=\"core/edit-site\" />\n\t\t\t\t\t<MoreMenu />\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/header/index.js"],"names":["preventDefault","event","Header","openEntitiesSavedStates","isEntitiesSavedStatesOpen","showIconLabels","inserterButton","deviceType","entityTitle","template","templateType","isInserterOpen","isListViewOpen","listViewShortcut","isLoaded","isVisualMode","select","__experimentalGetPreviewDeviceType","getEditedPostType","getEditedPostId","isInserterOpened","isListViewOpened","getEditorMode","editSiteStore","getEditedEntityRecord","coreStore","__experimentalGetTemplateInfo","getTemplateInfo","editorStore","getShortcutRepresentation","keyboardShortcutsStore","postType","postId","record","_isLoaded","title","__experimentalSetPreviewDeviceType","setPreviewDeviceType","setIsInserterOpened","setIsListViewOpened","isLargeViewport","openInserter","current","focus","toggleListView","isFocusMode","longLabel","shortLabel","Button","plus","ToolSelector","undefined","UndoButton","RedoButton","listView","onClose"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AA5BA;AACA;AACA;;AAiBA;AACA;AACA;AASA,MAAMA,cAAc,GAAKC,KAAF,IAAa;AACnCA,EAAAA,KAAK,CAACD,cAAN;AACA,CAFD;;AAIe,SAASE,MAAT,OAIX;AAAA,MAJ4B;AAC/BC,IAAAA,uBAD+B;AAE/BC,IAAAA,yBAF+B;AAG/BC,IAAAA;AAH+B,GAI5B;AACH,QAAMC,cAAc,GAAG,sBAAvB;AACA,QAAM;AACLC,IAAAA,UADK;AAELC,IAAAA,WAFK;AAGLC,IAAAA,QAHK;AAILC,IAAAA,YAJK;AAKLC,IAAAA,cALK;AAMLC,IAAAA,cANK;AAOLC,IAAAA,gBAPK;AAQLC,IAAAA,QARK;AASLC,IAAAA;AATK,MAUF,qBAAaC,MAAF,IAAc;AAC5B,UAAM;AACLC,MAAAA,kCADK;AAELC,MAAAA,iBAFK;AAGLC,MAAAA,eAHK;AAILC,MAAAA,gBAJK;AAKLC,MAAAA,gBALK;AAMLC,MAAAA;AANK,QAOFN,MAAM,CAAEO,YAAF,CAPV;AAQA,UAAM;AAAEC,MAAAA;AAAF,QAA4BR,MAAM,CAAES,eAAF,CAAxC;AACA,UAAM;AAAEC,MAAAA,6BAA6B,EAAEC;AAAjC,QACLX,MAAM,CAAEY,aAAF,CADP;AAEA,UAAM;AAAEC,MAAAA;AAAF,QAAgCb,MAAM,CAAEc,wBAAF,CAA5C;AAEA,UAAMC,QAAQ,GAAGb,iBAAiB,EAAlC;AACA,UAAMc,MAAM,GAAGb,eAAe,EAA9B;AACA,UAAMc,MAAM,GAAGT,qBAAqB,C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AA,SAAS,EAAC,4CAFX;AAGC,IAAA,IAAI,EAAGM,eAHR;AAIC,IAAA,QAAQ,EAAG,CAAEvC,YAJd;AAKC,IAAA,SAAS,EAAGH;AACZ;AAND;AAOC,IAAA,KAAK,EAAG,cAAI,WAAJ,CAPT;AAQC,IAAA,OAAO,EAAGgC,cARX;AASC,IAAA,QAAQ,EAAG/B,gBATZ;AAUC,IAAA,WAAW,EAAG,CAAER;AAVjB,IAvBD,CAfF,CAJD,CADD,EA4DC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,4BAAC,wBAAD;AACC,IAAA,WAAW,EAAGG,WADf;AAEC,IAAA,WAAW,EACVE,YAAY,KAAK,kBAAjB,GACG,eADH,GAEG,UALL;AAOC,IAAA,QAAQ,EAAGI,QAPZ;AAQC,IAAA,cAAc,EAAGT;AARlB,KAUG;AAAA,QAAE;AAAEkD,MAAAA;AAAF,KAAF;AAAA,WACD,4BAAC,wBAAD;AACC,MAAA,QAAQ,EAAG9C,QADZ;AAEC,MAAA,OAAO,EAAG8C;AAFX,MADC;AAAA,GAVH,CADD,CA5DD,EAgFC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC;AAAK,IAAA,SAAS,EAAC;AAAf,KACG,CAAEV,WAAF,IACD,4BAAC,yCAAD;AACC,IAAA,UAAU,EAAGtC,UADd;AAEC,IAAA,aAAa,EAAG8B;AAFjB,IAFF,EAOC,4BAAC,mBAAD;AACC,IAAA,uBAAuB,EAAGlC,uBAD3B;AAEC,IAAA,yBAAyB,EAAGC;AAF7B,IAPD,EAWC,4BAAC,sBAAD,CAAa,IAAb;AAAkB,IAAA,KAAK,EAAC;AAAxB,IAXD,EAYC,4BAAC,iBAAD,OAZD,CADD,CAhFD,CADD;AAmGA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback, useRef } from '@wordpress/element';\nimport { useViewportMatch } from '@wordpress/compose';\nimport {\n\tToolSelector,\n\t__experimentalPreviewOptions as PreviewOptions,\n\tNavigableToolbar,\n} from '@wordpress/block-editor';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { PinnedItems } from '@wordpress/interface';\nimport { _x, __ } from '@wordpress/i18n';\nimport { listView, plus } from '@wordpress/icons';\nimport { Button, ToolbarItem } from '@wordpress/components';\nimport { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\nimport { store as editorStore } from '@wordpress/editor';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport MoreMenu from './more-menu';\nimport SaveButton from '../save-button';\nimport UndoButton from './undo-redo/undo';\nimport RedoButton from './undo-redo/redo';\nimport DocumentActions from './document-actions';\nimport TemplateDetails from '../template-details';\nimport { store as editSiteStore } from '../../store';\n\nconst preventDefault = ( event ) => {\n\tevent.preventDefault();\n};\n\nexport default function Header( {\n\topenEntitiesSavedStates,\n\tisEntitiesSavedStatesOpen,\n\tshowIconLabels,\n} ) {\n\tconst inserterButton = useRef();\n\tconst {\n\t\tdeviceType,\n\t\tentityTitle,\n\t\ttemplate,\n\t\ttemplateType,\n\t\tisInserterOpen,\n\t\tisListViewOpen,\n\t\tlistViewShortcut,\n\t\tisLoaded,\n\t\tisVisualMode,\n\t} = useSelect( ( select ) => {\n\t\tconst {\n\t\t\t__experimentalGetPreviewDeviceType,\n\t\t\tgetEditedPostType,\n\t\t\tgetEditedPostId,\n\t\t\tisInserterOpened,\n\t\t\tisListViewOpened,\n\t\t\tgetEditorMode,\n\t\t} = select( editSiteStore );\n\t\tconst { getEditedEntityRecord } = select( coreStore );\n\t\tconst { __experimentalGetTemplateInfo: getTemplateInfo } =\n\t\t\tselect( editorStore );\n\t\tconst { getShortcutRepresentation } = select( keyboardShortcutsStore );\n\n\t\tconst postType = getEditedPostType();\n\t\tconst postId = getEditedPostId();\n\t\tconst record = getEditedEntityRecord( 'postType', postType, postId );\n\t\tconst _isLoaded = !! postId;\n\n\t\treturn {\n\t\t\tdeviceType: __experimentalGetPreviewDeviceType(),\n\t\t\tentityTitle: getTemplateInfo( record ).title,\n\t\t\tisLoaded: _isLoaded,\n\t\t\ttemplate: record,\n\t\t\ttemplateType: postType,\n\t\t\tisInserterOpen: isInserterOpened(),\n\t\t\tisListViewOpen: isListViewOpened(),\n\t\t\tlistViewShortcut: getShortcutRepresentation(\n\t\t\t\t'core/edit-site/toggle-list-view'\n\t\t\t),\n\t\t\tisVisualMode: getEditorMode() === 'visual',\n\t\t};\n\t}, [] );\n\n\tconst {\n\t\t__experimentalSetPreviewDeviceType: setPreviewDeviceType,\n\t\tsetIsInserterOpened,\n\t\tsetIsListViewOpened,\n\t} = useDispatch( editSiteStore );\n\n\tconst isLargeViewport = useViewportMatch( 'medium' );\n\n\tconst openInserter = useCallback( () => {\n\t\tif ( isInserterOpen ) {\n\t\t\t// Focusing the inserter button closes the inserter popover.\n\t\t\tinserterButton.current.focus();\n\t\t} else {\n\t\t\tsetIsInserterOpened( true );\n\t\t}\n\t}, [ isInserterOpen, setIsInserterOpened ] );\n\n\tconst toggleListView = useCallback(\n\t\t() => setIsListViewOpened( ! isListViewOpen ),\n\t\t[ setIsListViewOpened, isListViewOpen ]\n\t);\n\n\tconst isFocusMode = templateType === 'wp_template_part';\n\n\t/* translators: button label text should, if possible, be under 16 characters. */\n\tconst longLabel = _x(\n\t\t'Toggle block inserter',\n\t\t'Generic label for block inserter button'\n\t);\n\tconst shortLabel = ! isInserterOpen ? __( 'Add' ) : __( 'Close' );\n\n\treturn (\n\t\t<div className=\"edit-site-header\">\n\t\t\t<NavigableToolbar\n\t\t\t\tclassName=\"edit-site-header_start\"\n\t\t\t\taria-label={ __( 'Document tools' ) }\n\t\t\t>\n\t\t\t\t<div className=\"edit-site-header__toolbar\">\n\t\t\t\t\t<ToolbarItem\n\t\t\t\t\t\tref={ inserterButton }\n\t\t\t\t\t\tas={ Button }\n\t\t\t\t\t\tclassName=\"edit-site-header-toolbar__inserter-toggle\"\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\tisPressed={ isInserterOpen }\n\t\t\t\t\t\tonMouseDown={ preventDefault }\n\t\t\t\t\t\tonClick={ openInserter }\n\t\t\t\t\t\tdisabled={ ! isVisualMode }\n\t\t\t\t\t\ticon={ plus }\n\t\t\t\t\t\tlabel={ showIconLabels ? shortLabel : longLabel }\n\t\t\t\t\t\tshowTooltip={ ! showIconLabels }\n\t\t\t\t\t/>\n\t\t\t\t\t{ isLargeViewport && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<ToolbarItem\n\t\t\t\t\t\t\t\tas={ ToolSelector }\n\t\t\t\t\t\t\t\tshowTooltip={ ! showIconLabels }\n\t\t\t\t\t\t\t\tvariant={\n\t\t\t\t\t\t\t\t\tshowIconLabels ? 'tertiary' : undefined\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tdisabled={ ! isVisualMode }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<ToolbarItem\n\t\t\t\t\t\t\t\tas={ UndoButton }\n\t\t\t\t\t\t\t\tshowTooltip={ ! showIconLabels }\n\t\t\t\t\t\t\t\tvariant={\n\t\t\t\t\t\t\t\t\tshowIconLabels ? 'tertiary' : undefined\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<ToolbarItem\n\t\t\t\t\t\t\t\tas={ RedoButton }\n\t\t\t\t\t\t\t\tshowTooltip={ ! showIconLabels }\n\t\t\t\t\t\t\t\tvariant={\n\t\t\t\t\t\t\t\t\tshowIconLabels ? 'tertiary' : undefined\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<ToolbarItem\n\t\t\t\t\t\t\t\tas={ Button }\n\t\t\t\t\t\t\t\tclassName=\"edit-site-header-toolbar__list-view-toggle\"\n\t\t\t\t\t\t\t\ticon={ listView }\n\t\t\t\t\t\t\t\tdisabled={ ! isVisualMode }\n\t\t\t\t\t\t\t\tisPressed={ isListViewOpen }\n\t\t\t\t\t\t\t\t/* translators: button label text should, if possible, be under 16 characters. */\n\t\t\t\t\t\t\t\tlabel={ __( 'List View' ) }\n\t\t\t\t\t\t\t\tonClick={ toggleListView }\n\t\t\t\t\t\t\t\tshortcut={ listViewShortcut }\n\t\t\t\t\t\t\t\tshowTooltip={ ! showIconLabels }\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</div>\n\t\t\t</NavigableToolbar>\n\n\t\t\t<div className=\"edit-site-header_center\">\n\t\t\t\t<DocumentActions\n\t\t\t\t\tentityTitle={ entityTitle }\n\t\t\t\t\tentityLabel={\n\t\t\t\t\t\ttemplateType === 'wp_template_part'\n\t\t\t\t\t\t\t? 'template part'\n\t\t\t\t\t\t\t: 'template'\n\t\t\t\t\t}\n\t\t\t\t\tisLoaded={ isLoaded }\n\t\t\t\t\tshowIconLabels={ showIconLabels }\n\t\t\t\t>\n\t\t\t\t\t{ ( { onClose } ) => (\n\t\t\t\t\t\t<TemplateDetails\n\t\t\t\t\t\t\ttemplate={ template }\n\t\t\t\t\t\t\tonClose={ onClose }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</DocumentActions>\n\t\t\t</div>\n\n\t\t\t<div className=\"edit-site-header_end\">\n\t\t\t\t<div className=\"edit-site-header__actions\">\n\t\t\t\t\t{ ! isFocusMode && (\n\t\t\t\t\t\t<PreviewOptions\n\t\t\t\t\t\t\tdeviceType={ deviceType }\n\t\t\t\t\t\t\tsetDeviceType={ setPreviewDeviceType }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t<SaveButton\n\t\t\t\t\t\topenEntitiesSavedStates={ openEntitiesSavedStates }\n\t\t\t\t\t\tisEntitiesSavedStatesOpen={ isEntitiesSavedStatesOpen }\n\t\t\t\t\t/>\n\t\t\t\t\t<PinnedItems.Slot scope=\"core/edit-site\" />\n\t\t\t\t\t<MoreMenu />\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n"]}
|
package/build/hooks/index.js
CHANGED
package/build/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/hooks/index.js"],"names":[],"mappings":";;AAGA","sourcesContent":["/**\n * Internal dependencies\n */\nimport './components';\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/hooks/index.js"],"names":[],"mappings":";;AAGA;;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport './components';\nimport './template-part-edit';\n"]}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.withEditBlockControls = void 0;
|
|
9
|
+
|
|
10
|
+
var _element = require("@wordpress/element");
|
|
11
|
+
|
|
12
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
|
+
|
|
14
|
+
var _i18n = require("@wordpress/i18n");
|
|
15
|
+
|
|
16
|
+
var _data = require("@wordpress/data");
|
|
17
|
+
|
|
18
|
+
var _blockEditor = require("@wordpress/block-editor");
|
|
19
|
+
|
|
20
|
+
var _coreData = require("@wordpress/core-data");
|
|
21
|
+
|
|
22
|
+
var _components = require("@wordpress/components");
|
|
23
|
+
|
|
24
|
+
var _hooks = require("@wordpress/hooks");
|
|
25
|
+
|
|
26
|
+
var _compose = require("@wordpress/compose");
|
|
27
|
+
|
|
28
|
+
var _routes = require("../components/routes");
|
|
29
|
+
|
|
30
|
+
var _link = require("../components/routes/link");
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* WordPress dependencies
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Internal dependencies
|
|
38
|
+
*/
|
|
39
|
+
function EditTemplatePartMenuItem(_ref) {
|
|
40
|
+
let {
|
|
41
|
+
attributes
|
|
42
|
+
} = _ref;
|
|
43
|
+
const {
|
|
44
|
+
theme,
|
|
45
|
+
slug
|
|
46
|
+
} = attributes;
|
|
47
|
+
const {
|
|
48
|
+
params
|
|
49
|
+
} = (0, _routes.useLocation)();
|
|
50
|
+
const templatePart = (0, _data.useSelect)(select => {
|
|
51
|
+
return select(_coreData.store).getEntityRecord('postType', 'wp_template_part', // Ideally this should be an official public API.
|
|
52
|
+
`${theme}//${slug}`);
|
|
53
|
+
}, [theme, slug]);
|
|
54
|
+
const linkProps = (0, _link.useLink)({
|
|
55
|
+
postId: templatePart === null || templatePart === void 0 ? void 0 : templatePart.id,
|
|
56
|
+
postType: templatePart === null || templatePart === void 0 ? void 0 : templatePart.type
|
|
57
|
+
}, {
|
|
58
|
+
fromTemplateId: params.postId
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
if (!templatePart) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return (0, _element.createElement)(_blockEditor.BlockControls, {
|
|
66
|
+
group: "other"
|
|
67
|
+
}, (0, _element.createElement)(_components.ToolbarButton, (0, _extends2.default)({}, linkProps, {
|
|
68
|
+
onClick: event => {
|
|
69
|
+
linkProps.onClick(event);
|
|
70
|
+
}
|
|
71
|
+
}), (0, _i18n.__)('Edit')));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const withEditBlockControls = (0, _compose.createHigherOrderComponent)(BlockEdit => props => {
|
|
75
|
+
const {
|
|
76
|
+
attributes,
|
|
77
|
+
name
|
|
78
|
+
} = props;
|
|
79
|
+
const isDisplayed = name === 'core/template-part' && attributes.slug;
|
|
80
|
+
return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(BlockEdit, props), isDisplayed && (0, _element.createElement)(EditTemplatePartMenuItem, {
|
|
81
|
+
attributes: attributes
|
|
82
|
+
}));
|
|
83
|
+
}, 'withEditBlockControls');
|
|
84
|
+
exports.withEditBlockControls = withEditBlockControls;
|
|
85
|
+
(0, _hooks.addFilter)('editor.BlockEdit', 'core/edit-site/template-part-edit-button', withEditBlockControls);
|
|
86
|
+
//# sourceMappingURL=template-part-edit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/hooks/template-part-edit.js"],"names":["EditTemplatePartMenuItem","attributes","theme","slug","params","templatePart","select","coreStore","getEntityRecord","linkProps","postId","id","postType","type","fromTemplateId","event","onClick","withEditBlockControls","BlockEdit","props","name","isDisplayed"],"mappings":";;;;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAfA;AACA;AACA;;AASA;AACA;AACA;AAIA,SAASA,wBAAT,OAAoD;AAAA,MAAjB;AAAEC,IAAAA;AAAF,GAAiB;AACnD,QAAM;AAAEC,IAAAA,KAAF;AAASC,IAAAA;AAAT,MAAkBF,UAAxB;AACA,QAAM;AAAEG,IAAAA;AAAF,MAAa,0BAAnB;AACA,QAAMC,YAAY,GAAG,qBAClBC,MAAF,IAAc;AACb,WAAOA,MAAM,CAAEC,eAAF,CAAN,CAAoBC,eAApB,CACN,UADM,EAEN,kBAFM,EAGN;AACC,OAAGN,KAAO,KAAKC,IAAM,EAJhB,CAAP;AAMA,GARmB,EASpB,CAAED,KAAF,EAASC,IAAT,CAToB,CAArB;AAYA,QAAMM,SAAS,GAAG,mBACjB;AACCC,IAAAA,MAAM,EAAEL,YAAF,aAAEA,YAAF,uBAAEA,YAAY,CAAEM,EADvB;AAECC,IAAAA,QAAQ,EAAEP,YAAF,aAAEA,YAAF,uBAAEA,YAAY,CAAEQ;AAFzB,GADiB,EAKjB;AACCC,IAAAA,cAAc,EAAEV,MAAM,CAACM;AADxB,GALiB,CAAlB;;AAUA,MAAK,CAAEL,YAAP,EAAsB;AACrB,WAAO,IAAP;AACA;;AAED,SACC,4BAAC,0BAAD;AAAe,IAAA,KAAK,EAAC;AAArB,KACC,4BAAC,yBAAD,6BACMI,SADN;AAEC,IAAA,OAAO,EAAKM,KAAF,IAAa;AACtBN,MAAAA,SAAS,CAACO,OAAV,CAAmBD,KAAnB;AACA;AAJF,MAMG,cAAI,MAAJ,CANH,CADD,CADD;AAYA;;AAEM,MAAME,qBAAqB,GAAG,yCAClCC,SAAF,IAAmBC,KAAF,IAAa;AAC7B,QAAM;AAAElB,IAAAA,UAAF;AAAcmB,IAAAA;AAAd,MAAuBD,KAA7B;AACA,QAAME,WAAW,GAAGD,IAAI,KAAK,oBAAT,IAAiCnB,UAAU,CAACE,IAAhE;AAEA,SACC,qDACC,4BAAC,SAAD,EAAgBgB,KAAhB,CADD,EAEGE,WAAW,IACZ,4BAAC,wBAAD;AAA0B,IAAA,UAAU,EAAGpB;AAAvC,IAHF,CADD;AAQA,CAbmC,EAcpC,uBAdoC,CAA9B;;AAiBP,sBACC,kBADD,EAEC,0CAFD,EAGCgB,qBAHD","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport { BlockControls } from '@wordpress/block-editor';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { ToolbarButton } from '@wordpress/components';\nimport { addFilter } from '@wordpress/hooks';\nimport { createHigherOrderComponent } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { useLocation } from '../components/routes';\nimport { useLink } from '../components/routes/link';\n\nfunction EditTemplatePartMenuItem( { attributes } ) {\n\tconst { theme, slug } = attributes;\n\tconst { params } = useLocation();\n\tconst templatePart = useSelect(\n\t\t( select ) => {\n\t\t\treturn select( coreStore ).getEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template_part',\n\t\t\t\t// Ideally this should be an official public API.\n\t\t\t\t`${ theme }//${ slug }`\n\t\t\t);\n\t\t},\n\t\t[ theme, slug ]\n\t);\n\n\tconst linkProps = useLink(\n\t\t{\n\t\t\tpostId: templatePart?.id,\n\t\t\tpostType: templatePart?.type,\n\t\t},\n\t\t{\n\t\t\tfromTemplateId: params.postId,\n\t\t}\n\t);\n\n\tif ( ! templatePart ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<BlockControls group=\"other\">\n\t\t\t<ToolbarButton\n\t\t\t\t{ ...linkProps }\n\t\t\t\tonClick={ ( event ) => {\n\t\t\t\t\tlinkProps.onClick( event );\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ __( 'Edit' ) }\n\t\t\t</ToolbarButton>\n\t\t</BlockControls>\n\t);\n}\n\nexport const withEditBlockControls = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst { attributes, name } = props;\n\t\tconst isDisplayed = name === 'core/template-part' && attributes.slug;\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<BlockEdit { ...props } />\n\t\t\t\t{ isDisplayed && (\n\t\t\t\t\t<EditTemplatePartMenuItem attributes={ attributes } />\n\t\t\t\t) }\n\t\t\t</>\n\t\t);\n\t},\n\t'withEditBlockControls'\n);\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/edit-site/template-part-edit-button',\n\twithEditBlockControls\n);\n"]}
|
|
@@ -6,7 +6,7 @@ import { createElement, Fragment } from "@wordpress/element";
|
|
|
6
6
|
*/
|
|
7
7
|
import { useState, useMemo, useEffect } from '@wordpress/element';
|
|
8
8
|
import { __, sprintf } from '@wordpress/i18n';
|
|
9
|
-
import { Button, Flex, FlexItem, Modal, SearchControl, TextHighlight, __experimentalText as Text,
|
|
9
|
+
import { Button, Flex, FlexItem, Modal, SearchControl, TextHighlight, __experimentalText as Text, __unstableComposite as Composite, __unstableUseCompositeState as useCompositeState, __unstableCompositeItem as CompositeItem } from '@wordpress/components';
|
|
10
10
|
import { useDebounce } from '@wordpress/compose';
|
|
11
11
|
import { useEntityRecords } from '@wordpress/core-data';
|
|
12
12
|
/**
|
|
@@ -16,32 +16,6 @@ import { useEntityRecords } from '@wordpress/core-data';
|
|
|
16
16
|
import { mapToIHasNameAndId } from './utils';
|
|
17
17
|
const EMPTY_ARRAY = [];
|
|
18
18
|
|
|
19
|
-
function selectSuggestion(suggestion, onSelect, entityForSuggestions) {
|
|
20
|
-
const {
|
|
21
|
-
labels,
|
|
22
|
-
slug,
|
|
23
|
-
config: {
|
|
24
|
-
templateSlug,
|
|
25
|
-
templatePrefix
|
|
26
|
-
}
|
|
27
|
-
} = entityForSuggestions;
|
|
28
|
-
const title = sprintf( // translators: Represents the title of a user's custom template in the Site Editor, where %1$s is the singular name of a post type or taxonomy and %2$s is the name of the post or term, e.g. "Post: Hello, WordPress", "Category: shoes"
|
|
29
|
-
__('%1$s: %2$s'), labels.singular_name, suggestion.name);
|
|
30
|
-
let newTemplateSlug = `${templateSlug || slug}-${suggestion.slug}`;
|
|
31
|
-
|
|
32
|
-
if (templatePrefix) {
|
|
33
|
-
newTemplateSlug = templatePrefix + newTemplateSlug;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const newTemplate = {
|
|
37
|
-
title,
|
|
38
|
-
description: sprintf( // translators: Represents the description of a user's custom template in the Site Editor, e.g. "Template for Post: Hello, WordPress"
|
|
39
|
-
__('Template for %1$s'), title),
|
|
40
|
-
slug: newTemplateSlug
|
|
41
|
-
};
|
|
42
|
-
onSelect(newTemplate);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
19
|
function SuggestionListItem(_ref) {
|
|
46
20
|
let {
|
|
47
21
|
suggestion,
|
|
@@ -56,7 +30,7 @@ function SuggestionListItem(_ref) {
|
|
|
56
30
|
as: Button
|
|
57
31
|
}, composite, {
|
|
58
32
|
className: baseCssClass,
|
|
59
|
-
onClick: () =>
|
|
33
|
+
onClick: () => onSelect(entityForSuggestions.config.getSpecificTemplate(suggestion))
|
|
60
34
|
}), createElement("span", {
|
|
61
35
|
className: `${baseCssClass}__title`
|
|
62
36
|
}, createElement(TextHighlight, {
|
|
@@ -81,20 +55,15 @@ function useDebouncedInput() {
|
|
|
81
55
|
|
|
82
56
|
function useSearchSuggestions(entityForSuggestions, search) {
|
|
83
57
|
const {
|
|
84
|
-
config
|
|
85
|
-
postsToExclude
|
|
58
|
+
config
|
|
86
59
|
} = entityForSuggestions;
|
|
87
60
|
const query = useMemo(() => ({
|
|
88
61
|
order: 'asc',
|
|
89
|
-
_fields: 'id,name,title,slug,link',
|
|
90
62
|
context: 'view',
|
|
91
63
|
search,
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
exclude: postsToExclude,
|
|
96
|
-
per_page: search ? 20 : 10
|
|
97
|
-
}), [search, config, postsToExclude]);
|
|
64
|
+
per_page: search ? 20 : 10,
|
|
65
|
+
...config.queryArgs(search)
|
|
66
|
+
}), [search, config]);
|
|
98
67
|
const {
|
|
99
68
|
records: searchResults,
|
|
100
69
|
hasResolved: searchHasResolved
|
|
@@ -132,14 +101,21 @@ function SuggestionList(_ref2) {
|
|
|
132
101
|
const {
|
|
133
102
|
labels
|
|
134
103
|
} = entityForSuggestions;
|
|
135
|
-
|
|
104
|
+
const [showSearchControl, setShowSearchControl] = useState(false);
|
|
105
|
+
|
|
106
|
+
if (!showSearchControl && (suggestions === null || suggestions === void 0 ? void 0 : suggestions.length) > 9) {
|
|
107
|
+
setShowSearchControl(true);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return createElement(Fragment, null, showSearchControl && createElement(SearchControl, {
|
|
136
111
|
onChange: setSearch,
|
|
137
112
|
value: search,
|
|
138
113
|
label: labels.search_items,
|
|
139
114
|
placeholder: labels.search_items
|
|
140
115
|
}), !!(suggestions !== null && suggestions !== void 0 && suggestions.length) && createElement(Composite, _extends({}, composite, {
|
|
141
116
|
role: "listbox",
|
|
142
|
-
className: "edit-site-custom-template-modal__suggestions_list"
|
|
117
|
+
className: "edit-site-custom-template-modal__suggestions_list",
|
|
118
|
+
"aria-label": __('Suggestions list')
|
|
143
119
|
}), suggestions.map(suggestion => createElement(SuggestionListItem, {
|
|
144
120
|
key: suggestion.slug,
|
|
145
121
|
suggestion: suggestion,
|
|
@@ -172,6 +148,7 @@ function AddCustomTemplateModal(_ref3) {
|
|
|
172
148
|
align: "initial"
|
|
173
149
|
}, createElement(FlexItem, {
|
|
174
150
|
isBlock: true,
|
|
151
|
+
as: Button,
|
|
175
152
|
onClick: () => {
|
|
176
153
|
const {
|
|
177
154
|
slug,
|
|
@@ -184,18 +161,21 @@ function AddCustomTemplateModal(_ref3) {
|
|
|
184
161
|
description
|
|
185
162
|
});
|
|
186
163
|
}
|
|
187
|
-
}, createElement(
|
|
188
|
-
|
|
164
|
+
}, createElement(Text, {
|
|
165
|
+
as: "span",
|
|
166
|
+
weight: 600
|
|
189
167
|
}, entityForSuggestions.labels.all_items), createElement(Text, {
|
|
190
168
|
as: "span"
|
|
191
169
|
}, // translators: The user is given the choice to set up a template for all items of a post type or taxonomy, or just a specific one.
|
|
192
170
|
__('For all items'))), createElement(FlexItem, {
|
|
193
171
|
isBlock: true,
|
|
172
|
+
as: Button,
|
|
194
173
|
onClick: () => {
|
|
195
174
|
setShowSearchEntities(true);
|
|
196
175
|
}
|
|
197
|
-
}, createElement(
|
|
198
|
-
|
|
176
|
+
}, createElement(Text, {
|
|
177
|
+
as: "span",
|
|
178
|
+
weight: 600
|
|
199
179
|
}, entityForSuggestions.labels.singular_name), createElement(Text, {
|
|
200
180
|
as: "span"
|
|
201
181
|
}, // translators: The user is given the choice to set up a template for all items of a post type or taxonomy, or just a specific one.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/add-custom-template-modal.js"],"names":["useState","useMemo","useEffect","__","sprintf","Button","Flex","FlexItem","Modal","SearchControl","TextHighlight","__experimentalText","Text","__experimentalHeading","Heading","__unstableComposite","Composite","__unstableUseCompositeState","useCompositeState","__unstableCompositeItem","CompositeItem","useDebounce","useEntityRecords","mapToIHasNameAndId","EMPTY_ARRAY","selectSuggestion","suggestion","onSelect","entityForSuggestions","labels","slug","config","templateSlug","templatePrefix","title","singular_name","name","newTemplateSlug","newTemplate","description","SuggestionListItem","search","composite","baseCssClass","link","useDebouncedInput","input","setInput","debounced","setter","setDebounced","useSearchSuggestions","postsToExclude","query","order","_fields","context","orderBy","getOrderBy","exclude","per_page","records","searchResults","hasResolved","searchHasResolved","type","suggestions","setSuggestions","newSuggestions","length","recordNamePath","SuggestionList","orientation","setSearch","debouncedSearch","search_items","map","not_found","AddCustomTemplateModal","onClose","showSearchEntities","setShowSearchEntities","hasGeneralTemplate","template","all_items"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,QAAT,EAAmBC,OAAnB,EAA4BC,SAA5B,QAA6C,oBAA7C;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SACCC,MADD,EAECC,IAFD,EAGCC,QAHD,EAICC,KAJD,EAKCC,aALD,EAMCC,aAND,EAOCC,kBAAkB,IAAIC,IAPvB,EAQCC,qBAAqB,IAAIC,OAR1B,EASCC,mBAAmB,IAAIC,SATxB,EAUCC,2BAA2B,IAAIC,iBAVhC,EAWCC,uBAAuB,IAAIC,aAX5B,QAYO,uBAZP;AAaA,SAASC,WAAT,QAA4B,oBAA5B;AACA,SAASC,gBAAT,QAAiC,sBAAjC;AAEA;AACA;AACA;;AACA,SAASC,kBAAT,QAAmC,SAAnC;AAEA,MAAMC,WAAW,GAAG,EAApB;;AAEA,SAASC,gBAAT,CAA2BC,UAA3B,EAAuCC,QAAvC,EAAiDC,oBAAjD,EAAwE;AACvE,QAAM;AACLC,IAAAA,MADK;AAELC,IAAAA,IAFK;AAGLC,IAAAA,MAAM,EAAE;AAAEC,MAAAA,YAAF;AAAgBC,MAAAA;AAAhB;AAHH,MAIFL,oBAJJ;AAKA,QAAMM,KAAK,GAAG9B,OAAO,EACpB;AACAD,EAAAA,EAAE,CAAE,YAAF,CAFkB,EAGpB0B,MAAM,CAACM,aAHa,EAIpBT,UAAU,CAACU,IAJS,CAArB;AAMA,MAAIC,eAAe,GAAI,GAAGL,YAAY,IAAIF,IAAM,IAAIJ,UAAU,CAACI,IAAM,EAArE;;AACA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AAR;AACA;AANF,KAQC,cAAC,OAAD;AAAS,IAAA,KAAK,EAAG;AAAjB,KACGX,oBAAoB,CAACC,MAArB,CAA4BuD,SAD/B,CARD,EAWC,cAAC,IAAD;AAAM,IAAA,EAAE,EAAC;AAAT,KAEE;AACAjF,EAAAA,EAAE,CAAE,eAAF,CAHJ,CAXD,CALD,EAuBC,cAAC,QAAD;AACC,IAAA,OAAO,MADR;AAEC,IAAA,OAAO,EAAG,MAAM;AACf8E,MAAAA,qBAAqB,CAAE,IAAF,CAArB;AACA;AAJF,KAMC,cAAC,OAAD;AAAS,IAAA,KAAK,EAAG;AAAjB,KACGrD,oBAAoB,CAACC,MAArB,CAA4BM,aAD/B,CAND,EASC,cAAC,IAAD;AAAM,IAAA,EAAE,EAAC;AAAT,KAEE;AACAhC,EAAAA,EAAE,CAAE,qBAAF,CAHJ,CATD,CAvBD,CAND,CAXF,EA2DG6E,kBAAkB,IACnB,8BACC,yBACG7E,EAAE,CACH,+DADG,CADL,CADD,EAMC,cAAC,cAAD;AACC,IAAA,oBAAoB,EAAGyB,oBADxB;AAEC,IAAA,QAAQ,EAAGD;AAFZ,IAND,CA5DF,CADD;AA2EA;;AAED,eAAemD,sBAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useMemo, useEffect } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tButton,\n\tFlex,\n\tFlexItem,\n\tModal,\n\tSearchControl,\n\tTextHighlight,\n\t__experimentalText as Text,\n\t__experimentalHeading as Heading,\n\t__unstableComposite as Composite,\n\t__unstableUseCompositeState as useCompositeState,\n\t__unstableCompositeItem as CompositeItem,\n} from '@wordpress/components';\nimport { useDebounce } from '@wordpress/compose';\nimport { useEntityRecords } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { mapToIHasNameAndId } from './utils';\n\nconst EMPTY_ARRAY = [];\n\nfunction selectSuggestion( suggestion, onSelect, entityForSuggestions ) {\n\tconst {\n\t\tlabels,\n\t\tslug,\n\t\tconfig: { templateSlug, templatePrefix },\n\t} = entityForSuggestions;\n\tconst title = sprintf(\n\t\t// translators: Represents the title of a user's custom template in the Site Editor, where %1$s is the singular name of a post type or taxonomy and %2$s is the name of the post or term, e.g. \"Post: Hello, WordPress\", \"Category: shoes\"\n\t\t__( '%1$s: %2$s' ),\n\t\tlabels.singular_name,\n\t\tsuggestion.name\n\t);\n\tlet newTemplateSlug = `${ templateSlug || slug }-${ suggestion.slug }`;\n\tif ( templatePrefix ) {\n\t\tnewTemplateSlug = templatePrefix + newTemplateSlug;\n\t}\n\tconst newTemplate = {\n\t\ttitle,\n\t\tdescription: sprintf(\n\t\t\t// translators: Represents the description of a user's custom template in the Site Editor, e.g. \"Template for Post: Hello, WordPress\"\n\t\t\t__( 'Template for %1$s' ),\n\t\t\ttitle\n\t\t),\n\t\tslug: newTemplateSlug,\n\t};\n\tonSelect( newTemplate );\n}\n\nfunction SuggestionListItem( {\n\tsuggestion,\n\tsearch,\n\tonSelect,\n\tentityForSuggestions,\n\tcomposite,\n} ) {\n\tconst baseCssClass =\n\t\t'edit-site-custom-template-modal__suggestions_list__list-item';\n\treturn (\n\t\t<CompositeItem\n\t\t\trole=\"option\"\n\t\t\tas={ Button }\n\t\t\t{ ...composite }\n\t\t\tclassName={ baseCssClass }\n\t\t\tonClick={ () =>\n\t\t\t\tselectSuggestion( suggestion, onSelect, entityForSuggestions )\n\t\t\t}\n\t\t>\n\t\t\t<span className={ `${ baseCssClass }__title` }>\n\t\t\t\t<TextHighlight text={ suggestion.name } highlight={ search } />\n\t\t\t</span>\n\t\t\t{ suggestion.link && (\n\t\t\t\t<span className={ `${ baseCssClass }__info` }>\n\t\t\t\t\t{ suggestion.link }\n\t\t\t\t</span>\n\t\t\t) }\n\t\t</CompositeItem>\n\t);\n}\n\nfunction useDebouncedInput() {\n\tconst [ input, setInput ] = useState( '' );\n\tconst [ debounced, setter ] = useState( '' );\n\tconst setDebounced = useDebounce( setter, 250 );\n\tuseEffect( () => {\n\t\tif ( debounced !== input ) {\n\t\t\tsetDebounced( input );\n\t\t}\n\t}, [ debounced, input ] );\n\treturn [ input, setInput, debounced ];\n}\n\nfunction useSearchSuggestions( entityForSuggestions, search ) {\n\tconst { config, postsToExclude } = entityForSuggestions;\n\tconst query = useMemo(\n\t\t() => ( {\n\t\t\torder: 'asc',\n\t\t\t_fields: 'id,name,title,slug,link',\n\t\t\tcontext: 'view',\n\t\t\tsearch,\n\t\t\torderBy: config.getOrderBy( { search } ),\n\t\t\texclude: postsToExclude,\n\t\t\tper_page: search ? 20 : 10,\n\t\t} ),\n\t\t[ search, config, postsToExclude ]\n\t);\n\tconst { records: searchResults, hasResolved: searchHasResolved } =\n\t\tuseEntityRecords(\n\t\t\tentityForSuggestions.type,\n\t\t\tentityForSuggestions.slug,\n\t\t\tquery\n\t\t);\n\tconst [ suggestions, setSuggestions ] = useState( EMPTY_ARRAY );\n\tuseEffect( () => {\n\t\tif ( ! searchHasResolved ) return;\n\t\tlet newSuggestions = EMPTY_ARRAY;\n\t\tif ( searchResults?.length ) {\n\t\t\tnewSuggestions = searchResults;\n\t\t\tif ( config.recordNamePath ) {\n\t\t\t\tnewSuggestions = mapToIHasNameAndId(\n\t\t\t\t\tnewSuggestions,\n\t\t\t\t\tconfig.recordNamePath\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\t// Update suggestions only when the query has resolved, so as to keep\n\t\t// the previous results in the UI.\n\t\tsetSuggestions( newSuggestions );\n\t}, [ searchResults, searchHasResolved ] );\n\treturn suggestions;\n}\n\nfunction SuggestionList( { entityForSuggestions, onSelect } ) {\n\tconst composite = useCompositeState( { orientation: 'vertical' } );\n\tconst [ search, setSearch, debouncedSearch ] = useDebouncedInput();\n\tconst suggestions = useSearchSuggestions(\n\t\tentityForSuggestions,\n\t\tdebouncedSearch\n\t);\n\tconst { labels } = entityForSuggestions;\n\treturn (\n\t\t<>\n\t\t\t<SearchControl\n\t\t\t\tonChange={ setSearch }\n\t\t\t\tvalue={ search }\n\t\t\t\tlabel={ labels.search_items }\n\t\t\t\tplaceholder={ labels.search_items }\n\t\t\t/>\n\t\t\t{ !! suggestions?.length && (\n\t\t\t\t<Composite\n\t\t\t\t\t{ ...composite }\n\t\t\t\t\trole=\"listbox\"\n\t\t\t\t\tclassName=\"edit-site-custom-template-modal__suggestions_list\"\n\t\t\t\t>\n\t\t\t\t\t{ suggestions.map( ( suggestion ) => (\n\t\t\t\t\t\t<SuggestionListItem\n\t\t\t\t\t\t\tkey={ suggestion.slug }\n\t\t\t\t\t\t\tsuggestion={ suggestion }\n\t\t\t\t\t\t\tsearch={ debouncedSearch }\n\t\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t\t\t\tcomposite={ composite }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) ) }\n\t\t\t\t</Composite>\n\t\t\t) }\n\t\t\t{ debouncedSearch && ! suggestions?.length && (\n\t\t\t\t<p className=\"edit-site-custom-template-modal__no-results\">\n\t\t\t\t\t{ labels.not_found }\n\t\t\t\t</p>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction AddCustomTemplateModal( { onClose, onSelect, entityForSuggestions } ) {\n\tconst [ showSearchEntities, setShowSearchEntities ] = useState(\n\t\tentityForSuggestions.hasGeneralTemplate\n\t);\n\tconst baseCssClass = 'edit-site-custom-template-modal';\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ sprintf(\n\t\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t\t__( 'Add template: %s' ),\n\t\t\t\tentityForSuggestions.labels.singular_name\n\t\t\t) }\n\t\t\tclassName={ baseCssClass }\n\t\t\tcloseLabel={ __( 'Close' ) }\n\t\t\tonRequestClose={ onClose }\n\t\t>\n\t\t\t{ ! showSearchEntities && (\n\t\t\t\t<>\n\t\t\t\t\t<p>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'Select whether to create a single template for all items or a specific one.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t\t<Flex\n\t\t\t\t\t\tclassName={ `${ baseCssClass }__contents` }\n\t\t\t\t\t\tgap=\"4\"\n\t\t\t\t\t\talign=\"initial\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<FlexItem\n\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tconst { slug, title, description } =\n\t\t\t\t\t\t\t\t\tentityForSuggestions.template;\n\t\t\t\t\t\t\t\tonSelect( { slug, title, description } );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Heading level={ 5 }>\n\t\t\t\t\t\t\t\t{ entityForSuggestions.labels.all_items }\n\t\t\t\t\t\t\t</Heading>\n\t\t\t\t\t\t\t<Text as=\"span\">\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// translators: The user is given the choice to set up a template for all items of a post type or taxonomy, or just a specific one.\n\t\t\t\t\t\t\t\t\t__( 'For all items' )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t<FlexItem\n\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tsetShowSearchEntities( true );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Heading level={ 5 }>\n\t\t\t\t\t\t\t\t{ entityForSuggestions.labels.singular_name }\n\t\t\t\t\t\t\t</Heading>\n\t\t\t\t\t\t\t<Text as=\"span\">\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// translators: The user is given the choice to set up a template for all items of a post type or taxonomy, or just a specific one.\n\t\t\t\t\t\t\t\t\t__( 'For a specific item' )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t</Flex>\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t{ showSearchEntities && (\n\t\t\t\t<>\n\t\t\t\t\t<p>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'This template will be used only for the specific item chosen.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t\t<SuggestionList\n\t\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t/>\n\t\t\t\t</>\n\t\t\t) }\n\t\t</Modal>\n\t);\n}\n\nexport default AddCustomTemplateModal;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/add-custom-template-modal.js"],"names":["useState","useMemo","useEffect","__","sprintf","Button","Flex","FlexItem","Modal","SearchControl","TextHighlight","__experimentalText","Text","__unstableComposite","Composite","__unstableUseCompositeState","useCompositeState","__unstableCompositeItem","CompositeItem","useDebounce","useEntityRecords","mapToIHasNameAndId","EMPTY_ARRAY","SuggestionListItem","suggestion","search","onSelect","entityForSuggestions","composite","baseCssClass","config","getSpecificTemplate","name","link","useDebouncedInput","input","setInput","debounced","setter","setDebounced","useSearchSuggestions","query","order","context","per_page","queryArgs","records","searchResults","hasResolved","searchHasResolved","type","slug","suggestions","setSuggestions","newSuggestions","length","recordNamePath","SuggestionList","orientation","setSearch","debouncedSearch","labels","showSearchControl","setShowSearchControl","search_items","map","not_found","AddCustomTemplateModal","onClose","showSearchEntities","setShowSearchEntities","hasGeneralTemplate","singular_name","title","description","template","all_items"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,QAAT,EAAmBC,OAAnB,EAA4BC,SAA5B,QAA6C,oBAA7C;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SACCC,MADD,EAECC,IAFD,EAGCC,QAHD,EAICC,KAJD,EAKCC,aALD,EAMCC,aAND,EAOCC,kBAAkB,IAAIC,IAPvB,EAQCC,mBAAmB,IAAIC,SARxB,EASC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AACgD,QADtB;AAEAjD,MAAAA,QAAQ,CAAE;AAAEyB,QAAAA,IAAF;AAAQsB,QAAAA,KAAR;AAAeC,QAAAA;AAAf,OAAF,CAAR;AACA;AAPF,KASC,cAAC,IAAD;AAAM,IAAA,EAAE,EAAC,MAAT;AAAgB,IAAA,MAAM,EAAG;AAAzB,KACG/C,oBAAoB,CAACkC,MAArB,CAA4Be,SAD/B,CATD,EAYC,cAAC,IAAD;AAAM,IAAA,EAAE,EAAC;AAAT,KAEE;AACAzE,EAAAA,EAAE,CAAE,eAAF,CAHJ,CAZD,CALD,EAwBC,cAAC,QAAD;AACC,IAAA,OAAO,MADR;AAEC,IAAA,EAAE,EAAGE,MAFN;AAGC,IAAA,OAAO,EAAG,MAAM;AACfiE,MAAAA,qBAAqB,CAAE,IAAF,CAArB;AACA;AALF,KAOC,cAAC,IAAD;AAAM,IAAA,EAAE,EAAC,MAAT;AAAgB,IAAA,MAAM,EAAG;AAAzB,KACG3C,oBAAoB,CAACkC,MAArB,CAA4BW,aAD/B,CAPD,EAUC,cAAC,IAAD;AAAM,IAAA,EAAE,EAAC;AAAT,KAEE;AACArE,EAAAA,EAAE,CAAE,qBAAF,CAHJ,CAVD,CAxBD,CAND,CAXF,EA6DGkE,kBAAkB,IACnB,8BACC,yBACGlE,EAAE,CACH,+DADG,CADL,CADD,EAMC,cAAC,cAAD;AACC,IAAA,oBAAoB,EAAGwB,oBADxB;AAEC,IAAA,QAAQ,EAAGD;AAFZ,IAND,CA9DF,CADD;AA6EA;;AAED,eAAeyC,sBAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useMemo, useEffect } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tButton,\n\tFlex,\n\tFlexItem,\n\tModal,\n\tSearchControl,\n\tTextHighlight,\n\t__experimentalText as Text,\n\t__unstableComposite as Composite,\n\t__unstableUseCompositeState as useCompositeState,\n\t__unstableCompositeItem as CompositeItem,\n} from '@wordpress/components';\nimport { useDebounce } from '@wordpress/compose';\nimport { useEntityRecords } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { mapToIHasNameAndId } from './utils';\n\nconst EMPTY_ARRAY = [];\n\nfunction SuggestionListItem( {\n\tsuggestion,\n\tsearch,\n\tonSelect,\n\tentityForSuggestions,\n\tcomposite,\n} ) {\n\tconst baseCssClass =\n\t\t'edit-site-custom-template-modal__suggestions_list__list-item';\n\treturn (\n\t\t<CompositeItem\n\t\t\trole=\"option\"\n\t\t\tas={ Button }\n\t\t\t{ ...composite }\n\t\t\tclassName={ baseCssClass }\n\t\t\tonClick={ () =>\n\t\t\t\tonSelect(\n\t\t\t\t\tentityForSuggestions.config.getSpecificTemplate(\n\t\t\t\t\t\tsuggestion\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t}\n\t\t>\n\t\t\t<span className={ `${ baseCssClass }__title` }>\n\t\t\t\t<TextHighlight text={ suggestion.name } highlight={ search } />\n\t\t\t</span>\n\t\t\t{ suggestion.link && (\n\t\t\t\t<span className={ `${ baseCssClass }__info` }>\n\t\t\t\t\t{ suggestion.link }\n\t\t\t\t</span>\n\t\t\t) }\n\t\t</CompositeItem>\n\t);\n}\n\nfunction useDebouncedInput() {\n\tconst [ input, setInput ] = useState( '' );\n\tconst [ debounced, setter ] = useState( '' );\n\tconst setDebounced = useDebounce( setter, 250 );\n\tuseEffect( () => {\n\t\tif ( debounced !== input ) {\n\t\t\tsetDebounced( input );\n\t\t}\n\t}, [ debounced, input ] );\n\treturn [ input, setInput, debounced ];\n}\n\nfunction useSearchSuggestions( entityForSuggestions, search ) {\n\tconst { config } = entityForSuggestions;\n\tconst query = useMemo(\n\t\t() => ( {\n\t\t\torder: 'asc',\n\t\t\tcontext: 'view',\n\t\t\tsearch,\n\t\t\tper_page: search ? 20 : 10,\n\t\t\t...config.queryArgs( search ),\n\t\t} ),\n\t\t[ search, config ]\n\t);\n\tconst { records: searchResults, hasResolved: searchHasResolved } =\n\t\tuseEntityRecords(\n\t\t\tentityForSuggestions.type,\n\t\t\tentityForSuggestions.slug,\n\t\t\tquery\n\t\t);\n\tconst [ suggestions, setSuggestions ] = useState( EMPTY_ARRAY );\n\tuseEffect( () => {\n\t\tif ( ! searchHasResolved ) return;\n\t\tlet newSuggestions = EMPTY_ARRAY;\n\t\tif ( searchResults?.length ) {\n\t\t\tnewSuggestions = searchResults;\n\t\t\tif ( config.recordNamePath ) {\n\t\t\t\tnewSuggestions = mapToIHasNameAndId(\n\t\t\t\t\tnewSuggestions,\n\t\t\t\t\tconfig.recordNamePath\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\t// Update suggestions only when the query has resolved, so as to keep\n\t\t// the previous results in the UI.\n\t\tsetSuggestions( newSuggestions );\n\t}, [ searchResults, searchHasResolved ] );\n\treturn suggestions;\n}\n\nfunction SuggestionList( { entityForSuggestions, onSelect } ) {\n\tconst composite = useCompositeState( { orientation: 'vertical' } );\n\tconst [ search, setSearch, debouncedSearch ] = useDebouncedInput();\n\tconst suggestions = useSearchSuggestions(\n\t\tentityForSuggestions,\n\t\tdebouncedSearch\n\t);\n\tconst { labels } = entityForSuggestions;\n\tconst [ showSearchControl, setShowSearchControl ] = useState( false );\n\tif ( ! showSearchControl && suggestions?.length > 9 ) {\n\t\tsetShowSearchControl( true );\n\t}\n\treturn (\n\t\t<>\n\t\t\t{ showSearchControl && (\n\t\t\t\t<SearchControl\n\t\t\t\t\tonChange={ setSearch }\n\t\t\t\t\tvalue={ search }\n\t\t\t\t\tlabel={ labels.search_items }\n\t\t\t\t\tplaceholder={ labels.search_items }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ !! suggestions?.length && (\n\t\t\t\t<Composite\n\t\t\t\t\t{ ...composite }\n\t\t\t\t\trole=\"listbox\"\n\t\t\t\t\tclassName=\"edit-site-custom-template-modal__suggestions_list\"\n\t\t\t\t\taria-label={ __( 'Suggestions list' ) }\n\t\t\t\t>\n\t\t\t\t\t{ suggestions.map( ( suggestion ) => (\n\t\t\t\t\t\t<SuggestionListItem\n\t\t\t\t\t\t\tkey={ suggestion.slug }\n\t\t\t\t\t\t\tsuggestion={ suggestion }\n\t\t\t\t\t\t\tsearch={ debouncedSearch }\n\t\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t\t\t\tcomposite={ composite }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) ) }\n\t\t\t\t</Composite>\n\t\t\t) }\n\t\t\t{ debouncedSearch && ! suggestions?.length && (\n\t\t\t\t<p className=\"edit-site-custom-template-modal__no-results\">\n\t\t\t\t\t{ labels.not_found }\n\t\t\t\t</p>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction AddCustomTemplateModal( { onClose, onSelect, entityForSuggestions } ) {\n\tconst [ showSearchEntities, setShowSearchEntities ] = useState(\n\t\tentityForSuggestions.hasGeneralTemplate\n\t);\n\tconst baseCssClass = 'edit-site-custom-template-modal';\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ sprintf(\n\t\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t\t__( 'Add template: %s' ),\n\t\t\t\tentityForSuggestions.labels.singular_name\n\t\t\t) }\n\t\t\tclassName={ baseCssClass }\n\t\t\tcloseLabel={ __( 'Close' ) }\n\t\t\tonRequestClose={ onClose }\n\t\t>\n\t\t\t{ ! showSearchEntities && (\n\t\t\t\t<>\n\t\t\t\t\t<p>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'Select whether to create a single template for all items or a specific one.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t\t<Flex\n\t\t\t\t\t\tclassName={ `${ baseCssClass }__contents` }\n\t\t\t\t\t\tgap=\"4\"\n\t\t\t\t\t\talign=\"initial\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<FlexItem\n\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\tas={ Button }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tconst { slug, title, description } =\n\t\t\t\t\t\t\t\t\tentityForSuggestions.template;\n\t\t\t\t\t\t\t\tonSelect( { slug, title, description } );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Text as=\"span\" weight={ 600 }>\n\t\t\t\t\t\t\t\t{ entityForSuggestions.labels.all_items }\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t\t<Text as=\"span\">\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// translators: The user is given the choice to set up a template for all items of a post type or taxonomy, or just a specific one.\n\t\t\t\t\t\t\t\t\t__( 'For all items' )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t<FlexItem\n\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\tas={ Button }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tsetShowSearchEntities( true );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Text as=\"span\" weight={ 600 }>\n\t\t\t\t\t\t\t\t{ entityForSuggestions.labels.singular_name }\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t\t<Text as=\"span\">\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// translators: The user is given the choice to set up a template for all items of a post type or taxonomy, or just a specific one.\n\t\t\t\t\t\t\t\t\t__( 'For a specific item' )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t</Flex>\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t{ showSearchEntities && (\n\t\t\t\t<>\n\t\t\t\t\t<p>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'This template will be used only for the specific item chosen.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t\t<SuggestionList\n\t\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t/>\n\t\t\t\t</>\n\t\t\t) }\n\t\t</Modal>\n\t);\n}\n\nexport default AddCustomTemplateModal;\n"]}
|
|
@@ -15,7 +15,7 @@ import { store as noticesStore } from '@wordpress/notices';
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import AddCustomTemplateModal from './add-custom-template-modal';
|
|
18
|
-
import { useExistingTemplates, useDefaultTemplateTypes,
|
|
18
|
+
import { useExistingTemplates, useDefaultTemplateTypes, useTaxonomiesMenuItems, usePostTypeMenuItems } from './utils';
|
|
19
19
|
import AddCustomGenericTemplateModal from './add-custom-generic-template-modal';
|
|
20
20
|
import { useHistory } from '../routes';
|
|
21
21
|
import { store as editSiteStore } from '../../store';
|
|
@@ -141,11 +141,6 @@ export default function NewTemplate(_ref) {
|
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
function useMissingTemplates(setEntityForSuggestions, setShowCustomTemplateModal) {
|
|
144
|
-
const postTypes = usePostTypes();
|
|
145
|
-
const pagePostType = usePostTypePage();
|
|
146
|
-
const taxonomies = useTaxonomies();
|
|
147
|
-
const categoryTaxonomy = useTaxonomyCategory();
|
|
148
|
-
const tagTaxonomy = useTaxonomyTag();
|
|
149
144
|
const existingTemplates = useExistingTemplates();
|
|
150
145
|
const defaultTemplateTypes = useDefaultTemplateTypes();
|
|
151
146
|
const existingTemplateSlugs = (existingTemplates || []).map(_ref2 => {
|
|
@@ -159,41 +154,43 @@ function useMissingTemplates(setEntityForSuggestions, setShowCustomTemplateModal
|
|
|
159
154
|
const onClickMenuItem = _entityForSuggestions => {
|
|
160
155
|
setShowCustomTemplateModal(true);
|
|
161
156
|
setEntityForSuggestions(_entityForSuggestions);
|
|
162
|
-
}; //
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const categoryMenuItem = useExtraTemplates(categoryTaxonomy, entitiesConfig.category, onClickMenuItem);
|
|
166
|
-
const tagMenuItem = useExtraTemplates(tagTaxonomy, entitiesConfig.tag, onClickMenuItem);
|
|
167
|
-
const pageMenuItem = useExtraTemplates(pagePostType, entitiesConfig.page, onClickMenuItem); // We need to replace existing default template types with
|
|
157
|
+
}; // We need to replace existing default template types with
|
|
168
158
|
// the create specific template functionality. The original
|
|
169
159
|
// info (title, description, etc.) is preserved in the
|
|
170
|
-
//
|
|
160
|
+
// used hooks.
|
|
161
|
+
|
|
171
162
|
|
|
172
163
|
const enhancedMissingDefaultTemplateTypes = [...missingDefaultTemplates];
|
|
173
|
-
|
|
174
|
-
|
|
164
|
+
const {
|
|
165
|
+
defaultTaxonomiesMenuItems,
|
|
166
|
+
taxonomiesMenuItems
|
|
167
|
+
} = useTaxonomiesMenuItems(onClickMenuItem);
|
|
168
|
+
const {
|
|
169
|
+
defaultPostTypesMenuItems,
|
|
170
|
+
postTypesMenuItems
|
|
171
|
+
} = usePostTypeMenuItems(onClickMenuItem);
|
|
172
|
+
[...defaultTaxonomiesMenuItems, ...defaultPostTypesMenuItems].forEach(menuItem => {
|
|
173
|
+
if (!menuItem) {
|
|
175
174
|
return;
|
|
176
175
|
}
|
|
177
176
|
|
|
178
|
-
const matchIndex = enhancedMissingDefaultTemplateTypes.findIndex(template => template.slug === menuItem
|
|
177
|
+
const matchIndex = enhancedMissingDefaultTemplateTypes.findIndex(template => template.slug === menuItem.slug); // Some default template types might have been filtered above from
|
|
179
178
|
// `missingDefaultTemplates` because they only check for the general
|
|
180
179
|
// template. So here we either replace or append the item, augmented
|
|
181
180
|
// with the check if it has available specific item to create a
|
|
182
181
|
// template for.
|
|
183
182
|
|
|
184
183
|
if (matchIndex > -1) {
|
|
185
|
-
enhancedMissingDefaultTemplateTypes
|
|
184
|
+
enhancedMissingDefaultTemplateTypes[matchIndex] = menuItem;
|
|
186
185
|
} else {
|
|
187
|
-
enhancedMissingDefaultTemplateTypes.push(menuItem
|
|
186
|
+
enhancedMissingDefaultTemplateTypes.push(menuItem);
|
|
188
187
|
}
|
|
189
188
|
}); // Update the sort order to match the DEFAULT_TEMPLATE_SLUGS order.
|
|
190
189
|
|
|
191
190
|
enhancedMissingDefaultTemplateTypes === null || enhancedMissingDefaultTemplateTypes === void 0 ? void 0 : enhancedMissingDefaultTemplateTypes.sort((template1, template2) => {
|
|
192
191
|
return DEFAULT_TEMPLATE_SLUGS.indexOf(template1.slug) - DEFAULT_TEMPLATE_SLUGS.indexOf(template2.slug);
|
|
193
192
|
});
|
|
194
|
-
const
|
|
195
|
-
const extraTaxonomyTemplates = useExtraTemplates(taxonomies, entitiesConfig.taxonomy, onClickMenuItem);
|
|
196
|
-
const missingTemplates = [...enhancedMissingDefaultTemplateTypes, ...extraPostTypeTemplates, ...extraTaxonomyTemplates];
|
|
193
|
+
const missingTemplates = [...enhancedMissingDefaultTemplateTypes, ...postTypesMenuItems, ...taxonomiesMenuItems];
|
|
197
194
|
return missingTemplates;
|
|
198
195
|
}
|
|
199
196
|
//# sourceMappingURL=new-template.js.map
|