@64mb/freelens-power 2.21.1 → 2.21.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/renderer.js CHANGED
@@ -16166,6 +16166,8 @@ function startCatalogDisconnect() {
16166
16166
  var icons$3 = {
16167
16167
  "View Details": { material: "info_outline" },
16168
16168
  Settings: { material: "settings" },
16169
+ "Upload Icon": { material: "file_upload" },
16170
+ Clear: { material: "clear" },
16169
16171
  "Open kubeconfig": { material: "edit" },
16170
16172
  Connect: { material: "link" },
16171
16173
  Disconnect: { material: "link_off" },
@@ -16193,7 +16195,11 @@ function startCatalogMenuIcons() {
16193
16195
  const first = menu.querySelector(":scope > .MenuItem");
16194
16196
  return first && titleOf(first) === "Remove from Hotbar";
16195
16197
  });
16196
- const items = /* @__PURE__ */ new Set([...document.querySelectorAll("[data-testid^=\"menu-actions-for-catalog-for-\"] .MenuItem"), ...hotbarMenus.flatMap((menu) => [...menu.querySelectorAll(":scope > .MenuItem")])]);
16198
+ const items = /* @__PURE__ */ new Set([
16199
+ ...document.querySelectorAll("[data-testid^=\"menu-actions-for-catalog-for-\"] .MenuItem"),
16200
+ ...document.querySelectorAll("[data-testid^=\"menu-actions-for-cluster-icon-settings-for-\"] .MenuItem"),
16201
+ ...hotbarMenus.flatMap((menu) => [...menu.querySelectorAll(":scope > .MenuItem")])
16202
+ ]);
16197
16203
  for (const item of items) {
16198
16204
  const title = titleOf(item);
16199
16205
  const icon = icons$3[title];
@@ -16937,6 +16943,113 @@ function ClusterIconsPage() {
16937
16943
  })]
16938
16944
  });
16939
16945
  }
16946
+ // src/renderer/cluster-icon-settings-menu.tsx
16947
+ function startClusterIconSettingsMenu() {
16948
+ const prefix = "menu-actions-for-cluster-icon-settings-for-";
16949
+ const owned = /* @__PURE__ */ new Map();
16950
+ const modal = document.createElement("div");
16951
+ document.body.append(modal);
16952
+ let stopped = false;
16953
+ let request = 0;
16954
+ const open = async (id) => {
16955
+ if (stopped) return;
16956
+ const current = ++request;
16957
+ try {
16958
+ const entries = await ipcRenderer.invoke(CLUSTER_ICONS_CHANNEL, { operation: "list" });
16959
+ if (stopped || current !== request) return;
16960
+ const entry = entries.find((item) => item.id === id);
16961
+ if (!entry) return;
16962
+ renderIntoContainer(/* @__PURE__ */ jsx$1(IconEditor, {
16963
+ entry,
16964
+ onClose: () => unmountContainer(modal),
16965
+ onSaved: () => unmountContainer(modal)
16966
+ }, id), modal);
16967
+ } catch {
16968
+ if (!stopped && current === request) Renderer$1.Component.Notifications.error("Unable to open the cluster icon editor. Try again.");
16969
+ }
16970
+ };
16971
+ const addMenu = (entity, context) => {
16972
+ if (!Renderer$1.Catalog.getClusterById(entity.getId())) return;
16973
+ context.menuItems.push({
16974
+ title: "Edit icon",
16975
+ icon: "palette",
16976
+ onClick: () => void open(entity.getId())
16977
+ });
16978
+ };
16979
+ let category;
16980
+ const stopCategory = reaction(() => Renderer$1.Catalog.catalogCategories.getForGroupKind("entity.k8slens.dev", "KubernetesCluster"), (next) => {
16981
+ category?.off("contextMenuOpen", addMenu);
16982
+ category = next;
16983
+ category?.on("contextMenuOpen", addMenu);
16984
+ }, { fireImmediately: true });
16985
+ const remove = (menu, button) => {
16986
+ unmountContainer(button);
16987
+ button.remove();
16988
+ owned.delete(menu);
16989
+ };
16990
+ const update = () => {
16991
+ for (const [menu, button] of owned) if (!menu.isConnected) remove(menu, button);
16992
+ for (const menu of document.querySelectorAll(`[data-testid^="${prefix}"]`)) {
16993
+ if (owned.has(menu)) continue;
16994
+ const id = menu.dataset.testid?.slice(43);
16995
+ if (!id || !Renderer$1.Catalog.getClusterById(id)) continue;
16996
+ const button = document.createElement("li");
16997
+ button.tabIndex = 0;
16998
+ button.setAttribute("role", "menuitem");
16999
+ button.className = "MenuItem";
17000
+ button.setAttribute("aria-label", "Edit icon");
17001
+ button.onclick = () => {
17002
+ if (stopped) return;
17003
+ document.querySelector(`[data-testid="icon-for-${prefix}${CSS.escape(id)}"]`)?.click();
17004
+ open(id);
17005
+ };
17006
+ menu.append(button);
17007
+ owned.set(menu, button);
17008
+ renderIntoContainer(/* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx$1(Renderer$1.Component.Icon, {
17009
+ material: "palette",
17010
+ size: 18
17011
+ }), " Edit icon"] }), button);
17012
+ }
17013
+ };
17014
+ const onKeyDown = (event) => {
17015
+ if (event.defaultPrevented || event.isComposing || event.altKey || event.ctrlKey || event.metaKey) return;
17016
+ const target = event.target;
17017
+ if (!(target instanceof Element)) return;
17018
+ const menu = Array.from(owned.keys()).find((item) => item.contains(target));
17019
+ if (!menu) return;
17020
+ const items = Array.from(menu.querySelectorAll(":scope > .MenuItem:not(.disabled)"));
17021
+ const index = items.findIndex((item) => item === target || item.contains(target));
17022
+ if (index < 0) return;
17023
+ let next;
17024
+ if (event.key === "ArrowDown") next = items[(index + 1) % items.length];
17025
+ else if (event.key === "ArrowUp") next = items[(index - 1 + items.length) % items.length];
17026
+ else if (event.key === "Home") next = items[0];
17027
+ else if (event.key === "End") next = items.at(-1);
17028
+ else if (event.key !== "Enter" && event.key !== " " || items[index] !== owned.get(menu)) return;
17029
+ event.preventDefault();
17030
+ event.stopImmediatePropagation();
17031
+ if (next) next.focus();
17032
+ else items[index].click();
17033
+ };
17034
+ window.addEventListener("keydown", onKeyDown, true);
17035
+ const observer = new MutationObserver(update);
17036
+ observer.observe(document.body, {
17037
+ childList: true,
17038
+ subtree: true
17039
+ });
17040
+ update();
17041
+ return () => {
17042
+ stopped = true;
17043
+ request++;
17044
+ observer.disconnect();
17045
+ stopCategory();
17046
+ category?.off("contextMenuOpen", addMenu);
17047
+ window.removeEventListener("keydown", onKeyDown, true);
17048
+ for (const [menu, button] of owned) remove(menu, button);
17049
+ unmountContainer(modal);
17050
+ modal.remove();
17051
+ };
17052
+ }
16940
17053
  // src/common/dashboard-views.ts
16941
17054
  var DASHBOARD_VIEWS_SYNC = "freelens-power:dashboard-views:sync";
16942
17055
  var DASHBOARD_VIEWS_RELOAD = "freelens-power:dashboard-views:reload";
@@ -21103,7 +21216,7 @@ function startExtensionUpdateNotifications() {
21103
21216
  };
21104
21217
  const started = () => {
21105
21218
  attempt = {
21106
- version: current?.installedVersion ?? "2.21.1",
21219
+ version: current?.installedVersion ?? "2.21.3",
21107
21220
  startedAt: Date.now()
21108
21221
  };
21109
21222
  try {
@@ -44258,6 +44371,7 @@ var FreelensPowerRenderer = class extends Renderer$1.LensExtension {
44258
44371
  startExtensionUpdateNotifications,
44259
44372
  startAppearanceOverride,
44260
44373
  startClusterIconOverlay,
44374
+ startClusterIconSettingsMenu,
44261
44375
  startCatalogMenuIcons,
44262
44376
  startCatalogDisconnect,
44263
44377
  startWelcomeOverride,