material 0.9.20 → 0.9.22

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.
Files changed (51) hide show
  1. package/index.js +1 -0
  2. package/package.json +1 -1
  3. package/src/class/app.js +10 -0
  4. package/src/class/component.js +16 -13
  5. package/src/class/control.js +24 -16
  6. package/src/class/form.js +7 -22
  7. package/src/class/view.js +18 -19
  8. package/src/colorpicker.js +356 -0
  9. package/src/datehour.js +17 -12
  10. package/src/form/cancel.js +1 -2
  11. package/src/form/controller.js +10 -18
  12. package/src/form/data.js +175 -47
  13. package/src/form/fetch.js +18 -25
  14. package/src/form/render.js +2 -2
  15. package/src/form/submit.js +9 -3
  16. package/src/form/update.js +27 -30
  17. package/src/list/build.js +6 -1
  18. package/src/list/status.js +5 -0
  19. package/src/list/update.js +2 -0
  20. package/src/list/virtual.js +1 -1
  21. package/src/module/dom.js +0 -1
  22. package/src/module/emitter.js +45 -13
  23. package/src/module/extract.js +2 -2
  24. package/src/module/layout.js +1 -1
  25. package/src/module/request.js +49 -16
  26. package/src/selector.js +1 -1
  27. package/src/skin/material/control/colorpicker.sass +188 -0
  28. package/src/switch.js +6 -8
  29. package/src/switcher.js +21 -12
  30. package/src/text.js +1 -1
  31. package/src/textfield.js +6 -1
  32. package/src/list.new/build.js +0 -139
  33. package/src/list.new/click.js +0 -40
  34. package/src/list.new/collection.js +0 -30
  35. package/src/list.new/create.js +0 -45
  36. package/src/list.new/data.js +0 -16
  37. package/src/list.new/display.js +0 -78
  38. package/src/list.new/empty.js +0 -9
  39. package/src/list.new/filter.js +0 -114
  40. package/src/list.new/image.js +0 -19
  41. package/src/list.new/init.js +0 -6
  42. package/src/list.new/load.js +0 -9
  43. package/src/list.new/remove.js +0 -22
  44. package/src/list.new/render.js +0 -142
  45. package/src/list.new/request.js +0 -216
  46. package/src/list.new/search.js +0 -155
  47. package/src/list.new/select.js +0 -221
  48. package/src/list.new/status.js +0 -21
  49. package/src/list.new/update.js +0 -75
  50. package/src/list.new/virtual.js +0 -186
  51. package/src/list.new/virtual.new.js +0 -213
@@ -5,36 +5,69 @@ const request = async (
5
5
  headers = {},
6
6
  signal = null,
7
7
  debug = false,
8
- cache = 'no-store' // Adding cache parameter with a default value
8
+ cache = 'no-store'
9
9
  ) => {
10
- // console.trace('request')
11
- const defaultHeaders = {
12
- Accept: 'application/json',
13
- 'Content-Type': 'application/json'
14
- }
15
-
16
10
  const options = {
17
11
  method,
18
- headers: { ...defaultHeaders, ...headers },
12
+ headers: {}, // We'll set headers based on body type
19
13
  signal,
20
- cache // Including the cache option in the request
14
+ cache
21
15
  }
22
16
 
23
- if (debug) {
24
- console.log('debug', options)
17
+ // Handle headers and body based on body type
18
+ if (body) {
19
+ if (body instanceof FormData) {
20
+ // For FormData, don't set Content-Type - browser will set it automatically
21
+ options.body = body
22
+ options.headers = {
23
+ Accept: 'application/json',
24
+ ...headers
25
+ }
26
+
27
+ if (debug) {
28
+ console.group('FormData Contents:')
29
+ for (const pair of body.entries()) {
30
+ console.log(`${pair[0]}: ${pair[1]}`)
31
+ }
32
+ console.groupEnd()
33
+ }
34
+ } else {
35
+ // For JSON data
36
+ options.headers = {
37
+ Accept: 'application/json',
38
+ 'Content-Type': 'application/json',
39
+ ...headers
40
+ }
41
+ options.body = JSON.stringify(body)
42
+ }
43
+ } else {
44
+ // No body, use default headers
45
+ options.headers = {
46
+ Accept: 'application/json',
47
+ 'Content-Type': 'application/json',
48
+ ...headers
49
+ }
25
50
  }
26
51
 
27
- if (body) {
28
- options.body = JSON.stringify(body)
52
+ if (debug) {
53
+ console.group('Request Debug:')
54
+ console.log('URL:', url)
55
+ console.log('Method:', method)
56
+ console.log('Options:', { ...options, body: options.body instanceof FormData ? '[FormData]' : options.body })
57
+ console.groupEnd()
29
58
  }
30
59
 
31
60
  try {
32
61
  const response = await fetch(url, options)
62
+
33
63
  if (!response.ok) {
34
- // console.log('Error', response)
64
+ if (debug) {
65
+ console.error('Response error:', response.status, response.statusText)
66
+ }
67
+ throw new Error(`HTTP error! status: ${response.status}`)
35
68
  }
36
69
 
37
- // Determine response type based on 'Accept' header
70
+ // Handle response based on Accept header
38
71
  if (headers.Accept === 'text/xml') {
39
72
  return await response.text()
40
73
  } else {
@@ -44,7 +77,7 @@ const request = async (
44
77
  if (headers.Accept === 'text/xml') {
45
78
  throw error
46
79
  } else {
47
- throw { error }
80
+ throw { error: error.message || 'Request failed' }
48
81
  }
49
82
  }
50
83
  }
package/src/selector.js CHANGED
@@ -26,7 +26,7 @@ class Selector {
26
26
 
27
27
  init (options) {
28
28
  this.options = Object.assign({}, Selector.defaults, options || {})
29
- Object.assign(this, emitter, attach)
29
+ Object.assign(this, emitter, events)
30
30
  }
31
31
 
32
32
  /**
@@ -0,0 +1,188 @@
1
+ .colorpicker
2
+ display: none
3
+ position: absolute
4
+ width: 280px
5
+ background-color: var(--md-sys-color-surface)
6
+ border-radius: 4px
7
+ box-shadow: var(--md-sys-elevation-3)
8
+ z-index: 1000
9
+
10
+ // Panel container
11
+ .panel
12
+ padding: 16px
13
+
14
+ // Color gradient area
15
+ .gradient
16
+ position: relative
17
+ width: 100%
18
+ height: 150px
19
+ margin-bottom: 16px
20
+ border-radius: 4px
21
+ background-image: linear-gradient(rgba(0,0,0,0), #000), linear-gradient(90deg, #fff, currentColor)
22
+ cursor: pointer
23
+
24
+ .marker
25
+ position: absolute
26
+ width: 12px
27
+ height: 12px
28
+ margin: -6px
29
+ border: 2px solid #fff
30
+ border-radius: 50%
31
+ background-color: currentColor
32
+ box-shadow: 0 1px 4px rgba(0,0,0,0.2)
33
+ cursor: pointer
34
+ transition: transform 0.1s ease
35
+
36
+ &:focus
37
+ outline: none
38
+ transform: scale(1.1)
39
+
40
+ // Hue and Alpha sliders
41
+ .hue,
42
+ .alpha
43
+ position: relative
44
+ width: 100%
45
+ height: 20px
46
+ margin: 8px 0
47
+ border-radius: 10px
48
+
49
+ input[type="range"]
50
+ position: absolute
51
+ width: 100%
52
+ height: 100%
53
+ margin: 0
54
+ opacity: 0
55
+ cursor: pointer
56
+ appearance: none
57
+
58
+ .marker
59
+ position: absolute
60
+ width: 20px
61
+ height: 20px
62
+ transform: translateX(-50%)
63
+ border: 2px solid #fff
64
+ border-radius: 50%
65
+ background-color: currentColor
66
+ box-shadow: 0 1px 4px rgba(0,0,0,0.2)
67
+ pointer-events: none
68
+
69
+ .hue
70
+ background-image: linear-gradient(to right, #f00 0%, #ff0 16.66%, #0f0 33.33%, #0ff 50%, #00f 66.66%, #f0f 83.33%, #f00 100%)
71
+
72
+ .alpha
73
+ background-image: linear-gradient(45deg, #aaa 25%, transparent 25%, transparent 75%, #aaa 75%, #aaa), linear-gradient(45deg, #aaa 25%, #fff 25%, #fff 75%, #aaa 75%, #aaa)
74
+ background-size: 8px 8px
75
+ background-position: 0 0, 4px 4px
76
+
77
+ &:after
78
+ content: ''
79
+ position: absolute
80
+ width: 100%
81
+ height: 100%
82
+ border-radius: inherit
83
+ background-image: linear-gradient(90deg, rgba(0,0,0,0), currentColor)
84
+
85
+ // Input and Preview
86
+ .input
87
+ width: 100%
88
+ height: 40px
89
+ margin: 8px 0
90
+ padding: 0 12px
91
+ border: 1px solid var(--md-sys-color-outline)
92
+ border-radius: 4px
93
+ background: var(--md-sys-color-surface)
94
+ color: var(--md-sys-color-on-surface)
95
+ font-family: var(--md-sys-typescale-body-medium-font-family)
96
+ font-size: var(--md-sys-typescale-body-medium-size)
97
+ transition: border-color 0.2s ease
98
+
99
+ &:focus
100
+ outline: none
101
+ border-color: var(--md-sys-color-primary)
102
+
103
+ .preview
104
+ position: relative
105
+ width: 40px
106
+ height: 40px
107
+ border-radius: 4px
108
+ background-image: linear-gradient(45deg, #aaa 25%, transparent 25%, transparent 75%, #aaa 75%, #aaa), linear-gradient(45deg, #aaa 25%, #fff 25%, #fff 75%, #aaa 75%, #aaa)
109
+ background-size: 8px 8px
110
+ background-position: 0 0, 4px 4px
111
+ overflow: hidden
112
+
113
+ &:after
114
+ content: ''
115
+ position: absolute
116
+ inset: 0
117
+ background-color: currentColor
118
+
119
+ // Swatches
120
+ .swatches
121
+ display: flex
122
+ flex-wrap: wrap
123
+ gap: 8px
124
+ margin-top: 16px
125
+
126
+ button
127
+ width: 24px
128
+ height: 24px
129
+ padding: 0
130
+ border: none
131
+ border-radius: 4px
132
+ background-color: currentColor
133
+ cursor: pointer
134
+ transition: transform 0.1s ease
135
+
136
+ &:hover
137
+ transform: scale(1.1)
138
+
139
+ &:focus
140
+ outline: 2px solid var(--md-sys-color-primary)
141
+ outline-offset: 2px
142
+
143
+ // States
144
+ &.is-open
145
+ display: block
146
+
147
+ &[data-inline="true"]
148
+ position: relative
149
+ display: block
150
+
151
+ &[data-alpha="false"]
152
+ .alpha
153
+ display: none
154
+
155
+ // Field wrapper styles
156
+ .colorpicker-field
157
+ position: relative
158
+ display: inline-flex
159
+ align-items: center
160
+
161
+ input
162
+ padding-right: 40px
163
+
164
+ .preview
165
+ position: absolute
166
+ right: 8px
167
+ width: 24px
168
+ height: 24px
169
+ border-radius: 4px
170
+ background-image: linear-gradient(45deg, #aaa 25%, transparent 25%, transparent 75%, #aaa 75%, #aaa), linear-gradient(45deg, #aaa 25%, #fff 25%, #fff 75%, #aaa 75%, #aaa)
171
+ background-size: 8px 8px
172
+ background-position: 0 0, 4px 4px
173
+ pointer-events: none
174
+
175
+ &:after
176
+ content: ''
177
+ position: absolute
178
+ inset: 0
179
+ background-color: currentColor
180
+
181
+ // Dark theme support
182
+ @media (prefers-color-scheme: dark)
183
+ .colorpicker
184
+ background-color: var(--md-sys-color-surface-container-high)
185
+
186
+ .input
187
+ background: var(--md-sys-color-surface-container)
188
+ color: var(--md-sys-color-on-surface)
package/src/switch.js CHANGED
@@ -100,7 +100,7 @@ class Switch extends EventEmitter {
100
100
  this.setValue(value, silent)
101
101
  break
102
102
  case 'text':
103
- this.setValue(value)
103
+ this.setText(value)
104
104
  break
105
105
  case 'disabled':
106
106
  if (value === true) {
@@ -110,7 +110,7 @@ class Switch extends EventEmitter {
110
110
  }
111
111
  break
112
112
  default:
113
- this.setValue(prop, silent)
113
+ this.setValue(prop, value)
114
114
  }
115
115
 
116
116
  return this
@@ -160,17 +160,15 @@ class Switch extends EventEmitter {
160
160
  this.ui.input.checked = true
161
161
  this.checked = true
162
162
  this.value = true
163
- if (!silent) {
164
- this.emit('change', this.checked)
165
- }
166
163
  } else {
167
164
  this.element.classList.remove('is-checked')
168
165
  this.ui.input.checked = false
169
166
  this.checked = false
170
167
  this.value = false
171
- if (!silent) {
172
- this.emit('change', this.checked)
173
- }
168
+ }
169
+
170
+ if (!silent) {
171
+ this.emit('change', this.checked)
174
172
  }
175
173
  return this
176
174
  }
package/src/switcher.js CHANGED
@@ -151,7 +151,7 @@ class Switcher extends EventEmitter {
151
151
  this.emit('change', this.selected)
152
152
  }
153
153
 
154
- set (prop, value) {
154
+ set (prop, value, silent) {
155
155
  switch (prop) {
156
156
  case 'value':
157
157
  this.setValue(value)
@@ -163,13 +163,13 @@ class Switcher extends EventEmitter {
163
163
  this.addOptions(value)
164
164
  break
165
165
  default:
166
- this.setValue(prop)
166
+ this.setValue(prop, value)
167
167
  }
168
168
 
169
169
  return this
170
170
  }
171
171
 
172
- setValue (value) {
172
+ setValue (value, silent) {
173
173
  // console.log('value', value, this.options.list, this.element)
174
174
  const list = this.options.list
175
175
  if (this.options.mode === 'unique') {
@@ -193,6 +193,24 @@ class Switcher extends EventEmitter {
193
193
  }
194
194
  }
195
195
 
196
+ get () {
197
+ console.log('get', this.options.mode, this.selected[0])
198
+ if (this.options.mode === 'unique') {
199
+ return this.selected[0]
200
+ } else {
201
+ return this.selected
202
+ }
203
+ }
204
+
205
+ getValue () {
206
+ // console.log('get', this.selected)
207
+ if (this.options.mode === 'unique') {
208
+ return this.selected[0]
209
+ } else {
210
+ return this.selected
211
+ }
212
+ }
213
+
196
214
  addOptions (list) {
197
215
  // console.log('setOptions', list, this.options.list)
198
216
 
@@ -236,15 +254,6 @@ class Switcher extends EventEmitter {
236
254
  // console.log('setText', value)
237
255
  this.setLabel(value)
238
256
  }
239
-
240
- get () {
241
- // console.log('get', this.selected)
242
- if (this.options.mode === 'unique') {
243
- return this.selected[0]
244
- } else {
245
- return this.selected
246
- }
247
- }
248
257
  }
249
258
 
250
259
  export default Switcher
package/src/text.js CHANGED
@@ -19,7 +19,7 @@ class Text extends Component {
19
19
 
20
20
  set (text) {
21
21
  // console.log('set', text)
22
- if (text === 'undefined') text = ''
22
+ if (text === 'undefined' || !text) text = ''
23
23
 
24
24
  const label = this.options.label || ''
25
25
 
package/src/textfield.js CHANGED
@@ -2,6 +2,7 @@ import emitter from './module/emitter'
2
2
  import events from './module/events'
3
3
  import dataset from './module/dataset'
4
4
  import attributes from './module/attributes'
5
+ import * as css from './module/css'
5
6
 
6
7
  class Textfield {
7
8
  static isComponent () {
@@ -38,7 +39,7 @@ class Textfield {
38
39
  this.element.classList.add('textfield')
39
40
 
40
41
  if (this.options.class !== 'textfield') {
41
- this.element.classList.add(this.options.class)
42
+ css.add(this.element, this.options.class)
42
43
  }
43
44
 
44
45
  this.buildLabel()
@@ -166,6 +167,10 @@ class Textfield {
166
167
  get () {
167
168
  return this.input.value
168
169
  }
170
+
171
+ getValue () {
172
+ return this.input.value
173
+ }
169
174
  }
170
175
 
171
176
  export default Textfield
@@ -1,139 +0,0 @@
1
- import scrollbar from '../module/scrollbar'
2
- import dataset from '../module/dataset'
3
-
4
- import { create } from '../module/layout'
5
- import Virtual from './virtual'
6
- import Loading from '../loading'
7
-
8
- export default {
9
- build (data) {
10
- // console.log('options', this.options.name)
11
-
12
- this.dataId = this.options.dataId || '_id'
13
-
14
- this.element = document.createElement('div')
15
- this.element.classList.add('list')
16
-
17
- if (this.options.class) {
18
- this.addClass(this.options.class)
19
- }
20
-
21
- this.element.addEventListener('click', (e) => {
22
- e.stopPropagation()
23
- })
24
-
25
- if (this.options.name) {
26
- this.name = this.options.name
27
- }
28
-
29
- if (this.options.data) {
30
- dataset(this.element, this.options.data)
31
- }
32
-
33
- this.layout = create(this.options.layout.main, this.element)
34
- this.ui = this.layout.component
35
-
36
- // prepare loading
37
- // this.ui.loading = new Loading()
38
-
39
- if (this.options.container) {
40
- this.options.container.appendChild(this.element)
41
- }
42
-
43
- const scrollbarOffset = scrollbar()
44
-
45
- // console.log('scrollbarOffset', scrollbarOffset)
46
- if (this.ui && this.ui.body) {
47
- // console.log('body padding', 11 - scrollbarOffset + 'px')
48
- this.ui.body.style.marginRight = 11 - scrollbarOffset + 'px'
49
- this.ui.body.classList.add('offset' + scrollbarOffset)
50
- }
51
-
52
- this.buildVirtual()
53
- },
54
-
55
- addClass (c) {
56
- const list = c.split(' ')
57
-
58
- for (let i = 0; i < list.length; i++) {
59
- this.element.classList.add(list[i])
60
- }
61
- },
62
-
63
- buildVirtual () {
64
- // console.log('buildVirtual', this.options.class)
65
- let height = 80
66
- this.size = this.options.list.size
67
- this.stop = false
68
-
69
- if (this.options.item && this.options.item.height) {
70
- height = this.options.item.height
71
- }
72
-
73
- this.virtual = new Virtual({
74
- view: this.options.name,
75
- container: this.ui.body,
76
- itemHeight: height,
77
- size: this.size,
78
- render: (i) => {
79
- // console.log('render', this.data[i])
80
- return this.renderItem(this.data[i])
81
- }
82
- }).on('next', (total) => {
83
- // console.log('next', total)
84
- if (this.stop) return
85
-
86
- // console.log('next', total, this.page, this.size)
87
- this.page = this.page || 1
88
- // console.log('slide', total, this.options.list.size)
89
- // var page = Math.ceil(total / this.size) + 1
90
-
91
- this.page++
92
-
93
- if (this.mode === 'search') {
94
- this.search(this.ui['search-input'].input.value, this.page, this.size, true)
95
- } else {
96
- // console.log('request', this.page, this.size, true)
97
- this.request(this.page, this.size, true)
98
- }
99
- }).on('progress', (progress) => {
100
- // console.log('progress', progress, this.count)
101
-
102
- if (this.statusDisplay) {
103
- const percent = parseInt(progress / this.count * 100)
104
- this.statusDisplay('count', percent + '% | ' + progress + ' / ' + this.count)
105
- }
106
-
107
- this.onProgress(progress)
108
- })
109
- // .on('size', (size) => {
110
- // console.log('!!!!size', size)
111
- // this.size = size
112
- // })
113
- //
114
- },
115
-
116
- onProgress (value) {
117
- // console.log('progress', value, this._value)
118
-
119
- if (this.ui.head) {
120
- if (this.ui.body.scrollTop > 0 && this.ui.head) {
121
- this.ui.head.classList.add('scrolled')
122
- } else if (this.ui.head) {
123
- this.ui.head.classList.remove('scrolled')
124
- }
125
- }
126
-
127
- if (value > this._value) {
128
- // console.log('scrolling down')
129
- this.emit('scrolling', 'down')
130
- } else if (value < this._value) {
131
- // console.log('scrolling up')
132
- this.emit('scrolling', 'up')
133
- }
134
-
135
- this._value = value
136
-
137
- this.scrollTop = this.ui.body.scrollTop
138
- }
139
- }
@@ -1,40 +0,0 @@
1
-
2
- export default {
3
- click (e) {
4
- // console.log('click', e.target)
5
- e.stopPropagation()
6
-
7
- if (e.target === e.currentTarget) {
8
- return
9
- }
10
-
11
- const target = '[data-id]'
12
- let item = e.target
13
- let i = 0
14
-
15
- while (item && !item.matches(target)) {
16
- // console.log('item', item)
17
- if (i > 10) {
18
- item = null
19
- break
20
- }
21
- item = item.parentNode
22
- i++
23
- }
24
-
25
- if (e.target.matches('BUTTON') && e.target.dataset.name && item.dataset.id) {
26
- // console.log('button', e.target.dataset.name)
27
- this.emit(e.target.dataset.name, item.dataset.id)
28
- return this
29
- }
30
-
31
- if (this.select) {
32
- this.select(item)
33
- }
34
-
35
- // console.log('item', item, e.target.dataset.name)
36
-
37
- return this
38
- // console.log(item)
39
- }
40
- }
@@ -1,30 +0,0 @@
1
- class Collection {
2
- constructor () {
3
- this.items = {}
4
- this.ids = []
5
- }
6
-
7
- add (item) {
8
- const id = item[this.dataId]
9
- this.items[id] = item
10
- this.ids.push(id)
11
- }
12
-
13
- get (id) {
14
- return this.items[id] || null
15
- }
16
-
17
- getIndex (id) {
18
- return this.ids.indexOf(id)
19
- }
20
-
21
- getPage (page, pageSize) {
22
- const start = (page - 1) * pageSize
23
- const end = start + pageSize
24
- return this.ids.slice(start, end).map(id => this.items[id])
25
- }
26
-
27
- getCount () {
28
- return this.ids.length
29
- }
30
- }
@@ -1,45 +0,0 @@
1
- export default {
2
- create () {
3
- // console.log('create', this.mode, this.options.item.new)
4
- // console.log('selected', this.info, this.item)
5
-
6
- if (this.mode === 'create') return
7
-
8
- this.mode = 'create'
9
-
10
- if (this.options.virtual === true) {
11
- this.data.unshift(this.options.item.new)
12
- this.render(this.data)
13
- } else {
14
- if (this.options.item) {
15
- this.newItem = this.renderItem(this.options.item.new, 'create')
16
- }
17
- }
18
-
19
- this.emit('create', this.options.item.new)
20
- },
21
-
22
- created (data) {
23
- // console.log('created', this.data.length, data)
24
- if (this.options.virtual === true) {
25
- this.data[0] = data
26
- this.render(this.data)
27
- } else {
28
- this.mode = null
29
- this.info = data
30
- this.ui.body.removeChild(this.newItem)
31
- this.item = this.renderItem(data, 'top')
32
- }
33
- },
34
-
35
- createCancel () {
36
- // console.log('createCancel', this.newItem)
37
- // console.log('remove')
38
- // console.log('prepare reselect', this.info, this.item)
39
- this.ui.body.removeChild(this.newItem)
40
- this.mode = null
41
- if (this.item && this.info) {
42
- this.select(this.info, this.item)
43
- }
44
- }
45
- }
@@ -1,16 +0,0 @@
1
- export default {
2
- storeData (list, more) {
3
- console.log('storeData', list.length, more)
4
- if (more !== true) {
5
- this.dataList = []
6
- }
7
-
8
- // console.log('storeData', this.dataStore)
9
- this.dataStore = this.dataStore || {}
10
-
11
- for (let i = 0; i < list.length; i++) {
12
- this.dataList.push(list[i][this.dataId])
13
- this.dataStore[list[i][this.dataId]] = list[i]
14
- }
15
- }
16
- }