Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rko

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rko - npm Package Compare versions

Comparing version 0.5.7 to 0.5.8

CHANGELOG.md

2

dist/cjs/index.js

@@ -1,1 +0,1 @@

var U=Object.defineProperty;var P=Object.getOwnPropertySymbols;var D=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable;var k=(r,t,e)=>t in r?U(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,y=(r,t)=>{for(var e in t||(t={}))D.call(t,e)&&k(r,e,t[e]);if(P)for(var e of P(t))I.call(t,e)&&k(r,e,t[e]);return r};var R=(r,t,e)=>new Promise((n,a)=>{var o=h=>{try{d(e.next(h))}catch(s){a(s)}},u=h=>{try{d(e.throw(h))}catch(s){a(s)}},d=h=>h.done?n(h.value):Promise.resolve(h.value).then(o,u);d((e=e.apply(r,t)).next())});function _(r){let t,e=new Set,n=(s,c)=>{let i=typeof s=="function"?s(t):s;if(i!==t){let f=t;t=c?i:Object.assign({},t,i),e.forEach(p=>p(t,f))}},a=()=>t,o=(s,c=a,i=Object.is)=>{let f=c(t);function p(){let S=c(t);if(!i(f,S)){let l=f;s(f=S,l)}}return e.add(p),()=>e.delete(p)},h={setState:n,getState:a,subscribe:(s,c,i)=>c||i?o(s,c,i):(e.add(s),()=>e.delete(s)),destroy:()=>e.clear()};return t=r(n,a,h),h}import{useReducer as B,useRef as b,useEffect as V,useLayoutEffect as z}from"react";function G(r){let t,e=new Set,n=(s,c)=>{let i=typeof s=="function"?s(t):s;if(i!==t){let f=t;t=c?i:Object.assign({},t,i),e.forEach(p=>p(t,f))}},a=()=>t,o=(s,c=a,i=Object.is)=>{let f=c(t);function p(){let S=c(t);if(!i(f,S)){let l=f;s(f=S,l)}}return e.add(p),()=>e.delete(p)},h={setState:n,getState:a,subscribe:(s,c,i)=>c||i?o(s,c,i):(e.add(s),()=>e.delete(s)),destroy:()=>e.clear()};return t=r(n,a,h),h}var L=typeof window=="undefined"||!window.navigator||/ServerSideRendering|^Deno\//.test(window.navigator.userAgent),j=L?V:z;function A(r){let t=typeof r=="function"?G(r):r,e=(n=t.getState,a=Object.is)=>{let[,o]=B(l=>l+1,0),u=t.getState(),d=b(u),h=b(n),s=b(a),c=b(!1),i=b();i.current===void 0&&(i.current=n(u));let f,p=!1;(d.current!==u||h.current!==n||s.current!==a||c.current)&&(f=n(u),p=!a(i.current,f)),j(()=>{p&&(i.current=f),d.current=u,h.current=n,s.current=a,c.current=!1});let S=b(u);return j(()=>{let l=()=>{try{let T=t.getState(),x=h.current(T);s.current(i.current,x)||(d.current=T,i.current=x,o())}catch(T){c.current=!0,o()}},E=t.subscribe(l);return t.getState()!==S.current&&l(),E},[]),p?f:i.current};return Object.assign(e,t),e[Symbol.iterator]=function(){console.warn("[useStore, api] = create() is deprecated and will be removed in v4");let n=[e,t];return{next(){let a=n.length<=0;return{value:n.shift(),done:a}}}},e}function W(){if(!(!navigator.userAgentData&&/Safari\//.test(navigator.userAgent)&&!/Chrom(e|ium)\//.test(navigator.userAgent))||!indexedDB.databases)return Promise.resolve();let t;return new Promise(e=>{let n=()=>indexedDB.databases().finally(e);t=setInterval(n,100),n()}).finally(()=>clearInterval(t))}var M=W;function m(r){return new Promise((t,e)=>{r.oncomplete=r.onsuccess=()=>t(r.result),r.onabort=r.onerror=()=>e(r.error)})}function H(r,t){let e=M().then(()=>{let n=indexedDB.open(r);return n.onupgradeneeded=()=>n.result.createObjectStore(t),m(n)});return(n,a)=>e.then(o=>a(o.transaction(t,n).objectStore(t)))}var v;function O(){return v||(v=H("keyval-store","keyval")),v}function w(r,t=O()){return t("readonly",e=>m(e.get(r)))}function g(r,t,e=O()){return e("readwrite",n=>(n.put(t,r),m(n.transaction)))}function C(r,t){let e=y({},r),n=Object.entries(t);for(let[a,o]of n)e[a]=o===Object(o)&&!Array.isArray(o)?C(e[a],o):o;return e}var $=class{constructor(t,e="react-state-manager",n=1,a=(o,u,d)=>u){this.stack=[];this.pointer=-1;this.status="loading";this.persist=()=>g(this.id,this._state);this.applyPatch=t=>(this._state=this.cleanup(C(this._state,t),t),this.store.setState(this._state,!0),this);this.cleanup=(t,e)=>t;this.patchState=t=>(this.applyPatch(t),this);this.setState=t=>(this.pointer++,this.stack=this.stack.slice(0,this.pointer),this.stack.push(t),this.applyPatch(t.after),this.persist(),this);this.reset=()=>(this.stack=[],this.pointer=-1,this._state=this.initialState,this.store.setState(this.initialState,!0),this);this.resetHistory=()=>(this.stack=[],this.pointer=-1,this);this.undo=()=>{if(!this.canUndo)return this;let t=this.stack[this.pointer];return this.pointer--,this.applyPatch(t.before),this.persist(),this};this.redo=()=>{if(!this.canRedo)return this;this.pointer++;let t=this.stack[this.pointer];return this.applyPatch(t.after),this.persist(),this};this.setSnapshot=()=>(this.snapshot=y({},this._state),this);this.forceUpdate=()=>{this.store.setState(this._state,!0)};this.id=e,this._state=t,this.snapshot=t,this.initialState=t,this.store=_(()=>t),this.useStore=A(this.store),w(this.id).then(o=>R(this,null,function*(){if(o){let u=o,d=yield w(e+"_version");d&&d<n&&(u=a(o,t,d)),yield g(e+"_version",n),this._state=u,this.snapshot=u,this.initialState=u,this.status="ready",this.store.setState(u)}else g(e+"_version",n)}))}get canUndo(){return this.pointer>-1}get canRedo(){return this.pointer<this.stack.length-1}get state(){return this._state}};export{$ as StateManager};
var U=Object.defineProperty;var P=Object.getOwnPropertySymbols;var D=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable;var _=(n,t,e)=>t in n?U(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,y=(n,t)=>{for(var e in t||(t={}))D.call(t,e)&&_(n,e,t[e]);if(P)for(var e of P(t))I.call(t,e)&&_(n,e,t[e]);return n};var k=(n,t,e)=>new Promise((r,a)=>{var o=h=>{try{p(e.next(h))}catch(s){a(s)}},u=h=>{try{p(e.throw(h))}catch(s){a(s)}},p=h=>h.done?r(h.value):Promise.resolve(h.value).then(o,u);p((e=e.apply(n,t)).next())});function R(n){let t,e=new Set,r=(s,c)=>{let i=typeof s=="function"?s(t):s;if(i!==t){let f=t;t=c?i:Object.assign({},t,i),e.forEach(d=>d(t,f))}},a=()=>t,o=(s,c=a,i=Object.is)=>{let f=c(t);function d(){let S=c(t);if(!i(f,S)){let l=f;s(f=S,l)}}return e.add(d),()=>e.delete(d)},h={setState:r,getState:a,subscribe:(s,c,i)=>c||i?o(s,c,i):(e.add(s),()=>e.delete(s)),destroy:()=>e.clear()};return t=n(r,a,h),h}import{useReducer as B,useRef as b,useEffect as V,useLayoutEffect as z}from"react";function G(n){let t,e=new Set,r=(s,c)=>{let i=typeof s=="function"?s(t):s;if(i!==t){let f=t;t=c?i:Object.assign({},t,i),e.forEach(d=>d(t,f))}},a=()=>t,o=(s,c=a,i=Object.is)=>{let f=c(t);function d(){let S=c(t);if(!i(f,S)){let l=f;s(f=S,l)}}return e.add(d),()=>e.delete(d)},h={setState:r,getState:a,subscribe:(s,c,i)=>c||i?o(s,c,i):(e.add(s),()=>e.delete(s)),destroy:()=>e.clear()};return t=n(r,a,h),h}var H=typeof window=="undefined"||!window.navigator||/ServerSideRendering|^Deno\//.test(window.navigator.userAgent),j=H?V:z;function A(n){let t=typeof n=="function"?G(n):n,e=(r=t.getState,a=Object.is)=>{let[,o]=B(l=>l+1,0),u=t.getState(),p=b(u),h=b(r),s=b(a),c=b(!1),i=b();i.current===void 0&&(i.current=r(u));let f,d=!1;(p.current!==u||h.current!==r||s.current!==a||c.current)&&(f=r(u),d=!a(i.current,f)),j(()=>{d&&(i.current=f),p.current=u,h.current=r,s.current=a,c.current=!1});let S=b(u);return j(()=>{let l=()=>{try{let T=t.getState(),w=h.current(T);s.current(i.current,w)||(p.current=T,i.current=w,o())}catch(T){c.current=!0,o()}},E=t.subscribe(l);return t.getState()!==S.current&&l(),E},[]),d?f:i.current};return Object.assign(e,t),e[Symbol.iterator]=function(){console.warn("[useStore, api] = create() is deprecated and will be removed in v4");let r=[e,t];return{next(){let a=r.length<=0;return{value:r.shift(),done:a}}}},e}function L(){if(!(!navigator.userAgentData&&/Safari\//.test(navigator.userAgent)&&!/Chrom(e|ium)\//.test(navigator.userAgent))||!indexedDB.databases)return Promise.resolve();let t;return new Promise(e=>{let r=()=>indexedDB.databases().finally(e);t=setInterval(r,100),r()}).finally(()=>clearInterval(t))}var M=L;function m(n){return new Promise((t,e)=>{n.oncomplete=n.onsuccess=()=>t(n.result),n.onabort=n.onerror=()=>e(n.error)})}function W(n,t){let e=M().then(()=>{let r=indexedDB.open(n);return r.onupgradeneeded=()=>r.result.createObjectStore(t),m(r)});return(r,a)=>e.then(o=>a(o.transaction(t,r).objectStore(t)))}var v;function O(){return v||(v=W("keyval-store","keyval")),v}function x(n,t=O()){return t("readonly",e=>m(e.get(n)))}function g(n,t,e=O()){return e("readwrite",r=>(r.put(t,n),m(r.transaction)))}function C(n,t){let e=y({},n),r=Object.entries(t);for(let[a,o]of r)e[a]=o===Object(o)&&!Array.isArray(o)?C(e[a],o):o;return e}var $=class{constructor(t,e="react-state-manager",r=1,a=(o,u,p)=>u){this.stack=[];this.pointer=-1;this.status="loading";this.persist=()=>g(this.id,this._state);this.applyPatch=t=>{let e=this._state,r=C(this._state,t);return this._state=this.cleanup(r,e,t),this.store.setState(this._state,!0),this};this.cleanup=(t,e,r)=>t;this.patchState=t=>(this.applyPatch(t),this);this.replaceState=t=>(this._state=this.cleanup(t,this._state,t),this.store.setState(this._state,!0),this);this.setState=t=>(this.pointer++,this.stack=this.stack.slice(0,this.pointer),this.stack.push(t),this.applyPatch(t.after),this.persist(),this);this.reset=()=>(this._state=this.initialState,this.store.setState(this.initialState,!0),this.resetHistory(),this.persist(),this);this.resetHistory=()=>(this.stack=[],this.pointer=-1,this);this.undo=()=>{if(!this.canUndo)return this;let t=this.stack[this.pointer];return this.pointer--,this.applyPatch(t.before),this.persist(),this};this.redo=()=>{if(!this.canRedo)return this;this.pointer++;let t=this.stack[this.pointer];return this.applyPatch(t.after),this.persist(),this};this.setSnapshot=()=>(this.snapshot=y({},this._state),this);this.forceUpdate=()=>{this.store.setState(this._state,!0)};this.id=e,this._state=t,this.snapshot=t,this.initialState=t,this.store=R(()=>t),this.useStore=A(this.store),x(this.id).then(o=>k(this,null,function*(){if(o){let u=o,p=yield x(e+"_version");p&&p<r&&(u=a(o,t,p)),yield g(e+"_version",r),this._state=u,this.snapshot=u,this.initialState=u,this.status="ready",this.store.setState(this._state,!0)}else g(e+"_version",r)}))}get canUndo(){return this.pointer>-1}get canRedo(){return this.pointer<this.stack.length-1}get state(){return this._state}};export{$ as StateManager};

@@ -1,296 +0,1 @@

// ../../node_modules/zustand/esm/vanilla.mjs
function create(createState) {
let state;
const listeners = new Set();
const setState = (partial, replace) => {
const nextState = typeof partial === "function" ? partial(state) : partial;
if (nextState !== state) {
const previousState = state;
state = replace ? nextState : Object.assign({}, state, nextState);
listeners.forEach((listener) => listener(state, previousState));
}
};
const getState = () => state;
const subscribeWithSelector = (listener, selector = getState, equalityFn = Object.is) => {
let currentSlice = selector(state);
function listenerToAdd() {
const nextSlice = selector(state);
if (!equalityFn(currentSlice, nextSlice)) {
const previousSlice = currentSlice;
listener(currentSlice = nextSlice, previousSlice);
}
}
listeners.add(listenerToAdd);
return () => listeners.delete(listenerToAdd);
};
const subscribe = (listener, selector, equalityFn) => {
if (selector || equalityFn) {
return subscribeWithSelector(listener, selector, equalityFn);
}
listeners.add(listener);
return () => listeners.delete(listener);
};
const destroy = () => listeners.clear();
const api = { setState, getState, subscribe, destroy };
state = createState(setState, getState, api);
return api;
}
// ../../node_modules/zustand/esm/index.mjs
import { useReducer, useRef, useEffect, useLayoutEffect } from "react";
function create$1(createState) {
let state;
const listeners = new Set();
const setState = (partial, replace) => {
const nextState = typeof partial === "function" ? partial(state) : partial;
if (nextState !== state) {
const previousState = state;
state = replace ? nextState : Object.assign({}, state, nextState);
listeners.forEach((listener) => listener(state, previousState));
}
};
const getState = () => state;
const subscribeWithSelector = (listener, selector = getState, equalityFn = Object.is) => {
let currentSlice = selector(state);
function listenerToAdd() {
const nextSlice = selector(state);
if (!equalityFn(currentSlice, nextSlice)) {
const previousSlice = currentSlice;
listener(currentSlice = nextSlice, previousSlice);
}
}
listeners.add(listenerToAdd);
return () => listeners.delete(listenerToAdd);
};
const subscribe = (listener, selector, equalityFn) => {
if (selector || equalityFn) {
return subscribeWithSelector(listener, selector, equalityFn);
}
listeners.add(listener);
return () => listeners.delete(listener);
};
const destroy = () => listeners.clear();
const api = { setState, getState, subscribe, destroy };
state = createState(setState, getState, api);
return api;
}
var isSSR = typeof window === "undefined" || !window.navigator || /ServerSideRendering|^Deno\//.test(window.navigator.userAgent);
var useIsomorphicLayoutEffect = isSSR ? useEffect : useLayoutEffect;
function create2(createState) {
const api = typeof createState === "function" ? create$1(createState) : createState;
const useStore = (selector = api.getState, equalityFn = Object.is) => {
const [, forceUpdate] = useReducer((c) => c + 1, 0);
const state = api.getState();
const stateRef = useRef(state);
const selectorRef = useRef(selector);
const equalityFnRef = useRef(equalityFn);
const erroredRef = useRef(false);
const currentSliceRef = useRef();
if (currentSliceRef.current === void 0) {
currentSliceRef.current = selector(state);
}
let newStateSlice;
let hasNewStateSlice = false;
if (stateRef.current !== state || selectorRef.current !== selector || equalityFnRef.current !== equalityFn || erroredRef.current) {
newStateSlice = selector(state);
hasNewStateSlice = !equalityFn(currentSliceRef.current, newStateSlice);
}
useIsomorphicLayoutEffect(() => {
if (hasNewStateSlice) {
currentSliceRef.current = newStateSlice;
}
stateRef.current = state;
selectorRef.current = selector;
equalityFnRef.current = equalityFn;
erroredRef.current = false;
});
const stateBeforeSubscriptionRef = useRef(state);
useIsomorphicLayoutEffect(() => {
const listener = () => {
try {
const nextState = api.getState();
const nextStateSlice = selectorRef.current(nextState);
if (!equalityFnRef.current(currentSliceRef.current, nextStateSlice)) {
stateRef.current = nextState;
currentSliceRef.current = nextStateSlice;
forceUpdate();
}
} catch (error) {
erroredRef.current = true;
forceUpdate();
}
};
const unsubscribe = api.subscribe(listener);
if (api.getState() !== stateBeforeSubscriptionRef.current) {
listener();
}
return unsubscribe;
}, []);
return hasNewStateSlice ? newStateSlice : currentSliceRef.current;
};
Object.assign(useStore, api);
useStore[Symbol.iterator] = function() {
console.warn("[useStore, api] = create() is deprecated and will be removed in v4");
const items = [useStore, api];
return {
next() {
const done = items.length <= 0;
return { value: items.shift(), done };
}
};
};
return useStore;
}
// ../../node_modules/safari-14-idb-fix/dist/esm/index.js
function idbReady() {
const isSafari = !navigator.userAgentData && /Safari\//.test(navigator.userAgent) && !/Chrom(e|ium)\//.test(navigator.userAgent);
if (!isSafari || !indexedDB.databases)
return Promise.resolve();
let intervalId;
return new Promise((resolve) => {
const tryIdb = () => indexedDB.databases().finally(resolve);
intervalId = setInterval(tryIdb, 100);
tryIdb();
}).finally(() => clearInterval(intervalId));
}
var esm_default = idbReady;
// ../../node_modules/idb-keyval/dist/esm/index.js
function promisifyRequest(request) {
return new Promise((resolve, reject) => {
request.oncomplete = request.onsuccess = () => resolve(request.result);
request.onabort = request.onerror = () => reject(request.error);
});
}
function createStore(dbName, storeName) {
const dbp = esm_default().then(() => {
const request = indexedDB.open(dbName);
request.onupgradeneeded = () => request.result.createObjectStore(storeName);
return promisifyRequest(request);
});
return (txMode, callback) => dbp.then((db) => callback(db.transaction(storeName, txMode).objectStore(storeName)));
}
var defaultGetStoreFunc;
function defaultGetStore() {
if (!defaultGetStoreFunc) {
defaultGetStoreFunc = createStore("keyval-store", "keyval");
}
return defaultGetStoreFunc;
}
function get(key, customStore = defaultGetStore()) {
return customStore("readonly", (store) => promisifyRequest(store.get(key)));
}
function set(key, value, customStore = defaultGetStore()) {
return customStore("readwrite", (store) => {
store.put(value, key);
return promisifyRequest(store.transaction);
});
}
// src/index.tsx
function merge(target, patch) {
const result = { ...target };
const entries = Object.entries(patch);
for (const [key, value] of entries)
result[key] = value === Object(value) && !Array.isArray(value) ? merge(result[key], value) : value;
return result;
}
var StateManager = class {
constructor(initialState, id = "react-state-manager", version = 1, update = (prev, next, prevVersion) => next) {
this.stack = [];
this.pointer = -1;
this.status = "loading";
this.persist = () => set(this.id, this._state);
this.applyPatch = (patch) => {
this._state = this.cleanup(merge(this._state, patch), patch);
this.store.setState(this._state, true);
return this;
};
this.cleanup = (state, patch) => state;
this.patchState = (patch) => {
this.applyPatch(patch);
return this;
};
this.setState = (command) => {
this.pointer++;
this.stack = this.stack.slice(0, this.pointer);
this.stack.push(command);
this.applyPatch(command.after);
this.persist();
return this;
};
this.reset = () => {
this.stack = [];
this.pointer = -1;
this._state = this.initialState;
this.store.setState(this.initialState, true);
return this;
};
this.resetHistory = () => {
this.stack = [];
this.pointer = -1;
return this;
};
this.undo = () => {
if (!this.canUndo)
return this;
const command = this.stack[this.pointer];
this.pointer--;
this.applyPatch(command.before);
this.persist();
return this;
};
this.redo = () => {
if (!this.canRedo)
return this;
this.pointer++;
const command = this.stack[this.pointer];
this.applyPatch(command.after);
this.persist();
return this;
};
this.setSnapshot = () => {
this.snapshot = { ...this._state };
return this;
};
this.forceUpdate = () => {
this.store.setState(this._state, true);
};
this.id = id;
this._state = initialState;
this.snapshot = initialState;
this.initialState = initialState;
this.store = create(() => initialState);
this.useStore = create2(this.store);
get(this.id).then(async (saved) => {
if (saved) {
let next = saved;
let savedVersion = await get(id + "_version");
if (savedVersion && savedVersion < version) {
next = update(saved, initialState, savedVersion);
}
await set(id + "_version", version);
this._state = next;
this.snapshot = next;
this.initialState = next;
this.status = "ready";
this.store.setState(next);
} else {
set(id + "_version", version);
}
});
}
get canUndo() {
return this.pointer > -1;
}
get canRedo() {
return this.pointer < this.stack.length - 1;
}
get state() {
return this._state;
}
};
export {
StateManager
};
var V=Object.create;var g=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames,_=Object.getOwnPropertySymbols,H=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty,L=Object.prototype.propertyIsEnumerable;var R=(r,t,e)=>t in r?g(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,m=(r,t)=>{for(var e in t||(t={}))k.call(t,e)&&R(r,e,t[e]);if(_)for(var e of _(t))L.call(t,e)&&R(r,e,t[e]);return r};var j=r=>g(r,"__esModule",{value:!0});var W=(r,t)=>{j(r);for(var e in t)g(r,e,{get:t[e],enumerable:!0})},$=(r,t,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of G(t))!k.call(r,n)&&n!=="default"&&g(r,n,{get:()=>t[n],enumerable:!(e=z(t,n))||e.enumerable});return r},J=r=>$(j(g(r!=null?V(H(r)):{},"default",r&&r.__esModule&&"default"in r?{get:()=>r.default,enumerable:!0}:{value:r,enumerable:!0})),r);var A=(r,t,e)=>new Promise((n,a)=>{var o=h=>{try{p(e.next(h))}catch(s){a(s)}},u=h=>{try{p(e.throw(h))}catch(s){a(s)}},p=h=>h.done?n(h.value):Promise.resolve(h.value).then(o,u);p((e=e.apply(r,t)).next())});W(exports,{StateManager:()=>I});function M(r){let t,e=new Set,n=(s,c)=>{let i=typeof s=="function"?s(t):s;if(i!==t){let f=t;t=c?i:Object.assign({},t,i),e.forEach(d=>d(t,f))}},a=()=>t,o=(s,c=a,i=Object.is)=>{let f=c(t);function d(){let b=c(t);if(!i(f,b)){let S=f;s(f=b,S)}}return e.add(d),()=>e.delete(d)},h={setState:n,getState:a,subscribe:(s,c,i)=>c||i?o(s,c,i):(e.add(s),()=>e.delete(s)),destroy:()=>e.clear()};return t=r(n,a,h),h}var l=J(require("react"));function K(r){let t,e=new Set,n=(s,c)=>{let i=typeof s=="function"?s(t):s;if(i!==t){let f=t;t=c?i:Object.assign({},t,i),e.forEach(d=>d(t,f))}},a=()=>t,o=(s,c=a,i=Object.is)=>{let f=c(t);function d(){let b=c(t);if(!i(f,b)){let S=f;s(f=b,S)}}return e.add(d),()=>e.delete(d)},h={setState:n,getState:a,subscribe:(s,c,i)=>c||i?o(s,c,i):(e.add(s),()=>e.delete(s)),destroy:()=>e.clear()};return t=r(n,a,h),h}var Q=typeof window=="undefined"||!window.navigator||/ServerSideRendering|^Deno\//.test(window.navigator.userAgent),O=Q?l.useEffect:l.useLayoutEffect;function C(r){let t=typeof r=="function"?K(r):r,e=(n=t.getState,a=Object.is)=>{let[,o]=(0,l.useReducer)(S=>S+1,0),u=t.getState(),p=(0,l.useRef)(u),h=(0,l.useRef)(n),s=(0,l.useRef)(a),c=(0,l.useRef)(!1),i=(0,l.useRef)();i.current===void 0&&(i.current=n(u));let f,d=!1;(p.current!==u||h.current!==n||s.current!==a||c.current)&&(f=n(u),d=!a(i.current,f)),O(()=>{d&&(i.current=f),p.current=u,h.current=n,s.current=a,c.current=!1});let b=(0,l.useRef)(u);return O(()=>{let S=()=>{try{let y=t.getState(),P=h.current(y);s.current(i.current,P)||(p.current=y,i.current=P,o())}catch(y){c.current=!0,o()}},B=t.subscribe(S);return t.getState()!==b.current&&S(),B},[]),d?f:i.current};return Object.assign(e,t),e[Symbol.iterator]=function(){console.warn("[useStore, api] = create() is deprecated and will be removed in v4");let n=[e,t];return{next(){let a=n.length<=0;return{value:n.shift(),done:a}}}},e}function X(){if(!(!navigator.userAgentData&&/Safari\//.test(navigator.userAgent)&&!/Chrom(e|ium)\//.test(navigator.userAgent))||!indexedDB.databases)return Promise.resolve();let t;return new Promise(e=>{let n=()=>indexedDB.databases().finally(e);t=setInterval(n,100),n()}).finally(()=>clearInterval(t))}var E=X;function v(r){return new Promise((t,e)=>{r.oncomplete=r.onsuccess=()=>t(r.result),r.onabort=r.onerror=()=>e(r.error)})}function Y(r,t){let e=E().then(()=>{let n=indexedDB.open(r);return n.onupgradeneeded=()=>n.result.createObjectStore(t),v(n)});return(n,a)=>e.then(o=>a(o.transaction(t,n).objectStore(t)))}var x;function U(){return x||(x=Y("keyval-store","keyval")),x}function w(r,t=U()){return t("readonly",e=>v(e.get(r)))}function T(r,t,e=U()){return e("readwrite",n=>(n.put(t,r),v(n.transaction)))}function D(r,t){let e=m({},r),n=Object.entries(t);for(let[a,o]of n)e[a]=o===Object(o)&&!Array.isArray(o)?D(e[a],o):o;return e}var I=class{constructor(t,e="react-state-manager",n=1,a=(o,u,p)=>u){this.stack=[];this.pointer=-1;this.status="loading";this.persist=()=>T(this.id,this._state);this.applyPatch=t=>{let e=this._state,n=D(this._state,t);return this._state=this.cleanup(n,e,t),this.store.setState(this._state,!0),this};this.cleanup=(t,e,n)=>t;this.patchState=t=>(this.applyPatch(t),this);this.replaceState=t=>(this._state=this.cleanup(t,this._state,t),this.store.setState(this._state,!0),this);this.setState=t=>(this.pointer++,this.stack=this.stack.slice(0,this.pointer),this.stack.push(t),this.applyPatch(t.after),this.persist(),this);this.reset=()=>(this._state=this.initialState,this.store.setState(this.initialState,!0),this.resetHistory(),this.persist(),this);this.resetHistory=()=>(this.stack=[],this.pointer=-1,this);this.undo=()=>{if(!this.canUndo)return this;let t=this.stack[this.pointer];return this.pointer--,this.applyPatch(t.before),this.persist(),this};this.redo=()=>{if(!this.canRedo)return this;this.pointer++;let t=this.stack[this.pointer];return this.applyPatch(t.after),this.persist(),this};this.setSnapshot=()=>(this.snapshot=m({},this._state),this);this.forceUpdate=()=>{this.store.setState(this._state,!0)};this.id=e,this._state=t,this.snapshot=t,this.initialState=t,this.store=M(()=>t),this.useStore=C(this.store),w(this.id).then(o=>A(this,null,function*(){if(o){let u=o,p=yield w(e+"_version");p&&p<n&&(u=a(o,t,p)),yield T(e+"_version",n),this._state=u,this.snapshot=u,this.initialState=u,this.status="ready",this.store.setState(this._state,!0)}else T(e+"_version",n)}))}get canUndo(){return this.pointer>-1}get canRedo(){return this.pointer<this.stack.length-1}get state(){return this._state}};

@@ -162,3 +162,3 @@ ![logo](./rko-logo.svg)

Update the state and push the command to the undo/redo stack. This method accepts a `Command` type object containing two `Patch`es: `before` and `after`. The `after` patch should contain the changes to the state that you wish to make immediately and when the command is "re-done". The `before` patch should contain the changes to make when the command is "undone".
Update the state, push the command to the undo/redo stack, and persist the new state. This method accepts a `Command` type object containing two `Patch`es: `before` and `after`. The `after` patch should contain the changes to the state that you wish to make immediately and when the command is "re-done". The `before` patch should contain the changes to make when the command is "undone".

@@ -177,8 +177,21 @@ ```ts

#### `cleanup(state: T, patch: Patch<T>)`
#### `replaceState(state: T)`
The cleanup method is called on every state change, _after_ applying the current patch. It returns the "final" updated state. You can override this method in order to clean up any state that is no longer needed. For example, if you have a state that is a list of items, you can use the cleanup method to remove items that are no longer in the list. Note that the changes won't be present in the undo/redo stack.
Works like `patchState` but accepts an entire state instead of a patch. This is useful for cases where a deep merge may be too expensive, such as changing items during a drag or scroll interaction. Note that, like `patchState`, this method will not effect the undo/redo stack. You might also want to call `resetHistory`.
Example:
```ts
cleanup = (state: T, patch: Patch<T>) => {
loadNewTodos = (state: State) =>
this.replaceState({
todos,
})
```
#### `cleanup(next: T, prev: T, patch: Patch<T>)`
The cleanup method is called on every state change, _after_ applying the current patch. It receives the next state, the previous state, and the patch that was just applied. It returns the "final" updated state. You can override this method in order to clean up any state that is no longer needed. For example, if you have a state that is a list of items, you can use the cleanup method to remove items that are no longer in the list. Note that the changes won't be present in the undo/redo stack.
```ts
cleanup = (next: State) => {
const final = { ...state }

@@ -198,2 +211,17 @@

```ts
cleanup = (next: State, prev: State, patch: Patch<State>) => {
// Log an ID from the patch?
if (patch.patchId) {
logger.log(patch.patchId)
}
// Create a JSON patch and update the server?
const serverPatch = jsonpatch.compare(prev, state)
server.sendUpdate(clientId, serverPatch)
return next
}
```
### Public API

@@ -227,3 +255,3 @@

### `snapshot`
#### `snapshot`

@@ -230,0 +258,0 @@ The saved snapshot. You can use the `snapshot` to restore earlier parts of the state.

@@ -52,3 +52,5 @@ import { UseStore } from 'zustand';

/**
* Apply a patch to the current state. This does not effect the undo/redo stack.
* Apply a patch to the current state.
* This does not effect the undo/redo stack.
* This does not persist the state.
* @param patch

@@ -59,16 +61,25 @@ */

* Perform any last changes to the state before updating.
* Override this on the extending class.
* Override this on your extending class.
* @param state
*/
protected cleanup: (state: T, patch: Patch<T>) => T;
protected cleanup: (state: T, prevState: T, patch: Patch<T>) => T;
/**
* Apply a patch to the current state.
* This does not effect the undo/redo stack.
* @param patch
* This does not persist the state.
* @param patch The patch to apply.
*/
protected patchState: (patch: Patch<T>) => StateManager<T>;
/**
* Replace the current state.
* This does not effect the undo/redo stack.
* This does not persist the state.
* @param state The new state.
*/
protected replaceState: (state: T) => StateManager<T>;
/**
* Update the state using a Command.
* This effects the undo/redo stack.
* @param command
* This persists the state.
* @param command The command to apply and add to the undo/redo stack.
*/

@@ -75,0 +86,0 @@ protected setState: (command: Command<T>) => StateManager<T>;

{
"private": false,
"version": "0.5.7",
"version": "0.5.8",
"name": "rko",

@@ -49,5 +49,6 @@ "author": {

"dependencies": {
"idb-keyval": "^5.1.3",
"zustand": "^3.5.9"
},
"gitHead": "5f92683dda615706366963b02389a9fc3164b727"
"gitHead": "161a2ca056b63fb5450942a0aef4e88259031dd1"
}

@@ -162,3 +162,3 @@ ![logo](./rko-logo.svg)

Update the state and push the command to the undo/redo stack. This method accepts a `Command` type object containing two `Patch`es: `before` and `after`. The `after` patch should contain the changes to the state that you wish to make immediately and when the command is "re-done". The `before` patch should contain the changes to make when the command is "undone".
Update the state, push the command to the undo/redo stack, and persist the new state. This method accepts a `Command` type object containing two `Patch`es: `before` and `after`. The `after` patch should contain the changes to the state that you wish to make immediately and when the command is "re-done". The `before` patch should contain the changes to make when the command is "undone".

@@ -177,8 +177,21 @@ ```ts

#### `cleanup(state: T, patch: Patch<T>)`
#### `replaceState(state: T)`
The cleanup method is called on every state change, _after_ applying the current patch. It returns the "final" updated state. You can override this method in order to clean up any state that is no longer needed. For example, if you have a state that is a list of items, you can use the cleanup method to remove items that are no longer in the list. Note that the changes won't be present in the undo/redo stack.
Works like `patchState` but accepts an entire state instead of a patch. This is useful for cases where a deep merge may be too expensive, such as changing items during a drag or scroll interaction. Note that, like `patchState`, this method will not effect the undo/redo stack. You might also want to call `resetHistory`.
Example:
```ts
cleanup = (state: T, patch: Patch<T>) => {
loadNewTodos = (state: State) =>
this.replaceState({
todos,
})
```
#### `cleanup(next: T, prev: T, patch: Patch<T>)`
The cleanup method is called on every state change, _after_ applying the current patch. It receives the next state, the previous state, and the patch that was just applied. It returns the "final" updated state. You can override this method in order to clean up any state that is no longer needed. For example, if you have a state that is a list of items, you can use the cleanup method to remove items that are no longer in the list. Note that the changes won't be present in the undo/redo stack.
```ts
cleanup = (next: State) => {
const final = { ...state }

@@ -198,2 +211,17 @@

```ts
cleanup = (next: State, prev: State, patch: Patch<State>) => {
// Log an ID from the patch?
if (patch.patchId) {
logger.log(patch.patchId)
}
// Create a JSON patch and update the server?
const serverPatch = jsonpatch.compare(prev, state)
server.sendUpdate(clientId, serverPatch)
return next
}
```
### Public API

@@ -227,3 +255,3 @@

### `snapshot`
#### `snapshot`

@@ -230,0 +258,0 @@ The saved snapshot. You can use the `snapshot` to restore earlier parts of the state.

@@ -108,2 +108,9 @@ import { StateManager } from '../index'

}
/**
* Load an entirely new state.
*/
loadTodos = (state: State) => {
return this.replaceState(state)
}
}

@@ -141,2 +148,28 @@

it('Replaces the state', () => {
const todoState = new TodoState(initialState)
todoState.loadTodos({
todos: {
a: {
id: 'a',
text: 'placeholder a',
isComplete: false,
dateCreated: 1629575640560,
},
b: {
id: 'b',
text: 'placeholder b',
isComplete: false,
dateCreated: 1629575640560,
},
},
})
expect(todoState.state.todos.todo0).toBe(undefined)
expect(todoState.state.todos.todo1).toBe(undefined)
expect(todoState.state.todos.a.text).toBe('placeholder a')
expect(todoState.state.todos.b.text).toBe('placeholder b')
// TODO: Confirm that the new state IS NOT persisted
})
it('Does an command', () => {

@@ -147,2 +180,4 @@ const todoState = new TodoState(initialState)

expect(todoState.state.todos.todo0.isComplete).toBe(true)
// TODO: Confirm that the new state IS persisted
})

@@ -184,2 +219,4 @@

expect(todoState.state.todos.todo0.isComplete).toBe(false)
// TODO: Confirm that the new state IS persisted
})

@@ -186,0 +223,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc