@loadmap/react 0.33.0 → 0.34.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/dist/source.d.ts CHANGED
@@ -7,6 +7,13 @@ export interface LoadmapSourceProps extends Omit<LoadmapProps<any>, 'model' | 'v
7
7
  name?: string;
8
8
  /** A host's own functions for the formulas, as `compile(…, { functions })` takes them; read when the text compiles. */
9
9
  functions?: CompileOptions['functions'];
10
+ /**
11
+ * The other files of a definition written in several, by their path from the project root: its parts and libraries,
12
+ * and for a part or a variant its model. The component fetches nothing: what is not here is an error in the text.
13
+ */
14
+ files?: Readonly<Record<string, string>>;
15
+ /** This text's own path among them, from the project root (`models/checkout.loadmap`). */
16
+ path?: string;
10
17
  }
11
18
  /**
12
19
  * A `.loadmap` text drawn as `<Loadmap>`, with the options it declares (the page's props win; its `assumptions` come
@@ -15,6 +22,6 @@ export interface LoadmapSourceProps extends Omit<LoadmapProps<any>, 'model' | 'v
15
22
  * fit it, as the editor does; `initial` is for the first. A separate entry: a page built from code never loads the
16
23
  * compiler.
17
24
  */
18
- export declare function LoadmapSource({ source, name, functions, theme, assumptions, initial, ref, ...props }: LoadmapSourceProps): import("react").JSX.Element;
25
+ export declare function LoadmapSource({ source, name, functions, files, path, theme, assumptions, initial, ref, ...props }: LoadmapSourceProps): import("react").JSX.Element;
19
26
  /** True while a text with a `published` statement waits for the catalog, which loads once, on the first such text. */
20
27
  export declare function useCatalog(source: string): boolean;
package/dist/source.js CHANGED
@@ -11,14 +11,29 @@ import { fingerprint, pageOptions } from "@loadmap/dsl/internal";
11
11
  * fit it, as the editor does; `initial` is for the first. A separate entry: a page built from code never loads the
12
12
  * compiler.
13
13
  */
14
- function LoadmapSource({ source, name = "input.loadmap", functions, theme, assumptions, initial, ref, ...props }) {
14
+ function LoadmapSource({ source, name = "input.loadmap", functions, files, path, theme, assumptions, initial, ref, ...props }) {
15
15
  const fns = useRef(functions);
16
16
  fns.current = functions;
17
- const key = useMemo(() => fingerprint(source), [source]);
18
- const waiting = useCatalog(source);
17
+ const others = files ? Object.keys(files).sort() : [];
18
+ const texts = [source, ...others.map((p) => files[p])];
19
+ const key = useMemo(() => [
20
+ ...texts.map(fingerprint),
21
+ path ?? "",
22
+ ...others
23
+ ].join("\n"), [
24
+ path,
25
+ source,
26
+ files
27
+ ]);
28
+ const waiting = useCatalog(useMemo(() => texts.join("\n"), [key]));
19
29
  const compiled = useMemo(() => waiting ? null : {
20
30
  source,
21
- r: compile(source, fns.current ? { functions: fns.current } : {})
31
+ files,
32
+ r: compile(source, {
33
+ ...fns.current && { functions: fns.current },
34
+ ...files && { files },
35
+ ...path != null && { path }
36
+ })
22
37
  }, [key, waiting]);
23
38
  const good = useRef(null);
24
39
  if (compiled?.r.ok && compiled.r.definition) good.current = compiled.r.definition;
@@ -41,7 +56,7 @@ function LoadmapSource({ source, name = "input.loadmap", functions, theme, assum
41
56
  return /* @__PURE__ */ jsxs(Fragment, { children: [compiled && !compiled.r.ok && /* @__PURE__ */ jsx(Problems, {
42
57
  theme,
43
58
  stale: def != null,
44
- children: compiled.r.diagnostics.map((d) => formatDiagnostic(d, compiled.source, name)).join("\n")
59
+ children: compiled.r.diagnostics.map((d) => d.file == null ? formatDiagnostic(d, compiled.source, name) : formatDiagnostic(d, compiled.files?.[d.file] ?? "", d.file)).join("\n")
45
60
  }), def && /* @__PURE__ */ jsx(Loadmap, {
46
61
  model: def.model,
47
62
  view: def.view,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loadmap/react",
3
- "version": "0.33.0",
3
+ "version": "0.34.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.33.0",
43
- "@loadmap/dsl": "0.33.0",
44
- "@loadmap/sim": "0.33.0",
45
- "@loadmap/layout": "0.33.0",
42
+ "@loadmap/core": "0.34.0",
43
+ "@loadmap/dsl": "0.34.0",
44
+ "@loadmap/sim": "0.34.0",
45
+ "@loadmap/layout": "0.34.0",
46
46
  "elkjs": "^0.12.1"
47
47
  },
48
48
  "peerDependencies": {