@fixefy/fixefy-ui-utils 0.2.4 → 0.2.5

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,154 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "parseInput", {
6
- enumerable: true,
7
- get: function() {
8
- return parseInput;
9
- }
10
- });
11
- const _jsxruntime = require("react/jsx-runtime");
12
- const _react = /*#__PURE__*/ _interop_require_default(require("react"));
13
- const _ = require("../");
14
- const _fixefyuicomponents = require("@fixefy/fixefy-ui-components");
15
- function _define_property(obj, key, value) {
16
- if (key in obj) {
17
- Object.defineProperty(obj, key, {
18
- value: value,
19
- enumerable: true,
20
- configurable: true,
21
- writable: true
22
- });
23
- } else {
24
- obj[key] = value;
25
- }
26
- return obj;
27
- }
28
- function _interop_require_default(obj) {
29
- return obj && obj.__esModule ? obj : {
30
- default: obj
31
- };
32
- }
33
- function _object_spread(target) {
34
- for(var i = 1; i < arguments.length; i++){
35
- var source = arguments[i] != null ? arguments[i] : {};
36
- var ownKeys = Object.keys(source);
37
- if (typeof Object.getOwnPropertySymbols === "function") {
38
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
39
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
40
- }));
41
- }
42
- ownKeys.forEach(function(key) {
43
- _define_property(target, key, source[key]);
44
- });
45
- }
46
- return target;
47
- }
48
- function ownKeys(object, enumerableOnly) {
49
- var keys = Object.keys(object);
50
- if (Object.getOwnPropertySymbols) {
51
- var symbols = Object.getOwnPropertySymbols(object);
52
- if (enumerableOnly) {
53
- symbols = symbols.filter(function(sym) {
54
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
55
- });
56
- }
57
- keys.push.apply(keys, symbols);
58
- }
59
- return keys;
60
- }
61
- function _object_spread_props(target, source) {
62
- source = source != null ? source : {};
63
- if (Object.getOwnPropertyDescriptors) {
64
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
65
- } else {
66
- ownKeys(Object(source)).forEach(function(key) {
67
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
68
- });
69
- }
70
- return target;
71
- }
72
- function _object_without_properties(source, excluded) {
73
- if (source == null) return {};
74
- var target = _object_without_properties_loose(source, excluded);
75
- var key, i;
76
- if (Object.getOwnPropertySymbols) {
77
- var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
78
- for(i = 0; i < sourceSymbolKeys.length; i++){
79
- key = sourceSymbolKeys[i];
80
- if (excluded.indexOf(key) >= 0) continue;
81
- if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
82
- target[key] = source[key];
83
- }
84
- }
85
- return target;
86
- }
87
- function _object_without_properties_loose(source, excluded) {
88
- if (source == null) return {};
89
- var target = {};
90
- var sourceKeys = Object.keys(source);
91
- var key, i;
92
- for(i = 0; i < sourceKeys.length; i++){
93
- key = sourceKeys[i];
94
- if (excluded.indexOf(key) >= 0) continue;
95
- target[key] = source[key];
96
- }
97
- return target;
98
- }
99
- const parseInput = (_param)=>{
100
- var { client, fetcher, control, structure, droppedItem, state, onInputChange, classes, args } = _param, rest = _object_without_properties(_param, [
101
- "client",
102
- "fetcher",
103
- "control",
104
- "structure",
105
- "droppedItem",
106
- "state",
107
- "onInputChange",
108
- "classes",
109
- "args"
110
- ]);
111
- const { type, children } = structure;
112
- const { AsyncDropdown, Textfield, clear, dropdownOptions } = _.ComponentTypes;
113
- switch(type){
114
- case AsyncDropdown:
115
- {
116
- return /*#__PURE__*/ (0, _jsxruntime.jsx)(_fixefyuicomponents.FxAsyncDropdown, _object_spread({
117
- classes: classes,
118
- structure: structure,
119
- fetcher: fetcher,
120
- onChange: ()=>{}
121
- }, rest));
122
- }
123
- case Textfield:
124
- {
125
- return /*#__PURE__*/ (0, _jsxruntime.jsx)(_fixefyuicomponents.FxTextField, _object_spread({
126
- autoFocus: true,
127
- droppedItem: droppedItem,
128
- defaultValue: args && args.data && args.data.default_value,
129
- onChange: (e)=>onInputChange({
130
- structure,
131
- value: e.target.value
132
- }),
133
- structure: structure
134
- }, rest));
135
- }
136
- case dropdownOptions:
137
- return children.map((child)=>{
138
- return parseInput(_object_spread({
139
- client,
140
- control,
141
- structure: child,
142
- droppedItem,
143
- state,
144
- onInputChange,
145
- classes,
146
- args
147
- }, rest));
148
- });
149
- case clear:
150
- return /*#__PURE__*/ (0, _jsxruntime.jsx)(_fixefyuicomponents.FxButton, _object_spread_props(_object_spread({}, rest), {
151
- children: structure.name
152
- }));
153
- }
154
- };
@@ -1,41 +0,0 @@
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
- convertFileSize: function() {
13
- return convertFileSize;
14
- },
15
- convertFileTypeToIcon: function() {
16
- return convertFileTypeToIcon;
17
- }
18
- });
19
- const convertFileSize = (fileSize)=>{
20
- if (fileSize < 10000) {
21
- return `${(fileSize / 1000).toFixed(1)} KB`;
22
- } else if (fileSize < 10000000) {
23
- return `${(fileSize / 1000000).toFixed(1)} MB`;
24
- } else {
25
- return 0;
26
- }
27
- };
28
- const convertFileTypeToIcon = (fileType)=>{
29
- switch(fileType){
30
- case 'text/csv':
31
- return 'uploader/file_type_csv.svg';
32
- case 'text/xml':
33
- return 'uploader/file_type_xml.svg';
34
- case 'text/json':
35
- return 'uploader/file_type_json.svg';
36
- case 'text/xls':
37
- return 'uploader/file_type_xls.svg';
38
- default:
39
- return 'uploader/file_type_csv.svg';
40
- }
41
- };
@@ -1,382 +0,0 @@
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
- draggableTypes: function() {
13
- return draggableTypes;
14
- },
15
- getFields: function() {
16
- return getFields;
17
- },
18
- getFieldsStringified: function() {
19
- return getFieldsStringified;
20
- },
21
- getOperationObjectFromSchema: function() {
22
- return getOperationObjectFromSchema;
23
- },
24
- getOperationTypeForMutation: function() {
25
- return getOperationTypeForMutation;
26
- },
27
- getTypeKind: function() {
28
- return getTypeKind;
29
- },
30
- getTypeName: function() {
31
- return getTypeName;
32
- },
33
- getVariablesKeys: function() {
34
- return getVariablesKeys;
35
- },
36
- insertNewVariable: function() {
37
- return insertNewVariable;
38
- },
39
- isArgMandatory: function() {
40
- return isArgMandatory;
41
- },
42
- operationTypes: function() {
43
- return operationTypes;
44
- },
45
- parseInputDataToDataObject: function() {
46
- return parseInputDataToDataObject;
47
- }
48
- });
49
- const _pluralize = /*#__PURE__*/ _interop_require_default(require("pluralize"));
50
- const _language = require("graphql/language");
51
- function _define_property(obj, key, value) {
52
- if (key in obj) {
53
- Object.defineProperty(obj, key, {
54
- value: value,
55
- enumerable: true,
56
- configurable: true,
57
- writable: true
58
- });
59
- } else {
60
- obj[key] = value;
61
- }
62
- return obj;
63
- }
64
- function _interop_require_default(obj) {
65
- return obj && obj.__esModule ? obj : {
66
- default: obj
67
- };
68
- }
69
- function _object_spread(target) {
70
- for(var i = 1; i < arguments.length; i++){
71
- var source = arguments[i] != null ? arguments[i] : {};
72
- var ownKeys = Object.keys(source);
73
- if (typeof Object.getOwnPropertySymbols === "function") {
74
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
75
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
76
- }));
77
- }
78
- ownKeys.forEach(function(key) {
79
- _define_property(target, key, source[key]);
80
- });
81
- }
82
- return target;
83
- }
84
- function ownKeys(object, enumerableOnly) {
85
- var keys = Object.keys(object);
86
- if (Object.getOwnPropertySymbols) {
87
- var symbols = Object.getOwnPropertySymbols(object);
88
- if (enumerableOnly) {
89
- symbols = symbols.filter(function(sym) {
90
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
91
- });
92
- }
93
- keys.push.apply(keys, symbols);
94
- }
95
- return keys;
96
- }
97
- function _object_spread_props(target, source) {
98
- source = source != null ? source : {};
99
- if (Object.getOwnPropertyDescriptors) {
100
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
101
- } else {
102
- ownKeys(Object(source)).forEach(function(key) {
103
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
104
- });
105
- }
106
- return target;
107
- }
108
- const operationTypes = {
109
- MUTATIONS: {
110
- CREATE: 'mutations.create',
111
- DELETE: 'mutations.delete',
112
- UPDATE: 'mutations.update',
113
- ACTION: 'mutations.action'
114
- },
115
- QUERIES: 'queries',
116
- SUBSCRIPTIONS: 'subscriptions'
117
- };
118
- const draggableTypes = {
119
- ACTION: 'action',
120
- ENTITY: 'entity',
121
- FRAGMENT: 'fragment',
122
- VARIABLES: 'variables'
123
- };
124
- const getFields = ({ arg })=>arg.type.getFields ? arg.type.getFields() : arg.type._nameLookup ? arg.type._nameLookup : arg.type.ofType && arg.type.ofType.getFields ? arg.type.ofType.getFields() : arg.type.ofType && arg.type.ofType.ofType && arg.type.ofType.ofType.getFields ? arg.type.ofType.ofType.getFields() : {};
125
- const getFieldsStringified = ({ arg })=>arg.type.getFields ? Object.keys(arg.type.getFields()) : arg.type.getValues ? Object.keys(arg.type.getValues()) : arg.type.ofType && arg.type.ofType.getFields ? Object.keys(arg.type.ofType.getFields()) : [];
126
- const getTypeKind = (object)=>{
127
- return object && object.astNode && object.astNode.type && object.astNode.type.kind ? object.astNode.type.kind : object && object.astNode && object.astNode.kind ? object.astNode.kind : undefined;
128
- };
129
- const getTypeName = (object)=>{
130
- return object && object.type ? object.type.ofType ? object.type.ofType.name : object && object.type.name && object.type.name : object.astNode && object.astNode.name;
131
- };
132
- const getOperationObjectFromSchema = ({ operationName, schema })=>{
133
- const queries = schema.getQueryType().getFields();
134
- const mutations = schema.getMutationType().getFields();
135
- const subscriptions = schema.getSubscriptionType().getFields();
136
- let operationType;
137
- let rv;
138
- if (operationName in mutations) {
139
- operationType = getOperationTypeForMutation({
140
- operationName
141
- });
142
- rv = mutations[operationName];
143
- } else if (operationName in queries) {
144
- operationType = operationTypes.QUERIES;
145
- rv = queries[operationName];
146
- } else if (operationName in subscriptions) {
147
- operationType = operationTypes.SUBSCRIPTIONS;
148
- rv = subscriptions[operationName];
149
- }
150
- return [
151
- rv,
152
- operationType
153
- ];
154
- };
155
- const getOperationTypeForMutation = ({ operationName })=>{
156
- let operationType;
157
- if (operationName.includes('create')) {
158
- operationType = operationTypes.MUTATIONS.CREATE;
159
- } else if (operationName.includes('update')) {
160
- operationType = operationTypes.MUTATIONS.UPDATE;
161
- } else if (operationName.includes('delete')) {
162
- operationType = operationTypes.MUTATIONS.DELETE;
163
- } else {
164
- operationType = operationTypes.MUTATIONS.ACTION;
165
- }
166
- return operationType;
167
- };
168
- const getVariablesKeys = ({ variables, operationType })=>{
169
- let obj;
170
- let data;
171
- let where;
172
- if (variables && variables != '') {
173
- variables = JSON.parse(variables);
174
- switch(operationType){
175
- case operationTypes.QUERIES:
176
- where = variables && variables.where;
177
- return where && typeof where === 'object' ? Object.keys(where) : undefined;
178
- case operationTypes.MUTATIONS.CREATE:
179
- data = variables && variables['data'];
180
- return data && Array.isArray(data) ? Object.keys(data[0]) : typeof data === 'object' ? Object.keys(data) : undefined;
181
- default:
182
- obj = variables && variables['data'] || variables.where;
183
- return obj && Array.isArray(obj) && obj.length > 0 ? Object.keys(obj[0]) : typeof obj === 'object' ? Object.keys(obj) : undefined;
184
- }
185
- } else {
186
- return {};
187
- }
188
- };
189
- const insertNewVariable = ({ operationName, schema, key, value, _variables, action })=>{
190
- // get raw action from schema
191
- const [raw] = getOperationObjectFromSchema({
192
- operationName,
193
- schema
194
- });
195
- // loop through the _variables keys
196
- Object.keys(_variables).forEach((upper_key)=>{
197
- // get the args and loop through the arguments
198
- if (raw) {
199
- parseArgs({
200
- raw,
201
- _variables,
202
- upper_key,
203
- key,
204
- action,
205
- value
206
- });
207
- } else {
208
- throw `No Schema Action - '${operationName} - Go check the schema again'`;
209
- }
210
- });
211
- };
212
- const isArgMandatory = (arg)=>{
213
- const kind = getTypeKind(arg);
214
- const rv = kind === _language.Kind.NON_NULL_TYPE;
215
- return rv;
216
- };
217
- const parseInputDataToDataObject = ({ key, value, parent, method, list, state })=>{
218
- let rv = state;
219
- const type = typeof value;
220
- switch(type){
221
- case 'string':
222
- case 'number':
223
- case 'boolean':
224
- case 'bigint':
225
- rv = parent ? _object_spread_props(_object_spread({}, rv), {
226
- [parent]: _object_spread_props(_object_spread({}, rv[parent]), {
227
- [method]: _object_spread_props(_object_spread({}, rv[parent][method]), {
228
- [key]: value
229
- })
230
- })
231
- }) : _object_spread_props(_object_spread({}, rv), {
232
- [key]: value
233
- });
234
- break;
235
- case 'object':
236
- rv = parent ? {
237
- [parent]: _object_spread_props(_object_spread({}, rv[parent]), {
238
- [method]: _object_spread({}, rv[parent][method])
239
- })
240
- } : _object_spread_props(_object_spread({}, rv), {
241
- [key]: {
242
- [method]: list ? value.map(({ id })=>({
243
- id
244
- })) : {
245
- id: value.id
246
- }
247
- }
248
- });
249
- break;
250
- }
251
- return rv;
252
- };
253
- /// ================================================================= ///
254
- /// ============================= LOCAL ============================= ///
255
- // returns a value of type according to the field
256
- const buildValue = ({ name, value })=>{
257
- let rv;
258
- switch(name){
259
- case 'Float':
260
- rv = value || 0.0;
261
- break;
262
- case 'Int':
263
- rv = value || 0;
264
- break;
265
- case 'ID':
266
- rv = value || '000000000000000000000000';
267
- break;
268
- case 'String':
269
- rv = value || '';
270
- break;
271
- default:
272
- rv = name.includes('many') ? {
273
- connect: [
274
- {
275
- id: value || ''
276
- }
277
- ]
278
- } : {
279
- connect: {
280
- id: value || ''
281
- }
282
- };
283
- break;
284
- }
285
- return rv;
286
- };
287
- /// the first step in adding new variable from entity draggable
288
- const parseArgs = ({ raw, _variables, upper_key, key, action, value })=>{
289
- raw.args.forEach((arg)=>{
290
- // check if arg.name is equal to the _variables key
291
- if (upper_key === arg.name) {
292
- // get all fields keys
293
- const fields = getFieldsStringified({
294
- arg
295
- });
296
- const fields_obj = getFields({
297
- arg
298
- });
299
- // check if fields exists
300
- // loop through the fields
301
- if (fields.length > 0) {
302
- parseFields({
303
- fields,
304
- fields_obj,
305
- _variables,
306
- upper_key,
307
- key,
308
- action,
309
- value
310
- });
311
- } else {
312
- // throw `Schema Object/Action Does Not Have Any Fields - '${operationName} - ${getFlower()}'`;
313
- throw `Schema Object/Action Does Not Have Any Fields`;
314
- }
315
- }
316
- // if (_exists && raw.args.length > 0 && _exists === false) throw `Schema Object/Action Does Not Support - '${key}'`;
317
- });
318
- };
319
- /// the second step in adding new variable from entity draggable - take the fields and checks if this key is available / exists than set the entity according the operationType
320
- const parseFields = ({ fields, fields_obj, key, _variables, upper_key, value, action })=>{
321
- let _existsInFields = false;
322
- fields.forEach((field)=>{
323
- // create a pluralized entity_type value
324
- const _key = (0, _pluralize.default)(key);
325
- // check if either the single or the pluralized value exists in the key
326
- const exists = field.includes(_key.toLowerCase()) || field.includes(key.toLowerCase());
327
- // if indeed it exists
328
- if (exists === true) {
329
- _existsInFields = true;
330
- // get kind
331
- const kind = getTypeName(fields_obj[field]);
332
- // check if mutation or query
333
- if (action === 'mutation') {
334
- // check if the value is of type array
335
- setMutationEntityVariables({
336
- field,
337
- kind,
338
- _variables,
339
- upper_key,
340
- value
341
- });
342
- } else {
343
- // check if the string "some" exists 4in the field - meaning it is an array and format it accordingly
344
- setQueryEntityVariables({
345
- field,
346
- kind,
347
- _variables,
348
- upper_key,
349
- value
350
- });
351
- }
352
- }
353
- });
354
- if (_existsInFields === false) // throw `Schema Object/Action Does Not Support - '${key} - ${getFlower()}'`;
355
- throw `Schema Object/Action Does Not Support - '${key}'`;
356
- };
357
- const setMutationEntityVariables = ({ field, kind, _variables, upper_key, value })=>{
358
- Array.isArray(_variables[upper_key]) ? _variables[upper_key] = _variables[upper_key].map((item)=>_object_spread_props(_object_spread({}, item), {
359
- [field.toLowerCase()]: buildValue({
360
- name: kind,
361
- value
362
- })
363
- })) : _variables[upper_key] = _object_spread_props(_object_spread({}, _variables[upper_key]), {
364
- [field.toLowerCase()]: buildValue({
365
- name: kind,
366
- value
367
- })
368
- });
369
- };
370
- const setQueryEntityVariables = ({ field, _variables, upper_key, value })=>{
371
- field.includes('some') ? _variables[upper_key] = _object_spread_props(_object_spread({}, _variables[upper_key]), {
372
- [field]: {
373
- id_in: [
374
- value
375
- ]
376
- }
377
- }) : _variables[upper_key] = _object_spread_props(_object_spread({}, _variables[upper_key]), {
378
- [field]: value
379
- });
380
- } /// ================================================================= ///
381
- /// ============================= To Be Built ========================= ///
382
- ;