@anweb/nuxt-aneditor 0.1.3 → 0.1.5

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/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "AnEditor",
3
3
  "configKey": "aneditor",
4
- "version": "0.1.3",
4
+ "version": "0.1.5",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -14,10 +14,12 @@ const module$1 = defineNuxtModule({
14
14
  const { resolve } = createResolver(import.meta.url);
15
15
  _nuxt.options.alias["#aneditor/types"] = resolve("./runtime/types");
16
16
  _nuxt.options.icon = _nuxt.options.icon || {};
17
- _nuxt.options.icon.customCollections = [
18
- ..._nuxt.options.icon.customCollections || [],
19
- { prefix: "aneditor", dir: resolve("./runtime/assets/icons") }
20
- ];
17
+ _nuxt.options.icon.customCollections = _nuxt.options.icon.customCollections || [];
18
+ _nuxt.options.icon.customCollections.push({ prefix: "aneditor", dir: resolve("./runtime/assets/icons") });
19
+ const appIcon = _nuxt.options.appConfig.icon || {};
20
+ _nuxt.options.appConfig.icon = appIcon;
21
+ appIcon.customCollections = appIcon.customCollections || [];
22
+ appIcon.customCollections.push("aneditor");
21
23
  addComponentsDir({
22
24
  path: resolve("./runtime/components")
23
25
  });
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="4" width="20" height="16" rx="2"/><line x1="2" y1="8" x2="22" y2="8"/><circle cx="5" cy="6" r="0.5" fill="currentColor"/><circle cx="7.5" cy="6" r="0.5" fill="currentColor"/><circle cx="10" cy="6" r="0.5" fill="currentColor"/></svg>
@@ -1,7 +1,7 @@
1
1
  <script setup>
2
- import { ref, computed, watch, onMounted } from "vue";
2
+ import { ref, computed, watch, onMounted, nextTick } from "vue";
3
3
  import { useEventListener, useFileDialog, useDebounceFn, useThrottleFn } from "@vueuse/core";
4
- import { useTemplateRef, parseMarkdown, toMarkdown, extractYouTubeId, useAnDialogs, useSelection, useHistory, useBlocks, useTable, useImage, useList } from "#imports";
4
+ import { useTemplateRef, parseMarkdown, toMarkdown, extractYouTubeId, useAnDialogs, useSelection, useHistory, useBlocks, useTable, useEditorImage, useList } from "#imports";
5
5
  import { AnEditorToolbar, AnEditorPrompt } from "#components";
6
6
  const emit = defineEmits(["update:modelValue"]);
7
7
  const props = defineProps({
@@ -42,7 +42,7 @@ const syncToModel = () => {
42
42
  const history = useHistory(refContent, selection);
43
43
  const blocks = useBlocks(refContent, selection, syncToModel);
44
44
  const table = useTable(refContent, syncToModel);
45
- const image = useImage(refContent, syncToModel);
45
+ const image = useEditorImage(refContent, syncToModel);
46
46
  const list = useList(refContent, selection, syncToModel, blocks.ensureBlockWrapped, blocks.isInsideCodeBlock);
47
47
  const focus = () => {
48
48
  refContent.value?.focus();
@@ -99,6 +99,12 @@ const cleanOrphanedFormatting = () => {
99
99
  const openPrompt = (params) => {
100
100
  Dialogs.open(AnEditorPrompt, { ...params });
101
101
  };
102
+ const createHtmlElement = (html) => {
103
+ const div = document.createElement("div");
104
+ div.className = "an-editor__html";
105
+ div.innerHTML = html;
106
+ return div;
107
+ };
102
108
  const createYouTubeElement = (ytId) => {
103
109
  const div = document.createElement("div");
104
110
  div.className = "an-editor__youtube";
@@ -260,6 +266,29 @@ const onToolbarAction = (type) => {
260
266
  });
261
267
  break;
262
268
  }
269
+ case "iframe": {
270
+ const savedBlock = blocks.getCurrentBlock();
271
+ openPrompt({
272
+ title: "Embed HTML",
273
+ fields: [
274
+ { key: "html", label: "HTML", placeholder: '<iframe src="https://..."></iframe>', type: "textarea" }
275
+ ],
276
+ onSubmit: (values) => {
277
+ if (!values.html) return;
278
+ const div = createHtmlElement(values.html);
279
+ const p = document.createElement("p");
280
+ p.innerHTML = "<br>";
281
+ if (savedBlock && savedBlock.parentNode) {
282
+ savedBlock.parentNode.insertBefore(div, savedBlock.nextSibling);
283
+ } else {
284
+ refContent.value?.appendChild(div);
285
+ }
286
+ div.parentNode.insertBefore(p, div.nextSibling);
287
+ syncToModel();
288
+ }
289
+ });
290
+ break;
291
+ }
263
292
  case "table": {
264
293
  openPrompt({
265
294
  title: "Insert table",
@@ -385,6 +414,33 @@ const onContentClick = (e) => {
385
414
  });
386
415
  return;
387
416
  }
417
+ const htmlDiv = target.closest(".an-editor__html");
418
+ if (htmlDiv) {
419
+ const currentHtml = htmlDiv.innerHTML.trim();
420
+ openPrompt({
421
+ title: "Edit HTML",
422
+ submitLabel: "Save",
423
+ deleteLabel: "Delete",
424
+ fields: [
425
+ { key: "html", label: "HTML", value: currentHtml, type: "textarea" }
426
+ ],
427
+ onSubmit: (values) => {
428
+ if (!values.html) return;
429
+ const newDiv = createHtmlElement(values.html);
430
+ htmlDiv.replaceWith(newDiv);
431
+ syncToModel();
432
+ },
433
+ onDelete: () => {
434
+ const next = htmlDiv.nextElementSibling;
435
+ htmlDiv.remove();
436
+ if (next && next.tagName === "P" && (!next.textContent || next.textContent.trim() === "") && next.innerHTML === "<br>") {
437
+ next.remove();
438
+ }
439
+ syncToModel();
440
+ }
441
+ });
442
+ return;
443
+ }
388
444
  };
389
445
  const onPaste = (e) => {
390
446
  e.preventDefault();
@@ -395,6 +451,12 @@ const onPaste = (e) => {
395
451
  blocks.insertBlockAtCursor(div);
396
452
  return;
397
453
  }
454
+ const trimmed = text.trim();
455
+ if (/^<\w/.test(trimmed) && /<\/\w+>$/.test(trimmed)) {
456
+ const div = createHtmlElement(trimmed);
457
+ blocks.insertBlockAtCursor(div);
458
+ return;
459
+ }
398
460
  const sel = selection.getSelection();
399
461
  if (!sel) return;
400
462
  sel.range.deleteContents();
@@ -509,10 +571,7 @@ const updateActiveFormats = () => {
509
571
  }
510
572
  activeFormats.value = formats;
511
573
  };
512
- const isEmpty = computed(() => {
513
- const html = refContent.value?.innerHTML ?? "";
514
- return !html || html === "<br>" || html === "<p><br></p>";
515
- });
574
+ const isEmpty = computed(() => !props.modelValue);
516
575
  const throttledUpdateActiveFormats = useThrottleFn(updateActiveFormats, 100);
517
576
  useEventListener(document, "selectionchange", throttledUpdateActiveFormats);
518
577
  FileDialog.onChange((files) => {
@@ -522,11 +581,13 @@ FileDialog.onChange((files) => {
522
581
  FileDialog.reset();
523
582
  });
524
583
  onMounted(() => {
525
- if (refContent.value && props.modelValue) {
526
- refContent.value.innerHTML = parseMarkdown(props.modelValue);
527
- internalMd = props.modelValue;
528
- }
529
- history.pushHistory();
584
+ nextTick(() => {
585
+ if (refContent.value && props.modelValue && !internalMd) {
586
+ refContent.value.innerHTML = parseMarkdown(props.modelValue);
587
+ internalMd = props.modelValue;
588
+ }
589
+ history.pushHistory();
590
+ });
530
591
  });
531
592
  watch(() => props.modelValue, (newMd) => {
532
593
  if (newMd === internalMd) return;
@@ -626,5 +687,5 @@ defineExpose({ focus, clear });
626
687
  </template>
627
688
 
628
689
  <style scoped>
629
- .an-editor{background:var(--an-editor-background,#fff);border:1px solid var(--an-editor-border,#e0e0e0);border-radius:8px;overflow:hidden}.an-editor:focus-within{border-color:var(--an-editor-border-focus,#7c83ff)}.an-editor.-disabled{opacity:.6;pointer-events:none}.an-editor__body{position:relative}.an-editor__content{font-size:var(--an-editor-font-size,15px);line-height:1.6;min-height:var(--an-editor-min-height,200px);outline:none;padding:16px}.an-editor__content.-empty:before{color:#999;content:attr(data-placeholder);pointer-events:none}.an-editor__content :deep(h1){font-size:2em;font-weight:700;margin:.5em 0}.an-editor__content :deep(h2){font-size:1.5em;font-weight:700;margin:.5em 0}.an-editor__content :deep(h3){font-size:1.17em;font-weight:700;margin:.5em 0}.an-editor__content :deep(h4){font-size:1em;font-weight:700;margin:.5em 0}.an-editor__content :deep(h5){font-size:.83em;font-weight:700;margin:.5em 0}.an-editor__content :deep(h6){font-size:.67em;font-weight:700;margin:.5em 0}.an-editor__content :deep(strong){font-weight:700}.an-editor__content :deep(em){font-style:italic}.an-editor__content :deep(s){text-decoration:line-through}.an-editor__content :deep(a){color:#7c83ff;cursor:pointer;text-decoration:underline}.an-editor__content :deep(blockquote){border-left:3px solid #e0e0e0;color:#666;margin:12px 0;padding-left:16px}.an-editor__content :deep(ol),.an-editor__content :deep(ul){margin:8px 0;padding-left:24px}.an-editor__content :deep(code){background:#f4f4f5;border-radius:4px;font-family:SF Mono,Fira Code,monospace;font-size:.9em;padding:2px 6px}.an-editor__content :deep(pre){background:#1e1e2e;border-radius:8px;color:#cdd6f4;margin:12px 0;min-height:3em;overflow-x:auto;padding:16px}.an-editor__content :deep(pre) code{background:none;border-radius:0;color:inherit;display:block;min-height:1.4em;outline:none;padding:0}.an-editor__content :deep(hr){border:none;border-top:2px solid #e0e0e0;margin:16px 0}.an-editor__content :deep(.an-editor__youtube){cursor:pointer;margin:12px 0}.an-editor__content :deep(.an-editor__youtube) iframe{aspect-ratio:16/9;border:none;border-radius:8px;pointer-events:none;width:100%}.an-editor__content :deep(.an-editor__image){cursor:pointer;margin:12px 0;position:relative}.an-editor__content :deep(.an-editor__image) img{border-radius:8px;display:block;max-width:100%;transition:filter .15s}.an-editor__content :deep(.an-editor__image):hover img{filter:brightness(.92)}.an-editor__content :deep(.an-editor__table){border-collapse:collapse;font-size:.95em;margin:12px 0;width:100%}.an-editor__content :deep(.an-editor__table) td,.an-editor__content :deep(.an-editor__table) th{border:1px solid #d0d5dd;box-sizing:border-box;cursor:text;line-height:1.5;min-width:60px;outline:none;padding:8px 12px;text-align:left}.an-editor__content :deep(.an-editor__table) th{background:#f4f5f7;font-weight:600}.an-editor__content :deep(.an-editor__table) tr:hover td{background:#f9fafb}.an-editor__content :deep(p){margin:8px 0}.an-editor__content :deep(p):first-child{margin-top:0}.an-editor__content :deep(p):last-child{margin-bottom:0}.an-editor__table-actions{background:#fff;border:1px solid #e8eaed;border-radius:8px;box-shadow:0 4px 16px rgba(0,0,0,.1);min-width:160px;padding:4px;position:absolute;z-index:10}.an-editor__table-actions-divider{background:#e8eaed;height:1px;margin:4px 0}.an-editor__table-action-btn{background:none;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;display:block;font-size:13px;padding:8px 12px;text-align:left;transition:background .1s;width:100%}.an-editor__table-action-btn:hover{background:#f4f5f7}.an-editor__table-action-btn.-danger{color:#ff6b6b}.an-editor__table-action-btn.-danger:hover{background:#fff5f5}.an-editor__image-overlay{border:2px solid #7c83ff;border-radius:8px;pointer-events:none;position:absolute;z-index:10}.an-editor__image-edit,.an-editor__image-expand{align-items:center;background:rgba(0,0,0,.55);border:none;border-radius:6px;color:#fff;cursor:pointer;display:flex;font-size:18px;height:32px;justify-content:center;pointer-events:auto;position:absolute;top:8px;transition:background .15s;width:32px}.an-editor__image-edit:hover,.an-editor__image-expand:hover{background:rgba(0,0,0,.75)}.an-editor__image-expand{right:8px}.an-editor__image-edit{right:46px}.an-editor__image-resize{background:#7c83ff;border-radius:2px 0 8px 0;bottom:-2px;cursor:nwse-resize;height:16px;pointer-events:auto;position:absolute;right:-2px;width:16px}.an-editor__image-resize:before{border-bottom:2px solid #fff;border-right:2px solid #fff;bottom:3px;content:"";height:6px;position:absolute;right:3px;width:6px}
690
+ .an-editor{background:var(--an-editor-background,#fff);border:1px solid var(--an-editor-border,#e0e0e0);border-radius:8px;overflow:hidden}.an-editor:focus-within{border-color:var(--an-editor-border-focus,#7c83ff)}.an-editor.-disabled{opacity:.6;pointer-events:none}.an-editor__body{position:relative}.an-editor__content{font-size:var(--an-editor-font-size,15px);line-height:1.6;min-height:var(--an-editor-min-height,200px);outline:none;padding:16px}.an-editor__content.-empty:before{color:#999;content:attr(data-placeholder);pointer-events:none}.an-editor__content :deep(h1){font-size:2em;font-weight:700;margin:.5em 0}.an-editor__content :deep(h2){font-size:1.5em;font-weight:700;margin:.5em 0}.an-editor__content :deep(h3){font-size:1.17em;font-weight:700;margin:.5em 0}.an-editor__content :deep(h4){font-size:1em;font-weight:700;margin:.5em 0}.an-editor__content :deep(h5){font-size:.83em;font-weight:700;margin:.5em 0}.an-editor__content :deep(h6){font-size:.67em;font-weight:700;margin:.5em 0}.an-editor__content :deep(strong){font-weight:700}.an-editor__content :deep(em){font-style:italic}.an-editor__content :deep(s){text-decoration:line-through}.an-editor__content :deep(a){color:#7c83ff;cursor:pointer;text-decoration:underline}.an-editor__content :deep(blockquote){border-left:3px solid #e0e0e0;color:#666;margin:12px 0;padding-left:16px}.an-editor__content :deep(ol),.an-editor__content :deep(ul){margin:8px 0;padding-left:24px}.an-editor__content :deep(code){background:#f4f4f5;border-radius:4px;font-family:SF Mono,Fira Code,monospace;font-size:.9em;padding:2px 6px}.an-editor__content :deep(pre){background:#1e1e2e;border-radius:8px;color:#cdd6f4;margin:12px 0;min-height:3em;overflow-x:auto;padding:16px}.an-editor__content :deep(pre) code{background:none;border-radius:0;color:inherit;display:block;min-height:1.4em;outline:none;padding:0}.an-editor__content :deep(hr){border:none;border-top:2px solid #e0e0e0;margin:16px 0}.an-editor__content :deep(.an-editor__youtube){cursor:pointer;margin:12px 0;width:100%}.an-editor__content :deep(.an-editor__youtube) iframe{aspect-ratio:16/9;border:none;border-radius:8px;pointer-events:none;width:100%}.an-editor__content :deep(.an-editor__html){cursor:pointer;margin:12px 0;width:100%}.an-editor__content :deep(.an-editor__html)>*{pointer-events:none}.an-editor__content :deep(.an-editor__html) iframe{border:none;border-radius:8px;min-height:300px;width:100%}.an-editor__content :deep(.an-editor__image){cursor:pointer;margin:12px 0;position:relative}.an-editor__content :deep(.an-editor__image) img{border-radius:8px;display:block;max-width:100%;transition:filter .15s}.an-editor__content :deep(.an-editor__image):hover img{filter:brightness(.92)}.an-editor__content :deep(.an-editor__table){border-collapse:collapse;font-size:.95em;margin:12px 0;width:100%}.an-editor__content :deep(.an-editor__table) td,.an-editor__content :deep(.an-editor__table) th{border:1px solid #d0d5dd;box-sizing:border-box;cursor:text;line-height:1.5;min-width:60px;outline:none;padding:8px 12px;text-align:left}.an-editor__content :deep(.an-editor__table) th{background:#f4f5f7;font-weight:600}.an-editor__content :deep(.an-editor__table) tr:hover td{background:#f9fafb}.an-editor__content :deep(p){margin:8px 0}.an-editor__content :deep(p):first-child{margin-top:0}.an-editor__content :deep(p):last-child{margin-bottom:0}.an-editor__table-actions{background:#fff;border:1px solid #e8eaed;border-radius:8px;box-shadow:0 4px 16px rgba(0,0,0,.1);min-width:160px;padding:4px;position:absolute;z-index:10}.an-editor__table-actions-divider{background:#e8eaed;height:1px;margin:4px 0}.an-editor__table-action-btn{background:none;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;display:block;font-size:13px;padding:8px 12px;text-align:left;transition:background .1s;width:100%}.an-editor__table-action-btn:hover{background:#f4f5f7}.an-editor__table-action-btn.-danger{color:#ff6b6b}.an-editor__table-action-btn.-danger:hover{background:#fff5f5}.an-editor__image-overlay{border:2px solid #7c83ff;border-radius:8px;pointer-events:none;position:absolute;z-index:10}.an-editor__image-edit,.an-editor__image-expand{align-items:center;background:rgba(0,0,0,.55);border:none;border-radius:6px;color:#fff;cursor:pointer;display:flex;font-size:18px;height:32px;justify-content:center;pointer-events:auto;position:absolute;top:8px;transition:background .15s;width:32px}.an-editor__image-edit:hover,.an-editor__image-expand:hover{background:rgba(0,0,0,.75)}.an-editor__image-expand{right:8px}.an-editor__image-edit{right:46px}.an-editor__image-resize{background:#7c83ff;border-radius:2px 0 8px 0;bottom:-2px;cursor:nwse-resize;height:16px;pointer-events:auto;position:absolute;right:-2px;width:16px}.an-editor__image-resize:before{border-bottom:2px solid #fff;border-right:2px solid #fff;bottom:3px;content:"";height:6px;position:absolute;right:3px;width:6px}
630
691
  </style>
@@ -23,7 +23,15 @@ const onDelete = () => {
23
23
 
24
24
  <div v-for="field in params.fields" :key="field.key" class="an-editor-prompt__field">
25
25
  <label class="an-editor-prompt__label">{{ field.label }}</label>
26
+ <textarea
27
+ v-if="field.type === 'textarea'"
28
+ v-model="form[field.key]"
29
+ class="an-editor-prompt__input -textarea"
30
+ :placeholder="field.placeholder"
31
+ @keydown.enter.stop
32
+ />
26
33
  <input
34
+ v-else
27
35
  v-model="form[field.key]"
28
36
  class="an-editor-prompt__input"
29
37
  :placeholder="field.placeholder"
@@ -46,5 +54,5 @@ const onDelete = () => {
46
54
  </template>
47
55
 
48
56
  <style scoped>
49
- .an-editor-prompt{background:#fff;border-radius:12px;max-width:440px;min-width:360px;padding:24px}.an-editor-prompt__title{color:#1a1a2e;font-size:16px;font-weight:600;margin-bottom:16px}.an-editor-prompt__field{margin-bottom:12px}.an-editor-prompt__label{color:#344054;display:block;font-size:13px;font-weight:500;margin-bottom:4px}.an-editor-prompt__input{border:1px solid #d0d5dd;border-radius:6px;box-sizing:border-box;font-size:14px;outline:none;padding:8px 12px;transition:border-color .15s;width:100%}.an-editor-prompt__input:focus{border-color:#7c83ff}.an-editor-prompt__actions{display:flex;gap:8px;margin-top:16px}.an-editor-prompt__btn{border:none;border-radius:6px;cursor:pointer;font-size:13px;font-weight:500;padding:8px 16px;transition:all .15s}.an-editor-prompt__btn.-primary{background:#7c83ff;color:#fff}.an-editor-prompt__btn.-primary:hover{background:#6269e0}.an-editor-prompt__btn.-secondary{background:#e8eaed;color:#1a1a2e}.an-editor-prompt__btn.-secondary:hover{background:#d0d5dd}.an-editor-prompt__btn.-danger{background:#ff6b6b;color:#fff;margin-left:auto}.an-editor-prompt__btn.-danger:hover{background:#e05555}
57
+ .an-editor-prompt{background:#fff;border-radius:12px;max-width:440px;min-width:360px;padding:24px}.an-editor-prompt__title{color:#1a1a2e;font-size:16px;font-weight:600;margin-bottom:16px}.an-editor-prompt__field{margin-bottom:12px}.an-editor-prompt__label{color:#344054;display:block;font-size:13px;font-weight:500;margin-bottom:4px}.an-editor-prompt__input{border:1px solid #d0d5dd;border-radius:6px;box-sizing:border-box;font-size:14px;outline:none;padding:8px 12px;transition:border-color .15s;width:100%}.an-editor-prompt__input:focus{border-color:#7c83ff}.an-editor-prompt__input.-textarea{font-family:SF Mono,Fira Code,monospace;font-size:13px;line-height:1.5;min-height:120px;resize:vertical}.an-editor-prompt__actions{display:flex;gap:8px;margin-top:16px}.an-editor-prompt__btn{border:none;border-radius:6px;cursor:pointer;font-size:13px;font-weight:500;padding:8px 16px;transition:all .15s}.an-editor-prompt__btn.-primary{background:#7c83ff;color:#fff}.an-editor-prompt__btn.-primary:hover{background:#6269e0}.an-editor-prompt__btn.-secondary{background:#e8eaed;color:#1a1a2e}.an-editor-prompt__btn.-secondary:hover{background:#d0d5dd}.an-editor-prompt__btn.-danger{background:#ff6b6b;color:#fff;margin-left:auto}.an-editor-prompt__btn.-danger:hover{background:#e05555}
50
58
  </style>
@@ -182,6 +182,13 @@ const isActive = (format) => {
182
182
  >
183
183
  <Icon name="aneditor:youtube" />
184
184
  </button>
185
+ <button
186
+ class="an-editor-toolbar__btn"
187
+ title="Embed iframe"
188
+ @click.prevent="onAction('iframe')"
189
+ >
190
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="18" height="18"><rect x="2" y="4" width="20" height="16" rx="2"/><line x1="2" y1="8" x2="22" y2="8"/><circle cx="5" cy="6" r="0.5" fill="currentColor"/><circle cx="7.5" cy="6" r="0.5" fill="currentColor"/><circle cx="10" cy="6" r="0.5" fill="currentColor"/></svg>
191
+ </button>
185
192
  </div>
186
193
  </div>
187
194
  </template>
@@ -12,5 +12,5 @@ const html = computed(() => parseMarkdown(props.content));
12
12
  </template>
13
13
 
14
14
  <style scoped>
15
- .an-editor-viewer{font-size:var(--an-editor-font-size,15px);line-height:1.6}.an-editor-viewer :deep(h1){font-size:2em;font-weight:700;margin:.5em 0}.an-editor-viewer :deep(h2){font-size:1.5em;font-weight:700;margin:.5em 0}.an-editor-viewer :deep(h3){font-size:1.17em;font-weight:700;margin:.5em 0}.an-editor-viewer :deep(h4){font-size:1em;font-weight:700;margin:.5em 0}.an-editor-viewer :deep(h5){font-size:.83em;font-weight:700;margin:.5em 0}.an-editor-viewer :deep(h6){font-size:.67em;font-weight:700;margin:.5em 0}.an-editor-viewer :deep(strong){font-weight:700}.an-editor-viewer :deep(em){font-style:italic}.an-editor-viewer :deep(s){text-decoration:line-through}.an-editor-viewer :deep(a){color:#7c83ff;text-decoration:underline}.an-editor-viewer :deep(blockquote){border-left:3px solid #e0e0e0;color:#666;margin:12px 0;padding-left:16px}.an-editor-viewer :deep(ol),.an-editor-viewer :deep(ul){margin:8px 0;padding-left:24px}.an-editor-viewer :deep(code){background:#f4f4f5;border-radius:4px;font-family:SF Mono,Fira Code,monospace;font-size:.9em;padding:2px 6px}.an-editor-viewer :deep(pre){background:#1e1e2e;border-radius:8px;color:#cdd6f4;margin:12px 0;min-height:3em;overflow-x:auto;padding:16px}.an-editor-viewer :deep(pre) code{background:none;border-radius:0;color:inherit;display:block;min-height:1.4em;padding:0}.an-editor-viewer :deep(hr){border:none;border-top:2px solid #e0e0e0;margin:16px 0}.an-editor-viewer :deep(.an-editor__youtube){margin:12px 0}.an-editor-viewer :deep(.an-editor__youtube) iframe{aspect-ratio:16/9;border:none;border-radius:8px;width:100%}.an-editor-viewer :deep(.an-editor__image){margin:12px 0}.an-editor-viewer :deep(.an-editor__image) img{border-radius:8px;display:block;max-width:100%}.an-editor-viewer :deep(.an-editor__table){border-collapse:collapse;font-size:.95em;margin:12px 0;width:100%}.an-editor-viewer :deep(.an-editor__table) td,.an-editor-viewer :deep(.an-editor__table) th{border:1px solid #d0d5dd;box-sizing:border-box;line-height:1.5;min-width:60px;padding:8px 12px;text-align:left}.an-editor-viewer :deep(.an-editor__table) th{background:#f4f5f7;font-weight:600}.an-editor-viewer :deep(.an-editor__table) tr:hover td{background:#f9fafb}.an-editor-viewer :deep(p){margin:8px 0}.an-editor-viewer :deep(p):first-child{margin-top:0}.an-editor-viewer :deep(p):last-child{margin-bottom:0}
15
+ .an-editor-viewer{font-size:var(--an-editor-font-size,15px);line-height:1.6}.an-editor-viewer :deep(h1){font-size:2em;font-weight:700;margin:.5em 0}.an-editor-viewer :deep(h2){font-size:1.5em;font-weight:700;margin:.5em 0}.an-editor-viewer :deep(h3){font-size:1.17em;font-weight:700;margin:.5em 0}.an-editor-viewer :deep(h4){font-size:1em;font-weight:700;margin:.5em 0}.an-editor-viewer :deep(h5){font-size:.83em;font-weight:700;margin:.5em 0}.an-editor-viewer :deep(h6){font-size:.67em;font-weight:700;margin:.5em 0}.an-editor-viewer :deep(strong){font-weight:700}.an-editor-viewer :deep(em){font-style:italic}.an-editor-viewer :deep(s){text-decoration:line-through}.an-editor-viewer :deep(a){color:#7c83ff;text-decoration:underline}.an-editor-viewer :deep(blockquote){border-left:3px solid #e0e0e0;color:#666;margin:12px 0;padding-left:16px}.an-editor-viewer :deep(ol),.an-editor-viewer :deep(ul){margin:8px 0;padding-left:24px}.an-editor-viewer :deep(code){background:#f4f4f5;border-radius:4px;font-family:SF Mono,Fira Code,monospace;font-size:.9em;padding:2px 6px}.an-editor-viewer :deep(pre){background:#1e1e2e;border-radius:8px;color:#cdd6f4;margin:12px 0;min-height:3em;overflow-x:auto;padding:16px}.an-editor-viewer :deep(pre) code{background:none;border-radius:0;color:inherit;display:block;min-height:1.4em;padding:0}.an-editor-viewer :deep(hr){border:none;border-top:2px solid #e0e0e0;margin:16px 0}.an-editor-viewer :deep(.an-editor__youtube){margin:12px 0;width:100%}.an-editor-viewer :deep(.an-editor__youtube) iframe{aspect-ratio:16/9;border:none;border-radius:8px;width:100%}.an-editor-viewer :deep(.an-editor__html){margin:12px 0;width:100%}.an-editor-viewer :deep(.an-editor__html) iframe{border:none;border-radius:8px;min-height:300px;width:100%}.an-editor-viewer :deep(.an-editor__image){margin:12px 0}.an-editor-viewer :deep(.an-editor__image) img{border-radius:8px;display:block;max-width:100%}.an-editor-viewer :deep(.an-editor__table){border-collapse:collapse;font-size:.95em;margin:12px 0;width:100%}.an-editor-viewer :deep(.an-editor__table) td,.an-editor-viewer :deep(.an-editor__table) th{border:1px solid #d0d5dd;box-sizing:border-box;line-height:1.5;min-width:60px;padding:8px 12px;text-align:left}.an-editor-viewer :deep(.an-editor__table) th{background:#f4f5f7;font-weight:600}.an-editor-viewer :deep(.an-editor__table) tr:hover td{background:#f9fafb}.an-editor-viewer :deep(p){margin:8px 0}.an-editor-viewer :deep(p):first-child{margin-top:0}.an-editor-viewer :deep(p):last-child{margin-bottom:0}
16
16
  </style>
@@ -1,5 +1,5 @@
1
1
  import { type Ref } from 'vue';
2
- export declare const useImage: (refContent: Ref<HTMLDivElement | null>, syncToModel: () => void) => {
2
+ export declare const useEditorImage: (refContent: Ref<HTMLDivElement | null>, syncToModel: () => void) => {
3
3
  activeImage: Ref<{
4
4
  img: HTMLImageElement;
5
5
  figure: HTMLElement;
@@ -1,6 +1,6 @@
1
1
  import { ref, computed, nextTick, onScopeDispose } from "vue";
2
2
  import { useThrottleFn } from "@vueuse/core";
3
- export const useImage = (refContent, syncToModel) => {
3
+ export const useEditorImage = (refContent, syncToModel) => {
4
4
  const activeImage = ref(null);
5
5
  const imageResizing = ref(null);
6
6
  const createImageElement = (url, alt = "") => {
@@ -54,6 +54,10 @@ export const parseMarkdown = (md) => {
54
54
  output.push(`<div class="an-editor__youtube"><iframe src="https://www.youtube-nocookie.com/embed/${ytId}" style="border:none" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>`);
55
55
  continue;
56
56
  }
57
+ if (/^<(?!img\s)/i.test(block) && /<\/\w+>$/.test(block)) {
58
+ output.push(`<div class="an-editor__html">${block}</div>`);
59
+ continue;
60
+ }
57
61
  const imgMatch = block.match(/^!\[([^\]]*)\]\(([^)]+)\)$/);
58
62
  if (imgMatch) {
59
63
  output.push(`<figure class="an-editor__image"><img src="${escapeHtml(imgMatch[2])}" alt="${escapeHtml(imgMatch[1])}" /></figure>`);
@@ -206,6 +206,10 @@ ${content}
206
206
  }
207
207
  }
208
208
  }
209
+ if (tag === "div" && el.classList.contains("an-editor__html")) {
210
+ result += el.innerHTML.trim() + "\n\n";
211
+ continue;
212
+ }
209
213
  if (tag === "p") {
210
214
  const inner = walkNodes(el).trim();
211
215
  if (inner) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anweb/nuxt-aneditor",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "AnEditor Nuxt module — WYSIWYG markdown editor",
5
5
  "repository": "https://github.com/ANLTD/aneditor",
6
6
  "license": "MIT",