@loadmap/react 0.23.0 → 0.24.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/README.md CHANGED
@@ -80,7 +80,9 @@ its width.
80
80
 
81
81
  A `.loadmap` text draws with `<LoadmapSource source={text} name="shop.loadmap" />` from `@loadmap/react/source`: it
82
82
  compiles when the text changes, passes on the options the definition declares (your props win), and while the text
83
- does not compile shows its diagnostics as `loadmap check` prints them. It is the one entry that loads the compiler.
83
+ does not compile shows its diagnostics as `loadmap check` prints them. An edit keeps the values the board shows (the
84
+ load, the scenario, the controls) where they still fit; `initial` is for the first version, and a `key` per file
85
+ starts another file from its own defaults. It is the one entry that loads the compiler.
84
86
 
85
87
  A scenario, a story step or a control that changes the structure (more pods, more brokers) moves the diagram to it:
86
88
  what stays moves to its new place, what is new fades in. `transition={1.2}` sets the seconds it takes (default 0.8);
package/dist/source.d.ts CHANGED
@@ -11,6 +11,8 @@ export interface LoadmapSourceProps extends Omit<LoadmapProps<any>, 'model' | 'v
11
11
  /**
12
12
  * A `.loadmap` text drawn as `<Loadmap>`, with the options it declares (the page's props win; its `assumptions` come
13
13
  * first). While the text does not compile: its diagnostics, as `loadmap check` prints them, above the last version
14
- * that did. A separate entry: a page built from code never loads the compiler.
14
+ * that did. A new version keeps the values the board shows (the load, a scenario's, the controls) where they still
15
+ * fit it, as the editor does; `initial` is for the first. A separate entry: a page built from code never loads the
16
+ * compiler.
15
17
  */
16
- export declare function LoadmapSource({ source, name, functions, theme, assumptions, ...props }: LoadmapSourceProps): import("react").JSX.Element;
18
+ export declare function LoadmapSource({ source, name, functions, theme, assumptions, initial, ref, ...props }: LoadmapSourceProps): import("react").JSX.Element;
package/dist/source.js CHANGED
@@ -1,15 +1,17 @@
1
1
  import { a as usePageTheme, c as injectStyles, n as Loadmap } from "./Loadmap-BjtmzxzK.js";
2
- import { useEffect, useMemo, useRef } from "react";
2
+ import { useCallback, useEffect, useMemo, useRef } from "react";
3
3
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
- import { compile, formatDiagnostic } from "@loadmap/dsl";
4
+ import { compile, formatDiagnostic, sharedValues } from "@loadmap/dsl";
5
5
  import { fingerprint, pageOptions } from "@loadmap/dsl/internal";
6
6
  // src/source.tsx
7
7
  /**
8
8
  * A `.loadmap` text drawn as `<Loadmap>`, with the options it declares (the page's props win; its `assumptions` come
9
9
  * first). While the text does not compile: its diagnostics, as `loadmap check` prints them, above the last version
10
- * that did. A separate entry: a page built from code never loads the compiler.
10
+ * that did. A new version keeps the values the board shows (the load, a scenario's, the controls) where they still
11
+ * fit it, as the editor does; `initial` is for the first. A separate entry: a page built from code never loads the
12
+ * compiler.
11
13
  */
12
- function LoadmapSource({ source, name = "input.loadmap", functions, theme, assumptions, ...props }) {
14
+ function LoadmapSource({ source, name = "input.loadmap", functions, theme, assumptions, initial, ref, ...props }) {
13
15
  const fns = useRef(functions);
14
16
  fns.current = functions;
15
17
  const key = useMemo(() => fingerprint(source), [source]);
@@ -20,6 +22,19 @@ function LoadmapSource({ source, name = "input.loadmap", functions, theme, assum
20
22
  const good = useRef(null);
21
23
  if (compiled.r.ok && compiled.r.definition) good.current = compiled.r.definition;
22
24
  const def = good.current;
25
+ const board = useRef(null);
26
+ const drawn = useRef({
27
+ def: null,
28
+ values: initial ?? {}
29
+ });
30
+ if (def !== drawn.current.def) {
31
+ if (drawn.current.def && board.current) drawn.current.values = board.current.values();
32
+ drawn.current.def = def;
33
+ }
34
+ const handle = useCallback((h) => {
35
+ board.current = h;
36
+ pass(ref, h);
37
+ }, [ref]);
23
38
  const set = Object.fromEntries(Object.entries(props).filter(([, v]) => v !== void 0));
24
39
  const lines = def && [...assumptions ?? [], ...def.options.assumptions];
25
40
  return /* @__PURE__ */ jsxs(Fragment, { children: [!compiled.r.ok && /* @__PURE__ */ jsx(Problems, {
@@ -31,10 +46,17 @@ function LoadmapSource({ source, name = "input.loadmap", functions, theme, assum
31
46
  view: def.view,
32
47
  ...pageOptions(def.options),
33
48
  ...set,
49
+ ref: handle,
50
+ initial: sharedValues(def.model, drawn.current.values),
34
51
  theme,
35
52
  ...lines?.length ? { assumptions: lines } : {}
36
53
  })] });
37
54
  }
55
+ /** Hands the board to the page's own ref, an object or a function. */
56
+ function pass(ref, h) {
57
+ if (typeof ref === "function") ref(h);
58
+ else if (ref) ref.current = h;
59
+ }
38
60
  function Problems({ theme, stale, children }) {
39
61
  const look = usePageTheme(theme);
40
62
  useEffect(() => injectStyles(), []);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loadmap/react",
3
- "version": "0.23.0",
3
+ "version": "0.24.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",
@@ -35,10 +35,10 @@
35
35
  "dist"
36
36
  ],
37
37
  "dependencies": {
38
- "@loadmap/core": "0.23.0",
39
- "@loadmap/dsl": "0.23.0",
40
- "@loadmap/sim": "0.23.0",
41
- "@loadmap/layout": "0.23.0",
38
+ "@loadmap/core": "0.24.0",
39
+ "@loadmap/dsl": "0.24.0",
40
+ "@loadmap/sim": "0.24.0",
41
+ "@loadmap/layout": "0.24.0",
42
42
  "elkjs": "^0.12.1"
43
43
  },
44
44
  "peerDependencies": {