ozdenui 0.1.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.
- checksums.yaml +7 -0
- data/LICENSE +14 -0
- data/NOTICE +5 -0
- data/README.md +242 -0
- data/exe/ozdenui +17 -0
- data/lib/ozdenui/AGENTS.md +210 -0
- data/lib/ozdenui/COMPONENTS.md +3017 -0
- data/lib/ozdenui/app.rb +749 -0
- data/lib/ozdenui/command.rb +107 -0
- data/lib/ozdenui/components.rb +368 -0
- data/lib/ozdenui/dialogs.rb +212 -0
- data/lib/ozdenui/files.rb +124 -0
- data/lib/ozdenui/icon.png +0 -0
- data/lib/ozdenui/kit.json +1 -0
- data/lib/ozdenui/kit.rb +115 -0
- data/lib/ozdenui/look.rb +229 -0
- data/lib/ozdenui/objects.rb +652 -0
- data/lib/ozdenui/server.rb +270 -0
- data/lib/ozdenui/values.rb +273 -0
- data/lib/ozdenui/version.rb +15 -0
- data/lib/ozdenui/web/basic/LICENSE +14 -0
- data/lib/ozdenui/web/basic/basic.min.css +1 -0
- data/lib/ozdenui/web/basic/basic.min.js +78 -0
- data/lib/ozdenui/web/basic/font/open-sans/LICENSE.txt +206 -0
- data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Bold.ttf +0 -0
- data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Regular.ttf +0 -0
- data/lib/ozdenui/web/basic/scroll-bar.min.js +3 -0
- data/lib/ozdenui/web/bridge.js +584 -0
- data/lib/ozdenui/web/comp/accordion.js +659 -0
- data/lib/ozdenui/web/comp/action-button/add.png +0 -0
- data/lib/ozdenui/web/comp/action-button.js +521 -0
- data/lib/ozdenui/web/comp/action-tab-bar.js +383 -0
- data/lib/ozdenui/web/comp/app-bar.js +237 -0
- data/lib/ozdenui/web/comp/badge.js +292 -0
- data/lib/ozdenui/web/comp/bottom-bar.js +555 -0
- data/lib/ozdenui/web/comp/breadcrumbs.js +524 -0
- data/lib/ozdenui/web/comp/canvas.js +652 -0
- data/lib/ozdenui/web/comp/chat-view.js +827 -0
- data/lib/ozdenui/web/comp/check-box.js +490 -0
- data/lib/ozdenui/web/comp/code-editor.js +965 -0
- data/lib/ozdenui/web/comp/color-picker.js +636 -0
- data/lib/ozdenui/web/comp/context-menu.js +951 -0
- data/lib/ozdenui/web/comp/currency-field.js +209 -0
- data/lib/ozdenui/web/comp/data-table/arrow.svg +2 -0
- data/lib/ozdenui/web/comp/data-table.js +937 -0
- data/lib/ozdenui/web/comp/date-picker.js +1055 -0
- data/lib/ozdenui/web/comp/dialog.js +992 -0
- data/lib/ozdenui/web/comp/email-field.js +65 -0
- data/lib/ozdenui/web/comp/file-picker.js +920 -0
- data/lib/ozdenui/web/comp/filters.js +807 -0
- data/lib/ozdenui/web/comp/form.js +602 -0
- data/lib/ozdenui/web/comp/full-screen-select/arrow.svg +2 -0
- data/lib/ozdenui/web/comp/full-screen-select/cancel.svg +2 -0
- data/lib/ozdenui/web/comp/full-screen-select.js +614 -0
- data/lib/ozdenui/web/comp/gauge.js +439 -0
- data/lib/ozdenui/web/comp/graph-box.js +3911 -0
- data/lib/ozdenui/web/comp/grid-group.js +185 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button/trash-red.png +0 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button/trash.png +0 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button.js +289 -0
- data/lib/ozdenui/web/comp/image-view.js +598 -0
- data/lib/ozdenui/web/comp/item-list.js +1740 -0
- data/lib/ozdenui/web/comp/json-editor.js +3221 -0
- data/lib/ozdenui/web/comp/json-view.js +597 -0
- data/lib/ozdenui/web/comp/label-editor.js +1140 -0
- data/lib/ozdenui/web/comp/left-menu/data-table.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/home.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/reports.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/setting.png +0 -0
- data/lib/ozdenui/web/comp/left-menu.js +548 -0
- data/lib/ozdenui/web/comp/line-progress-bar.js +343 -0
- data/lib/ozdenui/web/comp/loading-screen.js +413 -0
- data/lib/ozdenui/web/comp/log-view.js +530 -0
- data/lib/ozdenui/web/comp/login-page.js +685 -0
- data/lib/ozdenui/web/comp/markdown-view.js +1045 -0
- data/lib/ozdenui/web/comp/menu-bar.js +624 -0
- data/lib/ozdenui/web/comp/mini-graph-box.js +492 -0
- data/lib/ozdenui/web/comp/minimal-accent.js +208 -0
- data/lib/ozdenui/web/comp/notice.js +229 -0
- data/lib/ozdenui/web/comp/number-field.js +128 -0
- data/lib/ozdenui/web/comp/numeric-keyboard.js +298 -0
- data/lib/ozdenui/web/comp/page-control.js +762 -0
- data/lib/ozdenui/web/comp/page-header.js +191 -0
- data/lib/ozdenui/web/comp/password-field/hide-btn.png +0 -0
- data/lib/ozdenui/web/comp/password-field/hide-btn2.png +0 -0
- data/lib/ozdenui/web/comp/password-field/show-btn.png +0 -0
- data/lib/ozdenui/web/comp/password-field/show-btn2.png +0 -0
- data/lib/ozdenui/web/comp/password-field.js +192 -0
- data/lib/ozdenui/web/comp/period-bar.js +436 -0
- data/lib/ozdenui/web/comp/phone-field.js +322 -0
- data/lib/ozdenui/web/comp/progress-bar.js +992 -0
- data/lib/ozdenui/web/comp/property-panel.js +3639 -0
- data/lib/ozdenui/web/comp/radio-button.js +527 -0
- data/lib/ozdenui/web/comp/range-slider.js +569 -0
- data/lib/ozdenui/web/comp/rich-text-editor.js +1064 -0
- data/lib/ozdenui/web/comp/scroll-area.js +308 -0
- data/lib/ozdenui/web/comp/scrolling-text.js +297 -0
- data/lib/ozdenui/web/comp/search-input/clear-round.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/clear.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/filter.png +0 -0
- data/lib/ozdenui/web/comp/search-input/filter.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/search.svg +1 -0
- data/lib/ozdenui/web/comp/search-input.js +725 -0
- data/lib/ozdenui/web/comp/search-results.js +596 -0
- data/lib/ozdenui/web/comp/select-box.js +1862 -0
- data/lib/ozdenui/web/comp/settings-row.js +299 -0
- data/lib/ozdenui/web/comp/side-panel.js +616 -0
- data/lib/ozdenui/web/comp/slider-field.js +952 -0
- data/lib/ozdenui/web/comp/slider.js +838 -0
- data/lib/ozdenui/web/comp/smart-button/alert-black.png +0 -0
- data/lib/ozdenui/web/comp/smart-button/clock.png +0 -0
- data/lib/ozdenui/web/comp/smart-button.js +981 -0
- data/lib/ozdenui/web/comp/smart-table/clock.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/down.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/scroll.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/sort.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/up.png +0 -0
- data/lib/ozdenui/web/comp/smart-table.js +1883 -0
- data/lib/ozdenui/web/comp/sortable-list.js +1181 -0
- data/lib/ozdenui/web/comp/spark-line-box.js +738 -0
- data/lib/ozdenui/web/comp/splitter.js +411 -0
- data/lib/ozdenui/web/comp/status-bar.js +408 -0
- data/lib/ozdenui/web/comp/step-bar.js +345 -0
- data/lib/ozdenui/web/comp/stepper.js +753 -0
- data/lib/ozdenui/web/comp/tabs.js +1366 -0
- data/lib/ozdenui/web/comp/tag-input.js +1107 -0
- data/lib/ozdenui/web/comp/tap-effect.js +170 -0
- data/lib/ozdenui/web/comp/text-area-field.js +233 -0
- data/lib/ozdenui/web/comp/text-field.js +1006 -0
- data/lib/ozdenui/web/comp/time-line.js +398 -0
- data/lib/ozdenui/web/comp/time-picker.js +1032 -0
- data/lib/ozdenui/web/comp/tiny-select/arrow.svg +1 -0
- data/lib/ozdenui/web/comp/tiny-select.js +322 -0
- data/lib/ozdenui/web/comp/tiny-table.js +283 -0
- data/lib/ozdenui/web/comp/toast.js +891 -0
- data/lib/ozdenui/web/comp/toggle.js +757 -0
- data/lib/ozdenui/web/comp/tool-bar.js +760 -0
- data/lib/ozdenui/web/comp/tooltip.js +534 -0
- data/lib/ozdenui/web/comp/tree-view.js +1179 -0
- data/lib/ozdenui/web/comp/ui-effects.js +1097 -0
- data/lib/ozdenui/web/comp/ui-standards.js +403 -0
- data/lib/ozdenui/web/comp/url-field.js +190 -0
- data/lib/ozdenui/web/comp/web-view.js +588 -0
- data/lib/ozdenui/web/components.js +123 -0
- data/lib/ozdenui/web/index.html +39 -0
- data/lib/ozdenui/window.rb +188 -0
- data/lib/ozdenui/window_cocoa.rb +221 -0
- data/lib/ozdenui.rb +32 -0
- metadata +200 -0
|
@@ -0,0 +1,1107 @@
|
|
|
1
|
+
/* Bismillah */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
Tag Input - v26.09
|
|
6
|
+
|
|
7
|
+
UI COMPONENT TEMPLATE
|
|
8
|
+
- A field that holds a list of small "chips" (tags, keywords, e-mail addresses, categories...).
|
|
9
|
+
- Type a text and press Enter (or a separator like ",") to add a tag. The tags are shown as chips with a remove (x) button.
|
|
10
|
+
- Suggestions: a list of known tags is shown under the field while typing. (ArrowUp / ArrowDown, Enter, mouse)
|
|
11
|
+
allowCustom: 0 -> Only the suggestions can be added (Ex: fixed categories).
|
|
12
|
+
- Rules: unique (case-insensitive), maxTags, minLength / maxLength, lowercase, and a custom validate() function.
|
|
13
|
+
A rejected tag shakes the field, shows the reason under it and calls onReject.
|
|
14
|
+
- Paste: "audio, guide; sale" is split into tags with the separators.
|
|
15
|
+
- Keyboard: Enter / separator adds. Backspace on an empty input selects the last chip, Backspace again removes it.
|
|
16
|
+
ArrowLeft / ArrowRight move between the chips, Delete removes the selected chip. Escape closes the suggestions.
|
|
17
|
+
- Counter: "3 / 5" when there is a maxTags limit.
|
|
18
|
+
- Accessibility: The chips have role="listitem" and aria-labels, the suggestion list is a listbox.
|
|
19
|
+
- Style packages: "light" (default; the old name "classic" works too), "modern", "dark", "minimal", "minimalDark".
|
|
20
|
+
Select with styleName. (TagInput.styles)
|
|
21
|
+
- Everything is drawn with code (no image files needed).
|
|
22
|
+
|
|
23
|
+
USAGE:
|
|
24
|
+
const tags = TagInput({
|
|
25
|
+
width: 320,
|
|
26
|
+
tags: ["audio", "guide"],
|
|
27
|
+
suggestions: ["audio", "fitness", "guide", "sale", "home", "news"],
|
|
28
|
+
maxTags: 5,
|
|
29
|
+
onChange: (self) => println(self.getTags().join(", ")),
|
|
30
|
+
});
|
|
31
|
+
tags.addTag("sale"); // Returns 1 when added, 0 when rejected. onChange is called.
|
|
32
|
+
tags.setTags(["a", "b"], 1); // silent: onChange is not called
|
|
33
|
+
tags.removeTag("a");
|
|
34
|
+
TagInput({ allowCustom: 0, suggestions: ["Red", "Green", "Blue"], placeholder: "Pick a color" });
|
|
35
|
+
TagInput({ validate: (tag) => (/^\S+@\S+\.\S+$/.test(tag)) ? "" : "Not an e-mail address", placeholder: "Add an e-mail" });
|
|
36
|
+
TagInput({ styleName: "dark" });
|
|
37
|
+
|
|
38
|
+
Started Date: September 2026
|
|
39
|
+
Webpage: https://bug7a.github.io/js-components/
|
|
40
|
+
|
|
41
|
+
Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
|
|
42
|
+
Licensed under the Apache License, Version 2.0
|
|
43
|
+
SPDX-License-Identifier: Apache-2.0
|
|
44
|
+
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
"use strict";
|
|
48
|
+
|
|
49
|
+
// Default values:
|
|
50
|
+
const TagInputDefaults = {
|
|
51
|
+
key: "0",
|
|
52
|
+
width: 320,
|
|
53
|
+
height: "auto",
|
|
54
|
+
tags: [], // ["audio", "guide"]
|
|
55
|
+
suggestions: [], // ["audio", "fitness", ...] Shown while typing. (Tags that are already added are hidden.)
|
|
56
|
+
allowCustom: 1, // 0: Only the suggestions can be added.
|
|
57
|
+
showSuggestionsOnFocus: 0, // 1: The suggestion list opens also when the input is empty.
|
|
58
|
+
maxSuggestions: 8,
|
|
59
|
+
maxTags: 0, // 0: No limit
|
|
60
|
+
minLength: 1,
|
|
61
|
+
maxLength: 32,
|
|
62
|
+
lowercase: 0, // 1: "Audio" -> "audio"
|
|
63
|
+
separators: ",", // Characters that end a tag while typing and when a text is pasted. (Enter always works.)
|
|
64
|
+
placeholder: "Add a tag...",
|
|
65
|
+
emptyText: "No suggestions", // Suggestion list, when the typed text does not match. (allowCustom: 0)
|
|
66
|
+
enabled: 1,
|
|
67
|
+
ariaLabel: "Tags",
|
|
68
|
+
validate: function (tag, self) { return ""; }, // Returns an error text, or "" when the tag is ok.
|
|
69
|
+
onChange: function (self) { }, // self.getTags()
|
|
70
|
+
onAdd: function (self, tag) { },
|
|
71
|
+
onRemove: function (self, tag) { },
|
|
72
|
+
onReject: function (self, tag, reason) { }, // reason: "duplicate", "max", "short", "long", "notAllowed", "invalid" (or the validate() text)
|
|
73
|
+
messages: {
|
|
74
|
+
duplicate: "\"{tag}\" is already added.",
|
|
75
|
+
max: "You can add up to {max} tags.",
|
|
76
|
+
short: "A tag needs at least {min} characters.",
|
|
77
|
+
long: "A tag can have up to {max} characters.",
|
|
78
|
+
notAllowed: "Choose a tag from the list.",
|
|
79
|
+
},
|
|
80
|
+
styleName: "light", // "light" ("classic": its old name), "modern", "dark", "minimal", "minimalDark" or a name added to TagInput.styles
|
|
81
|
+
style: { // Light style package (default)
|
|
82
|
+
field: {
|
|
83
|
+
color: White(1),
|
|
84
|
+
border: 1,
|
|
85
|
+
borderColor: Black(0.2),
|
|
86
|
+
round: 6,
|
|
87
|
+
padding: [8, 6], // [x, y]
|
|
88
|
+
gap: 6,
|
|
89
|
+
minHeight: 44,
|
|
90
|
+
},
|
|
91
|
+
fieldHover: {
|
|
92
|
+
borderColor: Black(0.5),
|
|
93
|
+
},
|
|
94
|
+
fieldFocus: {
|
|
95
|
+
borderColor: "#141414",
|
|
96
|
+
},
|
|
97
|
+
fieldError: {
|
|
98
|
+
borderColor: "#D64545",
|
|
99
|
+
},
|
|
100
|
+
input: {
|
|
101
|
+
fontSize: 15,
|
|
102
|
+
textColor: Black(0.85),
|
|
103
|
+
minWidth: 90,
|
|
104
|
+
height: 28,
|
|
105
|
+
},
|
|
106
|
+
placeholder: {
|
|
107
|
+
textColor: Black(0.4),
|
|
108
|
+
},
|
|
109
|
+
tag: {
|
|
110
|
+
color: Black(0.07),
|
|
111
|
+
border: 0,
|
|
112
|
+
borderColor: "transparent",
|
|
113
|
+
round: 5,
|
|
114
|
+
padding: [8, 0],
|
|
115
|
+
height: 28,
|
|
116
|
+
gap: 4,
|
|
117
|
+
},
|
|
118
|
+
tagHover: {
|
|
119
|
+
color: Black(0.12),
|
|
120
|
+
},
|
|
121
|
+
tagSelected: { // Selected with the keyboard (Backspace, arrows)
|
|
122
|
+
color: "#141414",
|
|
123
|
+
textColor: White(1),
|
|
124
|
+
removeColor: White(0.8),
|
|
125
|
+
},
|
|
126
|
+
tagText: {
|
|
127
|
+
fontSize: 13,
|
|
128
|
+
textColor: Black(0.85),
|
|
129
|
+
},
|
|
130
|
+
tagRemove: {
|
|
131
|
+
color: Black(0.45),
|
|
132
|
+
hoverColor: "#D64545",
|
|
133
|
+
},
|
|
134
|
+
panel: { // Suggestion list
|
|
135
|
+
color: White(1),
|
|
136
|
+
border: 1,
|
|
137
|
+
borderColor: Black(0.12),
|
|
138
|
+
round: 8,
|
|
139
|
+
padding: 4,
|
|
140
|
+
shadow: "0 8px 24px rgba(0, 0, 0, 0.12)",
|
|
141
|
+
maxHeight: 240,
|
|
142
|
+
},
|
|
143
|
+
option: {
|
|
144
|
+
fontSize: 14,
|
|
145
|
+
textColor: Black(0.85),
|
|
146
|
+
round: 5,
|
|
147
|
+
padding: [10, 7],
|
|
148
|
+
},
|
|
149
|
+
optionActive: {
|
|
150
|
+
color: Black(0.06),
|
|
151
|
+
},
|
|
152
|
+
highlight: { // The typed part of a suggestion
|
|
153
|
+
color: "rgba(255, 196, 0, 0.35)",
|
|
154
|
+
fontFamily: "", // "": the font of the option. Ex: "opensans-bold"
|
|
155
|
+
},
|
|
156
|
+
empty: {
|
|
157
|
+
fontSize: 13,
|
|
158
|
+
textColor: Black(0.45),
|
|
159
|
+
},
|
|
160
|
+
message: { // Error text under the field
|
|
161
|
+
fontSize: 12,
|
|
162
|
+
textColor: "#D64545",
|
|
163
|
+
},
|
|
164
|
+
counter: {
|
|
165
|
+
fontSize: 12,
|
|
166
|
+
textColor: Black(0.45),
|
|
167
|
+
},
|
|
168
|
+
disabled: {
|
|
169
|
+
opacity: 0.5,
|
|
170
|
+
},
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const TagInput = function (params = {}) {
|
|
175
|
+
|
|
176
|
+
// Merge style package: params.style > TagInput.styles[styleName] > TagInputDefaults.style (light)
|
|
177
|
+
basic.applyStylePackage(params, TagInput.styles, TagInputDefaults);
|
|
178
|
+
|
|
179
|
+
// Merge params:
|
|
180
|
+
mergeIntoIfMissing(params, TagInputDefaults);
|
|
181
|
+
|
|
182
|
+
// Edit params, if needed:
|
|
183
|
+
params.color = "transparent";
|
|
184
|
+
const startTags = params.tags;
|
|
185
|
+
params.tags = []; // Filled in the init code with the rules.
|
|
186
|
+
|
|
187
|
+
// BOX: Component container
|
|
188
|
+
let box = startObject(params);
|
|
189
|
+
|
|
190
|
+
// *** PRIVATE VARIABLES:
|
|
191
|
+
const _s = box.style;
|
|
192
|
+
const id = "tag-input-" + (TagInput._counter++);
|
|
193
|
+
let chips = []; // [{ tag, chip }]
|
|
194
|
+
let selectedIndex = -1; // Chip selected with the keyboard
|
|
195
|
+
let isOpen = 0; // Suggestion list
|
|
196
|
+
let isFocused = 0;
|
|
197
|
+
let filtered = []; // Suggestions in the list
|
|
198
|
+
let rows = []; // Rows in the list
|
|
199
|
+
let activeIndex = -1; // Active suggestion
|
|
200
|
+
let cancelMessage = null; // (box.after: the timers are stopped by remove())
|
|
201
|
+
let cancelError = null;
|
|
202
|
+
let isRendering = 0;
|
|
203
|
+
const MESSAGE_DURATION = 2500; // ms: the reject message is shown
|
|
204
|
+
const SHAKE_END_DELAY = 350; // ms: a little longer than the "tagInputShake 0.3s" animation
|
|
205
|
+
const PANEL_SPACE = 4; // Between the field and the panel
|
|
206
|
+
const PAGE_MARGIN = 8; // The panel stays this far from the edges of the page
|
|
207
|
+
const MIN_PANEL_WIDTH = 160;
|
|
208
|
+
const MIN_LIST_HEIGHT = 60; // When the list is made shorter to fit the page
|
|
209
|
+
const PANEL_Z_INDEX = 1001; // the panel on the page, over the content (over a Dialog that holds the field: at open)
|
|
210
|
+
|
|
211
|
+
// *** PUBLIC VARIABLES:
|
|
212
|
+
// NOTE: Default values are also public variables. (box.tags, box.suggestions, box.maxTags)
|
|
213
|
+
|
|
214
|
+
// *** PRIVATE FUNCTIONS:
|
|
215
|
+
|
|
216
|
+
const normalize = function (tag) {
|
|
217
|
+
tag = String(tag ?? "").trim().replace(/\s+/g, " ");
|
|
218
|
+
if (box.lowercase == 1) tag = tag.toLocaleLowerCase();
|
|
219
|
+
return tag;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const isSame = function (a, b) {
|
|
223
|
+
return a.toLocaleLowerCase() === b.toLocaleLowerCase();
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
const hasTag = function (tag) {
|
|
227
|
+
return box.tags.some(function (t) { return isSame(t, tag); });
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// "{tag} is added" + { tag: "audio" } -> "audio is added". (An unknown {key} stays as it is.)
|
|
231
|
+
const format = function (text, values) {
|
|
232
|
+
return String(text).replace(/\{(\w+)\}/g, function (match, key) {
|
|
233
|
+
return (values[key] !== undefined) ? values[key] : match;
|
|
234
|
+
});
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
// Splits a text with the separators. "a, b;c" -> ["a", "b", "c"]
|
|
238
|
+
const split = function (text) {
|
|
239
|
+
const chars = String(box.separators || "");
|
|
240
|
+
let parts = [text];
|
|
241
|
+
if (chars) {
|
|
242
|
+
const escapedChars = chars.replace(/[\]\\^-]/g, "\\$&");
|
|
243
|
+
parts = text.split(new RegExp("[" + escapedChars + "\\n\\r]"));
|
|
244
|
+
}
|
|
245
|
+
return parts.map(normalize).filter(Boolean);
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const isSuggestion = function (tag) {
|
|
249
|
+
return box.suggestions.some(function (suggestion) { return isSame(suggestion, tag); });
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
// Returns "" when the tag can be added, or the reject reason.
|
|
253
|
+
const check = function (tag) {
|
|
254
|
+
if (box.maxTags > 0 && box.tags.length >= box.maxTags) return "max";
|
|
255
|
+
if (tag.length < box.minLength) return "short";
|
|
256
|
+
if (box.maxLength > 0 && tag.length > box.maxLength) return "long";
|
|
257
|
+
if (hasTag(tag)) return "duplicate";
|
|
258
|
+
if (box.allowCustom != 1 && !isSuggestion(tag)) return "notAllowed";
|
|
259
|
+
const custom = box.validate(tag, box);
|
|
260
|
+
if (custom) return String(custom);
|
|
261
|
+
return "";
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
const getMessage = function (reason, tag) {
|
|
265
|
+
const text = box.messages[reason] || reason; // A custom validate() text is shown as it is.
|
|
266
|
+
return format(text, {
|
|
267
|
+
tag: tag,
|
|
268
|
+
max: (reason == "long") ? box.maxLength : box.maxTags,
|
|
269
|
+
min: box.minLength,
|
|
270
|
+
});
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// Creates objects in a container again, in one wrapper group.
|
|
274
|
+
// WHY: createIn() puts the default container back after it (also on an error).
|
|
275
|
+
const renderInto = function (container, buildContent) {
|
|
276
|
+
if (container.wrapper) container.wrapper.remove();
|
|
277
|
+
container.wrapper = createIn(container, function () {
|
|
278
|
+
const wrapper = VGroup({ width: "100%", height: "auto", align: "left top", gap: 0, position: "relative" });
|
|
279
|
+
wrapper.css.alignItems = "stretch";
|
|
280
|
+
buildContent();
|
|
281
|
+
endGroup();
|
|
282
|
+
return wrapper;
|
|
283
|
+
});
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
const updateFieldBorder = function () {
|
|
287
|
+
if (box.messageLabel.visible == 1) {
|
|
288
|
+
box.field.borderColor = _s.fieldError.borderColor;
|
|
289
|
+
} else if (isFocused) {
|
|
290
|
+
box.field.borderColor = _s.fieldFocus.borderColor;
|
|
291
|
+
} else {
|
|
292
|
+
box.field.borderColor = _s.field.borderColor;
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
const updateCounter = function () {
|
|
297
|
+
if (box.maxTags > 0) {
|
|
298
|
+
box.counterLabel.text = box.tags.length + " / " + box.maxTags;
|
|
299
|
+
box.counterLabel.visible = 1;
|
|
300
|
+
} else {
|
|
301
|
+
box.counterLabel.visible = 0;
|
|
302
|
+
}
|
|
303
|
+
box.bottomRow.visible = (box.counterLabel.visible == 1 || box.messageLabel.visible == 1) ? 1 : 0;
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
const showMessage = function (text) {
|
|
307
|
+
if (cancelMessage) cancelMessage();
|
|
308
|
+
if (cancelError) cancelError();
|
|
309
|
+
box.messageLabel.plainText = text;
|
|
310
|
+
box.messageLabel.visible = 1;
|
|
311
|
+
updateCounter();
|
|
312
|
+
updateFieldBorder();
|
|
313
|
+
shakeField();
|
|
314
|
+
cancelMessage = box.after(MESSAGE_DURATION, hideMessage);
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
const shakeField = function () {
|
|
318
|
+
box.field.css.animation = "none";
|
|
319
|
+
box.field.elem.offsetWidth; // WHY: Restart the animation.
|
|
320
|
+
box.field.css.animation = "tagInputShake 0.3s";
|
|
321
|
+
cancelError = box.after(SHAKE_END_DELAY, function () {
|
|
322
|
+
cancelError = null;
|
|
323
|
+
box.field.css.animation = "none";
|
|
324
|
+
});
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
const hideMessage = function () {
|
|
328
|
+
if (cancelMessage) cancelMessage();
|
|
329
|
+
cancelMessage = null;
|
|
330
|
+
box.messageLabel.visible = 0;
|
|
331
|
+
updateCounter();
|
|
332
|
+
updateFieldBorder();
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
const updateInputPlaceholder = function () {
|
|
336
|
+
const full = (box.maxTags > 0 && box.tags.length >= box.maxTags);
|
|
337
|
+
box.input.inputElement.placeholder = (full || box.tags.length) ? "" : box.placeholder;
|
|
338
|
+
box.input.inputElement.setAttribute("aria-label", box.placeholder || box.ariaLabel);
|
|
339
|
+
// WHY: A hidden input can not be focused. It is only small when the field is full.
|
|
340
|
+
box.input.css = {
|
|
341
|
+
flex: (full) ? "0 0 10px" : "1 1 " + _s.input.minWidth + "px",
|
|
342
|
+
minWidth: (full) ? "10px" : _s.input.minWidth + "px",
|
|
343
|
+
};
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
const paintChip = function (item, index) {
|
|
347
|
+
const selected = (index === selectedIndex);
|
|
348
|
+
item.chip.color = (selected) ? _s.tagSelected.color : _s.tag.color;
|
|
349
|
+
item.chip.borderColor = (selected) ? _s.tagSelected.color : _s.tag.borderColor;
|
|
350
|
+
item.label.textColor = (selected) ? _s.tagSelected.textColor : _s.tagText.textColor;
|
|
351
|
+
item.remove.text = TagInput.getCloseSvg((selected) ? _s.tagSelected.removeColor : _s.tagRemove.color);
|
|
352
|
+
item.chip.aria = { selected: (selected) ? "true" : "false" };
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
const paintChips = function () {
|
|
356
|
+
chips.forEach(paintChip);
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
// One chip: a tag text and a remove (x) button. Its container must be set. (createIn)
|
|
360
|
+
const createChip = function (tag) {
|
|
361
|
+
|
|
362
|
+
// GROUP: Chip
|
|
363
|
+
const chip = HGroup({
|
|
364
|
+
width: "auto",
|
|
365
|
+
height: _s.tag.height,
|
|
366
|
+
align: "left center",
|
|
367
|
+
gap: _s.tag.gap,
|
|
368
|
+
padding: _s.tag.padding,
|
|
369
|
+
color: _s.tag.color,
|
|
370
|
+
border: _s.tag.border,
|
|
371
|
+
borderColor: _s.tag.borderColor,
|
|
372
|
+
round: _s.tag.round,
|
|
373
|
+
clickable: 1,
|
|
374
|
+
});
|
|
375
|
+
chip.shrink = 0;
|
|
376
|
+
chip.css = { maxWidth: "100%", transition: "background-color 0.15s" };
|
|
377
|
+
chip.role = "listitem";
|
|
378
|
+
chip.aria = { label: tag };
|
|
379
|
+
chip.elem.title = tag;
|
|
380
|
+
|
|
381
|
+
// LABEL: Tag text
|
|
382
|
+
const label = Label({ plainText: tag, fontSize: _s.tagText.fontSize, textColor: _s.tagText.textColor });
|
|
383
|
+
label.ellipsis = 1;
|
|
384
|
+
label.css.minWidth = "0";
|
|
385
|
+
|
|
386
|
+
// LABEL: Remove (x)
|
|
387
|
+
const remove = Label({ text: TagInput.getCloseSvg(_s.tagRemove.color), width: 14, height: 14, clickable: 1 });
|
|
388
|
+
remove.lineHeight = "0";
|
|
389
|
+
remove.shrink = 0;
|
|
390
|
+
remove.cursor = "pointer";
|
|
391
|
+
remove.css.borderRadius = "3px";
|
|
392
|
+
remove.role = "button";
|
|
393
|
+
remove.aria = { label: "Remove " + tag };
|
|
394
|
+
|
|
395
|
+
endGroup();
|
|
396
|
+
|
|
397
|
+
return { tag: tag, chip: chip, label: label, remove: remove };
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
const bindChipEvents = function (item, index) {
|
|
401
|
+
item.chip.on("mouseenter", function () {
|
|
402
|
+
if (index !== selectedIndex) item.chip.color = _s.tagHover.color;
|
|
403
|
+
});
|
|
404
|
+
item.chip.on("mouseleave", function () { paintChip(item, index); });
|
|
405
|
+
item.chip.on("click", function (self, event) {
|
|
406
|
+
event.stopPropagation();
|
|
407
|
+
selectedIndex = index;
|
|
408
|
+
paintChips();
|
|
409
|
+
box.input.inputElement.focus({ preventScroll: true });
|
|
410
|
+
});
|
|
411
|
+
item.remove.on("mouseenter", function () {
|
|
412
|
+
item.remove.text = TagInput.getCloseSvg(_s.tagRemove.hoverColor);
|
|
413
|
+
});
|
|
414
|
+
item.remove.on("mouseleave", function () { paintChip(item, index); });
|
|
415
|
+
item.remove.on("click", function (self, event) {
|
|
416
|
+
event.stopPropagation();
|
|
417
|
+
if (box.enabled != 1) return;
|
|
418
|
+
box.removeTag(item.tag);
|
|
419
|
+
box.input.inputElement.focus({ preventScroll: true });
|
|
420
|
+
});
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
// Draws the chips in the field. (The input stays at the end.)
|
|
424
|
+
const renderChips = function () {
|
|
425
|
+
|
|
426
|
+
if (isRendering) return;
|
|
427
|
+
isRendering = 1;
|
|
428
|
+
|
|
429
|
+
chips.forEach(function (item) { item.chip.remove(); });
|
|
430
|
+
chips = [];
|
|
431
|
+
|
|
432
|
+
box.tags.forEach(function (tag, index) {
|
|
433
|
+
const item = createIn(box.field, function () { return createChip(tag); });
|
|
434
|
+
chips.push(item);
|
|
435
|
+
// WHY: The order of the chips is fixed, but the input must stay as the last child of the field.
|
|
436
|
+
box.field.elem.insertBefore(item.chip.elem, box.input.elem);
|
|
437
|
+
bindChipEvents(item, index);
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
isRendering = 0;
|
|
441
|
+
|
|
442
|
+
paintChips();
|
|
443
|
+
updateInputPlaceholder();
|
|
444
|
+
updateCounter();
|
|
445
|
+
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
const getFilteredSuggestions = function () {
|
|
449
|
+
const text = box.input.text.trim().toLocaleLowerCase();
|
|
450
|
+
const list = box.suggestions.filter(function (s) {
|
|
451
|
+
if (hasTag(s)) return false;
|
|
452
|
+
return (!text) || s.toLocaleLowerCase().includes(text);
|
|
453
|
+
});
|
|
454
|
+
const startsWithText = function (suggestion) {
|
|
455
|
+
return Number(suggestion.toLocaleLowerCase().startsWith(text));
|
|
456
|
+
};
|
|
457
|
+
// Suggestions that start with the text come first.
|
|
458
|
+
if (text) list.sort(function (a, b) { return startsWithText(b) - startsWithText(a); });
|
|
459
|
+
return list.slice(0, box.maxSuggestions);
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
// Label with the typed text highlighted (safe HTML)
|
|
463
|
+
const highlight = function (label) {
|
|
464
|
+
const text = box.input.text.trim();
|
|
465
|
+
const escaped = TagInput.escapeHtml(label);
|
|
466
|
+
if (!text) return escaped;
|
|
467
|
+
const index = label.toLocaleLowerCase().indexOf(text.toLocaleLowerCase());
|
|
468
|
+
if (index < 0) return escaped;
|
|
469
|
+
const before = TagInput.escapeHtml(label.slice(0, index));
|
|
470
|
+
const match = TagInput.escapeHtml(label.slice(index, index + text.length));
|
|
471
|
+
const after = TagInput.escapeHtml(label.slice(index + text.length));
|
|
472
|
+
let markStyle = "background:" + _s.highlight.color + "; color: inherit; border-radius: 3px";
|
|
473
|
+
if (_s.highlight.fontFamily) markStyle += "; font-family: " + _s.highlight.fontFamily;
|
|
474
|
+
return before + "<mark style='" + markStyle + "'>" + match + "</mark>" + after;
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
const paintRows = function () {
|
|
478
|
+
rows.forEach(function (row, index) {
|
|
479
|
+
row.color = (index === activeIndex) ? _s.optionActive.color : "transparent";
|
|
480
|
+
row.aria = { selected: (index === activeIndex) ? "true" : "false" };
|
|
481
|
+
});
|
|
482
|
+
const active = rows[activeIndex];
|
|
483
|
+
if (active) {
|
|
484
|
+
box.input.inputElement.setAttribute("aria-activedescendant", active.elem.id);
|
|
485
|
+
active.elem.scrollIntoView({ block: "nearest" });
|
|
486
|
+
} else {
|
|
487
|
+
box.input.inputElement.removeAttribute("aria-activedescendant");
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
const renderList = function () {
|
|
492
|
+
|
|
493
|
+
filtered = getFilteredSuggestions();
|
|
494
|
+
rows = [];
|
|
495
|
+
// WHY: With allowCustom: 0 the first suggestion is active, so Enter adds it. With custom tags, Enter adds the typed text.
|
|
496
|
+
activeIndex = (filtered.length && box.allowCustom != 1) ? 0 : -1;
|
|
497
|
+
|
|
498
|
+
renderInto(box.list, function () {
|
|
499
|
+
|
|
500
|
+
if (!filtered.length) {
|
|
501
|
+
Label({ plainText: box.emptyText, fontSize: _s.empty.fontSize, textColor: _s.empty.textColor, padding: [10, 8] });
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
filtered.forEach(function (suggestion, index) {
|
|
506
|
+
const row = HGroup({
|
|
507
|
+
width: "100%",
|
|
508
|
+
height: "auto",
|
|
509
|
+
align: "left center",
|
|
510
|
+
padding: _s.option.padding,
|
|
511
|
+
round: _s.option.round,
|
|
512
|
+
clickable: 1,
|
|
513
|
+
});
|
|
514
|
+
row.elem.id = id + "-option-" + index;
|
|
515
|
+
row.role = "option";
|
|
516
|
+
row.cursor = "pointer";
|
|
517
|
+
row.shrink = 0;
|
|
518
|
+
const lblOption = Label({ text: highlight(suggestion), fontSize: _s.option.fontSize, textColor: _s.option.textColor });
|
|
519
|
+
lblOption.ellipsis = 1;
|
|
520
|
+
lblOption.css.maxWidth = "100%";
|
|
521
|
+
endGroup();
|
|
522
|
+
rows.push(row);
|
|
523
|
+
row.on("mouseenter", function () {
|
|
524
|
+
activeIndex = index;
|
|
525
|
+
paintRows();
|
|
526
|
+
});
|
|
527
|
+
row.on("click", function () {
|
|
528
|
+
addFromInput(suggestion);
|
|
529
|
+
box.input.inputElement.focus({ preventScroll: true });
|
|
530
|
+
});
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
paintRows();
|
|
536
|
+
|
|
537
|
+
};
|
|
538
|
+
|
|
539
|
+
const positionPanel = function () {
|
|
540
|
+
|
|
541
|
+
const rect = box.field.elem.getBoundingClientRect();
|
|
542
|
+
const width = Math.max(withPageZoom(rect.width), MIN_PANEL_WIDTH);
|
|
543
|
+
|
|
544
|
+
box.panel.width = width;
|
|
545
|
+
box.list.css.maxHeight = _s.panel.maxHeight + "px";
|
|
546
|
+
|
|
547
|
+
const panelHeight = box.panel.elem.offsetHeight;
|
|
548
|
+
const below = page.height - withPageZoom(rect.bottom) - PANEL_SPACE - PAGE_MARGIN;
|
|
549
|
+
const above = withPageZoom(rect.top) - PANEL_SPACE - PAGE_MARGIN;
|
|
550
|
+
const shortenList = function (extra) {
|
|
551
|
+
box.list.css.maxHeight = Math.max(MIN_LIST_HEIGHT, _s.panel.maxHeight - extra) + "px";
|
|
552
|
+
};
|
|
553
|
+
|
|
554
|
+
let top = withPageZoom(rect.bottom) + PANEL_SPACE;
|
|
555
|
+
if (panelHeight > below && above > below) {
|
|
556
|
+
const extra = panelHeight - above;
|
|
557
|
+
if (extra > 0) shortenList(extra);
|
|
558
|
+
top = withPageZoom(rect.top) - box.panel.elem.offsetHeight - PANEL_SPACE;
|
|
559
|
+
} else if (panelHeight > below) {
|
|
560
|
+
shortenList(panelHeight - below);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
let left = withPageZoom(rect.left);
|
|
564
|
+
left = Math.max(PAGE_MARGIN, Math.min(left, page.width - width - PAGE_MARGIN));
|
|
565
|
+
|
|
566
|
+
box.panel.left = left;
|
|
567
|
+
box.panel.top = Math.max(PAGE_MARGIN, top);
|
|
568
|
+
|
|
569
|
+
};
|
|
570
|
+
|
|
571
|
+
const openPanel = function () {
|
|
572
|
+
if (box.enabled != 1) return;
|
|
573
|
+
const text = box.input.text.trim();
|
|
574
|
+
// No list when there is nothing to show.
|
|
575
|
+
if (!box.suggestions.length) return closePanel();
|
|
576
|
+
if (!text && box.showSuggestionsOnFocus != 1 && box.allowCustom == 1) return closePanel();
|
|
577
|
+
renderList();
|
|
578
|
+
if (!filtered.length && box.allowCustom == 1) return closePanel(); // Custom tags: an empty list is not useful.
|
|
579
|
+
if (!isOpen) {
|
|
580
|
+
isOpen = 1;
|
|
581
|
+
box.panel.zIndex = basic.zIndexAbove(box, PANEL_Z_INDEX); // WHY: over a Dialog that holds the field
|
|
582
|
+
box.panel.visible = 1;
|
|
583
|
+
box.input.inputElement.setAttribute("aria-expanded", "true");
|
|
584
|
+
}
|
|
585
|
+
positionPanel();
|
|
586
|
+
};
|
|
587
|
+
|
|
588
|
+
const closePanel = function () {
|
|
589
|
+
if (!isOpen) return;
|
|
590
|
+
isOpen = 0;
|
|
591
|
+
box.panel.visible = 0;
|
|
592
|
+
activeIndex = -1;
|
|
593
|
+
box.input.inputElement.setAttribute("aria-expanded", "false");
|
|
594
|
+
box.input.inputElement.removeAttribute("aria-activedescendant");
|
|
595
|
+
};
|
|
596
|
+
|
|
597
|
+
// Adds the typed text (or a suggestion) and clears the input.
|
|
598
|
+
const addFromInput = function (text) {
|
|
599
|
+
const value = (text !== undefined) ? text : box.input.text;
|
|
600
|
+
const parts = split(value);
|
|
601
|
+
if (!parts.length) {
|
|
602
|
+
box.input.text = "";
|
|
603
|
+
closePanel();
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
let added = 0;
|
|
607
|
+
parts.forEach(function (part) {
|
|
608
|
+
if (addOne(part, 0, 1)) added++;
|
|
609
|
+
});
|
|
610
|
+
box.input.text = "";
|
|
611
|
+
if (added) box.onChange(box);
|
|
612
|
+
closePanel();
|
|
613
|
+
if (box.showSuggestionsOnFocus == 1 || box.allowCustom != 1) openPanel();
|
|
614
|
+
};
|
|
615
|
+
|
|
616
|
+
// Adds one tag. Returns 1 when added.
|
|
617
|
+
// silent: 1 -> onChange is not called. skipChange: 1 -> The caller calls onChange (for many tags at once).
|
|
618
|
+
const addOne = function (tag, silent, skipChange) {
|
|
619
|
+
tag = normalize(tag);
|
|
620
|
+
const reason = check(tag);
|
|
621
|
+
if (reason) {
|
|
622
|
+
if (!silent) {
|
|
623
|
+
showMessage(getMessage(reason, tag));
|
|
624
|
+
box.onReject(box, tag, reason);
|
|
625
|
+
}
|
|
626
|
+
return 0;
|
|
627
|
+
}
|
|
628
|
+
box.tags.push(tag);
|
|
629
|
+
selectedIndex = -1;
|
|
630
|
+
renderChips();
|
|
631
|
+
hideMessage();
|
|
632
|
+
if (!silent) {
|
|
633
|
+
box.onAdd(box, tag);
|
|
634
|
+
if (!skipChange) box.onChange(box);
|
|
635
|
+
}
|
|
636
|
+
return 1;
|
|
637
|
+
};
|
|
638
|
+
|
|
639
|
+
// ArrowDown on a closed list: it opens with the first suggestion active.
|
|
640
|
+
const openPanelWithFirstActive = function () {
|
|
641
|
+
openPanel();
|
|
642
|
+
if (!isOpen || activeIndex >= 0 || !rows.length) return;
|
|
643
|
+
activeIndex = 0;
|
|
644
|
+
paintRows();
|
|
645
|
+
};
|
|
646
|
+
|
|
647
|
+
const unselectChip = function () {
|
|
648
|
+
selectedIndex = -1;
|
|
649
|
+
paintChips();
|
|
650
|
+
};
|
|
651
|
+
|
|
652
|
+
const onKeyDown = function (self, event) {
|
|
653
|
+
|
|
654
|
+
if (box.enabled != 1) return;
|
|
655
|
+
const key = event.key;
|
|
656
|
+
const text = box.input.text;
|
|
657
|
+
const cursorAtStart = (box.input.inputElement.selectionStart === 0 && box.input.inputElement.selectionEnd === 0);
|
|
658
|
+
|
|
659
|
+
// Separator characters add the tag. (Ex: ",")
|
|
660
|
+
if (key.length === 1 && String(box.separators || "").includes(key)) {
|
|
661
|
+
event.preventDefault();
|
|
662
|
+
addFromInput();
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
switch (key) {
|
|
667
|
+
case "Enter":
|
|
668
|
+
event.preventDefault();
|
|
669
|
+
if (isOpen && activeIndex >= 0 && filtered[activeIndex] !== undefined) {
|
|
670
|
+
addFromInput(filtered[activeIndex]);
|
|
671
|
+
} else if (text.trim()) {
|
|
672
|
+
addFromInput();
|
|
673
|
+
} else {
|
|
674
|
+
closePanel();
|
|
675
|
+
}
|
|
676
|
+
break;
|
|
677
|
+
case "ArrowDown":
|
|
678
|
+
if (!isOpen) {
|
|
679
|
+
openPanelWithFirstActive();
|
|
680
|
+
event.preventDefault();
|
|
681
|
+
break;
|
|
682
|
+
}
|
|
683
|
+
event.preventDefault();
|
|
684
|
+
activeIndex = (rows.length) ? (activeIndex + 1) % rows.length : -1;
|
|
685
|
+
paintRows();
|
|
686
|
+
break;
|
|
687
|
+
case "ArrowUp":
|
|
688
|
+
if (!isOpen) break;
|
|
689
|
+
event.preventDefault();
|
|
690
|
+
activeIndex = (rows.length) ? (activeIndex - 1 + rows.length) % rows.length : -1;
|
|
691
|
+
paintRows();
|
|
692
|
+
break;
|
|
693
|
+
case "Escape":
|
|
694
|
+
if (isOpen) {
|
|
695
|
+
event.preventDefault();
|
|
696
|
+
closePanel();
|
|
697
|
+
} else if (selectedIndex >= 0) {
|
|
698
|
+
unselectChip();
|
|
699
|
+
}
|
|
700
|
+
break;
|
|
701
|
+
case "Backspace":
|
|
702
|
+
if (text) break;
|
|
703
|
+
event.preventDefault();
|
|
704
|
+
if (selectedIndex >= 0) {
|
|
705
|
+
box.removeTag(box.tags[selectedIndex]);
|
|
706
|
+
} else if (box.tags.length) {
|
|
707
|
+
selectedIndex = box.tags.length - 1; // First press: select the last chip
|
|
708
|
+
paintChips();
|
|
709
|
+
}
|
|
710
|
+
break;
|
|
711
|
+
case "Delete":
|
|
712
|
+
if (text || selectedIndex < 0) break;
|
|
713
|
+
event.preventDefault();
|
|
714
|
+
box.removeTag(box.tags[selectedIndex]);
|
|
715
|
+
break;
|
|
716
|
+
case "ArrowLeft":
|
|
717
|
+
if (!cursorAtStart || !box.tags.length) break;
|
|
718
|
+
event.preventDefault();
|
|
719
|
+
selectedIndex = (selectedIndex < 0) ? box.tags.length - 1 : Math.max(0, selectedIndex - 1);
|
|
720
|
+
paintChips();
|
|
721
|
+
break;
|
|
722
|
+
case "ArrowRight":
|
|
723
|
+
if (selectedIndex < 0) break;
|
|
724
|
+
event.preventDefault();
|
|
725
|
+
selectedIndex = (selectedIndex >= box.tags.length - 1) ? -1 : selectedIndex + 1;
|
|
726
|
+
paintChips();
|
|
727
|
+
break;
|
|
728
|
+
case "Tab":
|
|
729
|
+
// Typed text becomes a tag when the focus leaves with Tab. (allowCustom: 1)
|
|
730
|
+
if (text.trim() && box.allowCustom == 1) addFromInput();
|
|
731
|
+
closePanel();
|
|
732
|
+
break;
|
|
733
|
+
default:
|
|
734
|
+
if (selectedIndex >= 0 && key.length === 1) unselectChip();
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
};
|
|
738
|
+
|
|
739
|
+
const onPaste = function (event) {
|
|
740
|
+
if (box.enabled != 1) return;
|
|
741
|
+
const text = (event.clipboardData || window.clipboardData).getData("text");
|
|
742
|
+
if (split(text).length <= 1) return; // One tag: Normal paste into the input.
|
|
743
|
+
event.preventDefault();
|
|
744
|
+
addFromInput(box.input.text + text);
|
|
745
|
+
};
|
|
746
|
+
|
|
747
|
+
const onPageResize = function () {
|
|
748
|
+
if (isOpen) positionPanel();
|
|
749
|
+
};
|
|
750
|
+
|
|
751
|
+
// WHY: The panel is on the page, not in the scrolled container. It must follow the field.
|
|
752
|
+
const onAnyScroll = function (self, event) {
|
|
753
|
+
if (!isOpen || event.target === box.list.elem) return;
|
|
754
|
+
positionPanel();
|
|
755
|
+
};
|
|
756
|
+
|
|
757
|
+
const onDocumentPointerDown = function (self, event) {
|
|
758
|
+
if (!box) return;
|
|
759
|
+
if (box.elem.contains(event.target) || box.panel.elem.contains(event.target)) return;
|
|
760
|
+
closePanel();
|
|
761
|
+
};
|
|
762
|
+
|
|
763
|
+
// *** PUBLIC FUNCTIONS:
|
|
764
|
+
|
|
765
|
+
box.getTags = function () {
|
|
766
|
+
return box.tags.slice();
|
|
767
|
+
};
|
|
768
|
+
// USAGE: tagInput.getTags() // ["audio", "guide"]
|
|
769
|
+
|
|
770
|
+
box.addTag = function (tag, silent = 0) {
|
|
771
|
+
return addOne(tag, silent, 0);
|
|
772
|
+
};
|
|
773
|
+
// USAGE: tagInput.addTag("sale") // 1: added, 0: rejected (the reason is shown under the field)
|
|
774
|
+
|
|
775
|
+
box.removeTag = function (tag, silent = 0) {
|
|
776
|
+
const index = box.tags.findIndex(function (t) { return isSame(t, String(tag)); });
|
|
777
|
+
if (index < 0) return 0;
|
|
778
|
+
const removed = box.tags.splice(index, 1)[0];
|
|
779
|
+
selectedIndex = -1;
|
|
780
|
+
renderChips();
|
|
781
|
+
if (isOpen) renderList(); // The removed tag can be a suggestion again.
|
|
782
|
+
if (!silent) {
|
|
783
|
+
box.onRemove(box, removed);
|
|
784
|
+
box.onChange(box);
|
|
785
|
+
}
|
|
786
|
+
return 1;
|
|
787
|
+
};
|
|
788
|
+
// USAGE: tagInput.removeTag("sale")
|
|
789
|
+
|
|
790
|
+
// Replaces all tags. The rules (unique, maxTags, validate...) are applied without messages.
|
|
791
|
+
box.setTags = function (tags, silent = 0) {
|
|
792
|
+
box.tags = [];
|
|
793
|
+
(tags || []).forEach(function (tag) { addOne(tag, 1, 1); });
|
|
794
|
+
selectedIndex = -1;
|
|
795
|
+
renderChips();
|
|
796
|
+
hideMessage();
|
|
797
|
+
if (isOpen) renderList();
|
|
798
|
+
if (!silent) box.onChange(box);
|
|
799
|
+
};
|
|
800
|
+
// USAGE: tagInput.setTags(["audio", "guide"]) // setTags([...], 1): onChange is not called
|
|
801
|
+
|
|
802
|
+
box.clear = function (silent = 0) {
|
|
803
|
+
box.setTags([], silent);
|
|
804
|
+
};
|
|
805
|
+
|
|
806
|
+
box.setSuggestions = function (suggestions) {
|
|
807
|
+
box.suggestions = (suggestions || []).map(normalize).filter(Boolean);
|
|
808
|
+
if (isOpen) openPanel();
|
|
809
|
+
};
|
|
810
|
+
// USAGE: tagInput.setSuggestions(["a", "b"])
|
|
811
|
+
|
|
812
|
+
box.setEnabled = function (enabled) {
|
|
813
|
+
box.enabled = basic.isOn(enabled) ? 1 : 0;
|
|
814
|
+
box.input.inputElement.disabled = (box.enabled != 1);
|
|
815
|
+
box.css = {
|
|
816
|
+
opacity: (box.enabled == 1) ? "1" : String(_s.disabled.opacity),
|
|
817
|
+
pointerEvents: (box.enabled == 1) ? "" : "none",
|
|
818
|
+
};
|
|
819
|
+
if (box.enabled != 1) closePanel();
|
|
820
|
+
};
|
|
821
|
+
// USAGE: get: tagInput.enabled, set: tagInput.setEnabled(0)
|
|
822
|
+
|
|
823
|
+
box.setPlaceholder = function (text) {
|
|
824
|
+
box.placeholder = text;
|
|
825
|
+
updateInputPlaceholder();
|
|
826
|
+
};
|
|
827
|
+
|
|
828
|
+
box.setMaxTags = function (max) {
|
|
829
|
+
box.maxTags = Math.max(0, Number(max) || 0);
|
|
830
|
+
updateInputPlaceholder();
|
|
831
|
+
updateCounter();
|
|
832
|
+
};
|
|
833
|
+
|
|
834
|
+
box.focus = function () {
|
|
835
|
+
box.input.inputElement.focus({ preventScroll: true });
|
|
836
|
+
};
|
|
837
|
+
|
|
838
|
+
box.blur = function () {
|
|
839
|
+
box.input.inputElement.blur();
|
|
840
|
+
};
|
|
841
|
+
|
|
842
|
+
|
|
843
|
+
// *** OBJECT VIEW:
|
|
844
|
+
TagInput.injectCss();
|
|
845
|
+
box.elem.style.setProperty("--tag-input-placeholder", _s.placeholder.textColor);
|
|
846
|
+
|
|
847
|
+
// GROUP: Field and bottom row
|
|
848
|
+
box.contentBox = VGroup({
|
|
849
|
+
width: "100%",
|
|
850
|
+
height: "auto",
|
|
851
|
+
align: "left top",
|
|
852
|
+
gap: 4,
|
|
853
|
+
position: "relative",
|
|
854
|
+
});
|
|
855
|
+
|
|
856
|
+
// GROUP: Field (chips + input). Wraps to new lines.
|
|
857
|
+
box.field = HGroup({
|
|
858
|
+
width: "100%",
|
|
859
|
+
height: "auto",
|
|
860
|
+
align: "left center",
|
|
861
|
+
gap: _s.field.gap,
|
|
862
|
+
padding: _s.field.padding,
|
|
863
|
+
color: _s.field.color,
|
|
864
|
+
border: _s.field.border,
|
|
865
|
+
borderColor: _s.field.borderColor,
|
|
866
|
+
round: _s.field.round,
|
|
867
|
+
clickable: 1,
|
|
868
|
+
});
|
|
869
|
+
box.field.css = {
|
|
870
|
+
flexWrap: "wrap",
|
|
871
|
+
minHeight: _s.field.minHeight + "px",
|
|
872
|
+
transition: "border-color 0.15s",
|
|
873
|
+
};
|
|
874
|
+
box.field.cursor = "text";
|
|
875
|
+
box.field.role = "list";
|
|
876
|
+
box.field.aria = { label: box.ariaLabel };
|
|
877
|
+
|
|
878
|
+
// INPUT: Typing area. (The chips are inserted before it.)
|
|
879
|
+
box.input = Input({
|
|
880
|
+
width: "auto",
|
|
881
|
+
height: _s.input.height,
|
|
882
|
+
minimal: 1,
|
|
883
|
+
color: "transparent",
|
|
884
|
+
fontSize: _s.input.fontSize,
|
|
885
|
+
textColor: _s.input.textColor,
|
|
886
|
+
});
|
|
887
|
+
box.input.elem.classList.add("tag-input-input");
|
|
888
|
+
box.input.inputElement.style.padding = "0px";
|
|
889
|
+
box.input.inputElement.style.height = "100%";
|
|
890
|
+
box.input.inputElement.style.width = "100%";
|
|
891
|
+
box.input.inputElement.setAttribute("autocomplete", "off");
|
|
892
|
+
box.input.inputElement.setAttribute("role", "combobox");
|
|
893
|
+
box.input.inputElement.setAttribute("aria-autocomplete", "list");
|
|
894
|
+
box.input.inputElement.setAttribute("aria-expanded", "false");
|
|
895
|
+
box.input.inputElement.setAttribute("aria-controls", id + "-list");
|
|
896
|
+
box.input.inputElement.maxLength = (box.maxLength > 0) ? box.maxLength + 8 : 524288; // WHY: A little longer, so the "long" message can be shown.
|
|
897
|
+
|
|
898
|
+
endGroup();
|
|
899
|
+
|
|
900
|
+
// GROUP: Bottom row (message, counter)
|
|
901
|
+
box.bottomRow = HGroup({ width: "100%", height: "auto", align: "left center", gap: 10 });
|
|
902
|
+
|
|
903
|
+
// LABEL: Message (reject reason)
|
|
904
|
+
box.messageLabel = Label({ text: "", fontSize: _s.message.fontSize, textColor: _s.message.textColor, visible: 0 });
|
|
905
|
+
box.messageLabel.css = { flex: "1 1 auto", minWidth: "0" };
|
|
906
|
+
box.messageLabel.role = "alert";
|
|
907
|
+
|
|
908
|
+
// LABEL: Counter "3 / 5"
|
|
909
|
+
box.counterLabel = Label({ text: "", fontSize: _s.counter.fontSize, textColor: _s.counter.textColor, visible: 0 });
|
|
910
|
+
box.counterLabel.css = { marginLeft: "auto", whiteSpace: "nowrap" };
|
|
911
|
+
|
|
912
|
+
endGroup();
|
|
913
|
+
|
|
914
|
+
endGroup();
|
|
915
|
+
|
|
916
|
+
// POPUP: Suggestion list, on the page over everything.
|
|
917
|
+
setDefaultContainerBox(page);
|
|
918
|
+
// NOTE: endGroup() of the panel below returns the default container to the component box.
|
|
919
|
+
|
|
920
|
+
// GROUP: Panel
|
|
921
|
+
box.panel = VGroup({
|
|
922
|
+
width: 200,
|
|
923
|
+
height: "auto",
|
|
924
|
+
align: "left top",
|
|
925
|
+
gap: 0,
|
|
926
|
+
color: _s.panel.color,
|
|
927
|
+
border: _s.panel.border,
|
|
928
|
+
borderColor: _s.panel.borderColor,
|
|
929
|
+
round: _s.panel.round,
|
|
930
|
+
padding: _s.panel.padding,
|
|
931
|
+
clickable: 1,
|
|
932
|
+
});
|
|
933
|
+
// WHY: visible: 0 at create time makes the children absolute (not flex items). Hide it after the children are added.
|
|
934
|
+
box.panel.css.alignItems = "stretch";
|
|
935
|
+
box.panel.boxShadow = _s.panel.shadow;
|
|
936
|
+
box.panel.zIndex = PANEL_Z_INDEX;
|
|
937
|
+
|
|
938
|
+
// BOX: List (scrolls)
|
|
939
|
+
box.list = Box({ width: "100%", height: "auto", color: "transparent", scrollY: 1, position: "relative" });
|
|
940
|
+
box.list.elem.id = id + "-list";
|
|
941
|
+
box.list.role = "listbox";
|
|
942
|
+
box.list.css.overscrollBehavior = "contain";
|
|
943
|
+
|
|
944
|
+
endGroup();
|
|
945
|
+
box.panel.visible = 0;
|
|
946
|
+
|
|
947
|
+
// *** OBJECT INIT CODE:
|
|
948
|
+
|
|
949
|
+
box.field.on("click", function () {
|
|
950
|
+
if (box.enabled != 1) return;
|
|
951
|
+
selectedIndex = -1;
|
|
952
|
+
paintChips();
|
|
953
|
+
box.input.inputElement.focus({ preventScroll: true });
|
|
954
|
+
});
|
|
955
|
+
box.field.on("mouseenter", function () {
|
|
956
|
+
if (isFocused || box.messageLabel.visible == 1) return;
|
|
957
|
+
box.field.borderColor = _s.fieldHover.borderColor;
|
|
958
|
+
});
|
|
959
|
+
box.field.on("mouseleave", function () { updateFieldBorder(); });
|
|
960
|
+
|
|
961
|
+
box.input.inputElement.addEventListener("focus", function () {
|
|
962
|
+
isFocused = 1;
|
|
963
|
+
updateFieldBorder();
|
|
964
|
+
if (box.showSuggestionsOnFocus == 1 || box.allowCustom != 1) openPanel();
|
|
965
|
+
});
|
|
966
|
+
box.input.inputElement.addEventListener("blur", function () {
|
|
967
|
+
isFocused = 0;
|
|
968
|
+
selectedIndex = -1;
|
|
969
|
+
paintChips();
|
|
970
|
+
updateFieldBorder();
|
|
971
|
+
});
|
|
972
|
+
box.input.inputElement.addEventListener("input", function () {
|
|
973
|
+
if (selectedIndex >= 0) unselectChip();
|
|
974
|
+
openPanel();
|
|
975
|
+
});
|
|
976
|
+
box.input.inputElement.addEventListener("keydown", function (event) { onKeyDown(box, event); });
|
|
977
|
+
box.input.inputElement.addEventListener("paste", onPaste);
|
|
978
|
+
|
|
979
|
+
// WHY: Keep the keyboard focus in the input when a suggestion is pressed.
|
|
980
|
+
box.panel.on("mousedown", function (self, event) { event.preventDefault(); });
|
|
981
|
+
|
|
982
|
+
// (listenTo / onPageResize / own: removed with the box)
|
|
983
|
+
box.listenTo(document, "pointerdown", onDocumentPointerDown, true);
|
|
984
|
+
box.listenTo(document, "scroll", onAnyScroll, true);
|
|
985
|
+
box.onPageResize(onPageResize);
|
|
986
|
+
box.own(box.panel); // WHY: It is on the page, not in the box.
|
|
987
|
+
|
|
988
|
+
box.suggestions = (box.suggestions || []).map(normalize).filter(Boolean);
|
|
989
|
+
box.maxTags = Math.max(0, Number(box.maxTags) || 0);
|
|
990
|
+
(startTags || []).forEach(function (tag) { addOne(tag, 1, 1); });
|
|
991
|
+
renderChips();
|
|
992
|
+
box.setEnabled(box.enabled);
|
|
993
|
+
|
|
994
|
+
return endObject(box);
|
|
995
|
+
|
|
996
|
+
};
|
|
997
|
+
|
|
998
|
+
// *** STATIC VARIABLES AND FUNCTIONS:
|
|
999
|
+
|
|
1000
|
+
TagInput._counter = 1;
|
|
1001
|
+
|
|
1002
|
+
// WHY: Label.text uses innerHTML. Texts must not be read as HTML.
|
|
1003
|
+
TagInput.escapeHtml = basic.escapeHtml; // (the name is kept: other code may use it)
|
|
1004
|
+
|
|
1005
|
+
TagInput.getCloseSvg = function (color) {
|
|
1006
|
+
return '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="' + color + '" stroke-width="2.4" stroke-linecap="round"><path d="M6 6l12 12M18 6 6 18"/></svg>';
|
|
1007
|
+
};
|
|
1008
|
+
|
|
1009
|
+
// Placeholder color and the shake animation can not be set with inline styles.
|
|
1010
|
+
TagInput.injectCss = function () {
|
|
1011
|
+
basic.addCss("tag-input-css",
|
|
1012
|
+
".tag-input-input input::placeholder { color: var(--tag-input-placeholder, rgba(0,0,0,0.4)); opacity: 1; }" +
|
|
1013
|
+
".tag-input-input input { pointer-events: auto; user-select: text; -webkit-user-select: text; }" +
|
|
1014
|
+
"@keyframes tagInputShake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }");
|
|
1015
|
+
};
|
|
1016
|
+
|
|
1017
|
+
// *** STYLE PACKAGES:
|
|
1018
|
+
// USAGE: TagInput({ styleName: "modern" })
|
|
1019
|
+
// USAGE: TagInput({ styleName: "dark", style: { tag: { color: "#3D7A6B" } } }) // Change only some keys.
|
|
1020
|
+
// USAGE: TagInput({ style: TagInput.styles.dark }) // The same as styleName: "dark". (The package is copied, never changed.)
|
|
1021
|
+
// NOTE: A new package needs only the keys that differ from the default (classic) style.
|
|
1022
|
+
// USAGE: TagInput.styles.myStyle = { tag: { color: "gold" } };
|
|
1023
|
+
TagInput.styles = {
|
|
1024
|
+
|
|
1025
|
+
// Gray chips in a white field.
|
|
1026
|
+
light: TagInputDefaults.style,
|
|
1027
|
+
|
|
1028
|
+
// Round cadetblue chips, same colors as the modern CheckBox, RadioButton and ProgressBar.
|
|
1029
|
+
modern: {
|
|
1030
|
+
field: { color: White(1), border: 1, borderColor: "#D9DADB", round: 10, padding: [8, 6], gap: 6, minHeight: 46 },
|
|
1031
|
+
fieldHover: { borderColor: "#A9B8B9" },
|
|
1032
|
+
fieldFocus: { borderColor: "cadetblue" },
|
|
1033
|
+
fieldError: { borderColor: "tomato" },
|
|
1034
|
+
input: { fontSize: 15, textColor: Black(0.85), minWidth: 90, height: 30 },
|
|
1035
|
+
placeholder: { textColor: Black(0.4) },
|
|
1036
|
+
tag: { color: "#DFECEC", border: 0, borderColor: "transparent", round: 100, padding: [10, 0], height: 30, gap: 5 },
|
|
1037
|
+
tagHover: { color: "#CFE2E2" },
|
|
1038
|
+
tagSelected: { color: "cadetblue", textColor: White(1), removeColor: White(0.85) },
|
|
1039
|
+
tagText: { fontSize: 13, textColor: "#2F5F61" },
|
|
1040
|
+
tagRemove: { color: "#5F9EA0", hoverColor: "tomato" },
|
|
1041
|
+
panel: { color: White(1), border: 1, borderColor: "#D9DADB", round: 10, padding: 4, shadow: "0 8px 24px rgba(0, 0, 0, 0.10)", maxHeight: 240 },
|
|
1042
|
+
option: { fontSize: 14, textColor: Black(0.85), round: 6, padding: [10, 7] },
|
|
1043
|
+
optionActive: { color: "#EEF5F5" },
|
|
1044
|
+
highlight: { color: "#DFECEC" },
|
|
1045
|
+
empty: { fontSize: 13, textColor: Black(0.45) },
|
|
1046
|
+
message: { fontSize: 12, textColor: "tomato" },
|
|
1047
|
+
counter: { fontSize: 12, textColor: "cadetblue" },
|
|
1048
|
+
disabled: { opacity: 0.5 },
|
|
1049
|
+
},
|
|
1050
|
+
|
|
1051
|
+
// Dark theme, same colors as SelectBox "dark".
|
|
1052
|
+
dark: {
|
|
1053
|
+
field: { color: "#232322", border: 1, borderColor: "rgba(255, 255, 255, 0.10)", round: 8, padding: [8, 6], gap: 6, minHeight: 44 },
|
|
1054
|
+
fieldHover: { borderColor: "rgba(255, 255, 255, 0.30)" },
|
|
1055
|
+
fieldFocus: { borderColor: "#65A293" },
|
|
1056
|
+
fieldError: { borderColor: "#E66767" },
|
|
1057
|
+
input: { fontSize: 15, textColor: "rgba(255, 255, 255, 0.90)", minWidth: 90, height: 28 },
|
|
1058
|
+
placeholder: { textColor: "rgba(255, 255, 255, 0.40)" },
|
|
1059
|
+
tag: { color: "rgba(255, 255, 255, 0.10)", border: 0, borderColor: "transparent", round: 5, padding: [8, 0], height: 28, gap: 4 },
|
|
1060
|
+
tagHover: { color: "rgba(255, 255, 255, 0.16)" },
|
|
1061
|
+
tagSelected: { color: "#3D7A6B", textColor: "#FFFFFF", removeColor: "rgba(255, 255, 255, 0.8)" },
|
|
1062
|
+
tagText: { fontSize: 13, textColor: "rgba(255, 255, 255, 0.90)" },
|
|
1063
|
+
tagRemove: { color: "rgba(255, 255, 255, 0.50)", hoverColor: "#E66767" },
|
|
1064
|
+
panel: { color: "#232322", border: 1, borderColor: "rgba(255, 255, 255, 0.12)", round: 10, padding: 4, shadow: "0 8px 24px rgba(0, 0, 0, 0.5)", maxHeight: 240 },
|
|
1065
|
+
option: { fontSize: 14, textColor: "rgba(255, 255, 255, 0.85)", round: 6, padding: [10, 7] },
|
|
1066
|
+
optionActive: { color: "rgba(255, 255, 255, 0.08)" },
|
|
1067
|
+
highlight: { color: "rgba(101, 162, 147, 0.45)" },
|
|
1068
|
+
empty: { fontSize: 13, textColor: "rgba(255, 255, 255, 0.45)" },
|
|
1069
|
+
message: { fontSize: 12, textColor: "#E66767" },
|
|
1070
|
+
counter: { fontSize: 12, textColor: "rgba(255, 255, 255, 0.45)" },
|
|
1071
|
+
disabled: { opacity: 0.4 },
|
|
1072
|
+
},
|
|
1073
|
+
|
|
1074
|
+
};
|
|
1075
|
+
TagInput.styles.classic = TagInput.styles.light; // the old name of light: the pages made with it keep their look
|
|
1076
|
+
|
|
1077
|
+
// The minimal theme (_designs/minimal-theme.htm): a 28 px field with no fill and an edge of 3:1 at least, ink while it
|
|
1078
|
+
// is typed in; the tags are 20 px with a soft line (a faint fill under the mouse, ink when they are chosen with the
|
|
1079
|
+
// keyboard); a flat suggestion list with a line and no shadow, the typed part in bold. minimalDark: the same on a dark
|
|
1080
|
+
// window.
|
|
1081
|
+
TagInput.createMinimalStyle = function (colors) {
|
|
1082
|
+
return {
|
|
1083
|
+
field: { color: "transparent", border: 1, borderColor: colors.edge, round: 4, padding: [6, 3], gap: 4, minHeight: 28 },
|
|
1084
|
+
fieldHover: { borderColor: colors.edgeHover },
|
|
1085
|
+
fieldFocus: { borderColor: colors.ink },
|
|
1086
|
+
fieldError: { borderColor: colors.danger },
|
|
1087
|
+
input: { fontSize: 13, textColor: colors.text, minWidth: 80, height: 20 },
|
|
1088
|
+
placeholder: { textColor: colors.faintText },
|
|
1089
|
+
tag: { color: "transparent", border: 1, borderColor: colors.line, round: 3, padding: [6, 0], height: 20, gap: 3 },
|
|
1090
|
+
tagHover: { color: colors.hover },
|
|
1091
|
+
tagSelected: { color: colors.ink, textColor: colors.onInk, removeColor: colors.onInk },
|
|
1092
|
+
tagText: { fontSize: 12, textColor: colors.text },
|
|
1093
|
+
tagRemove: { color: colors.softText, hoverColor: colors.danger },
|
|
1094
|
+
panel: { color: colors.ground, border: 1, borderColor: colors.line, round: 4, padding: 4, shadow: "none", maxHeight: 200 },
|
|
1095
|
+
option: { fontSize: 13, textColor: colors.text, round: 3, padding: [8, 5] },
|
|
1096
|
+
optionActive: { color: colors.hover },
|
|
1097
|
+
highlight: { color: "transparent", fontFamily: "opensans-bold" }, // WHY bold: a faint fill behind a few small letters read as a smudge
|
|
1098
|
+
empty: { fontSize: 12, textColor: colors.softText },
|
|
1099
|
+
message: { fontSize: 11, textColor: colors.danger },
|
|
1100
|
+
counter: { fontSize: 11, textColor: colors.softText },
|
|
1101
|
+
disabled: { opacity: 0.4 },
|
|
1102
|
+
};
|
|
1103
|
+
};
|
|
1104
|
+
TagInput.MINIMAL_COLORS = { ground: "#FFFFFF", text: Black(0.85), softText: Black(0.55), faintText: Black(0.54), line: Black(0.2), edge: Black(0.45), edgeHover: Black(0.65), ink: "#1F1F1F", onInk: "#FFFFFF", hover: Black(0.05), danger: "#C24A36" };
|
|
1105
|
+
TagInput.styles.minimal = TagInput.createMinimalStyle(TagInput.MINIMAL_COLORS);
|
|
1106
|
+
TagInput.MINIMAL_DARK_COLORS = { ground: "#1A1A19", text: White(0.88), softText: White(0.55), faintText: White(0.48), line: White(0.18), edge: White(0.42), edgeHover: White(0.62), ink: "#EDEDEB", onInk: "#1A1A19", hover: White(0.07), danger: "#FF9F93" };
|
|
1107
|
+
TagInput.styles.minimalDark = TagInput.createMinimalStyle(TagInput.MINIMAL_DARK_COLORS);
|