@statelyai/sdk 0.38.0 → 0.38.1

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
@@ -90,6 +90,15 @@ Use `viewMode: 'list'` on `createStatelyEmbed` to add `?view=list` to the
90
90
  iframe URL, or subscribe to `viewModeChanged` when the user switches views.
91
91
  Pass the initial `theme` or `settings.appearance.colorMode` when creating the
92
92
  embed so its loading screen uses that color mode before initialization.
93
+ The default is dark, matching the editor. Attached and mounted iframes use the
94
+ same color scheme while their document loads; `setTheme` and appearance settings
95
+ also update that frame surface.
96
+ If the initial theme is omitted, the SDK keeps the iframe hidden until the
97
+ machine loads or reports an error, so a theme supplied only to `init` cannot
98
+ flash the default theme. The surrounding host supplies the waiting surface.
99
+ Source conversion failures notify `onError` and reveal the editor's error screen.
100
+ Protocol incompatibility also restores the frame's visibility and reports the
101
+ failure to the host.
93
102
 
94
103
  Custom profiles and formats can be supplied when the embed is created. Their
95
104
  serializable manifests are sent to the iframe; detector, importer, exporter,
package/dist/embed.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./protocol-M3Zeun3o.mjs";
2
- import { c as createPendingExportManager, l as settingsWithViewMode, r as createPostMessageTransport, s as createEventRegistry, t as SDK_VERSION, u as toInitMessage } from "./version-DdcBDv8b.mjs";
2
+ import { c as createPendingExportManager, l as settingsWithViewMode, r as createPostMessageTransport, s as createEventRegistry, t as SDK_VERSION, u as toInitMessage } from "./version-IE72VxaP.mjs";
3
3
  import { EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol.mjs";
4
4
 
5
5
  //#region src/embed.ts
@@ -36,7 +36,7 @@ function buildEmbedUrl(options) {
36
36
  if (options.viewMode) url.searchParams.set("view", options.viewMode);
37
37
  const appearance = options.settings?.appearance;
38
38
  const settingsMode = appearance && typeof appearance === "object" && "colorMode" in appearance ? appearance.colorMode : void 0;
39
- const colorMode = options.theme ?? settingsMode;
39
+ const colorMode = options.theme ?? settingsMode ?? "dark";
40
40
  if (colorMode === "light" || colorMode === "dark" || colorMode === "system") url.searchParams.set("theme", colorMode);
41
41
  return url.toString();
42
42
  }
@@ -126,6 +126,7 @@ function createStatelyEmbed(options) {
126
126
  const embedUrl = buildEmbedUrl(options);
127
127
  const targetOrigin = options.origin ?? new URL(embedUrl).origin;
128
128
  let iframe = null;
129
+ let restoreIframeVisibility;
129
130
  let transport = null;
130
131
  let ownedIframe = false;
131
132
  let sourceUpdateBaseline;
@@ -238,6 +239,8 @@ function createStatelyEmbed(options) {
238
239
  if (ready.protocolVersion !== void 0) {
239
240
  if (ready.protocolVersion !== EDITOR_PROTOCOL_VERSION) {
240
241
  editorProtocolCompatible = false;
242
+ restoreIframeVisibility?.();
243
+ restoreIframeVisibility = void 0;
241
244
  const error = {
242
245
  code: "unsupported_protocol",
243
246
  message: `Editor protocol ${ready.protocolVersion} is unsupported; this SDK supports ${EDITOR_PROTOCOL_VERSION}.`
@@ -269,6 +272,8 @@ function createStatelyEmbed(options) {
269
272
  break;
270
273
  }
271
274
  case "@statelyai.loaded": {
275
+ restoreIframeVisibility?.();
276
+ restoreIframeVisibility = void 0;
272
277
  const loaded = data;
273
278
  sourceUpdateBaseline = structuredClone(loaded.graph);
274
279
  options.onLoaded?.(loaded.graph);
@@ -374,6 +379,8 @@ function createStatelyEmbed(options) {
374
379
  break;
375
380
  }
376
381
  case "@statelyai.error": {
382
+ restoreIframeVisibility?.();
383
+ restoreIframeVisibility = void 0;
377
384
  const error = data;
378
385
  const err = {
379
386
  code: error.code,
@@ -451,6 +458,23 @@ function createStatelyEmbed(options) {
451
458
  flush();
452
459
  });
453
460
  }
461
+ function applyIframeColorMode(el, mode) {
462
+ el.style.colorScheme = mode === "system" ? "light dark" : mode;
463
+ el.style.backgroundColor = "light-dark(#eff1f3, #15151d)";
464
+ }
465
+ function prepareIframe(el) {
466
+ restoreIframeVisibility?.();
467
+ restoreIframeVisibility = void 0;
468
+ applyIframeColorMode(el, new URL(embedUrl).searchParams.get("theme") ?? "dark");
469
+ const explicitMode = options.theme ?? (options.settings?.appearance)?.colorMode;
470
+ if (explicitMode !== "light" && explicitMode !== "dark" && explicitMode !== "system") {
471
+ const previous = el.style.visibility;
472
+ el.style.visibility = "hidden";
473
+ restoreIframeVisibility = () => {
474
+ el.style.visibility = previous;
475
+ };
476
+ }
477
+ }
454
478
  const embed = {
455
479
  attach(el) {
456
480
  if (destroyed) return;
@@ -461,16 +485,19 @@ function createStatelyEmbed(options) {
461
485
  });
462
486
  iframe = el;
463
487
  ownedIframe = false;
488
+ prepareIframe(el);
464
489
  el.src = embedUrl;
465
490
  setupTransport(el);
466
491
  },
467
492
  mount(container) {
468
493
  if (destroyed) throw new Error("Embed is destroyed");
469
494
  const el = document.createElement("iframe");
495
+ prepareIframe(el);
470
496
  el.src = embedUrl;
471
497
  el.style.border = "none";
472
498
  el.style.width = "100%";
473
499
  el.style.height = "100%";
500
+ el.style.display = "block";
474
501
  el.setAttribute("sandbox", "allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox");
475
502
  el.setAttribute("allow", "clipboard-read; clipboard-write");
476
503
  container.appendChild(el);
@@ -484,6 +511,8 @@ function createStatelyEmbed(options) {
484
511
  sendApiKey();
485
512
  },
486
513
  init(opts) {
514
+ const colorMode = opts.theme ?? (opts.settings?.appearance)?.colorMode;
515
+ if (iframe && (colorMode === "light" || colorMode === "dark" || colorMode === "system")) applyIframeColorMode(iframe, colorMode);
487
516
  send(toInitMessage("machine" in opts ? {
488
517
  ...opts,
489
518
  extensions: opts.extensions ?? bundledExtensions
@@ -543,12 +572,15 @@ function createStatelyEmbed(options) {
543
572
  });
544
573
  },
545
574
  setTheme(theme) {
575
+ if (iframe) applyIframeColorMode(iframe, theme);
546
576
  send({
547
577
  type: "@statelyai.setTheme",
548
578
  theme
549
579
  });
550
580
  },
551
581
  setSettings(settings) {
582
+ const mode = settings.appearance?.colorMode;
583
+ if (iframe && (mode === "light" || mode === "dark" || mode === "system")) applyIframeColorMode(iframe, mode);
552
584
  send({
553
585
  type: "@statelyai.setSettings",
554
586
  settings
@@ -606,6 +638,8 @@ function createStatelyEmbed(options) {
606
638
  exportManager.clear("Embed destroyed");
607
639
  events.clear();
608
640
  pendingMessages.length = 0;
641
+ restoreIframeVisibility?.();
642
+ restoreIframeVisibility = void 0;
609
643
  if (ownedIframe && iframe) iframe.remove();
610
644
  iframe = null;
611
645
  }
package/dist/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  import { n as StudioApiError, r as createStatelyClient, t as DEFAULT_STATELY_BASE_URL } from "./studio-uGK1kS0n.mjs";
2
2
  import { c as createInspectionRoomUrls, d as isEmbedExampleMachine, i as INSPECTION_ROOM_QUERY_PARAM, l as getInspectionRoomId, m as resolveInspectorSettings, n as EMBED_DOCUMENT_LIMITS, o as assertEmbedExamples, p as mergeInspectorSettings, r as INSPECTION_PROTOCOL_VERSION, s as createInspectionActorId, t as EMBED_DOCUMENT_LANGUAGES, u as isEmbedExample } from "./protocol-M3Zeun3o.mjs";
3
- import { i as createWebSocketTransport, r as createPostMessageTransport } from "./version-DdcBDv8b.mjs";
3
+ import { i as createWebSocketTransport, r as createPostMessageTransport } from "./version-IE72VxaP.mjs";
4
4
  import { EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol.mjs";
5
5
  import { createStatelyEmbed } from "./embed.mjs";
6
6
  import { createS3AssetUploadAdapter, createSupabaseAssetUploadAdapter } from "./assetStorage.mjs";
7
- import { n as createStatelyInspector, t as createInspector } from "./inspect-IxL93uKX.mjs";
7
+ import { n as createStatelyInspector, t as createInspector } from "./inspect-Ca_ZPcrf.mjs";
8
8
  import { createAuthorizationHeader, getCredentialToken } from "./auth.mjs";
9
9
  import { buildAuthorizeUrl, createPkcePair, discoverAuthorizationServer, discoverProtectedResource, exchangeCodeForToken, refreshToken, registerOAuthClient } from "./oauth.mjs";
10
10
  import { StatelyApiError, createStatelyApiClient, createStatelyApiUrl } from "./api.mjs";
@@ -1,5 +1,5 @@
1
1
  import { c as createInspectionRoomUrls, l as getInspectionRoomId, m as resolveInspectorSettings, p as mergeInspectorSettings, r as INSPECTION_PROTOCOL_VERSION } from "./protocol-M3Zeun3o.mjs";
2
- import { a as assertEmbedDocuments, c as createPendingExportManager, i as createWebSocketTransport, n as inspectionRuntime, o as assertEmbedPanels, s as createEventRegistry, t as SDK_VERSION } from "./version-DdcBDv8b.mjs";
2
+ import { a as assertEmbedDocuments, c as createPendingExportManager, i as createWebSocketTransport, n as inspectionRuntime, o as assertEmbedPanels, s as createEventRegistry, t as SDK_VERSION } from "./version-IE72VxaP.mjs";
3
3
 
4
4
  //#region src/openBrowser.ts
5
5
  async function openBrowser(url) {
package/dist/inspect.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./protocol-M3Zeun3o.mjs";
2
- import "./version-DdcBDv8b.mjs";
3
- import { n as createStatelyInspector, t as createInspector } from "./inspect-IxL93uKX.mjs";
2
+ import "./version-IE72VxaP.mjs";
3
+ import { n as createStatelyInspector, t as createInspector } from "./inspect-Ca_ZPcrf.mjs";
4
4
 
5
5
  export { createInspector, createStatelyInspector };
@@ -379,7 +379,7 @@ function createWebSocketTransport(options) {
379
379
 
380
380
  //#endregion
381
381
  //#region src/version.ts
382
- const SDK_VERSION = "0.38.0";
382
+ const SDK_VERSION = "0.38.1";
383
383
  function inspectionRuntime() {
384
384
  if (typeof window !== "undefined") return "browser";
385
385
  if (typeof process !== "undefined" && process.versions?.node) return "node";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statelyai/sdk",
3
- "version": "0.38.0",
3
+ "version": "0.38.1",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "stately-sdk": "./dist/bin.mjs"