material 0.9.23 → 0.9.25
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/.editorconfig +36 -0
- package/.zed/README.md +64 -0
- package/.zed/settings.json +42 -0
- package/CONTRIBUTING.md +125 -0
- package/bun.lock +615 -0
- package/eslint.config.js +63 -0
- package/index.d.ts +77 -0
- package/package.json +1 -1
- package/src/class/component.js +2 -1
- package/src/class/control.js +1 -1
- package/src/module/events.js +7 -6
- package/src/module/extract.js +31 -30
- package/src/module/request.js +22 -2
package/eslint.config.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import js from '@eslint/js'
|
|
2
|
+
import globals from 'globals'
|
|
3
|
+
|
|
4
|
+
export default [
|
|
5
|
+
// Base configuration
|
|
6
|
+
js.configs.recommended,
|
|
7
|
+
|
|
8
|
+
// Standard JS configuration for material library
|
|
9
|
+
{
|
|
10
|
+
languageOptions: {
|
|
11
|
+
ecmaVersion: 2022,
|
|
12
|
+
sourceType: 'module',
|
|
13
|
+
globals: {
|
|
14
|
+
...globals.browser,
|
|
15
|
+
...globals.es2021,
|
|
16
|
+
// Material library specific globals
|
|
17
|
+
log: 'readonly',
|
|
18
|
+
document: 'readonly',
|
|
19
|
+
window: 'readonly',
|
|
20
|
+
navigator: 'readonly',
|
|
21
|
+
Element: 'readonly',
|
|
22
|
+
HTMLElement: 'readonly',
|
|
23
|
+
Event: 'readonly',
|
|
24
|
+
EventTarget: 'readonly',
|
|
25
|
+
CustomEvent: 'readonly',
|
|
26
|
+
localStorage: 'readonly',
|
|
27
|
+
sessionStorage: 'readonly',
|
|
28
|
+
requestAnimationFrame: 'readonly',
|
|
29
|
+
cancelAnimationFrame: 'readonly'
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
rules: {
|
|
33
|
+
// Standard JS rules - core formatting
|
|
34
|
+
'no-var': 'error',
|
|
35
|
+
'prefer-const': 'error',
|
|
36
|
+
'semi': ['error', 'never'],
|
|
37
|
+
'quotes': ['error', 'single', { avoidEscape: true }],
|
|
38
|
+
'space-before-function-paren': ['error', 'always'],
|
|
39
|
+
'object-curly-spacing': ['error', 'always'],
|
|
40
|
+
'comma-spacing': ['error', { before: false, after: true }],
|
|
41
|
+
'key-spacing': ['error', { beforeColon: false, afterColon: true }],
|
|
42
|
+
'no-trailing-spaces': 'error',
|
|
43
|
+
'eol-last': 'error',
|
|
44
|
+
'no-multiple-empty-lines': ['error', { max: 1 }],
|
|
45
|
+
'indent': ['error', 2],
|
|
46
|
+
'comma-dangle': ['error', 'never'],
|
|
47
|
+
'space-infix-ops': 'error',
|
|
48
|
+
'keyword-spacing': ['error', { before: true, after: true }],
|
|
49
|
+
'space-before-blocks': 'error',
|
|
50
|
+
'arrow-spacing': ['error', { before: true, after: true }]
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
// Ignore patterns
|
|
55
|
+
{
|
|
56
|
+
ignores: [
|
|
57
|
+
'node_modules/**',
|
|
58
|
+
'dist/**',
|
|
59
|
+
'build/**',
|
|
60
|
+
'*.min.js'
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
]
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
declare module "material" {
|
|
2
|
+
// Base classes
|
|
3
|
+
export class Component {
|
|
4
|
+
constructor(options?: any);
|
|
5
|
+
options: any;
|
|
6
|
+
element: HTMLElement;
|
|
7
|
+
ui: any;
|
|
8
|
+
underlay?: HTMLElement;
|
|
9
|
+
position(target: HTMLElement): void;
|
|
10
|
+
destroy(): Promise<void>;
|
|
11
|
+
static defaults: any;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class Control extends Component {}
|
|
15
|
+
|
|
16
|
+
export class Element {
|
|
17
|
+
constructor(options?: any);
|
|
18
|
+
static isElement(): boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Components
|
|
22
|
+
export class AppBar extends Component {}
|
|
23
|
+
export class Badge extends Component {}
|
|
24
|
+
export class Button extends Component {}
|
|
25
|
+
export class Card extends Component {}
|
|
26
|
+
export class Checkbox extends Component {}
|
|
27
|
+
export class ColorPicker extends Component {}
|
|
28
|
+
export class DateHour extends Component {}
|
|
29
|
+
export class Dialog extends Component {}
|
|
30
|
+
export class Drawer extends Component {}
|
|
31
|
+
export class File extends Component {}
|
|
32
|
+
export class Form extends Component {}
|
|
33
|
+
export class Image extends Component {}
|
|
34
|
+
export class List extends Component {}
|
|
35
|
+
export class Loading extends Component {}
|
|
36
|
+
export class Menu extends Component {}
|
|
37
|
+
export class Navigation extends Component {}
|
|
38
|
+
export class Progress extends Component {}
|
|
39
|
+
export class Select extends Component {}
|
|
40
|
+
export class Selecter extends Component {}
|
|
41
|
+
export class Snackbar extends Component {}
|
|
42
|
+
export class Slider extends Component {}
|
|
43
|
+
export class Switch extends Component {}
|
|
44
|
+
export class Switcher extends Component {}
|
|
45
|
+
export class Tabs extends Component {}
|
|
46
|
+
export class TabView extends Component {}
|
|
47
|
+
export class Text extends Component {}
|
|
48
|
+
export class Textfield extends Component {}
|
|
49
|
+
export class Toolbar extends Component {}
|
|
50
|
+
export class Tooltip extends Component {}
|
|
51
|
+
export class View extends Component {}
|
|
52
|
+
|
|
53
|
+
// Mixins
|
|
54
|
+
export const EventEmitter: any;
|
|
55
|
+
export const display: any;
|
|
56
|
+
export const build: any;
|
|
57
|
+
export const position: {
|
|
58
|
+
position(target: HTMLElement, position?: any): any;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// Modules
|
|
62
|
+
export const attributes: any;
|
|
63
|
+
export const clone: any;
|
|
64
|
+
export const create: any;
|
|
65
|
+
export const dataset: any;
|
|
66
|
+
export const device: any;
|
|
67
|
+
export const emitter: any;
|
|
68
|
+
export const events: any;
|
|
69
|
+
export const jsonToHTML: any;
|
|
70
|
+
export const mediator: any;
|
|
71
|
+
export const merge: any;
|
|
72
|
+
export const observer: any;
|
|
73
|
+
export const request: any;
|
|
74
|
+
export const ripple: any;
|
|
75
|
+
export const smoothscroll: any;
|
|
76
|
+
export function touch(): boolean;
|
|
77
|
+
}
|
package/package.json
CHANGED
package/src/class/component.js
CHANGED
|
@@ -19,7 +19,6 @@ class Component {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
async destroy () {
|
|
22
|
-
console.log('destroy')
|
|
23
22
|
if (this.options.transition && this.element) {
|
|
24
23
|
this.element.classList.remove('show')
|
|
25
24
|
if (this.underlay) {
|
|
@@ -36,6 +35,8 @@ class Component {
|
|
|
36
35
|
dom.destroy(this.element)
|
|
37
36
|
if (this.underlay) dom.destroy(this.underlay)
|
|
38
37
|
}
|
|
38
|
+
|
|
39
|
+
// this.emit('destroy')
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
|
package/src/class/control.js
CHANGED
package/src/module/events.js
CHANGED
|
@@ -59,21 +59,22 @@ const events = {
|
|
|
59
59
|
},
|
|
60
60
|
|
|
61
61
|
detach (eventsArray, context) {
|
|
62
|
+
// console.log('this', this)
|
|
62
63
|
const uid = context._uid
|
|
63
64
|
if (!this.eventHandlers[uid]) return
|
|
64
65
|
|
|
65
66
|
eventsArray.forEach(([eventDef, funcDef, option]) => {
|
|
66
67
|
const e = extract.e(context, eventDef)
|
|
67
68
|
const handler = this.eventHandlers[uid][eventDef]
|
|
68
|
-
|
|
69
|
+
|
|
70
|
+
if (handler && e?.element?.removeEventListener) {
|
|
69
71
|
e.element.removeEventListener(e.name, handler)
|
|
70
|
-
|
|
72
|
+
delete this.eventHandlers[uid][eventDef]
|
|
73
|
+
} else if (e?.element?.off) {
|
|
71
74
|
e.element.off(e.name, handler)
|
|
75
|
+
delete this.eventHandlers[uid][eventDef]
|
|
72
76
|
}
|
|
73
|
-
|
|
74
|
-
delete this.eventHandlers[uid][eventDef]
|
|
75
|
-
}
|
|
76
|
-
)
|
|
77
|
+
})
|
|
77
78
|
},
|
|
78
79
|
|
|
79
80
|
list (context) {
|
package/src/module/extract.js
CHANGED
|
@@ -1,42 +1,43 @@
|
|
|
1
|
-
|
|
2
1
|
/**
|
|
3
2
|
* extract.e extract a event and the context
|
|
4
3
|
* @param {[type]} str [description]
|
|
5
4
|
* @return {[type]} [description]
|
|
6
5
|
*/
|
|
7
6
|
const e = (instance, ev) => {
|
|
8
|
-
if (!ev) return instance
|
|
7
|
+
if (!ev) return instance;
|
|
9
8
|
else if (!ev.match(/\./)) {
|
|
10
9
|
return {
|
|
11
10
|
element: instance,
|
|
12
|
-
name: ev
|
|
13
|
-
}
|
|
11
|
+
name: ev,
|
|
12
|
+
};
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
let iteration
|
|
17
|
-
const obj = {}
|
|
18
|
-
let element
|
|
15
|
+
let iteration;
|
|
16
|
+
const obj = {};
|
|
17
|
+
let element;
|
|
19
18
|
|
|
20
|
-
const keys = ev.split(
|
|
19
|
+
const keys = ev.split(".");
|
|
21
20
|
|
|
22
|
-
if (keys[0] ===
|
|
23
|
-
element = window
|
|
21
|
+
if (keys[0] === "window") {
|
|
22
|
+
element = window;
|
|
23
|
+
} else if (keys[0] === "document") {
|
|
24
|
+
element = document;
|
|
24
25
|
} else {
|
|
25
26
|
for (let i = 0, l = keys.length; i <= l; i++) {
|
|
26
|
-
const key = keys[i]
|
|
27
|
-
iteration = iteration || instance
|
|
28
|
-
iteration = iteration[key]
|
|
27
|
+
const key = keys[i];
|
|
28
|
+
iteration = iteration || instance;
|
|
29
|
+
iteration = iteration[key];
|
|
29
30
|
|
|
30
31
|
if (i === keys.length - 2) {
|
|
31
|
-
element = iteration
|
|
32
|
+
element = iteration;
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
obj.element = element
|
|
37
|
-
obj.name = keys[keys.length - 1]
|
|
38
|
-
return obj
|
|
39
|
-
}
|
|
37
|
+
obj.element = element;
|
|
38
|
+
obj.name = keys[keys.length - 1];
|
|
39
|
+
return obj;
|
|
40
|
+
};
|
|
40
41
|
|
|
41
42
|
/**
|
|
42
43
|
* extract.f extract a function from a string using dot
|
|
@@ -44,22 +45,22 @@ const e = (instance, ev) => {
|
|
|
44
45
|
* @return {function} The function
|
|
45
46
|
*/
|
|
46
47
|
const f = (instance, func) => {
|
|
47
|
-
if (!func) return
|
|
48
|
+
if (!func) return;
|
|
48
49
|
|
|
49
|
-
if (typeof func ===
|
|
50
|
-
return func
|
|
51
|
-
} else if (!func.match(/\./)) return instance[func]
|
|
52
|
-
let iteration
|
|
50
|
+
if (typeof func === "function") {
|
|
51
|
+
return func;
|
|
52
|
+
} else if (!func.match(/\./)) return instance[func];
|
|
53
|
+
let iteration;
|
|
53
54
|
|
|
54
|
-
const keys = func.split(
|
|
55
|
+
const keys = func.split(".");
|
|
55
56
|
for (let i = 0, l = keys.length; i < l; i++) {
|
|
56
|
-
const key = keys[i]
|
|
57
|
+
const key = keys[i];
|
|
57
58
|
|
|
58
|
-
iteration = iteration || instance
|
|
59
|
-
iteration = iteration[key]
|
|
59
|
+
iteration = iteration || instance;
|
|
60
|
+
iteration = iteration[key];
|
|
60
61
|
}
|
|
61
62
|
|
|
62
|
-
return iteration
|
|
63
|
-
}
|
|
63
|
+
return iteration;
|
|
64
|
+
};
|
|
64
65
|
|
|
65
|
-
export default { e, f }
|
|
66
|
+
export default { e, f };
|
package/src/module/request.js
CHANGED
|
@@ -64,7 +64,22 @@ const request = async (
|
|
|
64
64
|
if (debug) {
|
|
65
65
|
console.error('Response error:', response.status, response.statusText)
|
|
66
66
|
}
|
|
67
|
-
|
|
67
|
+
|
|
68
|
+
// Try to parse error response as JSON to preserve backend error data
|
|
69
|
+
let errorData
|
|
70
|
+
try {
|
|
71
|
+
errorData = await response.json()
|
|
72
|
+
} catch (jsonError) {
|
|
73
|
+
// If JSON parsing fails, throw basic error (backward compatible)
|
|
74
|
+
throw { error: `HTTP error! status: ${response.status}` }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// If we successfully parsed JSON, throw it with all data
|
|
78
|
+
// If we successfully parsed JSON, throw it with all data
|
|
79
|
+
throw {
|
|
80
|
+
error: errorData.error || `HTTP error! status: ${response.status}`,
|
|
81
|
+
...errorData
|
|
82
|
+
}
|
|
68
83
|
}
|
|
69
84
|
|
|
70
85
|
// Handle response based on Accept header
|
|
@@ -77,7 +92,12 @@ const request = async (
|
|
|
77
92
|
if (headers.Accept === 'text/xml') {
|
|
78
93
|
throw error
|
|
79
94
|
} else {
|
|
80
|
-
|
|
95
|
+
// If error is already an object with error field, preserve it
|
|
96
|
+
if (typeof error === 'object' && error.error) {
|
|
97
|
+
throw error
|
|
98
|
+
} else {
|
|
99
|
+
throw { error: error.message || 'Request failed' }
|
|
100
|
+
}
|
|
81
101
|
}
|
|
82
102
|
}
|
|
83
103
|
}
|