Skip to content

Use the new content saved events for live preview #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion samples/music-festival-vue-decoupled/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ This project uses:

### On-Page Editing helpers

- [epiBootstrap.js](frontend/src/epiBootstrap.js): registers the `contentSaved` and `epiReady` message handlers that updates the vuex store.
- [livePreview.js](frontend/src/livePreview.js): subscribes to `contentSaved` events to update the vuex store which enabled live preview of content.
- [epiEdit.js](frontend/src/directives/epiEdit.js): a directive that can be added on components to make them optionally editable (e.g. `<span v-epi-edit="Name">`), through `isEditable` and `epiDisableEditing`.
- [EpiProperty.vue](frontend/src/components/EpiProperty.vue): a component that renders a button to edit a property (e.g. `<epi-property property-name="Name">`).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EPiServer.CMS" Version="12.32.5" />
<PackageReference Include="EPiServer.CMS" Version="12.33.1" />
<PackageReference Include="EPiServer.ContentDeliveryApi.Cms" Version="3.12.2" />
</ItemGroup>

Expand Down
44 changes: 0 additions & 44 deletions samples/music-festival-vue-decoupled/frontend/src/epiBootstrap.js

This file was deleted.

15 changes: 15 additions & 0 deletions samples/music-festival-vue-decoupled/frontend/src/livePreview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Sets up subscription to the `contentSaved` event that will update
* the model in the store during editing.
*/

import store from "@/store";
import { parsePreviewToken } from "@/urlHelpers";
import { UPDATE_PREVIEW_TOKEN } from "@/store/modules/epiContext";
import { UPDATE_MODEL_BY_URL } from "@/store/modules/epiDataModel";

window.addEventListener("optimizely:cms:contentSaved", (event) => {
var parsed = parsePreviewToken(event.detail.previewUrl);
store.commit(UPDATE_PREVIEW_TOKEN, parsed.previewToken);
store.dispatch(UPDATE_MODEL_BY_URL, parsed.url);
});
27 changes: 12 additions & 15 deletions samples/music-festival-vue-decoupled/frontend/src/main.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
import { createApp } from 'vue';
import App from './App.vue';
import EpiEdit from './directives/epiEdit';
import router from './router';
import store from './store';
import './epiBootstrap';
import './assets/styles/main.less';
import { createApp } from "vue";
import App from "./App.vue";
import EpiEdit from "./directives/epiEdit";
import router from "./router";
import store from "./store";
import "./livePreview";
import "./assets/styles/main.less";

const app = createApp(App)
.directive('epi-edit', EpiEdit)
.use(store)
.use(router);
const app = createApp(App).directive("epi-edit", EpiEdit).use(store).use(router);

// Register all Optimizely view components globally. This requires webpack!
// Otherwise we need to register all components manually here in main.js.
const requireComponent = require.context('./views', true, /.vue$/);
const requireComponent = require.context("./views", true, /.vue$/);

requireComponent.keys().forEach((fileName) => {
const componentConfig = requireComponent(fileName);

// Gets the component name regardless folder depth
const componentName = fileName
.split('/')
.split("/")
.pop()
.replace(/\.\w+$/, '');
.replace(/\.\w+$/, "");

// Look for the component options on `.default`, which will
// exist if the component was exported with `export default`,
// otherwise fall back to module's root.
app.component(componentName, componentConfig.default || componentConfig);
});

app.mount('#app');
app.mount("#app");