@instantdb/components 1.0.37 → 1.0.38

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.
@@ -47,7 +47,7 @@ import React, {
47
47
  useRef,
48
48
  useState,
49
49
  } from 'react';
50
- import { useExplorerProps, useExplorerState } from '.';
50
+ import { useExplorerDialog, useExplorerProps, useExplorerState } from '.';
51
51
  import { SearchInput } from './search-input';
52
52
 
53
53
  import { errorToast, successToast } from '@lib/components/toast';
@@ -256,9 +256,11 @@ export const InnerExplorer: React.FC<{
256
256
  const [customPath, setCustomPath] = useState('');
257
257
  const [deleteDataConfirmationOpen, setDeleteDataConfirmationOpen] =
258
258
  useState(false);
259
- const [editNs, setEditNs] = useState<SchemaNamespace | null>(null);
260
- const [editableRowId, setEditableRowId] = useState<string | null>(null);
261
- const [addItemDialogOpen, setAddItemDialogOpen] = useState(false);
259
+ const { dialog, setDialog } = useExplorerDialog();
260
+ const editNs =
261
+ dialog?.type === 'edit-schema' ? (selectedNamespace ?? null) : null;
262
+ const editableRowId = dialog?.type === 'edit-row' ? dialog.rowId : null;
263
+ const addItemDialogOpen = dialog?.type === 'add-row';
262
264
  const lastSelectedIdRef = useRef<string | null>(null);
263
265
  const [offsets, setOffsets] = useState<{ [namespace: string]: number }>({});
264
266
 
@@ -457,7 +459,7 @@ export const InnerExplorer: React.FC<{
457
459
  {readOnlyNs ? null : (
458
460
  <button
459
461
  className="translate-y-0.5 opacity-0 transition-opacity group-hover:opacity-100"
460
- onClick={() => setEditableRowId(row.id)}
462
+ onClick={() => setDialog({ type: 'edit-row', rowId: row.id })}
461
463
  >
462
464
  <PencilSquareIcon className="h-4 w-4 text-neutral-500 dark:text-neutral-400" />
463
465
  </button>
@@ -893,30 +895,30 @@ export const InnerExplorer: React.FC<{
893
895
  ) : null}
894
896
  </Dialog>
895
897
  <Dialog
896
- title="Edit Row"
898
+ title="Add Row"
897
899
  open={addItemDialogOpen}
898
- onClose={() => setAddItemDialogOpen(false)}
900
+ onClose={() => setDialog(null)}
899
901
  >
900
902
  {selectedNamespace ? (
901
903
  <EditRowDialog
902
904
  db={db}
903
905
  item={{}}
904
906
  namespace={selectedNamespace}
905
- onClose={() => setAddItemDialogOpen(false)}
907
+ onClose={() => setDialog(null)}
906
908
  />
907
909
  ) : null}
908
910
  </Dialog>
909
911
  <Dialog
910
912
  title="Edit Row"
911
913
  open={!!selectedEditableItem}
912
- onClose={() => setEditableRowId(null)}
914
+ onClose={() => setDialog(null)}
913
915
  >
914
916
  {!!selectedNamespace && !!selectedEditableItem ? (
915
917
  <EditRowDialog
916
918
  db={db}
917
919
  namespace={selectedNamespace}
918
920
  item={selectedEditableItem}
919
- onClose={() => setEditableRowId(null)}
921
+ onClose={() => setDialog(null)}
920
922
  />
921
923
  ) : null}
922
924
  </Dialog>
@@ -924,7 +926,7 @@ export const InnerExplorer: React.FC<{
924
926
  title="Edit Namespace"
925
927
  stopFocusPropagation={true}
926
928
  open={Boolean(editNs)}
927
- onClose={() => setEditNs(null)}
929
+ onClose={() => setDialog(null)}
928
930
  >
929
931
  {selectedNamespace ? (
930
932
  <EditNamespaceDialog
@@ -933,8 +935,17 @@ export const InnerExplorer: React.FC<{
933
935
  db={db}
934
936
  namespace={selectedNamespace}
935
937
  namespaces={namespaces ?? []}
938
+ screen={
939
+ dialog?.type === 'edit-schema' ? dialog.screen : { kind: 'main' }
940
+ }
941
+ onScreenChange={(s) =>
942
+ setDialog(
943
+ { type: 'edit-schema', screen: s },
944
+ { history: 'replace' },
945
+ )
946
+ }
936
947
  onClose={(p) => {
937
- setEditNs(null);
948
+ setDialog(null);
938
949
  if (p?.ok) {
939
950
  history.push({ namespace: namespaces?.[0].id });
940
951
  }
@@ -1015,7 +1026,10 @@ export const InnerExplorer: React.FC<{
1015
1026
  variant="secondary"
1016
1027
  size="mini"
1017
1028
  onClick={() => {
1018
- setEditNs(selectedNamespace);
1029
+ setDialog({
1030
+ type: 'edit-schema',
1031
+ screen: { kind: 'main' },
1032
+ });
1019
1033
  }}
1020
1034
  >
1021
1035
  Edit Schema
@@ -1092,7 +1106,7 @@ export const InnerExplorer: React.FC<{
1092
1106
  size="mini"
1093
1107
  variant="secondary"
1094
1108
  onClick={() => {
1095
- setAddItemDialogOpen(true);
1109
+ setDialog({ type: 'add-row' });
1096
1110
  }}
1097
1111
  >
1098
1112
  <PlusIcon width={12} />
package/src/index.tsx CHANGED
@@ -1,7 +1,11 @@
1
1
  import * as ui from './components/ui';
2
2
 
3
3
  export { Explorer } from './components/explorer/index';
4
- export type { ExplorerNav } from './components/explorer/index';
4
+ export type {
5
+ EditSchemaScreen,
6
+ ExplorerDialog,
7
+ ExplorerNav,
8
+ } from './components/explorer/index';
5
9
  export { StyleMe } from './components/StyleMe';
6
10
 
7
11
  export { ui };