@ionic/core 7.5.7-dev.11701113479.149fdab6 → 7.5.7-dev.11701201960.104b3a1f
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/components/data.js +1 -1
- package/components/ion-datetime.js +16 -16
- package/components/{ion-picker-internal.d.ts → ion-picker-column.d.ts} +4 -4
- package/components/ion-picker-column.js +9 -0
- package/components/ion-picker-legacy-column.js +1 -1
- package/components/ion-picker-legacy.js +2 -2
- package/components/ion-picker.d.ts +11 -0
- package/components/ion-picker.js +9 -0
- package/components/picker-column.js +333 -322
- package/components/picker-column2.js +379 -0
- package/components/{picker-internal.js → picker.js} +16 -16
- package/dist/cjs/{data-c8d21093.js → data-4845b494.js} +1 -1
- package/dist/cjs/ion-datetime-button.cjs.entry.js +1 -1
- package/dist/cjs/ion-datetime_3.cjs.entry.js +13 -13
- package/dist/cjs/{ion-picker-column-internal.cjs.entry.js → ion-picker-column.cjs.entry.js} +9 -9
- package/dist/cjs/{ion-picker-internal.cjs.entry.js → ion-picker.cjs.entry.js} +13 -13
- package/dist/cjs/ionic.cjs.js +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/collection/collection-manifest.json +3 -3
- package/dist/collection/components/datetime/datetime.ios.css +1 -1
- package/dist/collection/components/datetime/datetime.js +9 -9
- package/dist/collection/components/datetime/datetime.md.css +1 -1
- package/dist/collection/components/datetime/test/disabled/datetime.spec.js +4 -4
- package/dist/collection/components/datetime/test/minmax/datetime.e2e.js +5 -5
- package/dist/collection/components/datetime/test/prefer-wheel/datetime.e2e.js +2 -2
- package/dist/collection/components/datetime/test/presentation/datetime.e2e.js +1 -1
- package/dist/collection/components/datetime/test/values/datetime.e2e.js +5 -5
- package/dist/collection/components/datetime/utils/data.js +1 -1
- package/dist/collection/components/{picker-internal/picker-internal.ios.css → picker/picker.ios.css} +3 -3
- package/dist/collection/components/{picker-internal/picker-internal.js → picker/picker.js} +17 -18
- package/dist/collection/components/{picker-internal/picker-internal.md.css → picker/picker.md.css} +3 -3
- package/dist/collection/components/{picker-internal/test/a11y/picker-internal.e2e.js → picker/test/a11y/picker.e2e.js} +2 -2
- package/dist/collection/components/{picker-internal/test/basic/picker-internal.e2e.js → picker/test/basic/picker.e2e.js} +22 -22
- package/dist/collection/components/{picker-internal/test/keyboard-entry/picker-internal.e2e.js → picker/test/keyboard-entry/picker.e2e.js} +20 -20
- package/dist/collection/components/{picker-column-internal/picker-column-internal.js → picker-column/picker-column.js} +12 -13
- package/dist/collection/components/{picker-column-internal/test/basic/picker-column-internal.e2e.js → picker-column/test/basic/picker-column.e2e.js} +7 -7
- package/dist/collection/components/{picker-column-internal/test/disabled/picker-column-internal.e2e.js → picker-column/test/disabled/picker-column.e2e.js} +39 -39
- package/dist/collection/components/picker-legacy/picker.js +1 -1
- package/dist/collection/components/{picker-column-legacy → picker-legacy-column}/test/standalone/picker-column.e2e.js +1 -1
- package/dist/docs.json +307 -14
- package/dist/esm/{data-44d9e816.js → data-12e24f00.js} +1 -1
- package/dist/esm/ion-datetime-button.entry.js +1 -1
- package/dist/esm/ion-datetime_3.entry.js +13 -13
- package/dist/esm/{ion-picker-column-internal.entry.js → ion-picker-column.entry.js} +9 -9
- package/dist/esm/{ion-picker-internal.entry.js → ion-picker.entry.js} +13 -13
- package/dist/esm/ionic.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm-es5/ion-datetime-button.entry.js +1 -1
- package/dist/esm-es5/ion-datetime_3.entry.js +1 -1
- package/dist/esm-es5/ion-picker-column.entry.js +4 -0
- package/dist/esm-es5/ion-picker.entry.js +4 -0
- package/dist/esm-es5/ionic.js +1 -1
- package/dist/esm-es5/loader.js +1 -1
- package/dist/html.html-data.json +95 -0
- package/dist/ionic/ionic.esm.js +1 -1
- package/dist/ionic/p-39074595.entry.js +4 -0
- package/dist/ionic/p-40903d34.system.js +1 -1
- package/dist/ionic/p-439e20ef.entry.js +4 -0
- package/dist/ionic/p-7c66a566.system.entry.js +4 -0
- package/dist/ionic/p-9403b297.system.entry.js +4 -0
- package/dist/ionic/p-ba70d455.entry.js +4 -0
- package/dist/ionic/{p-8ad82eb3.entry.js → p-baa7cb1e.entry.js} +1 -1
- package/dist/ionic/p-c32bf078.system.entry.js +4 -0
- package/dist/ionic/{p-4c80afe1.system.entry.js → p-cb62e3fc.system.entry.js} +1 -1
- package/dist/types/components/datetime/utils/data.d.ts +2 -2
- package/dist/types/components/picker/picker-interfaces.d.ts +8 -0
- package/dist/types/components/{picker-internal/picker-internal.d.ts → picker/picker.d.ts} +4 -5
- package/dist/types/components/{picker-column-internal/picker-column-internal.d.ts → picker-column/picker-column.d.ts} +3 -4
- package/dist/types/components.d.ts +47 -47
- package/hydrate/index.js +1046 -1048
- package/package.json +1 -1
- package/components/ion-picker-column-internal.d.ts +0 -11
- package/components/ion-picker-column-internal.js +0 -9
- package/components/ion-picker-internal.js +0 -9
- package/components/picker-column-internal.js +0 -390
- package/dist/esm-es5/ion-picker-column-internal.entry.js +0 -4
- package/dist/esm-es5/ion-picker-internal.entry.js +0 -4
- package/dist/ionic/p-1a368f2e.system.entry.js +0 -4
- package/dist/ionic/p-29fe18ef.entry.js +0 -4
- package/dist/ionic/p-5bd4e009.entry.js +0 -4
- package/dist/ionic/p-beb64be7.system.entry.js +0 -4
- package/dist/ionic/p-c56b6570.system.entry.js +0 -4
- package/dist/ionic/p-c59d068a.entry.js +0 -4
- package/dist/types/components/picker-internal/picker-internal-interfaces.d.ts +0 -8
- /package/dist/collection/components/{picker-internal/picker-internal-interfaces.js → picker/picker-interfaces.js} +0 -0
- /package/dist/collection/components/{picker-column-internal/picker-column-internal-interfaces.js → picker-column/picker-column-interfaces.js} +0 -0
- /package/dist/collection/components/{picker-column-internal/picker-column-internal.ios.css → picker-column/picker-column.ios.css} +0 -0
- /package/dist/collection/components/{picker-column-internal/picker-column-internal.md.css → picker-column/picker-column.md.css} +0 -0
- /package/dist/collection/components/{picker-column-legacy → picker-legacy-column}/picker-column.ios.css +0 -0
- /package/dist/collection/components/{picker-column-legacy → picker-legacy-column}/picker-column.js +0 -0
- /package/dist/collection/components/{picker-column-legacy → picker-legacy-column}/picker-column.md.css +0 -0
- /package/dist/collection/components/{picker-column-legacy → picker-legacy-column}/test/picker-column-aria.spec.js +0 -0
- /package/dist/collection/components/{picker-column-legacy → picker-legacy-column}/test/picker-column-dynamic.spec.js +0 -0
- /package/dist/collection/components/{picker-column-legacy → picker-legacy-column}/test/picker-column.spec.js +0 -0
- /package/dist/collection/components/{picker-column-legacy → picker-legacy-column}/test/test.utils.js +0 -0
- /package/dist/esm-es5/{data-44d9e816.js → data-12e24f00.js} +0 -0
- /package/dist/ionic/{p-17240d90.js → p-bb849ebb.js} +0 -0
- /package/dist/ionic/{p-b8c3f071.system.js → p-e4219e27.system.js} +0 -0
- /package/dist/types/components/{picker-column-internal/picker-column-internal-interfaces.d.ts → picker-column/picker-column-interfaces.d.ts} +0 -0
- /package/dist/types/components/{picker-column-legacy → picker-legacy-column}/picker-column.d.ts +0 -0
- /package/dist/types/components/{picker-column-legacy → picker-legacy-column}/test/test.utils.d.ts +0 -0
|
@@ -2,378 +2,389 @@
|
|
|
2
2
|
* (C) Ionic http://ionicframework.com - MIT License
|
|
3
3
|
*/
|
|
4
4
|
import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
5
|
+
import { r as raf, g as getElementRoot } from './helpers.js';
|
|
6
|
+
import { a as hapticSelectionStart, b as hapticSelectionChanged, h as hapticSelectionEnd } from './haptic.js';
|
|
7
|
+
import { a as isPlatform, b as getIonMode } from './ionic-global.js';
|
|
8
|
+
import { c as createColorClasses } from './theme.js';
|
|
9
9
|
|
|
10
|
-
const pickerColumnIosCss = "
|
|
10
|
+
const pickerColumnIosCss = ":host{-webkit-padding-start:16px;padding-inline-start:16px;-webkit-padding-end:16px;padding-inline-end:16px;padding-top:0px;padding-bottom:0px;height:200px;outline:none;font-size:22px;-webkit-scroll-snap-type:y mandatory;-ms-scroll-snap-type:y mandatory;scroll-snap-type:y mandatory;overflow-x:hidden;overflow-y:scroll;scrollbar-width:none;text-align:center}:host::-webkit-scrollbar{display:none}:host .picker-item{padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;margin-left:0;margin-right:0;margin-top:0;margin-bottom:0;display:block;width:100%;height:34px;border:0px;outline:none;background:transparent;color:inherit;font-family:var(--ion-font-family, inherit);font-size:inherit;line-height:34px;text-align:inherit;text-overflow:ellipsis;white-space:nowrap;cursor:pointer;overflow:hidden;scroll-snap-align:center}:host .picker-item-empty,:host .picker-item[disabled]{cursor:default}:host .picker-item-empty,:host(:not([disabled])) .picker-item[disabled]{scroll-snap-align:none}:host([disabled]){overflow-y:hidden}:host .picker-item[disabled]{opacity:0.4}:host(.picker-column-active) .picker-item.picker-item-active{color:var(--ion-color-base)}@media (any-hover: hover){:host(:focus){outline:none;background:rgba(var(--ion-color-base-rgb), 0.2)}}";
|
|
11
11
|
|
|
12
|
-
const pickerColumnMdCss = "
|
|
12
|
+
const pickerColumnMdCss = ":host{-webkit-padding-start:16px;padding-inline-start:16px;-webkit-padding-end:16px;padding-inline-end:16px;padding-top:0px;padding-bottom:0px;height:200px;outline:none;font-size:22px;-webkit-scroll-snap-type:y mandatory;-ms-scroll-snap-type:y mandatory;scroll-snap-type:y mandatory;overflow-x:hidden;overflow-y:scroll;scrollbar-width:none;text-align:center}:host::-webkit-scrollbar{display:none}:host .picker-item{padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;margin-left:0;margin-right:0;margin-top:0;margin-bottom:0;display:block;width:100%;height:34px;border:0px;outline:none;background:transparent;color:inherit;font-family:var(--ion-font-family, inherit);font-size:inherit;line-height:34px;text-align:inherit;text-overflow:ellipsis;white-space:nowrap;cursor:pointer;overflow:hidden;scroll-snap-align:center}:host .picker-item-empty,:host .picker-item[disabled]{cursor:default}:host .picker-item-empty,:host(:not([disabled])) .picker-item[disabled]{scroll-snap-align:none}:host([disabled]){overflow-y:hidden}:host .picker-item[disabled]{opacity:0.4}:host(.picker-column-active) .picker-item.picker-item-active{color:var(--ion-color-base)}@media (any-hover: hover){:host(:focus){outline:none;background:rgba(var(--ion-color-base-rgb), 0.2)}}:host .picker-item-active{color:var(--ion-color-base)}";
|
|
13
13
|
|
|
14
|
-
const
|
|
14
|
+
const PickerColumn = /*@__PURE__*/ proxyCustomElement(class PickerColumn extends HTMLElement {
|
|
15
15
|
constructor() {
|
|
16
16
|
super();
|
|
17
17
|
this.__registerHost();
|
|
18
|
-
this.
|
|
19
|
-
this.
|
|
20
|
-
this.
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
23
|
-
this.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (mode === 'ios') {
|
|
43
|
-
pickerRotateFactor = -0.46;
|
|
44
|
-
pickerScaleFactor = 1;
|
|
45
|
-
}
|
|
46
|
-
this.rotateFactor = pickerRotateFactor;
|
|
47
|
-
this.scaleFactor = pickerScaleFactor;
|
|
48
|
-
this.gesture = (await import('./index3.js')).createGesture({
|
|
49
|
-
el: this.el,
|
|
50
|
-
gestureName: 'picker-swipe',
|
|
51
|
-
gesturePriority: 100,
|
|
52
|
-
threshold: 0,
|
|
53
|
-
passive: false,
|
|
54
|
-
onStart: (ev) => this.onStart(ev),
|
|
55
|
-
onMove: (ev) => this.onMove(ev),
|
|
56
|
-
onEnd: (ev) => this.onEnd(ev),
|
|
57
|
-
});
|
|
58
|
-
this.gesture.enable();
|
|
59
|
-
// Options have not been initialized yet
|
|
60
|
-
// Animation must be disabled through the `noAnimate` flag
|
|
61
|
-
// Otherwise, the options will render
|
|
62
|
-
// at the top of the column and transition down
|
|
63
|
-
this.tmrId = setTimeout(() => {
|
|
64
|
-
this.noAnimate = false;
|
|
65
|
-
// After initialization, `refresh()` will be called
|
|
66
|
-
// At this point, animation will be enabled. The options will
|
|
67
|
-
// animate as they are being selected.
|
|
68
|
-
this.refresh(true);
|
|
69
|
-
}, 250);
|
|
70
|
-
}
|
|
71
|
-
componentDidLoad() {
|
|
72
|
-
this.onDomChange();
|
|
73
|
-
}
|
|
74
|
-
componentDidUpdate() {
|
|
75
|
-
// Options may have changed since last update.
|
|
76
|
-
if (this.colDidChange) {
|
|
77
|
-
// Animation must be disabled through the `onDomChange` parameter.
|
|
78
|
-
// Otherwise, the recently added options will render
|
|
79
|
-
// at the top of the column and transition down
|
|
80
|
-
this.onDomChange(true, false);
|
|
81
|
-
this.colDidChange = false;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
disconnectedCallback() {
|
|
85
|
-
if (this.rafId !== undefined)
|
|
86
|
-
cancelAnimationFrame(this.rafId);
|
|
87
|
-
if (this.tmrId)
|
|
88
|
-
clearTimeout(this.tmrId);
|
|
89
|
-
if (this.gesture) {
|
|
90
|
-
this.gesture.destroy();
|
|
91
|
-
this.gesture = undefined;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
emitColChange() {
|
|
95
|
-
this.ionPickerColChange.emit(this.col);
|
|
96
|
-
}
|
|
97
|
-
setSelected(selectedIndex, duration) {
|
|
98
|
-
// if there is a selected index, then figure out it's y position
|
|
99
|
-
// if there isn't a selected index, then just use the top y position
|
|
100
|
-
const y = selectedIndex > -1 ? -(selectedIndex * this.optHeight) : 0;
|
|
101
|
-
this.velocity = 0;
|
|
102
|
-
// set what y position we're at
|
|
103
|
-
if (this.rafId !== undefined)
|
|
104
|
-
cancelAnimationFrame(this.rafId);
|
|
105
|
-
this.update(y, duration, true);
|
|
106
|
-
this.emitColChange();
|
|
107
|
-
}
|
|
108
|
-
update(y, duration, saveY) {
|
|
109
|
-
if (!this.optsEl) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
// ensure we've got a good round number :)
|
|
113
|
-
let translateY = 0;
|
|
114
|
-
let translateZ = 0;
|
|
115
|
-
const { col, rotateFactor } = this;
|
|
116
|
-
const prevSelected = col.selectedIndex;
|
|
117
|
-
const selectedIndex = (col.selectedIndex = this.indexForY(-y));
|
|
118
|
-
const durationStr = duration === 0 ? '' : duration + 'ms';
|
|
119
|
-
const scaleStr = `scale(${this.scaleFactor})`;
|
|
120
|
-
const children = this.optsEl.children;
|
|
121
|
-
for (let i = 0; i < children.length; i++) {
|
|
122
|
-
const button = children[i];
|
|
123
|
-
const opt = col.options[i];
|
|
124
|
-
const optOffset = i * this.optHeight + y;
|
|
125
|
-
let transform = '';
|
|
126
|
-
if (rotateFactor !== 0) {
|
|
127
|
-
const rotateX = optOffset * rotateFactor;
|
|
128
|
-
if (Math.abs(rotateX) <= 90) {
|
|
129
|
-
translateY = 0;
|
|
130
|
-
translateZ = 90;
|
|
131
|
-
transform = `rotateX(${rotateX}deg) `;
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
translateY = -9999;
|
|
18
|
+
this.__attachShadow();
|
|
19
|
+
this.ionChange = createEvent(this, "ionChange", 7);
|
|
20
|
+
this.isScrolling = false;
|
|
21
|
+
this.isColumnVisible = false;
|
|
22
|
+
this.canExitInputMode = true;
|
|
23
|
+
this.centerPickerItemInView = (target, smooth = true, canExitInputMode = true) => {
|
|
24
|
+
const { el, isColumnVisible } = this;
|
|
25
|
+
if (isColumnVisible) {
|
|
26
|
+
// (Vertical offset from parent) - (three empty picker rows) + (half the height of the target to ensure the scroll triggers)
|
|
27
|
+
const top = target.offsetTop - 3 * target.clientHeight + target.clientHeight / 2;
|
|
28
|
+
if (el.scrollTop !== top) {
|
|
29
|
+
/**
|
|
30
|
+
* Setting this flag prevents input
|
|
31
|
+
* mode from exiting in the picker column's
|
|
32
|
+
* scroll callback. This is useful when the user manually
|
|
33
|
+
* taps an item or types on the keyboard as both
|
|
34
|
+
* of these can cause a scroll to occur.
|
|
35
|
+
*/
|
|
36
|
+
this.canExitInputMode = canExitInputMode;
|
|
37
|
+
el.scroll({
|
|
38
|
+
top,
|
|
39
|
+
left: 0,
|
|
40
|
+
behavior: smooth ? 'smooth' : undefined,
|
|
41
|
+
});
|
|
135
42
|
}
|
|
136
43
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
transform += `translate3d(0px,${translateY}px,${translateZ}px) `;
|
|
143
|
-
if (this.scaleFactor !== 1 && !selected) {
|
|
144
|
-
transform += scaleStr;
|
|
44
|
+
};
|
|
45
|
+
this.setPickerItemActiveState = (item, isActive) => {
|
|
46
|
+
if (isActive) {
|
|
47
|
+
item.classList.add(PICKER_ITEM_ACTIVE_CLASS);
|
|
48
|
+
item.part.add(PICKER_ITEM_ACTIVE_PART);
|
|
145
49
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
button.style.transitionDuration = '';
|
|
150
|
-
}
|
|
151
|
-
else if (duration !== opt.duration) {
|
|
152
|
-
opt.duration = duration;
|
|
153
|
-
button.style.transitionDuration = durationStr;
|
|
50
|
+
else {
|
|
51
|
+
item.classList.remove(PICKER_ITEM_ACTIVE_CLASS);
|
|
52
|
+
item.part.remove(PICKER_ITEM_ACTIVE_PART);
|
|
154
53
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* When ionInputModeChange is emitted, each column
|
|
57
|
+
* needs to check if it is the one being made available
|
|
58
|
+
* for text entry.
|
|
59
|
+
*/
|
|
60
|
+
this.inputModeChange = (ev) => {
|
|
61
|
+
if (!this.numericInput) {
|
|
62
|
+
return;
|
|
158
63
|
}
|
|
159
|
-
|
|
64
|
+
const { useInputMode, inputModeColumn } = ev.detail;
|
|
160
65
|
/**
|
|
161
|
-
*
|
|
162
|
-
*
|
|
66
|
+
* If inputModeColumn is undefined then this means
|
|
67
|
+
* all numericInput columns are being selected.
|
|
163
68
|
*/
|
|
164
|
-
|
|
165
|
-
if (
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
else {
|
|
169
|
-
button.classList.remove(PICKER_OPT_SELECTED);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
this.col.prevSelected = prevSelected;
|
|
173
|
-
if (saveY) {
|
|
174
|
-
this.y = y;
|
|
175
|
-
}
|
|
176
|
-
if (this.lastIndex !== selectedIndex) {
|
|
177
|
-
// have not set a last index yet
|
|
178
|
-
hapticSelectionChanged();
|
|
179
|
-
this.lastIndex = selectedIndex;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
decelerate() {
|
|
183
|
-
if (this.velocity !== 0) {
|
|
184
|
-
// still decelerating
|
|
185
|
-
this.velocity *= DECELERATION_FRICTION;
|
|
186
|
-
// do not let it go slower than a velocity of 1
|
|
187
|
-
this.velocity = this.velocity > 0 ? Math.max(this.velocity, 1) : Math.min(this.velocity, -1);
|
|
188
|
-
let y = this.y + this.velocity;
|
|
189
|
-
if (y > this.minY) {
|
|
190
|
-
// whoops, it's trying to scroll up farther than the options we have!
|
|
191
|
-
y = this.minY;
|
|
192
|
-
this.velocity = 0;
|
|
69
|
+
const isColumnActive = inputModeColumn === undefined || inputModeColumn === this.el;
|
|
70
|
+
if (!useInputMode || !isColumnActive) {
|
|
71
|
+
this.setInputModeActive(false);
|
|
72
|
+
return;
|
|
193
73
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
this.
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
else if (this.y % this.optHeight !== 0) {
|
|
212
|
-
// needs to still get locked into a position so options line up
|
|
213
|
-
const currentPos = Math.abs(this.y % this.optHeight);
|
|
214
|
-
// create a velocity in the direction it needs to scroll
|
|
215
|
-
this.velocity = currentPos > this.optHeight / 2 ? 1 : -1;
|
|
216
|
-
this.decelerate();
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
indexForY(y) {
|
|
220
|
-
return Math.min(Math.max(Math.abs(Math.round(y / this.optHeight)), 0), this.col.options.length - 1);
|
|
221
|
-
}
|
|
222
|
-
onStart(detail) {
|
|
223
|
-
// We have to prevent default in order to block scrolling under the picker
|
|
224
|
-
// but we DO NOT have to stop propagation, since we still want
|
|
225
|
-
// some "click" events to capture
|
|
226
|
-
if (detail.event.cancelable) {
|
|
227
|
-
detail.event.preventDefault();
|
|
228
|
-
}
|
|
229
|
-
detail.event.stopPropagation();
|
|
230
|
-
hapticSelectionStart();
|
|
231
|
-
// reset everything
|
|
232
|
-
if (this.rafId !== undefined)
|
|
233
|
-
cancelAnimationFrame(this.rafId);
|
|
234
|
-
const options = this.col.options;
|
|
235
|
-
let minY = options.length - 1;
|
|
236
|
-
let maxY = 0;
|
|
237
|
-
for (let i = 0; i < options.length; i++) {
|
|
238
|
-
if (!options[i].disabled) {
|
|
239
|
-
minY = Math.min(minY, i);
|
|
240
|
-
maxY = Math.max(maxY, i);
|
|
74
|
+
this.setInputModeActive(true);
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Setting isActive will cause a re-render.
|
|
78
|
+
* As a result, we do not want to cause the
|
|
79
|
+
* re-render mid scroll as this will cause
|
|
80
|
+
* the picker column to jump back to
|
|
81
|
+
* whatever value was selected at the
|
|
82
|
+
* start of the scroll interaction.
|
|
83
|
+
*/
|
|
84
|
+
this.setInputModeActive = (state) => {
|
|
85
|
+
if (this.isScrolling) {
|
|
86
|
+
this.scrollEndCallback = () => {
|
|
87
|
+
this.isActive = state;
|
|
88
|
+
};
|
|
89
|
+
return;
|
|
241
90
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
91
|
+
this.isActive = state;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* When the column scrolls, the component
|
|
95
|
+
* needs to determine which item is centered
|
|
96
|
+
* in the view and will emit an ionChange with
|
|
97
|
+
* the item object.
|
|
98
|
+
*/
|
|
99
|
+
this.initializeScrollListener = () => {
|
|
100
|
+
/**
|
|
101
|
+
* The haptics for the wheel picker are
|
|
102
|
+
* an iOS-only feature. As a result, they should
|
|
103
|
+
* be disabled on Android.
|
|
104
|
+
*/
|
|
105
|
+
const enableHaptics = isPlatform('ios');
|
|
106
|
+
const { el } = this;
|
|
107
|
+
let timeout;
|
|
108
|
+
let activeEl = this.activeItem;
|
|
109
|
+
const scrollCallback = () => {
|
|
110
|
+
raf(() => {
|
|
111
|
+
if (timeout) {
|
|
112
|
+
clearTimeout(timeout);
|
|
113
|
+
timeout = undefined;
|
|
114
|
+
}
|
|
115
|
+
if (!this.isScrolling) {
|
|
116
|
+
enableHaptics && hapticSelectionStart();
|
|
117
|
+
this.isScrolling = true;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Select item in the center of the column
|
|
121
|
+
* which is the month/year that we want to select
|
|
122
|
+
*/
|
|
123
|
+
const bbox = el.getBoundingClientRect();
|
|
124
|
+
const centerX = bbox.x + bbox.width / 2;
|
|
125
|
+
const centerY = bbox.y + bbox.height / 2;
|
|
126
|
+
const activeElement = el.shadowRoot.elementFromPoint(centerX, centerY);
|
|
127
|
+
if (activeEl !== null) {
|
|
128
|
+
this.setPickerItemActiveState(activeEl, false);
|
|
129
|
+
}
|
|
130
|
+
if (activeElement === null || activeElement.disabled) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* If we are selecting a new value,
|
|
135
|
+
* we need to run haptics again.
|
|
136
|
+
*/
|
|
137
|
+
if (activeElement !== activeEl) {
|
|
138
|
+
enableHaptics && hapticSelectionChanged();
|
|
139
|
+
if (this.canExitInputMode) {
|
|
140
|
+
/**
|
|
141
|
+
* The native iOS wheel picker
|
|
142
|
+
* only dismisses the keyboard
|
|
143
|
+
* once the selected item has changed
|
|
144
|
+
* as a result of a swipe
|
|
145
|
+
* from the user. If `canExitInputMode` is
|
|
146
|
+
* `false` then this means that the
|
|
147
|
+
* scroll is happening as a result of
|
|
148
|
+
* the `value` property programmatically changing
|
|
149
|
+
* either by an application or by the user via the keyboard.
|
|
150
|
+
*/
|
|
151
|
+
this.exitInputMode();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
activeEl = activeElement;
|
|
155
|
+
this.setPickerItemActiveState(activeElement, true);
|
|
156
|
+
timeout = setTimeout(() => {
|
|
157
|
+
this.isScrolling = false;
|
|
158
|
+
enableHaptics && hapticSelectionEnd();
|
|
159
|
+
/**
|
|
160
|
+
* Certain tasks (such as those that
|
|
161
|
+
* cause re-renders) should only be done
|
|
162
|
+
* once scrolling has finished, otherwise
|
|
163
|
+
* flickering may occur.
|
|
164
|
+
*/
|
|
165
|
+
const { scrollEndCallback } = this;
|
|
166
|
+
if (scrollEndCallback) {
|
|
167
|
+
scrollEndCallback();
|
|
168
|
+
this.scrollEndCallback = undefined;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Reset this flag as the
|
|
172
|
+
* next scroll interaction could
|
|
173
|
+
* be a scroll from the user. In this
|
|
174
|
+
* case, we should exit input mode.
|
|
175
|
+
*/
|
|
176
|
+
this.canExitInputMode = true;
|
|
177
|
+
const dataIndex = activeElement.getAttribute('data-index');
|
|
178
|
+
/**
|
|
179
|
+
* If no value it is
|
|
180
|
+
* possible we hit one of the
|
|
181
|
+
* empty padding columns.
|
|
182
|
+
*/
|
|
183
|
+
if (dataIndex === null) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
const index = parseInt(dataIndex, 10);
|
|
187
|
+
const selectedItem = this.items[index];
|
|
188
|
+
if (selectedItem.value !== this.value) {
|
|
189
|
+
this.setValue(selectedItem.value);
|
|
190
|
+
}
|
|
191
|
+
}, 250);
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Wrap this in an raf so that the scroll callback
|
|
196
|
+
* does not fire when component is initially shown.
|
|
197
|
+
*/
|
|
198
|
+
raf(() => {
|
|
199
|
+
el.addEventListener('scroll', scrollCallback);
|
|
200
|
+
this.destroyScrollListener = () => {
|
|
201
|
+
el.removeEventListener('scroll', scrollCallback);
|
|
202
|
+
};
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* Tells the parent picker to
|
|
207
|
+
* exit text entry mode. This is only called
|
|
208
|
+
* when the selected item changes during scroll, so
|
|
209
|
+
* we know that the user likely wants to scroll
|
|
210
|
+
* instead of type.
|
|
211
|
+
*/
|
|
212
|
+
this.exitInputMode = () => {
|
|
213
|
+
const { parentEl } = this;
|
|
214
|
+
if (parentEl == null)
|
|
215
|
+
return;
|
|
216
|
+
parentEl.exitInputMode();
|
|
217
|
+
/**
|
|
218
|
+
* setInputModeActive only takes
|
|
219
|
+
* effect once scrolling stops to avoid
|
|
220
|
+
* a component re-render while scrolling.
|
|
221
|
+
* However, we want the visual active
|
|
222
|
+
* indicator to go away immediately, so
|
|
223
|
+
* we call classList.remove here.
|
|
224
|
+
*/
|
|
225
|
+
this.el.classList.remove('picker-column-active');
|
|
226
|
+
};
|
|
227
|
+
this.isActive = false;
|
|
228
|
+
this.disabled = false;
|
|
229
|
+
this.items = [];
|
|
230
|
+
this.value = undefined;
|
|
231
|
+
this.color = 'primary';
|
|
232
|
+
this.numericInput = false;
|
|
245
233
|
}
|
|
246
|
-
|
|
247
|
-
if (
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
if (y > this.minY) {
|
|
254
|
-
// scrolling up higher than scroll area
|
|
255
|
-
y = Math.pow(y, 0.8);
|
|
256
|
-
this.bounceFrom = y;
|
|
257
|
-
}
|
|
258
|
-
else if (y < this.maxY) {
|
|
259
|
-
// scrolling down below scroll area
|
|
260
|
-
y += Math.pow(this.maxY - y, 0.9);
|
|
261
|
-
this.bounceFrom = y;
|
|
262
|
-
}
|
|
263
|
-
else {
|
|
264
|
-
this.bounceFrom = 0;
|
|
234
|
+
valueChange() {
|
|
235
|
+
if (this.isColumnVisible) {
|
|
236
|
+
/**
|
|
237
|
+
* Only scroll the active item into view when the picker column
|
|
238
|
+
* is actively visible to the user.
|
|
239
|
+
*/
|
|
240
|
+
this.scrollActiveItemIntoView();
|
|
265
241
|
}
|
|
266
|
-
this.update(y, 0, false);
|
|
267
242
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
const isScrollingUp = detail.deltaY > 0;
|
|
292
|
-
const optHeightFraction = (Math.abs(this.y) % this.optHeight) / this.optHeight;
|
|
293
|
-
if (isScrollingUp && optHeightFraction > 0.5) {
|
|
294
|
-
this.velocity = Math.abs(this.velocity) * -1;
|
|
243
|
+
/**
|
|
244
|
+
* Only setup scroll listeners
|
|
245
|
+
* when the picker is visible, otherwise
|
|
246
|
+
* the container will have a scroll
|
|
247
|
+
* height of 0px.
|
|
248
|
+
*/
|
|
249
|
+
componentWillLoad() {
|
|
250
|
+
const visibleCallback = (entries) => {
|
|
251
|
+
const ev = entries[0];
|
|
252
|
+
if (ev.isIntersecting) {
|
|
253
|
+
const { activeItem, el } = this;
|
|
254
|
+
this.isColumnVisible = true;
|
|
255
|
+
/**
|
|
256
|
+
* Because this initial call to scrollActiveItemIntoView has to fire before
|
|
257
|
+
* the scroll listener is set up, we need to manage the active class manually.
|
|
258
|
+
*/
|
|
259
|
+
const oldActive = getElementRoot(el).querySelector(`.${PICKER_ITEM_ACTIVE_CLASS}`);
|
|
260
|
+
if (oldActive) {
|
|
261
|
+
this.setPickerItemActiveState(oldActive, false);
|
|
262
|
+
}
|
|
263
|
+
this.scrollActiveItemIntoView();
|
|
264
|
+
if (activeItem) {
|
|
265
|
+
this.setPickerItemActiveState(activeItem, true);
|
|
295
266
|
}
|
|
296
|
-
|
|
297
|
-
|
|
267
|
+
this.initializeScrollListener();
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
this.isColumnVisible = false;
|
|
271
|
+
if (this.destroyScrollListener) {
|
|
272
|
+
this.destroyScrollListener();
|
|
273
|
+
this.destroyScrollListener = undefined;
|
|
298
274
|
}
|
|
299
275
|
}
|
|
300
|
-
|
|
276
|
+
};
|
|
277
|
+
new IntersectionObserver(visibleCallback, { threshold: 0.001 }).observe(this.el);
|
|
278
|
+
const parentEl = (this.parentEl = this.el.closest('ion-picker'));
|
|
279
|
+
if (parentEl !== null) {
|
|
280
|
+
// TODO(FW-2832): type
|
|
281
|
+
parentEl.addEventListener('ionInputModeChange', (ev) => this.inputModeChange(ev));
|
|
301
282
|
}
|
|
302
283
|
}
|
|
303
|
-
|
|
284
|
+
componentDidRender() {
|
|
304
285
|
var _a;
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
286
|
+
const { activeItem, items, isColumnVisible, value } = this;
|
|
287
|
+
if (isColumnVisible) {
|
|
288
|
+
if (activeItem) {
|
|
289
|
+
this.scrollActiveItemIntoView();
|
|
290
|
+
}
|
|
291
|
+
else if (((_a = items[0]) === null || _a === void 0 ? void 0 : _a.value) !== value) {
|
|
292
|
+
/**
|
|
293
|
+
* If the picker column does not have an active item and the current value
|
|
294
|
+
* does not match the first item in the picker column, that means
|
|
295
|
+
* the value is out of bounds. In this case, we assign the value to the
|
|
296
|
+
* first item to match the scroll position of the column.
|
|
297
|
+
*
|
|
298
|
+
*/
|
|
299
|
+
this.setValue(items[0].value);
|
|
312
300
|
}
|
|
313
301
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
*/
|
|
321
|
-
if (this.velocity !== 0) {
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
const selectedIndex = clamp(min, (_a = this.col.selectedIndex) !== null && _a !== void 0 ? _a : 0, max);
|
|
325
|
-
if (this.col.prevSelected !== selectedIndex || forceRefresh) {
|
|
326
|
-
const y = selectedIndex * this.optHeight * -1;
|
|
327
|
-
const duration = animated ? TRANSITION_DURATION : 0;
|
|
328
|
-
this.velocity = 0;
|
|
329
|
-
this.update(y, duration, true);
|
|
302
|
+
}
|
|
303
|
+
/** @internal */
|
|
304
|
+
async scrollActiveItemIntoView() {
|
|
305
|
+
const activeEl = this.activeItem;
|
|
306
|
+
if (activeEl) {
|
|
307
|
+
this.centerPickerItemInView(activeEl, false, false);
|
|
330
308
|
}
|
|
331
309
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
310
|
+
/**
|
|
311
|
+
* Sets the value prop and fires the ionChange event.
|
|
312
|
+
* This is used when we need to fire ionChange from
|
|
313
|
+
* user-generated events that cannot be caught with normal
|
|
314
|
+
* input/change event listeners.
|
|
315
|
+
* @internal
|
|
316
|
+
*/
|
|
317
|
+
async setValue(value) {
|
|
318
|
+
const { items } = this;
|
|
319
|
+
this.value = value;
|
|
320
|
+
const findItem = items.find((item) => item.value === value && item.disabled !== true);
|
|
321
|
+
if (findItem) {
|
|
322
|
+
this.ionChange.emit(findItem);
|
|
338
323
|
}
|
|
339
|
-
|
|
324
|
+
}
|
|
325
|
+
get activeItem() {
|
|
326
|
+
// If the whole picker column is disabled, the current value should appear active
|
|
327
|
+
// If the current value item is specifically disabled, it should not appear active
|
|
328
|
+
const selector = `.picker-item[data-value="${this.value}"]${this.disabled ? '' : ':not([disabled])'}`;
|
|
329
|
+
return getElementRoot(this.el).querySelector(selector);
|
|
340
330
|
}
|
|
341
331
|
render() {
|
|
342
|
-
const
|
|
332
|
+
const { items, color, disabled: pickerDisabled, isActive, numericInput } = this;
|
|
343
333
|
const mode = getIonMode(this);
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
334
|
+
/**
|
|
335
|
+
* exportparts is needed so ion-datetime can expose the parts
|
|
336
|
+
* from two layers of shadow nesting. If this causes problems,
|
|
337
|
+
* the attribute can be moved to datetime.tsx and set on every
|
|
338
|
+
* instance of ion-picker-column there instead.
|
|
339
|
+
*/
|
|
340
|
+
return (h(Host, { exportparts: `${PICKER_ITEM_PART}, ${PICKER_ITEM_ACTIVE_PART}`, disabled: pickerDisabled, tabindex: pickerDisabled ? null : 0, class: createColorClasses(color, {
|
|
341
|
+
[mode]: true,
|
|
342
|
+
['picker-column-active']: isActive,
|
|
343
|
+
['picker-column-numeric-input']: numericInput,
|
|
344
|
+
}) }, h("div", { class: "picker-item picker-item-empty", "aria-hidden": "true" }, "\u00A0"), h("div", { class: "picker-item picker-item-empty", "aria-hidden": "true" }, "\u00A0"), h("div", { class: "picker-item picker-item-empty", "aria-hidden": "true" }, "\u00A0"), items.map((item, index) => {
|
|
345
|
+
const isItemDisabled = pickerDisabled || item.disabled || false;
|
|
346
|
+
return (h("button", { tabindex: "-1", class: {
|
|
347
|
+
'picker-item': true,
|
|
348
|
+
}, "data-value": item.value, "data-index": index, onClick: (ev) => {
|
|
349
|
+
this.centerPickerItemInView(ev.target, true);
|
|
350
|
+
}, disabled: isItemDisabled, part: PICKER_ITEM_PART }, item.text));
|
|
351
|
+
}), h("div", { class: "picker-item picker-item-empty", "aria-hidden": "true" }, "\u00A0"), h("div", { class: "picker-item picker-item-empty", "aria-hidden": "true" }, "\u00A0"), h("div", { class: "picker-item picker-item-empty", "aria-hidden": "true" }, "\u00A0")));
|
|
347
352
|
}
|
|
348
353
|
get el() { return this; }
|
|
349
354
|
static get watchers() { return {
|
|
350
|
-
"
|
|
355
|
+
"value": ["valueChange"]
|
|
351
356
|
}; }
|
|
352
357
|
static get style() { return {
|
|
353
358
|
ios: pickerColumnIosCss,
|
|
354
359
|
md: pickerColumnMdCss
|
|
355
360
|
}; }
|
|
356
|
-
}, [
|
|
357
|
-
"
|
|
361
|
+
}, [33, "ion-picker-column", {
|
|
362
|
+
"disabled": [4],
|
|
363
|
+
"items": [16],
|
|
364
|
+
"value": [1032],
|
|
365
|
+
"color": [513],
|
|
366
|
+
"numericInput": [4, "numeric-input"],
|
|
367
|
+
"isActive": [32],
|
|
368
|
+
"scrollActiveItemIntoView": [64],
|
|
369
|
+
"setValue": [64]
|
|
358
370
|
}, undefined, {
|
|
359
|
-
"
|
|
371
|
+
"value": ["valueChange"]
|
|
360
372
|
}]);
|
|
361
|
-
const
|
|
362
|
-
const
|
|
363
|
-
const
|
|
364
|
-
const TRANSITION_DURATION = 150;
|
|
373
|
+
const PICKER_ITEM_ACTIVE_CLASS = 'picker-item-active';
|
|
374
|
+
const PICKER_ITEM_PART = 'wheel-item';
|
|
375
|
+
const PICKER_ITEM_ACTIVE_PART = 'active';
|
|
365
376
|
function defineCustomElement() {
|
|
366
377
|
if (typeof customElements === "undefined") {
|
|
367
378
|
return;
|
|
368
379
|
}
|
|
369
|
-
const components = ["ion-picker-
|
|
380
|
+
const components = ["ion-picker-column"];
|
|
370
381
|
components.forEach(tagName => { switch (tagName) {
|
|
371
|
-
case "ion-picker-
|
|
382
|
+
case "ion-picker-column":
|
|
372
383
|
if (!customElements.get(tagName)) {
|
|
373
|
-
customElements.define(tagName,
|
|
384
|
+
customElements.define(tagName, PickerColumn);
|
|
374
385
|
}
|
|
375
386
|
break;
|
|
376
387
|
} });
|
|
377
388
|
}
|
|
378
389
|
|
|
379
|
-
export {
|
|
390
|
+
export { PickerColumn as P, defineCustomElement as d };
|