@mapomodule/utils 1.0.0-alpha.0 → 1.0.0-alpha.13
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.
- package/CHANGELOG.md +49 -0
- package/LICENSE.md +20 -0
- package/helpers/objHelpers.js +75 -4
- package/index.js +13 -0
- package/package.json +2 -6
- package/plugins/v-draggable-modals.js +39 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
# [1.0.0-alpha.13](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.12...v1.0.0-alpha.13) (2022-03-01)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* make all modals draggable 🛸 ([57da10d](https://github.com/lotrekagency/mapo/commit/57da10d17aa31d58e55fda5385d45d43beed8c4f))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [1.0.0-alpha.10](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.9...v1.0.0-alpha.10) (2022-02-11)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* fix objectHelper getPointed returning a keyerror when some point in path are missing ([6f1c2aa](https://github.com/lotrekagency/mapo/commit/6f1c2aa72176c9965e499135042de0646d9a04f8))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* **core:** Completely rewritten multipart capabilities, now the crud helper autodiscovers whet to use a multipart request. ([0a6546c](https://github.com/lotrekagency/mapo/commit/0a6546c9adeaf1fcf57a88105101e476b8b786dc))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# [1.0.0-alpha.9](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.8...v1.0.0-alpha.9) (2022-02-08)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
### Bug Fixes
|
|
37
|
+
|
|
38
|
+
* **core:** fix object setPointed to create missing nesting ([7a26510](https://github.com/lotrekagency/mapo/commit/7a26510d6c1648156bd5a8f18d3851e4fe195d29))
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
# [1.0.0-alpha.8](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.7...v1.0.0-alpha.8) (2022-01-23)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
### Features
|
|
48
|
+
|
|
49
|
+
* **quickedit:** merge detail component logics in to quickedit ([691f610](https://github.com/lotrekagency/mapo/commit/691f610b156f58a5d30598d89bf06425d90451d8))
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) Lotrek 2021
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
package/helpers/objHelpers.js
CHANGED
|
@@ -11,7 +11,7 @@ function deepClone(obj) {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
function getPointed(obj, kpointed, def) {
|
|
14
|
-
const result = kpointed.split(".").reduce((o, k) => typeof (o) == 'object' ? o[k] : o, obj)
|
|
14
|
+
const result = kpointed.split(".").reduce((o, k) => typeof (o) == 'object' ? (o || {})[k] : o, obj)
|
|
15
15
|
return result === undefined ? def : result
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -21,19 +21,90 @@ function setPointed(obj, kpointed, val) {
|
|
|
21
21
|
obj[arr[0]] = val
|
|
22
22
|
return obj
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
obj[arr[0]] = obj[arr[0]] || {}
|
|
25
|
+
return setPointed(obj[arr[0]], arr.slice(1), val)
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
function filterObj(obj, kpointedArr) {
|
|
28
|
-
return kpointedArr.reduce((acc, kpointed) => {
|
|
29
|
+
return (kpointedArr || []).reduce((acc, kpointed) => {
|
|
29
30
|
setPointed(acc, kpointed, getPointed(obj, kpointed))
|
|
30
31
|
return acc
|
|
31
32
|
}, {})
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
function isFileInstance(input) {
|
|
36
|
+
if ('File' in window && input instanceof File)
|
|
37
|
+
return true;
|
|
38
|
+
else return false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function isBlobInstance(input) {
|
|
42
|
+
if ('Blob' in window && input instanceof Blob)
|
|
43
|
+
return true;
|
|
44
|
+
else return false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function isFileOrBlob(input) {
|
|
48
|
+
return isFileInstance(input) || isBlobInstance(input)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function filesInObject(obj) {
|
|
52
|
+
return findPropPaths(obj, ({ val }) => isFileOrBlob(val))
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function findPropPaths(obj, predicate) {
|
|
56
|
+
const discoveredObjects = [];
|
|
57
|
+
const path = [];
|
|
58
|
+
const results = [];
|
|
59
|
+
if (!obj && (typeof obj !== "object" || Array.isArray(obj))) {
|
|
60
|
+
throw new TypeError("First argument of finPropPath is not the correct type Object");
|
|
61
|
+
}
|
|
62
|
+
if (typeof predicate !== "function") {
|
|
63
|
+
throw new TypeError("Predicate is not a function");
|
|
64
|
+
}
|
|
65
|
+
(function find(obj) {
|
|
66
|
+
for (const key of Object.keys(obj)) {
|
|
67
|
+
if (predicate({ val: obj[key], obj, path, key }) === true) {
|
|
68
|
+
path.push(key);
|
|
69
|
+
results.push(path.join("."));
|
|
70
|
+
path.pop();
|
|
71
|
+
}
|
|
72
|
+
const o = obj[key];
|
|
73
|
+
if (o && typeof o === "object" && !Array.isArray(o)) {
|
|
74
|
+
if (!discoveredObjects.find(obj => obj === o)) {
|
|
75
|
+
path.push(key);
|
|
76
|
+
discoveredObjects.push(o);
|
|
77
|
+
find(o);
|
|
78
|
+
path.pop();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}(obj));
|
|
83
|
+
return results;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function diffObjs(obj1, obj2) {
|
|
87
|
+
const a = deepClone(obj1)
|
|
88
|
+
const b = deepClone(obj2)
|
|
89
|
+
for (const i in b) {
|
|
90
|
+
if (JSON.stringify(a[i]) === JSON.stringify(b[i])) {
|
|
91
|
+
delete b[i]
|
|
92
|
+
} else if (!Array.isArray(b[i]) && typeof b[i] == 'object') {
|
|
93
|
+
b[i] = diffObjs(a[i], b[i])
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return b;
|
|
97
|
+
}
|
|
98
|
+
|
|
34
99
|
module.exports = {
|
|
35
100
|
deepClone,
|
|
36
101
|
getPointed,
|
|
37
102
|
setPointed,
|
|
38
|
-
filterObj
|
|
103
|
+
filterObj,
|
|
104
|
+
isFileInstance,
|
|
105
|
+
isBlobInstance,
|
|
106
|
+
isFileOrBlob,
|
|
107
|
+
filesInObject,
|
|
108
|
+
findPropPaths,
|
|
109
|
+
diffObjs
|
|
39
110
|
}
|
package/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const auth = require('./helpers/auth');
|
|
2
|
+
const debounce = require('./helpers/debounce');
|
|
3
|
+
const formatters = require('./helpers/formatters');
|
|
4
|
+
const objHelpers = require('./helpers/objHelpers');
|
|
5
|
+
const VDraggableModals = require('./plugins/v-draggable-modals');
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
auth,
|
|
9
|
+
debounce,
|
|
10
|
+
formatters,
|
|
11
|
+
objHelpers,
|
|
12
|
+
VDraggableModals,
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mapomodule/utils",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.13",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "This is part of Mapo nuxt module. Provides a set of utils for the project.",
|
|
6
6
|
"author": "bnznamco <gabriele.baldi.01@gmail.com>",
|
|
7
7
|
"repository": "https://github.com/lotrekagency/mapo",
|
|
8
8
|
"main": "./index.js",
|
|
9
|
-
"files": [
|
|
10
|
-
"helpers",
|
|
11
|
-
"loaders"
|
|
12
|
-
],
|
|
13
9
|
"dependencies": {
|
|
14
10
|
"js-cookie": "^2.2.1"
|
|
15
11
|
},
|
|
16
12
|
"publishConfig": {
|
|
17
13
|
"access": "public"
|
|
18
14
|
},
|
|
19
|
-
"gitHead": "
|
|
15
|
+
"gitHead": "b0fac0f5ebde4c65cc5347dbb841392dc04ef5e8"
|
|
20
16
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module.exports = function () {
|
|
2
|
+
const d = {};
|
|
3
|
+
document.addEventListener("mousedown", e => {
|
|
4
|
+
const closestDialog = e.target.closest(".v-dialog.v-dialog--active");
|
|
5
|
+
if (e.button === 0 && closestDialog != null && e.target.classList.contains("v-card__title")) {
|
|
6
|
+
d.el = closestDialog;
|
|
7
|
+
d.mouseStartX = e.clientX;
|
|
8
|
+
d.mouseStartY = e.clientY;
|
|
9
|
+
d.elStartX = d.el.getBoundingClientRect().left;
|
|
10
|
+
d.elStartY = d.el.getBoundingClientRect().top;
|
|
11
|
+
d.el.style.position = "fixed";
|
|
12
|
+
d.el.style.margin = 0;
|
|
13
|
+
d.oldTransition = d.el.style.transition;
|
|
14
|
+
d.el.style.transition = "none"
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
document.addEventListener("mousemove", e => {
|
|
18
|
+
if (d.el === undefined) return;
|
|
19
|
+
d.el.style.left = Math.min(
|
|
20
|
+
Math.max(d.elStartX + e.clientX - d.mouseStartX, 0),
|
|
21
|
+
window.innerWidth - d.el.getBoundingClientRect().width
|
|
22
|
+
) + "px";
|
|
23
|
+
d.el.style.top = Math.min(
|
|
24
|
+
Math.max(d.elStartY + e.clientY - d.mouseStartY, 0),
|
|
25
|
+
window.innerHeight - d.el.getBoundingClientRect().height
|
|
26
|
+
) + "px";
|
|
27
|
+
});
|
|
28
|
+
document.addEventListener("mouseup", () => {
|
|
29
|
+
if (d.el === undefined) return;
|
|
30
|
+
d.el.style.transition = d.oldTransition;
|
|
31
|
+
d.el = undefined
|
|
32
|
+
});
|
|
33
|
+
setInterval(() => {
|
|
34
|
+
const dialog = document.querySelector(".v-dialog.v-dialog--active");
|
|
35
|
+
if (dialog === null) return;
|
|
36
|
+
dialog.style.left = Math.min(parseInt(dialog.style.left), window.innerWidth - dialog.getBoundingClientRect().width) + "px";
|
|
37
|
+
dialog.style.top = Math.min(parseInt(dialog.style.top), window.innerHeight - dialog.getBoundingClientRect().height) + "px";
|
|
38
|
+
}, 100);
|
|
39
|
+
}
|