Compare commits

..

3 commits

Author SHA1 Message Date
1963fddb7f
add fuse for fuzzy searching
All checks were successful
Actions / Build Plugins (push) Successful in 40s
currently unimplemented
2024-12-23 14:38:54 -05:00
870b4b2b7e
working on grid emojipicker 2024-12-23 14:38:42 -05:00
689e5db74a
add license 2024-12-23 14:15:04 -05:00
7 changed files with 3730 additions and 153 deletions

9
LICENSE Normal file
View file

@ -0,0 +1,9 @@
# The MIT License (MIT)
Copyright © 2024 cswimr
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -7,18 +7,18 @@ Repository: https://www.coastalcommits.com/cswimr/gauntlet-emojipicker
"""
[[entrypoint]]
id = 'emojipicker'
id = 'emojipicker-legacy'
name = 'Emoji Picker'
path = 'src/emojipicker.tsx'
path = 'src/emojipicker-legacy.tsx'
type = 'inline-view'
description = """
Copy emojis to your clipboard from Gauntlet!
"""
[[entrypoint]]
id = 'emojipicker-grid'
name = 'Emoji Picker (Grid)'
path = 'src/emojipicker-grid.tsx'
id = 'emojipicker'
name = 'Emoji Picker'
path = 'src/emojipicker.tsx'
type = 'view'
description = """
Copy emojis to your clipboard from Gauntlet!

View file

@ -1,5 +1,6 @@
{
"name": "cswimr-gauntlet-plugins",
"license": "MIT",
"scripts": {
"publish": "gauntlet publish",
"build": "gauntlet build",
@ -8,6 +9,7 @@
},
"dependencies": {
"@project-gauntlet/api": "0.12.0",
"fuse": "^0.12.1",
"unicode-emoji": "^2.6.0",
"which": "^5.0.0"
},

View file

@ -1,68 +0,0 @@
import { Grid } from "@project-gauntlet/api/components";
import React, { ReactNode, useState } from "react";
import { Clipboard, showHud } from "@project-gauntlet/api/helpers";
import {
GroupedBy,
BaseEmoji,
getEmojis,
getEmojisGroupedBy,
} from "unicode-emoji";
// @ts-expect-error gauntlet uses deno and not node
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const denoCore: DenoCore = Deno[Deno.internal].core;
export default function EmojiPicker(): ReactNode | undefined {
const [searchText, setSearchText] = useState<string | undefined>("");
let emojiList: BaseEmoji[] | Record<GroupedBy, BaseEmoji[]>;
let isCategory = null;
if (searchText) {
emojiList = getEmojis().filter((emoji) =>
emoji.keywords.some((keyword) => keyword.includes(searchText)),
);
isCategory = false;
} else {
emojiList = getEmojisGroupedBy("category");
isCategory = true;
}
return (
<Grid>
<Grid.SearchBar
placeholder={"Search for an emoji"}
value={searchText}
onChange={setSearchText}
/>
{isCategory
? Object.entries(emojiList).map(([category, emojis]) => (
<Grid.Section key={category} title={category}>
{emojis.map((emoji: BaseEmoji) => (
<Grid.Item
key={emoji.emoji}
title={emoji.emoji}
subtitle={emoji.keywords.join(", ")}
onClick={async () => {
console.log(emoji);
await Clipboard.writeText(emoji.emoji);
showHud(`${emoji.emoji} copied to clipboard`);
}}
/>
))}
</Grid.Section>
))
: (emojiList as BaseEmoji[]).map((emoji: BaseEmoji) => (
<Grid.Item
key={emoji.emoji}
title={emoji.emoji}
subtitle={emoji.keywords.join(", ")}
onClick={async () => {
console.log(emoji);
await Clipboard.writeText(emoji.emoji);
showHud(`${emoji.emoji} copied to clipboard`);
}}
/>
))}
</Grid>
);
}

View file

@ -0,0 +1,56 @@
import {
Action,
ActionPanel,
Content,
Icons,
Inline,
} from "@project-gauntlet/api/components";
import React, { ReactNode } from "react";
import { Clipboard, showHud } from "@project-gauntlet/api/helpers";
import * as UnicodeEmoji from "unicode-emoji";
// @ts-expect-error gauntlet uses deno and not node
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const denoCore: DenoCore = Deno[Deno.internal].core;
export default function EmojiPicker(props: {
text: string;
}): ReactNode | undefined {
const text = props.text.trim();
if (text.length < 3) {
return undefined;
}
const emoji = UnicodeEmoji.getEmojis().find((emoji) =>
emoji.keywords.includes(text),
);
if (!emoji) {
return undefined;
}
return (
<Inline
actions={
<ActionPanel>
<Action
label={`Copy ${emoji.emoji} to clipboard`}
onAction={async () => {
console.log(emoji);
await Clipboard.writeText(emoji.emoji);
showHud(`${emoji.emoji} copied to clipboard`);
}}
/>
</ActionPanel>
}
>
<Inline.Left>
<Content.H3>{text}</Content.H3>
</Inline.Left>
<Inline.Separator icon={Icons.ArrowRight} />
<Inline.Right>
<Content.Paragraph>{emoji.emoji}</Content.Paragraph>
</Inline.Right>
</Inline>
);
}

View file

@ -1,56 +1,89 @@
import {
Action,
ActionPanel,
Content,
Icons,
Inline,
} from "@project-gauntlet/api/components";
import React, { ReactNode } from "react";
import { Grid } from "@project-gauntlet/api/components";
import React, { ReactNode, useState } from "react";
import { Clipboard, showHud } from "@project-gauntlet/api/helpers";
import * as UnicodeEmoji from "unicode-emoji";
import {
GroupedBy,
BaseEmoji,
getEmojis,
getEmojisGroupedBy,
} from "unicode-emoji";
// @ts-expect-error gauntlet uses deno and not node
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const denoCore: DenoCore = Deno[Deno.internal].core;
export default function EmojiPicker(props: {
text: string;
}): ReactNode | undefined {
const text = props.text.trim();
export default function EmojiPicker(): ReactNode | undefined {
const [searchText, setSearchText] = useState<string | undefined>("");
if (text.length < 3) {
return undefined;
let emojiList: BaseEmoji[] | Record<GroupedBy, BaseEmoji[]>;
let isCategory = null;
if (searchText) {
emojiList = getEmojis().filter((emoji) =>
emoji.keywords.some((keyword) => keyword.includes(searchText)),
);
isCategory = false;
} else {
emojiList = getEmojisGroupedBy("category");
isCategory = true;
}
const emoji = UnicodeEmoji.getEmojis().find((emoji) =>
emoji.keywords.includes(text),
);
if (!emoji) {
return undefined;
let emojiListLength = 0;
if (isCategory) {
const typedList = emojiList as Record<GroupedBy, BaseEmoji[]>;
for (const category in typedList) {
emojiListLength += typedList[category as GroupedBy].length;
}
} else {
emojiListLength = (emojiList as BaseEmoji[]).length;
}
console.log(emojiListLength);
return (
<Inline
actions={
<ActionPanel>
<Action
label={`Copy ${emoji.emoji} to clipboard`}
onAction={async () => {
console.log(emoji);
await Clipboard.writeText(emoji.emoji);
showHud(`${emoji.emoji} copied to clipboard`);
}}
/>
</ActionPanel>
}
>
<Inline.Left>
<Content.H3>{text}</Content.H3>
</Inline.Left>
<Inline.Separator icon={Icons.ArrowRight} />
<Inline.Right>
<Content.Paragraph>{emoji.emoji}</Content.Paragraph>
</Inline.Right>
</Inline>
<Grid>
<Grid.SearchBar
placeholder={"Search for an emoji"}
value={searchText}
onChange={setSearchText}
/>
{isCategory
? Object.entries(emojiList).map(([category, emojis]) => (
<Grid.Section key={category} title={category}>
{emojis.map((emoji: BaseEmoji) => (
<Grid.Item
key={emoji.emoji}
title={emoji.description}
onClick={async () => {
console.log(emoji);
await Clipboard.writeText(emoji.emoji);
showHud(`${emoji.emoji} copied to clipboard`);
}}
>
<Grid.Item.Content>
<Grid.Item.Content.Paragraph>
{emoji.emoji}
</Grid.Item.Content.Paragraph>
</Grid.Item.Content>
</Grid.Item>
))}
</Grid.Section>
))
: (emojiList as BaseEmoji[]).map((emoji: BaseEmoji) => (
<Grid.Item
key={emoji.emoji}
title={emoji.description}
onClick={async () => {
console.log(emoji);
await Clipboard.writeText(emoji.emoji);
showHud(`${emoji.emoji} copied to clipboard`);
}}
>
<Grid.Item.Content>
<Grid.Item.Content.Paragraph>
{emoji.emoji}
</Grid.Item.Content.Paragraph>
</Grid.Item.Content>
</Grid.Item>
))}
</Grid>
);
}

3621
yarn.lock

File diff suppressed because it is too large Load diff