@kujoforall/paper-ui 0.0.0-stage → 0.1.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 (366) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE +21 -0
  3. package/README.md +252 -2
  4. package/dist/components/editor/block-text.d.ts +8 -0
  5. package/dist/components/editor/block-text.d.ts.map +1 -0
  6. package/dist/components/editor/block-text.js +213 -0
  7. package/dist/components/editor/block-text.js.map +1 -0
  8. package/dist/components/editor/blocks.d.ts +33 -0
  9. package/dist/components/editor/blocks.d.ts.map +1 -0
  10. package/dist/components/editor/blocks.js +187 -0
  11. package/dist/components/editor/blocks.js.map +1 -0
  12. package/dist/components/editor/document-editor.d.ts +27 -0
  13. package/dist/components/editor/document-editor.d.ts.map +1 -0
  14. package/dist/components/editor/document-editor.js +40 -0
  15. package/dist/components/editor/document-editor.js.map +1 -0
  16. package/dist/components/editor/document-view.d.ts +22 -0
  17. package/dist/components/editor/document-view.d.ts.map +1 -0
  18. package/dist/components/editor/document-view.js +105 -0
  19. package/dist/components/editor/document-view.js.map +1 -0
  20. package/dist/components/editor/editor-state.d.ts +100 -0
  21. package/dist/components/editor/editor-state.d.ts.map +1 -0
  22. package/dist/components/editor/editor-state.js +192 -0
  23. package/dist/components/editor/editor-state.js.map +1 -0
  24. package/dist/components/editor/extensions/spoiler.d.ts +8 -0
  25. package/dist/components/editor/extensions/spoiler.d.ts.map +1 -0
  26. package/dist/components/editor/extensions/spoiler.js +36 -0
  27. package/dist/components/editor/extensions/spoiler.js.map +1 -0
  28. package/dist/components/editor/index.d.ts +9 -0
  29. package/dist/components/editor/index.d.ts.map +1 -0
  30. package/dist/components/editor/index.js +9 -0
  31. package/dist/components/editor/index.js.map +1 -0
  32. package/dist/components/editor/kinds.d.ts +99 -0
  33. package/dist/components/editor/kinds.d.ts.map +1 -0
  34. package/dist/components/editor/kinds.js +74 -0
  35. package/dist/components/editor/kinds.js.map +1 -0
  36. package/dist/components/sketch/rough.d.ts +38 -0
  37. package/dist/components/sketch/rough.d.ts.map +1 -0
  38. package/dist/components/sketch/rough.js +57 -0
  39. package/dist/components/sketch/rough.js.map +1 -0
  40. package/dist/components/ui/accent-picker.d.ts +2 -0
  41. package/dist/components/ui/accent-picker.d.ts.map +1 -0
  42. package/dist/components/ui/accent-picker.js +44 -0
  43. package/dist/components/ui/accent-picker.js.map +1 -0
  44. package/dist/components/ui/address-field.d.ts +10 -0
  45. package/dist/components/ui/address-field.d.ts.map +1 -0
  46. package/dist/components/ui/address-field.js +24 -0
  47. package/dist/components/ui/address-field.js.map +1 -0
  48. package/dist/components/ui/app-shell.d.ts +25 -0
  49. package/dist/components/ui/app-shell.d.ts.map +1 -0
  50. package/dist/components/ui/app-shell.js +69 -0
  51. package/dist/components/ui/app-shell.js.map +1 -0
  52. package/dist/components/ui/badge.d.ts +19 -0
  53. package/dist/components/ui/badge.d.ts.map +1 -0
  54. package/dist/components/ui/badge.js +62 -0
  55. package/dist/components/ui/badge.js.map +1 -0
  56. package/dist/components/ui/breadcrumbs.d.ts +10 -0
  57. package/dist/components/ui/breadcrumbs.d.ts.map +1 -0
  58. package/dist/components/ui/breadcrumbs.js +9 -0
  59. package/dist/components/ui/breadcrumbs.js.map +1 -0
  60. package/dist/components/ui/button.d.ts +13 -0
  61. package/dist/components/ui/button.d.ts.map +1 -0
  62. package/dist/components/ui/button.js +45 -0
  63. package/dist/components/ui/button.js.map +1 -0
  64. package/dist/components/ui/calendar.d.ts +5 -0
  65. package/dist/components/ui/calendar.d.ts.map +1 -0
  66. package/dist/components/ui/calendar.js +64 -0
  67. package/dist/components/ui/calendar.js.map +1 -0
  68. package/dist/components/ui/callout.d.ts +13 -0
  69. package/dist/components/ui/callout.d.ts.map +1 -0
  70. package/dist/components/ui/callout.js +27 -0
  71. package/dist/components/ui/callout.js.map +1 -0
  72. package/dist/components/ui/card.d.ts +13 -0
  73. package/dist/components/ui/card.d.ts.map +1 -0
  74. package/dist/components/ui/card.js +27 -0
  75. package/dist/components/ui/card.js.map +1 -0
  76. package/dist/components/ui/checkbox.d.ts +6 -0
  77. package/dist/components/ui/checkbox.d.ts.map +1 -0
  78. package/dist/components/ui/checkbox.js +10 -0
  79. package/dist/components/ui/checkbox.js.map +1 -0
  80. package/dist/components/ui/command-menu.d.ts +15 -0
  81. package/dist/components/ui/command-menu.d.ts.map +1 -0
  82. package/dist/components/ui/command-menu.js +24 -0
  83. package/dist/components/ui/command-menu.js.map +1 -0
  84. package/dist/components/ui/date-picker.d.ts +35 -0
  85. package/dist/components/ui/date-picker.d.ts.map +1 -0
  86. package/dist/components/ui/date-picker.js +56 -0
  87. package/dist/components/ui/date-picker.js.map +1 -0
  88. package/dist/components/ui/date-time-picker.d.ts +19 -0
  89. package/dist/components/ui/date-time-picker.d.ts.map +1 -0
  90. package/dist/components/ui/date-time-picker.js +32 -0
  91. package/dist/components/ui/date-time-picker.js.map +1 -0
  92. package/dist/components/ui/dialog.d.ts +17 -0
  93. package/dist/components/ui/dialog.d.ts.map +1 -0
  94. package/dist/components/ui/dialog.js +33 -0
  95. package/dist/components/ui/dialog.js.map +1 -0
  96. package/dist/components/ui/dropdown-menu.d.ts +20 -0
  97. package/dist/components/ui/dropdown-menu.d.ts.map +1 -0
  98. package/dist/components/ui/dropdown-menu.js +56 -0
  99. package/dist/components/ui/dropdown-menu.js.map +1 -0
  100. package/dist/components/ui/editable-text.d.ts +17 -0
  101. package/dist/components/ui/editable-text.d.ts.map +1 -0
  102. package/dist/components/ui/editable-text.js +68 -0
  103. package/dist/components/ui/editable-text.js.map +1 -0
  104. package/dist/components/ui/field-button.d.ts +14 -0
  105. package/dist/components/ui/field-button.d.ts.map +1 -0
  106. package/dist/components/ui/field-button.js +16 -0
  107. package/dist/components/ui/field-button.js.map +1 -0
  108. package/dist/components/ui/file-preview.d.ts +5 -0
  109. package/dist/components/ui/file-preview.d.ts.map +1 -0
  110. package/dist/components/ui/file-preview.js +66 -0
  111. package/dist/components/ui/file-preview.js.map +1 -0
  112. package/dist/components/ui/file-uploader.d.ts +39 -0
  113. package/dist/components/ui/file-uploader.d.ts.map +1 -0
  114. package/dist/components/ui/file-uploader.js +110 -0
  115. package/dist/components/ui/file-uploader.js.map +1 -0
  116. package/dist/components/ui/handle-row.d.ts +15 -0
  117. package/dist/components/ui/handle-row.d.ts.map +1 -0
  118. package/dist/components/ui/handle-row.js +41 -0
  119. package/dist/components/ui/handle-row.js.map +1 -0
  120. package/dist/components/ui/image-block.d.ts +31 -0
  121. package/dist/components/ui/image-block.d.ts.map +1 -0
  122. package/dist/components/ui/image-block.js +103 -0
  123. package/dist/components/ui/image-block.js.map +1 -0
  124. package/dist/components/ui/image-card.d.ts +17 -0
  125. package/dist/components/ui/image-card.d.ts.map +1 -0
  126. package/dist/components/ui/image-card.js +38 -0
  127. package/dist/components/ui/image-card.js.map +1 -0
  128. package/dist/components/ui/image-viewer.d.ts +31 -0
  129. package/dist/components/ui/image-viewer.d.ts.map +1 -0
  130. package/dist/components/ui/image-viewer.js +81 -0
  131. package/dist/components/ui/image-viewer.js.map +1 -0
  132. package/dist/components/ui/image.d.ts +11 -0
  133. package/dist/components/ui/image.d.ts.map +1 -0
  134. package/dist/components/ui/image.js +32 -0
  135. package/dist/components/ui/image.js.map +1 -0
  136. package/dist/components/ui/index.d.ts +49 -0
  137. package/dist/components/ui/index.d.ts.map +1 -0
  138. package/dist/components/ui/index.js +49 -0
  139. package/dist/components/ui/index.js.map +1 -0
  140. package/dist/components/ui/input.d.ts +16 -0
  141. package/dist/components/ui/input.d.ts.map +1 -0
  142. package/dist/components/ui/input.js +32 -0
  143. package/dist/components/ui/input.js.map +1 -0
  144. package/dist/components/ui/link-block.d.ts +13 -0
  145. package/dist/components/ui/link-block.d.ts.map +1 -0
  146. package/dist/components/ui/link-block.js +21 -0
  147. package/dist/components/ui/link-block.js.map +1 -0
  148. package/dist/components/ui/mac-card.d.ts +15 -0
  149. package/dist/components/ui/mac-card.d.ts.map +1 -0
  150. package/dist/components/ui/mac-card.js +9 -0
  151. package/dist/components/ui/mac-card.js.map +1 -0
  152. package/dist/components/ui/nav-tree.d.ts +16 -0
  153. package/dist/components/ui/nav-tree.d.ts.map +1 -0
  154. package/dist/components/ui/nav-tree.js +34 -0
  155. package/dist/components/ui/nav-tree.js.map +1 -0
  156. package/dist/components/ui/page.d.ts +12 -0
  157. package/dist/components/ui/page.d.ts.map +1 -0
  158. package/dist/components/ui/page.js +15 -0
  159. package/dist/components/ui/page.js.map +1 -0
  160. package/dist/components/ui/popover.d.ts +8 -0
  161. package/dist/components/ui/popover.d.ts.map +1 -0
  162. package/dist/components/ui/popover.js +18 -0
  163. package/dist/components/ui/popover.js.map +1 -0
  164. package/dist/components/ui/progress.d.ts +9 -0
  165. package/dist/components/ui/progress.d.ts.map +1 -0
  166. package/dist/components/ui/progress.js +9 -0
  167. package/dist/components/ui/progress.js.map +1 -0
  168. package/dist/components/ui/property.d.ts +15 -0
  169. package/dist/components/ui/property.d.ts.map +1 -0
  170. package/dist/components/ui/property.js +34 -0
  171. package/dist/components/ui/property.js.map +1 -0
  172. package/dist/components/ui/segmented.d.ts +13 -0
  173. package/dist/components/ui/segmented.d.ts.map +1 -0
  174. package/dist/components/ui/segmented.js +10 -0
  175. package/dist/components/ui/segmented.js.map +1 -0
  176. package/dist/components/ui/select-menu.d.ts +10 -0
  177. package/dist/components/ui/select-menu.d.ts.map +1 -0
  178. package/dist/components/ui/select-menu.js +10 -0
  179. package/dist/components/ui/select-menu.js.map +1 -0
  180. package/dist/components/ui/select.d.ts +11 -0
  181. package/dist/components/ui/select.d.ts.map +1 -0
  182. package/dist/components/ui/select.js +31 -0
  183. package/dist/components/ui/select.js.map +1 -0
  184. package/dist/components/ui/selection-bar.d.ts +12 -0
  185. package/dist/components/ui/selection-bar.d.ts.map +1 -0
  186. package/dist/components/ui/selection-bar.js +15 -0
  187. package/dist/components/ui/selection-bar.js.map +1 -0
  188. package/dist/components/ui/separator.d.ts +4 -0
  189. package/dist/components/ui/separator.d.ts.map +1 -0
  190. package/dist/components/ui/separator.js +12 -0
  191. package/dist/components/ui/separator.js.map +1 -0
  192. package/dist/components/ui/spotlight.d.ts +23 -0
  193. package/dist/components/ui/spotlight.d.ts.map +1 -0
  194. package/dist/components/ui/spotlight.js +107 -0
  195. package/dist/components/ui/spotlight.js.map +1 -0
  196. package/dist/components/ui/stat-tile.d.ts +8 -0
  197. package/dist/components/ui/stat-tile.d.ts.map +1 -0
  198. package/dist/components/ui/stat-tile.js +9 -0
  199. package/dist/components/ui/stat-tile.js.map +1 -0
  200. package/dist/components/ui/step-dialog.d.ts +20 -0
  201. package/dist/components/ui/step-dialog.d.ts.map +1 -0
  202. package/dist/components/ui/step-dialog.js +36 -0
  203. package/dist/components/ui/step-dialog.js.map +1 -0
  204. package/dist/components/ui/table.d.ts +8 -0
  205. package/dist/components/ui/table.d.ts.map +1 -0
  206. package/dist/components/ui/table.js +23 -0
  207. package/dist/components/ui/table.js.map +1 -0
  208. package/dist/components/ui/theme-toggle.d.ts +2 -0
  209. package/dist/components/ui/theme-toggle.d.ts.map +1 -0
  210. package/dist/components/ui/theme-toggle.js +49 -0
  211. package/dist/components/ui/theme-toggle.js.map +1 -0
  212. package/dist/components/ui/time-picker.d.ts +21 -0
  213. package/dist/components/ui/time-picker.d.ts.map +1 -0
  214. package/dist/components/ui/time-picker.js +63 -0
  215. package/dist/components/ui/time-picker.js.map +1 -0
  216. package/dist/components/ui/tooltip.d.ts +15 -0
  217. package/dist/components/ui/tooltip.d.ts.map +1 -0
  218. package/dist/components/ui/tooltip.js +21 -0
  219. package/dist/components/ui/tooltip.js.map +1 -0
  220. package/dist/components/ui/typography.d.ts +34 -0
  221. package/dist/components/ui/typography.d.ts.map +1 -0
  222. package/dist/components/ui/typography.js +72 -0
  223. package/dist/components/ui/typography.js.map +1 -0
  224. package/dist/components/ui/video-block.d.ts +14 -0
  225. package/dist/components/ui/video-block.d.ts.map +1 -0
  226. package/dist/components/ui/video-block.js +18 -0
  227. package/dist/components/ui/video-block.js.map +1 -0
  228. package/dist/hooks/use-save-queue.d.ts +13 -0
  229. package/dist/hooks/use-save-queue.d.ts.map +1 -0
  230. package/dist/hooks/use-save-queue.js +45 -0
  231. package/dist/hooks/use-save-queue.js.map +1 -0
  232. package/dist/hooks/use-selection.d.ts +10 -0
  233. package/dist/hooks/use-selection.d.ts.map +1 -0
  234. package/dist/hooks/use-selection.js +43 -0
  235. package/dist/hooks/use-selection.js.map +1 -0
  236. package/dist/hooks/use-shared-transition.d.ts +3 -0
  237. package/dist/hooks/use-shared-transition.d.ts.map +1 -0
  238. package/dist/hooks/use-shared-transition.js +38 -0
  239. package/dist/hooks/use-shared-transition.js.map +1 -0
  240. package/dist/hooks/use-upload-queue.d.ts +22 -0
  241. package/dist/hooks/use-upload-queue.d.ts.map +1 -0
  242. package/dist/hooks/use-upload-queue.js +78 -0
  243. package/dist/hooks/use-upload-queue.js.map +1 -0
  244. package/dist/lib/accent.d.ts +5 -0
  245. package/dist/lib/accent.d.ts.map +1 -0
  246. package/dist/lib/accent.js +10 -0
  247. package/dist/lib/accent.js.map +1 -0
  248. package/dist/lib/bento.d.ts +17 -0
  249. package/dist/lib/bento.d.ts.map +1 -0
  250. package/dist/lib/bento.js +92 -0
  251. package/dist/lib/bento.js.map +1 -0
  252. package/dist/lib/dates.d.ts +14 -0
  253. package/dist/lib/dates.d.ts.map +1 -0
  254. package/dist/lib/dates.js +34 -0
  255. package/dist/lib/dates.js.map +1 -0
  256. package/dist/lib/document.d.ts +79 -0
  257. package/dist/lib/document.d.ts.map +1 -0
  258. package/dist/lib/document.js +11 -0
  259. package/dist/lib/document.js.map +1 -0
  260. package/dist/lib/embed.d.ts +14 -0
  261. package/dist/lib/embed.d.ts.map +1 -0
  262. package/dist/lib/embed.js +63 -0
  263. package/dist/lib/embed.js.map +1 -0
  264. package/dist/lib/files.d.ts +23 -0
  265. package/dist/lib/files.d.ts.map +1 -0
  266. package/dist/lib/files.js +69 -0
  267. package/dist/lib/files.js.map +1 -0
  268. package/dist/lib/justified.d.ts +50 -0
  269. package/dist/lib/justified.d.ts.map +1 -0
  270. package/dist/lib/justified.js +78 -0
  271. package/dist/lib/justified.js.map +1 -0
  272. package/dist/lib/rich-text-dom.d.ts +14 -0
  273. package/dist/lib/rich-text-dom.d.ts.map +1 -0
  274. package/dist/lib/rich-text-dom.js +143 -0
  275. package/dist/lib/rich-text-dom.js.map +1 -0
  276. package/dist/lib/rich-text.d.ts +15 -0
  277. package/dist/lib/rich-text.d.ts.map +1 -0
  278. package/dist/lib/rich-text.js +35 -0
  279. package/dist/lib/rich-text.js.map +1 -0
  280. package/dist/lib/spotlight.d.ts +22 -0
  281. package/dist/lib/spotlight.d.ts.map +1 -0
  282. package/dist/lib/spotlight.js +66 -0
  283. package/dist/lib/spotlight.js.map +1 -0
  284. package/dist/lib/tree.d.ts +17 -0
  285. package/dist/lib/tree.d.ts.map +1 -0
  286. package/dist/lib/tree.js +35 -0
  287. package/dist/lib/tree.js.map +1 -0
  288. package/dist/lib/utils.d.ts +3 -0
  289. package/dist/lib/utils.d.ts.map +1 -0
  290. package/dist/lib/utils.js +6 -0
  291. package/dist/lib/utils.js.map +1 -0
  292. package/dist/styles/notion.css +526 -0
  293. package/package.json +106 -5
  294. package/src/components/editor/block-text.tsx +230 -0
  295. package/src/components/editor/blocks.tsx +368 -0
  296. package/src/components/editor/document-editor.tsx +101 -0
  297. package/src/components/editor/document-view.tsx +192 -0
  298. package/src/components/editor/editor-state.tsx +270 -0
  299. package/src/components/editor/extensions/spoiler.tsx +76 -0
  300. package/src/components/editor/index.ts +9 -0
  301. package/src/components/editor/kinds.ts +158 -0
  302. package/src/components/sketch/rough.tsx +90 -0
  303. package/src/components/ui/accent-picker.tsx +72 -0
  304. package/src/components/ui/address-field.tsx +57 -0
  305. package/src/components/ui/app-shell.tsx +138 -0
  306. package/src/components/ui/badge.tsx +81 -0
  307. package/src/components/ui/breadcrumbs.tsx +25 -0
  308. package/src/components/ui/button.tsx +73 -0
  309. package/src/components/ui/calendar.tsx +100 -0
  310. package/src/components/ui/callout.tsx +62 -0
  311. package/src/components/ui/card.tsx +90 -0
  312. package/src/components/ui/checkbox.tsx +32 -0
  313. package/src/components/ui/command-menu.tsx +72 -0
  314. package/src/components/ui/date-picker.tsx +170 -0
  315. package/src/components/ui/date-time-picker.tsx +117 -0
  316. package/src/components/ui/dialog.tsx +124 -0
  317. package/src/components/ui/dropdown-menu.tsx +183 -0
  318. package/src/components/ui/editable-text.tsx +109 -0
  319. package/src/components/ui/field-button.tsx +68 -0
  320. package/src/components/ui/file-preview.tsx +80 -0
  321. package/src/components/ui/file-uploader.tsx +376 -0
  322. package/src/components/ui/handle-row.tsx +116 -0
  323. package/src/components/ui/image-block.tsx +238 -0
  324. package/src/components/ui/image-card.tsx +102 -0
  325. package/src/components/ui/image-viewer.tsx +187 -0
  326. package/src/components/ui/image.tsx +96 -0
  327. package/src/components/ui/index.ts +83 -0
  328. package/src/components/ui/input.tsx +99 -0
  329. package/src/components/ui/link-block.tsx +82 -0
  330. package/src/components/ui/mac-card.tsx +46 -0
  331. package/src/components/ui/nav-tree.tsx +86 -0
  332. package/src/components/ui/page.tsx +25 -0
  333. package/src/components/ui/popover.tsx +42 -0
  334. package/src/components/ui/progress.tsx +36 -0
  335. package/src/components/ui/property.tsx +64 -0
  336. package/src/components/ui/segmented.tsx +42 -0
  337. package/src/components/ui/select-menu.tsx +46 -0
  338. package/src/components/ui/select.tsx +124 -0
  339. package/src/components/ui/selection-bar.tsx +50 -0
  340. package/src/components/ui/separator.tsx +30 -0
  341. package/src/components/ui/spotlight.tsx +222 -0
  342. package/src/components/ui/stat-tile.tsx +25 -0
  343. package/src/components/ui/step-dialog.tsx +104 -0
  344. package/src/components/ui/table.tsx +42 -0
  345. package/src/components/ui/theme-toggle.tsx +101 -0
  346. package/src/components/ui/time-picker.tsx +173 -0
  347. package/src/components/ui/tooltip.tsx +64 -0
  348. package/src/components/ui/typography.tsx +168 -0
  349. package/src/components/ui/video-block.tsx +60 -0
  350. package/src/hooks/use-save-queue.ts +66 -0
  351. package/src/hooks/use-selection.ts +44 -0
  352. package/src/hooks/use-shared-transition.ts +40 -0
  353. package/src/hooks/use-upload-queue.ts +111 -0
  354. package/src/lib/accent.ts +11 -0
  355. package/src/lib/bento.ts +87 -0
  356. package/src/lib/dates.ts +39 -0
  357. package/src/lib/document.ts +55 -0
  358. package/src/lib/embed.ts +62 -0
  359. package/src/lib/files.ts +73 -0
  360. package/src/lib/justified.ts +106 -0
  361. package/src/lib/rich-text-dom.ts +136 -0
  362. package/src/lib/rich-text.ts +50 -0
  363. package/src/lib/spotlight.ts +78 -0
  364. package/src/lib/tree.ts +41 -0
  365. package/src/lib/utils.ts +6 -0
  366. package/src/styles/notion.css +526 -0
@@ -0,0 +1,158 @@
1
+ import type { ComponentType } from "react";
2
+ import { Bookmark, Heading1, Heading2, Heading3, Image, List, ListOrdered, ListTodo, Minus, Quote, SquarePlay, Type, type LucideIcon } from "lucide-react";
3
+ import { isListType, type AnyBlock, type Block } from "../../lib/document.ts";
4
+ import type { Text } from "../../lib/rich-text.ts";
5
+ import type { TreeNode } from "../../lib/tree.ts";
6
+
7
+ export { isListType };
8
+
9
+ /** A block as the editor holds it: every kind has children, so the tree helpers work on all of them. */
10
+ type Flat<B> = B extends unknown ? Omit<B, "children" | "id"> : never;
11
+ /** Written out, not Omit'd: Omit over an index signature loses `type`. */
12
+ type CustomDraft = { type: string; text?: Text; [field: string]: unknown };
13
+ export type BuiltinDraft = Flat<Block>;
14
+ export type Draft = BuiltinDraft | CustomDraft;
15
+ export type Node = TreeNode<Draft>;
16
+ /** A node of one of the kit's own kinds, once an extension has been ruled out. */
17
+ export type BuiltinNode = TreeNode<BuiltinDraft>;
18
+ export type TextNode = Node & { text: Text };
19
+
20
+ export const hasText = (node: Node): node is TextNode => "text" in node && Array.isArray((node as { text?: unknown }).text);
21
+
22
+ /** An entry in the "/" menu: what it is called and the block it makes. */
23
+ export type BlockKind = { key: string; label: string; hint: string; icon: LucideIcon; make: (text: Text) => Draft };
24
+
25
+ /**
26
+ * A block type an app adds to the editor: a spoiler, a table of items, anything
27
+ * Notion would call a block. The kit's own blocks follow the same rules.
28
+ *
29
+ * - `kinds` are its entries in the "/" menu; `shortcuts` map what is typed at the
30
+ * start of an empty line ("!! ") to one of those entries' keys.
31
+ * - `holds` says which blocks may sit inside it, by type. Without it, none.
32
+ * - `toggle` makes it behave like Notion's toggle: Enter on its own line starts
33
+ * its first child, and Enter on an empty last child steps back out.
34
+ * - `Edit` draws it in the editor, from the parts the kit exports (BlockRow,
35
+ * BlockText, BlockList, Caption, useEditor). `View` draws it read-only in
36
+ * DocumentView. A block with `text` takes a caret; one without is selected whole.
37
+ * - `focus` puts the caret somewhere inside a block without `text` (a table's
38
+ * first cell) when the editor is asked to focus it, for example right after it
39
+ * is made from the "/" menu. Return false to have it selected instead.
40
+ *
41
+ * An extension may take the `type` of one of the kit's own blocks (not a list),
42
+ * to draw it differently: an app's picture block with a picker of its own, say.
43
+ * Its `kinds`, if it gives any, then replace the kit's entries for that type.
44
+ */
45
+ export type BlockExtension<Fields extends object = Record<string, unknown>> = {
46
+ type: string;
47
+ kinds?: BlockKind[];
48
+ shortcuts?: Record<string, string>;
49
+ holds?: (childType: string) => boolean;
50
+ toggle?: boolean;
51
+ /** `Fields` are the extension's own, typed for it: `BlockExtension<{ stars: number }>`. */
52
+ Edit: ComponentType<{ block: Node & Fields; depth: number }>;
53
+ View?: ComponentType<{ block: AnyBlock & Fields; depth: number }>;
54
+ focus?: (element: HTMLElement, at: number | "end") => boolean;
55
+ };
56
+
57
+ /**
58
+ * Which of the kit's "/" entries an app offers, and what they are called. Keys
59
+ * are the entries' own: text, h1, h2, h3, bullet, numbered, todo, quote, divider,
60
+ * image, video, bookmark. A hidden entry's typed shortcut goes with it; blocks of
61
+ * that kind already in a document are still drawn.
62
+ */
63
+ export type KindOptions = { hide?: string[]; labels?: Record<string, string>; hints?: Record<string, string> };
64
+
65
+ const BUILTIN_KINDS: BlockKind[] = [
66
+ { key: "text", label: "Text", hint: "Plain words", icon: Type, make: (text) => ({ type: "paragraph", text }) },
67
+ { key: "h1", label: "Heading 1", hint: "A big section heading", icon: Heading1, make: (text) => ({ type: "heading", level: 1, text }) },
68
+ { key: "h2", label: "Heading 2", hint: "A medium heading", icon: Heading2, make: (text) => ({ type: "heading", level: 2, text }) },
69
+ { key: "h3", label: "Heading 3", hint: "A small heading", icon: Heading3, make: (text) => ({ type: "heading", level: 3, text }) },
70
+ { key: "bullet", label: "Bulleted list", hint: "A simple list", icon: List, make: (text) => ({ type: "bullet", text }) },
71
+ { key: "numbered", label: "Numbered list", hint: "A list in order", icon: ListOrdered, make: (text) => ({ type: "numbered", text }) },
72
+ { key: "todo", label: "To-do", hint: "Something to tick off", icon: ListTodo, make: (text) => ({ type: "check", checked: false, text }) },
73
+ { key: "quote", label: "Quote", hint: "Something someone said", icon: Quote, make: (text) => ({ type: "quote", text }) },
74
+ { key: "divider", label: "Divider", hint: "A line between parts", icon: Minus, make: () => ({ type: "divider" }) },
75
+ { key: "image", label: "Image", hint: "A picture", icon: Image, make: () => ({ type: "image", caption: [], width: 1 }) },
76
+ { key: "video", label: "Video", hint: "From YouTube or Vimeo", icon: SquarePlay, make: () => ({ type: "video", url: "", caption: [] }) },
77
+ { key: "bookmark", label: "Link", hint: "A web page, as a card", icon: Bookmark, make: () => ({ type: "bookmark", url: "", title: "" }) },
78
+ ];
79
+
80
+ /** Typed at the start of an empty block, these turn it into that kind. */
81
+ const BUILTIN_SHORTCUTS: Record<string, string> = {
82
+ "- ": "bullet",
83
+ "* ": "bullet",
84
+ "1. ": "numbered",
85
+ "[] ": "todo",
86
+ "# ": "h1",
87
+ "## ": "h2",
88
+ "### ": "h3",
89
+ "> ": "quote",
90
+ "---": "divider",
91
+ };
92
+
93
+ /** Everything the editor knows about block types: the kit's, then an app's. */
94
+ export type Schema = {
95
+ kinds: BlockKind[];
96
+ /** The kinds a block of text can be turned into. */
97
+ textKinds: BlockKind[];
98
+ shortcuts: Record<string, string>;
99
+ kind: (key: string) => BlockKind | undefined;
100
+ kindOf: (node: Node) => BlockKind | undefined;
101
+ extension: (type: string) => AnyExtension | undefined;
102
+ nests: (type: string) => boolean;
103
+ holds: (parent: string, child: string) => boolean;
104
+ toggle: (type: string) => boolean;
105
+ };
106
+
107
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- each extension has fields of its own
108
+ export type AnyExtension = BlockExtension<any>;
109
+
110
+ export function schemaFor(extensions: AnyExtension[] = [], options: KindOptions = {}): Schema {
111
+ const byType = new Map(extensions.map((x) => [x.type, x]));
112
+ const hidden = new Set(options.hide ?? []);
113
+ const builtin = BUILTIN_KINDS.filter((k) => !hidden.has(k.key) && byType.get(k.make([]).type)?.kinds === undefined).map((k) => ({
114
+ ...k,
115
+ label: options.labels?.[k.key] ?? k.label,
116
+ hint: options.hints?.[k.key] ?? k.hint,
117
+ }));
118
+ const kinds = [...builtin, ...extensions.flatMap((x) => x.kinds ?? [])];
119
+ const offered = new Set(kinds.map((k) => k.key));
120
+ const shortcuts = Object.fromEntries(
121
+ Object.entries(Object.assign({}, BUILTIN_SHORTCUTS, ...extensions.map((x) => x.shortcuts ?? {})) as Record<string, string>).filter(([, key]) => offered.has(key)),
122
+ );
123
+ const holds = (parent: string, child: string) => {
124
+ const x = byType.get(parent);
125
+ if (x !== undefined) return x.holds?.(child) ?? false;
126
+ return isListType(parent) && isListType(child);
127
+ };
128
+ const nests = (type: string) => {
129
+ const x = byType.get(type);
130
+ return x !== undefined ? x.holds !== undefined : isListType(type);
131
+ };
132
+ return {
133
+ kinds,
134
+ textKinds: kinds.filter((k) => "text" in k.make([])),
135
+ shortcuts,
136
+ kind: (key) => kinds.find((k) => k.key === key),
137
+ kindOf: (node) =>
138
+ kinds.find((k) => {
139
+ const made = k.make([]) as { type: string; level?: number };
140
+ return made.type === node.type && (made.type !== "heading" || made.level === (node as { level?: number }).level);
141
+ }),
142
+ extension: (type) => byType.get(type),
143
+ nests,
144
+ holds,
145
+ toggle: (type) => byType.get(type)?.toggle === true,
146
+ };
147
+ }
148
+
149
+ /** From the stored shape to the editor's, giving every block its children. */
150
+ export const toNodes = (blocks: AnyBlock[]): Node[] =>
151
+ blocks.map((b) => ({ ...b, children: Array.isArray((b as { children?: unknown }).children) ? toNodes((b as { children: AnyBlock[] }).children) : [] }) as Node);
152
+
153
+ /** Back to the stored shape: only the kinds that hold children keep them. */
154
+ export const toBlocks = (nodes: Node[], schema: Schema): AnyBlock[] =>
155
+ nodes.map((n) => {
156
+ const { children, ...rest } = n;
157
+ return (schema.nests(n.type) ? { ...rest, children: toBlocks(children, schema) } : rest) as AnyBlock;
158
+ });
@@ -0,0 +1,90 @@
1
+ "use client";
2
+
3
+ import rough from "roughjs";
4
+ import type { Options } from "roughjs/bin/core";
5
+ import { useLayoutEffect, useRef, useState, type CSSProperties, type ReactNode } from "react";
6
+ import { cn } from "../../lib/utils.ts";
7
+
8
+ // One generator for the page. Every shape passes a seed, so a drawing is the same
9
+ // on each render instead of shimmering.
10
+ const gen = rough.generator();
11
+
12
+ type Point = [number, number];
13
+ export type Shape =
14
+ | { kind: "rect"; x: number; y: number; w: number; h: number }
15
+ | { kind: "polygon"; points: Point[] }
16
+ | { kind: "line"; from: Point; to: Point }
17
+ // An SVG path, for curves.
18
+ | { kind: "path"; d: string };
19
+
20
+ export type Pen = {
21
+ seed: number;
22
+ // CSS colours, so tokens work: "var(--ink)".
23
+ stroke?: string;
24
+ fill?: string;
25
+ fillStyle?: "hachure" | "cross-hatch" | "solid";
26
+ dashed?: boolean;
27
+ strokeWidth?: number;
28
+ };
29
+
30
+ /* Hand-drawn SVG paths for a shape. Colours go on as styles, not attributes, because
31
+ an SVG attribute cannot hold var(). */
32
+ export function RoughPaths({ shape, pen }: { shape: Shape; pen: Pen }) {
33
+ const options: Options = {
34
+ seed: pen.seed,
35
+ roughness: 1.3,
36
+ bowing: 1.2,
37
+ strokeWidth: pen.strokeWidth ?? 1.4,
38
+ fill: pen.fill ? "fill" : undefined,
39
+ fillStyle: pen.fillStyle ?? "hachure",
40
+ hachureGap: 5,
41
+ fillWeight: 1,
42
+ strokeLineDash: pen.dashed ? [6, 5] : undefined,
43
+ };
44
+ const drawable =
45
+ shape.kind === "rect"
46
+ ? gen.rectangle(shape.x, shape.y, shape.w, shape.h, options)
47
+ : shape.kind === "polygon"
48
+ ? gen.polygon(shape.points, options)
49
+ : shape.kind === "path"
50
+ ? gen.path(shape.d, options)
51
+ : gen.line(...shape.from, ...shape.to, options);
52
+
53
+ return gen.toPaths(drawable).map((path, i) => {
54
+ // rough marks fill strokes by giving them the fill colour as their stroke.
55
+ const isFill = path.stroke === "fill" || path.fill === "fill";
56
+ const solid = isFill && path.fill === "fill";
57
+ const style: CSSProperties = solid
58
+ ? { fill: pen.fill, stroke: "none" }
59
+ : { fill: "none", stroke: isFill ? pen.fill : (pen.stroke ?? "currentColor"), strokeWidth: path.strokeWidth, strokeLinecap: "round" };
60
+ return <path key={i} d={path.d} style={style} strokeDasharray={!isFill && pen.dashed ? "6 5" : undefined} />;
61
+ });
62
+ }
63
+
64
+ /* A box with a hand-drawn border. The content lays itself out with ordinary CSS;
65
+ the border is an SVG stretched over it and redrawn whenever the box resizes. */
66
+ export function RoughBox({ pen, className, children }: { pen: Pen; className?: string; children: ReactNode }) {
67
+ const ref = useRef<HTMLDivElement>(null);
68
+ const [size, setSize] = useState<{ w: number; h: number } | null>(null);
69
+
70
+ useLayoutEffect(() => {
71
+ const el = ref.current;
72
+ if (!el) return;
73
+ const measure = () => setSize({ w: el.offsetWidth, h: el.offsetHeight });
74
+ measure();
75
+ const observer = new ResizeObserver(measure);
76
+ observer.observe(el);
77
+ return () => observer.disconnect();
78
+ }, []);
79
+
80
+ return (
81
+ <div ref={ref} className={cn("relative", className)}>
82
+ {size && (
83
+ <svg aria-hidden width={size.w} height={size.h} className="pointer-events-none absolute inset-0 overflow-visible">
84
+ <RoughPaths shape={{ kind: "rect", x: 2, y: 2, w: size.w - 4, h: size.h - 4 }} pen={pen} />
85
+ </svg>
86
+ )}
87
+ <div className="relative">{children}</div>
88
+ </div>
89
+ );
90
+ }
@@ -0,0 +1,72 @@
1
+ "use client";
2
+
3
+ import { ChevronsUpDown } from "lucide-react";
4
+ import { useEffect, useState } from "react";
5
+ import { DropdownMenu, DropdownMenuContent, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuTrigger } from "./dropdown-menu.tsx";
6
+ import { ACCENTS, ACCENT_KEY, type Accent } from "../../lib/accent.ts";
7
+
8
+ const label = (accent: Accent) => accent[0].toUpperCase() + accent.slice(1);
9
+
10
+ // A dot in a theme's colour. It carries its own data-accent, so it shows that
11
+ // theme's colour in whichever mode is on, whatever the page's theme is. Paper has no
12
+ // colour of its own, so its dot is a plain one with a ring.
13
+ function Swatch({ accent }: { accent: Accent }) {
14
+ if (accent === "paper") return <span className="size-3 shrink-0 rounded-full bg-tag-gray-bg shadow-[inset_0_0_0_1px_var(--hairline-strong)]" />;
15
+ return <span data-accent={accent} className="size-3 shrink-0 rounded-full bg-accent" />;
16
+ }
17
+
18
+ /* The colour theme: which colour titles, markers and controls take, and the wash it
19
+ gives every surface, so the background matches. Separate from light and dark, and
20
+ remembered per browser. One row in the sidebar shows the current theme and opens
21
+ the list of them. */
22
+ export function AccentPicker() {
23
+ const [accent, setAccent] = useState<Accent>("paper");
24
+
25
+ // The <head> script has already applied the stored choice; this only reads it back.
26
+ useEffect(() => {
27
+ const stored = document.documentElement.dataset.accent as Accent | undefined;
28
+ if (stored && ACCENTS.includes(stored)) setAccent(stored);
29
+ }, []);
30
+
31
+ const choose = (next: Accent) => {
32
+ setAccent(next);
33
+ // Paper is the absence of a theme, so the stylesheet's defaults apply.
34
+ if (next === "paper") delete document.documentElement.dataset.accent;
35
+ else document.documentElement.dataset.accent = next;
36
+ try {
37
+ localStorage.setItem(ACCENT_KEY, next);
38
+ } catch {
39
+ // Private mode: the choice lasts for this page view only.
40
+ }
41
+ };
42
+
43
+ return (
44
+ <DropdownMenu>
45
+ <DropdownMenuTrigger asChild>
46
+ <button
47
+ type="button"
48
+ aria-label={`Colour theme: ${label(accent)}`}
49
+ className="flex h-[30px] w-full items-center gap-2 rounded-control px-2 text-sm font-medium text-ink-secondary transition-colors duration-100 hover:bg-tint-hover data-[state=open]:bg-tint-hover"
50
+ >
51
+ <span className="flex size-5 items-center justify-center">
52
+ <Swatch accent={accent} />
53
+ </span>
54
+ <span className="min-w-0 flex-1 truncate text-left">Colour</span>
55
+ <span className="text-ink-tertiary">{label(accent)}</span>
56
+ <ChevronsUpDown className="size-3.5 text-ink-tertiary" />
57
+ </button>
58
+ </DropdownMenuTrigger>
59
+ <DropdownMenuContent side="top" align="start" className="w-[var(--radix-dropdown-menu-trigger-width)]">
60
+ <DropdownMenuLabel>Colour theme</DropdownMenuLabel>
61
+ <DropdownMenuRadioGroup value={accent} onValueChange={(next) => choose(next as Accent)}>
62
+ {ACCENTS.map((a) => (
63
+ <DropdownMenuRadioItem key={a} value={a}>
64
+ <Swatch accent={a} />
65
+ {label(a)}
66
+ </DropdownMenuRadioItem>
67
+ ))}
68
+ </DropdownMenuRadioGroup>
69
+ </DropdownMenuContent>
70
+ </DropdownMenu>
71
+ );
72
+ }
@@ -0,0 +1,57 @@
1
+ "use client";
2
+
3
+ import { useState, type ReactNode } from "react";
4
+ import { cn } from "../../lib/utils.ts";
5
+
6
+ /* Where an empty block asks for a link: one field that commits on Enter, and
7
+ says why when what was pasted will not do. `check` returns that reason, or
8
+ null for an address it accepts. */
9
+ export function AddressField({
10
+ icon,
11
+ placeholder,
12
+ check,
13
+ onCommit,
14
+ autoFocus = true,
15
+ className,
16
+ }: {
17
+ icon?: ReactNode;
18
+ placeholder: string;
19
+ check: (url: string) => string | null;
20
+ onCommit: (url: string) => void;
21
+ autoFocus?: boolean;
22
+ className?: string;
23
+ }) {
24
+ const [value, setValue] = useState("");
25
+ const [error, setError] = useState<string | null>(null);
26
+ return (
27
+ <form
28
+ className={cn("flex flex-wrap items-center gap-2 rounded-surface bg-tint-hover px-4 py-3 text-sm", className)}
29
+ onSubmit={(e) => {
30
+ e.preventDefault();
31
+ const url = value.trim();
32
+ const problem = check(url);
33
+ if (problem === null) onCommit(url);
34
+ else setError(problem);
35
+ }}
36
+ >
37
+ {icon && <span className="text-ink-tertiary [&_svg]:size-4">{icon}</span>}
38
+ <input
39
+ autoFocus={autoFocus}
40
+ value={value}
41
+ onChange={(e) => {
42
+ setValue(e.target.value);
43
+ setError(null);
44
+ }}
45
+ placeholder={placeholder}
46
+ aria-label={placeholder}
47
+ aria-invalid={error !== null || undefined}
48
+ className="h-8 min-w-0 flex-1 bg-transparent text-ink outline-none placeholder:text-ink-tertiary"
49
+ />
50
+ {error !== null && (
51
+ <span role="alert" className="w-full text-danger">
52
+ {error}
53
+ </span>
54
+ )}
55
+ </form>
56
+ );
57
+ }
@@ -0,0 +1,138 @@
1
+ "use client";
2
+
3
+ import { useEffect, useState, type ReactNode } from "react";
4
+ import { cn } from "../../lib/utils.ts";
5
+
6
+ const TOGGLE_SIDEBAR = "ui:toggle-sidebar";
7
+
8
+ /** Opens or closes the sidebar from anywhere, as the shortcut does. */
9
+ export const toggleSidebar = (): void => void window.dispatchEvent(new Event(TOGGLE_SIDEBAR));
10
+
11
+ export type ShellControls = {
12
+ // Whether the sidebar is showing at the current screen size.
13
+ sidebarOpen: boolean;
14
+ openSidebar: () => void;
15
+ closeSidebar: () => void;
16
+ };
17
+
18
+ /* The frame of a Notion-like app: a sidebar beside a top bar and a scrolling main
19
+ area. On a wide screen the sidebar is a column that collapses to nothing (⌘\ or
20
+ Ctrl-\ toggles it). Below the `md` breakpoint it is a drawer over a scrim, closed
21
+ until asked for.
22
+
23
+ `sidebar` and `topbar` are functions so they can render their own open and close
24
+ buttons. Pass something that changes on navigation as `routeKey` (the pathname)
25
+ and the drawer closes when a destination is chosen from it.
26
+
27
+ `main` is a container: size content to the room it actually has with container
28
+ variants (`@6xl:max-w-…`), which account for the sidebar being open or shut. */
29
+ export function AppShell({
30
+ sidebar,
31
+ topbar,
32
+ children,
33
+ routeKey,
34
+ }: {
35
+ sidebar: (controls: ShellControls) => ReactNode;
36
+ topbar: (controls: ShellControls) => ReactNode;
37
+ children: ReactNode;
38
+ routeKey?: string;
39
+ }) {
40
+ const [open, setOpen] = useState(true);
41
+ const [drawer, setDrawer] = useState(false);
42
+
43
+ useEffect(() => setDrawer(false), [routeKey]);
44
+
45
+ useEffect(() => {
46
+ const onKey = (e: KeyboardEvent) => {
47
+ if ((e.metaKey || e.ctrlKey) && e.key === "\\") {
48
+ e.preventDefault();
49
+ setOpen((o) => !o);
50
+ }
51
+ };
52
+ // Anything outside the shell may ask for the sidebar: a full-window view
53
+ // with its own button for it. On a small screen that means the drawer.
54
+ const onToggle = () => {
55
+ if (window.matchMedia("(min-width: 768px)").matches) setOpen((o) => !o);
56
+ else setDrawer((d) => !d);
57
+ };
58
+ window.addEventListener("keydown", onKey);
59
+ window.addEventListener(TOGGLE_SIDEBAR, onToggle);
60
+ return () => {
61
+ window.removeEventListener("keydown", onKey);
62
+ window.removeEventListener(TOGGLE_SIDEBAR, onToggle);
63
+ };
64
+ }, []);
65
+
66
+ // How much of the window the sidebar takes, published as `--sidebar-w` for
67
+ // anything laid over the page that should leave the sidebar showing or
68
+ // centre itself on what is left (an image viewer, a selection bar).
69
+ useEffect(() => {
70
+ document.documentElement.style.setProperty("--sidebar-w", open ? "15rem" : "0px");
71
+ return () => void document.documentElement.style.removeProperty("--sidebar-w");
72
+ }, [open]);
73
+
74
+ const desktop: ShellControls = { sidebarOpen: open, openSidebar: () => setOpen(true), closeSidebar: () => setOpen(false) };
75
+ // On a small screen the bar always offers to open the drawer.
76
+ const mobile: ShellControls = { sidebarOpen: false, openSidebar: () => setDrawer(true), closeSidebar: () => setDrawer(false) };
77
+
78
+ return (
79
+ <div className="flex h-dvh">
80
+ <div
81
+ className={cn(
82
+ "hidden shrink-0 overflow-hidden transition-[width] duration-150 ease-out-notion md:block",
83
+ open ? "w-60" : "w-0",
84
+ )}
85
+ inert={!open}
86
+ >
87
+ {sidebar(desktop)}
88
+ </div>
89
+
90
+ <div className={cn("fixed inset-0 z-40 md:hidden", !drawer && "pointer-events-none")} inert={!drawer}>
91
+ <div
92
+ className={cn("absolute inset-0 bg-black/30 transition-opacity duration-150", drawer ? "opacity-100" : "opacity-0")}
93
+ onClick={() => setDrawer(false)}
94
+ />
95
+ <div
96
+ className={cn(
97
+ "absolute inset-y-0 left-0 transition-transform duration-150 ease-out-notion",
98
+ // The shadow would otherwise spill onto the page from off-screen.
99
+ drawer ? "translate-x-0 shadow-dialog" : "-translate-x-full",
100
+ )}
101
+ >
102
+ {sidebar(mobile)}
103
+ </div>
104
+ </div>
105
+
106
+ <div className="flex min-w-0 flex-1 flex-col">
107
+ {/* Rendered twice because "is the sidebar showing" has a different answer
108
+ at each size, and CSS picks the one that applies. */}
109
+ <div className="md:hidden">{topbar(mobile)}</div>
110
+ <div className="hidden md:block">{topbar(desktop)}</div>
111
+ <main className="@container flex-1 overflow-y-auto">{children}</main>
112
+ </div>
113
+ </div>
114
+ );
115
+ }
116
+
117
+ /* The sidebar's own frame: a fixed-width sunken column with a header, a scrolling
118
+ middle and an optional footer. It is a named group, `group/sidebar`, so controls
119
+ in the header can stay hidden until the sidebar is hovered. */
120
+ export function SidebarFrame({ header, footer, children, label }: { header?: ReactNode; footer?: ReactNode; children: ReactNode; label: string }) {
121
+ return (
122
+ <nav aria-label={label} className="group/sidebar flex h-full w-60 flex-col bg-surface-sunken shadow-[inset_-1px_0_0_var(--hairline)]">
123
+ {header && <div className="flex h-11 shrink-0 items-center gap-2 pr-2 pl-3">{header}</div>}
124
+ <div className="min-h-0 flex-1 overflow-y-auto px-1 pb-6">{children}</div>
125
+ {footer && <div className="shrink-0 p-1 shadow-[inset_0_1px_0_var(--hairline)]">{footer}</div>}
126
+ </nav>
127
+ );
128
+ }
129
+
130
+ /* A labelled group of entries inside the sidebar. */
131
+ export function SidebarSection({ title, children }: { title: string; children: ReactNode }) {
132
+ return (
133
+ <section className="mt-4 first:mt-1">
134
+ <h2 className="truncate px-2 pb-1 text-caption font-medium text-accent-text/80">{title}</h2>
135
+ {children}
136
+ </section>
137
+ );
138
+ }
@@ -0,0 +1,81 @@
1
+ import { cva, type VariantProps } from "class-variance-authority";
2
+ import type { ComponentPropsWithoutRef } from "react";
3
+ import { cn } from "../../lib/utils.ts";
4
+
5
+ /* ────────────────────────────────────────────────────────────────────────
6
+ The nine.
7
+
8
+ This is the highest-leverage idea borrowed from Notion: there is no
9
+ colour picker. Nine desaturated pairs, each a tinted background with
10
+ same-hue ink. Because every pair is pre-harmonised at low chroma, a
11
+ board with forty tags on it still reads calm — and a user cannot
12
+ produce an ugly combination, because they cannot produce an arbitrary
13
+ one. Resist adding a tenth.
14
+ ──────────────────────────────────────────────────────────────────────── */
15
+
16
+ export const TAG_COLORS = [
17
+ "gray",
18
+ "brown",
19
+ "orange",
20
+ "yellow",
21
+ "green",
22
+ "blue",
23
+ "purple",
24
+ "pink",
25
+ "red",
26
+ ] as const;
27
+
28
+ export type TagColor = (typeof TAG_COLORS)[number];
29
+
30
+ const badgeVariants = cva(
31
+ "inline-flex items-center gap-1 rounded-[3px] font-medium whitespace-nowrap [&_svg]:size-3 [&_svg]:shrink-0",
32
+ {
33
+ variants: {
34
+ color: {
35
+ gray: "bg-tag-gray-bg text-tag-gray-ink",
36
+ brown: "bg-tag-brown-bg text-tag-brown-ink",
37
+ orange: "bg-tag-orange-bg text-tag-orange-ink",
38
+ yellow: "bg-tag-yellow-bg text-tag-yellow-ink",
39
+ green: "bg-tag-green-bg text-tag-green-ink",
40
+ blue: "bg-tag-blue-bg text-tag-blue-ink",
41
+ purple: "bg-tag-purple-bg text-tag-purple-ink",
42
+ pink: "bg-tag-pink-bg text-tag-pink-ink",
43
+ red: "bg-tag-red-bg text-tag-red-ink",
44
+ },
45
+ size: {
46
+ sm: "h-[18px] px-1.5 text-[11px]",
47
+ md: "h-5 px-2 text-caption",
48
+ },
49
+ },
50
+ defaultVariants: { color: "gray", size: "md" },
51
+ },
52
+ );
53
+
54
+ export interface BadgeProps
55
+ extends Omit<ComponentPropsWithoutRef<"span">, "color">,
56
+ VariantProps<typeof badgeVariants> {}
57
+
58
+ export function Badge({ className, color, size, ...props }: BadgeProps) {
59
+ return (
60
+ <span
61
+ className={cn(badgeVariants({ color, size }), className)}
62
+ {...props}
63
+ />
64
+ );
65
+ }
66
+
67
+ /**
68
+ * Deterministically maps any string to one of the nine. Use it for tags,
69
+ * owners, labels — anything user-generated that needs a stable colour
70
+ * without anyone choosing one.
71
+ */
72
+ export function tagColorFor(value: string): TagColor {
73
+ let hash = 0;
74
+ for (let i = 0; i < value.length; i++) {
75
+ hash = (hash << 5) - hash + value.charCodeAt(i);
76
+ hash |= 0;
77
+ }
78
+ return TAG_COLORS[Math.abs(hash) % TAG_COLORS.length];
79
+ }
80
+
81
+ export { badgeVariants };
@@ -0,0 +1,25 @@
1
+ import { Fragment, type ElementType } from "react";
2
+
3
+ export type Crumb = { title: string; href?: string };
4
+
5
+ /* Where you are. A crumb with an href is a link; the last one usually has none.
6
+ Pass your router's link as `link` (next/link, react-router's Link); it gets
7
+ `href`, `className` and children. */
8
+ export function Breadcrumbs({ crumbs, link: Link = "a" }: { crumbs: Crumb[]; link?: ElementType }) {
9
+ return (
10
+ <nav aria-label="Breadcrumb" className="flex min-w-0 items-center text-sm">
11
+ {crumbs.map((crumb, i) => (
12
+ <Fragment key={i}>
13
+ {i > 0 && <span className="px-0.5 text-ink-tertiary">/</span>}
14
+ {crumb.href ? (
15
+ <Link href={crumb.href} className="truncate rounded-control px-1.5 py-0.5 transition-colors duration-100 hover:bg-tint-hover">
16
+ {crumb.title}
17
+ </Link>
18
+ ) : (
19
+ <span className="truncate px-1.5 py-0.5 text-ink-secondary">{crumb.title}</span>
20
+ )}
21
+ </Fragment>
22
+ ))}
23
+ </nav>
24
+ );
25
+ }