@cleanweb/oore 1.2.0 → 1.2.1-beta.0

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.
@@ -45,7 +45,7 @@ var getComponentSlotName = function (TargetComponent, child) {
45
45
  return undefined;
46
46
  };
47
47
  exports.getComponentSlotName = getComponentSlotName;
48
- var useSlots = function (children, slotComponents, _requiredSlots) {
48
+ var useSlots = function (children, slotComponents, requiredSlotAliases) {
49
49
  var useMemo = react_1.default.useMemo;
50
50
  var slotsAliasLookup = useMemo(function () {
51
51
  var entries = Object.entries(slotComponents);
@@ -57,7 +57,7 @@ var useSlots = function (children, slotComponents, _requiredSlots) {
57
57
  (0, errors_1.throwDevError)("A registered slot component did not have a slot name. All components registered as slots must either be a string tag-name or a React component with either \"slotName\" or \"displayName\". The affected component was: ".concat(RegisteredSlotComponent));
58
58
  return;
59
59
  }
60
- return aliasLookup[slotName] = alias;
60
+ aliasLookup[slotName] = alias;
61
61
  });
62
62
  return aliasLookup;
63
63
  }, [slotComponents]);
@@ -65,7 +65,7 @@ var useSlots = function (children, slotComponents, _requiredSlots) {
65
65
  var slotNodes = {};
66
66
  var unmatchedChildren = [];
67
67
  var invalidChildren = [];
68
- var requiredSlots = __spreadArray([], (_requiredSlots !== null && _requiredSlots !== void 0 ? _requiredSlots : []), true);
68
+ var cachedRequiredSlotAliases = __spreadArray([], (requiredSlotAliases !== null && requiredSlotAliases !== void 0 ? requiredSlotAliases : []), true);
69
69
  react_1.default.Children.forEach(children, function (child) {
70
70
  if (!child) {
71
71
  invalidChildren.push(child);
@@ -87,15 +87,24 @@ var useSlots = function (children, slotComponents, _requiredSlots) {
87
87
  })();
88
88
  if (slotAlias && (typeof slotComponents[slotAlias] !== 'string')) {
89
89
  if (slotComponents[slotAlias].isRequiredSlot) {
90
- requiredSlots.push(slotAlias);
90
+ cachedRequiredSlotAliases.push(slotAlias);
91
+ }
92
+ }
93
+ if (slotAlias) {
94
+ if (!slotNodes[slotAlias]) {
95
+ slotNodes[slotAlias] = child;
96
+ }
97
+ else if (Array.isArray(slotNodes[slotAlias])) {
98
+ slotNodes[slotAlias].push(child);
99
+ }
100
+ else {
101
+ slotNodes[slotAlias] = [slotNodes[slotAlias], child];
91
102
  }
92
103
  }
93
- if (slotAlias)
94
- slotNodes[slotAlias] = child;
95
104
  else
96
105
  unmatchedChildren.push(child);
97
106
  });
98
- requiredSlots.forEach(function (slotAlias) {
107
+ cachedRequiredSlotAliases.forEach(function (slotAlias) {
99
108
  if (!slotNodes[slotAlias]) {
100
109
  (0, errors_1.throwDevError)("Missing required slot \"".concat(String(slotAlias), "\"."));
101
110
  }
@@ -18,7 +18,7 @@ export type SlottedComponent<TComponentArg extends TComponent = TComponent, TSlo
18
18
  Slots: TSlotsRecordArg;
19
19
  };
20
20
  export type TSlotNodes<TSlotAliasArg extends TSlotAlias> = {
21
- [Key in TSlotAliasArg]?: ReactElement<any>;
21
+ [Key in TSlotAliasArg]?: ReactElement<any> | Array<ReactElement<any>>;
22
22
  };
23
23
  export type TUseSlotsResult<TSlotAliasArg extends TSlotAlias = TSlotAlias> = Readonly<[
24
24
  slots: TSlotNodes<TSlotAliasArg>,
@@ -26,6 +26,6 @@ export type TUseSlotsResult<TSlotAliasArg extends TSlotAlias = TSlotAlias> = Rea
26
26
  invalidChildren: any[]
27
27
  ]>;
28
28
  export interface IUseSlots {
29
- <TSlotAliasArg extends TSlotAlias = TSlotAlias>(children: ReactNode, slotComponents: TSlotsRecord<TSlotAliasArg>, requiredSlots?: TSlotAliasArg[]): TUseSlotsResult<TSlotAliasArg>;
29
+ <TSlotAliasArg extends TSlotAlias = TSlotAlias>(children: ReactNode, slotComponents: TSlotsRecord<TSlotAliasArg>, requiredSlotAliases?: TSlotAliasArg[]): TUseSlotsResult<TSlotAliasArg>;
30
30
  }
31
31
  export type PotentialSlotComponent = string | SlotComponent | TComponent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cleanweb/oore",
3
- "version": "1.2.0",
3
+ "version": "1.2.1-beta.0",
4
4
  "description": "A library of helpers for writing cleaner React function components with object-oriented patterns.",
5
5
  "engines": {
6
6
  "node": ">=20"