UNPKG

attributes-kit

Version:
1,506 lines (1,275 loc) 1.05 MB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("react"), require("react-dom")); else if(typeof define === 'function' && define.amd) define(["react", "react-dom"], factory); else if(typeof exports === 'object') exports["AttributesKit"] = factory(require("react"), require("react-dom")); else root["AttributesKit"] = factory(root["React"], root["react-dom"]); })(this, function(__WEBPACK_EXTERNAL_MODULE_1__, __WEBPACK_EXTERNAL_MODULE_2__) { return /******/ (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] = { /******/ exports: {}, /******/ id: moduleId, /******/ loaded: false /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.loaded = 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; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(0); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ function(module, exports, __webpack_require__) { /* REACT HOT LOADER */ if (false) { (function () { var ReactHotAPI = require("/Users/Frantisek/Documents/Projects/Apiary/attributes-component/node_modules/react-hot-api/modules/index.js"), React = require("react"); module.makeHot = module.hot.data ? module.hot.data.makeHot : ReactHotAPI(React); })(); } try { (function () { 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = __webpack_require__(1); var _react2 = _interopRequireDefault(_react); var _reactDom = __webpack_require__(2); var _reactDom2 = _interopRequireDefault(_reactDom); var _events = __webpack_require__(3); var _Attributes = __webpack_require__(4); var _Attributes2 = _interopRequireDefault(_Attributes); var _Attribute = __webpack_require__(15); var _Attribute2 = _interopRequireDefault(_Attribute); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var AttributesKit = function (_EventEmitter) { _inherits(AttributesKit, _EventEmitter); _createClass(AttributesKit, null, [{ key: 'render', value: function render(refractElement, element, options) { var elementSelector = null; if (typeof element === 'string') { elementSelector = element; } var attributesKit = new AttributesKit({ element: element, elementSelector: elementSelector, options: options }); attributesKit.render(refractElement); return attributesKit; } }]); function AttributesKit(options) { _classCallCheck(this, AttributesKit); var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(AttributesKit).call(this)); _this.options = options || {}; _this.element = options.element; _this.elementSelector = options.elementSelector; _this.options = options.options; _this.getElement(); _this.validate(); return _this; } _createClass(AttributesKit, [{ key: 'validate', value: function validate() { if (!this.element) { throw Error('Unable to find element where to render attributes.'); } } }, { key: 'getElement', value: function getElement() { if (this.element) { return this.element; } this.element = document.querySelector(this.elementSelector); return this.element; } }, { key: 'render', value: function render(refractElement) { _reactDom2.default.render(_react2.default.createElement(_Attributes2.default, { element: refractElement, dataStructures: this.options.dataStructures }), this.element); } }]); return AttributesKit; }(_events.EventEmitter); // Exports AttributesKit.Attributes = _Attributes2.default; AttributesKit.Attribute = _Attribute2.default; exports.default = AttributesKit; module.exports = exports['default']; /* REACT HOT LOADER */ }).call(this); } finally { if (false) { (function () { var foundReactClasses = module.hot.data && module.hot.data.foundReactClasses || false; if (module.exports && module.makeHot) { var makeExportsHot = require("/Users/Frantisek/Documents/Projects/Apiary/attributes-component/node_modules/react-hot-loader/makeExportsHot.js"); if (makeExportsHot(module, require("react"))) { foundReactClasses = true; } var shouldAcceptModule = true && foundReactClasses; if (shouldAcceptModule) { module.hot.accept(function (err) { if (err) { console.error("Cannot apply hot update to " + "index.js" + ": " + err.message); } }); } } module.hot.dispose(function (data) { data.makeHot = module.makeHot; data.foundReactClasses = foundReactClasses; }); })(); } } /***/ }, /* 1 */ /***/ function(module, exports) { module.exports = __WEBPACK_EXTERNAL_MODULE_1__; /***/ }, /* 2 */ /***/ function(module, exports) { module.exports = __WEBPACK_EXTERNAL_MODULE_2__; /***/ }, /* 3 */ /***/ function(module, exports) { // Copyright Joyent, Inc. and other Node contributors. // // 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. function EventEmitter() { this._events = this._events || {}; this._maxListeners = this._maxListeners || undefined; } module.exports = EventEmitter; // Backwards-compat with node 0.10.x EventEmitter.EventEmitter = EventEmitter; EventEmitter.prototype._events = undefined; EventEmitter.prototype._maxListeners = undefined; // By default EventEmitters will print a warning if more than 10 listeners are // added to it. This is a useful default which helps finding memory leaks. EventEmitter.defaultMaxListeners = 10; // Obviously not all Emitters should be limited to 10. This function allows // that to be increased. Set to zero for unlimited. EventEmitter.prototype.setMaxListeners = function(n) { if (!isNumber(n) || n < 0 || isNaN(n)) throw TypeError('n must be a positive number'); this._maxListeners = n; return this; }; EventEmitter.prototype.emit = function(type) { var er, handler, len, args, i, listeners; if (!this._events) this._events = {}; // If there is no 'error' event listener then throw. if (type === 'error') { if (!this._events.error || (isObject(this._events.error) && !this._events.error.length)) { er = arguments[1]; if (er instanceof Error) { throw er; // Unhandled 'error' event } throw TypeError('Uncaught, unspecified "error" event.'); } } handler = this._events[type]; if (isUndefined(handler)) return false; if (isFunction(handler)) { switch (arguments.length) { // fast cases case 1: handler.call(this); break; case 2: handler.call(this, arguments[1]); break; case 3: handler.call(this, arguments[1], arguments[2]); break; // slower default: args = Array.prototype.slice.call(arguments, 1); handler.apply(this, args); } } else if (isObject(handler)) { args = Array.prototype.slice.call(arguments, 1); listeners = handler.slice(); len = listeners.length; for (i = 0; i < len; i++) listeners[i].apply(this, args); } return true; }; EventEmitter.prototype.addListener = function(type, listener) { var m; if (!isFunction(listener)) throw TypeError('listener must be a function'); if (!this._events) this._events = {}; // To avoid recursion in the case that type === "newListener"! Before // adding it to the listeners, first emit "newListener". if (this._events.newListener) this.emit('newListener', type, isFunction(listener.listener) ? listener.listener : listener); if (!this._events[type]) // Optimize the case of one listener. Don't need the extra array object. this._events[type] = listener; else if (isObject(this._events[type])) // If we've already got an array, just append. this._events[type].push(listener); else // Adding the second element, need to change to array. this._events[type] = [this._events[type], listener]; // Check for listener leak if (isObject(this._events[type]) && !this._events[type].warned) { if (!isUndefined(this._maxListeners)) { m = this._maxListeners; } else { m = EventEmitter.defaultMaxListeners; } if (m && m > 0 && this._events[type].length > m) { this._events[type].warned = true; console.error('(node) warning: possible EventEmitter memory ' + 'leak detected. %d listeners added. ' + 'Use emitter.setMaxListeners() to increase limit.', this._events[type].length); if (typeof console.trace === 'function') { // not supported in IE 10 console.trace(); } } } return this; }; EventEmitter.prototype.on = EventEmitter.prototype.addListener; EventEmitter.prototype.once = function(type, listener) { if (!isFunction(listener)) throw TypeError('listener must be a function'); var fired = false; function g() { this.removeListener(type, g); if (!fired) { fired = true; listener.apply(this, arguments); } } g.listener = listener; this.on(type, g); return this; }; // emits a 'removeListener' event iff the listener was removed EventEmitter.prototype.removeListener = function(type, listener) { var list, position, length, i; if (!isFunction(listener)) throw TypeError('listener must be a function'); if (!this._events || !this._events[type]) return this; list = this._events[type]; length = list.length; position = -1; if (list === listener || (isFunction(list.listener) && list.listener === listener)) { delete this._events[type]; if (this._events.removeListener) this.emit('removeListener', type, listener); } else if (isObject(list)) { for (i = length; i-- > 0;) { if (list[i] === listener || (list[i].listener && list[i].listener === listener)) { position = i; break; } } if (position < 0) return this; if (list.length === 1) { list.length = 0; delete this._events[type]; } else { list.splice(position, 1); } if (this._events.removeListener) this.emit('removeListener', type, listener); } return this; }; EventEmitter.prototype.removeAllListeners = function(type) { var key, listeners; if (!this._events) return this; // not listening for removeListener, no need to emit if (!this._events.removeListener) { if (arguments.length === 0) this._events = {}; else if (this._events[type]) delete this._events[type]; return this; } // emit removeListener for all listeners on all events if (arguments.length === 0) { for (key in this._events) { if (key === 'removeListener') continue; this.removeAllListeners(key); } this.removeAllListeners('removeListener'); this._events = {}; return this; } listeners = this._events[type]; if (isFunction(listeners)) { this.removeListener(type, listeners); } else if (listeners) { // LIFO order while (listeners.length) this.removeListener(type, listeners[listeners.length - 1]); } delete this._events[type]; return this; }; EventEmitter.prototype.listeners = function(type) { var ret; if (!this._events || !this._events[type]) ret = []; else if (isFunction(this._events[type])) ret = [this._events[type]]; else ret = this._events[type].slice(); return ret; }; EventEmitter.prototype.listenerCount = function(type) { if (this._events) { var evlistener = this._events[type]; if (isFunction(evlistener)) return 1; else if (evlistener) return evlistener.length; } return 0; }; EventEmitter.listenerCount = function(emitter, type) { return emitter.listenerCount(type); }; function isFunction(arg) { return typeof arg === 'function'; } function isNumber(arg) { return typeof arg === 'number'; } function isObject(arg) { return typeof arg === 'object' && arg !== null; } function isUndefined(arg) { return arg === void 0; } /***/ }, /* 4 */ /***/ function(module, exports, __webpack_require__) { /* REACT HOT LOADER */ if (false) { (function () { var ReactHotAPI = require("/Users/Frantisek/Documents/Projects/Apiary/attributes-component/node_modules/react-hot-api/modules/index.js"), React = require("react"); module.makeHot = module.hot.data ? module.hot.data.makeHot : ReactHotAPI(React); })(); } try { (function () { 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _eidolon = __webpack_require__(5); var _eidolon2 = _interopRequireDefault(_eidolon); var _react = __webpack_require__(1); var _react2 = _interopRequireDefault(_react); var _Attribute = __webpack_require__(15); var _Attribute2 = _interopRequireDefault(_Attribute); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var Attributes = function (_React$Component) { _inherits(Attributes, _React$Component); function Attributes() { _classCallCheck(this, Attributes); return _possibleConstructorReturn(this, Object.getPrototypeOf(Attributes).apply(this, arguments)); } _createClass(Attributes, [{ key: 'render', value: function render() { var element = this.props.element; if (element && this.props.dataStructures) { // Convert the list into a map of id -> structure. var structures = {}; var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; try { for (var _iterator = this.props.dataStructures[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var item = _step.value; structures[item.meta.id] = item; } // Dereference the element. This overwrites the original // value with the normalized result. Reference information // is still available in the `meta.ref` properties. } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } } element = JSON.parse(JSON.stringify(element)); element = _eidolon2.default.dereference(element, structures); } return _react2.default.createElement( 'div', null, _react2.default.createElement( 'div', null, _react2.default.createElement( 'h1', null, 'Attributes' ) ), _react2.default.createElement( 'div', null, _react2.default.createElement(_Attribute2.default, { element: element, theme: this.props.theme }) ) ); } }]); return Attributes; }(_react2.default.Component); Attributes.propTypes = { dataStructures: _react2.default.PropTypes.array, element: _react2.default.PropTypes.object, theme: _react2.default.PropTypes.object }; exports.default = Attributes; module.exports = exports['default']; /* REACT HOT LOADER */ }).call(this); } finally { if (false) { (function () { var foundReactClasses = module.hot.data && module.hot.data.foundReactClasses || false; if (module.exports && module.makeHot) { var makeExportsHot = require("/Users/Frantisek/Documents/Projects/Apiary/attributes-component/node_modules/react-hot-loader/makeExportsHot.js"); if (makeExportsHot(module, require("react"))) { foundReactClasses = true; } var shouldAcceptModule = true && foundReactClasses; if (shouldAcceptModule) { module.hot.accept(function (err) { if (err) { console.error("Cannot apply hot update to " + "Attributes.js" + ": " + err.message); } }); } } module.hot.dispose(function (data) { data.makeHot = module.makeHot; data.foundReactClasses = foundReactClasses; }); })(); } } /***/ }, /* 5 */ /***/ function(module, exports, __webpack_require__) { // Generated by CoffeeScript 1.10.0 (function() { var Eidolon, dereference, generateExample, generateSchema, inherit; dereference = __webpack_require__(6); generateExample = __webpack_require__(8); generateSchema = __webpack_require__(9); inherit = __webpack_require__(7).inherit; Eidolon = (function() { function Eidolon(structures) { this.structures = structures != null ? structures : {}; } Eidolon.prototype.dereference = function(element) { return dereference(element, this.structures); }; Eidolon.prototype.example = function(element) { return generateExample(element, this.structures); }; Eidolon.prototype.schema = function(element) { return generateSchema(element, this.structures); }; return Eidolon; })(); module.exports = { Eidolon: Eidolon, dereference: dereference, example: generateExample, inherit: inherit, schema: generateSchema }; }).call(this); /***/ }, /* 6 */ /***/ function(module, exports, __webpack_require__) { // Generated by CoffeeScript 1.10.0 (function() { var dereference, inherit, ref1, uniqueMembers; ref1 = __webpack_require__(7), uniqueMembers = ref1.uniqueMembers, inherit = ref1.inherit; module.exports = dereference = function(root, dataStructures) { var base, i, item, j, len, member, properties, property, ref, ref2; switch (root.element) { case 'enum': case 'array': root.content = (function() { var j, len, ref2, results; ref2 = root.content || []; results = []; for (j = 0, len = ref2.length; j < len; j++) { item = ref2[j]; results.push(dereference(item, dataStructures)); } return results; })(); return root; case 'object': properties = root.content ? root.content.slice(0) : []; i = 0; while (i < properties.length) { member = properties[i]; i++; if (member.element === 'ref') { i--; ref = dataStructures[member.content.href]; ref.content = JSON.parse(JSON.stringify(ref.content)); ref2 = ref.content; for (j = 0, len = ref2.length; j < len; j++) { property = ref2[j]; if (property.meta == null) { property.meta = {}; } property.meta.ref = member.content.href; if ((base = property.meta).links == null) { base.links = []; } property.meta.links.push({ relation: 'origin', href: 'http://refract.link/included-member/' }); } properties.splice.apply(properties, [i, 1].concat(ref.content)); continue; } if (member.content.key) { member.content.key = dereference(member.content.key, dataStructures); } if (member.content.value) { member.content.value = dereference(member.content.value, dataStructures); } } root.content = uniqueMembers(properties); return root; default: ref = dataStructures[root.element]; if (ref) { return dereference(inherit(ref, root), dataStructures); } else { return root; } } }; }).call(this); /***/ }, /* 7 */ /***/ function(module, exports) { // Generated by CoffeeScript 1.10.0 (function() { var inherit, uniqueMembers, hasProp = {}.hasOwnProperty; uniqueMembers = function(content) { var i, key, known; known = {}; i = 0; while (i < content.length) { if (content[i].element === 'member') { key = content[i].content.key.content; if (known[key] !== void 0) { content[known[key]] = content[i]; content.splice(i, 1); continue; } else { known[key] = i; } } i++; } return content; }; inherit = function(base, element) { var base1, base2, combined, item, j, k, key, len, len1, ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7, value; combined = JSON.parse(JSON.stringify(base)); if (((ref = base.meta) != null ? ref.id : void 0) != null) { delete combined.meta.id; combined.meta.ref = base.meta.id; if ((base1 = combined.meta).links == null) { base1.links = []; } combined.meta.links.push({ relation: 'origin', href: 'http://refract.link/inherited/' }); if ((ref1 = combined.content) != null ? ref1.length : void 0) { ref2 = combined.content; for (j = 0, len = ref2.length; j < len; j++) { item = ref2[j]; if (item.element) { if (!(item.meta && item.meta.ref)) { if (item.meta == null) { item.meta = {}; } item.meta.ref = base.meta.id; if ((base2 = item.meta).links == null) { base2.links = []; } item.meta.links.push({ relation: 'origin', href: 'http://refract.link/inherited-member/' }); } } } } } if (element.meta) { if (combined.meta == null) { combined.meta = {}; } ref3 = element.meta; for (key in ref3) { if (!hasProp.call(ref3, key)) continue; value = ref3[key]; combined.meta[key] = value; } } if (element.attributes) { if (combined.attributes == null) { combined.attributes = {}; } ref4 = element.attributes; for (key in ref4) { if (!hasProp.call(ref4, key)) continue; value = ref4[key]; combined.attributes[key] = value; } } if (element.content) { if (((ref5 = combined.content) != null ? ref5.push : void 0) || ((ref6 = element.content) != null ? ref6.push : void 0)) { if (combined.content == null) { combined.content = []; } ref7 = element.content; for (k = 0, len1 = ref7.length; k < len1; k++) { item = ref7[k]; combined.content.push(item); } if (combined.content.length && combined.content[0].element === 'member') { uniqueMembers(combined.content); } } else { if (element.content != null) { combined.content = element.content; } } } return combined; }; module.exports = { uniqueMembers: uniqueMembers, inherit: inherit }; }).call(this); /***/ }, /* 8 */ /***/ function(module, exports, __webpack_require__) { // Generated by CoffeeScript 1.10.0 (function() { var defaultValue, dereference, generateExample; dereference = __webpack_require__(6); defaultValue = function(type) { switch (type) { case 'boolean': return true; case 'number': return 1; case 'string': return 'Hello, world!'; } }; generateExample = function(root) { var i, item, j, key, len, len1, member, obj, ref, ref1, ref2, results; switch (root.element) { case 'boolean': case 'string': case 'number': if (root.content != null) { return root.content; } else { if (((ref = root.attributes) != null ? ref["default"] : void 0) !== void 0) { return root.attributes["default"]; } else { return defaultValue(root.element); } } break; case 'enum': return generateExample(root.content[0]); case 'array': ref1 = root.content || []; results = []; for (i = 0, len = ref1.length; i < len; i++) { item = ref1[i]; results.push(generateExample(item)); } return results; break; case 'object': obj = {}; ref2 = root.content; for (j = 0, len1 = ref2.length; j < len1; j++) { member = ref2[j]; if (member.element === 'select') { member = member.content[0].content[0]; } key = member.content.key.content; obj[key] = member.content.value ? generateExample(member.content.value) : defaultValue('string'); } return obj; } }; module.exports = function(root, dataStructures) { return generateExample(dereference(root, dataStructures)); }; }).call(this); /***/ }, /* 9 */ /***/ function(module, exports, __webpack_require__) { // Generated by CoffeeScript 1.10.0 (function() { var deepEqual, dereference, generateSchema; deepEqual = __webpack_require__(10).deepEqual; dereference = __webpack_require__(6); generateSchema = function(root, top) { var error, exclusive, i, item, items, j, k, key, len, len1, len2, len3, m, member, option, optionSchema, prop, properties, ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9, required, schema, typeAttr; if (top == null) { top = true; } schema = {}; if (top) { schema['$schema'] = 'http://json-schema.org/draft-04/schema#'; } switch (root.element) { case 'boolean': case 'string': case 'number': schema.type = root.element; if (((ref = root.attributes) != null ? ref["default"] : void 0) != null) { schema["default"] = root.attributes["default"]; } break; case 'enum': schema["enum"] = []; ref1 = root.content || []; for (i = 0, len = ref1.length; i < len; i++) { item = ref1[i]; schema["enum"].push(item.content); } break; case 'array': schema.type = 'array'; items = []; ref2 = root.content || []; for (j = 0, len1 = ref2.length; j < len1; j++) { item = ref2[j]; items.push(generateSchema(item, false)); } if (items.length === 1) { schema.items = items[0]; } else if (items.length > 1) { try { schema.items = items.reduce(function(l, r) { return deepEqual(l, r) || r; }); } catch (error) { schema.items = { 'anyOf': items }; } } break; case 'object': case 'option': schema.type = 'object'; schema.properties = {}; required = []; properties = root.content.slice(0); ref3 = root.content; for (k = 0, len2 = ref3.length; k < len2; k++) { member = ref3[k]; if (member.element === 'select') { exclusive = []; ref4 = member.content; for (m = 0, len3 = ref4.length; m < len3; m++) { option = ref4[m]; optionSchema = generateSchema(option, false); ref5 = optionSchema.properties; for (key in ref5) { prop = ref5[key]; exclusive.push(key); schema.properties[key] = prop; } } if (!schema.allOf) { schema.allOf = []; } schema.allOf.push({ not: { required: exclusive } }); continue; } key = member.content.key.content; schema.properties[key] = member.content.value ? generateSchema(member.content.value, false) : { type: 'string' }; if (((ref6 = member.meta) != null ? ref6.description : void 0) != null) { schema.properties[key].description = member.meta.description; } if ((ref7 = member.attributes) != null ? ref7.typeAttributes : void 0) { typeAttr = member.attributes.typeAttributes; if (typeAttr.indexOf('required') !== -1) { if (required.indexOf(key) === -1) { required.push(key); } } if (typeAttr.indexOf('nullable') !== -1) { schema.properties[key].type = [schema.properties[key].type, 'null']; } } } if (required.length) { schema.required = required; } } if (((ref8 = root.meta) != null ? ref8.description : void 0) != null) { schema.description = root.meta.description; } if ((ref9 = root.attributes) != null ? ref9.typeAttributes : void 0) { typeAttr = root.attributes.typeAttributes; if (typeAttr.indexOf('nullable') !== -1) { schema.type = [schema.type, 'null']; } } return schema; }; module.exports = function(root, dataStructures) { return generateSchema(dereference(root, dataStructures)); }; }).call(this); /***/ }, /* 10 */ /***/ function(module, exports, __webpack_require__) { // http://wiki.commonjs.org/wiki/Unit_Testing/1.0 // // THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8! // // Originally from narwhal.js (http://narwhaljs.org) // Copyright (c) 2009 Thomas Robinson <280north.com> // // 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 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. // when used in node, this will actually load the util module we depend on // versus loading the builtin util module as happens otherwise // this is a bug in node module loading as far as I am concerned var util = __webpack_require__(11); var pSlice = Array.prototype.slice; var hasOwn = Object.prototype.hasOwnProperty; // 1. The assert module provides functions that throw // AssertionError's when particular conditions are not met. The // assert module must conform to the following interface. var assert = module.exports = ok; // 2. The AssertionError is defined in assert. // new assert.AssertionError({ message: message, // actual: actual, // expected: expected }) assert.AssertionError = function AssertionError(options) { this.name = 'AssertionError'; this.actual = options.actual; this.expected = options.expected; this.operator = options.operator; if (options.message) { this.message = options.message; this.generatedMessage = false; } else { this.message = getMessage(this); this.generatedMessage = true; } var stackStartFunction = options.stackStartFunction || fail; if (Error.captureStackTrace) { Error.captureStackTrace(this, stackStartFunction); } else { // non v8 browsers so we can have a stacktrace var err = new Error(); if (err.stack) { var out = err.stack; // try to strip useless frames var fn_name = stackStartFunction.name; var idx = out.indexOf('\n' + fn_name); if (idx >= 0) { // once we have located the function frame // we need to strip out everything before it (and its line) var next_line = out.indexOf('\n', idx + 1); out = out.substring(next_line + 1); } this.stack = out; } } }; // assert.AssertionError instanceof Error util.inherits(assert.AssertionError, Error); function replacer(key, value) { if (util.isUndefined(value)) { return '' + value; } if (util.isNumber(value) && !isFinite(value)) { return value.toString(); } if (util.isFunction(value) || util.isRegExp(value)) { return value.toString(); } return value; } function truncate(s, n) { if (util.isString(s)) { return s.length < n ? s : s.slice(0, n); } else { return s; } } function getMessage(self) { return truncate(JSON.stringify(self.actual, replacer), 128) + ' ' + self.operator + ' ' + truncate(JSON.stringify(self.expected, replacer), 128); } // At present only the three keys mentioned above are used and // understood by the spec. Implementations or sub modules can pass // other keys to the AssertionError's constructor - they will be // ignored. // 3. All of the following functions must throw an AssertionError // when a corresponding condition is not met, with a message that // may be undefined if not provided. All assertion methods provide // both the actual and expected values to the assertion error for // display purposes. function fail(actual, expected, message, operator, stackStartFunction) { throw new assert.AssertionError({ message: message, actual: actual, expected: expected, operator: operator, stackStartFunction: stackStartFunction }); } // EXTENSION! allows for well behaved errors defined elsewhere. assert.fail = fail; // 4. Pure assertion tests whether a value is truthy, as determined // by !!guard. // assert.ok(guard, message_opt); // This statement is equivalent to assert.equal(true, !!guard, // message_opt);. To test strictly for the value true, use // assert.strictEqual(true, guard, message_opt);. function ok(value, message) { if (!value) fail(value, true, message, '==', assert.ok); } assert.ok = ok; // 5. The equality assertion tests shallow, coercive equality with // ==. // assert.equal(actual, expected, message_opt); assert.equal = function equal(actual, expected, message) { if (actual != expected) fail(actual, expected, message, '==', assert.equal); }; // 6. The non-equality assertion tests for whether two objects are not equal // with != assert.notEqual(actual, expected, message_opt); assert.notEqual = function notEqual(actual, expected, message) { if (actual == expected) { fail(actual, expected, message, '!=', assert.notEqual); } }; // 7. The equivalence assertion tests a deep equality relation. // assert.deepEqual(actual, expected, message_opt); assert.deepEqual = function deepEqual(actual, expected, message) { if (!_deepEqual(actual, expected)) { fail(actual, expected, message, 'deepEqual', assert.deepEqual); } }; function _deepEqual(actual, expected) { // 7.1. All identical values are equivalent, as determined by ===. if (actual === expected) { return true; } else if (util.isBuffer(actual) && util.isBuffer(expected)) { if (actual.length != expected.length) return false; for (var i = 0; i < actual.length; i++) { if (actual[i] !== expected[i]) return false; } return true; // 7.2. If the expected value is a Date object, the actual value is // equivalent if it is also a Date object that refers to the same time. } else if (util.isDate(actual) && util.isDate(expected)) { return actual.getTime() === expected.getTime(); // 7.3 If the expected value is a RegExp object, the actual value is // equivalent if it is also a RegExp object with the same source and // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`). } else if (util.isRegExp(actual) && util.isRegExp(expected)) { return actual.source === expected.source && actual.global === expected.global && actual.multiline === expected.multiline && actual.lastIndex === expected.lastIndex && actual.ignoreCase === expected.ignoreCase; // 7.4. Other pairs that do not both pass typeof value == 'object', // equivalence is determined by ==. } else if (!util.isObject(actual) && !util.isObject(expected)) { return actual == expected; // 7.5 For all other Object pairs, including Array objects, equivalence is // determined by having the same number of owned properties (as verified // with Object.prototype.hasOwnProperty.call), the same set of keys // (although not necessarily the same order), equivalent values for every // corresponding key, and an identical 'prototype' property. Note: this // accounts for both named and indexed properties on Arrays. } else { return objEquiv(actual, expected); } } function isArguments(object) { return Object.prototype.toString.call(object) == '[object Arguments]'; } function objEquiv(a, b) { if (util.isNullOrUndefined(a) || util.isNullOrUndefined(b)) return false; // an identical 'prototype' property. if (a.prototype !== b.prototype) return false; // if one is a primitive, the other must be same if (util.isPrimitive(a) || util.isPrimitive(b)) { return a === b; } var aIsArgs = isArguments(a), bIsArgs = isArguments(b); if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs)) return false; if (aIsArgs) { a = pSlice.call(a); b = pSlice.call(b); return _deepEqual(a, b); } var ka = objectKeys(a), kb = objectKeys(b), key, i; // having the same number of owned properties (keys incorporates // hasOwnProperty) if (ka.length != kb.length) return false; //the same set of keys (although not necessarily the same order), ka.sort(); kb.sort(); //~~~cheap key test for (i = ka.length - 1; i >= 0; i--) { if (ka[i] != kb[i]) return false; } //equivalent values for every corresponding key, and //~~~possibly expensive deep test for (i = ka.length - 1; i >= 0; i--) { key = ka[i]; if (!_deepEqual(a[key], b[key])) return false; } return true; } // 8. The non-equivalence assertion tests for any deep inequality. // assert.notDeepEqual(actual, expected, message_opt); assert.notDeepEqual = function notDeepEqual(actual, expected, message) { if (_deepEqual(actual, expected)) { fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual); } }; // 9. The strict equality assertion tests strict equality, as determined by ===. // assert.strictEqual(actual, expected, message_opt); assert.strictEqual = function strictEqual(actual, expected, message) { if (actual !== expected) { fail(actual, expected, message, '===', assert.strictEqual); } }; // 10. The strict non-equality assertion tests for strict inequality, as // determined by !==. assert.notStrictEqual(actual, expected, message_opt); assert.notStrictEqual = function notStrictEqual(actual, expected, message) { if (actual === expected) { fail(actual, expected, message, '!==', assert.notStrictEqual); } }; function expectedException(actual, expected) { if (!actual || !expected) { return false; } if (Object.prototype.toString.call(expected) == '[object RegExp]') { return expected.test(actual); } else if (actual instanceof expected) { return true; } else if (expected.call({}, actual) === true) { return true; } return false; } function _throws(shouldThrow, block, expected, message) { var actual; if (util.isString(expected)) { message = expected; expected = null; } try { block(); } catch (e) { actual = e; } message = (expected && expected.name ? ' (' + expected.name + ').' : '.') + (message ? ' ' + message : '.'); if (shouldThrow && !actual) { fail(actual, expected, 'Missing expected exception' + message); } if (!shouldThrow && expectedException(actual, expected)) { fail(actual, expected, 'Got unwanted exception' + message); } if ((shouldThrow && actual && expected && !expectedException(actual, expected)) || (!shouldThrow && actual)) { throw actual; } } // 11. Expected to throw an error: // assert.throws(block, Error_opt, message_opt); assert.throws = function(block, /*optional*/error, /*optional*/message) { _throws.apply(this, [true].concat(pSlice.call(arguments))); }; // EXTENSION! This is annoying to write outside this module. assert.doesNotThrow = function(block, /*optional*/message) { _throws.apply(this, [false].concat(pSlice.call(arguments))); }; assert.ifError = function(err) { if (err) {throw err;}}; var objectKeys = Object.keys || function (obj) { var keys = []; for (var key in obj) { if (hasOwn.call(obj, key)) keys.push(key); } return keys; }; /***/ }, /* 11 */ /***/ function(module, exports, __webpack_require__) { /* WEBPACK VAR INJECTION */(function(global, process) {// Copyright Joyent, Inc. and other Node contributors. // // 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. var formatRegExp = /%[sdj%]/g; exports.format = function(f) { if (!isString(f)) { var objects = []; for (var i = 0; i < arguments.length; i++) { objects.push(inspect(arguments[i])); } return objects.join(' '); } var i = 1; var args = arguments; var len = args.length; var str = String(f).replace(formatRegExp, function(x) { if (x === '%%') return '%'; if (i >= len) return x; switch (x) { case '%s': return String(args[i++]); case '%d': return Number(args[i++]); case '%j': try { return JSON.stringify(args[i++]); } catch (_) { return '[Circular]'; } default: return x; } }); for (var x = args[i]; i < len; x = args[++i]) { if (isNull(x) || !isObject(x)) { str += ' ' + x; } else { str += ' ' + inspect(x); } } return str; }; // Mark that a method should not be used. // Returns a modified function which warns once by default. // If --no-deprecation is set, then it is a no-op. exports.deprecate = function(fn, msg) { // Allow for deprecating things in the process of starting up. if (isUndefined(global.process)) { return function() { return exports.deprecate(fn, msg).apply(this, arguments); }; } if (process.noDeprecation === true) { return fn; } var warned = false; function deprecated() { if (!warned) { if (process.throwDeprecation) { throw new Error(msg); } else if (process.traceDeprecation) { console.trace(msg); } else { console.error(msg); } warned = true; } return fn.a