@synnaxlabs/drift 0.36.0 → 0.38.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 (65) hide show
  1. package/dist/debounce-BUAIXXZt.cjs +1 -0
  2. package/dist/debounce-DOZKRZa9.js +9 -0
  3. package/dist/electron.cjs +1 -0
  4. package/dist/electron.js +256 -0
  5. package/dist/index.cjs +1 -0
  6. package/dist/index.js +491 -0
  7. package/dist/react.cjs +1 -0
  8. package/dist/react.js +70 -0
  9. package/dist/selectors-CDBV8JlK.js +25 -0
  10. package/dist/selectors-DSYdcjUd.cjs +1 -0
  11. package/dist/src/configureStore.d.ts +43 -0
  12. package/dist/src/configureStore.d.ts.map +1 -0
  13. package/dist/src/debug.d.ts +4 -0
  14. package/dist/src/debug.d.ts.map +1 -0
  15. package/dist/src/electron/index.d.ts +49 -0
  16. package/dist/src/electron/index.d.ts.map +1 -0
  17. package/dist/src/external.d.ts +8 -0
  18. package/dist/src/external.d.ts.map +1 -0
  19. package/dist/src/index.d.ts +3 -0
  20. package/dist/src/index.d.ts.map +1 -0
  21. package/dist/src/middleware.d.ts +27 -0
  22. package/dist/src/middleware.d.ts.map +1 -0
  23. package/dist/src/middleware.spec.d.ts +2 -0
  24. package/dist/src/middleware.spec.d.ts.map +1 -0
  25. package/dist/src/mock/index.d.ts +2 -0
  26. package/dist/src/mock/index.d.ts.map +1 -0
  27. package/dist/src/mock/runtime.d.ts +44 -0
  28. package/dist/src/mock/runtime.d.ts.map +1 -0
  29. package/dist/src/react/Provider.d.ts +23 -0
  30. package/dist/src/react/Provider.d.ts.map +1 -0
  31. package/dist/src/react/hooks.d.ts +15 -0
  32. package/dist/src/react/hooks.d.ts.map +1 -0
  33. package/dist/src/react/index.d.ts +4 -0
  34. package/dist/src/react/index.d.ts.map +1 -0
  35. package/dist/src/react/selectors.d.ts +13 -0
  36. package/dist/src/react/selectors.d.ts.map +1 -0
  37. package/dist/src/runtime.d.ts +99 -0
  38. package/dist/src/runtime.d.ts.map +1 -0
  39. package/dist/src/selectors.d.ts +9 -0
  40. package/dist/src/selectors.d.ts.map +1 -0
  41. package/dist/src/serialization/index.d.ts +6 -0
  42. package/dist/src/serialization/index.d.ts.map +1 -0
  43. package/dist/src/state.d.ts +100 -0
  44. package/dist/src/state.d.ts.map +1 -0
  45. package/dist/src/sugar.d.ts +24 -0
  46. package/dist/src/sugar.d.ts.map +1 -0
  47. package/dist/src/sugar.spec.d.ts +2 -0
  48. package/dist/src/sugar.spec.d.ts.map +1 -0
  49. package/dist/src/sync.d.ts +11 -0
  50. package/dist/src/sync.d.ts.map +1 -0
  51. package/dist/src/sync.spec.d.ts +2 -0
  52. package/dist/src/sync.spec.d.ts.map +1 -0
  53. package/dist/src/tauri/index.d.ts +47 -0
  54. package/dist/src/tauri/index.d.ts.map +1 -0
  55. package/dist/src/validate.d.ts +11 -0
  56. package/dist/src/validate.d.ts.map +1 -0
  57. package/dist/src/validate.spec.d.ts +2 -0
  58. package/dist/src/validate.spec.d.ts.map +1 -0
  59. package/dist/src/window.d.ts +177 -0
  60. package/dist/src/window.d.ts.map +1 -0
  61. package/dist/state--TjGqMVk.cjs +13 -0
  62. package/dist/state-B6yPmERI.js +5918 -0
  63. package/dist/tauri.cjs +1 -0
  64. package/dist/tauri.js +2712 -0
  65. package/package.json +9 -10
package/dist/index.js ADDED
@@ -0,0 +1,491 @@
1
+ import { configureStore as F } from "@reduxjs/toolkit";
2
+ import { M as h, g as T, l as d, a as E, r as g, _ as p, G as N, I as V, b as I, i as $, c as U, s as Q, d as Z, e as K, f as C, h as q, S as M, Z as X, j as B, k as G, m as Y, n as H, o as J, p as x, q as W, t as ee, u as se, v as ie, w as te, x as ae, y as oe, z as ne, A as le, B as re, C as ce, D as ue, E as fe, F as de } from "./state-B6yPmERI.js";
3
+ import { s as we, a as he, b as pe, c as ye, d as _e, e as be } from "./selectors-CDBV8JlK.js";
4
+ const me = new Error("request for lock canceled");
5
+ var ze = function(i, e, s, t) {
6
+ function a(o) {
7
+ return o instanceof s ? o : new s(function(l) {
8
+ l(o);
9
+ });
10
+ }
11
+ return new (s || (s = Promise))(function(o, l) {
12
+ function n(r) {
13
+ try {
14
+ u(t.next(r));
15
+ } catch (f) {
16
+ l(f);
17
+ }
18
+ }
19
+ function c(r) {
20
+ try {
21
+ u(t.throw(r));
22
+ } catch (f) {
23
+ l(f);
24
+ }
25
+ }
26
+ function u(r) {
27
+ r.done ? o(r.value) : a(r.value).then(n, c);
28
+ }
29
+ u((t = t.apply(i, e || [])).next());
30
+ });
31
+ };
32
+ class Se {
33
+ constructor(e, s = me) {
34
+ this._value = e, this._cancelError = s, this._queue = [], this._weightedWaiters = [];
35
+ }
36
+ acquire(e = 1, s = 0) {
37
+ if (e <= 0)
38
+ throw new Error(`invalid weight ${e}: must be positive`);
39
+ return new Promise((t, a) => {
40
+ const o = { resolve: t, reject: a, weight: e, priority: s }, l = O(this._queue, (n) => s <= n.priority);
41
+ l === -1 && e <= this._value ? this._dispatchItem(o) : this._queue.splice(l + 1, 0, o);
42
+ });
43
+ }
44
+ runExclusive(e) {
45
+ return ze(this, arguments, void 0, function* (s, t = 1, a = 0) {
46
+ const [o, l] = yield this.acquire(t, a);
47
+ try {
48
+ return yield s(o);
49
+ } finally {
50
+ l();
51
+ }
52
+ });
53
+ }
54
+ waitForUnlock(e = 1, s = 0) {
55
+ if (e <= 0)
56
+ throw new Error(`invalid weight ${e}: must be positive`);
57
+ return this._couldLockImmediately(e, s) ? Promise.resolve() : new Promise((t) => {
58
+ this._weightedWaiters[e - 1] || (this._weightedWaiters[e - 1] = []), ke(this._weightedWaiters[e - 1], { resolve: t, priority: s });
59
+ });
60
+ }
61
+ isLocked() {
62
+ return this._value <= 0;
63
+ }
64
+ getValue() {
65
+ return this._value;
66
+ }
67
+ setValue(e) {
68
+ this._value = e, this._dispatchQueue();
69
+ }
70
+ release(e = 1) {
71
+ if (e <= 0)
72
+ throw new Error(`invalid weight ${e}: must be positive`);
73
+ this._value += e, this._dispatchQueue();
74
+ }
75
+ cancel() {
76
+ this._queue.forEach((e) => e.reject(this._cancelError)), this._queue = [];
77
+ }
78
+ _dispatchQueue() {
79
+ for (this._drainUnlockWaiters(); this._queue.length > 0 && this._queue[0].weight <= this._value; )
80
+ this._dispatchItem(this._queue.shift()), this._drainUnlockWaiters();
81
+ }
82
+ _dispatchItem(e) {
83
+ const s = this._value;
84
+ this._value -= e.weight, e.resolve([s, this._newReleaser(e.weight)]);
85
+ }
86
+ _newReleaser(e) {
87
+ let s = !1;
88
+ return () => {
89
+ s || (s = !0, this.release(e));
90
+ };
91
+ }
92
+ _drainUnlockWaiters() {
93
+ if (this._queue.length === 0)
94
+ for (let e = this._value; e > 0; e--) {
95
+ const s = this._weightedWaiters[e - 1];
96
+ s && (s.forEach((t) => t.resolve()), this._weightedWaiters[e - 1] = []);
97
+ }
98
+ else {
99
+ const e = this._queue[0].priority;
100
+ for (let s = this._value; s > 0; s--) {
101
+ const t = this._weightedWaiters[s - 1];
102
+ if (!t)
103
+ continue;
104
+ const a = t.findIndex((o) => o.priority <= e);
105
+ (a === -1 ? t : t.splice(0, a)).forEach((o) => o.resolve());
106
+ }
107
+ }
108
+ }
109
+ _couldLockImmediately(e, s) {
110
+ return (this._queue.length === 0 || this._queue[0].priority < s) && e <= this._value;
111
+ }
112
+ }
113
+ function ke(i, e) {
114
+ const s = O(i, (t) => e.priority <= t.priority);
115
+ i.splice(s + 1, 0, e);
116
+ }
117
+ function O(i, e) {
118
+ for (let s = i.length - 1; s >= 0; s--)
119
+ if (e(i[s]))
120
+ return s;
121
+ return -1;
122
+ }
123
+ var ve = function(i, e, s, t) {
124
+ function a(o) {
125
+ return o instanceof s ? o : new s(function(l) {
126
+ l(o);
127
+ });
128
+ }
129
+ return new (s || (s = Promise))(function(o, l) {
130
+ function n(r) {
131
+ try {
132
+ u(t.next(r));
133
+ } catch (f) {
134
+ l(f);
135
+ }
136
+ }
137
+ function c(r) {
138
+ try {
139
+ u(t.throw(r));
140
+ } catch (f) {
141
+ l(f);
142
+ }
143
+ }
144
+ function u(r) {
145
+ r.done ? o(r.value) : a(r.value).then(n, c);
146
+ }
147
+ u((t = t.apply(i, e || [])).next());
148
+ });
149
+ };
150
+ class Te {
151
+ constructor(e) {
152
+ this._semaphore = new Se(1, e);
153
+ }
154
+ acquire() {
155
+ return ve(this, arguments, void 0, function* (e = 0) {
156
+ const [, s] = yield this._semaphore.acquire(1, e);
157
+ return s;
158
+ });
159
+ }
160
+ runExclusive(e, s = 0) {
161
+ return this._semaphore.runExclusive(() => e(), 1, s);
162
+ }
163
+ isLocked() {
164
+ return this._semaphore.isLocked();
165
+ }
166
+ waitForUnlock(e = 0) {
167
+ return this._semaphore.waitForUnlock(1, e);
168
+ }
169
+ release() {
170
+ this._semaphore.isLocked() && this._semaphore.release();
171
+ }
172
+ cancel() {
173
+ return this._semaphore.cancel();
174
+ }
175
+ }
176
+ const Ee = (i) => [...new Set(i)], ge = (i, e, s = !0) => {
177
+ const t = /* @__PURE__ */ new Map();
178
+ return i.forEach((a) => {
179
+ const o = e(a);
180
+ if (t.has(o)) {
181
+ if (s) return;
182
+ t.delete(o);
183
+ }
184
+ t.set(o, a);
185
+ }), Array.from(t.values());
186
+ }, Ie = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
187
+ __proto__: null,
188
+ by: ge,
189
+ unique: Ee
190
+ }, Symbol.toStringTag, { value: "Module" })), L = "DA@", A = "://", Ce = (i, e) => L.concat(e, A, i), qe = (i) => {
191
+ const [e, s] = i.split(A);
192
+ if (s == null) return [i, ""];
193
+ const [, t] = e.split(L);
194
+ return [s, t];
195
+ }, z = (i, e) => ({
196
+ ...i,
197
+ type: Ce(i.type, e)
198
+ }), Me = (i) => {
199
+ const [e, s] = qe(i.type);
200
+ return {
201
+ emitted: s != null && s.length > 0,
202
+ emitter: s,
203
+ action: { ...i, type: e }
204
+ };
205
+ }, Oe = (i) => {
206
+ const {
207
+ centerCount: e,
208
+ processCount: s,
209
+ focusCount: t,
210
+ stage: a,
211
+ key: o,
212
+ prerenderLabel: l,
213
+ reserved: n,
214
+ minimized: c,
215
+ ...u
216
+ } = i;
217
+ return u;
218
+ }, Le = async (i, e, s, t) => {
219
+ const a = (await s.listLabels()).filter(
220
+ (r) => r !== h
221
+ ), o = Object.keys(i.windows).filter((r) => r !== h);
222
+ T(t, "syncInitial"), d(t, "existing windows in runtime", a.sort()), d(t, "non-main windows in state", o.sort()), E(t);
223
+ const l = Ie.unique([...a, ...o]);
224
+ for (const r of l)
225
+ !a.includes(r) && s.isMain() ? (d(t, "state window not in runtime, creating", r), await D(s, r, i.windows[r], t)) : o.includes(r) || (d(t, "runtime window not in state, closing", r), await y(s, r, t));
226
+ const n = s.label(), c = i.windows[n];
227
+ if (c == null) return;
228
+ const u = { ...V, key: n };
229
+ await R(u, c, s, t), e(
230
+ g({ label: s.label(), ...await s.getProps() })
231
+ );
232
+ }, Ae = async (i, e, s, t) => {
233
+ d(t, "sync", i, e), s.isMain() && await Re(i, e, s, t);
234
+ const a = i.windows[s.label()], o = e.windows[s.label()];
235
+ a == null || o == null || await R(a, o, s, t);
236
+ }, R = async (i, e, s, t) => {
237
+ const a = [];
238
+ e.title != null && e.title !== i.title && a.push([
239
+ "title",
240
+ { prev: i.title, next: e.title },
241
+ async () => s.setTitle(e.title)
242
+ ]);
243
+ const o = e.visible != null && e.visible !== i.visible, l = e.visible === !1, n = () => a.push([
244
+ "visible",
245
+ { prev: i.visible, next: e.visible },
246
+ async () => {
247
+ if (await s.setVisible(e.visible), e.visible === !1) return;
248
+ let c = e.position;
249
+ c ?? (c = (await s.getProps()).position), s.setPosition(N.translate(c, { x: 1, y: 1 })), s.setPosition(c);
250
+ }
251
+ ]);
252
+ if (o && l && n(), e.skipTaskbar != null && e.skipTaskbar !== i.skipTaskbar && a.push([
253
+ "skipTaskbar",
254
+ { prev: i.skipTaskbar, next: e.skipTaskbar },
255
+ async () => await s.setSkipTaskbar(e.skipTaskbar)
256
+ ]), e.maximized != null && e.maximized !== i.maximized && a.push([
257
+ "maximized",
258
+ { prev: i.maximized, next: e.maximized },
259
+ async () => await s.setMaximized(e.maximized)
260
+ ]), e.fullscreen != null && e.fullscreen !== i.fullscreen && a.push([
261
+ "fullscreen",
262
+ { prev: i.fullscreen, next: e.fullscreen },
263
+ async () => await s.setFullscreen(e.fullscreen)
264
+ ]), e.centerCount !== i.centerCount && a.push([
265
+ "center",
266
+ { prev: i.centerCount, next: e.centerCount },
267
+ async () => s.center()
268
+ ]), e.minimized != null && e.minimized !== i.minimized && a.push([
269
+ "minimized",
270
+ { prev: i.minimized, next: e.minimized },
271
+ async () => await s.setMinimized(e.minimized)
272
+ ]), e.resizable != null && e.resizable !== i.resizable && a.push([
273
+ "resizable",
274
+ { prev: i.resizable, next: e.resizable },
275
+ async () => await s.setResizable(e.resizable)
276
+ ]), e.minSize != null && !p.equals(e.minSize, i.minSize) && a.push([
277
+ "minSize",
278
+ { prev: i.minSize, next: e.minSize },
279
+ async () => await s.setMinSize(e.minSize)
280
+ ]), e.maxSize != null && !p.equals(e.maxSize, i.maxSize) && a.push([
281
+ "maxSize",
282
+ { prev: i.maxSize, next: e.maxSize },
283
+ async () => await s.setMaxSize(e.maxSize)
284
+ ]), e.size != null && !p.equals(e.size, i.size) && a.push([
285
+ "size",
286
+ { prev: i.size, next: e.size },
287
+ async () => await s.setSize(e.size)
288
+ ]), e.position != null && !p.equals(e.position, i.position) && a.push([
289
+ "position",
290
+ { prev: i.position, next: e.position },
291
+ async () => await s.setPosition(e.position)
292
+ ]), e.focusCount !== i.focusCount && a.push(
293
+ [
294
+ "setVisible",
295
+ { prev: i.visible, next: e.visible },
296
+ async () => await s.setVisible(!0)
297
+ ],
298
+ [
299
+ "focus",
300
+ { prev: i.focusCount, next: e.focusCount },
301
+ async () => await s.focus()
302
+ ]
303
+ ), e.decorations != null && e.decorations !== i.decorations && a.push([
304
+ "decorations",
305
+ { prev: i.decorations, next: e.decorations },
306
+ async () => await s.setDecorations(e.decorations)
307
+ ]), e.alwaysOnTop != null && e.alwaysOnTop !== i.alwaysOnTop && a.push([
308
+ "alwaysOnTop",
309
+ { prev: i.alwaysOnTop, next: e.alwaysOnTop },
310
+ async () => await s.setAlwaysOnTop(e.alwaysOnTop)
311
+ ]), o && !l && n(), a.length !== 0) {
312
+ T(t, `syncCurrent, label: ${s.label()}, key: ${e.key}`);
313
+ for (const [c, { prev: u, next: r }] of a) d(t, c, u, "->", r);
314
+ E(t);
315
+ for (const [, , c] of a) await c();
316
+ }
317
+ }, Re = async (i, e, s, t) => {
318
+ const a = Object.keys(i.windows).filter((n) => !(n in e.windows)), o = Object.keys(e.windows).filter((n) => !(n in i.windows)), l = s.isMain();
319
+ if (l && a.length > 0)
320
+ for (const n of a)
321
+ d(t, "syncMain", "closing", n), n === h && await Promise.all(
322
+ Object.keys(e.windows).filter((c) => c !== h).map(async (c) => await y(s, c, t))
323
+ ), await y(s, n, t);
324
+ if (l && o.length > 0)
325
+ for (const n of o)
326
+ await D(s, n, e.windows[n], t);
327
+ }, D = async (i, e, s, t) => (d(t, "createWindow", s), await i.create(e, Oe(s))), y = async (i, e, s) => (d(s, "closeWindow", e), await i.close(e)), S = "[drift] - unexpected undefined action", k = "[drift] - unexpected undefined action type", _ = (i) => {
328
+ if (i.emitted ?? (i.emitted = !1), i.action == null)
329
+ throw console.warn(S, i), new Error(S);
330
+ if (i.action.type == null || i.action.type.length === 0)
331
+ throw console.warn(k, i), new Error(k);
332
+ }, De = new Te(), Pe = [g.type, I.type], je = (i, e = !1) => ({ getState: s, dispatch: t }) => (a) => (o) => {
333
+ let { action: l, emitted: n, emitter: c } = Me(o);
334
+ const u = i.label();
335
+ _({ action: o, emitted: n, emitter: c });
336
+ const r = $(l.type);
337
+ if (r && d(e, "[drift] - middleware", {
338
+ action: l,
339
+ emitted: n,
340
+ emitter: c,
341
+ host: u
342
+ }), c === i.label()) return;
343
+ const f = r && !Pe.includes(l.type);
344
+ let w = null;
345
+ r && (w = s().drift, l = U(
346
+ l,
347
+ w
348
+ ));
349
+ const P = a(l), b = f ? s().drift : null, j = Q(n, l.type);
350
+ return De.runExclusive(async () => {
351
+ try {
352
+ w !== null && b !== null && await Ae(w, b, i, e), j && await i.emit({ action: l });
353
+ } catch (m) {
354
+ d(e, "[drift] - ERROR", {
355
+ error: m.message,
356
+ action: l,
357
+ emitted: n,
358
+ emitter: c,
359
+ host: u
360
+ }), t(Z({ key: u, message: m.message }));
361
+ }
362
+ }), P;
363
+ }, Fe = (i, e, s = !1) => (t) => {
364
+ const a = i != null ? typeof i == "function" ? i(t) : i : t();
365
+ return [je(e, s), ...a];
366
+ }, Ne = async ({
367
+ runtime: i,
368
+ preloadedState: e,
369
+ middleware: s,
370
+ debug: t = !1,
371
+ enablePrerender: a = !0,
372
+ defaultWindowProps: o,
373
+ ...l
374
+ }) => {
375
+ await i.configure();
376
+ let n;
377
+ n = F({
378
+ ...l,
379
+ preloadedState: await Ve(
380
+ t,
381
+ i,
382
+ () => n,
383
+ o,
384
+ e
385
+ ),
386
+ middleware: Fe(s, i, t)
387
+ }), await Le(n.getState().drift, n.dispatch, i, t);
388
+ const c = i.label();
389
+ return n.dispatch(
390
+ K({ enablePrerender: a, defaultWindowProps: o, debug: t, label: c })
391
+ ), n.dispatch(C({ stage: "created" })), i.onCloseRequested(() => n == null ? void 0 : n.dispatch(q({}))), n;
392
+ }, Ve = async (i, e, s, t, a) => e.isMain() ? (await e.subscribe(({ action: l, emitter: n, sendState: c }) => {
393
+ const u = s();
394
+ if (u == null) return;
395
+ if (l != null) {
396
+ _({ action: l, emitter: n }), u.dispatch(z(l, n));
397
+ return;
398
+ }
399
+ const r = u.getState();
400
+ c === !0 && e.emit({ state: r }, n);
401
+ }), typeof a == "function" ? v(t, i, await a()) : v(t, i, a)) : await new Promise((l, n) => {
402
+ (async () => {
403
+ try {
404
+ await e.subscribe(({ action: u, emitter: r, state: f }) => {
405
+ const w = s();
406
+ if (w == null)
407
+ return f != null ? l(f) : void 0;
408
+ u != null && (_({ action: u, emitter: r }), w.dispatch(z(u, r)));
409
+ }), await e.emit({ sendState: !0 }, h);
410
+ } catch (u) {
411
+ n(u);
412
+ }
413
+ })();
414
+ }), $e = Ne, v = (i, e, s) => {
415
+ if (s == null) return s;
416
+ const t = s[M];
417
+ return t.config.debug = e ?? t.config.debug, t.windows = Object.fromEntries(
418
+ Object.entries(t.windows).filter(([, a]) => a.reserved).map(([a, o]) => ((i == null ? void 0 : i.visible) != null && (o.visible = i.visible), o.focusCount = 0, o.centerCount = 0, o.processCount = 0, [a, o]))
419
+ ), s;
420
+ }, Ke = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
421
+ __proto__: null,
422
+ MAIN_WINDOW: h,
423
+ SLICE_NAME: M,
424
+ ZERO_SLICE_STATE: X,
425
+ closeWindow: q,
426
+ completeProcess: B,
427
+ configureStore: $e,
428
+ createWindow: G,
429
+ focusWindow: Y,
430
+ reducer: H,
431
+ registerProcess: J,
432
+ reloadWindow: I,
433
+ selectSliceState: we,
434
+ selectWindow: he,
435
+ selectWindowAttribute: pe,
436
+ selectWindowKey: ye,
437
+ selectWindowLabel: _e,
438
+ selectWindows: be,
439
+ setWindowAlwaysOnTop: x,
440
+ setWindowDecorations: W,
441
+ setWindowFullscreen: ee,
442
+ setWindowMaxSize: se,
443
+ setWindowMaximized: ie,
444
+ setWindowMinSize: te,
445
+ setWindowMinimized: ae,
446
+ setWindowPosition: oe,
447
+ setWindowProps: ne,
448
+ setWindowResizable: le,
449
+ setWindowSize: re,
450
+ setWindowSkipTaskbar: ce,
451
+ setWindowStage: C,
452
+ setWindowTitle: ue,
453
+ setWindowVisible: fe,
454
+ windowPropsZ: de
455
+ }, Symbol.toStringTag, { value: "Module" }));
456
+ export {
457
+ Ke as Drift,
458
+ h as MAIN_WINDOW,
459
+ M as SLICE_NAME,
460
+ X as ZERO_SLICE_STATE,
461
+ q as closeWindow,
462
+ B as completeProcess,
463
+ $e as configureStore,
464
+ G as createWindow,
465
+ Y as focusWindow,
466
+ H as reducer,
467
+ J as registerProcess,
468
+ I as reloadWindow,
469
+ we as selectSliceState,
470
+ he as selectWindow,
471
+ pe as selectWindowAttribute,
472
+ ye as selectWindowKey,
473
+ _e as selectWindowLabel,
474
+ be as selectWindows,
475
+ x as setWindowAlwaysOnTop,
476
+ W as setWindowDecorations,
477
+ ee as setWindowFullscreen,
478
+ se as setWindowMaxSize,
479
+ ie as setWindowMaximized,
480
+ te as setWindowMinSize,
481
+ ae as setWindowMinimized,
482
+ oe as setWindowPosition,
483
+ ne as setWindowProps,
484
+ le as setWindowResizable,
485
+ re as setWindowSize,
486
+ ce as setWindowSkipTaskbar,
487
+ C as setWindowStage,
488
+ ue as setWindowTitle,
489
+ fe as setWindowVisible,
490
+ de as windowPropsZ
491
+ };
package/dist/react.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),o=require("react-redux"),a=require("proxy-memoize"),d=require("./selectors-DSYdcjUd.cjs"),i=require("./state--TjGqMVk.cjs"),y=e=>o.useSelector(n.useCallback(a.memoize(s=>d.selectWindow(s,e)),[e])),w=()=>o.useSelector(n.useCallback(a.memoize(d.selectWindows),[])),S=e=>o.useSelector(n.useCallback(a.memoize(s=>d.selectWindowKey(s,e)),[e])),W=(e,s)=>o.useSelector(n.useCallback(a.memoize(t=>d.selectWindowAttribute(t,e,s)),[e,s])),m=(e,s)=>{const t=y(s),u=o.useDispatch(),c=n.useRef(null);n.useEffect(()=>{if(t==null)return;const{stage:r}=t;if(r==="created"&&c.current==null){const l=e();l!=null&&(c.current=l),u(i.registerProcess({key:t.key}))}else(r==="closing"||r==="reloading")&&c.current!=null&&(c.current(),c.current=null,u(i.completeProcess({key:t.key})))},[t])},g=(e,s)=>{const t=y(s),u=o.useDispatch(),c=n.useRef(null),r=n.useRef(!1);n.useEffect(()=>{if(t==null)return;const{stage:l}=t;if(l==="created"&&c.current==null)r.current=!0,e().then(f=>{c.current=f??(async()=>{}),u(i.registerProcess({key:t.key}))}).finally(()=>{r.current=!1});else if((l==="closing"||l==="reloading")&&c.current!=null){const f=c.current;c.current=null,f().then(()=>{c.current=null}).finally(()=>{u(i.completeProcess({key:t.key}))})}},[t])},k=({store:e,emptyContent:s=null,children:t})=>{const[u,c]=n.useState(null),[r,l]=n.useState(null);if(r!=null)throw l(null),r;return u==null?(e instanceof Promise?e.then(c).catch(l):c(e),s):n.createElement(o.Provider,{store:u},t)};exports.Provider=k;exports.useAsyncWindowLifecycle=g;exports.useSelectWindow=y;exports.useSelectWindowAttribute=W;exports.useSelectWindowKey=S;exports.useSelectWindows=w;exports.useWindowLifecycle=m;
package/dist/react.js ADDED
@@ -0,0 +1,70 @@
1
+ import { useCallback as o, useRef as a, useEffect as m, useState as d, createElement as h } from "react";
2
+ import { useSelector as u, useDispatch as y, Provider as g } from "react-redux";
3
+ import { memoize as i } from "proxy-memoize";
4
+ import { a as k, e as S, c as P, b as v } from "./selectors-CDBV8JlK.js";
5
+ import { o as w, j as p } from "./state-B6yPmERI.js";
6
+ const W = (e) => u(
7
+ o(
8
+ i((r) => k(r, e)),
9
+ [e]
10
+ )
11
+ ), j = () => u(o(i(S), [])), x = (e) => u(
12
+ o(
13
+ i((r) => P(r, e)),
14
+ [e]
15
+ )
16
+ ), z = (e, r) => u(
17
+ o(
18
+ i((t) => v(t, e, r)),
19
+ [e, r]
20
+ )
21
+ ), C = (e, r) => {
22
+ const t = W(r), l = y(), n = a(null);
23
+ m(() => {
24
+ if (t == null) return;
25
+ const { stage: s } = t;
26
+ if (s === "created" && n.current == null) {
27
+ const c = e();
28
+ c != null && (n.current = c), l(w({ key: t.key }));
29
+ } else (s === "closing" || s === "reloading") && n.current != null && (n.current(), n.current = null, l(p({ key: t.key })));
30
+ }, [t]);
31
+ }, L = (e, r) => {
32
+ const t = W(r), l = y(), n = a(null), s = a(!1);
33
+ m(() => {
34
+ if (t == null) return;
35
+ const { stage: c } = t;
36
+ if (c === "created" && n.current == null)
37
+ s.current = !0, e().then((f) => {
38
+ n.current = f ?? (async () => {
39
+ }), l(w({ key: t.key }));
40
+ }).finally(() => {
41
+ s.current = !1;
42
+ });
43
+ else if ((c === "closing" || c === "reloading") && n.current != null) {
44
+ const f = n.current;
45
+ n.current = null, f().then(() => {
46
+ n.current = null;
47
+ }).finally(() => {
48
+ l(p({ key: t.key }));
49
+ });
50
+ }
51
+ }, [t]);
52
+ }, R = ({
53
+ store: e,
54
+ emptyContent: r = null,
55
+ children: t
56
+ }) => {
57
+ const [l, n] = d(null), [s, c] = d(null);
58
+ if (s != null)
59
+ throw c(null), s;
60
+ return l == null ? (e instanceof Promise ? e.then(n).catch(c) : n(e), r) : h(g, { store: l }, t);
61
+ };
62
+ export {
63
+ R as Provider,
64
+ L as useAsyncWindowLifecycle,
65
+ W as useSelectWindow,
66
+ z as useSelectWindowAttribute,
67
+ x as useSelectWindowKey,
68
+ j as useSelectWindows,
69
+ C as useWindowLifecycle
70
+ };
@@ -0,0 +1,25 @@
1
+ import { M as i } from "./state-B6yPmERI.js";
2
+ const l = (n) => n.drift, a = (n) => Object.values(l(n).windows), r = (n, e) => {
3
+ const t = l(n);
4
+ if (e == null) return t.windows[t.label];
5
+ let s = t.windows[e];
6
+ if (s != null) return s;
7
+ const o = t.keyLabels[e];
8
+ return s = t.windows[o], s == null && e != null ? null : s ?? t.windows[t.label];
9
+ }, u = (n, e) => {
10
+ const t = l(n);
11
+ if (e == null) return t.labelKeys[t.label];
12
+ const s = t.labelKeys[e];
13
+ return s == null && e == i ? i : s;
14
+ }, d = (n, e, t) => {
15
+ var s;
16
+ return ((s = r(n, e)) == null ? void 0 : s[t]) ?? null;
17
+ }, w = (n, e) => l(n).keyLabels[e];
18
+ export {
19
+ r as a,
20
+ d as b,
21
+ u as c,
22
+ w as d,
23
+ a as e,
24
+ l as s
25
+ };
@@ -0,0 +1 @@
1
+ "use strict";const i=require("./state--TjGqMVk.cjs"),s=n=>n.drift,r=n=>Object.values(s(n).windows),c=(n,e)=>{const t=s(n);if(e==null)return t.windows[t.label];let l=t.windows[e];if(l!=null)return l;const o=t.keyLabels[e];return l=t.windows[o],l==null&&e!=null?null:l??t.windows[t.label]},u=(n,e)=>{const t=s(n);if(e==null)return t.labelKeys[t.label];const l=t.labelKeys[e];return l==null&&e==i.MAIN_WINDOW?i.MAIN_WINDOW:l},w=(n,e,t)=>{var l;return((l=c(n,e))==null?void 0:l[t])??null},d=(n,e)=>s(n).keyLabels[e];exports.selectSliceState=s;exports.selectWindow=c;exports.selectWindowAttribute=w;exports.selectWindowKey=u;exports.selectWindowLabel=d;exports.selectWindows=r;
@@ -0,0 +1,43 @@
1
+ import { Action as CoreAction, ConfigureStoreOptions as BaseOpts, EnhancedStore, StoreEnhancer, Tuple, UnknownAction } from '@reduxjs/toolkit';
2
+ import { Middlewares } from './middleware';
3
+ import { Runtime } from './runtime';
4
+ import { Action, StoreState } from './state';
5
+ import { WindowProps } from './window';
6
+ export type Enhancers = readonly StoreEnhancer[];
7
+ /**
8
+ * Extends the default configureStore options to add a runtime argument.
9
+ * See configureStore for more details.
10
+ */
11
+ export interface ConfigureStoreOptions<S extends StoreState, A extends CoreAction = UnknownAction, M extends Tuple<Middlewares<S>> = Tuple<Middlewares<S>>, E extends Tuple<Enhancers> = Tuple<Enhancers>> extends Omit<BaseOpts<S, A, M, E>, "preloadedState"> {
12
+ runtime: Runtime<S, A | Action>;
13
+ debug?: boolean;
14
+ preloadedState?: S | (() => Promise<S | undefined>);
15
+ enablePrerender?: boolean;
16
+ defaultWindowProps?: Omit<WindowProps, "key">;
17
+ }
18
+ /**
19
+ * configureStore replaces the standard Redux Toolkit configureStore function
20
+ * with one that enables drift to synchronize state between windows. The API
21
+ * is identical to the standard configureStore function, except for two
22
+ * important differences.
23
+ *
24
+ * @param options.runtime - The core runtime of the application. This should
25
+ * be chosen based on the platform you are running on (Tauri, Electron, etc.).
26
+ * @param options.debug - If true, drift will log debug information to the
27
+ * console. @default false
28
+ * @param props.enablePrerender - If true, drift will create an invisible, pre-rendered
29
+ * window before it is needed. While it adds an additional process to your application,
30
+ * it also dramatically reduces the time it takes to open a new window. @default true
31
+ * @param props.defaultWindowProps - A partial set of window props to merge with
32
+ * the props passed to drift.createWindow. This is useful for setting default window
33
+ * properties, especially with prerendering. @default {}
34
+ * @param options - The standard Redux Toolkit configureStore options.
35
+ *
36
+ * @returns A !PROMISE! that resolves to a Redux store. This is necessary because
37
+ * the store must receive it's initial state from the main window, which is
38
+ * an asynchronous operation. The promise will resolve when the store is configured
39
+ * and the window is ready for use.
40
+ */
41
+ export declare const configureStore: <S extends StoreState, A extends CoreAction = UnknownAction, M extends Tuple<Middlewares<S>> = Tuple<Middlewares<S>>, E extends Tuple<Enhancers> = Tuple<Enhancers>>(options: ConfigureStoreOptions<S, A, M, E>) => Promise<EnhancedStore<S, A | Action>>;
42
+ export declare const resetInitialState: <S extends StoreState>(defaultWindowProps?: Omit<WindowProps, "key">, debug?: boolean, state?: S) => S | undefined;
43
+ //# sourceMappingURL=configureStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configureStore.d.ts","sourceRoot":"","sources":["../../src/configureStore.ts"],"names":[],"mappings":"AASA,OAAO,EACL,KAAK,MAAM,IAAI,UAAU,EAEzB,KAAK,qBAAqB,IAAI,QAAQ,EACtC,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,KAAK,EACV,KAAK,aAAa,EACnB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EACL,KAAK,MAAM,EAKX,KAAK,UAAU,EAChB,MAAM,SAAS,CAAC;AAIjB,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,UAAU,CAAC;AAEzD,MAAM,MAAM,SAAS,GAAG,SAAS,aAAa,EAAE,CAAC;AAEjD;;;GAGG;AACH,MAAM,WAAW,qBAAqB,CACpC,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,UAAU,GAAG,aAAa,EACpC,CAAC,SAAS,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EACvD,CAAC,SAAS,KAAK,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,CAC7C,SAAQ,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,gBAAgB,CAAC;IACpD,OAAO,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC;IAChC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,cAAc,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;IACpD,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,kBAAkB,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;CAC/C;AA2GD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,cAAc,EAAE,CAC3B,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,UAAU,GAAG,aAAa,EACpC,CAAC,SAAS,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EACvD,CAAC,SAAS,KAAK,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,EAE7C,OAAO,EAAE,qBAAqB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KACvC,OAAO,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,CAA0B,CAAC;AAEpE,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,UAAU,uBAC/B,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC,UACrC,OAAO,UACP,CAAC,KACR,CAAC,GAAG,SAiBN,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare const log: (debug?: boolean, ...args: unknown[]) => void;
2
+ export declare const group: (debug?: boolean, ...args: unknown[]) => void;
3
+ export declare const groupEnd: (debug: boolean) => void;
4
+ //# sourceMappingURL=debug.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/debug.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,GAAG,WAAW,OAAO,WAAmB,OAAO,EAAE,KAAG,IAEhE,CAAC;AAEF,eAAO,MAAM,KAAK,WAAW,OAAO,WAAmB,OAAO,EAAE,KAAG,IAElE,CAAC;AAEF,eAAO,MAAM,QAAQ,UAAW,OAAO,KAAG,IAEzC,CAAC"}