@getmicdrop/svelte-components 1.0.5 → 1.0.6
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/utils/apiConfig.d.ts +30 -0
- package/dist/utils/apiConfig.d.ts.map +1 -0
- package/dist/utils/apiConfig.js +50 -0
- package/dist/utils/apiConfig.spec.d.ts +2 -0
- package/dist/utils/apiConfig.spec.d.ts.map +1 -0
- package/dist/utils/apiConfig.spec.js +118 -0
- package/dist/utils/data/table/bookingsTable.json +1934 -0
- package/dist/utils/data/table/eventsTable.json +959 -0
- package/dist/utils/data/table/performersTable.json +2563 -0
- package/dist/utils/data/table/types.d.ts +105 -0
- package/dist/utils/data/table/types.d.ts.map +1 -0
- package/dist/utils/data/table/types.js +1 -0
- package/dist/utils/data/table/venuesTable.json +16 -0
- package/dist/utils/greetings.d.ts +24 -0
- package/dist/utils/greetings.d.ts.map +1 -0
- package/dist/utils/greetings.js +187 -0
- package/dist/utils/greetings.spec.d.ts +2 -0
- package/dist/utils/greetings.spec.d.ts.map +1 -0
- package/dist/utils/greetings.spec.js +337 -0
- package/dist/utils/imageValidation.d.ts +36 -0
- package/dist/utils/imageValidation.d.ts.map +1 -0
- package/dist/utils/imageValidation.js +121 -0
- package/dist/utils/imageValidation.spec.d.ts +2 -0
- package/dist/utils/imageValidation.spec.d.ts.map +1 -0
- package/dist/utils/imageValidation.spec.js +220 -0
- package/dist/utils/portal.d.ts +12 -0
- package/dist/utils/portal.d.ts.map +1 -0
- package/dist/utils/portal.js +25 -0
- package/dist/utils/portal.spec.d.ts +2 -0
- package/dist/utils/portal.spec.d.ts.map +1 -0
- package/dist/utils/portal.spec.js +143 -0
- package/dist/utils/utils/utils.d.ts +73 -0
- package/dist/utils/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils/utils.js +323 -0
- package/dist/utils/utils/utils.spec.d.ts +2 -0
- package/dist/utils/utils/utils.spec.d.ts.map +1 -0
- package/dist/utils/utils/utils.spec.js +698 -0
- package/dist/utils/utils.d.ts +98 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +379 -0
- package/dist/utils/utils.spec.d.ts +2 -0
- package/dist/utils/utils.spec.d.ts.map +1 -0
- package/dist/utils/utils.spec.js +643 -0
- package/package.json +1 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates an image file according to upload guidelines
|
|
3
|
+
* @param {File} file - The image file to validate
|
|
4
|
+
* @returns {Promise<{valid: boolean, error: string|null, dimensions: {width: number, height: number}}>}
|
|
5
|
+
*/
|
|
6
|
+
export function validateImage(file: File): Promise<{
|
|
7
|
+
valid: boolean;
|
|
8
|
+
error: string | null;
|
|
9
|
+
dimensions: {
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
};
|
|
13
|
+
}>;
|
|
14
|
+
/**
|
|
15
|
+
* Gets the accept attribute value for file inputs
|
|
16
|
+
* @returns {string}
|
|
17
|
+
*/
|
|
18
|
+
export function getImageAcceptAttribute(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Gets formatted error messages for display in UI
|
|
21
|
+
* @returns {object}
|
|
22
|
+
*/
|
|
23
|
+
export function getValidationMessages(): object;
|
|
24
|
+
/**
|
|
25
|
+
* Image validation utilities for file uploads
|
|
26
|
+
*
|
|
27
|
+
* Guidelines:
|
|
28
|
+
* - Formats: PNG, JPG, JPEG, WebP, HEIC, HEIF
|
|
29
|
+
* - Max dimension: 8000px (to handle phone screenshots up to 4K)
|
|
30
|
+
* - Max file size: 20MB (we crop and optimize to 1000x1000 WebP anyway)
|
|
31
|
+
* - Aspect ratio: Any
|
|
32
|
+
*/
|
|
33
|
+
export const MAX_FILE_SIZE: number;
|
|
34
|
+
export const MAX_DIMENSION: 8000;
|
|
35
|
+
export const ALLOWED_IMAGE_TYPES: string[];
|
|
36
|
+
//# sourceMappingURL=imageValidation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imageValidation.d.ts","sourceRoot":"","sources":["../../src/lib/utils/imageValidation.js"],"names":[],"mappings":"AAqBA;;;;GAIG;AACH,oCAHW,IAAI,GACF,OAAO,CAAC;IAAC,KAAK,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,GAAC,IAAI,CAAC;IAAC,UAAU,EAAE;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC,CAAA;CAAC,CAAC,CA8CtG;AA6BD;;;GAGG;AACH,2CAFa,MAAM,CAIlB;AAED;;;GAGG;AACH,yCAFa,MAAM,CASlB;AAtHD;;;;;;;;GAQG;AAEH,mCAAuC;AACvC,4BAAsB,IAAI,CAAC;AAC3B,2CAOE"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image validation utilities for file uploads
|
|
3
|
+
*
|
|
4
|
+
* Guidelines:
|
|
5
|
+
* - Formats: PNG, JPG, JPEG, WebP, HEIC, HEIF
|
|
6
|
+
* - Max dimension: 8000px (to handle phone screenshots up to 4K)
|
|
7
|
+
* - Max file size: 20MB (we crop and optimize to 1000x1000 WebP anyway)
|
|
8
|
+
* - Aspect ratio: Any
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const MAX_FILE_SIZE = 20 * 1024 * 1024; // 20 MB - generous since we optimize
|
|
12
|
+
const MAX_DIMENSION = 8000; // pixels - handles 4K+ phone screenshots
|
|
13
|
+
const ALLOWED_IMAGE_TYPES = [
|
|
14
|
+
'image/jpeg',
|
|
15
|
+
'image/jpg',
|
|
16
|
+
'image/png',
|
|
17
|
+
'image/webp',
|
|
18
|
+
'image/heic',
|
|
19
|
+
'image/heif'
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Validates an image file according to upload guidelines
|
|
24
|
+
* @param {File} file - The image file to validate
|
|
25
|
+
* @returns {Promise<{valid: boolean, error: string|null, dimensions: {width: number, height: number}}>}
|
|
26
|
+
*/
|
|
27
|
+
export async function validateImage(file) {
|
|
28
|
+
// Check file type
|
|
29
|
+
if (!ALLOWED_IMAGE_TYPES.includes(file.type.toLowerCase())) {
|
|
30
|
+
return {
|
|
31
|
+
valid: false,
|
|
32
|
+
error: 'Invalid file format. Please upload PNG, JPG, WebP, or HEIC images only.',
|
|
33
|
+
dimensions: null
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Check file size
|
|
38
|
+
if (file.size > MAX_FILE_SIZE) {
|
|
39
|
+
const sizeMB = (file.size / (1024 * 1024)).toFixed(2);
|
|
40
|
+
return {
|
|
41
|
+
valid: false,
|
|
42
|
+
error: `File too large (${sizeMB}MB). Maximum file size is 20MB.`,
|
|
43
|
+
dimensions: null
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Check dimensions
|
|
48
|
+
try {
|
|
49
|
+
const dimensions = await getImageDimensions(file);
|
|
50
|
+
|
|
51
|
+
if (dimensions.width > MAX_DIMENSION || dimensions.height > MAX_DIMENSION) {
|
|
52
|
+
return {
|
|
53
|
+
valid: false,
|
|
54
|
+
error: `Image dimensions too large (${dimensions.width}x${dimensions.height}px). Maximum dimension is ${MAX_DIMENSION}px.`,
|
|
55
|
+
dimensions
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
valid: true,
|
|
61
|
+
error: null,
|
|
62
|
+
dimensions
|
|
63
|
+
};
|
|
64
|
+
} catch (error) {
|
|
65
|
+
return {
|
|
66
|
+
valid: false,
|
|
67
|
+
error: 'Failed to read image dimensions. Please try another file.',
|
|
68
|
+
dimensions: null
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Gets the dimensions of an image file
|
|
75
|
+
* @param {File} file - The image file
|
|
76
|
+
* @returns {Promise<{width: number, height: number}>}
|
|
77
|
+
*/
|
|
78
|
+
function getImageDimensions(file) {
|
|
79
|
+
return new Promise((resolve, reject) => {
|
|
80
|
+
const img = new Image();
|
|
81
|
+
const objectUrl = URL.createObjectURL(file);
|
|
82
|
+
|
|
83
|
+
img.onload = function() {
|
|
84
|
+
URL.revokeObjectURL(objectUrl);
|
|
85
|
+
resolve({
|
|
86
|
+
width: this.width,
|
|
87
|
+
height: this.height
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
img.onerror = function() {
|
|
92
|
+
URL.revokeObjectURL(objectUrl);
|
|
93
|
+
reject(new Error('Failed to load image'));
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
img.src = objectUrl;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Gets the accept attribute value for file inputs
|
|
102
|
+
* @returns {string}
|
|
103
|
+
*/
|
|
104
|
+
export function getImageAcceptAttribute() {
|
|
105
|
+
return 'image/png,image/jpeg,image/jpg,image/webp,image/heic,image/heif';
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Gets formatted error messages for display in UI
|
|
110
|
+
* @returns {object}
|
|
111
|
+
*/
|
|
112
|
+
export function getValidationMessages() {
|
|
113
|
+
return {
|
|
114
|
+
formats: 'PNG, JPG, WebP, HEIC',
|
|
115
|
+
maxSize: '20MB',
|
|
116
|
+
maxDimension: '8000px',
|
|
117
|
+
aspectRatio: 'Any'
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export { MAX_FILE_SIZE, MAX_DIMENSION, ALLOWED_IMAGE_TYPES };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imageValidation.spec.d.ts","sourceRoot":"","sources":["../../src/lib/utils/imageValidation.spec.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
validateImage,
|
|
4
|
+
getImageAcceptAttribute,
|
|
5
|
+
getValidationMessages,
|
|
6
|
+
MAX_FILE_SIZE,
|
|
7
|
+
MAX_DIMENSION,
|
|
8
|
+
ALLOWED_IMAGE_TYPES,
|
|
9
|
+
} from './imageValidation';
|
|
10
|
+
|
|
11
|
+
describe('imageValidation', () => {
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
// Mock URL.createObjectURL and URL.revokeObjectURL
|
|
14
|
+
global.URL.createObjectURL = vi.fn(() => 'mock-object-url');
|
|
15
|
+
global.URL.revokeObjectURL = vi.fn();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('constants', () => {
|
|
19
|
+
it('MAX_FILE_SIZE is 20MB', () => {
|
|
20
|
+
expect(MAX_FILE_SIZE).toBe(20 * 1024 * 1024);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('MAX_DIMENSION is 8000', () => {
|
|
24
|
+
expect(MAX_DIMENSION).toBe(8000);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('ALLOWED_IMAGE_TYPES includes common formats', () => {
|
|
28
|
+
expect(ALLOWED_IMAGE_TYPES).toContain('image/jpeg');
|
|
29
|
+
expect(ALLOWED_IMAGE_TYPES).toContain('image/png');
|
|
30
|
+
expect(ALLOWED_IMAGE_TYPES).toContain('image/webp');
|
|
31
|
+
expect(ALLOWED_IMAGE_TYPES).toContain('image/heic');
|
|
32
|
+
expect(ALLOWED_IMAGE_TYPES).toContain('image/heif');
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('validateImage', () => {
|
|
37
|
+
it('rejects invalid file type', async () => {
|
|
38
|
+
const file = new File(['content'], 'test.gif', { type: 'image/gif' });
|
|
39
|
+
const result = await validateImage(file);
|
|
40
|
+
|
|
41
|
+
expect(result.valid).toBe(false);
|
|
42
|
+
expect(result.error).toContain('Invalid file format');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('rejects file that is too large', async () => {
|
|
46
|
+
// Create a mock file larger than 20MB
|
|
47
|
+
const largeContent = new ArrayBuffer(21 * 1024 * 1024);
|
|
48
|
+
const file = new File([largeContent], 'large.jpg', { type: 'image/jpeg' });
|
|
49
|
+
|
|
50
|
+
const result = await validateImage(file);
|
|
51
|
+
|
|
52
|
+
expect(result.valid).toBe(false);
|
|
53
|
+
expect(result.error).toContain('File too large');
|
|
54
|
+
expect(result.error).toContain('20MB');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('accepts valid JPEG file', async () => {
|
|
58
|
+
const file = new File(['content'], 'test.jpg', { type: 'image/jpeg' });
|
|
59
|
+
|
|
60
|
+
// Mock Image loading
|
|
61
|
+
const mockImage = {
|
|
62
|
+
width: 100,
|
|
63
|
+
height: 100,
|
|
64
|
+
onload: null,
|
|
65
|
+
onerror: null,
|
|
66
|
+
src: '',
|
|
67
|
+
};
|
|
68
|
+
vi.spyOn(global, 'Image').mockImplementation(() => {
|
|
69
|
+
setTimeout(() => mockImage.onload?.call(mockImage), 0);
|
|
70
|
+
return mockImage;
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const result = await validateImage(file);
|
|
74
|
+
|
|
75
|
+
expect(result.valid).toBe(true);
|
|
76
|
+
expect(result.error).toBe(null);
|
|
77
|
+
expect(result.dimensions).toEqual({ width: 100, height: 100 });
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('accepts valid PNG file', async () => {
|
|
81
|
+
const file = new File(['content'], 'test.png', { type: 'image/png' });
|
|
82
|
+
|
|
83
|
+
const mockImage = {
|
|
84
|
+
width: 500,
|
|
85
|
+
height: 500,
|
|
86
|
+
onload: null,
|
|
87
|
+
onerror: null,
|
|
88
|
+
src: '',
|
|
89
|
+
};
|
|
90
|
+
vi.spyOn(global, 'Image').mockImplementation(() => {
|
|
91
|
+
setTimeout(() => mockImage.onload?.call(mockImage), 0);
|
|
92
|
+
return mockImage;
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const result = await validateImage(file);
|
|
96
|
+
|
|
97
|
+
expect(result.valid).toBe(true);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('accepts valid WebP file', async () => {
|
|
101
|
+
const file = new File(['content'], 'test.webp', { type: 'image/webp' });
|
|
102
|
+
|
|
103
|
+
const mockImage = {
|
|
104
|
+
width: 200,
|
|
105
|
+
height: 200,
|
|
106
|
+
onload: null,
|
|
107
|
+
onerror: null,
|
|
108
|
+
src: '',
|
|
109
|
+
};
|
|
110
|
+
vi.spyOn(global, 'Image').mockImplementation(() => {
|
|
111
|
+
setTimeout(() => mockImage.onload?.call(mockImage), 0);
|
|
112
|
+
return mockImage;
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const result = await validateImage(file);
|
|
116
|
+
|
|
117
|
+
expect(result.valid).toBe(true);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('rejects image with dimensions too large', async () => {
|
|
121
|
+
const file = new File(['content'], 'test.jpg', { type: 'image/jpeg' });
|
|
122
|
+
|
|
123
|
+
const mockImage = {
|
|
124
|
+
width: 9000,
|
|
125
|
+
height: 9000,
|
|
126
|
+
onload: null,
|
|
127
|
+
onerror: null,
|
|
128
|
+
src: '',
|
|
129
|
+
};
|
|
130
|
+
vi.spyOn(global, 'Image').mockImplementation(() => {
|
|
131
|
+
setTimeout(() => mockImage.onload?.call(mockImage), 0);
|
|
132
|
+
return mockImage;
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const result = await validateImage(file);
|
|
136
|
+
|
|
137
|
+
expect(result.valid).toBe(false);
|
|
138
|
+
expect(result.error).toContain('dimensions too large');
|
|
139
|
+
expect(result.dimensions).toEqual({ width: 9000, height: 9000 });
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('handles image load error', async () => {
|
|
143
|
+
const file = new File(['content'], 'test.jpg', { type: 'image/jpeg' });
|
|
144
|
+
|
|
145
|
+
const mockImage = {
|
|
146
|
+
onload: null,
|
|
147
|
+
onerror: null,
|
|
148
|
+
src: '',
|
|
149
|
+
};
|
|
150
|
+
vi.spyOn(global, 'Image').mockImplementation(() => {
|
|
151
|
+
setTimeout(() => mockImage.onerror?.(), 0);
|
|
152
|
+
return mockImage;
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
const result = await validateImage(file);
|
|
156
|
+
|
|
157
|
+
expect(result.valid).toBe(false);
|
|
158
|
+
expect(result.error).toContain('Failed to read image dimensions');
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('handles HEIC format', async () => {
|
|
162
|
+
const file = new File(['content'], 'test.heic', { type: 'image/heic' });
|
|
163
|
+
|
|
164
|
+
const mockImage = {
|
|
165
|
+
width: 100,
|
|
166
|
+
height: 100,
|
|
167
|
+
onload: null,
|
|
168
|
+
onerror: null,
|
|
169
|
+
src: '',
|
|
170
|
+
};
|
|
171
|
+
vi.spyOn(global, 'Image').mockImplementation(() => {
|
|
172
|
+
setTimeout(() => mockImage.onload?.call(mockImage), 0);
|
|
173
|
+
return mockImage;
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
const result = await validateImage(file);
|
|
177
|
+
|
|
178
|
+
expect(result.valid).toBe(true);
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
describe('getImageAcceptAttribute', () => {
|
|
183
|
+
it('returns accept string with all allowed types', () => {
|
|
184
|
+
const accept = getImageAcceptAttribute();
|
|
185
|
+
|
|
186
|
+
expect(accept).toContain('image/png');
|
|
187
|
+
expect(accept).toContain('image/jpeg');
|
|
188
|
+
expect(accept).toContain('image/webp');
|
|
189
|
+
expect(accept).toContain('image/heic');
|
|
190
|
+
expect(accept).toContain('image/heif');
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('returns comma-separated values', () => {
|
|
194
|
+
const accept = getImageAcceptAttribute();
|
|
195
|
+
expect(accept.split(',').length).toBeGreaterThan(1);
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
describe('getValidationMessages', () => {
|
|
200
|
+
it('returns formats message', () => {
|
|
201
|
+
const messages = getValidationMessages();
|
|
202
|
+
expect(messages.formats).toBe('PNG, JPG, WebP, HEIC');
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it('returns maxSize message', () => {
|
|
206
|
+
const messages = getValidationMessages();
|
|
207
|
+
expect(messages.maxSize).toBe('20MB');
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('returns maxDimension message', () => {
|
|
211
|
+
const messages = getValidationMessages();
|
|
212
|
+
expect(messages.maxDimension).toBe('8000px');
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('returns aspectRatio message', () => {
|
|
216
|
+
const messages = getValidationMessages();
|
|
217
|
+
expect(messages.aspectRatio).toBe('Any');
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Svelte action that portals an element to a target container (default: document.body)
|
|
3
|
+
* This moves the element outside of any stacking contexts, solving iOS z-index issues.
|
|
4
|
+
*
|
|
5
|
+
* Usage: <div use:portal>...</div>
|
|
6
|
+
* Or: <div use:portal={document.getElementById('modal-root')}>...</div>
|
|
7
|
+
*/
|
|
8
|
+
export function portal(node: any, target?: HTMLElement): {
|
|
9
|
+
update(newTarget: any): void;
|
|
10
|
+
destroy(): void;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=portal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portal.d.ts","sourceRoot":"","sources":["portal.js"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH;;;EAiBC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Svelte action that portals an element to a target container (default: document.body)
|
|
3
|
+
* This moves the element outside of any stacking contexts, solving iOS z-index issues.
|
|
4
|
+
*
|
|
5
|
+
* Usage: <div use:portal>...</div>
|
|
6
|
+
* Or: <div use:portal={document.getElementById('modal-root')}>...</div>
|
|
7
|
+
*/
|
|
8
|
+
export function portal(node, target = document.body) {
|
|
9
|
+
// Move the node to the target
|
|
10
|
+
target.appendChild(node);
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
update(newTarget) {
|
|
14
|
+
// If target changes, move to new target
|
|
15
|
+
newTarget = newTarget || document.body;
|
|
16
|
+
newTarget.appendChild(node);
|
|
17
|
+
},
|
|
18
|
+
destroy() {
|
|
19
|
+
// Clean up - remove the node when component is destroyed
|
|
20
|
+
if (node.parentNode) {
|
|
21
|
+
node.parentNode.removeChild(node);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portal.spec.d.ts","sourceRoot":"","sources":["../../src/lib/utils/portal.spec.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import { portal } from './portal';
|
|
3
|
+
|
|
4
|
+
describe('portal', () => {
|
|
5
|
+
let node;
|
|
6
|
+
let target;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
// Create mock nodes
|
|
10
|
+
node = document.createElement('div');
|
|
11
|
+
node.textContent = 'Portal Content';
|
|
12
|
+
target = document.createElement('div');
|
|
13
|
+
target.id = 'portal-target';
|
|
14
|
+
document.body.appendChild(target);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
// Clean up
|
|
19
|
+
if (target.parentNode) {
|
|
20
|
+
target.parentNode.removeChild(target);
|
|
21
|
+
}
|
|
22
|
+
if (node.parentNode) {
|
|
23
|
+
node.parentNode.removeChild(node);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('initial portal', () => {
|
|
28
|
+
it('appends node to document.body by default', () => {
|
|
29
|
+
portal(node);
|
|
30
|
+
expect(node.parentNode).toBe(document.body);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('appends node to specified target', () => {
|
|
34
|
+
portal(node, target);
|
|
35
|
+
expect(node.parentNode).toBe(target);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('returns an object with update and destroy methods', () => {
|
|
39
|
+
const result = portal(node);
|
|
40
|
+
expect(result).toHaveProperty('update');
|
|
41
|
+
expect(result).toHaveProperty('destroy');
|
|
42
|
+
expect(typeof result.update).toBe('function');
|
|
43
|
+
expect(typeof result.destroy).toBe('function');
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('update method', () => {
|
|
48
|
+
it('moves node to new target', () => {
|
|
49
|
+
const newTarget = document.createElement('div');
|
|
50
|
+
document.body.appendChild(newTarget);
|
|
51
|
+
|
|
52
|
+
const { update } = portal(node, target);
|
|
53
|
+
expect(node.parentNode).toBe(target);
|
|
54
|
+
|
|
55
|
+
update(newTarget);
|
|
56
|
+
expect(node.parentNode).toBe(newTarget);
|
|
57
|
+
|
|
58
|
+
// Clean up
|
|
59
|
+
newTarget.parentNode.removeChild(newTarget);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('moves node to document.body when new target is null', () => {
|
|
63
|
+
const { update } = portal(node, target);
|
|
64
|
+
expect(node.parentNode).toBe(target);
|
|
65
|
+
|
|
66
|
+
update(null);
|
|
67
|
+
expect(node.parentNode).toBe(document.body);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('moves node to document.body when new target is undefined', () => {
|
|
71
|
+
const { update } = portal(node, target);
|
|
72
|
+
expect(node.parentNode).toBe(target);
|
|
73
|
+
|
|
74
|
+
update(undefined);
|
|
75
|
+
expect(node.parentNode).toBe(document.body);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('destroy method', () => {
|
|
80
|
+
it('removes node from parent', () => {
|
|
81
|
+
const { destroy } = portal(node, target);
|
|
82
|
+
expect(node.parentNode).toBe(target);
|
|
83
|
+
|
|
84
|
+
destroy();
|
|
85
|
+
expect(node.parentNode).toBe(null);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('handles node already removed', () => {
|
|
89
|
+
const { destroy } = portal(node, target);
|
|
90
|
+
|
|
91
|
+
// Manually remove node first
|
|
92
|
+
target.removeChild(node);
|
|
93
|
+
|
|
94
|
+
// Should not throw
|
|
95
|
+
expect(() => destroy()).not.toThrow();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('removes node from document.body', () => {
|
|
99
|
+
const { destroy } = portal(node);
|
|
100
|
+
expect(node.parentNode).toBe(document.body);
|
|
101
|
+
|
|
102
|
+
destroy();
|
|
103
|
+
expect(node.parentNode).toBe(null);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe('real-world usage scenarios', () => {
|
|
108
|
+
it('can portal modal content outside stacking context', () => {
|
|
109
|
+
// Create a stacking context
|
|
110
|
+
const stackingContext = document.createElement('div');
|
|
111
|
+
stackingContext.style.position = 'relative';
|
|
112
|
+
stackingContext.style.zIndex = '1';
|
|
113
|
+
document.body.appendChild(stackingContext);
|
|
114
|
+
|
|
115
|
+
// Create modal inside stacking context
|
|
116
|
+
const modal = document.createElement('div');
|
|
117
|
+
modal.className = 'modal';
|
|
118
|
+
stackingContext.appendChild(modal);
|
|
119
|
+
|
|
120
|
+
// Portal should move it to body
|
|
121
|
+
portal(modal);
|
|
122
|
+
expect(modal.parentNode).toBe(document.body);
|
|
123
|
+
|
|
124
|
+
// Clean up
|
|
125
|
+
stackingContext.parentNode.removeChild(stackingContext);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('works with multiple portals', () => {
|
|
129
|
+
const node1 = document.createElement('div');
|
|
130
|
+
const node2 = document.createElement('div');
|
|
131
|
+
|
|
132
|
+
portal(node1);
|
|
133
|
+
portal(node2);
|
|
134
|
+
|
|
135
|
+
expect(node1.parentNode).toBe(document.body);
|
|
136
|
+
expect(node2.parentNode).toBe(document.body);
|
|
137
|
+
|
|
138
|
+
// Clean up
|
|
139
|
+
document.body.removeChild(node1);
|
|
140
|
+
document.body.removeChild(node2);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export function cn(...inputs: any[]): string;
|
|
2
|
+
export function convertToDate(value: any): string | null;
|
|
3
|
+
export function classNames(...classes: any[]): string;
|
|
4
|
+
export function truncateTitle(title: any, maxLength: any): any;
|
|
5
|
+
export function convertToCustomDateFormat(isoString: any): Date;
|
|
6
|
+
export function convertToCustomDateTimeFormat(isoDateString: any): Date;
|
|
7
|
+
export function formatHour(dateString: any): string;
|
|
8
|
+
export function formattedDate(date: any): string;
|
|
9
|
+
export function formattedFullDate(date: any): string;
|
|
10
|
+
export function formatTimeRange(startDate: any, endDate: any): string;
|
|
11
|
+
export function getDateRange(startDate: any, endDate: any): string[];
|
|
12
|
+
export function capitalize(word: any): any;
|
|
13
|
+
export function timeAgo(date: any): string;
|
|
14
|
+
export function formatDateTime(dateTimeString: any, timeZone?: string): string;
|
|
15
|
+
export function formatTimeline(startDateTime: any): string;
|
|
16
|
+
export function getDay(dateString: any): string;
|
|
17
|
+
export function getMonth(dateString: any): string;
|
|
18
|
+
export function getDateOfMonth(dateString: any): number;
|
|
19
|
+
export function getRoleFromRoleOnStage(roleOnStage: any): any;
|
|
20
|
+
export function formatEvent(event: any): {
|
|
21
|
+
eventId: any;
|
|
22
|
+
venueId: any;
|
|
23
|
+
title: any;
|
|
24
|
+
role: any;
|
|
25
|
+
startDateTime: any;
|
|
26
|
+
acceptedState: any;
|
|
27
|
+
doorsOpenTime: any;
|
|
28
|
+
spotDuration: string;
|
|
29
|
+
venueName: any;
|
|
30
|
+
location: any;
|
|
31
|
+
id: any;
|
|
32
|
+
image: any;
|
|
33
|
+
details: {
|
|
34
|
+
venue: any;
|
|
35
|
+
stageName: any;
|
|
36
|
+
address: any;
|
|
37
|
+
setLength: string;
|
|
38
|
+
eventDetails: any;
|
|
39
|
+
};
|
|
40
|
+
lastUpdated: any;
|
|
41
|
+
};
|
|
42
|
+
export function formatRosterEventPerformerInvite(event: any): {
|
|
43
|
+
venueId: any;
|
|
44
|
+
role: any;
|
|
45
|
+
acceptedState: any;
|
|
46
|
+
name: any;
|
|
47
|
+
shortVenue: string;
|
|
48
|
+
location: string;
|
|
49
|
+
id: any;
|
|
50
|
+
lastUpdated: any;
|
|
51
|
+
image: any;
|
|
52
|
+
hasAvailability: boolean;
|
|
53
|
+
invitationAccepted: boolean;
|
|
54
|
+
};
|
|
55
|
+
export function formatVenue(event: any): {
|
|
56
|
+
venueId: any;
|
|
57
|
+
name: any;
|
|
58
|
+
image: any;
|
|
59
|
+
location: string;
|
|
60
|
+
start: any;
|
|
61
|
+
end: any;
|
|
62
|
+
doorOpen: any;
|
|
63
|
+
email: any;
|
|
64
|
+
phone: any;
|
|
65
|
+
description: any;
|
|
66
|
+
instagram: any;
|
|
67
|
+
facebook: any;
|
|
68
|
+
twitter: any;
|
|
69
|
+
lastUpdated: any;
|
|
70
|
+
timeRange: string;
|
|
71
|
+
dateRange: string[];
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["utils.js"],"names":[],"mappings":"AAGA,6CAEC;AAED,yDAEC;AAED,sDAEC;AAED,+DAKC;AAED,gEAUC;AAED,wEAWC;AAED,oDAWC;AAED,iDAQC;AAED,qDAiBC;AAgDD,sEAgBC;AAED,qEAgBC;AA+HD,2CAEC;AAED,2CAsBC;AA1NM,+EAeN;AAEM,2DAYN;AAsCM,gDAIN;AAEM,kDAiBN;AAEM,wDAGN;AAgBM,8DAEN;AAGM;;;;;;;;;;;;;;;;;;;;;EAoCN;AAEM;;;;;;;;;;;;EAeN;AAEM;;;;;;;;;;;;;;;;;EAmBN"}
|