@real1ty-obsidian-plugins/utils 2.0.1 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -10,6 +10,7 @@ export * from "./frontmatter-utils";
10
10
  export * from "./generate";
11
11
  export * from "./link-parser";
12
12
  export * from "./settings-store";
13
+ export * from "./settings-ui-builder";
13
14
  export * from "./string-utils";
14
15
  export * from "./templater-utils";
15
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC"}
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ export * from "./frontmatter-utils";
10
10
  export * from "./generate";
11
11
  export * from "./link-parser";
12
12
  export * from "./settings-store";
13
+ export * from "./settings-ui-builder";
13
14
  export * from "./string-utils";
14
15
  export * from "./templater-utils";
15
16
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC","sourcesContent":["export * from \"./async-utils\";\nexport * from \"./batch-operations\";\nexport * from \"./child-reference-utils\";\nexport * from \"./date-recurrence-utils\";\nexport * from \"./date-utils\";\nexport * from \"./evaluator-base\";\nexport * from \"./file-operations\";\nexport * from \"./file-utils\";\nexport * from \"./frontmatter-utils\";\nexport * from \"./generate\";\nexport * from \"./link-parser\";\nexport * from \"./settings-store\";\nexport * from \"./string-utils\";\nexport * from \"./templater-utils\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC","sourcesContent":["export * from \"./async-utils\";\nexport * from \"./batch-operations\";\nexport * from \"./child-reference-utils\";\nexport * from \"./date-recurrence-utils\";\nexport * from \"./date-utils\";\nexport * from \"./evaluator-base\";\nexport * from \"./file-operations\";\nexport * from \"./file-utils\";\nexport * from \"./frontmatter-utils\";\nexport * from \"./generate\";\nexport * from \"./link-parser\";\nexport * from \"./settings-store\";\nexport * from \"./settings-ui-builder\";\nexport * from \"./string-utils\";\nexport * from \"./templater-utils\";\n"]}
@@ -7,6 +7,7 @@ export declare class SettingsStore<TSchema extends z.ZodTypeAny> {
7
7
  readonly settings$: BehaviorSubject<z.infer<TSchema>>;
8
8
  constructor(plugin: Plugin, schema: TSchema);
9
9
  get currentSettings(): z.infer<TSchema>;
10
+ get validationSchema(): TSchema;
10
11
  loadSettings(): Promise<void>;
11
12
  saveSettings(): Promise<void>;
12
13
  updateSettings(updater: (settings: z.infer<TSchema>) => z.infer<TSchema>): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"settings-store.d.ts","sourceRoot":"","sources":["../src/settings-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,qBAAa,aAAa,CAAC,OAAO,SAAS,CAAC,CAAC,UAAU;IACtD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAAU;IACxB,SAAgB,SAAS,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;gBAEjD,MAAM,EAAE,MAAM,EAAE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AE,MAAM,EAAE,MAAM,EAAE,OAAO;IAM3C,IAAI,eAAe,IAAI,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAEtC;IAED,IAAI,gBAAgB,IAAI,OAAO,CAE9B;IAEK,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAiB7B,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAI7B,cAAc,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAaxF,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAK9B,cAAc,CAAC,CAAC,SAAS,MAAM,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,EACpD,GAAG,EAAE,CAAC,EACN,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GACxB,OAAO,CAAC,IAAI,CAAC;IAQV,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAMzE,WAAW,IAAI,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;IAI/B,iBAAiB,IAAI,OAAO;CAI5B"}
@@ -9,6 +9,9 @@ export class SettingsStore {
9
9
  get currentSettings() {
10
10
  return this.settings$.value;
11
11
  }
12
+ get validationSchema() {
13
+ return this.schema;
14
+ }
12
15
  loadSettings() {
13
16
  return __awaiter(this, void 0, void 0, function* () {
14
17
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"settings-store.js","sourceRoot":"","sources":["../src/settings-store.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAGvC,MAAM,OAAO,aAAa;IAKzB,YAAY,MAAc,EAAE,MAAe;QAC1C,IAAI,CAAC,MAAM,GAAG,MAAM,CAA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,SAAS,CAAC,IAAI,CAAC,eAAe,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC1E,CAAC;CACD","sourcesContent":["import type { Plugin } from \"obsidian\";\nimport { BehaviorSubject } from \"rxjs\";\nimport type { z } from \"zod\";\n\nexport class SettingsStore<TSchema extends z.ZodTypeAny> {\n\tprivate plugin: Plugin;\n\tprivate schema: TSchema;\n\tpublic readonly settings$: BehaviorSubject<z.infer<TSchema>>;\n\n\tconstructor(plugin: Plugin, schema: TSchema) {\n\t\tthis.plugin = plugin;\n\t\tthis.schema = schema;\n\t\tthis.settings$ = new BehaviorSubject<z.infer<TSchema>>(schema.parse({}));\n\t}\n\n\tget currentSettings(): z.infer<TSchema> {\n\t\treturn this.settings$.value;\n\t}\n\n\tasync loadSettings(): Promise<void> {\n\t\ttry {\n\t\t\tconst data = await this.plugin.loadData();\n\t\t\tconst sanitized = this.schema.parse(data ?? {});\n\t\t\tthis.settings$.next(sanitized);\n\n\t\t\t// Save back if data was sanitized/normalized\n\t\t\tif (JSON.stringify(sanitized) !== JSON.stringify(data ?? {})) {\n\t\t\t\tawait this.saveSettings();\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error(\"Failed to load settings, using defaults:\", error);\n\t\t\tthis.settings$.next(this.schema.parse({}));\n\t\t\tawait this.saveSettings();\n\t\t}\n\t}\n\n\tasync saveSettings(): Promise<void> {\n\t\tawait this.plugin.saveData(this.currentSettings);\n\t}\n\n\tasync updateSettings(updater: (settings: z.infer<TSchema>) => z.infer<TSchema>): Promise<void> {\n\t\ttry {\n\t\t\tconst newSettings = updater(this.currentSettings);\n\t\t\tconst validated = this.schema.parse(newSettings);\n\n\t\t\tthis.settings$.next(validated);\n\t\t\tawait this.saveSettings();\n\t\t} catch (error) {\n\t\t\tconsole.error(\"Failed to update settings:\", error);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tasync resetSettings(): Promise<void> {\n\t\tthis.settings$.next(this.schema.parse({}));\n\t\tawait this.saveSettings();\n\t}\n\n\tasync updateProperty<K extends keyof z.infer<TSchema>>(\n\t\tkey: K,\n\t\tvalue: z.infer<TSchema>[K]\n\t): Promise<void> {\n\t\tawait this.updateSettings((settings) => {\n\t\t\tconst updated = Object.assign({}, settings);\n\t\t\t(updated as any)[key] = value;\n\t\t\treturn updated;\n\t\t});\n\t}\n\n\tasync updateProperties(updates: Partial<z.infer<TSchema>>): Promise<void> {\n\t\tawait this.updateSettings((settings) => {\n\t\t\treturn Object.assign({}, settings, updates);\n\t\t});\n\t}\n\n\tgetDefaults(): z.infer<TSchema> {\n\t\treturn this.schema.parse({});\n\t}\n\n\thasCustomizations(): boolean {\n\t\tconst defaults = this.getDefaults();\n\t\treturn JSON.stringify(this.currentSettings) !== JSON.stringify(defaults);\n\t}\n}\n"]}
1
+ {"version":3,"file":"settings-store.js","sourceRoot":"","sources":["../src/settings-store.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAGvC,MAAM,OAAO,aAAa;IAKzB,YAAY,MAAc,EAAE,MAAe;QAC1C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,IAAI,eAAe,CAAmB,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1E,CAAC;IAED,IAAI,eAAe;QAClB,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED,IAAI,gBAAgB;QACnB,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;IAEK,YAAY;;YACjB,IAAI,CAAC;gBACJ,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;gBAC1C,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,E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AK,CAAC,EAAE,CAAC,CAAC,CAAC;YAC3C,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QAC3B,CAAC;KAAA;IAEK,cAAc,CACnB,GAAM,EACN,KAA0B;;YAE1B,MAAM,IAAI,CAAC,cAAc,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACtC,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;gBAC3C,OAAe,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;gBAC9B,OAAO,OAAO,CAAC;YAChB,CAAC,CAAC,CAAC;QACJ,CAAC;KAAA;IAEK,gBAAgB,CAAC,OAAkC;;YACxD,MAAM,IAAI,CAAC,cAAc,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACtC,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;YAC7C,CAAC,CAAC,CAAC;QACJ,CAAC;KAAA;IAED,WAAW;QACV,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC9B,CAAC;IAED,iBAAiB;QAChB,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QACpC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,eAAe,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC1E,CAAC;CACD","sourcesContent":["import type { Plugin } from \"obsidian\";\nimport { BehaviorSubject } from \"rxjs\";\nimport type { z } from \"zod\";\n\nexport class SettingsStore<TSchema extends z.ZodTypeAny> {\n\tprivate plugin: Plugin;\n\tprivate schema: TSchema;\n\tpublic readonly settings$: BehaviorSubject<z.infer<TSchema>>;\n\n\tconstructor(plugin: Plugin, schema: TSchema) {\n\t\tthis.plugin = plugin;\n\t\tthis.schema = schema;\n\t\tthis.settings$ = new BehaviorSubject<z.infer<TSchema>>(schema.parse({}));\n\t}\n\n\tget currentSettings(): z.infer<TSchema> {\n\t\treturn this.settings$.value;\n\t}\n\n\tget validationSchema(): TSchema {\n\t\treturn this.schema;\n\t}\n\n\tasync loadSettings(): Promise<void> {\n\t\ttry {\n\t\t\tconst data = await this.plugin.loadData();\n\t\t\tconst sanitized = this.schema.parse(data ?? {});\n\t\t\tthis.settings$.next(sanitized);\n\n\t\t\t// Save back if data was sanitized/normalized\n\t\t\tif (JSON.stringify(sanitized) !== JSON.stringify(data ?? {})) {\n\t\t\t\tawait this.saveSettings();\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error(\"Failed to load settings, using defaults:\", error);\n\t\t\tthis.settings$.next(this.schema.parse({}));\n\t\t\tawait this.saveSettings();\n\t\t}\n\t}\n\n\tasync saveSettings(): Promise<void> {\n\t\tawait this.plugin.saveData(this.currentSettings);\n\t}\n\n\tasync updateSettings(updater: (settings: z.infer<TSchema>) => z.infer<TSchema>): Promise<void> {\n\t\ttry {\n\t\t\tconst newSettings = updater(this.currentSettings);\n\t\t\tconst validated = this.schema.parse(newSettings);\n\n\t\t\tthis.settings$.next(validated);\n\t\t\tawait this.saveSettings();\n\t\t} catch (error) {\n\t\t\tconsole.error(\"Failed to update settings:\", error);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tasync resetSettings(): Promise<void> {\n\t\tthis.settings$.next(this.schema.parse({}));\n\t\tawait this.saveSettings();\n\t}\n\n\tasync updateProperty<K extends keyof z.infer<TSchema>>(\n\t\tkey: K,\n\t\tvalue: z.infer<TSchema>[K]\n\t): Promise<void> {\n\t\tawait this.updateSettings((settings) => {\n\t\t\tconst updated = Object.assign({}, settings);\n\t\t\t(updated as any)[key] = value;\n\t\t\treturn updated;\n\t\t});\n\t}\n\n\tasync updateProperties(updates: Partial<z.infer<TSchema>>): Promise<void> {\n\t\tawait this.updateSettings((settings) => {\n\t\t\treturn Object.assign({}, settings, updates);\n\t\t});\n\t}\n\n\tgetDefaults(): z.infer<TSchema> {\n\t\treturn this.schema.parse({});\n\t}\n\n\thasCustomizations(): boolean {\n\t\tconst defaults = this.getDefaults();\n\t\treturn JSON.stringify(this.currentSettings) !== JSON.stringify(defaults);\n\t}\n}\n"]}
@@ -0,0 +1,64 @@
1
+ import type { ZodObject, ZodRawShape } from "zod";
2
+ import type { SettingsStore } from "./settings-store";
3
+ interface BaseSettingConfig {
4
+ key: string;
5
+ name: string;
6
+ desc: string;
7
+ }
8
+ interface TextSettingConfig extends BaseSettingConfig {
9
+ placeholder?: string;
10
+ }
11
+ interface SliderSettingConfig extends BaseSettingConfig {
12
+ min?: number;
13
+ max?: number;
14
+ step?: number;
15
+ }
16
+ interface DropdownSettingConfig extends BaseSettingConfig {
17
+ options: Record<string, string>;
18
+ }
19
+ interface ArraySettingConfig<T = string> extends BaseSettingConfig {
20
+ placeholder?: string;
21
+ arrayDelimiter?: string;
22
+ multiline?: boolean;
23
+ itemType?: "string" | "number";
24
+ parser?: (input: string) => T;
25
+ validator?: (item: T) => boolean;
26
+ }
27
+ interface ArrayManagerConfig extends BaseSettingConfig {
28
+ placeholder?: string;
29
+ addButtonText?: string;
30
+ removeButtonText?: string;
31
+ emptyArrayFallback?: unknown;
32
+ preventEmpty?: boolean;
33
+ itemDescriptionFn?: (item: unknown) => string;
34
+ onBeforeAdd?: (newItem: unknown, currentItems: unknown[]) => unknown[] | Promise<unknown[]>;
35
+ onBeforeRemove?: (itemToRemove: unknown, currentItems: unknown[]) => unknown[] | Promise<unknown[]>;
36
+ quickActions?: Array<{
37
+ name: string;
38
+ desc: string;
39
+ buttonText: string;
40
+ condition?: (currentItems: unknown[]) => boolean;
41
+ action: (currentItems: unknown[]) => unknown[] | Promise<unknown[]>;
42
+ }>;
43
+ }
44
+ export declare class SettingsUIBuilder<TSchema extends ZodObject<ZodRawShape>> {
45
+ private settingsStore;
46
+ constructor(settingsStore: SettingsStore<TSchema>);
47
+ private get settings();
48
+ private get schema();
49
+ private updateSetting;
50
+ private inferSliderBounds;
51
+ private inferArrayItemType;
52
+ addToggle(containerEl: HTMLElement, config: BaseSettingConfig): void;
53
+ addSlider(containerEl: HTMLElement, config: SliderSettingConfig): void;
54
+ addText(containerEl: HTMLElement, config: TextSettingConfig): void;
55
+ addDropdown(containerEl: HTMLElement, config: DropdownSettingConfig): void;
56
+ addTextArray<T = string>(containerEl: HTMLElement, config: ArraySettingConfig<T>): void;
57
+ /**
58
+ * Advanced array manager with add/remove buttons for each item
59
+ * Similar to the directory settings pattern
60
+ */
61
+ addArrayManager(containerEl: HTMLElement, config: ArrayManagerConfig): void;
62
+ }
63
+ export {};
64
+ //# sourceMappingURL=settings-ui-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings-ui-builder.d.ts","sourceRoot":"","sources":["../src/settings-ui-builder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAuB,SAAS,EAAE,WAAW,EAAK,MAAM,KAAK,CAAC;AAC1E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD,UAAU,iBAAiB;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACb;AAED,UAAU,iBAAkB,SAAQ,iBAAiB;IACpD,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,UAAU,mBAAoB,SAAQ,iBAAiB;IACtD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,UAAU,qBAAsB,SAAQ,iBAAiB;IACxD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC;AAED,UAAU,kBAAkB,CAAC,CAAC,GAAG,MAAM,CAAE,SAAQ,iBAAiB;IACjE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ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Q,GAEnB;IAED,OAAO,KAAK,MAAM,GAEjB;YAEa,aAAa;IAmB3B,OAAO,CAAC,iBAAiB;IAiCzB,OAAO,CAAC,kBAAkB;IA0B1B,SAAS,CAAC,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,iBAAiB,GAAG,IAAI;IAcpE,SAAS,CAAC,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,mBAAmB,GAAG,IAAI;IAwBtE,OAAO,CAAC,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,iBAAiB,GAAG,IAAI;IAiBlE,WAAW,CAAC,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,qBAAqB,GAAG,IAAI;IAiB1E,YAAY,CAAC,CAAC,GAAG,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,IAAI;IAyEvF;;;OAGG;IACH,eAAe,CAAC,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,kBAAkB,GAAG,IAAI;CAiI3E"}
@@ -0,0 +1,305 @@
1
+ import { __awaiter } from "tslib";
2
+ import { Notice, Setting } from "obsidian";
3
+ export class SettingsUIBuilder {
4
+ constructor(settingsStore) {
5
+ this.settingsStore = settingsStore;
6
+ }
7
+ get settings() {
8
+ return this.settingsStore.currentSettings;
9
+ }
10
+ get schema() {
11
+ return this.settingsStore.validationSchema;
12
+ }
13
+ updateSetting(key, value) {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ const newSettings = Object.assign(Object.assign({}, this.settings), { [key]: value });
16
+ const result = this.schema.safeParse(newSettings);
17
+ if (!result.success) {
18
+ const errors = result.error.issues
19
+ .map((e) => `${String(e.path.join("."))}${e.path.length > 0 ? ": " : ""}${e.message}`)
20
+ .join(", ");
21
+ new Notice(`Validation failed: ${errors}`, 5000);
22
+ throw new Error(`Validation failed: ${errors}`);
23
+ }
24
+ yield this.settingsStore.updateSettings(() => newSettings);
25
+ });
26
+ }
27
+ inferSliderBounds(key) {
28
+ var _a, _b;
29
+ try {
30
+ const fieldSchema = this.schema.shape[key];
31
+ if (!fieldSchema)
32
+ return {};
33
+ let innerSchema = fieldSchema;
34
+ while ((_a = innerSchema._def) === null || _a === void 0 ? void 0 : _a.innerType) {
35
+ innerSchema = innerSchema._def.innerType;
36
+ }
37
+ if (((_b = innerSchema._def) === null || _b === void 0 ? void 0 : _b.typeName) === "ZodNumber") {
38
+ const checks = innerSchema._def.checks || [];
39
+ let min;
40
+ let max;
41
+ for (const check of checks) {
42
+ if (check.kind === "min") {
43
+ min = check.value;
44
+ }
45
+ if (check.kind === "max") {
46
+ max = check.value;
47
+ }
48
+ }
49
+ return { min, max };
50
+ }
51
+ }
52
+ catch (error) {
53
+ console.warn(`Failed to infer slider bounds for key ${key}:`, error);
54
+ }
55
+ return {};
56
+ }
57
+ inferArrayItemType(key) {
58
+ var _a, _b, _c, _d;
59
+ try {
60
+ const fieldSchema = this.schema.shape[key];
61
+ if (!fieldSchema)
62
+ return undefined;
63
+ let innerSchema = fieldSchema;
64
+ while ((_a = innerSchema._def) === null || _a === void 0 ? void 0 : _a.innerType) {
65
+ innerSchema = innerSchema._def.innerType;
66
+ }
67
+ if (((_b = innerSchema._def) === null || _b === void 0 ? void 0 : _b.typeName) === "ZodArray") {
68
+ const elementType = innerSchema._def.type;
69
+ if (((_c = elementType._def) === null || _c === void 0 ? void 0 : _c.typeName) === "ZodNumber") {
70
+ return "number";
71
+ }
72
+ if (((_d = elementType._def) === null || _d === void 0 ? void 0 : _d.typeName) === "ZodString") {
73
+ return "string";
74
+ }
75
+ }
76
+ }
77
+ catch (error) {
78
+ console.warn(`Failed to infer array item type for key ${key}:`, error);
79
+ }
80
+ return undefined;
81
+ }
82
+ addToggle(containerEl, config) {
83
+ const { key, name, desc } = config;
84
+ const value = this.settings[key];
85
+ new Setting(containerEl)
86
+ .setName(name)
87
+ .setDesc(desc)
88
+ .addToggle((toggle) => toggle.setValue(Boolean(value)).onChange((newValue) => __awaiter(this, void 0, void 0, function* () {
89
+ yield this.updateSetting(key, newValue);
90
+ })));
91
+ }
92
+ addSlider(containerEl, config) {
93
+ var _a, _b, _c, _d;
94
+ const { key, name, desc, step = 1 } = config;
95
+ const value = this.settings[key];
96
+ const inferredBounds = this.inferSliderBounds(key);
97
+ const min = (_b = (_a = config.min) !== null && _a !== void 0 ? _a : inferredBounds.min) !== null && _b !== void 0 ? _b : 0;
98
+ const max = (_d = (_c = config.max) !== null && _c !== void 0 ? _c : inferredBounds.max) !== null && _d !== void 0 ? _d : 100;
99
+ new Setting(containerEl)
100
+ .setName(name)
101
+ .setDesc(desc)
102
+ .addSlider((slider) => {
103
+ slider
104
+ .setLimits(min, max, step)
105
+ .setValue(Number(value))
106
+ .setDynamicTooltip()
107
+ .onChange((newValue) => __awaiter(this, void 0, void 0, function* () {
108
+ yield this.updateSetting(key, newValue);
109
+ }));
110
+ return slider;
111
+ });
112
+ }
113
+ addText(containerEl, config) {
114
+ const { key, name, desc, placeholder = "" } = config;
115
+ const value = this.settings[key];
116
+ new Setting(containerEl)
117
+ .setName(name)
118
+ .setDesc(desc)
119
+ .addText((text) => text
120
+ .setPlaceholder(placeholder)
121
+ .setValue(String(value !== null && value !== void 0 ? value : ""))
122
+ .onChange((newValue) => __awaiter(this, void 0, void 0, function* () {
123
+ yield this.updateSetting(key, newValue);
124
+ })));
125
+ }
126
+ addDropdown(containerEl, config) {
127
+ const { key, name, desc, options } = config;
128
+ const value = this.settings[key];
129
+ new Setting(containerEl)
130
+ .setName(name)
131
+ .setDesc(desc)
132
+ .addDropdown((dropdown) => dropdown
133
+ .addOptions(options)
134
+ .setValue(String(value))
135
+ .onChange((newValue) => __awaiter(this, void 0, void 0, function* () {
136
+ yield this.updateSetting(key, newValue);
137
+ })));
138
+ }
139
+ addTextArray(containerEl, config) {
140
+ var _a, _b, _c, _d;
141
+ const { key, name, desc, placeholder = "", arrayDelimiter = ", ", multiline = false } = config;
142
+ const value = this.settings[key];
143
+ const inferredItemType = (_b = (_a = config.itemType) !== null && _a !== void 0 ? _a : this.inferArrayItemType(key)) !== null && _b !== void 0 ? _b : "string";
144
+ const parser = (_c = config.parser) !== null && _c !== void 0 ? _c : ((input) => {
145
+ if (inferredItemType === "number") {
146
+ const num = Number(input);
147
+ if (Number.isNaN(num)) {
148
+ throw new Error(`Invalid number: ${input}`);
149
+ }
150
+ return num;
151
+ }
152
+ return input;
153
+ });
154
+ const validator = (_d = config.validator) !== null && _d !== void 0 ? _d : ((_item) => true);
155
+ const setting = new Setting(containerEl).setName(name).setDesc(desc);
156
+ if (multiline) {
157
+ setting.addTextArea((text) => {
158
+ text.setPlaceholder(placeholder);
159
+ text.setValue(Array.isArray(value) ? value.join("\n") : "");
160
+ const commit = (inputValue) => __awaiter(this, void 0, void 0, function* () {
161
+ const lines = inputValue
162
+ .split("\n")
163
+ .map((s) => s.trim())
164
+ .filter((s) => s.length > 0);
165
+ try {
166
+ const items = lines.map(parser).filter(validator);
167
+ yield this.updateSetting(key, items);
168
+ }
169
+ catch (error) {
170
+ new Notice(`Invalid input: ${error}`, 5000);
171
+ }
172
+ });
173
+ text.inputEl.addEventListener("blur", () => void commit(text.inputEl.value));
174
+ text.inputEl.addEventListener("keydown", (e) => {
175
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
176
+ e.preventDefault();
177
+ void commit(text.inputEl.value);
178
+ }
179
+ });
180
+ text.inputEl.rows = 5;
181
+ text.inputEl.classList.add("settings-ui-builder-textarea");
182
+ });
183
+ }
184
+ else {
185
+ setting.addText((text) => {
186
+ text.setPlaceholder(placeholder);
187
+ text.setValue(Array.isArray(value) ? value.join(arrayDelimiter) : "");
188
+ text.onChange((inputValue) => __awaiter(this, void 0, void 0, function* () {
189
+ const tokens = inputValue
190
+ .split(",")
191
+ .map((s) => s.trim())
192
+ .filter((s) => s.length > 0);
193
+ try {
194
+ const items = tokens.map(parser).filter(validator);
195
+ yield this.updateSetting(key, items);
196
+ }
197
+ catch (error) {
198
+ new Notice(`Invalid input: ${error}`, 5000);
199
+ }
200
+ }));
201
+ });
202
+ }
203
+ }
204
+ /**
205
+ * Advanced array manager with add/remove buttons for each item
206
+ * Similar to the directory settings pattern
207
+ */
208
+ addArrayManager(containerEl, config) {
209
+ var _a;
210
+ const { key, name, desc, placeholder = "", addButtonText = "Add", removeButtonText = "Remove", emptyArrayFallback = [], preventEmpty = false, itemDescriptionFn, onBeforeAdd, onBeforeRemove, quickActions = [], } = config;
211
+ // Section heading
212
+ new Setting(containerEl).setName(name).setHeading();
213
+ // Description
214
+ if (desc) {
215
+ const descEl = containerEl.createDiv("setting-item-description");
216
+ descEl.setText(desc);
217
+ }
218
+ // Container for list items
219
+ const listContainer = containerEl.createDiv("settings-array-manager-list");
220
+ const render = () => {
221
+ var _a;
222
+ listContainer.empty();
223
+ const currentItems = (_a = this.settings[key]) !== null && _a !== void 0 ? _a : [];
224
+ for (const item of currentItems) {
225
+ const itemSetting = new Setting(listContainer).setName(String(item)).addButton((button) => button
226
+ .setButtonText(removeButtonText)
227
+ .setWarning()
228
+ .onClick(() => __awaiter(this, void 0, void 0, function* () {
229
+ let newItems = currentItems.filter((i) => i !== item);
230
+ // Apply custom logic before removal
231
+ if (onBeforeRemove) {
232
+ newItems = yield onBeforeRemove(item, currentItems);
233
+ }
234
+ // Prevent empty array if configured
235
+ if (preventEmpty && newItems.length === 0) {
236
+ newItems = Array.isArray(emptyArrayFallback)
237
+ ? emptyArrayFallback
238
+ : [emptyArrayFallback];
239
+ }
240
+ yield this.updateSetting(key, newItems);
241
+ render();
242
+ })));
243
+ // Add custom description for each item if provided
244
+ if (itemDescriptionFn) {
245
+ itemSetting.setDesc(itemDescriptionFn(item));
246
+ }
247
+ }
248
+ };
249
+ render();
250
+ // Add new item section
251
+ const inputId = `settings-array-manager-input-${key}`;
252
+ new Setting(containerEl)
253
+ .setName(`Add ${name.toLowerCase()}`)
254
+ .setDesc(`Enter a new value`)
255
+ .addText((text) => {
256
+ text.setPlaceholder(placeholder);
257
+ text.inputEl.id = inputId;
258
+ })
259
+ .addButton((button) => button
260
+ .setButtonText(addButtonText)
261
+ .setCta()
262
+ .onClick(() => __awaiter(this, void 0, void 0, function* () {
263
+ var _a;
264
+ const input = containerEl.querySelector(`#${inputId}`);
265
+ const newItem = input.value.trim();
266
+ if (!newItem) {
267
+ return;
268
+ }
269
+ const currentItems = (_a = this.settings[key]) !== null && _a !== void 0 ? _a : [];
270
+ let newItems = [...currentItems];
271
+ // Apply custom logic before adding
272
+ if (onBeforeAdd) {
273
+ newItems = yield onBeforeAdd(newItem, currentItems);
274
+ }
275
+ else {
276
+ // Default behavior: add if not exists
277
+ if (!newItems.includes(newItem)) {
278
+ newItems.push(newItem);
279
+ }
280
+ }
281
+ yield this.updateSetting(key, newItems);
282
+ input.value = "";
283
+ render();
284
+ })));
285
+ // Quick actions
286
+ for (const quickAction of quickActions) {
287
+ const currentItems = (_a = this.settings[key]) !== null && _a !== void 0 ? _a : [];
288
+ // Check condition if provided
289
+ if (quickAction.condition && !quickAction.condition(currentItems)) {
290
+ continue;
291
+ }
292
+ new Setting(containerEl)
293
+ .setName(quickAction.name)
294
+ .setDesc(quickAction.desc)
295
+ .addButton((button) => button.setButtonText(quickAction.buttonText).onClick(() => __awaiter(this, void 0, void 0, function* () {
296
+ var _a;
297
+ const currentItems = (_a = this.settings[key]) !== null && _a !== void 0 ? _a : [];
298
+ const newItems = yield quickAction.action(currentItems);
299
+ yield this.updateSetting(key, newItems);
300
+ render();
301
+ })));
302
+ }
303
+ }
304
+ }
305
+ //# sourceMappingURL=settings-ui-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings-ui-builder.js","sourceRoot":"","sources":["../src/settings-ui-builder.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAsD3C,MAAM,OAAO,iBAAiB;IAC7B,YAAoB,aAAqC;QAArC,kBAAa,GAAb,aAAa,CAAwB;IAAG,CAAC;IAE7D,IAAY,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,QAAQ,CAAC,CAAC;YAClE,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC;YACjB,MAAM,EAAE,CAAC;QACV,CAAC,CAAA,CAAC,CACH,CAAC;QAEH,gBAAgB;QAChB,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE,CAAC;YACxC,MAAM,YAAY,GAAG,MAAC,IAAI,CAAC,QAAQ,CAAC,GAA6B,CAAe,mCAAI,EAAE,CAAC;YAEvF,8BAA8B;YAC9B,IAAI,WAAW,CAAC,SAAS,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE,CAAC;gBACnE,SAAS;YACV,CAAC;YAED,IAAI,OAAO,CAAC,WAAW,CAAC;iBACtB,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC;iBACzB,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC;iBACzB,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE,CACrB,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,GAAS,EAAE;;gBAC/D,MAAM,YAAY,GAAG,MAAC,IAAI,CAAC,QAAQ,CAAC,GAA6B,CAAe,mCAAI,EAAE,CAAC;gBACvF,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;gBACxD,MAAM,IAAI,CAAC,aAAa,CAAC,GAA6B,EAAE,QAAQ,CAAC,CAAC;gBAClE,MAAM,EAAE,CAAC;YACV,CAAC,CAAA,CAAC,CACF,CAAC;QACJ,CAAC;IACF,CAAC;CACD","sourcesContent":["import { Notice, Setting } from \"obsidian\";\nimport type { ZodArray, ZodNumber, ZodObject, ZodRawShape, z } from \"zod\";\nimport type { SettingsStore } from \"./settings-store\";\n\ninterface BaseSettingConfig {\n\tkey: string;\n\tname: string;\n\tdesc: string;\n}\n\ninterface TextSettingConfig extends BaseSettingConfig {\n\tplaceholder?: string;\n}\n\ninterface SliderSettingConfig extends BaseSettingConfig {\n\tmin?: number;\n\tmax?: number;\n\tstep?: number;\n}\n\ninterface DropdownSettingConfig extends BaseSettingConfig {\n\toptions: Record<string, string>;\n}\n\ninterface ArraySettingConfig<T = string> extends BaseSettingConfig {\n\tplaceholder?: string;\n\tarrayDelimiter?: string;\n\tmultiline?: boolean;\n\titemType?: \"string\" | \"number\";\n\tparser?: (input: string) => T;\n\tvalidator?: (item: T) => boolean;\n}\n\ninterface ArrayManagerConfig extends BaseSettingConfig {\n\tplaceholder?: string;\n\taddButtonText?: string;\n\tremoveButtonText?: string;\n\temptyArrayFallback?: unknown;\n\tpreventEmpty?: boolean;\n\titemDescriptionFn?: (item: unknown) => string;\n\tonBeforeAdd?: (newItem: unknown, currentItems: unknown[]) => unknown[] | Promise<unknown[]>;\n\tonBeforeRemove?: (\n\t\titemToRemove: unknown,\n\t\tcurrentItems: unknown[]\n\t) => unknown[] | Promise<unknown[]>;\n\tquickActions?: Array<{\n\t\tname: string;\n\t\tdesc: string;\n\t\tbuttonText: string;\n\t\tcondition?: (currentItems: unknown[]) => boolean;\n\t\taction: (currentItems: unknown[]) => unknown[] | Promise<unknown[]>;\n\t}>;\n}\n\nexport class SettingsUIBuilder<TSchema extends ZodObject<ZodRawShape>> {\n\tconstructor(private settingsStore: SettingsStore<TSchema>) {}\n\n\tprivate get settings(): z.infer<TSchema> {\n\t\treturn this.settingsStore.currentSettings;\n\t}\n\n\tprivate get schema(): TSchema {\n\t\treturn this.settingsStore.validationSchema;\n\t}\n\n\tprivate async updateSetting(key: keyof z.infer<TSchema>, value: unknown): Promise<void> {\n\t\tconst newSettings = {\n\t\t\t...this.settings,\n\t\t\t[key]: value,\n\t\t} as z.infer<TSchema>;\n\n\t\tconst result = this.schema.safeParse(newSettings);\n\n\t\tif (!result.success) {\n\t\t\tconst errors = result.error.issues\n\t\t\t\t.map((e) => `${String(e.path.join(\".\"))}${e.path.length > 0 ? \": \" : \"\"}${e.message}`)\n\t\t\t\t.join(\", \");\n\t\t\tnew Notice(`Validation failed: ${errors}`, 5000);\n\t\t\tthrow new Error(`Validation failed: ${errors}`);\n\t\t}\n\n\t\tawait this.settingsStore.updateSettings(() => newSettings);\n\t}\n\n\tprivate inferSliderBounds(key: string): { min?: number; max?: number; step?: number } {\n\t\ttry {\n\t\t\tconst fieldSchema = (this.schema.shape as any)[key];\n\t\t\tif (!fieldSchema) return {};\n\n\t\t\tlet innerSchema = fieldSchema;\n\t\t\twhile ((innerSchema as any)._def?.innerType) {\n\t\t\t\tinnerSchema = (innerSchema as any)._def.innerType;\n\t\t\t}\n\n\t\t\tif ((innerSchema as any)._def?.typeName === \"ZodNumber\") {\n\t\t\t\tconst checks = ((innerSchema as ZodNumber)._def as any).checks || [];\n\t\t\t\tlet min: number | undefined;\n\t\t\t\tlet max: number | undefined;\n\n\t\t\t\tfor (const check of checks) {\n\t\t\t\t\tif ((check as any).kind === \"min\") {\n\t\t\t\t\t\tmin = (check as any).value;\n\t\t\t\t\t}\n\t\t\t\t\tif ((check as any).kind === \"max\") {\n\t\t\t\t\t\tmax = (check as any).value;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn { min, max };\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.warn(`Failed to infer slider bounds for key ${key}:`, error);\n\t\t}\n\n\t\treturn {};\n\t}\n\n\tprivate inferArrayItemType(key: string): \"string\" | \"number\" | undefined {\n\t\ttry {\n\t\t\tconst fieldSchema = (this.schema.shape as any)[key];\n\t\t\tif (!fieldSchema) return undefined;\n\n\t\t\tlet innerSchema = fieldSchema;\n\t\t\twhile ((innerSchema as any)._def?.innerType) {\n\t\t\t\tinnerSchema = (innerSchema as any)._def.innerType;\n\t\t\t}\n\n\t\t\tif ((innerSchema as any)._def?.typeName === \"ZodArray\") {\n\t\t\t\tconst elementType = ((innerSchema as ZodArray<any>)._def as any).type;\n\t\t\t\tif ((elementType as any)._def?.typeName === \"ZodNumber\") {\n\t\t\t\t\treturn \"number\";\n\t\t\t\t}\n\t\t\t\tif ((elementType as any)._def?.typeName === \"ZodString\") {\n\t\t\t\t\treturn \"string\";\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.warn(`Failed to infer array item type for key ${key}:`, error);\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\taddToggle(containerEl: HTMLElement, config: BaseSettingConfig): void {\n\t\tconst { key, name, desc } = config;\n\t\tconst value = this.settings[key as keyof z.infer<TSchema>];\n\n\t\tnew Setting(containerEl)\n\t\t\t.setName(name)\n\t\t\t.setDesc(desc)\n\t\t\t.addToggle((toggle) =>\n\t\t\t\ttoggle.setValue(Boolean(value)).onChange(async (newValue) => {\n\t\t\t\t\tawait this.updateSetting(key as keyof z.infer<TSchema>, newValue);\n\t\t\t\t})\n\t\t\t);\n\t}\n\n\taddSlider(containerEl: HTMLElement, config: SliderSettingConfig): void {\n\t\tconst { key, name, desc, step = 1 } = config;\n\t\tconst value = this.settings[key as keyof z.infer<TSchema>];\n\n\t\tconst inferredBounds = this.inferSliderBounds(key);\n\t\tconst min = config.min ?? inferredBounds.min ?? 0;\n\t\tconst max = config.max ?? inferredBounds.max ?? 100;\n\n\t\tnew Setting(containerEl)\n\t\t\t.setName(name)\n\t\t\t.setDesc(desc)\n\t\t\t.addSlider((slider) => {\n\t\t\t\tslider\n\t\t\t\t\t.setLimits(min, max, step)\n\t\t\t\t\t.setValue(Number(value))\n\t\t\t\t\t.setDynamicTooltip()\n\t\t\t\t\t.onChange(async (newValue) => {\n\t\t\t\t\t\tawait this.updateSetting(key as keyof z.infer<TSchema>, newValue);\n\t\t\t\t\t});\n\n\t\t\t\treturn slider;\n\t\t\t});\n\t}\n\n\taddText(containerEl: HTMLElement, config: TextSettingConfig): void {\n\t\tconst { key, name, desc, placeholder = \"\" } = config;\n\t\tconst value = this.settings[key as keyof z.infer<TSchema>];\n\n\t\tnew Setting(containerEl)\n\t\t\t.setName(name)\n\t\t\t.setDesc(desc)\n\t\t\t.addText((text) =>\n\t\t\t\ttext\n\t\t\t\t\t.setPlaceholder(placeholder)\n\t\t\t\t\t.setValue(String(value ?? \"\"))\n\t\t\t\t\t.onChange(async (newValue) => {\n\t\t\t\t\t\tawait this.updateSetting(key as keyof z.infer<TSchema>, newValue);\n\t\t\t\t\t})\n\t\t\t);\n\t}\n\n\taddDropdown(containerEl: HTMLElement, config: DropdownSettingConfig): void {\n\t\tconst { key, name, desc, options } = config;\n\t\tconst value = this.settings[key as keyof z.infer<TSchema>];\n\n\t\tnew Setting(containerEl)\n\t\t\t.setName(name)\n\t\t\t.setDesc(desc)\n\t\t\t.addDropdown((dropdown) =>\n\t\t\t\tdropdown\n\t\t\t\t\t.addOptions(options)\n\t\t\t\t\t.setValue(String(value))\n\t\t\t\t\t.onChange(async (newValue) => {\n\t\t\t\t\t\tawait this.updateSetting(key as keyof z.infer<TSchema>, newValue);\n\t\t\t\t\t})\n\t\t\t);\n\t}\n\n\taddTextArray<T = string>(containerEl: HTMLElement, config: ArraySettingConfig<T>): void {\n\t\tconst { key, name, desc, placeholder = \"\", arrayDelimiter = \", \", multiline = false } = config;\n\t\tconst value = this.settings[key as keyof z.infer<TSchema>] as T[];\n\n\t\tconst inferredItemType = config.itemType ?? this.inferArrayItemType(key) ?? \"string\";\n\t\tconst parser =\n\t\t\tconfig.parser ??\n\t\t\t((input: string) => {\n\t\t\t\tif (inferredItemType === \"number\") {\n\t\t\t\t\tconst num = Number(input);\n\t\t\t\t\tif (Number.isNaN(num)) {\n\t\t\t\t\t\tthrow new Error(`Invalid number: ${input}`);\n\t\t\t\t\t}\n\t\t\t\t\treturn num as T;\n\t\t\t\t}\n\t\t\t\treturn input as T;\n\t\t\t});\n\n\t\tconst validator = config.validator ?? ((_item: T) => true);\n\n\t\tconst setting = new Setting(containerEl).setName(name).setDesc(desc);\n\n\t\tif (multiline) {\n\t\t\tsetting.addTextArea((text) => {\n\t\t\t\ttext.setPlaceholder(placeholder);\n\t\t\t\ttext.setValue(Array.isArray(value) ? value.join(\"\\n\") : \"\");\n\n\t\t\t\tconst commit = async (inputValue: string) => {\n\t\t\t\t\tconst lines = inputValue\n\t\t\t\t\t\t.split(\"\\n\")\n\t\t\t\t\t\t.map((s) => s.trim())\n\t\t\t\t\t\t.filter((s) => s.length > 0);\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst items = lines.map(parser).filter(validator);\n\t\t\t\t\t\tawait this.updateSetting(key as keyof z.infer<TSchema>, items);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tnew Notice(`Invalid input: ${error}`, 5000);\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\ttext.inputEl.addEventListener(\"blur\", () => void commit(text.inputEl.value));\n\t\t\t\ttext.inputEl.addEventListener(\"keydown\", (e: KeyboardEvent) => {\n\t\t\t\t\tif (e.key === \"Enter\" && (e.ctrlKey || e.metaKey)) {\n\t\t\t\t\t\te.preventDefault();\n\t\t\t\t\t\tvoid commit(text.inputEl.value);\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\ttext.inputEl.rows = 5;\n\t\t\t\ttext.inputEl.classList.add(\"settings-ui-builder-textarea\");\n\t\t\t});\n\t\t} else {\n\t\t\tsetting.addText((text) => {\n\t\t\t\ttext.setPlaceholder(placeholder);\n\t\t\t\ttext.setValue(Array.isArray(value) ? value.join(arrayDelimiter) : \"\");\n\t\t\t\ttext.onChange(async (inputValue) => {\n\t\t\t\t\tconst tokens = inputValue\n\t\t\t\t\t\t.split(\",\")\n\t\t\t\t\t\t.map((s) => s.trim())\n\t\t\t\t\t\t.filter((s) => s.length > 0);\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst items = tokens.map(parser).filter(validator);\n\t\t\t\t\t\tawait this.updateSetting(key as keyof z.infer<TSchema>, items);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tnew Notice(`Invalid input: ${error}`, 5000);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Advanced array manager with add/remove buttons for each item\n\t * Similar to the directory settings pattern\n\t */\n\taddArrayManager(containerEl: HTMLElement, config: ArrayManagerConfig): void {\n\t\tconst {\n\t\t\tkey,\n\t\t\tname,\n\t\t\tdesc,\n\t\t\tplaceholder = \"\",\n\t\t\taddButtonText = \"Add\",\n\t\t\tremoveButtonText = \"Remove\",\n\t\t\temptyArrayFallback = [],\n\t\t\tpreventEmpty = false,\n\t\t\titemDescriptionFn,\n\t\t\tonBeforeAdd,\n\t\t\tonBeforeRemove,\n\t\t\tquickActions = [],\n\t\t} = config;\n\n\t\t// Section heading\n\t\tnew Setting(containerEl).setName(name).setHeading();\n\n\t\t// Description\n\t\tif (desc) {\n\t\t\tconst descEl = containerEl.createDiv(\"setting-item-description\");\n\t\t\tdescEl.setText(desc);\n\t\t}\n\n\t\t// Container for list items\n\t\tconst listContainer = containerEl.createDiv(\"settings-array-manager-list\");\n\n\t\tconst render = () => {\n\t\t\tlistContainer.empty();\n\n\t\t\tconst currentItems = (this.settings[key as keyof z.infer<TSchema>] as unknown[]) ?? [];\n\n\t\t\tfor (const item of currentItems) {\n\t\t\t\tconst itemSetting = new Setting(listContainer).setName(String(item)).addButton((button) =>\n\t\t\t\t\tbutton\n\t\t\t\t\t\t.setButtonText(removeButtonText)\n\t\t\t\t\t\t.setWarning()\n\t\t\t\t\t\t.onClick(async () => {\n\t\t\t\t\t\t\tlet newItems = currentItems.filter((i) => i !== item);\n\n\t\t\t\t\t\t\t// Apply custom logic before removal\n\t\t\t\t\t\t\tif (onBeforeRemove) {\n\t\t\t\t\t\t\t\tnewItems = await onBeforeRemove(item, currentItems);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Prevent empty array if configured\n\t\t\t\t\t\t\tif (preventEmpty && newItems.length === 0) {\n\t\t\t\t\t\t\t\tnewItems = Array.isArray(emptyArrayFallback)\n\t\t\t\t\t\t\t\t\t? emptyArrayFallback\n\t\t\t\t\t\t\t\t\t: [emptyArrayFallback];\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tawait this.updateSetting(key as keyof z.infer<TSchema>, newItems);\n\t\t\t\t\t\t\trender();\n\t\t\t\t\t\t})\n\t\t\t\t);\n\n\t\t\t\t// Add custom description for each item if provided\n\t\t\t\tif (itemDescriptionFn) {\n\t\t\t\t\titemSetting.setDesc(itemDescriptionFn(item));\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\trender();\n\n\t\t// Add new item section\n\t\tconst inputId = `settings-array-manager-input-${key}`;\n\t\tnew Setting(containerEl)\n\t\t\t.setName(`Add ${name.toLowerCase()}`)\n\t\t\t.setDesc(`Enter a new value`)\n\t\t\t.addText((text) => {\n\t\t\t\ttext.setPlaceholder(placeholder);\n\t\t\t\ttext.inputEl.id = inputId;\n\t\t\t})\n\t\t\t.addButton((button) =>\n\t\t\t\tbutton\n\t\t\t\t\t.setButtonText(addButtonText)\n\t\t\t\t\t.setCta()\n\t\t\t\t\t.onClick(async () => {\n\t\t\t\t\t\tconst input = containerEl.querySelector(`#${inputId}`) as HTMLInputElement;\n\t\t\t\t\t\tconst newItem = input.value.trim();\n\n\t\t\t\t\t\tif (!newItem) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst currentItems = (this.settings[key as keyof z.infer<TSchema>] as unknown[]) ?? [];\n\t\t\t\t\t\tlet newItems = [...currentItems];\n\n\t\t\t\t\t\t// Apply custom logic before adding\n\t\t\t\t\t\tif (onBeforeAdd) {\n\t\t\t\t\t\t\tnewItems = await onBeforeAdd(newItem, currentItems);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// Default behavior: add if not exists\n\t\t\t\t\t\t\tif (!newItems.includes(newItem)) {\n\t\t\t\t\t\t\t\tnewItems.push(newItem);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tawait this.updateSetting(key as keyof z.infer<TSchema>, newItems);\n\t\t\t\t\t\tinput.value = \"\";\n\t\t\t\t\t\trender();\n\t\t\t\t\t})\n\t\t\t);\n\n\t\t// Quick actions\n\t\tfor (const quickAction of quickActions) {\n\t\t\tconst currentItems = (this.settings[key as keyof z.infer<TSchema>] as unknown[]) ?? [];\n\n\t\t\t// Check condition if provided\n\t\t\tif (quickAction.condition && !quickAction.condition(currentItems)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tnew Setting(containerEl)\n\t\t\t\t.setName(quickAction.name)\n\t\t\t\t.setDesc(quickAction.desc)\n\t\t\t\t.addButton((button) =>\n\t\t\t\t\tbutton.setButtonText(quickAction.buttonText).onClick(async () => {\n\t\t\t\t\t\tconst currentItems = (this.settings[key as keyof z.infer<TSchema>] as unknown[]) ?? [];\n\t\t\t\t\t\tconst newItems = await quickAction.action(currentItems);\n\t\t\t\t\t\tawait this.updateSetting(key as keyof z.infer<TSchema>, newItems);\n\t\t\t\t\t\trender();\n\t\t\t\t\t})\n\t\t\t\t);\n\t\t}\n\t}\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@real1ty-obsidian-plugins/utils",
3
- "version": "2.0.1",
3
+ "version": "2.2.1",
4
4
  "description": "Shared utilities for Obsidian plugins",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",