@digital-gravy/etch-public-api 0.3.2 → 0.3.3
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.
- package/README.md +82 -5
- package/dist/index.d.cts +126 -22
- package/dist/index.d.ts +126 -22
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -55,22 +55,68 @@ async function whenEtchReady(timeoutMs = 10_000) {
|
|
|
55
55
|
const etch = await whenEtchReady();
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
-
### Reading and mutating
|
|
58
|
+
### Reading and mutating blocks
|
|
59
59
|
|
|
60
60
|
```ts
|
|
61
61
|
// Read
|
|
62
|
-
const textIds = etch.blocks.find({ type: "text" });
|
|
62
|
+
const textIds = etch.blocks.find({ type: "etch/text" });
|
|
63
63
|
const json = etch.blocks.getJson(textIds[0]);
|
|
64
64
|
|
|
65
65
|
// Mutate (routes through the same guarded paths as the UI; undo/redo works)
|
|
66
66
|
etch.blocks.setText(textIds[0], "Hello world");
|
|
67
67
|
etch.blocks.addClass(textIds[0], "lead");
|
|
68
68
|
|
|
69
|
+
// Persist (blocks/styles wait for save; stylesheets/components/fields persist immediately)
|
|
70
|
+
await etch.saveAsync();
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Styles
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
// Create a class or id rule
|
|
69
77
|
const styleId = etch.styles.create(".lead", "font-size: 1.25rem;");
|
|
78
|
+
|
|
79
|
+
// Find existing styles by selector type
|
|
80
|
+
const classStyles = etch.styles.list({ type: "class" });
|
|
81
|
+
const myStyle = etch.styles.list().find((s) => s.selector === ".lead");
|
|
82
|
+
console.log(myStyle?.id); // the id you pass to blocks.addClass etc.
|
|
83
|
+
|
|
84
|
+
// Global CSS custom properties
|
|
70
85
|
etch.styles.setVariable("--brand", "#0af");
|
|
86
|
+
etch.styles.getVariable("--brand"); // "#0af"
|
|
87
|
+
```
|
|
71
88
|
|
|
72
|
-
|
|
89
|
+
> **Note:** The `collection` field on style objects is an internal implementation
|
|
90
|
+
> detail. Always omit the `collection` argument — the default collection is the
|
|
91
|
+
> only one supported via the public API.
|
|
92
|
+
|
|
93
|
+
### Component edit mode
|
|
94
|
+
|
|
95
|
+
Use `blocks.enterComponentEditMode` to open a component's internal block tree
|
|
96
|
+
for direct inspection or mutation, then save and exit when done:
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
// Find a component block
|
|
100
|
+
const [compId] = etch.blocks.find({ type: "etch/component" });
|
|
101
|
+
|
|
102
|
+
// Enter edit mode — the component's block tree becomes accessible
|
|
103
|
+
etch.blocks.enterComponentEditMode(compId);
|
|
104
|
+
|
|
105
|
+
// Inspect or mutate the component's children
|
|
106
|
+
const tree = etch.blocks.getTree();
|
|
107
|
+
|
|
108
|
+
// Persist the component definition to the backend
|
|
109
|
+
await etch.blocks.saveComponentEditModeAsync();
|
|
110
|
+
|
|
111
|
+
// Save the page, then exit edit mode
|
|
73
112
|
await etch.saveAsync();
|
|
113
|
+
etch.blocks.exitComponentEditMode();
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
To discard in-memory changes and restore the original block:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
etch.blocks.exitComponentEditMode({ revert: true });
|
|
74
120
|
```
|
|
75
121
|
|
|
76
122
|
### Error handling
|
|
@@ -142,10 +188,33 @@ etch.blocks.create({
|
|
|
142
188
|
version: 1,
|
|
143
189
|
context: {},
|
|
144
190
|
children: [],
|
|
145
|
-
tag: "div",
|
|
191
|
+
tag: "div", // ✗ type error
|
|
146
192
|
});
|
|
147
193
|
```
|
|
148
194
|
|
|
195
|
+
### Special element attributes
|
|
196
|
+
|
|
197
|
+
Some block types recognise **special attributes** in addition to standard HTML:
|
|
198
|
+
|
|
199
|
+
**`etch/dynamic-image`** — rendered as `<img>`:
|
|
200
|
+
- `mediaId` — WordPress attachment ID. Etch fetches the media object and uses its URL as `src`, overriding any explicit `src`. Supports dynamic expressions (e.g. `{post.featured_image_id}`).
|
|
201
|
+
- `useSrcSet` — `"true"` to generate a responsive `srcset` from the media (requires `mediaId`).
|
|
202
|
+
- `maximumSize` — WordPress image size slug (e.g. `"large"`, `"full"`) used when resolving the image. Defaults to `"full"`.
|
|
203
|
+
|
|
204
|
+
```ts
|
|
205
|
+
etch.blocks.setAttribute(imgBlockId, "mediaId", "{post.featured_image_id}");
|
|
206
|
+
etch.blocks.setAttribute(imgBlockId, "useSrcSet", "true");
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
**`etch/svg`** — inline SVG:
|
|
210
|
+
- `src` — URL of an external `.svg` file. Etch fetches and inlines the SVG at render time. Supports dynamic expressions.
|
|
211
|
+
- `stripColors` — `"true"` to strip `fill` and `stroke` colour declarations from the fetched SVG, so CSS can drive its colours instead.
|
|
212
|
+
|
|
213
|
+
```ts
|
|
214
|
+
etch.blocks.setAttribute(svgBlockId, "src", "/icons/logo.svg");
|
|
215
|
+
etch.blocks.setAttribute(svgBlockId, "stripColors", "true");
|
|
216
|
+
```
|
|
217
|
+
|
|
149
218
|
### Types only
|
|
150
219
|
|
|
151
220
|
Every contract type is exported and dependency-free, so you can use them
|
|
@@ -167,7 +236,15 @@ is imported.
|
|
|
167
236
|
- `getEtch(options?)` / `isEtchAvailable()` — acquire the API from the page.
|
|
168
237
|
- `EtchApiError` / `isEtchApiError()` / `EtchApiErrorCode` — typed errors.
|
|
169
238
|
- `ETCH_API_VERSION` — the contract version this package targets (`0.x`).
|
|
170
|
-
- The full contract as exported types
|
|
239
|
+
- The full contract as exported types:
|
|
240
|
+
- **Blocks** — `Etch`, `EtchBlocksApi`, `EtchBlockJson`, `PublicBlockJson`, `FindBlocksPredicate`, `BlockPatch`, …
|
|
241
|
+
- **Styles** — `EtchStylesApi`, `StyleSummary`, `StyleListFilter`, `StyleSelectorType`, `StylePatch`
|
|
242
|
+
- **Stylesheets** — `EtchStylesheetsApi`, `StylesheetSummary`, `StylesheetInput`, `StylesheetPatch`
|
|
243
|
+
- **Components** — `EtchComponentsApi`, `PublicComponentSummary`, `PublicComponentJson`, `ComponentPatch`, `ComponentProperty`, …
|
|
244
|
+
- **Loops** — `EtchLoopsApi`, `EtchLoop`, `EtchLoopConfig`, `BlockLoopBinding`, …
|
|
245
|
+
- **Navigation** — `EtchNavigationApi`, `NavigationPlace`, `PostSummary`, `TemplateSummary`
|
|
246
|
+
- **Fields** — `EtchFieldsApi`, `CustomField`, `CustomFieldGroup`, …
|
|
247
|
+
- **UI / History** — `EtchUiApi`, `EtchHistoryApi`, `ColorScheme`
|
|
171
248
|
|
|
172
249
|
## Versioning
|
|
173
250
|
|
package/dist/index.d.cts
CHANGED
|
@@ -1,18 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Every type here is self-contained (no imports from the Etch source), so this
|
|
5
|
-
* file can ship as the published `.d.ts` and be the single artifact that is
|
|
6
|
-
* versioned deliberately. It mirrors the runtime exposed on `window.etch`.
|
|
7
|
-
*
|
|
8
|
-
* Method signatures take/return plain serializable values (block ids and JSON),
|
|
9
|
-
* never internal reactive class instances. Loose internal shapes (block JSON,
|
|
10
|
-
* loop query args, custom-field definitions) are modelled as **extensible**
|
|
11
|
-
* objects with an index signature, matching the runtime's permissive parsing.
|
|
12
|
-
*
|
|
13
|
-
* Several string fields use the `'literal' | (string & {})` idiom: the known
|
|
14
|
-
* values appear in autocomplete while any other string is still accepted (for
|
|
15
|
-
* loop parameter expressions, plugin-added values, etc.).
|
|
2
|
+
* Block JSON shapes (read and write) and the `etch.blocks` API surface.
|
|
16
3
|
*/
|
|
17
4
|
/** A block type identifier, always namespaced under `etch/` (e.g. `etch/text`). */
|
|
18
5
|
type EtchBlockType = `etch/${string}`;
|
|
@@ -324,7 +311,39 @@ interface EtchBlocksApi {
|
|
|
324
311
|
removeClass(blockId: string, className: string): void;
|
|
325
312
|
/** Whether the block currently has the given CSS class. */
|
|
326
313
|
hasClass(blockId: string, className: string): boolean;
|
|
314
|
+
/**
|
|
315
|
+
* Enter component edit (focus) mode on an `etch/component` block. The block
|
|
316
|
+
* is replaced by a focus wrapper whose children are the component's block
|
|
317
|
+
* tree, allowing direct inspection and mutation. Throws `WRONG_BLOCK_TYPE`
|
|
318
|
+
* for non-component blocks and `OPERATION_FAILED` if already in component
|
|
319
|
+
* edit mode or the component definition is not loaded.
|
|
320
|
+
*/
|
|
321
|
+
enterComponentEditMode(blockId: string): void;
|
|
322
|
+
/**
|
|
323
|
+
* Exit component edit (focus) mode. Does nothing when not in component edit
|
|
324
|
+
* mode. When `revert` is `true` the original component block is restored and
|
|
325
|
+
* any in-memory edits to the component definition are discarded; when
|
|
326
|
+
* omitted (or `false`) the focus wrapper is replaced by the component block
|
|
327
|
+
* as-is.
|
|
328
|
+
*/
|
|
329
|
+
exitComponentEditMode(options?: {
|
|
330
|
+
revert?: boolean;
|
|
331
|
+
}): void;
|
|
332
|
+
/** Whether the builder is currently in component edit (focus) mode. */
|
|
333
|
+
isInComponentEditMode(): boolean;
|
|
334
|
+
/**
|
|
335
|
+
* Persist the component currently being edited and save the page. The
|
|
336
|
+
* builder stays in component edit mode after the call; follow with
|
|
337
|
+
* `exitComponentEditMode()` when done. Throws `OPERATION_FAILED` when not
|
|
338
|
+
* in component edit mode.
|
|
339
|
+
*/
|
|
340
|
+
saveComponentEditModeAsync(): Promise<void>;
|
|
327
341
|
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Loop definitions, WordPress query argument shapes, and the `etch.loops` API
|
|
345
|
+
* surface.
|
|
346
|
+
*/
|
|
328
347
|
/**
|
|
329
348
|
* A loop parameter reference, e.g. `$count`. Resolved to a concrete value
|
|
330
349
|
* before the query runs.
|
|
@@ -517,32 +536,93 @@ interface EtchLoopsApi {
|
|
|
517
536
|
/** Bind (or update the binding of) a loop on an `etch/loop` block. */
|
|
518
537
|
setForBlock(blockId: string, loop: BlockLoopBinding): void;
|
|
519
538
|
}
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Global style (CSS rule) shapes and the `etch.styles` API surface.
|
|
542
|
+
*/
|
|
543
|
+
/**
|
|
544
|
+
* The selector type inferred from a style's selector string.
|
|
545
|
+
* - `class` — `.my-class`
|
|
546
|
+
* - `id` — `#my-id`
|
|
547
|
+
* - `tag` — `div`, `h1`, etc.
|
|
548
|
+
* - `element` — etch element selector (`:where([data-etch-element="..."])`)
|
|
549
|
+
* - `attribute` — `[data-foo]`, `[type="submit"]`, etc.
|
|
550
|
+
* - `custom` — anything else (pseudo-classes, combinators, etc.)
|
|
551
|
+
*/
|
|
552
|
+
type StyleSelectorType = "class" | "id" | "tag" | "element" | "attribute" | "custom";
|
|
553
|
+
/** A style entry as returned by `styles.list()`. */
|
|
554
|
+
interface StyleSummary {
|
|
555
|
+
/** Stable id of the style rule. */
|
|
556
|
+
id: string;
|
|
557
|
+
/** The CSS selector the rule targets. */
|
|
558
|
+
selector: string;
|
|
559
|
+
/**
|
|
560
|
+
* The selector type inferred from the selector string, or `undefined` when
|
|
561
|
+
* the selector is invalid.
|
|
562
|
+
*/
|
|
563
|
+
type: StyleSelectorType | undefined;
|
|
564
|
+
/**
|
|
565
|
+
* The collection this style belongs to.
|
|
566
|
+
*
|
|
567
|
+
* @reserved Collections are an internal implementation detail. Always
|
|
568
|
+
* `"default"` for styles created via the public API. Do not rely on this
|
|
569
|
+
* value — it may change without notice.
|
|
570
|
+
*/
|
|
571
|
+
collection: string;
|
|
572
|
+
/** The CSS declarations (rule body). */
|
|
573
|
+
css: string;
|
|
574
|
+
}
|
|
575
|
+
/** Filter accepted by `styles.list()`. All provided fields are AND-matched. */
|
|
576
|
+
interface StyleListFilter {
|
|
577
|
+
/** Restrict to styles whose inferred selector type matches. */
|
|
578
|
+
type?: StyleSelectorType;
|
|
579
|
+
/**
|
|
580
|
+
* Restrict to styles in this collection.
|
|
581
|
+
*
|
|
582
|
+
* @reserved Collections are an internal implementation detail. Omit this
|
|
583
|
+
* filter — filtering by collection is not supported for external use.
|
|
584
|
+
*/
|
|
585
|
+
collection?: string;
|
|
586
|
+
}
|
|
520
587
|
/** Patch accepted by `styles.update()`. Omitted fields keep their current value. */
|
|
521
588
|
interface StylePatch {
|
|
522
589
|
/** The CSS selector the rule targets. */
|
|
523
590
|
selector?: string;
|
|
524
591
|
/** The CSS declarations (rule body). */
|
|
525
592
|
css?: string;
|
|
526
|
-
/**
|
|
593
|
+
/**
|
|
594
|
+
* @reserved Collections are an internal implementation detail. Do not set
|
|
595
|
+
* this field — passing a value here has no guaranteed effect.
|
|
596
|
+
*/
|
|
527
597
|
collection?: string;
|
|
528
598
|
}
|
|
529
599
|
/** Global style (CSS) definitions, including `:root` global CSS variables. */
|
|
530
600
|
interface EtchStylesApi {
|
|
601
|
+
/**
|
|
602
|
+
* All styles as a flat array, optionally filtered by selector `type`.
|
|
603
|
+
* Useful for resolving selector names to their ids before passing those ids
|
|
604
|
+
* to other methods.
|
|
605
|
+
*/
|
|
606
|
+
list(filter?: StyleListFilter): StyleSummary[];
|
|
531
607
|
/** Create a style rule for `selector`; returns its id. */
|
|
532
|
-
create(selector: string, css?: string
|
|
533
|
-
/** Patch a style rule's selector
|
|
608
|
+
create(selector: string, css?: string): string;
|
|
609
|
+
/** Patch a style rule's selector or css. */
|
|
534
610
|
update(styleId: string, patch: StylePatch): void;
|
|
535
611
|
/** Delete a style rule by id. */
|
|
536
612
|
delete(styleId: string): void;
|
|
537
613
|
/** All global CSS custom properties as a `name -> value` record. */
|
|
538
|
-
listVariables(
|
|
614
|
+
listVariables(): Record<string, string>;
|
|
539
615
|
/** Read one global CSS custom property, or `undefined` when unset. */
|
|
540
|
-
getVariable(name: string
|
|
616
|
+
getVariable(name: string): string | undefined;
|
|
541
617
|
/** Set a global CSS custom property (e.g. `('--brand', '#0af')`). */
|
|
542
|
-
setVariable(name: string, value: string
|
|
618
|
+
setVariable(name: string, value: string): void;
|
|
543
619
|
/** Remove a global CSS custom property. */
|
|
544
|
-
removeVariable(name: string
|
|
620
|
+
removeVariable(name: string): void;
|
|
545
621
|
}
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Global stylesheet shapes and the `etch.stylesheets` API surface.
|
|
625
|
+
*/
|
|
546
626
|
/** Type of a global stylesheet. */
|
|
547
627
|
type StylesheetType = "default" | "@custom-media";
|
|
548
628
|
/** A global stylesheet entry. */
|
|
@@ -598,6 +678,12 @@ interface EtchStylesheetsApi {
|
|
|
598
678
|
/** Add (or look up) a `@custom-media` definition, e.g. `('--sm', '(max-width: 600px)')`. */
|
|
599
679
|
addCustomMediaAsync(name: string, query: string): Promise<void>;
|
|
600
680
|
}
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* Reusable-component property model, component JSON shapes, and the
|
|
684
|
+
* `etch.components` API surface.
|
|
685
|
+
*/
|
|
686
|
+
|
|
601
687
|
/** Fields shared by every component property. */
|
|
602
688
|
interface ComponentPropertyBase {
|
|
603
689
|
/** Display name of the property. */
|
|
@@ -832,6 +918,10 @@ interface EtchComponentsApi {
|
|
|
832
918
|
/** Delete a component by id. */
|
|
833
919
|
deleteAsync(componentId: number): Promise<void>;
|
|
834
920
|
}
|
|
921
|
+
|
|
922
|
+
/**
|
|
923
|
+
* Builder navigation shapes and the `etch.navigation` API surface.
|
|
924
|
+
*/
|
|
835
925
|
/**
|
|
836
926
|
* A navigable area of the builder UI:
|
|
837
927
|
* - `builder` — the canvas/editor
|
|
@@ -884,6 +974,10 @@ interface EtchNavigationApi {
|
|
|
884
974
|
/** List available templates. */
|
|
885
975
|
listTemplatesAsync(): Promise<TemplateSummary[]>;
|
|
886
976
|
}
|
|
977
|
+
|
|
978
|
+
/**
|
|
979
|
+
* Custom field group/value shapes and the `etch.fields` API surface.
|
|
980
|
+
*/
|
|
887
981
|
/** Custom field type. Open-ended for future field types. */
|
|
888
982
|
type CustomFieldType = "text" | "textarea" | "number" | "boolean" | (string & {});
|
|
889
983
|
/** A custom field definition (extensible). */
|
|
@@ -1000,6 +1094,10 @@ interface EtchFieldsApi {
|
|
|
1000
1094
|
/** Clear one field value on a post. */
|
|
1001
1095
|
deleteValueAsync(postId: number, fieldKey: string): Promise<void>;
|
|
1002
1096
|
}
|
|
1097
|
+
|
|
1098
|
+
/**
|
|
1099
|
+
* Builder chrome controls (`etch.ui`) and undo/redo (`etch.history`).
|
|
1100
|
+
*/
|
|
1003
1101
|
/** Canvas color scheme. */
|
|
1004
1102
|
type ColorScheme = "light" | "dark";
|
|
1005
1103
|
/** Builder app/chrome controls: color scheme, interface visibility, exit. */
|
|
@@ -1030,6 +1128,12 @@ interface EtchHistoryApi {
|
|
|
1030
1128
|
/** Whether there is a mutation to redo. */
|
|
1031
1129
|
canRedo(): boolean;
|
|
1032
1130
|
}
|
|
1131
|
+
|
|
1132
|
+
/**
|
|
1133
|
+
* The root {@link Etch} interface exposed on `window.etch`, tying every API
|
|
1134
|
+
* namespace together, plus connection/versioning options.
|
|
1135
|
+
*/
|
|
1136
|
+
|
|
1033
1137
|
/** Options for negotiating an API instance (see the runtime `connect`). */
|
|
1034
1138
|
interface ConnectOptions {
|
|
1035
1139
|
/**
|
|
@@ -1151,4 +1255,4 @@ declare function isEtchApiError(value: unknown): value is EtchApiError;
|
|
|
1151
1255
|
*/
|
|
1152
1256
|
declare const ETCH_API_VERSION = "0.x";
|
|
1153
1257
|
|
|
1154
|
-
export { type ArrayComponentProperty, type BlockLoopBinding, type BlockPatch, type BooleanComponentProperty, type BooleanParam, type ClassComponentProperty, type ColorScheme, type ComponentPatch, type ComponentProperty, type ComponentPropertyBase, type ConditionComponentProperty, type ConnectOptions, type CustomField, type CustomFieldAssignment, type CustomFieldGroup, type CustomFieldType, ETCH_API_VERSION, type Etch, EtchApiError, type EtchApiErrorCode, type EtchBlockCommon, type EtchBlockContext, type EtchBlockJson, type EtchBlockOptions, type EtchBlockScript, type EtchBlockType, type EtchBlockTypeName, type EtchBlocksApi, type EtchComponentBlockJson, type EtchComponentsApi, type EtchConditionBlockJson, type EtchDynamicElementBlockJson, type EtchDynamicImageBlockJson, type EtchElementBlockJson, type EtchFieldsApi, type EtchHistoryApi, type EtchHtmlAttributes, type EtchLoop, type EtchLoopBlockJson, type EtchLoopConfig, type EtchLoopObj, type EtchLoopsApi, type EtchNavigationApi, type EtchPassthroughBlockJson, type EtchPostContentBlockJson, type EtchRawHtmlBlockJson, type EtchSlotContentBlockJson, type EtchSlotPlaceholderBlockJson, type EtchStylesApi, type EtchStylesheetsApi, type EtchSvgBlockJson, type EtchTextBlockJson, type EtchUiApi, type FindBlocksPredicate, type GroupComponentProperty, type GutenbergBlock, type LoopParamRef, type MetaQueryItem, type NavigationPlace, type NumberComponentProperty, type NumericParam, type ObjectComponentProperty, type PostCustomFieldGroupEntry, type PostCustomFieldValueEntry, type PostCustomFieldValueResponse, type PostCustomFieldValuesResponse, type PostSummary, type PublicBlockJson, type PublicComponentJson, type PublicComponentSummary, type RepeaterComponentProperty, type ResolvedCustomField, type SelectOptionsString, type StringComponentProperty, type StylePatch, type StylesheetInput, type StylesheetPatch, type StylesheetSummary, type StylesheetType, type TaxQueryItem, type TemplateSummary, type WpQueryArgs, type WpTermsArgs, type WpUsersArgs, getEtch, isEtchApiError, isEtchAvailable };
|
|
1258
|
+
export { type ArrayComponentProperty, type BlockLoopBinding, type BlockPatch, type BooleanComponentProperty, type BooleanParam, type ClassComponentProperty, type ColorScheme, type ComponentPatch, type ComponentProperty, type ComponentPropertyBase, type ConditionComponentProperty, type ConnectOptions, type CustomField, type CustomFieldAssignment, type CustomFieldGroup, type CustomFieldType, ETCH_API_VERSION, type Etch, EtchApiError, type EtchApiErrorCode, type EtchBlockCommon, type EtchBlockContext, type EtchBlockJson, type EtchBlockOptions, type EtchBlockScript, type EtchBlockType, type EtchBlockTypeName, type EtchBlocksApi, type EtchComponentBlockJson, type EtchComponentsApi, type EtchConditionBlockJson, type EtchDynamicElementBlockJson, type EtchDynamicImageBlockJson, type EtchElementBlockJson, type EtchFieldsApi, type EtchHistoryApi, type EtchHtmlAttributes, type EtchLoop, type EtchLoopBlockJson, type EtchLoopConfig, type EtchLoopObj, type EtchLoopsApi, type EtchNavigationApi, type EtchPassthroughBlockJson, type EtchPostContentBlockJson, type EtchRawHtmlBlockJson, type EtchSlotContentBlockJson, type EtchSlotPlaceholderBlockJson, type EtchStylesApi, type EtchStylesheetsApi, type EtchSvgBlockJson, type EtchTextBlockJson, type EtchUiApi, type FindBlocksPredicate, type GroupComponentProperty, type GutenbergBlock, type LoopParamRef, type MetaQueryItem, type NavigationPlace, type NumberComponentProperty, type NumericParam, type ObjectComponentProperty, type PostCustomFieldGroupEntry, type PostCustomFieldValueEntry, type PostCustomFieldValueResponse, type PostCustomFieldValuesResponse, type PostSummary, type PublicBlockJson, type PublicComponentJson, type PublicComponentSummary, type RepeaterComponentProperty, type ResolvedCustomField, type SelectOptionsString, type StringComponentProperty, type StyleListFilter, type StylePatch, type StyleSelectorType, type StyleSummary, type StylesheetInput, type StylesheetPatch, type StylesheetSummary, type StylesheetType, type TaxQueryItem, type TemplateSummary, type WpQueryArgs, type WpTermsArgs, type WpUsersArgs, getEtch, isEtchApiError, isEtchAvailable };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Every type here is self-contained (no imports from the Etch source), so this
|
|
5
|
-
* file can ship as the published `.d.ts` and be the single artifact that is
|
|
6
|
-
* versioned deliberately. It mirrors the runtime exposed on `window.etch`.
|
|
7
|
-
*
|
|
8
|
-
* Method signatures take/return plain serializable values (block ids and JSON),
|
|
9
|
-
* never internal reactive class instances. Loose internal shapes (block JSON,
|
|
10
|
-
* loop query args, custom-field definitions) are modelled as **extensible**
|
|
11
|
-
* objects with an index signature, matching the runtime's permissive parsing.
|
|
12
|
-
*
|
|
13
|
-
* Several string fields use the `'literal' | (string & {})` idiom: the known
|
|
14
|
-
* values appear in autocomplete while any other string is still accepted (for
|
|
15
|
-
* loop parameter expressions, plugin-added values, etc.).
|
|
2
|
+
* Block JSON shapes (read and write) and the `etch.blocks` API surface.
|
|
16
3
|
*/
|
|
17
4
|
/** A block type identifier, always namespaced under `etch/` (e.g. `etch/text`). */
|
|
18
5
|
type EtchBlockType = `etch/${string}`;
|
|
@@ -324,7 +311,39 @@ interface EtchBlocksApi {
|
|
|
324
311
|
removeClass(blockId: string, className: string): void;
|
|
325
312
|
/** Whether the block currently has the given CSS class. */
|
|
326
313
|
hasClass(blockId: string, className: string): boolean;
|
|
314
|
+
/**
|
|
315
|
+
* Enter component edit (focus) mode on an `etch/component` block. The block
|
|
316
|
+
* is replaced by a focus wrapper whose children are the component's block
|
|
317
|
+
* tree, allowing direct inspection and mutation. Throws `WRONG_BLOCK_TYPE`
|
|
318
|
+
* for non-component blocks and `OPERATION_FAILED` if already in component
|
|
319
|
+
* edit mode or the component definition is not loaded.
|
|
320
|
+
*/
|
|
321
|
+
enterComponentEditMode(blockId: string): void;
|
|
322
|
+
/**
|
|
323
|
+
* Exit component edit (focus) mode. Does nothing when not in component edit
|
|
324
|
+
* mode. When `revert` is `true` the original component block is restored and
|
|
325
|
+
* any in-memory edits to the component definition are discarded; when
|
|
326
|
+
* omitted (or `false`) the focus wrapper is replaced by the component block
|
|
327
|
+
* as-is.
|
|
328
|
+
*/
|
|
329
|
+
exitComponentEditMode(options?: {
|
|
330
|
+
revert?: boolean;
|
|
331
|
+
}): void;
|
|
332
|
+
/** Whether the builder is currently in component edit (focus) mode. */
|
|
333
|
+
isInComponentEditMode(): boolean;
|
|
334
|
+
/**
|
|
335
|
+
* Persist the component currently being edited and save the page. The
|
|
336
|
+
* builder stays in component edit mode after the call; follow with
|
|
337
|
+
* `exitComponentEditMode()` when done. Throws `OPERATION_FAILED` when not
|
|
338
|
+
* in component edit mode.
|
|
339
|
+
*/
|
|
340
|
+
saveComponentEditModeAsync(): Promise<void>;
|
|
327
341
|
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Loop definitions, WordPress query argument shapes, and the `etch.loops` API
|
|
345
|
+
* surface.
|
|
346
|
+
*/
|
|
328
347
|
/**
|
|
329
348
|
* A loop parameter reference, e.g. `$count`. Resolved to a concrete value
|
|
330
349
|
* before the query runs.
|
|
@@ -517,32 +536,93 @@ interface EtchLoopsApi {
|
|
|
517
536
|
/** Bind (or update the binding of) a loop on an `etch/loop` block. */
|
|
518
537
|
setForBlock(blockId: string, loop: BlockLoopBinding): void;
|
|
519
538
|
}
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Global style (CSS rule) shapes and the `etch.styles` API surface.
|
|
542
|
+
*/
|
|
543
|
+
/**
|
|
544
|
+
* The selector type inferred from a style's selector string.
|
|
545
|
+
* - `class` — `.my-class`
|
|
546
|
+
* - `id` — `#my-id`
|
|
547
|
+
* - `tag` — `div`, `h1`, etc.
|
|
548
|
+
* - `element` — etch element selector (`:where([data-etch-element="..."])`)
|
|
549
|
+
* - `attribute` — `[data-foo]`, `[type="submit"]`, etc.
|
|
550
|
+
* - `custom` — anything else (pseudo-classes, combinators, etc.)
|
|
551
|
+
*/
|
|
552
|
+
type StyleSelectorType = "class" | "id" | "tag" | "element" | "attribute" | "custom";
|
|
553
|
+
/** A style entry as returned by `styles.list()`. */
|
|
554
|
+
interface StyleSummary {
|
|
555
|
+
/** Stable id of the style rule. */
|
|
556
|
+
id: string;
|
|
557
|
+
/** The CSS selector the rule targets. */
|
|
558
|
+
selector: string;
|
|
559
|
+
/**
|
|
560
|
+
* The selector type inferred from the selector string, or `undefined` when
|
|
561
|
+
* the selector is invalid.
|
|
562
|
+
*/
|
|
563
|
+
type: StyleSelectorType | undefined;
|
|
564
|
+
/**
|
|
565
|
+
* The collection this style belongs to.
|
|
566
|
+
*
|
|
567
|
+
* @reserved Collections are an internal implementation detail. Always
|
|
568
|
+
* `"default"` for styles created via the public API. Do not rely on this
|
|
569
|
+
* value — it may change without notice.
|
|
570
|
+
*/
|
|
571
|
+
collection: string;
|
|
572
|
+
/** The CSS declarations (rule body). */
|
|
573
|
+
css: string;
|
|
574
|
+
}
|
|
575
|
+
/** Filter accepted by `styles.list()`. All provided fields are AND-matched. */
|
|
576
|
+
interface StyleListFilter {
|
|
577
|
+
/** Restrict to styles whose inferred selector type matches. */
|
|
578
|
+
type?: StyleSelectorType;
|
|
579
|
+
/**
|
|
580
|
+
* Restrict to styles in this collection.
|
|
581
|
+
*
|
|
582
|
+
* @reserved Collections are an internal implementation detail. Omit this
|
|
583
|
+
* filter — filtering by collection is not supported for external use.
|
|
584
|
+
*/
|
|
585
|
+
collection?: string;
|
|
586
|
+
}
|
|
520
587
|
/** Patch accepted by `styles.update()`. Omitted fields keep their current value. */
|
|
521
588
|
interface StylePatch {
|
|
522
589
|
/** The CSS selector the rule targets. */
|
|
523
590
|
selector?: string;
|
|
524
591
|
/** The CSS declarations (rule body). */
|
|
525
592
|
css?: string;
|
|
526
|
-
/**
|
|
593
|
+
/**
|
|
594
|
+
* @reserved Collections are an internal implementation detail. Do not set
|
|
595
|
+
* this field — passing a value here has no guaranteed effect.
|
|
596
|
+
*/
|
|
527
597
|
collection?: string;
|
|
528
598
|
}
|
|
529
599
|
/** Global style (CSS) definitions, including `:root` global CSS variables. */
|
|
530
600
|
interface EtchStylesApi {
|
|
601
|
+
/**
|
|
602
|
+
* All styles as a flat array, optionally filtered by selector `type`.
|
|
603
|
+
* Useful for resolving selector names to their ids before passing those ids
|
|
604
|
+
* to other methods.
|
|
605
|
+
*/
|
|
606
|
+
list(filter?: StyleListFilter): StyleSummary[];
|
|
531
607
|
/** Create a style rule for `selector`; returns its id. */
|
|
532
|
-
create(selector: string, css?: string
|
|
533
|
-
/** Patch a style rule's selector
|
|
608
|
+
create(selector: string, css?: string): string;
|
|
609
|
+
/** Patch a style rule's selector or css. */
|
|
534
610
|
update(styleId: string, patch: StylePatch): void;
|
|
535
611
|
/** Delete a style rule by id. */
|
|
536
612
|
delete(styleId: string): void;
|
|
537
613
|
/** All global CSS custom properties as a `name -> value` record. */
|
|
538
|
-
listVariables(
|
|
614
|
+
listVariables(): Record<string, string>;
|
|
539
615
|
/** Read one global CSS custom property, or `undefined` when unset. */
|
|
540
|
-
getVariable(name: string
|
|
616
|
+
getVariable(name: string): string | undefined;
|
|
541
617
|
/** Set a global CSS custom property (e.g. `('--brand', '#0af')`). */
|
|
542
|
-
setVariable(name: string, value: string
|
|
618
|
+
setVariable(name: string, value: string): void;
|
|
543
619
|
/** Remove a global CSS custom property. */
|
|
544
|
-
removeVariable(name: string
|
|
620
|
+
removeVariable(name: string): void;
|
|
545
621
|
}
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Global stylesheet shapes and the `etch.stylesheets` API surface.
|
|
625
|
+
*/
|
|
546
626
|
/** Type of a global stylesheet. */
|
|
547
627
|
type StylesheetType = "default" | "@custom-media";
|
|
548
628
|
/** A global stylesheet entry. */
|
|
@@ -598,6 +678,12 @@ interface EtchStylesheetsApi {
|
|
|
598
678
|
/** Add (or look up) a `@custom-media` definition, e.g. `('--sm', '(max-width: 600px)')`. */
|
|
599
679
|
addCustomMediaAsync(name: string, query: string): Promise<void>;
|
|
600
680
|
}
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* Reusable-component property model, component JSON shapes, and the
|
|
684
|
+
* `etch.components` API surface.
|
|
685
|
+
*/
|
|
686
|
+
|
|
601
687
|
/** Fields shared by every component property. */
|
|
602
688
|
interface ComponentPropertyBase {
|
|
603
689
|
/** Display name of the property. */
|
|
@@ -832,6 +918,10 @@ interface EtchComponentsApi {
|
|
|
832
918
|
/** Delete a component by id. */
|
|
833
919
|
deleteAsync(componentId: number): Promise<void>;
|
|
834
920
|
}
|
|
921
|
+
|
|
922
|
+
/**
|
|
923
|
+
* Builder navigation shapes and the `etch.navigation` API surface.
|
|
924
|
+
*/
|
|
835
925
|
/**
|
|
836
926
|
* A navigable area of the builder UI:
|
|
837
927
|
* - `builder` — the canvas/editor
|
|
@@ -884,6 +974,10 @@ interface EtchNavigationApi {
|
|
|
884
974
|
/** List available templates. */
|
|
885
975
|
listTemplatesAsync(): Promise<TemplateSummary[]>;
|
|
886
976
|
}
|
|
977
|
+
|
|
978
|
+
/**
|
|
979
|
+
* Custom field group/value shapes and the `etch.fields` API surface.
|
|
980
|
+
*/
|
|
887
981
|
/** Custom field type. Open-ended for future field types. */
|
|
888
982
|
type CustomFieldType = "text" | "textarea" | "number" | "boolean" | (string & {});
|
|
889
983
|
/** A custom field definition (extensible). */
|
|
@@ -1000,6 +1094,10 @@ interface EtchFieldsApi {
|
|
|
1000
1094
|
/** Clear one field value on a post. */
|
|
1001
1095
|
deleteValueAsync(postId: number, fieldKey: string): Promise<void>;
|
|
1002
1096
|
}
|
|
1097
|
+
|
|
1098
|
+
/**
|
|
1099
|
+
* Builder chrome controls (`etch.ui`) and undo/redo (`etch.history`).
|
|
1100
|
+
*/
|
|
1003
1101
|
/** Canvas color scheme. */
|
|
1004
1102
|
type ColorScheme = "light" | "dark";
|
|
1005
1103
|
/** Builder app/chrome controls: color scheme, interface visibility, exit. */
|
|
@@ -1030,6 +1128,12 @@ interface EtchHistoryApi {
|
|
|
1030
1128
|
/** Whether there is a mutation to redo. */
|
|
1031
1129
|
canRedo(): boolean;
|
|
1032
1130
|
}
|
|
1131
|
+
|
|
1132
|
+
/**
|
|
1133
|
+
* The root {@link Etch} interface exposed on `window.etch`, tying every API
|
|
1134
|
+
* namespace together, plus connection/versioning options.
|
|
1135
|
+
*/
|
|
1136
|
+
|
|
1033
1137
|
/** Options for negotiating an API instance (see the runtime `connect`). */
|
|
1034
1138
|
interface ConnectOptions {
|
|
1035
1139
|
/**
|
|
@@ -1151,4 +1255,4 @@ declare function isEtchApiError(value: unknown): value is EtchApiError;
|
|
|
1151
1255
|
*/
|
|
1152
1256
|
declare const ETCH_API_VERSION = "0.x";
|
|
1153
1257
|
|
|
1154
|
-
export { type ArrayComponentProperty, type BlockLoopBinding, type BlockPatch, type BooleanComponentProperty, type BooleanParam, type ClassComponentProperty, type ColorScheme, type ComponentPatch, type ComponentProperty, type ComponentPropertyBase, type ConditionComponentProperty, type ConnectOptions, type CustomField, type CustomFieldAssignment, type CustomFieldGroup, type CustomFieldType, ETCH_API_VERSION, type Etch, EtchApiError, type EtchApiErrorCode, type EtchBlockCommon, type EtchBlockContext, type EtchBlockJson, type EtchBlockOptions, type EtchBlockScript, type EtchBlockType, type EtchBlockTypeName, type EtchBlocksApi, type EtchComponentBlockJson, type EtchComponentsApi, type EtchConditionBlockJson, type EtchDynamicElementBlockJson, type EtchDynamicImageBlockJson, type EtchElementBlockJson, type EtchFieldsApi, type EtchHistoryApi, type EtchHtmlAttributes, type EtchLoop, type EtchLoopBlockJson, type EtchLoopConfig, type EtchLoopObj, type EtchLoopsApi, type EtchNavigationApi, type EtchPassthroughBlockJson, type EtchPostContentBlockJson, type EtchRawHtmlBlockJson, type EtchSlotContentBlockJson, type EtchSlotPlaceholderBlockJson, type EtchStylesApi, type EtchStylesheetsApi, type EtchSvgBlockJson, type EtchTextBlockJson, type EtchUiApi, type FindBlocksPredicate, type GroupComponentProperty, type GutenbergBlock, type LoopParamRef, type MetaQueryItem, type NavigationPlace, type NumberComponentProperty, type NumericParam, type ObjectComponentProperty, type PostCustomFieldGroupEntry, type PostCustomFieldValueEntry, type PostCustomFieldValueResponse, type PostCustomFieldValuesResponse, type PostSummary, type PublicBlockJson, type PublicComponentJson, type PublicComponentSummary, type RepeaterComponentProperty, type ResolvedCustomField, type SelectOptionsString, type StringComponentProperty, type StylePatch, type StylesheetInput, type StylesheetPatch, type StylesheetSummary, type StylesheetType, type TaxQueryItem, type TemplateSummary, type WpQueryArgs, type WpTermsArgs, type WpUsersArgs, getEtch, isEtchApiError, isEtchAvailable };
|
|
1258
|
+
export { type ArrayComponentProperty, type BlockLoopBinding, type BlockPatch, type BooleanComponentProperty, type BooleanParam, type ClassComponentProperty, type ColorScheme, type ComponentPatch, type ComponentProperty, type ComponentPropertyBase, type ConditionComponentProperty, type ConnectOptions, type CustomField, type CustomFieldAssignment, type CustomFieldGroup, type CustomFieldType, ETCH_API_VERSION, type Etch, EtchApiError, type EtchApiErrorCode, type EtchBlockCommon, type EtchBlockContext, type EtchBlockJson, type EtchBlockOptions, type EtchBlockScript, type EtchBlockType, type EtchBlockTypeName, type EtchBlocksApi, type EtchComponentBlockJson, type EtchComponentsApi, type EtchConditionBlockJson, type EtchDynamicElementBlockJson, type EtchDynamicImageBlockJson, type EtchElementBlockJson, type EtchFieldsApi, type EtchHistoryApi, type EtchHtmlAttributes, type EtchLoop, type EtchLoopBlockJson, type EtchLoopConfig, type EtchLoopObj, type EtchLoopsApi, type EtchNavigationApi, type EtchPassthroughBlockJson, type EtchPostContentBlockJson, type EtchRawHtmlBlockJson, type EtchSlotContentBlockJson, type EtchSlotPlaceholderBlockJson, type EtchStylesApi, type EtchStylesheetsApi, type EtchSvgBlockJson, type EtchTextBlockJson, type EtchUiApi, type FindBlocksPredicate, type GroupComponentProperty, type GutenbergBlock, type LoopParamRef, type MetaQueryItem, type NavigationPlace, type NumberComponentProperty, type NumericParam, type ObjectComponentProperty, type PostCustomFieldGroupEntry, type PostCustomFieldValueEntry, type PostCustomFieldValueResponse, type PostCustomFieldValuesResponse, type PostSummary, type PublicBlockJson, type PublicComponentJson, type PublicComponentSummary, type RepeaterComponentProperty, type ResolvedCustomField, type SelectOptionsString, type StringComponentProperty, type StyleListFilter, type StylePatch, type StyleSelectorType, type StyleSummary, type StylesheetInput, type StylesheetPatch, type StylesheetSummary, type StylesheetType, type TaxQueryItem, type TemplateSummary, type WpQueryArgs, type WpTermsArgs, type WpUsersArgs, getEtch, isEtchApiError, isEtchAvailable };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digital-gravy/etch-public-api",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "MIT-licensed typed client and contract for the Etch builder scripting API (window.etch). Etch itself is a separate proprietary product governed by its own commercial terms.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|