Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit 2e76c0b

Browse files
committed
skeleton of alignment
1 parent 719f497 commit 2e76c0b

File tree

11 files changed

+118
-9
lines changed

11 files changed

+118
-9
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,22 @@
2828
"@testing-library/react": "13.4.0",
2929
"@types/jest": "28.1.8",
3030
"@types/luxon": "3.0.1",
31-
"@types/node": "18.7.16",
32-
"@types/react": "18.0.19",
31+
"@types/node": "18.7.18",
32+
"@types/react": "18.0.20",
3333
"@types/react-color": "3.0.6",
3434
"@types/react-csv": "1.1.3",
3535
"@types/react-datepicker": "4.4.2",
3636
"@types/react-dom": "18.0.6",
3737
"@types/react-window": "1.8.5",
3838
"@typescript-eslint/eslint-plugin": "5.36.2",
3939
"@typescript-eslint/parser": "5.36.2",
40-
"eslint": "8.23.0",
40+
"eslint": "8.23.1",
4141
"jest": "28.1.3",
4242
"jest-mock-extended": "2.0.7",
4343
"obsidian": "0.15.9",
4444
"rollup": "2.79.0",
4545
"rollup-plugin-terser": "7.0.2",
46-
"rollup-plugin-typescript2": "0.33.0",
46+
"rollup-plugin-typescript2": "0.34.0",
4747
"ts-jest": "28.0.8",
4848
"tslib": "2.4.0",
4949
"typescript": "4.8.3"

src/cdm/FolderModel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export interface ConfigColumn {
3939
media_width: number;
4040
media_height: number;
4141
isInline: boolean;
42+
content_alignment: string;
4243
task_hide_completed?: boolean;
4344
formula_query?: string;
4445
persist_formula?: boolean;

src/cdm/StyleModel.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import { RowSelectOption } from "cdm/ComponentsModel";
22
import { ColumnSettingsModal } from "components/modals/columnSettings/ColumnSettingsModal";
33

4-
export type ColorPickerProps = {
4+
type BaseStyleProps = {
55
modal: ColumnSettingsModal;
6+
columnKey: string;
7+
};
8+
9+
export type ColorPickerProps = {
610
options: RowSelectOption[];
711
option: RowSelectOption;
8-
columnKey: string;
9-
};
12+
} & BaseStyleProps;
13+
14+
export type TextAlignmentProps = {
15+
16+
} & BaseStyleProps;

src/components/modals/columnSettings/ColumnSections.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { SelectedColumnOptionsHandler } from "components/modals/columnSettings/h
77
import { HideCompletedTaskToggleHandler } from "components/modals/columnSettings/handlers/tasks/HideCompletedTaskToggleHandler";
88
import { LinkAliasToggleHandler } from "components/modals/columnSettings/handlers/media/LinkAliasToggleHandler";
99
import { FormulaInputHandler } from "components/modals/columnSettings/handlers/automations/FormulaInputHandler";
10+
import { AlignmentSelectorHandler } from "components/modals/columnSettings/handlers/AlignmentSelectorHandler";
1011
import { InputType } from "helpers/Constants";
1112
import { AbstractChain } from "patterns/AbstractFactoryChain";
1213
import { AbstractHandler } from "patterns/AbstractHandler";
@@ -25,6 +26,7 @@ class BehaviorSetttingsSection extends AbstractChain<ColumnSettingsHandlerRespon
2526
}
2627
protected getHandlers(): AbstractHandler<ColumnSettingsHandlerResponse>[] {
2728
const particularHandlers: AbstractHandler<ColumnSettingsHandlerResponse>[] = [];
29+
particularHandlers.push(new AlignmentSelectorHandler());
2830
switch (this.input) {
2931
case InputType.TASK:
3032
// do nothing
@@ -68,6 +70,7 @@ class ParticularSetttingsSection extends AbstractChain<ColumnSettingsHandlerResp
6870
break;
6971
case InputType.TASK:
7072
particularHandlers.push(new HideCompletedTaskToggleHandler());
73+
break;
7174
case InputType.FORMULA:
7275
particularHandlers.push(new FormulaInputHandler());
7376
break;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { ColumnSettingsHandlerResponse } from "cdm/ModalsModel";
2+
import TextAlignmentSelector from "components/styles/TextAlignmentSelector";
3+
import { Setting } from "obsidian";
4+
import { AbstractHandlerClass } from "patterns/AbstractHandler";
5+
import React from "react";
6+
import { createRoot } from "react-dom/client";
7+
8+
export class AlignmentSelectorHandler extends AbstractHandlerClass<ColumnSettingsHandlerResponse> {
9+
settingTitle: string = "Content alignment selector";
10+
handle(
11+
columnHandlerResponse: ColumnSettingsHandlerResponse
12+
): ColumnSettingsHandlerResponse {
13+
const { column, containerEl, columnSettingsManager } =
14+
columnHandlerResponse;
15+
16+
const alignmentSetting = new Setting(containerEl)
17+
.setName(this.settingTitle)
18+
.setDesc("Change content alignment of the column");
19+
20+
createRoot(alignmentSetting.controlEl.createDiv()).render(
21+
<TextAlignmentSelector
22+
modal={columnSettingsManager.modal}
23+
columnKey={column.key}
24+
/>
25+
);
26+
return this.goNext(columnHandlerResponse);
27+
}
28+
}

src/components/modals/columnSettings/handlers/SelectedColumnOptionsHandler.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ColumnSettingsHandlerResponse } from "cdm/ModalsModel";
22
import { ColorPickerProps } from "cdm/StyleModel";
3-
import { ColorPicker } from "components/ColorPicker";
3+
import { ColorPicker } from "components/styles/ColorPicker";
44
import { randomColor } from "helpers/Colors";
55
import { ButtonComponent, Notice, Setting } from "obsidian";
66
import { AbstractHandlerClass } from "patterns/AbstractHandler";

src/components/modals/columnSettings/handlers/media/LinkAliasToggleHandler.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export class LinkAliasToggleHandler extends AbstractHandlerClass<ColumnSettingsH
66
handle(columnHandlerResponse: ColumnSettingsHandlerResponse): ColumnSettingsHandlerResponse {
77
const { column, containerEl, columnSettingsManager } = columnHandlerResponse;
88
const { view } = columnSettingsManager.modal;
9-
const { config } = column
109
// pass if modal opened from local settings
1110
const link_alias_togle_promise = async (value: boolean): Promise<void> => {
1211
column.config.link_alias_enabled = value;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import * as React from "react";
2+
import FormatAlignLeftIcon from "@mui/icons-material/FormatAlignLeft";
3+
import FormatAlignCenterIcon from "@mui/icons-material/FormatAlignCenter";
4+
import FormatAlignRightIcon from "@mui/icons-material/FormatAlignRight";
5+
import Stack from "@mui/material/Stack";
6+
import ToggleButton from "@mui/material/ToggleButton";
7+
import ToggleButtonGroup from "@mui/material/ToggleButtonGroup";
8+
import { TextAlignmentProps } from "cdm/StyleModel";
9+
import { COLUMN_ALIGNMENT_OPTIONS } from "helpers/Constants";
10+
11+
export default function TextAlignmentSelector(props: TextAlignmentProps) {
12+
const { modal, columnKey } = props;
13+
const { view } = modal;
14+
const [alignment, setAlignment] = React.useState("left");
15+
16+
const handleAlignment = async (
17+
event: React.MouseEvent<HTMLElement>,
18+
newAlignment: string | null
19+
) => {
20+
if (newAlignment !== null) {
21+
// Persist changes
22+
await view.diskConfig.updateColumnConfig(columnKey, {
23+
content_alignment: newAlignment,
24+
});
25+
modal.enableReset = true;
26+
setAlignment(newAlignment);
27+
}
28+
};
29+
30+
return (
31+
<Stack direction="row" spacing={4}>
32+
<ToggleButtonGroup
33+
value={alignment}
34+
exclusive
35+
onChange={handleAlignment}
36+
aria-label="text alignment"
37+
>
38+
<ToggleButton
39+
value={COLUMN_ALIGNMENT_OPTIONS.LEFT}
40+
aria-label="left aligned"
41+
>
42+
<FormatAlignLeftIcon />
43+
</ToggleButton>
44+
<ToggleButton
45+
value={COLUMN_ALIGNMENT_OPTIONS.CENTER}
46+
aria-label="centered"
47+
>
48+
<FormatAlignCenterIcon />
49+
</ToggleButton>
50+
<ToggleButton
51+
value={COLUMN_ALIGNMENT_OPTIONS.RIGHT}
52+
aria-label="right aligned"
53+
>
54+
<FormatAlignRightIcon />
55+
</ToggleButton>
56+
</ToggleButtonGroup>
57+
</Stack>
58+
);
59+
}

src/helpers/Constants.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ export const MetadataLabels = Object.freeze({
7171
OUTLINKS: 'Outlinks',
7272
INLINKS: 'Inlinks',
7373
});
74+
/******************************************************************************
75+
* COLUMN CONFIGURATIONS *
76+
******************************************************************************/
77+
export const COLUMN_ALIGNMENT_OPTIONS = Object.freeze({
78+
LEFT: 'left',
79+
CENTER: 'center',
80+
RIGHT: 'right',
81+
});
7482

7583
export const DEFAULT_COLUMN_CONFIG: ConfigColumn = Object.freeze({
7684
enable_media_view: true,
@@ -79,6 +87,7 @@ export const DEFAULT_COLUMN_CONFIG: ConfigColumn = Object.freeze({
7987
media_height: 100,
8088
isInline: false,
8189
task_hide_completed: true,
90+
content_alignment: COLUMN_ALIGNMENT_OPTIONS.LEFT,
8291
});
8392

8493
export const MetadataDatabaseColumns: MetadataColumnsModel = Object.freeze({

0 commit comments

Comments
 (0)