Skip to content

Commit

Permalink
improve component api
Browse files Browse the repository at this point in the history
  • Loading branch information
MrWangJustToDo committed Mar 21, 2024
1 parent 706dd06 commit 6632bd2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
2 changes: 2 additions & 0 deletions packages/lowlight/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,6 @@ Object.defineProperty(instance, "processAST", {
},
});

export { processAST } from "./processAST";

export const highlighter: Highlighter = instance as Highlighter;
2 changes: 1 addition & 1 deletion packages/vue/src/components/DiffView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export const DiffView = defineComponent<

onUnmounted(() => diffFile.value._destroy?.());

options.expose({ getDiffView: () => diffFile.value });
options.expose({ getDiffFileInstance: () => diffFile.value });

return () => {
if (!diffFile.value) return null;
Expand Down
16 changes: 7 additions & 9 deletions ui/react-example/src/Example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ export function Example() {
<div className="border border-solid border-[rgb(200,200,200)] rounded-[4px]">
<div className="my-[5px] mx-[4px]">
<div className="w-[24px] h-[24px] inline-flex items-center justify-center rounded-full bg-slate-300">
W
@
</div>
<span className="mx-[2px]">:</span>
<span className="text-[12px]">{new Date().toDateString()}</span>
<span className="text-[11px] mx-[4px] text-[grey]">:</span>
<span className="text-[11px] text-[grey]">{new Date().toLocaleString()}</span>
</div>
<div className="bg-[rgb(210,210,210)] h-[1px] my-[5px]"></div>
<div className="indent-1 my-[5px] mx-[4px]">
Expand Down Expand Up @@ -246,15 +246,13 @@ export function Example() {
h(
"div",
{ class: "w-[24px] h-[24px] inline-flex items-center justify-center rounded-full bg-slate-300" },
"W"
"@"
),
h("span", { class: "mx-[2px]" }, ":"),
h("span", { class: "text-[12px]" }, new Date().toDateString()),
h("span", { class: "text-[11px] mx-[4px] text-[grey]" }, ":"),
h("span", { class: "text-[11px] text-[grey]" }, new Date().toLocaleString()),
]),
h("div", { class: "bg-[rgb(210,210,210)] h-[1px] my-[5px]" }),
h("div", { class: "indent-1 my-[5px] mx-[4px]" }, [
h("span", { class: "text-[15px]" }, data),
]),
h("div", { class: "indent-1 my-[5px] mx-[4px]" }, [h("span", { class: "text-[15px]" }, data)]),
]),
]);
},
Expand Down
2 changes: 1 addition & 1 deletion ui/react-example/src/worker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DiffFile } from "@git-diff-view/react";
// import { highlighter } from "@git-diff-view/shiki";
import { DiffFile } from "@git-diff-view/vue";

import type { DiffViewProps } from "@git-diff-view/react";

Expand Down
21 changes: 14 additions & 7 deletions ui/vue-example/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { computed, ref, watch } from "vue";
import { computed, onMounted, ref, watch } from "vue";
import * as data from "./data";
import { DiffModeEnum, DiffView, DiffViewProps, SplitSide, DiffFile } from "@git-diff-view/vue";
import { MessageData } from "./worker";
Expand Down Expand Up @@ -35,6 +35,12 @@ const k = ref<Key>("a");
const v = ref("");
const instance = ref<{ getDiffFileInstance: () => DiffFile }>();
onMounted(() => {
console.log(instance.value);
})
const _data = computed(() => data[k.value]);
const extendData = ref<DiffViewProps<any>["extendData"]>({ oldFile: {}, newFile: {} });
Expand Down Expand Up @@ -89,20 +95,21 @@ const resetV = () => (v.value = "");
</div>
<div class="w-[90%] m-auto border border-[#c1c1c1] border-solid rounded-[5px] overflow-hidden mb-[5em]">
<DiffView :diff-file="diffFile" :diff-view-font-size="14" :diff-view-mode="mode" :diff-view-highlight="highlight"
:diff-view-add-widget="true" :diff-view-wrap="wrap" @on-add-widget-click="resetV" :extend-data="extendData">
:diff-view-add-widget="true" ref="instance" :diff-view-wrap="wrap" @on-add-widget-click="resetV"
:extend-data="extendData">
<template #widget="{ onClose, lineNumber, side }">
<div class="border flex flex-col w-full px-[4px] py-[8px]">
<textarea class="w-full border min-h-[80px] p-[2px]" v-model="v" />
<div class="m-[5px] mt-[0.8em] text-right">
<div class="inline-flex gap-x-[12px] justify-end">
<button class="border px-[12px] py-[6px] rounded-[4px]" @click="onClose">cancel</button>
<button class="border px-[12px] py-[6px] rounded-[4px]" @click="() => {
if (v.length) {
const _side = side === SplitSide.old ? 'oldFile' : 'newFile';
extendData![_side]![lineNumber] = { data: v };
onClose();
}
if (v.length) {
const _side = side === SplitSide.old ? 'oldFile' : 'newFile';
extendData![_side]![lineNumber] = { data: v };
onClose();
}
}
">
submit
</button>
Expand Down

0 comments on commit 6632bd2

Please sign in to comment.