@@ -42,6 +42,7 @@ The preloading system consists of several interconnected components:
4242The ` EditorService ` actor coordinates fetching all editor dependencies concurrently:
4343
4444** Swift**
45+
4546``` swift
4647let service = EditorService (configuration : config)
4748let dependencies = try await service.prepare { progress in
@@ -50,40 +51,43 @@ let dependencies = try await service.prepare { progress in
5051```
5152
5253** Kotlin**
54+
5355``` kotlin
5456// TBD
5557```
5658
5759The ` prepare ` method fetches these resources in parallel:
58- - Editor settings (theme styles, block settings)
59- - Asset bundles (JavaScript and CSS files)
60- - Preload list (API responses for editor initialization)
60+
61+ - Editor settings (theme styles, block settings)
62+ - Asset bundles (JavaScript and CSS files)
63+ - Preload list (API responses for editor initialization)
6164
6265### EditorPreloadList
6366
6467The ` EditorPreloadList ` struct contains pre-fetched API responses that are serialized to JSON and injected into the editor's JavaScript runtime:
6568
66- | Property | API Endpoint | Description |
67- | ----------| --------------| -------------|
68- | ` postData ` | ` /wp/v2/posts/{id}?context=edit ` | The post being edited (existing posts only) |
69- | ` postTypeData ` | ` /wp/v2/types/{type}?context=edit ` | Schema for the current post type |
70- | ` postTypesData ` | ` /wp/v2/types?context=view ` | All available post types |
71- | ` activeThemeData ` | ` /wp/v2/themes?context=edit&status=active ` | Active theme information |
72- | ` settingsOptionsData ` | ` OPTIONS /wp/v2/settings ` | Site settings schema |
69+ | Property | API Endpoint | Description |
70+ | --------------------- | ------------------------------------------ | ------------------------------------------- |
71+ | ` postData ` | ` /wp/v2/posts/{id}?context=edit ` | The post being edited (existing posts only) |
72+ | ` postTypeData ` | ` /wp/v2/types/{type}?context=edit ` | Schema for the current post type |
73+ | ` postTypesData ` | ` /wp/v2/types?context=view ` | All available post types |
74+ | ` activeThemeData ` | ` /wp/v2/themes?context=edit&status=active ` | Active theme information |
75+ | ` settingsOptionsData ` | ` OPTIONS /wp/v2/settings ` | Site settings schema |
7376
7477### EditorURLCache
7578
7679The ` EditorURLCache ` provides disk-based caching for API responses, keyed by URL and HTTP method. It supports three cache policies via ` EditorCachePolicy ` :
7780
78- | Policy | Behavior |
79- | --------| ----------|
80- | ` .ignore ` | Never use cached responses (force fresh data) |
81+ | Policy | Behavior |
82+ | ----------------------- | --------------------------------------------------- |
83+ | ` .ignore ` | Never use cached responses (force fresh data) |
8184| ` .maxAge(TimeInterval) ` | Use cached responses younger than the specified age |
82- | ` .always ` | Always use cached responses regardless of age |
85+ | ` .always ` | Always use cached responses regardless of age |
8386
8487Example:
8588
8689** Swift**
90+
8791``` swift
8892// Cache responses for up to 1 hour
8993let service = EditorService (
@@ -93,6 +97,7 @@ let service = EditorService(
9397```
9498
9599** Kotlin**
100+
96101``` kotlin
97102// TBD
98103```
@@ -158,12 +163,16 @@ The `GBKitGlobal` struct packages all configuration and preload data, then injec
158163
159164``` javascript
160165window .GBKit = {
161- siteURL: " https://example.com" ,
162- siteApiRoot: " https://example.com/wp-json" ,
163- authHeader: " Bearer ..." ,
164- preloadData: { /* serialized EditorPreloadList */ },
165- editorSettings: { /* theme styles, colors, etc. */ },
166- // ... other configuration
166+ siteURL: ' https://example.com' ,
167+ siteApiRoot: ' https://example.com/wp-json' ,
168+ authHeader: ' Bearer ...' ,
169+ preloadData: {
170+ /* serialized EditorPreloadList */
171+ },
172+ editorSettings: {
173+ /* theme styles, colors, etc. */
174+ },
175+ // ... other configuration
167176};
168177```
169178
@@ -174,11 +183,11 @@ The `@wordpress/api-fetch` package includes a preloading middleware that interce
174183``` javascript
175184// In src/utils/api-fetch.js
176185export function configureApiFetch () {
177- const { preloadData } = getGBKit ();
186+ const { preloadData } = getGBKit ();
178187
179- apiFetch .use (
180- apiFetch .createPreloadingMiddleware (preloadData ?? defaultPreloadData)
181- );
188+ apiFetch .use (
189+ apiFetch .createPreloadingMiddleware ( preloadData ?? defaultPreloadData )
190+ );
182191}
183192` ` `
184193
@@ -193,8 +202,8 @@ When Gutenberg makes an API request:
193202
194203Only certain headers are preserved in preload responses to match WordPress core's behavior:
195204
196- - ` Accept` - Content type negotiation
197- - ` Link` - REST API discovery and pagination
205+ - ` Accept` - Content type negotiation
206+ - ` Link` - REST API discovery and pagination
198207
199208This filtering is performed by ` EditorURLResponse .asPreloadResponse ()` .
200209
@@ -205,20 +214,23 @@ This filtering is performed by `EditorURLResponse.asPreloadResponse()`.
205214` EditorService` automatically cleans up old asset bundles once per day:
206215
207216**Swift**
217+
208218` ` ` swift
209219try await onceEvery (.seconds (86_400 )) {
210220 try await self .cleanup ()
211221}
212222` ` `
213223
214224**Kotlin**
225+
215226` ` ` kotlin
216227// tbd
217228` ` `
218229
219230### Manual Cache Control
220231
221232**Swift**
233+
222234` ` ` swift
223235// Clear unused resources (keeps most recent)
224236try await service .cleanup ()
@@ -228,6 +240,7 @@ try await service.purge()
228240` ` `
229241
230242**Kotlin**
243+
231244` ` ` kotlin
232245// tbd
233246` ` `
@@ -261,11 +274,11 @@ that contain everything the editor needs, the progress bar will never be display
261274
262275` EditorDependencies` contains all pre-fetched resources needed to initialize the editor instantly.
263276
264- | Property | Type | Description |
265- |----------| ------| -------------|
266- | ` editorSettings` | ` EditorSettings` | Theme styles, colors, typography, block settings |
267- | ` assetBundle` | ` EditorAssetBundle` | Cached JavaScript/CSS for plugins/themes |
268- | ` preloadList` | ` EditorPreloadList? ` | Pre-fetched API responses |
277+ | Property | Type | Description |
278+ | ---------------- | -------------------- | ------------------------------------------------ |
279+ | ` editorSettings` | ` EditorSettings` | Theme styles, colors, typography, block settings |
280+ | ` assetBundle` | ` EditorAssetBundle` | Cached JavaScript/CSS for plugins/themes |
281+ | ` preloadList` | ` EditorPreloadList? ` | Pre-fetched API responses |
269282
270283### Obtaining Dependencies
271284
@@ -326,3 +339,4 @@ class PostListViewController: UIViewController {
326339 navigationController? .pushViewController (editor, animated: true )
327340 }
328341}
342+ ` ` `
0 commit comments