UNPKG

@contentful/rich-text-types

Version:

Type definitions and constants for the Contentful rich text field type.

80 lines (79 loc) 2.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "Path", { enumerable: true, get: function() { return Path; } }); function _array_like_to_array(arr, len) { if (len == null || len > arr.length) len = arr.length; for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; return arr2; } function _array_without_holes(arr) { if (Array.isArray(arr)) return _array_like_to_array(arr); } function _class_call_check(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _define_property(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _iterable_to_array(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _non_iterable_spread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _to_consumable_array(arr) { return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread(); } function _unsupported_iterable_to_array(o, minLen) { if (!o) return; if (typeof o === "string") return _array_like_to_array(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen); } var Path = function Path() { "use strict"; var _this = this; var path = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : []; _class_call_check(this, Path); _define_property(this, "path", void 0); _define_property(this, "of", void 0); _define_property(this, "isRoot", void 0); _define_property(this, "last", void 0); _define_property(this, "toArray", void 0); this.path = path; this.of = function(element) { return new Path(_to_consumable_array(_this.path).concat([ element ])); }; this.isRoot = function() { return _this.path.length === 0; }; this.last = function() { return _this.path[_this.path.length - 1]; }; this.toArray = function() { return _this.path; }; };