Keep lock files unchanged and type Datepicker extensions locally

This commit is contained in:
Bartek committed 2026-09-28 13:32:51 +02:00
1 parent edfcf5123a
commit da1e7304e9
4 files changed
+29 -15

No files matched your search

+8 -5
View File
@@ -43,6 +43,8 @@ const DATE_PATTERN = /^(\d{4})-(\d{2})-(\d{2})$/
// Vanilla Calendar Pro 3.4+ throws on an option whose extension is not registered
const PLUGIN_EXTENSIONS = ['annotations', 'months', 'motion', 'time', 'weeks'] as const
type ExtensionOptions = { extensions?: object[] }
// The public API is typed with local copies of the Vanilla Calendar Pro types.
// `vanilla-calendar-pro` is an optional peer dependency, so the published
// `dist/types` must not import it: a project that never loads the datepicker
@@ -559,12 +561,12 @@ class Datepicker extends BaseComponent {
}
/** @internal */
_buildCalendarOptions(): Options {
_buildCalendarOptions(): Options & ExtensionOptions {
// The plugin uses 'system' for auto-detection, Bootstrap and Tabler use 'auto'
const theme = this._getEffectiveTheme()
const vcpTheme = !theme || theme === 'auto' ? 'system' : theme
const calendarOptions: Options = {
const calendarOptions: Options & ExtensionOptions = {
...this._config.vcpOptions,
inputMode: !this._isInline,
positionToInput: this._config.placement,
@@ -610,11 +612,12 @@ class Datepicker extends BaseComponent {
}
/** @internal */
_getPluginExtensions(): NonNullable<Options['extensions']> {
const extensions = [...((this._config.vcpOptions as Options).extensions ?? [])]
_getPluginExtensions(): object[] {
const extensions = [...((this._config.vcpOptions as ExtensionOptions).extensions ?? [])]
const plugin = window.VanillaCalendarPro as Record<string, unknown> | undefined
for (const name of PLUGIN_EXTENSIONS) {
const extension = window.VanillaCalendarPro?.[name]
const extension = plugin?.[name]
if (extension && !extensions.includes(extension)) {
extensions.push(extension)
}
+15 -4
View File
@@ -154,13 +154,24 @@ describe('Datepicker', () => {
expect(fixtureEl.querySelector('[data-vc="time"]')).not.toBeNull()
})
it('should keep extensions passed through vcpOptions', () => {
it('should register the plugin extensions and keep those passed through vcpOptions', () => {
const months = { name: 'months' }
const custom = { name: 'custom' }
window.VanillaCalendarPro = { ...VanillaCalendarPro, months } as unknown as typeof VanillaCalendarPro
fixtureEl.innerHTML = '<input type="text" data-bs-toggle="datepicker">'
const instance = new Datepicker(input(), { vcpOptions: { extensions: [VanillaCalendarPro.time] } })
const instance = new Datepicker(input(), { vcpOptions: { extensions: [custom, months] } })
expect(instance.calendar!.extensions).toContain(VanillaCalendarPro.time)
expect(instance.calendar!.extensions).toContain(VanillaCalendarPro.months)
expect(instance._buildCalendarOptions().extensions).toEqual([custom, months])
})
it('should not pass extensions when the plugin has none', () => {
window.VanillaCalendarPro = { Calendar: VanillaCalendarPro.Calendar } as unknown as typeof VanillaCalendarPro
fixtureEl.innerHTML = '<input type="text" data-bs-toggle="datepicker">'
const instance = new Datepicker(input())
expect(instance._buildCalendarOptions()).not.toHaveProperty('extensions')
})
})
+1 -1
View File
@@ -287,7 +287,7 @@
"tom-select": "^2.6.2",
"typed.js": "^3.0.0",
"typescript": "^7.0.2",
"vanilla-calendar-pro": "^3.4.0",
"vanilla-calendar-pro": "^3.3.2",
"vitest": "4.1.11"
}
}
+5 -5
View File
@@ -214,8 +214,8 @@ importers:
specifier: ^7.0.2
version: 7.0.2
vanilla-calendar-pro:
specifier: ^3.4.0
version: 3.4.0
specifier: ^3.3.2
version: 3.3.2
vitest:
specifier: 4.1.11
version: 4.1.11(@types/node@26.4.0)(@vitest/browser-playwright@4.1.11)(@vitest/coverage-istanbul@4.1.11)(esbuild@0.28.1)(sass@1.103.1)(terser@5.51.2)(tsx@4.23.13)(yaml@2.9.0)
@@ -4601,8 +4601,8 @@ packages:
validate-npm-package-license@3.0.4:
resolution: {integrity: sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==}
vanilla-calendar-pro@3.4.0:
resolution: {integrity: sha512-HLWjzHOWvMIrjI77tXK5bYzp0s5TeBSrZC247STjcTAdWI7kqEwWT6Xvu20vqdwzF498H1Da8l4WpdgVIGtc1Q==}
vanilla-calendar-pro@3.3.2:
resolution: {integrity: sha512-RaLpDtvQFeKi0ajOpGBedLNrr0YoiYAF+0sppk4XZV/U57AuihJIhw8h2whUvIG1ZSR3LrdSXk3lHLkCPGlHvg==}
vfile-location@5.0.3:
resolution: {integrity: sha512-5yXvWDEgqeiYiBe1lbxYF7UMAIm/IcopxMHrMQDq3nvKcjPKIhZklUKL+AE7J7uApI4kwe2snsK+eI6UTj9EHg==}
@@ -9590,7 +9590,7 @@ snapshots:
spdx-correct: 3.2.0
spdx-expression-parse: 3.0.1
vanilla-calendar-pro@3.4.0: {}
vanilla-calendar-pro@3.3.2: {}
vfile-location@5.0.3:
dependencies: