nice-elements 1.15.1 → 1.16.1

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/CLAUDE.md +1 -0
  3. package/README.md +1 -1
  4. package/bower.json +1 -1
  5. package/dist/nice.js +620 -509
  6. package/dist/nice.min.js +1 -1
  7. package/dist/style.css +145 -126
  8. package/dist/style.css.map +1 -1
  9. package/dist/style.min.css +2 -2
  10. package/package.json +5 -6
  11. package/src/components/nice-calendar/nice-calendar.html +3 -4
  12. package/src/components/nice-calendar/nice-calendar.scss +0 -9
  13. package/src/components/nice-date/nice-date-picker.html +60 -0
  14. package/src/components/nice-date/nice-date.html +29 -86
  15. package/src/components/nice-date/nice-date.js +7 -35
  16. package/src/components/nice-date/nice-date.scss +6 -15
  17. package/src/components/nice-datetime-picker/nice-datetime-picker.html +1 -4
  18. package/src/components/nice-datetime-picker/nice-datetime-picker.scss +9 -12
  19. package/src/components/nice-datetimerange-picker/nice-datetimerange-picker.html +1 -3
  20. package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.html +32 -30
  21. package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.js +1 -33
  22. package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.scss +7 -12
  23. package/src/components/nice-dropdown/nice-dropdown.html +42 -40
  24. package/src/components/nice-dropdown/nice-dropdown.js +52 -54
  25. package/src/components/nice-dropdown/nice-dropdown.scss +25 -4
  26. package/src/components/nice-dropdown-old/nice-dropdown-old.html +1 -1
  27. package/src/components/nice-dropdown-old/nice-dropdown-old.scss +8 -2
  28. package/src/components/nice-dtp/nice-dtp.html +7 -7
  29. package/src/components/nice-notification/nice-notification.html +6 -6
  30. package/src/components/nice-notification/nice-notification.scss +7 -6
  31. package/src/components/nice-options/nice-options.scss +4 -0
  32. package/src/components/nice-popup/nice-popup.html +4 -4
  33. package/src/components/nice-popup/nice-popup.js +61 -75
  34. package/src/components/nice-popup/nice-popup.scss +10 -31
  35. package/src/components/nice-search/nice-search.html +21 -26
  36. package/src/components/nice-search/nice-search.js +9 -12
  37. package/src/components/nice-search/nice-search.scss +9 -10
  38. package/src/components/nice-search2/nice-search2.html +22 -18
  39. package/src/components/nice-search2/nice-search2.js +12 -56
  40. package/src/components/nice-search2/nice-search2.scss +3 -2
  41. package/src/components/nice-svgs/nice-svgs.html +8 -0
  42. package/src/components/nice-time-picker/nice-time-picker.html +1 -3
  43. package/src/components/nice-time-picker/nice-time-picker.scss +0 -8
  44. package/src/directives/nice-tooltip/_nice-tooltip.scss +7 -28
  45. package/src/directives/nice-tooltip/nice-tooltip.js +16 -29
  46. package/src/services/nice-service.js +236 -1
  47. package/src/styles/_nice-anchored.scss +75 -0
  48. package/src/styles/_nice.scss +1 -0
@@ -2,9 +2,8 @@
2
2
  // cursor: help;
3
3
  }
4
4
 
5
+ // Positioning and arrow placement come from _nice-anchored.scss
5
6
  .nice-tooltip-window {
6
- display: none;
7
- position: relative;
8
7
  background: var(--nice-help-popup-bg);
9
8
  color: var(--nice-help-popup-color);
10
9
  max-width: 200px;
@@ -15,41 +14,21 @@
15
14
  font-weight: normal;
16
15
  text-transform: none;
17
16
 
18
- &[data-show] {
19
- display: block;
20
- }
21
-
22
- .nice-tooltip-window-arrow,
23
- .nice-tooltip-window-arrow::before {
24
- position: absolute;
25
- width: 8px;
26
- height: 8px;
27
- background: inherit;
17
+ &.nice-anchored-fallback {
18
+ z-index: 1100;
28
19
  }
29
20
 
30
21
  .nice-tooltip-window-arrow {
31
22
  visibility: hidden;
32
23
 
33
24
  &::before {
25
+ position: absolute;
26
+ width: 8px;
27
+ height: 8px;
28
+ background: var(--nice-help-popup-bg);
34
29
  visibility: visible;
35
30
  content: "";
36
31
  transform: rotate(45deg);
37
32
  }
38
33
  }
39
-
40
- &[data-popper-placement^="top"] > .nice-tooltip-window-arrow {
41
- bottom: -4px;
42
- }
43
-
44
- &[data-popper-placement^="bottom"] > .nice-tooltip-window-arrow {
45
- top: -4px;
46
- }
47
-
48
- &[data-popper-placement^="left"] > .nice-tooltip-window-arrow {
49
- right: -4px;
50
- }
51
-
52
- &[data-popper-placement^="right"] > .nice-tooltip-window-arrow {
53
- left: -4px;
54
- }
55
34
  }
@@ -5,24 +5,27 @@
5
5
  * @name niceElements.directive:niceTooltip
6
6
  * @description
7
7
  * # niceTooltip
8
+ * Positioned with NiceService.anchor() (native popover + CSS anchor positioning, Popper fallback).
8
9
  */
9
10
  angular.module('niceElements')
10
11
  .directive('niceTooltip', function () {
11
12
  return {
12
13
  restrict: 'A',
13
- controller: function ($scope, $element, $attrs, $injector) {
14
+ controller: function ($scope, $element, $attrs, $injector, NiceService) {
14
15
  const id = Math.random().toString(36).substring(7);
15
16
  const showEvents = ['mouseenter', 'focus'];
16
17
  const hideEvents = ['mouseleave', 'blur'];
17
- const placement = $attrs.niceTooltipPlacement || "top";
18
+ // "auto" variants → top variants (flips when there is no space)
19
+ const placement = ($attrs.niceTooltipPlacement || 'top').replace(/^auto/, 'top');
18
20
 
19
- // Create popper window
20
- $element.addClass("nice-tooltip");
21
+ // Create tooltip window
22
+ $element.addClass('nice-tooltip');
21
23
  const tooltipWindow = document.createElement('div');
22
24
  tooltipWindow.className = 'nice-tooltip-window';
23
25
  tooltipWindow.id = 'nice-tooltip-window-' + id;
26
+ tooltipWindow.setAttribute('role', 'tooltip');
24
27
 
25
- // Popper body. The attribute's {{ }} is interpolated by Angular, but the
28
+ // Tooltip body. The attribute's {{ }} is interpolated by Angular, but the
26
29
  // resulting text is never compiled, so user data can't run as a template.
27
30
  // Safe HTML is kept when the app loads ngSanitize; otherwise it's plain text.
28
31
  const content = document.createElement('div');
@@ -36,44 +39,28 @@ angular.module('niceElements')
36
39
  else content.textContent = value;
37
40
  });
38
41
 
39
- // Popper arrow
42
+ // Arrow
40
43
  const tooltipWindowArrow = document.createElement('div');
41
44
  tooltipWindowArrow.className = 'nice-tooltip-window-arrow';
42
- tooltipWindowArrow.setAttribute("data-popper-arrow", "");
43
45
  tooltipWindow.append(tooltipWindowArrow);
44
46
 
45
47
  // Add to body
46
48
  document.body.append(tooltipWindow);
47
49
 
48
- // Setup popper
49
- const popper = Popper.createPopper($element[0], tooltipWindow, {
50
+ const anchored = NiceService.anchor($element[0], tooltipWindow, {
50
51
  placement: placement,
51
- strategy: 'fixed',
52
- modifiers: [
53
- {
54
- name: 'offset',
55
- options: {
56
- offset: [0, 8],
57
- },
58
- },
59
- {
60
- name: 'arrow',
61
- options: {
62
- element: tooltipWindowArrow,
63
- padding: 3
64
- },
65
- },
66
- ],
52
+ offset: 8,
53
+ arrow: tooltipWindowArrow,
54
+ onEscape: hide
67
55
  });
68
56
 
69
57
  function show() {
70
58
  if ($attrs.niceTooltipDisabled == true || $attrs.niceTooltipDisabled == "true") return;
71
- tooltipWindow.setAttribute('data-show', '');
72
- popper.update();
59
+ anchored.open();
73
60
  }
74
61
 
75
62
  function hide() {
76
- tooltipWindow.removeAttribute('data-show');
63
+ anchored.close();
77
64
  }
78
65
 
79
66
  showEvents.forEach((event) => {
@@ -86,8 +73,8 @@ angular.module('niceElements')
86
73
 
87
74
  // On destroy
88
75
  $scope.$on('$destroy', function () {
76
+ anchored.destroy();
89
77
  tooltipWindow.remove();
90
- if (popper) popper.destroy();
91
78
  });
92
79
  }
93
80
  };
@@ -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.15.1",
151
+ version: "1.16.1",
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
+ }
@@ -28,6 +28,7 @@
28
28
  @import "nice-buttons";
29
29
  @import "nice-spacing";
30
30
  @import "nice-ngdialog";
31
+ @import "nice-anchored";
31
32
 
32
33
  @import "../components/nice-dropdown/nice-dropdown";
33
34
  @import "../components/nice-dropdown-old/nice-dropdown-old";