Skip to content

Commit c288027

Browse files
committed
fix: sql editor compatible libro
1 parent 87bbfc1 commit c288027

File tree

4 files changed

+35
-13
lines changed

4 files changed

+35
-13
lines changed

packages/secretnote/src/modules/scql-editor/cell/view.tsx

+11-4
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class SQLCellView extends LibroExecutableCellView {
7676
this.viewManager = viewManager;
7777
this.commandRegistry = commandRegistry;
7878

79-
this.outputs = options.cell?.outputs as IOutput[];
79+
this.outputs = (options.cell?.outputs || []) as IOutput[];
8080
this.className = this.className + ' sql-editor-container';
8181

8282
this.viewManager
@@ -103,8 +103,17 @@ export class SQLCellView extends LibroExecutableCellView {
103103
await this.createEditor();
104104
};
105105

106+
override toJSON() {
107+
const meta = super.toJSON();
108+
return {
109+
...meta,
110+
outputs: this.outputArea?.toJSON() ?? this.outputs,
111+
};
112+
}
113+
106114
createEditor() {
107115
const option: CodeEditorViewOptions = {
116+
uuid: this.options.uuid,
108117
factory: (editorOption) => new SQLEditor(editorOption),
109118
model: this.cellModel,
110119
config: {
@@ -116,10 +125,8 @@ export class SQLCellView extends LibroExecutableCellView {
116125
.getOrCreateView<CodeEditorView, CodeEditorViewOptions>(CodeEditorView, option)
117126
.then(async (editorView) => {
118127
this.editorView = editorView;
119-
120-
await editorView.editorReady;
128+
await editorView.editor.editorReady;
121129
this.handleCommand();
122-
123130
return;
124131
})
125132
.catch(() => {

packages/secretnote/src/modules/scql-editor/editor/editor.ts

+12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {
88
IPosition,
99
ICoordinate,
1010
SearchMatch,
11+
EditorState,
1112
} from '@difizen/libro-jupyter';
1213
import {
1314
Disposable,
@@ -44,6 +45,7 @@ export class SQLEditor implements IEditor {
4445

4546
monacoEditor?: MonacoEditorType;
4647
host: HTMLElement;
48+
editorState?: EditorState<EditorState>;
4749

4850
get uuid(): string {
4951
return this._uuid;
@@ -220,6 +222,16 @@ export class SQLEditor implements IEditor {
220222
};
221223
}
222224

225+
getState(): EditorState<EditorState> {
226+
const cursorPosition = this.getCursorPosition();
227+
const selections = this.getSelections();
228+
return {
229+
...this.editorState!,
230+
cursorPosition,
231+
selections,
232+
};
233+
}
234+
223235
protected updateEditorSize() {
224236
const contentHeight = this.monacoEditor?.getContentHeight() ?? 20;
225237
this.host.style.height = `${contentHeight + 30}px`;

packages/secretnote/src/modules/scql-project/notification-view.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ import { ProjectService, Respond } from './service';
2626
export const InvitationNotificationComponent = () => {
2727
const instance = useInject<InvitationNotificationView>(ViewInstance);
2828
const pending = instance.service.invitationList.filter(
29-
(item) => item.accepted === Respond.Pending,
29+
(item) => item.status === Respond.UNDECIDED,
3030
);
3131
const archived = instance.service.invitationList.filter(
32-
(item) => item.accepted !== Respond.Pending,
32+
(item) => item.status !== Respond.UNDECIDED,
3333
);
3434

3535
const handleInvitation = async (id: string, accepted: boolean) => {
@@ -102,10 +102,10 @@ export const InvitationNotificationComponent = () => {
102102
<span
103103
className="action"
104104
style={{
105-
color: item.accepted === Respond.Accepted ? 'green' : 'orange',
105+
color: item.status === Respond.ACCEPTED ? 'green' : 'orange',
106106
}}
107107
>
108-
{Respond[item.accepted]}
108+
{Respond[item.status]}
109109
</span>
110110
</li>
111111
))}

packages/secretnote/src/modules/scql-project/service.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@ export interface Project {
1111
}
1212

1313
export interface Invitation {
14-
accepted: number;
1514
id: string;
1615
inviter: string;
16+
invitee: string;
1717
project: string;
18+
status: Respond;
1819
}
1920

2021
export enum Respond {
21-
Pending = 0,
22-
Accepted = 1,
23-
Declined = -1,
22+
UNDECIDED = 'UNDECIDED',
23+
ACCEPTED = 'ACCEPTED',
24+
DECLINED = 'DECLINED',
25+
INVALID = 'INVALID',
2426
}
2527

2628
export interface PlatformInfo {
@@ -91,9 +93,10 @@ export class ProjectService {
9193
});
9294
// eslint-disable-next-line @typescript-eslint/no-explicit-any
9395
this.invitationList = invitationList.map((item: any) => ({
94-
accepted: item.accepted,
96+
status: item.status,
9597
id: item.invitation_id,
9698
inviter: item.inviter,
99+
invitee: item.invitee,
97100
project: item.project.name || item.project.project_id,
98101
}));
99102
return invitationList;

0 commit comments

Comments
 (0)