-
-
Notifications
You must be signed in to change notification settings - Fork 287
feat: consolidate dendron configs #1295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
1ea9769
52dc0f0
afabae2
5884377
34ed614
5fab3e1
8ccc860
8c95505
8acc3d5
a9df10a
f5e1e75
142fac0
9c41819
6780bea
c5c22be
aca742d
67b1e6e
72e099b
3d06a31
864561d
5012ab1
e0cae85
a20e8f8
33653b1
fc180be
dfa32ff
1fa756f
69bc20b
51900ef
cbc92c4
517facc
b574dda
dc13a17
2ada327
609873b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export type DendronConfigValueType = string | boolean | number; | ||
|
||
/** | ||
* DendronConfigEntry | ||
* Holds the value, label, and description of individual configuration entries. | ||
* | ||
* For config entries that can be an arbitrary value, only specify the label and description. | ||
* For config entries that have pre-defined choices, provide the value as well as label and description specific to that value. | ||
*/ | ||
export type DendronConfigEntry<DendronConfigValueType> = { | ||
value?: DendronConfigValueType; | ||
label: string; | ||
desc: string; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { | ||
genDefaultInsertNoteLinkConfig, | ||
InsertNoteLinkConfig, | ||
INSERT_NOTE_LINK, | ||
} from "./insertNoteLink"; | ||
import { genDefaultLookupConfig, LookupConfig, LOOKUP } from "./lookup"; | ||
|
||
/** | ||
* Namespace for all command related configurations | ||
*/ | ||
export type DendronCommandConfig = { | ||
lookup: LookupConfig; | ||
insertNoteLink: InsertNoteLinkConfig; | ||
}; | ||
|
||
/** | ||
* Constants holding all command config related {@link DendronConfigEntry} | ||
*/ | ||
export const COMMANDS = { | ||
LOOKUP, | ||
INSERT_NOTE_LINK, | ||
}; | ||
|
||
/** | ||
* Generates default {@link DendronCommandConfig} using | ||
* respective default config generators that each command config implements. | ||
* @returns DendronCommandConfig | ||
*/ | ||
export function genDefaultCommandConfig(): DendronCommandConfig { | ||
return { | ||
lookup: genDefaultLookupConfig(), | ||
insertNoteLink: genDefaultInsertNoteLinkConfig(), | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { DendronConfigEntry } from "../base"; | ||
|
||
/** | ||
* Enum definitions of possible alias mode values | ||
*/ | ||
export enum InsertNoteLinkAliasModeEnum { | ||
snippet = "snippet", | ||
selection = "selection", | ||
title = "title", | ||
prompt = "prompt", | ||
none = "none", | ||
} | ||
|
||
/** | ||
* String literal types generated from {@link InsertNoteLinkAliasModeEnum} | ||
*/ | ||
export type InsertNoteLinkAliasMode = keyof typeof InsertNoteLinkAliasModeEnum; | ||
|
||
/** | ||
* Namespace for configuring {@link InsertNoteLinkCommand} | ||
*/ | ||
export type InsertNoteLinkConfig = { | ||
aliasMode: InsertNoteLinkAliasModeEnum; | ||
multiSelect: boolean; | ||
}; | ||
|
||
/** | ||
* Constants for possible alias mode choices. | ||
* Each key of {@link InsertNoteLinkAliasMode} is mapped to a {@link DendronConfigEntry} | ||
* which specifies the value, label, description of possible alias modes. | ||
* | ||
* These are used to generate user friendly descriptions in the configuration UI. | ||
*/ | ||
const ALIAS_MODES: { | ||
[key in InsertNoteLinkAliasMode]: DendronConfigEntry<string>; | ||
} = { | ||
snippet: { | ||
value: InsertNoteLinkAliasModeEnum.snippet, | ||
label: "snippet mode", | ||
desc: "Insert note link as snippet string", | ||
}, | ||
selection: { | ||
value: InsertNoteLinkAliasModeEnum.selection, | ||
label: "selection mode", | ||
desc: "Extract selection and use as link alias", | ||
}, | ||
title: { | ||
value: InsertNoteLinkAliasModeEnum.title, | ||
label: "title mode", | ||
desc: "Use linked note's title as link alias", | ||
}, | ||
prompt: { | ||
value: InsertNoteLinkAliasModeEnum.prompt, | ||
label: "prompt mode", | ||
desc: "Prompt for input to be used as link alias", | ||
}, | ||
none: { | ||
value: InsertNoteLinkAliasModeEnum.none, | ||
label: "no alias mode", | ||
desc: "Do not add link alias", | ||
}, | ||
}; | ||
|
||
/** | ||
* Given a boolean value, returns a {@link DendronConfigEntry} that holds | ||
* user friendly description of the multi-select behavior. | ||
* | ||
* This is a function instead of an object because object keys cannot be booleans. | ||
* | ||
* @param value boolean | ||
* @returns DendronConfigEntry<boolean> | ||
*/ | ||
const MULTI_SELECT = (value: boolean): DendronConfigEntry<boolean> => { | ||
const valueToString = value ? "Enable" : "Disable"; | ||
return { | ||
value, | ||
label: `${valueToString} multi-select`, | ||
desc: `${valueToString} multi-select when inserting note link(s)`, | ||
}; | ||
}; | ||
|
||
/** | ||
* Constants / functions that produce constants for | ||
* possible insert note link configurations. | ||
*/ | ||
export const INSERT_NOTE_LINK = { | ||
ALIAS_MODES, | ||
MULTI_SELECT, | ||
}; | ||
|
||
/** | ||
* Generates default {@link InsertNoteLinkConfig} | ||
* @returns InsertNoteLinkConfig | ||
*/ | ||
export function genDefaultInsertNoteLinkConfig(): InsertNoteLinkConfig { | ||
return { | ||
aliasMode: InsertNoteLinkAliasModeEnum.none, | ||
multiSelect: false, | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { DendronConfigEntry } from "../base"; | ||
|
||
/** | ||
* Enum definition of possible lookup selection behavior values | ||
*/ | ||
export enum NoteLookupSelectionBehaviorEnum { | ||
extract = "extract", | ||
link = "link", | ||
none = "none", | ||
} | ||
|
||
/** | ||
* String literal type generated from {@link NoteLookupSelectionBehaviorEnum} | ||
*/ | ||
export type NoteLookupSelectionBehavior = | ||
keyof typeof NoteLookupSelectionBehaviorEnum; | ||
|
||
/** | ||
* Namespace for configuring lookup commands | ||
*/ | ||
export type LookupConfig = { | ||
note: NoteLookupConfig; | ||
}; | ||
|
||
/** | ||
* Namespace for configuring {@link NoteLookupCommand} | ||
*/ | ||
type NoteLookupConfig = { | ||
selectionBehavior: NoteLookupSelectionBehavior; | ||
}; | ||
|
||
/** | ||
* Constants for possible note lookup selection behaviors. | ||
* Each key holds a {@link DendronConfigEntry} | ||
* which specifies the value, label, description of possible selection behaviors. | ||
* | ||
* These are used to generate user friendly descriptions in the configuration UI. | ||
*/ | ||
const SELECTION_BEHAVIORS: { | ||
[key in NoteLookupSelectionBehavior]: DendronConfigEntry<string>; | ||
} = { | ||
extract: { | ||
value: NoteLookupSelectionBehaviorEnum.extract, | ||
label: "extract selection", | ||
desc: "Extract selection of active editor and use it as body of new note.", | ||
}, | ||
link: { | ||
value: NoteLookupSelectionBehaviorEnum.link, | ||
label: "selection to link", | ||
desc: "Use selection of active editor for the basename of the lookup value.", | ||
}, | ||
none: { | ||
value: NoteLookupSelectionBehaviorEnum.none, | ||
label: "none", | ||
desc: "Do not set selection behavior", | ||
}, | ||
}; | ||
|
||
/** | ||
* Constants / functions that produce | ||
* constants for possible lookup configurations | ||
*/ | ||
export const LOOKUP = { | ||
NOTE: { | ||
SELECTION: SELECTION_BEHAVIORS, | ||
}, | ||
}; | ||
|
||
/** | ||
* Generates default {@link LookupConfig} | ||
* @returns LookupConfig | ||
*/ | ||
export function genDefaultLookupConfig(): LookupConfig { | ||
return { | ||
note: { | ||
selectionBehavior: NoteLookupSelectionBehaviorEnum.extract, | ||
}, | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { | ||
DendronCommandConfig, | ||
genDefaultCommandConfig, | ||
COMMANDS, | ||
} from "./commands/commands"; | ||
import { | ||
DendronWorkspaceConfig, | ||
genDefaultWorkspaceConfig, | ||
WORKSPACE, | ||
} from "./workspace/workspace"; | ||
|
||
/** | ||
* DendronConfig | ||
* This is the top level config that will hold everything. | ||
*/ | ||
export type DendronConfig = { | ||
commands: DendronCommandConfig; | ||
workspace: DendronWorkspaceConfig; | ||
}; | ||
|
||
/** | ||
* Constants holding all {@link DendronConfigEntry} | ||
*/ | ||
export const DENDRON_CONFIG = { | ||
COMMANDS, | ||
WORKSPACE, | ||
}; | ||
|
||
/** | ||
* Generates a default DendronConfig using | ||
* respective default config generators of each sub config groups. | ||
* @returns DendronConfig | ||
*/ | ||
export function genDefaultDendronConfig(): DendronConfig { | ||
return { | ||
commands: genDefaultCommandConfig(), | ||
workspace: genDefaultWorkspaceConfig(), | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import { DendronConfigEntry } from "../base"; | ||
|
||
/** | ||
* Enum definition of possible note add behavior values. | ||
*/ | ||
export enum NoteAddBehaviorEnum { | ||
childOfDomain = "childOfDomain", | ||
childOfDomainNamespace = "childOfDomainNamespace", | ||
childOfCurrent = "childOfCurrent", | ||
asOwnDomain = "asOwnDomain", | ||
} | ||
|
||
/** | ||
* String literal type generated from {@link NoteAddBehaviorEnum} | ||
*/ | ||
export type NoteAddBehavior = keyof typeof NoteAddBehaviorEnum; | ||
|
||
/** | ||
* Namespace for configuring journal note behavior | ||
*/ | ||
export type JournalConfig = { | ||
dailyDomain: string; | ||
dailyVault?: string; | ||
name: string; | ||
dateFormat: string; | ||
addBehavior: NoteAddBehaviorEnum; | ||
firstDayOfWeek: number; | ||
}; | ||
|
||
/** | ||
* Constants for possible note add behaviors. | ||
* Each key of {@link NoteAddBehavior} is mapped to a {@link DendronConfigEntry} | ||
* which specifies the value, label, description of possible note add behaviors. | ||
* | ||
* These are used to generate user friendly descriptions in the configuration. | ||
*/ | ||
const ADD_BEHAVIOR: { | ||
[key in NoteAddBehavior]: DendronConfigEntry<string>; | ||
} = { | ||
childOfDomain: { | ||
value: "childOfDomain", | ||
label: "child of domain", | ||
desc: "Note is added as the child of domain of the current hierarchy", | ||
}, | ||
childOfDomainNamespace: { | ||
value: "childOfDomainNamespace", | ||
label: "child of domain namespace", | ||
desc: "Note is added as child of the namespace of the current domain if it has a namespace. Otherwise added as child of domain.", | ||
}, | ||
childOfCurrent: { | ||
value: "childOfCurrent", | ||
label: "child of current", | ||
desc: "Note is added as a child of the current open note", | ||
}, | ||
asOwnDomain: { | ||
value: "asOwnDomain", | ||
label: "as own domain", | ||
desc: "Note is created under the domain specified by journal name value", | ||
}, | ||
}; | ||
|
||
// const assertion to tell the compiler that we only want these as dayOfWeekNumber. | ||
const possibleDayOfWeekNumber = [0, 1, 2, 3, 4, 5, 6] as const; | ||
export type dayOfWeekNumber = typeof possibleDayOfWeekNumber[number]; | ||
|
||
/** | ||
* Given a {@link dayOfWeekNumber}, returns a {@link DendronConfigEntry} that holds | ||
* user friendly description of the first day of week behavior. | ||
* | ||
* @param value {@link dayOfWeekNumber} | ||
* @returns DendronConfigEntry | ||
*/ | ||
const FIRST_DAY_OF_WEEK = ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just a heads up that we're currently not supporting this option due to limitation in calendar widget. we'll add support back in eventually but FYI There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am aware of this. I also have been taking note on other configs with some peculiarities that we need to address once we start actually migrating. |
||
value: dayOfWeekNumber | ||
): DendronConfigEntry<dayOfWeekNumber> => { | ||
const dayOfWeek = [ | ||
"Sunday", | ||
"Monday", | ||
"Tuesday", | ||
"Wednesday", | ||
"Thursday", | ||
"Friday", | ||
"Saturday", | ||
]; | ||
const valueToDay = dayOfWeek[value]; | ||
return { | ||
label: valueToDay, | ||
desc: `Set start of the week to ${valueToDay}`, | ||
}; | ||
}; | ||
|
||
/** | ||
* Constants / functions that produce constants for possible journal configurations. | ||
* config entries that doesn't have limited choices have their values omitted. | ||
* config entries that have specific choices have their choices predefined or generated. | ||
*/ | ||
export const JOURNAL = { | ||
DAILY_DOMAIN: { | ||
label: "daily domain", | ||
desc: "Domain where the journal notes are created", | ||
}, | ||
NAME: { | ||
label: "journal name", | ||
desc: "Name used for journal notes", | ||
}, | ||
DATE_FORMAT: { | ||
label: "date format", | ||
desc: "Date format used for journal notes", | ||
}, | ||
ADD_BEHAVIOR, | ||
FIRST_DAY_OF_WEEK, | ||
}; | ||
|
||
/** | ||
* Generates default {@link JournalConfig} | ||
* @returns JouranlConfig | ||
*/ | ||
export function genDefaultJournalConfig(): JournalConfig { | ||
return { | ||
dailyDomain: "daily", | ||
name: "journal", | ||
dateFormat: "y.MM.dd", | ||
addBehavior: NoteAddBehaviorEnum.childOfDomain, | ||
firstDayOfWeek: 1, | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thoughts between using constants vs enums? You can use
Object.values
to get all enum valuesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The values in the object are also constants that themselves holding other constants or functions that produce constants.
Are you suggesting we have nested enums (not sure if that's a thing)? or we flatten it out and have a giant enum that holds all possible labels and descriptions?