@weasel-js/forge 1.8.1 → 1.9.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.
@@ -1,10 +1,10 @@
1
1
  import { parseRoute, paramsToKnobs, knobPaths, sameKnob, knobsToParams, formatRoute, PLAYHEAD_PARAM, reservedParams } from '../chunk-CJX3W5HY.js';
2
- import { isIndexId, indexId, libraryOf, indexEntries, schemaFromDescription, LibraryBadge, openChannel, IndexPage } from '../chunk-JQD3MVUQ.js';
2
+ import { isIndexId, indexId, libraryOf, indexEntries, schemaFromDescription, LibraryBadge, openChannel, IndexPage } from '../chunk-JVRHBI3V.js';
3
3
  import { isGallery } from '../chunk-WEQSLPKT.js';
4
- import { useTrialFrame, createTrialFrames, createTrialClocks, StoryGlobalsContext, TrialFramesContext, TrialClocksContext, StoryTrial, useCssOverrides, useTrialClock, TrialHost } from '../chunk-GHTVXHNJ.js';
5
- export { StoryGlobalsContext, StoryTrial, TrialFramesContext, TrialHost, useTrialFrame } from '../chunk-GHTVXHNJ.js';
4
+ import { useTrialFrame, createTrialFrames, createTrialClocks, StoryGlobalsContext, TrialFramesContext, TrialClocksContext, StoryTrial, useCssOverrides, useNearViewport, IN_VIEW_MARGIN, useTrialClock, TrialHost } from '../chunk-QN3HJQXZ.js';
5
+ export { StoryGlobalsContext, StoryTrial, TrialFramesContext, TrialHost, useTrialFrame } from '../chunk-QN3HJQXZ.js';
6
6
  import { labGlobals, withGlobals, followApp, storyConfig, GLOBALS_KEY, effectiveGlobals, PLAYHEAD_KEY, labOptions, isGlobalsPath } from '../chunk-NI5FYQHW.js';
7
- import { loadStories, indexRenderOf } from '../chunk-5N4YP5HS.js';
7
+ import { loadStories, indexRenderOf } from '../chunk-Q2EZXJFE.js';
8
8
  import '../chunk-L5XM5VKB.js';
9
9
  import '../chunk-HRGPFQBW.js';
10
10
  import '../chunk-MGQWCPYE.js';
@@ -1446,24 +1446,6 @@ var readyKey = (ready) => stableStringify({ schema: ready.schema, layout: ready.
1446
1446
  var START_TIMEOUT_MS = 1e4;
1447
1447
  var HELLO_TIMEOUT_MS = 3e4;
1448
1448
  var requests = 0;
1449
- var IN_VIEW_MARGIN = "50%";
1450
- function useInView(ref) {
1451
- const [inView, setInView] = useState(true);
1452
- useEffect(() => {
1453
- const el = ref.current;
1454
- if (!el || typeof IntersectionObserver === "undefined") return;
1455
- const observer = new IntersectionObserver(
1456
- (entries) => {
1457
- const last = entries.at(-1);
1458
- if (last) setInView(last.isIntersecting);
1459
- },
1460
- { rootMargin: IN_VIEW_MARGIN }
1461
- );
1462
- observer.observe(el);
1463
- return () => observer.disconnect();
1464
- }, [ref]);
1465
- return inView;
1466
- }
1467
1449
  function closeLink(link) {
1468
1450
  if (!link.current) return;
1469
1451
  clearTimeout(link.current.timer);
@@ -1495,7 +1477,7 @@ function FrameView(props) {
1495
1477
  const iframeRef = useRef(null);
1496
1478
  const hostRef = useRef(null);
1497
1479
  const slotRef = useRef(null);
1498
- const inView = useInView(hostRef);
1480
+ const inView = useNearViewport(hostRef, IN_VIEW_MARGIN);
1499
1481
  const link = useRef(null);
1500
1482
  const latest = useLatest({ ...props, globals, overrides, pool, lab, title });
1501
1483
  const [fault, setFault] = useState(null);
@@ -1726,6 +1708,7 @@ function storyInstrument(options) {
1726
1708
  globals
1727
1709
  );
1728
1710
  const descriptionKey = ready ? readyKey(ready) : null;
1711
+ const viewport = ready ? ready.viewport : entry.viewport;
1729
1712
  return {
1730
1713
  name: entry.id,
1731
1714
  title: breadcrumb(entry.title, entry.name),
@@ -1743,7 +1726,8 @@ function storyInstrument(options) {
1743
1726
  ctx
1744
1727
  }
1745
1728
  ),
1746
- ...ready?.viewport ? { stage: { size: { width: ready.viewport.width, height: ready.viewport.height } } } : {}
1729
+ // Taken from the index until the frame reports, so the trial does not move the frame into a stage and reload it.
1730
+ ...viewport ? { stage: { size: { width: viewport.width, height: viewport.height } } } : {}
1747
1731
  };
1748
1732
  }
1749
1733
 
@@ -1766,13 +1750,16 @@ function useStoryRegistry(index, options) {
1766
1750
  return new Map(prev).set(entry.id, ready);
1767
1751
  });
1768
1752
  }, []);
1769
- useEffect(() => {
1753
+ const indexIds = JSON.stringify(index.map((entry) => entry.id));
1754
+ const [prunedFor, setPrunedFor] = useState(indexIds);
1755
+ if (prunedFor !== indexIds) {
1756
+ setPrunedFor(indexIds);
1770
1757
  const ids = new Set(index.map((entry) => entry.id));
1771
1758
  setReadies((prev) => pruned(prev, ids));
1772
1759
  setLoaded((prev) => pruned(prev, ids));
1773
1760
  setFaults((prev) => pruned(prev, ids));
1774
1761
  setRevisions((prev) => pruned(prev, ids));
1775
- }, [index]);
1762
+ }
1776
1763
  const imports = useRef(/* @__PURE__ */ new Map());
1777
1764
  const live = useLatest({ index, importers, setup, load });
1778
1765
  const importOf = useCallback((file) => {