1+ import type { CKTextEditor } from "@triliumnext/ckeditor5" ;
2+ import { AttributeRow } from "@triliumnext/commons" ;
3+
14import appContext from "../components/app_context.js" ;
5+ import type FBranch from "../entities/fbranch.js" ;
6+ import type FNote from "../entities/fnote.js" ;
7+ import type { ChooseNoteTypeResponse } from "../widgets/dialogs/note_type_chooser.js" ;
8+ import froca from "./froca.js" ;
9+ import { t } from "./i18n.js" ;
210import protectedSessionHolder from "./protected_session_holder.js" ;
311import server from "./server.js" ;
4- import ws from "./ws.js" ;
5- import froca from "./froca.js" ;
6- import treeService from "./tree.js" ;
712import toastService from "./toast.js" ;
8- import { t } from "./i18n.js" ;
9- import type FNote from "../entities/fnote.js" ;
10- import type FBranch from "../entities/fbranch.js" ;
11- import type { ChooseNoteTypeResponse } from "../widgets/dialogs/note_type_chooser.js" ;
12- import type { CKTextEditor } from "@triliumnext/ckeditor5" ;
13+ import treeService from "./tree.js" ;
14+ import ws from "./ws.js" ;
1315
1416export interface CreateNoteOpts {
1517 isProtected ?: boolean ;
@@ -24,6 +26,8 @@ export interface CreateNoteOpts {
2426 target ?: string ;
2527 targetBranchId ?: string ;
2628 textEditor ?: CKTextEditor ;
29+ /** Attributes to be set on the note. These are set atomically on note creation, so entity changes are not sent for attributes defined here. */
30+ attributes ?: Omit < AttributeRow , "noteId" | "attributeId" > [ ] ;
2731}
2832
2933interface Response {
@@ -37,7 +41,7 @@ interface DuplicateResponse {
3741 note : FNote ;
3842}
3943
40- async function createNote ( parentNotePath : string | undefined , options : CreateNoteOpts = { } ) {
44+ async function createNote ( parentNotePath : string | undefined , options : CreateNoteOpts = { } , componentId ?: string ) {
4145 options = Object . assign (
4246 {
4347 activate : true ,
@@ -63,22 +67,15 @@ async function createNote(parentNotePath: string | undefined, options: CreateNot
6367
6468 const parentNoteId = treeService . getNoteIdFromUrl ( parentNotePath ) ;
6569
66- if ( options . type === "mermaid" && ! options . content && ! options . templateNoteId ) {
67- options . content = `graph TD;
68- A-->B;
69- A-->C;
70- B-->D;
71- C-->D;` ;
72- }
73-
7470 const { note, branch } = await server . post < Response > ( `notes/${ parentNoteId } /children?target=${ options . target } &targetBranchId=${ options . targetBranchId || "" } ` , {
7571 title : options . title ,
7672 content : options . content || "" ,
7773 isProtected : options . isProtected ,
7874 type : options . type ,
7975 mime : options . mime ,
80- templateNoteId : options . templateNoteId
81- } ) ;
76+ templateNoteId : options . templateNoteId ,
77+ attributes : options . attributes
78+ } , componentId ) ;
8279
8380 if ( options . saveSelection ) {
8481 // we remove the selection only after it was saved to server to make sure we don't lose anything
@@ -140,9 +137,8 @@ function parseSelectedHtml(selectedHtml: string) {
140137 const content = selectedHtml . replace ( dom [ 0 ] . outerHTML , "" ) ;
141138
142139 return [ title , content ] ;
143- } else {
144- return [ null , selectedHtml ] ;
145140 }
141+ return [ null , selectedHtml ] ;
146142}
147143
148144async function duplicateSubtree ( noteId : string , parentNotePath : string ) {
0 commit comments