@azrico/global 1.3.16 → 1.3.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -6
- package/dist/packages/cache/g_cache.js +3 -244
- package/dist/packages/cache/index.js +1 -1
- package/dist/packages/core/index.js +2 -86
- package/dist/packages/hooks/g_filter.js +5 -66
- package/dist/packages/hooks/g_func.js +9 -122
- package/dist/packages/hooks/g_holder.js +2 -20
- package/dist/packages/hooks/g_view.js +7 -43
- package/dist/packages/hooks/index.js +1 -4
- package/dist/packages/once/g_once.js +1 -24
- package/dist/packages/once/index.js +1 -3
- package/dist/packages/state/g_state.js +6 -112
- package/dist/packages/state/index.js +1 -1
- package/dist/packages/storage/g_storage.js +1 -124
- package/dist/packages/storage/index.js +1 -1
- package/package.json +4 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export * as gonce from "./packages/once";
|
|
3
|
-
export * as gcache from "./packages/cache";
|
|
4
|
-
export * as gstorage from "./packages/storage";
|
|
5
|
-
export * as gstate from "./packages/state";
|
|
6
|
-
export { gfilter, gfunc, gholder, gview } from "./packages/hooks";
|
|
1
|
+
"use strict";var _gglobal=_interopRequireWildcard(require("./packages/core"));var _gonce=_interopRequireWildcard(require("./packages/once"));var _gcache=_interopRequireWildcard(require("./packages/cache"));var _gstorage=_interopRequireWildcard(require("./packages/storage"));var _gstate=_interopRequireWildcard(require("./packages/state"));var _hooks=require("./packages/hooks");function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.gcache=void 0,Object.defineProperty(exports,"gfilter",{enumerable:!0,get:function get(){return _hooks.gfilter}}),Object.defineProperty(exports,"gfunc",{enumerable:!0,get:function get(){return _hooks.gfunc}}),exports.gglobal=void 0,Object.defineProperty(exports,"gholder",{enumerable:!0,get:function get(){return _hooks.gholder}}),exports.gstorage=exports.gstate=exports.gonce=void 0,Object.defineProperty(exports,"gview",{enumerable:!0,get:function get(){return _hooks.gview}});exports.gglobal=_gglobal;exports.gonce=_gonce;exports.gcache=_gcache;exports.gstorage=_gstorage;exports.gstate=_gstate;function _getRequireWildcardCache(a){if("function"!=typeof WeakMap)return null;var b=new WeakMap,c=new WeakMap;return(_getRequireWildcardCache=function(a){return a?c:b})(a)}function _interopRequireWildcard(a,b){if(!b&&a&&a.__esModule)return a;if(null===a||"object"!==_typeof(a)&&"function"!=typeof a)return{default:a};var c=_getRequireWildcardCache(b);if(c&&c.has(a))return c.get(a);var d={},e=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var f in a)if("default"!=f&&Object.prototype.hasOwnProperty.call(a,f)){var g=e?Object.getOwnPropertyDescriptor(a,f):null;g&&(g.get||g.set)?Object.defineProperty(d,f,g):d[f]=a[f]}return d["default"]=a,c&&c.set(a,d),d}
|
|
@@ -1,244 +1,3 @@
|
|
|
1
|
-
import glb from "../core";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const name_pending = "pending_cache_loads";
|
|
5
|
-
const lname = "list_cache";
|
|
6
|
-
const lname_f = "list_cache_func";
|
|
7
|
-
export async function get_cache(key, getterFunction, params) {
|
|
8
|
-
key = glb.fixKey(key);
|
|
9
|
-
const cachePending_key = `cache-pending-${key}`;
|
|
10
|
-
const old_pending_cache = glb.Global_get(name_pending, cachePending_key);
|
|
11
|
-
if (old_pending_cache)
|
|
12
|
-
return await old_pending_cache;
|
|
13
|
-
const cache_loader = _get_cache_local(key, getterFunction, params);
|
|
14
|
-
glb.Global_set(name_pending, cachePending_key, cache_loader);
|
|
15
|
-
const cacheResponse = await cache_loader;
|
|
16
|
-
glb.Global_set(name_pending, cachePending_key, undefined);
|
|
17
|
-
return cacheResponse;
|
|
18
|
-
}
|
|
19
|
-
async function _get_cache_local(key, getterFunction, params) {
|
|
20
|
-
if (!params)
|
|
21
|
-
params = {};
|
|
22
|
-
const storage_key = `${sname}-${key}`;
|
|
23
|
-
/* -------------------------------------------------------------------------- */
|
|
24
|
-
/* get the cache */
|
|
25
|
-
/* -------------------------------------------------------------------------- */
|
|
26
|
-
let currentCache = "";
|
|
27
|
-
let cacheUpdated = false;
|
|
28
|
-
/* ----------------------- save to session by default ----------------------- */
|
|
29
|
-
if (!params.session && !params.storage && !params.local_storage) {
|
|
30
|
-
params.session = true;
|
|
31
|
-
}
|
|
32
|
-
currentCache = await gstorage.get_var(storage_key, {
|
|
33
|
-
local_storage: params.local_storage,
|
|
34
|
-
session: params.session,
|
|
35
|
-
storage: params.storage,
|
|
36
|
-
});
|
|
37
|
-
/* -------------------------------------------------------------------------- */
|
|
38
|
-
/* if cache not found use the cache func */
|
|
39
|
-
/* -------------------------------------------------------------------------- */
|
|
40
|
-
if (!currentCache) {
|
|
41
|
-
let currentCacheFunction = null;
|
|
42
|
-
if (typeof getterFunction === "function") {
|
|
43
|
-
currentCacheFunction = getterFunction;
|
|
44
|
-
}
|
|
45
|
-
else if (currentCacheFunction == null) {
|
|
46
|
-
currentCacheFunction = get_cacheFunc(key);
|
|
47
|
-
}
|
|
48
|
-
if (typeof currentCacheFunction === "function") {
|
|
49
|
-
currentCache = JSON.stringify(convert_to_cacheObject(await currentCacheFunction(params)));
|
|
50
|
-
cacheUpdated = true;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
const currentCacheObject = load_cacheObject(currentCache);
|
|
54
|
-
const cache_data = get_cacheValue(currentCacheObject);
|
|
55
|
-
if (cacheUpdated && cache_data != null)
|
|
56
|
-
await set_cache(key, cache_data, params);
|
|
57
|
-
/* -------------------------------------------------------------------------- */
|
|
58
|
-
/* return */
|
|
59
|
-
/* -------------------------------------------------------------------------- */
|
|
60
|
-
if (!params.search)
|
|
61
|
-
return cache_data;
|
|
62
|
-
return searchResult(cache_data, params.search);
|
|
63
|
-
}
|
|
64
|
-
export async function set_cache(key, value, params) {
|
|
65
|
-
if (!params)
|
|
66
|
-
params = {};
|
|
67
|
-
key = glb.fixKey(key);
|
|
68
|
-
const storage_key = `${sname}-${key}`;
|
|
69
|
-
const currentCacheObjectStr = value != null ? JSON.stringify(convert_to_cacheObject(value)) : value;
|
|
70
|
-
if (!params.session && !params.storage && !params.local_storage) {
|
|
71
|
-
params.session = true;
|
|
72
|
-
}
|
|
73
|
-
await gstorage.set_var(storage_key, currentCacheObjectStr, {
|
|
74
|
-
local_storage: params.local_storage,
|
|
75
|
-
session: params.session,
|
|
76
|
-
storage: params.storage,
|
|
77
|
-
});
|
|
78
|
-
return value;
|
|
79
|
-
}
|
|
80
|
-
export async function delete_cache(key, params) {
|
|
81
|
-
return await set_cache(key, undefined, params);
|
|
82
|
-
}
|
|
83
|
-
/* -------------------------------------------------------------------------- */
|
|
84
|
-
/* -------------------------------------------------------------------------- */
|
|
85
|
-
/* -------------------------------------------------------------------------- */
|
|
86
|
-
export function set_cache_sync(key, value) {
|
|
87
|
-
if (value == null) {
|
|
88
|
-
return glb.Global_set(lname, key, value);
|
|
89
|
-
}
|
|
90
|
-
const currentCacheObjectStr = JSON.stringify(convert_to_cacheObject(value));
|
|
91
|
-
return glb.Global_set(lname, key, currentCacheObjectStr);
|
|
92
|
-
}
|
|
93
|
-
export function get_cache_sync(key, getterFunction, params) {
|
|
94
|
-
if (!params)
|
|
95
|
-
params = {};
|
|
96
|
-
key = glb.fixKey(key);
|
|
97
|
-
/* -------------------------------------------------------------------------- */
|
|
98
|
-
/* get the cache */
|
|
99
|
-
/* -------------------------------------------------------------------------- */
|
|
100
|
-
let currentCache = "";
|
|
101
|
-
let cacheUpdated = false;
|
|
102
|
-
currentCache = glb.Global_get(lname, key);
|
|
103
|
-
/* -------------------------------------------------------------------------- */
|
|
104
|
-
/* if cache not found use the cache func */
|
|
105
|
-
/* -------------------------------------------------------------------------- */
|
|
106
|
-
if (!currentCache) {
|
|
107
|
-
let currentCacheFunction = null;
|
|
108
|
-
if (typeof getterFunction === "function") {
|
|
109
|
-
currentCacheFunction = getterFunction;
|
|
110
|
-
}
|
|
111
|
-
else if (currentCacheFunction == null) {
|
|
112
|
-
currentCacheFunction = get_cacheFunc(key);
|
|
113
|
-
}
|
|
114
|
-
if (typeof currentCacheFunction === "function") {
|
|
115
|
-
currentCache = JSON.stringify(convert_to_cacheObject(currentCacheFunction(params)));
|
|
116
|
-
cacheUpdated = true;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
const currentCacheObject = load_cacheObject(currentCache);
|
|
120
|
-
const cache_data = get_cacheValue(currentCacheObject);
|
|
121
|
-
if (cacheUpdated && cache_data != null)
|
|
122
|
-
set_cache_sync(key, cache_data);
|
|
123
|
-
/* -------------------------------------------------------------------------- */
|
|
124
|
-
/* return */
|
|
125
|
-
/* -------------------------------------------------------------------------- */
|
|
126
|
-
if (!params.search)
|
|
127
|
-
return cache_data;
|
|
128
|
-
return searchResult(cache_data, params.search);
|
|
129
|
-
}
|
|
130
|
-
export async function delete_cache_sync(key) {
|
|
131
|
-
return await set_cache_sync(key, undefined);
|
|
132
|
-
}
|
|
133
|
-
export function get_cacheFunc(key) {
|
|
134
|
-
return glb.Global_get(lname_f, key);
|
|
135
|
-
}
|
|
136
|
-
export function set_cacheFunc(key, f) {
|
|
137
|
-
return glb.Global_set(lname_f, key, f);
|
|
138
|
-
}
|
|
139
|
-
/* -------------------------------------------------------------------------- */
|
|
140
|
-
function convert_to_cacheObject(data) {
|
|
141
|
-
const data_type = typeof data;
|
|
142
|
-
const data_str = stringify_cacheValue(data);
|
|
143
|
-
return { original_type: data_type, raw_data: data_str };
|
|
144
|
-
}
|
|
145
|
-
function load_cacheObject(data) {
|
|
146
|
-
if (data === null || data === undefined)
|
|
147
|
-
return null;
|
|
148
|
-
if (typeof data === "object") {
|
|
149
|
-
return {
|
|
150
|
-
original_type: data.original_type,
|
|
151
|
-
raw_data: data.raw_data,
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
else if (typeof data === "string") {
|
|
155
|
-
try {
|
|
156
|
-
return load_cacheObject(JSON.parse(data));
|
|
157
|
-
}
|
|
158
|
-
catch { }
|
|
159
|
-
}
|
|
160
|
-
return null;
|
|
161
|
-
}
|
|
162
|
-
function get_cacheValue(data) {
|
|
163
|
-
if (data === null || data === undefined)
|
|
164
|
-
return null;
|
|
165
|
-
if (typeof data === "object") {
|
|
166
|
-
const { original_type, raw_data } = data;
|
|
167
|
-
if (original_type === "string")
|
|
168
|
-
return raw_data;
|
|
169
|
-
else
|
|
170
|
-
return JSON.parse(raw_data);
|
|
171
|
-
}
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
function stringify_cacheValue(data) {
|
|
175
|
-
if (data == null)
|
|
176
|
-
return "";
|
|
177
|
-
return typeof data != "string" ? JSON.stringify(data) : data;
|
|
178
|
-
}
|
|
179
|
-
/* -------------------------------------------------------------------------- */
|
|
180
|
-
function searchResult(value, search) {
|
|
181
|
-
if (typeof value != "object" || typeof search != "object")
|
|
182
|
-
return value; //cant search in non objects
|
|
183
|
-
if (value == null)
|
|
184
|
-
return value;
|
|
185
|
-
if (!isNaN(search._per_page) && search._per_page <= 0)
|
|
186
|
-
return null;
|
|
187
|
-
let fvalue = [];
|
|
188
|
-
if (Array.isArray(value)) {
|
|
189
|
-
for (let index = 0; index < value.length; index++) {
|
|
190
|
-
const vElem = gMatch(value[index], search);
|
|
191
|
-
if (vElem)
|
|
192
|
-
fvalue.push(vElem);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
const vElem = gMatch(value, search);
|
|
197
|
-
if (vElem)
|
|
198
|
-
return vElem;
|
|
199
|
-
}
|
|
200
|
-
if (!isNaN(search._per_page))
|
|
201
|
-
fvalue = fvalue.slice(0, Number(search._per_page));
|
|
202
|
-
return fvalue;
|
|
203
|
-
}
|
|
204
|
-
function gMatch(object, search) {
|
|
205
|
-
if (typeof object != "object" || typeof search != "object")
|
|
206
|
-
return object; //cant search in non objects
|
|
207
|
-
let isFullMatch = true;
|
|
208
|
-
for (const key in search) {
|
|
209
|
-
if (!key || key.startsWith("_"))
|
|
210
|
-
continue;
|
|
211
|
-
if (Object.hasOwnProperty.call(search, key) &&
|
|
212
|
-
Object.hasOwnProperty.call(object, key)) {
|
|
213
|
-
let isMatch = false;
|
|
214
|
-
const searchValue = search[key];
|
|
215
|
-
const objectValue = object[key];
|
|
216
|
-
if (objectValue === searchValue)
|
|
217
|
-
continue;
|
|
218
|
-
if (!isNaN(objectValue) && !isNaN(searchValue)) {
|
|
219
|
-
isMatch = false;
|
|
220
|
-
isFullMatch = false;
|
|
221
|
-
break;
|
|
222
|
-
}
|
|
223
|
-
let searchValueStr = String(searchValue);
|
|
224
|
-
if (searchValueStr.startsWith("!")) {
|
|
225
|
-
searchValueStr = searchValueStr.substr(1);
|
|
226
|
-
isMatch =
|
|
227
|
-
String(objectValue).toLowerCase() ==
|
|
228
|
-
searchValueStr.toLowerCase();
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
isMatch = String(objectValue)
|
|
232
|
-
.toLowerCase()
|
|
233
|
-
.includes(String(searchValueStr).toLowerCase());
|
|
234
|
-
}
|
|
235
|
-
if (!isMatch) {
|
|
236
|
-
isFullMatch = false;
|
|
237
|
-
break;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
if (isFullMatch)
|
|
242
|
-
return object;
|
|
243
|
-
return null;
|
|
244
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.delete_cache=delete_cache,exports.delete_cache_sync=delete_cache_sync,exports.get_cache=get_cache,exports.get_cacheFunc=get_cacheFunc,exports.get_cache_sync=get_cache_sync,exports.set_cache=set_cache,exports.set_cacheFunc=set_cacheFunc,exports.set_cache_sync=set_cache_sync;var _core=_interopRequireDefault(require("../core")),_index=require("../../index");function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _regeneratorRuntime(){"use strict";/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */function a(a,b,c){return Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}),a[b]}function b(a,b,c,e){var f=b&&b.prototype instanceof d?b:d,g=Object.create(f.prototype),h=new m(e||[]);return s(g,"_invoke",{value:i(a,c,h)}),g}function c(a,b,c){try{return{type:"normal",arg:a.call(b,c)}}catch(a){return{type:"throw",arg:a}}}function d(){}function e(){}function f(){}function g(b){["next","throw","return"].forEach(function(c){a(b,c,function(a){return this._invoke(c,a)})})}function h(a,b){function d(e,f,g,h){var i=c(a[e],a,f);if("throw"!==i.type){var j=i.arg,k=j.value;return k&&"object"==_typeof(k)&&r.call(k,"__await")?b.resolve(k.__await).then(function(a){d("next",a,g,h)},function(a){d("throw",a,g,h)}):b.resolve(k).then(function(a){j.value=a,g(j)},function(a){return d("throw",a,g,h)})}h(i.arg)}var e;s(this,"_invoke",{value:function value(a,c){function f(){return new b(function(b,e){d(a,c,b,e)})}return e=e?e.then(f,f):f()}})}function i(a,b,d){var e="suspendedStart";return function(f,g){if("executing"==e)throw new Error("Generator is already running");if("completed"==e){if("throw"===f)throw g;return o()}for(d.method=f,d.arg=g;;){var h=d.delegate;if(h){var i=j(h,d);if(i){if(i===x)continue;return i}}if("next"===d.method)d.sent=d._sent=d.arg;else if("throw"===d.method){if("suspendedStart"==e)throw e="completed",d.arg;d.dispatchException(d.arg)}else"return"===d.method&&d.abrupt("return",d.arg);e="executing";var k=c(a,b,d);if("normal"===k.type){if(e=d.done?"completed":"suspendedYield",k.arg===x)continue;return{value:k.arg,done:d.done}}"throw"===k.type&&(e="completed",d.method="throw",d.arg=k.arg)}}}function j(a,b){var d=b.method,e=a.iterator[d];if(void 0===e)return b.delegate=null,"throw"===d&&a.iterator["return"]&&(b.method="return",b.arg=void 0,j(a,b),"throw"===b.method)||"return"!==d&&(b.method="throw",b.arg=new TypeError("The iterator does not provide a '"+d+"' method")),x;var f=c(e,a.iterator,b.arg);if("throw"===f.type)return b.method="throw",b.arg=f.arg,b.delegate=null,x;var g=f.arg;return g?g.done?(b[a.resultName]=g.value,b.next=a.nextLoc,"return"!==b.method&&(b.method="next",b.arg=void 0),b.delegate=null,x):g:(b.method="throw",b.arg=new TypeError("iterator result is not an object"),b.delegate=null,x)}function k(a){var b={tryLoc:a[0]};1 in a&&(b.catchLoc=a[1]),2 in a&&(b.finallyLoc=a[2],b.afterLoc=a[3]),this.tryEntries.push(b)}function l(a){var b=a.completion||{};b.type="normal",delete b.arg,a.completion=b}function m(a){this.tryEntries=[{tryLoc:"root"}],a.forEach(k,this),this.reset(!0)}function n(a){if(a){var b=a[u];if(b)return b.call(a);if("function"==typeof a.next)return a;if(!isNaN(a.length)){var c=-1,d=function b(){for(;++c<a.length;)if(r.call(a,c))return b.value=a[c],b.done=!1,b;return b.value=void 0,b.done=!0,b};return d.next=d}}return{next:o}}function o(){return{value:void 0,done:!0}}_regeneratorRuntime=function(){return p};var p={},q=Object.prototype,r=q.hasOwnProperty,s=Object.defineProperty||function(a,b,c){a[b]=c.value},t="function"==typeof Symbol?Symbol:{},u=t.iterator||"@@iterator",v=t.asyncIterator||"@@asyncIterator",w=t.toStringTag||"@@toStringTag";try{a({},"")}catch(b){a=function(a,b,c){return a[b]=c}}p.wrap=b;var x={},y={};a(y,u,function(){return this});var z=Object.getPrototypeOf,A=z&&z(z(n([])));A&&A!==q&&r.call(A,u)&&(y=A);var B=f.prototype=d.prototype=Object.create(y);return e.prototype=f,s(B,"constructor",{value:f,configurable:!0}),s(f,"constructor",{value:e,configurable:!0}),e.displayName=a(f,w,"GeneratorFunction"),p.isGeneratorFunction=function(a){var b="function"==typeof a&&a.constructor;return!!b&&(b===e||"GeneratorFunction"===(b.displayName||b.name))},p.mark=function(b){return Object.setPrototypeOf?Object.setPrototypeOf(b,f):(b.__proto__=f,a(b,w,"GeneratorFunction")),b.prototype=Object.create(B),b},p.awrap=function(a){return{__await:a}},g(h.prototype),a(h.prototype,v,function(){return this}),p.AsyncIterator=h,p.async=function(a,c,d,e,f){void 0===f&&(f=Promise);var g=new h(b(a,c,d,e),f);return p.isGeneratorFunction(c)?g:g.next().then(function(a){return a.done?a.value:g.next()})},g(B),a(B,w,"Generator"),a(B,u,function(){return this}),a(B,"toString",function(){return"[object Generator]"}),p.keys=function(a){var b=Object(a),c=[];for(var d in b)c.push(d);return c.reverse(),function a(){for(;c.length;){var d=c.pop();if(d in b)return a.value=d,a.done=!1,a}return a.done=!0,a}},p.values=n,m.prototype={constructor:m,reset:function reset(a){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(l),!a)for(var b in this)"t"===b.charAt(0)&&r.call(this,b)&&!isNaN(+b.slice(1))&&(this[b]=void 0)},stop:function stop(){this.done=!0;var a=this.tryEntries[0].completion;if("throw"===a.type)throw a.arg;return this.rval},dispatchException:function dispatchException(a){function b(b,d){return f.type="throw",f.arg=a,c.next=b,d&&(c.method="next",c.arg=void 0),!!d}if(this.done)throw a;for(var c=this,d=this.tryEntries.length-1;0<=d;--d){var e=this.tryEntries[d],f=e.completion;if("root"===e.tryLoc)return b("end");if(e.tryLoc<=this.prev){var g=r.call(e,"catchLoc"),h=r.call(e,"finallyLoc");if(g&&h){if(this.prev<e.catchLoc)return b(e.catchLoc,!0);if(this.prev<e.finallyLoc)return b(e.finallyLoc)}else if(!g){if(!h)throw new Error("try statement without catch or finally");if(this.prev<e.finallyLoc)return b(e.finallyLoc)}else if(this.prev<e.catchLoc)return b(e.catchLoc,!0)}}},abrupt:function abrupt(a,b){for(var c,d=this.tryEntries.length-1;0<=d;--d)if(c=this.tryEntries[d],c.tryLoc<=this.prev&&r.call(c,"finallyLoc")&&this.prev<c.finallyLoc){var e=c;break}e&&("break"===a||"continue"===a)&&e.tryLoc<=b&&b<=e.finallyLoc&&(e=null);var f=e?e.completion:{};return f.type=a,f.arg=b,e?(this.method="next",this.next=e.finallyLoc,x):this.complete(f)},complete:function complete(a,b){if("throw"===a.type)throw a.arg;return"break"===a.type||"continue"===a.type?this.next=a.arg:"return"===a.type?(this.rval=this.arg=a.arg,this.method="return",this.next="end"):"normal"===a.type&&b&&(this.next=b),x},finish:function finish(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.finallyLoc===a)return this.complete(b.completion,b.afterLoc),l(b),x},catch:function _catch(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.tryLoc===a){var d=b.completion;if("throw"===d.type){var e=d.arg;l(b)}return e}throw new Error("illegal catch attempt")},delegateYield:function delegateYield(a,b,c){return this.delegate={iterator:n(a),resultName:b,nextLoc:c},"next"===this.method&&(this.arg=void 0),x}},p}function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function asyncGeneratorStep(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){return void c(a)}h.done?b(i):Promise.resolve(i).then(d,e)}function _asyncToGenerator(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){function f(a){asyncGeneratorStep(h,d,e,f,g,"next",a)}function g(a){asyncGeneratorStep(h,d,e,f,g,"throw",a)}var h=a.apply(b,c);f(void 0)})}}var sname="cache",name_pending="pending_cache_loads",lname="list_cache",lname_f="list_cache_func";function get_cache(){return _get_cache.apply(this,arguments)}function _get_cache(){return _get_cache=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function d(a,b,c){var e,f,g,h;return _regeneratorRuntime().wrap(function i(d){for(;1;)switch(d.prev=d.next){case 0:if(a=_core["default"].fixKey(a),e="cache-pending-".concat(a),f=_core["default"].Global_get(name_pending,e),!f){d.next=7;break}return d.next=6,f;case 6:return d.abrupt("return",d.sent);case 7:return g=_get_cache_local(a,b,c),_core["default"].Global_set(name_pending,e,g),d.next=11,g;case 11:return h=d.sent,_core["default"].Global_set(name_pending,e,void 0),d.abrupt("return",h);case 14:case"end":return d.stop();}},d)})),_get_cache.apply(this,arguments)}function _get_cache_local(a,b,c){return _get_cache_local2.apply(this,arguments)}function _get_cache_local2(){return _get_cache_local2=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function d(a,b,c){var e,f,g,h,i,j;return _regeneratorRuntime().wrap(function k(d){for(;1;)switch(d.prev=d.next){case 0:return c||(c={}),e="".concat(sname,"-").concat(a),f="",g=!1,c.session||c.storage||c.local_storage||(c.session=!0),d.next=7,_index.gstorage.get_var(e,{local_storage:c.local_storage,session:c.session,storage:c.storage});case 7:if(f=d.sent,f){d.next=20;break}if(h=null,"function"==typeof b?h=b:null==h&&(h=get_cacheFunc(a)),"function"!=typeof h){d.next=20;break}return d.t0=JSON,d.t1=convert_to_cacheObject,d.next=16,h(c);case 16:d.t2=d.sent,d.t3=(0,d.t1)(d.t2),f=d.t0.stringify.call(d.t0,d.t3),g=!0;case 20:if(i=load_cacheObject(f),j=get_cacheValue(i),!(g&&null!=j)){d.next=25;break}return d.next=25,set_cache(a,j,c);case 25:if(c.search){d.next=27;break}return d.abrupt("return",j);case 27:return d.abrupt("return",searchResult(j,c.search));case 28:case"end":return d.stop();}},d)})),_get_cache_local2.apply(this,arguments)}function set_cache(a,b,c){return _set_cache.apply(this,arguments)}function _set_cache(){return _set_cache=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function d(a,b,c){var e,f;return _regeneratorRuntime().wrap(function g(d){for(;1;)switch(d.prev=d.next){case 0:return c||(c={}),a=_core["default"].fixKey(a),e="".concat(sname,"-").concat(a),f=null==b?b:JSON.stringify(convert_to_cacheObject(b)),c.session||c.storage||c.local_storage||(c.session=!0),d.next=7,_index.gstorage.set_var(e,f,{local_storage:c.local_storage,session:c.session,storage:c.storage});case 7:return d.abrupt("return",b);case 8:case"end":return d.stop();}},d)})),_set_cache.apply(this,arguments)}function delete_cache(a,b){return _delete_cache.apply(this,arguments)}/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */function _delete_cache(){return _delete_cache=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function c(a,b){return _regeneratorRuntime().wrap(function d(c){for(;1;)switch(c.prev=c.next){case 0:return c.next=2,set_cache(a,void 0,b);case 2:return c.abrupt("return",c.sent);case 3:case"end":return c.stop();}},c)})),_delete_cache.apply(this,arguments)}function set_cache_sync(a,b){if(null==b)return _core["default"].Global_set(lname,a,b);var c=JSON.stringify(convert_to_cacheObject(b));return _core["default"].Global_set(lname,a,c)}function get_cache_sync(a,b,c){c||(c={}),a=_core["default"].fixKey(a);/* -------------------------------------------------------------------------- */ /* get the cache */ /* -------------------------------------------------------------------------- */var d="",e=!1;/* -------------------------------------------------------------------------- */ /* if cache not found use the cache func */ /* -------------------------------------------------------------------------- */if(d=_core["default"].Global_get(lname,a),!d){var f=null;"function"==typeof b?f=b:null==f&&(f=get_cacheFunc(a)),"function"==typeof f&&(d=JSON.stringify(convert_to_cacheObject(f(c))),e=!0)}var g=load_cacheObject(d),h=get_cacheValue(g);/* -------------------------------------------------------------------------- */ /* return */ /* -------------------------------------------------------------------------- */return e&&null!=h&&set_cache_sync(a,h),c.search?searchResult(h,c.search):h}function delete_cache_sync(a){return _delete_cache_sync.apply(this,arguments)}function _delete_cache_sync(){return _delete_cache_sync=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function b(a){return _regeneratorRuntime().wrap(function c(b){for(;1;)switch(b.prev=b.next){case 0:return b.next=2,set_cache_sync(a,void 0);case 2:return b.abrupt("return",b.sent);case 3:case"end":return b.stop();}},b)})),_delete_cache_sync.apply(this,arguments)}function get_cacheFunc(a){return _core["default"].Global_get(lname_f,a)}function set_cacheFunc(a,b){return _core["default"].Global_set(lname_f,a,b)}/* -------------------------------------------------------------------------- */function convert_to_cacheObject(a){var b=_typeof(a),c=stringify_cacheValue(a);return{original_type:b,raw_data:c}}function load_cacheObject(a){if(null===a||a===void 0)return null;if("object"===_typeof(a))return{original_type:a.original_type,raw_data:a.raw_data};if("string"==typeof a)try{return load_cacheObject(JSON.parse(a))}catch(a){}return null}function get_cacheValue(a){if(null===a||a===void 0)return null;if("object"===_typeof(a)){var b=a.original_type,c=a.raw_data;return"string"===b?c:JSON.parse(c)}return null}function stringify_cacheValue(a){return null==a?"":"string"==typeof a?a:JSON.stringify(a)}/* -------------------------------------------------------------------------- */function searchResult(a,b){if("object"!=_typeof(a)||"object"!=_typeof(b))return a;//cant search in non objects
|
|
2
|
+
if(null==a)return a;if(!isNaN(b._per_page)&&0>=b._per_page)return null;var c=[];if(Array.isArray(a))for(var d,e=0;e<a.length;e++)d=gMatch(a[e],b),d&&c.push(d);else{var f=gMatch(a,b);if(f)return f}return isNaN(b._per_page)||(c=c.slice(0,+b._per_page)),c}function gMatch(a,b){if("object"!=_typeof(a)||"object"!=_typeof(b))return a;//cant search in non objects
|
|
3
|
+
var c=!0;for(var d in b)if(d&&!d.startsWith("_")&&Object.hasOwnProperty.call(b,d)&&Object.hasOwnProperty.call(a,d)){var e=!1,f=b[d],g=a[d];if(g===f)continue;if(!isNaN(g)&&!isNaN(f)){e=!1,c=!1;break}var h=f+"";if(h.startsWith("!")?(h=h.substr(1),e=(g+"").toLowerCase()==h.toLowerCase()):e=(g+"").toLowerCase().includes((h+"").toLowerCase()),!e){c=!1;break}}return c?a:null}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";var _g_cache=require("./g_cache");Object.defineProperty(exports,"__esModule",{value:!0});Object.keys(_g_cache).forEach(function(a){"default"===a||"__esModule"===a||a in exports&&exports[a]===_g_cache[a]||Object.defineProperty(exports,a,{enumerable:!0,get:function get(){return _g_cache[a]}})});
|
|
@@ -1,91 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
static deus_globals;
|
|
3
|
-
static initGlobal() {
|
|
4
|
-
if (GlobalStorage == null)
|
|
5
|
-
return false;
|
|
6
|
-
if (GlobalStorage.deus_globals == undefined)
|
|
7
|
-
GlobalStorage.deus_globals = {};
|
|
8
|
-
}
|
|
9
|
-
/* -------------------------------------------------------------------------- */
|
|
10
|
-
static Global_set(type, key, value) {
|
|
11
|
-
GlobalStorage.loadGlobals(type);
|
|
12
|
-
if (key === true) {
|
|
13
|
-
if (value == null || value == undefined)
|
|
14
|
-
delete GlobalStorage.deus_globals[type];
|
|
15
|
-
else
|
|
16
|
-
GlobalStorage.deus_globals[type] = value;
|
|
17
|
-
GlobalStorage.deus_globals[type] = value;
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
key = GlobalStorage.fixKey(key);
|
|
21
|
-
if (value == null || value == undefined)
|
|
22
|
-
delete GlobalStorage.deus_globals[type][key];
|
|
23
|
-
else
|
|
24
|
-
GlobalStorage.deus_globals[type][key] = value;
|
|
25
|
-
}
|
|
26
|
-
return value;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=exports.GlobalStorage=void 0;function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,_toPropertyKey(c.key),c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),a}function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"===_typeof(b)?b:b+""}function _toPrimitive(a,b){if("object"!==_typeof(a)||null===a)return a;var c=a[Symbol.toPrimitive];if(c!==void 0){var d=c.call(a,b||"default");if("object"!==_typeof(d))return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}var GlobalStorage=/*#__PURE__*/function(){function a(){_classCallCheck(this,a)}return _createClass(a,null,[{key:"initGlobal",value:function initGlobal(){return null!=a&&void(null==a.deus_globals&&(a.deus_globals={}))}/* -------------------------------------------------------------------------- */},{key:"Global_set",value:function Global_set(b,c,d){return a.loadGlobals(b),!0===c?(null==d||null==d?delete a.deus_globals[b]:a.deus_globals[b]=d,a.deus_globals[b]=d):(c=a.fixKey(c),null==d||null==d?delete a.deus_globals[b][c]:a.deus_globals[b][c]=d),d}/**
|
|
29
2
|
*
|
|
30
3
|
* @param type
|
|
31
4
|
* @param key
|
|
32
5
|
* @param value
|
|
33
6
|
* @returns total number of elements in targeted glb array
|
|
34
|
-
*/
|
|
35
|
-
static Global_add(type, key, value) {
|
|
36
|
-
if (typeof key !== "string") {
|
|
37
|
-
throw new Error("Key was not a string");
|
|
38
|
-
}
|
|
39
|
-
key = GlobalStorage.fixKey(key);
|
|
40
|
-
GlobalStorage.loadGlobals(type);
|
|
41
|
-
var cval = GlobalStorage.deus_globals[type][key];
|
|
42
|
-
if (cval == null || !Array.isArray(cval)) {
|
|
43
|
-
if (cval == null) {
|
|
44
|
-
cval = [];
|
|
45
|
-
}
|
|
46
|
-
else
|
|
47
|
-
cval = [cval];
|
|
48
|
-
}
|
|
49
|
-
cval.push(value);
|
|
50
|
-
GlobalStorage.Global_set(type, key, cval);
|
|
51
|
-
return cval.length;
|
|
52
|
-
}
|
|
53
|
-
static Global_remove(type, key, value) {
|
|
54
|
-
if (typeof key !== "string") {
|
|
55
|
-
throw new Error("Key was not a string");
|
|
56
|
-
}
|
|
57
|
-
GlobalStorage.loadGlobals(type);
|
|
58
|
-
key = GlobalStorage.fixKey(key);
|
|
59
|
-
var cval = GlobalStorage.deus_globals[type][key];
|
|
60
|
-
if (cval == null)
|
|
61
|
-
cval = [];
|
|
62
|
-
if (!Array.isArray(cval)) {
|
|
63
|
-
console.warn(`Targeted global was not array ${key}`);
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
let newValue = cval.filter((s) => s !== value);
|
|
67
|
-
return GlobalStorage.Global_set(type, key, newValue);
|
|
68
|
-
}
|
|
69
|
-
static Global_get(type, key) {
|
|
70
|
-
if (!GlobalStorage.deus_globals)
|
|
71
|
-
return undefined;
|
|
72
|
-
if (typeof key === "boolean")
|
|
73
|
-
return GlobalStorage.deus_globals[type];
|
|
74
|
-
key = GlobalStorage.fixKey(key);
|
|
75
|
-
return GlobalStorage.deus_globals[type]?.[key];
|
|
76
|
-
}
|
|
77
|
-
static fixKey(key) {
|
|
78
|
-
if (typeof key === "boolean")
|
|
79
|
-
return key;
|
|
80
|
-
return String(Array.isArray(key) ? key.join("-") : key)
|
|
81
|
-
.toLowerCase()
|
|
82
|
-
.replace(" ", "_");
|
|
83
|
-
}
|
|
84
|
-
static loadGlobals(type) {
|
|
85
|
-
if (GlobalStorage.deus_globals == undefined)
|
|
86
|
-
GlobalStorage.deus_globals = {};
|
|
87
|
-
if (GlobalStorage.deus_globals[type] == undefined)
|
|
88
|
-
GlobalStorage.deus_globals[type] = {};
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
export default GlobalStorage;
|
|
7
|
+
*/},{key:"Global_add",value:function Global_add(b,c,d){if("string"!=typeof c)throw new Error("Key was not a string");c=a.fixKey(c),a.loadGlobals(b);var e=a.deus_globals[b][c];return null!=e&&Array.isArray(e)||(null==e?e=[]:e=[e]),e.push(d),a.Global_set(b,c,e),e.length}},{key:"Global_remove",value:function Global_remove(b,c,d){if("string"!=typeof c)throw new Error("Key was not a string");a.loadGlobals(b),c=a.fixKey(c);var e=a.deus_globals[b][c];if(null==e&&(e=[]),!Array.isArray(e))return console.warn("Targeted global was not array ".concat(c)),!1;var f=e.filter(function(a){return a!==d});return a.Global_set(b,c,f)}},{key:"Global_get",value:function Global_get(b,c){var d;if(a.deus_globals)return"boolean"==typeof c?a.deus_globals[b]:(c=a.fixKey(c),null===(d=a.deus_globals[b])||void 0===d?void 0:d[c])}},{key:"fixKey",value:function fixKey(a){return"boolean"==typeof a?a:((Array.isArray(a)?a.join("-"):a)+"").toLowerCase().replace(" ","_")}},{key:"loadGlobals",value:function loadGlobals(b){null==a.deus_globals&&(a.deus_globals={}),null==a.deus_globals[b]&&(a.deus_globals[b]={})}}]),a}();exports.GlobalStorage=GlobalStorage,_defineProperty(GlobalStorage,"deus_globals",void 0);var _default=GlobalStorage;exports["default"]=_default;
|
|
@@ -1,84 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
import glb from "../core";
|
|
3
|
-
/* -------------------------------------------------------------------------- */
|
|
4
|
-
/* Filters */
|
|
5
|
-
/* -------------------------------------------------------------------------- */
|
|
6
|
-
const lname_filter = "list_filter";
|
|
7
|
-
/**
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.add_filter=add_filter,exports.apply_filter=apply_filter,exports.apply_filter_sync=apply_filter_sync,exports.clear_all_filters=clear_all_filters,exports.clear_filter=clear_filter,exports.hold_add_filter=hold_add_filter,exports.remove_filter=remove_filter;var _react=_interopRequireDefault(require("react")),_core=_interopRequireDefault(require("../core"));function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _regeneratorRuntime(){"use strict";/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */function a(a,b,c){return Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}),a[b]}function b(a,b,c,e){var f=b&&b.prototype instanceof d?b:d,g=Object.create(f.prototype),h=new m(e||[]);return s(g,"_invoke",{value:i(a,c,h)}),g}function c(a,b,c){try{return{type:"normal",arg:a.call(b,c)}}catch(a){return{type:"throw",arg:a}}}function d(){}function e(){}function f(){}function g(b){["next","throw","return"].forEach(function(c){a(b,c,function(a){return this._invoke(c,a)})})}function h(a,b){function d(e,f,g,h){var i=c(a[e],a,f);if("throw"!==i.type){var j=i.arg,k=j.value;return k&&"object"==_typeof(k)&&r.call(k,"__await")?b.resolve(k.__await).then(function(a){d("next",a,g,h)},function(a){d("throw",a,g,h)}):b.resolve(k).then(function(a){j.value=a,g(j)},function(a){return d("throw",a,g,h)})}h(i.arg)}var e;s(this,"_invoke",{value:function value(a,c){function f(){return new b(function(b,e){d(a,c,b,e)})}return e=e?e.then(f,f):f()}})}function i(a,b,d){var e="suspendedStart";return function(f,g){if("executing"==e)throw new Error("Generator is already running");if("completed"==e){if("throw"===f)throw g;return o()}for(d.method=f,d.arg=g;;){var h=d.delegate;if(h){var i=j(h,d);if(i){if(i===x)continue;return i}}if("next"===d.method)d.sent=d._sent=d.arg;else if("throw"===d.method){if("suspendedStart"==e)throw e="completed",d.arg;d.dispatchException(d.arg)}else"return"===d.method&&d.abrupt("return",d.arg);e="executing";var k=c(a,b,d);if("normal"===k.type){if(e=d.done?"completed":"suspendedYield",k.arg===x)continue;return{value:k.arg,done:d.done}}"throw"===k.type&&(e="completed",d.method="throw",d.arg=k.arg)}}}function j(a,b){var d=b.method,e=a.iterator[d];if(void 0===e)return b.delegate=null,"throw"===d&&a.iterator["return"]&&(b.method="return",b.arg=void 0,j(a,b),"throw"===b.method)||"return"!==d&&(b.method="throw",b.arg=new TypeError("The iterator does not provide a '"+d+"' method")),x;var f=c(e,a.iterator,b.arg);if("throw"===f.type)return b.method="throw",b.arg=f.arg,b.delegate=null,x;var g=f.arg;return g?g.done?(b[a.resultName]=g.value,b.next=a.nextLoc,"return"!==b.method&&(b.method="next",b.arg=void 0),b.delegate=null,x):g:(b.method="throw",b.arg=new TypeError("iterator result is not an object"),b.delegate=null,x)}function k(a){var b={tryLoc:a[0]};1 in a&&(b.catchLoc=a[1]),2 in a&&(b.finallyLoc=a[2],b.afterLoc=a[3]),this.tryEntries.push(b)}function l(a){var b=a.completion||{};b.type="normal",delete b.arg,a.completion=b}function m(a){this.tryEntries=[{tryLoc:"root"}],a.forEach(k,this),this.reset(!0)}function n(a){if(a){var b=a[u];if(b)return b.call(a);if("function"==typeof a.next)return a;if(!isNaN(a.length)){var c=-1,d=function b(){for(;++c<a.length;)if(r.call(a,c))return b.value=a[c],b.done=!1,b;return b.value=void 0,b.done=!0,b};return d.next=d}}return{next:o}}function o(){return{value:void 0,done:!0}}_regeneratorRuntime=function(){return p};var p={},q=Object.prototype,r=q.hasOwnProperty,s=Object.defineProperty||function(a,b,c){a[b]=c.value},t="function"==typeof Symbol?Symbol:{},u=t.iterator||"@@iterator",v=t.asyncIterator||"@@asyncIterator",w=t.toStringTag||"@@toStringTag";try{a({},"")}catch(b){a=function(a,b,c){return a[b]=c}}p.wrap=b;var x={},y={};a(y,u,function(){return this});var z=Object.getPrototypeOf,A=z&&z(z(n([])));A&&A!==q&&r.call(A,u)&&(y=A);var B=f.prototype=d.prototype=Object.create(y);return e.prototype=f,s(B,"constructor",{value:f,configurable:!0}),s(f,"constructor",{value:e,configurable:!0}),e.displayName=a(f,w,"GeneratorFunction"),p.isGeneratorFunction=function(a){var b="function"==typeof a&&a.constructor;return!!b&&(b===e||"GeneratorFunction"===(b.displayName||b.name))},p.mark=function(b){return Object.setPrototypeOf?Object.setPrototypeOf(b,f):(b.__proto__=f,a(b,w,"GeneratorFunction")),b.prototype=Object.create(B),b},p.awrap=function(a){return{__await:a}},g(h.prototype),a(h.prototype,v,function(){return this}),p.AsyncIterator=h,p.async=function(a,c,d,e,f){void 0===f&&(f=Promise);var g=new h(b(a,c,d,e),f);return p.isGeneratorFunction(c)?g:g.next().then(function(a){return a.done?a.value:g.next()})},g(B),a(B,w,"Generator"),a(B,u,function(){return this}),a(B,"toString",function(){return"[object Generator]"}),p.keys=function(a){var b=Object(a),c=[];for(var d in b)c.push(d);return c.reverse(),function a(){for(;c.length;){var d=c.pop();if(d in b)return a.value=d,a.done=!1,a}return a.done=!0,a}},p.values=n,m.prototype={constructor:m,reset:function reset(a){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(l),!a)for(var b in this)"t"===b.charAt(0)&&r.call(this,b)&&!isNaN(+b.slice(1))&&(this[b]=void 0)},stop:function stop(){this.done=!0;var a=this.tryEntries[0].completion;if("throw"===a.type)throw a.arg;return this.rval},dispatchException:function dispatchException(a){function b(b,d){return f.type="throw",f.arg=a,c.next=b,d&&(c.method="next",c.arg=void 0),!!d}if(this.done)throw a;for(var c=this,d=this.tryEntries.length-1;0<=d;--d){var e=this.tryEntries[d],f=e.completion;if("root"===e.tryLoc)return b("end");if(e.tryLoc<=this.prev){var g=r.call(e,"catchLoc"),h=r.call(e,"finallyLoc");if(g&&h){if(this.prev<e.catchLoc)return b(e.catchLoc,!0);if(this.prev<e.finallyLoc)return b(e.finallyLoc)}else if(!g){if(!h)throw new Error("try statement without catch or finally");if(this.prev<e.finallyLoc)return b(e.finallyLoc)}else if(this.prev<e.catchLoc)return b(e.catchLoc,!0)}}},abrupt:function abrupt(a,b){for(var c,d=this.tryEntries.length-1;0<=d;--d)if(c=this.tryEntries[d],c.tryLoc<=this.prev&&r.call(c,"finallyLoc")&&this.prev<c.finallyLoc){var e=c;break}e&&("break"===a||"continue"===a)&&e.tryLoc<=b&&b<=e.finallyLoc&&(e=null);var f=e?e.completion:{};return f.type=a,f.arg=b,e?(this.method="next",this.next=e.finallyLoc,x):this.complete(f)},complete:function complete(a,b){if("throw"===a.type)throw a.arg;return"break"===a.type||"continue"===a.type?this.next=a.arg:"return"===a.type?(this.rval=this.arg=a.arg,this.method="return",this.next="end"):"normal"===a.type&&b&&(this.next=b),x},finish:function finish(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.finallyLoc===a)return this.complete(b.completion,b.afterLoc),l(b),x},catch:function _catch(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.tryLoc===a){var d=b.completion;if("throw"===d.type){var e=d.arg;l(b)}return e}throw new Error("illegal catch attempt")},delegateYield:function delegateYield(a,b,c){return this.delegate={iterator:n(a),resultName:b,nextLoc:c},"next"===this.method&&(this.arg=void 0),x}},p}function asyncGeneratorStep(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){return void c(a)}h.done?b(i):Promise.resolve(i).then(d,e)}function _asyncToGenerator(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){function f(a){asyncGeneratorStep(h,d,e,f,g,"next",a)}function g(a){asyncGeneratorStep(h,d,e,f,g,"throw",a)}var h=a.apply(b,c);f(void 0)})}}/* -------------------------------------------------------------------------- */ /* Filters */ /* -------------------------------------------------------------------------- */var lname_filter="list_filter";/**
|
|
8
2
|
* Adds a filter
|
|
9
3
|
* @param key
|
|
10
4
|
* @param action action of the filter
|
|
11
5
|
* @param priority filters with lower priority are executed first
|
|
12
6
|
* @returns
|
|
13
|
-
*/
|
|
14
|
-
export function add_filter(key, action, priority = 10) {
|
|
15
|
-
var fobject = { key: key, action: action, priority: priority };
|
|
16
|
-
return glb.Global_add(lname_filter, key, fobject);
|
|
17
|
-
}
|
|
18
|
-
export function remove_filter(key, action) {
|
|
19
|
-
return glb.Global_remove(lname_filter, key, action);
|
|
20
|
-
}
|
|
21
|
-
export function clear_filter(key) {
|
|
22
|
-
return glb.Global_set(lname_filter, key, null);
|
|
23
|
-
}
|
|
24
|
-
export function clear_all_filters() {
|
|
25
|
-
return glb.Global_set(lname_filter, true, null);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
7
|
+
*/function add_filter(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:10;return _core["default"].Global_add(lname_filter,a,{key:a,action:b,priority:c})}function remove_filter(a,b){return _core["default"].Global_remove(lname_filter,a,b)}function clear_filter(a){return _core["default"].Global_set(lname_filter,a,null)}function clear_all_filters(){return _core["default"].Global_set(lname_filter,!0,null)}/**
|
|
28
8
|
* Apply a filter asynchronously
|
|
29
9
|
* @param key
|
|
30
10
|
* @param initialValue
|
|
31
11
|
* @returns
|
|
32
|
-
*/
|
|
33
|
-
export async function apply_filter(key, initialValue = null) {
|
|
34
|
-
var filters = glb.Global_get(lname_filter, key);
|
|
35
|
-
if (!Array.isArray(filters) || filters.length == 0)
|
|
36
|
-
return initialValue;
|
|
37
|
-
filters.sort((a, b) => a.priority > b.priority ? 1 : -1); /* lower priority gets executed first */
|
|
38
|
-
let previous_value = initialValue;
|
|
39
|
-
for (let index = 0; index < filters.length; index++) {
|
|
40
|
-
const m_filter = filters[index];
|
|
41
|
-
let new_value = await m_filter.action(previous_value);
|
|
42
|
-
//console.log("filtered ", previous_value, " --> ", new_value);
|
|
43
|
-
previous_value = new_value;
|
|
44
|
-
}
|
|
45
|
-
return previous_value;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
12
|
+
*/function apply_filter(){return _apply_filter.apply(this,arguments)}/**
|
|
48
13
|
* Apply a filter synchronously
|
|
49
14
|
* @param key
|
|
50
15
|
* @param initialValue
|
|
51
16
|
* @returns
|
|
52
|
-
*/
|
|
53
|
-
export function apply_filter_sync(key, initialValue = null) {
|
|
54
|
-
var filters = glb.Global_get(lname_filter, key);
|
|
55
|
-
if (!Array.isArray(filters) || filters.length == 0)
|
|
56
|
-
return initialValue;
|
|
57
|
-
filters.sort((a, b) => a.priority > b.priority ? 1 : -1); /* lower priority gets executed first */
|
|
58
|
-
let previous_value = initialValue;
|
|
59
|
-
for (let index = 0; index < filters.length; index++) {
|
|
60
|
-
const m_filter = filters[index];
|
|
61
|
-
let new_value = m_filter.action(previous_value);
|
|
62
|
-
//console.log("filtered ", previous_value, " --> ", new_value);
|
|
63
|
-
if (new_value !== undefined)
|
|
64
|
-
previous_value = new_value;
|
|
65
|
-
}
|
|
66
|
-
return previous_value;
|
|
67
|
-
}
|
|
68
|
-
/* -------------------------------------------------------------------------- */
|
|
69
|
-
/**
|
|
17
|
+
*/function _apply_filter(){return _apply_filter=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function b(a){var c,d,e,f,g,h,i=arguments;return _regeneratorRuntime().wrap(function j(b){for(;1;)switch(b.prev=b.next){case 0:if(c=1<i.length&&void 0!==i[1]?i[1]:null,d=_core["default"].Global_get(lname_filter,a),Array.isArray(d)&&0!=d.length){b.next=4;break}return b.abrupt("return",c);case 4:d.sort(function(c,a){return c.priority>a.priority?1:-1}),e=c,f=0;case 7:if(!(f<d.length)){b.next=16;break}return g=d[f],b.next=11,g.action(e);case 11:h=b.sent,e=h;case 13:f++,b.next=7;break;case 16:return b.abrupt("return",e);case 17:case"end":return b.stop();}},b)})),_apply_filter.apply(this,arguments)}function apply_filter_sync(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:null,c=_core["default"].Global_get(lname_filter,a);if(!Array.isArray(c)||0==c.length)return b;c.sort(function(c,a){return c.priority>a.priority?1:-1});for(var d=b,e=0;e<c.length;e++){var f=c[e],g=f.action(d);g!==void 0&&(d=g)}return d}/* -------------------------------------------------------------------------- */ /**
|
|
70
18
|
* Adds a filter until the current component unmounts
|
|
71
19
|
* @param key
|
|
72
20
|
* @param action
|
|
73
21
|
* @param priority
|
|
74
22
|
* @returns
|
|
75
|
-
*/
|
|
76
|
-
export function hold_add_filter(key, action, priority = 10) {
|
|
77
|
-
const filterFunction = React.useCallback(action, []);
|
|
78
|
-
React.useEffect(() => {
|
|
79
|
-
add_filter(key, filterFunction, priority);
|
|
80
|
-
return () => {
|
|
81
|
-
remove_filter(key, filterFunction);
|
|
82
|
-
};
|
|
83
|
-
}, []);
|
|
84
|
-
}
|
|
23
|
+
*/function hold_add_filter(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:10,d=_react["default"].useCallback(b,[]);_react["default"].useEffect(function(){return add_filter(a,d,c),function(){remove_filter(a,d)}},[])}
|
|
@@ -1,154 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
import glb from "../core";
|
|
3
|
-
const lname = "list_func";
|
|
4
|
-
/* -------------------------------------------------------------------------- */
|
|
5
|
-
export function get_action(key) {
|
|
6
|
-
const res = glb.Global_get(lname, key);
|
|
7
|
-
return Array.isArray(res) || typeof res === "function" ? res : null;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.add_action=add_action,exports.get_action=get_action,exports.hold_add_action=hold_add_action,exports.hold_set_action=hold_set_action,exports.remove_action=remove_action,exports.run_action=run_action,exports.run_action_clear=run_action_clear,exports.run_action_sync=run_action_sync,exports.set_action=set_action;var _react=_interopRequireDefault(require("react")),_core=_interopRequireDefault(require("../core"));function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _regeneratorRuntime(){"use strict";/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */function a(a,b,c){return Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}),a[b]}function b(a,b,c,e){var f=b&&b.prototype instanceof d?b:d,g=Object.create(f.prototype),h=new m(e||[]);return s(g,"_invoke",{value:i(a,c,h)}),g}function c(a,b,c){try{return{type:"normal",arg:a.call(b,c)}}catch(a){return{type:"throw",arg:a}}}function d(){}function e(){}function f(){}function g(b){["next","throw","return"].forEach(function(c){a(b,c,function(a){return this._invoke(c,a)})})}function h(a,b){function d(e,f,g,h){var i=c(a[e],a,f);if("throw"!==i.type){var j=i.arg,k=j.value;return k&&"object"==_typeof(k)&&r.call(k,"__await")?b.resolve(k.__await).then(function(a){d("next",a,g,h)},function(a){d("throw",a,g,h)}):b.resolve(k).then(function(a){j.value=a,g(j)},function(a){return d("throw",a,g,h)})}h(i.arg)}var e;s(this,"_invoke",{value:function value(a,c){function f(){return new b(function(b,e){d(a,c,b,e)})}return e=e?e.then(f,f):f()}})}function i(a,b,d){var e="suspendedStart";return function(f,g){if("executing"==e)throw new Error("Generator is already running");if("completed"==e){if("throw"===f)throw g;return o()}for(d.method=f,d.arg=g;;){var h=d.delegate;if(h){var i=j(h,d);if(i){if(i===x)continue;return i}}if("next"===d.method)d.sent=d._sent=d.arg;else if("throw"===d.method){if("suspendedStart"==e)throw e="completed",d.arg;d.dispatchException(d.arg)}else"return"===d.method&&d.abrupt("return",d.arg);e="executing";var k=c(a,b,d);if("normal"===k.type){if(e=d.done?"completed":"suspendedYield",k.arg===x)continue;return{value:k.arg,done:d.done}}"throw"===k.type&&(e="completed",d.method="throw",d.arg=k.arg)}}}function j(a,b){var d=b.method,e=a.iterator[d];if(void 0===e)return b.delegate=null,"throw"===d&&a.iterator["return"]&&(b.method="return",b.arg=void 0,j(a,b),"throw"===b.method)||"return"!==d&&(b.method="throw",b.arg=new TypeError("The iterator does not provide a '"+d+"' method")),x;var f=c(e,a.iterator,b.arg);if("throw"===f.type)return b.method="throw",b.arg=f.arg,b.delegate=null,x;var g=f.arg;return g?g.done?(b[a.resultName]=g.value,b.next=a.nextLoc,"return"!==b.method&&(b.method="next",b.arg=void 0),b.delegate=null,x):g:(b.method="throw",b.arg=new TypeError("iterator result is not an object"),b.delegate=null,x)}function k(a){var b={tryLoc:a[0]};1 in a&&(b.catchLoc=a[1]),2 in a&&(b.finallyLoc=a[2],b.afterLoc=a[3]),this.tryEntries.push(b)}function l(a){var b=a.completion||{};b.type="normal",delete b.arg,a.completion=b}function m(a){this.tryEntries=[{tryLoc:"root"}],a.forEach(k,this),this.reset(!0)}function n(a){if(a){var b=a[u];if(b)return b.call(a);if("function"==typeof a.next)return a;if(!isNaN(a.length)){var c=-1,d=function b(){for(;++c<a.length;)if(r.call(a,c))return b.value=a[c],b.done=!1,b;return b.value=void 0,b.done=!0,b};return d.next=d}}return{next:o}}function o(){return{value:void 0,done:!0}}_regeneratorRuntime=function(){return p};var p={},q=Object.prototype,r=q.hasOwnProperty,s=Object.defineProperty||function(a,b,c){a[b]=c.value},t="function"==typeof Symbol?Symbol:{},u=t.iterator||"@@iterator",v=t.asyncIterator||"@@asyncIterator",w=t.toStringTag||"@@toStringTag";try{a({},"")}catch(b){a=function(a,b,c){return a[b]=c}}p.wrap=b;var x={},y={};a(y,u,function(){return this});var z=Object.getPrototypeOf,A=z&&z(z(n([])));A&&A!==q&&r.call(A,u)&&(y=A);var B=f.prototype=d.prototype=Object.create(y);return e.prototype=f,s(B,"constructor",{value:f,configurable:!0}),s(f,"constructor",{value:e,configurable:!0}),e.displayName=a(f,w,"GeneratorFunction"),p.isGeneratorFunction=function(a){var b="function"==typeof a&&a.constructor;return!!b&&(b===e||"GeneratorFunction"===(b.displayName||b.name))},p.mark=function(b){return Object.setPrototypeOf?Object.setPrototypeOf(b,f):(b.__proto__=f,a(b,w,"GeneratorFunction")),b.prototype=Object.create(B),b},p.awrap=function(a){return{__await:a}},g(h.prototype),a(h.prototype,v,function(){return this}),p.AsyncIterator=h,p.async=function(a,c,d,e,f){void 0===f&&(f=Promise);var g=new h(b(a,c,d,e),f);return p.isGeneratorFunction(c)?g:g.next().then(function(a){return a.done?a.value:g.next()})},g(B),a(B,w,"Generator"),a(B,u,function(){return this}),a(B,"toString",function(){return"[object Generator]"}),p.keys=function(a){var b=Object(a),c=[];for(var d in b)c.push(d);return c.reverse(),function a(){for(;c.length;){var d=c.pop();if(d in b)return a.value=d,a.done=!1,a}return a.done=!0,a}},p.values=n,m.prototype={constructor:m,reset:function reset(a){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(l),!a)for(var b in this)"t"===b.charAt(0)&&r.call(this,b)&&!isNaN(+b.slice(1))&&(this[b]=void 0)},stop:function stop(){this.done=!0;var a=this.tryEntries[0].completion;if("throw"===a.type)throw a.arg;return this.rval},dispatchException:function dispatchException(a){function b(b,d){return f.type="throw",f.arg=a,c.next=b,d&&(c.method="next",c.arg=void 0),!!d}if(this.done)throw a;for(var c=this,d=this.tryEntries.length-1;0<=d;--d){var e=this.tryEntries[d],f=e.completion;if("root"===e.tryLoc)return b("end");if(e.tryLoc<=this.prev){var g=r.call(e,"catchLoc"),h=r.call(e,"finallyLoc");if(g&&h){if(this.prev<e.catchLoc)return b(e.catchLoc,!0);if(this.prev<e.finallyLoc)return b(e.finallyLoc)}else if(!g){if(!h)throw new Error("try statement without catch or finally");if(this.prev<e.finallyLoc)return b(e.finallyLoc)}else if(this.prev<e.catchLoc)return b(e.catchLoc,!0)}}},abrupt:function abrupt(a,b){for(var c,d=this.tryEntries.length-1;0<=d;--d)if(c=this.tryEntries[d],c.tryLoc<=this.prev&&r.call(c,"finallyLoc")&&this.prev<c.finallyLoc){var e=c;break}e&&("break"===a||"continue"===a)&&e.tryLoc<=b&&b<=e.finallyLoc&&(e=null);var f=e?e.completion:{};return f.type=a,f.arg=b,e?(this.method="next",this.next=e.finallyLoc,x):this.complete(f)},complete:function complete(a,b){if("throw"===a.type)throw a.arg;return"break"===a.type||"continue"===a.type?this.next=a.arg:"return"===a.type?(this.rval=this.arg=a.arg,this.method="return",this.next="end"):"normal"===a.type&&b&&(this.next=b),x},finish:function finish(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.finallyLoc===a)return this.complete(b.completion,b.afterLoc),l(b),x},catch:function _catch(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.tryLoc===a){var d=b.completion;if("throw"===d.type){var e=d.arg;l(b)}return e}throw new Error("illegal catch attempt")},delegateYield:function delegateYield(a,b,c){return this.delegate={iterator:n(a),resultName:b,nextLoc:c},"next"===this.method&&(this.arg=void 0),x}},p}function asyncGeneratorStep(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){return void c(a)}h.done?b(i):Promise.resolve(i).then(d,e)}function _asyncToGenerator(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){function f(a){asyncGeneratorStep(h,d,e,f,g,"next",a)}function g(a){asyncGeneratorStep(h,d,e,f,g,"throw",a)}var h=a.apply(b,c);f(void 0)})}}var lname="list_func";/* -------------------------------------------------------------------------- */function get_action(a){var b=_core["default"].Global_get(lname,a);return Array.isArray(b)||"function"==typeof b?b:null}/**
|
|
10
2
|
* set action in action list by its key , you can later run this action using the key
|
|
11
3
|
* @param key
|
|
12
4
|
* @param value
|
|
13
5
|
* @returns
|
|
14
|
-
*/
|
|
15
|
-
export function set_action(key, func) {
|
|
16
|
-
return glb.Global_set(lname, key, func);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
6
|
+
*/function set_action(a,b){return _core["default"].Global_set(lname,a,b)}/**
|
|
19
7
|
* Adds an action to action list, you can later run those actions
|
|
20
8
|
* @param key
|
|
21
9
|
* @param value
|
|
22
10
|
* @returns
|
|
23
|
-
*/
|
|
24
|
-
export function add_action(key, func) {
|
|
25
|
-
return glb.Global_add(lname, key, func);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
11
|
+
*/function add_action(a,b){return _core["default"].Global_add(lname,a,b)}/**
|
|
28
12
|
* remove an action from action list
|
|
29
13
|
* @param key
|
|
30
14
|
* @param value
|
|
31
15
|
* @returns
|
|
32
|
-
*/
|
|
33
|
-
export function remove_action(key, value) {
|
|
34
|
-
return glb.Global_remove(lname, key, value);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
16
|
+
*/function remove_action(a,b){return _core["default"].Global_remove(lname,a,b)}/**
|
|
37
17
|
* Runs an action or a list of actions by their key, then clear the action list
|
|
38
18
|
* @param key
|
|
39
19
|
* @param args
|
|
40
20
|
* @returns result of action if there is a single action , or an array of results if there are multiple actions
|
|
41
|
-
*/
|
|
42
|
-
export async function run_action_clear(key, ...args) {
|
|
43
|
-
const result = await run_action(key, ...args);
|
|
44
|
-
set_action(key, null);
|
|
45
|
-
return result;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
21
|
+
*/function run_action_clear(){return _run_action_clear.apply(this,arguments)}/**
|
|
48
22
|
* Runs an action or a list of actions by their key,
|
|
49
23
|
* @param key
|
|
50
24
|
* @param args
|
|
51
25
|
* @returns result of action if there is a single action , or an array of results if there are multiple actions
|
|
52
|
-
*/
|
|
53
|
-
export async function run_action(key, ...args) {
|
|
54
|
-
let funcList = get_action(key);
|
|
55
|
-
if (funcList == null)
|
|
56
|
-
return null;
|
|
57
|
-
//console.log("run_action", funcList);
|
|
58
|
-
if (typeof funcList === "function") {
|
|
59
|
-
let func = funcList;
|
|
60
|
-
return await func(...args);
|
|
61
|
-
//if (func.constructor.name == "AsyncFunction") {
|
|
62
|
-
// //console.log("Doing async f");
|
|
63
|
-
//
|
|
64
|
-
// return await func(...args);
|
|
65
|
-
//} else {
|
|
66
|
-
// return func(...args);
|
|
67
|
-
//}
|
|
68
|
-
}
|
|
69
|
-
if (Array.isArray(funcList)) {
|
|
70
|
-
let resultObject = [];
|
|
71
|
-
for (let index = 0; index < funcList.length; index++) {
|
|
72
|
-
const func = funcList[index];
|
|
73
|
-
if (typeof func === "function") {
|
|
74
|
-
let functionResult = null;
|
|
75
|
-
functionResult = await func(...args);
|
|
76
|
-
//if (func.constructor.name == "AsyncFunction") {
|
|
77
|
-
// //console.log("Doing async f");
|
|
78
|
-
// functionResult = await func(...args);
|
|
79
|
-
//} else {
|
|
80
|
-
// functionResult = func(...args);
|
|
81
|
-
//}
|
|
82
|
-
resultObject.push(functionResult);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
console.error("[run_action]", "non function detected ", "key:", key);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return resultObject;
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
console.error("[run_action]", "invalid functions detected ", "key:", key);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
26
|
+
*/function _run_action_clear(){return _run_action_clear=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function b(a){var c,d,e,f,g=arguments;return _regeneratorRuntime().wrap(function h(b){for(;1;)switch(b.prev=b.next){case 0:for(c=g.length,d=Array(1<c?c-1:0),e=1;e<c;e++)d[e-1]=g[e];return b.next=3,run_action.apply(void 0,[a].concat(d));case 3:return f=b.sent,set_action(a,null),b.abrupt("return",f);case 6:case"end":return b.stop();}},b)})),_run_action_clear.apply(this,arguments)}function run_action(a){return _run_action.apply(this,arguments)}/**
|
|
95
27
|
* Runs an action or a list of actions by their key,
|
|
96
28
|
* @param key
|
|
97
29
|
* @param args
|
|
98
30
|
* @returns result of action if there is a single action , or an array of results if there are multiple actions
|
|
99
|
-
*/
|
|
100
|
-
export function run_action_sync(key, ...args) {
|
|
101
|
-
let funcList = get_action(key);
|
|
102
|
-
if (funcList == null)
|
|
103
|
-
return null;
|
|
104
|
-
if (typeof funcList === "function") {
|
|
105
|
-
let func = funcList;
|
|
106
|
-
return func(...args);
|
|
107
|
-
}
|
|
108
|
-
if (Array.isArray(funcList)) {
|
|
109
|
-
let resultObject = [];
|
|
110
|
-
for (let index = 0; index < funcList.length; index++) {
|
|
111
|
-
const func = funcList[index];
|
|
112
|
-
if (typeof func === "function") {
|
|
113
|
-
let functionResult = null;
|
|
114
|
-
functionResult = func(...args);
|
|
115
|
-
resultObject.push(functionResult);
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
console.error("[run_action]", "non function detected ", "key:", key);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return resultObject;
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
console.error("[run_action]", "invalid functions detected ", "key:", key);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
/* -------------------------------------------------------------------------- */
|
|
128
|
-
/* -------------------------------------------------------------------------- */
|
|
129
|
-
/**
|
|
31
|
+
*/function _run_action(){return _run_action=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function b(a){var c,d,e,f,g,h,i,j,k,l=arguments;return _regeneratorRuntime().wrap(function m(b){for(;1;)switch(b.prev=b.next){case 0:if(c=get_action(a),null!=c){b.next=3;break}return b.abrupt("return",null);case 3:for(d=l.length,e=Array(1<d?d-1:0),f=1;f<d;f++)e[f-1]=l[f];if("function"!=typeof c){b.next=9;break}return g=c,b.next=8,g.apply(void 0,e);case 8:return b.abrupt("return",b.sent);case 9:if(!Array.isArray(c)){b.next=29;break}h=[],i=0;case 12:if(!(i<c.length)){b.next=26;break}if(j=c[i],"function"!=typeof j){b.next=22;break}return k=null,b.next=18,j.apply(void 0,e);case 18:k=b.sent,h.push(k),b.next=23;break;case 22:console.error("[run_action]","non function detected ","key:",a);case 23:i++,b.next=12;break;case 26:return b.abrupt("return",h);case 29:console.error("[run_action]","invalid functions detected ","key:",a);case 30:case"end":return b.stop();}},b)})),_run_action.apply(this,arguments)}function run_action_sync(a){var b=get_action(a);if(null==b)return null;for(var c=arguments.length,d=Array(1<c?c-1:0),e=1;e<c;e++)d[e-1]=arguments[e];if("function"==typeof b){var f=b;return f.apply(void 0,d)}if(Array.isArray(b)){for(var g,h=[],i=0;i<b.length;i++)if(g=b[i],"function"==typeof g){var j=null;j=g.apply(void 0,d),h.push(j)}else console.error("[run_action]","non function detected ","key:",a);return h}console.error("[run_action]","invalid functions detected ","key:",a)}/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ /**
|
|
130
32
|
* Adds an action until the current component unmounts
|
|
131
33
|
* @param key
|
|
132
34
|
* @param value
|
|
133
35
|
* @returns
|
|
134
|
-
*/
|
|
135
|
-
export function hold_add_action(key, func) {
|
|
136
|
-
const actionFunction = React.useCallback(func, []);
|
|
137
|
-
React.useEffect(() => {
|
|
138
|
-
add_action(key, actionFunction);
|
|
139
|
-
return () => remove_action(key, actionFunction);
|
|
140
|
-
}, []);
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
36
|
+
*/function hold_add_action(a,b){var c=_react["default"].useCallback(b,[]);_react["default"].useEffect(function(){return add_action(a,c),function(){return remove_action(a,c)}},[])}/**
|
|
143
37
|
* set an action until the current component unmounts
|
|
144
38
|
* @param key
|
|
145
39
|
* @param value
|
|
146
40
|
* @returns
|
|
147
|
-
*/
|
|
148
|
-
export function hold_set_action(key, func) {
|
|
149
|
-
const actionFunction = React.useCallback(func, []);
|
|
150
|
-
React.useEffect(() => {
|
|
151
|
-
set_action(key, actionFunction);
|
|
152
|
-
return () => set_action(key, null);
|
|
153
|
-
}, []);
|
|
154
|
-
}
|
|
41
|
+
*/function hold_set_action(a,b){var c=_react["default"].useCallback(b,[]);_react["default"].useEffect(function(){return set_action(a,c),function(){return set_action(a,null)}},[])}
|
|
@@ -1,23 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import glb from "../core";
|
|
3
|
-
const lname_hold = "list_hold_keys";
|
|
4
|
-
/**
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.hold_key=hold_key,exports.is_key_held=is_key_held;var _react=_interopRequireDefault(require("react")),_core=_interopRequireDefault(require("../core"));function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}var lname_hold="list_hold_keys";/**
|
|
5
2
|
* Holds a key until the current component unmounts
|
|
6
3
|
* you can use this to see if a certain component is alive or not
|
|
7
4
|
* @param key
|
|
8
|
-
*/
|
|
9
|
-
export function hold_key(key, value = "", isActive = true) {
|
|
10
|
-
const hvar = React.useMemo(() => Symbol(value), []);
|
|
11
|
-
React.useEffect(() => {
|
|
12
|
-
const hkey = key;
|
|
13
|
-
if (isActive)
|
|
14
|
-
glb.Global_add(lname_hold, hkey, hvar);
|
|
15
|
-
else
|
|
16
|
-
glb.Global_remove(lname_hold, hkey, hvar);
|
|
17
|
-
return () => glb.Global_remove(lname_hold, hkey, hvar);
|
|
18
|
-
}, [isActive]);
|
|
19
|
-
}
|
|
20
|
-
export function is_key_held(key) {
|
|
21
|
-
const gval = glb.Global_get(lname_hold, key);
|
|
22
|
-
return Array.isArray(gval) && gval.length > 0;
|
|
23
|
-
}
|
|
5
|
+
*/function hold_key(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:"",c=!(2<arguments.length&&arguments[2]!==void 0)||arguments[2],d=_react["default"].useMemo(function(){return Symbol(b)},[]);_react["default"].useEffect(function(){var b=a;return c?_core["default"].Global_add(lname_hold,b,d):_core["default"].Global_remove(lname_hold,b,d),function(){return _core["default"].Global_remove(lname_hold,b,d)}},[c])}function is_key_held(a){var b=_core["default"].Global_get(lname_hold,a);return Array.isArray(b)&&0<b.length}
|
|
@@ -1,57 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
import glb from "../core";
|
|
3
|
-
/* -------------------------------------------------------------------------- */
|
|
4
|
-
/* Filters */
|
|
5
|
-
/* -------------------------------------------------------------------------- */
|
|
6
|
-
const lname_views = "list_views";
|
|
7
|
-
/**
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ViewsContainer=ViewsContainer,exports.add_view=add_view,exports.load_views=load_views,exports.use_views=use_views;var _react=_interopRequireDefault(require("react")),_core=_interopRequireDefault(require("../core"));function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"===_typeof(b)?b:b+""}function _toPrimitive(a,b){if("object"!==_typeof(a)||null===a)return a;var c=a[Symbol.toPrimitive];if(c!==void 0){var d=c.call(a,b||"default");if("object"!==_typeof(d))return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}/* -------------------------------------------------------------------------- */ /* Filters */ /* -------------------------------------------------------------------------- */var lname_views="list_views";/**
|
|
8
2
|
* Adds a view to view list
|
|
9
3
|
* @param key
|
|
10
4
|
* @param action action of the filter
|
|
11
5
|
* @param priority filters with lower priority are executed first
|
|
12
6
|
* @returns
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
view: view,
|
|
18
|
-
priority: priority,
|
|
19
|
-
};
|
|
20
|
-
return glb.Global_add(lname_views, key, view_object);
|
|
21
|
-
}
|
|
22
|
-
// export function remove_view(key: string, view: React.ReactNode ): any {
|
|
23
|
-
// const view_object = {key: key, view: view, priority: priority};
|
|
24
|
-
// return glb.Global_add(lname_filter, key, view);
|
|
25
|
-
// }
|
|
7
|
+
*/function add_view(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:10;return _core["default"].Global_add(lname_views,a,{view_key:a,view:b,priority:c})}// export function remove_view(key: string, view: React.ReactNode ): any {
|
|
8
|
+
// const view_object = {key: key, view: view, priority: priority};
|
|
9
|
+
// return glb.Global_add(lname_filter, key, view);
|
|
10
|
+
// }
|
|
26
11
|
/**
|
|
27
12
|
*
|
|
28
13
|
* @param view_key
|
|
29
14
|
* @param initialValue
|
|
30
15
|
* @returns
|
|
31
|
-
*/
|
|
32
|
-
export function load_views(view_key, initialValue, child_props) {
|
|
33
|
-
var view_list = glb.Global_get(lname_views, view_key);
|
|
34
|
-
if (!Array.isArray(view_list) || view_list.length == 0)
|
|
35
|
-
return initialValue;
|
|
36
|
-
view_list.sort((a, b) => a.priority > b.priority ? 1 : -1); /* lower priority gets executed first */
|
|
37
|
-
return view_list.map((r, i) => typeof r.view === "function"
|
|
38
|
-
? r.view({ ...child_props, key: String(i) })
|
|
39
|
-
: r.view);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
16
|
+
*/function load_views(a,b,c){var d=_core["default"].Global_get(lname_views,a);return Array.isArray(d)&&0!=d.length?(d.sort(function(c,a){return c.priority>a.priority?1:-1}),d.map(function(a,b){return"function"==typeof a.view?a.view(_objectSpread(_objectSpread({},c),{},{key:b+""})):a.view})):b}/**
|
|
42
17
|
*
|
|
43
18
|
* @param view_key
|
|
44
19
|
* @param initialValue
|
|
45
20
|
* @returns
|
|
46
|
-
*/
|
|
47
|
-
export function use_views(view_key, initialValue, child_props) {
|
|
48
|
-
return React.useMemo(() => {
|
|
49
|
-
return load_views(view_key, initialValue, child_props);
|
|
50
|
-
}, []);
|
|
51
|
-
}
|
|
52
|
-
export function ViewsContainer(props) {
|
|
53
|
-
const viewlist = use_views(props.view_key, props.initialValue, props.children_props);
|
|
54
|
-
return (React.createElement("div", null,
|
|
55
|
-
props.children,
|
|
56
|
-
viewlist));
|
|
57
|
-
}
|
|
21
|
+
*/function use_views(a,b,c){return _react["default"].useMemo(function(){return load_views(a,b,c)},[])}function ViewsContainer(a){var b=use_views(a.view_key,a.initialValue,a.children_props);return _react["default"].createElement("div",null,a.children,b)}
|
|
@@ -1,4 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export * as gfilter from "./g_filter";
|
|
3
|
-
export * as gview from "./g_view";
|
|
4
|
-
export * as gholder from "./g_holder";
|
|
1
|
+
"use strict";var _gfunc=_interopRequireWildcard(require("./g_func"));var _gfilter=_interopRequireWildcard(require("./g_filter"));var _gview=_interopRequireWildcard(require("./g_view"));var _gholder=_interopRequireWildcard(require("./g_holder"));function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.gview=exports.gholder=exports.gfunc=exports.gfilter=void 0;exports.gfunc=_gfunc;exports.gfilter=_gfilter;exports.gview=_gview;exports.gholder=_gholder;function _getRequireWildcardCache(a){if("function"!=typeof WeakMap)return null;var b=new WeakMap,c=new WeakMap;return(_getRequireWildcardCache=function(a){return a?c:b})(a)}function _interopRequireWildcard(a,b){if(!b&&a&&a.__esModule)return a;if(null===a||"object"!==_typeof(a)&&"function"!=typeof a)return{default:a};var c=_getRequireWildcardCache(b);if(c&&c.has(a))return c.get(a);var d={},e=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var f in a)if("default"!=f&&Object.prototype.hasOwnProperty.call(a,f)){var g=e?Object.getOwnPropertyDescriptor(a,f):null;g&&(g.get||g.set)?Object.defineProperty(d,f,g):d[f]=a[f]}return d["default"]=a,c&&c.set(a,d),d}
|
|
@@ -1,24 +1 @@
|
|
|
1
|
-
|
|
2
|
-
const lname = "list_once";
|
|
3
|
-
export async function do_once(f, key, ifNot) {
|
|
4
|
-
if (!f || typeof f !== "function")
|
|
5
|
-
return null;
|
|
6
|
-
if (!key || key == "")
|
|
7
|
-
key = "fn-" + f.name;
|
|
8
|
-
const isDone = glb.Global_get(lname, key);
|
|
9
|
-
if (isDone == "true") {
|
|
10
|
-
if (ifNot)
|
|
11
|
-
return await ifNot();
|
|
12
|
-
return undefined;
|
|
13
|
-
}
|
|
14
|
-
glb.Global_set(lname, key, "true");
|
|
15
|
-
return await f();
|
|
16
|
-
}
|
|
17
|
-
export function reset_once(key = "") {
|
|
18
|
-
if (!key || key == "") {
|
|
19
|
-
glb.Global_set(lname, true, null);
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
glb.Global_set(lname, key, null);
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
1
|
+
"use strict";var _core=_interopRequireDefault(require("../core"));Object.defineProperty(exports,"__esModule",{value:!0}),exports.do_once=do_once,exports.reset_once=reset_once;function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _regeneratorRuntime(){"use strict";/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */function a(a,b,c){return Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}),a[b]}function b(a,b,c,e){var f=b&&b.prototype instanceof d?b:d,g=Object.create(f.prototype),h=new m(e||[]);return s(g,"_invoke",{value:i(a,c,h)}),g}function c(a,b,c){try{return{type:"normal",arg:a.call(b,c)}}catch(a){return{type:"throw",arg:a}}}function d(){}function e(){}function f(){}function g(b){["next","throw","return"].forEach(function(c){a(b,c,function(a){return this._invoke(c,a)})})}function h(a,b){function d(e,f,g,h){var i=c(a[e],a,f);if("throw"!==i.type){var j=i.arg,k=j.value;return k&&"object"==_typeof(k)&&r.call(k,"__await")?b.resolve(k.__await).then(function(a){d("next",a,g,h)},function(a){d("throw",a,g,h)}):b.resolve(k).then(function(a){j.value=a,g(j)},function(a){return d("throw",a,g,h)})}h(i.arg)}var e;s(this,"_invoke",{value:function value(a,c){function f(){return new b(function(b,e){d(a,c,b,e)})}return e=e?e.then(f,f):f()}})}function i(a,b,d){var e="suspendedStart";return function(f,g){if("executing"==e)throw new Error("Generator is already running");if("completed"==e){if("throw"===f)throw g;return o()}for(d.method=f,d.arg=g;;){var h=d.delegate;if(h){var i=j(h,d);if(i){if(i===x)continue;return i}}if("next"===d.method)d.sent=d._sent=d.arg;else if("throw"===d.method){if("suspendedStart"==e)throw e="completed",d.arg;d.dispatchException(d.arg)}else"return"===d.method&&d.abrupt("return",d.arg);e="executing";var k=c(a,b,d);if("normal"===k.type){if(e=d.done?"completed":"suspendedYield",k.arg===x)continue;return{value:k.arg,done:d.done}}"throw"===k.type&&(e="completed",d.method="throw",d.arg=k.arg)}}}function j(a,b){var d=b.method,e=a.iterator[d];if(void 0===e)return b.delegate=null,"throw"===d&&a.iterator["return"]&&(b.method="return",b.arg=void 0,j(a,b),"throw"===b.method)||"return"!==d&&(b.method="throw",b.arg=new TypeError("The iterator does not provide a '"+d+"' method")),x;var f=c(e,a.iterator,b.arg);if("throw"===f.type)return b.method="throw",b.arg=f.arg,b.delegate=null,x;var g=f.arg;return g?g.done?(b[a.resultName]=g.value,b.next=a.nextLoc,"return"!==b.method&&(b.method="next",b.arg=void 0),b.delegate=null,x):g:(b.method="throw",b.arg=new TypeError("iterator result is not an object"),b.delegate=null,x)}function k(a){var b={tryLoc:a[0]};1 in a&&(b.catchLoc=a[1]),2 in a&&(b.finallyLoc=a[2],b.afterLoc=a[3]),this.tryEntries.push(b)}function l(a){var b=a.completion||{};b.type="normal",delete b.arg,a.completion=b}function m(a){this.tryEntries=[{tryLoc:"root"}],a.forEach(k,this),this.reset(!0)}function n(a){if(a){var b=a[u];if(b)return b.call(a);if("function"==typeof a.next)return a;if(!isNaN(a.length)){var c=-1,d=function b(){for(;++c<a.length;)if(r.call(a,c))return b.value=a[c],b.done=!1,b;return b.value=void 0,b.done=!0,b};return d.next=d}}return{next:o}}function o(){return{value:void 0,done:!0}}_regeneratorRuntime=function(){return p};var p={},q=Object.prototype,r=q.hasOwnProperty,s=Object.defineProperty||function(a,b,c){a[b]=c.value},t="function"==typeof Symbol?Symbol:{},u=t.iterator||"@@iterator",v=t.asyncIterator||"@@asyncIterator",w=t.toStringTag||"@@toStringTag";try{a({},"")}catch(b){a=function(a,b,c){return a[b]=c}}p.wrap=b;var x={},y={};a(y,u,function(){return this});var z=Object.getPrototypeOf,A=z&&z(z(n([])));A&&A!==q&&r.call(A,u)&&(y=A);var B=f.prototype=d.prototype=Object.create(y);return e.prototype=f,s(B,"constructor",{value:f,configurable:!0}),s(f,"constructor",{value:e,configurable:!0}),e.displayName=a(f,w,"GeneratorFunction"),p.isGeneratorFunction=function(a){var b="function"==typeof a&&a.constructor;return!!b&&(b===e||"GeneratorFunction"===(b.displayName||b.name))},p.mark=function(b){return Object.setPrototypeOf?Object.setPrototypeOf(b,f):(b.__proto__=f,a(b,w,"GeneratorFunction")),b.prototype=Object.create(B),b},p.awrap=function(a){return{__await:a}},g(h.prototype),a(h.prototype,v,function(){return this}),p.AsyncIterator=h,p.async=function(a,c,d,e,f){void 0===f&&(f=Promise);var g=new h(b(a,c,d,e),f);return p.isGeneratorFunction(c)?g:g.next().then(function(a){return a.done?a.value:g.next()})},g(B),a(B,w,"Generator"),a(B,u,function(){return this}),a(B,"toString",function(){return"[object Generator]"}),p.keys=function(a){var b=Object(a),c=[];for(var d in b)c.push(d);return c.reverse(),function a(){for(;c.length;){var d=c.pop();if(d in b)return a.value=d,a.done=!1,a}return a.done=!0,a}},p.values=n,m.prototype={constructor:m,reset:function reset(a){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(l),!a)for(var b in this)"t"===b.charAt(0)&&r.call(this,b)&&!isNaN(+b.slice(1))&&(this[b]=void 0)},stop:function stop(){this.done=!0;var a=this.tryEntries[0].completion;if("throw"===a.type)throw a.arg;return this.rval},dispatchException:function dispatchException(a){function b(b,d){return f.type="throw",f.arg=a,c.next=b,d&&(c.method="next",c.arg=void 0),!!d}if(this.done)throw a;for(var c=this,d=this.tryEntries.length-1;0<=d;--d){var e=this.tryEntries[d],f=e.completion;if("root"===e.tryLoc)return b("end");if(e.tryLoc<=this.prev){var g=r.call(e,"catchLoc"),h=r.call(e,"finallyLoc");if(g&&h){if(this.prev<e.catchLoc)return b(e.catchLoc,!0);if(this.prev<e.finallyLoc)return b(e.finallyLoc)}else if(!g){if(!h)throw new Error("try statement without catch or finally");if(this.prev<e.finallyLoc)return b(e.finallyLoc)}else if(this.prev<e.catchLoc)return b(e.catchLoc,!0)}}},abrupt:function abrupt(a,b){for(var c,d=this.tryEntries.length-1;0<=d;--d)if(c=this.tryEntries[d],c.tryLoc<=this.prev&&r.call(c,"finallyLoc")&&this.prev<c.finallyLoc){var e=c;break}e&&("break"===a||"continue"===a)&&e.tryLoc<=b&&b<=e.finallyLoc&&(e=null);var f=e?e.completion:{};return f.type=a,f.arg=b,e?(this.method="next",this.next=e.finallyLoc,x):this.complete(f)},complete:function complete(a,b){if("throw"===a.type)throw a.arg;return"break"===a.type||"continue"===a.type?this.next=a.arg:"return"===a.type?(this.rval=this.arg=a.arg,this.method="return",this.next="end"):"normal"===a.type&&b&&(this.next=b),x},finish:function finish(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.finallyLoc===a)return this.complete(b.completion,b.afterLoc),l(b),x},catch:function _catch(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.tryLoc===a){var d=b.completion;if("throw"===d.type){var e=d.arg;l(b)}return e}throw new Error("illegal catch attempt")},delegateYield:function delegateYield(a,b,c){return this.delegate={iterator:n(a),resultName:b,nextLoc:c},"next"===this.method&&(this.arg=void 0),x}},p}function asyncGeneratorStep(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){return void c(a)}h.done?b(i):Promise.resolve(i).then(d,e)}function _asyncToGenerator(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){function f(a){asyncGeneratorStep(h,d,e,f,g,"next",a)}function g(a){asyncGeneratorStep(h,d,e,f,g,"throw",a)}var h=a.apply(b,c);f(void 0)})}}var lname="list_once";function do_once(){return _do_once.apply(this,arguments)}function _do_once(){return _do_once=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function d(a,b,c){var e;return _regeneratorRuntime().wrap(function f(d){for(;1;)switch(d.prev=d.next){case 0:if(a&&"function"==typeof a){d.next=2;break}return d.abrupt("return",null);case 2:if(b&&""!=b||(b="fn-"+a.name),e=_core["default"].Global_get(lname,b),"true"!=e){d.next=10;break}if(!c){d.next=9;break}return d.next=8,c();case 8:return d.abrupt("return",d.sent);case 9:return d.abrupt("return",void 0);case 10:return _core["default"].Global_set(lname,b,"true"),d.next=13,a();case 13:return d.abrupt("return",d.sent);case 14:case"end":return d.stop();}},d)})),_do_once.apply(this,arguments)}function reset_once(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";return a&&""!=a?(_core["default"].Global_set(lname,a,null),!0):(_core["default"].Global_set(lname,!0,null),!0)}
|
|
@@ -1,3 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import * as g_once from "./g_once";
|
|
3
|
-
export default { ...g_once };
|
|
1
|
+
"use strict";var _exportNames={};var g_once=_interopRequireWildcard(require("./g_once"));Object.defineProperty(exports,"__esModule",{value:!0});exports["default"]=void 0;Object.keys(g_once).forEach(function(a){"default"===a||"__esModule"===a||Object.prototype.hasOwnProperty.call(_exportNames,a)||a in exports&&exports[a]===g_once[a]||Object.defineProperty(exports,a,{enumerable:!0,get:function get(){return g_once[a]}})});function _getRequireWildcardCache(a){if("function"!=typeof WeakMap)return null;var b=new WeakMap,c=new WeakMap;return(_getRequireWildcardCache=function(a){return a?c:b})(a)}function _interopRequireWildcard(a,b){if(!b&&a&&a.__esModule)return a;if(null===a||"object"!==_typeof(a)&&"function"!=typeof a)return{default:a};var c=_getRequireWildcardCache(b);if(c&&c.has(a))return c.get(a);var d={},e=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var f in a)if("default"!=f&&Object.prototype.hasOwnProperty.call(a,f)){var g=e?Object.getOwnPropertyDescriptor(a,f):null;g&&(g.get||g.set)?Object.defineProperty(d,f,g):d[f]=a[f]}return d["default"]=a,c&&c.set(a,d),d}function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"===_typeof(b)?b:b+""}function _toPrimitive(a,b){if("object"!==_typeof(a)||null===a)return a;var c=a[Symbol.toPrimitive];if(c!==void 0){var d=c.call(a,b||"default");if("object"!==_typeof(d))return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}var _default=_objectSpread({},g_once);exports["default"]=_default;
|
|
@@ -1,128 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
import React from "react";
|
|
3
|
-
const sd = {};
|
|
4
|
-
const DataStore = new Store(sd);
|
|
5
|
-
export function set_state(key, value) {
|
|
6
|
-
DataStore.update((s) => {
|
|
7
|
-
if (!s || typeof s != "object")
|
|
8
|
-
s = {};
|
|
9
|
-
if (typeof key === "function") {
|
|
10
|
-
const updRes = key(s);
|
|
11
|
-
if (updRes != undefined)
|
|
12
|
-
s = updRes;
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
s[key] = value;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.add_state=add_state,exports.hold_add_state=hold_add_state,exports.hold_set_keystate=hold_set_keystate,exports.hold_set_state=hold_set_state,exports.remove_keystate=remove_keystate,exports.remove_state=remove_state,exports.set_keystate=set_keystate,exports.set_state=set_state,exports.use_state=use_state;var _pullstate=require("pullstate"),_react=_interopRequireDefault(require("react"));function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"===_typeof(b)?b:b+""}function _toPrimitive(a,b){if("object"!==_typeof(a)||null===a)return a;var c=a[Symbol.toPrimitive];if(c!==void 0){var d=c.call(a,b||"default");if("object"!==_typeof(d))return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}function _toConsumableArray(a){return _arrayWithoutHoles(a)||_iterableToArray(a)||_unsupportedIterableToArray(a)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(a,b){if(a){if("string"==typeof a)return _arrayLikeToArray(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?_arrayLikeToArray(a,b):void 0}}function _iterableToArray(a){if("undefined"!=typeof Symbol&&null!=a[Symbol.iterator]||null!=a["@@iterator"])return Array.from(a)}function _arrayWithoutHoles(a){if(Array.isArray(a))return _arrayLikeToArray(a)}function _arrayLikeToArray(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}var sd={},DataStore=new _pullstate.Store(sd);function set_state(a,b){return DataStore.update(function(c){if(c&&"object"==_typeof(c)||(c={}),"function"==typeof a){var d=a(c);null!=d&&(c=d)}else c[a]=b}),!0}/**
|
|
21
2
|
* Add value to state array
|
|
22
3
|
* @param state_name
|
|
23
4
|
* @param value
|
|
24
|
-
*/
|
|
25
|
-
export function add_state(state_name, value) {
|
|
26
|
-
set_state((s) => {
|
|
27
|
-
if (!s || typeof s != "object")
|
|
28
|
-
s = {};
|
|
29
|
-
const oldval = Array.isArray(s[state_name]) ? s[state_name] : [];
|
|
30
|
-
s[state_name] = [...oldval, value];
|
|
31
|
-
return s;
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
5
|
+
*/function add_state(a,b){set_state(function(c){c&&"object"==_typeof(c)||(c={});var d=Array.isArray(c[a])?c[a]:[];return c[a]=[].concat(_toConsumableArray(d),[b]),c})}/**
|
|
35
6
|
* remove value from state array
|
|
36
7
|
* @param state_name
|
|
37
8
|
* @param value
|
|
38
|
-
*/
|
|
39
|
-
export function remove_state(state_name, value) {
|
|
40
|
-
set_state((s) => {
|
|
41
|
-
if (s) {
|
|
42
|
-
const oldval = Array.isArray(s[state_name])
|
|
43
|
-
? s[state_name]
|
|
44
|
-
: [];
|
|
45
|
-
s[state_name] = oldval.filter((v) => v !== value);
|
|
46
|
-
}
|
|
47
|
-
return s;
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
9
|
+
*/function remove_state(a,b){set_state(function(c){if(c){var d=Array.isArray(c[a])?c[a]:[];c[a]=d.filter(function(a){return a!==b})}return c})}/**
|
|
51
10
|
* Add value to state object
|
|
52
11
|
* @param state_name
|
|
53
12
|
* @param key
|
|
54
13
|
* @param value
|
|
55
|
-
*/
|
|
56
|
-
export function set_keystate(state_name, key, value) {
|
|
57
|
-
set_state((s) => {
|
|
58
|
-
if (!s || typeof s != "object")
|
|
59
|
-
s = {};
|
|
60
|
-
let oldval = s[state_name];
|
|
61
|
-
if (oldval == null || typeof oldval !== "object") {
|
|
62
|
-
oldval = {};
|
|
63
|
-
}
|
|
64
|
-
else
|
|
65
|
-
oldval = { ...oldval };
|
|
66
|
-
oldval[key] = value;
|
|
67
|
-
s[state_name] = oldval;
|
|
68
|
-
return s;
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
14
|
+
*/function set_keystate(a,b,c){set_state(function(d){d&&"object"==_typeof(d)||(d={});var e=d[a];return e=null==e||"object"!==_typeof(e)?{}:_objectSpread({},e),e[b]=c,d[a]=e,d})}/**
|
|
72
15
|
* remove value from state object
|
|
73
16
|
* @param state_name
|
|
74
17
|
* @param key
|
|
75
|
-
*/
|
|
76
|
-
export function remove_keystate(state_name, key) {
|
|
77
|
-
set_state((s) => {
|
|
78
|
-
if (s) {
|
|
79
|
-
let oldval = s[state_name];
|
|
80
|
-
if (oldval == null || typeof oldval !== "object") {
|
|
81
|
-
oldval = {};
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
// oldval = { ...oldval };
|
|
85
|
-
delete oldval[key];
|
|
86
|
-
}
|
|
87
|
-
s[state_name] = oldval;
|
|
88
|
-
}
|
|
89
|
-
return s;
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
18
|
+
*/function remove_keystate(a,b){set_state(function(c){if(c){var d=c[a];null==d||"object"!==_typeof(d)?d={}:delete d[b],c[a]=d}return c})}/**
|
|
93
19
|
* Returns a state by its name
|
|
94
20
|
* @param state_name
|
|
95
21
|
* @returns the state
|
|
96
|
-
*/
|
|
97
|
-
export function use_state(state_name) {
|
|
98
|
-
return DataStore.useState((s) => s[state_name]);
|
|
99
|
-
}
|
|
100
|
-
/* -------------------------------------------------------------------------- */
|
|
101
|
-
/* -------------------------------------------------------------------------- */
|
|
102
|
-
export function hold_set_state(state_name, value) {
|
|
103
|
-
React.useEffect(() => {
|
|
104
|
-
set_state(state_name, value);
|
|
105
|
-
return () => {
|
|
106
|
-
set_state(state_name, undefined);
|
|
107
|
-
};
|
|
108
|
-
}, [value]);
|
|
109
|
-
return value;
|
|
110
|
-
}
|
|
111
|
-
export function hold_set_keystate(state_name, key, value) {
|
|
112
|
-
React.useEffect(() => {
|
|
113
|
-
set_keystate(state_name, key, value);
|
|
114
|
-
return () => {
|
|
115
|
-
set_keystate(state_name, key, undefined);
|
|
116
|
-
};
|
|
117
|
-
}, [value]);
|
|
118
|
-
return value;
|
|
119
|
-
}
|
|
120
|
-
export function hold_add_state(state_name, value) {
|
|
121
|
-
React.useEffect(() => {
|
|
122
|
-
add_state(state_name, value);
|
|
123
|
-
return () => {
|
|
124
|
-
remove_state(state_name, undefined);
|
|
125
|
-
};
|
|
126
|
-
}, [value]);
|
|
127
|
-
return value;
|
|
128
|
-
}
|
|
22
|
+
*/function use_state(a){return DataStore.useState(function(b){return b[a]})}/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */function hold_set_state(a,b){return _react["default"].useEffect(function(){return set_state(a,b),function(){set_state(a,void 0)}},[b]),b}function hold_set_keystate(a,b,c){return _react["default"].useEffect(function(){return set_keystate(a,b,c),function(){set_keystate(a,b,void 0)}},[c]),c}function hold_add_state(a,b){return _react["default"].useEffect(function(){return add_state(a,b),function(){remove_state(a,void 0)}},[b]),b}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";var _g_state=require("./g_state");Object.defineProperty(exports,"__esModule",{value:!0});Object.keys(_g_state).forEach(function(a){"default"===a||"__esModule"===a||a in exports&&exports[a]===_g_state[a]||Object.defineProperty(exports,a,{enumerable:!0,get:function get(){return _g_state[a]}})});
|
|
@@ -1,124 +1 @@
|
|
|
1
|
-
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import { gencryption } from "../../index";
|
|
4
|
-
import glb from "../core";
|
|
5
|
-
const lname = "list_var";
|
|
6
|
-
export async function add_var(key, value, options) {
|
|
7
|
-
var foundValue = await get_var(key, options);
|
|
8
|
-
if (!Array.isArray(foundValue))
|
|
9
|
-
foundValue = [];
|
|
10
|
-
foundValue.push(value);
|
|
11
|
-
await set_var(key, foundValue, options);
|
|
12
|
-
return foundValue;
|
|
13
|
-
}
|
|
14
|
-
export function get_var_sync(key) {
|
|
15
|
-
let foundValue = glb.Global_get(lname, key);
|
|
16
|
-
var isString = typeof foundValue == "string";
|
|
17
|
-
if (!isString)
|
|
18
|
-
return foundValue;
|
|
19
|
-
foundValue = gencryption.Decode_Default(foundValue);
|
|
20
|
-
return foundValue;
|
|
21
|
-
}
|
|
22
|
-
export function set_var_sync(key, value) {
|
|
23
|
-
let final_value = value;
|
|
24
|
-
var isString = typeof final_value == "string";
|
|
25
|
-
if (isString) {
|
|
26
|
-
/* Encode any string */
|
|
27
|
-
final_value = gencryption.Encode_Default(final_value);
|
|
28
|
-
}
|
|
29
|
-
glb.Global_set(lname, key, final_value);
|
|
30
|
-
return final_value;
|
|
31
|
-
}
|
|
32
|
-
export async function get_var(key, options) {
|
|
33
|
-
if (!options)
|
|
34
|
-
options = {};
|
|
35
|
-
var jsonify = options.json;
|
|
36
|
-
var foundValue = null;
|
|
37
|
-
/* -------------------------------------------------------------------------- */
|
|
38
|
-
foundValue = glb.Global_get(lname, key);
|
|
39
|
-
if (foundValue == null && options.local_storage) {
|
|
40
|
-
const fname = lname + "_" + key;
|
|
41
|
-
foundValue = localStorage[fname]; // only strings
|
|
42
|
-
}
|
|
43
|
-
if (foundValue == null && options.session) {
|
|
44
|
-
const sessionStorage = window.sessionStorage;
|
|
45
|
-
foundValue = await sessionStorage.getItem(key);
|
|
46
|
-
}
|
|
47
|
-
if (foundValue == null && options.storage) {
|
|
48
|
-
foundValue = await AsyncStorage.getItem(key);
|
|
49
|
-
}
|
|
50
|
-
if (foundValue == null)
|
|
51
|
-
return null;
|
|
52
|
-
/* -------------------------------------------------------------------------- */
|
|
53
|
-
var isString = typeof foundValue == "string";
|
|
54
|
-
if (!isString)
|
|
55
|
-
return foundValue;
|
|
56
|
-
foundValue = await gencryption.Decode_Default(foundValue);
|
|
57
|
-
if (jsonify) {
|
|
58
|
-
try {
|
|
59
|
-
foundValue = JSON.parse(foundValue);
|
|
60
|
-
}
|
|
61
|
-
catch (Ex) { }
|
|
62
|
-
}
|
|
63
|
-
return foundValue;
|
|
64
|
-
}
|
|
65
|
-
export async function set_var(key, value, options) {
|
|
66
|
-
if (!options)
|
|
67
|
-
options = {};
|
|
68
|
-
var final_value = value;
|
|
69
|
-
var jsonify = options.json && typeof final_value != "function";
|
|
70
|
-
if (jsonify) {
|
|
71
|
-
try {
|
|
72
|
-
final_value = JSON.stringify(final_value);
|
|
73
|
-
}
|
|
74
|
-
catch (Ex) { }
|
|
75
|
-
}
|
|
76
|
-
if (final_value === null || final_value === undefined) {
|
|
77
|
-
final_value = "";
|
|
78
|
-
}
|
|
79
|
-
var isString = typeof final_value == "string";
|
|
80
|
-
if (isString) {
|
|
81
|
-
/* Encode any string */
|
|
82
|
-
final_value = gencryption.Encode_Default(final_value);
|
|
83
|
-
}
|
|
84
|
-
/* -------------------------------------------------------------------------- */
|
|
85
|
-
glb.Global_set(lname, key, final_value);
|
|
86
|
-
if (options.local_storage) {
|
|
87
|
-
if (!isString)
|
|
88
|
-
throw new Error("You cant save non-string values in local_storage !");
|
|
89
|
-
const fname = lname + "_" + key;
|
|
90
|
-
localStorage[fname] = final_value; // only strings
|
|
91
|
-
}
|
|
92
|
-
if (options.session) {
|
|
93
|
-
if (!isString)
|
|
94
|
-
throw new Error("You cant save non-string values in session !");
|
|
95
|
-
const sessionStorage = window.sessionStorage;
|
|
96
|
-
if (final_value !== "") {
|
|
97
|
-
sessionStorage.setItem(key, final_value);
|
|
98
|
-
}
|
|
99
|
-
else
|
|
100
|
-
sessionStorage.removeItem(key);
|
|
101
|
-
}
|
|
102
|
-
if (options.storage) {
|
|
103
|
-
if (!isString)
|
|
104
|
-
throw new Error("You cant save non-string values in AsyncStorage !");
|
|
105
|
-
if (final_value !== "") {
|
|
106
|
-
await AsyncStorage.setItem(key, final_value);
|
|
107
|
-
}
|
|
108
|
-
else
|
|
109
|
-
await AsyncStorage.removeItem(key);
|
|
110
|
-
}
|
|
111
|
-
/* -------------------------------------------------------------------------- */
|
|
112
|
-
return final_value;
|
|
113
|
-
}
|
|
114
|
-
/* -------------------------------------------------------------------------- */
|
|
115
|
-
/* -------------------------------------------------------------------------- */
|
|
116
|
-
export function hold_var(key, value, options) {
|
|
117
|
-
React.useEffect(() => {
|
|
118
|
-
set_var(key, value, options);
|
|
119
|
-
return () => {
|
|
120
|
-
set_var(key, null, options);
|
|
121
|
-
};
|
|
122
|
-
}, [value]);
|
|
123
|
-
return value;
|
|
124
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.add_var=add_var,exports.get_var=get_var,exports.get_var_sync=get_var_sync,exports.hold_var=hold_var,exports.set_var=set_var,exports.set_var_sync=set_var_sync;var _asyncStorage=_interopRequireDefault(require("@react-native-async-storage/async-storage")),_react=_interopRequireDefault(require("react")),_core=_interopRequireDefault(require("../core"));function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _regeneratorRuntime(){"use strict";/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */function a(a,b,c){return Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}),a[b]}function b(a,b,c,e){var f=b&&b.prototype instanceof d?b:d,g=Object.create(f.prototype),h=new m(e||[]);return s(g,"_invoke",{value:i(a,c,h)}),g}function c(a,b,c){try{return{type:"normal",arg:a.call(b,c)}}catch(a){return{type:"throw",arg:a}}}function d(){}function e(){}function f(){}function g(b){["next","throw","return"].forEach(function(c){a(b,c,function(a){return this._invoke(c,a)})})}function h(a,b){function d(e,f,g,h){var i=c(a[e],a,f);if("throw"!==i.type){var j=i.arg,k=j.value;return k&&"object"==_typeof(k)&&r.call(k,"__await")?b.resolve(k.__await).then(function(a){d("next",a,g,h)},function(a){d("throw",a,g,h)}):b.resolve(k).then(function(a){j.value=a,g(j)},function(a){return d("throw",a,g,h)})}h(i.arg)}var e;s(this,"_invoke",{value:function value(a,c){function f(){return new b(function(b,e){d(a,c,b,e)})}return e=e?e.then(f,f):f()}})}function i(a,b,d){var e="suspendedStart";return function(f,g){if("executing"==e)throw new Error("Generator is already running");if("completed"==e){if("throw"===f)throw g;return o()}for(d.method=f,d.arg=g;;){var h=d.delegate;if(h){var i=j(h,d);if(i){if(i===x)continue;return i}}if("next"===d.method)d.sent=d._sent=d.arg;else if("throw"===d.method){if("suspendedStart"==e)throw e="completed",d.arg;d.dispatchException(d.arg)}else"return"===d.method&&d.abrupt("return",d.arg);e="executing";var k=c(a,b,d);if("normal"===k.type){if(e=d.done?"completed":"suspendedYield",k.arg===x)continue;return{value:k.arg,done:d.done}}"throw"===k.type&&(e="completed",d.method="throw",d.arg=k.arg)}}}function j(a,b){var d=b.method,e=a.iterator[d];if(void 0===e)return b.delegate=null,"throw"===d&&a.iterator["return"]&&(b.method="return",b.arg=void 0,j(a,b),"throw"===b.method)||"return"!==d&&(b.method="throw",b.arg=new TypeError("The iterator does not provide a '"+d+"' method")),x;var f=c(e,a.iterator,b.arg);if("throw"===f.type)return b.method="throw",b.arg=f.arg,b.delegate=null,x;var g=f.arg;return g?g.done?(b[a.resultName]=g.value,b.next=a.nextLoc,"return"!==b.method&&(b.method="next",b.arg=void 0),b.delegate=null,x):g:(b.method="throw",b.arg=new TypeError("iterator result is not an object"),b.delegate=null,x)}function k(a){var b={tryLoc:a[0]};1 in a&&(b.catchLoc=a[1]),2 in a&&(b.finallyLoc=a[2],b.afterLoc=a[3]),this.tryEntries.push(b)}function l(a){var b=a.completion||{};b.type="normal",delete b.arg,a.completion=b}function m(a){this.tryEntries=[{tryLoc:"root"}],a.forEach(k,this),this.reset(!0)}function n(a){if(a){var b=a[u];if(b)return b.call(a);if("function"==typeof a.next)return a;if(!isNaN(a.length)){var c=-1,d=function b(){for(;++c<a.length;)if(r.call(a,c))return b.value=a[c],b.done=!1,b;return b.value=void 0,b.done=!0,b};return d.next=d}}return{next:o}}function o(){return{value:void 0,done:!0}}_regeneratorRuntime=function(){return p};var p={},q=Object.prototype,r=q.hasOwnProperty,s=Object.defineProperty||function(a,b,c){a[b]=c.value},t="function"==typeof Symbol?Symbol:{},u=t.iterator||"@@iterator",v=t.asyncIterator||"@@asyncIterator",w=t.toStringTag||"@@toStringTag";try{a({},"")}catch(b){a=function(a,b,c){return a[b]=c}}p.wrap=b;var x={},y={};a(y,u,function(){return this});var z=Object.getPrototypeOf,A=z&&z(z(n([])));A&&A!==q&&r.call(A,u)&&(y=A);var B=f.prototype=d.prototype=Object.create(y);return e.prototype=f,s(B,"constructor",{value:f,configurable:!0}),s(f,"constructor",{value:e,configurable:!0}),e.displayName=a(f,w,"GeneratorFunction"),p.isGeneratorFunction=function(a){var b="function"==typeof a&&a.constructor;return!!b&&(b===e||"GeneratorFunction"===(b.displayName||b.name))},p.mark=function(b){return Object.setPrototypeOf?Object.setPrototypeOf(b,f):(b.__proto__=f,a(b,w,"GeneratorFunction")),b.prototype=Object.create(B),b},p.awrap=function(a){return{__await:a}},g(h.prototype),a(h.prototype,v,function(){return this}),p.AsyncIterator=h,p.async=function(a,c,d,e,f){void 0===f&&(f=Promise);var g=new h(b(a,c,d,e),f);return p.isGeneratorFunction(c)?g:g.next().then(function(a){return a.done?a.value:g.next()})},g(B),a(B,w,"Generator"),a(B,u,function(){return this}),a(B,"toString",function(){return"[object Generator]"}),p.keys=function(a){var b=Object(a),c=[];for(var d in b)c.push(d);return c.reverse(),function a(){for(;c.length;){var d=c.pop();if(d in b)return a.value=d,a.done=!1,a}return a.done=!0,a}},p.values=n,m.prototype={constructor:m,reset:function reset(a){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(l),!a)for(var b in this)"t"===b.charAt(0)&&r.call(this,b)&&!isNaN(+b.slice(1))&&(this[b]=void 0)},stop:function stop(){this.done=!0;var a=this.tryEntries[0].completion;if("throw"===a.type)throw a.arg;return this.rval},dispatchException:function dispatchException(a){function b(b,d){return f.type="throw",f.arg=a,c.next=b,d&&(c.method="next",c.arg=void 0),!!d}if(this.done)throw a;for(var c=this,d=this.tryEntries.length-1;0<=d;--d){var e=this.tryEntries[d],f=e.completion;if("root"===e.tryLoc)return b("end");if(e.tryLoc<=this.prev){var g=r.call(e,"catchLoc"),h=r.call(e,"finallyLoc");if(g&&h){if(this.prev<e.catchLoc)return b(e.catchLoc,!0);if(this.prev<e.finallyLoc)return b(e.finallyLoc)}else if(!g){if(!h)throw new Error("try statement without catch or finally");if(this.prev<e.finallyLoc)return b(e.finallyLoc)}else if(this.prev<e.catchLoc)return b(e.catchLoc,!0)}}},abrupt:function abrupt(a,b){for(var c,d=this.tryEntries.length-1;0<=d;--d)if(c=this.tryEntries[d],c.tryLoc<=this.prev&&r.call(c,"finallyLoc")&&this.prev<c.finallyLoc){var e=c;break}e&&("break"===a||"continue"===a)&&e.tryLoc<=b&&b<=e.finallyLoc&&(e=null);var f=e?e.completion:{};return f.type=a,f.arg=b,e?(this.method="next",this.next=e.finallyLoc,x):this.complete(f)},complete:function complete(a,b){if("throw"===a.type)throw a.arg;return"break"===a.type||"continue"===a.type?this.next=a.arg:"return"===a.type?(this.rval=this.arg=a.arg,this.method="return",this.next="end"):"normal"===a.type&&b&&(this.next=b),x},finish:function finish(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.finallyLoc===a)return this.complete(b.completion,b.afterLoc),l(b),x},catch:function _catch(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.tryLoc===a){var d=b.completion;if("throw"===d.type){var e=d.arg;l(b)}return e}throw new Error("illegal catch attempt")},delegateYield:function delegateYield(a,b,c){return this.delegate={iterator:n(a),resultName:b,nextLoc:c},"next"===this.method&&(this.arg=void 0),x}},p}function asyncGeneratorStep(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){return void c(a)}h.done?b(i):Promise.resolve(i).then(d,e)}function _asyncToGenerator(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){function f(a){asyncGeneratorStep(h,d,e,f,g,"next",a)}function g(a){asyncGeneratorStep(h,d,e,f,g,"throw",a)}var h=a.apply(b,c);f(void 0)})}}var crypto,lname="list_var";try{crypto=require("@azrico/crypto")}catch(a){}function add_var(){return _add_var.apply(this,arguments)}function _add_var(){return _add_var=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function d(a,b,c){var e;return _regeneratorRuntime().wrap(function f(d){for(;1;)switch(d.prev=d.next){case 0:return d.next=2,get_var(a,c);case 2:return e=d.sent,Array.isArray(e)||(e=[]),e.push(b),d.next=7,set_var(a,e,c);case 7:return d.abrupt("return",e);case 8:case"end":return d.stop();}},d)})),_add_var.apply(this,arguments)}function get_var_sync(a){var b=_core["default"].Global_get(lname,a),c="string"==typeof b;return c?(b=_optional_dec(b),b):b}function set_var_sync(a,b){var c=b,d="string"==typeof c;return d&&(c=_optional_enc(c)),_core["default"].Global_set(lname,a,c),c}function get_var(a,b){return _get_var.apply(this,arguments)}function _get_var(){return _get_var=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function c(a,b){var d,e,f,g,h;return _regeneratorRuntime().wrap(function i(c){for(;1;)switch(c.prev=c.next){case 0:if(b||(b={}),d=b.json,e=null,e=_core["default"].Global_get(lname,a),null==e&&b.local_storage&&(f="list_var_"+a,e=localStorage[f]),!(null==e&&b.session)){c.next=10;break}return g=window.sessionStorage,c.next=9,g.getItem(a);case 9:e=c.sent;case 10:if(!(null==e&&b.storage)){c.next=14;break}return c.next=13,_asyncStorage["default"].getItem(a);case 13:e=c.sent;case 14:if(null!=e){c.next=16;break}return c.abrupt("return",null);case 16:if(h="string"==typeof e,h){c.next=19;break}return c.abrupt("return",e);case 19:return c.next=21,_optional_dec(e);case 21:if(e=c.sent,d)try{e=JSON.parse(e)}catch(a){}return c.abrupt("return",e);case 24:case"end":return c.stop();}},c)})),_get_var.apply(this,arguments)}function set_var(a,b,c){return _set_var.apply(this,arguments)}/* -------------------------------------------------------------------------- */ /* if we have crypto support use it, dont throw error otherwise */ /* -------------------------------------------------------------------------- */function _set_var(){return _set_var=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function d(a,b,c){var e,f,g,h,i;return _regeneratorRuntime().wrap(function j(d){for(;1;)switch(d.prev=d.next){case 0:if(c||(c={}),e=b,f=c.json&&"function"!=typeof e,f)try{e=JSON.stringify(e)}catch(a){}if((null===e||void 0===e)&&(e=""),g="string"==typeof e,g&&(e=_optional_enc(e)),_core["default"].Global_set(lname,a,e),!c.local_storage){d.next=13;break}if(g){d.next=11;break}throw new Error("You cant save non-string values in local_storage !");case 11:h="list_var_"+a,localStorage[h]=e;case 13:if(!c.session){d.next=18;break}if(g){d.next=16;break}throw new Error("You cant save non-string values in session !");case 16:i=window.sessionStorage,""===e?i.removeItem(a):i.setItem(a,e);case 18:if(!c.storage){d.next=28;break}if(g){d.next=21;break}throw new Error("You cant save non-string values in AsyncStorage !");case 21:if(""===e){d.next=26;break}return d.next=24,_asyncStorage["default"].setItem(a,e);case 24:d.next=28;break;case 26:return d.next=28,_asyncStorage["default"].removeItem(a);case 28:return d.abrupt("return",e);case 29:case"end":return d.stop();}},d)})),_set_var.apply(this,arguments)}function _optional_dec(a){return crypto?crypto.decrypt(a):a}function _optional_enc(a){return crypto?crypto.encrypt(a):a}/* -------------------------------------------------------------------------- */function hold_var(a,b,c){return _react["default"].useEffect(function(){return set_var(a,b,c),function(){set_var(a,null,c)}},[b]),b}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";var _g_storage=require("./g_storage");Object.defineProperty(exports,"__esModule",{value:!0});Object.keys(_g_storage).forEach(function(a){"default"===a||"__esModule"===a||a in exports&&exports[a]===_g_storage[a]||Object.defineProperty(exports,a,{enumerable:!0,get:function get(){return _g_storage[a]}})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azrico/global",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.17",
|
|
4
4
|
"description": "Simple global functions and helpers",
|
|
5
5
|
"author": "Azrideus",
|
|
6
6
|
"license": "MIT",
|
|
@@ -82,5 +82,8 @@
|
|
|
82
82
|
"@react-native-async-storage/async-storage": "^1.15.5",
|
|
83
83
|
"pullstate": "^1.24.0",
|
|
84
84
|
"react": "^18.0.0"
|
|
85
|
+
},
|
|
86
|
+
"optionalDependencies": {
|
|
87
|
+
"@azrico/crypto": "^1.0.1"
|
|
85
88
|
}
|
|
86
89
|
}
|