@witchcraft/spellcraft
    Preparing search index...
    Index

    Constructors

    • Parameters

      • createManager: (
            raw: Partial<Omit<Manager, "hooks" | "options" | "state" | "listener">> & {
                options: PickManager<
                    "options",
                    "enableShortcuts"
                    | "enableListeners"
                    | "updateStateOnAllEvents",
                >;
            },
            isNew: boolean,
        ) => Manager | Error
          • (
                raw: Partial<Omit<Manager, "hooks" | "options" | "state" | "listener">> & {
                    options: PickManager<
                        "options",
                        "enableShortcuts"
                        | "enableListeners"
                        | "updateStateOnAllEvents",
                    >;
                },
                isNew: boolean,
            ): Manager | Error
          • All new managers will be created using this function. It should be capable of taking as little information as {name} (when a new manager is created) and returining a full manger.

            It's suggested you not do validation here, use the onParse hook instead.

            If you return an error, onError will be called, and no manager will be created.

            Parameters

            • raw: Partial<Omit<Manager, "hooks" | "options" | "state" | "listener">> & {
                  options: PickManager<
                      "options",
                      "enableShortcuts"
                      | "enableListeners"
                      | "updateStateOnAllEvents",
                  >;
              }
            • isNew: boolean

            Returns Manager | Error

      • hooks: {
            onError: (err: Error) => void;
            onExport?: (res: object) => void;
            onParse?: (parsed: object) => undefined | Error;
            onSave?: (clone: DeepPartial<Manager>) => void;
            onSetActiveManager?: (name: string) => void;
            onSetManager?: (name: string, clone: Manager) => void;
            onSetManagerNames?: (names: string[]) => void;
        }
        • onError: (err: Error) => void

          Called on any errors loading/saving/etc, should be used to notify the user.

        • OptionalonExport?: (res: object) => void

          Called when a manager is exported. Can be used to actually do the export.

        • OptionalonParse?: (parsed: object) => undefined | Error

          Called when a manager is parsed from storage after being sucessfully JSON.parsed.

          You can validate the parsed object here so it's in the correct shape to pass to createManager.

          If you return an error, onError will be called and createManager will be skipped.

        • OptionalonSave?: (clone: DeepPartial<Manager>) => void

          Called when a manager is saved or exported. It's called with the cloned version of the manager that has been stripped of properties that should not be saved (see managerToStorableClone).

          You can delete/add properties here (it will not modify the original manager).

        • OptionalonSetActiveManager?: (name: string) => void

          Called when the active manager is set. Can be used to update your state.

        • OptionalonSetManager?: (name: string, clone: Manager) => void

          Called when a manager is set. Can be used to update your state.

        • OptionalonSetManagerNames?: (names: string[]) => void

          Called when the manager names are set. Can be used to update your state.

      • __namedParameters: {
            storage?: {
                getItem: (key: string) => null | string;
                removeItem: (key: string) => void;
                setItem: (key: string, value: string) => void;
            };
            storageKeys?: Partial<
                {
                    activeManager: string;
                    managerNames: string;
                    managerPrefix: string;
                    prefix: string;
                },
            >;
        } = {}

      Returns ShortcutManagerManager

    Properties

    activeManagerName: string = "default"
    createManager: (
        raw: Partial<Omit<Manager, "hooks" | "options" | "state" | "listener">> & {
            options: PickManager<
                "options",
                "enableShortcuts"
                | "enableListeners"
                | "updateStateOnAllEvents",
            >;
        },
        isNew: boolean,
    ) => Manager | Error

    All new managers will be created using this function. It should be capable of taking as little information as {name} (when a new manager is created) and returining a full manger.

    It's suggested you not do validation here, use the onParse hook instead.

    If you return an error, onError will be called, and no manager will be created.

    debouncedSave: (name: string) => void

    A debounced version of the save function. Is already bound to the instance.

    hooks: {
        onError: (err: Error) => void;
        onExport?: (res: object) => void;
        onParse?: (parsed: object) => undefined | Error;
        onSave?: (clone: DeepPartial<Manager>) => void;
        onSetActiveManager?: (name: string) => void;
        onSetManager?: (name: string, clone: Manager) => void;
        onSetManagerNames?: (names: string[]) => void;
    }

    Type Declaration

    • onError: (err: Error) => void

      Called on any errors loading/saving/etc, should be used to notify the user.

    • OptionalonExport?: (res: object) => void

      Called when a manager is exported. Can be used to actually do the export.

    • OptionalonParse?: (parsed: object) => undefined | Error

      Called when a manager is parsed from storage after being sucessfully JSON.parsed.

      You can validate the parsed object here so it's in the correct shape to pass to createManager.

      If you return an error, onError will be called and createManager will be skipped.

    • OptionalonSave?: (clone: DeepPartial<Manager>) => void

      Called when a manager is saved or exported. It's called with the cloned version of the manager that has been stripped of properties that should not be saved (see managerToStorableClone).

      You can delete/add properties here (it will not modify the original manager).

    • OptionalonSetActiveManager?: (name: string) => void

      Called when the active manager is set. Can be used to update your state.

    • OptionalonSetManager?: (name: string, clone: Manager) => void

      Called when a manager is set. Can be used to update your state.

    • OptionalonSetManagerNames?: (names: string[]) => void

      Called when the manager names are set. Can be used to update your state.

    managerNames: string[] = []
    managers: Readonly<Record<string, Manager>> = {}
    storage: {
        getItem: (key: string) => null | string;
        removeItem: (key: string) => void;
        setItem: (key: string, value: string) => void;
    }
    storageKeys: {
        activeManager: string;
        managerNames: string;
        managerPrefix: string;
        prefix: string;
    }

    Type Declaration

    • activeManager: string
      "shortcut-manager:active"
      
    • managerNames: string
      "shortcut-manager:names"
      
    • managerPrefix: string
      "shortcut-manager:manager."
      
    • prefix: string

      Prefix for all keys.

    Methods

    • Parameters

      • name: string
      • opts: { force?: boolean } = {}

      Returns Result<void, Error>

    • Clears all managers and resets the state. init must be called again if you want to use the class instance again.

      Returns void