@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.
Files changed (245) hide show
  1. package/README.md +12 -6
  2. package/dist/pages/actions.d.ts +7 -0
  3. package/dist/pages/actions.js +15 -0
  4. package/dist/pages/actions.js.map +1 -0
  5. package/dist/pages/component-action.d.ts +2 -0
  6. package/dist/pages/component-action.js +10 -0
  7. package/dist/pages/component-action.js.map +1 -0
  8. package/dist/pages/header-actions.d.ts +9 -0
  9. package/dist/pages/header-actions.js +146 -0
  10. package/dist/pages/header-actions.js.map +1 -0
  11. package/dist/pages/index.d.ts +6 -0
  12. package/dist/pages/index.js +6 -0
  13. package/dist/pages/index.js.map +1 -1
  14. package/dist/pages/language.d.ts +10 -0
  15. package/dist/pages/language.js +89 -0
  16. package/dist/pages/language.js.map +1 -0
  17. package/dist/pages/languages-table.d.ts +2 -0
  18. package/dist/pages/languages-table.js +120 -0
  19. package/dist/pages/languages-table.js.map +1 -0
  20. package/dist/pages/module.d.ts +7 -1
  21. package/dist/pages/module.js +28 -2
  22. package/dist/pages/module.js.map +1 -1
  23. package/dist/pages/overview.d.ts +2 -1
  24. package/dist/pages/overview.js +83 -8
  25. package/dist/pages/overview.js.map +1 -1
  26. package/dist/pages/page-actions.d.ts +6 -0
  27. package/dist/pages/page-actions.js +10 -0
  28. package/dist/pages/page-actions.js.map +1 -0
  29. package/dist/pages/quick-actions.d.ts +1 -0
  30. package/dist/pages/quick-actions.js +56 -0
  31. package/dist/pages/quick-actions.js.map +1 -0
  32. package/dist/pages/translations.d.ts +7 -1
  33. package/dist/pages/translations.js +47 -10
  34. package/dist/pages/translations.js.map +1 -1
  35. package/dist/pages/workspace-guard.d.ts +1 -0
  36. package/dist/pages/workspace-guard.js +35 -0
  37. package/dist/pages/workspace-guard.js.map +1 -0
  38. package/dist/pages/workspace.d.ts +18 -0
  39. package/dist/pages/workspace.js +162 -0
  40. package/dist/pages/workspace.js.map +1 -0
  41. package/dist/pages/workspaces.d.ts +14 -0
  42. package/dist/pages/workspaces.js +88 -0
  43. package/dist/pages/workspaces.js.map +1 -0
  44. package/dist/routes/publicLocales.d.ts +3 -2
  45. package/dist/routes/publicLocales.js +39 -18
  46. package/dist/routes/publicLocales.js.map +1 -1
  47. package/dist/routes/translations.d.ts +59 -63
  48. package/dist/routes/translations.js +400 -119
  49. package/dist/routes/translations.js.map +1 -1
  50. package/dist/utils/announce.d.ts +9 -0
  51. package/dist/utils/announce.js +29 -0
  52. package/dist/utils/announce.js.map +1 -0
  53. package/dist/utils/blocks.d.ts +8 -0
  54. package/dist/utils/blocks.js +213 -0
  55. package/dist/utils/blocks.js.map +1 -0
  56. package/dist/utils/body.d.ts +1 -0
  57. package/dist/utils/body.js +21 -0
  58. package/dist/utils/body.js.map +1 -0
  59. package/dist/utils/cache.d.ts +3 -0
  60. package/dist/utils/cache.js +32 -0
  61. package/dist/utils/cache.js.map +1 -0
  62. package/dist/utils/catalog.d.ts +7 -0
  63. package/dist/utils/catalog.js +62 -0
  64. package/dist/utils/catalog.js.map +1 -0
  65. package/dist/utils/constants.d.ts +6 -0
  66. package/dist/utils/constants.js +10 -0
  67. package/dist/utils/constants.js.map +1 -0
  68. package/dist/utils/coverage.d.ts +2 -0
  69. package/dist/utils/coverage.js +11 -0
  70. package/dist/utils/coverage.js.map +1 -0
  71. package/dist/utils/dialogs.d.ts +7 -0
  72. package/dist/utils/dialogs.js +103 -0
  73. package/dist/utils/dialogs.js.map +1 -0
  74. package/dist/utils/errors.d.ts +40 -0
  75. package/dist/utils/errors.js +60 -0
  76. package/dist/utils/errors.js.map +1 -0
  77. package/dist/utils/export.d.ts +17 -0
  78. package/dist/utils/export.js +129 -0
  79. package/dist/utils/export.js.map +1 -0
  80. package/dist/utils/json.d.ts +10 -1
  81. package/dist/utils/json.js +127 -19
  82. package/dist/utils/json.js.map +1 -1
  83. package/dist/utils/key-stores.d.ts +3 -0
  84. package/dist/utils/key-stores.js +24 -0
  85. package/dist/utils/key-stores.js.map +1 -0
  86. package/dist/utils/keys.d.ts +23 -0
  87. package/dist/utils/keys.js +252 -0
  88. package/dist/utils/keys.js.map +1 -0
  89. package/dist/utils/languages.d.ts +27 -0
  90. package/dist/utils/languages.js +121 -0
  91. package/dist/utils/languages.js.map +1 -0
  92. package/dist/utils/locale-codes.d.ts +5 -0
  93. package/dist/utils/locale-codes.js +56 -0
  94. package/dist/utils/locale-codes.js.map +1 -0
  95. package/dist/utils/locale-discovery.d.ts +1 -0
  96. package/dist/utils/locale-discovery.js +19 -1
  97. package/dist/utils/locale-discovery.js.map +1 -1
  98. package/dist/utils/message-check.d.ts +1 -0
  99. package/dist/utils/message-check.js +93 -0
  100. package/dist/utils/message-check.js.map +1 -0
  101. package/dist/utils/message-syntax.d.ts +6 -0
  102. package/dist/utils/message-syntax.js +38 -0
  103. package/dist/utils/message-syntax.js.map +1 -0
  104. package/dist/utils/namespaces.d.ts +12 -0
  105. package/dist/utils/namespaces.js +52 -0
  106. package/dist/utils/namespaces.js.map +1 -0
  107. package/dist/utils/notices.d.ts +4 -0
  108. package/dist/utils/notices.js +60 -0
  109. package/dist/utils/notices.js.map +1 -0
  110. package/dist/utils/own.d.ts +2 -3
  111. package/dist/utils/own.js +17 -57
  112. package/dist/utils/own.js.map +1 -1
  113. package/dist/utils/public-url.d.ts +8 -0
  114. package/dist/utils/public-url.js +87 -0
  115. package/dist/utils/public-url.js.map +1 -0
  116. package/dist/utils/registry.d.ts +3 -1
  117. package/dist/utils/registry.js +26 -10
  118. package/dist/utils/registry.js.map +1 -1
  119. package/dist/utils/resolve.d.ts +18 -15
  120. package/dist/utils/resolve.js +98 -151
  121. package/dist/utils/resolve.js.map +1 -1
  122. package/dist/utils/review.d.ts +5 -0
  123. package/dist/utils/review.js +64 -0
  124. package/dist/utils/review.js.map +1 -0
  125. package/dist/utils/snippets.d.ts +7 -0
  126. package/dist/utils/snippets.js +129 -0
  127. package/dist/utils/snippets.js.map +1 -0
  128. package/dist/utils/summary.d.ts +23 -0
  129. package/dist/utils/summary.js +65 -0
  130. package/dist/utils/summary.js.map +1 -0
  131. package/dist/utils/tree.d.ts +2 -17
  132. package/dist/utils/tree.js +21 -126
  133. package/dist/utils/tree.js.map +1 -1
  134. package/dist/utils/workspaces.d.ts +45 -15
  135. package/dist/utils/workspaces.js +256 -164
  136. package/dist/utils/workspaces.js.map +1 -1
  137. package/dist/validation/key.schema.d.ts +71 -0
  138. package/dist/validation/key.schema.js +67 -0
  139. package/dist/validation/key.schema.js.map +1 -0
  140. package/dist/validation/query.schema.d.ts +17 -0
  141. package/dist/validation/query.schema.js +44 -0
  142. package/dist/validation/query.schema.js.map +1 -0
  143. package/dist/validation/validate.d.ts +2 -0
  144. package/dist/validation/validate.js +24 -0
  145. package/dist/validation/validate.js.map +1 -0
  146. package/dist/validation/workspace.schema.d.ts +145 -0
  147. package/dist/validation/workspace.schema.js +83 -0
  148. package/dist/validation/workspace.schema.js.map +1 -0
  149. package/frontend-vue/app/build/components/KeyAddModal.vue +340 -0
  150. package/frontend-vue/app/build/components/KeyEditorDrawer.vue +951 -0
  151. package/frontend-vue/app/build/components/KeyRenameModal.vue +172 -0
  152. package/frontend-vue/app/build/components/LanguageAddModal.vue +199 -0
  153. package/frontend-vue/app/build/components/LanguagePicker.vue +233 -0
  154. package/frontend-vue/app/build/components/LocaleTile.vue +52 -0
  155. package/frontend-vue/app/build/components/PlaceholderText.vue +42 -0
  156. package/frontend-vue/app/build/components/ShortcutKbds.vue +22 -0
  157. package/frontend-vue/app/build/components/WorkspaceCreateModal.vue +193 -0
  158. package/frontend-vue/app/build/components/WorkspaceRenameModal.vue +107 -0
  159. package/frontend-vue/app/build/components/form/FormFieldRow.vue +70 -0
  160. package/frontend-vue/app/build/components/form/FormRows.vue +25 -0
  161. package/frontend-vue/app/build/components/form/WorkspaceDetailsFields.vue +44 -0
  162. package/frontend-vue/app/build/components/matrix/MatrixCell.vue +488 -0
  163. package/frontend-vue/app/build/components/matrix/MatrixColumns.vue +177 -0
  164. package/frontend-vue/app/build/components/matrix/MatrixGroupHeader.vue +57 -0
  165. package/frontend-vue/app/build/components/matrix/MatrixKeyCell.vue +83 -0
  166. package/frontend-vue/app/build/components/matrix/MatrixToolbar.vue +167 -0
  167. package/frontend-vue/app/build/components/queue/QueueActions.vue +60 -0
  168. package/frontend-vue/app/build/components/queue/QueueDone.vue +185 -0
  169. package/frontend-vue/app/build/components/queue/QueueEditor.vue +374 -0
  170. package/frontend-vue/app/build/components/queue/QueueHeader.vue +162 -0
  171. package/frontend-vue/app/build/components/queue/QueueUpNext.vue +61 -0
  172. package/frontend-vue/app/build/composables/useCellEditor.ts +324 -0
  173. package/frontend-vue/app/build/composables/useCellMoves.ts +155 -0
  174. package/frontend-vue/app/build/composables/useCellSaves.ts +339 -0
  175. package/frontend-vue/app/build/composables/useKeyPanel.ts +284 -0
  176. package/frontend-vue/app/build/composables/useKeySaves.ts +280 -0
  177. package/frontend-vue/app/build/composables/useMatrixFilters.ts +213 -0
  178. package/frontend-vue/app/build/composables/useMatrixRows.ts +104 -0
  179. package/frontend-vue/app/build/composables/useMatrixView.ts +181 -0
  180. package/frontend-vue/app/build/composables/useQueueContext.ts +31 -0
  181. package/frontend-vue/app/build/composables/useQueueEditing.ts +53 -0
  182. package/frontend-vue/app/build/composables/useQueueOrphans.ts +54 -0
  183. package/frontend-vue/app/build/composables/useQueueSave.ts +290 -0
  184. package/frontend-vue/app/build/composables/useQueueShortcuts.ts +106 -0
  185. package/frontend-vue/app/build/composables/useQueueToasts.ts +99 -0
  186. package/frontend-vue/app/components/LanguageNamespaces.vue +77 -0
  187. package/frontend-vue/app/components/NamespaceCoverage.vue +222 -0
  188. package/frontend-vue/app/components/TranslationMatrix.vue +809 -0
  189. package/frontend-vue/app/components/TranslationQueue.vue +212 -0
  190. package/frontend-vue/app/components/WorkspaceDangerZone.vue +81 -0
  191. package/frontend-vue/app/components/WorkspaceGeneral.vue +232 -0
  192. package/frontend-vue/app/components/WorkspaceList.vue +454 -0
  193. package/frontend-vue/app/components/WorkspaceScope.vue +384 -0
  194. package/frontend-vue/app/composables/translation/useFirstRun.ts +8 -0
  195. package/frontend-vue/app/composables/translation/useI18nWorkspaces.ts +221 -133
  196. package/frontend-vue/app/composables/translation/useKeyActions.ts +224 -0
  197. package/frontend-vue/app/composables/translation/useLangFormat.ts +10 -0
  198. package/frontend-vue/app/composables/translation/useLangLinks.ts +80 -0
  199. package/frontend-vue/app/composables/translation/useLanguageActions.ts +159 -0
  200. package/frontend-vue/app/composables/translation/useLanguageQueue.ts +232 -0
  201. package/frontend-vue/app/composables/translation/useLocaleNames.ts +166 -0
  202. package/frontend-vue/app/composables/translation/useMutationToast.ts +51 -17
  203. package/frontend-vue/app/composables/translation/useQueueDrafts.ts +115 -0
  204. package/frontend-vue/app/composables/translation/useQueueSession.ts +182 -0
  205. package/frontend-vue/app/composables/translation/useServedConfirm.ts +152 -0
  206. package/frontend-vue/app/composables/translation/useWorkspaceActions.ts +259 -0
  207. package/frontend-vue/app/composables/translation/useWorkspaceContext.ts +46 -15
  208. package/frontend-vue/app/composables/translation/useWorkspaceFlat.ts +322 -70
  209. package/frontend-vue/app/composables/translation/useWorkspaceNameCheck.ts +55 -0
  210. package/frontend-vue/app/composables/translation/useWorkspaceRoute.ts +129 -0
  211. package/frontend-vue/app/config/shortcuts-registry.ts +72 -0
  212. package/frontend-vue/app/types/lang.ts +130 -0
  213. package/frontend-vue/app/utils/boundedCache.ts +22 -0
  214. package/frontend-vue/app/utils/download.ts +16 -0
  215. package/frontend-vue/app/utils/keySaveErrors.ts +61 -0
  216. package/frontend-vue/app/utils/keySaves.ts +108 -0
  217. package/frontend-vue/app/utils/languages.ts +272 -0
  218. package/frontend-vue/app/utils/matrixExport.ts +47 -0
  219. package/frontend-vue/app/utils/queueDrafts.ts +115 -0
  220. package/frontend-vue/app/utils/queuePass.ts +145 -0
  221. package/frontend-vue/app/utils/queueView.ts +22 -0
  222. package/frontend-vue/app/utils/shortcuts.ts +75 -0
  223. package/frontend-vue/app/utils/translations.ts +756 -0
  224. package/frontend-vue/app/utils/workspaceBackup.ts +119 -0
  225. package/frontend-vue/app/utils/workspaces.ts +45 -0
  226. package/frontend-vue/dms.frontend.build.ts +5 -0
  227. package/frontend-vue/dms.frontend.ts +9 -20
  228. package/frontend-vue/i18n/locales/lang-en-GB.json +792 -69
  229. package/frontend-vue/i18n/locales/lang-fr-FR.json +792 -69
  230. package/frontend-vue/package.json +8 -6
  231. package/package.json +8 -6
  232. package/dist/utils/mutations.d.ts +0 -3
  233. package/dist/utils/mutations.js +0 -35
  234. package/dist/utils/mutations.js.map +0 -1
  235. package/frontend-vue/app/build/components/pages/lang/TranslationMatrix.vue +0 -284
  236. package/frontend-vue/app/components/LanguageAddModal.vue +0 -78
  237. package/frontend-vue/app/components/WorkspaceEndpoint.vue +0 -29
  238. package/frontend-vue/app/components/WorkspaceSelector.vue +0 -180
  239. package/frontend-vue/app/components/WorkspaceStatus.vue +0 -24
  240. package/frontend-vue/app/composables/translation/useLanguageCatalog.ts +0 -90
  241. package/frontend-vue/app/composables/translation/useLocaleMeta.ts +0 -18
  242. package/frontend-vue/app/composables/translation/useTranslationProgress.ts +0 -73
  243. package/frontend-vue/app/custom-pages/lang/overview.vue +0 -397
  244. package/frontend-vue/app/custom-pages/lang/translations.vue +0 -498
  245. 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 { WorkspaceSummary } from "./useI18nWorkspaces";
1
+ import type { ScopedWorkspace, WorkspacePermission } from '../../types/lang'
2
2
 
3
3
  /**
4
- * Read-only view of the globally selected workspace and of what the current
5
- * user may do with it, shared by every page and widget of the module.
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 } = useI18nWorkspaces();
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: WorkspaceSummary) =>
14
- workspace.id === selectedWorkspace.value,
15
+ (workspace) => workspace.id === selectedWorkspace.value,
15
16
  ) ?? null,
16
- );
17
+ )
17
18
 
18
- const isDefault = computed(() => current.value?.kind === "default");
19
- const isModules = computed(() => current.value?.kind === "modules");
20
- const isAdded = computed(() => current.value?.kind === "added");
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 canManage = computed(() => isAdded.value && isEditable.value);
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 { current, isDefault, isModules, isAdded, isEditable, canManage };
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
+ }