mirror of
https://github.com/colanode/colanode.git
synced 2025-12-29 00:25:03 +01:00
Fixes and improvements in document editor
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user