@get-set/gs-sortable 0.0.14 → 0.0.16
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,5 +1,4 @@
|
|
|
1
1
|
import { useEffect, useRef, useState } from 'react';
|
|
2
|
-
import NewGuid from '../helpers/uihelpers';
|
|
3
2
|
import getCurrentParams from '../actions/getCurrentParams';
|
|
4
3
|
import init from '../actions/init';
|
|
5
4
|
import destroy from '../actions/destroy';
|
|
@@ -10,10 +9,17 @@ import initSortEnd from '../actions/initSortEnd';
|
|
|
10
9
|
import initScroll from '../actions/initScroll';
|
|
11
10
|
import types from '../constants/types';
|
|
12
11
|
import './styles/GSSortable.css';
|
|
12
|
+
import {
|
|
13
|
+
NewGuid,
|
|
14
|
+
convertScssToCss,
|
|
15
|
+
injectCssToHead,
|
|
16
|
+
} from '../helpers/uihelpers';
|
|
13
17
|
|
|
14
18
|
const params = {
|
|
15
19
|
reference: PropTypes.string,
|
|
16
20
|
handler: PropTypes.string,
|
|
21
|
+
className: PropTypes.string,
|
|
22
|
+
gsx: PropTypes.object,
|
|
17
23
|
gap: PropTypes.string,
|
|
18
24
|
allowOutOfBox: PropTypes.bool,
|
|
19
25
|
count: PropTypes.number,
|
|
@@ -26,6 +32,8 @@ const params = {
|
|
|
26
32
|
* @component
|
|
27
33
|
* @param {Object} props - The props object.
|
|
28
34
|
* @param {string} props.reference - Unique key for each sortable.
|
|
35
|
+
* @param {boolean} props.className - Enable add classes.
|
|
36
|
+
* @param {React.CSSProperties & Record<string, React.CSSProperties | Record<string, React.CSSProperties | Record<string, React.CSSProperties | Record<string, React.CSSProperties>>>} props.gsx
|
|
29
37
|
* @param {string} props.gap - Allows set gap among elements.
|
|
30
38
|
* @param {string} props.handler - selector of target element to move.
|
|
31
39
|
* @param {number} props.count - Shows items count per row.
|
|
@@ -95,6 +103,15 @@ const GSSortable = ({ children, ...rest }) => {
|
|
|
95
103
|
const currentRef = window.GSSortableConfigue.references.find(
|
|
96
104
|
x => x.key === componentKey,
|
|
97
105
|
).ref;
|
|
106
|
+
|
|
107
|
+
if (params.gsx != undefined) {
|
|
108
|
+
const scss = {};
|
|
109
|
+
scss[`[data-key='${componentKey}']`] = {
|
|
110
|
+
...params.gsx,
|
|
111
|
+
};
|
|
112
|
+
const style = convertScssToCss(scss);
|
|
113
|
+
injectCssToHead(style, componentKey);
|
|
114
|
+
}
|
|
98
115
|
init(currentRef);
|
|
99
116
|
}
|
|
100
117
|
return () => {
|
|
@@ -104,6 +121,7 @@ const GSSortable = ({ children, ...rest }) => {
|
|
|
104
121
|
x => x.key !== componentKey,
|
|
105
122
|
);
|
|
106
123
|
}
|
|
124
|
+
removeCssToHead(componentKey);
|
|
107
125
|
};
|
|
108
126
|
}
|
|
109
127
|
}, [componentKey]);
|
|
@@ -115,7 +133,6 @@ const GSSortable = ({ children, ...rest }) => {
|
|
|
115
133
|
}, []);
|
|
116
134
|
|
|
117
135
|
useEffect(() => {
|
|
118
|
-
console.log('children change');
|
|
119
136
|
if (componentKey != null) {
|
|
120
137
|
const ref = window.GSSortableConfigue.instance(componentKey);
|
|
121
138
|
if (ref !== undefined) {
|
|
@@ -126,7 +143,7 @@ const GSSortable = ({ children, ...rest }) => {
|
|
|
126
143
|
|
|
127
144
|
return (
|
|
128
145
|
<div
|
|
129
|
-
className={`gs-sortable-instance gs-sortable-${params.type}`}
|
|
146
|
+
className={`gs-sortable-instance gs-sortable-${params.type} ${rest.className}`}
|
|
130
147
|
ref={gridRef}
|
|
131
148
|
{...Object.fromEntries(
|
|
132
149
|
Object.entries({ ...rest }).filter(([key]) => !(key in defaultParams)),
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
.gs-sortable-instance {
|
|
2
|
-
box-sizing: border-box;
|
|
3
|
-
-webkit-user-select: none !important;
|
|
4
|
-
-moz-user-select: none !important;
|
|
5
|
-
user-select: none !important;
|
|
6
|
-
transition: 0.4s;
|
|
7
|
-
z-index: 1;
|
|
8
|
-
}
|
|
9
|
-
.gs-sortable-instance.gs-sortable-active {
|
|
10
|
-
z-index: 2;
|
|
11
|
-
}
|
|
12
|
-
.gs-sortable-instance * {
|
|
13
|
-
-webkit-user-select: none !important;
|
|
14
|
-
-moz-user-select: none !important;
|
|
15
|
-
user-select: none !important;
|
|
16
|
-
}
|
|
17
|
-
.gs-sortable-instance .gs-sortable-placeholder {
|
|
18
|
-
position: absolute;
|
|
19
|
-
background-color: #f1f1f1;
|
|
20
|
-
border: 1px solid;
|
|
21
|
-
z-index: 1;
|
|
22
|
-
}
|
|
23
|
-
.gs-sortable-instance .gs-sortable-item {
|
|
24
|
-
z-index: 2;
|
|
25
|
-
}
|
|
26
|
-
.gs-sortable-instance .gs-sortable-item.gs-sortable-item-active-parent {
|
|
27
|
-
z-index: 3;
|
|
28
|
-
}
|
|
29
|
-
.gs-sortable-instance .gs-sortable-item-inmove {
|
|
30
|
-
transition: none !important;
|
|
31
|
-
z-index: 99999;
|
|
32
|
-
}
|
|
33
|
-
.gs-sortable-instance .gs-sortable-item-addjusting {
|
|
34
|
-
z-index: 99999;
|
|
35
|
-
}
|
|
36
|
-
.gs-sortable-instance.gs-sortable-row .gs-sortable-item {
|
|
37
|
-
width: -moz-max-content;
|
|
38
|
-
width: max-content;
|
|
1
|
+
.gs-sortable-instance {
|
|
2
|
+
box-sizing: border-box;
|
|
3
|
+
-webkit-user-select: none !important;
|
|
4
|
+
-moz-user-select: none !important;
|
|
5
|
+
user-select: none !important;
|
|
6
|
+
transition: 0.4s;
|
|
7
|
+
z-index: 1;
|
|
8
|
+
}
|
|
9
|
+
.gs-sortable-instance.gs-sortable-active {
|
|
10
|
+
z-index: 2;
|
|
11
|
+
}
|
|
12
|
+
.gs-sortable-instance * {
|
|
13
|
+
-webkit-user-select: none !important;
|
|
14
|
+
-moz-user-select: none !important;
|
|
15
|
+
user-select: none !important;
|
|
16
|
+
}
|
|
17
|
+
.gs-sortable-instance .gs-sortable-placeholder {
|
|
18
|
+
position: absolute;
|
|
19
|
+
background-color: #f1f1f1;
|
|
20
|
+
border: 1px solid;
|
|
21
|
+
z-index: 1;
|
|
22
|
+
}
|
|
23
|
+
.gs-sortable-instance .gs-sortable-item {
|
|
24
|
+
z-index: 2;
|
|
25
|
+
}
|
|
26
|
+
.gs-sortable-instance .gs-sortable-item.gs-sortable-item-active-parent {
|
|
27
|
+
z-index: 3;
|
|
28
|
+
}
|
|
29
|
+
.gs-sortable-instance .gs-sortable-item-inmove {
|
|
30
|
+
transition: none !important;
|
|
31
|
+
z-index: 99999;
|
|
32
|
+
}
|
|
33
|
+
.gs-sortable-instance .gs-sortable-item-addjusting {
|
|
34
|
+
z-index: 99999;
|
|
35
|
+
}
|
|
36
|
+
.gs-sortable-instance.gs-sortable-row .gs-sortable-item {
|
|
37
|
+
width: -moz-max-content;
|
|
38
|
+
width: max-content;
|
|
39
39
|
}/*# sourceMappingURL=GSSortable.css.map */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const NewGuid = () => {
|
|
1
|
+
export const NewGuid = () => {
|
|
2
2
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
3
3
|
const r = (Math.random() * 16) | 0,
|
|
4
4
|
v = c == 'x' ? r : (r & 0x3) | 0x8;
|
|
@@ -6,4 +6,47 @@ const NewGuid = () => {
|
|
|
6
6
|
});
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
export
|
|
9
|
+
export const removeCssToHead = key => {
|
|
10
|
+
const style = document.querySelector(`head style[data-key='${key}']`);
|
|
11
|
+
if (style != null) {
|
|
12
|
+
style.remove();
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
export const injectCssToHead = (css, key) => {
|
|
16
|
+
// Create a <style> element
|
|
17
|
+
const style = document.createElement('style');
|
|
18
|
+
style.dataset.key = key;
|
|
19
|
+
// Set the CSS as the inner content of the <style> element
|
|
20
|
+
style.innerHTML = css;
|
|
21
|
+
// Append the <style> element to the <head>
|
|
22
|
+
document.head.appendChild(style);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const camelToKebab = str =>
|
|
26
|
+
str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
|
27
|
+
|
|
28
|
+
export const convertScssToCss = scssObj => {
|
|
29
|
+
// Helper function to handle nested objects
|
|
30
|
+
const convertObjectToCss = (obj, parent = '') => {
|
|
31
|
+
let css = '';
|
|
32
|
+
|
|
33
|
+
// Iterate over each key-value pair in the SCSS object
|
|
34
|
+
for (let key in obj) {
|
|
35
|
+
const value = obj[key];
|
|
36
|
+
|
|
37
|
+
if (typeof value === 'object') {
|
|
38
|
+
// If the value is an object, it's a nested rule, so we recurse
|
|
39
|
+
const newParent = parent ? `${parent} ${key}` : key;
|
|
40
|
+
css += convertObjectToCss(value, newParent); // Recurse and concatenate
|
|
41
|
+
} else {
|
|
42
|
+
// Otherwise, it's a property-value pair (e.g. color: red)
|
|
43
|
+
css += `${parent} { ${camelToKebab(key)}: ${value}; }\n`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return css;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// Start recursion with the top-level object
|
|
51
|
+
return convertObjectToCss(scssObj, '');
|
|
52
|
+
};
|