@decocms/blocks 8.0.0 → 8.1.0-next.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.
Files changed (220) hide show
  1. package/bin/deco.js +13 -0
  2. package/package.json +32 -82
  3. package/src/index.ts +35 -8
  4. package/src/protocol/assets.ts +124 -0
  5. package/src/protocol/canonical.ts +7 -0
  6. package/src/protocol/ciphertext.ts +6 -0
  7. package/src/protocol/client.ts +170 -0
  8. package/src/protocol/conformance/cases/assets.ts +81 -0
  9. package/src/protocol/conformance/cases/guards.ts +314 -0
  10. package/src/protocol/conformance/cases/reads.ts +168 -0
  11. package/src/protocol/conformance/cases/types.ts +9 -0
  12. package/src/protocol/conformance/cases/wire.ts +138 -0
  13. package/src/protocol/conformance/cases/writes.ts +345 -0
  14. package/src/protocol/conformance/contentHashFixtures.ts +79 -0
  15. package/src/protocol/conformance/context.ts +222 -0
  16. package/src/protocol/conformance/index.ts +140 -0
  17. package/src/protocol/errors.ts +142 -0
  18. package/src/protocol/index.ts +39 -0
  19. package/src/protocol/keys.ts +279 -0
  20. package/src/protocol/params.ts +67 -0
  21. package/src/protocol/secrets.ts +231 -0
  22. package/src/protocol/server/assets.ts +119 -0
  23. package/src/protocol/server/auth.ts +49 -0
  24. package/src/protocol/server/bodyCache.ts +84 -0
  25. package/src/protocol/server/content.ts +175 -0
  26. package/src/protocol/server/core.ts +112 -0
  27. package/src/protocol/server/handler.ts +102 -0
  28. package/src/protocol/server/http.ts +139 -0
  29. package/src/protocol/server/index.ts +11 -0
  30. package/src/protocol/server/methods/apply.ts +341 -0
  31. package/src/protocol/server/methods/read.ts +156 -0
  32. package/src/protocol/server/rpc.ts +136 -0
  33. package/src/protocol/storage/fs/hash.ts +21 -0
  34. package/src/protocol/storage/fs/index.ts +338 -0
  35. package/src/protocol/storage/fs/lock.ts +68 -0
  36. package/src/protocol/storage/fs/transaction.ts +183 -0
  37. package/src/protocol/storage/fs/unsupported.ts +15 -0
  38. package/src/protocol/storage/memory.ts +238 -0
  39. package/src/protocol/storage.ts +182 -0
  40. package/src/protocol/types.ts +172 -0
  41. package/src/v8/analytics.ts +50 -0
  42. package/src/v8/background.ts +107 -0
  43. package/src/v8/builtins/data.ts +23 -0
  44. package/src/v8/builtins/index.ts +26 -0
  45. package/src/v8/builtins/lazy.ts +23 -0
  46. package/src/v8/builtins/legacy.ts +65 -0
  47. package/src/v8/builtins/matchers.ts +31 -0
  48. package/src/v8/builtins/multivariate.ts +25 -0
  49. package/src/v8/builtins/secret.ts +82 -0
  50. package/src/v8/canonical.ts +117 -0
  51. package/src/v8/ciphertext.ts +158 -0
  52. package/src/v8/cli/builtins.ts +20 -0
  53. package/src/v8/cli/check/index.ts +774 -0
  54. package/src/v8/cli/check/messages.ts +168 -0
  55. package/src/v8/cli/content.ts +287 -0
  56. package/src/v8/cli/index.ts +17 -0
  57. package/src/v8/cli/log.ts +18 -0
  58. package/src/v8/cli/main.ts +12 -0
  59. package/src/v8/cli/root.ts +66 -0
  60. package/src/v8/cli/run.ts +236 -0
  61. package/src/v8/cli/schema/builtinSchemas.ts +236 -0
  62. package/src/v8/cli/schema/generate.ts +507 -0
  63. package/src/v8/cli/schema/index.ts +63 -0
  64. package/src/v8/cli/schema/tsProgram.ts +497 -0
  65. package/src/v8/cli/schema/typeToSchema.ts +689 -0
  66. package/src/v8/cli/serve/server.ts +303 -0
  67. package/src/v8/cli/watch.ts +86 -0
  68. package/src/v8/client.ts +147 -0
  69. package/src/v8/cms.ts +237 -0
  70. package/src/v8/content.ts +195 -0
  71. package/src/v8/draft.ts +136 -0
  72. package/src/v8/errors.ts +59 -0
  73. package/src/v8/fetch.ts +133 -0
  74. package/src/v8/identity.ts +65 -0
  75. package/src/v8/index.ts +39 -0
  76. package/src/v8/json.ts +74 -0
  77. package/src/v8/matchRoute.ts +204 -0
  78. package/src/v8/remoteLoader.ts +282 -0
  79. package/src/v8/resolver.ts +278 -0
  80. package/src/v8/secrets.ts +17 -0
  81. package/src/v8/telemetry.ts +533 -0
  82. package/src/v8/types.ts +240 -0
  83. package/src/cms/applySectionConventions.ts +0 -124
  84. package/src/cms/blockSource.test.ts +0 -76
  85. package/src/cms/blockSource.ts +0 -191
  86. package/src/cms/client.browserBundle.test.ts +0 -44
  87. package/src/cms/client.ts +0 -80
  88. package/src/cms/draftSource.test.ts +0 -343
  89. package/src/cms/draftSource.ts +0 -362
  90. package/src/cms/index.ts +0 -151
  91. package/src/cms/layoutCacheRace.test.ts +0 -181
  92. package/src/cms/loadDecofileDirectory.test.ts +0 -109
  93. package/src/cms/loadDecofileDirectory.ts +0 -89
  94. package/src/cms/loader.test.ts +0 -200
  95. package/src/cms/loader.ts +0 -304
  96. package/src/cms/registry.test.ts +0 -110
  97. package/src/cms/registry.ts +0 -242
  98. package/src/cms/resolve.test.ts +0 -980
  99. package/src/cms/resolve.ts +0 -2282
  100. package/src/cms/schema.test.ts +0 -356
  101. package/src/cms/schema.ts +0 -1215
  102. package/src/cms/sectionLoaderContext.test.ts +0 -111
  103. package/src/cms/sectionLoaderContext.ts +0 -113
  104. package/src/cms/sectionLoaders.test.ts +0 -533
  105. package/src/cms/sectionLoaders.ts +0 -636
  106. package/src/cms/sectionMixins.test.ts +0 -167
  107. package/src/cms/sectionMixins.ts +0 -153
  108. package/src/cms/stickyFlags.test.ts +0 -117
  109. package/src/flags/audience.ts +0 -56
  110. package/src/flags/everyone.ts +0 -29
  111. package/src/flags/flag.ts +0 -15
  112. package/src/flags/flags.test.ts +0 -148
  113. package/src/flags/multivariate/image.ts +0 -11
  114. package/src/flags/multivariate/message.ts +0 -11
  115. package/src/flags/multivariate/page.ts +0 -16
  116. package/src/flags/multivariate/section.ts +0 -16
  117. package/src/flags/multivariate.ts +0 -1
  118. package/src/flags/types.ts +0 -59
  119. package/src/flags/utils/multivariate.ts +0 -20
  120. package/src/hooks/Image.test.ts +0 -100
  121. package/src/hooks/Image.tsx +0 -250
  122. package/src/hooks/JsonLd.tsx +0 -353
  123. package/src/hooks/LazySection.tsx +0 -121
  124. package/src/hooks/LiveControls.tsx +0 -122
  125. package/src/hooks/Picture.tsx +0 -127
  126. package/src/hooks/RenderSection.test.tsx +0 -81
  127. package/src/hooks/RenderSection.tsx +0 -91
  128. package/src/hooks/SectionErrorFallback.tsx +0 -97
  129. package/src/hooks/index.ts +0 -30
  130. package/src/matchers/builtins.test.ts +0 -318
  131. package/src/matchers/builtins.ts +0 -459
  132. package/src/matchers/countryNames.ts +0 -104
  133. package/src/matchers/override.test.ts +0 -205
  134. package/src/matchers/override.ts +0 -136
  135. package/src/matchers/posthog.ts +0 -154
  136. package/src/middleware/decoState.ts +0 -55
  137. package/src/middleware/healthMetrics.ts +0 -133
  138. package/src/middleware/hydrationContext.test.ts +0 -61
  139. package/src/middleware/hydrationContext.ts +0 -79
  140. package/src/middleware/index.ts +0 -88
  141. package/src/middleware/liveness.ts +0 -21
  142. package/src/middleware/observability.test.ts +0 -242
  143. package/src/middleware/observability.ts +0 -643
  144. package/src/middleware/validateSection.test.ts +0 -147
  145. package/src/middleware/validateSection.ts +0 -100
  146. package/src/sdk/abTesting.test.ts +0 -326
  147. package/src/sdk/abTesting.ts +0 -499
  148. package/src/sdk/analytics.ts +0 -77
  149. package/src/sdk/cacheHeaders.test.ts +0 -115
  150. package/src/sdk/cacheHeaders.ts +0 -433
  151. package/src/sdk/cachedLoader.test.ts +0 -122
  152. package/src/sdk/cachedLoader.ts +0 -503
  153. package/src/sdk/cachedLoaderModule.test.ts +0 -209
  154. package/src/sdk/clx.ts +0 -5
  155. package/src/sdk/cn.test.ts +0 -34
  156. package/src/sdk/cn.ts +0 -28
  157. package/src/sdk/composite.test.ts +0 -121
  158. package/src/sdk/composite.ts +0 -114
  159. package/src/sdk/cookie.test.ts +0 -108
  160. package/src/sdk/cookie.ts +0 -129
  161. package/src/sdk/crypto.ts +0 -185
  162. package/src/sdk/csp.ts +0 -59
  163. package/src/sdk/detectDevice.ts +0 -45
  164. package/src/sdk/djb2.ts +0 -20
  165. package/src/sdk/encoding.test.ts +0 -71
  166. package/src/sdk/encoding.ts +0 -47
  167. package/src/sdk/env.test.ts +0 -33
  168. package/src/sdk/env.ts +0 -54
  169. package/src/sdk/flags.test.ts +0 -91
  170. package/src/sdk/flags.ts +0 -108
  171. package/src/sdk/http.test.ts +0 -71
  172. package/src/sdk/http.ts +0 -124
  173. package/src/sdk/index.ts +0 -90
  174. package/src/sdk/inflightTimeout.test.ts +0 -35
  175. package/src/sdk/inflightTimeout.ts +0 -53
  176. package/src/sdk/instrumentedFetch.test.ts +0 -559
  177. package/src/sdk/instrumentedFetch.ts +0 -339
  178. package/src/sdk/invoke.test.ts +0 -115
  179. package/src/sdk/invoke.ts +0 -298
  180. package/src/sdk/logger.test.ts +0 -432
  181. package/src/sdk/logger.ts +0 -304
  182. package/src/sdk/mergeCacheControl.ts +0 -150
  183. package/src/sdk/normalizeUrls.ts +0 -91
  184. package/src/sdk/observability.ts +0 -109
  185. package/src/sdk/otel.test.ts +0 -526
  186. package/src/sdk/otel.ts +0 -1012
  187. package/src/sdk/otelAdapters/clickhouseCollector.ts +0 -65
  188. package/src/sdk/otelAdapters.test.ts +0 -89
  189. package/src/sdk/otelAdapters.ts +0 -144
  190. package/src/sdk/otelHttpLog.test.ts +0 -457
  191. package/src/sdk/otelHttpLog.ts +0 -419
  192. package/src/sdk/otelHttpMeter.test.ts +0 -292
  193. package/src/sdk/otelHttpMeter.ts +0 -506
  194. package/src/sdk/otelHttpTracer.test.ts +0 -474
  195. package/src/sdk/otelHttpTracer.ts +0 -543
  196. package/src/sdk/redirects.ts +0 -228
  197. package/src/sdk/requestContext.ts +0 -281
  198. package/src/sdk/requestContextStorage.browser.test.ts +0 -29
  199. package/src/sdk/requestContextStorage.browser.ts +0 -43
  200. package/src/sdk/requestContextStorage.ts +0 -35
  201. package/src/sdk/retry.ts +0 -45
  202. package/src/sdk/serverTimings.ts +0 -68
  203. package/src/sdk/signal.ts +0 -42
  204. package/src/sdk/sitemap.ts +0 -160
  205. package/src/sdk/urlRedaction.test.ts +0 -73
  206. package/src/sdk/urlRedaction.ts +0 -82
  207. package/src/sdk/urlUtils.ts +0 -134
  208. package/src/sdk/useDevice.test.ts +0 -130
  209. package/src/sdk/useDevice.ts +0 -89
  210. package/src/sdk/useDeviceContext.tsx +0 -108
  211. package/src/sdk/useId.ts +0 -7
  212. package/src/sdk/useScript.test.ts +0 -128
  213. package/src/sdk/useScript.ts +0 -210
  214. package/src/sdk/useSuggestions.test.ts +0 -230
  215. package/src/sdk/useSuggestions.ts +0 -188
  216. package/src/sdk/wrapCaughtErrors.ts +0 -107
  217. package/src/setup.ts +0 -120
  218. package/src/types/index.ts +0 -53
  219. package/src/types/widgets.ts +0 -14
  220. package/tsconfig.json +0 -7
@@ -1,353 +0,0 @@
1
- /**
2
- * SEO JSON-LD structured data components.
3
- *
4
- * Generates JSON-LD script tags for Product (PDP), ProductList (PLP),
5
- * and BreadcrumbList schemas. Compatible with Google's Rich Results
6
- * requirements.
7
- *
8
- * @example
9
- * ```tsx
10
- * import { ProductJsonLd, PLPJsonLd, BreadcrumbJsonLd } from "@decocms/blocks/hooks";
11
- *
12
- * // In a PDP route
13
- * <ProductJsonLd product={product} />
14
- *
15
- * // In a PLP route
16
- * <PLPJsonLd page={productListingPage} />
17
- *
18
- * // Anywhere with breadcrumbs
19
- * <BreadcrumbJsonLd breadcrumb={breadcrumbList} />
20
- * ```
21
- *
22
- * Type note: originally these components imported `Product`,
23
- * `ProductListingPage`, `BreadcrumbList`, etc. from apps-start's
24
- * commerce types module (now `@decocms/apps-commerce/types`).
25
- * `@decocms/blocks` must not depend on any `apps-*` package (one-way
26
- * dependency rule: `apps-*` depends on `blocks`, never the reverse), so
27
- * that import can't carry over as-is. Each function here only reads a
28
- * small, flat subset of the full schema.org Product/Offer/ListItem
29
- * graph (the original code already didn't fully trust the nominal
30
- * `Product.offers` type either — see the `as Offer[] | AggregateOffer`
31
- * casts it used). The types below are local, minimal, structural
32
- * equivalents of just that subset: any commerce `Product` /
33
- * `ProductListingPage` / `BreadcrumbList` value is a structural
34
- * superset and can be passed in directly without a cast.
35
- */
36
-
37
- // -------------------------------------------------------------------------
38
- // Minimal structural types (see file header for why these aren't imported
39
- // from @decocms/apps-commerce/types)
40
- // -------------------------------------------------------------------------
41
-
42
- interface JsonLdOffer {
43
- price?: number;
44
- priceCurrency?: string;
45
- availability?: string;
46
- seller?: string;
47
- priceValidUntil?: string;
48
- }
49
-
50
- interface JsonLdAggregateOffer {
51
- "@type"?: string;
52
- lowPrice?: number;
53
- priceCurrency?: string;
54
- }
55
-
56
- interface JsonLdPriceSpecification {
57
- priceType?: string;
58
- price?: number;
59
- }
60
-
61
- interface JsonLdAggregateRating {
62
- ratingValue?: number;
63
- reviewCount?: number;
64
- ratingCount?: number;
65
- bestRating?: number;
66
- worstRating?: number;
67
- }
68
-
69
- interface JsonLdImage {
70
- url?: string;
71
- }
72
-
73
- interface JsonLdBrand {
74
- name?: string;
75
- }
76
-
77
- export interface JsonLdProduct {
78
- name?: string;
79
- description?: string;
80
- url?: string;
81
- sku?: string;
82
- productID?: string;
83
- gtin?: string;
84
- brand?: JsonLdBrand | null;
85
- image?: JsonLdImage[] | null;
86
- offers?: JsonLdOffer[] | JsonLdAggregateOffer;
87
- aggregateRating?: JsonLdAggregateRating;
88
- }
89
-
90
- interface JsonLdSeo {
91
- canonical?: string;
92
- title?: string;
93
- description?: string;
94
- }
95
-
96
- export interface JsonLdProductListingPage {
97
- products?: JsonLdProduct[];
98
- seo?: JsonLdSeo | null;
99
- }
100
-
101
- interface JsonLdListItem {
102
- position?: number;
103
- name?: string;
104
- item?: string;
105
- url?: string;
106
- }
107
-
108
- export interface JsonLdBreadcrumbList {
109
- itemListElement?: JsonLdListItem[];
110
- }
111
-
112
- // -------------------------------------------------------------------------
113
- // JSON-LD script renderer
114
- // -------------------------------------------------------------------------
115
-
116
- function JsonLdScript({ data }: { data: unknown }) {
117
- return (
118
- <script type="application/ld+json" dangerouslySetInnerHTML={{ __html: JSON.stringify(data) }} />
119
- );
120
- }
121
-
122
- // -------------------------------------------------------------------------
123
- // Product (PDP)
124
- // -------------------------------------------------------------------------
125
-
126
- export interface ProductJsonLdProps {
127
- product: JsonLdProduct;
128
- /** Override the canonical URL. Defaults to product.url. */
129
- url?: string;
130
- }
131
-
132
- function getBestOffer(offers: JsonLdOffer[] | JsonLdAggregateOffer | undefined): {
133
- price?: number;
134
- priceCurrency?: string;
135
- availability?: string;
136
- seller?: string;
137
- priceValidUntil?: string;
138
- } {
139
- if (!offers) return {};
140
-
141
- if ("@type" in offers && offers["@type"] === "AggregateOffer") {
142
- const agg = offers as JsonLdAggregateOffer;
143
- return {
144
- price: agg.lowPrice,
145
- priceCurrency: agg.priceCurrency,
146
- };
147
- }
148
-
149
- if (Array.isArray(offers) && offers.length > 0) {
150
- const best = offers.reduce((a, b) => {
151
- const ap = a.price ?? Infinity;
152
- const bp = b.price ?? Infinity;
153
- return ap <= bp ? a : b;
154
- });
155
- return {
156
- price: best.price,
157
- priceCurrency: best.priceCurrency,
158
- availability: best.availability,
159
- seller: best.seller,
160
- priceValidUntil: best.priceValidUntil,
161
- };
162
- }
163
-
164
- return {};
165
- }
166
-
167
- function _getListPrice(priceSpec: JsonLdPriceSpecification[] | undefined): number | undefined {
168
- if (!priceSpec) return undefined;
169
- const list = priceSpec.find(
170
- (p) =>
171
- p.priceType === "https://schema.org/ListPrice" || p.priceType === "https://schema.org/SRP",
172
- );
173
- return list?.price;
174
- }
175
-
176
- export function ProductJsonLd({ product, url }: ProductJsonLdProps) {
177
- const offer = getBestOffer(product.offers);
178
- const images = product.image?.map((img) => img.url).filter(Boolean) ?? [];
179
- const rating = product.aggregateRating;
180
-
181
- const data: Record<string, unknown> = {
182
- "@context": "https://schema.org",
183
- "@type": "Product",
184
- name: product.name,
185
- description: product.description,
186
- image: images.length === 1 ? images[0] : images,
187
- url: url ?? product.url,
188
- sku: product.sku,
189
- productID: product.productID,
190
- brand: product.brand ? { "@type": "Brand", name: product.brand.name } : undefined,
191
- gtin: product.gtin,
192
- };
193
-
194
- if (offer.price != null) {
195
- data.offers = {
196
- "@type": "Offer",
197
- price: offer.price,
198
- priceCurrency: offer.priceCurrency ?? "BRL",
199
- availability: offer.availability ?? "https://schema.org/InStock",
200
- seller: offer.seller ? { "@type": "Organization", name: offer.seller } : undefined,
201
- priceValidUntil: offer.priceValidUntil,
202
- url: url ?? product.url,
203
- };
204
- }
205
-
206
- if (rating?.ratingValue) {
207
- data.aggregateRating = {
208
- "@type": "AggregateRating",
209
- ratingValue: rating.ratingValue,
210
- reviewCount: rating.reviewCount ?? rating.ratingCount ?? 0,
211
- bestRating: rating.bestRating ?? 5,
212
- worstRating: rating.worstRating ?? 1,
213
- };
214
- }
215
-
216
- return <JsonLdScript data={data} />;
217
- }
218
-
219
- // -------------------------------------------------------------------------
220
- // Product Listing Page (PLP)
221
- // -------------------------------------------------------------------------
222
-
223
- export interface PLPJsonLdProps {
224
- page: JsonLdProductListingPage;
225
- /** Override the canonical URL. */
226
- url?: string;
227
- }
228
-
229
- export function PLPJsonLd({ page, url }: PLPJsonLdProps) {
230
- const items = (page.products ?? []).map((product, index) => {
231
- const offer = getBestOffer(product.offers);
232
- return {
233
- "@type": "ListItem" as const,
234
- position: index + 1,
235
- item: {
236
- "@type": "Product" as const,
237
- name: product.name,
238
- url: product.url,
239
- image: product.image?.[0]?.url,
240
- offers:
241
- offer.price != null
242
- ? {
243
- "@type": "Offer" as const,
244
- price: offer.price,
245
- priceCurrency: offer.priceCurrency ?? "BRL",
246
- availability: offer.availability ?? "https://schema.org/InStock",
247
- }
248
- : undefined,
249
- },
250
- };
251
- });
252
-
253
- const data = {
254
- "@context": "https://schema.org",
255
- "@type": "ItemList",
256
- url: url ?? page.seo?.canonical,
257
- name: page.seo?.title,
258
- description: page.seo?.description,
259
- numberOfItems: page.products?.length ?? 0,
260
- itemListElement: items,
261
- };
262
-
263
- return <JsonLdScript data={data} />;
264
- }
265
-
266
- // -------------------------------------------------------------------------
267
- // Breadcrumb
268
- // -------------------------------------------------------------------------
269
-
270
- export interface BreadcrumbJsonLdProps {
271
- breadcrumb: JsonLdBreadcrumbList;
272
- }
273
-
274
- export function BreadcrumbJsonLd({ breadcrumb }: BreadcrumbJsonLdProps) {
275
- const items = (breadcrumb.itemListElement ?? []).map((item, index) => {
276
- return {
277
- "@type": "ListItem" as const,
278
- position: item.position ?? index + 1,
279
- name: item.name,
280
- item: item.item ?? item.url,
281
- };
282
- });
283
-
284
- const data = {
285
- "@context": "https://schema.org",
286
- "@type": "BreadcrumbList",
287
- itemListElement: items,
288
- numberOfItems: items.length,
289
- };
290
-
291
- return <JsonLdScript data={data} />;
292
- }
293
-
294
- // -------------------------------------------------------------------------
295
- // Generic SEO Meta
296
- // -------------------------------------------------------------------------
297
-
298
- export interface SeoMetaProps {
299
- title?: string;
300
- description?: string;
301
- canonical?: string;
302
- image?: string;
303
- noIndex?: boolean;
304
- type?: "website" | "article" | "product";
305
- siteName?: string;
306
- }
307
-
308
- /**
309
- * Generates Open Graph and Twitter Card meta tags.
310
- *
311
- * Use this in combination with TanStack Router's `meta()` route option,
312
- * or render directly in the component tree (tags will be hoisted to <head>
313
- * by React's built-in behavior with TanStack Start).
314
- */
315
- export function seoMetaTags(props: SeoMetaProps): Array<Record<string, string>> {
316
- const tags: Array<Record<string, string>> = [];
317
-
318
- if (props.title) {
319
- tags.push({ title: props.title });
320
- tags.push({ property: "og:title", content: props.title });
321
- tags.push({ name: "twitter:title", content: props.title });
322
- }
323
-
324
- if (props.description) {
325
- tags.push({ name: "description", content: props.description });
326
- tags.push({ property: "og:description", content: props.description });
327
- tags.push({ name: "twitter:description", content: props.description });
328
- }
329
-
330
- if (props.canonical) {
331
- tags.push({ property: "og:url", content: props.canonical });
332
- }
333
-
334
- if (props.image) {
335
- tags.push({ property: "og:image", content: props.image });
336
- tags.push({ name: "twitter:image", content: props.image });
337
- tags.push({ name: "twitter:card", content: "summary_large_image" });
338
- }
339
-
340
- if (props.type) {
341
- tags.push({ property: "og:type", content: props.type });
342
- }
343
-
344
- if (props.siteName) {
345
- tags.push({ property: "og:site_name", content: props.siteName });
346
- }
347
-
348
- if (props.noIndex) {
349
- tags.push({ name: "robots", content: "noindex, nofollow" });
350
- }
351
-
352
- return tags;
353
- }
@@ -1,121 +0,0 @@
1
- "use client";
2
-
3
- /**
4
- * LazySection -- Intersection Observer-based deferred rendering.
5
- *
6
- * Wraps section content and defers rendering until the element scrolls
7
- * into view. Uses IntersectionObserver for zero-JS-cost detection and
8
- * renders a lightweight placeholder until the content is needed.
9
- *
10
- * For SSR: the placeholder is rendered server-side. On hydration,
11
- * the observer is set up and content loads when visible.
12
- *
13
- * @example
14
- * ```tsx
15
- * <LazySection fallback={<div style={{ height: 400 }} />}>
16
- * <HeavyProductCarousel products={products} />
17
- * </LazySection>
18
- * ```
19
- *
20
- * `"use client"` added by Phase 2 Task 9 (@decocms/nextjs's next-smoke
21
- * fixture): this file uses `useEffect`/`useRef`/`useState`, which Next's App
22
- * Router statically rejects in any file reachable from a Server Component's
23
- * module graph unless the file itself declares the client boundary. Neither
24
- * `@decocms/tanstack` (Vite, no RSC directive enforcement) nor this
25
- * package's Vitest/jsdom unit tests caught this — `@decocms/nextjs` is the
26
- * first consumer to go through Next's real RSC-aware webpack build.
27
- */
28
-
29
- import { type ReactNode, useEffect, useRef, useState } from "react";
30
-
31
- export interface LazySectionProps {
32
- children: ReactNode;
33
- /**
34
- * Content shown before the section scrolls into view.
35
- * Should have a fixed height to prevent layout shifts.
36
- */
37
- fallback?: ReactNode;
38
- /**
39
- * IntersectionObserver rootMargin.
40
- * Positive values trigger loading before the element is visible.
41
- * @default "200px"
42
- */
43
- rootMargin?: string;
44
- /**
45
- * Minimum height for the wrapper div (prevents CLS).
46
- * Applied as CSS min-height.
47
- */
48
- minHeight?: string | number;
49
- /**
50
- * CSS class for the wrapper div.
51
- */
52
- className?: string;
53
- /**
54
- * If true, render the content immediately (bypass lazy loading).
55
- * Useful for sections above the fold.
56
- * @default false
57
- */
58
- eager?: boolean;
59
- }
60
-
61
- export function LazySection({
62
- children,
63
- fallback,
64
- rootMargin = "200px",
65
- minHeight,
66
- className,
67
- eager = false,
68
- }: LazySectionProps) {
69
- const [isVisible, setVisible] = useState(eager);
70
- const ref = useRef<HTMLDivElement>(null);
71
-
72
- useEffect(() => {
73
- if (eager || isVisible) return;
74
-
75
- const element = ref.current;
76
- if (!element) return;
77
-
78
- if (typeof IntersectionObserver === "undefined") {
79
- setVisible(true);
80
- return;
81
- }
82
-
83
- const observer = new IntersectionObserver(
84
- ([entry]) => {
85
- if (entry?.isIntersecting) {
86
- setVisible(true);
87
- observer.disconnect();
88
- }
89
- },
90
- { rootMargin },
91
- );
92
-
93
- observer.observe(element);
94
- return () => observer.disconnect();
95
- }, [eager, isVisible, rootMargin]);
96
-
97
- const style: React.CSSProperties | undefined = minHeight
98
- ? { minHeight: typeof minHeight === "number" ? `${minHeight}px` : minHeight }
99
- : undefined;
100
-
101
- return (
102
- <div ref={ref} className={className} style={style}>
103
- {isVisible ? children : (fallback ?? null)}
104
- </div>
105
- );
106
- }
107
-
108
- /**
109
- * Determine if a section index is "below the fold" and should be lazy-loaded.
110
- *
111
- * Used by DecoPageRenderer to auto-wrap distant sections.
112
- *
113
- * @param index - Zero-based section index on the page
114
- * @param foldThreshold - Sections at or above this index are below the fold.
115
- * Defaults to `Infinity` (nothing below the fold), matching the framework
116
- * default where the admin ⚡ toggle — not position — drives deferral.
117
- * @default foldThreshold = Infinity
118
- */
119
- export function isBelowFold(index: number, foldThreshold = Infinity): boolean {
120
- return index >= foldThreshold;
121
- }
@@ -1,122 +0,0 @@
1
- import React from "react";
2
-
3
- interface LiveControlsProps {
4
- site?: string;
5
- page?: { id?: string; pathTemplate?: string };
6
- flags?: any[];
7
- }
8
-
9
- /**
10
- * LiveControls bridges the deco admin (parent window) with the storefront (iframe).
11
- *
12
- * Mirrors production behavior (apps/website/components/_Controls.tsx):
13
- * 1. Injects __DECO_STATE for the admin to read
14
- * 2. Listens for postMessage events from the admin (inject scripts, scroll, rerender)
15
- * 3. "." opens admin in same tab, Ctrl/Cmd+"." opens in new tab, Ctrl+Shift+E also works
16
- */
17
- export function LiveControls({ site, page, flags }: LiveControlsProps) {
18
- return (
19
- <>
20
- <script
21
- id="__DECO_STATE"
22
- type="application/json"
23
- dangerouslySetInnerHTML={{
24
- __html: JSON.stringify({
25
- page: page || {},
26
- site: { name: site || "storefront" },
27
- flags: flags || [],
28
- }),
29
- }}
30
- />
31
- <LiveControlsScript />
32
- </>
33
- );
34
- }
35
-
36
- function LiveControlsScript() {
37
- const script = `
38
- (function() {
39
- if (window.__DECO_LIVE_CONTROLS__) return;
40
- window.__DECO_LIVE_CONTROLS__ = true;
41
-
42
- var TRUSTED_ORIGINS = ["https://deco.cx", "https://admin.deco.cx", "https://play.deco.cx"];
43
- function isTrustedOrigin(origin) {
44
- return TRUSTED_ORIGINS.indexOf(origin) !== -1 ||
45
- (origin.startsWith("https://") && origin.endsWith(".deco.cx")) ||
46
- origin === window.location.origin;
47
- }
48
-
49
- var LIVE = JSON.parse(document.getElementById("__DECO_STATE")?.textContent || "{}");
50
- window.LIVE = { ...window.LIVE, ...LIVE };
51
-
52
- window.addEventListener("message", function(event) {
53
- if (!isTrustedOrigin(event.origin)) return;
54
-
55
- var data = event.data;
56
- if (!data || typeof data !== "object") return;
57
-
58
- switch (data.type) {
59
- case "editor::inject":
60
- if (data.args && data.args.script) {
61
- try { eval(data.args.script); } catch(e) { console.error("[deco] inject error:", e); }
62
- }
63
- break;
64
-
65
- case "scrollToComponent":
66
- var el = document.querySelector('[data-manifest-key="' + CSS.escape(data.args?.id || "") + '"]');
67
- if (!el) el = document.getElementById(data.args?.id);
68
- if (el) el.scrollIntoView({ behavior: "smooth", block: "center" });
69
- break;
70
-
71
- case "DOMInspector":
72
- break;
73
-
74
- case "editor::rerender":
75
- if (data.args?.url) {
76
- try {
77
- var targetUrl = new URL(data.args.url, window.location.origin);
78
- if (targetUrl.origin === window.location.origin) {
79
- window.location.href = targetUrl.href;
80
- }
81
- } catch(e) {}
82
- }
83
- break;
84
- }
85
- });
86
-
87
- if (window.self === window.top) {
88
- document.body.addEventListener("keydown", function(e) {
89
- if (e.target !== document.body) return;
90
- if (e.defaultPrevented) return;
91
-
92
- if (
93
- (e.ctrlKey && e.shiftKey && e.key === "E") ||
94
- e.key === "."
95
- ) {
96
- e.preventDefault();
97
- e.stopPropagation();
98
-
99
- var siteName = (window.LIVE.site && window.LIVE.site.name) || window.LIVE.site || "storefront";
100
- var pageId = (window.LIVE.page && window.LIVE.page.id) || "";
101
- var pathTemplate = (window.LIVE.page && window.LIVE.page.pathTemplate) || "/*";
102
-
103
- var href = new URL("/choose-editor", "https://admin.deco.cx");
104
- href.searchParams.set("site", siteName);
105
- href.searchParams.set("domain", window.location.origin);
106
- if (pageId) href.searchParams.set("pageId", pageId);
107
- href.searchParams.set("path", encodeURIComponent(window.location.pathname + window.location.search));
108
- href.searchParams.set("pathTemplate", encodeURIComponent(pathTemplate));
109
-
110
- if ((e.ctrlKey || e.metaKey) && e.key === ".") {
111
- window.open(href.toString(), "_blank");
112
- return;
113
- }
114
- window.location.href = href.toString();
115
- }
116
- });
117
- }
118
- })();
119
- `;
120
-
121
- return <script type="module" dangerouslySetInnerHTML={{ __html: script }} />;
122
- }