@portabletext/editor 1.34.0 → 1.35.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/lib/_chunks-cjs/behavior.core.cjs +57 -118
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +27 -67
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
- package/lib/_chunks-cjs/plugin.event-listener.cjs +53 -71
- package/lib/_chunks-cjs/plugin.event-listener.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +5 -7
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-active-style.cjs +22 -36
- package/lib/_chunks-cjs/selector.is-active-style.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +68 -153
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
- package/lib/_chunks-cjs/util.block-offsets-to-selection.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +57 -118
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +27 -67
- package/lib/_chunks-es/behavior.markdown.js.map +1 -1
- package/lib/_chunks-es/plugin.event-listener.js +53 -71
- package/lib/_chunks-es/plugin.event-listener.js.map +1 -1
- package/lib/_chunks-es/selector.get-text-before.js +5 -7
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/selector.is-active-style.js +22 -36
- package/lib/_chunks-es/selector.is-active-style.js.map +1 -1
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +68 -153
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
- package/lib/_chunks-es/util.block-offsets-to-selection.js.map +1 -1
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/behaviors/index.cjs +18 -48
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +28 -16
- package/lib/behaviors/index.d.ts +28 -16
- package/lib/behaviors/index.js +18 -48
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.d.cts +132 -71
- package/lib/index.d.ts +132 -71
- package/lib/plugins/index.cjs +182 -186
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +147 -82
- package/lib/plugins/index.d.ts +147 -82
- package/lib/plugins/index.js +182 -186
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.cjs +22 -50
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +9 -200
- package/lib/selectors/index.d.ts +9 -200
- package/lib/selectors/index.js +22 -50
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +15 -7
- package/lib/utils/index.d.ts +15 -7
- package/lib/utils/index.js.map +1 -1
- package/package.json +6 -6
- package/src/behaviors/behavior.code-editor.ts +6 -6
- package/src/behaviors/behavior.core.annotations.ts +5 -4
- package/src/behaviors/behavior.core.block-objects.ts +17 -17
- package/src/behaviors/behavior.core.decorators.ts +12 -8
- package/src/behaviors/behavior.core.insert-break.ts +27 -29
- package/src/behaviors/behavior.core.lists.ts +19 -19
- package/src/behaviors/behavior.decorator-pair.ts +200 -0
- package/src/behaviors/behavior.default.ts +35 -30
- package/src/behaviors/behavior.emoji-picker.ts +12 -12
- package/src/behaviors/behavior.links.ts +7 -7
- package/src/behaviors/behavior.markdown.ts +41 -42
- package/src/behaviors/behavior.types.ts +15 -18
- package/src/behaviors/index.ts +0 -1
- package/src/converters/converter.json.ts +6 -6
- package/src/converters/converter.portable-text.deserialize.test.ts +28 -26
- package/src/converters/converter.portable-text.ts +6 -6
- package/src/converters/converter.text-html.deserialize.test.ts +17 -15
- package/src/converters/converter.text-html.serialize.test.ts +57 -53
- package/src/converters/converter.text-html.ts +14 -10
- package/src/converters/converter.text-plain.test.ts +17 -15
- package/src/converters/converter.text-plain.ts +15 -11
- package/src/converters/converter.types.ts +8 -7
- package/src/editor/editor-machine.ts +6 -1
- package/src/editor/plugins/create-with-event-listeners.ts +0 -5
- package/src/index.ts +3 -3
- package/src/internal-utils/get-text-to-emphasize.ts +29 -7
- package/src/plugins/plugin.decorator-shortcut.ts +235 -0
- package/src/plugins/plugin.markdown.tsx +56 -8
- package/src/plugins/plugin.one-line.tsx +17 -17
- package/src/selectors/selector.get-active-list-item.ts +4 -4
- package/src/selectors/selector.get-active-style.ts +6 -6
- package/src/selectors/selector.get-anchor-block.ts +5 -5
- package/src/selectors/selector.get-anchor-child.ts +5 -5
- package/src/selectors/selector.get-anchor-span.ts +2 -2
- package/src/selectors/selector.get-anchor-text-block.ts +2 -2
- package/src/selectors/selector.get-block-offsets.ts +8 -7
- package/src/selectors/selector.get-caret-word-selection.ts +19 -16
- package/src/selectors/selector.get-next-inline-object.ts +4 -4
- package/src/selectors/selector.get-previous-inline-object.ts +4 -4
- package/src/selectors/selector.get-selected-slice.ts +7 -4
- package/src/selectors/selector.get-selected-spans.ts +9 -9
- package/src/selectors/selector.get-selection-end-point.ts +5 -5
- package/src/selectors/selector.get-selection-start-point.ts +5 -5
- package/src/selectors/selector.get-selection-text.ts +2 -2
- package/src/selectors/selector.get-selection.ts +2 -2
- package/src/selectors/selector.get-text-before.ts +8 -8
- package/src/selectors/selector.get-trimmed-selection.ts +15 -13
- package/src/selectors/selector.get-value.ts +4 -4
- package/src/selectors/selector.is-at-the-end-of-block.ts +6 -3
- package/src/selectors/selector.is-at-the-start-of-block.ts +3 -3
- package/src/selectors/selector.is-overlapping-selection.ts +8 -6
- package/src/selectors/selector.is-selection-collapsed.ts +6 -5
- package/src/selectors/selector.is-selection-expanded.ts +2 -2
- package/src/selectors/selectors.ts +59 -59
- package/src/types/block-offset.ts +9 -0
- package/src/utils/index.ts +0 -1
- package/src/utils/util.block-offset.ts +1 -1
- package/src/utils/util.block-offsets-to-selection.ts +1 -1
- package/src/utils/util.child-selection-point-to-block-offset.ts +1 -1
- package/src/behaviors/behavior.markdown-emphasis.ts +0 -437
|
@@ -75,14 +75,16 @@ const paragraphWithInlineBlock: PortableTextTextBlock = {
|
|
|
75
75
|
],
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
function
|
|
78
|
+
function createSnapshot(schema: SchemaDefinition, selection: EditorSelection) {
|
|
79
79
|
return {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
80
|
+
context: {
|
|
81
|
+
converters: coreConverters,
|
|
82
|
+
activeDecorators: [],
|
|
83
|
+
keyGenerator: createTestKeyGenerator(),
|
|
84
|
+
schema: compileSchemaDefinition(schema),
|
|
85
|
+
selection,
|
|
86
|
+
value: [decoratedParagraph, image, b2, paragraphWithInlineBlock],
|
|
87
|
+
},
|
|
86
88
|
}
|
|
87
89
|
}
|
|
88
90
|
|
|
@@ -90,7 +92,7 @@ describe(converterTextHtml.serialize.name, () => {
|
|
|
90
92
|
test('paragraph with decorators', () => {
|
|
91
93
|
expect(
|
|
92
94
|
converterTextHtml.serialize({
|
|
93
|
-
|
|
95
|
+
snapshot: createSnapshot(defineSchema({}), {
|
|
94
96
|
anchor: {
|
|
95
97
|
path: [
|
|
96
98
|
{_key: decoratedParagraph._key},
|
|
@@ -121,7 +123,7 @@ describe(converterTextHtml.serialize.name, () => {
|
|
|
121
123
|
test('image', () => {
|
|
122
124
|
expect(
|
|
123
125
|
converterTextHtml.serialize({
|
|
124
|
-
|
|
126
|
+
snapshot: createSnapshot(defineSchema({}), {
|
|
125
127
|
anchor: {
|
|
126
128
|
path: [{_key: image._key}],
|
|
127
129
|
offset: 0,
|
|
@@ -144,7 +146,7 @@ describe(converterTextHtml.serialize.name, () => {
|
|
|
144
146
|
test('inline object', () => {
|
|
145
147
|
expect(
|
|
146
148
|
converterTextHtml.serialize({
|
|
147
|
-
|
|
149
|
+
snapshot: createSnapshot(defineSchema({}), {
|
|
148
150
|
anchor: {
|
|
149
151
|
path: [
|
|
150
152
|
{_key: paragraphWithInlineBlock._key},
|
|
@@ -175,49 +177,51 @@ describe(converterTextHtml.serialize.name, () => {
|
|
|
175
177
|
test('lists', () => {
|
|
176
178
|
expect(
|
|
177
179
|
converterTextHtml.serialize({
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
180
|
+
snapshot: {
|
|
181
|
+
context: {
|
|
182
|
+
converters: coreConverters,
|
|
183
|
+
activeDecorators: [],
|
|
184
|
+
keyGenerator: createTestKeyGenerator(),
|
|
185
|
+
schema: compileSchemaDefinition(defineSchema({})),
|
|
186
|
+
value: [
|
|
187
|
+
{
|
|
188
|
+
_key: 'k0',
|
|
189
|
+
_type: 'block',
|
|
190
|
+
children: [
|
|
191
|
+
{
|
|
192
|
+
_key: 'k1',
|
|
193
|
+
_type: 'span',
|
|
194
|
+
marks: [],
|
|
195
|
+
text: 'foo',
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
level: 1,
|
|
199
|
+
listItem: 'number',
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
_key: 'k2',
|
|
203
|
+
_type: 'block',
|
|
204
|
+
children: [
|
|
205
|
+
{
|
|
206
|
+
_key: 'k3',
|
|
207
|
+
_type: 'span',
|
|
208
|
+
marks: [],
|
|
209
|
+
text: 'bar',
|
|
210
|
+
},
|
|
211
|
+
],
|
|
212
|
+
level: 2,
|
|
213
|
+
listItem: 'bullet',
|
|
214
|
+
},
|
|
215
|
+
],
|
|
216
|
+
selection: {
|
|
217
|
+
anchor: {
|
|
218
|
+
path: [{_key: 'k0'}, 'children', {_key: 'k1'}],
|
|
219
|
+
offset: 0,
|
|
220
|
+
},
|
|
221
|
+
focus: {
|
|
222
|
+
path: [{_key: 'k2'}, 'children', {_key: 'k3'}],
|
|
223
|
+
offset: 3,
|
|
224
|
+
},
|
|
221
225
|
},
|
|
222
226
|
},
|
|
223
227
|
},
|
|
@@ -6,8 +6,8 @@ import {defineConverter} from './converter.types'
|
|
|
6
6
|
|
|
7
7
|
export const converterTextHtml = defineConverter({
|
|
8
8
|
mimeType: 'text/html',
|
|
9
|
-
serialize: ({
|
|
10
|
-
if (!context.selection) {
|
|
9
|
+
serialize: ({snapshot, event}) => {
|
|
10
|
+
if (!snapshot.context.selection) {
|
|
11
11
|
return {
|
|
12
12
|
type: 'serialization.failure',
|
|
13
13
|
mimeType: 'text/html',
|
|
@@ -17,8 +17,8 @@ export const converterTextHtml = defineConverter({
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
const blocks = sliceBlocks({
|
|
20
|
-
blocks: context.value,
|
|
21
|
-
selection: context.selection,
|
|
20
|
+
blocks: snapshot.context.value,
|
|
21
|
+
selection: snapshot.context.selection,
|
|
22
22
|
})
|
|
23
23
|
|
|
24
24
|
const html = toHTML(blocks, {
|
|
@@ -45,12 +45,16 @@ export const converterTextHtml = defineConverter({
|
|
|
45
45
|
originEvent: event.originEvent,
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
|
-
deserialize: ({
|
|
49
|
-
const blocks = htmlToBlocks(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
deserialize: ({snapshot, event}) => {
|
|
49
|
+
const blocks = htmlToBlocks(
|
|
50
|
+
event.data,
|
|
51
|
+
snapshot.context.schema.portableText,
|
|
52
|
+
{
|
|
53
|
+
keyGenerator: snapshot.context.keyGenerator,
|
|
54
|
+
unstable_whitespaceOnPasteMode:
|
|
55
|
+
snapshot.context.schema.block.options.unstable_whitespaceOnPasteMode,
|
|
56
|
+
},
|
|
57
|
+
) as Array<PortableTextBlock>
|
|
54
58
|
|
|
55
59
|
return {
|
|
56
60
|
type: 'deserialization.success',
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
defineSchema,
|
|
6
6
|
type SchemaDefinition,
|
|
7
7
|
} from '../editor/define-schema'
|
|
8
|
-
import type {
|
|
8
|
+
import type {EditorSnapshot} from '../editor/editor-snapshot'
|
|
9
9
|
import type {EditorSelection} from '../utils'
|
|
10
10
|
import {converterTextPlain} from './converter.text-plain'
|
|
11
11
|
import {coreConverters} from './converters.core'
|
|
@@ -65,27 +65,29 @@ const b4: PortableTextTextBlock = {
|
|
|
65
65
|
],
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
function
|
|
68
|
+
function createSnapshot({
|
|
69
69
|
schema,
|
|
70
70
|
selection,
|
|
71
71
|
}: {
|
|
72
72
|
schema: SchemaDefinition
|
|
73
73
|
selection: EditorSelection
|
|
74
|
-
}):
|
|
74
|
+
}): EditorSnapshot {
|
|
75
75
|
return {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
context: {
|
|
77
|
+
converters: coreConverters,
|
|
78
|
+
activeDecorators: [],
|
|
79
|
+
keyGenerator: () => '',
|
|
80
|
+
schema: compileSchemaDefinition(schema),
|
|
81
|
+
selection,
|
|
82
|
+
value: [b1, b2, b3, b4],
|
|
83
|
+
},
|
|
82
84
|
}
|
|
83
85
|
}
|
|
84
86
|
|
|
85
87
|
test(converterTextPlain.serialize.name, () => {
|
|
86
88
|
expect(
|
|
87
89
|
converterTextPlain.serialize({
|
|
88
|
-
|
|
90
|
+
snapshot: createSnapshot({
|
|
89
91
|
schema: defineSchema({}),
|
|
90
92
|
selection: {
|
|
91
93
|
anchor: {
|
|
@@ -109,7 +111,7 @@ test(converterTextPlain.serialize.name, () => {
|
|
|
109
111
|
|
|
110
112
|
expect(
|
|
111
113
|
converterTextPlain.serialize({
|
|
112
|
-
|
|
114
|
+
snapshot: createSnapshot({
|
|
113
115
|
schema: defineSchema({}),
|
|
114
116
|
selection: {
|
|
115
117
|
anchor: {
|
|
@@ -133,7 +135,7 @@ test(converterTextPlain.serialize.name, () => {
|
|
|
133
135
|
|
|
134
136
|
expect(
|
|
135
137
|
converterTextPlain.serialize({
|
|
136
|
-
|
|
138
|
+
snapshot: createSnapshot({
|
|
137
139
|
schema: defineSchema({}),
|
|
138
140
|
selection: {
|
|
139
141
|
anchor: {
|
|
@@ -157,7 +159,7 @@ test(converterTextPlain.serialize.name, () => {
|
|
|
157
159
|
|
|
158
160
|
expect(
|
|
159
161
|
converterTextPlain.serialize({
|
|
160
|
-
|
|
162
|
+
snapshot: createSnapshot({
|
|
161
163
|
schema: defineSchema({
|
|
162
164
|
blockObjects: [
|
|
163
165
|
{
|
|
@@ -187,7 +189,7 @@ test(converterTextPlain.serialize.name, () => {
|
|
|
187
189
|
|
|
188
190
|
expect(
|
|
189
191
|
converterTextPlain.serialize({
|
|
190
|
-
|
|
192
|
+
snapshot: createSnapshot({
|
|
191
193
|
schema: defineSchema({}),
|
|
192
194
|
selection: {
|
|
193
195
|
anchor: {
|
|
@@ -211,7 +213,7 @@ test(converterTextPlain.serialize.name, () => {
|
|
|
211
213
|
|
|
212
214
|
expect(
|
|
213
215
|
converterTextPlain.serialize({
|
|
214
|
-
|
|
216
|
+
snapshot: createSnapshot({
|
|
215
217
|
schema: defineSchema({
|
|
216
218
|
inlineObjects: [
|
|
217
219
|
{
|
|
@@ -5,8 +5,8 @@ import {defineConverter} from './converter.types'
|
|
|
5
5
|
|
|
6
6
|
export const converterTextPlain = defineConverter({
|
|
7
7
|
mimeType: 'text/plain',
|
|
8
|
-
serialize: ({
|
|
9
|
-
if (!context.selection) {
|
|
8
|
+
serialize: ({snapshot, event}) => {
|
|
9
|
+
if (!snapshot.context.selection) {
|
|
10
10
|
return {
|
|
11
11
|
type: 'serialization.failure',
|
|
12
12
|
mimeType: 'text/plain',
|
|
@@ -16,8 +16,8 @@ export const converterTextPlain = defineConverter({
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
const blocks = sliceBlocks({
|
|
19
|
-
blocks: context.value,
|
|
20
|
-
selection: context.selection,
|
|
19
|
+
blocks: snapshot.context.value,
|
|
20
|
+
selection: snapshot.context.selection,
|
|
21
21
|
})
|
|
22
22
|
|
|
23
23
|
const data = blocks
|
|
@@ -25,12 +25,12 @@ export const converterTextPlain = defineConverter({
|
|
|
25
25
|
if (isPortableTextTextBlock(block)) {
|
|
26
26
|
return block.children
|
|
27
27
|
.map((child) => {
|
|
28
|
-
if (child._type === context.schema.span.name) {
|
|
28
|
+
if (child._type === snapshot.context.schema.span.name) {
|
|
29
29
|
return child.text
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
return `[${
|
|
33
|
-
context.schema.inlineObjects.find(
|
|
33
|
+
snapshot.context.schema.inlineObjects.find(
|
|
34
34
|
(inlineObjectType) => inlineObjectType.name === child._type,
|
|
35
35
|
)?.title ?? 'Object'
|
|
36
36
|
}]`
|
|
@@ -39,7 +39,7 @@ export const converterTextPlain = defineConverter({
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
return `[${
|
|
42
|
-
context.schema.blockObjects.find(
|
|
42
|
+
snapshot.context.schema.blockObjects.find(
|
|
43
43
|
(blockObjectType) => blockObjectType.name === block._type,
|
|
44
44
|
)?.title ?? 'Object'
|
|
45
45
|
}]`
|
|
@@ -53,7 +53,7 @@ export const converterTextPlain = defineConverter({
|
|
|
53
53
|
originEvent: event.originEvent,
|
|
54
54
|
}
|
|
55
55
|
},
|
|
56
|
-
deserialize: ({
|
|
56
|
+
deserialize: ({snapshot, event}) => {
|
|
57
57
|
const html = escapeHtml(event.data)
|
|
58
58
|
.split(/\n{2,}/)
|
|
59
59
|
.map((line) =>
|
|
@@ -63,9 +63,13 @@ export const converterTextPlain = defineConverter({
|
|
|
63
63
|
|
|
64
64
|
const textToHtml = `<html><body>${html}</body></html>`
|
|
65
65
|
|
|
66
|
-
const blocks = htmlToBlocks(
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
const blocks = htmlToBlocks(
|
|
67
|
+
textToHtml,
|
|
68
|
+
snapshot.context.schema.portableText,
|
|
69
|
+
{
|
|
70
|
+
keyGenerator: snapshot.context.keyGenerator,
|
|
71
|
+
},
|
|
72
|
+
) as Array<PortableTextBlock>
|
|
69
73
|
|
|
70
74
|
return {
|
|
71
75
|
type: 'deserialization.success',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type {PortableTextBlock} from '@sanity/types'
|
|
2
|
-
import type {
|
|
2
|
+
import type {EditorSnapshot} from '../editor/editor-snapshot'
|
|
3
3
|
import type {MIMEType} from '../internal-utils/mime-type'
|
|
4
4
|
import type {PickFromUnion} from '../type-utils'
|
|
5
5
|
|
|
@@ -18,18 +18,19 @@ export function defineConverter<TMIMEType extends MIMEType>(
|
|
|
18
18
|
export type ConverterEvent<TMIMEType extends MIMEType = MIMEType> =
|
|
19
19
|
| {
|
|
20
20
|
type: 'serialize'
|
|
21
|
-
originEvent: 'copy' | 'cut' | 'unknown'
|
|
21
|
+
originEvent: 'copy' | 'cut' | 'drag' | 'unknown'
|
|
22
22
|
}
|
|
23
23
|
| {
|
|
24
24
|
type: 'serialization.failure'
|
|
25
25
|
mimeType: TMIMEType
|
|
26
|
+
originEvent: 'copy' | 'cut' | 'drag' | 'unknown'
|
|
26
27
|
reason: string
|
|
27
28
|
}
|
|
28
29
|
| {
|
|
29
30
|
type: 'serialization.success'
|
|
30
31
|
data: string
|
|
31
32
|
mimeType: TMIMEType
|
|
32
|
-
originEvent: 'copy' | 'cut' | 'unknown'
|
|
33
|
+
originEvent: 'copy' | 'cut' | 'drag' | 'unknown'
|
|
33
34
|
}
|
|
34
35
|
| {
|
|
35
36
|
type: 'deserialize'
|
|
@@ -47,10 +48,10 @@ export type ConverterEvent<TMIMEType extends MIMEType = MIMEType> =
|
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
export type Serializer<TMIMEType extends MIMEType> = ({
|
|
50
|
-
|
|
51
|
+
snapshot,
|
|
51
52
|
event,
|
|
52
53
|
}: {
|
|
53
|
-
|
|
54
|
+
snapshot: EditorSnapshot
|
|
54
55
|
event: PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'serialize'>
|
|
55
56
|
}) => PickFromUnion<
|
|
56
57
|
ConverterEvent<TMIMEType>,
|
|
@@ -59,10 +60,10 @@ export type Serializer<TMIMEType extends MIMEType> = ({
|
|
|
59
60
|
>
|
|
60
61
|
|
|
61
62
|
export type Deserializer<TMIMEType extends MIMEType> = ({
|
|
62
|
-
|
|
63
|
+
snapshot,
|
|
63
64
|
event,
|
|
64
65
|
}: {
|
|
65
|
-
|
|
66
|
+
snapshot: EditorSnapshot
|
|
66
67
|
event: PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'deserialize'>
|
|
67
68
|
}) => PickFromUnion<
|
|
68
69
|
ConverterEvent<TMIMEType>,
|
|
@@ -369,6 +369,7 @@ export const editorMachine = setup({
|
|
|
369
369
|
eventBehavior.guard === undefined ||
|
|
370
370
|
eventBehavior.guard({
|
|
371
371
|
context: editorSnapshot.context,
|
|
372
|
+
snapshot: editorSnapshot,
|
|
372
373
|
event: event.behaviorEvent,
|
|
373
374
|
})
|
|
374
375
|
|
|
@@ -378,7 +379,11 @@ export const editorMachine = setup({
|
|
|
378
379
|
|
|
379
380
|
const actionIntendSets = eventBehavior.actions.map((actionSet) =>
|
|
380
381
|
actionSet(
|
|
381
|
-
{
|
|
382
|
+
{
|
|
383
|
+
context: editorSnapshot.context,
|
|
384
|
+
snapshot: editorSnapshot,
|
|
385
|
+
event: event.behaviorEvent,
|
|
386
|
+
},
|
|
382
387
|
shouldRun,
|
|
383
388
|
),
|
|
384
389
|
)
|
|
@@ -236,11 +236,6 @@ export function createWithEventListeners(
|
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
editor.setFragmentData = (dataTransfer, originEvent) => {
|
|
239
|
-
if (originEvent === 'drag') {
|
|
240
|
-
setFragmentData(dataTransfer)
|
|
241
|
-
return
|
|
242
|
-
}
|
|
243
|
-
|
|
244
239
|
if (isApplyingBehaviorActions(editor)) {
|
|
245
240
|
setFragmentData(dataTransfer)
|
|
246
241
|
return
|
package/src/index.ts
CHANGED
|
@@ -10,7 +10,6 @@ export type {
|
|
|
10
10
|
BehaviorActionIntendSet,
|
|
11
11
|
BehaviorEvent,
|
|
12
12
|
BehaviorGuard,
|
|
13
|
-
BlockOffset,
|
|
14
13
|
NativeBehaviorEvent,
|
|
15
14
|
SyntheticBehaviorEvent,
|
|
16
15
|
} from './behaviors/index'
|
|
@@ -21,11 +20,9 @@ export {
|
|
|
21
20
|
type BaseDefinition,
|
|
22
21
|
type SchemaDefinition,
|
|
23
22
|
} from './editor/define-schema'
|
|
24
|
-
export type {PortableTextMemberSchemaTypes} from './types/editor'
|
|
25
23
|
export type {EditorSchema} from './editor/define-schema'
|
|
26
24
|
export {PortableTextEditable} from './editor/Editable'
|
|
27
25
|
export type {PortableTextEditableProps} from './editor/Editable'
|
|
28
|
-
export {EventListenerPlugin as EditorEventListener} from './plugins/plugin.event-listener'
|
|
29
26
|
export type {
|
|
30
27
|
EditorEmittedEvent,
|
|
31
28
|
MutationEvent,
|
|
@@ -44,5 +41,8 @@ export {defaultKeyGenerator as keyGenerator} from './editor/key-generator'
|
|
|
44
41
|
export type {AddedAnnotationPaths} from './editor/plugins/createWithEditableAPI'
|
|
45
42
|
export {PortableTextEditor} from './editor/PortableTextEditor'
|
|
46
43
|
export type {PortableTextEditorProps} from './editor/PortableTextEditor'
|
|
44
|
+
export {EventListenerPlugin as EditorEventListener} from './plugins/plugin.event-listener'
|
|
45
|
+
export type {BlockOffset} from './types/block-offset'
|
|
47
46
|
export * from './types/editor'
|
|
47
|
+
export type {PortableTextMemberSchemaTypes} from './types/editor'
|
|
48
48
|
export type {HotkeyOptions} from './types/options'
|
|
@@ -1,12 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
1
|
+
export function createPairRegex(char: string, amount: number) {
|
|
2
|
+
// Negative lookbehind: Ensures that the matched sequence is not preceded by the same character
|
|
3
|
+
const prePrefix = `(?<!\\${char})`
|
|
4
|
+
|
|
5
|
+
// Repeats the character `amount` times
|
|
6
|
+
const prefix = `\\${char}`.repeat(Math.max(amount, 1))
|
|
7
|
+
|
|
8
|
+
// Negative lookahead: Ensures that the opening pair (**, *, etc.) is not followed by a space
|
|
9
|
+
const postPrefix = `(?!\\s)`
|
|
10
|
+
|
|
11
|
+
// Captures the content inside the pair
|
|
12
|
+
const content = `([^${char}\\n]+?)`
|
|
13
|
+
|
|
14
|
+
// Negative lookbehind: Ensures that the content is not followed by a space
|
|
15
|
+
const preSuffix = `(?<!\\s)`
|
|
16
|
+
|
|
17
|
+
// Repeats the character `amount` times
|
|
18
|
+
const suffix = `\\${char}`.repeat(Math.max(amount, 1))
|
|
19
|
+
|
|
20
|
+
// Negative lookahead: Ensures that the matched sequence is not followed by the same character
|
|
21
|
+
const postSuffix = `(?!\\${char})`
|
|
22
|
+
|
|
23
|
+
return `${prePrefix}${prefix}${postPrefix}${content}${preSuffix}${suffix}${postSuffix}`
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const italicRegex = new RegExp(
|
|
27
|
+
`(${createPairRegex('*', 1)}|${createPairRegex('_', 1)})$`,
|
|
28
|
+
)
|
|
4
29
|
|
|
5
|
-
const doubleAsteriskPairRegex =
|
|
6
|
-
'(?<!\\*)\\*\\*(?!\\s)([^*\\n]+?)(?<!\\s)\\*\\*(?!\\*)'
|
|
7
|
-
const doubleUnderscorePairRegex = '(?<!_)__(?!\\s)([^_\\n]+?)(?<!\\s)__(?!_)'
|
|
8
30
|
const boldRegex = new RegExp(
|
|
9
|
-
`(${
|
|
31
|
+
`(${createPairRegex('*', 2)}|${createPairRegex('_', 2)})$`,
|
|
10
32
|
)
|
|
11
33
|
|
|
12
34
|
export function getTextToItalic(text: string) {
|