@kujoforall/paper-ui 0.0.0-stage → 0.2.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 +93 -0
- package/LICENSE +21 -0
- package/README.md +295 -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 +248 -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 +191 -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 +42 -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 +110 -0
- package/dist/components/editor/document-view.js.map +1 -0
- package/dist/components/editor/editor-state.d.ts +107 -0
- package/dist/components/editor/editor-state.d.ts.map +1 -0
- package/dist/components/editor/editor-state.js +217 -0
- package/dist/components/editor/editor-state.js.map +1 -0
- 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 +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 +10 -0
- package/dist/components/editor/index.d.ts.map +1 -0
- package/dist/components/editor/index.js +10 -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/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/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/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.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/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 +26 -0
- package/dist/components/ui/app-shell.d.ts.map +1 -0
- package/dist/components/ui/app-shell.js +71 -0
- package/dist/components/ui/app-shell.js.map +1 -0
- 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 +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/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.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 +15 -0
- package/dist/components/ui/button.d.ts.map +1 -0
- package/dist/components/ui/button.js +110 -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 +65 -0
- package/dist/components/ui/calendar.js.map +1 -0
- package/dist/components/ui/callout.d.ts +32 -0
- package/dist/components/ui/callout.d.ts.map +1 -0
- package/dist/components/ui/callout.js +40 -0
- package/dist/components/ui/callout.js.map +1 -0
- package/dist/components/ui/card.d.ts +18 -0
- package/dist/components/ui/card.d.ts.map +1 -0
- package/dist/components/ui/card.js +28 -0
- package/dist/components/ui/card.js.map +1 -0
- package/dist/components/ui/checkbox.d.ts +11 -0
- package/dist/components/ui/checkbox.d.ts.map +1 -0
- package/dist/components/ui/checkbox.js +30 -0
- package/dist/components/ui/checkbox.js.map +1 -0
- 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 +18 -0
- package/dist/components/ui/command-menu.d.ts.map +1 -0
- package/dist/components/ui/command-menu.js +49 -0
- package/dist/components/ui/command-menu.js.map +1 -0
- 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 +40 -0
- package/dist/components/ui/date-picker.d.ts.map +1 -0
- package/dist/components/ui/date-picker.js +64 -0
- package/dist/components/ui/date-picker.js.map +1 -0
- package/dist/components/ui/date-time-picker.d.ts +21 -0
- package/dist/components/ui/date-time-picker.d.ts.map +1 -0
- package/dist/components/ui/date-time-picker.js +34 -0
- package/dist/components/ui/date-time-picker.js.map +1 -0
- package/dist/components/ui/dialog.d.ts +21 -0
- package/dist/components/ui/dialog.d.ts.map +1 -0
- package/dist/components/ui/dialog.js +63 -0
- package/dist/components/ui/dialog.js.map +1 -0
- 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 +24 -0
- package/dist/components/ui/dropdown-menu.d.ts.map +1 -0
- package/dist/components/ui/dropdown-menu.js +65 -0
- package/dist/components/ui/dropdown-menu.js.map +1 -0
- package/dist/components/ui/editable-text.d.ts +24 -0
- package/dist/components/ui/editable-text.d.ts.map +1 -0
- package/dist/components/ui/editable-text.js +85 -0
- package/dist/components/ui/editable-text.js.map +1 -0
- 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 +15 -0
- package/dist/components/ui/field-button.d.ts.map +1 -0
- package/dist/components/ui/field-button.js +18 -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 +111 -0
- package/dist/components/ui/file-uploader.js.map +1 -0
- 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 +25 -0
- package/dist/components/ui/handle-row.d.ts.map +1 -0
- package/dist/components/ui/handle-row.js +110 -0
- package/dist/components/ui/handle-row.js.map +1 -0
- 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.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 +39 -0
- package/dist/components/ui/image-card.js.map +1 -0
- 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 +31 -0
- package/dist/components/ui/image-viewer.d.ts.map +1 -0
- package/dist/components/ui/image-viewer.js +114 -0
- package/dist/components/ui/image-viewer.js.map +1 -0
- package/dist/components/ui/image.d.ts +33 -0
- package/dist/components/ui/image.d.ts.map +1 -0
- package/dist/components/ui/image.js +61 -0
- package/dist/components/ui/image.js.map +1 -0
- package/dist/components/ui/index.d.ts +92 -0
- package/dist/components/ui/index.d.ts.map +1 -0
- package/dist/components/ui/index.js +92 -0
- package/dist/components/ui/index.js.map +1 -0
- package/dist/components/ui/input.d.ts +75 -0
- package/dist/components/ui/input.d.ts.map +1 -0
- package/dist/components/ui/input.js +245 -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/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.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/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 +16 -0
- package/dist/components/ui/nav-tree.d.ts.map +1 -0
- package/dist/components/ui/nav-tree.js +41 -0
- package/dist/components/ui/nav-tree.js.map +1 -0
- package/dist/components/ui/page.d.ts +23 -0
- package/dist/components/ui/page.d.ts.map +1 -0
- package/dist/components/ui/page.js +28 -0
- package/dist/components/ui/page.js.map +1 -0
- 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 +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 +19 -0
- package/dist/components/ui/progress.d.ts.map +1 -0
- package/dist/components/ui/progress.js +22 -0
- package/dist/components/ui/progress.js.map +1 -0
- package/dist/components/ui/property.d.ts +11 -0
- package/dist/components/ui/property.d.ts.map +1 -0
- package/dist/components/ui/property.js +18 -0
- package/dist/components/ui/property.js.map +1 -0
- 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 +21 -0
- package/dist/components/ui/segmented.d.ts.map +1 -0
- package/dist/components/ui/segmented.js +12 -0
- package/dist/components/ui/segmented.js.map +1 -0
- package/dist/components/ui/select-menu.d.ts +12 -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 +16 -0
- package/dist/components/ui/select.d.ts.map +1 -0
- package/dist/components/ui/select.js +45 -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/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 +23 -0
- package/dist/components/ui/spotlight.d.ts.map +1 -0
- package/dist/components/ui/spotlight.js +110 -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/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 +16 -0
- package/dist/components/ui/table.d.ts.map +1 -0
- package/dist/components/ui/table.js +76 -0
- package/dist/components/ui/table.js.map +1 -0
- 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 +16 -0
- package/dist/components/ui/theme-toggle.d.ts.map +1 -0
- package/dist/components/ui/theme-toggle.js +65 -0
- package/dist/components/ui/theme-toggle.js.map +1 -0
- 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 +47 -0
- package/dist/components/ui/time-picker.d.ts.map +1 -0
- package/dist/components/ui/time-picker.js +141 -0
- package/dist/components/ui/time-picker.js.map +1 -0
- 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 +15 -0
- package/dist/components/ui/tooltip.d.ts.map +1 -0
- package/dist/components/ui/tooltip.js +32 -0
- package/dist/components/ui/tooltip.js.map +1 -0
- 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 +40 -0
- package/dist/components/ui/typography.d.ts.map +1 -0
- package/dist/components/ui/typography.js +98 -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 +22 -0
- package/dist/components/ui/video-block.js.map +1 -0
- 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 +13 -0
- package/dist/hooks/use-save-queue.d.ts.map +1 -0
- package/dist/hooks/use-save-queue.js +57 -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 +52 -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/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 +30 -0
- package/dist/lib/dates.d.ts.map +1 -0
- package/dist/lib/dates.js +61 -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/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 +16 -0
- package/dist/lib/rich-text-dom.d.ts.map +1 -0
- package/dist/lib/rich-text-dom.js +145 -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/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/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 +24 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/styles/notion.css +817 -0
- package/package.json +129 -5
- package/src/components/editor/block-text.tsx +271 -0
- package/src/components/editor/blocks.tsx +373 -0
- package/src/components/editor/document-editor.tsx +106 -0
- package/src/components/editor/document-view.tsx +205 -0
- package/src/components/editor/editor-state.tsx +298 -0
- package/src/components/editor/extensions/kit-blocks.tsx +452 -0
- package/src/components/editor/extensions/spoiler.tsx +81 -0
- package/src/components/editor/index.ts +10 -0
- package/src/components/editor/kinds.ts +158 -0
- package/src/components/editor/look.tsx +36 -0
- package/src/components/sketch/rough.tsx +90 -0
- package/src/components/three/model-viewer.tsx +514 -0
- package/src/components/ui/accent-picker.tsx +72 -0
- package/src/components/ui/address-field.tsx +57 -0
- 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 +140 -0
- package/src/components/ui/avatar.tsx +106 -0
- package/src/components/ui/badge.tsx +81 -0
- package/src/components/ui/banner.tsx +53 -0
- package/src/components/ui/breadcrumbs.tsx +25 -0
- package/src/components/ui/button.tsx +147 -0
- package/src/components/ui/calendar.tsx +101 -0
- package/src/components/ui/callout.tsx +61 -0
- package/src/components/ui/card.tsx +59 -0
- package/src/components/ui/checkbox.tsx +66 -0
- 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 +102 -0
- 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 +208 -0
- package/src/components/ui/date-time-picker.tsx +123 -0
- package/src/components/ui/dialog.tsx +151 -0
- package/src/components/ui/document-layout.tsx +52 -0
- package/src/components/ui/dropdown-menu.tsx +185 -0
- package/src/components/ui/editable-text.tsx +142 -0
- 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 +70 -0
- package/src/components/ui/file-preview.tsx +80 -0
- package/src/components/ui/file-uploader.tsx +375 -0
- 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 +252 -0
- 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 +238 -0
- package/src/components/ui/image-card.tsx +95 -0
- package/src/components/ui/image-framer.tsx +160 -0
- package/src/components/ui/image-viewer.tsx +230 -0
- package/src/components/ui/image.tsx +200 -0
- package/src/components/ui/index.ts +178 -0
- package/src/components/ui/input.tsx +471 -0
- package/src/components/ui/link-block.tsx +85 -0
- package/src/components/ui/list-detail.tsx +115 -0
- package/src/components/ui/listbox.ts +26 -0
- package/src/components/ui/mac-card.tsx +46 -0
- 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 +92 -0
- package/src/components/ui/page.tsx +73 -0
- package/src/components/ui/pagination.tsx +143 -0
- package/src/components/ui/picker-panel.tsx +69 -0
- package/src/components/ui/popover.tsx +42 -0
- package/src/components/ui/progress.tsx +76 -0
- package/src/components/ui/property.tsx +33 -0
- 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 +74 -0
- package/src/components/ui/select-menu.tsx +54 -0
- package/src/components/ui/select.tsx +147 -0
- package/src/components/ui/selection-bar.tsx +50 -0
- package/src/components/ui/separator.tsx +30 -0
- 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 +222 -0
- package/src/components/ui/stat-tile.tsx +25 -0
- package/src/components/ui/step-dialog.tsx +104 -0
- package/src/components/ui/steps-layout.tsx +91 -0
- package/src/components/ui/switch.tsx +55 -0
- package/src/components/ui/table.tsx +99 -0
- package/src/components/ui/tabs.tsx +41 -0
- package/src/components/ui/theme-toggle.tsx +80 -0
- package/src/components/ui/time-list.tsx +106 -0
- package/src/components/ui/time-picker.tsx +344 -0
- package/src/components/ui/toast.tsx +132 -0
- package/src/components/ui/toggle.tsx +76 -0
- package/src/components/ui/tooltip.tsx +78 -0
- package/src/components/ui/top-bar.tsx +118 -0
- package/src/components/ui/typography.tsx +204 -0
- package/src/components/ui/video-block.tsx +66 -0
- 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 +78 -0
- package/src/hooks/use-selection.ts +51 -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/database.ts +322 -0
- package/src/lib/dates.ts +75 -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/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 +138 -0
- package/src/lib/rich-text.ts +50 -0
- package/src/lib/spotlight.ts +78 -0
- package/src/lib/theme.ts +18 -0
- package/src/lib/time.ts +83 -0
- package/src/lib/tree.ts +41 -0
- package/src/lib/utils.ts +25 -0
- package/src/styles/notion.css +817 -0
|
@@ -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
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/* Dates and times as the strings a form holds: `YYYY-MM-DD`, `HH:MM`, and the two
|
|
2
|
+
joined by a `T`. They are calendar values, not instants, so nothing here goes
|
|
3
|
+
through UTC: `new Date("2027-01-12")` is midnight in Greenwich, which is the day
|
|
4
|
+
before for anyone west of it. */
|
|
5
|
+
|
|
6
|
+
const pad = (n: number): string => String(n).padStart(2, "0");
|
|
7
|
+
|
|
8
|
+
export function toISODate(date: Date): string {
|
|
9
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** The local day a `YYYY-MM-DD` names, or undefined if it names none (30 February). */
|
|
13
|
+
export function fromISODate(value: string | null | undefined): Date | undefined {
|
|
14
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value ?? "");
|
|
15
|
+
if (match === null) return undefined;
|
|
16
|
+
const date = new Date(Number(match[1]), Number(match[2]) - 1, Number(match[3]));
|
|
17
|
+
return toISODate(date) === value ? date : undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function isTime(value: string | null | undefined): value is string {
|
|
21
|
+
return /^([01]\d|2[0-3]):[0-5]\d$/.test(value ?? "");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Splits `YYYY-MM-DDTHH:MM`; either half is null when it is missing or wrong. */
|
|
25
|
+
export function splitDateTime(value: string | null | undefined): { date: string | null; time: string | null } {
|
|
26
|
+
const [date = "", time = ""] = (value ?? "").split("T");
|
|
27
|
+
return {
|
|
28
|
+
date: fromISODate(date) === undefined ? null : date,
|
|
29
|
+
time: isTime(time.slice(0, 5)) ? time.slice(0, 5) : null,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const DAY = new Intl.DateTimeFormat("en-GB", { weekday: "short", day: "numeric", month: "short", year: "numeric" });
|
|
34
|
+
const SHORT_DAY = new Intl.DateTimeFormat("en-GB", { day: "numeric", month: "short", year: "numeric" });
|
|
35
|
+
|
|
36
|
+
/** "Sun 27 Dec 2026" */
|
|
37
|
+
export const formatDay = (date: Date): string => DAY.format(date).replace(",", "");
|
|
38
|
+
/** "27 Dec 2026" */
|
|
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
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Text } from "./rich-text.ts";
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* A document as data: Notion's blocks, nested where Notion nests them. Plain
|
|
5
|
+
* JSON, so an app stores it whole and validates it on its server; the editor in
|
|
6
|
+
* components/editor edits exactly this shape.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** Every block has an id the editor chose, so one can be focused before it is saved. */
|
|
10
|
+
type Id = { id: number };
|
|
11
|
+
|
|
12
|
+
export type Block = Id &
|
|
13
|
+
(
|
|
14
|
+
| { type: "paragraph"; text: Text }
|
|
15
|
+
| { type: "heading"; level: 1 | 2 | 3; text: Text }
|
|
16
|
+
| { type: "bullet" | "numbered"; text: Text; children: Block[] }
|
|
17
|
+
| { type: "check"; checked: boolean; text: Text; children: Block[] }
|
|
18
|
+
| { type: "quote"; text: Text }
|
|
19
|
+
| { type: "divider" }
|
|
20
|
+
/**
|
|
21
|
+
* A picture. `src` is what the browser loads; `ref` is the owner's own name
|
|
22
|
+
* for an uploaded one (its id in the owner's store), kept beside it so the
|
|
23
|
+
* owner can tell which uploads a document still uses. `width` is the share
|
|
24
|
+
* of the column; `aspect` holds the shape so nothing moves while it loads.
|
|
25
|
+
*/
|
|
26
|
+
| { type: "image"; src?: string; ref?: string; aspect?: number; caption: Text; width: number }
|
|
27
|
+
/** A YouTube or Vimeo video, played in place. Empty until a link is given. */
|
|
28
|
+
| { type: "video"; url: string; caption: Text }
|
|
29
|
+
/** A web page as a card, with a name the writer types. */
|
|
30
|
+
| { type: "bookmark"; url: string; title: string }
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A block an app adds through a BlockExtension (components/editor): its own
|
|
35
|
+
* `type`, and whatever fields it needs. One with `text` is written in like a
|
|
36
|
+
* paragraph; one with `children` holds blocks; one with neither is picked whole.
|
|
37
|
+
*/
|
|
38
|
+
export type CustomBlock = { id: number; type: string; text?: Text; children?: AnyBlock[]; [field: string]: unknown };
|
|
39
|
+
|
|
40
|
+
/** What a document holds: the kit's blocks and any an app adds. */
|
|
41
|
+
export type AnyBlock = Block | CustomBlock;
|
|
42
|
+
|
|
43
|
+
/** List items nest under one another and run together as one list. */
|
|
44
|
+
export const LISTS = ["bullet", "numbered", "check"] as const;
|
|
45
|
+
export const isListType = (type: string): boolean => (LISTS as readonly string[]).includes(type);
|
|
46
|
+
|
|
47
|
+
/** The kinds that hold children. */
|
|
48
|
+
export const nests = (type: string): boolean => isListType(type);
|
|
49
|
+
|
|
50
|
+
/** Whether `child` may sit inside `parent`. Lists hold list items. */
|
|
51
|
+
export const holds = (parent: string, child: string): boolean => isListType(parent) && isListType(child);
|
|
52
|
+
|
|
53
|
+
/** Kinds without words: picked as a whole in the editor rather than given a caret. */
|
|
54
|
+
export const WHOLE = ["divider", "image", "video", "bookmark"] as const;
|
|
55
|
+
export const isWhole = (type: string): boolean => (WHOLE as readonly string[]).includes(type);
|
package/src/lib/embed.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/* Addresses for things embedded in a document: what counts as a web address, and
|
|
2
|
+
where a video link plays. Pure, so a server can check what a browser sends with
|
|
3
|
+
the same rules. */
|
|
4
|
+
|
|
5
|
+
/** A web address. Anything else, `javascript:` above all, is refused. */
|
|
6
|
+
export function isWebUrl(value: string): boolean {
|
|
7
|
+
if (!/^https?:\/\//i.test(value)) return false;
|
|
8
|
+
try {
|
|
9
|
+
new URL(value);
|
|
10
|
+
return true;
|
|
11
|
+
} catch {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** A link in text a reader may follow: a web or mail address. Never `javascript:` or `data:`. */
|
|
17
|
+
export function isSafeHref(value: string): boolean {
|
|
18
|
+
return /^mailto:/i.test(value) || isWebUrl(value);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The site a link is on, for showing in place of a missing name. */
|
|
22
|
+
export function hostOf(url: string): string {
|
|
23
|
+
try {
|
|
24
|
+
return new URL(url).hostname.replace(/^www\./, "");
|
|
25
|
+
} catch {
|
|
26
|
+
return url;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** "1h2m3s", "90s" or "90" as seconds. */
|
|
31
|
+
function seconds(t: string | null): number | null {
|
|
32
|
+
const m = t?.match(/^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s?)?$/);
|
|
33
|
+
if (!m || !t) return null;
|
|
34
|
+
return Number(m[1] ?? 0) * 3600 + Number(m[2] ?? 0) * 60 + Number(m[3] ?? 0);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Where a YouTube or Vimeo link plays, or null when it is not one. YouTube is
|
|
39
|
+
* embedded from its privacy-enhanced domain, which sets no cookie until the video
|
|
40
|
+
* is played, and Vimeo is asked not to track. A start time in a YouTube link
|
|
41
|
+
* (`t=`) is kept.
|
|
42
|
+
*/
|
|
43
|
+
export function videoEmbed(url: string): string | null {
|
|
44
|
+
if (!isWebUrl(url)) return null;
|
|
45
|
+
const u = new URL(url);
|
|
46
|
+
const host = u.hostname.replace(/^(www|m|music)\./, "");
|
|
47
|
+
if (host === "vimeo.com") {
|
|
48
|
+
const id = u.pathname.match(/^\/(\d+)/)?.[1];
|
|
49
|
+
return id === undefined ? null : `https://player.vimeo.com/video/${id}?dnt=1`;
|
|
50
|
+
}
|
|
51
|
+
const id =
|
|
52
|
+
host === "youtu.be"
|
|
53
|
+
? u.pathname.slice(1)
|
|
54
|
+
: host === "youtube.com"
|
|
55
|
+
? u.pathname === "/watch"
|
|
56
|
+
? u.searchParams.get("v")
|
|
57
|
+
: (u.pathname.match(/^\/(?:shorts|embed|live)\/([\w-]+)/)?.[1] ?? null)
|
|
58
|
+
: null;
|
|
59
|
+
if (!id || !/^[\w-]{6,}$/.test(id)) return null;
|
|
60
|
+
const start = seconds(u.searchParams.get("t") ?? u.searchParams.get("start"));
|
|
61
|
+
return `https://www.youtube-nocookie.com/embed/${id}${start ? `?start=${start}` : ""}`;
|
|
62
|
+
}
|
package/src/lib/files.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/* Getting files from a person: the system's chooser, a whole folder, or a
|
|
2
|
+
drop. And sending one with progress, which `fetch` cannot report. */
|
|
3
|
+
|
|
4
|
+
const byName = (files: File[]): File[] => files.sort((a, b) => a.name.localeCompare(b.name, undefined, { numeric: true }));
|
|
5
|
+
|
|
6
|
+
/** The system dialog for files (or one, with `single`), or for a whole folder. Built on demand: nothing in the page needs to own an <input>. */
|
|
7
|
+
export function pickFiles(onPicked: (files: File[]) => void, options: { folder?: boolean; accept?: string; single?: boolean } = {}): void {
|
|
8
|
+
const input = document.createElement("input");
|
|
9
|
+
input.type = "file";
|
|
10
|
+
input.multiple = !options.single;
|
|
11
|
+
if (options.folder) input.webkitdirectory = true;
|
|
12
|
+
else if (options.accept !== undefined) input.accept = options.accept;
|
|
13
|
+
input.onchange = () => onPicked(byName([...(input.files ?? [])]));
|
|
14
|
+
input.click();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const fileOf = (entry: FileSystemFileEntry): Promise<File> => new Promise((resolve, reject) => entry.file(resolve, reject));
|
|
18
|
+
|
|
19
|
+
async function childrenOf(directory: FileSystemDirectoryEntry): Promise<FileSystemEntry[]> {
|
|
20
|
+
const reader = directory.createReader();
|
|
21
|
+
const all: FileSystemEntry[] = [];
|
|
22
|
+
// readEntries hands back a page at a time and signals the end with an empty one.
|
|
23
|
+
for (;;) {
|
|
24
|
+
const page = await new Promise<FileSystemEntry[]>((resolve, reject) => reader.readEntries(resolve, reject));
|
|
25
|
+
if (page.length === 0) return all;
|
|
26
|
+
all.push(...page);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function walk(entry: FileSystemEntry, into: File[]): Promise<void> {
|
|
31
|
+
if (entry.isFile) into.push(await fileOf(entry as FileSystemFileEntry));
|
|
32
|
+
else if (entry.isDirectory) for (const child of await childrenOf(entry as FileSystemDirectoryEntry)) await walk(child, into);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Everything in a drop: loose files as they are, folders walked to their leaves. Call it in the drop handler itself. */
|
|
36
|
+
export async function filesFromDrop(data: DataTransfer): Promise<File[]> {
|
|
37
|
+
// The entries must be taken synchronously; the list is emptied once the event returns.
|
|
38
|
+
const dropped = [...data.items].map((item) => ({ entry: item.webkitGetAsEntry(), file: item.getAsFile() }));
|
|
39
|
+
const files: File[] = [];
|
|
40
|
+
for (const { entry, file } of dropped) {
|
|
41
|
+
if (entry?.isDirectory) await walk(entry, files);
|
|
42
|
+
else if (file !== null) files.push(file);
|
|
43
|
+
}
|
|
44
|
+
return byName(files);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** True for a drag that is carrying files, as opposed to text or an element of the page. */
|
|
48
|
+
export const carriesFiles = (event: { dataTransfer: DataTransfer | null }): boolean => event.dataTransfer?.types.includes("Files") ?? false;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* One request with upload progress, 0 to 1. Resolves with the status and the
|
|
52
|
+
* parsed JSON body whatever the status; rejects only when the connection
|
|
53
|
+
* fails, which is the case worth retrying. `headers` are sent as given: a
|
|
54
|
+
* custom one is how a server tells this from another site's form.
|
|
55
|
+
*/
|
|
56
|
+
export function sendWithProgress(
|
|
57
|
+
method: string,
|
|
58
|
+
url: string,
|
|
59
|
+
body: Blob | FormData,
|
|
60
|
+
onProgress: (progress: number) => void,
|
|
61
|
+
headers: Record<string, string> = {},
|
|
62
|
+
): Promise<{ status: number; body: unknown }> {
|
|
63
|
+
return new Promise((resolve, reject) => {
|
|
64
|
+
const xhr = new XMLHttpRequest();
|
|
65
|
+
xhr.open(method, url);
|
|
66
|
+
for (const [name, value] of Object.entries(headers)) xhr.setRequestHeader(name, value);
|
|
67
|
+
xhr.responseType = "json";
|
|
68
|
+
xhr.upload.onprogress = (event) => event.lengthComputable && onProgress(event.loaded / event.total);
|
|
69
|
+
xhr.onload = () => resolve({ status: xhr.status, body: xhr.response });
|
|
70
|
+
xhr.onerror = xhr.ontimeout = xhr.onabort = () => reject(new Error("The connection was lost"));
|
|
71
|
+
xhr.send(body);
|
|
72
|
+
});
|
|
73
|
+
}
|