@synnaxlabs/drift 0.52.3 → 0.54.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synnaxlabs/drift",
3
- "version": "0.52.3",
3
+ "version": "0.54.0",
4
4
  "description": "State synchronization and Redux state synchronization for Tauri Apps",
5
5
  "repository": "https://github.com/synnaxlabs/synnax/tree/main/drift",
6
6
  "type": "module",
@@ -14,43 +14,44 @@
14
14
  ],
15
15
  "dependencies": {
16
16
  "@reduxjs/toolkit": "^2.11.2",
17
- "@tauri-apps/api": "^2.9.1",
17
+ "@tauri-apps/api": "^2.10.1",
18
18
  "async-mutex": "^0.5.0",
19
- "proxy-memoize": "2.0.3",
20
19
  "react": "^19.2.4",
21
20
  "react-dom": "^19.2.4",
22
21
  "react-redux": "^9.2.0",
23
22
  "zod": "^4.3.6",
24
- "@synnaxlabs/x": "^0.52.3"
23
+ "@synnaxlabs/x": "^0.54.0"
25
24
  },
26
25
  "devDependencies": {
27
- "@types/node": "^25.1.0",
28
- "@types/react": "^19.2.10",
29
- "@vitejs/plugin-react": "^5.1.2",
30
- "@vitest/coverage-v8": "^3.2.4",
31
- "eslint": "^9.39.2",
26
+ "@testing-library/react": "^16.3.2",
27
+ "@types/node": "^25.5.0",
28
+ "@types/react": "^19.2.14",
29
+ "@vitejs/plugin-react": "^6.0.1",
30
+ "@vitest/coverage-v8": "^4.1.2",
31
+ "jsdom": "^27.4.0",
32
+ "eslint": "^10.1.0",
32
33
  "madge": "^8.0.0",
33
34
  "react": "^19.2.4",
34
35
  "react-dom": "^19.2.4",
35
36
  "react-redux": "^9.2.0",
36
- "typescript": "^5.9.3",
37
- "vite": "^7.3.1",
38
- "vitest": "^3.2.4",
39
- "@synnaxlabs/eslint-config": "^0.0.0",
37
+ "typescript": "^6.0.2",
38
+ "vite": "^8.0.3",
39
+ "vitest": "^4.1.2",
40
40
  "@synnaxlabs/tsconfig": "^0.0.0",
41
- "@synnaxlabs/vite-plugin": "^0.0.0"
41
+ "@synnaxlabs/vite-plugin": "^0.0.0",
42
+ "@synnaxlabs/eslint-config": "^0.0.0"
42
43
  },
43
44
  "files": [
44
45
  "dist"
45
46
  ],
46
- "main": "./dist/drift.cjs.js",
47
- "module": "./dist/drift.es.js",
47
+ "main": "./dist/drift.cjs",
48
+ "module": "./dist/drift.js",
48
49
  "types": "./dist/src/index.d.ts",
49
50
  "exports": {
50
51
  ".": {
51
52
  "types": "./dist/src/index.d.ts",
52
- "import": "./dist/index.js",
53
- "require": "./dist/index.cjs"
53
+ "import": "./dist/drift.js",
54
+ "require": "./dist/drift.cjs"
54
55
  },
55
56
  "./react": {
56
57
  "types": "./dist/src/react/index.d.ts",
package/dist/index.cjs DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("@reduxjs/toolkit"),t=require("./state-BFBdNgbN.cjs"),f=require("./selectors-bSOXrqbl.cjs"),P=new Error("request for lock canceled");var N=function(i,e,s,o){function n(a){return a instanceof s?a:new s(function(c){c(a)})}return new(s||(s=Promise))(function(a,c){function l(r){try{u(o.next(r))}catch(w){c(w)}}function d(r){try{u(o.throw(r))}catch(w){c(w)}}function u(r){r.done?a(r.value):n(r.value).then(l,d)}u((o=o.apply(i,e||[])).next())})};class C{constructor(e,s=P){this._value=e,this._cancelError=s,this._queue=[],this._weightedWaiters=[]}acquire(e=1,s=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((o,n)=>{const a={resolve:o,reject:n,weight:e,priority:s},c=T(this._queue,l=>s<=l.priority);c===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(c+1,0,a)})}runExclusive(e){return N(this,arguments,void 0,function*(s,o=1,n=0){const[a,c]=yield this.acquire(o,n);try{return yield s(a)}finally{c()}})}waitForUnlock(e=1,s=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,s)?Promise.resolve():new Promise(o=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),L(this._weightedWaiters[e-1],{resolve:o,priority:s})})}isLocked(){return this._value<=0}getValue(){return this._value}setValue(e){this._value=e,this._dispatchQueue()}release(e=1){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);this._value+=e,this._dispatchQueue()}cancel(){this._queue.forEach(e=>e.reject(this._cancelError)),this._queue=[]}_dispatchQueue(){for(this._drainUnlockWaiters();this._queue.length>0&&this._queue[0].weight<=this._value;)this._dispatchItem(this._queue.shift()),this._drainUnlockWaiters()}_dispatchItem(e){const s=this._value;this._value-=e.weight,e.resolve([s,this._newReleaser(e.weight)])}_newReleaser(e){let s=!1;return()=>{s||(s=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){const s=this._weightedWaiters[e-1];s&&(s.forEach(o=>o.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let s=this._value;s>0;s--){const o=this._weightedWaiters[s-1];if(!o)continue;const n=o.findIndex(a=>a.priority<=e);(n===-1?o:o.splice(0,n)).forEach((a=>a.resolve()))}}}_couldLockImmediately(e,s){return(this._queue.length===0||this._queue[0].priority<s)&&e<=this._value}}function L(i,e){const s=T(i,o=>e.priority<=o.priority);i.splice(s+1,0,e)}function T(i,e){for(let s=i.length-1;s>=0;s--)if(e(i[s]))return s;return-1}var q=function(i,e,s,o){function n(a){return a instanceof s?a:new s(function(c){c(a)})}return new(s||(s=Promise))(function(a,c){function l(r){try{u(o.next(r))}catch(w){c(w)}}function d(r){try{u(o.throw(r))}catch(w){c(w)}}function u(r){r.done?a(r.value):n(r.value).then(l,d)}u((o=o.apply(i,e||[])).next())})};class D{constructor(e){this._semaphore=new C(1,e)}acquire(){return q(this,arguments,void 0,function*(e=0){const[,s]=yield this._semaphore.acquire(1,e);return s})}runExclusive(e,s=0){return this._semaphore.runExclusive(()=>e(),1,s)}isLocked(){return this._semaphore.isLocked()}waitForUnlock(e=0){return this._semaphore.waitForUnlock(1,e)}release(){this._semaphore.isLocked()&&this._semaphore.release()}cancel(){return this._semaphore.cancel()}}const I="DA@",M="://",R=(i,e)=>I.concat(e,M,i),F=i=>{const[e,s]=i.split(M);if(s==null)return[i,""];const[,o]=e.split(I);return[s,o]},b=(i,e)=>({...i,type:R(i.type,e)}),V=i=>{const[e,s]=F(i.type);return{emitted:s!=null&&s.length>0,emitter:s,action:{...i,type:e}}},j=i=>{const{centerCount:e,processCount:s,focusCount:o,stage:n,key:a,prerenderLabel:c,reserved:l,minimized:d,...u}=i;return u},Z=async(i,e,s,o)=>{const n=(await s.listLabels()).filter(r=>r!==t.MAIN_WINDOW),a=Object.keys(i.windows).filter(r=>r!==t.MAIN_WINDOW);t.group(o,"syncInitial"),t.log(o,"existing windows in runtime",n.sort()),t.log(o,"non-main windows in state",a.sort()),t.groupEnd(o);const c=t.gu.unique([...n,...a]);for(const r of c)!n.includes(r)&&s.isMain()?(t.log(o,"state window not in runtime, creating",r),await k(s,r,i.windows[r],o)):a.includes(r)||(t.log(o,"runtime window not in state, closing",r),await p(s,r,o));const l=s.label(),d=i.windows[l];if(d==null)return;const u={...t.INITIAL_WINDOW_STATE};await E(u,d,s,o),e(t.runtimeSetWindowProps({label:s.label(),...await s.getProps()}))},U=async(i,e,s,o)=>{t.log(o,"sync",i,e),s.isMain()&&await K(i,e,s,o);const n=i.windows[s.label()],a=e.windows[s.label()];n==null||a==null||await E(n,a,s,o)},E=async(i,e,s,o)=>{const n=[];e.title!=null&&e.title!==i.title&&n.push(["title",{prev:i.title,next:e.title},async()=>s.setTitle(e.title)]);const a=e.visible!=null&&e.visible!==i.visible,c=e.visible===!1,l=()=>n.push(["visible",{prev:i.visible,next:e.visible},async()=>{if(await s.setVisible(e.visible),e.visible===!1)return;let d=e.position;d??=(await s.getProps()).position,d!=null&&(await s.setPosition(t.Iu.translate(d,{x:1,y:1})),await s.setPosition(d))}]);if(a&&c&&l(),e.skipTaskbar!=null&&e.skipTaskbar!==i.skipTaskbar&&n.push(["skipTaskbar",{prev:i.skipTaskbar,next:e.skipTaskbar},async()=>await s.setSkipTaskbar(e.skipTaskbar)]),e.maximized!=null&&e.maximized!==i.maximized&&n.push(["maximized",{prev:i.maximized,next:e.maximized},async()=>await s.setMaximized(e.maximized)]),e.fullscreen!=null&&e.fullscreen!==i.fullscreen&&n.push(["fullscreen",{prev:i.fullscreen,next:e.fullscreen},async()=>await s.setFullscreen(e.fullscreen)]),e.centerCount!==i.centerCount&&n.push(["center",{prev:i.centerCount,next:e.centerCount},async()=>s.center()]),e.minimized!=null&&e.minimized!==i.minimized&&n.push(["minimized",{prev:i.minimized,next:e.minimized},async()=>await s.setMinimized(e.minimized)]),e.resizable!=null&&e.resizable!==i.resizable&&n.push(["resizable",{prev:i.resizable,next:e.resizable},async()=>await s.setResizable(e.resizable)]),e.minSize!=null&&!t.vu.equals(e.minSize,i.minSize)&&n.push(["minSize",{prev:i.minSize,next:e.minSize},async()=>await s.setMinSize(e.minSize)]),e.maxSize!=null&&!t.vu.equals(e.maxSize,i.maxSize)&&n.push(["maxSize",{prev:i.maxSize,next:e.maxSize},async()=>await s.setMaxSize(e.maxSize)]),e.size!=null&&!t.vu.equals(e.size,i.size)&&n.push(["size",{prev:i.size,next:e.size},async()=>await s.setSize(e.size)]),e.position!=null&&!t.vu.equals(e.position,i.position)&&n.push(["position",{prev:i.position,next:e.position},async()=>await s.setPosition(e.position)]),e.focusCount!==i.focusCount&&n.push(["setVisible",{prev:i.visible,next:e.visible},async()=>await s.setVisible(!0)],["focus",{prev:i.focusCount,next:e.focusCount},async()=>await s.focus()]),e.decorations!=null&&e.decorations!==i.decorations&&n.push(["decorations",{prev:i.decorations,next:e.decorations},async()=>await s.setDecorations(e.decorations)]),e.alwaysOnTop!=null&&e.alwaysOnTop!==i.alwaysOnTop&&n.push(["alwaysOnTop",{prev:i.alwaysOnTop,next:e.alwaysOnTop},async()=>await s.setAlwaysOnTop(e.alwaysOnTop)]),a&&!c&&l(),n.length!==0){t.group(o,`syncCurrent, label: ${s.label()}, key: ${e.key}`);for(const[d,{prev:u,next:r}]of n)t.log(o,d,u,"->",r);t.groupEnd(o);for(const[,,d]of n)await d()}},K=async(i,e,s,o)=>{const n=Object.keys(i.windows).filter(l=>!(l in e.windows)),a=Object.keys(e.windows).filter(l=>!(l in i.windows)),c=s.isMain();if(c&&n.length>0)for(const l of n)t.log(o,"syncMain","closing",l),l===t.MAIN_WINDOW&&await Promise.all(Object.keys(e.windows).filter(d=>d!==t.MAIN_WINDOW).map(async d=>await p(s,d,o))),await p(s,l,o);if(c&&a.length>0)for(const l of a)await k(s,l,e.windows[l],o)},k=async(i,e,s,o)=>(t.log(o,"createWindow",s),await i.create(e,j(s))),p=async(i,e,s)=>(t.log(s,"closeWindow",e),await i.close(e)),z="[drift] - unexpected undefined action",m="[drift] - unexpected undefined action type",y=i=>{if(i.emitted??=!1,i.action==null)throw console.warn(z,i),new Error(z);if(i.action.type==null||i.action.type.length===0)throw console.warn(m,i),new Error(m)},Q=new D,X=[t.runtimeSetWindowProps.type,t.reloadWindow.type],$=(i,e=!1)=>s=>o=>n=>{let{action:a,emitted:c,emitter:l}=V(n);const d=i.label();y({action:n,emitted:c,emitter:l});const u=t.isDriftAction(a.type);if(u&&t.log(e,"[drift] - middleware",{action:a,emitted:c,emitter:l,host:d}),l===i.label())return;const r=u&&!X.includes(a.type);let w=null;u&&(w=s.getState().drift,a=t.assignLabel(a,w));const h=o(a),_=r?s.getState().drift:null,A=t.shouldEmit(c,a.type);return Q.runExclusive(async()=>{try{w!==null&&_!==null&&await U(w,_,i,e),A&&await i.emit({action:a})}catch(S){t.log(e,"[drift] - ERROR",{error:S.message,action:a,emitted:c,emitter:l,host:d}),s.dispatch(t.setWindowError({key:d,message:S.message}))}}),h},Y=(i,e,s=!1)=>o=>{const n=i!=null?typeof i=="function"?i(o):i:o();return[$(e,s),...n]},B=async({runtime:i,preloadedState:e,middleware:s,debug:o=!1,enablePrerender:n=!0,defaultWindowProps:a,...c})=>{await i.configure();let l;l=O.configureStore({...c,preloadedState:await G(o,i,()=>l,a,e),middleware:Y(s,i,o)}),await Z(l.getState().drift,l.dispatch,i,o);const d=i.label();return l.dispatch(t.internalSetInitial({enablePrerender:n,defaultWindowProps:a,debug:o,label:d})),l.dispatch(t.setWindowStage({stage:"created"})),i.onCloseRequested(()=>l?.dispatch(t.closeWindow({}))),l},G=async(i,e,s,o,n)=>e.isMain()?(await e.subscribe(({action:c,emitter:l,sendState:d})=>{const u=s();if(u==null)return;if(c!=null){y({action:c,emitter:l}),u.dispatch(b(c,l));return}const r=u.getState();d===!0&&e.emit({state:r},l)}),typeof n=="function"?g(o,i,await n()):g(o,i,n)):await new Promise((c,l)=>{(async()=>{try{await e.subscribe(({action:u,emitter:r,state:w})=>{const h=s();if(h==null)return w!=null?c(w):void 0;u!=null&&(y({action:u,emitter:r}),h.dispatch(b(u,r)))}),await e.emit({sendState:!0},t.MAIN_WINDOW)}catch(u){l(u)}})()}),W=B,g=(i,e,s)=>{if(s==null)return s;const o=s[t.SLICE_NAME];return o.config.debug=e??o.config.debug,o.windows=Object.fromEntries(Object.entries(o.windows).filter(([,n])=>n.reserved).map(([n,a])=>(i?.visible!=null&&(a.visible=i.visible),a.focusCount=0,a.centerCount=0,a.processCount=0,[n,a]))),s};class v{async emit(){}async subscribe(){}isMain(){return!0}label(){return t.MAIN_WINDOW}onCloseRequested(){}async listLabels(){return[]}async getProps(){return{}}async create(){}async close(){}async focus(){}async setMinimized(){}async setMaximized(){}async setVisible(){}async setFullscreen(){}async center(){}async setPosition(){}async setSize(){}async setMinSize(){}async setMaxSize(){}async setResizable(){}async setSkipTaskbar(){}async setAlwaysOnTop(){}async setDecorations(){}async setTitle(){}async configure(){}}const H=Object.freeze(Object.defineProperty({__proto__:null,MAIN_WINDOW:t.MAIN_WINDOW,NoopRuntime:v,SLICE_NAME:t.SLICE_NAME,ZERO_SLICE_STATE:t.ZERO_SLICE_STATE,closeWindow:t.closeWindow,completeProcess:t.completeProcess,configureStore:W,createWindow:t.createWindow,focusWindow:t.focusWindow,reducer:t.reducer,registerProcess:t.registerProcess,reloadWindow:t.reloadWindow,selectSliceState:f.selectSliceState,selectWindow:f.selectWindow,selectWindowAttribute:f.selectWindowAttribute,selectWindowKey:f.selectWindowKey,selectWindowLabel:f.selectWindowLabel,selectWindows:f.selectWindows,setWindowAlwaysOnTop:t.setWindowAlwaysOnTop,setWindowDecorations:t.setWindowDecorations,setWindowFullscreen:t.setWindowFullscreen,setWindowMaxSize:t.setWindowMaxSize,setWindowMaximized:t.setWindowMaximized,setWindowMinSize:t.setWindowMinSize,setWindowMinimized:t.setWindowMinimized,setWindowPosition:t.setWindowPosition,setWindowProps:t.setWindowProps,setWindowResizable:t.setWindowResizable,setWindowSize:t.setWindowSize,setWindowSkipTaskbar:t.setWindowSkipTaskbar,setWindowStage:t.setWindowStage,setWindowTitle:t.setWindowTitle,setWindowVisible:t.setWindowVisible,windowPropsZ:t.windowPropsZ},Symbol.toStringTag,{value:"Module"}));exports.MAIN_WINDOW=t.MAIN_WINDOW;exports.SLICE_NAME=t.SLICE_NAME;exports.ZERO_SLICE_STATE=t.ZERO_SLICE_STATE;exports.closeWindow=t.closeWindow;exports.completeProcess=t.completeProcess;exports.createWindow=t.createWindow;exports.focusWindow=t.focusWindow;exports.reducer=t.reducer;exports.registerProcess=t.registerProcess;exports.reloadWindow=t.reloadWindow;exports.setWindowAlwaysOnTop=t.setWindowAlwaysOnTop;exports.setWindowDecorations=t.setWindowDecorations;exports.setWindowFullscreen=t.setWindowFullscreen;exports.setWindowMaxSize=t.setWindowMaxSize;exports.setWindowMaximized=t.setWindowMaximized;exports.setWindowMinSize=t.setWindowMinSize;exports.setWindowMinimized=t.setWindowMinimized;exports.setWindowPosition=t.setWindowPosition;exports.setWindowProps=t.setWindowProps;exports.setWindowResizable=t.setWindowResizable;exports.setWindowSize=t.setWindowSize;exports.setWindowSkipTaskbar=t.setWindowSkipTaskbar;exports.setWindowStage=t.setWindowStage;exports.setWindowTitle=t.setWindowTitle;exports.setWindowVisible=t.setWindowVisible;exports.windowPropsZ=t.windowPropsZ;exports.selectSliceState=f.selectSliceState;exports.selectWindow=f.selectWindow;exports.selectWindowAttribute=f.selectWindowAttribute;exports.selectWindowKey=f.selectWindowKey;exports.selectWindowLabel=f.selectWindowLabel;exports.selectWindows=f.selectWindows;exports.Drift=H;exports.NoopRuntime=v;exports.configureStore=W;
package/dist/index.js DELETED
@@ -1,536 +0,0 @@
1
- import { configureStore as F } from "@reduxjs/toolkit";
2
- import { M as w, g, l as f, a as T, b as N, r as E, v as y, I as V, c as j, d as I, i as $, e as U, s as Q, f as Z, h as K, j as M, k as C, S as q, Z as X, m as B, n as G, o as H, p as J, q as Y, t as x, u as W, w as ee, x as se, y as ie, z as te, A as ae, B as oe, C as ne, D as ce, E as le, F as re, G as ue, H as de, J as fe } from "./state-CGc6dCmt.js";
3
- import { s as we, a as he, b as ye, c as pe, d as _e, e as be } from "./selectors-D1g2urZp.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(c) {
8
- c(o);
9
- });
10
- }
11
- return new (s || (s = Promise))(function(o, c) {
12
- function n(l) {
13
- try {
14
- u(t.next(l));
15
- } catch (d) {
16
- c(d);
17
- }
18
- }
19
- function r(l) {
20
- try {
21
- u(t.throw(l));
22
- } catch (d) {
23
- c(d);
24
- }
25
- }
26
- function u(l) {
27
- l.done ? o(l.value) : a(l.value).then(n, r);
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 }, c = O(this._queue, (n) => s <= n.priority);
41
- c === -1 && e <= this._value ? this._dispatchItem(o) : this._queue.splice(c + 1, 0, o);
42
- });
43
- }
44
- runExclusive(e) {
45
- return ze(this, arguments, void 0, function* (s, t = 1, a = 0) {
46
- const [o, c] = yield this.acquire(t, a);
47
- try {
48
- return yield s(o);
49
- } finally {
50
- c();
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(c) {
126
- c(o);
127
- });
128
- }
129
- return new (s || (s = Promise))(function(o, c) {
130
- function n(l) {
131
- try {
132
- u(t.next(l));
133
- } catch (d) {
134
- c(d);
135
- }
136
- }
137
- function r(l) {
138
- try {
139
- u(t.throw(l));
140
- } catch (d) {
141
- c(d);
142
- }
143
- }
144
- function u(l) {
145
- l.done ? o(l.value) : a(l.value).then(n, r);
146
- }
147
- u((t = t.apply(i, e || [])).next());
148
- });
149
- };
150
- class ge {
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 L = "DA@", A = "://", Te = (i, e) => L.concat(e, A, i), Ee = (i) => {
177
- const [e, s] = i.split(A);
178
- if (s == null) return [i, ""];
179
- const [, t] = e.split(L);
180
- return [s, t];
181
- }, z = (i, e) => ({
182
- ...i,
183
- type: Te(i.type, e)
184
- }), Ie = (i) => {
185
- const [e, s] = Ee(i.type);
186
- return {
187
- emitted: s != null && s.length > 0,
188
- emitter: s,
189
- action: { ...i, type: e }
190
- };
191
- }, Me = (i) => {
192
- const {
193
- centerCount: e,
194
- processCount: s,
195
- focusCount: t,
196
- stage: a,
197
- key: o,
198
- prerenderLabel: c,
199
- reserved: n,
200
- minimized: r,
201
- ...u
202
- } = i;
203
- return u;
204
- }, Ce = async (i, e, s, t) => {
205
- const a = (await s.listLabels()).filter(
206
- (l) => l !== w
207
- ), o = Object.keys(i.windows).filter((l) => l !== w);
208
- g(t, "syncInitial"), f(t, "existing windows in runtime", a.sort()), f(t, "non-main windows in state", o.sort()), T(t);
209
- const c = N.unique([...a, ...o]);
210
- for (const l of c)
211
- !a.includes(l) && s.isMain() ? (f(t, "state window not in runtime, creating", l), await R(s, l, i.windows[l], t)) : o.includes(l) || (f(t, "runtime window not in state, closing", l), await p(s, l, t));
212
- const n = s.label(), r = i.windows[n];
213
- if (r == null) return;
214
- const u = { ...j };
215
- await P(u, r, s, t), e(
216
- E({ label: s.label(), ...await s.getProps() })
217
- );
218
- }, qe = async (i, e, s, t) => {
219
- f(t, "sync", i, e), s.isMain() && await Oe(i, e, s, t);
220
- const a = i.windows[s.label()], o = e.windows[s.label()];
221
- a == null || o == null || await P(a, o, s, t);
222
- }, P = async (i, e, s, t) => {
223
- const a = [];
224
- e.title != null && e.title !== i.title && a.push([
225
- "title",
226
- { prev: i.title, next: e.title },
227
- async () => s.setTitle(e.title)
228
- ]);
229
- const o = e.visible != null && e.visible !== i.visible, c = e.visible === !1, n = () => a.push([
230
- "visible",
231
- { prev: i.visible, next: e.visible },
232
- async () => {
233
- if (await s.setVisible(e.visible), e.visible === !1) return;
234
- let r = e.position;
235
- r ??= (await s.getProps()).position, r != null && (await s.setPosition(V.translate(r, { x: 1, y: 1 })), await s.setPosition(r));
236
- }
237
- ]);
238
- if (o && c && n(), e.skipTaskbar != null && e.skipTaskbar !== i.skipTaskbar && a.push([
239
- "skipTaskbar",
240
- { prev: i.skipTaskbar, next: e.skipTaskbar },
241
- async () => await s.setSkipTaskbar(e.skipTaskbar)
242
- ]), e.maximized != null && e.maximized !== i.maximized && a.push([
243
- "maximized",
244
- { prev: i.maximized, next: e.maximized },
245
- async () => await s.setMaximized(e.maximized)
246
- ]), e.fullscreen != null && e.fullscreen !== i.fullscreen && a.push([
247
- "fullscreen",
248
- { prev: i.fullscreen, next: e.fullscreen },
249
- async () => await s.setFullscreen(e.fullscreen)
250
- ]), e.centerCount !== i.centerCount && a.push([
251
- "center",
252
- { prev: i.centerCount, next: e.centerCount },
253
- async () => s.center()
254
- ]), e.minimized != null && e.minimized !== i.minimized && a.push([
255
- "minimized",
256
- { prev: i.minimized, next: e.minimized },
257
- async () => await s.setMinimized(e.minimized)
258
- ]), e.resizable != null && e.resizable !== i.resizable && a.push([
259
- "resizable",
260
- { prev: i.resizable, next: e.resizable },
261
- async () => await s.setResizable(e.resizable)
262
- ]), e.minSize != null && !y.equals(e.minSize, i.minSize) && a.push([
263
- "minSize",
264
- { prev: i.minSize, next: e.minSize },
265
- async () => await s.setMinSize(e.minSize)
266
- ]), e.maxSize != null && !y.equals(e.maxSize, i.maxSize) && a.push([
267
- "maxSize",
268
- { prev: i.maxSize, next: e.maxSize },
269
- async () => await s.setMaxSize(e.maxSize)
270
- ]), e.size != null && !y.equals(e.size, i.size) && a.push([
271
- "size",
272
- { prev: i.size, next: e.size },
273
- async () => await s.setSize(e.size)
274
- ]), e.position != null && !y.equals(e.position, i.position) && a.push([
275
- "position",
276
- { prev: i.position, next: e.position },
277
- async () => await s.setPosition(e.position)
278
- ]), e.focusCount !== i.focusCount && a.push(
279
- [
280
- "setVisible",
281
- { prev: i.visible, next: e.visible },
282
- async () => await s.setVisible(!0)
283
- ],
284
- [
285
- "focus",
286
- { prev: i.focusCount, next: e.focusCount },
287
- async () => await s.focus()
288
- ]
289
- ), e.decorations != null && e.decorations !== i.decorations && a.push([
290
- "decorations",
291
- { prev: i.decorations, next: e.decorations },
292
- async () => await s.setDecorations(e.decorations)
293
- ]), e.alwaysOnTop != null && e.alwaysOnTop !== i.alwaysOnTop && a.push([
294
- "alwaysOnTop",
295
- { prev: i.alwaysOnTop, next: e.alwaysOnTop },
296
- async () => await s.setAlwaysOnTop(e.alwaysOnTop)
297
- ]), o && !c && n(), a.length !== 0) {
298
- g(t, `syncCurrent, label: ${s.label()}, key: ${e.key}`);
299
- for (const [r, { prev: u, next: l }] of a) f(t, r, u, "->", l);
300
- T(t);
301
- for (const [, , r] of a) await r();
302
- }
303
- }, Oe = async (i, e, s, t) => {
304
- const a = Object.keys(i.windows).filter((n) => !(n in e.windows)), o = Object.keys(e.windows).filter((n) => !(n in i.windows)), c = s.isMain();
305
- if (c && a.length > 0)
306
- for (const n of a)
307
- f(t, "syncMain", "closing", n), n === w && await Promise.all(
308
- Object.keys(e.windows).filter((r) => r !== w).map(async (r) => await p(s, r, t))
309
- ), await p(s, n, t);
310
- if (c && o.length > 0)
311
- for (const n of o)
312
- await R(s, n, e.windows[n], t);
313
- }, R = async (i, e, s, t) => (f(t, "createWindow", s), await i.create(e, Me(s))), p = async (i, e, s) => (f(s, "closeWindow", e), await i.close(e)), S = "[drift] - unexpected undefined action", k = "[drift] - unexpected undefined action type", _ = (i) => {
314
- if (i.emitted ??= !1, i.action == null)
315
- throw console.warn(S, i), new Error(S);
316
- if (i.action.type == null || i.action.type.length === 0)
317
- throw console.warn(k, i), new Error(k);
318
- }, Le = new ge(), Ae = [E.type, I.type], Pe = (i, e = !1) => (s) => (t) => (a) => {
319
- let { action: o, emitted: c, emitter: n } = Ie(a);
320
- const r = i.label();
321
- _({ action: a, emitted: c, emitter: n });
322
- const u = $(o.type);
323
- if (u && f(e, "[drift] - middleware", {
324
- action: o,
325
- emitted: c,
326
- emitter: n,
327
- host: r
328
- }), n === i.label()) return;
329
- const l = u && !Ae.includes(o.type);
330
- let d = null;
331
- u && (d = s.getState().drift, o = U(
332
- o,
333
- d
334
- ));
335
- const h = t(o), b = l ? s.getState().drift : null, D = Q(c, o.type);
336
- return Le.runExclusive(async () => {
337
- try {
338
- d !== null && b !== null && await qe(d, b, i, e), D && await i.emit({ action: o });
339
- } catch (m) {
340
- f(e, "[drift] - ERROR", {
341
- error: m.message,
342
- action: o,
343
- emitted: c,
344
- emitter: n,
345
- host: r
346
- }), s.dispatch(Z({ key: r, message: m.message }));
347
- }
348
- }), h;
349
- }, Re = (i, e, s = !1) => (t) => {
350
- const a = i != null ? typeof i == "function" ? i(t) : i : t();
351
- return [Pe(e, s), ...a];
352
- }, De = async ({
353
- runtime: i,
354
- preloadedState: e,
355
- middleware: s,
356
- debug: t = !1,
357
- enablePrerender: a = !0,
358
- defaultWindowProps: o,
359
- ...c
360
- }) => {
361
- await i.configure();
362
- let n;
363
- n = F({
364
- ...c,
365
- preloadedState: await Fe(
366
- t,
367
- i,
368
- () => n,
369
- o,
370
- e
371
- ),
372
- middleware: Re(s, i, t)
373
- }), await Ce(n.getState().drift, n.dispatch, i, t);
374
- const r = i.label();
375
- return n.dispatch(
376
- K({ enablePrerender: a, defaultWindowProps: o, debug: t, label: r })
377
- ), n.dispatch(M({ stage: "created" })), i.onCloseRequested(() => n?.dispatch(C({}))), n;
378
- }, Fe = async (i, e, s, t, a) => e.isMain() ? (await e.subscribe(({ action: c, emitter: n, sendState: r }) => {
379
- const u = s();
380
- if (u == null) return;
381
- if (c != null) {
382
- _({ action: c, emitter: n }), u.dispatch(z(c, n));
383
- return;
384
- }
385
- const l = u.getState();
386
- r === !0 && e.emit({ state: l }, n);
387
- }), typeof a == "function" ? v(t, i, await a()) : v(t, i, a)) : await new Promise((c, n) => {
388
- (async () => {
389
- try {
390
- await e.subscribe(({ action: u, emitter: l, state: d }) => {
391
- const h = s();
392
- if (h == null)
393
- return d != null ? c(d) : void 0;
394
- u != null && (_({ action: u, emitter: l }), h.dispatch(z(u, l)));
395
- }), await e.emit({ sendState: !0 }, w);
396
- } catch (u) {
397
- n(u);
398
- }
399
- })();
400
- }), Ne = De, v = (i, e, s) => {
401
- if (s == null) return s;
402
- const t = s[q];
403
- return t.config.debug = e ?? t.config.debug, t.windows = Object.fromEntries(
404
- Object.entries(t.windows).filter(([, a]) => a.reserved).map(([a, o]) => (i?.visible != null && (o.visible = i.visible), o.focusCount = 0, o.centerCount = 0, o.processCount = 0, [a, o]))
405
- ), s;
406
- };
407
- class Ve {
408
- async emit() {
409
- }
410
- async subscribe() {
411
- }
412
- isMain() {
413
- return !0;
414
- }
415
- label() {
416
- return w;
417
- }
418
- onCloseRequested() {
419
- }
420
- async listLabels() {
421
- return [];
422
- }
423
- async getProps() {
424
- return {};
425
- }
426
- async create() {
427
- }
428
- async close() {
429
- }
430
- async focus() {
431
- }
432
- async setMinimized() {
433
- }
434
- async setMaximized() {
435
- }
436
- async setVisible() {
437
- }
438
- async setFullscreen() {
439
- }
440
- async center() {
441
- }
442
- async setPosition() {
443
- }
444
- async setSize() {
445
- }
446
- async setMinSize() {
447
- }
448
- async setMaxSize() {
449
- }
450
- async setResizable() {
451
- }
452
- async setSkipTaskbar() {
453
- }
454
- async setAlwaysOnTop() {
455
- }
456
- async setDecorations() {
457
- }
458
- async setTitle() {
459
- }
460
- async configure() {
461
- }
462
- }
463
- const Qe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
464
- __proto__: null,
465
- MAIN_WINDOW: w,
466
- NoopRuntime: Ve,
467
- SLICE_NAME: q,
468
- ZERO_SLICE_STATE: X,
469
- closeWindow: C,
470
- completeProcess: B,
471
- configureStore: Ne,
472
- createWindow: G,
473
- focusWindow: H,
474
- reducer: J,
475
- registerProcess: Y,
476
- reloadWindow: I,
477
- selectSliceState: we,
478
- selectWindow: he,
479
- selectWindowAttribute: ye,
480
- selectWindowKey: pe,
481
- selectWindowLabel: _e,
482
- selectWindows: be,
483
- setWindowAlwaysOnTop: x,
484
- setWindowDecorations: W,
485
- setWindowFullscreen: ee,
486
- setWindowMaxSize: se,
487
- setWindowMaximized: ie,
488
- setWindowMinSize: te,
489
- setWindowMinimized: ae,
490
- setWindowPosition: oe,
491
- setWindowProps: ne,
492
- setWindowResizable: ce,
493
- setWindowSize: le,
494
- setWindowSkipTaskbar: re,
495
- setWindowStage: M,
496
- setWindowTitle: ue,
497
- setWindowVisible: de,
498
- windowPropsZ: fe
499
- }, Symbol.toStringTag, { value: "Module" }));
500
- export {
501
- Qe as Drift,
502
- w as MAIN_WINDOW,
503
- Ve as NoopRuntime,
504
- q as SLICE_NAME,
505
- X as ZERO_SLICE_STATE,
506
- C as closeWindow,
507
- B as completeProcess,
508
- Ne as configureStore,
509
- G as createWindow,
510
- H as focusWindow,
511
- J as reducer,
512
- Y as registerProcess,
513
- I as reloadWindow,
514
- we as selectSliceState,
515
- he as selectWindow,
516
- ye as selectWindowAttribute,
517
- pe as selectWindowKey,
518
- _e as selectWindowLabel,
519
- be as selectWindows,
520
- x as setWindowAlwaysOnTop,
521
- W as setWindowDecorations,
522
- ee as setWindowFullscreen,
523
- se as setWindowMaxSize,
524
- ie as setWindowMaximized,
525
- te as setWindowMinSize,
526
- ae as setWindowMinimized,
527
- oe as setWindowPosition,
528
- ne as setWindowProps,
529
- ce as setWindowResizable,
530
- le as setWindowSize,
531
- re as setWindowSkipTaskbar,
532
- M as setWindowStage,
533
- ue as setWindowTitle,
534
- de as setWindowVisible,
535
- fe as windowPropsZ
536
- };
@@ -1,22 +0,0 @@
1
- import { M as i } from "./state-CGc6dCmt.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) => r(n, e)?.[t] ?? null, w = (n, e) => l(n).keyLabels[e];
15
- export {
16
- r as a,
17
- d as b,
18
- u as c,
19
- w as d,
20
- a as e,
21
- l as s
22
- };
@@ -1 +0,0 @@
1
- "use strict";const i=require("./state-BFBdNgbN.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)=>c(n,e)?.[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;
@@ -1,15 +0,0 @@
1
- import { destructor } from '@synnaxlabs/x';
2
- import { EffectCallback } from 'react';
3
- /**
4
- * A hook that allows a user to tap into the lifecycle of a window.
5
- * Maintains a similar API to useEffect. Executes the callback when the
6
- * window state changes to 'created', and cleans up when the window state
7
- * changes to 'closing'.
8
- *
9
- * @param cb - The callback to execute.
10
- * @param key - The key of the window to subscribe to.
11
- * If not provided, the current window is used.
12
- */
13
- export declare const useWindowLifecycle: (cb: EffectCallback, key?: string) => void;
14
- export declare const useAsyncWindowLifecycle: (cb: () => Promise<destructor.Async | undefined>, key?: string) => void;
15
- //# sourceMappingURL=hooks.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/react/hooks.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,KAAK,cAAc,EAAqB,MAAM,OAAO,CAAC;AAM/D;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,GAAI,IAAI,cAAc,EAAE,MAAM,MAAM,KAAG,IAoBrE,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAClC,IAAI,MAAM,OAAO,CAAC,UAAU,CAAC,KAAK,GAAG,SAAS,CAAC,EAC/C,MAAM,MAAM,KACX,IAmCF,CAAC"}