@lilaquadrat/design-core 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 +236 -0
- package/html/index.html +25 -0
- package/html/index.mail.html +15 -0
- package/html/index.server.html +29 -0
- package/package.json +148 -0
- package/src/client-entry.ts +28 -0
- package/src/components/partials/action.partial.vue +30 -0
- package/src/components/partials/client-only.partial.vue +11 -0
- package/src/components/partials/error.partial.vue +73 -0
- package/src/components/partials/main-components.partial.vue +167 -0
- package/src/components/partials/mediadetection.partial.vue +71 -0
- package/src/components/partials/qrcode.partial.vue +35 -0
- package/src/customs.ts +12 -0
- package/src/env.d.ts +1 -0
- package/src/functions/PaymenyProviderFactory.ts +27 -0
- package/src/functions/lila-dom.ts +100 -0
- package/src/functions/shopify.provider.ts +378 -0
- package/src/functions/stripe.provider.ts +181 -0
- package/src/globals.d.ts +19 -0
- package/src/index.ts +47 -0
- package/src/interfaces/AppState.interface.ts +4 -0
- package/src/interfaces/EditorConfiguration.interface.ts +15 -0
- package/src/interfaces/EventDeclaration.interface.ts +19 -0
- package/src/interfaces/FrontendConfig.interface.ts +42 -0
- package/src/interfaces/GenericEvents.interface.ts +6 -0
- package/src/interfaces/GenericState.interface.ts +5 -0
- package/src/interfaces/IconsPartial.ts +9 -0
- package/src/interfaces/IdTokenExtended.interface.ts +7 -0
- package/src/interfaces/ModuleBaseProps.interface.ts +8 -0
- package/src/interfaces/PaymentProvider.interface.ts +13 -0
- package/src/libs/ActionNotice.ts +235 -0
- package/src/libs/Models.class.ts +482 -0
- package/src/main.ts +84 -0
- package/src/mixins/createCookieString.ts +78 -0
- package/src/mixins/createModelDeclaration.ts +29 -0
- package/src/mixins/createRouter.ts +30 -0
- package/src/mixins/date.ts +23 -0
- package/src/mixins/formatSize.ts +12 -0
- package/src/mixins/getAnchor.ts +14 -0
- package/src/mixins/getRoutes.ts +50 -0
- package/src/mixins/hasSlotContent.ts +32 -0
- package/src/mixins/hooks.ts +104 -0
- package/src/mixins/loadComponents.ts +107 -0
- package/src/mixins/logger.ts +32 -0
- package/src/mixins/replaceVariables.ts +19 -0
- package/src/mixins/scroll.ts +83 -0
- package/src/models/Address.model.ts +24 -0
- package/src/models/Contact.model.ts +22 -0
- package/src/models.ts +2 -0
- package/src/plugins/auth.ts +121 -0
- package/src/plugins/currency.ts +26 -0
- package/src/plugins/events.ts +156 -0
- package/src/plugins/filters.ts +43 -0
- package/src/plugins/inview.ts +351 -0
- package/src/plugins/replacer.ts +18 -0
- package/src/plugins/resize.ts +128 -0
- package/src/plugins/signupFlow.ts +89 -0
- package/src/plugins/traceable.ts +53 -0
- package/src/plugins/translations.ts +29 -0
- package/src/plugins/youtube.ts +80 -0
- package/src/routes.ts +132 -0
- package/src/server-entry.ts +113 -0
- package/src/stores/calls.store.ts +33 -0
- package/src/stores/cart.store.ts +186 -0
- package/src/stores/content.store.ts +83 -0
- package/src/stores/editor.store.ts +27 -0
- package/src/stores/files.store.ts +166 -0
- package/src/stores/main.store.ts +184 -0
- package/src/stores/user.store.ts +124 -0
- package/src/translations/de.ts +138 -0
- package/src/views/content.view.vue +219 -0
- package/src/views/download.view.vue +143 -0
- package/src/views/editor.view.vue +243 -0
- package/src/views/login.view.vue +82 -0
- package/src/views/signup-account.view.vue +64 -0
- package/tooling/cypress/config.ts +80 -0
- package/tooling/cypress/generate-manifest.js +5 -0
- package/tooling/cypress/manifest-utils.mjs +40 -0
- package/tooling/cypress/run-parallel.mjs +77 -0
- package/tooling/cypress/support/commands.ts +436 -0
- package/tooling/cypress/support/e2e.ts +17 -0
- package/tooling/eslint.config.js +223 -0
- package/tooling/preview.plugin.ts +134 -0
- package/tooling/ssr-test/index.mjs +391 -0
- package/tooling/stylelint.config.mjs +24 -0
- package/tooling/vite.ts +246 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { ref } from 'vue'
|
|
2
|
+
import { defineStore } from 'pinia'
|
|
3
|
+
import PaymentProviderFactory from '../functions/PaymenyProviderFactory';
|
|
4
|
+
import useMainStore from './main.store';
|
|
5
|
+
import type { Agreement } from '@lilaquadrat/interfaces';
|
|
6
|
+
|
|
7
|
+
export const useCartStore = defineStore('cart', () => {
|
|
8
|
+
|
|
9
|
+
const products = ref<any[]>([]);
|
|
10
|
+
const costSummary = ref<number>(0);
|
|
11
|
+
const itemsQuantity = ref<number>(0);
|
|
12
|
+
const mainStore = useMainStore();
|
|
13
|
+
const paymentProvider = PaymentProviderFactory(mainStore.config?.payment?.type as 'internal' | 'shopify' | 'stripe', mainStore.config?.payment?.options);
|
|
14
|
+
const cartCache = ref();
|
|
15
|
+
|
|
16
|
+
async function getCart (attributes?: Record<string, string>) {
|
|
17
|
+
|
|
18
|
+
if(cartCache.value) return Promise.resolve(cartCache.value);
|
|
19
|
+
if(!attributes) return Promise.reject('ATTRIBUTES_MISSING');
|
|
20
|
+
|
|
21
|
+
const list = attributes.list;
|
|
22
|
+
|
|
23
|
+
if(!list) return Promise.reject('NO_LIST_GIVEN');
|
|
24
|
+
|
|
25
|
+
const cartId = `lila-cart-${list}`;
|
|
26
|
+
const storedCart = localStorage.getItem(cartId);
|
|
27
|
+
|
|
28
|
+
if(storedCart) {
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
|
|
32
|
+
cartCache.value = JSON.parse(storedCart);
|
|
33
|
+
products.value = await paymentProvider.getCartWithProducts(cartCache.value.id);
|
|
34
|
+
|
|
35
|
+
} catch (error) {
|
|
36
|
+
|
|
37
|
+
console.error(error);
|
|
38
|
+
localStorage.removeItem(cartId);
|
|
39
|
+
cartCache.value = undefined;
|
|
40
|
+
await getCart(attributes);
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
updateSummary();
|
|
45
|
+
|
|
46
|
+
} else {
|
|
47
|
+
|
|
48
|
+
const newCart = await paymentProvider.getCart(attributes);
|
|
49
|
+
|
|
50
|
+
localStorage.setItem(cartId, JSON.stringify(newCart));
|
|
51
|
+
|
|
52
|
+
cartCache.value = newCart;
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return Promise.resolve(cartCache.value);
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function getFinishedCart (cartId: string) {
|
|
61
|
+
|
|
62
|
+
return paymentProvider.getFinishedCart(cartId);
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function importCart (cart: any[]) {
|
|
67
|
+
|
|
68
|
+
console.log(cart);
|
|
69
|
+
|
|
70
|
+
products.value = cart;
|
|
71
|
+
updateSummary();
|
|
72
|
+
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function updateSummary () {
|
|
76
|
+
|
|
77
|
+
let costs = 0;
|
|
78
|
+
let quantity = 0;
|
|
79
|
+
|
|
80
|
+
products.value.forEach((single) => {
|
|
81
|
+
|
|
82
|
+
costs += ((single.price.amount || 0) / 100) * single.quantity;
|
|
83
|
+
quantity += single.quantity;
|
|
84
|
+
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
costSummary.value = Math.round(costs * 100) / 100
|
|
88
|
+
itemsQuantity.value = quantity;
|
|
89
|
+
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function updateAgreements (acceptedAgreements: Agreement[]) {
|
|
93
|
+
|
|
94
|
+
const attributes: Record<string, string> = {...cartCache.value.attributes};
|
|
95
|
+
|
|
96
|
+
acceptedAgreements.forEach((single, index) => {
|
|
97
|
+
|
|
98
|
+
attributes[`agreement_${index}`] = single.contentId;
|
|
99
|
+
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
console.log(acceptedAgreements, cartCache.value, attributes);
|
|
103
|
+
return paymentProvider.updateCartAttributes(cartCache.value.id, attributes);
|
|
104
|
+
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function getProductInCart (productId: string) {
|
|
108
|
+
|
|
109
|
+
if(!productId) return null;
|
|
110
|
+
return products.value.find((single) => single.id === productId);
|
|
111
|
+
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function addProduct (productId: string) {
|
|
115
|
+
|
|
116
|
+
const product = await paymentProvider.getProduct(productId);
|
|
117
|
+
const cart = await getCart();
|
|
118
|
+
const existingProduct = getProductInCart(product.id);
|
|
119
|
+
|
|
120
|
+
if(!existingProduct) {
|
|
121
|
+
|
|
122
|
+
const updatedProduct = await paymentProvider.addToCart(cart.id, product, 1);
|
|
123
|
+
|
|
124
|
+
products.value.push({...updatedProduct, quantity: 1});
|
|
125
|
+
updateSummary();
|
|
126
|
+
|
|
127
|
+
} else {
|
|
128
|
+
|
|
129
|
+
console.log('update instead of add', product.id, existingProduct.quantity);
|
|
130
|
+
updateQuantity(product.id, existingProduct.quantity + 1);
|
|
131
|
+
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async function updateQuantity (productId: string, quantity: number) {
|
|
137
|
+
|
|
138
|
+
const existingProduct = getProductInCart(productId);
|
|
139
|
+
const cart = await getCart();
|
|
140
|
+
|
|
141
|
+
paymentProvider.updateQuantity(cart.id, existingProduct, quantity)
|
|
142
|
+
|
|
143
|
+
existingProduct.quantity = quantity;
|
|
144
|
+
updateSummary();
|
|
145
|
+
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async function removeProduct (productId: string) {
|
|
149
|
+
|
|
150
|
+
const existingProduct = getProductInCart(productId);
|
|
151
|
+
const cart = await getCart();
|
|
152
|
+
|
|
153
|
+
await paymentProvider.removeFromCart(cart.id, existingProduct);
|
|
154
|
+
|
|
155
|
+
const index = products.value.findIndex((single) => single.id === productId);
|
|
156
|
+
|
|
157
|
+
products.value.splice(index, 1);
|
|
158
|
+
updateSummary();
|
|
159
|
+
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function finalize () {
|
|
163
|
+
|
|
164
|
+
return paymentProvider.finalize(cartCache.value.id);
|
|
165
|
+
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
addProduct,
|
|
170
|
+
updateQuantity,
|
|
171
|
+
removeProduct,
|
|
172
|
+
updateAgreements,
|
|
173
|
+
importCart,
|
|
174
|
+
products,
|
|
175
|
+
getProductInCart,
|
|
176
|
+
costSummary,
|
|
177
|
+
itemsQuantity,
|
|
178
|
+
getCart,
|
|
179
|
+
finalize,
|
|
180
|
+
getFinishedCart,
|
|
181
|
+
cart: cartCache
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
export default useCartStore;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { ref } from 'vue'
|
|
2
|
+
import { defineStore } from 'pinia'
|
|
3
|
+
import type { BasicData, Content, Customers, List } from '@lilaquadrat/interfaces';
|
|
4
|
+
|
|
5
|
+
export const useContentStore = defineStore('content', () => {
|
|
6
|
+
|
|
7
|
+
const content = ref<BasicData<Content>[]>([]);
|
|
8
|
+
const recipient = ref<Customers>();
|
|
9
|
+
const list = ref<List>();
|
|
10
|
+
const context = ref<Record<string, string | undefined | Record<string, string>>>();
|
|
11
|
+
|
|
12
|
+
function add (contentToAdd: Content) {
|
|
13
|
+
|
|
14
|
+
content.value.push(contentToAdd)
|
|
15
|
+
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function addMulti (contentToAdd: Content[]) {
|
|
19
|
+
|
|
20
|
+
content.value.push(...contentToAdd);
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function findById (id: string) {
|
|
25
|
+
|
|
26
|
+
return content.value.find((single) => single.id === id);
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function findByinternalId (internalId: string) {
|
|
31
|
+
|
|
32
|
+
return content.value.find((single) => single._id?.toString() === internalId);
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function findByFilename (filename: string) {
|
|
37
|
+
|
|
38
|
+
return content.value.find((single) => single.settings.filename?.includes(filename));
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function setContext (data: {sitetile?: string, description?: string, [key: string]: string | undefined}) {
|
|
43
|
+
|
|
44
|
+
context.value = data;
|
|
45
|
+
|
|
46
|
+
if(typeof document === 'undefined') return;
|
|
47
|
+
|
|
48
|
+
if(data.sitetitle) {
|
|
49
|
+
|
|
50
|
+
document.title = data.sitetitle;
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if(data.description) {
|
|
55
|
+
|
|
56
|
+
const metaDescription = document.querySelector('meta[name="description"]');
|
|
57
|
+
|
|
58
|
+
if (metaDescription) {
|
|
59
|
+
|
|
60
|
+
metaDescription.setAttribute('content', data.description);
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
add,
|
|
70
|
+
addMulti,
|
|
71
|
+
findById,
|
|
72
|
+
findByinternalId,
|
|
73
|
+
findByFilename,
|
|
74
|
+
content,
|
|
75
|
+
recipient,
|
|
76
|
+
list,
|
|
77
|
+
context,
|
|
78
|
+
setContext
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
export default useContentStore;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ref, shallowRef } from 'vue'
|
|
2
|
+
import { defineStore } from 'pinia'
|
|
3
|
+
import type { EditorActiveModule } from '@lilaquadrat/interfaces';
|
|
4
|
+
|
|
5
|
+
export const useEditorStore = defineStore('editor', () => {
|
|
6
|
+
|
|
7
|
+
const active = ref<EditorActiveModule>({});
|
|
8
|
+
const availableModulesWithRevision = ref<{ revision: number, modules: any[]}>();
|
|
9
|
+
const availableModulesWithRevisionMail = ref<{ revision: number, modules: any[]}>();
|
|
10
|
+
const modulesBrowser = shallowRef<any>();
|
|
11
|
+
const modulesMail = shallowRef<any>();
|
|
12
|
+
const partialsBrowser = shallowRef<any>();
|
|
13
|
+
const partialsMail = shallowRef<any>();
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
active,
|
|
17
|
+
availableModulesWithRevision,
|
|
18
|
+
availableModulesWithRevisionMail,
|
|
19
|
+
modulesBrowser,
|
|
20
|
+
modulesMail,
|
|
21
|
+
partialsBrowser,
|
|
22
|
+
partialsMail,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
export default useEditorStore;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { defineStore } from 'pinia';
|
|
2
|
+
import { ref } from 'vue';
|
|
3
|
+
import StudioSDK, { type UploadFile, type UploadProgressCallback, type UploadResult } from '@lilaquadrat/sdk';
|
|
4
|
+
import useMainStore from './main.store';
|
|
5
|
+
|
|
6
|
+
export interface TokenData {
|
|
7
|
+
token: string
|
|
8
|
+
expiresAt: number
|
|
9
|
+
createdAt: number
|
|
10
|
+
expiresIn: number
|
|
11
|
+
app: string
|
|
12
|
+
scope: 'company' | 'project'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface BackendMedia {
|
|
16
|
+
_id?: string
|
|
17
|
+
filename?: string
|
|
18
|
+
assetId?: string
|
|
19
|
+
app?: string
|
|
20
|
+
customer?: string
|
|
21
|
+
list?: string
|
|
22
|
+
type?: string
|
|
23
|
+
project?: string
|
|
24
|
+
company?: string
|
|
25
|
+
metadata?: {
|
|
26
|
+
size?: number
|
|
27
|
+
mimetype?: string
|
|
28
|
+
tags?: string[]
|
|
29
|
+
}
|
|
30
|
+
history?: { created?: string, version?: number, source?: string }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type QueueItemState = 'pending' | 'creating' | 'uploading' | 'processing' | 'done' | 'error';
|
|
34
|
+
|
|
35
|
+
export interface QueueItem {
|
|
36
|
+
id: string
|
|
37
|
+
file: File
|
|
38
|
+
state: QueueItemState
|
|
39
|
+
progress: number
|
|
40
|
+
structureInternalId?: string
|
|
41
|
+
assetId?: string
|
|
42
|
+
app?: string
|
|
43
|
+
uploadId?: string
|
|
44
|
+
error?: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface AddFilesOptions {
|
|
48
|
+
structureInternalId?: string
|
|
49
|
+
assetId?: string
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface UploadContext {
|
|
53
|
+
list?: string
|
|
54
|
+
contentId?: string
|
|
55
|
+
moduleUuid?: string
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const useFilesStore = defineStore('files', () => {
|
|
59
|
+
|
|
60
|
+
const token = ref<TokenData>();
|
|
61
|
+
|
|
62
|
+
function getSdk () {
|
|
63
|
+
|
|
64
|
+
const mainStore = useMainStore();
|
|
65
|
+
|
|
66
|
+
return new StudioSDK(mainStore.apiConfig);
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function fetchToken (app: string, scope: 'company' | 'project'): Promise<string> {
|
|
71
|
+
|
|
72
|
+
StudioSDK.flushCache();
|
|
73
|
+
|
|
74
|
+
const sdk = getSdk();
|
|
75
|
+
const response = await sdk.members.storage.token(app, scope);
|
|
76
|
+
const data = response?.data;
|
|
77
|
+
|
|
78
|
+
if (data?.token) {
|
|
79
|
+
|
|
80
|
+
token.value = {
|
|
81
|
+
token : data.token,
|
|
82
|
+
expiresAt: data.expiresAt,
|
|
83
|
+
createdAt: data.createdAt,
|
|
84
|
+
expiresIn: data.expiresIn,
|
|
85
|
+
app,
|
|
86
|
+
scope,
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return data?.token ?? '';
|
|
92
|
+
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function isTokenValid (app: string, scope: 'company' | 'project', bufferSeconds = 30): boolean {
|
|
96
|
+
|
|
97
|
+
if (!token.value) return false;
|
|
98
|
+
if (token.value.app !== app) return false;
|
|
99
|
+
if (token.value.scope !== scope) return false;
|
|
100
|
+
|
|
101
|
+
const now = Date.now() / 1000;
|
|
102
|
+
|
|
103
|
+
console.log(now + bufferSeconds, token.value.expiresAt, (now + bufferSeconds) < token.value.expiresAt);
|
|
104
|
+
|
|
105
|
+
return (now + bufferSeconds) < token.value.expiresAt;
|
|
106
|
+
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function listFiles (app: string, assetId?: string, model?: string): Promise<BackendMedia[]> {
|
|
110
|
+
|
|
111
|
+
const options = assetId
|
|
112
|
+
? {assetId: [assetId]}
|
|
113
|
+
: undefined;
|
|
114
|
+
const sdk = getSdk();
|
|
115
|
+
const response = model === 'customers'
|
|
116
|
+
? await sdk.members.storage.listCompany(app, 1, options)
|
|
117
|
+
: await sdk.members.storage.listProject(app, 1, options);
|
|
118
|
+
const payload = response?.data?.data as BackendMedia[] | undefined;
|
|
119
|
+
|
|
120
|
+
return Array.isArray(payload) ? payload : [];
|
|
121
|
+
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async function uploadOne (
|
|
125
|
+
file: File,
|
|
126
|
+
bucket: string,
|
|
127
|
+
options: { list?: string, contentId?: string, moduleUuid?: string, structureInternalId?: string },
|
|
128
|
+
onProgress?: UploadProgressCallback,
|
|
129
|
+
): Promise<UploadResult> {
|
|
130
|
+
|
|
131
|
+
const sdk = getSdk();
|
|
132
|
+
const uploadFile: UploadFile = {
|
|
133
|
+
filename: file.name,
|
|
134
|
+
size : file.size,
|
|
135
|
+
mimetype: file.type || 'application/octet-stream',
|
|
136
|
+
data : file,
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
return sdk.members.storage.upload(uploadFile, bucket, options, onProgress);
|
|
140
|
+
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async function deleteFile (app: string, id: string) {
|
|
144
|
+
|
|
145
|
+
if (!id) return;
|
|
146
|
+
|
|
147
|
+
const sdk = getSdk();
|
|
148
|
+
|
|
149
|
+
await sdk.members.storage.remove(app, id);
|
|
150
|
+
StudioSDK.flushCache('storage', 'listProject');
|
|
151
|
+
StudioSDK.flushCache('storage', 'listCompany');
|
|
152
|
+
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
token,
|
|
157
|
+
fetchToken,
|
|
158
|
+
isTokenValid,
|
|
159
|
+
listFiles,
|
|
160
|
+
uploadOne,
|
|
161
|
+
deleteFile,
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
export default useFilesStore;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { ref } from 'vue'
|
|
2
|
+
import { defineStore } from 'pinia'
|
|
3
|
+
import type { BasicData, Content, CustomModule } from '@lilaquadrat/interfaces';
|
|
4
|
+
import type EditorConfiguration from '../interfaces/EditorConfiguration.interface';
|
|
5
|
+
import StudioSDK, { type SDKResponse } from '@lilaquadrat/sdk';
|
|
6
|
+
import { useAuth } from '../plugins/auth';
|
|
7
|
+
import type FrontendConfig from '../interfaces/FrontendConfig.interface';
|
|
8
|
+
import type { AxiosError } from 'axios';
|
|
9
|
+
import { computed } from 'vue';
|
|
10
|
+
import { hardCopy } from '@lilaquadrat/studio/lib/esm/frontend';
|
|
11
|
+
|
|
12
|
+
export const useMainStore = defineStore('main', () => {
|
|
13
|
+
|
|
14
|
+
const startupDone = ref<boolean>(false);
|
|
15
|
+
const clientOnlyStartupDone = ref<boolean>(false);
|
|
16
|
+
const data = ref<BasicData<Content>>();
|
|
17
|
+
const layout = ref<BasicData<Content>>();
|
|
18
|
+
const editorConfiguration = ref<EditorConfiguration>({});
|
|
19
|
+
const fullscreen = ref<boolean>(false);
|
|
20
|
+
const config = ref<FrontendConfig>();
|
|
21
|
+
const isEditor = ref<boolean>(typeof window !== 'undefined' && window !== window.top);
|
|
22
|
+
/**
|
|
23
|
+
* there are case where the content should not update if the lock state changed
|
|
24
|
+
* e.g. the user is connected after using register-main
|
|
25
|
+
* this state will be set to false by the next navigation
|
|
26
|
+
*/
|
|
27
|
+
const disabledLockUpdate = ref<boolean>(false);
|
|
28
|
+
const staticData = ref<Record<string, Partial<BasicData<Content>>>>();
|
|
29
|
+
const customModulesBrowser = ref<CustomModule[]>();
|
|
30
|
+
const customModulesMail = ref<CustomModule[]>();
|
|
31
|
+
const target = ref<'browser'|'mail'>();
|
|
32
|
+
|
|
33
|
+
function setData (value: BasicData<Content>) {
|
|
34
|
+
|
|
35
|
+
data.value = value;
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function setFullscreen (value: boolean) {
|
|
40
|
+
|
|
41
|
+
fullscreen.value = value;
|
|
42
|
+
|
|
43
|
+
if (!document) return;
|
|
44
|
+
|
|
45
|
+
const { body } = document;
|
|
46
|
+
|
|
47
|
+
if (value) {
|
|
48
|
+
|
|
49
|
+
body.classList.add('fullscreen');
|
|
50
|
+
|
|
51
|
+
} else {
|
|
52
|
+
|
|
53
|
+
if (body.classList.contains('fullscreen')) {
|
|
54
|
+
body.classList.remove('fullscreen');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function checkFullscreen () {
|
|
62
|
+
|
|
63
|
+
const elements = document.querySelectorAll('.overlay-background:not(.inactive)');
|
|
64
|
+
|
|
65
|
+
if (!elements.length) setFullscreen(false);
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function setConfiguration (value: EditorConfiguration) {
|
|
70
|
+
|
|
71
|
+
editorConfiguration.value = value;
|
|
72
|
+
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const apiConfig = computed(() => {
|
|
76
|
+
|
|
77
|
+
const { authToken } = useAuth();
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
authToken,
|
|
81
|
+
...config.value?.api,
|
|
82
|
+
company: config.value?.company,
|
|
83
|
+
project: config.value?.project,
|
|
84
|
+
app : config.value?.name as string
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
async function getContent(params: { filename: string }, type: 'public' | 'members'): Promise<SDKResponse<BasicData<Content>|undefined>>
|
|
90
|
+
async function getContent(params: { id: string }, type: 'public' | 'members'): Promise<SDKResponse<BasicData<Content>|undefined>>
|
|
91
|
+
async function getContent(params: { internalId: string }, type: 'public' | 'members'): Promise<SDKResponse<BasicData<Content>|undefined>>
|
|
92
|
+
async function getContent(params: { latest?: boolean, predefined?: boolean, categories?: string[] }, type: 'public' | 'members'): Promise<SDKResponse<BasicData<Content>|undefined>>
|
|
93
|
+
async function getContent (params: { predefined?: boolean, filename?: string, latest?: boolean, id?: string, internalId?: string, categories?: string[] }, type: 'public' | 'members'): Promise<SDKResponse<BasicData<Content>|undefined>> {
|
|
94
|
+
|
|
95
|
+
const sdk = new StudioSDK(apiConfig.value);
|
|
96
|
+
const targetWithType = sdk[type === 'members' ? 'members' : 'public'];
|
|
97
|
+
|
|
98
|
+
if(params.filename && data.value?.settings?.filename?.includes(params.filename)) {
|
|
99
|
+
|
|
100
|
+
return hardCopy<SDKResponse<BasicData<Content>>>({ data: data.value, status: 200 });
|
|
101
|
+
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (params.id && data.value?.id === params.id) {
|
|
105
|
+
|
|
106
|
+
return hardCopy<SDKResponse<BasicData<Content>>>({ data: data.value, status: 200 });
|
|
107
|
+
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (params.internalId && data.value?._id?.toString() === params.internalId) {
|
|
111
|
+
|
|
112
|
+
return hardCopy<SDKResponse<BasicData<Content>>>({ data: data.value, status: 200 });
|
|
113
|
+
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
try {
|
|
117
|
+
|
|
118
|
+
if (params.predefined && !params.latest && params.id && type === 'public') {
|
|
119
|
+
|
|
120
|
+
return sdk.public.content.predefined(params.id);
|
|
121
|
+
|
|
122
|
+
} else if (params.predefined && params.latest && params.categories && type === 'public') {
|
|
123
|
+
|
|
124
|
+
return sdk.public.content.predefinedLatest(params.categories);
|
|
125
|
+
|
|
126
|
+
} else if (params.internalId) {
|
|
127
|
+
|
|
128
|
+
return targetWithType.content.getByInternalId(params.internalId);
|
|
129
|
+
|
|
130
|
+
} else if (params.id) {
|
|
131
|
+
|
|
132
|
+
return targetWithType.content.getById(params.id);
|
|
133
|
+
|
|
134
|
+
} else if (params.filename) {
|
|
135
|
+
|
|
136
|
+
return targetWithType.content.getByFilename(params.filename);
|
|
137
|
+
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
} catch (e) {
|
|
141
|
+
|
|
142
|
+
const error = e as AxiosError;
|
|
143
|
+
|
|
144
|
+
if (!error.response?.status) {
|
|
145
|
+
|
|
146
|
+
return { status: 400, data: undefined}
|
|
147
|
+
|
|
148
|
+
} else {
|
|
149
|
+
|
|
150
|
+
return { status: error?.response?.status, data: undefined };
|
|
151
|
+
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return { status: 400, data: undefined};
|
|
157
|
+
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
setData,
|
|
162
|
+
data,
|
|
163
|
+
layout,
|
|
164
|
+
fullscreen,
|
|
165
|
+
setFullscreen,
|
|
166
|
+
checkFullscreen,
|
|
167
|
+
setConfiguration,
|
|
168
|
+
configuration: editorConfiguration,
|
|
169
|
+
getContent,
|
|
170
|
+
startupDone,
|
|
171
|
+
clientOnlyStartupDone,
|
|
172
|
+
config,
|
|
173
|
+
staticData,
|
|
174
|
+
apiConfig,
|
|
175
|
+
customModulesBrowser,
|
|
176
|
+
customModulesMail,
|
|
177
|
+
target,
|
|
178
|
+
disabledLockUpdate,
|
|
179
|
+
isEditor
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
export default useMainStore;
|