pi-emoji-complete 0.0.0-stage → 1.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/CHANGELOG.md +6 -0
- package/LICENSE +21 -0
- package/README.md +26 -2
- package/extensions/emoji-complete.js +122 -0
- package/extensions/name-to-emoji.js +1916 -0
- package/package.json +40 -4
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
-
#
|
|
1
|
+
# pi-emoji-complete
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Slack / Claude-style `:shortcode:` emoji autocomplete for the [Pi](https://pi.dev) editor.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Triggers on `:<query>` (2+ characters) at the start of a line or after whitespace / opening punctuation
|
|
8
|
+
- Full GitHub emoji shortcode set (~1,900 emojis, extracted from `gemoji` with zero runtime dependencies)
|
|
9
|
+
- Live filtering as you type or backspace (exact → prefix → substring → fuzzy)
|
|
10
|
+
- Navigate with Up/Down arrows, accept with `Tab` or `Enter`, cancel with `Esc`
|
|
11
|
+
- Plays nicely with built-in `/` slash commands and `@` file path completion
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pi install npm:pi-emoji-complete
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or try it for a single session:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pi -e npm:pi-emoji-complete
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Contributing
|
|
26
|
+
|
|
27
|
+
See [contrib.md](./contrib.md) for architecture notes, build-time emoji extraction, and testing instructions.
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// Emoji autocomplete for Pi editor
|
|
2
|
+
// - Trigger: :<query> (2+ chars at start of line or after whitespace/opening punctuation)
|
|
3
|
+
// - Navigation: up/down arrows, Tab or Enter to insert emoji, Esc to cancel
|
|
4
|
+
// - Live filtering as you type or backspace
|
|
5
|
+
|
|
6
|
+
import { nameToEmoji } from "./name-to-emoji.js";
|
|
7
|
+
|
|
8
|
+
const EMOJI_ITEMS = Object.entries(nameToEmoji).map(([name, emoji]) => ({
|
|
9
|
+
name,
|
|
10
|
+
value: emoji,
|
|
11
|
+
label: `${emoji} :${name}:`,
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
const MIN_QUERY_LENGTH = 2;
|
|
15
|
+
const MAX_SUGGESTIONS = 20;
|
|
16
|
+
const SHORTCODE_RE = /(?:^|[\s([{"'`]):([a-zA-Z0-9_+-]+)$/;
|
|
17
|
+
|
|
18
|
+
export function extractEmojiQuery(textBeforeCursor) {
|
|
19
|
+
const match = textBeforeCursor.match(SHORTCODE_RE);
|
|
20
|
+
if (!match) return null;
|
|
21
|
+
const query = match[1];
|
|
22
|
+
if (!query || query.length < MIN_QUERY_LENGTH) return null;
|
|
23
|
+
return query;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function isSubsequence(query, target) {
|
|
27
|
+
let qi = 0;
|
|
28
|
+
for (let ti = 0; ti < target.length && qi < query.length; ti++) {
|
|
29
|
+
if (target[ti] === query[qi]) qi++;
|
|
30
|
+
}
|
|
31
|
+
return qi === query.length;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function filterEmoji(query, limit = MAX_SUGGESTIONS) {
|
|
35
|
+
const q = query.toLowerCase();
|
|
36
|
+
const exact = [];
|
|
37
|
+
const prefix = [];
|
|
38
|
+
const substring = [];
|
|
39
|
+
const fuzzy = [];
|
|
40
|
+
|
|
41
|
+
for (const item of EMOJI_ITEMS) {
|
|
42
|
+
const name = item.name;
|
|
43
|
+
if (name === q) {
|
|
44
|
+
exact.push(item);
|
|
45
|
+
if (exact.length >= limit) break;
|
|
46
|
+
} else if (name.startsWith(q)) {
|
|
47
|
+
if (prefix.length < limit) prefix.push(item);
|
|
48
|
+
} else if (exact.length + prefix.length < limit) {
|
|
49
|
+
if (name.includes(q)) {
|
|
50
|
+
if (substring.length < limit) substring.push(item);
|
|
51
|
+
} else if (
|
|
52
|
+
exact.length + prefix.length + substring.length === 0 &&
|
|
53
|
+
fuzzy.length < limit &&
|
|
54
|
+
isSubsequence(q, name)
|
|
55
|
+
) {
|
|
56
|
+
fuzzy.push(item);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const direct = [...exact, ...prefix, ...substring];
|
|
62
|
+
return (direct.length > 0 ? direct : fuzzy).slice(0, limit);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function createEmojiAutocompleteProvider(current) {
|
|
66
|
+
const triggerCharacters = [...(current.triggerCharacters ?? []), ":"];
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
triggerCharacters,
|
|
70
|
+
|
|
71
|
+
async getSuggestions(lines, cursorLine, cursorCol, options) {
|
|
72
|
+
const currentLine = lines[cursorLine] ?? "";
|
|
73
|
+
const textBeforeCursor = currentLine.slice(0, cursorCol);
|
|
74
|
+
const query = extractEmojiQuery(textBeforeCursor);
|
|
75
|
+
|
|
76
|
+
if (query === null) {
|
|
77
|
+
return current.getSuggestions(lines, cursorLine, cursorCol, options);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const items = filterEmoji(query);
|
|
81
|
+
if (items.length === 0) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
items,
|
|
87
|
+
prefix: `:${query}`,
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
applyCompletion(lines, cursorLine, cursorCol, item, prefix) {
|
|
92
|
+
if (!prefix.startsWith(":")) {
|
|
93
|
+
return current.applyCompletion(lines, cursorLine, cursorCol, item, prefix);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const currentLine = lines[cursorLine] ?? "";
|
|
97
|
+
const beforePrefix = currentLine.slice(0, cursorCol - prefix.length);
|
|
98
|
+
const afterCursor = currentLine.slice(cursorCol);
|
|
99
|
+
const needsTrailingSpace = afterCursor.length === 0 || !/^\s/.test(afterCursor);
|
|
100
|
+
const inserted = needsTrailingSpace ? `${item.value} ` : item.value;
|
|
101
|
+
|
|
102
|
+
const newLines = [...lines];
|
|
103
|
+
newLines[cursorLine] = `${beforePrefix}${inserted}${afterCursor}`;
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
lines: newLines,
|
|
107
|
+
cursorLine,
|
|
108
|
+
cursorCol: beforePrefix.length + inserted.length,
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
shouldTriggerFileCompletion(lines, cursorLine, cursorCol) {
|
|
113
|
+
return current.shouldTriggerFileCompletion?.(lines, cursorLine, cursorCol) ?? true;
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export default function (pi) {
|
|
119
|
+
pi.on("session_start", (_event, ctx) => {
|
|
120
|
+
ctx.ui.addAutocompleteProvider((current) => createEmojiAutocompleteProvider(current));
|
|
121
|
+
});
|
|
122
|
+
}
|