@portabletext/plugin-markdown-shortcuts 1.0.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/LICENSE +21 -0
- package/README.md +82 -0
- package/dist/index.cjs +392 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +44 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +382 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -0
- package/src/behavior.markdown-shortcuts.ts +486 -0
- package/src/index.ts +1 -0
- package/src/plugin.markdown-shortcuts.tsx +84 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEditor } from "@portabletext/editor";
|
|
3
|
+
import { CharacterPairDecoratorPlugin } from "@portabletext/plugin-character-pair-decorator";
|
|
4
|
+
import { useEffect } from "react";
|
|
5
|
+
import { defineBehavior, execute } from "@portabletext/editor/behaviors";
|
|
6
|
+
import * as selectors from "@portabletext/editor/selectors";
|
|
7
|
+
import * as utils from "@portabletext/editor/utils";
|
|
8
|
+
function createMarkdownBehaviors(config) {
|
|
9
|
+
const automaticBlockquoteOnSpace = defineBehavior({
|
|
10
|
+
on: "insert.text",
|
|
11
|
+
guard: ({ snapshot, event }) => {
|
|
12
|
+
if (event.text !== " ")
|
|
13
|
+
return !1;
|
|
14
|
+
const selectionCollapsed = selectors.isSelectionCollapsed(snapshot), focusTextBlock = selectors.getFocusTextBlock(snapshot), focusSpan = selectors.getFocusSpan(snapshot);
|
|
15
|
+
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
16
|
+
return !1;
|
|
17
|
+
const previousInlineObject = selectors.getPreviousInlineObject(snapshot), blockOffset = utils.spanSelectionPointToBlockOffset({
|
|
18
|
+
value: snapshot.context.value,
|
|
19
|
+
selectionPoint: {
|
|
20
|
+
path: [
|
|
21
|
+
{ _key: focusTextBlock.node._key },
|
|
22
|
+
"children",
|
|
23
|
+
{ _key: focusSpan.node._key }
|
|
24
|
+
],
|
|
25
|
+
offset: snapshot.context.selection?.focus.offset ?? 0
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
if (previousInlineObject || !blockOffset)
|
|
29
|
+
return !1;
|
|
30
|
+
const blockText = utils.getTextBlockText(focusTextBlock.node), caretAtTheEndOfQuote = blockOffset.offset === 1, looksLikeMarkdownQuote = /^>/.test(blockText), blockquoteStyle = config.blockquoteStyle?.({
|
|
31
|
+
schema: snapshot.context.schema
|
|
32
|
+
});
|
|
33
|
+
return caretAtTheEndOfQuote && looksLikeMarkdownQuote && blockquoteStyle !== void 0 ? { focusTextBlock, style: blockquoteStyle } : !1;
|
|
34
|
+
},
|
|
35
|
+
actions: [
|
|
36
|
+
() => [
|
|
37
|
+
execute({
|
|
38
|
+
type: "insert.text",
|
|
39
|
+
text: " "
|
|
40
|
+
})
|
|
41
|
+
],
|
|
42
|
+
(_, { focusTextBlock, style }) => [
|
|
43
|
+
execute({
|
|
44
|
+
type: "block.unset",
|
|
45
|
+
props: ["listItem", "level"],
|
|
46
|
+
at: focusTextBlock.path
|
|
47
|
+
}),
|
|
48
|
+
execute({
|
|
49
|
+
type: "block.set",
|
|
50
|
+
props: { style },
|
|
51
|
+
at: focusTextBlock.path
|
|
52
|
+
}),
|
|
53
|
+
execute({
|
|
54
|
+
type: "delete.text",
|
|
55
|
+
at: {
|
|
56
|
+
anchor: {
|
|
57
|
+
path: focusTextBlock.path,
|
|
58
|
+
offset: 0
|
|
59
|
+
},
|
|
60
|
+
focus: {
|
|
61
|
+
path: focusTextBlock.path,
|
|
62
|
+
offset: 2
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
]
|
|
67
|
+
]
|
|
68
|
+
}), automaticHr = defineBehavior({
|
|
69
|
+
on: "insert.text",
|
|
70
|
+
guard: ({ snapshot, event }) => {
|
|
71
|
+
const hrCharacter = event.text === "-" ? "-" : event.text === "*" ? "*" : event.text === "_" ? "_" : void 0;
|
|
72
|
+
if (hrCharacter === void 0)
|
|
73
|
+
return !1;
|
|
74
|
+
const hrObject = config.horizontalRuleObject?.({
|
|
75
|
+
schema: snapshot.context.schema
|
|
76
|
+
}), focusBlock = selectors.getFocusTextBlock(snapshot), selectionCollapsed = selectors.isSelectionCollapsed(snapshot);
|
|
77
|
+
if (!hrObject || !focusBlock || !selectionCollapsed)
|
|
78
|
+
return !1;
|
|
79
|
+
const previousInlineObject = selectors.getPreviousInlineObject(snapshot), textBefore = selectors.getBlockTextBefore(snapshot), hrBlockOffsets = {
|
|
80
|
+
anchor: {
|
|
81
|
+
path: focusBlock.path,
|
|
82
|
+
offset: 0
|
|
83
|
+
},
|
|
84
|
+
focus: {
|
|
85
|
+
path: focusBlock.path,
|
|
86
|
+
offset: 3
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
return !previousInlineObject && textBefore === `${hrCharacter}${hrCharacter}` ? { hrObject, focusBlock, hrCharacter, hrBlockOffsets } : !1;
|
|
90
|
+
},
|
|
91
|
+
actions: [
|
|
92
|
+
(_, { hrCharacter }) => [
|
|
93
|
+
execute({
|
|
94
|
+
type: "insert.text",
|
|
95
|
+
text: hrCharacter
|
|
96
|
+
})
|
|
97
|
+
],
|
|
98
|
+
(_, { hrObject, hrBlockOffsets }) => [
|
|
99
|
+
execute({
|
|
100
|
+
type: "insert.block",
|
|
101
|
+
block: {
|
|
102
|
+
_type: hrObject.name,
|
|
103
|
+
...hrObject.value ?? {}
|
|
104
|
+
},
|
|
105
|
+
placement: "before",
|
|
106
|
+
select: "none"
|
|
107
|
+
}),
|
|
108
|
+
execute({
|
|
109
|
+
type: "delete.text",
|
|
110
|
+
at: hrBlockOffsets
|
|
111
|
+
})
|
|
112
|
+
]
|
|
113
|
+
]
|
|
114
|
+
}), automaticHrOnPaste = defineBehavior({
|
|
115
|
+
on: "clipboard.paste",
|
|
116
|
+
guard: ({ snapshot, event }) => {
|
|
117
|
+
const text = event.originEvent.dataTransfer.getData("text/plain"), hrRegExp = /^(---)$|(___)$|(\*\*\*)$/, hrCharacters = text.match(hrRegExp)?.[0], hrObject = config.horizontalRuleObject?.({
|
|
118
|
+
schema: snapshot.context.schema
|
|
119
|
+
}), focusBlock = selectors.getFocusBlock(snapshot), focusTextBlock = selectors.getFocusTextBlock(snapshot);
|
|
120
|
+
return !hrCharacters || !hrObject || !focusBlock ? !1 : { hrCharacters, hrObject, focusBlock, focusTextBlock };
|
|
121
|
+
},
|
|
122
|
+
actions: [
|
|
123
|
+
(_, { hrCharacters }) => [
|
|
124
|
+
execute({
|
|
125
|
+
type: "insert.text",
|
|
126
|
+
text: hrCharacters
|
|
127
|
+
})
|
|
128
|
+
],
|
|
129
|
+
({ snapshot }, { hrObject, focusBlock, focusTextBlock }) => focusTextBlock ? [
|
|
130
|
+
execute({
|
|
131
|
+
type: "insert.block",
|
|
132
|
+
block: {
|
|
133
|
+
_type: snapshot.context.schema.block.name,
|
|
134
|
+
children: focusTextBlock.node.children
|
|
135
|
+
},
|
|
136
|
+
placement: "after"
|
|
137
|
+
}),
|
|
138
|
+
execute({
|
|
139
|
+
type: "insert.block",
|
|
140
|
+
block: {
|
|
141
|
+
_type: hrObject.name,
|
|
142
|
+
...hrObject.value ?? {}
|
|
143
|
+
},
|
|
144
|
+
placement: "after"
|
|
145
|
+
}),
|
|
146
|
+
execute({
|
|
147
|
+
type: "delete.block",
|
|
148
|
+
at: focusBlock.path
|
|
149
|
+
})
|
|
150
|
+
] : [
|
|
151
|
+
execute({
|
|
152
|
+
type: "insert.block",
|
|
153
|
+
block: {
|
|
154
|
+
_type: hrObject.name,
|
|
155
|
+
...hrObject.value ?? {}
|
|
156
|
+
},
|
|
157
|
+
placement: "after"
|
|
158
|
+
})
|
|
159
|
+
]
|
|
160
|
+
]
|
|
161
|
+
}), automaticHeadingOnSpace = defineBehavior({
|
|
162
|
+
on: "insert.text",
|
|
163
|
+
guard: ({ snapshot, event }) => {
|
|
164
|
+
if (event.text !== " ")
|
|
165
|
+
return !1;
|
|
166
|
+
const selectionCollapsed = selectors.isSelectionCollapsed(snapshot), focusTextBlock = selectors.getFocusTextBlock(snapshot), focusSpan = selectors.getFocusSpan(snapshot);
|
|
167
|
+
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
168
|
+
return !1;
|
|
169
|
+
const blockOffset = utils.spanSelectionPointToBlockOffset({
|
|
170
|
+
value: snapshot.context.value,
|
|
171
|
+
selectionPoint: {
|
|
172
|
+
path: [
|
|
173
|
+
{ _key: focusTextBlock.node._key },
|
|
174
|
+
"children",
|
|
175
|
+
{ _key: focusSpan.node._key }
|
|
176
|
+
],
|
|
177
|
+
offset: snapshot.context.selection?.focus.offset ?? 0
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
if (!blockOffset)
|
|
181
|
+
return !1;
|
|
182
|
+
const previousInlineObject = selectors.getPreviousInlineObject(snapshot), blockText = utils.getTextBlockText(focusTextBlock.node), markdownHeadingSearch = /^#+/.exec(blockText), level = markdownHeadingSearch ? markdownHeadingSearch[0].length : void 0, caretAtTheEndOfHeading = blockOffset.offset === level;
|
|
183
|
+
if (previousInlineObject || !caretAtTheEndOfHeading)
|
|
184
|
+
return !1;
|
|
185
|
+
const style = level !== void 0 ? config.headingStyle?.({ schema: snapshot.context.schema, level }) : void 0;
|
|
186
|
+
return level !== void 0 && style !== void 0 ? {
|
|
187
|
+
focusTextBlock,
|
|
188
|
+
style,
|
|
189
|
+
level
|
|
190
|
+
} : !1;
|
|
191
|
+
},
|
|
192
|
+
actions: [
|
|
193
|
+
({ event }) => [execute(event)],
|
|
194
|
+
(_, { focusTextBlock, style, level }) => [
|
|
195
|
+
execute({
|
|
196
|
+
type: "block.unset",
|
|
197
|
+
props: ["listItem", "level"],
|
|
198
|
+
at: focusTextBlock.path
|
|
199
|
+
}),
|
|
200
|
+
execute({
|
|
201
|
+
type: "block.set",
|
|
202
|
+
props: { style },
|
|
203
|
+
at: focusTextBlock.path
|
|
204
|
+
}),
|
|
205
|
+
execute({
|
|
206
|
+
type: "delete.text",
|
|
207
|
+
at: {
|
|
208
|
+
anchor: {
|
|
209
|
+
path: focusTextBlock.path,
|
|
210
|
+
offset: 0
|
|
211
|
+
},
|
|
212
|
+
focus: {
|
|
213
|
+
path: focusTextBlock.path,
|
|
214
|
+
offset: level + 1
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
})
|
|
218
|
+
]
|
|
219
|
+
]
|
|
220
|
+
}), clearStyleOnBackspace = defineBehavior({
|
|
221
|
+
on: "delete.backward",
|
|
222
|
+
guard: ({ snapshot }) => {
|
|
223
|
+
const selectionCollapsed = selectors.isSelectionCollapsed(snapshot), focusTextBlock = selectors.getFocusTextBlock(snapshot), focusSpan = selectors.getFocusSpan(snapshot);
|
|
224
|
+
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
225
|
+
return !1;
|
|
226
|
+
const atTheBeginningOfBLock = focusTextBlock.node.children[0]._key === focusSpan.node._key && snapshot.context.selection?.focus.offset === 0, defaultStyle = config.defaultStyle?.({
|
|
227
|
+
schema: snapshot.context.schema
|
|
228
|
+
});
|
|
229
|
+
return atTheBeginningOfBLock && defaultStyle && focusTextBlock.node.style !== defaultStyle ? { defaultStyle, focusTextBlock } : !1;
|
|
230
|
+
},
|
|
231
|
+
actions: [
|
|
232
|
+
(_, { defaultStyle, focusTextBlock }) => [
|
|
233
|
+
execute({
|
|
234
|
+
type: "block.set",
|
|
235
|
+
props: { style: defaultStyle },
|
|
236
|
+
at: focusTextBlock.path
|
|
237
|
+
})
|
|
238
|
+
]
|
|
239
|
+
]
|
|
240
|
+
}), automaticListOnSpace = defineBehavior({
|
|
241
|
+
on: "insert.text",
|
|
242
|
+
guard: ({ snapshot, event }) => {
|
|
243
|
+
if (event.text !== " ")
|
|
244
|
+
return !1;
|
|
245
|
+
const selectionCollapsed = selectors.isSelectionCollapsed(snapshot), focusTextBlock = selectors.getFocusTextBlock(snapshot), focusSpan = selectors.getFocusSpan(snapshot);
|
|
246
|
+
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
247
|
+
return !1;
|
|
248
|
+
const previousInlineObject = selectors.getPreviousInlineObject(snapshot), blockOffset = utils.spanSelectionPointToBlockOffset({
|
|
249
|
+
value: snapshot.context.value,
|
|
250
|
+
selectionPoint: {
|
|
251
|
+
path: [
|
|
252
|
+
{ _key: focusTextBlock.node._key },
|
|
253
|
+
"children",
|
|
254
|
+
{ _key: focusSpan.node._key }
|
|
255
|
+
],
|
|
256
|
+
offset: snapshot.context.selection?.focus.offset ?? 0
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
if (previousInlineObject || !blockOffset)
|
|
260
|
+
return !1;
|
|
261
|
+
const blockText = utils.getTextBlockText(focusTextBlock.node), defaultStyle = config.defaultStyle?.({
|
|
262
|
+
schema: snapshot.context.schema
|
|
263
|
+
}), looksLikeUnorderedList = /^(-|\*)/.test(blockText), unorderedList = config.unorderedList?.({
|
|
264
|
+
schema: snapshot.context.schema
|
|
265
|
+
}), caretAtTheEndOfUnorderedList = blockOffset.offset === 1;
|
|
266
|
+
if (defaultStyle && caretAtTheEndOfUnorderedList && looksLikeUnorderedList && unorderedList !== void 0)
|
|
267
|
+
return {
|
|
268
|
+
focusTextBlock,
|
|
269
|
+
listItem: unorderedList,
|
|
270
|
+
listItemLength: 1,
|
|
271
|
+
style: defaultStyle
|
|
272
|
+
};
|
|
273
|
+
const looksLikeOrderedList = /^1\./.test(blockText), orderedList = config.orderedList?.({
|
|
274
|
+
schema: snapshot.context.schema
|
|
275
|
+
}), caretAtTheEndOfOrderedList = blockOffset.offset === 2;
|
|
276
|
+
return defaultStyle && caretAtTheEndOfOrderedList && looksLikeOrderedList && orderedList !== void 0 ? {
|
|
277
|
+
focusTextBlock,
|
|
278
|
+
listItem: orderedList,
|
|
279
|
+
listItemLength: 2,
|
|
280
|
+
style: defaultStyle
|
|
281
|
+
} : !1;
|
|
282
|
+
},
|
|
283
|
+
actions: [
|
|
284
|
+
({ event }) => [execute(event)],
|
|
285
|
+
(_, { focusTextBlock, style, listItem, listItemLength }) => [
|
|
286
|
+
execute({
|
|
287
|
+
type: "block.set",
|
|
288
|
+
props: {
|
|
289
|
+
listItem,
|
|
290
|
+
level: 1,
|
|
291
|
+
style
|
|
292
|
+
},
|
|
293
|
+
at: focusTextBlock.path
|
|
294
|
+
}),
|
|
295
|
+
execute({
|
|
296
|
+
type: "delete.text",
|
|
297
|
+
at: {
|
|
298
|
+
anchor: {
|
|
299
|
+
path: focusTextBlock.path,
|
|
300
|
+
offset: 0
|
|
301
|
+
},
|
|
302
|
+
focus: {
|
|
303
|
+
path: focusTextBlock.path,
|
|
304
|
+
offset: listItemLength + 1
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
})
|
|
308
|
+
]
|
|
309
|
+
]
|
|
310
|
+
});
|
|
311
|
+
return [
|
|
312
|
+
automaticBlockquoteOnSpace,
|
|
313
|
+
automaticHeadingOnSpace,
|
|
314
|
+
automaticHr,
|
|
315
|
+
automaticHrOnPaste,
|
|
316
|
+
clearStyleOnBackspace,
|
|
317
|
+
automaticListOnSpace
|
|
318
|
+
];
|
|
319
|
+
}
|
|
320
|
+
function MarkdownShortcutsPlugin(props) {
|
|
321
|
+
const editor = useEditor();
|
|
322
|
+
return useEffect(() => {
|
|
323
|
+
const unregisterBehaviors = createMarkdownBehaviors(props).map(
|
|
324
|
+
(behavior) => editor.registerBehavior({ behavior })
|
|
325
|
+
);
|
|
326
|
+
return () => {
|
|
327
|
+
for (const unregisterBehavior of unregisterBehaviors)
|
|
328
|
+
unregisterBehavior();
|
|
329
|
+
};
|
|
330
|
+
}, [editor, props]), /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
331
|
+
props.boldDecorator ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
332
|
+
/* @__PURE__ */ jsx(
|
|
333
|
+
CharacterPairDecoratorPlugin,
|
|
334
|
+
{
|
|
335
|
+
decorator: props.boldDecorator,
|
|
336
|
+
pair: { char: "*", amount: 2 }
|
|
337
|
+
}
|
|
338
|
+
),
|
|
339
|
+
/* @__PURE__ */ jsx(
|
|
340
|
+
CharacterPairDecoratorPlugin,
|
|
341
|
+
{
|
|
342
|
+
decorator: props.boldDecorator,
|
|
343
|
+
pair: { char: "_", amount: 2 }
|
|
344
|
+
}
|
|
345
|
+
)
|
|
346
|
+
] }) : null,
|
|
347
|
+
props.codeDecorator ? /* @__PURE__ */ jsx(
|
|
348
|
+
CharacterPairDecoratorPlugin,
|
|
349
|
+
{
|
|
350
|
+
decorator: props.codeDecorator,
|
|
351
|
+
pair: { char: "`", amount: 1 }
|
|
352
|
+
}
|
|
353
|
+
) : null,
|
|
354
|
+
props.italicDecorator ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
355
|
+
/* @__PURE__ */ jsx(
|
|
356
|
+
CharacterPairDecoratorPlugin,
|
|
357
|
+
{
|
|
358
|
+
decorator: props.italicDecorator,
|
|
359
|
+
pair: { char: "*", amount: 1 }
|
|
360
|
+
}
|
|
361
|
+
),
|
|
362
|
+
/* @__PURE__ */ jsx(
|
|
363
|
+
CharacterPairDecoratorPlugin,
|
|
364
|
+
{
|
|
365
|
+
decorator: props.italicDecorator,
|
|
366
|
+
pair: { char: "_", amount: 1 }
|
|
367
|
+
}
|
|
368
|
+
)
|
|
369
|
+
] }) : null,
|
|
370
|
+
props.strikeThroughDecorator ? /* @__PURE__ */ jsx(
|
|
371
|
+
CharacterPairDecoratorPlugin,
|
|
372
|
+
{
|
|
373
|
+
decorator: props.strikeThroughDecorator,
|
|
374
|
+
pair: { char: "~", amount: 2 }
|
|
375
|
+
}
|
|
376
|
+
) : null
|
|
377
|
+
] });
|
|
378
|
+
}
|
|
379
|
+
export {
|
|
380
|
+
MarkdownShortcutsPlugin
|
|
381
|
+
};
|
|
382
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/behavior.markdown-shortcuts.ts","../src/plugin.markdown-shortcuts.tsx"],"sourcesContent":["import type {EditorSchema} from '@portabletext/editor'\nimport {defineBehavior, execute} from '@portabletext/editor/behaviors'\nimport * as selectors from '@portabletext/editor/selectors'\nimport * as utils from '@portabletext/editor/utils'\n\nexport type MarkdownBehaviorsConfig = {\n horizontalRuleObject?: (context: {\n schema: EditorSchema\n }) => {name: string; value?: {[prop: string]: unknown}} | undefined\n defaultStyle?: (context: {schema: EditorSchema}) => string | undefined\n headingStyle?: (context: {\n schema: EditorSchema\n level: number\n }) => string | undefined\n blockquoteStyle?: (context: {schema: EditorSchema}) => string | undefined\n unorderedList?: (context: {schema: EditorSchema}) => string | undefined\n orderedList?: (context: {schema: EditorSchema}) => string | undefined\n}\n\nexport function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {\n const automaticBlockquoteOnSpace = defineBehavior({\n on: 'insert.text',\n guard: ({snapshot, event}) => {\n const isSpace = event.text === ' '\n\n if (!isSpace) {\n return false\n }\n\n const selectionCollapsed = selectors.isSelectionCollapsed(snapshot)\n const focusTextBlock = selectors.getFocusTextBlock(snapshot)\n const focusSpan = selectors.getFocusSpan(snapshot)\n\n if (!selectionCollapsed || !focusTextBlock || !focusSpan) {\n return false\n }\n\n const previousInlineObject = selectors.getPreviousInlineObject(snapshot)\n const blockOffset = utils.spanSelectionPointToBlockOffset({\n value: snapshot.context.value,\n selectionPoint: {\n path: [\n {_key: focusTextBlock.node._key},\n 'children',\n {_key: focusSpan.node._key},\n ],\n offset: snapshot.context.selection?.focus.offset ?? 0,\n },\n })\n\n if (previousInlineObject || !blockOffset) {\n return false\n }\n\n const blockText = utils.getTextBlockText(focusTextBlock.node)\n const caretAtTheEndOfQuote = blockOffset.offset === 1\n const looksLikeMarkdownQuote = /^>/.test(blockText)\n const blockquoteStyle = config.blockquoteStyle?.({\n schema: snapshot.context.schema,\n })\n\n if (\n caretAtTheEndOfQuote &&\n looksLikeMarkdownQuote &&\n blockquoteStyle !== undefined\n ) {\n return {focusTextBlock, style: blockquoteStyle}\n }\n\n return false\n },\n actions: [\n () => [\n execute({\n type: 'insert.text',\n text: ' ',\n }),\n ],\n (_, {focusTextBlock, style}) => [\n execute({\n type: 'block.unset',\n props: ['listItem', 'level'],\n at: focusTextBlock.path,\n }),\n execute({\n type: 'block.set',\n props: {style},\n at: focusTextBlock.path,\n }),\n execute({\n type: 'delete.text',\n at: {\n anchor: {\n path: focusTextBlock.path,\n offset: 0,\n },\n focus: {\n path: focusTextBlock.path,\n offset: 2,\n },\n },\n }),\n ],\n ],\n })\n const automaticHr = defineBehavior({\n on: 'insert.text',\n guard: ({snapshot, event}) => {\n const hrCharacter =\n event.text === '-'\n ? '-'\n : event.text === '*'\n ? '*'\n : event.text === '_'\n ? '_'\n : undefined\n\n if (hrCharacter === undefined) {\n return false\n }\n\n const hrObject = config.horizontalRuleObject?.({\n schema: snapshot.context.schema,\n })\n const focusBlock = selectors.getFocusTextBlock(snapshot)\n const selectionCollapsed = selectors.isSelectionCollapsed(snapshot)\n\n if (!hrObject || !focusBlock || !selectionCollapsed) {\n return false\n }\n\n const previousInlineObject = selectors.getPreviousInlineObject(snapshot)\n const textBefore = selectors.getBlockTextBefore(snapshot)\n const hrBlockOffsets = {\n anchor: {\n path: focusBlock.path,\n offset: 0,\n },\n focus: {\n path: focusBlock.path,\n offset: 3,\n },\n }\n\n if (\n !previousInlineObject &&\n textBefore === `${hrCharacter}${hrCharacter}`\n ) {\n return {hrObject, focusBlock, hrCharacter, hrBlockOffsets}\n }\n\n return false\n },\n actions: [\n (_, {hrCharacter}) => [\n execute({\n type: 'insert.text',\n text: hrCharacter,\n }),\n ],\n (_, {hrObject, hrBlockOffsets}) => [\n execute({\n type: 'insert.block',\n block: {\n _type: hrObject.name,\n ...(hrObject.value ?? {}),\n },\n placement: 'before',\n select: 'none',\n }),\n execute({\n type: 'delete.text',\n at: hrBlockOffsets,\n }),\n ],\n ],\n })\n const automaticHrOnPaste = defineBehavior({\n on: 'clipboard.paste',\n guard: ({snapshot, event}) => {\n const text = event.originEvent.dataTransfer.getData('text/plain')\n const hrRegExp = /^(---)$|(___)$|(\\*\\*\\*)$/\n const hrCharacters = text.match(hrRegExp)?.[0]\n const hrObject = config.horizontalRuleObject?.({\n schema: snapshot.context.schema,\n })\n const focusBlock = selectors.getFocusBlock(snapshot)\n const focusTextBlock = selectors.getFocusTextBlock(snapshot)\n\n if (!hrCharacters || !hrObject || !focusBlock) {\n return false\n }\n\n return {hrCharacters, hrObject, focusBlock, focusTextBlock}\n },\n actions: [\n (_, {hrCharacters}) => [\n execute({\n type: 'insert.text',\n text: hrCharacters,\n }),\n ],\n ({snapshot}, {hrObject, focusBlock, focusTextBlock}) =>\n focusTextBlock\n ? [\n execute({\n type: 'insert.block',\n block: {\n _type: snapshot.context.schema.block.name,\n children: focusTextBlock.node.children,\n },\n placement: 'after',\n }),\n execute({\n type: 'insert.block',\n block: {\n _type: hrObject.name,\n ...(hrObject.value ?? {}),\n },\n placement: 'after',\n }),\n execute({\n type: 'delete.block',\n at: focusBlock.path,\n }),\n ]\n : [\n execute({\n type: 'insert.block',\n block: {\n _type: hrObject.name,\n ...(hrObject.value ?? {}),\n },\n placement: 'after',\n }),\n ],\n ],\n })\n const automaticHeadingOnSpace = defineBehavior({\n on: 'insert.text',\n guard: ({snapshot, event}) => {\n const isSpace = event.text === ' '\n\n if (!isSpace) {\n return false\n }\n\n const selectionCollapsed = selectors.isSelectionCollapsed(snapshot)\n const focusTextBlock = selectors.getFocusTextBlock(snapshot)\n const focusSpan = selectors.getFocusSpan(snapshot)\n\n if (!selectionCollapsed || !focusTextBlock || !focusSpan) {\n return false\n }\n\n const blockOffset = utils.spanSelectionPointToBlockOffset({\n value: snapshot.context.value,\n selectionPoint: {\n path: [\n {_key: focusTextBlock.node._key},\n 'children',\n {_key: focusSpan.node._key},\n ],\n offset: snapshot.context.selection?.focus.offset ?? 0,\n },\n })\n\n if (!blockOffset) {\n return false\n }\n\n const previousInlineObject = selectors.getPreviousInlineObject(snapshot)\n const blockText = utils.getTextBlockText(focusTextBlock.node)\n const markdownHeadingSearch = /^#+/.exec(blockText)\n const level = markdownHeadingSearch\n ? markdownHeadingSearch[0].length\n : undefined\n const caretAtTheEndOfHeading = blockOffset.offset === level\n\n if (previousInlineObject || !caretAtTheEndOfHeading) {\n return false\n }\n\n const style =\n level !== undefined\n ? config.headingStyle?.({schema: snapshot.context.schema, level})\n : undefined\n\n if (level !== undefined && style !== undefined) {\n return {\n focusTextBlock,\n style: style,\n level,\n }\n }\n\n return false\n },\n actions: [\n ({event}) => [execute(event)],\n (_, {focusTextBlock, style, level}) => [\n execute({\n type: 'block.unset',\n props: ['listItem', 'level'],\n at: focusTextBlock.path,\n }),\n execute({\n type: 'block.set',\n props: {style},\n at: focusTextBlock.path,\n }),\n execute({\n type: 'delete.text',\n at: {\n anchor: {\n path: focusTextBlock.path,\n offset: 0,\n },\n focus: {\n path: focusTextBlock.path,\n offset: level + 1,\n },\n },\n }),\n ],\n ],\n })\n const clearStyleOnBackspace = defineBehavior({\n on: 'delete.backward',\n guard: ({snapshot}) => {\n const selectionCollapsed = selectors.isSelectionCollapsed(snapshot)\n const focusTextBlock = selectors.getFocusTextBlock(snapshot)\n const focusSpan = selectors.getFocusSpan(snapshot)\n\n if (!selectionCollapsed || !focusTextBlock || !focusSpan) {\n return false\n }\n\n const atTheBeginningOfBLock =\n focusTextBlock.node.children[0]._key === focusSpan.node._key &&\n snapshot.context.selection?.focus.offset === 0\n\n const defaultStyle = config.defaultStyle?.({\n schema: snapshot.context.schema,\n })\n\n if (\n atTheBeginningOfBLock &&\n defaultStyle &&\n focusTextBlock.node.style !== defaultStyle\n ) {\n return {defaultStyle, focusTextBlock}\n }\n\n return false\n },\n actions: [\n (_, {defaultStyle, focusTextBlock}) => [\n execute({\n type: 'block.set',\n props: {style: defaultStyle},\n at: focusTextBlock.path,\n }),\n ],\n ],\n })\n const automaticListOnSpace = defineBehavior({\n on: 'insert.text',\n guard: ({snapshot, event}) => {\n const isSpace = event.text === ' '\n\n if (!isSpace) {\n return false\n }\n\n const selectionCollapsed = selectors.isSelectionCollapsed(snapshot)\n const focusTextBlock = selectors.getFocusTextBlock(snapshot)\n const focusSpan = selectors.getFocusSpan(snapshot)\n\n if (!selectionCollapsed || !focusTextBlock || !focusSpan) {\n return false\n }\n\n const previousInlineObject = selectors.getPreviousInlineObject(snapshot)\n const blockOffset = utils.spanSelectionPointToBlockOffset({\n value: snapshot.context.value,\n selectionPoint: {\n path: [\n {_key: focusTextBlock.node._key},\n 'children',\n {_key: focusSpan.node._key},\n ],\n offset: snapshot.context.selection?.focus.offset ?? 0,\n },\n })\n\n if (previousInlineObject || !blockOffset) {\n return false\n }\n\n const blockText = utils.getTextBlockText(focusTextBlock.node)\n const defaultStyle = config.defaultStyle?.({\n schema: snapshot.context.schema,\n })\n const looksLikeUnorderedList = /^(-|\\*)/.test(blockText)\n const unorderedList = config.unorderedList?.({\n schema: snapshot.context.schema,\n })\n const caretAtTheEndOfUnorderedList = blockOffset.offset === 1\n\n if (\n defaultStyle &&\n caretAtTheEndOfUnorderedList &&\n looksLikeUnorderedList &&\n unorderedList !== undefined\n ) {\n return {\n focusTextBlock,\n listItem: unorderedList,\n listItemLength: 1,\n style: defaultStyle,\n }\n }\n\n const looksLikeOrderedList = /^1\\./.test(blockText)\n const orderedList = config.orderedList?.({\n schema: snapshot.context.schema,\n })\n const caretAtTheEndOfOrderedList = blockOffset.offset === 2\n\n if (\n defaultStyle &&\n caretAtTheEndOfOrderedList &&\n looksLikeOrderedList &&\n orderedList !== undefined\n ) {\n return {\n focusTextBlock,\n listItem: orderedList,\n listItemLength: 2,\n style: defaultStyle,\n }\n }\n\n return false\n },\n actions: [\n ({event}) => [execute(event)],\n (_, {focusTextBlock, style, listItem, listItemLength}) => [\n execute({\n type: 'block.set',\n props: {\n listItem,\n level: 1,\n style,\n },\n at: focusTextBlock.path,\n }),\n execute({\n type: 'delete.text',\n at: {\n anchor: {\n path: focusTextBlock.path,\n offset: 0,\n },\n focus: {\n path: focusTextBlock.path,\n offset: listItemLength + 1,\n },\n },\n }),\n ],\n ],\n })\n\n const markdownBehaviors = [\n automaticBlockquoteOnSpace,\n automaticHeadingOnSpace,\n automaticHr,\n automaticHrOnPaste,\n clearStyleOnBackspace,\n automaticListOnSpace,\n ]\n\n return markdownBehaviors\n}\n","import {useEditor} from '@portabletext/editor'\nimport type {EditorSchema} from '@portabletext/editor'\nimport {CharacterPairDecoratorPlugin} from '@portabletext/plugin-character-pair-decorator'\nimport {useEffect} from 'react'\nimport {\n createMarkdownBehaviors,\n type MarkdownBehaviorsConfig,\n} from './behavior.markdown-shortcuts'\n\n/**\n * @beta\n */\nexport type MarkdownShortcutsPluginProps = MarkdownBehaviorsConfig & {\n boldDecorator?: ({schema}: {schema: EditorSchema}) => string | undefined\n codeDecorator?: ({schema}: {schema: EditorSchema}) => string | undefined\n italicDecorator?: ({schema}: {schema: EditorSchema}) => string | undefined\n strikeThroughDecorator?: ({\n schema,\n }: {\n schema: EditorSchema\n }) => string | undefined\n}\n\n/**\n * @beta\n */\nexport function MarkdownShortcutsPlugin(props: MarkdownShortcutsPluginProps) {\n const editor = useEditor()\n\n useEffect(() => {\n const behaviors = createMarkdownBehaviors(props)\n\n const unregisterBehaviors = behaviors.map((behavior) =>\n editor.registerBehavior({behavior}),\n )\n\n return () => {\n for (const unregisterBehavior of unregisterBehaviors) {\n unregisterBehavior()\n }\n }\n }, [editor, props])\n\n return (\n <>\n {props.boldDecorator ? (\n <>\n <CharacterPairDecoratorPlugin\n decorator={props.boldDecorator}\n pair={{char: '*', amount: 2}}\n />\n <CharacterPairDecoratorPlugin\n decorator={props.boldDecorator}\n pair={{char: '_', amount: 2}}\n />\n </>\n ) : null}\n {props.codeDecorator ? (\n <CharacterPairDecoratorPlugin\n decorator={props.codeDecorator}\n pair={{char: '`', amount: 1}}\n />\n ) : null}\n {props.italicDecorator ? (\n <>\n <CharacterPairDecoratorPlugin\n decorator={props.italicDecorator}\n pair={{char: '*', amount: 1}}\n />\n <CharacterPairDecoratorPlugin\n decorator={props.italicDecorator}\n pair={{char: '_', amount: 1}}\n />\n </>\n ) : null}\n {props.strikeThroughDecorator ? (\n <CharacterPairDecoratorPlugin\n decorator={props.strikeThroughDecorator}\n pair={{char: '~', amount: 2}}\n />\n ) : null}\n </>\n )\n}\n"],"names":[],"mappings":";;;;;;;AAmBO,SAAS,wBAAwB,QAAiC;AACvE,QAAM,6BAA6B,eAAe;AAAA,IAChD,IAAI;AAAA,IACJ,OAAO,CAAC,EAAC,UAAU,YAAW;AAGxB,UAFY,MAAM,SAAS;AAGtB,eAAA;AAGT,YAAM,qBAAqB,UAAU,qBAAqB,QAAQ,GAC5D,iBAAiB,UAAU,kBAAkB,QAAQ,GACrD,YAAY,UAAU,aAAa,QAAQ;AAEjD,UAAI,CAAC,sBAAsB,CAAC,kBAAkB,CAAC;AACtC,eAAA;AAGT,YAAM,uBAAuB,UAAU,wBAAwB,QAAQ,GACjE,cAAc,MAAM,gCAAgC;AAAA,QACxD,OAAO,SAAS,QAAQ;AAAA,QACxB,gBAAgB;AAAA,UACd,MAAM;AAAA,YACJ,EAAC,MAAM,eAAe,KAAK,KAAI;AAAA,YAC/B;AAAA,YACA,EAAC,MAAM,UAAU,KAAK,KAAI;AAAA,UAC5B;AAAA,UACA,QAAQ,SAAS,QAAQ,WAAW,MAAM,UAAU;AAAA,QAAA;AAAA,MACtD,CACD;AAED,UAAI,wBAAwB,CAAC;AACpB,eAAA;AAGT,YAAM,YAAY,MAAM,iBAAiB,eAAe,IAAI,GACtD,uBAAuB,YAAY,WAAW,GAC9C,yBAAyB,KAAK,KAAK,SAAS,GAC5C,kBAAkB,OAAO,kBAAkB;AAAA,QAC/C,QAAQ,SAAS,QAAQ;AAAA,MAAA,CAC1B;AAGC,aAAA,wBACA,0BACA,oBAAoB,SAEb,EAAC,gBAAgB,OAAO,oBAG1B;AAAA,IACT;AAAA,IACA,SAAS;AAAA,MACP,MAAM;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AAW,MAAM;AAAA,QACjB,MAAM,EAAC,MAAM,KAAK,QAAQ,EAAC;AAAA,MAAA;AAAA,IAAA,IAE3B;AAAA,EAAA,GACN;AAEJ;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@portabletext/plugin-markdown-shortcuts",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Adds helpful Markdown shortcuts to the editor",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"portabletext",
|
|
7
|
+
"plugin",
|
|
8
|
+
"markdown",
|
|
9
|
+
"shortcuts",
|
|
10
|
+
"behaviors"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://portabletext.org",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/portabletext/plugins/issues"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/portabletext/plugins.git",
|
|
19
|
+
"directory": "plugins/markdown-shortcuts"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"author": "Sanity.io <hello@sanity.io>",
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"type": "module",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"source": "./src/index.ts",
|
|
28
|
+
"import": "./dist/index.js",
|
|
29
|
+
"require": "./dist/index.cjs",
|
|
30
|
+
"default": "./dist/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./package.json": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
"main": "./dist/index.cjs",
|
|
35
|
+
"module": "./dist/index.js",
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"files": [
|
|
38
|
+
"src",
|
|
39
|
+
"dist"
|
|
40
|
+
],
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@portabletext/editor": "^1.48.5",
|
|
43
|
+
"@types/react": "^19.1.2",
|
|
44
|
+
"react": "^19.1.0"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@portabletext/editor": "^1.48.4",
|
|
48
|
+
"react": "^19.1.0"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@portabletext/plugin-character-pair-decorator": "^1.0.1"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "pkg-utils build --strict --check --clean",
|
|
55
|
+
"check:lint": "biome lint .",
|
|
56
|
+
"check:react-compiler": "eslint --cache --no-inline-config --no-eslintrc --ignore-pattern '**/__tests__/**' --ext .cjs,.mjs,.js,.jsx,.ts,.tsx --parser @typescript-eslint/parser --plugin react-compiler --plugin react-hooks --rule 'react-compiler/react-compiler: [warn]' --rule 'react-hooks/rules-of-hooks: [error]' --rule 'react-hooks/exhaustive-deps: [error]' src",
|
|
57
|
+
"check:types": "tsc",
|
|
58
|
+
"check:types:watch": "tsc --watch",
|
|
59
|
+
"clean": "del .turbo && del dist && del node_modules",
|
|
60
|
+
"dev": "pkg-utils watch",
|
|
61
|
+
"lint:fix": "biome lint --write ."
|
|
62
|
+
}
|
|
63
|
+
}
|