kyle-editor 1.0.8 → 1.0.10

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.
@@ -5,7 +5,9 @@
5
5
  const KEditorVue = {
6
6
  name: "KEditor",
7
7
  props: {
8
- modelValue: { type: String, default: "" },
8
+ // 不给默认值:v-model 未绑定 / 被赋 undefined 时必须保持 undefined,
9
+ // 否则会被兜成 '' 进而把正文清空(区分「空字符串 = 清空」与「undefined = 没给值」)
10
+ modelValue: { type: String },
9
11
  options: { type: Object, default: () => ({}) },
10
12
  disabled: { type: Boolean, default: false },
11
13
  // 内容区高度:不传 = 自适应内容;传 px 固定;'auto' 同不传
@@ -15,8 +17,11 @@
15
17
  setup(props, { emit, expose }) {
16
18
  const host = vue.ref(null);
17
19
  const instance = vue.shallowRef(null);
20
+ let warnedModel = false;
18
21
  const buildOptions = () => {
19
- const opts = { ...kyleEditor.defaults, ...props.options, value: props.modelValue || "" };
22
+ const opts = { ...props.options };
23
+ const model = typeof props.modelValue === "string" ? props.modelValue : "";
24
+ opts.value = model || opts.value || "";
20
25
  if (props.height !== null && props.height !== "" && props.height !== void 0) opts.height = props.height;
21
26
  opts.onChange = (html) => {
22
27
  emit("update:modelValue", html);
@@ -31,26 +36,140 @@
31
36
  get editor() {
32
37
  return instance.value;
33
38
  },
34
- getHTML: () => {
39
+ get root() {
35
40
  var _a;
36
- return ((_a = instance.value) == null ? void 0 : _a.getHTML()) || "";
41
+ return ((_a = instance.value) == null ? void 0 : _a.root) || null;
42
+ },
43
+ /* 读取 */
44
+ getHTML: (options) => {
45
+ var _a;
46
+ return ((_a = instance.value) == null ? void 0 : _a.getHTML(options)) ?? "";
37
47
  },
38
48
  getText: () => {
39
49
  var _a;
40
- return ((_a = instance.value) == null ? void 0 : _a.getText()) || "";
50
+ return ((_a = instance.value) == null ? void 0 : _a.getText()) ?? "";
51
+ },
52
+ getJSON: () => {
53
+ var _a;
54
+ return ((_a = instance.value) == null ? void 0 : _a.getJSON()) ?? null;
41
55
  },
42
56
  counts: () => {
43
57
  var _a;
44
- return ((_a = instance.value) == null ? void 0 : _a.counts()) || null;
58
+ return ((_a = instance.value) == null ? void 0 : _a.counts()) ?? null;
59
+ },
60
+ markdownOptions: () => {
61
+ var _a;
62
+ return ((_a = instance.value) == null ? void 0 : _a.markdownOptions()) ?? null;
63
+ },
64
+ /* 内容 */
65
+ setContent: (html, options) => {
66
+ var _a;
67
+ return (_a = instance.value) == null ? void 0 : _a.setContent(html, options);
68
+ },
69
+ clear: () => {
70
+ var _a;
71
+ return (_a = instance.value) == null ? void 0 : _a.clear();
45
72
  },
46
73
  focus: () => {
47
74
  var _a;
48
75
  return (_a = instance.value) == null ? void 0 : _a.focus();
49
76
  },
50
- setContent: (html) => {
77
+ blur: () => {
78
+ var _a;
79
+ return (_a = instance.value) == null ? void 0 : _a.blur();
80
+ },
81
+ undo: () => {
82
+ var _a;
83
+ return (_a = instance.value) == null ? void 0 : _a.undo();
84
+ },
85
+ redo: () => {
86
+ var _a;
87
+ return (_a = instance.value) == null ? void 0 : _a.redo();
88
+ },
89
+ setReadOnly: (value) => {
51
90
  var _a;
52
- return (_a = instance.value) == null ? void 0 : _a.setContent(html);
91
+ return (_a = instance.value) == null ? void 0 : _a.setReadOnly(value);
92
+ },
93
+ /* Markdown 导入 */
94
+ importMarkdown: (source, options) => {
95
+ var _a;
96
+ return (_a = instance.value) == null ? void 0 : _a.importMarkdown(source, options);
97
+ },
98
+ setMarkdown: (source, options) => {
99
+ var _a;
100
+ return (_a = instance.value) == null ? void 0 : _a.setMarkdown(source, options);
101
+ },
102
+ insertMarkdown: (source, options) => {
103
+ var _a;
104
+ return (_a = instance.value) == null ? void 0 : _a.insertMarkdown(source, options);
105
+ },
106
+ appendMarkdown: (source, options) => {
107
+ var _a;
108
+ return (_a = instance.value) == null ? void 0 : _a.appendMarkdown(source, options);
109
+ },
110
+ moveCaretToEnd: () => {
111
+ var _a;
112
+ return (_a = instance.value) == null ? void 0 : _a.moveCaretToEnd();
113
+ },
114
+ /* 插入 */
115
+ appendHTML: (html) => {
116
+ var _a;
117
+ return (_a = instance.value) == null ? void 0 : _a.appendHTML(html);
118
+ },
119
+ insertImage: (url, alt) => {
120
+ var _a;
121
+ return (_a = instance.value) == null ? void 0 : _a.insertImage(url, alt);
53
122
  },
123
+ insertVideo: (url, label) => {
124
+ var _a;
125
+ return (_a = instance.value) == null ? void 0 : _a.insertVideo(url, label);
126
+ },
127
+ insertCode: (code, lang) => {
128
+ var _a;
129
+ return (_a = instance.value) == null ? void 0 : _a.insertCode(code, lang);
130
+ },
131
+ codeLanguages: () => {
132
+ var _a;
133
+ return ((_a = instance.value) == null ? void 0 : _a.codeLanguages()) ?? [];
134
+ },
135
+ highlightCode: () => {
136
+ var _a;
137
+ return (_a = instance.value) == null ? void 0 : _a.highlightCode();
138
+ },
139
+ upload: (file, kind) => {
140
+ var _a;
141
+ return (_a = instance.value) == null ? void 0 : _a.upload(file, kind);
142
+ },
143
+ cancelUploads: () => {
144
+ var _a;
145
+ return (_a = instance.value) == null ? void 0 : _a.cancelUploads();
146
+ },
147
+ /* 按钮 */
148
+ addButton: (button) => {
149
+ var _a;
150
+ return (_a = instance.value) == null ? void 0 : _a.addButton(button);
151
+ },
152
+ removeButton: (name) => {
153
+ var _a;
154
+ return (_a = instance.value) == null ? void 0 : _a.removeButton(name);
155
+ },
156
+ moveButton: (name, position) => {
157
+ var _a;
158
+ return (_a = instance.value) == null ? void 0 : _a.moveButton(name, position);
159
+ },
160
+ setButtonOptions: (name, items) => {
161
+ var _a;
162
+ return (_a = instance.value) == null ? void 0 : _a.setButtonOptions(name, items);
163
+ },
164
+ getButtonValue: (name) => {
165
+ var _a;
166
+ return (_a = instance.value) == null ? void 0 : _a.getButtonValue(name);
167
+ },
168
+ setButtonValue: (name, value) => {
169
+ var _a;
170
+ return (_a = instance.value) == null ? void 0 : _a.setButtonValue(name, value);
171
+ },
172
+ /* 视图 */
54
173
  enterSource: () => {
55
174
  var _a;
56
175
  return (_a = instance.value) == null ? void 0 : _a.enterSource();
@@ -58,6 +177,23 @@
58
177
  openPreview: () => {
59
178
  var _a;
60
179
  return (_a = instance.value) == null ? void 0 : _a.openPreview();
180
+ },
181
+ setHeight: (height) => {
182
+ var _a;
183
+ return (_a = instance.value) == null ? void 0 : _a.setHeight(height);
184
+ },
185
+ setPaper: (paper) => {
186
+ var _a;
187
+ return (_a = instance.value) == null ? void 0 : _a.setPaper(paper);
188
+ },
189
+ /* 事件 */
190
+ on: (name, handler) => {
191
+ var _a;
192
+ return (_a = instance.value) == null ? void 0 : _a.on(name, handler);
193
+ },
194
+ off: (name, handler) => {
195
+ var _a;
196
+ return (_a = instance.value) == null ? void 0 : _a.off(name, handler);
61
197
  }
62
198
  });
63
199
  vue.onMounted(() => {
@@ -78,8 +214,15 @@
78
214
  (value) => {
79
215
  const editor = instance.value;
80
216
  if (!editor || editor.sourceMode) return;
217
+ if (typeof value !== "string") {
218
+ if (value != null && !warnedModel) {
219
+ warnedModel = true;
220
+ console.warn("[KEditor] v-model 只接受 HTML 字符串,本次非字符串赋值已忽略:", value);
221
+ }
222
+ return;
223
+ }
81
224
  if (value === editor.getHTML()) return;
82
- editor.setContent(value || "", { silent: true });
225
+ editor.setContent(value, { silent: true });
83
226
  }
84
227
  );
85
228
  vue.watch(
package/dist/keditor.cjs CHANGED
@@ -223,13 +223,13 @@ const CSS$1 = `
223
223
  .ke-md-panel {
224
224
  width: 372px; max-width: calc(100vw - 24px);
225
225
  display: flex; flex-direction: column; padding-bottom: 0;
226
- max-height: var(--ke-pop-max, 560px);
226
+ max-height: var(--ke-pop-max, 480px);
227
227
  }
228
228
  .ke-md-panel .ke-panel-head, .ke-md-panel .ke-tabs { flex: none; }
229
229
  .ke-md-panel .ke-tabs { margin-bottom: 0; }
230
230
  /* 中间区滚动、底部按钮常驻:窗口再矮也能点到「导入到正文」 */
231
231
  .ke-md-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; margin: 0 -14px; padding: 12px 14px 0; }
232
- .ke-md-panel .ke-panel-foot { flex: none; margin: 10px 0 12px; }
232
+ .ke-md-panel .ke-panel-foot { flex: none; margin: 10px 0 30px; }
233
233
  .ke-md-text {
234
234
  width: 100%; min-height: 118px; max-height: 190px; padding: 10px 11px; border: 1px solid var(--ke-line);
235
235
  border-radius: 8px; background: #fbfcfd; color: #1f2329; font-size: 12.5px; line-height: 1.7; resize: vertical;
@@ -6721,6 +6721,7 @@ class KEditor {
6721
6721
  if (place === "replace") this.setContent(html);
6722
6722
  else {
6723
6723
  if (place === "append") this.moveCaretToEnd();
6724
+ else if (!getRange(this.root)) this.restoreSelection();
6724
6725
  this.commands.insertHTML(html);
6725
6726
  this.highlightCode();
6726
6727
  }
@@ -7130,7 +7131,7 @@ function previewHtml(html) {
7130
7131
  });
7131
7132
  return root.innerHTML;
7132
7133
  }
7133
- const version = "1.0.8";
7134
+ const version = "1.0.10";
7134
7135
  function create(target, options = {}) {
7135
7136
  return new KEditor(target, options);
7136
7137
  }
@@ -221,13 +221,13 @@ const CSS$1 = `
221
221
  .ke-md-panel {
222
222
  width: 372px; max-width: calc(100vw - 24px);
223
223
  display: flex; flex-direction: column; padding-bottom: 0;
224
- max-height: var(--ke-pop-max, 560px);
224
+ max-height: var(--ke-pop-max, 480px);
225
225
  }
226
226
  .ke-md-panel .ke-panel-head, .ke-md-panel .ke-tabs { flex: none; }
227
227
  .ke-md-panel .ke-tabs { margin-bottom: 0; }
228
228
  /* 中间区滚动、底部按钮常驻:窗口再矮也能点到「导入到正文」 */
229
229
  .ke-md-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; margin: 0 -14px; padding: 12px 14px 0; }
230
- .ke-md-panel .ke-panel-foot { flex: none; margin: 10px 0 12px; }
230
+ .ke-md-panel .ke-panel-foot { flex: none; margin: 10px 0 30px; }
231
231
  .ke-md-text {
232
232
  width: 100%; min-height: 118px; max-height: 190px; padding: 10px 11px; border: 1px solid var(--ke-line);
233
233
  border-radius: 8px; background: #fbfcfd; color: #1f2329; font-size: 12.5px; line-height: 1.7; resize: vertical;
@@ -6719,6 +6719,7 @@ class KEditor {
6719
6719
  if (place === "replace") this.setContent(html);
6720
6720
  else {
6721
6721
  if (place === "append") this.moveCaretToEnd();
6722
+ else if (!getRange(this.root)) this.restoreSelection();
6722
6723
  this.commands.insertHTML(html);
6723
6724
  this.highlightCode();
6724
6725
  }
@@ -7128,7 +7129,7 @@ function previewHtml(html) {
7128
7129
  });
7129
7130
  return root.innerHTML;
7130
7131
  }
7131
- const version = "1.0.8";
7132
+ const version = "1.0.10";
7132
7133
  function create(target, options = {}) {
7133
7134
  return new KEditor(target, options);
7134
7135
  }
@@ -225,13 +225,13 @@
225
225
  .ke-md-panel {
226
226
  width: 372px; max-width: calc(100vw - 24px);
227
227
  display: flex; flex-direction: column; padding-bottom: 0;
228
- max-height: var(--ke-pop-max, 560px);
228
+ max-height: var(--ke-pop-max, 480px);
229
229
  }
230
230
  .ke-md-panel .ke-panel-head, .ke-md-panel .ke-tabs { flex: none; }
231
231
  .ke-md-panel .ke-tabs { margin-bottom: 0; }
232
232
  /* 中间区滚动、底部按钮常驻:窗口再矮也能点到「导入到正文」 */
233
233
  .ke-md-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; margin: 0 -14px; padding: 12px 14px 0; }
234
- .ke-md-panel .ke-panel-foot { flex: none; margin: 10px 0 12px; }
234
+ .ke-md-panel .ke-panel-foot { flex: none; margin: 10px 0 30px; }
235
235
  .ke-md-text {
236
236
  width: 100%; min-height: 118px; max-height: 190px; padding: 10px 11px; border: 1px solid var(--ke-line);
237
237
  border-radius: 8px; background: #fbfcfd; color: #1f2329; font-size: 12.5px; line-height: 1.7; resize: vertical;
@@ -6723,6 +6723,7 @@ ${items}
6723
6723
  if (place === "replace") this.setContent(html);
6724
6724
  else {
6725
6725
  if (place === "append") this.moveCaretToEnd();
6726
+ else if (!getRange(this.root)) this.restoreSelection();
6726
6727
  this.commands.insertHTML(html);
6727
6728
  this.highlightCode();
6728
6729
  }
@@ -7132,7 +7133,7 @@ ${items}
7132
7133
  });
7133
7134
  return root.innerHTML;
7134
7135
  }
7135
- const version = "1.0.8";
7136
+ const version = "1.0.10";
7136
7137
  function create(target, options = {}) {
7137
7138
  return new KEditor(target, options);
7138
7139
  }