@mapomodule/uikit 2.0.0-beta.7 → 2.0.0-experimental.1
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 +47 -174
- package/dist/__tests__/MapoConfirmDialog.component.test.d.ts +2 -0
- package/dist/__tests__/MapoConfirmDialog.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoDetail.component.test.d.ts +2 -0
- package/dist/__tests__/MapoDetail.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoDetailLangSwitch.component.test.d.ts +2 -0
- package/dist/__tests__/MapoDetailLangSwitch.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoListActions.component.test.d.ts +2 -0
- package/dist/__tests__/MapoListActions.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoListTable.component.test.d.ts +2 -0
- package/dist/__tests__/MapoListTable.component.test.d.ts.map +1 -0
- package/dist/__tests__/MapoSnackBar.component.test.d.ts +2 -0
- package/dist/__tests__/MapoSnackBar.component.test.d.ts.map +1 -0
- package/dist/__tests__/__mocks__/nuxt-app.d.ts +9 -0
- package/dist/__tests__/__mocks__/nuxt-app.d.ts.map +1 -0
- package/dist/__tests__/formValues.test.d.ts +2 -0
- package/dist/__tests__/formValues.test.d.ts.map +1 -0
- package/dist/__tests__/langInfo.test.d.ts +2 -0
- package/dist/__tests__/langInfo.test.d.ts.map +1 -0
- package/dist/__tests__/listTable.test.d.ts +2 -0
- package/dist/__tests__/listTable.test.d.ts.map +1 -0
- package/dist/__tests__/mediaLanguages.test.d.ts +2 -0
- package/dist/__tests__/mediaLanguages.test.d.ts.map +1 -0
- package/dist/__tests__/runtimePages.test.d.ts +2 -0
- package/dist/__tests__/runtimePages.test.d.ts.map +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/module.d.mts +2 -0
- package/dist/module.d.ts.map +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +23 -2
- package/dist/runtime/assets/main.css +1 -1
- package/dist/runtime/components/MapoConfirmDialog.vue +23 -4
- package/dist/runtime/components/MapoConfirmDialog.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoDetail.vue +301 -63
- package/dist/runtime/components/MapoDetail.vue.d.ts +191 -9
- package/dist/runtime/components/MapoDetail.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoDetailExtensions.vue +24 -0
- package/dist/runtime/components/MapoDetailExtensions.vue.d.ts +15 -0
- package/dist/runtime/components/MapoDetailExtensions.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoDetailLangSwitch.vue +22 -26
- package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts +4 -3
- package/dist/runtime/components/MapoDetailLangSwitch.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoDropArea.vue +5 -1
- package/dist/runtime/components/MapoDropArea.vue.d.ts +1 -1
- package/dist/runtime/components/MapoDropArea.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoLangSwitcher.vue +39 -0
- package/dist/runtime/components/MapoLangSwitcher.vue.d.ts +18 -0
- package/dist/runtime/components/MapoLangSwitcher.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoList.vue +7 -3
- package/dist/runtime/components/MapoList.vue.d.ts +14 -4
- package/dist/runtime/components/MapoList.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListActions.vue +27 -13
- package/dist/runtime/components/MapoListActions.vue.d.ts +4 -0
- package/dist/runtime/components/MapoListActions.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListFilters.vue +4 -2
- package/dist/runtime/components/MapoListFilters.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListQuickEdit.vue +12 -8
- package/dist/runtime/components/MapoListQuickEdit.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoListTable.vue +116 -45
- package/dist/runtime/components/MapoListTable.vue.d.ts +11 -6
- package/dist/runtime/components/MapoListTable.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoLogin.vue +13 -10
- package/dist/runtime/components/MapoLogin.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoLogoutButton.vue +4 -2
- package/dist/runtime/components/MapoLogoutButton.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaBreadcrumbs.vue +3 -1
- package/dist/runtime/components/MapoMediaBreadcrumbs.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaEditor.vue +36 -20
- package/dist/runtime/components/MapoMediaEditor.vue.d.ts +1 -0
- package/dist/runtime/components/MapoMediaEditor.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaFileChanger.vue +7 -3
- package/dist/runtime/components/MapoMediaFileChanger.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaFolders.vue +36 -14
- package/dist/runtime/components/MapoMediaFolders.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaGallery.vue +15 -5
- package/dist/runtime/components/MapoMediaGallery.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaManager.vue +17 -7
- package/dist/runtime/components/MapoMediaManager.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaManagerDialog.vue +8 -4
- package/dist/runtime/components/MapoMediaManagerDialog.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMediaUploader.vue +53 -29
- package/dist/runtime/components/MapoMediaUploader.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoMenuManager.vue +293 -0
- package/dist/runtime/components/MapoMenuManager.vue.d.ts +92 -0
- package/dist/runtime/components/MapoMenuManager.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMenuNodeEditor.vue +201 -0
- package/dist/runtime/components/MapoMenuNodeEditor.vue.d.ts +61 -0
- package/dist/runtime/components/MapoMenuNodeEditor.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMenuTreeview.vue +181 -0
- package/dist/runtime/components/MapoMenuTreeview.vue.d.ts +57 -0
- package/dist/runtime/components/MapoMenuTreeview.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoMenuTreeviewNode.vue +175 -0
- package/dist/runtime/components/MapoMenuTreeviewNode.vue.d.ts +27 -0
- package/dist/runtime/components/MapoMenuTreeviewNode.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoSidebar.vue +3 -1
- package/dist/runtime/components/MapoSidebar.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoSidebarList.vue +1 -1
- package/dist/runtime/components/MapoSidebarProfile.vue +6 -2
- package/dist/runtime/components/MapoSidebarProfile.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoSnackBar.vue +11 -0
- package/dist/runtime/components/MapoSnackBar.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoThemeToggle.vue +5 -1
- package/dist/runtime/components/MapoThemeToggle.vue.d.ts.map +1 -1
- package/dist/runtime/components/menuDndContext.d.ts +19 -0
- package/dist/runtime/components/menuDndContext.d.ts.map +1 -0
- package/dist/runtime/components/menuDndContext.js +3 -0
- package/dist/runtime/composables/defineDetailExtension.d.ts +32 -0
- package/dist/runtime/composables/defineDetailExtension.d.ts.map +1 -0
- package/dist/runtime/composables/defineDetailExtension.js +34 -0
- package/dist/runtime/composables/useMapoDetail.d.ts +18 -0
- package/dist/runtime/composables/useMapoDetail.d.ts.map +1 -0
- package/dist/runtime/composables/useMapoDetail.js +5 -0
- package/dist/runtime/page-meta.nuxt.d.ts +4 -0
- package/dist/runtime/pages/index.vue +4 -2
- package/dist/runtime/pages/index.vue.d.ts.map +1 -1
- package/dist/runtime/plugins/media-adapter.d.ts.map +1 -1
- package/dist/runtime/plugins/media-adapter.js +2 -1
- package/dist/runtime/stores/media.d.ts +8 -2
- package/dist/runtime/stores/media.d.ts.map +1 -1
- package/dist/runtime/stores/media.js +45 -13
- package/dist/runtime/types/detail.d.ts +167 -0
- package/dist/runtime/types/detail.d.ts.map +1 -0
- package/dist/runtime/types/detail.js +0 -0
- package/dist/runtime/types/list.d.ts +10 -2
- package/dist/runtime/types/list.d.ts.map +1 -1
- package/dist/runtime/types/menu.d.ts +66 -0
- package/dist/runtime/types/menu.d.ts.map +1 -0
- package/dist/runtime/types/menu.js +30 -0
- package/dist/runtime/utils/formValues.d.ts +8 -0
- package/dist/runtime/utils/formValues.d.ts.map +1 -0
- package/dist/runtime/utils/formValues.js +19 -0
- package/dist/runtime/utils/langInfo.d.ts +30 -0
- package/dist/runtime/utils/langInfo.d.ts.map +1 -0
- package/dist/runtime/utils/langInfo.js +8 -0
- package/dist/runtime/utils/listTable.d.ts +29 -0
- package/dist/runtime/utils/listTable.d.ts.map +1 -0
- package/dist/runtime/utils/listTable.js +21 -0
- package/package.json +12 -10
- package/src/__tests__/MapoConfirmDialog.component.test.ts +165 -0
- package/src/__tests__/MapoDetail.component.test.ts +1107 -0
- package/src/__tests__/MapoDetailLangSwitch.component.test.ts +145 -0
- package/src/__tests__/MapoListActions.component.test.ts +175 -0
- package/src/__tests__/MapoListTable.component.test.ts +504 -0
- package/src/__tests__/MapoSnackBar.component.test.ts +79 -0
- package/src/__tests__/__mocks__/nuxt-app.ts +8 -0
- package/src/__tests__/formValues.test.ts +31 -0
- package/src/__tests__/langInfo.test.ts +48 -0
- package/src/__tests__/listTable.test.ts +82 -0
- package/src/__tests__/mediaLanguages.test.ts +66 -0
- package/src/__tests__/runtimePages.test.ts +17 -0
- package/src/index.ts +20 -0
- package/src/module.ts +29 -0
- package/src/runtime/assets/main.css +13 -0
- package/src/runtime/components/MapoConfirmDialog.vue +33 -4
- package/src/runtime/components/MapoDetail.vue +520 -89
- package/src/runtime/components/MapoDetailExtensions.vue +39 -0
- package/src/runtime/components/MapoDetailLangSwitch.vue +27 -28
- package/src/runtime/components/MapoDropArea.vue +6 -1
- package/src/runtime/components/MapoLangSwitcher.vue +74 -0
- package/src/runtime/components/MapoList.vue +21 -6
- package/src/runtime/components/MapoListActions.vue +32 -14
- package/src/runtime/components/MapoListFilters.vue +5 -2
- package/src/runtime/components/MapoListQuickEdit.vue +12 -9
- package/src/runtime/components/MapoListTable.vue +147 -55
- package/src/runtime/components/MapoLogin.vue +13 -10
- package/src/runtime/components/MapoLogoutButton.vue +4 -2
- package/src/runtime/components/MapoMediaBreadcrumbs.vue +3 -1
- package/src/runtime/components/MapoMediaEditor.vue +43 -20
- package/src/runtime/components/MapoMediaFileChanger.vue +8 -3
- package/src/runtime/components/MapoMediaFolders.vue +37 -15
- package/src/runtime/components/MapoMediaGallery.vue +17 -5
- package/src/runtime/components/MapoMediaManager.vue +17 -7
- package/src/runtime/components/MapoMediaManagerDialog.vue +10 -4
- package/src/runtime/components/MapoMediaUploader.vue +60 -29
- package/src/runtime/components/MapoMenuManager.vue +437 -0
- package/src/runtime/components/MapoMenuNodeEditor.vue +282 -0
- package/src/runtime/components/MapoMenuTreeview.vue +264 -0
- package/src/runtime/components/MapoMenuTreeviewNode.vue +234 -0
- package/src/runtime/components/MapoSidebar.vue +3 -1
- package/src/runtime/components/MapoSidebarList.vue +1 -1
- package/src/runtime/components/MapoSidebarProfile.vue +6 -2
- package/src/runtime/components/MapoSnackBar.vue +12 -0
- package/src/runtime/components/MapoThemeToggle.vue +5 -1
- package/src/runtime/components/menuDndContext.ts +22 -0
- package/src/runtime/composables/defineDetailExtension.ts +78 -0
- package/src/runtime/composables/useMapoDetail.ts +24 -0
- package/src/runtime/page-meta.nuxt.d.ts +4 -0
- package/src/runtime/pages/index.vue +5 -2
- package/src/runtime/plugins/media-adapter.ts +9 -5
- package/src/runtime/stores/media.ts +61 -13
- package/src/runtime/types/detail.ts +178 -0
- package/src/runtime/types/list.ts +10 -2
- package/src/runtime/types/menu.ts +105 -0
- package/src/runtime/utils/formValues.ts +28 -0
- package/src/runtime/utils/langInfo.ts +38 -0
- package/src/runtime/utils/listTable.ts +54 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
import { useMapoDetail } from "../composables/useMapoDetail";
|
|
4
|
+
import { detailExtensions } from "../composables/defineDetailExtension";
|
|
5
|
+
import type { DetailExtensionPlacement } from "../types/detail";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Renders the extensions registered with `defineDetailExtension()` for one
|
|
9
|
+
* placement of the surrounding `MapoDetail`, in their order. `MapoDetail` uses
|
|
10
|
+
* it itself; place it in a slot that replaces one of those places, such as
|
|
11
|
+
* `side-buttons`, to keep the extensions there.
|
|
12
|
+
*/
|
|
13
|
+
const props = defineProps<{
|
|
14
|
+
/** Which extensions: `actions` or `body-top`. */
|
|
15
|
+
placement: DetailExtensionPlacement;
|
|
16
|
+
}>();
|
|
17
|
+
|
|
18
|
+
const detail = useMapoDetail();
|
|
19
|
+
const registry = detailExtensions();
|
|
20
|
+
|
|
21
|
+
const shown = computed(() => {
|
|
22
|
+
if (!detail) return [];
|
|
23
|
+
const allowed = detail.extensions.value;
|
|
24
|
+
if (allowed === false) return [];
|
|
25
|
+
return registry
|
|
26
|
+
.filter((extension) => extension.placement === props.placement)
|
|
27
|
+
.filter((extension) => allowed === true || allowed.includes(extension.key))
|
|
28
|
+
.filter((extension) => extension.visible?.(detail) ?? true)
|
|
29
|
+
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
30
|
+
});
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
<template>
|
|
34
|
+
<component
|
|
35
|
+
:is="extension.component"
|
|
36
|
+
v-for="extension in shown"
|
|
37
|
+
:key="extension.key"
|
|
38
|
+
/>
|
|
39
|
+
</template>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { ref, computed, watch, onMounted, nextTick } from "vue";
|
|
3
|
-
import { useRoute, useRouter } from "
|
|
3
|
+
import { useRoute, useRouter } from "#app";
|
|
4
4
|
|
|
5
5
|
const props = withDefaults(
|
|
6
6
|
defineProps<{
|
|
@@ -9,8 +9,9 @@ const props = withDefaults(
|
|
|
9
9
|
errors?: Record<string, string[]>;
|
|
10
10
|
noRouteChange?: boolean;
|
|
11
11
|
/**
|
|
12
|
-
* Number of languages above which
|
|
13
|
-
*
|
|
12
|
+
* Number of languages above which a searchable select appears next to the
|
|
13
|
+
* tab bar, for quick navigation. Default: `8`. `0` always shows it,
|
|
14
|
+
* `Infinity` never does.
|
|
14
15
|
*/
|
|
15
16
|
langThreshold?: number;
|
|
16
17
|
}>(),
|
|
@@ -69,6 +70,9 @@ function onSelectChange(v: unknown) {
|
|
|
69
70
|
|
|
70
71
|
// ─── Select menu items ────────────────────────────────────────────────────────
|
|
71
72
|
|
|
73
|
+
// A few languages fit in the tab bar; the select only helps once they overflow it.
|
|
74
|
+
const showSelect = computed(() => props.langs.length > props.langThreshold);
|
|
75
|
+
|
|
72
76
|
const selectItems = computed(() =>
|
|
73
77
|
props.langs.map((lang) => ({
|
|
74
78
|
label: lang.toUpperCase(),
|
|
@@ -106,26 +110,21 @@ watch(
|
|
|
106
110
|
<div
|
|
107
111
|
class="flex items-end gap-0 border-b border-gray-200 dark:border-gray-700 mt-2 mb-4"
|
|
108
112
|
>
|
|
109
|
-
<!-- Language select —
|
|
110
|
-
<
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
:trailing-icon="
|
|
125
|
-
open ? 'i-lucide-chevron-up' : 'i-lucide-chevron-down'
|
|
126
|
-
"
|
|
127
|
-
class="w-full justify-between font-medium"
|
|
128
|
-
>
|
|
113
|
+
<!-- Language select — above langThreshold only, aligned at bottom of row -->
|
|
114
|
+
<template v-if="showSelect">
|
|
115
|
+
<USelectMenu
|
|
116
|
+
:model-value="modelValue"
|
|
117
|
+
:items="selectItems"
|
|
118
|
+
value-key="value"
|
|
119
|
+
label-key="label"
|
|
120
|
+
size="sm"
|
|
121
|
+
variant="ghost"
|
|
122
|
+
class="w-28 shrink-0 mb-px font-medium"
|
|
123
|
+
@update:model-value="onSelectChange"
|
|
124
|
+
>
|
|
125
|
+
<!-- The trigger is already a button with its own chevron: the slot
|
|
126
|
+
holds only what it shows, never another button. -->
|
|
127
|
+
<template #default>
|
|
129
128
|
<span class="flex items-center gap-1">
|
|
130
129
|
<span
|
|
131
130
|
v-if="hasErrors(modelValue)"
|
|
@@ -133,12 +132,12 @@ watch(
|
|
|
133
132
|
/>
|
|
134
133
|
{{ modelValue.toUpperCase() }}
|
|
135
134
|
</span>
|
|
136
|
-
</
|
|
137
|
-
</
|
|
138
|
-
</USelectMenu>
|
|
135
|
+
</template>
|
|
136
|
+
</USelectMenu>
|
|
139
137
|
|
|
140
|
-
|
|
141
|
-
|
|
138
|
+
<!-- Divider -->
|
|
139
|
+
<div class="h-5 w-px bg-gray-200 dark:bg-gray-700 mx-2 shrink-0" />
|
|
140
|
+
</template>
|
|
142
141
|
|
|
143
142
|
<!-- Tab bar — always shown, scrollable -->
|
|
144
143
|
<div class="flex gap-1 overflow-x-auto scrollbar-none flex-1">
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { ref } from "vue";
|
|
3
|
+
import { useI18n } from "vue-i18n";
|
|
4
|
+
|
|
5
|
+
const { t } = useI18n();
|
|
3
6
|
|
|
4
7
|
const props = withDefaults(
|
|
5
8
|
defineProps<{
|
|
@@ -103,7 +106,9 @@ defineExpose({ triggerPick });
|
|
|
103
106
|
>
|
|
104
107
|
<div class="flex flex-col items-center gap-2 text-primary">
|
|
105
108
|
<UIcon name="i-lucide-upload-cloud" class="size-10" />
|
|
106
|
-
<span class="text-sm font-medium">
|
|
109
|
+
<span class="text-sm font-medium">{{
|
|
110
|
+
t("mapo.dropArea.dropHere")
|
|
111
|
+
}}</span>
|
|
107
112
|
</div>
|
|
108
113
|
</div>
|
|
109
114
|
</Transition>
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
import type { Ref } from "vue";
|
|
4
|
+
import { useI18n } from "vue-i18n";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* UI locale switcher — lists the locales configured in `@nuxtjs/i18n`
|
|
8
|
+
* (via `@mapomodule/i18n`) and switches the interface language with
|
|
9
|
+
* cookie persistence. Port of the v1 `LangSwitcher`.
|
|
10
|
+
*/
|
|
11
|
+
const props = withDefaults(
|
|
12
|
+
defineProps<{
|
|
13
|
+
/** Show the flag emoji derived from the locale `language` tag. */
|
|
14
|
+
flags?: boolean;
|
|
15
|
+
/** Nuxt UI USelectMenu `size` prop. */
|
|
16
|
+
size?: "xs" | "sm" | "md" | "lg" | "xl";
|
|
17
|
+
}>(),
|
|
18
|
+
{ flags: true, size: "sm" },
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
interface SwitcherLocale {
|
|
22
|
+
code: string;
|
|
23
|
+
name?: string;
|
|
24
|
+
language?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// `locales` and `setLocale` are @nuxtjs/i18n Composer extensions; the uikit
|
|
28
|
+
// package only depends on vue-i18n types, so they are typed structurally.
|
|
29
|
+
const { locale, locales, setLocale } = useI18n() as unknown as {
|
|
30
|
+
locale: Ref<string>;
|
|
31
|
+
locales: Ref<SwitcherLocale[]>;
|
|
32
|
+
setLocale: (code: string) => Promise<void>;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/** Regional-indicator flag emoji from a BCP-47 tag (e.g. `en-US` → 🇺🇸). */
|
|
36
|
+
function getFlag(language?: string): string {
|
|
37
|
+
const region = language?.split("-").at(-1);
|
|
38
|
+
if (!region || region.length !== 2 || !/^[A-Za-z]+$/.test(region)) return "";
|
|
39
|
+
const codePoints = region
|
|
40
|
+
.toUpperCase()
|
|
41
|
+
.split("")
|
|
42
|
+
.map((char) => 127397 + char.charCodeAt(0));
|
|
43
|
+
return String.fromCodePoint(...codePoints);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const items = computed(() =>
|
|
47
|
+
locales.value.map((l) => ({
|
|
48
|
+
label:
|
|
49
|
+
props.flags && getFlag(l.language)
|
|
50
|
+
? `${getFlag(l.language)} ${l.name ?? l.code.toUpperCase()}`
|
|
51
|
+
: (l.name ?? l.code.toUpperCase()),
|
|
52
|
+
value: l.code,
|
|
53
|
+
})),
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const current = computed({
|
|
57
|
+
get: () => locale.value,
|
|
58
|
+
set: (code: string) => {
|
|
59
|
+
if (code && code !== locale.value) setLocale(code);
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<template>
|
|
65
|
+
<USelectMenu
|
|
66
|
+
v-model="current"
|
|
67
|
+
:items="items"
|
|
68
|
+
value-key="value"
|
|
69
|
+
label-key="label"
|
|
70
|
+
:size="size"
|
|
71
|
+
:search-input="false"
|
|
72
|
+
class="w-40"
|
|
73
|
+
/>
|
|
74
|
+
</template>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts" generic="T extends object">
|
|
2
|
-
import { ref, computed, watch, useSlots } from "vue";
|
|
2
|
+
import { ref, computed, watch, useSlots, onBeforeUnmount } from "vue";
|
|
3
3
|
import type { Ref } from "vue";
|
|
4
4
|
import type {
|
|
5
5
|
ListColumn,
|
|
@@ -11,7 +11,7 @@ import type {
|
|
|
11
11
|
} from "../types/list.js";
|
|
12
12
|
import type { AnyFieldDescriptor, FieldRegistry } from "@mapomodule/form/types";
|
|
13
13
|
import { debounce } from "@mapomodule/utils";
|
|
14
|
-
import { useRoute, useRouter } from "
|
|
14
|
+
import { useRoute, useRouter } from "#app";
|
|
15
15
|
|
|
16
16
|
const props = withDefaults(
|
|
17
17
|
defineProps<{
|
|
@@ -30,6 +30,7 @@ const props = withDefaults(
|
|
|
30
30
|
* Ignored when `items` is provided.
|
|
31
31
|
*/
|
|
32
32
|
clientSide?: boolean;
|
|
33
|
+
/** Column definitions. A dotted `key` (`category.name`) reads a field of a related object. */
|
|
33
34
|
columns: ListColumn<T>[];
|
|
34
35
|
lookup?: string;
|
|
35
36
|
// Filters
|
|
@@ -56,11 +57,20 @@ const props = withDefaults(
|
|
|
56
57
|
* hides the trash unless the user has `delete_article`. Omit to always show both.
|
|
57
58
|
*/
|
|
58
59
|
permissionModel?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Whether to include the built-in permanent delete bulk action.
|
|
62
|
+
* Defaults to `true`; custom `actions` are unaffected.
|
|
63
|
+
*/
|
|
64
|
+
defaultActions?: boolean;
|
|
59
65
|
// Pagination
|
|
60
|
-
/** Initial page size
|
|
61
|
-
defaultPageSize?: number;
|
|
62
|
-
/**
|
|
63
|
-
|
|
66
|
+
/** Initial page size: a number, or `"all"`. Default: 20. */
|
|
67
|
+
defaultPageSize?: number | "all";
|
|
68
|
+
/**
|
|
69
|
+
* Options of the per-page selector. `"all"` adds an option that requests
|
|
70
|
+
* the list without pagination params, like `clientSide` does: the backend
|
|
71
|
+
* has to return the whole collection then. Default: [10, 20, 50, 100].
|
|
72
|
+
*/
|
|
73
|
+
pageSizeOptions?: (number | "all")[];
|
|
64
74
|
/**
|
|
65
75
|
* Custom response parser. Replaces the built-in DRF / flat-array detection.
|
|
66
76
|
* Return `{ items, total }` from any shape your backend returns.
|
|
@@ -169,6 +179,9 @@ const writeUrlState = debounce(() => {
|
|
|
169
179
|
|
|
170
180
|
watch([activeTab, activeFilters], writeUrlState, { deep: true });
|
|
171
181
|
|
|
182
|
+
// A URL write still pending when the list goes away would land on the next page.
|
|
183
|
+
onBeforeUnmount(() => writeUrlState.cancel());
|
|
184
|
+
|
|
172
185
|
// --- crudEndpoint: base path for mutations (no query string). ---
|
|
173
186
|
const crudEndpoint = computed(
|
|
174
187
|
() => (props.endpoint ?? "").split("?")[0] || (props.endpoint ?? ""),
|
|
@@ -296,6 +309,8 @@ watch([activeTab, activeFilters], () => {
|
|
|
296
309
|
:selection-query="selectionQuery"
|
|
297
310
|
:endpoint="crudEndpoint"
|
|
298
311
|
:lookup="lookup"
|
|
312
|
+
:permission-model="permissionModel"
|
|
313
|
+
:default-actions="defaultActions"
|
|
299
314
|
@action-completed="refresh"
|
|
300
315
|
/>
|
|
301
316
|
</div>
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
<script setup lang="ts" generic="T extends object">
|
|
2
2
|
import { ref, computed } from "vue";
|
|
3
|
+
import { useI18n } from "vue-i18n";
|
|
3
4
|
import type { ActionDescriptor } from "../types/list.js";
|
|
4
5
|
import { useSnackStore } from "@mapomodule/store/runtime/stores/snack";
|
|
5
6
|
import { useConfirmStore } from "@mapomodule/store/runtime/stores/confirm";
|
|
6
7
|
import { usePermissions } from "@mapomodule/store/runtime/composables/usePermissions";
|
|
7
8
|
import { useCrud } from "@mapomodule/core/runtime/api/crud";
|
|
9
|
+
import { getErrorDetail } from "@mapomodule/core/runtime/utils/fetchError";
|
|
8
10
|
|
|
9
11
|
const props = withDefaults(
|
|
10
12
|
defineProps<{
|
|
@@ -13,10 +15,16 @@ const props = withDefaults(
|
|
|
13
15
|
selectionQuery: URLSearchParams;
|
|
14
16
|
endpoint: string;
|
|
15
17
|
lookup?: string;
|
|
18
|
+
/** Django model label used to gate the built-in permanent delete action. */
|
|
19
|
+
permissionModel?: string;
|
|
20
|
+
/** Whether to include the built-in permanent delete action. */
|
|
21
|
+
defaultActions?: boolean;
|
|
16
22
|
}>(),
|
|
17
23
|
{
|
|
18
24
|
actions: () => [],
|
|
19
25
|
lookup: "id",
|
|
26
|
+
permissionModel: undefined,
|
|
27
|
+
defaultActions: true,
|
|
20
28
|
},
|
|
21
29
|
);
|
|
22
30
|
|
|
@@ -29,15 +37,17 @@ defineSlots<{
|
|
|
29
37
|
append(): any;
|
|
30
38
|
}>();
|
|
31
39
|
|
|
40
|
+
const { t } = useI18n();
|
|
32
41
|
const snack = useSnackStore();
|
|
33
42
|
const confirm = useConfirmStore();
|
|
43
|
+
const { canDelete, checkPermission } = usePermissions();
|
|
34
44
|
const crud = useCrud<T>(props.endpoint);
|
|
35
45
|
|
|
36
46
|
const isRunning = ref(false);
|
|
37
47
|
|
|
38
|
-
const
|
|
48
|
+
const builtInActions = computed<ActionDescriptor<T>[]>(() => [
|
|
39
49
|
{
|
|
40
|
-
label: "
|
|
50
|
+
label: t("mapo.listActions.permanentDelete"),
|
|
41
51
|
handler: async ({ selection }) => {
|
|
42
52
|
if (!selection) return;
|
|
43
53
|
await Promise.all(
|
|
@@ -48,13 +58,15 @@ const defaultActions = computed<ActionDescriptor<T>[]>(() => [
|
|
|
48
58
|
),
|
|
49
59
|
);
|
|
50
60
|
},
|
|
51
|
-
permissions: "delete",
|
|
52
61
|
handleMultiple: true,
|
|
53
62
|
handleAll: false,
|
|
54
63
|
},
|
|
55
64
|
]);
|
|
56
65
|
|
|
57
|
-
const allActions = computed(() => [
|
|
66
|
+
const allActions = computed(() => [
|
|
67
|
+
...(props.defaultActions ? builtInActions.value : []),
|
|
68
|
+
...props.actions,
|
|
69
|
+
]);
|
|
58
70
|
|
|
59
71
|
const visibleActions = computed(() =>
|
|
60
72
|
allActions.value.filter((a) =>
|
|
@@ -77,13 +89,16 @@ const applyButtonColor = computed(() =>
|
|
|
77
89
|
);
|
|
78
90
|
|
|
79
91
|
function canRun(action: ActionDescriptor<T>): boolean {
|
|
92
|
+
if (builtInActions.value.includes(action)) {
|
|
93
|
+
return !props.permissionModel || canDelete(props.permissionModel);
|
|
94
|
+
}
|
|
95
|
+
|
|
80
96
|
const perms = action.permissions
|
|
81
97
|
? Array.isArray(action.permissions)
|
|
82
98
|
? action.permissions
|
|
83
99
|
: [action.permissions]
|
|
84
100
|
: [];
|
|
85
101
|
if (!perms.length) return true;
|
|
86
|
-
const { checkPermission } = usePermissions();
|
|
87
102
|
return perms.every((p) => checkPermission(p));
|
|
88
103
|
}
|
|
89
104
|
|
|
@@ -95,9 +110,11 @@ async function runAction() {
|
|
|
95
110
|
title: action.label,
|
|
96
111
|
message:
|
|
97
112
|
props.selection === "all"
|
|
98
|
-
? "
|
|
99
|
-
:
|
|
100
|
-
|
|
113
|
+
? t("mapo.listActions.confirmBulk")
|
|
114
|
+
: t("mapo.listActions.confirmBulkCount", {
|
|
115
|
+
count: (props.selection as T[]).length,
|
|
116
|
+
}),
|
|
117
|
+
confirmText: t("mapo.confirm"),
|
|
101
118
|
dangerous: !!action.dangerous,
|
|
102
119
|
});
|
|
103
120
|
if (!ok) return;
|
|
@@ -109,13 +126,14 @@ async function runAction() {
|
|
|
109
126
|
selectionQuery: props.selectionQuery,
|
|
110
127
|
lookup: props.lookup,
|
|
111
128
|
});
|
|
112
|
-
snack.show("
|
|
129
|
+
snack.show(t("mapo.listActions.actionCompleted"), "success");
|
|
113
130
|
emit("actionCompleted");
|
|
114
131
|
selectedLabel.value = undefined;
|
|
115
132
|
} catch (err: unknown) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
133
|
+
snack.show(
|
|
134
|
+
getErrorDetail(err) ?? t("mapo.listActions.actionFailed"),
|
|
135
|
+
"error",
|
|
136
|
+
);
|
|
119
137
|
} finally {
|
|
120
138
|
isRunning.value = false;
|
|
121
139
|
}
|
|
@@ -134,7 +152,7 @@ const isActive = computed(
|
|
|
134
152
|
:items="visibleActions"
|
|
135
153
|
value-key="label"
|
|
136
154
|
label-key="label"
|
|
137
|
-
placeholder="
|
|
155
|
+
:placeholder="t('mapo.listActions.bulkActions')"
|
|
138
156
|
size="sm"
|
|
139
157
|
class="min-w-48"
|
|
140
158
|
/>
|
|
@@ -145,7 +163,7 @@ const isActive = computed(
|
|
|
145
163
|
:disabled="!selectedAction || !canRun(selectedAction)"
|
|
146
164
|
@click="runAction"
|
|
147
165
|
>
|
|
148
|
-
|
|
166
|
+
{{ t("mapo.apply") }}
|
|
149
167
|
</UButton>
|
|
150
168
|
<slot name="append" />
|
|
151
169
|
</div>
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { ref, computed, watch } from "vue";
|
|
3
|
+
import { useI18n } from "vue-i18n";
|
|
3
4
|
import type {
|
|
4
5
|
FilterDescriptor,
|
|
5
6
|
ActiveFilter,
|
|
6
7
|
FilterChoice,
|
|
7
8
|
} from "../types/list.js";
|
|
8
9
|
|
|
10
|
+
const { t } = useI18n();
|
|
11
|
+
|
|
9
12
|
const props = defineProps<{
|
|
10
13
|
filters: FilterDescriptor[];
|
|
11
14
|
modelValue: ActiveFilter[];
|
|
@@ -188,7 +191,7 @@ const isOpen = ref(false);
|
|
|
188
191
|
color="neutral"
|
|
189
192
|
@click="removeAll"
|
|
190
193
|
>
|
|
191
|
-
|
|
194
|
+
{{ t("mapo.listFilters.clearAll") }}
|
|
192
195
|
</UButton>
|
|
193
196
|
|
|
194
197
|
<!-- Filter dropdown button -->
|
|
@@ -201,7 +204,7 @@ const isOpen = ref(false);
|
|
|
201
204
|
:disabled="disabled"
|
|
202
205
|
trailing-icon=""
|
|
203
206
|
>
|
|
204
|
-
|
|
207
|
+
{{ t("mapo.listFilters.filters") }}
|
|
205
208
|
</UButton>
|
|
206
209
|
|
|
207
210
|
<template #content>
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
<script setup lang="ts" generic="T extends object">
|
|
2
2
|
import { ref, computed, watch } from "vue";
|
|
3
|
+
import { useI18n } from "vue-i18n";
|
|
3
4
|
import type { Ref } from "vue";
|
|
4
5
|
import type { AnyFieldDescriptor, FieldRegistry } from "@mapomodule/form/types";
|
|
5
6
|
import { useSnackStore } from "@mapomodule/store/runtime/stores/snack";
|
|
6
7
|
import { useCrud } from "@mapomodule/core/runtime/api/crud";
|
|
8
|
+
import { getErrorDetail } from "@mapomodule/core/runtime/utils/fetchError";
|
|
7
9
|
|
|
8
10
|
const props = withDefaults(
|
|
9
11
|
defineProps<{
|
|
@@ -45,6 +47,7 @@ defineSlots<{
|
|
|
45
47
|
extra(props: { model: T }): any;
|
|
46
48
|
}>();
|
|
47
49
|
|
|
50
|
+
const { t } = useI18n();
|
|
48
51
|
const snack = useSnackStore();
|
|
49
52
|
const crud = useCrud<T>(props.endpoint);
|
|
50
53
|
|
|
@@ -77,7 +80,7 @@ watch(
|
|
|
77
80
|
try {
|
|
78
81
|
model.value = await crud.detail(id as string | number);
|
|
79
82
|
} catch {
|
|
80
|
-
snack.show("
|
|
83
|
+
snack.show(t("mapo.loadItemError"), "error");
|
|
81
84
|
isOpen.value = false;
|
|
82
85
|
} finally {
|
|
83
86
|
loading.value = false;
|
|
@@ -91,7 +94,7 @@ async function save() {
|
|
|
91
94
|
// Offline: no backend roundtrip — emit the locally edited model and let
|
|
92
95
|
// the parent splice it back into the source array.
|
|
93
96
|
if (props.offline) {
|
|
94
|
-
snack.show("
|
|
97
|
+
snack.show(t("mapo.saveSuccess"), "success");
|
|
95
98
|
emit("saved", { ...model.value } as T);
|
|
96
99
|
isOpen.value = false;
|
|
97
100
|
return;
|
|
@@ -100,13 +103,11 @@ async function save() {
|
|
|
100
103
|
props.itemId != null
|
|
101
104
|
? await crud.partialUpdate(props.itemId as string | number, model.value)
|
|
102
105
|
: await crud.create(model.value);
|
|
103
|
-
snack.show("
|
|
106
|
+
snack.show(t("mapo.saveSuccess"), "success");
|
|
104
107
|
emit("saved", result);
|
|
105
108
|
isOpen.value = false;
|
|
106
109
|
} catch (err: unknown) {
|
|
107
|
-
|
|
108
|
-
?.response?.data?.detail;
|
|
109
|
-
snack.show(detail ?? "Failed to save", "error");
|
|
110
|
+
snack.show(getErrorDetail(err) ?? t("mapo.saveError"), "error");
|
|
110
111
|
} finally {
|
|
111
112
|
saving.value = false;
|
|
112
113
|
}
|
|
@@ -119,7 +120,9 @@ async function save() {
|
|
|
119
120
|
<div class="p-6 space-y-4">
|
|
120
121
|
<div class="flex items-center justify-between">
|
|
121
122
|
<h3 class="text-base font-semibold text-highlighted">
|
|
122
|
-
{{
|
|
123
|
+
{{
|
|
124
|
+
itemId != null ? t("mapo.edit") : t("mapo.listQuickEdit.newItem")
|
|
125
|
+
}}
|
|
123
126
|
</h3>
|
|
124
127
|
<UButton
|
|
125
128
|
size="xs"
|
|
@@ -150,10 +153,10 @@ async function save() {
|
|
|
150
153
|
|
|
151
154
|
<div class="flex justify-end gap-2 pt-2">
|
|
152
155
|
<UButton variant="ghost" color="neutral" @click="isOpen = false">
|
|
153
|
-
|
|
156
|
+
{{ t("mapo.cancel") }}
|
|
154
157
|
</UButton>
|
|
155
158
|
<UButton color="primary" :loading="saving" @click="save">
|
|
156
|
-
|
|
159
|
+
{{ t("mapo.save") }}
|
|
157
160
|
</UButton>
|
|
158
161
|
</div>
|
|
159
162
|
</template>
|