UNPKG

@freelensapp/example-extension

Version:
446 lines (445 loc) 18.1 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {}; var react_jsxRuntime; var hasRequiredReact_jsxRuntime; function requireReact_jsxRuntime() { if (hasRequiredReact_jsxRuntime) return react_jsxRuntime; hasRequiredReact_jsxRuntime = 1; react_jsxRuntime = commonjsGlobal.ReactJsxRuntime; return react_jsxRuntime; } var react_jsxRuntimeExports = requireReact_jsxRuntime(); var _freelensapp_extensions; var hasRequired_freelensapp_extensions; function require_freelensapp_extensions() { if (hasRequired_freelensapp_extensions) return _freelensapp_extensions; hasRequired_freelensapp_extensions = 1; _freelensapp_extensions = commonjsGlobal.LensExtensions; return _freelensapp_extensions; } var _freelensapp_extensionsExports = require_freelensapp_extensions(); var mobx; var hasRequiredMobx; function requireMobx() { if (hasRequiredMobx) return mobx; hasRequiredMobx = 1; mobx = commonjsGlobal.Mobx; return mobx; } var mobxExports = requireMobx(); var _Common$Store$Extensi; let _initProto, _init_enabled; function _applyDecs(e, t, r, n, o, a) { function i(e2, t2, r2) { return function(n2, o2) { return r2 && r2(n2), e2[t2].call(n2, o2); }; } function c(e2, t2) { for (var r2 = 0; r2 < e2.length; r2++) e2[r2].call(t2); return t2; } function s(e2, t2, r2, n2) { if ("function" != typeof e2 && (n2 || void 0 !== e2)) throw new TypeError(t2 + " must " + (r2 || "be") + " a function" + (n2 ? "" : " or undefined")); return e2; } function applyDec(e2, t2, r2, n2, o2, a2, c2, u2, l2, f2, p2, d, h) { function m(e3) { if (!h(e3)) throw new TypeError("Attempted to access private element on non-instance"); } var y, v = t2[0], g = t2[3], b = !u2; if (!b) { r2 || Array.isArray(v) || (v = [v]); var w = {}, S = [], A = 3 === o2 ? "get" : 4 === o2 || d ? "set" : "value"; f2 ? (p2 || d ? w = { get: _setFunctionName(function() { return g(this); }, n2, "get"), set: function(e3) { t2[4](this, e3); } } : w[A] = g, p2 || _setFunctionName(w[A], n2, 2 === o2 ? "" : A)) : p2 || (w = Object.getOwnPropertyDescriptor(e2, n2)); } for (var P = e2, j = v.length - 1; j >= 0; j -= r2 ? 2 : 1) { var D = v[j], E = r2 ? v[j - 1] : void 0, I = {}, O = { kind: ["field", "accessor", "method", "getter", "setter", "class"][o2], name: n2, metadata: a2, addInitializer: function(e3, t3) { if (e3.v) throw Error("attempted to call addInitializer after decoration was finished"); s(t3, "An initializer", "be", true), c2.push(t3); }.bind(null, I) }; try { if (b) (y = s(D.call(E, P, O), "class decorators", "return")) && (P = y); else { var k, F; O.static = l2, O.private = f2, f2 ? 2 === o2 ? k = function(e3) { return m(e3), w.value; } : (o2 < 4 && (k = i(w, "get", m)), 3 !== o2 && (F = i(w, "set", m))) : (k = function(e3) { return e3[n2]; }, (o2 < 2 || 4 === o2) && (F = function(e3, t3) { e3[n2] = t3; })); var N = O.access = { has: f2 ? h.bind() : function(e3) { return n2 in e3; } }; if (k && (N.get = k), F && (N.set = F), P = D.call(E, d ? { get: w.get, set: w.set } : w[A], O), d) { if ("object" == typeof P && P) (y = s(P.get, "accessor.get")) && (w.get = y), (y = s(P.set, "accessor.set")) && (w.set = y), (y = s(P.init, "accessor.init")) && S.push(y); else if (void 0 !== P) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0"); } else s(P, (p2 ? "field" : "method") + " decorators", "return") && (p2 ? S.push(P) : w[A] = P); } } finally { I.v = true; } } return (p2 || d) && u2.push(function(e3, t3) { for (var r3 = S.length - 1; r3 >= 0; r3--) t3 = S[r3].call(e3, t3); return t3; }), p2 || b || (f2 ? d ? u2.push(i(w, "get"), i(w, "set")) : u2.push(2 === o2 ? w[A] : i.call.bind(w[A])) : Object.defineProperty(e2, n2, w)), P; } function u(e2, t2) { return Object.defineProperty(e2, Symbol.metadata || Symbol.for("Symbol.metadata"), { configurable: true, enumerable: true, value: t2 }); } if (arguments.length >= 6) var l = a[Symbol.metadata || Symbol.for("Symbol.metadata")]; var f = Object.create(null == l ? null : l), p = function(e2, t2, r2, n2) { var o2, a2, i2 = [], s2 = function(t3) { return _checkInRHS(t3) === e2; }, u2 = /* @__PURE__ */ new Map(); function l2(e3) { e3 && i2.push(c.bind(null, e3)); } for (var f2 = 0; f2 < t2.length; f2++) { var p2 = t2[f2]; if (Array.isArray(p2)) { var d = p2[1], h = p2[2], m = p2.length > 3, y = 16 & d, v = !!(8 & d), g = 0 == (d &= 7), b = h + "/" + v; if (!g && !m) { var w = u2.get(b); if (true === w || 3 === w && 4 !== d || 4 === w && 3 !== d) throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + h); u2.set(b, !(d > 2) || d); } applyDec(v ? e2 : e2.prototype, p2, y, m ? "#" + h : _toPropertyKey(h), d, n2, v ? a2 = a2 || [] : o2 = o2 || [], i2, v, m, g, 1 === d, v && m ? s2 : r2); } } return l2(o2), l2(a2), i2; }(e, t, o, f); return r.length || u(e, f), { e: p, get c() { var t2 = []; return r.length && [u(applyDec(e, [r], n, e.name, 5, f, t2), f), c.bind(null, t2, e)]; } }; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return String(t); } function _setFunctionName(e, t, n) { "symbol" == typeof t && (t = (t = t.description) ? "[" + t + "]" : ""); try { Object.defineProperty(e, "name", { configurable: true, value: n ? n + " " + t : t }); } catch (e2) { } return e; } function _checkInRHS(e) { if (Object(e) !== e) throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? typeof e : "null")); return e; } class ExamplePreferencesStore extends (_Common$Store$Extensi = _freelensapp_extensionsExports.Common.Store.ExtensionStore) { static { [_init_enabled, _initProto] = _applyDecs(this, [[mobxExports.observable, 1, "enabled"]], [], 0, void 0, _Common$Store$Extensi).e; } #A = (_initProto(this), _init_enabled(this, false)); get enabled() { return this.#A; } set enabled(v) { this.#A = v; } constructor() { super({ configName: "example-preferences-store", defaults: { enabled: false } }); console.log("[EXAMPLE-PREFERENCES-STORE] constructor"); mobxExports.makeObservable(this); } fromStore({ enabled }) { console.log(`[EXAMPLE-PREFERENCES-STORE] set ${enabled}`); this.enabled = enabled; } toJSON() { const enabled = this.enabled; console.log(`[EXAMPLE-PREFERENCES-STORE] get ${enabled}`); return { enabled }; } } var mobxReact; var hasRequiredMobxReact; function requireMobxReact() { if (hasRequiredMobxReact) return mobxReact; hasRequiredMobxReact = 1; mobxReact = commonjsGlobal.MobxReact; return mobxReact; } var mobxReactExports = requireMobxReact(); const errorPage = "_errorPage_1y0la_1"; const errorMessage = "_errorMessage_1y0la_8"; const styles$2 = { errorPage, errorMessage }; const stylesInline$2 = "._errorPage_1y0la_1{display:flex;justify-content:center;width:100%;height:100%}._errorMessage_1y0la_8{display:flex;align-items:center;color:var(--colorError)}"; function ErrorPage({ error, extension, children }) { if (error) { _freelensapp_extensionsExports.Common.logger.error(`[${extension.name}]: ${error}`); } return /* @__PURE__ */ react_jsxRuntimeExports.jsxs(react_jsxRuntimeExports.Fragment, { children: [ /* @__PURE__ */ react_jsxRuntimeExports.jsx("style", { children: stylesInline$2 }), /* @__PURE__ */ react_jsxRuntimeExports.jsxs("div", { className: styles$2.errorPage, children: [ error ? /* @__PURE__ */ react_jsxRuntimeExports.jsx("p", { className: styles$2.errorMessage, children: String(error) }) : /* @__PURE__ */ react_jsxRuntimeExports.jsx(react_jsxRuntimeExports.Fragment, {}), children ] }) ] }); } function withErrorPage(props, wrapped) { try { return wrapped(props); } catch (error) { return /* @__PURE__ */ react_jsxRuntimeExports.jsx(ErrorPage, { error, extension: props.extension }); } } const exampleDetails = "_exampleDetails_1vgph_1"; const title$1 = "_title_1vgph_1"; const styles$1 = { exampleDetails, title: title$1 }; const stylesInline$1 = "._exampleDetails_1vgph_1 ._title_1vgph_1{margin-top:16px;margin-bottom:8px}"; const { Component: { BadgeBoolean: BadgeBoolean$1, DrawerItem, MarkdownViewer } } = _freelensapp_extensionsExports.Renderer; const ExampleDetails = mobxReactExports.observer((props) => withErrorPage(props, () => { const { object } = props; const preferences2 = ExamplePreferencesStore.getInstance(); return /* @__PURE__ */ react_jsxRuntimeExports.jsxs(react_jsxRuntimeExports.Fragment, { children: [ /* @__PURE__ */ react_jsxRuntimeExports.jsx("style", { children: stylesInline$1 }), /* @__PURE__ */ react_jsxRuntimeExports.jsxs("div", { className: styles$1.exampleDetails, children: [ /* @__PURE__ */ react_jsxRuntimeExports.jsx(DrawerItem, { name: "Description", children: /* @__PURE__ */ react_jsxRuntimeExports.jsx(MarkdownViewer, { markdown: object.spec.description ?? "" }) }), /* @__PURE__ */ react_jsxRuntimeExports.jsx(DrawerItem, { name: "Example checkbox", children: /* @__PURE__ */ react_jsxRuntimeExports.jsx(BadgeBoolean$1, { value: preferences2.enabled }) }) ] }) ] }); })); const svgIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="800" height="800" viewBox="0 0 32 32"><path d="M5.344 10.688q0 2.912 1.44 5.344t3.936 3.84q.512.736 1.056 1.344l-.032.064q-.032.064 0 .064V25.6q0 .896.608 1.536t1.504.608h4.288q.864 0 1.504-.608t.608-1.536v-4.32q0-.032-.032-.064.544-.608 1.088-1.344 2.432-1.376 3.904-3.84t1.472-5.344-1.44-5.344-3.904-3.904T16 0t-5.344 1.44-3.904 3.904-1.408 5.344m8.512 20.256q0 .448.32.768t.768.288h2.112q.448 0 .768-.288t.32-.768-.32-.768-.768-.32h-2.112q-.448 0-.768.32t-.32.768"/></svg>'; const { Component: { Icon: Icon$1 } } = _freelensapp_extensionsExports.Renderer; function ExampleIcon(props) { return /* @__PURE__ */ react_jsxRuntimeExports.jsx(Icon$1, { ...props, svg: svgIcon }); } class Example extends _freelensapp_extensionsExports.Renderer.K8sApi.LensExtensionKubeObject { static kind = "Example"; static namespaced = true; static apiBase = "/apis/example.freelens.app/v1alpha1/examples"; static crd = { apiVersions: ["example.freelens.app/v1alpha1"], plural: "examples", singular: "example", shortNames: ["ex"], title: "Examples" }; } class ExampleApi extends _freelensapp_extensionsExports.Renderer.K8sApi.KubeApi { } class ExampleStore extends _freelensapp_extensionsExports.Renderer.K8sApi.KubeObjectStore { } const { Component: { MenuItem, Icon } } = _freelensapp_extensionsExports.Renderer; const ExampleActiveToggleMenuItem = (props) => withErrorPage(props, () => { const { object, toolbar } = props; if (!object) return /* @__PURE__ */ react_jsxRuntimeExports.jsx(react_jsxRuntimeExports.Fragment, {}); const store = Example.getStore(); const disable = async () => { await store.patch(object, { spec: { active: false } }, "merge"); }; const enable = async () => { await store.patch(object, { spec: { active: true } }, "merge"); }; if (object.spec.active === false) { return /* @__PURE__ */ react_jsxRuntimeExports.jsxs(MenuItem, { onClick: enable, children: [ /* @__PURE__ */ react_jsxRuntimeExports.jsx(Icon, { material: "play_circle_outline", interactive: toolbar, title: "Resume" }), /* @__PURE__ */ react_jsxRuntimeExports.jsx("span", { className: "title", children: "Resume" }) ] }); } else { return /* @__PURE__ */ react_jsxRuntimeExports.jsxs(MenuItem, { onClick: disable, children: [ /* @__PURE__ */ react_jsxRuntimeExports.jsx(Icon, { material: "pause_circle_filled", interactive: toolbar, title: "Suspend" }), /* @__PURE__ */ react_jsxRuntimeExports.jsx("span", { className: "title", children: "Suspend" }) ] }); } }); var reactRouterDom; var hasRequiredReactRouterDom; function requireReactRouterDom() { if (hasRequiredReactRouterDom) return reactRouterDom; hasRequiredReactRouterDom = 1; reactRouterDom = commonjsGlobal.ReactRouterDom; return reactRouterDom; } var reactRouterDomExports = requireReactRouterDom(); const examplesPage = "_examplesPage_2wcm6_1"; const title = "_title_2wcm6_1"; const active = "_active_2wcm6_4"; const age = "_age_2wcm6_7"; const styles = { examplesPage, title, active, age }; const stylesInline = "._examplesPage_2wcm6_1 .TableCell._title_2wcm6_1{flex-grow:1.5}._examplesPage_2wcm6_1 .TableCell._active_2wcm6_4{flex-grow:.4}._examplesPage_2wcm6_1 .TableCell._age_2wcm6_7{flex-grow:.3}"; const { Component: { BadgeBoolean, KubeObjectAge, KubeObjectListLayout, WithTooltip }, K8sApi: { namespacesApi }, Navigation: { getDetailsUrl } } = _freelensapp_extensionsExports.Renderer; const { Util: { stopPropagation } } = _freelensapp_extensionsExports.Common; const KubeObject = Example; const ExamplesPage = mobxReactExports.observer((props) => withErrorPage(props, () => { const store = KubeObject.getStore(); return /* @__PURE__ */ react_jsxRuntimeExports.jsxs(react_jsxRuntimeExports.Fragment, { children: [ /* @__PURE__ */ react_jsxRuntimeExports.jsx("style", { children: stylesInline }), /* @__PURE__ */ react_jsxRuntimeExports.jsx(KubeObjectListLayout, { tableId: `${KubeObject.crd.singular}Table`, className: styles.examplesPage, store, sortingCallbacks: { name: (object) => object.getName(), namespace: (object) => object.getNs(), active: (object) => String(object.spec.active ?? false), title: (object) => object.spec.title, age: (object) => object.getCreationTimestamp() }, searchFilters: [(object) => object.getSearchFields()], renderHeaderTitle: KubeObject.crd.title, renderTableHeader: [{ title: "Name", sortBy: "name" }, { title: "Namespace", sortBy: "namespace" }, { title: "Active", sortBy: "active", className: styles.active }, { title: "Title", sortBy: "title", className: styles.title }, { title: "Age", sortBy: "age", className: styles.age }], renderTableContents: (object) => [/* @__PURE__ */ react_jsxRuntimeExports.jsx(WithTooltip, { children: object.getName() }), /* @__PURE__ */ react_jsxRuntimeExports.jsx(reactRouterDomExports.Link, { to: getDetailsUrl(namespacesApi.formatUrlForNotListing({ name: object.getNs() })), onClick: stopPropagation, children: /* @__PURE__ */ react_jsxRuntimeExports.jsx(WithTooltip, { children: object.getNs() }) }, "link"), /* @__PURE__ */ react_jsxRuntimeExports.jsx(BadgeBoolean, { value: object.spec.active }), /* @__PURE__ */ react_jsxRuntimeExports.jsx(WithTooltip, { children: object.spec.title }), /* @__PURE__ */ react_jsxRuntimeExports.jsx(KubeObjectAge, { object }, "age")] }) ] }); })); const { Component: { Checkbox } } = _freelensapp_extensionsExports.Renderer; const preferences = ExamplePreferencesStore.getInstanceOrCreate(); const ExamplePreferenceInput = mobxReactExports.observer(() => { return /* @__PURE__ */ react_jsxRuntimeExports.jsx(Checkbox, { label: "Example checkbox", value: preferences.enabled, onChange: (v) => { console.log(`[EXAMPLE-PREFERENCES-STORE] onChange ${v}`); preferences.enabled = v; } }); }); const ExamplePreferenceHint = () => /* @__PURE__ */ react_jsxRuntimeExports.jsx("span", { children: "This is an example of an preference for extensions." }); class ExampleRenderer extends _freelensapp_extensionsExports.Renderer.LensExtension { async onActivate() { await ExamplePreferencesStore.getInstanceOrCreate().loadExtension(this); } appPreferences = [{ title: "Example Preferences", components: { Input: () => /* @__PURE__ */ react_jsxRuntimeExports.jsx(ExamplePreferenceInput, {}), Hint: () => /* @__PURE__ */ react_jsxRuntimeExports.jsx(ExamplePreferenceHint, {}) } }]; kubeObjectDetailItems = [{ kind: Example.kind, apiVersions: Example.crd.apiVersions, priority: 10, components: { Details: (props) => /* @__PURE__ */ react_jsxRuntimeExports.jsx(ExampleDetails, { ...props, extension: this }) } }]; clusterPages = [{ id: Example.crd.plural, components: { Page: () => /* @__PURE__ */ react_jsxRuntimeExports.jsx(ExamplesPage, { extension: this }) } }]; clusterPageMenus = [{ id: Example.crd.plural, title: Example.crd.title, target: { pageId: Example.crd.plural }, components: { Icon: ExampleIcon } }]; kubeObjectMenuItems = [{ kind: Example.kind, apiVersions: Example.crd.apiVersions, components: { MenuItem: (props) => /* @__PURE__ */ react_jsxRuntimeExports.jsx(ExampleActiveToggleMenuItem, { ...props, extension: this }) } }]; } exports.default = ExampleRenderer; //# sourceMappingURL=index.js.map