3 namespace BookStack\Settings;
7 protected const DEFAULTS = [
10 "shelves_view" => "2",
12 "settings_view" => "4",
13 "favourites_view" => "5",
14 "profile_view" => "6",
15 "global_search" => "/",
31 "next" => "ArrowRight",
32 "previous" => "ArrowLeft",
36 * @var array<string, string>
38 protected array $mapping;
40 public function __construct(array $map)
42 $this->mapping = static::DEFAULTS;
47 * Merge the given map into the current shortcut mapping.
49 protected function merge(array $map): void
51 foreach ($map as $key => $value) {
52 if (is_string($value) && isset($this->mapping[$key])) {
53 $this->mapping[$key] = $value;
59 * Get the shortcut defined for the given ID.
61 public function getShortcut(string $id): string
63 return $this->mapping[$id] ?? '';
67 * Convert this mapping to JSON.
69 public function toJson(): string
71 return json_encode($this->mapping);
75 * Create a new instance from the current user's preferences.
77 public static function fromUserPreferences(): self
79 $userKeyMap = setting()->getForCurrentUser('ui-shortcuts');
80 return new self(json_decode($userKeyMap, true) ?: []);