edytor 6.0.0 → 7.0.1

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.
Files changed (93) hide show
  1. package/README.md +3 -3
  2. package/dist/cloudflare/DocumentRoom.d.ts +77 -2
  3. package/dist/cloudflare/DocumentRoom.js +37 -1
  4. package/dist/cloudflare/index.d.ts +1 -1
  5. package/dist/cloudflare/index.js +1 -1
  6. package/dist/cloudflare/room/access.d.ts +6 -1
  7. package/dist/cloudflare/room/access.js +30 -4
  8. package/dist/cloudflare/room/admission.d.ts +11 -0
  9. package/dist/cloudflare/room/admission.js +43 -10
  10. package/dist/cloudflare/room/context.d.ts +11 -2
  11. package/dist/cloudflare/room/context.js +17 -6
  12. package/dist/cloudflare/room/forged.d.ts +1 -1
  13. package/dist/cloudflare/room/forged.js +11 -9
  14. package/dist/cloudflare/room/frames.d.ts +2 -0
  15. package/dist/cloudflare/room/frames.js +2 -0
  16. package/dist/cloudflare/room/presence.js +1 -4
  17. package/dist/cloudflare/room/reseed.d.ts +93 -0
  18. package/dist/cloudflare/room/reseed.js +500 -0
  19. package/dist/cloudflare/room/scheduler.d.ts +1 -1
  20. package/dist/cloudflare/room/scheduler.js +9 -1
  21. package/dist/cloudflare/room/shared.d.ts +10 -0
  22. package/dist/cloudflare/room/shared.js +10 -0
  23. package/dist/cloudflare/room/storage.d.ts +7 -0
  24. package/dist/cloudflare/room/storage.js +33 -1
  25. package/dist/components/Content.svelte +7 -16
  26. package/dist/components/Edytor.svelte +32 -8
  27. package/dist/components/Edytor.svelte.d.ts +10 -1
  28. package/dist/components/EdytorRoot.svelte +17 -0
  29. package/dist/components/EdytorRoot.svelte.d.ts +4 -0
  30. package/dist/components/Suggestion.svelte +1 -1
  31. package/dist/components/Text.svelte +36 -33
  32. package/dist/components/Text.svelte.d.ts +2 -1
  33. package/dist/crdt/attribution/block.d.ts +3 -0
  34. package/dist/crdt/attribution/block.js +3 -2
  35. package/dist/crdt/doc/suggest.d.ts +6 -2
  36. package/dist/crdt/doc/suggest.js +6 -5
  37. package/dist/crdt/edytor-doc.d.ts +1 -1
  38. package/dist/crdt/edytor-doc.js +1 -1
  39. package/dist/crdt/engine-room.d.ts +4 -0
  40. package/dist/crdt/engine-room.js +6 -0
  41. package/dist/crdt/index.d.ts +2 -1
  42. package/dist/crdt/protocol.d.ts +2 -2
  43. package/dist/crdt/protocol.js +2 -2
  44. package/dist/crdt/protocols/auth.d.ts +8 -1
  45. package/dist/crdt/protocols/auth.js +14 -1
  46. package/dist/crdt/providers/index.d.ts +1 -0
  47. package/dist/crdt/providers/index.js +22 -3
  48. package/dist/crdt/providers/room.d.ts +15 -0
  49. package/dist/crdt/providers/room.js +16 -1
  50. package/dist/crdt/providers/websocket.d.ts +4 -2
  51. package/dist/crdt/providers/websocket.js +36 -9
  52. package/dist/crdt/reseed.d.ts +127 -0
  53. package/dist/crdt/reseed.js +533 -0
  54. package/dist/crdt/restore.d.ts +13 -1
  55. package/dist/crdt/restore.js +8 -3
  56. package/dist/crdt/schema.d.ts +6 -0
  57. package/dist/crdt/schema.js +6 -0
  58. package/dist/crdt/structs.d.ts +8 -11
  59. package/dist/crdt/structs.js +25 -44
  60. package/dist/crdt/text/index/build.d.ts +3 -9
  61. package/dist/crdt/text/index/build.js +87 -181
  62. package/dist/crdt/vendor/yjs/UPSTREAM.md +101 -5
  63. package/dist/crdt/vendor/yjs/dts/index.d.ts +1 -1
  64. package/dist/crdt/vendor/yjs/dts/utils/Transaction.d.ts +10 -10
  65. package/dist/crdt/vendor/yjs/dts/utils/encoding.d.ts +1 -0
  66. package/dist/crdt/vendor/yjs/src/index.js +1 -1
  67. package/dist/crdt/vendor/yjs/src/structs/Item.js +24 -13
  68. package/dist/crdt/vendor/yjs/src/utils/Transaction.js +12 -10
  69. package/dist/crdt/vendor/yjs/src/utils/encoding.js +42 -1
  70. package/dist/edytor.svelte.js +1 -1
  71. package/dist/events/onBeforeInput.js +7 -0
  72. package/dist/events/onKeyDown.js +3 -2
  73. package/dist/index.d.ts +1 -1
  74. package/dist/index.js +1 -1
  75. package/dist/plugins/blockHandles/BlockHandles.svelte +32 -5
  76. package/dist/selection/selection.svelte.d.ts +1 -1
  77. package/dist/selection/selection.svelte.js +87 -106
  78. package/dist/session/attempt.d.ts +6 -0
  79. package/dist/session/attempt.js +6 -0
  80. package/dist/session/commands.js +49 -51
  81. package/dist/session/composition.svelte.js +19 -7
  82. package/dist/surface/attributes.d.ts +3 -3
  83. package/dist/surface/attributes.js +2 -2
  84. package/dist/surface/cells.d.ts +7 -0
  85. package/dist/surface/cells.js +7 -0
  86. package/dist/surface/observer.svelte.d.ts +7 -7
  87. package/dist/surface/observer.svelte.js +225 -313
  88. package/dist/surface/pin.svelte.d.ts +7 -10
  89. package/dist/surface/pin.svelte.js +12 -15
  90. package/dist/surface/projector.svelte.d.ts +6 -3
  91. package/dist/surface/projector.svelte.js +20 -12
  92. package/dist/themes/notion.css +7 -0
  93. package/package.json +1 -1
@@ -31,18 +31,18 @@ export class Transaction {
31
31
  */
32
32
  insertSet: import("./ids.js").IdSet;
33
33
  /**
34
- * YP20: the visibility changes hold records made, in order: per item,
35
- * `client, clock, len` (`len > 0`: shown, `< 0`: hidden; an item removed
36
- * while held is logged shown, as the delete set counts it hidden).
34
+ * What the transaction did to items, in order: per run of one writer's
35
+ * items `kind, client, clock, len` (an item that continues the last entry
36
+ * extends it). Kind 0, an edit: integrated (`len > 0`, before its content
37
+ * integrates; an item integrated removed logs none) or removed (`len < 0`);
38
+ * kind 1, a hold record's
39
+ * (YP20): shown (`len > 0`) or hidden (`< 0`; an item removed while held
40
+ * is logged shown, so an item's kinds 0 and 1 sum to its visibility
41
+ * change); kind 2, its mover changed (YP22: a move record integrated or
42
+ * deleted, a moved unit removed).
37
43
  * @type {Array<number>}
38
44
  */
39
- holds: Array<number>;
40
- /**
41
- * YP22: the units whose mover changed (a move record integrated or
42
- * deleted, a moved unit removed), in order: per item `client, clock, len`.
43
- * @type {Array<number>}
44
- */
45
- moves: Array<number>;
45
+ log: Array<number>;
46
46
  /**
47
47
  * All types that were directly modified (property added or child
48
48
  * inserted/deleted). New types are not included in this Set.
@@ -5,6 +5,7 @@ export function writeStateAsUpdate(encoder: UpdateEncoder, doc: Doc, targetState
5
5
  export function encodeStateAsUpdate(doc: Doc, encodedTargetStateVector?: Uint8Array): Uint8Array<ArrayBuffer>;
6
6
  export function mergeUpdates(updates: Array<Uint8Array<ArrayBuffer>>): Uint8Array<ArrayBuffer>;
7
7
  export function diffUpdate(update: Uint8Array, sv: Uint8Array): Uint8Array<ArrayBuffer>;
8
+ export function clipUpdate(update: Uint8Array, sv: Uint8Array, ds: import("./ids.js").IdSet): Uint8Array<ArrayBuffer>;
8
9
  export function decodeStateVector(decodedState: Uint8Array): Map<number, number>;
9
10
  export function encodeStateVector(doc: Doc | Map<number, number>): Uint8Array<ArrayBuffer>;
10
11
  import { UpdateEncoder } from './UpdateEncoder.js';
@@ -7,7 +7,7 @@ export { IdSet, createDeleteSetFromStructStore, diffIdSet, createIdSet, mergeIdS
7
7
  export { Doc } from './utils/Doc.js'
8
8
  export { UpdateDecoder } from './utils/UpdateDecoder.js'
9
9
  export { UpdateEncoder } from './utils/UpdateEncoder.js'
10
- export { applyUpdate, encodeStateAsUpdate, encodeStateVector, decodeStateVector, diffUpdate, mergeUpdates } from './utils/encoding.js'
10
+ export { applyUpdate, encodeStateAsUpdate, encodeStateVector, decodeStateVector, diffUpdate, clipUpdate, mergeUpdates } from './utils/encoding.js' // YP34: clipUpdate
11
11
  export { ID, createID, compareIDs, findRootTypeKey } from './utils/ID.js'
12
12
  export { isParentOf } from './utils/isParentOf.js'
13
13
  export { idAtIndex, indexOfId } from './utils/positions.js' // YP19
@@ -308,6 +308,8 @@ export class Item extends AbstractStruct {
308
308
  }
309
309
  addStructToIdSet(transaction.insertSet, this)
310
310
  transaction.doc.store.add(this)
311
+ // YP33: log the units it shows before its content integrates (a node's children follow it)
312
+ logItem(transaction, 0, this, this.content.constructor === ContentDeleted ? 0 : this.length, false)
311
313
  this.content.integrate(transaction, this)
312
314
  // add parent to transaction.changed
313
315
  addChangedTypeToTransaction(transaction, /** @type {YNode} */ (this.parent), this.parentSub)
@@ -393,7 +395,7 @@ export class Item extends AbstractStruct {
393
395
  // adjust the length of parent
394
396
  if (this.holds > 0) {
395
397
  // YP20: already hidden — the delete set counts it again, the log gives it back
396
- logHold(transaction, this, this.length)
398
+ logItem(transaction, 1, this, this.length) // YP33
397
399
  } else if (this.movers !== null) {
398
400
  // YP22: hidden at home already; its mover shows it no more (`gone`)
399
401
  logMove(transaction, this, this.mover)
@@ -411,7 +413,7 @@ export class Item extends AbstractStruct {
411
413
  }
412
414
  this.markDeleted()
413
415
  transaction.deleteSet.add(this.id.client, this.id.clock, this.length)
414
- addChangedTypeToTransaction(transaction, parent, this.parentSub)
416
+ logItem(transaction, 0, this, -this.length) // YP33
415
417
  // YP14: a node a concurrent value replaced keeps its subtree (the document asked)
416
418
  if (!isKeptReplaced(this)) this.content.delete(transaction, this) // YP22: a move record drops itself from its units' movers
417
419
  }
@@ -929,26 +931,36 @@ export class ContentDeleted {
929
931
  }
930
932
 
931
933
  // YP20 begin (edytor fork: hold records — see UPSTREAM.md YP20)
934
+ // YP33 begin (edytor fork: one log of what a transaction did to items — see UPSTREAM.md YP33)
932
935
  /**
933
- * Log that a hold changed `item`'s visibility (`len > 0`: shown, `< 0`:
934
- * hidden) in `tr.holds`, in order, and its parent as changed.
936
+ * Log `len` units of `item` as `kind` (0 an edit, 1 a hold, 2 a move) in
937
+ * `tr.log`, in order, and (unless `mark` is false) its parent as changed.
938
+ * An entry the last one continues (its kind, its client, the next clock, its
939
+ * sign) extends it, so a run of one writer's items is one entry; `len` 0
940
+ * logs none.
935
941
  *
936
942
  * @param {Transaction} tr
943
+ * @param {number} kind
937
944
  * @param {Item} item
938
945
  * @param {number} len
946
+ * @param {boolean} [mark]
939
947
  */
940
- const logHold = (tr, item, len) => {
941
- tr.holds.push(item.id.client, item.id.clock, len)
942
- addChangedTypeToTransaction(tr, /** @type {YNode} */ (item.parent), item.parentSub)
948
+ const logItem = (tr, kind, item, len, mark = true) => {
949
+ const log = tr.log
950
+ const n = log.length
951
+ const { client, clock } = item.id
952
+ if (log[n - 4] === kind && log[n - 3] === client && log[n - 2] + math.abs(log[n - 1]) === clock && log[n - 1] * len > 0) log[n - 1] += len
953
+ else if (len !== 0) log.push(kind, client, clock, len)
954
+ if (mark) addChangedTypeToTransaction(tr, /** @type {YNode} */ (item.parent), item.parentSub)
943
955
  }
956
+ // YP33 end
944
957
 
945
958
  /**
946
959
  * Add `delta` (1, or -1: release) of a hold record (`record` null: `holds`)
947
960
  * or of the move record `record` (its `movers`, YP22; a record never moves a
948
961
  * record) to `item`. An item that is not removed and starts or stops being
949
962
  * hidden moves its parent's length and drops its search markers; a hold that
950
- * does is logged (`tr.holds`), and so is a unit whose mover changed
951
- * (`tr.moves`).
963
+ * does is logged (`tr.log`, YP33), and so is a unit whose mover changed.
952
964
  *
953
965
  * @param {Transaction} tr
954
966
  * @param {Item} item
@@ -976,7 +988,7 @@ const holdItem = (tr, item, delta, record) => {
976
988
  if (item.countable && item.parentSub === null) parent._length += len
977
989
  // the indices the search markers counted moved (a held delete moves them itself)
978
990
  if (parent._searchMarker) parent._searchMarker.length = 0
979
- if (record === null) logHold(tr, item, len)
991
+ if (record === null) logItem(tr, 1, item, len) // YP33
980
992
  }
981
993
  const after = item.mover
982
994
  if (before !== after) {
@@ -1223,15 +1235,14 @@ const stronger = (a, b) =>
1223
1235
 
1224
1236
  /**
1225
1237
  * Log that `item`'s mover changed (or it left its mover: removed) in
1226
- * `tr.moves`, in order, and its home and its new mover's sequences as changed.
1238
+ * `tr.log` (YP33), and its home and its new mover's sequences as changed.
1227
1239
  *
1228
1240
  * @param {Transaction} tr
1229
1241
  * @param {Item} item
1230
1242
  * @param {Item|null} mover
1231
1243
  */
1232
1244
  const logMove = (tr, item, mover) => {
1233
- tr.moves.push(item.id.client, item.id.clock, item.length)
1234
- addChangedTypeToTransaction(tr, /** @type {YNode} */ (item.parent), item.parentSub)
1245
+ logItem(tr, 2, item, item.length) // YP33
1235
1246
  if (mover !== null) addChangedTypeToTransaction(tr, /** @type {YNode} */ (mover.parent), null)
1236
1247
  }
1237
1248
 
@@ -40,19 +40,21 @@ export class Transaction {
40
40
  * Describes the set of inserted items by ids
41
41
  */
42
42
  this.insertSet = createIdSet()
43
+ // YP33 begin (edytor fork: one log of what the transaction did to items — see UPSTREAM.md YP33)
43
44
  /**
44
- * YP20: the visibility changes hold records made, in order: per item,
45
- * `client, clock, len` (`len > 0`: shown, `< 0`: hidden; an item removed
46
- * while held is logged shown, as the delete set counts it hidden).
45
+ * What the transaction did to items, in order: per run of one writer's
46
+ * items `kind, client, clock, len` (an item that continues the last entry
47
+ * extends it). Kind 0, an edit: integrated (`len > 0`, before its content
48
+ * integrates; an item integrated removed logs none) or removed (`len < 0`);
49
+ * kind 1, a hold record's
50
+ * (YP20): shown (`len > 0`) or hidden (`< 0`; an item removed while held
51
+ * is logged shown, so an item's kinds 0 and 1 sum to its visibility
52
+ * change); kind 2, its mover changed (YP22: a move record integrated or
53
+ * deleted, a moved unit removed).
47
54
  * @type {Array<number>}
48
55
  */
49
- this.holds = []
50
- /**
51
- * YP22: the units whose mover changed (a move record integrated or
52
- * deleted, a moved unit removed), in order: per item `client, clock, len`.
53
- * @type {Array<number>}
54
- */
55
- this.moves = []
56
+ this.log = []
57
+ // YP33 end
56
58
  /**
57
59
  * All types that were directly modified (property added or child
58
60
  * inserted/deleted). New types are not included in this Set.
@@ -22,7 +22,7 @@ import * as array from 'lib0-v14/array'
22
22
 
23
23
  import { getStateVector, StructStore } from './StructStore.js'
24
24
  import { getItemCleanStart, getItemCleanEnd } from './transaction-helpers.js'
25
- import { createIdSet, IdRange, readAndApplyDeleteSet, readIdSet, mergeIdSets, writeIdSet } from './ids.js'
25
+ import { createIdSet, IdRange, readAndApplyDeleteSet, readIdSet, mergeIdSets, writeIdSet, intersectSets } from './ids.js' // YP34: intersectSets
26
26
  import { createID, ID } from './ID.js'
27
27
  import { UpdateDecoder } from './UpdateDecoder.js'
28
28
  import { UpdateEncoder } from './UpdateEncoder.js'
@@ -469,6 +469,47 @@ export const diffUpdate = (update, sv) => {
469
469
  return encoder.toUint8Array()
470
470
  }
471
471
 
472
+ // YP34 begin
473
+ /**
474
+ * The part of `update` that the state vector `sv` covers, with only the
475
+ * deletes `ds` also holds: `update` as it read at an earlier state (the
476
+ * counterpart of `diffUpdate`). A struct that crosses the state vector is
477
+ * cut at it; a skip is written only where a later struct of its client
478
+ * follows it.
479
+ *
480
+ * @param {Uint8Array} update
481
+ * @param {Uint8Array} sv
482
+ * @param {import('./ids.js').IdSet} ds
483
+ */
484
+ export const clipUpdate = (update, sv, ds) => {
485
+ const state = decodeStateVector(sv)
486
+ const encoder = new UpdateEncoder()
487
+ const lazyStructWriter = new LazyStructWriter(encoder)
488
+ const decoder = new UpdateDecoder(decoding.createDecoder(update))
489
+ const reader = new LazyStructReader(decoder, false)
490
+ /** @type {Array<Skip>} */
491
+ let skips = []
492
+ let client = -1
493
+ for (let curr = reader.curr; curr !== null; curr = reader.next()) {
494
+ if (curr.id.client !== client) [client, skips] = [curr.id.client, []]
495
+ const svClock = state.get(client) || 0
496
+ if (curr.id.clock >= svClock) continue
497
+ if (curr.constructor === Skip) {
498
+ skips.push(/** @type {Skip} */ (curr))
499
+ continue
500
+ }
501
+ if (lazyStructWriter.written > 0 && lazyStructWriter.currClient === client) {
502
+ for (const skip of skips) writeStructToLazyStructWriter(lazyStructWriter, skip, 0, 0)
503
+ }
504
+ skips = []
505
+ writeStructToLazyStructWriter(lazyStructWriter, curr, 0, math.max(curr.id.clock + curr.length - svClock, 0))
506
+ }
507
+ finishLazyStructWriting(lazyStructWriter)
508
+ writeIdSet(encoder, intersectSets(readIdSet(decoder), ds))
509
+ return encoder.toUint8Array()
510
+ }
511
+ // YP34 end
512
+
472
513
  /**
473
514
  * Read decodedState and return State as Map.
474
515
  *
@@ -735,7 +735,7 @@ export class Edytor {
735
735
  if (!at)
736
736
  return [];
737
737
  const { cell, segment } = at;
738
- return this.pin.shown(cell, segment, this.definitionOf(cell.type).transformText).deltas;
738
+ return this.pin.shown(cell, segment, this.definitionOf(cell.type).transformText);
739
739
  };
740
740
  /** @internal The handle of inline atom `atom`, shown in block `id`. */
741
741
  atomAt = (id, atom) => this.idToBlock.atom(id, atom);
@@ -322,6 +322,7 @@ const runKeyAttempt = async (edytor, attempt) => {
322
322
  // A real `beforeinput` or a newer key may have taken over meanwhile.
323
323
  if (edytor.attempts.key !== attempt)
324
324
  return;
325
+ edytor.attempts.ran = attempt.inputType;
325
326
  await edytor.userInput(() => occur(edytor, { inputType: attempt.inputType, cancelable: false }, attempt, INTENTS[attempt.inputType]?.key ?? null, attempt));
326
327
  };
327
328
  export async function onBeforeInput(event) {
@@ -329,6 +330,12 @@ export async function onBeforeInput(event) {
329
330
  const [key, offered] = keyed(this);
330
331
  const { inputType } = event;
331
332
  const kind = kindOf(inputType);
333
+ // The key the deadline ran, announced late (iOS's software keyboard,
334
+ // `sel.key.late-announcement`): that occurrence again, never run twice.
335
+ const ran = this.attempts.ran;
336
+ this.attempts.ran = null;
337
+ if (ran === inputType)
338
+ return event.preventDefault();
332
339
  if (inputType === 'deleteByDrag' && event.isTrusted) {
333
340
  event.preventDefault();
334
341
  return this.selection.pointer.release();
@@ -73,8 +73,9 @@ const getStructuralFallbackInputType = (edytor, event) => {
73
73
  return !isCollapsed || atBlockEdge || atTextEdge || atMarker ? intent : null;
74
74
  };
75
75
  export function onKeyDown(e) {
76
- // A keydown the bindings are not offered offers no key to its `beforeinput`.
77
- this.keymap.offered = null;
76
+ // A keydown the bindings are not offered offers no key to its `beforeinput`,
77
+ // and a key's late announcement comes before the next key's keydown.
78
+ this.keymap.offered = this.attempts.ran = null;
78
79
  if (e.defaultPrevented) {
79
80
  return;
80
81
  }
package/dist/index.d.ts CHANGED
@@ -25,7 +25,7 @@
25
25
  * This module re-exports the `.svelte` component, so it requires a
26
26
  * bundler that understands Svelte (vite-plugin-svelte).
27
27
  */
28
- export { default as Edytor } from './components/Edytor.svelte';
28
+ export { default as Edytor } from './components/EdytorRoot.svelte';
29
29
  export { useEdytor } from './edytor.svelte.js';
30
30
  /** The editor instance plugins, hotkeys and `bind:edytor` receive (`Edytor` names the component). */
31
31
  export type { Edytor as EdytorInstance, EdytorDocData } from './edytor.svelte.js';
package/dist/index.js CHANGED
@@ -26,7 +26,7 @@
26
26
  * bundler that understands Svelte (vite-plugin-svelte).
27
27
  */
28
28
  // ── The editor ─────────────────────────────────────────────────────────
29
- export { default as Edytor } from './components/Edytor.svelte';
29
+ export { default as Edytor } from './components/EdytorRoot.svelte';
30
30
  export { useEdytor } from './edytor.svelte.js';
31
31
  export { Block } from './block/block.svelte.js';
32
32
  export { InlineBlock } from './block/inlineBlock.svelte.js';
@@ -48,16 +48,28 @@
48
48
  if (change.order.size || change.added.size || change.removed.size) structure++;
49
49
  })
50
50
  );
51
+ /**
52
+ * The blocks whose handle stays mounted beyond the near and hovered ones,
53
+ * and shows on a touch screen (no hover there): the selected blocks, the
54
+ * focused handle's, the dragged one. The blocks the selection's text is in
55
+ * show theirs too (`data-active`), mounted once near: a new block paints
56
+ * before its handle mounts (`handles.after-paint`).
57
+ */
58
+ const active = $derived.by(() => {
59
+ const out = new Set<string>();
60
+ for (const block of edytor.selection.selectedBlocks) out.add(block.id);
61
+ if (focused !== null) out.add(focused);
62
+ if (controller.dragging) out.add(controller.dragging);
63
+ return out;
64
+ });
65
+
51
66
  /**
52
67
  * The few blocks that show a handle, sorted into document order: never a
53
68
  * walk of the whole document (a structural commit on a long page).
54
69
  */
55
70
  const ids = $derived.by(() => {
56
71
  void structure;
57
- const shown = new Set([...near, ...hovered]);
58
- for (const block of edytor.selection.selectedBlocks) shown.add(block.id);
59
- if (focused !== null) shown.add(focused);
60
- if (controller.dragging) shown.add(controller.dragging);
72
+ const shown = new Set([...near, ...hovered, ...active]);
61
73
  // Document order by index paths (O(depth) each): no whole-document order is rebuilt.
62
74
  const paths = new Map<string, number[]>();
63
75
  for (const id of shown) {
@@ -161,6 +173,9 @@
161
173
  data-edytor-block-handle-host
162
174
  data-block-id={id}
163
175
  data-visible={hovered.has(id) ? 'true' : undefined}
176
+ data-active={active.has(id) || edytor.selection.projection.blocks.includes(id)
177
+ ? 'true'
178
+ : undefined}
164
179
  data-over-gap={overGaps.has(id) ? 'true' : undefined}
165
180
  data-dragging={controller.dragging && controller.dragging !== id ? 'true' : undefined}
166
181
  data-selecting={edytor.selection.dragging ? 'true' : undefined}
@@ -237,10 +252,22 @@
237
252
  opacity: 1;
238
253
  }
239
254
 
255
+ /* A touch screen has no hover: a handle shows for the block the selection
256
+ * is in (Notion's), never for a touched one (the hover a touch leaves
257
+ * behind), and only a shown one takes a tap, so a tap in the gutter never
258
+ * opens a hidden block's menu. A touch that showed a handle would also
259
+ * cost a tap: iOS Safari takes a touch whose hover reveals content as a
260
+ * hover only, and sends no click. */
240
261
  @media (hover: none) {
241
262
  [data-edytor-block-handle-host] {
242
- opacity: 1;
243
263
  padding-inline-end: 0;
244
264
  }
265
+ [data-edytor-block-handle-host]:not([data-active='true']) {
266
+ opacity: 0;
267
+ pointer-events: none;
268
+ }
269
+ [data-edytor-block-handle-host][data-active='true'] {
270
+ opacity: 1;
271
+ }
245
272
  }
246
273
  </style>
@@ -34,7 +34,7 @@ export type Caret = {
34
34
  * order), comparing boundary points — a focus on an ancestor element of the
35
35
  * anchor (`(textElement, childCount)`) is after it.
36
36
  */
37
- export declare const isBackward: (selection: {
37
+ export declare const isBackward: ({ anchorNode, anchorOffset, focusNode, focusOffset }: {
38
38
  anchorNode: Node | null;
39
39
  anchorOffset: number;
40
40
  focusNode: Node | null;