{"version":3,"sources":["components/date-picker/range-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAoB,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAEzE,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;iCAoB9B,MAAM,KAAG,MAAM;AAlBvC;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAwBE","file":"range-plugin.d.ts","sourcesContent":["/**\n * @license\n *\n * Copyright IBM Corp. 2019, 2021\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport rangePlugin, { Config } from 'flatpickr/dist/plugins/rangePlugin';\nimport { Instance as FlatpickrInstance } from 'flatpickr/dist/types/instance';\nimport { Plugin } from 'flatpickr/dist/types/options';\n\n/**\n * @param config Plugin configuration.\n * @returns\n *   An extension of Flatpickr `rangePlugin` that does the following:\n *\n *   * Better ensures the calendar dropdown is always aligned to the `<input>` for the starting date.\n *     Workaround for: https://github.com/flatpickr/flatpickr/issues/1944\n *   * Disables the logic in Flatpickr `rangePlugin` that calculates the new range with the old selected date\n *     when user selects a date from calendar dropdown.\n *     We'd like to reset the selection when user re-opens calendar dropdown and re-selects a date.\n *     Workaround for: https://github.com/flatpickr/flatpickr/issues/1958\n *   * Disables the logic in Flatpickr `rangePlugin` that closes the calendar dropdown\n *     when it's lauched from the `<input>` for the end date and user selects a date.\n *     Workaround for: https://github.com/flatpickr/flatpickr/issues/1958\n *   * Ensures that the `<input>` in shadow DOM is treated as part of Flatpickr UI,\n *     by ensuring such `<input>` hits `.contains()` search from `fp.config.ignoredFocusElements`.\n *     Without that, Flatpickr clears the `<input>` when end date hasn't been selected yet (which we don't want).\n */\nexport default (config: Config): Plugin => {\n  const factory = rangePlugin({ position: 'left', ...config });\n  return (fp: FlatpickrInstance) => {\n    const origRangePlugin = factory(fp);\n    const { onReady: origOnReady } = origRangePlugin;\n    return Object.assign(origRangePlugin, {\n      onChange() {},\n      onPreCalendarPosition() {},\n      onValueUpdate(selectedDates) {\n        const [startDateFormatted, endDateFormatted] = selectedDates.map(item => fp.formatDate(item, fp.config.dateFormat));\n        if (startDateFormatted) {\n          fp._input.value = startDateFormatted;\n        }\n        if (endDateFormatted) {\n          (config.input as HTMLInputElement).value = endDateFormatted;\n        }\n      },\n      onReady() {\n        (origOnReady as Function).call(this);\n        const { ignoredFocusElements } = fp.config;\n        ignoredFocusElements.push(...ignoredFocusElements.map(elem => elem.shadowRoot as any).filter(Boolean));\n      },\n    });\n  };\n};\n"]}