@monkey-mini-app/ui 0.1.0 → 0.1.4

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 (203) hide show
  1. package/README.md +58 -0
  2. package/dist/globals.css +1 -1
  3. package/dist/index.js +12 -2
  4. package/dist/manifest.json +6 -6
  5. package/dist/runtime.js +9 -0
  6. package/dist/sdk.js +158 -0
  7. package/dist/src/blocks/activity-feed.tsx +7 -0
  8. package/dist/src/blocks/app-shell.tsx +1 -0
  9. package/dist/src/blocks/attachment-gallery.tsx +7 -0
  10. package/dist/src/blocks/bar-chart.tsx +15 -1
  11. package/dist/src/blocks/comment-thread.tsx +7 -0
  12. package/dist/src/blocks/dashboard-shell.tsx +109 -0
  13. package/dist/src/blocks/description-list.tsx +7 -0
  14. package/dist/src/blocks/detail-panel.tsx +1 -0
  15. package/dist/src/blocks/donut-chart.tsx +19 -2
  16. package/dist/src/blocks/env-badge.tsx +7 -0
  17. package/dist/src/blocks/env-table.tsx +316 -0
  18. package/dist/src/blocks/file-tree.tsx +7 -0
  19. package/dist/src/blocks/filter-bar.tsx +1 -0
  20. package/dist/src/blocks/form-sheet.tsx +160 -0
  21. package/dist/src/blocks/gauge.tsx +29 -6
  22. package/dist/src/blocks/list-detail.tsx +121 -0
  23. package/dist/src/blocks/notification-center.tsx +7 -0
  24. package/dist/src/blocks/page-header.tsx +1 -0
  25. package/dist/src/blocks/progress-ring.tsx +20 -2
  26. package/dist/src/blocks/radar-chart.tsx +18 -1
  27. package/dist/src/blocks/request-inspector.tsx +7 -0
  28. package/dist/src/blocks/reveal.tsx +56 -0
  29. package/dist/src/blocks/run-timeline.tsx +7 -0
  30. package/dist/src/blocks/scrollspy.tsx +7 -0
  31. package/dist/src/blocks/settings-split.tsx +154 -0
  32. package/dist/src/blocks/severity-chip.tsx +7 -0
  33. package/dist/src/blocks/sparkline.tsx +12 -3
  34. package/dist/src/blocks/stat-card.tsx +1 -0
  35. package/dist/src/blocks/status-badge.tsx +1 -0
  36. package/dist/src/blocks/table-page.tsx +83 -0
  37. package/dist/src/blocks/terminal.tsx +21 -3
  38. package/dist/src/blocks/test-step-list.tsx +7 -0
  39. package/dist/src/blocks/trend-card.tsx +7 -0
  40. package/dist/src/blocks/wizard-shell.tsx +132 -0
  41. package/dist/src/cdn-modules.d.ts +5 -0
  42. package/dist/src/components/accordion.tsx +7 -0
  43. package/dist/src/components/alert-dialog.tsx +7 -0
  44. package/dist/src/components/alert.tsx +7 -0
  45. package/dist/src/components/aspect-ratio.tsx +4 -0
  46. package/dist/src/components/attachment.tsx +4 -0
  47. package/dist/src/components/avatar.tsx +4 -0
  48. package/dist/src/components/badge.tsx +7 -0
  49. package/dist/src/components/breadcrumb.tsx +4 -0
  50. package/dist/src/components/bubble.tsx +4 -0
  51. package/dist/src/components/button-group.tsx +6 -0
  52. package/dist/src/components/button.tsx +7 -0
  53. package/dist/src/components/calendar.tsx +4 -0
  54. package/dist/src/components/card.tsx +8 -1
  55. package/dist/src/components/chart.tsx +7 -0
  56. package/dist/src/components/checkbox.tsx +5 -0
  57. package/dist/src/components/collapsible.tsx +4 -0
  58. package/dist/src/components/combobox.tsx +4 -0
  59. package/dist/src/components/command.tsx +6 -0
  60. package/dist/src/components/context-menu.tsx +4 -0
  61. package/dist/src/components/dialog.tsx +21 -0
  62. package/dist/src/components/drawer.tsx +4 -0
  63. package/dist/src/components/dropdown-menu.tsx +7 -0
  64. package/dist/src/components/empty.tsx +7 -0
  65. package/dist/src/components/field.tsx +6 -0
  66. package/dist/src/components/hover-card.tsx +4 -0
  67. package/dist/src/components/input-group.tsx +4 -0
  68. package/dist/src/components/input.tsx +7 -0
  69. package/dist/src/components/item.tsx +4 -0
  70. package/dist/src/components/kbd.tsx +4 -0
  71. package/dist/src/components/label.tsx +7 -0
  72. package/dist/src/components/marker.tsx +4 -0
  73. package/dist/src/components/menubar.tsx +4 -0
  74. package/dist/src/components/message-scroller.tsx +4 -0
  75. package/dist/src/components/message.tsx +4 -0
  76. package/dist/src/components/native-select.tsx +4 -0
  77. package/dist/src/components/navigation-menu.tsx +4 -0
  78. package/dist/src/components/pagination.tsx +4 -0
  79. package/dist/src/components/popover.tsx +7 -0
  80. package/dist/src/components/progress.tsx +7 -0
  81. package/dist/src/components/questionnaire.tsx +4 -0
  82. package/dist/src/components/radio-group.tsx +4 -0
  83. package/dist/src/components/resizable.tsx +7 -0
  84. package/dist/src/components/scroll-area.tsx +4 -0
  85. package/dist/src/components/select.tsx +7 -0
  86. package/dist/src/components/separator.tsx +5 -0
  87. package/dist/src/components/sheet.tsx +22 -0
  88. package/dist/src/components/sidebar.tsx +4 -0
  89. package/dist/src/components/skeleton.tsx +7 -0
  90. package/dist/src/components/slider.tsx +4 -0
  91. package/dist/src/components/spinner.tsx +6 -0
  92. package/dist/src/components/switch.tsx +7 -0
  93. package/dist/src/components/table.tsx +7 -0
  94. package/dist/src/components/tabs.tsx +7 -0
  95. package/dist/src/components/textarea.tsx +7 -0
  96. package/dist/src/components/toast.tsx +7 -0
  97. package/dist/src/components/toggle-group.tsx +4 -0
  98. package/dist/src/components/toggle.tsx +4 -0
  99. package/dist/src/components/tooltip.tsx +7 -0
  100. package/dist/src/composites/autocomplete.tsx +7 -0
  101. package/dist/src/composites/cascader.tsx +7 -0
  102. package/dist/src/composites/color-picker.tsx +7 -0
  103. package/dist/src/composites/confirm-dialog.tsx +7 -0
  104. package/dist/src/composites/copyable.tsx +9 -1
  105. package/dist/src/composites/currency-input.tsx +7 -0
  106. package/dist/src/composites/date-picker.tsx +7 -0
  107. package/dist/src/composites/date-range-picker.tsx +4 -0
  108. package/dist/src/composites/date-time-picker.tsx +7 -0
  109. package/dist/src/composites/date-time-range-picker.tsx +7 -0
  110. package/dist/src/composites/duration-input.tsx +7 -0
  111. package/dist/src/composites/mini-calendar.tsx +7 -0
  112. package/dist/src/composites/number-field.tsx +7 -0
  113. package/dist/src/composites/password-field.tsx +7 -0
  114. package/dist/src/composites/phone-input.tsx +7 -0
  115. package/dist/src/composites/rating.tsx +7 -0
  116. package/dist/src/composites/relative-date-picker.tsx +7 -0
  117. package/dist/src/composites/search-input.tsx +7 -0
  118. package/dist/src/composites/slider-range.tsx +7 -0
  119. package/dist/src/composites/tag-input.tsx +7 -0
  120. package/dist/src/composites/time-picker.tsx +11 -1
  121. package/dist/src/composites/time-range-picker.tsx +7 -0
  122. package/dist/src/composites/timezone-select.tsx +7 -0
  123. package/dist/src/composites/transfer.tsx +7 -0
  124. package/dist/src/composites/user-picker.tsx +7 -0
  125. package/dist/src/hooks/use-html-dark.ts +37 -0
  126. package/dist/src/hooks/use-mobile.ts +3 -0
  127. package/dist/src/i18n/en.ts +109 -2
  128. package/dist/src/i18n/zh.ts +99 -2
  129. package/dist/src/index.ts +147 -134
  130. package/dist/src/lib/clipboard.ts +10 -0
  131. package/dist/src/lib/illustrations.tsx +2 -2
  132. package/dist/src/products/code-block.tsx +35 -18
  133. package/dist/src/products/code-editor.tsx +156 -24
  134. package/dist/src/products/commit-graph.tsx +644 -0
  135. package/dist/src/products/data-grid.tsx +2 -1
  136. package/dist/src/products/diff-viewer.tsx +104 -8
  137. package/dist/src/products/event-calendar.tsx +28 -823
  138. package/dist/src/products/file-dropzone.tsx +7 -0
  139. package/dist/src/products/full-calendar/animations.ts +38 -0
  140. package/dist/src/products/full-calendar/calendar-body.tsx +77 -0
  141. package/dist/src/products/full-calendar/constants.ts +10 -0
  142. package/dist/src/products/full-calendar/contexts/calendar-context.tsx +255 -0
  143. package/dist/src/products/full-calendar/contexts/dnd-context.tsx +157 -0
  144. package/dist/src/products/full-calendar/dialogs/add-edit-event-dialog.tsx +187 -0
  145. package/dist/src/products/full-calendar/dialogs/delete-event-dialog.tsx +39 -0
  146. package/dist/src/products/full-calendar/dialogs/event-details-dialog.tsx +100 -0
  147. package/dist/src/products/full-calendar/dialogs/events-list-dialog.tsx +87 -0
  148. package/dist/src/products/full-calendar/dnd/draggable-event.tsx +45 -0
  149. package/dist/src/products/full-calendar/dnd/droppable-area.tsx +45 -0
  150. package/dist/src/products/full-calendar/dnd/resizable-event.tsx +179 -0
  151. package/dist/src/products/full-calendar/header/calendar-header.tsx +65 -0
  152. package/dist/src/products/full-calendar/header/date-navigator.tsx +110 -0
  153. package/dist/src/products/full-calendar/header/filter.tsx +58 -0
  154. package/dist/src/products/full-calendar/header/today-button.tsx +45 -0
  155. package/dist/src/products/full-calendar/header/user-select.tsx +64 -0
  156. package/dist/src/products/full-calendar/header/view-tabs.tsx +36 -0
  157. package/dist/src/products/full-calendar/helpers.ts +453 -0
  158. package/dist/src/products/full-calendar/hooks/use-time-range-create.ts +152 -0
  159. package/dist/src/products/full-calendar/hooks.ts +70 -0
  160. package/dist/src/products/full-calendar/interfaces.ts +23 -0
  161. package/dist/src/products/full-calendar/settings/settings.tsx +80 -0
  162. package/dist/src/products/full-calendar/shims/avatar-group.tsx +16 -0
  163. package/dist/src/products/full-calendar/shims/day-picker.tsx +1 -0
  164. package/dist/src/products/full-calendar/shims/motion.tsx +97 -0
  165. package/dist/src/products/full-calendar/shims/next-themes.ts +6 -0
  166. package/dist/src/products/full-calendar/shims/re-resizable.tsx +25 -0
  167. package/dist/src/products/full-calendar/shims/sonner.ts +4 -0
  168. package/dist/src/products/full-calendar/types.ts +8 -0
  169. package/dist/src/products/full-calendar/views/agenda-view/agenda-events.tsx +140 -0
  170. package/dist/src/products/full-calendar/views/month-view/calendar-month-view.tsx +69 -0
  171. package/dist/src/products/full-calendar/views/month-view/day-cell.tsx +201 -0
  172. package/dist/src/products/full-calendar/views/month-view/event-bullet.tsx +40 -0
  173. package/dist/src/products/full-calendar/views/month-view/month-event-badge.tsx +143 -0
  174. package/dist/src/products/full-calendar/views/week-and-day-view/calendar-day-view.tsx +295 -0
  175. package/dist/src/products/full-calendar/views/week-and-day-view/calendar-time-line.tsx +35 -0
  176. package/dist/src/products/full-calendar/views/week-and-day-view/calendar-week-view.tsx +253 -0
  177. package/dist/src/products/full-calendar/views/week-and-day-view/day-view-multi-day-events-row.tsx +73 -0
  178. package/dist/src/products/full-calendar/views/week-and-day-view/event-block.tsx +114 -0
  179. package/dist/src/products/full-calendar/views/week-and-day-view/render-grouped-events.tsx +49 -0
  180. package/dist/src/products/full-calendar/views/week-and-day-view/week-view-multi-day-events-row.tsx +143 -0
  181. package/dist/src/products/full-calendar/views/year-view/calendar-year-view.tsx +161 -0
  182. package/dist/src/products/gantt.tsx +7 -0
  183. package/dist/src/products/jira-wiki.tsx +1 -0
  184. package/dist/src/products/jql-input.tsx +340 -37
  185. package/dist/src/products/json-viewer.tsx +7 -0
  186. package/dist/src/products/kanban-issue-panel.tsx +7 -0
  187. package/dist/src/products/kanban.tsx +1 -0
  188. package/dist/src/products/log-viewer.tsx +390 -18
  189. package/dist/src/products/markdown-editor.tsx +21 -6
  190. package/dist/src/products/markdown.tsx +7 -0
  191. package/dist/src/products/rich-text-editor.tsx +65 -59
  192. package/dist/src/products/sortable-list.tsx +7 -0
  193. package/dist/src/products/stepper.tsx +219 -70
  194. package/dist/src/products/timeline.tsx +7 -0
  195. package/dist/src/products/tree-view.tsx +7 -0
  196. package/dist/src/sdk/app-error-boundary.tsx +240 -0
  197. package/dist/src/sdk/app-id.ts +7 -0
  198. package/dist/src/sdk/use-app.ts +126 -0
  199. package/dist/src/styles/globals.css +7 -7
  200. package/dist/vendors/lodash.js +20 -0
  201. package/dist/vendors/motion.js +12 -0
  202. package/package.json +23 -19
  203. package/dist/src/products/jql-language.ts +0 -70
@@ -1,7 +1,9 @@
1
1
  "use client"
2
2
 
3
+ import { useEffect, useState } from "react"
3
4
  import { diffLines } from "diff"
4
5
 
6
+ import { useHtmlDark } from "@monkey-mini-app/ui/hooks/use-html-dark"
5
7
  import { cn } from "@monkey-mini-app/ui/lib/utils"
6
8
 
7
9
  type Row = {
@@ -11,6 +13,8 @@ type Row = {
11
13
  right?: number
12
14
  }
13
15
 
16
+ type Token = { content: string; color?: string }
17
+
14
18
  function toRows(original: string, modified: string): Row[] {
15
19
  const parts = diffLines(original, modified)
16
20
  const rows: Row[] = []
@@ -38,6 +42,39 @@ function stats(rows: Row[]) {
38
42
  }
39
43
  }
40
44
 
45
+ function escapeHtml(s: string): string {
46
+ return s
47
+ .replace(/&/g, "&")
48
+ .replace(/</g, "&lt;")
49
+ .replace(/>/g, "&gt;")
50
+ .replace(/"/g, "&quot;")
51
+ }
52
+
53
+ function lineToHtml(tokens: Token[]): string {
54
+ return tokens
55
+ .map((t) =>
56
+ t.color
57
+ ? `<span style="color:${escapeHtml(t.color)}">${escapeHtml(t.content)}</span>`
58
+ : escapeHtml(t.content),
59
+ )
60
+ .join("")
61
+ }
62
+
63
+ function langFromFile(name?: string): string {
64
+ const ext = name?.split(".").pop()?.toLowerCase()
65
+ const map: Record<string, string> = {
66
+ ts: "ts",
67
+ tsx: "tsx",
68
+ js: "js",
69
+ jsx: "jsx",
70
+ json: "json",
71
+ html: "html",
72
+ md: "md",
73
+ css: "css",
74
+ }
75
+ return (ext && map[ext]) || "ts"
76
+ }
77
+
41
78
  function Gutter({ n }: { n?: number }) {
42
79
  return (
43
80
  <span className="w-8 shrink-0 pr-2 text-right text-[11px] text-muted-foreground/70 select-none">
@@ -49,9 +86,11 @@ function Gutter({ n }: { n?: number }) {
49
86
  function Line({
50
87
  row,
51
88
  side,
89
+ html,
52
90
  }: {
53
91
  row: Row
54
92
  side?: "left" | "right"
93
+ html?: string
55
94
  }) {
56
95
  const hidden =
57
96
  (side === "left" && row.type === "add") ||
@@ -62,33 +101,90 @@ function Line({
62
101
  className={cn(
63
102
  "flex px-2",
64
103
  hidden && "bg-muted/40",
65
- !hidden && row.type === "add" && "bg-emerald-500/15 text-emerald-800 dark:text-emerald-300",
66
- !hidden && row.type === "del" && "bg-destructive/10 text-destructive"
104
+ !hidden && row.type === "add" && "bg-emerald-500/15",
105
+ !hidden && row.type === "del" && "bg-destructive/10",
106
+ !html && !hidden && row.type === "add" && "text-emerald-800 dark:text-emerald-300",
107
+ !html && !hidden && row.type === "del" && "text-destructive",
67
108
  )}
68
109
  >
69
110
  {side !== "right" ? <Gutter n={hidden ? undefined : row.left} /> : null}
70
111
  {side !== "left" ? <Gutter n={hidden ? undefined : row.right} /> : null}
71
112
  <span className="w-4 shrink-0 select-none">{hidden ? " " : mark}</span>
72
- <span className="min-w-0 flex-1 whitespace-pre-wrap break-all">
73
- {hidden ? "" : row.text}
74
- </span>
113
+ {hidden ? (
114
+ <span className="min-w-0 flex-1" />
115
+ ) : html ? (
116
+ <span
117
+ className="min-w-0 flex-1 whitespace-pre-wrap break-all"
118
+ dangerouslySetInnerHTML={{ __html: html }}
119
+ />
120
+ ) : (
121
+ <span className="min-w-0 flex-1 whitespace-pre-wrap break-all">{row.text}</span>
122
+ )}
75
123
  </div>
76
124
  )
77
125
  }
78
126
 
127
+ /**
128
+ * Unified or split diff view.
129
+ * @when Comparing two versions of text. Pass `original` + `modified` strings.
130
+ * @example
131
+ * <DiffViewer original={a} modified={b} language="ts" mode="split" />
132
+ * @family Discovery & inspect
133
+ */
79
134
  export function DiffViewer({
80
135
  original,
81
136
  modified,
82
137
  mode = "unified",
83
138
  fileName,
139
+ language,
84
140
  }: {
85
141
  original: string
86
142
  modified: string
87
143
  mode?: "unified" | "split"
88
144
  fileName?: string
145
+ language?: string
89
146
  }) {
90
147
  const rows = toRows(original, modified)
91
148
  const { added, removed } = stats(rows)
149
+ const lang = language ?? langFromFile(fileName)
150
+ const [hi, setHi] = useState<{ orig: string[]; mod: string[] } | null>(null)
151
+ const dark = useHtmlDark()
152
+
153
+ useEffect(() => {
154
+ let cancelled = false
155
+ ;(async () => {
156
+ try {
157
+ const shiki = (await import("https://esm.sh/shiki@4.4.3")) as {
158
+ codeToTokens?: (code: string, opts: object) => Promise<{ tokens: Token[][] }>
159
+ default?: { codeToTokens?: (code: string, opts: object) => Promise<{ tokens: Token[][] }> }
160
+ }
161
+ const codeToTokens = shiki.codeToTokens ?? shiki.default?.codeToTokens
162
+ if (!codeToTokens) throw new Error("shiki.codeToTokens missing")
163
+ const theme = dark ? "github-dark" : "github-light"
164
+ const [a, b] = await Promise.all([
165
+ codeToTokens(original, { lang, theme }),
166
+ codeToTokens(modified, { lang, theme }),
167
+ ])
168
+ if (cancelled) return
169
+ setHi({
170
+ orig: a.tokens.map(lineToHtml),
171
+ mod: b.tokens.map(lineToHtml),
172
+ })
173
+ } catch (err) {
174
+ console.warn("[DiffViewer] shiki CDN failed", err)
175
+ }
176
+ })()
177
+ return () => {
178
+ cancelled = true
179
+ }
180
+ }, [original, modified, lang, dark])
181
+
182
+ function htmlFor(row: Row): string | undefined {
183
+ if (!hi) return undefined
184
+ if (row.type === "del") return hi.orig[(row.left ?? 1) - 1]
185
+ if (row.type === "add") return hi.mod[(row.right ?? 1) - 1]
186
+ return hi.orig[(row.left ?? 1) - 1] ?? hi.mod[(row.right ?? 1) - 1]
187
+ }
92
188
 
93
189
  return (
94
190
  <div
@@ -108,19 +204,19 @@ export function DiffViewer({
108
204
  <div className="grid max-h-[28rem] grid-cols-2 overflow-auto">
109
205
  <div className="border-r">
110
206
  {rows.map((row, index) => (
111
- <Line key={`l${index}`} row={row} side="left" />
207
+ <Line key={`l${index}`} row={row} side="left" html={htmlFor(row)} />
112
208
  ))}
113
209
  </div>
114
210
  <div>
115
211
  {rows.map((row, index) => (
116
- <Line key={`r${index}`} row={row} side="right" />
212
+ <Line key={`r${index}`} row={row} side="right" html={htmlFor(row)} />
117
213
  ))}
118
214
  </div>
119
215
  </div>
120
216
  ) : (
121
217
  <div className="max-h-[28rem] overflow-auto">
122
218
  {rows.map((row, index) => (
123
- <Line key={index} row={row} />
219
+ <Line key={index} row={row} html={htmlFor(row)} />
124
220
  ))}
125
221
  </div>
126
222
  )}