@cmssy/react 19.34.1 → 19.35.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/dist/client.cjs CHANGED
@@ -109,9 +109,19 @@ function blockPaint(block) {
109
109
  if (media.length === 0) return "painted";
110
110
  return media.some((state) => state.opacity > TRANSPARENT) ? "painted" : "transparent";
111
111
  }
112
+ function settles(animation) {
113
+ if (animation.playState !== "running") return false;
114
+ const end = animation.effect?.getComputedTiming().endTime;
115
+ return typeof end === "number" && Number.isFinite(end);
116
+ }
117
+ function isAnimatingIn(block) {
118
+ if (typeof block.getAnimations !== "function") return false;
119
+ return block.getAnimations({ subtree: true }).some(settles);
120
+ }
112
121
 
113
122
  // src/bridge/use-invisible-blocks.ts
114
123
  var DWELL_MS = 1500;
124
+ var CONFIRM_MS = 3e3;
115
125
  var VISIBLE_FRACTION = 0.35;
116
126
  var SWEEP_MS = 2e3;
117
127
  function useInvisibleBlocks(enabled, blocksKey, report) {
@@ -123,6 +133,7 @@ function useInvisibleBlocks(enabled, blocksKey, report) {
123
133
  if (typeof IntersectionObserver === "undefined") return;
124
134
  const timers = /* @__PURE__ */ new Map();
125
135
  const observed = /* @__PURE__ */ new WeakSet();
136
+ const suspects = /* @__PURE__ */ new WeakSet();
126
137
  const invisible = /* @__PURE__ */ new Map();
127
138
  let reported = "";
128
139
  const flush = () => {
@@ -132,13 +143,32 @@ function useInvisibleBlocks(enabled, blocksKey, report) {
132
143
  reported = key;
133
144
  reportRef.current(blocks);
134
145
  };
146
+ const schedule = (el, delay) => {
147
+ timers.set(
148
+ el,
149
+ setTimeout(() => {
150
+ timers.delete(el);
151
+ judge(el);
152
+ }, delay)
153
+ );
154
+ };
135
155
  const judge = (el) => {
136
156
  const blockId = el.getAttribute("data-block-id");
137
157
  const blockType = el.getAttribute("data-block-type");
138
158
  if (!blockId || !blockType) return;
139
159
  const paint2 = blockPaint(el);
140
- if (paint2 === "painted") invisible.delete(blockId);
141
- else invisible.set(blockId, { blockId, blockType, reason: paint2 });
160
+ if (paint2 === "painted") {
161
+ suspects.delete(el);
162
+ invisible.delete(blockId);
163
+ flush();
164
+ return;
165
+ }
166
+ if (!suspects.has(el) || isAnimatingIn(el)) {
167
+ suspects.add(el);
168
+ schedule(el, CONFIRM_MS);
169
+ return;
170
+ }
171
+ invisible.set(blockId, { blockId, blockType, reason: paint2 });
142
172
  flush();
143
173
  };
144
174
  const observer = new IntersectionObserver(
@@ -150,16 +180,11 @@ function useInvisibleBlocks(enabled, blocksKey, report) {
150
180
  clearTimeout(pending);
151
181
  timers.delete(entry.target);
152
182
  }
183
+ suspects.delete(entry.target);
153
184
  continue;
154
185
  }
155
186
  if (pending) continue;
156
- timers.set(
157
- entry.target,
158
- setTimeout(() => {
159
- timers.delete(entry.target);
160
- judge(entry.target);
161
- }, DWELL_MS)
162
- );
187
+ schedule(entry.target, DWELL_MS);
163
188
  }
164
189
  },
165
190
  { threshold: VISIBLE_FRACTION }
package/dist/client.js CHANGED
@@ -107,9 +107,19 @@ function blockPaint(block) {
107
107
  if (media.length === 0) return "painted";
108
108
  return media.some((state) => state.opacity > TRANSPARENT) ? "painted" : "transparent";
109
109
  }
110
+ function settles(animation) {
111
+ if (animation.playState !== "running") return false;
112
+ const end = animation.effect?.getComputedTiming().endTime;
113
+ return typeof end === "number" && Number.isFinite(end);
114
+ }
115
+ function isAnimatingIn(block) {
116
+ if (typeof block.getAnimations !== "function") return false;
117
+ return block.getAnimations({ subtree: true }).some(settles);
118
+ }
110
119
 
111
120
  // src/bridge/use-invisible-blocks.ts
112
121
  var DWELL_MS = 1500;
122
+ var CONFIRM_MS = 3e3;
113
123
  var VISIBLE_FRACTION = 0.35;
114
124
  var SWEEP_MS = 2e3;
115
125
  function useInvisibleBlocks(enabled, blocksKey, report) {
@@ -121,6 +131,7 @@ function useInvisibleBlocks(enabled, blocksKey, report) {
121
131
  if (typeof IntersectionObserver === "undefined") return;
122
132
  const timers = /* @__PURE__ */ new Map();
123
133
  const observed = /* @__PURE__ */ new WeakSet();
134
+ const suspects = /* @__PURE__ */ new WeakSet();
124
135
  const invisible = /* @__PURE__ */ new Map();
125
136
  let reported = "";
126
137
  const flush = () => {
@@ -130,13 +141,32 @@ function useInvisibleBlocks(enabled, blocksKey, report) {
130
141
  reported = key;
131
142
  reportRef.current(blocks);
132
143
  };
144
+ const schedule = (el, delay) => {
145
+ timers.set(
146
+ el,
147
+ setTimeout(() => {
148
+ timers.delete(el);
149
+ judge(el);
150
+ }, delay)
151
+ );
152
+ };
133
153
  const judge = (el) => {
134
154
  const blockId = el.getAttribute("data-block-id");
135
155
  const blockType = el.getAttribute("data-block-type");
136
156
  if (!blockId || !blockType) return;
137
157
  const paint2 = blockPaint(el);
138
- if (paint2 === "painted") invisible.delete(blockId);
139
- else invisible.set(blockId, { blockId, blockType, reason: paint2 });
158
+ if (paint2 === "painted") {
159
+ suspects.delete(el);
160
+ invisible.delete(blockId);
161
+ flush();
162
+ return;
163
+ }
164
+ if (!suspects.has(el) || isAnimatingIn(el)) {
165
+ suspects.add(el);
166
+ schedule(el, CONFIRM_MS);
167
+ return;
168
+ }
169
+ invisible.set(blockId, { blockId, blockType, reason: paint2 });
140
170
  flush();
141
171
  };
142
172
  const observer = new IntersectionObserver(
@@ -148,16 +178,11 @@ function useInvisibleBlocks(enabled, blocksKey, report) {
148
178
  clearTimeout(pending);
149
179
  timers.delete(entry.target);
150
180
  }
181
+ suspects.delete(entry.target);
151
182
  continue;
152
183
  }
153
184
  if (pending) continue;
154
- timers.set(
155
- entry.target,
156
- setTimeout(() => {
157
- timers.delete(entry.target);
158
- judge(entry.target);
159
- }, DWELL_MS)
160
- );
185
+ schedule(entry.target, DWELL_MS);
161
186
  }
162
187
  },
163
188
  { threshold: VISIBLE_FRACTION }
package/dist/index.cjs CHANGED
@@ -415,6 +415,7 @@ async function resolveCmssyLayoutSlot(config, options) {
415
415
  retry,
416
416
  fetch: fetchImpl,
417
417
  layoutStore,
418
+ readByLayoutKey = false,
418
419
  onTransientLayoutFailure = "throw"
419
420
  } = options;
420
421
  const requestOptions = {
@@ -432,11 +433,26 @@ async function resolveCmssyLayoutSlot(config, options) {
432
433
  try {
433
434
  groups = await internal.readThroughLayoutStore(
434
435
  layoutStore,
435
- internal.layoutStoreKey(config, page.slug, previewSecret),
436
- () => internal.fetchLayouts(config, page.slug, {
437
- previewSecret,
438
- ...requestOptions
439
- })
436
+ internal.layoutStoreKey(config, { pageSlug: page.slug, previewSecret }),
437
+ async () => {
438
+ if (editMode || preview || !readByLayoutKey) {
439
+ return internal.fetchLayouts(config, page.slug, {
440
+ previewSecret,
441
+ ...requestOptions
442
+ });
443
+ }
444
+ const layoutKey = await internal.fetchLayoutKey(
445
+ config,
446
+ page.slug,
447
+ requestOptions
448
+ );
449
+ if (!layoutKey) return [];
450
+ return internal.readThroughLayoutStore(
451
+ layoutStore,
452
+ internal.layoutStoreKey(config, { layoutKey }),
453
+ () => internal.fetchLayoutsByKey(config, layoutKey, requestOptions)
454
+ );
455
+ }
440
456
  );
441
457
  } catch (error) {
442
458
  if (onTransientLayoutFailure !== "degrade" || !core.isTransientRequestError(error)) {
package/dist/index.d.cts CHANGED
@@ -37,6 +37,7 @@ interface ResolveCmssyLayoutSlotBase {
37
37
  retry?: RetryOption;
38
38
  fetch?: FetchLike;
39
39
  layoutStore?: CmssyLayoutStore;
40
+ readByLayoutKey?: boolean;
40
41
  onTransientLayoutFailure?: "throw" | "degrade";
41
42
  }
42
43
  type CmssyLayoutSlotLocaleSource = {
package/dist/index.d.ts CHANGED
@@ -37,6 +37,7 @@ interface ResolveCmssyLayoutSlotBase {
37
37
  retry?: RetryOption;
38
38
  fetch?: FetchLike;
39
39
  layoutStore?: CmssyLayoutStore;
40
+ readByLayoutKey?: boolean;
40
41
  onTransientLayoutFailure?: "throw" | "degrade";
41
42
  }
42
43
  type CmssyLayoutSlotLocaleSource = {
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { blocksToSchemas, isTransientRequestError, resolveEditorOrigin, verifyCmssyEditToken, CMSSY_EDIT_TOKEN_HEADER } from '@cmssy/core';
2
2
  export { CmssyRequestError, FieldType, MediaType, PROTOCOL_VERSION, createCmssyClient, defineCmssyLayout, evaluateFieldConditionGroup, fields, graphqlRequest, isFormFieldRequired, isFormFieldVisible, isProtocolCompatible, mediaAlt, mediaDuration, mediaType, mediaTypeValues, mediaUrl, mediaUrls, normalizeOrigin, parseEditorMessage, postToEditor, typedOperation, visibleFormFields } from '@cmssy/core';
3
- import { unreachableShowWhenTargets, buildBlockContext, readThroughLayoutStore, layoutStoreKey, fetchLayouts, normalizeBlockContent, asBucket, layoutRegionIds, fetchPage, resolveSiteLocales as resolveSiteLocales$1, getBlockContentForLanguage, resolveRelationContent } from '@cmssy/core/internal';
3
+ import { unreachableShowWhenTargets, buildBlockContext, readThroughLayoutStore, layoutStoreKey, fetchLayouts, fetchLayoutKey, fetchLayoutsByKey, normalizeBlockContent, asBucket, layoutRegionIds, fetchPage, resolveSiteLocales as resolveSiteLocales$1, getBlockContentForLanguage, resolveRelationContent } from '@cmssy/core/internal';
4
4
  export { buildBlockContext } from '@cmssy/core/internal';
5
5
  import { createElement } from 'react';
6
6
  import { BlockErrorBoundary } from '@cmssy/react/block-error-boundary';
@@ -415,6 +415,7 @@ async function resolveCmssyLayoutSlot(config, options) {
415
415
  retry,
416
416
  fetch: fetchImpl,
417
417
  layoutStore,
418
+ readByLayoutKey = false,
418
419
  onTransientLayoutFailure = "throw"
419
420
  } = options;
420
421
  const requestOptions = {
@@ -432,11 +433,26 @@ async function resolveCmssyLayoutSlot(config, options) {
432
433
  try {
433
434
  groups = await readThroughLayoutStore(
434
435
  layoutStore,
435
- layoutStoreKey(config, page.slug, previewSecret),
436
- () => fetchLayouts(config, page.slug, {
437
- previewSecret,
438
- ...requestOptions
439
- })
436
+ layoutStoreKey(config, { pageSlug: page.slug, previewSecret }),
437
+ async () => {
438
+ if (editMode || preview || !readByLayoutKey) {
439
+ return fetchLayouts(config, page.slug, {
440
+ previewSecret,
441
+ ...requestOptions
442
+ });
443
+ }
444
+ const layoutKey = await fetchLayoutKey(
445
+ config,
446
+ page.slug,
447
+ requestOptions
448
+ );
449
+ if (!layoutKey) return [];
450
+ return readThroughLayoutStore(
451
+ layoutStore,
452
+ layoutStoreKey(config, { layoutKey }),
453
+ () => fetchLayoutsByKey(config, layoutKey, requestOptions)
454
+ );
455
+ }
440
456
  );
441
457
  } catch (error) {
442
458
  if (onTransientLayoutFailure !== "degrade" || !isTransientRequestError(error)) {
package/dist/spa.cjs CHANGED
@@ -212,6 +212,7 @@ async function resolveCmssyLayoutSlot(config, options) {
212
212
  retry,
213
213
  fetch: fetchImpl,
214
214
  layoutStore,
215
+ readByLayoutKey = false,
215
216
  onTransientLayoutFailure = "throw"
216
217
  } = options;
217
218
  const requestOptions = {
@@ -229,11 +230,26 @@ async function resolveCmssyLayoutSlot(config, options) {
229
230
  try {
230
231
  groups = await internal.readThroughLayoutStore(
231
232
  layoutStore,
232
- internal.layoutStoreKey(config, page.slug, previewSecret),
233
- () => internal.fetchLayouts(config, page.slug, {
234
- previewSecret,
235
- ...requestOptions
236
- })
233
+ internal.layoutStoreKey(config, { pageSlug: page.slug, previewSecret }),
234
+ async () => {
235
+ if (editMode || preview || !readByLayoutKey) {
236
+ return internal.fetchLayouts(config, page.slug, {
237
+ previewSecret,
238
+ ...requestOptions
239
+ });
240
+ }
241
+ const layoutKey = await internal.fetchLayoutKey(
242
+ config,
243
+ page.slug,
244
+ requestOptions
245
+ );
246
+ if (!layoutKey) return [];
247
+ return internal.readThroughLayoutStore(
248
+ layoutStore,
249
+ internal.layoutStoreKey(config, { layoutKey }),
250
+ () => internal.fetchLayoutsByKey(config, layoutKey, requestOptions)
251
+ );
252
+ }
237
253
  );
238
254
  } catch (error) {
239
255
  if (onTransientLayoutFailure !== "degrade" || !core.isTransientRequestError(error)) {
package/dist/spa.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { useMemo, useState, useRef, useEffect, useCallback, createElement } from 'react';
3
- import { layoutRegionIds, fetchPage, buildBlockContext, readThroughLayoutStore, layoutStoreKey, fetchLayouts, normalizeBlockContent, asBucket, getBlockContentForLanguage, resolveRelationContent } from '@cmssy/core/internal';
3
+ import { layoutRegionIds, fetchPage, buildBlockContext, readThroughLayoutStore, layoutStoreKey, fetchLayouts, fetchLayoutKey, fetchLayoutsByKey, normalizeBlockContent, asBucket, getBlockContentForLanguage, resolveRelationContent } from '@cmssy/core/internal';
4
4
  import { isTransientRequestError, resolveEditorOrigin, blocksToSchemas } from '@cmssy/core';
5
5
  import { resolveSiteLocales, splitLocaleFromPath } from '@cmssy/core/internal/locale';
6
6
  import { BlockErrorBoundary } from '@cmssy/react/block-error-boundary';
@@ -210,6 +210,7 @@ async function resolveCmssyLayoutSlot(config, options) {
210
210
  retry,
211
211
  fetch: fetchImpl,
212
212
  layoutStore,
213
+ readByLayoutKey = false,
213
214
  onTransientLayoutFailure = "throw"
214
215
  } = options;
215
216
  const requestOptions = {
@@ -227,11 +228,26 @@ async function resolveCmssyLayoutSlot(config, options) {
227
228
  try {
228
229
  groups = await readThroughLayoutStore(
229
230
  layoutStore,
230
- layoutStoreKey(config, page.slug, previewSecret),
231
- () => fetchLayouts(config, page.slug, {
232
- previewSecret,
233
- ...requestOptions
234
- })
231
+ layoutStoreKey(config, { pageSlug: page.slug, previewSecret }),
232
+ async () => {
233
+ if (editMode || preview || !readByLayoutKey) {
234
+ return fetchLayouts(config, page.slug, {
235
+ previewSecret,
236
+ ...requestOptions
237
+ });
238
+ }
239
+ const layoutKey = await fetchLayoutKey(
240
+ config,
241
+ page.slug,
242
+ requestOptions
243
+ );
244
+ if (!layoutKey) return [];
245
+ return readThroughLayoutStore(
246
+ layoutStore,
247
+ layoutStoreKey(config, { layoutKey }),
248
+ () => fetchLayoutsByKey(config, layoutKey, requestOptions)
249
+ );
250
+ }
235
251
  );
236
252
  } catch (error) {
237
253
  if (onTransientLayoutFailure !== "degrade" || !isTransientRequestError(error)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/react",
3
- "version": "19.34.1",
3
+ "version": "19.35.1",
4
4
  "engines": {
5
5
  "node": ">=20"
6
6
  },
@@ -110,7 +110,7 @@
110
110
  },
111
111
  "dependencies": {
112
112
  "@cmssy/types": "0.77.0",
113
- "@cmssy/core": "19.34.1"
113
+ "@cmssy/core": "19.35.1"
114
114
  },
115
115
  "scripts": {
116
116
  "build": "tsup",