@tanstack/solid-hotkeys 0.8.4 → 0.9.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/createHotkey.cjs +20 -18
- package/dist/createHotkey.cjs.map +1 -1
- package/dist/createHotkey.js +21 -19
- package/dist/createHotkey.js.map +1 -1
- package/dist/createHotkeyRegistrations.cjs +26 -0
- package/dist/createHotkeyRegistrations.cjs.map +1 -0
- package/dist/createHotkeyRegistrations.d.cts +26 -0
- package/dist/createHotkeyRegistrations.d.ts +26 -0
- package/dist/createHotkeyRegistrations.js +26 -0
- package/dist/createHotkeyRegistrations.js.map +1 -0
- package/dist/createHotkeySequence.cjs +20 -18
- package/dist/createHotkeySequence.cjs.map +1 -1
- package/dist/createHotkeySequence.js +21 -19
- package/dist/createHotkeySequence.js.map +1 -1
- package/dist/createHotkeySequences.cjs +26 -24
- package/dist/createHotkeySequences.cjs.map +1 -1
- package/dist/createHotkeySequences.js +27 -25
- package/dist/createHotkeySequences.js.map +1 -1
- package/dist/createHotkeys.cjs +26 -24
- package/dist/createHotkeys.cjs.map +1 -1
- package/dist/createHotkeys.js +27 -25
- package/dist/createHotkeys.js.map +1 -1
- package/dist/createKeyHold.cjs.map +1 -1
- package/dist/createKeyHold.d.cts +2 -2
- package/dist/createKeyHold.d.ts +2 -2
- package/dist/createKeyHold.js.map +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/package.json +2 -2
- package/src/createHotkey.ts +29 -24
- package/src/createHotkeyRegistrations.ts +45 -0
- package/src/createHotkeySequence.ts +29 -24
- package/src/createHotkeySequences.ts +35 -30
- package/src/createHotkeys.ts +37 -32
- package/src/createKeyHold.ts +4 -2
- package/src/index.ts +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createHotkeySequences.js","names":[],"sources":["../src/createHotkeySequences.ts"],"sourcesContent":["import { createEffect, onCleanup } from 'solid-js'\nimport { formatHotkeySequence, getSequenceManager } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type { CreateHotkeySequenceOptions } from './createHotkeySequence'\nimport type {\n HotkeyCallback,\n HotkeySequence,\n SequenceRegistrationHandle,\n} from '@tanstack/hotkeys'\n\n/**\n * A single sequence definition for use with `createHotkeySequences`.\n */\nexport interface CreateHotkeySequenceDefinition {\n /** Array of hotkey strings that form the sequence */\n sequence: HotkeySequence\n /** The function to call when the sequence is completed */\n callback: HotkeyCallback\n /** Per-sequence options (merged on top of commonOptions) */\n options?: CreateHotkeySequenceOptions\n}\n\n/**\n * SolidJS primitive for registering multiple keyboard shortcut sequences at once (Vim-style).\n *\n * Uses the singleton SequenceManager. Accepts a dynamic array of definitions, or accessors,\n * so you can react to variable-length lists.\n *\n * Options are merged in this order:\n * HotkeysProvider defaults < commonOptions < per-definition options\n *\n * Definitions with an empty `sequence` are skipped (no registration).\n *\n * @param sequences - Array of sequence definitions, or accessor returning them\n * @param commonOptions - Shared options for all sequences, or accessor\n *\n * @example\n * ```tsx\n * function VimPalette() {\n * createHotkeySequences([\n * { sequence: ['G', 'G'], callback: () => scrollToTop() },\n * { sequence: ['D', 'D'], callback: () => deleteLine() },\n * ])\n * }\n * ```\n *\n * @example\n * ```tsx\n * function Dynamic(props) {\n * createHotkeySequences(\n * () => props.items.map((item) => ({\n * sequence: item.chords,\n * callback: item.action,\n * options: { enabled: item.enabled },\n * })),\n * { preventDefault: true },\n * )\n * }\n * ```\n */\nexport function createHotkeySequences(\n sequences:\n | Array<CreateHotkeySequenceDefinition>\n | (() => Array<CreateHotkeySequenceDefinition>),\n commonOptions:\n | CreateHotkeySequenceOptions\n | (() => CreateHotkeySequenceOptions) = {},\n): void {\n type RegistrationRecord = {\n handle: SequenceRegistrationHandle\n target: Document | HTMLElement | Window\n }\n\n const defaultOptions = useDefaultHotkeysOptions()\n const manager = getSequenceManager()\n\n const registrations = new Map<string, RegistrationRecord>()\n\n onCleanup(() => {\n for (const { handle } of registrations.values()) {\n if (handle.isActive) {\n handle.unregister()\n }\n }\n registrations.clear()\n })\n\n createEffect(() => {\n const resolved = typeof sequences === 'function' ? sequences() : sequences\n const resolvedCommonOptions =\n typeof commonOptions === 'function' ? commonOptions() : commonOptions\n\n const nextKeys = new Set<string>()\n const prepared: Array<{\n registrationKey: string\n def: CreateHotkeySequenceDefinition\n mergedOptions: CreateHotkeySequenceOptions\n sequenceString: string\n resolvedTarget: Document | HTMLElement | Window\n }> = []\n\n for (let i = 0; i < resolved.length; i++) {\n const def = resolved[i]!\n const resolvedDefOptions = def.options ?? {}\n\n const mergedOptions = {\n ...defaultOptions.hotkeySequence,\n ...resolvedCommonOptions,\n ...resolvedDefOptions,\n } as CreateHotkeySequenceOptions\n\n if (def.sequence.length === 0) {\n continue\n }\n\n const sequenceString = formatHotkeySequence(def.sequence)\n\n const resolvedTarget =\n 'target' in mergedOptions\n ? (mergedOptions.target ?? null)\n : typeof document !== 'undefined'\n ? document\n : null\n\n if (!resolvedTarget) {\n continue\n }\n\n const registrationKey = `${i}:${sequenceString}`\n nextKeys.add(registrationKey)\n prepared.push({\n registrationKey,\n def,\n mergedOptions,\n sequenceString,\n resolvedTarget,\n })\n }\n\n for (const [key, record] of [...registrations.entries()]) {\n
|
|
1
|
+
{"version":3,"file":"createHotkeySequences.js","names":[],"sources":["../src/createHotkeySequences.ts"],"sourcesContent":["import { createEffect, onCleanup, untrack } from 'solid-js'\nimport { formatHotkeySequence, getSequenceManager } from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type { CreateHotkeySequenceOptions } from './createHotkeySequence'\nimport type {\n HotkeyCallback,\n HotkeySequence,\n SequenceRegistrationHandle,\n} from '@tanstack/hotkeys'\n\n/**\n * A single sequence definition for use with `createHotkeySequences`.\n */\nexport interface CreateHotkeySequenceDefinition {\n /** Array of hotkey strings that form the sequence */\n sequence: HotkeySequence\n /** The function to call when the sequence is completed */\n callback: HotkeyCallback\n /** Per-sequence options (merged on top of commonOptions) */\n options?: CreateHotkeySequenceOptions\n}\n\n/**\n * SolidJS primitive for registering multiple keyboard shortcut sequences at once (Vim-style).\n *\n * Uses the singleton SequenceManager. Accepts a dynamic array of definitions, or accessors,\n * so you can react to variable-length lists.\n *\n * Options are merged in this order:\n * HotkeysProvider defaults < commonOptions < per-definition options\n *\n * Definitions with an empty `sequence` are skipped (no registration).\n *\n * @param sequences - Array of sequence definitions, or accessor returning them\n * @param commonOptions - Shared options for all sequences, or accessor\n *\n * @example\n * ```tsx\n * function VimPalette() {\n * createHotkeySequences([\n * { sequence: ['G', 'G'], callback: () => scrollToTop() },\n * { sequence: ['D', 'D'], callback: () => deleteLine() },\n * ])\n * }\n * ```\n *\n * @example\n * ```tsx\n * function Dynamic(props) {\n * createHotkeySequences(\n * () => props.items.map((item) => ({\n * sequence: item.chords,\n * callback: item.action,\n * options: { enabled: item.enabled },\n * })),\n * { preventDefault: true },\n * )\n * }\n * ```\n */\nexport function createHotkeySequences(\n sequences:\n | Array<CreateHotkeySequenceDefinition>\n | (() => Array<CreateHotkeySequenceDefinition>),\n commonOptions:\n | CreateHotkeySequenceOptions\n | (() => CreateHotkeySequenceOptions) = {},\n): void {\n type RegistrationRecord = {\n handle: SequenceRegistrationHandle\n target: Document | HTMLElement | Window\n }\n\n const defaultOptions = useDefaultHotkeysOptions()\n const manager = getSequenceManager()\n\n const registrations = new Map<string, RegistrationRecord>()\n\n onCleanup(() => {\n for (const { handle } of registrations.values()) {\n if (handle.isActive) {\n handle.unregister()\n }\n }\n registrations.clear()\n })\n\n createEffect(() => {\n const resolved = typeof sequences === 'function' ? sequences() : sequences\n const resolvedCommonOptions =\n typeof commonOptions === 'function' ? commonOptions() : commonOptions\n\n const nextKeys = new Set<string>()\n const prepared: Array<{\n registrationKey: string\n def: CreateHotkeySequenceDefinition\n mergedOptions: CreateHotkeySequenceOptions\n sequenceString: string\n resolvedTarget: Document | HTMLElement | Window\n }> = []\n\n for (let i = 0; i < resolved.length; i++) {\n const def = resolved[i]!\n const resolvedDefOptions = def.options ?? {}\n\n const mergedOptions = {\n ...defaultOptions.hotkeySequence,\n ...resolvedCommonOptions,\n ...resolvedDefOptions,\n } as CreateHotkeySequenceOptions\n\n if (def.sequence.length === 0) {\n continue\n }\n\n const sequenceString = formatHotkeySequence(def.sequence)\n\n const resolvedTarget =\n 'target' in mergedOptions\n ? (mergedOptions.target ?? null)\n : typeof document !== 'undefined'\n ? document\n : null\n\n if (!resolvedTarget) {\n continue\n }\n\n const registrationKey = `${i}:${sequenceString}`\n nextKeys.add(registrationKey)\n prepared.push({\n registrationKey,\n def,\n mergedOptions,\n sequenceString,\n resolvedTarget,\n })\n }\n\n // Untrack store mutations so that registering/updating sequences doesn't\n // create a circular reactive dependency when createHotkeyRegistrations\n // subscribes to the same store.\n untrack(() => {\n for (const [key, record] of [...registrations.entries()]) {\n if (!nextKeys.has(key)) {\n if (record.handle.isActive) {\n record.handle.unregister()\n }\n registrations.delete(key)\n }\n }\n\n for (const p of prepared) {\n const existing = registrations.get(p.registrationKey)\n if (existing?.handle.isActive && existing.target === p.resolvedTarget) {\n existing.handle.callback = p.def.callback\n const { target: _target, ...optionsWithoutTarget } = p.mergedOptions\n existing.handle.setOptions(optionsWithoutTarget)\n continue\n }\n\n if (existing) {\n if (existing.handle.isActive) {\n existing.handle.unregister()\n }\n registrations.delete(p.registrationKey)\n }\n\n const { target: _target, ...optionsWithoutTarget } = p.mergedOptions\n const handle = manager.register(p.def.sequence, p.def.callback, {\n ...optionsWithoutTarget,\n target: p.resolvedTarget,\n })\n registrations.set(p.registrationKey, {\n handle,\n target: p.resolvedTarget,\n })\n }\n })\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4DA,SAAgB,sBACd,WAGA,gBAE0C,EAAE,EACtC;CAMN,MAAM,iBAAiB,0BAA0B;CACjD,MAAM,UAAU,oBAAoB;CAEpC,MAAM,gCAAgB,IAAI,KAAiC;AAE3D,iBAAgB;AACd,OAAK,MAAM,EAAE,YAAY,cAAc,QAAQ,CAC7C,KAAI,OAAO,SACT,QAAO,YAAY;AAGvB,gBAAc,OAAO;GACrB;AAEF,oBAAmB;EACjB,MAAM,WAAW,OAAO,cAAc,aAAa,WAAW,GAAG;EACjE,MAAM,wBACJ,OAAO,kBAAkB,aAAa,eAAe,GAAG;EAE1D,MAAM,2BAAW,IAAI,KAAa;EAClC,MAAM,WAMD,EAAE;AAEP,OAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;GACxC,MAAM,MAAM,SAAS;GACrB,MAAM,qBAAqB,IAAI,WAAW,EAAE;GAE5C,MAAM,gBAAgB;IACpB,GAAG,eAAe;IAClB,GAAG;IACH,GAAG;IACJ;AAED,OAAI,IAAI,SAAS,WAAW,EAC1B;GAGF,MAAM,iBAAiB,qBAAqB,IAAI,SAAS;GAEzD,MAAM,iBACJ,YAAY,gBACP,cAAc,UAAU,OACzB,OAAO,aAAa,cAClB,WACA;AAER,OAAI,CAAC,eACH;GAGF,MAAM,kBAAkB,GAAG,EAAE,GAAG;AAChC,YAAS,IAAI,gBAAgB;AAC7B,YAAS,KAAK;IACZ;IACA;IACA;IACA;IACA;IACD,CAAC;;AAMJ,gBAAc;AACZ,QAAK,MAAM,CAAC,KAAK,WAAW,CAAC,GAAG,cAAc,SAAS,CAAC,CACtD,KAAI,CAAC,SAAS,IAAI,IAAI,EAAE;AACtB,QAAI,OAAO,OAAO,SAChB,QAAO,OAAO,YAAY;AAE5B,kBAAc,OAAO,IAAI;;AAI7B,QAAK,MAAM,KAAK,UAAU;IACxB,MAAM,WAAW,cAAc,IAAI,EAAE,gBAAgB;AACrD,QAAI,UAAU,OAAO,YAAY,SAAS,WAAW,EAAE,gBAAgB;AACrE,cAAS,OAAO,WAAW,EAAE,IAAI;KACjC,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB,EAAE;AACvD,cAAS,OAAO,WAAW,qBAAqB;AAChD;;AAGF,QAAI,UAAU;AACZ,SAAI,SAAS,OAAO,SAClB,UAAS,OAAO,YAAY;AAE9B,mBAAc,OAAO,EAAE,gBAAgB;;IAGzC,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB,EAAE;IACvD,MAAM,SAAS,QAAQ,SAAS,EAAE,IAAI,UAAU,EAAE,IAAI,UAAU;KAC9D,GAAG;KACH,QAAQ,EAAE;KACX,CAAC;AACF,kBAAc,IAAI,EAAE,iBAAiB;KACnC;KACA,QAAQ,EAAE;KACX,CAAC;;IAEJ;GACF"}
|
package/dist/createHotkeys.cjs
CHANGED
|
@@ -76,32 +76,34 @@ function createHotkeys(hotkeys, commonOptions = {}) {
|
|
|
76
76
|
resolvedTarget
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
for (const p of prepared) {
|
|
84
|
-
const existing = registrations.get(p.registrationKey);
|
|
85
|
-
if (existing?.handle.isActive && existing.target === p.resolvedTarget) {
|
|
86
|
-
existing.handle.callback = p.def.callback;
|
|
87
|
-
const { target: _target, ...optionsWithoutTarget } = p.mergedOptions;
|
|
88
|
-
existing.handle.setOptions(optionsWithoutTarget);
|
|
89
|
-
continue;
|
|
79
|
+
(0, solid_js.untrack)(() => {
|
|
80
|
+
for (const [key, record] of [...registrations.entries()]) if (!nextKeys.has(key)) {
|
|
81
|
+
if (record.handle.isActive) record.handle.unregister();
|
|
82
|
+
registrations.delete(key);
|
|
90
83
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
84
|
+
for (const p of prepared) {
|
|
85
|
+
const existing = registrations.get(p.registrationKey);
|
|
86
|
+
if (existing?.handle.isActive && existing.target === p.resolvedTarget) {
|
|
87
|
+
existing.handle.callback = p.def.callback;
|
|
88
|
+
const { target: _target, ...optionsWithoutTarget } = p.mergedOptions;
|
|
89
|
+
existing.handle.setOptions(optionsWithoutTarget);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (existing) {
|
|
93
|
+
if (existing.handle.isActive) existing.handle.unregister();
|
|
94
|
+
registrations.delete(p.registrationKey);
|
|
95
|
+
}
|
|
96
|
+
const { target: _target, ...optionsWithoutTarget } = p.mergedOptions;
|
|
97
|
+
const handle = manager.register(p.hotkeyString, p.def.callback, {
|
|
98
|
+
...optionsWithoutTarget,
|
|
99
|
+
target: p.resolvedTarget
|
|
100
|
+
});
|
|
101
|
+
registrations.set(p.registrationKey, {
|
|
102
|
+
handle,
|
|
103
|
+
target: p.resolvedTarget
|
|
104
|
+
});
|
|
94
105
|
}
|
|
95
|
-
|
|
96
|
-
const handle = manager.register(p.hotkeyString, p.def.callback, {
|
|
97
|
-
...optionsWithoutTarget,
|
|
98
|
-
target: p.resolvedTarget
|
|
99
|
-
});
|
|
100
|
-
registrations.set(p.registrationKey, {
|
|
101
|
-
handle,
|
|
102
|
-
target: p.resolvedTarget
|
|
103
|
-
});
|
|
104
|
-
}
|
|
106
|
+
});
|
|
105
107
|
});
|
|
106
108
|
}
|
|
107
109
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createHotkeys.cjs","names":["useDefaultHotkeysOptions"],"sources":["../src/createHotkeys.ts"],"sourcesContent":["import { createEffect, onCleanup } from 'solid-js'\nimport {\n detectPlatform,\n getHotkeyManager,\n normalizeRegisterableHotkey,\n} from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type { CreateHotkeyOptions } from './createHotkey'\nimport type {\n Hotkey,\n HotkeyCallback,\n HotkeyRegistrationHandle,\n RegisterableHotkey,\n} from '@tanstack/hotkeys'\n\n/**\n * A single hotkey definition for use with `createHotkeys`.\n */\nexport interface CreateHotkeyDefinition {\n /** The hotkey string (e.g., 'Mod+S', 'Escape') or RawHotkey object */\n hotkey: RegisterableHotkey\n /** The function to call when the hotkey is pressed */\n callback: HotkeyCallback\n /** Per-hotkey options (merged on top of commonOptions) */\n options?: CreateHotkeyOptions\n}\n\n/**\n * SolidJS primitive for registering multiple keyboard hotkeys at once.\n *\n * Uses the singleton HotkeyManager for efficient event handling.\n * Accepts a dynamic array of hotkey definitions, making it safe to use\n * with variable-length lists.\n *\n * Options are merged in this order:\n * HotkeysProvider defaults < commonOptions < per-definition options\n *\n * @param hotkeys - Array of hotkey definitions, or accessor returning them\n * @param commonOptions - Shared options applied to all hotkeys, or accessor\n *\n * @example\n * ```tsx\n * function Editor() {\n * createHotkeys([\n * { hotkey: 'Mod+S', callback: () => save() },\n * { hotkey: 'Mod+Z', callback: () => undo() },\n * { hotkey: 'Escape', callback: () => close() },\n * ])\n * }\n * ```\n *\n * @example\n * ```tsx\n * function MenuShortcuts(props) {\n * createHotkeys(\n * () => props.items.map((item) => ({\n * hotkey: item.shortcut,\n * callback: item.action,\n * options: { enabled: item.enabled },\n * })),\n * { preventDefault: true },\n * )\n * }\n * ```\n */\nexport function createHotkeys(\n hotkeys:\n | Array<CreateHotkeyDefinition>\n | (() => Array<CreateHotkeyDefinition>),\n commonOptions: CreateHotkeyOptions | (() => CreateHotkeyOptions) = {},\n): void {\n type RegistrationRecord = {\n handle: HotkeyRegistrationHandle\n target: Document | HTMLElement | Window\n }\n\n const defaultOptions = useDefaultHotkeysOptions()\n const manager = getHotkeyManager()\n\n const registrations = new Map<string, RegistrationRecord>()\n\n // Clean up only when this component/scope disposes — not before every effect\n // re-run. An inner `onCleanup` inside `createEffect` runs whenever reactive\n // deps change (e.g. dynamic hotkey list), which unregistered every hotkey and\n // re-registered them, flooding the manager store and could freeze the tab.\n onCleanup(() => {\n for (const { handle } of registrations.values()) {\n if (handle.isActive) {\n handle.unregister()\n }\n }\n registrations.clear()\n })\n\n createEffect(() => {\n const resolvedHotkeys = typeof hotkeys === 'function' ? hotkeys() : hotkeys\n const resolvedCommonOptions =\n typeof commonOptions === 'function' ? commonOptions() : commonOptions\n\n const nextKeys = new Set<string>()\n const prepared: Array<{\n registrationKey: string\n def: CreateHotkeyDefinition\n mergedOptions: CreateHotkeyOptions\n hotkeyString: Hotkey\n resolvedTarget: Document | HTMLElement | Window\n }> = []\n\n for (let i = 0; i < resolvedHotkeys.length; i++) {\n const def = resolvedHotkeys[i]!\n const resolvedDefOptions = def.options ?? {}\n\n const mergedOptions = {\n ...defaultOptions.hotkey,\n ...resolvedCommonOptions,\n ...resolvedDefOptions,\n } as CreateHotkeyOptions\n\n const platform = mergedOptions.platform ?? detectPlatform()\n const hotkeyString = normalizeRegisterableHotkey(def.hotkey, platform)\n\n const resolvedTarget =\n 'target' in mergedOptions\n ? (mergedOptions.target ?? null)\n : typeof document !== 'undefined'\n ? document\n : null\n\n if (!resolvedTarget) {\n continue\n }\n\n const registrationKey = `${i}:${hotkeyString}`\n nextKeys.add(registrationKey)\n prepared.push({\n registrationKey,\n def,\n mergedOptions,\n hotkeyString,\n resolvedTarget,\n })\n }\n\n // Drop stale keys first so list index shifts don't briefly double-register\n
|
|
1
|
+
{"version":3,"file":"createHotkeys.cjs","names":["useDefaultHotkeysOptions"],"sources":["../src/createHotkeys.ts"],"sourcesContent":["import { createEffect, onCleanup, untrack } from 'solid-js'\nimport {\n detectPlatform,\n getHotkeyManager,\n normalizeRegisterableHotkey,\n} from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type { CreateHotkeyOptions } from './createHotkey'\nimport type {\n Hotkey,\n HotkeyCallback,\n HotkeyRegistrationHandle,\n RegisterableHotkey,\n} from '@tanstack/hotkeys'\n\n/**\n * A single hotkey definition for use with `createHotkeys`.\n */\nexport interface CreateHotkeyDefinition {\n /** The hotkey string (e.g., 'Mod+S', 'Escape') or RawHotkey object */\n hotkey: RegisterableHotkey\n /** The function to call when the hotkey is pressed */\n callback: HotkeyCallback\n /** Per-hotkey options (merged on top of commonOptions) */\n options?: CreateHotkeyOptions\n}\n\n/**\n * SolidJS primitive for registering multiple keyboard hotkeys at once.\n *\n * Uses the singleton HotkeyManager for efficient event handling.\n * Accepts a dynamic array of hotkey definitions, making it safe to use\n * with variable-length lists.\n *\n * Options are merged in this order:\n * HotkeysProvider defaults < commonOptions < per-definition options\n *\n * @param hotkeys - Array of hotkey definitions, or accessor returning them\n * @param commonOptions - Shared options applied to all hotkeys, or accessor\n *\n * @example\n * ```tsx\n * function Editor() {\n * createHotkeys([\n * { hotkey: 'Mod+S', callback: () => save() },\n * { hotkey: 'Mod+Z', callback: () => undo() },\n * { hotkey: 'Escape', callback: () => close() },\n * ])\n * }\n * ```\n *\n * @example\n * ```tsx\n * function MenuShortcuts(props) {\n * createHotkeys(\n * () => props.items.map((item) => ({\n * hotkey: item.shortcut,\n * callback: item.action,\n * options: { enabled: item.enabled },\n * })),\n * { preventDefault: true },\n * )\n * }\n * ```\n */\nexport function createHotkeys(\n hotkeys:\n | Array<CreateHotkeyDefinition>\n | (() => Array<CreateHotkeyDefinition>),\n commonOptions: CreateHotkeyOptions | (() => CreateHotkeyOptions) = {},\n): void {\n type RegistrationRecord = {\n handle: HotkeyRegistrationHandle\n target: Document | HTMLElement | Window\n }\n\n const defaultOptions = useDefaultHotkeysOptions()\n const manager = getHotkeyManager()\n\n const registrations = new Map<string, RegistrationRecord>()\n\n // Clean up only when this component/scope disposes — not before every effect\n // re-run. An inner `onCleanup` inside `createEffect` runs whenever reactive\n // deps change (e.g. dynamic hotkey list), which unregistered every hotkey and\n // re-registered them, flooding the manager store and could freeze the tab.\n onCleanup(() => {\n for (const { handle } of registrations.values()) {\n if (handle.isActive) {\n handle.unregister()\n }\n }\n registrations.clear()\n })\n\n createEffect(() => {\n const resolvedHotkeys = typeof hotkeys === 'function' ? hotkeys() : hotkeys\n const resolvedCommonOptions =\n typeof commonOptions === 'function' ? commonOptions() : commonOptions\n\n const nextKeys = new Set<string>()\n const prepared: Array<{\n registrationKey: string\n def: CreateHotkeyDefinition\n mergedOptions: CreateHotkeyOptions\n hotkeyString: Hotkey\n resolvedTarget: Document | HTMLElement | Window\n }> = []\n\n for (let i = 0; i < resolvedHotkeys.length; i++) {\n const def = resolvedHotkeys[i]!\n const resolvedDefOptions = def.options ?? {}\n\n const mergedOptions = {\n ...defaultOptions.hotkey,\n ...resolvedCommonOptions,\n ...resolvedDefOptions,\n } as CreateHotkeyOptions\n\n const platform = mergedOptions.platform ?? detectPlatform()\n const hotkeyString = normalizeRegisterableHotkey(def.hotkey, platform)\n\n const resolvedTarget =\n 'target' in mergedOptions\n ? (mergedOptions.target ?? null)\n : typeof document !== 'undefined'\n ? document\n : null\n\n if (!resolvedTarget) {\n continue\n }\n\n const registrationKey = `${i}:${hotkeyString}`\n nextKeys.add(registrationKey)\n prepared.push({\n registrationKey,\n def,\n mergedOptions,\n hotkeyString,\n resolvedTarget,\n })\n }\n\n // Untrack store mutations so that registering/updating hotkeys doesn't\n // create a circular reactive dependency when createHotkeyRegistrations\n // subscribes to the same store.\n untrack(() => {\n // Drop stale keys first so list index shifts don't briefly double-register\n // the same hotkey+target (conflictBehavior: 'warn' + devtools can loop).\n for (const [key, record] of [...registrations.entries()]) {\n if (!nextKeys.has(key)) {\n if (record.handle.isActive) {\n record.handle.unregister()\n }\n registrations.delete(key)\n }\n }\n\n for (const p of prepared) {\n const existing = registrations.get(p.registrationKey)\n if (existing?.handle.isActive && existing.target === p.resolvedTarget) {\n existing.handle.callback = p.def.callback\n const { target: _target, ...optionsWithoutTarget } = p.mergedOptions\n existing.handle.setOptions(optionsWithoutTarget)\n continue\n }\n\n if (existing) {\n if (existing.handle.isActive) {\n existing.handle.unregister()\n }\n registrations.delete(p.registrationKey)\n }\n\n const { target: _target, ...optionsWithoutTarget } = p.mergedOptions\n const handle = manager.register(p.hotkeyString, p.def.callback, {\n ...optionsWithoutTarget,\n target: p.resolvedTarget,\n })\n registrations.set(p.registrationKey, {\n handle,\n target: p.resolvedTarget,\n })\n }\n })\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,SAAgB,cACd,SAGA,gBAAmE,EAAE,EAC/D;CAMN,MAAM,iBAAiBA,kDAA0B;CACjD,MAAM,mDAA4B;CAElC,MAAM,gCAAgB,IAAI,KAAiC;AAM3D,+BAAgB;AACd,OAAK,MAAM,EAAE,YAAY,cAAc,QAAQ,CAC7C,KAAI,OAAO,SACT,QAAO,YAAY;AAGvB,gBAAc,OAAO;GACrB;AAEF,kCAAmB;EACjB,MAAM,kBAAkB,OAAO,YAAY,aAAa,SAAS,GAAG;EACpE,MAAM,wBACJ,OAAO,kBAAkB,aAAa,eAAe,GAAG;EAE1D,MAAM,2BAAW,IAAI,KAAa;EAClC,MAAM,WAMD,EAAE;AAEP,OAAK,IAAI,IAAI,GAAG,IAAI,gBAAgB,QAAQ,KAAK;GAC/C,MAAM,MAAM,gBAAgB;GAC5B,MAAM,qBAAqB,IAAI,WAAW,EAAE;GAE5C,MAAM,gBAAgB;IACpB,GAAG,eAAe;IAClB,GAAG;IACH,GAAG;IACJ;GAED,MAAM,WAAW,cAAc,mDAA4B;GAC3D,MAAM,kEAA2C,IAAI,QAAQ,SAAS;GAEtE,MAAM,iBACJ,YAAY,gBACP,cAAc,UAAU,OACzB,OAAO,aAAa,cAClB,WACA;AAER,OAAI,CAAC,eACH;GAGF,MAAM,kBAAkB,GAAG,EAAE,GAAG;AAChC,YAAS,IAAI,gBAAgB;AAC7B,YAAS,KAAK;IACZ;IACA;IACA;IACA;IACA;IACD,CAAC;;AAMJ,8BAAc;AAGZ,QAAK,MAAM,CAAC,KAAK,WAAW,CAAC,GAAG,cAAc,SAAS,CAAC,CACtD,KAAI,CAAC,SAAS,IAAI,IAAI,EAAE;AACtB,QAAI,OAAO,OAAO,SAChB,QAAO,OAAO,YAAY;AAE5B,kBAAc,OAAO,IAAI;;AAI7B,QAAK,MAAM,KAAK,UAAU;IACxB,MAAM,WAAW,cAAc,IAAI,EAAE,gBAAgB;AACrD,QAAI,UAAU,OAAO,YAAY,SAAS,WAAW,EAAE,gBAAgB;AACrE,cAAS,OAAO,WAAW,EAAE,IAAI;KACjC,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB,EAAE;AACvD,cAAS,OAAO,WAAW,qBAAqB;AAChD;;AAGF,QAAI,UAAU;AACZ,SAAI,SAAS,OAAO,SAClB,UAAS,OAAO,YAAY;AAE9B,mBAAc,OAAO,EAAE,gBAAgB;;IAGzC,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB,EAAE;IACvD,MAAM,SAAS,QAAQ,SAAS,EAAE,cAAc,EAAE,IAAI,UAAU;KAC9D,GAAG;KACH,QAAQ,EAAE;KACX,CAAC;AACF,kBAAc,IAAI,EAAE,iBAAiB;KACnC;KACA,QAAQ,EAAE;KACX,CAAC;;IAEJ;GACF"}
|
package/dist/createHotkeys.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useDefaultHotkeysOptions } from "./HotkeysProvider.js";
|
|
2
2
|
import { detectPlatform, getHotkeyManager, normalizeRegisterableHotkey } from "@tanstack/hotkeys";
|
|
3
|
-
import { createEffect, onCleanup } from "solid-js";
|
|
3
|
+
import { createEffect, onCleanup, untrack } from "solid-js";
|
|
4
4
|
|
|
5
5
|
//#region src/createHotkeys.ts
|
|
6
6
|
/**
|
|
@@ -76,32 +76,34 @@ function createHotkeys(hotkeys, commonOptions = {}) {
|
|
|
76
76
|
resolvedTarget
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
for (const p of prepared) {
|
|
84
|
-
const existing = registrations.get(p.registrationKey);
|
|
85
|
-
if (existing?.handle.isActive && existing.target === p.resolvedTarget) {
|
|
86
|
-
existing.handle.callback = p.def.callback;
|
|
87
|
-
const { target: _target, ...optionsWithoutTarget } = p.mergedOptions;
|
|
88
|
-
existing.handle.setOptions(optionsWithoutTarget);
|
|
89
|
-
continue;
|
|
79
|
+
untrack(() => {
|
|
80
|
+
for (const [key, record] of [...registrations.entries()]) if (!nextKeys.has(key)) {
|
|
81
|
+
if (record.handle.isActive) record.handle.unregister();
|
|
82
|
+
registrations.delete(key);
|
|
90
83
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
84
|
+
for (const p of prepared) {
|
|
85
|
+
const existing = registrations.get(p.registrationKey);
|
|
86
|
+
if (existing?.handle.isActive && existing.target === p.resolvedTarget) {
|
|
87
|
+
existing.handle.callback = p.def.callback;
|
|
88
|
+
const { target: _target, ...optionsWithoutTarget } = p.mergedOptions;
|
|
89
|
+
existing.handle.setOptions(optionsWithoutTarget);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (existing) {
|
|
93
|
+
if (existing.handle.isActive) existing.handle.unregister();
|
|
94
|
+
registrations.delete(p.registrationKey);
|
|
95
|
+
}
|
|
96
|
+
const { target: _target, ...optionsWithoutTarget } = p.mergedOptions;
|
|
97
|
+
const handle = manager.register(p.hotkeyString, p.def.callback, {
|
|
98
|
+
...optionsWithoutTarget,
|
|
99
|
+
target: p.resolvedTarget
|
|
100
|
+
});
|
|
101
|
+
registrations.set(p.registrationKey, {
|
|
102
|
+
handle,
|
|
103
|
+
target: p.resolvedTarget
|
|
104
|
+
});
|
|
94
105
|
}
|
|
95
|
-
|
|
96
|
-
const handle = manager.register(p.hotkeyString, p.def.callback, {
|
|
97
|
-
...optionsWithoutTarget,
|
|
98
|
-
target: p.resolvedTarget
|
|
99
|
-
});
|
|
100
|
-
registrations.set(p.registrationKey, {
|
|
101
|
-
handle,
|
|
102
|
-
target: p.resolvedTarget
|
|
103
|
-
});
|
|
104
|
-
}
|
|
106
|
+
});
|
|
105
107
|
});
|
|
106
108
|
}
|
|
107
109
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createHotkeys.js","names":[],"sources":["../src/createHotkeys.ts"],"sourcesContent":["import { createEffect, onCleanup } from 'solid-js'\nimport {\n detectPlatform,\n getHotkeyManager,\n normalizeRegisterableHotkey,\n} from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type { CreateHotkeyOptions } from './createHotkey'\nimport type {\n Hotkey,\n HotkeyCallback,\n HotkeyRegistrationHandle,\n RegisterableHotkey,\n} from '@tanstack/hotkeys'\n\n/**\n * A single hotkey definition for use with `createHotkeys`.\n */\nexport interface CreateHotkeyDefinition {\n /** The hotkey string (e.g., 'Mod+S', 'Escape') or RawHotkey object */\n hotkey: RegisterableHotkey\n /** The function to call when the hotkey is pressed */\n callback: HotkeyCallback\n /** Per-hotkey options (merged on top of commonOptions) */\n options?: CreateHotkeyOptions\n}\n\n/**\n * SolidJS primitive for registering multiple keyboard hotkeys at once.\n *\n * Uses the singleton HotkeyManager for efficient event handling.\n * Accepts a dynamic array of hotkey definitions, making it safe to use\n * with variable-length lists.\n *\n * Options are merged in this order:\n * HotkeysProvider defaults < commonOptions < per-definition options\n *\n * @param hotkeys - Array of hotkey definitions, or accessor returning them\n * @param commonOptions - Shared options applied to all hotkeys, or accessor\n *\n * @example\n * ```tsx\n * function Editor() {\n * createHotkeys([\n * { hotkey: 'Mod+S', callback: () => save() },\n * { hotkey: 'Mod+Z', callback: () => undo() },\n * { hotkey: 'Escape', callback: () => close() },\n * ])\n * }\n * ```\n *\n * @example\n * ```tsx\n * function MenuShortcuts(props) {\n * createHotkeys(\n * () => props.items.map((item) => ({\n * hotkey: item.shortcut,\n * callback: item.action,\n * options: { enabled: item.enabled },\n * })),\n * { preventDefault: true },\n * )\n * }\n * ```\n */\nexport function createHotkeys(\n hotkeys:\n | Array<CreateHotkeyDefinition>\n | (() => Array<CreateHotkeyDefinition>),\n commonOptions: CreateHotkeyOptions | (() => CreateHotkeyOptions) = {},\n): void {\n type RegistrationRecord = {\n handle: HotkeyRegistrationHandle\n target: Document | HTMLElement | Window\n }\n\n const defaultOptions = useDefaultHotkeysOptions()\n const manager = getHotkeyManager()\n\n const registrations = new Map<string, RegistrationRecord>()\n\n // Clean up only when this component/scope disposes — not before every effect\n // re-run. An inner `onCleanup` inside `createEffect` runs whenever reactive\n // deps change (e.g. dynamic hotkey list), which unregistered every hotkey and\n // re-registered them, flooding the manager store and could freeze the tab.\n onCleanup(() => {\n for (const { handle } of registrations.values()) {\n if (handle.isActive) {\n handle.unregister()\n }\n }\n registrations.clear()\n })\n\n createEffect(() => {\n const resolvedHotkeys = typeof hotkeys === 'function' ? hotkeys() : hotkeys\n const resolvedCommonOptions =\n typeof commonOptions === 'function' ? commonOptions() : commonOptions\n\n const nextKeys = new Set<string>()\n const prepared: Array<{\n registrationKey: string\n def: CreateHotkeyDefinition\n mergedOptions: CreateHotkeyOptions\n hotkeyString: Hotkey\n resolvedTarget: Document | HTMLElement | Window\n }> = []\n\n for (let i = 0; i < resolvedHotkeys.length; i++) {\n const def = resolvedHotkeys[i]!\n const resolvedDefOptions = def.options ?? {}\n\n const mergedOptions = {\n ...defaultOptions.hotkey,\n ...resolvedCommonOptions,\n ...resolvedDefOptions,\n } as CreateHotkeyOptions\n\n const platform = mergedOptions.platform ?? detectPlatform()\n const hotkeyString = normalizeRegisterableHotkey(def.hotkey, platform)\n\n const resolvedTarget =\n 'target' in mergedOptions\n ? (mergedOptions.target ?? null)\n : typeof document !== 'undefined'\n ? document\n : null\n\n if (!resolvedTarget) {\n continue\n }\n\n const registrationKey = `${i}:${hotkeyString}`\n nextKeys.add(registrationKey)\n prepared.push({\n registrationKey,\n def,\n mergedOptions,\n hotkeyString,\n resolvedTarget,\n })\n }\n\n // Drop stale keys first so list index shifts don't briefly double-register\n
|
|
1
|
+
{"version":3,"file":"createHotkeys.js","names":[],"sources":["../src/createHotkeys.ts"],"sourcesContent":["import { createEffect, onCleanup, untrack } from 'solid-js'\nimport {\n detectPlatform,\n getHotkeyManager,\n normalizeRegisterableHotkey,\n} from '@tanstack/hotkeys'\nimport { useDefaultHotkeysOptions } from './HotkeysProvider'\nimport type { CreateHotkeyOptions } from './createHotkey'\nimport type {\n Hotkey,\n HotkeyCallback,\n HotkeyRegistrationHandle,\n RegisterableHotkey,\n} from '@tanstack/hotkeys'\n\n/**\n * A single hotkey definition for use with `createHotkeys`.\n */\nexport interface CreateHotkeyDefinition {\n /** The hotkey string (e.g., 'Mod+S', 'Escape') or RawHotkey object */\n hotkey: RegisterableHotkey\n /** The function to call when the hotkey is pressed */\n callback: HotkeyCallback\n /** Per-hotkey options (merged on top of commonOptions) */\n options?: CreateHotkeyOptions\n}\n\n/**\n * SolidJS primitive for registering multiple keyboard hotkeys at once.\n *\n * Uses the singleton HotkeyManager for efficient event handling.\n * Accepts a dynamic array of hotkey definitions, making it safe to use\n * with variable-length lists.\n *\n * Options are merged in this order:\n * HotkeysProvider defaults < commonOptions < per-definition options\n *\n * @param hotkeys - Array of hotkey definitions, or accessor returning them\n * @param commonOptions - Shared options applied to all hotkeys, or accessor\n *\n * @example\n * ```tsx\n * function Editor() {\n * createHotkeys([\n * { hotkey: 'Mod+S', callback: () => save() },\n * { hotkey: 'Mod+Z', callback: () => undo() },\n * { hotkey: 'Escape', callback: () => close() },\n * ])\n * }\n * ```\n *\n * @example\n * ```tsx\n * function MenuShortcuts(props) {\n * createHotkeys(\n * () => props.items.map((item) => ({\n * hotkey: item.shortcut,\n * callback: item.action,\n * options: { enabled: item.enabled },\n * })),\n * { preventDefault: true },\n * )\n * }\n * ```\n */\nexport function createHotkeys(\n hotkeys:\n | Array<CreateHotkeyDefinition>\n | (() => Array<CreateHotkeyDefinition>),\n commonOptions: CreateHotkeyOptions | (() => CreateHotkeyOptions) = {},\n): void {\n type RegistrationRecord = {\n handle: HotkeyRegistrationHandle\n target: Document | HTMLElement | Window\n }\n\n const defaultOptions = useDefaultHotkeysOptions()\n const manager = getHotkeyManager()\n\n const registrations = new Map<string, RegistrationRecord>()\n\n // Clean up only when this component/scope disposes — not before every effect\n // re-run. An inner `onCleanup` inside `createEffect` runs whenever reactive\n // deps change (e.g. dynamic hotkey list), which unregistered every hotkey and\n // re-registered them, flooding the manager store and could freeze the tab.\n onCleanup(() => {\n for (const { handle } of registrations.values()) {\n if (handle.isActive) {\n handle.unregister()\n }\n }\n registrations.clear()\n })\n\n createEffect(() => {\n const resolvedHotkeys = typeof hotkeys === 'function' ? hotkeys() : hotkeys\n const resolvedCommonOptions =\n typeof commonOptions === 'function' ? commonOptions() : commonOptions\n\n const nextKeys = new Set<string>()\n const prepared: Array<{\n registrationKey: string\n def: CreateHotkeyDefinition\n mergedOptions: CreateHotkeyOptions\n hotkeyString: Hotkey\n resolvedTarget: Document | HTMLElement | Window\n }> = []\n\n for (let i = 0; i < resolvedHotkeys.length; i++) {\n const def = resolvedHotkeys[i]!\n const resolvedDefOptions = def.options ?? {}\n\n const mergedOptions = {\n ...defaultOptions.hotkey,\n ...resolvedCommonOptions,\n ...resolvedDefOptions,\n } as CreateHotkeyOptions\n\n const platform = mergedOptions.platform ?? detectPlatform()\n const hotkeyString = normalizeRegisterableHotkey(def.hotkey, platform)\n\n const resolvedTarget =\n 'target' in mergedOptions\n ? (mergedOptions.target ?? null)\n : typeof document !== 'undefined'\n ? document\n : null\n\n if (!resolvedTarget) {\n continue\n }\n\n const registrationKey = `${i}:${hotkeyString}`\n nextKeys.add(registrationKey)\n prepared.push({\n registrationKey,\n def,\n mergedOptions,\n hotkeyString,\n resolvedTarget,\n })\n }\n\n // Untrack store mutations so that registering/updating hotkeys doesn't\n // create a circular reactive dependency when createHotkeyRegistrations\n // subscribes to the same store.\n untrack(() => {\n // Drop stale keys first so list index shifts don't briefly double-register\n // the same hotkey+target (conflictBehavior: 'warn' + devtools can loop).\n for (const [key, record] of [...registrations.entries()]) {\n if (!nextKeys.has(key)) {\n if (record.handle.isActive) {\n record.handle.unregister()\n }\n registrations.delete(key)\n }\n }\n\n for (const p of prepared) {\n const existing = registrations.get(p.registrationKey)\n if (existing?.handle.isActive && existing.target === p.resolvedTarget) {\n existing.handle.callback = p.def.callback\n const { target: _target, ...optionsWithoutTarget } = p.mergedOptions\n existing.handle.setOptions(optionsWithoutTarget)\n continue\n }\n\n if (existing) {\n if (existing.handle.isActive) {\n existing.handle.unregister()\n }\n registrations.delete(p.registrationKey)\n }\n\n const { target: _target, ...optionsWithoutTarget } = p.mergedOptions\n const handle = manager.register(p.hotkeyString, p.def.callback, {\n ...optionsWithoutTarget,\n target: p.resolvedTarget,\n })\n registrations.set(p.registrationKey, {\n handle,\n target: p.resolvedTarget,\n })\n }\n })\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,SAAgB,cACd,SAGA,gBAAmE,EAAE,EAC/D;CAMN,MAAM,iBAAiB,0BAA0B;CACjD,MAAM,UAAU,kBAAkB;CAElC,MAAM,gCAAgB,IAAI,KAAiC;AAM3D,iBAAgB;AACd,OAAK,MAAM,EAAE,YAAY,cAAc,QAAQ,CAC7C,KAAI,OAAO,SACT,QAAO,YAAY;AAGvB,gBAAc,OAAO;GACrB;AAEF,oBAAmB;EACjB,MAAM,kBAAkB,OAAO,YAAY,aAAa,SAAS,GAAG;EACpE,MAAM,wBACJ,OAAO,kBAAkB,aAAa,eAAe,GAAG;EAE1D,MAAM,2BAAW,IAAI,KAAa;EAClC,MAAM,WAMD,EAAE;AAEP,OAAK,IAAI,IAAI,GAAG,IAAI,gBAAgB,QAAQ,KAAK;GAC/C,MAAM,MAAM,gBAAgB;GAC5B,MAAM,qBAAqB,IAAI,WAAW,EAAE;GAE5C,MAAM,gBAAgB;IACpB,GAAG,eAAe;IAClB,GAAG;IACH,GAAG;IACJ;GAED,MAAM,WAAW,cAAc,YAAY,gBAAgB;GAC3D,MAAM,eAAe,4BAA4B,IAAI,QAAQ,SAAS;GAEtE,MAAM,iBACJ,YAAY,gBACP,cAAc,UAAU,OACzB,OAAO,aAAa,cAClB,WACA;AAER,OAAI,CAAC,eACH;GAGF,MAAM,kBAAkB,GAAG,EAAE,GAAG;AAChC,YAAS,IAAI,gBAAgB;AAC7B,YAAS,KAAK;IACZ;IACA;IACA;IACA;IACA;IACD,CAAC;;AAMJ,gBAAc;AAGZ,QAAK,MAAM,CAAC,KAAK,WAAW,CAAC,GAAG,cAAc,SAAS,CAAC,CACtD,KAAI,CAAC,SAAS,IAAI,IAAI,EAAE;AACtB,QAAI,OAAO,OAAO,SAChB,QAAO,OAAO,YAAY;AAE5B,kBAAc,OAAO,IAAI;;AAI7B,QAAK,MAAM,KAAK,UAAU;IACxB,MAAM,WAAW,cAAc,IAAI,EAAE,gBAAgB;AACrD,QAAI,UAAU,OAAO,YAAY,SAAS,WAAW,EAAE,gBAAgB;AACrE,cAAS,OAAO,WAAW,EAAE,IAAI;KACjC,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB,EAAE;AACvD,cAAS,OAAO,WAAW,qBAAqB;AAChD;;AAGF,QAAI,UAAU;AACZ,SAAI,SAAS,OAAO,SAClB,UAAS,OAAO,YAAY;AAE9B,mBAAc,OAAO,EAAE,gBAAgB;;IAGzC,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB,EAAE;IACvD,MAAM,SAAS,QAAQ,SAAS,EAAE,cAAc,EAAE,IAAI,UAAU;KAC9D,GAAG;KACH,QAAQ,EAAE;KACX,CAAC;AACF,kBAAc,IAAI,EAAE,iBAAiB;KACnC;KACA,QAAQ,EAAE;KACX,CAAC;;IAEJ;GACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createKeyHold.cjs","names":[],"sources":["../src/createKeyHold.ts"],"sourcesContent":["import { createMemo } from 'solid-js'\nimport { useStore } from '@tanstack/solid-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\nimport type {
|
|
1
|
+
{"version":3,"file":"createKeyHold.cjs","names":[],"sources":["../src/createKeyHold.ts"],"sourcesContent":["import { createMemo } from 'solid-js'\nimport { useStore } from '@tanstack/solid-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\nimport type { IndividualKey } from '@tanstack/hotkeys'\n\n/**\n * SolidJS primitive that returns whether a specific key is currently being held.\n *\n * This primitive uses `useStore` from `@tanstack/solid-store` to subscribe\n * to the global KeyStateTracker and uses a selector to determine if the\n * specified key is held.\n *\n * @param key - The key to check (e.g., 'Shift', 'Control', 'A') - can be an accessor function\n * @returns Signal accessor that returns true if the key is currently held down\n *\n * @example\n * ```tsx\n * function ShiftIndicator() {\n * const isShiftHeld = createKeyHold('Shift')\n *\n * return (\n * <div style={{ opacity: isShiftHeld() ? 1 : 0.5 }}>\n * {isShiftHeld() ? 'Shift is pressed!' : 'Press Shift'}\n * </div>\n * )\n * }\n * ```\n *\n * @example\n * ```tsx\n * function ModifierIndicators() {\n * const ctrl = createKeyHold('Control')\n * const shift = createKeyHold('Shift')\n * const alt = createKeyHold('Alt')\n *\n * return (\n * <div>\n * <span style={{ opacity: ctrl() ? 1 : 0.3 }}>Ctrl</span>\n * <span style={{ opacity: shift() ? 1 : 0.3 }}>Shift</span>\n * <span style={{ opacity: alt() ? 1 : 0.3 }}>Alt</span>\n * </div>\n * )\n * }\n * ```\n */\nexport function createKeyHold(\n key: IndividualKey | (() => IndividualKey),\n): () => boolean {\n const tracker = getKeyStateTracker()\n const heldKeysSelector = useStore(tracker.store, (state) => state.heldKeys)\n\n return createMemo(() => {\n const resolvedKey = typeof key === 'function' ? key() : key\n const normalizedKey = resolvedKey.toLowerCase()\n return heldKeysSelector().some(\n (heldKey) => heldKey.toLowerCase() === normalizedKey,\n )\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,cACd,KACe;CAEf,MAAM,kGAD8B,CACM,QAAQ,UAAU,MAAM,SAAS;AAE3E,uCAAwB;EAEtB,MAAM,iBADc,OAAO,QAAQ,aAAa,KAAK,GAAG,KACtB,aAAa;AAC/C,SAAO,kBAAkB,CAAC,MACvB,YAAY,QAAQ,aAAa,KAAK,cACxC;GACD"}
|
package/dist/createKeyHold.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IndividualKey } from "@tanstack/hotkeys";
|
|
2
2
|
|
|
3
3
|
//#region src/createKeyHold.d.ts
|
|
4
4
|
/**
|
|
@@ -41,7 +41,7 @@ import { HeldKey } from "@tanstack/hotkeys";
|
|
|
41
41
|
* }
|
|
42
42
|
* ```
|
|
43
43
|
*/
|
|
44
|
-
declare function createKeyHold(key:
|
|
44
|
+
declare function createKeyHold(key: IndividualKey | (() => IndividualKey)): () => boolean;
|
|
45
45
|
//#endregion
|
|
46
46
|
export { createKeyHold };
|
|
47
47
|
//# sourceMappingURL=createKeyHold.d.cts.map
|
package/dist/createKeyHold.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IndividualKey } from "@tanstack/hotkeys";
|
|
2
2
|
|
|
3
3
|
//#region src/createKeyHold.d.ts
|
|
4
4
|
/**
|
|
@@ -41,7 +41,7 @@ import { HeldKey } from "@tanstack/hotkeys";
|
|
|
41
41
|
* }
|
|
42
42
|
* ```
|
|
43
43
|
*/
|
|
44
|
-
declare function createKeyHold(key:
|
|
44
|
+
declare function createKeyHold(key: IndividualKey | (() => IndividualKey)): () => boolean;
|
|
45
45
|
//#endregion
|
|
46
46
|
export { createKeyHold };
|
|
47
47
|
//# sourceMappingURL=createKeyHold.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createKeyHold.js","names":[],"sources":["../src/createKeyHold.ts"],"sourcesContent":["import { createMemo } from 'solid-js'\nimport { useStore } from '@tanstack/solid-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\nimport type {
|
|
1
|
+
{"version":3,"file":"createKeyHold.js","names":[],"sources":["../src/createKeyHold.ts"],"sourcesContent":["import { createMemo } from 'solid-js'\nimport { useStore } from '@tanstack/solid-store'\nimport { getKeyStateTracker } from '@tanstack/hotkeys'\nimport type { IndividualKey } from '@tanstack/hotkeys'\n\n/**\n * SolidJS primitive that returns whether a specific key is currently being held.\n *\n * This primitive uses `useStore` from `@tanstack/solid-store` to subscribe\n * to the global KeyStateTracker and uses a selector to determine if the\n * specified key is held.\n *\n * @param key - The key to check (e.g., 'Shift', 'Control', 'A') - can be an accessor function\n * @returns Signal accessor that returns true if the key is currently held down\n *\n * @example\n * ```tsx\n * function ShiftIndicator() {\n * const isShiftHeld = createKeyHold('Shift')\n *\n * return (\n * <div style={{ opacity: isShiftHeld() ? 1 : 0.5 }}>\n * {isShiftHeld() ? 'Shift is pressed!' : 'Press Shift'}\n * </div>\n * )\n * }\n * ```\n *\n * @example\n * ```tsx\n * function ModifierIndicators() {\n * const ctrl = createKeyHold('Control')\n * const shift = createKeyHold('Shift')\n * const alt = createKeyHold('Alt')\n *\n * return (\n * <div>\n * <span style={{ opacity: ctrl() ? 1 : 0.3 }}>Ctrl</span>\n * <span style={{ opacity: shift() ? 1 : 0.3 }}>Shift</span>\n * <span style={{ opacity: alt() ? 1 : 0.3 }}>Alt</span>\n * </div>\n * )\n * }\n * ```\n */\nexport function createKeyHold(\n key: IndividualKey | (() => IndividualKey),\n): () => boolean {\n const tracker = getKeyStateTracker()\n const heldKeysSelector = useStore(tracker.store, (state) => state.heldKeys)\n\n return createMemo(() => {\n const resolvedKey = typeof key === 'function' ? key() : key\n const normalizedKey = resolvedKey.toLowerCase()\n return heldKeysSelector().some(\n (heldKey) => heldKey.toLowerCase() === normalizedKey,\n )\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,cACd,KACe;CAEf,MAAM,mBAAmB,SADT,oBAAoB,CACM,QAAQ,UAAU,MAAM,SAAS;AAE3E,QAAO,iBAAiB;EAEtB,MAAM,iBADc,OAAO,QAAQ,aAAa,KAAK,GAAG,KACtB,aAAa;AAC/C,SAAO,kBAAkB,CAAC,MACvB,YAAY,QAAQ,aAAa,KAAK,cACxC;GACD"}
|
package/dist/index.cjs
CHANGED
|
@@ -8,6 +8,7 @@ const require_createKeyHold = require('./createKeyHold.cjs');
|
|
|
8
8
|
const require_createHotkeySequence = require('./createHotkeySequence.cjs');
|
|
9
9
|
const require_createHotkeySequences = require('./createHotkeySequences.cjs');
|
|
10
10
|
const require_createHotkeyRecorder = require('./createHotkeyRecorder.cjs');
|
|
11
|
+
const require_createHotkeyRegistrations = require('./createHotkeyRegistrations.cjs');
|
|
11
12
|
const require_createHotkeySequenceRecorder = require('./createHotkeySequenceRecorder.cjs');
|
|
12
13
|
|
|
13
14
|
exports.HotkeysProvider = require_HotkeysProvider.HotkeysProvider;
|
|
@@ -15,6 +16,7 @@ exports.createHeldKeyCodes = require_createHeldKeyCodes.createHeldKeyCodes;
|
|
|
15
16
|
exports.createHeldKeys = require_createHeldKeys.createHeldKeys;
|
|
16
17
|
exports.createHotkey = require_createHotkey.createHotkey;
|
|
17
18
|
exports.createHotkeyRecorder = require_createHotkeyRecorder.createHotkeyRecorder;
|
|
19
|
+
exports.createHotkeyRegistrations = require_createHotkeyRegistrations.createHotkeyRegistrations;
|
|
18
20
|
exports.createHotkeySequence = require_createHotkeySequence.createHotkeySequence;
|
|
19
21
|
exports.createHotkeySequenceRecorder = require_createHotkeySequenceRecorder.createHotkeySequenceRecorder;
|
|
20
22
|
exports.createHotkeySequences = require_createHotkeySequences.createHotkeySequences;
|
package/dist/index.d.cts
CHANGED
|
@@ -7,6 +7,7 @@ import { createHeldKeyCodes } from "./createHeldKeyCodes.cjs";
|
|
|
7
7
|
import { createKeyHold } from "./createKeyHold.cjs";
|
|
8
8
|
import { CreateHotkeySequenceDefinition, createHotkeySequences } from "./createHotkeySequences.cjs";
|
|
9
9
|
import { SolidHotkeyRecorder, createHotkeyRecorder } from "./createHotkeyRecorder.cjs";
|
|
10
|
+
import { HotkeyRegistrationsResult, createHotkeyRegistrations } from "./createHotkeyRegistrations.cjs";
|
|
10
11
|
import { SolidHotkeySequenceRecorder, createHotkeySequenceRecorder } from "./createHotkeySequenceRecorder.cjs";
|
|
11
12
|
export * from "@tanstack/hotkeys";
|
|
12
|
-
export { CreateHotkeyDefinition, CreateHotkeyOptions, CreateHotkeySequenceDefinition, CreateHotkeySequenceOptions, HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, SolidHotkeyRecorder, SolidHotkeySequenceRecorder, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyRecorder, createHotkeySequence, createHotkeySequenceRecorder, createHotkeySequences, createHotkeys, createKeyHold, useDefaultHotkeysOptions, useHotkeysContext };
|
|
13
|
+
export { CreateHotkeyDefinition, CreateHotkeyOptions, CreateHotkeySequenceDefinition, CreateHotkeySequenceOptions, HotkeyRegistrationsResult, HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, SolidHotkeyRecorder, SolidHotkeySequenceRecorder, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyRecorder, createHotkeyRegistrations, createHotkeySequence, createHotkeySequenceRecorder, createHotkeySequences, createHotkeys, createKeyHold, useDefaultHotkeysOptions, useHotkeysContext };
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { createHeldKeyCodes } from "./createHeldKeyCodes.js";
|
|
|
7
7
|
import { createKeyHold } from "./createKeyHold.js";
|
|
8
8
|
import { CreateHotkeySequenceDefinition, createHotkeySequences } from "./createHotkeySequences.js";
|
|
9
9
|
import { SolidHotkeyRecorder, createHotkeyRecorder } from "./createHotkeyRecorder.js";
|
|
10
|
+
import { HotkeyRegistrationsResult, createHotkeyRegistrations } from "./createHotkeyRegistrations.js";
|
|
10
11
|
import { SolidHotkeySequenceRecorder, createHotkeySequenceRecorder } from "./createHotkeySequenceRecorder.js";
|
|
11
12
|
export * from "@tanstack/hotkeys";
|
|
12
|
-
export { CreateHotkeyDefinition, CreateHotkeyOptions, CreateHotkeySequenceDefinition, CreateHotkeySequenceOptions, HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, SolidHotkeyRecorder, SolidHotkeySequenceRecorder, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyRecorder, createHotkeySequence, createHotkeySequenceRecorder, createHotkeySequences, createHotkeys, createKeyHold, useDefaultHotkeysOptions, useHotkeysContext };
|
|
13
|
+
export { CreateHotkeyDefinition, CreateHotkeyOptions, CreateHotkeySequenceDefinition, CreateHotkeySequenceOptions, HotkeyRegistrationsResult, HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, SolidHotkeyRecorder, SolidHotkeySequenceRecorder, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyRecorder, createHotkeyRegistrations, createHotkeySequence, createHotkeySequenceRecorder, createHotkeySequences, createHotkeys, createKeyHold, useDefaultHotkeysOptions, useHotkeysContext };
|
package/dist/index.js
CHANGED
|
@@ -7,8 +7,9 @@ import { createKeyHold } from "./createKeyHold.js";
|
|
|
7
7
|
import { createHotkeySequence } from "./createHotkeySequence.js";
|
|
8
8
|
import { createHotkeySequences } from "./createHotkeySequences.js";
|
|
9
9
|
import { createHotkeyRecorder } from "./createHotkeyRecorder.js";
|
|
10
|
+
import { createHotkeyRegistrations } from "./createHotkeyRegistrations.js";
|
|
10
11
|
import { createHotkeySequenceRecorder } from "./createHotkeySequenceRecorder.js";
|
|
11
12
|
|
|
12
13
|
export * from "@tanstack/hotkeys"
|
|
13
14
|
|
|
14
|
-
export { HotkeysProvider, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyRecorder, createHotkeySequence, createHotkeySequenceRecorder, createHotkeySequences, createHotkeys, createKeyHold, useDefaultHotkeysOptions, useHotkeysContext };
|
|
15
|
+
export { HotkeysProvider, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyRecorder, createHotkeyRegistrations, createHotkeySequence, createHotkeySequenceRecorder, createHotkeySequences, createHotkeys, createKeyHold, useDefaultHotkeysOptions, useHotkeysContext };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/solid-hotkeys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "SolidJS adapter for TanStack Hotkeys",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@tanstack/solid-store": "^0.9.3",
|
|
46
|
-
"@tanstack/hotkeys": "0.
|
|
46
|
+
"@tanstack/hotkeys": "0.7.1"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@solidjs/testing-library": "^0.8.10",
|
package/src/createHotkey.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createEffect, onCleanup } from 'solid-js'
|
|
1
|
+
import { createEffect, onCleanup, untrack } from 'solid-js'
|
|
2
2
|
import {
|
|
3
3
|
detectPlatform,
|
|
4
4
|
getHotkeyManager,
|
|
@@ -136,32 +136,37 @@ export function createHotkey(
|
|
|
136
136
|
// Extract options without target (target is handled separately)
|
|
137
137
|
const { target: _target, ...optionsWithoutTarget } = mergedOptions
|
|
138
138
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
139
|
+
// Untrack store mutations so that registering/updating the hotkey doesn't
|
|
140
|
+
// create a circular reactive dependency when createHotkeyRegistrations
|
|
141
|
+
// subscribes to the same store.
|
|
142
|
+
untrack(() => {
|
|
143
|
+
if (
|
|
144
|
+
registration?.isActive &&
|
|
145
|
+
lastHotkeyString === hotkeyString &&
|
|
146
|
+
lastTarget === resolvedTarget
|
|
147
|
+
) {
|
|
148
|
+
registration.callback = callback
|
|
149
|
+
registration.setOptions(optionsWithoutTarget)
|
|
150
|
+
return
|
|
151
|
+
}
|
|
148
152
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
+
if (registration?.isActive) {
|
|
154
|
+
registration.unregister()
|
|
155
|
+
registration = null
|
|
156
|
+
}
|
|
153
157
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
+
registration = manager.register(hotkeyString, callback, {
|
|
159
|
+
...optionsWithoutTarget,
|
|
160
|
+
target: resolvedTarget,
|
|
161
|
+
})
|
|
158
162
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
+
if (registration.isActive) {
|
|
164
|
+
registration.callback = callback
|
|
165
|
+
registration.setOptions(optionsWithoutTarget)
|
|
166
|
+
}
|
|
163
167
|
|
|
164
|
-
|
|
165
|
-
|
|
168
|
+
lastHotkeyString = hotkeyString
|
|
169
|
+
lastTarget = resolvedTarget
|
|
170
|
+
})
|
|
166
171
|
})
|
|
167
172
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useStore } from '@tanstack/solid-store'
|
|
2
|
+
import {
|
|
3
|
+
getHotkeyManager,
|
|
4
|
+
getSequenceManager,
|
|
5
|
+
toHotkeyRegistrationView,
|
|
6
|
+
} from '@tanstack/hotkeys'
|
|
7
|
+
import type {
|
|
8
|
+
HotkeyRegistrationView,
|
|
9
|
+
SequenceRegistrationView,
|
|
10
|
+
} from '@tanstack/hotkeys'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Return type for createHotkeyRegistrations.
|
|
14
|
+
*/
|
|
15
|
+
export interface HotkeyRegistrationsResult {
|
|
16
|
+
/** Accessor for all registered hotkeys (public view, no callbacks) */
|
|
17
|
+
hotkeys: () => Array<HotkeyRegistrationView>
|
|
18
|
+
/** Accessor for all registered sequences */
|
|
19
|
+
sequences: () => Array<SequenceRegistrationView>
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Solid primitive that reactively reads all hotkey and sequence registrations
|
|
24
|
+
* from the singleton managers.
|
|
25
|
+
*
|
|
26
|
+
* This is a standalone primitive that does NOT require the HotkeysProvider.
|
|
27
|
+
* It subscribes to both HotkeyManager and SequenceManager stores and
|
|
28
|
+
* triggers reactivity when registrations change.
|
|
29
|
+
*
|
|
30
|
+
* @returns Object with `hotkeys` and `sequences` signal accessors
|
|
31
|
+
*/
|
|
32
|
+
export function createHotkeyRegistrations(): HotkeyRegistrationsResult {
|
|
33
|
+
const hotkeyManager = getHotkeyManager()
|
|
34
|
+
const sequenceManager = getSequenceManager()
|
|
35
|
+
|
|
36
|
+
const hotkeys = useStore(hotkeyManager.registrations, (state) =>
|
|
37
|
+
Array.from(state.values()).map(toHotkeyRegistrationView),
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
const sequences = useStore(sequenceManager.registrations, (state) =>
|
|
41
|
+
Array.from(state.values()),
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
return { hotkeys, sequences }
|
|
45
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createEffect, onCleanup } from 'solid-js'
|
|
1
|
+
import { createEffect, onCleanup, untrack } from 'solid-js'
|
|
2
2
|
import { formatHotkeySequence, getSequenceManager } from '@tanstack/hotkeys'
|
|
3
3
|
import { useDefaultHotkeysOptions } from './HotkeysProvider'
|
|
4
4
|
import type {
|
|
@@ -119,32 +119,37 @@ export function createHotkeySequence(
|
|
|
119
119
|
|
|
120
120
|
const sequenceKey = formatHotkeySequence(resolvedSequence)
|
|
121
121
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
122
|
+
// Untrack store mutations so that registering/updating the sequence doesn't
|
|
123
|
+
// create a circular reactive dependency when createHotkeyRegistrations
|
|
124
|
+
// subscribes to the same store.
|
|
125
|
+
untrack(() => {
|
|
126
|
+
if (
|
|
127
|
+
registration?.isActive &&
|
|
128
|
+
lastSequenceKey === sequenceKey &&
|
|
129
|
+
lastTarget === resolvedTarget
|
|
130
|
+
) {
|
|
131
|
+
registration.callback = callback
|
|
132
|
+
registration.setOptions(optionsWithoutTarget)
|
|
133
|
+
return
|
|
134
|
+
}
|
|
131
135
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
+
if (registration?.isActive) {
|
|
137
|
+
registration.unregister()
|
|
138
|
+
registration = null
|
|
139
|
+
}
|
|
136
140
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
+
registration = manager.register(resolvedSequence, callback, {
|
|
142
|
+
...mergedOptions,
|
|
143
|
+
target: resolvedTarget,
|
|
144
|
+
})
|
|
141
145
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
+
if (registration.isActive) {
|
|
147
|
+
registration.callback = callback
|
|
148
|
+
registration.setOptions(optionsWithoutTarget)
|
|
149
|
+
}
|
|
146
150
|
|
|
147
|
-
|
|
148
|
-
|
|
151
|
+
lastSequenceKey = sequenceKey
|
|
152
|
+
lastTarget = resolvedTarget
|
|
153
|
+
})
|
|
149
154
|
})
|
|
150
155
|
}
|