@yorkie-js/react 0.7.1 → 0.7.3

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.
@@ -1,4 +1,5 @@
1
1
  import { ClientOptions } from '@yorkie-js/sdk';
2
+ import { Counter } from '@yorkie-js/sdk';
2
3
  import { default as default_2 } from 'react';
3
4
  import { Document as Document_2 } from '@yorkie-js/sdk';
4
5
  import { Indexable } from '@yorkie-js/sdk';
@@ -9,6 +10,8 @@ import { Presence } from '@yorkie-js/sdk';
9
10
  import { PropsWithChildren } from 'react';
10
11
  import { RevisionSummary } from '@yorkie-js/sdk';
11
12
  import { StreamConnectionStatus } from '@yorkie-js/sdk';
13
+ import { Text as Text_2 } from '@yorkie-js/sdk';
14
+ import { Tree } from '@yorkie-js/sdk';
12
15
 
13
16
  /**
14
17
  * `ChannelProvider` is a component that provides Channel context to its children.
@@ -42,6 +45,8 @@ declare type ChannelProviderProps = PropsWithChildren<{
42
45
  isRealtime?: boolean;
43
46
  }>;
44
47
 
48
+ export { Counter }
49
+
45
50
  /**
46
51
  * `createDocumentSelector` is a factory function that provides a selector-based `useDocument` hook.
47
52
  * By currying this function, type T can be inferred from the selector function.
@@ -87,6 +92,10 @@ export { RevisionSummary }
87
92
  */
88
93
  export declare function shallowEqual<T>(valueA: T, valueB: T): boolean;
89
94
 
95
+ export { Text_2 as Text }
96
+
97
+ export { Tree }
98
+
90
99
  /**
91
100
  * `useChannel` is a custom hook that returns the channel state.
92
101
  * It must be used within a ChannelProvider.
@@ -5497,6 +5497,7 @@ var Code = /* @__PURE__ */ ((Code2) => {
5497
5497
  Code2["ErrUnauthenticated"] = "ErrUnauthenticated";
5498
5498
  Code2["ErrTooManySubscribers"] = "ErrTooManySubscribers";
5499
5499
  Code2["ErrTooManyAttachments"] = "ErrTooManyAttachments";
5500
+ Code2["ErrEpochMismatch"] = "ErrEpochMismatch";
5500
5501
  return Code2;
5501
5502
  })(Code || {});
5502
5503
  class YorkieError extends Error {
@@ -5828,6 +5829,8 @@ class ElementRHT {
5828
5829
  if (!node || executedAt.after(node.getValue().getPositionedAt())) {
5829
5830
  this.nodeMapByKey.set(key, newNode);
5830
5831
  value.setMovedAt(executedAt);
5832
+ } else if (!node.isRemoved()) {
5833
+ value.remove(node.getValue().getPositionedAt());
5831
5834
  }
5832
5835
  return removed;
5833
5836
  }
@@ -17217,22 +17220,49 @@ class Tree {
17217
17220
  }
17218
17221
  }
17219
17222
  /**
17220
- * `styleByPath` sets the attributes to the elements of the given path.
17223
+ * `styleByPath` sets the attributes to the elements of the given
17224
+ * path. When called with two paths, it styles the range between
17225
+ * them.
17221
17226
  */
17222
- styleByPath(path, attributes) {
17227
+ styleByPath(fromPathOrPath, toPathOrAttrs, maybeAttrs) {
17223
17228
  if (!this.context || !this.tree) {
17224
17229
  throw new YorkieError(
17225
17230
  Code.ErrNotInitialized,
17226
17231
  "Tree is not initialized yet"
17227
17232
  );
17228
17233
  }
17229
- if (!path.length) {
17230
- throw new YorkieError(
17231
- Code.ErrInvalidArgument,
17232
- "path should not be empty"
17233
- );
17234
+ let fromPos;
17235
+ let toPos;
17236
+ let attributes;
17237
+ if (Array.isArray(toPathOrAttrs)) {
17238
+ const fromPath = fromPathOrPath;
17239
+ const toPath = toPathOrAttrs;
17240
+ attributes = maybeAttrs;
17241
+ if (fromPath.length !== toPath.length) {
17242
+ throw new YorkieError(
17243
+ Code.ErrInvalidArgument,
17244
+ "path length should be equal"
17245
+ );
17246
+ }
17247
+ if (!fromPath.length || !toPath.length) {
17248
+ throw new YorkieError(
17249
+ Code.ErrInvalidArgument,
17250
+ "path should not be empty"
17251
+ );
17252
+ }
17253
+ fromPos = this.tree.pathToPos(fromPath);
17254
+ toPos = this.tree.pathToPos(toPath);
17255
+ } else {
17256
+ const path = fromPathOrPath;
17257
+ attributes = toPathOrAttrs;
17258
+ if (!path.length) {
17259
+ throw new YorkieError(
17260
+ Code.ErrInvalidArgument,
17261
+ "path should not be empty"
17262
+ );
17263
+ }
17264
+ [fromPos, toPos] = this.tree.pathToPosRange(path);
17234
17265
  }
17235
- const [fromPos, toPos] = this.tree.pathToPosRange(path);
17236
17266
  const ticket = this.context.issueTimeTicket();
17237
17267
  const attrs = attributes ? stringifyObjectValues(attributes) : void 0;
17238
17268
  const [pairs, , diff] = this.tree.style([fromPos, toPos], attrs, ticket);
@@ -17323,6 +17353,51 @@ class Tree {
17323
17353
  )
17324
17354
  );
17325
17355
  }
17356
+ /**
17357
+ * `removeStyleByPath` removes the attributes of the elements in
17358
+ * the given path range.
17359
+ */
17360
+ removeStyleByPath(fromPath, toPath, attributesToRemove) {
17361
+ if (!this.context || !this.tree) {
17362
+ throw new YorkieError(
17363
+ Code.ErrNotInitialized,
17364
+ "Tree is not initialized yet"
17365
+ );
17366
+ }
17367
+ if (fromPath.length !== toPath.length) {
17368
+ throw new YorkieError(
17369
+ Code.ErrInvalidArgument,
17370
+ "path length should be equal"
17371
+ );
17372
+ }
17373
+ if (!fromPath.length || !toPath.length) {
17374
+ throw new YorkieError(
17375
+ Code.ErrInvalidArgument,
17376
+ "path should not be empty"
17377
+ );
17378
+ }
17379
+ const fromPos = this.tree.pathToPos(fromPath);
17380
+ const toPos = this.tree.pathToPos(toPath);
17381
+ const ticket = this.context.issueTimeTicket();
17382
+ const [pairs, , diff] = this.tree.removeStyle(
17383
+ [fromPos, toPos],
17384
+ attributesToRemove,
17385
+ ticket
17386
+ );
17387
+ this.context.acc(diff);
17388
+ for (const pair of pairs) {
17389
+ this.context.registerGCPair(pair);
17390
+ }
17391
+ this.context.push(
17392
+ TreeStyleOperation.createTreeRemoveStyleOperation(
17393
+ this.tree.getCreatedAt(),
17394
+ fromPos,
17395
+ toPos,
17396
+ attributesToRemove,
17397
+ ticket
17398
+ )
17399
+ );
17400
+ }
17326
17401
  editInternal(fromPos, toPos, contents, splitLevel = 0) {
17327
17402
  if (contents.length !== 0 && contents[0]) {
17328
17403
  validateTreeNodes(contents);
@@ -18702,6 +18777,7 @@ var DocEventType = /* @__PURE__ */ ((DocEventType2) => {
18702
18777
  DocEventType2["Unwatched"] = "unwatched";
18703
18778
  DocEventType2["PresenceChanged"] = "presence-changed";
18704
18779
  DocEventType2["AuthError"] = "auth-error";
18780
+ DocEventType2["EpochMismatch"] = "epoch-mismatch";
18705
18781
  return DocEventType2;
18706
18782
  })(DocEventType || {});
18707
18783
  var StreamConnectionStatus = /* @__PURE__ */ ((StreamConnectionStatus2) => {
@@ -18991,6 +19067,17 @@ class Document {
18991
19067
  }
18992
19068
  }, arg3);
18993
19069
  }
19070
+ if (arg1 === "epoch-mismatch") {
19071
+ const callback2 = arg2;
19072
+ return this.eventStream.subscribe((event) => {
19073
+ for (const docEvent of event) {
19074
+ if (docEvent.type !== "epoch-mismatch") {
19075
+ continue;
19076
+ }
19077
+ callback2(docEvent);
19078
+ }
19079
+ }, arg3);
19080
+ }
18994
19081
  if (arg1 === "all") {
18995
19082
  const callback2 = arg2;
18996
19083
  return this.eventStream.subscribe(callback2, arg3, arg4);
@@ -19938,7 +20025,7 @@ function createAuthInterceptor(apiKey, token) {
19938
20025
  };
19939
20026
  }
19940
20027
  const name$1 = "@yorkie-js/sdk";
19941
- const version$1 = "0.7.1";
20028
+ const version$1 = "0.7.3";
19942
20029
  const pkg$1 = {
19943
20030
  name: name$1,
19944
20031
  version: version$1
@@ -20729,6 +20816,16 @@ class Client {
20729
20816
  ).catch(
20730
20817
  async (err) => {
20731
20818
  logger.error(`[SY] c:"${this.getKey()}" err :`, err);
20819
+ if (isErrorCode(err, Code.ErrEpochMismatch)) {
20820
+ attachment.resource.publish([
20821
+ {
20822
+ type: DocEventType.EpochMismatch,
20823
+ value: {
20824
+ method: "PushPull"
20825
+ }
20826
+ }
20827
+ ]);
20828
+ }
20732
20829
  await this.handleConnectError(err);
20733
20830
  throw err;
20734
20831
  }
@@ -21112,6 +21209,16 @@ class Client {
21112
21209
  }
21113
21210
  ]);
21114
21211
  }
21212
+ if (isErrorCode(e, Code.ErrEpochMismatch)) {
21213
+ attachment.resource.publish([
21214
+ {
21215
+ type: DocEventType.EpochMismatch,
21216
+ value: {
21217
+ method: "PushPull"
21218
+ }
21219
+ }
21220
+ ]);
21221
+ }
21115
21222
  throw e;
21116
21223
  })
21117
21224
  );
@@ -21541,6 +21648,9 @@ class Client {
21541
21648
  if (errorCodeOf(err) === Code.ErrTooManyAttachments) {
21542
21649
  return false;
21543
21650
  }
21651
+ if (errorCodeOf(err) === Code.ErrEpochMismatch) {
21652
+ return false;
21653
+ }
21544
21654
  if (errorCodeOf(err) === Code.ErrClientNotActivated || errorCodeOf(err) === Code.ErrClientNotFound) {
21545
21655
  this.deactivateInternal();
21546
21656
  }
@@ -21793,7 +21903,7 @@ if (typeof globalThis !== "undefined") {
21793
21903
  };
21794
21904
  }
21795
21905
  const name = "@yorkie-js/react";
21796
- const version = "0.7.1";
21906
+ const version = "0.7.3";
21797
21907
  const pkg = {
21798
21908
  name,
21799
21909
  version
@@ -22366,7 +22476,10 @@ const useChannelSessionCount = () => {
22366
22476
  };
22367
22477
  export {
22368
22478
  ChannelProvider,
22479
+ Counter,
22369
22480
  DocumentProvider,
22481
+ Text,
22482
+ Tree,
22370
22483
  YorkieProvider,
22371
22484
  createDocumentSelector,
22372
22485
  shallowEqual,