tgui-core 2.0.5 → 2.0.6

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,4 +1,31 @@
1
- import { ReactNode } from 'react';
1
+ import { ReactNode, RefObject } from 'react';
2
+ import { BoxProps } from './Box';
3
+ type Props = Partial<{
4
+ /** Buttons to render aside the section title. */
5
+ buttons: ReactNode;
6
+ /** id to assosiate with the parent div element used by this section, for uses with procs like getElementByID */
7
+ container_id: string;
8
+ /** If true, fills all available vertical space. */
9
+ fill: boolean;
10
+ /** If true, removes all section padding. */
11
+ fitted: boolean;
12
+ /** If true, fills the area without forcing height to 100% */
13
+ flexGrow: boolean;
14
+ /** If true, removes the section top padding */
15
+ noTopPadding: boolean;
16
+ /** @member Callback function for the `scroll` event */
17
+ onScroll: ((this: GlobalEventHandlers, ev: Event) => any) | null;
18
+ /** Ref to the section element. */
19
+ ref: RefObject<HTMLDivElement | null>;
20
+ /** Shows or hides the scrollbar. */
21
+ scrollable: boolean;
22
+ /** Shows or hides the horizontal scrollbar. */
23
+ scrollableHorizontal: boolean;
24
+ /** If true, filly the area except for -3rem */
25
+ stretchContents: boolean;
26
+ /** Title of the section. */
27
+ title: ReactNode;
28
+ }> & BoxProps;
2
29
  /**
3
30
  * ## Section
4
31
  * Section is a surface that displays content and actions on a single topic.
@@ -26,46 +53,5 @@ import { ReactNode } from 'react';
26
53
  * </Section>
27
54
  * ```
28
55
  */
29
- export declare const Section: import('react').ForwardRefExoticComponent<Partial<{
30
- /** Buttons to render aside the section title. */
31
- buttons: ReactNode;
32
- /** id to assosiate with the parent div element used by this section, for uses with procs like getElementByID */
33
- container_id: string;
34
- /** If true, fills all available vertical space. */
35
- fill: boolean;
36
- /** If true, removes all section padding. */
37
- fitted: boolean;
38
- /** If true, fills the area without forcing height to 100% */
39
- flexGrow: boolean;
40
- /** If true, removes the section top padding */
41
- noTopPadding: boolean;
42
- /** @member Callback function for the `scroll` event */
43
- onScroll: ((this: GlobalEventHandlers, ev: Event) => any) | null;
44
- /** Shows or hides the scrollbar. */
45
- scrollable: boolean;
46
- /** Shows or hides the horizontal scrollbar. */
47
- scrollableHorizontal: boolean;
48
- /** If true, filly the area except for -3rem */
49
- stretchContents: boolean;
50
- /** Title of the section. */
51
- title: ReactNode;
52
- }> & Partial<{
53
- as: string;
54
- children: ReactNode;
55
- className: string | import('../common/react').BooleanLike;
56
- id: string;
57
- style: import('react').CSSProperties;
58
- tw: string;
59
- } & import('../common/ui').BooleanStyleMap & import('../common/ui').StringStyleMap & {
60
- onClick: import('react').MouseEventHandler<HTMLDivElement>;
61
- onContextMenu: import('react').MouseEventHandler<HTMLDivElement>;
62
- onDoubleClick: import('react').MouseEventHandler<HTMLDivElement>;
63
- onKeyDown: import('react').KeyboardEventHandler<HTMLDivElement>;
64
- onKeyUp: import('react').KeyboardEventHandler<HTMLDivElement>;
65
- onMouseDown: import('react').MouseEventHandler<HTMLDivElement>;
66
- onMouseLeave: import('react').MouseEventHandler<HTMLDivElement>;
67
- onMouseMove: import('react').MouseEventHandler<HTMLDivElement>;
68
- onMouseOver: import('react').MouseEventHandler<HTMLDivElement>;
69
- onMouseUp: import('react').MouseEventHandler<HTMLDivElement>;
70
- onScroll: import('react').UIEventHandler<HTMLDivElement>;
71
- }> & import('react').RefAttributes<HTMLDivElement>>;
56
+ export declare function Section(props: Props): import("react/jsx-runtime").JSX.Element;
57
+ export {};
@@ -1,66 +1,65 @@
1
- import { jsxs as i, jsx as t } from "react/jsx-runtime";
2
- import { forwardRef as C, useRef as P, useEffect as g } from "react";
3
- import { addScrollableNode as j, removeScrollableNode as w } from "../common/events.js";
4
- import { canRender as s, classes as a } from "../common/react.js";
5
- import { computeBoxProps as z, computeBoxClassName as B } from "../common/ui.js";
6
- const q = C(
7
- (d, m) => {
8
- const {
9
- buttons: o,
10
- children: f,
11
- className: S,
12
- container_id: _ = "",
13
- fill: u,
14
- fitted: p,
15
- flexGrow: N,
16
- noTopPadding: h,
17
- onScroll: b,
18
- scrollable: n,
19
- scrollableHorizontal: c,
20
- stretchContents: x,
21
- title: r,
22
- ...l
23
- } = d, v = P(null), e = m || v, T = s(r) || s(o);
24
- return g(() => (e != null && e.current && (n || c) && j(e.current), () => {
25
- e != null && e.current && w(e.current);
26
- }), []), /* @__PURE__ */ i(
27
- "div",
28
- {
29
- id: _,
30
- className: a([
31
- "Section",
32
- u && "Section--fill",
33
- p && "Section--fitted",
34
- n && "Section--scrollable",
35
- c && "Section--scrollableHorizontal",
36
- N && "Section--flex",
37
- S,
38
- B(l)
39
- ]),
40
- ...z(l),
41
- children: [
42
- T && /* @__PURE__ */ i("div", { className: "Section__title", children: [
43
- /* @__PURE__ */ t("span", { className: "Section__titleText", children: r }),
44
- /* @__PURE__ */ t("div", { className: "Section__buttons", children: o })
45
- ] }),
46
- /* @__PURE__ */ t("div", { className: "Section__rest", children: /* @__PURE__ */ t(
47
- "div",
48
- {
49
- className: a([
50
- "Section__content",
51
- x && "Section__content--stretchContents",
52
- h && "Section__content--noTopPadding"
53
- ]),
54
- onScroll: b,
55
- ref: e,
56
- children: f
57
- }
58
- ) })
59
- ]
60
- }
61
- );
62
- }
63
- );
1
+ import { jsxs as s, jsx as e } from "react/jsx-runtime";
2
+ import { useRef as T, useEffect as C } from "react";
3
+ import { addScrollableNode as P, removeScrollableNode as g } from "../common/events.js";
4
+ import { canRender as a, classes as d } from "../common/react.js";
5
+ import { computeBoxProps as j, computeBoxClassName as z } from "../common/ui.js";
6
+ function k(m) {
7
+ const {
8
+ buttons: c,
9
+ children: S,
10
+ className: f,
11
+ container_id: u = "",
12
+ fill: _,
13
+ fitted: p,
14
+ flexGrow: N,
15
+ noTopPadding: h,
16
+ onScroll: b,
17
+ ref: o,
18
+ scrollable: n,
19
+ scrollableHorizontal: i,
20
+ stretchContents: x,
21
+ title: l,
22
+ ...r
23
+ } = m, t = T((o == null ? void 0 : o.current) ?? null), v = a(l) || a(c);
24
+ return C(() => (t != null && t.current && (n || i) && P(t.current), () => {
25
+ t != null && t.current && g(t.current);
26
+ }), []), /* @__PURE__ */ s(
27
+ "div",
28
+ {
29
+ id: u,
30
+ className: d([
31
+ "Section",
32
+ _ && "Section--fill",
33
+ p && "Section--fitted",
34
+ n && "Section--scrollable",
35
+ i && "Section--scrollableHorizontal",
36
+ N && "Section--flex",
37
+ f,
38
+ z(r)
39
+ ]),
40
+ ...j(r),
41
+ children: [
42
+ v && /* @__PURE__ */ s("div", { className: "Section__title", children: [
43
+ /* @__PURE__ */ e("span", { className: "Section__titleText", children: l }),
44
+ /* @__PURE__ */ e("div", { className: "Section__buttons", children: c })
45
+ ] }),
46
+ /* @__PURE__ */ e("div", { className: "Section__rest", children: /* @__PURE__ */ e(
47
+ "div",
48
+ {
49
+ className: d([
50
+ "Section__content",
51
+ x && "Section__content--stretchContents",
52
+ h && "Section__content--noTopPadding"
53
+ ]),
54
+ onScroll: b,
55
+ ref: t,
56
+ children: S
57
+ }
58
+ ) })
59
+ ]
60
+ }
61
+ );
62
+ }
64
63
  export {
65
- q as Section
64
+ k as Section
66
65
  };
@@ -1,11 +1,6 @@
1
- import { SyntheticEvent } from 'react';
2
- /**
3
- * ## Textarea
4
- *
5
- * An input for larger amounts of text. Use this when you want inputs larger
6
- * than one row.
7
- */
8
- export declare const TextArea: import('react').ForwardRefExoticComponent<Partial<{
1
+ import { RefObject, SyntheticEvent } from 'react';
2
+ import { BoxProps } from './Box';
3
+ type Props = Partial<{
9
4
  /** Automatically focus the textarea on mount */
10
5
  autoFocus: boolean;
11
6
  /** Selects all text on mount */
@@ -30,6 +25,8 @@ export declare const TextArea: import('react').ForwardRefExoticComponent<Partial
30
25
  onInput: (event: SyntheticEvent<HTMLTextAreaElement>, value: string) => void;
31
26
  /** Dummy text inside the textarea when it's empty */
32
27
  placeholder: string;
28
+ /** Ref to the textarea element. */
29
+ ref: RefObject<HTMLTextAreaElement | null>;
33
30
  /** Whether the textarea is scrollable when it has more content than height */
34
31
  scrollbar: boolean;
35
32
  /** Clears the textarea when the enter key is pressed */
@@ -38,23 +35,12 @@ export declare const TextArea: import('react').ForwardRefExoticComponent<Partial
38
35
  userMarkup: Record<string, string>;
39
36
  /** The value of the textarea */
40
37
  value: string;
41
- }> & Partial<{
42
- as: string;
43
- children: import('react').ReactNode;
44
- className: string | import('../common/react').BooleanLike;
45
- id: string;
46
- style: import('react').CSSProperties;
47
- tw: string;
48
- } & import('../common/ui').BooleanStyleMap & import('../common/ui').StringStyleMap & {
49
- onClick: import('react').MouseEventHandler<HTMLDivElement>;
50
- onContextMenu: import('react').MouseEventHandler<HTMLDivElement>;
51
- onDoubleClick: import('react').MouseEventHandler<HTMLDivElement>;
52
- onKeyDown: import('react').KeyboardEventHandler<HTMLDivElement>;
53
- onKeyUp: import('react').KeyboardEventHandler<HTMLDivElement>;
54
- onMouseDown: import('react').MouseEventHandler<HTMLDivElement>;
55
- onMouseLeave: import('react').MouseEventHandler<HTMLDivElement>;
56
- onMouseMove: import('react').MouseEventHandler<HTMLDivElement>;
57
- onMouseOver: import('react').MouseEventHandler<HTMLDivElement>;
58
- onMouseUp: import('react').MouseEventHandler<HTMLDivElement>;
59
- onScroll: import('react').UIEventHandler<HTMLDivElement>;
60
- }> & import('react').RefAttributes<HTMLTextAreaElement>>;
38
+ }> & BoxProps;
39
+ /**
40
+ * ## Textarea
41
+ *
42
+ * An input for larger amounts of text. Use this when you want inputs larger
43
+ * than one row.
44
+ */
45
+ export declare function TextArea(props: Props): import("react/jsx-runtime").JSX.Element;
46
+ export {};
@@ -1,139 +1,126 @@
1
- import { jsxs as F, jsx as p } from "react/jsx-runtime";
2
- import { forwardRef as I, useRef as M, useState as Y, useImperativeHandle as H, useEffect as y } from "react";
3
- import { KEY as A, isEscape as L } from "../common/keys.js";
4
- import { classes as x } from "../common/react.js";
5
- import { Box as U } from "./Box.js";
6
- import { toInputValue as _ } from "./Input.js";
7
- function q(u, o, l, t) {
8
- return `${u.substring(0, l)}${o}${u.substring(l, t)}${o}${u.substring(t)}`;
1
+ import { jsxs as M, jsx as d } from "react/jsx-runtime";
2
+ import { useRef as R, useState as Y, useEffect as y } from "react";
3
+ import { KEY as A, isEscape as I } from "../common/keys.js";
4
+ import { classes as p } from "../common/react.js";
5
+ import { Box as L } from "./Box.js";
6
+ import { toInputValue as h } from "./Input.js";
7
+ function U(a, s, l, e) {
8
+ return `${a.substring(0, l)}${s}${a.substring(l, e)}${s}${a.substring(e)}`;
9
9
  }
10
- const X = I(
11
- (u, o) => {
12
- const {
13
- autoFocus: l,
14
- autoSelect: t,
15
- displayedValue: s,
16
- dontUseTabForIndent: k,
17
- maxLength: w,
18
- noborder: S,
19
- onChange: i,
20
- onEnter: f,
21
- onEscape: g,
22
- onInput: d,
23
- placeholder: $,
24
- scrollbar: E,
25
- selfClear: b,
26
- userMarkup: m,
27
- value: T,
28
- ...K
29
- } = u, { className: D, fluid: N, nowrap: C, ...R } = K, a = M(null), [V, j] = Y(0);
30
- function B(r) {
31
- if (r.key === A.Enter) {
32
- if (r.shiftKey) {
33
- r.currentTarget.focus();
34
- return;
35
- }
36
- f == null || f(r, r.currentTarget.value), b && (r.currentTarget.value = ""), r.currentTarget.blur();
10
+ function Q(a) {
11
+ const {
12
+ autoFocus: s,
13
+ autoSelect: l,
14
+ displayedValue: e,
15
+ dontUseTabForIndent: k,
16
+ maxLength: S,
17
+ noborder: $,
18
+ onChange: n,
19
+ onEnter: i,
20
+ onEscape: f,
21
+ onInput: g,
22
+ placeholder: E,
23
+ ref: m,
24
+ scrollbar: K,
25
+ selfClear: b,
26
+ userMarkup: T,
27
+ value: x,
28
+ ...w
29
+ } = a, { className: N, fluid: D, nowrap: C, ...V } = w, u = R((m == null ? void 0 : m.current) ?? null), [j, B] = Y(0);
30
+ function F(r) {
31
+ if (r.key === A.Enter) {
32
+ if (r.shiftKey) {
33
+ r.currentTarget.focus();
37
34
  return;
38
35
  }
39
- if (L(r.key)) {
40
- g == null || g(r), b ? r.currentTarget.value = "" : (r.currentTarget.value = _(T), r.currentTarget.blur());
41
- return;
42
- }
43
- if (!k && r.key === A.Tab) {
44
- r.preventDefault();
45
- const { value: e, selectionStart: c, selectionEnd: n } = r.currentTarget;
46
- r.currentTarget.value = `${e.substring(0, c)} ${e.substring(n)}`, r.currentTarget.selectionEnd = c + 1;
47
- }
48
- if (m && (r.ctrlKey || r.metaKey) && m[r.key]) {
49
- r.preventDefault();
50
- const { value: e, selectionStart: c, selectionEnd: n } = r.currentTarget, h = m[r.key];
51
- r.currentTarget.value = q(
52
- e,
53
- h,
54
- c,
55
- n
56
- ), r.currentTarget.selectionEnd = n + h.length * 2;
57
- }
36
+ i == null || i(r, r.currentTarget.value), b && (r.currentTarget.value = ""), r.currentTarget.blur();
37
+ return;
58
38
  }
59
- return H(
60
- o,
61
- () => a.current
62
- ), y(() => {
63
- if (!l && !t) return;
64
- const r = a.current;
65
- r && (l || t) && setTimeout(() => {
66
- r.focus(), t && r.select();
39
+ if (I(r.key)) {
40
+ f == null || f(r), b ? r.currentTarget.value = "" : (r.currentTarget.value = h(x), r.currentTarget.blur());
41
+ return;
42
+ }
43
+ if (!k && r.key === A.Tab) {
44
+ r.preventDefault();
45
+ const { value: t, selectionStart: o, selectionEnd: c } = r.currentTarget;
46
+ r.currentTarget.value = `${t.substring(0, o)} ${t.substring(c)}`, r.currentTarget.selectionEnd = o + 1;
47
+ }
48
+ if (T && (r.ctrlKey || r.metaKey) && T[r.key]) {
49
+ r.preventDefault();
50
+ const { value: t, selectionStart: o, selectionEnd: c } = r.currentTarget, _ = T[r.key];
51
+ r.currentTarget.value = U(
52
+ t,
53
+ _,
54
+ o,
55
+ c
56
+ ), r.currentTarget.selectionEnd = c + _.length * 2;
57
+ }
58
+ }
59
+ return y(() => {
60
+ if (s || l) {
61
+ const r = u.current;
62
+ r && setTimeout(() => {
63
+ r.focus(), l && r.select();
67
64
  }, 1);
68
- }, []), y(() => {
69
- const r = a.current;
70
- if (!r) return;
71
- const e = _(T);
72
- r.value !== e && (r.value = e);
73
- }, [T]), /* @__PURE__ */ F(
74
- U,
75
- {
76
- className: x([
77
- "TextArea",
78
- N && "TextArea--fluid",
79
- S && "TextArea--noborder",
80
- D
81
- ]),
82
- ...R,
83
- children: [
84
- !!s && /* @__PURE__ */ p(
85
- "div",
86
- {
87
- style: {
88
- height: "100%",
89
- overflow: "hidden",
90
- position: "absolute",
91
- width: "100%"
92
- },
93
- children: /* @__PURE__ */ p(
94
- "div",
95
- {
96
- className: x([
97
- "TextArea__textarea",
98
- "TextArea__textarea_custom"
99
- ]),
100
- style: {
101
- transform: `translateY(-${V}px)`
102
- },
103
- children: s
104
- }
105
- )
106
- }
107
- ),
108
- /* @__PURE__ */ p(
109
- "textarea",
110
- {
111
- autoComplete: "off",
112
- className: x([
113
- "TextArea__textarea",
114
- E && "TextArea__textarea--scrollable",
115
- C && "TextArea__nowrap"
116
- ]),
117
- maxLength: w,
118
- onBlur: (r) => i == null ? void 0 : i(r, r.target.value),
119
- onChange: (r) => d == null ? void 0 : d(r, r.target.value),
120
- onKeyDown: B,
121
- onScroll: () => {
122
- s && a.current && j(a.current.scrollTop);
123
- },
124
- placeholder: $,
125
- ref: a,
126
- spellCheck: !1,
127
- style: {
128
- color: s ? "rgba(0, 0, 0, 0)" : "inherit"
129
- }
65
+ }
66
+ }, []), y(() => {
67
+ const r = u.current;
68
+ if (r) {
69
+ const t = h(x);
70
+ r.value !== t && (r.value = t);
71
+ }
72
+ }, [x]), /* @__PURE__ */ M(
73
+ L,
74
+ {
75
+ className: p([
76
+ "TextArea",
77
+ D && "TextArea--fluid",
78
+ $ && "TextArea--noborder",
79
+ N
80
+ ]),
81
+ ...V,
82
+ children: [
83
+ !!e && /* @__PURE__ */ d("div", { className: "TextArea__value-container", children: /* @__PURE__ */ d(
84
+ "div",
85
+ {
86
+ className: p([
87
+ "TextArea__textarea",
88
+ "TextArea__textarea_custom"
89
+ ]),
90
+ style: {
91
+ transform: `translateY(-${j}px)`
92
+ },
93
+ children: e
94
+ }
95
+ ) }),
96
+ /* @__PURE__ */ d(
97
+ "textarea",
98
+ {
99
+ autoComplete: "off",
100
+ className: p([
101
+ "TextArea__textarea",
102
+ K && "TextArea__textarea--scrollable",
103
+ C && "TextArea__nowrap"
104
+ ]),
105
+ maxLength: S,
106
+ onBlur: (r) => n == null ? void 0 : n(r, r.target.value),
107
+ onChange: (r) => g == null ? void 0 : g(r, r.target.value),
108
+ onKeyDown: F,
109
+ onScroll: () => {
110
+ e && u.current && B(u.current.scrollTop);
111
+ },
112
+ placeholder: E,
113
+ ref: u,
114
+ spellCheck: !1,
115
+ style: {
116
+ color: e ? "rgba(0, 0, 0, 0)" : "inherit"
130
117
  }
131
- )
132
- ]
133
- }
134
- );
135
- }
136
- );
118
+ }
119
+ )
120
+ ]
121
+ }
122
+ );
123
+ }
137
124
  export {
138
- X as TextArea
125
+ Q as TextArea
139
126
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tgui-core",
3
- "version": "2.0.5",
3
+ "version": "2.0.6",
4
4
  "description": "TGUI core component library",
5
5
  "keywords": ["TGUI", "library", "typescript"],
6
6
  "files": ["dist", "styles"],
@@ -73,3 +73,10 @@ $border-radius: 0 !default;
73
73
  overflow-x: scroll;
74
74
  white-space: nowrap;
75
75
  }
76
+
77
+ .TextArea__value-container {
78
+ height: 100%;
79
+ overflow: hidden;
80
+ position: absolute;
81
+ width: 100%;
82
+ }