@gitlab/ui
Version:
GitLab UI Components
133 lines (103 loc) • 3.75 kB
JavaScript
import has from 'lodash/has';
import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
return arr2;
}
}
function _iterableToArray(iter) {
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance");
}
var PREFIX = '%{';
var SUFFIX = '}';
var START_SUFFIX = "Start".concat(SUFFIX);
var END_SUFFIX = "End".concat(SUFFIX);
var PLACE_HOLDER_REGEX = new RegExp("(".concat(PREFIX, "[a-z]+[\\w-]*[a-z0-9]+").concat(SUFFIX, ")"), 'gi');
var script = {
functional: true,
props: {
message: {
type: String,
required: true
}
},
/**
* While a functional style is generally preferred, an imperative style is
* used here, as it lends itself better to the message parsing algorithm.
* This approach is also more performant, as it minimizes (relatively) object
* creation/garbage collection, which is important given how frequently this
* code may run on a given page.
*/
render: function render(createElement, context) {
var i = 0;
var vnodes = [];
var slots = context.scopedSlots;
var chunks = context.props.message.split(PLACE_HOLDER_REGEX);
while (i < chunks.length) {
var chunk = chunks[i]; // Skip past this chunk now we have it
i += 1;
if (!PLACE_HOLDER_REGEX.test(chunk)) {
// Not a placeholder, so pass through as-is
vnodes.push(chunk);
continue;
}
if (chunk.endsWith(START_SUFFIX)) {
var _slotName = chunk.slice(PREFIX.length, -START_SUFFIX.length); // Peek ahead to find end placeholder, if any
var indexOfEnd = chunks.indexOf("".concat(PREFIX).concat(_slotName).concat(END_SUFFIX), i);
if (indexOfEnd > -1) {
// We have a valid start/end placeholder pair! Extract the content
// between them and skip past the end placeholder
var content = chunks.slice(i, indexOfEnd);
i = indexOfEnd + 1;
if (!has(slots, _slotName)) {
// Slot hasn't been provided; return placeholders and content as-is
vnodes.push.apply(vnodes, [chunk].concat(_toConsumableArray(content), [chunks[indexOfEnd]]));
continue;
} // Provide content to provided scoped slot
vnodes.push(slots[_slotName]({
content: content.join('')
}));
continue;
}
} // By process of elimination, chunk must be a plain placeholder
var slotName = chunk.slice(PREFIX.length, -SUFFIX.length);
vnodes.push(has(slots, slotName) ? slots[slotName]() : chunk);
continue;
}
return vnodes;
}
};
/* script */
const __vue_script__ = script;
/* template */
/* style */
const __vue_inject_styles__ = undefined;
/* scoped */
const __vue_scope_id__ = undefined;
/* module identifier */
const __vue_module_identifier__ = undefined;
/* functional template */
const __vue_is_functional_template__ = undefined;
/* style inject */
/* style inject SSR */
/* style inject shadow dom */
const __vue_component__ = __vue_normalize__(
{},
__vue_inject_styles__,
__vue_script__,
__vue_scope_id__,
__vue_is_functional_template__,
__vue_module_identifier__,
false,
undefined,
undefined,
undefined
);
export default __vue_component__;