@portabletext/plugin-markdown-shortcuts 8.0.44 → 8.0.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +67 -121
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +372 -476
- package/dist/index.js.map +1 -1
- package/package.json +14 -12
package/dist/index.js
CHANGED
|
@@ -1,500 +1,396 @@
|
|
|
1
|
-
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
2
1
|
import { c } from "react/compiler-runtime";
|
|
3
2
|
import { useEditor } from "@portabletext/editor";
|
|
4
3
|
import { CharacterPairDecoratorPlugin } from "@portabletext/plugin-character-pair-decorator";
|
|
5
|
-
import {
|
|
4
|
+
import { InputRulePlugin, defineInputRule } from "@portabletext/plugin-input-rule";
|
|
6
5
|
import { useEffect } from "react";
|
|
7
6
|
import { defineBehavior, raise } from "@portabletext/editor/behaviors";
|
|
8
7
|
import * as selectors from "@portabletext/editor/selectors";
|
|
9
8
|
import { getPreviousInlineObject } from "@portabletext/editor/selectors";
|
|
10
9
|
import { getPathSubSchema } from "@portabletext/editor/traversal";
|
|
10
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
11
11
|
function createMarkdownBehaviors(config) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
schema: subSchema
|
|
75
|
-
},
|
|
76
|
-
schema: subSchema
|
|
77
|
-
});
|
|
78
|
-
return defaultStyle && focusTextBlock.node.style !== defaultStyle ? {
|
|
79
|
-
defaultStyle,
|
|
80
|
-
focusTextBlock
|
|
81
|
-
} : !1;
|
|
82
|
-
},
|
|
83
|
-
actions: [(_, {
|
|
84
|
-
defaultStyle,
|
|
85
|
-
focusTextBlock
|
|
86
|
-
}) => [raise({
|
|
87
|
-
type: "block.set",
|
|
88
|
-
props: {
|
|
89
|
-
style: defaultStyle
|
|
90
|
-
},
|
|
91
|
-
at: focusTextBlock.path
|
|
92
|
-
})]]
|
|
93
|
-
});
|
|
94
|
-
return [automaticHrOnPaste, clearStyleOnBackspace];
|
|
12
|
+
return [defineBehavior({
|
|
13
|
+
on: "clipboard.paste",
|
|
14
|
+
guard: ({ snapshot, event }) => {
|
|
15
|
+
let hrCharacters = event.originEvent.dataTransfer.getData("text/plain").match(/^(---)$|^(—-)$|^(___)$|^(\*\*\*)$/)?.[0], focusBlock = selectors.getFocusBlock(snapshot), focusTextBlock = selectors.getFocusTextBlock(snapshot);
|
|
16
|
+
if (!focusBlock) return !1;
|
|
17
|
+
let hrObject = config.horizontalRuleObject?.({ context: {
|
|
18
|
+
schema: getPathSubSchema(snapshot, focusBlock.path),
|
|
19
|
+
keyGenerator: snapshot.context.keyGenerator
|
|
20
|
+
} });
|
|
21
|
+
return !hrCharacters || !hrObject ? !1 : {
|
|
22
|
+
hrCharacters,
|
|
23
|
+
hrObject,
|
|
24
|
+
focusBlock,
|
|
25
|
+
focusTextBlock
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
actions: [(_, { hrCharacters }) => [raise({
|
|
29
|
+
type: "insert.text",
|
|
30
|
+
text: hrCharacters
|
|
31
|
+
})], ({ snapshot }, { hrObject, focusBlock, focusTextBlock }) => focusTextBlock ? [
|
|
32
|
+
raise({
|
|
33
|
+
type: "insert.block",
|
|
34
|
+
block: {
|
|
35
|
+
_type: snapshot.context.schema.block.name,
|
|
36
|
+
children: focusTextBlock.node.children
|
|
37
|
+
},
|
|
38
|
+
placement: "after"
|
|
39
|
+
}),
|
|
40
|
+
raise({
|
|
41
|
+
type: "insert.block",
|
|
42
|
+
block: hrObject,
|
|
43
|
+
placement: "after"
|
|
44
|
+
}),
|
|
45
|
+
raise({
|
|
46
|
+
type: "delete.block",
|
|
47
|
+
at: focusBlock.path
|
|
48
|
+
})
|
|
49
|
+
] : [raise({
|
|
50
|
+
type: "insert.block",
|
|
51
|
+
block: hrObject,
|
|
52
|
+
placement: "after"
|
|
53
|
+
})]]
|
|
54
|
+
}), defineBehavior({
|
|
55
|
+
on: "delete.backward",
|
|
56
|
+
guard: ({ snapshot }) => {
|
|
57
|
+
let selectionCollapsed = selectors.isSelectionCollapsed(snapshot), focusTextBlock = selectors.getFocusTextBlock(snapshot), focusSpan = selectors.getFocusSpan(snapshot);
|
|
58
|
+
if (!selectionCollapsed || !focusTextBlock || !focusSpan || focusTextBlock.node.children[0]._key !== focusSpan.node._key || snapshot.context.selection?.focus.offset !== 0) return !1;
|
|
59
|
+
let subSchema = getPathSubSchema(snapshot, focusTextBlock.path), defaultStyle = config.defaultStyle?.({
|
|
60
|
+
context: { schema: subSchema },
|
|
61
|
+
schema: subSchema
|
|
62
|
+
});
|
|
63
|
+
return defaultStyle && focusTextBlock.node.style !== defaultStyle ? {
|
|
64
|
+
defaultStyle,
|
|
65
|
+
focusTextBlock
|
|
66
|
+
} : !1;
|
|
67
|
+
},
|
|
68
|
+
actions: [(_, { defaultStyle, focusTextBlock }) => [raise({
|
|
69
|
+
type: "block.set",
|
|
70
|
+
props: { style: defaultStyle },
|
|
71
|
+
at: focusTextBlock.path
|
|
72
|
+
})]]
|
|
73
|
+
})];
|
|
95
74
|
}
|
|
96
75
|
function createBlockquoteRule(config) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
props: {
|
|
129
|
-
style
|
|
130
|
-
},
|
|
131
|
-
at: event.focusBlock.path
|
|
132
|
-
}), raise({
|
|
133
|
-
type: "delete",
|
|
134
|
-
at: match.targetOffsets
|
|
135
|
-
})]]
|
|
136
|
-
});
|
|
76
|
+
return defineInputRule({
|
|
77
|
+
on: /^> /,
|
|
78
|
+
guard: ({ snapshot, event }) => {
|
|
79
|
+
let subSchema = getPathSubSchema(snapshot, event.focusBlock.path), style = config.blockquoteStyle({
|
|
80
|
+
context: { schema: subSchema },
|
|
81
|
+
schema: subSchema
|
|
82
|
+
});
|
|
83
|
+
if (!style || getPreviousInlineObject(snapshot)) return !1;
|
|
84
|
+
let match = event.matches.at(0);
|
|
85
|
+
return match ? {
|
|
86
|
+
style,
|
|
87
|
+
match
|
|
88
|
+
} : !1;
|
|
89
|
+
},
|
|
90
|
+
actions: [({ event }, { style, match }) => [
|
|
91
|
+
raise({
|
|
92
|
+
type: "block.unset",
|
|
93
|
+
props: ["listItem", "level"],
|
|
94
|
+
at: event.focusBlock.path
|
|
95
|
+
}),
|
|
96
|
+
raise({
|
|
97
|
+
type: "block.set",
|
|
98
|
+
props: { style },
|
|
99
|
+
at: event.focusBlock.path
|
|
100
|
+
}),
|
|
101
|
+
raise({
|
|
102
|
+
type: "delete",
|
|
103
|
+
at: match.targetOffsets
|
|
104
|
+
})
|
|
105
|
+
]]
|
|
106
|
+
});
|
|
137
107
|
}
|
|
138
108
|
function createHeadingRule(config) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
at: event.focusBlock.path
|
|
174
|
-
}), raise({
|
|
175
|
-
type: "block.set",
|
|
176
|
-
props: {
|
|
177
|
-
style
|
|
178
|
-
},
|
|
179
|
-
at: event.focusBlock.path
|
|
180
|
-
}), raise({
|
|
181
|
-
type: "delete",
|
|
182
|
-
at: match.targetOffsets
|
|
183
|
-
})]]
|
|
184
|
-
});
|
|
109
|
+
return defineInputRule({
|
|
110
|
+
on: /^#+ /,
|
|
111
|
+
guard: ({ snapshot, event }) => {
|
|
112
|
+
if (getPreviousInlineObject(snapshot)) return !1;
|
|
113
|
+
let match = event.matches.at(0);
|
|
114
|
+
if (!match) return !1;
|
|
115
|
+
let level = match.text.length - 1, subSchema = getPathSubSchema(snapshot, event.focusBlock.path), style = config.headingStyle({
|
|
116
|
+
context: { schema: subSchema },
|
|
117
|
+
schema: subSchema,
|
|
118
|
+
props: { level },
|
|
119
|
+
level
|
|
120
|
+
});
|
|
121
|
+
return style ? {
|
|
122
|
+
match,
|
|
123
|
+
style
|
|
124
|
+
} : !1;
|
|
125
|
+
},
|
|
126
|
+
actions: [({ event }, { match, style }) => [
|
|
127
|
+
raise({
|
|
128
|
+
type: "block.unset",
|
|
129
|
+
props: ["listItem", "level"],
|
|
130
|
+
at: event.focusBlock.path
|
|
131
|
+
}),
|
|
132
|
+
raise({
|
|
133
|
+
type: "block.set",
|
|
134
|
+
props: { style },
|
|
135
|
+
at: event.focusBlock.path
|
|
136
|
+
}),
|
|
137
|
+
raise({
|
|
138
|
+
type: "delete",
|
|
139
|
+
at: match.targetOffsets
|
|
140
|
+
})
|
|
141
|
+
]]
|
|
142
|
+
});
|
|
185
143
|
}
|
|
186
144
|
function createHorizontalRuleRule(config) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
type: "insert.block",
|
|
212
|
-
block: hrObject,
|
|
213
|
-
placement: "before",
|
|
214
|
-
select: "none"
|
|
215
|
-
}), raise({
|
|
216
|
-
type: "delete",
|
|
217
|
-
at: match.targetOffsets
|
|
218
|
-
})]]
|
|
219
|
-
});
|
|
145
|
+
return defineInputRule({
|
|
146
|
+
on: /^(---)|^(—-)|^(___)|^(\*\*\*)/,
|
|
147
|
+
guard: ({ snapshot, event }) => {
|
|
148
|
+
let subSchema = getPathSubSchema(snapshot, event.focusBlock.path), hrObject = config.horizontalRuleObject({ context: {
|
|
149
|
+
schema: subSchema,
|
|
150
|
+
keyGenerator: snapshot.context.keyGenerator
|
|
151
|
+
} });
|
|
152
|
+
if (!hrObject || getPreviousInlineObject(snapshot)) return !1;
|
|
153
|
+
let match = event.matches.at(0);
|
|
154
|
+
return match ? {
|
|
155
|
+
hrObject,
|
|
156
|
+
match
|
|
157
|
+
} : !1;
|
|
158
|
+
},
|
|
159
|
+
actions: [(_, { hrObject, match }) => [raise({
|
|
160
|
+
type: "insert.block",
|
|
161
|
+
block: hrObject,
|
|
162
|
+
placement: "before",
|
|
163
|
+
select: "none"
|
|
164
|
+
}), raise({
|
|
165
|
+
type: "delete",
|
|
166
|
+
at: match.targetOffsets
|
|
167
|
+
})]]
|
|
168
|
+
});
|
|
220
169
|
}
|
|
221
170
|
function createMarkdownLinkRule(config) {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
at: rightSideOffsets
|
|
279
|
-
})), actions.push(raise({
|
|
280
|
-
type: "delete",
|
|
281
|
-
at: leftSideOffsets
|
|
282
|
-
}));
|
|
283
|
-
}
|
|
284
|
-
if (actions.length === 0)
|
|
285
|
-
return [];
|
|
286
|
-
const endCaretPosition = {
|
|
287
|
-
path: event.focusBlock.path,
|
|
288
|
-
offset: newText.length - textLengthDelta * -1
|
|
289
|
-
};
|
|
290
|
-
return [...actions, raise({
|
|
291
|
-
type: "select",
|
|
292
|
-
at: {
|
|
293
|
-
anchor: endCaretPosition,
|
|
294
|
-
focus: endCaretPosition
|
|
295
|
-
}
|
|
296
|
-
})];
|
|
297
|
-
}]
|
|
298
|
-
});
|
|
171
|
+
return defineInputRule({
|
|
172
|
+
on: /\[(?<text>[^[\]]+)]\((?<href>.+)\)/,
|
|
173
|
+
inlineObjects: { allow: ["text"] },
|
|
174
|
+
actions: [({ snapshot, event }) => {
|
|
175
|
+
let newText = event.textBefore + event.textInserted, textLengthDelta = 0, actions = [];
|
|
176
|
+
for (let match of event.matches.reverse()) {
|
|
177
|
+
let textMatch = match.groups.text, hrefMatch = match.groups.href;
|
|
178
|
+
if (textMatch === void 0 || hrefMatch === void 0) continue;
|
|
179
|
+
textLengthDelta -= match.targetOffsets.focus.offset - match.targetOffsets.anchor.offset - textMatch.text.length;
|
|
180
|
+
let linkObject = config.linkObject({
|
|
181
|
+
context: {
|
|
182
|
+
schema: getPathSubSchema(snapshot, event.focusBlock.path),
|
|
183
|
+
keyGenerator: snapshot.context.keyGenerator
|
|
184
|
+
},
|
|
185
|
+
props: { href: hrefMatch.text }
|
|
186
|
+
});
|
|
187
|
+
if (!linkObject) continue;
|
|
188
|
+
let { _type, _key, ...value } = linkObject, leftSideOffsets = {
|
|
189
|
+
anchor: match.targetOffsets.anchor,
|
|
190
|
+
focus: textMatch.targetOffsets.anchor
|
|
191
|
+
}, rightSideOffsets = {
|
|
192
|
+
anchor: textMatch.targetOffsets.focus,
|
|
193
|
+
focus: match.targetOffsets.focus
|
|
194
|
+
};
|
|
195
|
+
actions.push(raise({
|
|
196
|
+
type: "select",
|
|
197
|
+
at: textMatch.targetOffsets
|
|
198
|
+
})), actions.push(raise({
|
|
199
|
+
type: "annotation.add",
|
|
200
|
+
annotation: {
|
|
201
|
+
name: _type,
|
|
202
|
+
_key,
|
|
203
|
+
value
|
|
204
|
+
}
|
|
205
|
+
})), actions.push(raise({
|
|
206
|
+
type: "delete",
|
|
207
|
+
at: rightSideOffsets
|
|
208
|
+
})), actions.push(raise({
|
|
209
|
+
type: "delete",
|
|
210
|
+
at: leftSideOffsets
|
|
211
|
+
}));
|
|
212
|
+
}
|
|
213
|
+
if (actions.length === 0) return [];
|
|
214
|
+
let endCaretPosition = {
|
|
215
|
+
path: event.focusBlock.path,
|
|
216
|
+
offset: newText.length - textLengthDelta * -1
|
|
217
|
+
};
|
|
218
|
+
return [...actions, raise({
|
|
219
|
+
type: "select",
|
|
220
|
+
at: {
|
|
221
|
+
anchor: endCaretPosition,
|
|
222
|
+
focus: endCaretPosition
|
|
223
|
+
}
|
|
224
|
+
})];
|
|
225
|
+
}]
|
|
226
|
+
});
|
|
299
227
|
}
|
|
300
228
|
function createOrderedListRule(config) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
},
|
|
336
|
-
at: event.focusBlock.path
|
|
337
|
-
}), raise({
|
|
338
|
-
type: "delete",
|
|
339
|
-
at: match.targetOffsets
|
|
340
|
-
})]]
|
|
341
|
-
});
|
|
229
|
+
return defineInputRule({
|
|
230
|
+
on: /^1\. /,
|
|
231
|
+
guard: ({ snapshot, event }) => {
|
|
232
|
+
let subSchema = getPathSubSchema(snapshot, event.focusBlock.path), orderedList = config.orderedList({
|
|
233
|
+
context: { schema: subSchema },
|
|
234
|
+
schema: subSchema
|
|
235
|
+
});
|
|
236
|
+
if (!orderedList || getPreviousInlineObject(snapshot)) return !1;
|
|
237
|
+
let match = event.matches.at(0);
|
|
238
|
+
return match ? {
|
|
239
|
+
match,
|
|
240
|
+
orderedList
|
|
241
|
+
} : !1;
|
|
242
|
+
},
|
|
243
|
+
actions: [({ event }, { match, orderedList }) => [
|
|
244
|
+
raise({
|
|
245
|
+
type: "block.unset",
|
|
246
|
+
props: ["style"],
|
|
247
|
+
at: event.focusBlock.path
|
|
248
|
+
}),
|
|
249
|
+
raise({
|
|
250
|
+
type: "block.set",
|
|
251
|
+
props: {
|
|
252
|
+
listItem: orderedList,
|
|
253
|
+
level: event.focusBlock.node.level ?? 1
|
|
254
|
+
},
|
|
255
|
+
at: event.focusBlock.path
|
|
256
|
+
}),
|
|
257
|
+
raise({
|
|
258
|
+
type: "delete",
|
|
259
|
+
at: match.targetOffsets
|
|
260
|
+
})
|
|
261
|
+
]]
|
|
262
|
+
});
|
|
342
263
|
}
|
|
343
264
|
function createUnorderedListRule(config) {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
},
|
|
379
|
-
at: event.focusBlock.path
|
|
380
|
-
}), raise({
|
|
381
|
-
type: "delete",
|
|
382
|
-
at: match.targetOffsets
|
|
383
|
-
})]]
|
|
384
|
-
});
|
|
265
|
+
return defineInputRule({
|
|
266
|
+
on: /^(-|\*) /,
|
|
267
|
+
guard: ({ snapshot, event }) => {
|
|
268
|
+
let subSchema = getPathSubSchema(snapshot, event.focusBlock.path), unorderedList = config.unorderedList({
|
|
269
|
+
context: { schema: subSchema },
|
|
270
|
+
schema: subSchema
|
|
271
|
+
});
|
|
272
|
+
if (!unorderedList || getPreviousInlineObject(snapshot)) return !1;
|
|
273
|
+
let match = event.matches.at(0);
|
|
274
|
+
return match ? {
|
|
275
|
+
match,
|
|
276
|
+
unorderedList
|
|
277
|
+
} : !1;
|
|
278
|
+
},
|
|
279
|
+
actions: [({ event }, { match, unorderedList }) => [
|
|
280
|
+
raise({
|
|
281
|
+
type: "block.unset",
|
|
282
|
+
props: ["style"],
|
|
283
|
+
at: event.focusBlock.path
|
|
284
|
+
}),
|
|
285
|
+
raise({
|
|
286
|
+
type: "block.set",
|
|
287
|
+
props: {
|
|
288
|
+
listItem: unorderedList,
|
|
289
|
+
level: event.focusBlock.node.level ?? 1
|
|
290
|
+
},
|
|
291
|
+
at: event.focusBlock.path
|
|
292
|
+
}),
|
|
293
|
+
raise({
|
|
294
|
+
type: "delete",
|
|
295
|
+
at: match.targetOffsets
|
|
296
|
+
})
|
|
297
|
+
]]
|
|
298
|
+
});
|
|
385
299
|
}
|
|
300
|
+
/**
|
|
301
|
+
* @public
|
|
302
|
+
*/
|
|
386
303
|
function MarkdownShortcutsPlugin(t0) {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
/* @__PURE__ */ jsx(CharacterPairDecoratorPlugin, { decorator: italicDecorator, pair: {
|
|
477
|
-
char: "_",
|
|
478
|
-
amount: 1
|
|
479
|
-
} })
|
|
480
|
-
] }) : null, $[27] = italicDecorator, $[28] = t5) : t5 = $[28];
|
|
481
|
-
let t6;
|
|
482
|
-
$[29] !== strikeThroughDecorator ? (t6 = strikeThroughDecorator ? /* @__PURE__ */ jsx(CharacterPairDecoratorPlugin, { decorator: strikeThroughDecorator, pair: {
|
|
483
|
-
char: "~",
|
|
484
|
-
amount: 2
|
|
485
|
-
} }) : null, $[29] = strikeThroughDecorator, $[30] = t6) : t6 = $[30];
|
|
486
|
-
let t7;
|
|
487
|
-
$[31] !== inputRules ? (t7 = inputRules ? /* @__PURE__ */ jsx(InputRulePlugin, { rules: inputRules }) : null, $[31] = inputRules, $[32] = t7) : t7 = $[32];
|
|
488
|
-
let t8;
|
|
489
|
-
return $[33] !== t3 || $[34] !== t4 || $[35] !== t5 || $[36] !== t6 || $[37] !== t7 ? (t8 = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
490
|
-
t3,
|
|
491
|
-
t4,
|
|
492
|
-
t5,
|
|
493
|
-
t6,
|
|
494
|
-
t7
|
|
495
|
-
] }), $[33] = t3, $[34] = t4, $[35] = t5, $[36] = t6, $[37] = t7, $[38] = t8) : t8 = $[38], t8;
|
|
304
|
+
let $ = c(39), { blockquoteStyle, boldDecorator, codeDecorator, defaultStyle, headingStyle, horizontalRuleObject, linkObject, italicDecorator, orderedList, strikeThroughDecorator, unorderedList } = t0, editor = useEditor(), t1, t2;
|
|
305
|
+
$[0] !== defaultStyle || $[1] !== editor ? (t1 = () => {
|
|
306
|
+
let unregisterBehaviors = createMarkdownBehaviors({ defaultStyle }).map((behavior) => editor.registerBehavior({ behavior }));
|
|
307
|
+
return () => {
|
|
308
|
+
for (let unregisterBehavior of unregisterBehaviors) unregisterBehavior();
|
|
309
|
+
};
|
|
310
|
+
}, t2 = [defaultStyle, editor], $[0] = defaultStyle, $[1] = editor, $[2] = t1, $[3] = t2) : (t1 = $[2], t2 = $[3]), useEffect(t1, t2);
|
|
311
|
+
let rules;
|
|
312
|
+
if ($[4] !== blockquoteStyle || $[5] !== headingStyle || $[6] !== horizontalRuleObject || $[7] !== linkObject || $[8] !== orderedList || $[9] !== unorderedList) {
|
|
313
|
+
if (rules = [], blockquoteStyle) {
|
|
314
|
+
let t3;
|
|
315
|
+
$[11] === blockquoteStyle ? t3 = $[12] : (t3 = createBlockquoteRule({ blockquoteStyle }), $[11] = blockquoteStyle, $[12] = t3), rules.push(t3);
|
|
316
|
+
}
|
|
317
|
+
if (headingStyle) {
|
|
318
|
+
let t3;
|
|
319
|
+
$[13] === headingStyle ? t3 = $[14] : (t3 = createHeadingRule({ headingStyle }), $[13] = headingStyle, $[14] = t3), rules.push(t3);
|
|
320
|
+
}
|
|
321
|
+
if (horizontalRuleObject) {
|
|
322
|
+
let t3;
|
|
323
|
+
$[15] === horizontalRuleObject ? t3 = $[16] : (t3 = createHorizontalRuleRule({ horizontalRuleObject }), $[15] = horizontalRuleObject, $[16] = t3), rules.push(t3);
|
|
324
|
+
}
|
|
325
|
+
if (linkObject) {
|
|
326
|
+
let t3;
|
|
327
|
+
$[17] === linkObject ? t3 = $[18] : (t3 = createMarkdownLinkRule({ linkObject }), $[17] = linkObject, $[18] = t3), rules.push(t3);
|
|
328
|
+
}
|
|
329
|
+
if (orderedList) {
|
|
330
|
+
let t3;
|
|
331
|
+
$[19] === orderedList ? t3 = $[20] : (t3 = createOrderedListRule({ orderedList }), $[19] = orderedList, $[20] = t3), rules.push(t3);
|
|
332
|
+
}
|
|
333
|
+
if (unorderedList) {
|
|
334
|
+
let t3;
|
|
335
|
+
$[21] === unorderedList ? t3 = $[22] : (t3 = createUnorderedListRule({ unorderedList }), $[21] = unorderedList, $[22] = t3), rules.push(t3);
|
|
336
|
+
}
|
|
337
|
+
$[4] = blockquoteStyle, $[5] = headingStyle, $[6] = horizontalRuleObject, $[7] = linkObject, $[8] = orderedList, $[9] = unorderedList, $[10] = rules;
|
|
338
|
+
} else rules = $[10];
|
|
339
|
+
let inputRules = rules.length > 0 ? rules : null, t3;
|
|
340
|
+
$[23] === boldDecorator ? t3 = $[24] : (t3 = boldDecorator ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(CharacterPairDecoratorPlugin, {
|
|
341
|
+
decorator: boldDecorator,
|
|
342
|
+
pair: {
|
|
343
|
+
char: "*",
|
|
344
|
+
amount: 2
|
|
345
|
+
}
|
|
346
|
+
}), /* @__PURE__ */ jsx(CharacterPairDecoratorPlugin, {
|
|
347
|
+
decorator: boldDecorator,
|
|
348
|
+
pair: {
|
|
349
|
+
char: "_",
|
|
350
|
+
amount: 2
|
|
351
|
+
}
|
|
352
|
+
})] }) : null, $[23] = boldDecorator, $[24] = t3);
|
|
353
|
+
let t4;
|
|
354
|
+
$[25] === codeDecorator ? t4 = $[26] : (t4 = codeDecorator ? /* @__PURE__ */ jsx(CharacterPairDecoratorPlugin, {
|
|
355
|
+
decorator: codeDecorator,
|
|
356
|
+
pair: {
|
|
357
|
+
char: "`",
|
|
358
|
+
amount: 1
|
|
359
|
+
}
|
|
360
|
+
}) : null, $[25] = codeDecorator, $[26] = t4);
|
|
361
|
+
let t5;
|
|
362
|
+
$[27] === italicDecorator ? t5 = $[28] : (t5 = italicDecorator ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(CharacterPairDecoratorPlugin, {
|
|
363
|
+
decorator: italicDecorator,
|
|
364
|
+
pair: {
|
|
365
|
+
char: "*",
|
|
366
|
+
amount: 1
|
|
367
|
+
}
|
|
368
|
+
}), /* @__PURE__ */ jsx(CharacterPairDecoratorPlugin, {
|
|
369
|
+
decorator: italicDecorator,
|
|
370
|
+
pair: {
|
|
371
|
+
char: "_",
|
|
372
|
+
amount: 1
|
|
373
|
+
}
|
|
374
|
+
})] }) : null, $[27] = italicDecorator, $[28] = t5);
|
|
375
|
+
let t6;
|
|
376
|
+
$[29] === strikeThroughDecorator ? t6 = $[30] : (t6 = strikeThroughDecorator ? /* @__PURE__ */ jsx(CharacterPairDecoratorPlugin, {
|
|
377
|
+
decorator: strikeThroughDecorator,
|
|
378
|
+
pair: {
|
|
379
|
+
char: "~",
|
|
380
|
+
amount: 2
|
|
381
|
+
}
|
|
382
|
+
}) : null, $[29] = strikeThroughDecorator, $[30] = t6);
|
|
383
|
+
let t7;
|
|
384
|
+
$[31] === inputRules ? t7 = $[32] : (t7 = inputRules ? /* @__PURE__ */ jsx(InputRulePlugin, { rules: inputRules }) : null, $[31] = inputRules, $[32] = t7);
|
|
385
|
+
let t8;
|
|
386
|
+
return $[33] !== t3 || $[34] !== t4 || $[35] !== t5 || $[36] !== t6 || $[37] !== t7 ? (t8 = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
387
|
+
t3,
|
|
388
|
+
t4,
|
|
389
|
+
t5,
|
|
390
|
+
t6,
|
|
391
|
+
t7
|
|
392
|
+
] }), $[33] = t3, $[34] = t4, $[35] = t5, $[36] = t6, $[37] = t7, $[38] = t8) : t8 = $[38], t8;
|
|
496
393
|
}
|
|
497
|
-
export {
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
//# sourceMappingURL=index.js.map
|
|
394
|
+
export { MarkdownShortcutsPlugin };
|
|
395
|
+
|
|
396
|
+
//# sourceMappingURL=index.js.map
|