nice-elements 1.15.1 → 1.16.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.
- package/CHANGELOG.md +14 -0
- package/CLAUDE.md +1 -0
- package/README.md +1 -1
- package/bower.json +1 -1
- package/dist/nice.js +573 -468
- package/dist/nice.min.js +1 -1
- package/dist/style.css +122 -104
- package/dist/style.css.map +1 -1
- package/dist/style.min.css +2 -2
- package/package.json +5 -6
- package/src/components/nice-calendar/nice-calendar.html +3 -4
- package/src/components/nice-calendar/nice-calendar.scss +0 -9
- package/src/components/nice-date/nice-date-picker.html +60 -0
- package/src/components/nice-date/nice-date.html +29 -86
- package/src/components/nice-date/nice-date.js +7 -35
- package/src/components/nice-date/nice-date.scss +6 -15
- package/src/components/nice-datetime-picker/nice-datetime-picker.html +1 -4
- package/src/components/nice-datetime-picker/nice-datetime-picker.scss +9 -12
- package/src/components/nice-datetimerange-picker/nice-datetimerange-picker.html +1 -3
- package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.html +32 -30
- package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.js +1 -33
- package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.scss +7 -12
- package/src/components/nice-dropdown/nice-dropdown.html +42 -40
- package/src/components/nice-dropdown/nice-dropdown.js +52 -54
- package/src/components/nice-dropdown/nice-dropdown.scss +25 -4
- package/src/components/nice-dropdown-old/nice-dropdown-old.html +1 -1
- package/src/components/nice-dropdown-old/nice-dropdown-old.scss +8 -2
- package/src/components/nice-dtp/nice-dtp.html +7 -7
- package/src/components/nice-options/nice-options.scss +4 -0
- package/src/components/nice-popup/nice-popup.html +4 -4
- package/src/components/nice-popup/nice-popup.js +61 -75
- package/src/components/nice-popup/nice-popup.scss +10 -31
- package/src/components/nice-search/nice-search.html +0 -3
- package/src/components/nice-search2/nice-search2.html +22 -18
- package/src/components/nice-search2/nice-search2.js +1 -56
- package/src/components/nice-search2/nice-search2.scss +3 -2
- package/src/components/nice-svgs/nice-svgs.html +8 -0
- package/src/components/nice-time-picker/nice-time-picker.html +1 -3
- package/src/components/nice-time-picker/nice-time-picker.scss +0 -8
- package/src/directives/nice-tooltip/_nice-tooltip.scss +7 -28
- package/src/directives/nice-tooltip/nice-tooltip.js +16 -29
- package/src/services/nice-service.js +236 -1
- package/src/styles/_nice-anchored.scss +75 -0
- package/src/styles/_nice.scss +1 -0
|
@@ -8,9 +8,147 @@
|
|
|
8
8
|
*/
|
|
9
9
|
angular.module('niceElements')
|
|
10
10
|
.service('NiceService', function ($rootScope) {
|
|
11
|
+
// Can `el` scroll further in the wheel's direction?
|
|
12
|
+
function canScroll(el, deltaY) {
|
|
13
|
+
if (!/(auto|scroll)/.test(getComputedStyle(el).overflowY)) return false;
|
|
14
|
+
if (deltaY > 0) return el.scrollTop + el.clientHeight < el.scrollHeight;
|
|
15
|
+
return el.scrollTop > 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Nearest scrollable ancestor of `el` (null when only the page itself scrolls)
|
|
19
|
+
function scrollParent(el) {
|
|
20
|
+
for (el = el.parentElement; el && el !== document.body; el = el.parentElement) {
|
|
21
|
+
if (/(auto|scroll)/.test(getComputedStyle(el).overflowY) && el.scrollHeight > el.clientHeight) return el;
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Turns show/hide of NiceService.anchor() into open/close that, while open:
|
|
27
|
+
// - listen for Escape (options.onEscape decides what happens)
|
|
28
|
+
// - let the mouse wheel over the content scroll the page behind it
|
|
29
|
+
// - clip the content where the target scrolled out of its scroll container
|
|
30
|
+
function withEvents(target, content, options, mode) {
|
|
31
|
+
function onKeydown(event) {
|
|
32
|
+
if (event.key === 'Escape' && options.onEscape) options.onEscape(event);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// The content is position: fixed, so the browser only passes the wheel on to the
|
|
36
|
+
// window, never to the scroll container the target is in. Do that ourselves.
|
|
37
|
+
function onWheel(event) {
|
|
38
|
+
// Scrollable parts of the content (e.g. a long list) scroll themselves first
|
|
39
|
+
for (let el = event.target; el && el !== content.parentElement; el = el.parentElement) {
|
|
40
|
+
if (canScroll(el, event.deltaY)) return;
|
|
41
|
+
}
|
|
42
|
+
const scroller = scrollParent(target);
|
|
43
|
+
if (!scroller) return; // the window scrolls by itself
|
|
44
|
+
const lineHeight = event.deltaMode === 1 ? 16 : 1; // Firefox can report lines
|
|
45
|
+
scroller.scrollBy(event.deltaX * lineHeight, event.deltaY * lineHeight);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// The content is in the top layer, so the target's scroll container doesn't clip it.
|
|
49
|
+
// When the target scrolls out of that container (e.g. under the nice-view header),
|
|
50
|
+
// cut the content off at the container's edge on that side, so it slides under the
|
|
51
|
+
// header like normal content. Other sides stay open, so it can still stick out of
|
|
52
|
+
// a small scroll box or modal.
|
|
53
|
+
//
|
|
54
|
+
// The browser moves anchored content one frame after a scroll, so its position
|
|
55
|
+
// can't be read while scrolling. It moves together with the target though, so we
|
|
56
|
+
// measure its offset from the target once it has settled and add that to the
|
|
57
|
+
// target's (always current) position.
|
|
58
|
+
let offset = null;
|
|
59
|
+
function measure() {
|
|
60
|
+
const t = target.getBoundingClientRect();
|
|
61
|
+
const c = content.getBoundingClientRect();
|
|
62
|
+
offset = { top: c.top - t.top, left: c.left - t.left };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function clip() {
|
|
66
|
+
const scroller = scrollParent(target);
|
|
67
|
+
if (!scroller || !offset) {
|
|
68
|
+
content.style.clipPath = '';
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const box = scroller.getBoundingClientRect();
|
|
73
|
+
const t = target.getBoundingClientRect();
|
|
74
|
+
// Where the content is now: target position + measured offset
|
|
75
|
+
const c = {
|
|
76
|
+
top: t.top + offset.top,
|
|
77
|
+
left: t.left + offset.left,
|
|
78
|
+
bottom: t.top + offset.top + content.offsetHeight,
|
|
79
|
+
right: t.left + offset.left + content.offsetWidth
|
|
80
|
+
};
|
|
81
|
+
const open = -9999; // negative inset = no clipping (keeps arrow and shadow)
|
|
82
|
+
const top = t.top < box.top ? box.top - c.top : open;
|
|
83
|
+
const right = t.right > box.right ? c.right - box.right : open;
|
|
84
|
+
const bottom = t.bottom > box.bottom ? c.bottom - box.bottom : open;
|
|
85
|
+
const left = t.left < box.left ? box.left - c.left : open;
|
|
86
|
+
|
|
87
|
+
if (top == open && right == open && bottom == open && left == open) content.style.clipPath = '';
|
|
88
|
+
else content.style.clipPath = 'inset(' + top + 'px ' + right + 'px ' + bottom + 'px ' + left + 'px)';
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Measure again once things settled (two frames: the browser is one frame behind),
|
|
92
|
+
// e.g. after opening, a resize, or when scrolling stopped (it may have flipped)
|
|
93
|
+
let settleTimer = null;
|
|
94
|
+
function measureLater(delay) {
|
|
95
|
+
clearTimeout(settleTimer);
|
|
96
|
+
settleTimer = setTimeout(function () {
|
|
97
|
+
requestAnimationFrame(function () {
|
|
98
|
+
requestAnimationFrame(function () {
|
|
99
|
+
measure();
|
|
100
|
+
clip();
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}, delay);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function onScroll() {
|
|
107
|
+
clip();
|
|
108
|
+
measureLater(100);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function removeListeners() {
|
|
112
|
+
document.removeEventListener('keydown', onKeydown);
|
|
113
|
+
content.removeEventListener('wheel', onWheel);
|
|
114
|
+
document.removeEventListener('scroll', onScroll, true); // true: scroll of any element
|
|
115
|
+
window.removeEventListener('resize', onScroll);
|
|
116
|
+
clearTimeout(settleTimer);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function close() {
|
|
120
|
+
mode.hide();
|
|
121
|
+
removeListeners();
|
|
122
|
+
content.style.clipPath = '';
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
open: function () {
|
|
127
|
+
mode.show();
|
|
128
|
+
// remove first, so opening twice doesn't add them twice
|
|
129
|
+
removeListeners();
|
|
130
|
+
document.addEventListener('keydown', onKeydown);
|
|
131
|
+
content.addEventListener('wheel', onWheel, { passive: true });
|
|
132
|
+
document.addEventListener('scroll', onScroll, { capture: true, passive: true });
|
|
133
|
+
window.addEventListener('resize', onScroll);
|
|
134
|
+
offset = null;
|
|
135
|
+
measureLater(0);
|
|
136
|
+
},
|
|
137
|
+
close: close,
|
|
138
|
+
update: function () {
|
|
139
|
+
mode.update();
|
|
140
|
+
measureLater(0);
|
|
141
|
+
},
|
|
142
|
+
destroy: function () {
|
|
143
|
+
close();
|
|
144
|
+
mode.destroy();
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
11
149
|
const service = {
|
|
12
150
|
name: "Nice elements",
|
|
13
|
-
version: "1.
|
|
151
|
+
version: "1.16.0",
|
|
14
152
|
getHeader: function () {
|
|
15
153
|
return {};
|
|
16
154
|
},
|
|
@@ -32,6 +170,103 @@ angular.module('niceElements')
|
|
|
32
170
|
$scope[name] = service.isOn(value);
|
|
33
171
|
});
|
|
34
172
|
},
|
|
173
|
+
// Can the browser position popovers natively (popover API + CSS anchor positioning)?
|
|
174
|
+
supportsAnchor: function () {
|
|
175
|
+
return !!(window.CSS && CSS.supports('anchor-name', '--a') && ('popover' in HTMLElement.prototype));
|
|
176
|
+
},
|
|
177
|
+
// Position `content` next to `target` (used by nice-popup and nice-tooltip).
|
|
178
|
+
// Native: content becomes a manual popover (top layer) positioned with CSS anchor
|
|
179
|
+
// positioning, see src/styles/_nice-anchored.scss. Fallback: Popper.js.
|
|
180
|
+
// options: placement ("bottom-start", "auto", ...), offset (px gap), skidding (px shift
|
|
181
|
+
// along the target), sameWidth (content as wide as target), arrow (element inside content),
|
|
182
|
+
// onEscape (called when Escape is pressed while open; the owner closes it).
|
|
183
|
+
// While open, the mouse wheel over the content scrolls the page behind it.
|
|
184
|
+
// Returns { open(), close(), update(), destroy() }
|
|
185
|
+
anchor: function (target, content, options) {
|
|
186
|
+
options = options || {};
|
|
187
|
+
const placement = options.placement || 'bottom';
|
|
188
|
+
const offset = options.offset || 0;
|
|
189
|
+
const skidding = options.skidding || 0;
|
|
190
|
+
|
|
191
|
+
if (service.supportsAnchor()) {
|
|
192
|
+
// "auto" → bottom, CSS flips it when there is no space
|
|
193
|
+
const native = placement.replace(/^auto/, 'bottom');
|
|
194
|
+
const side = native.split('-')[0];
|
|
195
|
+
const align = native.split('-')[1];
|
|
196
|
+
const vertical = side == 'top' || side == 'bottom';
|
|
197
|
+
|
|
198
|
+
// position-area: side + alignment (start/end = align with the target's start/end edge)
|
|
199
|
+
let area = side;
|
|
200
|
+
if (align == 'start') area += vertical ? ' span-right' : ' span-bottom';
|
|
201
|
+
if (align == 'end') area += vertical ? ' span-left' : ' span-top';
|
|
202
|
+
|
|
203
|
+
// Unique anchor names: one for the target, one for the content (the arrow uses both)
|
|
204
|
+
const name = '--nice-anchor-' + Math.random().toString(36).substring(7);
|
|
205
|
+
target.style.anchorName = name;
|
|
206
|
+
content.setAttribute('popover', 'manual');
|
|
207
|
+
content.classList.add('nice-anchored', 'nice-anchored--' + side);
|
|
208
|
+
if (options.sameWidth) content.classList.add('nice-anchored--same-width');
|
|
209
|
+
content.style.positionAnchor = name;
|
|
210
|
+
content.style.positionArea = area;
|
|
211
|
+
content.style.anchorName = name + '-content';
|
|
212
|
+
content.style.setProperty('--nice-anchored', name + '-content');
|
|
213
|
+
content.style.setProperty('--nice-anchored-offset', offset + 'px');
|
|
214
|
+
// Skidding is a translate. Only set when used: translate makes the content the
|
|
215
|
+
// containing block of the fixed arrow, so the arrow can't use anchor() any more.
|
|
216
|
+
if (skidding) content.style.translate = vertical ? skidding + 'px 0' : '0 ' + skidding + 'px';
|
|
217
|
+
if (options.arrow) options.arrow.classList.add('nice-anchored-arrow');
|
|
218
|
+
|
|
219
|
+
const isOpen = function () { return content.matches(':popover-open'); };
|
|
220
|
+
return withEvents(target, content, options, {
|
|
221
|
+
show: function () { if (!isOpen() && content.isConnected) content.showPopover(); },
|
|
222
|
+
hide: function () { if (isOpen()) content.hidePopover(); },
|
|
223
|
+
update: function () { }, // the browser keeps it positioned
|
|
224
|
+
destroy: function () { }
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Fallback: Popper.js (content is shown with the [data-show] attribute)
|
|
229
|
+
// https://popper.js.org/docs/v2/constructors/
|
|
230
|
+
content.classList.add('nice-anchored-fallback');
|
|
231
|
+
if (options.arrow) {
|
|
232
|
+
options.arrow.classList.add('nice-anchored-arrow');
|
|
233
|
+
options.arrow.setAttribute('data-popper-arrow', '');
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const modifiers = [
|
|
237
|
+
{ name: 'offset', options: { offset: [skidding, offset] } },
|
|
238
|
+
{ name: 'arrow', options: { padding: 5 } }
|
|
239
|
+
];
|
|
240
|
+
if (options.sameWidth) {
|
|
241
|
+
modifiers.push({
|
|
242
|
+
name: 'sameWidth',
|
|
243
|
+
enabled: true,
|
|
244
|
+
phase: 'beforeWrite',
|
|
245
|
+
requires: ['computeStyles'],
|
|
246
|
+
fn: function (e) {
|
|
247
|
+
e.state.styles.popper.width = e.state.rects.reference.width + 'px';
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const popper = Popper.createPopper(target, content, {
|
|
253
|
+
placement: placement,
|
|
254
|
+
strategy: options.strategy || 'fixed',
|
|
255
|
+
modifiers: modifiers
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
return withEvents(target, content, options, {
|
|
259
|
+
show: function () {
|
|
260
|
+
content.setAttribute('data-show', '');
|
|
261
|
+
popper.update();
|
|
262
|
+
},
|
|
263
|
+
hide: function () {
|
|
264
|
+
content.removeAttribute('data-show');
|
|
265
|
+
},
|
|
266
|
+
update: function () { popper.update(); },
|
|
267
|
+
destroy: function () { popper.destroy(); }
|
|
268
|
+
});
|
|
269
|
+
},
|
|
35
270
|
// Check if value is a Decimal.js object (also Decimal.clone() instances)
|
|
36
271
|
isDecimal: function (value) {
|
|
37
272
|
return typeof Decimal !== 'undefined' && Decimal.isDecimal(value);
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Content positioned with NiceService.anchor() (nice-popup, nice-tooltip).
|
|
2
|
+
// position-anchor, position-area and the --nice-anchored-* variables are set inline by the service.
|
|
3
|
+
|
|
4
|
+
// ------------------------ Native: popover + CSS anchor positioning ------------------------
|
|
5
|
+
.nice-anchored {
|
|
6
|
+
// Reset browser popover styles
|
|
7
|
+
inset: auto;
|
|
8
|
+
margin: 0;
|
|
9
|
+
padding: 0;
|
|
10
|
+
border: 0;
|
|
11
|
+
overflow: visible; // let the arrow stick out
|
|
12
|
+
background: transparent;
|
|
13
|
+
color: inherit;
|
|
14
|
+
|
|
15
|
+
// Flip to the other side when there is not enough space
|
|
16
|
+
position-try-fallbacks: flip-block, flip-inline, flip-block flip-inline;
|
|
17
|
+
|
|
18
|
+
// Stay visible when the target is scrolled out of view, same as the Popper fallback
|
|
19
|
+
// (the browser default "anchors-visible" hides it)
|
|
20
|
+
position-visibility: always;
|
|
21
|
+
|
|
22
|
+
// Gap to the target (margins are flipped together with the side)
|
|
23
|
+
&--top { margin-bottom: var(--nice-anchored-offset); }
|
|
24
|
+
&--bottom { margin-top: var(--nice-anchored-offset); }
|
|
25
|
+
&--left { margin-right: var(--nice-anchored-offset); }
|
|
26
|
+
&--right { margin-left: var(--nice-anchored-offset); }
|
|
27
|
+
|
|
28
|
+
&--same-width {
|
|
29
|
+
width: anchor-size(width);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Arrow (8×8). Fixed so it can use anchor(): the target is its default anchor
|
|
33
|
+
// (position-anchor inherited from the content), the content is var(--nice-anchored).
|
|
34
|
+
// It points at the target's center, clamped between the content's edges. On the
|
|
35
|
+
// placement axis it clamps to the edge facing the target, so it follows a flip.
|
|
36
|
+
> .nice-anchored-arrow {
|
|
37
|
+
position: fixed;
|
|
38
|
+
position-anchor: inherit;
|
|
39
|
+
width: 8px;
|
|
40
|
+
height: 8px;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
&--top > .nice-anchored-arrow,
|
|
44
|
+
&--bottom > .nice-anchored-arrow {
|
|
45
|
+
top: clamp(anchor(var(--nice-anchored) top) - 4px, anchor(center) - 4px, anchor(var(--nice-anchored) bottom) - 4px);
|
|
46
|
+
left: clamp(anchor(var(--nice-anchored) left) + 4px, anchor(center) - 4px, anchor(var(--nice-anchored) right) - 12px);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
&--left > .nice-anchored-arrow,
|
|
50
|
+
&--right > .nice-anchored-arrow {
|
|
51
|
+
left: clamp(anchor(var(--nice-anchored) left) - 4px, anchor(center) - 4px, anchor(var(--nice-anchored) right) - 4px);
|
|
52
|
+
top: clamp(anchor(var(--nice-anchored) top) + 4px, anchor(center) - 4px, anchor(var(--nice-anchored) bottom) - 12px);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ------------------------ Fallback: Popper.js ------------------------
|
|
57
|
+
.nice-anchored-fallback {
|
|
58
|
+
display: none;
|
|
59
|
+
z-index: 1000;
|
|
60
|
+
|
|
61
|
+
&[data-show] {
|
|
62
|
+
display: block;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
> .nice-anchored-arrow {
|
|
66
|
+
position: absolute;
|
|
67
|
+
width: 8px;
|
|
68
|
+
height: 8px;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
&[data-popper-placement^="top"] > .nice-anchored-arrow { bottom: -4px; }
|
|
72
|
+
&[data-popper-placement^="bottom"] > .nice-anchored-arrow { top: -4px; }
|
|
73
|
+
&[data-popper-placement^="left"] > .nice-anchored-arrow { right: -4px; }
|
|
74
|
+
&[data-popper-placement^="right"] > .nice-anchored-arrow { left: -4px; }
|
|
75
|
+
}
|
package/src/styles/_nice.scss
CHANGED