@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.
- package/README.md +134 -118
- 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 +319 -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 +321 -38
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +532 -881
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +2 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +532 -881
- 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 +3 -3
- package/src/behaviors/behavior.emoji-picker.ts +410 -0
- package/src/behaviors/index.ts +4 -0
- package/src/editor/create-editor.ts +2 -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,304 @@ 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 (event.text !== ":")
|
|
68
|
+
return !1;
|
|
69
|
+
const matches = emojiPickerActor.getSnapshot().context.matches, selectedIndex = emojiPickerActor.getSnapshot().context.selectedIndex, emoji = matches[selectedIndex] ? config.parseMatch({
|
|
70
|
+
match: matches[selectedIndex]
|
|
71
|
+
}) : void 0, focusBlock = getFocusTextBlock({
|
|
72
|
+
context
|
|
73
|
+
}), textBefore = getBlockTextBefore({
|
|
74
|
+
context
|
|
75
|
+
}), emojiKeyword = `${textBefore}:`.match(emojiRegEx)?.[1];
|
|
76
|
+
if (!focusBlock || emojiKeyword === void 0)
|
|
77
|
+
return !1;
|
|
78
|
+
const emojiStringLength = emojiKeyword.length + 2;
|
|
79
|
+
return emoji ? {
|
|
80
|
+
focusBlock,
|
|
81
|
+
emoji,
|
|
82
|
+
emojiStringLength,
|
|
83
|
+
textBeforeLength: textBefore.length + 1
|
|
84
|
+
} : !1;
|
|
85
|
+
},
|
|
86
|
+
actions: [() => [{
|
|
87
|
+
type: "insert.text",
|
|
88
|
+
text: ":"
|
|
89
|
+
}], (_, params) => [{
|
|
90
|
+
type: "effect",
|
|
91
|
+
effect: () => {
|
|
92
|
+
emojiPickerActor.send({
|
|
93
|
+
type: "select"
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}, {
|
|
97
|
+
type: "delete.text",
|
|
98
|
+
anchor: {
|
|
99
|
+
path: params.focusBlock.path,
|
|
100
|
+
offset: params.textBeforeLength - params.emojiStringLength
|
|
101
|
+
},
|
|
102
|
+
focus: {
|
|
103
|
+
path: params.focusBlock.path,
|
|
104
|
+
offset: params.textBeforeLength
|
|
105
|
+
}
|
|
106
|
+
}, {
|
|
107
|
+
type: "insert.text",
|
|
108
|
+
text: params.emoji
|
|
109
|
+
}]]
|
|
110
|
+
}), defineBehavior({
|
|
111
|
+
on: "insert.text",
|
|
112
|
+
guard: ({
|
|
113
|
+
context,
|
|
114
|
+
event
|
|
115
|
+
}) => {
|
|
116
|
+
if (!emojiCharRegEx.test(event.text))
|
|
117
|
+
return {
|
|
118
|
+
emojis: []
|
|
119
|
+
};
|
|
120
|
+
const focusBlock = getFocusTextBlock({
|
|
121
|
+
context
|
|
122
|
+
}), emojiKeyword = `${getBlockTextBefore({
|
|
123
|
+
context
|
|
124
|
+
})}${event.text}`.match(incompleteEmojiRegEx)?.[1];
|
|
125
|
+
return !focusBlock || emojiKeyword === void 0 ? {
|
|
126
|
+
emojis: []
|
|
127
|
+
} : {
|
|
128
|
+
emojis: config.matchEmojis({
|
|
129
|
+
keyword: emojiKeyword
|
|
130
|
+
})
|
|
131
|
+
};
|
|
132
|
+
},
|
|
133
|
+
actions: [(_, params) => [{
|
|
134
|
+
type: "effect",
|
|
135
|
+
effect: () => {
|
|
136
|
+
emojiPickerActor.send({
|
|
137
|
+
type: "emojis found",
|
|
138
|
+
matches: params.emojis
|
|
139
|
+
});
|
|
140
|
+
}
|
|
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);
|
|
152
|
+
if (isEnter || isTab) {
|
|
153
|
+
const matches = emojiPickerActor.getSnapshot().context.matches, 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 ? {
|
|
175
|
+
action: "navigate down"
|
|
176
|
+
} : isArrowUp ? {
|
|
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")
|
|
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
|
+
event
|
|
254
|
+
} : {
|
|
255
|
+
emojis: config.matchEmojis({
|
|
256
|
+
keyword: emojiKeyword
|
|
257
|
+
})
|
|
258
|
+
};
|
|
259
|
+
},
|
|
260
|
+
actions: [(_, params) => [{
|
|
261
|
+
type: "effect",
|
|
262
|
+
effect: () => {
|
|
263
|
+
emojiPickerActor.send({
|
|
264
|
+
type: "emojis found",
|
|
265
|
+
matches: params.emojis
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}]]
|
|
269
|
+
})];
|
|
270
|
+
}
|
|
271
|
+
function createEmojiPickerMachine() {
|
|
272
|
+
return setup({
|
|
273
|
+
types: {
|
|
274
|
+
context: {},
|
|
275
|
+
events: {}
|
|
276
|
+
},
|
|
277
|
+
actions: {
|
|
278
|
+
"assign matches": assign({
|
|
279
|
+
matches: ({
|
|
280
|
+
event
|
|
281
|
+
}) => (assertEvent(event, "emojis found"), event.matches)
|
|
282
|
+
}),
|
|
283
|
+
"reset matches": assign({
|
|
284
|
+
matches: []
|
|
285
|
+
}),
|
|
286
|
+
"reset selected index": assign({
|
|
287
|
+
selectedIndex: 0
|
|
288
|
+
}),
|
|
289
|
+
"increment selected index": assign({
|
|
290
|
+
selectedIndex: ({
|
|
291
|
+
context
|
|
292
|
+
}) => context.selectedIndex === context.matches.length - 1 ? 0 : context.selectedIndex + 1
|
|
293
|
+
}),
|
|
294
|
+
"decrement selected index": assign({
|
|
295
|
+
selectedIndex: ({
|
|
296
|
+
context
|
|
297
|
+
}) => context.selectedIndex === 0 ? context.matches.length - 1 : context.selectedIndex - 1
|
|
298
|
+
})
|
|
299
|
+
},
|
|
300
|
+
guards: {
|
|
301
|
+
"no matches": ({
|
|
302
|
+
context
|
|
303
|
+
}) => context.matches.length === 0
|
|
304
|
+
}
|
|
305
|
+
}).createMachine({
|
|
306
|
+
id: "emoji picker",
|
|
307
|
+
context: {
|
|
308
|
+
matches: [],
|
|
309
|
+
selectedIndex: 0
|
|
310
|
+
},
|
|
311
|
+
initial: "idle",
|
|
312
|
+
states: {
|
|
313
|
+
idle: {
|
|
314
|
+
on: {
|
|
315
|
+
"emojis found": {
|
|
316
|
+
actions: "assign matches",
|
|
317
|
+
target: "showing matches"
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
},
|
|
321
|
+
"showing matches": {
|
|
322
|
+
always: {
|
|
323
|
+
guard: "no matches",
|
|
324
|
+
target: "idle"
|
|
325
|
+
},
|
|
326
|
+
exit: ["reset selected index"],
|
|
327
|
+
on: {
|
|
328
|
+
"emojis found": {
|
|
329
|
+
actions: "assign matches"
|
|
330
|
+
},
|
|
331
|
+
"navigate down": {
|
|
332
|
+
actions: "increment selected index"
|
|
333
|
+
},
|
|
334
|
+
"navigate up": {
|
|
335
|
+
actions: "decrement selected index"
|
|
336
|
+
},
|
|
337
|
+
reset: {
|
|
338
|
+
target: "idle",
|
|
339
|
+
actions: ["reset selected index", "reset matches"]
|
|
340
|
+
},
|
|
341
|
+
select: {
|
|
342
|
+
target: "idle",
|
|
343
|
+
actions: ["reset selected index", "reset matches"]
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
}
|
|
53
350
|
function createLinkBehaviors(config) {
|
|
54
351
|
const pasteLinkOnSelection = defineBehavior({
|
|
55
352
|
on: "paste",
|
|
@@ -57,10 +354,9 @@ function createLinkBehaviors(config) {
|
|
|
57
354
|
context,
|
|
58
355
|
event
|
|
59
356
|
}) => {
|
|
60
|
-
var _a;
|
|
61
357
|
const selectionCollapsed = isSelectionCollapsed({
|
|
62
358
|
context
|
|
63
|
-
}), text = event.data.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ?
|
|
359
|
+
}), text = event.data.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.linkAnnotation?.({
|
|
64
360
|
url,
|
|
65
361
|
schema: context.schema
|
|
66
362
|
}) : void 0;
|
|
@@ -80,7 +376,6 @@ function createLinkBehaviors(config) {
|
|
|
80
376
|
context,
|
|
81
377
|
event
|
|
82
378
|
}) => {
|
|
83
|
-
var _a;
|
|
84
379
|
const focusSpan = getFocusSpan({
|
|
85
380
|
context
|
|
86
381
|
}), selectionCollapsed = isSelectionCollapsed({
|
|
@@ -88,7 +383,7 @@ function createLinkBehaviors(config) {
|
|
|
88
383
|
});
|
|
89
384
|
if (!focusSpan || !selectionCollapsed)
|
|
90
385
|
return !1;
|
|
91
|
-
const text = event.data.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ?
|
|
386
|
+
const text = event.data.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.linkAnnotation?.({
|
|
92
387
|
url,
|
|
93
388
|
schema: context.schema
|
|
94
389
|
}) : void 0;
|
|
@@ -113,18 +408,10 @@ function looksLikeUrl(text) {
|
|
|
113
408
|
let looksLikeUrl2 = !1;
|
|
114
409
|
try {
|
|
115
410
|
new URL(text), looksLikeUrl2 = !0;
|
|
116
|
-
} catch
|
|
411
|
+
} catch {
|
|
117
412
|
}
|
|
118
413
|
return looksLikeUrl2;
|
|
119
414
|
}
|
|
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
415
|
function createMarkdownBehaviors(config) {
|
|
129
416
|
const automaticBlockquoteOnSpace = defineBehavior({
|
|
130
417
|
on: "insert.text",
|
|
@@ -132,7 +419,6 @@ function createMarkdownBehaviors(config) {
|
|
|
132
419
|
context,
|
|
133
420
|
event
|
|
134
421
|
}) => {
|
|
135
|
-
var _a, _b, _c;
|
|
136
422
|
if (event.text !== " ")
|
|
137
423
|
return !1;
|
|
138
424
|
const selectionCollapsed = isSelectionCollapsed({
|
|
@@ -152,12 +438,12 @@ function createMarkdownBehaviors(config) {
|
|
|
152
438
|
}, "children", {
|
|
153
439
|
_key: focusSpan.node._key
|
|
154
440
|
}],
|
|
155
|
-
offset:
|
|
441
|
+
offset: context.selection?.focus.offset ?? 0
|
|
156
442
|
}
|
|
157
443
|
});
|
|
158
444
|
if (!blockOffset)
|
|
159
445
|
return !1;
|
|
160
|
-
const blockText = getTextBlockText(focusTextBlock.node), caretAtTheEndOfQuote = blockOffset.offset === 1, looksLikeMarkdownQuote = /^>/.test(blockText), blockquoteStyle =
|
|
446
|
+
const blockText = getTextBlockText(focusTextBlock.node), caretAtTheEndOfQuote = blockOffset.offset === 1, looksLikeMarkdownQuote = /^>/.test(blockText), blockquoteStyle = config.blockquoteStyle?.(context);
|
|
161
447
|
return caretAtTheEndOfQuote && looksLikeMarkdownQuote && blockquoteStyle !== void 0 ? {
|
|
162
448
|
focusTextBlock,
|
|
163
449
|
style: blockquoteStyle
|
|
@@ -194,11 +480,10 @@ function createMarkdownBehaviors(config) {
|
|
|
194
480
|
context,
|
|
195
481
|
event
|
|
196
482
|
}) => {
|
|
197
|
-
var _a;
|
|
198
483
|
const hrCharacter = event.text === "-" ? "-" : event.text === "*" ? "*" : event.text === "_" ? "_" : void 0;
|
|
199
484
|
if (hrCharacter === void 0)
|
|
200
485
|
return !1;
|
|
201
|
-
const hrObject =
|
|
486
|
+
const hrObject = config.horizontalRuleObject?.(context), focusBlock = getFocusTextBlock({
|
|
202
487
|
context
|
|
203
488
|
}), selectionCollapsed = isSelectionCollapsed({
|
|
204
489
|
context
|
|
@@ -236,17 +521,17 @@ function createMarkdownBehaviors(config) {
|
|
|
236
521
|
type: "insert.block object",
|
|
237
522
|
placement: "before",
|
|
238
523
|
blockObject: hrObject
|
|
239
|
-
},
|
|
240
|
-
type: "delete.text"
|
|
241
|
-
|
|
524
|
+
}, {
|
|
525
|
+
type: "delete.text",
|
|
526
|
+
...hrBlockOffsets
|
|
527
|
+
}]]
|
|
242
528
|
}), automaticHrOnPaste = defineBehavior({
|
|
243
529
|
on: "paste",
|
|
244
530
|
guard: ({
|
|
245
531
|
context,
|
|
246
532
|
event
|
|
247
533
|
}) => {
|
|
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({
|
|
534
|
+
const text = event.data.getData("text/plain"), hrRegExp = /^(---)$|(___)$|(\*\*\*)$/gm, hrCharacters = text.match(hrRegExp)?.[0], hrObject = config.horizontalRuleObject?.(context), focusBlock = getFocusBlock({
|
|
250
535
|
context
|
|
251
536
|
});
|
|
252
537
|
return !hrCharacters || !hrObject || !focusBlock ? !1 : {
|
|
@@ -287,7 +572,6 @@ function createMarkdownBehaviors(config) {
|
|
|
287
572
|
context,
|
|
288
573
|
event
|
|
289
574
|
}) => {
|
|
290
|
-
var _a, _b, _c;
|
|
291
575
|
if (event.text !== " ")
|
|
292
576
|
return !1;
|
|
293
577
|
const selectionCollapsed = isSelectionCollapsed({
|
|
@@ -307,7 +591,7 @@ function createMarkdownBehaviors(config) {
|
|
|
307
591
|
}, "children", {
|
|
308
592
|
_key: focusSpan.node._key
|
|
309
593
|
}],
|
|
310
|
-
offset:
|
|
594
|
+
offset: context.selection?.focus.offset ?? 0
|
|
311
595
|
}
|
|
312
596
|
});
|
|
313
597
|
if (!blockOffset)
|
|
@@ -315,7 +599,7 @@ function createMarkdownBehaviors(config) {
|
|
|
315
599
|
const blockText = getTextBlockText(focusTextBlock.node), markdownHeadingSearch = /^#+/.exec(blockText), level = markdownHeadingSearch ? markdownHeadingSearch[0].length : void 0;
|
|
316
600
|
if (blockOffset.offset !== level)
|
|
317
601
|
return !1;
|
|
318
|
-
const style = level !== void 0 ?
|
|
602
|
+
const style = level !== void 0 ? config.headingStyle?.({
|
|
319
603
|
schema: context.schema,
|
|
320
604
|
level
|
|
321
605
|
}) : void 0;
|
|
@@ -355,7 +639,6 @@ function createMarkdownBehaviors(config) {
|
|
|
355
639
|
guard: ({
|
|
356
640
|
context
|
|
357
641
|
}) => {
|
|
358
|
-
var _a, _b;
|
|
359
642
|
const selectionCollapsed = isSelectionCollapsed({
|
|
360
643
|
context
|
|
361
644
|
}), focusTextBlock = getFocusTextBlock({
|
|
@@ -365,7 +648,7 @@ function createMarkdownBehaviors(config) {
|
|
|
365
648
|
});
|
|
366
649
|
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
367
650
|
return !1;
|
|
368
|
-
const atTheBeginningOfBLock = focusTextBlock.node.children[0]._key === focusSpan.node._key &&
|
|
651
|
+
const atTheBeginningOfBLock = focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection?.focus.offset === 0, defaultStyle = config.defaultStyle?.(context);
|
|
369
652
|
return atTheBeginningOfBLock && defaultStyle && focusTextBlock.node.style !== defaultStyle ? {
|
|
370
653
|
defaultStyle,
|
|
371
654
|
focusTextBlock
|
|
@@ -385,7 +668,6 @@ function createMarkdownBehaviors(config) {
|
|
|
385
668
|
context,
|
|
386
669
|
event
|
|
387
670
|
}) => {
|
|
388
|
-
var _a, _b, _c, _d, _e;
|
|
389
671
|
if (event.text !== " ")
|
|
390
672
|
return !1;
|
|
391
673
|
const selectionCollapsed = isSelectionCollapsed({
|
|
@@ -405,12 +687,12 @@ function createMarkdownBehaviors(config) {
|
|
|
405
687
|
}, "children", {
|
|
406
688
|
_key: focusSpan.node._key
|
|
407
689
|
}],
|
|
408
|
-
offset:
|
|
690
|
+
offset: context.selection?.focus.offset ?? 0
|
|
409
691
|
}
|
|
410
692
|
});
|
|
411
693
|
if (!blockOffset)
|
|
412
694
|
return !1;
|
|
413
|
-
const blockText = getTextBlockText(focusTextBlock.node), defaultStyle =
|
|
695
|
+
const blockText = getTextBlockText(focusTextBlock.node), defaultStyle = config.defaultStyle?.(context), looksLikeUnorderedList = /^(-|\*)/.test(blockText), unorderedListStyle = config.unorderedListStyle?.(context), caretAtTheEndOfUnorderedList = blockOffset.offset === 1;
|
|
414
696
|
if (defaultStyle && caretAtTheEndOfUnorderedList && looksLikeUnorderedList && unorderedListStyle !== void 0)
|
|
415
697
|
return {
|
|
416
698
|
focusTextBlock,
|
|
@@ -418,7 +700,7 @@ function createMarkdownBehaviors(config) {
|
|
|
418
700
|
listItemLength: 1,
|
|
419
701
|
style: defaultStyle
|
|
420
702
|
};
|
|
421
|
-
const looksLikeOrderedList = /^1\./.test(blockText), orderedListStyle =
|
|
703
|
+
const looksLikeOrderedList = /^1\./.test(blockText), orderedListStyle = config.orderedListStyle?.(context), caretAtTheEndOfOrderedList = blockOffset.offset === 2;
|
|
422
704
|
return defaultStyle && caretAtTheEndOfOrderedList && looksLikeOrderedList && orderedListStyle !== void 0 ? {
|
|
423
705
|
focusTextBlock,
|
|
424
706
|
listItem: orderedListStyle,
|
|
@@ -457,6 +739,7 @@ export {
|
|
|
457
739
|
coreBehavior,
|
|
458
740
|
coreBehaviors,
|
|
459
741
|
createCodeEditorBehaviors,
|
|
742
|
+
createEmojiPickerBehaviors,
|
|
460
743
|
createLinkBehaviors,
|
|
461
744
|
createMarkdownBehaviors,
|
|
462
745
|
defineBehavior
|