material 0.9.21 → 0.9.23

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.
@@ -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
@@ -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
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,7 +163,7 @@ 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
@@ -194,6 +194,15 @@ class Switcher extends EventEmitter {
194
194
  }
195
195
 
196
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 () {
197
206
  // console.log('get', this.selected)
198
207
  if (this.options.mode === 'unique') {
199
208
  return this.selected[0]
package/src/textfield.js CHANGED
@@ -167,6 +167,10 @@ class Textfield {
167
167
  get () {
168
168
  return this.input.value
169
169
  }
170
+
171
+ getValue () {
172
+ return this.input.value
173
+ }
170
174
  }
171
175
 
172
176
  export default Textfield
package/src/slider-new.js DELETED
@@ -1,341 +0,0 @@
1
- import init from './mixin/init'
2
- import build from './element/build'
3
- import control from './mixin/control'
4
-
5
- import events from './mixin/events'
6
- import insert from './element/insert'
7
- import offset from './element/offset'
8
- import classify from './module/classify'
9
- // import control from './control';
10
- import * as css from './module/css'
11
- import emitter from './module/emitter'
12
-
13
- import icon from './skin/material/icon/pin.svg'
14
-
15
- class Slider {
16
- static defaults = {
17
- class: 'slider',
18
- type: 'control',
19
- label: null,
20
- checked: false,
21
- error: false,
22
- value: false,
23
- range: [0, 100],
24
- step: 5,
25
- modules: [control, emitter],
26
- mixins: [],
27
- build: ['$root.material-slider', {},
28
- ['label$label.slider-label', {}],
29
- ['input$input'],
30
- ['$control.slider-control', {},
31
- ['$track.slider-track', {},
32
- ['canvas$canvas.slider-canvas', {}],
33
- ['$trackvalue.slider-track-value', {}],
34
- ['$knob.slider-knob', {}],
35
- ['$marker.slider-marker', {},
36
- ['$value.slider-value', {}]
37
- ]
38
- ]
39
- ]
40
- ],
41
- events: [
42
- ['element.input.focus', 'focus'],
43
- ['element.input.blur', 'blur']
44
- ]
45
- }
46
-
47
- constructor (options) {
48
- log.info('Slider')
49
- this.init(this.options)
50
- this.build(this.options)
51
- this.setup()
52
- }
53
-
54
- init (options) {
55
- this.options = Object.assign({}, Slider.defaults, options || {})
56
- init(this)
57
- }
58
-
59
- setup () {
60
- events.attach(this.options.events, this)
61
- }
62
-
63
- build () {
64
- this.element = build(this.options.build)
65
- this.element = this.element.root
66
-
67
- classify(this.element, this.options)
68
-
69
- if (this.options.container) {
70
- insert(this.element, this.options.container)
71
- }
72
-
73
- const value = this.element.marker.innerHTML
74
- this.element.marker.innerHTML = icon + value
75
-
76
- if (this.options.type) {
77
- css.add(this.element, 'type-' + this.options.type)
78
- }
79
-
80
- // init input
81
- if (this.options.disabled) {
82
- this.disable(true)
83
- }
84
-
85
- // if (this.options.name) {
86
- // this.element.dataset.name = name
87
- // this.element.input.name = name
88
- // }
89
-
90
- // init text
91
- const text = this.options.label || this.options.text
92
- this.element.label.textContent = text
93
-
94
- this.options.label = this.options.label || this.options.text
95
-
96
- this.initTrack()
97
-
98
- const delay = 50
99
-
100
- setTimeout(() => {
101
- this.initCanvas()
102
- }, delay)
103
- }
104
-
105
- initCanvas () {
106
- window.addEventListener('resize', () => {
107
- console.log('resize')
108
- this.drawCanvas()
109
- }, false)
110
- this.drawCanvas()
111
- }
112
-
113
- drawCanvas () {
114
- const width = offset(this.element.track, 'width')
115
- const height = offset(this.element.track, 'height')
116
-
117
- this.element.canvas.width = width
118
- this.element.canvas.height = height
119
-
120
- const context = this.element.canvas.getContext('2d')
121
- context.lineWidth = 2
122
- context.beginPath()
123
-
124
- context.moveTo(0, (height / 2) + 1)
125
- context.lineTo(width, (height / 2) + 1)
126
- context.strokeStyle = 'rgba(34, 31, 31, .26)'
127
- context.stroke()
128
- }
129
-
130
- /**
131
- * [buildControl description]
132
- * @return {?} [description]
133
- */
134
- initTrack () {
135
- this.element.track.addEventListener('mousedown', (ev) => {
136
- if (this.disabled === true) return
137
- this.initTrackSize()
138
- const position = ev.layerX
139
- this.update(position)
140
- })
141
-
142
- this.element.knob.addEventListener('click', (ev) => {
143
- ev.stopPropagation()
144
- })
145
-
146
- this.initDragging()
147
-
148
- const delay = 100
149
-
150
- setTimeout(() => {
151
- this.setValue(this.options.value)
152
- }, delay)
153
- }
154
-
155
- initTrackSize () {
156
- this._tracksize = offset(this.element.track, 'width')
157
- this._knobsize = offset(this.element.knob, 'width')
158
- this._markersize = 32 /* offset(this.element.marker, 'width') */
159
- this._trackleft = offset(this.element.track, 'left')
160
- return this
161
- }
162
-
163
- /**
164
- * [initDragging description]
165
- * @return {?} [description]
166
- */
167
- initDragging () {
168
- this.element.knob.onmousedown = (e) => {
169
- if (this.disabled === true) return
170
-
171
- e.stopPropagation()
172
- e = e || window.event
173
-
174
- css.add(this.element.control, 'dragging')
175
-
176
- let start = 0
177
- let position = 0
178
-
179
- if (e.pageX) start = e.pageX
180
- else if (e.clientX) start = e.clientX
181
-
182
- start = this._trackleft
183
- document.body.onmousemove = (e) => {
184
- if (this.disabled === true) return
185
- console.log('mousedown', this.disabled)
186
-
187
- e = e || window.event
188
- let end = 0
189
- if (e.pageX) end = e.pageX
190
- else if (e.clientX) end = e.clientX
191
-
192
- position = end - start
193
- this.update(position)
194
- }
195
- document.body.onmouseup = (e) => {
196
- document.body.onmousemove = document.body.onmouseup = null
197
-
198
- e = e || window.event
199
- let end = 0
200
- if (e.pageX) end = e.pageX
201
- else if (e.clientX) end = e.clientX
202
-
203
- position = end - start
204
- this.update(position)
205
- css.remove(this.element.control, 'dragging')
206
- }
207
- }
208
- }
209
-
210
- update (position) {
211
- const size = this._tracksize
212
- const range = this.options.range[1] - this.options.range[0]
213
-
214
- if (position > size) {
215
- position = size
216
- }
217
-
218
- if (position < 0) {
219
- position = 0
220
- }
221
-
222
- const ratio = (size / position)
223
- const value = Math.round((range / ratio)) + this.options.range[0]
224
-
225
- if (position === 0) {
226
- css.remove(this.element.knob, 'notnull')
227
- }
228
-
229
- this.element.knob.style.left = position - this._knobsize / 2 + 'px'
230
- this.element.trackvalue.style.width = (position) + 'px'
231
- this.element.marker.style.left = position - this._markersize / 2 + 'px'
232
-
233
- this.element.value.textContent = value
234
-
235
- this.element.input.value = value
236
- if (value > this.options.range[0]) {
237
- css.add(this.element.knob, 'notnull')
238
- } else {
239
- css.remove(this.element.knob, 'notnull')
240
- }
241
- }
242
-
243
- updateValue (value) {
244
- this.initTrackSize()
245
-
246
- let size = offset(this.element.track, 'width')
247
- size = parseInt(size)
248
-
249
- const range = this.options.range[1] - this.options.range[0]
250
- const ratio = value * 100 / range
251
- const position = Math.round(size * ratio / 100)
252
-
253
- this.update(position)
254
-
255
- return this
256
- }
257
-
258
- /**
259
- * [insert description]
260
- * @param {?} container [description]
261
- * @param {?} context [description]
262
- * @return {?} [description]
263
- */
264
- insert (container, context) {
265
- insert(this.element, container, context)
266
- }
267
-
268
- /**
269
- * Setter
270
- * @param {string} prop
271
- * @param {string} value
272
- */
273
- set (prop, value) {
274
- switch (prop) {
275
- case 'value':
276
- this.setValue(value)
277
- break
278
- case 'label':
279
- this.setLabel(value)
280
- break
281
- default:
282
- this.setValue(prop)
283
- }
284
-
285
- return this
286
- }
287
-
288
- /**
289
- * Getter
290
- * @param {string} prop
291
- * @param {string} value
292
- */
293
- get (prop) {
294
- let value
295
-
296
- switch (prop) {
297
- case 'value':
298
- value = this.getValue()
299
- break
300
- case 'name':
301
- value = this.name
302
- break
303
- default:
304
- return this.getValue()
305
- }
306
-
307
- return value
308
- }
309
-
310
- /**
311
- * [getValue description]
312
- * @return {Object} The class instance
313
- */
314
- getValue () {
315
- return this.element.input.value
316
- }
317
-
318
- /**
319
- * [setValue description]
320
- * @param {string} value [description]
321
- */
322
- setValue (value) {
323
- value = value || this.options.range[0]
324
- this.element.input.value = value
325
- this.updateValue(value)
326
- }
327
-
328
- /**
329
- * [setLabel description]
330
- * @param {?} text [description]
331
- */
332
- setLabel (text) {
333
- text = text || this.options.label || this.options.text
334
-
335
- if (text !== null && this.label) {
336
- this.label.textContent = text
337
- }
338
- }
339
- }
340
-
341
- export default Slider