sirius-common-utils 1.0.1 → 1.0.4

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,193 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _dayjs = _interopRequireDefault(require("dayjs"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
- var FORMAT_DATE = "DD-MM-YYYY";
10
- var FORMAT_DATETIME = "DD-MM-YYYY HH:mm:ss";
11
- var FORMAT_YEARMONTH = "YYYY-MMMM";
12
- var FORMAT_YEARWEEK = "YYYY-WW";
13
- var FORMAT_DAYOFMONTH = "DD";
14
- var FORMAT_YEAR = "YYYY";
15
- var FORMAT_TIME = "HH:mm:ss";
16
- function getCurrentMoment() {
17
- return (0, _dayjs["default"])();
18
- }
19
- function getCurrentDateText() {
20
- return convertMomentToDateText(getCurrentMoment());
21
- }
22
- function getCurrentDateTimeText() {
23
- return convertMomentToDateTimeText(getCurrentMoment());
24
- }
25
- function getCurrentDate() {
26
- return getCurrentMoment().toDate();
27
- }
28
- function convertMomentToTimestamp(moment) {
29
- if (moment) {
30
- return moment.toDate().getTime();
31
- } else {
32
- return null;
33
- }
34
- }
35
- function convertMomentToDateText(moment) {
36
- if (moment) {
37
- return moment.format(FORMAT_DATE);
38
- } else {
39
- return '';
40
- }
41
- }
42
- function convertTimestampToMoment(timestamp) {
43
- if (timestamp && timestamp > 0) {
44
- return (0, _dayjs["default"])(timestamp);
45
- } else {
46
- return null;
47
- }
48
- }
49
- function convertMomentToDateTimeText(moment) {
50
- if (moment) {
51
- return moment.format(FORMAT_DATETIME);
52
- } else {
53
- return "";
54
- }
55
- }
56
- function convertMomentToYearText(moment) {
57
- if (moment) {
58
- return moment.format(FORMAT_YEAR);
59
- } else {
60
- return "";
61
- }
62
- }
63
- function convertMomentToYearMonthText(moment) {
64
- if (moment) {
65
- return moment.format(FORMAT_YEARMONTH);
66
- } else {
67
- return "";
68
- }
69
- }
70
- function convertMomentToDayOfMonthText(moment) {
71
- if (moment) {
72
- return moment.format(FORMAT_DAYOFMONTH);
73
- } else {
74
- return "";
75
- }
76
- }
77
- function convertMomentToTimeText(moment) {
78
- if (moment) {
79
- return moment.format(FORMAT_TIME);
80
- } else {
81
- return "";
82
- }
83
- }
84
- function convertDateTimeTextToMoment(dateTimeText) {
85
- if (dateTimeText) {
86
- return (0, _dayjs["default"])(dateTimeText, FORMAT_DATETIME);
87
- } else {
88
- return null;
89
- }
90
- }
91
- function convertYearMonthTextToMoment(yearMonthText) {
92
- if (yearMonthText) {
93
- return (0, _dayjs["default"])(yearMonthText, FORMAT_YEARMONTH);
94
- } else {
95
- return null;
96
- }
97
- }
98
- function convertDateTextToMoment(dateText) {
99
- if (dateText) {
100
- return (0, _dayjs["default"])(dateText, FORMAT_DATE);
101
- } else {
102
- return null;
103
- }
104
- }
105
- function convertTimeTextToMoment(dateTimeText) {
106
- if (dateTimeText) {
107
- return (0, _dayjs["default"])(dateTimeText, FORMAT_TIME);
108
- } else {
109
- return null;
110
- }
111
- }
112
- function convertDateTextToDate(dateText) {
113
- if (dateText) {
114
- return (0, _dayjs["default"])(dateText, FORMAT_DATE).toDate();
115
- } else {
116
- return null;
117
- }
118
- }
119
- function convertDateTimeTextToDate(dateTimeText) {
120
- if (dateTimeText) {
121
- var moment = (0, _dayjs["default"])(dateTimeText, FORMAT_DATETIME);
122
- return (0, _dayjs["default"])(dateTimeText, FORMAT_DATETIME).toDate();
123
- } else {
124
- return null;
125
- }
126
- }
127
- function convertTimestampToDateText(timestamp) {
128
- var moments = convertTimestampToMoment(timestamp);
129
- var text = convertMomentToDateText(moments);
130
- return text;
131
- }
132
- function convertTimestampToDateTimeText(timestamp) {
133
- var moments = convertTimestampToMoment(timestamp);
134
- var text = convertMomentToDateTimeText(moments);
135
- return text;
136
- }
137
- function convertDateToMoment(date) {
138
- if (!date) {
139
- return null;
140
- }
141
- return (0, _dayjs["default"])(date);
142
- }
143
- function convertDateToDateText(date) {
144
- var moments = convertDateToMoment(date);
145
- var text = convertMomentToDateText(moments);
146
- return text;
147
- }
148
- function convertDateToDateTimeText(date) {
149
- var moments = convertDateToMoment(date);
150
- var text = convertMomentToDateTimeText(moments);
151
- return text;
152
- }
153
- function buildDateRange(from, to) {
154
- return from + " ~ " + to;
155
- }
156
- function getFormatTextOfMMM(mthNumber) {
157
- var moment = getCurrentMoment();
158
- moment = moment.month(mthNumber - 1);
159
- return moment.format('MMM');
160
- }
161
- var _default = {
162
- FORMAT_DATE: FORMAT_DATE,
163
- FORMAT_DATETIME: FORMAT_DATETIME,
164
- FORMAT_YEARMONTH: FORMAT_YEARMONTH,
165
- FORMAT_YEARWEEK: FORMAT_YEARWEEK,
166
- FORMAT_TIME: FORMAT_TIME,
167
- getCurrentMoment: getCurrentMoment,
168
- getCurrentDateTimeText: getCurrentDateTimeText,
169
- getCurrentDateText: getCurrentDateText,
170
- getCurrentDate: getCurrentDate,
171
- convertMomentToTimestamp: convertMomentToTimestamp,
172
- convertMomentToDateText: convertMomentToDateText,
173
- convertMomentToDateTimeText: convertMomentToDateTimeText,
174
- convertMomentToYearText: convertMomentToYearText,
175
- convertMomentToYearMonthText: convertMomentToYearMonthText,
176
- convertMomentToDayOfMonthText: convertMomentToDayOfMonthText,
177
- convertMomentToTimeText: convertMomentToTimeText,
178
- convertTimestampToMoment: convertTimestampToMoment,
179
- convertTimestampToDateText: convertTimestampToDateText,
180
- convertTimestampToDateTimeText: convertTimestampToDateTimeText,
181
- convertDateToMoment: convertDateToMoment,
182
- convertDateToDateText: convertDateToDateText,
183
- convertDateToDateTimeText: convertDateToDateTimeText,
184
- convertYearMonthTextToMoment: convertYearMonthTextToMoment,
185
- convertDateTextToMoment: convertDateTextToMoment,
186
- convertDateTimeTextToMoment: convertDateTimeTextToMoment,
187
- convertTimeTextToMoment: convertTimeTextToMoment,
188
- convertDateTextToDate: convertDateTextToDate,
189
- convertDateTimeTextToDate: convertDateTimeTextToDate,
190
- buildDateRange: buildDateRange,
191
- getFormatTextOfMMM: getFormatTextOfMMM
192
- };
193
- exports["default"] = _default;
@@ -1,50 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _lodash = _interopRequireDefault(require("lodash"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
- function resetBodyScroll() {
10
- document.querySelector("body").style.position = "initial";
11
- }
12
- function forbidBodyScroll() {
13
- document.querySelector("body").style.position = "fixed";
14
- }
15
- function syncDomAnimation() {
16
- setTimeout(function () {
17
- //sync all animation be the same
18
- _lodash["default"].each(document.getAnimations(), function (item) {
19
- item.startTime = 0;
20
- });
21
- }, 200);
22
- }
23
-
24
- /**
25
- * find the closet parent element by className
26
- *
27
- * @param elem
28
- * @param className
29
- */
30
- function closetByClassName(elem, classNameList) {
31
- var classList = elem.classList;
32
- if (classList) {
33
- if (_lodash["default"].intersection(classList, classNameList).length > 0) {
34
- return elem;
35
- }
36
- }
37
- var parentElement = elem.parentElement;
38
- if (parentElement) {
39
- return closetByClassName(parentElement, classNameList);
40
- } else {
41
- return null;
42
- }
43
- }
44
- var _default = {
45
- resetBodyScroll: resetBodyScroll,
46
- forbidBodyScroll: forbidBodyScroll,
47
- syncDomAnimation: syncDomAnimation,
48
- closetByClassName: closetByClassName
49
- };
50
- exports["default"] = _default;
@@ -1,48 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- function isIOS() {
8
- return ['iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone', 'iPod'].includes(navigator.platform) || navigator.userAgent.includes("Mac") && "ontouchend" in document;
9
- }
10
- function isDesktopChrome() {
11
- var result = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
12
- if (!result) {
13
- return false;
14
- }
15
- if (isMobileChrome()) {
16
- return false;
17
- }
18
- return true;
19
- }
20
- function isMobileChrome() {
21
- return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) && /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
22
- }
23
- function isMobileDevice() {
24
- return isIOS() || isMobileChrome();
25
- }
26
- function updateViewPort() {
27
- var pOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
28
- var viewport = document.getElementsByName("viewport");
29
- if (!viewport || viewport.length != 1) {
30
- return;
31
- }
32
- var options = {};
33
- _.merge(options, defaultOptions, pOptions);
34
- var content = [];
35
- _.each(options, function (value, key) {
36
- content.push(key + "=" + value);
37
- });
38
- viewport[0].content = _.join(content, ",");
39
- console.debug("curr viewport is: " + viewport[0].content);
40
- }
41
- var _default = {
42
- isIOS: isIOS,
43
- isDesktopChrome: isDesktopChrome,
44
- isMobileChrome: isMobileChrome,
45
- isMobileDevice: isMobileDevice,
46
- updateViewPort: updateViewPort
47
- };
48
- exports["default"] = _default;
@@ -1,128 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _react = _interopRequireWildcard(require("react"));
8
- var _lodash = _interopRequireDefault(require("lodash"));
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
11
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
12
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
13
- 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 e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
14
- 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); } }
15
- 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); }); }; }
16
- var globalDialogUtils;
17
- function init(pDialogInstanceUtils) {
18
- globalDialogUtils = pDialogInstanceUtils;
19
- }
20
- function toFormData(keyPrefix, model) {
21
- var ignoreKeys = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
22
- var formData = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
23
- if (model == null) {
24
- return {
25
- keyPrefix: null
26
- };
27
- }
28
- _lodash["default"].each(_lodash["default"].keys(model), function (attr) {
29
- var value = model[attr];
30
- var formKeyPath = keyPrefix ? keyPrefix + "#" + attr : attr;
31
- if (_lodash["default"].includes(ignoreKeys, formKeyPath)) {
32
- formData[formKeyPath] = value;
33
- return;
34
- }
35
- if (_lodash["default"].isPlainObject(value)) {
36
- toFormData(formKeyPath, value, ignoreKeys, formData);
37
- } else {
38
- formData[formKeyPath] = value;
39
- }
40
- });
41
- return formData;
42
- }
43
- function toModel(formData) {
44
- var ignoreKeys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
45
- if (formData == null) {
46
- return null;
47
- }
48
- var model = {};
49
- _lodash["default"].each(_lodash["default"].keys(formData), function (formKeyPath) {
50
- var value = formData[formKeyPath];
51
- var path = formKeyPath.replaceAll("#", ".");
52
- _lodash["default"].set(model, path, value);
53
- });
54
- return model;
55
- }
56
- function scrollToFirstError(ex) {
57
- var isError = document.getElementsByClassName('ant-form-item-has-error');
58
- isError[0] && isError[0].scrollIntoView();
59
- console.error(ex);
60
- }
61
-
62
- /**
63
- * show leave message when exit from a modified form page
64
- * @param formOrCheckFormDirtyFunc AntDesignForm or checkFormDirtyFunction
65
- * @returns {Promise<boolean>} true: can exit, or: abort exit
66
- */
67
- function confirmOfLeavingForm(_x) {
68
- return _confirmOfLeavingForm.apply(this, arguments);
69
- }
70
- function _confirmOfLeavingForm() {
71
- _confirmOfLeavingForm = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(formOrCheckFormDirtyFunc) {
72
- var formDirty, result;
73
- return _regeneratorRuntime().wrap(function _callee$(_context) {
74
- while (1) switch (_context.prev = _context.next) {
75
- case 0:
76
- if (!(formOrCheckFormDirtyFunc == null)) {
77
- _context.next = 2;
78
- break;
79
- }
80
- return _context.abrupt("return", true);
81
- case 2:
82
- formDirty = true;
83
- if (!(typeof formOrCheckFormDirtyFunc === 'function')) {
84
- _context.next = 9;
85
- break;
86
- }
87
- _context.next = 6;
88
- return formOrCheckFormDirtyFunc();
89
- case 6:
90
- formDirty = _context.sent;
91
- _context.next = 10;
92
- break;
93
- case 9:
94
- formDirty = formOrCheckFormDirtyFunc.isFieldsTouched();
95
- case 10:
96
- if (!formDirty) {
97
- _context.next = 16;
98
- break;
99
- }
100
- _context.next = 13;
101
- return globalDialogUtils.showConfirmDialog(leaveMessage);
102
- case 13:
103
- result = _context.sent;
104
- if (!(result !== true)) {
105
- _context.next = 16;
106
- break;
107
- }
108
- return _context.abrupt("return", false);
109
- case 16:
110
- return _context.abrupt("return", true);
111
- case 17:
112
- case "end":
113
- return _context.stop();
114
- }
115
- }, _callee);
116
- }));
117
- return _confirmOfLeavingForm.apply(this, arguments);
118
- }
119
- var leaveMessage = "Do you want to give up your modification?";
120
- var _default = {
121
- init: init,
122
- toFormData: toFormData,
123
- toModel: toModel,
124
- scrollToFirstError: scrollToFirstError,
125
- confirmOfLeavingForm: confirmOfLeavingForm,
126
- leaveMessage: leaveMessage
127
- };
128
- exports["default"] = _default;
@@ -1,23 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _lodash = _interopRequireDefault(require("lodash"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
- function isJsonText(value) {
10
- value = _lodash["default"].trim(value);
11
- return _lodash["default"].startsWith(value, "{") || _lodash["default"].startsWith(value, "[");
12
- }
13
- function formatJsonText(value) {
14
- if (!isJsonText(value)) {
15
- return value;
16
- }
17
- return JSON.stringify(JSON.parse(value), null, 4);
18
- }
19
- var _default = {
20
- isJsonText: isJsonText,
21
- formatJsonText: formatJsonText
22
- };
23
- exports["default"] = _default;
@@ -1,169 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _EnosAppPortalSdkUtils = _interopRequireDefault(require("./EnosAppPortalSdkUtils"));
8
- var _AxiosUtils = _interopRequireDefault(require("./AxiosUtils"));
9
- var _lodash = _interopRequireDefault(require("lodash"));
10
- var _AppUtils = _interopRequireDefault(require("./AppUtils"));
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
12
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
13
- 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 e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
14
- 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); } }
15
- 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); }); }; } /**
16
- * getCurrUserInfo
17
- */
18
- function init(_x, _x2) {
19
- return _init.apply(this, arguments);
20
- }
21
- function _init() {
22
- _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(deviceType, pCurrUserInfoCache) {
23
- return _regeneratorRuntime().wrap(function _callee$(_context) {
24
- while (1) switch (_context.prev = _context.next) {
25
- case 0:
26
- if (pCurrUserInfoCache) {
27
- currUserInfoCache = pCurrUserInfoCache;
28
- _AppUtils["default"].setLocalStorageObjItem("CURRENT_USER", currUserInfoCache);
29
- }
30
- _context.next = 3;
31
- return getCurrUserModel();
32
- case 3:
33
- setDeviceType(deviceType);
34
- case 4:
35
- case "end":
36
- return _context.stop();
37
- }
38
- }, _callee);
39
- }));
40
- return _init.apply(this, arguments);
41
- }
42
- function clear() {
43
- return _clear.apply(this, arguments);
44
- }
45
- function _clear() {
46
- _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
47
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
48
- while (1) switch (_context2.prev = _context2.next) {
49
- case 0:
50
- currUserInfoCache = null;
51
- appUserModel = null;
52
- _AppUtils["default"].setLocalStorageObjItem("CURRENT_USER", null);
53
- case 3:
54
- case "end":
55
- return _context2.stop();
56
- }
57
- }, _callee2);
58
- }));
59
- return _clear.apply(this, arguments);
60
- }
61
- function setDeviceType(deviceType) {
62
- if (deviceType === 'MOBILE') {
63
- _AppUtils["default"].setLocalStorageStringItem("DEVICE_TYPE", "MOBILE");
64
- } else {
65
- _AppUtils["default"].setLocalStorageStringItem("DEVICE_TYPE", "WEB");
66
- }
67
- }
68
- function isMobileDevice() {
69
- var deviceType = _AppUtils["default"].getLocalStorageStringItem("DEVICE_TYPE");
70
- return deviceType === 'MOBILE';
71
- }
72
- var currUserInfoCache = null;
73
- function getCurrUserInfo() {
74
- return _getCurrUserInfo.apply(this, arguments);
75
- }
76
- function _getCurrUserInfo() {
77
- _getCurrUserInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
78
- var currUser;
79
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
80
- while (1) switch (_context3.prev = _context3.next) {
81
- case 0:
82
- if (!isMobileDevice()) {
83
- _context3.next = 4;
84
- break;
85
- }
86
- return _context3.abrupt("return", getCurrUserInfoCache());
87
- case 4:
88
- _context3.next = 6;
89
- return _EnosAppPortalSdkUtils["default"].getUserInfo();
90
- case 6:
91
- currUser = _context3.sent;
92
- currUserInfoCache = currUser;
93
- return _context3.abrupt("return", currUser);
94
- case 9:
95
- case "end":
96
- return _context3.stop();
97
- }
98
- }, _callee3);
99
- }));
100
- return _getCurrUserInfo.apply(this, arguments);
101
- }
102
- function getCurrUserInfoCache() {
103
- if (currUserInfoCache != null) {
104
- return currUserInfoCache;
105
- }
106
- currUserInfoCache = _AppUtils["default"].getLocalStorageObjItem("CURRENT_USER");
107
- if (currUserInfoCache != null) {
108
- return currUserInfoCache;
109
- }
110
- console.debug("Please invoke getCurrUserInfo first");
111
- return null;
112
- }
113
- function getCurrUserId() {
114
- var _getCurrUserInfoCache;
115
- return (_getCurrUserInfoCache = getCurrUserInfoCache()) === null || _getCurrUserInfoCache === void 0 ? void 0 : _getCurrUserInfoCache.id;
116
- }
117
- var appUserModel = null;
118
- function getCurrUserModel() {
119
- return _getCurrUserModel.apply(this, arguments);
120
- }
121
- /**
122
- * check user role
123
- */
124
- function _getCurrUserModel() {
125
- _getCurrUserModel = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
126
- var url;
127
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
128
- while (1) switch (_context4.prev = _context4.next) {
129
- case 0:
130
- if (!(appUserModel == null)) {
131
- _context4.next = 5;
132
- break;
133
- }
134
- url = "/api/user/getCurrUserInfo";
135
- _context4.next = 4;
136
- return _AxiosUtils["default"].getJsonData(url);
137
- case 4:
138
- appUserModel = _context4.sent;
139
- case 5:
140
- return _context4.abrupt("return", appUserModel);
141
- case 6:
142
- case "end":
143
- return _context4.stop();
144
- }
145
- }, _callee4);
146
- }));
147
- return _getCurrUserModel.apply(this, arguments);
148
- }
149
- function userHasRole(roleCodeOrArray) {
150
- if (appUserModel == null) {
151
- return false;
152
- }
153
- if (_lodash["default"].isArray(roleCodeOrArray)) {
154
- return !_lodash["default"].isEmpty(_lodash["default"].intersection(appUserModel.roleList, roleCodeOrArray));
155
- } else {
156
- return _lodash["default"].includes(appUserModel.roleList, roleCodeOrArray);
157
- }
158
- }
159
- var _default = {
160
- init: init,
161
- clear: clear,
162
- getCurrUserInfo: getCurrUserInfo,
163
- getCurrUserInfoCache: getCurrUserInfoCache,
164
- getCurrUserId: getCurrUserId,
165
- getCurrUserModel: getCurrUserModel,
166
- userHasRole: userHasRole,
167
- isMobileDevice: isMobileDevice
168
- };
169
- exports["default"] = _default;