@operato/utils 8.0.0-beta.0 → 8.0.0-beta.2

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/package.json +2 -2
  3. package/.editorconfig +0 -29
  4. package/.storybook/main.js +0 -3
  5. package/.storybook/preview.js +0 -52
  6. package/.storybook/server.mjs +0 -8
  7. package/demo/index.html +0 -43
  8. package/src/adjust-list-param.ts +0 -79
  9. package/src/async-lock.ts +0 -27
  10. package/src/clipboard.ts +0 -41
  11. package/src/closest-element.ts +0 -24
  12. package/src/context-path.ts +0 -42
  13. package/src/cookie.ts +0 -44
  14. package/src/decode-html.ts +0 -5
  15. package/src/detect-overflow.ts +0 -18
  16. package/src/encode-form-params.ts +0 -24
  17. package/src/file-drop-helper.ts +0 -62
  18. package/src/format.ts +0 -123
  19. package/src/fullscreen.ts +0 -82
  20. package/src/gesture-helper.ts +0 -147
  21. package/src/has-overflow.ts +0 -22
  22. package/src/index.ts +0 -25
  23. package/src/is-unvalued.ts +0 -10
  24. package/src/logger.ts +0 -32
  25. package/src/longpressable.ts +0 -101
  26. package/src/mixins/gesture-mixin.ts +0 -157
  27. package/src/mixins/index.ts +0 -2
  28. package/src/mixins/infinite-scrollable.ts +0 -67
  29. package/src/number-parser.ts +0 -24
  30. package/src/os.ts +0 -48
  31. package/src/parse-jwt.ts +0 -21
  32. package/src/password-pattern.ts +0 -63
  33. package/src/reactive-controllers/index.ts +0 -1
  34. package/src/reactive-controllers/tooltip-reactive-controller.ts +0 -88
  35. package/src/sleep.ts +0 -10
  36. package/src/stringify-bignum.ts +0 -35
  37. package/src/swipe-listener.ts +0 -290
  38. package/src/timecapsule/index.ts +0 -2
  39. package/src/timecapsule/snapshot-taker.ts +0 -105
  40. package/src/timecapsule/timecapsule.ts +0 -139
  41. package/tsconfig.json +0 -24
  42. package/web-dev-server.config.mjs +0 -27
  43. package/web-test-runner.config.mjs +0 -41
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
- }
@@ -1,147 +0,0 @@
1
- export type GestureEventPinch = CustomEvent<{ scale: number; centerX: number; centerY: number }>
2
- export type GestureEventDrag = CustomEvent<{
3
- deltaX: number
4
- deltaY: number
5
- clientX: number
6
- clientY: number
7
- end: boolean
8
- }>
9
- export type GestureEventDoubleTap = CustomEvent<{ x: number; y: number }>
10
-
11
- export class GestureHelper {
12
- private __pointers = new Map<number, { x: number; y: number }>()
13
- private __lastTapTime = 0
14
- private __lastPinchDistance = 0
15
- private __dragStart: { x: number; y: number } | null = null
16
- private element: Element
17
-
18
- constructor(element: Element) {
19
- this.element = element
20
- this.init()
21
- }
22
-
23
- private init() {
24
- this.element.addEventListener('pointerdown', this.handlePointerDown as EventListener)
25
- }
26
-
27
- dispose() {
28
- this.element.removeEventListener('pointerdown', this.handlePointerDown as EventListener)
29
- this.removeGlobalListeners()
30
- }
31
-
32
- private handlePointerDown = (e: PointerEvent) => {
33
- e.preventDefault()
34
- const point = { x: e.clientX, y: e.clientY }
35
- this.__pointers.set(e.pointerId, point)
36
-
37
- this.addGlobalListeners()
38
- }
39
-
40
- private handlePointerMove = (e: PointerEvent) => {
41
- e.preventDefault()
42
- const point = { x: e.clientX, y: e.clientY }
43
- this.__pointers.set(e.pointerId, point)
44
-
45
- if (this.__pointers.size === 2) {
46
- this.handlePinch()
47
- } else if (this.__pointers.size === 1) {
48
- this.handleDrag(point, false)
49
- }
50
- }
51
-
52
- private handlePointerUp = (e: PointerEvent) => {
53
- const point = { x: e.clientX, y: e.clientY }
54
- this.__pointers.delete(e.pointerId)
55
-
56
- if (this.__dragStart) {
57
- this.handleDrag(point, true)
58
- }
59
-
60
- if (this.__pointers.size === 0) {
61
- this.removeGlobalListeners()
62
- this.__dragStart = null
63
- this.__lastPinchDistance = 0
64
- this.handleTap(point)
65
- }
66
- }
67
-
68
- private handlePinch() {
69
- const pointers = Array.from(this.__pointers.values()) as { x: number; y: number }[]
70
- const currentDistance = this.getDistance(pointers[0], pointers[1])
71
-
72
- if (this.__lastPinchDistance) {
73
- const scale = currentDistance / this.__lastPinchDistance
74
- const center = {
75
- x: (pointers[0].x + pointers[1].x) / 2,
76
- y: (pointers[0].y + pointers[1].y) / 2
77
- }
78
-
79
- this.element.dispatchEvent(
80
- new CustomEvent('pinch', {
81
- detail: { scale, centerX: center.x, centerY: center.y }
82
- })
83
- )
84
- }
85
-
86
- this.__lastPinchDistance = currentDistance
87
- }
88
-
89
- private handleDrag(point: { x: number; y: number }, end: boolean) {
90
- if (this.__dragStart) {
91
- const deltaX = point.x - this.__dragStart.x
92
- const deltaY = point.y - this.__dragStart.y
93
-
94
- this.element.dispatchEvent(
95
- new CustomEvent('drag', {
96
- detail: { deltaX, deltaY, clientX: point.x, clientY: point.y, end }
97
- })
98
- )
99
-
100
- if (end) {
101
- this.__dragStart = null
102
- } else {
103
- this.__dragStart = point
104
- }
105
- } else if (!end && this.__pointers.size === 1) {
106
- /* dragging을 시작하려면, pointer 개수가 1개인 것을 (지연)확인해야한다. */
107
- setTimeout(() => {
108
- if (this.__pointers.size === 1 && !this.__dragStart) {
109
- this.__dragStart = point
110
- }
111
- }, 30)
112
- }
113
- }
114
-
115
- private handleTap(point: { x: number; y: number }) {
116
- const currentTime = performance.now()
117
- const timeSinceLastTap = currentTime - this.__lastTapTime
118
-
119
- if (timeSinceLastTap < 300) {
120
- this.element.dispatchEvent(
121
- new CustomEvent('doubletap', {
122
- detail: { x: point.x, y: point.y }
123
- })
124
- )
125
- }
126
-
127
- this.__lastTapTime = currentTime
128
- }
129
-
130
- private getDistance(p1: { x: number; y: number }, p2: { x: number; y: number }): number {
131
- const dx = p1.x - p2.x
132
- const dy = p1.y - p2.y
133
- return Math.sqrt(dx * dx + dy * dy)
134
- }
135
-
136
- private addGlobalListeners() {
137
- document.addEventListener('pointermove', this.handlePointerMove as EventListener)
138
- document.addEventListener('pointerup', this.handlePointerUp as EventListener)
139
- document.addEventListener('pointercancel', this.handlePointerUp as EventListener)
140
- }
141
-
142
- private removeGlobalListeners() {
143
- document.removeEventListener('pointermove', this.handlePointerMove as EventListener)
144
- document.removeEventListener('pointerup', this.handlePointerUp as EventListener)
145
- document.removeEventListener('pointercancel', this.handlePointerUp as EventListener)
146
- }
147
- }
@@ -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'
@@ -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)
@@ -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
- }
@@ -1,157 +0,0 @@
1
- interface CustomElement extends HTMLElement {
2
- connectedCallback?(): void
3
- disconnectedCallback?(): void
4
- }
5
-
6
- type Constructor<T = CustomElement> = new (...args: any[]) => T
7
-
8
- export type GestureEventPinch = CustomEvent<{ scale: number; centerX: number; centerY: number }>
9
- export type GestureEventDrag = CustomEvent<{
10
- deltaX: number
11
- deltaY: number
12
- clientX: number
13
- clientY: number
14
- end: boolean
15
- }>
16
- export type GestureEventDoubleTap = CustomEvent<{ x: number; y: number }>
17
-
18
- export function gesture<TBase extends Constructor>(Base: TBase) {
19
- return class extends Base {
20
- __pointers = new Map<number, { x: number; y: number }>()
21
- __lastTapTime = 0
22
- __lastPinchDistance = 0
23
- __dragStart: { x: number; y: number } | null = null
24
-
25
- connectedCallback(): void {
26
- if (super.connectedCallback) {
27
- super.connectedCallback()
28
- }
29
- this.addEventListener('pointerdown', this.handlePointerDown as EventListener)
30
- }
31
-
32
- disconnectedCallback(): void {
33
- if (super.disconnectedCallback) {
34
- super.disconnectedCallback()
35
- }
36
- this.removeEventListener('pointerdown', this.handlePointerDown as EventListener)
37
- this.removeGlobalListeners()
38
- }
39
-
40
- handlePointerDown = (e: PointerEvent) => {
41
- e.preventDefault()
42
- const point = { x: e.clientX, y: e.clientY }
43
- this.__pointers.set(e.pointerId, point)
44
-
45
- this.addGlobalListeners()
46
- }
47
-
48
- handlePointerMove = (e: PointerEvent) => {
49
- e.preventDefault()
50
- const point = { x: e.clientX, y: e.clientY }
51
- this.__pointers.set(e.pointerId, point)
52
-
53
- if (this.__pointers.size === 2) {
54
- this.handlePinch()
55
- } else if (this.__pointers.size === 1) {
56
- this.handleDrag(point, false)
57
- }
58
- }
59
-
60
- handlePointerUp = (e: PointerEvent) => {
61
- const point = { x: e.clientX, y: e.clientY }
62
- this.__pointers.delete(e.pointerId)
63
-
64
- if (this.__dragStart) {
65
- this.handleDrag(point, true)
66
- }
67
-
68
- if (this.__pointers.size === 0) {
69
- this.removeGlobalListeners()
70
- this.__dragStart = null
71
- this.__lastPinchDistance = 0
72
- this.handleTap(point)
73
- }
74
- }
75
-
76
- handlePinch() {
77
- const pointers = Array.from(this.__pointers.values()) as { x: number; y: number }[]
78
- const currentDistance = this.getDistance(pointers[0], pointers[1])
79
-
80
- if (this.__lastPinchDistance) {
81
- const scale = currentDistance / this.__lastPinchDistance
82
- const center = {
83
- x: (pointers[0].x + pointers[1].x) / 2,
84
- y: (pointers[0].y + pointers[1].y) / 2
85
- }
86
-
87
- this.dispatchEvent(
88
- new CustomEvent('pinch', {
89
- detail: { scale, centerX: center.x, centerY: center.y }
90
- })
91
- )
92
- }
93
-
94
- this.__lastPinchDistance = currentDistance
95
- }
96
-
97
- handleDrag(point: { x: number; y: number }, end: boolean) {
98
- if (this.__dragStart) {
99
- const deltaX = point.x - this.__dragStart.x
100
- const deltaY = point.y - this.__dragStart.y
101
-
102
- this.dispatchEvent(
103
- new CustomEvent('drag', {
104
- detail: { deltaX, deltaY, clientX: point.x, clientY: point.y, end }
105
- })
106
- )
107
-
108
- if (end) {
109
- this.__dragStart = null
110
- } else {
111
- this.__dragStart = point
112
- }
113
- } else if (!end && this.__pointers.size === 1) {
114
- /* dragging을 시작하려면, pointer 개수가 1개인 것을 (지연)확인해야한다. */
115
- setTimeout(() => {
116
- if (this.__pointers.size === 1 && !this.__dragStart) {
117
- this.__dragStart = point
118
- }
119
- }, 30)
120
- }
121
- }
122
-
123
- handleTap(point: { x: number; y: number }) {
124
- const currentTime = performance.now()
125
- const timeSinceLastTap = currentTime - this.__lastTapTime
126
-
127
- if (timeSinceLastTap < 300) {
128
- // 300ms is a common double-tap threshold
129
- this.dispatchEvent(
130
- new CustomEvent('doubletap', {
131
- detail: { x: point.x, y: point.y }
132
- })
133
- )
134
- }
135
-
136
- this.__lastTapTime = currentTime
137
- }
138
-
139
- getDistance(p1: { x: number; y: number }, p2: { x: number; y: number }): number {
140
- const dx = p1.x - p2.x
141
- const dy = p1.y - p2.y
142
- return Math.sqrt(dx * dx + dy * dy)
143
- }
144
-
145
- addGlobalListeners() {
146
- document.addEventListener('pointermove', this.handlePointerMove as EventListener)
147
- document.addEventListener('pointerup', this.handlePointerUp as EventListener)
148
- document.addEventListener('pointercancel', this.handlePointerUp as EventListener)
149
- }
150
-
151
- removeGlobalListeners() {
152
- document.removeEventListener('pointermove', this.handlePointerMove as EventListener)
153
- document.removeEventListener('pointerup', this.handlePointerUp as EventListener)
154
- document.removeEventListener('pointercancel', this.handlePointerUp as EventListener)
155
- }
156
- }
157
- }
@@ -1,2 +0,0 @@
1
- export { default as InfiniteScrollable } from './infinite-scrollable.js'
2
- export * from './gesture-mixin.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
- }
@@ -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
- }