@g4rcez/components 0.3.0 → 0.3.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/dist/index.css +1 -1
- package/dist/index.js +53 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5363 -5291
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +55 -45
- package/dist/index.umd.js.map +1 -1
- package/dist/preset/src/styles/common.d.ts +1 -1
- package/dist/preset/src/styles/common.js +1 -1
- package/dist/src/components/core/tag.d.ts +9 -10
- package/dist/src/components/core/tag.d.ts.map +1 -1
- package/dist/src/components/core/tag.js +20 -18
- package/dist/src/components/display/shortcut.js +5 -3
- package/dist/src/components/floating/command-palette.d.ts +18 -6
- package/dist/src/components/floating/command-palette.d.ts.map +1 -1
- package/dist/src/components/floating/command-palette.js +94 -76
- package/dist/src/components/floating/menu.d.ts.map +1 -1
- package/dist/src/components/floating/menu.js +12 -15
- package/dist/src/config/default-translations.d.ts +38 -37
- package/dist/src/config/default-translations.d.ts.map +1 -1
- package/dist/src/config/default-translations.js +37 -36
- package/dist/src/constants.d.ts +1 -1
- package/dist/src/constants.js +1 -1
- package/dist/src/hooks/use-translations.d.ts +38 -37
- package/dist/src/hooks/use-translations.d.ts.map +1 -1
- package/dist/src/lib/combi-keys.d.ts +9 -6
- package/dist/src/lib/combi-keys.d.ts.map +1 -1
- package/dist/src/lib/combi-keys.js +15 -3
- package/dist/src/lib/dict.d.ts +1 -0
- package/dist/src/lib/dict.d.ts.map +1 -1
- package/dist/src/lib/dict.js +3 -0
- package/dist/src/lib/fzf.d.ts.map +1 -1
- package/dist/src/lib/fzf.js +11 -14
- package/dist/src/styles/common.d.ts +1 -1
- package/dist/src/styles/common.js +1 -1
- package/package.json +1 -1
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { type VariantProps } from "class-variance-authority";
|
|
2
1
|
import React from "react";
|
|
3
2
|
import { CvaVariants, Label } from "../../types";
|
|
4
3
|
import { PolymorphicProps } from "./polymorph";
|
|
5
|
-
declare const indicatorVariant: (props?: ({
|
|
6
|
-
theme?: "info" | "warn" | "muted" | "danger" | "primary" | "success" | "secondary" | null | undefined;
|
|
7
|
-
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
|
8
4
|
declare const variants: {
|
|
9
5
|
size: {
|
|
10
6
|
icon: string;
|
|
@@ -13,22 +9,25 @@ declare const variants: {
|
|
|
13
9
|
small: string;
|
|
14
10
|
};
|
|
15
11
|
theme: {
|
|
16
|
-
|
|
17
|
-
danger: string;
|
|
12
|
+
custom: string;
|
|
18
13
|
info: string;
|
|
19
|
-
success: string;
|
|
20
|
-
secondary: string;
|
|
21
14
|
warn: string;
|
|
22
15
|
muted: string;
|
|
23
|
-
|
|
16
|
+
danger: string;
|
|
24
17
|
disabled: string;
|
|
18
|
+
primary: string;
|
|
19
|
+
success: string;
|
|
20
|
+
neutral: string;
|
|
21
|
+
secondary: string;
|
|
25
22
|
loading: string;
|
|
26
23
|
};
|
|
27
24
|
};
|
|
25
|
+
type Variants = CvaVariants<typeof variants>;
|
|
26
|
+
type Themes = NonNullable<Variants["theme"]>;
|
|
28
27
|
export type TagProps<T extends React.ElementType = "span"> = PolymorphicProps<CvaVariants<typeof variants> & Partial<{
|
|
29
28
|
icon: Label;
|
|
30
29
|
loading: boolean;
|
|
31
|
-
indicator:
|
|
30
|
+
indicator: Themes;
|
|
32
31
|
}>, T>;
|
|
33
32
|
export declare const Tag: <T extends React.ElementType = "span">(props: TagProps<T>) => any;
|
|
34
33
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tag.d.ts","sourceRoot":"","sources":["../../../../src/components/core/tag.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tag.d.ts","sourceRoot":"","sources":["../../../../src/components/core/tag.tsx"],"names":[],"mappings":"AACA,OAAO,KAAqB,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAa,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE1D,QAAA,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;CAoBb,CAAC;AAEF,KAAK,QAAQ,GAAG,WAAW,CAAC,OAAO,QAAQ,CAAC,CAAC;AAE7C,KAAK,MAAM,GAAG,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;AAsB7C,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,KAAK,CAAC,WAAW,GAAG,MAAM,IAAI,gBAAgB,CACzE,WAAW,CAAC,OAAO,QAAQ,CAAC,GAAG,OAAO,CAAC;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,EAC5F,CAAC,CACJ,CAAC;AAEF,eAAO,MAAM,GAAG,EAAE,CAAC,CAAC,SAAS,KAAK,CAAC,WAAW,GAAG,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,GAkB9E,CAAC"}
|
|
@@ -3,19 +3,6 @@ import { cva } from "class-variance-authority";
|
|
|
3
3
|
import { forwardRef } from "react";
|
|
4
4
|
import { css } from "../../lib/dom";
|
|
5
5
|
import { Polymorph } from "./polymorph";
|
|
6
|
-
const indicatorVariant = cva("size-2.5 aspect-square rounded-full border-0", {
|
|
7
|
-
variants: {
|
|
8
|
-
theme: {
|
|
9
|
-
info: "bg-info",
|
|
10
|
-
warn: "bg-warn",
|
|
11
|
-
muted: "bg-muted",
|
|
12
|
-
primary: "bg-primary",
|
|
13
|
-
danger: "bg-danger",
|
|
14
|
-
success: "bg-success",
|
|
15
|
-
secondary: "bg-secondary",
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
});
|
|
19
6
|
const variants = {
|
|
20
7
|
size: {
|
|
21
8
|
icon: "p-1",
|
|
@@ -24,18 +11,33 @@ const variants = {
|
|
|
24
11
|
small: "h-6 p-2 px-3 text-sm",
|
|
25
12
|
},
|
|
26
13
|
theme: {
|
|
27
|
-
|
|
28
|
-
danger: "bg-tag-danger-bg text-tag-danger-text",
|
|
14
|
+
custom: "",
|
|
29
15
|
info: "bg-tag-info-bg text-tag-info-text",
|
|
30
|
-
success: "bg-tag-success-bg text-tag-success-text",
|
|
31
|
-
secondary: "bg-tag-secondary-bg text-tag-secondary-text",
|
|
32
16
|
warn: "bg-tag-warn-bg text-tag-warn-text",
|
|
33
17
|
muted: "bg-tag-muted-bg text-tag-muted-text",
|
|
34
|
-
|
|
18
|
+
danger: "bg-tag-danger-bg text-tag-danger-text",
|
|
35
19
|
disabled: "bg-disabled duration-700 opacity-70",
|
|
20
|
+
primary: "bg-tag-primary-bg text-tag-primary-text",
|
|
21
|
+
success: "bg-tag-success-bg text-tag-success-text",
|
|
22
|
+
neutral: "bg-transparent border border-card-border",
|
|
23
|
+
secondary: "bg-tag-secondary-bg text-tag-secondary-text",
|
|
36
24
|
loading: "animate-pulse bg-disabled duration-700 opacity-70",
|
|
37
25
|
},
|
|
38
26
|
};
|
|
27
|
+
const indicatorVariant = cva("size-2.5 aspect-square rounded-full border-0", {
|
|
28
|
+
variants: {
|
|
29
|
+
theme: {
|
|
30
|
+
info: "bg-info",
|
|
31
|
+
warn: "bg-warn",
|
|
32
|
+
muted: "bg-muted",
|
|
33
|
+
danger: "bg-danger",
|
|
34
|
+
neutral: "bg-muted",
|
|
35
|
+
primary: "bg-primary",
|
|
36
|
+
success: "bg-success",
|
|
37
|
+
secondary: "bg-secondary",
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
});
|
|
39
41
|
const tagVariants = cva("inline-flex rounded-pill gap-1.5 border-2 border-transparent items-center justify-center align-middle whitespace-nowrap", {
|
|
40
42
|
variants,
|
|
41
43
|
defaultVariants: { theme: "primary", size: "default" },
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { CommandIcon } from "lucide-react";
|
|
2
|
+
import { CommandIcon, OptionIcon } from "lucide-react";
|
|
3
3
|
import { Fragment } from "react";
|
|
4
4
|
import { isMac } from "../../lib/combi-keys";
|
|
5
5
|
const remap = (x) => {
|
|
6
|
-
|
|
6
|
+
x = x.trim();
|
|
7
|
+
if (x === "Alt")
|
|
8
|
+
return isMac() ? _jsx(OptionIcon, { "aria-label": "Option", size: 14 }) : "Alt";
|
|
9
|
+
if (x === "Mod")
|
|
7
10
|
return isMac() ? _jsx(CommandIcon, { "aria-label": "Command", size: 14 }) : "Ctrl";
|
|
8
|
-
}
|
|
9
11
|
return x;
|
|
10
12
|
};
|
|
11
13
|
export const Shortcut = (props) => {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LucideProps } from "lucide-react";
|
|
1
2
|
import React from "react";
|
|
2
3
|
import { Label } from "../../types";
|
|
3
4
|
type ViewProps = {
|
|
@@ -5,10 +6,11 @@ type ViewProps = {
|
|
|
5
6
|
};
|
|
6
7
|
type CommandItem<T extends string, P extends object> = {
|
|
7
8
|
type: T;
|
|
8
|
-
hint?: string;
|
|
9
|
-
|
|
9
|
+
hint?: string | string[];
|
|
10
|
+
Icon?: React.ReactElement;
|
|
11
|
+
enabled?: ((props: ViewProps) => boolean) | boolean;
|
|
10
12
|
} & P;
|
|
11
|
-
type View =
|
|
13
|
+
type View = string | ((props: ViewProps) => string);
|
|
12
14
|
type CommandShortcutItem = CommandItem<"shortcut", {
|
|
13
15
|
title: View;
|
|
14
16
|
shortcut?: string;
|
|
@@ -16,7 +18,7 @@ type CommandShortcutItem = CommandItem<"shortcut", {
|
|
|
16
18
|
text: string;
|
|
17
19
|
setOpen: (state: boolean) => void;
|
|
18
20
|
event: KeyboardEvent | React.MouseEvent | React.KeyboardEvent;
|
|
19
|
-
}) => void
|
|
21
|
+
}) => void | Promise<void>;
|
|
20
22
|
}>;
|
|
21
23
|
type CommandGroupItem = CommandItem<"group", {
|
|
22
24
|
title: View;
|
|
@@ -24,12 +26,22 @@ type CommandGroupItem = CommandItem<"group", {
|
|
|
24
26
|
}>;
|
|
25
27
|
export type CommandItemTypes = CommandGroupItem | CommandShortcutItem;
|
|
26
28
|
export type CommandPaletteProps = {
|
|
27
|
-
open: boolean;
|
|
28
29
|
bind?: string;
|
|
30
|
+
open: boolean;
|
|
31
|
+
loading?: boolean;
|
|
29
32
|
emptyMessage?: Label;
|
|
30
33
|
footer?: React.ReactElement;
|
|
31
34
|
commands: CommandItemTypes[];
|
|
32
|
-
|
|
35
|
+
onChangeText?: (text: string) => void;
|
|
36
|
+
onChangeVisibility: (next: boolean) => void;
|
|
37
|
+
Preview?: React.FC<{
|
|
38
|
+
command: CommandItemTypes;
|
|
39
|
+
text: string;
|
|
40
|
+
}>;
|
|
41
|
+
Icon?: React.FC<LucideProps & {
|
|
42
|
+
text: string;
|
|
43
|
+
Default: React.FC<LucideProps>;
|
|
44
|
+
}>;
|
|
33
45
|
};
|
|
34
46
|
export declare const CommandPalette: (props: CommandPaletteProps) => import("react/jsx-runtime").JSX.Element;
|
|
35
47
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-palette.d.ts","sourceRoot":"","sources":["../../../../src/components/floating/command-palette.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"command-palette.d.ts","sourceRoot":"","sources":["../../../../src/components/floating/command-palette.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAc,WAAW,EAAE,MAAM,cAAc,CAAC;AAEvD,OAAO,KAAmE,MAAM,OAAO,CAAC;AAQxF,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAKpC,KAAK,SAAS,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAElC,KAAK,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,IAAI;IACnD,IAAI,EAAE,CAAC,CAAC;IACR,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB,IAAI,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC;IAC1B,OAAO,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,SAAS,KAAK,OAAO,CAAC,GAAG,OAAO,CAAC;CACvD,GAAG,CAAC,CAAC;AAEN,KAAK,IAAI,GAAG,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,SAAS,KAAK,MAAM,CAAC,CAAC;AAEpD,KAAK,mBAAmB,GAAG,WAAW,CAClC,UAAU,EACV;IACI,KAAK,EAAE,IAAI,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,CAAC,IAAI,EAAE;QACX,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;QAClC,KAAK,EAAE,aAAa,GAAG,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,aAAa,CAAC;KACjE,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B,CACJ,CAAC;AAEF,KAAK,gBAAgB,GAAG,WAAW,CAAC,OAAO,EAAE;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,gBAAgB,EAAE,CAAA;CAAE,CAAC,CAAC;AAEzF,MAAM,MAAM,gBAAgB,GAAG,gBAAgB,GAAG,mBAAmB,CAAC;AAiDtE,MAAM,MAAM,mBAAmB,GAAG;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,KAAK,CAAC;IACrB,MAAM,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC;IAC5B,QAAQ,EAAE,gBAAgB,EAAE,CAAC;IAC7B,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,kBAAkB,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IAC5C,OAAO,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC;QAAE,OAAO,EAAE,gBAAgB,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAChE,IAAI,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAAC,CAAA;KAAE,CAAC,CAAC;CACnF,CAAC;AAsBF,eAAO,MAAM,cAAc,GAAI,OAAO,mBAAmB,4CAoMxD,CAAC"}
|
|
@@ -1,75 +1,82 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { createElement as _createElement } from "react";
|
|
3
3
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
|
-
import { autoUpdate, useFloating, useInteractions, useListNavigation
|
|
4
|
+
import { autoUpdate, useFloating, useInteractions, useListNavigation } from "@floating-ui/react";
|
|
5
|
+
import { FilterIcon } from "lucide-react";
|
|
5
6
|
import { AnimatePresence, motion } from "motion/react";
|
|
6
7
|
import { forwardRef, Fragment, useEffect, useId, useRef, useState } from "react";
|
|
8
|
+
import { Is } from "sidekicker";
|
|
7
9
|
import { useStableRef } from "../../hooks/use-stable-ref";
|
|
8
10
|
import { useTranslations } from "../../hooks/use-translations";
|
|
9
11
|
import { CombiKeys } from "../../lib/combi-keys";
|
|
12
|
+
import { Dict } from "../../lib/dict";
|
|
10
13
|
import { css, isReactFC } from "../../lib/dom";
|
|
11
14
|
import { fzf } from "../../lib/fzf";
|
|
12
15
|
import { Shortcut } from "../display/shortcut";
|
|
16
|
+
import { SkeletonCell } from "../display/skeleton";
|
|
13
17
|
import { Modal } from "./modal";
|
|
14
18
|
const Group = (props) => (_jsx("span", { className: "flex h-full items-center text-left text-sm font-medium text-secondary", children: isReactFC(props.item.title) ? _jsx(props.item.title, { text: props.text }) : props.item.title }));
|
|
15
19
|
const Item = forwardRef((props, ref) => {
|
|
16
20
|
const id = useId();
|
|
17
21
|
const active = props.active;
|
|
18
|
-
const classNameBase = "h-10";
|
|
19
22
|
const item = props.item;
|
|
20
|
-
if (item.type === "group")
|
|
23
|
+
if (item.type === "group")
|
|
21
24
|
return (_jsx(motion.div, { id: id, className: "h-10 px-2 pb-1 pt-2", children: _jsx(Group, { text: props.text, item: item }) }));
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
return _jsx(Fragment, {});
|
|
25
|
+
if (item.type !== "shortcut")
|
|
26
|
+
return _jsx(Fragment, {});
|
|
27
|
+
return (_jsxs(motion.button, { ...props, id: id, ref: ref, role: "option", type: "button", "aria-selected": active, "data-component": "command-palette-item", className: css("flex h-10 items-center justify-between rounded-lg p-2 hover:bg-floating-hover hover:text-floating-foreground", active ? "bg-floating-hover text-primary-foreground" : ""), children: [_jsxs("span", { className: "flex items-center gap-2", children: [item.Icon ? item.Icon : null, _jsx("span", { children: isReactFC(item.title) ? _jsx(item.title, { text: props.text }) : item.title })] }), item.shortcut ? _jsx(Shortcut, { value: item.shortcut }) : null] }));
|
|
27
28
|
});
|
|
29
|
+
const getFuzzyData = (commands, value) => {
|
|
30
|
+
if (value.length === 0)
|
|
31
|
+
return commands;
|
|
32
|
+
const rules = [
|
|
33
|
+
{ key: "title", value },
|
|
34
|
+
{ key: "shortcut", value },
|
|
35
|
+
{ key: "hint", value },
|
|
36
|
+
];
|
|
37
|
+
const normalize = commands.map((x) => ({ ...x, title: Is.function(x.title) ? x.title({ text: value }) : x.title }));
|
|
38
|
+
const target = normalize.reduce((acc, x) => {
|
|
39
|
+
const enabled = Is.function(x.enabled) ? x.enabled({ text: value }) : (x.enabled ?? true);
|
|
40
|
+
if (enabled)
|
|
41
|
+
acc.push({ ...x, enabled: enabled });
|
|
42
|
+
return acc;
|
|
43
|
+
}, []);
|
|
44
|
+
const filter = fzf(target, "title", rules);
|
|
45
|
+
const withEnabled = normalize.filter((x) => (Is.function(x.enabled) ? x.enabled({ text: value }) : false));
|
|
46
|
+
return Dict.unique(filter.concat(withEnabled), (x) => x.title);
|
|
47
|
+
};
|
|
48
|
+
const loadingSkeleton = [0, 0, 0, 0, 0];
|
|
28
49
|
export const CommandPalette = (props) => {
|
|
50
|
+
const bindKey = props.bind ?? "Mod + k";
|
|
51
|
+
const listRef = useRef([]);
|
|
29
52
|
const translations = useTranslations();
|
|
30
53
|
const [value, setValue] = useState("");
|
|
31
54
|
const valueRef = useStableRef(value);
|
|
32
|
-
const bindKey = props.bind ?? "Mod + k";
|
|
33
|
-
const [combi] = useState(new CombiKeys());
|
|
34
55
|
const id = useId();
|
|
35
56
|
const ref = useRef(null);
|
|
36
57
|
const [activeIndex, setActiveIndex] = useState(null);
|
|
37
58
|
const floating = useFloating({
|
|
38
59
|
open: props.open,
|
|
39
|
-
|
|
60
|
+
strategy: "absolute",
|
|
61
|
+
onOpenChange: props.onChangeVisibility,
|
|
40
62
|
whileElementsMounted: autoUpdate,
|
|
41
63
|
});
|
|
42
|
-
const listRef = useRef([]);
|
|
43
64
|
const listNav = useListNavigation(floating.context, {
|
|
44
65
|
listRef,
|
|
45
66
|
loop: true,
|
|
46
67
|
activeIndex,
|
|
47
68
|
virtual: true,
|
|
48
69
|
allowEscape: true,
|
|
49
|
-
onNavigate: setActiveIndex,
|
|
50
70
|
scrollItemIntoView: true,
|
|
71
|
+
onNavigate: (n) => setActiveIndex((prev) => {
|
|
72
|
+
if (Is.number(n))
|
|
73
|
+
return n;
|
|
74
|
+
return props.open ? (prev ?? 0) : null;
|
|
75
|
+
}),
|
|
51
76
|
});
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
? x.enabled
|
|
56
|
-
? x.enabled({ text: value })
|
|
57
|
-
? [x]
|
|
58
|
-
: []
|
|
59
|
-
: [x]
|
|
60
|
-
: [x, ...x.items].filter((x) => (x.enabled === undefined ? true : x.enabled({ text: value }))));
|
|
61
|
-
const fuzzy = commands.length === 0
|
|
62
|
-
? commands
|
|
63
|
-
: fzf(commands, "title", [
|
|
64
|
-
{ key: "title", value },
|
|
65
|
-
{ key: "shortcut", value },
|
|
66
|
-
{ key: "hint", value },
|
|
67
|
-
...commands.reduce((acc, el) => {
|
|
68
|
-
if (!el.hint)
|
|
69
|
-
return acc;
|
|
70
|
-
return [...acc, { key: "hint", value: el.hint }];
|
|
71
|
-
}, []),
|
|
72
|
-
]);
|
|
77
|
+
const { getItemProps } = useInteractions([listNav]);
|
|
78
|
+
const commands = props.commands.flatMap((x) => (x.type === "group" ? [x, ...x.items] : [x]));
|
|
79
|
+
const fuzzy = getFuzzyData(commands, value);
|
|
73
80
|
const displayItems = value === ""
|
|
74
81
|
? commands
|
|
75
82
|
: [
|
|
@@ -81,7 +88,8 @@ export const CommandPalette = (props) => {
|
|
|
81
88
|
...fuzzy.filter((x) => x.type !== "group"),
|
|
82
89
|
];
|
|
83
90
|
useEffect(() => {
|
|
84
|
-
combi
|
|
91
|
+
const combi = new CombiKeys();
|
|
92
|
+
combi.add(bindKey, () => props.onChangeVisibility?.(true));
|
|
85
93
|
commands.forEach((cmd) => {
|
|
86
94
|
if (cmd.type === "group")
|
|
87
95
|
return;
|
|
@@ -89,51 +97,61 @@ export const CommandPalette = (props) => {
|
|
|
89
97
|
combi.add(cmd.shortcut, (event) => cmd.action({
|
|
90
98
|
event,
|
|
91
99
|
text: valueRef.current,
|
|
92
|
-
setOpen: props.
|
|
100
|
+
setOpen: props.onChangeVisibility,
|
|
93
101
|
}));
|
|
94
102
|
});
|
|
95
103
|
return combi.register();
|
|
96
|
-
}, [
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
if (e.key === "Enter") {
|
|
106
|
-
if (activeIndex !== null && displayItems[activeIndex]) {
|
|
107
|
-
e.preventDefault();
|
|
108
|
-
const x = displayItems[activeIndex];
|
|
109
|
-
const text = e.currentTarget.value;
|
|
110
|
-
if (x.type === "shortcut")
|
|
111
|
-
return x.action({
|
|
112
|
-
event: e,
|
|
113
|
-
setOpen: props.onChange,
|
|
114
|
-
text,
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
if (displayItems.length === 1) {
|
|
118
|
-
e.preventDefault();
|
|
119
|
-
const x = displayItems[0];
|
|
120
|
-
const text = e.currentTarget.value;
|
|
121
|
-
if (x.type === "shortcut")
|
|
122
|
-
return x.action({
|
|
123
|
-
event: e,
|
|
124
|
-
setOpen: props.onChange,
|
|
125
|
-
text,
|
|
104
|
+
}, [bindKey]);
|
|
105
|
+
const Icon = props.Icon ?? FilterIcon;
|
|
106
|
+
return (_jsx(Fragment, { children: _jsxs(Modal, { ref: ref, closable: false, open: props.open, overlayClickClose: true, interactions: [listNav], onChange: props.onChangeVisibility, ariaTitle: "Command palette", bodyClassName: "px-0 py-0 pt-2", "data-component": "command-palette", className: "container relative py-0 md:max-w-screen-sm lg:max-w-screen-md", children: [_jsxs("header", { className: "sticky top-0 isolate z-floating flex h-12 w-full items-center border-b border-floating-border bg-floating-background px-4", children: [_jsx("div", { className: "flex size-10 items-center justify-center", children: _jsx(Icon, { Default: FilterIcon, text: value, size: 16 }) }), _jsx("input", { autoFocus: true, value: value, "data-combikeysbypass": "true", placeholder: "Search for...", onChange: (e) => setValue(e.target.value), className: "h-12 w-full items-center bg-transparent px-2 py-2 pb-2 text-left text-lg outline-none", onKeyDown: (e) => {
|
|
107
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
108
|
+
if (activeIndex !== null)
|
|
109
|
+
listRef.current[activeIndex]?.scrollIntoView({
|
|
110
|
+
block: "start",
|
|
111
|
+
inline: "start",
|
|
126
112
|
});
|
|
127
113
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
ref(node) {
|
|
131
|
-
listRef.current[index] = node;
|
|
132
|
-
},
|
|
133
|
-
onClick(e) {
|
|
114
|
+
if (e.key === "Enter") {
|
|
115
|
+
if (activeIndex !== null && displayItems[activeIndex]) {
|
|
134
116
|
e.preventDefault();
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
117
|
+
const x = displayItems[activeIndex];
|
|
118
|
+
const text = e.currentTarget.value;
|
|
119
|
+
if (x.type === "shortcut")
|
|
120
|
+
return x.action({
|
|
121
|
+
event: e,
|
|
122
|
+
setOpen: props.onChangeVisibility,
|
|
123
|
+
text,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
if (displayItems.length === 1) {
|
|
127
|
+
e.preventDefault();
|
|
128
|
+
const x = displayItems[0];
|
|
129
|
+
const text = e.currentTarget.value;
|
|
130
|
+
if (x.type === "shortcut")
|
|
131
|
+
return x.action({
|
|
132
|
+
event: e,
|
|
133
|
+
setOpen: props.onChangeVisibility,
|
|
134
|
+
text,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
} })] }), _jsx(AnimatePresence, { children: props.loading ? (_jsxs(motion.ul, { role: "listbox", "data-component": "command-palette-list", animate: { transform: "scaleY(1)", opacity: 1 }, initial: { transform: "scaleY(0)", opacity: 0.3 }, className: "my-2 flex max-h-96 w-full origin-[top_center] flex-col gap-1 overflow-y-auto px-2", children: [_jsx(motion.div, { className: "h-10 px-2 pb-1 pt-2", children: translations.commandPaletteLoading }), loadingSkeleton.map((x, i) => {
|
|
139
|
+
return (_jsx(motion.li, { className: css("flex h-10 items-center justify-between rounded-lg p-2 hover:bg-primary hover:text-primary-foreground"), children: SkeletonCell }, `${id}-${i}-skeleton-index`));
|
|
140
|
+
})] })) : (_jsxs(motion.div, { className: "flex min-w-full flex-row flex-nowrap", "data-component": "command-palette-container", children: [_jsxs(motion.ul, { role: "listbox", "data-component": "command-palette-list", animate: { transform: "scaleY(1)", opacity: 1 }, initial: { transform: "scaleY(0)", opacity: 0.3 }, className: "my-2 flex h-fit max-h-96 w-full origin-[top_center] flex-col gap-1 overflow-y-auto px-2", children: [displayItems.map((item, index) => (_createElement(Item, { ...getItemProps({
|
|
141
|
+
onMouseEnter: () => setActiveIndex(index),
|
|
142
|
+
ref(node) {
|
|
143
|
+
listRef.current[index] = node;
|
|
144
|
+
},
|
|
145
|
+
onClick(e) {
|
|
146
|
+
e.preventDefault();
|
|
147
|
+
props.onChangeVisibility(false);
|
|
148
|
+
floating.refs.domReference.current?.focus();
|
|
149
|
+
if (item.type === "shortcut")
|
|
150
|
+
item.action({
|
|
151
|
+
event: e,
|
|
152
|
+
setOpen: props.onChangeVisibility,
|
|
153
|
+
text: value,
|
|
154
|
+
});
|
|
155
|
+
},
|
|
156
|
+
}), item: item, text: value, active: activeIndex === index, key: `${id}-${item.type}-${index}` }))), displayItems.length === 1 ? (_jsx(motion.div, { className: css("flex items-center justify-between rounded-lg p-2 text-secondary"), children: translations.commandPaletteEmpty ?? props.emptyMessage })) : null] }), props.Preview && Is.number(activeIndex) ? _jsx(props.Preview, { command: displayItems[activeIndex], text: value }) : null] })) }), props.footer ? _jsx("footer", { className: "flex h-8 items-center rounded-b-lg bg-background p-2", children: props.footer }) : null] }) }));
|
|
139
157
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu.d.ts","sourceRoot":"","sources":["../../../../src/components/floating/menu.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"menu.d.ts","sourceRoot":"","sources":["../../../../src/components/floating/menu.tsx"],"names":[],"mappings":"AA0BA,OAAO,EAAoB,WAAW,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,KAA2E,MAAM,OAAO,CAAC;AA6BhG,MAAM,MAAM,SAAS,GAAG,OAAO,CAC3B;IACI,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,EAAE,KAAK,CAAC,WAAW,CAAC;CACxC,GAAG,CAAC;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,KAAK,CAAC,YAAY,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CACzE,CAAC;AAmKF,KAAK,aAAa,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAAC,CAAA;CAAE,CAAC;AAE1F,eAAO,MAAM,QAAQ,oKAmCpB,CAAC;AAEF,eAAO,MAAM,IAAI;WAnNF,OAAO;WACP,OAAO;YACN,OAAO;aACN,OAAO;cACN,OAAO;cACP,KAAK,CAAC,SAAS;uBACN,MAAM;uBACN,KAAK,CAAC,WAAW;;WAC1B,MAAM;;WART,OAAO;WACP,OAAO;YACN,OAAO;aACN,OAAO;cACN,OAAO;cACP,KAAK,CAAC,SAAS;uBACN,MAAM;uBACN,KAAK,CAAC,WAAW;;WACN,KAAK,CAAC,YAAY;WAAS,MAAM;qDAoNrE,CAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { autoUpdate, flip, FloatingFocusManager, FloatingList, FloatingNode, FloatingPortal, FloatingTree, offset, safePolygon, shift, useClick, useDismiss, useFloating, useFloatingNodeId, useFloatingParentNodeId, useFloatingTree, useHover, useInteractions, useListItem, useListNavigation,
|
|
3
|
+
import { autoUpdate, flip, FloatingFocusManager, FloatingList, FloatingNode, FloatingPortal, FloatingTree, offset, safePolygon, shift, useClick, useDismiss, useFloating, useFloatingNodeId, useFloatingParentNodeId, useFloatingTree, useHover, useInteractions, useListItem, useListNavigation, useRole, useTypeahead, } from "@floating-ui/react";
|
|
4
4
|
import { Slot } from "@radix-ui/react-slot";
|
|
5
5
|
import { ChevronRightIcon } from "lucide-react";
|
|
6
6
|
import React, { createContext, Fragment, useContext, useEffect, useRef, useState } from "react";
|
|
7
7
|
import { FLOATING_DELAY, TYPEAHEAD_RESET_DELAY } from "../../constants";
|
|
8
|
-
import { css } from "../../lib/dom";
|
|
8
|
+
import { css, mergeRefs } from "../../lib/dom";
|
|
9
9
|
const menuItemClassName = (highlight = "") => css("w-full min-w-36 outline-none p-2.5 items-center flex justify-between text-left", "hover:bg-primary focus:bg-primary aria-expanded:opacity-80", "focus:text-primary-foreground hover:text-primary-foreground", "first-of-type:rounded-t-lg last-of-type:rounded-b-lg", "disabled:opacity-40 disabled:cursor-not-allowed", highlight);
|
|
10
10
|
const MenuContext = createContext({
|
|
11
11
|
isOpen: false,
|
|
@@ -45,16 +45,17 @@ const MenuComponent = React.forwardRef(({ children, FloatingComponent = "div", h
|
|
|
45
45
|
handleClose: safePolygon({ blockPointerEvents: true }),
|
|
46
46
|
});
|
|
47
47
|
const click = useClick(context, {
|
|
48
|
-
event: "mousedown",
|
|
49
48
|
toggle: !isNested,
|
|
49
|
+
event: "mousedown",
|
|
50
50
|
ignoreMouse: isNested,
|
|
51
51
|
keyboardHandlers: true,
|
|
52
|
+
enabled: props.disabled === false,
|
|
52
53
|
});
|
|
53
54
|
const listNavigation = useListNavigation(context, {
|
|
54
55
|
loop: true,
|
|
55
|
-
listRef: elementsRef,
|
|
56
56
|
activeIndex,
|
|
57
57
|
nested: isNested,
|
|
58
|
+
listRef: elementsRef,
|
|
58
59
|
onNavigate: setActiveIndex,
|
|
59
60
|
});
|
|
60
61
|
const typeahead = useTypeahead(context, {
|
|
@@ -67,14 +68,11 @@ const MenuComponent = React.forwardRef(({ children, FloatingComponent = "div", h
|
|
|
67
68
|
useEffect(() => {
|
|
68
69
|
if (!tree)
|
|
69
70
|
return;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
function onSubMenuOpen(event) {
|
|
74
|
-
if (event.nodeId !== nodeId && event.parentId === parentId) {
|
|
71
|
+
const handleTreeClick = () => setIsOpen(false);
|
|
72
|
+
const onSubMenuOpen = (event) => {
|
|
73
|
+
if (event.nodeId !== nodeId && event.parentId === parentId)
|
|
75
74
|
setIsOpen(false);
|
|
76
|
-
|
|
77
|
-
}
|
|
75
|
+
};
|
|
78
76
|
tree.events.on("click", handleTreeClick);
|
|
79
77
|
tree.events.on("menuopen", onSubMenuOpen);
|
|
80
78
|
return () => {
|
|
@@ -83,9 +81,8 @@ const MenuComponent = React.forwardRef(({ children, FloatingComponent = "div", h
|
|
|
83
81
|
};
|
|
84
82
|
}, [tree, nodeId, parentId]);
|
|
85
83
|
useEffect(() => {
|
|
86
|
-
if (isOpen && tree)
|
|
84
|
+
if (isOpen && tree)
|
|
87
85
|
tree.events.emit("menuopen", { parentId, nodeId });
|
|
88
|
-
}
|
|
89
86
|
}, [tree, isOpen, nodeId, parentId]);
|
|
90
87
|
const className = isParent ? props.className : css(menuItemClassName(props.className));
|
|
91
88
|
return (_jsxs(FloatingNode, { id: nodeId, children: [_jsx(Fragment, { children: props.asChild ? (_jsx(Slot, { ...getReferenceProps(parent.getItemProps({
|
|
@@ -95,7 +92,7 @@ const MenuComponent = React.forwardRef(({ children, FloatingComponent = "div", h
|
|
|
95
92
|
setHasFocusInside(false);
|
|
96
93
|
parent.setHasFocusInside(true);
|
|
97
94
|
},
|
|
98
|
-
})), children: label,
|
|
95
|
+
})), children: label, className: className, "data-open": isOpen ? "" : undefined, "data-nested": isNested ? "" : undefined, role: isNested ? "menuitem" : undefined, "data-focus-inside": hasFocusInside ? "" : undefined, ref: mergeRefs(refs.setReference, item.ref, forwardedRef), tabIndex: !isNested ? undefined : parent.activeIndex === item.index ? 0 : -1 })) : (_jsxs("button", { type: "button", className: className, "data-open": isOpen ? "" : undefined, "data-nested": isNested ? "" : undefined, role: isNested ? "menuitem" : undefined, "data-focus-inside": hasFocusInside ? "" : undefined, ref: mergeRefs(refs.setReference, item.ref, forwardedRef), tabIndex: !isNested ? undefined : parent.activeIndex === item.index ? 0 : -1, ...getReferenceProps(parent.getItemProps({
|
|
99
96
|
...props,
|
|
100
97
|
onFocus(event) {
|
|
101
98
|
props.onFocus?.(event);
|
|
@@ -109,7 +106,7 @@ export const MenuItem = React.forwardRef(({ title, Right, disabled, children, ..
|
|
|
109
106
|
const item = useListItem({ label: disabled ? null : title });
|
|
110
107
|
const tree = useFloatingTree();
|
|
111
108
|
const isActive = item.index === menu.activeIndex;
|
|
112
|
-
return (_jsxs("button", { ...props, title: title, type: "button", role: "menuitem", disabled: disabled, "data-active": isActive, "data-open": menu.isOpen, tabIndex: isActive ? 0 : -1, ref:
|
|
109
|
+
return (_jsxs("button", { ...props, title: title, type: "button", role: "menuitem", disabled: disabled, "data-active": isActive, "data-open": menu.isOpen, tabIndex: isActive ? 0 : -1, ref: mergeRefs(item.ref, forwardedRef), className: menuItemClassName(`${props.className ?? ""} ${isActive ? "bg-primary text-primary-foreground" : ""}`), ...menu.getItemProps({
|
|
113
110
|
onClick(event) {
|
|
114
111
|
props.onClick?.(event);
|
|
115
112
|
tree?.events.emit("click");
|
|
@@ -1,44 +1,42 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
export declare const defaultTranslations: {
|
|
3
|
+
autocompleteEmpty: string;
|
|
4
|
+
calendarBackMonth: string;
|
|
5
|
+
calendarFromDate: string;
|
|
6
|
+
calendarMonthLabel: string;
|
|
7
|
+
calendarNextMonth: string;
|
|
8
|
+
calendarToDate: string;
|
|
9
|
+
calendarToday: string;
|
|
10
|
+
commandPaletteEmpty: string;
|
|
11
|
+
commandPaletteLoading: string;
|
|
12
|
+
datePickerCalendarButtonLabel: string;
|
|
3
13
|
emptyDataMessage: string;
|
|
4
14
|
inputCaretDown: string;
|
|
5
15
|
inputCloseValue: string;
|
|
6
|
-
datePickerCalendarButtonLabel: string;
|
|
7
16
|
inputOptionalLabel: string;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
tableGroupLabelWithCount: string;
|
|
11
|
-
tableSortAsc: string;
|
|
12
|
-
tableSortOrderByLabel: string;
|
|
13
|
-
tableSortOrderInputPlaceholder: string;
|
|
14
|
-
tableSortOrderInputTitle: string;
|
|
15
|
-
tableSortTypeInputPlaceholder: string;
|
|
16
|
-
tableSortTypeInputTitle: string;
|
|
17
|
-
tableSortAddButton: string;
|
|
18
|
-
tableSortDropdownTitle: string;
|
|
19
|
-
tableSortDesc: string;
|
|
17
|
+
multiSelectInnerPlaceholder: string;
|
|
18
|
+
multiSelectSelectedLabel: string;
|
|
20
19
|
tableColumnResizer: string;
|
|
20
|
+
tableFilterColumnPlaceholder: string;
|
|
21
|
+
tableFilterColumnTitle: string;
|
|
22
|
+
tableFilterDropdownTitle: string;
|
|
23
|
+
tableFilterDropdownTitleUnique: string;
|
|
24
|
+
tableFilterLabel: string;
|
|
25
|
+
tableFilterNewFilter: string;
|
|
26
|
+
tableFilterOperatorPlaceholder: string;
|
|
27
|
+
tableFilterOperatorTitle: string;
|
|
21
28
|
tableFilterTypeContains: string;
|
|
29
|
+
tableFilterTypeEndsWith: string;
|
|
30
|
+
tableFilterTypeGreaterThan: string;
|
|
22
31
|
tableFilterTypeIs: string;
|
|
23
32
|
tableFilterTypeIsNot: string;
|
|
24
|
-
tableFilterTypeNotContains: string;
|
|
25
33
|
tableFilterTypeLessThan: string;
|
|
26
|
-
|
|
34
|
+
tableFilterTypeNotContains: string;
|
|
27
35
|
tableFilterTypeStartsWith: string;
|
|
28
|
-
tableFilterTypeEndsWith: string;
|
|
29
|
-
tableFilterNewFilter: string;
|
|
30
|
-
tableFilterColumnTitle: string;
|
|
31
|
-
tableFilterColumnPlaceholder: string;
|
|
32
|
-
tableFilterOperatorTitle: string;
|
|
33
|
-
tableFilterOperatorPlaceholder: string;
|
|
34
|
-
tableFilterValueTitle: string;
|
|
35
36
|
tableFilterValuePlaceholder: string;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
tablePaginationPrevious: string;
|
|
40
|
-
tablePaginationNext: string;
|
|
41
|
-
tablePaginationSelectLabel: string;
|
|
37
|
+
tableFilterValueTitle: string;
|
|
38
|
+
tableGroupLabel: string;
|
|
39
|
+
tableGroupLabelWithCount: string;
|
|
42
40
|
tablePaginationFooter: (pagination: {
|
|
43
41
|
pages: number;
|
|
44
42
|
totalItems: number;
|
|
@@ -46,15 +44,18 @@ export declare const defaultTranslations: {
|
|
|
46
44
|
current: number;
|
|
47
45
|
select: React.ReactNode;
|
|
48
46
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
47
|
+
tablePaginationNext: string;
|
|
48
|
+
tablePaginationPrevious: string;
|
|
49
|
+
tablePaginationSelectLabel: string;
|
|
50
|
+
tableSortAddButton: string;
|
|
51
|
+
tableSortAsc: string;
|
|
52
|
+
tableSortDesc: string;
|
|
53
|
+
tableSortDropdownTitle: string;
|
|
54
|
+
tableSortOrderByLabel: string;
|
|
55
|
+
tableSortOrderInputPlaceholder: string;
|
|
56
|
+
tableSortOrderInputTitle: string;
|
|
57
|
+
tableSortTypeInputPlaceholder: string;
|
|
58
|
+
tableSortTypeInputTitle: string;
|
|
58
59
|
};
|
|
59
60
|
export type Translations = typeof defaultTranslations;
|
|
60
61
|
//# sourceMappingURL=default-translations.d.ts.map
|