@azrico/webobject 1.2.17 → 1.2.18

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.
@@ -1,575 +1,181 @@
1
- "use strict";
2
-
3
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports["default"] = exports.ObjectManager = void 0;
9
-
10
- var _event = require("@azrico/event");
11
-
12
- var _SimpleObject = _interopRequireDefault(require("./SimpleObject"));
13
-
14
- var _string = require("@azrico/string");
15
-
16
- var _global = require("@azrico/global");
17
-
18
- var _object = require("@azrico/object");
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
21
-
22
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
23
-
24
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
25
-
26
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
27
-
28
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
29
-
30
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
31
-
32
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
33
-
34
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
35
-
1
+ import { EventManager } from "@azrico/event";
2
+ import SimpleObject from "./SimpleObject";
3
+ import { combine_if_not_blank } from "@azrico/string";
4
+ import { gfunc } from "@azrico/global";
5
+ import { object_equals_loose } from "@azrico/object";
36
6
  /**
37
7
  * This class manages the events of an Simple Object
38
- */
39
- var ObjectManager = /*#__PURE__*/function () {
40
- function ObjectManager() {
41
- _classCallCheck(this, ObjectManager);
42
-
43
- _defineProperty(this, "__eventList", void 0);
44
-
45
- _defineProperty(this, "__eventPrefix", void 0);
46
-
47
- _defineProperty(this, "__sendEvents", true);
48
-
49
- _defineProperty(this, "__currentObject", void 0);
50
-
51
- _defineProperty(this, "__options", void 0);
52
-
53
- _defineProperty(this, "get", this.getValue);
54
- }
55
-
56
- _createClass(ObjectManager, [{
57
- key: "notifyChanged",
58
- value: function () {
59
- var _notifyChanged = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(type, key, value, subvalue) {
60
- var obj, typestr;
61
- return _regeneratorRuntime().wrap(function _callee$(_context) {
62
- while (1) {
63
- switch (_context.prev = _context.next) {
64
- case 0:
65
- obj = this.getObject();
66
-
67
- if (obj) {
68
- _context.next = 3;
69
- break;
70
- }
71
-
72
- return _context.abrupt("return", false);
73
-
74
- case 3:
75
- if (value === undefined && type != "meta") value = obj.getValue(key);
76
- typestr = (type ? "$".concat(type, "$") : "") + String(key);
77
- _context.next = 7;
78
- return this.event_run("on_change", typestr, value);
79
-
80
- case 7:
81
- return _context.abrupt("return", _context.sent);
82
-
83
- case 8:
84
- case "end":
85
- return _context.stop();
86
- }
87
- }
88
- }, _callee, this);
89
- }));
90
-
91
- function notifyChanged(_x, _x2, _x3, _x4) {
92
- return _notifyChanged.apply(this, arguments);
93
- }
94
-
95
- return notifyChanged;
96
- }()
97
- /* -------------------------------------------------------------------------- */
98
-
99
- }, {
100
- key: "obj",
101
- get: function get() {
102
- return this.getObject();
103
- }
8
+ */
9
+ export class ObjectManager {
10
+ __eventList;
11
+ __eventPrefix;
12
+ __sendEvents = true;
13
+ __currentObject;
14
+ __options;
15
+ async notifyChanged(type, key, value, subvalue) {
16
+ const obj = this.getObject();
17
+ if (!obj)
18
+ return false;
19
+ if (value === undefined && type != "meta")
20
+ value = obj.getValue(key);
21
+ const typestr = (type ? `$${type}$` : "") + String(key);
22
+ return await this.event_run("on_change", typestr, value);
23
+ }
24
+ /* -------------------------------------------------------------------------- */
25
+ get obj() {
26
+ return this.getObject();
27
+ }
104
28
  /**
105
29
  * Get the object this manager is managing
106
30
  * @returns the object
107
- */
108
-
109
- }, {
110
- key: "getObject",
111
- value: function getObject() {
112
- var _this$__currentObject;
113
-
114
- return (_this$__currentObject = this.__currentObject) !== null && _this$__currentObject !== void 0 ? _this$__currentObject : undefined;
115
- }
31
+ */
32
+ getObject() {
33
+ return this.__currentObject ?? undefined;
34
+ }
116
35
  /**
117
36
  * Set the object this manager is managing
118
37
  * @param toObj
119
38
  * @returns
120
- */
121
-
122
- }, {
123
- key: "setObject",
124
- value: function setObject(toObj) {
125
- var _this = this;
126
-
127
- this.__currentObject = toObj;
128
-
129
- if (this.__currentObject) {
130
- this.__currentObject.get_managerClass = function () {
131
- return _this;
132
- };
133
- }
134
-
135
- return true;
136
- }
137
- /* -------------------------------------------------------------------------- */
138
-
139
- /* Child functions */
140
-
141
- /* -------------------------------------------------------------------------- */
142
-
143
- }, {
144
- key: "isChanged",
145
- get: function get() {
146
- return this.obj != null && this.obj.isChanged;
147
- }
148
- }, {
149
- key: "isDeleted",
150
- get: function get() {
151
- return this.obj == null || this.obj.isDeleted;
152
- }
153
- }, {
154
- key: "d",
155
- get: function get() {
156
- var _this$obj;
157
-
158
- return (_this$obj = this.obj) === null || _this$obj === void 0 ? void 0 : _this$obj.d;
159
- }
160
- }, {
161
- key: "canModify",
162
- get: function get() {
163
- var _this$obj2;
164
-
165
- return !((_this$obj2 = this.obj) !== null && _this$obj2 !== void 0 && _this$obj2.canModify);
166
- }
167
- }, {
168
- key: "isNew",
169
- get: function get() {
170
- return this.obj == null || this.obj.isNew;
171
- }
172
- }, {
173
- key: "isSaved",
174
- get: function get() {
175
- var _this$obj3;
176
-
177
- return ((_this$obj3 = this.obj) === null || _this$obj3 === void 0 ? void 0 : _this$obj3.isSaved) || false;
178
- }
179
- }, {
180
- key: "__cache_name",
181
- get: function get() {
182
- return this.constructor["__cache_name"];
183
- }
184
- }, {
185
- key: "getSaveResult",
186
- value: function getSaveResult() {
187
- var _this$getObject;
188
-
189
- return ((_this$getObject = this.getObject()) === null || _this$getObject === void 0 ? void 0 : _this$getObject.getSaveResult()) || undefined;
190
- }
191
- }, {
192
- key: "getSaveResultType",
193
- value: function getSaveResultType() {
194
- var _this$getObject2;
195
-
196
- return ((_this$getObject2 = this.getObject()) === null || _this$getObject2 === void 0 ? void 0 : _this$getObject2.getSaveResultType()) || null;
197
- }
198
- }, {
199
- key: "setSaveResult",
200
- value: function setSaveResult(toObj, type) {
201
- return this.setSaveResult(toObj, type);
202
- }
203
- }, {
204
- key: "apply_changes",
205
- value: function apply_changes() {
206
- var _this$obj4;
207
-
208
- return (_this$obj4 = this.obj) === null || _this$obj4 === void 0 ? void 0 : _this$obj4.apply_changes();
209
- }
210
- }, {
211
- key: "getValue",
212
- value: function getValue(key) {
213
- var _this$obj5;
214
-
215
- var original = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
216
- return (_this$obj5 = this.obj) === null || _this$obj5 === void 0 ? void 0 : _this$obj5.getValue(key, original);
217
- }
218
- }, {
219
- key: "setValue",
220
- value:
39
+ */
40
+ setObject(toObj) {
41
+ this.__currentObject = toObj;
42
+ if (this.__currentObject) {
43
+ this.__currentObject.get_managerClass = (() => {
44
+ return this;
45
+ });
46
+ }
47
+ return true;
48
+ }
49
+ /* -------------------------------------------------------------------------- */
50
+ /* Child functions */
51
+ /* -------------------------------------------------------------------------- */
52
+ get isChanged() {
53
+ return this.obj != null && this.obj.isChanged;
54
+ }
55
+ get isDeleted() {
56
+ return this.obj == null || this.obj.isDeleted;
57
+ }
58
+ get d() {
59
+ return this.obj?.d;
60
+ }
61
+ get canModify() {
62
+ return !this.obj?.canModify;
63
+ }
64
+ get isNew() {
65
+ return this.obj == null || this.obj.isNew;
66
+ }
67
+ get isSaved() {
68
+ return this.obj?.isSaved || false;
69
+ }
70
+ get __cache_name() {
71
+ return this.constructor["__cache_name"];
72
+ }
73
+ getSaveResult() {
74
+ return this.getObject()?.getSaveResult() || undefined;
75
+ }
76
+ getSaveResultType() {
77
+ return this.getObject()?.getSaveResultType() || null;
78
+ }
79
+ setSaveResult(toObj, type) {
80
+ return this.setSaveResult(toObj, type);
81
+ }
82
+ apply_changes() {
83
+ return this.obj?.apply_changes();
84
+ }
85
+ getValue(key, original = false) {
86
+ return this.obj?.getValue(key, original);
87
+ }
88
+ get = this.getValue;
221
89
  /**
222
90
  * set value
223
91
  * @param key
224
92
  * @param value
225
93
  * @return true if changed , false otherwise
226
- */
227
- function () {
228
- var _setValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(key, value) {
229
- var _this$obj6;
230
-
231
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
232
- while (1) {
233
- switch (_context2.prev = _context2.next) {
234
- case 0:
235
- _context2.next = 2;
236
- return (_this$obj6 = this.obj) === null || _this$obj6 === void 0 ? void 0 : _this$obj6.setValue(key, value);
237
-
238
- case 2:
239
- _context2.t0 = _context2.sent;
240
-
241
- if (_context2.t0) {
242
- _context2.next = 5;
243
- break;
244
- }
245
-
246
- _context2.t0 = false;
247
-
248
- case 5:
249
- return _context2.abrupt("return", _context2.t0);
250
-
251
- case 6:
252
- case "end":
253
- return _context2.stop();
254
- }
255
- }
256
- }, _callee2, this);
257
- }));
258
-
259
- function setValue(_x5, _x6) {
260
- return _setValue.apply(this, arguments);
261
- }
262
-
263
- return setValue;
264
- }()
94
+ */
95
+ async setValue(key, value) {
96
+ return (await this.obj?.setValue(key, value)) || false;
97
+ }
265
98
  /**
266
99
  * set key of subObject
267
100
  * @param key
268
101
  * @param value
269
102
  * @param subvalue
270
103
  * @return true if changed , false otherwise
271
- */
272
-
273
- }, {
274
- key: "setSubValue",
275
- value: function () {
276
- var _setSubValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(key, objKey, subvalue) {
277
- var _this$obj7;
278
-
279
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
280
- while (1) {
281
- switch (_context3.prev = _context3.next) {
282
- case 0:
283
- _context3.next = 2;
284
- return (_this$obj7 = this.obj) === null || _this$obj7 === void 0 ? void 0 : _this$obj7.setSubValue(key, objKey, subvalue);
285
-
286
- case 2:
287
- _context3.t0 = _context3.sent;
288
-
289
- if (_context3.t0) {
290
- _context3.next = 5;
291
- break;
292
- }
293
-
294
- _context3.t0 = false;
295
-
296
- case 5:
297
- return _context3.abrupt("return", _context3.t0);
298
-
299
- case 6:
300
- case "end":
301
- return _context3.stop();
302
- }
303
- }
304
- }, _callee3, this);
305
- }));
306
-
307
- function setSubValue(_x7, _x8, _x9) {
308
- return _setSubValue.apply(this, arguments);
309
- }
310
-
311
- return setSubValue;
312
- }() //Push value on array
313
-
314
- }, {
315
- key: "pushValue",
316
- value: function () {
317
- var _pushValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(key, value) {
318
- var _this$obj8;
319
-
320
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
321
- while (1) {
322
- switch (_context4.prev = _context4.next) {
323
- case 0:
324
- _context4.next = 2;
325
- return (_this$obj8 = this.obj) === null || _this$obj8 === void 0 ? void 0 : _this$obj8.pushValue(key, value);
326
-
327
- case 2:
328
- _context4.t0 = _context4.sent;
329
-
330
- if (_context4.t0) {
331
- _context4.next = 5;
332
- break;
333
- }
334
-
335
- _context4.t0 = false;
336
-
337
- case 5:
338
- return _context4.abrupt("return", _context4.t0);
339
-
340
- case 6:
341
- case "end":
342
- return _context4.stop();
343
- }
344
- }
345
- }, _callee4, this);
346
- }));
347
-
348
- function pushValue(_x10, _x11) {
349
- return _pushValue.apply(this, arguments);
350
- }
351
-
352
- return pushValue;
353
- }()
354
- /* -------------------------------------------------------------------------- */
355
-
356
- }, {
357
- key: "getIndexOrID",
358
- value: function getIndexOrID() {
359
- var _this$obj9;
360
-
361
- return ((_this$obj9 = this.obj) === null || _this$obj9 === void 0 ? void 0 : _this$obj9.getIndexOrID()) || -1;
362
- }
363
- }, {
364
- key: "getIndex",
365
- value: function getIndex() {
366
- var _this$obj10;
367
-
368
- return ((_this$obj10 = this.obj) === null || _this$obj10 === void 0 ? void 0 : _this$obj10.getIndex()) || -1;
369
- }
370
- }, {
371
- key: "getID",
372
- value: function getID() {
373
- var _this$obj11;
374
-
375
- return ((_this$obj11 = this.obj) === null || _this$obj11 === void 0 ? void 0 : _this$obj11.getID()) || "";
376
- }
377
- /* -------------------------------------------------------------------------- */
378
-
379
- /* Getters */
380
-
381
- /* -------------------------------------------------------------------------- */
382
-
383
- /* -------------------------------------------------------------------------- */
384
-
385
- /* Events */
386
-
387
- /* -------------------------------------------------------------------------- */
388
-
389
- }, {
390
- key: "event_run",
391
- value: function () {
392
- var _event_run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(eventName) {
393
- var _len,
394
- params,
395
- _key,
396
- _args5 = arguments;
397
-
398
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
399
- while (1) {
400
- switch (_context5.prev = _context5.next) {
401
- case 0:
402
- if (this.__sendEvents) {
403
- _context5.next = 2;
404
- break;
405
- }
406
-
407
- return _context5.abrupt("return");
408
-
409
- case 2:
410
- for (_len = _args5.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
411
- params[_key - 1] = _args5[_key];
412
- }
413
-
414
- _context5.next = 5;
415
- return _event.EventManager.run.apply(_event.EventManager, [this, eventName].concat(params));
416
-
417
- case 5:
418
- case "end":
419
- return _context5.stop();
420
- }
421
- }
422
- }, _callee5, this);
423
- }));
424
-
425
- function event_run(_x12) {
426
- return _event_run.apply(this, arguments);
427
- }
428
-
429
- return event_run;
430
- }()
431
- }, {
432
- key: "event_use",
433
- value: function event_use(name, runEvent) {
434
- var onlyOn = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
435
- var runOnce = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
436
- return _event.EventManager.use(this, name, runEvent, onlyOn, runOnce);
437
- }
438
- }, {
439
- key: "event_remove",
440
- value: function event_remove(name, uname) {
441
- return _event.EventManager.remove(this, name, uname);
442
- }
443
- }, {
444
- key: "event_add",
445
- value: function () {
446
- var _event_add = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(name, uname, runEvent) {
447
- var onlyOn,
448
- runOnce,
449
- _args6 = arguments;
450
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
451
- while (1) {
452
- switch (_context6.prev = _context6.next) {
453
- case 0:
454
- onlyOn = _args6.length > 3 && _args6[3] !== undefined ? _args6[3] : null;
455
- runOnce = _args6.length > 4 && _args6[4] !== undefined ? _args6[4] : false;
456
- _context6.next = 4;
457
- return _event.EventManager.add(this, name, uname, runEvent, onlyOn, runOnce);
458
-
459
- case 4:
460
- case "end":
461
- return _context6.stop();
462
- }
463
- }
464
- }, _callee6, this);
465
- }));
466
-
467
- function event_add(_x13, _x14, _x15) {
468
- return _event_add.apply(this, arguments);
469
- }
470
-
471
- return event_add;
472
- }()
473
- }, {
474
- key: "events_stop",
475
- value: function events_stop() {
476
- this.__sendEvents = false;
477
- }
478
- }, {
479
- key: "events_clear",
480
- value: function events_clear() {
481
- ObjectManager.events_clear(this);
482
- }
483
- }, {
484
- key: "toggleOption",
485
- value:
486
- /* -------------------------------------------------------------------------- */
487
-
488
- /* Options */
489
-
490
- /* -------------------------------------------------------------------------- */
491
-
104
+ */
105
+ async setSubValue(key, objKey, subvalue) {
106
+ return ((await this.obj?.setSubValue(key, objKey, subvalue)) || false);
107
+ }
108
+ //Push value on array
109
+ async pushValue(key, value) {
110
+ return (await this.obj?.pushValue(key, value)) || false;
111
+ }
112
+ /* -------------------------------------------------------------------------- */
113
+ getIndexOrID() {
114
+ return this.obj?.getIndexOrID() || -1;
115
+ }
116
+ getIndex() {
117
+ return this.obj?.getIndex() || -1;
118
+ }
119
+ getID() {
120
+ return this.obj?.getID() || "";
121
+ }
122
+ /* -------------------------------------------------------------------------- */
123
+ /* Getters */
124
+ /* -------------------------------------------------------------------------- */
125
+ /* -------------------------------------------------------------------------- */
126
+ /* Events */
127
+ /* -------------------------------------------------------------------------- */
128
+ async event_run(eventName, ...params) {
129
+ if (!this.__sendEvents)
130
+ return;
131
+ await EventManager.run(this, eventName, ...params);
132
+ }
133
+ event_use(name, runEvent, onlyOn = null, runOnce = false) {
134
+ return EventManager.use(this, name, runEvent, onlyOn, runOnce);
135
+ }
136
+ event_remove(name, uname) {
137
+ return EventManager.remove(this, name, uname);
138
+ }
139
+ async event_add(name, uname, runEvent, onlyOn = null, runOnce = false) {
140
+ await EventManager.add(this, name, uname, runEvent, onlyOn, runOnce);
141
+ }
142
+ events_stop() {
143
+ this.__sendEvents = false;
144
+ }
145
+ events_clear() {
146
+ ObjectManager.events_clear(this);
147
+ }
148
+ static events_clear(obj) {
149
+ EventManager.removeAll(obj);
150
+ }
151
+ /* -------------------------------------------------------------------------- */
152
+ /* Options */
153
+ /* -------------------------------------------------------------------------- */
492
154
  /**
493
155
  * Set an option to some value, if its already equal to the value it will be deleted instead
494
156
  * @param key
495
157
  * @param value
496
158
  * @returns
497
- */
498
- function () {
499
- var _toggleOption = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(key, value) {
500
- var oldval;
501
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
502
- while (1) {
503
- switch (_context7.prev = _context7.next) {
504
- case 0:
505
- oldval = this.getOption(key);
506
-
507
- if (!(0, _object.object_equals_loose)(oldval, value)) {
508
- _context7.next = 6;
509
- break;
510
- }
511
-
512
- _context7.next = 4;
513
- return this.setOption(key, null);
514
-
515
- case 4:
516
- _context7.next = 8;
517
- break;
518
-
519
- case 6:
520
- _context7.next = 8;
521
- return this.setOption(key, value);
522
-
523
- case 8:
524
- case "end":
525
- return _context7.stop();
526
- }
527
- }
528
- }, _callee7, this);
529
- }));
530
-
531
- function toggleOption(_x16, _x17) {
532
- return _toggleOption.apply(this, arguments);
533
- }
534
-
535
- return toggleOption;
536
- }()
537
- }, {
538
- key: "setOption",
539
- value: function () {
540
- var _setOption = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(key, value) {
541
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
542
- while (1) {
543
- switch (_context8.prev = _context8.next) {
544
- case 0:
545
- if (this.__options == null) this.__options = {};
546
-
547
- if (value == null) {
548
- delete this.__options[key];
549
- } else {
550
- this.__options[key] = value;
551
- }
552
-
553
- _context8.next = 4;
554
- return this.event_run("on_option_change", key, value);
555
-
556
- case 4:
557
- return _context8.abrupt("return", _context8.sent);
558
-
559
- case 5:
560
- case "end":
561
- return _context8.stop();
562
- }
563
- }
564
- }, _callee8, this);
565
- }));
566
-
567
- function setOption(_x18, _x19) {
568
- return _setOption.apply(this, arguments);
569
- }
570
-
571
- return setOption;
572
- }()
159
+ */
160
+ async toggleOption(key, value) {
161
+ var oldval = this.getOption(key);
162
+ if (object_equals_loose(oldval, value)) {
163
+ await this.setOption(key, null);
164
+ }
165
+ else
166
+ await this.setOption(key, value);
167
+ }
168
+ async setOption(key, value) {
169
+ if (this.__options == null)
170
+ this.__options = {};
171
+ if (value == null) {
172
+ delete this.__options[key];
173
+ }
174
+ else {
175
+ this.__options[key] = value;
176
+ }
177
+ return await this.event_run("on_option_change", key, value);
178
+ }
573
179
  /**
574
180
  * Sets an option then does an action,
575
181
  * after the action is run, updates the option again
@@ -577,113 +183,52 @@ var ObjectManager = /*#__PURE__*/function () {
577
183
  * @param value
578
184
  * @param nextvalue
579
185
  * @param action
580
- */
581
-
582
- }, {
583
- key: "holdOption",
584
- value: function () {
585
- var _holdOption = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(key, value, nextvalue, action) {
586
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
587
- while (1) {
588
- switch (_context9.prev = _context9.next) {
589
- case 0:
590
- _context9.prev = 0;
591
- this.setOption(key, value);
592
-
593
- if (!(typeof action === "function")) {
594
- _context9.next = 5;
595
- break;
596
- }
597
-
598
- _context9.next = 5;
599
- return action();
600
-
601
- case 5:
602
- _context9.prev = 5;
603
- this.setOption(key, nextvalue);
604
- return _context9.finish(5);
605
-
606
- case 8:
607
- case "end":
608
- return _context9.stop();
609
- }
610
- }
611
- }, _callee9, this, [[0,, 5, 8]]);
612
- }));
613
-
614
- function holdOption(_x20, _x21, _x22, _x23) {
615
- return _holdOption.apply(this, arguments);
616
- }
617
-
618
- return holdOption;
619
- }()
620
- }, {
621
- key: "getOption",
622
- value: function getOption(key) {
623
- if (this.__options == null) return undefined;
624
- return this.__options[key];
625
- }
626
- /* -------------------------------------------------------------------------- */
627
-
628
- /* Errors */
629
-
630
- /* -------------------------------------------------------------------------- */
631
-
632
- }, {
633
- key: "addError",
634
- value: function addError(title, message) {
635
- var sendToRegister = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "auto";
636
- return ObjectManager.addError(this, title, message, sendToRegister);
637
- }
638
- }, {
639
- key: "getErrors",
640
- value: function getErrors() {
641
- return ObjectManager.getErrors(this);
642
- }
643
- }, {
644
- key: "clearErrors",
645
- value: function clearErrors() {
646
- return ObjectManager.clearErrors(this);
647
- }
648
- }], [{
649
- key: "events_clear",
650
- value: function events_clear(obj) {
651
- _event.EventManager.removeAll(obj);
652
- }
653
- }, {
654
- key: "addError",
655
- value: function addError(o, title, message) {
656
- var sendToRegister = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "auto";
657
-
658
- if (o && o.obj) {
659
- return _SimpleObject["default"].addError(o.obj, title, message, sendToRegister);
660
- }
661
-
662
- var errStr = (0, _string.combine_if_not_blank)(title, " : ", message);
663
- console.error("[REGISTER-ERROR]", errStr);
664
-
665
- _global.gfunc.run_action("add_error", {
666
- title: title,
667
- message: message,
668
- type: "error"
669
- });
670
- }
671
- }, {
672
- key: "getErrors",
673
- value: function getErrors(o) {
674
- var obj = o.obj;
675
- return obj != null ? _SimpleObject["default"].getErrors(o.obj) : [];
676
- }
677
- }, {
678
- key: "clearErrors",
679
- value: function clearErrors(o) {
680
- return _SimpleObject["default"].clearErrors(o.obj);
681
- }
682
- }]);
683
-
684
- return ObjectManager;
685
- }();
686
-
687
- exports.ObjectManager = ObjectManager;
688
- var _default = ObjectManager;
689
- exports["default"] = _default;
186
+ */
187
+ async holdOption(key, value, nextvalue, action) {
188
+ try {
189
+ this.setOption(key, value);
190
+ if (typeof action === "function")
191
+ await action();
192
+ }
193
+ finally {
194
+ this.setOption(key, nextvalue);
195
+ }
196
+ }
197
+ getOption(key) {
198
+ if (this.__options == null)
199
+ return undefined;
200
+ return this.__options[key];
201
+ }
202
+ /* -------------------------------------------------------------------------- */
203
+ /* Errors */
204
+ /* -------------------------------------------------------------------------- */
205
+ addError(title, message, sendToRegister = "auto") {
206
+ return ObjectManager.addError(this, title, message, sendToRegister);
207
+ }
208
+ getErrors() {
209
+ return ObjectManager.getErrors(this);
210
+ }
211
+ clearErrors() {
212
+ return ObjectManager.clearErrors(this);
213
+ }
214
+ static addError(o, title, message, sendToRegister = "auto") {
215
+ if (o && o.obj) {
216
+ return SimpleObject.addError(o.obj, title, message, sendToRegister);
217
+ }
218
+ const errStr = combine_if_not_blank(title, " : ", message);
219
+ console.error("[REGISTER-ERROR]", errStr);
220
+ gfunc.run_action("add_error", {
221
+ title: title,
222
+ message: message,
223
+ type: "error",
224
+ });
225
+ }
226
+ static getErrors(o) {
227
+ const obj = o.obj;
228
+ return obj != null ? SimpleObject.getErrors(o.obj) : [];
229
+ }
230
+ static clearErrors(o) {
231
+ return SimpleObject.clearErrors(o.obj);
232
+ }
233
+ }
234
+ export default ObjectManager;