UNPKG

api-console-assets

Version:

This repo only exists to publish api console components to npm

205 lines (192 loc) 6.24 kB
<!-- @license Copyright 2016 The Advanced REST client authors <arc@mulesoft.com> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <link rel="import" href="../polymer/polymer.html"> <link rel="import" href="../docs-parameters-table/docs-json-parameters-table.html"> <link rel="import" href="../docs-parameters-table/docs-xml-parameters-table.html"> <link rel="import" href="../docs-parameters-table/docs-json-structure-view.html"> <link rel="import" href="../docs-parameters-table/raml-type-property-description.html"> <link rel="import" href="../docs-parameters-table/docs-parameters-table-shared-styles.html"> <link rel="import" href="../raml-behaviors/raml-behavior.html"> <link rel="import" href="../iron-media-query/iron-media-query.html"> <!-- `<raml-docs-types-viewer>` A documentation viewer for RAML types ### Example ``` <raml-docs-types-viewer></raml-docs-types-viewer> ``` ### Styling `<raml-docs-types-viewer>` provides the following custom properties and mixins for styling: Custom property | Description | Default ----------------|-------------|---------- `--raml-docs-types-viewer` | Mixin applied to the element | `{}` @group RAML Elements @element raml-docs-types-viewer @demo demo/index.html --> <dom-module id="raml-docs-types-viewer"> <template> <style include="markdown-styles"></style> <style include="docs-parameters-table-shared-styles"></style> <style> :host { display: block; } h2 { @apply(--arc-font-headline); @apply(--raml-docs-h1); } h2 .value { font-weight: var(--raml-docs-types-viewer-title-type-font-weight, 500); margin-left: 8px; } .type-desc { margin-bottom: 28px; color: rgba(0, 0, 0, 0.74); @apply(--arc-font-body1); @apply(--raml-docs-types-viewer-content-section); @apply(--raml-docs-item-description); } </style> <h2> <span class="label">Type</span> <span class="value">[[typeName(type)]]</span> </h2> <template is="dom-if" if="[[!isPrimitive]]" restamp> <template is="dom-if" if="[[hasValue(type.description)]]" restamp> <div class="type-desc"> <marked-element markdown="[[type.description]]"> <div class="markdown-html markdown-body"></div> </marked-element> </div> </template> </template> <template is="dom-if" if="[[isObject]]" restamp> <docs-json-parameters-table type="[[typeProperties(type)]]" structure-display-opened narrow="[[narrow]]"></docs-json-parameters-table> </template> <template is="dom-if" if="[[isJson]]" restamp> <docs-json-structure-view type="[[type]]" structure-display-opened has-type narrow="[[narrow]]"></docs-json-structure-view> </template> <template is="dom-if" if="[[isXml]]" restamp> <docs-xml-parameters-table type="[[type]]" structure-display-opened narrow="[[narrow]]"></docs-xml-parameters-table> </template> <template is="dom-if" if="[[isPrimitive]]" restamp> <raml-type-property-description item="[[type]]" display-type></raml-type-property-description> </template> <iron-media-query query="max-width: 640px" query-matches="{{narrow}}"></iron-media-query> </template> <script> Polymer({ is: 'raml-docs-types-viewer', behaviors: [Polymer.RamlBehavior], properties: { // A type declaration to display. type: Object, /** * Set to true when whould display narrow layout. */ narrow: Boolean, // Computed value, true if current type is a RAML type definition isObject: { type: Object, value: false, readOnly: true }, // Computed value, true if current type is a JSON schema isJson: { type: Object, value: false, readOnly: true }, // Computed value, true if current type is an XML type object isXml: { type: Object, value: false, readOnly: true }, // Computed value, true if current type is a primitive isPrimitive: { type: Object, value: false, readOnly: true } }, observers: ['_computeType(type)'], /** * Resets read only properties states. */ reset: function() { this._setIsObject(false); this._setIsJson(false); this._setIsXml(false); this._setIsPrimitive(false); }, /** * Computes type of passed in `type` property object. */ _computeType: function(obj) { this.reset(); if (!obj) { return; } var type = obj.type; switch (type) { case 'object': case 'array': case 'union': this._setIsObject(true); break; case 'xml': this._setIsXml(true); break; case 'json': this._setIsJson(true); break; case 'nil': case 'number': case 'integer': case 'string': case 'boolean': case 'date-only': case 'time-only': case 'datetime-only': case 'datetime': case 'file': this._setIsPrimitive(true); break; default: type = this._detectType(obj.type); if (type === 'xml') { this._setIsXml(true); } else if (type === 'json') { this._setIsJson(true); } else { this._setIsPrimitive(true); } } }, _detectType: function(type) { if (!type || typeof type !== 'string') { return; } type = type.trim(); if (type[0] === '<') { return 'xml'; } if (type[0] === '{' || type[0] === '[') { return 'json'; } } }); </script> </dom-module>