tgui-core 1.1.23 → 1.2.0

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,26 +1,26 @@
1
- import '../assets/NumberInput.css';var w = Object.defineProperty;
2
- var E = (c, d, e) => d in c ? w(c, d, { enumerable: !0, configurable: !0, writable: !0, value: e }) : c[d] = e;
3
- var l = (c, d, e) => E(c, typeof d != "symbol" ? d + "" : d, e);
4
- import { jsxs as _, jsx as g } from "react/jsx-runtime";
5
- import { Component as I, createRef as D } from "react";
6
- import { KEY as S } from "../common/keys.js";
7
- import { clamp as h } from "../common/math.js";
8
- import { classes as T } from "../common/react.js";
9
- import { AnimatedNumber as F } from "./AnimatedNumber.js";
10
- import { Box as M } from "./Box.js";
11
- const R = "_numberInput_4xyrw_20", B = "_fluid_4xyrw_36", K = "_content_4xyrw_40", L = "_barContainer_4xyrw_44", Y = "_bar_4xyrw_44", j = "_inner_4xyrw_61", p = {
12
- numberInput: R,
13
- fluid: B,
14
- content: K,
15
- barContainer: L,
16
- bar: Y,
17
- inner: j
1
+ import '../assets/NumberInput.css';var N = Object.defineProperty;
2
+ var w = (c, d, e) => d in c ? N(c, d, { enumerable: !0, configurable: !0, writable: !0, value: e }) : c[d] = e;
3
+ var l = (c, d, e) => w(c, typeof d != "symbol" ? d + "" : d, e);
4
+ import { jsxs as _, jsx as V } from "react/jsx-runtime";
5
+ import { Component as E, createRef as I } from "react";
6
+ import { KEY as D, isEscape as M } from "../common/keys.js";
7
+ import { clamp as g, round as T } from "../common/math.js";
8
+ import { classes as F } from "../common/react.js";
9
+ import { AnimatedNumber as R } from "./AnimatedNumber.js";
10
+ import { Box as Y } from "./Box.js";
11
+ const B = "_numberInput_4xyrw_20", K = "_fluid_4xyrw_36", L = "_content_4xyrw_40", z = "_barContainer_4xyrw_44", j = "_bar_4xyrw_44", k = "_inner_4xyrw_61", p = {
12
+ numberInput: B,
13
+ fluid: K,
14
+ content: L,
15
+ barContainer: z,
16
+ bar: j,
17
+ inner: k
18
18
  };
19
- class $ extends I {
19
+ class J extends E {
20
20
  constructor(e) {
21
21
  super(e);
22
22
  // Ref to the input field to set focus & highlight
23
- l(this, "inputRef", D());
23
+ l(this, "inputRef", I());
24
24
  // After this time has elapsed we are in drag mode so no editing when dragging ends
25
25
  l(this, "dragTimeout");
26
26
  // Call onDrag at this interval
@@ -34,74 +34,74 @@ class $ extends I {
34
34
  origin: 0
35
35
  });
36
36
  l(this, "handleDragStart", (e) => {
37
- const { value: a, disabled: u } = this.props, { editing: n } = this.state;
38
- if (u || n)
37
+ const { value: o, disabled: a } = this.props, { editing: s } = this.state;
38
+ if (a || s)
39
39
  return;
40
40
  document.body.style["pointer-events"] = "none";
41
- const i = parseFloat(a.toString());
41
+ const r = parseFloat(o.toString());
42
42
  this.setState({
43
43
  dragging: !1,
44
44
  origin: e.screenY,
45
- currentValue: i,
46
- previousValue: i
45
+ currentValue: r,
46
+ previousValue: r
47
47
  }), this.dragTimeout = setTimeout(() => {
48
48
  this.setState({
49
49
  dragging: !0
50
50
  });
51
51
  }, 250), this.dragInterval = setInterval(() => {
52
- const { dragging: o, currentValue: s, previousValue: t } = this.state, { onDrag: r } = this.props;
53
- o && s !== t && (this.setState({
54
- previousValue: s
55
- }), r == null || r(s));
52
+ const { dragging: u, currentValue: i, previousValue: t } = this.state, { onDrag: n } = this.props;
53
+ u && i !== t && (this.setState({
54
+ previousValue: i
55
+ }), n == null || n(i));
56
56
  }, 400), document.addEventListener("mousemove", this.handleDragMove), document.addEventListener("mouseup", this.handleDragEnd);
57
57
  });
58
58
  l(this, "handleDragMove", (e) => {
59
- const { minValue: a, maxValue: u, step: n, stepPixelSize: i, disabled: o } = this.props;
60
- o || this.setState((s) => {
61
- const t = { ...s }, r = t.origin - e.screenY;
62
- if (s.dragging) {
63
- const f = isFinite(a) ? a % n : 0;
64
- t.currentValue = h(
65
- t.currentValue + r * n / (i || 1),
66
- a - n,
67
- u + n
68
- ), t.currentValue = h(
69
- t.currentValue - t.currentValue % n + f,
70
- a,
71
- u
72
- ), t.origin = e.screenY;
73
- } else Math.abs(r) > 4 && (t.dragging = !0);
59
+ const { minValue: o, maxValue: a, step: s, stepPixelSize: r, disabled: u } = this.props;
60
+ u || this.setState((i) => {
61
+ const t = { ...i }, n = t.origin - e.screenY;
62
+ if (i.dragging) {
63
+ const f = r || 1, m = g(
64
+ t.currentValue + n * s / f,
65
+ o - s,
66
+ a + s
67
+ );
68
+ Math.abs(m - t.currentValue) >= s ? (t.currentValue = g(
69
+ T(m / s, 0) * s,
70
+ o,
71
+ a
72
+ ), t.origin = e.screenY) : Math.abs(n) > f && (t.origin = e.screenY);
73
+ } else Math.abs(n) > 4 && (t.dragging = !0);
74
74
  return t;
75
75
  });
76
76
  });
77
77
  l(this, "handleDragEnd", (e) => {
78
- const { dragging: a, currentValue: u } = this.state, { onDrag: n, onChange: i, disabled: o } = this.props;
79
- if (!o) {
78
+ const { dragging: o, currentValue: a } = this.state, { onDrag: s, onChange: r, disabled: u } = this.props;
79
+ if (!u) {
80
80
  if (document.body.style["pointer-events"] = "auto", clearInterval(this.dragInterval), clearTimeout(this.dragTimeout), this.setState({
81
81
  dragging: !1,
82
- editing: !a,
83
- previousValue: u
84
- }), a)
85
- i == null || i(u), n == null || n(u);
82
+ editing: !o,
83
+ previousValue: a
84
+ }), o)
85
+ r == null || r(a), s == null || s(a);
86
86
  else if (this.inputRef) {
87
- const s = this.inputRef.current;
88
- s && (s.value = `${u}`, setTimeout(() => {
89
- s.focus(), s.select();
90
- }, 1));
87
+ const i = this.inputRef.current;
88
+ i && (i.value = `${a}`, setTimeout(() => {
89
+ i.focus(), i.select();
90
+ }, 10));
91
91
  }
92
92
  document.removeEventListener("mousemove", this.handleDragMove), document.removeEventListener("mouseup", this.handleDragEnd);
93
93
  }
94
94
  });
95
95
  l(this, "handleBlur", (e) => {
96
- const { editing: a, previousValue: u } = this.state, { minValue: n, maxValue: i, onChange: o, onDrag: s, disabled: t } = this.props;
97
- if (t || !a)
96
+ const { editing: o, previousValue: a } = this.state, { minValue: s, maxValue: r, onChange: u, onDrag: i, disabled: t } = this.props;
97
+ if (t || !o)
98
98
  return;
99
- const r = h(
99
+ const n = g(
100
100
  parseFloat(e.target.value),
101
- n,
102
- i
101
+ s,
102
+ r
103
103
  );
104
- if (isNaN(r)) {
104
+ if (isNaN(n)) {
105
105
  this.setState({
106
106
  editing: !1
107
107
  });
@@ -109,20 +109,20 @@ class $ extends I {
109
109
  }
110
110
  this.setState({
111
111
  editing: !1,
112
- currentValue: r,
113
- previousValue: r
114
- }), u !== r && (o == null || o(r), s == null || s(r));
112
+ currentValue: n,
113
+ previousValue: n
114
+ }), a !== n && (u == null || u(n), i == null || i(n));
115
115
  });
116
116
  l(this, "handleKeyDown", (e) => {
117
- const { minValue: a, maxValue: u, onChange: n, onDrag: i, disabled: o } = this.props;
118
- if (o)
117
+ const { minValue: o, maxValue: a, onChange: s, onDrag: r, disabled: u } = this.props;
118
+ if (u)
119
119
  return;
120
- const { previousValue: s } = this.state;
121
- if (e.key === S.Enter) {
122
- const t = h(
120
+ const { previousValue: i } = this.state;
121
+ if (e.key === D.Enter) {
122
+ const t = g(
123
123
  parseFloat(e.currentTarget.value),
124
- a,
125
- u
124
+ o,
125
+ a
126
126
  );
127
127
  if (isNaN(t)) {
128
128
  this.setState({
@@ -134,8 +134,8 @@ class $ extends I {
134
134
  editing: !1,
135
135
  currentValue: t,
136
136
  previousValue: t
137
- }), s !== t && (n == null || n(t), i == null || i(t));
138
- } else e.key === S.Escape && this.setState({
137
+ }), i !== t && (s == null || s(t), r == null || r(t));
138
+ } else M(e.key) && this.setState({
139
139
  editing: !1
140
140
  });
141
141
  });
@@ -148,62 +148,62 @@ class $ extends I {
148
148
  });
149
149
  }
150
150
  render() {
151
- const { dragging: e, editing: a, currentValue: u } = this.state, {
152
- className: n,
153
- fluid: i,
154
- animated: o,
155
- unit: s,
151
+ const { dragging: e, editing: o, currentValue: a } = this.state, {
152
+ className: s,
153
+ fluid: r,
154
+ animated: u,
155
+ unit: i,
156
156
  value: t,
157
- minValue: r,
157
+ minValue: n,
158
158
  maxValue: f,
159
- height: v,
160
- width: x,
159
+ height: m,
160
+ width: S,
161
161
  lineHeight: b,
162
162
  fontSize: y,
163
- format: V
163
+ format: v
164
164
  } = this.props;
165
- let m = parseFloat(t.toString());
166
- e && (m = u);
167
- const N = /* @__PURE__ */ _("div", { className: p.content, children: [
168
- o && !e ? /* @__PURE__ */ g(F, { value: m, format: V }) : V ? V(m) : m,
169
- s ? " " + s : ""
165
+ let h = parseFloat(t.toString());
166
+ e && (h = a);
167
+ const x = /* @__PURE__ */ _("div", { className: p.content, children: [
168
+ u && !e ? /* @__PURE__ */ V(R, { value: h, format: v }) : v ? v(h) : h,
169
+ i ? " " + i : ""
170
170
  ] });
171
171
  return /* @__PURE__ */ _(
172
- M,
172
+ Y,
173
173
  {
174
- className: T([
174
+ className: F([
175
175
  p.numberInput,
176
- i && p.fluid,
177
- n
176
+ r && p.fluid,
177
+ s
178
178
  ]),
179
- minWidth: x,
180
- minHeight: v,
179
+ minWidth: S,
180
+ minHeight: m,
181
181
  lineHeight: b,
182
182
  fontSize: y,
183
183
  onMouseDown: this.handleDragStart,
184
184
  children: [
185
- /* @__PURE__ */ g("div", { className: p.barContainer, children: /* @__PURE__ */ g(
185
+ /* @__PURE__ */ V("div", { className: p.barContainer, children: /* @__PURE__ */ V(
186
186
  "div",
187
187
  {
188
188
  className: p.bar,
189
189
  style: {
190
- height: h(
191
- (m - r) / (f - r) * 100,
190
+ height: g(
191
+ (h - n) / (f - n) * 100,
192
192
  0,
193
193
  100
194
194
  ) + "%"
195
195
  }
196
196
  }
197
197
  ) }),
198
- N,
199
- /* @__PURE__ */ g(
198
+ x,
199
+ /* @__PURE__ */ V(
200
200
  "input",
201
201
  {
202
202
  ref: this.inputRef,
203
203
  className: p.inner,
204
204
  style: {
205
- display: a ? "inline" : "none",
206
- height: v,
205
+ display: o ? "inline" : "none",
206
+ height: m,
207
207
  lineHeight: b,
208
208
  fontSize: y
209
209
  },
@@ -217,5 +217,5 @@ class $ extends I {
217
217
  }
218
218
  }
219
219
  export {
220
- $ as NumberInput
220
+ J as NumberInput
221
221
  };
@@ -1,5 +1,30 @@
1
1
  import { ReactNode } from 'react';
2
+ import { BoxProps } from './Box';
2
3
 
4
+ type Props = Partial<{
5
+ /** Buttons to render aside the section title. */
6
+ buttons: ReactNode;
7
+ /** id to assosiate with the parent div element used by this section, for uses with procs like getElementByID */
8
+ container_id: string;
9
+ /** If true, fills all available vertical space. */
10
+ fill: boolean;
11
+ /** If true, removes all section padding. */
12
+ fitted: boolean;
13
+ /** If true, fills the area without forcing height to 100% */
14
+ flexGrow: boolean;
15
+ /** If true, removes the section top padding */
16
+ noTopPadding: boolean;
17
+ /** @member Callback function for the `scroll` event */
18
+ onScroll: ((this: GlobalEventHandlers, ev: Event) => any) | null;
19
+ /** Shows or hides the scrollbar. */
20
+ scrollable: boolean;
21
+ /** Shows or hides the horizontal scrollbar. */
22
+ scrollableHorizontal: boolean;
23
+ /** If true, filly the area except for -3rem */
24
+ stretchContents: boolean;
25
+ /** Title of the section. */
26
+ title: ReactNode;
27
+ }> & BoxProps;
3
28
  /**
4
29
  * ## Section
5
30
  * Section is a surface that displays content and actions on a single topic.
@@ -27,37 +52,5 @@ import { ReactNode } from 'react';
27
52
  * </Section>
28
53
  * ```
29
54
  */
30
- export declare const Section: import('react').ForwardRefExoticComponent<Partial<{
31
- /** Buttons to render aside the section title. */
32
- buttons: ReactNode;
33
- /** id to assosiate with the parent div element used by this section, for uses with procs like getElementByID */
34
- container_id: string;
35
- /** If true, fills all available vertical space. */
36
- fill: boolean;
37
- /** If true, removes all section padding. */
38
- fitted: boolean;
39
- /** @member Callback function for the `scroll` event */
40
- onScroll: ((this: GlobalEventHandlers, ev: Event) => any) | null;
41
- /** Shows or hides the scrollbar. */
42
- scrollable: boolean;
43
- /** Shows or hides the horizontal scrollbar. */
44
- scrollableHorizontal: boolean;
45
- /** Title of the section. */
46
- title: ReactNode;
47
- }> & Partial<{
48
- as: string;
49
- children: ReactNode;
50
- className: string | import('../common/react').BooleanLike;
51
- style: import('react').CSSProperties;
52
- }> & Partial<Record<"bold" | "italic" | "nowrap" | "fillPositionedParent" | "inline" | "preserveWhitespace", boolean>> & Partial<Record<"fontWeight" | "textAlign" | "bottom" | "fontFamily" | "fontSize" | "height" | "left" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "opacity" | "overflow" | "overflowX" | "overflowY" | "position" | "right" | "top" | "verticalAlign" | "width" | "color" | "backgroundColor" | "align" | "lineHeight" | "m" | "mb" | "ml" | "mr" | "mt" | "mx" | "my" | "p" | "pb" | "pl" | "pr" | "pt" | "px" | "py" | "textColor", string | import('../common/react').BooleanLike>> & Partial<{
53
- onClick: import('react').MouseEventHandler<HTMLDivElement>;
54
- onContextMenu: import('react').MouseEventHandler<HTMLDivElement>;
55
- onDoubleClick: import('react').MouseEventHandler<HTMLDivElement>;
56
- onKeyDown: import('react').KeyboardEventHandler<HTMLDivElement>;
57
- onKeyUp: import('react').KeyboardEventHandler<HTMLDivElement>;
58
- onMouseDown: import('react').MouseEventHandler<HTMLDivElement>;
59
- onMouseMove: import('react').MouseEventHandler<HTMLDivElement>;
60
- onMouseOver: import('react').MouseEventHandler<HTMLDivElement>;
61
- onMouseUp: import('react').MouseEventHandler<HTMLDivElement>;
62
- onScroll: import('react').UIEventHandler<HTMLDivElement>;
63
- }> & import('react').RefAttributes<HTMLDivElement>>;
55
+ export declare const Section: (props: Props) => import("react/jsx-runtime").JSX.Element;
56
+ export {};
@@ -1,62 +1,69 @@
1
- import { jsxs as r, jsx as s } from "react/jsx-runtime";
2
- import { forwardRef as S, useEffect as j } from "react";
3
- import { addScrollableNode as z, removeScrollableNode as B } from "../common/events.js";
4
- import { classes as H, canRender as m } from "../common/react.js";
5
- import { s as t } from "../Section.module-CLVHJ4yA.js";
6
- import { computeBoxClassName as T, computeBoxProps as y } from "./Box.js";
7
- const q = S(
8
- (a, l) => {
9
- const {
10
- buttons: c,
11
- children: u,
12
- className: p,
13
- fill: N,
14
- fitted: b,
15
- onScroll: h,
16
- scrollable: i,
17
- scrollableHorizontal: e,
18
- title: n,
19
- container_id: v,
20
- ...o
21
- } = a, x = m(n) || m(c);
22
- return j(() => {
23
- if (l != null && l.current && !(!i && !e))
24
- return z(l.current), () => {
25
- l != null && l.current && B(l.current);
26
- };
27
- }, []), /* @__PURE__ */ r(
28
- "div",
29
- {
30
- id: v || "",
31
- className: H([
32
- t.section,
33
- N && t.fill,
34
- b && t.fitted,
35
- i && t.scrollable,
36
- e && t.scrollableHorizontal,
37
- p,
38
- T(o)
39
- ]),
40
- ...y(o),
41
- children: [
42
- x && /* @__PURE__ */ r("div", { className: t.title, children: [
43
- /* @__PURE__ */ s("span", { className: t.titleText, children: n }),
44
- /* @__PURE__ */ s("div", { className: t.buttons, children: c })
45
- ] }),
46
- /* @__PURE__ */ s("div", { className: t.rest, children: /* @__PURE__ */ s(
47
- "div",
48
- {
49
- className: t.content,
50
- onScroll: h,
51
- ref: l,
52
- children: u
53
- }
54
- ) })
55
- ]
56
- }
57
- );
58
- }
59
- );
1
+ import { jsxs as a, jsx as r } from "react/jsx-runtime";
2
+ import { useRef as P, useEffect as g } from "react";
3
+ import { addScrollableNode as j, removeScrollableNode as z } from "../common/events.js";
4
+ import { classes as d, canRender as m } from "../common/react.js";
5
+ import { s as e } from "../Section.module-qhQWhlUX.js";
6
+ import { computeBoxClassName as B, computeBoxProps as H } from "./Box.js";
7
+ const _ = (f) => {
8
+ const {
9
+ buttons: o,
10
+ children: u,
11
+ className: p,
12
+ fill: N,
13
+ fitted: h,
14
+ flexGrow: b,
15
+ noTopPadding: x,
16
+ onScroll: v,
17
+ scrollable: s,
18
+ scrollableHorizontal: n,
19
+ stretchContents: S,
20
+ title: c,
21
+ container_id: T,
22
+ ...i
23
+ } = f, t = P(null), C = m(c) || m(o);
24
+ return g(() => {
25
+ if (!(t != null && t.current) || !s && !n) return;
26
+ const l = t.current;
27
+ return j(l), () => {
28
+ l && z(l);
29
+ };
30
+ }, []), /* @__PURE__ */ a(
31
+ "div",
32
+ {
33
+ id: T || "",
34
+ className: d([
35
+ e.section,
36
+ N && e.fill,
37
+ h && e.fitted,
38
+ s && e.scrollable,
39
+ n && e.scrollableHorizontal,
40
+ b && e.sectionFlex,
41
+ p,
42
+ B(i)
43
+ ]),
44
+ ...H(i),
45
+ children: [
46
+ C && /* @__PURE__ */ a("div", { className: e.title, children: [
47
+ /* @__PURE__ */ r("span", { className: e.titleText, children: c }),
48
+ /* @__PURE__ */ r("div", { className: e.buttons, children: o })
49
+ ] }),
50
+ /* @__PURE__ */ r("div", { className: e.rest, children: /* @__PURE__ */ r(
51
+ "div",
52
+ {
53
+ className: d([
54
+ e.content,
55
+ !!S && e.stretchContents,
56
+ !!x && e.noTopPadding
57
+ ]),
58
+ onScroll: v,
59
+ ref: t,
60
+ children: u
61
+ }
62
+ ) })
63
+ ]
64
+ }
65
+ );
66
+ };
60
67
  export {
61
- q as Section
68
+ _ as Section
62
69
  };
@@ -15,6 +15,8 @@ type Props = {
15
15
  className: string;
16
16
  /** Color of the slider. */
17
17
  color: string;
18
+ /** Disables the slider. */
19
+ disabled: boolean;
18
20
  /** If set, this value will be used to set the fill percentage of the progress bar filler independently of the main value. */
19
21
  fillValue: number;
20
22
  /** Format value using this function before displaying it. */
@@ -1,5 +1,5 @@
1
1
  import { jsxs as s, jsx as l } from "react/jsx-runtime";
2
- import { s as t } from "../Section.module-CLVHJ4yA.js";
2
+ import { s as t } from "../Section.module-qhQWhlUX.js";
3
3
  import { Box as e } from "./Box.js";
4
4
  function h(i) {
5
5
  const { children: r, titleStyle: c, titleSubtext: n, title: o, textStyle: a, style: m } = i;
@@ -11,6 +11,7 @@ type TabProps = Partial<{
11
11
  className: string;
12
12
  color: string;
13
13
  icon: string;
14
+ iconSpin: boolean;
14
15
  leftSlot: ReactNode;
15
16
  onClick: (e?: any) => void;
16
17
  rightSlot: ReactNode;