Skip to content

Commit acf3ba5

Browse files
committed
essai
1 parent c5487cb commit acf3ba5

File tree

4 files changed

+149
-8
lines changed

4 files changed

+149
-8
lines changed

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,37 @@ Important: if you develop from another folder, you need to fill the `.env` file
5353
### SASS Support (need to be reviewed)
5454

5555
For SASS support, check out the `sass-ready` branch in the original template repository.
56-
When you are using the template for this branch, you need to check use all branchs option. then after you clone your new plugin, there is a batch in the root folder to replace the master branch by sass-ready one. run this once
56+
When you are using the template for this branch, you need to check use all branchs option. then after you clone your new plugin, there is a batch in the root folder to replace the master branch by sass-ready one. run this once
57+
58+
### Notes perso
59+
60+
#### Type Definitions Synchronization
61+
62+
To automatically install TypeScript type definitions for your dependencies:
63+
64+
```bash
65+
# Installation globale
66+
npm install -g typesync
67+
68+
# Dans votre projet
69+
typesync
70+
npm install
71+
```
72+
73+
#### Git Aliases Alternative
74+
75+
Instead of using npm/yarn commands that group multiple functions, you can directly create Git aliases:
76+
77+
```bash
78+
# Add + Commit + Push
79+
git config --global alias.acp '!f() { git add -A && git commit -m "$@" && git push; }; f'
80+
81+
# Build + Add + Commit + Push (for projects with build step)
82+
git config --global alias.bacp '!f() { npm run build && git add -A && git commit -m "$@" && git push; }; f'
83+
```
84+
85+
Usage:
86+
```bash
87+
git acp "Your commit message"
88+
git bacp "Your commit message after build"
89+
```
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { App, Modal, Setting } from "obsidian";
2+
3+
/**
4+
* Type definition for the confirmation callback
5+
*/
6+
export type ConfirmCallback = (confirmed: boolean) => void;
7+
8+
/**
9+
* A generic confirmation modal that can be used by different features
10+
*/
11+
export class GenericConfirmModal extends Modal {
12+
constructor(
13+
app: App,
14+
public title: string,
15+
public messages: string[],
16+
public confirmButtonText: string = "Confirm",
17+
public cancelButtonText: string = "Cancel",
18+
public onSubmit: ConfirmCallback
19+
) {
20+
super(app);
21+
}
22+
23+
onOpen() {
24+
const { contentEl } = this;
25+
contentEl.empty();
26+
27+
// Set modal size for better readability
28+
this.modalEl.style.width = `500px`;
29+
30+
// Add title
31+
contentEl.createEl("h2", { text: this.title });
32+
33+
// Add messages
34+
for (const message of this.messages) {
35+
contentEl.createEl("p", { text: message });
36+
}
37+
38+
// Add buttons
39+
new Setting(contentEl)
40+
.addButton((btn) => {
41+
btn.setButtonText(this.confirmButtonText)
42+
.setCta()
43+
.onClick(() => {
44+
this.onSubmit(true);
45+
this.close();
46+
});
47+
})
48+
.addButton((btn) =>
49+
btn.setButtonText(this.cancelButtonText)
50+
.onClick(() => {
51+
this.onSubmit(false);
52+
this.close();
53+
}));
54+
}
55+
56+
onClose() {
57+
this.contentEl.empty();
58+
}
59+
}

src/main.ts

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
import { App,
1+
import {
2+
App,
23
Plugin,
34
PluginSettingTab,
4-
Setting } from "obsidian";
5+
Setting,
6+
Notice
7+
} from "obsidian";
8+
import { GenericConfirmModal } from "./common/generic-confirm-modal.js";
59

610
// Remember to rename these classes and interfaces
711

@@ -19,9 +23,44 @@ export default class MyPlugin extends Plugin {
1923
async onload(): Promise<void> {
2024
console.log("loading plugin");
2125
await this.loadSettings();
26+
27+
// Ajouter une commande pour tester le modal de confirmation
28+
this.addCommand({
29+
id: 'show-confirmation-modal',
30+
name: 'Show Confirmation Modal',
31+
callback: () => this.showConfirmationModal()
32+
});
33+
2234
this.addSettingTab(new SampleSettingTab(this.app, this));
2335
}
2436

37+
/**
38+
* Affiche un modal de confirmation pour tester la fonctionnalité
39+
*/
40+
private showConfirmationModal(): void {
41+
const modal = new GenericConfirmModal(
42+
this.app,
43+
"Confirmation requise",
44+
[
45+
"Êtes-vous sûr de vouloir effectuer cette action ?",
46+
"Cette action ne peut pas être annulée."
47+
],
48+
"Confirmer",
49+
"Annuler",
50+
(confirmed: boolean) => {
51+
if (confirmed) {
52+
new Notice("Action confirmée !");
53+
console.log("Action confirmée par l'utilisateur");
54+
} else {
55+
new Notice("Action annulée.");
56+
console.log("Action annulée par l'utilisateur");
57+
}
58+
}
59+
);
60+
61+
modal.open();
62+
}
63+
2564
async loadSettings(): Promise<void> {
2665
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
2766
}
@@ -40,7 +79,7 @@ class SampleSettingTab extends PluginSettingTab {
4079
}
4180

4281
display(): void {
43-
const {containerEl} = this;
82+
const { containerEl } = this;
4483

4584
containerEl.empty();
4685

tsconfig.json

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
"strictPropertyInitialization": false,
55
"allowImportingTsExtensions": true,
66
"allowJs": true,
7-
"allowSyntheticDefaultImports": true,
7+
// Removing allowSyntheticDefaultImports since it's already included in esModuleInterop
8+
"esModuleInterop": true,
89
"forceConsistentCasingInFileNames": true,
910
"importHelpers": true,
10-
"inlineSourceMap": true,
11-
"inlineSources": true,
11+
// Removing inlineSourceMap and inlineSources since they are not needed with noEmit
12+
// "inlineSourceMap": true,
13+
// "inlineSources": true,
1214
"lib": [
1315
"DOM",
1416
"ES2023"
@@ -18,16 +20,24 @@
1820
"moduleResolution": "nodenext",
1921
"resolveJsonModule" : true,
2022
"noEmit": true,
21-
"skipLibCheck": false,
23+
// already false in npm run build. And true in npm run dev
24+
// "skipLibCheck": false,
2225
"target": "ESNext",
2326
"types": [
2427
"node",
2528
"obsidian-typings"
2629
],
2730
"verbatimModuleSyntax": true,
31+
// Uncomment the following options if you want to generate .d.ts declaration files.
32+
// This is useful if you're building a plugin that will be used as a dependency by other plugins.
33+
// "declaration": true,
34+
// "declarationMap": true, // Creates source maps for declaration files
2835
},
2936
"include": [
3037
"./src/**/*.ts",
3138
"./scripts/**/*.ts"
39+
],
40+
"exclude": [
41+
"node_modules"
3242
]
3343
}

0 commit comments

Comments
 (0)