vuewrite 0.0.5 → 0.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.
@@ -43,9 +43,14 @@ export declare type Style = {
43
43
  export declare const TextEditor: __VLS_WithTemplateSlots<DefineComponent<__VLS_TypePropsToRuntimeProps<{
44
44
  decorator?: Decorator | undefined;
45
45
  single?: boolean | undefined;
46
- modelValue?: string | string[] | undefined;
47
- styles?: Style[] | Style[][] | undefined;
46
+ modelValue?: string | {
47
+ text: string;
48
+ styles?: Style[] | undefined;
49
+ type?: string | undefined;
50
+ }[] | undefined;
51
+ styles?: Style[] | undefined;
48
52
  autofocus?: boolean | undefined;
53
+ autoselect?: boolean | undefined;
49
54
  }>, {
50
55
  currentStyles: ComputedRef<Map<string, Style>>;
51
56
  currentBlock: ComputedRef< {
@@ -83,9 +88,14 @@ keydown: (...args: any[]) => void;
83
88
  }, string, PublicProps, Readonly<ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
84
89
  decorator?: Decorator | undefined;
85
90
  single?: boolean | undefined;
86
- modelValue?: string | string[] | undefined;
87
- styles?: Style[] | Style[][] | undefined;
91
+ modelValue?: string | {
92
+ text: string;
93
+ styles?: Style[] | undefined;
94
+ type?: string | undefined;
95
+ }[] | undefined;
96
+ styles?: Style[] | undefined;
88
97
  autofocus?: boolean | undefined;
98
+ autoselect?: boolean | undefined;
89
99
  }>>> & {
90
100
  onKeydown?: ((...args: any[]) => any) | undefined;
91
101
  "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
package/dist/vuewrite.js CHANGED
@@ -415,7 +415,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
415
415
  return props.slots[props.block.type] ?? null;
416
416
  });
417
417
  const blockProps = {
418
- "data-block-id": props.block.id
418
+ "data-vw-block-id": props.block.id
419
419
  };
420
420
  const renderBlockPart = (text, styles) => {
421
421
  if (!props.decorator)
@@ -543,7 +543,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
543
543
  single: { type: Boolean },
544
544
  modelValue: {},
545
545
  styles: {},
546
- autofocus: { type: Boolean }
546
+ autofocus: { type: Boolean },
547
+ autoselect: { type: Boolean }
547
548
  },
548
549
  emits: ["keydown", "update:modelValue", "update:styles"],
549
550
  setup(__props, { expose: __expose, emit: __emit }) {
@@ -565,7 +566,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
565
566
  }
566
567
  store.blocks.length = newValue.length;
567
568
  for (let i = 0; i < newValue.length; i++) {
568
- store.blocks[i].text = newValue[i];
569
+ store.blocks[i].text = newValue[i].text;
570
+ store.blocks[i].type = newValue[i].type;
571
+ store.blocks[i].text = newValue[i].text;
569
572
  }
570
573
  }
571
574
  }, { immediate: true });
@@ -576,20 +579,23 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
576
579
  for (let i = 0; i < store.blocks.length; i++) {
577
580
  if (newStyles.length <= i)
578
581
  break;
579
- const style = props.single ? newStyles : newStyles[i];
580
- store.blocks[i].styles = style;
582
+ store.blocks[i].styles = newStyles;
581
583
  }
582
584
  }, { immediate: true });
583
585
  watch(() => store.blocks, () => {
584
586
  if (props.single) {
585
587
  modelValue = store.blocks[0].text;
586
588
  styles = store.blocks[0].styles;
589
+ emit("update:styles", styles);
590
+ emit("update:modelValue", modelValue);
587
591
  } else {
588
- modelValue = store.blocks.map((item) => item.text);
589
- styles = store.blocks.map((item) => item.styles);
592
+ modelValue = store.blocks.map((item) => ({
593
+ type: item.type,
594
+ text: item.text,
595
+ styles: item.styles.length === 0 ? void 0 : item.styles
596
+ }));
597
+ emit("update:modelValue", modelValue);
590
598
  }
591
- emit("update:modelValue", modelValue);
592
- emit("update:styles", styles);
593
599
  }, { deep: true });
594
600
  const onKeyDown = (e) => {
595
601
  emit("keydown", e);
@@ -617,15 +623,15 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
617
623
  let cachedSelection = {};
618
624
  useEventListener(document, "selectionchange", () => {
619
625
  const sel = window.getSelection();
620
- const anchor = findParent(sel.anchorNode, (el) => el.hasAttribute("data-block-id"));
626
+ const anchor = findParent(sel.anchorNode, (el) => el.hasAttribute("data-vw-block-id"));
621
627
  if (anchor) {
622
628
  const offset = anchor === sel.anchorNode ? 0 : calcOffsetToNode(anchor, sel.anchorNode) + sel.anchorOffset;
623
- store.selection.anchor = { blockId: anchor.getAttribute("data-block-id"), offset };
629
+ store.selection.anchor = { blockId: anchor.getAttribute("data-vw-block-id"), offset };
624
630
  }
625
- const focus = findParent(sel.focusNode, (el) => el.hasAttribute("data-block-id"));
631
+ const focus = findParent(sel.focusNode, (el) => el.hasAttribute("data-vw-block-id"));
626
632
  if (focus) {
627
633
  const offset = anchor === sel.focusNode ? 0 : calcOffsetToNode(focus, sel.focusNode) + sel.focusOffset;
628
- store.selection.focus = { blockId: focus.getAttribute("data-block-id"), offset };
634
+ store.selection.focus = { blockId: focus.getAttribute("data-vw-block-id"), offset };
629
635
  }
630
636
  if (store.isFocused.value !== !!focus || !!anchor) {
631
637
  store.isFocused.value = !!focus || !!anchor;
@@ -655,10 +661,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
655
661
  let anchor = null;
656
662
  let focus = null;
657
663
  for (let item of textEditorRef.value.children) {
658
- if (item.getAttribute("data-block-id") === store.selection.anchor.blockId) {
664
+ if (item.getAttribute("data-vw-block-id") === store.selection.anchor.blockId) {
659
665
  anchor = item;
660
666
  }
661
- if (item.getAttribute("data-block-id") === store.selection.focus.blockId) {
667
+ if (item.getAttribute("data-vw-block-id") === store.selection.focus.blockId) {
662
668
  focus = item;
663
669
  }
664
670
  }
@@ -672,11 +678,15 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
672
678
  };
673
679
  watch(() => store.selection, applySelection, { deep: true, flush: "post" });
674
680
  onMounted(() => {
675
- var _a;
681
+ var _a, _b;
676
682
  if (props.autofocus) {
677
683
  (_a = textEditorRef.value) == null ? void 0 : _a.focus();
678
684
  applySelection();
679
685
  }
686
+ if (props.autoselect) {
687
+ (_b = textEditorRef.value) == null ? void 0 : _b.focus();
688
+ store.selectAll();
689
+ }
680
690
  });
681
691
  const onCopy = (e) => {
682
692
  e.preventDefault();
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "vuewrite",
3
3
  "description": "Rich Text Editor based on Vue3 reactivity",
4
4
  "private": false,
5
- "version": "0.0.5",
5
+ "version": "0.0.6",
6
6
  "type": "module",
7
7
  "license": "MIT",
8
8
  "author": "den59k",