@kujoforall/paper-ui 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/LICENSE +21 -0
- package/README.md +252 -2
- package/dist/components/editor/block-text.d.ts +8 -0
- package/dist/components/editor/block-text.d.ts.map +1 -0
- package/dist/components/editor/block-text.js +213 -0
- package/dist/components/editor/block-text.js.map +1 -0
- package/dist/components/editor/blocks.d.ts +33 -0
- package/dist/components/editor/blocks.d.ts.map +1 -0
- package/dist/components/editor/blocks.js +187 -0
- package/dist/components/editor/blocks.js.map +1 -0
- package/dist/components/editor/document-editor.d.ts +27 -0
- package/dist/components/editor/document-editor.d.ts.map +1 -0
- package/dist/components/editor/document-editor.js +40 -0
- package/dist/components/editor/document-editor.js.map +1 -0
- package/dist/components/editor/document-view.d.ts +22 -0
- package/dist/components/editor/document-view.d.ts.map +1 -0
- package/dist/components/editor/document-view.js +105 -0
- package/dist/components/editor/document-view.js.map +1 -0
- package/dist/components/editor/editor-state.d.ts +100 -0
- package/dist/components/editor/editor-state.d.ts.map +1 -0
- package/dist/components/editor/editor-state.js +192 -0
- package/dist/components/editor/editor-state.js.map +1 -0
- package/dist/components/editor/extensions/spoiler.d.ts +8 -0
- package/dist/components/editor/extensions/spoiler.d.ts.map +1 -0
- package/dist/components/editor/extensions/spoiler.js +36 -0
- package/dist/components/editor/extensions/spoiler.js.map +1 -0
- package/dist/components/editor/index.d.ts +9 -0
- package/dist/components/editor/index.d.ts.map +1 -0
- package/dist/components/editor/index.js +9 -0
- package/dist/components/editor/index.js.map +1 -0
- package/dist/components/editor/kinds.d.ts +99 -0
- package/dist/components/editor/kinds.d.ts.map +1 -0
- package/dist/components/editor/kinds.js +74 -0
- package/dist/components/editor/kinds.js.map +1 -0
- package/dist/components/sketch/rough.d.ts +38 -0
- package/dist/components/sketch/rough.d.ts.map +1 -0
- package/dist/components/sketch/rough.js +57 -0
- package/dist/components/sketch/rough.js.map +1 -0
- package/dist/components/ui/accent-picker.d.ts +2 -0
- package/dist/components/ui/accent-picker.d.ts.map +1 -0
- package/dist/components/ui/accent-picker.js +44 -0
- package/dist/components/ui/accent-picker.js.map +1 -0
- package/dist/components/ui/address-field.d.ts +10 -0
- package/dist/components/ui/address-field.d.ts.map +1 -0
- package/dist/components/ui/address-field.js +24 -0
- package/dist/components/ui/address-field.js.map +1 -0
- package/dist/components/ui/app-shell.d.ts +25 -0
- package/dist/components/ui/app-shell.d.ts.map +1 -0
- package/dist/components/ui/app-shell.js +69 -0
- package/dist/components/ui/app-shell.js.map +1 -0
- package/dist/components/ui/badge.d.ts +19 -0
- package/dist/components/ui/badge.d.ts.map +1 -0
- package/dist/components/ui/badge.js +62 -0
- package/dist/components/ui/badge.js.map +1 -0
- package/dist/components/ui/breadcrumbs.d.ts +10 -0
- package/dist/components/ui/breadcrumbs.d.ts.map +1 -0
- package/dist/components/ui/breadcrumbs.js +9 -0
- package/dist/components/ui/breadcrumbs.js.map +1 -0
- package/dist/components/ui/button.d.ts +13 -0
- package/dist/components/ui/button.d.ts.map +1 -0
- package/dist/components/ui/button.js +45 -0
- package/dist/components/ui/button.js.map +1 -0
- package/dist/components/ui/calendar.d.ts +5 -0
- package/dist/components/ui/calendar.d.ts.map +1 -0
- package/dist/components/ui/calendar.js +64 -0
- package/dist/components/ui/calendar.js.map +1 -0
- package/dist/components/ui/callout.d.ts +13 -0
- package/dist/components/ui/callout.d.ts.map +1 -0
- package/dist/components/ui/callout.js +27 -0
- package/dist/components/ui/callout.js.map +1 -0
- package/dist/components/ui/card.d.ts +13 -0
- package/dist/components/ui/card.d.ts.map +1 -0
- package/dist/components/ui/card.js +27 -0
- package/dist/components/ui/card.js.map +1 -0
- package/dist/components/ui/checkbox.d.ts +6 -0
- package/dist/components/ui/checkbox.d.ts.map +1 -0
- package/dist/components/ui/checkbox.js +10 -0
- package/dist/components/ui/checkbox.js.map +1 -0
- package/dist/components/ui/command-menu.d.ts +15 -0
- package/dist/components/ui/command-menu.d.ts.map +1 -0
- package/dist/components/ui/command-menu.js +24 -0
- package/dist/components/ui/command-menu.js.map +1 -0
- package/dist/components/ui/date-picker.d.ts +35 -0
- package/dist/components/ui/date-picker.d.ts.map +1 -0
- package/dist/components/ui/date-picker.js +56 -0
- package/dist/components/ui/date-picker.js.map +1 -0
- package/dist/components/ui/date-time-picker.d.ts +19 -0
- package/dist/components/ui/date-time-picker.d.ts.map +1 -0
- package/dist/components/ui/date-time-picker.js +32 -0
- package/dist/components/ui/date-time-picker.js.map +1 -0
- package/dist/components/ui/dialog.d.ts +17 -0
- package/dist/components/ui/dialog.d.ts.map +1 -0
- package/dist/components/ui/dialog.js +33 -0
- package/dist/components/ui/dialog.js.map +1 -0
- package/dist/components/ui/dropdown-menu.d.ts +20 -0
- package/dist/components/ui/dropdown-menu.d.ts.map +1 -0
- package/dist/components/ui/dropdown-menu.js +56 -0
- package/dist/components/ui/dropdown-menu.js.map +1 -0
- package/dist/components/ui/editable-text.d.ts +17 -0
- package/dist/components/ui/editable-text.d.ts.map +1 -0
- package/dist/components/ui/editable-text.js +68 -0
- package/dist/components/ui/editable-text.js.map +1 -0
- package/dist/components/ui/field-button.d.ts +14 -0
- package/dist/components/ui/field-button.d.ts.map +1 -0
- package/dist/components/ui/field-button.js +16 -0
- package/dist/components/ui/field-button.js.map +1 -0
- package/dist/components/ui/file-preview.d.ts +5 -0
- package/dist/components/ui/file-preview.d.ts.map +1 -0
- package/dist/components/ui/file-preview.js +66 -0
- package/dist/components/ui/file-preview.js.map +1 -0
- package/dist/components/ui/file-uploader.d.ts +39 -0
- package/dist/components/ui/file-uploader.d.ts.map +1 -0
- package/dist/components/ui/file-uploader.js +110 -0
- package/dist/components/ui/file-uploader.js.map +1 -0
- package/dist/components/ui/handle-row.d.ts +15 -0
- package/dist/components/ui/handle-row.d.ts.map +1 -0
- package/dist/components/ui/handle-row.js +41 -0
- package/dist/components/ui/handle-row.js.map +1 -0
- package/dist/components/ui/image-block.d.ts +31 -0
- package/dist/components/ui/image-block.d.ts.map +1 -0
- package/dist/components/ui/image-block.js +103 -0
- package/dist/components/ui/image-block.js.map +1 -0
- package/dist/components/ui/image-card.d.ts +17 -0
- package/dist/components/ui/image-card.d.ts.map +1 -0
- package/dist/components/ui/image-card.js +38 -0
- package/dist/components/ui/image-card.js.map +1 -0
- package/dist/components/ui/image-viewer.d.ts +31 -0
- package/dist/components/ui/image-viewer.d.ts.map +1 -0
- package/dist/components/ui/image-viewer.js +81 -0
- package/dist/components/ui/image-viewer.js.map +1 -0
- package/dist/components/ui/image.d.ts +11 -0
- package/dist/components/ui/image.d.ts.map +1 -0
- package/dist/components/ui/image.js +32 -0
- package/dist/components/ui/image.js.map +1 -0
- package/dist/components/ui/index.d.ts +49 -0
- package/dist/components/ui/index.d.ts.map +1 -0
- package/dist/components/ui/index.js +49 -0
- package/dist/components/ui/index.js.map +1 -0
- package/dist/components/ui/input.d.ts +16 -0
- package/dist/components/ui/input.d.ts.map +1 -0
- package/dist/components/ui/input.js +32 -0
- package/dist/components/ui/input.js.map +1 -0
- package/dist/components/ui/link-block.d.ts +13 -0
- package/dist/components/ui/link-block.d.ts.map +1 -0
- package/dist/components/ui/link-block.js +21 -0
- package/dist/components/ui/link-block.js.map +1 -0
- package/dist/components/ui/mac-card.d.ts +15 -0
- package/dist/components/ui/mac-card.d.ts.map +1 -0
- package/dist/components/ui/mac-card.js +9 -0
- package/dist/components/ui/mac-card.js.map +1 -0
- package/dist/components/ui/nav-tree.d.ts +16 -0
- package/dist/components/ui/nav-tree.d.ts.map +1 -0
- package/dist/components/ui/nav-tree.js +34 -0
- package/dist/components/ui/nav-tree.js.map +1 -0
- package/dist/components/ui/page.d.ts +12 -0
- package/dist/components/ui/page.d.ts.map +1 -0
- package/dist/components/ui/page.js +15 -0
- package/dist/components/ui/page.js.map +1 -0
- package/dist/components/ui/popover.d.ts +8 -0
- package/dist/components/ui/popover.d.ts.map +1 -0
- package/dist/components/ui/popover.js +18 -0
- package/dist/components/ui/popover.js.map +1 -0
- package/dist/components/ui/progress.d.ts +9 -0
- package/dist/components/ui/progress.d.ts.map +1 -0
- package/dist/components/ui/progress.js +9 -0
- package/dist/components/ui/progress.js.map +1 -0
- package/dist/components/ui/property.d.ts +15 -0
- package/dist/components/ui/property.d.ts.map +1 -0
- package/dist/components/ui/property.js +34 -0
- package/dist/components/ui/property.js.map +1 -0
- package/dist/components/ui/segmented.d.ts +13 -0
- package/dist/components/ui/segmented.d.ts.map +1 -0
- package/dist/components/ui/segmented.js +10 -0
- package/dist/components/ui/segmented.js.map +1 -0
- package/dist/components/ui/select-menu.d.ts +10 -0
- package/dist/components/ui/select-menu.d.ts.map +1 -0
- package/dist/components/ui/select-menu.js +10 -0
- package/dist/components/ui/select-menu.js.map +1 -0
- package/dist/components/ui/select.d.ts +11 -0
- package/dist/components/ui/select.d.ts.map +1 -0
- package/dist/components/ui/select.js +31 -0
- package/dist/components/ui/select.js.map +1 -0
- package/dist/components/ui/selection-bar.d.ts +12 -0
- package/dist/components/ui/selection-bar.d.ts.map +1 -0
- package/dist/components/ui/selection-bar.js +15 -0
- package/dist/components/ui/selection-bar.js.map +1 -0
- package/dist/components/ui/separator.d.ts +4 -0
- package/dist/components/ui/separator.d.ts.map +1 -0
- package/dist/components/ui/separator.js +12 -0
- package/dist/components/ui/separator.js.map +1 -0
- package/dist/components/ui/spotlight.d.ts +23 -0
- package/dist/components/ui/spotlight.d.ts.map +1 -0
- package/dist/components/ui/spotlight.js +107 -0
- package/dist/components/ui/spotlight.js.map +1 -0
- package/dist/components/ui/stat-tile.d.ts +8 -0
- package/dist/components/ui/stat-tile.d.ts.map +1 -0
- package/dist/components/ui/stat-tile.js +9 -0
- package/dist/components/ui/stat-tile.js.map +1 -0
- package/dist/components/ui/step-dialog.d.ts +20 -0
- package/dist/components/ui/step-dialog.d.ts.map +1 -0
- package/dist/components/ui/step-dialog.js +36 -0
- package/dist/components/ui/step-dialog.js.map +1 -0
- package/dist/components/ui/table.d.ts +8 -0
- package/dist/components/ui/table.d.ts.map +1 -0
- package/dist/components/ui/table.js +23 -0
- package/dist/components/ui/table.js.map +1 -0
- package/dist/components/ui/theme-toggle.d.ts +2 -0
- package/dist/components/ui/theme-toggle.d.ts.map +1 -0
- package/dist/components/ui/theme-toggle.js +49 -0
- package/dist/components/ui/theme-toggle.js.map +1 -0
- package/dist/components/ui/time-picker.d.ts +21 -0
- package/dist/components/ui/time-picker.d.ts.map +1 -0
- package/dist/components/ui/time-picker.js +63 -0
- package/dist/components/ui/time-picker.js.map +1 -0
- package/dist/components/ui/tooltip.d.ts +15 -0
- package/dist/components/ui/tooltip.d.ts.map +1 -0
- package/dist/components/ui/tooltip.js +21 -0
- package/dist/components/ui/tooltip.js.map +1 -0
- package/dist/components/ui/typography.d.ts +34 -0
- package/dist/components/ui/typography.d.ts.map +1 -0
- package/dist/components/ui/typography.js +72 -0
- package/dist/components/ui/typography.js.map +1 -0
- package/dist/components/ui/video-block.d.ts +14 -0
- package/dist/components/ui/video-block.d.ts.map +1 -0
- package/dist/components/ui/video-block.js +18 -0
- package/dist/components/ui/video-block.js.map +1 -0
- package/dist/hooks/use-save-queue.d.ts +13 -0
- package/dist/hooks/use-save-queue.d.ts.map +1 -0
- package/dist/hooks/use-save-queue.js +45 -0
- package/dist/hooks/use-save-queue.js.map +1 -0
- package/dist/hooks/use-selection.d.ts +10 -0
- package/dist/hooks/use-selection.d.ts.map +1 -0
- package/dist/hooks/use-selection.js +43 -0
- package/dist/hooks/use-selection.js.map +1 -0
- package/dist/hooks/use-shared-transition.d.ts +3 -0
- package/dist/hooks/use-shared-transition.d.ts.map +1 -0
- package/dist/hooks/use-shared-transition.js +38 -0
- package/dist/hooks/use-shared-transition.js.map +1 -0
- package/dist/hooks/use-upload-queue.d.ts +22 -0
- package/dist/hooks/use-upload-queue.d.ts.map +1 -0
- package/dist/hooks/use-upload-queue.js +78 -0
- package/dist/hooks/use-upload-queue.js.map +1 -0
- package/dist/lib/accent.d.ts +5 -0
- package/dist/lib/accent.d.ts.map +1 -0
- package/dist/lib/accent.js +10 -0
- package/dist/lib/accent.js.map +1 -0
- package/dist/lib/bento.d.ts +17 -0
- package/dist/lib/bento.d.ts.map +1 -0
- package/dist/lib/bento.js +92 -0
- package/dist/lib/bento.js.map +1 -0
- package/dist/lib/dates.d.ts +14 -0
- package/dist/lib/dates.d.ts.map +1 -0
- package/dist/lib/dates.js +34 -0
- package/dist/lib/dates.js.map +1 -0
- package/dist/lib/document.d.ts +79 -0
- package/dist/lib/document.d.ts.map +1 -0
- package/dist/lib/document.js +11 -0
- package/dist/lib/document.js.map +1 -0
- package/dist/lib/embed.d.ts +14 -0
- package/dist/lib/embed.d.ts.map +1 -0
- package/dist/lib/embed.js +63 -0
- package/dist/lib/embed.js.map +1 -0
- package/dist/lib/files.d.ts +23 -0
- package/dist/lib/files.d.ts.map +1 -0
- package/dist/lib/files.js +69 -0
- package/dist/lib/files.js.map +1 -0
- package/dist/lib/justified.d.ts +50 -0
- package/dist/lib/justified.d.ts.map +1 -0
- package/dist/lib/justified.js +78 -0
- package/dist/lib/justified.js.map +1 -0
- package/dist/lib/rich-text-dom.d.ts +14 -0
- package/dist/lib/rich-text-dom.d.ts.map +1 -0
- package/dist/lib/rich-text-dom.js +143 -0
- package/dist/lib/rich-text-dom.js.map +1 -0
- package/dist/lib/rich-text.d.ts +15 -0
- package/dist/lib/rich-text.d.ts.map +1 -0
- package/dist/lib/rich-text.js +35 -0
- package/dist/lib/rich-text.js.map +1 -0
- package/dist/lib/spotlight.d.ts +22 -0
- package/dist/lib/spotlight.d.ts.map +1 -0
- package/dist/lib/spotlight.js +66 -0
- package/dist/lib/spotlight.js.map +1 -0
- package/dist/lib/tree.d.ts +17 -0
- package/dist/lib/tree.d.ts.map +1 -0
- package/dist/lib/tree.js +35 -0
- package/dist/lib/tree.js.map +1 -0
- package/dist/lib/utils.d.ts +3 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +6 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/styles/notion.css +526 -0
- package/package.json +106 -5
- package/src/components/editor/block-text.tsx +230 -0
- package/src/components/editor/blocks.tsx +368 -0
- package/src/components/editor/document-editor.tsx +101 -0
- package/src/components/editor/document-view.tsx +192 -0
- package/src/components/editor/editor-state.tsx +270 -0
- package/src/components/editor/extensions/spoiler.tsx +76 -0
- package/src/components/editor/index.ts +9 -0
- package/src/components/editor/kinds.ts +158 -0
- package/src/components/sketch/rough.tsx +90 -0
- package/src/components/ui/accent-picker.tsx +72 -0
- package/src/components/ui/address-field.tsx +57 -0
- package/src/components/ui/app-shell.tsx +138 -0
- package/src/components/ui/badge.tsx +81 -0
- package/src/components/ui/breadcrumbs.tsx +25 -0
- package/src/components/ui/button.tsx +73 -0
- package/src/components/ui/calendar.tsx +100 -0
- package/src/components/ui/callout.tsx +62 -0
- package/src/components/ui/card.tsx +90 -0
- package/src/components/ui/checkbox.tsx +32 -0
- package/src/components/ui/command-menu.tsx +72 -0
- package/src/components/ui/date-picker.tsx +170 -0
- package/src/components/ui/date-time-picker.tsx +117 -0
- package/src/components/ui/dialog.tsx +124 -0
- package/src/components/ui/dropdown-menu.tsx +183 -0
- package/src/components/ui/editable-text.tsx +109 -0
- package/src/components/ui/field-button.tsx +68 -0
- package/src/components/ui/file-preview.tsx +80 -0
- package/src/components/ui/file-uploader.tsx +376 -0
- package/src/components/ui/handle-row.tsx +116 -0
- package/src/components/ui/image-block.tsx +238 -0
- package/src/components/ui/image-card.tsx +102 -0
- package/src/components/ui/image-viewer.tsx +187 -0
- package/src/components/ui/image.tsx +96 -0
- package/src/components/ui/index.ts +83 -0
- package/src/components/ui/input.tsx +99 -0
- package/src/components/ui/link-block.tsx +82 -0
- package/src/components/ui/mac-card.tsx +46 -0
- package/src/components/ui/nav-tree.tsx +86 -0
- package/src/components/ui/page.tsx +25 -0
- package/src/components/ui/popover.tsx +42 -0
- package/src/components/ui/progress.tsx +36 -0
- package/src/components/ui/property.tsx +64 -0
- package/src/components/ui/segmented.tsx +42 -0
- package/src/components/ui/select-menu.tsx +46 -0
- package/src/components/ui/select.tsx +124 -0
- package/src/components/ui/selection-bar.tsx +50 -0
- package/src/components/ui/separator.tsx +30 -0
- package/src/components/ui/spotlight.tsx +222 -0
- package/src/components/ui/stat-tile.tsx +25 -0
- package/src/components/ui/step-dialog.tsx +104 -0
- package/src/components/ui/table.tsx +42 -0
- package/src/components/ui/theme-toggle.tsx +101 -0
- package/src/components/ui/time-picker.tsx +173 -0
- package/src/components/ui/tooltip.tsx +64 -0
- package/src/components/ui/typography.tsx +168 -0
- package/src/components/ui/video-block.tsx +60 -0
- package/src/hooks/use-save-queue.ts +66 -0
- package/src/hooks/use-selection.ts +44 -0
- package/src/hooks/use-shared-transition.ts +40 -0
- package/src/hooks/use-upload-queue.ts +111 -0
- package/src/lib/accent.ts +11 -0
- package/src/lib/bento.ts +87 -0
- package/src/lib/dates.ts +39 -0
- package/src/lib/document.ts +55 -0
- package/src/lib/embed.ts +62 -0
- package/src/lib/files.ts +73 -0
- package/src/lib/justified.ts +106 -0
- package/src/lib/rich-text-dom.ts +136 -0
- package/src/lib/rich-text.ts +50 -0
- package/src/lib/spotlight.ts +78 -0
- package/src/lib/tree.ts +41 -0
- package/src/lib/utils.ts +6 -0
- package/src/styles/notion.css +526 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
/* A queue of files being sent, a few at a time.
|
|
4
|
+
|
|
5
|
+
You supply `upload`: send one file, call `report` with 0 to 1 as it goes,
|
|
6
|
+
resolve when it is done (optionally with a message to show), throw an Error
|
|
7
|
+
when it fails. The queue does the rest: holds the order, runs `parallel` at
|
|
8
|
+
once, keeps each file's progress, and lets a failed one be tried again.
|
|
9
|
+
|
|
10
|
+
`validate` turns a file away before anything is sent, by returning why.
|
|
11
|
+
|
|
12
|
+
The queue lives in the component that calls this. For uploads that must
|
|
13
|
+
survive navigation, keep the same logic in a store outside React instead. */
|
|
14
|
+
export function useUploadQueue({ upload, validate, parallel = 3, }) {
|
|
15
|
+
const items = useRef([]);
|
|
16
|
+
const nextKey = useRef(1);
|
|
17
|
+
const running = useRef(0);
|
|
18
|
+
const [, render] = useState(0);
|
|
19
|
+
// The latest functions, so a queue started with one render's props finishes with the current ones.
|
|
20
|
+
const latest = useRef({ upload, validate });
|
|
21
|
+
latest.current = { upload, validate };
|
|
22
|
+
// Progress arrives many times a second per file; one render per frame is plenty.
|
|
23
|
+
const frame = useRef(0);
|
|
24
|
+
const changed = useCallback(() => {
|
|
25
|
+
if (frame.current !== 0)
|
|
26
|
+
return;
|
|
27
|
+
frame.current = requestAnimationFrame(() => {
|
|
28
|
+
frame.current = 0;
|
|
29
|
+
render((n) => n + 1);
|
|
30
|
+
});
|
|
31
|
+
}, []);
|
|
32
|
+
useEffect(() => () => cancelAnimationFrame(frame.current), []);
|
|
33
|
+
const pump = useCallback(() => {
|
|
34
|
+
while (running.current < parallel) {
|
|
35
|
+
const item = items.current.find((i) => i.state === "waiting");
|
|
36
|
+
if (item === undefined)
|
|
37
|
+
return;
|
|
38
|
+
running.current += 1;
|
|
39
|
+
Object.assign(item, { state: "uploading", progress: 0, message: undefined });
|
|
40
|
+
changed();
|
|
41
|
+
latest.current
|
|
42
|
+
.upload(item.file, (progress) => {
|
|
43
|
+
item.progress = progress;
|
|
44
|
+
changed();
|
|
45
|
+
})
|
|
46
|
+
.then((message) => Object.assign(item, { state: "done", progress: 1, message: message ?? undefined }), (error) => Object.assign(item, { state: "failed", message: error instanceof Error ? error.message : "It could not be sent" }))
|
|
47
|
+
.finally(() => {
|
|
48
|
+
running.current -= 1;
|
|
49
|
+
changed();
|
|
50
|
+
pump();
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}, [parallel, changed]);
|
|
54
|
+
const add = useCallback((files) => {
|
|
55
|
+
for (const file of files) {
|
|
56
|
+
const refused = latest.current.validate?.(file);
|
|
57
|
+
items.current.push({ key: nextKey.current++, file, state: refused === undefined ? "waiting" : "rejected", progress: 0, message: refused });
|
|
58
|
+
}
|
|
59
|
+
changed();
|
|
60
|
+
pump();
|
|
61
|
+
}, [changed, pump]);
|
|
62
|
+
const retry = useCallback((key) => {
|
|
63
|
+
const item = items.current.find((i) => i.key === key);
|
|
64
|
+
if (item?.state !== "failed")
|
|
65
|
+
return;
|
|
66
|
+
item.state = "waiting";
|
|
67
|
+
changed();
|
|
68
|
+
pump();
|
|
69
|
+
}, [changed, pump]);
|
|
70
|
+
/** Drops everything that has reached an end; work in flight stays. */
|
|
71
|
+
const clear = useCallback(() => {
|
|
72
|
+
items.current = items.current.filter((i) => i.state === "waiting" || i.state === "uploading");
|
|
73
|
+
changed();
|
|
74
|
+
}, [changed]);
|
|
75
|
+
const list = [...items.current];
|
|
76
|
+
return { items: list, busy: list.some((i) => i.state === "waiting" || i.state === "uploading"), add, retry, clear };
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=use-upload-queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-upload-queue.js","sourceRoot":"","sources":["../../src/hooks/use-upload-queue.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAcjE;;;;;;;;;;+EAU+E;AAC/E,MAAM,UAAU,cAAc,CAAC,EAC3B,MAAM,EACN,QAAQ,EACR,QAAQ,GAAG,CAAC,GAKf;IACG,MAAM,KAAK,GAAG,MAAM,CAAe,EAAE,CAAC,CAAC;IACvC,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAC1B,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC/B,mGAAmG;IACn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,OAAO,EAAE,IAAI,CAAC,CAClB,CAAC;IAEF,MAAM,KAAK,GAAG,WAAW,CACrB,CAAC,GAAW,EAAE,EAAE;QACZ,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;QACtD,IAAI,IAAI,EAAE,KAAK,KAAK,QAAQ;YAAE,OAAO;QACrC,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACvB,OAAO,EAAE,CAAC;QACV,IAAI,EAAE,CAAC;IACX,CAAC,EACD,CAAC,OAAO,EAAE,IAAI,CAAC,CAClB,CAAC;IAEF,sEAAsE;IACtE,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;QAC3B,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,SAAS,IAAI,CAAC,CAAC,KAAK,KAAK,WAAW,CAAC,CAAC;QAC9F,OAAO,EAAE,CAAC;IACd,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAEd,MAAM,IAAI,GAAG,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;IAChC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,SAAS,IAAI,CAAC,CAAC,KAAK,KAAK,WAAW,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AACxH,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const ACCENTS: readonly ["paper", "blue", "green", "purple", "pink", "orange", "red", "brown"];
|
|
2
|
+
export type Accent = (typeof ACCENTS)[number];
|
|
3
|
+
export declare const ACCENT_KEY = "accent";
|
|
4
|
+
export declare const ACCENT_INIT_SCRIPT: string;
|
|
5
|
+
//# sourceMappingURL=accent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accent.d.ts","sourceRoot":"","sources":["../../src/lib/accent.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,OAAO,iFAAkF,CAAC;AACvG,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;AAC9C,eAAO,MAAM,UAAU,WAAW,CAAC;AAGnC,eAAO,MAAM,kBAAkB,QAAyI,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// The colour themes, independent of light and dark. "paper" is the plain one: white
|
|
2
|
+
// and warm grey with the blue accent, and it is the absence of a theme, so nothing is
|
|
3
|
+
// set for it. Each of the others sets the accent and washes every surface with it;
|
|
4
|
+
// the colours live in notion.css under [data-accent]. This is only their names
|
|
5
|
+
// and where the choice is kept.
|
|
6
|
+
export const ACCENTS = ["paper", "blue", "green", "purple", "pink", "orange", "red", "brown"];
|
|
7
|
+
export const ACCENT_KEY = "accent";
|
|
8
|
+
// Runs in <head> before first paint, so the page never flashes the wrong theme.
|
|
9
|
+
export const ACCENT_INIT_SCRIPT = `try{var a=localStorage.getItem(${JSON.stringify(ACCENT_KEY)});if(a&&a!=="paper")document.documentElement.dataset.accent=a}catch(e){}`;
|
|
10
|
+
//# sourceMappingURL=accent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accent.js","sourceRoot":"","sources":["../../src/lib/accent.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,sFAAsF;AACtF,mFAAmF;AACnF,+EAA+E;AAC/E,gCAAgC;AAChC,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,CAAU,CAAC;AAEvG,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC;AAEnC,gFAAgF;AAChF,MAAM,CAAC,MAAM,kBAAkB,GAAG,kCAAkC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,0EAA0E,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type Tile<T> = {
|
|
2
|
+
item: T;
|
|
3
|
+
col: number;
|
|
4
|
+
row: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
};
|
|
8
|
+
export declare function bento<T>(items: T[], columns: number, ask: (item: T, index: number) => [number, number],
|
|
9
|
+
/** Width over height of each picture, and of one cell, so a gap goes to the neighbour it crops least. */
|
|
10
|
+
shape?: {
|
|
11
|
+
aspect: (item: T) => number;
|
|
12
|
+
cell: number;
|
|
13
|
+
}): {
|
|
14
|
+
tiles: Tile<T>[];
|
|
15
|
+
rows: number;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=bento.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bento.d.ts","sourceRoot":"","sources":["../../src/lib/bento.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI;IAAE,IAAI,EAAE,CAAC,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3F,wBAAgB,KAAK,CAAC,CAAC,EACnB,KAAK,EAAE,CAAC,EAAE,EACV,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC;AACjD,yGAAyG;AACzG,KAAK,CAAC,EAAE;IAAE,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACtD;IAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAqEpC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/* A bento: pictures packed into a grid of square-ish cells with no holes, so a
|
|
2
|
+
day's photos read as one composed block rather than a list that ran out.
|
|
3
|
+
|
|
4
|
+
Each picture asks for a span (wide ones two columns, tall ones two rows, a
|
|
5
|
+
chosen one both). They are placed in order at the first free cell, shrinking
|
|
6
|
+
to fit where the ask cannot be met. A grid packed that way can still leave
|
|
7
|
+
gaps, so afterwards each gap is filled by growing a neighbour into it, which
|
|
8
|
+
keeps every picture in the order it was placed. */
|
|
9
|
+
export function bento(items, columns, ask,
|
|
10
|
+
/** Width over height of each picture, and of one cell, so a gap goes to the neighbour it crops least. */
|
|
11
|
+
shape) {
|
|
12
|
+
const grid = [];
|
|
13
|
+
const free = (r, c) => c >= 0 && c < columns && (grid[r]?.[c] ?? null) === null;
|
|
14
|
+
const claim = (r, c, who) => {
|
|
15
|
+
while (grid.length <= r)
|
|
16
|
+
grid.push(Array.from({ length: columns }, () => null));
|
|
17
|
+
grid[r][c] = who;
|
|
18
|
+
};
|
|
19
|
+
const fits = (r, c, w, h) => {
|
|
20
|
+
for (let y = r; y < r + h; y++)
|
|
21
|
+
for (let x = c; x < c + w; x++)
|
|
22
|
+
if (!free(y, x))
|
|
23
|
+
return false;
|
|
24
|
+
return true;
|
|
25
|
+
};
|
|
26
|
+
const tiles = [];
|
|
27
|
+
items.forEach((item, index) => {
|
|
28
|
+
let [w, h] = ask(item, index);
|
|
29
|
+
w = Math.min(Math.max(w, 1), columns);
|
|
30
|
+
h = Math.max(h, 1);
|
|
31
|
+
let at = 0;
|
|
32
|
+
while (!free(Math.floor(at / columns), at % columns))
|
|
33
|
+
at++;
|
|
34
|
+
const row = Math.floor(at / columns);
|
|
35
|
+
const col = at % columns;
|
|
36
|
+
// The first free cell is free, so one of these always fits.
|
|
37
|
+
const size = [[w, h], [1, h], [w, 1], [1, 1]].find(([sw, sh]) => fits(row, col, sw, sh));
|
|
38
|
+
[w, h] = size;
|
|
39
|
+
for (let y = row; y < row + h; y++)
|
|
40
|
+
for (let x = col; x < col + w; x++)
|
|
41
|
+
claim(y, x, index);
|
|
42
|
+
tiles.push({ item, col, row, width: w, height: h });
|
|
43
|
+
});
|
|
44
|
+
const rows = grid.length;
|
|
45
|
+
const owner = (r, c) => (r >= 0 && r < rows && c >= 0 && c < columns ? (grid[r][c] ?? null) : null);
|
|
46
|
+
const column = (t, c) => Array.from({ length: t.height }, (_, k) => t.row + k).every((r) => owner(r, c) === null);
|
|
47
|
+
const line = (t, r) => Array.from({ length: t.width }, (_, k) => t.col + k).every((c) => owner(r, c) === null);
|
|
48
|
+
const take = (t, index) => {
|
|
49
|
+
for (let y = t.row; y < t.row + t.height; y++)
|
|
50
|
+
for (let x = t.col; x < t.col + t.width; x++)
|
|
51
|
+
grid[y][x] = index;
|
|
52
|
+
};
|
|
53
|
+
// Each gap is filled by growing a neighbour whose whole edge borders it.
|
|
54
|
+
// Of those that can, the one whose new shape is nearest its picture's grows,
|
|
55
|
+
// so a portrait grows down and a landscape across.
|
|
56
|
+
const misfit = (t, w, h) => (shape === undefined ? 0 : Math.abs(Math.log(((w / h) * shape.cell) / shape.aspect(t.item))));
|
|
57
|
+
for (let changed = true; changed;) {
|
|
58
|
+
changed = false;
|
|
59
|
+
for (let r = 0; r < rows; r++) {
|
|
60
|
+
for (let c = 0; c < columns; c++) {
|
|
61
|
+
if (owner(r, c) !== null)
|
|
62
|
+
continue;
|
|
63
|
+
const growths = [];
|
|
64
|
+
const left = owner(r, c - 1);
|
|
65
|
+
if (left !== null && tiles[left].col + tiles[left].width === c && column(tiles[left], c))
|
|
66
|
+
growths.push({ who: left, w: 1, h: 0, apply: (t) => t.width++ });
|
|
67
|
+
const right = owner(r, c + 1);
|
|
68
|
+
if (right !== null && tiles[right].col === c + 1 && column(tiles[right], c))
|
|
69
|
+
growths.push({ who: right, w: 1, h: 0, apply: (t) => (t.col--, t.width++) });
|
|
70
|
+
const above = owner(r - 1, c);
|
|
71
|
+
if (above !== null && tiles[above].row + tiles[above].height === r && line(tiles[above], r))
|
|
72
|
+
growths.push({ who: above, w: 0, h: 1, apply: (t) => t.height++ });
|
|
73
|
+
const below = owner(r + 1, c);
|
|
74
|
+
if (below !== null && tiles[below].row === r + 1 && line(tiles[below], r))
|
|
75
|
+
growths.push({ who: below, w: 0, h: 1, apply: (t) => (t.row--, t.height++) });
|
|
76
|
+
if (growths.length === 0)
|
|
77
|
+
continue;
|
|
78
|
+
const best = growths.reduce((a, b) => {
|
|
79
|
+
const ta = tiles[a.who];
|
|
80
|
+
const tb = tiles[b.who];
|
|
81
|
+
return misfit(tb, tb.width + b.w, tb.height + b.h) < misfit(ta, ta.width + a.w, ta.height + a.h) ? b : a;
|
|
82
|
+
});
|
|
83
|
+
const tile = tiles[best.who];
|
|
84
|
+
best.apply(tile);
|
|
85
|
+
take(tile, best.who);
|
|
86
|
+
changed = true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return { tiles, rows };
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=bento.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bento.js","sourceRoot":"","sources":["../../src/lib/bento.ts"],"names":[],"mappings":"AAAA;;;;;;;uDAOuD;AAIvD,MAAM,UAAU,KAAK,CACjB,KAAU,EACV,OAAe,EACf,GAAiD;AACjD,yGAAyG;AACzG,KAAqD;IAErD,MAAM,IAAI,GAAwB,EAAE,CAAC;IACrC,MAAM,IAAI,GAAG,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,IAAI,CAAC;IAChG,MAAM,KAA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AAE,CAAC,EAAE,CAAC,CAAC;gBAC3J,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;oBAAE,SAAS;gBACnC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;oBACjC,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,CAAE,CAAC;oBACzB,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,CAAE,CAAC;oBACzB,OAAO,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC7G,CAAC,CAAC,CAAC;gBACH,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAE,CAAC;gBAC9B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBACjB,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;gBACrB,OAAO,GAAG,IAAI,CAAC;YACnB,CAAC;QACL,CAAC;IACL,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare function toISODate(date: Date): string;
|
|
2
|
+
/** The local day a `YYYY-MM-DD` names, or undefined if it names none (30 February). */
|
|
3
|
+
export declare function fromISODate(value: string | null | undefined): Date | undefined;
|
|
4
|
+
export declare function isTime(value: string | null | undefined): value is string;
|
|
5
|
+
/** Splits `YYYY-MM-DDTHH:MM`; either half is null when it is missing or wrong. */
|
|
6
|
+
export declare function splitDateTime(value: string | null | undefined): {
|
|
7
|
+
date: string | null;
|
|
8
|
+
time: string | null;
|
|
9
|
+
};
|
|
10
|
+
/** "Sun 27 Dec 2026" */
|
|
11
|
+
export declare const formatDay: (date: Date) => string;
|
|
12
|
+
/** "27 Dec 2026" */
|
|
13
|
+
export declare const formatShortDay: (date: Date) => string;
|
|
14
|
+
//# sourceMappingURL=dates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dates.d.ts","sourceRoot":"","sources":["../../src/lib/dates.ts"],"names":[],"mappings":"AAOA,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE5C;AAED,uFAAuF;AACvF,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS,CAK9E;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,KAAK,IAAI,MAAM,CAExE;AAED,kFAAkF;AAClF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG;IAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAM5G;AAKD,wBAAwB;AACxB,eAAO,MAAM,SAAS,GAAI,MAAM,IAAI,KAAG,MAA2C,CAAC;AACnF,oBAAoB;AACpB,eAAO,MAAM,cAAc,GAAI,MAAM,IAAI,KAAG,MAAgC,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
6
|
+
export function toISODate(date) {
|
|
7
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
|
8
|
+
}
|
|
9
|
+
/** The local day a `YYYY-MM-DD` names, or undefined if it names none (30 February). */
|
|
10
|
+
export function fromISODate(value) {
|
|
11
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value ?? "");
|
|
12
|
+
if (match === null)
|
|
13
|
+
return undefined;
|
|
14
|
+
const date = new Date(Number(match[1]), Number(match[2]) - 1, Number(match[3]));
|
|
15
|
+
return toISODate(date) === value ? date : undefined;
|
|
16
|
+
}
|
|
17
|
+
export function isTime(value) {
|
|
18
|
+
return /^([01]\d|2[0-3]):[0-5]\d$/.test(value ?? "");
|
|
19
|
+
}
|
|
20
|
+
/** Splits `YYYY-MM-DDTHH:MM`; either half is null when it is missing or wrong. */
|
|
21
|
+
export function splitDateTime(value) {
|
|
22
|
+
const [date = "", time = ""] = (value ?? "").split("T");
|
|
23
|
+
return {
|
|
24
|
+
date: fromISODate(date) === undefined ? null : date,
|
|
25
|
+
time: isTime(time.slice(0, 5)) ? time.slice(0, 5) : null,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const DAY = new Intl.DateTimeFormat("en-GB", { weekday: "short", day: "numeric", month: "short", year: "numeric" });
|
|
29
|
+
const SHORT_DAY = new Intl.DateTimeFormat("en-GB", { day: "numeric", month: "short", year: "numeric" });
|
|
30
|
+
/** "Sun 27 Dec 2026" */
|
|
31
|
+
export const formatDay = (date) => DAY.format(date).replace(",", "");
|
|
32
|
+
/** "27 Dec 2026" */
|
|
33
|
+
export const formatShortDay = (date) => SHORT_DAY.format(date);
|
|
34
|
+
//# sourceMappingURL=dates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dates.js","sourceRoot":"","sources":["../../src/lib/dates.ts"],"names":[],"mappings":"AAAA;;;mCAGmC;AAEnC,MAAM,GAAG,GAAG,CAAC,CAAS,EAAU,EAAE,CAAC,MA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,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI;KAC3D,CAAC;AACN,CAAC;AAED,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;AACpH,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;AAExG,wBAAwB;AACxB,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAAU,EAAU,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;AACnF,oBAAoB;AACpB,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,IAAU,EAAU,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { Text } from "./rich-text.js";
|
|
2
|
+
/** Every block has an id the editor chose, so one can be focused before it is saved. */
|
|
3
|
+
type Id = {
|
|
4
|
+
id: number;
|
|
5
|
+
};
|
|
6
|
+
export type Block = Id & ({
|
|
7
|
+
type: "paragraph";
|
|
8
|
+
text: Text;
|
|
9
|
+
} | {
|
|
10
|
+
type: "heading";
|
|
11
|
+
level: 1 | 2 | 3;
|
|
12
|
+
text: Text;
|
|
13
|
+
} | {
|
|
14
|
+
type: "bullet" | "numbered";
|
|
15
|
+
text: Text;
|
|
16
|
+
children: Block[];
|
|
17
|
+
} | {
|
|
18
|
+
type: "check";
|
|
19
|
+
checked: boolean;
|
|
20
|
+
text: Text;
|
|
21
|
+
children: Block[];
|
|
22
|
+
} | {
|
|
23
|
+
type: "quote";
|
|
24
|
+
text: Text;
|
|
25
|
+
} | {
|
|
26
|
+
type: "divider";
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A picture. `src` is what the browser loads; `ref` is the owner's own name
|
|
30
|
+
* for an uploaded one (its id in the owner's store), kept beside it so the
|
|
31
|
+
* owner can tell which uploads a document still uses. `width` is the share
|
|
32
|
+
* of the column; `aspect` holds the shape so nothing moves while it loads.
|
|
33
|
+
*/
|
|
34
|
+
| {
|
|
35
|
+
type: "image";
|
|
36
|
+
src?: string;
|
|
37
|
+
ref?: string;
|
|
38
|
+
aspect?: number;
|
|
39
|
+
caption: Text;
|
|
40
|
+
width: number;
|
|
41
|
+
}
|
|
42
|
+
/** A YouTube or Vimeo video, played in place. Empty until a link is given. */
|
|
43
|
+
| {
|
|
44
|
+
type: "video";
|
|
45
|
+
url: string;
|
|
46
|
+
caption: Text;
|
|
47
|
+
}
|
|
48
|
+
/** A web page as a card, with a name the writer types. */
|
|
49
|
+
| {
|
|
50
|
+
type: "bookmark";
|
|
51
|
+
url: string;
|
|
52
|
+
title: string;
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* A block an app adds through a BlockExtension (components/editor): its own
|
|
56
|
+
* `type`, and whatever fields it needs. One with `text` is written in like a
|
|
57
|
+
* paragraph; one with `children` holds blocks; one with neither is picked whole.
|
|
58
|
+
*/
|
|
59
|
+
export type CustomBlock = {
|
|
60
|
+
id: number;
|
|
61
|
+
type: string;
|
|
62
|
+
text?: Text;
|
|
63
|
+
children?: AnyBlock[];
|
|
64
|
+
[field: string]: unknown;
|
|
65
|
+
};
|
|
66
|
+
/** What a document holds: the kit's blocks and any an app adds. */
|
|
67
|
+
export type AnyBlock = Block | CustomBlock;
|
|
68
|
+
/** List items nest under one another and run together as one list. */
|
|
69
|
+
export declare const LISTS: readonly ["bullet", "numbered", "check"];
|
|
70
|
+
export declare const isListType: (type: string) => boolean;
|
|
71
|
+
/** The kinds that hold children. */
|
|
72
|
+
export declare const nests: (type: string) => boolean;
|
|
73
|
+
/** Whether `child` may sit inside `parent`. Lists hold list items. */
|
|
74
|
+
export declare const holds: (parent: string, child: string) => boolean;
|
|
75
|
+
/** Kinds without words: picked as a whole in the editor rather than given a caret. */
|
|
76
|
+
export declare const WHOLE: readonly ["divider", "image", "video", "bookmark"];
|
|
77
|
+
export declare const isWhole: (type: string) => boolean;
|
|
78
|
+
export {};
|
|
79
|
+
//# sourceMappingURL=document.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../src/lib/document.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAQ3C,wFAAwF;AACxF,KAAK,EAAE,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzB,MAAM,MAAM,KAAK,GAAG,EAAE,GAClB,CACM;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,GACjD;IAAE,IAAI,EAAE,QAAQ,GAAG,UAAU,CAAC;IAAC,IAAI,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,KAAK,EAAE,CAAA;CAAE,GAC9D;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,KAAK,EAAE,CAAA;CAAE,GAClE;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,GAC7B;IAAE,IAAI,EAAE,SAAS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@@
|
|
|
1
|
+
/** List items nest under one another and run together as one list. */
|
|
2
|
+
export const LISTS = ["bullet", "numbered", "check"];
|
|
3
|
+
export const isListType = (type) => LISTS.includes(type);
|
|
4
|
+
/** The kinds that hold children. */
|
|
5
|
+
export const nests = (type) => isListType(type);
|
|
6
|
+
/** Whether `child` may sit inside `parent`. Lists hold list items. */
|
|
7
|
+
export const holds = (parent, child) => isListType(parent) && isListType(child);
|
|
8
|
+
/** Kinds without words: picked as a whole in the editor rather than given a caret. */
|
|
9
|
+
export const WHOLE = ["divider", "image", "video", "bookmark"];
|
|
10
|
+
export const isWhole = (type) => WHOLE.includes(type);
|
|
11
|
+
//# sourceMappingURL=document.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.js","sourceRoot":"","sources":["../../src/lib/document.ts"],"names":[],"mappings":"AA0CA,sEAAsE;AACtE,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,QAAQ,EAAE,UAAU,EAAE,OAAO,CAAU,CAAC;AAC9D,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAW,EAAE,CAAE,KAA2B,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAEjG,oCAAoC;AACpC,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;AAEjE,sEAAsE;AACtE,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,MAAc,EAAE,KAAa,EAAW,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;AAEzG,sFAAsF;AACtF,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,CAAU,CAAC;AACxE,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAY,EAAW,EAAE,CAAE,KAA2B,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** A web address. Anything else, `javascript:` above all, is refused. */
|
|
2
|
+
export declare function isWebUrl(value: string): boolean;
|
|
3
|
+
/** A link in text a reader may follow: a web or mail address. Never `javascript:` or `data:`. */
|
|
4
|
+
export declare function isSafeHref(value: string): boolean;
|
|
5
|
+
/** The site a link is on, for showing in place of a missing name. */
|
|
6
|
+
export declare function hostOf(url: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Where a YouTube or Vimeo link plays, or null when it is not one. YouTube is
|
|
9
|
+
* embedded from its privacy-enhanced domain, which sets no cookie until the video
|
|
10
|
+
* is played, and Vimeo is asked not to track. A start time in a YouTube link
|
|
11
|
+
* (`t=`) is kept.
|
|
12
|
+
*/
|
|
13
|
+
export declare function videoEmbed(url: string): string | null;
|
|
14
|
+
//# sourceMappingURL=embed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embed.d.ts","sourceRoot":"","sources":["../../src/lib/embed.ts"],"names":[],"mappings":"AAIA,yEAAyE;AACzE,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAQ/C;AAED,iGAAiG;AACjG,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEjD;AAED,qEAAqE;AACrE,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAM1C;AASD;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAmBrD"}
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
/** A web address. Anything else, `javascript:` above all, is refused. */
|
|
5
|
+
export function isWebUrl(value) {
|
|
6
|
+
if (!/^https?:\/\//i.test(value))
|
|
7
|
+
return false;
|
|
8
|
+
try {
|
|
9
|
+
new URL(value);
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return false;
|
|
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) {
|
|
18
|
+
return /^mailto:/i.test(value) || isWebUrl(value);
|
|
19
|
+
}
|
|
20
|
+
/** The site a link is on, for showing in place of a missing name. */
|
|
21
|
+
export function hostOf(url) {
|
|
22
|
+
try {
|
|
23
|
+
return new URL(url).hostname.replace(/^www\./, "");
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return url;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** "1h2m3s", "90s" or "90" as seconds. */
|
|
30
|
+
function seconds(t) {
|
|
31
|
+
const m = t?.match(/^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s?)?$/);
|
|
32
|
+
if (!m || !t)
|
|
33
|
+
return null;
|
|
34
|
+
return Number(m[1] ?? 0) * 3600 + Number(m[2] ?? 0) * 60 + Number(m[3] ?? 0);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Where a YouTube or Vimeo link plays, or null when it is not one. YouTube is
|
|
38
|
+
* embedded from its privacy-enhanced domain, which sets no cookie until the video
|
|
39
|
+
* is played, and Vimeo is asked not to track. A start time in a YouTube link
|
|
40
|
+
* (`t=`) is kept.
|
|
41
|
+
*/
|
|
42
|
+
export function videoEmbed(url) {
|
|
43
|
+
if (!isWebUrl(url))
|
|
44
|
+
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 = host === "youtu.be"
|
|
52
|
+
? u.pathname.slice(1)
|
|
53
|
+
: host === "youtube.com"
|
|
54
|
+
? u.pathname === "/watch"
|
|
55
|
+
? u.searchParams.get("v")
|
|
56
|
+
: (u.pathname.match(/^\/(?:shorts|embed|live)\/([\w-]+)/)?.[1] ?? null)
|
|
57
|
+
: null;
|
|
58
|
+
if (!id || !/^[\w-]{6,}$/.test(id))
|
|
59
|
+
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
|
+
}
|
|
63
|
+
//# sourceMappingURL=embed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embed.js","sourceRoot":"","sources":["../../src/lib/embed.ts"],"names":[],"mappings":"AAAA;;qBAEqB;AAErB,yEAAyE;AACzE,MAAM,UAAU,QAAQ,CAAC,KAAa;IAClC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC/C,IAAI,CAAC;QACD,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;QACf,OAAO,IAAI,CAAC;IAChB,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,KAAK,CAAC;IACjB,CAAC;AACL,CAAC;AAED,iGAAiG;AACjG,MAAM,UAAU,UAAU,CAAC,KAAa;IACpC,OAAO,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC;AACtD,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,MAAM,CAAC,GAAW;IAC9B,IAAI,CAAC;QACD,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IACvD,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,GAAG,CAAC;IACf,CAAC;AACL,CAAC;AAED,0CAA0C;AA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,CAAC,KAAK,CAAC,oCAAoC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;YAC3E,CAAC,CAAC,IAAI,CAAC;IACjB,IAAI,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;QAAE,OAAO,IAAI,CAAC;IAChD,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;IAC9E,OAAO,0CAA0C,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,UAAU,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AAC3F,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** 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>. */
|
|
2
|
+
export declare function pickFiles(onPicked: (files: File[]) => void, options?: {
|
|
3
|
+
folder?: boolean;
|
|
4
|
+
accept?: string;
|
|
5
|
+
single?: boolean;
|
|
6
|
+
}): void;
|
|
7
|
+
/** Everything in a drop: loose files as they are, folders walked to their leaves. Call it in the drop handler itself. */
|
|
8
|
+
export declare function filesFromDrop(data: DataTransfer): Promise<File[]>;
|
|
9
|
+
/** True for a drag that is carrying files, as opposed to text or an element of the page. */
|
|
10
|
+
export declare const carriesFiles: (event: {
|
|
11
|
+
dataTransfer: DataTransfer | null;
|
|
12
|
+
}) => boolean;
|
|
13
|
+
/**
|
|
14
|
+
* One request with upload progress, 0 to 1. Resolves with the status and the
|
|
15
|
+
* parsed JSON body whatever the status; rejects only when the connection
|
|
16
|
+
* fails, which is the case worth retrying. `headers` are sent as given: a
|
|
17
|
+
* custom one is how a server tells this from another site's form.
|
|
18
|
+
*/
|
|
19
|
+
export declare function sendWithProgress(method: string, url: string, body: Blob | FormData, onProgress: (progress: number) => void, headers?: Record<string, string>): Promise<{
|
|
20
|
+
status: number;
|
|
21
|
+
body: unknown;
|
|
22
|
+
}>;
|
|
23
|
+
//# sourceMappingURL=files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../src/lib/files.ts"],"names":[],"mappings":"AAKA,gJAAgJ;AAChJ,wBAAgB,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,EAAE,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,IAAI,CAQxI;AAoBD,yHAAyH;AACzH,wBAAsB,aAAa,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CASvE;AAED,4FAA4F;AAC5F,eAAO,MAAM,YAAY,GAAI,OAAO;IAAE,YAAY,EAAE,YAAY,GAAG,IAAI,CAAA;CAAE,KAAG,OAA+D,CAAC;AAE5I;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC5B,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,IAAI,GAAG,QAAQ,EACrB,UAAU,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,EACtC,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACrC,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,CAW5C"}
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
const byName = (files) => files.sort((a, b) => a.name.localeCompare(b.name, undefined, { numeric: true }));
|
|
4
|
+
/** 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>. */
|
|
5
|
+
export function pickFiles(onPicked, options = {}) {
|
|
6
|
+
const input = document.createElement("input");
|
|
7
|
+
input.type = "file";
|
|
8
|
+
input.multiple = !options.single;
|
|
9
|
+
if (options.folder)
|
|
10
|
+
input.webkitdirectory = true;
|
|
11
|
+
else if (options.accept !== undefined)
|
|
12
|
+
input.accept = options.accept;
|
|
13
|
+
input.onchange = () => onPicked(byName([...(input.files ?? [])]));
|
|
14
|
+
input.click();
|
|
15
|
+
}
|
|
16
|
+
const fileOf = (entry) => new Promise((resolve, reject) => entry.file(resolve, reject));
|
|
17
|
+
async function childrenOf(directory) {
|
|
18
|
+
const reader = directory.createReader();
|
|
19
|
+
const all = [];
|
|
20
|
+
// readEntries hands back a page at a time and signals the end with an empty one.
|
|
21
|
+
for (;;) {
|
|
22
|
+
const page = await new Promise((resolve, reject) => reader.readEntries(resolve, reject));
|
|
23
|
+
if (page.length === 0)
|
|
24
|
+
return all;
|
|
25
|
+
all.push(...page);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async function walk(entry, into) {
|
|
29
|
+
if (entry.isFile)
|
|
30
|
+
into.push(await fileOf(entry));
|
|
31
|
+
else if (entry.isDirectory)
|
|
32
|
+
for (const child of await childrenOf(entry))
|
|
33
|
+
await walk(child, into);
|
|
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) {
|
|
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 = [];
|
|
40
|
+
for (const { entry, file } of dropped) {
|
|
41
|
+
if (entry?.isDirectory)
|
|
42
|
+
await walk(entry, files);
|
|
43
|
+
else if (file !== null)
|
|
44
|
+
files.push(file);
|
|
45
|
+
}
|
|
46
|
+
return byName(files);
|
|
47
|
+
}
|
|
48
|
+
/** True for a drag that is carrying files, as opposed to text or an element of the page. */
|
|
49
|
+
export const carriesFiles = (event) => event.dataTransfer?.types.includes("Files") ?? false;
|
|
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(method, url, body, onProgress, headers = {}) {
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
const xhr = new XMLHttpRequest();
|
|
59
|
+
xhr.open(method, url);
|
|
60
|
+
for (const [name, value] of Object.entries(headers))
|
|
61
|
+
xhr.setRequestHeader(name, value);
|
|
62
|
+
xhr.responseType = "json";
|
|
63
|
+
xhr.upload.onprogress = (event) => event.lengthComputable && onProgress(event.loaded / event.total);
|
|
64
|
+
xhr.onload = () => resolve({ status: xhr.status, body: xhr.response });
|
|
65
|
+
xhr.onerror = xhr.ontimeout = xhr.onabort = () => reject(new Error("The connection was lost"));
|
|
66
|
+
xhr.send(body);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.js","sourceRoot":"","sources":["../../src/lib/files.ts"],"names":[],"mappings":"AAAA;uEACuE;AAEvE,MAAM,MAAM,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AAE3H,gJAAgJ;AAChJ,MAAM,UAAU,SAAS,CAAC,QAAiC,EAAE,UAAmE,EAAE;IAC9H,MAAM,KAAK,GAAG,QAAQ,CAA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