Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/components/ai/assistant/input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,15 @@ const exitAssistant = () => {
const replaceContent = () => {
// 记录插入前的选区位置
const { from, to } = editor.value?.state.selection ?? {}
const prevDocLength = editor.value?.state.doc.content.size || 0
const prevDocLength = editor.value?.state.doc.content.size ?? 0
editor.value?.chain().insertContent(result.content).run()
setSelectionText(editor.value, prevDocLength, from, to)
exitAssistant()
}

const insertContentAtAfter = () => {
const { to } = editor.value?.state.selection ?? {}
const prevDocLength = editor.value?.state.doc.content.size || 0
const prevDocLength = editor.value?.state.doc.content.size ?? 0
if (to) {
editor.value?.chain().insertContentAt(to, result.content).focus().run()
setSelectionText(editor.value, prevDocLength, to, to)
Expand All @@ -259,7 +259,7 @@ const insertContentAtAfter = () => {
const insertContentAtBelow = () => {
editor.value?.commands.selectParentNode()
const { to } = editor.value?.state.selection ?? {}
const prevDocLength = editor.value?.state.doc.content.size || 0
const prevDocLength = editor.value?.state.doc.content.size ?? 0
if (to) {
editor.value?.chain().insertContentAt(to, result.content).focus().run()
setSelectionText(editor.value, prevDocLength, to, to)
Expand Down
2 changes: 1 addition & 1 deletion src/components/container/search-replace.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ let replaceText = $ref<string>('')
const caseSensitive = $ref<boolean>(false)

const resultLength = computed(
() => editor.value?.storage.searchAndReplace?.results.length || 0,
() => editor.value?.storage.searchAndReplace?.results.length ?? 0,
)

const clear = () => {
Expand Down
6 changes: 5 additions & 1 deletion src/components/container/toc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { TextSelection } from '@tiptap/pm/state'

const container = inject('container')
const editor = inject('editor')
const page = inject('page')

defineEmits(['close'])

Expand Down Expand Up @@ -105,8 +106,11 @@ const headingActive = (value: any) => {
if (!nodeElement || !pageContainer || !pageHeader) {
return
}
const { zoomLevel } = page.value
pageContainer.scrollTo({
top: nodeElement.offsetTop + pageHeader.offsetHeight,
top: Math.round(
((nodeElement.offsetTop + pageHeader.offsetHeight) * zoomLevel) / 100,
),
})
const pos = editor.value.view.posAtDOM(nodeElement as Node, 0)
const { tr } = editor.value.view.state
Expand Down
10 changes: 4 additions & 6 deletions src/components/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,8 @@ const setWatermark = (params: Partial<WatermarkOption>) => {
if (!isRecord(params)) {
throw new Error('params must be an object.')
}
if (!page.value.watermark) {
page.value.watermark = {} as WatermarkOption
}
page.value.watermark ??= {} as WatermarkOption

if (isDefined(params.alpha)) {
if (!isNumber(params.alpha)) {
throw new Error('"params.alpha" must be a number.')
Expand Down Expand Up @@ -664,9 +663,8 @@ const setDocument = (params: DocumentOptions) => {
if (Object.prototype.toString.call(params) !== '[object Object]') {
throw new Error('params must be an object.')
}
if (!options.value.document) {
options.value.document = {} as DocumentOptions
}
options.value.document ??= {} as DocumentOptions

if (params.title) {
if (!isString(params.title)) {
throw new Error('"params.title" must be a string.')
Expand Down
2 changes: 1 addition & 1 deletion src/components/menus/bubble/node/tofile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const ndoeTofile = () => {
type: 'file',
attrs: {
...attrs,
url: attrs.url || attrs.src,
url: attrs.url ?? attrs.src,
},
})
return true
Expand Down
20 changes: 8 additions & 12 deletions src/components/page-options.vue
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,9 @@ const selectPageSize = (value: number) => {
pageOptions.size = options.value?.dicts?.pageSizes[value]
}
const inputPageSize = (value: number, field: 'width' | 'height') => {
if (!pageOptions.size) {
pageOptions.size = {
width: 0,
height: 0,
}
pageOptions.size ??= {
width: 0,
height: 0,
}
if (!value || value < 10) {
Reflect.set(pageOptions.size, field, 10)
Expand All @@ -292,13 +290,11 @@ const inputPageMargin = (
value: number,
field: 'top' | 'bottom' | 'left' | 'right' | 'layout',
) => {
if (!pageOptions.margin) {
pageOptions.margin = {
right: 0,
left: 0,
bottom: 0,
top: 0,
}
pageOptions.margin ??= {
right: 0,
left: 0,
bottom: 0,
top: 0,
}
if (!value || value < 0) {
Reflect.set(pageOptions.margin, field, 0)
Expand Down
2 changes: 1 addition & 1 deletion src/components/statusbar/countdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const startCountdown = async () => {
clearInterval(countdownInterval)
}
const totalSeconds =
(hours || 0) * 3600 + (minutes || 0) * 60 + (seconds || 0)
(hours ?? 0) * 3600 + (minutes ?? 0) * 60 + (seconds ?? 0)

if (totalSeconds <= 0) {
messageBox = await useMessage('error', {
Expand Down
2 changes: 1 addition & 1 deletion src/composables/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function useState<T extends StateKey>(
key: T,
options: any,
): RemovableRef<StateValue<T>> {
const storageKey = `umo-editor:${options?.value?.editorKey || 'default'}:${key}`
const storageKey = `umo-editor:${options?.value?.editorKey ?? 'default'}:${key}`

if (key === 'document') {
return useStorage<StateValue<T>>(
Expand Down
8 changes: 4 additions & 4 deletions src/extensions/file/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export default Node.create({
})
return false
}
const position = pos || editor.state.selection.anchor
const position = pos ?? editor.state.selection.anchor
let previewType = 'file'
// 图片
if (type.startsWith('image/') && mimeTypes.image.includes(type)) {
Expand All @@ -162,7 +162,7 @@ export default Node.create({
[previewType === 'file' ? 'url' : 'src']:
URL.createObjectURL(file),
name,
type: type || 'unknown', // Ensure type is never null
type: type ?? 'unknown', // Ensure type is never null
size,
previewType,
},
Expand Down Expand Up @@ -218,8 +218,8 @@ export default Node.create({
// 如果是文件节点,调用删除方法删除文件
if (['image', 'video', 'audio', 'file'].includes(node.attrs.type)) {
const { id, src, url } = node.attrs
const { onFileDelete } = editor.storage.options || {}
onFileDelete(id, src || url)
const { onFileDelete } = editor.storage.options ?? {}
onFileDelete(id, src ?? url)
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/hr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default hr.extend({
renderHTML: (attributes) => {
return {
'data-color': attributes.color,
style: `color: ${attributes.color || 'inherit'}`,
style: `color: ${attributes.color ?? 'inherit'}`,
}
},
},
Expand Down