@portabletext/editor 1.5.1 → 1.5.2
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/index.d.mts +74 -18
- package/lib/index.d.ts +74 -18
- package/lib/index.esm.js +151 -133
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +151 -133
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +151 -133
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/editor/behavior/behavior.core.block-objects.ts +4 -4
- package/src/editor/behavior/behavior.core.lists.ts +1 -1
- package/src/editor/behavior/behavior.core.ts +17 -2
- package/src/editor/behavior/behavior.markdown.ts +5 -0
- package/src/editor/editor-machine.ts +2 -4
- package/src/index.ts +2 -1
package/lib/index.js
CHANGED
|
@@ -119,6 +119,148 @@ function getNextBlock(context) {
|
|
|
119
119
|
function isEmptyTextBlock(block) {
|
|
120
120
|
return block.children.length === 1 && block.children[0].text === "";
|
|
121
121
|
}
|
|
122
|
+
const breakingBlockObject = {
|
|
123
|
+
on: "insert break",
|
|
124
|
+
guard: ({
|
|
125
|
+
context
|
|
126
|
+
}) => !!getFocusBlockObject(context),
|
|
127
|
+
actions: [() => [{
|
|
128
|
+
type: "insert text block",
|
|
129
|
+
decorators: []
|
|
130
|
+
}]]
|
|
131
|
+
}, deletingEmptyTextBlockAfterBlockObject = {
|
|
132
|
+
on: "delete backward",
|
|
133
|
+
guard: ({
|
|
134
|
+
context
|
|
135
|
+
}) => {
|
|
136
|
+
const focusTextBlock = getFocusTextBlock(context), selectionCollapsed = selectionIsCollapsed(context), previousBlock = getPreviousBlock(context);
|
|
137
|
+
return !focusTextBlock || !selectionCollapsed || !previousBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !types.isPortableTextTextBlock(previousBlock.node) ? {
|
|
138
|
+
focusTextBlock,
|
|
139
|
+
previousBlock
|
|
140
|
+
} : !1;
|
|
141
|
+
},
|
|
142
|
+
actions: [(_, {
|
|
143
|
+
focusTextBlock,
|
|
144
|
+
previousBlock
|
|
145
|
+
}) => [{
|
|
146
|
+
type: "delete",
|
|
147
|
+
selection: {
|
|
148
|
+
anchor: {
|
|
149
|
+
path: focusTextBlock.path,
|
|
150
|
+
offset: 0
|
|
151
|
+
},
|
|
152
|
+
focus: {
|
|
153
|
+
path: focusTextBlock.path,
|
|
154
|
+
offset: 0
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}, {
|
|
158
|
+
type: "select",
|
|
159
|
+
selection: {
|
|
160
|
+
anchor: {
|
|
161
|
+
path: previousBlock.path,
|
|
162
|
+
offset: 0
|
|
163
|
+
},
|
|
164
|
+
focus: {
|
|
165
|
+
path: previousBlock.path,
|
|
166
|
+
offset: 0
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}]]
|
|
170
|
+
}, deletingEmptyTextBlockBeforeBlockObject = {
|
|
171
|
+
on: "delete forward",
|
|
172
|
+
guard: ({
|
|
173
|
+
context
|
|
174
|
+
}) => {
|
|
175
|
+
const focusTextBlock = getFocusTextBlock(context), selectionCollapsed = selectionIsCollapsed(context), nextBlock = getNextBlock(context);
|
|
176
|
+
return !focusTextBlock || !selectionCollapsed || !nextBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !types.isPortableTextTextBlock(nextBlock.node) ? {
|
|
177
|
+
focusTextBlock,
|
|
178
|
+
nextBlock
|
|
179
|
+
} : !1;
|
|
180
|
+
},
|
|
181
|
+
actions: [(_, {
|
|
182
|
+
focusTextBlock,
|
|
183
|
+
nextBlock
|
|
184
|
+
}) => [{
|
|
185
|
+
type: "delete",
|
|
186
|
+
selection: {
|
|
187
|
+
anchor: {
|
|
188
|
+
path: focusTextBlock.path,
|
|
189
|
+
offset: 0
|
|
190
|
+
},
|
|
191
|
+
focus: {
|
|
192
|
+
path: focusTextBlock.path,
|
|
193
|
+
offset: 0
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}, {
|
|
197
|
+
type: "select",
|
|
198
|
+
selection: {
|
|
199
|
+
anchor: {
|
|
200
|
+
path: nextBlock.path,
|
|
201
|
+
offset: 0
|
|
202
|
+
},
|
|
203
|
+
focus: {
|
|
204
|
+
path: nextBlock.path,
|
|
205
|
+
offset: 0
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}]]
|
|
209
|
+
}, coreBlockObjectBehaviors = {
|
|
210
|
+
breakingBlockObject,
|
|
211
|
+
deletingEmptyTextBlockAfterBlockObject,
|
|
212
|
+
deletingEmptyTextBlockBeforeBlockObject
|
|
213
|
+
}, clearListOnBackspace = {
|
|
214
|
+
on: "delete backward",
|
|
215
|
+
guard: ({
|
|
216
|
+
context
|
|
217
|
+
}) => {
|
|
218
|
+
const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
|
|
219
|
+
return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0 && focusTextBlock.node.level === 1 ? {
|
|
220
|
+
focusTextBlock
|
|
221
|
+
} : !1;
|
|
222
|
+
},
|
|
223
|
+
actions: [(_, {
|
|
224
|
+
focusTextBlock
|
|
225
|
+
}) => [{
|
|
226
|
+
type: "unset block",
|
|
227
|
+
props: ["listItem", "level"],
|
|
228
|
+
paths: [focusTextBlock.path]
|
|
229
|
+
}]]
|
|
230
|
+
}, unindentListOnBackspace = {
|
|
231
|
+
on: "delete backward",
|
|
232
|
+
guard: ({
|
|
233
|
+
context
|
|
234
|
+
}) => {
|
|
235
|
+
const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
|
|
236
|
+
return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0 && focusTextBlock.node.level !== void 0 && focusTextBlock.node.level > 1 ? {
|
|
237
|
+
focusTextBlock,
|
|
238
|
+
level: focusTextBlock.node.level - 1
|
|
239
|
+
} : !1;
|
|
240
|
+
},
|
|
241
|
+
actions: [(_, {
|
|
242
|
+
focusTextBlock,
|
|
243
|
+
level
|
|
244
|
+
}) => [{
|
|
245
|
+
type: "set block",
|
|
246
|
+
level,
|
|
247
|
+
paths: [focusTextBlock.path]
|
|
248
|
+
}]]
|
|
249
|
+
}, coreListBehaviors = {
|
|
250
|
+
clearListOnBackspace,
|
|
251
|
+
unindentListOnBackspace
|
|
252
|
+
}, softReturn = {
|
|
253
|
+
on: "insert soft break",
|
|
254
|
+
actions: [() => [{
|
|
255
|
+
type: "insert text",
|
|
256
|
+
text: `
|
|
257
|
+
`
|
|
258
|
+
}]]
|
|
259
|
+
}, coreBehaviors = [softReturn, coreBlockObjectBehaviors.breakingBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockAfterBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockBeforeBlockObject, coreListBehaviors.clearListOnBackspace, coreListBehaviors.unindentListOnBackspace], coreBehavior = {
|
|
260
|
+
softReturn,
|
|
261
|
+
blockObjects: coreBlockObjectBehaviors,
|
|
262
|
+
lists: coreListBehaviors
|
|
263
|
+
};
|
|
122
264
|
function createMarkdownBehaviors(config) {
|
|
123
265
|
const automaticStyleOnSpace = {
|
|
124
266
|
on: "insert text",
|
|
@@ -150,6 +292,10 @@ function createMarkdownBehaviors(config) {
|
|
|
150
292
|
focusSpan,
|
|
151
293
|
style
|
|
152
294
|
}) => [{
|
|
295
|
+
type: "unset block",
|
|
296
|
+
props: ["listItem", "level"],
|
|
297
|
+
paths: [focusTextBlock.path]
|
|
298
|
+
}, {
|
|
153
299
|
type: "set block",
|
|
154
300
|
style,
|
|
155
301
|
paths: [focusTextBlock.path]
|
|
@@ -5318,137 +5464,7 @@ function performDefaultAction({
|
|
|
5318
5464
|
});
|
|
5319
5465
|
}
|
|
5320
5466
|
}
|
|
5321
|
-
const
|
|
5322
|
-
on: "insert break",
|
|
5323
|
-
guard: ({
|
|
5324
|
-
context
|
|
5325
|
-
}) => !!getFocusBlockObject(context),
|
|
5326
|
-
actions: [() => [{
|
|
5327
|
-
type: "insert text block",
|
|
5328
|
-
decorators: []
|
|
5329
|
-
}]]
|
|
5330
|
-
}, deletingEmptyTextBlockAfterBlockObject = {
|
|
5331
|
-
on: "delete backward",
|
|
5332
|
-
guard: ({
|
|
5333
|
-
context
|
|
5334
|
-
}) => {
|
|
5335
|
-
const focusTextBlock = getFocusTextBlock(context), selectionCollapsed = selectionIsCollapsed(context), previousBlock = getPreviousBlock(context);
|
|
5336
|
-
return !focusTextBlock || !selectionCollapsed || !previousBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !types.isPortableTextTextBlock(previousBlock.node) ? {
|
|
5337
|
-
focusTextBlock,
|
|
5338
|
-
previousBlock
|
|
5339
|
-
} : !1;
|
|
5340
|
-
},
|
|
5341
|
-
actions: [(_, {
|
|
5342
|
-
focusTextBlock,
|
|
5343
|
-
previousBlock
|
|
5344
|
-
}) => [{
|
|
5345
|
-
type: "delete",
|
|
5346
|
-
selection: {
|
|
5347
|
-
anchor: {
|
|
5348
|
-
path: focusTextBlock.path,
|
|
5349
|
-
offset: 0
|
|
5350
|
-
},
|
|
5351
|
-
focus: {
|
|
5352
|
-
path: focusTextBlock.path,
|
|
5353
|
-
offset: 0
|
|
5354
|
-
}
|
|
5355
|
-
}
|
|
5356
|
-
}, {
|
|
5357
|
-
type: "select",
|
|
5358
|
-
selection: {
|
|
5359
|
-
anchor: {
|
|
5360
|
-
path: previousBlock.path,
|
|
5361
|
-
offset: 0
|
|
5362
|
-
},
|
|
5363
|
-
focus: {
|
|
5364
|
-
path: previousBlock.path,
|
|
5365
|
-
offset: 0
|
|
5366
|
-
}
|
|
5367
|
-
}
|
|
5368
|
-
}]]
|
|
5369
|
-
}, deletingEmptyTextBlockBeforeBlockObject = {
|
|
5370
|
-
on: "delete forward",
|
|
5371
|
-
guard: ({
|
|
5372
|
-
context
|
|
5373
|
-
}) => {
|
|
5374
|
-
const focusTextBlock = getFocusTextBlock(context), selectionCollapsed = selectionIsCollapsed(context), nextBlock = getNextBlock(context);
|
|
5375
|
-
return !focusTextBlock || !selectionCollapsed || !nextBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !types.isPortableTextTextBlock(nextBlock.node) ? {
|
|
5376
|
-
focusTextBlock,
|
|
5377
|
-
nextBlock
|
|
5378
|
-
} : !1;
|
|
5379
|
-
},
|
|
5380
|
-
actions: [(_, {
|
|
5381
|
-
focusTextBlock,
|
|
5382
|
-
nextBlock
|
|
5383
|
-
}) => [{
|
|
5384
|
-
type: "delete",
|
|
5385
|
-
selection: {
|
|
5386
|
-
anchor: {
|
|
5387
|
-
path: focusTextBlock.path,
|
|
5388
|
-
offset: 0
|
|
5389
|
-
},
|
|
5390
|
-
focus: {
|
|
5391
|
-
path: focusTextBlock.path,
|
|
5392
|
-
offset: 0
|
|
5393
|
-
}
|
|
5394
|
-
}
|
|
5395
|
-
}, {
|
|
5396
|
-
type: "select",
|
|
5397
|
-
selection: {
|
|
5398
|
-
anchor: {
|
|
5399
|
-
path: nextBlock.path,
|
|
5400
|
-
offset: 0
|
|
5401
|
-
},
|
|
5402
|
-
focus: {
|
|
5403
|
-
path: nextBlock.path,
|
|
5404
|
-
offset: 0
|
|
5405
|
-
}
|
|
5406
|
-
}
|
|
5407
|
-
}]]
|
|
5408
|
-
}, coreBlockObjectBehaviors = [breakingVoidBlock, deletingEmptyTextBlockAfterBlockObject, deletingEmptyTextBlockBeforeBlockObject], clearListOnBackspace = {
|
|
5409
|
-
on: "delete backward",
|
|
5410
|
-
guard: ({
|
|
5411
|
-
context
|
|
5412
|
-
}) => {
|
|
5413
|
-
const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
|
|
5414
|
-
return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0 && focusTextBlock.node.level === 1 ? {
|
|
5415
|
-
focusTextBlock
|
|
5416
|
-
} : !1;
|
|
5417
|
-
},
|
|
5418
|
-
actions: [(_, {
|
|
5419
|
-
focusTextBlock
|
|
5420
|
-
}) => [{
|
|
5421
|
-
type: "unset block",
|
|
5422
|
-
props: ["listItem", "level"],
|
|
5423
|
-
paths: [focusTextBlock.path]
|
|
5424
|
-
}]]
|
|
5425
|
-
}, unindentListOnBackspace = {
|
|
5426
|
-
on: "delete backward",
|
|
5427
|
-
guard: ({
|
|
5428
|
-
context
|
|
5429
|
-
}) => {
|
|
5430
|
-
const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
|
|
5431
|
-
return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0 && focusTextBlock.node.level !== void 0 && focusTextBlock.node.level > 1 ? {
|
|
5432
|
-
focusTextBlock,
|
|
5433
|
-
level: focusTextBlock.node.level - 1
|
|
5434
|
-
} : !1;
|
|
5435
|
-
},
|
|
5436
|
-
actions: [(_, {
|
|
5437
|
-
focusTextBlock,
|
|
5438
|
-
level
|
|
5439
|
-
}) => [{
|
|
5440
|
-
type: "set block",
|
|
5441
|
-
level,
|
|
5442
|
-
paths: [focusTextBlock.path]
|
|
5443
|
-
}]]
|
|
5444
|
-
}, coreListBehaviors = [clearListOnBackspace, unindentListOnBackspace], softReturn = {
|
|
5445
|
-
on: "insert soft break",
|
|
5446
|
-
actions: [() => [{
|
|
5447
|
-
type: "insert text",
|
|
5448
|
-
text: `
|
|
5449
|
-
`
|
|
5450
|
-
}]]
|
|
5451
|
-
}, coreBehaviors = [softReturn, ...coreBlockObjectBehaviors, ...coreListBehaviors], networkLogic = xstate.fromCallback(({
|
|
5467
|
+
const networkLogic = xstate.fromCallback(({
|
|
5452
5468
|
sendBack
|
|
5453
5469
|
}) => {
|
|
5454
5470
|
const onlineHandler = () => {
|
|
@@ -5474,7 +5490,7 @@ const breakingVoidBlock = {
|
|
|
5474
5490
|
"assign behaviors": xstate.assign({
|
|
5475
5491
|
behaviors: ({
|
|
5476
5492
|
event
|
|
5477
|
-
}) => (xstate.assertEvent(event, "update behaviors"),
|
|
5493
|
+
}) => (xstate.assertEvent(event, "update behaviors"), event.behaviors)
|
|
5478
5494
|
}),
|
|
5479
5495
|
"assign schema": xstate.assign({
|
|
5480
5496
|
schema: ({
|
|
@@ -5568,7 +5584,7 @@ const breakingVoidBlock = {
|
|
|
5568
5584
|
context: ({
|
|
5569
5585
|
input
|
|
5570
5586
|
}) => ({
|
|
5571
|
-
behaviors: input.behaviors
|
|
5587
|
+
behaviors: input.behaviors ?? coreBehaviors,
|
|
5572
5588
|
keyGenerator: input.keyGenerator,
|
|
5573
5589
|
pendingEvents: [],
|
|
5574
5590
|
schema: input.schema
|
|
@@ -6267,6 +6283,8 @@ function useEditor(config) {
|
|
|
6267
6283
|
}
|
|
6268
6284
|
exports.PortableTextEditable = PortableTextEditable;
|
|
6269
6285
|
exports.PortableTextEditor = PortableTextEditor;
|
|
6286
|
+
exports.coreBehavior = coreBehavior;
|
|
6287
|
+
exports.coreBehaviors = coreBehaviors;
|
|
6270
6288
|
exports.createMarkdownBehaviors = createMarkdownBehaviors;
|
|
6271
6289
|
exports.defineBehavior = defineBehavior;
|
|
6272
6290
|
exports.defineSchema = defineSchema;
|