@wordpress/edit-site 5.27.1 → 5.27.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/build/components/block-editor/back-button.js +2 -3
  2. package/build/components/block-editor/back-button.js.map +1 -1
  3. package/build/components/block-editor/site-editor-canvas.js +8 -2
  4. package/build/components/block-editor/site-editor-canvas.js.map +1 -1
  5. package/build/components/block-editor/use-post-link-props.js +5 -1
  6. package/build/components/block-editor/use-post-link-props.js.map +1 -1
  7. package/build/components/editor/index.js +7 -7
  8. package/build/components/editor/index.js.map +1 -1
  9. package/build/components/global-styles/font-library-modal/context.js +14 -0
  10. package/build/components/global-styles/font-library-modal/context.js.map +1 -1
  11. package/build/components/global-styles/font-library-modal/font-collection.js +17 -33
  12. package/build/components/global-styles/font-library-modal/font-collection.js.map +1 -1
  13. package/build/components/global-styles/font-library-modal/font-demo.js +1 -1
  14. package/build/components/global-styles/font-library-modal/font-demo.js.map +1 -1
  15. package/build/components/global-styles/font-library-modal/google-fonts-confirm-dialog.js +1 -1
  16. package/build/components/global-styles/font-library-modal/google-fonts-confirm-dialog.js.map +1 -1
  17. package/build/components/global-styles/font-library-modal/index.js +10 -3
  18. package/build/components/global-styles/font-library-modal/index.js.map +1 -1
  19. package/build/components/global-styles/font-library-modal/installed-fonts.js +8 -21
  20. package/build/components/global-styles/font-library-modal/installed-fonts.js.map +1 -1
  21. package/build/components/global-styles/font-library-modal/library-font-variant.js +2 -2
  22. package/build/components/global-styles/font-library-modal/library-font-variant.js.map +1 -1
  23. package/build/components/global-styles/font-library-modal/resolvers.js +1 -1
  24. package/build/components/global-styles/font-library-modal/resolvers.js.map +1 -1
  25. package/build/components/global-styles/font-library-modal/tab-panel-layout.js +9 -1
  26. package/build/components/global-styles/font-library-modal/tab-panel-layout.js.map +1 -1
  27. package/build/components/global-styles/font-library-modal/upload-fonts.js +160 -4
  28. package/build/components/global-styles/font-library-modal/upload-fonts.js.map +1 -1
  29. package/build/components/global-styles/font-library-modal/utils/index.js +33 -31
  30. package/build/components/global-styles/font-library-modal/utils/index.js.map +1 -1
  31. package/build/components/routes/link.js +1 -1
  32. package/build/components/routes/link.js.map +1 -1
  33. package/build/components/sidebar-edit-mode/index.js +1 -2
  34. package/build/components/sidebar-edit-mode/index.js.map +1 -1
  35. package/build/components/sidebar-edit-mode/settings-header/index.js +7 -36
  36. package/build/components/sidebar-edit-mode/settings-header/index.js.map +1 -1
  37. package/build/components/welcome-guide/template.js +2 -2
  38. package/build/components/welcome-guide/template.js.map +1 -1
  39. package/build/hooks/commands/use-edit-mode-commands.js +16 -6
  40. package/build/hooks/commands/use-edit-mode-commands.js.map +1 -1
  41. package/build-module/components/block-editor/back-button.js +2 -3
  42. package/build-module/components/block-editor/back-button.js.map +1 -1
  43. package/build-module/components/block-editor/site-editor-canvas.js +8 -2
  44. package/build-module/components/block-editor/site-editor-canvas.js.map +1 -1
  45. package/build-module/components/block-editor/use-post-link-props.js +5 -1
  46. package/build-module/components/block-editor/use-post-link-props.js.map +1 -1
  47. package/build-module/components/editor/index.js +7 -7
  48. package/build-module/components/editor/index.js.map +1 -1
  49. package/build-module/components/global-styles/font-library-modal/context.js +14 -0
  50. package/build-module/components/global-styles/font-library-modal/context.js.map +1 -1
  51. package/build-module/components/global-styles/font-library-modal/font-collection.js +19 -35
  52. package/build-module/components/global-styles/font-library-modal/font-collection.js.map +1 -1
  53. package/build-module/components/global-styles/font-library-modal/font-demo.js +1 -1
  54. package/build-module/components/global-styles/font-library-modal/font-demo.js.map +1 -1
  55. package/build-module/components/global-styles/font-library-modal/google-fonts-confirm-dialog.js +1 -1
  56. package/build-module/components/global-styles/font-library-modal/google-fonts-confirm-dialog.js.map +1 -1
  57. package/build-module/components/global-styles/font-library-modal/index.js +10 -3
  58. package/build-module/components/global-styles/font-library-modal/index.js.map +1 -1
  59. package/build-module/components/global-styles/font-library-modal/installed-fonts.js +9 -22
  60. package/build-module/components/global-styles/font-library-modal/installed-fonts.js.map +1 -1
  61. package/build-module/components/global-styles/font-library-modal/library-font-variant.js +2 -2
  62. package/build-module/components/global-styles/font-library-modal/library-font-variant.js.map +1 -1
  63. package/build-module/components/global-styles/font-library-modal/resolvers.js +1 -1
  64. package/build-module/components/global-styles/font-library-modal/resolvers.js.map +1 -1
  65. package/build-module/components/global-styles/font-library-modal/tab-panel-layout.js +10 -2
  66. package/build-module/components/global-styles/font-library-modal/tab-panel-layout.js.map +1 -1
  67. package/build-module/components/global-styles/font-library-modal/upload-fonts.js +162 -6
  68. package/build-module/components/global-styles/font-library-modal/upload-fonts.js.map +1 -1
  69. package/build-module/components/global-styles/font-library-modal/utils/index.js +32 -30
  70. package/build-module/components/global-styles/font-library-modal/utils/index.js.map +1 -1
  71. package/build-module/components/routes/link.js +1 -1
  72. package/build-module/components/routes/link.js.map +1 -1
  73. package/build-module/components/sidebar-edit-mode/index.js +1 -2
  74. package/build-module/components/sidebar-edit-mode/index.js.map +1 -1
  75. package/build-module/components/sidebar-edit-mode/settings-header/index.js +7 -36
  76. package/build-module/components/sidebar-edit-mode/settings-header/index.js.map +1 -1
  77. package/build-module/components/welcome-guide/template.js +2 -2
  78. package/build-module/components/welcome-guide/template.js.map +1 -1
  79. package/build-module/hooks/commands/use-edit-mode-commands.js +16 -6
  80. package/build-module/hooks/commands/use-edit-mode-commands.js.map +1 -1
  81. package/build-style/style-rtl.css +4 -6
  82. package/build-style/style.css +4 -6
  83. package/package.json +11 -11
  84. package/src/components/block-editor/back-button.js +6 -3
  85. package/src/components/block-editor/site-editor-canvas.js +19 -12
  86. package/src/components/block-editor/use-post-link-props.js +5 -1
  87. package/src/components/editor/index.js +4 -9
  88. package/src/components/global-styles/font-library-modal/context.js +14 -0
  89. package/src/components/global-styles/font-library-modal/font-collection.js +16 -40
  90. package/src/components/global-styles/font-library-modal/font-demo.js +1 -1
  91. package/src/components/global-styles/font-library-modal/google-fonts-confirm-dialog.js +1 -1
  92. package/src/components/global-styles/font-library-modal/index.js +8 -3
  93. package/src/components/global-styles/font-library-modal/installed-fonts.js +12 -31
  94. package/src/components/global-styles/font-library-modal/library-font-variant.js +2 -2
  95. package/src/components/global-styles/font-library-modal/resolvers.js +1 -1
  96. package/src/components/global-styles/font-library-modal/style.scss +0 -10
  97. package/src/components/global-styles/font-library-modal/tab-panel-layout.js +15 -0
  98. package/src/components/global-styles/font-library-modal/upload-fonts.js +201 -6
  99. package/src/components/global-styles/font-library-modal/utils/index.js +44 -38
  100. package/src/components/routes/link.js +1 -1
  101. package/src/components/sidebar-edit-mode/index.js +1 -4
  102. package/src/components/sidebar-edit-mode/settings-header/index.js +12 -34
  103. package/src/components/welcome-guide/template.js +2 -2
  104. package/src/hooks/commands/use-edit-mode-commands.js +26 -14
  105. package/build/components/global-styles/font-library-modal/local-fonts.js +0 -196
  106. package/build/components/global-styles/font-library-modal/local-fonts.js.map +0 -1
  107. package/build-module/components/global-styles/font-library-modal/local-fonts.js +0 -187
  108. package/build-module/components/global-styles/font-library-modal/local-fonts.js.map +0 -1
  109. package/src/components/global-styles/font-library-modal/local-fonts.js +0 -239
@@ -6,8 +6,16 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = void 0;
8
8
  var _react = require("react");
9
+ var _i18n = require("@wordpress/i18n");
9
10
  var _components = require("@wordpress/components");
10
- var _localFonts = _interopRequireDefault(require("./local-fonts"));
11
+ var _element = require("@wordpress/element");
12
+ var _constants = require("./utils/constants");
13
+ var _context = require("./context");
14
+ var _libFont = require("../../../../lib/lib-font.browser");
15
+ var _makeFamiliesFromFaces = _interopRequireDefault(require("./utils/make-families-from-faces"));
16
+ var _utils = require("./utils");
17
+ var _tabPanelLayout = _interopRequireDefault(require("./tab-panel-layout"));
18
+ var _lockUnlock = require("../../../lock-unlock");
11
19
  /**
12
20
  * WordPress dependencies
13
21
  */
@@ -16,10 +24,158 @@ var _localFonts = _interopRequireDefault(require("./local-fonts"));
16
24
  * Internal dependencies
17
25
  */
18
26
 
27
+ const {
28
+ ProgressBar
29
+ } = (0, _lockUnlock.unlock)(_components.privateApis);
19
30
  function UploadFonts() {
20
- return (0, _react.createElement)(_react.Fragment, null, (0, _react.createElement)(_components.__experimentalSpacer, {
21
- margin: 8
22
- }), (0, _react.createElement)(_localFonts.default, null));
31
+ const {
32
+ installFont,
33
+ notice,
34
+ setNotice
35
+ } = (0, _element.useContext)(_context.FontLibraryContext);
36
+ const [isUploading, setIsUploading] = (0, _element.useState)(false);
37
+ const supportedFormats = _constants.ALLOWED_FILE_EXTENSIONS.slice(0, -1).map(extension => `.${extension}`).join(', ') + ` ${(0, _i18n.__)('and')} .${_constants.ALLOWED_FILE_EXTENSIONS.slice(-1)}`;
38
+ const handleDropZone = files => {
39
+ handleFilesUpload(files);
40
+ };
41
+ const onFilesUpload = event => {
42
+ handleFilesUpload(event.target.files);
43
+ };
44
+
45
+ /**
46
+ * Filters the selected files to only allow the ones with the allowed extensions
47
+ *
48
+ * @param {Array} files The files to be filtered
49
+ * @return {void}
50
+ */
51
+ const handleFilesUpload = files => {
52
+ setNotice(null);
53
+ setIsUploading(true);
54
+ const uniqueFilenames = new Set();
55
+ const selectedFiles = [...files];
56
+ const allowedFiles = selectedFiles.filter(file => {
57
+ if (uniqueFilenames.has(file.name)) {
58
+ return false; // Discard duplicates
59
+ }
60
+ // Eliminates files that are not allowed
61
+ const fileExtension = file.name.split('.').pop().toLowerCase();
62
+ if (_constants.ALLOWED_FILE_EXTENSIONS.includes(fileExtension)) {
63
+ uniqueFilenames.add(file.name);
64
+ return true; // Keep file if the extension is allowed
65
+ }
66
+
67
+ return false; // Discard file extension not allowed
68
+ });
69
+
70
+ if (allowedFiles.length > 0) {
71
+ loadFiles(allowedFiles);
72
+ }
73
+ };
74
+
75
+ /**
76
+ * Loads the selected files and reads the font metadata
77
+ *
78
+ * @param {Array} files The files to be loaded
79
+ * @return {void}
80
+ */
81
+ const loadFiles = async files => {
82
+ const fontFacesLoaded = await Promise.all(files.map(async fontFile => {
83
+ const fontFaceData = await getFontFaceMetadata(fontFile);
84
+ await (0, _utils.loadFontFaceInBrowser)(fontFaceData, fontFaceData.file, 'all');
85
+ return fontFaceData;
86
+ }));
87
+ handleInstall(fontFacesLoaded);
88
+ };
89
+
90
+ // Create a function to read the file as array buffer
91
+ async function readFileAsArrayBuffer(file) {
92
+ return new Promise((resolve, reject) => {
93
+ const reader = new window.FileReader();
94
+ reader.readAsArrayBuffer(file);
95
+ reader.onload = () => resolve(reader.result);
96
+ reader.onerror = reject;
97
+ });
98
+ }
99
+ const getFontFaceMetadata = async fontFile => {
100
+ const buffer = await readFileAsArrayBuffer(fontFile);
101
+ const fontObj = new _libFont.Font('Uploaded Font');
102
+ fontObj.fromDataBuffer(buffer, fontFile.name);
103
+ // Assuming that fromDataBuffer triggers onload event and returning a Promise
104
+ const onloadEvent = await new Promise(resolve => fontObj.onload = resolve);
105
+ const font = onloadEvent.detail.font;
106
+ const {
107
+ name
108
+ } = font.opentype.tables;
109
+ const fontName = name.get(16) || name.get(1);
110
+ const isItalic = name.get(2).toLowerCase().includes('italic');
111
+ const fontWeight = font.opentype.tables['OS/2'].usWeightClass || 'normal';
112
+ const isVariable = !!font.opentype.tables.fvar;
113
+ const weightAxis = isVariable && font.opentype.tables.fvar.axes.find(({
114
+ tag
115
+ }) => tag === 'wght');
116
+ const weightRange = weightAxis ? `${weightAxis.minValue} ${weightAxis.maxValue}` : null;
117
+ return {
118
+ file: fontFile,
119
+ fontFamily: fontName,
120
+ fontStyle: isItalic ? 'italic' : 'normal',
121
+ fontWeight: weightRange || fontWeight
122
+ };
123
+ };
124
+
125
+ /**
126
+ * Creates the font family definition and sends it to the server
127
+ *
128
+ * @param {Array} fontFaces The font faces to be installed
129
+ * @return {void}
130
+ */
131
+ const handleInstall = async fontFaces => {
132
+ const fontFamilies = (0, _makeFamiliesFromFaces.default)(fontFaces);
133
+ if (fontFamilies.length > 1) {
134
+ setNotice({
135
+ type: 'error',
136
+ message: (0, _i18n.__)('Variants from only one font family can be uploaded at a time.')
137
+ });
138
+ setIsUploading(false);
139
+ return;
140
+ }
141
+ try {
142
+ await installFont(fontFamilies[0]);
143
+ setNotice({
144
+ type: 'success',
145
+ message: (0, _i18n.__)('Fonts were installed successfully.')
146
+ });
147
+ } catch (error) {
148
+ setNotice({
149
+ type: 'error',
150
+ message: error.message
151
+ });
152
+ }
153
+ setIsUploading(false);
154
+ };
155
+ return (0, _react.createElement)(_tabPanelLayout.default, {
156
+ notice: notice
157
+ }, (0, _react.createElement)(_components.DropZone, {
158
+ onFilesDrop: handleDropZone
159
+ }), (0, _react.createElement)(_components.__experimentalVStack, {
160
+ className: "font-library-modal__local-fonts"
161
+ }, isUploading && (0, _react.createElement)(_components.FlexItem, null, (0, _react.createElement)("div", {
162
+ className: "font-library-modal__upload-area"
163
+ }, (0, _react.createElement)(ProgressBar, null))), !isUploading && (0, _react.createElement)(_components.FormFileUpload, {
164
+ accept: _constants.ALLOWED_FILE_EXTENSIONS.map(ext => `.${ext}`).join(','),
165
+ multiple: true,
166
+ onChange: onFilesUpload,
167
+ render: ({
168
+ openFileDialog
169
+ }) => (0, _react.createElement)(_components.Button, {
170
+ className: "font-library-modal__upload-area",
171
+ onClick: openFileDialog
172
+ }, (0, _react.createElement)("span", null, (0, _i18n.__)('Upload font')))
173
+ }), (0, _react.createElement)(_components.__experimentalSpacer, {
174
+ margin: 2
175
+ }), (0, _react.createElement)(_components.__experimentalText, {
176
+ className: "font-library-modal__upload-area__text"
177
+ }, (0, _i18n.sprintf)( /* translators: %s: supported font formats: ex: .ttf, .woff and .woff2 */
178
+ (0, _i18n.__)('Uploaded fonts appear in your library and can be used in your theme. Supported formats: %s.'), supportedFormats))));
23
179
  }
24
180
  var _default = UploadFonts;
25
181
  exports.default = _default;
@@ -1 +1 @@
1
- {"version":3,"names":["_components","require","_localFonts","_interopRequireDefault","UploadFonts","_react","createElement","Fragment","__experimentalSpacer","margin","default","_default","exports"],"sources":["@wordpress/edit-site/src/components/global-styles/font-library-modal/upload-fonts.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __experimentalSpacer as Spacer } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport LocalFonts from './local-fonts';\n\nfunction UploadFonts() {\n\treturn (\n\t\t<>\n\t\t\t<Spacer margin={ 8 } />\n\t\t\t<LocalFonts />\n\t\t</>\n\t);\n}\n\nexport default UploadFonts;\n"],"mappings":";;;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAKA,IAAAC,WAAA,GAAAC,sBAAA,CAAAF,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA,SAASG,WAAWA,CAAA,EAAG;EACtB,OACC,IAAAC,MAAA,CAAAC,aAAA,EAAAD,MAAA,CAAAE,QAAA,QACC,IAAAF,MAAA,CAAAC,aAAA,EAACN,WAAA,CAAAQ,oBAAM;IAACC,MAAM,EAAG;EAAG,CAAE,CAAC,EACvB,IAAAJ,MAAA,CAAAC,aAAA,EAACJ,WAAA,CAAAQ,OAAU,MAAE,CACZ,CAAC;AAEL;AAAC,IAAAC,QAAA,GAEcP,WAAW;AAAAQ,OAAA,CAAAF,OAAA,GAAAC,QAAA"}
1
+ {"version":3,"names":["_i18n","require","_components","_element","_constants","_context","_libFont","_makeFamiliesFromFaces","_interopRequireDefault","_utils","_tabPanelLayout","_lockUnlock","ProgressBar","unlock","componentsPrivateApis","UploadFonts","installFont","notice","setNotice","useContext","FontLibraryContext","isUploading","setIsUploading","useState","supportedFormats","ALLOWED_FILE_EXTENSIONS","slice","map","extension","join","__","handleDropZone","files","handleFilesUpload","onFilesUpload","event","target","uniqueFilenames","Set","selectedFiles","allowedFiles","filter","file","has","name","fileExtension","split","pop","toLowerCase","includes","add","length","loadFiles","fontFacesLoaded","Promise","all","fontFile","fontFaceData","getFontFaceMetadata","loadFontFaceInBrowser","handleInstall","readFileAsArrayBuffer","resolve","reject","reader","window","FileReader","readAsArrayBuffer","onload","result","onerror","buffer","fontObj","Font","fromDataBuffer","onloadEvent","font","detail","opentype","tables","fontName","get","isItalic","fontWeight","usWeightClass","isVariable","fvar","weightAxis","axes","find","tag","weightRange","minValue","maxValue","fontFamily","fontStyle","fontFaces","fontFamilies","makeFamiliesFromFaces","type","message","error","_react","createElement","default","DropZone","onFilesDrop","__experimentalVStack","className","FlexItem","FormFileUpload","accept","ext","multiple","onChange","render","openFileDialog","Button","onClick","__experimentalSpacer","margin","__experimentalText","sprintf","_default","exports"],"sources":["@wordpress/edit-site/src/components/global-styles/font-library-modal/upload-fonts.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tButton,\n\tDropZone,\n\t__experimentalSpacer as Spacer,\n\t__experimentalText as Text,\n\t__experimentalVStack as VStack,\n\tFormFileUpload,\n\tFlexItem,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { useContext, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { ALLOWED_FILE_EXTENSIONS } from './utils/constants';\nimport { FontLibraryContext } from './context';\nimport { Font } from '../../../../lib/lib-font.browser';\nimport makeFamiliesFromFaces from './utils/make-families-from-faces';\nimport { loadFontFaceInBrowser } from './utils';\nimport TabPanelLayout from './tab-panel-layout';\nimport { unlock } from '../../../lock-unlock';\n\nconst { ProgressBar } = unlock( componentsPrivateApis );\n\nfunction UploadFonts() {\n\tconst { installFont, notice, setNotice } = useContext( FontLibraryContext );\n\tconst [ isUploading, setIsUploading ] = useState( false );\n\tconst supportedFormats =\n\t\tALLOWED_FILE_EXTENSIONS.slice( 0, -1 )\n\t\t\t.map( ( extension ) => `.${ extension }` )\n\t\t\t.join( ', ' ) +\n\t\t` ${ __( 'and' ) } .${ ALLOWED_FILE_EXTENSIONS.slice( -1 ) }`;\n\n\tconst handleDropZone = ( files ) => {\n\t\thandleFilesUpload( files );\n\t};\n\tconst onFilesUpload = ( event ) => {\n\t\thandleFilesUpload( event.target.files );\n\t};\n\n\t/**\n\t * Filters the selected files to only allow the ones with the allowed extensions\n\t *\n\t * @param {Array} files The files to be filtered\n\t * @return {void}\n\t */\n\tconst handleFilesUpload = ( files ) => {\n\t\tsetNotice( null );\n\t\tsetIsUploading( true );\n\t\tconst uniqueFilenames = new Set();\n\t\tconst selectedFiles = [ ...files ];\n\t\tconst allowedFiles = selectedFiles.filter( ( file ) => {\n\t\t\tif ( uniqueFilenames.has( file.name ) ) {\n\t\t\t\treturn false; // Discard duplicates\n\t\t\t}\n\t\t\t// Eliminates files that are not allowed\n\t\t\tconst fileExtension = file.name.split( '.' ).pop().toLowerCase();\n\t\t\tif ( ALLOWED_FILE_EXTENSIONS.includes( fileExtension ) ) {\n\t\t\t\tuniqueFilenames.add( file.name );\n\t\t\t\treturn true; // Keep file if the extension is allowed\n\t\t\t}\n\t\t\treturn false; // Discard file extension not allowed\n\t\t} );\n\t\tif ( allowedFiles.length > 0 ) {\n\t\t\tloadFiles( allowedFiles );\n\t\t}\n\t};\n\n\t/**\n\t * Loads the selected files and reads the font metadata\n\t *\n\t * @param {Array} files The files to be loaded\n\t * @return {void}\n\t */\n\tconst loadFiles = async ( files ) => {\n\t\tconst fontFacesLoaded = await Promise.all(\n\t\t\tfiles.map( async ( fontFile ) => {\n\t\t\t\tconst fontFaceData = await getFontFaceMetadata( fontFile );\n\t\t\t\tawait loadFontFaceInBrowser(\n\t\t\t\t\tfontFaceData,\n\t\t\t\t\tfontFaceData.file,\n\t\t\t\t\t'all'\n\t\t\t\t);\n\t\t\t\treturn fontFaceData;\n\t\t\t} )\n\t\t);\n\t\thandleInstall( fontFacesLoaded );\n\t};\n\n\t// Create a function to read the file as array buffer\n\tasync function readFileAsArrayBuffer( file ) {\n\t\treturn new Promise( ( resolve, reject ) => {\n\t\t\tconst reader = new window.FileReader();\n\t\t\treader.readAsArrayBuffer( file );\n\t\t\treader.onload = () => resolve( reader.result );\n\t\t\treader.onerror = reject;\n\t\t} );\n\t}\n\n\tconst getFontFaceMetadata = async ( fontFile ) => {\n\t\tconst buffer = await readFileAsArrayBuffer( fontFile );\n\t\tconst fontObj = new Font( 'Uploaded Font' );\n\t\tfontObj.fromDataBuffer( buffer, fontFile.name );\n\t\t// Assuming that fromDataBuffer triggers onload event and returning a Promise\n\t\tconst onloadEvent = await new Promise(\n\t\t\t( resolve ) => ( fontObj.onload = resolve )\n\t\t);\n\t\tconst font = onloadEvent.detail.font;\n\t\tconst { name } = font.opentype.tables;\n\t\tconst fontName = name.get( 16 ) || name.get( 1 );\n\t\tconst isItalic = name.get( 2 ).toLowerCase().includes( 'italic' );\n\t\tconst fontWeight =\n\t\t\tfont.opentype.tables[ 'OS/2' ].usWeightClass || 'normal';\n\t\tconst isVariable = !! font.opentype.tables.fvar;\n\t\tconst weightAxis =\n\t\t\tisVariable &&\n\t\t\tfont.opentype.tables.fvar.axes.find(\n\t\t\t\t( { tag } ) => tag === 'wght'\n\t\t\t);\n\t\tconst weightRange = weightAxis\n\t\t\t? `${ weightAxis.minValue } ${ weightAxis.maxValue }`\n\t\t\t: null;\n\t\treturn {\n\t\t\tfile: fontFile,\n\t\t\tfontFamily: fontName,\n\t\t\tfontStyle: isItalic ? 'italic' : 'normal',\n\t\t\tfontWeight: weightRange || fontWeight,\n\t\t};\n\t};\n\n\t/**\n\t * Creates the font family definition and sends it to the server\n\t *\n\t * @param {Array} fontFaces The font faces to be installed\n\t * @return {void}\n\t */\n\tconst handleInstall = async ( fontFaces ) => {\n\t\tconst fontFamilies = makeFamiliesFromFaces( fontFaces );\n\n\t\tif ( fontFamilies.length > 1 ) {\n\t\t\tsetNotice( {\n\t\t\t\ttype: 'error',\n\t\t\t\tmessage: __(\n\t\t\t\t\t'Variants from only one font family can be uploaded at a time.'\n\t\t\t\t),\n\t\t\t} );\n\t\t\tsetIsUploading( false );\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tawait installFont( fontFamilies[ 0 ] );\n\t\t\tsetNotice( {\n\t\t\t\ttype: 'success',\n\t\t\t\tmessage: __( 'Fonts were installed successfully.' ),\n\t\t\t} );\n\t\t} catch ( error ) {\n\t\t\tsetNotice( {\n\t\t\t\ttype: 'error',\n\t\t\t\tmessage: error.message,\n\t\t\t} );\n\t\t}\n\n\t\tsetIsUploading( false );\n\t};\n\n\treturn (\n\t\t<TabPanelLayout notice={ notice }>\n\t\t\t<DropZone onFilesDrop={ handleDropZone } />\n\t\t\t<VStack className=\"font-library-modal__local-fonts\">\n\t\t\t\t{ isUploading && (\n\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t<div className=\"font-library-modal__upload-area\">\n\t\t\t\t\t\t\t<ProgressBar />\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</FlexItem>\n\t\t\t\t) }\n\t\t\t\t{ ! isUploading && (\n\t\t\t\t\t<FormFileUpload\n\t\t\t\t\t\taccept={ ALLOWED_FILE_EXTENSIONS.map(\n\t\t\t\t\t\t\t( ext ) => `.${ ext }`\n\t\t\t\t\t\t).join( ',' ) }\n\t\t\t\t\t\tmultiple={ true }\n\t\t\t\t\t\tonChange={ onFilesUpload }\n\t\t\t\t\t\trender={ ( { openFileDialog } ) => (\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\tclassName=\"font-library-modal__upload-area\"\n\t\t\t\t\t\t\t\tonClick={ openFileDialog }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<span>{ __( 'Upload font' ) }</span>\n\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t) }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t<Spacer margin={ 2 } />\n\t\t\t\t<Text className=\"font-library-modal__upload-area__text\">\n\t\t\t\t\t{ sprintf(\n\t\t\t\t\t\t/* translators: %s: supported font formats: ex: .ttf, .woff and .woff2 */\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'Uploaded fonts appear in your library and can be used in your theme. Supported formats: %s.'\n\t\t\t\t\t\t),\n\t\t\t\t\t\tsupportedFormats\n\t\t\t\t\t) }\n\t\t\t\t</Text>\n\t\t\t</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AAAC,IAAAmG,QAAA,GAEc5G,WAAW;AAAA6G,OAAA,CAAApB,OAAA,GAAAmB,QAAA"}
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.batchInstallFontFaces = batchInstallFontFaces;
7
7
  exports.checkFontFaceInstalled = checkFontFaceInstalled;
8
- exports.downloadFontFaceAsset = downloadFontFaceAsset;
8
+ exports.downloadFontFaceAssets = downloadFontFaceAssets;
9
9
  exports.getDisplaySrcFromFontFace = getDisplaySrcFromFontFace;
10
10
  exports.getFontFaceVariantName = getFontFaceVariantName;
11
11
  exports.isUrlEncoded = isUrlEncoded;
@@ -165,20 +165,19 @@ function makeFontFacesFormData(font) {
165
165
  const fontFacesFormData = font.fontFace.map((face, faceIndex) => {
166
166
  const formData = new FormData();
167
167
  if (face.file) {
168
- // Slugified file name because the it might contain spaces or characters treated differently on the server.
169
- const fileId = `file-${faceIndex}`;
170
- // Add the files to the formData
171
- formData.append(fileId, face.file, face.file.name);
172
- // remove the file object from the face object the file is referenced in src
173
- const {
174
- file,
175
- ...faceWithoutFileProperty
176
- } = face;
177
- const fontFaceSettings = {
178
- ...faceWithoutFileProperty,
179
- src: fileId
180
- };
181
- formData.append('font_face_settings', JSON.stringify(fontFaceSettings));
168
+ // Normalize to an array, since face.file may be a single file or an array of files.
169
+ const files = Array.isArray(face.file) ? face.file : [face.file];
170
+ const src = [];
171
+ files.forEach((file, key) => {
172
+ // Slugified file name because the it might contain spaces or characters treated differently on the server.
173
+ const fileId = `file-${faceIndex}-${key}`;
174
+ // Add the files to the formData
175
+ formData.append(fileId, file, file.name);
176
+ src.push(fileId);
177
+ });
178
+ face.src = src.length === 1 ? src[0] : src;
179
+ delete face.file;
180
+ formData.append('font_face_settings', JSON.stringify(face));
182
181
  } else {
183
182
  formData.append('font_face_settings', JSON.stringify(face));
184
183
  }
@@ -219,23 +218,26 @@ async function batchInstallFontFaces(fontFamilyId, fontFacesData) {
219
218
  /*
220
219
  * Downloads a font face asset from a URL to the client and returns a File object.
221
220
  */
222
- async function downloadFontFaceAsset(url) {
223
- return fetch(new Request(url)).then(response => {
224
- if (!response.ok) {
225
- throw new Error(`Error downloading font face asset from ${url}. Server responded with status: ${response.status}`);
226
- }
227
- return response.blob();
228
- }).then(blob => {
229
- const filename = url.split('/').pop();
230
- const file = new File([blob], filename, {
231
- type: blob.type
221
+ async function downloadFontFaceAssets(src) {
222
+ // Normalize to an array, since `src` could be a string or array.
223
+ src = Array.isArray(src) ? src : [src];
224
+ const files = await Promise.all(src.map(async url => {
225
+ return fetch(new Request(url)).then(response => {
226
+ if (!response.ok) {
227
+ throw new Error(`Error downloading font face asset from ${url}. Server responded with status: ${response.status}`);
228
+ }
229
+ return response.blob();
230
+ }).then(blob => {
231
+ const filename = url.split('/').pop();
232
+ const file = new File([blob], filename, {
233
+ type: blob.type
234
+ });
235
+ return file;
232
236
  });
233
- return file;
234
- }).catch(error => {
235
- // eslint-disable-next-line no-console
236
- console.error(`Error downloading font face asset from ${url}:`, error);
237
- throw error;
238
- });
237
+ }));
238
+
239
+ // If we only have one file return it (not the array). Otherwise return all of them in the array.
240
+ return files.length === 1 ? files[0] : files;
239
241
  }
240
242
 
241
243
  /*
@@ -1 +1 @@
1
- {"version":3,"names":["_components","require","_constants","_lockUnlock","_resolvers","_previewStyles","File","window","setUIValuesNeeded","font","extraValues","name","fontFamily","slug","isUrlEncoded","url","decodeURIComponent","getFontFaceVariantName","face","weightName","FONT_WEIGHTS","fontWeight","styleName","fontStyle","FONT_STYLES","mergeFontFaces","existing","incoming","map","Map","set","Array","from","values","mergeFontFamilies","has","fontFace","incomingFontFaces","restIncoming","existingFont","get","mergedFontFaces","loadFontFaceInBrowser","source","addTo","dataSource","arrayBuffer","newFont","FontFace","formatFontFamily","style","weight","loadedFace","load","document","fonts","add","iframeDocument","querySelector","contentDocument","getDisplaySrcFromFontFace","input","urlPrefix","src","isArray","startsWith","replace","encodeURI","makeFontFamilyFormData","formData","FormData","kebabCase","unlock","componentsPrivateApis","category","familyWithValidParameters","fontFamilySettings","append","JSON","stringify","makeFontFacesFormData","fontFacesFormData","faceIndex","file","fileId","faceWithoutFileProperty","fontFaceSettings","batchInstallFontFaces","fontFamilyId","fontFacesData","promises","faceData","fetchInstallFontFace","responses","Promise","allSettled","results","errors","successes","forEach","result","index","status","response","value","id","push","data","message","reason","downloadFontFaceAsset","fetch","Request","then","ok","Error","blob","filename","split","pop","type","catch","error","console","checkFontFaceInstalled","collection","findIndex","collectionFontFace"],"sources":["@wordpress/edit-site/src/components/global-styles/font-library-modal/utils/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { privateApis as componentsPrivateApis } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { FONT_WEIGHTS, FONT_STYLES } from './constants';\nimport { unlock } from '../../../../lock-unlock';\nimport { fetchInstallFontFace } from '../resolvers';\nimport { formatFontFamily } from './preview-styles';\n\n/**\n * Browser dependencies\n */\nconst { File } = window;\n\nexport function setUIValuesNeeded( font, extraValues = {} ) {\n\tif ( ! font.name && ( font.fontFamily || font.slug ) ) {\n\t\tfont.name = font.fontFamily || font.slug;\n\t}\n\treturn {\n\t\t...font,\n\t\t...extraValues,\n\t};\n}\n\nexport function isUrlEncoded( url ) {\n\tif ( typeof url !== 'string' ) {\n\t\treturn false;\n\t}\n\treturn url !== decodeURIComponent( url );\n}\n\nexport function getFontFaceVariantName( face ) {\n\tconst weightName = FONT_WEIGHTS[ face.fontWeight ] || face.fontWeight;\n\tconst styleName =\n\t\tface.fontStyle === 'normal'\n\t\t\t? ''\n\t\t\t: FONT_STYLES[ face.fontStyle ] || face.fontStyle;\n\treturn `${ weightName } ${ styleName }`;\n}\n\nexport function mergeFontFaces( existing = [], incoming = [] ) {\n\tconst map = new Map();\n\tfor ( const face of existing ) {\n\t\tmap.set( `${ face.fontWeight }${ face.fontStyle }`, face );\n\t}\n\tfor ( const face of incoming ) {\n\t\t// This will overwrite if the src already exists, keeping it unique.\n\t\tmap.set( `${ face.fontWeight }${ face.fontStyle }`, face );\n\t}\n\treturn Array.from( map.values() );\n}\n\nexport function mergeFontFamilies( existing = [], incoming = [] ) {\n\tconst map = new Map();\n\t// Add the existing array to the map.\n\tfor ( const font of existing ) {\n\t\tmap.set( font.slug, { ...font } );\n\t}\n\t// Add the incoming array to the map, overwriting existing values excepting fontFace that need to be merged.\n\tfor ( const font of incoming ) {\n\t\tif ( map.has( font.slug ) ) {\n\t\t\tconst { fontFace: incomingFontFaces, ...restIncoming } = font;\n\t\t\tconst existingFont = map.get( font.slug );\n\t\t\t// Merge the fontFaces existing with the incoming fontFaces.\n\t\t\tconst mergedFontFaces = mergeFontFaces(\n\t\t\t\texistingFont.fontFace,\n\t\t\t\tincomingFontFaces\n\t\t\t);\n\t\t\t// Except for the fontFace key all the other keys are overwritten with the incoming values.\n\t\t\tmap.set( font.slug, {\n\t\t\t\t...restIncoming,\n\t\t\t\tfontFace: mergedFontFaces,\n\t\t\t} );\n\t\t} else {\n\t\t\tmap.set( font.slug, { ...font } );\n\t\t}\n\t}\n\treturn Array.from( map.values() );\n}\n\n/*\n * Loads the font face from a URL and adds it to the browser.\n * It also adds it to the iframe document.\n */\nexport async function loadFontFaceInBrowser( fontFace, source, addTo = 'all' ) {\n\tlet dataSource;\n\n\tif ( typeof source === 'string' ) {\n\t\tdataSource = `url(${ source })`;\n\t\t// eslint-disable-next-line no-undef\n\t} else if ( source instanceof File ) {\n\t\tdataSource = await source.arrayBuffer();\n\t} else {\n\t\treturn;\n\t}\n\n\tconst newFont = new window.FontFace(\n\t\tformatFontFamily( fontFace.fontFamily ),\n\t\tdataSource,\n\t\t{\n\t\t\tstyle: fontFace.fontStyle,\n\t\t\tweight: fontFace.fontWeight,\n\t\t}\n\t);\n\n\tconst loadedFace = await newFont.load();\n\n\tif ( addTo === 'document' || addTo === 'all' ) {\n\t\tdocument.fonts.add( loadedFace );\n\t}\n\n\tif ( addTo === 'iframe' || addTo === 'all' ) {\n\t\tconst iframeDocument = document.querySelector(\n\t\t\t'iframe[name=\"editor-canvas\"]'\n\t\t).contentDocument;\n\t\tiframeDocument.fonts.add( loadedFace );\n\t}\n}\n\nexport function getDisplaySrcFromFontFace( input, urlPrefix ) {\n\tif ( ! input ) {\n\t\treturn;\n\t}\n\n\tlet src;\n\tif ( Array.isArray( input ) ) {\n\t\tsrc = input[ 0 ];\n\t} else {\n\t\tsrc = input;\n\t}\n\t// If it is a theme font, we need to make the url absolute\n\tif ( src.startsWith( 'file:.' ) && urlPrefix ) {\n\t\tsrc = src.replace( 'file:.', urlPrefix );\n\t}\n\tif ( ! isUrlEncoded( src ) ) {\n\t\tsrc = encodeURI( src );\n\t}\n\treturn src;\n}\n\nexport function makeFontFamilyFormData( fontFamily ) {\n\tconst formData = new FormData();\n\tconst { kebabCase } = unlock( componentsPrivateApis );\n\n\tconst { fontFace, category, ...familyWithValidParameters } = fontFamily;\n\tconst fontFamilySettings = {\n\t\t...familyWithValidParameters,\n\t\tslug: kebabCase( fontFamily.slug ),\n\t};\n\n\tformData.append(\n\t\t'font_family_settings',\n\t\tJSON.stringify( fontFamilySettings )\n\t);\n\treturn formData;\n}\n\nexport function makeFontFacesFormData( font ) {\n\tif ( font?.fontFace ) {\n\t\tconst fontFacesFormData = font.fontFace.map( ( face, faceIndex ) => {\n\t\t\tconst formData = new FormData();\n\t\t\tif ( face.file ) {\n\t\t\t\t// Slugified file name because the it might contain spaces or characters treated differently on the server.\n\t\t\t\tconst fileId = `file-${ faceIndex }`;\n\t\t\t\t// Add the files to the formData\n\t\t\t\tformData.append( fileId, face.file, face.file.name );\n\t\t\t\t// remove the file object from the face object the file is referenced in src\n\t\t\t\tconst { file, ...faceWithoutFileProperty } = face;\n\t\t\t\tconst fontFaceSettings = {\n\t\t\t\t\t...faceWithoutFileProperty,\n\t\t\t\t\tsrc: fileId,\n\t\t\t\t};\n\t\t\t\tformData.append(\n\t\t\t\t\t'font_face_settings',\n\t\t\t\t\tJSON.stringify( fontFaceSettings )\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tformData.append( 'font_face_settings', JSON.stringify( face ) );\n\t\t\t}\n\t\t\treturn formData;\n\t\t} );\n\n\t\treturn fontFacesFormData;\n\t}\n}\n\nexport async function batchInstallFontFaces( fontFamilyId, fontFacesData ) {\n\tconst promises = fontFacesData.map( ( faceData ) =>\n\t\tfetchInstallFontFace( fontFamilyId, faceData )\n\t);\n\tconst responses = await Promise.allSettled( promises );\n\n\tconst results = {\n\t\terrors: [],\n\t\tsuccesses: [],\n\t};\n\n\tresponses.forEach( ( result, index ) => {\n\t\tif ( result.status === 'fulfilled' ) {\n\t\t\tconst response = result.value;\n\t\t\tif ( response.id ) {\n\t\t\t\tresults.successes.push( response );\n\t\t\t} else {\n\t\t\t\tresults.errors.push( {\n\t\t\t\t\tdata: fontFacesData[ index ],\n\t\t\t\t\tmessage: `Error: ${ response.message }`,\n\t\t\t\t} );\n\t\t\t}\n\t\t} else {\n\t\t\t// Handle network errors or other fetch-related errors\n\t\t\tresults.errors.push( {\n\t\t\t\tdata: fontFacesData[ index ],\n\t\t\t\tmessage: `Fetch error: ${ result.reason.message }`,\n\t\t\t} );\n\t\t}\n\t} );\n\n\treturn results;\n}\n\n/*\n * Downloads a font face asset from a URL to the client and returns a File object.\n */\nexport async function downloadFontFaceAsset( url ) {\n\treturn fetch( new Request( url ) )\n\t\t.then( ( response ) => {\n\t\t\tif ( ! response.ok ) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Error downloading font face asset from ${ url }. Server responded with status: ${ response.status }`\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn response.blob();\n\t\t} )\n\t\t.then( ( blob ) => {\n\t\t\tconst filename = url.split( '/' ).pop();\n\t\t\tconst file = new File( [ blob ], filename, {\n\t\t\t\ttype: blob.type,\n\t\t\t} );\n\t\t\treturn file;\n\t\t} )\n\t\t.catch( ( error ) => {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.error(\n\t\t\t\t`Error downloading font face asset from ${ url }:`,\n\t\t\t\terror\n\t\t\t);\n\t\t\tthrow error;\n\t\t} );\n}\n\n/*\n * Determine if a given Font Face is present in a given collection.\n * We determine that a font face has been installed by comparing the fontWeight and fontStyle\n *\n * @param {Object} fontFace The Font Face to seek\n * @param {Array} collection The Collection to seek in\n * @returns True if the font face is found in the collection. Otherwise False.\n */\nexport function checkFontFaceInstalled( fontFace, collection ) {\n\treturn (\n\t\t-1 !==\n\t\tcollection.findIndex( ( collectionFontFace ) => {\n\t\t\treturn (\n\t\t\t\tcollectionFontFace.fontWeight === fontFace.fontWeight &&\n\t\t\t\tcollectionFontFace.fontStyle === fontFace.fontStyle\n\t\t\t);\n\t\t} )\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAKA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,cAAA,GAAAJ,OAAA;AAXA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;AACA,MAAM;EAAEK;AAAK,CAAC,GAAGC,MAAM;AAEhB,SAASC,iBAAiBA,CAAEC,IAAI,EAAEC,WAAW,GAAG,CAAC,CAAC,EAAG;EAC3D,IAAK,CAAED,IAAI,CAACE,IAAI,KAAMF,IAAI,CAACG,UAAU,IAAIH,IAAI,CAACI,IAAI,CAAE,EAAG;IACtDJ,IAAI,CAACE,IAAI,GAAGF,IAAI,CAACG,UAAU,IAAIH,IAAI,CAACI,IAAI;EACzC;EACA,OAAO;IACN,GAAGJ,IAAI;IACP,GAAGC;EACJ,CAAC;AACF;AAEO,SAASI,YAAYA,CAAEC,GAAG,EAAG;EACnC,IAAK,OAAOA,GAAG,KAAK,QAAQ,EAAG;IAC9B,OAAO,KAAK;EACb;EACA,OAAOA,GAAG,KAAKC,kBAAkB,CAAED,GAAI,CAAC;AACzC;AAEO,SAASE,sBAAsBA,CAAEC,IAAI,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ACC,GAAG,CAAC,CAAC;IACvC,MAAMpC,IAAI,GAAG,IAAI7E,IAAI,CAAE,CAAE8G,IAAI,CAAE,EAAEC,QAAQ,EAAE;MAC1CG,IAAI,EAAEJ,IAAI,CAACI;IACZ,CAAE,CAAC;IACH,OAAOrC,IAAI;EACZ,CAAE,CAAC,CACFsC,KAAK,CAAIC,KAAK,IAAM;IACpB;IACAC,OAAO,CAACD,KAAK,CACX,0CAA0C3G,GAAK,GAAE,EAClD2G,KACD,CAAC;IACD,MAAMA,KAAK;EACZ,CAAE,CAAC;AACL;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,sBAAsBA,CAAExF,QAAQ,EAAEyF,UAAU,EAAG;EAC9D,OACC,CAAC,CAAC,KACFA,UAAU,CAACC,SAAS,CAAIC,kBAAkB,IAAM;IAC/C,OACCA,kBAAkB,CAAC1G,UAAU,KAAKe,QAAQ,CAACf,UAAU,IACrD0G,kBAAkB,CAACxG,SAAS,KAAKa,QAAQ,CAACb,SAAS;EAErD,CAAE,CAAC;AAEL"}
1
+ {"version":3,"names":["_components","require","_constants","_lockUnlock","_resolvers","_previewStyles","File","window","setUIValuesNeeded","font","extraValues","name","fontFamily","slug","isUrlEncoded","url","decodeURIComponent","getFontFaceVariantName","face","weightName","FONT_WEIGHTS","fontWeight","styleName","fontStyle","FONT_STYLES","mergeFontFaces","existing","incoming","map","Map","set","Array","from","values","mergeFontFamilies","has","fontFace","incomingFontFaces","restIncoming","existingFont","get","mergedFontFaces","loadFontFaceInBrowser","source","addTo","dataSource","arrayBuffer","newFont","FontFace","formatFontFamily","style","weight","loadedFace","load","document","fonts","add","iframeDocument","querySelector","contentDocument","getDisplaySrcFromFontFace","input","urlPrefix","src","isArray","startsWith","replace","encodeURI","makeFontFamilyFormData","formData","FormData","kebabCase","unlock","componentsPrivateApis","category","familyWithValidParameters","fontFamilySettings","append","JSON","stringify","makeFontFacesFormData","fontFacesFormData","faceIndex","file","files","forEach","key","fileId","push","length","batchInstallFontFaces","fontFamilyId","fontFacesData","promises","faceData","fetchInstallFontFace","responses","Promise","allSettled","results","errors","successes","result","index","status","response","value","id","data","message","reason","downloadFontFaceAssets","all","fetch","Request","then","ok","Error","blob","filename","split","pop","type","checkFontFaceInstalled","collection","findIndex","collectionFontFace"],"sources":["@wordpress/edit-site/src/components/global-styles/font-library-modal/utils/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { privateApis as componentsPrivateApis } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { FONT_WEIGHTS, FONT_STYLES } from './constants';\nimport { unlock } from '../../../../lock-unlock';\nimport { fetchInstallFontFace } from '../resolvers';\nimport { formatFontFamily } from './preview-styles';\n\n/**\n * Browser dependencies\n */\nconst { File } = window;\n\nexport function setUIValuesNeeded( font, extraValues = {} ) {\n\tif ( ! font.name && ( font.fontFamily || font.slug ) ) {\n\t\tfont.name = font.fontFamily || font.slug;\n\t}\n\treturn {\n\t\t...font,\n\t\t...extraValues,\n\t};\n}\n\nexport function isUrlEncoded( url ) {\n\tif ( typeof url !== 'string' ) {\n\t\treturn false;\n\t}\n\treturn url !== decodeURIComponent( url );\n}\n\nexport function getFontFaceVariantName( face ) {\n\tconst weightName = FONT_WEIGHTS[ face.fontWeight ] || face.fontWeight;\n\tconst styleName =\n\t\tface.fontStyle === 'normal'\n\t\t\t? ''\n\t\t\t: FONT_STYLES[ face.fontStyle ] || face.fontStyle;\n\treturn `${ weightName } ${ styleName }`;\n}\n\nexport function mergeFontFaces( existing = [], incoming = [] ) {\n\tconst map = new Map();\n\tfor ( const face of existing ) {\n\t\tmap.set( `${ face.fontWeight }${ face.fontStyle }`, face );\n\t}\n\tfor ( const face of incoming ) {\n\t\t// This will overwrite if the src already exists, keeping it unique.\n\t\tmap.set( `${ face.fontWeight }${ face.fontStyle }`, face );\n\t}\n\treturn Array.from( map.values() );\n}\n\nexport function mergeFontFamilies( existing = [], incoming = [] ) {\n\tconst map = new Map();\n\t// Add the existing array to the map.\n\tfor ( const font of existing ) {\n\t\tmap.set( font.slug, { ...font } );\n\t}\n\t// Add the incoming array to the map, overwriting existing values excepting fontFace that need to be merged.\n\tfor ( const font of incoming ) {\n\t\tif ( map.has( font.slug ) ) {\n\t\t\tconst { fontFace: incomingFontFaces, ...restIncoming } = font;\n\t\t\tconst existingFont = map.get( font.slug );\n\t\t\t// Merge the fontFaces existing with the incoming fontFaces.\n\t\t\tconst mergedFontFaces = mergeFontFaces(\n\t\t\t\texistingFont.fontFace,\n\t\t\t\tincomingFontFaces\n\t\t\t);\n\t\t\t// Except for the fontFace key all the other keys are overwritten with the incoming values.\n\t\t\tmap.set( font.slug, {\n\t\t\t\t...restIncoming,\n\t\t\t\tfontFace: mergedFontFaces,\n\t\t\t} );\n\t\t} else {\n\t\t\tmap.set( font.slug, { ...font } );\n\t\t}\n\t}\n\treturn Array.from( map.values() );\n}\n\n/*\n * Loads the font face from a URL and adds it to the browser.\n * It also adds it to the iframe document.\n */\nexport async function loadFontFaceInBrowser( fontFace, source, addTo = 'all' ) {\n\tlet dataSource;\n\n\tif ( typeof source === 'string' ) {\n\t\tdataSource = `url(${ source })`;\n\t\t// eslint-disable-next-line no-undef\n\t} else if ( source instanceof File ) {\n\t\tdataSource = await source.arrayBuffer();\n\t} else {\n\t\treturn;\n\t}\n\n\tconst newFont = new window.FontFace(\n\t\tformatFontFamily( fontFace.fontFamily ),\n\t\tdataSource,\n\t\t{\n\t\t\tstyle: fontFace.fontStyle,\n\t\t\tweight: fontFace.fontWeight,\n\t\t}\n\t);\n\n\tconst loadedFace = await newFont.load();\n\n\tif ( addTo === 'document' || addTo === 'all' ) {\n\t\tdocument.fonts.add( loadedFace );\n\t}\n\n\tif ( addTo === 'iframe' || addTo === 'all' ) {\n\t\tconst iframeDocument = document.querySelector(\n\t\t\t'iframe[name=\"editor-canvas\"]'\n\t\t).contentDocument;\n\t\tiframeDocument.fonts.add( loadedFace );\n\t}\n}\n\nexport function getDisplaySrcFromFontFace( input, urlPrefix ) {\n\tif ( ! input ) {\n\t\treturn;\n\t}\n\n\tlet src;\n\tif ( Array.isArray( input ) ) {\n\t\tsrc = input[ 0 ];\n\t} else {\n\t\tsrc = input;\n\t}\n\t// If it is a theme font, we need to make the url absolute\n\tif ( src.startsWith( 'file:.' ) && urlPrefix ) {\n\t\tsrc = src.replace( 'file:.', urlPrefix );\n\t}\n\tif ( ! isUrlEncoded( src ) ) {\n\t\tsrc = encodeURI( src );\n\t}\n\treturn src;\n}\n\nexport function makeFontFamilyFormData( fontFamily ) {\n\tconst formData = new FormData();\n\tconst { kebabCase } = unlock( componentsPrivateApis );\n\n\tconst { fontFace, category, ...familyWithValidParameters } = fontFamily;\n\tconst fontFamilySettings = {\n\t\t...familyWithValidParameters,\n\t\tslug: kebabCase( fontFamily.slug ),\n\t};\n\n\tformData.append(\n\t\t'font_family_settings',\n\t\tJSON.stringify( fontFamilySettings )\n\t);\n\treturn formData;\n}\n\nexport function makeFontFacesFormData( font ) {\n\tif ( font?.fontFace ) {\n\t\tconst fontFacesFormData = font.fontFace.map( ( face, faceIndex ) => {\n\t\t\tconst formData = new FormData();\n\t\t\tif ( face.file ) {\n\t\t\t\t// Normalize to an array, since face.file may be a single file or an array of files.\n\t\t\t\tconst files = Array.isArray( face.file )\n\t\t\t\t\t? face.file\n\t\t\t\t\t: [ face.file ];\n\t\t\t\tconst src = [];\n\n\t\t\t\tfiles.forEach( ( file, key ) => {\n\t\t\t\t\t// Slugified file name because the it might contain spaces or characters treated differently on the server.\n\t\t\t\t\tconst fileId = `file-${ faceIndex }-${ key }`;\n\t\t\t\t\t// Add the files to the formData\n\t\t\t\t\tformData.append( fileId, file, file.name );\n\t\t\t\t\tsrc.push( fileId );\n\t\t\t\t} );\n\n\t\t\t\tface.src = src.length === 1 ? src[ 0 ] : src;\n\t\t\t\tdelete face.file;\n\n\t\t\t\tformData.append( 'font_face_settings', JSON.stringify( face ) );\n\t\t\t} else {\n\t\t\t\tformData.append( 'font_face_settings', JSON.stringify( face ) );\n\t\t\t}\n\t\t\treturn formData;\n\t\t} );\n\n\t\treturn fontFacesFormData;\n\t}\n}\n\nexport async function batchInstallFontFaces( fontFamilyId, fontFacesData ) {\n\tconst promises = fontFacesData.map( ( faceData ) =>\n\t\tfetchInstallFontFace( fontFamilyId, faceData )\n\t);\n\tconst responses = await Promise.allSettled( promises );\n\n\tconst results = {\n\t\terrors: [],\n\t\tsuccesses: [],\n\t};\n\n\tresponses.forEach( ( result, index ) => {\n\t\tif ( result.status === 'fulfilled' ) {\n\t\t\tconst response = result.value;\n\t\t\tif ( response.id ) {\n\t\t\t\tresults.successes.push( response );\n\t\t\t} else {\n\t\t\t\tresults.errors.push( {\n\t\t\t\t\tdata: fontFacesData[ index ],\n\t\t\t\t\tmessage: `Error: ${ response.message }`,\n\t\t\t\t} );\n\t\t\t}\n\t\t} else {\n\t\t\t// Handle network errors or other fetch-related errors\n\t\t\tresults.errors.push( {\n\t\t\t\tdata: fontFacesData[ index ],\n\t\t\t\tmessage: `Fetch error: ${ result.reason.message }`,\n\t\t\t} );\n\t\t}\n\t} );\n\n\treturn results;\n}\n\n/*\n * Downloads a font face asset from a URL to the client and returns a File object.\n */\nexport async function downloadFontFaceAssets( src ) {\n\t// Normalize to an array, since `src` could be a string or array.\n\tsrc = Array.isArray( src ) ? src : [ src ];\n\n\tconst files = await Promise.all(\n\t\tsrc.map( async ( url ) => {\n\t\t\treturn fetch( new Request( url ) )\n\t\t\t\t.then( ( response ) => {\n\t\t\t\t\tif ( ! response.ok ) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Error downloading font face asset from ${ url }. Server responded with status: ${ response.status }`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn response.blob();\n\t\t\t\t} )\n\t\t\t\t.then( ( blob ) => {\n\t\t\t\t\tconst filename = url.split( '/' ).pop();\n\t\t\t\t\tconst file = new File( [ blob ], filename, {\n\t\t\t\t\t\ttype: blob.type,\n\t\t\t\t\t} );\n\t\t\t\t\treturn file;\n\t\t\t\t} );\n\t\t} )\n\t);\n\n\t// If we only have one file return it (not the array). Otherwise return all of them in the array.\n\treturn files.length === 1 ? files[ 0 ] : files;\n}\n\n/*\n * Determine if a given Font Face is present in a given collection.\n * We determine that a font face has been installed by comparing the fontWeight and fontStyle\n *\n * @param {Object} fontFace The Font Face to seek\n * @param {Array} collection The Collection to seek in\n * @returns True if the font face is found in the collection. Otherwise False.\n */\nexport function checkFontFaceInstalled( fontFace, collection ) {\n\treturn (\n\t\t-1 !==\n\t\tcollection.findIndex( ( collectionFontFace ) => {\n\t\t\treturn (\n\t\t\t\tcollectionFontFace.fontWeight === fontFace.fontWeight &&\n\t\t\t\tcollectionFontFace.fontStyle === fontFace.fontStyle\n\t\t\t);\n\t\t} )\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAKA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,cAAA,GAAAJ,OAAA;AAXA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;AACA,MAAM;EAAEK;AAAK,CAAC,GAAGC,MAAM;AAEhB,SAASC,iBAAiBA,CAAEC,IAAI,EAAEC,WAAW,GAAG,CAAC,CAAC,EAAG;EAC3D,IAAK,CAAED,IAAI,CAACE,IAAI,KAAMF,IAAI,CAACG,UAAU,IAAIH,IAAI,CAACI,IAAI,CAAE,EAAG;IACtDJ,IAAI,CAACE,IAAI,GAAGF,IAAI,CAACG,UAAU,IAAIH,IAAI,CAACI,IAAI;EACzC;EACA,OAAO;IACN,GAAGJ,IAAI;IACP,GAAGC;EACJ,CAAC;AACF;AAEO,SAASI,YAAYA,CAAEC,GAAG,EAAG;EACnC,IAAK,OAAOA,GAAG,KAAK,QAAQ,EAAG;IAC9B,OAAO,KAAK;EACb;EACA,OAAOA,GAAG,KAAKC,k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@@ const {
24
24
  } = (0, _lockUnlock.unlock)(_router.privateApis);
25
25
  function getPostLinkProps(history, params = {}, state, shouldReplace = false) {
26
26
  function onClick(event) {
27
- event.preventDefault();
27
+ event?.preventDefault();
28
28
  if (shouldReplace) {
29
29
  history.replace(params, state);
30
30
  } else {
@@ -1 +1 @@
1
- {"version":3,"names":["_url","require","_router","_lockUnlock","_isPreviewingTheme","useHistory","unlock","routerPrivateApis","getPostLinkProps","history","params","state","shouldReplace","onClick","event","preventDefault","replace","push","currentArgs","getQueryArgs","window","location","href","currentUrlWithoutArgs","removeQueryArgs","Object","keys","isPreviewingTheme","wp_theme_preview","currentlyPreviewingTheme","newUrl","addQueryArgs","useLink","Link","children","props","_react","createElement"],"sources":["@wordpress/edit-site/src/components/routes/link.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs, getQueryArgs, removeQueryArgs } from '@wordpress/url';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\nimport {\n\tisPreviewingTheme,\n\tcurrentlyPreviewingTheme,\n} from '../../utils/is-previewing-theme';\n\nconst { useHistory } = unlock( routerPrivateApis );\n\nexport function getPostLinkProps(\n\thistory,\n\tparams = {},\n\tstate,\n\tshouldReplace = false\n) {\n\tfunction onClick( event ) {\n\t\tevent.preventDefault();\n\n\t\tif ( shouldReplace ) {\n\t\t\thistory.replace( params, state );\n\t\t} else {\n\t\t\thistory.push( params, state );\n\t\t}\n\t}\n\n\tconst currentArgs = getQueryArgs( window.location.href );\n\tconst currentUrlWithoutArgs = removeQueryArgs(\n\t\twindow.location.href,\n\t\t...Object.keys( currentArgs )\n\t);\n\n\tif ( isPreviewingTheme() ) {\n\t\tparams = {\n\t\t\t...params,\n\t\t\twp_theme_preview: currentlyPreviewingTheme(),\n\t\t};\n\t}\n\n\tconst newUrl = addQueryArgs( currentUrlWithoutArgs, params );\n\n\treturn {\n\t\thref: newUrl,\n\t\tonClick,\n\t};\n}\n\nexport function useLink( params, state, shouldReplace ) {\n\tconst history = useHistory();\n\treturn getPostLinkProps( history, params, state, shouldReplace );\n}\n\nexport default function Link( {\n\tparams = {},\n\tstate,\n\treplace: shouldReplace = false,\n\tchildren,\n\t...props\n} ) {\n\tconst { href, onClick } = useLink( params, state, shouldReplace );\n\n\treturn (\n\t\t<a href={ href } onClick={ onClick } { ...props }>\n\t\t\t{ children }\n\t\t</a>\n\t);\n}\n"],"mappings":";;;;;;;;;AAGA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAKA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,kBAAA,GAAAH,OAAA;AAVA;AACA;AACA;;AAIA;AACA;AACA;;AAOA,MAAM;EAAEI;AAAW,CAAC,GAAG,IAAAC,kBAAM,EAAEC,mBAAkB,CAAC;AAE3C,SAASC,gBAAgBA,CAC/BC,OAAO,EACPC,MAAM,GAAG,CAAC,CAAC,EACXC,KAAK,EACLC,aAAa,GAAG,KAAK,EACpB;EACD,SAASC,OAAOA,CAAEC,KAAK,EAAG;IACzBA,KAAK,CAACC,cAAc,CAAC,CAAC;IAEtB,IAAKH,aAAa,EAAG;MACpBH,OAAO,CAACO,OAAO,CAAEN,MAAM,EAAEC,KAAM,CAAC;IACjC,CAAC,MAAM;MACNF,OAAO,CAACQ,IAAI,CAAEP,MAAM,EAAEC,KAAM,CAAC;IAC9B;EACD;EAEA,MAAMO,WAAW,GAAG,IAAAC,iBAAY,EAAEC,MAAM,CAACC,QAAQ,CAACC,IAAK,CAAC;EACxD,MAAMC,qBAAqB,GAAG,IAAAC,oBAAe,EAC5CJ,MAAM,CAACC,QAAQ,CAACC,IAAI,EACpB,GAAGG,MAAM,CAACC,IAAI,CAAER,WAAY,CAC7B,CAAC;EAED,IAAK,IAAAS,oCAAiB,EAAC,CAAC,EAAG;IAC1BjB,MAAM,GAAG;MACR,GAAGA,MAAM;MACTkB,gBAAgB,EAAE,IAAAC,2CAAwB,EAAC;IAC5C,CAAC;EACF;EAEA,MAAMC,MAAM,GAAG,IAAAC,iBAAY,EAAER,qBAAqB,EAAEb,MAAO,CAAC;EAE5D,OAAO;IACNY,IAAI,EAAEQ,MAAM;IACZjB;EACD,CAAC;AACF;AAEO,SAASmB,OAAOA,CAAEtB,MAAM,EAAEC,KAAK,EAAEC,aAAa,EAAG;EACvD,MAAMH,OAAO,GAAGJ,UAAU,CAAC,CAAC;EAC5B,OAAOG,gBAAgB,CAAEC,OAAO,EAAEC,MAAM,EAAEC,KAAK,EAAEC,aAAc,CAAC;AACjE;AAEe,SAASqB,IAAIA,CAAE;EAC7BvB,MAAM,GAAG,CAAC,CAAC;EACXC,KAAK;EACLK,OAAO,EAAEJ,aAAa,GAAG,KAAK;EAC9BsB,QAAQ;EACR,GAAGC;AACJ,CAAC,EAAG;EACH,MAAM;IAAEb,IAAI;IAAET;EAAQ,CAAC,GAAGmB,OAAO,CAAEtB,MAAM,EAAEC,KAAK,EAAEC,aAAc,CAAC;EAEjE,OACC,IAAAwB,MAAA,CAAAC,aAAA;IAAGf,IAAI,EAAGA,IAAM;IAACT,OAAO,EAAGA,OAAS;IAAA,GAAMsB;EAAK,GAC5CD,QACA,CAAC;AAEN"}
1
+ {"version":3,"names":["_url","require","_router","_lockUnlock","_isPreviewingTheme","useHistory","unlock","routerPrivateApis","getPostLinkProps","history","params","state","shouldReplace","onClick","event","preventDefault","replace","push","currentArgs","getQueryArgs","window","location","href","currentUrlWithoutArgs","removeQueryArgs","Object","keys","isPreviewingTheme","wp_theme_preview","currentlyPreviewingTheme","newUrl","addQueryArgs","useLink","Link","children","props","_react","createElement"],"sources":["@wordpress/edit-site/src/components/routes/link.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs, getQueryArgs, removeQueryArgs } from '@wordpress/url';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\nimport {\n\tisPreviewingTheme,\n\tcurrentlyPreviewingTheme,\n} from '../../utils/is-previewing-theme';\n\nconst { useHistory } = unlock( routerPrivateApis );\n\nexport function getPostLinkProps(\n\thistory,\n\tparams = {},\n\tstate,\n\tshouldReplace = false\n) {\n\tfunction onClick( event ) {\n\t\tevent?.preventDefault();\n\n\t\tif ( shouldReplace ) {\n\t\t\thistory.replace( params, state );\n\t\t} else {\n\t\t\thistory.push( params, state );\n\t\t}\n\t}\n\n\tconst currentArgs = getQueryArgs( window.location.href );\n\tconst currentUrlWithoutArgs = removeQueryArgs(\n\t\twindow.location.href,\n\t\t...Object.keys( currentArgs )\n\t);\n\n\tif ( isPreviewingTheme() ) {\n\t\tparams = {\n\t\t\t...params,\n\t\t\twp_theme_preview: currentlyPreviewingTheme(),\n\t\t};\n\t}\n\n\tconst newUrl = addQueryArgs( currentUrlWithoutArgs, params );\n\n\treturn {\n\t\thref: newUrl,\n\t\tonClick,\n\t};\n}\n\nexport function useLink( params, state, shouldReplace ) {\n\tconst history = useHistory();\n\treturn getPostLinkProps( history, params, state, shouldReplace );\n}\n\nexport default function Link( {\n\tparams = {},\n\tstate,\n\treplace: shouldReplace = false,\n\tchildren,\n\t...props\n} ) {\n\tconst { href, onClick } = useLink( params, state, shouldReplace );\n\n\treturn (\n\t\t<a href={ href } onClick={ onClick } { ...props }>\n\t\t\t{ children }\n\t\t</a>\n\t);\n}\n"],"mappings":";;;;;;;;;AAGA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAKA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,kBAAA,GAAAH,OAAA;AAVA;AACA;AACA;;AAIA;AACA;AACA;;AAOA,MAAM;EAAEI;AAAW,CAAC,GAAG,IAAAC,kBAAM,EAAEC,mBAAkB,CAAC;AAE3C,SAASC,gBAAgBA,CAC/BC,OAAO,EACPC,MAAM,GAAG,CAAC,CAAC,EACXC,KAAK,EACLC,aAAa,GAAG,KAAK,EACpB;EACD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,MAAA,CAAAC,aAAA;IAAGf,IAAI,EAAGA,IAAM;IAACT,OAAO,EAAGA,OAAS;IAAA,GAAMsB;EAAK,GAC5CD,QACA,CAAC;AAEN"}
@@ -14,7 +14,6 @@ var _element = require("@wordpress/element");
14
14
  var _data = require("@wordpress/data");
15
15
  var _interface = require("@wordpress/interface");
16
16
  var _blockEditor = require("@wordpress/block-editor");
17
- var _editor = require("@wordpress/editor");
18
17
  var _defaultSidebar = _interopRequireDefault(require("./default-sidebar"));
19
18
  var _globalStylesSidebar = _interopRequireDefault(require("./global-styles-sidebar"));
20
19
  var _constants = require("../../store/constants");
@@ -54,7 +53,7 @@ function SidebarComplementaryAreaFills() {
54
53
  isEditorSidebarOpened: _isEditorSidebarOpened,
55
54
  hasBlockSelection: !!select(_blockEditor.store).getBlockSelectionStart(),
56
55
  supportsGlobalStyles: !settings?.supportsTemplatePartsMode,
57
- isEditingPage: select(_store.store).isPage() && select(_editor.store).getRenderingMode() !== 'template-only'
56
+ isEditingPage: select(_store.store).isPage()
58
57
  };
59
58
  }, []);
60
59
  const {
@@ -1 +1 @@
1
- {"version":3,"names":["_components","require","_i18n","_icons","_element","_data","_interface","_blockEditor","_editor","_defaultSidebar","_interopRequireDefault","_globalStylesSidebar","_constants","_settingsHeader","_pagePanels","_templatePanel","_pluginTemplateSettingPanel","_constants2","_store","Slot","InspectorSlot","Fill","InspectorFill","createSlotFill","SidebarInspectorFill","exports","SidebarComplementaryAreaFills","sidebar","isEditorSidebarOpened","hasBlockSelection","supportsGlobalStyles","isEditingPage","useSelect","select","_sidebar","interfaceStore","getActiveComplementaryArea","STORE_NAME","_isEditorSidebarOpened","SIDEBAR_BLOCK","SIDEBAR_TEMPLATE","includes","settings","editSiteStore","getSettings","blockEditorStore","getBlockSelectionStart","supportsTemplatePartsMode","isPage","editorStore","getRenderingMode","enableComplementaryArea","useDispatch","useEffect","sidebarName","_react","createElement","Fragment","default","identifier","title","__","icon","isRTL","drawerLeft","drawerRight","closeLabel","header","headerClassName","bubblesVirtually"],"sources":["@wordpress/edit-site/src/components/sidebar-edit-mode/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createSlotFill } from '@wordpress/components';\nimport { isRTL, __ } from '@wordpress/i18n';\nimport { drawerLeft, drawerRight } from '@wordpress/icons';\nimport { useEffect } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as interfaceStore } from '@wordpress/interface';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { store as editorStore } from '@wordpress/editor';\n\n/**\n * Internal dependencies\n */\nimport DefaultSidebar from './default-sidebar';\nimport GlobalStylesSidebar from './global-styles-sidebar';\nimport { STORE_NAME } from '../../store/constants';\nimport SettingsHeader from './settings-header';\nimport PagePanels from './page-panels';\nimport TemplatePanel from './template-panel';\nimport PluginTemplateSettingPanel from '../plugin-template-setting-panel';\nimport { SIDEBAR_BLOCK, SIDEBAR_TEMPLATE } from './constants';\nimport { store as editSiteStore } from '../../store';\n\nconst { Slot: InspectorSlot, Fill: InspectorFill } = createSlotFill(\n\t'EditSiteSidebarInspector'\n);\nexport const SidebarInspectorFill = InspectorFill;\n\nexport function SidebarComplementaryAreaFills() {\n\tconst {\n\t\tsidebar,\n\t\tisEditorSidebarOpened,\n\t\thasBlockSelection,\n\t\tsupportsGlobalStyles,\n\t\tisEditingPage,\n\t} = useSelect( ( select ) => {\n\t\tconst _sidebar =\n\t\t\tselect( interfaceStore ).getActiveComplementaryArea( STORE_NAME );\n\t\tconst _isEditorSidebarOpened = [\n\t\t\tSIDEBAR_BLOCK,\n\t\t\tSIDEBAR_TEMPLATE,\n\t\t].includes( _sidebar );\n\t\tconst settings = select( editSiteStore ).getSettings();\n\t\treturn {\n\t\t\tsidebar: _sidebar,\n\t\t\tisEditorSidebarOpened: _isEditorSidebarOpened,\n\t\t\thasBlockSelection:\n\t\t\t\t!! select( blockEditorStore ).getBlockSelectionStart(),\n\t\t\tsupportsGlobalStyles: ! settings?.supportsTemplatePartsMode,\n\t\t\tisEditingPage:\n\t\t\t\tselect( editSiteStore ).isPage() &&\n\t\t\t\tselect( editorStore ).getRenderingMode() !== 'template-only',\n\t\t};\n\t}, [] );\n\tconst { enableComplementaryArea } = useDispatch( interfaceStore );\n\n\tuseEffect( () => {\n\t\t// Don't automatically switch tab when the sidebar is closed or when we\n\t\t// are focused on page content.\n\t\tif ( ! isEditorSidebarOpened ) {\n\t\t\treturn;\n\t\t}\n\t\tif ( hasBlockSelection ) {\n\t\t\tif ( ! isEditingPage ) {\n\t\t\t\tenableComplementaryArea( STORE_NAME, SIDEBAR_BLOCK );\n\t\t\t}\n\t\t} else {\n\t\t\tenableComplementaryArea( STORE_NAME, SIDEBAR_TEMPLATE );\n\t\t}\n\t}, [\n\t\thasBlockSelection,\n\t\tisEditorSidebarOpened,\n\t\tisEditingPage,\n\t\tenableComplementaryArea,\n\t] );\n\n\tlet sidebarName = sidebar;\n\tif ( ! isEditorSidebarOpened ) {\n\t\tsidebarName = hasBlockSelection ? SIDEBAR_BLOCK : SIDEBAR_TEMPLATE;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<DefaultSidebar\n\t\t\t\tidentifier={ sidebarName }\n\t\t\t\ttitle={ __( 'Settings' ) }\n\t\t\t\ticon={ isRTL() ? drawerLeft : drawerRight }\n\t\t\t\tcloseLabel={ __( 'Close Settings' ) }\n\t\t\t\theader={ <SettingsHeader sidebarName={ sidebarName } /> }\n\t\t\t\theaderClassName=\"edit-site-sidebar-edit-mode__panel-tabs\"\n\t\t\t>\n\t\t\t\t{ sidebarName === SIDEBAR_TEMPLATE && (\n\t\t\t\t\t<>\n\t\t\t\t\t\t{ isEditingPage ? <PagePanels /> : <TemplatePanel /> }\n\t\t\t\t\t\t<PluginTemplateSettingPanel.Slot />\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t\t{ sidebarName === SIDEBAR_BLOCK && (\n\t\t\t\t\t<InspectorSlot bubblesVirtually />\n\t\t\t\t) }\n\t\t\t</Defa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ACdC,UAAU,EAAGL,WAAa;IAC1BM,KAAK,EAAG,IAAAC,QAAE,EAAE,UAAW,CAAG;IAC1BC,IAAI,EAAG,IAAAC,WAAK,EAAC,CAAC,GAAGC,iBAAU,GAAGC,kBAAa;IAC3CC,UAAU,EAAG,IAAAL,QAAE,EAAE,gBAAiB,CAAG;IACrCM,MAAM,EAAG,IAAAZ,MAAA,CAAAC,aAAA,EAAC3C,eAAA,CAAA6C,OAAc;MAACJ,WAAW,EAAGA;IAAa,CAAE,CAAG;IACzDc,eAAe,EAAC;EAAyC,GAEvDd,WAAW,KAAKd,4BAAgB,IACjC,IAAAe,MAAA,CAAAC,aAAA,EAAAD,MAAA,CAAAE,QAAA,QACG1B,aAAa,GAAG,IAAAwB,MAAA,CAAAC,aAAA,EAAC1C,WAAA,CAAA4C,OAAU,MAAE,CAAC,GAAG,IAAAH,MAAA,CAAAC,aAAA,EAACzC,cAAA,CAAA2C,OAAa,MAAE,CAAC,EACpD,IAAAH,MAAA,CAAAC,aAAA,EAACxC,2BAAA,CAAA0C,OAA0B,CAACvC,IAAI,MAAE,CACjC,CACF,EACCmC,WAAW,KAAKf,yBAAa,IAC9B,IAAAgB,MAAA,CAAAC,aAAA,EAACpC,aAAa;IAACiD,gBAAgB;EAAA,CAAE,CAEnB,CAAC,EACfvC,oBAAoB,IAAI,IAAAyB,MAAA,CAAAC,aAAA,EAAC7C,oBAAA,CAAA+C,OAAmB,MAAE,CAC/C,CAAC;AAEL"}
1
+ {"version":3,"names":["_components","require","_i18n","_icons","_element","_data","_interface","_blockEditor","_defaultSidebar","_interopRequireDefault","_globalStylesSidebar","_constants","_settingsHeader","_pagePanels","_templatePanel","_pluginTemplateSettingPanel","_constants2","_store","Slot","InspectorSlot","Fill","InspectorFill","createSlotFill","SidebarInspectorFill","exports","SidebarComplementaryAreaFills","sidebar","isEditorSidebarOpened","hasBlockSelection","supportsGlobalStyles","isEditingPage","useSelect","select","_sidebar","interfaceStore","getActiveComplementaryArea","STORE_NAME","_isEditorSidebarOpened","SIDEBAR_BLOCK","SIDEBAR_TEMPLATE","includes","settings","editSiteStore","getSettings","blockEditorStore","getBlockSelectionStart","supportsTemplatePartsMode","isPage","enableComplementaryArea","useDispatch","useEffect","sidebarName","_react","createElement","Fragment","default","identifier","title","__","icon","isRTL","drawerLeft","drawerRight","closeLabel","header","headerClassName","bubblesVirtually"],"sources":["@wordpress/edit-site/src/components/sidebar-edit-mode/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createSlotFill } from '@wordpress/components';\nimport { isRTL, __ } from '@wordpress/i18n';\nimport { drawerLeft, drawerRight } from '@wordpress/icons';\nimport { useEffect } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as interfaceStore } from '@wordpress/interface';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport DefaultSidebar from './default-sidebar';\nimport GlobalStylesSidebar from './global-styles-sidebar';\nimport { STORE_NAME } from '../../store/constants';\nimport SettingsHeader from './settings-header';\nimport PagePanels from './page-panels';\nimport TemplatePanel from './template-panel';\nimport PluginTemplateSettingPanel from '../plugin-template-setting-panel';\nimport { SIDEBAR_BLOCK, SIDEBAR_TEMPLATE } from './constants';\nimport { store as editSiteStore } from '../../store';\n\nconst { Slot: InspectorSlot, Fill: InspectorFill } = createSlotFill(\n\t'EditSiteSidebarInspector'\n);\nexport const SidebarInspectorFill = InspectorFill;\n\nexport function SidebarComplementaryAreaFills() {\n\tconst {\n\t\tsidebar,\n\t\tisEditorSidebarOpened,\n\t\thasBlockSelection,\n\t\tsupportsGlobalStyles,\n\t\tisEditingPage,\n\t} = useSelect( ( select ) => {\n\t\tconst _sidebar =\n\t\t\tselect( interfaceStore ).getActiveComplementaryArea( STORE_NAME );\n\t\tconst _isEditorSidebarOpened = [\n\t\t\tSIDEBAR_BLOCK,\n\t\t\tSIDEBAR_TEMPLATE,\n\t\t].includes( _sidebar );\n\t\tconst settings = select( editSiteStore ).getSettings();\n\t\treturn {\n\t\t\tsidebar: _sidebar,\n\t\t\tisEditorSidebarOpened: _isEditorSidebarOpened,\n\t\t\thasBlockSelection:\n\t\t\t\t!! select( blockEditorStore ).getBlockSelectionStart(),\n\t\t\tsupportsGlobalStyles: ! settings?.supportsTemplatePartsMode,\n\t\t\tisEditingPage: select( editSiteStore ).isPage(),\n\t\t};\n\t}, [] );\n\tconst { enableComplementaryArea } = useDispatch( interfaceStore );\n\n\tuseEffect( () => {\n\t\t// Don't automatically switch tab when the sidebar is closed or when we\n\t\t// are focused on page content.\n\t\tif ( ! isEditorSidebarOpened ) {\n\t\t\treturn;\n\t\t}\n\t\tif ( hasBlockSelection ) {\n\t\t\tif ( ! isEditingPage ) {\n\t\t\t\tenableComplementaryArea( STORE_NAME, SIDEBAR_BLOCK );\n\t\t\t}\n\t\t} else {\n\t\t\tenableComplementaryArea( STORE_NAME, SIDEBAR_TEMPLATE );\n\t\t}\n\t}, [\n\t\thasBlockSelection,\n\t\tisEditorSidebarOpened,\n\t\tisEditingPage,\n\t\tenableComplementaryArea,\n\t] );\n\n\tlet sidebarName = sidebar;\n\tif ( ! isEditorSidebarOpened ) {\n\t\tsidebarName = hasBlockSelection ? SIDEBAR_BLOCK : SIDEBAR_TEMPLATE;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<DefaultSidebar\n\t\t\t\tidentifier={ sidebarName }\n\t\t\t\ttitle={ __( 'Settings' ) }\n\t\t\t\ticon={ isRTL() ? drawerLeft : drawerRight }\n\t\t\t\tcloseLabel={ __( 'Close Settings' ) }\n\t\t\t\theader={ <SettingsHeader sidebarName={ sidebarName } /> }\n\t\t\t\theaderClassName=\"edit-site-sidebar-edit-mode__panel-tabs\"\n\t\t\t>\n\t\t\t\t{ sidebarName === SIDEBAR_TEMPLATE && (\n\t\t\t\t\t<>\n\t\t\t\t\t\t{ isEditingPage ? <PagePanels /> : <TemplatePanel /> }\n\t\t\t\t\t\t<PluginTemplateSettingPanel.Slot />\n\t\t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,eAAA,CAAA+C,OAAc;IACdC,UAAU,EAAGL,WAAa;IAC1BM,KAAK,EAAG,IAAAC,QAAE,EAAE,UAAW,CAAG;IAC1BC,IAAI,EAAG,IAAAC,WAAK,EAAC,CAAC,GAAGC,iBAAU,GAAGC,kBAAa;IAC3CC,UAAU,EAAG,IAAAL,QAAE,EAAE,gBAAiB,CAAG;IACrCM,MAAM,EAAG,IAAAZ,MAAA,CAAAC,aAAA,EAACzC,eAAA,CAAA2C,OAAc;MAACJ,WAAW,EAAGA;IAAa,CAAE,CAAG;IACzDc,eAAe,EAAC;EAAyC,GAEvDd,WAAW,KAAKZ,4BAAgB,IACjC,IAAAa,MAAA,CAAAC,aAAA,EAAAD,MAAA,CAAAE,QAAA,QACGxB,aAAa,GAAG,IAAAsB,MAAA,CAAAC,aAAA,EAACxC,WAAA,CAAA0C,OAAU,MAAE,CAAC,GAAG,IAAAH,MAAA,CAAAC,aAAA,EAACvC,cAAA,CAAAyC,OAAa,MAAE,CAAC,EACpD,IAAAH,MAAA,CAAAC,aAAA,EAACtC,2BAAA,CAAAwC,OAA0B,CAACrC,IAAI,MAAE,CACjC,CACF,EACCiC,WAAW,KAAKb,yBAAa,IAC9B,IAAAc,MAAA,CAAAC,aAAA,EAAClC,aAAa;IAAC+C,gBAAgB;EAAA,CAAE,CAEnB,CAAC,EACfrC,oBAAoB,IAAI,IAAAuB,MAAA,CAAAC,aAAA,EAAC3C,oBAAA,CAAA6C,OAAmB,MAAE,CAC/C,CAAC;AAEL"}
@@ -14,8 +14,6 @@ var _interface = require("@wordpress/interface");
14
14
  var _editor = require("@wordpress/editor");
15
15
  var _constants = require("../../../store/constants");
16
16
  var _constants2 = require("../constants");
17
- var _store = require("../../../store");
18
- var _constants3 = require("../../../utils/constants");
19
17
  /**
20
18
  * External dependencies
21
19
  */
@@ -31,42 +29,15 @@ var _constants3 = require("../../../utils/constants");
31
29
  const SettingsHeader = ({
32
30
  sidebarName
33
31
  }) => {
34
- const {
35
- isEditingPage,
36
- entityType
37
- } = (0, _data.useSelect)(select => {
38
- const {
39
- getEditedPostType,
40
- isPage
41
- } = select(_store.store);
42
- const {
43
- getRenderingMode
44
- } = select(_editor.store);
45
- return {
46
- isEditingPage: isPage() && getRenderingMode() !== 'template-only',
47
- entityType: getEditedPostType()
48
- };
49
- });
50
- const entityLabel = _constants3.POST_TYPE_LABELS[entityType] || _constants3.POST_TYPE_LABELS[_constants3.TEMPLATE_POST_TYPE];
32
+ const postTypeLabel = (0, _data.useSelect)(select => select(_editor.store).getPostTypeLabel(), []);
51
33
  const {
52
34
  enableComplementaryArea
53
35
  } = (0, _data.useDispatch)(_interface.store);
54
36
  const openTemplateSettings = () => enableComplementaryArea(_constants.STORE_NAME, _constants2.SIDEBAR_TEMPLATE);
55
37
  const openBlockSettings = () => enableComplementaryArea(_constants.STORE_NAME, _constants2.SIDEBAR_BLOCK);
56
- let templateAriaLabel;
57
- if (isEditingPage) {
58
- templateAriaLabel = sidebarName === _constants2.SIDEBAR_TEMPLATE ?
59
- // translators: ARIA label for the Template sidebar tab, selected.
60
- (0, _i18n.__)('Page (selected)') :
61
- // translators: ARIA label for the Template Settings Sidebar tab, not selected.
62
- (0, _i18n.__)('Page');
63
- } else {
64
- templateAriaLabel = sidebarName === _constants2.SIDEBAR_TEMPLATE ?
65
- // translators: ARIA label for the Template sidebar tab, selected.
66
- (0, _i18n.sprintf)((0, _i18n.__)('%s (selected)'), entityLabel) :
67
- // translators: ARIA label for the Template Settings Sidebar tab, not selected.
68
- entityLabel;
69
- }
38
+ const documentAriaLabel = sidebarName === _constants2.SIDEBAR_TEMPLATE ?
39
+ // translators: ARIA label for the Template sidebar tab, selected.
40
+ (0, _i18n.sprintf)((0, _i18n.__)('%s (selected)'), postTypeLabel) : postTypeLabel;
70
41
 
71
42
  /* Use a list so screen readers will announce how many tabs there are. */
72
43
  return (0, _react.createElement)("ul", null, (0, _react.createElement)("li", null, (0, _react.createElement)(_components.Button, {
@@ -74,9 +45,9 @@ const SettingsHeader = ({
74
45
  className: (0, _classnames.default)('edit-site-sidebar-edit-mode__panel-tab', {
75
46
  'is-active': sidebarName === _constants2.SIDEBAR_TEMPLATE
76
47
  }),
77
- "aria-label": templateAriaLabel,
78
- "data-label": isEditingPage ? (0, _i18n.__)('Page') : entityLabel
79
- }, isEditingPage ? (0, _i18n.__)('Page') : entityLabel)), (0, _react.createElement)("li", null, (0, _react.createElement)(_components.Button, {
48
+ "aria-label": documentAriaLabel,
49
+ "data-label": postTypeLabel
50
+ }, postTypeLabel)), (0, _react.createElement)("li", null, (0, _react.createElement)(_components.Button, {
80
51
  onClick: openBlockSettings,
81
52
  className: (0, _classnames.default)('edit-site-sidebar-edit-mode__panel-tab', {
82
53
  'is-active': sidebarName === _constants2.SIDEBAR_BLOCK
@@ -1 +1 @@
1
- {"version":3,"names":["_classnames","_interopRequireDefault","require","_components","_i18n","_data","_interface","_editor","_constants","_constants2","_store","_constants3","SettingsHeader","sidebarName","isEditingPage","entityType","useSelect","select","getEditedPostType","isPage","editSiteStore","getRenderingMode","editorStore","entityLabel","POST_TYPE_LABELS","TEMPLATE_POST_TYPE","enableComplementaryArea","useDispatch","interfaceStore","openTemplateSettings","STORE_NAME","SIDEBAR_TEMPLATE","openBlockSettings","SIDEBAR_BLOCK","templateAriaLabel","__","sprintf","_react","createElement","Button","onClick","className","classnames","_default","exports","default"],"sources":["@wordpress/edit-site/src/components/sidebar-edit-mode/settings-header/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { Button } from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as interfaceStore } from '@wordpress/interface';\nimport { store as editorStore } from '@wordpress/editor';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from '../../../store/constants';\nimport { SIDEBAR_BLOCK, SIDEBAR_TEMPLATE } from '../constants';\nimport { store as editSiteStore } from '../../../store';\nimport { POST_TYPE_LABELS, TEMPLATE_POST_TYPE } from '../../../utils/constants';\n\nconst SettingsHeader = ( { sidebarName } ) => {\n\tconst { isEditingPage, entityType } = useSelect( ( select ) => {\n\t\tconst { getEditedPostType, isPage } = select( editSiteStore );\n\t\tconst { getRenderingMode } = select( editorStore );\n\n\t\treturn {\n\t\t\tisEditingPage: isPage() && getRenderingMode() !== 'template-only',\n\t\t\tentityType: getEditedPostType(),\n\t\t};\n\t} );\n\n\tconst entityLabel =\n\t\tPOST_TYPE_LABELS[ entityType ] ||\n\t\tPOST_TYPE_LABELS[ TEMPLATE_POST_TYPE ];\n\n\tconst { enableComplementaryArea } = useDispatch( interfaceStore );\n\tconst openTemplateSettings = () =>\n\t\tenableComplementaryArea( STORE_NAME, SIDEBAR_TEMPLATE );\n\tconst openBlockSettings = () =>\n\t\tenableComplementaryArea( STORE_NAME, SIDEBAR_BLOCK );\n\n\tlet templateAriaLabel;\n\tif ( isEditingPage ) {\n\t\ttemplateAriaLabel =\n\t\t\tsidebarName === SIDEBAR_TEMPLATE\n\t\t\t\t? // translators: ARIA label for the Template sidebar tab, selected.\n\t\t\t\t __( 'Page (selected)' )\n\t\t\t\t: // translators: ARIA label for the Template Settings Sidebar tab, not selected.\n\t\t\t\t __( 'Page' );\n\t} else {\n\t\ttemplateAriaLabel =\n\t\t\tsidebarName === SIDEBAR_TEMPLATE\n\t\t\t\t? // translators: ARIA label for the Template sidebar tab, selected.\n\t\t\t\t sprintf( __( '%s (selected)' ), entityLabel )\n\t\t\t\t: // translators: ARIA label for the Template Settings Sidebar tab, not selected.\n\t\t\t\t entityLabel;\n\t}\n\n\t/* Use a list so screen readers will announce how many tabs there are. */\n\treturn (\n\t\t<ul>\n\t\t\t<li>\n\t\t\t\t<Button\n\t\t\t\t\tonClick={ openTemplateSettings }\n\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t'edit-site-sidebar-edit-mode__panel-tab',\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t'is-active': sidebarName === SIDEBAR_TEMPLATE,\n\t\t\t\t\t\t}\n\t\t\t\t\t) }\n\t\t\t\t\taria-label={ templateAriaLabel }\n\t\t\t\t\tdata-label={ isEditingPage ? __( 'Page' ) : entityLabel }\n\t\t\t\t>\n\t\t\t\t\t{ isEditingPage ? __( 'Page' ) : entityLabel }\n\t\t\t\t</Button>\n\t\t\t</li>\n\t\t\t<li>\n\t\t\t\t<Button\n\t\t\t\t\tonClick={ openBlockSettings }\n\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t'edit-site-sidebar-edit-mode__panel-tab',\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t'is-active': sidebarName === SIDEBAR_BLOCK,\n\t\t\t\t\t\t}\n\t\t\t\t\t) }\n\t\t\t\t\taria-label={\n\t\t\t\t\t\tsidebarName === SIDEBAR_BLOCK\n\t\t\t\t\t\t\t? // translators: ARIA label for the Block Settings Sidebar tab, selected.\n\t\t\t\t\t\t\t __( 'Block (selected)' )\n\t\t\t\t\t\t\t: // translators: ARIA label for the Block Settings Sidebar tab, not selected.\n\t\t\t\t\t\t\t __( 'Block' )\n\t\t\t\t\t}\n\t\t\t\t\tdata-label={ __( 'Block' ) }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Block' ) }\n\t\t\t\t</Button>\n\t\t\t</li>\n\t\t</ul>\n\t);\n};\n\nexport default SettingsHeader;\n"],"mappings":";;;;;;;;AAGA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AAKA,IAAAM,UAAA,GAAAN,OAAA;AACA,IAAAO,WAAA,GAAAP,OAAA;AACA,IAAAQ,MAAA,GAAAR,OAAA;AACA,IAAAS,WAAA,GAAAT,OAAA;AApBA;AACA;AACA;;AAGA;AACA;A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AA,cACC,IAAAD,MAAA,CAAAC,aAAA,EAACnC,WAAA,CAAAoC,MAAM;IACNC,OAAO,EAAGX,oBAAsB;IAChCY,SAAS,EAAG,IAAAC,mBAAU,EACrB,wCAAwC,EACxC;MACC,WAAW,EAAE7B,WAAW,KAAKkB;IAC9B,CACD,CAAG;IACH,cAAaG,iBAAmB;IAChC,cAAapB,aAAa,GAAG,IAAAqB,QAAE,EAAE,MAAO,CAAC,GAAGZ;EAAa,GAEvDT,aAAa,GAAG,IAAAqB,QAAE,EAAE,MAAO,CAAC,GAAGZ,WAC1B,CACL,CAAC,EACL,IAAAc,MAAA,CAAAC,aAAA,cACC,IAAAD,MAAA,CAAAC,aAAA,EAACnC,WAAA,CAAAoC,MAAM;IACNC,OAAO,EAAGR,iBAAmB;IAC7BS,SAAS,EAAG,IAAAC,mBAAU,EACrB,wCAAwC,EACxC;MACC,WAAW,EAAE7B,WAAW,KAAKoB;IAC9B,CACD,CAAG;IACH,cACCpB,WAAW,KAAKoB,yBAAa;IAC1B;IACA,IAAAE,QAAE,EAAE,kBAAmB,CAAC;IACxB;IACA,IAAAA,QAAE,EAAE,OAAQ,CACf;IACD,cAAa,IAAAA,QAAE,EAAE,OAAQ;EAAG,GAE1B,IAAAA,QAAE,EAAE,OAAQ,CACP,CACL,CACD,CAAC;AAEP,CAAC;AAAC,IAAAQ,QAAA,GAEa/B,cAAc;AAAAgC,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
1
+ {"version":3,"names":["_classnames","_interopRequireDefault","require","_components","_i18n","_data","_interface","_editor","_constants","_constants2","SettingsHeader","sidebarName","postTypeLabel","useSelect","select","editorStore","getPostTypeLabel","enableComplementaryArea","useDispatch","interfaceStore","openTemplateSettings","STORE_NAME","SIDEBAR_TEMPLATE","openBlockSettings","SIDEBAR_BLOCK","documentAriaLabel","sprintf","__","_react","createElement","Button","onClick","className","classnames","_default","exports","default"],"sources":["@wordpress/edit-site/src/components/sidebar-edit-mode/settings-header/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { Button } from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as interfaceStore } from '@wordpress/interface';\nimport { store as editorStore } from '@wordpress/editor';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from '../../../store/constants';\nimport { SIDEBAR_BLOCK, SIDEBAR_TEMPLATE } from '../constants';\n\nconst SettingsHeader = ( { sidebarName } ) => {\n\tconst postTypeLabel = useSelect(\n\t\t( select ) => select( editorStore ).getPostTypeLabel(),\n\t\t[]\n\t);\n\n\tconst { enableComplementaryArea } = useDispatch( interfaceStore );\n\tconst openTemplateSettings = () =>\n\t\tenableComplementaryArea( STORE_NAME, SIDEBAR_TEMPLATE );\n\tconst openBlockSettings = () =>\n\t\tenableComplementaryArea( STORE_NAME, SIDEBAR_BLOCK );\n\n\tconst documentAriaLabel =\n\t\tsidebarName === SIDEBAR_TEMPLATE\n\t\t\t? // translators: ARIA label for the Template sidebar tab, selected.\n\t\t\t sprintf( __( '%s (selected)' ), postTypeLabel )\n\t\t\t: postTypeLabel;\n\n\t/* Use a list so screen readers will announce how many tabs there are. */\n\treturn (\n\t\t<ul>\n\t\t\t<li>\n\t\t\t\t<Button\n\t\t\t\t\tonClick={ openTemplateSettings }\n\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t'edit-site-sidebar-edit-mode__panel-tab',\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t'is-active': sidebarName === SIDEBAR_TEMPLATE,\n\t\t\t\t\t\t}\n\t\t\t\t\t) }\n\t\t\t\t\taria-label={ documentAriaLabel }\n\t\t\t\t\tdata-label={ postTypeLabel }\n\t\t\t\t>\n\t\t\t\t\t{ postTypeLabel }\n\t\t\t\t</Button>\n\t\t\t</li>\n\t\t\t<li>\n\t\t\t\t<Button\n\t\t\t\t\tonClick={ openBlockSettings }\n\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t'edit-site-sidebar-edit-mode__panel-tab',\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t'is-active': sidebarName === SIDEBAR_BLOCK,\n\t\t\t\t\t\t}\n\t\t\t\t\t) }\n\t\t\t\t\taria-label={\n\t\t\t\t\t\tsidebarName === SIDEBAR_BLOCK\n\t\t\t\t\t\t\t? // translators: ARIA label for the Block Settings Sidebar tab, selected.\n\t\t\t\t\t\t\t __( 'Block (selected)' )\n\t\t\t\t\t\t\t: // translators: ARIA label for the Block Settings Sidebar tab, not selected.\n\t\t\t\t\t\t\t __( 'Block' )\n\t\t\t\t\t}\n\t\t\t\t\tdata-label={ __( 'Block' ) }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Block' ) }\n\t\t\t\t</Button>\n\t\t\t</li>\n\t\t</ul>\n\t);\n};\n\nexport default SettingsHeader;\n"],"mappings":";;;;;;;;AAGA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AAKA,IAAAM,UAAA,GAAAN,OAAA;AACA,IAAAO,WAAA,GAAAP,OAAA;AAlBA;AACA;AACA;;AAGA;AACA;AACA;;AAOA;AACA;AACA;;AAIA,MAAMQ,cAAc,GAAGA,CAAE;EAAEC;AAAY,CAAC,KAAM;EAC7C,MAAMC,aAAa,GAAG,IAAAC,eAAS,EAC5BC,MAAM,IAAMA,MAAM,CAAEC,aAAY,CAAC,CAACC,gBAAgB,CAAC,CAAC,EACtD,EACD,CAAC;EAED,MAAM;IAAEC;EAAwB,CAAC,GAAG,IAAAC,iBAAW,EAAEC,gBAAe,CAAC;EACjE,MAAMC,oBAAoB,GAAGA,CAAA,KAC5BH,uBAAuB,CAAEI,qBAAU,EAAEC,4BAAiB,CAAC;EACxD,MAAMC,iBAAiB,GAAGA,CAAA,KACzBN,uBAAuB,CAAEI,qBAAU,EAAEG,yBAAc,CAAC;EAErD,MAAMC,iBAAiB,GACtBd,WAAW,KAAKW,4BAAgB;EAC7B;EACA,IAAAI,aAAO,EAAE,IAAAC,QAAE,EAAE,eAAgB,CAAC,EAAEf,aAAc,CAAC,GAC/CA,aAAa;;EAEjB;EACA,OACC,IAAAgB,MAAA,CAAAC,aAAA,cACC,IAAAD,MAAA,CAAAC,aAAA,cACC,IAAAD,MAAA,CAAAC,aAAA,EAAC1B,WAAA,CAAA2B,MAAM;IACNC,OAAO,EAAGX,oBAAsB;IAChCY,SAAS,EAAG,IAAAC,mBAAU,EACrB,wCAAwC,EACxC;MACC,WAAW,EAAEtB,WAAW,KAAKW;IAC9B,CACD,CAAG;IACH,cAAaG,iBAAmB;IAChC,cAAab;EAAe,GAE1BA,aACK,CACL,CAAC,EACL,IAAAgB,MAAA,CAAAC,aAAA,cACC,IAAAD,MAAA,CAAAC,aAAA,EAAC1B,WAAA,CAAA2B,MAAM;IACNC,OAAO,EAAGR,iBAAmB;IAC7BS,SAAS,EAAG,IAAAC,mBAAU,EACrB,wCAAwC,EACxC;MACC,WAAW,EAAEtB,WAAW,KAAKa;IAC9B,CACD,CAAG;IACH,cACCb,WAAW,KAAKa,yBAAa;IAC1B;IACA,IAAAG,QAAE,EAAE,kBAAmB,CAAC;IACxB;IACA,IAAAA,QAAE,EAAE,OAAQ,CACf;IACD,cAAa,IAAAA,QAAE,EAAE,OAAQ;EAAG,GAE1B,IAAAA,QAAE,EAAE,OAAQ,CACP,CACL,CACD,CAAC;AAEP,CAAC;AAAC,IAAAO,QAAA,GAEaxB,cAAc;AAAAyB,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
@@ -30,9 +30,9 @@ function WelcomeGuideTemplate() {
30
30
  isPage
31
31
  } = select(_store.store);
32
32
  const {
33
- getRenderingMode
33
+ getCurrentPostType
34
34
  } = select(_editor.store);
35
- return isTemplateActive && !isEditorActive && isPage() && getRenderingMode() === 'template-only';
35
+ return isTemplateActive && !isEditorActive && isPage() && getCurrentPostType() === 'wp_template';
36
36
  }, []);
37
37
  if (!isVisible) {
38
38
  return null;