(opts: DateOptions)
| 169 | } |
| 170 | |
| 171 | constructor(opts: DateOptions) { |
| 172 | const detected = opts.format |
| 173 | ? { segments: segmentsFor(opts.format), separator: opts.separator ?? '/' } |
| 174 | : detectLocaleFormat(opts.locale); |
| 175 | const sep = opts.separator ?? detected.separator; |
| 176 | const segments = opts.format ? segmentsFor(opts.format) : detected.segments; |
| 177 | |
| 178 | const initialDate = opts.initialValue ?? opts.defaultValue; |
| 179 | const segmentValues: DateParts = initialDate |
| 180 | ? { |
| 181 | year: String(initialDate.getUTCFullYear()).padStart(4, '0'), |
| 182 | month: String(initialDate.getUTCMonth() + 1).padStart(2, '0'), |
| 183 | day: String(initialDate.getUTCDate()).padStart(2, '0'), |
| 184 | } |
| 185 | : { year: '____', month: '__', day: '__' }; |
| 186 | |
| 187 | const initialDisplay = segments.map((s) => segmentValues[s.type]).join(sep); |
| 188 | |
| 189 | super({ ...opts, initialUserInput: initialDisplay }, false); |
| 190 | this.#segments = segments; |
| 191 | this.#separator = sep; |
| 192 | this.#segmentValues = segmentValues; |
| 193 | this.#minDate = opts.minDate; |
| 194 | this.#maxDate = opts.maxDate; |
| 195 | this.#refresh(); |
| 196 | |
| 197 | this.on('cursor', (key) => this.#onCursor(key)); |
| 198 | this.on('key', (char, key) => this.#onKey(char, key)); |
| 199 | this.on('finalize', () => this.#onFinalize(opts)); |
| 200 | } |
| 201 | |
| 202 | #seg(): { segment: SegmentConfig; index: number } | undefined { |
| 203 | const index = Math.max(0, Math.min(this.#cursor.segmentIndex, this.#segments.length - 1)); |
nothing calls this directly
no test coverage detected