@digital-gravy/etch-public-api 0.1.1 → 0.3.0
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 +98 -21
- package/dist/index.d.cts +256 -36
- package/dist/index.d.ts +256 -36
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,26 +19,55 @@ npm install @digital-gravy/etch-public-api
|
|
|
19
19
|
|
|
20
20
|
## Usage
|
|
21
21
|
|
|
22
|
+
### Getting the API object
|
|
23
|
+
|
|
24
|
+
The Etch builder injects the runtime onto `window.etch` during its bootstrap.
|
|
25
|
+
Acquire it with `getEtch()`, guarded by `isEtchAvailable()` for code that might
|
|
26
|
+
run outside the builder:
|
|
27
|
+
|
|
22
28
|
```ts
|
|
23
|
-
import { getEtch, isEtchAvailable
|
|
29
|
+
import { getEtch, isEtchAvailable } from "@digital-gravy/etch-public-api";
|
|
24
30
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
function run() {
|
|
32
|
+
if (!isEtchAvailable()) return; // not running inside the Etch builder
|
|
33
|
+
const etch = getEtch();
|
|
34
|
+
const textIds = etch.blocks.find({ type: "text" });
|
|
35
|
+
etch.blocks.setText(textIds[0], "Hello world");
|
|
28
36
|
}
|
|
37
|
+
```
|
|
29
38
|
|
|
30
|
-
|
|
39
|
+
`getEtch()` throws an `EtchApiError` with code `NOT_AVAILABLE` when the builder
|
|
40
|
+
isn't on the page, so you can also `try`/`catch` it. If your script may run
|
|
41
|
+
before the builder has finished loading, wait until it appears:
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { getEtch, isEtchAvailable } from "@digital-gravy/etch-public-api";
|
|
45
|
+
|
|
46
|
+
async function whenEtchReady(timeoutMs = 10_000) {
|
|
47
|
+
const start = Date.now();
|
|
48
|
+
while (!isEtchAvailable()) {
|
|
49
|
+
if (Date.now() - start > timeoutMs) throw new Error("Etch did not load");
|
|
50
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
51
|
+
}
|
|
52
|
+
return getEtch();
|
|
53
|
+
}
|
|
31
54
|
|
|
55
|
+
const etch = await whenEtchReady();
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Reading and mutating
|
|
59
|
+
|
|
60
|
+
```ts
|
|
32
61
|
// Read
|
|
33
|
-
const textIds = etch.blocks.find({ type:
|
|
62
|
+
const textIds = etch.blocks.find({ type: "text" });
|
|
34
63
|
const json = etch.blocks.getJson(textIds[0]);
|
|
35
64
|
|
|
36
65
|
// Mutate (routes through the same guarded paths as the UI; undo/redo works)
|
|
37
|
-
etch.blocks.setText(textIds[0],
|
|
38
|
-
etch.blocks.addClass(textIds[0],
|
|
66
|
+
etch.blocks.setText(textIds[0], "Hello world");
|
|
67
|
+
etch.blocks.addClass(textIds[0], "lead");
|
|
39
68
|
|
|
40
|
-
const styleId = etch.styles.create(
|
|
41
|
-
etch.styles.setVariable(
|
|
69
|
+
const styleId = etch.styles.create(".lead", "font-size: 1.25rem;");
|
|
70
|
+
etch.styles.setVariable("--brand", "#0af");
|
|
42
71
|
|
|
43
72
|
// Persist (blocks/styles wait for save; stylesheets/components/fields persist immediately)
|
|
44
73
|
await etch.saveAsync();
|
|
@@ -50,26 +79,71 @@ Methods throw a typed `EtchApiError` with a `code`, rather than returning
|
|
|
50
79
|
sentinels:
|
|
51
80
|
|
|
52
81
|
```ts
|
|
53
|
-
import { isEtchApiError } from
|
|
82
|
+
import { isEtchApiError } from "@digital-gravy/etch-public-api";
|
|
54
83
|
|
|
55
84
|
try {
|
|
56
|
-
|
|
85
|
+
etch.blocks.getJson("does-not-exist");
|
|
57
86
|
} catch (err) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
87
|
+
if (isEtchApiError(err)) {
|
|
88
|
+
console.warn(err.code, err.message); // e.g. "BLOCK_NOT_FOUND"
|
|
89
|
+
}
|
|
61
90
|
}
|
|
62
91
|
```
|
|
63
92
|
|
|
64
93
|
### Version negotiation
|
|
65
94
|
|
|
66
|
-
`
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
95
|
+
**Today (`0.x`): there is no real negotiation yet.** The runtime reports
|
|
96
|
+
`etch.apiVersion` as the coarse marker `'0.x'` (not a precise version), and
|
|
97
|
+
`getEtch({ apiVersion })` only does a best-effort major-version check that
|
|
98
|
+
`console.warn`s on mismatch — it never throws or adapts. While the surface is
|
|
99
|
+
experimental, **prefer feature detection** over version comparison:
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
const etch = getEtch();
|
|
103
|
+
if (typeof etch.blocks.someNewMethod === "function") {
|
|
104
|
+
// safe to use
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**In the future (once the contract reaches `1.x`):** `etch.apiVersion` will
|
|
109
|
+
report a real semver, and `getEtch()` will negotiate against the runtime's
|
|
110
|
+
native `connect()` — returning an instance pinned to the version your plugin
|
|
111
|
+
targets, and failing fast when the runtime can't satisfy it:
|
|
70
112
|
|
|
71
113
|
```ts
|
|
72
|
-
|
|
114
|
+
// Reserved API — shape of versioned access once the contract is stable:
|
|
115
|
+
const etch = getEtch({ apiVersion: "^1.0", id: "my-plugin" });
|
|
116
|
+
// └─ delegates to window.etch.connect({ apiVersion: "^1.0", id }) when present,
|
|
117
|
+
// yielding a version-pinned instance (throws on an incompatible runtime).
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
`getEtch()` already accepts `{ apiVersion, id }` today, so plugins can pass them
|
|
121
|
+
now and have them take effect automatically once the stable runtime ships — no
|
|
122
|
+
code change needed.
|
|
123
|
+
|
|
124
|
+
### Typed block JSON
|
|
125
|
+
|
|
126
|
+
Block JSON is a **discriminated union** on `type`, so the compiler flags a block
|
|
127
|
+
whose payload doesn't match its declared type, and `getJson()` / `getTree()`
|
|
128
|
+
results narrow by `type`:
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
const block = etch.blocks.getJson(id);
|
|
132
|
+
|
|
133
|
+
if (block.type === "etch/text") {
|
|
134
|
+
console.log(block.text); // narrowed to the text-block shape
|
|
135
|
+
} else if (block.type === "etch/element") {
|
|
136
|
+
console.log(block.tag, block.attributes);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Authoring is checked too — this is a type error (an `etch/text` has no `tag`):
|
|
140
|
+
etch.blocks.create({
|
|
141
|
+
type: "etch/text",
|
|
142
|
+
version: 1,
|
|
143
|
+
context: {},
|
|
144
|
+
children: [],
|
|
145
|
+
tag: "div",
|
|
146
|
+
});
|
|
73
147
|
```
|
|
74
148
|
|
|
75
149
|
### Types only
|
|
@@ -78,7 +152,10 @@ Every contract type is exported and dependency-free, so you can use them
|
|
|
78
152
|
directly:
|
|
79
153
|
|
|
80
154
|
```ts
|
|
81
|
-
import type {
|
|
155
|
+
import type {
|
|
156
|
+
PublicBlockJson,
|
|
157
|
+
EtchBlocksApi,
|
|
158
|
+
} from "@digital-gravy/etch-public-api";
|
|
82
159
|
```
|
|
83
160
|
|
|
84
161
|
You can also work against the global directly — the package augments
|
package/dist/index.d.cts
CHANGED
|
@@ -42,14 +42,28 @@ interface EtchBlockScript {
|
|
|
42
42
|
interface EtchBlockOptions {
|
|
43
43
|
[key: string]: unknown;
|
|
44
44
|
}
|
|
45
|
+
/** HTML attributes of a block. A value of `undefined` clears that attribute. */
|
|
46
|
+
type EtchHtmlAttributes = Record<string, string | undefined>;
|
|
45
47
|
/**
|
|
46
|
-
* A
|
|
47
|
-
* `
|
|
48
|
-
* fields, so the shape is intentionally extensible.
|
|
48
|
+
* A parsed Gutenberg block (WordPress block grammar), as carried by an
|
|
49
|
+
* `etch/passthrough` block. `attrs` is an open bag.
|
|
49
50
|
*/
|
|
50
|
-
interface
|
|
51
|
-
/**
|
|
52
|
-
|
|
51
|
+
interface GutenbergBlock {
|
|
52
|
+
/** Block name, e.g. `core/paragraph`. */
|
|
53
|
+
blockName: string;
|
|
54
|
+
/** Nested Gutenberg blocks. */
|
|
55
|
+
innerBlocks: GutenbergBlock[];
|
|
56
|
+
/** Rendered inner HTML. */
|
|
57
|
+
innerHTML: string;
|
|
58
|
+
/** Inner-content fragments (`null` marks an inner-block insertion point). */
|
|
59
|
+
innerContent: (string | null)[];
|
|
60
|
+
/** Block attributes. */
|
|
61
|
+
attrs: {
|
|
62
|
+
[key: string]: unknown;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** Fields shared by every block, whatever its `type`. */
|
|
66
|
+
interface EtchBlockCommon {
|
|
53
67
|
/** Schema version of this block type. */
|
|
54
68
|
version: number;
|
|
55
69
|
/** Editor-facing metadata (label, hidden, structure state). */
|
|
@@ -58,36 +72,167 @@ interface EtchBlockJson {
|
|
|
58
72
|
script?: EtchBlockScript;
|
|
59
73
|
/** Optional block-type-specific options. */
|
|
60
74
|
options?: EtchBlockOptions;
|
|
61
|
-
/** Child blocks, each itself an
|
|
75
|
+
/** Child blocks, each itself an {@link EtchBlockJson}. */
|
|
62
76
|
children: EtchBlockJson[];
|
|
63
|
-
|
|
64
|
-
|
|
77
|
+
}
|
|
78
|
+
/** A text block (`etch/text`). */
|
|
79
|
+
interface EtchTextBlockJson extends EtchBlockCommon {
|
|
80
|
+
type: "etch/text";
|
|
81
|
+
/** The block's text content. */
|
|
82
|
+
text: string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* A static HTML element block (`etch/element`) with a concrete tag.
|
|
86
|
+
*
|
|
87
|
+
* The global `styles` applied to the block are **read-only**: they appear on the
|
|
88
|
+
* read shape ({@link PublicBlockJson}) but are not settable here, so
|
|
89
|
+
* `blocks.create()` / `blocks.replace()` ignore them.
|
|
90
|
+
*/
|
|
91
|
+
interface EtchElementBlockJson extends EtchBlockCommon {
|
|
92
|
+
type: "etch/element";
|
|
93
|
+
/** The HTML tag name, e.g. `div`, `p`, `h1`. */
|
|
94
|
+
tag: string;
|
|
95
|
+
/** HTML attributes. */
|
|
96
|
+
attributes: EtchHtmlAttributes;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* A dynamic element block (`etch/dynamic-element`). Its rendered tag is read
|
|
100
|
+
* from `attributes.tag` rather than a dedicated field.
|
|
101
|
+
*
|
|
102
|
+
* The global `styles` applied to the block are **read-only** (see
|
|
103
|
+
* {@link EtchElementBlockJson}).
|
|
104
|
+
*/
|
|
105
|
+
interface EtchDynamicElementBlockJson extends EtchBlockCommon {
|
|
106
|
+
type: "etch/dynamic-element";
|
|
107
|
+
/** HTML attributes (the rendered tag is read from `attributes.tag`). */
|
|
108
|
+
attributes: EtchHtmlAttributes;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* A dynamic image block (`etch/dynamic-image`), rendered as an `<img>`.
|
|
112
|
+
*
|
|
113
|
+
* The global `styles` applied to the block are **read-only** (see
|
|
114
|
+
* {@link EtchElementBlockJson}).
|
|
115
|
+
*/
|
|
116
|
+
interface EtchDynamicImageBlockJson extends EtchBlockCommon {
|
|
117
|
+
type: "etch/dynamic-image";
|
|
118
|
+
/** HTML attributes (e.g. `src`, `alt`). */
|
|
119
|
+
attributes: EtchHtmlAttributes;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* An inline SVG block (`etch/svg`).
|
|
123
|
+
*
|
|
124
|
+
* The global `styles` applied to the block are **read-only** (see
|
|
125
|
+
* {@link EtchElementBlockJson}).
|
|
126
|
+
*/
|
|
127
|
+
interface EtchSvgBlockJson extends EtchBlockCommon {
|
|
128
|
+
type: "etch/svg";
|
|
129
|
+
/** HTML/SVG attributes. */
|
|
130
|
+
attributes: EtchHtmlAttributes;
|
|
131
|
+
}
|
|
132
|
+
/** A loop block (`etch/loop`) that repeats its children over a data source. */
|
|
133
|
+
interface EtchLoopBlockJson extends EtchBlockCommon {
|
|
134
|
+
type: "etch/loop";
|
|
135
|
+
/** Variable name bound to the current item (e.g. `item`). */
|
|
136
|
+
itemId: string;
|
|
137
|
+
/** What the block iterates over (a dynamic path); omitted when bound via `loopId`. */
|
|
138
|
+
target?: string;
|
|
139
|
+
/** Variable name bound to the current index. */
|
|
140
|
+
indexId?: string;
|
|
141
|
+
/** Id of a registered loop definition this block is bound to. */
|
|
142
|
+
loopId?: string;
|
|
143
|
+
/** Values for the bound loop's parameters. */
|
|
144
|
+
loopParams?: Record<string, unknown>;
|
|
145
|
+
}
|
|
146
|
+
/** A conditional block (`etch/condition`); renders its children when the expression holds. */
|
|
147
|
+
interface EtchConditionBlockJson extends EtchBlockCommon {
|
|
148
|
+
type: "etch/condition";
|
|
149
|
+
/** The condition expression. */
|
|
150
|
+
conditionString: string;
|
|
151
|
+
}
|
|
152
|
+
/** An instance of a reusable component (`etch/component`). */
|
|
153
|
+
interface EtchComponentBlockJson extends EtchBlockCommon {
|
|
154
|
+
type: "etch/component";
|
|
155
|
+
/** Id of the component being instantiated. */
|
|
156
|
+
componentId: number;
|
|
157
|
+
/** Values bound to the component's properties. */
|
|
158
|
+
attributes: EtchHtmlAttributes;
|
|
159
|
+
}
|
|
160
|
+
/** Content projected into a component slot (`etch/slot-content`). */
|
|
161
|
+
interface EtchSlotContentBlockJson extends EtchBlockCommon {
|
|
162
|
+
type: "etch/slot-content";
|
|
163
|
+
/** Name of the slot this content targets. */
|
|
164
|
+
slotName: string;
|
|
165
|
+
}
|
|
166
|
+
/** A slot placeholder inside a component definition (`etch/slot-placeholder`). */
|
|
167
|
+
interface EtchSlotPlaceholderBlockJson extends EtchBlockCommon {
|
|
168
|
+
type: "etch/slot-placeholder";
|
|
169
|
+
/** Name of the slot. */
|
|
170
|
+
slotName: string;
|
|
171
|
+
}
|
|
172
|
+
/** The post-content insertion point (`etch/post-content`). No extra fields. */
|
|
173
|
+
interface EtchPostContentBlockJson extends EtchBlockCommon {
|
|
174
|
+
type: "etch/post-content";
|
|
175
|
+
}
|
|
176
|
+
/** A raw-HTML block (`etch/raw-html`). */
|
|
177
|
+
interface EtchRawHtmlBlockJson extends EtchBlockCommon {
|
|
178
|
+
type: "etch/raw-html";
|
|
179
|
+
/** Sanitized HTML content. */
|
|
180
|
+
content: string;
|
|
181
|
+
/** The original, unsanitized HTML as authored. */
|
|
182
|
+
unsafe: string;
|
|
183
|
+
}
|
|
184
|
+
/** A pass-through wrapper around a native Gutenberg block (`etch/passthrough`). */
|
|
185
|
+
interface EtchPassthroughBlockJson extends EtchBlockCommon {
|
|
186
|
+
type: "etch/passthrough";
|
|
187
|
+
/** The wrapped Gutenberg block. */
|
|
188
|
+
gutenbergBlock: GutenbergBlock;
|
|
65
189
|
}
|
|
66
190
|
/**
|
|
67
|
-
* A block
|
|
68
|
-
* `
|
|
69
|
-
*
|
|
191
|
+
* A block as plain, structured-clone-safe JSON — the shape accepted by
|
|
192
|
+
* `blocks.create()` / `blocks.replace()`.
|
|
193
|
+
*
|
|
194
|
+
* This is a **discriminated union** on `type`: the compiler flags a block whose
|
|
195
|
+
* payload does not match its declared `type` (e.g. an `etch/text` block missing
|
|
196
|
+
* `text`, or carrying an `etch/element`'s `tag`).
|
|
70
197
|
*/
|
|
71
|
-
|
|
198
|
+
type EtchBlockJson = EtchTextBlockJson | EtchElementBlockJson | EtchDynamicElementBlockJson | EtchDynamicImageBlockJson | EtchSvgBlockJson | EtchLoopBlockJson | EtchConditionBlockJson | EtchComponentBlockJson | EtchSlotContentBlockJson | EtchSlotPlaceholderBlockJson | EtchPostContentBlockJson | EtchRawHtmlBlockJson | EtchPassthroughBlockJson;
|
|
199
|
+
/** Every known block `type` string (the discriminants of {@link EtchBlockJson}). */
|
|
200
|
+
type EtchBlockTypeName = EtchBlockJson["type"];
|
|
201
|
+
/** Read-only identity attached to every serialized (read) block. */
|
|
202
|
+
interface BlockIdentity {
|
|
72
203
|
/** Stable id of this block. */
|
|
73
204
|
id: string;
|
|
74
|
-
/** Id of the parent block, or `null`
|
|
205
|
+
/** Id of the parent block, or `null` at the document root. */
|
|
75
206
|
parentId: string | null;
|
|
76
|
-
/**
|
|
77
|
-
type: EtchBlockType;
|
|
78
|
-
/** Schema version of this block type. */
|
|
79
|
-
version: number;
|
|
80
|
-
/** Editor-facing metadata (label, hidden, structure state). */
|
|
81
|
-
context: EtchBlockContext;
|
|
82
|
-
/** Optional inline script attached to the block. */
|
|
83
|
-
script?: EtchBlockScript;
|
|
84
|
-
/** Optional block-type-specific options. */
|
|
85
|
-
options?: EtchBlockOptions;
|
|
86
|
-
/** Child blocks, each itself a `PublicBlockJson` with its own id/parentId. */
|
|
207
|
+
/** Child blocks, each itself a `PublicBlockJson`. */
|
|
87
208
|
children: PublicBlockJson[];
|
|
88
|
-
/** Block-type-specific fields beyond the common ones above. */
|
|
89
|
-
[key: string]: unknown;
|
|
90
209
|
}
|
|
210
|
+
/**
|
|
211
|
+
* Block types that carry global `styles` (ids of the applied global styles).
|
|
212
|
+
* These are **read-only**: exposed when reading a block, but not part of the
|
|
213
|
+
* writable {@link EtchBlockJson}, so they cannot be set via
|
|
214
|
+
* `blocks.create()` / `blocks.replace()`.
|
|
215
|
+
*/
|
|
216
|
+
type StyledBlockType = "etch/element" | "etch/dynamic-element" | "etch/dynamic-image" | "etch/svg";
|
|
217
|
+
/** The read-only `styles` exposed on a {@link StyledBlockType} when reading. */
|
|
218
|
+
interface ReadOnlyBlockStyles {
|
|
219
|
+
/** Ids of the global styles applied to this block (read-only). */
|
|
220
|
+
readonly styles: string[];
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Attach read-only identity (`id`/`parentId`) to a block, recursively, plus the
|
|
224
|
+
* read-only `styles` array for the {@link StyledBlockType}s that carry one.
|
|
225
|
+
*/
|
|
226
|
+
type WithIdentity<B> = B extends EtchBlockCommon ? Omit<B, "children"> & BlockIdentity & (B extends {
|
|
227
|
+
type: StyledBlockType;
|
|
228
|
+
} ? ReadOnlyBlockStyles : unknown) : never;
|
|
229
|
+
/**
|
|
230
|
+
* A block serialized for reading: an {@link EtchBlockJson} variant plus its
|
|
231
|
+
* `id` and `parentId` (`null` at the document root), attached recursively so
|
|
232
|
+
* every node in `children` is itself a `PublicBlockJson`. Still discriminated
|
|
233
|
+
* on `type`, so `switch (block.type)` narrows to the matching payload.
|
|
234
|
+
*/
|
|
235
|
+
type PublicBlockJson = WithIdentity<EtchBlockJson>;
|
|
91
236
|
/** Predicate accepted by `blocks.find()`. All provided fields must match (AND). */
|
|
92
237
|
interface FindBlocksPredicate {
|
|
93
238
|
/** Match blocks of this exact type (e.g. `etch/text`). */
|
|
@@ -445,7 +590,36 @@ interface ComponentPropertyBase {
|
|
|
445
590
|
/** Optional human-readable description. */
|
|
446
591
|
description?: string;
|
|
447
592
|
}
|
|
448
|
-
/**
|
|
593
|
+
/**
|
|
594
|
+
* Options for a `select` string property: newline-separated entries, each
|
|
595
|
+
* `Label : Value` (note the spaces around the colon). A line with no ` : ` uses
|
|
596
|
+
* its text as both label and value, and the **first line is the default**.
|
|
597
|
+
*
|
|
598
|
+
* It is a plain `string` (the format is a runtime convention, not enforced by
|
|
599
|
+
* the type) — parse it by splitting on `\n`, then each line on `" : "`.
|
|
600
|
+
*
|
|
601
|
+
* @example
|
|
602
|
+
* ```text
|
|
603
|
+
* Red : #ff0000
|
|
604
|
+
* Green : #00ff00
|
|
605
|
+
* Blue : #0000ff
|
|
606
|
+
* ```
|
|
607
|
+
*/
|
|
608
|
+
type SelectOptionsString = string;
|
|
609
|
+
/**
|
|
610
|
+
* A string property.
|
|
611
|
+
*
|
|
612
|
+
* `type.specialized` selects a string sub-type; a plain text property omits it.
|
|
613
|
+
* Values the builder actually uses:
|
|
614
|
+
* - `'image'` — image URL
|
|
615
|
+
* - `'wpMediaId'` — WordPress media id
|
|
616
|
+
* - `'select'` — a choice from `options`
|
|
617
|
+
* - `'array'` — a loop/array binding
|
|
618
|
+
*
|
|
619
|
+
* `'color'` and `'url'` are defined in the runtime enum but are **not currently
|
|
620
|
+
* used** by the builder — do not rely on them. (A `'condition'` string is a
|
|
621
|
+
* gated group, modelled separately as {@link ConditionComponentProperty}.)
|
|
622
|
+
*/
|
|
449
623
|
interface StringComponentProperty {
|
|
450
624
|
type: {
|
|
451
625
|
primitive: "string";
|
|
@@ -455,6 +629,12 @@ interface StringComponentProperty {
|
|
|
455
629
|
default?: string;
|
|
456
630
|
/** Allowed values when `specialized` is `select`. */
|
|
457
631
|
options?: string[];
|
|
632
|
+
/**
|
|
633
|
+
* Options for a `select` property, as a newline-separated string. Each line
|
|
634
|
+
* is `Label : Value` (note the spaces around the colon); a line with no ` : `
|
|
635
|
+
* uses its text as both label and value. The **first line is the default**.
|
|
636
|
+
*/
|
|
637
|
+
selectOptionsString?: SelectOptionsString;
|
|
458
638
|
}
|
|
459
639
|
/** A numeric property. */
|
|
460
640
|
interface NumberComponentProperty {
|
|
@@ -474,7 +654,13 @@ interface BooleanComponentProperty {
|
|
|
474
654
|
/** Default value (a string is allowed for expression-driven defaults). */
|
|
475
655
|
default?: boolean | string;
|
|
476
656
|
}
|
|
477
|
-
/**
|
|
657
|
+
/**
|
|
658
|
+
* A generic object property carrying structured data.
|
|
659
|
+
*
|
|
660
|
+
* `type.specialized` is left open (`string`) because the runtime does not
|
|
661
|
+
* constrain it to an enum. The one reserved value is `'group'`, modelled as
|
|
662
|
+
* {@link GroupComponentProperty}; a plain object omits `specialized`.
|
|
663
|
+
*/
|
|
478
664
|
interface ObjectComponentProperty {
|
|
479
665
|
type: {
|
|
480
666
|
primitive: "object";
|
|
@@ -483,7 +669,13 @@ interface ObjectComponentProperty {
|
|
|
483
669
|
/** Default value. */
|
|
484
670
|
default?: Record<string, unknown> | unknown[];
|
|
485
671
|
}
|
|
486
|
-
/**
|
|
672
|
+
/**
|
|
673
|
+
* A generic array property carrying a list of values.
|
|
674
|
+
*
|
|
675
|
+
* `type.specialized` is left open (`string`). The reserved values are `'class'`
|
|
676
|
+
* ({@link ClassComponentProperty}) and `'repeater'`
|
|
677
|
+
* ({@link RepeaterComponentProperty}); a plain array omits `specialized`.
|
|
678
|
+
*/
|
|
487
679
|
interface ArrayComponentProperty {
|
|
488
680
|
type: {
|
|
489
681
|
primitive: "array";
|
|
@@ -492,7 +684,7 @@ interface ArrayComponentProperty {
|
|
|
492
684
|
/** Default value. */
|
|
493
685
|
default?: unknown[];
|
|
494
686
|
}
|
|
495
|
-
/** A
|
|
687
|
+
/** A list of CSS class names — an `array` specialized as `'class'`. */
|
|
496
688
|
interface ClassComponentProperty {
|
|
497
689
|
type: {
|
|
498
690
|
primitive: "array";
|
|
@@ -501,7 +693,7 @@ interface ClassComponentProperty {
|
|
|
501
693
|
/** Default value. */
|
|
502
694
|
default?: string[];
|
|
503
695
|
}
|
|
504
|
-
/** A group of nested properties (no default
|
|
696
|
+
/** A group of nested properties — an `object` specialized as `'group'` (no default). */
|
|
505
697
|
interface GroupComponentProperty {
|
|
506
698
|
type: {
|
|
507
699
|
primitive: "object";
|
|
@@ -510,7 +702,7 @@ interface GroupComponentProperty {
|
|
|
510
702
|
/** The nested properties in this group. */
|
|
511
703
|
properties: ComponentProperty[];
|
|
512
704
|
}
|
|
513
|
-
/** A repeatable group
|
|
705
|
+
/** A repeatable group — an `array` specialized as `'repeater'` (no default). */
|
|
514
706
|
interface RepeaterComponentProperty {
|
|
515
707
|
type: {
|
|
516
708
|
primitive: "array";
|
|
@@ -519,7 +711,7 @@ interface RepeaterComponentProperty {
|
|
|
519
711
|
/** The nested properties repeated per row. */
|
|
520
712
|
properties: ComponentProperty[];
|
|
521
713
|
}
|
|
522
|
-
/** A conditional group gated by an expression
|
|
714
|
+
/** A conditional group gated by an expression — a `string` specialized as `'condition'`. */
|
|
523
715
|
interface ConditionComponentProperty {
|
|
524
716
|
type: {
|
|
525
717
|
primitive: "string";
|
|
@@ -530,7 +722,35 @@ interface ConditionComponentProperty {
|
|
|
530
722
|
/** The condition expression. */
|
|
531
723
|
default?: string;
|
|
532
724
|
}
|
|
533
|
-
/**
|
|
725
|
+
/**
|
|
726
|
+
* A single configurable property of a component.
|
|
727
|
+
*
|
|
728
|
+
* The `type` object carries a `primitive` plus an optional `specialized`
|
|
729
|
+
* refinement. The combinations the builder actually uses:
|
|
730
|
+
*
|
|
731
|
+
* - `string` — plain text; or `'image'` | `'wpMediaId'` | `'select'` |
|
|
732
|
+
* `'array'`; or `'condition'` (a gated group with nested `properties`)
|
|
733
|
+
* - `number` — numeric
|
|
734
|
+
* - `boolean` — boolean
|
|
735
|
+
* - `object` — generic object; or `'group'` (nested `properties`)
|
|
736
|
+
* - `array` — generic array; or `'class'` (CSS classes); or `'repeater'`
|
|
737
|
+
* (repeating group with nested `properties`)
|
|
738
|
+
*
|
|
739
|
+
* (`'color'`/`'url'` are defined in the string enum but unused — see
|
|
740
|
+
* {@link StringComponentProperty}.)
|
|
741
|
+
*
|
|
742
|
+
* `object`/`array` `specialized` is typed as an open `string` because the
|
|
743
|
+
* runtime does not constrain it to an enum. Because plain `string`/`object`/
|
|
744
|
+
* `array` variants omit `specialized`, narrow before reading it:
|
|
745
|
+
*
|
|
746
|
+
* ```ts
|
|
747
|
+
* if (prop.type.primitive === "object" && "specialized" in prop.type) {
|
|
748
|
+
* if (prop.type.specialized === "group") {
|
|
749
|
+
* // …group property
|
|
750
|
+
* }
|
|
751
|
+
* }
|
|
752
|
+
* ```
|
|
753
|
+
*/
|
|
534
754
|
type ComponentProperty = ComponentPropertyBase & (StringComponentProperty | NumberComponentProperty | BooleanComponentProperty | ObjectComponentProperty | ArrayComponentProperty | ClassComponentProperty | GroupComponentProperty | RepeaterComponentProperty | ConditionComponentProperty);
|
|
535
755
|
/** Component metadata without its block tree (returned by `components.list()`). */
|
|
536
756
|
interface PublicComponentSummary {
|
|
@@ -900,4 +1120,4 @@ declare function isEtchApiError(value: unknown): value is EtchApiError;
|
|
|
900
1120
|
*/
|
|
901
1121
|
declare const ETCH_API_VERSION = "0.x";
|
|
902
1122
|
|
|
903
|
-
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 EtchBlockContext, type EtchBlockJson, type EtchBlockOptions, type EtchBlockScript, type EtchBlockType, type EtchBlocksApi, type EtchComponentsApi, type EtchFieldsApi, type EtchHistoryApi, type EtchLoop, type EtchLoopConfig, type EtchLoopObj, type EtchLoopsApi, type EtchNavigationApi, type EtchStylesApi, type EtchStylesheetsApi, type EtchUiApi, type FindBlocksPredicate, type GroupComponentProperty, 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 StringComponentProperty, type StylePatch, type StylesheetInput, type StylesheetPatch, type StylesheetSummary, type StylesheetType, type TaxQueryItem, type TemplateSummary, type WpQueryArgs, type WpTermsArgs, type WpUsersArgs, getEtch, isEtchApiError, isEtchAvailable };
|
|
1123
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -42,14 +42,28 @@ interface EtchBlockScript {
|
|
|
42
42
|
interface EtchBlockOptions {
|
|
43
43
|
[key: string]: unknown;
|
|
44
44
|
}
|
|
45
|
+
/** HTML attributes of a block. A value of `undefined` clears that attribute. */
|
|
46
|
+
type EtchHtmlAttributes = Record<string, string | undefined>;
|
|
45
47
|
/**
|
|
46
|
-
* A
|
|
47
|
-
* `
|
|
48
|
-
* fields, so the shape is intentionally extensible.
|
|
48
|
+
* A parsed Gutenberg block (WordPress block grammar), as carried by an
|
|
49
|
+
* `etch/passthrough` block. `attrs` is an open bag.
|
|
49
50
|
*/
|
|
50
|
-
interface
|
|
51
|
-
/**
|
|
52
|
-
|
|
51
|
+
interface GutenbergBlock {
|
|
52
|
+
/** Block name, e.g. `core/paragraph`. */
|
|
53
|
+
blockName: string;
|
|
54
|
+
/** Nested Gutenberg blocks. */
|
|
55
|
+
innerBlocks: GutenbergBlock[];
|
|
56
|
+
/** Rendered inner HTML. */
|
|
57
|
+
innerHTML: string;
|
|
58
|
+
/** Inner-content fragments (`null` marks an inner-block insertion point). */
|
|
59
|
+
innerContent: (string | null)[];
|
|
60
|
+
/** Block attributes. */
|
|
61
|
+
attrs: {
|
|
62
|
+
[key: string]: unknown;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** Fields shared by every block, whatever its `type`. */
|
|
66
|
+
interface EtchBlockCommon {
|
|
53
67
|
/** Schema version of this block type. */
|
|
54
68
|
version: number;
|
|
55
69
|
/** Editor-facing metadata (label, hidden, structure state). */
|
|
@@ -58,36 +72,167 @@ interface EtchBlockJson {
|
|
|
58
72
|
script?: EtchBlockScript;
|
|
59
73
|
/** Optional block-type-specific options. */
|
|
60
74
|
options?: EtchBlockOptions;
|
|
61
|
-
/** Child blocks, each itself an
|
|
75
|
+
/** Child blocks, each itself an {@link EtchBlockJson}. */
|
|
62
76
|
children: EtchBlockJson[];
|
|
63
|
-
|
|
64
|
-
|
|
77
|
+
}
|
|
78
|
+
/** A text block (`etch/text`). */
|
|
79
|
+
interface EtchTextBlockJson extends EtchBlockCommon {
|
|
80
|
+
type: "etch/text";
|
|
81
|
+
/** The block's text content. */
|
|
82
|
+
text: string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* A static HTML element block (`etch/element`) with a concrete tag.
|
|
86
|
+
*
|
|
87
|
+
* The global `styles` applied to the block are **read-only**: they appear on the
|
|
88
|
+
* read shape ({@link PublicBlockJson}) but are not settable here, so
|
|
89
|
+
* `blocks.create()` / `blocks.replace()` ignore them.
|
|
90
|
+
*/
|
|
91
|
+
interface EtchElementBlockJson extends EtchBlockCommon {
|
|
92
|
+
type: "etch/element";
|
|
93
|
+
/** The HTML tag name, e.g. `div`, `p`, `h1`. */
|
|
94
|
+
tag: string;
|
|
95
|
+
/** HTML attributes. */
|
|
96
|
+
attributes: EtchHtmlAttributes;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* A dynamic element block (`etch/dynamic-element`). Its rendered tag is read
|
|
100
|
+
* from `attributes.tag` rather than a dedicated field.
|
|
101
|
+
*
|
|
102
|
+
* The global `styles` applied to the block are **read-only** (see
|
|
103
|
+
* {@link EtchElementBlockJson}).
|
|
104
|
+
*/
|
|
105
|
+
interface EtchDynamicElementBlockJson extends EtchBlockCommon {
|
|
106
|
+
type: "etch/dynamic-element";
|
|
107
|
+
/** HTML attributes (the rendered tag is read from `attributes.tag`). */
|
|
108
|
+
attributes: EtchHtmlAttributes;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* A dynamic image block (`etch/dynamic-image`), rendered as an `<img>`.
|
|
112
|
+
*
|
|
113
|
+
* The global `styles` applied to the block are **read-only** (see
|
|
114
|
+
* {@link EtchElementBlockJson}).
|
|
115
|
+
*/
|
|
116
|
+
interface EtchDynamicImageBlockJson extends EtchBlockCommon {
|
|
117
|
+
type: "etch/dynamic-image";
|
|
118
|
+
/** HTML attributes (e.g. `src`, `alt`). */
|
|
119
|
+
attributes: EtchHtmlAttributes;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* An inline SVG block (`etch/svg`).
|
|
123
|
+
*
|
|
124
|
+
* The global `styles` applied to the block are **read-only** (see
|
|
125
|
+
* {@link EtchElementBlockJson}).
|
|
126
|
+
*/
|
|
127
|
+
interface EtchSvgBlockJson extends EtchBlockCommon {
|
|
128
|
+
type: "etch/svg";
|
|
129
|
+
/** HTML/SVG attributes. */
|
|
130
|
+
attributes: EtchHtmlAttributes;
|
|
131
|
+
}
|
|
132
|
+
/** A loop block (`etch/loop`) that repeats its children over a data source. */
|
|
133
|
+
interface EtchLoopBlockJson extends EtchBlockCommon {
|
|
134
|
+
type: "etch/loop";
|
|
135
|
+
/** Variable name bound to the current item (e.g. `item`). */
|
|
136
|
+
itemId: string;
|
|
137
|
+
/** What the block iterates over (a dynamic path); omitted when bound via `loopId`. */
|
|
138
|
+
target?: string;
|
|
139
|
+
/** Variable name bound to the current index. */
|
|
140
|
+
indexId?: string;
|
|
141
|
+
/** Id of a registered loop definition this block is bound to. */
|
|
142
|
+
loopId?: string;
|
|
143
|
+
/** Values for the bound loop's parameters. */
|
|
144
|
+
loopParams?: Record<string, unknown>;
|
|
145
|
+
}
|
|
146
|
+
/** A conditional block (`etch/condition`); renders its children when the expression holds. */
|
|
147
|
+
interface EtchConditionBlockJson extends EtchBlockCommon {
|
|
148
|
+
type: "etch/condition";
|
|
149
|
+
/** The condition expression. */
|
|
150
|
+
conditionString: string;
|
|
151
|
+
}
|
|
152
|
+
/** An instance of a reusable component (`etch/component`). */
|
|
153
|
+
interface EtchComponentBlockJson extends EtchBlockCommon {
|
|
154
|
+
type: "etch/component";
|
|
155
|
+
/** Id of the component being instantiated. */
|
|
156
|
+
componentId: number;
|
|
157
|
+
/** Values bound to the component's properties. */
|
|
158
|
+
attributes: EtchHtmlAttributes;
|
|
159
|
+
}
|
|
160
|
+
/** Content projected into a component slot (`etch/slot-content`). */
|
|
161
|
+
interface EtchSlotContentBlockJson extends EtchBlockCommon {
|
|
162
|
+
type: "etch/slot-content";
|
|
163
|
+
/** Name of the slot this content targets. */
|
|
164
|
+
slotName: string;
|
|
165
|
+
}
|
|
166
|
+
/** A slot placeholder inside a component definition (`etch/slot-placeholder`). */
|
|
167
|
+
interface EtchSlotPlaceholderBlockJson extends EtchBlockCommon {
|
|
168
|
+
type: "etch/slot-placeholder";
|
|
169
|
+
/** Name of the slot. */
|
|
170
|
+
slotName: string;
|
|
171
|
+
}
|
|
172
|
+
/** The post-content insertion point (`etch/post-content`). No extra fields. */
|
|
173
|
+
interface EtchPostContentBlockJson extends EtchBlockCommon {
|
|
174
|
+
type: "etch/post-content";
|
|
175
|
+
}
|
|
176
|
+
/** A raw-HTML block (`etch/raw-html`). */
|
|
177
|
+
interface EtchRawHtmlBlockJson extends EtchBlockCommon {
|
|
178
|
+
type: "etch/raw-html";
|
|
179
|
+
/** Sanitized HTML content. */
|
|
180
|
+
content: string;
|
|
181
|
+
/** The original, unsanitized HTML as authored. */
|
|
182
|
+
unsafe: string;
|
|
183
|
+
}
|
|
184
|
+
/** A pass-through wrapper around a native Gutenberg block (`etch/passthrough`). */
|
|
185
|
+
interface EtchPassthroughBlockJson extends EtchBlockCommon {
|
|
186
|
+
type: "etch/passthrough";
|
|
187
|
+
/** The wrapped Gutenberg block. */
|
|
188
|
+
gutenbergBlock: GutenbergBlock;
|
|
65
189
|
}
|
|
66
190
|
/**
|
|
67
|
-
* A block
|
|
68
|
-
* `
|
|
69
|
-
*
|
|
191
|
+
* A block as plain, structured-clone-safe JSON — the shape accepted by
|
|
192
|
+
* `blocks.create()` / `blocks.replace()`.
|
|
193
|
+
*
|
|
194
|
+
* This is a **discriminated union** on `type`: the compiler flags a block whose
|
|
195
|
+
* payload does not match its declared `type` (e.g. an `etch/text` block missing
|
|
196
|
+
* `text`, or carrying an `etch/element`'s `tag`).
|
|
70
197
|
*/
|
|
71
|
-
|
|
198
|
+
type EtchBlockJson = EtchTextBlockJson | EtchElementBlockJson | EtchDynamicElementBlockJson | EtchDynamicImageBlockJson | EtchSvgBlockJson | EtchLoopBlockJson | EtchConditionBlockJson | EtchComponentBlockJson | EtchSlotContentBlockJson | EtchSlotPlaceholderBlockJson | EtchPostContentBlockJson | EtchRawHtmlBlockJson | EtchPassthroughBlockJson;
|
|
199
|
+
/** Every known block `type` string (the discriminants of {@link EtchBlockJson}). */
|
|
200
|
+
type EtchBlockTypeName = EtchBlockJson["type"];
|
|
201
|
+
/** Read-only identity attached to every serialized (read) block. */
|
|
202
|
+
interface BlockIdentity {
|
|
72
203
|
/** Stable id of this block. */
|
|
73
204
|
id: string;
|
|
74
|
-
/** Id of the parent block, or `null`
|
|
205
|
+
/** Id of the parent block, or `null` at the document root. */
|
|
75
206
|
parentId: string | null;
|
|
76
|
-
/**
|
|
77
|
-
type: EtchBlockType;
|
|
78
|
-
/** Schema version of this block type. */
|
|
79
|
-
version: number;
|
|
80
|
-
/** Editor-facing metadata (label, hidden, structure state). */
|
|
81
|
-
context: EtchBlockContext;
|
|
82
|
-
/** Optional inline script attached to the block. */
|
|
83
|
-
script?: EtchBlockScript;
|
|
84
|
-
/** Optional block-type-specific options. */
|
|
85
|
-
options?: EtchBlockOptions;
|
|
86
|
-
/** Child blocks, each itself a `PublicBlockJson` with its own id/parentId. */
|
|
207
|
+
/** Child blocks, each itself a `PublicBlockJson`. */
|
|
87
208
|
children: PublicBlockJson[];
|
|
88
|
-
/** Block-type-specific fields beyond the common ones above. */
|
|
89
|
-
[key: string]: unknown;
|
|
90
209
|
}
|
|
210
|
+
/**
|
|
211
|
+
* Block types that carry global `styles` (ids of the applied global styles).
|
|
212
|
+
* These are **read-only**: exposed when reading a block, but not part of the
|
|
213
|
+
* writable {@link EtchBlockJson}, so they cannot be set via
|
|
214
|
+
* `blocks.create()` / `blocks.replace()`.
|
|
215
|
+
*/
|
|
216
|
+
type StyledBlockType = "etch/element" | "etch/dynamic-element" | "etch/dynamic-image" | "etch/svg";
|
|
217
|
+
/** The read-only `styles` exposed on a {@link StyledBlockType} when reading. */
|
|
218
|
+
interface ReadOnlyBlockStyles {
|
|
219
|
+
/** Ids of the global styles applied to this block (read-only). */
|
|
220
|
+
readonly styles: string[];
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Attach read-only identity (`id`/`parentId`) to a block, recursively, plus the
|
|
224
|
+
* read-only `styles` array for the {@link StyledBlockType}s that carry one.
|
|
225
|
+
*/
|
|
226
|
+
type WithIdentity<B> = B extends EtchBlockCommon ? Omit<B, "children"> & BlockIdentity & (B extends {
|
|
227
|
+
type: StyledBlockType;
|
|
228
|
+
} ? ReadOnlyBlockStyles : unknown) : never;
|
|
229
|
+
/**
|
|
230
|
+
* A block serialized for reading: an {@link EtchBlockJson} variant plus its
|
|
231
|
+
* `id` and `parentId` (`null` at the document root), attached recursively so
|
|
232
|
+
* every node in `children` is itself a `PublicBlockJson`. Still discriminated
|
|
233
|
+
* on `type`, so `switch (block.type)` narrows to the matching payload.
|
|
234
|
+
*/
|
|
235
|
+
type PublicBlockJson = WithIdentity<EtchBlockJson>;
|
|
91
236
|
/** Predicate accepted by `blocks.find()`. All provided fields must match (AND). */
|
|
92
237
|
interface FindBlocksPredicate {
|
|
93
238
|
/** Match blocks of this exact type (e.g. `etch/text`). */
|
|
@@ -445,7 +590,36 @@ interface ComponentPropertyBase {
|
|
|
445
590
|
/** Optional human-readable description. */
|
|
446
591
|
description?: string;
|
|
447
592
|
}
|
|
448
|
-
/**
|
|
593
|
+
/**
|
|
594
|
+
* Options for a `select` string property: newline-separated entries, each
|
|
595
|
+
* `Label : Value` (note the spaces around the colon). A line with no ` : ` uses
|
|
596
|
+
* its text as both label and value, and the **first line is the default**.
|
|
597
|
+
*
|
|
598
|
+
* It is a plain `string` (the format is a runtime convention, not enforced by
|
|
599
|
+
* the type) — parse it by splitting on `\n`, then each line on `" : "`.
|
|
600
|
+
*
|
|
601
|
+
* @example
|
|
602
|
+
* ```text
|
|
603
|
+
* Red : #ff0000
|
|
604
|
+
* Green : #00ff00
|
|
605
|
+
* Blue : #0000ff
|
|
606
|
+
* ```
|
|
607
|
+
*/
|
|
608
|
+
type SelectOptionsString = string;
|
|
609
|
+
/**
|
|
610
|
+
* A string property.
|
|
611
|
+
*
|
|
612
|
+
* `type.specialized` selects a string sub-type; a plain text property omits it.
|
|
613
|
+
* Values the builder actually uses:
|
|
614
|
+
* - `'image'` — image URL
|
|
615
|
+
* - `'wpMediaId'` — WordPress media id
|
|
616
|
+
* - `'select'` — a choice from `options`
|
|
617
|
+
* - `'array'` — a loop/array binding
|
|
618
|
+
*
|
|
619
|
+
* `'color'` and `'url'` are defined in the runtime enum but are **not currently
|
|
620
|
+
* used** by the builder — do not rely on them. (A `'condition'` string is a
|
|
621
|
+
* gated group, modelled separately as {@link ConditionComponentProperty}.)
|
|
622
|
+
*/
|
|
449
623
|
interface StringComponentProperty {
|
|
450
624
|
type: {
|
|
451
625
|
primitive: "string";
|
|
@@ -455,6 +629,12 @@ interface StringComponentProperty {
|
|
|
455
629
|
default?: string;
|
|
456
630
|
/** Allowed values when `specialized` is `select`. */
|
|
457
631
|
options?: string[];
|
|
632
|
+
/**
|
|
633
|
+
* Options for a `select` property, as a newline-separated string. Each line
|
|
634
|
+
* is `Label : Value` (note the spaces around the colon); a line with no ` : `
|
|
635
|
+
* uses its text as both label and value. The **first line is the default**.
|
|
636
|
+
*/
|
|
637
|
+
selectOptionsString?: SelectOptionsString;
|
|
458
638
|
}
|
|
459
639
|
/** A numeric property. */
|
|
460
640
|
interface NumberComponentProperty {
|
|
@@ -474,7 +654,13 @@ interface BooleanComponentProperty {
|
|
|
474
654
|
/** Default value (a string is allowed for expression-driven defaults). */
|
|
475
655
|
default?: boolean | string;
|
|
476
656
|
}
|
|
477
|
-
/**
|
|
657
|
+
/**
|
|
658
|
+
* A generic object property carrying structured data.
|
|
659
|
+
*
|
|
660
|
+
* `type.specialized` is left open (`string`) because the runtime does not
|
|
661
|
+
* constrain it to an enum. The one reserved value is `'group'`, modelled as
|
|
662
|
+
* {@link GroupComponentProperty}; a plain object omits `specialized`.
|
|
663
|
+
*/
|
|
478
664
|
interface ObjectComponentProperty {
|
|
479
665
|
type: {
|
|
480
666
|
primitive: "object";
|
|
@@ -483,7 +669,13 @@ interface ObjectComponentProperty {
|
|
|
483
669
|
/** Default value. */
|
|
484
670
|
default?: Record<string, unknown> | unknown[];
|
|
485
671
|
}
|
|
486
|
-
/**
|
|
672
|
+
/**
|
|
673
|
+
* A generic array property carrying a list of values.
|
|
674
|
+
*
|
|
675
|
+
* `type.specialized` is left open (`string`). The reserved values are `'class'`
|
|
676
|
+
* ({@link ClassComponentProperty}) and `'repeater'`
|
|
677
|
+
* ({@link RepeaterComponentProperty}); a plain array omits `specialized`.
|
|
678
|
+
*/
|
|
487
679
|
interface ArrayComponentProperty {
|
|
488
680
|
type: {
|
|
489
681
|
primitive: "array";
|
|
@@ -492,7 +684,7 @@ interface ArrayComponentProperty {
|
|
|
492
684
|
/** Default value. */
|
|
493
685
|
default?: unknown[];
|
|
494
686
|
}
|
|
495
|
-
/** A
|
|
687
|
+
/** A list of CSS class names — an `array` specialized as `'class'`. */
|
|
496
688
|
interface ClassComponentProperty {
|
|
497
689
|
type: {
|
|
498
690
|
primitive: "array";
|
|
@@ -501,7 +693,7 @@ interface ClassComponentProperty {
|
|
|
501
693
|
/** Default value. */
|
|
502
694
|
default?: string[];
|
|
503
695
|
}
|
|
504
|
-
/** A group of nested properties (no default
|
|
696
|
+
/** A group of nested properties — an `object` specialized as `'group'` (no default). */
|
|
505
697
|
interface GroupComponentProperty {
|
|
506
698
|
type: {
|
|
507
699
|
primitive: "object";
|
|
@@ -510,7 +702,7 @@ interface GroupComponentProperty {
|
|
|
510
702
|
/** The nested properties in this group. */
|
|
511
703
|
properties: ComponentProperty[];
|
|
512
704
|
}
|
|
513
|
-
/** A repeatable group
|
|
705
|
+
/** A repeatable group — an `array` specialized as `'repeater'` (no default). */
|
|
514
706
|
interface RepeaterComponentProperty {
|
|
515
707
|
type: {
|
|
516
708
|
primitive: "array";
|
|
@@ -519,7 +711,7 @@ interface RepeaterComponentProperty {
|
|
|
519
711
|
/** The nested properties repeated per row. */
|
|
520
712
|
properties: ComponentProperty[];
|
|
521
713
|
}
|
|
522
|
-
/** A conditional group gated by an expression
|
|
714
|
+
/** A conditional group gated by an expression — a `string` specialized as `'condition'`. */
|
|
523
715
|
interface ConditionComponentProperty {
|
|
524
716
|
type: {
|
|
525
717
|
primitive: "string";
|
|
@@ -530,7 +722,35 @@ interface ConditionComponentProperty {
|
|
|
530
722
|
/** The condition expression. */
|
|
531
723
|
default?: string;
|
|
532
724
|
}
|
|
533
|
-
/**
|
|
725
|
+
/**
|
|
726
|
+
* A single configurable property of a component.
|
|
727
|
+
*
|
|
728
|
+
* The `type` object carries a `primitive` plus an optional `specialized`
|
|
729
|
+
* refinement. The combinations the builder actually uses:
|
|
730
|
+
*
|
|
731
|
+
* - `string` — plain text; or `'image'` | `'wpMediaId'` | `'select'` |
|
|
732
|
+
* `'array'`; or `'condition'` (a gated group with nested `properties`)
|
|
733
|
+
* - `number` — numeric
|
|
734
|
+
* - `boolean` — boolean
|
|
735
|
+
* - `object` — generic object; or `'group'` (nested `properties`)
|
|
736
|
+
* - `array` — generic array; or `'class'` (CSS classes); or `'repeater'`
|
|
737
|
+
* (repeating group with nested `properties`)
|
|
738
|
+
*
|
|
739
|
+
* (`'color'`/`'url'` are defined in the string enum but unused — see
|
|
740
|
+
* {@link StringComponentProperty}.)
|
|
741
|
+
*
|
|
742
|
+
* `object`/`array` `specialized` is typed as an open `string` because the
|
|
743
|
+
* runtime does not constrain it to an enum. Because plain `string`/`object`/
|
|
744
|
+
* `array` variants omit `specialized`, narrow before reading it:
|
|
745
|
+
*
|
|
746
|
+
* ```ts
|
|
747
|
+
* if (prop.type.primitive === "object" && "specialized" in prop.type) {
|
|
748
|
+
* if (prop.type.specialized === "group") {
|
|
749
|
+
* // …group property
|
|
750
|
+
* }
|
|
751
|
+
* }
|
|
752
|
+
* ```
|
|
753
|
+
*/
|
|
534
754
|
type ComponentProperty = ComponentPropertyBase & (StringComponentProperty | NumberComponentProperty | BooleanComponentProperty | ObjectComponentProperty | ArrayComponentProperty | ClassComponentProperty | GroupComponentProperty | RepeaterComponentProperty | ConditionComponentProperty);
|
|
535
755
|
/** Component metadata without its block tree (returned by `components.list()`). */
|
|
536
756
|
interface PublicComponentSummary {
|
|
@@ -900,4 +1120,4 @@ declare function isEtchApiError(value: unknown): value is EtchApiError;
|
|
|
900
1120
|
*/
|
|
901
1121
|
declare const ETCH_API_VERSION = "0.x";
|
|
902
1122
|
|
|
903
|
-
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 EtchBlockContext, type EtchBlockJson, type EtchBlockOptions, type EtchBlockScript, type EtchBlockType, type EtchBlocksApi, type EtchComponentsApi, type EtchFieldsApi, type EtchHistoryApi, type EtchLoop, type EtchLoopConfig, type EtchLoopObj, type EtchLoopsApi, type EtchNavigationApi, type EtchStylesApi, type EtchStylesheetsApi, type EtchUiApi, type FindBlocksPredicate, type GroupComponentProperty, 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 StringComponentProperty, type StylePatch, type StylesheetInput, type StylesheetPatch, type StylesheetSummary, type StylesheetType, type TaxQueryItem, type TemplateSummary, type WpQueryArgs, type WpTermsArgs, type WpUsersArgs, getEtch, isEtchApiError, isEtchAvailable };
|
|
1123
|
+
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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digital-gravy/etch-public-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
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",
|