vuepress-api-playground
Version:
The VuePress API Playground is a Vue.js component for showcasing and testing API use cases in VuePress documentation
556 lines (520 loc) • 17.5 kB
JavaScript
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = "fb15");
/******/ })
/************************************************************************/
/******/ ({
/***/ "fb15":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// NAMESPACE OBJECT: ./src/components/index.js
var components_namespaceObject = {};
__webpack_require__.r(components_namespaceObject);
__webpack_require__.d(components_namespaceObject, "default", function() { return components_Playground; });
// CONCATENATED MODULE: ./node_modules/@vue/cli-service/lib/commands/build/setPublicPath.js
// This file is imported into lib/wc client bundles.
if (typeof window !== 'undefined') {
var currentScript = window.document.currentScript
if (false) { var getCurrentScript; }
var src = currentScript && currentScript.src.match(/(.+\/)[^/]+\.js(\?.*)?$/)
if (src) {
__webpack_require__.p = src[1] // eslint-disable-line
}
}
// Indicate to webpack that this file can be concatenated
/* harmony default export */ var setPublicPath = (null);
// CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"14537a5a-vue-loader-template"}!./node_modules/cache-loader/dist/cjs.js??ref--13-0!./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/loaders/templateLoader.js??ref--6!./node_modules/cache-loader/dist/cjs.js??ref--1-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/Playground/Playground.vue?vue&type=template&id=e503453c&
var render = function render() {
var _vm = this,
_c = _vm._self._c;
return _c('div', {
staticClass: "vp-playground"
}, [_vm.showMethod ? _c(_vm.headingTag, {
tag: "component",
staticClass: "vp-playground__method"
}, [_vm._v(" Method: "), _c('Badge', {
attrs: {
"type": "warn",
"text": _vm.method.toUpperCase(),
"vertical": "unset"
}
})], 1) : _vm._e(), _vm.showURL ? _c(_vm.headingTag, {
tag: "component",
staticClass: "vp-playground__url"
}, [_vm._v(" URL: "), _c('code', {
staticStyle: {
"word-break": "break-word"
}
}, [_vm._v(_vm._s(_vm.url))])]) : _vm._e(), _vm.headers && Object.keys(_vm.headers).length > 0 ? _c('div', [_c(_vm.headingTag, {
tag: "component"
}, [_vm._v("Headers:")]), _c('table', [_vm._m(0), _c('tbody', _vm._l(Object.keys(_vm.headers), function (item, id) {
return _c('tr', {
key: `headers-${id}`
}, [_c('td', [_vm._v(_vm._s(item))]), _c('td', [_c('input', {
directives: [{
name: "model",
rawName: "v-model",
value: _vm.headers[item],
expression: "headers[item]"
}],
attrs: {
"type": "text"
},
domProps: {
"value": _vm.headers[item]
},
on: {
"enter": _vm.request,
"input": function ($event) {
if ($event.target.composing) return;
_vm.$set(_vm.headers, item, $event.target.value);
}
}
})])]);
}), 0)])], 1) : _vm._e(), _c(_vm.headingTag, {
tag: "component"
}, [_vm._v("Data:")]), _vm.inputData && _vm.inputData.length > 0 ? _c('table', [_vm._m(1), _c('tbody', _vm._l(_vm.inputData, function (item, id) {
return _c('tr', {
key: `data-${id}`
}, [_c('td', [_vm._v(_vm._s(item.name))]), _c('td', [item.type === 'checkbox' ? _c('input', {
directives: [{
name: "model",
rawName: "v-model",
value: item.value,
expression: "item.value"
}],
attrs: {
"type": "checkbox"
},
domProps: {
"checked": Array.isArray(item.value) ? _vm._i(item.value, null) > -1 : item.value
},
on: {
"enter": _vm.request,
"change": function ($event) {
var $$a = item.value,
$$el = $event.target,
$$c = $$el.checked ? true : false;
if (Array.isArray($$a)) {
var $$v = null,
$$i = _vm._i($$a, $$v);
if ($$el.checked) {
$$i < 0 && _vm.$set(item, "value", $$a.concat([$$v]));
} else {
$$i > -1 && _vm.$set(item, "value", $$a.slice(0, $$i).concat($$a.slice($$i + 1)));
}
} else {
_vm.$set(item, "value", $$c);
}
}
}
}) : item.type === 'radio' ? _c('input', {
directives: [{
name: "model",
rawName: "v-model",
value: item.value,
expression: "item.value"
}],
attrs: {
"type": "radio"
},
domProps: {
"checked": _vm._q(item.value, null)
},
on: {
"enter": _vm.request,
"change": function ($event) {
return _vm.$set(item, "value", null);
}
}
}) : _c('input', {
directives: [{
name: "model",
rawName: "v-model",
value: item.value,
expression: "item.value"
}],
attrs: {
"type": item.type
},
domProps: {
"value": item.value
},
on: {
"enter": _vm.request,
"input": function ($event) {
if ($event.target.composing) return;
_vm.$set(item, "value", $event.target.value);
}
}
})])]);
}), 0)]) : _vm._e(), _c('button', {
attrs: {
"disabled": _vm.loading
},
on: {
"click": function ($event) {
return _vm.request();
}
}
}, [!_vm.loading ? _c('span', [_vm._v("Execute")]) : _c('span', [_vm._v("Loading")])]), _vm.response.text ? _c('div', {
staticClass: "vp-playground__response"
}, [_vm.response.code ? _c('span', {
staticClass: "vp-playground__status"
}, [_vm._v(" Status: "), _c('Badge', {
attrs: {
"type": _vm.response.code < 300 ? 'tip' : 'error',
"text": `${_vm.response.code}`,
"vertical": "unset"
}
})], 1) : _vm._e(), _c('div', {
staticClass: "language- extra-class"
}, [_c('pre', {
staticClass: "language-text"
}, [_c('code', [_vm._v(_vm._s(_vm.response.text))])])])]) : _vm._e()], 1);
};
var staticRenderFns = [function () {
var _vm = this,
_c = _vm._self._c;
return _c('thead', [_c('tr', [_c('th', [_vm._v("Key")]), _c('th', [_vm._v("Value")])])]);
}, function () {
var _vm = this,
_c = _vm._self._c;
return _c('thead', [_c('tr', [_c('th', [_vm._v("Key")]), _c('th', [_vm._v("Value")])])]);
}];
// CONCATENATED MODULE: ./src/components/Playground/Playground.vue?vue&type=template&id=e503453c&
// CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js??ref--13-0!./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--1-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/Playground/Playground.vue?vue&type=script&lang=js&
/* harmony default export */ var Playgroundvue_type_script_lang_js_ = ({
name: 'VuepressApiPlayground',
data() {
return {
loading: false,
inputData: [],
response: {
text: null,
code: null
}
};
},
props: {
url: {
type: String,
required: true
},
method: {
type: String,
required: true
},
data: {
type: Array,
required: false
},
showMethod: {
type: Boolean,
required: false,
default: false
},
showURL: {
type: Boolean,
required: false,
default: false
},
headingTag: {
type: String,
required: false,
default: 'h4'
},
headers: {
type: Object,
required: false,
default: null
}
},
mounted() {
this.inputData = [...this.data];
},
methods: {
clearResponseData() {
this.response = {
text: null,
code: null
};
},
getRequestData() {
if (this.inputData) {
const result = {};
this.inputData.forEach(item => {
try {
result[item.name] = JSON.parse(item.value);
} catch {
if (item.value !== '') {
result[item.name] = item.value;
}
}
});
return result;
}
return null;
},
getRequestParams() {
const requestData = this.getRequestData();
let {
url
} = this;
const method = this.method.toLowerCase();
let data = {
method
};
const urlMatchArray = [url.match(/{([a-zA-Z_-]+)}/g), url.match(/<([a-zA-Z_-]+)>/g)];
urlMatchArray.forEach(urlMatch => {
if (urlMatch) {
urlMatch.forEach(element => {
url = url.replace(element, requestData[element.slice(1, -1)]);
delete requestData[element.slice(1, -1)];
});
}
});
if (requestData) {
if (method === 'post' || method === 'put' || method === 'patch') {
const headers = this.headers || {
'Content-Type': 'application/json'
};
data = Object.assign(data, {
headers,
body: JSON.stringify(requestData)
});
} else {
let searchParams = new URLSearchParams(requestData).toString();
if (searchParams !== '') searchParams = `?${searchParams}`;
url = `${url}${searchParams}`;
}
}
return {
url,
data
};
},
request() {
const requestParams = this.getRequestParams();
this.clearResponseData();
this.loading = true;
fetch(requestParams.url, requestParams.data).then(response => {
this.loading = false;
this.response.code = response.status ? response.status : null;
return response.json();
}).then(result => {
this.response.text = result;
}).catch(error => {
this.loading = false;
this.response.text = error;
});
}
}
});
// CONCATENATED MODULE: ./src/components/Playground/Playground.vue?vue&type=script&lang=js&
/* harmony default export */ var Playground_Playgroundvue_type_script_lang_js_ = (Playgroundvue_type_script_lang_js_);
// CONCATENATED MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
/* globals __VUE_SSR_CONTEXT__ */
// IMPORTANT: Do NOT use ES2015 features in this file (except for modules).
// This module is a runtime utility for cleaner component module output and will
// be included in the final webpack user bundle.
function normalizeComponent(
scriptExports,
render,
staticRenderFns,
functionalTemplate,
injectStyles,
scopeId,
moduleIdentifier /* server only */,
shadowMode /* vue-cli only */
) {
// Vue.extend constructor export interop
var options =
typeof scriptExports === 'function' ? scriptExports.options : scriptExports
// render functions
if (render) {
options.render = render
options.staticRenderFns = staticRenderFns
options._compiled = true
}
// functional template
if (functionalTemplate) {
options.functional = true
}
// scopedId
if (scopeId) {
options._scopeId = 'data-v-' + scopeId
}
var hook
if (moduleIdentifier) {
// server build
hook = function (context) {
// 2.3 injection
context =
context || // cached call
(this.$vnode && this.$vnode.ssrContext) || // stateful
(this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
// 2.2 with runInNewContext: true
if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
context = __VUE_SSR_CONTEXT__
}
// inject component styles
if (injectStyles) {
injectStyles.call(this, context)
}
// register component module identifier for async chunk inferrence
if (context && context._registeredComponents) {
context._registeredComponents.add(moduleIdentifier)
}
}
// used by ssr in case component is cached and beforeCreate
// never gets called
options._ssrRegister = hook
} else if (injectStyles) {
hook = shadowMode
? function () {
injectStyles.call(
this,
(options.functional ? this.parent : this).$root.$options.shadowRoot
)
}
: injectStyles
}
if (hook) {
if (options.functional) {
// for template-only hot-reload because in that case the render fn doesn't
// go through the normalizer
options._injectStyles = hook
// register for functional component in vue file
var originalRender = options.render
options.render = function renderWithStyleInjection(h, context) {
hook.call(context)
return originalRender(h, context)
}
} else {
// inject component registration as beforeCreate hook
var existing = options.beforeCreate
options.beforeCreate = existing ? [].concat(existing, hook) : [hook]
}
}
return {
exports: scriptExports,
options: options
}
}
// CONCATENATED MODULE: ./src/components/Playground/Playground.vue
/* normalize component */
var component = normalizeComponent(
Playground_Playgroundvue_type_script_lang_js_,
render,
staticRenderFns,
false,
null,
null,
null
)
/* harmony default export */ var Playground = (component.exports);
// CONCATENATED MODULE: ./src/components/Playground/index.js
/* harmony default export */ var components_Playground = (Playground);
// CONCATENATED MODULE: ./src/components/index.js
// CONCATENATED MODULE: ./src/main.js
const ComponentLibrary = {
install(Vue = {}) {
Object.values(components_namespaceObject).forEach(component => {
Vue.component(component.name, component);
});
}
};
/* harmony default export */ var main = (ComponentLibrary);
if (typeof window !== 'undefined' && window.Vue) {
window.Vue.use(ComponentLibrary);
}
// CONCATENATED MODULE: ./node_modules/@vue/cli-service/lib/commands/build/entry-lib.js
/* harmony default export */ var entry_lib = __webpack_exports__["default"] = (main);
/***/ })
/******/ });
//# sourceMappingURL=VuepressApiPlayground.common.js.map