@notis_ai/cli 0.2.0 → 0.2.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/README.md +39 -10
- package/package.json +7 -1
- package/src/command-specs/apps.js +852 -47
- package/src/command-specs/helpers.js +28 -3
- package/src/command-specs/index.js +1 -1
- package/src/command-specs/tools.js +33 -6
- package/src/runtime/agent-browser.js +192 -0
- package/src/runtime/app-boundary-validator.js +132 -0
- package/src/runtime/app-dev-server.js +577 -0
- package/src/runtime/app-dev-sessions.js +87 -0
- package/src/runtime/app-platform.js +646 -71
- package/src/runtime/cli-mode.generated.js +4 -0
- package/src/runtime/cli-mode.js +29 -0
- package/src/runtime/output.js +2 -2
- package/src/runtime/ports.js +15 -0
- package/src/runtime/profiles.js +34 -3
- package/src/runtime/transport.js +129 -4
- package/template/.harness/index.html.tmpl +260 -0
- package/template/app/globals.css +3 -0
- package/template/app/layout.tsx +6 -0
- package/template/app/page.tsx +55 -0
- package/template/components/ui/badge.tsx +28 -0
- package/template/components/ui/button.tsx +53 -0
- package/template/components/ui/card.tsx +56 -0
- package/template/components.json +20 -0
- package/template/lib/utils.ts +6 -0
- package/template/notis.config.ts +33 -0
- package/template/package.json +31 -0
- package/template/packages/notis-sdk/package.json +26 -0
- package/template/packages/notis-sdk/src/components/MultiSelectActionBar.tsx +272 -0
- package/template/packages/notis-sdk/src/components/MultiSelectCheckbox.tsx +91 -0
- package/template/packages/notis-sdk/src/components/MultiSelectDragOverlay.tsx +39 -0
- package/template/packages/notis-sdk/src/config.ts +71 -0
- package/template/packages/notis-sdk/src/helpers.ts +131 -0
- package/template/packages/notis-sdk/src/hooks/useAppState.ts +50 -0
- package/template/packages/notis-sdk/src/hooks/useBackend.ts +41 -0
- package/template/packages/notis-sdk/src/hooks/useCollectionItem.ts +58 -0
- package/template/packages/notis-sdk/src/hooks/useDatabase.ts +88 -0
- package/template/packages/notis-sdk/src/hooks/useDocument.ts +61 -0
- package/template/packages/notis-sdk/src/hooks/useMultiSelect.ts +502 -0
- package/template/packages/notis-sdk/src/hooks/useNotis.ts +33 -0
- package/template/packages/notis-sdk/src/hooks/useNotisNavigation.ts +49 -0
- package/template/packages/notis-sdk/src/hooks/useTool.ts +49 -0
- package/template/packages/notis-sdk/src/hooks/useTools.ts +56 -0
- package/template/packages/notis-sdk/src/hooks/useTopBarSearch.ts +73 -0
- package/template/packages/notis-sdk/src/hooks/useUpsertDocument.ts +58 -0
- package/template/packages/notis-sdk/src/index.ts +67 -0
- package/template/packages/notis-sdk/src/provider.tsx +43 -0
- package/template/packages/notis-sdk/src/runtime.ts +182 -0
- package/template/packages/notis-sdk/src/styles.css +38 -0
- package/template/packages/notis-sdk/src/ui.ts +15 -0
- package/template/packages/notis-sdk/src/vite.ts +56 -0
- package/template/packages/notis-sdk/tsconfig.json +15 -0
- package/template/postcss.config.mjs +8 -0
- package/template/tailwind.config.ts +58 -0
- package/template/tsconfig.json +22 -0
- package/template/vite.config.ts +10 -0
- package/src/runtime/app-preview-server.js +0 -272
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
3
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
4
|
+
|
|
5
|
+
import { cn } from '@/lib/utils';
|
|
6
|
+
|
|
7
|
+
const buttonVariants = cva(
|
|
8
|
+
'inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',
|
|
9
|
+
{
|
|
10
|
+
variants: {
|
|
11
|
+
variant: {
|
|
12
|
+
default: 'bg-primary text-primary-foreground hover:bg-primary/90',
|
|
13
|
+
destructive: 'bg-destructive text-destructive-foreground hover:bg-destructive/90',
|
|
14
|
+
outline: 'border border-input bg-background hover:bg-accent hover:text-accent-foreground',
|
|
15
|
+
secondary: 'bg-secondary text-secondary-foreground hover:bg-secondary/80',
|
|
16
|
+
ghost: 'hover:bg-accent hover:text-accent-foreground',
|
|
17
|
+
link: 'text-primary underline-offset-4 hover:underline',
|
|
18
|
+
},
|
|
19
|
+
size: {
|
|
20
|
+
default: 'h-10 px-4 py-2',
|
|
21
|
+
sm: 'h-9 rounded-md px-3',
|
|
22
|
+
lg: 'h-11 rounded-md px-8',
|
|
23
|
+
icon: 'h-10 w-10',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
defaultVariants: {
|
|
27
|
+
variant: 'default',
|
|
28
|
+
size: 'default',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
export interface ButtonProps
|
|
34
|
+
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
|
35
|
+
VariantProps<typeof buttonVariants> {
|
|
36
|
+
asChild?: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
40
|
+
({ className, variant, size, asChild = false, ...props }, ref) => {
|
|
41
|
+
const Comp = asChild ? Slot : 'button';
|
|
42
|
+
return (
|
|
43
|
+
<Comp
|
|
44
|
+
className={cn(buttonVariants({ variant, size, className }))}
|
|
45
|
+
ref={ref}
|
|
46
|
+
{...props}
|
|
47
|
+
/>
|
|
48
|
+
);
|
|
49
|
+
},
|
|
50
|
+
);
|
|
51
|
+
Button.displayName = 'Button';
|
|
52
|
+
|
|
53
|
+
export { Button, buttonVariants };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
import { cn } from '@/lib/utils';
|
|
4
|
+
|
|
5
|
+
const Card = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
|
|
6
|
+
({ className, ...props }, ref) => (
|
|
7
|
+
<div
|
|
8
|
+
ref={ref}
|
|
9
|
+
className={cn('rounded-2xl border bg-card text-card-foreground shadow-sm', className)}
|
|
10
|
+
{...props}
|
|
11
|
+
/>
|
|
12
|
+
),
|
|
13
|
+
);
|
|
14
|
+
Card.displayName = 'Card';
|
|
15
|
+
|
|
16
|
+
const CardHeader = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
|
|
17
|
+
({ className, ...props }, ref) => (
|
|
18
|
+
<div ref={ref} className={cn('flex flex-col space-y-1.5 p-6', className)} {...props} />
|
|
19
|
+
),
|
|
20
|
+
);
|
|
21
|
+
CardHeader.displayName = 'CardHeader';
|
|
22
|
+
|
|
23
|
+
const CardTitle = React.forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLHeadingElement>>(
|
|
24
|
+
({ className, ...props }, ref) => (
|
|
25
|
+
<h3
|
|
26
|
+
ref={ref}
|
|
27
|
+
className={cn('text-xl font-semibold leading-none tracking-tight', className)}
|
|
28
|
+
{...props}
|
|
29
|
+
/>
|
|
30
|
+
),
|
|
31
|
+
);
|
|
32
|
+
CardTitle.displayName = 'CardTitle';
|
|
33
|
+
|
|
34
|
+
const CardDescription = React.forwardRef<
|
|
35
|
+
HTMLParagraphElement,
|
|
36
|
+
React.HTMLAttributes<HTMLParagraphElement>
|
|
37
|
+
>(({ className, ...props }, ref) => (
|
|
38
|
+
<p ref={ref} className={cn('text-sm text-muted-foreground', className)} {...props} />
|
|
39
|
+
));
|
|
40
|
+
CardDescription.displayName = 'CardDescription';
|
|
41
|
+
|
|
42
|
+
const CardContent = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
|
|
43
|
+
({ className, ...props }, ref) => (
|
|
44
|
+
<div ref={ref} className={cn('p-6 pt-0', className)} {...props} />
|
|
45
|
+
),
|
|
46
|
+
);
|
|
47
|
+
CardContent.displayName = 'CardContent';
|
|
48
|
+
|
|
49
|
+
const CardFooter = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
|
|
50
|
+
({ className, ...props }, ref) => (
|
|
51
|
+
<div ref={ref} className={cn('flex items-center p-6 pt-0', className)} {...props} />
|
|
52
|
+
),
|
|
53
|
+
);
|
|
54
|
+
CardFooter.displayName = 'CardFooter';
|
|
55
|
+
|
|
56
|
+
export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema.json",
|
|
3
|
+
"style": "new-york",
|
|
4
|
+
"rsc": false,
|
|
5
|
+
"tsx": true,
|
|
6
|
+
"tailwind": {
|
|
7
|
+
"config": "tailwind.config.ts",
|
|
8
|
+
"css": "app/globals.css",
|
|
9
|
+
"baseColor": "zinc",
|
|
10
|
+
"cssVariables": true,
|
|
11
|
+
"prefix": ""
|
|
12
|
+
},
|
|
13
|
+
"aliases": {
|
|
14
|
+
"components": "@/components",
|
|
15
|
+
"utils": "@/lib/utils",
|
|
16
|
+
"ui": "@/components/ui",
|
|
17
|
+
"lib": "@/lib",
|
|
18
|
+
"hooks": "@/hooks"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { defineNotisApp } from '@notis/sdk/config';
|
|
2
|
+
|
|
3
|
+
export default defineNotisApp({
|
|
4
|
+
name: 'My Notis App',
|
|
5
|
+
description: 'A new Notis app',
|
|
6
|
+
icon: 'lucide:layout-dashboard',
|
|
7
|
+
|
|
8
|
+
databases: ['items'],
|
|
9
|
+
|
|
10
|
+
routes: [
|
|
11
|
+
{ path: '/', slug: 'home', name: 'Home', icon: 'lucide:home', default: true },
|
|
12
|
+
// Example collection tree route:
|
|
13
|
+
// {
|
|
14
|
+
// path: '/notes',
|
|
15
|
+
// slug: 'notes',
|
|
16
|
+
// name: 'Notes',
|
|
17
|
+
// collection: {
|
|
18
|
+
// database: 'notes',
|
|
19
|
+
// titleProperty: 'Name',
|
|
20
|
+
// parentProperty: 'Parent',
|
|
21
|
+
// sidebar: {
|
|
22
|
+
// mode: 'tree',
|
|
23
|
+
// allowCreate: true,
|
|
24
|
+
// },
|
|
25
|
+
// },
|
|
26
|
+
// },
|
|
27
|
+
],
|
|
28
|
+
|
|
29
|
+
tools: [
|
|
30
|
+
'notis_query_database',
|
|
31
|
+
'notis_upsert_document',
|
|
32
|
+
],
|
|
33
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "my-notis-app",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"build": "vite build"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@notis/sdk": "file:./packages/notis-sdk",
|
|
12
|
+
"@radix-ui/react-slot": "^1.1.0",
|
|
13
|
+
"class-variance-authority": "^0.7.0",
|
|
14
|
+
"clsx": "^2.1.1",
|
|
15
|
+
"lucide-react": "^0.474.0",
|
|
16
|
+
"react": "^19.0.0",
|
|
17
|
+
"react-dom": "^19.0.0",
|
|
18
|
+
"tailwind-merge": "^2.6.0",
|
|
19
|
+
"tailwindcss-animate": "^1.0.7"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "^22.0.0",
|
|
23
|
+
"@types/react": "^19.0.0",
|
|
24
|
+
"@types/react-dom": "^19.0.0",
|
|
25
|
+
"@vitejs/plugin-react": "^4.0.0",
|
|
26
|
+
"postcss": "^8.0.0",
|
|
27
|
+
"tailwindcss": "^3.4.0",
|
|
28
|
+
"typescript": "^5.0.0",
|
|
29
|
+
"vite": "^6.0.0"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@notis/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./src/index.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./src/index.ts",
|
|
8
|
+
"./config": "./src/config.ts",
|
|
9
|
+
"./vite": "./src/vite.ts",
|
|
10
|
+
"./ui": "./src/ui.ts",
|
|
11
|
+
"./styles.css": "./src/styles.css"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"src",
|
|
15
|
+
"template"
|
|
16
|
+
],
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"react": ">=18.0.0",
|
|
19
|
+
"react-dom": ">=18.0.0",
|
|
20
|
+
"vite": ">=5.0.0",
|
|
21
|
+
"@vitejs/plugin-react": ">=4.0.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"typescript": "^5.0.0"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
useEffect,
|
|
5
|
+
useMemo,
|
|
6
|
+
useRef,
|
|
7
|
+
useState,
|
|
8
|
+
type CSSProperties,
|
|
9
|
+
type ReactNode,
|
|
10
|
+
} from 'react';
|
|
11
|
+
|
|
12
|
+
export interface MultiSelectAction {
|
|
13
|
+
id: string;
|
|
14
|
+
label: string;
|
|
15
|
+
icon: ReactNode;
|
|
16
|
+
/** Single-key (e.g. "E", "#") or "Mod+K" shortcut. Bound while the bar is mounted with count > 0. */
|
|
17
|
+
shortcut?: string;
|
|
18
|
+
onRun: () => void | Promise<void>;
|
|
19
|
+
/** Hint for future destructive styling. Currently unused visually. */
|
|
20
|
+
destructive?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface MultiSelectActionBarProps {
|
|
24
|
+
selectedCount: number;
|
|
25
|
+
actions: MultiSelectAction[];
|
|
26
|
+
/** Override the "{count} selected" label units. Default: "selected" with no item word. */
|
|
27
|
+
itemLabel?: { singular: string; plural: string };
|
|
28
|
+
/** Optional extra class on the outer container (composed alongside the inline styles). */
|
|
29
|
+
className?: string;
|
|
30
|
+
/** Optional override for the bar's positioning style. Defaults to bottom-center floating. */
|
|
31
|
+
style?: CSSProperties;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface ParsedShortcut {
|
|
35
|
+
key: string;
|
|
36
|
+
needsMod: boolean;
|
|
37
|
+
needsShift: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function parseShortcut(raw: string): ParsedShortcut | null {
|
|
41
|
+
const parts = raw.split('+').map((p) => p.trim()).filter(Boolean);
|
|
42
|
+
if (parts.length === 0) return null;
|
|
43
|
+
let needsMod = false;
|
|
44
|
+
let needsShift = false;
|
|
45
|
+
let key = '';
|
|
46
|
+
for (const part of parts) {
|
|
47
|
+
const lower = part.toLowerCase();
|
|
48
|
+
if (lower === 'mod' || lower === 'cmd' || lower === 'ctrl' || lower === 'meta') {
|
|
49
|
+
needsMod = true;
|
|
50
|
+
} else if (lower === 'shift') {
|
|
51
|
+
needsShift = true;
|
|
52
|
+
} else {
|
|
53
|
+
key = lower;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (!key) return null;
|
|
57
|
+
return { key, needsMod, needsShift };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function shortcutMatches(shortcut: ParsedShortcut, event: KeyboardEvent): boolean {
|
|
61
|
+
const eventKey = event.key.toLowerCase();
|
|
62
|
+
// Special-case "#" so Shift+3 matches without the consumer specifying Shift.
|
|
63
|
+
if (shortcut.key === '#') {
|
|
64
|
+
if (eventKey === '#') return true;
|
|
65
|
+
if (event.shiftKey && eventKey === '3') return true;
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
if (eventKey !== shortcut.key) return false;
|
|
69
|
+
if (shortcut.needsMod !== Boolean(event.metaKey || event.ctrlKey)) return false;
|
|
70
|
+
if (shortcut.needsShift !== event.shiftKey) return false;
|
|
71
|
+
if (event.altKey) return false;
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function isEditableTarget(target: EventTarget | null): boolean {
|
|
76
|
+
if (!(target instanceof HTMLElement)) return false;
|
|
77
|
+
if (target.isContentEditable) return true;
|
|
78
|
+
const tag = target.tagName;
|
|
79
|
+
return tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT';
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function shortcutDisplay(raw: string): string {
|
|
83
|
+
const parts = raw.split('+').map((p) => p.trim()).filter(Boolean);
|
|
84
|
+
return parts
|
|
85
|
+
.map((part) => {
|
|
86
|
+
const lower = part.toLowerCase();
|
|
87
|
+
if (lower === 'mod' || lower === 'cmd' || lower === 'meta') return '⌘';
|
|
88
|
+
if (lower === 'ctrl') return '⌃';
|
|
89
|
+
if (lower === 'shift') return '⇧';
|
|
90
|
+
if (lower === 'alt' || lower === 'option') return '⌥';
|
|
91
|
+
return part.length === 1 ? part.toUpperCase() : part;
|
|
92
|
+
})
|
|
93
|
+
.join('');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const containerBaseStyle: CSSProperties = {
|
|
97
|
+
position: 'fixed',
|
|
98
|
+
bottom: '1rem',
|
|
99
|
+
left: '50%',
|
|
100
|
+
transform: 'translateX(-50%)',
|
|
101
|
+
zIndex: 60,
|
|
102
|
+
display: 'flex',
|
|
103
|
+
alignItems: 'center',
|
|
104
|
+
gap: '0.25rem',
|
|
105
|
+
padding: '0.375rem 0.5rem',
|
|
106
|
+
borderRadius: '0.5rem',
|
|
107
|
+
background: 'color-mix(in srgb, hsl(var(--foreground)) 95%, transparent)',
|
|
108
|
+
color: 'hsl(var(--background))',
|
|
109
|
+
boxShadow: '0 10px 25px -10px rgba(0,0,0,0.35), 0 0 0 1px rgba(0,0,0,0.08)',
|
|
110
|
+
backdropFilter: 'blur(6px)',
|
|
111
|
+
WebkitBackdropFilter: 'blur(6px)',
|
|
112
|
+
pointerEvents: 'auto',
|
|
113
|
+
fontSize: '13px',
|
|
114
|
+
lineHeight: 1.2,
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const countStyle: CSSProperties = {
|
|
118
|
+
padding: '0 0.5rem',
|
|
119
|
+
fontSize: '12px',
|
|
120
|
+
fontWeight: 500,
|
|
121
|
+
fontVariantNumeric: 'tabular-nums',
|
|
122
|
+
color: 'color-mix(in srgb, hsl(var(--background)) 70%, transparent)',
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const dividerStyle: CSSProperties = {
|
|
126
|
+
width: '1px',
|
|
127
|
+
height: '1rem',
|
|
128
|
+
margin: '0 0.125rem',
|
|
129
|
+
background: 'color-mix(in srgb, hsl(var(--background)) 20%, transparent)',
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const baseButtonStyle: CSSProperties = {
|
|
133
|
+
display: 'inline-flex',
|
|
134
|
+
alignItems: 'center',
|
|
135
|
+
gap: '0.375rem',
|
|
136
|
+
padding: '0.25rem 0.5rem',
|
|
137
|
+
border: 0,
|
|
138
|
+
background: 'transparent',
|
|
139
|
+
color: 'color-mix(in srgb, hsl(var(--background)) 90%, transparent)',
|
|
140
|
+
borderRadius: '0.375rem',
|
|
141
|
+
cursor: 'pointer',
|
|
142
|
+
fontSize: '13px',
|
|
143
|
+
fontFamily: 'inherit',
|
|
144
|
+
transition: 'background-color 120ms ease, color 120ms ease',
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const keycapStyle: CSSProperties = {
|
|
148
|
+
display: 'inline-flex',
|
|
149
|
+
alignItems: 'center',
|
|
150
|
+
justifyContent: 'center',
|
|
151
|
+
minWidth: '20px',
|
|
152
|
+
height: '20px',
|
|
153
|
+
padding: '0 4px',
|
|
154
|
+
borderRadius: '4px',
|
|
155
|
+
border: '1px solid color-mix(in srgb, hsl(var(--background)) 20%, transparent)',
|
|
156
|
+
background: 'color-mix(in srgb, hsl(var(--background)) 15%, transparent)',
|
|
157
|
+
color: 'inherit',
|
|
158
|
+
fontSize: '11px',
|
|
159
|
+
fontWeight: 500,
|
|
160
|
+
lineHeight: 1,
|
|
161
|
+
fontFamily: 'inherit',
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const iconSlotStyle: CSSProperties = {
|
|
165
|
+
display: 'inline-flex',
|
|
166
|
+
alignItems: 'center',
|
|
167
|
+
justifyContent: 'center',
|
|
168
|
+
opacity: 0.8,
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
export function MultiSelectActionBar({
|
|
172
|
+
selectedCount,
|
|
173
|
+
actions,
|
|
174
|
+
itemLabel,
|
|
175
|
+
className,
|
|
176
|
+
style,
|
|
177
|
+
}: MultiSelectActionBarProps): JSX.Element | null {
|
|
178
|
+
const actionsRef = useRef(actions);
|
|
179
|
+
actionsRef.current = actions;
|
|
180
|
+
|
|
181
|
+
const parsedShortcuts = useMemo(() => {
|
|
182
|
+
return actions
|
|
183
|
+
.map((action) => {
|
|
184
|
+
if (!action.shortcut) return null;
|
|
185
|
+
const parsed = parseShortcut(action.shortcut);
|
|
186
|
+
return parsed ? { action, parsed } : null;
|
|
187
|
+
})
|
|
188
|
+
.filter((entry): entry is { action: MultiSelectAction; parsed: ParsedShortcut } => entry !== null);
|
|
189
|
+
}, [actions]);
|
|
190
|
+
|
|
191
|
+
useEffect(() => {
|
|
192
|
+
if (selectedCount === 0 || parsedShortcuts.length === 0) return;
|
|
193
|
+
|
|
194
|
+
const handleKeyDown = (event: KeyboardEvent) => {
|
|
195
|
+
if (isEditableTarget(event.target)) return;
|
|
196
|
+
for (const { action, parsed } of parsedShortcuts) {
|
|
197
|
+
if (shortcutMatches(parsed, event)) {
|
|
198
|
+
event.preventDefault();
|
|
199
|
+
event.stopPropagation();
|
|
200
|
+
if (typeof event.stopImmediatePropagation === 'function') {
|
|
201
|
+
event.stopImmediatePropagation();
|
|
202
|
+
}
|
|
203
|
+
void action.onRun();
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
document.addEventListener('keydown', handleKeyDown, true);
|
|
210
|
+
return () => {
|
|
211
|
+
document.removeEventListener('keydown', handleKeyDown, true);
|
|
212
|
+
};
|
|
213
|
+
}, [parsedShortcuts, selectedCount]);
|
|
214
|
+
|
|
215
|
+
if (selectedCount === 0) return null;
|
|
216
|
+
|
|
217
|
+
const countWord = itemLabel
|
|
218
|
+
? selectedCount === 1
|
|
219
|
+
? itemLabel.singular
|
|
220
|
+
: itemLabel.plural
|
|
221
|
+
: 'selected';
|
|
222
|
+
const countLabel = itemLabel
|
|
223
|
+
? `${selectedCount} ${countWord} selected`
|
|
224
|
+
: `${selectedCount} selected`;
|
|
225
|
+
|
|
226
|
+
const composedStyle: CSSProperties = { ...containerBaseStyle, ...(style || {}) };
|
|
227
|
+
|
|
228
|
+
return (
|
|
229
|
+
<div
|
|
230
|
+
role="toolbar"
|
|
231
|
+
aria-label={`Bulk actions for ${selectedCount} selected ${countWord}`}
|
|
232
|
+
className={className}
|
|
233
|
+
style={composedStyle}
|
|
234
|
+
>
|
|
235
|
+
<span style={countStyle}>{countLabel}</span>
|
|
236
|
+
{actions.length > 0 ? <span aria-hidden style={dividerStyle} /> : null}
|
|
237
|
+
{actions.map((action) => (
|
|
238
|
+
<ActionButton key={action.id} action={action} />
|
|
239
|
+
))}
|
|
240
|
+
</div>
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function ActionButton({ action }: { action: MultiSelectAction }) {
|
|
245
|
+
const [hover, setHover] = useState(false);
|
|
246
|
+
const display = action.shortcut ? shortcutDisplay(action.shortcut) : null;
|
|
247
|
+
const buttonStyle: CSSProperties = {
|
|
248
|
+
...baseButtonStyle,
|
|
249
|
+
background: hover
|
|
250
|
+
? 'color-mix(in srgb, hsl(var(--background)) 12%, transparent)'
|
|
251
|
+
: 'transparent',
|
|
252
|
+
color: hover
|
|
253
|
+
? 'hsl(var(--background))'
|
|
254
|
+
: baseButtonStyle.color,
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
return (
|
|
258
|
+
<button
|
|
259
|
+
type="button"
|
|
260
|
+
onClick={() => void action.onRun()}
|
|
261
|
+
onMouseEnter={() => setHover(true)}
|
|
262
|
+
onMouseLeave={() => setHover(false)}
|
|
263
|
+
onFocus={() => setHover(true)}
|
|
264
|
+
onBlur={() => setHover(false)}
|
|
265
|
+
style={buttonStyle}
|
|
266
|
+
>
|
|
267
|
+
<span aria-hidden style={iconSlotStyle}>{action.icon}</span>
|
|
268
|
+
{display ? <kbd aria-hidden style={keycapStyle}>{display}</kbd> : null}
|
|
269
|
+
<span>{action.label}</span>
|
|
270
|
+
</button>
|
|
271
|
+
);
|
|
272
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { type CSSProperties, type MouseEvent as ReactMouseEvent } from 'react';
|
|
4
|
+
|
|
5
|
+
export interface MultiSelectCheckboxProps {
|
|
6
|
+
isSelected: boolean;
|
|
7
|
+
onClick: (event: ReactMouseEvent) => void;
|
|
8
|
+
/** When true, the checkbox is always visible. Default false (hover/focus reveal via the parent's :hover state). */
|
|
9
|
+
alwaysVisible?: boolean;
|
|
10
|
+
/** Optional aria-label override. Defaults to "Select item" / "Deselect item". */
|
|
11
|
+
ariaLabel?: string;
|
|
12
|
+
className?: string;
|
|
13
|
+
/** Optional inline-style override merged with the defaults. */
|
|
14
|
+
style?: CSSProperties;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const baseStyle: CSSProperties = {
|
|
18
|
+
flexShrink: 0,
|
|
19
|
+
display: 'inline-flex',
|
|
20
|
+
alignItems: 'center',
|
|
21
|
+
justifyContent: 'center',
|
|
22
|
+
width: '16px',
|
|
23
|
+
height: '16px',
|
|
24
|
+
borderRadius: '4px',
|
|
25
|
+
border: '1px solid hsl(var(--border))',
|
|
26
|
+
background: 'transparent',
|
|
27
|
+
color: 'hsl(var(--primary-foreground))',
|
|
28
|
+
cursor: 'pointer',
|
|
29
|
+
padding: 0,
|
|
30
|
+
transition: 'background-color 120ms ease, border-color 120ms ease, opacity 150ms ease',
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const selectedStyle: CSSProperties = {
|
|
34
|
+
background: 'hsl(var(--primary))',
|
|
35
|
+
borderColor: 'hsl(var(--primary))',
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const checkPath = 'M3.5 7.5l2.5 2.5 6.5-6.5';
|
|
39
|
+
|
|
40
|
+
export function MultiSelectCheckbox({
|
|
41
|
+
isSelected,
|
|
42
|
+
onClick,
|
|
43
|
+
alwaysVisible = false,
|
|
44
|
+
ariaLabel,
|
|
45
|
+
className,
|
|
46
|
+
style,
|
|
47
|
+
}: MultiSelectCheckboxProps): JSX.Element {
|
|
48
|
+
const merged: CSSProperties = {
|
|
49
|
+
...baseStyle,
|
|
50
|
+
...(isSelected ? selectedStyle : null),
|
|
51
|
+
...(alwaysVisible || isSelected ? { opacity: 1 } : null),
|
|
52
|
+
...(style || null),
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// When alwaysVisible is false and the row isn't selected, defer the
|
|
56
|
+
// hover-reveal to the parent — consumers wrap the checkbox in a `.group`
|
|
57
|
+
// hover scope and pass `data-notis-hover-reveal` styles via className.
|
|
58
|
+
// Out of the box, we render the checkbox at full opacity if selected,
|
|
59
|
+
// otherwise inherit the parent's reveal state.
|
|
60
|
+
return (
|
|
61
|
+
<button
|
|
62
|
+
type="button"
|
|
63
|
+
role="checkbox"
|
|
64
|
+
aria-checked={isSelected}
|
|
65
|
+
aria-label={ariaLabel ?? (isSelected ? 'Deselect item' : 'Select item')}
|
|
66
|
+
onClick={onClick}
|
|
67
|
+
onMouseDown={(e) => e.stopPropagation()}
|
|
68
|
+
data-notis-multiselect-checkbox=""
|
|
69
|
+
data-selected={isSelected ? 'true' : 'false'}
|
|
70
|
+
className={className}
|
|
71
|
+
style={merged}
|
|
72
|
+
>
|
|
73
|
+
{isSelected ? (
|
|
74
|
+
<svg
|
|
75
|
+
width="10"
|
|
76
|
+
height="10"
|
|
77
|
+
viewBox="0 0 16 16"
|
|
78
|
+
fill="none"
|
|
79
|
+
stroke="currentColor"
|
|
80
|
+
strokeWidth={3}
|
|
81
|
+
strokeLinecap="round"
|
|
82
|
+
strokeLinejoin="round"
|
|
83
|
+
aria-hidden
|
|
84
|
+
focusable="false"
|
|
85
|
+
>
|
|
86
|
+
<path d={checkPath} />
|
|
87
|
+
</svg>
|
|
88
|
+
) : null}
|
|
89
|
+
</button>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { type CSSProperties } from 'react';
|
|
4
|
+
import type { DragRect } from '../hooks/useMultiSelect';
|
|
5
|
+
|
|
6
|
+
export interface MultiSelectDragOverlayProps {
|
|
7
|
+
rect: DragRect | null;
|
|
8
|
+
className?: string;
|
|
9
|
+
style?: CSSProperties;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const overlayBaseStyle: CSSProperties = {
|
|
13
|
+
position: 'fixed',
|
|
14
|
+
borderRadius: '3px',
|
|
15
|
+
border: '1px solid rgba(35, 131, 226, 0.3)',
|
|
16
|
+
background: 'rgba(35, 131, 226, 0.08)',
|
|
17
|
+
pointerEvents: 'none',
|
|
18
|
+
zIndex: 50,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export function MultiSelectDragOverlay({
|
|
22
|
+
rect,
|
|
23
|
+
className,
|
|
24
|
+
style,
|
|
25
|
+
}: MultiSelectDragOverlayProps): JSX.Element | null {
|
|
26
|
+
if (!rect) return null;
|
|
27
|
+
if (rect.width === 0 && rect.height === 0) return null;
|
|
28
|
+
|
|
29
|
+
const merged: CSSProperties = {
|
|
30
|
+
...overlayBaseStyle,
|
|
31
|
+
left: rect.left,
|
|
32
|
+
top: rect.top,
|
|
33
|
+
width: rect.width,
|
|
34
|
+
height: rect.height,
|
|
35
|
+
...(style || null),
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
return <div aria-hidden className={className} style={merged} />;
|
|
39
|
+
}
|