Giter VIP home page Giter VIP logo

live-preview-sdk's Introduction

Contentstack Live Preview Utils SDK

Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. Build your application frontend, and Contentstack will take care of the rest.

Contentstack provides the Live Preview Utils SDK to establish a communication channel between the various Contentstack SDKs and your website, transmitting live changes to the preview pane. Read More.

Installation

To install the package via npm, use the following command:

npm install @contentstack/live-preview-utils

Alternatively, if you want to include the package directly in your website HTML code, use the following command:

<script src="https://unpkg.com/@contentstack/[email protected]/dist/legacy/index.js"></script>

Initializing the SDK

Live Preview Utils

Since the Live Preview Utils SDK is responsible for communication, you need to only initialize it. Use the following command to initialize the SDK:

import ContentstackLivePreview from "@contentstack/live-preview-utils";

ContentstackLivePreview.init({
    stackDetails: {
        apiKey: "your-stack-api-key",
    },
});

Alternatively, if you want to initialize the SDK directly inside the HTML tag, use the ContentstackLivePreview.init() method as follows:

<script>
    ContentstackLivePreview.init({
        stackDetails: {
            apiKey: "your-stack-api-key",
        },
    });
</script>

License

MIT License

Copyright © 2024 Contentstack. All Rights Reserved

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

live-preview-sdk's People

Contributors

aravindbuilt avatar contentstack-admin avatar contentstackmridul avatar deepak-kharah avatar kane-99 avatar nandeesh-gajula avatar ravencolevol avatar sairajchouhan avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

lsliwaradioluz

live-preview-sdk's Issues

LivePreview callback uid and content type uid

Hi,

I managed to set this up for our project as a poc, but would like to request an enhancement on this feature.

It would be great if the uid and content type is passed to the call back, so we only re-render specific components, instead of everything.

SSR live preview doing too much

window.addEventListener("load", (e) => {

The SSR listeners that change how links/clicks work are breaking our site links. It's changing links from relative to absolute, which we don't want. It would be nice to be able to turn this off, and/or give us a way to disable live preview unless we are inside the Contentstack iFrame. I currently have the following code so that live preview only breaks our links in preview and not our deployed site.

We are using Next.js with SSR queries.

if (typeof window !== 'undefined'
  && window.location !== window.parent.location
  && window.location.ancestorOrigins[0] === 'https://app.contentstack.com'
  && (ContentstackLivePreview.hash == null || ContentstackLivePreview.hash === '')) {
  console.log('Initializing Contentstack Live Preview')
  void ContentstackLivePreview.init({
    ssr: true,
    runScriptsOnUpdate: false,
    cleanCslpOnProduction: false,
    editButton: {
      enable: false
    }
  })
}

Another solution I think that could help is if we could default the live preview in Contentstack to SSR with a setting so we can expect the URL params on first load.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.