@hvakr/firestate 0.1.6 → 0.1.7
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/README.md +8 -3
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +6 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -340,9 +340,14 @@ This distinction is important for collaborative applications where multiple user
|
|
|
340
340
|
|
|
341
341
|
### Undo/Redo
|
|
342
342
|
|
|
343
|
-
|
|
343
|
+
Undo tracking is opt-in per resource. Enable it on the hook, then each update
|
|
344
|
+
automatically creates an undo action. Actions with the same `undoGroupId` are
|
|
345
|
+
merged:
|
|
344
346
|
|
|
345
347
|
```tsx
|
|
348
|
+
const project = useProject({ projectId }, { undoable: true })
|
|
349
|
+
const spaces = useSpaces({ projectId }, { undoable: true })
|
|
350
|
+
|
|
346
351
|
const groupId = crypto.randomUUID()
|
|
347
352
|
|
|
348
353
|
// These two updates become a single undo action
|
|
@@ -353,7 +358,7 @@ spaces.update({ space1: { name: 'Updated' } }, { undoGroupId: groupId })
|
|
|
353
358
|
Grouped actions undo newest-first and redo oldest-first, so one undo/redo
|
|
354
359
|
always applies the complete group in write order.
|
|
355
360
|
|
|
356
|
-
|
|
361
|
+
After opting in, exclude an individual write from undo tracking with:
|
|
357
362
|
|
|
358
363
|
```tsx
|
|
359
364
|
project.update({ lastViewed: Date.now() }, { undoable: false })
|
|
@@ -683,7 +688,7 @@ const {
|
|
|
683
688
|
definition: projectDoc,
|
|
684
689
|
params: { projectId: '123' },
|
|
685
690
|
readOnly: false, // Optional: override read-only
|
|
686
|
-
undoable: true, // Optional: enable undo (default:
|
|
691
|
+
undoable: true, // Optional: enable undo (default: false)
|
|
687
692
|
enabled: true, // Optional: set false until required params exist
|
|
688
693
|
})
|
|
689
694
|
|
package/dist/index.d.mts
CHANGED
|
@@ -674,7 +674,7 @@ interface UseDocumentOptions<TData extends FirestoreObject> {
|
|
|
674
674
|
params?: Record<string, string>;
|
|
675
675
|
/** Override read-only setting */
|
|
676
676
|
readOnly?: boolean;
|
|
677
|
-
/** Enable undo/redo for this document (default:
|
|
677
|
+
/** Enable undo/redo for this document (default: false) */
|
|
678
678
|
undoable?: boolean;
|
|
679
679
|
/**
|
|
680
680
|
* If false, no subscription is created and a no-op handle is returned
|
|
@@ -764,7 +764,7 @@ interface UseCollectionOptions<TData extends FirestoreObject> {
|
|
|
764
764
|
readOnly?: boolean;
|
|
765
765
|
/** Additional query constraints */
|
|
766
766
|
queryConstraints?: QueryConstraint[];
|
|
767
|
-
/** Enable undo/redo for this collection (default:
|
|
767
|
+
/** Enable undo/redo for this collection (default: false) */
|
|
768
768
|
undoable?: boolean;
|
|
769
769
|
/**
|
|
770
770
|
* If false, no subscription is created and a no-op handle is returned
|
package/dist/index.mjs
CHANGED
|
@@ -1279,14 +1279,14 @@ const getDocumentShared = ({ store, definition, collectionPath, docId, readOnly
|
|
|
1279
1279
|
const entry = {
|
|
1280
1280
|
sub: null,
|
|
1281
1281
|
refCount: 0,
|
|
1282
|
-
undoableEnabled:
|
|
1282
|
+
undoableEnabled: false,
|
|
1283
1283
|
live: true
|
|
1284
1284
|
};
|
|
1285
1285
|
entry.sub = buildSub(entry);
|
|
1286
1286
|
return entry;
|
|
1287
1287
|
};
|
|
1288
1288
|
let ent = map.get(key) ?? buildEntry();
|
|
1289
|
-
let desiredUndoable =
|
|
1289
|
+
let desiredUndoable = false;
|
|
1290
1290
|
let readOnlySource = null;
|
|
1291
1291
|
let readOnlyHandle = null;
|
|
1292
1292
|
return {
|
|
@@ -1361,7 +1361,7 @@ const getCollectionShared = ({ store, definition, collectionPath, readOnly, quer
|
|
|
1361
1361
|
const entry = {
|
|
1362
1362
|
sub: null,
|
|
1363
1363
|
refCount: 0,
|
|
1364
|
-
undoableEnabled:
|
|
1364
|
+
undoableEnabled: false,
|
|
1365
1365
|
live: true,
|
|
1366
1366
|
query: query$1
|
|
1367
1367
|
};
|
|
@@ -1369,7 +1369,7 @@ const getCollectionShared = ({ store, definition, collectionPath, readOnly, quer
|
|
|
1369
1369
|
return entry;
|
|
1370
1370
|
};
|
|
1371
1371
|
let ent = bucket.find((e) => sameQuery(e.query, query$1)) ?? buildEntry();
|
|
1372
|
-
let desiredUndoable =
|
|
1372
|
+
let desiredUndoable = false;
|
|
1373
1373
|
let readOnlySource = null;
|
|
1374
1374
|
let readOnlyHandle = null;
|
|
1375
1375
|
return {
|
|
@@ -1571,7 +1571,7 @@ const useIsSynced = () => {
|
|
|
1571
1571
|
return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
1572
1572
|
};
|
|
1573
1573
|
function useDocument(options) {
|
|
1574
|
-
const { definition, params = {}, readOnly, undoable =
|
|
1574
|
+
const { definition, params = {}, readOnly, undoable = false, enabled = true, selector, isEqual } = options;
|
|
1575
1575
|
const store = useStore();
|
|
1576
1576
|
const docId = enabled ? typeof definition.id === "function" ? definition.id(params) : definition.id : void 0;
|
|
1577
1577
|
const collectionPath = enabled ? typeof definition.collection === "function" ? definition.collection(params) : definition.collection : void 0;
|
|
@@ -1640,7 +1640,7 @@ function useDocument(options) {
|
|
|
1640
1640
|
]);
|
|
1641
1641
|
}
|
|
1642
1642
|
function useCollection(options) {
|
|
1643
|
-
const { definition, params = {}, readOnly, queryConstraints, undoable =
|
|
1643
|
+
const { definition, params = {}, readOnly, queryConstraints, undoable = false, enabled = true, selector, isEqual } = options;
|
|
1644
1644
|
const store = useStore();
|
|
1645
1645
|
const collectionPath = enabled ? typeof definition.path === "function" ? definition.path(params) : definition.path : void 0;
|
|
1646
1646
|
const stableConstraintsRef = useRef(queryConstraints);
|