@portabletext/editor 1.16.3 → 1.17.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.
Files changed (33) hide show
  1. package/README.md +134 -118
  2. package/lib/_chunks-cjs/behavior.core.cjs +5 -12
  3. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  4. package/lib/_chunks-cjs/selector.get-text-before.cjs +3 -10
  5. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  6. package/lib/_chunks-cjs/selector.is-selection-collapsed.cjs +1 -4
  7. package/lib/_chunks-cjs/selector.is-selection-collapsed.cjs.map +1 -1
  8. package/lib/_chunks-es/behavior.core.js +5 -12
  9. package/lib/_chunks-es/behavior.core.js.map +1 -1
  10. package/lib/_chunks-es/selector.get-text-before.js +3 -10
  11. package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
  12. package/lib/_chunks-es/selector.is-selection-collapsed.js +1 -4
  13. package/lib/_chunks-es/selector.is-selection-collapsed.js.map +1 -1
  14. package/lib/behaviors/index.cjs +319 -37
  15. package/lib/behaviors/index.cjs.map +1 -1
  16. package/lib/behaviors/index.d.cts +46 -0
  17. package/lib/behaviors/index.d.ts +46 -0
  18. package/lib/behaviors/index.js +321 -38
  19. package/lib/behaviors/index.js.map +1 -1
  20. package/lib/index.cjs +532 -881
  21. package/lib/index.cjs.map +1 -1
  22. package/lib/index.d.cts +2 -0
  23. package/lib/index.d.ts +2 -0
  24. package/lib/index.js +532 -881
  25. package/lib/index.js.map +1 -1
  26. package/lib/selectors/index.cjs +7 -19
  27. package/lib/selectors/index.cjs.map +1 -1
  28. package/lib/selectors/index.js +7 -19
  29. package/lib/selectors/index.js.map +1 -1
  30. package/package.json +3 -3
  31. package/src/behaviors/behavior.emoji-picker.ts +410 -0
  32. package/src/behaviors/index.ts +4 -0
  33. package/src/editor/create-editor.ts +2 -0
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var selector_isSelectionCollapsed = require("../_chunks-cjs/selector.is-selection-collapsed.cjs"), behavior_core = require("../_chunks-cjs/behavior.core.cjs"), types = require("@sanity/types"), selector_getTextBefore = require("../_chunks-cjs/selector.get-text-before.cjs");
3
+ var selector_isSelectionCollapsed = require("../_chunks-cjs/selector.is-selection-collapsed.cjs"), behavior_core = require("../_chunks-cjs/behavior.core.cjs"), xstate = require("xstate"), selector_getTextBefore = require("../_chunks-cjs/selector.get-text-before.cjs"), types = require("@sanity/types");
4
4
  function createCodeEditorBehaviors(config) {
5
5
  return [behavior_core.defineBehavior({
6
6
  on: "key.down",
@@ -8,12 +8,11 @@ function createCodeEditorBehaviors(config) {
8
8
  context,
9
9
  event
10
10
  }) => {
11
- var _a;
12
11
  const isMoveUpShortcut = behavior_core.isHotkey(config.moveBlockUpShortcut, event.keyboardEvent), firstBlock = selector_isSelectionCollapsed.getFirstBlock({
13
12
  context
14
13
  }), selectedBlocks = selector_isSelectionCollapsed.getSelectedBlocks({
15
14
  context
16
- }), blocksAbove = (firstBlock == null ? void 0 : firstBlock.node._key) !== ((_a = selectedBlocks[0]) == null ? void 0 : _a.node._key);
15
+ }), blocksAbove = firstBlock?.node._key !== selectedBlocks[0]?.node._key;
17
16
  return !isMoveUpShortcut || !blocksAbove ? !1 : {
18
17
  paths: selectedBlocks.map((block) => block.path)
19
18
  };
@@ -30,12 +29,11 @@ function createCodeEditorBehaviors(config) {
30
29
  context,
31
30
  event
32
31
  }) => {
33
- var _a;
34
32
  const isMoveDownShortcut = behavior_core.isHotkey(config.moveBlockDownShortcut, event.keyboardEvent), lastBlock = selector_isSelectionCollapsed.getLastBlock({
35
33
  context
36
34
  }), selectedBlocks = selector_isSelectionCollapsed.getSelectedBlocks({
37
35
  context
38
- }), blocksBelow = (lastBlock == null ? void 0 : lastBlock.node._key) !== ((_a = selectedBlocks[selectedBlocks.length - 1]) == null ? void 0 : _a.node._key);
36
+ }), blocksBelow = lastBlock?.node._key !== selectedBlocks[selectedBlocks.length - 1]?.node._key;
39
37
  return !isMoveDownShortcut || !blocksBelow ? !1 : {
40
38
  paths: selectedBlocks.map((block) => block.path).reverse()
41
39
  };
@@ -48,6 +46,304 @@ function createCodeEditorBehaviors(config) {
48
46
  }))]
49
47
  })];
50
48
  }
49
+ const emojiCharRegEx = /^[a-zA-Z-_0-9]{1}$/, incompleteEmojiRegEx = /:([a-zA-Z-_0-9]+)$/, emojiRegEx = /:([a-zA-Z-_0-9]+):$/;
50
+ function createEmojiPickerBehaviors(config) {
51
+ const emojiPickerActor = xstate.createActor(createEmojiPickerMachine());
52
+ return emojiPickerActor.start(), emojiPickerActor.subscribe((state) => {
53
+ config.onMatchesChanged({
54
+ matches: state.context.matches
55
+ }), config.onSelectedIndexChanged({
56
+ selectedIndex: state.context.selectedIndex
57
+ });
58
+ }), [behavior_core.defineBehavior({
59
+ on: "insert.text",
60
+ guard: ({
61
+ context,
62
+ event
63
+ }) => {
64
+ if (event.text !== ":")
65
+ return !1;
66
+ const matches = emojiPickerActor.getSnapshot().context.matches, selectedIndex = emojiPickerActor.getSnapshot().context.selectedIndex, emoji = matches[selectedIndex] ? config.parseMatch({
67
+ match: matches[selectedIndex]
68
+ }) : void 0, focusBlock = selector_isSelectionCollapsed.getFocusTextBlock({
69
+ context
70
+ }), textBefore = selector_getTextBefore.getBlockTextBefore({
71
+ context
72
+ }), emojiKeyword = `${textBefore}:`.match(emojiRegEx)?.[1];
73
+ if (!focusBlock || emojiKeyword === void 0)
74
+ return !1;
75
+ const emojiStringLength = emojiKeyword.length + 2;
76
+ return emoji ? {
77
+ focusBlock,
78
+ emoji,
79
+ emojiStringLength,
80
+ textBeforeLength: textBefore.length + 1
81
+ } : !1;
82
+ },
83
+ actions: [() => [{
84
+ type: "insert.text",
85
+ text: ":"
86
+ }], (_, params) => [{
87
+ type: "effect",
88
+ effect: () => {
89
+ emojiPickerActor.send({
90
+ type: "select"
91
+ });
92
+ }
93
+ }, {
94
+ type: "delete.text",
95
+ anchor: {
96
+ path: params.focusBlock.path,
97
+ offset: params.textBeforeLength - params.emojiStringLength
98
+ },
99
+ focus: {
100
+ path: params.focusBlock.path,
101
+ offset: params.textBeforeLength
102
+ }
103
+ }, {
104
+ type: "insert.text",
105
+ text: params.emoji
106
+ }]]
107
+ }), behavior_core.defineBehavior({
108
+ on: "insert.text",
109
+ guard: ({
110
+ context,
111
+ event
112
+ }) => {
113
+ if (!emojiCharRegEx.test(event.text))
114
+ return {
115
+ emojis: []
116
+ };
117
+ const focusBlock = selector_isSelectionCollapsed.getFocusTextBlock({
118
+ context
119
+ }), emojiKeyword = `${selector_getTextBefore.getBlockTextBefore({
120
+ context
121
+ })}${event.text}`.match(incompleteEmojiRegEx)?.[1];
122
+ return !focusBlock || emojiKeyword === void 0 ? {
123
+ emojis: []
124
+ } : {
125
+ emojis: config.matchEmojis({
126
+ keyword: emojiKeyword
127
+ })
128
+ };
129
+ },
130
+ actions: [(_, params) => [{
131
+ type: "effect",
132
+ effect: () => {
133
+ emojiPickerActor.send({
134
+ type: "emojis found",
135
+ matches: params.emojis
136
+ });
137
+ }
138
+ }]]
139
+ }), behavior_core.defineBehavior({
140
+ on: "key.down",
141
+ guard: ({
142
+ context,
143
+ event
144
+ }) => {
145
+ const isShift = behavior_core.isHotkey("Shift", event.keyboardEvent), isColon = event.keyboardEvent.key === ":", isEmojiChar = emojiCharRegEx.test(event.keyboardEvent.key);
146
+ if (isShift || isColon || isEmojiChar)
147
+ return !1;
148
+ const isArrowDown = behavior_core.isHotkey("ArrowDown", event.keyboardEvent), isArrowUp = behavior_core.isHotkey("ArrowUp", event.keyboardEvent), isEnter = behavior_core.isHotkey("Enter", event.keyboardEvent), isTab = behavior_core.isHotkey("Tab", event.keyboardEvent);
149
+ if (isEnter || isTab) {
150
+ const matches = emojiPickerActor.getSnapshot().context.matches, selectedIndex = emojiPickerActor.getSnapshot().context.selectedIndex, emoji = matches[selectedIndex] ? config.parseMatch({
151
+ match: matches[selectedIndex]
152
+ }) : void 0;
153
+ if (!emoji)
154
+ return !1;
155
+ const focusBlock = selector_isSelectionCollapsed.getFocusTextBlock({
156
+ context
157
+ }), textBefore = selector_getTextBefore.getBlockTextBefore({
158
+ context
159
+ }), emojiKeyword = textBefore.match(incompleteEmojiRegEx)?.[1];
160
+ if (!focusBlock || emojiKeyword === void 0)
161
+ return !1;
162
+ const emojiStringLength = emojiKeyword.length + 1;
163
+ return emoji ? {
164
+ action: "select",
165
+ focusBlock,
166
+ emoji,
167
+ emojiStringLength,
168
+ textBeforeLength: textBefore.length
169
+ } : !1;
170
+ }
171
+ return isArrowDown ? {
172
+ action: "navigate down"
173
+ } : isArrowUp ? {
174
+ action: "navigate up"
175
+ } : {
176
+ action: "reset"
177
+ };
178
+ },
179
+ actions: [(_, params) => params.action === "select" ? [{
180
+ type: "effect",
181
+ effect: () => {
182
+ emojiPickerActor.send({
183
+ type: "select"
184
+ });
185
+ }
186
+ }, {
187
+ type: "delete.text",
188
+ anchor: {
189
+ path: params.focusBlock.path,
190
+ offset: params.textBeforeLength - params.emojiStringLength
191
+ },
192
+ focus: {
193
+ path: params.focusBlock.path,
194
+ offset: params.textBeforeLength
195
+ }
196
+ }, {
197
+ type: "insert.text",
198
+ text: params.emoji
199
+ }] : params.action === "navigate up" ? [
200
+ // If we are navigating then we want to hijack the key event and
201
+ // turn it into a noop.
202
+ {
203
+ type: "noop"
204
+ },
205
+ {
206
+ type: "effect",
207
+ effect: () => {
208
+ emojiPickerActor.send({
209
+ type: "navigate up"
210
+ });
211
+ }
212
+ }
213
+ ] : params.action === "navigate down" ? [
214
+ // If we are navigating then we want to hijack the key event and
215
+ // turn it into a noop.
216
+ {
217
+ type: "noop"
218
+ },
219
+ {
220
+ type: "effect",
221
+ effect: () => {
222
+ emojiPickerActor.send({
223
+ type: "navigate down"
224
+ });
225
+ }
226
+ }
227
+ ] : [{
228
+ type: "effect",
229
+ effect: () => {
230
+ emojiPickerActor.send({
231
+ type: "reset"
232
+ });
233
+ }
234
+ }]]
235
+ }), behavior_core.defineBehavior({
236
+ on: "delete.backward",
237
+ guard: ({
238
+ context,
239
+ event
240
+ }) => {
241
+ if (event.unit !== "character")
242
+ return !1;
243
+ const focusBlock = selector_isSelectionCollapsed.getFocusTextBlock({
244
+ context
245
+ }), textBefore = selector_getTextBefore.getBlockTextBefore({
246
+ context
247
+ }), emojiKeyword = textBefore.slice(0, textBefore.length - 1).match(incompleteEmojiRegEx)?.[1];
248
+ return !focusBlock || emojiKeyword === void 0 ? {
249
+ emojis: [],
250
+ event
251
+ } : {
252
+ emojis: config.matchEmojis({
253
+ keyword: emojiKeyword
254
+ })
255
+ };
256
+ },
257
+ actions: [(_, params) => [{
258
+ type: "effect",
259
+ effect: () => {
260
+ emojiPickerActor.send({
261
+ type: "emojis found",
262
+ matches: params.emojis
263
+ });
264
+ }
265
+ }]]
266
+ })];
267
+ }
268
+ function createEmojiPickerMachine() {
269
+ return xstate.setup({
270
+ types: {
271
+ context: {},
272
+ events: {}
273
+ },
274
+ actions: {
275
+ "assign matches": xstate.assign({
276
+ matches: ({
277
+ event
278
+ }) => (xstate.assertEvent(event, "emojis found"), event.matches)
279
+ }),
280
+ "reset matches": xstate.assign({
281
+ matches: []
282
+ }),
283
+ "reset selected index": xstate.assign({
284
+ selectedIndex: 0
285
+ }),
286
+ "increment selected index": xstate.assign({
287
+ selectedIndex: ({
288
+ context
289
+ }) => context.selectedIndex === context.matches.length - 1 ? 0 : context.selectedIndex + 1
290
+ }),
291
+ "decrement selected index": xstate.assign({
292
+ selectedIndex: ({
293
+ context
294
+ }) => context.selectedIndex === 0 ? context.matches.length - 1 : context.selectedIndex - 1
295
+ })
296
+ },
297
+ guards: {
298
+ "no matches": ({
299
+ context
300
+ }) => context.matches.length === 0
301
+ }
302
+ }).createMachine({
303
+ id: "emoji picker",
304
+ context: {
305
+ matches: [],
306
+ selectedIndex: 0
307
+ },
308
+ initial: "idle",
309
+ states: {
310
+ idle: {
311
+ on: {
312
+ "emojis found": {
313
+ actions: "assign matches",
314
+ target: "showing matches"
315
+ }
316
+ }
317
+ },
318
+ "showing matches": {
319
+ always: {
320
+ guard: "no matches",
321
+ target: "idle"
322
+ },
323
+ exit: ["reset selected index"],
324
+ on: {
325
+ "emojis found": {
326
+ actions: "assign matches"
327
+ },
328
+ "navigate down": {
329
+ actions: "increment selected index"
330
+ },
331
+ "navigate up": {
332
+ actions: "decrement selected index"
333
+ },
334
+ reset: {
335
+ target: "idle",
336
+ actions: ["reset selected index", "reset matches"]
337
+ },
338
+ select: {
339
+ target: "idle",
340
+ actions: ["reset selected index", "reset matches"]
341
+ }
342
+ }
343
+ }
344
+ }
345
+ });
346
+ }
51
347
  function createLinkBehaviors(config) {
52
348
  const pasteLinkOnSelection = behavior_core.defineBehavior({
53
349
  on: "paste",
@@ -55,10 +351,9 @@ function createLinkBehaviors(config) {
55
351
  context,
56
352
  event
57
353
  }) => {
58
- var _a;
59
354
  const selectionCollapsed = selector_isSelectionCollapsed.isSelectionCollapsed({
60
355
  context
61
- }), text = event.data.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? (_a = config.linkAnnotation) == null ? void 0 : _a.call(config, {
356
+ }), text = event.data.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.linkAnnotation?.({
62
357
  url,
63
358
  schema: context.schema
64
359
  }) : void 0;
@@ -78,7 +373,6 @@ function createLinkBehaviors(config) {
78
373
  context,
79
374
  event
80
375
  }) => {
81
- var _a;
82
376
  const focusSpan = selector_isSelectionCollapsed.getFocusSpan({
83
377
  context
84
378
  }), selectionCollapsed = selector_isSelectionCollapsed.isSelectionCollapsed({
@@ -86,7 +380,7 @@ function createLinkBehaviors(config) {
86
380
  });
87
381
  if (!focusSpan || !selectionCollapsed)
88
382
  return !1;
89
- const text = event.data.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? (_a = config.linkAnnotation) == null ? void 0 : _a.call(config, {
383
+ const text = event.data.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.linkAnnotation?.({
90
384
  url,
91
385
  schema: context.schema
92
386
  }) : void 0;
@@ -111,18 +405,10 @@ function looksLikeUrl(text) {
111
405
  let looksLikeUrl2 = !1;
112
406
  try {
113
407
  new URL(text), looksLikeUrl2 = !0;
114
- } catch (e) {
408
+ } catch {
115
409
  }
116
410
  return looksLikeUrl2;
117
411
  }
118
- var __defProp = Object.defineProperty, __getOwnPropSymbols = Object.getOwnPropertySymbols, __hasOwnProp = Object.prototype.hasOwnProperty, __propIsEnum = Object.prototype.propertyIsEnumerable, __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues = (a, b) => {
119
- for (var prop in b || (b = {}))
120
- __hasOwnProp.call(b, prop) && __defNormalProp(a, prop, b[prop]);
121
- if (__getOwnPropSymbols)
122
- for (var prop of __getOwnPropSymbols(b))
123
- __propIsEnum.call(b, prop) && __defNormalProp(a, prop, b[prop]);
124
- return a;
125
- };
126
412
  function createMarkdownBehaviors(config) {
127
413
  const automaticBlockquoteOnSpace = behavior_core.defineBehavior({
128
414
  on: "insert.text",
@@ -130,7 +416,6 @@ function createMarkdownBehaviors(config) {
130
416
  context,
131
417
  event
132
418
  }) => {
133
- var _a, _b, _c;
134
419
  if (event.text !== " ")
135
420
  return !1;
136
421
  const selectionCollapsed = selector_isSelectionCollapsed.isSelectionCollapsed({
@@ -150,12 +435,12 @@ function createMarkdownBehaviors(config) {
150
435
  }, "children", {
151
436
  _key: focusSpan.node._key
152
437
  }],
153
- offset: (_b = (_a = context.selection) == null ? void 0 : _a.focus.offset) != null ? _b : 0
438
+ offset: context.selection?.focus.offset ?? 0
154
439
  }
155
440
  });
156
441
  if (!blockOffset)
157
442
  return !1;
158
- const blockText = behavior_core.getTextBlockText(focusTextBlock.node), caretAtTheEndOfQuote = blockOffset.offset === 1, looksLikeMarkdownQuote = /^>/.test(blockText), blockquoteStyle = (_c = config.blockquoteStyle) == null ? void 0 : _c.call(config, context);
443
+ const blockText = behavior_core.getTextBlockText(focusTextBlock.node), caretAtTheEndOfQuote = blockOffset.offset === 1, looksLikeMarkdownQuote = /^>/.test(blockText), blockquoteStyle = config.blockquoteStyle?.(context);
159
444
  return caretAtTheEndOfQuote && looksLikeMarkdownQuote && blockquoteStyle !== void 0 ? {
160
445
  focusTextBlock,
161
446
  style: blockquoteStyle
@@ -192,11 +477,10 @@ function createMarkdownBehaviors(config) {
192
477
  context,
193
478
  event
194
479
  }) => {
195
- var _a;
196
480
  const hrCharacter = event.text === "-" ? "-" : event.text === "*" ? "*" : event.text === "_" ? "_" : void 0;
197
481
  if (hrCharacter === void 0)
198
482
  return !1;
199
- const hrObject = (_a = config.horizontalRuleObject) == null ? void 0 : _a.call(config, context), focusBlock = selector_isSelectionCollapsed.getFocusTextBlock({
483
+ const hrObject = config.horizontalRuleObject?.(context), focusBlock = selector_isSelectionCollapsed.getFocusTextBlock({
200
484
  context
201
485
  }), selectionCollapsed = selector_isSelectionCollapsed.isSelectionCollapsed({
202
486
  context
@@ -234,17 +518,17 @@ function createMarkdownBehaviors(config) {
234
518
  type: "insert.block object",
235
519
  placement: "before",
236
520
  blockObject: hrObject
237
- }, __spreadValues({
238
- type: "delete.text"
239
- }, hrBlockOffsets)]]
521
+ }, {
522
+ type: "delete.text",
523
+ ...hrBlockOffsets
524
+ }]]
240
525
  }), automaticHrOnPaste = behavior_core.defineBehavior({
241
526
  on: "paste",
242
527
  guard: ({
243
528
  context,
244
529
  event
245
530
  }) => {
246
- var _a, _b;
247
- const text = event.data.getData("text/plain"), hrRegExp = /^(---)$|(___)$|(\*\*\*)$/gm, hrCharacters = (_a = text.match(hrRegExp)) == null ? void 0 : _a[0], hrObject = (_b = config.horizontalRuleObject) == null ? void 0 : _b.call(config, context), focusBlock = selector_isSelectionCollapsed.getFocusBlock({
531
+ const text = event.data.getData("text/plain"), hrRegExp = /^(---)$|(___)$|(\*\*\*)$/gm, hrCharacters = text.match(hrRegExp)?.[0], hrObject = config.horizontalRuleObject?.(context), focusBlock = selector_isSelectionCollapsed.getFocusBlock({
248
532
  context
249
533
  });
250
534
  return !hrCharacters || !hrObject || !focusBlock ? !1 : {
@@ -285,7 +569,6 @@ function createMarkdownBehaviors(config) {
285
569
  context,
286
570
  event
287
571
  }) => {
288
- var _a, _b, _c;
289
572
  if (event.text !== " ")
290
573
  return !1;
291
574
  const selectionCollapsed = selector_isSelectionCollapsed.isSelectionCollapsed({
@@ -305,7 +588,7 @@ function createMarkdownBehaviors(config) {
305
588
  }, "children", {
306
589
  _key: focusSpan.node._key
307
590
  }],
308
- offset: (_b = (_a = context.selection) == null ? void 0 : _a.focus.offset) != null ? _b : 0
591
+ offset: context.selection?.focus.offset ?? 0
309
592
  }
310
593
  });
311
594
  if (!blockOffset)
@@ -313,7 +596,7 @@ function createMarkdownBehaviors(config) {
313
596
  const blockText = behavior_core.getTextBlockText(focusTextBlock.node), markdownHeadingSearch = /^#+/.exec(blockText), level = markdownHeadingSearch ? markdownHeadingSearch[0].length : void 0;
314
597
  if (blockOffset.offset !== level)
315
598
  return !1;
316
- const style = level !== void 0 ? (_c = config.headingStyle) == null ? void 0 : _c.call(config, {
599
+ const style = level !== void 0 ? config.headingStyle?.({
317
600
  schema: context.schema,
318
601
  level
319
602
  }) : void 0;
@@ -353,7 +636,6 @@ function createMarkdownBehaviors(config) {
353
636
  guard: ({
354
637
  context
355
638
  }) => {
356
- var _a, _b;
357
639
  const selectionCollapsed = selector_isSelectionCollapsed.isSelectionCollapsed({
358
640
  context
359
641
  }), focusTextBlock = selector_isSelectionCollapsed.getFocusTextBlock({
@@ -363,7 +645,7 @@ function createMarkdownBehaviors(config) {
363
645
  });
364
646
  if (!selectionCollapsed || !focusTextBlock || !focusSpan)
365
647
  return !1;
366
- const atTheBeginningOfBLock = focusTextBlock.node.children[0]._key === focusSpan.node._key && ((_a = context.selection) == null ? void 0 : _a.focus.offset) === 0, defaultStyle = (_b = config.defaultStyle) == null ? void 0 : _b.call(config, context);
648
+ const atTheBeginningOfBLock = focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection?.focus.offset === 0, defaultStyle = config.defaultStyle?.(context);
367
649
  return atTheBeginningOfBLock && defaultStyle && focusTextBlock.node.style !== defaultStyle ? {
368
650
  defaultStyle,
369
651
  focusTextBlock
@@ -383,7 +665,6 @@ function createMarkdownBehaviors(config) {
383
665
  context,
384
666
  event
385
667
  }) => {
386
- var _a, _b, _c, _d, _e;
387
668
  if (event.text !== " ")
388
669
  return !1;
389
670
  const selectionCollapsed = selector_isSelectionCollapsed.isSelectionCollapsed({
@@ -403,12 +684,12 @@ function createMarkdownBehaviors(config) {
403
684
  }, "children", {
404
685
  _key: focusSpan.node._key
405
686
  }],
406
- offset: (_b = (_a = context.selection) == null ? void 0 : _a.focus.offset) != null ? _b : 0
687
+ offset: context.selection?.focus.offset ?? 0
407
688
  }
408
689
  });
409
690
  if (!blockOffset)
410
691
  return !1;
411
- const blockText = behavior_core.getTextBlockText(focusTextBlock.node), defaultStyle = (_c = config.defaultStyle) == null ? void 0 : _c.call(config, context), looksLikeUnorderedList = /^(-|\*)/.test(blockText), unorderedListStyle = (_d = config.unorderedListStyle) == null ? void 0 : _d.call(config, context), caretAtTheEndOfUnorderedList = blockOffset.offset === 1;
692
+ const blockText = behavior_core.getTextBlockText(focusTextBlock.node), defaultStyle = config.defaultStyle?.(context), looksLikeUnorderedList = /^(-|\*)/.test(blockText), unorderedListStyle = config.unorderedListStyle?.(context), caretAtTheEndOfUnorderedList = blockOffset.offset === 1;
412
693
  if (defaultStyle && caretAtTheEndOfUnorderedList && looksLikeUnorderedList && unorderedListStyle !== void 0)
413
694
  return {
414
695
  focusTextBlock,
@@ -416,7 +697,7 @@ function createMarkdownBehaviors(config) {
416
697
  listItemLength: 1,
417
698
  style: defaultStyle
418
699
  };
419
- const looksLikeOrderedList = /^1\./.test(blockText), orderedListStyle = (_e = config.orderedListStyle) == null ? void 0 : _e.call(config, context), caretAtTheEndOfOrderedList = blockOffset.offset === 2;
700
+ const looksLikeOrderedList = /^1\./.test(blockText), orderedListStyle = config.orderedListStyle?.(context), caretAtTheEndOfOrderedList = blockOffset.offset === 2;
420
701
  return defaultStyle && caretAtTheEndOfOrderedList && looksLikeOrderedList && orderedListStyle !== void 0 ? {
421
702
  focusTextBlock,
422
703
  listItem: orderedListStyle,
@@ -455,6 +736,7 @@ exports.coreBehavior = behavior_core.coreBehavior;
455
736
  exports.coreBehaviors = behavior_core.coreBehaviors;
456
737
  exports.defineBehavior = behavior_core.defineBehavior;
457
738
  exports.createCodeEditorBehaviors = createCodeEditorBehaviors;
739
+ exports.createEmojiPickerBehaviors = createEmojiPickerBehaviors;
458
740
  exports.createLinkBehaviors = createLinkBehaviors;
459
741
  exports.createMarkdownBehaviors = createMarkdownBehaviors;
460
742
  //# sourceMappingURL=index.cjs.map