@baleada/logic 0.24.6 → 0.24.7

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/lib/index.cjs CHANGED
@@ -1800,6 +1800,7 @@ function createLayers$1(options = {}) {
1800
1800
  yield layers[depth - 1];
1801
1801
  (layers[depth] || (layers[depth] = [])).push(node);
1802
1802
  }
1803
+ yield layers.at(-1);
1803
1804
  };
1804
1805
  }
1805
1806
  function createTree$2(options = {}) {
@@ -2220,22 +2221,23 @@ const createKeycomboMatch$1 = (keycombo, options = {}) => {
2220
2221
  }
2221
2222
  return implicitModifierAliases2;
2222
2223
  })();
2223
- return (event) => {
2224
+ return (descriptor) => {
2224
2225
  const statuses = [];
2225
- createSet(fromEventToKeyStatusCode(event), "down")(statuses);
2226
+ if (descriptor.code)
2227
+ createSet(fromEventToKeyStatusCode(descriptor), "down")(statuses);
2226
2228
  for (const modifier of modifiers) {
2227
2229
  const prefix = modifier === "Control" ? "ctrl" : modifier.toLowerCase();
2228
- if (event[`${prefix}Key`])
2230
+ if (descriptor[`${prefix}Key`])
2229
2231
  createSet(modifier, "down")(statuses);
2230
2232
  }
2231
- const events = createMap(
2233
+ const descriptors = createMap(
2232
2234
  ([code]) => {
2233
- const e = { code };
2235
+ const newDescriptor = { code };
2234
2236
  for (const modifier of modifiers) {
2235
2237
  const prefix = modifier === "Control" ? "ctrl" : modifier.toLowerCase();
2236
- e[`${prefix}Key`] = event[`${prefix}Key`];
2238
+ newDescriptor[`${prefix}Key`] = descriptor[`${prefix}Key`];
2237
2239
  }
2238
- return e;
2240
+ return newDescriptor;
2239
2241
  }
2240
2242
  )(statuses);
2241
2243
  return lazyCollections.every(
@@ -2244,7 +2246,7 @@ const createKeycomboMatch$1 = (keycombo, options = {}) => {
2244
2246
  { predicateKey: createCode(code) }
2245
2247
  )(statuses) === "down"
2246
2248
  )(codes) && lazyCollections.every(
2247
- (e) => lazyCollections.pipe(
2249
+ (d) => lazyCollections.pipe(
2248
2250
  fromDescriptorToAliases,
2249
2251
  lazyCollections.map(fromComboToAliases),
2250
2252
  lazyCollections.some(
@@ -2252,8 +2254,8 @@ const createKeycomboMatch$1 = (keycombo, options = {}) => {
2252
2254
  (longhandAlias) => lazyCollections.includes(longhandAlias)(aliases) || lazyCollections.includes(longhandAlias)(implicitModifierAliases)
2253
2255
  )(longhandAliases)
2254
2256
  )
2255
- )(e)
2256
- )(events);
2257
+ )(d)
2258
+ )(descriptors);
2257
2259
  };
2258
2260
  };
2259
2261
 
@@ -2485,13 +2487,13 @@ const createKeycomboDown = (keycombo, options = {}) => {
2485
2487
  )(codes);
2486
2488
  };
2487
2489
 
2488
- function fromKeyboardEventDescriptorToAliases(event) {
2489
- if (event.shiftKey && event.code in aliasesByShiftCode)
2490
- return [aliasesByShiftCode[event.code]];
2491
- const withoutModifierSide = toWithoutModifierSide(event.code);
2490
+ function fromKeyboardEventDescriptorToAliases(descriptor) {
2491
+ if (descriptor.shiftKey && descriptor.code in aliasesByShiftCode)
2492
+ return [aliasesByShiftCode[descriptor.code]];
2493
+ const withoutModifierSide = toWithoutModifierSide(descriptor.code);
2492
2494
  if (withoutModifierSide in aliasListsByModifier)
2493
2495
  return aliasListsByModifier[withoutModifierSide];
2494
- return event.code in aliasesByCode ? [aliasesByCode[event.code]] : [event.code.match(aliasCaptureRE)?.[1].toLowerCase() || "unsupported"];
2496
+ return descriptor.code in aliasesByCode ? [aliasesByCode[descriptor.code]] : [descriptor.code.match(aliasCaptureRE)?.[1].toLowerCase() || "unsupported"];
2495
2497
  }
2496
2498
  const toWithoutModifierSide = createClip(/(?:Left|Right)$/);
2497
2499
  const aliasCaptureRE = /^(?:Digit|Key)?(F[0-9]{1,2}|[0-9]|[A-Z])$/;
package/lib/index.d.ts CHANGED
@@ -134,7 +134,7 @@ type CreateKeycomboMatchOptions$1 = CreateKeycomboDownOptions & {
134
134
  };
135
135
 
136
136
  type KeyboardEventDescriptor = {
137
- code: string;
137
+ code?: string;
138
138
  shiftKey?: boolean;
139
139
  altKey?: boolean;
140
140
  ctrlKey?: boolean;
@@ -638,14 +638,14 @@ type GraphTreeTransform<Id extends string, Transformed> = (tree: GraphTree<Id>)
638
638
  */
639
639
  declare function createFind<Id extends string>(node: GraphNode<Id>): GraphTreeTransform<Id, GraphTreeNode<Id>>;
640
640
 
641
- type KeyboardEventTransform<Transformed> = (keyboardEvent: KeyboardEvent) => Transformed;
641
+ type KeyboardEventDescriptorTransform<Transformed> = (descriptor: KeyboardEventDescriptor) => Transformed;
642
642
  type CreateKeycomboMatchOptions = Omit<CreateKeycomboMatchOptions$1, 'toAliases'> & {
643
643
  toAliases?: (descriptor: KeyboardEventDescriptor) => string[];
644
644
  };
645
645
  /**
646
646
  * [Docs](https://baleada.dev/docs/logic/pipes/keycombo-match)
647
647
  */
648
- declare const createKeycomboMatch: (keycombo: string, options?: CreateKeycomboMatchOptions) => KeyboardEventTransform<boolean>;
648
+ declare const createKeycomboMatch: (keycombo: string, options?: CreateKeycomboMatchOptions) => KeyboardEventDescriptorTransform<boolean>;
649
649
 
650
650
  type NumberTransform<Transformed> = (number: number) => Transformed;
651
651
  /**
package/lib/index.js CHANGED
@@ -1798,6 +1798,7 @@ function createLayers$1(options = {}) {
1798
1798
  yield layers[depth - 1];
1799
1799
  (layers[depth] || (layers[depth] = [])).push(node);
1800
1800
  }
1801
+ yield layers.at(-1);
1801
1802
  };
1802
1803
  }
1803
1804
  function createTree$2(options = {}) {
@@ -2218,22 +2219,23 @@ const createKeycomboMatch$1 = (keycombo, options = {}) => {
2218
2219
  }
2219
2220
  return implicitModifierAliases2;
2220
2221
  })();
2221
- return (event) => {
2222
+ return (descriptor) => {
2222
2223
  const statuses = [];
2223
- createSet(fromEventToKeyStatusCode(event), "down")(statuses);
2224
+ if (descriptor.code)
2225
+ createSet(fromEventToKeyStatusCode(descriptor), "down")(statuses);
2224
2226
  for (const modifier of modifiers) {
2225
2227
  const prefix = modifier === "Control" ? "ctrl" : modifier.toLowerCase();
2226
- if (event[`${prefix}Key`])
2228
+ if (descriptor[`${prefix}Key`])
2227
2229
  createSet(modifier, "down")(statuses);
2228
2230
  }
2229
- const events = createMap(
2231
+ const descriptors = createMap(
2230
2232
  ([code]) => {
2231
- const e = { code };
2233
+ const newDescriptor = { code };
2232
2234
  for (const modifier of modifiers) {
2233
2235
  const prefix = modifier === "Control" ? "ctrl" : modifier.toLowerCase();
2234
- e[`${prefix}Key`] = event[`${prefix}Key`];
2236
+ newDescriptor[`${prefix}Key`] = descriptor[`${prefix}Key`];
2235
2237
  }
2236
- return e;
2238
+ return newDescriptor;
2237
2239
  }
2238
2240
  )(statuses);
2239
2241
  return every(
@@ -2242,7 +2244,7 @@ const createKeycomboMatch$1 = (keycombo, options = {}) => {
2242
2244
  { predicateKey: createCode(code) }
2243
2245
  )(statuses) === "down"
2244
2246
  )(codes) && every(
2245
- (e) => pipe(
2247
+ (d) => pipe(
2246
2248
  fromDescriptorToAliases,
2247
2249
  map(fromComboToAliases),
2248
2250
  some(
@@ -2250,8 +2252,8 @@ const createKeycomboMatch$1 = (keycombo, options = {}) => {
2250
2252
  (longhandAlias) => includes(longhandAlias)(aliases) || includes(longhandAlias)(implicitModifierAliases)
2251
2253
  )(longhandAliases)
2252
2254
  )
2253
- )(e)
2254
- )(events);
2255
+ )(d)
2256
+ )(descriptors);
2255
2257
  };
2256
2258
  };
2257
2259
 
@@ -2483,13 +2485,13 @@ const createKeycomboDown = (keycombo, options = {}) => {
2483
2485
  )(codes);
2484
2486
  };
2485
2487
 
2486
- function fromKeyboardEventDescriptorToAliases(event) {
2487
- if (event.shiftKey && event.code in aliasesByShiftCode)
2488
- return [aliasesByShiftCode[event.code]];
2489
- const withoutModifierSide = toWithoutModifierSide(event.code);
2488
+ function fromKeyboardEventDescriptorToAliases(descriptor) {
2489
+ if (descriptor.shiftKey && descriptor.code in aliasesByShiftCode)
2490
+ return [aliasesByShiftCode[descriptor.code]];
2491
+ const withoutModifierSide = toWithoutModifierSide(descriptor.code);
2490
2492
  if (withoutModifierSide in aliasListsByModifier)
2491
2493
  return aliasListsByModifier[withoutModifierSide];
2492
- return event.code in aliasesByCode ? [aliasesByCode[event.code]] : [event.code.match(aliasCaptureRE)?.[1].toLowerCase() || "unsupported"];
2494
+ return descriptor.code in aliasesByCode ? [aliasesByCode[descriptor.code]] : [descriptor.code.match(aliasCaptureRE)?.[1].toLowerCase() || "unsupported"];
2493
2495
  }
2494
2496
  const toWithoutModifierSide = createClip(/(?:Left|Right)$/);
2495
2497
  const aliasCaptureRE = /^(?:Digit|Key)?(F[0-9]{1,2}|[0-9]|[A-Z])$/;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baleada/logic",
3
- "version": "0.24.6",
3
+ "version": "0.24.7",
4
4
  "description": "UI logic for the Baleada toolkit",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "lib/index.js",