@contractspec/lib.example-shared-ui 1.11.0 → 1.13.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/.turbo/turbo-build.log +86 -11
- package/.turbo/turbo-prebuild.log +1 -0
- package/CHANGELOG.md +27 -0
- package/dist/EvolutionDashboard.d.ts +11 -0
- package/dist/EvolutionDashboard.d.ts.map +1 -0
- package/dist/EvolutionDashboard.js +804 -0
- package/dist/EvolutionSidebar.d.ts +19 -0
- package/dist/EvolutionSidebar.d.ts.map +1 -0
- package/dist/EvolutionSidebar.js +532 -0
- package/dist/LocalDataIndicator.d.ts +2 -0
- package/dist/LocalDataIndicator.d.ts.map +1 -0
- package/dist/LocalDataIndicator.js +63 -0
- package/dist/MarkdownView.d.ts +20 -0
- package/dist/MarkdownView.d.ts.map +1 -0
- package/dist/MarkdownView.js +304 -0
- package/dist/OverlayContextProvider.d.ts +79 -0
- package/dist/OverlayContextProvider.d.ts.map +1 -0
- package/dist/OverlayContextProvider.js +203 -0
- package/dist/PersonalizationInsights.d.ts +14 -0
- package/dist/PersonalizationInsights.d.ts.map +1 -0
- package/dist/PersonalizationInsights.js +456 -0
- package/dist/SaveToStudioButton.d.ts +8 -0
- package/dist/SaveToStudioButton.d.ts.map +1 -0
- package/dist/SaveToStudioButton.js +74 -0
- package/dist/SpecEditorPanel.d.ts +23 -0
- package/dist/SpecEditorPanel.d.ts.map +1 -0
- package/dist/SpecEditorPanel.js +720 -0
- package/dist/TemplateShell.d.ts +13 -0
- package/dist/TemplateShell.d.ts.map +1 -0
- package/dist/TemplateShell.js +190 -0
- package/dist/browser/EvolutionDashboard.js +803 -0
- package/dist/browser/EvolutionSidebar.js +531 -0
- package/dist/browser/LocalDataIndicator.js +62 -0
- package/dist/browser/MarkdownView.js +303 -0
- package/dist/browser/OverlayContextProvider.js +202 -0
- package/dist/browser/PersonalizationInsights.js +455 -0
- package/dist/browser/SaveToStudioButton.js +73 -0
- package/dist/browser/SpecEditorPanel.js +719 -0
- package/dist/browser/TemplateShell.js +189 -0
- package/dist/browser/hooks/index.js +1516 -0
- package/dist/browser/hooks/useBehaviorTracking.js +157 -0
- package/dist/browser/hooks/useEvolution.js +260 -0
- package/dist/browser/hooks/useRegistryTemplates.js +31 -0
- package/dist/browser/hooks/useSpecContent.js +579 -0
- package/dist/browser/hooks/useWorkflowComposer.js +493 -0
- package/dist/browser/index.js +3497 -0
- package/dist/browser/lib/component-registry.js +42 -0
- package/dist/browser/lib/runtime-context.js +15 -0
- package/dist/browser/lib/types.js +0 -0
- package/dist/browser/overlay-types.js +0 -0
- package/dist/browser/utils/fetchPresentationData.js +15 -0
- package/dist/browser/utils/generateSpecFromTemplate.js +423 -0
- package/dist/browser/utils/index.js +437 -0
- package/dist/hooks/index.d.ts +6 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +1517 -0
- package/dist/hooks/useBehaviorTracking.d.ts +56 -0
- package/dist/hooks/useBehaviorTracking.d.ts.map +1 -0
- package/dist/hooks/useBehaviorTracking.js +158 -0
- package/dist/hooks/useEvolution.d.ts +111 -0
- package/dist/hooks/useEvolution.d.ts.map +1 -0
- package/dist/hooks/useEvolution.js +261 -0
- package/dist/hooks/useRegistryTemplates.d.ts +10 -0
- package/dist/hooks/useRegistryTemplates.d.ts.map +1 -0
- package/dist/hooks/useRegistryTemplates.js +32 -0
- package/dist/hooks/useSpecContent.d.ts +41 -0
- package/dist/hooks/useSpecContent.d.ts.map +1 -0
- package/dist/hooks/useSpecContent.js +580 -0
- package/dist/hooks/useWorkflowComposer.d.ts +94 -0
- package/dist/hooks/useWorkflowComposer.d.ts.map +1 -0
- package/dist/hooks/useWorkflowComposer.js +494 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3498 -0
- package/dist/lib/component-registry.d.ts +18 -0
- package/dist/lib/component-registry.d.ts.map +1 -0
- package/dist/lib/component-registry.js +43 -0
- package/dist/lib/runtime-context.d.ts +29 -0
- package/dist/lib/runtime-context.d.ts.map +1 -0
- package/dist/lib/runtime-context.js +16 -0
- package/dist/lib/types.d.ts +69 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +1 -0
- package/dist/node/EvolutionDashboard.js +803 -0
- package/dist/node/EvolutionSidebar.js +531 -0
- package/dist/node/LocalDataIndicator.js +62 -0
- package/dist/node/MarkdownView.js +303 -0
- package/dist/node/OverlayContextProvider.js +202 -0
- package/dist/node/PersonalizationInsights.js +455 -0
- package/dist/node/SaveToStudioButton.js +73 -0
- package/dist/node/SpecEditorPanel.js +719 -0
- package/dist/node/TemplateShell.js +189 -0
- package/dist/node/hooks/index.js +1516 -0
- package/dist/node/hooks/useBehaviorTracking.js +157 -0
- package/dist/node/hooks/useEvolution.js +260 -0
- package/dist/node/hooks/useRegistryTemplates.js +31 -0
- package/dist/node/hooks/useSpecContent.js +579 -0
- package/dist/node/hooks/useWorkflowComposer.js +493 -0
- package/dist/node/index.js +3497 -0
- package/dist/node/lib/component-registry.js +42 -0
- package/dist/node/lib/runtime-context.js +15 -0
- package/dist/node/lib/types.js +0 -0
- package/dist/node/overlay-types.js +0 -0
- package/dist/node/utils/fetchPresentationData.js +15 -0
- package/dist/node/utils/generateSpecFromTemplate.js +423 -0
- package/dist/node/utils/index.js +437 -0
- package/dist/overlay-types.d.ts +41 -0
- package/dist/overlay-types.d.ts.map +1 -0
- package/dist/overlay-types.js +1 -0
- package/dist/utils/fetchPresentationData.d.ts +34 -0
- package/dist/utils/fetchPresentationData.d.ts.map +1 -0
- package/dist/utils/fetchPresentationData.js +16 -0
- package/dist/utils/generateSpecFromTemplate.d.ts +7 -0
- package/dist/utils/generateSpecFromTemplate.d.ts.map +1 -0
- package/dist/utils/generateSpecFromTemplate.js +424 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +438 -0
- package/package.json +219 -14
- package/.turbo/turbo-build$colon$bundle.log +0 -9
- package/dist/index.mjs +0 -3121
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
// src/lib/runtime-context.tsx
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
"use client";
|
|
4
|
+
var TemplateRuntimeContext = createContext(null);
|
|
5
|
+
function useTemplateRuntime() {
|
|
6
|
+
const context = useContext(TemplateRuntimeContext);
|
|
7
|
+
if (!context) {
|
|
8
|
+
throw new Error("useTemplateRuntime must be used within a TemplateRuntimeProvider");
|
|
9
|
+
}
|
|
10
|
+
return context;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// src/MarkdownView.tsx
|
|
14
|
+
import { useCallback, useEffect, useState } from "react";
|
|
15
|
+
import {
|
|
16
|
+
Button,
|
|
17
|
+
ErrorState,
|
|
18
|
+
LoaderBlock
|
|
19
|
+
} from "@contractspec/lib.design-system";
|
|
20
|
+
import { Card } from "@contractspec/lib.ui-kit-web/ui/card";
|
|
21
|
+
import { Badge } from "@contractspec/lib.ui-kit-web/ui/badge";
|
|
22
|
+
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
23
|
+
"use client";
|
|
24
|
+
function MarkdownView({
|
|
25
|
+
templateId: propTemplateId,
|
|
26
|
+
presentationId,
|
|
27
|
+
className
|
|
28
|
+
}) {
|
|
29
|
+
const {
|
|
30
|
+
engine,
|
|
31
|
+
template,
|
|
32
|
+
templateId: contextTemplateId,
|
|
33
|
+
resolvePresentation,
|
|
34
|
+
fetchData
|
|
35
|
+
} = useTemplateRuntime();
|
|
36
|
+
const templateId = propTemplateId ?? contextTemplateId;
|
|
37
|
+
const presentations = template?.presentations ?? [];
|
|
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
|
+
} else if (presentations.length > 0 && !selectedPresentation) {
|
|
46
|
+
setSelectedPresentation(presentations[0] ?? "");
|
|
47
|
+
}
|
|
48
|
+
}, [presentationId, presentations, selectedPresentation]);
|
|
49
|
+
const renderMarkdown = useCallback(async () => {
|
|
50
|
+
if (!selectedPresentation || !engine)
|
|
51
|
+
return;
|
|
52
|
+
setLoading(true);
|
|
53
|
+
setError(null);
|
|
54
|
+
try {
|
|
55
|
+
if (!resolvePresentation) {
|
|
56
|
+
throw new Error("resolvePresentation not available in runtime context");
|
|
57
|
+
}
|
|
58
|
+
const descriptor = resolvePresentation(selectedPresentation);
|
|
59
|
+
if (!descriptor) {
|
|
60
|
+
throw new Error(`Presentation descriptor not found: ${selectedPresentation}`);
|
|
61
|
+
}
|
|
62
|
+
const dataResult = await fetchData(selectedPresentation);
|
|
63
|
+
const result = await engine.render("markdown", descriptor, { data: dataResult.data });
|
|
64
|
+
setMarkdownContent(result.body);
|
|
65
|
+
} catch (err) {
|
|
66
|
+
setError(err instanceof Error ? err : new Error("Failed to render markdown"));
|
|
67
|
+
} finally {
|
|
68
|
+
setLoading(false);
|
|
69
|
+
}
|
|
70
|
+
}, [
|
|
71
|
+
selectedPresentation,
|
|
72
|
+
templateId,
|
|
73
|
+
engine,
|
|
74
|
+
resolvePresentation,
|
|
75
|
+
fetchData
|
|
76
|
+
]);
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
renderMarkdown();
|
|
79
|
+
}, [renderMarkdown]);
|
|
80
|
+
if (!presentations.length) {
|
|
81
|
+
return /* @__PURE__ */ jsxDEV(Card, {
|
|
82
|
+
className,
|
|
83
|
+
children: /* @__PURE__ */ jsxDEV("div", {
|
|
84
|
+
className: "p-6 text-center",
|
|
85
|
+
children: /* @__PURE__ */ jsxDEV("p", {
|
|
86
|
+
className: "text-muted-foreground",
|
|
87
|
+
children: "No presentations available for this template."
|
|
88
|
+
}, undefined, false, undefined, this)
|
|
89
|
+
}, undefined, false, undefined, this)
|
|
90
|
+
}, undefined, false, undefined, this);
|
|
91
|
+
}
|
|
92
|
+
const handleCopy = useCallback(() => {
|
|
93
|
+
if (markdownContent) {
|
|
94
|
+
navigator.clipboard.writeText(markdownContent);
|
|
95
|
+
}
|
|
96
|
+
}, [markdownContent]);
|
|
97
|
+
return /* @__PURE__ */ jsxDEV("div", {
|
|
98
|
+
className,
|
|
99
|
+
children: [
|
|
100
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
101
|
+
className: "mb-4 flex flex-wrap items-center gap-2",
|
|
102
|
+
children: [
|
|
103
|
+
/* @__PURE__ */ jsxDEV("span", {
|
|
104
|
+
className: "text-muted-foreground text-sm font-medium",
|
|
105
|
+
children: "Presentation:"
|
|
106
|
+
}, undefined, false, undefined, this),
|
|
107
|
+
presentations.map((name) => /* @__PURE__ */ jsxDEV(Button, {
|
|
108
|
+
variant: selectedPresentation === name ? "default" : "outline",
|
|
109
|
+
size: "sm",
|
|
110
|
+
onPress: () => setSelectedPresentation(name),
|
|
111
|
+
children: formatPresentationName(name)
|
|
112
|
+
}, name, false, undefined, this)),
|
|
113
|
+
/* @__PURE__ */ jsxDEV("div", {
|
|
114
|
+
className: "ml-auto flex items-center gap-2",
|
|
115
|
+
children: [
|
|
116
|
+
/* @__PURE__ */ jsxDEV(Badge, {
|
|
117
|
+
variant: "secondary",
|
|
118
|
+
children: "LLM-friendly"
|
|
119
|
+
}, undefined, false, undefined, this),
|
|
120
|
+
/* @__PURE__ */ jsxDEV(Button, {
|
|
121
|
+
variant: "outline",
|
|
122
|
+
size: "sm",
|
|
123
|
+
onPress: handleCopy,
|
|
124
|
+
disabled: !markdownContent || loading,
|
|
125
|
+
children: "Copy"
|
|
126
|
+
}, undefined, false, undefined, this)
|
|
127
|
+
]
|
|
128
|
+
}, undefined, true, undefined, this)
|
|
129
|
+
]
|
|
130
|
+
}, undefined, true, undefined, this),
|
|
131
|
+
/* @__PURE__ */ jsxDEV(Card, {
|
|
132
|
+
className: "overflow-hidden",
|
|
133
|
+
children: [
|
|
134
|
+
loading && /* @__PURE__ */ jsxDEV(LoaderBlock, {
|
|
135
|
+
label: "Rendering markdown..."
|
|
136
|
+
}, undefined, false, undefined, this),
|
|
137
|
+
error && /* @__PURE__ */ jsxDEV(ErrorState, {
|
|
138
|
+
title: "Render failed",
|
|
139
|
+
description: error.message,
|
|
140
|
+
onRetry: renderMarkdown,
|
|
141
|
+
retryLabel: "Retry"
|
|
142
|
+
}, undefined, false, undefined, this),
|
|
143
|
+
!loading && !error && markdownContent && /* @__PURE__ */ jsxDEV("div", {
|
|
144
|
+
className: "p-6",
|
|
145
|
+
children: /* @__PURE__ */ jsxDEV(MarkdownRenderer, {
|
|
146
|
+
content: markdownContent
|
|
147
|
+
}, undefined, false, undefined, this)
|
|
148
|
+
}, undefined, false, undefined, this),
|
|
149
|
+
!loading && !error && !markdownContent && /* @__PURE__ */ jsxDEV("div", {
|
|
150
|
+
className: "p-6 text-center",
|
|
151
|
+
children: /* @__PURE__ */ jsxDEV("p", {
|
|
152
|
+
className: "text-muted-foreground",
|
|
153
|
+
children: "Select a presentation to view its markdown output."
|
|
154
|
+
}, undefined, false, undefined, this)
|
|
155
|
+
}, undefined, false, undefined, this)
|
|
156
|
+
]
|
|
157
|
+
}, undefined, true, undefined, this)
|
|
158
|
+
]
|
|
159
|
+
}, undefined, true, undefined, this);
|
|
160
|
+
}
|
|
161
|
+
function MarkdownRenderer({ content }) {
|
|
162
|
+
const lines = content.split(`
|
|
163
|
+
`);
|
|
164
|
+
const rendered = [];
|
|
165
|
+
let i = 0;
|
|
166
|
+
while (i < lines.length) {
|
|
167
|
+
const line = lines[i] ?? "";
|
|
168
|
+
if (line.startsWith("|") && lines[i + 1]?.match(/^\|[\s-|]+\|$/)) {
|
|
169
|
+
const tableLines = [line];
|
|
170
|
+
i++;
|
|
171
|
+
while (i < lines.length && (lines[i]?.startsWith("|") ?? false)) {
|
|
172
|
+
tableLines.push(lines[i] ?? "");
|
|
173
|
+
i++;
|
|
174
|
+
}
|
|
175
|
+
rendered.push(renderTable(tableLines, rendered.length));
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
if (line.startsWith("# ")) {
|
|
179
|
+
rendered.push(/* @__PURE__ */ jsxDEV("h1", {
|
|
180
|
+
className: "mb-4 text-2xl font-bold",
|
|
181
|
+
children: line.slice(2)
|
|
182
|
+
}, i, false, undefined, this));
|
|
183
|
+
} else if (line.startsWith("## ")) {
|
|
184
|
+
rendered.push(/* @__PURE__ */ jsxDEV("h2", {
|
|
185
|
+
className: "mt-6 mb-3 text-xl font-semibold",
|
|
186
|
+
children: line.slice(3)
|
|
187
|
+
}, i, false, undefined, this));
|
|
188
|
+
} else if (line.startsWith("### ")) {
|
|
189
|
+
rendered.push(/* @__PURE__ */ jsxDEV("h3", {
|
|
190
|
+
className: "mt-4 mb-2 text-lg font-medium",
|
|
191
|
+
children: line.slice(4)
|
|
192
|
+
}, i, false, undefined, this));
|
|
193
|
+
} else if (line.startsWith("> ")) {
|
|
194
|
+
rendered.push(/* @__PURE__ */ jsxDEV("blockquote", {
|
|
195
|
+
className: "text-muted-foreground my-2 border-l-4 border-violet-500/50 pl-4 italic",
|
|
196
|
+
children: line.slice(2)
|
|
197
|
+
}, i, false, undefined, this));
|
|
198
|
+
} else if (line.startsWith("- ")) {
|
|
199
|
+
rendered.push(/* @__PURE__ */ jsxDEV("li", {
|
|
200
|
+
className: "ml-4 list-disc",
|
|
201
|
+
children: formatInlineMarkdown(line.slice(2))
|
|
202
|
+
}, i, false, undefined, this));
|
|
203
|
+
} else if (line.startsWith("**") && line.includes(":**")) {
|
|
204
|
+
const [label, ...rest] = line.split(":**");
|
|
205
|
+
rendered.push(/* @__PURE__ */ jsxDEV("p", {
|
|
206
|
+
className: "my-1",
|
|
207
|
+
children: [
|
|
208
|
+
/* @__PURE__ */ jsxDEV("strong", {
|
|
209
|
+
children: [
|
|
210
|
+
label?.slice(2),
|
|
211
|
+
":"
|
|
212
|
+
]
|
|
213
|
+
}, undefined, true, undefined, this),
|
|
214
|
+
rest.join(":**")
|
|
215
|
+
]
|
|
216
|
+
}, i, true, undefined, this));
|
|
217
|
+
} else if (line.startsWith("_") && line.endsWith("_")) {
|
|
218
|
+
rendered.push(/* @__PURE__ */ jsxDEV("p", {
|
|
219
|
+
className: "text-muted-foreground my-1 italic",
|
|
220
|
+
children: line.slice(1, -1)
|
|
221
|
+
}, i, false, undefined, this));
|
|
222
|
+
} else if (!line.trim()) {
|
|
223
|
+
rendered.push(/* @__PURE__ */ jsxDEV("div", {
|
|
224
|
+
className: "h-2"
|
|
225
|
+
}, i, false, undefined, this));
|
|
226
|
+
} else {
|
|
227
|
+
rendered.push(/* @__PURE__ */ jsxDEV("p", {
|
|
228
|
+
className: "my-1",
|
|
229
|
+
children: formatInlineMarkdown(line)
|
|
230
|
+
}, i, false, undefined, this));
|
|
231
|
+
}
|
|
232
|
+
i++;
|
|
233
|
+
}
|
|
234
|
+
return /* @__PURE__ */ jsxDEV("div", {
|
|
235
|
+
className: "prose prose-sm dark:prose-invert max-w-none",
|
|
236
|
+
children: rendered
|
|
237
|
+
}, undefined, false, undefined, this);
|
|
238
|
+
}
|
|
239
|
+
function renderTable(lines, keyPrefix) {
|
|
240
|
+
if (lines.length < 2)
|
|
241
|
+
return null;
|
|
242
|
+
const parseRow = (row) => row.split("|").slice(1, -1).map((cell) => cell.trim());
|
|
243
|
+
const headers = parseRow(lines[0] ?? "");
|
|
244
|
+
const dataRows = lines.slice(2).map(parseRow);
|
|
245
|
+
return /* @__PURE__ */ jsxDEV("div", {
|
|
246
|
+
className: "my-4 overflow-x-auto",
|
|
247
|
+
children: /* @__PURE__ */ jsxDEV("table", {
|
|
248
|
+
className: "border-border min-w-full border-collapse border text-sm",
|
|
249
|
+
children: [
|
|
250
|
+
/* @__PURE__ */ jsxDEV("thead", {
|
|
251
|
+
children: /* @__PURE__ */ jsxDEV("tr", {
|
|
252
|
+
className: "bg-muted/50",
|
|
253
|
+
children: headers.map((header, idx) => /* @__PURE__ */ jsxDEV("th", {
|
|
254
|
+
className: "border-border border px-3 py-2 text-left font-semibold",
|
|
255
|
+
children: header
|
|
256
|
+
}, idx, false, undefined, this))
|
|
257
|
+
}, undefined, false, undefined, this)
|
|
258
|
+
}, undefined, false, undefined, this),
|
|
259
|
+
/* @__PURE__ */ jsxDEV("tbody", {
|
|
260
|
+
children: dataRows.map((row, rowIdx) => /* @__PURE__ */ jsxDEV("tr", {
|
|
261
|
+
className: "hover:bg-muted/30",
|
|
262
|
+
children: row.map((cell, cellIdx) => /* @__PURE__ */ jsxDEV("td", {
|
|
263
|
+
className: "border-border border px-3 py-2",
|
|
264
|
+
children: formatInlineMarkdown(cell)
|
|
265
|
+
}, cellIdx, false, undefined, this))
|
|
266
|
+
}, rowIdx, false, undefined, this))
|
|
267
|
+
}, undefined, false, undefined, this)
|
|
268
|
+
]
|
|
269
|
+
}, undefined, true, undefined, this)
|
|
270
|
+
}, `table-${keyPrefix}`, false, undefined, this);
|
|
271
|
+
}
|
|
272
|
+
function formatInlineMarkdown(text) {
|
|
273
|
+
const parts = text.split(/(\*\*[^*]+\*\*)/g);
|
|
274
|
+
return parts.map((part, i) => {
|
|
275
|
+
if (part.startsWith("**") && part.endsWith("**")) {
|
|
276
|
+
return /* @__PURE__ */ jsxDEV("strong", {
|
|
277
|
+
children: part.slice(2, -2)
|
|
278
|
+
}, i, false, undefined, this);
|
|
279
|
+
}
|
|
280
|
+
if (part.includes("`")) {
|
|
281
|
+
const codeParts = part.split(/(`[^`]+`)/g);
|
|
282
|
+
return codeParts.map((cp, j) => {
|
|
283
|
+
if (cp.startsWith("`") && cp.endsWith("`")) {
|
|
284
|
+
return /* @__PURE__ */ jsxDEV("code", {
|
|
285
|
+
className: "rounded bg-violet-500/10 px-1.5 py-0.5 font-mono text-sm",
|
|
286
|
+
children: cp.slice(1, -1)
|
|
287
|
+
}, `${i}-${j}`, false, undefined, this);
|
|
288
|
+
}
|
|
289
|
+
return cp;
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
return part;
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
function formatPresentationName(name) {
|
|
296
|
+
const parts = name.split(".");
|
|
297
|
+
const lastPart = parts[parts.length - 1] ?? name;
|
|
298
|
+
return lastPart.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
|
|
299
|
+
}
|
|
300
|
+
export {
|
|
301
|
+
MarkdownView,
|
|
302
|
+
MarkdownRenderer
|
|
303
|
+
};
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// src/OverlayContextProvider.tsx
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { useContext, useMemo } from "react";
|
|
4
|
+
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
5
|
+
"use client";
|
|
6
|
+
var OverlayContext = React.createContext(null);
|
|
7
|
+
function OverlayContextProvider({
|
|
8
|
+
templateId,
|
|
9
|
+
role = "user",
|
|
10
|
+
device = "desktop",
|
|
11
|
+
children
|
|
12
|
+
}) {
|
|
13
|
+
const overlays = useMemo(() => getTemplateOverlays(templateId, role), [templateId, role]);
|
|
14
|
+
const activeOverlays = useMemo(() => {
|
|
15
|
+
return overlays.filter((overlay) => {
|
|
16
|
+
const conditions = overlay.conditions;
|
|
17
|
+
if (!conditions)
|
|
18
|
+
return true;
|
|
19
|
+
if (conditions.role && !conditions.role.includes(role)) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
if (conditions.device && conditions.device !== "any" && conditions.device !== device) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
});
|
|
27
|
+
}, [overlays, role, device]);
|
|
28
|
+
const overlayMap = useMemo(() => {
|
|
29
|
+
const map = new Map;
|
|
30
|
+
for (const overlay of activeOverlays) {
|
|
31
|
+
map.set(overlay.target, overlay);
|
|
32
|
+
}
|
|
33
|
+
return map;
|
|
34
|
+
}, [activeOverlays]);
|
|
35
|
+
const applyOverlay = useMemo(() => (path, target) => {
|
|
36
|
+
const overlay = overlayMap.get(path);
|
|
37
|
+
if (!overlay)
|
|
38
|
+
return target;
|
|
39
|
+
let result = { ...target };
|
|
40
|
+
for (const mod of overlay.modifications) {
|
|
41
|
+
switch (mod.op) {
|
|
42
|
+
case "hide":
|
|
43
|
+
result = { ...result, hidden: true };
|
|
44
|
+
break;
|
|
45
|
+
case "relabel":
|
|
46
|
+
result = { ...result, label: mod.label };
|
|
47
|
+
break;
|
|
48
|
+
case "reorder":
|
|
49
|
+
result = { ...result, position: mod.position };
|
|
50
|
+
break;
|
|
51
|
+
case "restyle":
|
|
52
|
+
result = {
|
|
53
|
+
...result,
|
|
54
|
+
className: mod.className,
|
|
55
|
+
variant: mod.variant
|
|
56
|
+
};
|
|
57
|
+
break;
|
|
58
|
+
case "set-default":
|
|
59
|
+
result = { ...result, defaultValue: mod.value };
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}, [overlayMap]);
|
|
65
|
+
const isHidden = useMemo(() => (path) => {
|
|
66
|
+
const overlay = overlayMap.get(path);
|
|
67
|
+
return overlay?.modifications.some((m) => m.op === "hide") ?? false;
|
|
68
|
+
}, [overlayMap]);
|
|
69
|
+
const getLabel = useMemo(() => (path, defaultLabel) => {
|
|
70
|
+
const overlay = overlayMap.get(path);
|
|
71
|
+
const relabel = overlay?.modifications.find((m) => m.op === "relabel");
|
|
72
|
+
return relabel && relabel.op === "relabel" ? relabel.label : defaultLabel;
|
|
73
|
+
}, [overlayMap]);
|
|
74
|
+
const getPosition = useMemo(() => (path, defaultPosition) => {
|
|
75
|
+
const overlay = overlayMap.get(path);
|
|
76
|
+
const reorder = overlay?.modifications.find((m) => m.op === "reorder");
|
|
77
|
+
return reorder && reorder.op === "reorder" ? reorder.position : defaultPosition;
|
|
78
|
+
}, [overlayMap]);
|
|
79
|
+
const getStyle = useMemo(() => (path) => {
|
|
80
|
+
const overlay = overlayMap.get(path);
|
|
81
|
+
const restyle = overlay?.modifications.find((m) => m.op === "restyle");
|
|
82
|
+
if (restyle && restyle.op === "restyle") {
|
|
83
|
+
return {
|
|
84
|
+
className: restyle.className,
|
|
85
|
+
variant: restyle.variant
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return {};
|
|
89
|
+
}, [overlayMap]);
|
|
90
|
+
const getDefault = useMemo(() => (path, defaultValue) => {
|
|
91
|
+
const overlay = overlayMap.get(path);
|
|
92
|
+
const setDefault = overlay?.modifications.find((m) => m.op === "set-default");
|
|
93
|
+
return setDefault && setDefault.op === "set-default" ? setDefault.value : defaultValue;
|
|
94
|
+
}, [overlayMap]);
|
|
95
|
+
const value = useMemo(() => ({
|
|
96
|
+
overlays: activeOverlays,
|
|
97
|
+
applyOverlay,
|
|
98
|
+
isHidden,
|
|
99
|
+
getLabel,
|
|
100
|
+
getPosition,
|
|
101
|
+
getStyle,
|
|
102
|
+
getDefault,
|
|
103
|
+
role,
|
|
104
|
+
device
|
|
105
|
+
}), [
|
|
106
|
+
activeOverlays,
|
|
107
|
+
applyOverlay,
|
|
108
|
+
isHidden,
|
|
109
|
+
getLabel,
|
|
110
|
+
getPosition,
|
|
111
|
+
getStyle,
|
|
112
|
+
getDefault,
|
|
113
|
+
role,
|
|
114
|
+
device
|
|
115
|
+
]);
|
|
116
|
+
return /* @__PURE__ */ jsxDEV(OverlayContext.Provider, {
|
|
117
|
+
value,
|
|
118
|
+
children
|
|
119
|
+
}, undefined, false, undefined, this);
|
|
120
|
+
}
|
|
121
|
+
function useOverlayContext() {
|
|
122
|
+
const context = useContext(OverlayContext);
|
|
123
|
+
if (!context) {
|
|
124
|
+
throw new Error("useOverlayContext must be used within an OverlayContextProvider");
|
|
125
|
+
}
|
|
126
|
+
return context;
|
|
127
|
+
}
|
|
128
|
+
function useIsInOverlayContext() {
|
|
129
|
+
return useContext(OverlayContext) !== null;
|
|
130
|
+
}
|
|
131
|
+
function getTemplateOverlays(templateId, _role) {
|
|
132
|
+
const templateOverlays = {
|
|
133
|
+
"crm-pipeline": [
|
|
134
|
+
{
|
|
135
|
+
id: "crm-hide-internal-fields",
|
|
136
|
+
target: "deal.internalNotes",
|
|
137
|
+
modifications: [{ op: "hide" }],
|
|
138
|
+
conditions: { role: ["viewer", "user"] }
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
id: "crm-relabel-value",
|
|
142
|
+
target: "deal.value",
|
|
143
|
+
modifications: [{ op: "relabel", label: "Deal Amount" }]
|
|
144
|
+
}
|
|
145
|
+
],
|
|
146
|
+
"saas-boilerplate": [
|
|
147
|
+
{
|
|
148
|
+
id: "saas-hide-billing",
|
|
149
|
+
target: "settings.billing",
|
|
150
|
+
modifications: [{ op: "hide" }],
|
|
151
|
+
conditions: { role: ["viewer"] }
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
id: "saas-restyle-plan",
|
|
155
|
+
target: "settings.plan",
|
|
156
|
+
modifications: [{ op: "restyle", variant: "premium" }],
|
|
157
|
+
conditions: { role: ["admin"] }
|
|
158
|
+
}
|
|
159
|
+
],
|
|
160
|
+
"agent-console": [
|
|
161
|
+
{
|
|
162
|
+
id: "agent-hide-cost",
|
|
163
|
+
target: "run.cost",
|
|
164
|
+
modifications: [{ op: "hide" }],
|
|
165
|
+
conditions: { role: ["viewer"] }
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
id: "agent-relabel-tokens",
|
|
169
|
+
target: "run.tokens",
|
|
170
|
+
modifications: [{ op: "relabel", label: "Token Usage" }]
|
|
171
|
+
}
|
|
172
|
+
],
|
|
173
|
+
"todos-app": [
|
|
174
|
+
{
|
|
175
|
+
id: "todos-hide-assignee",
|
|
176
|
+
target: "task.assignee",
|
|
177
|
+
modifications: [{ op: "hide" }],
|
|
178
|
+
conditions: { device: "mobile" }
|
|
179
|
+
}
|
|
180
|
+
],
|
|
181
|
+
"messaging-app": [
|
|
182
|
+
{
|
|
183
|
+
id: "messaging-reorder-timestamp",
|
|
184
|
+
target: "message.timestamp",
|
|
185
|
+
modifications: [{ op: "reorder", position: 0 }]
|
|
186
|
+
}
|
|
187
|
+
],
|
|
188
|
+
"recipe-app-i18n": [
|
|
189
|
+
{
|
|
190
|
+
id: "recipe-relabel-servings",
|
|
191
|
+
target: "recipe.servings",
|
|
192
|
+
modifications: [{ op: "relabel", label: "Portions" }]
|
|
193
|
+
}
|
|
194
|
+
]
|
|
195
|
+
};
|
|
196
|
+
return templateOverlays[templateId] ?? [];
|
|
197
|
+
}
|
|
198
|
+
export {
|
|
199
|
+
useOverlayContext,
|
|
200
|
+
useIsInOverlayContext,
|
|
201
|
+
OverlayContextProvider
|
|
202
|
+
};
|