@contractspec/lib.example-shared-ui 6.0.17 → 6.0.18

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 (84) hide show
  1. package/.turbo/turbo-build.log +81 -81
  2. package/CHANGELOG.md +17 -0
  3. package/dist/EvolutionDashboard.js +1 -803
  4. package/dist/EvolutionSidebar.js +1 -531
  5. package/dist/LocalDataIndicator.js +1 -68
  6. package/dist/MarkdownView.js +1 -213
  7. package/dist/OverlayContextProvider.js +1 -202
  8. package/dist/PersonalizationInsights.js +1 -455
  9. package/dist/SaveToStudioButton.js +1 -79
  10. package/dist/SpecDrivenTemplateShell.js +1 -203
  11. package/dist/SpecEditorPanel.js +17 -364
  12. package/dist/TemplateShell.js +1 -195
  13. package/dist/browser/EvolutionDashboard.js +1 -803
  14. package/dist/browser/EvolutionSidebar.js +1 -531
  15. package/dist/browser/LocalDataIndicator.js +1 -68
  16. package/dist/browser/MarkdownView.js +1 -213
  17. package/dist/browser/OverlayContextProvider.js +1 -202
  18. package/dist/browser/PersonalizationInsights.js +1 -455
  19. package/dist/browser/SaveToStudioButton.js +1 -79
  20. package/dist/browser/SpecDrivenTemplateShell.js +1 -203
  21. package/dist/browser/SpecEditorPanel.js +17 -364
  22. package/dist/browser/TemplateShell.js +1 -195
  23. package/dist/browser/bundles/ExampleTemplateBundle.js +1 -85
  24. package/dist/browser/bundles/index.js +1 -85
  25. package/dist/browser/hooks/index.js +40 -1151
  26. package/dist/browser/hooks/useBehaviorTracking.js +1 -157
  27. package/dist/browser/hooks/useEvolution.js +1 -260
  28. package/dist/browser/hooks/useRegistryTemplates.js +1 -31
  29. package/dist/browser/hooks/useSpecContent.js +17 -224
  30. package/dist/browser/hooks/useWorkflowComposer.js +24 -483
  31. package/dist/browser/index.js +40 -3122
  32. package/dist/browser/lib/component-registry.js +1 -48
  33. package/dist/browser/lib/runtime-context.js +1 -21
  34. package/dist/browser/markdown/formatPresentationName.js +1 -9
  35. package/dist/browser/markdown/useMarkdownPresentation.js +1 -65
  36. package/dist/browser/utils/fetchPresentationData.js +1 -15
  37. package/dist/browser/utils/generateSpecFromTemplate.js +16 -62
  38. package/dist/browser/utils/index.js +16 -76
  39. package/dist/bundles/ExampleTemplateBundle.js +1 -85
  40. package/dist/bundles/index.js +1 -85
  41. package/dist/hooks/index.js +40 -1151
  42. package/dist/hooks/useBehaviorTracking.js +1 -157
  43. package/dist/hooks/useEvolution.js +1 -260
  44. package/dist/hooks/useRegistryTemplates.js +1 -31
  45. package/dist/hooks/useSpecContent.js +17 -224
  46. package/dist/hooks/useWorkflowComposer.js +24 -483
  47. package/dist/index.js +40 -3122
  48. package/dist/lib/component-registry.js +1 -48
  49. package/dist/lib/runtime-context.js +1 -21
  50. package/dist/markdown/formatPresentationName.js +1 -9
  51. package/dist/markdown/useMarkdownPresentation.js +1 -65
  52. package/dist/node/EvolutionDashboard.js +1 -803
  53. package/dist/node/EvolutionSidebar.js +1 -531
  54. package/dist/node/LocalDataIndicator.js +1 -68
  55. package/dist/node/MarkdownView.js +1 -213
  56. package/dist/node/OverlayContextProvider.js +1 -202
  57. package/dist/node/PersonalizationInsights.js +1 -455
  58. package/dist/node/SaveToStudioButton.js +1 -79
  59. package/dist/node/SpecDrivenTemplateShell.js +1 -203
  60. package/dist/node/SpecEditorPanel.js +17 -364
  61. package/dist/node/TemplateShell.js +1 -195
  62. package/dist/node/bundles/ExampleTemplateBundle.js +1 -85
  63. package/dist/node/bundles/index.js +1 -85
  64. package/dist/node/hooks/index.js +40 -1151
  65. package/dist/node/hooks/useBehaviorTracking.js +1 -157
  66. package/dist/node/hooks/useEvolution.js +1 -260
  67. package/dist/node/hooks/useRegistryTemplates.js +1 -31
  68. package/dist/node/hooks/useSpecContent.js +17 -224
  69. package/dist/node/hooks/useWorkflowComposer.js +24 -483
  70. package/dist/node/index.js +40 -3122
  71. package/dist/node/lib/component-registry.js +1 -48
  72. package/dist/node/lib/runtime-context.js +1 -21
  73. package/dist/node/markdown/formatPresentationName.js +1 -9
  74. package/dist/node/markdown/useMarkdownPresentation.js +1 -65
  75. package/dist/node/utils/fetchPresentationData.js +1 -15
  76. package/dist/node/utils/generateSpecFromTemplate.js +16 -62
  77. package/dist/node/utils/index.js +16 -76
  78. package/dist/utils/fetchPresentationData.js +1 -15
  79. package/dist/utils/generateSpecFromTemplate.js +16 -62
  80. package/dist/utils/index.js +16 -76
  81. package/package.json +13 -13
  82. package/src/lib/component-registry.tsx +2 -1
  83. package/src/lib/runtime-context.tsx +1 -1
  84. package/src/lib/singletons.test.ts +19 -22
@@ -1,455 +1 @@
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 { Button } from "@contractspec/lib.design-system";
158
- import { Badge } from "@contractspec/lib.ui-kit-web/ui/badge";
159
- import { Card } from "@contractspec/lib.ui-kit-web/ui/card";
160
- import { useCallback as useCallback2, useMemo as useMemo2, useState as useState2 } from "react";
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-blue-500/20 border-b 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: "p-1 text-muted-foreground hover:text-foreground",
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 font-semibold text-blue-400 text-xs 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 font-semibold text-blue-400 text-xs 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-blue-500/10 border-t 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: "font-bold text-lg",
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-blue-500/10 border-t pt-4",
365
- children: [
366
- summary.mostUsedTemplates.length > 0 && /* @__PURE__ */ jsxDEV("div", {
367
- children: [
368
- /* @__PURE__ */ jsxDEV("h4", {
369
- className: "mb-2 font-semibold text-blue-400 text-xs 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 font-semibold text-blue-400 text-xs 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 font-semibold text-blue-400 text-xs 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
- };
1
+ import{useCallback as A,useEffect as b,useMemo as p,useRef as y,useState as I}from"react";var k="contractspec-behavior-data",f=["playground","specs","builder","markdown","evolution","canvas_add","canvas_delete","spec_save","spec_validate","ai_suggestions"];function T(P){let[J,W]=I([]),Z=y(new Date),[H,O]=I(0);b(()=>{try{let K=localStorage.getItem(k);if(K){let V=JSON.parse(K);W(V.events.map((L)=>({...L,timestamp:new Date(L.timestamp)}))),Z.current=new Date(V.sessionStart)}}catch{}},[]),b(()=>{if(J.length>0)try{localStorage.setItem(k,JSON.stringify({events:J.map((K)=>({...K,timestamp:K.timestamp.toISOString()})),sessionStart:Z.current.toISOString()}))}catch{}},[J]);let M=A((K,V)=>{let L={type:K,timestamp:new Date,templateId:P,metadata:V};W((N)=>[...N,L]),O((N)=>N+1)},[P]),w=A((K)=>{return J.filter((V)=>V.type===K)},[J]),_=A(()=>{let V=new Date().getTime()-Z.current.getTime(),L=new Map;for(let z of J){let X=L.get(z.templateId)??0;L.set(z.templateId,X+1)}let N=Array.from(L.entries()).map(([z,X])=>({templateId:z,count:X})).sort((z,X)=>X.count-z.count).slice(0,3),G=new Map;for(let z of J)if(z.type==="mode_change"&&z.metadata?.mode){let X=z.metadata.mode,g=G.get(X)??0;G.set(X,g+1)}let D=Array.from(G.entries()).map(([z,X])=>({mode:z,count:X})).sort((z,X)=>X.count-z.count),Y=new Set;for(let z of J){if(z.type==="mode_change"&&z.metadata?.mode)Y.add(z.metadata.mode);if(z.type==="feature_usage"&&z.metadata?.feature)Y.add(z.metadata.feature);if(z.type==="canvas_interaction"){let X=z.metadata?.action;if(X==="add")Y.add("canvas_add");if(X==="delete")Y.add("canvas_delete")}if(z.type==="spec_edit"){let X=z.metadata?.action;if(X==="save")Y.add("spec_save");if(X==="validate")Y.add("spec_validate")}}let R=f.filter((z)=>!Y.has(z)),E=J.filter((z)=>z.type==="error").length,S=j(Array.from(Y),R,D,J.length);return{totalEvents:J.length,sessionDuration:V,mostUsedTemplates:N,mostUsedModes:D,featuresUsed:Array.from(Y),unusedFeatures:R,errorCount:E,recommendations:S}},[J]),$=A(()=>{W([]),O(0),Z.current=new Date,localStorage.removeItem(k)},[]);return p(()=>({trackEvent:M,getSummary:_,getEventsByType:w,eventCount:H,sessionStart:Z.current,clear:$}),[M,_,w,H,$])}function j(P,J,W,Z){let H=[];if(J.includes("evolution"))H.push("Try the AI Evolution mode to get automated improvement suggestions");if(J.includes("markdown"))H.push("Use Markdown preview to see documentation for your specs");if(J.includes("builder"))H.push("Explore the Visual Builder to design your UI components");if(!P.includes("spec_validate")&&P.includes("specs"))H.push("Don't forget to validate your specs before saving");if(P.includes("evolution")&&!P.includes("ai_suggestions"))H.push("Generate AI suggestions to get actionable improvement recommendations");if(Z>50)H.push("Great engagement! Consider saving your work regularly");if(W.length===1)H.push("Try different modes to explore all sandbox capabilities");return H}import{Button as U}from"@contractspec/lib.design-system";import{Badge as B}from"@contractspec/lib.ui-kit-web/ui/badge";import{Card as v}from"@contractspec/lib.ui-kit-web/ui/card";import{useCallback as C,useMemo as x,useState as i}from"react";import{jsx as q,jsxs as Q}from"react/jsx-runtime";function t({templateId:P,collapsed:J=!1,onToggle:W}){let{getSummary:Z,eventCount:H,clear:O,sessionStart:M}=T(P),[w,_]=i(!1),$=x(()=>Z(),[Z]),K=C((L)=>{let N=Math.floor(L/1000),G=Math.floor(N/60),D=Math.floor(G/60);if(D>0)return`${D}h ${G%60}m`;if(G>0)return`${G}m ${N%60}s`;return`${N}s`},[]),V=C(()=>{O()},[O]);if(J)return Q("button",{onClick:W,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",type:"button",children:[q("span",{children:"\uD83D\uDCCA"}),q("span",{children:"Insights"}),q(B,{variant:"secondary",children:H})]});return Q(v,{className:"overflow-hidden",children:[Q("div",{className:"flex items-center justify-between border-blue-500/20 border-b bg-blue-500/5 px-4 py-3",children:[Q("div",{className:"flex items-center gap-2",children:[q("span",{children:"\uD83D\uDCCA"}),q("span",{className:"font-semibold",children:"Personalization Insights"})]}),Q("div",{className:"flex items-center gap-2",children:[q(U,{variant:"ghost",size:"sm",onPress:()=>_(!w),children:w?"Hide Details":"Show Details"}),W&&q("button",{onClick:W,className:"p-1 text-muted-foreground hover:text-foreground",type:"button",title:"Collapse",children:"✕"})]})]}),Q("div",{className:"p-4",children:[Q("div",{className:"mb-4 grid grid-cols-2 gap-3 md:grid-cols-4",children:[q(h,{label:"Session Time",value:K($.sessionDuration),icon:"⏱️"}),q(h,{label:"Events Tracked",value:$.totalEvents.toString(),icon:"\uD83D\uDCC8"}),q(h,{label:"Features Used",value:`${$.featuresUsed.length}/${$.featuresUsed.length+$.unusedFeatures.length}`,icon:"✨"}),q(h,{label:"Errors",value:$.errorCount.toString(),icon:"⚠️",variant:$.errorCount>0?"warning":"success"})]}),$.recommendations.length>0&&Q("div",{className:"mb-4",children:[q("h4",{className:"mb-2 font-semibold text-blue-400 text-xs uppercase",children:"Recommendations"}),q("ul",{className:"space-y-1",children:$.recommendations.map((L,N)=>Q("li",{className:"flex items-start gap-2 text-sm",children:[q("span",{className:"text-blue-400",children:"\uD83D\uDCA1"}),q("span",{children:L})]},N))})]}),$.unusedFeatures.length>0&&Q("div",{className:"mb-4",children:[q("h4",{className:"mb-2 font-semibold text-blue-400 text-xs uppercase",children:"Try These Features"}),q("div",{className:"flex flex-wrap gap-2",children:$.unusedFeatures.slice(0,5).map((L)=>q(B,{variant:"secondary",children:F(L)},L))})]}),w&&q(l,{summary:$,sessionStart:M}),q("div",{className:"mt-4 flex justify-end border-blue-500/10 border-t pt-4",children:q(U,{variant:"ghost",size:"sm",onPress:V,children:"Clear Data"})})]})]})}function h({label:P,value:J,icon:W,variant:Z="default"}){return Q("div",{className:`rounded-lg border p-3 text-center ${{default:"bg-blue-500/5 border-blue-500/20",warning:"bg-amber-500/5 border-amber-500/20",success:"bg-green-500/5 border-green-500/20"}[Z]}`,children:[q("div",{className:"mb-1 text-lg",children:W}),q("div",{className:"font-bold text-lg",children:J}),q("div",{className:"text-muted-foreground text-xs",children:P})]})}function l({summary:P,sessionStart:J}){return Q("div",{className:"mt-4 space-y-4 border-blue-500/10 border-t pt-4",children:[P.mostUsedTemplates.length>0&&Q("div",{children:[q("h4",{className:"mb-2 font-semibold text-blue-400 text-xs uppercase",children:"Most Used Templates"}),q("div",{className:"space-y-1",children:P.mostUsedTemplates.map(({templateId:W,count:Z})=>Q("div",{className:"flex items-center justify-between text-sm",children:[q("span",{children:c(W)}),Q("span",{className:"text-muted-foreground",children:[Z," events"]})]},W))})]}),P.mostUsedModes.length>0&&Q("div",{children:[q("h4",{className:"mb-2 font-semibold text-blue-400 text-xs uppercase",children:"Mode Usage"}),q("div",{className:"space-y-1",children:P.mostUsedModes.map(({mode:W,count:Z})=>Q("div",{className:"flex items-center justify-between text-sm",children:[q("span",{children:F(W)}),Q("span",{className:"text-muted-foreground",children:[Z," switches"]})]},W))})]}),Q("div",{children:[q("h4",{className:"mb-2 font-semibold text-blue-400 text-xs uppercase",children:"Features Used"}),q("div",{className:"flex flex-wrap gap-2",children:P.featuresUsed.map((W)=>Q(B,{variant:"default",className:"border-green-500/30 bg-green-500/20 text-green-400",children:["✓ ",F(W)]},W))})]}),Q("div",{className:"text-muted-foreground text-xs",children:["Session started: ",J.toLocaleString()]})]})}function F(P){return P.replace(/_/g," ").replace(/\b\w/g,(J)=>J.toUpperCase())}function c(P){return P.replace(/-/g," ").replace(/\b\w/g,(J)=>J.toUpperCase())}export{t as PersonalizationInsights};
@@ -1,79 +1 @@
1
- // src/lib/runtime-context.tsx
2
- import { createContext, useContext } from "react";
3
- "use client";
4
- var TEMPLATE_RUNTIME_CONTEXT_KEY = Symbol.for("@contractspec/lib.example-shared-ui/template-runtime-context");
5
- function getTemplateRuntimeContextSingleton() {
6
- const store = globalThis;
7
- store[TEMPLATE_RUNTIME_CONTEXT_KEY] ??= createContext(null);
8
- return store[TEMPLATE_RUNTIME_CONTEXT_KEY];
9
- }
10
- var TemplateRuntimeContext = getTemplateRuntimeContextSingleton();
11
- function useTemplateRuntime() {
12
- const context = useContext(TemplateRuntimeContext);
13
- if (!context) {
14
- throw new Error("useTemplateRuntime must be used within a TemplateRuntimeProvider");
15
- }
16
- return context;
17
- }
18
-
19
- // src/SaveToStudioButton.tsx
20
- import { Sparkles } from "lucide-react";
21
- import { useState } from "react";
22
- import { jsxDEV } from "react/jsx-dev-runtime";
23
- "use client";
24
- function SaveToStudioButton({
25
- organizationId = "demo-org",
26
- projectName,
27
- endpoint,
28
- token
29
- }) {
30
- const { installer, templateId, template } = useTemplateRuntime();
31
- const [status, setStatus] = useState("idle");
32
- const [error, setError] = useState(null);
33
- const handleSave = async () => {
34
- setStatus("saving");
35
- setError(null);
36
- try {
37
- await installer.saveToStudio({
38
- templateId,
39
- projectName: projectName ?? `${template.name} demo`,
40
- organizationId,
41
- endpoint,
42
- token
43
- });
44
- setStatus("saved");
45
- setTimeout(() => setStatus("idle"), 3000);
46
- } catch (err) {
47
- setStatus("error");
48
- setError(err instanceof Error ? err.message : "Unknown error");
49
- }
50
- };
51
- return /* @__PURE__ */ jsxDEV("div", {
52
- className: "flex flex-col items-end gap-1",
53
- children: [
54
- /* @__PURE__ */ jsxDEV("button", {
55
- type: "button",
56
- className: "btn-primary inline-flex items-center gap-2 text-sm",
57
- onClick: handleSave,
58
- disabled: status === "saving",
59
- children: [
60
- /* @__PURE__ */ jsxDEV(Sparkles, {
61
- className: "h-4 w-4"
62
- }, undefined, false, undefined, this),
63
- status === "saving" ? "Publishing…" : "Save to Studio"
64
- ]
65
- }, undefined, true, undefined, this),
66
- status === "error" && error ? /* @__PURE__ */ jsxDEV("p", {
67
- className: "text-destructive text-xs",
68
- children: error
69
- }, undefined, false, undefined, this) : null,
70
- status === "saved" ? /* @__PURE__ */ jsxDEV("p", {
71
- className: "text-emerald-400 text-xs",
72
- children: "Template sent to Studio."
73
- }, undefined, false, undefined, this) : null
74
- ]
75
- }, undefined, true, undefined, this);
76
- }
77
- export {
78
- SaveToStudioButton
79
- };
1
+ import{createContext as f,useContext as b}from"react";var i=Symbol.for("@contractspec/lib.example-shared-ui/template-runtime-context");function h(){let e=globalThis;return e[i]??=f(null),e[i]}var k=h();function l(){let e=b(k);if(!e)throw Error("useTemplateRuntime must be used within a TemplateRuntimeProvider");return e}import{Sparkles as y}from"lucide-react";import{useState as d}from"react";import{jsx as r,jsxs as u}from"react/jsx-runtime";function $({organizationId:e="demo-org",projectName:m,endpoint:p,token:c}){let{installer:v,templateId:S,template:g}=l(),[t,a]=d("idle"),[o,n]=d(null);return u("div",{className:"flex flex-col items-end gap-1",children:[u("button",{type:"button",className:"btn-primary inline-flex items-center gap-2 text-sm",onClick:async()=>{a("saving"),n(null);try{await v.saveToStudio({templateId:S,projectName:m??`${g.name} demo`,organizationId:e,endpoint:p,token:c}),a("saved"),setTimeout(()=>a("idle"),3000)}catch(s){a("error"),n(s instanceof Error?s.message:"Unknown error")}},disabled:t==="saving",children:[r(y,{className:"h-4 w-4"}),t==="saving"?"Publishing…":"Save to Studio"]}),t==="error"&&o?r("p",{className:"text-destructive text-xs",children:o}):null,t==="saved"?r("p",{className:"text-emerald-400 text-xs",children:"Template sent to Studio."}):null]})}export{$ as SaveToStudioButton};