@antelopejs/dms-lang 0.0.6 → 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/README.md +12 -6
- package/dist/pages/actions.d.ts +7 -0
- package/dist/pages/actions.js +15 -0
- package/dist/pages/actions.js.map +1 -0
- package/dist/pages/component-action.d.ts +2 -0
- package/dist/pages/component-action.js +10 -0
- package/dist/pages/component-action.js.map +1 -0
- package/dist/pages/header-actions.d.ts +9 -0
- package/dist/pages/header-actions.js +146 -0
- package/dist/pages/header-actions.js.map +1 -0
- package/dist/pages/index.d.ts +6 -0
- package/dist/pages/index.js +6 -0
- package/dist/pages/index.js.map +1 -1
- package/dist/pages/language.d.ts +10 -0
- package/dist/pages/language.js +89 -0
- package/dist/pages/language.js.map +1 -0
- package/dist/pages/languages-table.d.ts +2 -0
- package/dist/pages/languages-table.js +120 -0
- package/dist/pages/languages-table.js.map +1 -0
- package/dist/pages/module.d.ts +7 -1
- package/dist/pages/module.js +28 -2
- package/dist/pages/module.js.map +1 -1
- package/dist/pages/overview.d.ts +2 -1
- package/dist/pages/overview.js +83 -8
- package/dist/pages/overview.js.map +1 -1
- package/dist/pages/page-actions.d.ts +6 -0
- package/dist/pages/page-actions.js +10 -0
- package/dist/pages/page-actions.js.map +1 -0
- package/dist/pages/quick-actions.d.ts +1 -0
- package/dist/pages/quick-actions.js +56 -0
- package/dist/pages/quick-actions.js.map +1 -0
- package/dist/pages/translations.d.ts +7 -1
- package/dist/pages/translations.js +47 -10
- package/dist/pages/translations.js.map +1 -1
- package/dist/pages/workspace-guard.d.ts +1 -0
- package/dist/pages/workspace-guard.js +35 -0
- package/dist/pages/workspace-guard.js.map +1 -0
- package/dist/pages/workspace.d.ts +18 -0
- package/dist/pages/workspace.js +162 -0
- package/dist/pages/workspace.js.map +1 -0
- package/dist/pages/workspaces.d.ts +14 -0
- package/dist/pages/workspaces.js +88 -0
- package/dist/pages/workspaces.js.map +1 -0
- package/dist/routes/publicLocales.d.ts +3 -2
- package/dist/routes/publicLocales.js +39 -18
- package/dist/routes/publicLocales.js.map +1 -1
- package/dist/routes/translations.d.ts +59 -63
- package/dist/routes/translations.js +400 -119
- package/dist/routes/translations.js.map +1 -1
- package/dist/utils/announce.d.ts +9 -0
- package/dist/utils/announce.js +29 -0
- package/dist/utils/announce.js.map +1 -0
- package/dist/utils/blocks.d.ts +8 -0
- package/dist/utils/blocks.js +213 -0
- package/dist/utils/blocks.js.map +1 -0
- package/dist/utils/body.d.ts +1 -0
- package/dist/utils/body.js +21 -0
- package/dist/utils/body.js.map +1 -0
- package/dist/utils/cache.d.ts +3 -0
- package/dist/utils/cache.js +32 -0
- package/dist/utils/cache.js.map +1 -0
- package/dist/utils/catalog.d.ts +7 -0
- package/dist/utils/catalog.js +62 -0
- package/dist/utils/catalog.js.map +1 -0
- package/dist/utils/constants.d.ts +6 -0
- package/dist/utils/constants.js +10 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/coverage.d.ts +2 -0
- package/dist/utils/coverage.js +11 -0
- package/dist/utils/coverage.js.map +1 -0
- package/dist/utils/dialogs.d.ts +7 -0
- package/dist/utils/dialogs.js +103 -0
- package/dist/utils/dialogs.js.map +1 -0
- package/dist/utils/errors.d.ts +40 -0
- package/dist/utils/errors.js +60 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/export.d.ts +17 -0
- package/dist/utils/export.js +129 -0
- package/dist/utils/export.js.map +1 -0
- package/dist/utils/json.d.ts +10 -1
- package/dist/utils/json.js +127 -19
- package/dist/utils/json.js.map +1 -1
- package/dist/utils/key-stores.d.ts +3 -0
- package/dist/utils/key-stores.js +24 -0
- package/dist/utils/key-stores.js.map +1 -0
- package/dist/utils/keys.d.ts +23 -0
- package/dist/utils/keys.js +252 -0
- package/dist/utils/keys.js.map +1 -0
- package/dist/utils/languages.d.ts +27 -0
- package/dist/utils/languages.js +121 -0
- package/dist/utils/languages.js.map +1 -0
- package/dist/utils/locale-codes.d.ts +5 -0
- package/dist/utils/locale-codes.js +56 -0
- package/dist/utils/locale-codes.js.map +1 -0
- package/dist/utils/locale-discovery.d.ts +1 -0
- package/dist/utils/locale-discovery.js +19 -1
- package/dist/utils/locale-discovery.js.map +1 -1
- package/dist/utils/message-check.d.ts +1 -0
- package/dist/utils/message-check.js +93 -0
- package/dist/utils/message-check.js.map +1 -0
- package/dist/utils/message-syntax.d.ts +6 -0
- package/dist/utils/message-syntax.js +38 -0
- package/dist/utils/message-syntax.js.map +1 -0
- package/dist/utils/namespaces.d.ts +12 -0
- package/dist/utils/namespaces.js +52 -0
- package/dist/utils/namespaces.js.map +1 -0
- package/dist/utils/notices.d.ts +4 -0
- package/dist/utils/notices.js +60 -0
- package/dist/utils/notices.js.map +1 -0
- package/dist/utils/own.d.ts +2 -3
- package/dist/utils/own.js +17 -57
- package/dist/utils/own.js.map +1 -1
- package/dist/utils/public-url.d.ts +8 -0
- package/dist/utils/public-url.js +87 -0
- package/dist/utils/public-url.js.map +1 -0
- package/dist/utils/registry.d.ts +3 -1
- package/dist/utils/registry.js +26 -10
- package/dist/utils/registry.js.map +1 -1
- package/dist/utils/resolve.d.ts +18 -15
- package/dist/utils/resolve.js +98 -151
- package/dist/utils/resolve.js.map +1 -1
- package/dist/utils/review.d.ts +5 -0
- package/dist/utils/review.js +64 -0
- package/dist/utils/review.js.map +1 -0
- package/dist/utils/snippets.d.ts +7 -0
- package/dist/utils/snippets.js +129 -0
- package/dist/utils/snippets.js.map +1 -0
- package/dist/utils/summary.d.ts +23 -0
- package/dist/utils/summary.js +65 -0
- package/dist/utils/summary.js.map +1 -0
- package/dist/utils/tree.d.ts +2 -17
- package/dist/utils/tree.js +21 -126
- package/dist/utils/tree.js.map +1 -1
- package/dist/utils/workspaces.d.ts +45 -15
- package/dist/utils/workspaces.js +256 -164
- package/dist/utils/workspaces.js.map +1 -1
- package/dist/validation/key.schema.d.ts +71 -0
- package/dist/validation/key.schema.js +67 -0
- package/dist/validation/key.schema.js.map +1 -0
- package/dist/validation/query.schema.d.ts +17 -0
- package/dist/validation/query.schema.js +44 -0
- package/dist/validation/query.schema.js.map +1 -0
- package/dist/validation/validate.d.ts +2 -0
- package/dist/validation/validate.js +24 -0
- package/dist/validation/validate.js.map +1 -0
- package/dist/validation/workspace.schema.d.ts +145 -0
- package/dist/validation/workspace.schema.js +83 -0
- package/dist/validation/workspace.schema.js.map +1 -0
- package/frontend-vue/app/build/components/KeyAddModal.vue +340 -0
- package/frontend-vue/app/build/components/KeyEditorDrawer.vue +951 -0
- package/frontend-vue/app/build/components/KeyRenameModal.vue +172 -0
- package/frontend-vue/app/build/components/LanguageAddModal.vue +199 -0
- package/frontend-vue/app/build/components/LanguagePicker.vue +233 -0
- package/frontend-vue/app/build/components/LocaleTile.vue +52 -0
- package/frontend-vue/app/build/components/PlaceholderText.vue +42 -0
- package/frontend-vue/app/build/components/ShortcutKbds.vue +22 -0
- package/frontend-vue/app/build/components/WorkspaceCreateModal.vue +193 -0
- package/frontend-vue/app/build/components/WorkspaceRenameModal.vue +107 -0
- package/frontend-vue/app/build/components/form/FormFieldRow.vue +70 -0
- package/frontend-vue/app/build/components/form/FormRows.vue +25 -0
- package/frontend-vue/app/build/components/form/WorkspaceDetailsFields.vue +44 -0
- package/frontend-vue/app/build/components/matrix/MatrixCell.vue +488 -0
- package/frontend-vue/app/build/components/matrix/MatrixColumns.vue +177 -0
- package/frontend-vue/app/build/components/matrix/MatrixGroupHeader.vue +57 -0
- package/frontend-vue/app/build/components/matrix/MatrixKeyCell.vue +83 -0
- package/frontend-vue/app/build/components/matrix/MatrixToolbar.vue +167 -0
- package/frontend-vue/app/build/components/queue/QueueActions.vue +60 -0
- package/frontend-vue/app/build/components/queue/QueueDone.vue +185 -0
- package/frontend-vue/app/build/components/queue/QueueEditor.vue +374 -0
- package/frontend-vue/app/build/components/queue/QueueHeader.vue +162 -0
- package/frontend-vue/app/build/components/queue/QueueUpNext.vue +61 -0
- package/frontend-vue/app/build/composables/useCellEditor.ts +324 -0
- package/frontend-vue/app/build/composables/useCellMoves.ts +155 -0
- package/frontend-vue/app/build/composables/useCellSaves.ts +339 -0
- package/frontend-vue/app/build/composables/useKeyPanel.ts +284 -0
- package/frontend-vue/app/build/composables/useKeySaves.ts +280 -0
- package/frontend-vue/app/build/composables/useMatrixFilters.ts +213 -0
- package/frontend-vue/app/build/composables/useMatrixRows.ts +104 -0
- package/frontend-vue/app/build/composables/useMatrixView.ts +181 -0
- package/frontend-vue/app/build/composables/useQueueContext.ts +31 -0
- package/frontend-vue/app/build/composables/useQueueEditing.ts +53 -0
- package/frontend-vue/app/build/composables/useQueueOrphans.ts +54 -0
- package/frontend-vue/app/build/composables/useQueueSave.ts +290 -0
- package/frontend-vue/app/build/composables/useQueueShortcuts.ts +106 -0
- package/frontend-vue/app/build/composables/useQueueToasts.ts +99 -0
- package/frontend-vue/app/components/LanguageNamespaces.vue +77 -0
- package/frontend-vue/app/components/NamespaceCoverage.vue +222 -0
- package/frontend-vue/app/components/TranslationMatrix.vue +809 -0
- package/frontend-vue/app/components/TranslationQueue.vue +212 -0
- package/frontend-vue/app/components/WorkspaceDangerZone.vue +81 -0
- package/frontend-vue/app/components/WorkspaceGeneral.vue +232 -0
- package/frontend-vue/app/components/WorkspaceList.vue +454 -0
- package/frontend-vue/app/components/WorkspaceScope.vue +384 -0
- package/frontend-vue/app/composables/translation/useFirstRun.ts +8 -0
- package/frontend-vue/app/composables/translation/useI18nWorkspaces.ts +221 -133
- package/frontend-vue/app/composables/translation/useKeyActions.ts +224 -0
- package/frontend-vue/app/composables/translation/useLangFormat.ts +10 -0
- package/frontend-vue/app/composables/translation/useLangLinks.ts +80 -0
- package/frontend-vue/app/composables/translation/useLanguageActions.ts +159 -0
- package/frontend-vue/app/composables/translation/useLanguageQueue.ts +232 -0
- package/frontend-vue/app/composables/translation/useLocaleNames.ts +166 -0
- package/frontend-vue/app/composables/translation/useMutationToast.ts +51 -17
- package/frontend-vue/app/composables/translation/useQueueDrafts.ts +115 -0
- package/frontend-vue/app/composables/translation/useQueueSession.ts +182 -0
- package/frontend-vue/app/composables/translation/useServedConfirm.ts +152 -0
- package/frontend-vue/app/composables/translation/useWorkspaceActions.ts +259 -0
- package/frontend-vue/app/composables/translation/useWorkspaceContext.ts +46 -15
- package/frontend-vue/app/composables/translation/useWorkspaceFlat.ts +322 -70
- package/frontend-vue/app/composables/translation/useWorkspaceNameCheck.ts +55 -0
- package/frontend-vue/app/composables/translation/useWorkspaceRoute.ts +129 -0
- package/frontend-vue/app/config/shortcuts-registry.ts +72 -0
- package/frontend-vue/app/types/lang.ts +130 -0
- package/frontend-vue/app/utils/boundedCache.ts +22 -0
- package/frontend-vue/app/utils/download.ts +16 -0
- package/frontend-vue/app/utils/keySaveErrors.ts +61 -0
- package/frontend-vue/app/utils/keySaves.ts +108 -0
- package/frontend-vue/app/utils/languages.ts +272 -0
- package/frontend-vue/app/utils/matrixExport.ts +47 -0
- package/frontend-vue/app/utils/queueDrafts.ts +115 -0
- package/frontend-vue/app/utils/queuePass.ts +145 -0
- package/frontend-vue/app/utils/queueView.ts +22 -0
- package/frontend-vue/app/utils/shortcuts.ts +75 -0
- package/frontend-vue/app/utils/translations.ts +756 -0
- package/frontend-vue/app/utils/workspaceBackup.ts +119 -0
- package/frontend-vue/app/utils/workspaces.ts +45 -0
- package/frontend-vue/dms.frontend.build.ts +5 -0
- package/frontend-vue/dms.frontend.ts +9 -20
- package/frontend-vue/i18n/locales/lang-en-GB.json +792 -69
- package/frontend-vue/i18n/locales/lang-fr-FR.json +792 -69
- package/frontend-vue/package.json +10 -5
- package/package.json +10 -8
- package/dist/utils/mutations.d.ts +0 -3
- package/dist/utils/mutations.js +0 -35
- package/dist/utils/mutations.js.map +0 -1
- package/frontend-vue/app/build/components/pages/lang/TranslationMatrix.vue +0 -284
- package/frontend-vue/app/components/LanguageAddModal.vue +0 -78
- package/frontend-vue/app/components/WorkspaceEndpoint.vue +0 -29
- package/frontend-vue/app/components/WorkspaceSelector.vue +0 -180
- package/frontend-vue/app/components/WorkspaceStatus.vue +0 -24
- package/frontend-vue/app/composables/translation/useLanguageCatalog.ts +0 -90
- package/frontend-vue/app/composables/translation/useLocaleMeta.ts +0 -18
- package/frontend-vue/app/composables/translation/useTranslationProgress.ts +0 -73
- package/frontend-vue/app/custom-pages/lang/overview.vue +0 -397
- package/frontend-vue/app/custom-pages/lang/translations.vue +0 -498
- package/frontend-vue/app/plugins/workspace-sidebar-widget.ts +0 -12
|
@@ -1,177 +1,265 @@
|
|
|
1
|
-
import { useDmsState } from '#dms/frontend-module'
|
|
1
|
+
import { useDmsCookie, useDmsState } from '#dms/frontend-module'
|
|
2
|
+
import type {
|
|
3
|
+
FlatCounts,
|
|
4
|
+
FlatTranslations,
|
|
5
|
+
KeyRowResponse,
|
|
6
|
+
ScopedWorkspace,
|
|
7
|
+
WorkspaceDetails,
|
|
8
|
+
WorkspaceLocale,
|
|
9
|
+
WorkspacePermissionIds,
|
|
10
|
+
WorkspaceStats,
|
|
11
|
+
WorkspaceSummary,
|
|
12
|
+
} from '../../types/lang'
|
|
13
|
+
import {
|
|
14
|
+
BACKUP_FORMAT,
|
|
15
|
+
type DetailsChange,
|
|
16
|
+
type WorkspaceBackup,
|
|
17
|
+
type WorkspaceImport,
|
|
18
|
+
} from '../../utils/workspaceBackup'
|
|
2
19
|
|
|
3
|
-
|
|
4
|
-
code: string
|
|
5
|
-
name?: string
|
|
6
|
-
flag?: string
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export type WorkspaceKind = 'default' | 'modules' | 'added'
|
|
10
|
-
|
|
11
|
-
export interface WorkspaceSummary {
|
|
12
|
-
id: string
|
|
13
|
-
kind: WorkspaceKind
|
|
20
|
+
interface WorkspacesResponse {
|
|
14
21
|
editable: boolean
|
|
15
|
-
|
|
16
|
-
|
|
22
|
+
workspaces: ScopedWorkspace[]
|
|
23
|
+
permissions: WorkspacePermissionIds
|
|
24
|
+
publicBaseUrl: string
|
|
17
25
|
}
|
|
18
26
|
|
|
19
|
-
interface
|
|
27
|
+
interface SummaryResponse {
|
|
20
28
|
editable: boolean
|
|
21
|
-
workspaces:
|
|
29
|
+
workspaces: WorkspaceStats[]
|
|
22
30
|
}
|
|
23
31
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
type KeyValues = Record<string, unknown>
|
|
33
|
+
|
|
34
|
+
/** The routes of the module's API. */
|
|
35
|
+
export const LANG_API = '/api/lang/translations'
|
|
36
|
+
const API_BASE = LANG_API
|
|
37
|
+
const ENDPOINTS = {
|
|
38
|
+
workspaces: `${API_BASE}/workspaces`,
|
|
39
|
+
flat: `${API_BASE}/flat`,
|
|
40
|
+
row: `${API_BASE}/row`,
|
|
41
|
+
summary: `${API_BASE}/summary`,
|
|
42
|
+
workspace: `${API_BASE}/workspace`,
|
|
43
|
+
workspaceRename: `${API_BASE}/workspace/rename`,
|
|
44
|
+
backup: `${API_BASE}/backup`,
|
|
45
|
+
import: `${API_BASE}/import`,
|
|
46
|
+
locale: `${API_BASE}/locale`,
|
|
47
|
+
languages: `${API_BASE}/languages`,
|
|
48
|
+
key: `${API_BASE}/key`,
|
|
49
|
+
keyRename: `${API_BASE}/key/rename`,
|
|
50
|
+
keyOverride: `${API_BASE}/key/override`,
|
|
51
|
+
keyReviewed: `${API_BASE}/key/reviewed`,
|
|
52
|
+
} as const
|
|
32
53
|
|
|
33
54
|
export const DEFAULT_WORKSPACE = 'default'
|
|
55
|
+
export const MODULES_WORKSPACE = 'modules'
|
|
56
|
+
|
|
57
|
+
/** The route of one language of a workspace: removing it, making it the base, the dialogs that ask first. */
|
|
58
|
+
export function languageUrl(workspace: string, code: string): string {
|
|
59
|
+
return `${ENDPOINTS.languages}/${encodeURIComponent(workspace)}/${encodeURIComponent(code)}`
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const LAST_WORKSPACE_COOKIE = 'dms-lang-workspace'
|
|
63
|
+
const LAST_WORKSPACE_MAX_AGE = 60 * 60 * 24 * 365
|
|
34
64
|
|
|
35
65
|
const WORKSPACE_ID_RE = /^[a-z0-9][\w-]{0,63}$/
|
|
66
|
+
const RESERVED_WORKSPACE_IDS = new Set([DEFAULT_WORKSPACE, MODULES_WORKSPACE])
|
|
36
67
|
|
|
37
68
|
export function normalizeWorkspaceId(raw: string): string {
|
|
38
69
|
return raw.trim().toLowerCase()
|
|
39
70
|
}
|
|
40
71
|
|
|
41
|
-
export
|
|
42
|
-
|
|
72
|
+
export function isValidWorkspaceId(id: string): boolean {
|
|
73
|
+
return WORKSPACE_ID_RE.test(id) && !RESERVED_WORKSPACE_IDS.has(id)
|
|
74
|
+
}
|
|
43
75
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
() =>
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
'
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const isLoading = useDmsState<boolean>(
|
|
53
|
-
'dms-lang-workspaces-loading',
|
|
54
|
-
() => false,
|
|
55
|
-
)
|
|
56
|
-
const selectedWorkspace = useDmsState<string>(
|
|
57
|
-
'dms-lang-selected-workspace',
|
|
58
|
-
() => DEFAULT_WORKSPACE,
|
|
59
|
-
)
|
|
60
|
-
const requestSeq = useDmsState<number>('dms-lang-workspaces-seq', () => 0)
|
|
76
|
+
function useLastWorkspace() {
|
|
77
|
+
return useDmsCookie<string>(LAST_WORKSPACE_COOKIE, {
|
|
78
|
+
default: () => DEFAULT_WORKSPACE,
|
|
79
|
+
maxAge: LAST_WORKSPACE_MAX_AGE,
|
|
80
|
+
path: '/',
|
|
81
|
+
sameSite: 'lax',
|
|
82
|
+
})
|
|
83
|
+
}
|
|
61
84
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
85
|
+
function useWorkspacesState() {
|
|
86
|
+
const lastWorkspace = useLastWorkspace()
|
|
87
|
+
return {
|
|
88
|
+
lastWorkspace,
|
|
89
|
+
workspaces: useDmsState<ScopedWorkspace[]>(
|
|
90
|
+
'dms-lang-workspaces',
|
|
91
|
+
() => [],
|
|
92
|
+
),
|
|
93
|
+
editable: useDmsState<boolean>('dms-lang-workspaces-editable', () => false),
|
|
94
|
+
permissions: useDmsState<WorkspacePermissionIds | null>(
|
|
95
|
+
'dms-lang-workspaces-permissions',
|
|
96
|
+
() => null,
|
|
97
|
+
),
|
|
98
|
+
publicBaseUrl: useDmsState<string>('dms-lang-public-base-url', () => ''),
|
|
99
|
+
isLoading: useDmsState<boolean>('dms-lang-workspaces-loading', () => false),
|
|
100
|
+
isLoaded: useDmsState<boolean>('dms-lang-workspaces-loaded', () => false),
|
|
101
|
+
selectedWorkspace: useDmsState<string>(
|
|
102
|
+
'dms-lang-selected-workspace',
|
|
103
|
+
() => lastWorkspace.value || DEFAULT_WORKSPACE,
|
|
104
|
+
),
|
|
105
|
+
requestSeq: useDmsState<number>('dms-lang-workspaces-seq', () => 0),
|
|
67
106
|
}
|
|
107
|
+
}
|
|
68
108
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
109
|
+
function useKeyWrites() {
|
|
110
|
+
const { $authFetch } = useAuthFetch()
|
|
111
|
+
const send = (url: string, method: string, body: Record<string, unknown>) =>
|
|
112
|
+
$authFetch<KeyRowResponse>(url, { method, body })
|
|
73
113
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
114
|
+
return {
|
|
115
|
+
/** `before`: the path of the sibling the key goes right before (an undone deletion). */
|
|
116
|
+
createKey: (
|
|
117
|
+
workspace: string,
|
|
118
|
+
path: string,
|
|
119
|
+
values: KeyValues,
|
|
120
|
+
before?: string,
|
|
121
|
+
) => send(ENDPOINTS.key, 'POST', { workspace, path, values, before }),
|
|
122
|
+
/** `expected`: the texts the change was made on, a 409 when they changed since. */
|
|
123
|
+
updateKey: (
|
|
124
|
+
workspace: string,
|
|
125
|
+
path: string,
|
|
126
|
+
values: KeyValues = {},
|
|
127
|
+
expected?: KeyValues,
|
|
128
|
+
) => send(ENDPOINTS.key, 'PUT', { workspace, path, values, expected }),
|
|
129
|
+
/** Keeps translations as they are although the base text changed. */
|
|
130
|
+
markReviewed: (workspace: string, path: string, locales: string[]) =>
|
|
131
|
+
send(ENDPOINTS.keyReviewed, 'POST', { workspace, path, locales }),
|
|
132
|
+
revertOverride: (workspace: string, path: string, locales?: string[]) =>
|
|
133
|
+
send(ENDPOINTS.keyOverride, 'DELETE', { workspace, path, locales }),
|
|
134
|
+
renameKey: (workspace: string, path: string, newPath: string) =>
|
|
135
|
+
send(ENDPOINTS.keyRename, 'POST', { workspace, path, newPath }),
|
|
136
|
+
deleteKey: (workspace: string, path: string) =>
|
|
137
|
+
send(ENDPOINTS.key, 'DELETE', { workspace, path }),
|
|
90
138
|
}
|
|
139
|
+
}
|
|
91
140
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
})
|
|
97
|
-
}
|
|
141
|
+
function useWorkspaceWrites() {
|
|
142
|
+
const { $authFetch } = useAuthFetch()
|
|
143
|
+
const send = (url: string, method: string, body: Record<string, unknown>) =>
|
|
144
|
+
$authFetch(url, { method, body })
|
|
98
145
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
146
|
+
return {
|
|
147
|
+
createWorkspace: (
|
|
148
|
+
id: string,
|
|
149
|
+
locale: WorkspaceLocale,
|
|
150
|
+
details: WorkspaceDetails = {},
|
|
151
|
+
) => send(ENDPOINTS.workspace, 'POST', { id, locale, ...details }),
|
|
152
|
+
renameWorkspace: (id: string, newId: string) =>
|
|
153
|
+
send(ENDPOINTS.workspaceRename, 'POST', { id, newId }),
|
|
154
|
+
deleteWorkspace: (id: string) =>
|
|
155
|
+
send(ENDPOINTS.workspace, 'DELETE', { id }),
|
|
156
|
+
updateWorkspace: (id: string, change: DetailsChange) =>
|
|
157
|
+
$authFetch<WorkspaceSummary>(ENDPOINTS.workspace, {
|
|
158
|
+
method: 'PATCH',
|
|
159
|
+
body: { id, ...change },
|
|
160
|
+
}),
|
|
161
|
+
importWorkspace: (id: string, backup: WorkspaceImport) =>
|
|
162
|
+
$authFetch<WorkspaceSummary>(ENDPOINTS.import, {
|
|
163
|
+
method: 'POST',
|
|
164
|
+
body: { ...backup, format: BACKUP_FORMAT, id },
|
|
165
|
+
}),
|
|
166
|
+
addLocale: (workspace: string, locale: WorkspaceLocale) =>
|
|
167
|
+
send(ENDPOINTS.locale, 'POST', { workspace, ...locale }),
|
|
168
|
+
removeLocale: (workspace: string, code: string) =>
|
|
169
|
+
$authFetch(languageUrl(workspace, code), { method: 'DELETE' }),
|
|
170
|
+
setDefaultLocale: (workspace: string, code: string) =>
|
|
171
|
+
$authFetch(`${languageUrl(workspace, code)}/base`, { method: 'POST' }),
|
|
104
172
|
}
|
|
173
|
+
}
|
|
105
174
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
175
|
+
function useWorkspaceReads() {
|
|
176
|
+
const { $authFetch } = useAuthFetch()
|
|
177
|
+
return {
|
|
178
|
+
fetchSummary: () => $authFetch<SummaryResponse>(ENDPOINTS.summary),
|
|
179
|
+
fetchBackup: (workspace: string) =>
|
|
180
|
+
$authFetch<WorkspaceBackup>(ENDPOINTS.backup, { query: { workspace } }),
|
|
181
|
+
fetchFlat: (workspace: string) =>
|
|
182
|
+
$authFetch<FlatTranslations>(ENDPOINTS.flat, { query: { workspace } }),
|
|
183
|
+
fetchRow: (workspace: string, key: string) =>
|
|
184
|
+
$authFetch<KeyRowResponse>(ENDPOINTS.row, { query: { workspace, key } }),
|
|
111
185
|
}
|
|
186
|
+
}
|
|
112
187
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
188
|
+
/**
|
|
189
|
+
* The workspaces of the module, the one selected for every page, and the
|
|
190
|
+
* routes that read and change them. The selection follows the page URL
|
|
191
|
+
* (`?workspace=`, see useWorkspaceRoute): a workspace the URL names but the
|
|
192
|
+
* list lacks stays selected, so the page can say it does not exist.
|
|
193
|
+
*/
|
|
194
|
+
export const useI18nWorkspaces = () => {
|
|
195
|
+
const { $authFetch } = useAuthFetch()
|
|
196
|
+
const state = useWorkspacesState()
|
|
119
197
|
|
|
120
|
-
function
|
|
121
|
-
return
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
198
|
+
function canUseWorkspaceId(id: string): boolean {
|
|
199
|
+
return (
|
|
200
|
+
isValidWorkspaceId(id) &&
|
|
201
|
+
!state.workspaces.value.some((workspace) => workspace.id === id)
|
|
202
|
+
)
|
|
125
203
|
}
|
|
126
204
|
|
|
127
|
-
function
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
205
|
+
function applyResponse(response: WorkspacesResponse): void {
|
|
206
|
+
state.editable.value = response.editable
|
|
207
|
+
state.workspaces.value = response.workspaces
|
|
208
|
+
state.permissions.value = response.permissions
|
|
209
|
+
state.publicBaseUrl.value = response.publicBaseUrl
|
|
210
|
+
state.isLoaded.value = true
|
|
132
211
|
}
|
|
133
212
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
213
|
+
/** Takes the figures a key write answered into the workspace list (the scope bar). */
|
|
214
|
+
function patchCounts(id: string, counts: FlatCounts): void {
|
|
215
|
+
state.workspaces.value = state.workspaces.value.map((workspace) =>
|
|
216
|
+
workspace.id === id
|
|
217
|
+
? {
|
|
218
|
+
...workspace,
|
|
219
|
+
totalKeys: counts.totalKeys,
|
|
220
|
+
baseMissing: counts.baseMissing,
|
|
221
|
+
}
|
|
222
|
+
: workspace,
|
|
223
|
+
)
|
|
144
224
|
}
|
|
145
225
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
body: { workspace, path, newPath },
|
|
150
|
-
})
|
|
226
|
+
/** Remembers the workspace a page without `?workspace=` opens on (a new tab, a menu link). */
|
|
227
|
+
function rememberWorkspace(id: string): void {
|
|
228
|
+
if (state.lastWorkspace.value !== id) state.lastWorkspace.value = id
|
|
151
229
|
}
|
|
152
230
|
|
|
153
|
-
function
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
231
|
+
async function fetchWorkspaces(): Promise<ScopedWorkspace[]> {
|
|
232
|
+
state.requestSeq.value += 1
|
|
233
|
+
const sequence = state.requestSeq.value
|
|
234
|
+
state.isLoading.value = true
|
|
235
|
+
try {
|
|
236
|
+
const response = await $authFetch<WorkspacesResponse>(
|
|
237
|
+
ENDPOINTS.workspaces,
|
|
238
|
+
)
|
|
239
|
+
if (sequence !== state.requestSeq.value) return state.workspaces.value
|
|
240
|
+
applyResponse(response)
|
|
241
|
+
return state.workspaces.value
|
|
242
|
+
} catch {
|
|
243
|
+
return state.workspaces.value
|
|
244
|
+
} finally {
|
|
245
|
+
if (sequence === state.requestSeq.value) state.isLoading.value = false
|
|
246
|
+
}
|
|
158
247
|
}
|
|
159
248
|
|
|
160
249
|
return {
|
|
161
|
-
workspaces,
|
|
162
|
-
editable,
|
|
163
|
-
|
|
164
|
-
|
|
250
|
+
workspaces: state.workspaces,
|
|
251
|
+
editable: state.editable,
|
|
252
|
+
permissions: readonly(state.permissions),
|
|
253
|
+
publicBaseUrl: readonly(state.publicBaseUrl),
|
|
254
|
+
selectedWorkspace: state.selectedWorkspace,
|
|
255
|
+
isLoading: readonly(state.isLoading),
|
|
256
|
+
isLoaded: readonly(state.isLoaded),
|
|
165
257
|
fetchWorkspaces,
|
|
258
|
+
patchCounts,
|
|
166
259
|
canUseWorkspaceId,
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
removeLocale,
|
|
172
|
-
setDefaultLocale,
|
|
173
|
-
upsertKey,
|
|
174
|
-
renameKey,
|
|
175
|
-
deleteKey,
|
|
260
|
+
rememberWorkspace,
|
|
261
|
+
...useWorkspaceReads(),
|
|
262
|
+
...useWorkspaceWrites(),
|
|
263
|
+
...useKeyWrites(),
|
|
176
264
|
}
|
|
177
265
|
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import KeyAddModal from '../../build/components/KeyAddModal.vue'
|
|
2
|
+
import KeyRenameModal from '../../build/components/KeyRenameModal.vue'
|
|
3
|
+
import type { FlatTranslationRow, KeyRowResponse } from '../../types/lang'
|
|
4
|
+
|
|
5
|
+
/** What the key actions share: the selected workspace, its keys and the DMS helpers. */
|
|
6
|
+
interface KeyActionsContext {
|
|
7
|
+
t: ReturnType<typeof useI18n>['t']
|
|
8
|
+
toast: ReturnType<typeof useToast>
|
|
9
|
+
overlay: ReturnType<typeof useOverlay>
|
|
10
|
+
confirm: ReturnType<typeof useConfirm>['confirm']
|
|
11
|
+
workspaces: ReturnType<typeof useI18nWorkspaces>
|
|
12
|
+
translations: ReturnType<typeof useWorkspaceFlat>
|
|
13
|
+
isDefault: ReturnType<typeof useWorkspaceContext>['isDefault']
|
|
14
|
+
tryMutate: ReturnType<typeof useMutationToast>['tryMutate']
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** A removal asked about in a dialog, then announced with an Undo. */
|
|
18
|
+
interface KeyRemoval {
|
|
19
|
+
path: string
|
|
20
|
+
/** The group of its texts (`key_delete`, `key_revert`). */
|
|
21
|
+
texts: string
|
|
22
|
+
color: 'error' | 'warning'
|
|
23
|
+
run: (workspace: string) => Promise<KeyRowResponse>
|
|
24
|
+
undo: (workspace: string, row: FlatTranslationRow) => Promise<void>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The written values of a row, without the languages it lacks. */
|
|
28
|
+
export function filledValues(row: FlatTranslationRow): Record<string, string> {
|
|
29
|
+
const values: Record<string, string> = {}
|
|
30
|
+
for (const [locale, value] of Object.entries(row.values)) {
|
|
31
|
+
if (!isLocaleValueMissing(value)) values[locale] = stringValue(value)
|
|
32
|
+
}
|
|
33
|
+
return values
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function rowsOf(context: KeyActionsContext): FlatTranslationRow[] {
|
|
37
|
+
return context.translations.flat.value.rows
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The keys the installed modules provide, which the project files can override. */
|
|
41
|
+
async function moduleRows(
|
|
42
|
+
context: KeyActionsContext,
|
|
43
|
+
): Promise<FlatTranslationRow[]> {
|
|
44
|
+
if (!context.isDefault.value) return []
|
|
45
|
+
return (await context.translations.load(MODULES_WORKSPACE)).rows
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function addKey(context: KeyActionsContext): Promise<string[]> {
|
|
49
|
+
const { flat } = context.translations
|
|
50
|
+
const modal = context.overlay.create(KeyAddModal, {
|
|
51
|
+
props: {
|
|
52
|
+
workspace: context.workspaces.selectedWorkspace.value,
|
|
53
|
+
baseLocale: flat.value.defaultLocale,
|
|
54
|
+
locales: flat.value.locales,
|
|
55
|
+
existingKeys: rowsOf(context).map((row) => row.key),
|
|
56
|
+
moduleRows: await moduleRows(context),
|
|
57
|
+
},
|
|
58
|
+
destroyOnClose: true,
|
|
59
|
+
})
|
|
60
|
+
return ((await modal.open()) as string[] | undefined) ?? []
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function notify(context: KeyActionsContext, title: string, icon: string) {
|
|
64
|
+
context.toast.add({ title, color: 'success', icon })
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function renameKey(
|
|
68
|
+
context: KeyActionsContext,
|
|
69
|
+
path: string,
|
|
70
|
+
): Promise<string | null> {
|
|
71
|
+
const modules = await moduleRows(context)
|
|
72
|
+
const modal = context.overlay.create(KeyRenameModal, {
|
|
73
|
+
props: {
|
|
74
|
+
workspace: context.workspaces.selectedWorkspace.value,
|
|
75
|
+
path,
|
|
76
|
+
languageCount: context.translations.flat.value.locales.length,
|
|
77
|
+
existingKeys: rowsOf(context).map((row) => row.key),
|
|
78
|
+
moduleKeys: modules.map((row) => row.key),
|
|
79
|
+
},
|
|
80
|
+
destroyOnClose: true,
|
|
81
|
+
})
|
|
82
|
+
const renamed = (await modal.open()) as string | null
|
|
83
|
+
if (!renamed) return null
|
|
84
|
+
notify(
|
|
85
|
+
context,
|
|
86
|
+
context.t('dms_lang.key_rename.done', { path: renamed }),
|
|
87
|
+
'i-ph-check-circle',
|
|
88
|
+
)
|
|
89
|
+
return renamed
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function announceRemoval(
|
|
93
|
+
context: KeyActionsContext,
|
|
94
|
+
title: string,
|
|
95
|
+
undo: () => Promise<void>,
|
|
96
|
+
): void {
|
|
97
|
+
context.toast.add({
|
|
98
|
+
title,
|
|
99
|
+
color: 'neutral',
|
|
100
|
+
icon: 'i-ph-trash',
|
|
101
|
+
actions: [
|
|
102
|
+
{
|
|
103
|
+
label: context.t('dms_lang.actions.undo'),
|
|
104
|
+
color: 'neutral',
|
|
105
|
+
variant: 'outline',
|
|
106
|
+
onClick: () => undo(),
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Asks, runs a removal, puts its answer in place, and offers to undo it with the row as it was. */
|
|
113
|
+
async function removeKeyTexts(
|
|
114
|
+
context: KeyActionsContext,
|
|
115
|
+
removal: KeyRemoval,
|
|
116
|
+
): Promise<boolean> {
|
|
117
|
+
const { t } = context
|
|
118
|
+
const workspace = context.workspaces.selectedWorkspace.value
|
|
119
|
+
const row = rowsOf(context).find((entry) => entry.key === removal.path)
|
|
120
|
+
const filled = row ? Object.keys(filledValues(row)) : []
|
|
121
|
+
const count = filled.length
|
|
122
|
+
const params = {
|
|
123
|
+
path: removal.path,
|
|
124
|
+
workspace,
|
|
125
|
+
count,
|
|
126
|
+
locales: filled.join(', '),
|
|
127
|
+
}
|
|
128
|
+
const removed = await context.confirm({
|
|
129
|
+
title: t(`dms_lang.${removal.texts}.title`, params),
|
|
130
|
+
description: t(`dms_lang.${removal.texts}.description`, params, count),
|
|
131
|
+
color: removal.color,
|
|
132
|
+
confirmLabel: t(`dms_lang.${removal.texts}.submit`),
|
|
133
|
+
onConfirm: async () => {
|
|
134
|
+
const response = await removal.run(workspace)
|
|
135
|
+
context.translations.applyRow(workspace, removal.path, response)
|
|
136
|
+
},
|
|
137
|
+
})
|
|
138
|
+
if (!removed) return false
|
|
139
|
+
if (row)
|
|
140
|
+
announceRemoval(context, t(`dms_lang.${removal.texts}.done`, params), () =>
|
|
141
|
+
removal.undo(workspace, row),
|
|
142
|
+
)
|
|
143
|
+
return true
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** The row a removal took away, written back where it was. */
|
|
147
|
+
interface RowRestore {
|
|
148
|
+
workspace: string
|
|
149
|
+
row: FlatTranslationRow
|
|
150
|
+
before?: string
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Writes a row back as it was and puts the answer in place. */
|
|
154
|
+
async function restoreRow(
|
|
155
|
+
context: KeyActionsContext,
|
|
156
|
+
{ workspace, row, before }: RowRestore,
|
|
157
|
+
write: () => Promise<KeyRowResponse>,
|
|
158
|
+
): Promise<boolean> {
|
|
159
|
+
return context.tryMutate(async () => {
|
|
160
|
+
const response = await write()
|
|
161
|
+
context.translations.applyRow(workspace, row.key, response, before)
|
|
162
|
+
})
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function deleteKey(context: KeyActionsContext, path: string) {
|
|
166
|
+
const { deleteKey: remove, createKey } = context.workspaces
|
|
167
|
+
const before = nextSiblingPath(
|
|
168
|
+
rowsOf(context).map((row) => row.key),
|
|
169
|
+
path,
|
|
170
|
+
)
|
|
171
|
+
return removeKeyTexts(context, {
|
|
172
|
+
path,
|
|
173
|
+
texts: 'key_delete',
|
|
174
|
+
color: 'error',
|
|
175
|
+
run: (workspace) => remove(workspace, path),
|
|
176
|
+
undo: async (workspace, row) => {
|
|
177
|
+
const write = () =>
|
|
178
|
+
createKey(workspace, row.key, filledValues(row), before)
|
|
179
|
+
if (!(await restoreRow(context, { workspace, row, before }, write)))
|
|
180
|
+
return
|
|
181
|
+
notify(
|
|
182
|
+
context,
|
|
183
|
+
context.t('dms_lang.key_delete.restored', { path: row.key }),
|
|
184
|
+
'i-ph-arrow-counter-clockwise',
|
|
185
|
+
)
|
|
186
|
+
},
|
|
187
|
+
})
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Drops the project text of a module key: the module text shows again. */
|
|
191
|
+
function revertToModule(context: KeyActionsContext, path: string) {
|
|
192
|
+
const { revertOverride, updateKey } = context.workspaces
|
|
193
|
+
return removeKeyTexts(context, {
|
|
194
|
+
path,
|
|
195
|
+
texts: 'key_revert',
|
|
196
|
+
color: 'warning',
|
|
197
|
+
run: (workspace) => revertOverride(workspace, path),
|
|
198
|
+
undo: async (workspace, row) => {
|
|
199
|
+
await restoreRow(context, { workspace, row }, () =>
|
|
200
|
+
updateKey(workspace, row.key, filledValues(row)),
|
|
201
|
+
)
|
|
202
|
+
},
|
|
203
|
+
})
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** Add, rename and delete translation keys of the selected workspace. */
|
|
207
|
+
export const useKeyActions = () => {
|
|
208
|
+
const context: KeyActionsContext = {
|
|
209
|
+
t: useI18n().t,
|
|
210
|
+
toast: useToast(),
|
|
211
|
+
overlay: useOverlay(),
|
|
212
|
+
confirm: useConfirm().confirm,
|
|
213
|
+
workspaces: useI18nWorkspaces(),
|
|
214
|
+
translations: useWorkspaceFlat(),
|
|
215
|
+
isDefault: useWorkspaceContext().isDefault,
|
|
216
|
+
tryMutate: useMutationToast().tryMutate,
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
addKey: () => addKey(context),
|
|
220
|
+
renameKey: (path: string) => renameKey(context, path),
|
|
221
|
+
deleteKey: (path: string) => deleteKey(context, path),
|
|
222
|
+
revertToModule: (path: string) => revertToModule(context, path),
|
|
223
|
+
}
|
|
224
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Counts written in the user's language and regional format. */
|
|
2
|
+
export const useLangFormat = () => {
|
|
3
|
+
const { formatNumber } = useRegionalFormat()
|
|
4
|
+
|
|
5
|
+
function formatCount(value: number): string {
|
|
6
|
+
return String(formatNumber(value))
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return { formatCount }
|
|
10
|
+
}
|