@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.
- package/CHANGELOG.md +5 -0
- package/LICENSE +21 -0
- package/README.md +252 -2
- package/dist/components/editor/block-text.d.ts +8 -0
- package/dist/components/editor/block-text.d.ts.map +1 -0
- package/dist/components/editor/block-text.js +213 -0
- package/dist/components/editor/block-text.js.map +1 -0
- package/dist/components/editor/blocks.d.ts +33 -0
- package/dist/components/editor/blocks.d.ts.map +1 -0
- package/dist/components/editor/blocks.js +187 -0
- package/dist/components/editor/blocks.js.map +1 -0
- package/dist/components/editor/document-editor.d.ts +27 -0
- package/dist/components/editor/document-editor.d.ts.map +1 -0
- package/dist/components/editor/document-editor.js +40 -0
- package/dist/components/editor/document-editor.js.map +1 -0
- package/dist/components/editor/document-view.d.ts +22 -0
- package/dist/components/editor/document-view.d.ts.map +1 -0
- package/dist/components/editor/document-view.js +105 -0
- package/dist/components/editor/document-view.js.map +1 -0
- package/dist/components/editor/editor-state.d.ts +100 -0
- package/dist/components/editor/editor-state.d.ts.map +1 -0
- package/dist/components/editor/editor-state.js +192 -0
- package/dist/components/editor/editor-state.js.map +1 -0
- package/dist/components/editor/extensions/spoiler.d.ts +8 -0
- package/dist/components/editor/extensions/spoiler.d.ts.map +1 -0
- package/dist/components/editor/extensions/spoiler.js +36 -0
- package/dist/components/editor/extensions/spoiler.js.map +1 -0
- package/dist/components/editor/index.d.ts +9 -0
- package/dist/components/editor/index.d.ts.map +1 -0
- package/dist/components/editor/index.js +9 -0
- package/dist/components/editor/index.js.map +1 -0
- package/dist/components/editor/kinds.d.ts +99 -0
- package/dist/components/editor/kinds.d.ts.map +1 -0
- package/dist/components/editor/kinds.js +74 -0
- package/dist/components/editor/kinds.js.map +1 -0
- package/dist/components/sketch/rough.d.ts +38 -0
- package/dist/components/sketch/rough.d.ts.map +1 -0
- package/dist/components/sketch/rough.js +57 -0
- package/dist/components/sketch/rough.js.map +1 -0
- package/dist/components/ui/accent-picker.d.ts +2 -0
- package/dist/components/ui/accent-picker.d.ts.map +1 -0
- package/dist/components/ui/accent-picker.js +44 -0
- package/dist/components/ui/accent-picker.js.map +1 -0
- package/dist/components/ui/address-field.d.ts +10 -0
- package/dist/components/ui/address-field.d.ts.map +1 -0
- package/dist/components/ui/address-field.js +24 -0
- package/dist/components/ui/address-field.js.map +1 -0
- package/dist/components/ui/app-shell.d.ts +25 -0
- package/dist/components/ui/app-shell.d.ts.map +1 -0
- package/dist/components/ui/app-shell.js +69 -0
- package/dist/components/ui/app-shell.js.map +1 -0
- package/dist/components/ui/badge.d.ts +19 -0
- package/dist/components/ui/badge.d.ts.map +1 -0
- package/dist/components/ui/badge.js +62 -0
- package/dist/components/ui/badge.js.map +1 -0
- package/dist/components/ui/breadcrumbs.d.ts +10 -0
- package/dist/components/ui/breadcrumbs.d.ts.map +1 -0
- package/dist/components/ui/breadcrumbs.js +9 -0
- package/dist/components/ui/breadcrumbs.js.map +1 -0
- package/dist/components/ui/button.d.ts +13 -0
- package/dist/components/ui/button.d.ts.map +1 -0
- package/dist/components/ui/button.js +45 -0
- package/dist/components/ui/button.js.map +1 -0
- package/dist/components/ui/calendar.d.ts +5 -0
- package/dist/components/ui/calendar.d.ts.map +1 -0
- package/dist/components/ui/calendar.js +64 -0
- package/dist/components/ui/calendar.js.map +1 -0
- package/dist/components/ui/callout.d.ts +13 -0
- package/dist/components/ui/callout.d.ts.map +1 -0
- package/dist/components/ui/callout.js +27 -0
- package/dist/components/ui/callout.js.map +1 -0
- package/dist/components/ui/card.d.ts +13 -0
- package/dist/components/ui/card.d.ts.map +1 -0
- package/dist/components/ui/card.js +27 -0
- package/dist/components/ui/card.js.map +1 -0
- package/dist/components/ui/checkbox.d.ts +6 -0
- package/dist/components/ui/checkbox.d.ts.map +1 -0
- package/dist/components/ui/checkbox.js +10 -0
- package/dist/components/ui/checkbox.js.map +1 -0
- package/dist/components/ui/command-menu.d.ts +15 -0
- package/dist/components/ui/command-menu.d.ts.map +1 -0
- package/dist/components/ui/command-menu.js +24 -0
- package/dist/components/ui/command-menu.js.map +1 -0
- package/dist/components/ui/date-picker.d.ts +35 -0
- package/dist/components/ui/date-picker.d.ts.map +1 -0
- package/dist/components/ui/date-picker.js +56 -0
- package/dist/components/ui/date-picker.js.map +1 -0
- package/dist/components/ui/date-time-picker.d.ts +19 -0
- package/dist/components/ui/date-time-picker.d.ts.map +1 -0
- package/dist/components/ui/date-time-picker.js +32 -0
- package/dist/components/ui/date-time-picker.js.map +1 -0
- package/dist/components/ui/dialog.d.ts +17 -0
- package/dist/components/ui/dialog.d.ts.map +1 -0
- package/dist/components/ui/dialog.js +33 -0
- package/dist/components/ui/dialog.js.map +1 -0
- package/dist/components/ui/dropdown-menu.d.ts +20 -0
- package/dist/components/ui/dropdown-menu.d.ts.map +1 -0
- package/dist/components/ui/dropdown-menu.js +56 -0
- package/dist/components/ui/dropdown-menu.js.map +1 -0
- package/dist/components/ui/editable-text.d.ts +17 -0
- package/dist/components/ui/editable-text.d.ts.map +1 -0
- package/dist/components/ui/editable-text.js +68 -0
- package/dist/components/ui/editable-text.js.map +1 -0
- package/dist/components/ui/field-button.d.ts +14 -0
- package/dist/components/ui/field-button.d.ts.map +1 -0
- package/dist/components/ui/field-button.js +16 -0
- package/dist/components/ui/field-button.js.map +1 -0
- package/dist/components/ui/file-preview.d.ts +5 -0
- package/dist/components/ui/file-preview.d.ts.map +1 -0
- package/dist/components/ui/file-preview.js +66 -0
- package/dist/components/ui/file-preview.js.map +1 -0
- package/dist/components/ui/file-uploader.d.ts +39 -0
- package/dist/components/ui/file-uploader.d.ts.map +1 -0
- package/dist/components/ui/file-uploader.js +110 -0
- package/dist/components/ui/file-uploader.js.map +1 -0
- package/dist/components/ui/handle-row.d.ts +15 -0
- package/dist/components/ui/handle-row.d.ts.map +1 -0
- package/dist/components/ui/handle-row.js +41 -0
- package/dist/components/ui/handle-row.js.map +1 -0
- package/dist/components/ui/image-block.d.ts +31 -0
- package/dist/components/ui/image-block.d.ts.map +1 -0
- package/dist/components/ui/image-block.js +103 -0
- package/dist/components/ui/image-block.js.map +1 -0
- package/dist/components/ui/image-card.d.ts +17 -0
- package/dist/components/ui/image-card.d.ts.map +1 -0
- package/dist/components/ui/image-card.js +38 -0
- package/dist/components/ui/image-card.js.map +1 -0
- package/dist/components/ui/image-viewer.d.ts +31 -0
- package/dist/components/ui/image-viewer.d.ts.map +1 -0
- package/dist/components/ui/image-viewer.js +81 -0
- package/dist/components/ui/image-viewer.js.map +1 -0
- package/dist/components/ui/image.d.ts +11 -0
- package/dist/components/ui/image.d.ts.map +1 -0
- package/dist/components/ui/image.js +32 -0
- package/dist/components/ui/image.js.map +1 -0
- package/dist/components/ui/index.d.ts +49 -0
- package/dist/components/ui/index.d.ts.map +1 -0
- package/dist/components/ui/index.js +49 -0
- package/dist/components/ui/index.js.map +1 -0
- package/dist/components/ui/input.d.ts +16 -0
- package/dist/components/ui/input.d.ts.map +1 -0
- package/dist/components/ui/input.js +32 -0
- package/dist/components/ui/input.js.map +1 -0
- package/dist/components/ui/link-block.d.ts +13 -0
- package/dist/components/ui/link-block.d.ts.map +1 -0
- package/dist/components/ui/link-block.js +21 -0
- package/dist/components/ui/link-block.js.map +1 -0
- package/dist/components/ui/mac-card.d.ts +15 -0
- package/dist/components/ui/mac-card.d.ts.map +1 -0
- package/dist/components/ui/mac-card.js +9 -0
- package/dist/components/ui/mac-card.js.map +1 -0
- package/dist/components/ui/nav-tree.d.ts +16 -0
- package/dist/components/ui/nav-tree.d.ts.map +1 -0
- package/dist/components/ui/nav-tree.js +34 -0
- package/dist/components/ui/nav-tree.js.map +1 -0
- package/dist/components/ui/page.d.ts +12 -0
- package/dist/components/ui/page.d.ts.map +1 -0
- package/dist/components/ui/page.js +15 -0
- package/dist/components/ui/page.js.map +1 -0
- package/dist/components/ui/popover.d.ts +8 -0
- package/dist/components/ui/popover.d.ts.map +1 -0
- package/dist/components/ui/popover.js +18 -0
- package/dist/components/ui/popover.js.map +1 -0
- package/dist/components/ui/progress.d.ts +9 -0
- package/dist/components/ui/progress.d.ts.map +1 -0
- package/dist/components/ui/progress.js +9 -0
- package/dist/components/ui/progress.js.map +1 -0
- package/dist/components/ui/property.d.ts +15 -0
- package/dist/components/ui/property.d.ts.map +1 -0
- package/dist/components/ui/property.js +34 -0
- package/dist/components/ui/property.js.map +1 -0
- package/dist/components/ui/segmented.d.ts +13 -0
- package/dist/components/ui/segmented.d.ts.map +1 -0
- package/dist/components/ui/segmented.js +10 -0
- package/dist/components/ui/segmented.js.map +1 -0
- package/dist/components/ui/select-menu.d.ts +10 -0
- package/dist/components/ui/select-menu.d.ts.map +1 -0
- package/dist/components/ui/select-menu.js +10 -0
- package/dist/components/ui/select-menu.js.map +1 -0
- package/dist/components/ui/select.d.ts +11 -0
- package/dist/components/ui/select.d.ts.map +1 -0
- package/dist/components/ui/select.js +31 -0
- package/dist/components/ui/select.js.map +1 -0
- package/dist/components/ui/selection-bar.d.ts +12 -0
- package/dist/components/ui/selection-bar.d.ts.map +1 -0
- package/dist/components/ui/selection-bar.js +15 -0
- package/dist/components/ui/selection-bar.js.map +1 -0
- package/dist/components/ui/separator.d.ts +4 -0
- package/dist/components/ui/separator.d.ts.map +1 -0
- package/dist/components/ui/separator.js +12 -0
- package/dist/components/ui/separator.js.map +1 -0
- package/dist/components/ui/spotlight.d.ts +23 -0
- package/dist/components/ui/spotlight.d.ts.map +1 -0
- package/dist/components/ui/spotlight.js +107 -0
- package/dist/components/ui/spotlight.js.map +1 -0
- package/dist/components/ui/stat-tile.d.ts +8 -0
- package/dist/components/ui/stat-tile.d.ts.map +1 -0
- package/dist/components/ui/stat-tile.js +9 -0
- package/dist/components/ui/stat-tile.js.map +1 -0
- package/dist/components/ui/step-dialog.d.ts +20 -0
- package/dist/components/ui/step-dialog.d.ts.map +1 -0
- package/dist/components/ui/step-dialog.js +36 -0
- package/dist/components/ui/step-dialog.js.map +1 -0
- package/dist/components/ui/table.d.ts +8 -0
- package/dist/components/ui/table.d.ts.map +1 -0
- package/dist/components/ui/table.js +23 -0
- package/dist/components/ui/table.js.map +1 -0
- package/dist/components/ui/theme-toggle.d.ts +2 -0
- package/dist/components/ui/theme-toggle.d.ts.map +1 -0
- package/dist/components/ui/theme-toggle.js +49 -0
- package/dist/components/ui/theme-toggle.js.map +1 -0
- package/dist/components/ui/time-picker.d.ts +21 -0
- package/dist/components/ui/time-picker.d.ts.map +1 -0
- package/dist/components/ui/time-picker.js +63 -0
- package/dist/components/ui/time-picker.js.map +1 -0
- package/dist/components/ui/tooltip.d.ts +15 -0
- package/dist/components/ui/tooltip.d.ts.map +1 -0
- package/dist/components/ui/tooltip.js +21 -0
- package/dist/components/ui/tooltip.js.map +1 -0
- package/dist/components/ui/typography.d.ts +34 -0
- package/dist/components/ui/typography.d.ts.map +1 -0
- package/dist/components/ui/typography.js +72 -0
- package/dist/components/ui/typography.js.map +1 -0
- package/dist/components/ui/video-block.d.ts +14 -0
- package/dist/components/ui/video-block.d.ts.map +1 -0
- package/dist/components/ui/video-block.js +18 -0
- package/dist/components/ui/video-block.js.map +1 -0
- package/dist/hooks/use-save-queue.d.ts +13 -0
- package/dist/hooks/use-save-queue.d.ts.map +1 -0
- package/dist/hooks/use-save-queue.js +45 -0
- package/dist/hooks/use-save-queue.js.map +1 -0
- package/dist/hooks/use-selection.d.ts +10 -0
- package/dist/hooks/use-selection.d.ts.map +1 -0
- package/dist/hooks/use-selection.js +43 -0
- package/dist/hooks/use-selection.js.map +1 -0
- package/dist/hooks/use-shared-transition.d.ts +3 -0
- package/dist/hooks/use-shared-transition.d.ts.map +1 -0
- package/dist/hooks/use-shared-transition.js +38 -0
- package/dist/hooks/use-shared-transition.js.map +1 -0
- package/dist/hooks/use-upload-queue.d.ts +22 -0
- package/dist/hooks/use-upload-queue.d.ts.map +1 -0
- package/dist/hooks/use-upload-queue.js +78 -0
- package/dist/hooks/use-upload-queue.js.map +1 -0
- package/dist/lib/accent.d.ts +5 -0
- package/dist/lib/accent.d.ts.map +1 -0
- package/dist/lib/accent.js +10 -0
- package/dist/lib/accent.js.map +1 -0
- package/dist/lib/bento.d.ts +17 -0
- package/dist/lib/bento.d.ts.map +1 -0
- package/dist/lib/bento.js +92 -0
- package/dist/lib/bento.js.map +1 -0
- package/dist/lib/dates.d.ts +14 -0
- package/dist/lib/dates.d.ts.map +1 -0
- package/dist/lib/dates.js +34 -0
- package/dist/lib/dates.js.map +1 -0
- package/dist/lib/document.d.ts +79 -0
- package/dist/lib/document.d.ts.map +1 -0
- package/dist/lib/document.js +11 -0
- package/dist/lib/document.js.map +1 -0
- package/dist/lib/embed.d.ts +14 -0
- package/dist/lib/embed.d.ts.map +1 -0
- package/dist/lib/embed.js +63 -0
- package/dist/lib/embed.js.map +1 -0
- package/dist/lib/files.d.ts +23 -0
- package/dist/lib/files.d.ts.map +1 -0
- package/dist/lib/files.js +69 -0
- package/dist/lib/files.js.map +1 -0
- package/dist/lib/justified.d.ts +50 -0
- package/dist/lib/justified.d.ts.map +1 -0
- package/dist/lib/justified.js +78 -0
- package/dist/lib/justified.js.map +1 -0
- package/dist/lib/rich-text-dom.d.ts +14 -0
- package/dist/lib/rich-text-dom.d.ts.map +1 -0
- package/dist/lib/rich-text-dom.js +143 -0
- package/dist/lib/rich-text-dom.js.map +1 -0
- package/dist/lib/rich-text.d.ts +15 -0
- package/dist/lib/rich-text.d.ts.map +1 -0
- package/dist/lib/rich-text.js +35 -0
- package/dist/lib/rich-text.js.map +1 -0
- package/dist/lib/spotlight.d.ts +22 -0
- package/dist/lib/spotlight.d.ts.map +1 -0
- package/dist/lib/spotlight.js +66 -0
- package/dist/lib/spotlight.js.map +1 -0
- package/dist/lib/tree.d.ts +17 -0
- package/dist/lib/tree.d.ts.map +1 -0
- package/dist/lib/tree.js +35 -0
- package/dist/lib/tree.js.map +1 -0
- package/dist/lib/utils.d.ts +3 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +6 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/styles/notion.css +526 -0
- package/package.json +106 -5
- package/src/components/editor/block-text.tsx +230 -0
- package/src/components/editor/blocks.tsx +368 -0
- package/src/components/editor/document-editor.tsx +101 -0
- package/src/components/editor/document-view.tsx +192 -0
- package/src/components/editor/editor-state.tsx +270 -0
- package/src/components/editor/extensions/spoiler.tsx +76 -0
- package/src/components/editor/index.ts +9 -0
- package/src/components/editor/kinds.ts +158 -0
- package/src/components/sketch/rough.tsx +90 -0
- package/src/components/ui/accent-picker.tsx +72 -0
- package/src/components/ui/address-field.tsx +57 -0
- package/src/components/ui/app-shell.tsx +138 -0
- package/src/components/ui/badge.tsx +81 -0
- package/src/components/ui/breadcrumbs.tsx +25 -0
- package/src/components/ui/button.tsx +73 -0
- package/src/components/ui/calendar.tsx +100 -0
- package/src/components/ui/callout.tsx +62 -0
- package/src/components/ui/card.tsx +90 -0
- package/src/components/ui/checkbox.tsx +32 -0
- package/src/components/ui/command-menu.tsx +72 -0
- package/src/components/ui/date-picker.tsx +170 -0
- package/src/components/ui/date-time-picker.tsx +117 -0
- package/src/components/ui/dialog.tsx +124 -0
- package/src/components/ui/dropdown-menu.tsx +183 -0
- package/src/components/ui/editable-text.tsx +109 -0
- package/src/components/ui/field-button.tsx +68 -0
- package/src/components/ui/file-preview.tsx +80 -0
- package/src/components/ui/file-uploader.tsx +376 -0
- package/src/components/ui/handle-row.tsx +116 -0
- package/src/components/ui/image-block.tsx +238 -0
- package/src/components/ui/image-card.tsx +102 -0
- package/src/components/ui/image-viewer.tsx +187 -0
- package/src/components/ui/image.tsx +96 -0
- package/src/components/ui/index.ts +83 -0
- package/src/components/ui/input.tsx +99 -0
- package/src/components/ui/link-block.tsx +82 -0
- package/src/components/ui/mac-card.tsx +46 -0
- package/src/components/ui/nav-tree.tsx +86 -0
- package/src/components/ui/page.tsx +25 -0
- package/src/components/ui/popover.tsx +42 -0
- package/src/components/ui/progress.tsx +36 -0
- package/src/components/ui/property.tsx +64 -0
- package/src/components/ui/segmented.tsx +42 -0
- package/src/components/ui/select-menu.tsx +46 -0
- package/src/components/ui/select.tsx +124 -0
- package/src/components/ui/selection-bar.tsx +50 -0
- package/src/components/ui/separator.tsx +30 -0
- package/src/components/ui/spotlight.tsx +222 -0
- package/src/components/ui/stat-tile.tsx +25 -0
- package/src/components/ui/step-dialog.tsx +104 -0
- package/src/components/ui/table.tsx +42 -0
- package/src/components/ui/theme-toggle.tsx +101 -0
- package/src/components/ui/time-picker.tsx +173 -0
- package/src/components/ui/tooltip.tsx +64 -0
- package/src/components/ui/typography.tsx +168 -0
- package/src/components/ui/video-block.tsx +60 -0
- package/src/hooks/use-save-queue.ts +66 -0
- package/src/hooks/use-selection.ts +44 -0
- package/src/hooks/use-shared-transition.ts +40 -0
- package/src/hooks/use-upload-queue.ts +111 -0
- package/src/lib/accent.ts +11 -0
- package/src/lib/bento.ts +87 -0
- package/src/lib/dates.ts +39 -0
- package/src/lib/document.ts +55 -0
- package/src/lib/embed.ts +62 -0
- package/src/lib/files.ts +73 -0
- package/src/lib/justified.ts +106 -0
- package/src/lib/rich-text-dom.ts +136 -0
- package/src/lib/rich-text.ts +50 -0
- package/src/lib/spotlight.ts +78 -0
- package/src/lib/tree.ts +41 -0
- package/src/lib/utils.ts +6 -0
- package/src/styles/notion.css +526 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { CalendarClock } from "lucide-react";
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { Button } from "./button.tsx";
|
|
6
|
+
import { Calendar, focusCalendarDay } from "./calendar.tsx";
|
|
7
|
+
import { FieldButton, type FieldButtonProps } from "./field-button.tsx";
|
|
8
|
+
import { Popover, PopoverClose, PopoverContent, PopoverTrigger } from "./popover.tsx";
|
|
9
|
+
import { TimeColumns } from "./time-picker.tsx";
|
|
10
|
+
import { formatDay, fromISODate, isTime, splitDateTime, toISODate } from "../../lib/dates.ts";
|
|
11
|
+
|
|
12
|
+
export interface DateTimePickerProps extends Omit<FieldButtonProps, "value" | "onChange" | "children" | "onClear" | "icon"> {
|
|
13
|
+
/** `YYYY-MM-DDTHH:MM`, local, or null for none. What a `datetime-local` input holds. */
|
|
14
|
+
value: string | null;
|
|
15
|
+
onChange: (value: string | null) => void;
|
|
16
|
+
/** Earliest and latest day that can be chosen, `YYYY-MM-DD`. */
|
|
17
|
+
min?: string | null;
|
|
18
|
+
max?: string | null;
|
|
19
|
+
/** The month shown when nothing is chosen yet, as any day in it. */
|
|
20
|
+
openTo?: string | null;
|
|
21
|
+
/** The time a day gets when it is chosen before any time is. */
|
|
22
|
+
defaultTime?: string;
|
|
23
|
+
minuteStep?: number;
|
|
24
|
+
clearable?: boolean;
|
|
25
|
+
/** Sends the value with a form, as a hidden field of this name. */
|
|
26
|
+
name?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/* A day and a time of day, in one field: the calendar with the clock beside it
|
|
30
|
+
(below it, on a phone). There is no value until there is a day. A time chosen
|
|
31
|
+
first is held and joins the day when one is picked. */
|
|
32
|
+
export function DateTimePicker({
|
|
33
|
+
value,
|
|
34
|
+
onChange,
|
|
35
|
+
min,
|
|
36
|
+
max,
|
|
37
|
+
openTo,
|
|
38
|
+
defaultTime = "12:00",
|
|
39
|
+
minuteStep = 5,
|
|
40
|
+
clearable = true,
|
|
41
|
+
placeholder = "Pick a date and time",
|
|
42
|
+
name,
|
|
43
|
+
...props
|
|
44
|
+
}: DateTimePickerProps) {
|
|
45
|
+
const [open, setOpen] = useState(false);
|
|
46
|
+
/** A time chosen while there is still no day to attach it to. */
|
|
47
|
+
const [heldTime, setHeldTime] = useState<string | null>(null);
|
|
48
|
+
|
|
49
|
+
const { date, time } = splitDateTime(value);
|
|
50
|
+
const selected = fromISODate(date);
|
|
51
|
+
// Shown even before there is a day: it is the time the day will get.
|
|
52
|
+
const shownTime = date === null ? (heldTime ?? defaultTime) : (time ?? defaultTime);
|
|
53
|
+
const from = fromISODate(min);
|
|
54
|
+
const to = fromISODate(max);
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<Popover
|
|
58
|
+
open={open}
|
|
59
|
+
onOpenChange={(next) => {
|
|
60
|
+
setOpen(next);
|
|
61
|
+
if (!next) setHeldTime(null);
|
|
62
|
+
}}
|
|
63
|
+
>
|
|
64
|
+
<PopoverTrigger asChild>
|
|
65
|
+
<FieldButton
|
|
66
|
+
icon={CalendarClock}
|
|
67
|
+
placeholder={placeholder}
|
|
68
|
+
onClear={clearable ? () => onChange(null) : undefined}
|
|
69
|
+
clearLabel="Clear the date and time"
|
|
70
|
+
{...props}
|
|
71
|
+
>
|
|
72
|
+
{selected === undefined ? null : (
|
|
73
|
+
<>
|
|
74
|
+
{formatDay(selected)}
|
|
75
|
+
<span className="ml-2 text-ink-secondary tabular-nums">{time ?? defaultTime}</span>
|
|
76
|
+
</>
|
|
77
|
+
)}
|
|
78
|
+
</FieldButton>
|
|
79
|
+
</PopoverTrigger>
|
|
80
|
+
{name !== undefined && <input type="hidden" name={name} value={date === null ? "" : `${date}T${time ?? defaultTime}`} />}
|
|
81
|
+
<PopoverContent
|
|
82
|
+
className="w-auto"
|
|
83
|
+
onOpenAutoFocus={focusCalendarDay}
|
|
84
|
+
>
|
|
85
|
+
<div className="flex max-sm:flex-col sm:divide-x sm:divide-hairline">
|
|
86
|
+
<Calendar
|
|
87
|
+
mode="single"
|
|
88
|
+
required
|
|
89
|
+
selected={selected}
|
|
90
|
+
onSelect={(day: Date) => onChange(`${toISODate(day)}T${shownTime}`)}
|
|
91
|
+
defaultMonth={selected ?? fromISODate(openTo) ?? from}
|
|
92
|
+
disabled={[...(from === undefined ? [] : [{ before: from }]), ...(to === undefined ? [] : [{ after: to }])]}
|
|
93
|
+
startMonth={from}
|
|
94
|
+
endMonth={to}
|
|
95
|
+
className="max-sm:mx-auto"
|
|
96
|
+
/>
|
|
97
|
+
<TimeColumns
|
|
98
|
+
value={isTime(shownTime) ? shownTime : null}
|
|
99
|
+
onChange={(next) => (date === null ? setHeldTime(next) : onChange(`${date}T${next}`))}
|
|
100
|
+
minuteStep={minuteStep}
|
|
101
|
+
fallbackHour={defaultTime.slice(0, 2)}
|
|
102
|
+
// Beside the calendar the lists are as tall as it is; under it, on a phone, short.
|
|
103
|
+
className="sm:[&>div]:h-[17.75rem] max-sm:justify-center max-sm:border-hairline max-sm:border-t max-sm:[&>div]:h-32"
|
|
104
|
+
/>
|
|
105
|
+
</div>
|
|
106
|
+
<div className="flex items-center justify-between gap-3 border-hairline border-t p-1.5 pl-3">
|
|
107
|
+
<p className="text-caption text-ink-tertiary">{date === null ? "Pick a day to set it." : " "}</p>
|
|
108
|
+
<PopoverClose asChild>
|
|
109
|
+
<Button variant="ghost" size="sm">
|
|
110
|
+
Done
|
|
111
|
+
</Button>
|
|
112
|
+
</PopoverClose>
|
|
113
|
+
</div>
|
|
114
|
+
</PopoverContent>
|
|
115
|
+
</Popover>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
|
4
|
+
import { X } from "lucide-react";
|
|
5
|
+
import type { ComponentPropsWithoutRef } from "react";
|
|
6
|
+
import { cn } from "../../lib/utils.ts";
|
|
7
|
+
|
|
8
|
+
export const Dialog = DialogPrimitive.Root;
|
|
9
|
+
export const DialogTrigger = DialogPrimitive.Trigger;
|
|
10
|
+
export const DialogClose = DialogPrimitive.Close;
|
|
11
|
+
export const DialogPortal = DialogPrimitive.Portal;
|
|
12
|
+
|
|
13
|
+
/* The scrim is light — 32%, not 60%. The page behind stays legible, so
|
|
14
|
+
a dialog reads as a layer rather than a mode switch. */
|
|
15
|
+
export function DialogOverlay({
|
|
16
|
+
className,
|
|
17
|
+
...props
|
|
18
|
+
}: ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>) {
|
|
19
|
+
return (
|
|
20
|
+
<DialogPrimitive.Overlay
|
|
21
|
+
className={cn(
|
|
22
|
+
"z-50 fixed inset-0 bg-black/32",
|
|
23
|
+
"data-[state=open]:animate-fade-in data-[state=closed]:animate-fade-out",
|
|
24
|
+
className,
|
|
25
|
+
)}
|
|
26
|
+
{...props}
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface DialogContentProps
|
|
32
|
+
extends ComponentPropsWithoutRef<typeof DialogPrimitive.Content> {
|
|
33
|
+
showClose?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function DialogContent({
|
|
37
|
+
className,
|
|
38
|
+
children,
|
|
39
|
+
showClose = true,
|
|
40
|
+
...props
|
|
41
|
+
}: DialogContentProps) {
|
|
42
|
+
return (
|
|
43
|
+
<DialogPortal>
|
|
44
|
+
<DialogOverlay />
|
|
45
|
+
<DialogPrimitive.Content
|
|
46
|
+
className={cn(
|
|
47
|
+
"z-50 fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2",
|
|
48
|
+
"w-[calc(100vw-2rem)] max-w-lg max-h-[85vh] overflow-y-auto",
|
|
49
|
+
"bg-surface-overlay shadow-dialog rounded-overlay",
|
|
50
|
+
"data-[state=open]:animate-scale-in data-[state=closed]:animate-scale-out",
|
|
51
|
+
className,
|
|
52
|
+
)}
|
|
53
|
+
{...props}
|
|
54
|
+
>
|
|
55
|
+
{children}
|
|
56
|
+
{showClose && (
|
|
57
|
+
<DialogPrimitive.Close
|
|
58
|
+
className={cn(
|
|
59
|
+
"top-3 right-3 absolute inline-flex justify-center items-center",
|
|
60
|
+
"rounded-control size-7 text-ink-tertiary hover:text-ink",
|
|
61
|
+
"hover:bg-tint-hover transition-colors duration-100",
|
|
62
|
+
)}
|
|
63
|
+
aria-label="Close"
|
|
64
|
+
>
|
|
65
|
+
<X className="size-4" />
|
|
66
|
+
</DialogPrimitive.Close>
|
|
67
|
+
)}
|
|
68
|
+
</DialogPrimitive.Content>
|
|
69
|
+
</DialogPortal>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function DialogHeader({
|
|
74
|
+
className,
|
|
75
|
+
...props
|
|
76
|
+
}: ComponentPropsWithoutRef<"div">) {
|
|
77
|
+
return <div className={cn("px-5 pt-5 pb-0 pr-12", className)} {...props} />;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function DialogTitle({
|
|
81
|
+
className,
|
|
82
|
+
...props
|
|
83
|
+
}: ComponentPropsWithoutRef<typeof DialogPrimitive.Title>) {
|
|
84
|
+
return (
|
|
85
|
+
<DialogPrimitive.Title
|
|
86
|
+
className={cn("font-semibold text-ink text-h3", className)}
|
|
87
|
+
{...props}
|
|
88
|
+
/>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function DialogDescription({
|
|
93
|
+
className,
|
|
94
|
+
...props
|
|
95
|
+
}: ComponentPropsWithoutRef<typeof DialogPrimitive.Description>) {
|
|
96
|
+
return (
|
|
97
|
+
<DialogPrimitive.Description
|
|
98
|
+
className={cn("mt-1.5 text-ink-secondary text-sm", className)}
|
|
99
|
+
{...props}
|
|
100
|
+
/>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function DialogBody({
|
|
105
|
+
className,
|
|
106
|
+
...props
|
|
107
|
+
}: ComponentPropsWithoutRef<"div">) {
|
|
108
|
+
return <div className={cn("px-5 py-4", className)} {...props} />;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function DialogFooter({
|
|
112
|
+
className,
|
|
113
|
+
...props
|
|
114
|
+
}: ComponentPropsWithoutRef<"div">) {
|
|
115
|
+
return (
|
|
116
|
+
<div
|
|
117
|
+
className={cn(
|
|
118
|
+
"flex justify-end items-center gap-2 px-5 py-3.5 border-hairline border-t",
|
|
119
|
+
className,
|
|
120
|
+
)}
|
|
121
|
+
{...props}
|
|
122
|
+
/>
|
|
123
|
+
);
|
|
124
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
|
4
|
+
import { Check, ChevronRight } from "lucide-react";
|
|
5
|
+
import type { ComponentPropsWithoutRef } from "react";
|
|
6
|
+
import { cn } from "../../lib/utils.ts";
|
|
7
|
+
|
|
8
|
+
/* The archetypal Notion surface: 6px padding, 4px-radius rows, 28px
|
|
9
|
+
tall, hover = tint. The shadow's 1px ambient ring is what keeps this
|
|
10
|
+
crisp when it opens over a white page. */
|
|
11
|
+
|
|
12
|
+
export const DropdownMenu = DropdownMenuPrimitive.Root;
|
|
13
|
+
export const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger;
|
|
14
|
+
export const DropdownMenuGroup = DropdownMenuPrimitive.Group;
|
|
15
|
+
export const DropdownMenuSub = DropdownMenuPrimitive.Sub;
|
|
16
|
+
export const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup;
|
|
17
|
+
|
|
18
|
+
const surfaceClasses = [
|
|
19
|
+
"z-50 min-w-[11rem] overflow-hidden p-1.5",
|
|
20
|
+
"bg-surface-overlay shadow-popover rounded-overlay",
|
|
21
|
+
"data-[state=open]:animate-slide-in data-[state=closed]:animate-fade-out",
|
|
22
|
+
"origin-[--radix-dropdown-menu-content-transform-origin]",
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
const itemClasses = [
|
|
26
|
+
"relative flex items-center gap-2 cursor-default select-none",
|
|
27
|
+
"h-7 px-2 rounded-control text-sm text-ink outline-none",
|
|
28
|
+
"transition-colors duration-75",
|
|
29
|
+
"data-[highlighted]:bg-tint-hover",
|
|
30
|
+
"data-[disabled]:pointer-events-none data-[disabled]:text-ink-disabled",
|
|
31
|
+
"[&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:text-ink-tertiary",
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
export function DropdownMenuContent({
|
|
35
|
+
className,
|
|
36
|
+
sideOffset = 6,
|
|
37
|
+
...props
|
|
38
|
+
}: ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content>) {
|
|
39
|
+
return (
|
|
40
|
+
<DropdownMenuPrimitive.Portal>
|
|
41
|
+
<DropdownMenuPrimitive.Content
|
|
42
|
+
sideOffset={sideOffset}
|
|
43
|
+
className={cn(surfaceClasses, className)}
|
|
44
|
+
{...props}
|
|
45
|
+
/>
|
|
46
|
+
</DropdownMenuPrimitive.Portal>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface DropdownMenuItemProps
|
|
51
|
+
extends ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> {
|
|
52
|
+
danger?: boolean;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function DropdownMenuItem({
|
|
56
|
+
className,
|
|
57
|
+
danger,
|
|
58
|
+
...props
|
|
59
|
+
}: DropdownMenuItemProps) {
|
|
60
|
+
return (
|
|
61
|
+
<DropdownMenuPrimitive.Item
|
|
62
|
+
className={cn(
|
|
63
|
+
itemClasses,
|
|
64
|
+
danger &&
|
|
65
|
+
"text-danger data-[highlighted]:bg-danger-tint [&_svg]:text-danger",
|
|
66
|
+
className,
|
|
67
|
+
)}
|
|
68
|
+
{...props}
|
|
69
|
+
/>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function DropdownMenuCheckboxItem({
|
|
74
|
+
className,
|
|
75
|
+
children,
|
|
76
|
+
...props
|
|
77
|
+
}: ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.CheckboxItem>) {
|
|
78
|
+
return (
|
|
79
|
+
<DropdownMenuPrimitive.CheckboxItem
|
|
80
|
+
className={cn(itemClasses, "pl-7", className)}
|
|
81
|
+
{...props}
|
|
82
|
+
>
|
|
83
|
+
<span className="left-2 absolute flex justify-center items-center size-4">
|
|
84
|
+
<DropdownMenuPrimitive.ItemIndicator>
|
|
85
|
+
<Check className="size-3.5 !text-ink" />
|
|
86
|
+
</DropdownMenuPrimitive.ItemIndicator>
|
|
87
|
+
</span>
|
|
88
|
+
{children}
|
|
89
|
+
</DropdownMenuPrimitive.CheckboxItem>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function DropdownMenuRadioItem({
|
|
94
|
+
className,
|
|
95
|
+
children,
|
|
96
|
+
...props
|
|
97
|
+
}: ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.RadioItem>) {
|
|
98
|
+
return (
|
|
99
|
+
<DropdownMenuPrimitive.RadioItem
|
|
100
|
+
className={cn(itemClasses, "pl-7", className)}
|
|
101
|
+
{...props}
|
|
102
|
+
>
|
|
103
|
+
<span className="left-2 absolute flex justify-center items-center size-4">
|
|
104
|
+
<DropdownMenuPrimitive.ItemIndicator>
|
|
105
|
+
<span className="bg-ink rounded-full size-1.5" />
|
|
106
|
+
</DropdownMenuPrimitive.ItemIndicator>
|
|
107
|
+
</span>
|
|
108
|
+
{children}
|
|
109
|
+
</DropdownMenuPrimitive.RadioItem>
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function DropdownMenuLabel({
|
|
114
|
+
className,
|
|
115
|
+
...props
|
|
116
|
+
}: ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Label>) {
|
|
117
|
+
return (
|
|
118
|
+
<DropdownMenuPrimitive.Label
|
|
119
|
+
className={cn(
|
|
120
|
+
"px-2 pt-1.5 pb-1 font-medium text-ink-tertiary text-caption",
|
|
121
|
+
className,
|
|
122
|
+
)}
|
|
123
|
+
{...props}
|
|
124
|
+
/>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function DropdownMenuSeparator({
|
|
129
|
+
className,
|
|
130
|
+
...props
|
|
131
|
+
}: ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Separator>) {
|
|
132
|
+
return (
|
|
133
|
+
<DropdownMenuPrimitive.Separator
|
|
134
|
+
className={cn("-mx-1.5 my-1.5 bg-hairline h-px", className)}
|
|
135
|
+
{...props}
|
|
136
|
+
/>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function DropdownMenuShortcut({
|
|
141
|
+
className,
|
|
142
|
+
...props
|
|
143
|
+
}: ComponentPropsWithoutRef<"span">) {
|
|
144
|
+
return (
|
|
145
|
+
<span
|
|
146
|
+
className={cn(
|
|
147
|
+
"ml-auto pl-4 text-ink-tertiary text-caption tracking-wide",
|
|
148
|
+
className,
|
|
149
|
+
)}
|
|
150
|
+
{...props}
|
|
151
|
+
/>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function DropdownMenuSubTrigger({
|
|
156
|
+
className,
|
|
157
|
+
children,
|
|
158
|
+
...props
|
|
159
|
+
}: ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubTrigger>) {
|
|
160
|
+
return (
|
|
161
|
+
<DropdownMenuPrimitive.SubTrigger
|
|
162
|
+
className={cn(itemClasses, "data-[state=open]:bg-tint-hover", className)}
|
|
163
|
+
{...props}
|
|
164
|
+
>
|
|
165
|
+
{children}
|
|
166
|
+
<ChevronRight className="ml-auto size-3.5" />
|
|
167
|
+
</DropdownMenuPrimitive.SubTrigger>
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function DropdownMenuSubContent({
|
|
172
|
+
className,
|
|
173
|
+
...props
|
|
174
|
+
}: ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubContent>) {
|
|
175
|
+
return (
|
|
176
|
+
<DropdownMenuPrimitive.Portal>
|
|
177
|
+
<DropdownMenuPrimitive.SubContent
|
|
178
|
+
className={cn(surfaceClasses, className)}
|
|
179
|
+
{...props}
|
|
180
|
+
/>
|
|
181
|
+
</DropdownMenuPrimitive.Portal>
|
|
182
|
+
);
|
|
183
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useMemo, type ClipboardEvent, type KeyboardEvent, type MouseEvent } from "react";
|
|
4
|
+
import { isWebUrl } from "../../lib/embed.ts";
|
|
5
|
+
import type { Text } from "../../lib/rich-text.ts";
|
|
6
|
+
import { readSpans, spansToHtml } from "../../lib/rich-text-dom.ts";
|
|
7
|
+
import { cn } from "../../lib/utils.ts";
|
|
8
|
+
|
|
9
|
+
/* Rich text edited in place: bold, italic, strike, code, links and page mentions
|
|
10
|
+
over the span model in lib/rich-text. The browser owns the DOM while the user
|
|
11
|
+
types: the markup is written once per `rev`, and every edit is read back into
|
|
12
|
+
spans. Bump `rev` only when you replace the text from outside (a split, a merge,
|
|
13
|
+
a command), which is when the DOM has to be rewritten.
|
|
14
|
+
|
|
15
|
+
⌘B and ⌘I are the browser's own; ⌘⇧S strikes through. Paste is plain text,
|
|
16
|
+
except a web address: pasted over a selection it links the selection, and
|
|
17
|
+
pasted on its own it arrives as a link. */
|
|
18
|
+
|
|
19
|
+
const escape = (s: string) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
20
|
+
export function EditableText({
|
|
21
|
+
id,
|
|
22
|
+
text,
|
|
23
|
+
rev = 0,
|
|
24
|
+
onChange,
|
|
25
|
+
onKeyDown,
|
|
26
|
+
onLink,
|
|
27
|
+
placeholder,
|
|
28
|
+
alwaysShowPlaceholder,
|
|
29
|
+
className,
|
|
30
|
+
}: {
|
|
31
|
+
// Put on the element as data-text, so it can be found to move focus to it.
|
|
32
|
+
id?: string;
|
|
33
|
+
text: Text;
|
|
34
|
+
rev?: number;
|
|
35
|
+
onChange: (text: Text, el: HTMLElement) => void;
|
|
36
|
+
onKeyDown?: (e: KeyboardEvent<HTMLDivElement>) => void;
|
|
37
|
+
// A click on a link or a page mention. Without it, links open in a new tab and
|
|
38
|
+
// mentions do nothing: wire mentions to your router here.
|
|
39
|
+
onLink?: (link: { href?: string; page?: string }) => void;
|
|
40
|
+
placeholder?: string;
|
|
41
|
+
alwaysShowPlaceholder?: boolean;
|
|
42
|
+
className?: string;
|
|
43
|
+
}) {
|
|
44
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- see the note above
|
|
45
|
+
const html = useMemo(() => spansToHtml(text), [rev]);
|
|
46
|
+
|
|
47
|
+
const onInput = (el: HTMLDivElement) => {
|
|
48
|
+
// An emptied element keeps a stray <br>, which would defeat :empty and read
|
|
49
|
+
// back as a newline.
|
|
50
|
+
if (el.textContent === "" && !el.querySelector("[data-page]")) el.innerHTML = "";
|
|
51
|
+
onChange(readSpans(el), el);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const onPaste = (e: ClipboardEvent<HTMLDivElement>) => {
|
|
55
|
+
e.preventDefault();
|
|
56
|
+
const pasted = e.clipboardData.getData("text/plain");
|
|
57
|
+
const url = pasted.trim();
|
|
58
|
+
if (/^\S+$/.test(url) && isWebUrl(url)) {
|
|
59
|
+
const selection = window.getSelection();
|
|
60
|
+
if (selection && !selection.isCollapsed) document.execCommand("createLink", false, url);
|
|
61
|
+
else document.execCommand("insertHTML", false, `<a href="${escape(url)}">${escape(url)}</a> `);
|
|
62
|
+
onInput(e.currentTarget);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
document.execCommand("insertText", false, pasted);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const onClick = (e: MouseEvent<HTMLDivElement>) => {
|
|
69
|
+
const link = (e.target as Element).closest("a");
|
|
70
|
+
if (!link) return;
|
|
71
|
+
e.preventDefault();
|
|
72
|
+
const target = link.dataset.page ? { page: link.dataset.page } : { href: link.getAttribute("href") ?? undefined };
|
|
73
|
+
if (onLink) onLink(target);
|
|
74
|
+
else if (target.href) window.open(target.href, "_blank", "noreferrer");
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<div
|
|
79
|
+
data-text={id}
|
|
80
|
+
role="textbox"
|
|
81
|
+
contentEditable
|
|
82
|
+
suppressContentEditableWarning
|
|
83
|
+
spellCheck
|
|
84
|
+
data-placeholder={placeholder}
|
|
85
|
+
className={cn(
|
|
86
|
+
// A link the browser inserts (a paste) is styled before the text is redrawn.
|
|
87
|
+
"min-w-0 break-words whitespace-pre-wrap outline-none [&_a]:underline [&_a]:decoration-accent/50 [&_a]:underline-offset-[3px] [&_b]:font-semibold",
|
|
88
|
+
"empty:before:pointer-events-none empty:before:text-ink-tertiary",
|
|
89
|
+
alwaysShowPlaceholder
|
|
90
|
+
? "empty:before:content-[attr(data-placeholder)]"
|
|
91
|
+
: "focus:empty:before:content-[attr(data-placeholder)]",
|
|
92
|
+
className,
|
|
93
|
+
)}
|
|
94
|
+
dangerouslySetInnerHTML={{ __html: html }}
|
|
95
|
+
onInput={(e) => onInput(e.currentTarget)}
|
|
96
|
+
onKeyDown={(e) => {
|
|
97
|
+
// The model has no underline.
|
|
98
|
+
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "u") e.preventDefault();
|
|
99
|
+
if ((e.metaKey || e.ctrlKey) && e.shiftKey && e.key.toLowerCase() === "s") {
|
|
100
|
+
e.preventDefault();
|
|
101
|
+
document.execCommand("strikeThrough");
|
|
102
|
+
}
|
|
103
|
+
onKeyDown?.(e);
|
|
104
|
+
}}
|
|
105
|
+
onPaste={onPaste}
|
|
106
|
+
onClick={onClick}
|
|
107
|
+
/>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { X, type LucideIcon } from "lucide-react";
|
|
4
|
+
import type { ComponentPropsWithRef, ReactNode } from "react";
|
|
5
|
+
import { fieldBase } from "./input.tsx";
|
|
6
|
+
import { cn } from "../../lib/utils.ts";
|
|
7
|
+
|
|
8
|
+
export interface FieldButtonProps extends Omit<ComponentPropsWithRef<"button">, "children"> {
|
|
9
|
+
icon?: LucideIcon;
|
|
10
|
+
/** What is chosen. Nothing, and the placeholder shows in its place. */
|
|
11
|
+
children?: ReactNode;
|
|
12
|
+
placeholder?: string;
|
|
13
|
+
/** Supplying this adds the cross that empties the field. */
|
|
14
|
+
onClear?: () => void;
|
|
15
|
+
clearLabel?: string;
|
|
16
|
+
invalid?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/* A field you press rather than type in: what a picker shows at rest. It is the
|
|
20
|
+
same sunken well as Input, so a row of both reads as one form. The cross sits
|
|
21
|
+
beside the button, not inside it, because a button cannot hold a button. */
|
|
22
|
+
export function FieldButton({
|
|
23
|
+
icon: Icon,
|
|
24
|
+
children,
|
|
25
|
+
placeholder,
|
|
26
|
+
onClear,
|
|
27
|
+
clearLabel = "Clear",
|
|
28
|
+
invalid,
|
|
29
|
+
className,
|
|
30
|
+
disabled,
|
|
31
|
+
...props
|
|
32
|
+
}: FieldButtonProps) {
|
|
33
|
+
const empty = children === undefined || children === null || children === "";
|
|
34
|
+
const clearable = onClear !== undefined && !empty && !disabled;
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<span className={cn("relative block w-full", className)}>
|
|
38
|
+
<button
|
|
39
|
+
type="button"
|
|
40
|
+
disabled={disabled}
|
|
41
|
+
aria-invalid={invalid || undefined}
|
|
42
|
+
{...props}
|
|
43
|
+
className={cn(
|
|
44
|
+
fieldBase,
|
|
45
|
+
"flex h-8 items-center gap-2 text-left text-sm cursor-pointer",
|
|
46
|
+
// Open, it looks the way a focused input does.
|
|
47
|
+
"data-[state=open]:bg-surface data-[state=open]:shadow-[inset_0_0_0_1px_var(--accent),0_0_0_3px_var(--accent-tint)]",
|
|
48
|
+
clearable && "pr-8",
|
|
49
|
+
)}
|
|
50
|
+
>
|
|
51
|
+
{Icon !== undefined && <Icon className="size-4 shrink-0 text-ink-tertiary" />}
|
|
52
|
+
<span className={cn("min-w-0 flex-1 truncate", empty && "text-ink-tertiary")}>
|
|
53
|
+
{empty ? placeholder : children}
|
|
54
|
+
</span>
|
|
55
|
+
</button>
|
|
56
|
+
{clearable && (
|
|
57
|
+
<button
|
|
58
|
+
type="button"
|
|
59
|
+
aria-label={clearLabel}
|
|
60
|
+
onClick={onClear}
|
|
61
|
+
className="absolute top-1/2 right-1 flex size-6 -translate-y-1/2 items-center justify-center rounded-control text-ink-tertiary transition-colors duration-100 hover:bg-tint-active hover:text-ink"
|
|
62
|
+
>
|
|
63
|
+
<X className="size-3.5" />
|
|
64
|
+
</button>
|
|
65
|
+
)}
|
|
66
|
+
</span>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { ImageOff } from "lucide-react";
|
|
4
|
+
import { useEffect, useRef, useState } from "react";
|
|
5
|
+
import { cn } from "../../lib/utils.ts";
|
|
6
|
+
|
|
7
|
+
/* A small picture of an image file that has not been uploaded: for showing
|
|
8
|
+
someone what they picked before anything is sent.
|
|
9
|
+
|
|
10
|
+
A camera's files are tens of megapixels; decoding a folder of them at full
|
|
11
|
+
size would stall the tab. So each is decoded straight to a few hundred
|
|
12
|
+
pixels, two at a time, and only once it is scrolled into view. A file is
|
|
13
|
+
decoded once however many times its preview is shown. */
|
|
14
|
+
|
|
15
|
+
const decoded = new WeakMap<File, Promise<ImageBitmap>>();
|
|
16
|
+
let running = 0;
|
|
17
|
+
const waiting: (() => void)[] = [];
|
|
18
|
+
|
|
19
|
+
function small(file: File): Promise<ImageBitmap> {
|
|
20
|
+
let promise = decoded.get(file);
|
|
21
|
+
if (promise === undefined) {
|
|
22
|
+
promise = (async () => {
|
|
23
|
+
if (running >= 2) await new Promise<void>((resolve) => waiting.push(resolve));
|
|
24
|
+
running += 1;
|
|
25
|
+
try {
|
|
26
|
+
return await createImageBitmap(file, { resizeWidth: 360, resizeQuality: "low" });
|
|
27
|
+
} finally {
|
|
28
|
+
running -= 1;
|
|
29
|
+
waiting.shift()?.();
|
|
30
|
+
}
|
|
31
|
+
})();
|
|
32
|
+
decoded.set(file, promise);
|
|
33
|
+
}
|
|
34
|
+
return promise;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function FilePreview({ file, className }: { file: File | undefined; className?: string }) {
|
|
38
|
+
const canvas = useRef<HTMLCanvasElement>(null);
|
|
39
|
+
const [state, setState] = useState<"waiting" | "shown" | "unreadable">("waiting");
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
const el = canvas.current;
|
|
43
|
+
if (el === null || file === undefined) return;
|
|
44
|
+
let cancelled = false;
|
|
45
|
+
const observer = new IntersectionObserver(
|
|
46
|
+
(entries) => {
|
|
47
|
+
if (!entries.some((entry) => entry.isIntersecting)) return;
|
|
48
|
+
observer.disconnect();
|
|
49
|
+
small(file).then(
|
|
50
|
+
(bitmap) => {
|
|
51
|
+
if (cancelled) return;
|
|
52
|
+
el.width = bitmap.width;
|
|
53
|
+
el.height = bitmap.height;
|
|
54
|
+
el.getContext("2d")?.drawImage(bitmap, 0, 0);
|
|
55
|
+
setState("shown");
|
|
56
|
+
},
|
|
57
|
+
// Not an image the browser can read: another type renamed, a damaged file.
|
|
58
|
+
() => !cancelled && setState("unreadable"),
|
|
59
|
+
);
|
|
60
|
+
},
|
|
61
|
+
{ rootMargin: "200px" },
|
|
62
|
+
);
|
|
63
|
+
observer.observe(el);
|
|
64
|
+
return () => {
|
|
65
|
+
cancelled = true;
|
|
66
|
+
observer.disconnect();
|
|
67
|
+
};
|
|
68
|
+
}, [file]);
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<span className={cn("relative block overflow-hidden bg-surface-sunken", className)}>
|
|
72
|
+
<canvas ref={canvas} className={cn("h-full w-full object-cover transition-opacity duration-200", state === "shown" ? "opacity-100" : "opacity-0")} />
|
|
73
|
+
{(state === "unreadable" || file === undefined) && (
|
|
74
|
+
<span className="absolute inset-0 flex items-center justify-center text-ink-disabled">
|
|
75
|
+
<ImageOff className="size-5" />
|
|
76
|
+
</span>
|
|
77
|
+
)}
|
|
78
|
+
</span>
|
|
79
|
+
);
|
|
80
|
+
}
|