From d35574c198c6950d2b7c45a9f2fa62caffa0fc0c Mon Sep 17 00:00:00 2001 From: Dmitry S Date: Wed, 4 Sep 2024 17:27:53 -0400 Subject: [PATCH] (core) Add support for locales to DateEditor and DateTimeEditor. Summary: Addresses request https://github.com/gristlabs/grist-core/issues/443 The bootstrap-datepicker used for the Date/DateTime dropdown calendar does support a number of locales. This diff loads them on-demand, if available, based on the document's locale setting. Also: - Improves NewBaseEditor typings, reduces some casts, adds comments. - Converts DateEditor and DateTimeEditor to typescript. - Moves DateEditor nbrowser test to core. Test Plan: Added a test case for locales to DateEditor test. Reviewers: jarek Reviewed By: jarek Differential Revision: https://phab.getgrist.com/D4335 --- app/client/declarations.d.ts | 4 + app/client/widgets/DateEditor.js | 172 --------------------- app/client/widgets/DateEditor.ts | 216 +++++++++++++++++++++++++++ app/client/widgets/DateTimeEditor.js | 173 --------------------- app/client/widgets/DateTimeEditor.ts | 173 +++++++++++++++++++++ app/client/widgets/FieldBuilder.ts | 4 +- app/client/widgets/FieldEditor.ts | 4 +- app/client/widgets/FormulaEditor.ts | 16 +- app/client/widgets/NTextEditor.ts | 8 + app/client/widgets/NewBaseEditor.ts | 13 +- app/client/widgets/UserTypeImpl.ts | 8 +- test/nbrowser/DateEditor.ts | 166 ++++++++++++++++++++ 12 files changed, 593 insertions(+), 364 deletions(-) delete mode 100644 app/client/widgets/DateEditor.js create mode 100644 app/client/widgets/DateEditor.ts delete mode 100644 app/client/widgets/DateTimeEditor.js create mode 100644 app/client/widgets/DateTimeEditor.ts create mode 100644 test/nbrowser/DateEditor.ts diff --git a/app/client/declarations.d.ts b/app/client/declarations.d.ts index 7b9c9cdf..0fa0fe36 100644 --- a/app/client/declarations.d.ts +++ b/app/client/declarations.d.ts @@ -335,3 +335,7 @@ interface Location { // historical accident than an intentional choice. reload(forceGet?: boolean): void; } + +interface JQuery { + datepicker(options: unknown): JQuery; +} diff --git a/app/client/widgets/DateEditor.js b/app/client/widgets/DateEditor.js deleted file mode 100644 index d11f4cef..00000000 --- a/app/client/widgets/DateEditor.js +++ /dev/null @@ -1,172 +0,0 @@ -/* global $, document */ -const moment = require('moment-timezone'); -const _ = require('underscore'); -const gutil = require('app/common/gutil'); -const commands = require('../components/commands'); -const dispose = require('../lib/dispose'); -const dom = require('../lib/dom'); -const kd = require('../lib/koDom'); -const TextEditor = require('./TextEditor'); -const { parseDate, TWO_DIGIT_YEAR_THRESHOLD } = require('app/common/parseDate'); - -// DatePicker unfortunately requires an (not