@portabletext/plugin-emoji-picker 0.0.15 → 1.0.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.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,7 +77,9 @@ export declare type EmojiMatch =
62
77
  /**
63
78
  * @beta
64
79
  */
65
- export declare type EmojiPicker<TEmojiMatch = EmojiMatch> = {
80
+ export declare type EmojiPicker<
81
+ TEmojiMatch extends BaseEmojiMatch = BaseEmojiMatch,
82
+ > = {
66
83
  /**
67
84
  * The matched keyword, including colons.
68
85
  *
@@ -155,7 +172,9 @@ export declare type EmojiPicker<TEmojiMatch = EmojiMatch> = {
155
172
  /**
156
173
  * @beta
157
174
  */
158
- export declare type EmojiPickerProps<TEmojiMatch = EmojiMatch> = {
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<TEmojiMatch = EmojiMatch> = (query: {
168
- keyword: string
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<TEmojiMatch = EmojiMatch>(
206
- props: EmojiPickerProps<TEmojiMatch>,
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,7 +77,9 @@ export declare type EmojiMatch =
62
77
  /**
63
78
  * @beta
64
79
  */
65
- export declare type EmojiPicker<TEmojiMatch = EmojiMatch> = {
80
+ export declare type EmojiPicker<
81
+ TEmojiMatch extends BaseEmojiMatch = BaseEmojiMatch,
82
+ > = {
66
83
  /**
67
84
  * The matched keyword, including colons.
68
85
  *
@@ -155,7 +172,9 @@ export declare type EmojiPicker<TEmojiMatch = EmojiMatch> = {
155
172
  /**
156
173
  * @beta
157
174
  */
158
- export declare type EmojiPickerProps<TEmojiMatch = EmojiMatch> = {
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<TEmojiMatch = EmojiMatch> = (query: {
168
- keyword: string
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<TEmojiMatch = EmojiMatch>(
206
- props: EmojiPickerProps<TEmojiMatch>,
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
@@ -2039,7 +2039,7 @@ function createKeywordFoundEvent(payload) {
2039
2039
  ...payload
2040
2040
  };
2041
2041
  }
2042
- const colonListenerCallback = ({
2042
+ const triggerListenerCallback = ({
2043
2043
  sendBack,
2044
2044
  input
2045
2045
  }) => {
@@ -2062,10 +2062,7 @@ const colonListenerCallback = ({
2062
2062
  actions: [({
2063
2063
  event
2064
2064
  }) => [effect(() => {
2065
- sendBack({
2066
- ...event,
2067
- type: "colon inserted"
2068
- });
2065
+ sendBack(event);
2069
2066
  })]]
2070
2067
  })
2071
2068
  }), input.editor.registerBehavior({
@@ -2074,10 +2071,7 @@ const colonListenerCallback = ({
2074
2071
  actions: [({
2075
2072
  event
2076
2073
  }) => [effect(() => {
2077
- sendBack({
2078
- ...event,
2079
- type: "colon inserted"
2080
- });
2074
+ sendBack(event);
2081
2075
  })]]
2082
2076
  })
2083
2077
  })];
@@ -2135,65 +2129,28 @@ const colonListenerCallback = ({
2135
2129
  };
2136
2130
  }, emojiInsertListener = ({
2137
2131
  sendBack,
2138
- input,
2139
- receive
2140
- }) => {
2141
- let context = input.context;
2142
- receive((event) => {
2143
- context = event.context;
2144
- });
2145
- const unregisterBehaviors = [input.context.editor.registerBehavior({
2146
- behavior: defineBehavior({
2147
- on: "custom.insert emoji",
2148
- actions: [({
2149
- event
2150
- }) => [effect(() => {
2151
- sendBack({
2152
- type: "dismiss"
2153
- });
2154
- }), raise({
2155
- type: "delete.text",
2156
- at: {
2157
- anchor: event.anchor,
2158
- focus: event.focus
2159
- }
2160
- }), raise({
2161
- type: "insert.text",
2162
- text: event.emoji
2163
- })]]
2164
- })
2165
- }), input.context.editor.registerBehavior({
2166
- behavior: defineBehavior({
2167
- on: "insert.text",
2168
- guard: ({
2169
- event
2170
- }) => {
2171
- if (event.text !== ":")
2172
- return !1;
2173
- const anchor = context.keywordAnchor?.blockOffset, focus = context.keywordFocus, match = context.matches[context.selectedIndex];
2174
- return match && match.type === "exact" && anchor && focus ? {
2175
- anchor,
2176
- focus,
2177
- emoji: match.emoji
2178
- } : !1;
2179
- },
2180
- actions: [(_, {
2181
- anchor,
2182
- focus,
2183
- emoji
2184
- }) => [raise({
2185
- type: "custom.insert emoji",
2186
- emoji,
2187
- anchor,
2188
- focus
2189
- })]]
2190
- })
2191
- })];
2192
- return () => {
2193
- for (const unregister of unregisterBehaviors)
2194
- unregister();
2195
- };
2196
- }, submitListenerCallback = ({
2132
+ input
2133
+ }) => input.context.editor.registerBehavior({
2134
+ behavior: defineBehavior({
2135
+ on: "custom.insert emoji",
2136
+ actions: [({
2137
+ event
2138
+ }) => [effect(() => {
2139
+ sendBack({
2140
+ type: "dismiss"
2141
+ });
2142
+ }), raise({
2143
+ type: "delete.text",
2144
+ at: {
2145
+ anchor: event.anchor,
2146
+ focus: event.focus
2147
+ }
2148
+ }), raise({
2149
+ type: "insert.text",
2150
+ text: event.emoji
2151
+ })]]
2152
+ })
2153
+ }), submitListenerCallback = ({
2197
2154
  sendBack,
2198
2155
  input,
2199
2156
  receive
@@ -2240,6 +2197,19 @@ const colonListenerCallback = ({
2240
2197
  });
2241
2198
  })]]
2242
2199
  })
2200
+ }), input.context.editor.registerBehavior({
2201
+ behavior: defineInputRuleBehavior({
2202
+ rules: [keywordRule]
2203
+ })
2204
+ }), input.context.editor.registerBehavior({
2205
+ behavior: defineBehavior({
2206
+ on: "custom.keyword found",
2207
+ actions: [({
2208
+ event
2209
+ }) => [effect(() => {
2210
+ sendBack(event);
2211
+ })]]
2212
+ })
2243
2213
  })];
2244
2214
  return () => {
2245
2215
  for (const unregister of unregisterBehaviors)
@@ -2332,7 +2302,7 @@ const colonListenerCallback = ({
2332
2302
  "emoji insert listener": fromCallback(emojiInsertListener),
2333
2303
  "submit listener": fromCallback(submitListenerCallback),
2334
2304
  "arrow listener": fromCallback(arrowListenerCallback),
2335
- "colon listener": fromCallback(colonListenerCallback),
2305
+ "trigger listener": fromCallback(triggerListenerCallback),
2336
2306
  "escape listener": fromCallback(escapeListenerCallback),
2337
2307
  "selection listener": fromCallback(selectionListenerCallback),
2338
2308
  "text change listener": fromCallback(textChangeListener)
@@ -2342,19 +2312,19 @@ const colonListenerCallback = ({
2342
2312
  keyword: ({
2343
2313
  context,
2344
2314
  event
2345
- }) => event.type !== "colon inserted" && event.type !== "custom.keyword found" ? context.keyword : event.keyword
2315
+ }) => event.type !== "custom.trigger found" && event.type !== "custom.partial keyword found" && event.type !== "custom.keyword found" ? context.keyword : event.keyword
2346
2316
  }),
2347
2317
  "set keyword anchor": assign({
2348
2318
  keywordAnchor: ({
2349
2319
  context,
2350
2320
  event
2351
- }) => event.type !== "colon inserted" && event.type !== "custom.keyword found" ? context.keywordAnchor : event.keywordAnchor
2321
+ }) => event.type !== "custom.trigger found" && event.type !== "custom.partial keyword found" && event.type !== "custom.keyword found" ? context.keywordAnchor : event.keywordAnchor
2352
2322
  }),
2353
2323
  "set keyword focus": assign({
2354
2324
  keywordFocus: ({
2355
2325
  context,
2356
2326
  event
2357
- }) => event.type !== "colon inserted" && event.type !== "custom.keyword found" ? context.keywordFocus : event.keywordFocus
2327
+ }) => event.type !== "custom.trigger found" && event.type !== "custom.partial keyword found" && event.type !== "custom.keyword found" ? context.keywordFocus : event.keywordFocus
2358
2328
  }),
2359
2329
  "update keyword focus": assign({
2360
2330
  keywordFocus: ({
@@ -2430,10 +2400,11 @@ const colonListenerCallback = ({
2430
2400
  context
2431
2401
  })),
2432
2402
  "insert selected match": ({
2433
- context
2403
+ context,
2404
+ event
2434
2405
  }) => {
2435
2406
  const match = context.matches[context.selectedIndex];
2436
- !match || !context.keywordAnchor || !context.keywordFocus || context.editor.send({
2407
+ !match || !context.keywordAnchor || !context.keywordFocus || event.type === "custom.keyword found" && match.type !== "exact" || context.editor.send({
2437
2408
  type: "custom.insert emoji",
2438
2409
  emoji: match.emoji,
2439
2410
  anchor: context.keywordAnchor.blockOffset,
@@ -2526,7 +2497,7 @@ const colonListenerCallback = ({
2526
2497
  idle: {
2527
2498
  entry: ["reset"],
2528
2499
  invoke: {
2529
- src: "colon listener",
2500
+ src: "trigger listener",
2530
2501
  input: ({
2531
2502
  context
2532
2503
  }) => ({
@@ -2534,12 +2505,18 @@ const colonListenerCallback = ({
2534
2505
  })
2535
2506
  },
2536
2507
  on: {
2537
- "colon inserted": {
2508
+ "custom.trigger found": {
2509
+ target: "searching",
2510
+ actions: ["set keyword anchor", "set keyword focus", "init keyword"]
2511
+ },
2512
+ "custom.partial keyword found": {
2538
2513
  target: "searching",
2539
2514
  actions: ["set keyword anchor", "set keyword focus", "init keyword"]
2540
2515
  },
2541
2516
  "custom.keyword found": {
2542
- actions: ["set keyword anchor", "set keyword focus", "init keyword", "update matches", "insert selected match"]
2517
+ actions: ["set keyword anchor", "set keyword focus", "init keyword", "update matches", "insert selected match"],
2518
+ target: "idle",
2519
+ reenter: !0
2543
2520
  }
2544
2521
  }
2545
2522
  },
@@ -2575,6 +2552,9 @@ const colonListenerCallback = ({
2575
2552
  })
2576
2553
  }],
2577
2554
  on: {
2555
+ "custom.keyword found": {
2556
+ actions: ["set keyword anchor", "set keyword focus", "init keyword", "update matches", "insert selected match"]
2557
+ },
2578
2558
  "insert.text": [{
2579
2559
  guard: "unexpected text insertion",
2580
2560
  target: "idle"
@@ -2594,7 +2574,7 @@ const colonListenerCallback = ({
2594
2574
  guard: "selection moved unexpectedly",
2595
2575
  target: "idle"
2596
2576
  }, {
2597
- actions: ["update keyword", "update matches", "reset selected index", "update emoji insert listener context", "update submit listener context"]
2577
+ actions: ["update keyword", "update matches", "reset selected index", "update submit listener context"]
2598
2578
  }]
2599
2579
  },
2600
2580
  always: [{
@@ -2625,13 +2605,13 @@ const colonListenerCallback = ({
2625
2605
  }],
2626
2606
  on: {
2627
2607
  "navigate down": {
2628
- actions: ["increment selected index", "update emoji insert listener context", "update submit listener context"]
2608
+ actions: ["increment selected index", "update submit listener context"]
2629
2609
  },
2630
2610
  "navigate up": {
2631
- actions: ["decrement selected index", "update emoji insert listener context", "update submit listener context"]
2611
+ actions: ["decrement selected index", "update submit listener context"]
2632
2612
  },
2633
2613
  "navigate to": {
2634
- actions: ["set selected index", "update emoji insert listener context", "update submit listener context"]
2614
+ actions: ["set selected index", "update submit listener context"]
2635
2615
  },
2636
2616
  "insert selected match": {
2637
2617
  actions: ["insert selected match"]
@@ -2643,48 +2623,48 @@ const colonListenerCallback = ({
2643
2623
  }
2644
2624
  });
2645
2625
  function useEmojiPicker(props) {
2646
- const $ = c(17), editor = useEditor(), t0 = props.matchEmojis;
2647
- let t1;
2648
- $[0] !== editor || $[1] !== t0 ? (t1 = {
2626
+ const $ = c(17), editor = useEditor();
2627
+ let t0;
2628
+ $[0] !== editor || $[1] !== props.matchEmojis ? (t0 = {
2649
2629
  input: {
2650
2630
  editor,
2651
- matchEmojis: t0
2631
+ matchEmojis: props.matchEmojis
2652
2632
  }
2653
- }, $[0] = editor, $[1] = t0, $[2] = t1) : t1 = $[2];
2654
- const emojiPickerActor = useActorRef(emojiPickerMachine, t1), keyword = useSelector(emojiPickerActor, _temp), matches = useSelector(emojiPickerActor, _temp2), selectedIndex = useSelector(emojiPickerActor, _temp3);
2655
- let t2;
2656
- $[3] !== emojiPickerActor ? (t2 = () => {
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 = () => {
2657
2637
  emojiPickerActor.send({
2658
2638
  type: "dismiss"
2659
2639
  });
2660
- }, $[3] = emojiPickerActor, $[4] = t2) : t2 = $[4];
2661
- const onDismiss = t2;
2662
- let t3;
2663
- $[5] !== emojiPickerActor ? (t3 = (index) => {
2640
+ }, $[3] = emojiPickerActor, $[4] = t1) : t1 = $[4];
2641
+ const onDismiss = t1;
2642
+ let t2;
2643
+ $[5] !== emojiPickerActor ? (t2 = (index) => {
2664
2644
  emojiPickerActor.send({
2665
2645
  type: "navigate to",
2666
2646
  index
2667
2647
  });
2668
- }, $[5] = emojiPickerActor, $[6] = t3) : t3 = $[6];
2669
- const onNavigateTo = t3;
2670
- let t4;
2671
- $[7] !== editor || $[8] !== emojiPickerActor ? (t4 = () => {
2648
+ }, $[5] = emojiPickerActor, $[6] = t2) : t2 = $[6];
2649
+ const onNavigateTo = t2;
2650
+ let t3;
2651
+ $[7] !== editor || $[8] !== emojiPickerActor ? (t3 = () => {
2672
2652
  emojiPickerActor.send({
2673
2653
  type: "insert selected match"
2674
2654
  }), editor.send({
2675
2655
  type: "focus"
2676
2656
  });
2677
- }, $[7] = editor, $[8] = emojiPickerActor, $[9] = t4) : t4 = $[9];
2678
- const onSelect = t4;
2679
- let t5;
2680
- return $[10] !== keyword || $[11] !== matches || $[12] !== onDismiss || $[13] !== onNavigateTo || $[14] !== onSelect || $[15] !== selectedIndex ? (t5 = {
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 = {
2681
2661
  keyword,
2682
2662
  matches,
2683
2663
  selectedIndex,
2684
2664
  onDismiss,
2685
2665
  onNavigateTo,
2686
2666
  onSelect
2687
- }, $[10] = keyword, $[11] = matches, $[12] = onDismiss, $[13] = onNavigateTo, $[14] = onSelect, $[15] = selectedIndex, $[16] = t5) : t5 = $[16], t5;
2667
+ }, $[10] = keyword, $[11] = matches, $[12] = onDismiss, $[13] = onNavigateTo, $[14] = onSelect, $[15] = selectedIndex, $[16] = t4) : t4 = $[16], t4;
2688
2668
  }
2689
2669
  function _temp3(snapshot_1) {
2690
2670
  return snapshot_1.context.selectedIndex;