@loomwork/blueprint-runtime 0.0.0-stage → 0.1.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.
- package/LICENSE +202 -0
- package/NOTICE +8 -0
- package/README.md +83 -2
- package/dist/Blueprint.d.ts +14 -0
- package/dist/Blueprint.d.ts.map +1 -0
- package/dist/Blueprint.js +18 -0
- package/dist/Blueprint.js.map +1 -0
- package/dist/RendererRegistry.d.ts +9 -0
- package/dist/RendererRegistry.d.ts.map +1 -0
- package/dist/RendererRegistry.js +39 -0
- package/dist/RendererRegistry.js.map +1 -0
- package/dist/catalog.d.ts +129 -0
- package/dist/catalog.d.ts.map +1 -0
- package/dist/catalog.js +435 -0
- package/dist/catalog.js.map +1 -0
- package/dist/coverage.d.ts +18 -0
- package/dist/coverage.d.ts.map +1 -0
- package/dist/coverage.js +22 -0
- package/dist/coverage.js.map +1 -0
- package/dist/customWidget.d.ts +10 -0
- package/dist/customWidget.d.ts.map +1 -0
- package/dist/customWidget.js +34 -0
- package/dist/customWidget.js.map +1 -0
- package/dist/esm/Blueprint.js +15 -0
- package/dist/esm/Blueprint.js.map +1 -0
- package/dist/esm/RendererRegistry.js +35 -0
- package/dist/esm/RendererRegistry.js.map +1 -0
- package/dist/esm/catalog.js +430 -0
- package/dist/esm/catalog.js.map +1 -0
- package/dist/esm/coverage.js +19 -0
- package/dist/esm/coverage.js.map +1 -0
- package/dist/esm/customWidget.js +31 -0
- package/dist/esm/customWidget.js.map +1 -0
- package/dist/esm/identity.js +116 -0
- package/dist/esm/identity.js.map +1 -0
- package/dist/esm/index.js +15 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/irVersion.js +150 -0
- package/dist/esm/irVersion.js.map +1 -0
- package/dist/esm/layout.js +63 -0
- package/dist/esm/layout.js.map +1 -0
- package/dist/esm/normalize.js +115 -0
- package/dist/esm/normalize.js.map +1 -0
- package/dist/esm/pins.js +82 -0
- package/dist/esm/pins.js.map +1 -0
- package/dist/esm/traverseBlueprint.js +38 -0
- package/dist/esm/traverseBlueprint.js.map +1 -0
- package/dist/esm/traverseBlueprintAsync.js +48 -0
- package/dist/esm/traverseBlueprintAsync.js.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/widgetStatus.js +137 -0
- package/dist/esm/widgetStatus.js.map +1 -0
- package/dist/esm/widgets.js +105 -0
- package/dist/esm/widgets.js.map +1 -0
- package/dist/identity.d.ts +58 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +122 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +61 -0
- package/dist/index.js.map +1 -0
- package/dist/irVersion.d.ts +23 -0
- package/dist/irVersion.d.ts.map +1 -0
- package/dist/irVersion.js +153 -0
- package/dist/irVersion.js.map +1 -0
- package/dist/layout.d.ts +57 -0
- package/dist/layout.d.ts.map +1 -0
- package/dist/layout.js +71 -0
- package/dist/layout.js.map +1 -0
- package/dist/normalize.d.ts +29 -0
- package/dist/normalize.d.ts.map +1 -0
- package/dist/normalize.js +126 -0
- package/dist/normalize.js.map +1 -0
- package/dist/pins.d.ts +27 -0
- package/dist/pins.d.ts.map +1 -0
- package/dist/pins.js +86 -0
- package/dist/pins.js.map +1 -0
- package/dist/traverseBlueprint.d.ts +27 -0
- package/dist/traverseBlueprint.d.ts.map +1 -0
- package/dist/traverseBlueprint.js +40 -0
- package/dist/traverseBlueprint.js.map +1 -0
- package/dist/traverseBlueprintAsync.d.ts +18 -0
- package/dist/traverseBlueprintAsync.d.ts.map +1 -0
- package/dist/traverseBlueprintAsync.js +51 -0
- package/dist/traverseBlueprintAsync.js.map +1 -0
- package/dist/types.d.ts +176 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/widgetStatus.d.ts +66 -0
- package/dist/widgetStatus.d.ts.map +1 -0
- package/dist/widgetStatus.js +141 -0
- package/dist/widgetStatus.js.map +1 -0
- package/dist/widgets.d.ts +101 -0
- package/dist/widgets.d.ts.map +1 -0
- package/dist/widgets.js +115 -0
- package/dist/widgets.js.map +1 -0
- package/package.json +60 -3
- package/src/Blueprint.ts +28 -0
- package/src/RendererRegistry.ts +38 -0
- package/src/catalog.ts +638 -0
- package/src/coverage.ts +52 -0
- package/src/customWidget.ts +42 -0
- package/src/identity.ts +178 -0
- package/src/index.ts +84 -0
- package/src/irVersion.ts +195 -0
- package/src/layout.ts +105 -0
- package/src/normalize.ts +130 -0
- package/src/pins.ts +84 -0
- package/src/traverseBlueprint.bench.ts +47 -0
- package/src/traverseBlueprint.ts +94 -0
- package/src/traverseBlueprintAsync.ts +92 -0
- package/src/types.ts +195 -0
- package/src/widgetStatus.ts +231 -0
- package/src/widgets.ts +213 -0
package/dist/widgets.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MetricCard = MetricCard;
|
|
4
|
+
exports.Timeline = Timeline;
|
|
5
|
+
exports.ApprovalCard = ApprovalCard;
|
|
6
|
+
exports.StatusBadge = StatusBadge;
|
|
7
|
+
exports.ProgressBar = ProgressBar;
|
|
8
|
+
exports.DataTable = DataTable;
|
|
9
|
+
exports.AlertCard = AlertCard;
|
|
10
|
+
exports.StreamingText = StreamingText;
|
|
11
|
+
// A derived id, used when the caller supplies none. It is an IDENTITY, not a
|
|
12
|
+
// content address: a 32-bit non-cryptographic hash, scoped to one blueprint.
|
|
13
|
+
// Never treat it as an audit anchor for "which view was this" — use a real digest
|
|
14
|
+
// (`contentAddress` in @loomwork/plugin-content) for that.
|
|
15
|
+
//
|
|
16
|
+
// Because it is derived from the props, it CHANGES when any prop changes. That is
|
|
17
|
+
// correct for a view that is authored once and wrong for one a composer revises,
|
|
18
|
+
// which is why every builder accepts an explicit `id`.
|
|
19
|
+
function stableId(kind, props) {
|
|
20
|
+
const str = kind + JSON.stringify(props, Object.keys(props).sort());
|
|
21
|
+
let hash = 0;
|
|
22
|
+
for (let i = 0; i < str.length; i++) {
|
|
23
|
+
hash = (Math.imul(31, hash) + str.charCodeAt(i)) | 0;
|
|
24
|
+
}
|
|
25
|
+
return `${kind}-${(hash >>> 0).toString(16)}`;
|
|
26
|
+
}
|
|
27
|
+
function MetricCard(props) {
|
|
28
|
+
const { title, id, ...rest } = props;
|
|
29
|
+
return {
|
|
30
|
+
_tag: "Widget",
|
|
31
|
+
id: id ?? stableId("MetricCard", props),
|
|
32
|
+
kind: "MetricCard",
|
|
33
|
+
title,
|
|
34
|
+
props: rest,
|
|
35
|
+
binding: props.binding,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function Timeline(props) {
|
|
39
|
+
const { title, id, ...rest } = props;
|
|
40
|
+
return {
|
|
41
|
+
_tag: "Widget",
|
|
42
|
+
id: id ?? stableId("Timeline", props),
|
|
43
|
+
kind: "Timeline",
|
|
44
|
+
...(title !== undefined && { title }),
|
|
45
|
+
props: rest,
|
|
46
|
+
binding: props.binding,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function ApprovalCard(props) {
|
|
50
|
+
const { title, id, ...rest } = props;
|
|
51
|
+
return {
|
|
52
|
+
_tag: "Widget",
|
|
53
|
+
id: id ?? stableId("ApprovalCard", props),
|
|
54
|
+
kind: "ApprovalCard",
|
|
55
|
+
title,
|
|
56
|
+
props: rest,
|
|
57
|
+
binding: props.binding,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function StatusBadge(props) {
|
|
61
|
+
const { title, id, ...rest } = props;
|
|
62
|
+
return {
|
|
63
|
+
_tag: "Widget",
|
|
64
|
+
id: id ?? stableId("StatusBadge", props),
|
|
65
|
+
kind: "StatusBadge",
|
|
66
|
+
...(title !== undefined && { title }),
|
|
67
|
+
props: rest,
|
|
68
|
+
binding: props.binding,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function ProgressBar(props) {
|
|
72
|
+
const { title, id, ...rest } = props;
|
|
73
|
+
return {
|
|
74
|
+
_tag: "Widget",
|
|
75
|
+
id: id ?? stableId("ProgressBar", props),
|
|
76
|
+
kind: "ProgressBar",
|
|
77
|
+
...(title !== undefined && { title }),
|
|
78
|
+
props: rest,
|
|
79
|
+
binding: props.binding,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function DataTable(props) {
|
|
83
|
+
const { title, id, ...rest } = props;
|
|
84
|
+
return {
|
|
85
|
+
_tag: "Widget",
|
|
86
|
+
id: id ?? stableId("DataTable", props),
|
|
87
|
+
kind: "DataTable",
|
|
88
|
+
...(title !== undefined && { title }),
|
|
89
|
+
props: rest,
|
|
90
|
+
binding: props.binding,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function AlertCard(props) {
|
|
94
|
+
const { title, id, ...rest } = props;
|
|
95
|
+
return {
|
|
96
|
+
_tag: "Widget",
|
|
97
|
+
id: id ?? stableId("AlertCard", props),
|
|
98
|
+
kind: "AlertCard",
|
|
99
|
+
...(title !== undefined && { title }),
|
|
100
|
+
props: rest,
|
|
101
|
+
binding: props.binding,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function StreamingText(props) {
|
|
105
|
+
const { title, id, ...rest } = props;
|
|
106
|
+
return {
|
|
107
|
+
_tag: "Widget",
|
|
108
|
+
id: id ?? stableId("StreamingText", props),
|
|
109
|
+
kind: "StreamingText",
|
|
110
|
+
...(title !== undefined && { title }),
|
|
111
|
+
props: rest,
|
|
112
|
+
binding: props.binding,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=widgets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widgets.js","sourceRoot":"","sources":["../src/widgets.ts"],"names":[],"mappings":";;AAiCA,gCAUC;AAeD,4BAUC;AAgBD,oCAUC;AAcD,kCAUC;AAeD,kCAUC;AAeD,8BAUC;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,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loomwork/blueprint-runtime",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Schema-driven UI blueprint generation — pure JSON-serializable types",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"module": "./dist/esm/index.js",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"require": "./dist/index.js",
|
|
13
|
+
"node": "./dist/index.js",
|
|
14
|
+
"import": "./dist/esm/index.js",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@loomwork/scheduler": "^0.1.1",
|
|
20
|
+
"@loomwork/classify": "^0.1.1",
|
|
21
|
+
"@loomwork/core": "^0.1.1"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/node": "^22.0.0",
|
|
25
|
+
"typescript": "^5.6.3",
|
|
26
|
+
"vitest": "^2.1.8"
|
|
27
|
+
},
|
|
28
|
+
"license": "Apache-2.0",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/chhetrisushil/loom.git",
|
|
32
|
+
"directory": "packages/blueprint-runtime"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"src",
|
|
37
|
+
"!src/**/*.test.ts",
|
|
38
|
+
"!src/**/*.test.tsx",
|
|
39
|
+
"!src/**/__tests__",
|
|
40
|
+
"!src/**/__fixtures__",
|
|
41
|
+
"!src/**/__snapshots__",
|
|
42
|
+
"!src/**/__golden__",
|
|
43
|
+
"LICENSE",
|
|
44
|
+
"NOTICE"
|
|
45
|
+
],
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public",
|
|
48
|
+
"tag": "next"
|
|
49
|
+
},
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=20.0.0"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsc --build && rm -rf dist/esm && tsc -p tsconfig.esm.json",
|
|
55
|
+
"build:esm": "rm -rf dist/esm && tsc -p tsconfig.esm.json",
|
|
56
|
+
"dev": "tsc --build --watch",
|
|
57
|
+
"test": "vitest run",
|
|
58
|
+
"test:watch": "vitest",
|
|
59
|
+
"bench": "vitest bench --run",
|
|
60
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
61
|
+
"typecheck:tests": "tsc -p tsconfig.test.json"
|
|
62
|
+
}
|
|
6
63
|
}
|
package/src/Blueprint.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { BLUEPRINT_IR_VERSION } from "./irVersion";
|
|
2
|
+
import type { Blueprint, Layout } from "./types";
|
|
3
|
+
|
|
4
|
+
export interface BlueprintConfig {
|
|
5
|
+
id: string;
|
|
6
|
+
title: string;
|
|
7
|
+
layout: Layout;
|
|
8
|
+
projections: string[];
|
|
9
|
+
/**
|
|
10
|
+
* ADR 0095 — the declared versions of the projections this view binds to, at composition.
|
|
11
|
+
* `projectionRuntime.pins()` is where they come from. See {@link Blueprint.projectionVersions}.
|
|
12
|
+
*/
|
|
13
|
+
projectionVersions?: Readonly<Record<string, string>>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function blueprint$(config: BlueprintConfig): Blueprint {
|
|
17
|
+
return {
|
|
18
|
+
_tag: "Blueprint",
|
|
19
|
+
irVersion: BLUEPRINT_IR_VERSION,
|
|
20
|
+
id: config.id,
|
|
21
|
+
title: config.title,
|
|
22
|
+
layout: config.layout,
|
|
23
|
+
projections: config.projections,
|
|
24
|
+
...(config.projectionVersions !== undefined && {
|
|
25
|
+
projectionVersions: config.projectionVersions,
|
|
26
|
+
}),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Generic widget registry — framework-agnostic.
|
|
2
|
+
// TRenderer is narrowed by each framework adapter:
|
|
3
|
+
// React: RendererRegistry<React.FC<WidgetRendererProps>>
|
|
4
|
+
// Angular: RendererRegistry<Type<unknown>>
|
|
5
|
+
// DOM: RendererRegistry<(el: HTMLElement, props: WidgetRendererProps) => void>
|
|
6
|
+
|
|
7
|
+
export class RendererRegistry<TRenderer> {
|
|
8
|
+
private readonly renderers = new Map<string, TRenderer>();
|
|
9
|
+
|
|
10
|
+
register(kind: string, renderer: TRenderer): this {
|
|
11
|
+
this.renderers.set(kind, renderer);
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
get(kind: string): TRenderer | undefined {
|
|
16
|
+
return this.renderers.get(kind);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
has(kind: string): boolean {
|
|
20
|
+
return this.renderers.has(kind);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
kinds(): string[] {
|
|
24
|
+
return Array.from(this.renderers.keys());
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Returns a new registry that contains all renderers from both registries.
|
|
28
|
+
// Entries in `other` win on conflicts.
|
|
29
|
+
merge(other: RendererRegistry<TRenderer>): RendererRegistry<TRenderer> {
|
|
30
|
+
const merged = new RendererRegistry<TRenderer>();
|
|
31
|
+
for (const [kind, r] of this.renderers) merged.register(kind, r);
|
|
32
|
+
for (const kind of other.kinds()) {
|
|
33
|
+
const r = other.get(kind);
|
|
34
|
+
if (r !== undefined) merged.register(kind, r);
|
|
35
|
+
}
|
|
36
|
+
return merged;
|
|
37
|
+
}
|
|
38
|
+
}
|