@loadmap/react 0.7.0 → 0.8.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.
@@ -0,0 +1,16 @@
1
+ import { a as LoadmapProps } from "./Loadmap-VLbQ__eh.js";
2
+ import { CompileOptions } from "@loadmap/dsl";
3
+ export interface LoadmapSourceProps extends Omit<LoadmapProps<any>, 'model' | 'view'> {
4
+ /** The `.loadmap` text. Compiled again when its tokens change: spaces, line breaks and comments change nothing. */
5
+ source: string;
6
+ /** The file the diagnostics name, as `loadmap check` does. Default "input.loadmap". */
7
+ name?: string;
8
+ /** A host's own functions for the formulas, as `compile(…, { functions })` takes them; read when the text compiles. */
9
+ functions?: CompileOptions['functions'];
10
+ }
11
+ /**
12
+ * A `.loadmap` text drawn as `<Loadmap>`, with the options it declares (the page's props win; its `assumptions` come
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.
15
+ */
16
+ export declare function LoadmapSource({ source, name, functions, theme, assumptions, ...props }: LoadmapSourceProps): import("react").JSX.Element;
package/dist/source.js ADDED
@@ -0,0 +1,54 @@
1
+ import { a as usePageTheme, c as injectStyles, n as Loadmap } from "./Loadmap-D_Kto8cB.js";
2
+ import { useEffect, useMemo, useRef } from "react";
3
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
+ import { compile, formatDiagnostic } from "@loadmap/dsl";
5
+ import { fingerprint, pageOptions } from "@loadmap/dsl/internal";
6
+ // src/source.tsx
7
+ /**
8
+ * A `.loadmap` text drawn as `<Loadmap>`, with the options it declares (the page's props win; its `assumptions` come
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.
11
+ */
12
+ function LoadmapSource({ source, name = "input.loadmap", functions, theme, assumptions, ...props }) {
13
+ const fns = useRef(functions);
14
+ fns.current = functions;
15
+ const key = useMemo(() => fingerprint(source), [source]);
16
+ const compiled = useMemo(() => ({
17
+ source,
18
+ r: compile(source, fns.current ? { functions: fns.current } : {})
19
+ }), [key]);
20
+ const good = useRef(null);
21
+ if (compiled.r.ok && compiled.r.definition) good.current = compiled.r.definition;
22
+ const def = good.current;
23
+ const set = Object.fromEntries(Object.entries(props).filter(([, v]) => v !== void 0));
24
+ const lines = def && [...assumptions ?? [], ...def.options.assumptions];
25
+ return /* @__PURE__ */ jsxs(Fragment, { children: [!compiled.r.ok && /* @__PURE__ */ jsx(Problems, {
26
+ theme,
27
+ stale: def != null,
28
+ children: compiled.r.diagnostics.map((d) => formatDiagnostic(d, compiled.source, name)).join("\n")
29
+ }), def && /* @__PURE__ */ jsx(Loadmap, {
30
+ model: def.model,
31
+ view: def.view,
32
+ ...pageOptions(def.options),
33
+ ...set,
34
+ theme,
35
+ ...lines?.length ? { assumptions: lines } : {}
36
+ })] });
37
+ }
38
+ function Problems({ theme, stale, children }) {
39
+ const look = usePageTheme(theme);
40
+ useEffect(() => injectStyles(), []);
41
+ return /* @__PURE__ */ jsxs("div", {
42
+ className: "lm",
43
+ "data-theme": look === "auto" ? void 0 : look,
44
+ children: [/* @__PURE__ */ jsx("pre", {
45
+ className: "lm-problems",
46
+ role: "alert",
47
+ children
48
+ }), stale && /* @__PURE__ */ jsx("p", {
49
+ className: "lm-note",
50
+ children: "The diagram below is the last version without errors."
51
+ })]
52
+ });
53
+ }
54
+ export { LoadmapSource };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loadmap/react",
3
- "version": "0.7.0",
3
+ "version": "0.8.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",
@@ -25,15 +25,20 @@
25
25
  "types": "./dist/index.d.ts",
26
26
  "import": "./dist/index.js"
27
27
  },
28
+ "./source": {
29
+ "types": "./dist/source.d.ts",
30
+ "import": "./dist/source.js"
31
+ },
28
32
  "./elk.worker.js": "./dist/elk.worker.js"
29
33
  },
30
34
  "files": [
31
35
  "dist"
32
36
  ],
33
37
  "dependencies": {
34
- "@loadmap/core": "0.7.0",
35
- "@loadmap/sim": "0.7.0",
36
- "@loadmap/layout": "0.7.0",
38
+ "@loadmap/core": "0.8.0",
39
+ "@loadmap/dsl": "0.8.0",
40
+ "@loadmap/sim": "0.8.0",
41
+ "@loadmap/layout": "0.8.0",
37
42
  "elkjs": "^0.12.1"
38
43
  },
39
44
  "peerDependencies": {