This commit is contained in:
@@ -76,12 +76,16 @@ export const AuthProvider: Component<AuthProviderProps> = (props) => {
|
|||||||
// Инициализация авторизации при монтировании
|
// Инициализация авторизации при монтировании
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
console.log('[AuthProvider] Performing auth initialization...')
|
console.log('[AuthProvider] Performing auth initialization...')
|
||||||
|
console.log('[AuthProvider] Checking localStorage token:', !!localStorage.getItem(AUTH_TOKEN_KEY))
|
||||||
|
console.log('[AuthProvider] Checking cookie token:', !!getAuthTokenFromCookie())
|
||||||
|
console.log('[AuthProvider] Checking CSRF token:', !!getCsrfTokenFromCookie())
|
||||||
|
|
||||||
// Небольшая задержка для завершения других инициализаций
|
// Небольшая задержка для завершения других инициализаций
|
||||||
await new Promise((resolve) => setTimeout(resolve, 100))
|
await new Promise((resolve) => setTimeout(resolve, 100))
|
||||||
|
|
||||||
// Проверяем текущее состояние авторизации
|
// Проверяем текущее состояние авторизации
|
||||||
const authStatus = checkAuthStatus()
|
const authStatus = checkAuthStatus()
|
||||||
|
console.log('[AuthProvider] Final auth status after check:', authStatus)
|
||||||
setIsAuthenticated(authStatus)
|
setIsAuthenticated(authStatus)
|
||||||
|
|
||||||
console.log('[AuthProvider] Auth initialization complete, ready for requests')
|
console.log('[AuthProvider] Auth initialization complete, ready for requests')
|
||||||
|
@@ -191,8 +191,11 @@ const HTMLEditor = (props: HTMLEditorProps) => {
|
|||||||
const value = props.value || ''
|
const value = props.value || ''
|
||||||
|
|
||||||
if (value.trim()) {
|
if (value.trim()) {
|
||||||
|
// Форматируем HTML перед экранированием
|
||||||
|
const formattedValue = formatHTML(value)
|
||||||
|
|
||||||
// Экранируем HTML для безопасности
|
// Экранируем HTML для безопасности
|
||||||
const escapedValue = value
|
const escapedValue = formattedValue
|
||||||
.replace(/&/g, '&')
|
.replace(/&/g, '&')
|
||||||
.replace(/</g, '<')
|
.replace(/</g, '<')
|
||||||
.replace(/>/g, '>')
|
.replace(/>/g, '>')
|
||||||
@@ -334,16 +337,47 @@ const HTMLEditor = (props: HTMLEditorProps) => {
|
|||||||
|
|
||||||
const formatHTML = (html: string): string => {
|
const formatHTML = (html: string): string => {
|
||||||
try {
|
try {
|
||||||
// Простое форматирование с отступами
|
if (!html.trim()) return html
|
||||||
const lines = html.split(/\n/)
|
|
||||||
const formattedLines = lines.map((line, index) => {
|
// Функция для форматирования HTML с правильными отступами
|
||||||
const trimmedLine = line.trim()
|
const formatHTMLString = (str: string): string => {
|
||||||
if (trimmedLine.startsWith('<') && !trimmedLine.startsWith('</')) {
|
let formatted = ''
|
||||||
return ' '.repeat(index > 0 ? 1 : 0) + trimmedLine
|
let indent = 0
|
||||||
|
const indentStr = ' ' // 2 пробела для отступа
|
||||||
|
|
||||||
|
// Разбиваем на токены (теги и текст)
|
||||||
|
const tokens = str.match(/<\/?[^>]*>|[^<]+/g) || []
|
||||||
|
|
||||||
|
for (let i = 0; i < tokens.length; i++) {
|
||||||
|
const token = tokens[i].trim()
|
||||||
|
if (!token) continue
|
||||||
|
|
||||||
|
if (token.startsWith('</')) {
|
||||||
|
// Закрывающий тег - уменьшаем отступ
|
||||||
|
indent--
|
||||||
|
formatted += indentStr.repeat(Math.max(0, indent)) + token + '\n'
|
||||||
|
} else if (token.startsWith('<') && token.endsWith('>')) {
|
||||||
|
// Открывающий тег
|
||||||
|
const isSelfClosing = token.endsWith('/>') ||
|
||||||
|
/^<(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)(\s|>)/i.test(token)
|
||||||
|
|
||||||
|
formatted += indentStr.repeat(indent) + token + '\n'
|
||||||
|
|
||||||
|
if (!isSelfClosing) {
|
||||||
|
indent++
|
||||||
}
|
}
|
||||||
return trimmedLine
|
} else {
|
||||||
})
|
// Текстовое содержимое
|
||||||
return formattedLines.join('\n')
|
if (token.length > 0) {
|
||||||
|
formatted += indentStr.repeat(indent) + token + '\n'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return formatted.trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
return formatHTMLString(html)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn('HTML formatting error:', error)
|
console.warn('HTML formatting error:', error)
|
||||||
return html
|
return html
|
||||||
|
Reference in New Issue
Block a user