handsontable 16.1.1 → 16.2.0-next-216dbd0-20251112
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/3rdparty/walkontable/src/overlays.js +1 -1
- package/3rdparty/walkontable/src/overlays.mjs +1 -1
- package/3rdparty/walkontable/src/selection/border/border.js +19 -3
- package/3rdparty/walkontable/src/selection/border/border.mjs +19 -3
- package/CHANGELOG.md +39 -0
- package/base.js +2 -2
- package/base.mjs +2 -2
- package/core/coordsMapper/index.js +11 -0
- package/core/coordsMapper/index.mjs +1 -0
- package/core/hooks/bucket.js +7 -1
- package/core/hooks/bucket.mjs +7 -1
- package/core/hooks/constants.js +54 -0
- package/core/hooks/constants.mjs +54 -0
- package/core/hooks/index.d.ts +6 -0
- package/core/index.js +10 -4
- package/core/index.mjs +2 -1
- package/core.d.ts +3 -2
- package/core.js +67 -26
- package/core.mjs +56 -15
- package/dataMap/metaManager/metaSchema.js +197 -20
- package/dataMap/metaManager/metaSchema.mjs +197 -20
- package/dist/handsontable.css +175 -3
- package/dist/handsontable.full.css +175 -3
- package/dist/handsontable.full.js +10864 -8426
- package/dist/handsontable.full.min.css +5 -4
- package/dist/handsontable.full.min.js +194 -193
- package/dist/handsontable.js +7126 -4827
- package/dist/handsontable.min.css +4 -4
- package/dist/handsontable.min.js +43 -42
- package/dist/languages/all.js +168 -21
- package/dist/languages/all.min.js +1 -1
- package/dist/languages/ar-AR.js +8 -1
- package/dist/languages/ar-AR.min.js +1 -1
- package/dist/languages/cs-CZ.js +8 -1
- package/dist/languages/cs-CZ.min.js +1 -1
- package/dist/languages/de-CH.js +8 -1
- package/dist/languages/de-CH.min.js +1 -1
- package/dist/languages/de-DE.js +8 -1
- package/dist/languages/de-DE.min.js +1 -1
- package/dist/languages/en-US.js +8 -1
- package/dist/languages/en-US.min.js +1 -1
- package/dist/languages/es-MX.js +8 -1
- package/dist/languages/es-MX.min.js +1 -1
- package/dist/languages/fa-IR.js +8 -1
- package/dist/languages/fa-IR.min.js +1 -1
- package/dist/languages/fr-FR.js +8 -1
- package/dist/languages/fr-FR.min.js +1 -1
- package/dist/languages/hr-HR.js +8 -1
- package/dist/languages/hr-HR.min.js +1 -1
- package/dist/languages/it-IT.js +8 -1
- package/dist/languages/it-IT.min.js +1 -1
- package/dist/languages/ja-JP.js +8 -1
- package/dist/languages/ja-JP.min.js +1 -1
- package/dist/languages/ko-KR.js +8 -1
- package/dist/languages/ko-KR.min.js +1 -1
- package/dist/languages/lv-LV.js +8 -1
- package/dist/languages/lv-LV.min.js +1 -1
- package/dist/languages/nb-NO.js +8 -1
- package/dist/languages/nb-NO.min.js +1 -1
- package/dist/languages/nl-NL.js +8 -1
- package/dist/languages/nl-NL.min.js +1 -1
- package/dist/languages/pl-PL.js +8 -1
- package/dist/languages/pl-PL.min.js +1 -1
- package/dist/languages/pt-BR.js +8 -1
- package/dist/languages/pt-BR.min.js +1 -1
- package/dist/languages/ru-RU.js +8 -1
- package/dist/languages/ru-RU.min.js +1 -1
- package/dist/languages/sr-SP.js +8 -1
- package/dist/languages/sr-SP.min.js +1 -1
- package/dist/languages/zh-CN.js +8 -1
- package/dist/languages/zh-CN.min.js +1 -1
- package/dist/languages/zh-TW.js +8 -1
- package/dist/languages/zh-TW.min.js +1 -1
- package/editors/autocompleteEditor/autocompleteEditor.js +21 -1
- package/editors/autocompleteEditor/autocompleteEditor.mjs +22 -2
- package/focusManager/constants.js +25 -0
- package/focusManager/constants.mjs +22 -0
- package/focusManager/eventListener.js +107 -0
- package/focusManager/eventListener.mjs +103 -0
- package/{focusManager.d.ts → focusManager/grid.d.ts} +1 -1
- package/{focusManager.js → focusManager/grid.js} +48 -17
- package/{focusManager.mjs → focusManager/grid.mjs} +47 -16
- package/focusManager/index.d.ts +2 -0
- package/focusManager/index.js +20 -0
- package/focusManager/index.mjs +20 -0
- package/focusManager/scope.js +133 -0
- package/focusManager/scope.mjs +129 -0
- package/focusManager/scopeManager.d.ts +19 -0
- package/focusManager/scopeManager.js +268 -0
- package/focusManager/scopeManager.mjs +263 -0
- package/focusManager/scopes/grid.js +120 -0
- package/focusManager/scopes/grid.mjs +116 -0
- package/focusManager/scopes/index.js +13 -0
- package/focusManager/scopes/index.mjs +9 -0
- package/{utils → focusManager/utils}/focusDetector.js +21 -31
- package/{utils → focusManager/utils}/focusDetector.mjs +21 -31
- package/focusManager/utils/utils.js +95 -0
- package/focusManager/utils/utils.mjs +89 -0
- package/helpers/dom/element.js +1 -1
- package/helpers/dom/element.mjs +2 -2
- package/helpers/dom/event.js +1 -1
- package/helpers/dom/event.mjs +1 -1
- package/helpers/mixed.js +2 -65
- package/helpers/mixed.mjs +2 -63
- package/i18n/constants.js +10 -1
- package/i18n/constants.mjs +10 -1
- package/i18n/languages/ar-AR.js +8 -1
- package/i18n/languages/ar-AR.mjs +8 -1
- package/i18n/languages/cs-CZ.js +8 -1
- package/i18n/languages/cs-CZ.mjs +8 -1
- package/i18n/languages/de-CH.js +8 -1
- package/i18n/languages/de-CH.mjs +8 -1
- package/i18n/languages/de-DE.js +8 -1
- package/i18n/languages/de-DE.mjs +8 -1
- package/i18n/languages/en-US.js +8 -1
- package/i18n/languages/en-US.mjs +8 -1
- package/i18n/languages/es-MX.js +8 -1
- package/i18n/languages/es-MX.mjs +8 -1
- package/i18n/languages/fa-IR.js +8 -1
- package/i18n/languages/fa-IR.mjs +8 -1
- package/i18n/languages/fr-FR.js +8 -1
- package/i18n/languages/fr-FR.mjs +8 -1
- package/i18n/languages/hr-HR.js +8 -1
- package/i18n/languages/hr-HR.mjs +8 -1
- package/i18n/languages/it-IT.js +8 -1
- package/i18n/languages/it-IT.mjs +8 -1
- package/i18n/languages/ja-JP.js +8 -1
- package/i18n/languages/ja-JP.mjs +8 -1
- package/i18n/languages/ko-KR.js +8 -1
- package/i18n/languages/ko-KR.mjs +8 -1
- package/i18n/languages/lv-LV.js +8 -1
- package/i18n/languages/lv-LV.mjs +8 -1
- package/i18n/languages/nb-NO.js +8 -1
- package/i18n/languages/nb-NO.mjs +8 -1
- package/i18n/languages/nl-NL.js +8 -1
- package/i18n/languages/nl-NL.mjs +8 -1
- package/i18n/languages/pl-PL.js +8 -1
- package/i18n/languages/pl-PL.mjs +8 -1
- package/i18n/languages/pt-BR.js +8 -1
- package/i18n/languages/pt-BR.mjs +8 -1
- package/i18n/languages/ru-RU.js +8 -1
- package/i18n/languages/ru-RU.mjs +8 -1
- package/i18n/languages/sr-SP.js +8 -1
- package/i18n/languages/sr-SP.mjs +8 -1
- package/i18n/languages/zh-CN.js +8 -1
- package/i18n/languages/zh-CN.mjs +8 -1
- package/i18n/languages/zh-TW.js +8 -1
- package/i18n/languages/zh-TW.mjs +8 -1
- package/index.d.ts +9 -0
- package/languages/all.js +168 -21
- package/languages/ar-AR.js +8 -1
- package/languages/ar-AR.mjs +8 -1
- package/languages/cs-CZ.js +8 -1
- package/languages/cs-CZ.mjs +8 -1
- package/languages/de-CH.js +8 -1
- package/languages/de-CH.mjs +8 -1
- package/languages/de-DE.js +8 -1
- package/languages/de-DE.mjs +8 -1
- package/languages/en-US.js +8 -1
- package/languages/en-US.mjs +8 -1
- package/languages/es-MX.js +8 -1
- package/languages/es-MX.mjs +8 -1
- package/languages/fa-IR.js +8 -1
- package/languages/fa-IR.mjs +8 -1
- package/languages/fr-FR.js +8 -1
- package/languages/fr-FR.mjs +8 -1
- package/languages/hr-HR.js +8 -1
- package/languages/hr-HR.mjs +8 -1
- package/languages/index.js +168 -21
- package/languages/it-IT.js +8 -1
- package/languages/it-IT.mjs +8 -1
- package/languages/ja-JP.js +8 -1
- package/languages/ja-JP.mjs +8 -1
- package/languages/ko-KR.js +8 -1
- package/languages/ko-KR.mjs +8 -1
- package/languages/lv-LV.js +8 -1
- package/languages/lv-LV.mjs +8 -1
- package/languages/nb-NO.js +8 -1
- package/languages/nb-NO.mjs +8 -1
- package/languages/nl-NL.js +8 -1
- package/languages/nl-NL.mjs +8 -1
- package/languages/pl-PL.js +8 -1
- package/languages/pl-PL.mjs +8 -1
- package/languages/pt-BR.js +8 -1
- package/languages/pt-BR.mjs +8 -1
- package/languages/ru-RU.js +8 -1
- package/languages/ru-RU.mjs +8 -1
- package/languages/sr-SP.js +8 -1
- package/languages/sr-SP.mjs +8 -1
- package/languages/zh-CN.js +8 -1
- package/languages/zh-CN.mjs +8 -1
- package/languages/zh-TW.js +8 -1
- package/languages/zh-TW.mjs +8 -1
- package/package.json +25 -7
- package/plugins/autoRowSize/autoRowSize.js +8 -1
- package/plugins/autoRowSize/autoRowSize.mjs +8 -1
- package/plugins/base/base.js +36 -10
- package/plugins/base/base.mjs +36 -10
- package/plugins/columnSummary/endpoints.js +13 -3
- package/plugins/columnSummary/endpoints.mjs +13 -3
- package/plugins/customBorders/customBorders.d.ts +1 -0
- package/plugins/customBorders/customBorders.js +32 -2
- package/plugins/customBorders/customBorders.mjs +32 -2
- package/plugins/dialog/constants.js +7 -0
- package/plugins/dialog/constants.mjs +4 -0
- package/plugins/dialog/dialog.d.ts +22 -2
- package/plugins/dialog/dialog.js +197 -81
- package/plugins/dialog/dialog.mjs +196 -81
- package/plugins/dialog/templates/base.js +60 -0
- package/plugins/dialog/templates/base.mjs +56 -0
- package/plugins/dialog/templates/confirm.js +106 -0
- package/plugins/dialog/templates/confirm.mjs +102 -0
- package/plugins/dialog/templates/index.js +6 -0
- package/plugins/dialog/templates/index.mjs +4 -0
- package/plugins/dialog/ui.js +125 -41
- package/plugins/dialog/ui.mjs +119 -35
- package/plugins/emptyDataState/emptyDataState.d.ts +24 -0
- package/plugins/emptyDataState/emptyDataState.js +526 -0
- package/plugins/emptyDataState/emptyDataState.mjs +521 -0
- package/plugins/emptyDataState/index.d.ts +1 -0
- package/plugins/emptyDataState/index.js +7 -0
- package/plugins/emptyDataState/index.mjs +1 -0
- package/plugins/emptyDataState/ui.js +282 -0
- package/plugins/emptyDataState/ui.mjs +278 -0
- package/plugins/filters/component/value.js +16 -1
- package/plugins/filters/component/value.mjs +16 -1
- package/plugins/filters/filters.d.ts +5 -1
- package/plugins/filters/filters.js +22 -1
- package/plugins/filters/filters.mjs +22 -1
- package/plugins/filters/ui/multipleSelect.js +90 -79
- package/plugins/filters/ui/multipleSelect.mjs +90 -79
- package/plugins/index.d.ts +3 -0
- package/plugins/index.js +3 -0
- package/plugins/index.mjs +3 -1
- package/plugins/mergeCells/utils.js +1 -5
- package/plugins/mergeCells/utils.mjs +1 -5
- package/plugins/pagination/pagination.js +37 -175
- package/plugins/pagination/pagination.mjs +37 -175
- package/plugins/pagination/strategies/autoPageSize.js +2 -2
- package/plugins/pagination/strategies/autoPageSize.mjs +2 -2
- package/plugins/pagination/ui.js +6 -10
- package/plugins/pagination/ui.mjs +7 -11
- package/plugins/stretchColumns/calculator.js +3 -1
- package/plugins/stretchColumns/calculator.mjs +3 -1
- package/plugins/undoRedo/undoRedo.js +16 -6
- package/plugins/undoRedo/undoRedo.mjs +16 -5
- package/renderers/checkboxRenderer/checkboxRenderer.js +12 -15
- package/renderers/checkboxRenderer/checkboxRenderer.mjs +12 -15
- package/selection/selection.js +1 -1
- package/selection/selection.mjs +1 -1
- package/settings.d.ts +3 -0
- package/shortcutContexts/commands/index.js +2 -1
- package/shortcutContexts/commands/index.mjs +2 -1
- package/shortcutContexts/commands/tabNavigation.js +51 -0
- package/shortcutContexts/commands/tabNavigation.mjs +48 -0
- package/shortcutContexts/constants.js +16 -1
- package/shortcutContexts/constants.mjs +16 -1
- package/shortcutContexts/editor.js +2 -2
- package/shortcutContexts/editor.mjs +3 -3
- package/shortcutContexts/grid.js +19 -3
- package/shortcutContexts/grid.mjs +20 -4
- package/shortcuts/manager.d.ts +1 -0
- package/shortcuts/manager.js +17 -2
- package/shortcuts/manager.mjs +17 -2
- package/styles/handsontable.css +192 -35
- package/styles/handsontable.min.css +3 -3
- package/styles/ht-icons-horizon.css +233 -0
- package/styles/ht-icons-horizon.min.css +30 -0
- package/styles/ht-icons-main.css +233 -0
- package/styles/ht-icons-main.min.css +30 -0
- package/styles/ht-theme-classic-no-icons.css +399 -0
- package/styles/ht-theme-classic-no-icons.min.css +30 -0
- package/styles/ht-theme-classic.css +308 -556
- package/styles/ht-theme-classic.min.css +3 -3
- package/styles/ht-theme-horizon-no-icons.css +405 -0
- package/styles/ht-theme-horizon-no-icons.min.css +30 -0
- package/styles/ht-theme-horizon.css +312 -556
- package/styles/ht-theme-horizon.min.css +3 -3
- package/styles/ht-theme-main-no-icons.css +396 -0
- package/styles/ht-theme-main-no-icons.min.css +30 -0
- package/styles/ht-theme-main.css +303 -556
- package/styles/ht-theme-main.min.css +3 -3
- package/tableView.js +23 -5
- package/tableView.mjs +23 -5
- package/utils/dataStructures/uniqueMap.js +10 -0
- package/utils/dataStructures/uniqueMap.mjs +10 -0
- package/utils/ghostTable.js +0 -3
- package/utils/ghostTable.mjs +0 -3
- package/utils/stylesHandler.js +19 -4
- package/utils/stylesHandler.mjs +19 -4
- package/core/focusCatcher/index.js +0 -131
- package/core/focusCatcher/index.mjs +0 -127
- package/core/focusCatcher/utils.js +0 -31
- package/core/focusCatcher/utils.mjs +0 -27
- package/plugins/pagination/focusController.js +0 -27
- package/plugins/pagination/focusController.mjs +0 -23
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import "core-js/modules/es.error.cause.js";
|
|
2
|
+
import "core-js/modules/es.array.at.js";
|
|
3
|
+
import "core-js/modules/es.string.at-alternative.js";
|
|
4
|
+
import "core-js/modules/esnext.iterator.constructor.js";
|
|
5
|
+
import "core-js/modules/esnext.iterator.every.js";
|
|
2
6
|
function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); }
|
|
3
7
|
function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
|
|
4
8
|
function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
@@ -7,8 +11,8 @@ function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
|
7
11
|
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
8
12
|
import { BasePlugin } from "../base/index.mjs";
|
|
9
13
|
import { DialogUI } from "./ui.mjs";
|
|
10
|
-
import { installFocusDetector } from "../../utils/focusDetector.mjs";
|
|
11
14
|
import { isObject } from "../../helpers/object.mjs";
|
|
15
|
+
import * as C from "../../i18n/constants.mjs";
|
|
12
16
|
export const PLUGIN_KEY = 'dialog';
|
|
13
17
|
export const PLUGIN_PRIORITY = 360;
|
|
14
18
|
const SHORTCUTS_GROUP = PLUGIN_KEY;
|
|
@@ -26,6 +30,15 @@ const SHORTCUTS_CONTEXT_NAME = `plugin:${PLUGIN_KEY}`;
|
|
|
26
30
|
* In order to enable the dialog mechanism, {@link Options#dialog} option must be set to `true`.
|
|
27
31
|
*
|
|
28
32
|
* The plugin provides several configuration options to customize the dialog behavior and appearance:
|
|
33
|
+
* - `template`: The template to use for the dialog (default: `null`). The error will be thrown when
|
|
34
|
+
* the template is provided together with the `content` option.
|
|
35
|
+
* - `type`: The type of the template ('confirm')
|
|
36
|
+
* - `title`: The title of the dialog
|
|
37
|
+
* - `description`: The description of the dialog (default: '')
|
|
38
|
+
* - `buttons`: The buttons to display in the dialog (default: [])
|
|
39
|
+
* - `text`: The text of the button
|
|
40
|
+
* - `type`: The type of the button ('primary' | 'secondary')
|
|
41
|
+
* - `callback`: The callback to trigger when the button is clicked
|
|
29
42
|
* - `content`: The string or HTMLElement content to display in the dialog (default: '')
|
|
30
43
|
* - `customClassName`: Custom class name to apply to the dialog (default: '')
|
|
31
44
|
* - `background`: Dialog background variant 'solid' | 'semi-transparent' (default: 'solid')
|
|
@@ -33,14 +46,10 @@ const SHORTCUTS_CONTEXT_NAME = `plugin:${PLUGIN_KEY}`;
|
|
|
33
46
|
* - `animation`: Whether to enable animations (default: true)
|
|
34
47
|
* - `closable`: Whether the dialog can be closed (default: false)
|
|
35
48
|
* - `a11y`: Object with accessibility options (default object below)
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* ariaLabelledby: '', // ID of the element that labels the dialog (default: '')
|
|
41
|
-
* ariaDescribedby: '', // ID of the element that describes the dialog (default: ''),
|
|
42
|
-
* }
|
|
43
|
-
* ```
|
|
49
|
+
* - `role`: The role of the dialog ('dialog' | 'alertdialog') (default: 'dialog')
|
|
50
|
+
* - `ariaLabel`: The label of the dialog (default: 'Dialog')
|
|
51
|
+
* - `ariaLabelledby`: The ID of the element that labels the dialog (default: '')
|
|
52
|
+
* - `ariaDescribedby`: The ID of the element that describes the dialog (default: ''),
|
|
44
53
|
*
|
|
45
54
|
* @example
|
|
46
55
|
*
|
|
@@ -65,6 +74,31 @@ const SHORTCUTS_CONTEXT_NAME = `plugin:${PLUGIN_KEY}`;
|
|
|
65
74
|
* }
|
|
66
75
|
* }
|
|
67
76
|
*
|
|
77
|
+
* // Enable dialog plugin using prebuild templates
|
|
78
|
+
* dialog: {
|
|
79
|
+
* template: {
|
|
80
|
+
* type: 'confirm',
|
|
81
|
+
* title: 'Confirm',
|
|
82
|
+
* description: 'This is a confirm',
|
|
83
|
+
* buttons: [
|
|
84
|
+
* {
|
|
85
|
+
* text: 'Ok',
|
|
86
|
+
* type: 'primary',
|
|
87
|
+
* callback: () => {
|
|
88
|
+
* console.log('Ok');
|
|
89
|
+
* }
|
|
90
|
+
* },
|
|
91
|
+
* {
|
|
92
|
+
* text: 'Cancel',
|
|
93
|
+
* type: 'secondary',
|
|
94
|
+
* callback: () => {
|
|
95
|
+
* console.log('Cancel');
|
|
96
|
+
* }
|
|
97
|
+
* },
|
|
98
|
+
* ],
|
|
99
|
+
* },
|
|
100
|
+
* }
|
|
101
|
+
*
|
|
68
102
|
* // Access to dialog plugin instance:
|
|
69
103
|
* const dialogPlugin = hot.getPlugin('dialog');
|
|
70
104
|
*
|
|
@@ -136,7 +170,6 @@ const SHORTCUTS_CONTEXT_NAME = `plugin:${PLUGIN_KEY}`;
|
|
|
136
170
|
*/
|
|
137
171
|
var _ui = /*#__PURE__*/new WeakMap();
|
|
138
172
|
var _isVisible = /*#__PURE__*/new WeakMap();
|
|
139
|
-
var _focusDetector = /*#__PURE__*/new WeakMap();
|
|
140
173
|
var _selectionState = /*#__PURE__*/new WeakMap();
|
|
141
174
|
var _Dialog_brand = /*#__PURE__*/new WeakSet();
|
|
142
175
|
export class Dialog extends BasePlugin {
|
|
@@ -158,12 +191,6 @@ export class Dialog extends BasePlugin {
|
|
|
158
191
|
* @type {boolean}
|
|
159
192
|
*/
|
|
160
193
|
_classPrivateFieldInitSpec(this, _isVisible, false);
|
|
161
|
-
/**
|
|
162
|
-
* Focus detector instance.
|
|
163
|
-
*
|
|
164
|
-
* @type {FocusDetector}
|
|
165
|
-
*/
|
|
166
|
-
_classPrivateFieldInitSpec(this, _focusDetector, null);
|
|
167
194
|
/**
|
|
168
195
|
* Keeps the selection state that will be restored after the dialog is closed.
|
|
169
196
|
*
|
|
@@ -179,6 +206,7 @@ export class Dialog extends BasePlugin {
|
|
|
179
206
|
}
|
|
180
207
|
static get DEFAULT_SETTINGS() {
|
|
181
208
|
return {
|
|
209
|
+
template: null,
|
|
182
210
|
content: '',
|
|
183
211
|
customClassName: '',
|
|
184
212
|
background: 'solid',
|
|
@@ -195,6 +223,7 @@ export class Dialog extends BasePlugin {
|
|
|
195
223
|
}
|
|
196
224
|
static get SETTINGS_VALIDATORS() {
|
|
197
225
|
return {
|
|
226
|
+
template: value => isObject(value) && typeof ['alert', 'confirm'].includes(value.type) && typeof value.title === 'string' && (typeof (value === null || value === void 0 ? void 0 : value.description) === 'undefined' || typeof (value === null || value === void 0 ? void 0 : value.description) === 'string') && (typeof (value === null || value === void 0 ? void 0 : value.buttons) === 'undefined' || Array.isArray(value === null || value === void 0 ? void 0 : value.buttons) && value.buttons.every(item => typeof item === 'object' && typeof item.text === 'string' && ['primary', 'secondary'].includes(item.type) && (typeof item.callback === 'undefined' || typeof item.callback === 'function'))),
|
|
198
227
|
content: value => typeof value === 'string' || typeof HTMLElement !== 'undefined' && value instanceof HTMLElement || typeof DocumentFragment !== 'undefined' && value instanceof DocumentFragment,
|
|
199
228
|
customClassName: value => typeof value === 'string',
|
|
200
229
|
background: value => ['solid', 'semi-transparent'].includes(value),
|
|
@@ -225,20 +254,10 @@ export class Dialog extends BasePlugin {
|
|
|
225
254
|
rootElement: this.hot.rootGridElement,
|
|
226
255
|
isRtl: this.hot.isRtl()
|
|
227
256
|
}));
|
|
228
|
-
_classPrivateFieldGet(_ui, this).addLocalHook('clickDialogElement', () => _assertClassBrand(_Dialog_brand, this, _onDialogClick).call(this));
|
|
229
|
-
_classPrivateFieldSet(_focusDetector, this, installFocusDetector(this.hot, _classPrivateFieldGet(_ui, this).getDialogElement(), {
|
|
230
|
-
onFocus: from => {
|
|
231
|
-
this.hot.getShortcutManager().setActiveContextName(SHORTCUTS_CONTEXT_NAME);
|
|
232
|
-
this.hot.listen();
|
|
233
|
-
this.hot.runHooks('afterDialogFocus', `tab_${from}`);
|
|
234
|
-
}
|
|
235
|
-
}));
|
|
236
257
|
}
|
|
237
258
|
_assertClassBrand(_Dialog_brand, this, _registerShortcuts).call(this);
|
|
238
|
-
|
|
239
|
-
this.addHook('afterViewRender', () => _assertClassBrand(_Dialog_brand, this,
|
|
240
|
-
this.addHook('afterListen', () => _assertClassBrand(_Dialog_brand, this, _onAfterListen).call(this));
|
|
241
|
-
this.addHook('afterUnlisten', () => _assertClassBrand(_Dialog_brand, this, _onAfterUnlisten).call(this));
|
|
259
|
+
_assertClassBrand(_Dialog_brand, this, _registerFocusScope).call(this);
|
|
260
|
+
this.addHook('afterViewRender', () => _assertClassBrand(_Dialog_brand, this, _onAfterViewRender).call(this));
|
|
242
261
|
super.enablePlugin();
|
|
243
262
|
}
|
|
244
263
|
|
|
@@ -257,8 +276,10 @@ export class Dialog extends BasePlugin {
|
|
|
257
276
|
disablePlugin() {
|
|
258
277
|
this.hide();
|
|
259
278
|
_assertClassBrand(_Dialog_brand, this, _unregisterShortcuts).call(this);
|
|
279
|
+
_assertClassBrand(_Dialog_brand, this, _unregisterFocusScope).call(this);
|
|
260
280
|
super.disablePlugin();
|
|
261
281
|
}
|
|
282
|
+
|
|
262
283
|
/**
|
|
263
284
|
* Check if the dialog is currently visible.
|
|
264
285
|
*
|
|
@@ -273,6 +294,15 @@ export class Dialog extends BasePlugin {
|
|
|
273
294
|
* Displays the dialog with the specified content and options.
|
|
274
295
|
*
|
|
275
296
|
* @param {object} options Dialog configuration object containing content and display options.
|
|
297
|
+
* @param {object} options.template The template to use for the dialog (default: `null`). The error will be thrown when
|
|
298
|
+
* the template is provided together with the `content` option.
|
|
299
|
+
* @param {'confirm'} options.template.type The type of the template ('confirm').
|
|
300
|
+
* @param {string} options.template.title The title of the dialog.
|
|
301
|
+
* @param {string} options.template.description The description of the dialog. Default: ''.
|
|
302
|
+
* @param {object[]} options.template.buttons The buttons to display in the dialog. Default: [].
|
|
303
|
+
* @param {string} options.template.buttons.text The text of the button.
|
|
304
|
+
* @param {'primary' | 'secondary'} options.template.buttons.type The type of the button.
|
|
305
|
+
* @param {function(MouseEvent)} options.template.buttons.callback The callback to trigger when the button is clicked.
|
|
276
306
|
* @param {string|HTMLElement|DocumentFragment} options.content The content to display in the dialog. Can be a string, HTMLElement, or DocumentFragment. Default: ''
|
|
277
307
|
* @param {string} options.customClassName Custom CSS class name to apply to the dialog container. Default: ''
|
|
278
308
|
* @param {'solid'|'semi-transparent'} options.background Dialog background variant. Default: 'solid'.
|
|
@@ -298,19 +328,10 @@ export class Dialog extends BasePlugin {
|
|
|
298
328
|
this.update(options);
|
|
299
329
|
_classPrivateFieldGet(_ui, this).showDialog(this.getSetting('animation'));
|
|
300
330
|
_classPrivateFieldSet(_isVisible, this, true);
|
|
331
|
+
this.hot.getFocusScopeManager().activateScope(PLUGIN_KEY);
|
|
301
332
|
_classPrivateFieldSet(_selectionState, this, this.hot.selection.exportSelection());
|
|
302
333
|
this.hot.deselectCell();
|
|
303
334
|
this.hot.runHooks('afterDialogShow');
|
|
304
|
-
const {
|
|
305
|
-
activeElement
|
|
306
|
-
} = this.hot.rootDocument;
|
|
307
|
-
if (this.hot.rootWrapperElement.contains(activeElement) || this.hot.rootPortalElement.contains(activeElement)) {
|
|
308
|
-
this.hot.unlisten();
|
|
309
|
-
this.hot.getShortcutManager().setActiveContextName(SHORTCUTS_CONTEXT_NAME);
|
|
310
|
-
this.hot.listen();
|
|
311
|
-
_classPrivateFieldGet(_ui, this).focusDialog();
|
|
312
|
-
this.hot.runHooks('afterDialogFocus', 'show');
|
|
313
|
-
}
|
|
314
335
|
}
|
|
315
336
|
|
|
316
337
|
/**
|
|
@@ -318,14 +339,15 @@ export class Dialog extends BasePlugin {
|
|
|
318
339
|
* Closes the dialog and restores the focus to the table.
|
|
319
340
|
*/
|
|
320
341
|
hide() {
|
|
342
|
+
var _classPrivateFieldGet2;
|
|
321
343
|
if (!this.isVisible()) {
|
|
322
344
|
return;
|
|
323
345
|
}
|
|
324
346
|
this.hot.runHooks('beforeDialogHide');
|
|
325
347
|
_classPrivateFieldGet(_ui, this).hideDialog(this.getSetting('animation'));
|
|
326
|
-
this.hot.getShortcutManager().setActiveContextName('grid');
|
|
327
348
|
_classPrivateFieldSet(_isVisible, this, false);
|
|
328
|
-
|
|
349
|
+
this.hot.getFocusScopeManager().deactivateScope(PLUGIN_KEY);
|
|
350
|
+
if (((_classPrivateFieldGet2 = _classPrivateFieldGet(_selectionState, this)) === null || _classPrivateFieldGet2 === void 0 ? void 0 : _classPrivateFieldGet2.ranges.length) > 0) {
|
|
329
351
|
this.hot.selection.importSelection(_classPrivateFieldGet(_selectionState, this));
|
|
330
352
|
this.hot.view.render();
|
|
331
353
|
_classPrivateFieldSet(_selectionState, this, null);
|
|
@@ -339,6 +361,15 @@ export class Dialog extends BasePlugin {
|
|
|
339
361
|
* Update the dialog configuration.
|
|
340
362
|
*
|
|
341
363
|
* @param {object} options Dialog configuration object containing content and display options.
|
|
364
|
+
* @param {object} options.template The template to use for the dialog (default: `null`). The error will be thrown when
|
|
365
|
+
* the template is provided together with the `content` option.
|
|
366
|
+
* @param {'confirm'} options.template.type The type of the template ('confirm').
|
|
367
|
+
* @param {string} options.template.title The title of the dialog.
|
|
368
|
+
* @param {string} options.template.description The description of the dialog. Default: ''.
|
|
369
|
+
* @param {object[]} options.template.buttons The buttons to display in the dialog. Default: [].
|
|
370
|
+
* @param {string} options.template.buttons.text The text of the button.
|
|
371
|
+
* @param {'primary' | 'secondary'} options.template.buttons.type The type of the button.
|
|
372
|
+
* @param {function(MouseEvent)} options.template.buttons.callback The callback to trigger when the button is clicked.
|
|
342
373
|
* @param {string|HTMLElement|DocumentFragment} options.content The content to display in the dialog. Can be a string, HTMLElement, or DocumentFragment. Default: ''
|
|
343
374
|
* @param {string} options.customClassName Custom CSS class name to apply to the dialog container. Default: ''
|
|
344
375
|
* @param {'solid'|'semi-transparent'} options.background Dialog background variant. Default: 'solid'.
|
|
@@ -356,6 +387,18 @@ export class Dialog extends BasePlugin {
|
|
|
356
387
|
return;
|
|
357
388
|
}
|
|
358
389
|
this.updatePluginSettings(options);
|
|
390
|
+
const templateValue = this.getSetting('template');
|
|
391
|
+
if (templateValue !== Dialog.DEFAULT_SETTINGS.template && this.getSetting('content') !== Dialog.DEFAULT_SETTINGS.content) {
|
|
392
|
+
throw new Error('The `template` option cannot be used together with the `content` option.');
|
|
393
|
+
}
|
|
394
|
+
if (templateValue) {
|
|
395
|
+
_classPrivateFieldGet(_ui, this).useTemplate(templateValue.type, {
|
|
396
|
+
id: this.hot.guid,
|
|
397
|
+
...templateValue
|
|
398
|
+
});
|
|
399
|
+
} else {
|
|
400
|
+
_classPrivateFieldGet(_ui, this).useDefaultTemplate();
|
|
401
|
+
}
|
|
359
402
|
_classPrivateFieldGet(_ui, this).updateDialog({
|
|
360
403
|
isVisible: this.isVisible(),
|
|
361
404
|
content: this.getSetting('content'),
|
|
@@ -368,28 +411,103 @@ export class Dialog extends BasePlugin {
|
|
|
368
411
|
}
|
|
369
412
|
|
|
370
413
|
/**
|
|
371
|
-
*
|
|
414
|
+
* Displays the alert dialog with the specified content.
|
|
415
|
+
*
|
|
416
|
+
* @param {string | { title: string, description: string }} message The message to display in the dialog.
|
|
417
|
+
* Can be a string or an object with `title` and `description` properties.
|
|
418
|
+
* @param {function(MouseEvent): void} [callback] The callback to trigger when the button is clicked.
|
|
372
419
|
*/
|
|
373
|
-
|
|
374
|
-
|
|
420
|
+
showAlert(message, callback) {
|
|
421
|
+
const {
|
|
422
|
+
title = 'Alert',
|
|
423
|
+
description
|
|
424
|
+
} = isObject(message) ? message : {
|
|
425
|
+
title: message
|
|
426
|
+
};
|
|
427
|
+
this.show({
|
|
428
|
+
template: {
|
|
429
|
+
type: 'confirm',
|
|
430
|
+
title,
|
|
431
|
+
description,
|
|
432
|
+
buttons: [{
|
|
433
|
+
text: this.hot.getTranslatedPhrase(C.OK),
|
|
434
|
+
type: 'primary',
|
|
435
|
+
callback: function () {
|
|
436
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
437
|
+
args[_key] = arguments[_key];
|
|
438
|
+
}
|
|
439
|
+
return callback === null || callback === void 0 ? void 0 : callback(...args);
|
|
440
|
+
}
|
|
441
|
+
}]
|
|
442
|
+
},
|
|
443
|
+
contentBackground: false,
|
|
444
|
+
background: 'solid',
|
|
445
|
+
animation: true,
|
|
446
|
+
closable: false
|
|
447
|
+
});
|
|
375
448
|
}
|
|
376
449
|
|
|
377
450
|
/**
|
|
378
|
-
*
|
|
451
|
+
* Displays the confirm dialog with the specified content and options.
|
|
379
452
|
*
|
|
380
|
-
* @param {
|
|
381
|
-
*
|
|
453
|
+
* @param {string | { title: string, description: string }} message The message to display in the dialog.
|
|
454
|
+
* Can be a string or an object with `title` and `description` properties.
|
|
455
|
+
* @param {function(MouseEvent): void} [onOk] The callback to trigger when the OK button is clicked.
|
|
456
|
+
* @param {function(MouseEvent): void} [onCancel] The callback to trigger when the Cancel button is clicked.
|
|
382
457
|
*/
|
|
458
|
+
showConfirm(message, onOk, onCancel) {
|
|
459
|
+
const {
|
|
460
|
+
title = 'Confirm',
|
|
461
|
+
description
|
|
462
|
+
} = isObject(message) ? message : {
|
|
463
|
+
title: message
|
|
464
|
+
};
|
|
465
|
+
this.show({
|
|
466
|
+
template: {
|
|
467
|
+
type: 'confirm',
|
|
468
|
+
title,
|
|
469
|
+
description,
|
|
470
|
+
buttons: [{
|
|
471
|
+
text: this.hot.getTranslatedPhrase(C.CANCEL),
|
|
472
|
+
type: 'secondary',
|
|
473
|
+
callback: function () {
|
|
474
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
475
|
+
args[_key2] = arguments[_key2];
|
|
476
|
+
}
|
|
477
|
+
return onCancel === null || onCancel === void 0 ? void 0 : onCancel(...args);
|
|
478
|
+
}
|
|
479
|
+
}, {
|
|
480
|
+
text: this.hot.getTranslatedPhrase(C.OK),
|
|
481
|
+
type: 'primary',
|
|
482
|
+
callback: function () {
|
|
483
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
484
|
+
args[_key3] = arguments[_key3];
|
|
485
|
+
}
|
|
486
|
+
return onOk === null || onOk === void 0 ? void 0 : onOk(...args);
|
|
487
|
+
}
|
|
488
|
+
}]
|
|
489
|
+
},
|
|
490
|
+
contentBackground: true,
|
|
491
|
+
background: 'semi-transparent',
|
|
492
|
+
animation: true,
|
|
493
|
+
closable: false
|
|
494
|
+
});
|
|
495
|
+
}
|
|
383
496
|
|
|
497
|
+
/**
|
|
498
|
+
* Focus the dialog.
|
|
499
|
+
*/
|
|
500
|
+
focus() {
|
|
501
|
+
_classPrivateFieldGet(_ui, this).focusDialog();
|
|
502
|
+
}
|
|
384
503
|
/**
|
|
385
504
|
* Destroy dialog and reset plugin state.
|
|
386
505
|
*/
|
|
387
506
|
destroy() {
|
|
388
|
-
var
|
|
389
|
-
(
|
|
507
|
+
var _classPrivateFieldGet3;
|
|
508
|
+
(_classPrivateFieldGet3 = _classPrivateFieldGet(_ui, this)) === null || _classPrivateFieldGet3 === void 0 || _classPrivateFieldGet3.destroyDialog();
|
|
390
509
|
_classPrivateFieldSet(_ui, this, null);
|
|
391
510
|
_classPrivateFieldSet(_isVisible, this, false);
|
|
392
|
-
_classPrivateFieldSet(_focusDetector, this, null);
|
|
393
511
|
_classPrivateFieldSet(_selectionState, this, null);
|
|
394
512
|
super.destroy();
|
|
395
513
|
}
|
|
@@ -411,19 +529,12 @@ function _registerShortcuts() {
|
|
|
411
529
|
preventDefault: false,
|
|
412
530
|
callback: event => {
|
|
413
531
|
this.hot._registerTimeout(() => {
|
|
414
|
-
const {
|
|
415
|
-
activeElement
|
|
416
|
-
} = this.hot.rootDocument;
|
|
417
|
-
if (!_classPrivateFieldGet(_ui, this).isInsideDialog(activeElement)) {
|
|
418
|
-
this.hot.unlisten();
|
|
419
|
-
return;
|
|
420
|
-
}
|
|
421
532
|
if (event.shiftKey) {
|
|
422
533
|
this.hot.runHooks('dialogFocusPreviousElement');
|
|
423
534
|
} else {
|
|
424
535
|
this.hot.runHooks('dialogFocusNextElement');
|
|
425
536
|
}
|
|
426
|
-
}
|
|
537
|
+
});
|
|
427
538
|
},
|
|
428
539
|
group: SHORTCUTS_GROUP
|
|
429
540
|
});
|
|
@@ -436,39 +547,43 @@ function _unregisterShortcuts() {
|
|
|
436
547
|
const pluginContext = shortcutManager.getContext(SHORTCUTS_CONTEXT_NAME);
|
|
437
548
|
pluginContext.removeShortcutsByGroup(SHORTCUTS_GROUP);
|
|
438
549
|
}
|
|
439
|
-
function _onFocusTabNavigation(from) {
|
|
440
|
-
if (this.isVisible()) {
|
|
441
|
-
_classPrivateFieldGet(_focusDetector, this).focus(from);
|
|
442
|
-
return false;
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
550
|
/**
|
|
446
|
-
*
|
|
551
|
+
* Registers the focus scope for the dialog plugin.
|
|
447
552
|
*/
|
|
448
|
-
function
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
553
|
+
function _registerFocusScope() {
|
|
554
|
+
this.hot.getFocusScopeManager().registerScope(PLUGIN_KEY, _classPrivateFieldGet(_ui, this).getContainer(), {
|
|
555
|
+
shortcutsContextName: SHORTCUTS_CONTEXT_NAME,
|
|
556
|
+
type: 'modal',
|
|
557
|
+
runOnlyIf: () => this.isVisible(),
|
|
558
|
+
onActivate: focusSource => {
|
|
559
|
+
const isListening = this.hot.isListening();
|
|
560
|
+
const focusableElements = _classPrivateFieldGet(_ui, this).getFocusableElements();
|
|
561
|
+
if (focusableElements.length > 0) {
|
|
562
|
+
if (focusSource === 'tab_from_above') {
|
|
563
|
+
focusableElements.at(0).focus();
|
|
564
|
+
} else if (focusSource === 'tab_from_below') {
|
|
565
|
+
focusableElements.at(-1).focus();
|
|
566
|
+
}
|
|
567
|
+
} else if (focusSource !== 'tab_from_above' && focusSource !== 'tab_from_below' && isListening && !_classPrivateFieldGet(_ui, this).getContainer().contains(this.hot.rootDocument.activeElement)) {
|
|
568
|
+
_classPrivateFieldGet(_ui, this).getContainer().focus();
|
|
569
|
+
}
|
|
570
|
+
if (isListening) {
|
|
571
|
+
this.hot.runHooks('afterDialogFocus', focusSource === 'unknown' ? 'show' : focusSource);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
});
|
|
460
575
|
}
|
|
461
576
|
/**
|
|
462
|
-
*
|
|
577
|
+
* Unregisters the focus scope for the dialog plugin.
|
|
463
578
|
*/
|
|
464
|
-
function
|
|
465
|
-
|
|
579
|
+
function _unregisterFocusScope() {
|
|
580
|
+
this.hot.getFocusScopeManager().unregisterScope(PLUGIN_KEY);
|
|
466
581
|
}
|
|
467
582
|
/**
|
|
468
583
|
* Called after the rendering of the table is completed. It updates the width and
|
|
469
584
|
* height of the dialog container to the same size as the table.
|
|
470
585
|
*/
|
|
471
|
-
function
|
|
586
|
+
function _onAfterViewRender() {
|
|
472
587
|
const {
|
|
473
588
|
view,
|
|
474
589
|
rootWrapperElement,
|
|
@@ -479,7 +594,7 @@ function _onAfterRender() {
|
|
|
479
594
|
const dialogInfo = rootWrapperElement.querySelector('.hot-display-license-info');
|
|
480
595
|
if (dialogInfo) {
|
|
481
596
|
const height = dialogInfo.offsetHeight;
|
|
482
|
-
const marginTop = parseFloat(rootWindow.getComputedStyle(dialogInfo).marginTop);
|
|
597
|
+
const marginTop = Number.parseFloat(rootWindow.getComputedStyle(dialogInfo).marginTop);
|
|
483
598
|
_classPrivateFieldGet(_ui, this).updateHeight(height + marginTop);
|
|
484
599
|
}
|
|
485
600
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.baseTemplate = baseTemplate;
|
|
5
|
+
require("core-js/modules/es.error.cause.js");
|
|
6
|
+
var _constants = require("../constants");
|
|
7
|
+
var _templateLiteralTag = require("../../../helpers/templateLiteralTag");
|
|
8
|
+
/**
|
|
9
|
+
* The `baseTemplate` function returns a HTML string with the base template.
|
|
10
|
+
*
|
|
11
|
+
* @returns {string} HTML string with the base template.
|
|
12
|
+
*/
|
|
13
|
+
function baseTemplate() {
|
|
14
|
+
/**
|
|
15
|
+
* Returns the HTML string for the template.
|
|
16
|
+
*
|
|
17
|
+
* @returns {string}
|
|
18
|
+
*/
|
|
19
|
+
function template() {
|
|
20
|
+
return `
|
|
21
|
+
<div data-ref="contentElement" class="${_constants.DIALOG_CLASS_NAME}__content"></div>
|
|
22
|
+
`;
|
|
23
|
+
}
|
|
24
|
+
let fragment = null;
|
|
25
|
+
const refs = {};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Compiles the template.
|
|
29
|
+
*
|
|
30
|
+
* @returns {object} The compiled template.
|
|
31
|
+
*/
|
|
32
|
+
function compile() {
|
|
33
|
+
const elements = (0, _templateLiteralTag.html)`${template()}`;
|
|
34
|
+
Object.assign(refs, elements.refs);
|
|
35
|
+
fragment = elements.fragment;
|
|
36
|
+
return elements;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Gets the focusable elements of the template.
|
|
41
|
+
*
|
|
42
|
+
* @returns {HTMLElement[]} The focusable elements.
|
|
43
|
+
*/
|
|
44
|
+
function focusableElements() {
|
|
45
|
+
if (fragment === null) {
|
|
46
|
+
throw new Error('Compile the template first.');
|
|
47
|
+
}
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
TEMPLATE_NAME: 'base',
|
|
52
|
+
dialogA11YOptions() {
|
|
53
|
+
return {
|
|
54
|
+
role: 'dialog'
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
compile,
|
|
58
|
+
focusableElements
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import "core-js/modules/es.error.cause.js";
|
|
2
|
+
import { DIALOG_CLASS_NAME } from "../constants.mjs";
|
|
3
|
+
import { html } from "../../../helpers/templateLiteralTag.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* The `baseTemplate` function returns a HTML string with the base template.
|
|
6
|
+
*
|
|
7
|
+
* @returns {string} HTML string with the base template.
|
|
8
|
+
*/
|
|
9
|
+
export function baseTemplate() {
|
|
10
|
+
/**
|
|
11
|
+
* Returns the HTML string for the template.
|
|
12
|
+
*
|
|
13
|
+
* @returns {string}
|
|
14
|
+
*/
|
|
15
|
+
function template() {
|
|
16
|
+
return `
|
|
17
|
+
<div data-ref="contentElement" class="${DIALOG_CLASS_NAME}__content"></div>
|
|
18
|
+
`;
|
|
19
|
+
}
|
|
20
|
+
let fragment = null;
|
|
21
|
+
const refs = {};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Compiles the template.
|
|
25
|
+
*
|
|
26
|
+
* @returns {object} The compiled template.
|
|
27
|
+
*/
|
|
28
|
+
function compile() {
|
|
29
|
+
const elements = html`${template()}`;
|
|
30
|
+
Object.assign(refs, elements.refs);
|
|
31
|
+
fragment = elements.fragment;
|
|
32
|
+
return elements;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Gets the focusable elements of the template.
|
|
37
|
+
*
|
|
38
|
+
* @returns {HTMLElement[]} The focusable elements.
|
|
39
|
+
*/
|
|
40
|
+
function focusableElements() {
|
|
41
|
+
if (fragment === null) {
|
|
42
|
+
throw new Error('Compile the template first.');
|
|
43
|
+
}
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
TEMPLATE_NAME: 'base',
|
|
48
|
+
dialogA11YOptions() {
|
|
49
|
+
return {
|
|
50
|
+
role: 'dialog'
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
compile,
|
|
54
|
+
focusableElements
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.confirmTemplate = confirmTemplate;
|
|
5
|
+
require("core-js/modules/es.error.cause.js");
|
|
6
|
+
require("core-js/modules/es.array.push.js");
|
|
7
|
+
require("core-js/modules/esnext.iterator.constructor.js");
|
|
8
|
+
require("core-js/modules/esnext.iterator.map.js");
|
|
9
|
+
var _constants = require("../constants");
|
|
10
|
+
var _string = require("../../../helpers/string");
|
|
11
|
+
var _templateLiteralTag = require("../../../helpers/templateLiteralTag");
|
|
12
|
+
/**
|
|
13
|
+
* The `confirmTemplate` function returns a HTML string with the confirm template.
|
|
14
|
+
*
|
|
15
|
+
* @param {object} vars The variables to use for the template.
|
|
16
|
+
* @param {string} vars.id The ID of the confirm.
|
|
17
|
+
* @param {string} vars.title The title of the confirm.
|
|
18
|
+
* @param {string} vars.description The description of the confirm.
|
|
19
|
+
* @param {object[]} vars.buttons The buttons to display in the confirm.
|
|
20
|
+
* - `text`: The text of the button.
|
|
21
|
+
* - `type`: The type of the button ('primary' | 'secondary').
|
|
22
|
+
* - `callback`: The callback to trigger when the button is clicked.
|
|
23
|
+
* @returns {string} HTML string with the confirm template.
|
|
24
|
+
*/
|
|
25
|
+
function confirmTemplate(_ref) {
|
|
26
|
+
let {
|
|
27
|
+
id = '',
|
|
28
|
+
title = '',
|
|
29
|
+
description = '',
|
|
30
|
+
buttons = []
|
|
31
|
+
} = _ref;
|
|
32
|
+
/**
|
|
33
|
+
* Returns the HTML string for the template.
|
|
34
|
+
*
|
|
35
|
+
* @returns {string}
|
|
36
|
+
*/
|
|
37
|
+
function template() {
|
|
38
|
+
return `
|
|
39
|
+
<div tabindex="-1" data-ref="contentElement" class="${_constants.DIALOG_CLASS_NAME}__content-wrapper-inner">
|
|
40
|
+
<div class="${_constants.DIALOG_CLASS_NAME}__content">
|
|
41
|
+
<h2
|
|
42
|
+
id="${id}-dialog-confirm-title"
|
|
43
|
+
class="${_constants.DIALOG_CLASS_NAME}__title">${(0, _string.stripTags)(title)}</h2>
|
|
44
|
+
<p
|
|
45
|
+
id="${id}-dialog-confirm-description"
|
|
46
|
+
class="${_constants.DIALOG_CLASS_NAME}__description">${(0, _string.stripTags)(description)}</p>
|
|
47
|
+
</div>
|
|
48
|
+
${buttons.length > 0 ? `
|
|
49
|
+
<div data-ref="buttonsContainer" class="${_constants.DIALOG_CLASS_NAME}__buttons">
|
|
50
|
+
${buttons.map(button => `
|
|
51
|
+
<button class="ht-button ht-button--${button.type}">${(0, _string.stripTags)(button.text)}</button>
|
|
52
|
+
`).join('')}
|
|
53
|
+
</div>
|
|
54
|
+
` : ''}
|
|
55
|
+
</div>
|
|
56
|
+
`;
|
|
57
|
+
}
|
|
58
|
+
let fragment = null;
|
|
59
|
+
const refs = {};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Compiles the template.
|
|
63
|
+
*
|
|
64
|
+
* @returns {object} The compiled template.
|
|
65
|
+
*/
|
|
66
|
+
function compile() {
|
|
67
|
+
const elements = (0, _templateLiteralTag.html)`${template()}`;
|
|
68
|
+
Object.assign(refs, elements.refs);
|
|
69
|
+
fragment = elements.fragment;
|
|
70
|
+
return elements;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Gets the focusable elements of the template.
|
|
75
|
+
*
|
|
76
|
+
* @returns {HTMLElement[]} The focusable elements.
|
|
77
|
+
*/
|
|
78
|
+
function focusableElements() {
|
|
79
|
+
if (fragment === null) {
|
|
80
|
+
throw new Error('Compile the template first.');
|
|
81
|
+
}
|
|
82
|
+
const {
|
|
83
|
+
contentElement,
|
|
84
|
+
buttonsContainer
|
|
85
|
+
} = refs;
|
|
86
|
+
const elements = [];
|
|
87
|
+
if (buttonsContainer) {
|
|
88
|
+
elements.push(...Array.from(buttonsContainer.children));
|
|
89
|
+
} else {
|
|
90
|
+
elements.push(contentElement);
|
|
91
|
+
}
|
|
92
|
+
return elements;
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
TEMPLATE_NAME: 'confirm',
|
|
96
|
+
dialogA11YOptions() {
|
|
97
|
+
return {
|
|
98
|
+
role: 'alertdialog',
|
|
99
|
+
ariaLabelledby: `${id}-dialog-confirm-title`,
|
|
100
|
+
ariaDescribedby: description ? `${id}-dialog-confirm-description` : undefined
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
compile,
|
|
104
|
+
focusableElements
|
|
105
|
+
};
|
|
106
|
+
}
|