@operato/utils 7.1.1 → 7.1.32
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 +10 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/.editorconfig +0 -29
- package/.storybook/main.js +0 -3
- package/.storybook/preview.js +0 -52
- package/.storybook/server.mjs +0 -8
- package/demo/index.html +0 -43
- package/src/adjust-list-param.ts +0 -79
- package/src/async-lock.ts +0 -27
- package/src/clipboard.ts +0 -41
- package/src/closest-element.ts +0 -24
- package/src/context-path.ts +0 -42
- package/src/cookie.ts +0 -44
- package/src/decode-html.ts +0 -5
- package/src/detect-overflow.ts +0 -18
- package/src/encode-form-params.ts +0 -24
- package/src/file-drop-helper.ts +0 -62
- package/src/format.ts +0 -123
- package/src/fullscreen.ts +0 -82
- package/src/has-overflow.ts +0 -22
- package/src/index.ts +0 -25
- package/src/is-unvalued.ts +0 -10
- package/src/logger.ts +0 -32
- package/src/longpressable.ts +0 -101
- package/src/mixins/index.ts +0 -1
- package/src/mixins/infinite-scrollable.ts +0 -67
- package/src/number-parser.ts +0 -24
- package/src/os.ts +0 -48
- package/src/parse-jwt.ts +0 -21
- package/src/password-pattern.ts +0 -63
- package/src/reactive-controllers/index.ts +0 -1
- package/src/reactive-controllers/tooltip-reactive-controller.ts +0 -88
- package/src/sleep.ts +0 -10
- package/src/stringify-bignum.ts +0 -35
- package/src/swipe-listener.ts +0 -290
- package/src/timecapsule/index.ts +0 -2
- package/src/timecapsule/snapshot-taker.ts +0 -105
- package/src/timecapsule/timecapsule.ts +0 -139
- package/tsconfig.json +0 -24
- package/web-dev-server.config.mjs +0 -27
- package/web-test-runner.config.mjs +0 -41
package/src/cookie.ts
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Sets a cookie with the given name, value, and expiration days.
|
3
|
-
*
|
4
|
-
* @param {string} cname - The name of the cookie.
|
5
|
-
* @param {string} cvalue - The value to be stored in the cookie.
|
6
|
-
* @param {number} exdays - The number of days until the cookie expires.
|
7
|
-
*/
|
8
|
-
export function setCookie(cname: string, cvalue: string, exdays: number) {
|
9
|
-
var d = new Date()
|
10
|
-
d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000)
|
11
|
-
var expires = 'expires=' + d.toUTCString()
|
12
|
-
document.cookie = cname + '=' + cvalue + ';' + expires + ';path=/'
|
13
|
-
}
|
14
|
-
|
15
|
-
/**
|
16
|
-
* Retrieves the value of a cookie with the given name.
|
17
|
-
*
|
18
|
-
* @param {string} cname - The name of the cookie to retrieve.
|
19
|
-
* @returns {string} - The value of the cookie, or an empty string if the cookie is not found.
|
20
|
-
*/
|
21
|
-
export function getCookie(cname: string) {
|
22
|
-
var name = cname + '='
|
23
|
-
var decodedCookie = decodeURIComponent(document.cookie)
|
24
|
-
var ca = decodedCookie.split(';')
|
25
|
-
for (var i = 0; i < ca.length; i++) {
|
26
|
-
var c = ca[i]
|
27
|
-
while (c.charAt(0) == ' ') {
|
28
|
-
c = c.substring(1)
|
29
|
-
}
|
30
|
-
if (c.indexOf(name) == 0) {
|
31
|
-
return c.substring(name.length, c.length)
|
32
|
-
}
|
33
|
-
}
|
34
|
-
return ''
|
35
|
-
}
|
36
|
-
|
37
|
-
/**
|
38
|
-
* Deletes a cookie with the given name.
|
39
|
-
*
|
40
|
-
* @param {string} name - The name of the cookie to delete.
|
41
|
-
*/
|
42
|
-
export function deleteCookie(name: string) {
|
43
|
-
document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;'
|
44
|
-
}
|
package/src/decode-html.ts
DELETED
package/src/detect-overflow.ts
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Detects if the content of an HTMLElement overflows its boundaries.
|
3
|
-
*
|
4
|
-
* @param {HTMLElement} el - The HTMLElement to check for overflow.
|
5
|
-
* @returns {boolean} - `true` if overflow is detected, `false` otherwise.
|
6
|
-
* @deprecated This function is no longer recommended for use and has been replaced by 'hasOverflow'.
|
7
|
-
*/
|
8
|
-
export function detectOverflow(el: HTMLElement) {
|
9
|
-
var styleOverflow = el.style.overflow
|
10
|
-
|
11
|
-
if (!styleOverflow || styleOverflow === 'visible') el.style.overflow = 'hidden'
|
12
|
-
|
13
|
-
var overflowed = el.clientWidth < el.scrollWidth || el.clientHeight < el.scrollHeight
|
14
|
-
|
15
|
-
el.style.overflow = styleOverflow
|
16
|
-
|
17
|
-
return overflowed
|
18
|
-
}
|
@@ -1,24 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* encode form parameter string from object
|
3
|
-
* @param {Object} obj target object
|
4
|
-
*/
|
5
|
-
export function encodeFormParams(obj: { [key: string]: any }) {
|
6
|
-
return Object.keys(obj)
|
7
|
-
.map(k => `${encodeURIComponent(k)}=${encodeURIComponent(obj[k])}`)
|
8
|
-
.join('&')
|
9
|
-
}
|
10
|
-
|
11
|
-
/**
|
12
|
-
* encode url parameter string from object
|
13
|
-
* replace null value to ''
|
14
|
-
* @param {Object} obj target object
|
15
|
-
*/
|
16
|
-
export function encodeUrlParams(urlParams: { [key: string]: any }) {
|
17
|
-
return Object.keys(urlParams)
|
18
|
-
.filter((key: string) => {
|
19
|
-
// ignore empty
|
20
|
-
return !!urlParams[key]
|
21
|
-
})
|
22
|
-
.map(key => `${key}=${encodeURIComponent(urlParams[key] || '')}`)
|
23
|
-
.join('&')
|
24
|
-
}
|
package/src/file-drop-helper.ts
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* judge callback function for FileDropHelper.set
|
3
|
-
*/
|
4
|
-
type JudgeCallback = () => boolean
|
5
|
-
|
6
|
-
/**
|
7
|
-
* file drop assist class
|
8
|
-
*/
|
9
|
-
export class FileDropHelper {
|
10
|
-
/**
|
11
|
-
* 파일 드롭 영역에서의 file drag&drop과 관련된 이벤트에 대한 처리를 설정한다.
|
12
|
-
* @param dropArea file drag&drop target area
|
13
|
-
* @param [judge] file drag&drop과 관련된 이벤트에 대한 judge callback function
|
14
|
-
*/
|
15
|
-
static set(dropArea: HTMLElement, judge?: JudgeCallback) {
|
16
|
-
var preventDefaults = (e: Event) => {
|
17
|
-
if (!judge || judge()) {
|
18
|
-
e.preventDefault()
|
19
|
-
e.stopPropagation()
|
20
|
-
}
|
21
|
-
}
|
22
|
-
|
23
|
-
var highlight = (e: Event) => {
|
24
|
-
if (!judge || judge()) {
|
25
|
-
dropArea.classList.add('candrop')
|
26
|
-
}
|
27
|
-
}
|
28
|
-
|
29
|
-
var unhighlight = (e: Event) => {
|
30
|
-
if (!judge || judge()) {
|
31
|
-
dropArea.classList.remove('candrop')
|
32
|
-
}
|
33
|
-
}
|
34
|
-
|
35
|
-
;['dragenter', 'dragover', 'dragleave', 'drop'].forEach(event => {
|
36
|
-
dropArea.addEventListener(event, preventDefaults, false)
|
37
|
-
})
|
38
|
-
;['dragenter', 'dragover'].forEach(event => {
|
39
|
-
dropArea.addEventListener(event, highlight, false)
|
40
|
-
})
|
41
|
-
;['dragleave', 'drop'].forEach(event => {
|
42
|
-
dropArea.addEventListener(event, unhighlight, false)
|
43
|
-
})
|
44
|
-
|
45
|
-
dropArea.addEventListener(
|
46
|
-
'drop',
|
47
|
-
e => {
|
48
|
-
if (!judge || judge()) {
|
49
|
-
let dt = e.dataTransfer!
|
50
|
-
let files = dt.files
|
51
|
-
|
52
|
-
dropArea.dispatchEvent(
|
53
|
-
new CustomEvent('file-drop', {
|
54
|
-
detail: [...Array.from(files)]
|
55
|
-
})
|
56
|
-
)
|
57
|
-
}
|
58
|
-
},
|
59
|
-
false
|
60
|
-
)
|
61
|
-
}
|
62
|
-
}
|
package/src/format.ts
DELETED
@@ -1,123 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Source Code from https://github.com/Mottie/javascript-number-formatter
|
3
|
-
* 소스코드 출처 : https://github.com/Mottie/javascript-number-formatter
|
4
|
-
*/
|
5
|
-
|
6
|
-
/**
|
7
|
-
* Formats a number according to the given mask.
|
8
|
-
*
|
9
|
-
* ```example
|
10
|
-
* var formattedValue = format('+$#,##0.00', 12345.67);
|
11
|
-
* console.log(formattedValue); // Output: +$12,345.67
|
12
|
-
* ```
|
13
|
-
*
|
14
|
-
* @param {any} mask - The formatting mask to apply.
|
15
|
-
* @param {any} value - The value to format.
|
16
|
-
* @returns {string} - The formatted string.
|
17
|
-
*/
|
18
|
-
export function format(mask: string, value: number): string {
|
19
|
-
if (!mask || isNaN(+value)) {
|
20
|
-
return value.toString() // return as it is.
|
21
|
-
}
|
22
|
-
|
23
|
-
let isNegative: boolean,
|
24
|
-
result: string | RegExpMatchArray | null,
|
25
|
-
decimal: string,
|
26
|
-
group: string,
|
27
|
-
posLeadZero: number,
|
28
|
-
posTrailZero: number,
|
29
|
-
posSeparator: number,
|
30
|
-
part: string[],
|
31
|
-
szSep: string[],
|
32
|
-
integer: string,
|
33
|
-
// find prefix/suffix
|
34
|
-
len = mask.length,
|
35
|
-
start = mask.search(/[0-9\-\+#]/),
|
36
|
-
prefix = start > 0 ? mask.substring(0, start) : '',
|
37
|
-
// reverse string: not an ideal method if there are surrogate pairs
|
38
|
-
str = mask.split('').reverse().join(''),
|
39
|
-
end = str.search(/[0-9\-\+#]/),
|
40
|
-
offset = len - end,
|
41
|
-
substr = mask.substring(offset, offset + 1),
|
42
|
-
indx = offset + (substr === '.' || substr === ',' ? 1 : 0),
|
43
|
-
suffix = end > 0 ? mask.substring(indx, len) : '',
|
44
|
-
splittedMask: string[],
|
45
|
-
splittedValue: string[],
|
46
|
-
stringValue: string
|
47
|
-
|
48
|
-
// mask with prefix & suffix removed
|
49
|
-
mask = mask.substring(start, indx)
|
50
|
-
|
51
|
-
// convert any string to number according to formation sign.
|
52
|
-
value = mask.charAt(0) === '-' ? -value : +value
|
53
|
-
isNegative = value < 0 ? ((value = -value), true) : false // process only abs(), and turn on flag.
|
54
|
-
|
55
|
-
// search for separator for grp & decimal, anything not digit, not +/- sign, not #.
|
56
|
-
result = mask.match(/[^\d\-\+#]/g)
|
57
|
-
decimal = '.' // ( result && result[ result.length - 1 ] ) || '.'; // ','는 소수점이 되지 않게 함
|
58
|
-
group = (result && result[1] && result[0]) || ',' // treat the left most symbol as group separator
|
59
|
-
|
60
|
-
// split the decimal for the format string if any.
|
61
|
-
splittedMask = mask.split(decimal)
|
62
|
-
// Fix the decimal first, toFixed will auto fill trailing zero.
|
63
|
-
value = parseFloat(value.toFixed((splittedMask[1] && splittedMask[1].length) || 0))
|
64
|
-
stringValue = +value + '' // convert number to string to trim off *all* trailing decimal zero(es)
|
65
|
-
|
66
|
-
// fill back any trailing zero according to format
|
67
|
-
posTrailZero = (splittedMask[1] && splittedMask[1].lastIndexOf('0')) || 0 // look for last zero in format
|
68
|
-
part = stringValue.split('.')
|
69
|
-
// integer will get !part[1]
|
70
|
-
if (!part[1] || (part[1] && part[1].length <= posTrailZero)) {
|
71
|
-
stringValue = (+value).toFixed(posTrailZero + 1)
|
72
|
-
}
|
73
|
-
szSep = splittedMask[0].split(group) // look for separator
|
74
|
-
splittedMask[0] = szSep.join('') // join back without separator for counting the pos of any leading 0.
|
75
|
-
|
76
|
-
posLeadZero = (splittedMask[0] && splittedMask[0].indexOf('0')) || 0
|
77
|
-
if (posLeadZero > -1) {
|
78
|
-
while (part[0].length < splittedMask[0].length - posLeadZero) {
|
79
|
-
part[0] = '0' + part[0]
|
80
|
-
}
|
81
|
-
} else if (+part[0] === 0) {
|
82
|
-
part[0] = ''
|
83
|
-
}
|
84
|
-
|
85
|
-
splittedValue = stringValue.split('.')
|
86
|
-
splittedValue[0] = part[0]
|
87
|
-
|
88
|
-
// process the first group separator from decimal (.) only, the rest ignore.
|
89
|
-
// get the length of the last slice of split result.
|
90
|
-
posSeparator = (szSep[1] && szSep[szSep.length - 1].length) || 0
|
91
|
-
if (posSeparator) {
|
92
|
-
integer = splittedValue[0]
|
93
|
-
str = ''
|
94
|
-
offset = integer.length % posSeparator
|
95
|
-
len = integer.length
|
96
|
-
for (indx = 0; indx < len; indx++) {
|
97
|
-
str += integer.charAt(indx) // ie6 only support charAt for sz.
|
98
|
-
// -posSeparator so that won't trail separator on full length
|
99
|
-
/* jshint -W018 */
|
100
|
-
if (!((indx - offset + 1) % posSeparator) && indx < len - posSeparator) {
|
101
|
-
str += group
|
102
|
-
}
|
103
|
-
}
|
104
|
-
splittedValue[0] = str
|
105
|
-
}
|
106
|
-
splittedValue[1] = splittedMask[1] && splittedValue[1] ? decimal + splittedValue[1] : ''
|
107
|
-
|
108
|
-
// remove negative sign if result is zero
|
109
|
-
result = splittedValue.join('')
|
110
|
-
if (result === '0' || result === '') {
|
111
|
-
// remove negative sign if result is zero
|
112
|
-
isNegative = false
|
113
|
-
}
|
114
|
-
|
115
|
-
// 앞에 +가 붙는다면 양수일 경우에도 +를 표기해줌
|
116
|
-
let fixedPlusSign: string
|
117
|
-
|
118
|
-
if (splittedMask[0].substring(0, 1) === '+') fixedPlusSign = isNegative ? '-' : '+'
|
119
|
-
else fixedPlusSign = isNegative ? '-' : ''
|
120
|
-
|
121
|
-
// put back any negation, combine integer and fraction, and add back prefix & suffix
|
122
|
-
return prefix + (fixedPlusSign + result) + suffix
|
123
|
-
}
|
package/src/fullscreen.ts
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* 풀스크린 전환 이후와 풀스크린 해제 이후에 호출되는 콜백함수
|
3
|
-
* @callback FullscreenCallback
|
4
|
-
*/
|
5
|
-
export type FullscreenCallback = () => void
|
6
|
-
|
7
|
-
/**
|
8
|
-
* 엘리먼트를 풀스크린으로 표시되도록 한다.
|
9
|
-
* @param {HTMLElement} element 대상 엘리먼트
|
10
|
-
* @param {FullscreenCallback} afterfull 풀스크린이 된 이후에 호출되는 콜백함수
|
11
|
-
* @param {FullscreenCallback} afterfinish 풀스크린이 해제된 이후에 호출되는 콜백함수
|
12
|
-
*/
|
13
|
-
export function fullscreen(element: HTMLElement, afterfull?: FullscreenCallback, afterfinish?: FullscreenCallback) {
|
14
|
-
var org_width = element.style.width
|
15
|
-
var org_height = element.style.height
|
16
|
-
|
17
|
-
function _fullscreen_callback(e: Event) {
|
18
|
-
if (
|
19
|
-
!document.fullscreenElement &&
|
20
|
-
//@ts-ignore
|
21
|
-
!document.mozFullScreen &&
|
22
|
-
//@ts-ignore
|
23
|
-
!document.webkitIsFullScreen &&
|
24
|
-
//@ts-ignore
|
25
|
-
!document.msFullscreenElement
|
26
|
-
) {
|
27
|
-
;['fullscreenchange', 'webkitfullscreenchange', 'MSFullscreenChange'].forEach(event =>
|
28
|
-
document.removeEventListener(event, _fullscreen_callback)
|
29
|
-
)
|
30
|
-
|
31
|
-
element.style.width = org_width
|
32
|
-
element.style.height = org_height
|
33
|
-
|
34
|
-
afterfinish && afterfinish()
|
35
|
-
} else {
|
36
|
-
element.style.width = '100%'
|
37
|
-
element.style.height = '100%'
|
38
|
-
|
39
|
-
afterfull && afterfull()
|
40
|
-
}
|
41
|
-
}
|
42
|
-
|
43
|
-
;['fullscreenchange', 'webkitfullscreenchange', 'MSFullscreenChange'].forEach(event =>
|
44
|
-
document.addEventListener(event, _fullscreen_callback)
|
45
|
-
)
|
46
|
-
|
47
|
-
if (element.requestFullscreen) element.requestFullscreen()
|
48
|
-
//@ts-ignore
|
49
|
-
else if (element.webkitRequestFullScreen) element.webkitRequestFullScreen()
|
50
|
-
//@ts-ignore
|
51
|
-
else if (element.mozRequestFullScreen) element.mozRequestFullScreen()
|
52
|
-
//@ts-ignore
|
53
|
-
else if (element.msRequestFullscreen) element.msRequestFullscreen()
|
54
|
-
}
|
55
|
-
|
56
|
-
export function exitfullscreen() {
|
57
|
-
if (document.exitFullscreen) document.exitFullscreen()
|
58
|
-
//@ts-ignore
|
59
|
-
else if (document.mozCancelFullScreen) document.mozCancelFullScreen()
|
60
|
-
//@ts-ignore
|
61
|
-
else if (document.webkitCancelFullScreen) document.webkitCancelFullScreen()
|
62
|
-
//@ts-ignore
|
63
|
-
else if (document.msExitFullscreen) document.msExitFullscreen()
|
64
|
-
}
|
65
|
-
|
66
|
-
export function togglefullscreen(
|
67
|
-
element: HTMLElement,
|
68
|
-
afterfull?: FullscreenCallback,
|
69
|
-
afterfinish?: FullscreenCallback
|
70
|
-
) {
|
71
|
-
if (
|
72
|
-
!document.fullscreenElement &&
|
73
|
-
//@ts-ignore
|
74
|
-
!document.mozFullScreen &&
|
75
|
-
//@ts-ignore
|
76
|
-
!document.webkitIsFullScreen &&
|
77
|
-
//@ts-ignore
|
78
|
-
!document.msFullscreenElement
|
79
|
-
)
|
80
|
-
fullscreen(element, afterfull, afterfinish)
|
81
|
-
else exitfullscreen()
|
82
|
-
}
|
package/src/has-overflow.ts
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Detects if the content of an HTMLElement overflows its boundaries.
|
3
|
-
*
|
4
|
-
* @param {HTMLElement} el - The HTMLElement to check for overflow.
|
5
|
-
* @returns {boolean} - `true` if overflow is detected, `false` otherwise.
|
6
|
-
*/
|
7
|
-
export function hasOverflow(el: HTMLElement): boolean {
|
8
|
-
const computedStyle = getComputedStyle(el)
|
9
|
-
const originalOverflow = computedStyle.overflow
|
10
|
-
|
11
|
-
if (originalOverflow === 'visible') {
|
12
|
-
el.style.overflow = 'hidden'
|
13
|
-
}
|
14
|
-
|
15
|
-
const isOverflowing = el.clientWidth < el.scrollWidth || el.clientHeight < el.scrollHeight
|
16
|
-
|
17
|
-
if (originalOverflow === 'visible') {
|
18
|
-
el.style.overflow = ''
|
19
|
-
}
|
20
|
-
|
21
|
-
return isOverflowing
|
22
|
-
}
|
package/src/index.ts
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
export * from './sleep.js'
|
2
|
-
export * from './async-lock.js'
|
3
|
-
export * from './file-drop-helper.js'
|
4
|
-
export * from './context-path.js'
|
5
|
-
export * from './os.js'
|
6
|
-
export * from './swipe-listener.js'
|
7
|
-
export * from './fullscreen.js'
|
8
|
-
export * from './parse-jwt.js'
|
9
|
-
export * from './password-pattern.js'
|
10
|
-
export * from './closest-element.js'
|
11
|
-
export * from './detect-overflow.js' /* deprecated by 'has-overflow' */
|
12
|
-
export * from './has-overflow.js'
|
13
|
-
export * from './timecapsule/index.js'
|
14
|
-
export * from './clipboard.js'
|
15
|
-
export * from './format.js'
|
16
|
-
export * from './adjust-list-param.js'
|
17
|
-
export * from './is-unvalued.js'
|
18
|
-
export * from './stringify-bignum.js'
|
19
|
-
export * from './encode-form-params.js'
|
20
|
-
export * from './cookie.js'
|
21
|
-
export * from './number-parser.js'
|
22
|
-
export * from './longpressable.js'
|
23
|
-
export * from './decode-html.js'
|
24
|
-
|
25
|
-
export * from './reactive-controllers'
|
package/src/is-unvalued.ts
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* It judges whether it is false except 0, false. Returns true in case of undefined, null, NaN, '', {}, [].
|
3
|
-
*
|
4
|
-
* @param value
|
5
|
-
* @returns boolean
|
6
|
-
*/
|
7
|
-
export function isUnvalued(value: any) {
|
8
|
-
/* value == null same as (value === undefined || value === null) */
|
9
|
-
return value == null || value !== 0 || value !== false || value.length === 0 || Object.keys(value).length === 0
|
10
|
-
}
|
package/src/logger.ts
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
const ERROR = '[ERROR]'
|
2
|
-
const WARN = '[WARN]'
|
3
|
-
const DEBUG = '[DEBUG]'
|
4
|
-
|
5
|
-
/**
|
6
|
-
* Logs an error message with optional stack trace.
|
7
|
-
*
|
8
|
-
* @param {...any} args - The error message and optional additional data.
|
9
|
-
*/
|
10
|
-
export var error = (...args: any[]) => {
|
11
|
-
var trace = [] as string[]
|
12
|
-
args.forEach(arg => arg && arg.stack && trace.push(arg.stack))
|
13
|
-
console.error(ERROR, ...args, trace.join(' '))
|
14
|
-
}
|
15
|
-
|
16
|
-
/**
|
17
|
-
* Logs a warning message with optional stack trace.
|
18
|
-
*
|
19
|
-
* @param {...any} args - The warning message and optional additional data.
|
20
|
-
*/
|
21
|
-
export var warn = (...args: any[]) => {
|
22
|
-
var trace = [] as string[]
|
23
|
-
args.forEach(arg => arg && arg.stack && trace.push(arg.stack))
|
24
|
-
console.warn(WARN, ...args, trace.join(' '))
|
25
|
-
}
|
26
|
-
|
27
|
-
/**
|
28
|
-
* Logs a debug message.
|
29
|
-
*
|
30
|
-
* @param {...any} args - The debug message and optional additional data.
|
31
|
-
*/
|
32
|
-
export var debug = (...args: any[]) => console.log(DEBUG, ...args)
|
package/src/longpressable.ts
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @license Copyright © HatioLab Inc. All rights reserved.
|
3
|
-
*/
|
4
|
-
|
5
|
-
/* Inspired by https://github.com/john-doherty/long-press-event */
|
6
|
-
|
7
|
-
var timer = null as any
|
8
|
-
|
9
|
-
// check if we're using a touch screen
|
10
|
-
//@ts-ignore
|
11
|
-
const isTouch = 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0
|
12
|
-
|
13
|
-
// switch to touch events if using a touch screen
|
14
|
-
const mouseDown = isTouch ? 'touchstart' : 'mousedown'
|
15
|
-
const mouseOut = isTouch ? 'touchcancel' : 'mouseout'
|
16
|
-
const mouseUp = isTouch ? 'touchend' : 'mouseup'
|
17
|
-
const mouseMove = isTouch ? 'touchmove' : 'mousemove'
|
18
|
-
|
19
|
-
/*
|
20
|
-
* Fires the 'long-press' event on element
|
21
|
-
* @returns {void}
|
22
|
-
*/
|
23
|
-
function fireLongPressEvent(this: HTMLElement) {
|
24
|
-
clearLongPressTimer()
|
25
|
-
|
26
|
-
// fire the long-press event
|
27
|
-
var suppressClickEvent = this.dispatchEvent(new CustomEvent('long-press', { bubbles: true, cancelable: true }))
|
28
|
-
|
29
|
-
if (suppressClickEvent) {
|
30
|
-
// temporarily intercept and clear the next click
|
31
|
-
this.addEventListener(
|
32
|
-
mouseUp,
|
33
|
-
function clearMouseUp(e) {
|
34
|
-
this.removeEventListener(mouseUp, clearMouseUp, true)
|
35
|
-
cancelEvent(e)
|
36
|
-
},
|
37
|
-
true
|
38
|
-
)
|
39
|
-
}
|
40
|
-
}
|
41
|
-
|
42
|
-
/*
|
43
|
-
* method responsible for starting the long press timer
|
44
|
-
* @param {event} e - event object
|
45
|
-
* @returns {void}
|
46
|
-
*/
|
47
|
-
function startLongPressTimer(e: Event) {
|
48
|
-
clearLongPressTimer(e)
|
49
|
-
|
50
|
-
var el = e.target as HTMLElement
|
51
|
-
|
52
|
-
// get delay from html attribute if it exists, otherwise default to 1500
|
53
|
-
var longPressDelayInMs = parseInt(el.getAttribute('data-long-press-delay') || '600', 10)
|
54
|
-
|
55
|
-
// start the timer
|
56
|
-
timer = setTimeout(fireLongPressEvent.bind(el), longPressDelayInMs)
|
57
|
-
}
|
58
|
-
|
59
|
-
/*
|
60
|
-
* method responsible for clearing a pending long press timer
|
61
|
-
* @param {event} e - event object
|
62
|
-
* @returns {void}
|
63
|
-
*/
|
64
|
-
function clearLongPressTimer(e?: Event) {
|
65
|
-
clearTimeout(timer)
|
66
|
-
timer = null
|
67
|
-
}
|
68
|
-
|
69
|
-
/*
|
70
|
-
* Cancels the current event
|
71
|
-
* @param {object} e - browser event object
|
72
|
-
* @returns {void}
|
73
|
-
*/
|
74
|
-
function cancelEvent(e: Event) {
|
75
|
-
e.stopImmediatePropagation()
|
76
|
-
e.preventDefault()
|
77
|
-
e.stopPropagation()
|
78
|
-
}
|
79
|
-
|
80
|
-
/**
|
81
|
-
* method set target element to be able to respond longpress event
|
82
|
-
* @param {HTMLElement} element target element
|
83
|
-
*/
|
84
|
-
export const longpressable = (element: HTMLElement) => {
|
85
|
-
// hook events that clear a pending long press event
|
86
|
-
element.addEventListener(mouseOut, clearLongPressTimer, true)
|
87
|
-
element.addEventListener(mouseUp, clearLongPressTimer, true)
|
88
|
-
element.addEventListener(mouseMove, clearLongPressTimer, true)
|
89
|
-
element.addEventListener('wheel', clearLongPressTimer, true)
|
90
|
-
element.addEventListener('scroll', clearLongPressTimer, true)
|
91
|
-
|
92
|
-
// hook events that can trigger a long press event
|
93
|
-
element.addEventListener(mouseDown, startLongPressTimer, true) // <- start
|
94
|
-
|
95
|
-
// cancel context for touch display
|
96
|
-
if (mouseDown.indexOf('touch') === 0) {
|
97
|
-
element.addEventListener('contextmenu', cancelEvent, true)
|
98
|
-
} else {
|
99
|
-
element.addEventListener('contextmenu', clearLongPressTimer, true)
|
100
|
-
}
|
101
|
-
}
|
package/src/mixins/index.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export { default as InfiniteScrollable } from './infinite-scrollable.js'
|
@@ -1,67 +0,0 @@
|
|
1
|
-
import debounce from 'lodash-es/debounce'
|
2
|
-
|
3
|
-
type Constructor = new (...args: any[]) => {}
|
4
|
-
|
5
|
-
/**
|
6
|
-
* A higher-order function that enhances a base class with infinite scrolling functionality.
|
7
|
-
*
|
8
|
-
* @template TBase - The base class constructor type.
|
9
|
-
* @param {TBase} Base - The base class to enhance with infinite scrolling.
|
10
|
-
* @returns {TBase & InfiniteScrollable} - The extended class with infinite scrolling capabilities.
|
11
|
-
*/
|
12
|
-
export default function InfiniteScrollable<TBase extends Constructor>(Base: TBase) {
|
13
|
-
return class Scrolling extends Base {
|
14
|
-
/**
|
15
|
-
* Default options for infinite scrolling.
|
16
|
-
*
|
17
|
-
* @type {object}
|
18
|
-
* @property {number} threshold - The threshold value to trigger loading more items.
|
19
|
-
* @property {number} limit - The limit of items to load per page.
|
20
|
-
* @property {string} totalProp - The property name for the total number of items.
|
21
|
-
* @property {string} pageProp - The property name for the current page number.
|
22
|
-
*/
|
23
|
-
_infiniteScrollOptions = {
|
24
|
-
threshold: 20,
|
25
|
-
limit: 30,
|
26
|
-
totalProp: '_total',
|
27
|
-
pageProp: '_page'
|
28
|
-
}
|
29
|
-
|
30
|
-
/**
|
31
|
-
* Event handler for the scroll event with debouncing.
|
32
|
-
*
|
33
|
-
* @param {Event} e - The scroll event object.
|
34
|
-
*/
|
35
|
-
onScroll = debounce(e => {
|
36
|
-
//@ts-ignore inheritted class should have scrollTargetEl property
|
37
|
-
var el = this.scrollTargetEl
|
38
|
-
if (!el) {
|
39
|
-
console.warn('scroll target element is not defined.')
|
40
|
-
return
|
41
|
-
}
|
42
|
-
|
43
|
-
var { threshold = 0, limit, totalProp, pageProp } = this._infiniteScrollOptions
|
44
|
-
|
45
|
-
if (
|
46
|
-
(this as any)[pageProp] < (this as any)[totalProp] / limit &&
|
47
|
-
el.scrollHeight - el.clientHeight <= el.scrollTop + threshold
|
48
|
-
) {
|
49
|
-
this.scrollAction()
|
50
|
-
}
|
51
|
-
}, 300)
|
52
|
-
|
53
|
-
// commented due to TS2611 error
|
54
|
-
// get scrollTargetEl(): HTMLElement | null {
|
55
|
-
// console.warn('scroll target element is not defined.')
|
56
|
-
|
57
|
-
// return null
|
58
|
-
// }
|
59
|
-
|
60
|
-
/**
|
61
|
-
* An async function to handle scroll action when the threshold is reached.
|
62
|
-
*/
|
63
|
-
async scrollAction() {
|
64
|
-
console.warn('scroll action not implemented.')
|
65
|
-
}
|
66
|
-
}
|
67
|
-
}
|
package/src/number-parser.ts
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
// 숫자라면 숫자값을, 아니면 null을 반환
|
2
|
-
// 0 = true
|
3
|
-
// '0' = true
|
4
|
-
// 123 = true
|
5
|
-
// "123" = true
|
6
|
-
// -123 = true
|
7
|
-
// "-123" = true
|
8
|
-
// true = false
|
9
|
-
// false = false
|
10
|
-
// "" = false
|
11
|
-
// null = false
|
12
|
-
// undefined = false
|
13
|
-
// {} = false
|
14
|
-
// [] = false
|
15
|
-
export function parseToNumberOrNull(value: any): number | null {
|
16
|
-
let result: number | null = null
|
17
|
-
|
18
|
-
// 숫자나 스트링이면서 NaN이 아니면 숫자로 변환
|
19
|
-
if ((typeof value === 'string' || typeof value === 'number') && value !== '' && !isNaN(value as number)) {
|
20
|
-
result = Number(value)
|
21
|
-
}
|
22
|
-
|
23
|
-
return result
|
24
|
-
}
|