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,170 @@
|
|
|
1
|
+
/* Bismillah */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
Tap Effect - v26.11
|
|
6
|
+
|
|
7
|
+
A soft circle where the screen is tapped. A black circle
|
|
8
|
+
(80 px, opacity 0.05) comes in the middle of the tap, fades to 0 in 0.2 s (it starts 50 ms after the tap) and goes
|
|
9
|
+
(removed at 250 ms). It is over everything and never catches a tap: the tap goes to the object under it.
|
|
10
|
+
- TapEffect.start(options): the taps of the page make circles. TapEffect.stop(): no more circles (its window
|
|
11
|
+
listener is removed; a circle that is seen goes by itself). TapEffect.isOn: 1 while it is started.
|
|
12
|
+
- options (TapEffect.DEFAULT_OPTIONS): { color: "#000000", opacity: 0.05, size: 80, duration: 0.2, oneAtATime: 1 }
|
|
13
|
+
-- size: page px (on a page fitted with page.fit() the circle is zoomed with the page)
|
|
14
|
+
-- duration: s, the fade
|
|
15
|
+
-- oneAtATime: 1: a tap while a circle is seen makes no new one. 0: every tap gets its own circle.
|
|
16
|
+
- TapEffect.show(x, y): a circle at a place of the page (page px) with the options of start(). It returns the
|
|
17
|
+
circle, or null when there is none (one at a time, reduced motion). It works without start() too.
|
|
18
|
+
- Only real taps: a click of the keyboard or of the code (event.detail 0) has no place on the screen.
|
|
19
|
+
- A tap does not change "that" of the page. (TapEffect.show() called by your code makes the circle "that".)
|
|
20
|
+
- A page fitted with page.fit(): the place of the tap is read in page px (withPageZoom of clientX / clientY).
|
|
21
|
+
- Nothing when the system asks for reduced motion.
|
|
22
|
+
- TapEffect(params): one circle in the current container (x, y: its middle; size, color, opacity, duration).
|
|
23
|
+
TapEffect.show() makes it on page.
|
|
24
|
+
|
|
25
|
+
USAGE:
|
|
26
|
+
TapEffect.start();
|
|
27
|
+
TapEffect.start({ color: "#FFFFFF", opacity: 0.12 }); // on a dark page
|
|
28
|
+
TapEffect.stop();
|
|
29
|
+
TapEffect.show(200, 300); // a circle at x 200, y 300 of the page
|
|
30
|
+
if (TapEffect.isOn) TapEffect.stop();
|
|
31
|
+
|
|
32
|
+
Started Date: November 2026
|
|
33
|
+
Webpage: https://bug7a.github.io/js-components/
|
|
34
|
+
|
|
35
|
+
Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
|
|
36
|
+
Licensed under the Apache License, Version 2.0
|
|
37
|
+
SPDX-License-Identifier: Apache-2.0
|
|
38
|
+
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
"use strict";
|
|
42
|
+
|
|
43
|
+
// Default values: (one circle)
|
|
44
|
+
const TapEffectDefaults = {
|
|
45
|
+
x: 0, // px: the middle of the circle (the place of the tap)
|
|
46
|
+
y: 0,
|
|
47
|
+
size: 80, // px: the width of the circle
|
|
48
|
+
color: "#000000",
|
|
49
|
+
opacity: 0.05, // at the start; it fades to 0
|
|
50
|
+
duration: 0.2, // s: the fade
|
|
51
|
+
zIndex: 100001, // WHY: over everything: Tooltip (100000), Notice (50000), Dialog (4000 and up)
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const TapEffect = function (params = {}) {
|
|
55
|
+
|
|
56
|
+
// Merge params:
|
|
57
|
+
mergeIntoIfMissing(params, TapEffectDefaults);
|
|
58
|
+
|
|
59
|
+
// WHY: the circle is placed by its middle (the place of the tap), not by its corner.
|
|
60
|
+
params.left = params.x - params.size / 2;
|
|
61
|
+
params.top = params.y - params.size / 2;
|
|
62
|
+
params.width = params.size;
|
|
63
|
+
params.height = params.size;
|
|
64
|
+
|
|
65
|
+
// BOX: Component container (the circle)
|
|
66
|
+
let box = startObject(params);
|
|
67
|
+
|
|
68
|
+
// *** PRIVATE VARIABLES:
|
|
69
|
+
const FADE_START_TIME = 50; // ms: the circle is seen whole for a moment, then it fades
|
|
70
|
+
const REMOVE_TIME = FADE_START_TIME + box.duration * 1000; // ms: the end of the fade
|
|
71
|
+
|
|
72
|
+
// *** PUBLIC FUNCTIONS:
|
|
73
|
+
|
|
74
|
+
// REMOVE: the static TapEffect.current must not keep a removed circle.
|
|
75
|
+
const superRemove = box.remove;
|
|
76
|
+
box.superRemove = superRemove;
|
|
77
|
+
box.remove = function () {
|
|
78
|
+
if (!box) return;
|
|
79
|
+
if (TapEffect.current == box) TapEffect.current = null;
|
|
80
|
+
superRemove.call(box);
|
|
81
|
+
box = null;
|
|
82
|
+
};
|
|
83
|
+
// USAGE: circle.remove()
|
|
84
|
+
|
|
85
|
+
// *** OBJECT VIEW:
|
|
86
|
+
|
|
87
|
+
box.round = box.size / 2;
|
|
88
|
+
box.clickable = 0; // WHY: it never catches a tap
|
|
89
|
+
// WHY setMotionNow: a new object has no look before, so nothing moves at its first view.
|
|
90
|
+
box.setMotionNow("opacity " + box.duration + "s");
|
|
91
|
+
|
|
92
|
+
// *** OBJECT INIT CODE:
|
|
93
|
+
|
|
94
|
+
box.after(FADE_START_TIME, function (self) { self.opacity = 0; });
|
|
95
|
+
box.after(REMOVE_TIME, function (self) { self.remove(); });
|
|
96
|
+
|
|
97
|
+
return endObject(box);
|
|
98
|
+
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// *** STATIC VARIABLES AND FUNCTIONS:
|
|
102
|
+
|
|
103
|
+
// The options of TapEffect.start(): the look of the circle (TapEffectDefaults) and oneAtATime.
|
|
104
|
+
TapEffect.DEFAULT_OPTIONS = {
|
|
105
|
+
color: TapEffectDefaults.color,
|
|
106
|
+
opacity: TapEffectDefaults.opacity,
|
|
107
|
+
size: TapEffectDefaults.size, // page px
|
|
108
|
+
duration: TapEffectDefaults.duration, // s
|
|
109
|
+
oneAtATime: 1, // 1: a tap while a circle is seen makes no new one. 0: every tap gets its own circle.
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
TapEffect.options = Object.assign({}, TapEffect.DEFAULT_OPTIONS); // The options in use (start() sets them)
|
|
113
|
+
TapEffect.isOn = 0; // 1: the taps of the page make circles (start / stop)
|
|
114
|
+
TapEffect.current = null; // The circle that is seen (the last one)
|
|
115
|
+
|
|
116
|
+
TapEffect.isReducedMotion = function () {
|
|
117
|
+
return window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// The taps of the page make circles. The options not given are the defaults (also when it is called again: then
|
|
121
|
+
// only the options change, the window listener is added once).
|
|
122
|
+
TapEffect.start = function (options = {}) {
|
|
123
|
+
TapEffect.options = Object.assign({}, TapEffect.DEFAULT_OPTIONS, options);
|
|
124
|
+
if (TapEffect.isOn) return;
|
|
125
|
+
TapEffect.isOn = 1;
|
|
126
|
+
// WHY capture: the circle comes also where the code of the page stops the click (Ex: a menu, a popover).
|
|
127
|
+
window.addEventListener("click", TapEffect.onWindowClick, true);
|
|
128
|
+
};
|
|
129
|
+
// USAGE: TapEffect.start() / TapEffect.start({ color: "#FFFFFF", opacity: 0.12 })
|
|
130
|
+
|
|
131
|
+
// No more circles. (A circle that is seen goes by itself.)
|
|
132
|
+
TapEffect.stop = function () {
|
|
133
|
+
window.removeEventListener("click", TapEffect.onWindowClick, true);
|
|
134
|
+
TapEffect.isOn = 0;
|
|
135
|
+
};
|
|
136
|
+
// USAGE: TapEffect.stop()
|
|
137
|
+
|
|
138
|
+
// A circle at a place of the page (page px) with TapEffect.options. Returns it, or null when there is none.
|
|
139
|
+
TapEffect.show = function (x, y) {
|
|
140
|
+
const options = TapEffect.options;
|
|
141
|
+
if (!basic.isReady) return null; // WHY: a tap while the page loads has no page to draw on (start() at load time)
|
|
142
|
+
if (TapEffect.isReducedMotion()) return null;
|
|
143
|
+
if (basic.isOn(options.oneAtATime) && TapEffect.current) return null;
|
|
144
|
+
const params = {
|
|
145
|
+
x: x,
|
|
146
|
+
y: y,
|
|
147
|
+
size: options.size,
|
|
148
|
+
color: options.color,
|
|
149
|
+
opacity: options.opacity,
|
|
150
|
+
duration: options.duration,
|
|
151
|
+
};
|
|
152
|
+
TapEffect.current = createIn(page, function () { return TapEffect(params); });
|
|
153
|
+
return TapEffect.current;
|
|
154
|
+
};
|
|
155
|
+
// USAGE: TapEffect.show(200, 300)
|
|
156
|
+
|
|
157
|
+
// A click of the page (TapEffect.start): a real tap makes a circle at its place.
|
|
158
|
+
TapEffect.onWindowClick = function (event) {
|
|
159
|
+
// WHY: a click of the keyboard or of the code (event.detail 0) has no place on the screen.
|
|
160
|
+
const isRealTap = (event.detail > 0);
|
|
161
|
+
if (!isRealTap) return;
|
|
162
|
+
// WHY: a tap must not change "that" of the page (its code may use it after an await).
|
|
163
|
+
saveCurrentThat();
|
|
164
|
+
try {
|
|
165
|
+
// WHY withPageZoom: clientX / clientY are screen px, and a page fitted with page.fit() is zoomed.
|
|
166
|
+
TapEffect.show(withPageZoom(event.clientX), withPageZoom(event.clientY));
|
|
167
|
+
} finally {
|
|
168
|
+
restoreThatFromSaved();
|
|
169
|
+
}
|
|
170
|
+
};
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/* Bismillah */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
TextAreaField - v26.11
|
|
6
|
+
|
|
7
|
+
UI COMPONENT TEMPLATE
|
|
8
|
+
- You can customize, this template code as you need:
|
|
9
|
+
- NEW PROJECTS: styleName "light" (the default) on a light page, "dark" on a dark page (the packages
|
|
10
|
+
of TextField, comp/text-field.js; the look of 02-comp-examples/text-field-8-light-dark.htm), unless the user asks for another one.
|
|
11
|
+
- scrollBarStyle: the scroll bar of the text (the params of ScrollBar; a style package can give it: minimal).
|
|
12
|
+
- rightPadding is its own (5): a style package does not change it (on the right is the scroll bar). Under its title
|
|
13
|
+
(titlePosition "above", minimal), from the right edge: the scroll bar right inside the edge, the warning ball left
|
|
14
|
+
of it, then the text.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
Started Date: June 2024
|
|
18
|
+
Webpage: https://bug7a.github.io/js-components/
|
|
19
|
+
|
|
20
|
+
Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
|
|
21
|
+
Licensed under the Apache License, Version 2.0
|
|
22
|
+
SPDX-License-Identifier: Apache-2.0
|
|
23
|
+
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
"use strict";
|
|
27
|
+
|
|
28
|
+
// Default values
|
|
29
|
+
const TextAreaFieldDefaults = {
|
|
30
|
+
type: "textarea",
|
|
31
|
+
titleText: "MESSAGE",
|
|
32
|
+
placeholder: "How can we help you?",
|
|
33
|
+
required: 1,
|
|
34
|
+
minCharCount: 80, // 0, 80
|
|
35
|
+
showCount: 1, // 0, 1
|
|
36
|
+
lengthText: "length: ",
|
|
37
|
+
warningText: "The entered text must be longer than 80",
|
|
38
|
+
warningColor: "#E5885E",
|
|
39
|
+
maxLength: 255,
|
|
40
|
+
height: 170, // 170 (4line)
|
|
41
|
+
rightPadding: 5,
|
|
42
|
+
unitStyle: {
|
|
43
|
+
padding: [12, 4],
|
|
44
|
+
color: "#373836EE",
|
|
45
|
+
textColor: "white",
|
|
46
|
+
},
|
|
47
|
+
scrollBarStyle: { // The scroll bar of the text (the params of ScrollBar)
|
|
48
|
+
bar_border: 0,
|
|
49
|
+
bar_round: 2,
|
|
50
|
+
bar_borderColor: "rgba(0, 0, 0, 1)",
|
|
51
|
+
bar_width: 4,
|
|
52
|
+
bar_mouseOverWidth: 4,
|
|
53
|
+
bar_mouseOverColor: "#373836",
|
|
54
|
+
bar_opacity: 0.4,
|
|
55
|
+
bar_mouseOverOpacity: 0.9,
|
|
56
|
+
bar_padding: 3,
|
|
57
|
+
bar_color: "#373836",
|
|
58
|
+
neverHide: 1,
|
|
59
|
+
showDots: 1,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const TextAreaField = function(params = {}) {
|
|
64
|
+
|
|
65
|
+
// Merge params first: the style package of TextField, then the defaults of TextAreaField
|
|
66
|
+
// WHY the package first: a package that sets a key of TextAreaField (minimal: unitStyle, scrollBarStyle) wins over the
|
|
67
|
+
// defaults here, as over the defaults of TextField
|
|
68
|
+
// WHY its own rightPadding: on the right of a TextAreaField is its scroll bar, not the room of the warning ball of a
|
|
69
|
+
// one-line field (the rightPadding of a package pushed the scroll bar to the middle)
|
|
70
|
+
const givenRightPadding = params.rightPadding;
|
|
71
|
+
basic.applyStylePackage(params, TextField.styles, TextFieldDefaults);
|
|
72
|
+
params.rightPadding = (givenRightPadding !== undefined) ? givenRightPadding : TextAreaFieldDefaults.rightPadding;
|
|
73
|
+
mergeIntoIfMissing(params, TextAreaFieldDefaults);
|
|
74
|
+
|
|
75
|
+
// Control params
|
|
76
|
+
params.createInput = 0; // WHY: A <textarea> is made here instead of the Input of TextField.
|
|
77
|
+
params.showDescription = 0;
|
|
78
|
+
params.descriptionText = "";
|
|
79
|
+
|
|
80
|
+
if (params.showCount != 0) {
|
|
81
|
+
params.showUnit = 1;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// BOX: Component container
|
|
85
|
+
const box = startExtendedObject(TextField, params);
|
|
86
|
+
|
|
87
|
+
// *** PRIVATE VARIABLES:
|
|
88
|
+
const textareaElem = document.createElement("textarea");
|
|
89
|
+
|
|
90
|
+
// *** PUBLIC VARIABLES:
|
|
91
|
+
box.textareaElem = textareaElem; // the raw <textarea>: a page can listen to its paste / drop / keydown
|
|
92
|
+
|
|
93
|
+
// *** PRIVATE FUNCTIONS:
|
|
94
|
+
// The count is hidden when the text is long enough.
|
|
95
|
+
const refreshCount = function() {
|
|
96
|
+
if (!box.showCount) return;
|
|
97
|
+
|
|
98
|
+
const currentLength = box.getValue().length;
|
|
99
|
+
box.setUnitText(`${box.lengthText}${currentLength}`);
|
|
100
|
+
box.unit.opacity = (currentLength > box.minCharCount) ? 0 : 1;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// The textarea grows with its text (the inputBox scrolls).
|
|
104
|
+
const autoGrow = function(elem) {
|
|
105
|
+
elem.style.height = "auto"; // WHY: First reset, so scrollHeight is the height of the text (also when it got shorter).
|
|
106
|
+
// WHY: not drawn yet (a closed tab, a Dialog filled before it opens): scrollHeight is 0 and a 0 px textarea
|
|
107
|
+
// could not be seen or clicked. box.onResize grows it when it is shown.
|
|
108
|
+
if (elem.scrollHeight === 0) return;
|
|
109
|
+
elem.style.height = elem.scrollHeight + "px";
|
|
110
|
+
// WHY: After the browser drew the new height.
|
|
111
|
+
box.after(0, () => box.inputBox.scrollBar.refreshScroll());
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// *** PUBLIC FUNCTIONS:
|
|
115
|
+
box.setValue = function(value) { // OVERRIDE
|
|
116
|
+
if (value != textareaElem.value) {
|
|
117
|
+
box.value = value;
|
|
118
|
+
textareaElem.value = value;
|
|
119
|
+
// WHY: Same as TextField.setValue. Without it, a required textarea cleared by code (after a form is sent) showed no required icon.
|
|
120
|
+
box.checkIfInputIsRequiredAndEmpty();
|
|
121
|
+
box.showWarningIfNotValid(box.isValid());
|
|
122
|
+
refreshCount();
|
|
123
|
+
autoGrow(textareaElem);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
box.getValue = function() { // OVERRIDE
|
|
128
|
+
return textareaElem.value;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// WHY: The ones of TextField write to box.input, which a TextAreaField does not have (createInput: 0): a TypeError.
|
|
132
|
+
box.setPlaceholder = function(text) { // OVERRIDE
|
|
133
|
+
box.placeholder = text;
|
|
134
|
+
textareaElem.placeholder = text;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
box.setMaxLength = function(count) { // OVERRIDE
|
|
138
|
+
box.maxLength = count;
|
|
139
|
+
textareaElem.maxLength = count;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
box.isValid = function() { // OVERRIDE
|
|
143
|
+
return (box.getValue().length > box.minCharCount) ? 1 : 0;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// UNDER ITS TITLE (titlePosition "above"), from the right edge of the field: the scroll bar right inside the edge,
|
|
147
|
+
// the warning ball left of it, then the text. WHY apart: the scroll bar was under the ball.
|
|
148
|
+
const EDGE_WIDTH = 1; // px: the edge of the field
|
|
149
|
+
const BALL_SPACE = 2; // px between the scroll bar and the ball, and between the ball and the text
|
|
150
|
+
const placeRightSideUnderTitle = function () {
|
|
151
|
+
const bar = box.scrollBarStyle;
|
|
152
|
+
const barRoom = bar.bar_padding + Math.max(bar.bar_width, bar.bar_mouseOverWidth);
|
|
153
|
+
const ballRight = EDGE_WIDTH + barRoom + BALL_SPACE;
|
|
154
|
+
const textRight = ballRight + box.warningBall.width + BALL_SPACE - EDGE_WIDTH; // from the right of the text box
|
|
155
|
+
box.inputGroup.padding = [box.leftPadding, 0, EDGE_WIDTH, 0];
|
|
156
|
+
box.warningBall.right = ballRight;
|
|
157
|
+
textareaElem.style.padding = TEXT_SPACE + "px " + textRight + "px " + TEXT_SPACE + "px 0px";
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
// *** OBJECT VIEW:
|
|
161
|
+
const isTitleAbove = (box.titlePosition === "above");
|
|
162
|
+
const TEXT_SPACE = 6; // px over and under the text in a field under its title (titlePosition "above")
|
|
163
|
+
box.inputGroup.gap = isTitleAbove ? box.titleGap : 8;
|
|
164
|
+
box.inputGroup.height = "100%";
|
|
165
|
+
box.inputBox.color = "transparent";
|
|
166
|
+
box.inputBox.height = isTitleAbove ? "calc(100% - " + box.fieldTop + "px)" : "calc(100% - 20px)";
|
|
167
|
+
|
|
168
|
+
// WHY: A raw <textarea> (not a basic.js object): its style is written directly.
|
|
169
|
+
textareaElem.classList.add("basic_textbox");
|
|
170
|
+
textareaElem.classList.add("minimal");
|
|
171
|
+
textareaElem.style.cssText = "background-color:transparent;font-size:" + box.inputFontSize + "px;resize:none;width:100%;padding:0px 0px;box-sizing:border-box";
|
|
172
|
+
textareaElem.style.overflow = "hidden";
|
|
173
|
+
if (isTitleAbove) placeRightSideUnderTitle();
|
|
174
|
+
// WHY a CSS size, not the measured one: the field is clickable in all its height, also when it is made hidden
|
|
175
|
+
// (box.inputBox.height is 0 then) and after the text changed (autoGrow cleared the measured one)
|
|
176
|
+
textareaElem.style.minHeight = "calc(100% - 4px)";
|
|
177
|
+
textareaElem.style.height = "auto";
|
|
178
|
+
|
|
179
|
+
textareaElem.placeholder = box.placeholder;
|
|
180
|
+
// WHY: The <textarea> is made here, not by TextField, so the text colors of TextField were never given to it:
|
|
181
|
+
// on a dark package (dark, ozdenDark) the typed text was dark on a dark field.
|
|
182
|
+
box.applyTextColors(textareaElem);
|
|
183
|
+
textareaElem.maxLength = box.maxLength;
|
|
184
|
+
box.inputBox.elem.appendChild(textareaElem);
|
|
185
|
+
box.inputBox.clickable = 1;
|
|
186
|
+
textareaElem.value = box.value;
|
|
187
|
+
box.inputBox.scrollY = 1;
|
|
188
|
+
|
|
189
|
+
// SCROLL BAR:
|
|
190
|
+
box.inputBox.scrollBar = ScrollBar(Object.assign({ scrollableBox: box.inputBox }, box.scrollBarStyle));
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
// *** OBJECT INIT CODE:
|
|
194
|
+
|
|
195
|
+
// Event bindings
|
|
196
|
+
box.focusFunc = function () {
|
|
197
|
+
box.paintFocus(1);
|
|
198
|
+
box.onFocus(box);
|
|
199
|
+
}
|
|
200
|
+
textareaElem.addEventListener("focus", function(){ box.focusFunc() });
|
|
201
|
+
|
|
202
|
+
box.blurFunc = function () {
|
|
203
|
+
box.paintFocus(0);
|
|
204
|
+
box.onBlur(box);
|
|
205
|
+
}
|
|
206
|
+
textareaElem.addEventListener("blur", function(){ box.blurFunc() });
|
|
207
|
+
|
|
208
|
+
box.inputFunc = function () {
|
|
209
|
+
|
|
210
|
+
box.applyFormattedValueToInput();
|
|
211
|
+
box.checkIfInputIsRequiredAndEmpty();
|
|
212
|
+
box.showWarningIfNotValid(box.isValid());
|
|
213
|
+
|
|
214
|
+
// Refresh count on unit
|
|
215
|
+
refreshCount();
|
|
216
|
+
autoGrow(textareaElem);
|
|
217
|
+
|
|
218
|
+
box.onChange(box);
|
|
219
|
+
|
|
220
|
+
}
|
|
221
|
+
textareaElem.addEventListener("input", function(){ box.inputFunc() });
|
|
222
|
+
|
|
223
|
+
box.checkIfInputIsRequiredAndEmpty();
|
|
224
|
+
|
|
225
|
+
refreshCount();
|
|
226
|
+
|
|
227
|
+
box.onResize(function() {
|
|
228
|
+
autoGrow(textareaElem); // WHY: a field made or filled while hidden gets its height when it is shown
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
return endExtendedObject(box);
|
|
232
|
+
|
|
233
|
+
};
|