@timefoldai/viz-platform 0.0.0 → 0.1.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 +69 -1
- package/dist/analytics/use-analytics-bridge.d.mts +6 -0
- package/dist/analytics/use-analytics-bridge.mjs +21 -0
- package/dist/assignability/assignability.d.mts +97 -0
- package/dist/assignability/assignability.mjs +51 -0
- package/dist/assignability/use-assignability.d.mts +32 -0
- package/dist/assignability/use-assignability.mjs +151 -0
- package/dist/config/credential-channel.d.mts +13 -0
- package/dist/config/credential-channel.mjs +33 -0
- package/dist/config/embedding-params.d.mts +30 -0
- package/dist/config/embedding-params.mjs +54 -0
- package/dist/config/security.d.mts +36 -0
- package/dist/config/security.mjs +64 -0
- package/dist/dataset-context/DataSetContext.d.mts +215 -0
- package/dist/dataset-context/DataSetContext.mjs +170 -0
- package/dist/dataset-context/DataSetContextProvider.d.mts +19 -0
- package/dist/dataset-context/DataSetContextProvider.mjs +627 -0
- package/dist/dataset-context/DataSetLoader.d.mts +68 -0
- package/dist/dataset-context/DataSetLoader.mjs +130 -0
- package/dist/dataset-context/data-set-key.d.mts +2 -0
- package/dist/dataset-context/data-set-key.mjs +14 -0
- package/dist/dataset-context/model-api-url.d.mts +13 -0
- package/dist/dataset-context/model-api-url.mjs +27 -0
- package/dist/dataset-context/use-data-set-load-state.d.mts +26 -0
- package/dist/dataset-context/use-data-set-load-state.mjs +29 -0
- package/dist/dataset-context/use-fetch-dataset-resource.d.mts +8 -0
- package/dist/dataset-context/use-fetch-dataset-resource.mjs +20 -0
- package/dist/dataset-context/use-fetch-waypoints.d.mts +8 -0
- package/dist/dataset-context/use-fetch-waypoints.mjs +20 -0
- package/dist/dataset-context/use-run-events.d.mts +34 -0
- package/dist/dataset-context/use-run-events.mjs +138 -0
- package/dist/demo-data/use-demo-data.d.mts +42 -0
- package/dist/demo-data/use-demo-data.mjs +187 -0
- package/dist/env.d.mts +2 -0
- package/dist/env.mjs +4 -0
- package/dist/feature-flags/feature-flags.d.mts +34 -0
- package/dist/feature-flags/feature-flags.mjs +51 -0
- package/dist/feature-flags/use-feature-flag.d.mts +11 -0
- package/dist/feature-flags/use-feature-flag.mjs +17 -0
- package/dist/http/describe-response.d.mts +9 -0
- package/dist/http/describe-response.mjs +13 -0
- package/dist/http/models-api-request.d.mts +3 -0
- package/dist/http/models-api-request.mjs +20 -0
- package/dist/iframe-bridge/iframe-bridge.d.mts +10 -0
- package/dist/iframe-bridge/iframe-bridge.mjs +24 -0
- package/dist/iframe-bridge/use-iframe-bridge.d.mts +32 -0
- package/dist/iframe-bridge/use-iframe-bridge.mjs +200 -0
- package/dist/index.d.mts +16 -0
- package/dist/index.mjs +14 -0
- package/dist/solve-control/use-solve-control.d.mts +16 -0
- package/dist/solve-control/use-solve-control.mjs +46 -0
- package/dist/theme/prefers-dark.d.mts +11 -0
- package/dist/theme/prefers-dark.mjs +43 -0
- package/dist/view-channel/view-channel.d.mts +17 -0
- package/dist/view-channel/view-channel.mjs +67 -0
- package/dist/visualization-provider/VisualizationProvider.d.mts +20 -0
- package/dist/visualization-provider/VisualizationProvider.mjs +26 -0
- package/package.json +36 -5
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SolvePhase } from "@timefoldai/viz-core";
|
|
2
|
+
/** The phase of the solve that `useSolveControl` reports: viz-core's `SolvePhase`. */
|
|
3
|
+
export type SolveControlPhase = SolvePhase;
|
|
4
|
+
/**
|
|
5
|
+
* The solve lifecycle as plain data for a solve control: what it says, its phase and the handler that starts or
|
|
6
|
+
* stops a solve. `viz-react`'s `SolveButton` takes it as props.
|
|
7
|
+
*/
|
|
8
|
+
export interface SolveControl {
|
|
9
|
+
label: string;
|
|
10
|
+
phase: SolveControlPhase;
|
|
11
|
+
onToggle: () => Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Reads the solve lifecycle from the `VisualizationProvider` for a solve control to render.
|
|
15
|
+
*/
|
|
16
|
+
export declare function useSolveControl(): SolveControl;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { isSolveAtWork, isSolveFailure, useDataSetActions, useDataSetProviderState } from "../dataset-context/DataSetContext.mjs";
|
|
3
|
+
// src/solve-control/use-solve-control.ts
|
|
4
|
+
const PREPARATION_STEP_LABELS = {
|
|
5
|
+
DATASET_CREATED: "Validating dataset",
|
|
6
|
+
DATASET_VALIDATED: "Computing dataset"
|
|
7
|
+
};
|
|
8
|
+
function solverStatusOf(status) {
|
|
9
|
+
return status.phase === "solving" || status.phase === "solve-failed" ? status.solverStatus : void 0;
|
|
10
|
+
}
|
|
11
|
+
function describeSolve(isSolving, status) {
|
|
12
|
+
const solverStatus = solverStatusOf(status);
|
|
13
|
+
if (status.phase === "solving" && status.solveId === "") return {
|
|
14
|
+
label: "Starting solve",
|
|
15
|
+
phase: "starting"
|
|
16
|
+
};
|
|
17
|
+
const preparationStep = !isSolving && solverStatus !== void 0 ? PREPARATION_STEP_LABELS[solverStatus] : void 0;
|
|
18
|
+
if (preparationStep) return {
|
|
19
|
+
label: preparationStep,
|
|
20
|
+
phase: "preparing"
|
|
21
|
+
};
|
|
22
|
+
if (isSolving) return {
|
|
23
|
+
label: "Stop solving",
|
|
24
|
+
phase: "solving"
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
label: solverStatus !== void 0 && isSolveFailure(solverStatus) ? "Solve failed" : "Solve",
|
|
28
|
+
phase: "idle"
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Reads the solve lifecycle from the `VisualizationProvider` for a solve control to render.
|
|
33
|
+
*/
|
|
34
|
+
function useSolveControl() {
|
|
35
|
+
const { status, inAppSolveActive } = useDataSetProviderState();
|
|
36
|
+
const isSolving = isSolveAtWork(status, inAppSolveActive);
|
|
37
|
+
const { startSolve, stopSolve } = useDataSetActions();
|
|
38
|
+
return {
|
|
39
|
+
...describeSolve(isSolving, status),
|
|
40
|
+
onToggle: async () => {
|
|
41
|
+
if (isSolving) stopSolve();
|
|
42
|
+
else await startSolve();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export { useSolveControl };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ColorScheme } from "@timefoldai/viz-core";
|
|
2
|
+
/**
|
|
3
|
+
* Paints the embedding host's colour scheme on `<html>`. From then on it wins over a stored choice and the OS
|
|
4
|
+
* preference for the life of the page.
|
|
5
|
+
*/
|
|
6
|
+
export declare function applyHostColorScheme(scheme: ColorScheme): void;
|
|
7
|
+
/**
|
|
8
|
+
* Paints `<html>` from a `colorScheme` query param, else the reader's stored choice, else the OS preference.
|
|
9
|
+
* No-op if a theme is already painted. Returns an unsubscribe.
|
|
10
|
+
*/
|
|
11
|
+
export declare function applyPreferredColorScheme(): () => void;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { COLOR_SCHEME_STORAGE_KEY, parseColorScheme } from "@timefoldai/viz-core";
|
|
2
|
+
// src/theme/prefers-dark.ts
|
|
3
|
+
const QUERY = "(prefers-color-scheme: dark)";
|
|
4
|
+
let hostColorScheme;
|
|
5
|
+
function storedColorScheme() {
|
|
6
|
+
try {
|
|
7
|
+
return parseColorScheme(localStorage.getItem(COLOR_SCHEME_STORAGE_KEY));
|
|
8
|
+
} catch {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function paint(choice, prefersDark) {
|
|
13
|
+
const root = document.documentElement;
|
|
14
|
+
const dark = choice === void 0 ? prefersDark : choice === "dark";
|
|
15
|
+
root.classList.toggle("dark", dark);
|
|
16
|
+
root.classList.toggle("light", choice === "light");
|
|
17
|
+
root.dataset["theme"] = dark ? "dark" : "light";
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Paints the embedding host's colour scheme on `<html>`. From then on it wins over a stored choice and the OS
|
|
21
|
+
* preference for the life of the page.
|
|
22
|
+
*/
|
|
23
|
+
function applyHostColorScheme(scheme) {
|
|
24
|
+
hostColorScheme = scheme;
|
|
25
|
+
paint(scheme, false);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Paints `<html>` from a `colorScheme` query param, else the reader's stored choice, else the OS preference.
|
|
29
|
+
* No-op if a theme is already painted. Returns an unsubscribe.
|
|
30
|
+
*/
|
|
31
|
+
function applyPreferredColorScheme() {
|
|
32
|
+
const fromQuery = parseColorScheme(new URLSearchParams(window.location.search).get("colorScheme"));
|
|
33
|
+
if (fromQuery !== void 0) applyHostColorScheme(fromQuery);
|
|
34
|
+
const root = document.documentElement;
|
|
35
|
+
if (root.classList.contains("dark") || root.classList.contains("light") || root.dataset["theme"] != null || typeof matchMedia !== "function") return () => {};
|
|
36
|
+
const mql = matchMedia(QUERY);
|
|
37
|
+
const sync = (prefersDark) => paint(hostColorScheme ?? storedColorScheme(), prefersDark);
|
|
38
|
+
sync(mql.matches);
|
|
39
|
+
const onChange = (e) => sync(e.matches);
|
|
40
|
+
mql.addEventListener("change", onChange);
|
|
41
|
+
return () => mql.removeEventListener("change", onChange);
|
|
42
|
+
}
|
|
43
|
+
export { applyHostColorScheme, applyPreferredColorScheme };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Options for {@link useViewChannel}. */
|
|
2
|
+
export type UseViewChannelOptions = {
|
|
3
|
+
viewKeys: string[];
|
|
4
|
+
activeView: string;
|
|
5
|
+
onNavigate: (key: string) => void;
|
|
6
|
+
/** @defaultValue true */
|
|
7
|
+
enabled?: boolean;
|
|
8
|
+
/** @defaultValue window.location.origin */
|
|
9
|
+
targetOrigin?: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Signals readiness and the active view to the embedding parent and applies inbound navigation, without a page
|
|
13
|
+
* reload. It trusts the page's own origin and the provider's `allowedApiHosts`.
|
|
14
|
+
*
|
|
15
|
+
* @category Hooks
|
|
16
|
+
*/
|
|
17
|
+
export declare function useViewChannel({ viewKeys, activeView, onNavigate, enabled, targetOrigin }: UseViewChannelOptions): void;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useDataSetProviderState } from "../dataset-context/DataSetContext.mjs";
|
|
3
|
+
import { VISUALIZATION_MESSAGE_SOURCE, isTrustedMessageOrigin, postToParent } from "../iframe-bridge/iframe-bridge.mjs";
|
|
4
|
+
import { useEffect, useRef } from "react";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
// src/view-channel/view-channel.ts
|
|
7
|
+
const navigateMessageSchema = z.object({
|
|
8
|
+
source: z.literal(VISUALIZATION_MESSAGE_SOURCE),
|
|
9
|
+
type: z.literal("navigate"),
|
|
10
|
+
page: z.string().min(1)
|
|
11
|
+
});
|
|
12
|
+
const requestViewActiveMessageSchema = z.object({
|
|
13
|
+
source: z.literal(VISUALIZATION_MESSAGE_SOURCE),
|
|
14
|
+
type: z.literal("request-view-active")
|
|
15
|
+
});
|
|
16
|
+
function postViewActive(active, targetOrigin) {
|
|
17
|
+
postToParent("view-active", { page: active }, targetOrigin);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Signals readiness and the active view to the embedding parent and applies inbound navigation, without a page
|
|
21
|
+
* reload. It trusts the page's own origin and the provider's `allowedApiHosts`.
|
|
22
|
+
*
|
|
23
|
+
* @category Hooks
|
|
24
|
+
*/
|
|
25
|
+
function useViewChannel({ viewKeys, activeView, onNavigate, enabled = true, targetOrigin = window.location.origin }) {
|
|
26
|
+
const allowlist = useDataSetProviderState().allowedApiHosts;
|
|
27
|
+
const viewKeysRef = useRef(viewKeys);
|
|
28
|
+
const activeRef = useRef(activeView);
|
|
29
|
+
const onNavigateRef = useRef(onNavigate);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
viewKeysRef.current = viewKeys;
|
|
32
|
+
activeRef.current = activeView;
|
|
33
|
+
onNavigateRef.current = onNavigate;
|
|
34
|
+
}, [
|
|
35
|
+
viewKeys,
|
|
36
|
+
activeView,
|
|
37
|
+
onNavigate
|
|
38
|
+
]);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (!enabled) return;
|
|
41
|
+
postViewActive(activeView, targetOrigin);
|
|
42
|
+
}, [
|
|
43
|
+
enabled,
|
|
44
|
+
activeView,
|
|
45
|
+
targetOrigin
|
|
46
|
+
]);
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (!enabled) return;
|
|
49
|
+
function handleMessage(event) {
|
|
50
|
+
if (!isTrustedMessageOrigin(event, allowlist)) return;
|
|
51
|
+
const navigate = navigateMessageSchema.safeParse(event.data);
|
|
52
|
+
if (navigate.success) {
|
|
53
|
+
if (!viewKeysRef.current.includes(navigate.data.page)) return;
|
|
54
|
+
onNavigateRef.current(navigate.data.page);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (requestViewActiveMessageSchema.safeParse(event.data).success) postViewActive(activeRef.current, targetOrigin);
|
|
58
|
+
}
|
|
59
|
+
window.addEventListener("message", handleMessage);
|
|
60
|
+
return () => window.removeEventListener("message", handleMessage);
|
|
61
|
+
}, [
|
|
62
|
+
enabled,
|
|
63
|
+
allowlist,
|
|
64
|
+
targetOrigin
|
|
65
|
+
]);
|
|
66
|
+
}
|
|
67
|
+
export { useViewChannel };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DataSetInitialState, VisualizationConfig } from "../dataset-context/DataSetContext.mjs";
|
|
2
|
+
import { DistanceUnitSystem } from "@timefoldai/viz-core";
|
|
3
|
+
import { ReactNode } from "react";
|
|
4
|
+
/** The props of `VisualizationProvider`: the dataset configuration and the content it wraps. */
|
|
5
|
+
export interface VisualizationProviderProps<InputType, OutputType, MergedType = InputType> {
|
|
6
|
+
config: VisualizationConfig<InputType, OutputType, MergedType>;
|
|
7
|
+
initialState?: DataSetInitialState<InputType, OutputType, MergedType>;
|
|
8
|
+
/** @remarks Unset, the embedding host's `unitSystem` decides, else metric. */
|
|
9
|
+
unitSystem?: DistanceUnitSystem;
|
|
10
|
+
/** @defaultValue true */
|
|
11
|
+
resizeBridge?: boolean;
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The entry point a visualisation mounts at its root: the dataset provider
|
|
16
|
+
* plus the ambient wiring every embed needs.
|
|
17
|
+
*
|
|
18
|
+
* @category Providers
|
|
19
|
+
*/
|
|
20
|
+
export declare function VisualizationProvider<InputType, OutputType, MergedType = InputType>({ config, initialState, unitSystem, resizeBridge, children }: VisualizationProviderProps<InputType, OutputType, MergedType>): import("react").JSX.Element;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useDataSetProviderState } from "../dataset-context/DataSetContext.mjs";
|
|
3
|
+
import { DataSetContextProvider } from "../dataset-context/DataSetContextProvider.mjs";
|
|
4
|
+
import { useIframeBridge } from "../iframe-bridge/use-iframe-bridge.mjs";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
// src/visualization-provider/VisualizationProvider.tsx
|
|
7
|
+
function ResizeBridge() {
|
|
8
|
+
const { isOnPlatform } = useDataSetProviderState();
|
|
9
|
+
useIframeBridge({ resize: isOnPlatform });
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The entry point a visualisation mounts at its root: the dataset provider
|
|
14
|
+
* plus the ambient wiring every embed needs.
|
|
15
|
+
*
|
|
16
|
+
* @category Providers
|
|
17
|
+
*/
|
|
18
|
+
function VisualizationProvider({ config, initialState, unitSystem, resizeBridge = true, children }) {
|
|
19
|
+
return /* @__PURE__ */ jsxs(DataSetContextProvider, {
|
|
20
|
+
config,
|
|
21
|
+
initialState,
|
|
22
|
+
unitSystem,
|
|
23
|
+
children: [resizeBridge && /* @__PURE__ */ jsx(ResizeBridge, {}), children]
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export { VisualizationProvider };
|
package/package.json
CHANGED
|
@@ -1,13 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@timefoldai/viz-platform",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "The data layer of a Timefold model visualization: load a dataset from the Timefold Models API, demo data or a file, and keep it live while the model solves.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"models-api",
|
|
7
|
+
"planning",
|
|
8
|
+
"react",
|
|
9
|
+
"timefold",
|
|
10
|
+
"visualization"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://timefold.ai",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://docs.timefold.ai/timefold-platform/latest/support/contacting-support"
|
|
15
|
+
},
|
|
5
16
|
"license": "Apache-2.0",
|
|
6
17
|
"repository": {
|
|
7
18
|
"type": "git",
|
|
8
19
|
"url": "git+https://github.com/TimefoldAI/timefold-visualisations.git",
|
|
9
20
|
"directory": "packages/platform"
|
|
10
21
|
},
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.mts",
|
|
30
|
+
"default": "./dist/index.mjs"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public",
|
|
35
|
+
"registry": "https://registry.npmjs.org"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@timefoldai/viz-core": "0.1.0",
|
|
39
|
+
"zod": "^4.6.7"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"react": "^19"
|
|
43
|
+
}
|
|
44
|
+
}
|