@dashadmin/dash-utils 1.3.72 → 1.3.74-srcfree.1
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/components/LazyAppLoader.d.ts +17 -0
- package/dist/components/MinimalLayout.d.ts +6 -0
- package/dist/components/RouterComponent.d.ts +22 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/contexts/IPCMessageBrokerContext.d.ts +42 -0
- package/dist/hooks/useCapacitorAppStateRefresh.d.ts +2 -0
- package/dist/hooks/useCapacitorKeyboard.d.ts +19 -0
- package/dist/hooks/useDeviceStorageSync.d.ts +4 -0
- package/dist/hooks/useDraggable.d.ts +24 -0
- package/dist/hooks/useMenuStateInit.d.ts +10 -0
- package/dist/hooks/useMobileDetection.d.ts +20 -0
- package/dist/hooks/useNotifications.d.ts +51 -0
- package/dist/hooks/useQuickSearch.d.ts +6 -0
- package/dist/hooks/useWindowSize.d.ts +6 -0
- package/dist/index.d.ts +30 -0
- package/dist/utils/authProviderUtils.d.ts +37 -0
- package/dist/utils/dashBootstrapApp.d.ts +9 -0
- package/dist/utils/dashDtorage.d.ts +8 -0
- package/dist/utils/dashIPCService.d.ts +93 -0
- package/dist/utils/dataProviderUtils.d.ts +44 -0
- package/dist/utils/electronStoreSync.d.ts +3 -0
- package/dist/utils/envUtils.d.ts +1 -0
- package/dist/utils/environmentBodyClasses.d.ts +11 -0
- package/dist/utils/isDev.d.ts +5 -0
- package/dist/utils/notificationPermission.d.ts +5 -0
- package/dist/utils/platformDetection.d.ts +13 -0
- package/dist/utils/priceFormatter.d.ts +2 -0
- package/dist/utils/resourceLoader.d.ts +8 -0
- package/dist/utils/speechService.d.ts +7 -0
- package/dist/utils/storedTheme.d.ts +11 -0
- package/dist/utils/updateDomCssVariables.d.ts +6 -0
- package/dist/utils/validation.d.ts +12 -0
- package/package.json +13 -10
- package/src/components/LazyAppLoader.tsx +0 -143
- package/src/components/MinimalLayout.tsx +0 -22
- package/src/components/RouterComponent.tsx +0 -169
- package/src/components/index.ts +0 -16
- package/src/contexts/IPCMessageBrokerContext.tsx +0 -303
- package/src/hooks/useCapacitorAppStateRefresh.ts +0 -34
- package/src/hooks/useCapacitorKeyboard.ts +0 -213
- package/src/hooks/useDeviceStorageSync.ts +0 -70
- package/src/hooks/useDraggable.ts +0 -133
- package/src/hooks/useMenuStateInit.ts +0 -85
- package/src/hooks/useMobileDetection.ts +0 -165
- package/src/hooks/useNotifications.ts +0 -220
- package/src/hooks/useQuickSearch.ts +0 -42
- package/src/hooks/useWindowSize.tsx +0 -36
- package/src/index.ts +0 -202
- package/src/utils/authProviderUtils.ts +0 -170
- package/src/utils/dashBootstrapApp.ts +0 -104
- package/src/utils/dashDtorage.tsx +0 -51
- package/src/utils/dashDtorage.tsx.old +0 -78
- package/src/utils/dashIPCService.ts +0 -204
- package/src/utils/dataProviderUtils.ts +0 -221
- package/src/utils/electronStoreSync.ts +0 -34
- package/src/utils/envUtils.tsx +0 -27
- package/src/utils/environmentBodyClasses.ts +0 -72
- package/src/utils/isDev.ts +0 -65
- package/src/utils/notificationPermission.ts +0 -57
- package/src/utils/platformDetection.ts +0 -98
- package/src/utils/priceFormatter.ts +0 -36
- package/src/utils/resourceLoader.ts +0 -107
- package/src/utils/speechService.ts +0 -112
- package/src/utils/storedTheme.ts +0 -60
- package/src/utils/updateDomCssVariables.tsx +0 -181
- package/src/utils/validation.ts +0 -147
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
function getCssVarFromDom(key: string): string | undefined {
|
|
2
|
-
const value = getComputedStyle(document.documentElement).getPropertyValue(`--${key}`).trim();
|
|
3
|
-
return value || undefined;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
function getAllCSSVariableNames(styleSheets: StyleSheetList = document.styleSheets): string[] {
|
|
7
|
-
const cssVars = new Set<string>();
|
|
8
|
-
|
|
9
|
-
for (let i = 0; i < styleSheets.length; i++) {
|
|
10
|
-
const sheet = styleSheets[i];
|
|
11
|
-
let rules: CSSRuleList | undefined;
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
// Some stylesheets may be cross-origin and throw on access
|
|
15
|
-
rules = (sheet as CSSStyleSheet).cssRules;
|
|
16
|
-
} catch {
|
|
17
|
-
continue;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (!rules) continue;
|
|
21
|
-
|
|
22
|
-
for (let j = 0; j < rules.length; j++) {
|
|
23
|
-
const rule = rules[j];
|
|
24
|
-
// Only process style rules (ignore @media, @font-face, etc.)
|
|
25
|
-
if ('style' in rule && rule.style) {
|
|
26
|
-
const style = rule.style as CSSStyleDeclaration;
|
|
27
|
-
for (let k = 0; k < style.length; k++) {
|
|
28
|
-
const name = style[k];
|
|
29
|
-
if (name.startsWith('--')) {
|
|
30
|
-
cssVars.add(name);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return Array.from(cssVars);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Read CSS variables from all stylesheets EXCEPT the dynamic theme style element.
|
|
42
|
-
* This gives us the "static" compiled LESS/CSS defaults, unaffected by our own dynamic overrides.
|
|
43
|
-
*/
|
|
44
|
-
function getStaticCssVariables(): Record<string, string> {
|
|
45
|
-
const result: Record<string, string> = {};
|
|
46
|
-
for (let i = 0; i < document.styleSheets.length; i++) {
|
|
47
|
-
const sheet = document.styleSheets[i];
|
|
48
|
-
const ownerNode = sheet.ownerNode as HTMLElement;
|
|
49
|
-
// Skip our dynamic theme style element to avoid reading back our own values
|
|
50
|
-
if (ownerNode?.id === 'dash-theme-variables') continue;
|
|
51
|
-
try {
|
|
52
|
-
const rules = (sheet as CSSStyleSheet).cssRules;
|
|
53
|
-
if (!rules) continue;
|
|
54
|
-
for (let j = 0; j < rules.length; j++) {
|
|
55
|
-
const rule = rules[j];
|
|
56
|
-
if ('selectorText' in rule && (rule as CSSStyleRule).selectorText === ':root') {
|
|
57
|
-
const style = (rule as CSSStyleRule).style;
|
|
58
|
-
for (let k = 0; k < style.length; k++) {
|
|
59
|
-
const name = style[k];
|
|
60
|
-
if (name.startsWith('--')) {
|
|
61
|
-
result[name] = style.getPropertyValue(name).trim();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
} catch {
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return result;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export const updateDomCssVariables = (
|
|
74
|
-
theme: string,
|
|
75
|
-
colors?: { [x: string]: string },
|
|
76
|
-
values?: { [x: string]: string }
|
|
77
|
-
) => {
|
|
78
|
-
const debug = false;
|
|
79
|
-
const themeSuffix = `--${theme}`;
|
|
80
|
-
const logKeys = [
|
|
81
|
-
"primary-color--light",
|
|
82
|
-
"primary-color--dark",
|
|
83
|
-
"primary-contrast--light",
|
|
84
|
-
"primary-contrast--dark",
|
|
85
|
-
// "secondary-color--light",
|
|
86
|
-
// "secondary-color--dark",
|
|
87
|
-
// "highlight-color--light",
|
|
88
|
-
// "highlight-color--dark",
|
|
89
|
-
//"framed_layout-bg--light",
|
|
90
|
-
//"framed_layout-bg--dark",
|
|
91
|
-
];
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
// Find or create the style element
|
|
95
|
-
let themeStyleElement = document.getElementById('dash-theme-variables') as HTMLStyleElement | null;
|
|
96
|
-
|
|
97
|
-
if (!themeStyleElement) {
|
|
98
|
-
themeStyleElement = document.createElement('style');
|
|
99
|
-
themeStyleElement.id = 'dash-theme-variables';
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// CRITICAL FIX: Always ensure the style element is at the END of <head>
|
|
103
|
-
// for highest CSS cascade priority. This ensures our dynamic tenant colors
|
|
104
|
-
// override the static compiled LESS/CSS defaults.
|
|
105
|
-
// appendChild on an already-attached element moves it to the new position.
|
|
106
|
-
document.head.appendChild(themeStyleElement);
|
|
107
|
-
|
|
108
|
-
let styleString = '';
|
|
109
|
-
|
|
110
|
-
values && Object.entries(values).forEach(([key, value]) => {
|
|
111
|
-
styleString += `--${key}: ${value}; `;
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
// Always read the compiled static defaults (excluding our dynamic style) as a
|
|
115
|
-
// per-key fallback — even when `colors` is provided. A tenant's saved `colors`
|
|
116
|
-
// object can be PARTIAL (e.g. only --light keys saved, no --dark counterparts).
|
|
117
|
-
// Without this fallback, any key missing from `colors` for the active theme
|
|
118
|
-
// would never be set at all, leaving base vars like --primary-color undefined
|
|
119
|
-
// and breaking anything (e.g. the sidebar gradient) that depends on them.
|
|
120
|
-
const staticVars = getStaticCssVariables();
|
|
121
|
-
|
|
122
|
-
// Collect all keys to set: union of the tenant's saved colors AND the static
|
|
123
|
-
// compiled defaults, so nothing is ever silently left unset.
|
|
124
|
-
const allKeys = new Set<string>();
|
|
125
|
-
if (colors) {
|
|
126
|
-
Object.keys(colors).forEach(k => allKeys.add(k));
|
|
127
|
-
}
|
|
128
|
-
Object.keys(staticVars).forEach(name => {
|
|
129
|
-
allKeys.add(name.slice(2)); // remove leading '--'
|
|
130
|
-
});
|
|
131
|
-
logKeys.forEach(k => allKeys.add(k));
|
|
132
|
-
|
|
133
|
-
allKeys.forEach(key => {
|
|
134
|
-
// Get value: prefer colors param, then static vars, then computed DOM
|
|
135
|
-
let value = colors?.[key];
|
|
136
|
-
if (!value && staticVars) {
|
|
137
|
-
value = staticVars[`--${key}`];
|
|
138
|
-
}
|
|
139
|
-
if (!value) value = getCssVarFromDom(key);
|
|
140
|
-
|
|
141
|
-
if (value) {
|
|
142
|
-
// Write EVERY key we have a value for — including BOTH the --light AND
|
|
143
|
-
// --dark suffixed variants, regardless of the active theme.
|
|
144
|
-
//
|
|
145
|
-
// Previously this only wrote the ACTIVE theme's suffixed keys, which left
|
|
146
|
-
// the OTHER theme's suffixed vars stuck at their static compiled defaults
|
|
147
|
-
// (e.g. while in light mode, --primary-color--dark stayed the app's
|
|
148
|
-
// build-time default instead of the tenant's value). Any code that
|
|
149
|
-
// references a specific theme's variable directly — notably the
|
|
150
|
-
// always-dark sidebar, which reads var(--primary-color--dark) in both
|
|
151
|
-
// modes — needs BOTH variants populated with the tenant values no matter
|
|
152
|
-
// which mode is active. Only the BASE (unsuffixed) key below stays
|
|
153
|
-
// theme-dependent and follows the active mode.
|
|
154
|
-
styleString += `--${key}: ${value}; `;
|
|
155
|
-
if (logKeys.includes(key)) {
|
|
156
|
-
debug && console.log(`%c ⬤ --${key}: ${value}; `, `color: ${value};`);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Only set baseKey for the current theme
|
|
161
|
-
if (key.endsWith(themeSuffix)) {
|
|
162
|
-
const baseKey = key.slice(0, -themeSuffix.length);
|
|
163
|
-
let baseValue = colors?.[key];
|
|
164
|
-
if (!baseValue && staticVars) {
|
|
165
|
-
baseValue = staticVars[`--${key}`];
|
|
166
|
-
}
|
|
167
|
-
if (!baseValue) baseValue = getCssVarFromDom(key);
|
|
168
|
-
if (baseValue) {
|
|
169
|
-
styleString += `--${baseKey}: ${baseValue}; `;
|
|
170
|
-
if (logKeys.includes(`${baseKey}${themeSuffix}`)) {
|
|
171
|
-
debug && console.log(`%c ⬤ [DEFAULT][${themeSuffix}] --${baseKey}: ${baseValue}; `, `color: ${baseValue};`);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
// Remove this log or set debug to false in production
|
|
177
|
-
debug && console.log("STYLES", styleString);
|
|
178
|
-
themeStyleElement.textContent = `:root { ${styleString} }`;
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
export default updateDomCssVariables;
|
package/src/utils/validation.ts
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Common validation utilities
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Email validation regex pattern
|
|
7
|
-
* RFC 5322 compliant email validation
|
|
8
|
-
*/
|
|
9
|
-
export const EMAIL_REGEX = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Validate email address
|
|
13
|
-
* @param email - Email string to validate
|
|
14
|
-
* @returns boolean indicating if email is valid
|
|
15
|
-
*/
|
|
16
|
-
export const validateEmail = (email: string): boolean => {
|
|
17
|
-
if (!email || typeof email !== 'string') return false;
|
|
18
|
-
return EMAIL_REGEX.test(email.trim());
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Phone number validation regex (basic international format)
|
|
23
|
-
*/
|
|
24
|
-
export const PHONE_REGEX = /^\+?[\d\s\-()]{7,20}$/;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Validate phone number
|
|
28
|
-
* @param phone - Phone string to validate
|
|
29
|
-
* @returns boolean indicating if phone is valid
|
|
30
|
-
*/
|
|
31
|
-
export const validatePhone = (phone: string): boolean => {
|
|
32
|
-
if (!phone || typeof phone !== 'string') return false;
|
|
33
|
-
return PHONE_REGEX.test(phone.trim());
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* URL validation regex
|
|
38
|
-
*/
|
|
39
|
-
export const URL_REGEX = /^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*\/?$/i;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Validate URL
|
|
43
|
-
* @param url - URL string to validate
|
|
44
|
-
* @returns boolean indicating if URL is valid
|
|
45
|
-
*/
|
|
46
|
-
export const validateUrl = (url: string): boolean => {
|
|
47
|
-
if (!url || typeof url !== 'string') return false;
|
|
48
|
-
return URL_REGEX.test(url.trim());
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Password strength levels
|
|
53
|
-
*/
|
|
54
|
-
export type PasswordStrength = 'weak' | 'fair' | 'good' | 'strong';
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Check password strength
|
|
58
|
-
* @param password - Password to check
|
|
59
|
-
* @returns Password strength level
|
|
60
|
-
*/
|
|
61
|
-
export const checkPasswordStrength = (password: string): PasswordStrength => {
|
|
62
|
-
if (!password) return 'weak';
|
|
63
|
-
|
|
64
|
-
let score = 0;
|
|
65
|
-
|
|
66
|
-
// Length checks
|
|
67
|
-
if (password.length >= 8) score++;
|
|
68
|
-
if (password.length >= 12) score++;
|
|
69
|
-
|
|
70
|
-
// Character type checks
|
|
71
|
-
if (/[a-z]/.test(password)) score++;
|
|
72
|
-
if (/[A-Z]/.test(password)) score++;
|
|
73
|
-
if (/[0-9]/.test(password)) score++;
|
|
74
|
-
if (/[^a-zA-Z0-9]/.test(password)) score++;
|
|
75
|
-
|
|
76
|
-
if (score <= 2) return 'weak';
|
|
77
|
-
if (score <= 3) return 'fair';
|
|
78
|
-
if (score <= 4) return 'good';
|
|
79
|
-
return 'strong';
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Validate required field
|
|
84
|
-
* @param value - Value to check
|
|
85
|
-
* @returns boolean indicating if value is not empty
|
|
86
|
-
*/
|
|
87
|
-
export const validateRequired = (value: any): boolean => {
|
|
88
|
-
if (value === null || value === undefined) return false;
|
|
89
|
-
if (typeof value === 'string') return value.trim().length > 0;
|
|
90
|
-
if (Array.isArray(value)) return value.length > 0;
|
|
91
|
-
return true;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Validate minimum length
|
|
96
|
-
* @param value - String to check
|
|
97
|
-
* @param minLength - Minimum length required
|
|
98
|
-
* @returns boolean indicating if value meets minimum length
|
|
99
|
-
*/
|
|
100
|
-
export const validateMinLength = (value: string, minLength: number): boolean => {
|
|
101
|
-
if (!value || typeof value !== 'string') return false;
|
|
102
|
-
return value.trim().length >= minLength;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Validate maximum length
|
|
107
|
-
* @param value - String to check
|
|
108
|
-
* @param maxLength - Maximum length allowed
|
|
109
|
-
* @returns boolean indicating if value is within maximum length
|
|
110
|
-
*/
|
|
111
|
-
export const validateMaxLength = (value: string, maxLength: number): boolean => {
|
|
112
|
-
if (!value || typeof value !== 'string') return true; // Empty is valid for max check
|
|
113
|
-
return value.trim().length <= maxLength;
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* RUT (Chilean ID) validation
|
|
118
|
-
*/
|
|
119
|
-
export const validateRut = (rut: string): boolean => {
|
|
120
|
-
if (!rut || typeof rut !== 'string') return false;
|
|
121
|
-
|
|
122
|
-
// Clean the RUT
|
|
123
|
-
const cleanRut = rut.replace(/[.-]/g, '').toUpperCase();
|
|
124
|
-
|
|
125
|
-
if (cleanRut.length < 2) return false;
|
|
126
|
-
|
|
127
|
-
const body = cleanRut.slice(0, -1);
|
|
128
|
-
const dv = cleanRut.slice(-1);
|
|
129
|
-
|
|
130
|
-
// Calculate verification digit
|
|
131
|
-
let sum = 0;
|
|
132
|
-
let multiplier = 2;
|
|
133
|
-
|
|
134
|
-
for (let i = body.length - 1; i >= 0; i--) {
|
|
135
|
-
sum += parseInt(body[i], 10) * multiplier;
|
|
136
|
-
multiplier = multiplier === 7 ? 2 : multiplier + 1;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const calculatedDv = 11 - (sum % 11);
|
|
140
|
-
let expectedDv: string;
|
|
141
|
-
|
|
142
|
-
if (calculatedDv === 11) expectedDv = '0';
|
|
143
|
-
else if (calculatedDv === 10) expectedDv = 'K';
|
|
144
|
-
else expectedDv = calculatedDv.toString();
|
|
145
|
-
|
|
146
|
-
return dv === expectedDv;
|
|
147
|
-
};
|