@mixd-id/web-scaffold 0.1.230406390 → 0.1.230406392

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.230406390",
4
+ "version": "0.1.230406392",
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"
@@ -287,6 +289,7 @@ export default{
287
289
  },
288
290
  presetKey: String,
289
291
  subscribeKey: String,
292
+ controller: String,
290
293
  src: undefined,
291
294
  title: String,
292
295
  view: {
@@ -365,13 +368,13 @@ export default{
365
368
  },
366
369
 
367
370
  load(){
368
- if(this.src){
371
+ if(this.computedSrc){
369
372
  if(!this.preset.columns){
370
373
  this.preset.columns = JSON.parse(JSON.stringify(this.config.columns))
371
374
  }
372
375
 
373
376
  this.readyState = 2
374
- return this.socket.send(this.src, {
377
+ return this.socket.send(this.computedSrc, {
375
378
  ...this.preset,
376
379
  id: undefined,
377
380
  itemsPerPage: this.data.itemsPerPage,
@@ -394,14 +397,14 @@ export default{
394
397
  },
395
398
 
396
399
  loadNext(){
397
- if(this.src && this.readyState !== 4 &&
400
+ if(this.computedSrc && this.readyState !== 4 &&
398
401
  ((this.data ?? {}).hasNext !== false) &&
399
402
  !(this.preset.pivot ?? {}).enabled) {
400
403
 
401
404
  const afterItem = this.dataItems[this.dataItems.length - 1]
402
405
 
403
406
  this.readyState = 4
404
- this.socket.send(this.src, {
407
+ this.socket.send(this.computedSrc, {
405
408
  ...this.preset,
406
409
  id: undefined,
407
410
  itemsPerPage: this.data.itemsPerPage,
@@ -422,7 +425,7 @@ export default{
422
425
  loadPreset(){
423
426
  if(!Object.keys(this.$route.query).map(_ => _.toLowerCase()).includes('reset')){
424
427
  if(this.presetKey){
425
- return this.socket.send('user.preset', { key:this.presetKey })
428
+ return this.socket.send(this.presetSrc, { key:this.presetKey })
426
429
  .then(config => {
427
430
  Object.assign(this.config, config)
428
431
 
@@ -434,8 +437,6 @@ export default{
434
437
  }
435
438
  else{
436
439
  return new Promise((resolve) => {
437
- this.savePreset()
438
-
439
440
  const query = {}
440
441
  for(let key in this.$route.query){
441
442
  if(key.toLowerCase() !== 'reset')
@@ -504,7 +505,7 @@ export default{
504
505
  if(!this.extBar.open) return
505
506
 
506
507
  this.readyState = 3
507
- return this.socket.send(this.src, {
508
+ return this.socket.send(this.computedSrc, {
508
509
  ...this.preset,
509
510
  filters: [
510
511
  ...(this.preset.filters ?? []),
@@ -521,7 +522,7 @@ export default{
521
522
  loadExtNext(){
522
523
  if(!this.preset.filters) return
523
524
 
524
- return this.socket.send(this.src, {
525
+ return this.socket.send(this.computedSrc, {
525
526
  ...this.preset,
526
527
  filters: [
527
528
  ...(this.preset.filters ?? []),
@@ -544,7 +545,7 @@ export default{
544
545
 
545
546
  selectPreset(idx){
546
547
  if(this.config.presets[idx]){
547
- this.config.presetIdx = idx
548
+ this.configParams.presetIdx = this.config.presets[idx].uid
548
549
  this.load()
549
550
  this.$refs.presetSelector.close()
550
551
  this.$refs.contextMenu.close()
@@ -553,7 +554,7 @@ export default{
553
554
 
554
555
  savePreset: invokeAfterIdle(function() {
555
556
  if(this.presetKey) {
556
- this.socket.send('user.preset',
557
+ this.socket.send(this.presetSrc,
557
558
  {key: this.presetKey, config: this.config})
558
559
  }
559
560
  }),
@@ -609,7 +610,7 @@ export default{
609
610
  loadQueued(items){
610
611
  const key = items[0] && items[0].uid ? 'uid' : 'id'
611
612
 
612
- this.socket.send(this.src, {
613
+ this.socket.send(this.computedSrc, {
613
614
  ...this.preset,
614
615
  [key]: items.map(item => item[key])
615
616
  })
@@ -945,7 +946,14 @@ export default{
945
946
  },
946
947
 
947
948
  preset(){
948
- 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'
949
957
  },
950
958
 
951
959
  presetView(){
@@ -956,6 +964,12 @@ export default{
956
964
  configParams(){
957
965
  if(!this.config.params)
958
966
  this.config.params = {}
967
+
968
+ if(this.config.presets.length > 0 &&
969
+ (!this.config.params.presetIdx ||
970
+ !this.config.presets.find(_ => _.uid === this.config.params.presetIdx)))
971
+ this.config.params.presetIdx = this.config.presets[0].uid
972
+
959
973
  return this.config.params
960
974
  },
961
975
 
@@ -994,6 +1008,10 @@ export default{
994
1008
 
995
1009
  pivotEnabled(){
996
1010
  return ((this.preset ?? {}).pivot ?? {}).enabled
1011
+ },
1012
+
1013
+ computedSrc(){
1014
+ return this.src ?? `${this.controller}.load`
997
1015
  }
998
1016
 
999
1017
  },
@@ -578,7 +578,14 @@ export default{
578
578
  break
579
579
  }
580
580
 
581
- 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;")
582
589
  },
583
590
 
584
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