@fireproof/use-fireproof 0.0.0-smoke-b310d20f-1765361723

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/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@fireproof/use-fireproof",
3
+ "version": "0.0.0-smoke-b310d20f-1765361723",
4
+ "description": "Fireproof live ledger, JavaScript API and React hooks",
5
+ "type": "module",
6
+ "main": "./index.js",
7
+ "homepage": "https://use-fireproof.com",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/fireproof-storage/fireproof.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/fireproof-storage/fireproof/issues"
14
+ },
15
+ "scripts": {
16
+ "build": "core-cli tsc",
17
+ "test": "echo vitest --run"
18
+ },
19
+ "author": "J Chris Anderson",
20
+ "license": "AFL-2.0",
21
+ "gptdoc": "Fireproof/React/Usage: import { useFireproof } from 'use-fireproof'; function WordCounterApp() { const { useLiveQuery, useDocument } = useFireproof('my-word-app'); const { doc: wordInput, merge: updateWordInput, save: saveWordInput, reset: clearWordInput } = useDocument({ word: '', timestamp: Date.now() }); const recentWords = useLiveQuery('timestamp', { descending: true, limit: 10 }); const { doc: { totalSubmitted }, merge: updateTotalSubmitted, save: saveTotalSubmitted } = useDocument({ _id: 'word-counter', totalSubmitted: 0 }); const handleWordSubmission = (e) => { e.preventDefault(); updateTotalSubmitted({ totalSubmitted: totalSubmitted + 1 }); saveTotalSubmitted(); saveWordInput(); clearWordInput();}; return (<><p>{totalSubmitted} words submitted</p><form onSubmit={handleWordSubmission}><input type='text' value={wordInput.word} onChange={e => updateWordInput({ word: e.target.value })} placeholder='Enter a word' /></form><ul>{recentWords.docs.map(entry => (<li key={entry._id}>{entry.word}</li>))} </ul></>) } export default WordCounterApp;",
22
+ "dependencies": {
23
+ "@adviser/cement": "0.5.5",
24
+ "@fireproof/core-base": "0.0.0-smoke-b310d20f-1765361723",
25
+ "@fireproof/core-gateways-cloud": "0.0.0-smoke-b310d20f-1765361723",
26
+ "@fireproof/core-keybag": "0.0.0-smoke-b310d20f-1765361723",
27
+ "@fireproof/core-protocols-dashboard": "0.0.0-smoke-b310d20f-1765361723",
28
+ "@fireproof/core-runtime": "0.0.0-smoke-b310d20f-1765361723",
29
+ "@fireproof/core-types-base": "0.0.0-smoke-b310d20f-1765361723",
30
+ "@fireproof/core-types-blockstore": "0.0.0-smoke-b310d20f-1765361723",
31
+ "@fireproof/core-types-protocols-cloud": "0.0.0-smoke-b310d20f-1765361723",
32
+ "@fireproof/vendor": "0.0.0-smoke-b310d20f-1765361723",
33
+ "dompurify": "3.3.0",
34
+ "jose": "6.1.3",
35
+ "react": "19.2.1",
36
+ "ts-essentials": "10.1.1"
37
+ },
38
+ "peerDependencies": {
39
+ "@adviser/cement": ">=0.4.20",
40
+ "react": ">=18.0.0"
41
+ },
42
+ "keywords": [
43
+ "react",
44
+ "ledger",
45
+ "json",
46
+ "live",
47
+ "sync"
48
+ ]
49
+ }
@@ -0,0 +1,302 @@
1
+ import { DocFileMeta } from "@fireproof/core-types-base";
2
+ import React, { ImgHTMLAttributes } from "react";
3
+ type FileType = File | DocFileMeta;
4
+ interface ImgFileProps extends Omit<ImgHTMLAttributes<HTMLImageElement>, "src"> {
5
+ file?: FileType;
6
+ meta?: FileType;
7
+ }
8
+ export declare function ImgFile({ file, meta, ...imgProps }: ImgFileProps): React.DetailedReactHTMLElement<{
9
+ children?: React.ReactNode;
10
+ dangerouslySetInnerHTML?: {
11
+ __html: string | TrustedHTML;
12
+ } | undefined;
13
+ onCopy?: React.ClipboardEventHandler<HTMLImageElement> | undefined;
14
+ onCopyCapture?: React.ClipboardEventHandler<HTMLImageElement> | undefined;
15
+ onCut?: React.ClipboardEventHandler<HTMLImageElement> | undefined;
16
+ onCutCapture?: React.ClipboardEventHandler<HTMLImageElement> | undefined;
17
+ onPaste?: React.ClipboardEventHandler<HTMLImageElement> | undefined;
18
+ onPasteCapture?: React.ClipboardEventHandler<HTMLImageElement> | undefined;
19
+ onCompositionEnd?: React.CompositionEventHandler<HTMLImageElement> | undefined;
20
+ onCompositionEndCapture?: React.CompositionEventHandler<HTMLImageElement> | undefined;
21
+ onCompositionStart?: React.CompositionEventHandler<HTMLImageElement> | undefined;
22
+ onCompositionStartCapture?: React.CompositionEventHandler<HTMLImageElement> | undefined;
23
+ onCompositionUpdate?: React.CompositionEventHandler<HTMLImageElement> | undefined;
24
+ onCompositionUpdateCapture?: React.CompositionEventHandler<HTMLImageElement> | undefined;
25
+ onFocus?: React.FocusEventHandler<HTMLImageElement> | undefined;
26
+ onFocusCapture?: React.FocusEventHandler<HTMLImageElement> | undefined;
27
+ onBlur?: React.FocusEventHandler<HTMLImageElement> | undefined;
28
+ onBlurCapture?: React.FocusEventHandler<HTMLImageElement> | undefined;
29
+ onChange?: React.FormEventHandler<HTMLImageElement> | undefined;
30
+ onChangeCapture?: React.FormEventHandler<HTMLImageElement> | undefined;
31
+ onBeforeInput?: React.InputEventHandler<HTMLImageElement> | undefined;
32
+ onBeforeInputCapture?: React.FormEventHandler<HTMLImageElement> | undefined;
33
+ onInput?: React.FormEventHandler<HTMLImageElement> | undefined;
34
+ onInputCapture?: React.FormEventHandler<HTMLImageElement> | undefined;
35
+ onReset?: React.FormEventHandler<HTMLImageElement> | undefined;
36
+ onResetCapture?: React.FormEventHandler<HTMLImageElement> | undefined;
37
+ onSubmit?: React.FormEventHandler<HTMLImageElement> | undefined;
38
+ onSubmitCapture?: React.FormEventHandler<HTMLImageElement> | undefined;
39
+ onInvalid?: React.FormEventHandler<HTMLImageElement> | undefined;
40
+ onInvalidCapture?: React.FormEventHandler<HTMLImageElement> | undefined;
41
+ onLoad?: React.ReactEventHandler<HTMLImageElement> | undefined;
42
+ onLoadCapture?: React.ReactEventHandler<HTMLImageElement> | undefined;
43
+ onError?: React.ReactEventHandler<HTMLImageElement> | undefined;
44
+ onErrorCapture?: React.ReactEventHandler<HTMLImageElement> | undefined;
45
+ onKeyDown?: React.KeyboardEventHandler<HTMLImageElement> | undefined;
46
+ onKeyDownCapture?: React.KeyboardEventHandler<HTMLImageElement> | undefined;
47
+ onKeyPress?: React.KeyboardEventHandler<HTMLImageElement> | undefined;
48
+ onKeyPressCapture?: React.KeyboardEventHandler<HTMLImageElement> | undefined;
49
+ onKeyUp?: React.KeyboardEventHandler<HTMLImageElement> | undefined;
50
+ onKeyUpCapture?: React.KeyboardEventHandler<HTMLImageElement> | undefined;
51
+ onAbort?: React.ReactEventHandler<HTMLImageElement> | undefined;
52
+ onAbortCapture?: React.ReactEventHandler<HTMLImageElement> | undefined;
53
+ onCanPlay?: React.ReactEventHandler<HTMLImageElement> | undefined;
54
+ onCanPlayCapture?: React.ReactEventHandler<HTMLImageElement> | undefined;
55
+ onCanPlayThrough?: React.ReactEventHandler<HTMLImageElement> | undefined;
56
+ onCanPlayThroughCapture?: React.ReactEventHandler<HTMLImageElement> | undefined;
57
+ onDurationChange?: React.ReactEventHandler<HTMLImageElement> | undefined;
58
+ onDurationChangeCapture?: React.ReactEventHandler<HTMLImageElement> | undefined;
59
+ onEmptied?: React.ReactEventHandler<HTMLImageElement> | undefined;
60
+ onEmptiedCapture?: React.ReactEventHandler<HTMLImageElement> | undefined;
61
+ onEncrypted?: React.ReactEventHandler<HTMLImageElement> | undefined;
62
+ onEncryptedCapture?: React.ReactEventHandler<HTMLImageElement> | undefined;
63
+ onEnded?: React.ReactEventHandler<HTMLImageElement> | undefined;
64
+ onEndedCapture?: React.ReactEventHandler<HTMLImageElement> | undefined;
65
+ onLoadedData?: React.ReactEventHandler<HTMLImageElement> | undefined;
66
+ onLoadedDataCapture?: React.ReactEventHandler<HTMLImageElement> | undefined;
67
+ onLoadedMetadata?: React.ReactEventHandler<HTMLImageElement> | undefined;
68
+ onLoadedMetadataCapture?: React.ReactEventHandler<HTMLImageElement> | undefined;
69
+ onLoadStart?: React.ReactEventHandler<HTMLImageElement> | undefined;
70
+ onLoadStartCapture?: React.ReactEventHandler<HTMLImageElement> | undefined;
71
+ onPause?: React.ReactEventHandler<HTMLImageElement> | undefined;
72
+ onPauseCapture?: React.ReactEventHandler<HTMLImageElement> | undefined;
73
+ onPlay?: React.ReactEventHandler<HTMLImageElement> | undefined;
74
+ onPlayCapture?: React.ReactEventHandler<HTMLImageElement> | undefined;
75
+ onPlaying?: React.ReactEventHandler<HTMLImageElement> | undefined;
76
+ onPlayingCapture?: React.ReactEventHandler<HTMLImageElement> | undefined;
77
+ onProgress?: React.ReactEventHandler<HTMLImageElement> | undefined;
78
+ onProgressCapture?: React.ReactEventHandler<HTMLImageElement> | undefined;
79
+ onRateChange?: React.ReactEventHandler<HTMLImageElement> | undefined;
80
+ onRateChangeCapture?: React.ReactEventHandler<HTMLImageElement> | undefined;
81
+ onSeeked?: React.ReactEventHandler<HTMLImageElement> | undefined;
82
+ onSeekedCapture?: React.ReactEventHandler<HTMLImageElement> | undefined;
83
+ onSeeking?: React.ReactEventHandler<HTMLImageElement> | undefined;
84
+ onSeekingCapture?: React.ReactEventHandler<HTMLImageElement> | undefined;
85
+ onStalled?: React.ReactEventHandler<HTMLImageElement> | undefined;
86
+ onStalledCapture?: React.ReactEventHandler<HTMLImageElement> | undefined;
87
+ onSuspend?: React.ReactEventHandler<HTMLImageElement> | undefined;
88
+ onSuspendCapture?: React.ReactEventHandler<HTMLImageElement> | undefined;
89
+ onTimeUpdate?: React.ReactEventHandler<HTMLImageElement> | undefined;
90
+ onTimeUpdateCapture?: React.ReactEventHandler<HTMLImageElement> | undefined;
91
+ onVolumeChange?: React.ReactEventHandler<HTMLImageElement> | undefined;
92
+ onVolumeChangeCapture?: React.ReactEventHandler<HTMLImageElement> | undefined;
93
+ onWaiting?: React.ReactEventHandler<HTMLImageElement> | undefined;
94
+ onWaitingCapture?: React.ReactEventHandler<HTMLImageElement> | undefined;
95
+ onAuxClick?: React.MouseEventHandler<HTMLImageElement> | undefined;
96
+ onAuxClickCapture?: React.MouseEventHandler<HTMLImageElement> | undefined;
97
+ onClick?: React.MouseEventHandler<HTMLImageElement> | undefined;
98
+ onClickCapture?: React.MouseEventHandler<HTMLImageElement> | undefined;
99
+ onContextMenu?: React.MouseEventHandler<HTMLImageElement> | undefined;
100
+ onContextMenuCapture?: React.MouseEventHandler<HTMLImageElement> | undefined;
101
+ onDoubleClick?: React.MouseEventHandler<HTMLImageElement> | undefined;
102
+ onDoubleClickCapture?: React.MouseEventHandler<HTMLImageElement> | undefined;
103
+ onDrag?: React.DragEventHandler<HTMLImageElement> | undefined;
104
+ onDragCapture?: React.DragEventHandler<HTMLImageElement> | undefined;
105
+ onDragEnd?: React.DragEventHandler<HTMLImageElement> | undefined;
106
+ onDragEndCapture?: React.DragEventHandler<HTMLImageElement> | undefined;
107
+ onDragEnter?: React.DragEventHandler<HTMLImageElement> | undefined;
108
+ onDragEnterCapture?: React.DragEventHandler<HTMLImageElement> | undefined;
109
+ onDragExit?: React.DragEventHandler<HTMLImageElement> | undefined;
110
+ onDragExitCapture?: React.DragEventHandler<HTMLImageElement> | undefined;
111
+ onDragLeave?: React.DragEventHandler<HTMLImageElement> | undefined;
112
+ onDragLeaveCapture?: React.DragEventHandler<HTMLImageElement> | undefined;
113
+ onDragOver?: React.DragEventHandler<HTMLImageElement> | undefined;
114
+ onDragOverCapture?: React.DragEventHandler<HTMLImageElement> | undefined;
115
+ onDragStart?: React.DragEventHandler<HTMLImageElement> | undefined;
116
+ onDragStartCapture?: React.DragEventHandler<HTMLImageElement> | undefined;
117
+ onDrop?: React.DragEventHandler<HTMLImageElement> | undefined;
118
+ onDropCapture?: React.DragEventHandler<HTMLImageElement> | undefined;
119
+ onMouseDown?: React.MouseEventHandler<HTMLImageElement> | undefined;
120
+ onMouseDownCapture?: React.MouseEventHandler<HTMLImageElement> | undefined;
121
+ onMouseEnter?: React.MouseEventHandler<HTMLImageElement> | undefined;
122
+ onMouseLeave?: React.MouseEventHandler<HTMLImageElement> | undefined;
123
+ onMouseMove?: React.MouseEventHandler<HTMLImageElement> | undefined;
124
+ onMouseMoveCapture?: React.MouseEventHandler<HTMLImageElement> | undefined;
125
+ onMouseOut?: React.MouseEventHandler<HTMLImageElement> | undefined;
126
+ onMouseOutCapture?: React.MouseEventHandler<HTMLImageElement> | undefined;
127
+ onMouseOver?: React.MouseEventHandler<HTMLImageElement> | undefined;
128
+ onMouseOverCapture?: React.MouseEventHandler<HTMLImageElement> | undefined;
129
+ onMouseUp?: React.MouseEventHandler<HTMLImageElement> | undefined;
130
+ onMouseUpCapture?: React.MouseEventHandler<HTMLImageElement> | undefined;
131
+ onSelect?: React.ReactEventHandler<HTMLImageElement> | undefined;
132
+ onSelectCapture?: React.ReactEventHandler<HTMLImageElement> | undefined;
133
+ onTouchCancel?: React.TouchEventHandler<HTMLImageElement> | undefined;
134
+ onTouchCancelCapture?: React.TouchEventHandler<HTMLImageElement> | undefined;
135
+ onTouchEnd?: React.TouchEventHandler<HTMLImageElement> | undefined;
136
+ onTouchEndCapture?: React.TouchEventHandler<HTMLImageElement> | undefined;
137
+ onTouchMove?: React.TouchEventHandler<HTMLImageElement> | undefined;
138
+ onTouchMoveCapture?: React.TouchEventHandler<HTMLImageElement> | undefined;
139
+ onTouchStart?: React.TouchEventHandler<HTMLImageElement> | undefined;
140
+ onTouchStartCapture?: React.TouchEventHandler<HTMLImageElement> | undefined;
141
+ onPointerDown?: React.PointerEventHandler<HTMLImageElement> | undefined;
142
+ onPointerDownCapture?: React.PointerEventHandler<HTMLImageElement> | undefined;
143
+ onPointerMove?: React.PointerEventHandler<HTMLImageElement> | undefined;
144
+ onPointerMoveCapture?: React.PointerEventHandler<HTMLImageElement> | undefined;
145
+ onPointerUp?: React.PointerEventHandler<HTMLImageElement> | undefined;
146
+ onPointerUpCapture?: React.PointerEventHandler<HTMLImageElement> | undefined;
147
+ onPointerCancel?: React.PointerEventHandler<HTMLImageElement> | undefined;
148
+ onPointerCancelCapture?: React.PointerEventHandler<HTMLImageElement> | undefined;
149
+ onPointerEnter?: React.PointerEventHandler<HTMLImageElement> | undefined;
150
+ onPointerLeave?: React.PointerEventHandler<HTMLImageElement> | undefined;
151
+ onPointerOver?: React.PointerEventHandler<HTMLImageElement> | undefined;
152
+ onPointerOverCapture?: React.PointerEventHandler<HTMLImageElement> | undefined;
153
+ onPointerOut?: React.PointerEventHandler<HTMLImageElement> | undefined;
154
+ onPointerOutCapture?: React.PointerEventHandler<HTMLImageElement> | undefined;
155
+ onGotPointerCapture?: React.PointerEventHandler<HTMLImageElement> | undefined;
156
+ onGotPointerCaptureCapture?: React.PointerEventHandler<HTMLImageElement> | undefined;
157
+ onLostPointerCapture?: React.PointerEventHandler<HTMLImageElement> | undefined;
158
+ onLostPointerCaptureCapture?: React.PointerEventHandler<HTMLImageElement> | undefined;
159
+ onScroll?: React.UIEventHandler<HTMLImageElement> | undefined;
160
+ onScrollCapture?: React.UIEventHandler<HTMLImageElement> | undefined;
161
+ onScrollEnd?: React.UIEventHandler<HTMLImageElement> | undefined;
162
+ onScrollEndCapture?: React.UIEventHandler<HTMLImageElement> | undefined;
163
+ onWheel?: React.WheelEventHandler<HTMLImageElement> | undefined;
164
+ onWheelCapture?: React.WheelEventHandler<HTMLImageElement> | undefined;
165
+ onAnimationStart?: React.AnimationEventHandler<HTMLImageElement> | undefined;
166
+ onAnimationStartCapture?: React.AnimationEventHandler<HTMLImageElement> | undefined;
167
+ onAnimationEnd?: React.AnimationEventHandler<HTMLImageElement> | undefined;
168
+ onAnimationEndCapture?: React.AnimationEventHandler<HTMLImageElement> | undefined;
169
+ onAnimationIteration?: React.AnimationEventHandler<HTMLImageElement> | undefined;
170
+ onAnimationIterationCapture?: React.AnimationEventHandler<HTMLImageElement> | undefined;
171
+ onToggle?: React.ToggleEventHandler<HTMLImageElement> | undefined;
172
+ onBeforeToggle?: React.ToggleEventHandler<HTMLImageElement> | undefined;
173
+ onTransitionCancel?: React.TransitionEventHandler<HTMLImageElement> | undefined;
174
+ onTransitionCancelCapture?: React.TransitionEventHandler<HTMLImageElement> | undefined;
175
+ onTransitionEnd?: React.TransitionEventHandler<HTMLImageElement> | undefined;
176
+ onTransitionEndCapture?: React.TransitionEventHandler<HTMLImageElement> | undefined;
177
+ onTransitionRun?: React.TransitionEventHandler<HTMLImageElement> | undefined;
178
+ onTransitionRunCapture?: React.TransitionEventHandler<HTMLImageElement> | undefined;
179
+ onTransitionStart?: React.TransitionEventHandler<HTMLImageElement> | undefined;
180
+ onTransitionStartCapture?: React.TransitionEventHandler<HTMLImageElement> | undefined;
181
+ "aria-activedescendant"?: string | undefined;
182
+ "aria-atomic"?: ("false" | "true" | boolean) | undefined;
183
+ "aria-autocomplete"?: "both" | "inline" | "list" | "none" | undefined;
184
+ "aria-braillelabel"?: string | undefined;
185
+ "aria-brailleroledescription"?: string | undefined;
186
+ "aria-busy"?: ("false" | "true" | boolean) | undefined;
187
+ "aria-checked"?: "false" | "mixed" | "true" | boolean | undefined;
188
+ "aria-colcount"?: number | undefined;
189
+ "aria-colindex"?: number | undefined;
190
+ "aria-colindextext"?: string | undefined;
191
+ "aria-colspan"?: number | undefined;
192
+ "aria-controls"?: string | undefined;
193
+ "aria-current"?: "date" | "false" | "location" | "page" | "step" | "time" | "true" | boolean | undefined;
194
+ "aria-describedby"?: string | undefined;
195
+ "aria-description"?: string | undefined;
196
+ "aria-details"?: string | undefined;
197
+ "aria-disabled"?: ("false" | "true" | boolean) | undefined;
198
+ "aria-dropeffect"?: "copy" | "execute" | "link" | "move" | "none" | "popup" | undefined;
199
+ "aria-errormessage"?: string | undefined;
200
+ "aria-expanded"?: ("false" | "true" | boolean) | undefined;
201
+ "aria-flowto"?: string | undefined;
202
+ "aria-grabbed"?: ("false" | "true" | boolean) | undefined;
203
+ "aria-haspopup"?: "dialog" | "false" | "grid" | "listbox" | "menu" | "tree" | "true" | boolean | undefined;
204
+ "aria-hidden"?: ("false" | "true" | boolean) | undefined;
205
+ "aria-invalid"?: "false" | "grammar" | "spelling" | "true" | boolean | undefined;
206
+ "aria-keyshortcuts"?: string | undefined;
207
+ "aria-label"?: string | undefined;
208
+ "aria-labelledby"?: string | undefined;
209
+ "aria-level"?: number | undefined;
210
+ "aria-live"?: "assertive" | "off" | "polite" | undefined;
211
+ "aria-modal"?: ("false" | "true" | boolean) | undefined;
212
+ "aria-multiline"?: ("false" | "true" | boolean) | undefined;
213
+ "aria-multiselectable"?: ("false" | "true" | boolean) | undefined;
214
+ "aria-orientation"?: "horizontal" | "vertical" | undefined;
215
+ "aria-owns"?: string | undefined;
216
+ "aria-placeholder"?: string | undefined;
217
+ "aria-posinset"?: number | undefined;
218
+ "aria-pressed"?: "false" | "mixed" | "true" | boolean | undefined;
219
+ "aria-readonly"?: ("false" | "true" | boolean) | undefined;
220
+ "aria-relevant"?: "additions" | "additions removals" | "additions text" | "all" | "removals" | "removals additions" | "removals text" | "text" | "text additions" | "text removals" | undefined;
221
+ "aria-required"?: ("false" | "true" | boolean) | undefined;
222
+ "aria-roledescription"?: string | undefined;
223
+ "aria-rowcount"?: number | undefined;
224
+ "aria-rowindex"?: number | undefined;
225
+ "aria-rowindextext"?: string | undefined;
226
+ "aria-rowspan"?: number | undefined;
227
+ "aria-selected"?: ("false" | "true" | boolean) | undefined;
228
+ "aria-setsize"?: number | undefined;
229
+ "aria-sort"?: "ascending" | "descending" | "none" | "other" | undefined;
230
+ "aria-valuemax"?: number | undefined;
231
+ "aria-valuemin"?: number | undefined;
232
+ "aria-valuenow"?: number | undefined;
233
+ "aria-valuetext"?: string | undefined;
234
+ defaultChecked?: boolean | undefined;
235
+ defaultValue?: string | number | readonly string[] | undefined;
236
+ suppressContentEditableWarning?: boolean | undefined;
237
+ suppressHydrationWarning?: boolean | undefined;
238
+ accessKey?: string | undefined;
239
+ autoCapitalize?: "characters" | "none" | "off" | "on" | "sentences" | "words" | (string & {}) | undefined;
240
+ autoFocus?: boolean | undefined;
241
+ className?: string | undefined;
242
+ contentEditable?: "inherit" | "plaintext-only" | ("false" | "true" | boolean) | undefined;
243
+ contextMenu?: string | undefined;
244
+ dir?: string | undefined;
245
+ draggable?: ("false" | "true" | boolean) | undefined;
246
+ enterKeyHint?: "done" | "enter" | "go" | "next" | "previous" | "search" | "send" | undefined;
247
+ hidden?: boolean | undefined;
248
+ id?: string | undefined;
249
+ lang?: string | undefined;
250
+ nonce?: string | undefined;
251
+ slot?: string | undefined;
252
+ spellCheck?: ("false" | "true" | boolean) | undefined;
253
+ style?: React.CSSProperties | undefined;
254
+ tabIndex?: number | undefined;
255
+ title?: string | undefined;
256
+ translate?: "no" | "yes" | undefined;
257
+ radioGroup?: string | undefined;
258
+ role?: React.AriaRole | undefined;
259
+ about?: string | undefined;
260
+ content?: string | undefined;
261
+ datatype?: string | undefined;
262
+ inlist?: any;
263
+ prefix?: string | undefined;
264
+ property?: string | undefined;
265
+ rel?: string | undefined;
266
+ resource?: string | undefined;
267
+ rev?: string | undefined;
268
+ typeof?: string | undefined;
269
+ vocab?: string | undefined;
270
+ autoCorrect?: string | undefined;
271
+ autoSave?: string | undefined;
272
+ color?: string | undefined;
273
+ itemProp?: string | undefined;
274
+ itemScope?: boolean | undefined;
275
+ itemType?: string | undefined;
276
+ itemID?: string | undefined;
277
+ itemRef?: string | undefined;
278
+ results?: number | undefined;
279
+ security?: string | undefined;
280
+ unselectable?: "off" | "on" | undefined;
281
+ popover?: "" | "auto" | "hint" | "manual" | undefined;
282
+ popoverTargetAction?: "hide" | "show" | "toggle" | undefined;
283
+ popoverTarget?: string | undefined;
284
+ inert?: boolean | undefined;
285
+ inputMode?: "decimal" | "email" | "none" | "numeric" | "search" | "tel" | "text" | "url" | undefined;
286
+ is?: string | undefined;
287
+ exportparts?: string | undefined;
288
+ part?: string | undefined;
289
+ alt?: string | undefined;
290
+ crossOrigin?: "" | "anonymous" | "use-credentials" | undefined;
291
+ decoding?: "async" | "auto" | "sync" | undefined;
292
+ fetchPriority?: "auto" | "high" | "low" | undefined;
293
+ height?: string | number | undefined;
294
+ loading?: "eager" | "lazy" | undefined;
295
+ referrerPolicy?: React.HTMLAttributeReferrerPolicy | undefined;
296
+ sizes?: string | undefined;
297
+ srcSet?: string | undefined;
298
+ useMap?: string | undefined;
299
+ width?: string | number | undefined;
300
+ src: string;
301
+ }, HTMLElement> | null;
302
+ export default ImgFile;
@@ -0,0 +1,133 @@
1
+ import { LRUMap } from "@adviser/cement";
2
+ import React, { useState, useEffect, useLayoutEffect, useRef, useMemo } from "react";
3
+ const objectUrlCache = new LRUMap({
4
+ maxEntries: 50,
5
+ });
6
+ function isFile(obj) {
7
+ return "type" in obj && "size" in obj && "stream" in obj && typeof obj.stream === "function";
8
+ }
9
+ function isFileMeta(obj) {
10
+ return "type" in obj && "size" in obj && "file" in obj && typeof obj.file === "function";
11
+ }
12
+ function getCacheKey(fileObj) {
13
+ return `file:${fileObj.name}-${fileObj.size}-${fileObj.lastModified}`;
14
+ }
15
+ function getObjectUrlByKey(cacheKey, fileObj) {
16
+ if (!objectUrlCache.has(cacheKey)) {
17
+ objectUrlCache.set(cacheKey, URL.createObjectURL(fileObj));
18
+ }
19
+ return objectUrlCache.get(cacheKey);
20
+ }
21
+ async function loadFile({ fileData, fileObjRef, cleanupRef, setImgDataUrl, keyRef, }) {
22
+ let fileObj = null;
23
+ let fileType = "";
24
+ if (fileData) {
25
+ switch (true) {
26
+ case isFile(fileData):
27
+ fileObj = fileData;
28
+ fileType = fileData.type;
29
+ break;
30
+ case isFileMeta(fileData):
31
+ fileType = fileData.type;
32
+ fileObj = typeof fileData.file === "function" ? await fileData.file() : null;
33
+ break;
34
+ }
35
+ }
36
+ const currentKey = keyRef.current ?? null;
37
+ const newKey = fileData && isFileMeta(fileData) && fileData.cid
38
+ ? `cid:${String(fileData.cid)}`
39
+ : fileData && isFile(fileData)
40
+ ? getCacheKey(fileData)
41
+ : null;
42
+ const isDifferentFile = currentKey !== newKey;
43
+ const canReuseCache = !isDifferentFile && newKey && objectUrlCache.has(newKey);
44
+ if (fileObj && /image/.test(fileType)) {
45
+ if (isDifferentFile && newKey) {
46
+ const src = getObjectUrlByKey(newKey, fileObj);
47
+ setImgDataUrl(src);
48
+ fileObjRef.current = fileObj;
49
+ const prevCleanup = cleanupRef.current;
50
+ const newCleanupObj = {
51
+ contentKey: newKey,
52
+ revoke: () => {
53
+ if (objectUrlCache.has(newKey)) {
54
+ URL.revokeObjectURL(objectUrlCache.get(newKey));
55
+ objectUrlCache.delete(newKey);
56
+ }
57
+ },
58
+ };
59
+ keyRef.current = newKey;
60
+ if (prevCleanup && prevCleanup.revoke) {
61
+ prevCleanup.revoke();
62
+ }
63
+ return newCleanupObj;
64
+ }
65
+ if (canReuseCache && newKey) {
66
+ const src = objectUrlCache.get(newKey);
67
+ setImgDataUrl(src);
68
+ fileObjRef.current = fileObj;
69
+ keyRef.current = newKey;
70
+ return cleanupRef.current;
71
+ }
72
+ return cleanupRef.current;
73
+ }
74
+ return null;
75
+ }
76
+ export function ImgFile({ file, meta, ...imgProps }) {
77
+ const [imgDataUrl, setImgDataUrl] = useState("");
78
+ const fileObjRef = useRef(null);
79
+ const cleanupRef = useRef(null);
80
+ const keyRef = useRef(null);
81
+ const nextFileDataRef = useRef(undefined);
82
+ const fileData = useMemo(() => {
83
+ return file || meta;
84
+ }, [file, meta]);
85
+ useLayoutEffect(() => {
86
+ nextFileDataRef.current = fileData;
87
+ }, [fileData]);
88
+ useEffect(() => {
89
+ if (!fileData)
90
+ return;
91
+ let isMounted = true;
92
+ loadFile({ fileData, fileObjRef, cleanupRef, setImgDataUrl, keyRef }).then(function handleResult(result) {
93
+ if (isMounted) {
94
+ cleanupRef.current = result;
95
+ }
96
+ else if (result && result.revoke) {
97
+ result.revoke();
98
+ }
99
+ });
100
+ return function cleanupEffect() {
101
+ isMounted = false;
102
+ if (cleanupRef.current) {
103
+ const currentContentKey = cleanupRef.current.contentKey;
104
+ let nextContentKey = null;
105
+ const upcomingFileData = nextFileDataRef.current;
106
+ if (upcomingFileData) {
107
+ if (isFileMeta(upcomingFileData) && upcomingFileData.cid) {
108
+ nextContentKey = `cid:${String(upcomingFileData.cid)}`;
109
+ }
110
+ else if (isFile(upcomingFileData)) {
111
+ nextContentKey = `file:${upcomingFileData.name}-${upcomingFileData.size}-${upcomingFileData.lastModified}`;
112
+ }
113
+ }
114
+ const isContentChanging = currentContentKey !== nextContentKey;
115
+ const isFileObject = currentContentKey?.startsWith("file:");
116
+ const isDocFileMetaObject = currentContentKey?.startsWith("cid:");
117
+ const shouldCleanup = isFileObject || (isDocFileMetaObject && isContentChanging);
118
+ if (shouldCleanup && cleanupRef.current.revoke) {
119
+ cleanupRef.current.revoke();
120
+ }
121
+ cleanupRef.current = null;
122
+ }
123
+ };
124
+ }, [fileData]);
125
+ return imgDataUrl
126
+ ? React.createElement("img", {
127
+ src: imgDataUrl,
128
+ ...imgProps,
129
+ })
130
+ : null;
131
+ }
132
+ export default ImgFile;
133
+ //# sourceMappingURL=img-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"img-file.js","sourceRoot":"","sources":["../../jsr/react/img-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,EAAE,OAAO,EAAqB,MAAM,OAAO,CAAC;AAIxG,MAAM,cAAc,GAAG,IAAI,MAAM,CAAiB;IAChD,UAAU,EAAE,EAAE;CACf,CAAC,CAAC;AAeH,SAAS,MAAM,CAAC,GAAa,EAAe;IAC1C,OAAO,MAAM,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG,IAAI,QAAQ,IAAI,GAAG,IAAI,OAAO,GAAG,CAAC,MAAM,KAAK,UAAU,CAAC;AAAA,CAC9F;AAGD,SAAS,UAAU,CAAC,GAAa,EAAsB;IACrD,OAAO,MAAM,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,UAAU,CAAC;AAAA,CAC1F;AAGD,SAAS,WAAW,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AG,IAAI,CAAC;YAC5B,CAAC;QAAA,CACF,CAAC;IAAA,CACH,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,OAAO,UAAU;QACf,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,EAAE;YACzB,GAAG,EAAE,UAAU;YACf,GAAG,QAAQ;SACZ,CAAC;QACJ,CAAC,CAAC,IAAI,CAAC;AAAA,CACV;AAED,eAAe,OAAO,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { FireproofCtx, useFireproof } from "./use-fireproof.js";
2
+ export * from "./types.js";
3
+ export * from "./img-file.js";
4
+ export * from "./use-attach.js";
package/react/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { FireproofCtx, useFireproof } from "./use-fireproof.js";
2
+ export * from "./types.js";
3
+ export * from "./img-file.js";
4
+ export * from "./use-attach.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../jsr/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAChE,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,90 @@
1
+ import type { AllDocsQueryOpts, Attached, ChangesOptions, ClockHead, ConfigOpts, Database, DocFragment, DocResponse, DocSet, DocTypes, DocWithId, IndexKeyType, FPIndexRow, MapFn, QueryOpts, SuperThis, KeyBagIf, IndexRowsWithDocs } from "@fireproof/core-types-base";
2
+ import { ToCloudAttachable, TokenAndClaims } from "@fireproof/core-types-protocols-cloud";
3
+ export interface HookResult {
4
+ readonly hydrated: boolean;
5
+ }
6
+ export type LiveQueryResult<T extends DocTypes, K extends IndexKeyType, R extends DocFragment = T> = IndexRowsWithDocs<T, K, R> & HookResult;
7
+ export type UseLiveQuery = <T extends DocTypes, K extends IndexKeyType = string, R extends DocFragment = T>(mapFn: string | MapFn<T>, query?: Partial<QueryOpts<K>>, initialRows?: FPIndexRow<K, T, R>[]) => LiveQueryResult<T, K, R>;
8
+ export interface AllDocsResult<T extends DocTypes> extends HookResult {
9
+ readonly docs: DocWithId<T>[];
10
+ }
11
+ export interface ChangesResult<T extends DocTypes> extends HookResult {
12
+ readonly docs: DocWithId<T>[];
13
+ }
14
+ export type UseAllDocs = <T extends DocTypes>(query?: Partial<AllDocsQueryOpts>) => AllDocsResult<T>;
15
+ export type UseChanges = <T extends DocTypes>(since: ClockHead, opts: ChangesOptions) => ChangesResult<T>;
16
+ export interface UpdateDocFnOptions {
17
+ replace?: boolean;
18
+ reset?: boolean;
19
+ }
20
+ export type UpdateDocFn<T extends DocTypes> = (newDoc?: DocSet<T>, options?: UpdateDocFnOptions) => void;
21
+ export type StoreDocFn<T extends DocTypes> = (existingDoc?: DocWithId<T>) => Promise<DocResponse>;
22
+ export type DeleteDocFn<T extends DocTypes> = (existingDoc?: DocWithId<T>) => Promise<DocResponse>;
23
+ export type UseDocumentResultTuple<T extends DocTypes> = [DocWithId<T>, UpdateDocFn<T>, StoreDocFn<T>, DeleteDocFn<T>];
24
+ export interface UseDocumentResultObject<T extends DocTypes> extends HookResult {
25
+ readonly doc: DocWithId<T>;
26
+ merge(newDoc: Partial<T>): void;
27
+ replace(newDoc: T): void;
28
+ reset(): void;
29
+ refresh(): Promise<void>;
30
+ save(existingDoc?: DocWithId<T>): Promise<DocResponse>;
31
+ remove(existingDoc?: DocWithId<T>): Promise<DocResponse>;
32
+ submit(e?: Event): Promise<void>;
33
+ }
34
+ export type AttachStatus = "initial" | "attaching" | "attached" | "error";
35
+ export interface InitialAttachState {
36
+ readonly state: "initial";
37
+ readonly ctx: WebCtxHook;
38
+ }
39
+ export interface AttachingAttachState {
40
+ readonly state: "attaching";
41
+ readonly ctx: WebCtxHook;
42
+ }
43
+ export interface AttachedAttachState {
44
+ readonly state: "attached";
45
+ readonly attached: Attached;
46
+ readonly ctx: WebCtxHook;
47
+ }
48
+ export interface ErrorAttachState {
49
+ readonly state: "error";
50
+ readonly error: Error;
51
+ readonly ctx: WebCtxHook;
52
+ }
53
+ export type AttachState = InitialAttachState | AttachingAttachState | AttachedAttachState | ErrorAttachState;
54
+ export type UseDocumentResult<T extends DocTypes> = UseDocumentResultObject<T> & UseDocumentResultTuple<T>;
55
+ export type UseDocumentInitialDocOrFn<T extends DocTypes> = DocSet<T> | (() => DocSet<T>);
56
+ export type UseDocument = <T extends DocTypes>(initialDocOrFn: UseDocumentInitialDocOrFn<T>) => UseDocumentResult<T>;
57
+ export interface UseFireproof {
58
+ readonly database: Database;
59
+ readonly useDocument: UseDocument;
60
+ readonly useLiveQuery: UseLiveQuery;
61
+ readonly useAllDocs: UseAllDocs;
62
+ readonly useChanges: UseChanges;
63
+ readonly attach: AttachState;
64
+ }
65
+ export interface InitialTokenAndClaimsState {
66
+ readonly state: "initial";
67
+ }
68
+ export interface ReadyTokenAndClaimsState {
69
+ readonly state: "ready";
70
+ readonly tokenAndClaims: TokenAndClaims;
71
+ readonly reset: () => void;
72
+ }
73
+ export interface WebCtxHook {
74
+ readonly tokenAndClaims: InitialTokenAndClaimsState | ReadyTokenAndClaimsState;
75
+ }
76
+ export interface WebToCloudCtx {
77
+ readonly sthis: SuperThis;
78
+ readonly dashboardURI: string;
79
+ readonly tokenApiURI: string;
80
+ keyBag?: KeyBagIf;
81
+ readonly tokenParam: string;
82
+ ready(db: Database): Promise<void>;
83
+ onTokenChange(on: (token?: TokenAndClaims) => void): void;
84
+ resetToken(): Promise<void>;
85
+ setToken(token: TokenAndClaims | string): Promise<void>;
86
+ token(): Promise<TokenAndClaims | undefined>;
87
+ }
88
+ export type UseFPConfig = ConfigOpts & {
89
+ readonly attach?: ToCloudAttachable;
90
+ };
package/react/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../jsr/react/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ import type { AllDocsQueryOpts, Database } from "@fireproof/core-types-base";
2
+ import type { AllDocsResult } from "./types.js";
3
+ export declare function createUseAllDocs(database: Database): <T extends {}>(query?: Partial<AllDocsQueryOpts>) => AllDocsResult<T>;
@@ -0,0 +1,35 @@
1
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
2
+ export function createUseAllDocs(database) {
3
+ return function useAllDocs(query = {}) {
4
+ const [hydrated, setHydrated] = useState(false);
5
+ const [result, setResult] = useState({
6
+ docs: [],
7
+ });
8
+ const queryString = useMemo(() => JSON.stringify(query), [query]);
9
+ const requestIdRef = useRef(0);
10
+ useEffect(() => {
11
+ setHydrated(false);
12
+ requestIdRef.current += 1;
13
+ }, [queryString]);
14
+ const refreshRows = useCallback(async () => {
15
+ const myReq = ++requestIdRef.current;
16
+ const res = await database.allDocs(query);
17
+ if (myReq === requestIdRef.current) {
18
+ setResult({
19
+ ...res,
20
+ docs: res.rows.map((r) => r.value),
21
+ });
22
+ setHydrated(true);
23
+ }
24
+ }, [database, query, queryString]);
25
+ useEffect(() => {
26
+ refreshRows();
27
+ const unsubscribe = database.subscribe(refreshRows);
28
+ return () => {
29
+ unsubscribe();
30
+ };
31
+ }, [database, refreshRows]);
32
+ return { ...result, hydrated };
33
+ };
34
+ }
35
+ //# sourceMappingURL=use-all-docs.js.map