goodteditor-ui 1.0.21 → 1.0.23
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/.eslintrc.js +7 -7
- package/.prettierrc +14 -14
- package/README.md +35 -35
- package/babel.config.js +5 -5
- package/index.js +53 -53
- package/jsconfig.json +13 -13
- package/package.json +66 -70
- package/src/App.vue +36 -36
- package/src/components/ui/Avatar.md +68 -68
- package/src/components/ui/Avatar.vue +180 -177
- package/src/components/ui/Badge.md +20 -20
- package/src/components/ui/Badge.vue +75 -75
- package/src/components/ui/Collapse.md +90 -90
- package/src/components/ui/Collapse.vue +86 -86
- package/src/components/ui/ColorPicker/Alpha.vue +114 -114
- package/src/components/ui/ColorPicker/Colors.vue +117 -117
- package/src/components/ui/ColorPicker/Hue.vue +113 -113
- package/src/components/ui/ColorPicker/Preview.vue +55 -55
- package/src/components/ui/ColorPicker/Saturation.vue +123 -123
- package/src/components/ui/ColorPicker/mixin.js +105 -105
- package/src/components/ui/ColorPicker.md +17 -17
- package/src/components/ui/ColorPicker.vue +314 -314
- package/src/components/ui/Datalist.md +41 -41
- package/src/components/ui/Datalist.vue +157 -157
- package/src/components/ui/DatePicker.md +168 -168
- package/src/components/ui/DatePicker.vue +527 -527
- package/src/components/ui/FileSelector.md +105 -105
- package/src/components/ui/FileSelector.vue +82 -82
- package/src/components/ui/Grid.md +130 -130
- package/src/components/ui/Grid.vue +92 -92
- package/src/components/ui/Image.md +59 -59
- package/src/components/ui/Image.vue +57 -57
- package/src/components/ui/InputAutocomplete.md +115 -115
- package/src/components/ui/InputAutocomplete.vue +341 -341
- package/src/components/ui/InputColorPicker.md +51 -51
- package/src/components/ui/InputColorPicker.vue +151 -151
- package/src/components/ui/InputDatePicker.md +121 -121
- package/src/components/ui/InputDatePicker.vue +326 -326
- package/src/components/ui/InputTags.md +51 -51
- package/src/components/ui/InputTags.vue +184 -184
- package/src/components/ui/InputTimePicker.md +25 -25
- package/src/components/ui/InputTimePicker.vue +253 -253
- package/src/components/ui/InputUnits.md +20 -20
- package/src/components/ui/InputUnits.vue +257 -257
- package/src/components/ui/Lazy.md +37 -37
- package/src/components/ui/Lazy.vue +92 -92
- package/src/components/ui/Pagination.md +74 -74
- package/src/components/ui/Pagination.vue +138 -138
- package/src/components/ui/Paginator.md +34 -34
- package/src/components/ui/Paginator.vue +83 -83
- package/src/components/ui/Popover.md +34 -34
- package/src/components/ui/Popover.vue +274 -274
- package/src/components/ui/Popup.md +59 -59
- package/src/components/ui/Popup.vue +150 -150
- package/src/components/ui/ResponsiveContainer.md +58 -58
- package/src/components/ui/ResponsiveContainer.vue +99 -99
- package/src/components/ui/Select.md +187 -187
- package/src/components/ui/Select.vue +421 -421
- package/src/components/ui/TimePicker.md +50 -50
- package/src/components/ui/TimePicker.vue +252 -252
- package/src/components/ui/Tooltip.md +54 -114
- package/src/components/ui/Tooltip.vue +113 -113
- package/src/components/ui/WysiwygEditor/WysiwygEditor.d.ts +119 -119
- package/src/components/ui/WysiwygEditor/constants.js +264 -264
- package/src/components/ui/WysiwygEditor/extensions/blockquote.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/bold.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/bullet-list.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/code-block.js +13 -13
- package/src/components/ui/WysiwygEditor/extensions/code.js +13 -13
- package/src/components/ui/WysiwygEditor/extensions/font-size.js +34 -34
- package/src/components/ui/WysiwygEditor/extensions/formatting.js +14 -14
- package/src/components/ui/WysiwygEditor/extensions/heading.js +13 -13
- package/src/components/ui/WysiwygEditor/extensions/horizontal-rule.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/image.js +19 -19
- package/src/components/ui/WysiwygEditor/extensions/index.d.ts +32 -32
- package/src/components/ui/WysiwygEditor/extensions/index.js +32 -32
- package/src/components/ui/WysiwygEditor/extensions/italic.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/link.js +16 -16
- package/src/components/ui/WysiwygEditor/extensions/list-item.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/ordered-list.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/paragraph.js +23 -23
- package/src/components/ui/WysiwygEditor/extensions/strike.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/table-cell.js +13 -13
- package/src/components/ui/WysiwygEditor/extensions/table-header.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/table-row.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/table.js +29 -29
- package/src/components/ui/WysiwygEditor/extensions/text-align.js +6 -6
- package/src/components/ui/WysiwygEditor/extensions/text-style.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/underline.js +15 -15
- package/src/components/ui/WysiwygEditor/index.d.ts +4 -4
- package/src/components/ui/WysiwygEditor/index.js +4 -4
- package/src/components/ui/WysiwygEditor/renders/Button.vue +28 -28
- package/src/components/ui/WysiwygEditor/renders/ColorPicker.vue +41 -41
- package/src/components/ui/WysiwygEditor/renders/InputAuto.vue +34 -34
- package/src/components/ui/WysiwygEditor/renders/InputBrowse.vue +35 -35
- package/src/components/ui/WysiwygEditor/renders/InputUnits.vue +38 -38
- package/src/components/ui/WysiwygEditor/renders/Link.vue +87 -87
- package/src/components/ui/WysiwygEditor/renders/Select.vue +47 -47
- package/src/components/ui/WysiwygEditor/renders/ToolbarPopover.vue +49 -49
- package/src/components/ui/WysiwygEditor/renders/index.d.ts +8 -8
- package/src/components/ui/WysiwygEditor/renders/index.js +8 -8
- package/src/components/ui/WysiwygEditor/renders/mixins/RenderMixin.js +39 -39
- package/src/components/ui/WysiwygEditor/renders/mixins/index.js +1 -1
- package/src/components/ui/WysiwygEditor/tools-and-commands.js +704 -704
- package/src/components/ui/WysiwygEditor/utils.js +72 -72
- package/src/components/ui/WysiwygEditor.md +18 -18
- package/src/components/ui/WysiwygEditor.vue +271 -271
- package/src/components/ui/utils/FormComponent.js +107 -107
- package/src/components/ui/utils/Helpers.js +84 -84
- package/src/components/ui/utils/WithPopover.js +81 -99
- package/src/main.js +8 -8
- package/styleguide.config.js +37 -37
- package/vue.config.js +8 -8
- package/dist/js.png +0 -0
|
@@ -1,274 +1,274 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<transition name="transition" appear>
|
|
3
|
-
<div :style="cssStyle" v-if="show" v-append-body>
|
|
4
|
-
<slot></slot>
|
|
5
|
-
</div>
|
|
6
|
-
</transition>
|
|
7
|
-
</template>
|
|
8
|
-
<style lang="less" scoped>
|
|
9
|
-
.transition {
|
|
10
|
-
&-enter,
|
|
11
|
-
&-leave-to {
|
|
12
|
-
opacity: 0;
|
|
13
|
-
}
|
|
14
|
-
&-enter-active,
|
|
15
|
-
&-leave-active {
|
|
16
|
-
transition: opacity 0.15s ease;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
</style>
|
|
20
|
-
<script>
|
|
21
|
-
import { createPopper } from '@popperjs/core';
|
|
22
|
-
import { Position, generateGetBoundingClientRect } from './utils/Helpers';
|
|
23
|
-
|
|
24
|
-
const isElem = el => el instanceof HTMLElement;
|
|
25
|
-
|
|
26
|
-
const isCoordinates = (target) => {
|
|
27
|
-
if (Array.isArray(target) === false) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
if (target.length !== 2) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
if (target.some((item) => Number.isNaN(Number(item)))) {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const Strategy = Object.freeze({
|
|
40
|
-
ABSOLUTE: 'absolute',
|
|
41
|
-
FIXED: 'fixed'
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const Modifier = Object.freeze({
|
|
45
|
-
FLIP: 'flip',
|
|
46
|
-
OFFSET: 'offset'
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
export default {
|
|
50
|
-
directives: {
|
|
51
|
-
'append-body': {
|
|
52
|
-
inserted(el, bindings, { context }) {
|
|
53
|
-
let { appendToBody } = context;
|
|
54
|
-
if (!appendToBody) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
const nt = context.$nextTick;
|
|
58
|
-
nt(() => nt(() => document.body.appendChild(el)));
|
|
59
|
-
},
|
|
60
|
-
unbind(el, bindings, { context }) {
|
|
61
|
-
el.parentNode && el.parentNode.removeChild(el);
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
props: {
|
|
66
|
-
/**
|
|
67
|
-
* Target HTMLElement|selector|array of coordinates used for positioning
|
|
68
|
-
*/
|
|
69
|
-
target: { default: null },
|
|
70
|
-
/**
|
|
71
|
-
* Whether to show popover
|
|
72
|
-
*/
|
|
73
|
-
show: { type: Boolean, default: false },
|
|
74
|
-
/**
|
|
75
|
-
* z-index
|
|
76
|
-
*/
|
|
77
|
-
zIndex: {
|
|
78
|
-
type: Number,
|
|
79
|
-
default: 1010,
|
|
80
|
-
},
|
|
81
|
-
/**
|
|
82
|
-
* Whether to append popover to body
|
|
83
|
-
*/
|
|
84
|
-
appendToBody: {
|
|
85
|
-
type: Boolean,
|
|
86
|
-
default: true,
|
|
87
|
-
},
|
|
88
|
-
/**
|
|
89
|
-
* Position, values of the popover:
|
|
90
|
-
* bl, br, tl, tr - bottom-left, bottom-right, top-left, top-right
|
|
91
|
-
* @values bl, br, tl, tr, top, top-start, top-end, left, left-start, left-end, right, right-start, right-end, bottom, bottom-start, bottom-end
|
|
92
|
-
*/
|
|
93
|
-
position: {
|
|
94
|
-
type: String,
|
|
95
|
-
default: `${Position.BOTTOM}-${Position.START}`,
|
|
96
|
-
},
|
|
97
|
-
/**
|
|
98
|
-
* Position offset [ x, y ] where:
|
|
99
|
-
* x - skidding (offset along target)
|
|
100
|
-
* y - distance (offset away from target)
|
|
101
|
-
*/
|
|
102
|
-
positionOffset: {
|
|
103
|
-
type: Array,
|
|
104
|
-
default() {
|
|
105
|
-
return [1, 1];
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
/**
|
|
109
|
-
* Whether to flip position if out of viewport
|
|
110
|
-
*/
|
|
111
|
-
positionFlip: {
|
|
112
|
-
type: Boolean,
|
|
113
|
-
default: true,
|
|
114
|
-
},
|
|
115
|
-
/**
|
|
116
|
-
* Auto width
|
|
117
|
-
*/
|
|
118
|
-
autoWidth: {
|
|
119
|
-
type: Boolean,
|
|
120
|
-
default: false,
|
|
121
|
-
},
|
|
122
|
-
/**
|
|
123
|
-
* Should respond to pointer events
|
|
124
|
-
*/
|
|
125
|
-
shouldRespondToPointerEvents: {
|
|
126
|
-
type: Boolean,
|
|
127
|
-
default: true
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
data() {
|
|
131
|
-
return { cssStyle: {} };
|
|
132
|
-
},
|
|
133
|
-
computed: {
|
|
134
|
-
placement() {
|
|
135
|
-
const { position } = this;
|
|
136
|
-
const map = { t: Position.TOP, l: Position.START, r: Position.END, b: Position.BOTTOM };
|
|
137
|
-
// t-b-l-r mode
|
|
138
|
-
if (position.length == 2) {
|
|
139
|
-
return position
|
|
140
|
-
.split('')
|
|
141
|
-
.map(k => map[k])
|
|
142
|
-
.filter(v => !!v)
|
|
143
|
-
.join('-');
|
|
144
|
-
}
|
|
145
|
-
return position;
|
|
146
|
-
},
|
|
147
|
-
options() {
|
|
148
|
-
const { appendToBody, placement, positionFlip, positionOffset } = this;
|
|
149
|
-
const strategy = appendToBody ? Strategy.FIXED : Strategy.ABSOLUTE;
|
|
150
|
-
const modifiers = [
|
|
151
|
-
{
|
|
152
|
-
name: Modifier.FLIP,
|
|
153
|
-
enabled: positionFlip,
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
name: Modifier.OFFSET,
|
|
157
|
-
options: {
|
|
158
|
-
offset: positionOffset,
|
|
159
|
-
},
|
|
160
|
-
},
|
|
161
|
-
]
|
|
162
|
-
return { placement, strategy, modifiers };
|
|
163
|
-
}
|
|
164
|
-
},
|
|
165
|
-
watch: {
|
|
166
|
-
show: {
|
|
167
|
-
handler(val) {
|
|
168
|
-
this.$nextTick(() => {
|
|
169
|
-
if (val === false) {
|
|
170
|
-
this.handleReset();
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (isCoordinates(this.target) === false) {
|
|
175
|
-
this.addEventListeners();
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
this.createPopper();
|
|
179
|
-
});
|
|
180
|
-
},
|
|
181
|
-
immediate: true,
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
created() {
|
|
185
|
-
this.popper = null;
|
|
186
|
-
},
|
|
187
|
-
destroyed() {
|
|
188
|
-
this.handleReset();
|
|
189
|
-
},
|
|
190
|
-
methods: {
|
|
191
|
-
addEventListeners() {
|
|
192
|
-
window.addEventListener('blur', this.onWinBlur);
|
|
193
|
-
document.addEventListener('mousedown', this.onDocMouseDown);
|
|
194
|
-
},
|
|
195
|
-
removeEventListeners() {
|
|
196
|
-
window.removeEventListener('blur', this.onWinBlur);
|
|
197
|
-
document.removeEventListener('mousedown', this.onDocMouseDown);
|
|
198
|
-
},
|
|
199
|
-
calcStyle() {
|
|
200
|
-
const { zIndex, autoWidth, shouldRespondToPointerEvents } = this;
|
|
201
|
-
const target = this.getTarget();
|
|
202
|
-
const style = { zIndex };
|
|
203
|
-
if (autoWidth && target) {
|
|
204
|
-
const b = target.getBoundingClientRect();
|
|
205
|
-
style.width = `${b.width}px`;
|
|
206
|
-
}
|
|
207
|
-
if (shouldRespondToPointerEvents === false) {
|
|
208
|
-
style.pointerEvents = 'none';
|
|
209
|
-
}
|
|
210
|
-
this.cssStyle = style;
|
|
211
|
-
},
|
|
212
|
-
getTarget() {
|
|
213
|
-
const { target } = this;
|
|
214
|
-
return isCoordinates(target) ? null : isElem(target) ? target : document.querySelector(target);
|
|
215
|
-
},
|
|
216
|
-
setShow(val) {
|
|
217
|
-
this.$nextTick(() => this.$emit('update:show', val));
|
|
218
|
-
},
|
|
219
|
-
createPopper() {
|
|
220
|
-
const { options, $el: popper } = this;
|
|
221
|
-
const target = this.getTarget();
|
|
222
|
-
|
|
223
|
-
if (target != null) {
|
|
224
|
-
this.popper = createPopper(target, popper, options);
|
|
225
|
-
this.$nextTick(this.updatePopper);
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
if (isCoordinates(this.target)) {
|
|
230
|
-
const [x, y] = this.target;
|
|
231
|
-
const virtualElem = {
|
|
232
|
-
getBoundingClientRect: generateGetBoundingClientRect(x, y),
|
|
233
|
-
};
|
|
234
|
-
this.popper = createPopper(virtualElem, popper, options);
|
|
235
|
-
this.$nextTick(this.updatePopper);
|
|
236
|
-
this.unwatchCursorCoordinates = this.$watch('target', ([x, y]) => {
|
|
237
|
-
virtualElem.getBoundingClientRect = generateGetBoundingClientRect(x, y);
|
|
238
|
-
this.popper?.update();
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
},
|
|
242
|
-
updatePopper() {
|
|
243
|
-
this.calcStyle();
|
|
244
|
-
this.popper.update();
|
|
245
|
-
},
|
|
246
|
-
destroyPopper() {
|
|
247
|
-
this.popper?.destroy();
|
|
248
|
-
this.popper = null;
|
|
249
|
-
},
|
|
250
|
-
handleReset() {
|
|
251
|
-
this.unwatchCursorCoordinates?.();
|
|
252
|
-
if (isCoordinates(this.target) === false) {
|
|
253
|
-
this.removeEventListeners();
|
|
254
|
-
}
|
|
255
|
-
this.destroyPopper();
|
|
256
|
-
},
|
|
257
|
-
onWinBlur(e) {
|
|
258
|
-
if (this.show) {
|
|
259
|
-
this.setShow(false);
|
|
260
|
-
}
|
|
261
|
-
},
|
|
262
|
-
onDocMouseDown(e) {
|
|
263
|
-
let target = this.getTarget();
|
|
264
|
-
let root = this.$el && isElem(this.$el) ? this.$el : null;
|
|
265
|
-
if ((root && root.contains(e.target)) || (target && target.contains(e.target))) {
|
|
266
|
-
return;
|
|
267
|
-
}
|
|
268
|
-
if (this.show) {
|
|
269
|
-
this.setShow(false);
|
|
270
|
-
}
|
|
271
|
-
},
|
|
272
|
-
},
|
|
273
|
-
};
|
|
274
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<transition name="transition" appear>
|
|
3
|
+
<div :style="cssStyle" v-if="show" v-append-body>
|
|
4
|
+
<slot></slot>
|
|
5
|
+
</div>
|
|
6
|
+
</transition>
|
|
7
|
+
</template>
|
|
8
|
+
<style lang="less" scoped>
|
|
9
|
+
.transition {
|
|
10
|
+
&-enter,
|
|
11
|
+
&-leave-to {
|
|
12
|
+
opacity: 0;
|
|
13
|
+
}
|
|
14
|
+
&-enter-active,
|
|
15
|
+
&-leave-active {
|
|
16
|
+
transition: opacity 0.15s ease;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
</style>
|
|
20
|
+
<script>
|
|
21
|
+
import { createPopper } from '@popperjs/core';
|
|
22
|
+
import { Position, generateGetBoundingClientRect } from './utils/Helpers';
|
|
23
|
+
|
|
24
|
+
const isElem = el => el instanceof HTMLElement;
|
|
25
|
+
|
|
26
|
+
const isCoordinates = (target) => {
|
|
27
|
+
if (Array.isArray(target) === false) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
if (target.length !== 2) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
if (target.some((item) => Number.isNaN(Number(item)))) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const Strategy = Object.freeze({
|
|
40
|
+
ABSOLUTE: 'absolute',
|
|
41
|
+
FIXED: 'fixed'
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const Modifier = Object.freeze({
|
|
45
|
+
FLIP: 'flip',
|
|
46
|
+
OFFSET: 'offset'
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export default {
|
|
50
|
+
directives: {
|
|
51
|
+
'append-body': {
|
|
52
|
+
inserted(el, bindings, { context }) {
|
|
53
|
+
let { appendToBody } = context;
|
|
54
|
+
if (!appendToBody) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const nt = context.$nextTick;
|
|
58
|
+
nt(() => nt(() => document.body.appendChild(el)));
|
|
59
|
+
},
|
|
60
|
+
unbind(el, bindings, { context }) {
|
|
61
|
+
el.parentNode && el.parentNode.removeChild(el);
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
props: {
|
|
66
|
+
/**
|
|
67
|
+
* Target HTMLElement|selector|array of coordinates used for positioning
|
|
68
|
+
*/
|
|
69
|
+
target: { default: null },
|
|
70
|
+
/**
|
|
71
|
+
* Whether to show popover
|
|
72
|
+
*/
|
|
73
|
+
show: { type: Boolean, default: false },
|
|
74
|
+
/**
|
|
75
|
+
* z-index
|
|
76
|
+
*/
|
|
77
|
+
zIndex: {
|
|
78
|
+
type: Number,
|
|
79
|
+
default: 1010,
|
|
80
|
+
},
|
|
81
|
+
/**
|
|
82
|
+
* Whether to append popover to body
|
|
83
|
+
*/
|
|
84
|
+
appendToBody: {
|
|
85
|
+
type: Boolean,
|
|
86
|
+
default: true,
|
|
87
|
+
},
|
|
88
|
+
/**
|
|
89
|
+
* Position, values of the popover:
|
|
90
|
+
* bl, br, tl, tr - bottom-left, bottom-right, top-left, top-right
|
|
91
|
+
* @values bl, br, tl, tr, top, top-start, top-end, left, left-start, left-end, right, right-start, right-end, bottom, bottom-start, bottom-end
|
|
92
|
+
*/
|
|
93
|
+
position: {
|
|
94
|
+
type: String,
|
|
95
|
+
default: `${Position.BOTTOM}-${Position.START}`,
|
|
96
|
+
},
|
|
97
|
+
/**
|
|
98
|
+
* Position offset [ x, y ] where:
|
|
99
|
+
* x - skidding (offset along target)
|
|
100
|
+
* y - distance (offset away from target)
|
|
101
|
+
*/
|
|
102
|
+
positionOffset: {
|
|
103
|
+
type: Array,
|
|
104
|
+
default() {
|
|
105
|
+
return [1, 1];
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
/**
|
|
109
|
+
* Whether to flip position if out of viewport
|
|
110
|
+
*/
|
|
111
|
+
positionFlip: {
|
|
112
|
+
type: Boolean,
|
|
113
|
+
default: true,
|
|
114
|
+
},
|
|
115
|
+
/**
|
|
116
|
+
* Auto width
|
|
117
|
+
*/
|
|
118
|
+
autoWidth: {
|
|
119
|
+
type: Boolean,
|
|
120
|
+
default: false,
|
|
121
|
+
},
|
|
122
|
+
/**
|
|
123
|
+
* Should respond to pointer events
|
|
124
|
+
*/
|
|
125
|
+
shouldRespondToPointerEvents: {
|
|
126
|
+
type: Boolean,
|
|
127
|
+
default: true
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
data() {
|
|
131
|
+
return { cssStyle: {} };
|
|
132
|
+
},
|
|
133
|
+
computed: {
|
|
134
|
+
placement() {
|
|
135
|
+
const { position } = this;
|
|
136
|
+
const map = { t: Position.TOP, l: Position.START, r: Position.END, b: Position.BOTTOM };
|
|
137
|
+
// t-b-l-r mode
|
|
138
|
+
if (position.length == 2) {
|
|
139
|
+
return position
|
|
140
|
+
.split('')
|
|
141
|
+
.map(k => map[k])
|
|
142
|
+
.filter(v => !!v)
|
|
143
|
+
.join('-');
|
|
144
|
+
}
|
|
145
|
+
return position;
|
|
146
|
+
},
|
|
147
|
+
options() {
|
|
148
|
+
const { appendToBody, placement, positionFlip, positionOffset } = this;
|
|
149
|
+
const strategy = appendToBody ? Strategy.FIXED : Strategy.ABSOLUTE;
|
|
150
|
+
const modifiers = [
|
|
151
|
+
{
|
|
152
|
+
name: Modifier.FLIP,
|
|
153
|
+
enabled: positionFlip,
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
name: Modifier.OFFSET,
|
|
157
|
+
options: {
|
|
158
|
+
offset: positionOffset,
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
]
|
|
162
|
+
return { placement, strategy, modifiers };
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
watch: {
|
|
166
|
+
show: {
|
|
167
|
+
handler(val) {
|
|
168
|
+
this.$nextTick(() => {
|
|
169
|
+
if (val === false) {
|
|
170
|
+
this.handleReset();
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (isCoordinates(this.target) === false) {
|
|
175
|
+
this.addEventListeners();
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
this.createPopper();
|
|
179
|
+
});
|
|
180
|
+
},
|
|
181
|
+
immediate: true,
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
created() {
|
|
185
|
+
this.popper = null;
|
|
186
|
+
},
|
|
187
|
+
destroyed() {
|
|
188
|
+
this.handleReset();
|
|
189
|
+
},
|
|
190
|
+
methods: {
|
|
191
|
+
addEventListeners() {
|
|
192
|
+
window.addEventListener('blur', this.onWinBlur);
|
|
193
|
+
document.addEventListener('mousedown', this.onDocMouseDown);
|
|
194
|
+
},
|
|
195
|
+
removeEventListeners() {
|
|
196
|
+
window.removeEventListener('blur', this.onWinBlur);
|
|
197
|
+
document.removeEventListener('mousedown', this.onDocMouseDown);
|
|
198
|
+
},
|
|
199
|
+
calcStyle() {
|
|
200
|
+
const { zIndex, autoWidth, shouldRespondToPointerEvents } = this;
|
|
201
|
+
const target = this.getTarget();
|
|
202
|
+
const style = { zIndex };
|
|
203
|
+
if (autoWidth && target) {
|
|
204
|
+
const b = target.getBoundingClientRect();
|
|
205
|
+
style.width = `${b.width}px`;
|
|
206
|
+
}
|
|
207
|
+
if (shouldRespondToPointerEvents === false) {
|
|
208
|
+
style.pointerEvents = 'none';
|
|
209
|
+
}
|
|
210
|
+
this.cssStyle = style;
|
|
211
|
+
},
|
|
212
|
+
getTarget() {
|
|
213
|
+
const { target } = this;
|
|
214
|
+
return isCoordinates(target) ? null : isElem(target) ? target : document.querySelector(target);
|
|
215
|
+
},
|
|
216
|
+
setShow(val) {
|
|
217
|
+
this.$nextTick(() => this.$emit('update:show', val));
|
|
218
|
+
},
|
|
219
|
+
createPopper() {
|
|
220
|
+
const { options, $el: popper } = this;
|
|
221
|
+
const target = this.getTarget();
|
|
222
|
+
|
|
223
|
+
if (target != null) {
|
|
224
|
+
this.popper = createPopper(target, popper, options);
|
|
225
|
+
this.$nextTick(this.updatePopper);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (isCoordinates(this.target)) {
|
|
230
|
+
const [x, y] = this.target;
|
|
231
|
+
const virtualElem = {
|
|
232
|
+
getBoundingClientRect: generateGetBoundingClientRect(x, y),
|
|
233
|
+
};
|
|
234
|
+
this.popper = createPopper(virtualElem, popper, options);
|
|
235
|
+
this.$nextTick(this.updatePopper);
|
|
236
|
+
this.unwatchCursorCoordinates = this.$watch('target', ([x, y]) => {
|
|
237
|
+
virtualElem.getBoundingClientRect = generateGetBoundingClientRect(x, y);
|
|
238
|
+
this.popper?.update();
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
updatePopper() {
|
|
243
|
+
this.calcStyle();
|
|
244
|
+
this.popper.update();
|
|
245
|
+
},
|
|
246
|
+
destroyPopper() {
|
|
247
|
+
this.popper?.destroy();
|
|
248
|
+
this.popper = null;
|
|
249
|
+
},
|
|
250
|
+
handleReset() {
|
|
251
|
+
this.unwatchCursorCoordinates?.();
|
|
252
|
+
if (isCoordinates(this.target) === false) {
|
|
253
|
+
this.removeEventListeners();
|
|
254
|
+
}
|
|
255
|
+
this.destroyPopper();
|
|
256
|
+
},
|
|
257
|
+
onWinBlur(e) {
|
|
258
|
+
if (this.show) {
|
|
259
|
+
this.setShow(false);
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
onDocMouseDown(e) {
|
|
263
|
+
let target = this.getTarget();
|
|
264
|
+
let root = this.$el && isElem(this.$el) ? this.$el : null;
|
|
265
|
+
if ((root && root.contains(e.target)) || (target && target.contains(e.target))) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
if (this.show) {
|
|
269
|
+
this.setShow(false);
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
</script>
|
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
Simple example
|
|
2
|
-
|
|
3
|
-
```vue
|
|
4
|
-
<template>
|
|
5
|
-
<div class="pad-l5">
|
|
6
|
-
<ui-popup :visible.sync="visible" v-bind="props">
|
|
7
|
-
<template #body>
|
|
8
|
-
<div style="height:100%; max-width:30vw">
|
|
9
|
-
<h3>Popup title</h3>
|
|
10
|
-
<div>
|
|
11
|
-
Lorem ipsum dolor sit amet consectetur adipisicing elit. Totam nesciunt
|
|
12
|
-
suscipit porro alias rem consequuntur veritatis iusto accusantium cumque
|
|
13
|
-
assumenda.
|
|
14
|
-
</div>
|
|
15
|
-
</div>
|
|
16
|
-
</template>
|
|
17
|
-
<template #footer="{ close }">
|
|
18
|
-
<div class="text-right">
|
|
19
|
-
<div class="btn btn-primary" @click="close">close</div>
|
|
20
|
-
</div>
|
|
21
|
-
</template>
|
|
22
|
-
</ui-popup>
|
|
23
|
-
<div class="p" v-for="k in bools" :key="k">
|
|
24
|
-
<label>
|
|
25
|
-
<input class="checkbox checkbox-small" type="checkbox" v-model="props[k]" />
|
|
26
|
-
<span class="pad-left-2 v-mid">{{ k }}</span>
|
|
27
|
-
</label>
|
|
28
|
-
</div>
|
|
29
|
-
<div class="btn btn-primary" @click="visible = true">open popup</div>
|
|
30
|
-
</div>
|
|
31
|
-
</template>
|
|
32
|
-
<script>
|
|
33
|
-
import UiPopup from './Popup.vue';
|
|
34
|
-
|
|
35
|
-
export default {
|
|
36
|
-
components: { UiPopup },
|
|
37
|
-
data() {
|
|
38
|
-
return {
|
|
39
|
-
visible: false,
|
|
40
|
-
props: {
|
|
41
|
-
modal: false,
|
|
42
|
-
fullscreen: false,
|
|
43
|
-
usePadding: true,
|
|
44
|
-
showCloseButton: true,
|
|
45
|
-
dialog: {
|
|
46
|
-
class: {},
|
|
47
|
-
style: {},
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
},
|
|
52
|
-
computed: {
|
|
53
|
-
bools() {
|
|
54
|
-
return Object.keys(this.props).filter(p => typeof this.props[p] == 'boolean');
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
</script>
|
|
59
|
-
```
|
|
1
|
+
Simple example
|
|
2
|
+
|
|
3
|
+
```vue
|
|
4
|
+
<template>
|
|
5
|
+
<div class="pad-l5">
|
|
6
|
+
<ui-popup :visible.sync="visible" v-bind="props">
|
|
7
|
+
<template #body>
|
|
8
|
+
<div style="height:100%; max-width:30vw">
|
|
9
|
+
<h3>Popup title</h3>
|
|
10
|
+
<div>
|
|
11
|
+
Lorem ipsum dolor sit amet consectetur adipisicing elit. Totam nesciunt
|
|
12
|
+
suscipit porro alias rem consequuntur veritatis iusto accusantium cumque
|
|
13
|
+
assumenda.
|
|
14
|
+
</div>
|
|
15
|
+
</div>
|
|
16
|
+
</template>
|
|
17
|
+
<template #footer="{ close }">
|
|
18
|
+
<div class="text-right">
|
|
19
|
+
<div class="btn btn-primary" @click="close">close</div>
|
|
20
|
+
</div>
|
|
21
|
+
</template>
|
|
22
|
+
</ui-popup>
|
|
23
|
+
<div class="p" v-for="k in bools" :key="k">
|
|
24
|
+
<label>
|
|
25
|
+
<input class="checkbox checkbox-small" type="checkbox" v-model="props[k]" />
|
|
26
|
+
<span class="pad-left-2 v-mid">{{ k }}</span>
|
|
27
|
+
</label>
|
|
28
|
+
</div>
|
|
29
|
+
<div class="btn btn-primary" @click="visible = true">open popup</div>
|
|
30
|
+
</div>
|
|
31
|
+
</template>
|
|
32
|
+
<script>
|
|
33
|
+
import UiPopup from './Popup.vue';
|
|
34
|
+
|
|
35
|
+
export default {
|
|
36
|
+
components: { UiPopup },
|
|
37
|
+
data() {
|
|
38
|
+
return {
|
|
39
|
+
visible: false,
|
|
40
|
+
props: {
|
|
41
|
+
modal: false,
|
|
42
|
+
fullscreen: false,
|
|
43
|
+
usePadding: true,
|
|
44
|
+
showCloseButton: true,
|
|
45
|
+
dialog: {
|
|
46
|
+
class: {},
|
|
47
|
+
style: {},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
computed: {
|
|
53
|
+
bools() {
|
|
54
|
+
return Object.keys(this.props).filter(p => typeof this.props[p] == 'boolean');
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
</script>
|
|
59
|
+
```
|