From 8a7bac626f09ad9d00b71d6753df5b009cf38538 Mon Sep 17 00:00:00 2001 From: Bart van den Aardweg Date: Tue, 4 May 2021 17:40:45 +0200 Subject: [PATCH] feat: upgrade to bridge v2 --- .github/workflows/release.yaml | 1 + src/bridge/init.ts | 24 +++++++----------------- src/story.ts | 1 + 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index e02c7bf..a63c7b7 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -3,6 +3,7 @@ on: push: branches: - master + - beta jobs: release: name: Release diff --git a/src/bridge/init.ts b/src/bridge/init.ts index f47a7c3..e9d35b7 100644 --- a/src/bridge/init.ts +++ b/src/bridge/init.ts @@ -3,7 +3,7 @@ import { Story } from '../story'; const loadBridge = (callback: () => void) => { if (!window.storyblok) { const script = document.createElement('script'); - script.src = `//app.storyblok.com/f/storyblok-latest.js`; + script.src = `//app.storyblok.com/f/storyblok-v2-latest.js`; script.onload = callback; document.body.appendChild(script); } else { @@ -18,26 +18,16 @@ export const init = ( resolveRelations: string[] = [], ) => { loadBridge(() => { - if (window.storyblok) { - window.storyblok.init({ accessToken: token }); + if (window.StoryblokBridge) { + window.storyblok = new window.StoryblokBridge({ + // accessToken: token, + resolveRelations, + }); // Update story on input in Visual Editor - // this will alter the state and replaces the current story with a - // current raw story object and resolve relations window.storyblok.on('input', (event) => { if (event.story.content.uuid === story?.content?.uuid) { - event.story.content = window.storyblok.addComments( - event.story.content, - event.story.id, - ); - - window.storyblok.resolveRelations( - event.story, - resolveRelations, - () => { - onStoryInput(event.story); - }, - ); + onStoryInput(event.story); } }); } diff --git a/src/story.ts b/src/story.ts index f11265d..b996cfc 100644 --- a/src/story.ts +++ b/src/story.ts @@ -46,6 +46,7 @@ declare global { } interface Window { storyblok: StoryblokBridge; + StoryblokBridge: any; StoryblokCacheVersion: number; } }