Skip to content

Commit

Permalink
👷 CI: Merge dev by GitOK
Browse files Browse the repository at this point in the history
  • Loading branch information
nookery committed Nov 26, 2024
2 parents 4462389 + 85b3db9 commit 6ef0b8d
Show file tree
Hide file tree
Showing 41 changed files with 639 additions and 309 deletions.
7 changes: 4 additions & 3 deletions src/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@ const editor = EditorFactory.register('my-editor', {
// editor.enableWebKit()
editor.enableLocalStorage()

// editor.disableWebKit()
editor.disableWebKit()
editor.disableWebKitSendNodes()
// editor.disableLocalStorageVerbose()
editor.disableLocalStorageVerbose()
editor.disableCodeBlockVerbose()
editor.disableURLListenerVerbose()
// editor.disableArticleVerbose()
editor.disableArticleVerbose()
editor.disableImageVerbose()
editor.disableAssistantVerbose()
editor.disableDocVerbose()
editor.disableSmartSelectionVerbose()

editor.setChatApi(chatApi)
editor.setDrawLink('/draw/index.html?')
Expand Down
25 changes: 25 additions & 0 deletions src/error/ArticleError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class ArticleFormatError extends Error {
constructor(message: string) {
super(message)
}
}

class ArticleContentError extends Error {
constructor(message: string) {
super(message)
}
}

class ArticleHasNoUUIDError extends Error {
constructor(message: string) {
super(message)
}
}

class ArticleHasNoHTMLError extends Error {
constructor(message: string) {
super(message)
}
}

export { ArticleFormatError, ArticleContentError, ArticleHasNoUUIDError, ArticleHasNoHTMLError }
13 changes: 13 additions & 0 deletions src/error/DocError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class DocHasNoContentError extends Error {
constructor(message: string) {
super(message)
}
}

class DocHasNoArticleError extends Error {
constructor(message: string) {
super(message)
}
}

export { DocHasNoContentError, DocHasNoArticleError }
24 changes: 24 additions & 0 deletions src/error/EditorNodeError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import EditorNode from "../model/EditorNode"

class EditorNodeNoParentIdError extends Error {
block: EditorNode

constructor(message: string = 'Parent ID is not set', block: EditorNode) {
super(message)
this.block = block
}
}

class EditorNodeNoUUIDError extends Error {
block: EditorNode

constructor(message: string = 'UUID is not set', block: EditorNode) {
super(message)
this.block = block
}
}

export {
EditorNodeNoParentIdError,
EditorNodeNoUUIDError
}
10 changes: 10 additions & 0 deletions src/error/ParamError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class ParamErrorNoUUID extends Error {
public stage: string

constructor(message: string, stage: string) {
super(message)
this.stage = stage
}
}

export { ParamErrorNoUUID }
13 changes: 0 additions & 13 deletions src/error/UUIDError.ts

This file was deleted.

21 changes: 0 additions & 21 deletions src/extensions/Article.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { Node } from '@tiptap/core'
import UUIDHelper from '../helper/UUIDHelper'
import EditorNode from '../model/EditorNode'
import { createApp, h } from 'vue'
import TocView from './SmartToc/TocView.vue'
import SmartHeading from './SmartHeading'
import TocHeading from './SmartToc/TocHeading'
import UUIDError from '../error/UUIDError'
import { priorityOfArticle } from '../model/TiptapGroup'

export interface ArticleOptions {
Expand Down Expand Up @@ -57,13 +53,6 @@ const Article = Node.create<ArticleOptions, ArticleStorage>({

addAttributes() {
return {
uuid: {
default: UUIDHelper.generate("Article"),
parseHTML: element => element.getAttribute('data-uuid'),
renderHTML: attributes => ({
'data-uuid': attributes.uuid,
}),
},
toc: {
default: false,
parseHTML: element => element.getAttribute('data-toc') == 'true',
Expand Down Expand Up @@ -130,16 +119,6 @@ const Article = Node.create<ArticleOptions, ArticleStorage>({
renderHTML({ HTMLAttributes }) {
return ['article', { ...HTMLAttributes }, 0]
},

onUpdate() {
if (this.storage.verbose) {
console.log(this.storage.title, "onUpdate")
}

if (this.storage.verbose) {
console.log(this.storage.title, "onUpdate, article updated")
}
},
})

export default Article
33 changes: 32 additions & 1 deletion src/extensions/DebugBar/Component.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script lang="ts" setup>
import { computed, ref } from 'vue';
import { TiptapEditor } from '../../model/TiptapGroup';
import Tree from './Tree.vue';
import { NodeStoreStorage } from '../../extensions/NodeStore';
const props = defineProps({
editor: {
Expand All @@ -10,6 +12,8 @@ const props = defineProps({
})
const type = ref('')
const showTree = ref(false)
const nodeStoreStorage = props.editor.storage.nodeStore as NodeStoreStorage
props.editor.on('selectionUpdate', () => {
const { selection } = props.editor.state;
Expand All @@ -32,16 +36,43 @@ props.editor.on('selectionUpdate', () => {
function closeMessage() {
props.editor.commands.closeDebugBar()
}
function toggleTree() {
showTree.value = !showTree.value
}
const editorNode = computed(() => nodeStoreStorage.article)
</script>

<template>
<div class="w-full h-12 px-4 bg-slate-800 text-gray-400">
<div class="flex justify-between items-center">
<p>{{ type }}</p>

<div class="card-actions justify-end">
<div class="card-actions justify-end flex gap-2">
<button class="btn btn-primary btn-sm" @click="toggleTree">查看结构</button>
<button class="btn btn-primary btn-sm" @click="closeMessage">关闭</button>
</div>
</div>

<!-- Tree Modal -->
<div v-if="showTree"
class="fixed bottom-24 inset-0 bg-black bg-opacity-50 z-[100] flex items-center justify-center -translate-y-96">
<div
class="bg-indigo-100/95 rounded-lg p-6 pb-24 w-[90%] max-w-3xl max-h-[75vh] overflow-auto -translate-y-44">
<div class="flex justify-between items-center mb-4">
<h3 class="text-lg font-bold text-gray-900">节点结构</h3>
<button class="text-gray-500 hover:text-gray-700" @click="toggleTree">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
<div class="pb-2">
<Tree :nodes="[editorNode]" />
</div>
</div>
</div>
</div>
</template>
6 changes: 2 additions & 4 deletions src/extensions/DebugBar/DebugBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ const DebugBar = TiptapExtension.create({
name: 'DebugBar',

onCreate() {
if (this.storage.verbose) {
console.log('DebugBar created');
if (process.env.NODE_ENV === 'development') {
this.editor.commands.showDebugBar('Hello', { a: 1, b: 2 })
}

this.editor.commands.showDebugBar('Hello', { a: 1, b: 2 })
},

addStorage() {
Expand Down
30 changes: 30 additions & 0 deletions src/extensions/DebugBar/Tree.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<template>
<div class="pl-4">
<div v-for="node in nodes" :key="node.getUUID()" class="my-1">
<div class="flex items-center gap-2">
<span class="text-blue-600">{{ node.type }}</span>
<span class="text-gray-500 text-sm">({{ node.getUUID() }})</span>
<span v-if="node.title" class="text-emerald-600">"{{ node.title }}"</span>
</div>

<div v-if="node.children?.length" class="border-l border-red-500 ml-2">
<Tree :nodes="node.children" />
</div>
</div>
</div>
</template>

<script lang="ts">
import { defineComponent, PropType } from 'vue'
import EditorNode from '../../model/EditorNode'
export default defineComponent({
name: 'Tree',
props: {
nodes: {
type: Array as PropType<EditorNode[]>,
required: true
}
}
})
</script>
13 changes: 7 additions & 6 deletions src/extensions/LocalStorage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { TiptapExtension } from '../model/TiptapGroup';
import { NodeStoreStorage } from './NodeStore';
import { SmartSlotStorage } from './SmartSlot';

export interface LocalStorageStorage {
verbose: boolean,
Expand Down Expand Up @@ -46,13 +48,10 @@ const LocalStorage = TiptapExtension.create<{}, LocalStorageStorage>({
},

onUpdate() {
if (this.storage.verbose && this.storage.enabled) {
console.log(this.storage.emoji, "onUpdate")
}

if (this.storage.printDocNode) {
console.log(this.storage.emoji, 'the doc node is')
console.log(this.editor.storage.article.article)
const nodeStore = this.editor.storage.nodeStore as NodeStoreStorage
console.log(nodeStore.article)
}

if (!this.storage.enabled) {
Expand Down Expand Up @@ -144,7 +143,9 @@ const LocalStorage = TiptapExtension.create<{}, LocalStorageStorage>({
console.log(this.storage.emoji, '🖥️ boot local storage')
}

if (this.editor.storage.smartSlot.slotHasOriginalContent == false) {
const smartSlot = this.editor.storage.smartSlot as SmartSlotStorage

if (smartSlot.slotHasOriginalContent == false) {
commands.setContentFromLocalStorage()
} else {
if (this.storage.verbose) {
Expand Down
Loading

0 comments on commit 6ef0b8d

Please sign in to comment.