@omnicajs/vue-remote
Version:
Proxy renderer for Vue.js based on @remote-ui
353 lines (352 loc) • 5.95 kB
JavaScript
const ACTION_MOUNT = "mount";
const ACTION_INSERT_CHILD = "insert-child";
const ACTION_REMOVE_CHILD = "remove-child";
const ACTION_UPDATE_TEXT = "update-text";
const ACTION_UPDATE_PROPERTIES = "update-properties";
const ACTION_INVOKE = "invoke";
function createChannel({
mount,
insertChild,
removeChild,
updateProperties,
updateText,
invoke
}) {
const methods = /* @__PURE__ */ new Map([
[ACTION_MOUNT, mount],
[ACTION_INSERT_CHILD, insertChild],
[ACTION_REMOVE_CHILD, removeChild],
[ACTION_UPDATE_PROPERTIES, updateProperties],
[ACTION_UPDATE_TEXT, updateText],
[ACTION_INVOKE, invoke]
]);
return (type, ...payload) => methods.get(type)(...payload);
}
const KIND_COMMENT = "comment";
const KIND_COMPONENT = "component";
const KIND_FRAGMENT = "fragment";
const KIND_ROOT = "root";
const KIND_TEXT = "text";
const ROOT_ID = "~";
const isSerializedComponent = (value) => {
return value != null && value.kind === KIND_COMPONENT;
};
const isSerializedFragment = (value) => {
return value != null && value.kind === KIND_FRAGMENT;
};
const addMethod = (o, name, fn) => {
return Object.defineProperty(o, name, {
value: fn,
configurable: true,
writable: false,
enumerable: false
});
};
const arraify = (value) => Array.isArray(value) ? [...value] : [value];
const capture = (o, freeze) => {
return freeze ? Object.freeze(o) : o;
};
const isFunction = (value) => {
return typeof value === "function";
};
const isObject = (value) => {
if (value == null || typeof value !== "object") {
return false;
}
const prototype = Object.getPrototypeOf(value);
return prototype == null || prototype === Object.prototype;
};
const keysOf = (o) => Object.keys(o);
const visitArray = (value, visited, visit) => {
const result = [];
visited.set(value, result);
for (const nested of value) {
result.push(visit(nested, visited));
}
return result;
};
const visitObject = (value, visited, visit) => {
const result = {};
visited.set(value, result);
for (const key of keysOf(value)) {
result[key] = visit(value[key], visited);
}
return result;
};
const REMOTE_SLOT = "RemoteSlot";
const HTMLTagList = [
"a",
"abbr",
"address",
"area",
"article",
"aside",
"audio",
"b",
"base",
"bdi",
"bdo",
"blockquote",
"body",
"br",
"button",
"canvas",
"caption",
"cite",
"code",
"col",
"colgroup",
"datalist",
"dd",
"del",
"details",
"dfn",
"dialog",
"div",
"dl",
"dt",
"em",
"embed",
"fieldset",
"figcaption",
"figure",
"footer",
"form",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
"head",
"header",
"hgroup",
"hr",
"html",
"i",
"iframe",
"img",
"input",
"ins",
"kbd",
"keygen",
"label",
"legend",
"li",
"link",
"main",
"map",
"mark",
"menu",
"menuitem",
"meta",
"meter",
"nav",
"noscript",
"object",
"ol",
"optgroup",
"option",
"output",
"p",
"param",
"picture",
"pre",
"progress",
"q",
"rp",
"rt",
"ruby",
"s",
"samp",
"script",
"section",
"select",
"small",
"source",
"span",
"strong",
"style",
"sub",
"summary",
"sup",
"table",
"tbody",
"td",
"textarea",
"tfoot",
"th",
"thead",
"time",
"title",
"tr",
"track",
"u",
"ul",
"var",
"video",
"wbr"
];
const MathMLTagList = [
"math",
"maction",
"maligngroup",
"malignmark",
"menclose",
"merror",
"mfenced",
"mfrac",
"mglyph",
"mi",
"mlabeledtr",
"mlongdiv",
"mmultiscripts",
"mn",
"mo",
"mover",
"mpadded",
"mphantom",
"mroot",
"mrow",
"ms",
"mscarries",
"mscarry",
"msgroup",
"msline",
"mstack",
"mspace",
"msqrt",
"msrow",
"mstyle",
"msub",
"msup",
"msubsup",
"mtable",
"mtd",
"mtext",
"mtr",
"munder",
"munderover",
"none",
"semantics",
"annotation",
"annotation-xml"
];
const SVGTagList = [
"a",
"altGlyph",
"altGlyphDef",
"altGlyphItem",
"animate",
"animateColor",
"animateMotion",
"animateTransform",
"circle",
"clipPath",
"color-profile",
"cursor",
"defs",
"desc",
"discard",
"ellipse",
"feBlend",
"feColorMatrix",
"feComponentTransfer",
"feComposite",
"feConvolveMatrix",
"feDiffuseLighting",
"feDisplacementMap",
"feDistantLight",
"feDropShadow",
"feFlood",
"feFuncA",
"feFuncB",
"feFuncG",
"feFuncR",
"feGaussianBlur",
"feImage",
"feMerge",
"feMergeNode",
"feMorphology",
"feOffset",
"fePointLight",
"feSpecularLighting",
"feSpotLight",
"feTile",
"feTurbulence",
"filter",
"font",
"font-face",
"font-face-format",
"font-face-name",
"font-face-src",
"font-face-uri",
"foreignObject",
"g",
"glyph",
"glyphRef",
"hkern",
"image",
"line",
"linearGradient",
"marker",
"mask",
"metadata",
"missing-glyph",
"mpath",
"path",
"pattern",
"polygon",
"polyline",
"radialGradient",
"rect",
"script",
"set",
"stop",
"style",
"svg",
"switch",
"symbol",
"text",
"textPath",
"title",
"tref",
"tspan",
"use",
"view",
"vkern"
];
const isHTMLTag = (tag) => HTMLTagList.includes(tag);
const isMathMLTag = (tag) => MathMLTagList.includes(tag);
const isSVGTag = (tag) => SVGTagList.includes(tag);
const isDOMTag = (tag) => isHTMLTag(tag) || isMathMLTag(tag) || isSVGTag(tag);
export {
ACTION_MOUNT as A,
HTMLTagList as H,
KIND_COMPONENT as K,
MathMLTagList as M,
ROOT_ID as R,
SVGTagList as S,
isSerializedFragment as a,
addMethod as b,
KIND_ROOT as c,
createChannel as d,
KIND_TEXT as e,
KIND_COMMENT as f,
REMOTE_SLOT as g,
isDOMTag as h,
isSerializedComponent as i,
isFunction as j,
keysOf as k,
ACTION_INSERT_CHILD as l,
ACTION_REMOVE_CHILD as m,
ACTION_UPDATE_PROPERTIES as n,
ACTION_UPDATE_TEXT as o,
KIND_FRAGMENT as p,
ACTION_INVOKE as q,
capture as r,
isObject as s,
visitObject as t,
arraify as u,
visitArray as v
};