@mixd-id/web-scaffold 0.1.230406389 → 0.1.230406391

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.230406389",
4
+ "version": "0.1.230406391",
5
5
  "scripts": {
6
6
  "dev": "vite serve",
7
7
  "build": "vite build",
@@ -11,6 +11,8 @@
11
11
  <PresetBar :config="config"
12
12
  class="flex-1"
13
13
  :enumCache="enumCache"
14
+ :controller="controller"
15
+ :preset-key="presetKey"
14
16
  @apply="load">
15
17
 
16
18
  <template #toolbar>
@@ -26,7 +28,7 @@
26
28
  @mousedown="(e) => $util.dragResize(e, resize1)"></div>
27
29
  </div>
28
30
 
29
- <div class="flex-1 flex flex-col relative">
31
+ <div v-if="preset" class="flex-1 flex flex-col relative">
30
32
 
31
33
  <div class="flex-1 flex flex-col" :class="containerClass">
32
34
  <slot name="head"
@@ -86,6 +88,7 @@
86
88
 
87
89
  <div class="flex flex-row gap-2 gap-1" v-if="Boolean(toolbar)">
88
90
  <Textbox class="flex-1 md:w-[240px]" placeholder="Search..." clearable="1"
91
+ maxlength="100"
89
92
  v-model="preset.search"
90
93
  @clear="delete preset.search; load()"
91
94
  @keyup.enter="load">
@@ -146,8 +149,8 @@
146
149
  </template>
147
150
 
148
151
  <template #end>
149
- <div v-if="data?.hasNext" class="flex justify-center p-3">
150
- <svg v-if="readyState === 4" class="animate-spin aspect-square w-[14px] h-[14px] fill-text-300" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg>
152
+ <div v-if="data?.hasNext" class="flex justify-center pt-3 pb-5">
153
+ <svg v-if="readyState === 4" class="animate-spin w-[21px] h-[21px]" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg>
151
154
  <button v-else type="button" class="text-text-300" @click="loadNext()">
152
155
  {{ $t('Load More' )}}
153
156
  </button>
@@ -286,6 +289,7 @@ export default{
286
289
  },
287
290
  presetKey: String,
288
291
  subscribeKey: String,
292
+ controller: String,
289
293
  src: undefined,
290
294
  title: String,
291
295
  view: {
@@ -364,29 +368,25 @@ export default{
364
368
  },
365
369
 
366
370
  load(){
367
- if(this.src){
371
+ if(this.computedSrc){
368
372
  if(!this.preset.columns){
369
373
  this.preset.columns = JSON.parse(JSON.stringify(this.config.columns))
370
374
  }
371
375
 
372
376
  this.readyState = 2
373
- return this.socket.send(this.src, {
377
+ return this.socket.send(this.computedSrc, {
374
378
  ...this.preset,
375
379
  id: undefined,
376
380
  itemsPerPage: this.data.itemsPerPage,
377
381
  })
378
382
  .then(data => {
379
- const firstItem = data.items[0]
380
- const lastItem = data.items[data.items.length - 1]
381
- console.log('@load',
382
- `${firstItem?.id + ':' + firstItem?.name + ':' + firstItem?.lastMessageAt}`,
383
- `${lastItem?.id + ':' + lastItem?.name + ':' + lastItem?.lastMessageAt}`)
384
-
385
383
  generatePivotColumns(this.preset, data.items)
386
384
  generateTotalColumns(this.preset, data.items)
387
385
  this.loadEnums(data.items)
388
- Object.assign(this.data, data ?? {})
389
- this.$emit('after-load')
386
+ .then(() => {
387
+ Object.assign(this.data, data ?? {})
388
+ this.$emit('after-load')
389
+ })
390
390
  })
391
391
  .catch(err => {
392
392
  this.toast(err)
@@ -397,29 +397,24 @@ export default{
397
397
  },
398
398
 
399
399
  loadNext(){
400
- if(this.src &&
400
+ if(this.computedSrc && this.readyState !== 4 &&
401
401
  ((this.data ?? {}).hasNext !== false) &&
402
402
  !(this.preset.pivot ?? {}).enabled) {
403
403
 
404
404
  const afterItem = this.dataItems[this.dataItems.length - 1]
405
405
 
406
406
  this.readyState = 4
407
- this.socket.send(this.src, {
407
+ this.socket.send(this.computedSrc, {
408
408
  ...this.preset,
409
409
  id: undefined,
410
410
  itemsPerPage: this.data.itemsPerPage,
411
411
  afterItem,
412
412
  })
413
413
  .then(data => {
414
- const firstItem = data.items[0]
415
- const lastItem = data.items[data.items.length - 1]
416
- console.log('@loadNext',
417
- `${afterItem?.id + ':' + afterItem?.name + ':' + afterItem?.lastMessageAt}`,
418
- `${firstItem?.id + ':' + firstItem?.name + ':' + firstItem?.lastMessageAt}`,
419
- `${lastItem?.id + ':' + lastItem?.name + ':' + lastItem?.lastMessageAt}`)
420
-
421
- this.data.items.push(...data.items)
422
414
  this.loadEnums(data.items)
415
+ .then(() => {
416
+ this.data.items.push(...data.items)
417
+ })
423
418
  })
424
419
  .catch(err => this.toast(err))
425
420
  .finally(_ => this.readyState = 1)
@@ -430,7 +425,7 @@ export default{
430
425
  loadPreset(){
431
426
  if(!Object.keys(this.$route.query).map(_ => _.toLowerCase()).includes('reset')){
432
427
  if(this.presetKey){
433
- return this.socket.send('user.preset', { key:this.presetKey })
428
+ return this.socket.send(this.presetSrc, { key:this.presetKey })
434
429
  .then(config => {
435
430
  Object.assign(this.config, config)
436
431
 
@@ -442,8 +437,6 @@ export default{
442
437
  }
443
438
  else{
444
439
  return new Promise((resolve) => {
445
- this.savePreset()
446
-
447
440
  const query = {}
448
441
  for(let key in this.$route.query){
449
442
  if(key.toLowerCase() !== 'reset')
@@ -459,10 +452,8 @@ export default{
459
452
  }
460
453
  },
461
454
 
462
- loadEnums(items){
463
-
464
- for(let i in this.preset.columns){
465
- const column = this.preset.columns[i]
455
+ async loadEnums(items){
456
+ return Promise.all((this.preset.columns ?? []).map(async column => {
466
457
 
467
458
  if(column.enumSrc) {
468
459
 
@@ -480,7 +471,7 @@ export default{
480
471
  if(reqItems.length > 0 && reqItems !== this.lastEnumItems){
481
472
 
482
473
  const [ src, key, attr ] = column.enumSrc.split(':')
483
- this.socket.send(src, {
474
+ const res = await this.socket.send(src, {
484
475
  columns: [
485
476
  { key:attr, visible:true }
486
477
  ],
@@ -489,34 +480,32 @@ export default{
489
480
  key:key, value: [ { operator:'in', value:reqItems } ]
490
481
  }
491
482
  ]
483
+ });
484
+
485
+ (res.items ?? []).forEach(_ => {
486
+ this.enumCache[column.key][_[key]] = {
487
+ text: _[attr] ?? _[key],
488
+ value: _[key],
489
+ }
492
490
  })
493
- .then(res => {
494
- (res.items ?? []).forEach(_ => {
495
- this.enumCache[column.key][_[key]] = {
496
- text: _[attr] ?? _[key],
497
- value: _[key],
498
- }
499
- })
500
491
 
501
- for(let key in this.enumCache[column.key]){
502
- if(!this.enumCache[column.key][key].text)
503
- this.enumCache[column.key][key].text = key
504
- }
492
+ for(let key in this.enumCache[column.key]){
493
+ if(!this.enumCache[column.key][key].text)
494
+ this.enumCache[column.key][key].text = key
495
+ }
505
496
 
506
- this.lastEnumItems = reqItems
507
- })
508
- .catch(err => this.log('Load enums error', err))
497
+ this.lastEnumItems = reqItems
509
498
  }
510
499
  }
511
- }
512
500
 
501
+ }))
513
502
  },
514
503
 
515
504
  loadExt(){
516
505
  if(!this.extBar.open) return
517
506
 
518
507
  this.readyState = 3
519
- return this.socket.send(this.src, {
508
+ return this.socket.send(this.computedSrc, {
520
509
  ...this.preset,
521
510
  filters: [
522
511
  ...(this.preset.filters ?? []),
@@ -533,7 +522,7 @@ export default{
533
522
  loadExtNext(){
534
523
  if(!this.preset.filters) return
535
524
 
536
- return this.socket.send(this.src, {
525
+ return this.socket.send(this.computedSrc, {
537
526
  ...this.preset,
538
527
  filters: [
539
528
  ...(this.preset.filters ?? []),
@@ -556,7 +545,7 @@ export default{
556
545
 
557
546
  selectPreset(idx){
558
547
  if(this.config.presets[idx]){
559
- this.config.presetIdx = idx
548
+ this.configParams.presetIdx = this.config.presets[idx].uid
560
549
  this.load()
561
550
  this.$refs.presetSelector.close()
562
551
  this.$refs.contextMenu.close()
@@ -565,7 +554,7 @@ export default{
565
554
 
566
555
  savePreset: invokeAfterIdle(function() {
567
556
  if(this.presetKey) {
568
- this.socket.send('user.preset',
557
+ this.socket.send(this.presetSrc,
569
558
  {key: this.presetKey, config: this.config})
570
559
  }
571
560
  }),
@@ -621,7 +610,7 @@ export default{
621
610
  loadQueued(items){
622
611
  const key = items[0] && items[0].uid ? 'uid' : 'id'
623
612
 
624
- this.socket.send(this.src, {
613
+ this.socket.send(this.computedSrc, {
625
614
  ...this.preset,
626
615
  [key]: items.map(item => item[key])
627
616
  })
@@ -957,7 +946,14 @@ export default{
957
946
  },
958
947
 
959
948
  preset(){
960
- return ((this.config ?? {}).presets ?? [])[(this.config ?? {}).presetIdx ?? 0] ?? {}
949
+ return this.config.presets.find(_ => _.uid === this.configParams.presetIdx) ??
950
+ this.config.sharedPresets.find(_ => _.uid === this.configParams.presetIdx)
951
+ },
952
+
953
+ presetSrc(){
954
+ return this.controller ?
955
+ `${this.controller}.preset` :
956
+ 'user.preset'
961
957
  },
962
958
 
963
959
  presetView(){
@@ -968,6 +964,10 @@ export default{
968
964
  configParams(){
969
965
  if(!this.config.params)
970
966
  this.config.params = {}
967
+
968
+ if(!this.config.params.presetIdx && this.config.presets.length > 0)
969
+ this.config.params.presetIdx = this.config.presets[0].uid
970
+
971
971
  return this.config.params
972
972
  },
973
973
 
@@ -1006,6 +1006,10 @@ export default{
1006
1006
 
1007
1007
  pivotEnabled(){
1008
1008
  return ((this.preset ?? {}).pivot ?? {}).enabled
1009
+ },
1010
+
1011
+ computedSrc(){
1012
+ return this.src ?? `${this.controller}.load`
1009
1013
  }
1010
1014
 
1011
1015
  },
@@ -57,7 +57,6 @@
57
57
  <svg class="animate-spin aspect-square w-[16px] h-[16px] text-primary" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg>
58
58
  </div>
59
59
  </div>
60
- <slot name="end"></slot>
61
60
  </div>
62
61
  </div>
63
62
  <div v-else-if="visibleColumns.length <= 0 && Array.isArray(columns)" class="text-center p-3 flex-1 min-h-[100%] flex items-center justify-center">
@@ -67,6 +66,8 @@
67
66
  <h5 class="text-text-300">No data available</h5>
68
67
  </div>
69
68
 
69
+ <slot name="end"></slot>
70
+
70
71
  <div :class="$style.calc" v-if="visibleColumns.length > 0 && cItems && cItems.length > 0" ref="calc">
71
72
  <table :class="$style.table">
72
73
  <tbody>
@@ -577,7 +578,14 @@ export default{
577
578
  break
578
579
  }
579
580
 
580
- return text ? text : (value === null ? '' : '-')
581
+ const res = text ? text : (value === null ? '' : '-')
582
+
583
+ return `${res}`
584
+ .replace(/&/g, "&amp;")
585
+ .replace(/</g, "&lt;")
586
+ .replace(/>/g, "&gt;")
587
+ .replace(/"/g, "&quot;")
588
+ .replace(/'/g, "&#039;")
581
589
  },
582
590
 
583
591
  setState(state){
@@ -1286,6 +1286,7 @@ const presetToSequelizeList = async(preset, {
1286
1286
  include,
1287
1287
  order:initialOrder
1288
1288
  }) => {
1289
+ if(!model) return {}
1289
1290
 
1290
1291
  const updatedAtField = model.rawAttributes['updatedAt'] ?? model.rawAttributes['updated_at']
1291
1292
 
@@ -68,6 +68,9 @@ const setupConfig = (config) => {
68
68
 
69
69
  if(!config.presets[idx].view)
70
70
  config.presets[idx].view = 'table'
71
+
72
+ if(!config.presets[idx].uid)
73
+ config.presets[idx].uid = getPresetUid(config.name)
71
74
  }
72
75
 
73
76
  if(!config.presetIdx && config.presets.length > 0){
package/src/utils/wss.js CHANGED
@@ -74,18 +74,21 @@ class WSS extends EventEmitter2{
74
74
  _reqFn = []
75
75
  _retryCount = 0
76
76
 
77
- async fromBinaryData(binaryData){
77
+ _connectionId = 0
78
+ _debugIds = {}
79
+
80
+ async fromBinaryData(binaryData, debugMode = false){
78
81
  const encryptedString = Buffer.from(binaryData).toString('utf-8');
79
- const decryptedData = this._opt.key ?
82
+ const decryptedData = this._opt.key && !debugMode ?
80
83
  CryptoJS.AES.decrypt(encryptedString, this._opt.key).toString(CryptoJS.enc.Utf8) :
81
84
  encryptedString;
82
85
  const receivedObject = JSON.parse(decryptedData);
83
86
  return await revertDataUrlObj(receivedObject);
84
87
  }
85
88
 
86
- async toBinaryData(obj){
89
+ async toBinaryData(obj, debugMode = false){
87
90
  const dataUrlObj = await convertDataUrlObj(obj)
88
- const encryptedData = this._opt.key ?
91
+ const encryptedData = this._opt.key && !debugMode ?
89
92
  CryptoJS.AES.encrypt(JSON.stringify(dataUrlObj), this._opt.key).toString() :
90
93
  JSON.stringify(dataUrlObj);
91
94
  return new TextEncoder().encode(encryptedData);
@@ -106,12 +109,17 @@ class WSS extends EventEmitter2{
106
109
  this._client.connect().then()
107
110
 
108
111
  this._instance.on('connection', async (socket, req) => {
112
+ socket.id = `${++this._connectionId}`
113
+
114
+ if(`${req.url}`.indexOf('debug-ws') > 0){
115
+ this._debugIds[socket.id] = {}
116
+ }
109
117
 
110
118
  let subscriber
111
119
 
112
120
  const listener = (message) => {
113
121
  const { model, event, items } = JSON.parse(message)
114
- this.toBinaryData({ data:{ model, event, items } })
122
+ this.toBinaryData({ data:{ model, event, items } }, !!this._debugIds[socket.id])
115
123
  .then(data => socket.send(data))
116
124
  }
117
125
 
@@ -157,7 +165,7 @@ class WSS extends EventEmitter2{
157
165
 
158
166
  let obj
159
167
  try{
160
- obj = await this.fromBinaryData(binaryData);
168
+ obj = await this.fromBinaryData(binaryData, !!this._debugIds[socket.id]);
161
169
  }
162
170
  catch(e){
163
171
  return socket.close(1002, e.message);
@@ -170,7 +178,7 @@ class WSS extends EventEmitter2{
170
178
  this._retryCount = 0
171
179
  }
172
180
  else if(ping){
173
- socket.send(await this.toBinaryData({ pong: 1 }))
181
+ socket.send(await this.toBinaryData({ pong: 1 }, !!this._debugIds[socket.id]))
174
182
  }
175
183
  else{
176
184
  let status = 200
@@ -209,7 +217,7 @@ class WSS extends EventEmitter2{
209
217
  _requestId,
210
218
  status,
211
219
  data
212
- }))
220
+ }, !!this._debugIds[socket.id]))
213
221
  }
214
222
  });
215
223
 
@@ -231,7 +239,7 @@ class WSS extends EventEmitter2{
231
239
  }
232
240
 
233
241
  socket.isAuth = true
234
- socket.send(await this.toBinaryData({ auth:true }))
242
+ socket.send(await this.toBinaryData({ auth:true }, !!this._debugIds[socket.id]))
235
243
 
236
244
  subscriber = this._client.duplicate()
237
245
  await subscriber.connect()
@@ -243,7 +251,7 @@ class WSS extends EventEmitter2{
243
251
  if(this._opt.ping !== false){
244
252
 
245
253
  const ping = async() => {
246
- socket.send(await this.toBinaryData({ ping:1 }))
254
+ socket.send(await this.toBinaryData({ ping:1 }, !!this._debugIds[socket.id]))
247
255
  socket.pinging = true
248
256
 
249
257
  setTimeout(() => {
package/src/utils/wss.mjs CHANGED
@@ -78,14 +78,14 @@ class WSS extends EventEmitter2{
78
78
 
79
79
  async fromBinaryData(binaryData){
80
80
  const encryptedString = new TextDecoder().decode(binaryData)
81
- const decryptedData = this._opt.key ?
81
+ const decryptedData = this._opt.key && !this._opt.debug ?
82
82
  CryptoJS.AES.decrypt(encryptedString, this._opt.key).toString(CryptoJS.enc.Utf8) :
83
83
  encryptedString;
84
84
  return JSON.parse(decryptedData)
85
85
  }
86
86
 
87
87
  async toBinaryData(obj){
88
- const encryptedData = this._opt.key ?
88
+ const encryptedData = this._opt.key && !this._opt.debug ?
89
89
  CryptoJS.AES.encrypt(JSON.stringify(obj), this._opt.key).toString() :
90
90
  JSON.stringify(obj);
91
91
  return new TextEncoder().encode(encryptedData)
@@ -32,7 +32,7 @@
32
32
  <div class="flex-1 p-6 flex flex-col">
33
33
 
34
34
  <div v-if="items?.length > 0">
35
- <div v-for="item in items" :class="dashboardStyle.button" @click="select(item)">
35
+ <div v-for="item in items" :class="appStyle.menuItem" @click="select(item)">
36
36
  <slot name="item" :item="item">
37
37
  <div>{{ item.name }}</div>
38
38
  </slot>
@@ -55,7 +55,7 @@ export default{
55
55
 
56
56
  emits: [ 'select' ],
57
57
 
58
- inject: [ 'dashboardStyle', 'socket', 'toast' ],
58
+ inject: [ 'appStyle', 'socket', 'toast' ],
59
59
 
60
60
  name: 'SharingModal',
61
61