{"version":3,"sources":["jsdelivr-header.js","/npm/@advanced-rest-client/rest-api-menu@3.0.0-preview.1/rest-api-menu.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;OCOQ,mBAAqB,kDACtB,kDACA,gDACA,yDACC,qBAAuB,gFACvB,SAAW,+CAmDnB,MAAM,oBAAoB,iBAAiB,iBACzC,mBAAW,GACT,OAAO,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoGb,CAEA,aAAW,GAAM,MAAO,eAAgB,CACxC,qBAAW,GACT,MAAO,CAKL,MAAO,MAIP,SAAU,CACR,KAAM,QACN,UAAU,EACV,QAAQ,GAKV,SAAU,CACR,KAAM,QACN,OAAO,EACP,SAAU,iCACV,QAAQ,GAKV,gBAAiB,CACf,KAAM,QACN,SAAU,+CAGZ,YAAa,OAEb,cAAe,OAKf,YAAa,QAEjB,CAEA,WAAA,GACE,QACA,KAAK,mBAAqB,KAAK,mBAAmB,KAAK,MACvD,KAAK,mBAAqB,KAAK,mBAAmB,KAAK,MACvD,KAAK,cAAgB,KAAK,cAAc,KAAK,MAC7C,KAAK,cAAgB,KAAK,cAAc,KAAK,KAC/C,CAEA,iBAAA,GACE,MAAM,oBACN,OAAO,iBAAiB,sBAAuB,KAAK,oBACpD,OAAO,iBAAiB,4BAA6B,KAAK,oBAC1D,OAAO,iBAAiB,oBAAqB,KAAK,eAClD,OAAO,iBAAiB,cAAe,KAAK,eACvC,KAAK,UAAa,KAAK,OAC1B,KAAK,WAET,CAEA,oBAAA,GACE,MAAM,uBACF,KAAK,iBACP,aAAa,KAAK,gBAClB,KAAK,oBAAiB,GAExB,OAAO,oBAAoB,sBAAuB,KAAK,oBACvD,OAAO,oBAAoB,4BAA6B,KAAK,oBAC7D,OAAO,oBAAoB,oBAAqB,KAAK,eACrD,OAAO,oB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ACtC,IAAX,IAGJ,KAAK,OAAO,QAAS,EAAO,GAC5B,KAAK,cACP,EAEF,OAAO,eAAe,OAAO,YAAY,GAAI","file":"/npm/@advanced-rest-client/rest-api-menu@3.0.0-preview.1/rest-api-menu.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@advanced-rest-client/rest-api-menu@3.0.0-preview.1/rest-api-menu.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/**\n@license\nCopyright 2018 The Advanced REST client authors <arc@mulesoft.com>\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not\nuse this file except in compliance with the License. You may obtain a copy of\nthe License at\nhttp://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\nWARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\nLicense for the specific language governing permissions and limitations under\nthe License.\n*/\nimport {PolymerElement} from '../../@polymer/polymer/polymer-element.js';\nimport '../../@polymer/paper-toast/paper-toast.js';\nimport '../../@polymer/paper-item/paper-item.js';\nimport '../../@polymer/paper-progress/paper-progress.js';\nimport {ArcFileDropMixin} from '../../@advanced-rest-client/arc-file-drop-mixin/arc-file-drop-mixin.js';\nimport {html} from '../../@polymer/polymer/lib/utils/html-tag.js';\n/**\n * A quick access menu for REST API projects\n *\n * A list of REST APIs in the ARC main menu.\n * The element uses direct implementation of the PouchDB to make a query to the\n * datastore.\n * It also listens to `datastore-destroyed` custom event update state of the list\n * items when datastore was destroyed.\n *\n * It listens for `selected-rest-api-changed` custom event as an alternative\n * to setting `selectedApi` property directly on the element.\n *\n * ### Example\n *\n * ```html\n * <rest-api-menu selected-api=\"[[route.api]]\"></rest-api-menu>\n * ```\n *\n * ### Datastore access\n *\n * This element uses events API to access datastore data. This is provided by the\n * `arc-models/rest-api-model` element. See documentation for this element if you\n * need to implement own data exchange logic.\n *\n * Datastore element is not in the shadow DOM of this element and is should be\n * included in the application DOM.\n *\n * ```html\n * <link rel=\"import\" href=\"bower_components/arc-models/rest-api-model.html\">\n * <link rel=\"import\" href=\"bower_components/rest-api-menu/rest-api-menu.html\">\n * <rest-api-menu selected-api=\"[[route.api]]\"></rest-api-menu>\n * <rest-api-model></rest-api-model>\n * ```\n *\n * ### Styling\n * `<rest-api-menu>` provides the following custom properties and mixins for styling:\n *\n * Custom property | Description | Default\n * ----------------|-------------|----------\n * `--rest-api-menu-background-color` | Background color of the menu | `inherit`\n * `--rest-api-menu-selected-item-background-color` | Background color of the selected list item | `rgba(255, 152, 0, 0.24)`\n * `--arc-menu-empty-info-color` | Color applied to the empty info section | ``\n * `--arc-menu-empty-info-title-color` | Color applied to the title in the empty info section | ``\n *\n * @polymer\n * @customElement\n * @memberof UiElements\n * @demo demo/index.html\n * @appliesMixin ArcFileDropMixin\n */\nclass RestApiMenu extends ArcFileDropMixin(PolymerElement) {\n  static get template() {\n    return html`\n    <style>\n    :host {\n      display: block;\n      background-color: var(--rest-api-menu-background-color, inherit);\n      position: relative;\n      overflow: auto;\n      @apply --layout-flex;\n      @apply --layout-vertical;\n    }\n\n    paper-item {\n      @apply --arc-font-menu;\n      font-weight: 400;\n      min-height: 40px;\n      cursor: pointer;\n      @apply --layout-center;\n    }\n\n    paper-item.dragging {\n      z-index: 1;\n      background-color: #fff;\n    }\n\n    paper-item.iron-selected {\n      background-color: var(--rest-api-menu-selected-item-background-color, rgba(255, 152, 0, 0.24));\n    }\n\n    .name {\n      @apply --layout-flex;\n      white-space: nowrap;\n      text-overflow: ellipsis;\n      overflow: hidden;\n      font-size: 14px;\n    }\n\n    paper-progress {\n      width: calc(100% - 32px);\n      margin: 0 16px;\n      position: absolute;\n    }\n\n    .empty-info {\n      @apply --arc-font-body1;\n      font-style: italic;\n      margin: 1em 16px;\n      color: var(--arc-menu-empty-info-color);\n    }\n\n    .empty-title {\n      @apply --paper-font-title;\n      white-space: normal;\n      color: var(--arc-menu-empty-info-title-color);\n    }\n\n    .empty-message {\n      @apply --layout-flex;\n      @apply --layout-vertical;\n      @apply --layout-center-center;\n      text-align: center;\n    }\n\n    [hidden] {\n      display: none !important;\n    }\n\n    .drop-target {\n      display: none;\n      z-index: 100;\n    }\n\n    :host([dragging]) .drop-target {\n      display: block;\n      @apply --layout-fit;\n      @apply --layout-vertical;\n      @apply --layout-center;\n      background-color: #fff;\n      border: 4px var(--drop-file-importer-header-background-color, var(--primary-color)) solid;\n    }\n    </style>\n    <paper-progress hidden\\$=\"[[!querying]]\" indeterminate=\"\"></paper-progress>\n    <template is=\"dom-if\" if=\"[[dataUnavailable]]\">\n      <div class=\"empty-message\">\n        <h3 class=\"empty-title\">Drop API project here</h3>\n        <p class=\"empty-info\">There is no API stored with the application</p>\n      </div>\n    </template>\n    <dom-reorderer on-dom-order-changed=\"_onReorder\">\n\n    </dom-reorderer>\n    <template is=\"dom-repeat\" items=\"[[items]]\" id=\"list\">\n      <paper-item on-tap=\"_openAPI\" title\\$=\"[[item.title]]\" class\\$=\"[[_computeItemClass(item._id, selectedApi)]]\">\n        <span class=\"name\">[[item.title]]</span>\n      </paper-item>\n    </template>\n    <paper-toast id=\"reorderError\" class=\"error-toast\" text=\"Unable to reorder items. Please, report an issue.\"></paper-toast>\n    <section class=\"drop-target\">\n      <p class=\"drop-message\">Drop file here</p>\n    </section>\n`;\n  }\n\n  static get is() {return 'rest-api-menu';}\n  static get properties() {\n    return {\n      /**\n       * Saved items restored from the datastore.\n       * @type {Array<Object>}\n       */\n      items: Array,\n      /**\n       * True when the element is querying the database for the data.\n       */\n      querying: {\n        type: Boolean,\n        readOnly: true,\n        notify: true\n      },\n      /**\n       * Computed value. `true` if the `items` property has values.\n       */\n      hasItems: {\n        type: Boolean,\n        value: false,\n        computed: '_computeHasItems(items.length)',\n        notify: true\n      },\n      /**\n       * Computed value. True if query ended and there's no results.\n       */\n      dataUnavailable: {\n        type: Boolean,\n        computed: '_computeDataUnavailable(hasItems, querying)'\n      },\n      // Currently selected project ID\n      selectedApi: String,\n      // Page token for datastore pagination\n      nextPageToken: String,\n      /**\n       * When set the element won't query for APIs data when connected to the DOM.\n       * In this case manually call `makeQuery()`\n       */\n      noAutoQuery: Boolean\n    };\n  }\n\n  constructor() {\n    super();\n    this._onDatabaseDestroy = this._onDatabaseDestroy.bind(this);\n    this._selecteApiHandler = this._selecteApiHandler.bind(this);\n    this._indexUpdated = this._indexUpdated.bind(this);\n    this._indexDeleted = this._indexDeleted.bind(this);\n  }\n\n  connectedCallback() {\n    super.connectedCallback();\n    window.addEventListener('datastore-destroyed', this._onDatabaseDestroy);\n    window.addEventListener('selected-rest-api-changed', this._selecteApiHandler);\n    window.addEventListener('api-index-changed', this._indexUpdated);\n    window.addEventListener('api-deleted', this._indexDeleted);\n    if (!this.querying && !this.items) {\n      this.makeQuery();\n    }\n  }\n\n  disconnectedCallback() {\n    super.disconnectedCallback();\n    if (this.__queryTimeout) {\n      clearTimeout(this.__queryTimeout);\n      this.__queryTimeout = undefined;\n    }\n    window.removeEventListener('datastore-destroyed', this._onDatabaseDestroy);\n    window.removeEventListener('selected-rest-api-changed', this._selecteApiHandler);\n    window.removeEventListener('api-index-changed', this._indexUpdated);\n    window.removeEventListener('api-deleted', this._indexDeleted);\n  }\n  /**\n   * Resets the state of the variables.\n   */\n  reset() {\n    if (this.nextPageToken) {\n      this.nextPageToken = undefined;\n    }\n    if (this.__queryTimeout) {\n      clearTimeout(this.__queryTimeout);\n      this.__queryTimeout = undefined;\n    }\n    this._setQuerying(false);\n    this.set('items', []);\n  }\n  /**\n   * Refreshes the data from the datastore.\n   * It resets the query options, clears items and makes a query to the datastore.\n   */\n  refresh() {\n    this.reset();\n    this.makeQuery();\n  }\n  // Handler for the `datastore-destroyed` custom event\n  _onDatabaseDestroy(e) {\n    let datastore = e.detail.datastore;\n    if (!datastore || !datastore.length) {\n      return;\n    }\n    if (typeof datastore === 'string') {\n      datastore = [datastore];\n    }\n    if (datastore.indexOf('api-index') === -1 && datastore[0] !== 'all') {\n      return;\n    }\n    this.refresh();\n  }\n  /**\n   * Computes class name for the HTML element representing a saved item.\n   *\n   * @param {String} id An id to compare\n   * @param {String} selectedProject Currently selected API id\n   * @return {String}\n   */\n  _computeItemClass(id, selectedProject) {\n    if (id && id === selectedProject) {\n      return 'iron-selected';\n    }\n    return '';\n  }\n  // Computes value for the `hasItems` property.\n  _computeHasItems(length) {\n    return !!(length);\n  }\n  /**\n   * The function to call when new query for data is needed.\n   * Use this intead of `loadPage()` as this function uses debouncer to\n   * prevent multiple calls at once.\n   */\n  makeQuery() {\n    if (this.__makingQuery) {\n      return;\n    }\n    this.__makingQuery = true;\n    this.__queryTimeout = setTimeout(() => {\n      this.__queryTimeout = undefined;\n      this.__makingQuery = false;\n      this.loadPage();\n    }, 20);\n  }\n\n  _dispatchApiList(detail) {\n    const e = new CustomEvent('api-index-list', {\n      detail,\n      bubbles: true,\n      cancelable: true,\n      composed: true\n    });\n    this.dispatchEvent(e);\n    return e;\n  }\n\n  _getApiListDetail() {\n    const detail = {};\n    if (this.nextPageToken) {\n      detail.nextPageToken = this.nextPageToken;\n    }\n    return detail;\n  }\n  /**\n   * Performs the query and processes the result.\n   * This function immediately queries the data model for data.\n   * It does this in a loop until all data are read.\n   *\n   * @return {Promise}\n   */\n  loadPage() {\n    const detail = this._getApiListDetail();\n    const e = this._dispatchApiList(detail);\n    if (!e.defaultPrevented) {\n      this._setQuerying(false);\n      console.warn('REST API model not in the DOM.');\n      return Promise.reject(new Error('Model not found'));\n    }\n    return e.detail.result\n    .then((result) => {\n      this._setQuerying(false);\n      this.nextPageToken = result.nextPageToken;\n      return result.items;\n    })\n    .then((items) => {\n      if (!items || !items.length) {\n        return;\n      }\n      if (!this.items) {\n        items.sort(this._sortData);\n        this.set('items', items);\n      } else {\n        const concat = this.items.concat(items);\n        concat.sort(this._sortData);\n        this.set('items', concat);\n        this._renderList();\n      }\n      this.makeQuery();\n    })\n    .catch((e) => {\n      this._setQuerying(false);\n      console.warn('Query menu items', e);\n    });\n  }\n\n  _renderList() {\n    this.shadowRoot.querySelector('#list').render();\n  }\n  /**\n   * Sorts projects list by `order` and the `title` properties.\n   *\n   * @param {Object} a\n   * @param {Object} b\n   * @return {Number}\n   */\n  _sortData(a, b) {\n    if (a.order < b.order) {\n      return -1;\n    }\n    if (a.order > b.order) {\n      return 1;\n    }\n    return (a.title || '').localeCompare(b.title);\n  }\n  // Computes value for the `dataUnavailable` property.\n  _computeDataUnavailable(hasItems, querying) {\n    return !hasItems && !querying;\n  }\n  // Handler for the `tap` event on the item.\n  _openAPI(e) {\n    e.preventDefault();\n    e.stopPropagation();\n    e.stopImmediatePropagation();\n    const id = e.model.get('item._id');\n    const version = e.model.get('item.latest');\n    this.dispatchEvent(new CustomEvent('navigate', {\n      bubbles: true,\n      composed: true,\n      detail: {\n        base: 'api-console',\n        id,\n        version\n      }\n    }));\n  }\n  /**\n   * Handler for the `selected-rest-api-changed` event.\n   * It expects the detail object to have `value` property with selection id.\n   * @param {CustomEvent} e\n   */\n  _selecteApiHandler(e) {\n    const id = e.detail.value;\n    if (id && id !== this.selectedApi) {\n      this.set('selectedApi', id);\n    } else if (!id) {\n      this.set('selectedApi', '');\n    }\n  }\n  /**\n   * Index item has been changed and should be updated / added.\n   * Only non-cancelable event is considered.\n   * @param {CustomEvent} e\n   */\n  _indexUpdated(e) {\n    if (e.cancelable) {\n      return;\n    }\n    const item = e.detail.apiInfo;\n    if (!this.items) {\n      this.set('items', [item]);\n      this._renderList();\n      return;\n    }\n    const index = this.items.findIndex((obj) => obj._id === item._id);\n    if (index === -1) {\n      this.push('items', item);\n      this.items.sort(this._sortData);\n      this._renderList();\n    } else {\n      this.set(['items', index], item);\n    }\n  }\n  /**\n   * Handler for API delete event.\n   * Only non-cancelable event is considered.\n   * @param {CustomEvent} e\n   */\n  _indexDeleted(e) {\n    if (e.cancelable) {\n      return;\n    }\n    const items = this.items;\n    if (!items || !items.length) {\n      return;\n    }\n    const id = e.detail.id;\n    const index = items.findIndex((item) => item._id === id);\n    if (index === -1) {\n      return;\n    }\n    this.splice('items', index, 1);\n    this._renderList();\n  }\n}\nwindow.customElements.define(RestApiMenu.is, RestApiMenu);\n"]}