kempo-ui 0.0.28 → 0.0.30
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/.github/copilot-instructions.md +16 -0
- package/color-picker-fixed.png +0 -0
- package/dist/components/Accordion.js +1 -1
- package/dist/components/ColorPicker.js +34 -0
- package/dist/components/Table.js +1 -1
- package/dist/utils/cookie.js +1 -0
- package/dist/utils/object.js +1 -0
- package/dist/utils/string.js +1 -0
- package/dist/utils/type.js +1 -0
- package/dist/utils/wait.js +1 -0
- package/docs/components/color-picker.html +369 -0
- package/docs/components/content-slider.html +2 -2
- package/docs/components/theme-switcher.html +4 -4
- package/docs/index.html +33 -3
- package/docs/init-1.js +1 -1
- package/docs/nav-1.inc.html +6 -1
- package/docs/nav.inc.html +6 -1
- package/docs/src/components/Accordion.js +1 -1
- package/docs/src/components/ColorPicker.js +34 -0
- package/docs/src/components/Table.js +1 -1
- package/docs/src/utils/cookie.js +1 -0
- package/docs/src/utils/object.js +1 -0
- package/docs/src/utils/string.js +1 -0
- package/docs/src/utils/type.js +1 -0
- package/docs/src/utils/wait.js +1 -0
- package/docs/utils/cookie.html +145 -0
- package/docs/utils/object.html +93 -0
- package/docs/utils/string.html +83 -0
- package/docs/utils/toTitleCase.html +2 -1
- package/docs/utils/type.html +48 -0
- package/docs/utils/wait.html +48 -0
- package/package.json +1 -1
- package/src/components/Accordion.js +5 -13
- package/src/components/Card.js +1 -3
- package/src/components/ColorPicker.js +578 -0
- package/src/components/ContentSlider.js +1 -3
- package/src/components/Dialog.js +1 -3
- package/src/components/Icon.js +1 -3
- package/src/components/Import.js +1 -3
- package/src/components/PhotoViewer.js +1 -3
- package/src/components/Resize.js +1 -3
- package/src/components/ShowMore.js +1 -3
- package/src/components/SideMenu.js +1 -3
- package/src/components/Table.js +1 -1
- package/src/components/ThemeSwitcher.js +1 -3
- package/src/components/tableControls/Edit.js +1 -3
- package/src/components/tableControls/HiddenCount.js +1 -3
- package/src/components/tableControls/Search.js +1 -3
- package/src/components/tableControls/TableControl.js +1 -3
- package/src/utils/cookie.js +20 -0
- package/src/utils/object.js +198 -0
- package/src/utils/string.js +74 -0
- package/src/utils/type.js +13 -0
- package/src/utils/wait.js +18 -0
- package/dist/utils/toTitleCase.js +0 -1
- package/docs/src/utils/toTitleCase.js +0 -1
- package/src/utils/toTitleCase.js +0 -9
|
@@ -2,9 +2,7 @@ import ShadowComponent from '../ShadowComponent.js';
|
|
|
2
2
|
import { html, css } from '../../lit-all.min.js';
|
|
3
3
|
|
|
4
4
|
export default class TableControl extends ShadowComponent {
|
|
5
|
-
/*
|
|
6
|
-
Properties
|
|
7
|
-
*/
|
|
5
|
+
/* Properties */
|
|
8
6
|
static properties = {
|
|
9
7
|
maxWidth: { type: Number, reflect: true, attribute: 'max-width' }
|
|
10
8
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const saveCookie = (name, value, minutes = 30 * 24 * 60, path = '/') => {
|
|
2
|
+
const expires = new Date(Date.now() + minutes * 60 * 1000);
|
|
3
|
+
document.cookie = `${name}=${value};expires=${expires.toUTCString()};path=${path}`;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export const getCookie = (name) => {
|
|
7
|
+
const cookies = document.cookie.split(';').map(cookie => cookie.trim().split('='));
|
|
8
|
+
const cookie = cookies.find(cookie => cookie[0] === name);
|
|
9
|
+
return cookie ? cookie[1] : null;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const deleteCookie = (name) => {
|
|
13
|
+
document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 UTC;path=/`;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default {
|
|
17
|
+
saveCookie,
|
|
18
|
+
getCookie,
|
|
19
|
+
deleteCookie
|
|
20
|
+
};
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { typeOf } from './type.js';
|
|
2
|
+
|
|
3
|
+
export const toJson = (obj) => {
|
|
4
|
+
return JSON.stringify(obj, (key, value) => {
|
|
5
|
+
if (key !== '' && value === obj) {
|
|
6
|
+
return '<<Circular Reference>>';
|
|
7
|
+
} else if (typeof(Element) !== 'undefined' && value instanceof Element) {
|
|
8
|
+
return value.outerHTML;
|
|
9
|
+
} else if(typeOf(value) === 'function'){
|
|
10
|
+
return `<<Function ${key}>>`;
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const flattenObject = (
|
|
17
|
+
obj,
|
|
18
|
+
maxDepth = 100,
|
|
19
|
+
prevDepth = 0,
|
|
20
|
+
parentKeys = []
|
|
21
|
+
) => {
|
|
22
|
+
const thisDepth = prevDepth + 1;
|
|
23
|
+
if (obj === null) return {};
|
|
24
|
+
return Object.keys(obj).reduce((o, k) => {
|
|
25
|
+
const v = obj[k];
|
|
26
|
+
const key = [...parentKeys, k].join('.');
|
|
27
|
+
if (typeOf(Element) !== 'undefined' && v instanceof Element) {
|
|
28
|
+
return {
|
|
29
|
+
...o,
|
|
30
|
+
[key]: v.outerHTML
|
|
31
|
+
};
|
|
32
|
+
} else if (v === null) {
|
|
33
|
+
return {
|
|
34
|
+
...o,
|
|
35
|
+
[key]: null
|
|
36
|
+
};
|
|
37
|
+
} else if (typeof v === 'object') {
|
|
38
|
+
if (maxDepth <= thisDepth) {
|
|
39
|
+
return {
|
|
40
|
+
...o,
|
|
41
|
+
[key]: '<<Max Depth Reached>>'
|
|
42
|
+
};
|
|
43
|
+
} else {
|
|
44
|
+
return {
|
|
45
|
+
...o,
|
|
46
|
+
...flattenObject(v, maxDepth, thisDepth, [...parentKeys, k])
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
return {
|
|
51
|
+
...o,
|
|
52
|
+
[key]: v
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}, {});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const flattenedObjects = (...objects) => objects.map(o=>flattenObject(o));
|
|
59
|
+
|
|
60
|
+
export const objectSummary = (object, maxLength = 100) => {
|
|
61
|
+
if (typeof object === 'object') {
|
|
62
|
+
const flatObject = flattenObject(object);
|
|
63
|
+
const kvp = []; // key value pairs
|
|
64
|
+
Object.keys(flatObject).forEach((key) => {
|
|
65
|
+
kvp.push(`${key} = ${objectSummary(flatObject[key])}`);
|
|
66
|
+
});
|
|
67
|
+
return kvp.join(', ').substring(0, maxLength);
|
|
68
|
+
} else {
|
|
69
|
+
return `${object}`.substring(0, maxLength);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export const clone = (obj) => {
|
|
74
|
+
const type = typeof obj;
|
|
75
|
+
const Element =
|
|
76
|
+
typeof window === 'undefined' ? class Element {} : window.Element; // So this can run in Node
|
|
77
|
+
if (obj instanceof Element) {
|
|
78
|
+
return obj.outerHTML;
|
|
79
|
+
} else if (obj === null) {
|
|
80
|
+
return null;
|
|
81
|
+
} else if (
|
|
82
|
+
['string', 'number', 'boolean', 'undefined', 'bigint'].includes(type)
|
|
83
|
+
) {
|
|
84
|
+
return obj;
|
|
85
|
+
} else if (type === 'symbol') {
|
|
86
|
+
return '<<SYMBOL>>';
|
|
87
|
+
} else if (type === 'function') {
|
|
88
|
+
return '<<function>>';
|
|
89
|
+
} else if (obj instanceof Array) {
|
|
90
|
+
return obj.map((item) => clone(item));
|
|
91
|
+
} else if (type === 'object') {
|
|
92
|
+
return Object.keys(obj).reduce((r, k) => {
|
|
93
|
+
return {
|
|
94
|
+
...r,
|
|
95
|
+
[k]: clone(obj[k])
|
|
96
|
+
};
|
|
97
|
+
}, {});
|
|
98
|
+
} else {
|
|
99
|
+
return obj;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export const equalObjs = (...objs) => {
|
|
104
|
+
if (objs.length < 2) return true;
|
|
105
|
+
const first = toJson(objs[0]);
|
|
106
|
+
for (let i = 1; i < objs.length; i++) {
|
|
107
|
+
if (first !== toJson(objs[i])) return false;
|
|
108
|
+
}
|
|
109
|
+
return true;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const pruneVar = (value) => {
|
|
113
|
+
if (typeof value === 'undefined') {
|
|
114
|
+
return [undefined, true];
|
|
115
|
+
} else if (typeof value === 'string') {
|
|
116
|
+
return [value, value === ''];
|
|
117
|
+
} else if (value instanceof Array) {
|
|
118
|
+
return [value, value.length === 0];
|
|
119
|
+
} else if (value === null) {
|
|
120
|
+
return [value, false];
|
|
121
|
+
} else if (typeof value === 'object') {
|
|
122
|
+
// eslint-disable-next-line no-use-before-define
|
|
123
|
+
return pruneObject(value);
|
|
124
|
+
}
|
|
125
|
+
return [value, false];
|
|
126
|
+
};
|
|
127
|
+
const pruneObject = (object) => {
|
|
128
|
+
const results = {};
|
|
129
|
+
Object.keys(object).forEach((key) => {
|
|
130
|
+
const [pruned, isBlank] = pruneVar(object[key]);
|
|
131
|
+
if (!isBlank) {
|
|
132
|
+
results[key] = pruned;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
return [results, Object.keys(results).length === 0];
|
|
136
|
+
};
|
|
137
|
+
export const prune = (object) => {
|
|
138
|
+
return pruneObject(object)[0]
|
|
139
|
+
}
|
|
140
|
+
export const getAllKeys = (...objects) => [...new Set(objects.map(o => Object.keys(o)).flat())];
|
|
141
|
+
export const getDifferencesKeys = (...objects) => {
|
|
142
|
+
return getAllKeys(...objects)
|
|
143
|
+
.map(k => new Set(objects.map(o => o[k])).size !== 1 ? k : null)
|
|
144
|
+
.filter(k => k !== null);
|
|
145
|
+
}
|
|
146
|
+
export const diff = (obj1, obj2) => {
|
|
147
|
+
const result = {};
|
|
148
|
+
|
|
149
|
+
function compareValues(path, value1, value2) {
|
|
150
|
+
if (Array.isArray(value1) && Array.isArray(value2)) {
|
|
151
|
+
if (value1.length !== value2.length || !value1.every((v, i) => v === value2[i])) {
|
|
152
|
+
result[path.join('.')] = { newValue: value1, oldValue: value2 };
|
|
153
|
+
}
|
|
154
|
+
} else if (typeof value1 === 'object' && typeof value2 === 'object') {
|
|
155
|
+
compareObjects([...path], value1, value2);
|
|
156
|
+
} else if (value1 !== value2) {
|
|
157
|
+
result[path.join('.')] = { newValue: value1, oldValue: value2 };
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function compareObjects(path, obj1, obj2) {
|
|
162
|
+
for (const key in obj1) {
|
|
163
|
+
if (obj1.hasOwnProperty(key)) {
|
|
164
|
+
const value1 = obj1[key];
|
|
165
|
+
const value2 = obj2[key];
|
|
166
|
+
|
|
167
|
+
compareValues([...path, key], value1, value2);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
compareObjects([], obj1, obj2);
|
|
173
|
+
return result;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export const mapObject = (obj, func) => {
|
|
177
|
+
return Object.entries(obj).reduce((newObj, [key, value]) => {
|
|
178
|
+
const [newKey, newValue] = func(key, value);
|
|
179
|
+
newObj[newKey] = newValue;
|
|
180
|
+
return newObj;
|
|
181
|
+
}, {});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export default {
|
|
185
|
+
toJson,
|
|
186
|
+
flattenObject,
|
|
187
|
+
flattenedObjects,
|
|
188
|
+
objectSummary,
|
|
189
|
+
clone,
|
|
190
|
+
equalObjs,
|
|
191
|
+
pruneVar,
|
|
192
|
+
pruneObject,
|
|
193
|
+
prune,
|
|
194
|
+
getAllKeys,
|
|
195
|
+
getDifferencesKeys,
|
|
196
|
+
diff,
|
|
197
|
+
mapObject
|
|
198
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export const camelToDash = (str) => str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
|
2
|
+
export const dashToCamel = (str) => str.replace(/-([a-z])/g, (_, group) => group.toUpperCase());
|
|
3
|
+
export const isCamelCase = (str) => /[a-z][A-Z]/.test(str);
|
|
4
|
+
export const getCase = (str) => {
|
|
5
|
+
if(isCamelCase(str)){
|
|
6
|
+
return {
|
|
7
|
+
camel: str,
|
|
8
|
+
dash: camelToDash(str)
|
|
9
|
+
}
|
|
10
|
+
} else {
|
|
11
|
+
return {
|
|
12
|
+
camel: dashToCamel(str),
|
|
13
|
+
dash: str
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export const escapeHTML = str => str.replace(/[&<>"'/]/g, match => {
|
|
18
|
+
switch (match) {
|
|
19
|
+
case '&':
|
|
20
|
+
return '&';
|
|
21
|
+
case '<':
|
|
22
|
+
return '<';
|
|
23
|
+
case '>':
|
|
24
|
+
return '>';
|
|
25
|
+
case '"':
|
|
26
|
+
return '"';
|
|
27
|
+
case "'":
|
|
28
|
+
return ''';
|
|
29
|
+
case '/':
|
|
30
|
+
return '/';
|
|
31
|
+
default:
|
|
32
|
+
return match;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
export const unescapeHTML = str => str.replace(/&|<|>|"|'|//g, match => {
|
|
36
|
+
switch (match) {
|
|
37
|
+
case '&':
|
|
38
|
+
return '&';
|
|
39
|
+
case '<':
|
|
40
|
+
return '<';
|
|
41
|
+
case '>':
|
|
42
|
+
return '>';
|
|
43
|
+
case '"':
|
|
44
|
+
return '"';
|
|
45
|
+
case ''':
|
|
46
|
+
return "'";
|
|
47
|
+
case '/':
|
|
48
|
+
return '/';
|
|
49
|
+
default:
|
|
50
|
+
return match;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
});
|
|
54
|
+
export const trim = (str, chars) => str.replace(new RegExp(`^[${chars}]+|[${chars}]+$`, 'g'), '');
|
|
55
|
+
export const compoundKey = keys => trim(keys.join('.'), '.');
|
|
56
|
+
export const toTitleCase = str =>
|
|
57
|
+
str
|
|
58
|
+
.replace(/([A-Z])/g, ' $1')
|
|
59
|
+
.split(/[\s_-]+/)
|
|
60
|
+
.filter(word => word.length > 0)
|
|
61
|
+
.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
62
|
+
.join(' ');
|
|
63
|
+
|
|
64
|
+
export default {
|
|
65
|
+
camelToDash,
|
|
66
|
+
dashToCamel,
|
|
67
|
+
isCamelCase,
|
|
68
|
+
getCase,
|
|
69
|
+
escapeHTML,
|
|
70
|
+
unescapeHTML,
|
|
71
|
+
trim,
|
|
72
|
+
compoundKey,
|
|
73
|
+
toTitleCase
|
|
74
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const typeOf = value => {
|
|
2
|
+
if(value === null) return 'null';
|
|
3
|
+
else if(value instanceof Array) return 'array';
|
|
4
|
+
else if(typeof(Element) !== 'undefined' && value instanceof Element) return 'element';
|
|
5
|
+
else return typeof(value);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const isType = (value, type) => typeOf(value) === type;
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
typeOf,
|
|
12
|
+
isType
|
|
13
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const wait = (ms) => new Promise(resolve=>new Timeout(resolve,ms));
|
|
2
|
+
const waitFrmaes = (frameCount = 1) => {
|
|
3
|
+
return new Promise((resolve) => {
|
|
4
|
+
let frames = 0;
|
|
5
|
+
|
|
6
|
+
function frameHandler() {
|
|
7
|
+
frames++;
|
|
8
|
+
|
|
9
|
+
if (frames >= frameCount) {
|
|
10
|
+
resolve();
|
|
11
|
+
} else {
|
|
12
|
+
requestAnimationFrame(frameHandler);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
requestAnimationFrame(frameHandler);
|
|
17
|
+
});
|
|
18
|
+
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const toTitleCase=e=>e.replace(/([A-Z])/g," $1").split(/[\s_-]+/).filter(e=>e.length>0).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(" ");export default toTitleCase;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const toTitleCase=e=>e.replace(/([A-Z])/g," $1").split(/[\s_-]+/).filter(e=>e.length>0).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(" ");export default toTitleCase;
|
package/src/utils/toTitleCase.js
DELETED