Fixes and improvements in document editor

This commit is contained in:
Hakan Shehu
2024-08-29 10:00:29 +02:00
parent ce84e6519e
commit 0bd5c18907
4 changed files with 19 additions and 12 deletions

View File

@@ -1,6 +1,7 @@
import SQLite from 'better-sqlite3';
import { Parser, AST, Select } from 'node-sql-parser';
import { QueryResult } from 'kysely';
import { isEqual } from 'lodash';
const parser = new Parser();
const parseOptions = { database: 'Sqlite' };
@@ -76,15 +77,9 @@ export const resultHasChanged = <R>(
const oldRow = oldResult.rows[i];
const newRow = newResult.rows[i];
if (Object.keys(oldRow).length !== Object.keys(newRow).length) {
if (!isEqual(oldRow, newRow)) {
return true;
}
for (const key in oldRow) {
if (oldRow[key] !== newRow[key]) {
return true;
}
}
}
return false;

View File

@@ -157,6 +157,7 @@ export class WorkspaceManager {
const newResult = await this.database.executeQuery(subscriberData.query);
if (resultHasChanged(subscriberData.result, newResult)) {
subscriberData.result = newResult;
eventBus.publish({
event: 'workspace_query_updated',
payload: {

View File

@@ -23,8 +23,18 @@ export const mapNodeToEditorNode = (node: LocalNode): EditorNode => {
id: node.id,
type: node.type,
parentId: node.parentId,
attrs: node.attrs,
content: node.content,
attrs:
node.attrs !== null &&
node.attrs !== undefined &&
Object.keys(node.attrs).length > 0
? node.attrs
: null,
content:
node.content !== null &&
node.content !== undefined &&
node.content.length > 0
? node.content
: null,
index: node.index,
};
};
@@ -159,6 +169,7 @@ const mapAndPushJSONContentToEditorNode = (
parentId: parentId,
index: index,
attrs: attrs,
content: null,
};
editorNodes.set(id, editorNode);

View File

@@ -23,7 +23,7 @@ export type EditorNode = {
id: string;
parentId: string;
type: string;
index?: string | null;
attrs?: Record<string, any> | null;
content?: NodeBlock[] | null;
index: string | null;
attrs: Record<string, any> | null;
content: NodeBlock[] | null;
};