@fixefy/fixefy-ui-utils 0.0.333 → 0.0.335

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.
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return _default;
9
+ }
10
+ });
11
+ const _router = /*#__PURE__*/ _interop_require_default(require("next/router"));
12
+ function _interop_require_default(obj) {
13
+ return obj && obj.__esModule ? obj : {
14
+ default: obj
15
+ };
16
+ }
17
+ const redirect = (context, target)=>{
18
+ if (context.res) {
19
+ // server
20
+ // 303: "See other"
21
+ // console.log('SERVER RESPONSE :', context.res)
22
+ context.res.writeHead(303, {
23
+ Location: target
24
+ });
25
+ context.res.end();
26
+ } else {
27
+ // In the browser, we just pretend like this never even happened ;)
28
+ _router.default.replace(target);
29
+ }
30
+ };
31
+ const _default = redirect;
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ getValueComponentByComponentValue: function() {
13
+ return getValueComponentByComponentValue;
14
+ },
15
+ parseValue: function() {
16
+ return parseValue;
17
+ }
18
+ });
19
+ const _jsxruntime = require("react/jsx-runtime");
20
+ const _react = /*#__PURE__*/ _interop_require_default(require("react"));
21
+ const _material = require("@mui/material");
22
+ const _fixefyuicomponents = require("@fixefy/fixefy-ui-components");
23
+ const _ = require("../");
24
+ function _interop_require_default(obj) {
25
+ return obj && obj.__esModule ? obj : {
26
+ default: obj
27
+ };
28
+ }
29
+ const parseValue = ({ value, structure, onClick })=>{
30
+ //TODO: change active to enabled or disabled
31
+ const { extended, name, type, title } = structure;
32
+ // extract path if exists
33
+ const path = extended && extended.title_path;
34
+ let theTruth;
35
+ if (path) {
36
+ // extract the object in the path
37
+ theTruth = (0, _.getJPart)(value, path, undefined);
38
+ }
39
+ const _value = theTruth === undefined || theTruth === null ? value[name] : theTruth;
40
+ if (_value === undefined || _value === null) {
41
+ return getValueComponentByComponentValue({
42
+ value: 'No Value Found'
43
+ });
44
+ }
45
+ // get string value according to value type
46
+ let rv = (0, _.getStringValueByValueType)({
47
+ value: _value,
48
+ name
49
+ });
50
+ // parse wrapping component according to type
51
+ rv = getValueComponentByComponentValue({
52
+ value: rv,
53
+ name,
54
+ title,
55
+ type,
56
+ onClick: (e)=>onClick(e, _value)
57
+ });
58
+ return rv;
59
+ };
60
+ const getValueComponentByComponentValue = ({ value, name, title, type, onClick })=>{
61
+ let rv = null;
62
+ switch(type){
63
+ case _.ComponentTypes.Chip:
64
+ rv = /*#__PURE__*/ (0, _jsxruntime.jsx)(_fixefyuicomponents.FxChip, {
65
+ size: "small",
66
+ style: {
67
+ marginBottom: '5px'
68
+ },
69
+ status: value.toLowerCase(),
70
+ label: value
71
+ }, `${name}-Chip-3003`);
72
+ break;
73
+ case _.ComponentTypes.ClickableLabel:
74
+ rv = /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Typography, {
75
+ sx: {
76
+ marginBottom: '5px',
77
+ fontSize: '14px',
78
+ textDecoration: 'underline',
79
+ cursor: 'pointer'
80
+ },
81
+ variant: "body1",
82
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Link, {
83
+ onClick: onClick,
84
+ children: (0, _.titleCase)(value)
85
+ })
86
+ }, `${name}-Link-2002`);
87
+ break;
88
+ case _.ComponentTypes.Label:
89
+ if (Array.isArray(value) && (value === null || value === void 0 ? void 0 : value.length) > 1) {
90
+ rv = /*#__PURE__*/ (0, _jsxruntime.jsx)(_fixefyuicomponents.FxShowMore, {
91
+ items: value,
92
+ label: title !== null && title !== void 0 ? title : '',
93
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Typography, {
94
+ lineHeight: '20px',
95
+ sx: {
96
+ fontSize: '14px'
97
+ },
98
+ variant: "body1",
99
+ children: (0, _.titleCase)(value[0])
100
+ }, `${name}-Label-1000`)
101
+ });
102
+ } else {
103
+ rv = /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Typography, {
104
+ lineHeight: '20px',
105
+ sx: {
106
+ fontSize: '14px'
107
+ },
108
+ variant: "body1",
109
+ children: (0, _.titleCase)(value)
110
+ }, `${name}-Label-1000`);
111
+ }
112
+ break;
113
+ default:
114
+ rv = /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Typography, {
115
+ lineHeight: '20px',
116
+ sx: {
117
+ fontSize: '14px'
118
+ },
119
+ variant: "body1",
120
+ children: (0, _.titleCase)(value)
121
+ }, `${name}-Label-1000`);
122
+ break;
123
+ }
124
+ return rv;
125
+ };
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "resolvers", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return resolvers;
9
+ }
10
+ });
11
+ const _graphqltag = /*#__PURE__*/ _interop_require_default(require("graphql-tag"));
12
+ function _interop_require_default(obj) {
13
+ return obj && obj.__esModule ? obj : {
14
+ default: obj
15
+ };
16
+ }
17
+ const CURRENT_PAGE_QUERY = (0, _graphqltag.default)`
18
+ query CURRENT_PAGE_QUERY {
19
+ currentPage @client {
20
+ name
21
+ path
22
+ }
23
+ }
24
+ `;
25
+ const resolvers = {
26
+ Mutation: {
27
+ changePage (_, args, { cache }) {
28
+ // console.log(_, args, cache)
29
+ // read the page value from the cache
30
+ const { currentPage } = cache.readQuery({
31
+ query: CURRENT_PAGE_QUERY
32
+ });
33
+ // if navigating to new page Write the Page State to that
34
+ if (args.to !== currentPage.name) {
35
+ const data = {
36
+ currentPage: {
37
+ name: args.to,
38
+ path: '/' + args.to,
39
+ __typename: 'currentPage'
40
+ }
41
+ };
42
+ cache.writeQuery({
43
+ query: CURRENT_PAGE_QUERY,
44
+ data
45
+ });
46
+ return data;
47
+ }
48
+ return null;
49
+ }
50
+ }
51
+ };
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "transform", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return transform;
9
+ }
10
+ });
11
+ const _csvtojson = /*#__PURE__*/ _interop_require_default(require("csvtojson"));
12
+ const _convertexceltojson = /*#__PURE__*/ _interop_require_default(require("convert-excel-to-json"));
13
+ require("regenerator-runtime/runtime.js");
14
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
15
+ try {
16
+ var info = gen[key](arg);
17
+ var value = info.value;
18
+ } catch (error) {
19
+ reject(error);
20
+ return;
21
+ }
22
+ if (info.done) {
23
+ resolve(value);
24
+ } else {
25
+ Promise.resolve(value).then(_next, _throw);
26
+ }
27
+ }
28
+ function _async_to_generator(fn) {
29
+ return function() {
30
+ var self = this, args = arguments;
31
+ return new Promise(function(resolve, reject) {
32
+ var gen = fn.apply(self, args);
33
+ function _next(value) {
34
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
35
+ }
36
+ function _throw(err) {
37
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
38
+ }
39
+ _next(undefined);
40
+ });
41
+ };
42
+ }
43
+ function _interop_require_default(obj) {
44
+ return obj && obj.__esModule ? obj : {
45
+ default: obj
46
+ };
47
+ }
48
+ const defaultOptions = {
49
+ columns: true,
50
+ skip_empty_lines: true,
51
+ quote: '"',
52
+ ltrim: true,
53
+ rtrim: true,
54
+ delimiter: ','
55
+ };
56
+ const transform = function() {
57
+ var _ref = _async_to_generator(function*({ data, data_type, options = defaultOptions }) {
58
+ let rv = data;
59
+ data_type = data_type.substring(data_type.lastIndexOf('/') + 1, data_type.length + 1).toLowerCase();
60
+ switch(data_type){
61
+ case 'csv':
62
+ rv = yield _csvToJson({
63
+ csv: data,
64
+ options
65
+ });
66
+ rv = JSON.stringify(rv).trim();
67
+ break;
68
+ case 'xls':
69
+ rv = _xlsToJson({
70
+ xls: data
71
+ });
72
+ break;
73
+ case 'xml':
74
+ break;
75
+ }
76
+ return rv;
77
+ });
78
+ return function transform(_) {
79
+ return _ref.apply(this, arguments);
80
+ };
81
+ }();
82
+ const _csvToJson = function() {
83
+ var _ref = _async_to_generator(function*({ csv, options = defaultOptions }) {
84
+ const rv = yield (0, _csvtojson.default)(options).fromString(csv);
85
+ return rv;
86
+ });
87
+ return function _csvToJson(_) {
88
+ return _ref.apply(this, arguments);
89
+ };
90
+ }();
91
+ const _xlsToJson = ({ xls })=>{
92
+ const rv = (0, _convertexceltojson.default)({
93
+ source: xls
94
+ });
95
+ return rv;
96
+ };
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ isArrayValid: function() {
13
+ return isArrayValid;
14
+ },
15
+ isDateValid: function() {
16
+ return isDateValid;
17
+ },
18
+ isObjectId: function() {
19
+ return isObjectId;
20
+ },
21
+ isObjectValid: function() {
22
+ return isObjectValid;
23
+ },
24
+ isStringValid: function() {
25
+ return isStringValid;
26
+ }
27
+ });
28
+ const isArrayValid = (arr, minLength = 1, maxLength = 0)=>{
29
+ let rv = //arr instanceof Array
30
+ Object.prototype.toString.call(arr) == '[object Array]' && isObjectValid(arr) && arr.length >= minLength;
31
+ if (maxLength > 0) {
32
+ rv = rv && arr.length <= maxLength;
33
+ }
34
+ return rv;
35
+ };
36
+ const isDateValid = ()=>{
37
+ return false;
38
+ };
39
+ const isObjectValid = (obj, isCheckKeys = false)=>{
40
+ let rv = typeof obj !== 'undefined' && obj !== null;
41
+ if (isCheckKeys) {
42
+ rv = rv && Object.keys(obj).length > 0;
43
+ }
44
+ return rv;
45
+ };
46
+ const isStringValid = (str, minLength = null, maxLength = null, isValidateType = true)=>{
47
+ if (str == null) return false;
48
+ if (isValidateType && typeof str !== 'string') return false;
49
+ if (str.toString().length == 0) return false;
50
+ if (minLength && isNaN(minLength) === false && minLength > 0) {
51
+ return str.toString().length >= minLength;
52
+ }
53
+ if (maxLength && isNaN(maxLength) === false && maxLength > 0) {
54
+ return str.toString().length <= maxLength;
55
+ }
56
+ return true;
57
+ };
58
+ const isObjectId = (value)=>{
59
+ ///!* input check - if value is invalid - return false *!/
60
+ if (isStringValid(value) === false) return false;
61
+ ///!* set the regex *!/
62
+ const regex = /^[0-9a-fA-F]{24}$/;
63
+ //!* get the match *!/
64
+ const matches = regex.exec(value);
65
+ //!* check is null *!/
66
+ const rv = matches != null && isArrayValid(matches);
67
+ return rv;
68
+ };
package/package.json CHANGED
@@ -65,5 +65,5 @@
65
65
  "require": "./dist/index.js"
66
66
  }
67
67
  },
68
- "version": "0.0.333"
68
+ "version": "0.0.335"
69
69
  }