@antelopejs/dms-lang 0.0.7 → 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 +8 -6
- package/package.json +8 -6
- 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
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { h } from 'vue'
|
|
2
|
+
import UButton from '@nuxt/ui/components/Button.vue'
|
|
3
|
+
import type { WorkspaceKind, WorkspaceType } from '../../types/lang'
|
|
4
|
+
import {
|
|
5
|
+
parseBackup,
|
|
6
|
+
type DetailsChange,
|
|
7
|
+
type WorkspaceBackup,
|
|
8
|
+
} from '../../utils/workspaceBackup'
|
|
9
|
+
import WorkspaceCreateModal from '../../build/components/WorkspaceCreateModal.vue'
|
|
10
|
+
import WorkspaceRenameModal from '../../build/components/WorkspaceRenameModal.vue'
|
|
11
|
+
|
|
12
|
+
const JSON_FILE_TYPES = '.json,application/json'
|
|
13
|
+
const WORKSPACE_DESCRIPTION_MAX = 500
|
|
14
|
+
|
|
15
|
+
const TYPE_ICONS: Record<WorkspaceType, string> = {
|
|
16
|
+
dms: 'i-ph-squares-four',
|
|
17
|
+
website: 'i-ph-globe',
|
|
18
|
+
mobile: 'i-ph-device-mobile',
|
|
19
|
+
other: 'i-ph-shapes',
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const KIND_ICONS: Record<WorkspaceKind, string> = {
|
|
23
|
+
default: 'i-ph-file-code',
|
|
24
|
+
added: 'i-ph-stack',
|
|
25
|
+
modules: 'i-ph-puzzle-piece',
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function isWorkspaceType(value: unknown): value is WorkspaceType {
|
|
29
|
+
return typeof value === 'string' && Object.hasOwn(TYPE_ICONS, value)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface DeleteImpact {
|
|
33
|
+
files: number
|
|
34
|
+
strings: number
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function pickFile(accept: string): Promise<File | null> {
|
|
38
|
+
return new Promise((resolve) => {
|
|
39
|
+
const input = document.createElement('input')
|
|
40
|
+
input.type = 'file'
|
|
41
|
+
input.accept = accept
|
|
42
|
+
input.addEventListener('change', () => resolve(input.files?.[0] ?? null))
|
|
43
|
+
input.addEventListener('cancel', () => resolve(null))
|
|
44
|
+
input.click()
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The kinds of app a workspace serves, as a picker offers them, and the icon of each kind of workspace. */
|
|
49
|
+
export const useWorkspaceTypes = () => {
|
|
50
|
+
const { t } = useI18n()
|
|
51
|
+
const typeItems = computed(() =>
|
|
52
|
+
(Object.keys(TYPE_ICONS) as WorkspaceType[]).map((value) => ({
|
|
53
|
+
value,
|
|
54
|
+
label: t(`dms_lang.workspace_types.${value}`),
|
|
55
|
+
icon: TYPE_ICONS[value],
|
|
56
|
+
})),
|
|
57
|
+
)
|
|
58
|
+
const typeIcon = (type: WorkspaceType) => TYPE_ICONS[type]
|
|
59
|
+
const typeOf = (value: unknown): WorkspaceType | undefined =>
|
|
60
|
+
isWorkspaceType(value) ? value : undefined
|
|
61
|
+
const typeLabel = (type: WorkspaceType) =>
|
|
62
|
+
t(`dms_lang.workspace_types.${type}`)
|
|
63
|
+
return {
|
|
64
|
+
typeItems,
|
|
65
|
+
typeIcon,
|
|
66
|
+
typeLabel,
|
|
67
|
+
typeOf,
|
|
68
|
+
kindIcon: (kind: WorkspaceKind) => KIND_ICONS[kind],
|
|
69
|
+
descriptionMax: WORKSPACE_DESCRIPTION_MAX,
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** What the workspace actions share: the workspaces, the routes and the DMS helpers. */
|
|
74
|
+
interface WorkspaceActionsContext {
|
|
75
|
+
t: ReturnType<typeof useI18n>['t']
|
|
76
|
+
toast: ReturnType<typeof useToast>
|
|
77
|
+
overlay: ReturnType<typeof useOverlay>
|
|
78
|
+
confirm: ReturnType<typeof useConfirm>['confirm']
|
|
79
|
+
formatCount: ReturnType<typeof useLangFormat>['formatCount']
|
|
80
|
+
workspaces: ReturnType<typeof useI18nWorkspaces>
|
|
81
|
+
selectWorkspace: ReturnType<typeof useWorkspaceRoute>['selectWorkspace']
|
|
82
|
+
failures: ReturnType<typeof useMutationToast>
|
|
83
|
+
links: ReturnType<typeof useLangLinks>
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function succeed(context: WorkspaceActionsContext, title: string): void {
|
|
87
|
+
context.toast.add({ title, color: 'success', icon: 'i-ph-check-circle' })
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function openCreate(
|
|
91
|
+
context: WorkspaceActionsContext,
|
|
92
|
+
backup?: WorkspaceBackup,
|
|
93
|
+
): Promise<string | null> {
|
|
94
|
+
const modal = context.overlay.create(WorkspaceCreateModal, {
|
|
95
|
+
props: { backup },
|
|
96
|
+
})
|
|
97
|
+
const created = (await modal.open()) as string | null
|
|
98
|
+
if (!created) return null
|
|
99
|
+
await context.workspaces.fetchWorkspaces()
|
|
100
|
+
const texts = backup ? 'workspace_import' : 'workspace_create'
|
|
101
|
+
succeed(context, context.t(`dms_lang.${texts}.done`, { name: created }))
|
|
102
|
+
await context.selectWorkspace(created, { page: 'workspace' })
|
|
103
|
+
return created
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async function importWorkspace(
|
|
107
|
+
context: WorkspaceActionsContext,
|
|
108
|
+
): Promise<string | null> {
|
|
109
|
+
const { t } = context
|
|
110
|
+
const file = await pickFile(JSON_FILE_TYPES)
|
|
111
|
+
if (!file) return null
|
|
112
|
+
const read = parseBackup(await file.text(), file.name)
|
|
113
|
+
if (read.backup) return openCreate(context, read.backup)
|
|
114
|
+
context.toast.add({
|
|
115
|
+
title: t(`dms_lang.workspace_import.${read.problem}_title`, {
|
|
116
|
+
file: file.name,
|
|
117
|
+
}),
|
|
118
|
+
description: t(`dms_lang.workspace_import.${read.problem}_help`),
|
|
119
|
+
color: 'error',
|
|
120
|
+
icon: 'i-ph-warning-circle',
|
|
121
|
+
})
|
|
122
|
+
return null
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function renameWorkspace(
|
|
126
|
+
context: WorkspaceActionsContext,
|
|
127
|
+
workspace: string,
|
|
128
|
+
): Promise<string | null> {
|
|
129
|
+
const modal = context.overlay.create(WorkspaceRenameModal, {
|
|
130
|
+
props: { workspace },
|
|
131
|
+
})
|
|
132
|
+
const renamed = (await modal.open()) as string | null
|
|
133
|
+
if (!renamed) return null
|
|
134
|
+
await context.workspaces.fetchWorkspaces()
|
|
135
|
+
succeed(
|
|
136
|
+
context,
|
|
137
|
+
context.t('dms_lang.workspace_rename.done', { name: renamed }),
|
|
138
|
+
)
|
|
139
|
+
await context.selectWorkspace(renamed, { replace: true })
|
|
140
|
+
return renamed
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Saves a workspace's details; a failure says why in a toast. */
|
|
144
|
+
async function updateDetails(
|
|
145
|
+
context: WorkspaceActionsContext,
|
|
146
|
+
id: string,
|
|
147
|
+
change: DetailsChange,
|
|
148
|
+
): Promise<boolean> {
|
|
149
|
+
const ok = await context.failures.tryMutate(
|
|
150
|
+
() => context.workspaces.updateWorkspace(id, change),
|
|
151
|
+
{ title: context.t('dms_lang.workspace_details.save_failed') },
|
|
152
|
+
)
|
|
153
|
+
if (!ok) return false
|
|
154
|
+
await context.workspaces.fetchWorkspaces()
|
|
155
|
+
return true
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async function downloadBackup(
|
|
159
|
+
context: WorkspaceActionsContext,
|
|
160
|
+
workspace: string,
|
|
161
|
+
): Promise<void> {
|
|
162
|
+
try {
|
|
163
|
+
downloadJson(`${workspace}.json`, await context.workspaces.fetchBackup(workspace))
|
|
164
|
+
} catch (error) {
|
|
165
|
+
context.failures.reportFailure(error, {
|
|
166
|
+
title: context.t('dms_lang.errors.export_failed'),
|
|
167
|
+
})
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function deleteImpact(
|
|
172
|
+
{ t, formatCount, links }: WorkspaceActionsContext,
|
|
173
|
+
workspace: string,
|
|
174
|
+
impact: DeleteImpact,
|
|
175
|
+
) {
|
|
176
|
+
return [
|
|
177
|
+
{
|
|
178
|
+
icon: 'i-ph-files',
|
|
179
|
+
label: t('dms_lang.workspace_delete.files'),
|
|
180
|
+
count: formatCount(impact.files),
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
icon: 'i-ph-text-aa',
|
|
184
|
+
label: t('dms_lang.workspace_delete.strings'),
|
|
185
|
+
count: formatCount(impact.strings),
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
icon: 'i-ph-plugs',
|
|
189
|
+
label: t('dms_lang.workspace_delete.url', {
|
|
190
|
+
url: links.publicLocaleUrl(workspace),
|
|
191
|
+
}),
|
|
192
|
+
},
|
|
193
|
+
]
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function backupButton(context: WorkspaceActionsContext, workspace: string) {
|
|
197
|
+
return h(UButton, {
|
|
198
|
+
icon: 'i-ph-download-simple',
|
|
199
|
+
color: 'neutral',
|
|
200
|
+
variant: 'outline',
|
|
201
|
+
size: 'sm',
|
|
202
|
+
class: 'self-start',
|
|
203
|
+
label: context.t('dms_lang.workspace_delete.backup'),
|
|
204
|
+
onClick: () => downloadBackup(context, workspace),
|
|
205
|
+
})
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async function deleteWorkspace(
|
|
209
|
+
context: WorkspaceActionsContext,
|
|
210
|
+
workspace: string,
|
|
211
|
+
impact: DeleteImpact,
|
|
212
|
+
): Promise<boolean> {
|
|
213
|
+
const { t, workspaces } = context
|
|
214
|
+
const deleted = await context.confirm({
|
|
215
|
+
title: t('dms_lang.workspace_delete.title', { name: workspace }),
|
|
216
|
+
description: t('dms_lang.workspace_delete.description'),
|
|
217
|
+
color: 'error',
|
|
218
|
+
confirmLabel: t('dms_lang.workspace_delete.submit'),
|
|
219
|
+
confirmText: workspace,
|
|
220
|
+
impact: deleteImpact(context, workspace, impact),
|
|
221
|
+
body: () => backupButton(context, workspace),
|
|
222
|
+
onConfirm: async () => {
|
|
223
|
+
await workspaces.deleteWorkspace(workspace)
|
|
224
|
+
await workspaces.fetchWorkspaces()
|
|
225
|
+
},
|
|
226
|
+
})
|
|
227
|
+
if (!deleted) return false
|
|
228
|
+
succeed(context, t('dms_lang.workspace_delete.done', { name: workspace }))
|
|
229
|
+
await context.selectWorkspace(DEFAULT_WORKSPACE, {
|
|
230
|
+
page: 'workspaces',
|
|
231
|
+
replace: true,
|
|
232
|
+
})
|
|
233
|
+
return true
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** Create, import, rename, back up and delete workspaces. */
|
|
237
|
+
export const useWorkspaceActions = () => {
|
|
238
|
+
const context: WorkspaceActionsContext = {
|
|
239
|
+
t: useI18n().t,
|
|
240
|
+
toast: useToast(),
|
|
241
|
+
overlay: useOverlay(),
|
|
242
|
+
confirm: useConfirm().confirm,
|
|
243
|
+
formatCount: useLangFormat().formatCount,
|
|
244
|
+
workspaces: useI18nWorkspaces(),
|
|
245
|
+
selectWorkspace: useWorkspaceRoute().selectWorkspace,
|
|
246
|
+
failures: useMutationToast(),
|
|
247
|
+
links: useLangLinks(),
|
|
248
|
+
}
|
|
249
|
+
return {
|
|
250
|
+
createWorkspace: () => openCreate(context),
|
|
251
|
+
importWorkspace: () => importWorkspace(context),
|
|
252
|
+
renameWorkspace: (workspace: string) => renameWorkspace(context, workspace),
|
|
253
|
+
updateDetails: (id: string, change: DetailsChange) =>
|
|
254
|
+
updateDetails(context, id, change),
|
|
255
|
+
deleteWorkspace: (workspace: string, impact: DeleteImpact) =>
|
|
256
|
+
deleteWorkspace(context, workspace, impact),
|
|
257
|
+
downloadBackup: (workspace: string) => downloadBackup(context, workspace),
|
|
258
|
+
}
|
|
259
|
+
}
|
|
@@ -1,27 +1,58 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ScopedWorkspace, WorkspacePermission } from '../../types/lang'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Read-only view of the
|
|
5
|
-
*
|
|
4
|
+
* Read-only view of the selected workspace and of what the current user may
|
|
5
|
+
* do with it, shared by every page of the module.
|
|
6
6
|
*/
|
|
7
7
|
export const useWorkspaceContext = () => {
|
|
8
|
-
const { workspaces, editable, selectedWorkspace } =
|
|
8
|
+
const { workspaces, editable, selectedWorkspace, isLoaded, permissions } =
|
|
9
|
+
useI18nWorkspaces()
|
|
10
|
+
const { hasPermission } = usePermissions()
|
|
9
11
|
|
|
10
|
-
const current = computed(
|
|
12
|
+
const current = computed<ScopedWorkspace | null>(
|
|
11
13
|
() =>
|
|
12
14
|
workspaces.value.find(
|
|
13
|
-
(workspace
|
|
14
|
-
workspace.id === selectedWorkspace.value,
|
|
15
|
+
(workspace) => workspace.id === selectedWorkspace.value,
|
|
15
16
|
) ?? null,
|
|
16
|
-
)
|
|
17
|
+
)
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
19
|
+
/** The URL names a workspace the server does not have. */
|
|
20
|
+
const isUnknown = computed(
|
|
21
|
+
() => isLoaded.value && !!selectedWorkspace.value && !current.value,
|
|
22
|
+
)
|
|
23
|
+
/** The workspace is in, with its figures. */
|
|
24
|
+
const isResolved = computed(() => current.value !== null)
|
|
25
|
+
|
|
26
|
+
const isDefault = computed(() => current.value?.kind === 'default')
|
|
27
|
+
const isModules = computed(() => current.value?.kind === 'modules')
|
|
28
|
+
const isAdded = computed(() => current.value?.kind === 'added')
|
|
21
29
|
const isEditable = computed(
|
|
22
30
|
() => editable.value && (current.value?.editable ?? false),
|
|
23
|
-
)
|
|
24
|
-
const
|
|
31
|
+
)
|
|
32
|
+
const canEditValues = computed(() => isEditable.value && !isModules.value)
|
|
33
|
+
const canManage = computed(() => isAdded.value && isEditable.value)
|
|
34
|
+
|
|
35
|
+
/** Whether the user holds the DMS permission guarding a kind of write. */
|
|
36
|
+
function allows(permission: WorkspacePermission): boolean {
|
|
37
|
+
const id = permissions.value?.[permission]
|
|
38
|
+
return id ? hasPermission(id) : true
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const canManageKeys = computed(
|
|
42
|
+
() => canEditValues.value && allows('manageKeys'),
|
|
43
|
+
)
|
|
25
44
|
|
|
26
|
-
return {
|
|
27
|
-
|
|
45
|
+
return {
|
|
46
|
+
current,
|
|
47
|
+
isUnknown,
|
|
48
|
+
isResolved,
|
|
49
|
+
isDefault,
|
|
50
|
+
isModules,
|
|
51
|
+
isAdded,
|
|
52
|
+
isEditable,
|
|
53
|
+
canEditValues,
|
|
54
|
+
canManage,
|
|
55
|
+
canManageKeys,
|
|
56
|
+
allows,
|
|
57
|
+
}
|
|
58
|
+
}
|