nanosplash 3.0.1 → 3.0.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.
- package/.github/workflows/ci.yml +50 -44
- package/.github/workflows/vitepress.yml +69 -0
- package/.prettierignore +1 -0
- package/.prettierrc +10 -10
- package/README.md +11 -172
- package/bun.lockb +0 -0
- package/coverage/{core/Dom.ts.html → DomUtilities.ts.html} +141 -138
- package/coverage/{core/Service.ts.html → Service.ts.html} +250 -322
- package/coverage/{core/Splash.ts.html → Splash.ts.html} +145 -154
- package/coverage/SplashQueue.ts.html +232 -0
- package/coverage/clover.xml +557 -552
- package/coverage/coverage-final.json +5 -9043
- package/coverage/index.html +53 -23
- package/dist/cjs/ns.cjs +2 -0
- package/dist/es/ns.js +342 -0
- package/dist/iife/ns.iife.js +2 -0
- package/docs/.vitepress/config.ts +75 -0
- package/docs/.vitepress/theme/css/style.css +157 -0
- package/docs/.vitepress/theme/index.ts +16 -0
- package/docs/.vitepress/theme/vue/Card.vue +31 -0
- package/docs/.vitepress/theme/vue/CardGrid.vue +17 -0
- package/docs/.vitepress/theme/vue/Exe.vue +86 -0
- package/docs/.vitepress/theme/vue/PlayGround.vue +50 -0
- package/docs/api/doc/hide.md +69 -0
- package/docs/api/doc/show.md +47 -0
- package/docs/api/start/features.md +17 -0
- package/docs/api/start/install.md +53 -0
- package/docs/api/start/playground.md +11 -0
- package/docs/api/start/usage.md +25 -0
- package/docs/index.md +30 -0
- package/package.json +86 -87
- package/src/style/ns.sass +95 -0
- package/src/ts/core/{Dom.ts → DomUtilities.ts} +58 -57
- package/src/ts/core/Service.ts +66 -90
- package/src/ts/core/ServiceInterface.ts +5 -7
- package/src/ts/core/Splash.ts +23 -26
- package/src/ts/core/SplashInterface.ts +12 -20
- package/src/ts/core/SplashQueue.ts +49 -0
- package/src/ts/types/Types.ts +0 -9
- package/tests/{Dom.spec.ts → DomUtilities.spec.ts} +13 -23
- package/tests/Guid.spec.ts +3 -3
- package/tests/Service.spec.ts +146 -67
- package/tests/Splash.spec.ts +26 -26
- package/tests/TestUtilities.ts +48 -0
- package/tsconfig.json +1 -0
- package/vite.config.ts +1 -15
- package/coverage/core/index.html +0 -146
- package/coverage/types/Types.ts.html +0 -121
- package/coverage/types/index.html +0 -116
- package/dist/latest/cjs/ns.cjs +0 -1
- package/dist/latest/cjs/style.css +0 -1
- package/dist/latest/es/ns.js +0 -306
- package/dist/latest/es/style.css +0 -1
- package/dist/latest/iife/ns.iife.js +0 -4
- package/dist/versioned/3.0.1/cjs/ns.cjs +0 -1
- package/dist/versioned/3.0.1/cjs/style.css +0 -1
- package/dist/versioned/3.0.1/es/ns.js +0 -306
- package/dist/versioned/3.0.1/es/style.css +0 -1
- package/dist/versioned/3.0.1/iife/ns.iife.js +0 -2
- package/docs/index.6d66a821.js +0 -1
- package/docs/index.74dbd99e.css +0 -1
- package/docs/index.f34144dc.js +0 -1
- package/docs/index.html +0 -107
- package/index.html +0 -105
- package/src/sass/ns.sass +0 -95
- package/vite.demo.config.ts +0 -16
package/src/ts/core/Service.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
// @ts-strict
|
|
2
|
-
|
|
3
1
|
import { version } from '../../../package.json'
|
|
4
|
-
import '../../sass/ns.sass'
|
|
5
2
|
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
3
|
+
import { Reference, GUIDString } from '../types/Types'
|
|
4
|
+
import {
|
|
5
|
+
getRecycledSplash,
|
|
6
|
+
move,
|
|
7
|
+
elementFrom,
|
|
8
|
+
render,
|
|
9
|
+
removeNSHostClass,
|
|
10
|
+
} from './DomUtilities'
|
|
8
11
|
import { ServiceInterface } from './ServiceInterface'
|
|
9
12
|
import { Splash } from './Splash'
|
|
13
|
+
import css from '../../style/ns.sass?inline'
|
|
14
|
+
import { SplashQueue } from './SplashQueue'
|
|
10
15
|
|
|
11
16
|
/**
|
|
12
17
|
* # Service
|
|
@@ -38,7 +43,7 @@ export class Service implements ServiceInterface {
|
|
|
38
43
|
/**
|
|
39
44
|
* @inheritdoc
|
|
40
45
|
*/
|
|
41
|
-
public readonly
|
|
46
|
+
public readonly nsQueue: SplashQueue
|
|
42
47
|
|
|
43
48
|
/**
|
|
44
49
|
* # Constructor
|
|
@@ -47,29 +52,17 @@ export class Service implements ServiceInterface {
|
|
|
47
52
|
*/
|
|
48
53
|
private constructor() {
|
|
49
54
|
this.version = version
|
|
50
|
-
this.
|
|
55
|
+
this.nsQueue = new SplashQueue()
|
|
56
|
+
Service.addStyle()
|
|
51
57
|
}
|
|
52
58
|
|
|
53
|
-
/**
|
|
54
|
-
* #
|
|
55
|
-
*
|
|
56
|
-
* @param callback Callback function that returns a boolean.
|
|
57
|
-
* @returns {number} Index of Nanosplash instance in the stack or -1.
|
|
58
|
-
* @private
|
|
59
|
+
/**e
|
|
60
|
+
* # Add Style
|
|
61
|
+
* Add Nanosplash CSS to the DOM.
|
|
59
62
|
*/
|
|
60
|
-
private
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* # Find
|
|
66
|
-
* Find Nanosplash in the stack by callback.
|
|
67
|
-
* @param callback Callback function that returns a boolean.
|
|
68
|
-
* @returns {Splash | undefined} Nanosplash instance or undefined
|
|
69
|
-
* @private
|
|
70
|
-
*/
|
|
71
|
-
private find(callback: NSFinder): Splash | undefined {
|
|
72
|
-
return this.nsStack.find(callback)
|
|
63
|
+
private static addStyle(): void {
|
|
64
|
+
const style = render(`<style>${css}</style>`) as HTMLStyleElement
|
|
65
|
+
document.body.append(style)
|
|
73
66
|
}
|
|
74
67
|
|
|
75
68
|
/**
|
|
@@ -104,14 +97,10 @@ export class Service implements ServiceInterface {
|
|
|
104
97
|
* Initialize and attach a Nanosplash Service instance to the Window object.
|
|
105
98
|
*/
|
|
106
99
|
public static start(): void {
|
|
107
|
-
Service.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (!nssAssigned) {
|
|
112
|
-
Service.assignToWindow()
|
|
113
|
-
}
|
|
114
|
-
})
|
|
100
|
+
const nss = window[Service.WindowAccessorKey]
|
|
101
|
+
if (!nss) {
|
|
102
|
+
Service.assignToWindow()
|
|
103
|
+
}
|
|
115
104
|
}
|
|
116
105
|
|
|
117
106
|
/**
|
|
@@ -122,113 +111,100 @@ export class Service implements ServiceInterface {
|
|
|
122
111
|
* @private
|
|
123
112
|
*/
|
|
124
113
|
private createNS(text?: string): Splash {
|
|
125
|
-
const ns = new Splash()
|
|
126
|
-
|
|
127
|
-
this.nsStack.push(ns)
|
|
114
|
+
const ns = new Splash().setText(text || '')
|
|
115
|
+
this.nsQueue.enqueue(ns)
|
|
128
116
|
return ns
|
|
129
117
|
}
|
|
130
118
|
|
|
131
119
|
/**
|
|
132
|
-
* # Clean And Remove
|
|
120
|
+
* # Clean And Remove From DOM
|
|
133
121
|
* Remove Nanosplash from DOM and clean its parent.
|
|
134
122
|
* @param ns Nanosplash instance.
|
|
135
|
-
* @returns
|
|
136
|
-
* @private
|
|
137
|
-
*/
|
|
138
|
-
private cleanAndRemove(ns: Splash): GUIDString {
|
|
139
|
-
cleanNSParentOf(ns)
|
|
140
|
-
return ns.remove().getId()
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* # Stack Delete
|
|
145
|
-
* Remove Nanosplash instance from the stack.
|
|
146
|
-
* @param ns Nanosplash instance.
|
|
147
|
-
* @returns {GUIDString | null} Nanosplash ID or null if it doesn't exist.
|
|
123
|
+
* @returns True if Nanosplash was removed from DOM.
|
|
148
124
|
* @private
|
|
149
125
|
*/
|
|
150
|
-
private
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
126
|
+
private cleanAndRemoveFromDOM(ns: Splash | null): boolean {
|
|
127
|
+
if (ns) {
|
|
128
|
+
removeNSHostClass(ns.getElement()?.parentElement ?? null)
|
|
129
|
+
return ns.delete()
|
|
130
|
+
}
|
|
131
|
+
return false
|
|
155
132
|
}
|
|
156
133
|
|
|
157
134
|
/**
|
|
158
135
|
* # Delete NS
|
|
159
136
|
* Remove Nanosplash instance from both the stack and the
|
|
160
|
-
* @param
|
|
161
|
-
* @returns
|
|
137
|
+
* @param guid Nanosplash ID.
|
|
138
|
+
* @returns True if Nanosplash was removed from DOM.
|
|
162
139
|
* @private
|
|
163
140
|
*/
|
|
164
|
-
private deleteNS(
|
|
165
|
-
|
|
166
|
-
if (ns) {
|
|
167
|
-
this.cleanAndRemove(ns)
|
|
168
|
-
return this.stackDelete(ns)
|
|
169
|
-
}
|
|
170
|
-
return null
|
|
141
|
+
private deleteNS(guid: GUIDString): boolean {
|
|
142
|
+
return this.cleanAndRemoveFromDOM(this.nsQueue.delete(guid) ?? null)
|
|
171
143
|
}
|
|
172
144
|
|
|
173
145
|
/**
|
|
174
146
|
* @inheritdoc
|
|
175
147
|
*/
|
|
176
|
-
public show(text?: string): GUIDString {
|
|
177
|
-
|
|
178
|
-
if (!ns) {
|
|
179
|
-
ns = this.createNS()
|
|
180
|
-
move(ns.getNSElement(), document.body)
|
|
181
|
-
}
|
|
182
|
-
return ns.setText(text || '').getId()
|
|
148
|
+
public show(text?: string): GUIDString | null {
|
|
149
|
+
return this.showInside(document.body, text)
|
|
183
150
|
}
|
|
184
151
|
|
|
185
152
|
/**
|
|
186
153
|
* @inheritdoc
|
|
187
154
|
*/
|
|
188
155
|
public showInside(ref: Reference, text?: string): GUIDString | null {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
156
|
+
try {
|
|
157
|
+
const destinationNode = elementFrom(ref) as Element
|
|
158
|
+
const ns = getRecycledSplash(destinationNode) ?? this.createNS()
|
|
159
|
+
move(ns.getElement() as Element, destinationNode)
|
|
160
|
+
const parsedText = text ? String(text) : ''
|
|
161
|
+
return ns.setText(parsedText).getId()
|
|
162
|
+
} catch (e) {
|
|
163
|
+
console.error(e)
|
|
164
|
+
return null
|
|
197
165
|
}
|
|
198
|
-
|
|
199
|
-
return null
|
|
200
166
|
}
|
|
201
167
|
|
|
202
168
|
/**
|
|
203
169
|
* @inheritdoc
|
|
204
170
|
*/
|
|
205
171
|
public hide(): GUIDString | null {
|
|
206
|
-
const ns = this.
|
|
207
|
-
|
|
172
|
+
const ns = this.nsQueue.dequeue()
|
|
173
|
+
if (!ns) return null
|
|
174
|
+
this.cleanAndRemoveFromDOM(ns)
|
|
175
|
+
return ns.getId()
|
|
208
176
|
}
|
|
209
177
|
|
|
210
178
|
/**
|
|
211
179
|
* @inheritdoc
|
|
212
180
|
*/
|
|
213
181
|
public hideAll(): void {
|
|
214
|
-
this.
|
|
215
|
-
|
|
182
|
+
let ns = this.nsQueue.dequeue()
|
|
183
|
+
while (ns) {
|
|
184
|
+
this.cleanAndRemoveFromDOM(ns)
|
|
185
|
+
ns = this.nsQueue.dequeue()
|
|
186
|
+
}
|
|
216
187
|
}
|
|
217
188
|
|
|
218
189
|
/**
|
|
219
190
|
* @inheritdoc
|
|
220
191
|
*/
|
|
221
192
|
public hideId(id: GUIDString): GUIDString | null {
|
|
222
|
-
return this.deleteNS(
|
|
193
|
+
return this.deleteNS(id) ? id : null
|
|
223
194
|
}
|
|
224
195
|
|
|
225
196
|
/**
|
|
226
197
|
* @inheritdoc
|
|
227
198
|
*/
|
|
228
199
|
public hideInside(ref: Reference): GUIDString | null {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
200
|
+
try {
|
|
201
|
+
const ns = getRecycledSplash(elementFrom(ref) as Element)
|
|
202
|
+
const guid = ns?.getId() ?? ''
|
|
203
|
+
return this.deleteNS(guid ?? '') ? guid : null
|
|
204
|
+
} catch (e) {
|
|
205
|
+
console.error(e)
|
|
206
|
+
return null
|
|
207
|
+
}
|
|
232
208
|
}
|
|
233
209
|
}
|
|
234
210
|
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
// @ts-strict
|
|
2
|
-
|
|
3
1
|
import { GUIDString, Reference } from '../types/Types'
|
|
4
|
-
import {
|
|
2
|
+
import { SplashQueue } from './SplashQueue'
|
|
5
3
|
|
|
6
4
|
export interface ServiceInterface {
|
|
7
5
|
/**
|
|
@@ -10,15 +8,15 @@ export interface ServiceInterface {
|
|
|
10
8
|
* When a Nanosplash instance is removed, it's removed from the stack.
|
|
11
9
|
* @see Splash
|
|
12
10
|
*/
|
|
13
|
-
readonly
|
|
11
|
+
readonly nsQueue: SplashQueue
|
|
14
12
|
|
|
15
13
|
/**
|
|
16
14
|
* # Show
|
|
17
15
|
* Present a Nanosplash in the browser window displaying the given text.
|
|
18
16
|
* @param text Text to display.
|
|
19
|
-
* @returns {GUIDString} Nanosplash ID.
|
|
17
|
+
* @returns {GUIDString | null} Nanosplash ID.
|
|
20
18
|
*/
|
|
21
|
-
show(text?: string): GUIDString
|
|
19
|
+
show(text?: string): GUIDString | null
|
|
22
20
|
|
|
23
21
|
/**
|
|
24
22
|
* # Show Inside
|
|
@@ -31,7 +29,7 @@ export interface ServiceInterface {
|
|
|
31
29
|
|
|
32
30
|
/**
|
|
33
31
|
* # Hide
|
|
34
|
-
* Hide the
|
|
32
|
+
* Hide the oldest Nanosplash.
|
|
35
33
|
* @returns {GUIDString | null} Nanosplash ID or null if it doesn't exist.
|
|
36
34
|
*/
|
|
37
35
|
hide(): GUIDString | null
|
package/src/ts/core/Splash.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
// @ts-strict
|
|
2
|
-
|
|
3
1
|
import { GUIDString } from '../types/Types'
|
|
4
|
-
import { createElement, showElement, hideElement } from './
|
|
2
|
+
import { createElement, showElement, hideElement } from './DomUtilities'
|
|
5
3
|
import { SplashInterface } from './SplashInterface'
|
|
6
4
|
|
|
7
5
|
/**
|
|
@@ -28,13 +26,13 @@ export class Splash implements SplashInterface {
|
|
|
28
26
|
* # ID
|
|
29
27
|
* Each Nanosplash instance is given a unique GUID.
|
|
30
28
|
*/
|
|
31
|
-
private
|
|
29
|
+
private id: GUIDString | null
|
|
32
30
|
|
|
33
31
|
/**
|
|
34
32
|
* # Element
|
|
35
33
|
* The root element of the Nanosplash component.
|
|
36
34
|
*/
|
|
37
|
-
private element
|
|
35
|
+
private element: HTMLDivElement | null
|
|
38
36
|
|
|
39
37
|
/**
|
|
40
38
|
* # Generate GUID
|
|
@@ -61,36 +59,33 @@ export class Splash implements SplashInterface {
|
|
|
61
59
|
/**
|
|
62
60
|
* @inheritdoc
|
|
63
61
|
*/
|
|
64
|
-
public
|
|
65
|
-
return
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* @inheritdoc
|
|
70
|
-
*/
|
|
71
|
-
public getNSTextElement(): HTMLDivElement {
|
|
72
|
-
return <HTMLDivElement>this.getNSContentElement().firstElementChild
|
|
62
|
+
public getId(): GUIDString | null {
|
|
63
|
+
return this.id
|
|
73
64
|
}
|
|
74
65
|
|
|
75
66
|
/**
|
|
76
67
|
* @inheritdoc
|
|
77
68
|
*/
|
|
78
|
-
public
|
|
79
|
-
return this.
|
|
69
|
+
public getElement(): HTMLDivElement | null {
|
|
70
|
+
return <HTMLDivElement>this.element
|
|
80
71
|
}
|
|
81
72
|
|
|
82
73
|
/**
|
|
83
74
|
* @inheritdoc
|
|
84
75
|
*/
|
|
85
|
-
public
|
|
86
|
-
return
|
|
76
|
+
public getTextElement(): HTMLDivElement {
|
|
77
|
+
return (
|
|
78
|
+
<HTMLDivElement>(
|
|
79
|
+
this.getElement()?.firstElementChild?.firstElementChild
|
|
80
|
+
) ?? null
|
|
81
|
+
)
|
|
87
82
|
}
|
|
88
83
|
|
|
89
84
|
/**
|
|
90
85
|
* @inheritdoc
|
|
91
86
|
*/
|
|
92
87
|
public setText(text: string): Splash {
|
|
93
|
-
this.
|
|
88
|
+
this.getTextElement().innerText = text
|
|
94
89
|
text.length > 0 ? this.showText() : this.hideText()
|
|
95
90
|
return this
|
|
96
91
|
}
|
|
@@ -99,7 +94,7 @@ export class Splash implements SplashInterface {
|
|
|
99
94
|
* @inheritdoc
|
|
100
95
|
*/
|
|
101
96
|
public showText(): Splash {
|
|
102
|
-
showElement(this.
|
|
97
|
+
showElement(this.getTextElement())
|
|
103
98
|
return this
|
|
104
99
|
}
|
|
105
100
|
|
|
@@ -107,18 +102,20 @@ export class Splash implements SplashInterface {
|
|
|
107
102
|
* @inheritdoc
|
|
108
103
|
*/
|
|
109
104
|
public hideText(): Splash {
|
|
110
|
-
hideElement(this.
|
|
105
|
+
hideElement(this.getTextElement())
|
|
111
106
|
return this
|
|
112
107
|
}
|
|
113
108
|
|
|
114
109
|
/**
|
|
115
110
|
* @inheritdoc
|
|
116
111
|
*/
|
|
117
|
-
public
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
112
|
+
public delete(): boolean {
|
|
113
|
+
this.id = null
|
|
114
|
+
if (this.element !== null) {
|
|
115
|
+
this.element.innerHTML = ''
|
|
116
|
+
this.element.remove()
|
|
117
|
+
this.element = null
|
|
121
118
|
}
|
|
122
|
-
return this
|
|
119
|
+
return this.element === null
|
|
123
120
|
}
|
|
124
121
|
}
|
|
@@ -1,32 +1,24 @@
|
|
|
1
|
-
// @ts-strict
|
|
2
|
-
|
|
3
1
|
import { GUIDString } from '../types/Types'
|
|
4
2
|
import { Splash } from './Splash'
|
|
5
3
|
|
|
6
4
|
export interface SplashInterface {
|
|
7
|
-
/**
|
|
8
|
-
* # Get NS Content Element
|
|
9
|
-
* Returns the content element of the Nanosplash.
|
|
10
|
-
*/
|
|
11
|
-
getNSContentElement(): HTMLDivElement
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* # Get NS Text Element
|
|
15
|
-
* Returns the text element of the Nanosplash.
|
|
16
|
-
*/
|
|
17
|
-
getNSTextElement(): HTMLDivElement
|
|
18
|
-
|
|
19
5
|
/**
|
|
20
6
|
* # Get ID
|
|
21
7
|
* Return Nanosplash instance GUID.
|
|
22
8
|
*/
|
|
23
|
-
getId(): GUIDString
|
|
9
|
+
getId(): GUIDString | null
|
|
24
10
|
|
|
25
11
|
/**
|
|
26
|
-
* # Get
|
|
12
|
+
* # Get Element
|
|
27
13
|
* Return Nanosplash instance HTMLDivElement.
|
|
28
14
|
*/
|
|
29
|
-
|
|
15
|
+
getElement(): HTMLDivElement | null
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* # Get Text Element
|
|
19
|
+
* Returns the text element of the Nanosplash.
|
|
20
|
+
*/
|
|
21
|
+
getTextElement(): HTMLDivElement | null
|
|
30
22
|
|
|
31
23
|
/**
|
|
32
24
|
* # Set Text
|
|
@@ -47,8 +39,8 @@ export interface SplashInterface {
|
|
|
47
39
|
hideText(): Splash
|
|
48
40
|
|
|
49
41
|
/**
|
|
50
|
-
* #
|
|
51
|
-
*
|
|
42
|
+
* # Delete
|
|
43
|
+
* Remove from DOM and delete internal data.
|
|
52
44
|
*/
|
|
53
|
-
|
|
45
|
+
delete(): boolean
|
|
54
46
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { GUIDString } from '../types/Types'
|
|
2
|
+
import { Splash } from './Splash'
|
|
3
|
+
|
|
4
|
+
export class SplashQueue {
|
|
5
|
+
public queue: Array<Splash>
|
|
6
|
+
|
|
7
|
+
constructor() {
|
|
8
|
+
this.queue = []
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* # Enqueue
|
|
13
|
+
* Add a new item to the queue.
|
|
14
|
+
* @param item The item to add to the queue.
|
|
15
|
+
*/
|
|
16
|
+
public enqueue(item: Splash): SplashQueue {
|
|
17
|
+
this.queue.push(item)
|
|
18
|
+
return this
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* # Dequeue
|
|
23
|
+
* Remove the first item from the queue.
|
|
24
|
+
* @returns The first item from the queue.
|
|
25
|
+
*/
|
|
26
|
+
public dequeue(): Splash | undefined {
|
|
27
|
+
return this.queue.shift()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* # Get
|
|
32
|
+
* @param id The GUID of the Nanosplash to get.
|
|
33
|
+
* @returns The Nanosplash with the given GUID.
|
|
34
|
+
*/
|
|
35
|
+
public get(id: GUIDString): Splash | undefined {
|
|
36
|
+
return this.queue.find(item => item.getId() === id)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* # Delete
|
|
41
|
+
* @param id The GUID of the Nanosplash to delete.
|
|
42
|
+
* @returns The deleted Nanosplash.
|
|
43
|
+
*/
|
|
44
|
+
public delete(id: GUIDString): Splash | undefined {
|
|
45
|
+
const index = this.queue.findIndex(item => item.getId() === id)
|
|
46
|
+
if (index === -1) return undefined
|
|
47
|
+
return this.queue.splice(index, 1)[0]
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/ts/types/Types.ts
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
import { Splash } from '../core/Splash'
|
|
2
|
-
|
|
3
1
|
export type GUIDString = string
|
|
4
2
|
export type CSSSelector = string
|
|
5
|
-
export type FindCallback<T> = (item: T, index: number) => boolean
|
|
6
|
-
export type NSFinder = FindCallback<Splash>
|
|
7
3
|
export type Reference = CSSSelector | Element
|
|
8
|
-
|
|
9
|
-
export enum ClassListAction {
|
|
10
|
-
Add = 'add',
|
|
11
|
-
Remove = 'remove',
|
|
12
|
-
}
|
|
@@ -5,19 +5,16 @@ import { beforeEach, describe, expect, it } from 'vitest'
|
|
|
5
5
|
import {
|
|
6
6
|
createElement,
|
|
7
7
|
injectAsFirstChild,
|
|
8
|
-
prepareParentOf,
|
|
9
|
-
cleanNSParentOf,
|
|
10
8
|
showElement,
|
|
11
9
|
hideElement,
|
|
12
|
-
setNSHostClass,
|
|
13
10
|
move,
|
|
14
11
|
elementFrom,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
getRecycledSplash,
|
|
13
|
+
addNSHostClass,
|
|
14
|
+
removeNSHostClass,
|
|
15
|
+
} from '../src/ts/core/DomUtilities'
|
|
18
16
|
import { Splash } from '../src/ts/core/Splash'
|
|
19
17
|
import { Service } from '../src/ts/core/Service'
|
|
20
|
-
import { ClassListAction } from '../src/ts/types/Types'
|
|
21
18
|
|
|
22
19
|
describe('DOMUtilities', () => {
|
|
23
20
|
// Reset the DOM before each test
|
|
@@ -56,17 +53,17 @@ describe('DOMUtilities', () => {
|
|
|
56
53
|
it('Should be able to prepare the parent of a Nanosplash component', () => {
|
|
57
54
|
const ns = new Splash()
|
|
58
55
|
const parent = document.createElement('div')
|
|
59
|
-
parent.appendChild(ns.
|
|
60
|
-
|
|
56
|
+
parent.appendChild(ns.getElement() as Element)
|
|
57
|
+
addNSHostClass(parent)
|
|
61
58
|
expect(parent.classList.contains(Splash.NSHostClass)).toBe(true)
|
|
62
59
|
})
|
|
63
60
|
|
|
64
61
|
it('Should be able to clean the parent of a Nanosplash component', () => {
|
|
65
62
|
const ns = new Splash()
|
|
66
63
|
const parent = document.createElement('div')
|
|
67
|
-
parent.appendChild(ns.
|
|
64
|
+
parent.appendChild(ns.getElement() as Element)
|
|
68
65
|
parent.classList.add(Splash.NSClass)
|
|
69
|
-
|
|
66
|
+
removeNSHostClass(parent)
|
|
70
67
|
expect(parent.classList.contains(Splash.NSHostClass)).toBe(false)
|
|
71
68
|
})
|
|
72
69
|
|
|
@@ -82,19 +79,12 @@ describe('DOMUtilities', () => {
|
|
|
82
79
|
expect(elementFrom(element)).toBe(element)
|
|
83
80
|
})
|
|
84
81
|
|
|
85
|
-
it('Should be able to check if an element is a Nanosplash element', () => {
|
|
86
|
-
const elementA = new Splash().getNSElement()
|
|
87
|
-
const elementB = document.createElement('div')
|
|
88
|
-
expect(elementIsNS(elementA)).toBe(true)
|
|
89
|
-
expect(elementIsNS(elementB)).toBe(false)
|
|
90
|
-
})
|
|
91
|
-
|
|
92
82
|
it('Should be able to recycle a Nanosplash component', () => {
|
|
93
83
|
const destination = document.createElement('div')
|
|
94
84
|
document.body.appendChild(destination)
|
|
95
85
|
const nss = Service.getInstance()
|
|
96
86
|
const id = nss.showInside(destination, 'Hello World!')
|
|
97
|
-
const recycled =
|
|
87
|
+
const recycled = getRecycledSplash(destination)
|
|
98
88
|
expect(recycled?.getId()).toBe(id)
|
|
99
89
|
})
|
|
100
90
|
|
|
@@ -112,16 +102,16 @@ describe('DOMUtilities', () => {
|
|
|
112
102
|
|
|
113
103
|
it('Should be able to alter the class of a Nanosplash host', () => {
|
|
114
104
|
const div = document.createElement('div')
|
|
115
|
-
|
|
105
|
+
addNSHostClass(div)
|
|
116
106
|
expect(div.classList.contains(Splash.NSHostClass)).toBe(true)
|
|
117
|
-
|
|
107
|
+
removeNSHostClass(div)
|
|
118
108
|
expect(div.classList.contains(Splash.NSHostClass)).toBe(false)
|
|
119
109
|
})
|
|
120
110
|
|
|
121
111
|
it('Should be able to move a Nanosplash component', () => {
|
|
122
112
|
const ns = new Splash()
|
|
123
113
|
const destination = document.createElement('div')
|
|
124
|
-
move(ns.
|
|
125
|
-
expect(destination.firstElementChild).toBe(ns.
|
|
114
|
+
move(ns.getElement() as Element, destination)
|
|
115
|
+
expect(destination.firstElementChild).toBe(ns.getElement())
|
|
126
116
|
})
|
|
127
117
|
})
|
package/tests/Guid.spec.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { beforeEach, describe, expect, it } from 'vitest'
|
|
|
2
2
|
import { JSDOM } from 'jsdom'
|
|
3
3
|
import { Splash } from '../src/ts/core/Splash'
|
|
4
4
|
|
|
5
|
+
const rgx = /^[{]?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}[}]?$/
|
|
6
|
+
|
|
5
7
|
describe('Guid', () => {
|
|
6
8
|
// Reset the DOM before each test
|
|
7
9
|
beforeEach(() => {
|
|
@@ -13,9 +15,7 @@ describe('Guid', () => {
|
|
|
13
15
|
})
|
|
14
16
|
|
|
15
17
|
it('Should generate a valid GUID', () => {
|
|
16
|
-
const guidRegex =
|
|
17
|
-
/^[{]?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}[}]?$/
|
|
18
18
|
const value = new Splash().getId()
|
|
19
|
-
expect(value).toMatch(
|
|
19
|
+
expect(value).toMatch(rgx)
|
|
20
20
|
})
|
|
21
21
|
})
|