@tailor-cms/tce-preview-runtime 0.4.0-beta.4 → 0.4.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/package.json +3 -1
- package/src/App.vue +9 -6
- package/src/main.ts +7 -0
- package/vite.config.ts +4 -1
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tailor-cms/tce-preview-runtime",
|
|
3
|
-
"version": "0.4.0
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"dependencies": {
|
|
5
|
+
"@lukeed/uuid": "^2.0.1",
|
|
5
6
|
"@mdi/font": "7.2.96",
|
|
6
7
|
"@vitejs/plugin-vue": "4.3.4",
|
|
7
8
|
"@vueuse/core": "10.4.1",
|
|
@@ -11,6 +12,7 @@
|
|
|
11
12
|
"sass": "1.68.0",
|
|
12
13
|
"split.js": "1.6.5",
|
|
13
14
|
"typescript": "5.2.2",
|
|
15
|
+
"universal-cookie": "^6.1.3",
|
|
14
16
|
"vite": "4.4.9",
|
|
15
17
|
"vite-plugin-vuetify": "1.0.2",
|
|
16
18
|
"vue": "3.3.4",
|
package/src/App.vue
CHANGED
|
@@ -7,6 +7,7 @@ import MainLayout from './components/MainLayout.vue';
|
|
|
7
7
|
|
|
8
8
|
interface ContentElement {
|
|
9
9
|
id: number;
|
|
10
|
+
uid: string;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
const appUrl = new URL(window.location.href);
|
|
@@ -19,19 +20,18 @@ const element = ref<ContentElement>();
|
|
|
19
20
|
const userState = ref({});
|
|
20
21
|
|
|
21
22
|
onMounted(async () => {
|
|
22
|
-
|
|
23
|
-
element.value = elementVal;
|
|
24
|
-
userState.value = userStateVal;
|
|
23
|
+
await getElement();
|
|
25
24
|
ws.addEventListener('message', (message) => {
|
|
26
25
|
const event = JSON.parse(message.data);
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
26
|
+
const elementUid = element.value?.uid;
|
|
27
|
+
if (elementUid && elementUid !== event.entityId) return;
|
|
29
28
|
if (event.type === 'userState:update') {
|
|
30
29
|
userState.value = event.payload;
|
|
31
30
|
}
|
|
32
31
|
if (event.type === 'element:update') {
|
|
33
32
|
element.value = event.payload;
|
|
34
33
|
}
|
|
34
|
+
if (event.type === 'userContext:change') getElement();
|
|
35
35
|
});
|
|
36
36
|
});
|
|
37
37
|
|
|
@@ -41,7 +41,10 @@ function timeout(ms: number) {
|
|
|
41
41
|
|
|
42
42
|
async function getElement(): Promise<any> {
|
|
43
43
|
try {
|
|
44
|
-
|
|
44
|
+
const res = await api('content-element').json();
|
|
45
|
+
const { element: elementVal, userState: userStateVal } = res as any;
|
|
46
|
+
element.value = elementVal;
|
|
47
|
+
userState.value = userStateVal;
|
|
45
48
|
} catch (error) {
|
|
46
49
|
console.log('Error on element get', error);
|
|
47
50
|
await timeout(2000);
|
package/src/main.ts
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import '@mdi/font/css/materialdesignicons.css';
|
|
2
2
|
import 'vuetify/styles';
|
|
3
3
|
|
|
4
|
+
import Cookies from 'universal-cookie';
|
|
4
5
|
import { createApp } from 'vue';
|
|
5
6
|
import { createVuetify } from 'vuetify';
|
|
7
|
+
import { v4 as uuid } from '@lukeed/uuid/secure';
|
|
6
8
|
|
|
7
9
|
import App from './App.vue';
|
|
8
10
|
|
|
11
|
+
const CLIENT_ID_KEY = 'cekClientId';
|
|
12
|
+
|
|
13
|
+
const cookies = new Cookies(null, { path: '/' });
|
|
14
|
+
if (!cookies.get(CLIENT_ID_KEY)) cookies.set(CLIENT_ID_KEY, uuid());
|
|
15
|
+
|
|
9
16
|
createApp(App)
|
|
10
17
|
.use(createVuetify({ icons: { defaultSet: 'mdi' } }))
|
|
11
18
|
.mount('#app');
|
package/vite.config.ts
CHANGED
|
@@ -33,7 +33,10 @@ export default defineConfig((): any => {
|
|
|
33
33
|
},
|
|
34
34
|
},
|
|
35
35
|
logLevel: 'warn',
|
|
36
|
-
optimizeDeps: {
|
|
36
|
+
optimizeDeps: {
|
|
37
|
+
include: ['universal-cookie'],
|
|
38
|
+
entries: ['./src/main.js'],
|
|
39
|
+
},
|
|
37
40
|
plugins: [vue(), vuetify({ autoImport: true })],
|
|
38
41
|
};
|
|
39
42
|
});
|