Skip to content

Commit b11a37e

Browse files
card style
1 parent c6b649d commit b11a37e

File tree

3 files changed

+443
-339
lines changed

3 files changed

+443
-339
lines changed

main.ts

Lines changed: 170 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -2,161 +2,192 @@ import { App, Plugin, TFile, addIcon } from "obsidian";
22
import familyModal from "./src/createFamily/familyModal";
33
import deleteActiveNoteModal from "./src/createFamily/deleteActiveNoteModal";
44
import { NewFileLocation } from "./src/util/enums";
5-
import { buttonsLine } from "./src/createFamily/buttons";
6-
import { coloringTreePanel, addUnsortedFilesCounter, unSortedObserver, foldPropertiesElement } from "./src/createFamily/coloringTreePanel";
5+
import { buttonsLine, cardStyleFunction } from "./src/createFamily/buttons";
6+
import {
7+
coloringTreePanel,
8+
addUnsortedFilesCounter,
9+
unSortedObserver,
10+
foldPropertiesElement,
11+
} from "./src/createFamily/coloringTreePanel";
712
import { createClustersAndOrphansFolder } from "./src/createFamily/createClustersAndOrphansFolder";
813
import { fileMenu } from "src/createFamily/fileMenu";
914
import { settingTab } from "./src/createFamily/settings";
1015

16+
const clusters = "CLUSTERS";
17+
const orphans = "ORPHANS";
1118

12-
const clusters = "CLUSTERS"
13-
const orphans = "ORPHANS"
19+
export interface clusterPluginSettings {
20+
foldProperties: boolean;
1421

15-
16-
17-
interface clusterPluginSettings {
18-
foldProperties: boolean;
19-
20-
firstPageClusters: boolean;
21-
22-
restBgClusters: boolean;
23-
newBG_clusters: string;
24-
newBG_orphans: string;
25-
restBgOrphans: boolean;
26-
buttonsLineContainerBG_clusters: string;
27-
buttonsLineContainerBG_orphans: string;
22+
firstPageClusters: boolean;
23+
cardStyle: boolean;
24+
restBgClusters: boolean;
25+
newBG_clusters: string;
26+
newBG_orphans: string;
27+
restBgOrphans: boolean;
28+
buttonsLineContainerBG_clusters: string;
29+
buttonsLineContainerBG_orphans: string;
2830
}
2931

3032
const DEFAULT_SETTINGS: Partial<clusterPluginSettings> = {
31-
foldProperties: true,
32-
33-
firstPageClusters: true,
34-
35-
restBgClusters: true,
36-
restBgOrphans: true,
37-
buttonsLineContainerBG_clusters: "var(--background-button-container-clusters)",
38-
buttonsLineContainerBG_orphans: "var(--background-button-container-orphans)"
39-
33+
foldProperties: true,
34+
35+
firstPageClusters: true,
36+
cardStyle: false,
37+
restBgClusters: true,
38+
restBgOrphans: true,
39+
buttonsLineContainerBG_clusters:
40+
"var(--background-button-container-clusters)",
41+
buttonsLineContainerBG_orphans: "var(--background-button-container-orphans)",
4042
};
4143

42-
43-
4444
export default class clusterPlugin extends Plugin {
45-
actions = new Map();// ! whats this
46-
settings: clusterPluginSettings;
47-
48-
async onload() {
49-
console.log("loading Cluster plugin");
50-
51-
await this.loadSettings();
52-
53-
this.addSettingTab(new settingTab(this.app, this));
54-
55-
//- UN-SORTED Folder Styling
56-
setTimeout(async () => {
57-
await addUnsortedFilesCounter(this.app)
58-
await unSortedObserver(this.app)
59-
}, 1000);
60-
61-
const file = this.app.workspace.getActiveFile() as TFile
62-
if (file) {
63-
await buttonsLine(this.app, file, this.settings)
64-
}
65-
66-
this.registerEvent(this.app.workspace.on("file-open", async (file) => {
67-
68-
if (file) {
69-
70-
//- Add Buttons
71-
await buttonsLine(this.app, file, this.settings)
72-
73-
//- Coloring Tree Panel
74-
await coloringTreePanel(this.app, file)
75-
//- Fold Properties Element
76-
if (this.settings.foldProperties) {
77-
await foldPropertiesElement(this.app, file)
78-
}
79-
await addUnsortedFilesCounter(this.app)
80-
await unSortedObserver(this.app)
81-
82-
}
83-
84-
}));
85-
86-
//- Commands
87-
this.addCommand({
88-
id: "New-Cluster",
89-
name: "new cluster",
90-
callback: () => {
91-
createClustersAndOrphansFolder(this.app);
92-
new familyModal(this.app, NewFileLocation.NewTab, "newCluster", undefined).open();
93-
},
94-
});
95-
this.addCommand({
96-
id: "New-Son",
97-
name: "New son",
98-
callback: () => {
99-
createClustersAndOrphansFolder(this.app);
100-
new familyModal(this.app, NewFileLocation.NewTab, "newSon", undefined).open();
101-
},
102-
});
103-
this.addCommand({
104-
id: "New-Brother",
105-
name: "New brother",
106-
callback: () => {
107-
createClustersAndOrphansFolder(this.app);
108-
new familyModal(this.app, NewFileLocation.NewTab, "newBrother", undefined).open();
109-
},
110-
});
111-
this.addCommand({
112-
id: "New-Orphan",
113-
name: "New orphan",
114-
callback: () => {
115-
createClustersAndOrphansFolder(this.app);
116-
new familyModal(this.app, NewFileLocation.NewTab, "newOrphan", undefined).open();
117-
},
118-
});
119-
this.addCommand({
120-
id: "Delete-Active-Note",
121-
name: "Delete active note",
122-
callback: () => {
123-
createClustersAndOrphansFolder(this.app);
124-
new deleteActiveNoteModal(this.app, NewFileLocation.NewTab, "deleteNote").open();
125-
},
126-
});
127-
128-
//- Ribbon Icon
129-
addIcon("cluster-svg", `<g clip-path="url(#clip0_2_2)">
45+
actions = new Map(); // ! whats this
46+
settings: clusterPluginSettings;
47+
48+
async onload() {
49+
console.log("loading Cluster plugin");
50+
51+
await this.loadSettings();
52+
53+
this.addSettingTab(new settingTab(this.app, this));
54+
55+
//- UN-SORTED Folder Styling
56+
setTimeout(async () => {
57+
await addUnsortedFilesCounter(this.app);
58+
await unSortedObserver(this.app);
59+
}, 1000);
60+
//- Card style
61+
await cardStyleFunction( this.settings);
62+
63+
const file = this.app.workspace.getActiveFile() as TFile;
64+
if (file) {
65+
await buttonsLine(this.app, file, this.settings);
66+
}
67+
68+
this.registerEvent(
69+
this.app.workspace.on("file-open", async (file) => {
70+
if (file) {
71+
//- Add Buttons
72+
await buttonsLine(this.app, file, this.settings);
73+
74+
//- Coloring Tree Panel
75+
await coloringTreePanel(this.app, file);
76+
//- Fold Properties Element
77+
if (this.settings.foldProperties) {
78+
await foldPropertiesElement(this.app, file);
79+
}
80+
await addUnsortedFilesCounter(this.app);
81+
await unSortedObserver(this.app);
82+
}
83+
}),
84+
);
85+
86+
//- Commands
87+
this.addCommand({
88+
id: "New-Cluster",
89+
name: "new cluster",
90+
callback: () => {
91+
createClustersAndOrphansFolder(this.app);
92+
new familyModal(
93+
this.app,
94+
NewFileLocation.NewTab,
95+
"newCluster",
96+
undefined,
97+
).open();
98+
},
99+
});
100+
this.addCommand({
101+
id: "New-Son",
102+
name: "New son",
103+
callback: () => {
104+
createClustersAndOrphansFolder(this.app);
105+
new familyModal(
106+
this.app,
107+
NewFileLocation.NewTab,
108+
"newSon",
109+
undefined,
110+
).open();
111+
},
112+
});
113+
this.addCommand({
114+
id: "New-Brother",
115+
name: "New brother",
116+
callback: () => {
117+
createClustersAndOrphansFolder(this.app);
118+
new familyModal(
119+
this.app,
120+
NewFileLocation.NewTab,
121+
"newBrother",
122+
undefined,
123+
).open();
124+
},
125+
});
126+
this.addCommand({
127+
id: "New-Orphan",
128+
name: "New orphan",
129+
callback: () => {
130+
createClustersAndOrphansFolder(this.app);
131+
new familyModal(
132+
this.app,
133+
NewFileLocation.NewTab,
134+
"newOrphan",
135+
undefined,
136+
).open();
137+
},
138+
});
139+
this.addCommand({
140+
id: "Delete-Active-Note",
141+
name: "Delete active note",
142+
callback: () => {
143+
createClustersAndOrphansFolder(this.app);
144+
new deleteActiveNoteModal(
145+
this.app,
146+
NewFileLocation.NewTab,
147+
"deleteNote",
148+
).open();
149+
},
150+
});
151+
152+
//- Ribbon Icon
153+
addIcon(
154+
"cluster-svg",
155+
`<g clip-path="url(#clip0_2_2)">
130156
<path d="M87.4883 74.9859C85.1634 75.0547 83.0136 75.7421 81.1887 76.8918L67.3645 63.4256C70.0769 60.0075 71.7893 55.6833 71.9892 50.9717L81.8011 49.9906C83.2073 53.465 86.5508 55.8708 90.4568 55.8708C95.6003 55.8708 99.7688 51.7028 99.7688 46.56C99.7688 41.4172 95.6003 37.2493 90.4568 37.2493C85.7759 37.2493 81.9074 40.6986 81.2449 45.1915L71.3018 45.9914C69.9019 38.8927 65.2209 33.1188 58.9401 30.2381L60.8649 24.9953H62.4898C69.3582 24.9453 74.9016 19.3714 74.9016 12.4977C74.9016 5.5927 69.3082 0 62.4023 0C55.4965 0 49.9031 5.5927 49.9031 12.4977C49.9031 17.1343 52.428 21.1835 56.1777 23.3394L54.4903 28.6821C53.0717 28.3447 51.4468 28.1572 49.7781 28.1572C44.591 28.1572 39.8413 30.0069 36.1477 33.0875L17.4364 14.3161C18.3176 12.9163 18.8426 11.2104 18.8426 9.37949C18.8426 4.20546 14.6428 0.00624883 9.46816 0.00624883C4.29348 0.00624883 0.0937441 4.20546 0.0937441 9.37949C0.0937441 14.5223 4.23723 18.7027 9.36816 18.7527C11.1243 18.7465 12.768 18.2591 14.1616 17.4155L32.8667 36.187C29.9044 39.8613 28.117 44.5854 28.117 49.7344C28.117 49.8282 28.117 49.9219 28.117 50.0156C28.117 50.3781 28.117 50.6905 28.117 51.0029L23.9922 51.6903C22.0361 47.1912 17.6239 44.1042 12.4992 44.1042C5.5934 44.1042 0 49.6969 0 56.6019C0 63.5068 5.5934 69.0995 12.4992 69.0995C19.405 69.0995 24.9984 63.5068 24.9984 56.6019C24.9984 56.4769 24.9984 56.3582 24.9922 56.2332L28.9294 55.6271C30.4418 60.8948 33.7291 65.2378 38.0914 68.0747L34.6166 75.4983C33.6104 75.1922 32.448 75.0109 31.248 74.9984C31.2105 74.9984 31.1731 74.9984 31.1418 74.9984C24.236 74.9984 18.6426 80.5911 18.6426 87.4961C18.6426 94.4011 24.236 99.9938 31.1418 99.9938C38.0476 99.9938 43.641 94.4011 43.641 87.4961C43.641 83.4968 41.7599 79.9288 38.8351 77.6417L42.3724 70.4368C44.6472 71.3491 47.2908 71.8803 50.0531 71.8803C55.3465 71.8803 60.1837 69.9369 63.9022 66.7312L77.5014 80.0038C75.939 82.0659 75.0016 84.6779 75.0016 87.5023C75.0016 94.4073 80.595 100 87.5008 100C94.4066 100 100 94.4073 100 87.5023C100 80.5974 94.4066 75.0047 87.5008 75.0047L87.4883 74.9859ZM31.2418 93.7324C27.792 93.7324 24.9922 90.933 24.9922 87.4836C24.9922 84.0342 27.792 81.2348 31.2418 81.2348C34.6916 81.2348 37.4914 84.0342 37.4914 87.4836C37.4914 90.933 34.6916 93.7324 31.2418 93.7324ZM49.9906 65.6127C41.3599 65.6127 34.3666 58.6203 34.3666 49.9906C34.3666 41.361 41.3599 34.3686 49.9906 34.3686C58.6213 34.3686 65.6146 41.361 65.6146 49.9906C65.6146 58.6203 58.6213 65.6127 49.9906 65.6127Z" />
131157
</g>
132158
<defs>
133159
<clipPath id="clip0_2_2">
134160
<rect width="100" height="100" fill="white"/>
135161
</clipPath>
136-
</defs>`);
137-
this.addRibbonIcon("cluster-svg", "Create new cluster", (evt) => {
138-
createClustersAndOrphansFolder(this.app);
139-
new familyModal(this.app, NewFileLocation.NewTab, "newCluster", undefined).open();
140-
});
141-
//- File Menu
142-
fileMenu(this)
143-
144-
}
145-
146-
async loadSettings() {
147-
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
148-
}
149-
150-
async saveSettings() {
151-
await this.saveData(this.settings);
152-
}
153-
154-
async onunload() {
155-
//FIX if there more than one file in workspace you need to remove the buttons line from them all
156-
// Remove Buttons line
157-
const file = this.app.workspace.getActiveFile() as TFile
158-
await buttonsLine(this.app, file, this.settings, true)
159-
unSortedObserver(this.app, false)
160-
console.log("unloading Cluster plugin");
161-
}
162+
</defs>`,
163+
);
164+
this.addRibbonIcon("cluster-svg", "Create new cluster", (evt) => {
165+
createClustersAndOrphansFolder(this.app);
166+
new familyModal(
167+
this.app,
168+
NewFileLocation.NewTab,
169+
"newCluster",
170+
undefined,
171+
).open();
172+
});
173+
//- File Menu
174+
fileMenu(this);
175+
}
176+
177+
async loadSettings() {
178+
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
179+
}
180+
181+
async saveSettings() {
182+
await this.saveData(this.settings);
183+
}
184+
185+
async onunload() {
186+
//FIX if there more than one file in workspace you need to remove the buttons line from them all
187+
// Remove Buttons line
188+
const file = this.app.workspace.getActiveFile() as TFile;
189+
await buttonsLine(this.app, file, this.settings, true);
190+
unSortedObserver(this.app, false);
191+
console.log("unloading Cluster plugin");
192+
}
162193
}

src/createFamily/buttons.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1-
import { App, TFile, setTooltip, setIcon, addIcon, WorkspaceLeaf, MarkdownView, Editor, Platform } from "obsidian";
1+
import { App, TFile, setTooltip, setIcon, addIcon, MarkdownView, Editor, Platform } from "obsidian";
22
import familyModal from "./familyModal";
33
import { NewFileLocation } from '../util/enums';
44
import deleteActiveNoteModal from "./deleteActiveNoteModal";
55
import { createClustersAndOrphansFolder } from "./createClustersAndOrphansFolder";
66
import { puzzleTemplate } from "./templates";
7+
import type { clusterPluginSettings } from "main";
78

89
const clusters = "CLUSTERS"
910
const orphans = "ORPHANS"
1011
let Vars = {}
11-
export async function buttonsLine(appObject: App, file: TFile, settings?: any, removeButtons?: boolean) {
12+
export async function buttonsLine(appObject: App, file: TFile, settings?: clusterPluginSettings, removeButtons?: boolean) {
1213

13-
Vars = settings
14+
Vars = settings as clusterPluginSettings;
1415
//! Android
1516
if (Platform.isMobile) {
16-
let LEAF = appObject.workspace.getActiveViewOfType(MarkdownView)
17+
const LEAF = appObject.workspace.getActiveViewOfType(MarkdownView)
1718
if (LEAF !== null) {
18-
const obsidianContainer = LEAF!.containerEl
19+
const obsidianContainer = LEAF?.containerEl
1920

2021
const obsidianContainerElements = Array?.from(obsidianContainer?.children)
2122
//@ts-ignore
22-
const obsidianHeaderEl = LEAF!.headerEl
23+
const obsidianHeaderEl = LEAF?.headerEl
2324
if (removeButtons) {//remove buttons when on unload
2425
RemoveButtonsLine(file, obsidianContainer, obsidianContainerElements, obsidianHeaderEl)
2526
} else {
@@ -36,7 +37,7 @@ export async function buttonsLine(appObject: App, file: TFile, settings?: any, r
3637
//@ts-ignore
3738
const activeLeavePath = activeLeave?.file?.path as string
3839
if (activeLeavePath.startsWith(clusters) || activeLeavePath.startsWith(orphans)) {
39-
const obsidianContainer = activeLeave!.containerEl
40+
const obsidianContainer = activeLeave?.containerEl
4041
const obsidianContainerElements = Array?.from(obsidianContainer?.children)
4142
//@ts-ignore
4243
const obsidianHeaderEl = activeLeave!.headerEl
@@ -276,4 +277,16 @@ function firstPageOfClusters(file: TFile, obsidianContainerElements: any) {
276277
}
277278
}
278279

280+
}
281+
282+
export async function cardStyleFunction(settings: clusterPluginSettings){
283+
setTimeout(() => {
284+
285+
const appContainer = document.body
286+
if(settings.cardStyle){
287+
appContainer.classList.add("card-layout-open-dark")
288+
}else{
289+
appContainer.classList.remove("card-layout-open-dark")
290+
}
291+
}, 500);
279292
}

0 commit comments

Comments
 (0)