@wordpress/edit-site 5.14.0 → 5.15.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.
Files changed (341) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/add-new-page/index.js +1 -6
  3. package/build/components/add-new-page/index.js.map +1 -1
  4. package/build/components/add-new-pattern/index.js +21 -7
  5. package/build/components/add-new-pattern/index.js.map +1 -1
  6. package/build/components/add-new-template/utils.js +10 -8
  7. package/build/components/add-new-template/utils.js.map +1 -1
  8. package/build/components/block-editor/constants.js +1 -1
  9. package/build/components/block-editor/constants.js.map +1 -1
  10. package/build/components/block-editor/editor-canvas.js +1 -1
  11. package/build/components/block-editor/editor-canvas.js.map +1 -1
  12. package/build/components/block-editor/index.js +0 -4
  13. package/build/components/block-editor/index.js.map +1 -1
  14. package/build/components/block-editor/use-site-editor-settings.js +87 -13
  15. package/build/components/block-editor/use-site-editor-settings.js.map +1 -1
  16. package/build/components/code-editor/index.js +60 -28
  17. package/build/components/code-editor/index.js.map +1 -1
  18. package/build/components/create-pattern-modal/index.js +7 -3
  19. package/build/components/create-pattern-modal/index.js.map +1 -1
  20. package/build/components/editor/index.js +1 -1
  21. package/build/components/editor/index.js.map +1 -1
  22. package/build/components/header-edit-mode/index.js +13 -9
  23. package/build/components/header-edit-mode/index.js.map +1 -1
  24. package/build/components/layout/index.js +8 -3
  25. package/build/components/layout/index.js.map +1 -1
  26. package/build/components/page-actions/index.js +2 -2
  27. package/build/components/page-actions/index.js.map +1 -1
  28. package/build/components/page-actions/{delete-page-menu-item.js → trash-page-menu-item.js} +8 -16
  29. package/build/components/page-actions/trash-page-menu-item.js.map +1 -0
  30. package/build/components/page-content-focus-manager/disable-non-page-content-blocks.js +5 -5
  31. package/build/components/page-content-focus-manager/disable-non-page-content-blocks.js.map +1 -1
  32. package/build/components/page-patterns/duplicate-menu-item.js +163 -0
  33. package/build/components/page-patterns/duplicate-menu-item.js.map +1 -0
  34. package/build/components/page-patterns/grid-item.js +83 -58
  35. package/build/components/page-patterns/grid-item.js.map +1 -1
  36. package/build/components/page-patterns/grid.js +5 -18
  37. package/build/components/page-patterns/grid.js.map +1 -1
  38. package/build/components/page-patterns/header.js +69 -0
  39. package/build/components/page-patterns/header.js.map +1 -0
  40. package/build/components/page-patterns/index.js +3 -1
  41. package/build/components/page-patterns/index.js.map +1 -1
  42. package/build/components/page-patterns/pagination.js +63 -0
  43. package/build/components/page-patterns/pagination.js.map +1 -0
  44. package/build/components/page-patterns/patterns-list.js +95 -30
  45. package/build/components/page-patterns/patterns-list.js.map +1 -1
  46. package/build/components/page-patterns/rename-menu-item.js +109 -0
  47. package/build/components/page-patterns/rename-menu-item.js.map +1 -0
  48. package/build/components/page-patterns/use-patterns.js +102 -121
  49. package/build/components/page-patterns/use-patterns.js.map +1 -1
  50. package/build/components/page-template-parts/add-new-template-part.js +74 -0
  51. package/build/components/page-template-parts/add-new-template-part.js.map +1 -0
  52. package/build/components/page-template-parts/index.js +2 -23
  53. package/build/components/page-template-parts/index.js.map +1 -1
  54. package/build/components/resizable-frame/index.js +78 -36
  55. package/build/components/resizable-frame/index.js.map +1 -1
  56. package/build/components/save-panel/index.js +5 -5
  57. package/build/components/save-panel/index.js.map +1 -1
  58. package/build/components/sidebar-edit-mode/page-panels/page-content.js +4 -3
  59. package/build/components/sidebar-edit-mode/page-panels/page-content.js.map +1 -1
  60. package/build/components/sidebar-edit-mode/page-panels/page-status.js +3 -8
  61. package/build/components/sidebar-edit-mode/page-panels/page-status.js.map +1 -1
  62. package/build/components/sidebar-navigation-screen/index.js +14 -8
  63. package/build/components/sidebar-navigation-screen/index.js.map +1 -1
  64. package/build/components/sidebar-navigation-screen-main/index.js +4 -2
  65. package/build/components/sidebar-navigation-screen-main/index.js.map +1 -1
  66. package/build/components/sidebar-navigation-screen-main/template-part-hint.js +45 -0
  67. package/build/components/sidebar-navigation-screen-main/template-part-hint.js.map +1 -0
  68. package/build/components/sidebar-navigation-screen-navigation-menu/index.js +4 -4
  69. package/build/components/sidebar-navigation-screen-navigation-menu/index.js.map +1 -1
  70. package/build/components/sidebar-navigation-screen-navigation-menu/more-menu.js +1 -0
  71. package/build/components/sidebar-navigation-screen-navigation-menu/more-menu.js.map +1 -1
  72. package/build/components/sidebar-navigation-screen-navigation-menu/single-navigation-menu.js +3 -3
  73. package/build/components/sidebar-navigation-screen-navigation-menu/single-navigation-menu.js.map +1 -1
  74. package/build/components/sidebar-navigation-screen-navigation-menu/use-navigation-menu-handlers.js +4 -3
  75. package/build/components/sidebar-navigation-screen-navigation-menu/use-navigation-menu-handlers.js.map +1 -1
  76. package/build/components/sidebar-navigation-screen-navigation-menus/constants.js +2 -0
  77. package/build/components/sidebar-navigation-screen-navigation-menus/constants.js.map +1 -1
  78. package/build/components/sidebar-navigation-screen-page/index.js +2 -3
  79. package/build/components/sidebar-navigation-screen-page/index.js.map +1 -1
  80. package/build/components/sidebar-navigation-screen-page/status-label.js +1 -34
  81. package/build/components/sidebar-navigation-screen-page/status-label.js.map +1 -1
  82. package/build/components/sidebar-navigation-screen-pages/index.js +33 -25
  83. package/build/components/sidebar-navigation-screen-pages/index.js.map +1 -1
  84. package/build/components/sidebar-navigation-screen-pattern/index.js +9 -7
  85. package/build/components/sidebar-navigation-screen-pattern/index.js.map +1 -1
  86. package/build/components/sidebar-navigation-screen-pattern/template-part-navigation-menu.js +3 -2
  87. package/build/components/sidebar-navigation-screen-pattern/template-part-navigation-menu.js.map +1 -1
  88. package/build/components/sidebar-navigation-screen-pattern/template-part-navigation-menus.js +3 -2
  89. package/build/components/sidebar-navigation-screen-pattern/template-part-navigation-menus.js.map +1 -1
  90. package/build/components/sidebar-navigation-screen-pattern/use-navigation-menu-content.js +11 -3
  91. package/build/components/sidebar-navigation-screen-pattern/use-navigation-menu-content.js.map +1 -1
  92. package/build/components/sidebar-navigation-screen-pattern/use-pattern-details.js +5 -2
  93. package/build/components/sidebar-navigation-screen-pattern/use-pattern-details.js.map +1 -1
  94. package/build/components/sidebar-navigation-screen-patterns/index.js +72 -51
  95. package/build/components/sidebar-navigation-screen-patterns/index.js.map +1 -1
  96. package/build/components/sidebar-navigation-screen-patterns/use-my-patterns.js +9 -5
  97. package/build/components/sidebar-navigation-screen-patterns/use-my-patterns.js.map +1 -1
  98. package/build/components/sidebar-navigation-screen-patterns/use-pattern-categories.js +11 -1
  99. package/build/components/sidebar-navigation-screen-patterns/use-pattern-categories.js.map +1 -1
  100. package/build/components/sidebar-navigation-screen-patterns/use-template-part-areas.js +20 -9
  101. package/build/components/sidebar-navigation-screen-patterns/use-template-part-areas.js.map +1 -1
  102. package/build/components/sidebar-navigation-screen-patterns/use-theme-patterns.js +1 -1
  103. package/build/components/sidebar-navigation-screen-patterns/use-theme-patterns.js.map +1 -1
  104. package/build/components/site-hub/index.js +24 -11
  105. package/build/components/site-hub/index.js.map +1 -1
  106. package/build/components/sync-state-with-url/use-init-edited-entity-from-url.js +10 -5
  107. package/build/components/sync-state-with-url/use-init-edited-entity-from-url.js.map +1 -1
  108. package/build/components/sync-state-with-url/use-sync-path-with-url.js +15 -12
  109. package/build/components/sync-state-with-url/use-sync-path-with-url.js.map +1 -1
  110. package/build/components/template-actions/index.js +3 -1
  111. package/build/components/template-actions/index.js.map +1 -1
  112. package/build/components/template-actions/rename-menu-item.js +12 -8
  113. package/build/components/template-actions/rename-menu-item.js.map +1 -1
  114. package/build/components/use-edited-entity-record/index.js +6 -1
  115. package/build/components/use-edited-entity-record/index.js.map +1 -1
  116. package/build/hooks/commands/use-common-commands.js +78 -20
  117. package/build/hooks/commands/use-common-commands.js.map +1 -1
  118. package/build/hooks/push-changes-to-global-styles/index.js +56 -10
  119. package/build/hooks/push-changes-to-global-styles/index.js.map +1 -1
  120. package/build/store/private-actions.js +7 -1
  121. package/build/store/private-actions.js.map +1 -1
  122. package/build/utils/normalize-record-key.js +19 -0
  123. package/build/utils/normalize-record-key.js.map +1 -0
  124. package/build/utils/use-activate-theme.js +1 -1
  125. package/build/utils/use-activate-theme.js.map +1 -1
  126. package/build-module/components/add-new-page/index.js +1 -6
  127. package/build-module/components/add-new-page/index.js.map +1 -1
  128. package/build-module/components/add-new-pattern/index.js +19 -7
  129. package/build-module/components/add-new-pattern/index.js.map +1 -1
  130. package/build-module/components/add-new-template/utils.js +9 -6
  131. package/build-module/components/add-new-template/utils.js.map +1 -1
  132. package/build-module/components/block-editor/constants.js +1 -1
  133. package/build-module/components/block-editor/constants.js.map +1 -1
  134. package/build-module/components/block-editor/editor-canvas.js +1 -1
  135. package/build-module/components/block-editor/editor-canvas.js.map +1 -1
  136. package/build-module/components/block-editor/index.js +0 -4
  137. package/build-module/components/block-editor/index.js.map +1 -1
  138. package/build-module/components/block-editor/use-site-editor-settings.js +89 -14
  139. package/build-module/components/block-editor/use-site-editor-settings.js.map +1 -1
  140. package/build-module/components/code-editor/index.js +62 -30
  141. package/build-module/components/code-editor/index.js.map +1 -1
  142. package/build-module/components/create-pattern-modal/index.js +6 -3
  143. package/build-module/components/create-pattern-modal/index.js.map +1 -1
  144. package/build-module/components/editor/index.js +1 -1
  145. package/build-module/components/editor/index.js.map +1 -1
  146. package/build-module/components/header-edit-mode/index.js +13 -9
  147. package/build-module/components/header-edit-mode/index.js.map +1 -1
  148. package/build-module/components/layout/index.js +8 -3
  149. package/build-module/components/layout/index.js.map +1 -1
  150. package/build-module/components/page-actions/index.js +2 -2
  151. package/build-module/components/page-actions/index.js.map +1 -1
  152. package/build-module/components/page-actions/{delete-page-menu-item.js → trash-page-menu-item.js} +8 -17
  153. package/build-module/components/page-actions/trash-page-menu-item.js.map +1 -0
  154. package/build-module/components/page-content-focus-manager/disable-non-page-content-blocks.js +5 -3
  155. package/build-module/components/page-content-focus-manager/disable-non-page-content-blocks.js.map +1 -1
  156. package/build-module/components/page-patterns/duplicate-menu-item.js +147 -0
  157. package/build-module/components/page-patterns/duplicate-menu-item.js.map +1 -0
  158. package/build-module/components/page-patterns/grid-item.js +84 -64
  159. package/build-module/components/page-patterns/grid-item.js.map +1 -1
  160. package/build-module/components/page-patterns/grid.js +5 -17
  161. package/build-module/components/page-patterns/grid.js.map +1 -1
  162. package/build-module/components/page-patterns/header.js +54 -0
  163. package/build-module/components/page-patterns/header.js.map +1 -0
  164. package/build-module/components/page-patterns/index.js +3 -1
  165. package/build-module/components/page-patterns/index.js.map +1 -1
  166. package/build-module/components/page-patterns/pagination.js +54 -0
  167. package/build-module/components/page-patterns/pagination.js.map +1 -0
  168. package/build-module/components/page-patterns/patterns-list.js +96 -33
  169. package/build-module/components/page-patterns/patterns-list.js.map +1 -1
  170. package/build-module/components/page-patterns/rename-menu-item.js +97 -0
  171. package/build-module/components/page-patterns/rename-menu-item.js.map +1 -0
  172. package/build-module/components/page-patterns/use-patterns.js +103 -122
  173. package/build-module/components/page-patterns/use-patterns.js.map +1 -1
  174. package/build-module/components/page-template-parts/add-new-template-part.js +58 -0
  175. package/build-module/components/page-template-parts/add-new-template-part.js.map +1 -0
  176. package/build-module/components/page-template-parts/index.js +3 -22
  177. package/build-module/components/page-template-parts/index.js.map +1 -1
  178. package/build-module/components/resizable-frame/index.js +79 -39
  179. package/build-module/components/resizable-frame/index.js.map +1 -1
  180. package/build-module/components/save-panel/index.js +5 -5
  181. package/build-module/components/save-panel/index.js.map +1 -1
  182. package/build-module/components/sidebar-edit-mode/page-panels/page-content.js +5 -2
  183. package/build-module/components/sidebar-edit-mode/page-panels/page-content.js.map +1 -1
  184. package/build-module/components/sidebar-edit-mode/page-panels/page-status.js +3 -8
  185. package/build-module/components/sidebar-edit-mode/page-panels/page-status.js.map +1 -1
  186. package/build-module/components/sidebar-navigation-screen/index.js +15 -9
  187. package/build-module/components/sidebar-navigation-screen/index.js.map +1 -1
  188. package/build-module/components/sidebar-navigation-screen-main/index.js +4 -3
  189. package/build-module/components/sidebar-navigation-screen-main/index.js.map +1 -1
  190. package/build-module/components/sidebar-navigation-screen-main/template-part-hint.js +33 -0
  191. package/build-module/components/sidebar-navigation-screen-main/template-part-hint.js.map +1 -0
  192. package/build-module/components/sidebar-navigation-screen-navigation-menu/index.js +4 -4
  193. package/build-module/components/sidebar-navigation-screen-navigation-menu/index.js.map +1 -1
  194. package/build-module/components/sidebar-navigation-screen-navigation-menu/more-menu.js +1 -0
  195. package/build-module/components/sidebar-navigation-screen-navigation-menu/more-menu.js.map +1 -1
  196. package/build-module/components/sidebar-navigation-screen-navigation-menu/single-navigation-menu.js +3 -3
  197. package/build-module/components/sidebar-navigation-screen-navigation-menu/single-navigation-menu.js.map +1 -1
  198. package/build-module/components/sidebar-navigation-screen-navigation-menu/use-navigation-menu-handlers.js +4 -3
  199. package/build-module/components/sidebar-navigation-screen-navigation-menu/use-navigation-menu-handlers.js.map +1 -1
  200. package/build-module/components/sidebar-navigation-screen-navigation-menus/constants.js +2 -0
  201. package/build-module/components/sidebar-navigation-screen-navigation-menus/constants.js.map +1 -1
  202. package/build-module/components/sidebar-navigation-screen-page/index.js +2 -3
  203. package/build-module/components/sidebar-navigation-screen-page/index.js.map +1 -1
  204. package/build-module/components/sidebar-navigation-screen-page/status-label.js +1 -32
  205. package/build-module/components/sidebar-navigation-screen-page/status-label.js.map +1 -1
  206. package/build-module/components/sidebar-navigation-screen-pages/index.js +33 -25
  207. package/build-module/components/sidebar-navigation-screen-pages/index.js.map +1 -1
  208. package/build-module/components/sidebar-navigation-screen-pattern/index.js +8 -7
  209. package/build-module/components/sidebar-navigation-screen-pattern/index.js.map +1 -1
  210. package/build-module/components/sidebar-navigation-screen-pattern/template-part-navigation-menu.js +3 -2
  211. package/build-module/components/sidebar-navigation-screen-pattern/template-part-navigation-menu.js.map +1 -1
  212. package/build-module/components/sidebar-navigation-screen-pattern/template-part-navigation-menus.js +3 -2
  213. package/build-module/components/sidebar-navigation-screen-pattern/template-part-navigation-menus.js.map +1 -1
  214. package/build-module/components/sidebar-navigation-screen-pattern/use-navigation-menu-content.js +11 -3
  215. package/build-module/components/sidebar-navigation-screen-pattern/use-navigation-menu-content.js.map +1 -1
  216. package/build-module/components/sidebar-navigation-screen-pattern/use-pattern-details.js +4 -2
  217. package/build-module/components/sidebar-navigation-screen-pattern/use-pattern-details.js.map +1 -1
  218. package/build-module/components/sidebar-navigation-screen-patterns/index.js +76 -53
  219. package/build-module/components/sidebar-navigation-screen-patterns/index.js.map +1 -1
  220. package/build-module/components/sidebar-navigation-screen-patterns/use-my-patterns.js +9 -5
  221. package/build-module/components/sidebar-navigation-screen-patterns/use-my-patterns.js.map +1 -1
  222. package/build-module/components/sidebar-navigation-screen-patterns/use-pattern-categories.js +10 -1
  223. package/build-module/components/sidebar-navigation-screen-patterns/use-pattern-categories.js.map +1 -1
  224. package/build-module/components/sidebar-navigation-screen-patterns/use-template-part-areas.js +18 -9
  225. package/build-module/components/sidebar-navigation-screen-patterns/use-template-part-areas.js.map +1 -1
  226. package/build-module/components/sidebar-navigation-screen-patterns/use-theme-patterns.js +1 -1
  227. package/build-module/components/sidebar-navigation-screen-patterns/use-theme-patterns.js.map +1 -1
  228. package/build-module/components/site-hub/index.js +24 -11
  229. package/build-module/components/site-hub/index.js.map +1 -1
  230. package/build-module/components/sync-state-with-url/use-init-edited-entity-from-url.js +7 -5
  231. package/build-module/components/sync-state-with-url/use-init-edited-entity-from-url.js.map +1 -1
  232. package/build-module/components/sync-state-with-url/use-sync-path-with-url.js +16 -12
  233. package/build-module/components/sync-state-with-url/use-sync-path-with-url.js.map +1 -1
  234. package/build-module/components/template-actions/index.js +2 -1
  235. package/build-module/components/template-actions/index.js.map +1 -1
  236. package/build-module/components/template-actions/rename-menu-item.js +11 -8
  237. package/build-module/components/template-actions/rename-menu-item.js.map +1 -1
  238. package/build-module/components/use-edited-entity-record/index.js +3 -1
  239. package/build-module/components/use-edited-entity-record/index.js.map +1 -1
  240. package/build-module/hooks/commands/use-common-commands.js +74 -20
  241. package/build-module/hooks/commands/use-common-commands.js.map +1 -1
  242. package/build-module/hooks/push-changes-to-global-styles/index.js +57 -10
  243. package/build-module/hooks/push-changes-to-global-styles/index.js.map +1 -1
  244. package/build-module/store/private-actions.js +7 -1
  245. package/build-module/store/private-actions.js.map +1 -1
  246. package/build-module/utils/normalize-record-key.js +12 -0
  247. package/build-module/utils/normalize-record-key.js.map +1 -0
  248. package/build-module/utils/use-activate-theme.js +1 -1
  249. package/build-module/utils/use-activate-theme.js.map +1 -1
  250. package/build-style/style-rtl.css +221 -63
  251. package/build-style/style.css +221 -63
  252. package/package.json +39 -40
  253. package/src/components/add-new-page/index.js +0 -3
  254. package/src/components/add-new-pattern/index.js +23 -12
  255. package/src/components/add-new-template/utils.js +9 -6
  256. package/src/components/block-editor/constants.js +5 -1
  257. package/src/components/block-editor/editor-canvas.js +1 -1
  258. package/src/components/block-editor/index.js +0 -4
  259. package/src/components/block-editor/use-site-editor-settings.js +99 -20
  260. package/src/components/canvas-spinner/style.scss +14 -0
  261. package/src/components/code-editor/index.js +51 -33
  262. package/src/components/create-pattern-modal/index.js +5 -2
  263. package/src/components/editor/index.js +2 -2
  264. package/src/components/header-edit-mode/document-actions/style.scss +4 -0
  265. package/src/components/header-edit-mode/index.js +29 -22
  266. package/src/components/layout/index.js +16 -2
  267. package/src/components/layout/style.scss +2 -1
  268. package/src/components/page-actions/index.js +2 -2
  269. package/src/components/page-actions/{delete-page-menu-item.js → trash-page-menu-item.js} +9 -22
  270. package/src/components/page-content-focus-manager/disable-non-page-content-blocks.js +12 -3
  271. package/src/components/page-patterns/duplicate-menu-item.js +196 -0
  272. package/src/components/page-patterns/grid-item.js +189 -133
  273. package/src/components/page-patterns/grid.js +3 -20
  274. package/src/components/page-patterns/header.js +69 -0
  275. package/src/components/page-patterns/index.js +6 -1
  276. package/src/components/page-patterns/pagination.js +80 -0
  277. package/src/components/page-patterns/patterns-list.js +160 -72
  278. package/src/components/page-patterns/rename-menu-item.js +115 -0
  279. package/src/components/page-patterns/style.scss +140 -30
  280. package/src/components/page-patterns/use-patterns.js +102 -172
  281. package/src/components/page-template-parts/add-new-template-part.js +57 -0
  282. package/src/components/page-template-parts/index.js +3 -22
  283. package/src/components/resizable-frame/index.js +102 -34
  284. package/src/components/resizable-frame/style.scss +9 -9
  285. package/src/components/save-panel/index.js +10 -4
  286. package/src/components/sidebar-edit-mode/page-panels/page-content.js +7 -5
  287. package/src/components/sidebar-edit-mode/page-panels/page-status.js +2 -5
  288. package/src/components/sidebar-navigation-item/style.scss +5 -12
  289. package/src/components/sidebar-navigation-screen/index.js +14 -7
  290. package/src/components/sidebar-navigation-screen/style.scss +14 -0
  291. package/src/components/sidebar-navigation-screen-main/index.js +44 -40
  292. package/src/components/sidebar-navigation-screen-main/template-part-hint.js +34 -0
  293. package/src/components/sidebar-navigation-screen-navigation-menu/index.js +4 -3
  294. package/src/components/sidebar-navigation-screen-navigation-menu/more-menu.js +1 -0
  295. package/src/components/sidebar-navigation-screen-navigation-menu/single-navigation-menu.js +1 -1
  296. package/src/components/sidebar-navigation-screen-navigation-menu/use-navigation-menu-handlers.js +15 -5
  297. package/src/components/sidebar-navigation-screen-navigation-menus/constants.js +2 -0
  298. package/src/components/sidebar-navigation-screen-page/index.js +3 -3
  299. package/src/components/sidebar-navigation-screen-page/status-label.js +1 -35
  300. package/src/components/sidebar-navigation-screen-pages/index.js +39 -29
  301. package/src/components/sidebar-navigation-screen-pattern/index.js +5 -2
  302. package/src/components/sidebar-navigation-screen-pattern/template-part-navigation-menu.js +2 -1
  303. package/src/components/sidebar-navigation-screen-pattern/template-part-navigation-menus.js +2 -1
  304. package/src/components/sidebar-navigation-screen-pattern/use-navigation-menu-content.js +12 -2
  305. package/src/components/sidebar-navigation-screen-pattern/use-pattern-details.js +5 -2
  306. package/src/components/sidebar-navigation-screen-patterns/index.js +103 -98
  307. package/src/components/sidebar-navigation-screen-patterns/style.scss +20 -0
  308. package/src/components/sidebar-navigation-screen-patterns/use-my-patterns.js +7 -6
  309. package/src/components/sidebar-navigation-screen-patterns/use-pattern-categories.js +9 -0
  310. package/src/components/sidebar-navigation-screen-patterns/use-template-part-areas.js +31 -9
  311. package/src/components/sidebar-navigation-screen-patterns/use-theme-patterns.js +2 -1
  312. package/src/components/site-hub/index.js +45 -28
  313. package/src/components/site-hub/style.scss +13 -0
  314. package/src/components/sync-state-with-url/use-init-edited-entity-from-url.js +8 -2
  315. package/src/components/sync-state-with-url/use-sync-path-with-url.js +73 -66
  316. package/src/components/template-actions/index.js +2 -1
  317. package/src/components/template-actions/rename-menu-item.js +17 -10
  318. package/src/components/use-edited-entity-record/index.js +6 -1
  319. package/src/hooks/commands/use-common-commands.js +56 -23
  320. package/src/hooks/push-changes-to-global-styles/index.js +63 -9
  321. package/src/store/private-actions.js +5 -1
  322. package/src/style.scss +10 -12
  323. package/src/utils/normalize-record-key.js +11 -0
  324. package/src/utils/use-activate-theme.js +1 -1
  325. package/build/components/code-editor/code-editor-text-area.js +0 -96
  326. package/build/components/code-editor/code-editor-text-area.js.map +0 -1
  327. package/build/components/keyboard-shortcuts/index.js +0 -148
  328. package/build/components/keyboard-shortcuts/index.js.map +0 -1
  329. package/build/components/page-actions/delete-page-menu-item.js.map +0 -1
  330. package/build/components/page-content-focus-manager/constants.js +0 -9
  331. package/build/components/page-content-focus-manager/constants.js.map +0 -1
  332. package/build-module/components/code-editor/code-editor-text-area.js +0 -84
  333. package/build-module/components/code-editor/code-editor-text-area.js.map +0 -1
  334. package/build-module/components/keyboard-shortcuts/index.js +0 -132
  335. package/build-module/components/keyboard-shortcuts/index.js.map +0 -1
  336. package/build-module/components/page-actions/delete-page-menu-item.js.map +0 -1
  337. package/build-module/components/page-content-focus-manager/constants.js +0 -2
  338. package/build-module/components/page-content-focus-manager/constants.js.map +0 -1
  339. package/src/components/code-editor/code-editor-text-area.js +0 -84
  340. package/src/components/keyboard-shortcuts/index.js +0 -137
  341. package/src/components/page-content-focus-manager/constants.js +0 -5
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/template-actions/index.js"],"names":["TemplateActions","postType","postId","className","toggleProps","onRemove","template","select","coreStore","getEntityRecord","removeTemplate","revertTemplate","editSiteStore","saveEditedEntityRecord","createSuccessNotice","createErrorNotice","noticesStore","isRemovable","isRevertable","revertAndSaveTemplate","allowUndo","type","id","title","rendered","error","errorMessage","message","code","moreVertical","onClose","DeleteMenuItem","isTemplate","isModalOpen","setIsModalOpen"],"mappings":";;;;;;;;;AAKA;;AAFA;;AACA;;AAEA;;AACA;;AAMA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AAtBA;AACA;AACA;;AAcA;AACA;AACA;AAMe,SAASA,eAAT,CAA0B;AACxCC,EAAAA,QADwC;AAExCC,EAAAA,MAFwC;AAGxCC,EAAAA,SAHwC;AAIxCC,EAAAA,WAJwC;AAKxCC,EAAAA;AALwC,CAA1B,EAMX;AACH,QAAMC,QAAQ,GAAG,qBACdC,MAAF,IACCA,MAAM,CAAEC,eAAF,CAAN,CAAoBC,eAApB,CAAqC,UAArC,EAAiDR,QAAjD,EAA2DC,MAA3D,CAFe,EAGhB,CAAED,QAAF,EAAYC,MAAZ,CAHgB,CAAjB;AAKA,QAAM;AAAEQ,IAAAA,cAAF;AAAkBC,IAAAA;AAAlB,MAAqC,uBAAaC,YAAb,CAA3C;AACA,QAAM;AAAEC,IAAAA;AAAF,MAA6B,uBAAaL,eAAb,CAAnC;AACA,QAAM;AAAEM,IAAAA,mBAAF;AAAuBC,IAAAA;AAAvB,MACL,uBAAaC,cAAb,CADD;AAEA,QAAMC,WAAW,GAAG,kCAAqBX,QAArB,CAApB;AACA,QAAMY,YAAY,GAAG,mCAAsBZ,QAAtB,CAArB;;AAEA,MAAK,CAAEW,WAAF,IAAiB,CAAEC,YAAxB,EAAuC;AACtC,WAAO,IAAP;AACA;;AAED,iBAAeC,qBAAf,GAAuC;AACtC,QAAI;AACH,YAAMR,cAAc,CAAEL,QAAF,EAAY;AAAEc,QAAAA,SAAS,EAAE;AAAb,OAAZ,CAApB;AACA,YAAMP,sBAAsB,CAC3B,UAD2B,EAE3BP,QAAQ,CAACe,IAFkB,EAG3Bf,QAAQ,CAACgB,EAHkB,C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AAT,CAAyB;AAAE1B,EAAAA,QAAF;AAAY2B,EAAAA;AAAZ,CAAzB,EAAoD;AACnD,QAAM,CAAEC,WAAF,EAAeC,cAAf,IAAkC,uBAAU,KAAV,CAAxC;AACA,SACC,qDACC,4BAAC,oBAAD;AACC,IAAA,aAAa,MADd;AAEC,IAAA,UAAU,MAFX;AAGC,IAAA,OAAO,EAAG,MAAMA,cAAc,CAAE,IAAF;AAH/B,KAKG,cAAI,QAAJ,CALH,CADD,EAQC,4BAAC,uCAAD;AACC,IAAA,MAAM,EAAGD,WADV;AAEC,IAAA,SAAS,EAAG5B,QAFb;AAGC,IAAA,QAAQ,EAAG,MAAM6B,cAAc,CAAE,KAAF,CAHhC;AAIC,IAAA,iBAAiB,EAAG,cAAI,QAAJ;AAJrB,KAMGF,UAAU,GACT,cAAI,gDAAJ,CADS,GAET,cACA,qDADA,CARJ,CARD,CADD;AAuBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useState } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tDropdownMenu,\n\tMenuGroup,\n\tMenuItem,\n\t__experimentalConfirmDialog as ConfirmDialog,\n} from '@wordpress/components';\nimport { moreVertical } from '@wordpress/icons';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport { store as editSiteStore } from '../../store';\nimport isTemplateRemovable from '../../utils/is-template-removable';\nimport isTemplateRevertable from '../../utils/is-template-revertable';\nimport RenameMenuItem from './rename-menu-item';\n\nexport default function TemplateActions( {\n\tpostType,\n\tpostId,\n\tclassName,\n\ttoggleProps,\n\tonRemove,\n} ) {\n\tconst template = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getEntityRecord( 'postType', postType, postId ),\n\t\t[ postType, postId ]\n\t);\n\tconst { removeTemplate, revertTemplate } = useDispatch( editSiteStore );\n\tconst { saveEditedEntityRecord } = useDispatch( coreStore );\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\tconst isRemovable = isTemplateRemovable( template );\n\tconst isRevertable = isTemplateRevertable( template );\n\n\tif ( ! isRemovable && ! isRevertable ) {\n\t\treturn null;\n\t}\n\n\tasync function revertAndSaveTemplate() {\n\t\ttry {\n\t\t\tawait revertTemplate( template, { allowUndo: false } );\n\t\t\tawait saveEditedEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\ttemplate.type,\n\t\t\t\ttemplate.id\n\t\t\t);\n\n\t\t\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t/* translators: The template/part's name. */\n\t\t\t\t\t__( '\"%s\" reverted.' ),\n\t\t\t\t\ttemplate.title.rendered\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tid: 'edit-site-template-reverted',\n\t\t\t\t}\n\t\t\t);\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __( 'An error occurred while reverting the entity.' );\n\n\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\t\t}\n\t}\n\n\treturn (\n\t\t<DropdownMenu\n\t\t\ticon={ moreVertical }\n\t\t\tlabel={ __( 'Actions' ) }\n\t\t\tclassName={ className }\n\t\t\ttoggleProps={ toggleProps }\n\t\t>\n\t\t\t{ ( { onClose } ) => (\n\t\t\t\t<MenuGroup>\n\t\t\t\t\t{ isRemovable && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<RenameMenuItem\n\t\t\t\t\t\t\t\ttemplate={ template }\n\t\t\t\t\t\t\t\tonClose={ onClose }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<DeleteMenuItem\n\t\t\t\t\t\t\t\tonRemove={ () => {\n\t\t\t\t\t\t\t\t\tremoveTemplate( template );\n\t\t\t\t\t\t\t\t\tonRemove?.();\n\t\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\tisTemplate={ template.type === 'wp_template' }\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\t{ isRevertable && (\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\tinfo={ __(\n\t\t\t\t\t\t\t\t'Use the template as supplied by the theme.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\trevertAndSaveTemplate();\n\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Clear customizations' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t) }\n\t\t\t\t</MenuGroup>\n\t\t\t) }\n\t\t</DropdownMenu>\n\t);\n}\n\nfunction DeleteMenuItem( { onRemove, isTemplate } ) {\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\treturn (\n\t\t<>\n\t\t\t<MenuItem\n\t\t\t\tisDestructive\n\t\t\t\tisTertiary\n\t\t\t\tonClick={ () => setIsModalOpen( true ) }\n\t\t\t>\n\t\t\t\t{ __( 'Delete' ) }\n\t\t\t</MenuItem>\n\t\t\t<ConfirmDialog\n\t\t\t\tisOpen={ isModalOpen }\n\t\t\t\tonConfirm={ onRemove }\n\t\t\t\tonCancel={ () => setIsModalOpen( false ) }\n\t\t\t\tconfirmButtonText={ __( 'Delete' ) }\n\t\t\t>\n\t\t\t\t{ isTemplate\n\t\t\t\t\t? __( 'Are you sure you want to delete this template?' )\n\t\t\t\t\t: __(\n\t\t\t\t\t\t\t'Are you sure you want to delete this template part?'\n\t\t\t\t\t ) }\n\t\t\t</ConfirmDialog>\n\t\t</>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-site/src/components/template-actions/index.js"],"names":["TemplateActions","postType","postId","className","toggleProps","onRemove","template","select","coreStore","getEntityRecord","removeTemplate","revertTemplate","editSiteStore","saveEditedEntityRecord","createSuccessNotice","createErrorNotice","noticesStore","isRemovable","isRevertable","revertAndSaveTemplate","allowUndo","type","id","title","rendered","error","errorMessage","message","code","moreVertical","onClose","DeleteMenuItem","isTemplate","isModalOpen","setIsModalOpen"],"mappings":";;;;;;;;;AAKA;;AAFA;;AACA;;AAEA;;AACA;;AAMA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AAvBA;AACA;AACA;;AAeA;AACA;AACA;AAMe,SAASA,eAAT,CAA0B;AACxCC,EAAAA,QADwC;AAExCC,EAAAA,MAFwC;AAGxCC,EAAAA,SAHwC;AAIxCC,EAAAA,WAJwC;AAKxCC,EAAAA;AALwC,CAA1B,EAMX;AACH,QAAMC,QAAQ,GAAG,qBACdC,MAAF,IACCA,MAAM,CAAEC,eAAF,CAAN,CAAoBC,eAApB,CAAqC,UAArC,EAAiDR,QAAjD,EAA2DC,MAA3D,CAFe,EAGhB,CAAED,QAAF,EAAYC,MAAZ,CAHgB,CAAjB;AAKA,QAAM;AAAEQ,IAAAA,cAAF;AAAkBC,IAAAA;AAAlB,MAAqC,uBAAaC,YAAb,CAA3C;AACA,QAAM;AAAEC,IAAAA;AAAF,MAA6B,uBAAaL,eAAb,CAAnC;AACA,QAAM;AAAEM,IAAAA,mBAAF;AAAuBC,IAAAA;AAAvB,MACL,uBAAaC,cAAb,CADD;AAEA,QAAMC,WAAW,GAAG,kCAAqBX,QAArB,CAApB;AACA,QAAMY,YAAY,GAAG,mCAAsBZ,QAAtB,CAArB;;AAEA,MAAK,CAAEW,WAAF,IAAiB,CAAEC,YAAxB,EAAuC;AACtC,WAAO,IAAP;AACA;;AAED,iBAAeC,qBAAf,GAAuC;AACtC,QAAI;AACH,YAAMR,cAAc,CAAEL,QAAF,EAAY;AAAEc,QAAAA,SAAS,EAAE;AAAb,OAAZ,CAApB;AACA,YAAMP,sBAAsB,CAC3B,UAD2B,EA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AACP;AAPF,KASG,cAAI,sBAAJ,CATH,CAlBF,CAPF,CADD;AA0CA;;AAED,SAASC,cAAT,CAAyB;AAAE1B,EAAAA,QAAF;AAAY2B,EAAAA;AAAZ,CAAzB,EAAoD;AACnD,QAAM,CAAEC,WAAF,EAAeC,cAAf,IAAkC,uBAAU,KAAV,CAAxC;AACA,SACC,qDACC,4BAAC,oBAAD;AACC,IAAA,aAAa,MADd;AAEC,IAAA,UAAU,MAFX;AAGC,IAAA,OAAO,EAAG,MAAMA,cAAc,CAAE,IAAF;AAH/B,KAKG,cAAI,QAAJ,CALH,CADD,EAQC,4BAAC,uCAAD;AACC,IAAA,MAAM,EAAGD,WADV;AAEC,IAAA,SAAS,EAAG5B,QAFb;AAGC,IAAA,QAAQ,EAAG,MAAM6B,cAAc,CAAE,KAAF,CAHhC;AAIC,IAAA,iBAAiB,EAAG,cAAI,QAAJ;AAJrB,KAMGF,UAAU,GACT,cAAI,gDAAJ,CADS,GAET,cACA,qDADA,CARJ,CARD,CADD;AAuBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useState } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tDropdownMenu,\n\tMenuGroup,\n\tMenuItem,\n\t__experimentalConfirmDialog as ConfirmDialog,\n} from '@wordpress/components';\nimport { moreVertical } from '@wordpress/icons';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { decodeEntities } from '@wordpress/html-entities';\n\n/**\n * Internal dependencies\n */\nimport { store as editSiteStore } from '../../store';\nimport isTemplateRemovable from '../../utils/is-template-removable';\nimport isTemplateRevertable from '../../utils/is-template-revertable';\nimport RenameMenuItem from './rename-menu-item';\n\nexport default function TemplateActions( {\n\tpostType,\n\tpostId,\n\tclassName,\n\ttoggleProps,\n\tonRemove,\n} ) {\n\tconst template = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getEntityRecord( 'postType', postType, postId ),\n\t\t[ postType, postId ]\n\t);\n\tconst { removeTemplate, revertTemplate } = useDispatch( editSiteStore );\n\tconst { saveEditedEntityRecord } = useDispatch( coreStore );\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\tconst isRemovable = isTemplateRemovable( template );\n\tconst isRevertable = isTemplateRevertable( template );\n\n\tif ( ! isRemovable && ! isRevertable ) {\n\t\treturn null;\n\t}\n\n\tasync function revertAndSaveTemplate() {\n\t\ttry {\n\t\t\tawait revertTemplate( template, { allowUndo: false } );\n\t\t\tawait saveEditedEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\ttemplate.type,\n\t\t\t\ttemplate.id\n\t\t\t);\n\n\t\t\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t/* translators: The template/part's name. */\n\t\t\t\t\t__( '\"%s\" reverted.' ),\n\t\t\t\t\tdecodeEntities( template.title.rendered )\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tid: 'edit-site-template-reverted',\n\t\t\t\t}\n\t\t\t);\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __( 'An error occurred while reverting the entity.' );\n\n\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\t\t}\n\t}\n\n\treturn (\n\t\t<DropdownMenu\n\t\t\ticon={ moreVertical }\n\t\t\tlabel={ __( 'Actions' ) }\n\t\t\tclassName={ className }\n\t\t\ttoggleProps={ toggleProps }\n\t\t>\n\t\t\t{ ( { onClose } ) => (\n\t\t\t\t<MenuGroup>\n\t\t\t\t\t{ isRemovable && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<RenameMenuItem\n\t\t\t\t\t\t\t\ttemplate={ template }\n\t\t\t\t\t\t\t\tonClose={ onClose }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<DeleteMenuItem\n\t\t\t\t\t\t\t\tonRemove={ () => {\n\t\t\t\t\t\t\t\t\tremoveTemplate( template );\n\t\t\t\t\t\t\t\t\tonRemove?.();\n\t\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\tisTemplate={ template.type === 'wp_template' }\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\t{ isRevertable && (\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\tinfo={ __(\n\t\t\t\t\t\t\t\t'Use the template as supplied by the theme.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\trevertAndSaveTemplate();\n\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Clear customizations' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t) }\n\t\t\t\t</MenuGroup>\n\t\t\t) }\n\t\t</DropdownMenu>\n\t);\n}\n\nfunction DeleteMenuItem( { onRemove, isTemplate } ) {\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\treturn (\n\t\t<>\n\t\t\t<MenuItem\n\t\t\t\tisDestructive\n\t\t\t\tisTertiary\n\t\t\t\tonClick={ () => setIsModalOpen( true ) }\n\t\t\t>\n\t\t\t\t{ __( 'Delete' ) }\n\t\t\t</MenuItem>\n\t\t\t<ConfirmDialog\n\t\t\t\tisOpen={ isModalOpen }\n\t\t\t\tonConfirm={ onRemove }\n\t\t\t\tonCancel={ () => setIsModalOpen( false ) }\n\t\t\t\tconfirmButtonText={ __( 'Delete' ) }\n\t\t\t>\n\t\t\t\t{ isTemplate\n\t\t\t\t\t? __( 'Are you sure you want to delete this template?' )\n\t\t\t\t\t: __(\n\t\t\t\t\t\t\t'Are you sure you want to delete this template part?'\n\t\t\t\t\t ) }\n\t\t\t</ConfirmDialog>\n\t\t</>\n\t);\n}\n"]}
@@ -17,6 +17,8 @@ var _coreData = require("@wordpress/core-data");
17
17
 
18
18
  var _notices = require("@wordpress/notices");
19
19
 
20
+ var _htmlEntities = require("@wordpress/html-entities");
21
+
20
22
  /**
21
23
  * WordPress dependencies
22
24
  */
@@ -24,11 +26,12 @@ function RenameMenuItem({
24
26
  template,
25
27
  onClose
26
28
  }) {
27
- const [title, setTitle] = (0, _element.useState)(() => template.title.rendered);
29
+ const title = (0, _htmlEntities.decodeEntities)(template.title.rendered);
30
+ const [editedTitle, setEditedTitle] = (0, _element.useState)(title);
28
31
  const [isModalOpen, setIsModalOpen] = (0, _element.useState)(false);
29
32
  const {
30
33
  editEntityRecord,
31
- saveEditedEntityRecord
34
+ __experimentalSaveSpecifiedEntityEdits: saveSpecifiedEntityEdits
32
35
  } = (0, _data.useDispatch)(_coreData.store);
33
36
  const {
34
37
  createSuccessNotice,
@@ -44,14 +47,15 @@ function RenameMenuItem({
44
47
 
45
48
  try {
46
49
  await editEntityRecord('postType', template.type, template.id, {
47
- title
50
+ title: editedTitle
48
51
  }); // Update state before saving rerenders the list.
49
52
 
50
- setTitle('');
53
+ setEditedTitle('');
51
54
  setIsModalOpen(false);
52
55
  onClose(); // Persist edited entity.
53
56
 
54
- await saveEditedEntityRecord('postType', template.type, template.id, {
57
+ await saveSpecifiedEntityEdits('postType', template.type, template.id, ['title'], // Only save title to avoid persisting other edits.
58
+ {
55
59
  throwOnError: true
56
60
  });
57
61
  createSuccessNotice((0, _i18n.__)('Entity renamed.'), {
@@ -68,7 +72,7 @@ function RenameMenuItem({
68
72
  return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_components.MenuItem, {
69
73
  onClick: () => {
70
74
  setIsModalOpen(true);
71
- setTitle(template.title.rendered);
75
+ setEditedTitle(title);
72
76
  }
73
77
  }, (0, _i18n.__)('Rename')), isModalOpen && (0, _element.createElement)(_components.Modal, {
74
78
  title: (0, _i18n.__)('Rename'),
@@ -83,8 +87,8 @@ function RenameMenuItem({
83
87
  }, (0, _element.createElement)(_components.TextControl, {
84
88
  __nextHasNoMarginBottom: true,
85
89
  label: (0, _i18n.__)('Name'),
86
- value: title,
87
- onChange: setTitle,
90
+ value: editedTitle,
91
+ onChange: setEditedTitle,
88
92
  required: true
89
93
  }), (0, _element.createElement)(_components.__experimentalHStack, {
90
94
  justify: "right"
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/template-actions/rename-menu-item.js"],"names":["RenameMenuItem","template","onClose","title","setTitle","rendered","isModalOpen","setIsModalOpen","editEntityRecord","saveEditedEntityRecord","coreStore","createSuccessNotice","createErrorNotice","noticesStore","type","is_custom","onTemplateRename","event","preventDefault","id","throwOnError","error","errorMessage","message","code"],"mappings":";;;;;;;AAIA;;AADA;;AAEA;;AACA;;AAQA;;AACA;;AAfA;AACA;AACA;AAee,SAASA,cAAT,CAAyB;AAAEC,EAAAA,QAAF;AAAYC,EAAAA;AAAZ,CAAzB,EAAiD;AAC/D,QAAM,CAAEC,KAAF,EAASC,QAAT,IAAsB,uBAAU,MAAMH,QAAQ,CAACE,KAAT,CAAeE,QAA/B,CAA5B;AACA,QAAM,CAAEC,WAAF,EAAeC,cAAf,IAAkC,uBAAU,KAAV,CAAxC;AAEA,QAAM;AAAEC,IAAAA,gBAAF;AAAoBC,IAAAA;AAApB,MACL,uBAAaC,eAAb,CADD;AAEA,QAAM;AAAEC,IAAAA,mBAAF;AAAuBC,IAAAA;AAAvB,MACL,uBAAaC,cAAb,CADD;;AAGA,MAAKZ,QAAQ,CAACa,IAAT,KAAkB,aAAlB,IAAmC,CAAEb,QAAQ,CAACc,SAAnD,EAA+D;AAC9D,WAAO,IAAP;AACA;;AAED,iBAAeC,gBAAf,CAAiCC,KAAjC,EAAyC;AACxCA,IAAAA,KAAK,CAACC,cAAN;;AAEA,QAAI;AACH,YAAMV,gBAAgB,CAAE,UAAF,EAAcP,QAAQ,CAACa,IAAvB,EAA6Bb,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AuB,MADxB;AAEC,IAAA,KAAK,EAAG,cAAI,MAAJ,CAFT;AAGC,IAAA,KAAK,EAAGb,KAHT;AAIC,IAAA,QAAQ,EAAGC,QAJZ;AAKC,IAAA,QAAQ;AALT,IADD,EASC,4BAAC,gCAAD;AAAQ,IAAA,OAAO,EAAC;AAAhB,KACC,4BAAC,kBAAD;AACC,IAAA,OAAO,EAAC,UADT;AAEC,IAAA,OAAO,EAAG,MAAM;AACfG,MAAAA,cAAc,CAAE,KAAF,CAAd;AACA;AAJF,KAMG,cAAI,QAAJ,CANH,CADD,EAUC,4BAAC,kBAAD;AAAQ,IAAA,OAAO,EAAC,SAAhB;AAA0B,IAAA,IAAI,EAAC;AAA/B,KACG,cAAI,MAAJ,CADH,CAVD,CATD,CADD,CAPD,CAVF,CADD;AAgDA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport {\n\tButton,\n\tMenuItem,\n\tModal,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as noticesStore } from '@wordpress/notices';\n\nexport default function RenameMenuItem( { template, onClose } ) {\n\tconst [ title, setTitle ] = useState( () => template.title.rendered );\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\n\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\tuseDispatch( coreStore );\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\n\tif ( template.type === 'wp_template' && ! template.is_custom ) {\n\t\treturn null;\n\t}\n\n\tasync function onTemplateRename( event ) {\n\t\tevent.preventDefault();\n\n\t\ttry {\n\t\t\tawait editEntityRecord( 'postType', template.type, template.id, {\n\t\t\t\ttitle,\n\t\t\t} );\n\n\t\t\t// Update state before saving rerenders the list.\n\t\t\tsetTitle( '' );\n\t\t\tsetIsModalOpen( false );\n\t\t\tonClose();\n\n\t\t\t// Persist edited entity.\n\t\t\tawait saveEditedEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\ttemplate.type,\n\t\t\t\ttemplate.id,\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\n\t\t\tcreateSuccessNotice( __( 'Entity renamed.' ), {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __( 'An error occurred while renaming the entity.' );\n\n\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\t\t}\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<MenuItem\n\t\t\t\tonClick={ () => {\n\t\t\t\t\tsetIsModalOpen( true );\n\t\t\t\t\tsetTitle( template.title.rendered );\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ __( 'Rename' ) }\n\t\t\t</MenuItem>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Rename' ) }\n\t\t\t\t\tonRequestClose={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t\toverlayClassName=\"edit-site-list__rename-modal\"\n\t\t\t\t>\n\t\t\t\t\t<form onSubmit={ onTemplateRename }>\n\t\t\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\t\t\trequired\n\t\t\t\t\t\t\t/>\n\n\t\t\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t\t\t</Button>\n\n\t\t\t\t\t\t\t\t<Button variant=\"primary\" type=\"submit\">\n\t\t\t\t\t\t\t\t\t{ __( 'Save' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t</HStack>\n\t\t\t\t\t\t</VStack>\n\t\t\t\t\t</form>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-site/src/components/template-actions/rename-menu-item.js"],"names":["RenameMenuItem","template","onClose","title","rendered","editedTitle","setEditedTitle","isModalOpen","setIsModalOpen","editEntityRecord","__experimentalSaveSpecifiedEntityEdits","saveSpecifiedEntityEdits","coreStore","createSuccessNotice","createErrorNotice","noticesStore","type","is_custom","onTemplateRename","event","preventDefault","id","throwOnError","error","errorMessage","message","code"],"mappings":";;;;;;;AAIA;;AADA;;AAEA;;AACA;;AAQA;;AACA;;AACA;;AAhBA;AACA;AACA;AAgBe,SAASA,cAAT,CAAyB;AAAEC,EAAAA,QAAF;AAAYC,EAAAA;AAAZ,CAAzB,EAAiD;AAC/D,QAAMC,KAAK,GAAG,kCAAgBF,QAAQ,CAACE,KAAT,CAAeC,QAA/B,CAAd;AACA,QAAM,CAAEC,WAAF,EAAeC,cAAf,IAAkC,uBAAUH,KAAV,CAAxC;AACA,QAAM,CAAEI,WAAF,EAAeC,cAAf,IAAkC,uBAAU,KAAV,CAAxC;AAEA,QAAM;AACLC,IAAAA,gBADK;AAELC,IAAAA,sCAAsC,EAAEC;AAFnC,MAGF,uBAAaC,eAAb,CAHJ;AAIA,QAAM;AAAEC,IAAAA,mBAAF;AAAuBC,IAAAA;AAAvB,MACL,uBAAaC,cAAb,CADD;;AAGA,MAAKd,QAAQ,CAACe,IAAT,KA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,QAAJ,CADT;AAEC,IAAA,cAAc,EAAG,MAAM;AACtBC,MAAAA,cAAc,CAAE,KAAF,CAAd;AACA,KAJF;AAKC,IAAA,gBAAgB,EAAC;AALlB,KAOC;AAAM,IAAA,QAAQ,EAAGU;AAAjB,KACC,4BAAC,gCAAD;AAAQ,IAAA,OAAO,EAAC;AAAhB,KACC,4BAAC,uBAAD;AACC,IAAA,uBAAuB,MADxB;AAEC,IAAA,KAAK,EAAG,cAAI,MAAJ,CAFT;AAGC,IAAA,KAAK,EAAGb,WAHT;AAIC,IAAA,QAAQ,EAAGC,cAJZ;AAKC,IAAA,QAAQ;AALT,IADD,EASC,4BAAC,gCAAD;AAAQ,IAAA,OAAO,EAAC;AAAhB,KACC,4BAAC,kBAAD;AACC,IAAA,OAAO,EAAC,UADT;AAEC,IAAA,OAAO,EAAG,MAAM;AACfE,MAAAA,cAAc,CAAE,KAAF,CAAd;AACA;AAJF,KAMG,cAAI,QAAJ,CANH,CADD,EAUC,4BAAC,kBAAD;AAAQ,IAAA,OAAO,EAAC,SAAhB;AAA0B,IAAA,IAAI,EAAC;AAA/B,KACG,cAAI,MAAJ,CADH,CAVD,CATD,CADD,CAPD,CAVF,CADD;AAgDA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport {\n\tButton,\n\tMenuItem,\n\tModal,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { decodeEntities } from '@wordpress/html-entities';\n\nexport default function RenameMenuItem( { template, onClose } ) {\n\tconst title = decodeEntities( template.title.rendered );\n\tconst [ editedTitle, setEditedTitle ] = useState( title );\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\n\tconst {\n\t\teditEntityRecord,\n\t\t__experimentalSaveSpecifiedEntityEdits: saveSpecifiedEntityEdits,\n\t} = useDispatch( coreStore );\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\n\tif ( template.type === 'wp_template' && ! template.is_custom ) {\n\t\treturn null;\n\t}\n\n\tasync function onTemplateRename( event ) {\n\t\tevent.preventDefault();\n\n\t\ttry {\n\t\t\tawait editEntityRecord( 'postType', template.type, template.id, {\n\t\t\t\ttitle: editedTitle,\n\t\t\t} );\n\n\t\t\t// Update state before saving rerenders the list.\n\t\t\tsetEditedTitle( '' );\n\t\t\tsetIsModalOpen( false );\n\t\t\tonClose();\n\n\t\t\t// Persist edited entity.\n\t\t\tawait saveSpecifiedEntityEdits(\n\t\t\t\t'postType',\n\t\t\t\ttemplate.type,\n\t\t\t\ttemplate.id,\n\t\t\t\t[ 'title' ], // Only save title to avoid persisting other edits.\n\t\t\t\t{\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tcreateSuccessNotice( __( 'Entity renamed.' ), {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __( 'An error occurred while renaming the entity.' );\n\n\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\t\t}\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<MenuItem\n\t\t\t\tonClick={ () => {\n\t\t\t\t\tsetIsModalOpen( true );\n\t\t\t\t\tsetEditedTitle( title );\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ __( 'Rename' ) }\n\t\t\t</MenuItem>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Rename' ) }\n\t\t\t\t\tonRequestClose={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t\toverlayClassName=\"edit-site-list__rename-modal\"\n\t\t\t\t>\n\t\t\t\t\t<form onSubmit={ onTemplateRename }>\n\t\t\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\t\t\tvalue={ editedTitle }\n\t\t\t\t\t\t\t\tonChange={ setEditedTitle }\n\t\t\t\t\t\t\t\trequired\n\t\t\t\t\t\t\t/>\n\n\t\t\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t\t\t</Button>\n\n\t\t\t\t\t\t\t\t<Button variant=\"primary\" type=\"submit\">\n\t\t\t\t\t\t\t\t\t{ __( 'Save' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t</HStack>\n\t\t\t\t\t\t</VStack>\n\t\t\t\t\t</form>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"]}
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
@@ -15,6 +17,8 @@ var _htmlEntities = require("@wordpress/html-entities");
15
17
 
16
18
  var _store = require("../../store");
17
19
 
20
+ var _normalizeRecordKey = _interopRequireDefault(require("../../utils/normalize-record-key"));
21
+
18
22
  /**
19
23
  * WordPress dependencies
20
24
  */
@@ -42,7 +46,8 @@ function useEditedEntityRecord(postType, postId) {
42
46
  __experimentalGetTemplateInfo: getTemplateInfo
43
47
  } = select(_editor.store);
44
48
  const usedPostType = postType !== null && postType !== void 0 ? postType : getEditedPostType();
45
- const usedPostId = postId !== null && postId !== void 0 ? postId : getEditedPostId();
49
+ let usedPostId = postId !== null && postId !== void 0 ? postId : getEditedPostId();
50
+ usedPostId = (0, _normalizeRecordKey.default)(usedPostId, usedPostType);
46
51
 
47
52
  const _record = getEditedEntityRecord('postType', usedPostType, usedPostId);
48
53
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/use-edited-entity-record/index.js"],"names":["useEditedEntityRecord","postType","postId","record","title","description","isLoaded","icon","select","getEditedPostType","getEditedPostId","editSiteStore","getEditedEntityRecord","hasFinishedResolution","coreStore","__experimentalGetTemplateInfo","getTemplateInfo","editorStore","usedPostType","usedPostId","_record","_isLoaded","templateInfo","getTitle","getDescription"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AACA;;AAKA;;AAXA;AACA;AACA;;AAMA;AACA;AACA;AAGe,SAASA,qBAAT,CAAgCC,QAAhC,EAA0CC,MAA1C,EAAmD;AACjE,QAAM;AAAEC,IAAAA,MAAF;AAAUC,IAAAA,KAAV;AAAiBC,IAAAA,WAAjB;AAA8BC,IAAAA,QAA9B;AAAwCC,IAAAA;AAAxC,MAAiD,qBACpDC,MAAF,IAAc;AACb,UAAM;AAAEC,MAAAA,iBAAF;AAAqBC,MAAAA;AAArB,QACLF,MAAM,CAAEG,YAAF,CADP;AAEA,UAAM;AAAEC,MAAAA,qBAAF;AAAyBC,MAAAA;AAAzB,QACLL,MAAM,CAAEM,eAAF,CADP;AAEA,UAAM;AAAEC,MAAAA,6BAA6B,EAAEC;AAAjC,QACLR,MAAM,CAAES,aAAF,CADP;AAEA,UAAMC,YAAY,GAAGjB,QAAH,aAAGA,QAAH,cAAGA,QAAH,GAAeQ,iBAAiB,EAAlD;AACA,UAAMU,UAAU,GAAGjB,MAAH,aAAGA,MAAH,cAAGA,MAAH,GAAaQ,eAAe,EAA5C;;AACA,UAAMU,OAAO,GAAGR,qBAAqB,CACpC,UADoC,EAEpCM,YAFoC,EAGpCC,UAHoC,CAArC;;AAKA,UAAME,SAAS,GACdF,UAAU,IACVN,qBAAqB,CAAE,uBAAF,EAA2B,CAC/C,UAD+C,EAE/CK,YAF+C,EAG/CC,UAH+C,CAA3B,CAFtB;;AAOA,UAAMG,YAAY,GAAGN,eAAe,CAAEI,OAAF,CAApC;AAEA,WAAO;AACNjB,MAAAA,MAAM,EAAEiB,OADF;AAENhB,MAAAA,KAAK,EAAEkB,YAAY,CAAClB,KAFd;AAGNC,MAAAA,WAAW,EAAEiB,YAAY,CAACjB,WAHpB;AAINC,MAAAA,QAAQ,EAAEe,SAJJ;AAKNd,MAAAA,IAAI,EAAEe,YAAY,CAACf;AALb,KAAP;AAOA,GA/BqD,EAgCtD,CAAEN,QAAF,EAAYC,MAAZ,CAhCsD,CAAvD;AAmCA,SAAO;AACNI,IAAAA,QADM;AAENC,IAAAA,IAFM;AAGNJ,IAAAA,MAHM;AAINoB,IAAAA,QAAQ,EAAE,MAAQnB,KAAK,GAAG,kCAAgBA,KAAhB,CAAH,GAA6B,IAJ9C;AAKNoB,IAAAA,cAAc,EAAE,MACfnB,WAAW,GAAG,kCAAgBA,WAAhB,CAAH,GAAmC;AANzC,GAAP;AAQA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as editorStore } from '@wordpress/editor';\nimport { decodeEntities } from '@wordpress/html-entities';\n\n/**\n * Internal dependencies\n */\nimport { store as editSiteStore } from '../../store';\n\nexport default function useEditedEntityRecord( postType, postId ) {\n\tconst { record, title, description, isLoaded, icon } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEditedPostType, getEditedPostId } =\n\t\t\t\tselect( editSiteStore );\n\t\t\tconst { getEditedEntityRecord, hasFinishedResolution } =\n\t\t\t\tselect( coreStore );\n\t\t\tconst { __experimentalGetTemplateInfo: getTemplateInfo } =\n\t\t\t\tselect( editorStore );\n\t\t\tconst usedPostType = postType ?? getEditedPostType();\n\t\t\tconst usedPostId = postId ?? getEditedPostId();\n\t\t\tconst _record = getEditedEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tusedPostType,\n\t\t\t\tusedPostId\n\t\t\t);\n\t\t\tconst _isLoaded =\n\t\t\t\tusedPostId &&\n\t\t\t\thasFinishedResolution( 'getEditedEntityRecord', [\n\t\t\t\t\t'postType',\n\t\t\t\t\tusedPostType,\n\t\t\t\t\tusedPostId,\n\t\t\t\t] );\n\t\t\tconst templateInfo = getTemplateInfo( _record );\n\n\t\t\treturn {\n\t\t\t\trecord: _record,\n\t\t\t\ttitle: templateInfo.title,\n\t\t\t\tdescription: templateInfo.description,\n\t\t\t\tisLoaded: _isLoaded,\n\t\t\t\ticon: templateInfo.icon,\n\t\t\t};\n\t\t},\n\t\t[ postType, postId ]\n\t);\n\n\treturn {\n\t\tisLoaded,\n\t\ticon,\n\t\trecord,\n\t\tgetTitle: () => ( title ? decodeEntities( title ) : null ),\n\t\tgetDescription: () =>\n\t\t\tdescription ? decodeEntities( description ) : null,\n\t};\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-site/src/components/use-edited-entity-record/index.js"],"names":["useEditedEntityRecord","postType","postId","record","title","description","isLoaded","icon","select","getEditedPostType","getEditedPostId","editSiteStore","getEditedEntityRecord","hasFinishedResolution","coreStore","__experimentalGetTemplateInfo","getTemplateInfo","editorStore","usedPostType","usedPostId","_record","_isLoaded","templateInfo","getTitle","getDescription"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAZA;AACA;AACA;;AAMA;AACA;AACA;AAIe,SAASA,qBAAT,CAAgCC,QAAhC,EAA0CC,MAA1C,EAAmD;AACjE,QAAM;AAAEC,IAAAA,MAAF;AAAUC,IAAAA,KAAV;AAAiBC,IAAAA,WAAjB;AAA8BC,IAAAA,QAA9B;AAAwCC,IAAAA;AAAxC,MAAiD,qBACpDC,MAAF,IA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,WAAW,GAAG,kCAAgBA,WAAhB,CAAH,GAAmC;AANzC,GAAP;AAQA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as editorStore } from '@wordpress/editor';\nimport { decodeEntities } from '@wordpress/html-entities';\n\n/**\n * Internal dependencies\n */\nimport { store as editSiteStore } from '../../store';\nimport normalizeRecordKey from '../../utils/normalize-record-key';\n\nexport default function useEditedEntityRecord( postType, postId ) {\n\tconst { record, title, description, isLoaded, icon } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEditedPostType, getEditedPostId } =\n\t\t\t\tselect( editSiteStore );\n\t\t\tconst { getEditedEntityRecord, hasFinishedResolution } =\n\t\t\t\tselect( coreStore );\n\t\t\tconst { __experimentalGetTemplateInfo: getTemplateInfo } =\n\t\t\t\tselect( editorStore );\n\t\t\tconst usedPostType = postType ?? getEditedPostType();\n\n\t\t\tlet usedPostId = postId ?? getEditedPostId();\n\n\t\t\tusedPostId = normalizeRecordKey( usedPostId, usedPostType );\n\n\t\t\tconst _record = getEditedEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tusedPostType,\n\t\t\t\tusedPostId\n\t\t\t);\n\t\t\tconst _isLoaded =\n\t\t\t\tusedPostId &&\n\t\t\t\thasFinishedResolution( 'getEditedEntityRecord', [\n\t\t\t\t\t'postType',\n\t\t\t\t\tusedPostType,\n\t\t\t\t\tusedPostId,\n\t\t\t\t] );\n\t\t\tconst templateInfo = getTemplateInfo( _record );\n\n\t\t\treturn {\n\t\t\t\trecord: _record,\n\t\t\t\ttitle: templateInfo.title,\n\t\t\t\tdescription: templateInfo.description,\n\t\t\t\tisLoaded: _isLoaded,\n\t\t\t\ticon: templateInfo.icon,\n\t\t\t};\n\t\t},\n\t\t[ postType, postId ]\n\t);\n\n\treturn {\n\t\tisLoaded,\n\t\ticon,\n\t\trecord,\n\t\tgetTitle: () => ( title ? decodeEntities( title ) : null ),\n\t\tgetDescription: () =>\n\t\t\tdescription ? decodeEntities( description ) : null,\n\t};\n}\n"]}
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
@@ -25,10 +27,14 @@ var _coreData = require("@wordpress/core-data");
25
27
 
26
28
  var _notices = require("@wordpress/notices");
27
29
 
30
+ var _compose = require("@wordpress/compose");
31
+
28
32
  var _lockUnlock = require("../../lock-unlock");
29
33
 
30
34
  var _store = require("../../store");
31
35
 
36
+ var _getIsListPage = _interopRequireDefault(require("../../utils/get-is-list-page"));
37
+
32
38
  /**
33
39
  * WordPress dependencies
34
40
  */
@@ -40,7 +46,8 @@ const {
40
46
  useGlobalStylesReset
41
47
  } = (0, _lockUnlock.unlock)(_blockEditor.privateApis);
42
48
  const {
43
- useHistory
49
+ useHistory,
50
+ useLocation
44
51
  } = (0, _lockUnlock.unlock)(_router.privateApis);
45
52
 
46
53
  function useGlobalStylesResetCommands() {
@@ -71,8 +78,15 @@ function useGlobalStylesResetCommands() {
71
78
  function useGlobalStylesOpenCssCommands() {
72
79
  const {
73
80
  openGeneralSidebar,
74
- setEditorCanvasContainerView
81
+ setEditorCanvasContainerView,
82
+ setCanvasMode
75
83
  } = (0, _lockUnlock.unlock)((0, _data.useDispatch)(_store.store));
84
+ const {
85
+ params
86
+ } = useLocation();
87
+ const isMobileViewport = (0, _compose.useViewportMatch)('medium', '<');
88
+ const isListPage = (0, _getIsListPage.default)(params, isMobileViewport);
89
+ const isEditorPage = !isListPage;
76
90
  const history = useHistory();
77
91
  const {
78
92
  canEditCSS
@@ -91,6 +105,9 @@ function useGlobalStylesOpenCssCommands() {
91
105
  canEditCSS: (_globalStyles$_links$ = !!globalStyles?._links?.['wp:action-edit-css']) !== null && _globalStyles$_links$ !== void 0 ? _globalStyles$_links$ : false
92
106
  };
93
107
  }, []);
108
+ const {
109
+ getCanvasMode
110
+ } = (0, _lockUnlock.unlock)((0, _data.useSelect)(_store.store));
94
111
  const commands = (0, _element.useMemo)(() => {
95
112
  if (!canEditCSS) {
96
113
  return [];
@@ -104,15 +121,23 @@ function useGlobalStylesOpenCssCommands() {
104
121
  close
105
122
  }) => {
106
123
  close();
107
- history.push({
108
- path: '/wp_global_styles',
109
- canvas: 'edit'
110
- });
124
+
125
+ if (!isEditorPage) {
126
+ history.push({
127
+ path: '/wp_global_styles',
128
+ canvas: 'edit'
129
+ });
130
+ }
131
+
132
+ if (isEditorPage && getCanvasMode() !== 'edit') {
133
+ setCanvasMode('edit');
134
+ }
135
+
111
136
  openGeneralSidebar('edit-site/global-styles');
112
137
  setEditorCanvasContainerView('global-styles-css');
113
138
  }
114
139
  }];
115
- }, [history, openGeneralSidebar, setEditorCanvasContainerView, canEditCSS]);
140
+ }, [history, openGeneralSidebar, setEditorCanvasContainerView, canEditCSS, isEditorPage, getCanvasMode, setCanvasMode]);
116
141
  return {
117
142
  isLoading: false,
118
143
  commands
@@ -122,8 +147,18 @@ function useGlobalStylesOpenCssCommands() {
122
147
  function useCommonCommands() {
123
148
  const {
124
149
  openGeneralSidebar,
125
- setEditorCanvasContainerView
150
+ setEditorCanvasContainerView,
151
+ setCanvasMode
126
152
  } = (0, _lockUnlock.unlock)((0, _data.useDispatch)(_store.store));
153
+ const {
154
+ params
155
+ } = useLocation();
156
+ const isMobileViewport = (0, _compose.useViewportMatch)('medium', '<');
157
+ const isListPage = (0, _getIsListPage.default)(params, isMobileViewport);
158
+ const isEditorPage = !isListPage;
159
+ const {
160
+ getCanvasMode
161
+ } = (0, _lockUnlock.unlock)((0, _data.useSelect)(_store.store));
127
162
  const {
128
163
  set
129
164
  } = (0, _data.useDispatch)(_preferences.store);
@@ -152,10 +187,18 @@ function useCommonCommands() {
152
187
  close
153
188
  }) => {
154
189
  close();
155
- history.push({
156
- path: '/wp_global_styles',
157
- canvas: 'edit'
158
- });
190
+
191
+ if (!isEditorPage) {
192
+ history.push({
193
+ path: '/wp_global_styles',
194
+ canvas: 'edit'
195
+ });
196
+ }
197
+
198
+ if (isEditorPage && getCanvasMode() !== 'edit') {
199
+ setCanvasMode('edit');
200
+ }
201
+
159
202
  openGeneralSidebar('edit-site/global-styles');
160
203
  setEditorCanvasContainerView('global-styles-revisions');
161
204
  }
@@ -167,10 +210,17 @@ function useCommonCommands() {
167
210
  close
168
211
  }) => {
169
212
  close();
170
- history.push({
171
- path: '/wp_global_styles',
172
- canvas: 'edit'
173
- });
213
+
214
+ if (!isEditorPage) {
215
+ history.push({
216
+ path: '/wp_global_styles',
217
+ canvas: 'edit'
218
+ });
219
+ }
220
+
221
+ if (isEditorPage && getCanvasMode() !== 'edit') {
222
+ setCanvasMode('edit');
223
+ }
174
224
 
175
225
  if (isDistractionFree) {
176
226
  set(_store.store.name, 'distractionFree', false);
@@ -190,10 +240,18 @@ function useCommonCommands() {
190
240
  close
191
241
  }) => {
192
242
  close();
193
- history.push({
194
- path: '/wp_global_styles',
195
- canvas: 'edit'
196
- });
243
+
244
+ if (!isEditorPage) {
245
+ history.push({
246
+ path: '/wp_global_styles',
247
+ canvas: 'edit'
248
+ });
249
+ }
250
+
251
+ if (isEditorPage && getCanvasMode() !== 'edit') {
252
+ setCanvasMode('edit');
253
+ }
254
+
197
255
  openGeneralSidebar('edit-site/global-styles');
198
256
  set('core/edit-site', 'welcomeGuideStyles', true); // sometimes there's a focus loss that happens after some time
199
257
  // that closes the modal, we need to force reopening it.
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/hooks/commands/use-common-commands.js"],"names":["useGlobalStylesReset","blockEditorPrivateApis","useHistory","routerPrivateApis","useGlobalStylesResetCommands","canReset","onReset","commands","name","label","icon","trash","callback","close","isLoading","useGlobalStylesOpenCssCommands","openGeneralSidebar","setEditorCanvasContainerView","editSiteStore","history","canEditCSS","select","getEntityRecord","__experimentalGetCurrentGlobalStylesId","coreStore","globalStylesId","globalStyles","undefined","_links","styles","push","path","canvas","useCommonCommands","set","preferencesStore","createInfoNotice","noticesStore","homeUrl","isDistractionFree","getUnstableBase","home","get","backup","type","setTimeout","help","window","open","external","hook"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAlBA;AACA;AACA;;AAYA;AACA;AACA;AAIA,MAAM;AAAEA,EAAAA;AAAF,IAA2B,wBAAQC,wBAAR,CAAjC;AACA,MAAM;AAAEC,EAAAA;AAAF,IAAiB,wBAAQC,mBAAR,CAAvB;;AAEA,SAASC,4BAAT,GAAwC;AACvC,QAAM,CAAEC,QAAF,EAAYC,OAAZ,IAAwBN,oBAAoB,EAAlD;AACA,QAAMO,QAAQ,GAAG,sBAAS,MAAM;AAC/B,QAAK,CAAEF,QAAP,EAAkB;AACjB,aAAO,EAAP;AACA;;AAED,WAAO,CACN;AACCG,MAAAA,IAAI,EAAE,oCADP;AAECC,MAAAA,KAAK,EAAE,cAAI,0BAAJ,CAFR;AAGCC,MAAAA,IAAI,EAAEC,YAHP;AAICC,MAAAA,QAAQ,EAAE,CAAE;AAAEC,QAAAA;AAAF,OAAF,KAAiB;AAC1BA,QAAAA,KAAK;AACLP,QAAAA,OAAO;AACP;AAPF,KADM,CAAP;AAWA,GAhBgB,EAgBd,CAAED,QAAF,EAAYC,OAAZ,CAhBc,CAAjB;AAkBA,SAAO;AACNQ,IAAAA,SAAS,EAAE,KADL;AAENP,IAAAA;AAFM,GAAP;AAIA;;AAED,SAASQ,8BAAT,GAA0C;AACzC,QAAM;AAAEC,IAAAA,kBAAF;AAAsBC,IAAAA;AAAtB,MAAuD,wBAC5D,uBAAaC,YAAb,CAD4D,CAA7D;AAGA,QAAMC,OAAO,GAAGjB,UAAU,EAA1B;AACA,QAAM;AAAEkB,IAAAA;AAAF,MAAiB,qBAAaC,MAAF,IAAc;AAAA;;AAC/C,UAAM;AAAEC,MAAAA,eAAF;AAAmBC,MAAAA;AAAnB,QACLF,MA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AAFW,GAAlB;AAKA,kCAAkB;AACjBI,IAAAA,IAAI,EAAE,gCADW;AAEjB0C,IAAAA,IAAI,EAAEnC;AAFW,GAAlB;AAIA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { trash, backup, help, styles, external } from '@wordpress/icons';\nimport { useCommandLoader, useCommand } from '@wordpress/commands';\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { store as preferencesStore } from '@wordpress/preferences';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\nimport { store as editSiteStore } from '../../store';\n\nconst { useGlobalStylesReset } = unlock( blockEditorPrivateApis );\nconst { useHistory } = unlock( routerPrivateApis );\n\nfunction useGlobalStylesResetCommands() {\n\tconst [ canReset, onReset ] = useGlobalStylesReset();\n\tconst commands = useMemo( () => {\n\t\tif ( ! canReset ) {\n\t\t\treturn [];\n\t\t}\n\n\t\treturn [\n\t\t\t{\n\t\t\t\tname: 'core/edit-site/reset-global-styles',\n\t\t\t\tlabel: __( 'Reset styles to defaults' ),\n\t\t\t\ticon: trash,\n\t\t\t\tcallback: ( { close } ) => {\n\t\t\t\t\tclose();\n\t\t\t\t\tonReset();\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\t}, [ canReset, onReset ] );\n\n\treturn {\n\t\tisLoading: false,\n\t\tcommands,\n\t};\n}\n\nfunction useGlobalStylesOpenCssCommands() {\n\tconst { openGeneralSidebar, setEditorCanvasContainerView } = unlock(\n\t\tuseDispatch( editSiteStore )\n\t);\n\tconst history = useHistory();\n\tconst { canEditCSS } = useSelect( ( select ) => {\n\t\tconst { getEntityRecord, __experimentalGetCurrentGlobalStylesId } =\n\t\t\tselect( coreStore );\n\n\t\tconst globalStylesId = __experimentalGetCurrentGlobalStylesId();\n\t\tconst globalStyles = globalStylesId\n\t\t\t? getEntityRecord( 'root', 'globalStyles', globalStylesId )\n\t\t\t: undefined;\n\n\t\treturn {\n\t\t\tcanEditCSS:\n\t\t\t\t!! globalStyles?._links?.[ 'wp:action-edit-css' ] ?? false,\n\t\t};\n\t}, [] );\n\n\tconst commands = useMemo( () => {\n\t\tif ( ! canEditCSS ) {\n\t\t\treturn [];\n\t\t}\n\n\t\treturn [\n\t\t\t{\n\t\t\t\tname: 'core/edit-site/open-styles-css',\n\t\t\t\tlabel: __( 'Open CSS' ),\n\t\t\t\ticon: styles,\n\t\t\t\tcallback: ( { close } ) => {\n\t\t\t\t\tclose();\n\t\t\t\t\thistory.push( {\n\t\t\t\t\t\tpath: '/wp_global_styles',\n\t\t\t\t\t\tcanvas: 'edit',\n\t\t\t\t\t} );\n\t\t\t\t\topenGeneralSidebar( 'edit-site/global-styles' );\n\t\t\t\t\tsetEditorCanvasContainerView( 'global-styles-css' );\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\t}, [\n\t\thistory,\n\t\topenGeneralSidebar,\n\t\tsetEditorCanvasContainerView,\n\t\tcanEditCSS,\n\t] );\n\treturn {\n\t\tisLoading: false,\n\t\tcommands,\n\t};\n}\n\nexport function useCommonCommands() {\n\tconst { openGeneralSidebar, setEditorCanvasContainerView } = unlock(\n\t\tuseDispatch( editSiteStore )\n\t);\n\tconst { set } = useDispatch( preferencesStore );\n\tconst { createInfoNotice } = useDispatch( noticesStore );\n\tconst history = useHistory();\n\tconst { homeUrl, isDistractionFree } = useSelect( ( select ) => {\n\t\tconst {\n\t\t\tgetUnstableBase, // Site index.\n\t\t} = select( coreStore );\n\n\t\treturn {\n\t\t\thomeUrl: getUnstableBase()?.home,\n\t\t\tisDistractionFree: select( preferencesStore ).get(\n\t\t\t\teditSiteStore.name,\n\t\t\t\t'distractionFree'\n\t\t\t),\n\t\t};\n\t}, [] );\n\n\tuseCommand( {\n\t\tname: 'core/edit-site/open-global-styles-revisions',\n\t\tlabel: __( 'Open styles revisions' ),\n\t\ticon: backup,\n\t\tcallback: ( { close } ) => {\n\t\t\tclose();\n\t\t\thistory.push( {\n\t\t\t\tpath: '/wp_global_styles',\n\t\t\t\tcanvas: 'edit',\n\t\t\t} );\n\t\t\topenGeneralSidebar( 'edit-site/global-styles' );\n\t\t\tsetEditorCanvasContainerView( 'global-styles-revisions' );\n\t\t},\n\t} );\n\n\tuseCommand( {\n\t\tname: 'core/edit-site/open-styles',\n\t\tlabel: __( 'Open styles' ),\n\t\tcallback: ( { close } ) => {\n\t\t\tclose();\n\t\t\thistory.push( {\n\t\t\t\tpath: '/wp_global_styles',\n\t\t\t\tcanvas: 'edit',\n\t\t\t} );\n\t\t\tif ( isDistractionFree ) {\n\t\t\t\tset( editSiteStore.name, 'distractionFree', false );\n\t\t\t\tcreateInfoNotice( __( 'Distraction free mode turned off.' ), {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t}\n\t\t\topenGeneralSidebar( 'edit-site/global-styles' );\n\t\t},\n\t\ticon: styles,\n\t} );\n\n\tuseCommand( {\n\t\tname: 'core/edit-site/toggle-styles-welcome-guide',\n\t\tlabel: __( 'Learn about styles' ),\n\t\tcallback: ( { close } ) => {\n\t\t\tclose();\n\t\t\thistory.push( {\n\t\t\t\tpath: '/wp_global_styles',\n\t\t\t\tcanvas: 'edit',\n\t\t\t} );\n\t\t\topenGeneralSidebar( 'edit-site/global-styles' );\n\t\t\tset( 'core/edit-site', 'welcomeGuideStyles', true );\n\t\t\t// sometimes there's a focus loss that happens after some time\n\t\t\t// that closes the modal, we need to force reopening it.\n\t\t\tsetTimeout( () => {\n\t\t\t\tset( 'core/edit-site', 'welcomeGuideStyles', true );\n\t\t\t}, 500 );\n\t\t},\n\t\ticon: help,\n\t} );\n\n\tuseCommand( {\n\t\tname: 'core/edit-site/view-site',\n\t\tlabel: __( 'View site' ),\n\t\tcallback: ( { close } ) => {\n\t\t\tclose();\n\t\t\twindow.open( homeUrl, '_blank' );\n\t\t},\n\t\ticon: external,\n\t} );\n\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/reset-global-styles',\n\t\thook: useGlobalStylesResetCommands,\n\t} );\n\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/open-styles-css',\n\t\thook: useGlobalStylesOpenCssCommands,\n\t} );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-site/src/hooks/commands/use-common-commands.js"],"names":["useGlobalStylesReset","blockEditorPrivateApis","useHistory","useLocation","routerPrivateApis","useGlobalStylesResetCommands","canReset","onReset","commands","name","label","icon","trash","callback","close","isLoading","useGlobalStylesOpenCssCommands","openGeneralSidebar","setEditorCanvasContainerView","setCanvasMode","editSiteStore","params","isMobileViewport","isListPage","isEditorPage","history","canEditCSS","select","getEntityRecord","__experimentalGetCurrentGlobalStylesId","coreStore","globalStylesId","globalStyles","undefined","_links","getCanvasMode","styles","push","path","canvas","useCommonCommands","set","preferencesStore","createInfoNotice","noticesStore","homeUrl","isDistractionFree","getUnstableBase","home","get","backup","type","setTimeout","help","window","open","external","hook"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AApBA;AACA;AACA;;AAaA;AACA;AACA;AAKA,MAAM;AAAEA,EAAAA;AAAF,IAA2B,wBAAQC,wBAAR,CAAjC;AACA,MAAM;AAAEC,EAAAA,UAAF;AAAcC,EAAAA;AAAd,IAA8B,wBAAQC,mBAAR,CAApC;;AAEA,SAASC,4BAAT,GAAwC;AACvC,QAAM,CAAEC,QAAF,EAAYC,OAAZ,IAAwBP,oBAAoB,EAAlD;AACA,QAAMQ,QAAQ,GAAG,sBAAS,MAAM;AAC/B,QAAK,CAAEF,QAAP,EAAkB;AACjB,aAAO,EAAP;AACA;;AAED,WAAO,CACN;AACCG,MAAAA,IAAI,EAAE,oCADP;AAECC,MAAAA,KAAK,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EAA0C,IAA1C,CAAH,CAZ0B,CAa1B;AACA;;AACAW,MAAAA,UAAU,CAAE,MAAM;AACjBX,QAAAA,GAAG,CAAE,gBAAF,EAAoB,oBAApB,EAA0C,IAA1C,CAAH;AACA,OAFS,EAEP,GAFO,CAAV;AAGA,KArBU;AAsBX9B,IAAAA,IAAI,EAAE0C;AAtBK,GAAZ;AAyBA,4BAAY;AACX5C,IAAAA,IAAI,EAAE,0BADK;AAEXC,IAAAA,KAAK,EAAE,cAAI,WAAJ,CAFI;AAGXG,IAAAA,QAAQ,EAAE,CAAE;AAAEC,MAAAA;AAAF,KAAF,KAAiB;AAC1BA,MAAAA,KAAK;AACLwC,MAAAA,MAAM,CAACC,IAAP,CAAaV,OAAb,EAAsB,QAAtB;AACA,KANU;AAOXlC,IAAAA,IAAI,EAAE6C;AAPK,GAAZ;AAUA,kCAAkB;AACjB/C,IAAAA,IAAI,EAAE,oCADW;AAEjBgD,IAAAA,IAAI,EAAEpD;AAFW,GAAlB;AAKA,kCAAkB;AACjBI,IAAAA,IAAI,EAAE,gCADW;AAEjBgD,IAAAA,IAAI,EAAEzC;AAFW,GAAlB;AAIA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { trash, backup, help, styles, external } from '@wordpress/icons';\nimport { useCommandLoader, useCommand } from '@wordpress/commands';\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { store as preferencesStore } from '@wordpress/preferences';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useViewportMatch } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\nimport { store as editSiteStore } from '../../store';\nimport getIsListPage from '../../utils/get-is-list-page';\n\nconst { useGlobalStylesReset } = unlock( blockEditorPrivateApis );\nconst { useHistory, useLocation } = unlock( routerPrivateApis );\n\nfunction useGlobalStylesResetCommands() {\n\tconst [ canReset, onReset ] = useGlobalStylesReset();\n\tconst commands = useMemo( () => {\n\t\tif ( ! canReset ) {\n\t\t\treturn [];\n\t\t}\n\n\t\treturn [\n\t\t\t{\n\t\t\t\tname: 'core/edit-site/reset-global-styles',\n\t\t\t\tlabel: __( 'Reset styles to defaults' ),\n\t\t\t\ticon: trash,\n\t\t\t\tcallback: ( { close } ) => {\n\t\t\t\t\tclose();\n\t\t\t\t\tonReset();\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\t}, [ canReset, onReset ] );\n\n\treturn {\n\t\tisLoading: false,\n\t\tcommands,\n\t};\n}\n\nfunction useGlobalStylesOpenCssCommands() {\n\tconst { openGeneralSidebar, setEditorCanvasContainerView, setCanvasMode } =\n\t\tunlock( useDispatch( editSiteStore ) );\n\tconst { params } = useLocation();\n\tconst isMobileViewport = useViewportMatch( 'medium', '<' );\n\tconst isListPage = getIsListPage( params, isMobileViewport );\n\tconst isEditorPage = ! isListPage;\n\tconst history = useHistory();\n\tconst { canEditCSS } = useSelect( ( select ) => {\n\t\tconst { getEntityRecord, __experimentalGetCurrentGlobalStylesId } =\n\t\t\tselect( coreStore );\n\n\t\tconst globalStylesId = __experimentalGetCurrentGlobalStylesId();\n\t\tconst globalStyles = globalStylesId\n\t\t\t? getEntityRecord( 'root', 'globalStyles', globalStylesId )\n\t\t\t: undefined;\n\n\t\treturn {\n\t\t\tcanEditCSS:\n\t\t\t\t!! globalStyles?._links?.[ 'wp:action-edit-css' ] ?? false,\n\t\t};\n\t}, [] );\n\tconst { getCanvasMode } = unlock( useSelect( editSiteStore ) );\n\n\tconst commands = useMemo( () => {\n\t\tif ( ! canEditCSS ) {\n\t\t\treturn [];\n\t\t}\n\n\t\treturn [\n\t\t\t{\n\t\t\t\tname: 'core/edit-site/open-styles-css',\n\t\t\t\tlabel: __( 'Open CSS' ),\n\t\t\t\ticon: styles,\n\t\t\t\tcallback: ( { close } ) => {\n\t\t\t\t\tclose();\n\t\t\t\t\tif ( ! isEditorPage ) {\n\t\t\t\t\t\thistory.push( {\n\t\t\t\t\t\t\tpath: '/wp_global_styles',\n\t\t\t\t\t\t\tcanvas: 'edit',\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\t\t\t\t\tif ( isEditorPage && getCanvasMode() !== 'edit' ) {\n\t\t\t\t\t\tsetCanvasMode( 'edit' );\n\t\t\t\t\t}\n\t\t\t\t\topenGeneralSidebar( 'edit-site/global-styles' );\n\t\t\t\t\tsetEditorCanvasContainerView( 'global-styles-css' );\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\t}, [\n\t\thistory,\n\t\topenGeneralSidebar,\n\t\tsetEditorCanvasContainerView,\n\t\tcanEditCSS,\n\t\tisEditorPage,\n\t\tgetCanvasMode,\n\t\tsetCanvasMode,\n\t] );\n\treturn {\n\t\tisLoading: false,\n\t\tcommands,\n\t};\n}\n\nexport function useCommonCommands() {\n\tconst { openGeneralSidebar, setEditorCanvasContainerView, setCanvasMode } =\n\t\tunlock( useDispatch( editSiteStore ) );\n\tconst { params } = useLocation();\n\tconst isMobileViewport = useViewportMatch( 'medium', '<' );\n\tconst isListPage = getIsListPage( params, isMobileViewport );\n\tconst isEditorPage = ! isListPage;\n\tconst { getCanvasMode } = unlock( useSelect( editSiteStore ) );\n\tconst { set } = useDispatch( preferencesStore );\n\tconst { createInfoNotice } = useDispatch( noticesStore );\n\tconst history = useHistory();\n\tconst { homeUrl, isDistractionFree } = useSelect( ( select ) => {\n\t\tconst {\n\t\t\tgetUnstableBase, // Site index.\n\t\t} = select( coreStore );\n\n\t\treturn {\n\t\t\thomeUrl: getUnstableBase()?.home,\n\t\t\tisDistractionFree: select( preferencesStore ).get(\n\t\t\t\teditSiteStore.name,\n\t\t\t\t'distractionFree'\n\t\t\t),\n\t\t};\n\t}, [] );\n\n\tuseCommand( {\n\t\tname: 'core/edit-site/open-global-styles-revisions',\n\t\tlabel: __( 'Open styles revisions' ),\n\t\ticon: backup,\n\t\tcallback: ( { close } ) => {\n\t\t\tclose();\n\t\t\tif ( ! isEditorPage ) {\n\t\t\t\thistory.push( {\n\t\t\t\t\tpath: '/wp_global_styles',\n\t\t\t\t\tcanvas: 'edit',\n\t\t\t\t} );\n\t\t\t}\n\t\t\tif ( isEditorPage && getCanvasMode() !== 'edit' ) {\n\t\t\t\tsetCanvasMode( 'edit' );\n\t\t\t}\n\t\t\topenGeneralSidebar( 'edit-site/global-styles' );\n\t\t\tsetEditorCanvasContainerView( 'global-styles-revisions' );\n\t\t},\n\t} );\n\n\tuseCommand( {\n\t\tname: 'core/edit-site/open-styles',\n\t\tlabel: __( 'Open styles' ),\n\t\tcallback: ( { close } ) => {\n\t\t\tclose();\n\t\t\tif ( ! isEditorPage ) {\n\t\t\t\thistory.push( {\n\t\t\t\t\tpath: '/wp_global_styles',\n\t\t\t\t\tcanvas: 'edit',\n\t\t\t\t} );\n\t\t\t}\n\t\t\tif ( isEditorPage && getCanvasMode() !== 'edit' ) {\n\t\t\t\tsetCanvasMode( 'edit' );\n\t\t\t}\n\t\t\tif ( isDistractionFree ) {\n\t\t\t\tset( editSiteStore.name, 'distractionFree', false );\n\t\t\t\tcreateInfoNotice( __( 'Distraction free mode turned off.' ), {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t}\n\t\t\topenGeneralSidebar( 'edit-site/global-styles' );\n\t\t},\n\t\ticon: styles,\n\t} );\n\n\tuseCommand( {\n\t\tname: 'core/edit-site/toggle-styles-welcome-guide',\n\t\tlabel: __( 'Learn about styles' ),\n\t\tcallback: ( { close } ) => {\n\t\t\tclose();\n\t\t\tif ( ! isEditorPage ) {\n\t\t\t\thistory.push( {\n\t\t\t\t\tpath: '/wp_global_styles',\n\t\t\t\t\tcanvas: 'edit',\n\t\t\t\t} );\n\t\t\t}\n\t\t\tif ( isEditorPage && getCanvasMode() !== 'edit' ) {\n\t\t\t\tsetCanvasMode( 'edit' );\n\t\t\t}\n\t\t\topenGeneralSidebar( 'edit-site/global-styles' );\n\t\t\tset( 'core/edit-site', 'welcomeGuideStyles', true );\n\t\t\t// sometimes there's a focus loss that happens after some time\n\t\t\t// that closes the modal, we need to force reopening it.\n\t\t\tsetTimeout( () => {\n\t\t\t\tset( 'core/edit-site', 'welcomeGuideStyles', true );\n\t\t\t}, 500 );\n\t\t},\n\t\ticon: help,\n\t} );\n\n\tuseCommand( {\n\t\tname: 'core/edit-site/view-site',\n\t\tlabel: __( 'View site' ),\n\t\tcallback: ( { close } ) => {\n\t\t\tclose();\n\t\t\twindow.open( homeUrl, '_blank' );\n\t\t},\n\t\ticon: external,\n\t} );\n\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/reset-global-styles',\n\t\thook: useGlobalStylesResetCommands,\n\t} );\n\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/open-styles-css',\n\t\thook: useGlobalStylesOpenCssCommands,\n\t} );\n}\n"]}
@@ -2,8 +2,6 @@
2
2
 
3
3
  var _element = require("@wordpress/element");
4
4
 
5
- var _lodash = require("lodash");
6
-
7
5
  var _hooks = require("@wordpress/hooks");
8
6
 
9
7
  var _compose = require("@wordpress/compose");
@@ -24,10 +22,6 @@ var _hooks2 = require("../../components/global-styles/hooks");
24
22
 
25
23
  var _lockUnlock = require("../../lock-unlock");
26
24
 
27
- /**
28
- * External dependencies
29
- */
30
-
31
25
  /**
32
26
  * WordPress dependencies
33
27
  */
@@ -97,6 +91,15 @@ const STYLE_PATH_TO_PRESET_BLOCK_ATTRIBUTE = {
97
91
  'typography.fontSize': 'fontSize',
98
92
  'typography.fontFamily': 'fontFamily'
99
93
  };
94
+ const SUPPORTED_STYLES = ['border', 'color', 'spacing', 'typography'];
95
+
96
+ const getValueFromObjectPath = (object, path) => {
97
+ let value = object;
98
+ path.forEach(fieldName => {
99
+ value = value?.[fieldName];
100
+ });
101
+ return value;
102
+ };
100
103
 
101
104
  function useChangesToPush(name, attributes) {
102
105
  const supports = (0, _hooks2.useSupportedStyles)(name);
@@ -110,13 +113,55 @@ function useChangesToPush(name, attributes) {
110
113
  } = _blocks.__EXPERIMENTAL_STYLE_PROPERTY[key];
111
114
  const presetAttributeKey = path.join('.');
112
115
  const presetAttributeValue = attributes[STYLE_PATH_TO_PRESET_BLOCK_ATTRIBUTE[presetAttributeKey]];
113
- const value = presetAttributeValue ? `var:preset|${STYLE_PATH_TO_CSS_VAR_INFIX[presetAttributeKey]}|${presetAttributeValue}` : (0, _lodash.get)(attributes.style, path);
116
+ const value = presetAttributeValue ? `var:preset|${STYLE_PATH_TO_CSS_VAR_INFIX[presetAttributeKey]}|${presetAttributeValue}` : getValueFromObjectPath(attributes.style, path);
114
117
  return value ? [{
115
118
  path,
116
119
  value
117
120
  }] : [];
118
121
  }), [supports, name, attributes]);
119
122
  }
123
+ /**
124
+ * Sets the value at path of object.
125
+ * If a portion of path doesn’t exist, it’s created.
126
+ * Arrays are created for missing index properties while objects are created
127
+ * for all other missing properties.
128
+ *
129
+ * This function intentionally mutates the input object.
130
+ *
131
+ * Inspired by _.set().
132
+ *
133
+ * @see https://lodash.com/docs/4.17.15#set
134
+ *
135
+ * @todo Needs to be deduplicated with its copy in `@wordpress/core-data`.
136
+ *
137
+ * @param {Object} object Object to modify
138
+ * @param {Array} path Path of the property to set.
139
+ * @param {*} value Value to set.
140
+ */
141
+
142
+
143
+ function setNestedValue(object, path, value) {
144
+ if (!object || typeof object !== 'object') {
145
+ return object;
146
+ }
147
+
148
+ path.reduce((acc, key, idx) => {
149
+ if (acc[key] === undefined) {
150
+ if (Number.isInteger(path[idx + 1])) {
151
+ acc[key] = [];
152
+ } else {
153
+ acc[key] = {};
154
+ }
155
+ }
156
+
157
+ if (idx === path.length - 1) {
158
+ acc[key] = value;
159
+ }
160
+
161
+ return acc[key];
162
+ }, object);
163
+ return object;
164
+ }
120
165
 
121
166
  function cloneDeep(object) {
122
167
  return !object ? {} : JSON.parse(JSON.stringify(object));
@@ -153,8 +198,8 @@ function PushChangesToGlobalStylesControl({
153
198
  path,
154
199
  value
155
200
  } of changes) {
156
- (0, _lodash.set)(newBlockStyles, path, undefined);
157
- (0, _lodash.set)(newUserConfig, ['styles', 'blocks', name, ...path], value);
201
+ setNestedValue(newBlockStyles, path, undefined);
202
+ setNestedValue(newUserConfig, ['styles', 'blocks', name, ...path], value);
158
203
  } // @wordpress/core-data doesn't support editing multiple entity types in
159
204
  // a single undo level. So for now, we disable @wordpress/core-data undo
160
205
  // tracking and implement our own Undo button in the snackbar
@@ -202,8 +247,9 @@ function PushChangesToGlobalStylesControl({
202
247
 
203
248
  const withPushChangesToGlobalStyles = (0, _compose.createHigherOrderComponent)(BlockEdit => props => {
204
249
  const blockEditingMode = useBlockEditingMode();
250
+ const supportsStyles = SUPPORTED_STYLES.some(feature => (0, _blocks.hasBlockSupport)(props.name, feature));
205
251
  return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(BlockEdit, { ...props
206
- }), blockEditingMode === 'default' && (0, _element.createElement)(_blockEditor.InspectorAdvancedControls, null, (0, _element.createElement)(PushChangesToGlobalStylesControl, { ...props
252
+ }), blockEditingMode === 'default' && supportsStyles && (0, _element.createElement)(_blockEditor.InspectorAdvancedControls, null, (0, _element.createElement)(PushChangesToGlobalStylesControl, { ...props
207
253
  })));
208
254
  });
209
255
  (0, _hooks.addFilter)('editor.BlockEdit', 'core/edit-site/push-changes-to-global-styles', withPushChangesToGlobalStyles);
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/hooks/push-changes-to-global-styles/index.js"],"names":["GlobalStylesContext","useBlockEditingMode","blockEditorPrivateApis","STYLE_PATH_TO_CSS_VAR_INFIX","STYLE_PATH_TO_PRESET_BLOCK_ATTRIBUTE","useChangesToPush","name","attributes","supports","flatMap","key","STYLE_PROPERTY","value","path","presetAttributeKey","join","presetAttributeValue","style","cloneDeep","object","JSON","parse","stringify","PushChangesToGlobalStylesControl","setAttributes","changes","user","userConfig","setUserConfig","__unstableMarkNextChangeAsNotPersistent","blockEditorStore","createSuccessNotice","noticesStore","pushChanges","length","blockStyles","newBlockStyles","newUserConfig","undefined","undoIgnore","title","type","actions","label","onClick","withPushChangesToGlobalStyles","BlockEdit","props","blockEditingMode"],"mappings":";;AAqBA;;AAlBA;;AAKA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AAKA;;AACA;;AAKA;;AACA;;AA7BA;AACA;AACA;;AAGA;AACA;AACA;;AAkBA;AACA;AACA;AAIA,MAAM;AAAEA,EAAAA,mBAAF;AAAuBC,EAAAA;AAAvB,IAA+C,wBACpDC,wBADoD,CAArD,C,CAIA;AACA;AACA;;AACA,MAAMC,2BAA2B,GAAG;AACnC,sBAAoB,OADe;AAEnC,gBAAc,OAFqB;AAGnC,8BAA4B,OAHO;AAInC,qCAAmC,OAJA;AAKnC,yCAAuC,aALJ;AAMnC,uCAAqC,WANF;AAOnC,gCAA8B,OAPK;AAQnC,sCAAoC,OARD;AASnC,2CAAyC,aATN;AAUnC,yCAAuC,WAVJ;AAWnC,iCAA+B,OAXI;AAYnC,4BAA0B,OAZS;AAanC,uCAAqC,OAbF;AAcnC,4CAA0C,aAdP;AAenC,+BAA6B,UAfM;AAgBnC,qCAAmC,UAhBA;AAiBnC,uBAAqB,OAjBc;AAkBnC,kCAAgC,OAlBG;AAmBnC,uCAAqC,aAnBF;AAoBnC,gCAA8B,UApBK;AAqBnC,uBAAqB,OArBc;AAsBnC,kCAAgC,OAtBG;AAuBnC,uCAAqC,aAvBF;AAwBnC,gCAA8B,UAxBK;AAyBnC,uBAAqB,OAzBc;AA0BnC,kCAAgC,OA1BG;AA2BnC,uCAAqC,aA3BF;AA4BnC,gCAA8B,UA5BK;AA6BnC,uBAAqB,OA7Bc;AA8BnC,kCAAgC,OA9BG;AA+BnC,uCAAqC,aA/BF;AAgCnC,gCAA8B,UAhCK;AAiCnC,uBAAqB,OAjCc;AAkCnC,kCAAgC,OAlCG;AAmCnC,uCAAqC,aAnCF;AAoCnC,gCAA8B,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CAboC,CAAtC;AAgBA,sBACC,kBADD,EAEC,8CAFD,EAGCF,6BAHD","sourcesContent":["/**\n * External dependencies\n */\nimport { get, set } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport {\n\tInspectorAdvancedControls,\n\tstore as blockEditorStore,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { BaseControl, Button } from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\t__EXPERIMENTAL_STYLE_PROPERTY as STYLE_PROPERTY,\n\tgetBlockType,\n} from '@wordpress/blocks';\nimport { useContext, useMemo, useCallback } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport { useSupportedStyles } from '../../components/global-styles/hooks';\nimport { unlock } from '../../lock-unlock';\n\nconst { GlobalStylesContext, useBlockEditingMode } = unlock(\n\tblockEditorPrivateApis\n);\n\n// TODO: Temporary duplication of constant in @wordpress/block-editor. Can be\n// removed by moving PushChangesToGlobalStylesControl to\n// @wordpress/block-editor.\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.link.:hover.color.text': 'color',\n\t'elements.link.typography.fontFamily': 'font-family',\n\t'elements.link.typography.fontSize': 'font-size',\n\t'elements.button.color.text': 'color',\n\t'elements.button.color.background': 'color',\n\t'elements.button.typography.fontFamily': 'font-family',\n\t'elements.button.typography.fontSize': 'font-size',\n\t'elements.caption.color.text': 'color',\n\t'elements.heading.color': 'color',\n\t'elements.heading.color.background': 'color',\n\t'elements.heading.typography.fontFamily': 'font-family',\n\t'elements.heading.gradient': 'gradient',\n\t'elements.heading.color.gradient': 'gradient',\n\t'elements.h1.color': 'color',\n\t'elements.h1.color.background': 'color',\n\t'elements.h1.typography.fontFamily': 'font-family',\n\t'elements.h1.color.gradient': 'gradient',\n\t'elements.h2.color': 'color',\n\t'elements.h2.color.background': 'color',\n\t'elements.h2.typography.fontFamily': 'font-family',\n\t'elements.h2.color.gradient': 'gradient',\n\t'elements.h3.color': 'color',\n\t'elements.h3.color.background': 'color',\n\t'elements.h3.typography.fontFamily': 'font-family',\n\t'elements.h3.color.gradient': 'gradient',\n\t'elements.h4.color': 'color',\n\t'elements.h4.color.background': 'color',\n\t'elements.h4.typography.fontFamily': 'font-family',\n\t'elements.h4.color.gradient': 'gradient',\n\t'elements.h5.color': 'color',\n\t'elements.h5.color.background': 'color',\n\t'elements.h5.typography.fontFamily': 'font-family',\n\t'elements.h5.color.gradient': 'gradient',\n\t'elements.h6.color': 'color',\n\t'elements.h6.color.background': 'color',\n\t'elements.h6.typography.fontFamily': 'font-family',\n\t'elements.h6.color.gradient': 'gradient',\n\t'color.gradient': 'gradient',\n\t'typography.fontSize': 'font-size',\n\t'typography.fontFamily': 'font-family',\n};\n\n// TODO: Temporary duplication of constant in @wordpress/block-editor. Can be\n// removed by moving PushChangesToGlobalStylesControl to\n// @wordpress/block-editor.\nconst STYLE_PATH_TO_PRESET_BLOCK_ATTRIBUTE = {\n\t'color.background': 'backgroundColor',\n\t'color.text': 'textColor',\n\t'color.gradient': 'gradient',\n\t'typography.fontSize': 'fontSize',\n\t'typography.fontFamily': 'fontFamily',\n};\n\nfunction useChangesToPush( name, attributes ) {\n\tconst supports = useSupportedStyles( name );\n\n\treturn useMemo(\n\t\t() =>\n\t\t\tsupports.flatMap( ( key ) => {\n\t\t\t\tif ( ! STYLE_PROPERTY[ key ] ) {\n\t\t\t\t\treturn [];\n\t\t\t\t}\n\t\t\t\tconst { value: path } = STYLE_PROPERTY[ key ];\n\t\t\t\tconst presetAttributeKey = path.join( '.' );\n\t\t\t\tconst presetAttributeValue =\n\t\t\t\t\tattributes[\n\t\t\t\t\t\tSTYLE_PATH_TO_PRESET_BLOCK_ATTRIBUTE[\n\t\t\t\t\t\t\tpresetAttributeKey\n\t\t\t\t\t\t]\n\t\t\t\t\t];\n\t\t\t\tconst value = presetAttributeValue\n\t\t\t\t\t? `var:preset|${ STYLE_PATH_TO_CSS_VAR_INFIX[ presetAttributeKey ] }|${ presetAttributeValue }`\n\t\t\t\t\t: get( attributes.style, path );\n\t\t\t\treturn value ? [ { path, value } ] : [];\n\t\t\t} ),\n\t\t[ supports, name, attributes ]\n\t);\n}\n\nfunction cloneDeep( object ) {\n\treturn ! object ? {} : JSON.parse( JSON.stringify( object ) );\n}\n\nfunction PushChangesToGlobalStylesControl( {\n\tname,\n\tattributes,\n\tsetAttributes,\n} ) {\n\tconst changes = useChangesToPush( name, attributes );\n\n\tconst { user: userConfig, setUserConfig } =\n\t\tuseContext( GlobalStylesContext );\n\n\tconst { __unstableMarkNextChangeAsNotPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\n\tconst pushChanges = useCallback( () => {\n\t\tif ( changes.length === 0 ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { style: blockStyles } = attributes;\n\n\t\tconst newBlockStyles = cloneDeep( blockStyles );\n\t\tconst newUserConfig = cloneDeep( userConfig );\n\n\t\tfor ( const { path, value } of changes ) {\n\t\t\tset( newBlockStyles, path, undefined );\n\t\t\tset( newUserConfig, [ 'styles', 'blocks', name, ...path ], value );\n\t\t}\n\n\t\t// @wordpress/core-data doesn't support editing multiple entity types in\n\t\t// a single undo level. So for now, we disable @wordpress/core-data undo\n\t\t// tracking and implement our own Undo button in the snackbar\n\t\t// notification.\n\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\tsetAttributes( { style: newBlockStyles } );\n\t\tsetUserConfig( () => newUserConfig, { undoIgnore: true } );\n\n\t\tcreateSuccessNotice(\n\t\t\tsprintf(\n\t\t\t\t// translators: %s: Title of the block e.g. 'Heading'.\n\t\t\t\t__( '%s styles applied.' ),\n\t\t\t\tgetBlockType( name ).title\n\t\t\t),\n\t\t\t{\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tactions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tlabel: __( 'Undo' ),\n\t\t\t\t\t\tonClick() {\n\t\t\t\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\t\t\t\tsetAttributes( { style: blockStyles } );\n\t\t\t\t\t\t\tsetUserConfig( () => userConfig, {\n\t\t\t\t\t\t\t\tundoIgnore: true,\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],\n\t\t\t}\n\t\t);\n\t}, [ changes, attributes, userConfig, name ] );\n\n\treturn (\n\t\t<BaseControl\n\t\t\tclassName=\"edit-site-push-changes-to-global-styles-control\"\n\t\t\thelp={ sprintf(\n\t\t\t\t// translators: %s: Title of the block e.g. 'Heading'.\n\t\t\t\t__(\n\t\t\t\t\t'Apply this block’s typography, spacing, dimensions, and color styles to all %s blocks.'\n\t\t\t\t),\n\t\t\t\tgetBlockType( name ).title\n\t\t\t) }\n\t\t>\n\t\t\t<BaseControl.VisualLabel>\n\t\t\t\t{ __( 'Styles' ) }\n\t\t\t</BaseControl.VisualLabel>\n\t\t\t<Button\n\t\t\t\tvariant=\"primary\"\n\t\t\t\tdisabled={ changes.length === 0 }\n\t\t\t\tonClick={ pushChanges }\n\t\t\t>\n\t\t\t\t{ __( 'Apply globally' ) }\n\t\t\t</Button>\n\t\t</BaseControl>\n\t);\n}\n\nconst withPushChangesToGlobalStyles = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst blockEditingMode = useBlockEditingMode();\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<BlockEdit { ...props } />\n\t\t\t\t{ blockEditingMode === 'default' && (\n\t\t\t\t\t<InspectorAdvancedControls>\n\t\t\t\t\t\t<PushChangesToGlobalStylesControl { ...props } />\n\t\t\t\t\t</InspectorAdvancedControls>\n\t\t\t\t) }\n\t\t\t</>\n\t\t);\n\t}\n);\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/edit-site/push-changes-to-global-styles',\n\twithPushChangesToGlobalStyles\n);\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-site/src/hooks/push-changes-to-global-styles/index.js"],"names":["GlobalStylesContext","useBlockEditingMode","blockEditorPrivateApis","STYLE_PATH_TO_CSS_VAR_INFIX","STYLE_PATH_TO_PRESET_BLOCK_ATTRIBUTE","SUPPORTED_STYLES","getValueFromObjectPath","object","path","value","forEach","fieldName","useChangesToPush","name","attributes","supports","flatMap","key","STYLE_PROPERTY","presetAttributeKey","join","presetAttributeValue","style","setNestedValue","reduce","acc","idx","undefined","Number","isInteger","length","cloneDeep","JSON","parse","stringify","PushChangesToGlobalStylesControl","setAttributes","changes","user","userConfig","setUserConfig","__unstableMarkNextChangeAsNotPersistent","blockEditorStore","createSuccessNotice","noticesStore","pushChanges","blockStyles","newBlockStyles","newUserConfig","undoIgnore","title","type","actions","label","onClick","withPushChangesToGlobalStyles","BlockEdit","props","blockEditingMode","supportsStyles","some","feature"],"mappings":";;AAiBA;;AAdA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AAMA;;AACA;;AAKA;;AACA;;AAzBA;AACA;AACA;;AAmBA;AACA;AACA;AAIA,MAAM;AAAEA,EAAAA,mBAAF;AAAuBC,EAAAA;AAAvB,IAA+C,wBACpDC,wBADoD,CAArD,C,CAIA;AACA;AACA;;AACA,MAAMC,2BAA2B,GAAG;AACnC,sBAAoB,OADe;AAEnC,gBAAc,OAFqB;AAGnC,8BAA4B,OAHO;AAInC,qCAAmC,OAJA;AAKnC,yCAAuC,aALJ;AAMnC,uCAAqC,WANF;AAOnC,gCAA8B,OAPK;AAQnC,sCAAoC,OARD;AASnC,2CAAyC,aATN;AAUnC,yCAAuC,WAVJ;AAWnC,iCAA+B,OAXI;AAYnC,4BAA0B,OAZS;AAanC,uCAAqC,OAbF;AAcnC,4CAA0C,aAdP;AAenC,+BAA6B,UAfM;AAgBnC,qCAAmC,UAhBA;AAi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AJ,CADH,CAVD,EAaC,4BAAC,kBAAD;AACC,IAAA,OAAO,EAAC,SADT;AAEC,IAAA,QAAQ,EAAGb,OAAO,CAACP,MAAR,KAAmB,CAF/B;AAGC,IAAA,OAAO,EAAGe;AAHX,KAKG,cAAI,gBAAJ,CALH,CAbD,CADD;AAuBA;;AAED,MAAMU,6BAA6B,GAAG,yCACnCC,SAAF,IAAmBC,KAAF,IAAa;AAC7B,QAAMC,gBAAgB,GAAGzD,mBAAmB,EAA5C;AACA,QAAM0D,cAAc,GAAGtD,gBAAgB,CAACuD,IAAjB,CAAyBC,OAAF,IAC7C,6BAAiBJ,KAAK,CAAC5C,IAAvB,EAA6BgD,OAA7B,CADsB,CAAvB;AAIA,SACC,qDACC,4BAAC,SAAD,OAAgBJ;AAAhB,IADD,EAEGC,gBAAgB,KAAK,SAArB,IAAkCC,cAAlC,IACD,4BAAC,sCAAD,QACC,4BAAC,gCAAD,OAAuCF;AAAvC,IADD,CAHF,CADD;AAUA,CAjBoC,CAAtC;AAoBA,sBACC,kBADD,EAEC,8CAFD,EAGCF,6BAHD","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport {\n\tInspectorAdvancedControls,\n\tstore as blockEditorStore,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { BaseControl, Button } from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\t__EXPERIMENTAL_STYLE_PROPERTY as STYLE_PROPERTY,\n\tgetBlockType,\n\thasBlockSupport,\n} from '@wordpress/blocks';\nimport { useContext, useMemo, useCallback } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport { useSupportedStyles } from '../../components/global-styles/hooks';\nimport { unlock } from '../../lock-unlock';\n\nconst { GlobalStylesContext, useBlockEditingMode } = unlock(\n\tblockEditorPrivateApis\n);\n\n// TODO: Temporary duplication of constant in @wordpress/block-editor. Can be\n// removed by moving PushChangesToGlobalStylesControl to\n// @wordpress/block-editor.\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.link.:hover.color.text': 'color',\n\t'elements.link.typography.fontFamily': 'font-family',\n\t'elements.link.typography.fontSize': 'font-size',\n\t'elements.button.color.text': 'color',\n\t'elements.button.color.background': 'color',\n\t'elements.button.typography.fontFamily': 'font-family',\n\t'elements.button.typography.fontSize': 'font-size',\n\t'elements.caption.color.text': 'color',\n\t'elements.heading.color': 'color',\n\t'elements.heading.color.background': 'color',\n\t'elements.heading.typography.fontFamily': 'font-family',\n\t'elements.heading.gradient': 'gradient',\n\t'elements.heading.color.gradient': 'gradient',\n\t'elements.h1.color': 'color',\n\t'elements.h1.color.background': 'color',\n\t'elements.h1.typography.fontFamily': 'font-family',\n\t'elements.h1.color.gradient': 'gradient',\n\t'elements.h2.color': 'color',\n\t'elements.h2.color.background': 'color',\n\t'elements.h2.typography.fontFamily': 'font-family',\n\t'elements.h2.color.gradient': 'gradient',\n\t'elements.h3.color': 'color',\n\t'elements.h3.color.background': 'color',\n\t'elements.h3.typography.fontFamily': 'font-family',\n\t'elements.h3.color.gradient': 'gradient',\n\t'elements.h4.color': 'color',\n\t'elements.h4.color.background': 'color',\n\t'elements.h4.typography.fontFamily': 'font-family',\n\t'elements.h4.color.gradient': 'gradient',\n\t'elements.h5.color': 'color',\n\t'elements.h5.color.background': 'color',\n\t'elements.h5.typography.fontFamily': 'font-family',\n\t'elements.h5.color.gradient': 'gradient',\n\t'elements.h6.color': 'color',\n\t'elements.h6.color.background': 'color',\n\t'elements.h6.typography.fontFamily': 'font-family',\n\t'elements.h6.color.gradient': 'gradient',\n\t'color.gradient': 'gradient',\n\t'typography.fontSize': 'font-size',\n\t'typography.fontFamily': 'font-family',\n};\n\n// TODO: Temporary duplication of constant in @wordpress/block-editor. Can be\n// removed by moving PushChangesToGlobalStylesControl to\n// @wordpress/block-editor.\nconst STYLE_PATH_TO_PRESET_BLOCK_ATTRIBUTE = {\n\t'color.background': 'backgroundColor',\n\t'color.text': 'textColor',\n\t'color.gradient': 'gradient',\n\t'typography.fontSize': 'fontSize',\n\t'typography.fontFamily': 'fontFamily',\n};\n\nconst SUPPORTED_STYLES = [ 'border', 'color', 'spacing', 'typography' ];\n\nconst getValueFromObjectPath = ( object, path ) => {\n\tlet value = object;\n\tpath.forEach( ( fieldName ) => {\n\t\tvalue = value?.[ fieldName ];\n\t} );\n\treturn value;\n};\n\nfunction useChangesToPush( name, attributes ) {\n\tconst supports = useSupportedStyles( name );\n\n\treturn useMemo(\n\t\t() =>\n\t\t\tsupports.flatMap( ( key ) => {\n\t\t\t\tif ( ! STYLE_PROPERTY[ key ] ) {\n\t\t\t\t\treturn [];\n\t\t\t\t}\n\t\t\t\tconst { value: path } = STYLE_PROPERTY[ key ];\n\t\t\t\tconst presetAttributeKey = path.join( '.' );\n\t\t\t\tconst presetAttributeValue =\n\t\t\t\t\tattributes[\n\t\t\t\t\t\tSTYLE_PATH_TO_PRESET_BLOCK_ATTRIBUTE[\n\t\t\t\t\t\t\tpresetAttributeKey\n\t\t\t\t\t\t]\n\t\t\t\t\t];\n\t\t\t\tconst value = presetAttributeValue\n\t\t\t\t\t? `var:preset|${ STYLE_PATH_TO_CSS_VAR_INFIX[ presetAttributeKey ] }|${ presetAttributeValue }`\n\t\t\t\t\t: getValueFromObjectPath( attributes.style, path );\n\t\t\t\treturn value ? [ { path, value } ] : [];\n\t\t\t} ),\n\t\t[ supports, name, attributes ]\n\t);\n}\n\n/**\n * Sets the value at path of object.\n * If a portion of path doesn’t exist, it’s created.\n * Arrays are created for missing index properties while objects are created\n * for all other missing properties.\n *\n * This function intentionally mutates the input object.\n *\n * Inspired by _.set().\n *\n * @see https://lodash.com/docs/4.17.15#set\n *\n * @todo Needs to be deduplicated with its copy in `@wordpress/core-data`.\n *\n * @param {Object} object Object to modify\n * @param {Array} path Path of the property to set.\n * @param {*} value Value to set.\n */\nfunction setNestedValue( object, path, value ) {\n\tif ( ! object || typeof object !== 'object' ) {\n\t\treturn object;\n\t}\n\n\tpath.reduce( ( acc, key, idx ) => {\n\t\tif ( acc[ key ] === undefined ) {\n\t\t\tif ( Number.isInteger( path[ idx + 1 ] ) ) {\n\t\t\t\tacc[ key ] = [];\n\t\t\t} else {\n\t\t\t\tacc[ key ] = {};\n\t\t\t}\n\t\t}\n\t\tif ( idx === path.length - 1 ) {\n\t\t\tacc[ key ] = value;\n\t\t}\n\t\treturn acc[ key ];\n\t}, object );\n\n\treturn object;\n}\n\nfunction cloneDeep( object ) {\n\treturn ! object ? {} : JSON.parse( JSON.stringify( object ) );\n}\n\nfunction PushChangesToGlobalStylesControl( {\n\tname,\n\tattributes,\n\tsetAttributes,\n} ) {\n\tconst changes = useChangesToPush( name, attributes );\n\n\tconst { user: userConfig, setUserConfig } =\n\t\tuseContext( GlobalStylesContext );\n\n\tconst { __unstableMarkNextChangeAsNotPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\n\tconst pushChanges = useCallback( () => {\n\t\tif ( changes.length === 0 ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { style: blockStyles } = attributes;\n\n\t\tconst newBlockStyles = cloneDeep( blockStyles );\n\t\tconst newUserConfig = cloneDeep( userConfig );\n\n\t\tfor ( const { path, value } of changes ) {\n\t\t\tsetNestedValue( newBlockStyles, path, undefined );\n\t\t\tsetNestedValue(\n\t\t\t\tnewUserConfig,\n\t\t\t\t[ 'styles', 'blocks', name, ...path ],\n\t\t\t\tvalue\n\t\t\t);\n\t\t}\n\n\t\t// @wordpress/core-data doesn't support editing multiple entity types in\n\t\t// a single undo level. So for now, we disable @wordpress/core-data undo\n\t\t// tracking and implement our own Undo button in the snackbar\n\t\t// notification.\n\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\tsetAttributes( { style: newBlockStyles } );\n\t\tsetUserConfig( () => newUserConfig, { undoIgnore: true } );\n\n\t\tcreateSuccessNotice(\n\t\t\tsprintf(\n\t\t\t\t// translators: %s: Title of the block e.g. 'Heading'.\n\t\t\t\t__( '%s styles applied.' ),\n\t\t\t\tgetBlockType( name ).title\n\t\t\t),\n\t\t\t{\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tactions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tlabel: __( 'Undo' ),\n\t\t\t\t\t\tonClick() {\n\t\t\t\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\t\t\t\tsetAttributes( { style: blockStyles } );\n\t\t\t\t\t\t\tsetUserConfig( () => userConfig, {\n\t\t\t\t\t\t\t\tundoIgnore: true,\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],\n\t\t\t}\n\t\t);\n\t}, [ changes, attributes, userConfig, name ] );\n\n\treturn (\n\t\t<BaseControl\n\t\t\tclassName=\"edit-site-push-changes-to-global-styles-control\"\n\t\t\thelp={ sprintf(\n\t\t\t\t// translators: %s: Title of the block e.g. 'Heading'.\n\t\t\t\t__(\n\t\t\t\t\t'Apply this block’s typography, spacing, dimensions, and color styles to all %s blocks.'\n\t\t\t\t),\n\t\t\t\tgetBlockType( name ).title\n\t\t\t) }\n\t\t>\n\t\t\t<BaseControl.VisualLabel>\n\t\t\t\t{ __( 'Styles' ) }\n\t\t\t</BaseControl.VisualLabel>\n\t\t\t<Button\n\t\t\t\tvariant=\"primary\"\n\t\t\t\tdisabled={ changes.length === 0 }\n\t\t\t\tonClick={ pushChanges }\n\t\t\t>\n\t\t\t\t{ __( 'Apply globally' ) }\n\t\t\t</Button>\n\t\t</BaseControl>\n\t);\n}\n\nconst withPushChangesToGlobalStyles = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst blockEditingMode = useBlockEditingMode();\n\t\tconst supportsStyles = SUPPORTED_STYLES.some( ( feature ) =>\n\t\t\thasBlockSupport( props.name, feature )\n\t\t);\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<BlockEdit { ...props } />\n\t\t\t\t{ blockEditingMode === 'default' && supportsStyles && (\n\t\t\t\t\t<InspectorAdvancedControls>\n\t\t\t\t\t\t<PushChangesToGlobalStylesControl { ...props } />\n\t\t\t\t\t</InspectorAdvancedControls>\n\t\t\t\t) }\n\t\t\t</>\n\t\t);\n\t}\n);\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/edit-site/push-changes-to-global-styles',\n\twithPushChangesToGlobalStyles\n);\n"]}
@@ -20,7 +20,8 @@ var _preferences = require("@wordpress/preferences");
20
20
  */
21
21
  const setCanvasMode = mode => ({
22
22
  registry,
23
- dispatch
23
+ dispatch,
24
+ select
24
25
  }) => {
25
26
  registry.dispatch(_blockEditor.store).__unstableSetEditorMode('edit');
26
27
 
@@ -31,6 +32,11 @@ const setCanvasMode = mode => ({
31
32
 
32
33
  if (mode === 'edit' && registry.select(_preferences.store).get('core/edit-site', 'showListViewByDefault')) {
33
34
  dispatch.setIsListViewOpened(true);
35
+ } // Switch focus away from editing the template when switching to view mode.
36
+
37
+
38
+ if (mode === 'view' && select.isPage()) {
39
+ dispatch.setHasPageContentFocus(true);
34
40
  }
35
41
  };
36
42
  /**