@instantdb/components 0.0.1
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/.env +2 -0
- package/.turbo/turbo-build.log +18 -0
- package/README.md +78 -0
- package/app/App.css +38 -0
- package/app/App.tsx +61 -0
- package/app/index.css +18 -0
- package/app/main.tsx +10 -0
- package/dist/components/StyleMe.d.ts +15 -0
- package/dist/components/StyleMe.d.ts.map +1 -0
- package/dist/components/error-boundary.d.ts +17 -0
- package/dist/components/error-boundary.d.ts.map +1 -0
- package/dist/components/explorer/edit-namespace-dialog.d.ts +14 -0
- package/dist/components/explorer/edit-namespace-dialog.d.ts.map +1 -0
- package/dist/components/explorer/edit-row-dialog.d.ts +10 -0
- package/dist/components/explorer/edit-row-dialog.d.ts.map +1 -0
- package/dist/components/explorer/expandable-deleted-attr.d.ts +15 -0
- package/dist/components/explorer/expandable-deleted-attr.d.ts.map +1 -0
- package/dist/components/explorer/explorer-layout.d.ts +8 -0
- package/dist/components/explorer/explorer-layout.d.ts.map +1 -0
- package/dist/components/explorer/index.d.ts +44 -0
- package/dist/components/explorer/index.d.ts.map +1 -0
- package/dist/components/explorer/inner-explorer.d.ts +16 -0
- package/dist/components/explorer/inner-explorer.d.ts.map +1 -0
- package/dist/components/explorer/new-namespace-dialog.d.ts +10 -0
- package/dist/components/explorer/new-namespace-dialog.d.ts.map +1 -0
- package/dist/components/explorer/query-inspector.d.ts +11 -0
- package/dist/components/explorer/query-inspector.d.ts.map +1 -0
- package/dist/components/explorer/recently-deleted.d.ts +36 -0
- package/dist/components/explorer/recently-deleted.d.ts.map +1 -0
- package/dist/components/explorer/search-input.d.ts +9 -0
- package/dist/components/explorer/search-input.d.ts.map +1 -0
- package/dist/components/explorer/table-components.d.ts +16 -0
- package/dist/components/explorer/table-components.d.ts.map +1 -0
- package/dist/components/explorer/view-settings.d.ts +10 -0
- package/dist/components/explorer/view-settings.d.ts.map +1 -0
- package/dist/components/rosePineDawnTheme.d.ts +13 -0
- package/dist/components/rosePineDawnTheme.d.ts.map +1 -0
- package/dist/components/select.d.ts +16 -0
- package/dist/components/select.d.ts.map +1 -0
- package/dist/components/toast.d.ts +4 -0
- package/dist/components/toast.d.ts.map +1 -0
- package/dist/components/ui.d.ts +336 -0
- package/dist/components/ui.d.ts.map +1 -0
- package/dist/config.d.ts +14 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/hooks/explorer.d.ts +29 -0
- package/dist/hooks/explorer.d.ts.map +1 -0
- package/dist/hooks/useAttrNotes.d.ts +10 -0
- package/dist/hooks/useAttrNotes.d.ts.map +1 -0
- package/dist/hooks/useClickOutside.d.ts +3 -0
- package/dist/hooks/useClickOutside.d.ts.map +1 -0
- package/dist/hooks/useColumnVisibility.d.ts +12 -0
- package/dist/hooks/useColumnVisibility.d.ts.map +1 -0
- package/dist/hooks/useEditBlobConstraints.d.ts +32 -0
- package/dist/hooks/useEditBlobConstraints.d.ts.map +1 -0
- package/dist/hooks/useExplorerHistory.d.ts +1 -0
- package/dist/hooks/useExplorerHistory.d.ts.map +1 -0
- package/dist/hooks/useIsOverflow.d.ts +6 -0
- package/dist/hooks/useIsOverflow.d.ts.map +1 -0
- package/dist/hooks/useLocalStorage.d.ts +2 -0
- package/dist/hooks/useLocalStorage.d.ts.map +1 -0
- package/dist/hooks/useMonacoJSONSchema.d.ts +3 -0
- package/dist/hooks/useMonacoJSONSchema.d.ts.map +1 -0
- package/dist/hooks/useStableDB.d.ts +7 -0
- package/dist/hooks/useStableDB.d.ts.map +1 -0
- package/dist/index.cjs +15 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9270 -0
- package/dist/schema.d.ts +5 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/style.css +1 -0
- package/dist/types.d.ts +241 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/format.d.ts +2 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/indexingJobs.d.ts +24 -0
- package/dist/utils/indexingJobs.d.ts.map +1 -0
- package/dist/utils/parsePermsJSON.d.ts +11 -0
- package/dist/utils/parsePermsJSON.d.ts.map +1 -0
- package/dist/utils/renames.d.ts +3 -0
- package/dist/utils/renames.d.ts.map +1 -0
- package/dist/utils/tableWidthSize.d.ts +9 -0
- package/dist/utils/tableWidthSize.d.ts.map +1 -0
- package/index.html +13 -0
- package/package.json +109 -0
- package/src/components/StyleMe.tsx +97 -0
- package/src/components/error-boundary.tsx +76 -0
- package/src/components/explorer/edit-namespace-dialog.tsx +1886 -0
- package/src/components/explorer/edit-row-dialog.tsx +1151 -0
- package/src/components/explorer/expandable-deleted-attr.tsx +170 -0
- package/src/components/explorer/explorer-layout.tsx +156 -0
- package/src/components/explorer/index.tsx +217 -0
- package/src/components/explorer/inner-explorer.tsx +1341 -0
- package/src/components/explorer/new-namespace-dialog.tsx +54 -0
- package/src/components/explorer/query-inspector.tsx +394 -0
- package/src/components/explorer/recently-deleted.tsx +344 -0
- package/src/components/explorer/search-input.tsx +358 -0
- package/src/components/explorer/table-components.tsx +341 -0
- package/src/components/explorer/view-settings.tsx +75 -0
- package/src/components/rosePineDawnTheme.ts +45 -0
- package/src/components/select.tsx +198 -0
- package/src/components/toast.tsx +18 -0
- package/src/components/ui.tsx +1561 -0
- package/src/config.ts +61 -0
- package/src/hooks/explorer.tsx +125 -0
- package/src/hooks/useAttrNotes.ts +27 -0
- package/src/hooks/useClickOutside.ts +23 -0
- package/src/hooks/useColumnVisibility.ts +39 -0
- package/src/hooks/useEditBlobConstraints.ts +185 -0
- package/src/hooks/useExplorerHistory.ts +0 -0
- package/src/hooks/useIsOverflow.ts +24 -0
- package/src/hooks/useLocalStorage.ts +51 -0
- package/src/hooks/useMonacoJSONSchema.ts +41 -0
- package/src/hooks/useStableDB.ts +30 -0
- package/src/index.tsx +8 -0
- package/src/schema.ts +285 -0
- package/src/style.css +5 -0
- package/src/types.ts +359 -0
- package/src/utils/format.ts +13 -0
- package/src/utils/indexingJobs.ts +126 -0
- package/src/utils/parsePermsJSON.ts +35 -0
- package/src/utils/renames.ts +42 -0
- package/src/utils/tableWidthSize.ts +62 -0
- package/tailwind.config.cjs +42 -0
- package/tsconfig.json +22 -0
- package/vite-env.d.ts +1 -0
- package/vite.config.ts +49 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ReactNode,
|
|
3
|
+
useRef,
|
|
4
|
+
useState,
|
|
5
|
+
useEffect,
|
|
6
|
+
createContext,
|
|
7
|
+
useContext,
|
|
8
|
+
} from 'react';
|
|
9
|
+
import { createPortal } from 'react-dom';
|
|
10
|
+
import React from 'react';
|
|
11
|
+
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
import myStyles from '../style.css?inline';
|
|
14
|
+
import { cn } from './ui';
|
|
15
|
+
import { useExplorerProps } from './explorer';
|
|
16
|
+
|
|
17
|
+
// Context for shadow root - used by portaled components (Dialog, Tooltip, etc.)
|
|
18
|
+
type ShadowRootContextType = {
|
|
19
|
+
shadowRoot: ShadowRoot | null;
|
|
20
|
+
container: HTMLDivElement | null;
|
|
21
|
+
darkMode: boolean;
|
|
22
|
+
};
|
|
23
|
+
const ShadowRootContext = createContext<ShadowRootContextType>({
|
|
24
|
+
shadowRoot: null,
|
|
25
|
+
container: null,
|
|
26
|
+
darkMode: false,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Returns the shadow root container element for portaling components.
|
|
31
|
+
* This is the container div inside the shadow root that has the dark class applied.
|
|
32
|
+
*/
|
|
33
|
+
export function useShadowRoot(): HTMLDivElement | null {
|
|
34
|
+
return useContext(ShadowRootContext).container;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Returns the dark mode state from the shadow root context.
|
|
39
|
+
* Used by portaled components to apply dark mode styles.
|
|
40
|
+
*/
|
|
41
|
+
export function useShadowDarkMode(): boolean {
|
|
42
|
+
return useContext(ShadowRootContext).darkMode;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const StyleMe = ({ children }: { children: ReactNode }) => {
|
|
46
|
+
const hostRef = useRef<HTMLDivElement>(null);
|
|
47
|
+
const shadowRoot = useRef<ShadowRoot | null>(null);
|
|
48
|
+
const [mountNode, setMountNode] = useState<HTMLDivElement | null>(null);
|
|
49
|
+
|
|
50
|
+
const explorerProps = useExplorerProps();
|
|
51
|
+
const darkMode = explorerProps.darkMode;
|
|
52
|
+
|
|
53
|
+
// Initialize shadow DOM
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (hostRef.current && !mountNode) {
|
|
56
|
+
try {
|
|
57
|
+
const shadow = hostRef.current.attachShadow({ mode: 'open' });
|
|
58
|
+
shadowRoot.current = shadow;
|
|
59
|
+
|
|
60
|
+
const style = document.createElement('style');
|
|
61
|
+
style.textContent = myStyles;
|
|
62
|
+
const container = document.createElement('div');
|
|
63
|
+
|
|
64
|
+
container.setAttribute('class', darkMode ? 'h-full dark' : 'h-full');
|
|
65
|
+
|
|
66
|
+
shadow.appendChild(style);
|
|
67
|
+
shadow.appendChild(container);
|
|
68
|
+
|
|
69
|
+
setMountNode(container);
|
|
70
|
+
} catch (err) {}
|
|
71
|
+
}
|
|
72
|
+
}, [mountNode]);
|
|
73
|
+
|
|
74
|
+
// Update dark mode class when darkMode prop changes
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (mountNode) {
|
|
77
|
+
mountNode.setAttribute('class', darkMode ? 'h-full dark' : 'h-full');
|
|
78
|
+
}
|
|
79
|
+
}, [darkMode, mountNode]);
|
|
80
|
+
|
|
81
|
+
const contextValue = React.useMemo(
|
|
82
|
+
() => ({
|
|
83
|
+
shadowRoot: shadowRoot.current,
|
|
84
|
+
container: mountNode,
|
|
85
|
+
darkMode,
|
|
86
|
+
}),
|
|
87
|
+
[mountNode, darkMode],
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<div ref={hostRef} style={{ height: '100%' }} className={cn('h-full')}>
|
|
92
|
+
<ShadowRootContext.Provider value={contextValue}>
|
|
93
|
+
{mountNode ? createPortal(children, mountNode) : null}
|
|
94
|
+
</ShadowRootContext.Provider>
|
|
95
|
+
</div>
|
|
96
|
+
);
|
|
97
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// from https://react-typescript-cheatsheet.netlify.app/docs/basic/getting-started/error_boundaries/#option-2-writing-your-custom-error-boundary-component
|
|
2
|
+
|
|
3
|
+
import React, { Component, ErrorInfo, ReactNode } from 'react';
|
|
4
|
+
import { ExclamationTriangleIcon } from '@heroicons/react/24/outline';
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface State {
|
|
11
|
+
hasError: boolean;
|
|
12
|
+
error: Error | null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
class ErrorBoundary extends Component<Props, State> {
|
|
16
|
+
public state: State = {
|
|
17
|
+
hasError: false,
|
|
18
|
+
error: null,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
public static getDerivedStateFromError(error: Error): State {
|
|
22
|
+
// Update state so the next render will show the fallback UI.
|
|
23
|
+
return { hasError: true, error };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
|
27
|
+
console.error('Uncaught error:', error, errorInfo);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private handleRetry = () => {
|
|
31
|
+
this.setState({ hasError: false, error: null });
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
public render() {
|
|
35
|
+
if (this.state.hasError) {
|
|
36
|
+
return (
|
|
37
|
+
<div className="flex h-full w-full flex-1 flex-col items-center justify-center gap-4 bg-white p-6 dark:bg-neutral-800">
|
|
38
|
+
<div className="flex flex-col items-center gap-3 text-center">
|
|
39
|
+
<div className="flex h-12 w-12 items-center justify-center rounded-full bg-red-100 dark:bg-red-900/30">
|
|
40
|
+
<ExclamationTriangleIcon className="h-6 w-6 text-red-600 dark:text-red-400" />
|
|
41
|
+
</div>
|
|
42
|
+
<div className="flex flex-col gap-1">
|
|
43
|
+
<h2 className="text-lg font-semibold text-gray-900 dark:text-white">
|
|
44
|
+
Something went wrong
|
|
45
|
+
</h2>
|
|
46
|
+
<p className="max-w-md text-sm text-gray-500 dark:text-neutral-400">
|
|
47
|
+
An unexpected error occurred. Please try again or contact
|
|
48
|
+
support if the problem persists.
|
|
49
|
+
</p>
|
|
50
|
+
</div>
|
|
51
|
+
{this.state.error && (
|
|
52
|
+
<details className="mt-2 w-full max-w-md">
|
|
53
|
+
<summary className="cursor-pointer text-sm text-gray-500 hover:text-gray-700 dark:text-neutral-400 dark:hover:text-neutral-300">
|
|
54
|
+
Error details
|
|
55
|
+
</summary>
|
|
56
|
+
<pre className="mt-2 overflow-auto rounded border border-gray-200 bg-gray-50 p-2 text-left font-mono text-xs text-gray-700 dark:border-neutral-700 dark:bg-neutral-900 dark:text-neutral-300">
|
|
57
|
+
{this.state.error.message}
|
|
58
|
+
</pre>
|
|
59
|
+
</details>
|
|
60
|
+
)}
|
|
61
|
+
</div>
|
|
62
|
+
<button
|
|
63
|
+
onClick={this.handleRetry}
|
|
64
|
+
className="inline-flex cursor-pointer items-center justify-center gap-1 rounded-sm bg-[#606AF4] px-8 py-1 font-bold whitespace-nowrap text-white transition-all hover:bg-[#4543e9]"
|
|
65
|
+
>
|
|
66
|
+
Try again
|
|
67
|
+
</button>
|
|
68
|
+
</div>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return this.props.children;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export default ErrorBoundary;
|