@portabletext/plugin-emoji-picker 1.0.0 → 1.0.2
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 +1 -1
- package/dist/index.cjs +23 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +31 -12
- package/dist/index.d.ts +31 -12
- package/dist/index.js +23 -22
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/create-match-emojis.ts +113 -0
- package/src/emoji-picker-machine.tsx +4 -4
- package/src/emoji-picker.feature +2 -2
- package/src/emoji-picker.test.tsx +1 -1
- package/src/emojis.ts +0 -3
- package/src/index.ts +1 -0
- package/src/match-emojis.ts +4 -103
- package/src/use-emoji-picker.ts +17 -13
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The base type representing an emoji match.
|
|
3
|
+
*
|
|
4
|
+
* @beta
|
|
5
|
+
*/
|
|
6
|
+
export declare type BaseEmojiMatch =
|
|
7
|
+
| {
|
|
8
|
+
type: 'exact'
|
|
9
|
+
emoji: string
|
|
10
|
+
}
|
|
11
|
+
| {
|
|
12
|
+
type: 'partial'
|
|
13
|
+
emoji: string
|
|
14
|
+
}
|
|
15
|
+
|
|
1
16
|
/**
|
|
2
17
|
* Proposed, but not required, function to create a `MatchEmojis` function.
|
|
3
18
|
*
|
|
@@ -15,7 +30,7 @@
|
|
|
15
30
|
*/
|
|
16
31
|
export declare function createMatchEmojis(config: {
|
|
17
32
|
emojis: Record<string, ReadonlyArray<string>>
|
|
18
|
-
}): MatchEmojis
|
|
33
|
+
}): MatchEmojis<EmojiMatch>
|
|
19
34
|
|
|
20
35
|
/**
|
|
21
36
|
* Proposed, but not required type, to represent an emoji match.
|
|
@@ -62,16 +77,18 @@ export declare type EmojiMatch =
|
|
|
62
77
|
/**
|
|
63
78
|
* @beta
|
|
64
79
|
*/
|
|
65
|
-
export declare type EmojiPicker<
|
|
80
|
+
export declare type EmojiPicker<
|
|
81
|
+
TEmojiMatch extends BaseEmojiMatch = BaseEmojiMatch,
|
|
82
|
+
> = {
|
|
66
83
|
/**
|
|
67
|
-
* The matched keyword
|
|
84
|
+
* The matched keyword.
|
|
68
85
|
*
|
|
69
86
|
* Can be used to display the keyword in the UI or conditionally render the
|
|
70
87
|
* list of matches.
|
|
71
88
|
*
|
|
72
89
|
* @example
|
|
73
90
|
* ```tsx
|
|
74
|
-
* if (keyword.length <
|
|
91
|
+
* if (keyword.length < 1) {
|
|
75
92
|
* return null
|
|
76
93
|
* }
|
|
77
94
|
* ```
|
|
@@ -155,7 +172,9 @@ export declare type EmojiPicker<TEmojiMatch = EmojiMatch> = {
|
|
|
155
172
|
/**
|
|
156
173
|
* @beta
|
|
157
174
|
*/
|
|
158
|
-
export declare type EmojiPickerProps<
|
|
175
|
+
export declare type EmojiPickerProps<
|
|
176
|
+
TEmojiMatch extends BaseEmojiMatch = BaseEmojiMatch,
|
|
177
|
+
> = {
|
|
159
178
|
matchEmojis: MatchEmojis<TEmojiMatch>
|
|
160
179
|
}
|
|
161
180
|
|
|
@@ -164,16 +183,16 @@ export declare type EmojiPickerProps<TEmojiMatch = EmojiMatch> = {
|
|
|
164
183
|
*
|
|
165
184
|
* @beta
|
|
166
185
|
*/
|
|
167
|
-
export declare type MatchEmojis<
|
|
168
|
-
|
|
169
|
-
}) => ReadonlyArray<TEmojiMatch>
|
|
186
|
+
export declare type MatchEmojis<
|
|
187
|
+
TEmojiMatch extends BaseEmojiMatch = BaseEmojiMatch,
|
|
188
|
+
> = (query: {keyword: string}) => ReadonlyArray<TEmojiMatch>
|
|
170
189
|
|
|
171
190
|
/**
|
|
172
191
|
* Proposed, but not required, default implementation of `MatchEmojis`.
|
|
173
192
|
*
|
|
174
193
|
* @beta
|
|
175
194
|
*/
|
|
176
|
-
export declare const matchEmojis: MatchEmojis
|
|
195
|
+
export declare const matchEmojis: MatchEmojis<EmojiMatch>
|
|
177
196
|
|
|
178
197
|
/**
|
|
179
198
|
* Handles the state and logic needed to create an emoji picker.
|
|
@@ -202,8 +221,8 @@ export declare const matchEmojis: MatchEmojis
|
|
|
202
221
|
*
|
|
203
222
|
* @beta
|
|
204
223
|
*/
|
|
205
|
-
export declare function useEmojiPicker<
|
|
206
|
-
|
|
207
|
-
): EmojiPicker<TEmojiMatch>
|
|
224
|
+
export declare function useEmojiPicker<
|
|
225
|
+
TEmojiMatch extends BaseEmojiMatch = BaseEmojiMatch,
|
|
226
|
+
>(props: EmojiPickerProps<TEmojiMatch>): EmojiPicker<TEmojiMatch>
|
|
208
227
|
|
|
209
228
|
export {}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The base type representing an emoji match.
|
|
3
|
+
*
|
|
4
|
+
* @beta
|
|
5
|
+
*/
|
|
6
|
+
export declare type BaseEmojiMatch =
|
|
7
|
+
| {
|
|
8
|
+
type: 'exact'
|
|
9
|
+
emoji: string
|
|
10
|
+
}
|
|
11
|
+
| {
|
|
12
|
+
type: 'partial'
|
|
13
|
+
emoji: string
|
|
14
|
+
}
|
|
15
|
+
|
|
1
16
|
/**
|
|
2
17
|
* Proposed, but not required, function to create a `MatchEmojis` function.
|
|
3
18
|
*
|
|
@@ -15,7 +30,7 @@
|
|
|
15
30
|
*/
|
|
16
31
|
export declare function createMatchEmojis(config: {
|
|
17
32
|
emojis: Record<string, ReadonlyArray<string>>
|
|
18
|
-
}): MatchEmojis
|
|
33
|
+
}): MatchEmojis<EmojiMatch>
|
|
19
34
|
|
|
20
35
|
/**
|
|
21
36
|
* Proposed, but not required type, to represent an emoji match.
|
|
@@ -62,16 +77,18 @@ export declare type EmojiMatch =
|
|
|
62
77
|
/**
|
|
63
78
|
* @beta
|
|
64
79
|
*/
|
|
65
|
-
export declare type EmojiPicker<
|
|
80
|
+
export declare type EmojiPicker<
|
|
81
|
+
TEmojiMatch extends BaseEmojiMatch = BaseEmojiMatch,
|
|
82
|
+
> = {
|
|
66
83
|
/**
|
|
67
|
-
* The matched keyword
|
|
84
|
+
* The matched keyword.
|
|
68
85
|
*
|
|
69
86
|
* Can be used to display the keyword in the UI or conditionally render the
|
|
70
87
|
* list of matches.
|
|
71
88
|
*
|
|
72
89
|
* @example
|
|
73
90
|
* ```tsx
|
|
74
|
-
* if (keyword.length <
|
|
91
|
+
* if (keyword.length < 1) {
|
|
75
92
|
* return null
|
|
76
93
|
* }
|
|
77
94
|
* ```
|
|
@@ -155,7 +172,9 @@ export declare type EmojiPicker<TEmojiMatch = EmojiMatch> = {
|
|
|
155
172
|
/**
|
|
156
173
|
* @beta
|
|
157
174
|
*/
|
|
158
|
-
export declare type EmojiPickerProps<
|
|
175
|
+
export declare type EmojiPickerProps<
|
|
176
|
+
TEmojiMatch extends BaseEmojiMatch = BaseEmojiMatch,
|
|
177
|
+
> = {
|
|
159
178
|
matchEmojis: MatchEmojis<TEmojiMatch>
|
|
160
179
|
}
|
|
161
180
|
|
|
@@ -164,16 +183,16 @@ export declare type EmojiPickerProps<TEmojiMatch = EmojiMatch> = {
|
|
|
164
183
|
*
|
|
165
184
|
* @beta
|
|
166
185
|
*/
|
|
167
|
-
export declare type MatchEmojis<
|
|
168
|
-
|
|
169
|
-
}) => ReadonlyArray<TEmojiMatch>
|
|
186
|
+
export declare type MatchEmojis<
|
|
187
|
+
TEmojiMatch extends BaseEmojiMatch = BaseEmojiMatch,
|
|
188
|
+
> = (query: {keyword: string}) => ReadonlyArray<TEmojiMatch>
|
|
170
189
|
|
|
171
190
|
/**
|
|
172
191
|
* Proposed, but not required, default implementation of `MatchEmojis`.
|
|
173
192
|
*
|
|
174
193
|
* @beta
|
|
175
194
|
*/
|
|
176
|
-
export declare const matchEmojis: MatchEmojis
|
|
195
|
+
export declare const matchEmojis: MatchEmojis<EmojiMatch>
|
|
177
196
|
|
|
178
197
|
/**
|
|
179
198
|
* Handles the state and logic needed to create an emoji picker.
|
|
@@ -202,8 +221,8 @@ export declare const matchEmojis: MatchEmojis
|
|
|
202
221
|
*
|
|
203
222
|
* @beta
|
|
204
223
|
*/
|
|
205
|
-
export declare function useEmojiPicker<
|
|
206
|
-
|
|
207
|
-
): EmojiPicker<TEmojiMatch>
|
|
224
|
+
export declare function useEmojiPicker<
|
|
225
|
+
TEmojiMatch extends BaseEmojiMatch = BaseEmojiMatch,
|
|
226
|
+
>(props: EmojiPickerProps<TEmojiMatch>): EmojiPicker<TEmojiMatch>
|
|
208
227
|
|
|
209
228
|
export {}
|
package/dist/index.js
CHANGED
|
@@ -2623,48 +2623,48 @@ const triggerListenerCallback = ({
|
|
|
2623
2623
|
}
|
|
2624
2624
|
});
|
|
2625
2625
|
function useEmojiPicker(props) {
|
|
2626
|
-
const $ = c(17), editor = useEditor()
|
|
2627
|
-
let
|
|
2628
|
-
$[0] !== editor || $[1] !==
|
|
2626
|
+
const $ = c(17), editor = useEditor();
|
|
2627
|
+
let t0;
|
|
2628
|
+
$[0] !== editor || $[1] !== props.matchEmojis ? (t0 = {
|
|
2629
2629
|
input: {
|
|
2630
2630
|
editor,
|
|
2631
|
-
matchEmojis:
|
|
2631
|
+
matchEmojis: props.matchEmojis
|
|
2632
2632
|
}
|
|
2633
|
-
}, $[0] = editor, $[1] =
|
|
2634
|
-
const emojiPickerActor = useActorRef(emojiPickerMachine,
|
|
2635
|
-
let
|
|
2636
|
-
$[3] !== emojiPickerActor ? (
|
|
2633
|
+
}, $[0] = editor, $[1] = props.matchEmojis, $[2] = t0) : t0 = $[2];
|
|
2634
|
+
const emojiPickerActor = useActorRef(emojiPickerMachine, t0), keyword = useSelector(emojiPickerActor, _temp), matches = useSelector(emojiPickerActor, _temp2), selectedIndex = useSelector(emojiPickerActor, _temp3);
|
|
2635
|
+
let t1;
|
|
2636
|
+
$[3] !== emojiPickerActor ? (t1 = () => {
|
|
2637
2637
|
emojiPickerActor.send({
|
|
2638
2638
|
type: "dismiss"
|
|
2639
2639
|
});
|
|
2640
|
-
}, $[3] = emojiPickerActor, $[4] =
|
|
2641
|
-
const onDismiss =
|
|
2642
|
-
let
|
|
2643
|
-
$[5] !== emojiPickerActor ? (
|
|
2640
|
+
}, $[3] = emojiPickerActor, $[4] = t1) : t1 = $[4];
|
|
2641
|
+
const onDismiss = t1;
|
|
2642
|
+
let t2;
|
|
2643
|
+
$[5] !== emojiPickerActor ? (t2 = (index) => {
|
|
2644
2644
|
emojiPickerActor.send({
|
|
2645
2645
|
type: "navigate to",
|
|
2646
2646
|
index
|
|
2647
2647
|
});
|
|
2648
|
-
}, $[5] = emojiPickerActor, $[6] =
|
|
2649
|
-
const onNavigateTo =
|
|
2650
|
-
let
|
|
2651
|
-
$[7] !== editor || $[8] !== emojiPickerActor ? (
|
|
2648
|
+
}, $[5] = emojiPickerActor, $[6] = t2) : t2 = $[6];
|
|
2649
|
+
const onNavigateTo = t2;
|
|
2650
|
+
let t3;
|
|
2651
|
+
$[7] !== editor || $[8] !== emojiPickerActor ? (t3 = () => {
|
|
2652
2652
|
emojiPickerActor.send({
|
|
2653
2653
|
type: "insert selected match"
|
|
2654
2654
|
}), editor.send({
|
|
2655
2655
|
type: "focus"
|
|
2656
2656
|
});
|
|
2657
|
-
}, $[7] = editor, $[8] = emojiPickerActor, $[9] =
|
|
2658
|
-
const onSelect =
|
|
2659
|
-
let
|
|
2660
|
-
return $[10] !== keyword || $[11] !== matches || $[12] !== onDismiss || $[13] !== onNavigateTo || $[14] !== onSelect || $[15] !== selectedIndex ? (
|
|
2657
|
+
}, $[7] = editor, $[8] = emojiPickerActor, $[9] = t3) : t3 = $[9];
|
|
2658
|
+
const onSelect = t3;
|
|
2659
|
+
let t4;
|
|
2660
|
+
return $[10] !== keyword || $[11] !== matches || $[12] !== onDismiss || $[13] !== onNavigateTo || $[14] !== onSelect || $[15] !== selectedIndex ? (t4 = {
|
|
2661
2661
|
keyword,
|
|
2662
2662
|
matches,
|
|
2663
2663
|
selectedIndex,
|
|
2664
2664
|
onDismiss,
|
|
2665
2665
|
onNavigateTo,
|
|
2666
2666
|
onSelect
|
|
2667
|
-
}, $[10] = keyword, $[11] = matches, $[12] = onDismiss, $[13] = onNavigateTo, $[14] = onSelect, $[15] = selectedIndex, $[16] =
|
|
2667
|
+
}, $[10] = keyword, $[11] = matches, $[12] = onDismiss, $[13] = onNavigateTo, $[14] = onSelect, $[15] = selectedIndex, $[16] = t4) : t4 = $[16], t4;
|
|
2668
2668
|
}
|
|
2669
2669
|
function _temp3(snapshot_1) {
|
|
2670
2670
|
return snapshot_1.context.selectedIndex;
|
|
@@ -2673,7 +2673,8 @@ function _temp2(snapshot_0) {
|
|
|
2673
2673
|
return snapshot_0.context.matches;
|
|
2674
2674
|
}
|
|
2675
2675
|
function _temp(snapshot) {
|
|
2676
|
-
|
|
2676
|
+
const rawKeyword = snapshot.context.keyword.startsWith(":") ? snapshot.context.keyword.slice(1) : snapshot.context.keyword;
|
|
2677
|
+
return rawKeyword.endsWith(":") ? rawKeyword.slice(0, -1) : rawKeyword;
|
|
2677
2678
|
}
|
|
2678
2679
|
export {
|
|
2679
2680
|
createMatchEmojis,
|