@gpa-gemstone/react-forms 1.1.112 → 1.1.114
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/lib/AutoCompleteInput.d.ts +24 -0
- package/lib/AutoCompleteInput.js +225 -0
- package/lib/AutoCompleteMultiInput.d.ts +52 -0
- package/lib/AutoCompleteMultiInput.js +98 -0
- package/lib/AutoCompleteTextArea.d.ts +6 -0
- package/lib/AutoCompleteTextArea.js +162 -0
- package/lib/CheckBox.d.ts +2 -1
- package/lib/CheckBox.js +7 -20
- package/lib/ColorPicker.d.ts +2 -2
- package/lib/ColorPicker.js +13 -18
- package/lib/DateTimeUI/DateTimePicker.js +8 -15
- package/lib/HelpIcon.d.ts +29 -0
- package/lib/HelpIcon.js +44 -0
- package/lib/Input.d.ts +7 -2
- package/lib/Input.js +5 -17
- package/lib/InputWithButton.js +5 -18
- package/lib/MultiInput.js +9 -18
- package/lib/MultiSearchableSelect.js +9 -18
- package/lib/MutliCheckBoxSelect.js +5 -14
- package/lib/RadioButtons.js +2 -13
- package/lib/Select.js +3 -12
- package/lib/StylableSelect.js +3 -9
- package/lib/TextArea.d.ts +14 -2
- package/lib/TextArea.js +7 -12
- package/lib/TimePicker.js +3 -10
- package/lib/ToggleSwitch.js +2 -11
- package/lib/index.d.ts +5 -1
- package/lib/index.js +9 -1
- package/package.json +1 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IProps as IInputProps } from './Input';
|
|
2
|
+
interface IProps<T> extends Omit<IInputProps<T>, 'Type'> {
|
|
3
|
+
Options: string[];
|
|
4
|
+
}
|
|
5
|
+
export interface IVariable {
|
|
6
|
+
Start: number;
|
|
7
|
+
End: number;
|
|
8
|
+
Variable: string | null;
|
|
9
|
+
}
|
|
10
|
+
export default function AutoCompleteInput<T>(props: IProps<T>): JSX.Element;
|
|
11
|
+
export declare const getSuggestions: (variable: IVariable, text: string, options: string[]) => {
|
|
12
|
+
Label: string;
|
|
13
|
+
Value: string;
|
|
14
|
+
}[];
|
|
15
|
+
export declare const getCurrentVariable: (text: string, selection: number) => {
|
|
16
|
+
Start: number;
|
|
17
|
+
End: number;
|
|
18
|
+
Variable: null;
|
|
19
|
+
} | {
|
|
20
|
+
Start: number;
|
|
21
|
+
End: number;
|
|
22
|
+
Variable: string;
|
|
23
|
+
};
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ******************************************************************************************************
|
|
3
|
+
// AutoCompleteInput.tsx - Gbtc
|
|
4
|
+
//
|
|
5
|
+
// Copyright © 2024, Grid Protection Alliance. All Rights Reserved.
|
|
6
|
+
//
|
|
7
|
+
// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
|
|
8
|
+
// the NOTICE file distributed with this work for additional information regarding copyright ownership.
|
|
9
|
+
// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
|
|
10
|
+
// file except in compliance with the License. You may obtain a copy of the License at:
|
|
11
|
+
//
|
|
12
|
+
// http://opensource.org/licenses/MIT
|
|
13
|
+
//
|
|
14
|
+
// Unless agreed to in writing, the subject software distributed under the License is distributed on an
|
|
15
|
+
// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
|
|
16
|
+
// License for the specific language governing permissions and limitations.
|
|
17
|
+
//
|
|
18
|
+
// Code Modification History:
|
|
19
|
+
// ----------------------------------------------------------------------------------------------------
|
|
20
|
+
// 01/21/2026 - Natalie Beatty
|
|
21
|
+
// Generated original version of source code.
|
|
22
|
+
//
|
|
23
|
+
// ******************************************************************************************************
|
|
24
|
+
var __assign = (this && this.__assign) || function () {
|
|
25
|
+
__assign = Object.assign || function(t) {
|
|
26
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
27
|
+
s = arguments[i];
|
|
28
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
29
|
+
t[p] = s[p];
|
|
30
|
+
}
|
|
31
|
+
return t;
|
|
32
|
+
};
|
|
33
|
+
return __assign.apply(this, arguments);
|
|
34
|
+
};
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getCurrentVariable = exports.getSuggestions = void 0;
|
|
37
|
+
exports.default = AutoCompleteInput;
|
|
38
|
+
var React = require("react");
|
|
39
|
+
var Input_1 = require("./Input");
|
|
40
|
+
var react_portal_1 = require("react-portal");
|
|
41
|
+
var _ = require("lodash");
|
|
42
|
+
function AutoCompleteInput(props) {
|
|
43
|
+
var autoCompleteInput = React.useRef(null);
|
|
44
|
+
var inputElement = React.useRef(null);
|
|
45
|
+
var tableContainer = React.useRef(null);
|
|
46
|
+
var selectTable = React.useRef(null);
|
|
47
|
+
var _a = React.useState([]), suggestions = _a[0], setSuggestions = _a[1];
|
|
48
|
+
var _b = React.useState(null), position = _b[0], setPosition = _b[1];
|
|
49
|
+
var _c = React.useState(true), show = _c[0], setShow = _c[1];
|
|
50
|
+
// Handle showing and hiding of the dropdown.
|
|
51
|
+
var HandleShow = React.useCallback(function (evt) {
|
|
52
|
+
var _a;
|
|
53
|
+
// Ignore if disabled or not a mousedown event
|
|
54
|
+
if ((props.Disabled === undefined ? false : props.Disabled)
|
|
55
|
+
|| evt.type !== 'mousedown') {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
//ignore the click if it was inside the table or table container
|
|
59
|
+
if ((selectTable.current != null && selectTable.current.contains(evt.target)) || (tableContainer.current != null && tableContainer.current.contains(evt.target))) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (inputElement.current !== null && !((_a = inputElement.current) === null || _a === void 0 ? void 0 : _a.contains(evt.target))) {
|
|
63
|
+
setShow(false);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
setShow(true);
|
|
67
|
+
}
|
|
68
|
+
}, [props.Disabled]);
|
|
69
|
+
// update dropdown position
|
|
70
|
+
React.useLayoutEffect(function () {
|
|
71
|
+
if ((suggestions === null || suggestions === void 0 ? void 0 : suggestions.length) == 0) {
|
|
72
|
+
setPosition(null);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
var updatePosition = _.debounce(function () {
|
|
76
|
+
if (inputElement.current == null) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
var rect = inputElement.current.getBoundingClientRect();
|
|
80
|
+
setPosition({ Top: rect.bottom, Left: rect.left, Width: rect.width, Height: rect.height });
|
|
81
|
+
}, 200);
|
|
82
|
+
var handleScroll = function () {
|
|
83
|
+
if (tableContainer.current == null)
|
|
84
|
+
return;
|
|
85
|
+
updatePosition();
|
|
86
|
+
};
|
|
87
|
+
updatePosition();
|
|
88
|
+
window.addEventListener('scroll', handleScroll, true);
|
|
89
|
+
window.addEventListener('resize', updatePosition);
|
|
90
|
+
return function () {
|
|
91
|
+
window.removeEventListener('scroll', handleScroll, true);
|
|
92
|
+
window.removeEventListener('resize', updatePosition);
|
|
93
|
+
updatePosition.cancel();
|
|
94
|
+
};
|
|
95
|
+
}, [suggestions]);
|
|
96
|
+
// listen for changes in input caret position
|
|
97
|
+
React.useEffect(function () {
|
|
98
|
+
var autoComplete = inputElement.current;
|
|
99
|
+
if (autoComplete == null)
|
|
100
|
+
return;
|
|
101
|
+
autoComplete.addEventListener("keyup", handleCaretPosition);
|
|
102
|
+
autoComplete.addEventListener("click", handleCaretPosition);
|
|
103
|
+
window.addEventListener('mousedown', HandleShow, false);
|
|
104
|
+
return function () {
|
|
105
|
+
autoComplete.removeEventListener("keyup", handleCaretPosition);
|
|
106
|
+
autoComplete.removeEventListener("click", handleCaretPosition);
|
|
107
|
+
window.removeEventListener('mousedown', HandleShow, false);
|
|
108
|
+
};
|
|
109
|
+
}, [HandleShow]);
|
|
110
|
+
// edit input text when suggestion is selected
|
|
111
|
+
var handleOptionClick = function (option) {
|
|
112
|
+
var _a, _b, _c, _d, _e;
|
|
113
|
+
if (inputElement.current == null)
|
|
114
|
+
return;
|
|
115
|
+
var currentPos = (_a = inputElement.current.selectionStart) !== null && _a !== void 0 ? _a : 0;
|
|
116
|
+
var optionLength = option.Value.length;
|
|
117
|
+
props.Record[props.Field] = option.Value;
|
|
118
|
+
props.Setter(props.Record);
|
|
119
|
+
var textLength = (_c = (_b = inputElement.current.textContent) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0;
|
|
120
|
+
var newCaretPos = (optionLength > textLength ? textLength - 1 : optionLength + currentPos);
|
|
121
|
+
(_d = inputElement.current) === null || _d === void 0 ? void 0 : _d.focus();
|
|
122
|
+
(_e = inputElement.current) === null || _e === void 0 ? void 0 : _e.setSelectionRange(newCaretPos, newCaretPos);
|
|
123
|
+
setSuggestions([]);
|
|
124
|
+
};
|
|
125
|
+
// update variable when caret position changes
|
|
126
|
+
var handleCaretPosition = function () {
|
|
127
|
+
var _a, _b, _c, _d, _e;
|
|
128
|
+
if (inputElement.current !== null) {
|
|
129
|
+
var selection = ((_a = inputElement.current.selectionStart) !== null && _a !== void 0 ? _a : 0);
|
|
130
|
+
var variable = (0, exports.getCurrentVariable)((_c = (_b = inputElement.current) === null || _b === void 0 ? void 0 : _b.getAttribute('value')) !== null && _c !== void 0 ? _c : "", selection);
|
|
131
|
+
var suggests = (0, exports.getSuggestions)(variable, (_e = (_d = inputElement.current) === null || _d === void 0 ? void 0 : _d.getAttribute('value')) !== null && _e !== void 0 ? _e : "", props.Options);
|
|
132
|
+
setSuggestions(suggests);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
return (React.createElement("div", { ref: autoCompleteInput },
|
|
136
|
+
React.createElement(Input_1.default, __assign({}, props, { InputRef: inputElement })),
|
|
137
|
+
position == null || !show ? null :
|
|
138
|
+
React.createElement(react_portal_1.Portal, null,
|
|
139
|
+
React.createElement("div", { ref: tableContainer, className: 'popover', style: {
|
|
140
|
+
maxHeight: window.innerHeight - position.Top,
|
|
141
|
+
overflowY: 'auto',
|
|
142
|
+
padding: '10 5',
|
|
143
|
+
display: 'block',
|
|
144
|
+
position: 'absolute',
|
|
145
|
+
zIndex: 9999,
|
|
146
|
+
top: "".concat(position.Top, "px"),
|
|
147
|
+
left: "".concat(position.Left, "px"),
|
|
148
|
+
minWidth: "".concat(position.Width, "px"),
|
|
149
|
+
maxWidth: '100%'
|
|
150
|
+
} },
|
|
151
|
+
React.createElement("table", { className: "table table-hover", style: { margin: 0 }, ref: selectTable },
|
|
152
|
+
React.createElement("tbody", null, suggestions.map(function (f, i) { return (f.Value === props.Record[props.Field] ? null :
|
|
153
|
+
React.createElement("tr", { key: i, onMouseDown: function (_) { return handleOptionClick(f); } },
|
|
154
|
+
React.createElement("td", null, f.Label))); })))))));
|
|
155
|
+
}
|
|
156
|
+
var getSuggestions = function (variable, text, options) {
|
|
157
|
+
if (!(variable.Variable != null)) {
|
|
158
|
+
return [];
|
|
159
|
+
}
|
|
160
|
+
// if variable is valid option and hasEndBracket, assume it doesn't need autocompletion.
|
|
161
|
+
if (options.includes(variable.Variable)) {
|
|
162
|
+
return [];
|
|
163
|
+
}
|
|
164
|
+
if (text === "") {
|
|
165
|
+
return [];
|
|
166
|
+
}
|
|
167
|
+
// Find suggestions for the variable
|
|
168
|
+
var possibleVariables = options.filter(function (v) { var _a; return v.toLowerCase().includes(((_a = variable.Variable) !== null && _a !== void 0 ? _a : "").toLowerCase()); });
|
|
169
|
+
var before = text.substring(0, (variable.Start) - 1);
|
|
170
|
+
var after = text.substring(variable.End);
|
|
171
|
+
var hasEndBracket = (text[variable.End] === '}');
|
|
172
|
+
// Generate suggestions
|
|
173
|
+
var suggestions = possibleVariables.map(function (pv) {
|
|
174
|
+
// Ensure we have braces around the variable and add closing '}' if it was missing
|
|
175
|
+
var variableWithBraces = hasEndBracket ? "{".concat(pv) : "{".concat(pv, "}");
|
|
176
|
+
return { Label: "".concat(variableWithBraces).concat(hasEndBracket ? '}' : ''), Value: "".concat(before).concat(variableWithBraces).concat(after) };
|
|
177
|
+
});
|
|
178
|
+
return suggestions;
|
|
179
|
+
};
|
|
180
|
+
exports.getSuggestions = getSuggestions;
|
|
181
|
+
var getCurrentVariable = function (text, selection) {
|
|
182
|
+
var thisVariable = {
|
|
183
|
+
Start: 0,
|
|
184
|
+
End: 0,
|
|
185
|
+
Variable: null
|
|
186
|
+
};
|
|
187
|
+
if (text === "") {
|
|
188
|
+
return thisVariable;
|
|
189
|
+
}
|
|
190
|
+
// easy returns if selection start could not have a curly bracket before it
|
|
191
|
+
if (selection === null || selection < 0 || selection > text.length) {
|
|
192
|
+
return thisVariable;
|
|
193
|
+
}
|
|
194
|
+
// check backwards from the caret to find the nearest open curly bracket or space
|
|
195
|
+
var start = selection;
|
|
196
|
+
while (start > 0) {
|
|
197
|
+
// check for open curly bracket. if found, assign and break as start of valid variable expression
|
|
198
|
+
if (/{/g.test(text[start - 1])) {
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
// if space is encountered first, return
|
|
202
|
+
if (/[\s}]/g.test(text[start - 1])) {
|
|
203
|
+
return thisVariable;
|
|
204
|
+
}
|
|
205
|
+
start--;
|
|
206
|
+
}
|
|
207
|
+
// if no variable found, return
|
|
208
|
+
if (start == 0) {
|
|
209
|
+
return thisVariable;
|
|
210
|
+
}
|
|
211
|
+
thisVariable.Start = start;
|
|
212
|
+
// then, get the rest of the word.
|
|
213
|
+
var end = start !== null && start !== void 0 ? start : 0;
|
|
214
|
+
while (end < text.length) {
|
|
215
|
+
if (/[}{\s}]/.test(text[end])) {
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
end++;
|
|
219
|
+
}
|
|
220
|
+
thisVariable.End = end;
|
|
221
|
+
// get variable as substring of text
|
|
222
|
+
var variable = text.substring(start, end);
|
|
223
|
+
return { Start: thisVariable.Start, End: thisVariable.End, Variable: variable };
|
|
224
|
+
};
|
|
225
|
+
exports.getCurrentVariable = getCurrentVariable;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Gemstone } from '@gpa-gemstone/application-typings';
|
|
3
|
+
interface IProps<T> extends Omit<Gemstone.TSX.Interfaces.IBaseFormProps<T>, 'Valid' | 'Feedback'> {
|
|
4
|
+
/**
|
|
5
|
+
* CSS styles to apply to the Input component
|
|
6
|
+
* @type {React.CSSProperties}
|
|
7
|
+
* @optional
|
|
8
|
+
*/
|
|
9
|
+
Style?: React.CSSProperties;
|
|
10
|
+
/**
|
|
11
|
+
* Default value to use when adding an item and when value is null
|
|
12
|
+
* @type {number | string}
|
|
13
|
+
*/
|
|
14
|
+
DefaultValue: number | string;
|
|
15
|
+
/**
|
|
16
|
+
* Flag to allow null values
|
|
17
|
+
* @type {boolean}
|
|
18
|
+
* @optional
|
|
19
|
+
*/
|
|
20
|
+
AllowNull?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Function to determine the validity of a field
|
|
23
|
+
* @param value - The value of the item to check
|
|
24
|
+
* @param index - The index of the item in the array
|
|
25
|
+
* @param arr - The full array of items
|
|
26
|
+
* @returns {boolean}
|
|
27
|
+
*/
|
|
28
|
+
ItemValid?: (value: string | number, index: number, arr: Array<string | number>) => boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Feedback message to show when input is invalid
|
|
31
|
+
* @param value - The value of the item to check
|
|
32
|
+
* @param index - The index of the item in the array
|
|
33
|
+
* @param arr - The full array of items
|
|
34
|
+
* @returns {string | undefined}
|
|
35
|
+
*/
|
|
36
|
+
ItemFeedback?: (value: string | number, index: number, arr: Array<string | number>) => string | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Flag to disable add button
|
|
39
|
+
*/
|
|
40
|
+
DisableAdd?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Flag to disable all input fields
|
|
43
|
+
*/
|
|
44
|
+
Disabled?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* List of autocomplete suggestion options
|
|
47
|
+
* @type {string[]}
|
|
48
|
+
*/
|
|
49
|
+
Options: string[];
|
|
50
|
+
}
|
|
51
|
+
declare function AutoCompleteMultiInput<T>(props: IProps<T>): JSX.Element;
|
|
52
|
+
export default AutoCompleteMultiInput;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ******************************************************************************************************
|
|
3
|
+
// AutoCompleteMultiInput.tsx - Gbtc
|
|
4
|
+
//
|
|
5
|
+
// Copyright © 2026, Grid Protection Alliance. All Rights Reserved.
|
|
6
|
+
//
|
|
7
|
+
// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
|
|
8
|
+
// the NOTICE file distributed with this work for additional information regarding copyright ownership.
|
|
9
|
+
// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
|
|
10
|
+
// file except in compliance with the License. You may obtain a copy of the License at:
|
|
11
|
+
//
|
|
12
|
+
// http://opensource.org/licenses/MIT
|
|
13
|
+
//
|
|
14
|
+
// Unless agreed to in writing, the subject software distributed under the License is distributed on an
|
|
15
|
+
// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
|
|
16
|
+
// License for the specific language governing permissions and limitations.
|
|
17
|
+
//
|
|
18
|
+
// Code Modification History:
|
|
19
|
+
// ----------------------------------------------------------------------------------------------------
|
|
20
|
+
// 02/26/2026 - Preston Crawford
|
|
21
|
+
// Generated original version of source code.
|
|
22
|
+
//
|
|
23
|
+
// ******************************************************************************************************
|
|
24
|
+
var __assign = (this && this.__assign) || function () {
|
|
25
|
+
__assign = Object.assign || function(t) {
|
|
26
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
27
|
+
s = arguments[i];
|
|
28
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
29
|
+
t[p] = s[p];
|
|
30
|
+
}
|
|
31
|
+
return t;
|
|
32
|
+
};
|
|
33
|
+
return __assign.apply(this, arguments);
|
|
34
|
+
};
|
|
35
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
36
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
37
|
+
if (ar || !(i in from)) {
|
|
38
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
39
|
+
ar[i] = from[i];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
var React = require("react");
|
|
46
|
+
var AutoCompleteInput_1 = require("./AutoCompleteInput");
|
|
47
|
+
var gpa_symbols_1 = require("@gpa-gemstone/gpa-symbols");
|
|
48
|
+
var HelpIcon_1 = require("./HelpIcon");
|
|
49
|
+
function AutoCompleteMultiInput(props) {
|
|
50
|
+
var fieldArray = props.Record[props.Field];
|
|
51
|
+
if ((fieldArray === null || fieldArray === void 0 ? void 0 : fieldArray.constructor) !== Array) {
|
|
52
|
+
console.warn("AutoCompleteMultiInput: ".concat(props.Field.toString(), " is not of type array."));
|
|
53
|
+
return React.createElement(React.Fragment, null);
|
|
54
|
+
}
|
|
55
|
+
// Variables to control the rendering of label and help icon.
|
|
56
|
+
var showLabel = props.Label !== "";
|
|
57
|
+
var label = props.Label === undefined ? props.Field : props.Label;
|
|
58
|
+
return (React.createElement(React.Fragment, null,
|
|
59
|
+
fieldArray.length === 0 ?
|
|
60
|
+
React.createElement(React.Fragment, null, showLabel ?
|
|
61
|
+
React.createElement("label", { className: "d-flex align-items-center" },
|
|
62
|
+
React.createElement("span", null, showLabel ? label : ''),
|
|
63
|
+
React.createElement(HelpIcon_1.default, { Help: props.Help }))
|
|
64
|
+
: null)
|
|
65
|
+
: null,
|
|
66
|
+
fieldArray.map(function (r, index) {
|
|
67
|
+
var _a, _b, _c, _d, _e, _f;
|
|
68
|
+
return (React.createElement("div", { className: 'row no-gutters', key: index },
|
|
69
|
+
React.createElement("div", { className: 'col-10' },
|
|
70
|
+
React.createElement(AutoCompleteInput_1.default, { Record: fieldArray, Field: index, Label: index === 0 ? props.Label : '', AllowNull: props.AllowNull, Help: index === 0 ? props.Help : undefined, Feedback: (_b = (_a = props.ItemFeedback) === null || _a === void 0 ? void 0 : _a.call(props, r, index, fieldArray)) !== null && _b !== void 0 ? _b : undefined, Valid: function () { var _a, _b; return (_b = (_a = props.ItemValid) === null || _a === void 0 ? void 0 : _a.call(props, r, index, fieldArray)) !== null && _b !== void 0 ? _b : true; }, Style: props.Style, Disabled: props.Disabled, DefaultValue: typeof props.DefaultValue === 'number' ? props.DefaultValue : undefined, Options: props.Options, Setter: function (record) {
|
|
71
|
+
var _a;
|
|
72
|
+
var _b;
|
|
73
|
+
var newArray = __spreadArray([], fieldArray, true);
|
|
74
|
+
if (!((_b = props.AllowNull) !== null && _b !== void 0 ? _b : true) && record[index] === null)
|
|
75
|
+
newArray[index] = props.DefaultValue;
|
|
76
|
+
else
|
|
77
|
+
newArray[index] = record[index];
|
|
78
|
+
props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = newArray, _a)));
|
|
79
|
+
} })),
|
|
80
|
+
React.createElement("div", { className: "col-".concat(index === __spreadArray([], fieldArray, true).length - 1 ? 1 : 2, " ").concat(index === 0 ? 'd-flex align-items-center justify-content-center' : '') },
|
|
81
|
+
React.createElement("button", { className: 'btn', style: ((_c = props.Disabled) !== null && _c !== void 0 ? _c : false) ? { display: 'none' } : undefined, onClick: function () {
|
|
82
|
+
var _a;
|
|
83
|
+
var newRecords = __spreadArray([], fieldArray, true).filter(function (_, i) { return i !== index; });
|
|
84
|
+
props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = newRecords, _a)));
|
|
85
|
+
} },
|
|
86
|
+
React.createElement(gpa_symbols_1.ReactIcons.TrashCan, { Color: 'red' }))),
|
|
87
|
+
index === __spreadArray([], fieldArray, true).length - 1 ?
|
|
88
|
+
React.createElement("div", { className: "col-1 ".concat(index === 0 ? 'd-flex align-items-center justify-content-center' : '') },
|
|
89
|
+
React.createElement("button", { className: 'btn', style: ((_f = (((_d = props.DisableAdd) !== null && _d !== void 0 ? _d : false) || ((_e = props.Disabled) !== null && _e !== void 0 ? _e : false))) !== null && _f !== void 0 ? _f : false) ? { display: 'none' } : undefined, onClick: function () {
|
|
90
|
+
var _a;
|
|
91
|
+
var newRecords = __spreadArray(__spreadArray([], __spreadArray([], fieldArray, true), true), [props.DefaultValue], false);
|
|
92
|
+
props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = newRecords, _a)));
|
|
93
|
+
} },
|
|
94
|
+
React.createElement(gpa_symbols_1.ReactIcons.CirclePlus, null)))
|
|
95
|
+
: null));
|
|
96
|
+
})));
|
|
97
|
+
}
|
|
98
|
+
exports.default = AutoCompleteMultiInput;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.default = AutoCompleteTextArea;
|
|
15
|
+
var React = require("react");
|
|
16
|
+
var TextArea_1 = require("./TextArea");
|
|
17
|
+
var react_portal_1 = require("react-portal");
|
|
18
|
+
var _ = require("lodash");
|
|
19
|
+
var AutoCompleteInput_1 = require("./AutoCompleteInput");
|
|
20
|
+
function AutoCompleteTextArea(props) {
|
|
21
|
+
var autoCompleteTextArea = React.useRef(null);
|
|
22
|
+
var tableContainer = React.useRef(null);
|
|
23
|
+
var selectTable = React.useRef(null);
|
|
24
|
+
var textAreaElement = React.useRef(null);
|
|
25
|
+
var _a = React.useState([]), suggestions = _a[0], setSuggestions = _a[1];
|
|
26
|
+
var _b = React.useState(null), position = _b[0], setPosition = _b[1];
|
|
27
|
+
var _c = React.useState({ Start: 0, End: 0, Variable: "" }), variable = _c[0], setVariable = _c[1];
|
|
28
|
+
var _d = React.useState(true), show = _d[0], setShow = _d[1];
|
|
29
|
+
// Handle showing and hiding of the dropdown.
|
|
30
|
+
var HandleShow = React.useCallback(function (evt) {
|
|
31
|
+
var _a;
|
|
32
|
+
// Ignore if disabled or not a mousedown event
|
|
33
|
+
if ((props.Disabled === undefined ? false : props.Disabled)
|
|
34
|
+
|| evt.type !== 'mousedown') {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
//ignore the click if it was inside the table or table container
|
|
38
|
+
if ((selectTable.current != null && selectTable.current.contains(evt.target)) || (tableContainer.current != null && tableContainer.current.contains(evt.target))) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (textAreaElement.current !== null && !((_a = textAreaElement.current) === null || _a === void 0 ? void 0 : _a.contains(evt.target))) {
|
|
42
|
+
setShow(false);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
setShow(true);
|
|
46
|
+
}
|
|
47
|
+
}, [props.Disabled]);
|
|
48
|
+
// add listeners to follow caret
|
|
49
|
+
React.useEffect(function () {
|
|
50
|
+
var autoComplete = textAreaElement.current;
|
|
51
|
+
if (autoComplete == null)
|
|
52
|
+
return;
|
|
53
|
+
autoComplete.addEventListener("keyup", handleCaretPosition);
|
|
54
|
+
autoComplete.addEventListener("click", handleCaretPosition);
|
|
55
|
+
return function () {
|
|
56
|
+
autoComplete.removeEventListener("keyup", handleCaretPosition);
|
|
57
|
+
autoComplete.removeEventListener("click", handleCaretPosition);
|
|
58
|
+
};
|
|
59
|
+
}, []);
|
|
60
|
+
// set position of the suggestion dropdown
|
|
61
|
+
React.useLayoutEffect(function () {
|
|
62
|
+
if ((suggestions === null || suggestions === void 0 ? void 0 : suggestions.length) == 0) {
|
|
63
|
+
setPosition(null);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
var updatePosition = _.debounce(function () {
|
|
67
|
+
if (textAreaElement.current == null) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
var rect = textAreaElement.current.getBoundingClientRect();
|
|
71
|
+
var _a = getTextDimensions(textAreaElement, variable.Start - 1, "\n"), caret_X = _a[0], caret_Y = _a[1];
|
|
72
|
+
setPosition({ Top: rect.top + caret_Y, Left: rect.left + caret_X, Width: rect.width, Height: rect.height });
|
|
73
|
+
}, 200);
|
|
74
|
+
var handleScroll = function () {
|
|
75
|
+
if (tableContainer.current == null)
|
|
76
|
+
return;
|
|
77
|
+
updatePosition();
|
|
78
|
+
};
|
|
79
|
+
updatePosition();
|
|
80
|
+
window.addEventListener('scroll', handleScroll, true);
|
|
81
|
+
window.addEventListener('resize', updatePosition);
|
|
82
|
+
window.addEventListener('mousedown', HandleShow, false);
|
|
83
|
+
return function () {
|
|
84
|
+
window.removeEventListener('scroll', handleScroll, true);
|
|
85
|
+
window.removeEventListener('resize', updatePosition);
|
|
86
|
+
window.removeEventListener('mousedown', HandleShow, false);
|
|
87
|
+
updatePosition.cancel();
|
|
88
|
+
};
|
|
89
|
+
}, [suggestions, HandleShow]);
|
|
90
|
+
// update variable and suggestions when caret position changes
|
|
91
|
+
var handleCaretPosition = function () {
|
|
92
|
+
var _a, _b, _c, _d;
|
|
93
|
+
if (textAreaElement.current !== null) {
|
|
94
|
+
var selection = textAreaElement.current.selectionStart;
|
|
95
|
+
var variable_1 = (0, AutoCompleteInput_1.getCurrentVariable)((_b = (_a = textAreaElement.current) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : "", selection);
|
|
96
|
+
setVariable(variable_1);
|
|
97
|
+
var suggests = (0, AutoCompleteInput_1.getSuggestions)(variable_1, (_d = (_c = textAreaElement.current) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : "", props.Options);
|
|
98
|
+
setSuggestions(suggests);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
// edit text area contents with selected suggestion
|
|
102
|
+
var handleOptionClick = function (option) {
|
|
103
|
+
var _a, _b, _c, _d;
|
|
104
|
+
var currentPos = textAreaElement.current !== null ? textAreaElement.current.selectionStart : 0;
|
|
105
|
+
var optionLength = option.Value.length;
|
|
106
|
+
props.Record[props.Field] = option.Value;
|
|
107
|
+
props.Setter(props.Record);
|
|
108
|
+
var textLength = textAreaElement.current !== null ? (_b = (_a = textAreaElement.current.textContent) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0 : 0;
|
|
109
|
+
var newCaretPos = (optionLength > textLength ? textLength - 1 : optionLength + currentPos);
|
|
110
|
+
(_c = textAreaElement.current) === null || _c === void 0 ? void 0 : _c.focus();
|
|
111
|
+
(_d = textAreaElement.current) === null || _d === void 0 ? void 0 : _d.setSelectionRange(newCaretPos, newCaretPos);
|
|
112
|
+
setSuggestions([]);
|
|
113
|
+
};
|
|
114
|
+
return (React.createElement("div", { ref: autoCompleteTextArea },
|
|
115
|
+
React.createElement(TextArea_1.default, __assign({}, props, { TextAreaRef: textAreaElement, SpellCheck: false })),
|
|
116
|
+
position == null || !show ? React.createElement(React.Fragment, null) :
|
|
117
|
+
React.createElement(react_portal_1.Portal, null,
|
|
118
|
+
React.createElement("div", { ref: tableContainer, className: 'popover', style: {
|
|
119
|
+
maxHeight: window.innerHeight - position.Top,
|
|
120
|
+
overflowY: 'auto',
|
|
121
|
+
padding: '10 5',
|
|
122
|
+
display: 'block',
|
|
123
|
+
position: 'absolute',
|
|
124
|
+
zIndex: 9999,
|
|
125
|
+
maxWidth: '100%',
|
|
126
|
+
top: "".concat(position.Top, "px"),
|
|
127
|
+
left: "".concat(position.Left, "px"),
|
|
128
|
+
minWidth: "".concat(position.Width, "px")
|
|
129
|
+
} },
|
|
130
|
+
React.createElement("table", { className: "table table-hover", style: { margin: 0 }, ref: selectTable },
|
|
131
|
+
React.createElement("tbody", null, suggestions.map(function (f, i) { return (f.Value === props.Record[props.Field] ? null :
|
|
132
|
+
React.createElement("tr", { key: i, onMouseDown: function (_) { return handleOptionClick(f); } },
|
|
133
|
+
React.createElement("td", null, f.Label))); })))))));
|
|
134
|
+
}
|
|
135
|
+
var getTextDimensions = function (textArea, selection, prefix) {
|
|
136
|
+
var _a;
|
|
137
|
+
if (textArea.current == null)
|
|
138
|
+
return [0, 0];
|
|
139
|
+
var textarea = textArea.current;
|
|
140
|
+
if (textarea.parentNode == null)
|
|
141
|
+
return [0, 0];
|
|
142
|
+
var hiddenDiv = document.createElement('div');
|
|
143
|
+
var style = getComputedStyle(textarea);
|
|
144
|
+
Array.from(style).forEach(function (propertyName) {
|
|
145
|
+
var value = style.getPropertyValue(propertyName);
|
|
146
|
+
hiddenDiv.style.setProperty(propertyName, value);
|
|
147
|
+
});
|
|
148
|
+
// Set text content up to caret
|
|
149
|
+
var beforeSelection = textarea.value.substring(0, selection);
|
|
150
|
+
var afterSelection = (_a = textarea.value.substring(selection)) !== null && _a !== void 0 ? _a : '.';
|
|
151
|
+
hiddenDiv.textContent = (prefix !== null && prefix !== void 0 ? prefix : "") + beforeSelection;
|
|
152
|
+
// Create a span to mark caret position
|
|
153
|
+
var span = document.createElement('span');
|
|
154
|
+
span.textContent = afterSelection[0];
|
|
155
|
+
hiddenDiv.appendChild(span);
|
|
156
|
+
textarea.parentNode.appendChild(hiddenDiv);
|
|
157
|
+
// Get caret's vertical position relative to textarea
|
|
158
|
+
var caretX = span.offsetLeft - hiddenDiv.offsetLeft - hiddenDiv.scrollLeft;
|
|
159
|
+
var caretY = span.offsetTop - hiddenDiv.offsetTop - textarea.scrollTop;
|
|
160
|
+
textarea.parentNode.removeChild(hiddenDiv);
|
|
161
|
+
return [caretX, caretY];
|
|
162
|
+
};
|
package/lib/CheckBox.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { Gemstone } from '@gpa-gemstone/application-typings';
|
|
2
|
-
|
|
2
|
+
declare const CheckBox: <T>(props: Gemstone.TSX.Interfaces.IBaseFormProps<T>) => JSX.Element;
|
|
3
|
+
export default CheckBox;
|
package/lib/CheckBox.js
CHANGED
|
@@ -33,20 +33,10 @@ var __assign = (this && this.__assign) || function () {
|
|
|
33
33
|
return __assign.apply(this, arguments);
|
|
34
34
|
};
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.default = CheckBox;
|
|
37
36
|
var React = require("react");
|
|
38
|
-
var
|
|
39
|
-
var
|
|
40
|
-
var gpa_symbols_1 = require("@gpa-gemstone/gpa-symbols");
|
|
41
|
-
function CheckBox(props) {
|
|
42
|
-
var _a = React.useState(""), guid = _a[0], setGuid = _a[1];
|
|
43
|
-
var _b = React.useState(false), showHelp = _b[0], setShowHelp = _b[1];
|
|
44
|
-
// Runs once, setting a unique GUID for each checkbox instance.
|
|
45
|
-
React.useEffect(function () {
|
|
46
|
-
setGuid((0, helper_functions_1.CreateGuid)());
|
|
47
|
-
}, []);
|
|
37
|
+
var HelpIcon_1 = require("./HelpIcon");
|
|
38
|
+
var CheckBox = function (props) {
|
|
48
39
|
var showLabel = props.Label !== "";
|
|
49
|
-
var showHelpIcon = props.Help !== undefined;
|
|
50
40
|
var label = props.Label === undefined ? props.Field : props.Label;
|
|
51
41
|
return (React.createElement("div", { className: "form-check" },
|
|
52
42
|
React.createElement("input", { type: "checkbox", className: "form-check-input", style: { zIndex: 1 }, onChange: function (evt) {
|
|
@@ -54,13 +44,10 @@ function CheckBox(props) {
|
|
|
54
44
|
record[props.Field] = evt.target.checked;
|
|
55
45
|
props.Setter(record);
|
|
56
46
|
}, value: props.Record[props.Field] ? 'on' : 'off', checked: props.Record[props.Field], disabled: props.Disabled == null ? false : props.Disabled }),
|
|
57
|
-
|
|
58
|
-
React.createElement("label", { className: "
|
|
47
|
+
showLabel ?
|
|
48
|
+
React.createElement("label", { className: "d-flex align-items-center" },
|
|
59
49
|
React.createElement("span", null, showLabel ? label : ''),
|
|
60
|
-
|
|
61
|
-
React.createElement(gpa_symbols_1.ReactIcons.QuestionMark, { Color: "var(--info)", Size: 20 }))))
|
|
62
|
-
: null,
|
|
63
|
-
showHelpIcon ?
|
|
64
|
-
React.createElement(ToolTip_1.default, { Show: showHelp, Target: guid, Class: "info", Position: "top" }, props.Help)
|
|
50
|
+
React.createElement(HelpIcon_1.default, { Help: props.Help }))
|
|
65
51
|
: null));
|
|
66
|
-
}
|
|
52
|
+
};
|
|
53
|
+
exports.default = CheckBox;
|
package/lib/ColorPicker.d.ts
CHANGED
|
@@ -40,5 +40,5 @@ interface IProps<T> extends Omit<Gemstone.TSX.Interfaces.IBaseFormProps<T>, "Set
|
|
|
40
40
|
*/
|
|
41
41
|
Triangle?: 'hide' | 'top';
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
export
|
|
43
|
+
declare const ColorPicker: <T>(props: IProps<T>) => JSX.Element;
|
|
44
|
+
export default ColorPicker;
|