@loadmap/react 0.42.0 → 0.43.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.
@@ -343,7 +343,9 @@ interface LoadmapOptions<P> extends SimOptions {
343
343
  /**
344
344
  * The subsystems drawn closed at first, each as one box that stands for everything inside it, by the ids the view
345
345
  * gives them. The reader opens one with a click on it and closes one with a click on its name; a story step says
346
- * its own (`closed` in the step). Default none.
346
+ * its own (`closed` in the step). Default none. What the reader opened and closed holds, by id, across a new `model`
347
+ * and `view` (the text edited); a subsystem this list changes later follows the list. Another definition altogether
348
+ * takes a `key` of its own.
347
349
  */
348
350
  closed?: readonly string[];
349
351
  /**
@@ -89,7 +89,7 @@ function covered(size, bars, panel, panels = true) {
89
89
  };
90
90
  }
91
91
  // src/Diagram.tsx
92
- const Detail = lazy(() => import("./later-_c1UnFld.js").then((m) => ({ default: m.Detail })));
92
+ const Detail = lazy(() => import("./later-DEyKXK9p.js").then((m) => ({ default: m.Detail })));
93
93
  /**
94
94
  * What draws the subsystems (frames.tsx): their frames, and what a closed one's box says and does. It comes with the
95
95
  * first view that has a subsystem, before that view is laid out, so a page without subsystems never loads it and a
@@ -2177,7 +2177,7 @@ function VerdictLine({ lm, verdict = true, extra = 0, open, why = true, assumpti
2177
2177
  ] });
2178
2178
  }
2179
2179
  // src/frame.tsx
2180
- const Body = lazy(() => import("./framePanels-BL9_bQ8A.js").then((m) => ({ default: m.FramePanelBody })));
2180
+ const Body = lazy(() => import("./framePanels-8jyTYFiO.js").then((m) => ({ default: m.FramePanelBody })));
2181
2181
  /** A frame's panels, in the order of their tabs: one opens at a time. */
2182
2182
  const FRAME_PANELS = [
2183
2183
  "limits",
@@ -3049,6 +3049,9 @@ const FOLDS = [
3049
3049
  2,
3050
3050
  3
3051
3051
  ];
3052
+ /** A page that closes no subsystem. */
3053
+ const NONE = [];
3054
+ const sameIds = (a, b) => a === b || a.length === b.length && a.every((id, i) => id === b[i]);
3052
3055
  /** Stands for a room that is still to come. */
3053
3056
  const DUE = {
3054
3057
  w: 0,
@@ -3056,8 +3059,39 @@ const DUE = {
3056
3059
  };
3057
3060
  /** The state behind a loadmap: values, the model's evaluation, the layout and the engine. */
3058
3061
  function useLoadmap(model, whole, o = {}) {
3059
- const [shut, setShut] = useState(null);
3060
- const closed = shut?.view === whole ? shut.ids : o.closed ?? [];
3062
+ const [stepState, setStepState] = useState({
3063
+ model,
3064
+ i: null
3065
+ });
3066
+ const step = stepState.model === model && stepState.i != null && stepState.i < model.story.length ? stepState.i : null;
3067
+ const [turned, setTurned] = useState(null);
3068
+ const own = o.closed ?? NONE;
3069
+ const ownRef = useRef(own);
3070
+ ownRef.current = own;
3071
+ let kept = turned;
3072
+ if (kept && !sameIds(kept.own, own)) {
3073
+ const was = kept.own;
3074
+ const stays = (id) => was.includes(id) === own.includes(id);
3075
+ kept = {
3076
+ ...kept,
3077
+ own,
3078
+ open: kept.open.filter(stays),
3079
+ shut: kept.shut.filter(stays)
3080
+ };
3081
+ setTurned(kept);
3082
+ }
3083
+ const turn = kept && !(kept.story && step == null) ? kept : null;
3084
+ const closed = turn ? [...own.filter((id) => !turn.open.includes(id)), ...turn.shut.filter((id) => !own.includes(id))] : own;
3085
+ /** These drawn closed and every other one open, as what it changes of the page's own; null is the page's own. */
3086
+ const setTurn = useCallback((ids, story) => {
3087
+ const page = ownRef.current;
3088
+ setTurned(ids && {
3089
+ own: page,
3090
+ open: page.filter((id) => !ids.includes(id)),
3091
+ shut: ids.filter((id) => !page.includes(id)),
3092
+ story
3093
+ });
3094
+ }, []);
3061
3095
  const [close, setClose] = useState(null);
3062
3096
  useEffect(() => {
3063
3097
  let live = true;
@@ -3069,10 +3103,7 @@ function useLoadmap(model, whole, o = {}) {
3069
3103
  }, [whole]);
3070
3104
  const unready = !close && Object.keys(whole.def.subsystems ?? {}).length > 0;
3071
3105
  const view = close && closed.length ? close(whole, closed) : whole;
3072
- const setClosed = useCallback((ids) => setShut({
3073
- view: whole,
3074
- ids
3075
- }), [whole]);
3106
+ const setClosed = useCallback((ids) => setTurn(ids, false), [setTurn]);
3076
3107
  const init = () => ({
3077
3108
  ...model.defaults(),
3078
3109
  ...o.initial
@@ -3263,11 +3294,6 @@ function useLoadmap(model, whole, o = {}) {
3263
3294
  const s = model.scenarios.find((x) => x.label === label);
3264
3295
  if (s) setValues(s.values);
3265
3296
  }, [model, setValues]);
3266
- const [stepState, setStepState] = useState({
3267
- model,
3268
- i: null
3269
- });
3270
- const step = stepState.model === model && stepState.i != null && stepState.i < model.story.length ? stepState.i : null;
3271
3297
  const show = useCallback((i) => {
3272
3298
  const st = i == null ? void 0 : model.story[i];
3273
3299
  if (st) apply(st.values);
@@ -3277,15 +3303,12 @@ function useLoadmap(model, whole, o = {}) {
3277
3303
  model,
3278
3304
  i: st ? i : null
3279
3305
  });
3280
- setShut(st?.closed ? {
3281
- view: whole,
3282
- ids: st.closed
3283
- } : null);
3306
+ setTurn(st?.closed ?? null, true);
3284
3307
  }, [
3285
3308
  model,
3286
3309
  apply,
3287
3310
  engine,
3288
- whole
3311
+ setTurn
3289
3312
  ]);
3290
3313
  const setStep = useCallback((i) => {
3291
3314
  stop();
@@ -1,6 +1,6 @@
1
- import { w as Legend } from "./Loadmap-CM8HshXp.js";
2
- import { a as Verdict, i as Meters, n as Controls, r as Limits, t as Assumptions } from "./panels-CemD3oVS.js";
3
- import { n as HeadroomChart, t as Compare } from "./scenarios-D7DDcwS5.js";
1
+ import { w as Legend } from "./Loadmap-UvoLoTLT.js";
2
+ import { a as Verdict, i as Meters, n as Controls, r as Limits, t as Assumptions } from "./panels-DVlqE2Dj.js";
3
+ import { n as HeadroomChart, t as Compare } from "./scenarios-CFSzYWOU.js";
4
4
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
5
  // src/framePanels.tsx
6
6
  /**
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as useLoadmap, a as LoadmapProps, b as Engine, c as handleOf, d as Diagram, f as DiagramProps, g as LoadmapOptions, h as LoadmapController, i as LoadmapPanel, l as panelsOf, m as FullScreenMode, n as Loadmap, o as LoadmapRoot, p as Chrome, r as LoadmapHandle, s as Theme, t as LOADMAP_PANELS, u as usePageTheme, v as Cue, y as Dot } from "./Loadmap-CyxcmVoc.js";
1
+ import { _ as useLoadmap, a as LoadmapProps, b as Engine, c as handleOf, d as Diagram, f as DiagramProps, g as LoadmapOptions, h as LoadmapController, i as LoadmapPanel, l as panelsOf, m as FullScreenMode, n as Loadmap, o as LoadmapRoot, p as Chrome, r as LoadmapHandle, s as Theme, t as LOADMAP_PANELS, u as usePageTheme, v as Cue, y as Dot } from "./Loadmap-D6Yrp2jI.js";
2
2
  import { Comparison, Model } from "@loadmap/core";
3
3
  import { fitLinear } from "@loadmap/core/calibrate";
4
4
  import { compact, fmt, multiple, pct, secs } from "@loadmap/core/format";
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { C as Diagram, S as injectStyles, T as CANVAS, _ as workerElk, a as panelsOf, b as useCanvasSize, c as LoadBar, i as handleOf, l as LoadRange, n as Loadmap, o as usePageTheme, p as scenarioColor, r as LoadmapRoot, s as useLoadmap, t as LOADMAP_PANELS, u as Scenarios, v as Canvas, x as LOADMAP_CSS, y as useCanvasPanels } from "./Loadmap-CM8HshXp.js";
2
- import { a as Verdict, i as Meters, n as Controls, r as Limits, t as Assumptions } from "./panels-CemD3oVS.js";
3
- import { n as HeadroomChart, r as useComparison, t as Compare } from "./scenarios-D7DDcwS5.js";
1
+ import { C as Diagram, S as injectStyles, T as CANVAS, _ as workerElk, a as panelsOf, b as useCanvasSize, c as LoadBar, i as handleOf, l as LoadRange, n as Loadmap, o as usePageTheme, p as scenarioColor, r as LoadmapRoot, s as useLoadmap, t as LOADMAP_PANELS, u as Scenarios, v as Canvas, x as LOADMAP_CSS, y as useCanvasPanels } from "./Loadmap-UvoLoTLT.js";
2
+ import { a as Verdict, i as Meters, n as Controls, r as Limits, t as Assumptions } from "./panels-DVlqE2Dj.js";
3
+ import { n as HeadroomChart, r as useComparison, t as Compare } from "./scenarios-CFSzYWOU.js";
4
4
  import { t as Story } from "./story-mK-TEB6j.js";
5
5
  import { fitLinear } from "@loadmap/core/calibrate";
6
6
  import { compact, fmt, multiple, pct, secs } from "@loadmap/core/format";
@@ -1,6 +1,6 @@
1
1
  import { g as rankLabels, r as boxComponent } from "./camera-RqbxjjVv.js";
2
- import { f as plusMinus, p as scenarioColor } from "./Loadmap-CM8HshXp.js";
3
- import { r as useComparison } from "./scenarios-D7DDcwS5.js";
2
+ import { f as plusMinus, p as scenarioColor } from "./Loadmap-UvoLoTLT.js";
3
+ import { r as useComparison } from "./scenarios-CFSzYWOU.js";
4
4
  import { reach } from "@loadmap/core";
5
5
  import { compact, fmt, multiple, multiples, pct } from "@loadmap/core/format";
6
6
  import { useEffect, useLayoutEffect, useRef } from "react";
@@ -1,4 +1,4 @@
1
- import { d as isOn, f as plusMinus, l as LoadRange } from "./Loadmap-CM8HshXp.js";
1
+ import { d as isOn, f as plusMinus, l as LoadRange } from "./Loadmap-UvoLoTLT.js";
2
2
  import { sourceText } from "@loadmap/core";
3
3
  import { compact, duration, fmt, multiple, multiples, pct, secs } from "@loadmap/core/format";
4
4
  import { useEffect, useState } from "react";
@@ -1,4 +1,4 @@
1
- import { g as whenRange, h as when, m as useSize, p as scenarioColor } from "./Loadmap-CM8HshXp.js";
1
+ import { g as whenRange, h as when, m as useSize, p as scenarioColor } from "./Loadmap-UvoLoTLT.js";
2
2
  import { compare, headroom } from "@loadmap/core";
3
3
  import { fmt, multiple, multiples, pct } from "@loadmap/core/format";
4
4
  import { useId, useLayoutEffect, useMemo, useRef, useState } from "react";
package/dist/source.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as LoadmapProps } from "./Loadmap-CyxcmVoc.js";
1
+ import { a as LoadmapProps } from "./Loadmap-D6Yrp2jI.js";
2
2
  import { CompileOptions } from "@loadmap/dsl";
3
3
  export interface LoadmapSourceProps extends Omit<LoadmapProps<any>, 'model' | 'view'> {
4
4
  /** The `.loadmap` text. Compiled again when its tokens change: spaces, line breaks and comments change nothing. */
package/dist/source.js CHANGED
@@ -1,4 +1,4 @@
1
- import { S as injectStyles, n as Loadmap, o as usePageTheme } from "./Loadmap-CM8HshXp.js";
1
+ import { S as injectStyles, n as Loadmap, o as usePageTheme } from "./Loadmap-UvoLoTLT.js";
2
2
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
3
3
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
4
  import { compile, formatDiagnostic, loadCatalogFor, loadedCatalog, needsCatalog, sharedValues } from "@loadmap/dsl";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loadmap/react",
3
- "version": "0.42.0",
3
+ "version": "0.43.0",
4
4
  "description": "Interactive capacity models for React: an architecture diagram with moving dots, the limits ranked, the verdict, scenarios and headroom.",
5
5
  "keywords": [
6
6
  "loadmap",
@@ -39,10 +39,10 @@
39
39
  "dist"
40
40
  ],
41
41
  "dependencies": {
42
- "@loadmap/core": "0.42.0",
43
- "@loadmap/dsl": "0.42.0",
44
- "@loadmap/sim": "0.42.0",
45
- "@loadmap/layout": "0.42.0",
42
+ "@loadmap/core": "0.43.0",
43
+ "@loadmap/dsl": "0.43.0",
44
+ "@loadmap/sim": "0.43.0",
45
+ "@loadmap/layout": "0.43.0",
46
46
  "elkjs": "^0.12.1"
47
47
  },
48
48
  "peerDependencies": {