@64mb/freelens-power 2.21.5 → 2.21.7

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
@@ -7319,6 +7319,7 @@ var PowerPreferencesStore = class extends Common.Store.ExtensionStore {
7319
7319
  checkUpdates = true;
7320
7320
  nodeBulkActions = true;
7321
7321
  hotbarShortcuts = true;
7322
+ hotbarItemShortcuts = true;
7322
7323
  constructor() {
7323
7324
  super({
7324
7325
  configName: "power-preferences",
@@ -7326,14 +7327,16 @@ var PowerPreferencesStore = class extends Common.Store.ExtensionStore {
7326
7327
  enabled: true,
7327
7328
  checkUpdates: true,
7328
7329
  nodeBulkActions: true,
7329
- hotbarShortcuts: true
7330
+ hotbarShortcuts: true,
7331
+ hotbarItemShortcuts: true
7330
7332
  }
7331
7333
  });
7332
7334
  makeObservable(this, {
7333
7335
  enabled: observable,
7334
7336
  checkUpdates: observable,
7335
7337
  nodeBulkActions: observable,
7336
- hotbarShortcuts: observable
7338
+ hotbarShortcuts: observable,
7339
+ hotbarItemShortcuts: observable
7337
7340
  });
7338
7341
  }
7339
7342
  fromStore(data) {
@@ -7341,13 +7344,15 @@ var PowerPreferencesStore = class extends Common.Store.ExtensionStore {
7341
7344
  this.checkUpdates = data.checkUpdates !== false;
7342
7345
  this.nodeBulkActions = data.nodeBulkActions !== false;
7343
7346
  this.hotbarShortcuts = data.hotbarShortcuts !== false;
7347
+ this.hotbarItemShortcuts = data.hotbarItemShortcuts !== false;
7344
7348
  }
7345
7349
  toJSON() {
7346
7350
  return {
7347
7351
  enabled: this.enabled,
7348
7352
  checkUpdates: this.checkUpdates,
7349
7353
  nodeBulkActions: this.nodeBulkActions,
7350
- hotbarShortcuts: this.hotbarShortcuts
7354
+ hotbarShortcuts: this.hotbarShortcuts,
7355
+ hotbarItemShortcuts: this.hotbarItemShortcuts
7351
7356
  };
7352
7357
  }
7353
7358
  };
@@ -16251,7 +16256,7 @@ function startClusterIconOverlay() {
16251
16256
  const owned = /* @__PURE__ */ new Map();
16252
16257
  const webLinkAvatars = /* @__PURE__ */ new Set();
16253
16258
  const style = document.createElement("style");
16254
- style.textContent = `[data-power-cluster-icon]{position:relative!important;color:transparent!important;background:transparent!important}[data-power-cluster-icon]>:not([data-power-icon-image]){visibility:hidden!important}[data-power-icon-image]{position:absolute;inset:0;width:100%;height:100%;border-radius:inherit;pointer-events:none;object-fit:cover}[data-power-web-link-avatar]>img{width:16px;height:16px;margin:auto;object-fit:contain}`;
16259
+ style.textContent = `[data-power-cluster-icon]{position:relative!important;color:transparent!important;background:transparent!important}[data-power-cluster-icon]>:not([data-power-icon-image]):not([data-power-hotbar-number]){visibility:hidden!important}[data-power-icon-image]{position:absolute;inset:0;width:100%;height:100%;border-radius:inherit;pointer-events:none;object-fit:cover}[data-power-web-link-avatar]>img{width:16px;height:16px;margin:auto;object-fit:contain}`;
16255
16260
  document.head.append(style);
16256
16261
  let stopped = false;
16257
16262
  const update = () => {
@@ -21241,7 +21246,7 @@ function startExtensionUpdateNotifications() {
21241
21246
  };
21242
21247
  const started = () => {
21243
21248
  attempt = {
21244
- version: current?.installedVersion ?? "2.21.5",
21249
+ version: current?.installedVersion ?? "2.21.7",
21245
21250
  startedAt: Date.now()
21246
21251
  };
21247
21252
  try {
@@ -26731,6 +26736,53 @@ function startHostPreferencesStyles() {
26731
26736
  style.remove();
26732
26737
  };
26733
26738
  }
26739
+ // src/renderer/hotbar-frame-shortcuts.ts
26740
+ var channel = "freelens-power:hotbar-shortcut";
26741
+ function rendererOrigin(value, cluster = false) {
26742
+ try {
26743
+ const url = new URL(value);
26744
+ if (url.protocol === "https:" && !url.username && !url.password && (cluster ? /^[a-z0-9-]+\.renderer\.freelens\.app$/.test(url.hostname) : /^(?:[a-z0-9-]+\.)?renderer\.freelens\.app$/.test(url.hostname))) return url.origin;
26745
+ } catch {}
26746
+ }
26747
+ function isShortcut(value) {
26748
+ if (!value || typeof value !== "object") return false;
26749
+ const data = value;
26750
+ return Object.keys(data).length === 4 && data.channel === channel && typeof data.code === "string" && /^Digit[0-9]$/.test(data.code) && typeof data.metaKey === "boolean" && typeof data.ctrlKey === "boolean" && !(data.metaKey && data.ctrlKey) && !(data.code === "Digit0" && (data.metaKey || data.ctrlKey));
26751
+ }
26752
+ function startHotbarFrameShortcuts(onShortcut, context = window) {
26753
+ if (context.parent !== context) return () => {};
26754
+ const listener = (event) => {
26755
+ if (!isShortcut(event.data) || !rendererOrigin(event.origin, true)) return;
26756
+ const frame = Array.from(context.document.querySelectorAll("#lens-views > iframe[id^=\"cluster-frame-\"]")).find((candidate) => candidate.contentWindow === event.source);
26757
+ if (!frame || context.document.activeElement !== frame || rendererOrigin(frame.src, true) !== event.origin) return;
26758
+ for (let node = frame; node; node = node.parentElement) {
26759
+ const style = context.getComputedStyle(node);
26760
+ if (node.hidden || node.classList.contains("hidden") || style.display === "none" || style.visibility === "hidden") return;
26761
+ }
26762
+ const { code, metaKey, ctrlKey } = event.data;
26763
+ onShortcut({
26764
+ code,
26765
+ metaKey,
26766
+ ctrlKey
26767
+ });
26768
+ };
26769
+ context.addEventListener("message", listener);
26770
+ return () => context.removeEventListener("message", listener);
26771
+ }
26772
+ function forwardHotbarShortcut(event, context = window) {
26773
+ if (context.parent === context || !rendererOrigin(context.location.origin, true) || event.defaultPrevented || event.repeat || event.isComposing || event.altKey || event.shiftKey) return false;
26774
+ const data = {
26775
+ channel,
26776
+ code: event.code,
26777
+ metaKey: event.metaKey,
26778
+ ctrlKey: event.ctrlKey
26779
+ };
26780
+ if (!isShortcut(data)) return false;
26781
+ const parentOrigin = rendererOrigin(context.document.referrer || context.location.ancestorOrigins?.[0] || "");
26782
+ if (!parentOrigin) return false;
26783
+ context.parent.postMessage(data, parentOrigin);
26784
+ return true;
26785
+ }
26734
26786
  // src/renderer/hotbar-name.tsx
26735
26787
  function startHotbarName() {
26736
26788
  const preferences = PowerPreferencesStore.getInstanceOrCreate();
@@ -26738,9 +26790,12 @@ function startHotbarName() {
26738
26790
  let count = 0;
26739
26791
  let stopped = false;
26740
26792
  let refreshing = false;
26793
+ const seenSearches = /* @__PURE__ */ new WeakSet();
26794
+ const numbers = /* @__PURE__ */ new Map();
26741
26795
  const owned = /* @__PURE__ */ new Map();
26742
26796
  const style = document.createElement("style");
26743
26797
  style.textContent = `[data-power-hotbar-name]{position:relative;z-index:1;flex-shrink:0;width:100%;min-width:0;padding:6px;box-sizing:border-box;text-align:center;color:var(--settingsColor);font-size:10px;line-height:16px}[data-power-hotbar-name] span{display:block;padding:1px 4px;border:1px solid var(--borderColor);border-radius:4px;background:var(--secondaryBackground);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}`;
26798
+ style.textContent += "[data-power-hotbar-numbered]{position:relative}[data-power-hotbar-number]{position:absolute;left:100%;top:2px;transform:translateX(-50%);z-index:3;display:flex;align-items:center;justify-content:center;width:14px;height:14px;padding:0;box-sizing:border-box;border:1px solid var(--borderColor);border-radius:3px;background:var(--mainBackground);color:var(--textColorAccent);font:500 9px/1 system-ui;font-variant-numeric:tabular-nums;pointer-events:none}";
26744
26799
  document.head.append(style);
26745
26800
  const remove = (selector) => {
26746
26801
  const entry = owned.get(selector);
@@ -26750,6 +26805,37 @@ function startHotbarName() {
26750
26805
  owned.delete(selector);
26751
26806
  };
26752
26807
  const update = () => {
26808
+ for (const input of document.querySelectorAll("[data-testid^=\"catalog-list-for-\"] > .header .SearchInput input")) {
26809
+ if (seenSearches.has(input)) continue;
26810
+ seenSearches.add(input);
26811
+ if ((preferences.hotbarShortcuts !== false || preferences.hotbarItemShortcuts !== false) && document.activeElement === input) input.blur();
26812
+ }
26813
+ const allIcons = Array.from(document.querySelectorAll(".HotbarMenu [id^=\"hotbarIcon-\"]"));
26814
+ const icons = preferences.hotbarItemShortcuts !== false ? [...allIcons.slice(0, 9), ...allIcons.length > 9 ? [allIcons[allIcons.length - 1]] : []] : [];
26815
+ for (const [icon, badge] of numbers) {
26816
+ if (icons.includes(icon)) continue;
26817
+ badge.parentElement?.removeAttribute("data-power-hotbar-numbered");
26818
+ badge.remove();
26819
+ icon.removeAttribute("data-power-hotbar-numbered");
26820
+ numbers.delete(icon);
26821
+ }
26822
+ icons.forEach((icon, index) => {
26823
+ let badge = numbers.get(icon);
26824
+ if (!badge) {
26825
+ badge = document.createElement("span");
26826
+ badge.setAttribute("data-power-hotbar-number", "");
26827
+ badge.setAttribute("aria-hidden", "true");
26828
+ numbers.set(icon, badge);
26829
+ }
26830
+ const label = index === 9 ? "0" : String(index + 1);
26831
+ if (badge.textContent !== label) badge.textContent = label;
26832
+ const wrapper = icon.parentElement?.matches("[class*=\"HotbarIcon\"]") ? icon.parentElement : icon;
26833
+ wrapper.setAttribute("data-power-hotbar-numbered", "");
26834
+ if (badge.parentElement !== wrapper) wrapper.append(badge);
26835
+ const markerBounds = wrapper.querySelector(":scope > .Icon[class*=\"badge\"]")?.getBoundingClientRect();
26836
+ const left = markerBounds?.width ? `${markerBounds.left + markerBounds.width / 2 - wrapper.getBoundingClientRect().left}px` : "100%";
26837
+ if (badge.style.left !== left) badge.style.left = left;
26838
+ });
26753
26839
  const targets = /* @__PURE__ */ new Set();
26754
26840
  for (const badge of count > 1 ? document.querySelectorAll(`.HotbarMenu [data-testid^="${prefix}"]`) : []) {
26755
26841
  const selector = badge.closest("[class*=\"HotbarSelector\"]");
@@ -26798,19 +26884,39 @@ function startHotbarName() {
26798
26884
  childList: true,
26799
26885
  subtree: true,
26800
26886
  attributes: true,
26801
- attributeFilter: ["data-testid"]
26887
+ attributeFilter: [
26888
+ "data-testid",
26889
+ "id",
26890
+ "class"
26891
+ ]
26802
26892
  });
26803
26893
  refreshCount();
26804
26894
  const keydown = (event) => {
26805
- if (preferences.hotbarShortcuts === false) return;
26806
26895
  const mac = /Mac|iPhone|iPad/.test(navigator.platform);
26807
- if (event.defaultPrevented || event.repeat || event.isComposing || event.altKey || event.shiftKey || (mac ? !event.metaKey || event.ctrlKey : !event.ctrlKey || event.metaKey)) return;
26808
- const digit = /^Digit([1-9])$/.exec(event.code);
26809
- if (!digit) return;
26896
+ const itemShortcut = !event.metaKey && !event.ctrlKey;
26897
+ if ((itemShortcut ? preferences.hotbarItemShortcuts : preferences.hotbarShortcuts) === false) return;
26898
+ if (event.defaultPrevented || event.repeat || event.isComposing || event.altKey || event.shiftKey || !itemShortcut && (mac ? !event.metaKey || event.ctrlKey : !event.ctrlKey || event.metaKey)) return;
26899
+ const digit = /^Digit([0-9])$/.exec(event.code);
26900
+ if (!digit || !itemShortcut && digit[1] === "0") return;
26810
26901
  const editable = "input, textarea, select, [contenteditable]:not([contenteditable=\"false\"]), [role=\"textbox\"], [role=\"combobox\"], .monaco-editor, .xterm, .cm-editor, .CodeMirror";
26811
- if (!(event.target instanceof HTMLInputElement && event.target.matches("[data-testid^=\"catalog-list-for-\"] > .header .SearchInput input")) && event.composedPath().some((node) => node instanceof Element && node.closest(editable))) return;
26902
+ if (event.composedPath().some((node) => node instanceof Element && node.closest(editable))) return;
26812
26903
  if (document.querySelector(".Dialog.modal, [aria-modal=\"true\"], .SettingLayout, [class*=\"command-container-module__CommandContainer--\"]")) return;
26904
+ if (itemShortcut && document.querySelector(".Menu.portal, .HotbarMenu .isDragging")) return;
26905
+ if (forwardHotbarShortcut(event)) {
26906
+ event.preventDefault();
26907
+ event.stopPropagation();
26908
+ return;
26909
+ }
26813
26910
  const target = Number(digit[1]);
26911
+ if (itemShortcut) {
26912
+ const icons = document.querySelectorAll(".HotbarMenu [id^=\"hotbarIcon-\"]");
26913
+ const icon = icons[target === 0 ? icons.length - 1 : target - 1];
26914
+ if (!icon || icon.matches("[aria-disabled=\"true\"], [disabled], [class*=\"disabled\"]")) return;
26915
+ event.preventDefault();
26916
+ event.stopPropagation();
26917
+ icon.click();
26918
+ return;
26919
+ }
26814
26920
  const badge = document.querySelector(".HotbarMenu [data-testid^=\"hotbar-menu-badge-for-\"]");
26815
26921
  const current = Number(badge?.textContent?.trim());
26816
26922
  const arrows = (badge?.closest("[class*=\"HotbarSelector\"]"))?.querySelectorAll(":scope > .Icon");
@@ -26820,12 +26926,28 @@ function startHotbarName() {
26820
26926
  const arrow = arrows[target > current ? 1 : 0];
26821
26927
  for (let step = 0; step < Math.abs(target - current); step++) arrow.click();
26822
26928
  };
26929
+ const stopFrameShortcuts = startHotbarFrameShortcuts((shortcut) => {
26930
+ document.dispatchEvent(new KeyboardEvent("keydown", {
26931
+ ...shortcut,
26932
+ bubbles: true,
26933
+ cancelable: true
26934
+ }));
26935
+ });
26823
26936
  document.addEventListener("keydown", keydown);
26937
+ const stopItemPreference = reaction(() => preferences.hotbarItemShortcuts, update, { fireImmediately: true });
26824
26938
  const timer = setInterval(() => void refreshCount(), 2e3);
26825
26939
  return () => {
26826
26940
  stopped = true;
26827
26941
  document.removeEventListener("keydown", keydown);
26942
+ stopFrameShortcuts();
26828
26943
  clearInterval(timer);
26944
+ stopItemPreference();
26945
+ for (const [icon, badge] of numbers) {
26946
+ badge.parentElement?.removeAttribute("data-power-hotbar-numbered");
26947
+ badge.remove();
26948
+ icon.removeAttribute("data-power-hotbar-numbered");
26949
+ }
26950
+ numbers.clear();
26829
26951
  observer.disconnect();
26830
26952
  for (const selector of owned.keys()) remove(selector);
26831
26953
  style.remove();
@@ -26834,6 +26956,23 @@ function startHotbarName() {
26834
26956
  // src/common/kubeconfig-editor.ts
26835
26957
  var KUBECONFIG_EDITOR_CHANNEL = "freelens-power:kubeconfig-editor";
26836
26958
  // src/renderer/kubeconfig-editor.tsx
26959
+ function actionLabel(label, material) {
26960
+ return /* @__PURE__ */ jsxs("span", {
26961
+ style: {
26962
+ display: "inline-flex",
26963
+ alignItems: "center",
26964
+ gap: 6
26965
+ },
26966
+ children: [/* @__PURE__ */ jsx$1("span", {
26967
+ "aria-hidden": "true",
26968
+ style: { display: "inline-flex" },
26969
+ children: /* @__PURE__ */ jsx$1(Renderer$1.Component.Icon, {
26970
+ material,
26971
+ size: 16
26972
+ })
26973
+ }), label]
26974
+ });
26975
+ }
26837
26976
  var KubeconfigEditor = observer(function KubeconfigEditor({ clusterId, onClose }) {
26838
26977
  const [snapshot, setSnapshot] = useState();
26839
26978
  const [text, setText] = useState("");
@@ -26949,7 +27088,7 @@ var KubeconfigEditor = observer(function KubeconfigEditor({ clusterId, onClose }
26949
27088
  marginTop: 16
26950
27089
  },
26951
27090
  children: [/* @__PURE__ */ jsx$1(Renderer$1.Component.Button, {
26952
- label: "Reload",
27091
+ label: actionLabel("Reload", "refresh"),
26953
27092
  disabled: busy,
26954
27093
  onClick: () => {
26955
27094
  if (dirty) {
@@ -26972,12 +27111,12 @@ var KubeconfigEditor = observer(function KubeconfigEditor({ clusterId, onClose }
26972
27111
  }
26973
27112
  }),
26974
27113
  /* @__PURE__ */ jsx$1(Renderer$1.Component.Button, {
26975
- label: discard ? "Keep editing" : "Close",
27114
+ label: actionLabel(discard ? "Keep editing" : "Close", discard ? "edit" : "close"),
26976
27115
  disabled: busy,
26977
27116
  onClick: close
26978
27117
  }),
26979
27118
  /* @__PURE__ */ jsx$1(Renderer$1.Component.Button, {
26980
- label: "Save",
27119
+ label: actionLabel("Save", "save"),
26981
27120
  primary: true,
26982
27121
  disabled: busy || !!readOnly || !dirty,
26983
27122
  onClick: () => void save()
@@ -41300,6 +41439,16 @@ var OtherPreferences = observer(() => {
41300
41439
  className: "power-settings-hint",
41301
41440
  children: "Switch panels with Cmd+1-9 on macOS or Ctrl+1-9 on Windows and Linux."
41302
41441
  })] }),
41442
+ /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx$1(Renderer$1.Component.Switch, {
41443
+ checked: preferences.hotbarItemShortcuts,
41444
+ onChange: (value) => {
41445
+ preferences.hotbarItemShortcuts = value;
41446
+ },
41447
+ children: "Hotbar item shortcuts"
41448
+ }), /* @__PURE__ */ jsx$1("div", {
41449
+ className: "power-settings-hint",
41450
+ children: "Show number badges and open hotbar items with 1-9 or the last item with 0 outside input fields."
41451
+ })] }),
41303
41452
  /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx$1(Renderer$1.Component.Switch, {
41304
41453
  checked: monitoring.resourceSearchEnabled,
41305
41454
  onChange: (value) => {