@digital-gravy/etch-public-api 0.3.2 → 0.3.4
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 +91 -5
- package/dist/index.d.cts +138 -22
- package/dist/index.d.ts +138 -22
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -55,22 +55,77 @@ 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 (default collection)
|
|
70
85
|
etch.styles.setVariable("--brand", "#0af");
|
|
86
|
+
etch.styles.getVariable("--brand"); // "#0af"
|
|
71
87
|
|
|
72
|
-
//
|
|
88
|
+
// Variable methods accept an optional collection for multi-collection :root setups
|
|
89
|
+
etch.styles.setVariable("--brand", "#0af", "theme-a");
|
|
90
|
+
etch.styles.getVariable("--brand", "theme-a"); // "#0af"
|
|
91
|
+
etch.styles.listVariables("theme-a");
|
|
92
|
+
etch.styles.removeVariable("--brand", "theme-a");
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
> **Note:** The `collection` field on style **objects** (`StyleSummary`) and the
|
|
96
|
+
> `collection` argument on `create` / `update` are internal implementation
|
|
97
|
+
> details — always omit them for regular styles. The four `:root` variable
|
|
98
|
+
> methods (`listVariables`, `getVariable`, `setVariable`, `removeVariable`) are
|
|
99
|
+
> the exception: they accept an optional `collection` parameter, defaulting to
|
|
100
|
+
> `"default"` when omitted.
|
|
101
|
+
|
|
102
|
+
### Component edit mode
|
|
103
|
+
|
|
104
|
+
Use `blocks.enterComponentEditMode` to open a component's internal block tree
|
|
105
|
+
for direct inspection or mutation, then save and exit when done:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
// Find a component block
|
|
109
|
+
const [compId] = etch.blocks.find({ type: "etch/component" });
|
|
110
|
+
|
|
111
|
+
// Enter edit mode — the component's block tree becomes accessible
|
|
112
|
+
etch.blocks.enterComponentEditMode(compId);
|
|
113
|
+
|
|
114
|
+
// Inspect or mutate the component's children
|
|
115
|
+
const tree = etch.blocks.getTree();
|
|
116
|
+
|
|
117
|
+
// Persist the component definition to the backend
|
|
118
|
+
await etch.blocks.saveComponentEditModeAsync();
|
|
119
|
+
|
|
120
|
+
// Save the page, then exit edit mode
|
|
73
121
|
await etch.saveAsync();
|
|
122
|
+
etch.blocks.exitComponentEditMode();
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
To discard in-memory changes and restore the original block:
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
etch.blocks.exitComponentEditMode({ revert: true });
|
|
74
129
|
```
|
|
75
130
|
|
|
76
131
|
### Error handling
|
|
@@ -142,10 +197,33 @@ etch.blocks.create({
|
|
|
142
197
|
version: 1,
|
|
143
198
|
context: {},
|
|
144
199
|
children: [],
|
|
145
|
-
tag: "div",
|
|
200
|
+
tag: "div", // ✗ type error
|
|
146
201
|
});
|
|
147
202
|
```
|
|
148
203
|
|
|
204
|
+
### Special element attributes
|
|
205
|
+
|
|
206
|
+
Some block types recognise **special attributes** in addition to standard HTML:
|
|
207
|
+
|
|
208
|
+
**`etch/dynamic-image`** — rendered as `<img>`:
|
|
209
|
+
- `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}`).
|
|
210
|
+
- `useSrcSet` — `"true"` to generate a responsive `srcset` from the media (requires `mediaId`).
|
|
211
|
+
- `maximumSize` — WordPress image size slug (e.g. `"large"`, `"full"`) used when resolving the image. Defaults to `"full"`.
|
|
212
|
+
|
|
213
|
+
```ts
|
|
214
|
+
etch.blocks.setAttribute(imgBlockId, "mediaId", "{post.featured_image_id}");
|
|
215
|
+
etch.blocks.setAttribute(imgBlockId, "useSrcSet", "true");
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
**`etch/svg`** — inline SVG:
|
|
219
|
+
- `src` — URL of an external `.svg` file. Etch fetches and inlines the SVG at render time. Supports dynamic expressions.
|
|
220
|
+
- `stripColors` — `"true"` to strip `fill` and `stroke` colour declarations from the fetched SVG, so CSS can drive its colours instead.
|
|
221
|
+
|
|
222
|
+
```ts
|
|
223
|
+
etch.blocks.setAttribute(svgBlockId, "src", "/icons/logo.svg");
|
|
224
|
+
etch.blocks.setAttribute(svgBlockId, "stripColors", "true");
|
|
225
|
+
```
|
|
226
|
+
|
|
149
227
|
### Types only
|
|
150
228
|
|
|
151
229
|
Every contract type is exported and dependency-free, so you can use them
|
|
@@ -167,7 +245,15 @@ is imported.
|
|
|
167
245
|
- `getEtch(options?)` / `isEtchAvailable()` — acquire the API from the page.
|
|
168
246
|
- `EtchApiError` / `isEtchApiError()` / `EtchApiErrorCode` — typed errors.
|
|
169
247
|
- `ETCH_API_VERSION` — the contract version this package targets (`0.x`).
|
|
170
|
-
- The full contract as exported types
|
|
248
|
+
- The full contract as exported types:
|
|
249
|
+
- **Blocks** — `Etch`, `EtchBlocksApi`, `EtchBlockJson`, `PublicBlockJson`, `FindBlocksPredicate`, `BlockPatch`, …
|
|
250
|
+
- **Styles** — `EtchStylesApi`, `StyleSummary`, `StyleListFilter`, `StyleSelectorType`, `StylePatch`
|
|
251
|
+
- **Stylesheets** — `EtchStylesheetsApi`, `StylesheetSummary`, `StylesheetInput`, `StylesheetPatch`
|
|
252
|
+
- **Components** — `EtchComponentsApi`, `PublicComponentSummary`, `PublicComponentJson`, `ComponentPatch`, `ComponentProperty`, …
|
|
253
|
+
- **Loops** — `EtchLoopsApi`, `EtchLoop`, `EtchLoopConfig`, `BlockLoopBinding`, …
|
|
254
|
+
- **Navigation** — `EtchNavigationApi`, `NavigationPlace`, `PostSummary`, `TemplateSummary`
|
|
255
|
+
- **Fields** — `EtchFieldsApi`, `CustomField`, `CustomFieldGroup`, …
|
|
256
|
+
- **UI / History** — `EtchUiApi`, `EtchHistoryApi`, `ColorScheme`
|
|
171
257
|
|
|
172
258
|
## Versioning
|
|
173
259
|
|
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,105 @@ 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
|
+
/**
|
|
614
|
+
* All global CSS custom properties as a `name -> value` record.
|
|
615
|
+
* @param collection - The `:root` style collection. Defaults to `"default"`.
|
|
616
|
+
*/
|
|
538
617
|
listVariables(collection?: string): Record<string, string>;
|
|
539
|
-
/**
|
|
618
|
+
/**
|
|
619
|
+
* Read one global CSS custom property, or `undefined` when unset.
|
|
620
|
+
* @param collection - The `:root` style collection. Defaults to `"default"`.
|
|
621
|
+
*/
|
|
540
622
|
getVariable(name: string, collection?: string): string | undefined;
|
|
541
|
-
/**
|
|
623
|
+
/**
|
|
624
|
+
* Set a global CSS custom property (e.g. `('--brand', '#0af')`).
|
|
625
|
+
* @param collection - The `:root` style collection. Defaults to `"default"`.
|
|
626
|
+
*/
|
|
542
627
|
setVariable(name: string, value: string, collection?: string): void;
|
|
543
|
-
/**
|
|
628
|
+
/**
|
|
629
|
+
* Remove a global CSS custom property.
|
|
630
|
+
* @param collection - The `:root` style collection. Defaults to `"default"`.
|
|
631
|
+
*/
|
|
544
632
|
removeVariable(name: string, collection?: string): void;
|
|
545
633
|
}
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* Global stylesheet shapes and the `etch.stylesheets` API surface.
|
|
637
|
+
*/
|
|
546
638
|
/** Type of a global stylesheet. */
|
|
547
639
|
type StylesheetType = "default" | "@custom-media";
|
|
548
640
|
/** A global stylesheet entry. */
|
|
@@ -598,6 +690,12 @@ interface EtchStylesheetsApi {
|
|
|
598
690
|
/** Add (or look up) a `@custom-media` definition, e.g. `('--sm', '(max-width: 600px)')`. */
|
|
599
691
|
addCustomMediaAsync(name: string, query: string): Promise<void>;
|
|
600
692
|
}
|
|
693
|
+
|
|
694
|
+
/**
|
|
695
|
+
* Reusable-component property model, component JSON shapes, and the
|
|
696
|
+
* `etch.components` API surface.
|
|
697
|
+
*/
|
|
698
|
+
|
|
601
699
|
/** Fields shared by every component property. */
|
|
602
700
|
interface ComponentPropertyBase {
|
|
603
701
|
/** Display name of the property. */
|
|
@@ -832,6 +930,10 @@ interface EtchComponentsApi {
|
|
|
832
930
|
/** Delete a component by id. */
|
|
833
931
|
deleteAsync(componentId: number): Promise<void>;
|
|
834
932
|
}
|
|
933
|
+
|
|
934
|
+
/**
|
|
935
|
+
* Builder navigation shapes and the `etch.navigation` API surface.
|
|
936
|
+
*/
|
|
835
937
|
/**
|
|
836
938
|
* A navigable area of the builder UI:
|
|
837
939
|
* - `builder` — the canvas/editor
|
|
@@ -884,6 +986,10 @@ interface EtchNavigationApi {
|
|
|
884
986
|
/** List available templates. */
|
|
885
987
|
listTemplatesAsync(): Promise<TemplateSummary[]>;
|
|
886
988
|
}
|
|
989
|
+
|
|
990
|
+
/**
|
|
991
|
+
* Custom field group/value shapes and the `etch.fields` API surface.
|
|
992
|
+
*/
|
|
887
993
|
/** Custom field type. Open-ended for future field types. */
|
|
888
994
|
type CustomFieldType = "text" | "textarea" | "number" | "boolean" | (string & {});
|
|
889
995
|
/** A custom field definition (extensible). */
|
|
@@ -1000,6 +1106,10 @@ interface EtchFieldsApi {
|
|
|
1000
1106
|
/** Clear one field value on a post. */
|
|
1001
1107
|
deleteValueAsync(postId: number, fieldKey: string): Promise<void>;
|
|
1002
1108
|
}
|
|
1109
|
+
|
|
1110
|
+
/**
|
|
1111
|
+
* Builder chrome controls (`etch.ui`) and undo/redo (`etch.history`).
|
|
1112
|
+
*/
|
|
1003
1113
|
/** Canvas color scheme. */
|
|
1004
1114
|
type ColorScheme = "light" | "dark";
|
|
1005
1115
|
/** Builder app/chrome controls: color scheme, interface visibility, exit. */
|
|
@@ -1030,6 +1140,12 @@ interface EtchHistoryApi {
|
|
|
1030
1140
|
/** Whether there is a mutation to redo. */
|
|
1031
1141
|
canRedo(): boolean;
|
|
1032
1142
|
}
|
|
1143
|
+
|
|
1144
|
+
/**
|
|
1145
|
+
* The root {@link Etch} interface exposed on `window.etch`, tying every API
|
|
1146
|
+
* namespace together, plus connection/versioning options.
|
|
1147
|
+
*/
|
|
1148
|
+
|
|
1033
1149
|
/** Options for negotiating an API instance (see the runtime `connect`). */
|
|
1034
1150
|
interface ConnectOptions {
|
|
1035
1151
|
/**
|
|
@@ -1151,4 +1267,4 @@ declare function isEtchApiError(value: unknown): value is EtchApiError;
|
|
|
1151
1267
|
*/
|
|
1152
1268
|
declare const ETCH_API_VERSION = "0.x";
|
|
1153
1269
|
|
|
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 };
|
|
1270
|
+
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,105 @@ 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
|
+
/**
|
|
614
|
+
* All global CSS custom properties as a `name -> value` record.
|
|
615
|
+
* @param collection - The `:root` style collection. Defaults to `"default"`.
|
|
616
|
+
*/
|
|
538
617
|
listVariables(collection?: string): Record<string, string>;
|
|
539
|
-
/**
|
|
618
|
+
/**
|
|
619
|
+
* Read one global CSS custom property, or `undefined` when unset.
|
|
620
|
+
* @param collection - The `:root` style collection. Defaults to `"default"`.
|
|
621
|
+
*/
|
|
540
622
|
getVariable(name: string, collection?: string): string | undefined;
|
|
541
|
-
/**
|
|
623
|
+
/**
|
|
624
|
+
* Set a global CSS custom property (e.g. `('--brand', '#0af')`).
|
|
625
|
+
* @param collection - The `:root` style collection. Defaults to `"default"`.
|
|
626
|
+
*/
|
|
542
627
|
setVariable(name: string, value: string, collection?: string): void;
|
|
543
|
-
/**
|
|
628
|
+
/**
|
|
629
|
+
* Remove a global CSS custom property.
|
|
630
|
+
* @param collection - The `:root` style collection. Defaults to `"default"`.
|
|
631
|
+
*/
|
|
544
632
|
removeVariable(name: string, collection?: string): void;
|
|
545
633
|
}
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* Global stylesheet shapes and the `etch.stylesheets` API surface.
|
|
637
|
+
*/
|
|
546
638
|
/** Type of a global stylesheet. */
|
|
547
639
|
type StylesheetType = "default" | "@custom-media";
|
|
548
640
|
/** A global stylesheet entry. */
|
|
@@ -598,6 +690,12 @@ interface EtchStylesheetsApi {
|
|
|
598
690
|
/** Add (or look up) a `@custom-media` definition, e.g. `('--sm', '(max-width: 600px)')`. */
|
|
599
691
|
addCustomMediaAsync(name: string, query: string): Promise<void>;
|
|
600
692
|
}
|
|
693
|
+
|
|
694
|
+
/**
|
|
695
|
+
* Reusable-component property model, component JSON shapes, and the
|
|
696
|
+
* `etch.components` API surface.
|
|
697
|
+
*/
|
|
698
|
+
|
|
601
699
|
/** Fields shared by every component property. */
|
|
602
700
|
interface ComponentPropertyBase {
|
|
603
701
|
/** Display name of the property. */
|
|
@@ -832,6 +930,10 @@ interface EtchComponentsApi {
|
|
|
832
930
|
/** Delete a component by id. */
|
|
833
931
|
deleteAsync(componentId: number): Promise<void>;
|
|
834
932
|
}
|
|
933
|
+
|
|
934
|
+
/**
|
|
935
|
+
* Builder navigation shapes and the `etch.navigation` API surface.
|
|
936
|
+
*/
|
|
835
937
|
/**
|
|
836
938
|
* A navigable area of the builder UI:
|
|
837
939
|
* - `builder` — the canvas/editor
|
|
@@ -884,6 +986,10 @@ interface EtchNavigationApi {
|
|
|
884
986
|
/** List available templates. */
|
|
885
987
|
listTemplatesAsync(): Promise<TemplateSummary[]>;
|
|
886
988
|
}
|
|
989
|
+
|
|
990
|
+
/**
|
|
991
|
+
* Custom field group/value shapes and the `etch.fields` API surface.
|
|
992
|
+
*/
|
|
887
993
|
/** Custom field type. Open-ended for future field types. */
|
|
888
994
|
type CustomFieldType = "text" | "textarea" | "number" | "boolean" | (string & {});
|
|
889
995
|
/** A custom field definition (extensible). */
|
|
@@ -1000,6 +1106,10 @@ interface EtchFieldsApi {
|
|
|
1000
1106
|
/** Clear one field value on a post. */
|
|
1001
1107
|
deleteValueAsync(postId: number, fieldKey: string): Promise<void>;
|
|
1002
1108
|
}
|
|
1109
|
+
|
|
1110
|
+
/**
|
|
1111
|
+
* Builder chrome controls (`etch.ui`) and undo/redo (`etch.history`).
|
|
1112
|
+
*/
|
|
1003
1113
|
/** Canvas color scheme. */
|
|
1004
1114
|
type ColorScheme = "light" | "dark";
|
|
1005
1115
|
/** Builder app/chrome controls: color scheme, interface visibility, exit. */
|
|
@@ -1030,6 +1140,12 @@ interface EtchHistoryApi {
|
|
|
1030
1140
|
/** Whether there is a mutation to redo. */
|
|
1031
1141
|
canRedo(): boolean;
|
|
1032
1142
|
}
|
|
1143
|
+
|
|
1144
|
+
/**
|
|
1145
|
+
* The root {@link Etch} interface exposed on `window.etch`, tying every API
|
|
1146
|
+
* namespace together, plus connection/versioning options.
|
|
1147
|
+
*/
|
|
1148
|
+
|
|
1033
1149
|
/** Options for negotiating an API instance (see the runtime `connect`). */
|
|
1034
1150
|
interface ConnectOptions {
|
|
1035
1151
|
/**
|
|
@@ -1151,4 +1267,4 @@ declare function isEtchApiError(value: unknown): value is EtchApiError;
|
|
|
1151
1267
|
*/
|
|
1152
1268
|
declare const ETCH_API_VERSION = "0.x";
|
|
1153
1269
|
|
|
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 };
|
|
1270
|
+
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.4",
|
|
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",
|
|
@@ -43,4 +43,4 @@
|
|
|
43
43
|
"typescript": "^5.7.2",
|
|
44
44
|
"vitest": "^3.0.5"
|
|
45
45
|
}
|
|
46
|
-
}
|
|
46
|
+
}
|