@wordpress/block-library 7.0.0 → 7.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (230) hide show
  1. package/README.md +16 -0
  2. package/build/button/edit.native.js +2 -2
  3. package/build/button/edit.native.js.map +1 -1
  4. package/build/columns/index.js +12 -0
  5. package/build/columns/index.js.map +1 -1
  6. package/build/comment-author-avatar/edit.js +17 -4
  7. package/build/comment-author-avatar/edit.js.map +1 -1
  8. package/build/comment-template/edit.js +94 -36
  9. package/build/comment-template/edit.js.map +1 -1
  10. package/build/comment-template/hooks.js +175 -0
  11. package/build/comment-template/hooks.js.map +1 -0
  12. package/build/comment-template/index.js +1 -1
  13. package/build/comment-template/util.js.map +1 -1
  14. package/build/comments-pagination-next/index.js +1 -1
  15. package/build/comments-pagination-numbers/index.js +1 -1
  16. package/build/comments-query-loop/edit/comments-inspector-controls.js +20 -9
  17. package/build/comments-query-loop/edit/comments-inspector-controls.js.map +1 -1
  18. package/build/comments-query-loop/edit.js +1 -19
  19. package/build/comments-query-loop/edit.js.map +1 -1
  20. package/build/comments-query-loop/index.js +5 -0
  21. package/build/comments-query-loop/index.js.map +1 -1
  22. package/build/cover/edit.js +21 -22
  23. package/build/cover/edit.js.map +1 -1
  24. package/build/cover/edit.native.js +7 -5
  25. package/build/cover/edit.native.js.map +1 -1
  26. package/build/cover/overlay-color-settings.native.js +4 -3
  27. package/build/cover/overlay-color-settings.native.js.map +1 -1
  28. package/build/cover/transforms.js +4 -2
  29. package/build/cover/transforms.js.map +1 -1
  30. package/build/group/index.js +1 -0
  31. package/build/group/index.js.map +1 -1
  32. package/build/heading/edit.js +14 -2
  33. package/build/heading/edit.js.map +1 -1
  34. package/build/image/deprecated.js +89 -5
  35. package/build/image/deprecated.js.map +1 -1
  36. package/build/image/save.js +0 -7
  37. package/build/image/save.js.map +1 -1
  38. package/build/latest-posts/edit.js +1 -0
  39. package/build/latest-posts/edit.js.map +1 -1
  40. package/build/navigation/edit/index.js +17 -15
  41. package/build/navigation/edit/index.js.map +1 -1
  42. package/build/navigation/edit/navigation-menu-selector.js +44 -27
  43. package/build/navigation/edit/navigation-menu-selector.js.map +1 -1
  44. package/build/navigation/edit/placeholder/index.js +8 -22
  45. package/build/navigation/edit/placeholder/index.js.map +1 -1
  46. package/build/navigation/use-navigation-menu.js +6 -6
  47. package/build/navigation/use-navigation-menu.js.map +1 -1
  48. package/build/navigation-submenu/edit.js +41 -9
  49. package/build/navigation-submenu/edit.js.map +1 -1
  50. package/build/page-list/edit.js +11 -17
  51. package/build/page-list/edit.js.map +1 -1
  52. package/build/social-links/deprecated.js +1 -62
  53. package/build/social-links/deprecated.js.map +1 -1
  54. package/build/template-part/edit/index.js +36 -64
  55. package/build/template-part/edit/index.js.map +1 -1
  56. package/build/template-part/edit/placeholder.js +64 -0
  57. package/build/template-part/edit/placeholder.js.map +1 -0
  58. package/build/template-part/edit/selection-modal.js +103 -0
  59. package/build/template-part/edit/selection-modal.js.map +1 -0
  60. package/build/template-part/edit/title-modal.js +54 -0
  61. package/build/template-part/edit/title-modal.js.map +1 -0
  62. package/build/template-part/edit/utils/hooks.js +156 -0
  63. package/build/template-part/edit/utils/hooks.js.map +1 -0
  64. package/build/template-part/index.js +3 -1
  65. package/build/template-part/index.js.map +1 -1
  66. package/build-module/button/edit.native.js +4 -4
  67. package/build-module/button/edit.native.js.map +1 -1
  68. package/build-module/columns/index.js +12 -0
  69. package/build-module/columns/index.js.map +1 -1
  70. package/build-module/comment-author-avatar/edit.js +18 -6
  71. package/build-module/comment-author-avatar/edit.js.map +1 -1
  72. package/build-module/comment-template/edit.js +95 -37
  73. package/build-module/comment-template/edit.js.map +1 -1
  74. package/build-module/comment-template/hooks.js +156 -0
  75. package/build-module/comment-template/hooks.js.map +1 -0
  76. package/build-module/comment-template/index.js +1 -1
  77. package/build-module/comment-template/util.js.map +1 -1
  78. package/build-module/comments-pagination-next/index.js +1 -1
  79. package/build-module/comments-pagination-numbers/index.js +1 -1
  80. package/build-module/comments-query-loop/edit/comments-inspector-controls.js +20 -9
  81. package/build-module/comments-query-loop/edit/comments-inspector-controls.js.map +1 -1
  82. package/build-module/comments-query-loop/edit.js +2 -19
  83. package/build-module/comments-query-loop/edit.js.map +1 -1
  84. package/build-module/comments-query-loop/index.js +5 -0
  85. package/build-module/comments-query-loop/index.js.map +1 -1
  86. package/build-module/cover/edit.js +23 -24
  87. package/build-module/cover/edit.js.map +1 -1
  88. package/build-module/cover/edit.native.js +10 -8
  89. package/build-module/cover/edit.native.js.map +1 -1
  90. package/build-module/cover/overlay-color-settings.native.js +4 -4
  91. package/build-module/cover/overlay-color-settings.native.js.map +1 -1
  92. package/build-module/cover/transforms.js +4 -2
  93. package/build-module/cover/transforms.js.map +1 -1
  94. package/build-module/group/index.js +1 -0
  95. package/build-module/group/index.js.map +1 -1
  96. package/build-module/heading/edit.js +15 -3
  97. package/build-module/heading/edit.js.map +1 -1
  98. package/build-module/image/deprecated.js +90 -7
  99. package/build-module/image/deprecated.js.map +1 -1
  100. package/build-module/image/save.js +0 -7
  101. package/build-module/image/save.js.map +1 -1
  102. package/build-module/latest-posts/edit.js +1 -0
  103. package/build-module/latest-posts/edit.js.map +1 -1
  104. package/build-module/navigation/edit/index.js +17 -15
  105. package/build-module/navigation/edit/index.js.map +1 -1
  106. package/build-module/navigation/edit/navigation-menu-selector.js +45 -27
  107. package/build-module/navigation/edit/navigation-menu-selector.js.map +1 -1
  108. package/build-module/navigation/edit/placeholder/index.js +8 -21
  109. package/build-module/navigation/edit/placeholder/index.js.map +1 -1
  110. package/build-module/navigation/use-navigation-menu.js +6 -6
  111. package/build-module/navigation/use-navigation-menu.js.map +1 -1
  112. package/build-module/navigation-submenu/edit.js +41 -10
  113. package/build-module/navigation-submenu/edit.js.map +1 -1
  114. package/build-module/page-list/edit.js +12 -18
  115. package/build-module/page-list/edit.js.map +1 -1
  116. package/build-module/social-links/deprecated.js +1 -62
  117. package/build-module/social-links/deprecated.js.map +1 -1
  118. package/build-module/template-part/edit/index.js +37 -65
  119. package/build-module/template-part/edit/index.js.map +1 -1
  120. package/build-module/template-part/edit/placeholder.js +52 -0
  121. package/build-module/template-part/edit/placeholder.js.map +1 -0
  122. package/build-module/template-part/edit/selection-modal.js +89 -0
  123. package/build-module/template-part/edit/selection-modal.js.map +1 -0
  124. package/build-module/template-part/edit/title-modal.js +46 -0
  125. package/build-module/template-part/edit/title-modal.js.map +1 -0
  126. package/build-module/template-part/edit/utils/hooks.js +135 -0
  127. package/build-module/template-part/edit/utils/hooks.js.map +1 -0
  128. package/build-module/template-part/index.js +2 -1
  129. package/build-module/template-part/index.js.map +1 -1
  130. package/build-style/comment-author-avatar/editor-rtl.css +83 -0
  131. package/build-style/comment-author-avatar/editor.css +83 -0
  132. package/build-style/cover/style-rtl.css +4 -0
  133. package/build-style/cover/style.css +4 -0
  134. package/build-style/editor-rtl.css +27 -81
  135. package/build-style/editor.css +27 -81
  136. package/build-style/image/editor-rtl.css +0 -16
  137. package/build-style/image/editor.css +0 -16
  138. package/build-style/image/style-rtl.css +2 -0
  139. package/build-style/image/style.css +2 -0
  140. package/build-style/navigation/style-rtl.css +14 -3
  141. package/build-style/navigation/style.css +14 -3
  142. package/build-style/page-list/editor-rtl.css +0 -9
  143. package/build-style/page-list/editor.css +0 -9
  144. package/build-style/style-rtl.css +20 -3
  145. package/build-style/style.css +20 -3
  146. package/build-style/template-part/editor-rtl.css +19 -56
  147. package/build-style/template-part/editor.css +19 -56
  148. package/package.json +15 -15
  149. package/src/archives/index.php +1 -1
  150. package/src/button/edit.native.js +3 -3
  151. package/src/columns/block.json +12 -0
  152. package/src/comment-author-avatar/edit.js +13 -8
  153. package/src/comment-author-avatar/editor.scss +7 -0
  154. package/src/comment-template/block.json +7 -1
  155. package/src/comment-template/edit.js +102 -40
  156. package/src/comment-template/hooks.js +151 -0
  157. package/src/comment-template/index.php +8 -0
  158. package/src/comment-template/util.js +1 -0
  159. package/src/comments-pagination-next/block.json +8 -1
  160. package/src/comments-pagination-next/index.php +6 -8
  161. package/src/comments-pagination-numbers/block.json +7 -1
  162. package/src/comments-pagination-numbers/index.php +3 -10
  163. package/src/comments-query-loop/block.json +5 -0
  164. package/src/comments-query-loop/edit/comments-inspector-controls.js +22 -4
  165. package/src/comments-query-loop/edit.js +1 -16
  166. package/src/cover/edit.js +15 -28
  167. package/src/cover/edit.native.js +15 -7
  168. package/src/cover/overlay-color-settings.native.js +3 -4
  169. package/src/cover/style.scss +4 -0
  170. package/src/cover/transforms.js +2 -0
  171. package/src/editor.scss +1 -0
  172. package/src/gallery/index.php +1 -8
  173. package/src/group/block.json +1 -0
  174. package/src/heading/edit.js +18 -5
  175. package/src/home-link/index.php +1 -19
  176. package/src/image/deprecated.js +105 -1
  177. package/src/image/editor.scss +0 -18
  178. package/src/image/save.js +0 -8
  179. package/src/image/style.scss +3 -0
  180. package/src/image/test/edit.native.js +0 -10
  181. package/src/latest-posts/edit.js +1 -0
  182. package/src/latest-posts/index.php +1 -1
  183. package/src/navigation/edit/index.js +25 -26
  184. package/src/navigation/edit/navigation-menu-selector.js +73 -28
  185. package/src/navigation/edit/placeholder/index.js +8 -32
  186. package/src/navigation/index.php +4 -4
  187. package/src/navigation/style.scss +22 -3
  188. package/src/navigation/use-navigation-menu.js +6 -6
  189. package/src/navigation-link/index.php +3 -22
  190. package/src/navigation-submenu/edit.js +50 -12
  191. package/src/navigation-submenu/index.php +3 -21
  192. package/src/page-list/edit.js +21 -25
  193. package/src/page-list/editor.scss +0 -10
  194. package/src/page-list/index.php +4 -4
  195. package/src/post-navigation-link/index.php +3 -3
  196. package/src/search/index.php +6 -3
  197. package/src/site-logo/index.php +1 -1
  198. package/src/social-links/deprecated.js +0 -59
  199. package/src/template-part/edit/index.js +61 -71
  200. package/src/template-part/edit/placeholder.js +78 -0
  201. package/src/template-part/edit/selection-modal.js +115 -0
  202. package/src/template-part/edit/title-modal.js +59 -0
  203. package/src/template-part/edit/utils/hooks.js +158 -0
  204. package/src/template-part/editor.scss +16 -74
  205. package/src/template-part/index.js +4 -1
  206. package/build/navigation/edit/existing-menus-options.js +0 -62
  207. package/build/navigation/edit/existing-menus-options.js.map +0 -1
  208. package/build/template-part/edit/placeholder/index.js +0 -141
  209. package/build/template-part/edit/placeholder/index.js.map +0 -1
  210. package/build/template-part/edit/placeholder/patterns-setup.js +0 -100
  211. package/build/template-part/edit/placeholder/patterns-setup.js.map +0 -1
  212. package/build/template-part/edit/selection/index.js +0 -45
  213. package/build/template-part/edit/selection/index.js.map +0 -1
  214. package/build/template-part/edit/selection/template-part-previews.js +0 -317
  215. package/build/template-part/edit/selection/template-part-previews.js.map +0 -1
  216. package/build-module/navigation/edit/existing-menus-options.js +0 -53
  217. package/build-module/navigation/edit/existing-menus-options.js.map +0 -1
  218. package/build-module/template-part/edit/placeholder/index.js +0 -124
  219. package/build-module/template-part/edit/placeholder/index.js.map +0 -1
  220. package/build-module/template-part/edit/placeholder/patterns-setup.js +0 -91
  221. package/build-module/template-part/edit/placeholder/patterns-setup.js.map +0 -1
  222. package/build-module/template-part/edit/selection/index.js +0 -35
  223. package/build-module/template-part/edit/selection/index.js.map +0 -1
  224. package/build-module/template-part/edit/selection/template-part-previews.js +0 -298
  225. package/build-module/template-part/edit/selection/template-part-previews.js.map +0 -1
  226. package/src/navigation/edit/existing-menus-options.js +0 -70
  227. package/src/template-part/edit/placeholder/index.js +0 -172
  228. package/src/template-part/edit/placeholder/patterns-setup.js +0 -124
  229. package/src/template-part/edit/selection/index.js +0 -37
  230. package/src/template-part/edit/selection/template-part-previews.js +0 -372
@@ -0,0 +1,158 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { find, kebabCase } from 'lodash';
5
+
6
+ /**
7
+ * WordPress dependencies
8
+ */
9
+ import { useDispatch, useSelect } from '@wordpress/data';
10
+ import { store as coreStore } from '@wordpress/core-data';
11
+ import { store as blockEditorStore } from '@wordpress/block-editor';
12
+ import { useMemo } from '@wordpress/element';
13
+ import { serialize } from '@wordpress/blocks';
14
+ import { __ } from '@wordpress/i18n';
15
+
16
+ /**
17
+ * Internal dependencies
18
+ */
19
+ import { createTemplatePartId } from './create-template-part-id';
20
+
21
+ /**
22
+ * Retrieves the available template parts for the given area.
23
+ *
24
+ * @param {string} area Template part area.
25
+ * @param {string} excludedId Template part ID to exclude.
26
+ *
27
+ * @return {{ templateParts: Array, isResolving: boolean }} array of template parts.
28
+ */
29
+ export function useAlternativeTemplateParts( area, excludedId ) {
30
+ const { templateParts, isResolving } = useSelect( ( select ) => {
31
+ const { getEntityRecords, isResolving: _isResolving } = select(
32
+ coreStore
33
+ );
34
+ const query = { per_page: -1 };
35
+ return {
36
+ templateParts: getEntityRecords(
37
+ 'postType',
38
+ 'wp_template_part',
39
+ query
40
+ ),
41
+ isLoading: _isResolving( 'getEntityRecords', [
42
+ 'postType',
43
+ 'wp_template_part',
44
+ query,
45
+ ] ),
46
+ };
47
+ }, [] );
48
+
49
+ const filteredTemplateParts = useMemo( () => {
50
+ if ( ! templateParts ) {
51
+ return [];
52
+ }
53
+ return (
54
+ templateParts.filter(
55
+ ( templatePart ) =>
56
+ createTemplatePartId(
57
+ templatePart.theme,
58
+ templatePart.slug
59
+ ) !== excludedId &&
60
+ ( ! area ||
61
+ 'uncategorized' === area ||
62
+ templatePart.area === area )
63
+ ) || []
64
+ );
65
+ }, [ templateParts, area ] );
66
+
67
+ return {
68
+ templateParts: filteredTemplateParts,
69
+ isResolving,
70
+ };
71
+ }
72
+
73
+ /**
74
+ * Retrieves the available block patterns for the given area.
75
+ *
76
+ * @param {string} area Template part area.
77
+ * @param {string} clientId Block Client ID. (The container of the block can impact allowed blocks).
78
+ *
79
+ * @return {Array} array of block patterns.
80
+ */
81
+ export function useAlternativeBlockPatterns( area, clientId ) {
82
+ return useSelect(
83
+ ( select ) => {
84
+ const blockNameWithArea = area
85
+ ? `core/template-part/${ area }`
86
+ : 'core/template-part';
87
+ const {
88
+ getBlockRootClientId,
89
+ __experimentalGetPatternsByBlockTypes,
90
+ } = select( blockEditorStore );
91
+ const rootClientId = getBlockRootClientId( clientId );
92
+ return __experimentalGetPatternsByBlockTypes(
93
+ blockNameWithArea,
94
+ rootClientId
95
+ );
96
+ },
97
+ [ area, clientId ]
98
+ );
99
+ }
100
+
101
+ export function useCreateTemplatePartFromBlocks( area, setAttributes ) {
102
+ const { saveEntityRecord } = useDispatch( coreStore );
103
+
104
+ return async ( blocks = [], title = __( 'Untitled Template Part' ) ) => {
105
+ // If we have `area` set from block attributes, means an exposed
106
+ // block variation was inserted. So add this prop to the template
107
+ // part entity on creation. Afterwards remove `area` value from
108
+ // block attributes.
109
+ const record = {
110
+ title,
111
+ slug: kebabCase( title ),
112
+ content: serialize( blocks ),
113
+ // `area` is filterable on the server and defaults to `UNCATEGORIZED`
114
+ // if provided value is not allowed.
115
+ area,
116
+ };
117
+ const templatePart = await saveEntityRecord(
118
+ 'postType',
119
+ 'wp_template_part',
120
+ record
121
+ );
122
+ setAttributes( {
123
+ slug: templatePart.slug,
124
+ theme: templatePart.theme,
125
+ area: undefined,
126
+ } );
127
+ };
128
+ }
129
+
130
+ /**
131
+ * Retrieves the template part area object.
132
+ *
133
+ * @param {string} area Template part area identifier.
134
+ *
135
+ * @return {{icon: Object, label: string, tagName: string}} Template Part area.
136
+ */
137
+ export function useTemplatePartArea( area ) {
138
+ return useSelect(
139
+ ( select ) => {
140
+ // FIXME: @wordpress/block-library should not depend on @wordpress/editor.
141
+ // Blocks can be loaded into a *non-post* block editor.
142
+ // eslint-disable-next-line @wordpress/data-no-store-string-literals
143
+ const definedAreas = select(
144
+ 'core/editor'
145
+ ).__experimentalGetDefaultTemplatePartAreas();
146
+
147
+ const selectedArea = find( definedAreas, { area } );
148
+ const defaultArea = find( definedAreas, { area: 'uncategorized' } );
149
+
150
+ return {
151
+ icon: selectedArea?.icon || defaultArea?.icon,
152
+ label: selectedArea?.label || __( 'Template Part' ),
153
+ tagName: selectedArea?.area_tag ?? 'div',
154
+ };
155
+ },
156
+ [ area ]
157
+ );
158
+ }
@@ -1,82 +1,24 @@
1
-
2
- .wp-block-template-part__placeholder-preview-dropdown-content,
3
- .wp-block-template-part__preview-dropdown-content {
4
- .components-popover__content {
5
- min-width: 320px;
6
- padding: 0;
7
- }
8
- }
9
-
10
- .wp-block-template-part__selection-preview-search-form {
11
- border-bottom: $border-width solid $gray-300;
12
- }
13
-
14
- .wp-block-template-part__selection-preview-container {
15
- background: $white;
16
- padding-bottom: 16px;
17
-
18
- .wp-block-template-part__selection-preview-item {
19
- border-radius: $radius-block-ui;
20
- cursor: pointer;
21
- margin-top: $grid-unit-20;
22
- transition: all 0.05s ease-in-out;
23
- border: $border-width solid $gray-300;
24
- width: 100%;
25
- background-color: $white;
26
-
27
- &:hover {
28
- border: $border-width solid var(--wp-admin-theme-color);
29
- }
30
-
31
- &:focus {
32
- box-shadow: inset 0 0 0 1px $white, 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);
33
-
34
- // Windows High Contrast mode will show this outline, but not the box-shadow.
35
- outline: 2px solid transparent;
36
- }
37
-
38
- &.is-placeholder {
39
- min-height: 100px;
40
- }
41
-
42
- .block-editor-block-preview__container {
43
- border-bottom: $border-width solid $gray-300;
44
- }
1
+ .block-editor-template-part__selection-modal {
2
+ // To keep modal dimensions consistent as subsections are navigated, width
3
+ // and height are used instead of max-(width/height).
4
+ @include break-small() {
5
+ width: calc(100% - #{ $grid-unit-20 * 2 });
6
+ height: calc(100% - #{ $header-height * 2 });
45
7
  }
46
-
47
- .wp-block-template-part__selection-preview-item-title {
48
- padding: $grid-unit-05;
49
- font-size: $helptext-font-size;
50
- text-align: left;
8
+ @include break-medium() {
9
+ width: $break-medium - $grid-unit-20 * 2;
51
10
  }
52
-
53
- .wp-block-template-part__selection-panel-group-header {
54
- padding: $grid-unit-20 $grid-unit-20 0;
55
- }
56
-
57
- .wp-block-template-part__selection-panel-group-content {
58
- padding: 0 $grid-unit-20;
59
- }
60
-
61
- .wp-block-template-part__selection-panel-group-title {
62
- color: var(--wp-admin-theme-color);
63
- text-transform: uppercase;
64
- font-size: 11px;
65
- font-weight: 500;
11
+ @include break-large() {
12
+ height: 70%;
66
13
  }
67
14
  }
68
15
 
69
- .wp-block-template-part__placeholder-create-new__title-form {
70
- .wp-block-template-part__placeholder-create-new__title-form-actions {
71
- padding-top: $grid-unit-15;
72
- // Unsure why these styles need to be added since we are using the Flex component with
73
- // flex-end setting. Created issue https://github.com/WordPress/gutenberg/issues/33735 to
74
- // attempt document this issue.
75
- display: flex;
76
- justify-content: flex-end;
16
+ .block-library-template-part__selection-content .block-editor-block-patterns-list {
17
+ display: grid;
18
+ grid-template-columns: 1fr 1fr;
19
+ grid-gap: $grid-unit-10;
77
20
 
78
- .components-flex-item {
79
- margin-left: $grid-unit-15;
80
- }
21
+ .block-editor-block-patterns-list__list-item {
22
+ margin-bottom: 0;
81
23
  }
82
24
  }
@@ -10,6 +10,7 @@ import { store as coreDataStore } from '@wordpress/core-data';
10
10
  import { select } from '@wordpress/data';
11
11
  import { symbolFilled } from '@wordpress/icons';
12
12
  import { addFilter } from '@wordpress/hooks';
13
+ import { decodeEntities } from '@wordpress/html-entities';
13
14
 
14
15
  /**
15
16
  * Internal dependencies
@@ -39,7 +40,9 @@ export const settings = {
39
40
  return;
40
41
  }
41
42
 
42
- return startCase( entity.title?.rendered || entity.slug );
43
+ return (
44
+ decodeEntities( entity.title?.rendered ) || startCase( entity.slug )
45
+ );
43
46
  },
44
47
  edit,
45
48
  };
@@ -1,62 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _element = require("@wordpress/element");
9
-
10
- var _components = require("@wordpress/components");
11
-
12
- var _i18n = require("@wordpress/i18n");
13
-
14
- var _htmlEntities = require("@wordpress/html-entities");
15
-
16
- /**
17
- * WordPress dependencies
18
- */
19
- const ExistingMenusOptions = _ref => {
20
- let {
21
- showNavigationMenus,
22
- showClassicMenus = false,
23
- navigationMenus,
24
- classicMenus,
25
- onSelectNavigationMenu,
26
- onSelectClassicMenu,
27
- actionLabel
28
- } = _ref;
29
- const hasNavigationMenus = !!(navigationMenus !== null && navigationMenus !== void 0 && navigationMenus.length);
30
- const hasClassicMenus = !!(classicMenus !== null && classicMenus !== void 0 && classicMenus.length);
31
- /* translators: %s: The name of a menu. */
32
-
33
- const createActionLabel = (0, _i18n.__)("Create from '%s'");
34
- actionLabel = actionLabel || createActionLabel;
35
- return (0, _element.createElement)(_element.Fragment, null, showNavigationMenus && hasNavigationMenus && (0, _element.createElement)(_components.MenuGroup, {
36
- label: (0, _i18n.__)('Menus')
37
- }, navigationMenus.map(menu => {
38
- const label = (0, _htmlEntities.decodeEntities)(menu.title.rendered);
39
- return (0, _element.createElement)(_components.MenuItem, {
40
- onClick: () => {
41
- onSelectNavigationMenu(menu);
42
- },
43
- key: menu.id,
44
- "aria-label": (0, _i18n.sprintf)(actionLabel, label)
45
- }, label);
46
- })), showClassicMenus && hasClassicMenus && (0, _element.createElement)(_components.MenuGroup, {
47
- label: (0, _i18n.__)('Classic Menus')
48
- }, classicMenus.map(menu => {
49
- const label = (0, _htmlEntities.decodeEntities)(menu.name);
50
- return (0, _element.createElement)(_components.MenuItem, {
51
- onClick: () => {
52
- onSelectClassicMenu(menu);
53
- },
54
- key: menu.id,
55
- "aria-label": (0, _i18n.sprintf)(createActionLabel, label)
56
- }, label);
57
- })));
58
- };
59
-
60
- var _default = ExistingMenusOptions;
61
- exports.default = _default;
62
- //# sourceMappingURL=existing-menus-options.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/block-library/src/navigation/edit/existing-menus-options.js"],"names":["ExistingMenusOptions","showNavigationMenus","showClassicMenus","navigationMenus","classicMenus","onSelectNavigationMenu","onSelectClassicMenu","actionLabel","hasNavigationMenus","length","hasClassicMenus","createActionLabel","map","menu","label","title","rendered","id","name"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AALA;AACA;AACA;AAKA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AM;AACfZ,QAAAA,mBAAmB,CAAEO,IAAF,CAAnB;AACA,OAHF;AAIC,MAAA,GAAG,EAAGA,IAAI,CAACI,EAJZ;AAKC,oBAAa,mBACZN,iBADY,EAEZG,KAFY;AALd,OAUGA,KAVH,CADD;AAcA,GAhBC,CADH,CApBF,CADD;AA2CA,CA5DD;;eA8Ded,oB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { MenuGroup, MenuItem } from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { decodeEntities } from '@wordpress/html-entities';\n\nconst ExistingMenusOptions = ( {\n\tshowNavigationMenus,\n\tshowClassicMenus = false,\n\tnavigationMenus,\n\tclassicMenus,\n\tonSelectNavigationMenu,\n\tonSelectClassicMenu,\n\tactionLabel,\n} ) => {\n\tconst hasNavigationMenus = !! navigationMenus?.length;\n\tconst hasClassicMenus = !! classicMenus?.length;\n\n\t/* translators: %s: The name of a menu. */\n\tconst createActionLabel = __( \"Create from '%s'\" );\n\n\tactionLabel = actionLabel || createActionLabel;\n\n\treturn (\n\t\t<>\n\t\t\t{ showNavigationMenus && hasNavigationMenus && (\n\t\t\t\t<MenuGroup label={ __( 'Menus' ) }>\n\t\t\t\t\t{ navigationMenus.map( ( menu ) => {\n\t\t\t\t\t\tconst label = decodeEntities( menu.title.rendered );\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\tonSelectNavigationMenu( menu );\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\tkey={ menu.id }\n\t\t\t\t\t\t\t\taria-label={ sprintf( actionLabel, label ) }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ label }\n\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t);\n\t\t\t\t\t} ) }\n\t\t\t\t</MenuGroup>\n\t\t\t) }\n\t\t\t{ showClassicMenus && hasClassicMenus && (\n\t\t\t\t<MenuGroup label={ __( 'Classic Menus' ) }>\n\t\t\t\t\t{ classicMenus.map( ( menu ) => {\n\t\t\t\t\t\tconst label = decodeEntities( menu.name );\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\tonSelectClassicMenu( menu );\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\tkey={ menu.id }\n\t\t\t\t\t\t\t\taria-label={ sprintf(\n\t\t\t\t\t\t\t\t\tcreateActionLabel,\n\t\t\t\t\t\t\t\t\tlabel\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ label }\n\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t);\n\t\t\t\t\t} ) }\n\t\t\t\t</MenuGroup>\n\t\t\t) }\n\t\t</>\n\t);\n};\n\nexport default ExistingMenusOptions;\n"]}
@@ -1,141 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = TemplatePartPlaceholder;
9
-
10
- var _element = require("@wordpress/element");
11
-
12
- var _lodash = require("lodash");
13
-
14
- var _i18n = require("@wordpress/i18n");
15
-
16
- var _data = require("@wordpress/data");
17
-
18
- var _components = require("@wordpress/components");
19
-
20
- var _blocks = require("@wordpress/blocks");
21
-
22
- var _coreData = require("@wordpress/core-data");
23
-
24
- var _selection = _interopRequireDefault(require("../selection"));
25
-
26
- var _patternsSetup = _interopRequireDefault(require("./patterns-setup"));
27
-
28
- /**
29
- * External dependencies
30
- */
31
-
32
- /**
33
- * WordPress dependencies
34
- */
35
-
36
- /**
37
- * Internal dependencies
38
- */
39
- const PLACEHOLDER_STEPS = {
40
- initial: 1,
41
- patterns: 2
42
- };
43
-
44
- function TemplatePartPlaceholder(_ref) {
45
- let {
46
- area,
47
- clientId,
48
- setAttributes,
49
- enableSelection,
50
- hasResolvedReplacements
51
- } = _ref;
52
- const {
53
- saveEntityRecord
54
- } = (0, _data.useDispatch)(_coreData.store);
55
- const [step, setStep] = (0, _element.useState)(PLACEHOLDER_STEPS.initial);
56
- const {
57
- areaIcon,
58
- areaLabel
59
- } = (0, _data.useSelect)(select => {
60
- // FIXME: @wordpress/block-library should not depend on @wordpress/editor.
61
- // Blocks can be loaded into a *non-post* block editor.
62
- // eslint-disable-next-line @wordpress/data-no-store-string-literals
63
- const definedAreas = select('core/editor').__experimentalGetDefaultTemplatePartAreas();
64
-
65
- const selectedArea = (0, _lodash.find)(definedAreas, {
66
- area
67
- });
68
- const defaultArea = (0, _lodash.find)(definedAreas, {
69
- area: 'uncategorized'
70
- });
71
- return {
72
- areaIcon: (selectedArea === null || selectedArea === void 0 ? void 0 : selectedArea.icon) || (defaultArea === null || defaultArea === void 0 ? void 0 : defaultArea.icon),
73
- areaLabel: (selectedArea === null || selectedArea === void 0 ? void 0 : selectedArea.label) || (0, _i18n.__)('Template Part')
74
- };
75
- }, [area]);
76
- const onCreate = (0, _element.useCallback)(async function () {
77
- let startingBlocks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
78
- let title = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : (0, _i18n.__)('Untitled Template Part');
79
- // If we have `area` set from block attributes, means an exposed
80
- // block variation was inserted. So add this prop to the template
81
- // part entity on creation. Afterwards remove `area` value from
82
- // block attributes.
83
- const record = {
84
- title,
85
- slug: (0, _lodash.kebabCase)(title),
86
- content: (0, _blocks.serialize)(startingBlocks),
87
- // `area` is filterable on the server and defaults to `UNCATEGORIZED`
88
- // if provided value is not allowed.
89
- area
90
- };
91
- const templatePart = await saveEntityRecord('postType', 'wp_template_part', record);
92
- setAttributes({
93
- slug: templatePart.slug,
94
- theme: templatePart.theme,
95
- area: undefined
96
- });
97
- }, [setAttributes, area]);
98
- return (0, _element.createElement)(_element.Fragment, null, step === PLACEHOLDER_STEPS.initial && (0, _element.createElement)(_components.Placeholder, {
99
- icon: areaIcon,
100
- label: areaLabel,
101
- instructions: enableSelection ? (0, _i18n.sprintf)( // Translators: %s as template part area title ("Header", "Footer", etc.).
102
- (0, _i18n.__)('Choose an existing %s or create a new one.'), areaLabel.toLowerCase()) : (0, _i18n.sprintf)( // Translators: %s as template part area title ("Header", "Footer", etc.).
103
- (0, _i18n.__)('Create a new %s.'), areaLabel.toLowerCase())
104
- }, !hasResolvedReplacements ? (0, _element.createElement)(_components.Spinner, null) : (0, _element.createElement)(_components.Dropdown, {
105
- contentClassName: "wp-block-template-part__placeholder-preview-dropdown-content",
106
- position: "bottom right left",
107
- renderToggle: _ref2 => {
108
- let {
109
- isOpen,
110
- onToggle
111
- } = _ref2;
112
- return (0, _element.createElement)(_element.Fragment, null, enableSelection && (0, _element.createElement)(_components.Button, {
113
- variant: "primary",
114
- onClick: onToggle,
115
- "aria-expanded": isOpen
116
- }, (0, _i18n.__)('Choose existing')), (0, _element.createElement)(_components.Button, {
117
- variant: enableSelection ? 'tertiary' : 'primary',
118
- onClick: () => setStep(PLACEHOLDER_STEPS.patterns)
119
- }, (0, _i18n.sprintf)( // Translators: %s as template part area title ("Header", "Footer", etc.).
120
- (0, _i18n.__)('New %s'), areaLabel.toLowerCase())));
121
- },
122
- renderContent: _ref3 => {
123
- let {
124
- onClose
125
- } = _ref3;
126
- return (0, _element.createElement)(_selection.default, {
127
- setAttributes: setAttributes,
128
- onClose: onClose,
129
- area: area
130
- });
131
- }
132
- })), step === PLACEHOLDER_STEPS.patterns && (0, _element.createElement)(_patternsSetup.default, {
133
- area: area,
134
- areaLabel: areaLabel,
135
- areaIcon: areaIcon,
136
- onCreate: onCreate,
137
- clientId: clientId,
138
- resetPlaceholder: () => setStep(PLACEHOLDER_STEPS.initial)
139
- }));
140
- }
141
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/block-library/src/template-part/edit/placeholder/index.js"],"names":["PLACEHOLDER_STEPS","initial","patterns","TemplatePartPlaceholder","area","clientId","setAttributes","enableSelection","hasResolvedReplacements","saveEntityRecord","coreStore","step","setStep","areaIcon","areaLabel","select","definedAreas","__experimentalGetDefaultTemplatePartAreas","selectedArea","defaultArea","icon","label","onCreate","startingBlocks","title","record","slug","content","templatePart","theme","undefined","toLowerCase","isOpen","onToggle","onClose"],"mappings":";;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAnBA;AACA;AACA;;AAGA;AACA;AACA;;AAQA;AACA;AACA;AAIA,MAAMA,iBAAiB,GAAG;AACzBC,EAAAA,OAAO,EAAE,CADgB;AAEzBC,EAAAA,QAAQ,EAAE;AAFe,CAA1B;;AAKe,SAASC,uBAAT,OAMX;AAAA,MAN6C;AAChDC,IAAAA,IADgD;AAEhDC,IAAAA,QAFgD;AAGhDC,IAAAA,aAHgD;AAIhDC,IAAAA,eAJgD;AAKhDC,IAAAA;AALgD,GAM7C;AACH,QAAM;AAAEC,IAAAA;AAAF,MAAuB,uBAAaC,eAAb,CAA7B;AACA,QAAM,CAAEC,IAAF,EAAQC,OAAR,IAAoB,uBAAUZ,iBAAiB,CAACC,OAA5B,CAA1B;AAEA,QAAM;AAAEY,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,MAA0B,qBAC7BC,MAAF,IAAc;AACb;AACA;AACA;AACA,UAAMC,YAAY,GAAGD,MAAM,CAC1B,aAD0B,CAAN,CAEnBE,yCAFmB,EAArB;;AAIA,UAAMC,YAAY,GAAG,kBAAMF,YAAN,EAAoB;AAAEZ,MAAAA;AAAF,KAApB,CAArB;AACA,UAAMe,WAAW,GAAG,kBAAMH,YAAN,EAAoB;AAAEZ,MAAAA,IAAI,EAAE;AAAR,KAApB,CAApB;AAEA,WAAO;AACNS,MAAAA,QAAQ,EAAE,CAAAK,YAAY,SAAZ,IAAAA,YAAY,WAAZ,YAAAA,YAAY,CAAEE,IAAd,MAAsBD,WAAtB,aAA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AGD,4BAAC,oBAAD;AACC,IAAA,gBAAgB,EAAC,8DADlB;AAEC,IAAA,QAAQ,EAAC,mBAFV;AAGC,IAAA,YAAY,EAAG;AAAA,UAAE;AAAEwB,QAAAA,MAAF;AAAUC,QAAAA;AAAV,OAAF;AAAA,aACd,qDACG1B,eAAe,IAChB,4BAAC,kBAAD;AACC,QAAA,OAAO,EAAC,SADT;AAEC,QAAA,OAAO,EAAG0B,QAFX;AAGC,yBAAgBD;AAHjB,SAKG,cAAI,iBAAJ,CALH,CAFF,EAUC,4BAAC,kBAAD;AACC,QAAA,OAAO,EACNzB,eAAe,GACZ,UADY,GAEZ,SAJL;AAMC,QAAA,OAAO,EAAG,MACTK,OAAO,CACNZ,iBAAiB,CAACE,QADZ;AAPT,SAYG,oBACD;AACA,oBAAI,QAAJ,CAFC,EAGDY,SAAS,CAACiB,WAAV,EAHC,CAZH,CAVD,CADc;AAAA,KAHhB;AAkCC,IAAA,aAAa,EAAG;AAAA,UAAE;AAAEG,QAAAA;AAAF,OAAF;AAAA,aACf,4BAAC,kBAAD;AACC,QAAA,aAAa,EAAG5B,aADjB;AAEC,QAAA,OAAO,EAAG4B,OAFX;AAGC,QAAA,IAAI,EAAG9B;AAHR,QADe;AAAA;AAlCjB,IAtBF,CAFF,EAqEGO,IAAI,KAAKX,iBAAiB,CAACE,QAA3B,IACD,4BAAC,sBAAD;AACC,IAAA,IAAI,EAAGE,IADR;AAEC,IAAA,SAAS,EAAGU,SAFb;AAGC,IAAA,QAAQ,EAAGD,QAHZ;AAIC,IAAA,QAAQ,EAAGS,QAJZ;AAKC,IAAA,QAAQ,EAAGjB,QALZ;AAMC,IAAA,gBAAgB,EAAG,MAClBO,OAAO,CAAEZ,iBAAiB,CAACC,OAApB;AAPT,IAtEF,CADD;AAoFA","sourcesContent":["/**\n * External dependencies\n */\nimport { find, kebabCase } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useCallback, useState } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { Placeholder, Dropdown, Button, Spinner } from '@wordpress/components';\nimport { serialize } from '@wordpress/blocks';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport TemplatePartSelection from '../selection';\nimport PatternsSetup from './patterns-setup';\n\nconst PLACEHOLDER_STEPS = {\n\tinitial: 1,\n\tpatterns: 2,\n};\n\nexport default function TemplatePartPlaceholder( {\n\tarea,\n\tclientId,\n\tsetAttributes,\n\tenableSelection,\n\thasResolvedReplacements,\n} ) {\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst [ step, setStep ] = useState( PLACEHOLDER_STEPS.initial );\n\n\tconst { areaIcon, areaLabel } = useSelect(\n\t\t( select ) => {\n\t\t\t// FIXME: @wordpress/block-library should not depend on @wordpress/editor.\n\t\t\t// Blocks can be loaded into a *non-post* block editor.\n\t\t\t// eslint-disable-next-line @wordpress/data-no-store-string-literals\n\t\t\tconst definedAreas = select(\n\t\t\t\t'core/editor'\n\t\t\t).__experimentalGetDefaultTemplatePartAreas();\n\n\t\t\tconst selectedArea = find( definedAreas, { area } );\n\t\t\tconst defaultArea = find( definedAreas, { area: 'uncategorized' } );\n\n\t\t\treturn {\n\t\t\t\tareaIcon: selectedArea?.icon || defaultArea?.icon,\n\t\t\t\tareaLabel: selectedArea?.label || __( 'Template Part' ),\n\t\t\t};\n\t\t},\n\t\t[ area ]\n\t);\n\n\tconst onCreate = useCallback(\n\t\tasync (\n\t\t\tstartingBlocks = [],\n\t\t\ttitle = __( 'Untitled Template Part' )\n\t\t) => {\n\t\t\t// If we have `area` set from block attributes, means an exposed\n\t\t\t// block variation was inserted. So add this prop to the template\n\t\t\t// part entity on creation. Afterwards remove `area` value from\n\t\t\t// block attributes.\n\t\t\tconst record = {\n\t\t\t\ttitle,\n\t\t\t\tslug: kebabCase( title ),\n\t\t\t\tcontent: serialize( startingBlocks ),\n\t\t\t\t// `area` is filterable on the server and defaults to `UNCATEGORIZED`\n\t\t\t\t// if provided value is not allowed.\n\t\t\t\tarea,\n\t\t\t};\n\t\t\tconst templatePart = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template_part',\n\t\t\t\trecord\n\t\t\t);\n\t\t\tsetAttributes( {\n\t\t\t\tslug: templatePart.slug,\n\t\t\t\ttheme: templatePart.theme,\n\t\t\t\tarea: undefined,\n\t\t\t} );\n\t\t},\n\t\t[ setAttributes, area ]\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t{ step === PLACEHOLDER_STEPS.initial && (\n\t\t\t\t<Placeholder\n\t\t\t\t\ticon={ areaIcon }\n\t\t\t\t\tlabel={ areaLabel }\n\t\t\t\t\tinstructions={\n\t\t\t\t\t\tenableSelection\n\t\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t\t// Translators: %s as template part area title (\"Header\", \"Footer\", etc.).\n\t\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t\t'Choose an existing %s or create a new one.'\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\tareaLabel.toLowerCase()\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t\t// Translators: %s as template part area title (\"Header\", \"Footer\", etc.).\n\t\t\t\t\t\t\t\t\t__( 'Create a new %s.' ),\n\t\t\t\t\t\t\t\t\tareaLabel.toLowerCase()\n\t\t\t\t\t\t\t )\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t{ ! hasResolvedReplacements ? (\n\t\t\t\t\t\t<Spinner />\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<Dropdown\n\t\t\t\t\t\t\tcontentClassName=\"wp-block-template-part__placeholder-preview-dropdown-content\"\n\t\t\t\t\t\t\tposition=\"bottom right left\"\n\t\t\t\t\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t{ enableSelection && (\n\t\t\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t\t\t\t\t\t\taria-expanded={ isOpen }\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ __( 'Choose existing' ) }\n\t\t\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t\tvariant={\n\t\t\t\t\t\t\t\t\t\t\tenableSelection\n\t\t\t\t\t\t\t\t\t\t\t\t? 'tertiary'\n\t\t\t\t\t\t\t\t\t\t\t\t: 'primary'\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\t\tsetStep(\n\t\t\t\t\t\t\t\t\t\t\t\tPLACEHOLDER_STEPS.patterns\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ sprintf(\n\t\t\t\t\t\t\t\t\t\t\t// Translators: %s as template part area title (\"Header\", \"Footer\", etc.).\n\t\t\t\t\t\t\t\t\t\t\t__( 'New %s' ),\n\t\t\t\t\t\t\t\t\t\t\tareaLabel.toLowerCase()\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t\t\t\t\t<TemplatePartSelection\n\t\t\t\t\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\t\t\t\t\tonClose={ onClose }\n\t\t\t\t\t\t\t\t\tarea={ area }\n\t\t\t\t\t\t\t\t/>\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</Placeholder>\n\t\t\t) }\n\t\t\t{ step === PLACEHOLDER_STEPS.patterns && (\n\t\t\t\t<PatternsSetup\n\t\t\t\t\tarea={ area }\n\t\t\t\t\tareaLabel={ areaLabel }\n\t\t\t\t\tareaIcon={ areaIcon }\n\t\t\t\t\tonCreate={ onCreate }\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\tresetPlaceholder={ () =>\n\t\t\t\t\t\tsetStep( PLACEHOLDER_STEPS.initial )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"]}
@@ -1,100 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = PatternsSetup;
7
-
8
- var _element = require("@wordpress/element");
9
-
10
- var _blockEditor = require("@wordpress/block-editor");
11
-
12
- var _i18n = require("@wordpress/i18n");
13
-
14
- var _components = require("@wordpress/components");
15
-
16
- /**
17
- * WordPress dependencies
18
- */
19
- function PatternsSetup(_ref) {
20
- let {
21
- area,
22
- areaLabel,
23
- areaIcon,
24
- clientId,
25
- onCreate,
26
- resetPlaceholder
27
- } = _ref;
28
- const blockNameWithArea = area ? `core/template-part/${area}` : 'core/template-part'; // Restructure onCreate to set the blocks on local state.
29
- // Add modal to confirm title and trigger onCreate.
30
-
31
- const [title, setTitle] = (0, _element.useState)((0, _i18n.__)('Untitled Template Part'));
32
- const [startingBlocks, setStartingBlocks] = (0, _element.useState)([]);
33
- const [isTitleStep, setIsTitleStep] = (0, _element.useState)(false);
34
-
35
- const selectPattern = selectedPattern => {
36
- setStartingBlocks(selectedPattern);
37
- setIsTitleStep(true);
38
- };
39
-
40
- const submitForCreation = event => {
41
- event.preventDefault();
42
- onCreate(startingBlocks, title);
43
- };
44
-
45
- return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_blockEditor.__experimentalBlockPatternSetup, {
46
- clientId: clientId,
47
- startBlankComponent: (0, _element.createElement)(StartBlankComponent, {
48
- setTitleStep: setIsTitleStep,
49
- areaLabel: areaLabel,
50
- areaIcon: areaIcon
51
- }),
52
- onBlockPatternSelect: selectPattern,
53
- filterPatternsFn: pattern => {
54
- var _pattern$blockTypes, _pattern$blockTypes$s;
55
-
56
- return pattern === null || pattern === void 0 ? void 0 : (_pattern$blockTypes = pattern.blockTypes) === null || _pattern$blockTypes === void 0 ? void 0 : (_pattern$blockTypes$s = _pattern$blockTypes.some) === null || _pattern$blockTypes$s === void 0 ? void 0 : _pattern$blockTypes$s.call(_pattern$blockTypes, blockType => blockType === blockNameWithArea);
57
- }
58
- }), isTitleStep && (0, _element.createElement)(_components.Modal, {
59
- title: (0, _i18n.sprintf)( // Translators: %s as template part area title ("Header", "Footer", etc.).
60
- (0, _i18n.__)('Name and create your new %s'), areaLabel.toLowerCase()),
61
- closeLabel: (0, _i18n.__)('Cancel'),
62
- onRequestClose: resetPlaceholder,
63
- overlayClassName: "wp-block-template-part__placeholder-create-new__title-form"
64
- }, (0, _element.createElement)("form", {
65
- onSubmit: submitForCreation
66
- }, (0, _element.createElement)(_components.TextControl, {
67
- label: (0, _i18n.__)('Name'),
68
- value: title,
69
- onChange: setTitle
70
- }), (0, _element.createElement)(_components.Flex, {
71
- className: "wp-block-template-part__placeholder-create-new__title-form-actions",
72
- justify: "flex-end"
73
- }, (0, _element.createElement)(_components.FlexItem, null, (0, _element.createElement)(_components.Button, {
74
- variant: "secondary",
75
- onClick: resetPlaceholder
76
- }, (0, _i18n.__)('Cancel'))), (0, _element.createElement)(_components.FlexItem, null, (0, _element.createElement)(_components.Button, {
77
- variant: "primary",
78
- type: "submit",
79
- disabled: !title.length,
80
- "aria-disabled": !title.length
81
- }, (0, _i18n.__)('Create')))))));
82
- }
83
-
84
- function StartBlankComponent(_ref2) {
85
- let {
86
- setTitleStep,
87
- areaLabel,
88
- areaIcon
89
- } = _ref2;
90
- (0, _element.useEffect)(() => {
91
- setTitleStep(true);
92
- }, []);
93
- return (0, _element.createElement)(_components.Placeholder, {
94
- label: areaLabel,
95
- icon: areaIcon,
96
- instructions: (0, _i18n.sprintf)( // Translators: %s as template part area title ("Header", "Footer", "Template Part", etc.).
97
- (0, _i18n.__)('Creating your new %s…'), areaLabel.toLowerCase())
98
- });
99
- }
100
- //# sourceMappingURL=patterns-setup.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/block-library/src/template-part/edit/placeholder/patterns-setup.js"],"names":["PatternsSetup","area","areaLabel","areaIcon","clientId","onCreate","resetPlaceholder","blockNameWithArea","title","setTitle","startingBlocks","setStartingBlocks","isTitleStep","setIsTitleStep","selectPattern","selectedPattern","submitForCreation","event","preventDefault","pattern","blockTypes","some","blockType","toLowerCase","length","StartBlankComponent","setTitleStep"],"mappings":";;;;;;;AAIA;;AADA;;AAEA;;AACA;;AANA;AACA;AACA;AAae,SAASA,aAAT,OAOX;AAAA,MAPmC;AACtCC,IAAAA,IADsC;AAEtCC,IAAAA,SAFsC;AAGtCC,IAAAA,QAHsC;AAItCC,IAAAA,QAJsC;AAKtCC,IAAAA,QALsC;AAMtCC,IAAAA;AANsC,GAOnC;AACH,QAAMC,iBAAiB,GAAGN,IAAI,GAC1B,sBAAsBA,IAAM,EADF,GAE3B,oBAFH,CADG,CAKH;AACA;;AACA,QAAM,CAAEO,KAAF,EAASC,QAAT,IAAsB,uBAAU,cAAI,wBAAJ,CAAV,CAA5B;AACA,QAAM,CAAEC,cAAF,EAAkBC,iBAAlB,IAAwC,uBAAU,EAAV,CAA9C;AACA,QAAM,CAAEC,WAAF,EAAeC,cAAf,IAAkC,uBAAU,KAAV,CAAxC;;AAEA,QAAMC,aAAa,GAAKC,eAAF,IAAuB;AAC5CJ,IAAAA,iBAAiB,CAAEI,eAAF,CAAjB;AACAF,IAAAA,cAAc,CAAE,IAAF,CAAd;AACA,GAHD;;AAKA,QAAMG,iBAAiB,GAAKC,KAAF,IAAa;AACtCA,IAAAA,KAAK,CAACC,cAAN;AACAb,IA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AG,CAAEE,KAAK,CAACgB,MAHpB;AAIC,qBAAgB,CAAEhB,KAAK,CAACgB;AAJzB,KAMG,cAAI,QAAJ,CANH,CADD,CAZD,CAND,CAVD,CAlBF,CADD;AA+DA;;AAED,SAASC,mBAAT,QAAsE;AAAA,MAAxC;AAAEC,IAAAA,YAAF;AAAgBxB,IAAAA,SAAhB;AAA2BC,IAAAA;AAA3B,GAAwC;AACrE,0BAAW,MAAM;AAChBuB,IAAAA,YAAY,CAAE,IAAF,CAAZ;AACA,GAFD,EAEG,EAFH;AAGA,SACC,4BAAC,uBAAD;AACC,IAAA,KAAK,EAAGxB,SADT;AAEC,IAAA,IAAI,EAAGC,QAFR;AAGC,IAAA,YAAY,EAAG,oBACd;AACA,kBAAI,uBAAJ,CAFc,EAGdD,SAAS,CAACqB,WAAV,EAHc;AAHhB,IADD;AAWA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __experimentalBlockPatternSetup as BlockPatternSetup } from '@wordpress/block-editor';\nimport { useEffect, useState } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tTextControl,\n\tFlex,\n\tFlexItem,\n\tButton,\n\tModal,\n\tPlaceholder,\n} from '@wordpress/components';\n\nexport default function PatternsSetup( {\n\tarea,\n\tareaLabel,\n\tareaIcon,\n\tclientId,\n\tonCreate,\n\tresetPlaceholder,\n} ) {\n\tconst blockNameWithArea = area\n\t\t? `core/template-part/${ area }`\n\t\t: 'core/template-part';\n\n\t// Restructure onCreate to set the blocks on local state.\n\t// Add modal to confirm title and trigger onCreate.\n\tconst [ title, setTitle ] = useState( __( 'Untitled Template Part' ) );\n\tconst [ startingBlocks, setStartingBlocks ] = useState( [] );\n\tconst [ isTitleStep, setIsTitleStep ] = useState( false );\n\n\tconst selectPattern = ( selectedPattern ) => {\n\t\tsetStartingBlocks( selectedPattern );\n\t\tsetIsTitleStep( true );\n\t};\n\n\tconst submitForCreation = ( event ) => {\n\t\tevent.preventDefault();\n\t\tonCreate( startingBlocks, title );\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t<BlockPatternSetup\n\t\t\t\tclientId={ clientId }\n\t\t\t\tstartBlankComponent={\n\t\t\t\t\t<StartBlankComponent\n\t\t\t\t\t\tsetTitleStep={ setIsTitleStep }\n\t\t\t\t\t\tareaLabel={ areaLabel }\n\t\t\t\t\t\tareaIcon={ areaIcon }\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t\tonBlockPatternSelect={ selectPattern }\n\t\t\t\tfilterPatternsFn={ ( pattern ) =>\n\t\t\t\t\tpattern?.blockTypes?.some?.(\n\t\t\t\t\t\t( blockType ) => blockType === blockNameWithArea\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t/>\n\t\t\t{ isTitleStep && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ sprintf(\n\t\t\t\t\t\t// Translators: %s as template part area title (\"Header\", \"Footer\", etc.).\n\t\t\t\t\t\t__( 'Name and create your new %s' ),\n\t\t\t\t\t\tareaLabel.toLowerCase()\n\t\t\t\t\t) }\n\t\t\t\t\tcloseLabel={ __( 'Cancel' ) }\n\t\t\t\t\tonRequestClose={ resetPlaceholder }\n\t\t\t\t\toverlayClassName=\"wp-block-template-part__placeholder-create-new__title-form\"\n\t\t\t\t>\n\t\t\t\t\t<form onSubmit={ submitForCreation }>\n\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<Flex\n\t\t\t\t\t\t\tclassName=\"wp-block-template-part__placeholder-create-new__title-form-actions\"\n\t\t\t\t\t\t\tjustify=\"flex-end\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\t\t\t\tonClick={ resetPlaceholder }\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\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\t\t\tdisabled={ ! title.length }\n\t\t\t\t\t\t\t\t\taria-disabled={ ! title.length }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Create' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t</Flex>\n\t\t\t\t\t</form>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction StartBlankComponent( { setTitleStep, areaLabel, areaIcon } ) {\n\tuseEffect( () => {\n\t\tsetTitleStep( true );\n\t}, [] );\n\treturn (\n\t\t<Placeholder\n\t\t\tlabel={ areaLabel }\n\t\t\ticon={ areaIcon }\n\t\t\tinstructions={ sprintf(\n\t\t\t\t// Translators: %s as template part area title (\"Header\", \"Footer\", \"Template Part\", etc.).\n\t\t\t\t__( 'Creating your new %s…' ),\n\t\t\t\tareaLabel.toLowerCase()\n\t\t\t) }\n\t\t/>\n\t);\n}\n"]}
@@ -1,45 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = TemplatePartSelection;
9
-
10
- var _element = require("@wordpress/element");
11
-
12
- var _components = require("@wordpress/components");
13
-
14
- var _templatePartPreviews = _interopRequireDefault(require("./template-part-previews"));
15
-
16
- /**
17
- * WordPress dependencies
18
- */
19
-
20
- /**
21
- * Internal dependencies
22
- */
23
- function TemplatePartSelection(_ref) {
24
- let {
25
- setAttributes,
26
- onClose,
27
- area,
28
- templatePartId = null
29
- } = _ref;
30
- const [filterValue, setFilterValue] = (0, _element.useState)('');
31
- return (0, _element.createElement)("div", null, (0, _element.createElement)(_components.SearchControl, {
32
- value: filterValue,
33
- onChange: setFilterValue,
34
- className: "wp-block-template-part__selection-preview-search-form"
35
- }), (0, _element.createElement)("div", {
36
- className: "wp-block-template-part__selection-preview-container"
37
- }, (0, _element.createElement)(_templatePartPreviews.default, {
38
- setAttributes: setAttributes,
39
- filterValue: filterValue,
40
- onClose: onClose,
41
- area: area,
42
- templatePartId: templatePartId
43
- })));
44
- }
45
- //# sourceMappingURL=index.js.map