| 1 |
import { parseCssClassList } from '@/utils/form-styles/classParser' |
| 2 |
|
| 3 |
export interface FormStyleSelectors { |
| 4 |
formSelector: string |
| 5 |
wrapperSelector: string |
| 6 |
customClassName: string |
| 7 |
customClass: string |
| 8 |
baseSelector: string |
| 9 |
} |
| 10 |
|
| 11 |
export function normalizeFormScopeToken(formId: string | number): string { |
| 12 |
const normalized = String(formId) |
| 13 |
.trim() |
| 14 |
.replace(/[^a-zA-Z0-9_-]+/g, '-') |
| 15 |
.replace(/-+/g, '-') |
| 16 |
.replace(/^-|-$/g, '') |
| 17 |
|
| 18 |
return normalized || 'default' |
| 19 |
} |
| 20 |
|
| 21 |
export function buildFormPopperScopeClass(formId: string | number): string { |
| 22 |
return `ivyforms-form-popper-${normalizeFormScopeToken(formId)}` |
| 23 |
} |
| 24 |
|
| 25 |
export function buildFormStyleSelectors( |
| 26 |
formId: string | number, |
| 27 |
customCssClass?: string, |
| 28 |
): FormStyleSelectors { |
| 29 |
const normalizedFormId = normalizeFormScopeToken(formId) |
| 30 |
const formSelector = `.ivyforms-form-${normalizedFormId}` |
| 31 |
const wrapperSelector = `.ivyforms-form-wrapper-${normalizedFormId}` |
| 32 |
const customClassName = parseCssClassList(customCssClass)[0] || '' |
| 33 |
const customClass = customClassName ? `.${customClassName}` : '' |
| 34 |
const baseSelector = customClass ? `${wrapperSelector}${customClass}` : wrapperSelector |
| 35 |
|
| 36 |
return { |
| 37 |
formSelector, |
| 38 |
wrapperSelector, |
| 39 |
customClassName, |
| 40 |
customClass, |
| 41 |
baseSelector, |
| 42 |
} |
| 43 |
} |
| 44 |
|