Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
ruibaby committed Mar 19, 2024
2 parents 496847d + fa26516 commit e832292
Show file tree
Hide file tree
Showing 21 changed files with 235 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public Mono<ListResult<CommentVo>> list(Ref ref, PageRequest pageParam) {
public Mono<ListResult<CommentWithReplyVo>> convertToWithReplyVo(ListResult<CommentVo> comments,
int replySize) {
return Flux.fromIterable(comments.getItems())
.flatMap(commentVo -> {
.concatMap(commentVo -> {
var commentName = commentVo.getMetadata().getName();
return listReply(commentName, 1, replySize)
.map(replyList -> CommentWithReplyVo.from(commentVo)
Expand Down
6 changes: 6 additions & 0 deletions application/src/main/resources/extensions/system-setting.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,17 @@ spec:
value: 'shortUUID'
- label: 'UUID'
value: 'UUID'
help: 此选项仅在创建文章时生效,修改此选项不会影响已有文章
- $formkit: attachmentPolicySelect
name: attachmentPolicyName
label: "附件存储策略"
value: "default-policy"
help: 用于指定在文章编辑器中上传的默认附件存储策略
- $formkit: attachmentGroupSelect
name: attachmentGroupName
label: "附件存储组"
value: ""
help: 用于指定在文章编辑器中上传的默认附件存储分组
- group: seo
label: SEO 设置
formSchema:
Expand Down Expand Up @@ -104,10 +107,12 @@ spec:
- $formkit: roleSelect
name: defaultRole
label: "默认角色"
help: 用户注册之后默认为用户分配的角色
- $formkit: attachmentPolicySelect
name: avatarPolicy
label: "头像存储位置"
value: "default-policy"
help: 指定用户上传头像的存储策略
- group: comment
label: 评论设置
formSchema:
Expand All @@ -119,6 +124,7 @@ spec:
name: requireReviewForNew
value: true
label: "新评论审核"
help: 开启之后,新评论需要管理员审核后才会显示
- $formkit: checkbox
name: systemUserOnly
value: true
Expand Down
21 changes: 12 additions & 9 deletions ui/console-src/composables/use-slugify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ export default function useSlugify(
auto: Ref<boolean>,
formType: FormType
) {
watch(
() => source.value,
() => {
if (auto.value) {
handleGenerateSlug(false, formType);
}
}
);

const handleGenerateSlug = (forceUpdate = false, formType: FormType) => {
const globalInfoStore = useGlobalInfoStore();
const mode = globalInfoStore.globalInfo?.postSlugGenerationStrategy;
Expand All @@ -60,6 +51,18 @@ export default function useSlugify(
target.value = Strategy[mode](source.value);
};

watch(
() => source.value,
() => {
if (auto.value) {
handleGenerateSlug(false, formType);
}
},
{
immediate: true,
}
);

return {
handleGenerateSlug,
};
Expand Down
32 changes: 27 additions & 5 deletions ui/console-src/modules/contents/pages/SinglePageEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import {
ref,
toRef,
type ComputedRef,
watch,
} from "vue";
import { apiClient } from "@/utils/api-client";
import { useRouteQuery } from "@vueuse/router";
import { cloneDeep } from "lodash-es";
import { useRouter } from "vue-router";
import { randomUUID } from "@/utils/id";
import { useContentCache } from "@/composables/use-content-cache";
Expand Down Expand Up @@ -69,7 +69,7 @@ const handleChangeEditorProvider = async (provider: EditorProvider) => {
};
// SinglePage form
const initialFormState: SinglePageRequest = {
const formState = ref<SinglePageRequest>({
page: {
spec: {
title: "",
Expand Down Expand Up @@ -101,13 +101,19 @@ const initialFormState: SinglePageRequest = {
content: "",
rawType: "HTML",
},
};
const formState = ref<SinglePageRequest>(cloneDeep(initialFormState));
});
const saving = ref(false);
const publishing = ref(false);
const settingModal = ref(false);
const isTitleChanged = ref(false);
watch(
() => formState.value.page.spec.title,
(newValue, oldValue) => {
isTitleChanged.value = newValue !== oldValue;
}
);
const isUpdateMode = computed(() => {
return !!formState.value.page.metadata.creationTimestamp;
});
Expand Down Expand Up @@ -143,15 +149,23 @@ const handleSave = async (options?: { mute?: boolean }) => {
}
if (isUpdateMode.value) {
if (isTitleChanged.value) {
formState.value.page = (
await singlePageUpdateMutate(formState.value.page)
).data;
}
const { data } = await apiClient.singlePage.updateSinglePageContent({
name: formState.value.page.metadata.name,
content: formState.value.content,
});
formState.value.page = data;
isTitleChanged.value = false;
} else {
// Clear new page content cache
handleClearCache();
const { data } = await apiClient.singlePage.draftSinglePage({
singlePageRequest: formState.value,
});
Expand Down Expand Up @@ -184,6 +198,12 @@ const handlePublish = async () => {
const { name: singlePageName } = formState.value.page.metadata;
const { permalink } = formState.value.page.status || {};
if (isTitleChanged.value) {
formState.value.page = (
await singlePageUpdateMutate(formState.value.page)
).data;
}
await apiClient.singlePage.updateSinglePageContent({
name: singlePageName,
content: formState.value.content,
Expand Down Expand Up @@ -224,6 +244,7 @@ const handlePublishClick = () => {
if (isUpdateMode.value) {
handlePublish();
} else {
// Set editor title to page
settingModal.value = true;
}
};
Expand Down Expand Up @@ -477,6 +498,7 @@ async function handleUploadImage(file: File, options?: AxiosRequestConfig) {
v-if="currentEditorProvider"
v-model:raw="formState.content.raw"
v-model:content="formState.content.content"
v-model:title="formState.page.spec.title"
:upload-image="handleUploadImage"
class="h-full"
@update="handleSetContentCache"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ watch(
formState.value = toRaw(value);
publishTime.value = toDatetimeLocal(formState.value.spec.publishTime);
}
},
{
immediate: true,
}
);
Expand Down
34 changes: 29 additions & 5 deletions ui/console-src/modules/contents/posts/PostEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import {
ref,
toRef,
type ComputedRef,
watch,
} from "vue";
import { cloneDeep } from "lodash-es";
import { apiClient } from "@/utils/api-client";
import { useRouteQuery } from "@vueuse/router";
import { useRouter } from "vue-router";
Expand Down Expand Up @@ -80,7 +80,7 @@ interface PostRequestWithContent extends PostRequest {
}
// Post form
const initialFormState: PostRequestWithContent = {
const formState = ref<PostRequestWithContent>({
post: {
spec: {
title: "",
Expand Down Expand Up @@ -114,13 +114,19 @@ const initialFormState: PostRequestWithContent = {
content: "",
rawType: "HTML",
},
};
const formState = ref<PostRequestWithContent>(cloneDeep(initialFormState));
});
const settingModal = ref(false);
const saving = ref(false);
const publishing = ref(false);
const isTitleChanged = ref(false);
watch(
() => formState.value.post.spec.title,
(newValue, oldValue) => {
isTitleChanged.value = newValue !== oldValue;
}
);
const isUpdateMode = computed(() => {
return !!formState.value.post.metadata.creationTimestamp;
});
Expand Down Expand Up @@ -155,15 +161,25 @@ const handleSave = async (options?: { mute?: boolean }) => {
}
if (isUpdateMode.value) {
// Save post title
if (isTitleChanged.value) {
formState.value.post = (
await postUpdateMutate(formState.value.post)
).data;
}
const { data } = await apiClient.post.updatePostContent({
name: formState.value.post.metadata.name,
content: formState.value.content,
});
formState.value.post = data;
isTitleChanged.value = false;
} else {
// Clear new post content cache
handleClearCache();
const { data } = await apiClient.post.draftPost({
postRequest: formState.value,
});
Expand Down Expand Up @@ -195,6 +211,12 @@ const handlePublish = async () => {
const { name: postName } = formState.value.post.metadata;
const { permalink } = formState.value.post.status || {};
if (isTitleChanged.value) {
formState.value.post = (
await postUpdateMutate(formState.value.post)
).data;
}
await apiClient.post.updatePostContent({
name: postName,
content: formState.value.content,
Expand Down Expand Up @@ -240,6 +262,7 @@ const handlePublishClick = () => {
if (isUpdateMode.value) {
handlePublish();
} else {
// Set editor title to post
settingModal.value = true;
}
};
Expand Down Expand Up @@ -503,6 +526,7 @@ async function handleUploadImage(file: File, options?: AxiosRequestConfig) {
v-if="currentEditorProvider"
v-model:raw="formState.content.raw"
v-model:content="formState.content.content"
v-model:title="formState.post.spec.title"
:upload-image="handleUploadImage"
class="h-full"
@update="handleSetContentCache"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ watch(
formState.value = toRaw(value);
publishTime.value = toDatetimeLocal(formState.value.spec.publishTime);
}
},
{
immediate: true,
}
);
Expand Down
5 changes: 5 additions & 0 deletions ui/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,10 @@ declare module "@formkit/inputs" {
type: "menuCheckbox";
value?: string[];
};

code: {
type: "code";
value?: string;
};
}
}
18 changes: 12 additions & 6 deletions ui/packages/editor/src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,20 @@ watch(
<editor-bubble-menu :editor="editor" />
<editor-header :editor="editor" />
<div class="h-full flex flex-row w-full overflow-hidden">
<editor-content
:editor="editor"
:style="contentStyles"
class="editor-content markdown-body flex-1 relative bg-white overflow-y-auto"
/>
<div class="overflow-y-auto flex-1 bg-white">
<div v-if="$slots.content" class="editor-header-extra">
<slot name="content" />
</div>

<editor-content
:editor="editor"
:style="contentStyles"
class="editor-content markdown-body relative"
/>
</div>
<div
v-if="$slots.extra"
class="h-full hidden sm:!block w-72 flex-shrink-0"
class="h-full hidden sm:!block w-72 flex-shrink-0 flex-none"
>
<slot name="extra"></slot>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,24 @@ export class SearchAndReplacePluginView {

public containerElement: HTMLElement;

public init: boolean;

constructor({ view, editor, element }: SearchAndReplacePluginViewProps) {
this.editor = editor;
this.view = view;
this.containerElement = element;
const { element: editorElement } = this.editor.options;
editorElement.insertAdjacentElement("afterbegin", this.containerElement);
this.init = false;
}

update() {
const { parentElement: editorParentElement } = this.editor.options.element;
if (!this.init && editorParentElement) {
editorParentElement.insertAdjacentElement(
"afterbegin",
this.containerElement
);
this.init = true;
}
return false;
}

Expand Down
8 changes: 7 additions & 1 deletion ui/packages/editor/src/styles/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
height: 48px;
}

.editor-header-extra {
width: 100%;
padding: $editorVerticalPadding 20px;
}

.editor-content {
width: 100%;
position: relative;
Expand Down Expand Up @@ -78,7 +83,8 @@
}

@media screen {
.ProseMirror {
.ProseMirror,
.editor-header-extra {
@media (min-width: 640px) {
padding: $editorVerticalPadding min($editorHorizontalPadding, 10%) !important;
}
Expand Down
Loading

0 comments on commit e832292

Please sign in to comment.