piral-core 0.14.8-beta.3500 → 0.14.8-beta.3511

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 (113) hide show
  1. package/esm/Piral.d.ts +2 -2
  2. package/esm/Piral.js +3 -1
  3. package/esm/Piral.js.map +1 -1
  4. package/esm/RootListener.d.ts +2 -0
  5. package/esm/RootListener.js +23 -0
  6. package/esm/RootListener.js.map +1 -0
  7. package/esm/components/ExtensionSlot.js +2 -2
  8. package/esm/components/ExtensionSlot.js.map +1 -1
  9. package/esm/components/Mediator.js +11 -8
  10. package/esm/components/Mediator.js.map +1 -1
  11. package/esm/components/ResponsiveLayout.js +3 -3
  12. package/esm/components/ResponsiveLayout.js.map +1 -1
  13. package/esm/components/SetComponent.js +2 -2
  14. package/esm/components/SetComponent.js.map +1 -1
  15. package/esm/components/SetError.js +2 -2
  16. package/esm/components/SetError.js.map +1 -1
  17. package/esm/components/SetProvider.js +2 -2
  18. package/esm/components/SetProvider.js.map +1 -1
  19. package/esm/components/SetRedirect.js +2 -2
  20. package/esm/components/SetRedirect.js.map +1 -1
  21. package/esm/components/SetRoute.js +2 -2
  22. package/esm/components/SetRoute.js.map +1 -1
  23. package/esm/createInstance.d.ts +2 -2
  24. package/esm/createInstance.js +3 -1
  25. package/esm/createInstance.js.map +1 -1
  26. package/esm/modules/api.d.ts +3 -4
  27. package/esm/modules/api.js +1 -106
  28. package/esm/modules/api.js.map +1 -1
  29. package/esm/modules/core.d.ts +3 -0
  30. package/esm/modules/core.js +48 -0
  31. package/esm/modules/core.js.map +1 -0
  32. package/esm/modules/element.d.ts +5 -0
  33. package/esm/modules/element.js +83 -0
  34. package/esm/modules/element.js.map +1 -0
  35. package/esm/modules/index.d.ts +1 -0
  36. package/esm/modules/index.js +1 -0
  37. package/esm/modules/index.js.map +1 -1
  38. package/esm/state/withApi.js +2 -3
  39. package/esm/state/withApi.js.map +1 -1
  40. package/esm/types/extension.d.ts +7 -3
  41. package/esm/types/instance.d.ts +18 -3
  42. package/esm/utils/extension.d.ts +13 -0
  43. package/esm/utils/extension.js +32 -0
  44. package/esm/utils/extension.js.map +1 -1
  45. package/lib/Piral.d.ts +2 -2
  46. package/lib/Piral.js +3 -1
  47. package/lib/Piral.js.map +1 -1
  48. package/lib/RootListener.d.ts +2 -0
  49. package/lib/RootListener.js +27 -0
  50. package/lib/RootListener.js.map +1 -0
  51. package/lib/components/ExtensionSlot.js +2 -2
  52. package/lib/components/ExtensionSlot.js.map +1 -1
  53. package/lib/components/Mediator.js +10 -7
  54. package/lib/components/Mediator.js.map +1 -1
  55. package/lib/components/ResponsiveLayout.js +2 -2
  56. package/lib/components/ResponsiveLayout.js.map +1 -1
  57. package/lib/components/SetComponent.js +1 -1
  58. package/lib/components/SetComponent.js.map +1 -1
  59. package/lib/components/SetError.js +1 -1
  60. package/lib/components/SetError.js.map +1 -1
  61. package/lib/components/SetProvider.js +1 -1
  62. package/lib/components/SetProvider.js.map +1 -1
  63. package/lib/components/SetRedirect.js +1 -1
  64. package/lib/components/SetRedirect.js.map +1 -1
  65. package/lib/components/SetRoute.js +1 -1
  66. package/lib/components/SetRoute.js.map +1 -1
  67. package/lib/createInstance.d.ts +2 -2
  68. package/lib/createInstance.js +3 -1
  69. package/lib/createInstance.js.map +1 -1
  70. package/lib/modules/api.d.ts +3 -4
  71. package/lib/modules/api.js +3 -109
  72. package/lib/modules/api.js.map +1 -1
  73. package/lib/modules/core.d.ts +3 -0
  74. package/lib/modules/core.js +52 -0
  75. package/lib/modules/core.js.map +1 -0
  76. package/lib/modules/element.d.ts +5 -0
  77. package/lib/modules/element.js +87 -0
  78. package/lib/modules/element.js.map +1 -0
  79. package/lib/modules/index.d.ts +1 -0
  80. package/lib/modules/index.js +1 -0
  81. package/lib/modules/index.js.map +1 -1
  82. package/lib/state/withApi.js +1 -2
  83. package/lib/state/withApi.js.map +1 -1
  84. package/lib/types/extension.d.ts +7 -3
  85. package/lib/types/instance.d.ts +18 -3
  86. package/lib/utils/extension.d.ts +13 -0
  87. package/lib/utils/extension.js +34 -1
  88. package/lib/utils/extension.js.map +1 -1
  89. package/package.json +4 -4
  90. package/src/Piral.tsx +5 -3
  91. package/src/RootListener.tsx +26 -0
  92. package/src/actions/app.ts +1 -1
  93. package/src/components/ExtensionSlot.tsx +2 -1
  94. package/src/components/Mediator.test.tsx +4 -3
  95. package/src/components/Mediator.tsx +15 -8
  96. package/src/components/ResponsiveLayout.test.tsx +15 -5
  97. package/src/components/ResponsiveLayout.tsx +3 -3
  98. package/src/components/SetComponent.tsx +2 -2
  99. package/src/components/SetError.tsx +2 -2
  100. package/src/components/SetProvider.tsx +2 -2
  101. package/src/components/SetRedirect.tsx +2 -2
  102. package/src/components/SetRoute.tsx +2 -2
  103. package/src/createInstance.tsx +5 -2
  104. package/src/modules/api.test.ts +15 -15
  105. package/src/modules/api.ts +3 -125
  106. package/src/modules/core.test.ts +148 -0
  107. package/src/modules/core.ts +50 -0
  108. package/src/modules/element.ts +103 -0
  109. package/src/modules/index.ts +1 -0
  110. package/src/state/withApi.tsx +2 -3
  111. package/src/types/extension.ts +7 -2
  112. package/src/types/instance.ts +19 -3
  113. package/src/utils/extension.tsx +41 -0
@@ -1,11 +1,12 @@
1
1
  import type { PiletApi, PiletApiCreator, LoadPiletsOptions, EventEmitter } from 'piral-base';
2
2
  import type { GlobalStateContext } from './state';
3
3
  import type { LayoutBreakpoints } from './layout';
4
+ import { PiralConfiguration } from './config';
4
5
 
5
6
  /**
6
7
  * The props of the Piral component.
7
8
  */
8
- export interface PortalProps {
9
+ export interface PiralProps {
9
10
  /**
10
11
  * The specific Piral instance to be used.
11
12
  */
@@ -17,10 +18,25 @@ export interface PortalProps {
17
18
  }
18
19
 
19
20
  /**
20
- * The PiralInstance component, which is an event emitter containing the React
21
- * functional component as well as some other utilities and helpers.
21
+ * The options for creating a new PiralInstance object.
22
+ */
23
+ export interface PiralInstanceOptions extends PiralConfiguration {
24
+ /**
25
+ * Defines the id of this instance. Used in case of multiple instances.
26
+ */
27
+ id?: string;
28
+ }
29
+
30
+ /**
31
+ * The PiralInstance object, which is an event emitter with some other
32
+ * utilities and helper. This object is the source for the React
33
+ * functional component (`Piral`).
22
34
  */
23
35
  export interface PiralInstance extends EventEmitter {
36
+ /**
37
+ * The id of the Piral instance.
38
+ */
39
+ id: string;
24
40
  /**
25
41
  * The global state context instance.
26
42
  */
@@ -1,6 +1,47 @@
1
1
  import * as React from 'react';
2
2
  import { ExtensionComponentProps, WrappedComponent } from '../types';
3
3
 
4
+ function removeAll(nodes: Array<ChildNode>) {
5
+ nodes.forEach((node) => node.remove());
6
+ }
7
+
8
+ interface SlotCarrierProps {
9
+ nodes: Array<ChildNode>;
10
+ }
11
+
12
+ const SlotCarrier: React.FC<SlotCarrierProps> = ({ nodes }) => {
13
+ const host = React.useRef<HTMLSlotElement>();
14
+
15
+ React.useEffect(() => {
16
+ host.current?.append(...nodes);
17
+ return () => removeAll(nodes);
18
+ }, [nodes]);
19
+
20
+ if (nodes.length) {
21
+ return <slot ref={host} />;
22
+ }
23
+
24
+ return null;
25
+ };
26
+
27
+ /**
28
+ * Transforms the given component to an extension component.
29
+ * @param Component The component to transform.
30
+ * @returns The extension component (receiving its props via params).
31
+ */
4
32
  export function toExtension<T>(Component: React.ComponentType<T>): WrappedComponent<ExtensionComponentProps<T>> {
5
33
  return (props) => <Component {...props.params} />;
6
34
  }
35
+
36
+ /**
37
+ * Reactifies the list of child nodes to a React Node by removing the
38
+ * nodes from the DOM and carrying it in a React Node, where it would be
39
+ * attached at a slot.
40
+ * @param childNodes The child nodes to reactify.
41
+ * @returns The React Node.
42
+ */
43
+ export function reactifyContent(childNodes: NodeListOf<ChildNode>): React.ReactNode {
44
+ const nodes: Array<ChildNode> = Array.prototype.filter.call(childNodes, Boolean);
45
+ removeAll(nodes);
46
+ return <SlotCarrier nodes={nodes} />;
47
+ }