@azrico/webobject 1.3.21 → 1.3.22

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,464 +1,189 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = exports.ObjectManager = void 0;
7
- var _event = require("@azrico/event");
8
- var _SimpleObject = _interopRequireDefault(require("./SimpleObject"));
9
- var _string = require("@azrico/string");
10
- var _global = require("@azrico/global");
11
- var _object = require("@azrico/object");
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
- 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); }
14
- 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, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $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 defineProperty(generator, "_invoke", { value: makeInvokeMethod(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; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(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); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), 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, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), 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 (val) { var object = Object(val), 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; }
15
- 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); } }
16
- 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); }); }; }
17
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
18
- 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, _toPropertyKey(descriptor.key), descriptor); } }
19
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
20
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
21
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
22
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
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";
23
6
  /**
24
7
  * This class manages the events of an Simple Object
25
- */
26
- var ObjectManager = /*#__PURE__*/function () {
27
- function ObjectManager() {
28
- _classCallCheck(this, ObjectManager);
29
- _defineProperty(this, "__eventList", void 0);
30
- _defineProperty(this, "__eventPrefix", void 0);
31
- _defineProperty(this, "__sendEvents", true);
32
- _defineProperty(this, "__currentObject", void 0);
33
- _defineProperty(this, "__options", void 0);
34
- _defineProperty(this, "get", this.getValue);
35
- }
36
- _createClass(ObjectManager, [{
37
- key: "notifyChanged",
38
- value: function () {
39
- var _notifyChanged = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(type, key, value, subvalue) {
40
- var obj, typestr;
41
- return _regeneratorRuntime().wrap(function _callee$(_context) {
42
- while (1) switch (_context.prev = _context.next) {
43
- case 0:
44
- obj = this.getObject();
45
- if (obj) {
46
- _context.next = 3;
47
- break;
48
- }
49
- return _context.abrupt("return", false);
50
- case 3:
51
- if (value === undefined && type != "meta") value = obj.getValue(key);
52
- typestr = (type ? "$".concat(type, "$") : "") + String(key);
53
- _context.next = 7;
54
- return this.event_run("on_change", typestr, value);
55
- case 7:
56
- return _context.abrupt("return", _context.sent);
57
- case 8:
58
- case "end":
59
- return _context.stop();
60
- }
61
- }, _callee, this);
62
- }));
63
- function notifyChanged(_x, _x2, _x3, _x4) {
64
- return _notifyChanged.apply(this, arguments);
65
- }
66
- return notifyChanged;
67
- }() /* -------------------------------------------------------------------------- */
68
- }, {
69
- key: "obj",
70
- get: function get() {
71
- return this.getObject();
72
- }
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
+ }
73
28
  /**
74
29
  * Get the object this manager is managing
75
30
  * @returns the object
76
- */
77
- }, {
78
- key: "getObject",
79
- value: function getObject() {
80
- var _this$__currentObject;
81
- return (_this$__currentObject = this.__currentObject) !== null && _this$__currentObject !== void 0 ? _this$__currentObject : undefined;
82
- }
31
+ */
32
+ getObject() {
33
+ return this.__currentObject ?? undefined;
34
+ }
83
35
  /**
84
36
  * Set the object this manager is managing
85
37
  * @param toObj
86
38
  * @returns
87
- */
88
- }, {
89
- key: "setObject",
90
- value: function setObject(toObj) {
91
- this.__currentObject = toObj;
92
- if (this.__currentObject) {
93
- this.__currentObject.set_managerClass(this);
94
- }
95
- if (toObj == null) {
96
- console.warn("setObject was used to set null. try to use empty objects instead of null");
97
- }
98
- return true;
99
- }
100
- /* -------------------------------------------------------------------------- */
101
- /* Child functions */
102
- /* -------------------------------------------------------------------------- */
103
- }, {
104
- key: "isChanged",
105
- get: function get() {
106
- return this.obj != null && this.obj.isChanged;
107
- }
108
- }, {
109
- key: "isDeleted",
110
- get: function get() {
111
- return this.obj == null || this.obj.isDeleted;
112
- }
113
- }, {
114
- key: "d",
115
- get: function get() {
116
- var _this$obj;
117
- return (_this$obj = this.obj) === null || _this$obj === void 0 ? void 0 : _this$obj.d;
118
- }
119
- }, {
120
- key: "canModify",
121
- get: function get() {
122
- var _this$obj2;
123
- return !((_this$obj2 = this.obj) !== null && _this$obj2 !== void 0 && _this$obj2.canModify);
124
- }
125
- }, {
126
- key: "isNew",
127
- get: function get() {
128
- return this.obj == null || this.obj.isNew;
129
- }
130
- }, {
131
- key: "isSaved",
132
- get: function get() {
133
- var _this$obj3;
134
- return ((_this$obj3 = this.obj) === null || _this$obj3 === void 0 ? void 0 : _this$obj3.isSaved) || false;
135
- }
136
- }, {
137
- key: "__cache_name",
138
- get: function get() {
139
- var _this$obj4;
140
- return ((_this$obj4 = this.obj) === null || _this$obj4 === void 0 ? void 0 : _this$obj4.__cache_name) || "";
141
- }
142
- }, {
143
- key: "getSaveResult",
144
- value: function getSaveResult() {
145
- var _this$getObject;
146
- return ((_this$getObject = this.getObject()) === null || _this$getObject === void 0 ? void 0 : _this$getObject.getSaveResult()) || undefined;
147
- }
148
- }, {
149
- key: "getSaveResultType",
150
- value: function getSaveResultType() {
151
- var _this$getObject2;
152
- return ((_this$getObject2 = this.getObject()) === null || _this$getObject2 === void 0 ? void 0 : _this$getObject2.getSaveResultType()) || null;
153
- }
154
- }, {
155
- key: "setSaveResult",
156
- value: function setSaveResult(toObj, type) {
157
- var _this$getObject3;
158
- return (_this$getObject3 = this.getObject()) === null || _this$getObject3 === void 0 ? void 0 : _this$getObject3.setSaveResult(toObj, type);
159
- }
160
- }, {
161
- key: "apply_changes",
162
- value: function apply_changes() {
163
- var _this$obj5;
164
- return ((_this$obj5 = this.obj) === null || _this$obj5 === void 0 ? void 0 : _this$obj5.apply_changes()) || false;
165
- }
166
- }, {
167
- key: "getValue",
168
- value: function getValue(key) {
169
- var original = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
170
- var thisobj = this.obj;
171
- if (thisobj == null || typeof thisobj.getValue != "function") {
172
- console.error("cant use getValue when object is not defined. maybe you have to use New() ?");
173
- return null;
174
- }
175
- return thisobj.getValue(key, original);
176
- }
177
- }, {
178
- key: "setValue",
179
- value:
39
+ */
40
+ setObject(toObj) {
41
+ this.__currentObject = toObj;
42
+ if (this.__currentObject) {
43
+ this.__currentObject.set_managerClass(this);
44
+ }
45
+ if (toObj == null) {
46
+ console.warn("setObject was used to set null. try to use empty objects instead of null");
47
+ }
48
+ return true;
49
+ }
50
+ /* -------------------------------------------------------------------------- */
51
+ /* Child functions */
52
+ /* -------------------------------------------------------------------------- */
53
+ get isChanged() {
54
+ return this.obj != null && this.obj.isChanged;
55
+ }
56
+ get isDeleted() {
57
+ return this.obj == null || this.obj.isDeleted;
58
+ }
59
+ get d() {
60
+ return this.obj?.d;
61
+ }
62
+ get canModify() {
63
+ return !this.obj?.canModify;
64
+ }
65
+ get isNew() {
66
+ return this.obj == null || this.obj.isNew;
67
+ }
68
+ get isSaved() {
69
+ return this.obj?.isSaved || false;
70
+ }
71
+ get __cache_name() {
72
+ return this.obj?.__cache_name || "";
73
+ }
74
+ getSaveResult() {
75
+ return this.getObject()?.getSaveResult() || undefined;
76
+ }
77
+ getSaveResultType() {
78
+ return this.getObject()?.getSaveResultType() || null;
79
+ }
80
+ setSaveResult(toObj, type) {
81
+ return this.getObject()?.setSaveResult(toObj, type);
82
+ }
83
+ apply_changes() {
84
+ return this.obj?.apply_changes() || false;
85
+ }
86
+ getValue(key, original = false) {
87
+ const thisobj = this.obj;
88
+ if (thisobj == null || typeof thisobj.getValue != "function") {
89
+ console.error("cant use getValue when object is not defined. maybe you have to use New() ?");
90
+ return null;
91
+ }
92
+ return thisobj.getValue(key, original);
93
+ }
94
+ get = this.getValue;
180
95
  /**
181
96
  * set value
182
97
  * @param key
183
98
  * @param value
184
99
  * @return true if changed , false otherwise
185
- */
186
- function () {
187
- var _setValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(key, value) {
188
- var thisobj;
189
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
190
- while (1) switch (_context2.prev = _context2.next) {
191
- case 0:
192
- thisobj = this.obj;
193
- if (!(thisobj == null || typeof thisobj.setValue != "function")) {
194
- _context2.next = 4;
195
- break;
196
- }
197
- console.error("cant use setValue when object is not defined. maybe you have to use New() ?");
198
- return _context2.abrupt("return", false);
199
- case 4:
200
- _context2.next = 6;
201
- return thisobj.setValue(key, value);
202
- case 6:
203
- _context2.t0 = _context2.sent;
204
- if (_context2.t0) {
205
- _context2.next = 9;
206
- break;
207
- }
208
- _context2.t0 = false;
209
- case 9:
210
- return _context2.abrupt("return", _context2.t0);
211
- case 10:
212
- case "end":
213
- return _context2.stop();
214
- }
215
- }, _callee2, this);
216
- }));
217
- function setValue(_x5, _x6) {
218
- return _setValue.apply(this, arguments);
219
- }
220
- return setValue;
221
- }()
100
+ */
101
+ async setValue(key, value) {
102
+ const thisobj = this.obj;
103
+ if (thisobj == null || typeof thisobj.setValue != "function") {
104
+ console.error("cant use setValue when object is not defined. maybe you have to use New() ?");
105
+ return false;
106
+ }
107
+ return (await thisobj.setValue(key, value)) || false;
108
+ }
222
109
  /**
223
110
  * set key of subObject
224
111
  * @param key
225
112
  * @param value
226
113
  * @param subvalue
227
114
  * @return true if changed , false otherwise
228
- */
229
- }, {
230
- key: "setSubValue",
231
- value: function () {
232
- var _setSubValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(key, objKey, subvalue) {
233
- var _this$obj6;
234
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
235
- while (1) switch (_context3.prev = _context3.next) {
236
- case 0:
237
- _context3.next = 2;
238
- return (_this$obj6 = this.obj) === null || _this$obj6 === void 0 ? void 0 : _this$obj6.setSubValue(key, objKey, subvalue);
239
- case 2:
240
- _context3.t0 = _context3.sent;
241
- if (_context3.t0) {
242
- _context3.next = 5;
243
- break;
244
- }
245
- _context3.t0 = false;
246
- case 5:
247
- return _context3.abrupt("return", _context3.t0);
248
- case 6:
249
- case "end":
250
- return _context3.stop();
251
- }
252
- }, _callee3, this);
253
- }));
254
- function setSubValue(_x7, _x8, _x9) {
255
- return _setSubValue.apply(this, arguments);
256
- }
257
- return setSubValue;
258
- }() //Push value on array
259
- }, {
260
- key: "pushValue",
261
- value: function () {
262
- var _pushValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(key, value) {
263
- var _this$obj7;
264
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
265
- while (1) switch (_context4.prev = _context4.next) {
266
- case 0:
267
- _context4.next = 2;
268
- return (_this$obj7 = this.obj) === null || _this$obj7 === void 0 ? void 0 : _this$obj7.pushValue(key, value);
269
- case 2:
270
- _context4.t0 = _context4.sent;
271
- if (_context4.t0) {
272
- _context4.next = 5;
273
- break;
274
- }
275
- _context4.t0 = false;
276
- case 5:
277
- return _context4.abrupt("return", _context4.t0);
278
- case 6:
279
- case "end":
280
- return _context4.stop();
281
- }
282
- }, _callee4, this);
283
- }));
284
- function pushValue(_x10, _x11) {
285
- return _pushValue.apply(this, arguments);
286
- }
287
- return pushValue;
288
- }() /* -------------------------------------------------------------------------- */
289
- }, {
290
- key: "getIndexOrID",
291
- value: function getIndexOrID() {
292
- var _this$obj8;
293
- return ((_this$obj8 = this.obj) === null || _this$obj8 === void 0 ? void 0 : _this$obj8.getIndexOrID()) || -1;
294
- }
295
- }, {
296
- key: "getIndex",
297
- value: function getIndex() {
298
- var _this$obj9;
299
- return ((_this$obj9 = this.obj) === null || _this$obj9 === void 0 ? void 0 : _this$obj9.getIndex()) || -1;
300
- }
301
- }, {
302
- key: "getID",
303
- value: function getID() {
304
- var _this$obj10;
305
- return ((_this$obj10 = this.obj) === null || _this$obj10 === void 0 ? void 0 : _this$obj10.getID()) || "";
306
- }
307
- /* -------------------------------------------------------------------------- */
308
- /* Events */
309
- /* -------------------------------------------------------------------------- */
310
- }, {
311
- key: "event_run",
312
- value: function () {
313
- var _event_run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(eventName) {
314
- var _len,
315
- params,
316
- _key,
317
- _args5 = arguments;
318
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
319
- while (1) switch (_context5.prev = _context5.next) {
320
- case 0:
321
- if (this.__sendEvents) {
322
- _context5.next = 2;
323
- break;
324
- }
325
- return _context5.abrupt("return");
326
- case 2:
327
- for (_len = _args5.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
328
- params[_key - 1] = _args5[_key];
329
- }
330
- _context5.next = 5;
331
- return _event.EventManager.run.apply(_event.EventManager, [this, eventName].concat(params));
332
- case 5:
333
- return _context5.abrupt("return", _context5.sent);
334
- case 6:
335
- case "end":
336
- return _context5.stop();
337
- }
338
- }, _callee5, this);
339
- }));
340
- function event_run(_x12) {
341
- return _event_run.apply(this, arguments);
342
- }
343
- return event_run;
344
- }()
345
- }, {
346
- key: "event_use",
347
- value: function event_use(name, runEvent) {
348
- var onlyOn = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
349
- var runOnce = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
350
- return _event.EventManager.use(this, name, runEvent, onlyOn, runOnce);
351
- }
352
- }, {
353
- key: "event_remove",
354
- value: function event_remove(name, uname) {
355
- return _event.EventManager.remove(this, name, uname);
356
- }
357
- }, {
358
- key: "event_add",
359
- value: function () {
360
- var _event_add = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(name, uname, runEvent) {
361
- var onlyOn,
362
- runOnce,
363
- _args6 = arguments;
364
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
365
- while (1) switch (_context6.prev = _context6.next) {
366
- case 0:
367
- onlyOn = _args6.length > 3 && _args6[3] !== undefined ? _args6[3] : null;
368
- runOnce = _args6.length > 4 && _args6[4] !== undefined ? _args6[4] : false;
369
- _context6.next = 4;
370
- return _event.EventManager.add(this, name, uname, runEvent, onlyOn, runOnce);
371
- case 4:
372
- case "end":
373
- return _context6.stop();
374
- }
375
- }, _callee6, this);
376
- }));
377
- function event_add(_x13, _x14, _x15) {
378
- return _event_add.apply(this, arguments);
379
- }
380
- return event_add;
381
- }()
382
- }, {
383
- key: "events_stop",
384
- value: function events_stop() {
385
- this.__sendEvents = false;
386
- }
387
- }, {
388
- key: "events_clear",
389
- value: function events_clear() {
390
- ObjectManager.events_clear(this);
391
- }
392
- }, {
393
- key: "toggleOption",
394
- value:
395
- /* -------------------------------------------------------------------------- */
396
- /* Options */
397
- /* -------------------------------------------------------------------------- */
115
+ */
116
+ async setSubValue(key, objKey, subvalue) {
117
+ return ((await this.obj?.setSubValue(key, objKey, subvalue)) || false);
118
+ }
119
+ //Push value on array
120
+ async pushValue(key, value) {
121
+ return (await this.obj?.pushValue(key, value)) || false;
122
+ }
123
+ /* -------------------------------------------------------------------------- */
124
+ getIndexOrID() {
125
+ return this.obj?.getIndexOrID() || -1;
126
+ }
127
+ getIndex() {
128
+ return this.obj?.getIndex() || -1;
129
+ }
130
+ getID() {
131
+ return this.obj?.getID() || "";
132
+ }
133
+ /* -------------------------------------------------------------------------- */
134
+ /* Events */
135
+ /* -------------------------------------------------------------------------- */
136
+ async event_run(eventName, ...params) {
137
+ if (!this.__sendEvents)
138
+ return;
139
+ return await EventManager.run(this, eventName, ...params);
140
+ }
141
+ event_use(name, runEvent, onlyOn = null, runOnce = false) {
142
+ return EventManager.use(this, name, runEvent, onlyOn, runOnce);
143
+ }
144
+ event_remove(name, uname) {
145
+ return EventManager.remove(this, name, uname);
146
+ }
147
+ async event_add(name, uname, runEvent, onlyOn = null, runOnce = false) {
148
+ await EventManager.add(this, name, uname, runEvent, onlyOn, runOnce);
149
+ }
150
+ events_stop() {
151
+ this.__sendEvents = false;
152
+ }
153
+ events_clear() {
154
+ ObjectManager.events_clear(this);
155
+ }
156
+ static events_clear(obj) {
157
+ EventManager.removeAll(obj);
158
+ }
159
+ /* -------------------------------------------------------------------------- */
160
+ /* Options */
161
+ /* -------------------------------------------------------------------------- */
398
162
  /**
399
163
  * Set an option to some value, if its already equal to the value it will be deleted instead
400
164
  * @param key
401
165
  * @param value
402
166
  * @returns
403
- */
404
- function () {
405
- var _toggleOption = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(key, value) {
406
- var oldval;
407
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
408
- while (1) switch (_context7.prev = _context7.next) {
409
- case 0:
410
- oldval = this.getOption(key);
411
- if (!(0, _object.object_equals_loose)(oldval, value)) {
412
- _context7.next = 6;
413
- break;
414
- }
415
- _context7.next = 4;
416
- return this.setOption(key, null);
417
- case 4:
418
- _context7.next = 8;
419
- break;
420
- case 6:
421
- _context7.next = 8;
422
- return this.setOption(key, value);
423
- case 8:
424
- case "end":
425
- return _context7.stop();
426
- }
427
- }, _callee7, this);
428
- }));
429
- function toggleOption(_x16, _x17) {
430
- return _toggleOption.apply(this, arguments);
431
- }
432
- return toggleOption;
433
- }()
434
- }, {
435
- key: "setOption",
436
- value: function () {
437
- var _setOption = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(key, value) {
438
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
439
- while (1) switch (_context8.prev = _context8.next) {
440
- case 0:
441
- if (this.__options == null) this.__options = {};
442
- if (value == null) {
443
- delete this.__options[key];
444
- } else {
445
- this.__options[key] = value;
446
- }
447
- _context8.next = 4;
448
- return this.event_run("on_option_change", key, value);
449
- case 4:
450
- return _context8.abrupt("return", _context8.sent);
451
- case 5:
452
- case "end":
453
- return _context8.stop();
454
- }
455
- }, _callee8, this);
456
- }));
457
- function setOption(_x18, _x19) {
458
- return _setOption.apply(this, arguments);
459
- }
460
- return setOption;
461
- }()
167
+ */
168
+ async toggleOption(key, value) {
169
+ var oldval = this.getOption(key);
170
+ if (object_equals_loose(oldval, value)) {
171
+ await this.setOption(key, null);
172
+ }
173
+ else
174
+ await this.setOption(key, value);
175
+ }
176
+ async setOption(key, value) {
177
+ if (this.__options == null)
178
+ this.__options = {};
179
+ if (value == null) {
180
+ delete this.__options[key];
181
+ }
182
+ else {
183
+ this.__options[key] = value;
184
+ }
185
+ return await this.event_run("on_option_change", key, value);
186
+ }
462
187
  /**
463
188
  * Sets an option then does an action,
464
189
  * after the action is run, updates the option again
@@ -466,96 +191,52 @@ var ObjectManager = /*#__PURE__*/function () {
466
191
  * @param value
467
192
  * @param nextvalue
468
193
  * @param action
469
- */
470
- }, {
471
- key: "holdOption",
472
- value: function () {
473
- var _holdOption = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(key, value, nextvalue, action) {
474
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
475
- while (1) switch (_context9.prev = _context9.next) {
476
- case 0:
477
- _context9.prev = 0;
478
- this.setOption(key, value);
479
- if (!(typeof action === "function")) {
480
- _context9.next = 5;
481
- break;
482
- }
483
- _context9.next = 5;
484
- return action();
485
- case 5:
486
- _context9.prev = 5;
487
- this.setOption(key, nextvalue);
488
- return _context9.finish(5);
489
- case 8:
490
- case "end":
491
- return _context9.stop();
492
- }
493
- }, _callee9, this, [[0,, 5, 8]]);
494
- }));
495
- function holdOption(_x20, _x21, _x22, _x23) {
496
- return _holdOption.apply(this, arguments);
497
- }
498
- return holdOption;
499
- }()
500
- }, {
501
- key: "getOption",
502
- value: function getOption(key) {
503
- if (this.__options == null) return undefined;
504
- return this.__options[key];
505
- }
506
- /* -------------------------------------------------------------------------- */
507
- /* Errors */
508
- /* -------------------------------------------------------------------------- */
509
- }, {
510
- key: "addError",
511
- value: function addError(title, message) {
512
- var sendToRegister = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "auto";
513
- return ObjectManager.addError(this, title, message, sendToRegister);
514
- }
515
- }, {
516
- key: "getErrors",
517
- value: function getErrors() {
518
- return ObjectManager.getErrors(this);
519
- }
520
- }, {
521
- key: "clearErrors",
522
- value: function clearErrors() {
523
- return ObjectManager.clearErrors(this);
524
- }
525
- }], [{
526
- key: "events_clear",
527
- value: function events_clear(obj) {
528
- _event.EventManager.removeAll(obj);
529
- }
530
- }, {
531
- key: "addError",
532
- value: function addError(o, title, message) {
533
- var sendToRegister = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "auto";
534
- if (o && o.obj) {
535
- return _SimpleObject["default"].addError(o.obj, title, message, sendToRegister);
536
- }
537
- var errStr = (0, _string.combine_if_not_blank)(title, " : ", message);
538
- console.error("[REGISTER-ERROR]", errStr);
539
- _global.gfunc.run_action("add_error", {
540
- title: title,
541
- message: message,
542
- type: "error"
543
- });
544
- }
545
- }, {
546
- key: "getErrors",
547
- value: function getErrors(o) {
548
- var obj = o.obj;
549
- return obj != null ? _SimpleObject["default"].getErrors(o.obj) : [];
550
- }
551
- }, {
552
- key: "clearErrors",
553
- value: function clearErrors(o) {
554
- return _SimpleObject["default"].clearErrors(o.obj);
555
- }
556
- }]);
557
- return ObjectManager;
558
- }();
559
- exports.ObjectManager = ObjectManager;
560
- var _default = ObjectManager;
561
- exports["default"] = _default;
194
+ */
195
+ async holdOption(key, value, nextvalue, action) {
196
+ try {
197
+ this.setOption(key, value);
198
+ if (typeof action === "function")
199
+ await action();
200
+ }
201
+ finally {
202
+ this.setOption(key, nextvalue);
203
+ }
204
+ }
205
+ getOption(key) {
206
+ if (this.__options == null)
207
+ return undefined;
208
+ return this.__options[key];
209
+ }
210
+ /* -------------------------------------------------------------------------- */
211
+ /* Errors */
212
+ /* -------------------------------------------------------------------------- */
213
+ addError(title, message, sendToRegister = "auto") {
214
+ return ObjectManager.addError(this, title, message, sendToRegister);
215
+ }
216
+ getErrors() {
217
+ return ObjectManager.getErrors(this);
218
+ }
219
+ clearErrors() {
220
+ return ObjectManager.clearErrors(this);
221
+ }
222
+ static addError(o, title, message, sendToRegister = "auto") {
223
+ if (o && o.obj) {
224
+ return SimpleObject.addError(o.obj, title, message, sendToRegister);
225
+ }
226
+ const errStr = combine_if_not_blank(title, " : ", message);
227
+ console.error("[REGISTER-ERROR]", errStr);
228
+ gfunc.run_action("add_error", {
229
+ title: title,
230
+ message: message,
231
+ type: "error",
232
+ });
233
+ }
234
+ static getErrors(o) {
235
+ const obj = o.obj;
236
+ return obj != null ? SimpleObject.getErrors(o.obj) : [];
237
+ }
238
+ static clearErrors(o) {
239
+ return SimpleObject.clearErrors(o.obj);
240
+ }
241
+ }
242
+ export default ObjectManager;