Skip to content

Commit 2932d43

Browse files
authored
Console log (AppFlowy-IO#187)
* chore: log json * chore: use log
1 parent 2c2d8c3 commit 2932d43

File tree

7 files changed

+119
-87
lines changed

7 files changed

+119
-87
lines changed

src/application/slate-yjs/command/index.ts

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import {
5050
YjsEditorKey,
5151
} from '@/application/types';
5252
import { EditorInlineAttributes } from '@/slate-editor';
53+
import { Log } from '@/utils/log';
5354
import { renderDate } from '@/utils/time';
5455

5556
export const CustomEditor = {
@@ -114,7 +115,7 @@ export const CustomEditor = {
114115
const entry = findSlateEntryByBlockId(editor, blockId);
115116

116117
if (!entry) {
117-
console.error('Block not found');
118+
Log.error('Block not found');
118119
return;
119120
}
120121

@@ -149,7 +150,7 @@ export const CustomEditor = {
149150
},
150151

151152
deleteBlockBackward(editor: YjsEditor, at?: BaseRange) {
152-
console.trace('deleteBlockBackward', editor.selection, at);
153+
Log.trace('deleteBlockBackward', editor.selection, at);
153154

154155
const sharedRoot = getSharedRoot(editor);
155156
const newAt = getSelectionOrThrow(editor, at);
@@ -162,7 +163,7 @@ export const CustomEditor = {
162163
const blockEntry = getBlockEntry(editor, point);
163164

164165
if (!blockEntry) {
165-
console.warn('Block not found', point);
166+
Log.warn('Block not found', point);
166167
return;
167168
}
168169

@@ -208,7 +209,7 @@ export const CustomEditor = {
208209
const blockEntry = getBlockEntry(editor, point);
209210

210211
if (!blockEntry) {
211-
console.warn('Block not found', point);
212+
Log.warn('Block not found', point);
212213
return;
213214
}
214215

@@ -327,15 +328,15 @@ export const CustomEditor = {
327328
const endResult = blockResults.find((r) => r.isEnd);
328329

329330
if (!startResult?.newId || !endResult?.newId) {
330-
console.warn('Failed to get new block IDs after tab operation');
331+
Log.warn('Failed to get new block IDs after tab operation');
331332
return;
332333
}
333334

334335
const newStartBlockEntry = findSlateEntryByBlockId(editor, startResult.newId);
335336
const newEndBlockEntry = findSlateEntryByBlockId(editor, endResult.newId);
336337

337338
if (!newStartBlockEntry || !newEndBlockEntry) {
338-
console.warn('Failed to find new block entries after tab operation');
339+
Log.warn('Failed to find new block entries after tab operation');
339340
// Try to restore selection using original selection
340341
const fallbackSelection = findNearestValidSelection(editor, originalSelection);
341342

@@ -380,23 +381,23 @@ export const CustomEditor = {
380381
};
381382
}
382383
} catch (error) {
383-
console.warn('Error constructing new selection paths:', error);
384+
Log.warn('Error constructing new selection paths:', error);
384385
newSelection = null;
385386
}
386387

387388
// Try to apply the new selection, with multiple fallback strategies
388389
if (newSelection && isValidSelection(editor, newSelection)) {
389-
console.debug('✅ Using calculated selection:', newSelection);
390+
Log.debug('✅ Using calculated selection:', newSelection);
390391
Transforms.select(editor, newSelection);
391392
} else {
392-
console.warn('⚠️ Calculated selection invalid, trying fallback strategies');
393+
Log.warn('⚠️ Calculated selection invalid, trying fallback strategies');
393394

394395
// Strategy 1: Try to find nearest valid selection from our calculated selection
395396
if (newSelection) {
396397
const nearestFromCalculated = findNearestValidSelection(editor, newSelection);
397398

398399
if (nearestFromCalculated) {
399-
console.debug('✅ Using nearest from calculated:', nearestFromCalculated);
400+
Log.debug('✅ Using nearest from calculated:', nearestFromCalculated);
400401
Transforms.select(editor, nearestFromCalculated);
401402
return;
402403
}
@@ -406,7 +407,7 @@ export const CustomEditor = {
406407
const nearestFromOriginal = findNearestValidSelection(editor, originalSelection);
407408

408409
if (nearestFromOriginal) {
409-
console.debug('✅ Using nearest from original:', nearestFromOriginal);
410+
Log.debug('✅ Using nearest from original:', nearestFromOriginal);
410411
Transforms.select(editor, nearestFromOriginal);
411412
return;
412413
}
@@ -417,23 +418,23 @@ export const CustomEditor = {
417418
const startOfBlock = Editor.start(editor, newStartBlockPath);
418419

419420
if (isValidSelection(editor, { anchor: startOfBlock, focus: startOfBlock })) {
420-
console.debug('✅ Using start of block:', startOfBlock);
421+
Log.debug('✅ Using start of block:', startOfBlock);
421422
Transforms.select(editor, startOfBlock);
422423
return;
423424
}
424425
} catch (error) {
425-
console.warn('Failed to select start of block:', error);
426+
Log.warn('Failed to select start of block:', error);
426427
}
427428
}
428429

429430
// Strategy 4: Last resort - find any valid selection in the document
430431
const documentSelection = findNearestValidSelection(editor, null);
431432

432433
if (documentSelection) {
433-
console.debug('✅ Using document fallback:', documentSelection);
434+
Log.debug('✅ Using document fallback:', documentSelection);
434435
Transforms.select(editor, documentSelection);
435436
} else {
436-
console.warn('❌ Could not establish any valid selection after tab operation');
437+
Log.warn('❌ Could not establish any valid selection after tab operation');
437438
}
438439
}
439440
},
@@ -455,7 +456,7 @@ export const CustomEditor = {
455456
const blockEntry = getBlockEntry(editor, point);
456457

457458
if (!blockEntry) {
458-
console.warn('Block not found', point);
459+
Log.warn('Block not found', point);
459460
return;
460461
}
461462

@@ -615,7 +616,7 @@ export const CustomEditor = {
615616
return Boolean((attributes as Record<string, boolean | string>)[key]);
616617
});
617618
} catch (error) {
618-
console.warn('Error checking mark in expanded selection:', error);
619+
Log.warn('Error checking mark in expanded selection:', error);
619620
return false;
620621
}
621622
}
@@ -625,7 +626,7 @@ export const CustomEditor = {
625626

626627
return marks ? !!marks[key] : false;
627628
} catch (error) {
628-
console.warn('Error checking mark at collapsed selection:', error);
629+
Log.warn('Error checking mark at collapsed selection:', error);
629630
return false;
630631
}
631632
},
@@ -650,7 +651,7 @@ export const CustomEditor = {
650651
return attributes as EditorInlineAttributes;
651652
});
652653
} catch (error) {
653-
console.warn('Error getting all marks:', error);
654+
Log.warn('Error getting all marks:', error);
654655
return [];
655656
}
656657
}
@@ -660,7 +661,7 @@ export const CustomEditor = {
660661

661662
return [marks];
662663
} catch (error) {
663-
console.warn('Error getting marks at collapsed selection:', error);
664+
Log.warn('Error getting marks at collapsed selection:', error);
664665
return [];
665666
}
666667
},
@@ -697,7 +698,7 @@ export const CustomEditor = {
697698
const parent = getBlock(blockId, sharedRoot);
698699

699700
if (!parent) {
700-
console.warn('Parent block not found');
701+
Log.warn('Parent block not found');
701702
return;
702703
}
703704

@@ -712,7 +713,7 @@ export const CustomEditor = {
712713
);
713714

714715
if (!newBlockId) {
715-
console.warn('Failed to add block');
716+
Log.warn('Failed to add block');
716717
return;
717718
}
718719

@@ -731,7 +732,7 @@ export const CustomEditor = {
731732
return newBlockId;
732733
}
733734
} catch (e) {
734-
console.error(e);
735+
Log.error(e);
735736
}
736737
},
737738

@@ -778,7 +779,7 @@ export const CustomEditor = {
778779
return newBlockId;
779780
}
780781
} catch (e) {
781-
console.error(e);
782+
Log.error(e);
782783
}
783784
},
784785

@@ -795,7 +796,7 @@ export const CustomEditor = {
795796
const parent = getParent(blockId, sharedRoot);
796797

797798
if (!parent) {
798-
console.warn('Parent block not found');
799+
Log.warn('Parent block not found');
799800
return;
800801
}
801802

@@ -872,7 +873,7 @@ export const CustomEditor = {
872873
const prevIndex = getBlockIndex(prevId || blockId, sharedRoot);
873874

874875
if (!parent) {
875-
console.warn('Parent block not found');
876+
Log.warn('Parent block not found');
876877
return;
877878
}
878879

@@ -885,7 +886,7 @@ export const CustomEditor = {
885886
newBlockId = deepCopyBlock(sharedRoot, block);
886887

887888
if (!newBlockId) {
888-
console.warn('Copied block not found');
889+
Log.warn('Copied block not found');
889890
return;
890891
}
891892

src/application/slate-yjs/plugins/withYjs.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ export function withYjs<T extends Editor>(
8585
}
8686
): T & YjsEditor {
8787
const {
88-
id,
8988
uploadFile,
9089
localOrigin = CollabOrigin.Local,
9190
readSummary,
@@ -127,7 +126,6 @@ export function withYjs<T extends Editor>(
127126
}
128127

129128
onContentChange?.(content.children);
130-
console.debug('===initializeDocumentContent', e.children);
131129
Editor.normalize(e, { force: true });
132130
};
133131

@@ -181,7 +179,6 @@ export function withYjs<T extends Editor>(
181179
throw new Error('Already connected');
182180
}
183181

184-
console.debug('===connect', id);
185182
initializeDocumentContent();
186183
e.sharedRoot.observeDeep(handleYEvents);
187184
connectSet.add(e);

0 commit comments

Comments
 (0)