@portabletext/editor 1.5.0 → 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/lib/index.esm.js CHANGED
@@ -140,6 +140,148 @@ function getNextBlock(context) {
140
140
  function isEmptyTextBlock(block) {
141
141
  return block.children.length === 1 && block.children[0].text === "";
142
142
  }
143
+ const breakingBlockObject = {
144
+ on: "insert break",
145
+ guard: ({
146
+ context
147
+ }) => !!getFocusBlockObject(context),
148
+ actions: [() => [{
149
+ type: "insert text block",
150
+ decorators: []
151
+ }]]
152
+ }, deletingEmptyTextBlockAfterBlockObject = {
153
+ on: "delete backward",
154
+ guard: ({
155
+ context
156
+ }) => {
157
+ const focusTextBlock = getFocusTextBlock(context), selectionCollapsed = selectionIsCollapsed(context), previousBlock = getPreviousBlock(context);
158
+ return !focusTextBlock || !selectionCollapsed || !previousBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !isPortableTextTextBlock(previousBlock.node) ? {
159
+ focusTextBlock,
160
+ previousBlock
161
+ } : !1;
162
+ },
163
+ actions: [(_, {
164
+ focusTextBlock,
165
+ previousBlock
166
+ }) => [{
167
+ type: "delete",
168
+ selection: {
169
+ anchor: {
170
+ path: focusTextBlock.path,
171
+ offset: 0
172
+ },
173
+ focus: {
174
+ path: focusTextBlock.path,
175
+ offset: 0
176
+ }
177
+ }
178
+ }, {
179
+ type: "select",
180
+ selection: {
181
+ anchor: {
182
+ path: previousBlock.path,
183
+ offset: 0
184
+ },
185
+ focus: {
186
+ path: previousBlock.path,
187
+ offset: 0
188
+ }
189
+ }
190
+ }]]
191
+ }, deletingEmptyTextBlockBeforeBlockObject = {
192
+ on: "delete forward",
193
+ guard: ({
194
+ context
195
+ }) => {
196
+ const focusTextBlock = getFocusTextBlock(context), selectionCollapsed = selectionIsCollapsed(context), nextBlock = getNextBlock(context);
197
+ return !focusTextBlock || !selectionCollapsed || !nextBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !isPortableTextTextBlock(nextBlock.node) ? {
198
+ focusTextBlock,
199
+ nextBlock
200
+ } : !1;
201
+ },
202
+ actions: [(_, {
203
+ focusTextBlock,
204
+ nextBlock
205
+ }) => [{
206
+ type: "delete",
207
+ selection: {
208
+ anchor: {
209
+ path: focusTextBlock.path,
210
+ offset: 0
211
+ },
212
+ focus: {
213
+ path: focusTextBlock.path,
214
+ offset: 0
215
+ }
216
+ }
217
+ }, {
218
+ type: "select",
219
+ selection: {
220
+ anchor: {
221
+ path: nextBlock.path,
222
+ offset: 0
223
+ },
224
+ focus: {
225
+ path: nextBlock.path,
226
+ offset: 0
227
+ }
228
+ }
229
+ }]]
230
+ }, coreBlockObjectBehaviors = {
231
+ breakingBlockObject,
232
+ deletingEmptyTextBlockAfterBlockObject,
233
+ deletingEmptyTextBlockBeforeBlockObject
234
+ }, clearListOnBackspace = {
235
+ on: "delete backward",
236
+ guard: ({
237
+ context
238
+ }) => {
239
+ const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
240
+ return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0 && focusTextBlock.node.level === 1 ? {
241
+ focusTextBlock
242
+ } : !1;
243
+ },
244
+ actions: [(_, {
245
+ focusTextBlock
246
+ }) => [{
247
+ type: "unset block",
248
+ props: ["listItem", "level"],
249
+ paths: [focusTextBlock.path]
250
+ }]]
251
+ }, unindentListOnBackspace = {
252
+ on: "delete backward",
253
+ guard: ({
254
+ context
255
+ }) => {
256
+ const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
257
+ 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 ? {
258
+ focusTextBlock,
259
+ level: focusTextBlock.node.level - 1
260
+ } : !1;
261
+ },
262
+ actions: [(_, {
263
+ focusTextBlock,
264
+ level
265
+ }) => [{
266
+ type: "set block",
267
+ level,
268
+ paths: [focusTextBlock.path]
269
+ }]]
270
+ }, coreListBehaviors = {
271
+ clearListOnBackspace,
272
+ unindentListOnBackspace
273
+ }, softReturn = {
274
+ on: "insert soft break",
275
+ actions: [() => [{
276
+ type: "insert text",
277
+ text: `
278
+ `
279
+ }]]
280
+ }, coreBehaviors = [softReturn, coreBlockObjectBehaviors.breakingBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockAfterBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockBeforeBlockObject, coreListBehaviors.clearListOnBackspace, coreListBehaviors.unindentListOnBackspace], coreBehavior = {
281
+ softReturn,
282
+ blockObjects: coreBlockObjectBehaviors,
283
+ lists: coreListBehaviors
284
+ };
143
285
  function createMarkdownBehaviors(config) {
144
286
  const automaticStyleOnSpace = {
145
287
  on: "insert text",
@@ -171,6 +313,10 @@ function createMarkdownBehaviors(config) {
171
313
  focusSpan,
172
314
  style
173
315
  }) => [{
316
+ type: "unset block",
317
+ props: ["listItem", "level"],
318
+ paths: [focusTextBlock.path]
319
+ }, {
174
320
  type: "set block",
175
321
  style,
176
322
  paths: [focusTextBlock.path]
@@ -5339,137 +5485,7 @@ function performDefaultAction({
5339
5485
  });
5340
5486
  }
5341
5487
  }
5342
- const breakingVoidBlock = {
5343
- on: "insert break",
5344
- guard: ({
5345
- context
5346
- }) => !!getFocusBlockObject(context),
5347
- actions: [() => [{
5348
- type: "insert text block",
5349
- decorators: []
5350
- }]]
5351
- }, deletingEmptyTextBlockAfterBlockObject = {
5352
- on: "delete backward",
5353
- guard: ({
5354
- context
5355
- }) => {
5356
- const focusTextBlock = getFocusTextBlock(context), selectionCollapsed = selectionIsCollapsed(context), previousBlock = getPreviousBlock(context);
5357
- return !focusTextBlock || !selectionCollapsed || !previousBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !isPortableTextTextBlock(previousBlock.node) ? {
5358
- focusTextBlock,
5359
- previousBlock
5360
- } : !1;
5361
- },
5362
- actions: [(_, {
5363
- focusTextBlock,
5364
- previousBlock
5365
- }) => [{
5366
- type: "delete",
5367
- selection: {
5368
- anchor: {
5369
- path: focusTextBlock.path,
5370
- offset: 0
5371
- },
5372
- focus: {
5373
- path: focusTextBlock.path,
5374
- offset: 0
5375
- }
5376
- }
5377
- }, {
5378
- type: "select",
5379
- selection: {
5380
- anchor: {
5381
- path: previousBlock.path,
5382
- offset: 0
5383
- },
5384
- focus: {
5385
- path: previousBlock.path,
5386
- offset: 0
5387
- }
5388
- }
5389
- }]]
5390
- }, deletingEmptyTextBlockBeforeBlockObject = {
5391
- on: "delete forward",
5392
- guard: ({
5393
- context
5394
- }) => {
5395
- const focusTextBlock = getFocusTextBlock(context), selectionCollapsed = selectionIsCollapsed(context), nextBlock = getNextBlock(context);
5396
- return !focusTextBlock || !selectionCollapsed || !nextBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !isPortableTextTextBlock(nextBlock.node) ? {
5397
- focusTextBlock,
5398
- nextBlock
5399
- } : !1;
5400
- },
5401
- actions: [(_, {
5402
- focusTextBlock,
5403
- nextBlock
5404
- }) => [{
5405
- type: "delete",
5406
- selection: {
5407
- anchor: {
5408
- path: focusTextBlock.path,
5409
- offset: 0
5410
- },
5411
- focus: {
5412
- path: focusTextBlock.path,
5413
- offset: 0
5414
- }
5415
- }
5416
- }, {
5417
- type: "select",
5418
- selection: {
5419
- anchor: {
5420
- path: nextBlock.path,
5421
- offset: 0
5422
- },
5423
- focus: {
5424
- path: nextBlock.path,
5425
- offset: 0
5426
- }
5427
- }
5428
- }]]
5429
- }, coreBlockObjectBehaviors = [breakingVoidBlock, deletingEmptyTextBlockAfterBlockObject, deletingEmptyTextBlockBeforeBlockObject], clearListOnBackspace = {
5430
- on: "delete backward",
5431
- guard: ({
5432
- context
5433
- }) => {
5434
- const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
5435
- return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0 && focusTextBlock.node.level === 1 ? {
5436
- focusTextBlock
5437
- } : !1;
5438
- },
5439
- actions: [(_, {
5440
- focusTextBlock
5441
- }) => [{
5442
- type: "unset block",
5443
- props: ["listItem", "level"],
5444
- paths: [focusTextBlock.path]
5445
- }]]
5446
- }, unindentListOnBackspace = {
5447
- on: "delete backward",
5448
- guard: ({
5449
- context
5450
- }) => {
5451
- const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
5452
- 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 ? {
5453
- focusTextBlock,
5454
- level: focusTextBlock.node.level - 1
5455
- } : !1;
5456
- },
5457
- actions: [(_, {
5458
- focusTextBlock,
5459
- level
5460
- }) => [{
5461
- type: "set block",
5462
- level,
5463
- paths: [focusTextBlock.path]
5464
- }]]
5465
- }, coreListBehaviors = [clearListOnBackspace, unindentListOnBackspace], softReturn = {
5466
- on: "insert soft break",
5467
- actions: [() => [{
5468
- type: "insert text",
5469
- text: `
5470
- `
5471
- }]]
5472
- }, coreBehaviors = [softReturn, ...coreBlockObjectBehaviors, ...coreListBehaviors], networkLogic = fromCallback(({
5488
+ const networkLogic = fromCallback(({
5473
5489
  sendBack
5474
5490
  }) => {
5475
5491
  const onlineHandler = () => {
@@ -5495,7 +5511,7 @@ const breakingVoidBlock = {
5495
5511
  "assign behaviors": assign({
5496
5512
  behaviors: ({
5497
5513
  event
5498
- }) => (assertEvent(event, "update behaviors"), [...coreBehaviors, ...event.behaviors])
5514
+ }) => (assertEvent(event, "update behaviors"), event.behaviors)
5499
5515
  }),
5500
5516
  "assign schema": assign({
5501
5517
  schema: ({
@@ -5589,7 +5605,7 @@ const breakingVoidBlock = {
5589
5605
  context: ({
5590
5606
  input
5591
5607
  }) => ({
5592
- behaviors: input.behaviors ? [...coreBehaviors, ...input.behaviors] : coreBehaviors,
5608
+ behaviors: input.behaviors ?? coreBehaviors,
5593
5609
  keyGenerator: input.keyGenerator,
5594
5610
  pendingEvents: [],
5595
5611
  schema: input.schema
@@ -6289,6 +6305,8 @@ function useEditor(config) {
6289
6305
  export {
6290
6306
  PortableTextEditable,
6291
6307
  PortableTextEditor,
6308
+ coreBehavior,
6309
+ coreBehaviors,
6292
6310
  createMarkdownBehaviors,
6293
6311
  defineBehavior,
6294
6312
  defineSchema,