@data-fair/lib-vuetify 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.
@@ -0,0 +1,103 @@
1
+ /// <reference types=".vue-global-types/vue_3.5_false.d.ts" />
2
+ import { computed } from 'vue';
3
+ const { defineProps, defineSlots, defineEmits, defineExpose, defineModel, defineOptions, withDefaults, } = await import('vue');
4
+ const ownerProps = defineProps({
5
+ owner: {
6
+ type: Object,
7
+ default: null
8
+ }
9
+ });
10
+ const avatarUrl = computed(() => {
11
+ if (ownerProps.owner.department)
12
+ return `/simple-directory/api/avatars/${ownerProps.owner.type}/${ownerProps.owner.id}/${ownerProps.owner.department}/avatar.png`;
13
+ else
14
+ return `/simple-directory/api/avatars/${ownerProps.owner.type}/${ownerProps.owner.id}/avatar.png`;
15
+ });
16
+ const label = computed(() => {
17
+ let label = ownerProps.owner.name;
18
+ if (ownerProps.owner.department)
19
+ label += ' - ' + (ownerProps.owner.departmentName || ownerProps.owner.department);
20
+ if (ownerProps.owner.role)
21
+ label += ` (${ownerProps.owner.role})`;
22
+ return label;
23
+ });
24
+ const __VLS_fnComponent = (await import('vue')).defineComponent({
25
+ props: {
26
+ owner: {
27
+ type: Object,
28
+ default: null
29
+ }
30
+ },
31
+ });
32
+ ;
33
+ let __VLS_functionalComponentProps;
34
+ function __VLS_template() {
35
+ const __VLS_ctx = {};
36
+ const __VLS_localComponents = {
37
+ ...{},
38
+ ...{},
39
+ ...__VLS_ctx,
40
+ };
41
+ let __VLS_components;
42
+ const __VLS_localDirectives = {
43
+ ...{},
44
+ ...__VLS_ctx,
45
+ };
46
+ let __VLS_directives;
47
+ let __VLS_styleScopedClasses;
48
+ // CSS variable injection
49
+ // CSS variable injection end
50
+ let __VLS_resolvedLocalAndGlobalComponents;
51
+ const __VLS_0 = __VLS_resolvedLocalAndGlobalComponents.VTooltip;
52
+ /** @type { [typeof __VLS_components.VTooltip, typeof __VLS_components.vTooltip, typeof __VLS_components.VTooltip, typeof __VLS_components.vTooltip, ] } */
53
+ // @ts-ignore
54
+ const __VLS_1 = __VLS_asFunctionalComponent(__VLS_0, new __VLS_0({ location: ("top"), }));
55
+ const __VLS_2 = __VLS_1({ location: ("top"), }, ...__VLS_functionalComponentArgsRest(__VLS_1));
56
+ __VLS_elementAsFunction(__VLS_intrinsicElements.template, __VLS_intrinsicElements.template)({});
57
+ {
58
+ const { activator: __VLS_thisSlot } = __VLS_nonNullable(__VLS_5.slots);
59
+ const [{ props }] = __VLS_getSlotParams(__VLS_thisSlot);
60
+ __VLS_elementAsFunction(__VLS_intrinsicElements.span, __VLS_intrinsicElements.span)({ ...(props), ...{ class: ("text-body-2") }, });
61
+ const __VLS_6 = __VLS_resolvedLocalAndGlobalComponents.VAvatar;
62
+ /** @type { [typeof __VLS_components.VAvatar, typeof __VLS_components.vAvatar, typeof __VLS_components.VAvatar, typeof __VLS_components.vAvatar, ] } */
63
+ // @ts-ignore
64
+ const __VLS_7 = __VLS_asFunctionalComponent(__VLS_6, new __VLS_6({ size: ((28)), }));
65
+ const __VLS_8 = __VLS_7({ size: ((28)), }, ...__VLS_functionalComponentArgsRest(__VLS_7));
66
+ __VLS_elementAsFunction(__VLS_intrinsicElements.img, __VLS_intrinsicElements.img)({ src: ((__VLS_ctx.avatarUrl)), ...{ style: ({}) }, });
67
+ __VLS_nonNullable(__VLS_11.slots).default;
68
+ const __VLS_11 = __VLS_pickFunctionalComponentCtx(__VLS_6, __VLS_8);
69
+ }
70
+ (__VLS_ctx.label);
71
+ const __VLS_5 = __VLS_pickFunctionalComponentCtx(__VLS_0, __VLS_2);
72
+ __VLS_styleScopedClasses['text-body-2'];
73
+ var __VLS_slots;
74
+ var __VLS_inheritedAttrs;
75
+ const __VLS_refs = {};
76
+ var $refs;
77
+ return {
78
+ slots: __VLS_slots,
79
+ refs: $refs,
80
+ attrs: {},
81
+ };
82
+ }
83
+ ;
84
+ const __VLS_self = (await import('vue')).defineComponent({
85
+ setup() {
86
+ return {
87
+ $props: __VLS_makeOptional(ownerProps),
88
+ ...ownerProps,
89
+ avatarUrl: avatarUrl,
90
+ label: label,
91
+ };
92
+ },
93
+ });
94
+ export default (await import('vue')).defineComponent({
95
+ setup() {
96
+ return {
97
+ $props: __VLS_makeOptional(ownerProps),
98
+ ...ownerProps,
99
+ };
100
+ },
101
+ });
102
+ ;
103
+ //# sourceMappingURL=owner-avatar.vue.js.map
package/owner-pick.vue ADDED
@@ -0,0 +1,123 @@
1
+ <template lang="html">
2
+ <v-row>
3
+ <v-col>
4
+ <template v-if="status === 'loading'">
5
+ <v-progress-linear
6
+ indeterminate
7
+ color="primary"
8
+ />
9
+ </template>
10
+ <template v-if="status === 'ok'">
11
+ <p>{{ message || t('message') }}</p>
12
+ <v-radio-group
13
+ v-if="model"
14
+ v-model="model"
15
+ class="my-3 ml-2"
16
+ >
17
+ <v-radio
18
+ v-for="(owner, $index) in owners"
19
+ :key="$index"
20
+ :label="getLabel(owner)"
21
+ :value="owner"
22
+ />
23
+ </v-radio-group>
24
+ </template>
25
+ </v-col>
26
+ </v-row>
27
+ </template>
28
+
29
+ <i18n lang="yaml">
30
+ fr:
31
+ yourself: Compte personnel
32
+ org: Organisation
33
+ message: Choisissez un propriétaire
34
+ en:
35
+ yourself: Personal account
36
+ org: Organization
37
+ message: Choisissez un propriétaire
38
+ </i18n>
39
+
40
+ <script setup>
41
+ import { watch, computed } from 'vue'
42
+ import { computedAsync } from '@vueuse/core'
43
+ import { ofetch } from 'ofetch'
44
+ import { useI18n } from 'vue-i18n'
45
+ import { useSessionAuthenticated } from '@data-fair/lib/vue/session.js'
46
+
47
+ const { t } = useI18n({ useScope: 'local' })
48
+
49
+ const props = defineProps({
50
+ otherAccounts: { type: Boolean, default: false },
51
+ hideSingle: { type: Boolean, default: true },
52
+ message: { type: String, default: null }
53
+ })
54
+
55
+ const model = defineModel({ type: Object, default: null })
56
+ const ready = defineModel('ready', { type: Boolean, default: false })
57
+
58
+ const session = useSessionAuthenticated()
59
+
60
+ const owners = computedAsync(async () => {
61
+ const user = session.state.user
62
+
63
+ /** @type {import('@data-fair/lib-common-types/session').Account[]} */
64
+ const owners = []
65
+ if (props.otherAccounts || session.state.account.type === 'user') {
66
+ owners.push({ type: 'user', id: user.id, name: user.name })
67
+ }
68
+ for (const o of user.organizations.filter(o => ['contrib', 'admin'].includes(o.role))) {
69
+ if (!props.otherAccounts) {
70
+ if (session.state.account.type !== 'organization' || o.id !== session.state.account.id) {
71
+ continue
72
+ }
73
+ if (session.state.account.department && session.state.account.department !== o.department) {
74
+ continue
75
+ }
76
+ }
77
+ if (o.department && !owners.find(ow => ow.type === 'organization' && ow.id === o.id && ow.department === o.department)) {
78
+ owners.push({ type: 'organization', id: o.id, name: o.name, department: o.department, departmentName: o.departmentName || '' })
79
+ }
80
+ if (!o.department) {
81
+ const org = await ofetch(`/simple-directory/api/organizations/${o.id}`)
82
+ owners.push({ type: 'organization', id: o.id, name: o.name })
83
+ if (!org.departments) continue
84
+ for (const dep of org.departments) {
85
+ if (!owners.find(ow => ow.type === 'organization' && ow.id === o.id && ow.department === dep.id)) {
86
+ owners.push({ type: 'organization', id: o.id, name: o.name, department: dep.id, departmentName: dep.name })
87
+ }
88
+ }
89
+ }
90
+ }
91
+
92
+ return owners
93
+ })
94
+
95
+ /**
96
+ * @param {import('@data-fair/lib-common-types/session').Account} owner
97
+ */
98
+ const getLabel = (owner) => {
99
+ if (owner.type === 'user' && owner.id === session.state.user?.id) return t('yourself')
100
+ if (owner.type === 'organization') {
101
+ if (owner.department) return `${t('org')} ${owner.name} / ${owner.departmentName || owner.department}`
102
+ else return `${t('org')} ${owner.name}`
103
+ }
104
+ return owner.name
105
+ }
106
+
107
+ watch(owners, () => {
108
+ if (!model.value && owners.value?.length) {
109
+ model.value = owners.value[0]
110
+ }
111
+ if (owners.value) {
112
+ ready.value = true
113
+ }
114
+ })
115
+
116
+ const status = computed(() => {
117
+ if (!owners.value) return 'loading'
118
+ if (owners.value.length === 0) return 'hidden'
119
+ if (props.hideSingle && owners.value.length === 1) return 'hidden'
120
+ return 'ok'
121
+ })
122
+
123
+ </script>
@@ -0,0 +1,11 @@
1
+ declare const _default: import("vue").DefineComponent<{}, {
2
+ otherAccounts: boolean;
3
+ hideSingle: boolean;
4
+ message: string;
5
+ $props: {
6
+ readonly otherAccounts?: boolean | undefined;
7
+ readonly hideSingle?: boolean | undefined;
8
+ readonly message?: string | undefined;
9
+ };
10
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
11
+ export default _default;
@@ -0,0 +1,186 @@
1
+ /// <reference types=".vue-global-types/vue_3.5_false.d.ts" />
2
+ import { watch, computed } from 'vue';
3
+ import { computedAsync } from '@vueuse/core';
4
+ import { ofetch } from 'ofetch';
5
+ import { useI18n } from 'vue-i18n';
6
+ import { useSessionAuthenticated } from '@data-fair/lib/vue/session.js';
7
+ const { defineProps, defineSlots, defineEmits, defineExpose, defineModel, defineOptions, withDefaults, } = await import('vue');
8
+ const { t } = useI18n({ useScope: 'local' });
9
+ const props = defineProps({
10
+ otherAccounts: { type: Boolean, default: false },
11
+ hideSingle: { type: Boolean, default: true },
12
+ message: { type: String, default: null }
13
+ });
14
+ const model = defineModel({ type: Object, default: null });
15
+ const ready = defineModel('ready', { type: Boolean, default: false });
16
+ const session = useSessionAuthenticated();
17
+ const owners = computedAsync(async () => {
18
+ const user = session.state.user;
19
+ /** @type {import('@data-fair/lib-common-types/session').Account[]} */
20
+ const owners = [];
21
+ if (props.otherAccounts || session.state.account.type === 'user') {
22
+ owners.push({ type: 'user', id: user.id, name: user.name });
23
+ }
24
+ for (const o of user.organizations.filter(o => ['contrib', 'admin'].includes(o.role))) {
25
+ if (!props.otherAccounts) {
26
+ if (session.state.account.type !== 'organization' || o.id !== session.state.account.id) {
27
+ continue;
28
+ }
29
+ if (session.state.account.department && session.state.account.department !== o.department) {
30
+ continue;
31
+ }
32
+ }
33
+ if (o.department && !owners.find(ow => ow.type === 'organization' && ow.id === o.id && ow.department === o.department)) {
34
+ owners.push({ type: 'organization', id: o.id, name: o.name, department: o.department, departmentName: o.departmentName || '' });
35
+ }
36
+ if (!o.department) {
37
+ const org = await ofetch(`/simple-directory/api/organizations/${o.id}`);
38
+ owners.push({ type: 'organization', id: o.id, name: o.name });
39
+ if (!org.departments)
40
+ continue;
41
+ for (const dep of org.departments) {
42
+ if (!owners.find(ow => ow.type === 'organization' && ow.id === o.id && ow.department === dep.id)) {
43
+ owners.push({ type: 'organization', id: o.id, name: o.name, department: dep.id, departmentName: dep.name });
44
+ }
45
+ }
46
+ }
47
+ }
48
+ return owners;
49
+ });
50
+ /**
51
+ * @param {import('@data-fair/lib-common-types/session').Account} owner
52
+ */
53
+ const getLabel = (owner) => {
54
+ if (owner.type === 'user' && owner.id === session.state.user?.id)
55
+ return t('yourself');
56
+ if (owner.type === 'organization') {
57
+ if (owner.department)
58
+ return `${t('org')} ${owner.name} / ${owner.departmentName || owner.department}`;
59
+ else
60
+ return `${t('org')} ${owner.name}`;
61
+ }
62
+ return owner.name;
63
+ };
64
+ watch(owners, () => {
65
+ if (!model.value && owners.value?.length) {
66
+ model.value = owners.value[0];
67
+ }
68
+ if (owners.value) {
69
+ ready.value = true;
70
+ }
71
+ });
72
+ const status = computed(() => {
73
+ if (!owners.value)
74
+ return 'loading';
75
+ if (owners.value.length === 0)
76
+ return 'hidden';
77
+ if (props.hideSingle && owners.value.length === 1)
78
+ return 'hidden';
79
+ return 'ok';
80
+ });
81
+ const __VLS_fnComponent = (await import('vue')).defineComponent({
82
+ props: {
83
+ otherAccounts: { type: Boolean, default: false },
84
+ hideSingle: { type: Boolean, default: true },
85
+ message: { type: String, default: null }
86
+ },
87
+ __typeEmits: {},
88
+ });
89
+ ;
90
+ let __VLS_functionalComponentProps;
91
+ const __VLS_defaults = {
92
+ modelValue: null,
93
+ ready: false,
94
+ };
95
+ function __VLS_template() {
96
+ const __VLS_ctx = {};
97
+ const __VLS_localComponents = {
98
+ ...{},
99
+ ...{},
100
+ ...__VLS_ctx,
101
+ };
102
+ let __VLS_components;
103
+ const __VLS_localDirectives = {
104
+ ...{},
105
+ ...__VLS_ctx,
106
+ };
107
+ let __VLS_directives;
108
+ let __VLS_styleScopedClasses;
109
+ let __VLS_resolvedLocalAndGlobalComponents;
110
+ const __VLS_0 = __VLS_resolvedLocalAndGlobalComponents.VRow;
111
+ /** @type { [typeof __VLS_components.VRow, typeof __VLS_components.vRow, typeof __VLS_components.VRow, typeof __VLS_components.vRow, ] } */
112
+ // @ts-ignore
113
+ const __VLS_1 = __VLS_asFunctionalComponent(__VLS_0, new __VLS_0({}));
114
+ const __VLS_2 = __VLS_1({}, ...__VLS_functionalComponentArgsRest(__VLS_1));
115
+ const __VLS_6 = __VLS_resolvedLocalAndGlobalComponents.VCol;
116
+ /** @type { [typeof __VLS_components.VCol, typeof __VLS_components.vCol, typeof __VLS_components.VCol, typeof __VLS_components.vCol, ] } */
117
+ // @ts-ignore
118
+ const __VLS_7 = __VLS_asFunctionalComponent(__VLS_6, new __VLS_6({}));
119
+ const __VLS_8 = __VLS_7({}, ...__VLS_functionalComponentArgsRest(__VLS_7));
120
+ if (__VLS_ctx.status === 'loading') {
121
+ const __VLS_12 = __VLS_resolvedLocalAndGlobalComponents.VProgressLinear;
122
+ /** @type { [typeof __VLS_components.VProgressLinear, typeof __VLS_components.vProgressLinear, ] } */
123
+ // @ts-ignore
124
+ const __VLS_13 = __VLS_asFunctionalComponent(__VLS_12, new __VLS_12({ indeterminate: (true), color: ("primary"), }));
125
+ const __VLS_14 = __VLS_13({ indeterminate: (true), color: ("primary"), }, ...__VLS_functionalComponentArgsRest(__VLS_13));
126
+ }
127
+ if (__VLS_ctx.status === 'ok') {
128
+ __VLS_elementAsFunction(__VLS_intrinsicElements.p, __VLS_intrinsicElements.p)({});
129
+ (__VLS_ctx.message || __VLS_ctx.t('message'));
130
+ if (__VLS_ctx.model) {
131
+ const __VLS_18 = __VLS_resolvedLocalAndGlobalComponents.VRadioGroup;
132
+ /** @type { [typeof __VLS_components.VRadioGroup, typeof __VLS_components.vRadioGroup, typeof __VLS_components.VRadioGroup, typeof __VLS_components.vRadioGroup, ] } */
133
+ // @ts-ignore
134
+ const __VLS_19 = __VLS_asFunctionalComponent(__VLS_18, new __VLS_18({ modelValue: ((__VLS_ctx.model)), ...{ class: ("my-3 ml-2") }, }));
135
+ const __VLS_20 = __VLS_19({ modelValue: ((__VLS_ctx.model)), ...{ class: ("my-3 ml-2") }, }, ...__VLS_functionalComponentArgsRest(__VLS_19));
136
+ for (const [owner, $index] of __VLS_getVForSourceType((__VLS_ctx.owners))) {
137
+ const __VLS_24 = __VLS_resolvedLocalAndGlobalComponents.VRadio;
138
+ /** @type { [typeof __VLS_components.VRadio, typeof __VLS_components.vRadio, ] } */
139
+ // @ts-ignore
140
+ const __VLS_25 = __VLS_asFunctionalComponent(__VLS_24, new __VLS_24({ key: (($index)), label: ((__VLS_ctx.getLabel(owner))), value: ((owner)), }));
141
+ const __VLS_26 = __VLS_25({ key: (($index)), label: ((__VLS_ctx.getLabel(owner))), value: ((owner)), }, ...__VLS_functionalComponentArgsRest(__VLS_25));
142
+ }
143
+ __VLS_nonNullable(__VLS_23.slots).default;
144
+ const __VLS_23 = __VLS_pickFunctionalComponentCtx(__VLS_18, __VLS_20);
145
+ }
146
+ }
147
+ __VLS_nonNullable(__VLS_11.slots).default;
148
+ const __VLS_11 = __VLS_pickFunctionalComponentCtx(__VLS_6, __VLS_8);
149
+ __VLS_nonNullable(__VLS_5.slots).default;
150
+ const __VLS_5 = __VLS_pickFunctionalComponentCtx(__VLS_0, __VLS_2);
151
+ __VLS_styleScopedClasses['my-3'];
152
+ __VLS_styleScopedClasses['ml-2'];
153
+ var __VLS_slots;
154
+ var __VLS_inheritedAttrs;
155
+ const __VLS_refs = {};
156
+ var $refs;
157
+ return {
158
+ slots: __VLS_slots,
159
+ refs: $refs,
160
+ attrs: {},
161
+ };
162
+ }
163
+ ;
164
+ const __VLS_self = (await import('vue')).defineComponent({
165
+ setup() {
166
+ return {
167
+ $props: __VLS_makeOptional(props),
168
+ ...props,
169
+ t: t,
170
+ model: model,
171
+ owners: owners,
172
+ getLabel: getLabel,
173
+ status: status,
174
+ };
175
+ },
176
+ });
177
+ export default (await import('vue')).defineComponent({
178
+ setup() {
179
+ return {
180
+ $props: __VLS_makeOptional(props),
181
+ ...props,
182
+ };
183
+ },
184
+ });
185
+ ;
186
+ //# sourceMappingURL=owner-pick.vue.js.map
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@data-fair/lib-vuetify",
3
+ "version": "0.1.0",
4
+ "description": "Components based on the Vuetify 3 UI lib for the data-fair stack.",
5
+ "main": "index.js",
6
+ "files": [
7
+ "**/*.js",
8
+ "**/*.d.ts",
9
+ "**/*.vue"
10
+ ],
11
+ "author": "",
12
+ "license": "MIT",
13
+ "peerDependencies": {
14
+ "ofetch": "^1.4.0",
15
+ "vue-i18n": "^10.0.4",
16
+ "vuetify": "^3.7.2"
17
+ },
18
+ "type": "module",
19
+ "dependencies": {
20
+ "@data-fair/lib-common-types": "^0.2.0"
21
+ }
22
+ }