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