@portabletext/plugin-emoji-picker 0.0.15
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 +3 -0
- package/dist/index.cjs +2711 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +209 -0
- package/dist/index.d.ts +209 -0
- package/dist/index.js +2703 -0
- package/dist/index.js.map +1 -0
- package/package.json +88 -0
- package/src/emoji-picker-machine.tsx +1009 -0
- package/src/emoji-picker.feature +127 -0
- package/src/emoji-picker.test.tsx +45 -0
- package/src/emojis.ts +15219 -0
- package/src/global.d.ts +4 -0
- package/src/index.ts +2 -0
- package/src/match-emojis.ts +121 -0
- package/src/use-emoji-picker.ts +181 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
Feature: Emoji Picker
|
|
2
|
+
|
|
3
|
+
Background:
|
|
4
|
+
Given the editor is focused
|
|
5
|
+
|
|
6
|
+
Scenario: Picking a direct hit
|
|
7
|
+
When ":joy:" is typed
|
|
8
|
+
Then the text is "π"
|
|
9
|
+
|
|
10
|
+
Scenario: Picking the closest hit with Enter
|
|
11
|
+
When ":joy" is typed
|
|
12
|
+
And "{Enter}" is pressed
|
|
13
|
+
Then the text is "π"
|
|
14
|
+
|
|
15
|
+
Scenario: Picking the closest hit with Tab
|
|
16
|
+
When ":joy" is typed
|
|
17
|
+
And "{Tab}" is pressed
|
|
18
|
+
Then the text is "π"
|
|
19
|
+
|
|
20
|
+
Scenario: Navigating down the list
|
|
21
|
+
When ":joy" is typed
|
|
22
|
+
And "{ArrowDown}" is pressed
|
|
23
|
+
And "{Enter}" is pressed
|
|
24
|
+
Then the text is "πΉ"
|
|
25
|
+
|
|
26
|
+
Scenario: Aborting on Escape
|
|
27
|
+
When ":joy" is typed
|
|
28
|
+
And "{Escape}" is pressed
|
|
29
|
+
And "{Enter}" is pressed
|
|
30
|
+
Then the text is ":joy|"
|
|
31
|
+
|
|
32
|
+
Scenario: Backspacing to narrow search
|
|
33
|
+
When ":joy" is typed
|
|
34
|
+
And "{Backspace}" is pressed
|
|
35
|
+
And "{Enter}" is pressed
|
|
36
|
+
Then the text is "π"
|
|
37
|
+
|
|
38
|
+
Scenario Outline: Inserting longer trigger text
|
|
39
|
+
Given the text <text>
|
|
40
|
+
When <inserted text> is inserted
|
|
41
|
+
And <new text> is typed
|
|
42
|
+
Then the text is <final text>
|
|
43
|
+
|
|
44
|
+
Examples:
|
|
45
|
+
| text | inserted text | new text | final text |
|
|
46
|
+
| "" | ":" | "joy:" | "π" |
|
|
47
|
+
| "" | ":j" | "oy:" | "π" |
|
|
48
|
+
| "" | ":joy" | ":" | "π" |
|
|
49
|
+
| "" | ":joy:" | ":" | "π:" |
|
|
50
|
+
|
|
51
|
+
Scenario Outline: Matching inside decorator
|
|
52
|
+
Given the text <text>
|
|
53
|
+
And "strong" around <decorated>
|
|
54
|
+
When the caret is put <position>
|
|
55
|
+
And <keyword> is typed
|
|
56
|
+
Then the text is <final text>
|
|
57
|
+
|
|
58
|
+
Examples:
|
|
59
|
+
| text | decorated | position | keyword | final text |
|
|
60
|
+
| "foo bar baz" | "bar" | before "ar baz" | ":joy:" | "foo ,bπar, baz" |
|
|
61
|
+
| "foo bar baz" | "bar" | before "r baz" | ":joy:" | "foo ,baπr, baz" |
|
|
62
|
+
|
|
63
|
+
Scenario Outline: Matching at the edge of decorator
|
|
64
|
+
Given the text <text>
|
|
65
|
+
And "strong" around <decorated>
|
|
66
|
+
When the caret is put <position>
|
|
67
|
+
And <keyword> is typed
|
|
68
|
+
Then the text is <final text>
|
|
69
|
+
|
|
70
|
+
Examples:
|
|
71
|
+
| text | decorated | position | keyword | final text |
|
|
72
|
+
| "foo bar baz" | "bar" | after "foo " | ":joy:" | "foo π,bar, baz" |
|
|
73
|
+
# | "foo bar baz" | "bar" | before "bar" | ":joy:" | "foo π,bar, baz" |
|
|
74
|
+
| "foo bar baz" | "bar" | after "bar" | ":joy:" | "foo ,barπ, baz" |
|
|
75
|
+
|
|
76
|
+
# | "foo bar baz" | "bar" | before " baz" | ":joy:" | "foo ,barπ, baz" |
|
|
77
|
+
Scenario Outline: Matching inside annotation
|
|
78
|
+
Given the text <text>
|
|
79
|
+
And a "link" "l1" around <annotated>
|
|
80
|
+
When the caret is put <position>
|
|
81
|
+
And <keyword> is typed
|
|
82
|
+
Then the text is <final text>
|
|
83
|
+
|
|
84
|
+
Examples:
|
|
85
|
+
| text | annotated | position | keyword | final text |
|
|
86
|
+
| "foo bar baz" | "bar" | before "ar baz" | ":joy:" | "foo ,bπar, baz" |
|
|
87
|
+
| "foo bar baz" | "bar" | before "r baz" | ":joy:" | "foo ,baπr, baz" |
|
|
88
|
+
|
|
89
|
+
Scenario Outline: Matching at the edge of an annotation
|
|
90
|
+
Given the text <text>
|
|
91
|
+
And a "link" "l1" around <annotated>
|
|
92
|
+
When the caret is put <position>
|
|
93
|
+
And <keyword> is typed
|
|
94
|
+
Then the text is <final text>
|
|
95
|
+
|
|
96
|
+
Examples:
|
|
97
|
+
| text | annotated | position | keyword | final text |
|
|
98
|
+
| "foo bar baz" | "bar" | after "foo " | ":joy:" | "foo π,bar, baz" |
|
|
99
|
+
# | "foo bar baz" | "bar" | before "bar" | ":joy:" | "foo π,bar, baz" |
|
|
100
|
+
| "foo bar baz" | "bar" | after "bar" | ":joy:" | "foo ,bar,π baz" |
|
|
101
|
+
| "foo bar baz" | "bar" | before " baz" | ":joy:" | "foo ,bar,π baz" |
|
|
102
|
+
|
|
103
|
+
Scenario Outline: Typing before the colon
|
|
104
|
+
Given the text <text>
|
|
105
|
+
When <keyword> is typed
|
|
106
|
+
And <button> is pressed
|
|
107
|
+
And <new text> is typed
|
|
108
|
+
And "{Enter}" is pressed
|
|
109
|
+
Then the text is <final text>
|
|
110
|
+
|
|
111
|
+
Examples:
|
|
112
|
+
| text | keyword | button | new text | final text |
|
|
113
|
+
| "" | ":j" | "{ArrowLeft}{ArrowLeft}" | "f" | "f\|:j" |
|
|
114
|
+
| "fo" | ":j" | "{ArrowLeft}{ArrowLeft}" | "o" | "foo\|:j" |
|
|
115
|
+
|
|
116
|
+
Scenario Outline: Navigating away from the keyword
|
|
117
|
+
Given the text <text>
|
|
118
|
+
When the caret is put <position>
|
|
119
|
+
And <keyword> is typed
|
|
120
|
+
And <button> is pressed
|
|
121
|
+
And "{Enter}" is pressed
|
|
122
|
+
Then the text is <final text>
|
|
123
|
+
|
|
124
|
+
Examples:
|
|
125
|
+
| text | position | keyword | button | final text |
|
|
126
|
+
| "foo bar baz" | after "foo" | ":j" | "{ArrowRight}" | "foo:j \|bar baz" |
|
|
127
|
+
| "foo bar baz" | after "foo" | ":j" | "{ArrowLeft}{ArrowLeft}{ArrowLeft}" | "fo\|o:j bar baz" |
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {parameterTypes} from '@portabletext/editor/test'
|
|
2
|
+
import {
|
|
3
|
+
createTestEditor,
|
|
4
|
+
stepDefinitions,
|
|
5
|
+
type Context,
|
|
6
|
+
} from '@portabletext/editor/test/vitest'
|
|
7
|
+
import {defineSchema} from '@portabletext/schema'
|
|
8
|
+
import {Before} from 'racejar'
|
|
9
|
+
import {Feature} from 'racejar/vitest'
|
|
10
|
+
import emojiPickerFeature from './emoji-picker.feature?raw'
|
|
11
|
+
import {createMatchEmojis} from './match-emojis'
|
|
12
|
+
import {useEmojiPicker} from './use-emoji-picker'
|
|
13
|
+
|
|
14
|
+
Feature({
|
|
15
|
+
hooks: [
|
|
16
|
+
Before(async (context: Context) => {
|
|
17
|
+
const {editor, locator} = await createTestEditor({
|
|
18
|
+
children: <EmojiPickerPlugin />,
|
|
19
|
+
schemaDefinition: defineSchema({
|
|
20
|
+
decorators: [{name: 'strong'}],
|
|
21
|
+
annotations: [{name: 'link'}],
|
|
22
|
+
}),
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
context.locator = locator
|
|
26
|
+
context.editor = editor
|
|
27
|
+
}),
|
|
28
|
+
],
|
|
29
|
+
featureText: emojiPickerFeature,
|
|
30
|
+
stepDefinitions,
|
|
31
|
+
parameterTypes,
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
const emojis: Record<string, Array<string>> = {
|
|
35
|
+
'π': ['joy'],
|
|
36
|
+
'πΉ': ['joy_cat'],
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const matchEmojis = createMatchEmojis({emojis})
|
|
40
|
+
|
|
41
|
+
function EmojiPickerPlugin() {
|
|
42
|
+
useEmojiPicker({matchEmojis})
|
|
43
|
+
|
|
44
|
+
return null
|
|
45
|
+
}
|