@cleanweb/oore 2.0.0-alpha.23 → 2.0.0-alpha.25

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.
@@ -28,9 +28,9 @@ export declare class ComponentMethods<TProps extends object = {}, TState extends
28
28
  _onHmrUpdate?: <TInstance extends this>(oldInstance: TInstance) => void;
29
29
  }
30
30
  type UseMethods = {
31
- <Class extends typeof ComponentMethods<object, object>>(Methods: Class & Constructor<InstanceType<Class>>, props: InstanceType<Class>['props'], state: InstanceType<Class>['state']): InstanceType<Class>;
32
- <Class extends typeof ComponentMethods<object, null>>(Methods: Class & Constructor<InstanceType<Class>>, props: InstanceType<Class>['props'], state?: null): InstanceType<Class>;
33
- <Class extends typeof ComponentMethods<NeverObject, null>>(Methods: Class & Constructor<InstanceType<Class>>): InstanceType<Class>;
31
+ <Class extends typeof ComponentMethods<object, object>>(Methods: Class, props: InstanceType<Class>['props'], state: InstanceType<Class>['state']): InstanceType<Class>;
32
+ <Class extends typeof ComponentMethods<object, null>>(Methods: Class, props: InstanceType<Class>['props'], state?: null): InstanceType<Class>;
33
+ <Class extends typeof ComponentMethods<NeverObject, null>>(Methods: Class): InstanceType<Class>;
34
34
  };
35
35
  /**
36
36
  * Returns an instance of the provided class,
@@ -50,6 +50,9 @@ const getComponentSlotName = (TargetComponent, child) => {
50
50
  else if ('displayName' in TargetComponent) {
51
51
  return TargetComponent.displayName;
52
52
  }
53
+ else if ('name' in TargetComponent) {
54
+ return TargetComponent.name;
55
+ }
53
56
  return undefined;
54
57
  };
55
58
  exports.getComponentSlotName = getComponentSlotName;
@@ -72,14 +75,18 @@ exports.isPortalChild = isPortalChild;
72
75
  const useSlots = (children, Caller) => {
73
76
  const slotsAliasLookup = (0, react_1.useMemo)(() => {
74
77
  const entries = Object.entries(Caller.Slots);
75
- const aliasLookup = {};
78
+ const aliasLookup = {
79
+ byName: {},
80
+ byIdentity: new Map(),
81
+ };
76
82
  entries.forEach(([alias, RegisteredSlotComponent]) => {
77
83
  const slotName = (0, exports.getComponentSlotName)(RegisteredSlotComponent);
78
84
  if (!slotName) {
79
- (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: ${RegisteredSlotComponent}`);
80
- return;
85
+ aliasLookup.byIdentity.set(RegisteredSlotComponent, alias);
86
+ aliasLookup.byName[alias] = alias;
81
87
  }
82
- aliasLookup[slotName] = alias;
88
+ else
89
+ aliasLookup.byName[slotName] = alias;
83
90
  });
84
91
  return aliasLookup;
85
92
  }, [Caller.Slots]);
@@ -93,7 +100,6 @@ const useSlots = (children, Caller) => {
93
100
  ...((_a = Caller.requiredSlotAliases) !== null && _a !== void 0 ? _a : [])
94
101
  ];
95
102
  react_1.default.Children.forEach(children, (_child) => {
96
- var _a;
97
103
  const child = _child;
98
104
  if (!child) {
99
105
  invalidChildren.push(child);
@@ -111,16 +117,13 @@ const useSlots = (children, Caller) => {
111
117
  return;
112
118
  }
113
119
  const slotAlias = (() => {
114
- var _a;
115
120
  const slotName = (0, exports.getComponentSlotName)(child.type, child);
116
- return slotName ? (_a = slotsAliasLookup[slotName]) !== null && _a !== void 0 ? _a : null : null;
121
+ const alias = slotName
122
+ ? slotsAliasLookup.byName[slotName]
123
+ : slotsAliasLookup.byIdentity.get(child.type);
124
+ return alias !== null && alias !== void 0 ? alias : null;
117
125
  })();
118
126
  if (slotAlias) {
119
- if (typeof Caller.Slots[slotAlias] !== 'string') {
120
- if ((_a = Caller.Slots[slotAlias]) === null || _a === void 0 ? void 0 : _a.isRequiredSlot) {
121
- requiredSlotAliases.push(slotAlias);
122
- }
123
- }
124
127
  if (slotNodes[slotAlias]) {
125
128
  slotNodes[slotAlias].push(child);
126
129
  }
@@ -18,12 +18,7 @@ export type DisplayNamedComponent<TComponent extends ComponentType<any> = Compon
18
18
  displayName: TName;
19
19
  };
20
20
  interface ISlotConfig<TName> {
21
- slotName: TName;
22
- /**
23
- * @deprecated The SlottedComponent should be responsible for indicating which slots it requires.
24
- * Individual slot components may be reused by multiple slotted components with varying requirements.
25
- */
26
- isRequiredSlot?: boolean;
21
+ slotName?: TName;
27
22
  }
28
23
  /**
29
24
  * A child component used to insert content into a specific slot in the parent component.
@@ -28,9 +28,9 @@ export declare class ComponentMethods<TProps extends object = {}, TState extends
28
28
  _onHmrUpdate?: <TInstance extends this>(oldInstance: TInstance) => void;
29
29
  }
30
30
  type UseMethods = {
31
- <Class extends typeof ComponentMethods<object, object>>(Methods: Class & Constructor<InstanceType<Class>>, props: InstanceType<Class>['props'], state: InstanceType<Class>['state']): InstanceType<Class>;
32
- <Class extends typeof ComponentMethods<object, null>>(Methods: Class & Constructor<InstanceType<Class>>, props: InstanceType<Class>['props'], state?: null): InstanceType<Class>;
33
- <Class extends typeof ComponentMethods<NeverObject, null>>(Methods: Class & Constructor<InstanceType<Class>>): InstanceType<Class>;
31
+ <Class extends typeof ComponentMethods<object, object>>(Methods: Class, props: InstanceType<Class>['props'], state: InstanceType<Class>['state']): InstanceType<Class>;
32
+ <Class extends typeof ComponentMethods<object, null>>(Methods: Class, props: InstanceType<Class>['props'], state?: null): InstanceType<Class>;
33
+ <Class extends typeof ComponentMethods<NeverObject, null>>(Methods: Class): InstanceType<Class>;
34
34
  };
35
35
  /**
36
36
  * Returns an instance of the provided class,
@@ -23,6 +23,9 @@ export const getComponentSlotName = (TargetComponent, child) => {
23
23
  else if ('displayName' in TargetComponent) {
24
24
  return TargetComponent.displayName;
25
25
  }
26
+ else if ('name' in TargetComponent) {
27
+ return TargetComponent.name;
28
+ }
26
29
  return undefined;
27
30
  };
28
31
  export const isPortalChild = (child) => {
@@ -43,14 +46,18 @@ export const isPortalChild = (child) => {
43
46
  export const useSlots = (children, Caller) => {
44
47
  const slotsAliasLookup = useMemo(() => {
45
48
  const entries = Object.entries(Caller.Slots);
46
- const aliasLookup = {};
49
+ const aliasLookup = {
50
+ byName: {},
51
+ byIdentity: new Map(),
52
+ };
47
53
  entries.forEach(([alias, RegisteredSlotComponent]) => {
48
54
  const slotName = getComponentSlotName(RegisteredSlotComponent);
49
55
  if (!slotName) {
50
- 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: ${RegisteredSlotComponent}`);
51
- return;
56
+ aliasLookup.byIdentity.set(RegisteredSlotComponent, alias);
57
+ aliasLookup.byName[alias] = alias;
52
58
  }
53
- aliasLookup[slotName] = alias;
59
+ else
60
+ aliasLookup.byName[slotName] = alias;
54
61
  });
55
62
  return aliasLookup;
56
63
  }, [Caller.Slots]);
@@ -64,7 +71,6 @@ export const useSlots = (children, Caller) => {
64
71
  ...((_a = Caller.requiredSlotAliases) !== null && _a !== void 0 ? _a : [])
65
72
  ];
66
73
  React.Children.forEach(children, (_child) => {
67
- var _a;
68
74
  const child = _child;
69
75
  if (!child) {
70
76
  invalidChildren.push(child);
@@ -82,16 +88,13 @@ export const useSlots = (children, Caller) => {
82
88
  return;
83
89
  }
84
90
  const slotAlias = (() => {
85
- var _a;
86
91
  const slotName = getComponentSlotName(child.type, child);
87
- return slotName ? (_a = slotsAliasLookup[slotName]) !== null && _a !== void 0 ? _a : null : null;
92
+ const alias = slotName
93
+ ? slotsAliasLookup.byName[slotName]
94
+ : slotsAliasLookup.byIdentity.get(child.type);
95
+ return alias !== null && alias !== void 0 ? alias : null;
88
96
  })();
89
97
  if (slotAlias) {
90
- if (typeof Caller.Slots[slotAlias] !== 'string') {
91
- if ((_a = Caller.Slots[slotAlias]) === null || _a === void 0 ? void 0 : _a.isRequiredSlot) {
92
- requiredSlotAliases.push(slotAlias);
93
- }
94
- }
95
98
  if (slotNodes[slotAlias]) {
96
99
  slotNodes[slotAlias].push(child);
97
100
  }
@@ -18,12 +18,7 @@ export type DisplayNamedComponent<TComponent extends ComponentType<any> = Compon
18
18
  displayName: TName;
19
19
  };
20
20
  interface ISlotConfig<TName> {
21
- slotName: TName;
22
- /**
23
- * @deprecated The SlottedComponent should be responsible for indicating which slots it requires.
24
- * Individual slot components may be reused by multiple slotted components with varying requirements.
25
- */
26
- isRequiredSlot?: boolean;
21
+ slotName?: TName;
27
22
  }
28
23
  /**
29
24
  * A child component used to insert content into a specific slot in the parent component.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cleanweb/oore",
3
- "version": "2.0.0-alpha.23",
3
+ "version": "2.0.0-alpha.25",
4
4
  "description": "A library of helpers for writing cleaner React function components with object-oriented patterns.",
5
5
  "engines": {
6
6
  "node": ">=22"