renusify 2.0.4 → 2.0.6
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/components/form/json/index.vue +2 -2
- package/components/form/text-editor/preview.vue +14 -13
- package/components/form/text-editor/style.scss +4 -2
- package/components/index.js +2 -1
- package/components/nestable/NestableItem.vue +163 -0
- package/components/nestable/editable.js +44 -0
- package/components/nestable/index.vue +109 -0
- package/components/nestable/methods.js +397 -0
- package/components/table/index.vue +10 -17
- package/package.json +1 -1
|
@@ -258,8 +258,8 @@ export default {
|
|
|
258
258
|
textarea {
|
|
259
259
|
&::selection {
|
|
260
260
|
background-color: var(--color-one);
|
|
261
|
-
-webkit-text-fill-color: var(--color-one
|
|
262
|
-
color: var(--color-one
|
|
261
|
+
-webkit-text-fill-color: var(--color-on-one);
|
|
262
|
+
color: var(--color-on-one);
|
|
263
263
|
}
|
|
264
264
|
|
|
265
265
|
padding: 12px;
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div ref="editorPreview" :class="`${$r.prefix}text-editor
|
|
2
|
+
<div ref="editorPreview" :class="`${$r.prefix}text-editor text-editor-preview`"
|
|
3
|
+
v-html="$helper.cleanXss(text)"></div>
|
|
3
4
|
</template>
|
|
4
5
|
|
|
5
6
|
<script>
|
|
6
|
-
|
|
7
|
+
import './style.scss'
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
export default {
|
|
10
|
+
name: "law",
|
|
11
|
+
props: {
|
|
12
|
+
text: String
|
|
13
|
+
},
|
|
14
|
+
data() {
|
|
15
|
+
return {
|
|
16
|
+
id: null,
|
|
17
|
+
imgs: []
|
|
18
|
+
}
|
|
19
|
+
},
|
|
19
20
|
mounted() {
|
|
20
21
|
this.id=setTimeout(() => {
|
|
21
22
|
this.imgs = this.$refs.editorPreview.querySelectorAll('img')
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
@import '../../../style/include';
|
|
2
2
|
|
|
3
3
|
.#{$prefix}text-editor {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
&:not(.text-editor-preview) {
|
|
5
|
+
background-color: var(--color-sheet-container);
|
|
6
|
+
margin-top: 20px;
|
|
7
|
+
}
|
|
6
8
|
|
|
7
9
|
&.input-tile {
|
|
8
10
|
border-radius: map-get($borders, 'sm');
|
package/components/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const list = {
|
|
2
2
|
'r-app': {'p': 'app/index.vue', 'c': ['r-btn', 'r-icon', 'r-spacer'], 'd': []},
|
|
3
|
-
'r-notify': {'p': 'notify/index.vue', 'c': ['r-btn', 'r-icon'], 'd': []},
|
|
4
3
|
'r-avatar': {'p': 'avatar/index.vue', 'c': ['r-btn', 'r-icon'], 'd': []},
|
|
5
4
|
'r-toolbar': {
|
|
6
5
|
'p': 'bar/toolbar/index.vue',
|
|
@@ -140,6 +139,8 @@ const list = {
|
|
|
140
139
|
'r-message': {'p': 'message/index.vue', 'c': ['r-container', 'r-row', 'r-col'], 'd': []},
|
|
141
140
|
'r-meta': {'p': 'meta/index.js', 'c': [], 'd': []},
|
|
142
141
|
'r-modal': {'p': 'modal/index.vue', 'c': ['r-btn', 'r-icon'], 'd': []},
|
|
142
|
+
'r-nestable': {'p': 'nestable/index.vue', 'c': [], 'd': []},
|
|
143
|
+
'r-notify': {'p': 'notify/index.vue', 'c': ['r-btn', 'r-icon'], 'd': []},
|
|
143
144
|
'r-progress-circle': {'p': 'progress/circle.vue', 'c': [], 'd': []},
|
|
144
145
|
'r-progress-line': {'p': 'progress/line.vue', 'c': [], 'd': []},
|
|
145
146
|
'r-search-box': {
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
:class="itemClasses"
|
|
4
|
+
class="nestable-handle"
|
|
5
|
+
draggable="true"
|
|
6
|
+
@dragstart="dragstart"
|
|
7
|
+
@touchend="touchend"
|
|
8
|
+
@touchmove="touchmove"
|
|
9
|
+
@touchstart="dragstart"
|
|
10
|
+
>
|
|
11
|
+
<div
|
|
12
|
+
class="nestable-item-content"
|
|
13
|
+
@mouseenter="onMouseEnter"
|
|
14
|
+
@mouseleave="onMouseLeave"
|
|
15
|
+
@mousemove="onMouseMove"
|
|
16
|
+
>
|
|
17
|
+
<r-btn-confirm
|
|
18
|
+
v-if="editable"
|
|
19
|
+
class="color-error-text"
|
|
20
|
+
icon
|
|
21
|
+
text
|
|
22
|
+
@click="del(item)"
|
|
23
|
+
>
|
|
24
|
+
<r-icon v-html="$r.icons.delete"></r-icon>
|
|
25
|
+
</r-btn-confirm>
|
|
26
|
+
<slot :item="item"></slot>
|
|
27
|
+
</div>
|
|
28
|
+
|
|
29
|
+
<div v-if="hasChildren" class="nestable-list ms-5">
|
|
30
|
+
<template
|
|
31
|
+
v-for="(child, childIndex) in item[childrenProp]"
|
|
32
|
+
:key="childIndex"
|
|
33
|
+
>
|
|
34
|
+
<NestableItem
|
|
35
|
+
:childrenProp="childrenProp"
|
|
36
|
+
:dragItem="dragItem"
|
|
37
|
+
:index="childIndex"
|
|
38
|
+
:item="child"
|
|
39
|
+
:key-prop="keyProp"
|
|
40
|
+
is-child
|
|
41
|
+
@delete="$emit('delete', $event)"
|
|
42
|
+
@drag-start="$emit('drag-start', $event)"
|
|
43
|
+
@touch-move="$emit('touch-move', $event)"
|
|
44
|
+
@mouse-enter="$emit('mouse-enter', $event)"
|
|
45
|
+
@drag-end="$emit('drag-end', $event)"
|
|
46
|
+
>
|
|
47
|
+
<template v-slot="{ item }">
|
|
48
|
+
<r-btn-confirm
|
|
49
|
+
v-if="editable"
|
|
50
|
+
class="color-error-text"
|
|
51
|
+
icon
|
|
52
|
+
text
|
|
53
|
+
@click="del(item)"
|
|
54
|
+
>
|
|
55
|
+
<r-icon v-html="$r.icons.delete"></r-icon>
|
|
56
|
+
</r-btn-confirm>
|
|
57
|
+
<slot :item="item" itemscope></slot>
|
|
58
|
+
</template>
|
|
59
|
+
</NestableItem>
|
|
60
|
+
</template>
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
</template>
|
|
64
|
+
|
|
65
|
+
<script>
|
|
66
|
+
export default {
|
|
67
|
+
name: "NestableItem",
|
|
68
|
+
props: {
|
|
69
|
+
editable: Boolean,
|
|
70
|
+
keyProp: String,
|
|
71
|
+
item: {
|
|
72
|
+
type: Object,
|
|
73
|
+
required: true,
|
|
74
|
+
default: () => ({}),
|
|
75
|
+
},
|
|
76
|
+
index: {
|
|
77
|
+
type: Number,
|
|
78
|
+
required: false,
|
|
79
|
+
default: null,
|
|
80
|
+
},
|
|
81
|
+
isChild: {
|
|
82
|
+
type: Boolean,
|
|
83
|
+
required: false,
|
|
84
|
+
default: false,
|
|
85
|
+
},
|
|
86
|
+
childrenProp: String,
|
|
87
|
+
dragItem: Object,
|
|
88
|
+
},
|
|
89
|
+
data() {
|
|
90
|
+
return {
|
|
91
|
+
breakPoint: null,
|
|
92
|
+
moveDown: false,
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
computed: {
|
|
97
|
+
isDragging() {
|
|
98
|
+
return (
|
|
99
|
+
this.dragItem && this.dragItem[this.keyProp] === this.item[this.keyProp]
|
|
100
|
+
);
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
hasChildren() {
|
|
104
|
+
return (
|
|
105
|
+
this.item[this.childrenProp] && this.item[this.childrenProp].length > 0
|
|
106
|
+
);
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
itemClasses() {
|
|
110
|
+
const isDragging = this.isDragging ? ["is-dragging"] : [];
|
|
111
|
+
|
|
112
|
+
return [
|
|
113
|
+
"nestable-item",
|
|
114
|
+
`nestable-item-${this.item[this.keyProp]}`,
|
|
115
|
+
...isDragging,
|
|
116
|
+
];
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
methods: {
|
|
121
|
+
del(item) {
|
|
122
|
+
this.$emit("delete", item);
|
|
123
|
+
},
|
|
124
|
+
dragstart(event) {
|
|
125
|
+
this.$emit("drag-start", [event, this.item]);
|
|
126
|
+
},
|
|
127
|
+
touchend(event) {
|
|
128
|
+
this.$emit("drag-end", event);
|
|
129
|
+
},
|
|
130
|
+
touchmove(event) {
|
|
131
|
+
this.$emit("touch-move", event);
|
|
132
|
+
},
|
|
133
|
+
onMouseEnter(event) {
|
|
134
|
+
if (!this.dragItem) return;
|
|
135
|
+
|
|
136
|
+
if (!event.movementY) {
|
|
137
|
+
return this.sendNotification(event);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
this.moveDown = event.movementY > 0;
|
|
141
|
+
|
|
142
|
+
this.breakPoint = event.target.getBoundingClientRect().height / 2;
|
|
143
|
+
},
|
|
144
|
+
onMouseLeave() {
|
|
145
|
+
this.breakPoint = null;
|
|
146
|
+
},
|
|
147
|
+
onMouseMove(event) {
|
|
148
|
+
if (!this.breakPoint) return;
|
|
149
|
+
|
|
150
|
+
const delta = event.offsetY - this.breakPoint;
|
|
151
|
+
|
|
152
|
+
if (this.moveDown && delta < this.breakPoint / 4) return;
|
|
153
|
+
if (!this.moveDown && delta > -this.breakPoint / 4) return;
|
|
154
|
+
|
|
155
|
+
this.sendNotification(event);
|
|
156
|
+
},
|
|
157
|
+
sendNotification(event) {
|
|
158
|
+
this.breakPoint = null;
|
|
159
|
+
this.$emit("mouse-enter", [event, this.item]);
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
</script>
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
data() {
|
|
3
|
+
return {
|
|
4
|
+
name: null,
|
|
5
|
+
};
|
|
6
|
+
},
|
|
7
|
+
methods: {
|
|
8
|
+
lastId(list) {
|
|
9
|
+
let r = 0;
|
|
10
|
+
list.map((item) => {
|
|
11
|
+
if (typeof item.id === "number" && item.id > r) {
|
|
12
|
+
r = item.id;
|
|
13
|
+
}
|
|
14
|
+
let d = this.lastId(item[this.childrenProp]);
|
|
15
|
+
if (d > r) {
|
|
16
|
+
r = d;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return r;
|
|
20
|
+
},
|
|
21
|
+
add() {
|
|
22
|
+
let items = this.modelValue;
|
|
23
|
+
items.push({
|
|
24
|
+
title: this.name,
|
|
25
|
+
[this.keyProp]: this.lastId(items) + 1,
|
|
26
|
+
[this.childrenProp]: [],
|
|
27
|
+
});
|
|
28
|
+
this.$emit("update:model-value", items);
|
|
29
|
+
this.name = null;
|
|
30
|
+
},
|
|
31
|
+
del(item) {
|
|
32
|
+
const removePath = this.getSplicePath(
|
|
33
|
+
this.getPathById(item[this.keyProp]),
|
|
34
|
+
{
|
|
35
|
+
numToRemove: 1,
|
|
36
|
+
childrenProp: this.childrenProp,
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
let items = this.modelValue;
|
|
40
|
+
items = this.update(items, removePath);
|
|
41
|
+
this.$emit("update:model-value", items);
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div ref="nestable" :class="`${$r.prefix}nestable`">
|
|
3
|
+
<div class="nestable-list nestable-group">
|
|
4
|
+
<template v-for="(item, index) in modelValue" :key="index">
|
|
5
|
+
<nestable-item
|
|
6
|
+
:childrenProp="childrenProp"
|
|
7
|
+
:dragItem="dragItem"
|
|
8
|
+
:editable="editable"
|
|
9
|
+
:index="index"
|
|
10
|
+
:item="item"
|
|
11
|
+
:keyProp="keyProp"
|
|
12
|
+
@delete="del"
|
|
13
|
+
@drag-start="dragstart"
|
|
14
|
+
@touch-move="touchmove"
|
|
15
|
+
@mouse-enter="mouseenter"
|
|
16
|
+
@drag-end="onDragEnd"
|
|
17
|
+
>
|
|
18
|
+
<template v-slot="{ item }">
|
|
19
|
+
<slot :item="item">{{ item }}</slot>
|
|
20
|
+
</template>
|
|
21
|
+
</nestable-item>
|
|
22
|
+
</template>
|
|
23
|
+
</div>
|
|
24
|
+
<div v-if="editable" class="d-flex v-end w-full">
|
|
25
|
+
<div class="pe-1 flex-grow-1">
|
|
26
|
+
<r-text-input v-model="name" :label="labelInput"></r-text-input>
|
|
27
|
+
</div>
|
|
28
|
+
<r-btn :disabled="!name" class="color-success" icon @click="add">
|
|
29
|
+
<r-icon v-html="$r.icons.plus"></r-icon>
|
|
30
|
+
</r-btn>
|
|
31
|
+
</div>
|
|
32
|
+
</div>
|
|
33
|
+
</template>
|
|
34
|
+
|
|
35
|
+
<script>
|
|
36
|
+
import NestableItem from "./NestableItem.vue";
|
|
37
|
+
import methods from "./methods";
|
|
38
|
+
import editable from "./editable";
|
|
39
|
+
|
|
40
|
+
export default {
|
|
41
|
+
name: "r-nestable",
|
|
42
|
+
components: {
|
|
43
|
+
NestableItem,
|
|
44
|
+
},
|
|
45
|
+
mixins: [methods, editable],
|
|
46
|
+
props: {
|
|
47
|
+
labelInput: String,
|
|
48
|
+
editable: Boolean,
|
|
49
|
+
modelValue: {
|
|
50
|
+
type: Array,
|
|
51
|
+
default: () => [],
|
|
52
|
+
},
|
|
53
|
+
threshold: {
|
|
54
|
+
type: Number,
|
|
55
|
+
default: 30,
|
|
56
|
+
},
|
|
57
|
+
maxDepth: {
|
|
58
|
+
type: Number,
|
|
59
|
+
default: 7,
|
|
60
|
+
},
|
|
61
|
+
keyProp: {
|
|
62
|
+
type: String,
|
|
63
|
+
default: "id",
|
|
64
|
+
},
|
|
65
|
+
childrenProp: {
|
|
66
|
+
type: String,
|
|
67
|
+
default: "children",
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
data() {
|
|
71
|
+
return {
|
|
72
|
+
itemsOld: null,
|
|
73
|
+
dragItem: null,
|
|
74
|
+
mouse: {
|
|
75
|
+
last: {x: 0},
|
|
76
|
+
shift: {x: 0},
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
mounted() {
|
|
81
|
+
const items = this.listAddChildren(this.modelValue, this.childrenProp);
|
|
82
|
+
this.$emit("update:model-value", items);
|
|
83
|
+
},
|
|
84
|
+
beforeUnmount() {
|
|
85
|
+
this.stopTrackMouse();
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
</script>
|
|
89
|
+
<style lang="scss">
|
|
90
|
+
@import "~renusify/style/include";
|
|
91
|
+
|
|
92
|
+
.#{$prefix}nestable {
|
|
93
|
+
.nestable-handle {
|
|
94
|
+
cursor: grab;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.is-dragging {
|
|
98
|
+
cursor: grabbing !important;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.nestable-drag-item {
|
|
102
|
+
display: none;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.nestable-item-content {
|
|
106
|
+
display: flex;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
</style>
|
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
methods: {
|
|
3
|
+
listAddChildren(list, childrenProp) {
|
|
4
|
+
return list.map((item) => {
|
|
5
|
+
return {
|
|
6
|
+
...item,
|
|
7
|
+
[childrenProp]: item[childrenProp]
|
|
8
|
+
? this.listAddChildren(item[childrenProp], childrenProp)
|
|
9
|
+
: [],
|
|
10
|
+
};
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
mouseenter(e) {
|
|
14
|
+
this.onMouseEnter(e[0], e[1]);
|
|
15
|
+
},
|
|
16
|
+
touchmove(e) {
|
|
17
|
+
this.onMouseMove(e);
|
|
18
|
+
},
|
|
19
|
+
dragstart(e) {
|
|
20
|
+
this.onDragStart(e[0], e[1]);
|
|
21
|
+
},
|
|
22
|
+
startTrackMouse() {
|
|
23
|
+
document.addEventListener("mousemove", this.onMouseMove);
|
|
24
|
+
document.addEventListener("mouseup", this.onDragEnd);
|
|
25
|
+
document.addEventListener("touchend", this.onDragEnd);
|
|
26
|
+
document.addEventListener("touchcancel", this.onDragEnd);
|
|
27
|
+
document.addEventListener("keydown", this.onKeyDown);
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
stopTrackMouse() {
|
|
31
|
+
document.removeEventListener("mousemove", this.onMouseMove);
|
|
32
|
+
document.removeEventListener("mouseup", this.onDragEnd);
|
|
33
|
+
document.removeEventListener("touchend", this.onDragEnd);
|
|
34
|
+
document.removeEventListener("touchcancel", this.onDragEnd);
|
|
35
|
+
document.removeEventListener("keydown", this.onKeyDown);
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
onDragStart(event, item) {
|
|
39
|
+
if (event) {
|
|
40
|
+
event.preventDefault();
|
|
41
|
+
event.stopPropagation();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
this.startTrackMouse();
|
|
45
|
+
|
|
46
|
+
this.dragItem = item;
|
|
47
|
+
this.itemsOld = this.modelValue;
|
|
48
|
+
|
|
49
|
+
this.$nextTick(() => {
|
|
50
|
+
this.onMouseMove(event);
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
onDragEnd(event, isCancel) {
|
|
55
|
+
event && event.preventDefault();
|
|
56
|
+
|
|
57
|
+
this.stopTrackMouse();
|
|
58
|
+
|
|
59
|
+
isCancel ? this.dragRevert() : this.dragApply();
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
onKeyDown(event) {
|
|
63
|
+
if (event.which === 27) {
|
|
64
|
+
// ESC
|
|
65
|
+
this.onDragEnd(null, true);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
getXandYFromEvent(event) {
|
|
70
|
+
let {clientX, clientY} = event;
|
|
71
|
+
|
|
72
|
+
const {targetTouches} = event;
|
|
73
|
+
|
|
74
|
+
if (targetTouches) {
|
|
75
|
+
const touch = targetTouches[0];
|
|
76
|
+
clientX = touch.clientX;
|
|
77
|
+
clientY = touch.clientY;
|
|
78
|
+
const event = new Event("mouseenter");
|
|
79
|
+
const element = document.elementFromPoint(clientX, clientY);
|
|
80
|
+
const touchElement =
|
|
81
|
+
element && element.closest(".nestable-item-content");
|
|
82
|
+
if (touchElement) touchElement.dispatchEvent(event);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {clientX, clientY};
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
onMouseMove(event) {
|
|
89
|
+
event && event.preventDefault();
|
|
90
|
+
|
|
91
|
+
const {clientX} = this.getXandYFromEvent(event);
|
|
92
|
+
|
|
93
|
+
if (this.mouse.last.x === 0) {
|
|
94
|
+
this.mouse.last.x = clientX;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const diffX = this.$r.rtl
|
|
98
|
+
? this.mouse.last.x - clientX
|
|
99
|
+
: clientX - this.mouse.last.x;
|
|
100
|
+
if (
|
|
101
|
+
(diffX >= 0 && this.mouse.shift.x >= 0) ||
|
|
102
|
+
(diffX <= 0 && this.mouse.shift.x <= 0)
|
|
103
|
+
) {
|
|
104
|
+
this.mouse.shift.x += diffX;
|
|
105
|
+
} else {
|
|
106
|
+
this.mouse.shift.x = 0;
|
|
107
|
+
}
|
|
108
|
+
this.mouse.last.x = clientX;
|
|
109
|
+
|
|
110
|
+
if (Math.abs(this.mouse.shift.x) > this.threshold) {
|
|
111
|
+
if (this.mouse.shift.x > 0) {
|
|
112
|
+
this.tryIncreaseDepth(this.dragItem);
|
|
113
|
+
} else {
|
|
114
|
+
this.tryDecreaseDepth(this.dragItem);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
this.mouse.shift.x = 0;
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
moveItem({dragItem, pathFrom, pathTo}) {
|
|
122
|
+
const realPathTo = this.getRealNextPath(pathFrom, pathTo);
|
|
123
|
+
|
|
124
|
+
const removePath = this.getSplicePath(pathFrom, {
|
|
125
|
+
numToRemove: 1,
|
|
126
|
+
childrenProp: this.childrenProp,
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const insertPath = this.getSplicePath(realPathTo, {
|
|
130
|
+
numToRemove: 0,
|
|
131
|
+
itemsToInsert: [dragItem],
|
|
132
|
+
childrenProp: this.childrenProp,
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
let items = this.modelValue;
|
|
136
|
+
items = this.update(items, removePath);
|
|
137
|
+
items = this.update(items, insertPath);
|
|
138
|
+
|
|
139
|
+
this.pathTo = realPathTo;
|
|
140
|
+
this.$emit("update:model-value", items);
|
|
141
|
+
},
|
|
142
|
+
isEquals(x, y) {
|
|
143
|
+
return x === y;
|
|
144
|
+
},
|
|
145
|
+
copy(o) {
|
|
146
|
+
return JSON.parse(JSON.stringify(o));
|
|
147
|
+
},
|
|
148
|
+
update(object, $spec) {
|
|
149
|
+
if (!object) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const that = this;
|
|
153
|
+
const commands = {
|
|
154
|
+
$splice(value, nextObject, spec, originalObject) {
|
|
155
|
+
value.forEach((args) => {
|
|
156
|
+
if (nextObject === originalObject && args.length) {
|
|
157
|
+
nextObject = that.copy(originalObject);
|
|
158
|
+
}
|
|
159
|
+
Array.prototype.splice.apply(nextObject, args);
|
|
160
|
+
});
|
|
161
|
+
return nextObject;
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
const spec = typeof $spec === "function" ? {$apply: $spec} : $spec;
|
|
165
|
+
let nextObject = object;
|
|
166
|
+
Object.keys(spec).forEach((key) => {
|
|
167
|
+
if (commands[key]) {
|
|
168
|
+
const objectWasNextObject = object === nextObject;
|
|
169
|
+
nextObject = commands[key](spec[key], nextObject, spec, object);
|
|
170
|
+
if (objectWasNextObject && this.isEquals(nextObject, object)) {
|
|
171
|
+
nextObject = object;
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
const nextValueForKey = this.update(object[key], spec[key]);
|
|
175
|
+
const nextObjectValue = nextObject[key];
|
|
176
|
+
if (
|
|
177
|
+
!this.isEquals(nextValueForKey, nextObjectValue) ||
|
|
178
|
+
(typeof nextValueForKey === "undefined" && !object[key])
|
|
179
|
+
) {
|
|
180
|
+
if (nextObject === object) {
|
|
181
|
+
nextObject = this.copy(object);
|
|
182
|
+
}
|
|
183
|
+
nextObject[key] = nextValueForKey;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
return nextObject;
|
|
188
|
+
},
|
|
189
|
+
tryIncreaseDepth(dragItem) {
|
|
190
|
+
let pathFrom;
|
|
191
|
+
try {
|
|
192
|
+
pathFrom = this.getPathById(dragItem[this.keyProp]);
|
|
193
|
+
} catch (e) {
|
|
194
|
+
this.dragRevert();
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const itemIndex = pathFrom[pathFrom.length - 1];
|
|
198
|
+
const newDepth = pathFrom.length + this.getItemDepth(dragItem);
|
|
199
|
+
if (itemIndex > 0 && newDepth <= this.maxDepth) {
|
|
200
|
+
const prevSibling = this.getItemByPath(
|
|
201
|
+
pathFrom.slice(0, -1).concat(itemIndex - 1)
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
if (
|
|
205
|
+
prevSibling[this.childrenProp] &&
|
|
206
|
+
(!prevSibling[this.childrenProp].length || true)
|
|
207
|
+
) {
|
|
208
|
+
const pathTo = pathFrom
|
|
209
|
+
.slice(0, -1)
|
|
210
|
+
.concat(itemIndex - 1)
|
|
211
|
+
.concat(prevSibling[this.childrenProp].length);
|
|
212
|
+
|
|
213
|
+
this.moveItem({dragItem, pathFrom, pathTo});
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
|
|
218
|
+
tryDecreaseDepth(dragItem) {
|
|
219
|
+
let pathFrom;
|
|
220
|
+
try {
|
|
221
|
+
pathFrom = this.getPathById(dragItem[this.keyProp]);
|
|
222
|
+
} catch (e) {
|
|
223
|
+
this.dragRevert();
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
const itemIndex = pathFrom[pathFrom.length - 1];
|
|
227
|
+
|
|
228
|
+
if (pathFrom.length > 1) {
|
|
229
|
+
const parent = this.getItemByPath(pathFrom.slice(0, -1));
|
|
230
|
+
|
|
231
|
+
if (itemIndex + 1 === parent[this.childrenProp].length) {
|
|
232
|
+
const pathTo = pathFrom.slice(0, -1);
|
|
233
|
+
pathTo[pathTo.length - 1] += 1;
|
|
234
|
+
|
|
235
|
+
this.moveItem({dragItem, pathFrom, pathTo});
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
|
|
240
|
+
onMouseEnter(event, item) {
|
|
241
|
+
if (event) {
|
|
242
|
+
event.preventDefault();
|
|
243
|
+
event.stopPropagation();
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (!this.dragItem) return;
|
|
247
|
+
|
|
248
|
+
if (item !== null && this.dragItem[this.keyProp] === item[this.keyProp])
|
|
249
|
+
return;
|
|
250
|
+
let pathFrom;
|
|
251
|
+
try {
|
|
252
|
+
pathFrom = this.getPathById(this.dragItem[this.keyProp]);
|
|
253
|
+
} catch (e) {
|
|
254
|
+
this.dragRevert();
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (pathFrom.length === 0) return;
|
|
259
|
+
|
|
260
|
+
let pathTo = null;
|
|
261
|
+
if (item === null) {
|
|
262
|
+
pathTo = pathFrom.length > 0 ? [] : [0];
|
|
263
|
+
} else {
|
|
264
|
+
pathTo = this.getPathById(item[this.keyProp]);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const newDepth =
|
|
268
|
+
this.getRealNextPath(pathFrom, pathTo).length +
|
|
269
|
+
(this.getItemDepth(this.dragItem) - 1);
|
|
270
|
+
if (newDepth > this.maxDepth) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
this.moveItem({dragItem: this.dragItem, pathFrom, pathTo});
|
|
275
|
+
},
|
|
276
|
+
|
|
277
|
+
dragApply() {
|
|
278
|
+
this.$emit("change", this.dragItem, {
|
|
279
|
+
items: this.modelValue,
|
|
280
|
+
pathTo: this.pathTo,
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
this.pathTo = null;
|
|
284
|
+
this.itemsOld = null;
|
|
285
|
+
this.dragItem = null;
|
|
286
|
+
},
|
|
287
|
+
|
|
288
|
+
dragRevert() {
|
|
289
|
+
if (this.itemsOld) {
|
|
290
|
+
this.$emit("update:model-value", this.itemsOld);
|
|
291
|
+
}
|
|
292
|
+
this.pathTo = null;
|
|
293
|
+
this.itemsOld = null;
|
|
294
|
+
this.dragItem = null;
|
|
295
|
+
},
|
|
296
|
+
getPathById(id, items = this.modelValue) {
|
|
297
|
+
let path = [];
|
|
298
|
+
items.every((item, i) => {
|
|
299
|
+
if (item[this.keyProp] === id) {
|
|
300
|
+
path.push(i);
|
|
301
|
+
} else if (item[this.childrenProp]) {
|
|
302
|
+
const childrenPath = this.getPathById(id, item[this.childrenProp]);
|
|
303
|
+
|
|
304
|
+
if (childrenPath.length) {
|
|
305
|
+
path = path.concat(i).concat(childrenPath);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return path.length === 0;
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
return path;
|
|
313
|
+
},
|
|
314
|
+
|
|
315
|
+
getItemByPath(path, items = this.modelValue) {
|
|
316
|
+
let item = null;
|
|
317
|
+
|
|
318
|
+
path.forEach((index) => {
|
|
319
|
+
const list =
|
|
320
|
+
item && item[this.childrenProp] ? item[this.childrenProp] : items;
|
|
321
|
+
item = list[index];
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
return item;
|
|
325
|
+
},
|
|
326
|
+
|
|
327
|
+
getItemDepth(item) {
|
|
328
|
+
let level = 1;
|
|
329
|
+
|
|
330
|
+
if (item[this.childrenProp] && item[this.childrenProp].length > 0) {
|
|
331
|
+
const childrenDepths = item[this.childrenProp].map(this.getItemDepth);
|
|
332
|
+
level += Math.max(...childrenDepths);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return level;
|
|
336
|
+
},
|
|
337
|
+
|
|
338
|
+
getSplicePath(path, options = {}) {
|
|
339
|
+
const splicePath = {};
|
|
340
|
+
const numToRemove = options.numToRemove || 0;
|
|
341
|
+
const itemsToInsert = options.itemsToInsert || [];
|
|
342
|
+
const lastIndex = path.length - 1;
|
|
343
|
+
let currentPath = splicePath;
|
|
344
|
+
|
|
345
|
+
path.forEach((index, i) => {
|
|
346
|
+
if (i === lastIndex) {
|
|
347
|
+
currentPath.$splice = [[index, numToRemove, ...itemsToInsert]];
|
|
348
|
+
} else {
|
|
349
|
+
const nextPath = {};
|
|
350
|
+
currentPath[index] = {[options.childrenProp]: nextPath};
|
|
351
|
+
currentPath = nextPath;
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
return splicePath;
|
|
356
|
+
},
|
|
357
|
+
|
|
358
|
+
getRealNextPath(prevPath, nextPath) {
|
|
359
|
+
const ppLastIndex = prevPath.length - 1;
|
|
360
|
+
const npLastIndex = nextPath.length - 1;
|
|
361
|
+
|
|
362
|
+
if (prevPath.length < nextPath.length) {
|
|
363
|
+
let wasShifted = false;
|
|
364
|
+
|
|
365
|
+
return nextPath.map((nextIndex, i) => {
|
|
366
|
+
if (wasShifted) {
|
|
367
|
+
return i === npLastIndex ? nextIndex + 1 : nextIndex;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (typeof prevPath[i] !== "number") {
|
|
371
|
+
return nextIndex;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
if (nextPath[i] > prevPath[i] && i === ppLastIndex) {
|
|
375
|
+
wasShifted = true;
|
|
376
|
+
return nextIndex - 1;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
return nextIndex;
|
|
380
|
+
});
|
|
381
|
+
} else if (prevPath.length === nextPath.length) {
|
|
382
|
+
if (nextPath[npLastIndex] > prevPath[npLastIndex]) {
|
|
383
|
+
const target = this.getItemByPath(nextPath);
|
|
384
|
+
|
|
385
|
+
if (target[this.childrenProp] && target[this.childrenProp].length) {
|
|
386
|
+
return nextPath
|
|
387
|
+
.slice(0, -1)
|
|
388
|
+
.concat(nextPath[npLastIndex] - 1)
|
|
389
|
+
.concat(0);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
return nextPath;
|
|
395
|
+
},
|
|
396
|
+
},
|
|
397
|
+
};
|
|
@@ -71,34 +71,27 @@
|
|
|
71
71
|
</div>
|
|
72
72
|
</div>
|
|
73
73
|
<r-modal v-if="editable" v-model="showModal">
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
<div
|
|
75
|
+
v-sortable="{
|
|
76
76
|
items: cols,
|
|
77
77
|
end: store_db,
|
|
78
78
|
grab: '.drag-btn'
|
|
79
79
|
}"
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
:key="col.value+i"
|
|
84
|
-
class="no-gutters"
|
|
85
|
-
>
|
|
86
|
-
<r-col>
|
|
87
|
-
<r-card class="pa-4 ma-1 d-flex h-space-between" tile>
|
|
80
|
+
>
|
|
81
|
+
<r-card v-for="(col, i) in cols"
|
|
82
|
+
:key="i" class="pa-4 ma-1 d-flex h-space-between" tile>
|
|
88
83
|
<span class="title-1">
|
|
89
84
|
<r-btn class="drag-btn" icon text>
|
|
90
85
|
<r-icon v-html="$r.icons.drag"></r-icon>
|
|
91
86
|
</r-btn>
|
|
92
87
|
{{ col.text }}
|
|
93
88
|
</span>
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
89
|
+
<span>
|
|
90
|
+
<r-switch-input v-model="col.show" :label="$t('show','renusify')"
|
|
91
|
+
@update:model-value="store_db(cols)"></r-switch-input>
|
|
97
92
|
</span>
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
</r-row>
|
|
101
|
-
</r-container>
|
|
93
|
+
</r-card>
|
|
94
|
+
</div>
|
|
102
95
|
</r-modal>
|
|
103
96
|
</template>
|
|
104
97
|
|