edytor 5.0.0 → 7.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.
Files changed (137) 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 +73 -76
  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/Edytor.svelte +18 -3
  26. package/dist/components/Edytor.svelte.d.ts +10 -1
  27. package/dist/components/EdytorRoot.svelte +17 -0
  28. package/dist/components/EdytorRoot.svelte.d.ts +4 -0
  29. package/dist/components/Suggestion.svelte +1 -1
  30. package/dist/crdt/attribution/block.d.ts +3 -0
  31. package/dist/crdt/attribution/block.js +3 -2
  32. package/dist/crdt/doc/history.js +2 -3
  33. package/dist/crdt/doc/ops.d.ts +81 -0
  34. package/dist/crdt/doc/ops.js +1898 -0
  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 +157 -157
  38. package/dist/crdt/edytor-doc.js +15 -43
  39. package/dist/crdt/engine-room.d.ts +4 -0
  40. package/dist/crdt/engine-room.js +6 -0
  41. package/dist/crdt/flow.d.ts +4 -46
  42. package/dist/crdt/flow.js +2 -262
  43. package/dist/crdt/index.d.ts +64 -75
  44. package/dist/crdt/operations.d.ts +1 -1
  45. package/dist/crdt/placement/resolve.d.ts +1 -1
  46. package/dist/crdt/protocol.d.ts +2 -2
  47. package/dist/crdt/protocol.js +2 -2
  48. package/dist/crdt/protocols/auth.d.ts +8 -1
  49. package/dist/crdt/protocols/auth.js +14 -1
  50. package/dist/crdt/protocols/awareness.js +46 -81
  51. package/dist/crdt/providers/index.d.ts +11 -22
  52. package/dist/crdt/providers/index.js +22 -3
  53. package/dist/crdt/providers/indexeddb.d.ts +6 -10
  54. package/dist/crdt/providers/indexeddb.js +10 -16
  55. package/dist/crdt/providers/room.d.ts +26 -0
  56. package/dist/crdt/providers/room.js +41 -12
  57. package/dist/crdt/providers/websocket.d.ts +10 -14
  58. package/dist/crdt/providers/websocket.js +43 -23
  59. package/dist/crdt/rangeDelete.d.ts +2 -47
  60. package/dist/crdt/rangeDelete.js +1 -169
  61. package/dist/crdt/reseed.d.ts +127 -0
  62. package/dist/crdt/reseed.js +533 -0
  63. package/dist/crdt/restore.d.ts +13 -1
  64. package/dist/crdt/restore.js +8 -3
  65. package/dist/crdt/schema.d.ts +6 -0
  66. package/dist/crdt/schema.js +6 -0
  67. package/dist/crdt/structs.d.ts +8 -11
  68. package/dist/crdt/structs.js +25 -44
  69. package/dist/crdt/text/index/build.d.ts +119 -0
  70. package/dist/crdt/text/index/build.js +2801 -0
  71. package/dist/crdt/text/index/shared.d.ts +2 -6
  72. package/dist/crdt/text/index/shared.js +2 -5
  73. package/dist/crdt/text/model.js +2 -3
  74. package/dist/crdt/text/runs.d.ts +9 -12
  75. package/dist/crdt/text/runs.js +2 -165
  76. package/dist/crdt/vendor/yjs/UPSTREAM.md +101 -5
  77. package/dist/crdt/vendor/yjs/dts/index.d.ts +1 -1
  78. package/dist/crdt/vendor/yjs/dts/utils/Transaction.d.ts +10 -10
  79. package/dist/crdt/vendor/yjs/dts/utils/encoding.d.ts +1 -0
  80. package/dist/crdt/vendor/yjs/src/index.js +1 -1
  81. package/dist/crdt/vendor/yjs/src/structs/Item.js +24 -13
  82. package/dist/crdt/vendor/yjs/src/utils/Transaction.js +12 -10
  83. package/dist/crdt/vendor/yjs/src/utils/encoding.js +42 -1
  84. package/dist/events/domTextOffset.d.ts +2 -0
  85. package/dist/events/domTextOffset.js +8 -0
  86. package/dist/export/forms.d.ts +50 -50
  87. package/dist/index.d.ts +1 -1
  88. package/dist/index.js +1 -1
  89. package/dist/plugins/richtext/RichTextPlugin.svelte +63 -61
  90. package/dist/plugins/richtext/richTextOperations.js +26 -32
  91. package/dist/selection/selection.svelte.d.ts +1 -1
  92. package/dist/selection/selection.svelte.js +87 -106
  93. package/dist/selection/selection.utils.js +5 -8
  94. package/dist/session/commands.js +49 -51
  95. package/dist/session/handles.js +3 -7
  96. package/dist/surface/attributes.d.ts +3 -3
  97. package/dist/surface/attributes.js +2 -2
  98. package/dist/surface/observer.svelte.d.ts +7 -7
  99. package/dist/surface/observer.svelte.js +225 -336
  100. package/dist/surface/projector.svelte.js +2 -2
  101. package/dist/utils.d.ts +5 -0
  102. package/dist/utils.js +7 -0
  103. package/package.json +1 -1
  104. package/dist/crdt/doc/capability.d.ts +0 -56
  105. package/dist/crdt/doc/capability.js +0 -207
  106. package/dist/crdt/doc/content.d.ts +0 -16
  107. package/dist/crdt/doc/content.js +0 -77
  108. package/dist/crdt/doc/delete.d.ts +0 -15
  109. package/dist/crdt/doc/delete.js +0 -84
  110. package/dist/crdt/doc/layout.d.ts +0 -9
  111. package/dist/crdt/doc/layout.js +0 -178
  112. package/dist/crdt/doc/meta.d.ts +0 -19
  113. package/dist/crdt/doc/meta.js +0 -198
  114. package/dist/crdt/doc/moves.d.ts +0 -21
  115. package/dist/crdt/doc/moves.js +0 -274
  116. package/dist/crdt/doc/split-merge.d.ts +0 -10
  117. package/dist/crdt/doc/split-merge.js +0 -179
  118. package/dist/crdt/doc/steps.d.ts +0 -65
  119. package/dist/crdt/doc/steps.js +0 -311
  120. package/dist/crdt/text/index/cache.d.ts +0 -16
  121. package/dist/crdt/text/index/cache.js +0 -175
  122. package/dist/crdt/text/index/claims.d.ts +0 -18
  123. package/dist/crdt/text/index/claims.js +0 -203
  124. package/dist/crdt/text/index/fold.d.ts +0 -21
  125. package/dist/crdt/text/index/fold.js +0 -656
  126. package/dist/crdt/text/index/layout.d.ts +0 -22
  127. package/dist/crdt/text/index/layout.js +0 -258
  128. package/dist/crdt/text/index/placement.d.ts +0 -47
  129. package/dist/crdt/text/index/placement.js +0 -738
  130. package/dist/crdt/text/index/records.d.ts +0 -13
  131. package/dist/crdt/text/index/records.js +0 -139
  132. package/dist/crdt/text/index/report.d.ts +0 -18
  133. package/dist/crdt/text/index/report.js +0 -337
  134. package/dist/crdt/text/index/state.d.ts +0 -197
  135. package/dist/crdt/text/index/state.js +0 -116
  136. package/dist/crdt/text/index/streams.d.ts +0 -25
  137. package/dist/crdt/text/index/streams.js +0 -248
@@ -193,6 +193,8 @@
193
193
  params,
194
194
  onSyncExpired,
195
195
  onSyncRefused,
196
+ rebuild,
197
+ adopt,
196
198
  requireHydration,
197
199
  snapshot,
198
200
  actor,
@@ -208,7 +210,15 @@
208
210
  autocapitalize = 'none',
209
211
  inputmode,
210
212
  enterkeyhint
211
- }: EdytorProps = $props();
213
+ }: EdytorProps & {
214
+ /** The view's own rebuild (`EdytorRoot`): a new view on a new document. */
215
+ rebuild?: () => void;
216
+ /**
217
+ * Hands the view to `EdytorRoot`, which a binding cannot: on the server a
218
+ * bound prop renders the tree twice, and the discarded view never ends.
219
+ */
220
+ adopt?: (view: EdytorClass) => void;
221
+ } = $props();
212
222
 
213
223
  const initialEdytorOptions = untrack(() => ({
214
224
  readonly,
@@ -227,6 +237,7 @@
227
237
  }));
228
238
 
229
239
  edytor = new EdytorClass(initialEdytorOptions);
240
+ untrack(() => adopt)?.(edytor);
230
241
 
231
242
  // ONE attach path for owned and injected documents: `attachSync`
232
243
  // tracks the provider on the DOCUMENT's lifetime (one provider per
@@ -276,7 +287,11 @@
276
287
  }
277
288
  // Subscribe first, then replay the standing refusal isolated like the
278
289
  // later ones: a throwing callback still hears the next refusal.
279
- offRefused = document.onSyncRefused((next) => onSyncRefused?.(next));
290
+ offRefused = document.onSyncRefused((next) => {
291
+ onSyncRefused?.(next);
292
+ // A re-seed (`4410`): a view that owns its document builds itself again on a new one.
293
+ if (next.code === CLOSE.reseeded && !edytorDocument) rebuild?.();
294
+ });
280
295
  if (refusal) {
281
296
  try {
282
297
  onSyncRefused?.(refusal);
@@ -379,7 +394,7 @@
379
394
  contenteditable="false"
380
395
  aria-hidden="true"
381
396
  style="display: none"
382
- use:edytor.surface.anchor
397
+ use:edytor.surface.own
383
398
  ></span>
384
399
  </div>
385
400
  {:else if snapshot}
@@ -113,6 +113,15 @@ export type EdytorProps = {
113
113
  import type { JSONDoc } from '../utils/json.js';
114
114
  import type { HotKey, HotKeyCombination } from '../session/keymap.js';
115
115
  import type { EdytorSelection } from '../selection/selection.svelte.js';
116
- declare const Edytor: import("svelte").Component<EdytorProps, {}, "edytor">;
116
+ type $$ComponentProps = EdytorProps & {
117
+ /** The view's own rebuild (`EdytorRoot`): a new view on a new document. */
118
+ rebuild?: () => void;
119
+ /**
120
+ * Hands the view to `EdytorRoot`, which a binding cannot: on the server a
121
+ * bound prop renders the tree twice, and the discarded view never ends.
122
+ */
123
+ adopt?: (view: EdytorClass) => void;
124
+ };
125
+ declare const Edytor: import("svelte").Component<$$ComponentProps, {}, "edytor">;
117
126
  type Edytor = ReturnType<typeof Edytor>;
118
127
  export default Edytor;
@@ -0,0 +1,17 @@
1
+ <script lang="ts">
2
+ // The public `<Edytor>`: the view, built again on a new document when the
3
+ // room re-seeds the one it owns (`room.reseed.protocol`).
4
+ import Edytor, { type EdytorProps } from './Edytor.svelte';
5
+
6
+ // eslint-disable-next-line no-useless-assignment -- bindable: `adopt` assigns it
7
+ let { edytor = $bindable(), ...props }: EdytorProps = $props();
8
+ let epoch = $state(0);
9
+ </script>
10
+
11
+ <!-- A view built again loads the room's document: it never seeds its value over it. -->
12
+ {#key epoch}<Edytor
13
+ {...props}
14
+ requireHydration={epoch > 0 || props.requireHydration}
15
+ adopt={(view) => (edytor = view)}
16
+ rebuild={() => epoch++}
17
+ />{/key}
@@ -0,0 +1,4 @@
1
+ import { type EdytorProps } from './Edytor.svelte';
2
+ declare const EdytorRoot: import("svelte").Component<EdytorProps, {}, "edytor">;
3
+ type EdytorRoot = ReturnType<typeof EdytorRoot>;
4
+ export default EdytorRoot;
@@ -31,7 +31,7 @@
31
31
  contenteditable="false"
32
32
  aria-label={suggestion.label ?? labelsOf(edytor, 'editor', editorEnglish).suggestion}
33
33
  role="group"
34
- use:edytor.surface.preview={suggestion.id}
34
+ use:edytor.surface.own={suggestion.id}
35
35
  onmousedown={cancel}
36
36
  >
37
37
  {#each cells as cell (cell.id)}<Block kid={cell} />{/each}
@@ -78,6 +78,9 @@ export type BlockAttribution = {
78
78
  lastChangedBy?: ActorId;
79
79
  };
80
80
  export { BLOCK_ATTR_ROOT, LAST_CHANGED_ATTR };
81
+ /** A record's `createdBy` key, and the prefix of its contributors' (a re-seed copies them: `crdt/reseed.ts`). */
82
+ export declare const CREATED_KEY = "c";
83
+ export declare const CONTRIBUTOR_PREFIX = "k/";
81
84
  /** The `k/` member set on a `b/` record node. */
82
85
  export declare const contributorsOfRecord: (rec: EngineNode | null) => Set<ActorId>;
83
86
  /**
@@ -5,8 +5,9 @@ import { attrItems, newNode as makeNode } from '../structs.js';
5
5
  // `../schema.js` leaf — re-exported so existing import sites stay.
6
6
  export { BLOCK_ATTR_ROOT, LAST_CHANGED_ATTR };
7
7
  const REC_NODE = 'brec';
8
- const CREATED_KEY = 'c';
9
- const CONTRIBUTOR_PREFIX = 'k/';
8
+ /** A record's `createdBy` key, and the prefix of its contributors' (a re-seed copies them: `crdt/reseed.ts`). */
9
+ export const CREATED_KEY = 'c';
10
+ export const CONTRIBUTOR_PREFIX = 'k/';
10
11
  /** Incarnation stamp on a record: the nonce `n` of the node it belongs to. */
11
12
  const INCARNATION_KEY = 'i';
12
13
  const recordOf = (doc, id) => {
@@ -20,6 +20,7 @@ import { changedUnder, collectable, collectNow, collects, dropSearchMarkers, eng
20
20
  import { isInitialized } from './gate.js';
21
21
  import { DocumentDestroyedError } from './funnel.js';
22
22
  import { registryOf, withdrawOnUndo } from '../placement/model.js';
23
+ import { getOr } from '../../utils.js';
23
24
  /** The undo steps a document's history keeps by default: older ones are released. */
24
25
  export const DEFAULT_HISTORY_LIMIT = 200;
25
26
  /** The origin of the transaction that releases a dropped history step's content. */
@@ -465,9 +466,7 @@ export const historyRules = (Y, doc) => {
465
466
  if (step.inserts.has(s.id.client, s.id.clock))
466
467
  return;
467
468
  const values = s.content;
468
- let attrs = lost.get(node);
469
- if (attrs === undefined)
470
- lost.set(node, (attrs = new Map()));
469
+ const attrs = getOr(lost, node, () => new Map());
471
470
  attrs.set(key, values.getContent().at(-1));
472
471
  });
473
472
  for (const [node, attrs] of lost) {
@@ -0,0 +1,81 @@
1
+ import { type JSONBlock, type JSONInlineBlock, type JSONText } from '../../utils/json.js';
2
+ import { type DataPatch } from '../data.js';
3
+ import { type BlockId, type BlockSpec, type ContentItem, type Destination, type InlineSpec, type SplitTail } from '../placement/model.js';
4
+ import type { DataTarget, Plan, PlanStep, Prepared } from './types.js';
5
+ import type { DocBase, DocReads } from './reads.js';
6
+ import type { DocPosition, RangeView } from '../rangeDelete.js';
7
+ import { type Flow, type FlowTarget, type FlowView } from '../flow.js';
8
+ /**
9
+ * A record's order among the records standing at one block, for the
10
+ * engine's sort of two records at one origin (fork patch YP22): what a split
11
+ * of a list around a block writes there — a new head list holding the items
12
+ * before it (`head`), new blocks placed after the items before it, which
13
+ * stay (`kept`), a head holding those items and the block (`with`), the
14
+ * block itself leaving (`self`), new blocks after it (`after`) — in the
15
+ * order every serial run of the gestures gives (`del.merge.container`).
16
+ */
17
+ export declare const PART: {
18
+ readonly head: 0;
19
+ readonly kept: 1;
20
+ readonly with: 2;
21
+ readonly self: 3;
22
+ readonly after: 4;
23
+ };
24
+ /** An inline atom to insert: its id is minted when it names none. */
25
+ export type NewInline = Omit<InlineSpec, 'id'> & {
26
+ id?: string;
27
+ };
28
+ /** The prepared ops of one facade over its reads. */
29
+ export declare const docOps: (c: DocBase & DocReads) => {
30
+ plan: (ids: readonly BlockId[], writes: PlanStep[], at?: DocPosition) => Plan;
31
+ canPlace: (ids: readonly BlockId[], parent?: BlockId | null, kindOf?: (id: BlockId) => string | undefined) => boolean;
32
+ fits: (parent: BlockId | null, kind: string | undefined) => boolean;
33
+ nestParent: (ids: readonly BlockId[], parent: BlockId) => BlockId;
34
+ canMerge: (fromId: BlockId, intoId: BlockId) => boolean;
35
+ defaultChild: (parent: BlockId | null) => string;
36
+ landingOf: (id: BlockId, kind: string, after?: boolean) => {
37
+ parent: string | null;
38
+ levels: string[];
39
+ };
40
+ besideAt: (target: BlockId, kind?: string) => BlockId;
41
+ /** Every op of the families, prepared. */
42
+ prepare: {
43
+ insertBlocks: (dest: Destination, specs: readonly (BlockSpec | JSONBlock)[]) => Prepared;
44
+ moveBlocks: (ids: readonly BlockId[], dest: Destination) => Prepared;
45
+ unNestBlocks: (ids: readonly BlockId[]) => Prepared;
46
+ unNestBlock: (id: BlockId) => Prepared;
47
+ liftOut: (id: BlockId, kind: string, { keep, after }?: {
48
+ keep?: boolean;
49
+ after?: readonly BlockSpec[];
50
+ }) => Prepared;
51
+ duplicateBlock: (id: BlockId, freshId?: (oldId: string, kind: "block" | "inline") => string) => Prepared;
52
+ placeBeside: (ids: readonly BlockId[], target: BlockId, side: "left" | "right", kind?: string) => Prepared;
53
+ wrapInLayout: (ids: readonly BlockId[], kind?: string, columns?: number) => Prepared;
54
+ splitBlock: (id: BlockId, offset: number, newId: BlockId, tail?: SplitTail) => Prepared;
55
+ mergeBlocks: (fromId: BlockId, intoId: BlockId) => Prepared;
56
+ mergeBackward: (id: BlockId) => Prepared;
57
+ mergeForward: (id: BlockId) => Prepared;
58
+ deleteBlocks: (ids: readonly BlockId[], subtree?: boolean, filled?: BlockId | null) => Prepared;
59
+ deleteBlock: (id: BlockId, opts?: {
60
+ keepChildren?: boolean;
61
+ }) => Prepared;
62
+ setBlockType: (id: BlockId, type: string) => Prepared;
63
+ patchData: (target: DataTarget, patches: readonly DataPatch[]) => Prepared;
64
+ setBlock: (id: BlockId, value: {
65
+ type?: string;
66
+ data?: Record<string, unknown>;
67
+ content?: (ContentItem | JSONText | JSONInlineBlock)[];
68
+ children?: (BlockSpec | JSONBlock)[];
69
+ }) => Prepared;
70
+ insertText: (id: BlockId, offset: number, text: string, marks?: Record<string, unknown>) => Prepared;
71
+ deleteText: (id: BlockId, offset: number, length: number) => Prepared;
72
+ formatRange: (id: BlockId, offset: number, length: number, marks: Record<string, unknown>) => Prepared;
73
+ clearMarks: (id: BlockId, offset: number, length: number) => Prepared;
74
+ insertInline: (id: BlockId, offset: number, atom: NewInline) => Prepared;
75
+ removeInline: (id: BlockId, inlineId: string) => Prepared;
76
+ insertFlow: (target: FlowTarget, flow: Flow, view?: FlowView) => Prepared;
77
+ deleteRange: (from: DocPosition, to: DocPosition, view?: RangeView) => Prepared;
78
+ replaceRange: (from: DocPosition, to: DocPosition, view?: RangeView) => Prepared;
79
+ };
80
+ };
81
+ export type DocOps = ReturnType<typeof docOps>;