@contractspec/lib.example-shared-ui 6.0.17 → 6.0.19
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/.turbo/turbo-build.log +81 -81
- package/CHANGELOG.md +28 -0
- package/dist/EvolutionDashboard.js +1 -803
- package/dist/EvolutionSidebar.js +1 -531
- package/dist/LocalDataIndicator.js +1 -68
- package/dist/MarkdownView.js +1 -213
- package/dist/OverlayContextProvider.js +1 -202
- package/dist/PersonalizationInsights.js +1 -455
- package/dist/SaveToStudioButton.js +1 -79
- package/dist/SpecDrivenTemplateShell.js +1 -203
- package/dist/SpecEditorPanel.js +17 -364
- package/dist/TemplateShell.js +1 -195
- package/dist/browser/EvolutionDashboard.js +1 -803
- package/dist/browser/EvolutionSidebar.js +1 -531
- package/dist/browser/LocalDataIndicator.js +1 -68
- package/dist/browser/MarkdownView.js +1 -213
- package/dist/browser/OverlayContextProvider.js +1 -202
- package/dist/browser/PersonalizationInsights.js +1 -455
- package/dist/browser/SaveToStudioButton.js +1 -79
- package/dist/browser/SpecDrivenTemplateShell.js +1 -203
- package/dist/browser/SpecEditorPanel.js +17 -364
- package/dist/browser/TemplateShell.js +1 -195
- package/dist/browser/bundles/ExampleTemplateBundle.js +1 -85
- package/dist/browser/bundles/index.js +1 -85
- package/dist/browser/hooks/index.js +40 -1151
- package/dist/browser/hooks/useBehaviorTracking.js +1 -157
- package/dist/browser/hooks/useEvolution.js +1 -260
- package/dist/browser/hooks/useRegistryTemplates.js +1 -31
- package/dist/browser/hooks/useSpecContent.js +17 -224
- package/dist/browser/hooks/useWorkflowComposer.js +24 -483
- package/dist/browser/index.js +40 -3122
- package/dist/browser/lib/component-registry.js +1 -48
- package/dist/browser/lib/runtime-context.js +1 -21
- package/dist/browser/markdown/formatPresentationName.js +1 -9
- package/dist/browser/markdown/useMarkdownPresentation.js +1 -65
- package/dist/browser/utils/fetchPresentationData.js +1 -15
- package/dist/browser/utils/generateSpecFromTemplate.js +16 -62
- package/dist/browser/utils/index.js +16 -76
- package/dist/bundles/ExampleTemplateBundle.js +1 -85
- package/dist/bundles/index.js +1 -85
- package/dist/hooks/index.js +40 -1151
- package/dist/hooks/useBehaviorTracking.js +1 -157
- package/dist/hooks/useEvolution.js +1 -260
- package/dist/hooks/useRegistryTemplates.js +1 -31
- package/dist/hooks/useSpecContent.js +17 -224
- package/dist/hooks/useWorkflowComposer.js +24 -483
- package/dist/index.js +40 -3122
- package/dist/lib/component-registry.js +1 -48
- package/dist/lib/runtime-context.js +1 -21
- package/dist/markdown/formatPresentationName.js +1 -9
- package/dist/markdown/useMarkdownPresentation.js +1 -65
- package/dist/node/EvolutionDashboard.js +1 -803
- package/dist/node/EvolutionSidebar.js +1 -531
- package/dist/node/LocalDataIndicator.js +1 -68
- package/dist/node/MarkdownView.js +1 -213
- package/dist/node/OverlayContextProvider.js +1 -202
- package/dist/node/PersonalizationInsights.js +1 -455
- package/dist/node/SaveToStudioButton.js +1 -79
- package/dist/node/SpecDrivenTemplateShell.js +1 -203
- package/dist/node/SpecEditorPanel.js +17 -364
- package/dist/node/TemplateShell.js +1 -195
- package/dist/node/bundles/ExampleTemplateBundle.js +1 -85
- package/dist/node/bundles/index.js +1 -85
- package/dist/node/hooks/index.js +40 -1151
- package/dist/node/hooks/useBehaviorTracking.js +1 -157
- package/dist/node/hooks/useEvolution.js +1 -260
- package/dist/node/hooks/useRegistryTemplates.js +1 -31
- package/dist/node/hooks/useSpecContent.js +17 -224
- package/dist/node/hooks/useWorkflowComposer.js +24 -483
- package/dist/node/index.js +40 -3122
- package/dist/node/lib/component-registry.js +1 -48
- package/dist/node/lib/runtime-context.js +1 -21
- package/dist/node/markdown/formatPresentationName.js +1 -9
- package/dist/node/markdown/useMarkdownPresentation.js +1 -65
- package/dist/node/utils/fetchPresentationData.js +1 -15
- package/dist/node/utils/generateSpecFromTemplate.js +16 -62
- package/dist/node/utils/index.js +16 -76
- package/dist/utils/fetchPresentationData.js +1 -15
- package/dist/utils/generateSpecFromTemplate.js +16 -62
- package/dist/utils/index.js +16 -76
- package/package.json +13 -13
- package/src/lib/component-registry.tsx +2 -1
- package/src/lib/runtime-context.tsx +1 -1
- package/src/lib/singletons.test.ts +19 -22
package/dist/MarkdownView.js
CHANGED
|
@@ -1,214 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
import { createContext, useContext } from "react";
|
|
4
|
-
"use client";
|
|
5
|
-
var TEMPLATE_RUNTIME_CONTEXT_KEY = Symbol.for("@contractspec/lib.example-shared-ui/template-runtime-context");
|
|
6
|
-
function getTemplateRuntimeContextSingleton() {
|
|
7
|
-
const store = globalThis;
|
|
8
|
-
store[TEMPLATE_RUNTIME_CONTEXT_KEY] ??= createContext(null);
|
|
9
|
-
return store[TEMPLATE_RUNTIME_CONTEXT_KEY];
|
|
10
|
-
}
|
|
11
|
-
var TemplateRuntimeContext = getTemplateRuntimeContextSingleton();
|
|
12
|
-
function useTemplateRuntime() {
|
|
13
|
-
const context = useContext(TemplateRuntimeContext);
|
|
14
|
-
if (!context) {
|
|
15
|
-
throw new Error("useTemplateRuntime must be used within a TemplateRuntimeProvider");
|
|
16
|
-
}
|
|
17
|
-
return context;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// src/markdown/formatPresentationName.ts
|
|
21
|
-
function formatPresentationName(name) {
|
|
22
|
-
const parts = name.split(".");
|
|
23
|
-
const lastPart = parts[parts.length - 1] ?? name;
|
|
24
|
-
return lastPart.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// src/markdown/useMarkdownPresentation.ts
|
|
28
|
-
import { useCallback, useEffect, useState } from "react";
|
|
29
|
-
"use client";
|
|
30
|
-
function useMarkdownPresentation({
|
|
31
|
-
engine,
|
|
32
|
-
fetchData,
|
|
33
|
-
presentationId,
|
|
34
|
-
presentations,
|
|
35
|
-
resolvePresentation,
|
|
36
|
-
templateId
|
|
37
|
-
}) {
|
|
38
|
-
const [selectedPresentation, setSelectedPresentation] = useState("");
|
|
39
|
-
const [markdownContent, setMarkdownContent] = useState("");
|
|
40
|
-
const [loading, setLoading] = useState(false);
|
|
41
|
-
const [error, setError] = useState(null);
|
|
42
|
-
useEffect(() => {
|
|
43
|
-
if (presentationId && presentations.includes(presentationId)) {
|
|
44
|
-
setSelectedPresentation(presentationId);
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
if (presentations.length === 0) {
|
|
48
|
-
setSelectedPresentation("");
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
if (!presentations.includes(selectedPresentation)) {
|
|
52
|
-
setSelectedPresentation(presentations[0] ?? "");
|
|
53
|
-
}
|
|
54
|
-
}, [presentationId, presentations, selectedPresentation, templateId]);
|
|
55
|
-
const renderMarkdown = useCallback(async () => {
|
|
56
|
-
if (!selectedPresentation || !engine)
|
|
57
|
-
return;
|
|
58
|
-
setLoading(true);
|
|
59
|
-
setError(null);
|
|
60
|
-
try {
|
|
61
|
-
if (!resolvePresentation) {
|
|
62
|
-
throw new Error("resolvePresentation not available in runtime context");
|
|
63
|
-
}
|
|
64
|
-
const descriptor = resolvePresentation(selectedPresentation);
|
|
65
|
-
if (!descriptor) {
|
|
66
|
-
throw new Error(`Presentation descriptor not found: ${selectedPresentation}`);
|
|
67
|
-
}
|
|
68
|
-
const dataResult = await fetchData(selectedPresentation);
|
|
69
|
-
const result = await engine.render("markdown", descriptor, { data: dataResult.data });
|
|
70
|
-
setMarkdownContent(result.body);
|
|
71
|
-
} catch (err) {
|
|
72
|
-
setError(err instanceof Error ? err : new Error("Failed to render markdown"));
|
|
73
|
-
} finally {
|
|
74
|
-
setLoading(false);
|
|
75
|
-
}
|
|
76
|
-
}, [engine, fetchData, resolvePresentation, selectedPresentation]);
|
|
77
|
-
useEffect(() => {
|
|
78
|
-
renderMarkdown();
|
|
79
|
-
}, [renderMarkdown]);
|
|
80
|
-
return {
|
|
81
|
-
error,
|
|
82
|
-
loading,
|
|
83
|
-
markdownContent,
|
|
84
|
-
renderMarkdown,
|
|
85
|
-
selectedPresentation,
|
|
86
|
-
setSelectedPresentation
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// src/MarkdownView.tsx
|
|
91
|
-
import {
|
|
92
|
-
Button,
|
|
93
|
-
ErrorState,
|
|
94
|
-
LoaderBlock,
|
|
95
|
-
MarkdownRenderer
|
|
96
|
-
} from "@contractspec/lib.design-system";
|
|
97
|
-
import { Badge } from "@contractspec/lib.ui-kit-web/ui/badge";
|
|
98
|
-
import { Card } from "@contractspec/lib.ui-kit-web/ui/card";
|
|
99
|
-
import { useCallback as useCallback2 } from "react";
|
|
100
|
-
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
101
|
-
"use client";
|
|
102
|
-
function MarkdownView({
|
|
103
|
-
templateId: propTemplateId,
|
|
104
|
-
presentationId,
|
|
105
|
-
className
|
|
106
|
-
}) {
|
|
107
|
-
const {
|
|
108
|
-
engine,
|
|
109
|
-
template,
|
|
110
|
-
templateId: contextTemplateId,
|
|
111
|
-
resolvePresentation,
|
|
112
|
-
fetchData
|
|
113
|
-
} = useTemplateRuntime();
|
|
114
|
-
const templateId = propTemplateId ?? contextTemplateId;
|
|
115
|
-
const presentations = template?.presentations ?? [];
|
|
116
|
-
const {
|
|
117
|
-
error,
|
|
118
|
-
loading,
|
|
119
|
-
markdownContent,
|
|
120
|
-
renderMarkdown,
|
|
121
|
-
selectedPresentation,
|
|
122
|
-
setSelectedPresentation
|
|
123
|
-
} = useMarkdownPresentation({
|
|
124
|
-
engine,
|
|
125
|
-
fetchData,
|
|
126
|
-
presentationId,
|
|
127
|
-
presentations,
|
|
128
|
-
resolvePresentation,
|
|
129
|
-
templateId
|
|
130
|
-
});
|
|
131
|
-
if (!presentations.length) {
|
|
132
|
-
return /* @__PURE__ */ jsxDEV(Card, {
|
|
133
|
-
className,
|
|
134
|
-
children: /* @__PURE__ */ jsxDEV("div", {
|
|
135
|
-
className: "p-6 text-center",
|
|
136
|
-
children: /* @__PURE__ */ jsxDEV("p", {
|
|
137
|
-
className: "text-muted-foreground",
|
|
138
|
-
children: "No presentations available for this template."
|
|
139
|
-
}, undefined, false, undefined, this)
|
|
140
|
-
}, undefined, false, undefined, this)
|
|
141
|
-
}, undefined, false, undefined, this);
|
|
142
|
-
}
|
|
143
|
-
const handleCopy = useCallback2(() => {
|
|
144
|
-
if (markdownContent) {
|
|
145
|
-
navigator.clipboard.writeText(markdownContent);
|
|
146
|
-
}
|
|
147
|
-
}, [markdownContent]);
|
|
148
|
-
return /* @__PURE__ */ jsxDEV("div", {
|
|
149
|
-
className,
|
|
150
|
-
children: [
|
|
151
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
152
|
-
className: "mb-4 flex flex-wrap items-center gap-2",
|
|
153
|
-
children: [
|
|
154
|
-
/* @__PURE__ */ jsxDEV("span", {
|
|
155
|
-
className: "font-medium text-muted-foreground text-sm",
|
|
156
|
-
children: "Presentation:"
|
|
157
|
-
}, undefined, false, undefined, this),
|
|
158
|
-
presentations.map((name) => /* @__PURE__ */ jsxDEV(Button, {
|
|
159
|
-
variant: selectedPresentation === name ? "default" : "outline",
|
|
160
|
-
size: "sm",
|
|
161
|
-
onPress: () => setSelectedPresentation(name),
|
|
162
|
-
children: formatPresentationName(name)
|
|
163
|
-
}, name, false, undefined, this)),
|
|
164
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
165
|
-
className: "ml-auto flex items-center gap-2",
|
|
166
|
-
children: [
|
|
167
|
-
/* @__PURE__ */ jsxDEV(Badge, {
|
|
168
|
-
variant: "secondary",
|
|
169
|
-
children: "LLM-friendly"
|
|
170
|
-
}, undefined, false, undefined, this),
|
|
171
|
-
/* @__PURE__ */ jsxDEV(Button, {
|
|
172
|
-
variant: "outline",
|
|
173
|
-
size: "sm",
|
|
174
|
-
onPress: handleCopy,
|
|
175
|
-
disabled: !markdownContent || loading,
|
|
176
|
-
children: "Copy"
|
|
177
|
-
}, undefined, false, undefined, this)
|
|
178
|
-
]
|
|
179
|
-
}, undefined, true, undefined, this)
|
|
180
|
-
]
|
|
181
|
-
}, undefined, true, undefined, this),
|
|
182
|
-
/* @__PURE__ */ jsxDEV(Card, {
|
|
183
|
-
className: "overflow-hidden",
|
|
184
|
-
children: [
|
|
185
|
-
loading && /* @__PURE__ */ jsxDEV(LoaderBlock, {
|
|
186
|
-
label: "Rendering markdown..."
|
|
187
|
-
}, undefined, false, undefined, this),
|
|
188
|
-
error && /* @__PURE__ */ jsxDEV(ErrorState, {
|
|
189
|
-
title: "Render failed",
|
|
190
|
-
description: error.message,
|
|
191
|
-
onRetry: renderMarkdown,
|
|
192
|
-
retryLabel: "Retry"
|
|
193
|
-
}, undefined, false, undefined, this),
|
|
194
|
-
!loading && !error && markdownContent && /* @__PURE__ */ jsxDEV("div", {
|
|
195
|
-
className: "p-6",
|
|
196
|
-
children: /* @__PURE__ */ jsxDEV(MarkdownRenderer, {
|
|
197
|
-
content: markdownContent
|
|
198
|
-
}, undefined, false, undefined, this)
|
|
199
|
-
}, undefined, false, undefined, this),
|
|
200
|
-
!loading && !error && !markdownContent && /* @__PURE__ */ jsxDEV("div", {
|
|
201
|
-
className: "p-6 text-center",
|
|
202
|
-
children: /* @__PURE__ */ jsxDEV("p", {
|
|
203
|
-
className: "text-muted-foreground",
|
|
204
|
-
children: "Select a presentation to view its markdown output."
|
|
205
|
-
}, undefined, false, undefined, this)
|
|
206
|
-
}, undefined, false, undefined, this)
|
|
207
|
-
]
|
|
208
|
-
}, undefined, true, undefined, this)
|
|
209
|
-
]
|
|
210
|
-
}, undefined, true, undefined, this);
|
|
211
|
-
}
|
|
212
|
-
export {
|
|
213
|
-
MarkdownView
|
|
214
|
-
};
|
|
2
|
+
import{createContext as z,useContext as E}from"react";var v=Symbol.for("@contractspec/lib.example-shared-ui/template-runtime-context");function G(){let r=globalThis;return r[v]??=z(null),r[v]}var H=G();function U(){let r=E(H);if(!r)throw Error("useTemplateRuntime must be used within a TemplateRuntimeProvider");return r}function M(r){let c=r.split(".");return(c[c.length-1]??r).split("-").map((n)=>n.charAt(0).toUpperCase()+n.slice(1)).join(" ")}import{useCallback as J,useEffect as O,useState as y}from"react";function F({engine:r,fetchData:c,presentationId:s,presentations:n,resolvePresentation:g,templateId:p}){let[i,u]=y(""),[h,d]=y(""),[l,e]=y(!1),[o,P]=y(null);O(()=>{if(s&&n.includes(s)){u(s);return}if(n.length===0){u("");return}if(!n.includes(i))u(n[0]??"")},[s,n,i,p]);let w=J(async()=>{if(!i||!r)return;e(!0),P(null);try{if(!g)throw Error("resolvePresentation not available in runtime context");let f=g(i);if(!f)throw Error(`Presentation descriptor not found: ${i}`);let k=await c(i),a=await r.render("markdown",f,{data:k.data});d(a.body)}catch(f){P(f instanceof Error?f:Error("Failed to render markdown"))}finally{e(!1)}},[r,c,g,i]);return O(()=>{w()},[w]),{error:o,loading:l,markdownContent:h,renderMarkdown:w,selectedPresentation:i,setSelectedPresentation:u}}import{Button as $,ErrorState as Q,LoaderBlock as S,MarkdownRenderer as V}from"@contractspec/lib.design-system";import{Badge as W}from"@contractspec/lib.ui-kit-web/ui/badge";import{Card as q}from"@contractspec/lib.ui-kit-web/ui/card";import{useCallback as Z}from"react";import{jsx as t,jsxs as b}from"react/jsx-runtime";function C({templateId:r,presentationId:c,className:s}){let{engine:n,template:g,templateId:p,resolvePresentation:i,fetchData:u}=U(),h=r??p,d=g?.presentations??[],{error:l,loading:e,markdownContent:o,renderMarkdown:P,selectedPresentation:w,setSelectedPresentation:f}=F({engine:n,fetchData:u,presentationId:c,presentations:d,resolvePresentation:i,templateId:h});if(!d.length)return t(q,{className:s,children:t("div",{className:"p-6 text-center",children:t("p",{className:"text-muted-foreground",children:"No presentations available for this template."})})});let k=Z(()=>{if(o)navigator.clipboard.writeText(o)},[o]);return b("div",{className:s,children:[b("div",{className:"mb-4 flex flex-wrap items-center gap-2",children:[t("span",{className:"font-medium text-muted-foreground text-sm",children:"Presentation:"}),d.map((a)=>t($,{variant:w===a?"default":"outline",size:"sm",onPress:()=>f(a),children:M(a)},a)),b("div",{className:"ml-auto flex items-center gap-2",children:[t(W,{variant:"secondary",children:"LLM-friendly"}),t($,{variant:"outline",size:"sm",onPress:k,disabled:!o||e,children:"Copy"})]})]}),b(q,{className:"overflow-hidden",children:[e&&t(S,{label:"Rendering markdown..."}),l&&t(Q,{title:"Render failed",description:l.message,onRetry:P,retryLabel:"Retry"}),!e&&!l&&o&&t("div",{className:"p-6",children:t(V,{content:o})}),!e&&!l&&!o&&t("div",{className:"p-6 text-center",children:t("p",{className:"text-muted-foreground",children:"Select a presentation to view its markdown output."})})]})]})}export{C as MarkdownView};
|
|
@@ -1,203 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
import * as React from "react";
|
|
4
|
-
import { useContext, useMemo } from "react";
|
|
5
|
-
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
6
|
-
"use client";
|
|
7
|
-
var OverlayContext = React.createContext(null);
|
|
8
|
-
function OverlayContextProvider({
|
|
9
|
-
templateId,
|
|
10
|
-
role = "user",
|
|
11
|
-
device = "desktop",
|
|
12
|
-
children
|
|
13
|
-
}) {
|
|
14
|
-
const overlays = useMemo(() => getTemplateOverlays(templateId, role), [templateId, role]);
|
|
15
|
-
const activeOverlays = useMemo(() => {
|
|
16
|
-
return overlays.filter((overlay) => {
|
|
17
|
-
const conditions = overlay.conditions;
|
|
18
|
-
if (!conditions)
|
|
19
|
-
return true;
|
|
20
|
-
if (conditions.role && !conditions.role.includes(role)) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
if (conditions.device && conditions.device !== "any" && conditions.device !== device) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
return true;
|
|
27
|
-
});
|
|
28
|
-
}, [overlays, role, device]);
|
|
29
|
-
const overlayMap = useMemo(() => {
|
|
30
|
-
const map = new Map;
|
|
31
|
-
for (const overlay of activeOverlays) {
|
|
32
|
-
map.set(overlay.target, overlay);
|
|
33
|
-
}
|
|
34
|
-
return map;
|
|
35
|
-
}, [activeOverlays]);
|
|
36
|
-
const applyOverlay = useMemo(() => (path, target) => {
|
|
37
|
-
const overlay = overlayMap.get(path);
|
|
38
|
-
if (!overlay)
|
|
39
|
-
return target;
|
|
40
|
-
let result = { ...target };
|
|
41
|
-
for (const mod of overlay.modifications) {
|
|
42
|
-
switch (mod.op) {
|
|
43
|
-
case "hide":
|
|
44
|
-
result = { ...result, hidden: true };
|
|
45
|
-
break;
|
|
46
|
-
case "relabel":
|
|
47
|
-
result = { ...result, label: mod.label };
|
|
48
|
-
break;
|
|
49
|
-
case "reorder":
|
|
50
|
-
result = { ...result, position: mod.position };
|
|
51
|
-
break;
|
|
52
|
-
case "restyle":
|
|
53
|
-
result = {
|
|
54
|
-
...result,
|
|
55
|
-
className: mod.className,
|
|
56
|
-
variant: mod.variant
|
|
57
|
-
};
|
|
58
|
-
break;
|
|
59
|
-
case "set-default":
|
|
60
|
-
result = { ...result, defaultValue: mod.value };
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return result;
|
|
65
|
-
}, [overlayMap]);
|
|
66
|
-
const isHidden = useMemo(() => (path) => {
|
|
67
|
-
const overlay = overlayMap.get(path);
|
|
68
|
-
return overlay?.modifications.some((m) => m.op === "hide") ?? false;
|
|
69
|
-
}, [overlayMap]);
|
|
70
|
-
const getLabel = useMemo(() => (path, defaultLabel) => {
|
|
71
|
-
const overlay = overlayMap.get(path);
|
|
72
|
-
const relabel = overlay?.modifications.find((m) => m.op === "relabel");
|
|
73
|
-
return relabel && relabel.op === "relabel" ? relabel.label : defaultLabel;
|
|
74
|
-
}, [overlayMap]);
|
|
75
|
-
const getPosition = useMemo(() => (path, defaultPosition) => {
|
|
76
|
-
const overlay = overlayMap.get(path);
|
|
77
|
-
const reorder = overlay?.modifications.find((m) => m.op === "reorder");
|
|
78
|
-
return reorder && reorder.op === "reorder" ? reorder.position : defaultPosition;
|
|
79
|
-
}, [overlayMap]);
|
|
80
|
-
const getStyle = useMemo(() => (path) => {
|
|
81
|
-
const overlay = overlayMap.get(path);
|
|
82
|
-
const restyle = overlay?.modifications.find((m) => m.op === "restyle");
|
|
83
|
-
if (restyle && restyle.op === "restyle") {
|
|
84
|
-
return {
|
|
85
|
-
className: restyle.className,
|
|
86
|
-
variant: restyle.variant
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
return {};
|
|
90
|
-
}, [overlayMap]);
|
|
91
|
-
const getDefault = useMemo(() => (path, defaultValue) => {
|
|
92
|
-
const overlay = overlayMap.get(path);
|
|
93
|
-
const setDefault = overlay?.modifications.find((m) => m.op === "set-default");
|
|
94
|
-
return setDefault && setDefault.op === "set-default" ? setDefault.value : defaultValue;
|
|
95
|
-
}, [overlayMap]);
|
|
96
|
-
const value = useMemo(() => ({
|
|
97
|
-
overlays: activeOverlays,
|
|
98
|
-
applyOverlay,
|
|
99
|
-
isHidden,
|
|
100
|
-
getLabel,
|
|
101
|
-
getPosition,
|
|
102
|
-
getStyle,
|
|
103
|
-
getDefault,
|
|
104
|
-
role,
|
|
105
|
-
device
|
|
106
|
-
}), [
|
|
107
|
-
activeOverlays,
|
|
108
|
-
applyOverlay,
|
|
109
|
-
isHidden,
|
|
110
|
-
getLabel,
|
|
111
|
-
getPosition,
|
|
112
|
-
getStyle,
|
|
113
|
-
getDefault,
|
|
114
|
-
role,
|
|
115
|
-
device
|
|
116
|
-
]);
|
|
117
|
-
return /* @__PURE__ */ jsxDEV(OverlayContext.Provider, {
|
|
118
|
-
value,
|
|
119
|
-
children
|
|
120
|
-
}, undefined, false, undefined, this);
|
|
121
|
-
}
|
|
122
|
-
function useOverlayContext() {
|
|
123
|
-
const context = useContext(OverlayContext);
|
|
124
|
-
if (!context) {
|
|
125
|
-
throw new Error("useOverlayContext must be used within an OverlayContextProvider");
|
|
126
|
-
}
|
|
127
|
-
return context;
|
|
128
|
-
}
|
|
129
|
-
function useIsInOverlayContext() {
|
|
130
|
-
return useContext(OverlayContext) !== null;
|
|
131
|
-
}
|
|
132
|
-
function getTemplateOverlays(templateId, _role) {
|
|
133
|
-
const templateOverlays = {
|
|
134
|
-
"crm-pipeline": [
|
|
135
|
-
{
|
|
136
|
-
id: "crm-hide-internal-fields",
|
|
137
|
-
target: "deal.internalNotes",
|
|
138
|
-
modifications: [{ op: "hide" }],
|
|
139
|
-
conditions: { role: ["viewer", "user"] }
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
id: "crm-relabel-value",
|
|
143
|
-
target: "deal.value",
|
|
144
|
-
modifications: [{ op: "relabel", label: "Deal Amount" }]
|
|
145
|
-
}
|
|
146
|
-
],
|
|
147
|
-
"saas-boilerplate": [
|
|
148
|
-
{
|
|
149
|
-
id: "saas-hide-billing",
|
|
150
|
-
target: "settings.billing",
|
|
151
|
-
modifications: [{ op: "hide" }],
|
|
152
|
-
conditions: { role: ["viewer"] }
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
id: "saas-restyle-plan",
|
|
156
|
-
target: "settings.plan",
|
|
157
|
-
modifications: [{ op: "restyle", variant: "premium" }],
|
|
158
|
-
conditions: { role: ["admin"] }
|
|
159
|
-
}
|
|
160
|
-
],
|
|
161
|
-
"agent-console": [
|
|
162
|
-
{
|
|
163
|
-
id: "agent-hide-cost",
|
|
164
|
-
target: "run.cost",
|
|
165
|
-
modifications: [{ op: "hide" }],
|
|
166
|
-
conditions: { role: ["viewer"] }
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
id: "agent-relabel-tokens",
|
|
170
|
-
target: "run.tokens",
|
|
171
|
-
modifications: [{ op: "relabel", label: "Token Usage" }]
|
|
172
|
-
}
|
|
173
|
-
],
|
|
174
|
-
"todos-app": [
|
|
175
|
-
{
|
|
176
|
-
id: "todos-hide-assignee",
|
|
177
|
-
target: "task.assignee",
|
|
178
|
-
modifications: [{ op: "hide" }],
|
|
179
|
-
conditions: { device: "mobile" }
|
|
180
|
-
}
|
|
181
|
-
],
|
|
182
|
-
"messaging-app": [
|
|
183
|
-
{
|
|
184
|
-
id: "messaging-reorder-timestamp",
|
|
185
|
-
target: "message.timestamp",
|
|
186
|
-
modifications: [{ op: "reorder", position: 0 }]
|
|
187
|
-
}
|
|
188
|
-
],
|
|
189
|
-
"recipe-app-i18n": [
|
|
190
|
-
{
|
|
191
|
-
id: "recipe-relabel-servings",
|
|
192
|
-
target: "recipe.servings",
|
|
193
|
-
modifications: [{ op: "relabel", label: "Portions" }]
|
|
194
|
-
}
|
|
195
|
-
]
|
|
196
|
-
};
|
|
197
|
-
return templateOverlays[templateId] ?? [];
|
|
198
|
-
}
|
|
199
|
-
export {
|
|
200
|
-
useOverlayContext,
|
|
201
|
-
useIsInOverlayContext,
|
|
202
|
-
OverlayContextProvider
|
|
203
|
-
};
|
|
2
|
+
import*as _ from"react";import{useContext as $,useMemo as E}from"react";import{jsx as S}from"react/jsx-runtime";var N=_.createContext(null);function L({templateId:F,role:G="user",device:J="desktop",children:T}){let Q=E(()=>H(F,G),[F,G]),K=E(()=>{return Q.filter((w)=>{let q=w.conditions;if(!q)return!0;if(q.role&&!q.role.includes(G))return!1;if(q.device&&q.device!=="any"&&q.device!==J)return!1;return!0})},[Q,G,J]),z=E(()=>{let w=new Map;for(let q of K)w.set(q.target,q);return w},[K]),R=E(()=>(w,q)=>{let A=z.get(w);if(!A)return q;let k={...q};for(let B of A.modifications)switch(B.op){case"hide":k={...k,hidden:!0};break;case"relabel":k={...k,label:B.label};break;case"reorder":k={...k,position:B.position};break;case"restyle":k={...k,className:B.className,variant:B.variant};break;case"set-default":k={...k,defaultValue:B.value};break}return k},[z]),U=E(()=>(w)=>{return z.get(w)?.modifications.some((A)=>A.op==="hide")??!1},[z]),W=E(()=>(w,q)=>{let k=z.get(w)?.modifications.find((B)=>B.op==="relabel");return k&&k.op==="relabel"?k.label:q},[z]),X=E(()=>(w,q)=>{let k=z.get(w)?.modifications.find((B)=>B.op==="reorder");return k&&k.op==="reorder"?k.position:q},[z]),Y=E(()=>(w)=>{let A=z.get(w)?.modifications.find((k)=>k.op==="restyle");if(A&&A.op==="restyle")return{className:A.className,variant:A.variant};return{}},[z]),Z=E(()=>(w,q)=>{let k=z.get(w)?.modifications.find((B)=>B.op==="set-default");return k&&k.op==="set-default"?k.value:q},[z]),j=E(()=>({overlays:K,applyOverlay:R,isHidden:U,getLabel:W,getPosition:X,getStyle:Y,getDefault:Z,role:G,device:J}),[K,R,U,W,X,Y,Z,G,J]);return S(N.Provider,{value:j,children:T})}function P(){let F=$(N);if(!F)throw Error("useOverlayContext must be used within an OverlayContextProvider");return F}function C(){return $(N)!==null}function H(F,G){return{"crm-pipeline":[{id:"crm-hide-internal-fields",target:"deal.internalNotes",modifications:[{op:"hide"}],conditions:{role:["viewer","user"]}},{id:"crm-relabel-value",target:"deal.value",modifications:[{op:"relabel",label:"Deal Amount"}]}],"saas-boilerplate":[{id:"saas-hide-billing",target:"settings.billing",modifications:[{op:"hide"}],conditions:{role:["viewer"]}},{id:"saas-restyle-plan",target:"settings.plan",modifications:[{op:"restyle",variant:"premium"}],conditions:{role:["admin"]}}],"agent-console":[{id:"agent-hide-cost",target:"run.cost",modifications:[{op:"hide"}],conditions:{role:["viewer"]}},{id:"agent-relabel-tokens",target:"run.tokens",modifications:[{op:"relabel",label:"Token Usage"}]}],"todos-app":[{id:"todos-hide-assignee",target:"task.assignee",modifications:[{op:"hide"}],conditions:{device:"mobile"}}],"messaging-app":[{id:"messaging-reorder-timestamp",target:"message.timestamp",modifications:[{op:"reorder",position:0}]}],"recipe-app-i18n":[{id:"recipe-relabel-servings",target:"recipe.servings",modifications:[{op:"relabel",label:"Portions"}]}]}[F]??[]}export{P as useOverlayContext,C as useIsInOverlayContext,L as OverlayContextProvider};
|