@sensefolks/fastpoll 0.1.0
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 +24 -0
- package/LICENSE +21 -0
- package/dist/cjs/app-globals-V2Kpy_OQ.js +8 -0
- package/dist/cjs/app-globals-V2Kpy_OQ.js.map +1 -0
- package/dist/cjs/index-CC5IS5t8.js +1437 -0
- package/dist/cjs/index-CC5IS5t8.js.map +1 -0
- package/dist/cjs/index-D8TNlmQq.js +201 -0
- package/dist/cjs/index-D8TNlmQq.js.map +1 -0
- package/dist/cjs/index.cjs.js +11 -0
- package/dist/cjs/index.cjs.js.map +1 -0
- package/dist/cjs/loader.cjs.js +16 -0
- package/dist/cjs/loader.cjs.js.map +1 -0
- package/dist/cjs/sf-fastpoll.cjs.entry.js +395 -0
- package/dist/cjs/sf-fastpoll.cjs.entry.js.map +1 -0
- package/dist/cjs/sf-fastpoll.cjs.js +28 -0
- package/dist/cjs/sf-fastpoll.cjs.js.map +1 -0
- package/dist/cjs/sf-fastpoll.entry.cjs.js.map +1 -0
- package/dist/collection/collection-manifest.json +12 -0
- package/dist/collection/components/sf-fastpoll/sf-fastpoll.css +76 -0
- package/dist/collection/components/sf-fastpoll/sf-fastpoll.js +454 -0
- package/dist/collection/components/sf-fastpoll/sf-fastpoll.js.map +1 -0
- package/dist/collection/index.js +11 -0
- package/dist/collection/index.js.map +1 -0
- package/dist/collection/utils/utils.js +189 -0
- package/dist/collection/utils/utils.js.map +1 -0
- package/dist/components/index.d.ts +33 -0
- package/dist/components/index.js +1427 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/sf-fastpoll.d.ts +11 -0
- package/dist/components/sf-fastpoll.js +425 -0
- package/dist/components/sf-fastpoll.js.map +1 -0
- package/dist/esm/app-globals-DQuL1Twl.js +6 -0
- package/dist/esm/app-globals-DQuL1Twl.js.map +1 -0
- package/dist/esm/index-CfdIRf0W.js +193 -0
- package/dist/esm/index-CfdIRf0W.js.map +1 -0
- package/dist/esm/index-XYfqntZe.js +1428 -0
- package/dist/esm/index-XYfqntZe.js.map +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/loader.js +14 -0
- package/dist/esm/loader.js.map +1 -0
- package/dist/esm/polyfills/core-js.js +11 -0
- package/dist/esm/polyfills/dom.js +79 -0
- package/dist/esm/polyfills/es5-html-element.js +1 -0
- package/dist/esm/polyfills/index.js +34 -0
- package/dist/esm/polyfills/system.js +6 -0
- package/dist/esm/sf-fastpoll.entry.js +393 -0
- package/dist/esm/sf-fastpoll.entry.js.map +1 -0
- package/dist/esm/sf-fastpoll.js +24 -0
- package/dist/esm/sf-fastpoll.js.map +1 -0
- package/dist/esm-es5/app-globals-DQuL1Twl.js +2 -0
- package/dist/esm-es5/app-globals-DQuL1Twl.js.map +1 -0
- package/dist/esm-es5/index-CfdIRf0W.js +2 -0
- package/dist/esm-es5/index-CfdIRf0W.js.map +1 -0
- package/dist/esm-es5/index-XYfqntZe.js +3 -0
- package/dist/esm-es5/index-XYfqntZe.js.map +1 -0
- package/dist/esm-es5/index.js +2 -0
- package/dist/esm-es5/index.js.map +1 -0
- package/dist/esm-es5/loader.js +2 -0
- package/dist/esm-es5/loader.js.map +1 -0
- package/dist/esm-es5/sf-fastpoll.entry.js +2 -0
- package/dist/esm-es5/sf-fastpoll.entry.js.map +1 -0
- package/dist/esm-es5/sf-fastpoll.js +2 -0
- package/dist/esm-es5/sf-fastpoll.js.map +1 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.js +1 -0
- package/dist/sf-fastpoll/index.esm.js +2 -0
- package/dist/sf-fastpoll/index.esm.js.map +1 -0
- package/dist/sf-fastpoll/loader.esm.js.map +1 -0
- package/dist/sf-fastpoll/p-1f6dca2a.system.entry.js +2 -0
- package/dist/sf-fastpoll/p-1f6dca2a.system.entry.js.map +1 -0
- package/dist/sf-fastpoll/p-4648bca3.entry.js +2 -0
- package/dist/sf-fastpoll/p-4648bca3.entry.js.map +1 -0
- package/dist/sf-fastpoll/p-BbPAtVJG.system.js +2 -0
- package/dist/sf-fastpoll/p-BbPAtVJG.system.js.map +1 -0
- package/dist/sf-fastpoll/p-C7EMppj8.system.js.map +1 -0
- package/dist/sf-fastpoll/p-C9ESvisV.system.js +3 -0
- package/dist/sf-fastpoll/p-C9ESvisV.system.js.map +1 -0
- package/dist/sf-fastpoll/p-CfdIRf0W.js +2 -0
- package/dist/sf-fastpoll/p-CfdIRf0W.js.map +1 -0
- package/dist/sf-fastpoll/p-CpmSDeqe.system.js +2 -0
- package/dist/sf-fastpoll/p-CpmSDeqe.system.js.map +1 -0
- package/dist/sf-fastpoll/p-DQuL1Twl.js +2 -0
- package/dist/sf-fastpoll/p-DQuL1Twl.js.map +1 -0
- package/dist/sf-fastpoll/p-JC66e5NR.system.js.map +1 -0
- package/dist/sf-fastpoll/p-S-cJYJS7.system.js +2 -0
- package/dist/sf-fastpoll/p-S-cJYJS7.system.js.map +1 -0
- package/dist/sf-fastpoll/p-XYfqntZe.js +3 -0
- package/dist/sf-fastpoll/p-XYfqntZe.js.map +1 -0
- package/dist/sf-fastpoll/p-zRZYYxiz.system.js +2 -0
- package/dist/sf-fastpoll/p-zRZYYxiz.system.js.map +1 -0
- package/dist/sf-fastpoll/sf-fastpoll.entry.esm.js.map +1 -0
- package/dist/sf-fastpoll/sf-fastpoll.esm.js +2 -0
- package/dist/sf-fastpoll/sf-fastpoll.esm.js.map +1 -0
- package/dist/sf-fastpoll/sf-fastpoll.js +127 -0
- package/dist/types/components/sf-fastpoll/sf-fastpoll.d.ts +77 -0
- package/dist/types/components.d.ts +47 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/stencil-public-runtime.d.ts +1709 -0
- package/dist/types/utils/utils.d.ts +86 -0
- package/loader/cdn.js +2 -0
- package/loader/index.cjs.js +2 -0
- package/loader/index.d.ts +24 -0
- package/loader/index.es2017.js +2 -0
- package/loader/index.js +3 -0
- package/package.json +86 -0
- package/readme.md +239 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for sf-fastpoll
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Maximum allowed length for text inputs
|
|
6
|
+
*/
|
|
7
|
+
const MAX_TEXT_LENGTH = 500;
|
|
8
|
+
const MAX_EMAIL_LENGTH = 254;
|
|
9
|
+
/**
|
|
10
|
+
* Sanitize user input to prevent XSS and limit length
|
|
11
|
+
* @param input The raw user input
|
|
12
|
+
* @param maxLength Maximum allowed length (default: 500)
|
|
13
|
+
* @returns Sanitized string
|
|
14
|
+
*/
|
|
15
|
+
export function sanitizeInput(input, maxLength = MAX_TEXT_LENGTH) {
|
|
16
|
+
if (typeof input !== 'string') {
|
|
17
|
+
return '';
|
|
18
|
+
}
|
|
19
|
+
// Trim whitespace
|
|
20
|
+
let sanitized = input.replace(/^\s+|\s+$/g, '');
|
|
21
|
+
// Remove null bytes
|
|
22
|
+
sanitized = sanitized.replace(/\0/g, '');
|
|
23
|
+
// Encode HTML entities to prevent XSS
|
|
24
|
+
sanitized = sanitized.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
|
25
|
+
// Truncate to max length
|
|
26
|
+
if (sanitized.length > maxLength) {
|
|
27
|
+
sanitized = sanitized.substring(0, maxLength);
|
|
28
|
+
}
|
|
29
|
+
return sanitized;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Sanitize email input with email-specific rules
|
|
33
|
+
* @param email The raw email input
|
|
34
|
+
* @returns Sanitized email string
|
|
35
|
+
*/
|
|
36
|
+
export function sanitizeEmail(email) {
|
|
37
|
+
if (typeof email !== 'string') {
|
|
38
|
+
return '';
|
|
39
|
+
}
|
|
40
|
+
// Trim and lowercase
|
|
41
|
+
let sanitized = email.replace(/^\s+|\s+$/g, '').toLowerCase();
|
|
42
|
+
// Remove null bytes and control characters
|
|
43
|
+
sanitized = sanitized.replace(/[\0\x00-\x1F\x7F]/g, '');
|
|
44
|
+
// Truncate to max email length (RFC 5321)
|
|
45
|
+
if (sanitized.length > MAX_EMAIL_LENGTH) {
|
|
46
|
+
sanitized = sanitized.substring(0, MAX_EMAIL_LENGTH);
|
|
47
|
+
}
|
|
48
|
+
return sanitized;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Sanitize a value based on field type
|
|
52
|
+
* @param value The raw value
|
|
53
|
+
* @param inputType The type of input field
|
|
54
|
+
* @returns Sanitized value
|
|
55
|
+
*/
|
|
56
|
+
export function sanitizeByType(value, inputType) {
|
|
57
|
+
switch (inputType) {
|
|
58
|
+
case 'email':
|
|
59
|
+
return sanitizeEmail(value);
|
|
60
|
+
case 'number':
|
|
61
|
+
// Only allow digits, decimal point, and minus sign
|
|
62
|
+
const numStr = String(value).replace(/[^0-9.\-]/g, '');
|
|
63
|
+
return numStr.substring(0, 20); // Reasonable max for numbers
|
|
64
|
+
case 'dropdown':
|
|
65
|
+
case 'radio':
|
|
66
|
+
// For select/radio, sanitize but be more permissive (values come from config)
|
|
67
|
+
return sanitizeInput(value, 100);
|
|
68
|
+
case 'checkbox':
|
|
69
|
+
// Checkbox values are comma-separated, sanitize each
|
|
70
|
+
return value
|
|
71
|
+
.split(',')
|
|
72
|
+
.map(v => sanitizeInput(v.replace(/^\s+|\s+$/g, ''), 100))
|
|
73
|
+
.join(', ');
|
|
74
|
+
default:
|
|
75
|
+
return sanitizeInput(value);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Check if a survey key is valid UUID
|
|
80
|
+
* @param key The survey key to validate
|
|
81
|
+
* @returns True if the key is a valid UUID, false otherwise
|
|
82
|
+
*/
|
|
83
|
+
export function isValidKey(key) {
|
|
84
|
+
if (typeof key !== 'string' || key.trim().length === 0) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
// UUID v4 regex pattern
|
|
88
|
+
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
89
|
+
return uuidRegex.test(key.trim());
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Format error messages for display
|
|
93
|
+
* @param error The error object or message
|
|
94
|
+
* @returns A formatted error message string
|
|
95
|
+
*/
|
|
96
|
+
export function formatErrorMessage(error) {
|
|
97
|
+
if (typeof error === 'string') {
|
|
98
|
+
return error;
|
|
99
|
+
}
|
|
100
|
+
if (error instanceof Error) {
|
|
101
|
+
return error.message;
|
|
102
|
+
}
|
|
103
|
+
return 'An unknown error occurred';
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Browser-compatible helper to check if array contains a value
|
|
107
|
+
* @param array The array to search
|
|
108
|
+
* @param value The value to find
|
|
109
|
+
* @returns true if value is found in array
|
|
110
|
+
*/
|
|
111
|
+
function arrayContains(array, value) {
|
|
112
|
+
for (let i = 0; i < array.length; i++) {
|
|
113
|
+
if (array[i] === value) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Browser-compatible helper to trim and split comma-separated values
|
|
121
|
+
* @param value The comma-separated string
|
|
122
|
+
* @returns Array of trimmed values
|
|
123
|
+
*/
|
|
124
|
+
function parseCommaSeparatedValues(value) {
|
|
125
|
+
if (!value) {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
const parts = value.split(',');
|
|
129
|
+
const result = [];
|
|
130
|
+
for (let i = 0; i < parts.length; i++) {
|
|
131
|
+
const trimmed = parts[i].replace(/^\s+|\s+$/g, ''); // Manual trim for IE compatibility
|
|
132
|
+
if (trimmed) {
|
|
133
|
+
result.push(trimmed);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Get field configuration for rendering
|
|
140
|
+
* @param detail The respondent detail configuration
|
|
141
|
+
* @param value The current value of the field
|
|
142
|
+
* @returns Field configuration object
|
|
143
|
+
*/
|
|
144
|
+
export function getFieldConfig(detail, value) {
|
|
145
|
+
const inputType = detail.inputType || 'text';
|
|
146
|
+
const placeholder = detail.placeholder || 'Enter your ' + detail.label.toLowerCase();
|
|
147
|
+
const required = detail.required !== false;
|
|
148
|
+
return {
|
|
149
|
+
inputType: inputType,
|
|
150
|
+
placeholder: placeholder,
|
|
151
|
+
required: required,
|
|
152
|
+
options: detail.options || [],
|
|
153
|
+
defaultValue: detail.defaultValue,
|
|
154
|
+
hasOptions: detail.options && detail.options.length > 0,
|
|
155
|
+
selectedValues: parseCommaSeparatedValues(value),
|
|
156
|
+
fieldValue: detail.value,
|
|
157
|
+
currentValue: value || '',
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Browser-compatible helper to add value to comma-separated list
|
|
162
|
+
* @param currentValue The current comma-separated string
|
|
163
|
+
* @param valueToAdd The value to add
|
|
164
|
+
* @returns Updated comma-separated string
|
|
165
|
+
*/
|
|
166
|
+
export function addToCommaSeparatedList(currentValue, valueToAdd) {
|
|
167
|
+
const values = parseCommaSeparatedValues(currentValue);
|
|
168
|
+
if (!arrayContains(values, valueToAdd)) {
|
|
169
|
+
values.push(valueToAdd);
|
|
170
|
+
}
|
|
171
|
+
return values.join(', ');
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Browser-compatible helper to remove value from comma-separated list
|
|
175
|
+
* @param currentValue The current comma-separated string
|
|
176
|
+
* @param valueToRemove The value to remove
|
|
177
|
+
* @returns Updated comma-separated string
|
|
178
|
+
*/
|
|
179
|
+
export function removeFromCommaSeparatedList(currentValue, valueToRemove) {
|
|
180
|
+
const values = parseCommaSeparatedValues(currentValue);
|
|
181
|
+
const result = [];
|
|
182
|
+
for (let i = 0; i < values.length; i++) {
|
|
183
|
+
if (values[i] !== valueToRemove) {
|
|
184
|
+
result.push(values[i]);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return result.join(', ');
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,eAAe,GAAG,GAAG,CAAC;AAC5B,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAE7B;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa,EAAE,YAAoB,eAAe;IAC9E,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,kBAAkB;IAClB,IAAI,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;IAEhD,oBAAoB;IACpB,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAEzC,sCAAsC;IACtC,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAEzI,yBAAyB;IACzB,IAAI,SAAS,CAAC,MAAM,GAAG,SAAS,EAAE,CAAC;QACjC,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;IAChD,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,EAAE,CAAC;IACZ,CA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B,CAAC,YAAoB,EAAE,aAAqB;IACtF,MAAM,MAAM,GAAG,yBAAyB,CAAC,YAAY,CAAC,CAAC;IACvD,MAAM,MAAM,GAAG,EAAE,CAAC;IAClB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,aAAa,EAAE,CAAC;YAChC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["/**\n * Utility functions for sf-fastpoll\n */\n\n/**\n * Maximum allowed length for text inputs\n */\nconst MAX_TEXT_LENGTH = 500;\nconst MAX_EMAIL_LENGTH = 254;\n\n/**\n * Sanitize user input to prevent XSS and limit length\n * @param input The raw user input\n * @param maxLength Maximum allowed length (default: 500)\n * @returns Sanitized string\n */\nexport function sanitizeInput(input: string, maxLength: number = MAX_TEXT_LENGTH): string {\n if (typeof input !== 'string') {\n return '';\n }\n\n // Trim whitespace\n let sanitized = input.replace(/^\\s+|\\s+$/g, '');\n\n // Remove null bytes\n sanitized = sanitized.replace(/\\0/g, '');\n\n // Encode HTML entities to prevent XSS\n sanitized = sanitized.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/\"/g, '"').replace(/'/g, ''');\n\n // Truncate to max length\n if (sanitized.length > maxLength) {\n sanitized = sanitized.substring(0, maxLength);\n }\n\n return sanitized;\n}\n\n/**\n * Sanitize email input with email-specific rules\n * @param email The raw email input\n * @returns Sanitized email string\n */\nexport function sanitizeEmail(email: string): string {\n if (typeof email !== 'string') {\n return '';\n }\n\n // Trim and lowercase\n let sanitized = email.replace(/^\\s+|\\s+$/g, '').toLowerCase();\n\n // Remove null bytes and control characters\n sanitized = sanitized.replace(/[\\0\\x00-\\x1F\\x7F]/g, '');\n\n // Truncate to max email length (RFC 5321)\n if (sanitized.length > MAX_EMAIL_LENGTH) {\n sanitized = sanitized.substring(0, MAX_EMAIL_LENGTH);\n }\n\n return sanitized;\n}\n\n/**\n * Sanitize a value based on field type\n * @param value The raw value\n * @param inputType The type of input field\n * @returns Sanitized value\n */\nexport function sanitizeByType(value: string, inputType: string): string {\n switch (inputType) {\n case 'email':\n return sanitizeEmail(value);\n case 'number':\n // Only allow digits, decimal point, and minus sign\n const numStr = String(value).replace(/[^0-9.\\-]/g, '');\n return numStr.substring(0, 20); // Reasonable max for numbers\n case 'dropdown':\n case 'radio':\n // For select/radio, sanitize but be more permissive (values come from config)\n return sanitizeInput(value, 100);\n case 'checkbox':\n // Checkbox values are comma-separated, sanitize each\n return value\n .split(',')\n .map(v => sanitizeInput(v.replace(/^\\s+|\\s+$/g, ''), 100))\n .join(', ');\n default:\n return sanitizeInput(value);\n }\n}\n\n/**\n * Interface for respondent detail options\n */\ninterface RespondentDetailOption {\n value: string;\n label: string;\n}\n\n/**\n * Interface for respondent detail configuration\n */\ninterface RespondentDetail {\n label: string;\n value: string;\n inputType: string;\n required?: boolean;\n placeholder?: string;\n options?: RespondentDetailOption[];\n defaultValue?: any;\n}\n\n/**\n * Check if a survey key is valid UUID\n * @param key The survey key to validate\n * @returns True if the key is a valid UUID, false otherwise\n */\nexport function isValidKey(key: string | undefined | null): boolean {\n if (typeof key !== 'string' || key.trim().length === 0) {\n return false;\n }\n\n // UUID v4 regex pattern\n const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;\n return uuidRegex.test(key.trim());\n}\n\n/**\n * Format error messages for display\n * @param error The error object or message\n * @returns A formatted error message string\n */\nexport function formatErrorMessage(error: any): string {\n if (typeof error === 'string') {\n return error;\n }\n\n if (error instanceof Error) {\n return error.message;\n }\n\n return 'An unknown error occurred';\n}\n\n/**\n * Browser-compatible helper to check if array contains a value\n * @param array The array to search\n * @param value The value to find\n * @returns true if value is found in array\n */\nfunction arrayContains(array: string[], value: string): boolean {\n for (let i = 0; i < array.length; i++) {\n if (array[i] === value) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Browser-compatible helper to trim and split comma-separated values\n * @param value The comma-separated string\n * @returns Array of trimmed values\n */\nfunction parseCommaSeparatedValues(value: string): string[] {\n if (!value) {\n return [];\n }\n const parts = value.split(',');\n const result = [];\n for (let i = 0; i < parts.length; i++) {\n const trimmed = parts[i].replace(/^\\s+|\\s+$/g, ''); // Manual trim for IE compatibility\n if (trimmed) {\n result.push(trimmed);\n }\n }\n return result;\n}\n\n/**\n * Get field configuration for rendering\n * @param detail The respondent detail configuration\n * @param value The current value of the field\n * @returns Field configuration object\n */\nexport function getFieldConfig(detail: RespondentDetail, value: string) {\n const inputType = detail.inputType || 'text';\n const placeholder = detail.placeholder || 'Enter your ' + detail.label.toLowerCase();\n const required = detail.required !== false;\n\n return {\n inputType: inputType,\n placeholder: placeholder,\n required: required,\n options: detail.options || [],\n defaultValue: detail.defaultValue,\n hasOptions: detail.options && detail.options.length > 0,\n selectedValues: parseCommaSeparatedValues(value),\n fieldValue: detail.value,\n currentValue: value || '',\n };\n}\n\n/**\n * Browser-compatible helper to add value to comma-separated list\n * @param currentValue The current comma-separated string\n * @param valueToAdd The value to add\n * @returns Updated comma-separated string\n */\nexport function addToCommaSeparatedList(currentValue: string, valueToAdd: string): string {\n const values = parseCommaSeparatedValues(currentValue);\n if (!arrayContains(values, valueToAdd)) {\n values.push(valueToAdd);\n }\n return values.join(', ');\n}\n\n/**\n * Browser-compatible helper to remove value from comma-separated list\n * @param currentValue The current comma-separated string\n * @param valueToRemove The value to remove\n * @returns Updated comma-separated string\n */\nexport function removeFromCommaSeparatedList(currentValue: string, valueToRemove: string): string {\n const values = parseCommaSeparatedValues(currentValue);\n const result = [];\n for (let i = 0; i < values.length; i++) {\n if (values[i] !== valueToRemove) {\n result.push(values[i]);\n }\n }\n return result.join(', ');\n}\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the base path to where the assets can be found. Use "setAssetPath(path)"
|
|
3
|
+
* if the path needs to be customized.
|
|
4
|
+
*/
|
|
5
|
+
export declare const getAssetPath: (path: string) => string;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Used to manually set the base path where assets can be found.
|
|
9
|
+
* If the script is used as "module", it's recommended to use "import.meta.url",
|
|
10
|
+
* such as "setAssetPath(import.meta.url)". Other options include
|
|
11
|
+
* "setAssetPath(document.currentScript.src)", or using a bundler's replace plugin to
|
|
12
|
+
* dynamically set the path at build time, such as "setAssetPath(process.env.ASSET_PATH)".
|
|
13
|
+
* But do note that this configuration depends on how your script is bundled, or lack of
|
|
14
|
+
* bundling, and where your assets can be loaded from. Additionally custom bundling
|
|
15
|
+
* will have to ensure the static assets are copied to its build directory.
|
|
16
|
+
*/
|
|
17
|
+
export declare const setAssetPath: (path: string) => void;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Used to specify a nonce value that corresponds with an application's CSP.
|
|
21
|
+
* When set, the nonce will be added to all dynamically created script and style tags at runtime.
|
|
22
|
+
* Alternatively, the nonce value can be set on a meta tag in the DOM head
|
|
23
|
+
* (<meta name="csp-nonce" content="{ nonce value here }" />) which
|
|
24
|
+
* will result in the same behavior.
|
|
25
|
+
*/
|
|
26
|
+
export declare const setNonce: (nonce: string) => void
|
|
27
|
+
|
|
28
|
+
export interface SetPlatformOptions {
|
|
29
|
+
raf?: (c: FrameRequestCallback) => number;
|
|
30
|
+
ael?: (el: EventTarget, eventName: string, listener: EventListenerOrEventListenerObject, options: boolean | AddEventListenerOptions) => void;
|
|
31
|
+
rel?: (el: EventTarget, eventName: string, listener: EventListenerOrEventListenerObject, options: boolean | AddEventListenerOptions) => void;
|
|
32
|
+
}
|
|
33
|
+
export declare const setPlatformOptions: (opts: SetPlatformOptions) => void;
|