(params: {
region: PageRegion;
worldPos?: Vec2;
center?: boolean;
destIndex?: number;
edit?: boolean;
})
| 115 | } |
| 116 | |
| 117 | async create(params: { |
| 118 | region: PageRegion; |
| 119 | worldPos?: Vec2; |
| 120 | center?: boolean; |
| 121 | destIndex?: number; |
| 122 | edit?: boolean; |
| 123 | }) { |
| 124 | if (this.page.react.readOnly) { |
| 125 | return; |
| 126 | } |
| 127 | |
| 128 | const note = this.page.app.serialization.deserialize( |
| 129 | internals.pages.defaultNote, |
| 130 | params.region, |
| 131 | params?.destIndex, |
| 132 | ).notes[0]; |
| 133 | |
| 134 | await nextTick(); |
| 135 | await watchUntilTrue(() => note.react.loaded); |
| 136 | |
| 137 | if (params.edit !== false) { |
| 138 | await this.page.editing.start(note); |
| 139 | } |
| 140 | |
| 141 | note.react.collab.pos.x = params?.worldPos?.x ?? 0; |
| 142 | note.react.collab.pos.y = params?.worldPos?.y ?? 0; |
| 143 | |
| 144 | if (params?.center !== false) { |
| 145 | const worldSize = note.getWorldRect('note-frame')?.size; |
| 146 | |
| 147 | if (worldSize != null) { |
| 148 | const newPos = new Vec2(note.react.collab.pos).add( |
| 149 | worldSize.mul(new Vec2(note.react.collab.anchor).subScalar(0.5)), |
| 150 | ); |
| 151 | |
| 152 | note.react.collab.pos.x = newPos.x; |
| 153 | note.react.collab.pos.y = newPos.y; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | return note; |
| 158 | } |
| 159 | } |
no test coverage detected