@kujoforall/paper-ui 0.1.0 → 0.2.1
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 +94 -0
- package/README.md +50 -7
- package/dist/components/editor/block-text.d.ts.map +1 -1
- package/dist/components/editor/block-text.js +52 -17
- package/dist/components/editor/block-text.js.map +1 -1
- package/dist/components/editor/blocks.d.ts.map +1 -1
- package/dist/components/editor/blocks.js +17 -13
- package/dist/components/editor/blocks.js.map +1 -1
- package/dist/components/editor/document-editor.d.ts.map +1 -1
- package/dist/components/editor/document-editor.js +4 -2
- package/dist/components/editor/document-editor.js.map +1 -1
- package/dist/components/editor/document-view.d.ts.map +1 -1
- package/dist/components/editor/document-view.js +17 -12
- package/dist/components/editor/document-view.js.map +1 -1
- package/dist/components/editor/editor-state.d.ts +7 -0
- package/dist/components/editor/editor-state.d.ts.map +1 -1
- package/dist/components/editor/editor-state.js +28 -3
- package/dist/components/editor/editor-state.js.map +1 -1
- package/dist/components/editor/extensions/kit-blocks.d.ts +34 -0
- package/dist/components/editor/extensions/kit-blocks.d.ts.map +1 -0
- package/dist/components/editor/extensions/kit-blocks.js +201 -0
- package/dist/components/editor/extensions/kit-blocks.js.map +1 -0
- package/dist/components/editor/extensions/spoiler.d.ts.map +1 -1
- package/dist/components/editor/extensions/spoiler.js +2 -2
- package/dist/components/editor/extensions/spoiler.js.map +1 -1
- package/dist/components/editor/index.d.ts +1 -0
- package/dist/components/editor/index.d.ts.map +1 -1
- package/dist/components/editor/index.js +1 -0
- package/dist/components/editor/index.js.map +1 -1
- package/dist/components/editor/kinds.js +1 -1
- package/dist/components/editor/kinds.js.map +1 -1
- package/dist/components/editor/look.d.ts +18 -0
- package/dist/components/editor/look.d.ts.map +1 -0
- package/dist/components/editor/look.js +21 -0
- package/dist/components/editor/look.js.map +1 -0
- package/dist/components/three/model-viewer.d.ts +36 -0
- package/dist/components/three/model-viewer.d.ts.map +1 -0
- package/dist/components/three/model-viewer.js +338 -0
- package/dist/components/three/model-viewer.js.map +1 -0
- package/dist/components/ui/accent-picker.js +1 -1
- package/dist/components/ui/accent-picker.js.map +1 -1
- package/dist/components/ui/alert-dialog.d.ts +29 -0
- package/dist/components/ui/alert-dialog.d.ts.map +1 -0
- package/dist/components/ui/alert-dialog.js +72 -0
- package/dist/components/ui/alert-dialog.js.map +1 -0
- package/dist/components/ui/animated-height.d.ts +6 -0
- package/dist/components/ui/animated-height.d.ts.map +1 -0
- package/dist/components/ui/animated-height.js +26 -0
- package/dist/components/ui/animated-height.js.map +1 -0
- package/dist/components/ui/app-shell.d.ts +1 -0
- package/dist/components/ui/app-shell.d.ts.map +1 -1
- package/dist/components/ui/app-shell.js +5 -3
- package/dist/components/ui/app-shell.js.map +1 -1
- package/dist/components/ui/avatar.d.ts +30 -0
- package/dist/components/ui/avatar.d.ts.map +1 -0
- package/dist/components/ui/avatar.js +50 -0
- package/dist/components/ui/avatar.js.map +1 -0
- package/dist/components/ui/badge.d.ts +3 -3
- package/dist/components/ui/badge.d.ts.map +1 -1
- package/dist/components/ui/badge.js +2 -2
- package/dist/components/ui/badge.js.map +1 -1
- package/dist/components/ui/banner.d.ts +33 -0
- package/dist/components/ui/banner.d.ts.map +1 -0
- package/dist/components/ui/banner.js +21 -0
- package/dist/components/ui/banner.js.map +1 -0
- package/dist/components/ui/breadcrumbs.js +1 -1
- package/dist/components/ui/breadcrumbs.js.map +1 -1
- package/dist/components/ui/button.d.ts +8 -6
- package/dist/components/ui/button.d.ts.map +1 -1
- package/dist/components/ui/button.js +91 -26
- package/dist/components/ui/button.js.map +1 -1
- package/dist/components/ui/calendar.d.ts.map +1 -1
- package/dist/components/ui/calendar.js +6 -5
- package/dist/components/ui/calendar.js.map +1 -1
- package/dist/components/ui/callout.d.ts +23 -4
- package/dist/components/ui/callout.d.ts.map +1 -1
- package/dist/components/ui/callout.js +28 -15
- package/dist/components/ui/callout.js.map +1 -1
- package/dist/components/ui/card.d.ts +13 -8
- package/dist/components/ui/card.d.ts.map +1 -1
- package/dist/components/ui/card.js +10 -9
- package/dist/components/ui/card.js.map +1 -1
- package/dist/components/ui/checkbox.d.ts +9 -4
- package/dist/components/ui/checkbox.d.ts.map +1 -1
- package/dist/components/ui/checkbox.js +25 -5
- package/dist/components/ui/checkbox.js.map +1 -1
- package/dist/components/ui/choice-label.d.ts +13 -0
- package/dist/components/ui/choice-label.d.ts.map +1 -0
- package/dist/components/ui/choice-label.js +17 -0
- package/dist/components/ui/choice-label.js.map +1 -0
- package/dist/components/ui/collapsible.d.ts +10 -0
- package/dist/components/ui/collapsible.d.ts.map +1 -0
- package/dist/components/ui/collapsible.js +21 -0
- package/dist/components/ui/collapsible.js.map +1 -0
- package/dist/components/ui/collection-layout.d.ts +24 -0
- package/dist/components/ui/collection-layout.d.ts.map +1 -0
- package/dist/components/ui/collection-layout.js +16 -0
- package/dist/components/ui/collection-layout.js.map +1 -0
- package/dist/components/ui/combobox.d.ts +10 -0
- package/dist/components/ui/combobox.d.ts.map +1 -0
- package/dist/components/ui/combobox.js +93 -0
- package/dist/components/ui/combobox.js.map +1 -0
- package/dist/components/ui/command-menu.d.ts +5 -2
- package/dist/components/ui/command-menu.d.ts.map +1 -1
- package/dist/components/ui/command-menu.js +31 -6
- package/dist/components/ui/command-menu.js.map +1 -1
- package/dist/components/ui/context-menu.d.ts +19 -0
- package/dist/components/ui/context-menu.d.ts.map +1 -0
- package/dist/components/ui/context-menu.js +42 -0
- package/dist/components/ui/context-menu.js.map +1 -0
- package/dist/components/ui/copy-button.d.ts +11 -0
- package/dist/components/ui/copy-button.d.ts.map +1 -0
- package/dist/components/ui/copy-button.js +48 -0
- package/dist/components/ui/copy-button.js.map +1 -0
- package/dist/components/ui/database/calendar-view.d.ts +10 -0
- package/dist/components/ui/database/calendar-view.d.ts.map +1 -0
- package/dist/components/ui/database/calendar-view.js +65 -0
- package/dist/components/ui/database/calendar-view.js.map +1 -0
- package/dist/components/ui/database/card-views.d.ts +22 -0
- package/dist/components/ui/database/card-views.d.ts.map +1 -0
- package/dist/components/ui/database/card-views.js +74 -0
- package/dist/components/ui/database/card-views.js.map +1 -0
- package/dist/components/ui/database/cells.d.ts +20 -0
- package/dist/components/ui/database/cells.d.ts.map +1 -0
- package/dist/components/ui/database/cells.js +132 -0
- package/dist/components/ui/database/cells.js.map +1 -0
- package/dist/components/ui/database/database.d.ts +19 -0
- package/dist/components/ui/database/database.d.ts.map +1 -0
- package/dist/components/ui/database/database.js +102 -0
- package/dist/components/ui/database/database.js.map +1 -0
- package/dist/components/ui/database/icons.d.ts +5 -0
- package/dist/components/ui/database/icons.d.ts.map +1 -0
- package/dist/components/ui/database/icons.js +13 -0
- package/dist/components/ui/database/icons.js.map +1 -0
- package/dist/components/ui/database/table-view.d.ts +11 -0
- package/dist/components/ui/database/table-view.d.ts.map +1 -0
- package/dist/components/ui/database/table-view.js +157 -0
- package/dist/components/ui/database/table-view.js.map +1 -0
- package/dist/components/ui/date-picker.d.ts +6 -1
- package/dist/components/ui/date-picker.d.ts.map +1 -1
- package/dist/components/ui/date-picker.js +20 -12
- package/dist/components/ui/date-picker.js.map +1 -1
- package/dist/components/ui/date-time-picker.d.ts +3 -1
- package/dist/components/ui/date-time-picker.d.ts.map +1 -1
- package/dist/components/ui/date-time-picker.js +17 -15
- package/dist/components/ui/date-time-picker.js.map +1 -1
- package/dist/components/ui/dialog.d.ts +13 -9
- package/dist/components/ui/dialog.d.ts.map +1 -1
- package/dist/components/ui/dialog.js +33 -3
- package/dist/components/ui/dialog.js.map +1 -1
- package/dist/components/ui/document-layout.d.ts +15 -0
- package/dist/components/ui/document-layout.d.ts.map +1 -0
- package/dist/components/ui/document-layout.js +15 -0
- package/dist/components/ui/document-layout.js.map +1 -0
- package/dist/components/ui/dropdown-menu.d.ts +14 -10
- package/dist/components/ui/dropdown-menu.d.ts.map +1 -1
- package/dist/components/ui/dropdown-menu.js +22 -13
- package/dist/components/ui/dropdown-menu.js.map +1 -1
- package/dist/components/ui/editable-text.d.ts +9 -2
- package/dist/components/ui/editable-text.d.ts.map +1 -1
- package/dist/components/ui/editable-text.js +27 -10
- package/dist/components/ui/editable-text.js.map +1 -1
- package/dist/components/ui/empty-state.d.ts +11 -0
- package/dist/components/ui/empty-state.d.ts.map +1 -0
- package/dist/components/ui/empty-state.js +9 -0
- package/dist/components/ui/empty-state.js.map +1 -0
- package/dist/components/ui/error-state.d.ts +20 -0
- package/dist/components/ui/error-state.d.ts.map +1 -0
- package/dist/components/ui/error-state.js +17 -0
- package/dist/components/ui/error-state.js.map +1 -0
- package/dist/components/ui/field-button.d.ts +2 -1
- package/dist/components/ui/field-button.d.ts.map +1 -1
- package/dist/components/ui/field-button.js +7 -5
- package/dist/components/ui/field-button.js.map +1 -1
- package/dist/components/ui/file-preview.js +1 -1
- package/dist/components/ui/file-preview.js.map +1 -1
- package/dist/components/ui/file-uploader.d.ts.map +1 -1
- package/dist/components/ui/file-uploader.js +5 -4
- package/dist/components/ui/file-uploader.js.map +1 -1
- package/dist/components/ui/filter-builder.d.ts +18 -0
- package/dist/components/ui/filter-builder.d.ts.map +1 -0
- package/dist/components/ui/filter-builder.js +98 -0
- package/dist/components/ui/filter-builder.js.map +1 -0
- package/dist/components/ui/focus-shell.d.ts +14 -0
- package/dist/components/ui/focus-shell.d.ts.map +1 -0
- package/dist/components/ui/focus-shell.js +13 -0
- package/dist/components/ui/focus-shell.js.map +1 -0
- package/dist/components/ui/handle-row.d.ts +11 -1
- package/dist/components/ui/handle-row.d.ts.map +1 -1
- package/dist/components/ui/handle-row.js +101 -32
- package/dist/components/ui/handle-row.js.map +1 -1
- package/dist/components/ui/header-bar.d.ts +5 -0
- package/dist/components/ui/header-bar.d.ts.map +1 -0
- package/dist/components/ui/header-bar.js +10 -0
- package/dist/components/ui/header-bar.js.map +1 -0
- package/dist/components/ui/hover-card.d.ts +6 -0
- package/dist/components/ui/hover-card.d.ts.map +1 -0
- package/dist/components/ui/hover-card.js +13 -0
- package/dist/components/ui/hover-card.js.map +1 -0
- package/dist/components/ui/image-block.js +4 -4
- package/dist/components/ui/image-block.js.map +1 -1
- package/dist/components/ui/image-card.d.ts.map +1 -1
- package/dist/components/ui/image-card.js +5 -4
- package/dist/components/ui/image-card.js.map +1 -1
- package/dist/components/ui/image-framer.d.ts +24 -0
- package/dist/components/ui/image-framer.d.ts.map +1 -0
- package/dist/components/ui/image-framer.js +89 -0
- package/dist/components/ui/image-framer.js.map +1 -0
- package/dist/components/ui/image-viewer.d.ts.map +1 -1
- package/dist/components/ui/image-viewer.js +38 -5
- package/dist/components/ui/image-viewer.js.map +1 -1
- package/dist/components/ui/image.d.ts +25 -3
- package/dist/components/ui/image.d.ts.map +1 -1
- package/dist/components/ui/image.js +50 -21
- package/dist/components/ui/image.js.map +1 -1
- package/dist/components/ui/index.d.ts +54 -11
- package/dist/components/ui/index.d.ts.map +1 -1
- package/dist/components/ui/index.js +53 -10
- package/dist/components/ui/index.js.map +1 -1
- package/dist/components/ui/input.d.ts +71 -12
- package/dist/components/ui/input.d.ts.map +1 -1
- package/dist/components/ui/input.js +236 -23
- package/dist/components/ui/input.js.map +1 -1
- package/dist/components/ui/link-block.d.ts.map +1 -1
- package/dist/components/ui/link-block.js +1 -1
- package/dist/components/ui/link-block.js.map +1 -1
- package/dist/components/ui/list-detail.d.ts +23 -0
- package/dist/components/ui/list-detail.d.ts.map +1 -0
- package/dist/components/ui/list-detail.js +33 -0
- package/dist/components/ui/list-detail.js.map +1 -0
- package/dist/components/ui/listbox.d.ts +7 -0
- package/dist/components/ui/listbox.d.ts.map +1 -0
- package/dist/components/ui/listbox.js +29 -0
- package/dist/components/ui/listbox.js.map +1 -0
- package/dist/components/ui/mac-card.js +1 -1
- package/dist/components/ui/mac-card.js.map +1 -1
- package/dist/components/ui/month-picker.d.ts +13 -0
- package/dist/components/ui/month-picker.d.ts.map +1 -0
- package/dist/components/ui/month-picker.js +53 -0
- package/dist/components/ui/month-picker.js.map +1 -0
- package/dist/components/ui/multi-select.d.ts +22 -0
- package/dist/components/ui/multi-select.d.ts.map +1 -0
- package/dist/components/ui/multi-select.js +88 -0
- package/dist/components/ui/multi-select.js.map +1 -0
- package/dist/components/ui/nav-tree.d.ts.map +1 -1
- package/dist/components/ui/nav-tree.js +10 -3
- package/dist/components/ui/nav-tree.js.map +1 -1
- package/dist/components/ui/page.d.ts +16 -5
- package/dist/components/ui/page.d.ts.map +1 -1
- package/dist/components/ui/page.js +23 -10
- package/dist/components/ui/page.js.map +1 -1
- package/dist/components/ui/pagination.d.ts +26 -0
- package/dist/components/ui/pagination.d.ts.map +1 -0
- package/dist/components/ui/pagination.js +54 -0
- package/dist/components/ui/pagination.js.map +1 -0
- package/dist/components/ui/picker-panel.d.ts +13 -0
- package/dist/components/ui/picker-panel.d.ts.map +1 -0
- package/dist/components/ui/picker-panel.js +19 -0
- package/dist/components/ui/picker-panel.js.map +1 -0
- package/dist/components/ui/popover.d.ts +2 -2
- package/dist/components/ui/popover.d.ts.map +1 -1
- package/dist/components/ui/popover.js +1 -1
- package/dist/components/ui/popover.js.map +1 -1
- package/dist/components/ui/progress.d.ts +11 -1
- package/dist/components/ui/progress.d.ts.map +1 -1
- package/dist/components/ui/progress.js +17 -4
- package/dist/components/ui/progress.js.map +1 -1
- package/dist/components/ui/property.d.ts +2 -6
- package/dist/components/ui/property.d.ts.map +1 -1
- package/dist/components/ui/property.js +6 -22
- package/dist/components/ui/property.js.map +1 -1
- package/dist/components/ui/radio-group.d.ts +8 -0
- package/dist/components/ui/radio-group.d.ts.map +1 -0
- package/dist/components/ui/radio-group.js +18 -0
- package/dist/components/ui/radio-group.js.map +1 -0
- package/dist/components/ui/rating.d.ts +14 -0
- package/dist/components/ui/rating.d.ts.map +1 -0
- package/dist/components/ui/rating.js +61 -0
- package/dist/components/ui/rating.js.map +1 -0
- package/dist/components/ui/save-status.d.ts +8 -0
- package/dist/components/ui/save-status.d.ts.map +1 -0
- package/dist/components/ui/save-status.js +31 -0
- package/dist/components/ui/save-status.js.map +1 -0
- package/dist/components/ui/segmented.d.ts +15 -7
- package/dist/components/ui/segmented.d.ts.map +1 -1
- package/dist/components/ui/segmented.js +8 -6
- package/dist/components/ui/segmented.js.map +1 -1
- package/dist/components/ui/select-menu.d.ts +3 -1
- package/dist/components/ui/select-menu.d.ts.map +1 -1
- package/dist/components/ui/select-menu.js +2 -2
- package/dist/components/ui/select-menu.js.map +1 -1
- package/dist/components/ui/select.d.ts +7 -2
- package/dist/components/ui/select.d.ts.map +1 -1
- package/dist/components/ui/select.js +19 -5
- package/dist/components/ui/select.js.map +1 -1
- package/dist/components/ui/selection-bar.js +1 -1
- package/dist/components/ui/selection-bar.js.map +1 -1
- package/dist/components/ui/settings-layout.d.ts +34 -0
- package/dist/components/ui/settings-layout.d.ts.map +1 -0
- package/dist/components/ui/settings-layout.js +16 -0
- package/dist/components/ui/settings-layout.js.map +1 -0
- package/dist/components/ui/share-link.d.ts +14 -0
- package/dist/components/ui/share-link.d.ts.map +1 -0
- package/dist/components/ui/share-link.js +16 -0
- package/dist/components/ui/share-link.js.map +1 -0
- package/dist/components/ui/sheet.d.ts +21 -0
- package/dist/components/ui/sheet.d.ts.map +1 -0
- package/dist/components/ui/sheet.js +53 -0
- package/dist/components/ui/sheet.js.map +1 -0
- package/dist/components/ui/sidebar.d.ts +82 -0
- package/dist/components/ui/sidebar.d.ts.map +1 -0
- package/dist/components/ui/sidebar.js +258 -0
- package/dist/components/ui/sidebar.js.map +1 -0
- package/dist/components/ui/skeleton.d.ts +8 -0
- package/dist/components/ui/skeleton.d.ts.map +1 -0
- package/dist/components/ui/skeleton.js +15 -0
- package/dist/components/ui/skeleton.js.map +1 -0
- package/dist/components/ui/spinner.d.ts +12 -0
- package/dist/components/ui/spinner.d.ts.map +1 -0
- package/dist/components/ui/spinner.js +14 -0
- package/dist/components/ui/spinner.js.map +1 -0
- package/dist/components/ui/spotlight.d.ts.map +1 -1
- package/dist/components/ui/spotlight.js +14 -11
- package/dist/components/ui/spotlight.js.map +1 -1
- package/dist/components/ui/step-dialog.js +3 -3
- package/dist/components/ui/step-dialog.js.map +1 -1
- package/dist/components/ui/steps-layout.d.ts +20 -0
- package/dist/components/ui/steps-layout.d.ts.map +1 -0
- package/dist/components/ui/steps-layout.js +26 -0
- package/dist/components/ui/steps-layout.js.map +1 -0
- package/dist/components/ui/switch.d.ts +8 -0
- package/dist/components/ui/switch.d.ts.map +1 -0
- package/dist/components/ui/switch.js +21 -0
- package/dist/components/ui/switch.js.map +1 -0
- package/dist/components/ui/table.d.ts +13 -5
- package/dist/components/ui/table.d.ts.map +1 -1
- package/dist/components/ui/table.js +65 -12
- package/dist/components/ui/table.js.map +1 -1
- package/dist/components/ui/tabs.d.ts +7 -0
- package/dist/components/ui/tabs.d.ts.map +1 -0
- package/dist/components/ui/tabs.js +19 -0
- package/dist/components/ui/tabs.js.map +1 -0
- package/dist/components/ui/theme-toggle.d.ts +14 -0
- package/dist/components/ui/theme-toggle.d.ts.map +1 -1
- package/dist/components/ui/theme-toggle.js +69 -41
- package/dist/components/ui/theme-toggle.js.map +1 -1
- package/dist/components/ui/time-list.d.ts +16 -0
- package/dist/components/ui/time-list.d.ts.map +1 -0
- package/dist/components/ui/time-list.js +49 -0
- package/dist/components/ui/time-list.js.map +1 -0
- package/dist/components/ui/time-picker.d.ts +37 -11
- package/dist/components/ui/time-picker.d.ts.map +1 -1
- package/dist/components/ui/time-picker.js +130 -52
- package/dist/components/ui/time-picker.js.map +1 -1
- package/dist/components/ui/toast.d.ts +18 -0
- package/dist/components/ui/toast.d.ts.map +1 -0
- package/dist/components/ui/toast.js +77 -0
- package/dist/components/ui/toast.js.map +1 -0
- package/dist/components/ui/toggle.d.ts +15 -0
- package/dist/components/ui/toggle.d.ts.map +1 -0
- package/dist/components/ui/toggle.js +55 -0
- package/dist/components/ui/toggle.js.map +1 -0
- package/dist/components/ui/tooltip.d.ts +1 -1
- package/dist/components/ui/tooltip.d.ts.map +1 -1
- package/dist/components/ui/tooltip.js +13 -2
- package/dist/components/ui/tooltip.js.map +1 -1
- package/dist/components/ui/top-bar.d.ts +25 -0
- package/dist/components/ui/top-bar.d.ts.map +1 -0
- package/dist/components/ui/top-bar.js +23 -0
- package/dist/components/ui/top-bar.js.map +1 -0
- package/dist/components/ui/typography.d.ts +11 -5
- package/dist/components/ui/typography.d.ts.map +1 -1
- package/dist/components/ui/typography.js +31 -5
- package/dist/components/ui/typography.js.map +1 -1
- package/dist/components/ui/video-block.d.ts.map +1 -1
- package/dist/components/ui/video-block.js +5 -1
- package/dist/components/ui/video-block.js.map +1 -1
- package/dist/hooks/use-dismiss.d.ts +5 -0
- package/dist/hooks/use-dismiss.d.ts.map +1 -0
- package/dist/hooks/use-dismiss.js +23 -0
- package/dist/hooks/use-dismiss.js.map +1 -0
- package/dist/hooks/use-escape-first.d.ts +3 -0
- package/dist/hooks/use-escape-first.d.ts.map +1 -0
- package/dist/hooks/use-escape-first.js +27 -0
- package/dist/hooks/use-escape-first.js.map +1 -0
- package/dist/hooks/use-media-query.d.ts +5 -0
- package/dist/hooks/use-media-query.d.ts.map +1 -0
- package/dist/hooks/use-media-query.js +16 -0
- package/dist/hooks/use-media-query.js.map +1 -0
- package/dist/hooks/use-save-queue.d.ts.map +1 -1
- package/dist/hooks/use-save-queue.js +19 -7
- package/dist/hooks/use-save-queue.js.map +1 -1
- package/dist/hooks/use-selection.d.ts.map +1 -1
- package/dist/hooks/use-selection.js +10 -1
- package/dist/hooks/use-selection.js.map +1 -1
- package/dist/lib/database.d.ts +92 -0
- package/dist/lib/database.d.ts.map +1 -0
- package/dist/lib/database.js +272 -0
- package/dist/lib/database.js.map +1 -0
- package/dist/lib/dates.d.ts +16 -0
- package/dist/lib/dates.d.ts.map +1 -1
- package/dist/lib/dates.js +27 -0
- package/dist/lib/dates.js.map +1 -1
- package/dist/lib/keys.d.ts +18 -0
- package/dist/lib/keys.d.ts.map +1 -0
- package/dist/lib/keys.js +66 -0
- package/dist/lib/keys.js.map +1 -0
- package/dist/lib/number.d.ts +4 -0
- package/dist/lib/number.d.ts.map +1 -0
- package/dist/lib/number.js +33 -0
- package/dist/lib/number.js.map +1 -0
- package/dist/lib/pointer.d.ts +2 -0
- package/dist/lib/pointer.d.ts.map +1 -0
- package/dist/lib/pointer.js +4 -0
- package/dist/lib/pointer.js.map +1 -0
- package/dist/lib/prepare-image.d.ts +43 -0
- package/dist/lib/prepare-image.d.ts.map +1 -0
- package/dist/lib/prepare-image.js +105 -0
- package/dist/lib/prepare-image.js.map +1 -0
- package/dist/lib/rich-text-dom.d.ts +2 -0
- package/dist/lib/rich-text-dom.d.ts.map +1 -1
- package/dist/lib/rich-text-dom.js +5 -3
- package/dist/lib/rich-text-dom.js.map +1 -1
- package/dist/lib/theme.d.ts +6 -0
- package/dist/lib/theme.d.ts.map +1 -0
- package/dist/lib/theme.js +15 -0
- package/dist/lib/theme.js.map +1 -0
- package/dist/lib/time.d.ts +19 -0
- package/dist/lib/time.d.ts.map +1 -0
- package/dist/lib/time.js +91 -0
- package/dist/lib/time.js.map +1 -0
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +20 -2
- package/dist/lib/utils.js.map +1 -1
- package/dist/styles/notion.css +342 -51
- package/package.json +27 -4
- package/src/components/editor/block-text.tsx +58 -17
- package/src/components/editor/blocks.tsx +19 -14
- package/src/components/editor/document-editor.tsx +7 -2
- package/src/components/editor/document-view.tsx +37 -24
- package/src/components/editor/editor-state.tsx +31 -3
- package/src/components/editor/extensions/kit-blocks.tsx +452 -0
- package/src/components/editor/extensions/spoiler.tsx +9 -4
- package/src/components/editor/index.ts +1 -0
- package/src/components/editor/kinds.ts +1 -1
- package/src/components/editor/look.tsx +36 -0
- package/src/components/three/model-viewer.tsx +514 -0
- package/src/components/ui/accent-picker.tsx +2 -2
- package/src/components/ui/alert-dialog.tsx +136 -0
- package/src/components/ui/animated-height.tsx +34 -0
- package/src/components/ui/app-shell.tsx +9 -7
- package/src/components/ui/avatar.tsx +106 -0
- package/src/components/ui/badge.tsx +4 -4
- package/src/components/ui/banner.tsx +53 -0
- package/src/components/ui/breadcrumbs.tsx +1 -1
- package/src/components/ui/button.tsx +115 -41
- package/src/components/ui/calendar.tsx +8 -7
- package/src/components/ui/callout.tsx +41 -42
- package/src/components/ui/card.tsx +27 -58
- package/src/components/ui/checkbox.tsx +53 -19
- package/src/components/ui/choice-label.tsx +43 -0
- package/src/components/ui/collapsible.tsx +58 -0
- package/src/components/ui/collection-layout.tsx +69 -0
- package/src/components/ui/combobox.tsx +155 -0
- package/src/components/ui/command-menu.tsx +61 -31
- package/src/components/ui/context-menu.tsx +89 -0
- package/src/components/ui/copy-button.tsx +80 -0
- package/src/components/ui/database/calendar-view.tsx +180 -0
- package/src/components/ui/database/card-views.tsx +221 -0
- package/src/components/ui/database/cells.tsx +237 -0
- package/src/components/ui/database/database.tsx +279 -0
- package/src/components/ui/database/icons.ts +15 -0
- package/src/components/ui/database/table-view.tsx +311 -0
- package/src/components/ui/date-picker.tsx +99 -61
- package/src/components/ui/date-time-picker.tsx +68 -62
- package/src/components/ui/dialog.tsx +48 -21
- package/src/components/ui/document-layout.tsx +52 -0
- package/src/components/ui/dropdown-menu.tsx +33 -31
- package/src/components/ui/editable-text.tsx +40 -7
- package/src/components/ui/empty-state.tsx +35 -0
- package/src/components/ui/error-state.tsx +67 -0
- package/src/components/ui/field-button.tsx +11 -9
- package/src/components/ui/file-preview.tsx +1 -1
- package/src/components/ui/file-uploader.tsx +23 -24
- package/src/components/ui/filter-builder.tsx +304 -0
- package/src/components/ui/focus-shell.tsx +48 -0
- package/src/components/ui/handle-row.tsx +176 -40
- package/src/components/ui/header-bar.tsx +15 -0
- package/src/components/ui/hover-card.tsx +30 -0
- package/src/components/ui/image-block.tsx +6 -6
- package/src/components/ui/image-card.tsx +18 -25
- package/src/components/ui/image-framer.tsx +160 -0
- package/src/components/ui/image-viewer.tsx +53 -10
- package/src/components/ui/image.tsx +133 -29
- package/src/components/ui/index.ts +106 -11
- package/src/components/ui/input.tsx +437 -65
- package/src/components/ui/link-block.tsx +5 -2
- package/src/components/ui/list-detail.tsx +115 -0
- package/src/components/ui/listbox.ts +26 -0
- package/src/components/ui/mac-card.tsx +5 -5
- package/src/components/ui/month-picker.tsx +119 -0
- package/src/components/ui/multi-select.tsx +221 -0
- package/src/components/ui/nav-tree.tsx +11 -5
- package/src/components/ui/page.tsx +63 -15
- package/src/components/ui/pagination.tsx +143 -0
- package/src/components/ui/picker-panel.tsx +69 -0
- package/src/components/ui/popover.tsx +3 -3
- package/src/components/ui/progress.tsx +56 -16
- package/src/components/ui/property.tsx +6 -37
- package/src/components/ui/radio-group.tsx +61 -0
- package/src/components/ui/rating.tsx +122 -0
- package/src/components/ui/save-status.tsx +53 -0
- package/src/components/ui/segmented.tsx +48 -16
- package/src/components/ui/select-menu.tsx +11 -3
- package/src/components/ui/select.tsx +33 -10
- package/src/components/ui/selection-bar.tsx +1 -1
- package/src/components/ui/settings-layout.tsx +117 -0
- package/src/components/ui/share-link.tsx +66 -0
- package/src/components/ui/sheet.tsx +90 -0
- package/src/components/ui/sidebar.tsx +627 -0
- package/src/components/ui/skeleton.tsx +22 -0
- package/src/components/ui/spinner.tsx +28 -0
- package/src/components/ui/spotlight.tsx +21 -21
- package/src/components/ui/step-dialog.tsx +6 -6
- package/src/components/ui/steps-layout.tsx +91 -0
- package/src/components/ui/switch.tsx +55 -0
- package/src/components/ui/table.tsx +75 -18
- package/src/components/ui/tabs.tsx +41 -0
- package/src/components/ui/theme-toggle.tsx +74 -83
- package/src/components/ui/time-list.tsx +106 -0
- package/src/components/ui/time-picker.tsx +305 -134
- package/src/components/ui/toast.tsx +132 -0
- package/src/components/ui/toggle.tsx +76 -0
- package/src/components/ui/tooltip.tsx +20 -6
- package/src/components/ui/top-bar.tsx +118 -0
- package/src/components/ui/typography.tsx +45 -9
- package/src/components/ui/video-block.tsx +9 -3
- package/src/hooks/use-dismiss.ts +24 -0
- package/src/hooks/use-escape-first.ts +25 -0
- package/src/hooks/use-media-query.ts +23 -0
- package/src/hooks/use-save-queue.ts +19 -7
- package/src/hooks/use-selection.ts +8 -1
- package/src/lib/database.ts +322 -0
- package/src/lib/dates.ts +36 -0
- package/src/lib/keys.ts +72 -0
- package/src/lib/number.ts +29 -0
- package/src/lib/pointer.ts +3 -0
- package/src/lib/prepare-image.ts +141 -0
- package/src/lib/rich-text-dom.ts +5 -3
- package/src/lib/theme.ts +18 -0
- package/src/lib/time.ts +83 -0
- package/src/lib/utils.ts +21 -2
- package/src/styles/notion.css +342 -51
|
@@ -21,7 +21,14 @@ export function useSelection(order: string[]): { selection: Selection | null; st
|
|
|
21
21
|
};
|
|
22
22
|
useEffect(() => {
|
|
23
23
|
if (!selecting) return;
|
|
24
|
-
|
|
24
|
+
// Escape ends the selection, unless it was meant for something over the page:
|
|
25
|
+
// the confirm() asked about deleting the selection, a menu, a list. That
|
|
26
|
+
// closes, and the selection stays.
|
|
27
|
+
const onKey = (event: KeyboardEvent) => {
|
|
28
|
+
if (event.key !== "Escape" || event.defaultPrevented) return;
|
|
29
|
+
if (document.querySelector('[role="dialog"], [role="alertdialog"], [role="menu"], [role="listbox"]')) return;
|
|
30
|
+
stop();
|
|
31
|
+
};
|
|
25
32
|
window.addEventListener("keydown", onKey);
|
|
26
33
|
return () => window.removeEventListener("keydown", onKey);
|
|
27
34
|
}, [selecting]);
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
/* A database, as Notion's: rows with typed properties, seen through views that
|
|
2
|
+
filter, sort and group them. The app owns the data; this is the meaning of it,
|
|
3
|
+
pure functions with no React, so a server can filter and sort by the same
|
|
4
|
+
rules the page does.
|
|
5
|
+
|
|
6
|
+
Values are plain JSON: text as a string, a number, a date as "YYYY-MM-DD", a
|
|
7
|
+
checkbox as a boolean, a select as its option's id, a multi-select as an array
|
|
8
|
+
of option ids. Empty is null (or "" or []). */
|
|
9
|
+
|
|
10
|
+
export type PropertyType = "title" | "text" | "number" | "select" | "multiSelect" | "date" | "checkbox" | "url";
|
|
11
|
+
|
|
12
|
+
export type TagColor = "gray" | "brown" | "orange" | "yellow" | "green" | "blue" | "purple" | "pink" | "red";
|
|
13
|
+
|
|
14
|
+
export type PropertyOption = { id: string; name: string; color: TagColor };
|
|
15
|
+
|
|
16
|
+
export type Property = { id: string; name: string; type: PropertyType; options?: PropertyOption[] };
|
|
17
|
+
|
|
18
|
+
export type Value = string | number | boolean | string[] | null;
|
|
19
|
+
|
|
20
|
+
export type Row = { id: string; values: Record<string, Value>; cover?: string | null };
|
|
21
|
+
|
|
22
|
+
export type FilterOp =
|
|
23
|
+
| "contains"
|
|
24
|
+
| "notContains"
|
|
25
|
+
| "is"
|
|
26
|
+
| "isNot"
|
|
27
|
+
| "isEmpty"
|
|
28
|
+
| "isNotEmpty"
|
|
29
|
+
| "gt"
|
|
30
|
+
| "lt"
|
|
31
|
+
| "gte"
|
|
32
|
+
| "lte"
|
|
33
|
+
| "before"
|
|
34
|
+
| "after"
|
|
35
|
+
| "onOrBefore"
|
|
36
|
+
| "onOrAfter";
|
|
37
|
+
|
|
38
|
+
export type Filter = { id: string; property: string; op: FilterOp; value?: Value };
|
|
39
|
+
export type Match = "all" | "any";
|
|
40
|
+
export type Sort = { property: string; direction: "asc" | "desc" };
|
|
41
|
+
|
|
42
|
+
/** What can be asked of each kind of property, in the order a menu shows them, with their words. */
|
|
43
|
+
export const OPS: Record<PropertyType, readonly { op: FilterOp; label: string }[]> = {
|
|
44
|
+
title: textOps(),
|
|
45
|
+
text: textOps(),
|
|
46
|
+
url: textOps(),
|
|
47
|
+
number: [
|
|
48
|
+
{ op: "is", label: "=" },
|
|
49
|
+
{ op: "isNot", label: "≠" },
|
|
50
|
+
{ op: "gt", label: ">" },
|
|
51
|
+
{ op: "lt", label: "<" },
|
|
52
|
+
{ op: "gte", label: "≥" },
|
|
53
|
+
{ op: "lte", label: "≤" },
|
|
54
|
+
{ op: "isEmpty", label: "is empty" },
|
|
55
|
+
{ op: "isNotEmpty", label: "is not empty" },
|
|
56
|
+
],
|
|
57
|
+
select: [
|
|
58
|
+
{ op: "is", label: "is" },
|
|
59
|
+
{ op: "isNot", label: "is not" },
|
|
60
|
+
{ op: "isEmpty", label: "is empty" },
|
|
61
|
+
{ op: "isNotEmpty", label: "is not empty" },
|
|
62
|
+
],
|
|
63
|
+
multiSelect: [
|
|
64
|
+
{ op: "contains", label: "contains" },
|
|
65
|
+
{ op: "notContains", label: "does not contain" },
|
|
66
|
+
{ op: "isEmpty", label: "is empty" },
|
|
67
|
+
{ op: "isNotEmpty", label: "is not empty" },
|
|
68
|
+
],
|
|
69
|
+
date: [
|
|
70
|
+
{ op: "is", label: "is" },
|
|
71
|
+
{ op: "before", label: "is before" },
|
|
72
|
+
{ op: "after", label: "is after" },
|
|
73
|
+
{ op: "onOrBefore", label: "is on or before" },
|
|
74
|
+
{ op: "onOrAfter", label: "is on or after" },
|
|
75
|
+
{ op: "isEmpty", label: "is empty" },
|
|
76
|
+
{ op: "isNotEmpty", label: "is not empty" },
|
|
77
|
+
],
|
|
78
|
+
checkbox: [{ op: "is", label: "is" }],
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
function textOps() {
|
|
82
|
+
return [
|
|
83
|
+
{ op: "contains", label: "contains" },
|
|
84
|
+
{ op: "notContains", label: "does not contain" },
|
|
85
|
+
{ op: "is", label: "is" },
|
|
86
|
+
{ op: "isNot", label: "is not" },
|
|
87
|
+
{ op: "isEmpty", label: "is empty" },
|
|
88
|
+
{ op: "isNotEmpty", label: "is not empty" },
|
|
89
|
+
] as const satisfies readonly { op: FilterOp; label: string }[];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Whether an op needs a value to compare with (is empty does not). */
|
|
93
|
+
export const needsValue = (op: FilterOp) => op !== "isEmpty" && op !== "isNotEmpty";
|
|
94
|
+
|
|
95
|
+
export const isEmpty = (v: Value | undefined): boolean => v === null || v === undefined || v === "" || (Array.isArray(v) && v.length === 0);
|
|
96
|
+
|
|
97
|
+
/** A filter just added for `property`: its first op, and for a checkbox, checked. */
|
|
98
|
+
export function newFilter(property: Property, id: string): Filter {
|
|
99
|
+
const op = OPS[property.type][0]!.op;
|
|
100
|
+
return { id, property: property.id, op, value: property.type === "checkbox" ? true : null };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Whether `row` passes `filter`. A filter still missing its value lets everything through, so a half-written one never empties the view. */
|
|
104
|
+
export function passes(row: Row, filter: Filter, property: Property | undefined): boolean {
|
|
105
|
+
if (!property) return true;
|
|
106
|
+
const v = row.values[property.id] ?? null;
|
|
107
|
+
if (filter.op === "isEmpty") return isEmpty(v);
|
|
108
|
+
if (filter.op === "isNotEmpty") return !isEmpty(v);
|
|
109
|
+
const want = filter.value;
|
|
110
|
+
if (property.type === "checkbox") return (v === true) === (want !== false);
|
|
111
|
+
if (isEmpty(want)) return true;
|
|
112
|
+
switch (property.type) {
|
|
113
|
+
case "title":
|
|
114
|
+
case "text":
|
|
115
|
+
case "url": {
|
|
116
|
+
const have = String(v ?? "").toLocaleLowerCase();
|
|
117
|
+
const w = String(want).toLocaleLowerCase();
|
|
118
|
+
if (filter.op === "contains") return have.includes(w);
|
|
119
|
+
if (filter.op === "notContains") return !have.includes(w);
|
|
120
|
+
if (filter.op === "is") return have === w;
|
|
121
|
+
if (filter.op === "isNot") return have !== w;
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
case "number": {
|
|
125
|
+
// A number stored as text counts as that number.
|
|
126
|
+
const n = typeof v === "number" ? v : typeof v === "string" && v.trim() !== "" ? Number(v) : NaN;
|
|
127
|
+
if (Number.isNaN(n)) return filter.op === "isNot";
|
|
128
|
+
const w = Number(want);
|
|
129
|
+
const v2 = n;
|
|
130
|
+
return { is: v2 === w, isNot: v2 !== w, gt: v2 > w, lt: v2 < w, gte: v2 >= w, lte: v2 <= w }[filter.op as "is"] ?? true;
|
|
131
|
+
}
|
|
132
|
+
case "select":
|
|
133
|
+
if (filter.op === "is") return v === want;
|
|
134
|
+
if (filter.op === "isNot") return v !== want;
|
|
135
|
+
return true;
|
|
136
|
+
case "multiSelect": {
|
|
137
|
+
const have = Array.isArray(v) ? v : [];
|
|
138
|
+
const wants = Array.isArray(want) ? want : [String(want)];
|
|
139
|
+
const any = wants.some((w) => have.includes(w));
|
|
140
|
+
return filter.op === "notContains" ? !any : any;
|
|
141
|
+
}
|
|
142
|
+
case "date": {
|
|
143
|
+
if (typeof v !== "string" || v === "") return false;
|
|
144
|
+
const w = String(want);
|
|
145
|
+
// "YYYY-MM-DD" compares as text in date order.
|
|
146
|
+
const day = v.slice(0, 10);
|
|
147
|
+
return { is: day === w, before: day < w, after: day > w, onOrBefore: day <= w, onOrAfter: day >= w }[filter.op as "is"] ?? true;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Whether a filter says anything yet: its property exists, and it has a value if it needs one. */
|
|
153
|
+
export function isActive(filter: Filter, property: Property | undefined): boolean {
|
|
154
|
+
if (!property) return false;
|
|
155
|
+
if (!needsValue(filter.op) || property.type === "checkbox") return true;
|
|
156
|
+
return !isEmpty(filter.value ?? null);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Rows passing all (or any) of the filters. Filters that say nothing yet (a deleted property, a value not given) are left out,
|
|
160
|
+
so with "any" a half-written one does not let every row through. */
|
|
161
|
+
export function filterRows(rows: readonly Row[], properties: readonly Property[], filters: readonly Filter[], match: Match = "all"): Row[] {
|
|
162
|
+
const byId = new Map(properties.map((p) => [p.id, p]));
|
|
163
|
+
const active = filters.filter((f) => isActive(f, byId.get(f.property)));
|
|
164
|
+
if (active.length === 0) return [...rows];
|
|
165
|
+
return rows.filter((row) => (match === "all" ? active.every((f) => passes(row, f, byId.get(f.property))) : active.some((f) => passes(row, f, byId.get(f.property)))));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
|
|
169
|
+
|
|
170
|
+
/** How two values of `property` order, ascending. Empty sorts last, whichever way. */
|
|
171
|
+
export function compareValues(a: Value | undefined, b: Value | undefined, property: Property): number {
|
|
172
|
+
switch (property.type) {
|
|
173
|
+
case "number": {
|
|
174
|
+
// Something not a number sorts after every number.
|
|
175
|
+
const na = Number(a);
|
|
176
|
+
const nb = Number(b);
|
|
177
|
+
if (Number.isNaN(na) || Number.isNaN(nb)) return Number(Number.isNaN(na)) - Number(Number.isNaN(nb));
|
|
178
|
+
return na - nb;
|
|
179
|
+
}
|
|
180
|
+
case "checkbox":
|
|
181
|
+
return Number(a === true) - Number(b === true);
|
|
182
|
+
case "select": {
|
|
183
|
+
// In the options' own order, as a board's columns are.
|
|
184
|
+
// An id no longer among the options sorts after them.
|
|
185
|
+
const order = (v: Value | undefined) => {
|
|
186
|
+
const i = property.options?.findIndex((o) => o.id === v) ?? -1;
|
|
187
|
+
return i === -1 ? Number.MAX_SAFE_INTEGER : i;
|
|
188
|
+
};
|
|
189
|
+
return order(a) - order(b);
|
|
190
|
+
}
|
|
191
|
+
case "multiSelect": {
|
|
192
|
+
const name = (v: Value | undefined) => (Array.isArray(v) ? v.map((id) => property.options?.find((o) => o.id === id)?.name ?? id).join(", ") : "");
|
|
193
|
+
return collator.compare(name(a), name(b));
|
|
194
|
+
}
|
|
195
|
+
default:
|
|
196
|
+
return collator.compare(String(a ?? ""), String(b ?? ""));
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** Sorted by each sort in turn; rows equal on all of them keep their order. */
|
|
201
|
+
export function sortRows(rows: readonly Row[], properties: readonly Property[], sorts: readonly Sort[]): Row[] {
|
|
202
|
+
const byId = new Map(properties.map((p) => [p.id, p]));
|
|
203
|
+
const keyed = rows.map((row, index) => ({ row, index }));
|
|
204
|
+
keyed.sort((x, y) => {
|
|
205
|
+
for (const sort of sorts) {
|
|
206
|
+
const property = byId.get(sort.property);
|
|
207
|
+
if (!property) continue;
|
|
208
|
+
const a = x.row.values[property.id];
|
|
209
|
+
const b = y.row.values[property.id];
|
|
210
|
+
// A checkbox is never empty: unset is unchecked, sorted with the unchecked.
|
|
211
|
+
const ea = property.type !== "checkbox" && isEmpty(a ?? null);
|
|
212
|
+
const eb = property.type !== "checkbox" && isEmpty(b ?? null);
|
|
213
|
+
if (ea !== eb) return ea ? 1 : -1;
|
|
214
|
+
if (ea && eb) continue;
|
|
215
|
+
const c = compareValues(a, b, property);
|
|
216
|
+
if (c !== 0) return sort.direction === "asc" ? c : -c;
|
|
217
|
+
}
|
|
218
|
+
return x.index - y.index;
|
|
219
|
+
});
|
|
220
|
+
return keyed.map((k) => k.row);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export type Group = { key: string | null; option: PropertyOption | null; rows: Row[] };
|
|
224
|
+
|
|
225
|
+
/** Rows by a select (or a checkbox): a group per option in its order, then "No value". Empty groups are kept, for a board's columns. */
|
|
226
|
+
export function groupRows(rows: readonly Row[], property: Property): Group[] {
|
|
227
|
+
if (property.type === "checkbox") {
|
|
228
|
+
return [true, false].map((on) => ({ key: String(on), option: null, rows: rows.filter((r) => (r.values[property.id] === true) === on) }));
|
|
229
|
+
}
|
|
230
|
+
const options = property.options ?? [];
|
|
231
|
+
const groups: Group[] = options.map((option) => ({ key: option.id, option, rows: [] }));
|
|
232
|
+
const none: Group = { key: null, option: null, rows: [] };
|
|
233
|
+
for (const row of rows) {
|
|
234
|
+
const v = row.values[property.id];
|
|
235
|
+
const ids = Array.isArray(v) ? v : v === null || v === undefined || v === "" ? [] : [String(v)];
|
|
236
|
+
const homes = groups.filter((g) => ids.includes(g.key!));
|
|
237
|
+
if (homes.length === 0) none.rows.push(row);
|
|
238
|
+
for (const g of homes) g.rows.push(row);
|
|
239
|
+
}
|
|
240
|
+
return [...groups, none];
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** The first title property, which names a row. */
|
|
244
|
+
export const titleOf = (properties: readonly Property[]) => properties.find((p) => p.type === "title");
|
|
245
|
+
|
|
246
|
+
/** A value as words, for a screen reader or a plain cell. */
|
|
247
|
+
export function valueText(v: Value | undefined, property: Property): string {
|
|
248
|
+
if (isEmpty(v ?? null)) return "";
|
|
249
|
+
switch (property.type) {
|
|
250
|
+
case "checkbox":
|
|
251
|
+
return v ? "Yes" : "No";
|
|
252
|
+
case "select":
|
|
253
|
+
return property.options?.find((o) => o.id === v)?.name ?? String(v);
|
|
254
|
+
case "multiSelect":
|
|
255
|
+
return (v as string[]).map((id) => property.options?.find((o) => o.id === id)?.name ?? id).join(", ");
|
|
256
|
+
default:
|
|
257
|
+
return String(v);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/* ── Views ───────────────────────────────────────────────────────────────── */
|
|
262
|
+
|
|
263
|
+
export type ViewKind = "table" | "board" | "gallery" | "list" | "calendar";
|
|
264
|
+
|
|
265
|
+
/** One way of seeing the rows. A view keeps its own filter, sort, hidden properties and, per kind, what it groups or dates by. */
|
|
266
|
+
export type View = {
|
|
267
|
+
id: string;
|
|
268
|
+
name: string;
|
|
269
|
+
kind: ViewKind;
|
|
270
|
+
sort: Sort[];
|
|
271
|
+
filter: Filter[];
|
|
272
|
+
match?: Match;
|
|
273
|
+
/** A board's columns: a select property. */
|
|
274
|
+
groupBy?: string;
|
|
275
|
+
/** A calendar's days: a date property. */
|
|
276
|
+
dateProperty?: string;
|
|
277
|
+
/** Properties not shown (a table's columns, a card's lines). */
|
|
278
|
+
hidden: string[];
|
|
279
|
+
/** A table's column widths, in px, by property. */
|
|
280
|
+
widths?: Record<string, number>;
|
|
281
|
+
/** A table's column order, by property id; any not listed follow in the properties' order. */
|
|
282
|
+
order?: string[];
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
/** Rows whose words (title, text, url, select and multi-select names) contain `query`, ignoring case. */
|
|
286
|
+
export function searchRows(rows: readonly Row[], properties: readonly Property[], query: string): Row[] {
|
|
287
|
+
const q = query.trim().toLocaleLowerCase();
|
|
288
|
+
if (q === "") return [...rows];
|
|
289
|
+
const words = properties.filter((p) => p.type !== "checkbox" && p.type !== "number" && p.type !== "date");
|
|
290
|
+
return rows.filter((row) => words.some((p) => valueText(row.values[p.id], p).toLocaleLowerCase().includes(q)));
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** What a view shows: searched, filtered, then sorted. */
|
|
294
|
+
export function applyView(rows: readonly Row[], properties: readonly Property[], view: Pick<View, "filter" | "sort" | "match">, query = ""): Row[] {
|
|
295
|
+
return sortRows(filterRows(searchRows(rows, properties, query), properties, view.filter, view.match), properties, view.sort);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** A view's properties to show, in its order, without the hidden ones. The title always shows. */
|
|
299
|
+
export function shownProperties(properties: readonly Property[], view: Pick<View, "hidden" | "order">): Property[] {
|
|
300
|
+
const order = view.order ?? [];
|
|
301
|
+
const ranked = [...properties].sort((a, b) => {
|
|
302
|
+
const ia = order.indexOf(a.id);
|
|
303
|
+
const ib = order.indexOf(b.id);
|
|
304
|
+
return (ia === -1 ? order.length + properties.indexOf(a) : ia) - (ib === -1 ? order.length + properties.indexOf(b) : ib);
|
|
305
|
+
});
|
|
306
|
+
return ranked.filter((p) => p.type === "title" || !view.hidden.includes(p.id));
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** A fresh view of `kind`, choosing what a board groups by and a calendar dates by. */
|
|
310
|
+
export function newView(kind: ViewKind, properties: readonly Property[], id: string, name?: string): View {
|
|
311
|
+
const names: Record<ViewKind, string> = { table: "Table", board: "Board", gallery: "Gallery", list: "List", calendar: "Calendar" };
|
|
312
|
+
return {
|
|
313
|
+
id,
|
|
314
|
+
name: name ?? names[kind],
|
|
315
|
+
kind,
|
|
316
|
+
sort: [],
|
|
317
|
+
filter: [],
|
|
318
|
+
hidden: [],
|
|
319
|
+
groupBy: kind === "board" ? properties.find((p) => p.type === "select")?.id : undefined,
|
|
320
|
+
dateProperty: kind === "calendar" ? properties.find((p) => p.type === "date")?.id : undefined,
|
|
321
|
+
};
|
|
322
|
+
}
|
package/src/lib/dates.ts
CHANGED
|
@@ -37,3 +37,39 @@ const SHORT_DAY = new Intl.DateTimeFormat("en-GB", { day: "numeric", month: "sho
|
|
|
37
37
|
export const formatDay = (date: Date): string => DAY.format(date).replace(",", "");
|
|
38
38
|
/** "27 Dec 2026" */
|
|
39
39
|
export const formatShortDay = (date: Date): string => SHORT_DAY.format(date);
|
|
40
|
+
|
|
41
|
+
/* Months as `YYYY-MM`, for a month at a time: a calendar, a budget, a report.
|
|
42
|
+
From endgame, 2026-12-05, without its fixed time zone: "today" here is the
|
|
43
|
+
browser's local day, which is the reader's. */
|
|
44
|
+
|
|
45
|
+
/** The reader's local day, `YYYY-MM-DD`. */
|
|
46
|
+
export const today = (now: Date = new Date()): string => toISODate(now);
|
|
47
|
+
|
|
48
|
+
export const isMonth = (value: unknown): value is string => typeof value === "string" && /^\d{4}-(0[1-9]|1[0-2])$/.test(value);
|
|
49
|
+
|
|
50
|
+
/** The month a `YYYY-MM-DD` falls in. */
|
|
51
|
+
export const monthOf = (day: string): string => day.slice(0, 7);
|
|
52
|
+
|
|
53
|
+
/** How many days the month has (28 to 31). */
|
|
54
|
+
export function daysIn(month: string): number {
|
|
55
|
+
const [y, m] = month.split("-").map(Number);
|
|
56
|
+
return new Date(y, m, 0).getDate();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The month `by` months before or after, across a year's end. */
|
|
60
|
+
export function shiftMonth(month: string, by: number): string {
|
|
61
|
+
const [y, m] = month.split("-").map(Number);
|
|
62
|
+
const date = new Date(y, m - 1 + by, 1);
|
|
63
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The first and last day of a month, both included. */
|
|
67
|
+
export const monthSpan = (month: string): { from: string; to: string } => ({ from: `${month}-01`, to: `${month}-${pad(daysIn(month))}` });
|
|
68
|
+
|
|
69
|
+
const MONTH = new Intl.DateTimeFormat("en-GB", { month: "long", year: "numeric" });
|
|
70
|
+
|
|
71
|
+
/** "December 2026" */
|
|
72
|
+
export const formatMonth = (month: string): string => {
|
|
73
|
+
const [y, m] = month.split("-").map(Number);
|
|
74
|
+
return MONTH.format(new Date(y, m - 1, 1));
|
|
75
|
+
};
|
package/src/lib/keys.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/* Keyboard shortcuts written once, shown right on every platform. A shortcut is
|
|
2
|
+
written as "mod+shift+k": `mod` is ⌘ on Apple platforms and Ctrl elsewhere,
|
|
3
|
+
which is what the kit's own shortcuts listen for (⌘\, ⌘K). */
|
|
4
|
+
|
|
5
|
+
export type Platform = "apple" | "other";
|
|
6
|
+
|
|
7
|
+
/** Which platform the browser says it is. "other" on the server. */
|
|
8
|
+
export function platform(): Platform {
|
|
9
|
+
if (typeof navigator === "undefined") return "other";
|
|
10
|
+
const name = (navigator as Navigator & { userAgentData?: { platform?: string } }).userAgentData?.platform ?? navigator.platform ?? "";
|
|
11
|
+
return /mac|iphone|ipad|ipod/i.test(name) ? "apple" : "other";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type Key = { shown: string; spoken: string };
|
|
15
|
+
|
|
16
|
+
const NAMES: Record<string, Record<Platform, Key>> = {
|
|
17
|
+
mod: { apple: { shown: "⌘", spoken: "Command" }, other: { shown: "Ctrl", spoken: "Control" } },
|
|
18
|
+
ctrl: { apple: { shown: "⌃", spoken: "Control" }, other: { shown: "Ctrl", spoken: "Control" } },
|
|
19
|
+
alt: { apple: { shown: "⌥", spoken: "Option" }, other: { shown: "Alt", spoken: "Alt" } },
|
|
20
|
+
shift: { apple: { shown: "⇧", spoken: "Shift" }, other: { shown: "Shift", spoken: "Shift" } },
|
|
21
|
+
enter: { apple: { shown: "↵", spoken: "Enter" }, other: { shown: "Enter", spoken: "Enter" } },
|
|
22
|
+
backspace: { apple: { shown: "⌫", spoken: "Backspace" }, other: { shown: "Backspace", spoken: "Backspace" } },
|
|
23
|
+
escape: { apple: { shown: "Esc", spoken: "Escape" }, other: { shown: "Esc", spoken: "Escape" } },
|
|
24
|
+
tab: { apple: { shown: "⇥", spoken: "Tab" }, other: { shown: "Tab", spoken: "Tab" } },
|
|
25
|
+
up: { apple: { shown: "↑", spoken: "Up" }, other: { shown: "↑", spoken: "Up" } },
|
|
26
|
+
down: { apple: { shown: "↓", spoken: "Down" }, other: { shown: "↓", spoken: "Down" } },
|
|
27
|
+
left: { apple: { shown: "←", spoken: "Left" }, other: { shown: "←", spoken: "Left" } },
|
|
28
|
+
right: { apple: { shown: "→", spoken: "Right" }, other: { shown: "→", spoken: "Right" } },
|
|
29
|
+
"\\": { apple: { shown: "\\", spoken: "Backslash" }, other: { shown: "\\", spoken: "Backslash" } },
|
|
30
|
+
"/": { apple: { shown: "/", spoken: "Slash" }, other: { shown: "/", spoken: "Slash" } },
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** "mod+shift+k" → the keys as shown and as spoken on `on`. */
|
|
34
|
+
export function shortcutKeys(shortcut: string, on: Platform = platform()): Key[] {
|
|
35
|
+
return shortcut
|
|
36
|
+
.split("+")
|
|
37
|
+
.filter(Boolean)
|
|
38
|
+
.map((part) => {
|
|
39
|
+
const key = part.trim().toLowerCase();
|
|
40
|
+
return NAMES[key]?.[on] ?? { shown: key.length === 1 ? key.toUpperCase() : part.trim(), spoken: key.length === 1 ? key.toUpperCase() : part.trim() };
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** "mod+k" → "⌘K" on Apple, "Ctrl+K" elsewhere: for text, such as a tooltip. */
|
|
45
|
+
export function formatShortcut(shortcut: string, on: Platform = platform()): string {
|
|
46
|
+
return shortcutKeys(shortcut, on)
|
|
47
|
+
.map((k) => k.shown)
|
|
48
|
+
.join(on === "apple" ? "" : "+");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** "mod+k" → "Command K": what a screen reader should say. */
|
|
52
|
+
export const speakShortcut = (shortcut: string, on: Platform = platform()): string =>
|
|
53
|
+
shortcutKeys(shortcut, on)
|
|
54
|
+
.map((k) => k.spoken)
|
|
55
|
+
.join(" ");
|
|
56
|
+
|
|
57
|
+
const KEY_NAMES: Record<string, string> = { enter: "enter", escape: "escape", tab: "tab", backspace: "backspace", up: "arrowup", down: "arrowdown", left: "arrowleft", right: "arrowright", space: " " };
|
|
58
|
+
|
|
59
|
+
/** Whether a key press is `shortcut` ("mod+k", "shift+?", "f8"). `mod` is ⌘ or Ctrl, either, as the kit's
|
|
60
|
+
own shortcuts take both. Modifiers not written must be up. Safe for the key events autofill sends with no key. */
|
|
61
|
+
export function matchShortcut(e: Pick<KeyboardEvent, "key" | "metaKey" | "ctrlKey" | "altKey" | "shiftKey">, shortcut: string): boolean {
|
|
62
|
+
if (typeof e.key !== "string" || e.key === "") return false;
|
|
63
|
+
const parts = shortcut.toLowerCase().split("+");
|
|
64
|
+
const key = parts.pop()!;
|
|
65
|
+
const want = new Set(parts);
|
|
66
|
+
const mod = want.has("mod");
|
|
67
|
+
if (mod ? !(e.metaKey || e.ctrlKey) : e.metaKey !== want.has("meta") || e.ctrlKey !== want.has("ctrl")) return false;
|
|
68
|
+
if (e.altKey !== want.has("alt")) return false;
|
|
69
|
+
// A shifted symbol ("?") is its own key; shift is only checked when written, or for a letter.
|
|
70
|
+
if (want.has("shift") ? !e.shiftKey : e.shiftKey && /^[a-z0-9]$/.test(key)) return false;
|
|
71
|
+
return e.key.toLowerCase() === (KEY_NAMES[key] ?? key);
|
|
72
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* Reading a number someone typed, in whichever way they write numbers.
|
|
2
|
+
|
|
3
|
+
Currency signs, spaces and apostrophes (1'000, as in Switzerland) are ignored.
|
|
4
|
+
With both "," and ".", the last one is the decimal point: 1,234.5 and 1.234,5
|
|
5
|
+
are both one thousand two hundred and thirty-four and a half. With only commas,
|
|
6
|
+
they are thousands when every group after the first is three digits (1,234 and
|
|
7
|
+
12,345,678), and otherwise the decimal point (12,5). With only points, one is the
|
|
8
|
+
decimal point and several are thousands (1.234.567).
|
|
9
|
+
|
|
10
|
+
Returns null for an empty field and NaN for anything that is not a number, so a
|
|
11
|
+
caller can tell "cleared" from "typed nonsense". */
|
|
12
|
+
export function parseNumber(text: string): number | null {
|
|
13
|
+
let s = text.replace(/[\s '’$€£¥₹]/g, "").replace(/^\((.*)\)$/, "-$1");
|
|
14
|
+
if (s === "") return null;
|
|
15
|
+
const comma = s.lastIndexOf(",");
|
|
16
|
+
const point = s.lastIndexOf(".");
|
|
17
|
+
if (comma !== -1 && point !== -1) {
|
|
18
|
+
s = comma > point ? s.replace(/\./g, "").replace(",", ".") : s.replace(/,/g, "");
|
|
19
|
+
} else if (comma !== -1) {
|
|
20
|
+
s = /^[-+]?\d{1,3}(,\d{3})+$/.test(s) ? s.replace(/,/g, "") : s.replace(",", ".");
|
|
21
|
+
} else if ((s.match(/\./g) ?? []).length > 1) {
|
|
22
|
+
s = s.replace(/\./g, "");
|
|
23
|
+
}
|
|
24
|
+
if (!/^[-+]?(\d+\.?\d*|\.\d+)$/.test(s)) return Number.NaN;
|
|
25
|
+
return Number(s);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Keeps a number within `min` and `max`, either of which may be absent. */
|
|
29
|
+
export const clamp = (n: number, min?: number, max?: number): number => Math.min(max ?? Infinity, Math.max(min ?? -Infinity, n));
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/* Turning a picture off a phone or a camera into what is worth uploading: a display
|
|
2
|
+
JPEG and a thumbnail, each under a byte budget, the right way up, never the
|
|
3
|
+
original. Three apps each wrote this (endgame, medialogue, triptrack); this is
|
|
4
|
+
the one, with their differences as options.
|
|
5
|
+
|
|
6
|
+
- The picture is turned upright from its EXIF orientation (createImageBitmap's
|
|
7
|
+
default) and drawn on white, so a cut-out PNG does not come out on black.
|
|
8
|
+
- It is halved until the last step is small: a canvas shrinking a picture to a
|
|
9
|
+
quarter or less in one go skips pixels and the result shimmers.
|
|
10
|
+
- Each copy is saved at the best quality that fits its budget, stepping down;
|
|
11
|
+
a photograph fits at the first. One that will not fit fails, rather than
|
|
12
|
+
sending what the server will refuse.
|
|
13
|
+
- `square` crops to the middle square first (an avatar, a cover).
|
|
14
|
+
- `hash` adds a SHA-256 of the original file, to spot a picture sent twice.
|
|
15
|
+
|
|
16
|
+
Browser only: it needs a canvas. */
|
|
17
|
+
|
|
18
|
+
export type ImageCopy = {
|
|
19
|
+
/** The longest edge, in pixels. */
|
|
20
|
+
edge?: number;
|
|
21
|
+
/** Or the height, for a thumbnail strip of even height. */
|
|
22
|
+
height?: number;
|
|
23
|
+
/** The most bytes the JPEG may be. */
|
|
24
|
+
bytes: number;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type PreparedImage = {
|
|
28
|
+
display: Blob;
|
|
29
|
+
thumb: Blob;
|
|
30
|
+
/** The display copy's size. */
|
|
31
|
+
width: number;
|
|
32
|
+
height: number;
|
|
33
|
+
aspect: number;
|
|
34
|
+
/** SHA-256 of the original, as hex, when asked for. */
|
|
35
|
+
hash?: string;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const QUALITIES = [0.82, 0.72, 0.6, 0.5, 0.4] as const;
|
|
39
|
+
|
|
40
|
+
const DEFAULTS = {
|
|
41
|
+
display: { edge: 1600, bytes: 1_000_000 },
|
|
42
|
+
thumb: { edge: 400, bytes: 140_000 },
|
|
43
|
+
} satisfies Record<string, ImageCopy>;
|
|
44
|
+
|
|
45
|
+
/** The size a picture of `width` × `height` becomes for `copy`, never larger than it was. */
|
|
46
|
+
export function fitSize(width: number, height: number, copy: Pick<ImageCopy, "edge" | "height">): { width: number; height: number } {
|
|
47
|
+
const scale = Math.min(1, copy.height !== undefined ? copy.height / height : (copy.edge ?? Infinity) / Math.max(width, height));
|
|
48
|
+
return { width: Math.max(1, Math.round(width * scale)), height: Math.max(1, Math.round(height * scale)) };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type Crop = { x: number; y: number; width: number; height: number };
|
|
52
|
+
|
|
53
|
+
function canvasOf(width: number, height: number): [HTMLCanvasElement, CanvasRenderingContext2D] {
|
|
54
|
+
const canvas = document.createElement("canvas");
|
|
55
|
+
canvas.width = width;
|
|
56
|
+
canvas.height = height;
|
|
57
|
+
const context = canvas.getContext("2d");
|
|
58
|
+
if (context === null) throw new Error("This browser could not resize the picture.");
|
|
59
|
+
context.fillStyle = "#fff";
|
|
60
|
+
context.fillRect(0, 0, width, height);
|
|
61
|
+
context.imageSmoothingQuality = "high";
|
|
62
|
+
return [canvas, context];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** `source` (its `crop`) drawn at `width` × `height`, halving on the way so nothing shimmers. */
|
|
66
|
+
export function resizeTo(source: CanvasImageSource, crop: Crop, width: number, height: number): HTMLCanvasElement {
|
|
67
|
+
let current: CanvasImageSource = source;
|
|
68
|
+
let from = crop;
|
|
69
|
+
let w = crop.width;
|
|
70
|
+
let h = crop.height;
|
|
71
|
+
while (w / 2 >= width && h / 2 >= height) {
|
|
72
|
+
w = Math.round(w / 2);
|
|
73
|
+
h = Math.round(h / 2);
|
|
74
|
+
const [canvas, context] = canvasOf(w, h);
|
|
75
|
+
context.drawImage(current, from.x, from.y, from.width, from.height, 0, 0, w, h);
|
|
76
|
+
// A step's own canvas (never the caller's) is let go of once drawn from: iOS Safari caps the memory canvases may hold.
|
|
77
|
+
if (current !== source && current instanceof HTMLCanvasElement) current.width = 0;
|
|
78
|
+
current = canvas;
|
|
79
|
+
from = { x: 0, y: 0, width: w, height: h };
|
|
80
|
+
}
|
|
81
|
+
const [canvas, context] = canvasOf(width, height);
|
|
82
|
+
context.drawImage(current, from.x, from.y, from.width, from.height, 0, 0, width, height);
|
|
83
|
+
if (current !== source && current instanceof HTMLCanvasElement) current.width = 0;
|
|
84
|
+
return canvas;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const encode = (canvas: HTMLCanvasElement, quality: number): Promise<Blob> =>
|
|
88
|
+
new Promise((resolve, reject) =>
|
|
89
|
+
canvas.toBlob((blob) => (blob ? resolve(blob) : reject(new Error("This browser could not save the picture."))), "image/jpeg", quality),
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
/** The best quality JPEG that fits in `bytes`. */
|
|
93
|
+
export async function jpegUnder(canvas: HTMLCanvasElement, bytes: number, qualities: readonly number[] = QUALITIES): Promise<Blob> {
|
|
94
|
+
let blob: Blob | null = null;
|
|
95
|
+
for (const quality of qualities) {
|
|
96
|
+
blob = await encode(canvas, quality);
|
|
97
|
+
if (blob.size <= bytes) return blob;
|
|
98
|
+
}
|
|
99
|
+
throw new Error("That picture would not shrink far enough to keep.");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const hex = (buffer: ArrayBuffer) => [...new Uint8Array(buffer)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
103
|
+
|
|
104
|
+
export async function prepareImage(
|
|
105
|
+
file: Blob,
|
|
106
|
+
{
|
|
107
|
+
display = DEFAULTS.display,
|
|
108
|
+
thumb = DEFAULTS.thumb,
|
|
109
|
+
square = false,
|
|
110
|
+
hash = false,
|
|
111
|
+
qualities = QUALITIES,
|
|
112
|
+
}: { display?: ImageCopy; thumb?: ImageCopy; square?: boolean; hash?: boolean; qualities?: readonly number[] } = {},
|
|
113
|
+
): Promise<PreparedImage> {
|
|
114
|
+
let bitmap: ImageBitmap;
|
|
115
|
+
try {
|
|
116
|
+
bitmap = await createImageBitmap(file);
|
|
117
|
+
} catch {
|
|
118
|
+
throw new Error("This browser cannot open that kind of picture.");
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
const side = Math.min(bitmap.width, bitmap.height);
|
|
122
|
+
const crop: Crop = square
|
|
123
|
+
? { x: Math.round((bitmap.width - side) / 2), y: Math.round((bitmap.height - side) / 2), width: side, height: side }
|
|
124
|
+
: { x: 0, y: 0, width: bitmap.width, height: bitmap.height };
|
|
125
|
+
const size = fitSize(crop.width, crop.height, display);
|
|
126
|
+
const big = resizeTo(bitmap, crop, size.width, size.height);
|
|
127
|
+
const small = fitSize(size.width, size.height, thumb);
|
|
128
|
+
const little = resizeTo(big, { x: 0, y: 0, width: size.width, height: size.height }, small.width, small.height);
|
|
129
|
+
return {
|
|
130
|
+
display: await jpegUnder(big, display.bytes, qualities),
|
|
131
|
+
thumb: await jpegUnder(little, thumb.bytes, qualities),
|
|
132
|
+
width: size.width,
|
|
133
|
+
height: size.height,
|
|
134
|
+
aspect: size.width / size.height,
|
|
135
|
+
...(hash ? { hash: hex(await crypto.subtle.digest("SHA-256", await file.arrayBuffer())) } : null),
|
|
136
|
+
};
|
|
137
|
+
} finally {
|
|
138
|
+
// A 24 MP bitmap is about 100 MB; the next file should not wait for the collector.
|
|
139
|
+
bitmap.close();
|
|
140
|
+
}
|
|
141
|
+
}
|
package/src/lib/rich-text-dom.ts
CHANGED
|
@@ -7,8 +7,10 @@ import { normalize, type Span, type Text } from "./rich-text.ts";
|
|
|
7
7
|
|
|
8
8
|
const escape = (s: string) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
9
9
|
|
|
10
|
-
const UNDERLINE = "
|
|
11
|
-
|
|
10
|
+
const UNDERLINE = "link";
|
|
11
|
+
/** Inline code, the same in Code, the editor and the read view. */
|
|
12
|
+
export const CODE_CLASSES = "rounded-small bg-tag-red-bg/70 px-1.5 py-0.5 font-mono text-[0.85em] text-tag-red-ink";
|
|
13
|
+
const CODE = CODE_CLASSES;
|
|
12
14
|
const PAGE_ICON =
|
|
13
15
|
'<svg class="mr-1 mb-0.5 inline size-[1em] text-ink-secondary" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/><path d="M10 9H8"/><path d="M16 13H8"/><path d="M16 17H8"/></svg>';
|
|
14
16
|
|
|
@@ -17,7 +19,7 @@ export function spansToHtml(text: Text): string {
|
|
|
17
19
|
.map((span) => {
|
|
18
20
|
// A page link is one uneditable token, as a Notion mention is.
|
|
19
21
|
if (span.page)
|
|
20
|
-
return `<a data-page="${escape(span.page)}" href="/${escape(span.page)}" contenteditable="false" class="font-medium cursor-pointer rounded-
|
|
22
|
+
return `<a data-page="${escape(span.page)}" href="/${escape(span.page)}" contenteditable="false" class="font-medium cursor-pointer rounded-small hover:bg-tint-hover">${PAGE_ICON}<span class="${UNDERLINE}">${escape(span.text)}</span></a>`;
|
|
21
23
|
let html = escape(span.text);
|
|
22
24
|
if (span.code) html = `<code class="${CODE}">${html}</code>`;
|
|
23
25
|
if (span.strike) html = `<s>${html}</s>`;
|