All files / lib index.js

100% Statements 9/9
100% Branches 2/2
100% Functions 4/4
100% Lines 8/8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60      6x   6x                                                                       6x 4x 2x 2x 2x                 2x          
import Extension from './extension.js';
import postRobot from 'post-robot';
 
const version = '2.0.0';
 
postRobot.CONFIG.LOG_LEVEL = 'debug';
 
/** Class to initialize the plugin on Contentstack UI. */
/**
   * @hideconstructor
   */
 
class ContentstackUIExtension {
  /**
    * You need to first include Contentstack UI Extensions SDK and
    * Contentstack UI Stylesheet in you HTML file and then call
    * ContentstackUIExtension.init in the script tag.
    * @example
    * HTML
    * <script src="https://www.contentstack.com/sdks/contentstack-ui-extensions/2.0.0/ui-extension-sdk.js"></script>
    * <link href="https://www.contentstack.com/sdks/contentstack-ui-extensions/2.0.0/ui-extension-sdk.css" rel="stylesheet" >
    * @example <caption>Custom Filed</caption>
    * // javascript
    * ContentstackUIExtension.init().then(function (extension) {
    *     var value = extension.field.getData()
    *     extension.field.setData("New Field Data")
    * })
    * @example <caption>Custom Widget</caption>
    * // javascript
    * ContentstackUIExtension.init().then(function (extension) {
    *     var entry = extension.entry.getData()
    * })
    * @example <caption>Dashboard Widget</caption>
    * // javascript
    * ContentstackUIExtension.init().then(function (extension) {
    *     var stack = extension.stack;
    *     var stackData = stack.getData();
    * })
    * @return {external:Promise}  A promise object which will be resolved with an instance of the {@link Extension} class which is instantiated using the data received from the Contentstack UI.
    */
  static init() {
    if (this._extension) { return Promise.resolve(this._extension); }
    return Extension.initialize().then((initializationData) => {
      this._extension = new Extension(initializationData);
      return Promise.resolve(this._extension);
    }).catch(e => Promise.reject(e));
  }
 
 
  /**
    * Version of Contentstack UI extension.
    * @type {string}
    */
  static get SDK_VERSION() {
    return version;
  }
}
 
export default ContentstackUIExtension;