@digital-gravy/etch-public-api 0.3.3 → 0.6.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 CHANGED
@@ -81,14 +81,23 @@ const classStyles = etch.styles.list({ type: "class" });
81
81
  const myStyle = etch.styles.list().find((s) => s.selector === ".lead");
82
82
  console.log(myStyle?.id); // the id you pass to blocks.addClass etc.
83
83
 
84
- // Global CSS custom properties
84
+ // Global CSS custom properties (default collection)
85
85
  etch.styles.setVariable("--brand", "#0af");
86
86
  etch.styles.getVariable("--brand"); // "#0af"
87
+
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");
87
93
  ```
88
94
 
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.
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.
92
101
 
93
102
  ### Component edit mode
94
103
 
package/dist/index.d.cts CHANGED
@@ -610,14 +610,26 @@ interface EtchStylesApi {
610
610
  update(styleId: string, patch: StylePatch): void;
611
611
  /** Delete a style rule by id. */
612
612
  delete(styleId: string): void;
613
- /** All global CSS custom properties as a `name -> value` record. */
614
- listVariables(): Record<string, string>;
615
- /** Read one global CSS custom property, or `undefined` when unset. */
616
- getVariable(name: string): string | undefined;
617
- /** Set a global CSS custom property (e.g. `('--brand', '#0af')`). */
618
- setVariable(name: string, value: string): void;
619
- /** Remove a global CSS custom property. */
620
- removeVariable(name: string): void;
613
+ /**
614
+ * All global CSS custom properties as a `name -> value` record.
615
+ * @param collection - The `:root` style collection. Defaults to `"default"`.
616
+ */
617
+ listVariables(collection?: string): Record<string, string>;
618
+ /**
619
+ * Read one global CSS custom property, or `undefined` when unset.
620
+ * @param collection - The `:root` style collection. Defaults to `"default"`.
621
+ */
622
+ getVariable(name: string, collection?: string): string | undefined;
623
+ /**
624
+ * Set a global CSS custom property (e.g. `('--brand', '#0af')`).
625
+ * @param collection - The `:root` style collection. Defaults to `"default"`.
626
+ */
627
+ setVariable(name: string, value: string, collection?: string): void;
628
+ /**
629
+ * Remove a global CSS custom property.
630
+ * @param collection - The `:root` style collection. Defaults to `"default"`.
631
+ */
632
+ removeVariable(name: string, collection?: string): void;
621
633
  }
622
634
 
623
635
  /**
@@ -1129,6 +1141,59 @@ interface EtchHistoryApi {
1129
1141
  canRedo(): boolean;
1130
1142
  }
1131
1143
 
1144
+ /**
1145
+ * Live bridge connection — lets an external tool (an IDE, a script runner, an AI
1146
+ * agent) drive this Etch instance from outside the page over a WebSocket.
1147
+ *
1148
+ * Calling `window.etch.connectAs(name)` from the builder console opens a
1149
+ * connection to a local bridge server and registers this instance under `name`.
1150
+ * Because the name travels to the server, one server can hold connections to
1151
+ * several Etch tabs at once and address each by name. The server then pushes JS
1152
+ * to evaluate in the page; the page streams console output and the return value
1153
+ * back.
1154
+ *
1155
+ * This is the inverse of Chrome remote debugging: the browser dials out to the
1156
+ * tool, instead of the tool attaching to the browser's debug port. Console-run
1157
+ * code is exempt from the page's CSP, so the connection works even on
1158
+ * locked-down pages.
1159
+ */
1160
+ /** Options for {@link Etch.connectAs} / `etch.connectAs`. */
1161
+ interface BridgeConnectOptions {
1162
+ /**
1163
+ * Full WebSocket endpoint of the bridge server. Defaults to
1164
+ * `ws://127.0.0.1:7331`. Set this to target a different host/port or a
1165
+ * `wss://` endpoint.
1166
+ */
1167
+ url?: string;
1168
+ /**
1169
+ * Shorthand for a localhost endpoint on a custom port
1170
+ * (`ws://127.0.0.1:<port>`). Ignored when {@link url} is provided.
1171
+ */
1172
+ port?: number;
1173
+ /**
1174
+ * Extra identifying metadata sent to the server alongside the name (e.g. a
1175
+ * project id or environment label), so the tool can group or disambiguate
1176
+ * tabs beyond the name alone.
1177
+ */
1178
+ meta?: Record<string, unknown>;
1179
+ /**
1180
+ * Reconnect automatically (with backoff) when the socket drops. Default
1181
+ * `true`.
1182
+ */
1183
+ reconnect?: boolean;
1184
+ }
1185
+ /** Handle to a live bridge connection returned by `etch.connectAs`. */
1186
+ interface EtchBridgeConnection {
1187
+ /** The name this instance registered under — how the tool addresses it. */
1188
+ readonly name: string;
1189
+ /** The resolved WebSocket endpoint the connection targets. */
1190
+ readonly url: string;
1191
+ /** Whether the socket is currently open. */
1192
+ readonly connected: boolean;
1193
+ /** Close the connection and stop reconnecting. */
1194
+ close(): void;
1195
+ }
1196
+
1132
1197
  /**
1133
1198
  * The root {@link Etch} interface exposed on `window.etch`, tying every API
1134
1199
  * namespace together, plus connection/versioning options.
@@ -1177,6 +1242,21 @@ interface Etch {
1177
1242
  history: EtchHistoryApi;
1178
1243
  /** Persist everything (blocks, loops, styles, UI). */
1179
1244
  saveAsync(): Promise<void>;
1245
+ /**
1246
+ * Open a live bridge connection to a local tooling server (an IDE, a script
1247
+ * runner, an AI agent) and register this instance under `name`, so one server
1248
+ * can drive several Etch tabs at once and tell them apart by name. Returns a
1249
+ * handle; call again with a different name/endpoint to open more connections.
1250
+ *
1251
+ * @example
1252
+ * ```js
1253
+ * // In the builder console:
1254
+ * const conn = etch.connectAs('homepage');
1255
+ * // …the tool can now evaluate code in this tab; later:
1256
+ * conn.close();
1257
+ * ```
1258
+ */
1259
+ connectAs(name: string, options?: BridgeConnectOptions): EtchBridgeConnection;
1180
1260
  /**
1181
1261
  * Negotiate a version-pinned API instance. **Reserved** — not implemented by
1182
1262
  * `0.x` runtimes. When present on a future stable runtime, it returns an
@@ -1255,4 +1335,4 @@ declare function isEtchApiError(value: unknown): value is EtchApiError;
1255
1335
  */
1256
1336
  declare const ETCH_API_VERSION = "0.x";
1257
1337
 
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 };
1338
+ export { type ArrayComponentProperty, type BlockLoopBinding, type BlockPatch, type BooleanComponentProperty, type BooleanParam, type BridgeConnectOptions, 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 EtchBridgeConnection, 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
@@ -610,14 +610,26 @@ interface EtchStylesApi {
610
610
  update(styleId: string, patch: StylePatch): void;
611
611
  /** Delete a style rule by id. */
612
612
  delete(styleId: string): void;
613
- /** All global CSS custom properties as a `name -> value` record. */
614
- listVariables(): Record<string, string>;
615
- /** Read one global CSS custom property, or `undefined` when unset. */
616
- getVariable(name: string): string | undefined;
617
- /** Set a global CSS custom property (e.g. `('--brand', '#0af')`). */
618
- setVariable(name: string, value: string): void;
619
- /** Remove a global CSS custom property. */
620
- removeVariable(name: string): void;
613
+ /**
614
+ * All global CSS custom properties as a `name -> value` record.
615
+ * @param collection - The `:root` style collection. Defaults to `"default"`.
616
+ */
617
+ listVariables(collection?: string): Record<string, string>;
618
+ /**
619
+ * Read one global CSS custom property, or `undefined` when unset.
620
+ * @param collection - The `:root` style collection. Defaults to `"default"`.
621
+ */
622
+ getVariable(name: string, collection?: string): string | undefined;
623
+ /**
624
+ * Set a global CSS custom property (e.g. `('--brand', '#0af')`).
625
+ * @param collection - The `:root` style collection. Defaults to `"default"`.
626
+ */
627
+ setVariable(name: string, value: string, collection?: string): void;
628
+ /**
629
+ * Remove a global CSS custom property.
630
+ * @param collection - The `:root` style collection. Defaults to `"default"`.
631
+ */
632
+ removeVariable(name: string, collection?: string): void;
621
633
  }
622
634
 
623
635
  /**
@@ -1129,6 +1141,59 @@ interface EtchHistoryApi {
1129
1141
  canRedo(): boolean;
1130
1142
  }
1131
1143
 
1144
+ /**
1145
+ * Live bridge connection — lets an external tool (an IDE, a script runner, an AI
1146
+ * agent) drive this Etch instance from outside the page over a WebSocket.
1147
+ *
1148
+ * Calling `window.etch.connectAs(name)` from the builder console opens a
1149
+ * connection to a local bridge server and registers this instance under `name`.
1150
+ * Because the name travels to the server, one server can hold connections to
1151
+ * several Etch tabs at once and address each by name. The server then pushes JS
1152
+ * to evaluate in the page; the page streams console output and the return value
1153
+ * back.
1154
+ *
1155
+ * This is the inverse of Chrome remote debugging: the browser dials out to the
1156
+ * tool, instead of the tool attaching to the browser's debug port. Console-run
1157
+ * code is exempt from the page's CSP, so the connection works even on
1158
+ * locked-down pages.
1159
+ */
1160
+ /** Options for {@link Etch.connectAs} / `etch.connectAs`. */
1161
+ interface BridgeConnectOptions {
1162
+ /**
1163
+ * Full WebSocket endpoint of the bridge server. Defaults to
1164
+ * `ws://127.0.0.1:7331`. Set this to target a different host/port or a
1165
+ * `wss://` endpoint.
1166
+ */
1167
+ url?: string;
1168
+ /**
1169
+ * Shorthand for a localhost endpoint on a custom port
1170
+ * (`ws://127.0.0.1:<port>`). Ignored when {@link url} is provided.
1171
+ */
1172
+ port?: number;
1173
+ /**
1174
+ * Extra identifying metadata sent to the server alongside the name (e.g. a
1175
+ * project id or environment label), so the tool can group or disambiguate
1176
+ * tabs beyond the name alone.
1177
+ */
1178
+ meta?: Record<string, unknown>;
1179
+ /**
1180
+ * Reconnect automatically (with backoff) when the socket drops. Default
1181
+ * `true`.
1182
+ */
1183
+ reconnect?: boolean;
1184
+ }
1185
+ /** Handle to a live bridge connection returned by `etch.connectAs`. */
1186
+ interface EtchBridgeConnection {
1187
+ /** The name this instance registered under — how the tool addresses it. */
1188
+ readonly name: string;
1189
+ /** The resolved WebSocket endpoint the connection targets. */
1190
+ readonly url: string;
1191
+ /** Whether the socket is currently open. */
1192
+ readonly connected: boolean;
1193
+ /** Close the connection and stop reconnecting. */
1194
+ close(): void;
1195
+ }
1196
+
1132
1197
  /**
1133
1198
  * The root {@link Etch} interface exposed on `window.etch`, tying every API
1134
1199
  * namespace together, plus connection/versioning options.
@@ -1177,6 +1242,21 @@ interface Etch {
1177
1242
  history: EtchHistoryApi;
1178
1243
  /** Persist everything (blocks, loops, styles, UI). */
1179
1244
  saveAsync(): Promise<void>;
1245
+ /**
1246
+ * Open a live bridge connection to a local tooling server (an IDE, a script
1247
+ * runner, an AI agent) and register this instance under `name`, so one server
1248
+ * can drive several Etch tabs at once and tell them apart by name. Returns a
1249
+ * handle; call again with a different name/endpoint to open more connections.
1250
+ *
1251
+ * @example
1252
+ * ```js
1253
+ * // In the builder console:
1254
+ * const conn = etch.connectAs('homepage');
1255
+ * // …the tool can now evaluate code in this tab; later:
1256
+ * conn.close();
1257
+ * ```
1258
+ */
1259
+ connectAs(name: string, options?: BridgeConnectOptions): EtchBridgeConnection;
1180
1260
  /**
1181
1261
  * Negotiate a version-pinned API instance. **Reserved** — not implemented by
1182
1262
  * `0.x` runtimes. When present on a future stable runtime, it returns an
@@ -1255,4 +1335,4 @@ declare function isEtchApiError(value: unknown): value is EtchApiError;
1255
1335
  */
1256
1336
  declare const ETCH_API_VERSION = "0.x";
1257
1337
 
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 };
1338
+ export { type ArrayComponentProperty, type BlockLoopBinding, type BlockPatch, type BooleanComponentProperty, type BooleanParam, type BridgeConnectOptions, 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 EtchBridgeConnection, 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",
3
+ "version": "0.6.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",