@sidekickdb/components 0.0.0 → 2.0.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/.turbo/turbo-build.log +20 -0
- package/LICENSE.md +202 -0
- package/NOTICE +27 -0
- package/README.md +92 -2
- package/app/App.css +38 -0
- package/app/App.tsx +63 -0
- package/app/index.css +18 -0
- package/app/main.tsx +10 -0
- package/dist/components/DialogContentPrimitive.d.ts +1 -0
- package/dist/components/DialogContentPrimitive.d.ts.map +1 -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/__tests__/edit-row-dialog.test.d.ts +2 -0
- package/dist/components/explorer/__tests__/edit-row-dialog.test.d.ts.map +1 -0
- package/dist/components/explorer/__tests__/format-value.test.d.ts +2 -0
- package/dist/components/explorer/__tests__/format-value.test.d.ts.map +1 -0
- package/dist/components/explorer/edit-namespace-dialog.d.ts +17 -0
- package/dist/components/explorer/edit-namespace-dialog.d.ts.map +1 -0
- package/dist/components/explorer/edit-row-dialog.d.ts +15 -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 +9 -0
- package/dist/components/explorer/explorer-layout.d.ts.map +1 -0
- package/dist/components/explorer/format-value.d.ts +2 -0
- package/dist/components/explorer/format-value.d.ts.map +1 -0
- package/dist/components/explorer/index.d.ts +128 -0
- package/dist/components/explorer/index.d.ts.map +1 -0
- package/dist/components/explorer/inner-explorer.d.ts +17 -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 +349 -0
- package/dist/components/ui.d.ts.map +1 -0
- package/dist/config.d.ts +11 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/hooks/__tests__/explorer.test.d.ts +2 -0
- package/dist/hooks/__tests__/explorer.test.d.ts.map +1 -0
- package/dist/hooks/explorer.d.ts +33 -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 +9751 -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 +106 -3
- package/src/components/DialogContentPrimitive.tsx +0 -0
- package/src/components/StyleMe.tsx +97 -0
- package/src/components/error-boundary.tsx +76 -0
- package/src/components/explorer/__tests__/edit-row-dialog.test.ts +31 -0
- package/src/components/explorer/__tests__/format-value.test.ts +9 -0
- package/src/components/explorer/edit-namespace-dialog.tsx +1890 -0
- package/src/components/explorer/edit-row-dialog.tsx +1367 -0
- package/src/components/explorer/expandable-deleted-attr.tsx +170 -0
- package/src/components/explorer/explorer-layout.tsx +196 -0
- package/src/components/explorer/format-value.ts +9 -0
- package/src/components/explorer/index.tsx +280 -0
- package/src/components/explorer/inner-explorer.tsx +1524 -0
- package/src/components/explorer/new-namespace-dialog.tsx +55 -0
- package/src/components/explorer/query-inspector.tsx +395 -0
- package/src/components/explorer/recently-deleted.tsx +349 -0
- package/src/components/explorer/search-input.tsx +358 -0
- package/src/components/explorer/table-components.tsx +416 -0
- package/src/components/explorer/view-settings.tsx +76 -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 +1740 -0
- package/src/config.ts +57 -0
- package/src/hooks/__tests__/explorer.test.ts +109 -0
- package/src/hooks/explorer.tsx +137 -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 +31 -0
- package/src/index.tsx +12 -0
- package/src/schema.ts +286 -0
- package/src/style.css +84 -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 +48 -0
- package/tsconfig.json +22 -0
- package/vite-env.d.ts +1 -0
- package/vite.config.ts +50 -0
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
cn,
|
|
4
|
+
Fence,
|
|
5
|
+
Tooltip,
|
|
6
|
+
TooltipContent,
|
|
7
|
+
TooltipTrigger,
|
|
8
|
+
} from '@lib/components/ui';
|
|
9
|
+
import {
|
|
10
|
+
Cell,
|
|
11
|
+
flexRender,
|
|
12
|
+
Header,
|
|
13
|
+
HeaderGroup,
|
|
14
|
+
Table,
|
|
15
|
+
} from '@tanstack/react-table';
|
|
16
|
+
import { useSortable } from '@dnd-kit/sortable';
|
|
17
|
+
import { CSS } from '@dnd-kit/utilities';
|
|
18
|
+
|
|
19
|
+
import clsx from 'clsx';
|
|
20
|
+
import { CSSProperties, useEffect, useState } from 'react';
|
|
21
|
+
import {
|
|
22
|
+
ArrowDownIcon,
|
|
23
|
+
ArrowsUpDownIcon,
|
|
24
|
+
ArrowUpIcon,
|
|
25
|
+
PencilSquareIcon,
|
|
26
|
+
} from '@heroicons/react/24/outline';
|
|
27
|
+
import { useIsOverflow } from '@lib/hooks/useIsOverflow';
|
|
28
|
+
import { isObject } from 'lodash';
|
|
29
|
+
import copy from 'copy-to-clipboard';
|
|
30
|
+
import { useExplorerDialog, useExplorerProps, useExplorerState } from '.';
|
|
31
|
+
import { TableColMeta } from './inner-explorer';
|
|
32
|
+
import { formatVal } from './format-value';
|
|
33
|
+
|
|
34
|
+
export const TableHeader = ({
|
|
35
|
+
header,
|
|
36
|
+
table,
|
|
37
|
+
headerGroup,
|
|
38
|
+
index,
|
|
39
|
+
setMinViableColWidth,
|
|
40
|
+
onSort,
|
|
41
|
+
currentSortAttr,
|
|
42
|
+
currentSortAsc,
|
|
43
|
+
}: {
|
|
44
|
+
header: Header<any, any>;
|
|
45
|
+
table: Table<any>;
|
|
46
|
+
headerGroup: HeaderGroup<any>;
|
|
47
|
+
index: number;
|
|
48
|
+
setMinViableColWidth: (columnId: string) => void;
|
|
49
|
+
onSort?: (
|
|
50
|
+
attrName: string,
|
|
51
|
+
currentAttr: string | undefined,
|
|
52
|
+
currentAsc?: boolean,
|
|
53
|
+
) => void;
|
|
54
|
+
currentSortAttr?: string;
|
|
55
|
+
currentSortAsc?: boolean;
|
|
56
|
+
}) => {
|
|
57
|
+
const {
|
|
58
|
+
attributes,
|
|
59
|
+
setActivatorNodeRef,
|
|
60
|
+
isDragging,
|
|
61
|
+
listeners,
|
|
62
|
+
setNodeRef,
|
|
63
|
+
transform,
|
|
64
|
+
} = useSortable({
|
|
65
|
+
id: header.column.id,
|
|
66
|
+
disabled: header.id === 'select-col',
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const style: CSSProperties = {
|
|
70
|
+
opacity: isDragging ? 0.8 : 1,
|
|
71
|
+
position: 'relative',
|
|
72
|
+
transform:
|
|
73
|
+
header.id === 'select-col'
|
|
74
|
+
? undefined
|
|
75
|
+
: CSS.Translate.toString(transform), // translate instead of transform to avoid squishing
|
|
76
|
+
transition: 'width transform 0.2s ease-in-out',
|
|
77
|
+
whiteSpace: 'nowrap',
|
|
78
|
+
width: header.column.getSize(),
|
|
79
|
+
zIndex: isDragging ? 1 : 0,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const meta = header.column.columnDef?.meta as TableColMeta | null;
|
|
83
|
+
|
|
84
|
+
const isSortable = !!meta?.sortable;
|
|
85
|
+
|
|
86
|
+
const headerText =
|
|
87
|
+
typeof header.column.columnDef.header === 'string'
|
|
88
|
+
? header.column.columnDef.header
|
|
89
|
+
: '';
|
|
90
|
+
|
|
91
|
+
// Check if this column is currently sorted
|
|
92
|
+
const isCurrentSort =
|
|
93
|
+
currentSortAttr === headerText ||
|
|
94
|
+
(currentSortAttr === 'serverCreatedAt' && headerText === 'id');
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<div
|
|
98
|
+
key={header.id}
|
|
99
|
+
ref={setNodeRef}
|
|
100
|
+
className={clsx(
|
|
101
|
+
'group relative z-10 h-8 w-full whitespace-nowrap select-none',
|
|
102
|
+
)}
|
|
103
|
+
style={{
|
|
104
|
+
...style,
|
|
105
|
+
width: header.getSize() !== 0 ? header.getSize() : undefined,
|
|
106
|
+
}}
|
|
107
|
+
>
|
|
108
|
+
{header.id !== 'select-col' && (
|
|
109
|
+
<button
|
|
110
|
+
className="absolute inset-0 z-0 hover:cursor-grab active:cursor-grabbing"
|
|
111
|
+
{...attributes}
|
|
112
|
+
{...listeners}
|
|
113
|
+
ref={setActivatorNodeRef}
|
|
114
|
+
style={{ pointerEvents: 'auto' }}
|
|
115
|
+
/>
|
|
116
|
+
)}
|
|
117
|
+
{header.id === 'select-col' ? (
|
|
118
|
+
<div
|
|
119
|
+
className={`flex h-full w-full items-center px-2 py-1 th-${header.column.id}`}
|
|
120
|
+
>
|
|
121
|
+
{header.isPlaceholder
|
|
122
|
+
? null
|
|
123
|
+
: flexRender(header.column.columnDef.header, header.getContext())}
|
|
124
|
+
</div>
|
|
125
|
+
) : (
|
|
126
|
+
<div className="flex h-full items-stretch justify-between overflow-hidden">
|
|
127
|
+
<div
|
|
128
|
+
className={`flex shrink items-center gap-1 truncate px-2 py-1 font-semibold th-${header.column.id}`}
|
|
129
|
+
>
|
|
130
|
+
{isSortable ? (
|
|
131
|
+
<button
|
|
132
|
+
className="relative z-50 flex items-center gap-1 py-2 pr-5"
|
|
133
|
+
onClick={() => {
|
|
134
|
+
if (onSort) {
|
|
135
|
+
let thisAttrName =
|
|
136
|
+
headerText === 'id' ? 'serverCreatedAt' : headerText;
|
|
137
|
+
onSort(thisAttrName, currentSortAttr, currentSortAsc);
|
|
138
|
+
}
|
|
139
|
+
}}
|
|
140
|
+
>
|
|
141
|
+
<span className={cn(isCurrentSort && 'underline')}>
|
|
142
|
+
{header.isPlaceholder
|
|
143
|
+
? null
|
|
144
|
+
: flexRender(
|
|
145
|
+
header.column.columnDef.header,
|
|
146
|
+
header.getContext(),
|
|
147
|
+
)}
|
|
148
|
+
</span>
|
|
149
|
+
<span
|
|
150
|
+
className="opacity-50 transition-opacity group-hover:opacity-70"
|
|
151
|
+
style={{
|
|
152
|
+
opacity: isCurrentSort ? 1 : undefined,
|
|
153
|
+
fontWeight: isCurrentSort ? 'bold' : 'normal',
|
|
154
|
+
}}
|
|
155
|
+
>
|
|
156
|
+
{isCurrentSort ? (
|
|
157
|
+
currentSortAsc ? (
|
|
158
|
+
<ArrowUpIcon strokeWidth={3} width={10} />
|
|
159
|
+
) : (
|
|
160
|
+
<ArrowDownIcon strokeWidth={3} width={10} />
|
|
161
|
+
)
|
|
162
|
+
) : (
|
|
163
|
+
<ArrowsUpDownIcon strokeWidth={3} width={10} />
|
|
164
|
+
)}
|
|
165
|
+
</span>
|
|
166
|
+
</button>
|
|
167
|
+
) : (
|
|
168
|
+
<>
|
|
169
|
+
{header.isPlaceholder
|
|
170
|
+
? null
|
|
171
|
+
: flexRender(
|
|
172
|
+
header.column.columnDef.header,
|
|
173
|
+
header.getContext(),
|
|
174
|
+
)}
|
|
175
|
+
</>
|
|
176
|
+
)}
|
|
177
|
+
</div>
|
|
178
|
+
|
|
179
|
+
<div className="flex h-full items-center justify-between">
|
|
180
|
+
<div
|
|
181
|
+
{...{
|
|
182
|
+
onDoubleClick: () => setMinViableColWidth(header.column.id),
|
|
183
|
+
onMouseDown: (e) => {
|
|
184
|
+
e.stopPropagation();
|
|
185
|
+
return header.getResizeHandler()(e);
|
|
186
|
+
},
|
|
187
|
+
onTouchStart: header.getResizeHandler(),
|
|
188
|
+
className: cn(
|
|
189
|
+
`resizer h-full flex justify-center z-50 ${
|
|
190
|
+
table.options.columnResizeDirection
|
|
191
|
+
} ${header.column.getIsResizing() ? 'isResizing' : ''}`,
|
|
192
|
+
headerGroup.headers.length - 1 == index && 'justify-end',
|
|
193
|
+
header.id !== 'select-col' && 'hover:cursor-col-resize',
|
|
194
|
+
),
|
|
195
|
+
style: {
|
|
196
|
+
width: 8,
|
|
197
|
+
pointerEvents: 'auto',
|
|
198
|
+
},
|
|
199
|
+
}}
|
|
200
|
+
>
|
|
201
|
+
{headerGroup.headers.length - 1 !== index && (
|
|
202
|
+
<div className="h-full w-0.5 bg-neutral-200 dark:bg-neutral-700"></div>
|
|
203
|
+
)}
|
|
204
|
+
</div>
|
|
205
|
+
</div>
|
|
206
|
+
</div>
|
|
207
|
+
)}
|
|
208
|
+
</div>
|
|
209
|
+
);
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
export const TableCell = ({ cell }: { cell: Cell<any, unknown> }) => {
|
|
213
|
+
const resizing = cell.column.getIsResizing();
|
|
214
|
+
|
|
215
|
+
const { history } = useExplorerState();
|
|
216
|
+
const { setDialog } = useExplorerDialog();
|
|
217
|
+
|
|
218
|
+
const meta = cell.column.columnDef.meta as TableColMeta | null;
|
|
219
|
+
const showEditButton = meta?.editable && meta.attr && !meta?.isLink;
|
|
220
|
+
const { isDragging, setNodeRef, transform } = useSortable({
|
|
221
|
+
id: cell.column.id,
|
|
222
|
+
disabled: cell.column.id === 'select-col',
|
|
223
|
+
});
|
|
224
|
+
const [showCopy, setShowCopy] = useState(false);
|
|
225
|
+
const { ref: overflowRef, isOverflow, setIsOverflow } = useIsOverflow();
|
|
226
|
+
const realValue = cell.getValue();
|
|
227
|
+
const shouldShowTooltip =
|
|
228
|
+
(isOverflow || isObject(realValue)) && !meta?.isLink;
|
|
229
|
+
|
|
230
|
+
useEffect(() => {
|
|
231
|
+
const el = overflowRef.current;
|
|
232
|
+
if (!el) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const checkOverflow = () => {
|
|
237
|
+
setIsOverflow(
|
|
238
|
+
el.scrollWidth > el.clientWidth || el.scrollHeight > el.clientHeight,
|
|
239
|
+
);
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
checkOverflow();
|
|
243
|
+
const observer = new ResizeObserver(checkOverflow);
|
|
244
|
+
observer.observe(el);
|
|
245
|
+
|
|
246
|
+
return () => {
|
|
247
|
+
observer.disconnect();
|
|
248
|
+
};
|
|
249
|
+
}, [realValue, cell.column.getSize(), setIsOverflow]);
|
|
250
|
+
|
|
251
|
+
const style: CSSProperties = {
|
|
252
|
+
opacity: isDragging ? 0.8 : 1,
|
|
253
|
+
position: 'relative',
|
|
254
|
+
transform:
|
|
255
|
+
cell.column.id === 'select-col'
|
|
256
|
+
? undefined
|
|
257
|
+
: CSS.Translate.toString(transform), // translate instead of transform to avoid squishing
|
|
258
|
+
transition: 'width transform 0.2s ease-in-out',
|
|
259
|
+
width: cell.column.getSize(),
|
|
260
|
+
zIndex: isDragging ? 1 : 0,
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
const disablePadding = meta?.disablePadding ?? false;
|
|
264
|
+
const isSelectCol = cell.column.id === 'select-col';
|
|
265
|
+
|
|
266
|
+
const hasNavigableLink =
|
|
267
|
+
meta?.isLink &&
|
|
268
|
+
meta.attr &&
|
|
269
|
+
Array.isArray(realValue) &&
|
|
270
|
+
realValue.length > 0;
|
|
271
|
+
const canCopy = meta?.copyable && isCopyableCellValue(realValue, meta);
|
|
272
|
+
|
|
273
|
+
const cellInner = (
|
|
274
|
+
<div
|
|
275
|
+
ref={setNodeRef}
|
|
276
|
+
style={{
|
|
277
|
+
...style,
|
|
278
|
+
...(isSelectCol || disablePadding ? {} : { padding: '0.5rem' }),
|
|
279
|
+
}}
|
|
280
|
+
className={cn(
|
|
281
|
+
'group/cell relative flex min-w-0 cursor-default items-center whitespace-nowrap',
|
|
282
|
+
isSelectCol && 'px-2 py-1',
|
|
283
|
+
)}
|
|
284
|
+
key={cell.id}
|
|
285
|
+
>
|
|
286
|
+
<span
|
|
287
|
+
ref={isSelectCol ? undefined : overflowRef}
|
|
288
|
+
className={cn(
|
|
289
|
+
`h-full min-h-full min-w-0 td-${cell.column.id}`,
|
|
290
|
+
isSelectCol
|
|
291
|
+
? 'flex w-full items-center gap-2 overflow-visible'
|
|
292
|
+
: cn(
|
|
293
|
+
'min-w-0 flex-1 truncate',
|
|
294
|
+
(hasNavigableLink || canCopy) && 'cursor-pointer',
|
|
295
|
+
),
|
|
296
|
+
!isSelectCol && (disablePadding ? '' : 'pr-2'),
|
|
297
|
+
showEditButton && 'pr-6',
|
|
298
|
+
)}
|
|
299
|
+
onClick={
|
|
300
|
+
isSelectCol
|
|
301
|
+
? undefined
|
|
302
|
+
: () => {
|
|
303
|
+
if (hasNavigableLink && meta?.attr) {
|
|
304
|
+
const attr = meta.attr;
|
|
305
|
+
const linkConfigDir =
|
|
306
|
+
attr.linkConfig[!attr.isForward ? 'forward' : 'reverse'];
|
|
307
|
+
|
|
308
|
+
if (linkConfigDir) {
|
|
309
|
+
history.push({
|
|
310
|
+
namespace: linkConfigDir.namespace,
|
|
311
|
+
where: [`${linkConfigDir.attr}.id`, cell.row.original.id],
|
|
312
|
+
});
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
if (canCopy && copy(formatVal(realValue))) {
|
|
317
|
+
setShowCopy(true);
|
|
318
|
+
setTimeout(() => setShowCopy(false), 1000);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
>
|
|
323
|
+
{showCopy ? (
|
|
324
|
+
<div className="h-1">Copied!</div>
|
|
325
|
+
) : (
|
|
326
|
+
flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
327
|
+
)}
|
|
328
|
+
</span>
|
|
329
|
+
{showEditButton ? (
|
|
330
|
+
<button
|
|
331
|
+
type="button"
|
|
332
|
+
title={`Edit ${meta.attr.name}`}
|
|
333
|
+
className="absolute top-1/2 right-1 z-20 -translate-y-1/2 rounded-xs p-0.5 opacity-0 transition-opacity group-hover/cell:opacity-100 hover:bg-neutral-100 focus-visible:bg-neutral-100 focus-visible:opacity-100 focus-visible:ring-2 focus-visible:ring-neutral-400 focus-visible:outline-hidden dark:hover:bg-neutral-700 dark:focus-visible:bg-neutral-700 dark:focus-visible:ring-neutral-500"
|
|
334
|
+
onClick={(e) => {
|
|
335
|
+
e.stopPropagation();
|
|
336
|
+
setDialog({
|
|
337
|
+
type: 'edit-row',
|
|
338
|
+
rowId: cell.row.original.id as string,
|
|
339
|
+
focusAttr: meta.attr.name,
|
|
340
|
+
});
|
|
341
|
+
}}
|
|
342
|
+
>
|
|
343
|
+
<PencilSquareIcon className="h-4 w-4 text-neutral-500 dark:text-neutral-400" />
|
|
344
|
+
</button>
|
|
345
|
+
) : null}
|
|
346
|
+
</div>
|
|
347
|
+
);
|
|
348
|
+
|
|
349
|
+
if (isSelectCol) {
|
|
350
|
+
return cellInner;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
return (
|
|
354
|
+
<Tooltip delayDuration={400}>
|
|
355
|
+
{' '}
|
|
356
|
+
<TooltipTrigger className="text-left" asChild>
|
|
357
|
+
{cellInner}
|
|
358
|
+
</TooltipTrigger>
|
|
359
|
+
{shouldShowTooltip && !resizing && (
|
|
360
|
+
<TooltipContent
|
|
361
|
+
collisionPadding={10}
|
|
362
|
+
className={cn(
|
|
363
|
+
'max-h-[min(50vh,var(--radix-popper-available-height))] max-w-[min(75rem,80vw)] min-w-0 overflow-x-hidden overflow-y-auto wrap-break-word whitespace-pre-wrap [&_code]:wrap-break-word [&_pre]:wrap-break-word [&_pre]:whitespace-pre-wrap',
|
|
364
|
+
isObject(realValue) && 'p-0',
|
|
365
|
+
)}
|
|
366
|
+
side="bottom"
|
|
367
|
+
>
|
|
368
|
+
{typeof realValue === 'string' ? (
|
|
369
|
+
flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
370
|
+
) : (
|
|
371
|
+
<Val pretty data={realValue} />
|
|
372
|
+
)}
|
|
373
|
+
</TooltipContent>
|
|
374
|
+
)}
|
|
375
|
+
</Tooltip>
|
|
376
|
+
);
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
function isCopyableCellValue(
|
|
380
|
+
value: unknown,
|
|
381
|
+
meta: TableColMeta | null,
|
|
382
|
+
): boolean {
|
|
383
|
+
if (value === null || value === undefined) {
|
|
384
|
+
return false;
|
|
385
|
+
}
|
|
386
|
+
if (meta?.isLink) {
|
|
387
|
+
return Array.isArray(value) && value.length > 0;
|
|
388
|
+
}
|
|
389
|
+
if (Array.isArray(value)) {
|
|
390
|
+
return value.length > 0;
|
|
391
|
+
}
|
|
392
|
+
if (isObject(value)) {
|
|
393
|
+
return Object.keys(value).length > 0;
|
|
394
|
+
}
|
|
395
|
+
if (typeof value === 'string') {
|
|
396
|
+
return value.trim().length > 0;
|
|
397
|
+
}
|
|
398
|
+
return true;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function Val({ data, pretty }: { data: any; pretty?: boolean }) {
|
|
402
|
+
const sanitized = formatVal(data, pretty);
|
|
403
|
+
const explorerProps = useExplorerProps();
|
|
404
|
+
|
|
405
|
+
if (pretty && isObject(data)) {
|
|
406
|
+
return (
|
|
407
|
+
<Fence
|
|
408
|
+
darkMode={explorerProps.darkMode}
|
|
409
|
+
code={sanitized}
|
|
410
|
+
language="json"
|
|
411
|
+
/>
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
return <>{sanitized}</>;
|
|
416
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Switch } from '@lib/components/ui';
|
|
3
|
+
import { Checkbox, Dialog, Divider, IconButton } from '@lib/components/ui';
|
|
4
|
+
import { useColumnVisibility } from '@lib/hooks/useColumnVisibility';
|
|
5
|
+
import { Cog6ToothIcon, XMarkIcon } from '@heroicons/react/24/outline';
|
|
6
|
+
import { useState } from 'react';
|
|
7
|
+
|
|
8
|
+
interface ViewSettingsProps {
|
|
9
|
+
visiblity: ReturnType<typeof useColumnVisibility>;
|
|
10
|
+
localDates: boolean;
|
|
11
|
+
setLocalDates: (v: boolean | undefined) => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const ViewSettings = ({
|
|
15
|
+
visiblity,
|
|
16
|
+
localDates,
|
|
17
|
+
setLocalDates,
|
|
18
|
+
}: ViewSettingsProps) => {
|
|
19
|
+
const [dialogOpen, setDialogOpen] = useState(false);
|
|
20
|
+
return (
|
|
21
|
+
<>
|
|
22
|
+
<IconButton
|
|
23
|
+
icon={<Cog6ToothIcon width={16} />}
|
|
24
|
+
label="View Settings"
|
|
25
|
+
onClick={() => setDialogOpen(true)}
|
|
26
|
+
/>
|
|
27
|
+
<Dialog
|
|
28
|
+
title="Explorer View Settings"
|
|
29
|
+
hideCloseButton={true}
|
|
30
|
+
onClose={() => setDialogOpen(false)}
|
|
31
|
+
open={dialogOpen}
|
|
32
|
+
>
|
|
33
|
+
<div className="flex items-center justify-between">
|
|
34
|
+
<div className="text-lg">Explorer View Settings</div>
|
|
35
|
+
<button onClick={() => setDialogOpen(false)}>
|
|
36
|
+
<XMarkIcon className="h-4 w-4 cursor-pointer" />
|
|
37
|
+
</button>
|
|
38
|
+
</div>
|
|
39
|
+
|
|
40
|
+
<div className="py-2">
|
|
41
|
+
<div>Visible Columns</div>
|
|
42
|
+
<div className="py-1">
|
|
43
|
+
{visiblity.attrs?.map((attr) => (
|
|
44
|
+
<div key={attr.id + attr.name} className="flex gap-2">
|
|
45
|
+
<Checkbox
|
|
46
|
+
label={attr.name}
|
|
47
|
+
checked={visiblity.visibility[attr.id + attr.name] !== false}
|
|
48
|
+
onChange={(checked) =>
|
|
49
|
+
visiblity.setVisibility((prev) => ({
|
|
50
|
+
...prev,
|
|
51
|
+
[attr.id + attr.name]: checked,
|
|
52
|
+
}))
|
|
53
|
+
}
|
|
54
|
+
></Checkbox>
|
|
55
|
+
</div>
|
|
56
|
+
))}
|
|
57
|
+
</div>
|
|
58
|
+
</div>
|
|
59
|
+
<Divider className="py-2" />
|
|
60
|
+
|
|
61
|
+
<div className="flex items-center gap-2">
|
|
62
|
+
<div>Show Dates in Local Time</div>
|
|
63
|
+
<Switch
|
|
64
|
+
onClick={(e) => {
|
|
65
|
+
setLocalDates(!localDates);
|
|
66
|
+
}}
|
|
67
|
+
checked={localDates}
|
|
68
|
+
></Switch>
|
|
69
|
+
</div>
|
|
70
|
+
<div className="text-xs opacity-40">
|
|
71
|
+
Copy to clipboard will still use the original value.
|
|
72
|
+
</div>
|
|
73
|
+
</Dialog>
|
|
74
|
+
</>
|
|
75
|
+
);
|
|
76
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Rosé Pine Dawn theme (matching prism.css)
|
|
2
|
+
export const rosePineDawnTheme = {
|
|
3
|
+
plain: {
|
|
4
|
+
backgroundColor: '#fff',
|
|
5
|
+
color: '#575279',
|
|
6
|
+
},
|
|
7
|
+
styles: [
|
|
8
|
+
{
|
|
9
|
+
types: ['comment', 'prolog', 'cdata', 'punctuation'],
|
|
10
|
+
style: { color: '#797593' },
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
types: ['delimiter', 'important', 'atrule', 'operator', 'keyword'],
|
|
14
|
+
style: { color: '#286983' },
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
types: [
|
|
18
|
+
'tag',
|
|
19
|
+
'doctype',
|
|
20
|
+
'variable',
|
|
21
|
+
'regex',
|
|
22
|
+
'class-name',
|
|
23
|
+
'selector',
|
|
24
|
+
'inserted',
|
|
25
|
+
],
|
|
26
|
+
style: { color: '#56949f' },
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
types: ['boolean', 'entity', 'number', 'symbol', 'function'],
|
|
30
|
+
style: { color: '#d7827e' },
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
types: ['string', 'char', 'property', 'attr-value'],
|
|
34
|
+
style: { color: '#ea9d34' },
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
types: ['parameter', 'url', 'attr-name', 'builtin'],
|
|
38
|
+
style: { color: '#907aa9' },
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
types: ['deleted'],
|
|
42
|
+
style: { color: '#b4637a' },
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
};
|