@yorkie-js/react 0.6.10 → 0.6.12

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.
@@ -5,7 +5,7 @@ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
5
5
  import { jsx } from "react/jsx-runtime";
6
6
  import { createContext, useMemo, useState, useEffect, useContext, useCallback } from "react";
7
7
  const name$1 = "@yorkie-js/react";
8
- const version$1 = "0.6.10";
8
+ const version$1 = "0.6.12";
9
9
  const pkg$1 = {
10
10
  name: name$1,
11
11
  version: version$1
@@ -7614,76 +7614,11 @@ class YorkieError extends Error {
7614
7614
  this.toString = () => `[code=${this.code}]: ${this.message}`;
7615
7615
  }
7616
7616
  }
7617
- function deepcopy(object) {
7618
- if (object instanceof Map) {
7619
- const pairs = Array.from(object);
7620
- return new Map(JSON.parse(JSON.stringify(pairs)));
7621
- }
7622
- return JSON.parse(JSON.stringify(object));
7623
- }
7624
- const isEmpty = (object) => {
7625
- if (!object) {
7626
- return true;
7627
- }
7628
- return Object.entries(object).length === 0;
7629
- };
7630
- const stringifyObjectValues = (attributes) => {
7631
- const attrs = {};
7632
- for (const [key, value] of Object.entries(attributes)) {
7633
- attrs[key] = JSON.stringify(value);
7634
- }
7635
- return attrs;
7636
- };
7637
- const parseObjectValues = (attrs) => {
7638
- const attributes = {};
7639
- for (const [key, value] of Object.entries(attrs)) {
7640
- attributes[key] = JSON.parse(value);
7641
- }
7642
- return attributes;
7643
- };
7644
7617
  var PresenceChangeType = /* @__PURE__ */ ((PresenceChangeType2) => {
7645
7618
  PresenceChangeType2["Put"] = "put";
7646
7619
  PresenceChangeType2["Clear"] = "clear";
7647
7620
  return PresenceChangeType2;
7648
7621
  })(PresenceChangeType || {});
7649
- class Presence {
7650
- constructor(changeContext, presence) {
7651
- __publicField(this, "context");
7652
- __publicField(this, "presence");
7653
- this.context = changeContext;
7654
- this.presence = presence;
7655
- }
7656
- /**
7657
- * `set` updates the presence based on the partial presence.
7658
- */
7659
- set(presence, option) {
7660
- for (const key of Object.keys(presence)) {
7661
- this.presence[key] = presence[key];
7662
- }
7663
- this.context.setPresenceChange({
7664
- type: "put",
7665
- presence: deepcopy(this.presence)
7666
- });
7667
- this.context.setReversePresence(presence, option);
7668
- }
7669
- /**
7670
- * `get` returns the presence value of the given key.
7671
- */
7672
- get(key) {
7673
- return this.presence[key];
7674
- }
7675
- /**
7676
- * `clear` clears the presence.
7677
- * @internal
7678
- */
7679
- clear() {
7680
- this.presence = {};
7681
- this.context.setPresenceChange({
7682
- type: "clear"
7683
- /* Clear */
7684
- });
7685
- }
7686
- }
7687
7622
  const InitialActorID = "000000000000000000000000";
7688
7623
  const TimeTicketSize = 8 + 4 + 12;
7689
7624
  class TimeTicket {
@@ -7799,10 +7734,11 @@ class TimeTicket {
7799
7734
  return 0;
7800
7735
  }
7801
7736
  }
7737
+ const InitialLamport = 0n;
7802
7738
  const InitialDelimiter = 0;
7803
7739
  const MaxLamport = 9223372036854775807n;
7804
7740
  const InitialTimeTicket = new TimeTicket(
7805
- 0n,
7741
+ InitialLamport,
7806
7742
  InitialDelimiter,
7807
7743
  InitialActorID
7808
7744
  );
@@ -11013,6 +10949,33 @@ class RHT {
11013
10949
  this.numberOfRemovedElement--;
11014
10950
  }
11015
10951
  }
10952
+ function deepcopy(object) {
10953
+ if (object instanceof Map) {
10954
+ const pairs = Array.from(object);
10955
+ return new Map(JSON.parse(JSON.stringify(pairs)));
10956
+ }
10957
+ return JSON.parse(JSON.stringify(object));
10958
+ }
10959
+ const isEmpty = (object) => {
10960
+ if (!object) {
10961
+ return true;
10962
+ }
10963
+ return Object.entries(object).length === 0;
10964
+ };
10965
+ const stringifyObjectValues = (attributes) => {
10966
+ const attrs = {};
10967
+ for (const [key, value] of Object.entries(attributes)) {
10968
+ attrs[key] = JSON.stringify(value);
10969
+ }
10970
+ return attrs;
10971
+ };
10972
+ const parseObjectValues = (attrs) => {
10973
+ const attributes = {};
10974
+ for (const [key, value] of Object.entries(attrs)) {
10975
+ attributes[key] = JSON.parse(value);
10976
+ }
10977
+ return attributes;
10978
+ };
11016
10979
  class CRDTTextValue {
11017
10980
  constructor(content) {
11018
10981
  __publicField(this, "attributes");
@@ -13928,12 +13891,15 @@ class ChangeID {
13928
13891
  __publicField(this, "clientSeq");
13929
13892
  // `serverSeq` is optional and only present for changes stored on the server.
13930
13893
  __publicField(this, "serverSeq");
13931
- // `lamport` and `actor` are the lamport clock and the actor of this change.
13932
- // This is used to determine the order of changes in logical time.
13933
- __publicField(this, "lamport");
13894
+ // `actor` is the creator of this change.
13934
13895
  __publicField(this, "actor");
13896
+ // `lamport` is the lamport clock of this change. This is used to determine
13897
+ // the order of changes in logical time. It is optional and only present
13898
+ // if the change has operations.
13899
+ __publicField(this, "lamport");
13935
13900
  // `versionVector` is the vector clock of this change. This is used to
13936
- // determine the relationship is causal or not between changes.
13901
+ // determine the relationship is causal or not between changes. It is optional
13902
+ // and only present if the change has operations.
13937
13903
  __publicField(this, "versionVector");
13938
13904
  this.clientSeq = clientSeq;
13939
13905
  this.serverSeq = serverSeq;
@@ -13941,6 +13907,12 @@ class ChangeID {
13941
13907
  this.versionVector = vector;
13942
13908
  this.actor = actor;
13943
13909
  }
13910
+ /**
13911
+ * `hasClocks` returns true if this ID has logical clocks.
13912
+ */
13913
+ hasClocks() {
13914
+ return this.versionVector.size() > 0 && this.lamport != InitialLamport;
13915
+ }
13944
13916
  /**
13945
13917
  * `of` creates a new instance of ChangeID.
13946
13918
  */
@@ -13950,7 +13922,16 @@ class ChangeID {
13950
13922
  /**
13951
13923
  * `next` creates a next ID of this ID.
13952
13924
  */
13953
- next() {
13925
+ next(excludeClocks = false) {
13926
+ if (excludeClocks) {
13927
+ return new ChangeID(
13928
+ this.clientSeq + 1,
13929
+ this.lamport,
13930
+ this.actor,
13931
+ InitialVersionVector,
13932
+ InitialLamport
13933
+ );
13934
+ }
13954
13935
  const vector = this.versionVector.deepcopy();
13955
13936
  vector.set(this.actor, this.lamport + 1n);
13956
13937
  return new ChangeID(
@@ -13961,9 +13942,13 @@ class ChangeID {
13961
13942
  );
13962
13943
  }
13963
13944
  /**
13964
- * `syncClocks` syncs logical clocks with the given ID.
13945
+ * `syncClocks` syncs logical clocks with the given ID. If the given ID
13946
+ * doesn't have logical clocks, this ID is returned.
13965
13947
  */
13966
13948
  syncClocks(other) {
13949
+ if (!other.hasClocks()) {
13950
+ return this;
13951
+ }
13967
13952
  const lamport = other.lamport > this.lamport ? other.lamport + 1n : this.lamport + 1n;
13968
13953
  const maxVersionVector = this.versionVector.max(other.versionVector);
13969
13954
  const newID = new ChangeID(
@@ -14004,6 +13989,18 @@ class ChangeID {
14004
13989
  this.serverSeq
14005
13990
  );
14006
13991
  }
13992
+ /**
13993
+ * `setLamport` sets the given lamport clock.
13994
+ */
13995
+ setLamport(lamport) {
13996
+ return new ChangeID(
13997
+ this.clientSeq,
13998
+ lamport,
13999
+ this.actor,
14000
+ this.versionVector,
14001
+ this.serverSeq
14002
+ );
14003
+ }
14007
14004
  /**
14008
14005
  * `setVersionVector` sets the given version vector.
14009
14006
  */
@@ -16959,8 +16956,9 @@ function createObservable(executor) {
16959
16956
  };
16960
16957
  }
16961
16958
  class ChangeContext {
16962
- constructor(id, root, presence, message) {
16963
- __publicField(this, "id");
16959
+ constructor(prevID, root, presence, message) {
16960
+ __publicField(this, "prevID");
16961
+ __publicField(this, "nextID");
16964
16962
  __publicField(this, "delimiter");
16965
16963
  __publicField(this, "message");
16966
16964
  __publicField(this, "root");
@@ -16976,7 +16974,8 @@ class ChangeContext {
16976
16974
  * presence changes.
16977
16975
  */
16978
16976
  __publicField(this, "reversePresenceKeys");
16979
- this.id = id;
16977
+ this.prevID = prevID;
16978
+ this.nextID = prevID.next();
16980
16979
  this.delimiter = InitialDelimiter;
16981
16980
  this.root = root;
16982
16981
  this.operations = [];
@@ -16988,8 +16987,8 @@ class ChangeContext {
16988
16987
  /**
16989
16988
  * `create` creates a new instance of ChangeContext.
16990
16989
  */
16991
- static create(id, root, presence, message) {
16992
- return new ChangeContext(id, root, presence, message);
16990
+ static create(prevID, root, presence, message) {
16991
+ return new ChangeContext(prevID, root, presence, message);
16993
16992
  }
16994
16993
  /**
16995
16994
  * `push` pushes the given operation to this context.
@@ -17016,11 +17015,22 @@ class ChangeContext {
17016
17015
  this.root.registerGCPair(pair);
17017
17016
  }
17018
17017
  /**
17019
- * `getChange` creates a new instance of Change in this context.
17018
+ * `getNextID` returns the next ID of this context. It will be set to the
17019
+ * document for the next change.returns the next ID of this context.
17020
+ */
17021
+ getNextID() {
17022
+ if (this.operations.length === 0) {
17023
+ return this.prevID.next(true).setLamport(this.prevID.getLamport()).setVersionVector(this.prevID.getVersionVector());
17024
+ }
17025
+ return this.nextID;
17026
+ }
17027
+ /**
17028
+ * `toChange` creates a new instance of Change in this context.
17020
17029
  */
17021
- getChange() {
17030
+ toChange() {
17031
+ const id = this.operations.length === 0 ? this.prevID.next(true) : this.nextID;
17022
17032
  return Change.create({
17023
- id: this.id,
17033
+ id,
17024
17034
  operations: this.operations,
17025
17035
  presenceChange: this.presenceChange,
17026
17036
  message: this.message
@@ -17066,13 +17076,13 @@ class ChangeContext {
17066
17076
  */
17067
17077
  issueTimeTicket() {
17068
17078
  this.delimiter += 1;
17069
- return this.id.createTimeTicket(this.delimiter);
17079
+ return this.nextID.createTimeTicket(this.delimiter);
17070
17080
  }
17071
17081
  /**
17072
17082
  * `getLastTimeTicket` returns the last time ticket issued in this context.
17073
17083
  */
17074
17084
  getLastTimeTicket() {
17075
- return this.id.createTimeTicket(this.delimiter);
17085
+ return this.nextID.createTimeTicket(this.delimiter);
17076
17086
  }
17077
17087
  }
17078
17088
  class CRDTRoot {
@@ -19001,6 +19011,43 @@ function buildCRDTElement(context, value, createdAt) {
19001
19011
  }
19002
19012
  return element;
19003
19013
  }
19014
+ class Presence {
19015
+ constructor(changeContext, presence) {
19016
+ __publicField(this, "context");
19017
+ __publicField(this, "presence");
19018
+ this.context = changeContext;
19019
+ this.presence = presence;
19020
+ }
19021
+ /**
19022
+ * `set` updates the presence based on the partial presence.
19023
+ */
19024
+ set(presence, option) {
19025
+ for (const key of Object.keys(presence)) {
19026
+ this.presence[key] = presence[key];
19027
+ }
19028
+ this.context.setPresenceChange({
19029
+ type: PresenceChangeType.Put,
19030
+ presence: deepcopy(this.presence)
19031
+ });
19032
+ this.context.setReversePresence(presence, option);
19033
+ }
19034
+ /**
19035
+ * `get` returns the presence value of the given key.
19036
+ */
19037
+ get(key) {
19038
+ return this.presence[key];
19039
+ }
19040
+ /**
19041
+ * `clear` clears the presence.
19042
+ * @internal
19043
+ */
19044
+ clear() {
19045
+ this.presence = {};
19046
+ this.context.setPresenceChange({
19047
+ type: PresenceChangeType.Clear
19048
+ });
19049
+ }
19050
+ }
19004
19051
  const MaxUndoRedoStackDepth = 50;
19005
19052
  class History {
19006
19053
  constructor() {
@@ -19263,7 +19310,7 @@ class Document {
19263
19310
  this.ensureClone();
19264
19311
  const actorID = this.changeID.getActorID();
19265
19312
  const context = ChangeContext.create(
19266
- this.changeID.next(),
19313
+ this.changeID,
19267
19314
  this.clone.root,
19268
19315
  this.clone.presences.get(actorID) || {},
19269
19316
  message
@@ -19291,7 +19338,7 @@ class Document {
19291
19338
  if (logger.isEnabled(LogLevel.Trivial)) {
19292
19339
  logger.trivial(`trying to update a local change: ${this.toJSON()}`);
19293
19340
  }
19294
- const change = context.getChange();
19341
+ const change = context.toChange();
19295
19342
  const { opInfos, reverseOps } = change.execute(
19296
19343
  this.root,
19297
19344
  this.presences,
@@ -19311,7 +19358,7 @@ class Document {
19311
19358
  if (opInfos.length > 0) {
19312
19359
  this.internalHistory.clearRedo();
19313
19360
  }
19314
- this.changeID = change.getID();
19361
+ this.changeID = context.getNextID();
19315
19362
  const event = [];
19316
19363
  if (opInfos.length > 0) {
19317
19364
  event.push({
@@ -20180,14 +20227,6 @@ class Document {
20180
20227
  canUndo() {
20181
20228
  return this.internalHistory.hasUndo() && !this.isUpdating;
20182
20229
  }
20183
- /**
20184
- * 'filterVersionVector' filters detached client's lamport from version vector.
20185
- */
20186
- filterVersionVector(minSyncedVersionVector) {
20187
- const versionVector = this.changeID.getVersionVector();
20188
- const filteredVersionVector = versionVector.filter(minSyncedVersionVector);
20189
- this.changeID = this.changeID.setVersionVector(filteredVersionVector);
20190
- }
20191
20230
  /**
20192
20231
  * `canRedo` returns whether there are any operations to redo.
20193
20232
  */
@@ -20214,7 +20253,7 @@ class Document {
20214
20253
  }
20215
20254
  this.ensureClone();
20216
20255
  const context = ChangeContext.create(
20217
- this.changeID.next(),
20256
+ this.changeID,
20218
20257
  this.clone.root,
20219
20258
  this.clone.presences.get(this.changeID.getActorID()) || {}
20220
20259
  );
@@ -20231,7 +20270,7 @@ class Document {
20231
20270
  undoOp.setExecutedAt(ticket);
20232
20271
  context.push(undoOp);
20233
20272
  }
20234
- const change = context.getChange();
20273
+ const change = context.toChange();
20235
20274
  change.execute(this.clone.root, this.clone.presences, OpSource.UndoRedo);
20236
20275
  const { opInfos, reverseOps } = change.execute(
20237
20276
  this.root,
@@ -20252,7 +20291,7 @@ class Document {
20252
20291
  return;
20253
20292
  }
20254
20293
  this.localChanges.push(change);
20255
- this.changeID = change.getID();
20294
+ this.changeID = context.getNextID();
20256
20295
  const actorID = this.changeID.getActorID();
20257
20296
  const event = [];
20258
20297
  if (opInfos.length > 0) {
@@ -20301,7 +20340,7 @@ class Document {
20301
20340
  }
20302
20341
  this.ensureClone();
20303
20342
  const context = ChangeContext.create(
20304
- this.changeID.next(),
20343
+ this.changeID,
20305
20344
  this.clone.root,
20306
20345
  this.clone.presences.get(this.changeID.getActorID()) || {}
20307
20346
  );
@@ -20318,7 +20357,7 @@ class Document {
20318
20357
  redoOp.setExecutedAt(ticket);
20319
20358
  context.push(redoOp);
20320
20359
  }
20321
- const change = context.getChange();
20360
+ const change = context.toChange();
20322
20361
  change.execute(this.clone.root, this.clone.presences, OpSource.UndoRedo);
20323
20362
  const { opInfos, reverseOps } = change.execute(
20324
20363
  this.root,
@@ -20339,7 +20378,7 @@ class Document {
20339
20378
  return;
20340
20379
  }
20341
20380
  this.localChanges.push(change);
20342
- this.changeID = change.getID();
20381
+ this.changeID = context.getNextID();
20343
20382
  const actorID = this.changeID.getActorID();
20344
20383
  const event = [];
20345
20384
  if (opInfos.length > 0) {
@@ -20418,7 +20457,7 @@ function createAuthInterceptor(apiKey, token) {
20418
20457
  };
20419
20458
  }
20420
20459
  const name = "@yorkie-js/sdk";
20421
- const version = "0.6.10";
20460
+ const version = "0.6.12";
20422
20461
  const pkg = {
20423
20462
  name,
20424
20463
  version