md-editor-v3 5.7.0 → 5.8.0

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.
@@ -2,241 +2,328 @@
2
2
  const vue = require("vue");
3
3
  const config = require("./config.cjs");
4
4
  const vueTsx = require("./vue-tsx.cjs");
5
- const props$1 = {
6
- overlay: {
7
- type: [String, Object],
8
- default: ""
9
- },
10
- visible: {
11
- type: Boolean,
12
- default: false
13
- },
14
- onChange: {
15
- type: Function,
16
- default: () => {
5
+ const dom = require("./dom.cjs");
6
+ const lucideVueNext = require("lucide-vue-next");
7
+ const index = require("./index5.cjs");
8
+ const Github = () => vue.createVNode("svg", {
9
+ "xmlns": "http://www.w3.org/2000/svg",
10
+ "viewBox": "0 0 24 24",
11
+ "fill": "none",
12
+ "stroke": "currentColor",
13
+ "stroke-width": "2",
14
+ "stroke-linecap": "round",
15
+ "stroke-linejoin": "round",
16
+ "class": "lucide lucide-github-icon"
17
+ }, [vue.createVNode("path", {
18
+ "d": "M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"
19
+ }, null), vue.createVNode("path", {
20
+ "d": "M9 18c-4.51 2-5-2-7-2"
21
+ }, null)]);
22
+ const iconMaps = {
23
+ bold: lucideVueNext.Bold,
24
+ underline: lucideVueNext.Underline,
25
+ italic: lucideVueNext.Italic,
26
+ "strike-through": lucideVueNext.Strikethrough,
27
+ title: lucideVueNext.Heading,
28
+ sub: lucideVueNext.Subscript,
29
+ sup: lucideVueNext.Superscript,
30
+ quote: lucideVueNext.Quote,
31
+ "unordered-list": lucideVueNext.List,
32
+ "ordered-list": lucideVueNext.ListOrdered,
33
+ task: lucideVueNext.ListTodo,
34
+ "code-row": lucideVueNext.Code,
35
+ code: lucideVueNext.SquareCode,
36
+ link: lucideVueNext.Link,
37
+ image: lucideVueNext.Image,
38
+ table: lucideVueNext.Table,
39
+ revoke: lucideVueNext.Reply,
40
+ next: lucideVueNext.Forward,
41
+ save: lucideVueNext.Save,
42
+ prettier: lucideVueNext.SquareCode,
43
+ minimize: lucideVueNext.Minimize2,
44
+ maximize: lucideVueNext.Maximize2,
45
+ "fullscreen-exit": lucideVueNext.Shrink,
46
+ fullscreen: lucideVueNext.Expand,
47
+ "preview-only": lucideVueNext.View,
48
+ preview: lucideVueNext.Eye,
49
+ "preview-html": lucideVueNext.CodeXml,
50
+ catalog: lucideVueNext.ListTree,
51
+ github: Github,
52
+ mermaid: lucideVueNext.ChartArea,
53
+ formula: lucideVueNext.SquareSigma,
54
+ close: lucideVueNext.X,
55
+ delete: lucideVueNext.Trash2,
56
+ upload: lucideVueNext.Upload
57
+ };
58
+ const Icon$1 = /* @__PURE__ */ vue.defineComponent({
59
+ name: `${config.prefix}-icon-set`,
60
+ props: {
61
+ name: {
62
+ type: String,
63
+ default: ""
17
64
  }
18
65
  },
19
- // 相对滚动的元素选择器
20
- relative: {
21
- type: String,
22
- default: "html"
23
- },
24
- disabled: {
25
- type: Boolean,
26
- default: void 0
27
- }
28
- };
29
- const Dropdown = /* @__PURE__ */ vue.defineComponent({
30
- name: `${config.prefix}-dropdown`,
31
- props: props$1,
32
- setup(props2, ctx) {
33
- const HIDDEN_CLASS = `${config.prefix}-dropdown-hidden`;
34
- const ctl = vue.reactive({
35
- overlayClass: [HIDDEN_CLASS],
36
- overlayStyle: {},
37
- triggerHover: false,
38
- overlayHover: false
39
- });
40
- const triggerRef = vue.ref();
41
- const overlayRef = vue.ref();
42
- const triggerHandler = () => {
43
- var _a, _b;
44
- if (props2.disabled) {
45
- return false;
46
- }
47
- ctl.triggerHover = true;
48
- const triggerEle = triggerRef.value;
49
- const overlayEle = overlayRef.value;
50
- if (!triggerEle || !overlayEle) {
51
- return;
52
- }
53
- const triggerInfo = triggerEle.getBoundingClientRect();
54
- const triggerTop = triggerEle.offsetTop;
55
- const triggerLeft = triggerEle.offsetLeft;
56
- const triggerHeight = triggerInfo.height;
57
- const triggerWidth = triggerInfo.width;
58
- const rootNode = triggerEle.getRootNode();
59
- const relativecrollLeft = ((_a = rootNode.querySelector(props2.relative)) == null ? void 0 : _a.scrollLeft) || 0;
60
- const relativeWidth = ((_b = rootNode.querySelector(props2.relative)) == null ? void 0 : _b.clientWidth) || 0;
61
- let left = triggerLeft - overlayEle.offsetWidth / 2 + triggerWidth / 2 - relativecrollLeft;
62
- if (left + overlayEle.offsetWidth > relativecrollLeft + relativeWidth) {
63
- left = relativecrollLeft + relativeWidth - overlayEle.offsetWidth;
64
- }
65
- if (left < 0) {
66
- left = 0;
67
- }
68
- ctl.overlayStyle = {
69
- ...ctl.overlayStyle,
70
- top: triggerTop + triggerHeight + "px",
71
- left: left + "px"
72
- };
73
- props2.onChange(true);
74
- };
75
- const overlayHandler = () => {
76
- if (props2.disabled) {
77
- return false;
78
- }
79
- ctl.overlayHover = true;
80
- };
81
- vue.watch(() => props2.visible, (newV) => {
82
- if (newV) {
83
- ctl.overlayClass = ctl.overlayClass.filter((classItem) => classItem !== HIDDEN_CLASS);
84
- } else {
85
- ctl.overlayClass.push(HIDDEN_CLASS);
86
- }
87
- });
88
- let hiddenTimer = -1;
89
- const leaveHidden = (e) => {
90
- if (triggerRef.value === e.target) {
91
- ctl.triggerHover = false;
92
- } else {
93
- ctl.overlayHover = false;
94
- }
95
- clearTimeout(hiddenTimer);
96
- hiddenTimer = window.setTimeout(() => {
97
- if (!ctl.overlayHover && !ctl.triggerHover) {
98
- props2.onChange(false);
99
- }
100
- }, 10);
101
- };
102
- vue.onMounted(() => {
103
- triggerRef.value.addEventListener("mouseenter", triggerHandler);
104
- triggerRef.value.addEventListener("mouseleave", leaveHidden);
105
- overlayRef.value.addEventListener("mouseenter", overlayHandler);
106
- overlayRef.value.addEventListener("mouseleave", leaveHidden);
107
- });
108
- vue.onBeforeUnmount(() => {
109
- triggerRef.value.removeEventListener("mouseenter", triggerHandler);
110
- triggerRef.value.removeEventListener("mouseleave", leaveHidden);
111
- overlayRef.value.removeEventListener("mouseenter", overlayHandler);
112
- overlayRef.value.removeEventListener("mouseleave", leaveHidden);
113
- });
66
+ setup(props2) {
114
67
  return () => {
115
- const slotDefault = vueTsx.getSlot({
116
- ctx
117
- });
118
- const slotOverlay = vueTsx.getSlot({
119
- props: props2,
120
- ctx
121
- }, "overlay");
122
- const trigger = vue.cloneVNode(slotDefault instanceof Array ? slotDefault[0] : slotDefault, {
123
- ref: triggerRef,
124
- key: "cloned-dropdown-trigger"
68
+ return vue.h(iconMaps[props2.name], {
69
+ class: `${config.prefix}-icon`
125
70
  });
126
- const overlay = vue.createVNode("div", {
127
- "class": [`${config.prefix}-dropdown`, ctl.overlayClass],
128
- "style": ctl.overlayStyle,
129
- "ref": overlayRef
130
- }, [vue.createVNode("div", {
131
- "class": `${config.prefix}-dropdown-overlay`
132
- }, [slotOverlay instanceof Array ? slotOverlay[0] : slotOverlay])]);
133
- return [trigger, overlay];
71
+ };
72
+ }
73
+ });
74
+ const Icon = /* @__PURE__ */ vue.defineComponent({
75
+ name: `${config.prefix}-icon`,
76
+ props: {
77
+ name: {
78
+ type: String,
79
+ default: ""
80
+ }
81
+ },
82
+ setup(props2) {
83
+ const customIcon = vue.inject("customIcon");
84
+ return () => {
85
+ const item = customIcon.value[props2.name];
86
+ if (typeof item === "object") {
87
+ return typeof item.component === "object" ? vue.h(item.component, item.props) : vue.createVNode("span", {
88
+ "innerHTML": item.component
89
+ }, null);
90
+ }
91
+ return vue.createVNode(Icon$1, {
92
+ "name": props2.name
93
+ }, null);
134
94
  };
135
95
  }
136
96
  });
137
97
  const props = {
138
98
  title: {
139
- type: String,
99
+ type: [String, Object],
140
100
  default: ""
141
101
  },
142
102
  visible: {
143
103
  type: Boolean,
144
- default: void 0
145
- },
146
- /**
147
- * 展示在工具栏的内容,通常是个图标
148
- *
149
- * @deprecated 使用默认插槽代替
150
- */
151
- trigger: {
152
- type: [String, Object],
153
- default: void 0
104
+ default: false
154
105
  },
155
- onChange: {
156
- type: Function,
157
- default: void 0
106
+ width: {
107
+ type: String,
108
+ default: "auto"
158
109
  },
159
- // 下拉框中的内容
160
- overlay: {
161
- type: [String, Object],
162
- default: void 0
110
+ height: {
111
+ type: String,
112
+ default: "auto"
163
113
  },
164
- /**
165
- * ==没有意义,仅用于规避克隆组件自动嵌入insert方法时,传入的是该组件而产生的waring
166
- */
167
- insert: {
168
- type: Function,
169
- default: void 0
114
+ onClose: {
115
+ type: Function
170
116
  },
171
- language: {
172
- type: String,
173
- default: void 0
117
+ showAdjust: {
118
+ type: Boolean,
119
+ default: false
174
120
  },
175
- theme: {
176
- type: String,
177
- default: void 0
121
+ isFullscreen: {
122
+ type: Boolean,
123
+ default: false
178
124
  },
179
- previewTheme: {
180
- type: String,
181
- default: void 0
125
+ onAdjust: {
126
+ type: Function,
127
+ default: () => {
128
+ }
182
129
  },
183
- codeTheme: {
130
+ class: {
184
131
  type: String,
185
132
  default: void 0
186
133
  },
187
- disabled: {
188
- type: Boolean,
189
- default: void 0
134
+ style: {
135
+ type: [Object, String],
136
+ default: () => ({})
190
137
  },
191
- showToolbarName: {
138
+ showMask: {
192
139
  type: Boolean,
193
- default: void 0
140
+ default: true
194
141
  }
195
- /**
196
- * ==结束
197
- */
198
142
  };
199
- const DropdownToolbar = /* @__PURE__ */ vue.defineComponent({
200
- name: "DropdownToolbar",
143
+ const MdModal = /* @__PURE__ */ vue.defineComponent({
144
+ name: "MdModal",
201
145
  props,
202
- emits: ["onChange"],
146
+ emits: ["onClose"],
203
147
  setup(props2, ctx) {
204
- const editorId = vue.inject("editorId");
148
+ const themeRef = vue.inject("theme");
149
+ const rootRef = vue.inject("rootRef");
150
+ const modalVisible = vue.ref(props2.visible);
151
+ const modalClass = vue.ref([`${config.prefix}-modal`]);
152
+ const modalRef = vue.ref();
153
+ const modalHeaderRef = vue.ref();
154
+ const bodyRef = vue.ref();
155
+ const containerRef = vue.shallowRef();
156
+ let keyMoveClear = () => {
157
+ };
158
+ const state = vue.reactive({
159
+ maskStyle: {
160
+ zIndex: -1
161
+ },
162
+ modalStyle: {
163
+ zIndex: -1
164
+ },
165
+ initPos: {
166
+ left: "0px",
167
+ top: "0px"
168
+ },
169
+ historyPos: {
170
+ left: "0px",
171
+ top: "0px"
172
+ }
173
+ });
174
+ const innerSize = vue.computed(() => {
175
+ if (props2.isFullscreen) {
176
+ return {
177
+ width: "100%",
178
+ height: "100%"
179
+ };
180
+ } else {
181
+ return {
182
+ width: props2.width,
183
+ height: props2.height
184
+ };
185
+ }
186
+ });
187
+ vue.watch(() => props2.isFullscreen, (nVal) => {
188
+ if (nVal) {
189
+ keyMoveClear();
190
+ } else {
191
+ vue.nextTick(() => {
192
+ keyMoveClear = dom.keyMove(modalHeaderRef.value, (left, top) => {
193
+ state.initPos.left = left + "px";
194
+ state.initPos.top = top + "px";
195
+ });
196
+ });
197
+ }
198
+ });
199
+ vue.watch(() => props2.visible, (nVal) => {
200
+ if (nVal) {
201
+ state.maskStyle.zIndex = config.globalConfig.editorConfig.zIndex + index.getZIndexIncrement();
202
+ state.modalStyle.zIndex = config.globalConfig.editorConfig.zIndex + index.getZIndexIncrement();
203
+ modalClass.value.push("zoom-in");
204
+ modalVisible.value = nVal;
205
+ vue.nextTick(() => {
206
+ const halfWidth = modalRef.value.offsetWidth / 2;
207
+ const halfHeight = modalRef.value.offsetHeight / 2;
208
+ const halfClientWidth = document.documentElement.clientWidth / 2;
209
+ const halfClientHeight = document.documentElement.clientHeight / 2;
210
+ state.initPos.left = halfClientWidth - halfWidth + "px";
211
+ state.initPos.top = halfClientHeight - halfHeight + "px";
212
+ if (!props2.isFullscreen) {
213
+ keyMoveClear = dom.keyMove(modalHeaderRef.value, (left, top) => {
214
+ state.initPos.left = left + "px";
215
+ state.initPos.top = top + "px";
216
+ });
217
+ }
218
+ });
219
+ setTimeout(() => {
220
+ modalClass.value = modalClass.value.filter((item) => item !== "zoom-in");
221
+ }, 140);
222
+ } else {
223
+ modalClass.value.push("zoom-out");
224
+ keyMoveClear();
225
+ setTimeout(() => {
226
+ modalClass.value = modalClass.value.filter((item) => item !== "zoom-out");
227
+ modalVisible.value = nVal;
228
+ }, 130);
229
+ }
230
+ });
231
+ const internalStyle = vue.computed(() => ({
232
+ display: modalVisible.value ? "block" : "none"
233
+ }));
234
+ const combinedStyle = vue.computed(() => {
235
+ if (typeof props2.style === "string") {
236
+ return [props2.style, internalStyle.value].join("; ");
237
+ } else if (props2.style instanceof Object) {
238
+ return {
239
+ ...internalStyle.value,
240
+ ...props2.style
241
+ };
242
+ } else {
243
+ return internalStyle.value;
244
+ }
245
+ });
246
+ vue.onMounted(() => {
247
+ var _a;
248
+ const rootNode = (_a = rootRef.value) == null ? void 0 : _a.getRootNode();
249
+ bodyRef.value = rootNode instanceof Document ? document.body : rootNode;
250
+ });
205
251
  return () => {
206
- const Trigger = vueTsx.getSlot({
207
- props: props2,
208
- ctx
209
- }, "trigger");
210
- const Overlay = vueTsx.getSlot({
211
- props: props2,
252
+ const slotDefault = vueTsx.getSlot({
212
253
  ctx
213
- }, "overlay");
214
- const Default = vueTsx.getSlot({
254
+ });
255
+ const slotTitle = vueTsx.getSlot({
215
256
  props: props2,
216
257
  ctx
217
- });
218
- return vue.createVNode(Dropdown, {
219
- "relative": `#${editorId}-toolbar-wrapper`,
220
- "visible": props2.visible,
221
- "onChange": (v) => {
222
- var _a;
223
- (_a = props2.onChange) == null ? void 0 : _a.call(props2, v);
224
- ctx.emit("onChange", v);
225
- },
226
- "overlay": Overlay,
227
- "disabled": props2.disabled
258
+ }, "title");
259
+ return bodyRef.value ? vue.createVNode(vue.Teleport, {
260
+ "to": bodyRef.value
228
261
  }, {
229
262
  default: () => [vue.createVNode("div", {
230
- "class": [`${config.prefix}-toolbar-item`, props2.disabled && `${config.prefix}-disabled`],
231
- "title": props2.title || ""
232
- }, [Default || Trigger])]
233
- });
263
+ "ref": containerRef,
264
+ "class": `${config.prefix}-modal-container`,
265
+ "data-theme": themeRef.value
266
+ }, [vue.createVNode("div", {
267
+ "class": props2.class,
268
+ "style": combinedStyle.value
269
+ }, [props2.showMask && vue.createVNode("div", {
270
+ "class": `${config.prefix}-modal-mask`,
271
+ "style": state.maskStyle,
272
+ "onClick": () => {
273
+ var _a;
274
+ (_a = props2.onClose) == null ? void 0 : _a.call(props2);
275
+ ctx.emit("onClose");
276
+ }
277
+ }, null), vue.createVNode("div", {
278
+ "class": modalClass.value,
279
+ "style": {
280
+ ...state.modalStyle,
281
+ ...state.initPos,
282
+ ...innerSize.value
283
+ },
284
+ "ref": modalRef
285
+ }, [vue.createVNode("div", {
286
+ "class": `${config.prefix}-modal-header`,
287
+ "ref": modalHeaderRef
288
+ }, [slotTitle || ""]), vue.createVNode("div", {
289
+ "class": `${config.prefix}-modal-body`
290
+ }, [slotDefault]), vue.createVNode("div", {
291
+ "class": `${config.prefix}-modal-func`
292
+ }, [props2.showAdjust && vue.createVNode("div", {
293
+ "class": `${config.prefix}-modal-adjust`,
294
+ "onClick": (e) => {
295
+ e.stopPropagation();
296
+ if (!props2.isFullscreen) {
297
+ state.historyPos = state.initPos;
298
+ state.initPos = {
299
+ left: "0",
300
+ top: "0"
301
+ };
302
+ } else {
303
+ state.initPos = state.historyPos;
304
+ }
305
+ props2.onAdjust(!props2.isFullscreen);
306
+ }
307
+ }, [vue.createVNode(Icon, {
308
+ "name": props2.isFullscreen ? "minimize" : "maximize"
309
+ }, null)]), vue.createVNode("div", {
310
+ "class": `${config.prefix}-modal-close`,
311
+ "onClick": (e) => {
312
+ var _a;
313
+ e.stopPropagation();
314
+ (_a = props2.onClose) == null ? void 0 : _a.call(props2);
315
+ ctx.emit("onClose");
316
+ }
317
+ }, [vue.createVNode(Icon, {
318
+ "name": "close"
319
+ }, null)])])])])])]
320
+ }) : "";
234
321
  };
235
322
  }
236
323
  });
237
- DropdownToolbar.install = (app) => {
238
- app.component(DropdownToolbar.name, DropdownToolbar);
324
+ MdModal.install = (app) => {
325
+ app.component(MdModal.name, MdModal);
239
326
  return app;
240
327
  };
241
- exports.Dropdown = Dropdown;
242
- exports.DropdownToolbar = DropdownToolbar;
328
+ exports.Icon = Icon;
329
+ exports.MdModal = MdModal;