@@ -14,4 +14,244 @@ npm install @wordpress/block-directory --save
14
14
15
15
_ This package assumes that your code will run in an ** ES2015+** environment. If you're using an environment that has limited or no support for ES2015+ such as lower versions of IE then using [ core-js] ( https://github.com/zloirock/core-js ) or [ @babel/polyfill ] ( https://babeljs.io/docs/en/next/babel-polyfill ) will add support for these methods. Learn more about it in [ Babel docs] ( https://babeljs.io/docs/en/next/caveats ) ._
16
16
17
+ ## Usage
18
+
19
+ This package builds a standalone JS file. When loaded on a page with the block editor, it extends the block inserter to search for blocks from WordPress.org.
20
+
21
+ To do this, it uses the ` __experimentalInserterMenuExtension ` , a slot-fill area hooked into the block types list. When the user runs a search and there are no results currently installed, it fires off a request to WordPress.org for matching blocks. These are listed for the user to install with a one-click process that [ installs, activates, and injects the block into the post.] ( ./src/store/actions.js#L49 ) When the post is saved, if the block was not used, it will be [ silently uninstalled] ( ./src/store/actions.js#L129 ) to avoid clutter.
22
+
23
+ See also the API endpoints for searching WordPress.org: ` /wp/v2/block-directory/search ` , and installing & activating plugins: ` /wp/v2/plugins/ ` .
24
+
25
+ ## Actions
26
+
27
+ The following set of dispatching action creators are available on the object returned by ` wp.data.dispatch( 'core/block-directory' ) ` :
28
+
29
+ <!-- START TOKEN(Autogenerated actions|src/store/actions.js) -->
30
+
31
+ <a name =" addInstalledBlockType " href =" #addInstalledBlockType " >#</a > ** addInstalledBlockType**
32
+
33
+ Returns an action object used to add a block type to the "newly installed"
34
+ tracking list.
35
+
36
+ _ Parameters_
37
+
38
+ - _ item_ ` Object ` : The block item with the block id and name.
39
+
40
+ _ Returns_
41
+
42
+ - ` Object ` : Action object.
43
+
44
+ <a name =" clearErrorNotice " href =" #clearErrorNotice " >#</a > ** clearErrorNotice**
45
+
46
+ Sets the error notice to empty for specific block.
47
+
48
+ _ Parameters_
49
+
50
+ - _ blockId_ ` string ` : The ID of the block plugin. eg: my-block
51
+
52
+ _ Returns_
53
+
54
+ - ` Object ` : Action object.
55
+
56
+ <a name =" fetchDownloadableBlocks " href =" #fetchDownloadableBlocks " >#</a > ** fetchDownloadableBlocks**
57
+
58
+ Returns an action object used in signalling that the downloadable blocks
59
+ have been requested and are loading.
60
+
61
+ _ Parameters_
62
+
63
+ - _ filterValue_ ` string ` : Search string.
64
+
65
+ _ Returns_
66
+
67
+ - ` Object ` : Action object.
68
+
69
+ <a name =" installBlockType " href =" #installBlockType " >#</a > ** installBlockType**
70
+
71
+ Action triggered to install a block plugin.
72
+
73
+ _ Parameters_
74
+
75
+ - _ block_ ` Object ` : The block item returned by search.
76
+
77
+ _ Returns_
78
+
79
+ - ` boolean ` : Whether the block was successfully installed & loaded.
80
+
81
+ <a name =" receiveDownloadableBlocks " href =" #receiveDownloadableBlocks " >#</a > ** receiveDownloadableBlocks**
82
+
83
+ Returns an action object used in signalling that the downloadable blocks
84
+ have been updated.
85
+
86
+ _ Parameters_
87
+
88
+ - _ downloadableBlocks_ ` Array ` : Downloadable blocks.
89
+ - _ filterValue_ ` string ` : Search string.
90
+
91
+ _ Returns_
92
+
93
+ - ` Object ` : Action object.
94
+
95
+ <a name =" removeInstalledBlockType " href =" #removeInstalledBlockType " >#</a > ** removeInstalledBlockType**
96
+
97
+ Returns an action object used to remove a block type from the "newly installed"
98
+ tracking list.
99
+
100
+ _ Parameters_
101
+
102
+ - _ item_ ` string ` : The block item with the block id and name.
103
+
104
+ _ Returns_
105
+
106
+ - ` Object ` : Action object.
107
+
108
+ <a name =" setErrorNotice " href =" #setErrorNotice " >#</a > ** setErrorNotice**
109
+
110
+ Sets an error notice to be displayed to the user for a given block.
111
+
112
+ _ Parameters_
113
+
114
+ - _ blockId_ ` string ` : The ID of the block plugin. eg: my-block
115
+ - _ message_ ` string ` : The message shown in the notice.
116
+ - _ isFatal_ ` boolean ` : Whether the user can recover from the error.
117
+
118
+ _ Returns_
119
+
120
+ - ` Object ` : Action object.
121
+
122
+ <a name =" setIsInstalling " href =" #setIsInstalling " >#</a > ** setIsInstalling**
123
+
124
+ Returns an action object used to indicate install in progress.
125
+
126
+ _ Parameters_
127
+
128
+ - _ blockId_ ` string ` :
129
+ - _ isInstalling_ ` boolean ` :
130
+
131
+ _ Returns_
132
+
133
+ - ` Object ` : Action object.
134
+
135
+ <a name =" uninstallBlockType " href =" #uninstallBlockType " >#</a > ** uninstallBlockType**
136
+
137
+ Action triggered to uninstall a block plugin.
138
+
139
+ _ Parameters_
140
+
141
+ - _ block_ ` Object ` : The blockType object.
142
+
143
+ <!-- END TOKEN(Autogenerated actions|src/store/actions.js) -->
144
+
145
+ ## Selectors
146
+
147
+ The following selectors are available on the object returned by ` wp.data.select( 'core/block-directory' ) ` :
148
+
149
+ <!-- START TOKEN(Autogenerated selectors|src/store/selectors.js) -->
150
+
151
+ <a name =" getDownloadableBlocks " href =" #getDownloadableBlocks " >#</a > ** getDownloadableBlocks**
152
+
153
+ Returns the available uninstalled blocks.
154
+
155
+ _ Parameters_
156
+
157
+ - _ state_ ` Object ` : Global application state.
158
+ - _ filterValue_ ` string ` : Search string.
159
+
160
+ _ Returns_
161
+
162
+ - ` Array ` : Downloadable blocks.
163
+
164
+ <a name =" getErrorNoticeForBlock " href =" #getErrorNoticeForBlock " >#</a > ** getErrorNoticeForBlock**
165
+
166
+ Returns the error notice for a given block.
167
+
168
+ _ Parameters_
169
+
170
+ - _ state_ ` Object ` : Global application state.
171
+ - _ blockId_ ` string ` : The ID of the block plugin. eg: my-block
172
+
173
+ _ Returns_
174
+
175
+ - ` (string|boolean) ` : The error text, or false if no error.
176
+
177
+ <a name =" getErrorNotices " href =" #getErrorNotices " >#</a > ** getErrorNotices**
178
+
179
+ Returns all block error notices.
180
+
181
+ _ Parameters_
182
+
183
+ - _ state_ ` Object ` : Global application state.
184
+
185
+ _ Returns_
186
+
187
+ - ` Object ` : Object with error notices.
188
+
189
+ <a name =" getInstalledBlockTypes " href =" #getInstalledBlockTypes " >#</a > ** getInstalledBlockTypes**
190
+
191
+ Returns the block types that have been installed on the server in this
192
+ session.
193
+
194
+ _ Parameters_
195
+
196
+ - _ state_ ` Object ` : Global application state.
197
+
198
+ _ Returns_
199
+
200
+ - ` Array ` : Block type items
201
+
202
+ <a name =" getNewBlockTypes " href =" #getNewBlockTypes " >#</a > ** getNewBlockTypes**
203
+
204
+ Returns block types that have been installed on the server and used in the
205
+ current post.
206
+
207
+ _ Parameters_
208
+
209
+ - _ state_ ` Object ` : Global application state.
210
+
211
+ _ Returns_
212
+
213
+ - ` Array ` : Block type items.
214
+
215
+ <a name =" getUnusedBlockTypes " href =" #getUnusedBlockTypes " >#</a > ** getUnusedBlockTypes**
216
+
217
+ Returns the block types that have been installed on the server but are not
218
+ used in the current post.
219
+
220
+ _ Parameters_
221
+
222
+ - _ state_ ` Object ` : Global application state.
223
+
224
+ _ Returns_
225
+
226
+ - ` Array ` : Block type items.
227
+
228
+ <a name =" isInstalling " href =" #isInstalling " >#</a > ** isInstalling**
229
+
230
+ Returns true if a block plugin install is in progress.
231
+
232
+ _ Parameters_
233
+
234
+ - _ state_ ` Object ` : Global application state.
235
+ - _ blockId_ ` string ` : Id of the block.
236
+
237
+ _ Returns_
238
+
239
+ - ` boolean ` : Whether this block is currently being installed.
240
+
241
+ <a name =" isRequestingDownloadableBlocks " href =" #isRequestingDownloadableBlocks " >#</a > ** isRequestingDownloadableBlocks**
242
+
243
+ Returns true if application is requesting for downloadable blocks.
244
+
245
+ _ Parameters_
246
+
247
+ - _ state_ ` Object ` : Global application state.
248
+ - _ filterValue_ ` string ` : Search string.
249
+
250
+ _ Returns_
251
+
252
+ - ` boolean ` : Whether a request is in progress for the blocks list.
253
+
254
+
255
+ <!-- END TOKEN(Autogenerated selectors|src/store/selectors.js) -->
256
+
17
257
<br /><br /><p align =" center " ><img src =" https://s.w.org/style/images/codeispoetry.png?1 " alt =" Code is Poetry. " /></p >
0 commit comments