v0.1
This commit is contained in:
commit
4aaaf23d2f
2411 files changed
+1248679
No files matched your search
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2019-present Eduardo San Martin Morote
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
<p align="center">
|
||||
<a href="https://pinia.vuejs.org" target="_blank" rel="noopener noreferrer">
|
||||
<img width="180" src="https://pinia.vuejs.org/logo.svg" alt="Pinia logo">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
# Pinia
|
||||
|
||||
> Intuitive, type safe and flexible Store for Vue
|
||||
|
||||
## 👉 [Demo with Vue 3 on StackBlitz](https://stackblitz.com/github/piniajs/example-vue-3-vite)
|
||||
|
||||
## Help me keep working on this project 💚
|
||||
|
||||
- [Become a Sponsor on GitHub](https://github.com/sponsors/posva)
|
||||
- [One-time donation via PayPal](https://paypal.me/posva)
|
||||
|
||||
## Documentation
|
||||
|
||||
To learn more about Pinia, check [its documentation](https://pinia.vuejs.org).
|
||||
|
||||
## License
|
||||
|
||||
[MIT](http://opensource.org/licenses/MIT)
|
||||
+1957
File diff suppressed because it is too large.
Load diff
+1037
File diff suppressed because it is too large.
Load diff
+1932
File diff suppressed because it is too large.
Load diff
+1950
File diff suppressed because it is too large.
Load diff
+7
@@ -0,0 +1,7 @@
|
||||
/*!
|
||||
* pinia v3.0.4
|
||||
* (c) 2025 Eduardo San Martin Morote
|
||||
* @license MIT
|
||||
*/
|
||||
var Pinia=function(t,e){"use strict";let n;const o=t=>n=t,c=Symbol();function i(t){return t&&"object"==typeof t&&"[object Object]"===Object.prototype.toString.call(t)&&"function"!=typeof t.toJSON}var r;t.MutationType=void 0,(r=t.MutationType||(t.MutationType={})).direct="direct",r.patchObject="patch object",r.patchFunction="patch function";const s=()=>{};function a(t,n,o,c=s){t.add(n);const i=()=>{t.delete(n)&&c()};return!o&&e.getCurrentScope()&&e.onScopeDispose(i),i}function u(t,...e){t.forEach((t=>{t(...e)}))}const f=t=>t(),p=Symbol(),l=Symbol();function h(t,n){t instanceof Map&&n instanceof Map?n.forEach(((e,n)=>t.set(n,e))):t instanceof Set&&n instanceof Set&&n.forEach(t.add,t);for(const o in n){if(!n.hasOwnProperty(o))continue;const c=n[o],r=t[o];t[o]=i(r)&&i(c)&&t.hasOwnProperty(o)&&!e.isRef(c)&&!e.isReactive(c)?h(r,c):c}return t}const d=Symbol();function y(t){return!i(t)||!Object.prototype.hasOwnProperty.call(t,d)}const{assign:v}=Object;function b(n,c,i={},r,d,b){let S;const $=v({actions:{}},i),_={deep:!0};let j,m,O,R=new Set,g=new Set;const w=r.state.value[n];let P;function A(o){let c;j=m=!1,"function"==typeof o?(o(r.state.value[n]),c={type:t.MutationType.patchFunction,storeId:n,events:O}):(h(r.state.value[n],o),c={type:t.MutationType.patchObject,payload:o,storeId:n,events:O});const i=P=Symbol();e.nextTick().then((()=>{P===i&&(j=!0)})),m=!0,u(R,c,r.state.value[n])}b||w||(r.state.value[n]={}),e.ref({});const M=b?function(){const{state:t}=i,e=t?t():{};this.$patch((t=>{v(t,e)}))}:s;const k=(t,e="")=>{if(p in t)return t[l]=e,t;const c=function(){o(r);const e=Array.from(arguments),i=new Set,s=new Set;let a;u(g,{args:e,name:c[l],store:E,after:function(t){i.add(t)},onError:function(t){s.add(t)}});try{a=t.apply(this&&this.$id===n?this:E,e)}catch(t){throw u(s,t),t}return a instanceof Promise?a.then((t=>(u(i,t),t))).catch((t=>(u(s,t),Promise.reject(t)))):(u(i,a),a)};return c[p]=!0,c[l]=e,c},T={_p:r,$id:n,$onAction:a.bind(null,g),$patch:A,$reset:M,$subscribe(o,c={}){const i=a(R,o,c.detached,(()=>s())),s=S.run((()=>e.watch((()=>r.state.value[n]),(e=>{("sync"===c.flush?m:j)&&o({storeId:n,type:t.MutationType.direct,events:O},e)}),v({},_,c))));return i},$dispose:function(){S.stop(),R.clear(),g.clear(),r._s.delete(n)}},E=e.reactive(T);r._s.set(n,E);const x=(r._a&&r._a.runWithContext||f)((()=>r._e.run((()=>(S=e.effectScope()).run((()=>c({action:k})))))));for(const t in x){const o=x[t];if(e.isRef(o)&&(!e.isRef(I=o)||!I.effect)||e.isReactive(o))b||(w&&y(o)&&(e.isRef(o)?o.value=w[t]:h(o,w[t])),r.state.value[n][t]=o);else if("function"==typeof o){const e=k(o,t);x[t]=e,$.actions[t]=o}}var I;return v(E,x),v(e.toRaw(E),x),Object.defineProperty(E,"$state",{get:()=>r.state.value[n],set:t=>{A((e=>{v(e,t)}))}}),r._p.forEach((t=>{v(E,S.run((()=>t({store:E,app:r._a,pinia:r,options:$}))))})),w&&b&&i.hydrate&&i.hydrate(E.$state,w),j=!0,m=!0,E}
|
||||
/*! #__NO_SIDE_EFFECTS__ */let S="Store";function $(t,e){return Array.isArray(e)?e.reduce(((e,n)=>(e[n]=function(){return t(this.$pinia)[n]},e)),{}):Object.keys(e).reduce(((n,o)=>(n[o]=function(){const n=t(this.$pinia),c=e[o];return"function"==typeof c?c.call(this,n):n[c]},n)),{})}const _=$;return t.acceptHMRUpdate=function(t,e){return()=>{}},t.createPinia=function(){const t=e.effectScope(!0),n=t.run((()=>e.ref({})));let i=[],r=[];const s=e.markRaw({install(t){o(s),s._a=t,t.provide(c,s),t.config.globalProperties.$pinia=s,r.forEach((t=>i.push(t))),r=[]},use(t){return this._a?i.push(t):r.push(t),this},_p:i,_a:null,_e:t,_s:new Map,state:n});return s},t.defineStore=function(t,i,r){let s;const a="function"==typeof i;function u(r,u){const f=e.hasInjectionContext();(r=r||(f?e.inject(c,null):null))&&o(r),(r=n)._s.has(t)||(a?b(t,i,s,r):function(t,n,c){const{state:i,actions:r,getters:s}=n,a=c.state.value[t];let u;u=b(t,(function(){a||(c.state.value[t]=i?i():{});const n=e.toRefs(c.state.value[t]);return v(n,r,Object.keys(s||{}).reduce(((n,i)=>(n[i]=e.markRaw(e.computed((()=>{o(c);const e=c._s.get(t);return s[i].call(e,e)}))),n)),{}))}),n,c,0,!0)}(t,s,r));return r._s.get(t)}return s=a?r:i,u.$id=t,u},t.disposePinia=function(t){t._e.stop(),t._s.clear(),t._p.splice(0),t.state.value={},t._a=null},t.getActivePinia=()=>e.hasInjectionContext()&&e.inject(c)||n,t.mapActions=function(t,e){return Array.isArray(e)?e.reduce(((e,n)=>(e[n]=function(...e){return t(this.$pinia)[n](...e)},e)),{}):Object.keys(e).reduce(((n,o)=>(n[o]=function(...n){return t(this.$pinia)[e[o]](...n)},n)),{})},t.mapGetters=_,t.mapState=$,t.mapStores=function(...t){return t.reduce(((t,e)=>(t[e.$id+S]=function(){return e(this.$pinia)},t)),{})},t.mapWritableState=function(t,e){return Array.isArray(e)?e.reduce(((e,n)=>(e[n]={get(){return t(this.$pinia)[n]},set(e){return t(this.$pinia)[n]=e}},e)),{}):Object.keys(e).reduce(((n,o)=>(n[o]={get(){return t(this.$pinia)[e[o]]},set(n){return t(this.$pinia)[e[o]]=n}},n)),{})},t.setActivePinia=o,t.setMapStoreSuffix=function(t){S=t},t.shouldHydrate=y,t.skipHydrate=function(t){return Object.defineProperty(t,d,{})},t.storeToRefs=function(t){const n=e.toRaw(t),o={};for(const c in n){const i=n[c];i.effect?o[c]=e.computed({get:()=>t[c],set(e){t[c]=e}}):(e.isRef(i)||e.isReactive(i))&&(o[c]=e.toRef(t,c))}return o},t}({},Vue);
|
||||
+1941
File diff suppressed because it is too large.
Load diff
+719
@@ -0,0 +1,719 @@
|
||||
/*!
|
||||
* pinia v3.0.4
|
||||
* (c) 2025 Eduardo San Martin Morote
|
||||
* @license MIT
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var vue = require('vue');
|
||||
require('@vue/devtools-api');
|
||||
|
||||
/**
|
||||
* setActivePinia must be called to handle SSR at the top of functions like
|
||||
* `fetch`, `setup`, `serverPrefetch` and others
|
||||
*/
|
||||
let activePinia;
|
||||
/**
|
||||
* Sets or unsets the active pinia. Used in SSR and internally when calling
|
||||
* actions and getters
|
||||
*
|
||||
* @param pinia - Pinia instance
|
||||
*/
|
||||
// @ts-expect-error: cannot constrain the type of the return
|
||||
const setActivePinia = (pinia) => (activePinia = pinia);
|
||||
/**
|
||||
* Get the currently active pinia if there is any.
|
||||
*/
|
||||
const getActivePinia = () => (vue.hasInjectionContext() && vue.inject(piniaSymbol)) || activePinia;
|
||||
const piniaSymbol = (/* istanbul ignore next */ Symbol());
|
||||
|
||||
function isPlainObject(
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
o) {
|
||||
return (o &&
|
||||
typeof o === 'object' &&
|
||||
Object.prototype.toString.call(o) === '[object Object]' &&
|
||||
typeof o.toJSON !== 'function');
|
||||
}
|
||||
// type DeepReadonly<T> = { readonly [P in keyof T]: DeepReadonly<T[P]> }
|
||||
// TODO: can we change these to numbers?
|
||||
/**
|
||||
* Possible types for SubscriptionCallback
|
||||
*/
|
||||
exports.MutationType = void 0;
|
||||
(function (MutationType) {
|
||||
/**
|
||||
* Direct mutation of the state:
|
||||
*
|
||||
* - `store.name = 'new name'`
|
||||
* - `store.$state.name = 'new name'`
|
||||
* - `store.list.push('new item')`
|
||||
*/
|
||||
MutationType["direct"] = "direct";
|
||||
/**
|
||||
* Mutated the state with `$patch` and an object
|
||||
*
|
||||
* - `store.$patch({ name: 'newName' })`
|
||||
*/
|
||||
MutationType["patchObject"] = "patch object";
|
||||
/**
|
||||
* Mutated the state with `$patch` and a function
|
||||
*
|
||||
* - `store.$patch(state => state.name = 'newName')`
|
||||
*/
|
||||
MutationType["patchFunction"] = "patch function";
|
||||
// maybe reset? for $state = {} and $reset
|
||||
})(exports.MutationType || (exports.MutationType = {}));
|
||||
|
||||
/**
|
||||
* Creates a Pinia instance to be used by the application
|
||||
*/
|
||||
function createPinia() {
|
||||
const scope = vue.effectScope(true);
|
||||
// NOTE: here we could check the window object for a state and directly set it
|
||||
// if there is anything like it with Vue 3 SSR
|
||||
const state = scope.run(() => vue.ref({}));
|
||||
let _p = [];
|
||||
// plugins added before calling app.use(pinia)
|
||||
let toBeInstalled = [];
|
||||
const pinia = vue.markRaw({
|
||||
install(app) {
|
||||
// this allows calling useStore() outside of a component setup after
|
||||
// installing pinia's plugin
|
||||
setActivePinia(pinia);
|
||||
pinia._a = app;
|
||||
app.provide(piniaSymbol, pinia);
|
||||
app.config.globalProperties.$pinia = pinia;
|
||||
toBeInstalled.forEach((plugin) => _p.push(plugin));
|
||||
toBeInstalled = [];
|
||||
},
|
||||
use(plugin) {
|
||||
if (!this._a) {
|
||||
toBeInstalled.push(plugin);
|
||||
}
|
||||
else {
|
||||
_p.push(plugin);
|
||||
}
|
||||
return this;
|
||||
},
|
||||
_p,
|
||||
// it's actually undefined here
|
||||
// @ts-expect-error
|
||||
_a: null,
|
||||
_e: scope,
|
||||
_s: new Map(),
|
||||
state,
|
||||
});
|
||||
return pinia;
|
||||
}
|
||||
/**
|
||||
* Dispose a Pinia instance by stopping its effectScope and removing the state, plugins and stores. This is mostly
|
||||
* useful in tests, with both a testing pinia or a regular pinia and in applications that use multiple pinia instances.
|
||||
* Once disposed, the pinia instance cannot be used anymore.
|
||||
*
|
||||
* @param pinia - pinia instance
|
||||
*/
|
||||
function disposePinia(pinia) {
|
||||
pinia._e.stop();
|
||||
pinia._s.clear();
|
||||
pinia._p.splice(0);
|
||||
pinia.state.value = {};
|
||||
// @ts-expect-error: non valid
|
||||
pinia._a = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an _accept_ function to pass to `import.meta.hot` in Vite applications.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
* const useUser = defineStore(...)
|
||||
* if (import.meta.hot) {
|
||||
* import.meta.hot.accept(acceptHMRUpdate(useUser, import.meta.hot))
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @param initialUseStore - return of the defineStore to hot update
|
||||
* @param hot - `import.meta.hot`
|
||||
*/
|
||||
function acceptHMRUpdate(initialUseStore, hot) {
|
||||
// strip as much as possible from iife.prod
|
||||
{
|
||||
return () => { };
|
||||
}
|
||||
}
|
||||
|
||||
const noop = () => { };
|
||||
function addSubscription(subscriptions, callback, detached, onCleanup = noop) {
|
||||
subscriptions.add(callback);
|
||||
const removeSubscription = () => {
|
||||
const isDel = subscriptions.delete(callback);
|
||||
isDel && onCleanup();
|
||||
};
|
||||
if (!detached && vue.getCurrentScope()) {
|
||||
vue.onScopeDispose(removeSubscription);
|
||||
}
|
||||
return removeSubscription;
|
||||
}
|
||||
function triggerSubscriptions(subscriptions, ...args) {
|
||||
subscriptions.forEach((callback) => {
|
||||
callback(...args);
|
||||
});
|
||||
}
|
||||
|
||||
const fallbackRunWithContext = (fn) => fn();
|
||||
/**
|
||||
* Marks a function as an action for `$onAction`
|
||||
* @internal
|
||||
*/
|
||||
const ACTION_MARKER = Symbol();
|
||||
/**
|
||||
* Action name symbol. Allows to add a name to an action after defining it
|
||||
* @internal
|
||||
*/
|
||||
const ACTION_NAME = Symbol();
|
||||
function mergeReactiveObjects(target, patchToApply) {
|
||||
// Handle Map instances
|
||||
if (target instanceof Map && patchToApply instanceof Map) {
|
||||
patchToApply.forEach((value, key) => target.set(key, value));
|
||||
}
|
||||
else if (target instanceof Set && patchToApply instanceof Set) {
|
||||
// Handle Set instances
|
||||
patchToApply.forEach(target.add, target);
|
||||
}
|
||||
// no need to go through symbols because they cannot be serialized anyway
|
||||
for (const key in patchToApply) {
|
||||
if (!patchToApply.hasOwnProperty(key))
|
||||
continue;
|
||||
const subPatch = patchToApply[key];
|
||||
const targetValue = target[key];
|
||||
if (isPlainObject(targetValue) &&
|
||||
isPlainObject(subPatch) &&
|
||||
target.hasOwnProperty(key) &&
|
||||
!vue.isRef(subPatch) &&
|
||||
!vue.isReactive(subPatch)) {
|
||||
// NOTE: here I wanted to warn about inconsistent types but it's not possible because in setup stores one might
|
||||
// start the value of a property as a certain type e.g. a Map, and then for some reason, during SSR, change that
|
||||
// to `undefined`. When trying to hydrate, we want to override the Map with `undefined`.
|
||||
target[key] = mergeReactiveObjects(targetValue, subPatch);
|
||||
}
|
||||
else {
|
||||
// @ts-expect-error: subPatch is a valid value
|
||||
target[key] = subPatch;
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
const skipHydrateSymbol = /* istanbul ignore next */ Symbol();
|
||||
/**
|
||||
* Tells Pinia to skip the hydration process of a given object. This is useful in setup stores (only) when you return a
|
||||
* stateful object in the store but it isn't really state. e.g. returning a router instance in a setup store.
|
||||
*
|
||||
* @param obj - target object
|
||||
* @returns obj
|
||||
*/
|
||||
function skipHydrate(obj) {
|
||||
return Object.defineProperty(obj, skipHydrateSymbol, {});
|
||||
}
|
||||
/**
|
||||
* Returns whether a value should be hydrated
|
||||
*
|
||||
* @param obj - target variable
|
||||
* @returns true if `obj` should be hydrated
|
||||
*/
|
||||
function shouldHydrate(obj) {
|
||||
return (!isPlainObject(obj) ||
|
||||
!Object.prototype.hasOwnProperty.call(obj, skipHydrateSymbol));
|
||||
}
|
||||
const { assign } = Object;
|
||||
function isComputed(o) {
|
||||
return !!(vue.isRef(o) && o.effect);
|
||||
}
|
||||
function createOptionsStore(id, options, pinia, hot) {
|
||||
const { state, actions, getters } = options;
|
||||
const initialState = pinia.state.value[id];
|
||||
let store;
|
||||
function setup() {
|
||||
if (!initialState && (true)) {
|
||||
/* istanbul ignore if */
|
||||
pinia.state.value[id] = state ? state() : {};
|
||||
}
|
||||
// avoid creating a state in pinia.state.value
|
||||
const localState = vue.toRefs(pinia.state.value[id]);
|
||||
return assign(localState, actions, Object.keys(getters || {}).reduce((computedGetters, name) => {
|
||||
computedGetters[name] = vue.markRaw(vue.computed(() => {
|
||||
setActivePinia(pinia);
|
||||
// it was created just before
|
||||
const store = pinia._s.get(id);
|
||||
// allow cross using stores
|
||||
// @ts-expect-error
|
||||
// return getters![name].call(context, context)
|
||||
// TODO: avoid reading the getter while assigning with a global variable
|
||||
return getters[name].call(store, store);
|
||||
}));
|
||||
return computedGetters;
|
||||
}, {}));
|
||||
}
|
||||
store = createSetupStore(id, setup, options, pinia, hot, true);
|
||||
return store;
|
||||
}
|
||||
function createSetupStore($id, setup, options = {}, pinia, hot, isOptionsStore) {
|
||||
let scope;
|
||||
const optionsForPlugin = assign({ actions: {} }, options);
|
||||
// watcher options for $subscribe
|
||||
const $subscribeOptions = { deep: true };
|
||||
// internal state
|
||||
let isListening; // set to true at the end
|
||||
let isSyncListening; // set to true at the end
|
||||
let subscriptions = new Set();
|
||||
let actionSubscriptions = new Set();
|
||||
let debuggerEvents;
|
||||
const initialState = pinia.state.value[$id];
|
||||
// avoid setting the state for option stores if it is set
|
||||
// by the setup
|
||||
if (!isOptionsStore && !initialState && (true)) {
|
||||
/* istanbul ignore if */
|
||||
pinia.state.value[$id] = {};
|
||||
}
|
||||
vue.ref({});
|
||||
// avoid triggering too many listeners
|
||||
// https://github.com/vuejs/pinia/issues/1129
|
||||
let activeListener;
|
||||
function $patch(partialStateOrMutator) {
|
||||
let subscriptionMutation;
|
||||
isListening = isSyncListening = false;
|
||||
if (typeof partialStateOrMutator === 'function') {
|
||||
partialStateOrMutator(pinia.state.value[$id]);
|
||||
subscriptionMutation = {
|
||||
type: exports.MutationType.patchFunction,
|
||||
storeId: $id,
|
||||
events: debuggerEvents,
|
||||
};
|
||||
}
|
||||
else {
|
||||
mergeReactiveObjects(pinia.state.value[$id], partialStateOrMutator);
|
||||
subscriptionMutation = {
|
||||
type: exports.MutationType.patchObject,
|
||||
payload: partialStateOrMutator,
|
||||
storeId: $id,
|
||||
events: debuggerEvents,
|
||||
};
|
||||
}
|
||||
const myListenerId = (activeListener = Symbol());
|
||||
vue.nextTick().then(() => {
|
||||
if (activeListener === myListenerId) {
|
||||
isListening = true;
|
||||
}
|
||||
});
|
||||
isSyncListening = true;
|
||||
// because we paused the watcher, we need to manually call the subscriptions
|
||||
triggerSubscriptions(subscriptions, subscriptionMutation, pinia.state.value[$id]);
|
||||
}
|
||||
const $reset = isOptionsStore
|
||||
? function $reset() {
|
||||
const { state } = options;
|
||||
const newState = state ? state() : {};
|
||||
// we use a patch to group all changes into one single subscription
|
||||
this.$patch(($state) => {
|
||||
// @ts-expect-error: FIXME: shouldn't error?
|
||||
assign($state, newState);
|
||||
});
|
||||
}
|
||||
: /* istanbul ignore next */
|
||||
noop;
|
||||
function $dispose() {
|
||||
scope.stop();
|
||||
subscriptions.clear();
|
||||
actionSubscriptions.clear();
|
||||
pinia._s.delete($id);
|
||||
}
|
||||
/**
|
||||
* Helper that wraps function so it can be tracked with $onAction
|
||||
* @param fn - action to wrap
|
||||
* @param name - name of the action
|
||||
*/
|
||||
const action = (fn, name = '') => {
|
||||
if (ACTION_MARKER in fn) {
|
||||
fn[ACTION_NAME] = name;
|
||||
return fn;
|
||||
}
|
||||
const wrappedAction = function () {
|
||||
setActivePinia(pinia);
|
||||
const args = Array.from(arguments);
|
||||
const afterCallbackSet = new Set();
|
||||
const onErrorCallbackSet = new Set();
|
||||
function after(callback) {
|
||||
afterCallbackSet.add(callback);
|
||||
}
|
||||
function onError(callback) {
|
||||
onErrorCallbackSet.add(callback);
|
||||
}
|
||||
// @ts-expect-error
|
||||
triggerSubscriptions(actionSubscriptions, {
|
||||
args,
|
||||
name: wrappedAction[ACTION_NAME],
|
||||
store,
|
||||
after,
|
||||
onError,
|
||||
});
|
||||
let ret;
|
||||
try {
|
||||
ret = fn.apply(this && this.$id === $id ? this : store, args);
|
||||
// handle sync errors
|
||||
}
|
||||
catch (error) {
|
||||
triggerSubscriptions(onErrorCallbackSet, error);
|
||||
throw error;
|
||||
}
|
||||
if (ret instanceof Promise) {
|
||||
return ret
|
||||
.then((value) => {
|
||||
triggerSubscriptions(afterCallbackSet, value);
|
||||
return value;
|
||||
})
|
||||
.catch((error) => {
|
||||
triggerSubscriptions(onErrorCallbackSet, error);
|
||||
return Promise.reject(error);
|
||||
});
|
||||
}
|
||||
// trigger after callbacks
|
||||
triggerSubscriptions(afterCallbackSet, ret);
|
||||
return ret;
|
||||
};
|
||||
wrappedAction[ACTION_MARKER] = true;
|
||||
wrappedAction[ACTION_NAME] = name; // will be set later
|
||||
// @ts-expect-error: we are intentionally limiting the returned type to just Fn
|
||||
// because all the added properties are internals that are exposed through `$onAction()` only
|
||||
return wrappedAction;
|
||||
};
|
||||
const partialStore = {
|
||||
_p: pinia,
|
||||
// _s: scope,
|
||||
$id,
|
||||
$onAction: addSubscription.bind(null, actionSubscriptions),
|
||||
$patch,
|
||||
$reset,
|
||||
$subscribe(callback, options = {}) {
|
||||
const removeSubscription = addSubscription(subscriptions, callback, options.detached, () => stopWatcher());
|
||||
const stopWatcher = scope.run(() => vue.watch(() => pinia.state.value[$id], (state) => {
|
||||
if (options.flush === 'sync' ? isSyncListening : isListening) {
|
||||
callback({
|
||||
storeId: $id,
|
||||
type: exports.MutationType.direct,
|
||||
events: debuggerEvents,
|
||||
}, state);
|
||||
}
|
||||
}, assign({}, $subscribeOptions, options)));
|
||||
return removeSubscription;
|
||||
},
|
||||
$dispose,
|
||||
};
|
||||
const store = vue.reactive(partialStore);
|
||||
// store the partial store now so the setup of stores can instantiate each other before they are finished without
|
||||
// creating infinite loops.
|
||||
pinia._s.set($id, store);
|
||||
const runWithContext = (pinia._a && pinia._a.runWithContext) || fallbackRunWithContext;
|
||||
// TODO: idea create skipSerialize that marks properties as non serializable and they are skipped
|
||||
const setupStore = runWithContext(() => pinia._e.run(() => (scope = vue.effectScope()).run(() => setup({ action }))));
|
||||
// overwrite existing actions to support $onAction
|
||||
for (const key in setupStore) {
|
||||
const prop = setupStore[key];
|
||||
if ((vue.isRef(prop) && !isComputed(prop)) || vue.isReactive(prop)) {
|
||||
// mark it as a piece of state to be serialized
|
||||
if (!isOptionsStore) {
|
||||
// in setup stores we must hydrate the state and sync pinia state tree with the refs the user just created
|
||||
if (initialState && shouldHydrate(prop)) {
|
||||
if (vue.isRef(prop)) {
|
||||
prop.value = initialState[key];
|
||||
}
|
||||
else {
|
||||
// probably a reactive object, lets recursively assign
|
||||
// @ts-expect-error: prop is unknown
|
||||
mergeReactiveObjects(prop, initialState[key]);
|
||||
}
|
||||
}
|
||||
// transfer the ref to the pinia state to keep everything in sync
|
||||
pinia.state.value[$id][key] = prop;
|
||||
}
|
||||
// action
|
||||
}
|
||||
else if (typeof prop === 'function') {
|
||||
const actionValue = action(prop, key);
|
||||
// this a hot module replacement store because the hotUpdate method needs
|
||||
// to do it with the right context
|
||||
// @ts-expect-error
|
||||
setupStore[key] = actionValue;
|
||||
// list actions so they can be used in plugins
|
||||
// @ts-expect-error
|
||||
optionsForPlugin.actions[key] = prop;
|
||||
}
|
||||
else ;
|
||||
}
|
||||
// add the state, getters, and action properties
|
||||
/* istanbul ignore if */
|
||||
assign(store, setupStore);
|
||||
// allows retrieving reactive objects with `storeToRefs()`. Must be called after assigning to the reactive object.
|
||||
// Make `storeToRefs()` work with `reactive()` #799
|
||||
assign(vue.toRaw(store), setupStore);
|
||||
// use this instead of a computed with setter to be able to create it anywhere
|
||||
// without linking the computed lifespan to wherever the store is first
|
||||
// created.
|
||||
Object.defineProperty(store, '$state', {
|
||||
get: () => (pinia.state.value[$id]),
|
||||
set: (state) => {
|
||||
$patch(($state) => {
|
||||
// @ts-expect-error: FIXME: shouldn't error?
|
||||
assign($state, state);
|
||||
});
|
||||
},
|
||||
});
|
||||
// apply all plugins
|
||||
pinia._p.forEach((extender) => {
|
||||
/* istanbul ignore else */
|
||||
{
|
||||
assign(store, scope.run(() => extender({
|
||||
store: store,
|
||||
app: pinia._a,
|
||||
pinia,
|
||||
options: optionsForPlugin,
|
||||
})));
|
||||
}
|
||||
});
|
||||
// only apply hydrate to option stores with an initial state in pinia
|
||||
if (initialState &&
|
||||
isOptionsStore &&
|
||||
options.hydrate) {
|
||||
options.hydrate(store.$state, initialState);
|
||||
}
|
||||
isListening = true;
|
||||
isSyncListening = true;
|
||||
return store;
|
||||
}
|
||||
// allows unused stores to be tree shaken
|
||||
/*! #__NO_SIDE_EFFECTS__ */
|
||||
function defineStore(
|
||||
// TODO: add proper types from above
|
||||
id, setup, setupOptions) {
|
||||
let options;
|
||||
const isSetupStore = typeof setup === 'function';
|
||||
// the option store setup will contain the actual options in this case
|
||||
options = isSetupStore ? setupOptions : setup;
|
||||
function useStore(pinia, hot) {
|
||||
const hasContext = vue.hasInjectionContext();
|
||||
pinia =
|
||||
// in test mode, ignore the argument provided as we can always retrieve a
|
||||
// pinia instance with getActivePinia()
|
||||
((process.env.NODE_ENV === 'test') && activePinia && activePinia._testing ? null : pinia) ||
|
||||
(hasContext ? vue.inject(piniaSymbol, null) : null);
|
||||
if (pinia)
|
||||
setActivePinia(pinia);
|
||||
pinia = activePinia;
|
||||
if (!pinia._s.has(id)) {
|
||||
// creating the store registers it in `pinia._s`
|
||||
if (isSetupStore) {
|
||||
createSetupStore(id, setup, options, pinia);
|
||||
}
|
||||
else {
|
||||
createOptionsStore(id, options, pinia);
|
||||
}
|
||||
}
|
||||
const store = pinia._s.get(id);
|
||||
// StoreGeneric cannot be casted towards Store
|
||||
return store;
|
||||
}
|
||||
useStore.$id = id;
|
||||
return useStore;
|
||||
}
|
||||
|
||||
let mapStoreSuffix = 'Store';
|
||||
/**
|
||||
* Changes the suffix added by `mapStores()`. Can be set to an empty string.
|
||||
* Defaults to `"Store"`. Make sure to extend the MapStoresCustomization
|
||||
* interface if you are using TypeScript.
|
||||
*
|
||||
* @param suffix - new suffix
|
||||
*/
|
||||
function setMapStoreSuffix(suffix // could be 'Store' but that would be annoying for JS
|
||||
) {
|
||||
mapStoreSuffix = suffix;
|
||||
}
|
||||
/**
|
||||
* Allows using stores without the composition API (`setup()`) by generating an
|
||||
* object to be spread in the `computed` field of a component. It accepts a list
|
||||
* of store definitions.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
* export default {
|
||||
* computed: {
|
||||
* // other computed properties
|
||||
* ...mapStores(useUserStore, useCartStore)
|
||||
* },
|
||||
*
|
||||
* created() {
|
||||
* this.userStore // store with id "user"
|
||||
* this.cartStore // store with id "cart"
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @param stores - list of stores to map to an object
|
||||
*/
|
||||
function mapStores(...stores) {
|
||||
return stores.reduce((reduced, useStore) => {
|
||||
// @ts-expect-error: $id is added by defineStore
|
||||
reduced[useStore.$id + mapStoreSuffix] = function () {
|
||||
return useStore(this.$pinia);
|
||||
};
|
||||
return reduced;
|
||||
}, {});
|
||||
}
|
||||
/**
|
||||
* Allows using state and getters from one store without using the composition
|
||||
* API (`setup()`) by generating an object to be spread in the `computed` field
|
||||
* of a component.
|
||||
*
|
||||
* @param useStore - store to map from
|
||||
* @param keysOrMapper - array or object
|
||||
*/
|
||||
function mapState(useStore, keysOrMapper) {
|
||||
return Array.isArray(keysOrMapper)
|
||||
? keysOrMapper.reduce((reduced, key) => {
|
||||
reduced[key] = function () {
|
||||
// @ts-expect-error: FIXME: should work?
|
||||
return useStore(this.$pinia)[key];
|
||||
};
|
||||
return reduced;
|
||||
}, {})
|
||||
: Object.keys(keysOrMapper).reduce((reduced, key) => {
|
||||
// @ts-expect-error
|
||||
reduced[key] = function () {
|
||||
const store = useStore(this.$pinia);
|
||||
const storeKey = keysOrMapper[key];
|
||||
// for some reason TS is unable to infer the type of storeKey to be a
|
||||
// function
|
||||
return typeof storeKey === 'function'
|
||||
? storeKey.call(this, store)
|
||||
: // @ts-expect-error: FIXME: should work?
|
||||
store[storeKey];
|
||||
};
|
||||
return reduced;
|
||||
}, {});
|
||||
}
|
||||
/**
|
||||
* Alias for `mapState()`. You should use `mapState()` instead.
|
||||
* @deprecated use `mapState()` instead.
|
||||
*/
|
||||
const mapGetters = mapState;
|
||||
/**
|
||||
* Allows directly using actions from your store without using the composition
|
||||
* API (`setup()`) by generating an object to be spread in the `methods` field
|
||||
* of a component.
|
||||
*
|
||||
* @param useStore - store to map from
|
||||
* @param keysOrMapper - array or object
|
||||
*/
|
||||
function mapActions(useStore, keysOrMapper) {
|
||||
return Array.isArray(keysOrMapper)
|
||||
? keysOrMapper.reduce((reduced, key) => {
|
||||
// @ts-expect-error
|
||||
reduced[key] = function (...args) {
|
||||
// @ts-expect-error: FIXME: should work?
|
||||
return useStore(this.$pinia)[key](...args);
|
||||
};
|
||||
return reduced;
|
||||
}, {})
|
||||
: Object.keys(keysOrMapper).reduce((reduced, key) => {
|
||||
// @ts-expect-error
|
||||
reduced[key] = function (...args) {
|
||||
// @ts-expect-error: FIXME: should work?
|
||||
return useStore(this.$pinia)[keysOrMapper[key]](...args);
|
||||
};
|
||||
return reduced;
|
||||
}, {});
|
||||
}
|
||||
/**
|
||||
* Allows using state and getters from one store without using the composition
|
||||
* API (`setup()`) by generating an object to be spread in the `computed` field
|
||||
* of a component.
|
||||
*
|
||||
* @param useStore - store to map from
|
||||
* @param keysOrMapper - array or object
|
||||
*/
|
||||
function mapWritableState(useStore, keysOrMapper) {
|
||||
return Array.isArray(keysOrMapper)
|
||||
? keysOrMapper.reduce((reduced, key) => {
|
||||
reduced[key] = {
|
||||
get() {
|
||||
return useStore(this.$pinia)[key];
|
||||
},
|
||||
set(value) {
|
||||
return (useStore(this.$pinia)[key] = value);
|
||||
},
|
||||
};
|
||||
return reduced;
|
||||
}, {})
|
||||
: Object.keys(keysOrMapper).reduce((reduced, key) => {
|
||||
reduced[key] = {
|
||||
get() {
|
||||
return useStore(this.$pinia)[keysOrMapper[key]];
|
||||
},
|
||||
set(value) {
|
||||
return (useStore(this.$pinia)[keysOrMapper[key]] = value);
|
||||
},
|
||||
};
|
||||
return reduced;
|
||||
}, {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an object of references with all the state, getters, and plugin-added
|
||||
* state properties of the store. Similar to `toRefs()` but specifically
|
||||
* designed for Pinia stores so methods and non reactive properties are
|
||||
* completely ignored.
|
||||
*
|
||||
* @param store - store to extract the refs from
|
||||
*/
|
||||
function storeToRefs(store) {
|
||||
const rawStore = vue.toRaw(store);
|
||||
const refs = {};
|
||||
for (const key in rawStore) {
|
||||
const value = rawStore[key];
|
||||
// There is no native method to check for a computed
|
||||
// https://github.com/vuejs/core/pull/4165
|
||||
if (value.effect) {
|
||||
// @ts-expect-error: too hard to type correctly
|
||||
refs[key] =
|
||||
// ...
|
||||
vue.computed({
|
||||
get: () => store[key],
|
||||
set(value) {
|
||||
store[key] = value;
|
||||
},
|
||||
});
|
||||
}
|
||||
else if (vue.isRef(value) || vue.isReactive(value)) {
|
||||
// @ts-expect-error: the key is state or getter
|
||||
refs[key] =
|
||||
// ---
|
||||
vue.toRef(store, key);
|
||||
}
|
||||
}
|
||||
return refs;
|
||||
}
|
||||
|
||||
exports.acceptHMRUpdate = acceptHMRUpdate;
|
||||
exports.createPinia = createPinia;
|
||||
exports.defineStore = defineStore;
|
||||
exports.disposePinia = disposePinia;
|
||||
exports.getActivePinia = getActivePinia;
|
||||
exports.mapActions = mapActions;
|
||||
exports.mapGetters = mapGetters;
|
||||
exports.mapState = mapState;
|
||||
exports.mapStores = mapStores;
|
||||
exports.mapWritableState = mapWritableState;
|
||||
exports.setActivePinia = setActivePinia;
|
||||
exports.setMapStoreSuffix = setMapStoreSuffix;
|
||||
exports.shouldHydrate = shouldHydrate;
|
||||
exports.skipHydrate = skipHydrate;
|
||||
exports.storeToRefs = storeToRefs;
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
module.exports = require('./dist/pinia.prod.cjs')
|
||||
} else {
|
||||
module.exports = require('./dist/pinia.cjs')
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 webfansplz
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
# @vue/devtools-api
|
||||
|
||||
> Plugins API for easier DevTools integrations.
|
||||
|
||||
## Getting Started
|
||||
|
||||
Please follow the documentation at [devtools.vuejs.org](https://devtools.vuejs.org/plugins/api).
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
|
||||
// src/index.ts
|
||||
var index_exports = {};
|
||||
__export(index_exports, {
|
||||
addCustomCommand: () => import_devtools_kit.addCustomCommand,
|
||||
addCustomTab: () => import_devtools_kit.addCustomTab,
|
||||
onDevToolsClientConnected: () => import_devtools_kit.onDevToolsClientConnected,
|
||||
onDevToolsConnected: () => import_devtools_kit.onDevToolsConnected,
|
||||
removeCustomCommand: () => import_devtools_kit.removeCustomCommand,
|
||||
setupDevToolsPlugin: () => import_devtools_kit.setupDevToolsPlugin,
|
||||
setupDevtoolsPlugin: () => import_devtools_kit.setupDevToolsPlugin
|
||||
});
|
||||
module.exports = __toCommonJS(index_exports);
|
||||
var import_devtools_kit = require("@vue/devtools-kit");
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
addCustomCommand,
|
||||
addCustomTab,
|
||||
onDevToolsClientConnected,
|
||||
onDevToolsConnected,
|
||||
removeCustomCommand,
|
||||
setupDevToolsPlugin,
|
||||
setupDevtoolsPlugin
|
||||
});
|
||||
+1
@@ -0,0 +1 @@
|
||||
export { CustomCommand, CustomTab, addCustomCommand, addCustomTab, onDevToolsClientConnected, onDevToolsConnected, removeCustomCommand, setupDevToolsPlugin, setupDevToolsPlugin as setupDevtoolsPlugin } from '@vue/devtools-kit';
|
||||
+1
@@ -0,0 +1 @@
|
||||
export { CustomCommand, CustomTab, addCustomCommand, addCustomTab, onDevToolsClientConnected, onDevToolsConnected, removeCustomCommand, setupDevToolsPlugin, setupDevToolsPlugin as setupDevtoolsPlugin } from '@vue/devtools-kit';
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// src/index.ts
|
||||
import {
|
||||
addCustomCommand,
|
||||
addCustomTab,
|
||||
onDevToolsClientConnected,
|
||||
onDevToolsConnected,
|
||||
removeCustomCommand,
|
||||
setupDevToolsPlugin,
|
||||
setupDevToolsPlugin as setupDevToolsPlugin2
|
||||
} from "@vue/devtools-kit";
|
||||
export {
|
||||
addCustomCommand,
|
||||
addCustomTab,
|
||||
onDevToolsClientConnected,
|
||||
onDevToolsConnected,
|
||||
removeCustomCommand,
|
||||
setupDevToolsPlugin,
|
||||
setupDevToolsPlugin2 as setupDevtoolsPlugin
|
||||
};
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "@vue/devtools-api",
|
||||
"type": "module",
|
||||
"version": "7.7.9",
|
||||
"author": "webfansplz",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"directory": "packages/devtools-api",
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/vuejs/devtools.git"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/index.js",
|
||||
"require": "./dist/index.cjs"
|
||||
}
|
||||
},
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"dependencies": {
|
||||
"@vue/devtools-kit": "^7.7.9"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsup --clean",
|
||||
"prepare:type": "tsup --dts-only",
|
||||
"stub": "tsup --watch --onSuccess 'tsup --dts-only'"
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 webfansplz
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
# @vue/devtools-kit
|
||||
|
||||
> Utility kit for DevTools.
|
||||
+6850
File diff suppressed because it is too large.
Load diff
+1121
File diff suppressed because it is too large.
Load diff
+1121
File diff suppressed because it is too large.
Load diff
+6757
File diff suppressed because it is too large.
Load diff
+20
@@ -0,0 +1,20 @@
|
||||
import type { DevToolsHook, RouterInfo } from './src/types'
|
||||
|
||||
/* eslint-disable vars-on-top, no-var */
|
||||
declare global {
|
||||
var __VUE_DEVTOOLS_GLOBAL_HOOK__: DevToolsHook
|
||||
var __VUE_DEVTOOLS_NEXT_APP_RECORD_INFO__: {
|
||||
id: number
|
||||
appIds: Set<string>
|
||||
}
|
||||
var __VUE_DEVTOOLS_ROUTER_INFO__: RouterInfo
|
||||
var __VUE_DEVTOOLS_ENV__: {
|
||||
vitePluginDetected: boolean
|
||||
}
|
||||
var __VUE_DEVTOOLS_COMPONENT_INSPECTOR_ENABLED__: boolean
|
||||
var __VUE_DEVTOOLS_VITE_PLUGIN_DETECTED__: boolean
|
||||
var __VUE_DEVTOOLS_VITE_PLUGIN_CLIENT_URL__: string
|
||||
var __VUE_DEVTOOLS_BROWSER_EXTENSION_DETECTED__: boolean
|
||||
}
|
||||
|
||||
export { }
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "@vue/devtools-kit",
|
||||
"type": "module",
|
||||
"version": "7.7.9",
|
||||
"author": "webfansplz",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"directory": "packages/devtools-kit",
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/vuejs/devtools.git"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/index.js",
|
||||
"require": "./dist/index.cjs"
|
||||
}
|
||||
},
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
"types": "./types.d.ts",
|
||||
"files": [
|
||||
"**.d.ts",
|
||||
"dist"
|
||||
],
|
||||
"dependencies": {
|
||||
"birpc": "^2.3.0",
|
||||
"hookable": "^5.5.3",
|
||||
"mitt": "^3.0.1",
|
||||
"perfect-debounce": "^1.0.0",
|
||||
"speakingurl": "^14.0.1",
|
||||
"superjson": "^2.2.2",
|
||||
"@vue/devtools-shared": "^7.7.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/speakingurl": "^13.0.6",
|
||||
"vue": "^3.5.13",
|
||||
"vue-router": "^4.5.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsup --clean",
|
||||
"prepare:type": "tsup --dts-only",
|
||||
"stub": "tsup --watch --onSuccess 'tsup --dts-only'"
|
||||
}
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
/// <reference path="./global.d.ts" />
|
||||
export * from './dist/index'
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 webfansplz
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
# @vue/devtools-shared
|
||||
|
||||
> Internal utility types shared across @vue/devtools packages.
|
||||
+378
@@ -0,0 +1,378 @@
|
||||
"use strict";
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __esm = (fn, res) => function __init() {
|
||||
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
||||
};
|
||||
var __commonJS = (cb, mod) => function __require() {
|
||||
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
||||
};
|
||||
var __export = (target2, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target2, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target2) => (target2 = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||
// If the importer is in node compatibility mode or this is not an ESM
|
||||
// file that has been converted to a CommonJS file using a Babel-
|
||||
// compatible transform (i.e. "__esModule" has not been set), then set
|
||||
// "default" to the CommonJS "module.exports" for node compatibility.
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target2, "default", { value: mod, enumerable: true }) : target2,
|
||||
mod
|
||||
));
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
|
||||
// ../../node_modules/.pnpm/tsup@8.4.0_@microsoft+api-extractor@7.51.1_@types+node@22.13.14__jiti@2.4.2_postcss@8.5_96eb05a9d65343021e53791dd83f3773/node_modules/tsup/assets/cjs_shims.js
|
||||
var init_cjs_shims = __esm({
|
||||
"../../node_modules/.pnpm/tsup@8.4.0_@microsoft+api-extractor@7.51.1_@types+node@22.13.14__jiti@2.4.2_postcss@8.5_96eb05a9d65343021e53791dd83f3773/node_modules/tsup/assets/cjs_shims.js"() {
|
||||
"use strict";
|
||||
}
|
||||
});
|
||||
|
||||
// ../../node_modules/.pnpm/rfdc@1.4.1/node_modules/rfdc/index.js
|
||||
var require_rfdc = __commonJS({
|
||||
"../../node_modules/.pnpm/rfdc@1.4.1/node_modules/rfdc/index.js"(exports2, module2) {
|
||||
"use strict";
|
||||
init_cjs_shims();
|
||||
module2.exports = rfdc2;
|
||||
function copyBuffer(cur) {
|
||||
if (cur instanceof Buffer) {
|
||||
return Buffer.from(cur);
|
||||
}
|
||||
return new cur.constructor(cur.buffer.slice(), cur.byteOffset, cur.length);
|
||||
}
|
||||
function rfdc2(opts) {
|
||||
opts = opts || {};
|
||||
if (opts.circles) return rfdcCircles(opts);
|
||||
const constructorHandlers = /* @__PURE__ */ new Map();
|
||||
constructorHandlers.set(Date, (o) => new Date(o));
|
||||
constructorHandlers.set(Map, (o, fn) => new Map(cloneArray(Array.from(o), fn)));
|
||||
constructorHandlers.set(Set, (o, fn) => new Set(cloneArray(Array.from(o), fn)));
|
||||
if (opts.constructorHandlers) {
|
||||
for (const handler2 of opts.constructorHandlers) {
|
||||
constructorHandlers.set(handler2[0], handler2[1]);
|
||||
}
|
||||
}
|
||||
let handler = null;
|
||||
return opts.proto ? cloneProto : clone;
|
||||
function cloneArray(a, fn) {
|
||||
const keys = Object.keys(a);
|
||||
const a2 = new Array(keys.length);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const k = keys[i];
|
||||
const cur = a[k];
|
||||
if (typeof cur !== "object" || cur === null) {
|
||||
a2[k] = cur;
|
||||
} else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) {
|
||||
a2[k] = handler(cur, fn);
|
||||
} else if (ArrayBuffer.isView(cur)) {
|
||||
a2[k] = copyBuffer(cur);
|
||||
} else {
|
||||
a2[k] = fn(cur);
|
||||
}
|
||||
}
|
||||
return a2;
|
||||
}
|
||||
function clone(o) {
|
||||
if (typeof o !== "object" || o === null) return o;
|
||||
if (Array.isArray(o)) return cloneArray(o, clone);
|
||||
if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) {
|
||||
return handler(o, clone);
|
||||
}
|
||||
const o2 = {};
|
||||
for (const k in o) {
|
||||
if (Object.hasOwnProperty.call(o, k) === false) continue;
|
||||
const cur = o[k];
|
||||
if (typeof cur !== "object" || cur === null) {
|
||||
o2[k] = cur;
|
||||
} else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) {
|
||||
o2[k] = handler(cur, clone);
|
||||
} else if (ArrayBuffer.isView(cur)) {
|
||||
o2[k] = copyBuffer(cur);
|
||||
} else {
|
||||
o2[k] = clone(cur);
|
||||
}
|
||||
}
|
||||
return o2;
|
||||
}
|
||||
function cloneProto(o) {
|
||||
if (typeof o !== "object" || o === null) return o;
|
||||
if (Array.isArray(o)) return cloneArray(o, cloneProto);
|
||||
if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) {
|
||||
return handler(o, cloneProto);
|
||||
}
|
||||
const o2 = {};
|
||||
for (const k in o) {
|
||||
const cur = o[k];
|
||||
if (typeof cur !== "object" || cur === null) {
|
||||
o2[k] = cur;
|
||||
} else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) {
|
||||
o2[k] = handler(cur, cloneProto);
|
||||
} else if (ArrayBuffer.isView(cur)) {
|
||||
o2[k] = copyBuffer(cur);
|
||||
} else {
|
||||
o2[k] = cloneProto(cur);
|
||||
}
|
||||
}
|
||||
return o2;
|
||||
}
|
||||
}
|
||||
function rfdcCircles(opts) {
|
||||
const refs = [];
|
||||
const refsNew = [];
|
||||
const constructorHandlers = /* @__PURE__ */ new Map();
|
||||
constructorHandlers.set(Date, (o) => new Date(o));
|
||||
constructorHandlers.set(Map, (o, fn) => new Map(cloneArray(Array.from(o), fn)));
|
||||
constructorHandlers.set(Set, (o, fn) => new Set(cloneArray(Array.from(o), fn)));
|
||||
if (opts.constructorHandlers) {
|
||||
for (const handler2 of opts.constructorHandlers) {
|
||||
constructorHandlers.set(handler2[0], handler2[1]);
|
||||
}
|
||||
}
|
||||
let handler = null;
|
||||
return opts.proto ? cloneProto : clone;
|
||||
function cloneArray(a, fn) {
|
||||
const keys = Object.keys(a);
|
||||
const a2 = new Array(keys.length);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const k = keys[i];
|
||||
const cur = a[k];
|
||||
if (typeof cur !== "object" || cur === null) {
|
||||
a2[k] = cur;
|
||||
} else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) {
|
||||
a2[k] = handler(cur, fn);
|
||||
} else if (ArrayBuffer.isView(cur)) {
|
||||
a2[k] = copyBuffer(cur);
|
||||
} else {
|
||||
const index = refs.indexOf(cur);
|
||||
if (index !== -1) {
|
||||
a2[k] = refsNew[index];
|
||||
} else {
|
||||
a2[k] = fn(cur);
|
||||
}
|
||||
}
|
||||
}
|
||||
return a2;
|
||||
}
|
||||
function clone(o) {
|
||||
if (typeof o !== "object" || o === null) return o;
|
||||
if (Array.isArray(o)) return cloneArray(o, clone);
|
||||
if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) {
|
||||
return handler(o, clone);
|
||||
}
|
||||
const o2 = {};
|
||||
refs.push(o);
|
||||
refsNew.push(o2);
|
||||
for (const k in o) {
|
||||
if (Object.hasOwnProperty.call(o, k) === false) continue;
|
||||
const cur = o[k];
|
||||
if (typeof cur !== "object" || cur === null) {
|
||||
o2[k] = cur;
|
||||
} else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) {
|
||||
o2[k] = handler(cur, clone);
|
||||
} else if (ArrayBuffer.isView(cur)) {
|
||||
o2[k] = copyBuffer(cur);
|
||||
} else {
|
||||
const i = refs.indexOf(cur);
|
||||
if (i !== -1) {
|
||||
o2[k] = refsNew[i];
|
||||
} else {
|
||||
o2[k] = clone(cur);
|
||||
}
|
||||
}
|
||||
}
|
||||
refs.pop();
|
||||
refsNew.pop();
|
||||
return o2;
|
||||
}
|
||||
function cloneProto(o) {
|
||||
if (typeof o !== "object" || o === null) return o;
|
||||
if (Array.isArray(o)) return cloneArray(o, cloneProto);
|
||||
if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) {
|
||||
return handler(o, cloneProto);
|
||||
}
|
||||
const o2 = {};
|
||||
refs.push(o);
|
||||
refsNew.push(o2);
|
||||
for (const k in o) {
|
||||
const cur = o[k];
|
||||
if (typeof cur !== "object" || cur === null) {
|
||||
o2[k] = cur;
|
||||
} else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) {
|
||||
o2[k] = handler(cur, cloneProto);
|
||||
} else if (ArrayBuffer.isView(cur)) {
|
||||
o2[k] = copyBuffer(cur);
|
||||
} else {
|
||||
const i = refs.indexOf(cur);
|
||||
if (i !== -1) {
|
||||
o2[k] = refsNew[i];
|
||||
} else {
|
||||
o2[k] = cloneProto(cur);
|
||||
}
|
||||
}
|
||||
}
|
||||
refs.pop();
|
||||
refsNew.pop();
|
||||
return o2;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// src/index.ts
|
||||
var index_exports = {};
|
||||
__export(index_exports, {
|
||||
BROADCAST_CHANNEL_NAME: () => BROADCAST_CHANNEL_NAME,
|
||||
NOOP: () => NOOP,
|
||||
VIEW_MODE_STORAGE_KEY: () => VIEW_MODE_STORAGE_KEY,
|
||||
VITE_PLUGIN_CLIENT_URL_STORAGE_KEY: () => VITE_PLUGIN_CLIENT_URL_STORAGE_KEY,
|
||||
VITE_PLUGIN_DETECTED_STORAGE_KEY: () => VITE_PLUGIN_DETECTED_STORAGE_KEY,
|
||||
basename: () => basename,
|
||||
camelize: () => camelize,
|
||||
classify: () => classify,
|
||||
deepClone: () => deepClone,
|
||||
isArray: () => isArray,
|
||||
isBrowser: () => isBrowser,
|
||||
isInChromePanel: () => isInChromePanel,
|
||||
isInElectron: () => isInElectron,
|
||||
isInIframe: () => isInIframe,
|
||||
isInSeparateWindow: () => isInSeparateWindow,
|
||||
isMacOS: () => isMacOS,
|
||||
isMap: () => isMap,
|
||||
isNumeric: () => isNumeric,
|
||||
isNuxtApp: () => isNuxtApp,
|
||||
isObject: () => isObject,
|
||||
isSet: () => isSet,
|
||||
isUrlString: () => isUrlString,
|
||||
kebabize: () => kebabize,
|
||||
randomStr: () => randomStr,
|
||||
sortByKey: () => sortByKey,
|
||||
target: () => target
|
||||
});
|
||||
module.exports = __toCommonJS(index_exports);
|
||||
init_cjs_shims();
|
||||
|
||||
// src/constants.ts
|
||||
init_cjs_shims();
|
||||
var VIEW_MODE_STORAGE_KEY = "__vue-devtools-view-mode__";
|
||||
var VITE_PLUGIN_DETECTED_STORAGE_KEY = "__vue-devtools-vite-plugin-detected__";
|
||||
var VITE_PLUGIN_CLIENT_URL_STORAGE_KEY = "__vue-devtools-vite-plugin-client-url__";
|
||||
var BROADCAST_CHANNEL_NAME = "__vue-devtools-broadcast-channel__";
|
||||
|
||||
// src/env.ts
|
||||
init_cjs_shims();
|
||||
var isBrowser = typeof navigator !== "undefined";
|
||||
var target = typeof window !== "undefined" ? window : typeof globalThis !== "undefined" ? globalThis : typeof global !== "undefined" ? global : {};
|
||||
var isInChromePanel = typeof target.chrome !== "undefined" && !!target.chrome.devtools;
|
||||
var isInIframe = isBrowser && target.self !== target.top;
|
||||
var _a;
|
||||
var isInElectron = typeof navigator !== "undefined" && ((_a = navigator.userAgent) == null ? void 0 : _a.toLowerCase().includes("electron"));
|
||||
var isNuxtApp = typeof window !== "undefined" && !!window.__NUXT__;
|
||||
var isInSeparateWindow = !isInIframe && !isInChromePanel && !isInElectron;
|
||||
|
||||
// src/general.ts
|
||||
init_cjs_shims();
|
||||
var import_rfdc = __toESM(require_rfdc(), 1);
|
||||
function NOOP() {
|
||||
}
|
||||
var isNumeric = (str) => `${+str}` === str;
|
||||
var isMacOS = () => (navigator == null ? void 0 : navigator.platform) ? navigator == null ? void 0 : navigator.platform.toLowerCase().includes("mac") : /Macintosh/.test(navigator.userAgent);
|
||||
var classifyRE = /(?:^|[-_/])(\w)/g;
|
||||
var camelizeRE = /-(\w)/g;
|
||||
var kebabizeRE = /([a-z0-9])([A-Z])/g;
|
||||
function toUpper(_, c) {
|
||||
return c ? c.toUpperCase() : "";
|
||||
}
|
||||
function classify(str) {
|
||||
return str && `${str}`.replace(classifyRE, toUpper);
|
||||
}
|
||||
function camelize(str) {
|
||||
return str && str.replace(camelizeRE, toUpper);
|
||||
}
|
||||
function kebabize(str) {
|
||||
return str && str.replace(kebabizeRE, (_, lowerCaseCharacter, upperCaseLetter) => {
|
||||
return `${lowerCaseCharacter}-${upperCaseLetter}`;
|
||||
}).toLowerCase();
|
||||
}
|
||||
function basename(filename, ext) {
|
||||
let normalizedFilename = filename.replace(/^[a-z]:/i, "").replace(/\\/g, "/");
|
||||
if (normalizedFilename.endsWith(`index${ext}`)) {
|
||||
normalizedFilename = normalizedFilename.replace(`/index${ext}`, ext);
|
||||
}
|
||||
const lastSlashIndex = normalizedFilename.lastIndexOf("/");
|
||||
const baseNameWithExt = normalizedFilename.substring(lastSlashIndex + 1);
|
||||
if (ext) {
|
||||
const extIndex = baseNameWithExt.lastIndexOf(ext);
|
||||
return baseNameWithExt.substring(0, extIndex);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
function sortByKey(state) {
|
||||
return state && state.slice().sort((a, b) => {
|
||||
if (a.key < b.key)
|
||||
return -1;
|
||||
if (a.key > b.key)
|
||||
return 1;
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
var HTTP_URL_RE = /^https?:\/\//;
|
||||
function isUrlString(str) {
|
||||
return str.startsWith("/") || HTTP_URL_RE.test(str);
|
||||
}
|
||||
var deepClone = (0, import_rfdc.default)({ circles: true });
|
||||
function randomStr() {
|
||||
return Math.random().toString(36).slice(2);
|
||||
}
|
||||
function isObject(value) {
|
||||
return typeof value === "object" && !Array.isArray(value) && value !== null;
|
||||
}
|
||||
function isArray(value) {
|
||||
return Array.isArray(value);
|
||||
}
|
||||
function isSet(value) {
|
||||
return value instanceof Set;
|
||||
}
|
||||
function isMap(value) {
|
||||
return value instanceof Map;
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
BROADCAST_CHANNEL_NAME,
|
||||
NOOP,
|
||||
VIEW_MODE_STORAGE_KEY,
|
||||
VITE_PLUGIN_CLIENT_URL_STORAGE_KEY,
|
||||
VITE_PLUGIN_DETECTED_STORAGE_KEY,
|
||||
basename,
|
||||
camelize,
|
||||
classify,
|
||||
deepClone,
|
||||
isArray,
|
||||
isBrowser,
|
||||
isInChromePanel,
|
||||
isInElectron,
|
||||
isInIframe,
|
||||
isInSeparateWindow,
|
||||
isMacOS,
|
||||
isMap,
|
||||
isNumeric,
|
||||
isNuxtApp,
|
||||
isObject,
|
||||
isSet,
|
||||
isUrlString,
|
||||
kebabize,
|
||||
randomStr,
|
||||
sortByKey,
|
||||
target
|
||||
});
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
declare const VIEW_MODE_STORAGE_KEY = "__vue-devtools-view-mode__";
|
||||
declare const VITE_PLUGIN_DETECTED_STORAGE_KEY = "__vue-devtools-vite-plugin-detected__";
|
||||
declare const VITE_PLUGIN_CLIENT_URL_STORAGE_KEY = "__vue-devtools-vite-plugin-client-url__";
|
||||
declare const BROADCAST_CHANNEL_NAME = "__vue-devtools-broadcast-channel__";
|
||||
|
||||
declare const isBrowser: boolean;
|
||||
declare const target: typeof globalThis;
|
||||
declare const isInChromePanel: boolean;
|
||||
declare const isInIframe: boolean;
|
||||
declare const isInElectron: boolean;
|
||||
declare const isNuxtApp: boolean;
|
||||
declare const isInSeparateWindow: boolean;
|
||||
|
||||
declare function NOOP(): void;
|
||||
declare const isNumeric: (str: string | number) => boolean;
|
||||
declare const isMacOS: () => boolean;
|
||||
declare function classify(str: string): string;
|
||||
declare function camelize(str: string): string;
|
||||
declare function kebabize(str: string): string;
|
||||
declare function basename(filename: string, ext: string): string;
|
||||
declare function sortByKey(state: unknown[]): Record<"key", number>[];
|
||||
/**
|
||||
* Check a string is start with `/` or a valid http url
|
||||
*/
|
||||
declare function isUrlString(str: string): boolean;
|
||||
/**
|
||||
* @copyright [rfdc](https://github.com/davidmarkclements/rfdc)
|
||||
* @description A really fast deep clone alternative
|
||||
*/
|
||||
declare const deepClone: <T>(input: T) => T;
|
||||
declare function randomStr(): string;
|
||||
declare function isObject<T extends object>(value: any): value is T;
|
||||
declare function isArray<T>(value: any): value is T[];
|
||||
declare function isSet<T>(value: any): value is Set<T>;
|
||||
declare function isMap<K, V>(value: any): value is Map<K, V>;
|
||||
|
||||
export { BROADCAST_CHANNEL_NAME, NOOP, VIEW_MODE_STORAGE_KEY, VITE_PLUGIN_CLIENT_URL_STORAGE_KEY, VITE_PLUGIN_DETECTED_STORAGE_KEY, basename, camelize, classify, deepClone, isArray, isBrowser, isInChromePanel, isInElectron, isInIframe, isInSeparateWindow, isMacOS, isMap, isNumeric, isNuxtApp, isObject, isSet, isUrlString, kebabize, randomStr, sortByKey, target };
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
declare const VIEW_MODE_STORAGE_KEY = "__vue-devtools-view-mode__";
|
||||
declare const VITE_PLUGIN_DETECTED_STORAGE_KEY = "__vue-devtools-vite-plugin-detected__";
|
||||
declare const VITE_PLUGIN_CLIENT_URL_STORAGE_KEY = "__vue-devtools-vite-plugin-client-url__";
|
||||
declare const BROADCAST_CHANNEL_NAME = "__vue-devtools-broadcast-channel__";
|
||||
|
||||
declare const isBrowser: boolean;
|
||||
declare const target: typeof globalThis;
|
||||
declare const isInChromePanel: boolean;
|
||||
declare const isInIframe: boolean;
|
||||
declare const isInElectron: boolean;
|
||||
declare const isNuxtApp: boolean;
|
||||
declare const isInSeparateWindow: boolean;
|
||||
|
||||
declare function NOOP(): void;
|
||||
declare const isNumeric: (str: string | number) => boolean;
|
||||
declare const isMacOS: () => boolean;
|
||||
declare function classify(str: string): string;
|
||||
declare function camelize(str: string): string;
|
||||
declare function kebabize(str: string): string;
|
||||
declare function basename(filename: string, ext: string): string;
|
||||
declare function sortByKey(state: unknown[]): Record<"key", number>[];
|
||||
/**
|
||||
* Check a string is start with `/` or a valid http url
|
||||
*/
|
||||
declare function isUrlString(str: string): boolean;
|
||||
/**
|
||||
* @copyright [rfdc](https://github.com/davidmarkclements/rfdc)
|
||||
* @description A really fast deep clone alternative
|
||||
*/
|
||||
declare const deepClone: <T>(input: T) => T;
|
||||
declare function randomStr(): string;
|
||||
declare function isObject<T extends object>(value: any): value is T;
|
||||
declare function isArray<T>(value: any): value is T[];
|
||||
declare function isSet<T>(value: any): value is Set<T>;
|
||||
declare function isMap<K, V>(value: any): value is Map<K, V>;
|
||||
|
||||
export { BROADCAST_CHANNEL_NAME, NOOP, VIEW_MODE_STORAGE_KEY, VITE_PLUGIN_CLIENT_URL_STORAGE_KEY, VITE_PLUGIN_DETECTED_STORAGE_KEY, basename, camelize, classify, deepClone, isArray, isBrowser, isInChromePanel, isInElectron, isInIframe, isInSeparateWindow, isMacOS, isMap, isNumeric, isNuxtApp, isObject, isSet, isUrlString, kebabize, randomStr, sortByKey, target };
|
||||
+341
@@ -0,0 +1,341 @@
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __esm = (fn, res) => function __init() {
|
||||
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
||||
};
|
||||
var __commonJS = (cb, mod) => function __require() {
|
||||
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target2) => (target2 = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||
// If the importer is in node compatibility mode or this is not an ESM
|
||||
// file that has been converted to a CommonJS file using a Babel-
|
||||
// compatible transform (i.e. "__esModule" has not been set), then set
|
||||
// "default" to the CommonJS "module.exports" for node compatibility.
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target2, "default", { value: mod, enumerable: true }) : target2,
|
||||
mod
|
||||
));
|
||||
|
||||
// ../../node_modules/.pnpm/tsup@8.4.0_@microsoft+api-extractor@7.51.1_@types+node@22.13.14__jiti@2.4.2_postcss@8.5_96eb05a9d65343021e53791dd83f3773/node_modules/tsup/assets/esm_shims.js
|
||||
var init_esm_shims = __esm({
|
||||
"../../node_modules/.pnpm/tsup@8.4.0_@microsoft+api-extractor@7.51.1_@types+node@22.13.14__jiti@2.4.2_postcss@8.5_96eb05a9d65343021e53791dd83f3773/node_modules/tsup/assets/esm_shims.js"() {
|
||||
"use strict";
|
||||
}
|
||||
});
|
||||
|
||||
// ../../node_modules/.pnpm/rfdc@1.4.1/node_modules/rfdc/index.js
|
||||
var require_rfdc = __commonJS({
|
||||
"../../node_modules/.pnpm/rfdc@1.4.1/node_modules/rfdc/index.js"(exports, module) {
|
||||
"use strict";
|
||||
init_esm_shims();
|
||||
module.exports = rfdc2;
|
||||
function copyBuffer(cur) {
|
||||
if (cur instanceof Buffer) {
|
||||
return Buffer.from(cur);
|
||||
}
|
||||
return new cur.constructor(cur.buffer.slice(), cur.byteOffset, cur.length);
|
||||
}
|
||||
function rfdc2(opts) {
|
||||
opts = opts || {};
|
||||
if (opts.circles) return rfdcCircles(opts);
|
||||
const constructorHandlers = /* @__PURE__ */ new Map();
|
||||
constructorHandlers.set(Date, (o) => new Date(o));
|
||||
constructorHandlers.set(Map, (o, fn) => new Map(cloneArray(Array.from(o), fn)));
|
||||
constructorHandlers.set(Set, (o, fn) => new Set(cloneArray(Array.from(o), fn)));
|
||||
if (opts.constructorHandlers) {
|
||||
for (const handler2 of opts.constructorHandlers) {
|
||||
constructorHandlers.set(handler2[0], handler2[1]);
|
||||
}
|
||||
}
|
||||
let handler = null;
|
||||
return opts.proto ? cloneProto : clone;
|
||||
function cloneArray(a, fn) {
|
||||
const keys = Object.keys(a);
|
||||
const a2 = new Array(keys.length);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const k = keys[i];
|
||||
const cur = a[k];
|
||||
if (typeof cur !== "object" || cur === null) {
|
||||
a2[k] = cur;
|
||||
} else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) {
|
||||
a2[k] = handler(cur, fn);
|
||||
} else if (ArrayBuffer.isView(cur)) {
|
||||
a2[k] = copyBuffer(cur);
|
||||
} else {
|
||||
a2[k] = fn(cur);
|
||||
}
|
||||
}
|
||||
return a2;
|
||||
}
|
||||
function clone(o) {
|
||||
if (typeof o !== "object" || o === null) return o;
|
||||
if (Array.isArray(o)) return cloneArray(o, clone);
|
||||
if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) {
|
||||
return handler(o, clone);
|
||||
}
|
||||
const o2 = {};
|
||||
for (const k in o) {
|
||||
if (Object.hasOwnProperty.call(o, k) === false) continue;
|
||||
const cur = o[k];
|
||||
if (typeof cur !== "object" || cur === null) {
|
||||
o2[k] = cur;
|
||||
} else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) {
|
||||
o2[k] = handler(cur, clone);
|
||||
} else if (ArrayBuffer.isView(cur)) {
|
||||
o2[k] = copyBuffer(cur);
|
||||
} else {
|
||||
o2[k] = clone(cur);
|
||||
}
|
||||
}
|
||||
return o2;
|
||||
}
|
||||
function cloneProto(o) {
|
||||
if (typeof o !== "object" || o === null) return o;
|
||||
if (Array.isArray(o)) return cloneArray(o, cloneProto);
|
||||
if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) {
|
||||
return handler(o, cloneProto);
|
||||
}
|
||||
const o2 = {};
|
||||
for (const k in o) {
|
||||
const cur = o[k];
|
||||
if (typeof cur !== "object" || cur === null) {
|
||||
o2[k] = cur;
|
||||
} else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) {
|
||||
o2[k] = handler(cur, cloneProto);
|
||||
} else if (ArrayBuffer.isView(cur)) {
|
||||
o2[k] = copyBuffer(cur);
|
||||
} else {
|
||||
o2[k] = cloneProto(cur);
|
||||
}
|
||||
}
|
||||
return o2;
|
||||
}
|
||||
}
|
||||
function rfdcCircles(opts) {
|
||||
const refs = [];
|
||||
const refsNew = [];
|
||||
const constructorHandlers = /* @__PURE__ */ new Map();
|
||||
constructorHandlers.set(Date, (o) => new Date(o));
|
||||
constructorHandlers.set(Map, (o, fn) => new Map(cloneArray(Array.from(o), fn)));
|
||||
constructorHandlers.set(Set, (o, fn) => new Set(cloneArray(Array.from(o), fn)));
|
||||
if (opts.constructorHandlers) {
|
||||
for (const handler2 of opts.constructorHandlers) {
|
||||
constructorHandlers.set(handler2[0], handler2[1]);
|
||||
}
|
||||
}
|
||||
let handler = null;
|
||||
return opts.proto ? cloneProto : clone;
|
||||
function cloneArray(a, fn) {
|
||||
const keys = Object.keys(a);
|
||||
const a2 = new Array(keys.length);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const k = keys[i];
|
||||
const cur = a[k];
|
||||
if (typeof cur !== "object" || cur === null) {
|
||||
a2[k] = cur;
|
||||
} else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) {
|
||||
a2[k] = handler(cur, fn);
|
||||
} else if (ArrayBuffer.isView(cur)) {
|
||||
a2[k] = copyBuffer(cur);
|
||||
} else {
|
||||
const index = refs.indexOf(cur);
|
||||
if (index !== -1) {
|
||||
a2[k] = refsNew[index];
|
||||
} else {
|
||||
a2[k] = fn(cur);
|
||||
}
|
||||
}
|
||||
}
|
||||
return a2;
|
||||
}
|
||||
function clone(o) {
|
||||
if (typeof o !== "object" || o === null) return o;
|
||||
if (Array.isArray(o)) return cloneArray(o, clone);
|
||||
if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) {
|
||||
return handler(o, clone);
|
||||
}
|
||||
const o2 = {};
|
||||
refs.push(o);
|
||||
refsNew.push(o2);
|
||||
for (const k in o) {
|
||||
if (Object.hasOwnProperty.call(o, k) === false) continue;
|
||||
const cur = o[k];
|
||||
if (typeof cur !== "object" || cur === null) {
|
||||
o2[k] = cur;
|
||||
} else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) {
|
||||
o2[k] = handler(cur, clone);
|
||||
} else if (ArrayBuffer.isView(cur)) {
|
||||
o2[k] = copyBuffer(cur);
|
||||
} else {
|
||||
const i = refs.indexOf(cur);
|
||||
if (i !== -1) {
|
||||
o2[k] = refsNew[i];
|
||||
} else {
|
||||
o2[k] = clone(cur);
|
||||
}
|
||||
}
|
||||
}
|
||||
refs.pop();
|
||||
refsNew.pop();
|
||||
return o2;
|
||||
}
|
||||
function cloneProto(o) {
|
||||
if (typeof o !== "object" || o === null) return o;
|
||||
if (Array.isArray(o)) return cloneArray(o, cloneProto);
|
||||
if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) {
|
||||
return handler(o, cloneProto);
|
||||
}
|
||||
const o2 = {};
|
||||
refs.push(o);
|
||||
refsNew.push(o2);
|
||||
for (const k in o) {
|
||||
const cur = o[k];
|
||||
if (typeof cur !== "object" || cur === null) {
|
||||
o2[k] = cur;
|
||||
} else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) {
|
||||
o2[k] = handler(cur, cloneProto);
|
||||
} else if (ArrayBuffer.isView(cur)) {
|
||||
o2[k] = copyBuffer(cur);
|
||||
} else {
|
||||
const i = refs.indexOf(cur);
|
||||
if (i !== -1) {
|
||||
o2[k] = refsNew[i];
|
||||
} else {
|
||||
o2[k] = cloneProto(cur);
|
||||
}
|
||||
}
|
||||
}
|
||||
refs.pop();
|
||||
refsNew.pop();
|
||||
return o2;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// src/index.ts
|
||||
init_esm_shims();
|
||||
|
||||
// src/constants.ts
|
||||
init_esm_shims();
|
||||
var VIEW_MODE_STORAGE_KEY = "__vue-devtools-view-mode__";
|
||||
var VITE_PLUGIN_DETECTED_STORAGE_KEY = "__vue-devtools-vite-plugin-detected__";
|
||||
var VITE_PLUGIN_CLIENT_URL_STORAGE_KEY = "__vue-devtools-vite-plugin-client-url__";
|
||||
var BROADCAST_CHANNEL_NAME = "__vue-devtools-broadcast-channel__";
|
||||
|
||||
// src/env.ts
|
||||
init_esm_shims();
|
||||
var isBrowser = typeof navigator !== "undefined";
|
||||
var target = typeof window !== "undefined" ? window : typeof globalThis !== "undefined" ? globalThis : typeof global !== "undefined" ? global : {};
|
||||
var isInChromePanel = typeof target.chrome !== "undefined" && !!target.chrome.devtools;
|
||||
var isInIframe = isBrowser && target.self !== target.top;
|
||||
var _a;
|
||||
var isInElectron = typeof navigator !== "undefined" && ((_a = navigator.userAgent) == null ? void 0 : _a.toLowerCase().includes("electron"));
|
||||
var isNuxtApp = typeof window !== "undefined" && !!window.__NUXT__;
|
||||
var isInSeparateWindow = !isInIframe && !isInChromePanel && !isInElectron;
|
||||
|
||||
// src/general.ts
|
||||
init_esm_shims();
|
||||
var import_rfdc = __toESM(require_rfdc(), 1);
|
||||
function NOOP() {
|
||||
}
|
||||
var isNumeric = (str) => `${+str}` === str;
|
||||
var isMacOS = () => (navigator == null ? void 0 : navigator.platform) ? navigator == null ? void 0 : navigator.platform.toLowerCase().includes("mac") : /Macintosh/.test(navigator.userAgent);
|
||||
var classifyRE = /(?:^|[-_/])(\w)/g;
|
||||
var camelizeRE = /-(\w)/g;
|
||||
var kebabizeRE = /([a-z0-9])([A-Z])/g;
|
||||
function toUpper(_, c) {
|
||||
return c ? c.toUpperCase() : "";
|
||||
}
|
||||
function classify(str) {
|
||||
return str && `${str}`.replace(classifyRE, toUpper);
|
||||
}
|
||||
function camelize(str) {
|
||||
return str && str.replace(camelizeRE, toUpper);
|
||||
}
|
||||
function kebabize(str) {
|
||||
return str && str.replace(kebabizeRE, (_, lowerCaseCharacter, upperCaseLetter) => {
|
||||
return `${lowerCaseCharacter}-${upperCaseLetter}`;
|
||||
}).toLowerCase();
|
||||
}
|
||||
function basename(filename, ext) {
|
||||
let normalizedFilename = filename.replace(/^[a-z]:/i, "").replace(/\\/g, "/");
|
||||
if (normalizedFilename.endsWith(`index${ext}`)) {
|
||||
normalizedFilename = normalizedFilename.replace(`/index${ext}`, ext);
|
||||
}
|
||||
const lastSlashIndex = normalizedFilename.lastIndexOf("/");
|
||||
const baseNameWithExt = normalizedFilename.substring(lastSlashIndex + 1);
|
||||
if (ext) {
|
||||
const extIndex = baseNameWithExt.lastIndexOf(ext);
|
||||
return baseNameWithExt.substring(0, extIndex);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
function sortByKey(state) {
|
||||
return state && state.slice().sort((a, b) => {
|
||||
if (a.key < b.key)
|
||||
return -1;
|
||||
if (a.key > b.key)
|
||||
return 1;
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
var HTTP_URL_RE = /^https?:\/\//;
|
||||
function isUrlString(str) {
|
||||
return str.startsWith("/") || HTTP_URL_RE.test(str);
|
||||
}
|
||||
var deepClone = (0, import_rfdc.default)({ circles: true });
|
||||
function randomStr() {
|
||||
return Math.random().toString(36).slice(2);
|
||||
}
|
||||
function isObject(value) {
|
||||
return typeof value === "object" && !Array.isArray(value) && value !== null;
|
||||
}
|
||||
function isArray(value) {
|
||||
return Array.isArray(value);
|
||||
}
|
||||
function isSet(value) {
|
||||
return value instanceof Set;
|
||||
}
|
||||
function isMap(value) {
|
||||
return value instanceof Map;
|
||||
}
|
||||
export {
|
||||
BROADCAST_CHANNEL_NAME,
|
||||
NOOP,
|
||||
VIEW_MODE_STORAGE_KEY,
|
||||
VITE_PLUGIN_CLIENT_URL_STORAGE_KEY,
|
||||
VITE_PLUGIN_DETECTED_STORAGE_KEY,
|
||||
basename,
|
||||
camelize,
|
||||
classify,
|
||||
deepClone,
|
||||
isArray,
|
||||
isBrowser,
|
||||
isInChromePanel,
|
||||
isInElectron,
|
||||
isInIframe,
|
||||
isInSeparateWindow,
|
||||
isMacOS,
|
||||
isMap,
|
||||
isNumeric,
|
||||
isNuxtApp,
|
||||
isObject,
|
||||
isSet,
|
||||
isUrlString,
|
||||
kebabize,
|
||||
randomStr,
|
||||
sortByKey,
|
||||
target
|
||||
};
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "@vue/devtools-shared",
|
||||
"type": "module",
|
||||
"version": "7.7.9",
|
||||
"author": "webfansplz",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"directory": "packages/shared",
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/vuejs/devtools.git"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/index.js",
|
||||
"require": "./dist/index.cjs"
|
||||
}
|
||||
},
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"dependencies": {
|
||||
"rfdc": "^1.4.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.13.14"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsup",
|
||||
"prepare:type": "tsup --dts-only",
|
||||
"stub": "tsup --watch --onSuccess 'tsup --dts-only'"
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Pooya Parsa <pooya@pi0.io>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
# perfect-debounce
|
||||
|
||||
[![npm version][npm-version-src]][npm-version-href]
|
||||
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
||||
[![Github Actions][github-actions-src]][github-actions-href]
|
||||
[![Codecov][codecov-src]][codecov-href]
|
||||
|
||||
> An improved debounce function with Promise support.
|
||||
|
||||
- Well tested debounce implementation
|
||||
- Native Promise support
|
||||
- Avoid duplicate calls while promise is being resolved
|
||||
- Configurable `trailing` and `leading` behavior
|
||||
|
||||
## Usage
|
||||
|
||||
Install package:
|
||||
|
||||
```sh
|
||||
# npm
|
||||
npm install perfect-debounce
|
||||
|
||||
# yarn
|
||||
yarn add perfect-debounce
|
||||
|
||||
# pnpm
|
||||
pnpm add perfect-debounce
|
||||
```
|
||||
|
||||
Import:
|
||||
|
||||
```js
|
||||
// ESM
|
||||
import { debounce } from 'perfect-debounce'
|
||||
|
||||
// CommonJS
|
||||
const { debounce } = require('perfect-debounce')
|
||||
```
|
||||
|
||||
Debounce function:
|
||||
|
||||
```js
|
||||
const debounced = debounce(async () => {
|
||||
// Some heavy stuff
|
||||
}, 25)
|
||||
```
|
||||
|
||||
When calling `debounced`, it will wait at least for `25ms` as configured before actually calling our function. This helps to avoid multiple calls.
|
||||
|
||||
To avoid initial wait, we can set `leading: true` option. It will cause function to be immediately called if there is no other call:
|
||||
|
||||
```js
|
||||
const debounced = debounce(async () => {
|
||||
// Some heavy stuff
|
||||
}, 25, { leading: true })
|
||||
```
|
||||
|
||||
If executing async function takes longer than debounce value, duplicate calls will be still prevented a last call will happen. To disable this behavior, we can set `trailing: false` option:
|
||||
|
||||
```js
|
||||
const debounced = debounce(async () => {
|
||||
// Some heavy stuff
|
||||
}, 25, { trailing: false })
|
||||
```
|
||||
|
||||
## 💻 Development
|
||||
|
||||
- Clone this repository
|
||||
- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable` (use `npm i -g corepack` for Node.js < 16.10)
|
||||
- Install dependencies using `pnpm install`
|
||||
- Run interactive tests using `pnpm dev`
|
||||
|
||||
## License
|
||||
|
||||
Made with 💛
|
||||
|
||||
Based on [sindresorhus/p-debounce](https://github.com/sindresorhus/p-debounce).
|
||||
|
||||
Published under [MIT License](./LICENSE).
|
||||
|
||||
<!-- Badges -->
|
||||
[npm-version-src]: https://img.shields.io/npm/v/perfect-debounce?style=flat-square
|
||||
[npm-version-href]: https://npmjs.com/package/perfect-debounce
|
||||
|
||||
[npm-downloads-src]: https://img.shields.io/npm/dm/perfect-debounce?style=flat-square
|
||||
[npm-downloads-href]: https://npmjs.com/package/perfect-debounce
|
||||
|
||||
[github-actions-src]: https://img.shields.io/github/workflow/status/unjs/perfect-debounce/ci/main?style=flat-square
|
||||
[github-actions-href]: https://github.com/unjs/perfect-debounce/actions?query=workflow%3Aci
|
||||
|
||||
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/perfect-debounce/main?style=flat-square
|
||||
[codecov-href]: https://codecov.io/gh/unjs/perfect-debounce
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
'use strict';
|
||||
|
||||
const DEBOUNCE_DEFAULTS = {
|
||||
trailing: true
|
||||
};
|
||||
function debounce(fn, wait = 25, options = {}) {
|
||||
options = { ...DEBOUNCE_DEFAULTS, ...options };
|
||||
if (!Number.isFinite(wait)) {
|
||||
throw new TypeError("Expected `wait` to be a finite number");
|
||||
}
|
||||
let leadingValue;
|
||||
let timeout;
|
||||
let resolveList = [];
|
||||
let currentPromise;
|
||||
let trailingArgs;
|
||||
const applyFn = (_this, args) => {
|
||||
currentPromise = _applyPromised(fn, _this, args);
|
||||
currentPromise.finally(() => {
|
||||
currentPromise = null;
|
||||
if (options.trailing && trailingArgs && !timeout) {
|
||||
const promise = applyFn(_this, trailingArgs);
|
||||
trailingArgs = null;
|
||||
return promise;
|
||||
}
|
||||
});
|
||||
return currentPromise;
|
||||
};
|
||||
return function(...args) {
|
||||
if (currentPromise) {
|
||||
if (options.trailing) {
|
||||
trailingArgs = args;
|
||||
}
|
||||
return currentPromise;
|
||||
}
|
||||
return new Promise((resolve) => {
|
||||
const shouldCallNow = !timeout && options.leading;
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => {
|
||||
timeout = null;
|
||||
const promise = options.leading ? leadingValue : applyFn(this, args);
|
||||
for (const _resolve of resolveList) {
|
||||
_resolve(promise);
|
||||
}
|
||||
resolveList = [];
|
||||
}, wait);
|
||||
if (shouldCallNow) {
|
||||
leadingValue = applyFn(this, args);
|
||||
resolve(leadingValue);
|
||||
} else {
|
||||
resolveList.push(resolve);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
async function _applyPromised(fn, _this, args) {
|
||||
return await fn.apply(_this, args);
|
||||
}
|
||||
|
||||
exports.debounce = debounce;
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
interface DebounceOptions {
|
||||
/**
|
||||
Call the `fn` on the [leading edge of the timeout](https://css-tricks.com/debouncing-throttling-explained-examples/#article-header-id-1).
|
||||
Meaning immediately, instead of waiting for `wait` milliseconds.
|
||||
@default false
|
||||
*/
|
||||
readonly leading?: boolean;
|
||||
/**
|
||||
Call the `fn` on trailing edge with last used arguments. Result of call is from previous call.
|
||||
@default false
|
||||
*/
|
||||
readonly trailing?: boolean;
|
||||
}
|
||||
/**
|
||||
Debounce functions
|
||||
@param fn - Promise-returning/async function to debounce.
|
||||
@param wait - Milliseconds to wait before calling `fn`. Default value is 25ms
|
||||
@returns A function that delays calling `fn` until after `wait` milliseconds have elapsed since the last time it was called.
|
||||
@example
|
||||
```
|
||||
import { debounce } from 'perfect-debounce';
|
||||
const expensiveCall = async input => input;
|
||||
const debouncedFn = debounce(expensiveCall, 200);
|
||||
for (const number of [1, 2, 3]) {
|
||||
console.log(await debouncedFn(number));
|
||||
}
|
||||
//=> 3
|
||||
//=> 3
|
||||
//=> 3
|
||||
```
|
||||
*/
|
||||
declare function debounce<ArgumentsT extends unknown[], ReturnT>(fn: (...args: ArgumentsT) => PromiseLike<ReturnT> | ReturnT, wait?: number, options?: DebounceOptions): (...args: ArgumentsT) => Promise<ReturnT>;
|
||||
|
||||
export { DebounceOptions, debounce };
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
const DEBOUNCE_DEFAULTS = {
|
||||
trailing: true
|
||||
};
|
||||
function debounce(fn, wait = 25, options = {}) {
|
||||
options = { ...DEBOUNCE_DEFAULTS, ...options };
|
||||
if (!Number.isFinite(wait)) {
|
||||
throw new TypeError("Expected `wait` to be a finite number");
|
||||
}
|
||||
let leadingValue;
|
||||
let timeout;
|
||||
let resolveList = [];
|
||||
let currentPromise;
|
||||
let trailingArgs;
|
||||
const applyFn = (_this, args) => {
|
||||
currentPromise = _applyPromised(fn, _this, args);
|
||||
currentPromise.finally(() => {
|
||||
currentPromise = null;
|
||||
if (options.trailing && trailingArgs && !timeout) {
|
||||
const promise = applyFn(_this, trailingArgs);
|
||||
trailingArgs = null;
|
||||
return promise;
|
||||
}
|
||||
});
|
||||
return currentPromise;
|
||||
};
|
||||
return function(...args) {
|
||||
if (currentPromise) {
|
||||
if (options.trailing) {
|
||||
trailingArgs = args;
|
||||
}
|
||||
return currentPromise;
|
||||
}
|
||||
return new Promise((resolve) => {
|
||||
const shouldCallNow = !timeout && options.leading;
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => {
|
||||
timeout = null;
|
||||
const promise = options.leading ? leadingValue : applyFn(this, args);
|
||||
for (const _resolve of resolveList) {
|
||||
_resolve(promise);
|
||||
}
|
||||
resolveList = [];
|
||||
}, wait);
|
||||
if (shouldCallNow) {
|
||||
leadingValue = applyFn(this, args);
|
||||
resolve(leadingValue);
|
||||
} else {
|
||||
resolveList.push(resolve);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
async function _applyPromised(fn, _this, args) {
|
||||
return await fn.apply(_this, args);
|
||||
}
|
||||
|
||||
export { debounce };
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "perfect-debounce",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"repository": "unjs/perfect-debounce",
|
||||
"license": "MIT",
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.cjs"
|
||||
}
|
||||
},
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "unbuild",
|
||||
"dev": "vitest dev",
|
||||
"lint": "eslint --ext .ts,.js,.mjs,.cjs . && prettier --check src test",
|
||||
"lint:fix": "eslint --ext .ts,.js,.mjs,.cjs . --fix && prettier -w src test",
|
||||
"release": "pnpm test && pnpm build && changelogen --release --push && npm publish",
|
||||
"test": "vitest run --coverage"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.16.3",
|
||||
"@vitest/coverage-c8": "^0.31.0",
|
||||
"changelogen": "^0.5.3",
|
||||
"eslint": "^8.39.0",
|
||||
"eslint-config-unjs": "^0.1.0",
|
||||
"in-range": "^3.0.0",
|
||||
"prettier": "^2.8.8",
|
||||
"time-span": "^5.1.0",
|
||||
"typescript": "^5.0.4",
|
||||
"unbuild": "^1.2.1",
|
||||
"vitest": "^0.31.0"
|
||||
},
|
||||
"packageManager": "pnpm@8.4.0"
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
{
|
||||
"name": "pinia",
|
||||
"version": "3.0.4",
|
||||
"description": "Intuitive, type safe and flexible Store for Vue",
|
||||
"type": "module",
|
||||
"main": "index.cjs",
|
||||
"module": "dist/pinia.mjs",
|
||||
"unpkg": "dist/pinia.iife.js",
|
||||
"jsdelivr": "dist/pinia.iife.js",
|
||||
"types": "dist/pinia.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/pinia.d.ts",
|
||||
"node": {
|
||||
"import": {
|
||||
"production": "./dist/pinia.prod.cjs",
|
||||
"development": "./dist/pinia.mjs",
|
||||
"default": "./dist/pinia.mjs"
|
||||
},
|
||||
"require": {
|
||||
"production": "./dist/pinia.prod.cjs",
|
||||
"development": "./dist/pinia.cjs",
|
||||
"default": "./index.cjs"
|
||||
}
|
||||
},
|
||||
"import": "./dist/pinia.mjs",
|
||||
"require": "./index.cjs"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"author": {
|
||||
"name": "Eduardo San Martin Morote",
|
||||
"email": "posva13@gmail.com"
|
||||
},
|
||||
"funding": "https://github.com/sponsors/posva",
|
||||
"files": [
|
||||
"dist/*.js",
|
||||
"dist/*.mjs",
|
||||
"dist/*.cjs",
|
||||
"dist/pinia.d.ts",
|
||||
"index.cjs",
|
||||
"LICENSE",
|
||||
"README.md"
|
||||
],
|
||||
"keywords": [
|
||||
"vue",
|
||||
"vuex",
|
||||
"store",
|
||||
"pinia",
|
||||
"piña",
|
||||
"pigna",
|
||||
"composition",
|
||||
"api",
|
||||
"setup",
|
||||
"typed",
|
||||
"typescript",
|
||||
"ts",
|
||||
"type",
|
||||
"safe"
|
||||
],
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@microsoft/api-extractor": "7.53.3",
|
||||
"@vue/test-utils": "^2.4.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@vue/devtools-api": "^7.7.7"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": ">=4.5.0",
|
||||
"vue": "^3.5.11"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/vuejs/pinia.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/vuejs/pinia/issues"
|
||||
},
|
||||
"homepage": "https://pinia.vuejs.org",
|
||||
"scripts": {
|
||||
"build": "rimraf dist && rollup -c ../../rollup.config.mjs --environment TARGET:pinia",
|
||||
"build:dts": "api-extractor run --local --verbose && tail -n +3 ./src/globalExtensions.ts >> dist/pinia.d.ts",
|
||||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . -l pinia -r 1",
|
||||
"test:dts": "tsc -p ./test-dts/tsconfig.json",
|
||||
"test": "pnpm run build && pnpm run build:dts && pnpm test:dts"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user