@kokimoki/app 1.4.5 → 1.4.7

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.
@@ -35,6 +35,7 @@ export declare class KokimokiClient<ClientContextT = any> extends KokimokiClient
35
35
  private _reconnectTimeout;
36
36
  private _pingInterval;
37
37
  private _clientTokenKey;
38
+ private _editorContext;
38
39
  constructor(host: string, appId: string, code?: string);
39
40
  get id(): string;
40
41
  get connectionId(): string;
@@ -44,6 +45,7 @@ export declare class KokimokiClient<ClientContextT = any> extends KokimokiClient
44
45
  get clientContext(): ClientContextT & ({} | null);
45
46
  get connected(): boolean;
46
47
  get ws(): WebSocket;
48
+ get isEditor(): boolean;
47
49
  connect(): Promise<void>;
48
50
  private handleInitMessage;
49
51
  private handleBinaryMessage;
@@ -35,6 +35,7 @@ export class KokimokiClient extends EventEmitter {
35
35
  _reconnectTimeout = 0;
36
36
  _pingInterval;
37
37
  _clientTokenKey = "KM_TOKEN";
38
+ _editorContext;
38
39
  constructor(host, appId, code = "") {
39
40
  super();
40
41
  this.host = host;
@@ -54,9 +55,10 @@ export class KokimokiClient extends EventEmitter {
54
55
  }
55
56
  }, 5000);
56
57
  // Listen for devtools messages
57
- if (window.top && window.self !== window.top) {
58
+ if (window.parent && window.self !== window.parent) {
58
59
  window.addEventListener("message", (e) => {
59
60
  console.log(`[KM TOOLS] ${e.data}`);
61
+ this._editorContext = e.data;
60
62
  if (e.data === "km:clearStorage") {
61
63
  localStorage.removeItem(this._clientTokenKey);
62
64
  window.location.reload();
@@ -112,12 +114,15 @@ export class KokimokiClient extends EventEmitter {
112
114
  }
113
115
  return this._ws;
114
116
  }
117
+ get isEditor() {
118
+ return !!this._editorContext;
119
+ }
115
120
  async connect() {
116
121
  if (this._connectPromise) {
117
122
  return await this._connectPromise;
118
123
  }
119
124
  // Detect devtools
120
- if (window.top && window.self !== window.top) {
125
+ if (window.parent && window.self !== window.parent) {
121
126
  await new Promise((resolve) => {
122
127
  /* // Wait up to 500ms for parent to respond
123
128
  const timeout = setTimeout(() => {
@@ -134,7 +139,7 @@ export class KokimokiClient extends EventEmitter {
134
139
  resolve();
135
140
  };
136
141
  window.addEventListener("message", onMessage);
137
- window.top.postMessage({ appId: this.appId }, "*");
142
+ window.parent.postMessage({ appId: this.appId }, "*");
138
143
  });
139
144
  }
140
145
  // Set up the WebSocket connection
@@ -344,6 +344,7 @@ declare class KokimokiClient<ClientContextT = any> extends KokimokiClient_base {
344
344
  private _reconnectTimeout;
345
345
  private _pingInterval;
346
346
  private _clientTokenKey;
347
+ private _editorContext;
347
348
  constructor(host: string, appId: string, code?: string);
348
349
  get id(): string;
349
350
  get connectionId(): string;
@@ -353,6 +354,7 @@ declare class KokimokiClient<ClientContextT = any> extends KokimokiClient_base {
353
354
  get clientContext(): ClientContextT & ({} | null);
354
355
  get connected(): boolean;
355
356
  get ws(): WebSocket;
357
+ get isEditor(): boolean;
356
358
  connect(): Promise<void>;
357
359
  private handleInitMessage;
358
360
  private handleBinaryMessage;
@@ -634,7 +634,7 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
634
634
  var eventsExports = events.exports;
635
635
  var EventEmitter$1 = /*@__PURE__*/getDefaultExportFromCjs(eventsExports);
636
636
 
637
- const KOKIMOKI_APP_VERSION = "1.4.5";
637
+ const KOKIMOKI_APP_VERSION = "1.4.7";
638
638
 
639
639
  /**
640
640
  * Utility module to work with key-value stores.
@@ -12248,6 +12248,7 @@ class KokimokiClient extends EventEmitter$1 {
12248
12248
  _reconnectTimeout = 0;
12249
12249
  _pingInterval;
12250
12250
  _clientTokenKey = "KM_TOKEN";
12251
+ _editorContext;
12251
12252
  constructor(host, appId, code = "") {
12252
12253
  super();
12253
12254
  this.host = host;
@@ -12267,9 +12268,10 @@ class KokimokiClient extends EventEmitter$1 {
12267
12268
  }
12268
12269
  }, 5000);
12269
12270
  // Listen for devtools messages
12270
- if (window.top && window.self !== window.top) {
12271
+ if (window.parent && window.self !== window.parent) {
12271
12272
  window.addEventListener("message", (e) => {
12272
12273
  console.log(`[KM TOOLS] ${e.data}`);
12274
+ this._editorContext = e.data;
12273
12275
  if (e.data === "km:clearStorage") {
12274
12276
  localStorage.removeItem(this._clientTokenKey);
12275
12277
  window.location.reload();
@@ -12325,12 +12327,15 @@ class KokimokiClient extends EventEmitter$1 {
12325
12327
  }
12326
12328
  return this._ws;
12327
12329
  }
12330
+ get isEditor() {
12331
+ return !!this._editorContext;
12332
+ }
12328
12333
  async connect() {
12329
12334
  if (this._connectPromise) {
12330
12335
  return await this._connectPromise;
12331
12336
  }
12332
12337
  // Detect devtools
12333
- if (window.top && window.self !== window.top) {
12338
+ if (window.parent && window.self !== window.parent) {
12334
12339
  await new Promise((resolve) => {
12335
12340
  /* // Wait up to 500ms for parent to respond
12336
12341
  const timeout = setTimeout(() => {
@@ -12347,7 +12352,7 @@ class KokimokiClient extends EventEmitter$1 {
12347
12352
  resolve();
12348
12353
  };
12349
12354
  window.addEventListener("message", onMessage);
12350
- window.top.postMessage({ appId: this.appId }, "*");
12355
+ window.parent.postMessage({ appId: this.appId }, "*");
12351
12356
  });
12352
12357
  }
12353
12358
  // Set up the WebSocket connection