@genesislcap/foundation-events 14.67.2 → 14.67.3

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.
Files changed (51) hide show
  1. package/README.md +5 -1
  2. package/dist/dts/eventEmitter/eventEmitterDI.d.ts +43 -4
  3. package/dist/dts/eventEmitter/eventEmitterDI.d.ts.map +1 -1
  4. package/dist/dts/eventEmitter/eventEmitterMixin.d.ts +57 -317
  5. package/dist/dts/eventEmitter/eventEmitterMixin.d.ts.map +1 -1
  6. package/dist/dts/index.d.ts +1 -0
  7. package/dist/dts/index.d.ts.map +1 -1
  8. package/dist/dts/tsdoc-metadata.json +11 -0
  9. package/dist/dts/types.d.ts +78 -10
  10. package/dist/dts/types.d.ts.map +1 -1
  11. package/dist/dts/utils/index.d.ts +2 -0
  12. package/dist/dts/utils/index.d.ts.map +1 -0
  13. package/dist/dts/utils/logger.d.ts +5 -0
  14. package/dist/dts/utils/logger.d.ts.map +1 -0
  15. package/dist/esm/eventEmitter/eventEmitterDI.js +14 -0
  16. package/dist/esm/eventEmitter/eventEmitterMixin.js +57 -4
  17. package/dist/esm/index.js +1 -0
  18. package/dist/esm/types.js +48 -0
  19. package/dist/esm/utils/index.js +1 -0
  20. package/dist/esm/utils/logger.js +5 -0
  21. package/dist/foundation-events.api.json +1374 -0
  22. package/dist/foundation-events.d.ts +246 -0
  23. package/docs/.gitattributes +2 -0
  24. package/docs/api/foundation-events.constructabletypedeventemitter.md +16 -0
  25. package/docs/api/foundation-events.createinputemitter.md +27 -0
  26. package/docs/api/foundation-events.createselectemitter.md +27 -0
  27. package/docs/api/foundation-events.customevent.md +12 -0
  28. package/docs/api/foundation-events.customeventmap.md +16 -0
  29. package/docs/api/foundation-events.defaulteventemitterdi.emit.md +22 -0
  30. package/docs/api/foundation-events.defaulteventemitterdi.md +21 -0
  31. package/docs/api/foundation-events.emitargs.md +14 -0
  32. package/docs/api/foundation-events.emitoptions.md +12 -0
  33. package/docs/api/foundation-events.emitorigin.md +12 -0
  34. package/docs/api/foundation-events.emitreturn.md +12 -0
  35. package/docs/api/foundation-events.eventdetailmap.md +12 -0
  36. package/docs/api/foundation-events.eventemitter.md +59 -0
  37. package/docs/api/foundation-events.eventemitterdi.emit.md +22 -0
  38. package/docs/api/foundation-events.eventemitterdi.md +48 -0
  39. package/docs/api/foundation-events.eventemittertarget.md +16 -0
  40. package/docs/api/foundation-events.getbaseemitargs.md +12 -0
  41. package/docs/api/foundation-events.keysmatching.md +14 -0
  42. package/docs/api/foundation-events.logger.md +12 -0
  43. package/docs/api/foundation-events.md +47 -0
  44. package/docs/api/foundation-events.registeremitter.md +13 -0
  45. package/docs/api/foundation-events.targetfirstselectedvalue.md +12 -0
  46. package/docs/api/foundation-events.targetvalue.md +12 -0
  47. package/docs/api/foundation-events.typedemitter._emit.md +22 -0
  48. package/docs/api/foundation-events.typedemitter.md +19 -0
  49. package/docs/api/index.md +12 -0
  50. package/docs/api-report.md +106 -0
  51. package/package.json +24 -4
@@ -1,5 +1,10 @@
1
1
  import { DI } from '@microsoft/fast-foundation';
2
2
  import { getBaseEmitArgs } from '../types';
3
+ /**
4
+ * Default EventEmitterDI.
5
+ * @typeParam TEventDetailMap - The {@link EventDetailMap}.
6
+ * @public
7
+ */
3
8
  export class DefaultEventEmitterDI {
4
9
  emit(...args) {
5
10
  const [origin, ...rest] = args;
@@ -7,7 +12,16 @@ export class DefaultEventEmitterDI {
7
12
  return origin.$emit(type, detail, options);
8
13
  }
9
14
  }
15
+ /**
16
+ * EventEmitterDI DI key.
17
+ * @internal
18
+ */
10
19
  export const EventEmitterDI = DI.createInterface((x) => x.singleton(DefaultEventEmitterDI));
20
+ /**
21
+ * Register an emitter with the DI.
22
+ * @typeParam TEventDetailMap - The {@link EventDetailMap}.
23
+ * @public
24
+ */
11
25
  export const registerEmitter = () => {
12
26
  return DI.createInterface((x) => x.aliasTo(EventEmitterDI));
13
27
  };
@@ -1,7 +1,60 @@
1
1
  import { getBaseEmitArgs, } from '../types';
2
- export const EventEmitter = (Base) => class extends Base {
3
- $emit(...args) {
4
- const [type, detail, options] = getBaseEmitArgs(...args);
5
- return super.$emit(type, detail, options);
2
+ /**
3
+ * EventEmitter mixin.
4
+ *
5
+ * @remarks
6
+ * Strongly types the components `$emit` method, allowing only the mapped events to be emitted.
7
+ *
8
+ * @example
9
+ * Apply mixin to the base {@link @microsoft/fast-element#FASTElement | FASTElement}
10
+ *
11
+ * # Import
12
+ * ```ts
13
+ * import { EventEmitter, SomeSystemLevelEventDetailMap } from '@genesislcap/foundation-events';
14
+ * import { StoreEventDetailMap, TradeEntryEventDetailMap } from '../store'; // < custom app level event maps
15
+ * ```
16
+ *
17
+ * # Create event map
18
+ * ```ts
19
+ * type EventMap = SomeSystemLevelEventDetailMap & StoreEventDetailMap & TradeEntryEventDetailMap;
20
+ * ```
21
+ *
22
+ * # Apply Mixin
23
+ * ```ts
24
+ * export class MyComponent extends EventEmitter<EventMap>(FASTElement) {
25
+ * onSomeComponentEvent() {
26
+ * this.$emit('some-allowed-event', { foo: 'expected data structure' });
27
+ * }
28
+ * }
29
+ * ```
30
+ *
31
+ * @example
32
+ * Apply mixin to a class in the inheritance chain requires a second generic type param.
33
+ *
34
+ * # Apply Mixin to MyComponent that extends MyBaseComponent (which might be abstract). Mixin can be applied at different levels.
35
+ * # Please note there's a current limitation on retaining protected member access with this approach, so apply to base where possible.
36
+ * # Also, super classes cannot emit typed events via inheritance. Each level must have an explicit map. Devs can use a Union and Pick to create these.
37
+ * ```ts
38
+ * export class MyComponent extends EventEmitter<EventMap, MyBaseComponent>(MyBaseComponent) {}
39
+ * ```
40
+ *
41
+ * @privateRemarks
42
+ * Failed to retain protected member access when the mixin is applied while keeping the typed emitter, we can revisit if needed.
43
+ * So in the last example, if `MyBaseComponent` had a protected member, `MyComponent` wouldn't be able to access it with the mixin
44
+ * applied. Public members are fine. It may be a limitation of TypeScript. Suggestions welcome, but be warned it's a time sink.
45
+ *
46
+ * @typeParam TEventDetailMap - The {@link EventDetailMap}.
47
+ * @typeParam TTarget - The target class.
48
+ * @param Target - The class to apply the mixin to which ultimately extends {@link @microsoft/fast-element#FASTElement | FASTElement}.
49
+ * @public
50
+ */
51
+ export const EventEmitter = (Target) => {
52
+ // @ts-ignore used here instead of `extends (Target as EventEmitterTarget<FASTElement>)` to avoid modifying return type
53
+ class Mixin extends Target {
54
+ $emit(...args) {
55
+ const [type, detail, options] = getBaseEmitArgs(...args);
56
+ return super.$emit(type, detail, options);
57
+ }
6
58
  }
59
+ return Mixin;
7
60
  };
package/dist/esm/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './eventEmitter';
2
2
  export * from './types';
3
+ export * from './utils';
package/dist/esm/types.js CHANGED
@@ -1,6 +1,12 @@
1
+ /**
2
+ * @public
3
+ */
1
4
  const isEmitOptions = (candidate) => (candidate === null || candidate === void 0 ? void 0 : candidate.hasOwnProperty('bubbles')) ||
2
5
  (candidate === null || candidate === void 0 ? void 0 : candidate.hasOwnProperty('cancelable')) ||
3
6
  (candidate === null || candidate === void 0 ? void 0 : candidate.hasOwnProperty('composed'));
7
+ /**
8
+ * @public
9
+ */
4
10
  export const getBaseEmitArgs = (...args) => {
5
11
  let [type, detailOrOptions, options] = args;
6
12
  let detail = detailOrOptions;
@@ -13,9 +19,51 @@ export const getBaseEmitArgs = (...args) => {
13
19
  }
14
20
  return [type, detail, options];
15
21
  };
22
+ /**
23
+ * @public
24
+ */
16
25
  export const customEvent = (ctx) => ctx.event;
26
+ /**
27
+ * @public
28
+ */
17
29
  export const targetValue = (ctx) => ctx.event.target.value;
30
+ /**
31
+ * @public
32
+ */
18
33
  export const targetFirstSelectedValue = (ctx) => { var _a, _b; return (_b = (_a = ctx.event.target) === null || _a === void 0 ? void 0 : _a.firstSelectedOption) === null || _b === void 0 ? void 0 : _b.value; };
34
+ /**
35
+ * @internal
36
+ */
19
37
  const createChangeEmitter = (valueGetter) => (type, options) => (x, c) => x.$emit(String(type), valueGetter(c), options);
38
+ /**
39
+ * `<input>` template emit helper.
40
+ *
41
+ * @remarks
42
+ * In some.template.ts file you create the helper upfront by passing in the full event map.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * const inputEmit = createInputEmitter<EventMap>();
47
+ * ...
48
+ * <zero-text-field @change="${inputEmit('some-input-changed')}">
49
+ * ```
50
+ *
51
+ * @public
52
+ */
20
53
  export const createInputEmitter = () => createChangeEmitter(targetValue);
54
+ /**
55
+ * `<select>` template emit helper.
56
+ *
57
+ * @remarks
58
+ * In some.template.ts file you create the helper upfront by passing in the full event map.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * const selectEmit = createSelectEmitter<EventMap>();
63
+ * ...
64
+ * <zero-select @change="${selectEmit('some-select-changed')}">
65
+ * ```
66
+ *
67
+ * @public
68
+ */
21
69
  export const createSelectEmitter = () => createChangeEmitter(targetFirstSelectedValue);
@@ -0,0 +1 @@
1
+ export * from './logger';
@@ -0,0 +1,5 @@
1
+ import { createLogger } from '@genesislcap/foundation-utils';
2
+ /**
3
+ * @public
4
+ */
5
+ export const logger = createLogger('foundation-events');