mtrl 0.3.1 → 0.3.3
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/.env +15 -0
- package/CONTRIBUTING.md +62 -23
- package/DOCS.md +3 -3
- package/README.md +43 -20
- package/TESTING.md +128 -18
- package/dist/index.js +14865 -0
- package/git-user-stats.js +545 -0
- package/index.ts +9 -67
- package/package.json +8 -3
- package/src/components/badge/api.ts +15 -1
- package/src/components/badge/badge.ts +43 -4
- package/src/components/badge/config.ts +40 -8
- package/src/components/badge/index.ts +64 -3
- package/src/components/badge/types.ts +175 -33
- package/src/components/button/api.ts +63 -1
- package/src/components/button/button.ts +39 -3
- package/src/components/button/config.ts +21 -4
- package/src/components/button/index.ts +26 -1
- package/src/components/button/types.ts +7 -1
- package/src/components/card/api.ts +78 -9
- package/src/components/card/card.ts +58 -3
- package/src/components/card/config.ts +41 -11
- package/src/components/card/features.ts +39 -12
- package/src/components/card/index.ts +84 -19
- package/src/components/card/types.ts +218 -29
- package/src/components/carousel/carousel.ts +92 -28
- package/src/components/carousel/constants.ts +107 -21
- package/src/components/carousel/index.ts +31 -13
- package/src/components/checkbox/checkbox.ts +83 -16
- package/src/components/checkbox/index.ts +43 -1
- package/src/components/checkbox/types.ts +219 -32
- package/src/components/chips/api.ts +194 -0
- package/src/components/{chip → chips/chip}/api.ts +42 -2
- package/src/components/chips/chip/chip.ts +131 -0
- package/src/components/{chip → chips/chip}/config.ts +3 -3
- package/src/components/chips/chip/index.ts +3 -0
- package/src/components/chips/chips.md +481 -0
- package/src/components/chips/chips.ts +75 -0
- package/src/components/chips/config.ts +109 -0
- package/src/components/chips/constants.ts +61 -0
- package/src/components/chips/features/chip-items.ts +33 -0
- package/src/components/chips/features/container.ts +77 -0
- package/src/components/chips/features/controller.ts +448 -0
- package/src/components/chips/features/index.ts +5 -0
- package/src/components/chips/features/label.ts +108 -0
- package/src/components/chips/index.ts +11 -0
- package/src/components/chips/schema.ts +61 -0
- package/src/components/{chip → chips}/types.ts +203 -92
- package/src/components/dialog/dialog.ts +99 -16
- package/src/components/dialog/index.ts +97 -1
- package/src/components/dialog/types.ts +375 -69
- package/src/components/divider/config.ts +90 -6
- package/src/components/divider/divider.ts +32 -2
- package/src/components/divider/features.ts +26 -0
- package/src/components/divider/index.ts +30 -0
- package/src/components/divider/types.ts +86 -9
- package/src/components/extended-fab/api.ts +53 -1
- package/src/components/extended-fab/config.ts +29 -1
- package/src/components/extended-fab/extended-fab.ts +28 -0
- package/src/components/extended-fab/index.ts +36 -0
- package/src/components/extended-fab/types.ts +458 -13
- package/src/components/fab/api.ts +42 -2
- package/src/components/fab/config.ts +29 -1
- package/src/components/fab/fab.ts +16 -2
- package/src/components/fab/index.ts +35 -0
- package/src/components/fab/types.ts +374 -10
- package/src/components/list/api.ts +12 -2
- package/src/components/list/config.ts +21 -0
- package/src/components/list/features.ts +6 -0
- package/src/components/list/index.ts +56 -1
- package/src/components/list/list-item.ts +46 -2
- package/src/components/list/list.ts +73 -2
- package/src/components/list/types.ts +172 -0
- package/src/components/list/utils.ts +26 -2
- package/src/components/menu/api.ts +217 -20
- package/src/components/menu/config.ts +27 -0
- package/src/components/menu/features/visibility.ts +55 -6
- package/src/components/menu/index.ts +64 -0
- package/src/components/menu/menu-item.ts +46 -3
- package/src/components/menu/menu.ts +77 -1
- package/src/components/menu/types.ts +404 -39
- package/src/components/navigation/nav-item.ts +13 -2
- package/src/components/sheet/config.ts +1 -2
- package/src/components/sheet/features/gestures.ts +1 -1
- package/src/components/sheet/features/position.ts +1 -2
- package/src/components/sheet/features/state.ts +1 -1
- package/src/components/sheet/index.ts +10 -2
- package/src/components/sheet/sheet.ts +1 -2
- package/src/components/sheet/types.ts +29 -1
- package/src/components/slider/api.ts +1 -1
- package/src/components/slider/config.ts +1 -1
- package/src/components/slider/features/controller.ts +1 -1
- package/src/components/slider/features/handlers.ts +1 -1
- package/src/components/slider/features/states.ts +1 -1
- package/src/components/slider/index.ts +12 -5
- package/src/components/slider/schema.ts +1 -1
- package/src/components/slider/types.ts +31 -0
- package/src/components/tabs/tab-api.ts +1 -1
- package/src/components/tabs/types.ts +1 -1
- package/src/components/tooltip/api.ts +6 -2
- package/src/components/tooltip/config.ts +9 -28
- package/src/components/tooltip/index.ts +10 -1
- package/src/components/tooltip/types.ts +38 -3
- package/src/core/dom/create.ts +57 -51
- package/src/index.ts +129 -31
- package/src/styles/abstract/_mixins.scss +23 -9
- package/src/styles/abstract/_variables.scss +14 -4
- package/src/styles/components/_card.scss +1 -1
- package/src/styles/components/_chip.scss +323 -113
- package/src/styles/components/_tabs.scss +1 -1
- package/src/styles/themes/_autumn.scss +3 -0
- package/CLAUDE.md +0 -33
- package/src/components/checkbox/constants.ts +0 -37
- package/src/components/chip/chip-set.ts +0 -225
- package/src/components/chip/chip.ts +0 -118
- package/src/components/chip/constants.ts +0 -28
- package/src/components/chip/index.ts +0 -12
- package/src/components/list/constants.ts +0 -116
- package/src/components/sheet/constants.ts +0 -20
- package/src/components/slider/constants.ts +0 -32
- package/src/components/tooltip/constants.ts +0 -27
- package/test/components/badge.test.ts +0 -545
- package/test/components/bottom-app-bar.test.ts +0 -303
- package/test/components/button.test.ts +0 -233
- package/test/components/card.test.ts +0 -560
- package/test/components/carousel.test.ts +0 -951
- package/test/components/checkbox.test.ts +0 -462
- package/test/components/chip.test.ts +0 -692
- package/test/components/datepicker.test.ts +0 -1124
- package/test/components/dialog.test.ts +0 -990
- package/test/components/divider.test.ts +0 -412
- package/test/components/extended-fab.test.ts +0 -672
- package/test/components/fab.test.ts +0 -561
- package/test/components/list.test.ts +0 -365
- package/test/components/menu.test.ts +0 -718
- package/test/components/navigation.test.ts +0 -186
- package/test/components/progress.test.ts +0 -567
- package/test/components/radios.test.ts +0 -699
- package/test/components/search.test.ts +0 -1135
- package/test/components/segmented-button.test.ts +0 -732
- package/test/components/sheet.test.ts +0 -641
- package/test/components/slider.test.ts +0 -1220
- package/test/components/snackbar.test.ts +0 -461
- package/test/components/switch.test.ts +0 -452
- package/test/components/tabs.test.ts +0 -1369
- package/test/components/textfield.test.ts +0 -400
- package/test/components/timepicker.test.ts +0 -592
- package/test/components/tooltip.test.ts +0 -630
- package/test/components/top-app-bar.test.ts +0 -566
- package/test/core/dom.attributes.test.ts +0 -148
- package/test/core/dom.classes.test.ts +0 -152
- package/test/core/dom.events.test.ts +0 -243
- package/test/core/emitter.test.ts +0 -141
- package/test/core/ripple.test.ts +0 -99
- package/test/core/state.store.test.ts +0 -189
- package/test/core/utils.normalize.test.ts +0 -61
- package/test/core/utils.object.test.ts +0 -120
- package/test/setup.js +0 -371
- package/test/setup.ts +0 -451
- package/tsconfig.json +0 -22
- package/typedoc.json +0 -28
- package/typedoc.simple.json +0 -14
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
// src/components/sheet/types.ts
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sheet variants
|
|
5
|
+
*/
|
|
6
|
+
export const SHEET_VARIANTS = {
|
|
7
|
+
STANDARD: 'standard',
|
|
8
|
+
MODAL: 'modal',
|
|
9
|
+
EXPANDED: 'expanded'
|
|
10
|
+
} as const;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Sheet positions
|
|
14
|
+
*/
|
|
15
|
+
export const SHEET_POSITIONS = {
|
|
16
|
+
BOTTOM: 'bottom',
|
|
17
|
+
TOP: 'top',
|
|
18
|
+
LEFT: 'left',
|
|
19
|
+
RIGHT: 'right'
|
|
20
|
+
} as const;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Sheet events
|
|
24
|
+
*/
|
|
25
|
+
export const SHEET_EVENTS = {
|
|
26
|
+
OPEN: 'open',
|
|
27
|
+
CLOSE: 'close',
|
|
28
|
+
DRAG_START: 'dragstart',
|
|
29
|
+
DRAG_END: 'dragend'
|
|
30
|
+
} as const;
|
|
3
31
|
|
|
4
32
|
/**
|
|
5
33
|
* Configuration interface for the Sheet component
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/components/slider/api.ts
|
|
2
2
|
import { SliderComponent, SliderEvent } from './types';
|
|
3
|
-
import { SLIDER_COLORS, SLIDER_SIZES, SLIDER_EVENTS } from './
|
|
3
|
+
import { SLIDER_COLORS, SLIDER_SIZES, SLIDER_EVENTS } from './types';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* API options interface - structured by feature area
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
createElementConfig
|
|
5
5
|
} from '../../core/config/component-config';
|
|
6
6
|
import { SliderConfig } from './types';
|
|
7
|
-
import { SLIDER_COLORS, SLIDER_SIZES } from './
|
|
7
|
+
import { SLIDER_COLORS, SLIDER_SIZES } from './types';
|
|
8
8
|
import { createSliderSchema } from './schema';
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -3,8 +3,15 @@
|
|
|
3
3
|
// Export main component creator
|
|
4
4
|
export { default } from './slider';
|
|
5
5
|
|
|
6
|
-
// Export constants
|
|
7
|
-
export {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
// Export constants and types
|
|
7
|
+
export {
|
|
8
|
+
// Constants
|
|
9
|
+
SLIDER_COLORS,
|
|
10
|
+
SLIDER_SIZES,
|
|
11
|
+
SLIDER_EVENTS,
|
|
12
|
+
|
|
13
|
+
// Types
|
|
14
|
+
type SliderConfig,
|
|
15
|
+
type SliderComponent,
|
|
16
|
+
type SliderEvent
|
|
17
|
+
} from './types';
|
|
@@ -22,7 +22,7 @@ export function createSliderSchema(component, config: SliderConfig) {
|
|
|
22
22
|
// Calculate initial position
|
|
23
23
|
const valuePercent = ((value - min) / (max - min)) * 100;
|
|
24
24
|
|
|
25
|
-
// Return base structure definition formatted for
|
|
25
|
+
// Return base structure definition formatted for createLayout
|
|
26
26
|
return {
|
|
27
27
|
element: {
|
|
28
28
|
options: {
|
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
// src/components/slider/types.ts
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Available slider color variants
|
|
5
|
+
*/
|
|
6
|
+
export const SLIDER_COLORS = {
|
|
7
|
+
PRIMARY: 'primary',
|
|
8
|
+
SECONDARY: 'secondary',
|
|
9
|
+
TERTIARY: 'tertiary',
|
|
10
|
+
ERROR: 'error'
|
|
11
|
+
} as const;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Available slider size variants
|
|
15
|
+
*/
|
|
16
|
+
export const SLIDER_SIZES = {
|
|
17
|
+
SMALL: 'small',
|
|
18
|
+
MEDIUM: 'medium',
|
|
19
|
+
LARGE: 'large'
|
|
20
|
+
} as const;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Available slider events
|
|
24
|
+
*/
|
|
25
|
+
export const SLIDER_EVENTS = {
|
|
26
|
+
CHANGE: 'change',
|
|
27
|
+
INPUT: 'input',
|
|
28
|
+
FOCUS: 'focus',
|
|
29
|
+
BLUR: 'blur',
|
|
30
|
+
START: 'start',
|
|
31
|
+
END: 'end'
|
|
32
|
+
} as const;
|
|
33
|
+
|
|
3
34
|
/**
|
|
4
35
|
* Available slider color variants
|
|
5
36
|
*/
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
// src/components/tooltip/api.ts
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
TooltipComponent,
|
|
4
|
+
TOOLTIP_POSITIONS,
|
|
5
|
+
DEFAULT_OFFSET,
|
|
6
|
+
DEFAULT_ARROW_SIZE
|
|
7
|
+
} from './types';
|
|
4
8
|
|
|
5
9
|
interface ApiOptions {
|
|
6
10
|
lifecycle: {
|
|
@@ -3,34 +3,15 @@ import {
|
|
|
3
3
|
createComponentConfig,
|
|
4
4
|
createElementConfig
|
|
5
5
|
} from '../../core/config/component-config';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
TOP_END: 'top-end',
|
|
16
|
-
RIGHT_START: 'right-start',
|
|
17
|
-
RIGHT_END: 'right-end',
|
|
18
|
-
BOTTOM_START: 'bottom-start',
|
|
19
|
-
BOTTOM_END: 'bottom-end',
|
|
20
|
-
LEFT_START: 'left-start',
|
|
21
|
-
LEFT_END: 'left-end'
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const TOOLTIP_VARIANTS = {
|
|
25
|
-
DEFAULT: 'default',
|
|
26
|
-
RICH: 'rich',
|
|
27
|
-
PLAIN: 'plain'
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export const DEFAULT_SHOW_DELAY = 300
|
|
31
|
-
export const DEFAULT_HIDE_DELAY = 100
|
|
32
|
-
export const DEFAULT_OFFSET = 8
|
|
33
|
-
export const DEFAULT_ARROW_SIZE = 8
|
|
6
|
+
import {
|
|
7
|
+
TooltipConfig,
|
|
8
|
+
TOOLTIP_POSITIONS,
|
|
9
|
+
TOOLTIP_VARIANTS,
|
|
10
|
+
DEFAULT_SHOW_DELAY,
|
|
11
|
+
DEFAULT_HIDE_DELAY,
|
|
12
|
+
DEFAULT_OFFSET,
|
|
13
|
+
DEFAULT_ARROW_SIZE
|
|
14
|
+
} from './types';
|
|
34
15
|
|
|
35
16
|
/**
|
|
36
17
|
* Default configuration for the Tooltip component
|
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
// src/components/tooltip/index.ts
|
|
2
2
|
export { default } from './tooltip';
|
|
3
|
-
export {
|
|
3
|
+
export {
|
|
4
|
+
TooltipConfig,
|
|
5
|
+
TooltipComponent,
|
|
6
|
+
TOOLTIP_POSITIONS,
|
|
7
|
+
TOOLTIP_VARIANTS,
|
|
8
|
+
DEFAULT_SHOW_DELAY,
|
|
9
|
+
DEFAULT_HIDE_DELAY,
|
|
10
|
+
DEFAULT_OFFSET,
|
|
11
|
+
DEFAULT_ARROW_SIZE
|
|
12
|
+
} from './types';
|
|
@@ -1,12 +1,47 @@
|
|
|
1
1
|
// src/components/tooltip/types.ts
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Tooltip positions
|
|
5
|
+
*/
|
|
6
|
+
export const TOOLTIP_POSITIONS = {
|
|
7
|
+
TOP: 'top',
|
|
8
|
+
RIGHT: 'right',
|
|
9
|
+
BOTTOM: 'bottom',
|
|
10
|
+
LEFT: 'left',
|
|
11
|
+
TOP_START: 'top-start',
|
|
12
|
+
TOP_END: 'top-end',
|
|
13
|
+
RIGHT_START: 'right-start',
|
|
14
|
+
RIGHT_END: 'right-end',
|
|
15
|
+
BOTTOM_START: 'bottom-start',
|
|
16
|
+
BOTTOM_END: 'bottom-end',
|
|
17
|
+
LEFT_START: 'left-start',
|
|
18
|
+
LEFT_END: 'left-end'
|
|
19
|
+
} as const;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Tooltip variants
|
|
23
|
+
*/
|
|
24
|
+
export const TOOLTIP_VARIANTS = {
|
|
25
|
+
DEFAULT: 'default',
|
|
26
|
+
RICH: 'rich',
|
|
27
|
+
PLAIN: 'plain'
|
|
28
|
+
} as const;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Default values
|
|
32
|
+
*/
|
|
33
|
+
export const DEFAULT_SHOW_DELAY = 300;
|
|
34
|
+
export const DEFAULT_HIDE_DELAY = 100;
|
|
35
|
+
export const DEFAULT_OFFSET = 8;
|
|
36
|
+
export const DEFAULT_ARROW_SIZE = 8;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Available Tooltip variants
|
|
5
40
|
*/
|
|
6
41
|
export type TooltipVariant = 'default' | 'rich' | 'plain';
|
|
7
42
|
|
|
8
43
|
/**
|
|
9
|
-
* Available
|
|
44
|
+
* Available Tooltip positions
|
|
10
45
|
*/
|
|
11
46
|
export type TooltipPosition = 'top' | 'right' | 'bottom' | 'left' | 'top-start' | 'top-end' | 'right-start' | 'right-end' | 'bottom-start' | 'bottom-end' | 'left-start' | 'left-end';
|
|
12
47
|
|
|
@@ -38,7 +73,7 @@ export interface TooltipConfig {
|
|
|
38
73
|
* Tooltip variant that determines visual styling
|
|
39
74
|
* @default 'default'
|
|
40
75
|
*/
|
|
41
|
-
variant?:
|
|
76
|
+
variant?: TooltipVariant | string;
|
|
42
77
|
|
|
43
78
|
/**
|
|
44
79
|
* Whether the tooltip is initially visible
|
package/src/core/dom/create.ts
CHANGED
|
@@ -6,6 +6,17 @@
|
|
|
6
6
|
|
|
7
7
|
import { setAttributes } from './attributes';
|
|
8
8
|
import { normalizeClasses } from '../utils';
|
|
9
|
+
import { PREFIX } from '../config';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Event handler function type
|
|
13
|
+
*/
|
|
14
|
+
export type EventHandler = (event: Event) => void;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Event condition type - either a boolean or a function that returns a boolean
|
|
18
|
+
*/
|
|
19
|
+
export type EventCondition = boolean | ((context: any, event: Event) => boolean);
|
|
9
20
|
|
|
10
21
|
/**
|
|
11
22
|
* Options for element creation
|
|
@@ -59,7 +70,7 @@ export interface CreateElementOptions {
|
|
|
59
70
|
/**
|
|
60
71
|
* Events to forward when component has emit method
|
|
61
72
|
*/
|
|
62
|
-
forwardEvents?: Record<string,
|
|
73
|
+
forwardEvents?: Record<string, EventCondition>;
|
|
63
74
|
|
|
64
75
|
/**
|
|
65
76
|
* Callback after element creation
|
|
@@ -81,9 +92,12 @@ export interface CreateElementOptions {
|
|
|
81
92
|
* Event handler storage to facilitate cleanup
|
|
82
93
|
*/
|
|
83
94
|
export interface EventHandlerStorage {
|
|
84
|
-
[eventName: string]:
|
|
95
|
+
[eventName: string]: EventHandler;
|
|
85
96
|
}
|
|
86
97
|
|
|
98
|
+
// Constant for prefix with dash
|
|
99
|
+
const PREFIX_WITH_DASH = `${PREFIX}-`;
|
|
100
|
+
|
|
87
101
|
/**
|
|
88
102
|
* Creates a DOM element with the specified options
|
|
89
103
|
*
|
|
@@ -108,89 +122,78 @@ export const createElement = (options: CreateElementOptions = {}): HTMLElement =
|
|
|
108
122
|
|
|
109
123
|
const element = document.createElement(tag);
|
|
110
124
|
|
|
111
|
-
//
|
|
125
|
+
// Apply basic properties
|
|
112
126
|
if (html) element.innerHTML = html;
|
|
113
127
|
if (text) element.textContent = text;
|
|
114
128
|
if (id) element.id = id;
|
|
115
129
|
|
|
116
130
|
// Handle classes
|
|
117
131
|
if (className) {
|
|
118
|
-
const
|
|
119
|
-
if (
|
|
120
|
-
|
|
132
|
+
const classes = normalizeClasses(className);
|
|
133
|
+
if (classes.length) {
|
|
134
|
+
// Apply prefix to classes in a single operation
|
|
135
|
+
element.classList.add(...classes.map(cls =>
|
|
136
|
+
cls && !cls.startsWith(PREFIX_WITH_DASH) ? PREFIX_WITH_DASH + cls : cls
|
|
137
|
+
).filter(Boolean));
|
|
121
138
|
}
|
|
122
139
|
}
|
|
123
140
|
|
|
124
|
-
// Handle data attributes
|
|
125
|
-
|
|
126
|
-
element.dataset[key] =
|
|
127
|
-
}
|
|
141
|
+
// Handle data attributes directly
|
|
142
|
+
for (const key in data) {
|
|
143
|
+
element.dataset[key] = data[key];
|
|
144
|
+
}
|
|
128
145
|
|
|
129
|
-
// Handle
|
|
146
|
+
// Handle regular attributes
|
|
130
147
|
const allAttrs = { ...attrs, ...rest };
|
|
131
|
-
|
|
148
|
+
for (const key in allAttrs) {
|
|
149
|
+
const value = allAttrs[key];
|
|
132
150
|
if (value != null) element.setAttribute(key, String(value));
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
// Initialize event handler storage if not present
|
|
136
|
-
if (!element.__eventHandlers) {
|
|
137
|
-
element.__eventHandlers = {};
|
|
138
151
|
}
|
|
139
152
|
|
|
140
|
-
// Handle event forwarding
|
|
153
|
+
// Handle event forwarding
|
|
141
154
|
if (forwardEvents && (context?.emit || context?.on)) {
|
|
142
|
-
|
|
143
|
-
|
|
155
|
+
element.__eventHandlers = {};
|
|
156
|
+
|
|
157
|
+
for (const nativeEvent in forwardEvents) {
|
|
158
|
+
const eventConfig = forwardEvents[nativeEvent];
|
|
159
|
+
|
|
144
160
|
const handler = (event: Event) => {
|
|
145
|
-
// Determine if the event should be forwarded
|
|
146
161
|
let shouldForward = true;
|
|
147
162
|
|
|
148
163
|
if (typeof eventConfig === 'function') {
|
|
149
164
|
try {
|
|
150
|
-
//
|
|
151
|
-
|
|
165
|
+
// Create a lightweight context clone
|
|
166
|
+
const ctxWithElement = { ...context, element };
|
|
167
|
+
shouldForward = eventConfig(ctxWithElement, event);
|
|
152
168
|
} catch (error) {
|
|
153
169
|
console.warn(`Error in event condition for ${nativeEvent}:`, error);
|
|
154
170
|
shouldForward = false;
|
|
155
171
|
}
|
|
156
172
|
} else {
|
|
157
|
-
// If it's a boolean, use directly
|
|
158
173
|
shouldForward = Boolean(eventConfig);
|
|
159
174
|
}
|
|
160
175
|
|
|
161
|
-
// Forward the event if condition passes
|
|
162
176
|
if (shouldForward) {
|
|
163
177
|
if (context.emit) {
|
|
164
178
|
context.emit(nativeEvent, { event, element, originalEvent: event });
|
|
165
179
|
} else if (context.on) {
|
|
166
|
-
|
|
167
|
-
// Dispatch a custom event that can be listened to
|
|
168
|
-
const customEvent = new CustomEvent(nativeEvent, {
|
|
180
|
+
element.dispatchEvent(new CustomEvent(nativeEvent, {
|
|
169
181
|
detail: { event, element, originalEvent: event },
|
|
170
182
|
bubbles: true,
|
|
171
183
|
cancelable: true
|
|
172
|
-
});
|
|
173
|
-
element.dispatchEvent(customEvent);
|
|
184
|
+
}));
|
|
174
185
|
}
|
|
175
186
|
}
|
|
176
187
|
};
|
|
177
188
|
|
|
178
|
-
// Store the handler for future removal
|
|
179
189
|
element.__eventHandlers[nativeEvent] = handler;
|
|
180
|
-
|
|
181
|
-
// Add the actual event listener
|
|
182
190
|
element.addEventListener(nativeEvent, handler);
|
|
183
|
-
}
|
|
191
|
+
}
|
|
184
192
|
}
|
|
185
193
|
|
|
186
194
|
// Append to container if provided
|
|
187
|
-
if (container)
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
if (typeof onCreate === 'function') {
|
|
192
|
-
onCreate(element, context);
|
|
193
|
-
}
|
|
195
|
+
if (container) container.appendChild(element);
|
|
196
|
+
if (onCreate) onCreate(element, context);
|
|
194
197
|
|
|
195
198
|
return element;
|
|
196
199
|
};
|
|
@@ -200,10 +203,11 @@ export const createElement = (options: CreateElementOptions = {}): HTMLElement =
|
|
|
200
203
|
* @param element - Element to cleanup
|
|
201
204
|
*/
|
|
202
205
|
export const removeEventHandlers = (element: HTMLElement): void => {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
206
|
+
const handlers = element.__eventHandlers;
|
|
207
|
+
if (handlers) {
|
|
208
|
+
for (const event in handlers) {
|
|
209
|
+
element.removeEventListener(event, handlers[event]);
|
|
210
|
+
}
|
|
207
211
|
delete element.__eventHandlers;
|
|
208
212
|
}
|
|
209
213
|
};
|
|
@@ -228,7 +232,9 @@ export const withClasses = (...classes: (string | string[])[]) =>
|
|
|
228
232
|
(element: HTMLElement): HTMLElement => {
|
|
229
233
|
const normalizedClasses = normalizeClasses(...classes);
|
|
230
234
|
if (normalizedClasses.length) {
|
|
231
|
-
element.classList.add(...normalizedClasses
|
|
235
|
+
element.classList.add(...normalizedClasses.map(cls =>
|
|
236
|
+
cls && !cls.startsWith(PREFIX_WITH_DASH) ? PREFIX_WITH_DASH + cls : cls
|
|
237
|
+
).filter(Boolean));
|
|
232
238
|
}
|
|
233
239
|
return element;
|
|
234
240
|
};
|
|
@@ -240,17 +246,17 @@ export const withClasses = (...classes: (string | string[])[]) =>
|
|
|
240
246
|
*/
|
|
241
247
|
export const withContent = (content: Node | string) =>
|
|
242
248
|
(element: HTMLElement): HTMLElement => {
|
|
243
|
-
if (content instanceof Node)
|
|
244
|
-
|
|
245
|
-
} else {
|
|
246
|
-
element.textContent = content;
|
|
247
|
-
}
|
|
249
|
+
if (content instanceof Node) element.appendChild(content);
|
|
250
|
+
else element.textContent = content;
|
|
248
251
|
return element;
|
|
249
252
|
};
|
|
250
253
|
|
|
251
254
|
// Extend HTMLElement interface to add eventHandlers property
|
|
252
255
|
declare global {
|
|
253
256
|
interface HTMLElement {
|
|
257
|
+
/**
|
|
258
|
+
* Storage for event handlers to enable cleanup
|
|
259
|
+
*/
|
|
254
260
|
__eventHandlers?: EventHandlerStorage;
|
|
255
261
|
}
|
|
256
262
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,32 +1,130 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Main mtrl library exports
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// Direct component imports
|
|
9
|
+
import { createElement } from './core/dom/create';
|
|
10
|
+
import createLayout from './core/layout';
|
|
11
|
+
import createBadge from './components/badge';
|
|
12
|
+
import createBottomAppBar from './components/bottom-app-bar';
|
|
13
|
+
import createButton from './components/button';
|
|
14
|
+
import createCard from './components/card';
|
|
15
|
+
import {
|
|
16
|
+
createCardContent,
|
|
17
|
+
createCardHeader,
|
|
18
|
+
createCardActions,
|
|
19
|
+
createCardMedia
|
|
20
|
+
} from './components/card/content';
|
|
21
|
+
import createCarousel from './components/carousel';
|
|
22
|
+
import createCheckbox from './components/checkbox';
|
|
23
|
+
import { createChip, createChips } from './components/chips';
|
|
24
|
+
import createDatePicker from './components/datepicker';
|
|
25
|
+
import createDialog from './components/dialog';
|
|
26
|
+
import { createDivider } from './components/divider';
|
|
27
|
+
import createFab from './components/fab';
|
|
28
|
+
import createExtendedFab from './components/extended-fab';
|
|
29
|
+
import createList, { createListItem } from './components/list';
|
|
30
|
+
import createMenu from './components/menu';
|
|
31
|
+
import createNavigation, { createNavigationSystem } from './components/navigation';
|
|
32
|
+
import createProgress from './components/progress';
|
|
33
|
+
import createRadios from './components/radios';
|
|
34
|
+
import createSearch from './components/search';
|
|
35
|
+
import createSegmentedButton, { createSegment } from './components/segmented-button';
|
|
36
|
+
import createSheet from './components/sheet';
|
|
37
|
+
import createSlider from './components/slider';
|
|
38
|
+
import createSnackbar from './components/snackbar';
|
|
39
|
+
import createSwitch from './components/switch';
|
|
40
|
+
import createTabs, { createTab } from './components/tabs';
|
|
41
|
+
import createTextfield from './components/textfield';
|
|
42
|
+
import createTimePicker from './components/timepicker';
|
|
43
|
+
import createTopAppBar from './components/top-app-bar';
|
|
44
|
+
import createTooltip from './components/tooltip';
|
|
45
|
+
|
|
46
|
+
// Export all "create*" functions
|
|
47
|
+
export {
|
|
48
|
+
createElement,
|
|
49
|
+
createLayout,
|
|
50
|
+
createBadge,
|
|
51
|
+
createBottomAppBar,
|
|
52
|
+
createButton,
|
|
53
|
+
createCard,
|
|
54
|
+
createCardContent,
|
|
55
|
+
createCardHeader,
|
|
56
|
+
createCardActions,
|
|
57
|
+
createCardMedia,
|
|
58
|
+
createCarousel,
|
|
59
|
+
createCheckbox,
|
|
60
|
+
createChip,
|
|
61
|
+
createChipSet,
|
|
62
|
+
createDatePicker,
|
|
63
|
+
createDialog,
|
|
64
|
+
createDivider,
|
|
65
|
+
createFab,
|
|
66
|
+
createExtendedFab,
|
|
67
|
+
createList,
|
|
68
|
+
createListItem,
|
|
69
|
+
createMenu,
|
|
70
|
+
createNavigation,
|
|
71
|
+
createNavigationSystem,
|
|
72
|
+
createProgress,
|
|
73
|
+
createRadios,
|
|
74
|
+
createSearch,
|
|
75
|
+
createSegmentedButton,
|
|
76
|
+
createSegment,
|
|
77
|
+
createSheet,
|
|
78
|
+
createSlider,
|
|
79
|
+
createSnackbar,
|
|
80
|
+
createSwitch,
|
|
81
|
+
createTabs,
|
|
82
|
+
createTab,
|
|
83
|
+
createTextfield,
|
|
84
|
+
createTimePicker,
|
|
85
|
+
createTopAppBar,
|
|
86
|
+
createTooltip
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// Export all "f*" aliases
|
|
90
|
+
export {
|
|
91
|
+
createElement as fElement,
|
|
92
|
+
createLayout as fLayout,
|
|
93
|
+
createBadge as fBadge,
|
|
94
|
+
createBottomAppBar as fBottomAppBar,
|
|
95
|
+
createButton as fButton,
|
|
96
|
+
createCard as fCard,
|
|
97
|
+
createCardContent as fCardContent,
|
|
98
|
+
createCardHeader as fCardHeader,
|
|
99
|
+
createCardActions as fCardActions,
|
|
100
|
+
createCardMedia as fCardMedia,
|
|
101
|
+
createCarousel as fCarousel,
|
|
102
|
+
createCheckbox as fCheckbox,
|
|
103
|
+
createChip as fChip,
|
|
104
|
+
createChips as fChips,
|
|
105
|
+
createDatePicker as fDatePicker,
|
|
106
|
+
createDialog as fDialog,
|
|
107
|
+
createDivider as fDivider,
|
|
108
|
+
createFab as fFab,
|
|
109
|
+
createExtendedFab as fExtendedFab,
|
|
110
|
+
createList as fList,
|
|
111
|
+
createListItem as fListItem,
|
|
112
|
+
createMenu as fMenu,
|
|
113
|
+
createNavigation as fNavigation,
|
|
114
|
+
createNavigationSystem as fNavigationSystem,
|
|
115
|
+
createProgress as fProgress,
|
|
116
|
+
createRadios as fRadios,
|
|
117
|
+
createSearch as fSearch,
|
|
118
|
+
createSegmentedButton as fSegmentedButton,
|
|
119
|
+
createSegment as fSegment,
|
|
120
|
+
createSheet as fSheet,
|
|
121
|
+
createSlider as fSlider,
|
|
122
|
+
createSnackbar as fSnackbar,
|
|
123
|
+
createSwitch as fSwitch,
|
|
124
|
+
createTabs as fTabs,
|
|
125
|
+
createTab as fTab,
|
|
126
|
+
createTextfield as fTextfield,
|
|
127
|
+
createTimePicker as fTimePicker,
|
|
128
|
+
createTopAppBar as fTopAppBar,
|
|
129
|
+
createTooltip as fTooltip
|
|
130
|
+
};
|