impact-nova 1.7.9 → 1.7.11

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.
@@ -1,91 +1,112 @@
1
- import { jsxs as O, Fragment as L, jsx as p } from "react/jsx-runtime";
2
- import * as d from "react";
3
- import { createPortal as M } from "react-dom";
1
+ import { jsxs as x, Fragment as L, jsx as v } from "react/jsx-runtime";
2
+ import * as h from "react";
3
+ import { createPortal as O } from "react-dom";
4
4
  import { useShortcutOverlay as S } from "./shortcut-overlay-context.js";
5
- import { useCommandPalette as C } from "./command-palette-context.js";
6
- import { Kbd as X } from "./kbd.js";
7
- const u = 26, h = 80, s = 4;
8
- function z() {
9
- const t = document.querySelectorAll(
10
- '[role="dialog"][data-state="open"]'
5
+ import { useCommandPalette as M } from "./command-palette-context.js";
6
+ import { Kbd as T } from "./kbd.js";
7
+ const u = 26, y = 80, s = 4;
8
+ function X() {
9
+ const o = document.querySelectorAll(
10
+ '[role="dialog"][data-state="open"], [role="alertdialog"][data-state="open"], [data-component="sheet-content"][data-state="open"]'
11
11
  );
12
- return t.length > 0 ? t[t.length - 1] : null;
12
+ return o.length === 0 ? null : o[o.length - 1];
13
13
  }
14
- function F(t) {
15
- if (t.length <= 1) return t;
16
- const r = [...t].sort((n, e) => n.top - e.top), l = (n, e) => Math.abs(n.left - e.left) < h && Math.abs(n.top - e.top) < u + s;
17
- for (let n = 1; n < r.length; n++) {
18
- const e = r[n], c = () => r.slice(Math.max(0, n - 5), n).some((y) => l(y, e));
19
- c() && (e.placement === "above" ? (e.placement = "below", e.top = e.top + u + 32 + s) : (e.placement = "above", e.top = e.top - u - 32 - s), c() && (e.left = e.left + h + s));
14
+ function z(o) {
15
+ if (o.length <= 1) return o;
16
+ const a = [...o].sort((e, t) => e.top - t.top || e.left - t.left), f = (e, t) => Math.abs(e.left - t.left) < y && Math.abs(e.top - t.top) < u + s, c = (e) => a.slice(0, e).some((t) => f(t, a[e]));
17
+ for (let e = 1; e < a.length; e++) {
18
+ if (!c(e)) continue;
19
+ const t = a[e], d = t.top, m = t.left, n = t.placement;
20
+ if (t.placement === "above" ? (t.placement = "below", t.top = d + u + 32 + s) : (t.placement = "above", t.top = d - u - 32 - s), !c(e)) continue;
21
+ t.placement = n, t.left = m;
22
+ let i = !1;
23
+ for (let r = 1; r <= 6; r++)
24
+ if (t.top = d + (u + s) * r, !c(e)) {
25
+ i = !0;
26
+ break;
27
+ }
28
+ if (!i) {
29
+ t.top = d;
30
+ for (let r = 1; r <= 4; r++)
31
+ if (t.left = m + (y + s) * r, !c(e)) {
32
+ i = !0;
33
+ break;
34
+ }
35
+ if (!i) {
36
+ t.left = m;
37
+ for (let r = 1; r <= 4 && (t.top = d - (u + s) * r, !!c(e)); r++)
38
+ ;
39
+ }
40
+ }
20
41
  }
21
- return r;
42
+ return a;
22
43
  }
23
- function R(t) {
24
- const r = window.innerWidth, l = window.innerHeight;
44
+ function C(o) {
45
+ const a = window.innerWidth, f = window.innerHeight;
25
46
  return {
26
- ...t,
27
- top: Math.max(s, Math.min(t.top, l - u - s)),
28
- left: Math.max(h / 2, Math.min(t.left, r - h / 2))
47
+ ...o,
48
+ top: Math.max(s, Math.min(o.top, f - u - s)),
49
+ left: Math.max(y / 2, Math.min(o.left, a - y / 2))
29
50
  };
30
51
  }
31
- function T() {
32
- const { isOverlayVisible: t, setOverlayVisible: r } = S(), { getEffectiveKeybinding: l, version: n } = C(), [e, c] = d.useState([]), [y, x] = d.useState(0);
33
- return d.useLayoutEffect(() => {
34
- if (!t) {
35
- c([]);
52
+ function D() {
53
+ const { isOverlayVisible: o, setOverlayVisible: a } = S(), { getEffectiveKeybinding: f, version: c } = M(), [e, t] = h.useState([]), [d, m] = h.useState(0);
54
+ return h.useLayoutEffect(() => {
55
+ if (!o) {
56
+ t([]);
36
57
  return;
37
58
  }
38
- const f = (z() ?? document).querySelectorAll("[data-shortcut-id]"), m = [];
39
- f.forEach((v) => {
40
- const w = v.getAttribute("data-shortcut-id");
41
- if (!w) return;
42
- const b = window.getComputedStyle(v);
59
+ const n = X(), i = document.querySelectorAll("[data-shortcut-id]"), r = [];
60
+ i.forEach((p) => {
61
+ const w = p.getAttribute("data-shortcut-id");
62
+ if (!w || n && !n.contains(p)) return;
63
+ const b = window.getComputedStyle(p);
43
64
  if (b.display === "none" || b.visibility === "hidden" || b.opacity === "0")
44
65
  return;
45
- const a = v.getBoundingClientRect();
46
- if (a.width === 0 || a.height === 0 || a.bottom < 0 || a.top > window.innerHeight || a.right < 0 || a.left > window.innerWidth)
66
+ const l = p.getBoundingClientRect();
67
+ if (l.width === 0 || l.height === 0 || l.bottom < 0 || l.top > window.innerHeight || l.right < 0 || l.left > window.innerWidth)
47
68
  return;
48
- const E = l(w);
49
- if (!E) return;
50
- const A = a.left + a.width / 2;
51
- let k = "above", g = a.top - u - s;
52
- g < s && (k = "below", g = a.bottom + s), m.push({
69
+ const k = f(w);
70
+ if (!k) return;
71
+ const A = l.left + l.width / 2;
72
+ let E = "above", g = l.top - u - s;
73
+ g < s && (E = "below", g = l.bottom + s), r.push({
53
74
  id: w,
54
- keybinding: E,
75
+ keybinding: k,
55
76
  top: g,
56
77
  left: A,
57
- placement: k
78
+ placement: E
58
79
  });
59
- }), c(F(m).map(R));
60
- }, [t, l, n, y]), d.useEffect(() => {
61
- if (!t) return;
62
- const o = (i) => {
63
- i.key === "Escape" && (i.preventDefault(), i.stopPropagation(), r(!1));
80
+ }), t(z(r).map(C));
81
+ }, [o, f, c, d]), h.useEffect(() => {
82
+ if (!o) return;
83
+ const n = (i) => {
84
+ i.key === "Escape" && (i.preventDefault(), i.stopPropagation(), a(!1));
64
85
  };
65
- return window.addEventListener("keydown", o, !0), () => window.removeEventListener("keydown", o, !0);
66
- }, [t, r]), d.useEffect(() => {
67
- if (!t) return;
68
- let o;
86
+ return window.addEventListener("keydown", n, !0), () => window.removeEventListener("keydown", n, !0);
87
+ }, [o, a]), h.useEffect(() => {
88
+ if (!o) return;
89
+ let n;
69
90
  const i = () => {
70
- cancelAnimationFrame(o), o = requestAnimationFrame(() => x((m) => m + 1));
91
+ cancelAnimationFrame(n), n = requestAnimationFrame(() => m((p) => p + 1));
71
92
  };
72
93
  window.addEventListener("scroll", i, !0), window.addEventListener("resize", i);
73
- const f = new MutationObserver(i);
74
- return f.observe(document.body, {
94
+ const r = new MutationObserver(i);
95
+ return r.observe(document.body, {
75
96
  childList: !0,
76
97
  subtree: !0,
77
98
  attributes: !0,
78
99
  attributeFilter: ["data-state"]
79
100
  }), () => {
80
- cancelAnimationFrame(o), window.removeEventListener("scroll", i, !0), window.removeEventListener("resize", i), f.disconnect();
101
+ cancelAnimationFrame(n), window.removeEventListener("scroll", i, !0), window.removeEventListener("resize", i), r.disconnect();
81
102
  };
82
- }, [t]), !t || e.length === 0 ? null : M(
83
- /* @__PURE__ */ O(L, { children: [
84
- /* @__PURE__ */ p(
103
+ }, [o]), !o || e.length === 0 ? null : O(
104
+ /* @__PURE__ */ x(L, { children: [
105
+ /* @__PURE__ */ v(
85
106
  "div",
86
107
  {
87
108
  "data-shortcut-overlay-backdrop": "",
88
- onClick: () => r(!1),
109
+ onClick: () => a(!1),
89
110
  style: {
90
111
  position: "fixed",
91
112
  inset: 0,
@@ -95,31 +116,31 @@ function T() {
95
116
  }
96
117
  }
97
118
  ),
98
- e.map((o) => /* @__PURE__ */ p(
119
+ e.map((n) => /* @__PURE__ */ v(
99
120
  "div",
100
121
  {
101
122
  "data-shortcut-overlay-badge": "",
102
123
  style: {
103
124
  position: "fixed",
104
- top: o.top,
105
- left: o.left,
125
+ top: n.top,
126
+ left: n.left,
106
127
  transform: "translateX(-50%)",
107
128
  zIndex: 99999,
108
129
  pointerEvents: "none",
109
- animation: o.placement === "below" ? "shortcut-overlay-badge-in-below 0.15s ease-out" : "shortcut-overlay-badge-in 0.15s ease-out"
130
+ animation: n.placement === "below" ? "shortcut-overlay-badge-in-below 0.15s ease-out" : "shortcut-overlay-badge-in 0.15s ease-out"
110
131
  },
111
- children: /* @__PURE__ */ p(
112
- X,
132
+ children: /* @__PURE__ */ v(
133
+ T,
113
134
  {
114
- keybinding: o.keybinding,
135
+ keybinding: n.keybinding,
115
136
  size: "sm",
116
137
  variant: "dark"
117
138
  }
118
139
  )
119
140
  },
120
- o.id
141
+ n.id
121
142
  )),
122
- /* @__PURE__ */ p("style", { children: `
143
+ /* @__PURE__ */ v("style", { children: `
123
144
  @keyframes shortcut-overlay-badge-in {
124
145
  from {
125
146
  opacity: 0;
@@ -145,7 +166,7 @@ function T() {
145
166
  document.body
146
167
  );
147
168
  }
148
- T.displayName = "ShortcutOverlay";
169
+ D.displayName = "ShortcutOverlay";
149
170
  export {
150
- T as ShortcutOverlay
171
+ D as ShortcutOverlay
151
172
  };
@@ -1,4 +1,4 @@
1
- import { deserialiseOverrides as h, serialiseOverrides as f, isReservedShortcut as u, keybindingsEqual as m, scopePriority as a, matchesKeybinding as g } from "./utils.js";
1
+ import { deserialiseOverrides as h, serialiseOverrides as u, isReservedShortcut as f, keybindingsEqual as m, scopePriority as a, matchesKeybinding as g } from "./utils.js";
2
2
  const v = 10;
3
3
  class c {
4
4
  static STORAGE_KEY = "impact-nova-shortcuts";
@@ -15,7 +15,7 @@ class c {
15
15
  saveOverrides(e) {
16
16
  if (!(typeof localStorage > "u"))
17
17
  try {
18
- localStorage.setItem(c.STORAGE_KEY, f(e));
18
+ localStorage.setItem(c.STORAGE_KEY, u(e));
19
19
  } catch {
20
20
  }
21
21
  }
@@ -86,7 +86,7 @@ class C {
86
86
  const s = this.commands.get(e);
87
87
  if (!s) return { success: !1 };
88
88
  if (!s.customisable) return { success: !1 };
89
- if (u(t))
89
+ if (f(t))
90
90
  return { success: !1, reserved: !0 };
91
91
  const i = this.findConflict(e, t, s.scope);
92
92
  return i ? { success: !1, conflict: i } : (s.keybinding = t, this.overrides.set(e, t), this.saveOverrides(), this.emit({ type: "update-keybinding", commandId: e }), { success: !0 });
@@ -147,7 +147,7 @@ class C {
147
147
  getPaletteCommands() {
148
148
  const t = this.getRegisteredInstances().length > 1;
149
149
  return this.getAllCommands().filter((s) => {
150
- if (s.hidden || s.when && !s.when()) return !1;
150
+ if (s.hidden) return !1;
151
151
  const i = this.getHighestActiveScopePriority();
152
152
  return !(a(s.scope) > i || s.instance && t && this.activeInstance && s.instance !== this.activeInstance);
153
153
  });