@fabric-msft/fabric-web 5.0.0 → 5.0.1
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/CHANGELOG.json +180 -0
- package/CHANGELOG.md +56 -1
- package/dist/dts/components/accordion-menu/accordion-menu.d.ts +1 -1
- package/dist/dts/components/accordion-menu/accordion-menu.d.ts.map +1 -1
- package/dist/dts/components/accordion-menu-panel/accordion-menu-panel.d.ts +2 -2
- package/dist/dts/components/accordion-menu-panel/accordion-menu-panel.d.ts.map +1 -1
- package/dist/dts/components/component-register.d.ts +67 -0
- package/dist/dts/components/component-register.d.ts.map +1 -0
- package/dist/dts/components/field/field.d.ts +32 -1
- package/dist/dts/components/field/field.d.ts.map +1 -1
- package/dist/dts/components/filter-pill/filter-pill.d.ts +1 -1
- package/dist/dts/components/filter-pill/filter-pill.d.ts.map +1 -1
- package/dist/dts/components/listbox/listbox.d.ts +1 -1
- package/dist/dts/components/listbox/listbox.d.ts.map +1 -1
- package/dist/dts/components/menu/menu.d.ts +71 -83
- package/dist/dts/components/menu/menu.d.ts.map +1 -1
- package/dist/dts/components/menu/menu.positioning.d.ts +26 -67
- package/dist/dts/components/menu/menu.positioning.d.ts.map +1 -1
- package/dist/dts/components/menu/menu.styles.d.ts.map +1 -1
- package/dist/dts/components/menu-item/menu-item.d.ts +4 -4
- package/dist/dts/components/menu-item/menu-item.d.ts.map +1 -1
- package/dist/dts/components/menu-list/menu-list.d.ts +1 -1
- package/dist/dts/components/menu-list/menu-list.d.ts.map +1 -1
- package/dist/dts/components/option-group/option-group.d.ts +1 -1
- package/dist/dts/components/option-group/option-group.d.ts.map +1 -1
- package/dist/dts/components/popover/popover.d.ts +48 -69
- package/dist/dts/components/popover/popover.d.ts.map +1 -1
- package/dist/dts/components/popover/popover.definition.d.ts +1 -1
- package/dist/dts/components/popover/popover.definition.d.ts.map +1 -1
- package/dist/dts/components/popover/popover.options.d.ts +2 -2
- package/dist/dts/components/popover/popover.options.d.ts.map +1 -1
- package/dist/dts/components/popover/popover.positioning.d.ts +92 -0
- package/dist/dts/components/popover/popover.positioning.d.ts.map +1 -0
- package/dist/dts/components/popover/popover.styles.d.ts.map +1 -1
- package/dist/dts/components/search-box/search-box.d.ts +1 -1
- package/dist/dts/components/search-box/search-box.d.ts.map +1 -1
- package/dist/dts/components/search-box/search-box.options.d.ts.map +1 -1
- package/dist/dts/components/table/table.d.ts +1 -1
- package/dist/dts/components/table/table.d.ts.map +1 -1
- package/dist/dts/components/text-input/text-input.base.d.ts +3 -3
- package/dist/dts/components/text-input/text-input.base.d.ts.map +1 -1
- package/dist/dts/components/text-input/text-input.d.ts.map +1 -1
- package/dist/dts/components/tooltip/tooltip.d.ts +5 -0
- package/dist/dts/components/tooltip/tooltip.d.ts.map +1 -1
- package/dist/dts/components/tooltip/tooltip.template.d.ts +13 -0
- package/dist/dts/components/tooltip/tooltip.template.d.ts.map +1 -0
- package/dist/dts/components/tree/tree.d.ts +16 -0
- package/dist/dts/components/tree/tree.d.ts.map +1 -1
- package/dist/dts/components/tree-item/index.d.ts +2 -1
- package/dist/dts/components/tree-item/index.d.ts.map +1 -1
- package/dist/dts/components/tree-item/tree-item.definition.d.ts.map +1 -1
- package/dist/dts/components/tree-item/tree-item.styles.d.ts +2 -0
- package/dist/dts/components/tree-item/tree-item.styles.d.ts.map +1 -0
- package/dist/dts/components/tree-item/tree-item.template.d.ts +4 -0
- package/dist/dts/components/tree-item/tree-item.template.d.ts.map +1 -0
- package/dist/dts/components/wizard/wizard.d.ts +1 -1
- package/dist/dts/components/wizard/wizard.d.ts.map +1 -1
- package/dist/dts/components/wizard-step/wizard-step.d.ts +1 -1
- package/dist/dts/components/wizard-step/wizard-step.d.ts.map +1 -1
- package/dist/dts/index.d.ts +3 -2
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/util/accessibility-utilities.d.ts +23 -0
- package/dist/dts/util/accessibility-utilities.d.ts.map +1 -0
- package/dist/dts/util/attribute-utilities.d.ts +9 -0
- package/dist/dts/util/attribute-utilities.d.ts.map +1 -0
- package/dist/dts/util/debounce.d.ts.map +1 -0
- package/dist/dts/util/debug.d.ts +32 -0
- package/dist/dts/util/debug.d.ts.map +1 -0
- package/dist/dts/util/direction.d.ts +193 -0
- package/dist/dts/util/direction.d.ts.map +1 -1
- package/dist/dts/util/dom.d.ts +2 -0
- package/dist/dts/util/dom.d.ts.map +1 -0
- package/dist/dts/util/element-internal-mocks.d.ts +67 -0
- package/dist/dts/util/element-internal-mocks.d.ts.map +1 -0
- package/dist/dts/util/focus-management.d.ts +132 -0
- package/dist/dts/util/focus-management.d.ts.map +1 -0
- package/dist/dts/util/hash-utilities.d.ts +8 -0
- package/dist/dts/util/hash-utilities.d.ts.map +1 -0
- package/dist/dts/util/index.d.ts +13 -6
- package/dist/dts/util/index.d.ts.map +1 -1
- package/dist/dts/util/positioning/flexible-position-strategy.d.ts +87 -0
- package/dist/dts/util/positioning/flexible-position-strategy.d.ts.map +1 -0
- package/dist/dts/util/positioning/index.d.ts +9 -0
- package/dist/dts/util/positioning/index.d.ts.map +1 -0
- package/dist/dts/util/positioning/position-calculator.d.ts +46 -0
- package/dist/dts/util/positioning/position-calculator.d.ts.map +1 -0
- package/dist/dts/util/positioning/types.d.ts +181 -0
- package/dist/dts/util/positioning/types.d.ts.map +1 -0
- package/dist/esm/components/accordion-menu/accordion-menu.js +1 -1
- package/dist/esm/components/accordion-menu/accordion-menu.js.map +1 -1
- package/dist/esm/components/accordion-menu/accordion-menu.styles.js +1 -1
- package/dist/esm/components/accordion-menu-panel/accordion-menu-panel.js +2 -2
- package/dist/esm/components/accordion-menu-panel/accordion-menu-panel.js.map +1 -1
- package/dist/esm/components/accordion-menu-panel/accordion-menu-panel.styles.js +1 -1
- package/dist/esm/components/card/card.styles.js +1 -1
- package/dist/esm/components/card-footer/card-footer.styles.js +1 -1
- package/dist/esm/components/card-header/card-header.styles.js +1 -1
- package/dist/esm/components/card-preview/card-preview.styles.js +1 -1
- package/dist/esm/components/carousel/carousel.js +1 -1
- package/dist/esm/components/carousel/carousel.js.map +1 -1
- package/dist/esm/components/carousel/carousel.styles.js +1 -1
- package/dist/esm/components/component-register.js +67 -0
- package/dist/esm/components/component-register.js.map +1 -0
- package/dist/esm/components/compound-button/compound-button.options.js +1 -1
- package/dist/esm/components/field/field.js +68 -1
- package/dist/esm/components/field/field.js.map +1 -1
- package/dist/esm/components/filter-pill/filter-pill.js +1 -1
- package/dist/esm/components/filter-pill/filter-pill.js.map +1 -1
- package/dist/esm/components/filter-pill/filter-pill.options.js +1 -1
- package/dist/esm/components/filter-pill/filter-pill.styles.js +3 -2
- package/dist/esm/components/listbox/listbox.js +1 -1
- package/dist/esm/components/listbox/listbox.js.map +1 -1
- package/dist/esm/components/loading-button/loading-button.js.map +1 -1
- package/dist/esm/components/menu/menu.js +158 -230
- package/dist/esm/components/menu/menu.js.map +1 -1
- package/dist/esm/components/menu/menu.options.js +1 -1
- package/dist/esm/components/menu/menu.options.js.map +1 -1
- package/dist/esm/components/menu/menu.positioning.js +98 -201
- package/dist/esm/components/menu/menu.positioning.js.map +1 -1
- package/dist/esm/components/menu/menu.styles.js +2 -2
- package/dist/esm/components/menu/menu.styles.js.map +1 -1
- package/dist/esm/components/menu-item/menu-item.js +4 -4
- package/dist/esm/components/menu-item/menu-item.js.map +1 -1
- package/dist/esm/components/menu-item/menu-item.styles.js +1 -1
- package/dist/esm/components/menu-list/menu-list.js +1 -1
- package/dist/esm/components/menu-list/menu-list.js.map +1 -1
- package/dist/esm/components/menu-list/menu-list.styles.js +1 -1
- package/dist/esm/components/multi-view/multi-view.styles.js +1 -1
- package/dist/esm/components/multi-view-controller/multi-view-controller.styles.js +1 -1
- package/dist/esm/components/multi-view-group/multi-view-group.styles.js +1 -1
- package/dist/esm/components/option-group/option-group.js +1 -1
- package/dist/esm/components/option-group/option-group.js.map +1 -1
- package/dist/esm/components/popover/define.js +2 -2
- package/dist/esm/components/popover/define.js.map +1 -1
- package/dist/esm/components/popover/popover.definition.js.map +1 -1
- package/dist/esm/components/popover/popover.js +82 -122
- package/dist/esm/components/popover/popover.js.map +1 -1
- package/dist/esm/components/popover/popover.options.js +2 -2
- package/dist/esm/components/popover/popover.options.js.map +1 -1
- package/dist/esm/components/popover/popover.positioning.js +314 -0
- package/dist/esm/components/popover/popover.positioning.js.map +1 -0
- package/dist/esm/components/popover/popover.styles.js +14 -18
- package/dist/esm/components/popover/popover.styles.js.map +1 -1
- package/dist/esm/components/search-box/search-box.js +1 -1
- package/dist/esm/components/search-box/search-box.js.map +1 -1
- package/dist/esm/components/search-box/search-box.options.js +1 -1
- package/dist/esm/components/search-box/search-box.options.js.map +1 -1
- package/dist/esm/components/simple-table/simple-table.styles.js +2 -1
- package/dist/esm/components/table/table.js +1 -1
- package/dist/esm/components/table/table.js.map +1 -1
- package/dist/esm/components/table/table.styles.js +1 -1
- package/dist/esm/components/table-cell/table-cell.styles.js +1 -1
- package/dist/esm/components/tag/tag.styles.js +1 -1
- package/dist/esm/components/teaching-bubble/teaching-bubble.styles.js +1 -1
- package/dist/esm/components/text-input/text-input.base.js +3 -3
- package/dist/esm/components/text-input/text-input.base.js.map +1 -1
- package/dist/esm/components/text-input/text-input.js +1 -0
- package/dist/esm/components/text-input/text-input.js.map +1 -1
- package/dist/esm/components/text-input/text-input.styles.js +1 -1
- package/dist/esm/components/tooltip/tooltip.js +23 -0
- package/dist/esm/components/tooltip/tooltip.js.map +1 -1
- package/dist/esm/components/tooltip/tooltip.template.js +16 -0
- package/dist/esm/components/tooltip/tooltip.template.js.map +1 -0
- package/dist/esm/components/tree/tree.js +38 -1
- package/dist/esm/components/tree/tree.js.map +1 -1
- package/dist/esm/components/tree-item/index.js +2 -1
- package/dist/esm/components/tree-item/index.js.map +1 -1
- package/dist/esm/components/tree-item/tree-item.definition.js +4 -3
- package/dist/esm/components/tree-item/tree-item.definition.js.map +1 -1
- package/dist/esm/components/tree-item/tree-item.styles.js +9 -0
- package/dist/esm/components/tree-item/tree-item.styles.js.map +1 -0
- package/dist/esm/components/tree-item/tree-item.template.js +6 -0
- package/dist/esm/components/tree-item/tree-item.template.js.map +1 -0
- package/dist/esm/components/wizard/wizard.js +3 -3
- package/dist/esm/components/wizard/wizard.js.map +1 -1
- package/dist/esm/components/wizard/wizard.styles.js +1 -1
- package/dist/esm/components/wizard-panel/wizard-panel.styles.js +1 -1
- package/dist/esm/components/wizard-step/wizard-step.js +1 -1
- package/dist/esm/components/wizard-step/wizard-step.js.map +1 -1
- package/dist/esm/components/wizard-step/wizard-step.styles.js +1 -1
- package/dist/esm/index.js +17 -7
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/util/accessibility-utilities.js +40 -0
- package/dist/esm/util/accessibility-utilities.js.map +1 -0
- package/dist/esm/util/attribute-utilities.js +12 -0
- package/dist/esm/util/attribute-utilities.js.map +1 -0
- package/dist/esm/util/debounce.js.map +1 -0
- package/dist/esm/util/debug.js +74 -0
- package/dist/esm/util/debug.js.map +1 -0
- package/dist/esm/util/direction.js +240 -8
- package/dist/esm/util/direction.js.map +1 -1
- package/dist/esm/util/dom.js +3 -0
- package/dist/esm/util/dom.js.map +1 -0
- package/dist/esm/util/element-internal-mocks.js +114 -0
- package/dist/esm/util/element-internal-mocks.js.map +1 -0
- package/dist/esm/util/focus-management.js +247 -0
- package/dist/esm/util/focus-management.js.map +1 -0
- package/dist/esm/util/hash-utilities.js +12 -0
- package/dist/esm/util/hash-utilities.js.map +1 -0
- package/dist/esm/util/index.js +13 -6
- package/dist/esm/util/index.js.map +1 -1
- package/dist/esm/util/positioning/flexible-position-strategy.js +232 -0
- package/dist/esm/util/positioning/flexible-position-strategy.js.map +1 -0
- package/dist/esm/util/positioning/index.js +10 -0
- package/dist/esm/util/positioning/index.js.map +1 -0
- package/dist/esm/util/positioning/position-calculator.js +196 -0
- package/dist/esm/util/positioning/position-calculator.js.map +1 -0
- package/dist/esm/util/positioning/types.js +30 -0
- package/dist/esm/util/positioning/types.js.map +1 -0
- package/dist/index.d.ts +697 -223
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2365 -1215
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +109 -110
- package/dist/index.min.js.map +1 -1
- package/package.json +6 -8
- package/dist/component-utilities.js +0 -43
- package/dist/dts/components/popover/positioning.d.ts +0 -51
- package/dist/dts/components/popover/positioning.d.ts.map +0 -1
- package/dist/dts/util/positioning.d.ts +0 -129
- package/dist/dts/util/positioning.d.ts.map +0 -1
- package/dist/dts/utils/debounce.d.ts.map +0 -1
- package/dist/esm/component-utilities.js +0 -13
- package/dist/esm/components/popover/positioning.js +0 -189
- package/dist/esm/components/popover/positioning.js.map +0 -1
- package/dist/esm/util/positioning.js +0 -130
- package/dist/esm/util/positioning.js.map +0 -1
- package/dist/esm/utils/debounce.js.map +0 -1
- /package/dist/dts/{utils → util}/debounce.d.ts +0 -0
- /package/dist/esm/{utils → util}/debounce.js +0 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
//-----------------------------------------------------------------------
|
|
2
|
+
// <copyright company="Microsoft Corporation">
|
|
3
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
// </copyright>
|
|
5
|
+
//-----------------------------------------------------------------------
|
|
6
|
+
/**
|
|
7
|
+
* Holds a collection of debug-related functions. When the instance is not in debug mode, most/all of
|
|
8
|
+
* the side-effects will be disabled.
|
|
9
|
+
*/
|
|
10
|
+
class debug {
|
|
11
|
+
static setAssertFailFunction(f) {
|
|
12
|
+
debug.assertFailFunction = f;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Asserts that the condition is true, fails otherwise.
|
|
16
|
+
*/
|
|
17
|
+
static assert(conditionFunc, message) {
|
|
18
|
+
if (!this.enabled) return;
|
|
19
|
+
const condition = conditionFunc();
|
|
20
|
+
message = message !== null && message !== void 0 ? message : "condition: " + condition;
|
|
21
|
+
if (condition !== true) {
|
|
22
|
+
debug.assertFail(message);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Asserts that the value is neither null nor undefined, fails otherwise.
|
|
27
|
+
*/
|
|
28
|
+
static assertDefined(value, message) {
|
|
29
|
+
if (!this.enabled) return;
|
|
30
|
+
debug.assert(() => value !== null && value !== undefined, message);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Asserts that the value is neither null nor undefined, and has a length property that returns greater than zero, fails otherwise.
|
|
34
|
+
*/
|
|
35
|
+
static assertNonEmpty(value, message) {
|
|
36
|
+
if (!this.enabled) return;
|
|
37
|
+
debug.assert(() => value != null && value.length > 0, message);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Asserts that this function is never called. This is to be used
|
|
41
|
+
*/
|
|
42
|
+
static assertNever(neverValue) {
|
|
43
|
+
if (!this.enabled) return;
|
|
44
|
+
debug.assertFail("Expected to never have value " + neverValue);
|
|
45
|
+
}
|
|
46
|
+
static assertFail(message) {
|
|
47
|
+
if (!this.enabled) return;
|
|
48
|
+
(debug.assertFailFunction || alert)(`Debug Assert failed: ${message}`);
|
|
49
|
+
}
|
|
50
|
+
static log(message, ...optionalParams) {
|
|
51
|
+
if (!this.enabled) return;
|
|
52
|
+
console.log(message, ...(optionalParams || []));
|
|
53
|
+
}
|
|
54
|
+
static logDebug(message, ...optionalParams) {
|
|
55
|
+
if (!this.enabled) return;
|
|
56
|
+
console.debug(message, ...(optionalParams || []));
|
|
57
|
+
}
|
|
58
|
+
static warn(message, ...optionalParams) {
|
|
59
|
+
if (!this.enabled) return;
|
|
60
|
+
if (console && console.warn) {
|
|
61
|
+
console.warn(message, ...(optionalParams || []));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
static execute(action) {
|
|
65
|
+
if (!this.enabled) return;
|
|
66
|
+
action();
|
|
67
|
+
}
|
|
68
|
+
static enable() {
|
|
69
|
+
this.enabled = true;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
debug.enabled = false;
|
|
73
|
+
|
|
74
|
+
export { deb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|
|
2
|
-
|
|
1
|
+
import { Direction } from '@microsoft/fast-web-utilities';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This module provides a composable system for detecting and monitoring text direction
|
|
5
|
+
* (LTR/RTL) changes in web applications. It follows a strategy/observer pattern to allow
|
|
6
|
+
* flexibility for the many ways that direction can be controlled in the document.
|
|
7
|
+
*
|
|
8
|
+
* ## Architecture
|
|
9
|
+
*
|
|
10
|
+
* The system uses two complementary interfaces:
|
|
11
|
+
*
|
|
12
|
+
* - **DirectionStrategy**: Detection - reads direction from a source (CSS, attributes, etc.)
|
|
13
|
+
* - **DirectionObserver**: Change monitoring - watches for direction changes and notifies
|
|
14
|
+
*
|
|
15
|
+
* The `DirectionDetector` class combines the detection and observer strategies to provide
|
|
16
|
+
* robust direction detection with automatic change notifications.
|
|
17
|
+
*
|
|
18
|
+
* ## Built-in Strategies
|
|
19
|
+
*
|
|
20
|
+
* - `DirAttributeStrategy`: Reads the `dir` attribute from elements
|
|
21
|
+
* - `ElementCssStrategy`: Reads computed CSS `direction` property
|
|
22
|
+
*
|
|
23
|
+
* ## Built-in Observers
|
|
24
|
+
*
|
|
25
|
+
* - `DirAttributeObserver`: Watches for `dir` attribute mutations via MutationObserver
|
|
26
|
+
*
|
|
27
|
+
* ## Global DirectionDetector
|
|
28
|
+
*
|
|
29
|
+
* A singleton detector is available via `globalDirectionDetector()`. By default, it
|
|
30
|
+
* monitors the `dir` attribute on the `<html>` element. This is the detector used by the
|
|
31
|
+
* components in this package to correctly adjust layout, keyboard navigation, etc.
|
|
32
|
+
*
|
|
33
|
+
* To customize the global detector, call `setGlobalDirectionDetector()`:
|
|
34
|
+
*
|
|
35
|
+
* ```typescript
|
|
36
|
+
* import {
|
|
37
|
+
* setGlobalDirectionDetector,
|
|
38
|
+
* DirectionDetector,
|
|
39
|
+
* DirAttributeStrategy,
|
|
40
|
+
* DirAttributeObserver
|
|
41
|
+
* } from "@fabric-msft/fabric-web";
|
|
42
|
+
*
|
|
43
|
+
* setGlobalDirectionDetector(
|
|
44
|
+
* new DirectionDetector({
|
|
45
|
+
* strategies: [new DirAttributeStrategy([document.documentElement])],
|
|
46
|
+
* observers: [new DirAttributeObserver("html")],
|
|
47
|
+
* onChange: (dir) => console.log("Global direction:", dir)
|
|
48
|
+
* })
|
|
49
|
+
* );
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* ## Defaults
|
|
53
|
+
*
|
|
54
|
+
* The default global DirectionDetector will monitor the `dir` attribute on the
|
|
55
|
+
* `html` element. You do not need to set anything if this is the strategy that your app
|
|
56
|
+
* uses to control document direction.
|
|
57
|
+
*
|
|
58
|
+
* ```html
|
|
59
|
+
* <html dir="rtl">
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* ## Custom DirectionDetector
|
|
63
|
+
*
|
|
64
|
+
* ```typescript
|
|
65
|
+
* import {
|
|
66
|
+
* DirectionDetector,
|
|
67
|
+
* DirAttributeStrategy,
|
|
68
|
+
* DirAttributeObserver
|
|
69
|
+
* } from "@fabric-msft/fabric-web";
|
|
70
|
+
*
|
|
71
|
+
* const detector = new DirectionDetector({
|
|
72
|
+
* strategies: [new DirAttributeStrategy([document.documentElement])],
|
|
73
|
+
* observers: [new DirAttributeObserver("html")],
|
|
74
|
+
* onChange: (dir, { previous }) => {
|
|
75
|
+
* console.log(`Direction changed: ${previous} → ${dir}`);
|
|
76
|
+
* }
|
|
77
|
+
* });
|
|
78
|
+
*
|
|
79
|
+
* // Access current direction
|
|
80
|
+
* console.log(detector.value); // 'ltr' or 'rtl'
|
|
81
|
+
*
|
|
82
|
+
* // Clean up when done
|
|
83
|
+
* detector.stop();
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
3
86
|
/**
|
|
4
87
|
* Determines the current localization direction of an element.
|
|
5
88
|
*
|
|
@@ -8,10 +91,159 @@ import { Direction } from "@microsoft/fast-web-utilities";
|
|
|
8
91
|
*
|
|
9
92
|
* @public
|
|
10
93
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
? Direction.rtl
|
|
15
|
-
: Direction.ltr;
|
|
94
|
+
const getDirection = rootNode => {
|
|
95
|
+
var _a;
|
|
96
|
+
return ((_a = rootNode.closest("[dir]")) === null || _a === void 0 ? void 0 : _a.dir) === "rtl" ? Direction.rtl : Direction.ltr;
|
|
16
97
|
};
|
|
17
|
-
|
|
98
|
+
function isRtl() {
|
|
99
|
+
return globalDirectionDetector().value === Direction.rtl;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Strategy that reads direction from the dir attribute.
|
|
103
|
+
* Takes a list of elements and checks each element until it finds one with a "dir" attribute specified.
|
|
104
|
+
* @public
|
|
105
|
+
*/
|
|
106
|
+
class DirAttributeStrategy {
|
|
107
|
+
constructor(elements) {
|
|
108
|
+
this.elements = elements;
|
|
109
|
+
}
|
|
110
|
+
getDirection() {
|
|
111
|
+
var _a;
|
|
112
|
+
for (const el of this.elements) {
|
|
113
|
+
const raw = ((_a = el.getAttribute("dir")) !== null && _a !== void 0 ? _a : "").trim().toLowerCase();
|
|
114
|
+
if (raw === Direction.rtl || raw === Direction.ltr) return raw;
|
|
115
|
+
if (raw === "auto") return null;
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Observer that watches for dir attribute changes using MutationObserver.
|
|
122
|
+
* @public
|
|
123
|
+
*/
|
|
124
|
+
class DirAttributeObserver {
|
|
125
|
+
constructor(target = "html", doc = document) {
|
|
126
|
+
this.mo = null;
|
|
127
|
+
this.target = target;
|
|
128
|
+
this.doc = doc;
|
|
129
|
+
}
|
|
130
|
+
start(notify) {
|
|
131
|
+
var _a;
|
|
132
|
+
if (this.mo) return;
|
|
133
|
+
const observeEl = typeof this.target === "string" ? (_a = this.doc.querySelector(this.target)) !== null && _a !== void 0 ? _a : this.doc.documentElement : this.target;
|
|
134
|
+
if (!observeEl) return;
|
|
135
|
+
this.mo = new MutationObserver(() => notify());
|
|
136
|
+
this.mo.observe(observeEl, {
|
|
137
|
+
attributes: true,
|
|
138
|
+
attributeFilter: ["dir"]
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
stop() {
|
|
142
|
+
var _a;
|
|
143
|
+
(_a = this.mo) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
144
|
+
this.mo = null;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Detects and (optionally) observes direction using a chain of strategies.
|
|
149
|
+
* The first strategy to return a non-null direction wins.
|
|
150
|
+
* @public
|
|
151
|
+
*/
|
|
152
|
+
class DirectionDetector {
|
|
153
|
+
constructor(options) {
|
|
154
|
+
var _a;
|
|
155
|
+
this.rafId = null;
|
|
156
|
+
this._value = null;
|
|
157
|
+
this.observing = false;
|
|
158
|
+
this.strategies = options.strategies;
|
|
159
|
+
this.observers = (_a = options.observers) !== null && _a !== void 0 ? _a : [];
|
|
160
|
+
this.onChange = options.onChange;
|
|
161
|
+
this._value = this.computeDirection();
|
|
162
|
+
if (this.observers.length > 0) this.start();
|
|
163
|
+
}
|
|
164
|
+
get value() {
|
|
165
|
+
var _a;
|
|
166
|
+
return (_a = this._value) !== null && _a !== void 0 ? _a : Direction.ltr;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Start all observers.
|
|
170
|
+
*/
|
|
171
|
+
start() {
|
|
172
|
+
if (this.observing) return;
|
|
173
|
+
this.observing = true;
|
|
174
|
+
const scheduleRefresh = () => {
|
|
175
|
+
if (this.rafId != null) return;
|
|
176
|
+
if (typeof requestAnimationFrame === "undefined") {
|
|
177
|
+
this.refresh();
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
this.rafId = requestAnimationFrame(() => {
|
|
181
|
+
this.rafId = null;
|
|
182
|
+
this.refresh();
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
for (const observer of this.observers) {
|
|
186
|
+
observer.start(scheduleRefresh);
|
|
187
|
+
}
|
|
188
|
+
// Initial refresh after starting observation
|
|
189
|
+
this.refresh();
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Stop observing and cancel any scheduled refresh.
|
|
193
|
+
*/
|
|
194
|
+
stop() {
|
|
195
|
+
if (this.rafId != null && typeof cancelAnimationFrame !== "undefined") {
|
|
196
|
+
cancelAnimationFrame(this.rafId);
|
|
197
|
+
}
|
|
198
|
+
this.rafId = null;
|
|
199
|
+
for (const observer of this.observers) {
|
|
200
|
+
observer.stop();
|
|
201
|
+
}
|
|
202
|
+
this.observing = false;
|
|
203
|
+
}
|
|
204
|
+
stable() {
|
|
205
|
+
return this.rafId == null;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Force recomputation; invokes onChange only if the resolved direction changed.
|
|
209
|
+
*/
|
|
210
|
+
refresh() {
|
|
211
|
+
var _a;
|
|
212
|
+
const previous = this._value;
|
|
213
|
+
const next = this.computeDirection();
|
|
214
|
+
if (next !== previous) {
|
|
215
|
+
this._value = next;
|
|
216
|
+
try {
|
|
217
|
+
(_a = this.onChange) === null || _a === void 0 ? void 0 : _a.call(this, next, {
|
|
218
|
+
previous
|
|
219
|
+
});
|
|
220
|
+
} catch {
|
|
221
|
+
// ignore callback errors
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return this._value;
|
|
225
|
+
}
|
|
226
|
+
computeDirection() {
|
|
227
|
+
for (const strategy of this.strategies) {
|
|
228
|
+
const dir = strategy.getDirection();
|
|
229
|
+
if (dir) return dir;
|
|
230
|
+
}
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
let _globalDetector = null;
|
|
235
|
+
function setGlobalDirectionDetector(detector) {
|
|
236
|
+
_globalDetector = detector;
|
|
237
|
+
}
|
|
238
|
+
function globalDirectionDetector() {
|
|
239
|
+
if (!_globalDetector) {
|
|
240
|
+
// Default to a strategy that expects dir to be on the root html element.
|
|
241
|
+
_globalDetector = new DirectionDetector({
|
|
242
|
+
strategies: [new DirAttributeStrategy([document.documentElement])],
|
|
243
|
+
observers: [new DirAttributeObserver("html")]
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
return _globalDetector;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export { DirAttributeObserver, DirAttributeStrategy, DirectionDetector, getDirection, globalDirectionDetector, isRtl, setGlobalDirectionDetector };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"direction.js","sourceRoot":"","sources":["../../../../../../src/util/direction.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"direction.js","sourceRoot":"","sources":["../../../../../../src/util/direction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkFG;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,QAAqB,EAAa,EAAE;;IAC/D,OAAO,CAAA,MAAA,QAAQ,CAAC,OAAO,CAAc,OAAO,CAAC,0CAAE,GAAG,MAAK,KAAK;QAC1D,CAAC,CAAC,SAAS,CAAC,GAAG;QACf,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC;AACpB,CAAC,CAAC;AAEF,MAAM,UAAU,0BAA0B,CAAC,OAAgB;;IACzD,MAAM,UAAU,GAAc,EAAE,CAAC;IAEjC,gDAAgD;IAChD,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5C,IAAI,UAAU;QAAE,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAE5C,+BAA+B;IAC/B,MAAM,IAAI,GAAG,CAAC,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,aAAa,mCAAI,QAAQ,CAAC,CAAC,eAAe,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,QAAQ,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,uBAAuB;IACrC,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,yEAAyE;QACzE,eAAe,GAAG,IAAI,iBAAiB,CAAC;YACtC,UAAU,EAAE,CAAC,IAAI,oBAAoB,CAAC,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC;YAClE,SAAS,EAAE,CAAC,IAAI,oBAAoB,CAAC,MAAM,CAAC,CAAC;SAC9C,CAAC,CAAC;IACL,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom.js","sourceRoot":"","sources":["../../../../../../src/util/dom.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,MAAM;IACN,OAAO;IACP,OAAO;IACP,QAAQ;IACR,mBAAmB;IACnB,cAAc;IACd,mBAAmB;IACnB,YAAY;IACZ,eAAe;IACf,gBAAgB;IAChB,QAAQ;IACR,UAAU;CACX,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
class MockElementInternals {
|
|
2
|
+
constructor(element) {
|
|
3
|
+
this.ariaDescription = null;
|
|
4
|
+
this.ariaBrailleLabel = null;
|
|
5
|
+
this.ariaBrailleRoleDescription = null;
|
|
6
|
+
this._form = null;
|
|
7
|
+
this._labels = document.createDocumentFragment().childNodes;
|
|
8
|
+
// ARIA properties
|
|
9
|
+
this.role = "";
|
|
10
|
+
this.ariaAtomic = "";
|
|
11
|
+
this.ariaAutoComplete = "";
|
|
12
|
+
this.ariaBusy = "";
|
|
13
|
+
this.ariaChecked = "";
|
|
14
|
+
this.ariaColCount = "";
|
|
15
|
+
this.ariaColIndex = "";
|
|
16
|
+
this.ariaColIndexText = "";
|
|
17
|
+
this.ariaColSpan = "";
|
|
18
|
+
this.ariaCurrent = "";
|
|
19
|
+
this.ariaDisabled = "";
|
|
20
|
+
this.ariaExpanded = "";
|
|
21
|
+
this.ariaHasPopup = "";
|
|
22
|
+
this.ariaHidden = "";
|
|
23
|
+
this.ariaInvalid = "";
|
|
24
|
+
this.ariaKeyShortcuts = "";
|
|
25
|
+
this.ariaLabel = "";
|
|
26
|
+
this.ariaLevel = "";
|
|
27
|
+
this.ariaLive = "";
|
|
28
|
+
this.ariaModal = "";
|
|
29
|
+
this.ariaMultiLine = "";
|
|
30
|
+
this.ariaMultiSelectable = "";
|
|
31
|
+
this.ariaOrientation = "";
|
|
32
|
+
this.ariaPlaceholder = "";
|
|
33
|
+
this.ariaPosInSet = "";
|
|
34
|
+
this.ariaPressed = "";
|
|
35
|
+
this.ariaReadOnly = "";
|
|
36
|
+
this.ariaRelevant = "";
|
|
37
|
+
this.ariaRequired = "";
|
|
38
|
+
this.ariaRoleDescription = "";
|
|
39
|
+
this.ariaRowCount = "";
|
|
40
|
+
this.ariaRowIndex = "";
|
|
41
|
+
this.ariaRowIndexText = "";
|
|
42
|
+
this.ariaRowSpan = "";
|
|
43
|
+
this.ariaSelected = "";
|
|
44
|
+
this.ariaSetSize = "";
|
|
45
|
+
this.ariaSort = "";
|
|
46
|
+
this.ariaValueMax = "";
|
|
47
|
+
this.ariaValueMin = "";
|
|
48
|
+
this.ariaValueNow = "";
|
|
49
|
+
this.ariaValueText = "";
|
|
50
|
+
// add the element to the MockElementInternals class
|
|
51
|
+
// the constructor is called when attachInternals is called on the element using ElementInternals.
|
|
52
|
+
this._element = element;
|
|
53
|
+
}
|
|
54
|
+
get form() {
|
|
55
|
+
if (!this._form) {
|
|
56
|
+
// get the closest form element from the element
|
|
57
|
+
this._form = this._element.closest("form");
|
|
58
|
+
}
|
|
59
|
+
return this._form;
|
|
60
|
+
}
|
|
61
|
+
get labels() {
|
|
62
|
+
return this._labels;
|
|
63
|
+
}
|
|
64
|
+
get shadowRoot() {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
get states() {
|
|
68
|
+
return new Set();
|
|
69
|
+
}
|
|
70
|
+
// Validation properties
|
|
71
|
+
get validationMessage() {
|
|
72
|
+
return "";
|
|
73
|
+
}
|
|
74
|
+
get validity() {
|
|
75
|
+
return {
|
|
76
|
+
badInput: false,
|
|
77
|
+
customError: false,
|
|
78
|
+
patternMismatch: false,
|
|
79
|
+
rangeOverflow: false,
|
|
80
|
+
rangeUnderflow: false,
|
|
81
|
+
stepMismatch: false,
|
|
82
|
+
tooLong: false,
|
|
83
|
+
tooShort: false,
|
|
84
|
+
typeMismatch: false,
|
|
85
|
+
valid: true,
|
|
86
|
+
valueMissing: false
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
get willValidate() {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
// Methods
|
|
93
|
+
checkValidity() {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
reportValidity() {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
setFormValue(_value, _state) {}
|
|
100
|
+
setValidity(_flags, _message, _anchor) {}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* If the HTMLElement prototype does not have the attachInternals method, add it.
|
|
104
|
+
* This is used to create a new MockElementInternals instance when the element is attached to the DOM.
|
|
105
|
+
*/
|
|
106
|
+
function attachMockElementInternals() {
|
|
107
|
+
if (!HTMLElement.prototype.attachInternals) {
|
|
108
|
+
HTMLElement.prototype.attachInternals = function () {
|
|
109
|
+
return new MockElementInternals(this);
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { MockElementInternals, attachMockElementInternals };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element-internal-mocks.js","sourceRoot":"","sources":["../../../../../../src/util/element-internal-mocks.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,oBAAoB;IAQ/B,YAAY,OAAoB;QAPhC,oBAAe,GAAkB,IAAI,CAAC;QACtC,qBAAgB,GAAkB,IAAI,CAAC;QACvC,+BAA0B,GA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