@juo/blocks 1.1.0 → 1.2.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/dist/core.js CHANGED
@@ -1,8 +1,8 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import { c as createContext, d, w, E, u } from "./theme-state-DMyDKxtl.js";
5
- import { B, C, a, D, S, T, b, e, f, g, h, i, j, k, l, m, n, o, p, r, s, q, t, v } from "./theme-state-DMyDKxtl.js";
4
+ import { c as createContext, d, w, r as registerBlock, E, u } from "./theme-state-DMyDKxtl.js";
5
+ import { B, C, a, D, S, T, b, e, f, g, h, i, j, k, l, m, n, o, p, s, q, t, v } from "./theme-state-DMyDKxtl.js";
6
6
  import { T as T2, W, c, a as a2, b as b2, g as g2, h as h2 } from "./juo-workflow-BvTgGZQj.js";
7
7
  function createState() {
8
8
  const discountCode = d(null);
@@ -72,6 +72,73 @@ function createState() {
72
72
  };
73
73
  }
74
74
  const StateContext = createContext("state");
75
+ function isLocalhostOrigin(origin) {
76
+ try {
77
+ const url = new URL(origin);
78
+ return ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
79
+ } catch {
80
+ return false;
81
+ }
82
+ }
83
+ function isLocalhostUrl(url) {
84
+ try {
85
+ const parsed = new URL(url);
86
+ return ["localhost", "127.0.0.1", "[::1]"].includes(parsed.hostname);
87
+ } catch {
88
+ return false;
89
+ }
90
+ }
91
+ function waitForDevBlocksUrl(timeout = 5e3) {
92
+ return new Promise((resolve) => {
93
+ const timer = setTimeout(() => {
94
+ window.removeEventListener("message", handler);
95
+ resolve(null);
96
+ }, timeout);
97
+ function handler(event) {
98
+ var _a, _b, _c;
99
+ if (!isLocalhostOrigin(event.origin)) return;
100
+ if (((_a = event.data) == null ? void 0 : _a.type) !== "PROVIDE_DEV_BLOCKS_URL") return;
101
+ const url = (_c = (_b = event.data) == null ? void 0 : _b.payload) == null ? void 0 : _c.url;
102
+ if (typeof url !== "string" || !isLocalhostUrl(url)) return;
103
+ clearTimeout(timer);
104
+ window.removeEventListener("message", handler);
105
+ resolve(url);
106
+ }
107
+ window.addEventListener("message", handler);
108
+ window.parent.postMessage(
109
+ { type: "PREVIEW_READY", timestamp: Date.now() },
110
+ "*"
111
+ );
112
+ });
113
+ }
114
+ async function loadBlockRegistry(options = {}) {
115
+ const { distributedRegistryUrl } = options;
116
+ if (distributedRegistryUrl) {
117
+ await import(
118
+ /* @vite-ignore */
119
+ distributedRegistryUrl
120
+ ).then((module) => {
121
+ if (typeof module !== "object" || module == null) {
122
+ console.warn("Distributed registry module is invalid");
123
+ return;
124
+ }
125
+ if ("registerBlocks" in module && typeof module.registerBlocks === "function") {
126
+ module.registerBlocks();
127
+ } else {
128
+ Object.entries(module).forEach(([_, item]) => {
129
+ if (typeof item === "object" && item != null) {
130
+ registerBlock(item);
131
+ }
132
+ });
133
+ }
134
+ }).catch(
135
+ (err) => console.warn(
136
+ `Distributed registry ${distributedRegistryUrl} not available`,
137
+ err
138
+ )
139
+ );
140
+ }
141
+ }
75
142
  const PARAMS = {
76
143
  DELETGATED_TOKEN: "delegated-token",
77
144
  REDIRECT_TO: "redirect-to",
@@ -1206,13 +1273,15 @@ export {
1206
1273
  h2 as hasDefaultBlockForAction,
1207
1274
  m as indexOverrides,
1208
1275
  n as injectContext,
1276
+ loadBlockRegistry,
1209
1277
  loginService,
1210
1278
  o as onRegisterBlock,
1211
1279
  p as provideContext,
1212
- r as registerBlock,
1280
+ registerBlock,
1213
1281
  s as serializeBlocks,
1214
1282
  d as signal,
1215
1283
  q as subscribeContext,
1216
1284
  t as untracked,
1285
+ waitForDevBlocksUrl,
1217
1286
  v as withWrapper
1218
1287
  };
package/dist/main.d.ts CHANGED
@@ -4,6 +4,7 @@ export { ThemeStateContext, createThemeState, indexOverrides, type TranslationCa
4
4
  export { TranslationContext, createTranslationService, type TranslationServiceOptions, type TranslationService, } from './translation';
5
5
  export { ContextRequestEvent, ContextProvideEvent, type ContextCallback, createContext, injectContext, provideContext, subscribeContext, type ContextType, type UnknownContext, } from './context';
6
6
  export { StateContext, createState } from './state';
7
+ export { waitForDevBlocksUrl, loadBlockRegistry } from './registry';
7
8
  export * from './utils';
8
9
  export * from './services';
9
10
  export * from './flows';
@@ -1 +1 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,KAAK,EACL,aAAa,EACb,eAAe,EACf,eAAe,EACf,aAAa,EACb,WAAW,EACX,YAAY,GACb,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,mBAAmB,EACnB,2BAA2B,EAC3B,6BAA6B,EAC7B,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAClB,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,EACf,eAAe,GAChB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACd,qBAAqB,GACtB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,KAAK,yBAAyB,EAC9B,KAAK,kBAAkB,GACxB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,KAAK,eAAe,EACpB,aAAa,EACb,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,KAAK,WAAW,EAChB,KAAK,cAAc,GACpB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEpD,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AAExB,OAAO,EACL,MAAM,EACN,MAAM,EACN,MAAM,EACN,QAAQ,EACR,SAAS,GACV,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,KAAK,EACL,aAAa,EACb,eAAe,EACf,eAAe,EACf,aAAa,EACb,WAAW,EACX,YAAY,GACb,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,mBAAmB,EACnB,2BAA2B,EAC3B,6BAA6B,EAC7B,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAClB,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,EACf,eAAe,GAChB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACd,qBAAqB,GACtB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,KAAK,yBAAyB,EAC9B,KAAK,kBAAkB,GACxB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,KAAK,eAAe,EACpB,aAAa,EACb,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,KAAK,WAAW,EAChB,KAAK,cAAc,GACpB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEpD,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpE,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AAExB,OAAO,EACL,MAAM,EACN,MAAM,EACN,MAAM,EACN,QAAQ,EACR,SAAS,GACV,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Sends PREVIEW_READY to the parent window and waits for a PROVIDE_DEV_BLOCKS_URL
3
+ * response containing a validated localhost URL.
4
+ *
5
+ * Used by the theme when running inside the standalone blocks editor iframe,
6
+ * where there is no server to inject an import map override.
7
+ *
8
+ * Returns the URL or null if the timeout elapses first.
9
+ */
10
+ export declare function waitForDevBlocksUrl(timeout?: number): Promise<string | null>;
11
+ /**
12
+ * Loads the distributed block registry from the given URL.
13
+ *
14
+ * In dev/preview mode the server injects an import map override that
15
+ * redirects the store-specific registry URL to the local dev server, so
16
+ * this function does not need to know about dev mode — it simply imports
17
+ * the URL and the browser resolves it via the import map.
18
+ */
19
+ export declare function loadBlockRegistry(options?: {
20
+ distributedRegistryUrl?: string;
21
+ }): Promise<void>;
22
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAoBA;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,SAAO,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAwB1E;AAED;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,GAAE;IACP,sBAAsB,CAAC,EAAE,MAAM,CAAC;CAC5B,GACL,OAAO,CAAC,IAAI,CAAC,CA+Bf"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@juo/blocks",
3
3
  "private": false,
4
- "version": "1.1.0",
4
+ "version": "1.2.0",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"