Skip to content

Commit 2ffa613

Browse files
Fixed display bugs when the new prop :get-all-properties="true", this prop can be used to show properties of classes (static properties) and class objects (enumerating also the prototype properties from parents and grand parents when extends inheritance is used).
Enjoy!
1 parent 63c98b4 commit 2ffa613

File tree

3 files changed

+104
-58
lines changed

3 files changed

+104
-58
lines changed

vue-dd/demo/App.vue

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,64 @@
11
<script setup lang="ts">
22
import { reactive, ref } from 'vue'
33
import { action, computed, inject, makeObservable, observable } from "*";
4-
const w = window
5-
const test = reactive({ 'test': 'test' })
6-
const test2 = { 'test': ref({test: 'test'}), 'array':['test','test2'] }
74
8-
abstract class MessagesPresenter {
5+
const w = window
6+
const test = reactive({ 'test': 'test' })
7+
const test2 = { 'test': ref({ test: 'test' }), 'array': ['test', 'test2'] }
98
9+
abstract class GrandParent {
10+
grandParent = 'test'
11+
12+
get grandParentGetter () {
13+
return 'fun'
14+
}
15+
}
16+
17+
abstract class MessagesPresenter extends GrandParent {
1018
1119
showValidationWarning = null
1220
21+
static _name = 'hi'
1322
14-
constructor() {
15-
}
23+
constructor () {
24+
super()
1625
17-
init = () => {
1826
}
1927
20-
abstract reset(): void
28+
init = () => {}
2129
22-
get messages() {
23-
}
30+
abstract reset (): void
2431
25-
unpackRepositoryPmToVm = (pm, userMessage) => {
32+
get messages () {
33+
return 'yes'
2634
}
27-
}
2835
36+
unpackRepositoryPmToVm = (pm, userMessage) => {}
37+
}
38+
class Auth {
39+
test = 1
40+
}
2941
class LoginRegisterPresenter extends MessagesPresenter {
3042
43+
static test = 2
44+
static test2 = 2
45+
46+
static testF () {
47+
return 1
48+
}
3149
3250
email = null
3351
password = null
3452
option = null
3553
36-
getVm () {
37-
38-
}
39-
4054
constructor () {
4155
super()
56+
this.auth = new Auth()
4257
}
4358
4459
//
4560
get viewTest () {
46-
return ''
61+
return 'test'
4762
}
4863
4964
set viewTest (value) {
@@ -72,16 +87,23 @@ class LoginRegisterPresenter extends MessagesPresenter {
7287
}
7388
7489
const presenter = new LoginRegisterPresenter()
90+
91+
const proto = Object.getPrototypeOf(presenter)
92+
7593
</script>
7694
<template>
77-
<h1>Basic Tests</h1>
78-
<vue-dd name="window" :get-all-properties="true" v-model="w" />
95+
<h1>vue-dd integration tests</h1>
96+
<vue-dd name="window" :save-focus="false" :get-all-properties="false" v-model="w" />
7997
<br />
80-
<vue-dd name="test" :get-all-properties="true" v-model="test" />
98+
<vue-dd name="test" get-all-properties v-model="test" />
8199
<br />
82-
<vue-dd name="test2" :get-all-properties="true" v-model="test2" />
100+
<vue-dd name="test2" get-all-properties v-model="test2" />
83101
<br />
84102
<vue-dd name="presenter" :get-all-properties="true" v-model="presenter" />
103+
<vue-dd name="LoginRegisterPresenter" :get-all-properties="true" v-model="LoginRegisterPresenter" />
104+
105+
106+
85107
</template>
86108

87109

vue-dd/src/NodeComplex.vue

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -455,10 +455,43 @@ export default {
455455
emit (name, ...args) {
456456
this.emitFn(this, name, ...args)
457457
},
458+
makeClassItems (modelValue) {
459+
460+
// Get all object properties as well as prototype properties
461+
let proto = Object.getPrototypeOf(modelValue)
462+
463+
let props = []
464+
while(proto && proto.constructor.name !== 'Object') {
465+
props.push.apply(props, Object.getOwnPropertyNames(proto).filter(el => !['caller', 'callee', 'arguments'].includes(el)))
466+
proto = Object.getPrototypeOf(proto.constructor.prototype)
467+
}
468+
469+
let keys = Array.from(
470+
new Set(
471+
Object.getOwnPropertyNames(modelValue).concat(props)
472+
)
473+
)
474+
475+
let keysLength = keys.length;
476+
477+
if (!this.isOpen) {
478+
// handle closed state
479+
const preview = parseInt(this.preview)
480+
let i = 0;
481+
while (i < keysLength) {
482+
if (i === preview) break;
483+
keys[i] = keys[i]
484+
i++
485+
}
486+
}
487+
return { keys, keysLength }
488+
},
458489
makeItems () {
490+
let keys = [], i = 0
459491
switch (true) {
492+
460493
case this.isObject:
461-
let keys = [], i = 0;
494+
462495
switch (true) {
463496
case this.isSet:
464497
this.getMapSet = Array.from(this.modelValue)
@@ -477,26 +510,9 @@ export default {
477510
478511
if (this.getAllProperties) {
479512
480-
// Get all object properties
481-
const proto = Object.getPrototypeOf(this.modelValue)
482-
483-
// Converting to and from set, deduplicates the array
484-
keys = Array.from(new Set(Object.getOwnPropertyNames(this.modelValue)
485-
.concat(proto && proto.constructor.name !== 'Object' ? Object.getOwnPropertyNames(proto) : [])))
486-
487-
let keysLength = keys.length;
488-
489-
if (!this.isOpen) {
490-
// handle closed state
491-
const preview = parseInt(this.preview)
492-
while (i < keysLength) {
493-
if (i === preview) break;
494-
keys[i] = keys[i]
495-
i++
496-
}
497-
}
498-
499-
this.getSize = keysLength
513+
const classItems = this.makeClassItems(this.modelValue)
514+
keys = classItems.keys
515+
this.getSize = classItems.keysLength
500516
501517
} else {
502518
// show regular enumerable properties only
@@ -523,6 +539,11 @@ export default {
523539
case this.isArray:
524540
this.getSize = this.modelValue.length
525541
return [...Array(this.modelValue.length).keys()]
542+
case this.isClass:
543+
const classItems = this.makeClassItems(this.modelValue)
544+
keys = classItems.keys
545+
this.getSize = classItems.keysLength
546+
return keys
526547
default:
527548
return this.modelValue
528549
}
@@ -625,18 +646,18 @@ export default {
625646
return this.isObject ? 'vue-dd-obj-char' : 'vue-dd-arr-char'
626647
},
627648
charOpen () {
628-
return this.isObject ? "{" : "["
649+
return this.isArray ? "[" : "{"
629650
},
630651
charClose () {
631-
return this.isObject ? "}" : "]"
652+
return this.isArray ? "]" : "}"
632653
},
633654
functionInlinePreview () {
634-
const length = this.items.toString().length
655+
const f = this.items.toString()
635656
const maxLength = 100
636-
if (length > maxLength) {
637-
return this.items.toString().substring(0, maxLength) + '...}'
657+
if (f.length > maxLength) {
658+
return f.substring(0, maxLength) + '...}'
638659
} else {
639-
return this.items.toString()
660+
return f
640661
}
641662
},
642663
functionInline () {
@@ -720,7 +741,7 @@ export default {
720741
return this.isRef || this.isReactive
721742
},
722743
isIterable () {
723-
return this.isArray || this.isObject
744+
return this.isArray || this.isObject || this.isClass
724745
},
725746
isArray () {
726747
return this.type === 'array'
@@ -731,6 +752,9 @@ export default {
731752
isFunction () {
732753
return this.type === 'function'
733754
},
755+
isClass () {
756+
return this.type === 'class'
757+
},
734758
isPromise () {
735759
return isPromise(this.modelValue)
736760
},
@@ -767,7 +791,7 @@ export default {
767791
// make reactive to startClose prop change
768792
startClosed () {
769793
if (this.level === 0) {
770-
console.log('start closed changed to', !this.startClosed)
794+
// console.log('start closed changed to', !this.startClosed)
771795
this.setOpen(!this.startClosed, { user: false })
772796
}
773797
},
@@ -893,7 +917,6 @@ export default {
893917
this.useOpenSpecific = this.openSpecific
894918
}
895919
},
896-
// expose: ['$options', 'open', 'toggle', 'close', 'isOpen'],
897920
components: {
898921
NodePrimitive
899922
}

vue-dd/src/VueDd.vue

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ export default defineComponent({
316316
317317
} else {
318318
319-
// console.log('this.useOpenSpecific', oldFocus, this.useOpenSpecific, this.openSpecific)
319+
// console.log('this.useOpenSpecific', oldFocus, this.useOpenSpecific, this.openSpecific)
320320
if (this.openSpecific.indexOf(oldFocus) === -1){
321321
const index = this.useOpenSpecific.indexOf(oldFocus);
322322
if (index > -1) { // only splice array when item is found
@@ -464,10 +464,15 @@ export default defineComponent({
464464
_type = 'longtext'
465465
}
466466
}
467+
if (_type === 'function') {
468+
if (this.getAllProperties && value.toString()[0] === 'c') {
469+
_type = 'class'
470+
}
471+
}
467472
return _type;
468473
},
469474
isPrimitiveFn (type) {
470-
return !(type === 'array' || type === 'object' || type === 'function' || type === 'longtext');
475+
return !(type === 'array' || type === 'object' || type === 'function' || type === 'longtext' || type === 'class');
471476
},
472477
escapeQuotesFn (text) {
473478
return this.escapeQuotes ? text.replaceAll('"', '\\"') : text
@@ -539,10 +544,7 @@ export default defineComponent({
539544
},
540545
toggle() {
541546
this.$refs.nodeComplex.toggle()
542-
},
543-
// isOpen() {
544-
// return this.$refs.nodeComplex.isOpen
545-
// }
547+
}
546548
},
547549
watch: {
548550
modelValue: {
@@ -561,7 +563,6 @@ export default defineComponent({
561563
this.useOpenSpecific = this.getOpenSpecific()
562564
}
563565
},
564-
// expose: ['$options', 'open', 'toggle', 'close', 'isOpen', 'root'],
565566
components: {
566567
NodeComplex,
567568
NodePrimitive

0 commit comments

Comments
 (0)