@contractspec/lib.example-shared-ui 1.11.0 → 1.12.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.
Files changed (121) hide show
  1. package/.turbo/turbo-build.log +86 -11
  2. package/.turbo/turbo-prebuild.log +1 -0
  3. package/CHANGELOG.md +14 -0
  4. package/dist/EvolutionDashboard.d.ts +11 -0
  5. package/dist/EvolutionDashboard.d.ts.map +1 -0
  6. package/dist/EvolutionDashboard.js +804 -0
  7. package/dist/EvolutionSidebar.d.ts +19 -0
  8. package/dist/EvolutionSidebar.d.ts.map +1 -0
  9. package/dist/EvolutionSidebar.js +532 -0
  10. package/dist/LocalDataIndicator.d.ts +2 -0
  11. package/dist/LocalDataIndicator.d.ts.map +1 -0
  12. package/dist/LocalDataIndicator.js +63 -0
  13. package/dist/MarkdownView.d.ts +20 -0
  14. package/dist/MarkdownView.d.ts.map +1 -0
  15. package/dist/MarkdownView.js +304 -0
  16. package/dist/OverlayContextProvider.d.ts +79 -0
  17. package/dist/OverlayContextProvider.d.ts.map +1 -0
  18. package/dist/OverlayContextProvider.js +203 -0
  19. package/dist/PersonalizationInsights.d.ts +14 -0
  20. package/dist/PersonalizationInsights.d.ts.map +1 -0
  21. package/dist/PersonalizationInsights.js +456 -0
  22. package/dist/SaveToStudioButton.d.ts +8 -0
  23. package/dist/SaveToStudioButton.d.ts.map +1 -0
  24. package/dist/SaveToStudioButton.js +74 -0
  25. package/dist/SpecEditorPanel.d.ts +23 -0
  26. package/dist/SpecEditorPanel.d.ts.map +1 -0
  27. package/dist/SpecEditorPanel.js +720 -0
  28. package/dist/TemplateShell.d.ts +13 -0
  29. package/dist/TemplateShell.d.ts.map +1 -0
  30. package/dist/TemplateShell.js +190 -0
  31. package/dist/browser/EvolutionDashboard.js +803 -0
  32. package/dist/browser/EvolutionSidebar.js +531 -0
  33. package/dist/browser/LocalDataIndicator.js +62 -0
  34. package/dist/browser/MarkdownView.js +303 -0
  35. package/dist/browser/OverlayContextProvider.js +202 -0
  36. package/dist/browser/PersonalizationInsights.js +455 -0
  37. package/dist/browser/SaveToStudioButton.js +73 -0
  38. package/dist/browser/SpecEditorPanel.js +719 -0
  39. package/dist/browser/TemplateShell.js +189 -0
  40. package/dist/browser/hooks/index.js +1516 -0
  41. package/dist/browser/hooks/useBehaviorTracking.js +157 -0
  42. package/dist/browser/hooks/useEvolution.js +260 -0
  43. package/dist/browser/hooks/useRegistryTemplates.js +31 -0
  44. package/dist/browser/hooks/useSpecContent.js +579 -0
  45. package/dist/browser/hooks/useWorkflowComposer.js +493 -0
  46. package/dist/browser/index.js +3497 -0
  47. package/dist/browser/lib/component-registry.js +42 -0
  48. package/dist/browser/lib/runtime-context.js +15 -0
  49. package/dist/browser/lib/types.js +0 -0
  50. package/dist/browser/overlay-types.js +0 -0
  51. package/dist/browser/utils/fetchPresentationData.js +15 -0
  52. package/dist/browser/utils/generateSpecFromTemplate.js +423 -0
  53. package/dist/browser/utils/index.js +437 -0
  54. package/dist/hooks/index.d.ts +6 -0
  55. package/dist/hooks/index.d.ts.map +1 -0
  56. package/dist/hooks/index.js +1517 -0
  57. package/dist/hooks/useBehaviorTracking.d.ts +56 -0
  58. package/dist/hooks/useBehaviorTracking.d.ts.map +1 -0
  59. package/dist/hooks/useBehaviorTracking.js +158 -0
  60. package/dist/hooks/useEvolution.d.ts +111 -0
  61. package/dist/hooks/useEvolution.d.ts.map +1 -0
  62. package/dist/hooks/useEvolution.js +261 -0
  63. package/dist/hooks/useRegistryTemplates.d.ts +10 -0
  64. package/dist/hooks/useRegistryTemplates.d.ts.map +1 -0
  65. package/dist/hooks/useRegistryTemplates.js +32 -0
  66. package/dist/hooks/useSpecContent.d.ts +41 -0
  67. package/dist/hooks/useSpecContent.d.ts.map +1 -0
  68. package/dist/hooks/useSpecContent.js +580 -0
  69. package/dist/hooks/useWorkflowComposer.d.ts +94 -0
  70. package/dist/hooks/useWorkflowComposer.d.ts.map +1 -0
  71. package/dist/hooks/useWorkflowComposer.js +494 -0
  72. package/dist/index.d.ts +16 -0
  73. package/dist/index.d.ts.map +1 -0
  74. package/dist/index.js +3498 -0
  75. package/dist/lib/component-registry.d.ts +18 -0
  76. package/dist/lib/component-registry.d.ts.map +1 -0
  77. package/dist/lib/component-registry.js +43 -0
  78. package/dist/lib/runtime-context.d.ts +29 -0
  79. package/dist/lib/runtime-context.d.ts.map +1 -0
  80. package/dist/lib/runtime-context.js +16 -0
  81. package/dist/lib/types.d.ts +69 -0
  82. package/dist/lib/types.d.ts.map +1 -0
  83. package/dist/lib/types.js +1 -0
  84. package/dist/node/EvolutionDashboard.js +803 -0
  85. package/dist/node/EvolutionSidebar.js +531 -0
  86. package/dist/node/LocalDataIndicator.js +62 -0
  87. package/dist/node/MarkdownView.js +303 -0
  88. package/dist/node/OverlayContextProvider.js +202 -0
  89. package/dist/node/PersonalizationInsights.js +455 -0
  90. package/dist/node/SaveToStudioButton.js +73 -0
  91. package/dist/node/SpecEditorPanel.js +719 -0
  92. package/dist/node/TemplateShell.js +189 -0
  93. package/dist/node/hooks/index.js +1516 -0
  94. package/dist/node/hooks/useBehaviorTracking.js +157 -0
  95. package/dist/node/hooks/useEvolution.js +260 -0
  96. package/dist/node/hooks/useRegistryTemplates.js +31 -0
  97. package/dist/node/hooks/useSpecContent.js +579 -0
  98. package/dist/node/hooks/useWorkflowComposer.js +493 -0
  99. package/dist/node/index.js +3497 -0
  100. package/dist/node/lib/component-registry.js +42 -0
  101. package/dist/node/lib/runtime-context.js +15 -0
  102. package/dist/node/lib/types.js +0 -0
  103. package/dist/node/overlay-types.js +0 -0
  104. package/dist/node/utils/fetchPresentationData.js +15 -0
  105. package/dist/node/utils/generateSpecFromTemplate.js +423 -0
  106. package/dist/node/utils/index.js +437 -0
  107. package/dist/overlay-types.d.ts +41 -0
  108. package/dist/overlay-types.d.ts.map +1 -0
  109. package/dist/overlay-types.js +1 -0
  110. package/dist/utils/fetchPresentationData.d.ts +34 -0
  111. package/dist/utils/fetchPresentationData.d.ts.map +1 -0
  112. package/dist/utils/fetchPresentationData.js +16 -0
  113. package/dist/utils/generateSpecFromTemplate.d.ts +7 -0
  114. package/dist/utils/generateSpecFromTemplate.d.ts.map +1 -0
  115. package/dist/utils/generateSpecFromTemplate.js +424 -0
  116. package/dist/utils/index.d.ts +3 -0
  117. package/dist/utils/index.d.ts.map +1 -0
  118. package/dist/utils/index.js +438 -0
  119. package/package.json +219 -14
  120. package/.turbo/turbo-build$colon$bundle.log +0 -9
  121. package/dist/index.mjs +0 -3121
@@ -0,0 +1,455 @@
1
+ // src/hooks/useBehaviorTracking.ts
2
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
3
+ "use client";
4
+ var BEHAVIOR_STORAGE_KEY = "contractspec-behavior-data";
5
+ var ALL_FEATURES = [
6
+ "playground",
7
+ "specs",
8
+ "builder",
9
+ "markdown",
10
+ "evolution",
11
+ "canvas_add",
12
+ "canvas_delete",
13
+ "spec_save",
14
+ "spec_validate",
15
+ "ai_suggestions"
16
+ ];
17
+ function useBehaviorTracking(templateId) {
18
+ const [events, setEvents] = useState([]);
19
+ const sessionStartRef = useRef(new Date);
20
+ const [eventCount, setEventCount] = useState(0);
21
+ useEffect(() => {
22
+ try {
23
+ const stored = localStorage.getItem(BEHAVIOR_STORAGE_KEY);
24
+ if (stored) {
25
+ const data = JSON.parse(stored);
26
+ setEvents(data.events.map((e) => ({
27
+ ...e,
28
+ timestamp: new Date(e.timestamp)
29
+ })));
30
+ sessionStartRef.current = new Date(data.sessionStart);
31
+ }
32
+ } catch {}
33
+ }, []);
34
+ useEffect(() => {
35
+ if (events.length > 0) {
36
+ try {
37
+ localStorage.setItem(BEHAVIOR_STORAGE_KEY, JSON.stringify({
38
+ events: events.map((e) => ({
39
+ ...e,
40
+ timestamp: e.timestamp.toISOString()
41
+ })),
42
+ sessionStart: sessionStartRef.current.toISOString()
43
+ }));
44
+ } catch {}
45
+ }
46
+ }, [events]);
47
+ const trackEvent = useCallback((type, metadata) => {
48
+ const event = {
49
+ type,
50
+ timestamp: new Date,
51
+ templateId,
52
+ metadata
53
+ };
54
+ setEvents((prev) => [...prev, event]);
55
+ setEventCount((prev) => prev + 1);
56
+ }, [templateId]);
57
+ const getEventsByType = useCallback((type) => {
58
+ return events.filter((e) => e.type === type);
59
+ }, [events]);
60
+ const getSummary = useCallback(() => {
61
+ const now = new Date;
62
+ const sessionDuration = now.getTime() - sessionStartRef.current.getTime();
63
+ const templateCounts = new Map;
64
+ for (const event of events) {
65
+ const count = templateCounts.get(event.templateId) ?? 0;
66
+ templateCounts.set(event.templateId, count + 1);
67
+ }
68
+ const mostUsedTemplates = Array.from(templateCounts.entries()).map(([templateId2, count]) => ({ templateId: templateId2, count })).sort((a, b) => b.count - a.count).slice(0, 3);
69
+ const modeCounts = new Map;
70
+ for (const event of events) {
71
+ if (event.type === "mode_change" && event.metadata?.mode) {
72
+ const mode = event.metadata.mode;
73
+ const count = modeCounts.get(mode) ?? 0;
74
+ modeCounts.set(mode, count + 1);
75
+ }
76
+ }
77
+ const mostUsedModes = Array.from(modeCounts.entries()).map(([mode, count]) => ({ mode, count })).sort((a, b) => b.count - a.count);
78
+ const featuresUsed = new Set;
79
+ for (const event of events) {
80
+ if (event.type === "mode_change" && event.metadata?.mode) {
81
+ featuresUsed.add(event.metadata.mode);
82
+ }
83
+ if (event.type === "feature_usage" && event.metadata?.feature) {
84
+ featuresUsed.add(event.metadata.feature);
85
+ }
86
+ if (event.type === "canvas_interaction") {
87
+ const action = event.metadata?.action;
88
+ if (action === "add")
89
+ featuresUsed.add("canvas_add");
90
+ if (action === "delete")
91
+ featuresUsed.add("canvas_delete");
92
+ }
93
+ if (event.type === "spec_edit") {
94
+ const action = event.metadata?.action;
95
+ if (action === "save")
96
+ featuresUsed.add("spec_save");
97
+ if (action === "validate")
98
+ featuresUsed.add("spec_validate");
99
+ }
100
+ }
101
+ const unusedFeatures = ALL_FEATURES.filter((f) => !featuresUsed.has(f));
102
+ const errorCount = events.filter((e) => e.type === "error").length;
103
+ const recommendations = generateRecommendations(Array.from(featuresUsed), unusedFeatures, mostUsedModes, events.length);
104
+ return {
105
+ totalEvents: events.length,
106
+ sessionDuration,
107
+ mostUsedTemplates,
108
+ mostUsedModes,
109
+ featuresUsed: Array.from(featuresUsed),
110
+ unusedFeatures,
111
+ errorCount,
112
+ recommendations
113
+ };
114
+ }, [events]);
115
+ const clear = useCallback(() => {
116
+ setEvents([]);
117
+ setEventCount(0);
118
+ sessionStartRef.current = new Date;
119
+ localStorage.removeItem(BEHAVIOR_STORAGE_KEY);
120
+ }, []);
121
+ return useMemo(() => ({
122
+ trackEvent,
123
+ getSummary,
124
+ getEventsByType,
125
+ eventCount,
126
+ sessionStart: sessionStartRef.current,
127
+ clear
128
+ }), [trackEvent, getSummary, getEventsByType, eventCount, clear]);
129
+ }
130
+ function generateRecommendations(featuresUsed, unusedFeatures, mostUsedModes, totalEvents) {
131
+ const recommendations = [];
132
+ if (unusedFeatures.includes("evolution")) {
133
+ recommendations.push("Try the AI Evolution mode to get automated improvement suggestions");
134
+ }
135
+ if (unusedFeatures.includes("markdown")) {
136
+ recommendations.push("Use Markdown preview to see documentation for your specs");
137
+ }
138
+ if (unusedFeatures.includes("builder")) {
139
+ recommendations.push("Explore the Visual Builder to design your UI components");
140
+ }
141
+ if (!featuresUsed.includes("spec_validate") && featuresUsed.includes("specs")) {
142
+ recommendations.push("Don't forget to validate your specs before saving");
143
+ }
144
+ if (featuresUsed.includes("evolution") && !featuresUsed.includes("ai_suggestions")) {
145
+ recommendations.push("Generate AI suggestions to get actionable improvement recommendations");
146
+ }
147
+ if (totalEvents > 50) {
148
+ recommendations.push("Great engagement! Consider saving your work regularly");
149
+ }
150
+ if (mostUsedModes.length === 1) {
151
+ recommendations.push("Try different modes to explore all sandbox capabilities");
152
+ }
153
+ return recommendations;
154
+ }
155
+
156
+ // src/PersonalizationInsights.tsx
157
+ import { useCallback as useCallback2, useMemo as useMemo2, useState as useState2 } from "react";
158
+ import { Button } from "@contractspec/lib.design-system";
159
+ import { Card } from "@contractspec/lib.ui-kit-web/ui/card";
160
+ import { Badge } from "@contractspec/lib.ui-kit-web/ui/badge";
161
+ import { jsxDEV } from "react/jsx-dev-runtime";
162
+ "use client";
163
+ function PersonalizationInsights({
164
+ templateId,
165
+ collapsed = false,
166
+ onToggle
167
+ }) {
168
+ const { getSummary, eventCount, clear, sessionStart } = useBehaviorTracking(templateId);
169
+ const [showDetails, setShowDetails] = useState2(false);
170
+ const summary = useMemo2(() => getSummary(), [getSummary]);
171
+ const formatDuration = useCallback2((ms) => {
172
+ const seconds = Math.floor(ms / 1000);
173
+ const minutes = Math.floor(seconds / 60);
174
+ const hours = Math.floor(minutes / 60);
175
+ if (hours > 0) {
176
+ return `${hours}h ${minutes % 60}m`;
177
+ }
178
+ if (minutes > 0) {
179
+ return `${minutes}m ${seconds % 60}s`;
180
+ }
181
+ return `${seconds}s`;
182
+ }, []);
183
+ const handleClear = useCallback2(() => {
184
+ clear();
185
+ }, [clear]);
186
+ if (collapsed) {
187
+ return /* @__PURE__ */ jsxDEV("button", {
188
+ onClick: onToggle,
189
+ className: "flex items-center gap-2 rounded-lg border border-blue-500/30 bg-blue-500/10 px-3 py-2 text-sm transition hover:bg-blue-500/20",
190
+ type: "button",
191
+ children: [
192
+ /* @__PURE__ */ jsxDEV("span", {
193
+ children: "\uD83D\uDCCA"
194
+ }, undefined, false, undefined, this),
195
+ /* @__PURE__ */ jsxDEV("span", {
196
+ children: "Insights"
197
+ }, undefined, false, undefined, this),
198
+ /* @__PURE__ */ jsxDEV(Badge, {
199
+ variant: "secondary",
200
+ children: eventCount
201
+ }, undefined, false, undefined, this)
202
+ ]
203
+ }, undefined, true, undefined, this);
204
+ }
205
+ return /* @__PURE__ */ jsxDEV(Card, {
206
+ className: "overflow-hidden",
207
+ children: [
208
+ /* @__PURE__ */ jsxDEV("div", {
209
+ className: "flex items-center justify-between border-b border-blue-500/20 bg-blue-500/5 px-4 py-3",
210
+ children: [
211
+ /* @__PURE__ */ jsxDEV("div", {
212
+ className: "flex items-center gap-2",
213
+ children: [
214
+ /* @__PURE__ */ jsxDEV("span", {
215
+ children: "\uD83D\uDCCA"
216
+ }, undefined, false, undefined, this),
217
+ /* @__PURE__ */ jsxDEV("span", {
218
+ className: "font-semibold",
219
+ children: "Personalization Insights"
220
+ }, undefined, false, undefined, this)
221
+ ]
222
+ }, undefined, true, undefined, this),
223
+ /* @__PURE__ */ jsxDEV("div", {
224
+ className: "flex items-center gap-2",
225
+ children: [
226
+ /* @__PURE__ */ jsxDEV(Button, {
227
+ variant: "ghost",
228
+ size: "sm",
229
+ onPress: () => setShowDetails(!showDetails),
230
+ children: showDetails ? "Hide Details" : "Show Details"
231
+ }, undefined, false, undefined, this),
232
+ onToggle && /* @__PURE__ */ jsxDEV("button", {
233
+ onClick: onToggle,
234
+ className: "text-muted-foreground hover:text-foreground p-1",
235
+ type: "button",
236
+ title: "Collapse",
237
+ children: "✕"
238
+ }, undefined, false, undefined, this)
239
+ ]
240
+ }, undefined, true, undefined, this)
241
+ ]
242
+ }, undefined, true, undefined, this),
243
+ /* @__PURE__ */ jsxDEV("div", {
244
+ className: "p-4",
245
+ children: [
246
+ /* @__PURE__ */ jsxDEV("div", {
247
+ className: "mb-4 grid grid-cols-2 gap-3 md:grid-cols-4",
248
+ children: [
249
+ /* @__PURE__ */ jsxDEV(StatCard, {
250
+ label: "Session Time",
251
+ value: formatDuration(summary.sessionDuration),
252
+ icon: "⏱️"
253
+ }, undefined, false, undefined, this),
254
+ /* @__PURE__ */ jsxDEV(StatCard, {
255
+ label: "Events Tracked",
256
+ value: summary.totalEvents.toString(),
257
+ icon: "\uD83D\uDCC8"
258
+ }, undefined, false, undefined, this),
259
+ /* @__PURE__ */ jsxDEV(StatCard, {
260
+ label: "Features Used",
261
+ value: `${summary.featuresUsed.length}/${summary.featuresUsed.length + summary.unusedFeatures.length}`,
262
+ icon: "✨"
263
+ }, undefined, false, undefined, this),
264
+ /* @__PURE__ */ jsxDEV(StatCard, {
265
+ label: "Errors",
266
+ value: summary.errorCount.toString(),
267
+ icon: "⚠️",
268
+ variant: summary.errorCount > 0 ? "warning" : "success"
269
+ }, undefined, false, undefined, this)
270
+ ]
271
+ }, undefined, true, undefined, this),
272
+ summary.recommendations.length > 0 && /* @__PURE__ */ jsxDEV("div", {
273
+ className: "mb-4",
274
+ children: [
275
+ /* @__PURE__ */ jsxDEV("h4", {
276
+ className: "mb-2 text-xs font-semibold text-blue-400 uppercase",
277
+ children: "Recommendations"
278
+ }, undefined, false, undefined, this),
279
+ /* @__PURE__ */ jsxDEV("ul", {
280
+ className: "space-y-1",
281
+ children: summary.recommendations.map((rec, index) => /* @__PURE__ */ jsxDEV("li", {
282
+ className: "flex items-start gap-2 text-sm",
283
+ children: [
284
+ /* @__PURE__ */ jsxDEV("span", {
285
+ className: "text-blue-400",
286
+ children: "\uD83D\uDCA1"
287
+ }, undefined, false, undefined, this),
288
+ /* @__PURE__ */ jsxDEV("span", {
289
+ children: rec
290
+ }, undefined, false, undefined, this)
291
+ ]
292
+ }, index, true, undefined, this))
293
+ }, undefined, false, undefined, this)
294
+ ]
295
+ }, undefined, true, undefined, this),
296
+ summary.unusedFeatures.length > 0 && /* @__PURE__ */ jsxDEV("div", {
297
+ className: "mb-4",
298
+ children: [
299
+ /* @__PURE__ */ jsxDEV("h4", {
300
+ className: "mb-2 text-xs font-semibold text-blue-400 uppercase",
301
+ children: "Try These Features"
302
+ }, undefined, false, undefined, this),
303
+ /* @__PURE__ */ jsxDEV("div", {
304
+ className: "flex flex-wrap gap-2",
305
+ children: summary.unusedFeatures.slice(0, 5).map((feature) => /* @__PURE__ */ jsxDEV(Badge, {
306
+ variant: "secondary",
307
+ children: formatFeatureName(feature)
308
+ }, feature, false, undefined, this))
309
+ }, undefined, false, undefined, this)
310
+ ]
311
+ }, undefined, true, undefined, this),
312
+ showDetails && /* @__PURE__ */ jsxDEV(DetailedInsights, {
313
+ summary,
314
+ sessionStart
315
+ }, undefined, false, undefined, this),
316
+ /* @__PURE__ */ jsxDEV("div", {
317
+ className: "mt-4 flex justify-end border-t border-blue-500/10 pt-4",
318
+ children: /* @__PURE__ */ jsxDEV(Button, {
319
+ variant: "ghost",
320
+ size: "sm",
321
+ onPress: handleClear,
322
+ children: "Clear Data"
323
+ }, undefined, false, undefined, this)
324
+ }, undefined, false, undefined, this)
325
+ ]
326
+ }, undefined, true, undefined, this)
327
+ ]
328
+ }, undefined, true, undefined, this);
329
+ }
330
+ function StatCard({
331
+ label,
332
+ value,
333
+ icon,
334
+ variant = "default"
335
+ }) {
336
+ const bgColors = {
337
+ default: "bg-blue-500/5 border-blue-500/20",
338
+ warning: "bg-amber-500/5 border-amber-500/20",
339
+ success: "bg-green-500/5 border-green-500/20"
340
+ };
341
+ return /* @__PURE__ */ jsxDEV("div", {
342
+ className: `rounded-lg border p-3 text-center ${bgColors[variant]}`,
343
+ children: [
344
+ /* @__PURE__ */ jsxDEV("div", {
345
+ className: "mb-1 text-lg",
346
+ children: icon
347
+ }, undefined, false, undefined, this),
348
+ /* @__PURE__ */ jsxDEV("div", {
349
+ className: "text-lg font-bold",
350
+ children: value
351
+ }, undefined, false, undefined, this),
352
+ /* @__PURE__ */ jsxDEV("div", {
353
+ className: "text-muted-foreground text-xs",
354
+ children: label
355
+ }, undefined, false, undefined, this)
356
+ ]
357
+ }, undefined, true, undefined, this);
358
+ }
359
+ function DetailedInsights({
360
+ summary,
361
+ sessionStart
362
+ }) {
363
+ return /* @__PURE__ */ jsxDEV("div", {
364
+ className: "mt-4 space-y-4 border-t border-blue-500/10 pt-4",
365
+ children: [
366
+ summary.mostUsedTemplates.length > 0 && /* @__PURE__ */ jsxDEV("div", {
367
+ children: [
368
+ /* @__PURE__ */ jsxDEV("h4", {
369
+ className: "mb-2 text-xs font-semibold text-blue-400 uppercase",
370
+ children: "Most Used Templates"
371
+ }, undefined, false, undefined, this),
372
+ /* @__PURE__ */ jsxDEV("div", {
373
+ className: "space-y-1",
374
+ children: summary.mostUsedTemplates.map(({ templateId, count }) => /* @__PURE__ */ jsxDEV("div", {
375
+ className: "flex items-center justify-between text-sm",
376
+ children: [
377
+ /* @__PURE__ */ jsxDEV("span", {
378
+ children: formatTemplateId(templateId)
379
+ }, undefined, false, undefined, this),
380
+ /* @__PURE__ */ jsxDEV("span", {
381
+ className: "text-muted-foreground",
382
+ children: [
383
+ count,
384
+ " events"
385
+ ]
386
+ }, undefined, true, undefined, this)
387
+ ]
388
+ }, templateId, true, undefined, this))
389
+ }, undefined, false, undefined, this)
390
+ ]
391
+ }, undefined, true, undefined, this),
392
+ summary.mostUsedModes.length > 0 && /* @__PURE__ */ jsxDEV("div", {
393
+ children: [
394
+ /* @__PURE__ */ jsxDEV("h4", {
395
+ className: "mb-2 text-xs font-semibold text-blue-400 uppercase",
396
+ children: "Mode Usage"
397
+ }, undefined, false, undefined, this),
398
+ /* @__PURE__ */ jsxDEV("div", {
399
+ className: "space-y-1",
400
+ children: summary.mostUsedModes.map(({ mode, count }) => /* @__PURE__ */ jsxDEV("div", {
401
+ className: "flex items-center justify-between text-sm",
402
+ children: [
403
+ /* @__PURE__ */ jsxDEV("span", {
404
+ children: formatFeatureName(mode)
405
+ }, undefined, false, undefined, this),
406
+ /* @__PURE__ */ jsxDEV("span", {
407
+ className: "text-muted-foreground",
408
+ children: [
409
+ count,
410
+ " switches"
411
+ ]
412
+ }, undefined, true, undefined, this)
413
+ ]
414
+ }, mode, true, undefined, this))
415
+ }, undefined, false, undefined, this)
416
+ ]
417
+ }, undefined, true, undefined, this),
418
+ /* @__PURE__ */ jsxDEV("div", {
419
+ children: [
420
+ /* @__PURE__ */ jsxDEV("h4", {
421
+ className: "mb-2 text-xs font-semibold text-blue-400 uppercase",
422
+ children: "Features Used"
423
+ }, undefined, false, undefined, this),
424
+ /* @__PURE__ */ jsxDEV("div", {
425
+ className: "flex flex-wrap gap-2",
426
+ children: summary.featuresUsed.map((feature) => /* @__PURE__ */ jsxDEV(Badge, {
427
+ variant: "default",
428
+ className: "border-green-500/30 bg-green-500/20 text-green-400",
429
+ children: [
430
+ "✓ ",
431
+ formatFeatureName(feature)
432
+ ]
433
+ }, feature, true, undefined, this))
434
+ }, undefined, false, undefined, this)
435
+ ]
436
+ }, undefined, true, undefined, this),
437
+ /* @__PURE__ */ jsxDEV("div", {
438
+ className: "text-muted-foreground text-xs",
439
+ children: [
440
+ "Session started: ",
441
+ sessionStart.toLocaleString()
442
+ ]
443
+ }, undefined, true, undefined, this)
444
+ ]
445
+ }, undefined, true, undefined, this);
446
+ }
447
+ function formatFeatureName(feature) {
448
+ return feature.replace(/_/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
449
+ }
450
+ function formatTemplateId(id) {
451
+ return id.replace(/-/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
452
+ }
453
+ export {
454
+ PersonalizationInsights
455
+ };
@@ -0,0 +1,73 @@
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/SaveToStudioButton.tsx
14
+ import { useState } from "react";
15
+ import { Sparkles } from "lucide-react";
16
+ import { jsxDEV } from "react/jsx-dev-runtime";
17
+ "use client";
18
+ function SaveToStudioButton({
19
+ organizationId = "demo-org",
20
+ projectName,
21
+ endpoint,
22
+ token
23
+ }) {
24
+ const { installer, templateId, template } = useTemplateRuntime();
25
+ const [status, setStatus] = useState("idle");
26
+ const [error, setError] = useState(null);
27
+ const handleSave = async () => {
28
+ setStatus("saving");
29
+ setError(null);
30
+ try {
31
+ await installer.saveToStudio({
32
+ templateId,
33
+ projectName: projectName ?? `${template.name} demo`,
34
+ organizationId,
35
+ endpoint,
36
+ token
37
+ });
38
+ setStatus("saved");
39
+ setTimeout(() => setStatus("idle"), 3000);
40
+ } catch (err) {
41
+ setStatus("error");
42
+ setError(err instanceof Error ? err.message : "Unknown error");
43
+ }
44
+ };
45
+ return /* @__PURE__ */ jsxDEV("div", {
46
+ className: "flex flex-col items-end gap-1",
47
+ children: [
48
+ /* @__PURE__ */ jsxDEV("button", {
49
+ type: "button",
50
+ className: "btn-primary inline-flex items-center gap-2 text-sm",
51
+ onClick: handleSave,
52
+ disabled: status === "saving",
53
+ children: [
54
+ /* @__PURE__ */ jsxDEV(Sparkles, {
55
+ className: "h-4 w-4"
56
+ }, undefined, false, undefined, this),
57
+ status === "saving" ? "Publishing…" : "Save to Studio"
58
+ ]
59
+ }, undefined, true, undefined, this),
60
+ status === "error" && error ? /* @__PURE__ */ jsxDEV("p", {
61
+ className: "text-destructive text-xs",
62
+ children: error
63
+ }, undefined, false, undefined, this) : null,
64
+ status === "saved" ? /* @__PURE__ */ jsxDEV("p", {
65
+ className: "text-xs text-emerald-400",
66
+ children: "Template sent to Studio."
67
+ }, undefined, false, undefined, this) : null
68
+ ]
69
+ }, undefined, true, undefined, this);
70
+ }
71
+ export {
72
+ SaveToStudioButton
73
+ };