Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into feat/editor-search-…
Browse files Browse the repository at this point in the history
…and-replace
  • Loading branch information
LIlGG committed Jan 22, 2024
2 parents 6735780 + 14580b9 commit 140b7e9
Show file tree
Hide file tree
Showing 23 changed files with 1,214 additions and 487 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import type { Attachment, Group, Policy } from "@halo-dev/api-client";
import { computed, nextTick, type Ref } from "vue";
import { ref, watch } from "vue";
import type { AttachmentLike } from "@halo-dev/console-shared";
import { apiClient } from "@/utils/api-client";
import { Dialog, Toast } from "@halo-dev/components";
import type { Content, Editor } from "@halo-dev/richtext-editor";
import { useQuery } from "@tanstack/vue-query";
import { useI18n } from "vue-i18n";
import { useClipboard } from "@vueuse/core";
Expand All @@ -28,10 +26,6 @@ interface useAttachmentControlReturn {
handleReset: () => void;
}

interface useAttachmentSelectReturn {
onAttachmentSelect: (attachments: AttachmentLike[]) => void;
}

export function useAttachmentControl(filterOptions: {
policy?: Ref<Policy | undefined>;
group?: Ref<Group | undefined>;
Expand Down Expand Up @@ -219,86 +213,6 @@ export function useAttachmentControl(filterOptions: {
};
}

export function useAttachmentSelect(
editor: Ref<Editor | undefined>
): useAttachmentSelectReturn {
const onAttachmentSelect = (attachments: AttachmentLike[]) => {
const contents: Content[] = attachments
.map((attachment) => {
if (typeof attachment === "string") {
return {
type: "image",
attrs: {
src: attachment,
},
};
}

if ("url" in attachment) {
return {
type: "image",
attrs: {
src: attachment.url,
alt: attachment.type,
},
};
}

if ("spec" in attachment) {
const { mediaType, displayName } = attachment.spec;
const { permalink } = attachment.status || {};
if (mediaType?.startsWith("image/")) {
return {
type: "image",
attrs: {
src: permalink,
alt: displayName,
},
};
}

if (mediaType?.startsWith("video/")) {
return {
type: "video",
attrs: {
src: permalink,
},
};
}

if (mediaType?.startsWith("audio/")) {
return {
type: "audio",
attrs: {
src: permalink,
},
};
}

return {
type: "text",
marks: [
{
type: "link",
attrs: {
href: permalink,
},
},
],
text: displayName,
};
}
})
.filter(Boolean) as Content[];

editor.value?.chain().focus().insertContent(contents).run();
};

return {
onAttachmentSelect,
};
}

export function useAttachmentPermalinkCopy(
attachment: Ref<Attachment | undefined>
) {
Expand Down
16 changes: 10 additions & 6 deletions console/console-src/modules/contents/pages/SinglePageEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { useContentSnapshot } from "@console/composables/use-content-snapshot";
import { useSaveKeybinding } from "@console/composables/use-save-keybinding";
import { useSessionKeepAlive } from "@/composables/use-session-keep-alive";
import { usePermission } from "@/utils/permission";
import type { AxiosRequestConfig } from "axios";
const router = useRouter();
const { t } = useI18n();
Expand Down Expand Up @@ -380,19 +381,22 @@ useSaveKeybinding(handleSave);
useSessionKeepAlive();
// Upload image
async function handleUploadImage(file: File) {
async function handleUploadImage(file: File, options?: AxiosRequestConfig) {
if (!currentUserHasPermission(["uc:attachments:manage"])) {
return;
}
if (!isUpdateMode.value) {
await handleSave();
}
const { data } = await apiClient.uc.attachment.createAttachmentForPost({
file,
singlePageName: formState.value.page.metadata.name,
waitForPermalink: true,
});
const { data } = await apiClient.uc.attachment.createAttachmentForPost(
{
file,
singlePageName: formState.value.page.metadata.name,
waitForPermalink: true,
},
options
);
return data;
}
</script>
Expand Down
16 changes: 10 additions & 6 deletions console/console-src/modules/contents/posts/PostEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { useContentSnapshot } from "@console/composables/use-content-snapshot";
import { useSaveKeybinding } from "@console/composables/use-save-keybinding";
import { useSessionKeepAlive } from "@/composables/use-session-keep-alive";
import { usePermission } from "@/utils/permission";
import type { AxiosRequestConfig } from "axios";
const router = useRouter();
const { t } = useI18n();
Expand Down Expand Up @@ -405,7 +406,7 @@ useSaveKeybinding(handleSave);
useSessionKeepAlive();
// Upload image
async function handleUploadImage(file: File) {
async function handleUploadImage(file: File, options?: AxiosRequestConfig) {
if (!currentUserHasPermission(["uc:attachments:manage"])) {
return;
}
Expand All @@ -414,11 +415,14 @@ async function handleUploadImage(file: File) {
await handleSave();
}
const { data } = await apiClient.uc.attachment.createAttachmentForPost({
file,
postName: formState.value.post.metadata.name,
waitForPermalink: true,
});
const { data } = await apiClient.uc.attachment.createAttachmentForPost(
{
file,
postName: formState.value.post.metadata.name,
waitForPermalink: true,
},
options
);
return data;
}
</script>
Expand Down
3 changes: 1 addition & 2 deletions console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@halo-dev/console-shared": "workspace:*",
"@halo-dev/richtext-editor": "workspace:*",
"@tanstack/vue-query": "^4.29.1",
"@tiptap/extension-character-count": "^2.1.15",
"@tiptap/extension-character-count": "^2.1.16",
"@uppy/core": "^3.8.0",
"@uppy/dashboard": "^3.7.1",
"@uppy/drag-drop": "^3.0.3",
Expand All @@ -80,7 +80,6 @@
"cropperjs": "^1.5.13",
"dayjs": "^1.11.7",
"emoji-mart": "^5.3.3",
"fastq": "^1.15.0",
"floating-vue": "2.0.0-beta.24",
"fuse.js": "^6.6.2",
"jsencrypt": "^3.3.2",
Expand Down
2 changes: 2 additions & 0 deletions console/packages/components/src/icons/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import IconNotificationBadgeLine from "~icons/ri/notification-badge-line";
import IconLogoutCircleRLine from "~icons/ri/logout-circle-r-line";
import IconAccountCircleLine from "~icons/ri/account-circle-line";
import IconSettings3Line from "~icons/ri/settings-3-line";
import IconImageAddLine from "~icons/ri/image-add-line";

export {
IconDashboard,
Expand Down Expand Up @@ -144,4 +145,5 @@ export {
IconLogoutCircleRLine,
IconAccountCircleLine,
IconSettings3Line,
IconImageAddLine,
};
74 changes: 37 additions & 37 deletions console/packages/editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,44 +41,44 @@
},
"dependencies": {
"@ckpack/vue-color": "^1.5.0",
"@tiptap/core": "^2.1.15",
"@tiptap/extension-blockquote": "^2.1.15",
"@tiptap/extension-bold": "^2.1.15",
"@tiptap/extension-bullet-list": "^2.1.15",
"@tiptap/extension-code": "^2.1.15",
"@tiptap/extension-code-block": "^2.1.15",
"@tiptap/extension-code-block-lowlight": "^2.1.15",
"@tiptap/extension-color": "^2.1.15",
"@tiptap/extension-document": "^2.1.15",
"@tiptap/extension-dropcursor": "^2.1.15",
"@tiptap/extension-gapcursor": "^2.1.15",
"@tiptap/extension-hard-break": "^2.1.15",
"@tiptap/extension-heading": "^2.1.15",
"@tiptap/extension-highlight": "^2.1.15",
"@tiptap/extension-history": "^2.1.15",
"@tiptap/extension-horizontal-rule": "^2.1.15",
"@tiptap/extension-image": "^2.1.15",
"@tiptap/extension-italic": "^2.1.15",
"@tiptap/extension-link": "^2.1.15",
"@tiptap/extension-list-item": "^2.1.15",
"@tiptap/extension-list-keymap": "^2.1.15",
"@tiptap/extension-ordered-list": "^2.1.15",
"@tiptap/extension-paragraph": "^2.1.15",
"@tiptap/extension-placeholder": "^2.1.15",
"@tiptap/extension-strike": "^2.1.15",
"@tiptap/extension-subscript": "^2.1.15",
"@tiptap/extension-superscript": "^2.1.15",
"@tiptap/core": "^2.1.16",
"@tiptap/extension-blockquote": "^2.1.16",
"@tiptap/extension-bold": "^2.1.16",
"@tiptap/extension-bullet-list": "^2.1.16",
"@tiptap/extension-code": "^2.1.16",
"@tiptap/extension-code-block": "^2.1.16",
"@tiptap/extension-code-block-lowlight": "^2.1.16",
"@tiptap/extension-color": "^2.1.16",
"@tiptap/extension-document": "^2.1.16",
"@tiptap/extension-dropcursor": "^2.1.16",
"@tiptap/extension-gapcursor": "^2.1.16",
"@tiptap/extension-hard-break": "^2.1.16",
"@tiptap/extension-heading": "^2.1.16",
"@tiptap/extension-highlight": "^2.1.16",
"@tiptap/extension-history": "^2.1.16",
"@tiptap/extension-horizontal-rule": "^2.1.16",
"@tiptap/extension-image": "^2.1.16",
"@tiptap/extension-italic": "^2.1.16",
"@tiptap/extension-link": "^2.1.16",
"@tiptap/extension-list-item": "^2.1.16",
"@tiptap/extension-list-keymap": "^2.1.16",
"@tiptap/extension-ordered-list": "^2.1.16",
"@tiptap/extension-paragraph": "^2.1.16",
"@tiptap/extension-placeholder": "^2.1.16",
"@tiptap/extension-strike": "^2.1.16",
"@tiptap/extension-subscript": "^2.1.16",
"@tiptap/extension-superscript": "^2.1.16",
"@tiptap/extension-table": "2.2.0-rc.8",
"@tiptap/extension-table-row": "^2.1.15",
"@tiptap/extension-task-item": "^2.1.15",
"@tiptap/extension-task-list": "^2.1.15",
"@tiptap/extension-text": "^2.1.15",
"@tiptap/extension-text-align": "^2.1.15",
"@tiptap/extension-text-style": "^2.1.15",
"@tiptap/extension-underline": "^2.1.15",
"@tiptap/pm": "^2.1.15",
"@tiptap/suggestion": "^2.1.15",
"@tiptap/vue-3": "^2.1.15",
"@tiptap/extension-table-row": "^2.1.16",
"@tiptap/extension-task-item": "^2.1.16",
"@tiptap/extension-task-list": "^2.1.16",
"@tiptap/extension-text": "^2.1.16",
"@tiptap/extension-text-align": "^2.1.16",
"@tiptap/extension-text-style": "^2.1.16",
"@tiptap/extension-underline": "^2.1.16",
"@tiptap/pm": "^2.1.16",
"@tiptap/suggestion": "^2.1.16",
"@tiptap/vue-3": "^2.1.16",
"floating-vue": "2.0.0-beta.24",
"github-markdown-css": "^5.2.0",
"highlight.js": "11.8.0",
Expand Down
1 change: 1 addition & 0 deletions console/packages/editor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export * from "./tiptap";
export * from "./extensions";
export * from "./components";
export * from "./utils";
// TODO: export * from "./types";
1 change: 1 addition & 0 deletions console/packages/editor/src/tiptap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export {
textblockTypeInputRule,
wrappingInputRule,
} from "./vue-3";
export { Editor as CoreEditor } from "./core";
export {
type Command as PMCommand,
InputRule as PMInputRule,
Expand Down
Loading

0 comments on commit 140b7e9

Please sign in to comment.