editor: added filter in console for testing query

This commit is contained in:
Muhammad Ali
2023-06-01 16:57:02 +05:00
parent 40c0b527c9
commit 6a86a0e088
2 changed files with 34 additions and 7 deletions

View File

@@ -17,13 +17,14 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import {Extension } from "@tiptap/core";
import { Extension } from "@tiptap/core";
import { isInTable } from "@tiptap/pm/tables";
import { LIST_ITEM_NODE_TYPES, LIST_NODE_TYPES } from "../../utils/node-types";
import { isListActive } from "../../utils/prosemirror";
import { CodeBlock } from "../code-block";
import { ShowBlockNodesComponent } from "../../toolbar/popups/blocknodes-popup";
import { Editor} from "../../types";
import { Editor } from "../../types";
import { getAllTools } from "../../toolbar";
export const KeyMap = Extension.create({
name: "key-map",
@@ -48,7 +49,12 @@ export const KeyMap = Extension.create({
return joinUpWithLastListItem(editor as Editor);
},
"/": ({ editor }) => {
const { $from, to } = editor.state.selection;
const { state } = editor as Editor;
const { $from } = state.selection;
const before = $from.nodeBefore?.textContent;
if (before) return false;
const selectedElement = editor.view.domAtPos($from.pos)
.node as HTMLElement;
@@ -56,7 +62,20 @@ export const KeyMap = Extension.create({
editor: editor as Editor,
selectedElement: selectedElement
});
return false;
(editor as Editor).current?.commands.focus();
(editor as Editor).current?.on("update", ({ editor }) => {
const { state } = editor as Editor;
const { $from } = state.selection;
const before = $from.nodeBefore?.textContent;
console.log(
" inlistenr",
Object.keys(getAllTools()).filter(
(string) => string.indexOf(before as string) > -1
)
);
});
return true;
}
};
}

View File

@@ -21,6 +21,7 @@ import { showPopup } from "../../components/popup-presenter";
import { Editor } from "../../types";
import { MenuItem } from "../../components/menu/types";
import { getToolbarElement } from "../utils/dom";
import { getAllTools } from "../tool-definitions";
export const ShowBlockNodesComponent = (props: {
editor: Editor;
@@ -53,13 +54,18 @@ export const ShowBlockNodesComponent = (props: {
marginRight: isBottom ? "10px" : 0,
display: "flex",
alignItems: isBottom ? "center" : "unset"
},
onFocus: () => {
console.log("on foucs");
},
onBlur: () => {
console.log("on bluur");
}
});
};
const blocknodes = [
{ id: "table", title: "Table" },
{ id: "list", title: "List" },
{ id: "outline-list", title: "Outline list" },
{ id: "task-list", title: "Task list" },
{ id: "bullet-list", title: "Bullet list" },
@@ -76,6 +82,9 @@ function toMenuItems(editor: Editor): MenuItem[] {
type: "button",
title: blocknode.title,
onClick: () => {
console.log(getAllTools());
editor.current?.chain().focus().insertContent(" ").run();
switch (blocknode.id) {
case "table":
editor.current
@@ -84,8 +93,6 @@ function toMenuItems(editor: Editor): MenuItem[] {
.insertTable({ rows: 3, cols: 3 })
.run();
break;
case "list":
break;
case "outline-list":
editor.current?.chain().focus().toggleOutlineList().run();
break;
@@ -105,6 +112,7 @@ function toMenuItems(editor: Editor): MenuItem[] {
editor.current?.chain().focus().toggleCodeBlock().run();
break;
}
editor.current?.off("update");
}
});
}