1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | const index = require('./index-a0a08b2a.js');
|
6 | const ionicGlobal = require('./ionic-global-06f21c1a.js');
|
7 | const helpers = require('./helpers-d381ec4d.js');
|
8 | const theme = require('./theme-30b7a575.js');
|
9 |
|
10 | const inputIosCss = ".sc-ion-input-ios-h{--placeholder-color:initial;--placeholder-font-style:initial;--placeholder-font-weight:initial;--placeholder-opacity:.5;--padding-top:0;--padding-end:0;--padding-bottom:0;--padding-start:0;--background:transparent;--color:initial;display:-ms-flexbox;display:flex;position:relative;-ms-flex:1;flex:1;-ms-flex-align:center;align-items:center;width:100%;padding:0 !important;background:var(--background);color:var(--color);font-family:var(--ion-font-family, inherit);z-index:2}ion-item.sc-ion-input-ios-h:not(.item-label),ion-item:not(.item-label) .sc-ion-input-ios-h{--padding-start:0}.ion-color.sc-ion-input-ios-h{color:var(--ion-color-base)}.native-input.sc-ion-input-ios{border-radius:var(--border-radius);padding-left:var(--padding-start);padding-right:var(--padding-end);padding-top:var(--padding-top);padding-bottom:var(--padding-bottom);font-family:inherit;font-size:inherit;font-style:inherit;font-weight:inherit;letter-spacing:inherit;text-decoration:inherit;text-indent:inherit;text-overflow:inherit;text-transform:inherit;text-align:inherit;white-space:inherit;color:inherit;display:inline-block;-ms-flex:1;flex:1;width:100%;max-width:100%;max-height:100%;border:0;outline:none;background:transparent;-webkit-box-sizing:border-box;box-sizing:border-box;-webkit-appearance:none;-moz-appearance:none;appearance:none}@supports ((-webkit-margin-start: 0) or (margin-inline-start: 0)) or (-webkit-margin-start: 0){.native-input.sc-ion-input-ios{padding-left:unset;padding-right:unset;-webkit-padding-start:var(--padding-start);padding-inline-start:var(--padding-start);-webkit-padding-end:var(--padding-end);padding-inline-end:var(--padding-end)}}.native-input.sc-ion-input-ios::-webkit-input-placeholder{color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-input.sc-ion-input-ios::-moz-placeholder{color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-input.sc-ion-input-ios:-ms-input-placeholder{color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-input.sc-ion-input-ios::-ms-input-placeholder{color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-input.sc-ion-input-ios::placeholder{color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-input.sc-ion-input-ios:-webkit-autofill{background-color:transparent}.native-input.sc-ion-input-ios:invalid{-webkit-box-shadow:none;box-shadow:none}.native-input.sc-ion-input-ios::-ms-clear{display:none}.native-input[disabled].sc-ion-input-ios{opacity:0.4}.cloned-input.sc-ion-input-ios{left:0;top:0;position:absolute;pointer-events:none}[dir=rtl].sc-ion-input-ios .cloned-input.sc-ion-input-ios,[dir=rtl].sc-ion-input-ios-h .cloned-input.sc-ion-input-ios,[dir=rtl] .sc-ion-input-ios-h .cloned-input.sc-ion-input-ios{left:unset;right:unset;right:0}.input-clear-icon.sc-ion-input-ios{margin-left:0;margin-right:0;margin-top:0;margin-bottom:0;padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;background-position:center;border:0;outline:none;background-color:transparent;background-repeat:no-repeat;visibility:hidden;-webkit-appearance:none;-moz-appearance:none;appearance:none}.input-clear-icon.sc-ion-input-ios:focus{opacity:0.5}.has-value.sc-ion-input-ios-h .input-clear-icon.sc-ion-input-ios{visibility:visible}.has-focus.sc-ion-input-ios-h{pointer-events:none}.has-focus.sc-ion-input-ios-h input.sc-ion-input-ios,.has-focus.sc-ion-input-ios-h a.sc-ion-input-ios,.has-focus.sc-ion-input-ios-h button.sc-ion-input-ios{pointer-events:auto}.item-label-floating.item-has-placeholder.sc-ion-input-ios-h:not(.item-has-value),.item-label-floating.item-has-placeholder:not(.item-has-value) .sc-ion-input-ios-h{opacity:0}.item-label-floating.item-has-placeholder.sc-ion-input-ios-h:not(.item-has-value).item-has-focus,.item-label-floating.item-has-placeholder:not(.item-has-value).item-has-focus .sc-ion-input-ios-h{-webkit-transition:opacity 0.15s cubic-bezier(0.4, 0, 0.2, 1);transition:opacity 0.15s cubic-bezier(0.4, 0, 0.2, 1);opacity:1}.sc-ion-input-ios-h{--padding-top:10px;--padding-end:10px;--padding-bottom:10px;--padding-start:0;font-size:inherit}.item-label-stacked.sc-ion-input-ios-h,.item-label-stacked .sc-ion-input-ios-h,.item-label-floating.sc-ion-input-ios-h,.item-label-floating .sc-ion-input-ios-h{--padding-top:8px;--padding-bottom:8px;--padding-start:0px}.input-clear-icon.sc-ion-input-ios{background-image:url(\"data:image/svg+xml;charset=utf-8,<svg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20512%20512'><path%20fill='var(--ion-color-step-600,%20%23666666)'%20d='M403.1,108.9c-81.2-81.2-212.9-81.2-294.2,0s-81.2,212.9,0,294.2c81.2,81.2,212.9,81.2,294.2,0S484.3,190.1,403.1,108.9z%20M352,340.2L340.2,352l-84.4-84.2l-84,83.8L160,339.8l84-83.8l-84-83.8l11.8-11.8l84,83.8l84.4-84.2l11.8,11.8L267.6,256L352,340.2z'/></svg>\");width:30px;height:30px;background-size:18px}";
|
11 |
|
12 | const inputMdCss = ".sc-ion-input-md-h{--placeholder-color:initial;--placeholder-font-style:initial;--placeholder-font-weight:initial;--placeholder-opacity:.5;--padding-top:0;--padding-end:0;--padding-bottom:0;--padding-start:0;--background:transparent;--color:initial;display:-ms-flexbox;display:flex;position:relative;-ms-flex:1;flex:1;-ms-flex-align:center;align-items:center;width:100%;padding:0 !important;background:var(--background);color:var(--color);font-family:var(--ion-font-family, inherit);z-index:2}ion-item.sc-ion-input-md-h:not(.item-label),ion-item:not(.item-label) .sc-ion-input-md-h{--padding-start:0}.ion-color.sc-ion-input-md-h{color:var(--ion-color-base)}.native-input.sc-ion-input-md{border-radius:var(--border-radius);padding-left:var(--padding-start);padding-right:var(--padding-end);padding-top:var(--padding-top);padding-bottom:var(--padding-bottom);font-family:inherit;font-size:inherit;font-style:inherit;font-weight:inherit;letter-spacing:inherit;text-decoration:inherit;text-indent:inherit;text-overflow:inherit;text-transform:inherit;text-align:inherit;white-space:inherit;color:inherit;display:inline-block;-ms-flex:1;flex:1;width:100%;max-width:100%;max-height:100%;border:0;outline:none;background:transparent;-webkit-box-sizing:border-box;box-sizing:border-box;-webkit-appearance:none;-moz-appearance:none;appearance:none}@supports ((-webkit-margin-start: 0) or (margin-inline-start: 0)) or (-webkit-margin-start: 0){.native-input.sc-ion-input-md{padding-left:unset;padding-right:unset;-webkit-padding-start:var(--padding-start);padding-inline-start:var(--padding-start);-webkit-padding-end:var(--padding-end);padding-inline-end:var(--padding-end)}}.native-input.sc-ion-input-md::-webkit-input-placeholder{color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-input.sc-ion-input-md::-moz-placeholder{color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-input.sc-ion-input-md:-ms-input-placeholder{color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-input.sc-ion-input-md::-ms-input-placeholder{color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-input.sc-ion-input-md::placeholder{color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-input.sc-ion-input-md:-webkit-autofill{background-color:transparent}.native-input.sc-ion-input-md:invalid{-webkit-box-shadow:none;box-shadow:none}.native-input.sc-ion-input-md::-ms-clear{display:none}.native-input[disabled].sc-ion-input-md{opacity:0.4}.cloned-input.sc-ion-input-md{left:0;top:0;position:absolute;pointer-events:none}[dir=rtl].sc-ion-input-md .cloned-input.sc-ion-input-md,[dir=rtl].sc-ion-input-md-h .cloned-input.sc-ion-input-md,[dir=rtl] .sc-ion-input-md-h .cloned-input.sc-ion-input-md{left:unset;right:unset;right:0}.input-clear-icon.sc-ion-input-md{margin-left:0;margin-right:0;margin-top:0;margin-bottom:0;padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;background-position:center;border:0;outline:none;background-color:transparent;background-repeat:no-repeat;visibility:hidden;-webkit-appearance:none;-moz-appearance:none;appearance:none}.input-clear-icon.sc-ion-input-md:focus{opacity:0.5}.has-value.sc-ion-input-md-h .input-clear-icon.sc-ion-input-md{visibility:visible}.has-focus.sc-ion-input-md-h{pointer-events:none}.has-focus.sc-ion-input-md-h input.sc-ion-input-md,.has-focus.sc-ion-input-md-h a.sc-ion-input-md,.has-focus.sc-ion-input-md-h button.sc-ion-input-md{pointer-events:auto}.item-label-floating.item-has-placeholder.sc-ion-input-md-h:not(.item-has-value),.item-label-floating.item-has-placeholder:not(.item-has-value) .sc-ion-input-md-h{opacity:0}.item-label-floating.item-has-placeholder.sc-ion-input-md-h:not(.item-has-value).item-has-focus,.item-label-floating.item-has-placeholder:not(.item-has-value).item-has-focus .sc-ion-input-md-h{-webkit-transition:opacity 0.15s cubic-bezier(0.4, 0, 0.2, 1);transition:opacity 0.15s cubic-bezier(0.4, 0, 0.2, 1);opacity:1}.sc-ion-input-md-h{--padding-top:10px;--padding-end:0;--padding-bottom:10px;--padding-start:8px;font-size:inherit}.item-label-stacked.sc-ion-input-md-h,.item-label-stacked .sc-ion-input-md-h,.item-label-floating.sc-ion-input-md-h,.item-label-floating .sc-ion-input-md-h{--padding-top:8px;--padding-bottom:8px;--padding-start:0}.input-clear-icon.sc-ion-input-md{background-image:url(\"data:image/svg+xml;charset=utf-8,<svg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20512%20512'><polygon%20fill='var(--ion-color-step-600,%20%23666666)'%20points='405,136.798%20375.202,107%20256,226.202%20136.798,107%20107,136.798%20226.202,256%20107,375.202%20136.798,405%20256,285.798%20375.202,405%20405,375.202%20285.798,256'/></svg>\");width:30px;height:30px;background-size:22px}";
|
13 |
|
14 | const Input = class {
|
15 | constructor(hostRef) {
|
16 | index.registerInstance(this, hostRef);
|
17 | this.ionInput = index.createEvent(this, "ionInput", 7);
|
18 | this.ionChange = index.createEvent(this, "ionChange", 7);
|
19 | this.ionBlur = index.createEvent(this, "ionBlur", 7);
|
20 | this.ionFocus = index.createEvent(this, "ionFocus", 7);
|
21 | this.ionStyle = index.createEvent(this, "ionStyle", 7);
|
22 | this.inputId = `ion-input-${inputIds++}`;
|
23 | this.didBlurAfterEdit = false;
|
24 | this.inheritedAttributes = {};
|
25 | |
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | this.fireFocusEvents = true;
|
34 | this.hasFocus = false;
|
35 | |
36 |
|
37 |
|
38 |
|
39 | this.autocapitalize = 'off';
|
40 | |
41 |
|
42 |
|
43 | this.autocomplete = 'off';
|
44 | |
45 |
|
46 |
|
47 | this.autocorrect = 'off';
|
48 | |
49 |
|
50 |
|
51 | this.autofocus = false;
|
52 | |
53 |
|
54 |
|
55 | this.clearInput = false;
|
56 | |
57 |
|
58 |
|
59 | this.debounce = 0;
|
60 | |
61 |
|
62 |
|
63 | this.disabled = false;
|
64 | |
65 |
|
66 |
|
67 | this.name = this.inputId;
|
68 | |
69 |
|
70 |
|
71 | this.readonly = false;
|
72 | |
73 |
|
74 |
|
75 | this.required = false;
|
76 | |
77 |
|
78 |
|
79 | this.spellcheck = false;
|
80 | |
81 |
|
82 |
|
83 | this.type = 'text';
|
84 | |
85 |
|
86 |
|
87 | this.value = '';
|
88 | this.onInput = (ev) => {
|
89 | const input = ev.target;
|
90 | if (input) {
|
91 | this.value = input.value || '';
|
92 | }
|
93 | this.ionInput.emit(ev);
|
94 | };
|
95 | this.onBlur = (ev) => {
|
96 | this.hasFocus = false;
|
97 | this.focusChanged();
|
98 | this.emitStyle();
|
99 | if (this.fireFocusEvents) {
|
100 | this.ionBlur.emit(ev);
|
101 | }
|
102 | };
|
103 | this.onFocus = (ev) => {
|
104 | this.hasFocus = true;
|
105 | this.focusChanged();
|
106 | this.emitStyle();
|
107 | if (this.fireFocusEvents) {
|
108 | this.ionFocus.emit(ev);
|
109 | }
|
110 | };
|
111 | this.onKeydown = (ev) => {
|
112 | if (this.shouldClearOnEdit()) {
|
113 |
|
114 |
|
115 | if (this.didBlurAfterEdit && this.hasValue() && ev.key !== 'Enter') {
|
116 |
|
117 | this.clearTextInput();
|
118 | }
|
119 |
|
120 | this.didBlurAfterEdit = false;
|
121 | }
|
122 | };
|
123 | this.clearTextOnEnter = (ev) => {
|
124 | if (ev.key === 'Enter') {
|
125 | this.clearTextInput(ev);
|
126 | }
|
127 | };
|
128 | this.clearTextInput = (ev) => {
|
129 | if (this.clearInput && !this.readonly && !this.disabled && ev) {
|
130 | ev.preventDefault();
|
131 | ev.stopPropagation();
|
132 |
|
133 | this.setFocus();
|
134 | }
|
135 | this.value = '';
|
136 | |
137 |
|
138 |
|
139 |
|
140 |
|
141 | if (this.nativeInput) {
|
142 | this.nativeInput.value = '';
|
143 | }
|
144 | };
|
145 | }
|
146 | debounceChanged() {
|
147 | this.ionChange = helpers.debounceEvent(this.ionChange, this.debounce);
|
148 | }
|
149 | disabledChanged() {
|
150 | this.emitStyle();
|
151 | }
|
152 | |
153 |
|
154 |
|
155 | placeholderChanged() {
|
156 | this.emitStyle();
|
157 | }
|
158 | |
159 |
|
160 |
|
161 | valueChanged() {
|
162 | this.emitStyle();
|
163 | this.ionChange.emit({ value: this.value == null ? this.value : this.value.toString() });
|
164 | }
|
165 | componentWillLoad() {
|
166 | this.inheritedAttributes = helpers.inheritAttributes(this.el, ['aria-label', 'tabindex', 'title']);
|
167 | }
|
168 | connectedCallback() {
|
169 | this.emitStyle();
|
170 | this.debounceChanged();
|
171 | {
|
172 | document.dispatchEvent(new CustomEvent('ionInputDidLoad', {
|
173 | detail: this.el
|
174 | }));
|
175 | }
|
176 | }
|
177 | disconnectedCallback() {
|
178 | {
|
179 | document.dispatchEvent(new CustomEvent('ionInputDidUnload', {
|
180 | detail: this.el
|
181 | }));
|
182 | }
|
183 | }
|
184 | |
185 |
|
186 |
|
187 |
|
188 | async setFocus() {
|
189 | if (this.nativeInput) {
|
190 | this.nativeInput.focus();
|
191 | }
|
192 | }
|
193 | |
194 |
|
195 |
|
196 |
|
197 |
|
198 | async setBlur() {
|
199 | if (this.nativeInput) {
|
200 | this.nativeInput.blur();
|
201 | }
|
202 | }
|
203 | |
204 |
|
205 |
|
206 | getInputElement() {
|
207 | return Promise.resolve(this.nativeInput);
|
208 | }
|
209 | shouldClearOnEdit() {
|
210 | const { type, clearOnEdit } = this;
|
211 | return (clearOnEdit === undefined)
|
212 | ? type === 'password'
|
213 | : clearOnEdit;
|
214 | }
|
215 | getValue() {
|
216 | return typeof this.value === 'number' ? this.value.toString() :
|
217 | (this.value || '').toString();
|
218 | }
|
219 | emitStyle() {
|
220 | this.ionStyle.emit({
|
221 | 'interactive': true,
|
222 | 'input': true,
|
223 | 'has-placeholder': this.placeholder != null,
|
224 | 'has-value': this.hasValue(),
|
225 | 'has-focus': this.hasFocus,
|
226 | 'interactive-disabled': this.disabled,
|
227 | });
|
228 | }
|
229 | focusChanged() {
|
230 |
|
231 | if (!this.hasFocus && this.shouldClearOnEdit() && this.hasValue()) {
|
232 | this.didBlurAfterEdit = true;
|
233 | }
|
234 | }
|
235 | hasValue() {
|
236 | return this.getValue().length > 0;
|
237 | }
|
238 | render() {
|
239 | const mode = ionicGlobal.getIonMode(this);
|
240 | const value = this.getValue();
|
241 | const labelId = this.inputId + '-lbl';
|
242 | const label = helpers.findItemLabel(this.el);
|
243 | if (label) {
|
244 | label.id = labelId;
|
245 | }
|
246 | return (index.h(index.Host, { "aria-disabled": this.disabled ? 'true' : null, class: theme.createColorClasses(this.color, {
|
247 | [mode]: true,
|
248 | 'has-value': this.hasValue(),
|
249 | 'has-focus': this.hasFocus
|
250 | }) }, index.h("input", Object.assign({ class: "native-input", ref: input => this.nativeInput = input, "aria-labelledby": label ? labelId : null, disabled: this.disabled, accept: this.accept, autoCapitalize: this.autocapitalize, autoComplete: this.autocomplete, autoCorrect: this.autocorrect, autoFocus: this.autofocus, enterKeyHint: this.enterkeyhint, inputMode: this.inputmode, min: this.min, max: this.max, minLength: this.minlength, maxLength: this.maxlength, multiple: this.multiple, name: this.name, pattern: this.pattern, placeholder: this.placeholder || '', readOnly: this.readonly, required: this.required, spellcheck: this.spellcheck, step: this.step, size: this.size, type: this.type, value: value, onInput: this.onInput, onBlur: this.onBlur, onFocus: this.onFocus, onKeyDown: this.onKeydown }, this.inheritedAttributes)), (this.clearInput && !this.readonly && !this.disabled) && index.h("button", { "aria-label": "reset", type: "button", class: "input-clear-icon", onTouchStart: this.clearTextInput, onMouseDown: this.clearTextInput, onKeyDown: this.clearTextOnEnter })));
|
251 | }
|
252 | get el() { return index.getElement(this); }
|
253 | static get watchers() { return {
|
254 | "debounce": ["debounceChanged"],
|
255 | "disabled": ["disabledChanged"],
|
256 | "placeholder": ["placeholderChanged"],
|
257 | "value": ["valueChanged"]
|
258 | }; }
|
259 | };
|
260 | let inputIds = 0;
|
261 | Input.style = {
|
262 | ios: inputIosCss,
|
263 | md: inputMdCss
|
264 | };
|
265 |
|
266 | exports.ion_input = Input;
|