@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.cjs
CHANGED
|
@@ -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"),
|
|
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 =
|
|
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 =
|
|
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,303 @@ 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 (!emojiCharRegEx.test(event.text))
|
|
65
|
+
return {
|
|
66
|
+
emojis: []
|
|
67
|
+
};
|
|
68
|
+
const focusBlock = selector_isSelectionCollapsed.getFocusTextBlock({
|
|
69
|
+
context
|
|
70
|
+
}), emojiKeyword = `${selector_getTextBefore.getBlockTextBefore({
|
|
71
|
+
context
|
|
72
|
+
})}${event.text}`.match(incompleteEmojiRegEx)?.[1];
|
|
73
|
+
return !focusBlock || emojiKeyword === void 0 ? {
|
|
74
|
+
emojis: []
|
|
75
|
+
} : {
|
|
76
|
+
emojis: config.matchEmojis({
|
|
77
|
+
keyword: emojiKeyword
|
|
78
|
+
})
|
|
79
|
+
};
|
|
80
|
+
},
|
|
81
|
+
actions: [(_, params) => [{
|
|
82
|
+
type: "effect",
|
|
83
|
+
effect: () => {
|
|
84
|
+
emojiPickerActor.send({
|
|
85
|
+
type: "emojis found",
|
|
86
|
+
matches: params.emojis
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}]]
|
|
90
|
+
}), behavior_core.defineBehavior({
|
|
91
|
+
on: "insert.text",
|
|
92
|
+
guard: ({
|
|
93
|
+
context,
|
|
94
|
+
event
|
|
95
|
+
}) => {
|
|
96
|
+
if (event.text !== ":")
|
|
97
|
+
return !1;
|
|
98
|
+
const matches = emojiPickerActor.getSnapshot().context.matches, selectedIndex = emojiPickerActor.getSnapshot().context.selectedIndex, emoji = matches[selectedIndex] ? config.parseMatch({
|
|
99
|
+
match: matches[selectedIndex]
|
|
100
|
+
}) : void 0, focusBlock = selector_isSelectionCollapsed.getFocusTextBlock({
|
|
101
|
+
context
|
|
102
|
+
}), textBefore = selector_getTextBefore.getBlockTextBefore({
|
|
103
|
+
context
|
|
104
|
+
}), emojiKeyword = `${textBefore}:`.match(emojiRegEx)?.[1];
|
|
105
|
+
if (!focusBlock || emojiKeyword === void 0)
|
|
106
|
+
return !1;
|
|
107
|
+
const emojiStringLength = emojiKeyword.length + 2;
|
|
108
|
+
return emoji ? {
|
|
109
|
+
focusBlock,
|
|
110
|
+
emoji,
|
|
111
|
+
emojiStringLength,
|
|
112
|
+
textBeforeLength: textBefore.length + 1
|
|
113
|
+
} : !1;
|
|
114
|
+
},
|
|
115
|
+
actions: [() => [{
|
|
116
|
+
type: "insert.text",
|
|
117
|
+
text: ":"
|
|
118
|
+
}], (_, params) => [{
|
|
119
|
+
type: "effect",
|
|
120
|
+
effect: () => {
|
|
121
|
+
emojiPickerActor.send({
|
|
122
|
+
type: "select"
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}, {
|
|
126
|
+
type: "delete.text",
|
|
127
|
+
anchor: {
|
|
128
|
+
path: params.focusBlock.path,
|
|
129
|
+
offset: params.textBeforeLength - params.emojiStringLength
|
|
130
|
+
},
|
|
131
|
+
focus: {
|
|
132
|
+
path: params.focusBlock.path,
|
|
133
|
+
offset: params.textBeforeLength
|
|
134
|
+
}
|
|
135
|
+
}, {
|
|
136
|
+
type: "insert.text",
|
|
137
|
+
text: params.emoji
|
|
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), matches = emojiPickerActor.getSnapshot().context.matches;
|
|
149
|
+
if (isEnter || isTab) {
|
|
150
|
+
const 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 && matches.length > 0 ? {
|
|
172
|
+
action: "navigate down"
|
|
173
|
+
} : isArrowUp && matches.length > 0 ? {
|
|
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" || emojiPickerActor.getSnapshot().context.matches.length === 0)
|
|
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
|
+
} : {
|
|
251
|
+
emojis: config.matchEmojis({
|
|
252
|
+
keyword: emojiKeyword
|
|
253
|
+
})
|
|
254
|
+
};
|
|
255
|
+
},
|
|
256
|
+
actions: [(_, params) => [{
|
|
257
|
+
type: "effect",
|
|
258
|
+
effect: () => {
|
|
259
|
+
emojiPickerActor.send({
|
|
260
|
+
type: "emojis found",
|
|
261
|
+
matches: params.emojis
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}]]
|
|
265
|
+
})];
|
|
266
|
+
}
|
|
267
|
+
function createEmojiPickerMachine() {
|
|
268
|
+
return xstate.setup({
|
|
269
|
+
types: {
|
|
270
|
+
context: {},
|
|
271
|
+
events: {}
|
|
272
|
+
},
|
|
273
|
+
actions: {
|
|
274
|
+
"assign matches": xstate.assign({
|
|
275
|
+
matches: ({
|
|
276
|
+
event
|
|
277
|
+
}) => (xstate.assertEvent(event, "emojis found"), event.matches)
|
|
278
|
+
}),
|
|
279
|
+
"reset matches": xstate.assign({
|
|
280
|
+
matches: []
|
|
281
|
+
}),
|
|
282
|
+
"reset selected index": xstate.assign({
|
|
283
|
+
selectedIndex: 0
|
|
284
|
+
}),
|
|
285
|
+
"increment selected index": xstate.assign({
|
|
286
|
+
selectedIndex: ({
|
|
287
|
+
context
|
|
288
|
+
}) => context.selectedIndex === context.matches.length - 1 ? 0 : context.selectedIndex + 1
|
|
289
|
+
}),
|
|
290
|
+
"decrement selected index": xstate.assign({
|
|
291
|
+
selectedIndex: ({
|
|
292
|
+
context
|
|
293
|
+
}) => context.selectedIndex === 0 ? context.matches.length - 1 : context.selectedIndex - 1
|
|
294
|
+
})
|
|
295
|
+
},
|
|
296
|
+
guards: {
|
|
297
|
+
"no matches": ({
|
|
298
|
+
context
|
|
299
|
+
}) => context.matches.length === 0
|
|
300
|
+
}
|
|
301
|
+
}).createMachine({
|
|
302
|
+
id: "emoji picker",
|
|
303
|
+
context: {
|
|
304
|
+
matches: [],
|
|
305
|
+
selectedIndex: 0
|
|
306
|
+
},
|
|
307
|
+
initial: "idle",
|
|
308
|
+
states: {
|
|
309
|
+
idle: {
|
|
310
|
+
on: {
|
|
311
|
+
"emojis found": {
|
|
312
|
+
actions: "assign matches",
|
|
313
|
+
target: "showing matches"
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
"showing matches": {
|
|
318
|
+
always: {
|
|
319
|
+
guard: "no matches",
|
|
320
|
+
target: "idle"
|
|
321
|
+
},
|
|
322
|
+
exit: ["reset selected index"],
|
|
323
|
+
on: {
|
|
324
|
+
"emojis found": {
|
|
325
|
+
actions: "assign matches"
|
|
326
|
+
},
|
|
327
|
+
"navigate down": {
|
|
328
|
+
actions: "increment selected index"
|
|
329
|
+
},
|
|
330
|
+
"navigate up": {
|
|
331
|
+
actions: "decrement selected index"
|
|
332
|
+
},
|
|
333
|
+
reset: {
|
|
334
|
+
target: "idle",
|
|
335
|
+
actions: ["reset selected index", "reset matches"]
|
|
336
|
+
},
|
|
337
|
+
select: {
|
|
338
|
+
target: "idle",
|
|
339
|
+
actions: ["reset selected index", "reset matches"]
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
}
|
|
51
346
|
function createLinkBehaviors(config) {
|
|
52
347
|
const pasteLinkOnSelection = behavior_core.defineBehavior({
|
|
53
348
|
on: "paste",
|
|
@@ -55,10 +350,9 @@ function createLinkBehaviors(config) {
|
|
|
55
350
|
context,
|
|
56
351
|
event
|
|
57
352
|
}) => {
|
|
58
|
-
var _a;
|
|
59
353
|
const selectionCollapsed = selector_isSelectionCollapsed.isSelectionCollapsed({
|
|
60
354
|
context
|
|
61
|
-
}), text = event.data.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ?
|
|
355
|
+
}), text = event.data.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.linkAnnotation?.({
|
|
62
356
|
url,
|
|
63
357
|
schema: context.schema
|
|
64
358
|
}) : void 0;
|
|
@@ -78,7 +372,6 @@ function createLinkBehaviors(config) {
|
|
|
78
372
|
context,
|
|
79
373
|
event
|
|
80
374
|
}) => {
|
|
81
|
-
var _a;
|
|
82
375
|
const focusSpan = selector_isSelectionCollapsed.getFocusSpan({
|
|
83
376
|
context
|
|
84
377
|
}), selectionCollapsed = selector_isSelectionCollapsed.isSelectionCollapsed({
|
|
@@ -86,7 +379,7 @@ function createLinkBehaviors(config) {
|
|
|
86
379
|
});
|
|
87
380
|
if (!focusSpan || !selectionCollapsed)
|
|
88
381
|
return !1;
|
|
89
|
-
const text = event.data.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ?
|
|
382
|
+
const text = event.data.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.linkAnnotation?.({
|
|
90
383
|
url,
|
|
91
384
|
schema: context.schema
|
|
92
385
|
}) : void 0;
|
|
@@ -111,18 +404,10 @@ function looksLikeUrl(text) {
|
|
|
111
404
|
let looksLikeUrl2 = !1;
|
|
112
405
|
try {
|
|
113
406
|
new URL(text), looksLikeUrl2 = !0;
|
|
114
|
-
} catch
|
|
407
|
+
} catch {
|
|
115
408
|
}
|
|
116
409
|
return looksLikeUrl2;
|
|
117
410
|
}
|
|
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
411
|
function createMarkdownBehaviors(config) {
|
|
127
412
|
const automaticBlockquoteOnSpace = behavior_core.defineBehavior({
|
|
128
413
|
on: "insert.text",
|
|
@@ -130,7 +415,6 @@ function createMarkdownBehaviors(config) {
|
|
|
130
415
|
context,
|
|
131
416
|
event
|
|
132
417
|
}) => {
|
|
133
|
-
var _a, _b, _c;
|
|
134
418
|
if (event.text !== " ")
|
|
135
419
|
return !1;
|
|
136
420
|
const selectionCollapsed = selector_isSelectionCollapsed.isSelectionCollapsed({
|
|
@@ -150,12 +434,12 @@ function createMarkdownBehaviors(config) {
|
|
|
150
434
|
}, "children", {
|
|
151
435
|
_key: focusSpan.node._key
|
|
152
436
|
}],
|
|
153
|
-
offset:
|
|
437
|
+
offset: context.selection?.focus.offset ?? 0
|
|
154
438
|
}
|
|
155
439
|
});
|
|
156
440
|
if (!blockOffset)
|
|
157
441
|
return !1;
|
|
158
|
-
const blockText = behavior_core.getTextBlockText(focusTextBlock.node), caretAtTheEndOfQuote = blockOffset.offset === 1, looksLikeMarkdownQuote = /^>/.test(blockText), blockquoteStyle =
|
|
442
|
+
const blockText = behavior_core.getTextBlockText(focusTextBlock.node), caretAtTheEndOfQuote = blockOffset.offset === 1, looksLikeMarkdownQuote = /^>/.test(blockText), blockquoteStyle = config.blockquoteStyle?.(context);
|
|
159
443
|
return caretAtTheEndOfQuote && looksLikeMarkdownQuote && blockquoteStyle !== void 0 ? {
|
|
160
444
|
focusTextBlock,
|
|
161
445
|
style: blockquoteStyle
|
|
@@ -192,11 +476,10 @@ function createMarkdownBehaviors(config) {
|
|
|
192
476
|
context,
|
|
193
477
|
event
|
|
194
478
|
}) => {
|
|
195
|
-
var _a;
|
|
196
479
|
const hrCharacter = event.text === "-" ? "-" : event.text === "*" ? "*" : event.text === "_" ? "_" : void 0;
|
|
197
480
|
if (hrCharacter === void 0)
|
|
198
481
|
return !1;
|
|
199
|
-
const hrObject =
|
|
482
|
+
const hrObject = config.horizontalRuleObject?.(context), focusBlock = selector_isSelectionCollapsed.getFocusTextBlock({
|
|
200
483
|
context
|
|
201
484
|
}), selectionCollapsed = selector_isSelectionCollapsed.isSelectionCollapsed({
|
|
202
485
|
context
|
|
@@ -234,17 +517,17 @@ function createMarkdownBehaviors(config) {
|
|
|
234
517
|
type: "insert.block object",
|
|
235
518
|
placement: "before",
|
|
236
519
|
blockObject: hrObject
|
|
237
|
-
},
|
|
238
|
-
type: "delete.text"
|
|
239
|
-
|
|
520
|
+
}, {
|
|
521
|
+
type: "delete.text",
|
|
522
|
+
...hrBlockOffsets
|
|
523
|
+
}]]
|
|
240
524
|
}), automaticHrOnPaste = behavior_core.defineBehavior({
|
|
241
525
|
on: "paste",
|
|
242
526
|
guard: ({
|
|
243
527
|
context,
|
|
244
528
|
event
|
|
245
529
|
}) => {
|
|
246
|
-
|
|
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({
|
|
530
|
+
const text = event.data.getData("text/plain"), hrRegExp = /^(---)$|(___)$|(\*\*\*)$/gm, hrCharacters = text.match(hrRegExp)?.[0], hrObject = config.horizontalRuleObject?.(context), focusBlock = selector_isSelectionCollapsed.getFocusBlock({
|
|
248
531
|
context
|
|
249
532
|
});
|
|
250
533
|
return !hrCharacters || !hrObject || !focusBlock ? !1 : {
|
|
@@ -285,7 +568,6 @@ function createMarkdownBehaviors(config) {
|
|
|
285
568
|
context,
|
|
286
569
|
event
|
|
287
570
|
}) => {
|
|
288
|
-
var _a, _b, _c;
|
|
289
571
|
if (event.text !== " ")
|
|
290
572
|
return !1;
|
|
291
573
|
const selectionCollapsed = selector_isSelectionCollapsed.isSelectionCollapsed({
|
|
@@ -305,7 +587,7 @@ function createMarkdownBehaviors(config) {
|
|
|
305
587
|
}, "children", {
|
|
306
588
|
_key: focusSpan.node._key
|
|
307
589
|
}],
|
|
308
|
-
offset:
|
|
590
|
+
offset: context.selection?.focus.offset ?? 0
|
|
309
591
|
}
|
|
310
592
|
});
|
|
311
593
|
if (!blockOffset)
|
|
@@ -313,7 +595,7 @@ function createMarkdownBehaviors(config) {
|
|
|
313
595
|
const blockText = behavior_core.getTextBlockText(focusTextBlock.node), markdownHeadingSearch = /^#+/.exec(blockText), level = markdownHeadingSearch ? markdownHeadingSearch[0].length : void 0;
|
|
314
596
|
if (blockOffset.offset !== level)
|
|
315
597
|
return !1;
|
|
316
|
-
const style = level !== void 0 ?
|
|
598
|
+
const style = level !== void 0 ? config.headingStyle?.({
|
|
317
599
|
schema: context.schema,
|
|
318
600
|
level
|
|
319
601
|
}) : void 0;
|
|
@@ -353,7 +635,6 @@ function createMarkdownBehaviors(config) {
|
|
|
353
635
|
guard: ({
|
|
354
636
|
context
|
|
355
637
|
}) => {
|
|
356
|
-
var _a, _b;
|
|
357
638
|
const selectionCollapsed = selector_isSelectionCollapsed.isSelectionCollapsed({
|
|
358
639
|
context
|
|
359
640
|
}), focusTextBlock = selector_isSelectionCollapsed.getFocusTextBlock({
|
|
@@ -363,7 +644,7 @@ function createMarkdownBehaviors(config) {
|
|
|
363
644
|
});
|
|
364
645
|
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
365
646
|
return !1;
|
|
366
|
-
const atTheBeginningOfBLock = focusTextBlock.node.children[0]._key === focusSpan.node._key &&
|
|
647
|
+
const atTheBeginningOfBLock = focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection?.focus.offset === 0, defaultStyle = config.defaultStyle?.(context);
|
|
367
648
|
return atTheBeginningOfBLock && defaultStyle && focusTextBlock.node.style !== defaultStyle ? {
|
|
368
649
|
defaultStyle,
|
|
369
650
|
focusTextBlock
|
|
@@ -383,7 +664,6 @@ function createMarkdownBehaviors(config) {
|
|
|
383
664
|
context,
|
|
384
665
|
event
|
|
385
666
|
}) => {
|
|
386
|
-
var _a, _b, _c, _d, _e;
|
|
387
667
|
if (event.text !== " ")
|
|
388
668
|
return !1;
|
|
389
669
|
const selectionCollapsed = selector_isSelectionCollapsed.isSelectionCollapsed({
|
|
@@ -403,12 +683,12 @@ function createMarkdownBehaviors(config) {
|
|
|
403
683
|
}, "children", {
|
|
404
684
|
_key: focusSpan.node._key
|
|
405
685
|
}],
|
|
406
|
-
offset:
|
|
686
|
+
offset: context.selection?.focus.offset ?? 0
|
|
407
687
|
}
|
|
408
688
|
});
|
|
409
689
|
if (!blockOffset)
|
|
410
690
|
return !1;
|
|
411
|
-
const blockText = behavior_core.getTextBlockText(focusTextBlock.node), defaultStyle =
|
|
691
|
+
const blockText = behavior_core.getTextBlockText(focusTextBlock.node), defaultStyle = config.defaultStyle?.(context), looksLikeUnorderedList = /^(-|\*)/.test(blockText), unorderedListStyle = config.unorderedListStyle?.(context), caretAtTheEndOfUnorderedList = blockOffset.offset === 1;
|
|
412
692
|
if (defaultStyle && caretAtTheEndOfUnorderedList && looksLikeUnorderedList && unorderedListStyle !== void 0)
|
|
413
693
|
return {
|
|
414
694
|
focusTextBlock,
|
|
@@ -416,7 +696,7 @@ function createMarkdownBehaviors(config) {
|
|
|
416
696
|
listItemLength: 1,
|
|
417
697
|
style: defaultStyle
|
|
418
698
|
};
|
|
419
|
-
const looksLikeOrderedList = /^1\./.test(blockText), orderedListStyle =
|
|
699
|
+
const looksLikeOrderedList = /^1\./.test(blockText), orderedListStyle = config.orderedListStyle?.(context), caretAtTheEndOfOrderedList = blockOffset.offset === 2;
|
|
420
700
|
return defaultStyle && caretAtTheEndOfOrderedList && looksLikeOrderedList && orderedListStyle !== void 0 ? {
|
|
421
701
|
focusTextBlock,
|
|
422
702
|
listItem: orderedListStyle,
|
|
@@ -455,6 +735,7 @@ exports.coreBehavior = behavior_core.coreBehavior;
|
|
|
455
735
|
exports.coreBehaviors = behavior_core.coreBehaviors;
|
|
456
736
|
exports.defineBehavior = behavior_core.defineBehavior;
|
|
457
737
|
exports.createCodeEditorBehaviors = createCodeEditorBehaviors;
|
|
738
|
+
exports.createEmojiPickerBehaviors = createEmojiPickerBehaviors;
|
|
458
739
|
exports.createLinkBehaviors = createLinkBehaviors;
|
|
459
740
|
exports.createMarkdownBehaviors = createMarkdownBehaviors;
|
|
460
741
|
//# sourceMappingURL=index.cjs.map
|