@kinetis/vector-ui 0.10.1 → 0.10.3

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.
Files changed (80) hide show
  1. package/CHANGELOG.md +88 -0
  2. package/app/components/Vx/Action/Dialog.vue +15 -9
  3. package/app/components/Vx/Cell/RichText.vue +1 -1
  4. package/app/components/Vx/Import/Dialog.vue +14 -3
  5. package/app/components/Vx/Inbox.vue +10 -3
  6. package/app/components/Vx/Input/KeyValue.vue +9 -4
  7. package/app/components/Vx/Input/Number.vue +2 -1
  8. package/app/components/Vx/Input/Relation.vue +15 -5
  9. package/app/components/Vx/Input/Repeater.vue +15 -5
  10. package/app/components/Vx/Input/RichText.vue +2 -2
  11. package/app/components/Vx/Input/Upload.vue +5 -3
  12. package/app/components/Vx/List/BulkEdit.vue +5 -5
  13. package/app/components/Vx/List/FilterBar.vue +14 -10
  14. package/app/components/Vx/Resource/Audit.vue +4 -1
  15. package/app/components/Vx/Resource/Form.vue +23 -8
  16. package/app/components/Vx/Resource/RelationPanel.vue +2 -1
  17. package/app/components/Vx/Resource/Table.vue +32 -15
  18. package/app/components/Vx/Widget/Card.vue +2 -1
  19. package/app/components/Vx/Widget/Table.vue +22 -4
  20. package/app/components/Vx/Widget/Trend.vue +1 -1
  21. package/app/composables/useVectorApi.ts +70 -14
  22. package/app/composables/useVectorAuthStore.ts +32 -7
  23. package/app/composables/useVectorBranding.ts +1 -1
  24. package/app/composables/useVectorExtensions.ts +1 -1
  25. package/app/composables/useVectorFields.ts +7 -1
  26. package/app/composables/useVectorForm.ts +8 -3
  27. package/app/composables/useVectorIdle.ts +3 -1
  28. package/app/composables/useVectorImpersonation.ts +11 -11
  29. package/app/composables/useVectorInputs.ts +6 -6
  30. package/app/composables/useVectorJobs.ts +6 -3
  31. package/app/composables/useVectorLocale.ts +3 -5
  32. package/app/composables/useVectorResource.ts +37 -32
  33. package/app/composables/useVectorSchema.ts +9 -1
  34. package/app/i18n/ar/actions.ts +1 -0
  35. package/app/i18n/ar/shell.ts +3 -0
  36. package/app/i18n/de/actions.ts +1 -0
  37. package/app/i18n/de/shell.ts +3 -0
  38. package/app/i18n/en/actions.ts +1 -0
  39. package/app/i18n/en/shell.ts +3 -0
  40. package/app/i18n/es/actions.ts +1 -0
  41. package/app/i18n/es/shell.ts +3 -0
  42. package/app/i18n/fr/actions.ts +1 -0
  43. package/app/i18n/fr/shell.ts +3 -0
  44. package/app/i18n/he/actions.ts +1 -0
  45. package/app/i18n/he/shell.ts +3 -0
  46. package/app/i18n/index.ts +15 -1
  47. package/app/i18n/it/actions.ts +1 -0
  48. package/app/i18n/it/shell.ts +3 -0
  49. package/app/i18n/ja/actions.ts +1 -0
  50. package/app/i18n/ja/shell.ts +3 -0
  51. package/app/i18n/ko/actions.ts +1 -0
  52. package/app/i18n/ko/shell.ts +3 -0
  53. package/app/i18n/nl/actions.ts +1 -0
  54. package/app/i18n/nl/shell.ts +3 -0
  55. package/app/i18n/pl/actions.ts +1 -0
  56. package/app/i18n/pl/shell.ts +3 -0
  57. package/app/i18n/pt/actions.ts +1 -0
  58. package/app/i18n/pt/shell.ts +3 -0
  59. package/app/i18n/pt-BR/actions.ts +1 -0
  60. package/app/i18n/pt-BR/shell.ts +3 -0
  61. package/app/i18n/ru/actions.ts +1 -0
  62. package/app/i18n/ru/shell.ts +3 -0
  63. package/app/i18n/tr/actions.ts +1 -0
  64. package/app/i18n/tr/shell.ts +3 -0
  65. package/app/i18n/uk/actions.ts +1 -0
  66. package/app/i18n/uk/shell.ts +3 -0
  67. package/app/i18n/zh-Hans/actions.ts +1 -0
  68. package/app/i18n/zh-Hans/shell.ts +3 -0
  69. package/app/pages/jobs/index.vue +18 -4
  70. package/app/pages/login.vue +11 -4
  71. package/app/pages/settings.vue +4 -3
  72. package/app/plugins/vector-extensions.client.ts +1 -1
  73. package/app/plugins/vector-i18n.ts +2 -2
  74. package/app/utils/files.ts +5 -2
  75. package/app/utils/internal/paths.ts +12 -0
  76. package/app/utils/internal/patterns.ts +50 -0
  77. package/app/utils/internal/violations.ts +26 -0
  78. package/app/utils/richtext.ts +2 -2
  79. package/app/utils/rules.ts +2 -12
  80. package/package.json +1 -1
@@ -7,6 +7,7 @@ export default {
7
7
  subjectCount: '{count} {label}',
8
8
  done: '{label} tamamlandı.',
9
9
  declined: 'Eylem reddedildi.',
10
+ redirectRefused: 'Eylem, yönetim paneli dışında bir sayfa açmak istedi; sayfa açılmadı.',
10
11
  downloadStarted: 'İndirme başladı.',
11
12
  queued: '{label} kuyruğa alındı.',
12
13
  }
@@ -8,6 +8,7 @@ export default {
8
8
  toggleTheme: 'Temayı değiştir',
9
9
  language: 'Dil: {name}',
10
10
  languageFailed: 'Dil kaydedilemedi: {error}',
11
+ unsupportedDescriptor: 'API, tanımlayıcı sürümü {version} yayımlıyor; bu yönetim paneli sürüm {supported} okuyor. kinetis/vector ve vector-ui için uyumlu sürümleri yükleyin.',
11
12
  nav: {
12
13
  main: 'Ana',
13
14
  dashboard: 'Pano',
@@ -26,6 +27,7 @@ export default {
26
27
  stop: 'Kimliğine bürünmeyi bitir',
27
28
  noAccess: '{name} yönetim paneline erişemiyor, bu yüzden onun gözünden görülecek bir şey yok. Kimliğine bürünme sonlandırıldı.',
28
29
  noToken: 'Uygulama belirteç veya yeniden yükleme olmadan yanıt verdi; hiçbir şey değişmedi.',
30
+ ended: 'Kimliğe bürünme süresi doldu; kendi hesabınıza geri döndünüz.',
29
31
  },
30
32
  palette: {
31
33
  placeholder: 'Kayıt ve kaynak ara…',
@@ -47,6 +49,7 @@ export default {
47
49
  invalidEmail: 'Geçerli bir e-posta adresi girin',
48
50
  welcome: 'Tekrar hoş geldiniz, {name}.',
49
51
  signedOutIdle: '{minutes} dakika boyunca işlem yapılmadığı için oturumunuz kapatıldı. Kaldığınız yerden devam etmek için yeniden giriş yapın.',
52
+ impersonationEnded: 'Kimliğe bürünme süresi doldu ve kendi oturumunuz yenilenemedi. Devam etmek için yeniden oturum açın.',
50
53
  },
51
54
  home: {
52
55
  title: 'Pano',
@@ -7,6 +7,7 @@ export default {
7
7
  subjectCount: '{count} {label}',
8
8
  done: '{label}: виконано.',
9
9
  declined: 'Дію відхилено.',
10
+ redirectRefused: 'Дія намагалася відкрити сторінку поза панеллю; її не відкрито.',
10
11
  downloadStarted: 'Завантаження розпочато.',
11
12
  queued: '{label}: додано до черги.',
12
13
  }
@@ -8,6 +8,7 @@ export default {
8
8
  toggleTheme: 'Перемкнути тему',
9
9
  language: 'Мова: {name}',
10
10
  languageFailed: 'Не вдалося зберегти мову: {error}',
11
+ unsupportedDescriptor: 'API публікує дескриптор версії {version}, а ця панель читає версію {supported}. Установіть сумісні випуски kinetis/vector і vector-ui.',
11
12
  nav: {
12
13
  main: 'Головне',
13
14
  dashboard: 'Панель керування',
@@ -26,6 +27,7 @@ export default {
26
27
  stop: 'Повернутися до свого облікового запису',
27
28
  noAccess: '{name} не має доступу до адмінпанелі, тож від цього імені нічого не видно. Дію від імені користувача припинено.',
28
29
  noToken: 'Застосунок відповів без токена й без перезавантаження, тож нічого не змінилося.',
30
+ ended: 'Термін роботи від імені іншого користувача сплив, ви знову у своєму обліковому записі.',
29
31
  },
30
32
  palette: {
31
33
  placeholder: 'Пошук записів і ресурсів…',
@@ -47,6 +49,7 @@ export default {
47
49
  invalidEmail: 'Введіть дійсну адресу електронної пошти',
48
50
  welcome: 'З поверненням, {name}.',
49
51
  signedOutIdle: 'Сеанс завершено після {minutes} хвилин бездіяльності. Увійдіть знову, щоб продовжити з того самого місця.',
52
+ impersonationEnded: 'Термін роботи від імені іншого користувача сплив, а ваш власний сеанс не вдалося продовжити. Увійдіть знову, щоб продовжити.',
50
53
  },
51
54
  home: {
52
55
  title: 'Панель керування',
@@ -7,6 +7,7 @@ export default {
7
7
  subjectCount: '{count} 个{label}',
8
8
  done: '{label}已完成。',
9
9
  declined: '该操作已被拒绝。',
10
+ redirectRefused: '该操作要求打开管理后台之外的页面,未予打开。',
10
11
  downloadStarted: '已开始下载。',
11
12
  queued: '{label}已加入队列。',
12
13
  }
@@ -8,6 +8,7 @@ export default {
8
8
  toggleTheme: '切换主题',
9
9
  language: '语言:{name}',
10
10
  languageFailed: '无法保存语言:{error}',
11
+ unsupportedDescriptor: 'API 发布的描述符版本为 {version},而此管理界面读取版本 {supported}。请安装相互匹配的 kinetis/vector 和 vector-ui 版本。',
11
12
  nav: {
12
13
  main: '主菜单',
13
14
  dashboard: '仪表盘',
@@ -26,6 +27,7 @@ export default {
26
27
  stop: '停止模拟登录',
27
28
  noAccess: '{name} 无权访问管理后台,因此无法以其身份查看任何内容。模拟登录已停止。',
28
29
  noToken: '应用返回的响应中既没有令牌也没有重新加载,因此未做任何更改。',
30
+ ended: '模拟身份已过期,你已回到自己的账户。',
29
31
  },
30
32
  palette: {
31
33
  placeholder: '搜索记录和资源…',
@@ -47,6 +49,7 @@ export default {
47
49
  invalidEmail: '请输入有效的电子邮件地址',
48
50
  welcome: '欢迎回来,{name}。',
49
51
  signedOutIdle: '由于 {minutes} 分钟内没有操作,你已被登出。重新登录即可从上次离开的地方继续。',
52
+ impersonationEnded: '模拟身份已过期,且无法续期你自己的会话。请重新登录以继续。',
50
53
  },
51
54
  home: {
52
55
  title: '仪表盘',
@@ -6,7 +6,7 @@ definePageMeta({ layout: 'vector', middleware: 'vector-auth' })
6
6
  const appConfig = useAppConfig()
7
7
  const jobs = useVectorJobs()
8
8
  const { t } = useVectorT()
9
- const { data, refresh } = await useAsyncData('vector.jobs', () => jobs.list())
9
+ const { data, error, refresh } = await useAsyncData('vector.jobs', () => jobs.list())
10
10
  const running = computed(() => (data.value ?? []).some(j => j.status === 'queued' || j.status === 'running'))
11
11
  const { pause, resume } = useIntervalFn(() => refresh(), 3000, { immediate: false })
12
12
  watch(running, r => (r ? resume() : pause()), { immediate: true })
@@ -14,19 +14,33 @@ onUnmounted(pause)
14
14
 
15
15
  useHead({ title: () => t('jobs.title') })
16
16
 
17
+ function open(job: VectorJob) {
18
+ navigateTo(`${appConfig.vector.basePath}/jobs/${job.id}`)
19
+ }
20
+
17
21
  const color: Record<VectorJob['status'], string> = { queued: 'grey', running: 'info', done: 'success', failed: 'error', stalled: 'warning' }
18
22
  </script>
19
23
 
20
24
  <template>
21
25
  <div>
22
26
  <h1 class="text-h4 mb-4">{{ t('jobs.heading') }}</h1>
27
+ <v-alert v-if="error" type="error" variant="tonal" class="mb-4" :text="vectorErrorMessage(error)" />
23
28
  <v-card>
24
29
  <v-table hover>
25
30
  <thead>
26
- <tr><th>{{ t('jobs.columns.job') }}</th><th>{{ t('jobs.columns.resource') }}</th><th>{{ t('jobs.columns.status') }}</th><th class="text-end">{{ t('jobs.columns.progress') }}</th><th>{{ t('jobs.columns.started') }}</th><th /></tr>
31
+ <tr><th scope="col">{{ t('jobs.columns.job') }}</th><th scope="col">{{ t('jobs.columns.resource') }}</th><th scope="col">{{ t('jobs.columns.status') }}</th><th scope="col" class="text-end">{{ t('jobs.columns.progress') }}</th><th scope="col">{{ t('jobs.columns.started') }}</th><th scope="col" /></tr>
27
32
  </thead>
28
33
  <tbody>
29
- <tr v-for="job in data ?? []" :key="job.id" style="cursor: pointer" @click="navigateTo(`${appConfig.vector.basePath}/jobs/${job.id}`)">
34
+ <tr
35
+ v-for="job in data ?? []"
36
+ :key="job.id"
37
+ style="cursor: pointer"
38
+ tabindex="0"
39
+ role="link"
40
+ @click="open(job)"
41
+ @keydown.enter.self.prevent="open(job)"
42
+ @keydown.space.self.prevent="open(job)"
43
+ >
30
44
  <td><span class="text-capitalize">{{ t(`jobs.kind.${job.kind}`) }}</span> <span class="text-medium-emphasis">{{ job.name }}</span></td>
31
45
  <td>{{ job.resource }}</td>
32
46
  <td><v-chip size="small" :color="color[job.status]" variant="tonal">{{ t(`jobs.status.${job.status}`) }}</v-chip></td>
@@ -34,7 +48,7 @@ const color: Record<VectorJob['status'], string> = { queued: 'grey', running: 'i
34
48
  <td>{{ formatDateTime(job.createdAt) }}</td>
35
49
  <td class="text-end"><v-btn v-if="job.hasFile && job.status === 'done'" size="small" variant="text" icon="mdi-download-outline" :aria-label="t('common.download')" @click.stop="jobs.download(job)" /></td>
36
50
  </tr>
37
- <tr v-if="(data ?? []).length === 0"><td colspan="6" class="text-medium-emphasis">{{ t('jobs.empty') }}</td></tr>
51
+ <tr v-if="!error && (data ?? []).length === 0"><td colspan="6" class="text-medium-emphasis">{{ t('jobs.empty') }}</td></tr>
38
52
  </tbody>
39
53
  </v-table>
40
54
  </v-card>
@@ -1,5 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import type { SubmitEventPromise } from 'vuetify'
3
+ import { hasEmailShape } from '#vector/app/utils/internal/patterns'
4
+ import { isAdminPath } from '#vector/app/utils/internal/paths'
3
5
 
4
6
  definePageMeta({ layout: 'default' })
5
7
 
@@ -14,11 +16,16 @@ const password = ref('')
14
16
  const submitting = ref(false)
15
17
  const error = ref<string | null>(null)
16
18
  // why the last session ended, when the admin ended it itself
17
- const notice = computed(() => route.query.reason === 'idle' ? t('shell.login.signedOutIdle', { minutes: appConfig.vector.idleMinutes }) : null)
19
+ const notice = computed(() => {
20
+ if (route.query.reason === 'idle') return t('shell.login.signedOutIdle', { minutes: appConfig.vector.idleMinutes })
21
+ if (route.query.reason === 'impersonation') return t('shell.login.impersonationEnded')
22
+
23
+ return null
24
+ })
18
25
 
19
26
  const rules = {
20
27
  required: (value: string) => value.trim() !== '' || t('common.required'),
21
- email: (value: string) => /.+@.+\..+/.test(value) || t('shell.login.invalidEmail'),
28
+ email: (value: string) => hasEmailShape(value) || t('shell.login.invalidEmail'),
22
29
  }
23
30
 
24
31
  const runtime = useVectorRuntime()
@@ -60,9 +67,9 @@ async function submit(event: SubmitEventPromise) {
60
67
 
61
68
  notifications.success(t('shell.login.welcome', { name: auth.user?.name ?? email.value }))
62
69
 
63
- // only a path of this app: `//host`, `/\host` and anything with a scheme are not places to go back to
70
+ // only a path of this app: `//host`, `/\host`, `/\t/host` and anything with a scheme are not places to go back to
64
71
  const wanted = typeof route.query.redirect === 'string' ? route.query.redirect : ''
65
- const redirect = /^\/(?![/\\])/.test(wanted) ? wanted : (appConfig.vector.basePath || '/')
72
+ const redirect = isAdminPath(wanted) ? wanted : (appConfig.vector.basePath || '/')
66
73
  await navigateTo(redirect, { replace: true })
67
74
  } catch (caught) {
68
75
  error.value = vectorErrorMessage(caught)
@@ -14,7 +14,7 @@ const { load: loadSchema } = useVectorSchema()
14
14
 
15
15
  // fetched again in a new language, whose labels the server translates
16
16
  const { current: locale } = useVectorLocale()
17
- const { data, refresh } = await useAsyncData('vector.settings', () => api<{ data: VectorSettingsGroup[] }>('/vector/settings'), { watch: [locale] })
17
+ const { data, error, refresh } = await useAsyncData('vector.settings', () => api<{ data: VectorSettingsGroup[] }>('/vector/settings'), { watch: [locale] })
18
18
  // Vector's own Languages group: each language keeps its own name, with its name in the admin's language beneath
19
19
  const groups = computed(() => (data.value?.data ?? []).map(group => group.name === 'languages' ? withLanguageNames(group, locale.value) : group))
20
20
  // what each group held when it was loaded: a group edited since keeps its edits when the page is fetched again
@@ -79,8 +79,9 @@ function withLanguageNames(group: VectorSettingsGroup, inLanguage: string): Vect
79
79
  <template>
80
80
  <div>
81
81
  <h1 class="text-h4 mb-4">{{ t('settings.heading') }}</h1>
82
- <v-empty-state v-if="groups.length === 0" icon="mdi-cog-off-outline" :title="t('settings.empty.title')" :text="t('settings.empty.text')" />
83
- <v-card v-else>
82
+ <v-alert v-if="error" type="error" variant="tonal" class="mb-4" :text="vectorErrorMessage(error)" />
83
+ <v-empty-state v-if="!error && groups.length === 0" icon="mdi-cog-off-outline" :title="t('settings.empty.title')" :text="t('settings.empty.text')" />
84
+ <v-card v-else-if="groups.length > 0">
84
85
  <v-tabs v-model="tab" color="primary">
85
86
  <v-tab v-for="group in groups" :key="group.name" :value="group.name" :prepend-icon="group.icon ?? undefined">{{ group.label }}</v-tab>
86
87
  </v-tabs>
@@ -56,7 +56,7 @@ export default defineNuxtPlugin(() => {
56
56
 
57
57
  const urls = [...(window.__VECTOR__?.extensions ?? []), ...((config.public.vector as { extensions?: string[] }).extensions ?? [])]
58
58
 
59
- Promise.allSettled(urls.map(url => import(/* @vite-ignore */ url)
59
+ void Promise.allSettled(urls.map(url => import(/* @vite-ignore */ url)
60
60
  .then(module => (typeof module.default === 'function' ? module.default(api) : undefined))
61
61
  .catch(error => console.error(`Vector extension ${url} failed to load`, error))))
62
62
  .then(() => { registries.ready.value = true })
@@ -1,6 +1,6 @@
1
1
  import { createI18n } from 'vue-i18n'
2
2
  import type { VectorI18n } from '#vector/app/utils/translate'
3
- import { bundledMessages, isRtl, pluralRule, rtlLanguages, vuetifyLocale } from '#vector/app/i18n'
3
+ import { bundledMessages, isRtl, knownVuetifyLocale, pluralRule, rtlLanguages } from '#vector/app/i18n'
4
4
 
5
5
  /**
6
6
  * The admin's own strings, translated through vue-i18n, in the language
@@ -61,7 +61,7 @@ export default defineNuxtPlugin({
61
61
  nuxtApp.hook('vuetify:before-create', async ({ vuetifyOptions }) => {
62
62
  const all = await import('vuetify/locale') as Record<string, unknown>
63
63
  const messages = Object.fromEntries(Object.entries(all).filter(([, value]) => value && typeof value === 'object' && !Array.isArray(value)))
64
- const current = messages[vuetifyLocale(locale)] ? vuetifyLocale(locale) : (messages[locale.split('-')[0]!] ? locale.split('-')[0]! : 'en')
64
+ const current = knownVuetifyLocale(locale, messages)
65
65
  vuetifyOptions.locale = {
66
66
  ...(typeof vuetifyOptions.locale === 'object' ? vuetifyOptions.locale : {}),
67
67
  locale: current,
@@ -7,8 +7,11 @@
7
7
  export function dataUrl(blob: Blob): Promise<string> {
8
8
  return new Promise((resolve, reject) => {
9
9
  const reader = new FileReader()
10
- reader.onload = () => resolve(String(reader.result))
11
- reader.onerror = () => reject(reader.error)
10
+ reader.onload = () => {
11
+ if (typeof reader.result === 'string') resolve(reader.result)
12
+ else reject(new Error('The file was not read as a data URL'))
13
+ }
14
+ reader.onerror = () => reject(reader.error ?? new Error('The file could not be read'))
12
15
  reader.readAsDataURL(blob)
13
16
  })
14
17
  }
@@ -0,0 +1,12 @@
1
+ // Where a server-supplied path may send the browser. Nested under utils/
2
+ // so Nuxt does not auto-import it: it is not part of the layer's public API.
3
+
4
+ /**
5
+ * A path of this admin, and nothing a browser would read as another
6
+ * origin: one leading `/` not followed by `/` or `\` (`//host`, `/\host`),
7
+ * no scheme, and no backslash, whitespace or control character anywhere —
8
+ * a browser strips tab, CR and LF from a URL, so `/\t/host` is `//host`.
9
+ */
10
+ export function isAdminPath(path: string): boolean {
11
+ return /^\/(?![/\\])/.test(path) && !/[\\\s\p{Cc}]/u.test(path)
12
+ }
@@ -0,0 +1,50 @@
1
+ // Linear-time scans the form rules use in place of backtracking regular
2
+ // expressions. Nested under utils/ so Nuxt does not auto-import them:
3
+ // they are not part of the layer's public API.
4
+
5
+ /**
6
+ * An e-mail address as the Email rule takes it: no whitespace, one `@`
7
+ * with text before it, and a domain with a dot that has text on both
8
+ * sides. Scanned, not matched, so a long input costs linear time.
9
+ */
10
+ export function isEmailAddress(value: string): boolean {
11
+ if (/\s/.test(value)) return false
12
+
13
+ const at = value.indexOf('@')
14
+
15
+ if (at < 1 || value.includes('@', at + 1)) return false
16
+
17
+ const domain = value.slice(at + 1)
18
+
19
+ return domain.lastIndexOf('.', domain.length - 2) >= 1
20
+ }
21
+
22
+ /**
23
+ * The sign-in form's looser check: somewhere on one line, text, an `@`,
24
+ * text, a dot and text again.
25
+ */
26
+ export function hasEmailShape(value: string): boolean {
27
+ return value.split(/[\n\r\u2028\u2029]/).some((line) => {
28
+ const at = line.indexOf('@', 1)
29
+
30
+ return at !== -1 && line.lastIndexOf('.', line.length - 2) >= at + 2
31
+ })
32
+ }
33
+
34
+ /**
35
+ * A PCRE pattern with its delimiters and flags, as the framework's Regex
36
+ * constraint takes it, as a JavaScript RegExp: the first character is the
37
+ * delimiter, its last occurrence closes the pattern, and only letters may
38
+ * follow it. Anything else is taken as a bare pattern.
39
+ */
40
+ export function phpRegex(pattern: string): RegExp {
41
+ const delimiter = pattern.charAt(0)
42
+ const end = pattern.lastIndexOf(delimiter)
43
+ const modifiers = pattern.slice(end + 1)
44
+
45
+ if (end < 1 || '\n\r\u2028\u2029'.includes(delimiter) || !/^[a-zA-Z]*$/.test(modifiers)) return new RegExp(pattern)
46
+
47
+ const flags = [...modifiers].filter(f => 'gimsuy'.includes(f)).join('')
48
+
49
+ return new RegExp(pattern.slice(1, end), flags)
50
+ }
@@ -0,0 +1,26 @@
1
+ // The entries of the framework's 422 document. Nested under utils/ so
2
+ // Nuxt does not auto-import them: they are not part of the layer's public API.
3
+
4
+ /** One segment of a violation's path: a field or key name, or a list index. */
5
+ export type ViolationSegment = string | number
6
+
7
+ /** One entry of a 422 document's `errors`, as the framework writes it (it adds a `code` and `parameters`). */
8
+ export interface Violation {
9
+ path: ViolationSegment[]
10
+ message: string
11
+ }
12
+
13
+ /** Whether an `errors` entry is a violation: a list of names and indexes for `path`, and a `message`. Anything else is ignored. */
14
+ export function isViolation(entry: unknown): entry is Violation {
15
+ const candidate = entry as { path?: unknown, message?: unknown } | null
16
+
17
+ return typeof candidate === 'object' && candidate !== null
18
+ && typeof candidate.message === 'string'
19
+ && Array.isArray(candidate.path)
20
+ && candidate.path.every(s => typeof s === 'string' || Number.isInteger(s))
21
+ }
22
+
23
+ /** The violations of a 422 document's `errors`, malformed entries left out; none when it is not a list. */
24
+ export function violationsOf(errors: unknown): Violation[] {
25
+ return Array.isArray(errors) ? errors.filter(isViolation) : []
26
+ }
@@ -108,7 +108,7 @@ function vectorImage(imageSource?: (key: string) => Promise<string | null>): Any
108
108
  return ['img', { ...rest, 'data-vector-key': src }]
109
109
  },
110
110
  parseHTML() {
111
- return [{ tag: 'img[src]' }, { tag: 'img[data-vector-key]', getAttrs: element => ({ src: (element as HTMLElement).getAttribute('data-vector-key') }) }]
111
+ return [{ tag: 'img[src]' }, { tag: 'img[data-vector-key]', getAttrs: element => ({ src: (element as HTMLElement).dataset.vectorKey ?? null }) }]
112
112
  },
113
113
  addNodeView() {
114
114
  return ({ node }) => {
@@ -116,7 +116,7 @@ function vectorImage(imageSource?: (key: string) => Promise<string | null>): Any
116
116
  img.alt = String(node.attrs.alt ?? '')
117
117
  img.className = 'vx-richtext-image'
118
118
  const key = String(node.attrs.src ?? '')
119
- img.setAttribute('data-vector-key', key)
119
+ img.dataset.vectorKey = key
120
120
  imageSource?.(key).then((url) => {
121
121
  if (url) img.src = url
122
122
  }).catch(() => undefined)
@@ -1,4 +1,5 @@
1
1
  import type { VectorCondition, VectorField, VectorFieldState, VectorRule } from '#vector/app/types/vector'
2
+ import { isEmailAddress, phpRegex } from '#vector/app/utils/internal/patterns'
2
3
 
3
4
  type Rule = (value: unknown) => true | string
4
5
 
@@ -41,7 +42,7 @@ function compile(rule: VectorRule): Rule | null {
41
42
  case 'MinLength':
42
43
  return value => empty(value) || typeof value !== 'string' || [...value].length >= Number(a) || vt('fields.rules.minLength', { min: String(a) })
43
44
  case 'Email':
44
- return value => empty(value) || (typeof value === 'string' && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)) || vt('fields.rules.email')
45
+ return value => empty(value) || (typeof value === 'string' && isEmailAddress(value)) || vt('fields.rules.email')
45
46
  case 'Url':
46
47
  case 'WebUrl':
47
48
  return value => empty(value) || (typeof value === 'string' && /^https?:\/\/\S+$/i.test(value)) || vt('fields.rules.url')
@@ -62,17 +63,6 @@ function compile(rule: VectorRule): Rule | null {
62
63
  }
63
64
  }
64
65
 
65
- /** A PCRE pattern with its delimiters and flags, as the framework's Regex constraint takes it, as a JavaScript RegExp. */
66
- function phpRegex(pattern: string): RegExp {
67
- const match = pattern.match(/^(.)([\s\S]*)\1([a-zA-Z]*)$/)
68
-
69
- if (!match) return new RegExp(pattern)
70
-
71
- const flags = [...match[3]!].filter(f => 'gimsuy'.includes(f)).join('')
72
-
73
- return new RegExp(match[2]!, flags)
74
- }
75
-
76
66
  /**
77
67
  * What a field's conditions decide under the form's current values: the
78
68
  * server evaluates the same conditions the same way, comparing a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kinetis/vector-ui",
3
- "version": "0.10.1",
3
+ "version": "0.10.3",
4
4
  "description": "The Kinetis Vector admin UI, as a Nuxt layer on Vuetify.",
5
5
  "keywords": [
6
6
  "kinetis",