@mixd-id/web-scaffold 0.1.230406261 → 0.1.230406263

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mixd-id/web-scaffold",
3
3
  "private": false,
4
- "version": "0.1.230406261",
4
+ "version": "0.1.230406263",
5
5
  "scripts": {
6
6
  "dev": "vite serve",
7
7
  "build": "vite build",
@@ -480,8 +480,6 @@ export default{
480
480
 
481
481
  .comp{
482
482
  @apply flex flex-col p-2;
483
- @apply backdrop-blur-lg;
484
- padding-bottom: 50px;
485
483
  }
486
484
 
487
485
  </style>
@@ -133,11 +133,12 @@
133
133
  <script>
134
134
 
135
135
  import VirtualTable from "./VirtualTable.vue";
136
+ import VirtualGrid from "./VirtualGrid.vue";
136
137
  import throttle from "lodash/throttle";
137
138
  import PresetSelector from "../widgets/PresetSelector.vue";
138
139
  import groupBy from "lodash/groupBy";
139
- import {capitalize} from "lodash";
140
140
  import {sortsFn} from "../utils/preset-selector.mjs";
141
+ import PresetBar from "../widgets/PresetBar.vue";
141
142
 
142
143
  export default{
143
144
 
@@ -181,6 +182,11 @@ export default{
181
182
 
182
183
  load(){
183
184
  if(this.src){
185
+
186
+ if(!this.preset.columns){
187
+ this.preset.columns = JSON.parse(JSON.stringify(this.config.columns))
188
+ }
189
+
184
190
  return this.socket.send(this.src, {
185
191
  ...this.preset,
186
192
  itemsPerPage: this.data.itemsPerPage,
@@ -354,7 +360,7 @@ export default{
354
360
 
355
361
  },
356
362
 
357
- components: {PresetSelector, VirtualTable},
363
+ components: {PresetBar, PresetSelector, VirtualGrid, VirtualTable},
358
364
 
359
365
  emits: [ 'after-load', 'open-preset' ],
360
366
 
@@ -311,6 +311,10 @@ export default{
311
311
  @apply panel-400;
312
312
  @apply border-[1px] border-text-50 z-20 flex max-h-[90vh];
313
313
  @apply rounded-xl overflow-hidden transition-all;
314
+ background-color: rgba(255, 255, 255, .6)
315
+ }
316
+ html[data-theme='dark'] .modal{
317
+ background-color: rgba(0, 0, 0, .3)
314
318
  }
315
319
 
316
320
  .modal.v-show{
@@ -6,7 +6,7 @@
6
6
  <div class="flex-1 flex flex-row gap-2">
7
7
  <Dropdown v-model="value.operator"
8
8
  class="w-[100px]"
9
- @change="value.value ? $emit('change') : null">
9
+ @change="apply">
10
10
  <option value="=">=</option>
11
11
  <option value=">">&gt;</option>
12
12
  <option value=">=">&gt;=</option>
@@ -24,12 +24,12 @@
24
24
  <Datepicker class="flex-1"
25
25
  mode="popup"
26
26
  v-model="value.value"
27
- @change="value.operator ? $emit('change') : null" />
27
+ @change="apply" />
28
28
  <Datepicker v-if="value.operator === 'between'"
29
29
  class="flex-1"
30
30
  mode="popup"
31
31
  v-model="value.value2"
32
- @change="value.operator ? $emit('change') : null" />
32
+ @change="apply" />
33
33
  </div>
34
34
  </div>
35
35
  </div>
@@ -37,7 +37,7 @@
37
37
  <div v-else-if="type === 'number'" class="flex flex-row gap-2">
38
38
  <Dropdown v-model="value.operator"
39
39
  class="w-[100px]"
40
- @change="value.value ? $emit('change') : null">
40
+ @change="apply">
41
41
  <option value="=">=</option>
42
42
  <option value=">">&gt;</option>
43
43
  <option value=">=">&gt;=</option>
@@ -48,18 +48,18 @@
48
48
  </Dropdown>
49
49
  <Textbox v-model="value.value"
50
50
  class="flex-1"
51
- @keyup.enter="value.operator ? $emit('change') : null"
52
- @blur="value.operator ? $emit('change') : null" />
51
+ @keyup.enter="apply"
52
+ @blur="apply" />
53
53
  </div>
54
54
 
55
55
  <div v-else-if="type === 'boolean'" class="flex flex-row gap-2">
56
- <Radio :name="value.key" :value="true" v-model="value.value" @change="$emit('change')">True</Radio>
57
- <Radio :name="value.key" :value="false" v-model="value.value" @change="$emit('change')">False</Radio>
56
+ <Radio :name="value.key" :value="true" v-model="value.value" @change="apply">True</Radio>
57
+ <Radio :name="value.key" :value="false" v-model="value.value" @change="apply">False</Radio>
58
58
  </div>
59
59
 
60
60
  <div v-else class="flex flex-row gap-2">
61
61
  <Dropdown v-model="value.operator" class="w-[100px]"
62
- @change="value.value ? $emit('change') : null">
62
+ @change="apply">
63
63
  <option value="eq">Equal</option>
64
64
  <option value="not">Not Equal</option>
65
65
  <option value="startsWith">Starts With</option>
@@ -72,8 +72,8 @@
72
72
  </Dropdown>
73
73
  <Textbox v-model="value.value"
74
74
  class="flex-1"
75
- @keyup.enter="value.operator ? $emit('change') : null"
76
- @blur="value.operator ? $emit('change') : null" />
75
+ @keyup.enter="apply"
76
+ @blur="apply" />
77
77
  </div>
78
78
 
79
79
  </div>
@@ -94,9 +94,26 @@ export default{
94
94
 
95
95
  },
96
96
 
97
+ computed:{
98
+
99
+ valueRequired(){
100
+ return (!(['yesterday', 'today', 'thisWeek', 'thisMonth', 'thisYear'].includes(this.value.operator) ||
101
+ this.type === 'boolean'));
102
+ }
103
+
104
+ },
105
+
97
106
  methods: {
98
107
 
108
+ apply(){
109
+
110
+ if((!this.valueRequired && this.value.operator) ||
111
+ (this.value.operator && this.value.operator !== 'between' && this.value.value) ||
112
+ (this.value.operator === 'between' && !!this.value.value && !!this.value.value2)){
113
+ this.$emit('change')
114
+ }
99
115
 
116
+ }
100
117
 
101
118
  }
102
119
 
@@ -29,8 +29,6 @@ const pickColumns = function(columns, keys){
29
29
  return acc
30
30
  }, {})
31
31
 
32
- console.log('#1', groupedColumns)
33
-
34
32
  for(let key of keys){
35
33
  if(groupedColumns[key]){
36
34
  groupedColumns[key].visible = true
package/src/utils/wss.js CHANGED
@@ -95,7 +95,7 @@ class WSS extends EventEmitter2{
95
95
  this._opt = opt
96
96
  this._instance = new WebSocket.Server(opt);
97
97
 
98
- this._instance.on('connection', (socket, req) => {
98
+ this._instance.on('connection', async (socket, req) => {
99
99
 
100
100
  socket.leave = (channel) => {
101
101
  if((socket.channels ?? {})[channel]){
@@ -128,6 +128,7 @@ class WSS extends EventEmitter2{
128
128
  }
129
129
 
130
130
  socket.on('message', async (binaryData) => {
131
+ if(!socket.isAuth) return
131
132
 
132
133
  let obj
133
134
  try{
@@ -143,17 +144,6 @@ class WSS extends EventEmitter2{
143
144
  let data
144
145
  switch(path){
145
146
 
146
- case '_auth':
147
- try{
148
- for(let fn of this._authFn){
149
- await fn(params, socket)
150
- }
151
- }
152
- catch(e){
153
- return socket.close(1002, e.message);
154
- }
155
- break
156
-
157
147
  case 'ping':
158
148
  data = { type:'pong' }
159
149
  break
@@ -192,6 +182,16 @@ class WSS extends EventEmitter2{
192
182
  socket.on('close', (e) => {
193
183
  this.emit('close', e, socket)
194
184
  });
185
+
186
+ const token = req.headers['sec-websocket-protocol'];
187
+ try{
188
+ await this._opt.auth(token, socket)
189
+ socket.isAuth = true
190
+ socket.send(await this.toBinaryData({ auth:true }))
191
+ }
192
+ catch(e){
193
+ return socket.close(1002, e.message);
194
+ }
195
195
  })
196
196
  }
197
197
 
package/src/utils/wss.mjs CHANGED
@@ -46,7 +46,6 @@ class WSS extends EventEmitter2{
46
46
  _callbacks = {}
47
47
  _pendingSend = []
48
48
  _lastBlurAt
49
- _readyState = 0
50
49
 
51
50
  constructor(opt) {
52
51
  super();
@@ -55,19 +54,16 @@ class WSS extends EventEmitter2{
55
54
  auth: {},
56
55
  debug: false,
57
56
  key: '',
58
- onConnect: null,
59
- onConnectError: null,
60
- onDisconnect: null,
61
57
  timeout: 30000,
62
58
  url: '',
63
59
  }, opt ?? {})
64
60
 
65
- if(typeof window !== 'undefined'){
61
+ /*if(typeof window !== 'undefined'){
66
62
  window.addEventListener('online', this._onOnlineChanged)
67
63
  window.addEventListener('offline', this._onOnlineChanged)
68
64
  window.addEventListener('blur', this._onBlur)
69
65
  window.addEventListener('focus', this._onFocus)
70
- }
66
+ }*/
71
67
 
72
68
  this.connect().then()
73
69
  }
@@ -113,31 +109,24 @@ class WSS extends EventEmitter2{
113
109
 
114
110
  async connect(reconnect = false){
115
111
 
116
- this._readyState = 0
112
+ this._instance = new WebSocket(this._opt.url, this._opt.token)
117
113
 
118
- this._instance = new WebSocket(this._opt.url)
119
114
  this._instance.binaryType = 'arraybuffer';
120
- this._instance.onopen = () => {
121
- this._readyState = 2
122
- this.send('_auth', this._opt.auth)
123
- .then(() => {
124
- this._readyState = 1
125
-
126
- reconnect ? this.emit('reconnect', null, []) : this.emit('connect', null, [])
127
-
128
- for(let sendParams of this._pendingSend){
129
- this.sendSync(sendParams.path, sendParams.params, sendParams.cb, sendParams.err)
130
- }
131
- this._pendingSend = []
132
- })
133
- };
134
115
 
135
116
  this._instance.onmessage = async (event) => {
136
117
  const obj = await this.fromBinaryData(event.data);
137
118
 
138
- const { _requestId, status, data } = obj
119
+ const { _requestId, status, data, auth } = obj
120
+
121
+ if(auth){
122
+ reconnect ? this.emit('reconnect', null, []) : this.emit('connect', null, [])
139
123
 
140
- if(_requestId){
124
+ for(let sendParams of this._pendingSend){
125
+ this.sendSync(sendParams.path, sendParams.params, sendParams.cb, sendParams.err)
126
+ }
127
+ this._pendingSend = []
128
+ }
129
+ else if(_requestId){
141
130
  if(this._callbacks[_requestId]){
142
131
  const { cb, err, path, params, t1 } = this._callbacks[_requestId]
143
132
  status === 200 ? cb(data) : err(data)
@@ -160,10 +149,13 @@ class WSS extends EventEmitter2{
160
149
  };
161
150
 
162
151
  this._instance.onerror = (e) => {
152
+ console.log('onerror', e)
153
+
163
154
  this.emit('error', e, [])
164
155
  }
165
156
 
166
157
  this._instance.onclose = (e) => {
158
+ console.log('onclose', e)
167
159
 
168
160
  switch(e.code){
169
161
 
@@ -189,10 +181,15 @@ class WSS extends EventEmitter2{
189
181
  }
190
182
 
191
183
  sendSync(path, params, cb, err, override){
192
- if(this._instance.readyState !== 1 || (path !== '_auth' && this._readyState !== 1)){
184
+
185
+ if(this._instance.readyState === 0){
193
186
  this._pendingSend.push({ path, params, cb, err })
194
187
  return
195
188
  }
189
+ else if(this._instance.readyState !== 1){
190
+ console.log('unable to send, ready state not 1', this._instance.readyState)
191
+ return
192
+ }
196
193
 
197
194
  /*if(!navigator.onLine){
198
195
  err({ message: 'Unable to send, network disconnected' })
@@ -207,7 +204,9 @@ class WSS extends EventEmitter2{
207
204
  params
208
205
  })
209
206
  .then(async(dataUrlObj) => {
207
+
210
208
  const binaryData = await this.toBinaryData(dataUrlObj)
209
+ console.log('sendSync', this._instance.readyState, dataUrlObj)
211
210
  this._instance.send(binaryData)
212
211
 
213
212
  this._callbacks[_requestId] = {
@@ -1,7 +1,7 @@
1
1
  <template>
2
- <Modal :state="isOpen" width="320" height="400" class="bg-base-500">
2
+ <Modal :state="isOpen" width="320" height="400">
3
3
  <template v-slot:head>
4
- <div class="relative p-5 bg-base-400">
4
+ <div class="relative p-5">
5
5
  <h3>{{ $t('Select Column') }}</h3>
6
6
  <div class="absolute top-0 right-0 p-2">
7
7
  <button type="button" class="p-2" @click="close">
@@ -12,11 +12,14 @@
12
12
  </div>
13
13
  </div>
14
14
  </template>
15
- <div class="flex-1">
15
+ <template #foot>
16
+ <div class="pb-6"></div>
17
+ </template>
18
+ <div class="flex-1 px-3">
16
19
 
17
- <div class="flex flex-col divide-y divide-border-50">
20
+ <div class="flex flex-col divide-y divide-text-50 bg-base-400 border-[1px] border-text-50 rounded-lg overflow-hidden">
18
21
  <button v-for="column in columns"
19
- type="button" class="p-3 px-5 text-left hover:bg-primary-100"
22
+ type="button" class="p-3 px-5 text-left hover:bg-primary hover:text-white"
20
23
  @click="select(column)">
21
24
  {{ column.label ? column.label : column.key }}
22
25
  </button>
@@ -78,7 +78,7 @@
78
78
  <Tabs :items="tabItems[config.type ?? 'list']" v-model="config.presetBarTabIndex" />
79
79
  </div>
80
80
 
81
- <div class="flex-1 overflow-y-auto bg-base-500 dark:bg-base-400">
81
+ <div class="flex-1 overflow-y-auto">
82
82
 
83
83
  <div v-if="config.presetBarTabIndex === 1" class="flex-1 flex flex-col p-5">
84
84
  <ListItem :items="presetColumns"
@@ -102,7 +102,7 @@
102
102
 
103
103
  <div v-else-if="config.presetBarTabIndex === 2" class="flex-1 flex flex-col p-5">
104
104
 
105
- <div class="flex-1 flex flex-col">
105
+ <div class="flex-1 flex flex-col gap-6">
106
106
 
107
107
  <div v-for="(filter, idx) in preset.filters">
108
108
 
@@ -247,7 +247,7 @@
247
247
  </button>
248
248
  </div>
249
249
  <ListItem :items="xAxis"
250
- class="mt-2 h-[90px] border-[1px] border-border-200 bg-base-400 rounded-lg p-0.5"
250
+ class="mt-2 h-[90px] border-[1px] border-text-200 bg-base-400 rounded-lg p-1"
251
251
  body-class="flex flex-col gap-1"
252
252
  @reorder="(from, to) => { xAxis.splice(to, 0, xAxis.splice(from, 1)[0]); }">
253
253
  <template v-slot="{ item, index }">
@@ -287,7 +287,7 @@
287
287
  </button>
288
288
  </div>
289
289
  <ListItem :items="yAxis"
290
- class="mt-2 h-[90px] border-[1px] border-border-200 bg-base-400 rounded-lg p-0.5"
290
+ class="mt-2 h-[90px] border-[1px] border-text-200 bg-base-400 rounded-lg p-1"
291
291
  body-class="flex flex-col gap-1"
292
292
  @reorder="(from, to) => { yAxis.splice(to, 0, yAxis.splice(from, 1)[0]); }">
293
293
  <template v-slot="{ item, index }">
@@ -338,7 +338,7 @@
338
338
  </button>
339
339
  </div>
340
340
  <ListItem :items="yAxis"
341
- class="mt-2 h-[90px] border-[1px] border-border-200 bg-base-400 rounded-lg p-0.5"
341
+ class="mt-2 h-[90px] border-[1px] border-text-200 bg-base-400 rounded-lg p-0.5"
342
342
  body-class="flex flex-col gap-1"
343
343
  @reorder="(from, to) => { yAxis.splice(to, 0, yAxis.splice(from, 1)[0]); }">
344
344
  <template v-slot="{ item, index }">
@@ -370,7 +370,7 @@
370
370
  </button>
371
371
  </div>
372
372
  <ListItem :items="xAxis"
373
- class="mt-2 h-[90px] border-[1px] border-border-200 bg-base-400 rounded-lg p-0.5"
373
+ class="mt-2 h-[90px] border-[1px] border-text-200 bg-base-400 rounded-lg p-0.5"
374
374
  body-class="flex flex-col gap-1"
375
375
  @reorder="(from, to) => { xAxis.splice(to, 0, xAxis.splice(from, 1)[0]); }">
376
376
  <template v-slot="{ item, index }">
@@ -448,7 +448,7 @@
448
448
  </div>
449
449
  <ListItem :items="presetPivot.rows"
450
450
  @reorder="(from, to) => { presetPivot.rows.splice(to, 0, presetPivot.rows.splice(from, 1)[0]); apply() }"
451
- class="mt-2 h-[90px] border-[1px] border-border-200 bg-base-400 rounded-lg p-0.5">
451
+ class="mt-2 h-[90px] border-[1px] border-text-200 bg-base-400 rounded-lg p-0.5">
452
452
  <template v-slot="{ item, index }">
453
453
  <div class="flex flex-row items-center gap-3 p-2 bg-base-500 hover:bg-primary-100 first:rounded-t-md last:rounded-b-md">
454
454
  <div data-reorder v-if="(presetPivot.rows ?? []).length > 1">
@@ -484,7 +484,7 @@
484
484
  </div>
485
485
  <ListItem :items="presetPivot.values"
486
486
  @reorder="(from, to) => { presetPivot.values.splice(to, 0, presetPivot.values.splice(from, 1)[0]); }"
487
- class="mt-2 h-[90px] border-[1px] border-border-200 bg-base-400 rounded-lg p-0.5">
487
+ class="mt-2 h-[90px] border-[1px] border-text-200 bg-base-400 rounded-lg p-0.5">
488
488
  <template v-slot="{ item, index }">
489
489
  <div class="flex flex-row items-center gap-3 p-2 bg-base-500 hover:bg-primary-100 first:rounded-t-md last:rounded-b-md">
490
490
  <div data-reorder v-if="(presetPivot.values ?? []).length > 1">