@eightshift/ui-components 0.0.3 → 0.0.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.
- package/dist/assets/style.css +1 -1
- package/dist/assets/wp.css +1 -1
- package/dist/components/breakpoint-preview/breakpoint-preview.js +1 -1
- package/dist/components/index.js +120 -0
- package/dist/components/matrix-align/matrix-align.js +1 -1
- package/dist/components/options-panel/options-panel.js +57 -0
- package/dist/components/responsive/responsive-legacy.js +1 -1
- package/dist/components/responsive/responsive.js +1 -1
- package/dist/components/responsive-preview/responsive-preview.js +1 -1
- package/dist/components/tabs/tabs.js +22 -8
- package/dist/icons/icons.js +8 -0
- package/dist/icons/index.js +12 -0
- package/dist/index.js +4 -17
- package/dist/utilities/debounce-throttle.js +123 -0
- package/dist/utilities/es-dash.js +376 -0
- package/dist/utilities/index.js +18 -1
- package/dist/utilities/text-helpers.js +68 -81
- package/package.json +14 -4
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
var stringKebabCase = kebabCase$1;
|
|
2
|
+
var wordSeparators = /[\s\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~]+/;
|
|
3
|
+
var capital_plus_lower = /[A-ZÀ-Ý\u00C0-\u00D6\u00D9-\u00DD][a-zà-ÿ]/g;
|
|
4
|
+
var capitals = /[A-ZÀ-Ý\u00C0-\u00D6\u00D9-\u00DD]+/g;
|
|
5
|
+
function kebabCase$1(str) {
|
|
6
|
+
str = str.replace(capital_plus_lower, function(match) {
|
|
7
|
+
return " " + (match[0].toLowerCase() || match[0]) + match[1];
|
|
8
|
+
});
|
|
9
|
+
str = str.replace(capitals, function(match) {
|
|
10
|
+
return " " + match.toLowerCase();
|
|
11
|
+
});
|
|
12
|
+
return str.trim().split(wordSeparators).join("-").replace(/^-/, "").replace(/-\s*$/, "");
|
|
13
|
+
}
|
|
14
|
+
var stringCamelCase = camelCase$1;
|
|
15
|
+
var wordSeparatorsRegEx = /[\s\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~]+/;
|
|
16
|
+
var basicCamelRegEx = /^[a-z\u00E0-\u00FCA-Z\u00C0-\u00DC][\d|a-z\u00E0-\u00FCA-Z\u00C0-\u00DC]*$/;
|
|
17
|
+
var fourOrMoreConsecutiveCapsRegEx = /([A-Z\u00C0-\u00DC]{4,})/g;
|
|
18
|
+
var allCapsRegEx = /^[A-Z\u00C0-\u00DC]+$/;
|
|
19
|
+
function camelCase$1(str) {
|
|
20
|
+
var words = str.split(wordSeparatorsRegEx);
|
|
21
|
+
var len = words.length;
|
|
22
|
+
var mappedWords = new Array(len);
|
|
23
|
+
for (var i = 0; i < len; i++) {
|
|
24
|
+
var word = words[i];
|
|
25
|
+
if (word === "") {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
var isCamelCase = basicCamelRegEx.test(word) && !allCapsRegEx.test(word);
|
|
29
|
+
if (isCamelCase) {
|
|
30
|
+
word = word.replace(fourOrMoreConsecutiveCapsRegEx, function(match, p1, offset) {
|
|
31
|
+
return deCap(match, word.length - offset - match.length == 0);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
var firstLetter = word[0];
|
|
35
|
+
firstLetter = i > 0 ? firstLetter.toUpperCase() : firstLetter.toLowerCase();
|
|
36
|
+
mappedWords[i] = firstLetter + (!isCamelCase ? word.slice(1).toLowerCase() : word.slice(1));
|
|
37
|
+
}
|
|
38
|
+
return mappedWords.join("");
|
|
39
|
+
}
|
|
40
|
+
function deCap(match, endOfWord) {
|
|
41
|
+
var arr = match.split("");
|
|
42
|
+
var first = arr.shift().toUpperCase();
|
|
43
|
+
var last = endOfWord ? arr.pop().toLowerCase() : arr.pop();
|
|
44
|
+
return first + arr.join("").toLowerCase() + last;
|
|
45
|
+
}
|
|
46
|
+
var objectIsEmpty = isEmpty$1;
|
|
47
|
+
function isEmpty$1(obj) {
|
|
48
|
+
if (obj == null) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
if (Array.isArray(obj)) {
|
|
52
|
+
return !obj.length;
|
|
53
|
+
}
|
|
54
|
+
if (typeof obj == "string") {
|
|
55
|
+
return !obj.length;
|
|
56
|
+
}
|
|
57
|
+
var type = {}.toString.call(obj);
|
|
58
|
+
if (type == "[object Object]") {
|
|
59
|
+
return !Object.keys(obj).length && !Object.getOwnPropertySymbols(obj).length;
|
|
60
|
+
}
|
|
61
|
+
if (type == "[object Map]" || type == "[object Set]") {
|
|
62
|
+
return !obj.size;
|
|
63
|
+
}
|
|
64
|
+
return Object(obj) !== obj || !Object.keys(obj).length;
|
|
65
|
+
}
|
|
66
|
+
var objectHas = has$1;
|
|
67
|
+
function has$1(obj, propsArg) {
|
|
68
|
+
if (!obj) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
var props, prop;
|
|
72
|
+
if (Array.isArray(propsArg)) {
|
|
73
|
+
props = propsArg.slice(0);
|
|
74
|
+
}
|
|
75
|
+
if (typeof propsArg == "string") {
|
|
76
|
+
props = propsArg.split(".");
|
|
77
|
+
}
|
|
78
|
+
if (typeof propsArg == "symbol") {
|
|
79
|
+
props = [propsArg];
|
|
80
|
+
}
|
|
81
|
+
if (!Array.isArray(props)) {
|
|
82
|
+
throw new Error("props arg must be an array, a string or a symbol");
|
|
83
|
+
}
|
|
84
|
+
while (props.length) {
|
|
85
|
+
prop = props.shift();
|
|
86
|
+
if (obj == null) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
if (!Object.prototype.hasOwnProperty.call(obj, prop)) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
if (props.length === 0) {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
obj = obj[prop];
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Returns a camelCase-formatted string.
|
|
101
|
+
*
|
|
102
|
+
* @param {string} input - String to convert.
|
|
103
|
+
*
|
|
104
|
+
* @access public
|
|
105
|
+
*
|
|
106
|
+
* @return {string} *camelCase*-formatted string.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* camelCase('New super Test-title') // => 'newSuperTestTitle'
|
|
110
|
+
* camelCase(null) // => ''
|
|
111
|
+
*
|
|
112
|
+
* @preserve
|
|
113
|
+
*/
|
|
114
|
+
const camelCase = (input) => lowerFirst(stringCamelCase(input ?? ""));
|
|
115
|
+
/**
|
|
116
|
+
* Returns a PascalCase-formatted string.
|
|
117
|
+
*
|
|
118
|
+
* @param {string} input - String to convert.
|
|
119
|
+
*
|
|
120
|
+
* @access public
|
|
121
|
+
*
|
|
122
|
+
* @return {string} *PascalCase*-formatted string.
|
|
123
|
+
*
|
|
124
|
+
* Usage:
|
|
125
|
+
* ```js
|
|
126
|
+
* pascalCase('New super Test-title') // => 'NewSuperTestTitle'
|
|
127
|
+
* pascalCase(null) // => ''
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* @preserve
|
|
131
|
+
*/
|
|
132
|
+
const pascalCase = (input) => upperFirst(stringCamelCase(input ?? ""));
|
|
133
|
+
/**
|
|
134
|
+
* Returns a snake_case-formatted string.
|
|
135
|
+
*
|
|
136
|
+
* @param {string} input - String to convert.
|
|
137
|
+
*
|
|
138
|
+
* @access public
|
|
139
|
+
*
|
|
140
|
+
* @return {string} *snake_case*-formatted string.
|
|
141
|
+
*
|
|
142
|
+
* Usage:
|
|
143
|
+
* ```js
|
|
144
|
+
* snakeCase('New super Test-title') // => 'new_super_test_title'
|
|
145
|
+
* snakeCase(null) // => ''
|
|
146
|
+
* ```
|
|
147
|
+
*
|
|
148
|
+
* @preserve
|
|
149
|
+
*/
|
|
150
|
+
const snakeCase = (input) => kebabCase(input ?? "").replaceAll("-", "_");
|
|
151
|
+
const kebabCase = (input) => stringKebabCase(input ?? "");
|
|
152
|
+
/**
|
|
153
|
+
* Checks if value is an empty object or collection.
|
|
154
|
+
*
|
|
155
|
+
* @param {*} input - Value to check.
|
|
156
|
+
*
|
|
157
|
+
* @returns true if the object is empty, false otherwise.
|
|
158
|
+
*
|
|
159
|
+
* Usage:
|
|
160
|
+
* ```js
|
|
161
|
+
* isEmpty({}) // => true
|
|
162
|
+
* isEmpty([]) // => true
|
|
163
|
+
* isEmpty('') // => true
|
|
164
|
+
* isEmpty({ a: 1 }) // => false
|
|
165
|
+
* isEmpty([1, 2, 3]) // => false
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* @preserve
|
|
169
|
+
*/
|
|
170
|
+
const isEmpty = (input) => objectIsEmpty(input);
|
|
171
|
+
/**
|
|
172
|
+
* Returns the string with its first character converted to uppercase.
|
|
173
|
+
*
|
|
174
|
+
* @param {string} input - String to convert.
|
|
175
|
+
*
|
|
176
|
+
* @return {string} string with its first character converted to uppercase.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* upperFirst('new super Test-title') // => 'New super Test-title'
|
|
180
|
+
*
|
|
181
|
+
* @preserve
|
|
182
|
+
*/
|
|
183
|
+
const upperFirst = (input) => {
|
|
184
|
+
if (typeof input === "undefined") {
|
|
185
|
+
return "";
|
|
186
|
+
}
|
|
187
|
+
if (input === true) {
|
|
188
|
+
return "True";
|
|
189
|
+
} else if (input === false) {
|
|
190
|
+
return "False";
|
|
191
|
+
}
|
|
192
|
+
if (input.length < 2) {
|
|
193
|
+
return input.toUpperCase();
|
|
194
|
+
}
|
|
195
|
+
return input.charAt(0).toUpperCase() + input.slice(1);
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* Returns the string with its first character converted to lowercase.
|
|
199
|
+
*
|
|
200
|
+
* @param {string} input - String to convert.
|
|
201
|
+
*
|
|
202
|
+
* @return {string} string with its first character converted to lowercase.
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* lowerFirst('New super Test-title') // => 'new super Test-title'
|
|
206
|
+
*
|
|
207
|
+
* @preserve
|
|
208
|
+
*/
|
|
209
|
+
const lowerFirst = (input) => {
|
|
210
|
+
if (typeof input === "undefined") {
|
|
211
|
+
return "";
|
|
212
|
+
}
|
|
213
|
+
if (input === true) {
|
|
214
|
+
return "true";
|
|
215
|
+
} else if (input === false) {
|
|
216
|
+
return "false";
|
|
217
|
+
}
|
|
218
|
+
if ((input == null ? void 0 : input.length) < 2) {
|
|
219
|
+
return input.toLowerCase();
|
|
220
|
+
}
|
|
221
|
+
return input.charAt(0).toLowerCase() + input.slice(1);
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* Checks if `key` is a direct property of `object`. Key may be a path of a value separated by `.`
|
|
225
|
+
*
|
|
226
|
+
* @param {object} obj - Object to check.
|
|
227
|
+
* @param {string} key - Key to check.
|
|
228
|
+
*
|
|
229
|
+
* @return {boolean} true if key is a direct property, false otherwise.
|
|
230
|
+
*
|
|
231
|
+
* Usage:
|
|
232
|
+
* ```js
|
|
233
|
+
* has({ a: 1 }, 'a') // => true
|
|
234
|
+
* has({ a: 1 }, 'b') // => false
|
|
235
|
+
* has({ a: { b: 2 } }, 'a.b') // => true
|
|
236
|
+
* has({ a: { b: 3 } }, 'a.c') // => false
|
|
237
|
+
* ```
|
|
238
|
+
*
|
|
239
|
+
* @preserve
|
|
240
|
+
*/
|
|
241
|
+
const has = (obj, key) => objectHas(obj, key);
|
|
242
|
+
/*
|
|
243
|
+
* Checks if value is a plain object, that is, an object created by the Object constructor or one with a `[[Prototype]]` of `null`.
|
|
244
|
+
*
|
|
245
|
+
* @param {*} value - Value to check.
|
|
246
|
+
* @returns {boolean} true if value is a plain object, false otherwise.
|
|
247
|
+
*
|
|
248
|
+
* Usage:
|
|
249
|
+
* ```js
|
|
250
|
+
* isPlainObject({ a: 2 }) // => true
|
|
251
|
+
* isPlainObject('Lorem') // => false
|
|
252
|
+
* isPlainObject([]) // => false
|
|
253
|
+
* isPlainObject(new Boolean()) // => false
|
|
254
|
+
* ```
|
|
255
|
+
*
|
|
256
|
+
* @preserve
|
|
257
|
+
*/
|
|
258
|
+
const isPlainObject = (value) => {
|
|
259
|
+
if (typeof value !== "object" || value === null) {
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
if (Object.prototype.toString.call(value) !== "[object Object]") {
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
const proto = Object.getPrototypeOf(value);
|
|
266
|
+
if (proto === null) {
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
const Ctor = Object.prototype.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
|
270
|
+
return typeof Ctor === "function" && Ctor instanceof Ctor && Function.prototype.call(Ctor) === Function.prototype.call(value);
|
|
271
|
+
};
|
|
272
|
+
/**
|
|
273
|
+
* Checks if value is the language type of `Object`. (e.g. arrays, functions, objects, regexes, new Number(0), and new String(’’))
|
|
274
|
+
*
|
|
275
|
+
* @param {*} input - Value to check.
|
|
276
|
+
*
|
|
277
|
+
* @returns {boolean} true if value is an array, false otherwise.
|
|
278
|
+
*
|
|
279
|
+
* Usage:
|
|
280
|
+
* ```js
|
|
281
|
+
* isObject({}) // => true
|
|
282
|
+
* isObject([1, 2, 3]) // => true
|
|
283
|
+
* isObject(() => {}) // => true
|
|
284
|
+
* isObject(null) // => false
|
|
285
|
+
* ```
|
|
286
|
+
*
|
|
287
|
+
* @preserve
|
|
288
|
+
*/
|
|
289
|
+
const isObject = (input) => input instanceof Object;
|
|
290
|
+
/**
|
|
291
|
+
* Performs a deep comparison between two values to determine if they are equivalent.
|
|
292
|
+
*
|
|
293
|
+
* **Note**: works for simple types, arrays, and objects. Might not work for all the types the lodash version supports.
|
|
294
|
+
*
|
|
295
|
+
* @param {*} first First value to compare.
|
|
296
|
+
* @param {*} second Second value to compare.
|
|
297
|
+
*
|
|
298
|
+
* @returns true if the values are equivalent, false otherwise.
|
|
299
|
+
*
|
|
300
|
+
* Usage:
|
|
301
|
+
* ```js
|
|
302
|
+
* isEqual({ a: 1 }, { a: 1 }) // => true
|
|
303
|
+
* isEqual({ a: 1 }, { a: 2 }) // => false
|
|
304
|
+
* isEqual({ a: 1 }, 'b') // => false
|
|
305
|
+
* ```
|
|
306
|
+
*
|
|
307
|
+
* @preserve
|
|
308
|
+
*/
|
|
309
|
+
const isEqual = (first, second) => {
|
|
310
|
+
if (first === second) {
|
|
311
|
+
return true;
|
|
312
|
+
}
|
|
313
|
+
if ((first === void 0 || second === void 0 || first === null || second === null) && (first || second)) {
|
|
314
|
+
return false;
|
|
315
|
+
}
|
|
316
|
+
const firstType = first == null ? void 0 : first.constructor.name;
|
|
317
|
+
const secondType = second == null ? void 0 : second.constructor.name;
|
|
318
|
+
if (firstType !== secondType) {
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
321
|
+
if (firstType === "Array") {
|
|
322
|
+
if (first.length !== second.length) {
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
let equal = true;
|
|
326
|
+
for (let i = 0; i < first.length; i++) {
|
|
327
|
+
if (!isEqual(first[i], second[i])) {
|
|
328
|
+
equal = false;
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return equal;
|
|
333
|
+
}
|
|
334
|
+
if (firstType === "Object") {
|
|
335
|
+
let equal = true;
|
|
336
|
+
const fKeys = Object.keys(first);
|
|
337
|
+
const sKeys = Object.keys(second);
|
|
338
|
+
if (fKeys.length !== sKeys.length) {
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
for (let i = 0; i < fKeys.length; i++) {
|
|
342
|
+
if (first[fKeys[i]] && second[fKeys[i]]) {
|
|
343
|
+
if (first[fKeys[i]] === second[fKeys[i]]) {
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
if (first[fKeys[i]] && (first[fKeys[i]].constructor.name === "Array" || first[fKeys[i]].constructor.name === "Object")) {
|
|
347
|
+
equal = isEqual(first[fKeys[i]], second[fKeys[i]]);
|
|
348
|
+
if (!equal) {
|
|
349
|
+
break;
|
|
350
|
+
}
|
|
351
|
+
} else if (first[fKeys[i]] !== second[fKeys[i]]) {
|
|
352
|
+
equal = false;
|
|
353
|
+
break;
|
|
354
|
+
}
|
|
355
|
+
} else if (first[fKeys[i]] && !second[fKeys[i]] || !first[fKeys[i]] && second[fKeys[i]]) {
|
|
356
|
+
equal = false;
|
|
357
|
+
break;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return equal;
|
|
361
|
+
}
|
|
362
|
+
return first === second;
|
|
363
|
+
};
|
|
364
|
+
export {
|
|
365
|
+
camelCase,
|
|
366
|
+
has,
|
|
367
|
+
isEmpty,
|
|
368
|
+
isEqual,
|
|
369
|
+
isObject,
|
|
370
|
+
isPlainObject,
|
|
371
|
+
kebabCase,
|
|
372
|
+
lowerFirst,
|
|
373
|
+
pascalCase,
|
|
374
|
+
snakeCase,
|
|
375
|
+
upperFirst
|
|
376
|
+
};
|
package/dist/utilities/index.js
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
import { arrayMoveMultiple } from "./array-helpers.js";
|
|
2
|
-
import { camelCase, lowerFirst, upperFirst } from "./
|
|
2
|
+
import { camelCase, has, isEmpty, isEqual, isObject, isPlainObject, kebabCase, lowerFirst, pascalCase, snakeCase, upperFirst } from "./es-dash.js";
|
|
3
|
+
import { truncate, truncateMiddle, unescapeHTML } from "./text-helpers.js";
|
|
4
|
+
import { debounce, throttle } from "./debounce-throttle.js";
|
|
5
|
+
import { c } from "../lite-pbIeT7tm.js";
|
|
3
6
|
export {
|
|
4
7
|
arrayMoveMultiple,
|
|
5
8
|
camelCase,
|
|
9
|
+
c as clsx,
|
|
10
|
+
debounce,
|
|
11
|
+
has,
|
|
12
|
+
isEmpty,
|
|
13
|
+
isEqual,
|
|
14
|
+
isObject,
|
|
15
|
+
isPlainObject,
|
|
16
|
+
kebabCase,
|
|
6
17
|
lowerFirst,
|
|
18
|
+
pascalCase,
|
|
19
|
+
snakeCase,
|
|
20
|
+
throttle,
|
|
21
|
+
truncate,
|
|
22
|
+
truncateMiddle,
|
|
23
|
+
unescapeHTML,
|
|
7
24
|
upperFirst
|
|
8
25
|
};
|
|
@@ -1,105 +1,92 @@
|
|
|
1
|
-
var stringCamelCase = camelCase$1;
|
|
2
|
-
var wordSeparatorsRegEx = /[\s\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~]+/;
|
|
3
|
-
var basicCamelRegEx = /^[a-z\u00E0-\u00FCA-Z\u00C0-\u00DC][\d|a-z\u00E0-\u00FCA-Z\u00C0-\u00DC]*$/;
|
|
4
|
-
var fourOrMoreConsecutiveCapsRegEx = /([A-Z\u00C0-\u00DC]{4,})/g;
|
|
5
|
-
var allCapsRegEx = /^[A-Z\u00C0-\u00DC]+$/;
|
|
6
|
-
function camelCase$1(str) {
|
|
7
|
-
var words = str.split(wordSeparatorsRegEx);
|
|
8
|
-
var len = words.length;
|
|
9
|
-
var mappedWords = new Array(len);
|
|
10
|
-
for (var i = 0; i < len; i++) {
|
|
11
|
-
var word = words[i];
|
|
12
|
-
if (word === "") {
|
|
13
|
-
continue;
|
|
14
|
-
}
|
|
15
|
-
var isCamelCase = basicCamelRegEx.test(word) && !allCapsRegEx.test(word);
|
|
16
|
-
if (isCamelCase) {
|
|
17
|
-
word = word.replace(fourOrMoreConsecutiveCapsRegEx, function(match, p1, offset) {
|
|
18
|
-
return deCap(match, word.length - offset - match.length == 0);
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
var firstLetter = word[0];
|
|
22
|
-
firstLetter = i > 0 ? firstLetter.toUpperCase() : firstLetter.toLowerCase();
|
|
23
|
-
mappedWords[i] = firstLetter + (!isCamelCase ? word.slice(1).toLowerCase() : word.slice(1));
|
|
24
|
-
}
|
|
25
|
-
return mappedWords.join("");
|
|
26
|
-
}
|
|
27
|
-
function deCap(match, endOfWord) {
|
|
28
|
-
var arr = match.split("");
|
|
29
|
-
var first = arr.shift().toUpperCase();
|
|
30
|
-
var last = endOfWord ? arr.pop().toLowerCase() : arr.pop();
|
|
31
|
-
return first + arr.join("").toLowerCase() + last;
|
|
32
|
-
}
|
|
33
1
|
/**
|
|
34
|
-
*
|
|
2
|
+
* Slices the string in the middle and inputs the provided separator so that the string is maxLength characters long.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} input - String to slice.
|
|
5
|
+
* @param {number} maxLength - Maximum allowed string length.
|
|
6
|
+
* @param {string} [separator='...'] - Separator to insert.
|
|
7
|
+
*
|
|
8
|
+
* @access public
|
|
35
9
|
*
|
|
36
|
-
* @
|
|
10
|
+
* @returns {string|Error} Truncated string or error if separator length exceeds maxLength.
|
|
37
11
|
*
|
|
38
|
-
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* ```js
|
|
14
|
+
* truncateMiddle('https://eightshift.com/contact/', 22);
|
|
15
|
+
* ```
|
|
39
16
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
17
|
+
* Output:
|
|
18
|
+
* ```js
|
|
19
|
+
* "https://ei.../contact/"
|
|
42
20
|
*
|
|
43
21
|
* @preserve
|
|
44
22
|
*/
|
|
45
|
-
const
|
|
46
|
-
if (
|
|
47
|
-
return
|
|
23
|
+
const truncateMiddle = (input, maxLength, separator = "...") => {
|
|
24
|
+
if ((input == null ? void 0 : input.length) <= maxLength) {
|
|
25
|
+
return input;
|
|
48
26
|
}
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
} else if (input === false) {
|
|
52
|
-
return "False";
|
|
27
|
+
if (separator.length + 1 > maxLength) {
|
|
28
|
+
throw new Error("Separator length exceeds the passed maximum length, string wouldn't be visible.");
|
|
53
29
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
30
|
+
const maxStringLength = maxLength - separator.length;
|
|
31
|
+
const leftPartLength = Math.ceil(maxStringLength / 2);
|
|
32
|
+
const rightPartLength = Math.floor(maxStringLength / 2);
|
|
33
|
+
const leftPart = input.slice(0, leftPartLength).trim();
|
|
34
|
+
const rightPart = rightPartLength > 0 ? input.slice(-1 * rightPartLength).trim() : "";
|
|
35
|
+
return `${leftPart}${separator}${rightPart}`;
|
|
58
36
|
};
|
|
59
37
|
/**
|
|
60
|
-
|
|
38
|
+
* Un-escapes HTML entities.
|
|
39
|
+
*
|
|
40
|
+
* @param {string} input - Input string.
|
|
41
|
+
*
|
|
42
|
+
* @access public
|
|
43
|
+
*
|
|
44
|
+
* @returns {string} String with HTML entities unescaped.
|
|
45
|
+
*
|
|
46
|
+
* Usage:
|
|
47
|
+
* ```js
|
|
48
|
+
* unescapeHTML('Test&Up');
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* Output:
|
|
52
|
+
* ```js
|
|
53
|
+
* Test&Up
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @preserve
|
|
57
|
+
*/
|
|
58
|
+
const unescapeHTML = (input = "") => new DOMParser().parseFromString(input, "text/html").documentElement.textContent;
|
|
59
|
+
/**
|
|
60
|
+
* Limits the string to the maximum length and adds the provided separator in case the string is longer.
|
|
61
61
|
*
|
|
62
|
-
* @param {string} input
|
|
62
|
+
* @param {string} input - String to slice.
|
|
63
|
+
* @param {number} maxLength - Maximum allowed string length.
|
|
64
|
+
* @param {string} [separator='...'] - Separator to insert.
|
|
63
65
|
*
|
|
64
66
|
* @access public
|
|
65
67
|
*
|
|
66
|
-
* @
|
|
67
|
-
*
|
|
68
|
-
* @example
|
|
69
|
-
* camelCase('New super Test-title') // => 'newSuperTestTitle'
|
|
70
|
-
* camelCase(null) // => ''
|
|
68
|
+
* @returns {string|Error} Truncated string or error if separator length exceeds maxLength.
|
|
71
69
|
*
|
|
72
|
-
*
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
* Returns the string with its first character converted to lowercase.
|
|
77
|
-
*
|
|
78
|
-
* @param {string} input - String to convert.
|
|
79
|
-
*
|
|
80
|
-
* @return {string} string with its first character converted to lowercase.
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* lowerFirst('New super Test-title') // => 'new super Test-title'
|
|
70
|
+
* Usage:
|
|
71
|
+
* ```js
|
|
72
|
+
* truncate('Hello this is a string', 13); // => "Hello this..."
|
|
73
|
+
* ```
|
|
84
74
|
*
|
|
85
75
|
* @preserve
|
|
86
76
|
*/
|
|
87
|
-
const
|
|
88
|
-
if (
|
|
89
|
-
return
|
|
90
|
-
}
|
|
91
|
-
if (input === true) {
|
|
92
|
-
return "true";
|
|
93
|
-
} else if (input === false) {
|
|
94
|
-
return "false";
|
|
77
|
+
const truncate = (input, maxLength, separator = "...") => {
|
|
78
|
+
if ((input == null ? void 0 : input.length) <= maxLength) {
|
|
79
|
+
return input;
|
|
95
80
|
}
|
|
96
|
-
if (
|
|
97
|
-
|
|
81
|
+
if (separator.length + 1 > maxLength) {
|
|
82
|
+
throw new Error("Separator length exceeds the passed maximum length, string wouldn't be visible.");
|
|
98
83
|
}
|
|
99
|
-
|
|
84
|
+
const maxStringLength = maxLength - separator.length;
|
|
85
|
+
const leftPart = input.slice(0, maxStringLength).trim();
|
|
86
|
+
return `${leftPart}${separator}`;
|
|
100
87
|
};
|
|
101
88
|
export {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
89
|
+
truncate,
|
|
90
|
+
truncateMiddle,
|
|
91
|
+
unescapeHTML
|
|
105
92
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eightshift/ui-components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -19,9 +19,14 @@
|
|
|
19
19
|
"import": "./dist/index.js",
|
|
20
20
|
"require": "./dist/index.js"
|
|
21
21
|
},
|
|
22
|
+
"./icons": "./dist/icons/index.js",
|
|
23
|
+
"./utilities": "./dist/utilities/index.js",
|
|
22
24
|
"./dist/assets/style.css": "./dist/assets/style.css",
|
|
23
25
|
"./dist/assets/fonts.css": "./dist/assets/fonts.css",
|
|
24
|
-
"./dist/assets/wp.css": "./dist/assets/wp.css"
|
|
26
|
+
"./dist/assets/wp.css": "./dist/assets/wp.css",
|
|
27
|
+
"./styles": "./dist/assets/style.css",
|
|
28
|
+
"./fonts": "./dist/assets/fonts.css",
|
|
29
|
+
"./wp-overrides": "./dist/assets/wp.css"
|
|
25
30
|
},
|
|
26
31
|
"scripts": {
|
|
27
32
|
"dev": "vite",
|
|
@@ -62,7 +67,6 @@
|
|
|
62
67
|
"eslint-plugin-react-refresh": "^0.4.7",
|
|
63
68
|
"framer-motion": "^11.2.10",
|
|
64
69
|
"glob": "^10.4.1",
|
|
65
|
-
"just-camel-case": "^6.2.0",
|
|
66
70
|
"postcss": "^8.4.38",
|
|
67
71
|
"prettier": "^3.3.0",
|
|
68
72
|
"prettier-plugin-tailwindcss": "^0.6.1",
|
|
@@ -73,6 +77,12 @@
|
|
|
73
77
|
"tailwindcss-animate": "^1.0.7",
|
|
74
78
|
"tailwindcss-react-aria-components": "^1.1.3",
|
|
75
79
|
"vite": "^5.2.12",
|
|
76
|
-
"vite-plugin-lib-inject-css": "^2.1.1"
|
|
80
|
+
"vite-plugin-lib-inject-css": "^2.1.1",
|
|
81
|
+
"just-camel-case": "^6.2.0",
|
|
82
|
+
"just-debounce-it": "^3.2.0",
|
|
83
|
+
"just-has": "^2.3.0",
|
|
84
|
+
"just-is-empty": "^3.4.1",
|
|
85
|
+
"just-kebab-case": "^4.2.0",
|
|
86
|
+
"just-throttle": "^4.2.0"
|
|
77
87
|
}
|
|
78
88
|
}
|