piral-core 0.15.0-beta.4633 → 0.15.0-beta.4672

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 (48) hide show
  1. package/app.codegen +6 -135
  2. package/esm/components/ForeignComponentContainer.js +1 -1
  3. package/esm/components/ForeignComponentContainer.js.map +1 -1
  4. package/esm/defaults/navigator_v5.d.ts +6 -0
  5. package/esm/defaults/navigator_v5.js +77 -0
  6. package/esm/defaults/navigator_v5.js.map +1 -0
  7. package/esm/defaults/navigator_v6.d.ts +6 -0
  8. package/esm/defaults/navigator_v6.js +73 -0
  9. package/esm/defaults/navigator_v6.js.map +1 -0
  10. package/esm/modules/element.js +46 -2
  11. package/esm/modules/element.js.map +1 -1
  12. package/esm/types/navigation.d.ts +6 -2
  13. package/esm/utils/extension.d.ts +1 -1
  14. package/esm/utils/extension.js +1 -1
  15. package/esm/utils/extension.js.map +1 -1
  16. package/esm/utils/foreign.d.ts +3 -0
  17. package/esm/utils/foreign.js +5 -2
  18. package/esm/utils/foreign.js.map +1 -1
  19. package/lib/components/ForeignComponentContainer.js +1 -1
  20. package/lib/components/ForeignComponentContainer.js.map +1 -1
  21. package/lib/defaults/navigator_v5.d.ts +6 -0
  22. package/lib/defaults/navigator_v5.js +84 -0
  23. package/lib/defaults/navigator_v5.js.map +1 -0
  24. package/lib/defaults/navigator_v6.d.ts +6 -0
  25. package/lib/defaults/navigator_v6.js +80 -0
  26. package/lib/defaults/navigator_v6.js.map +1 -0
  27. package/lib/modules/element.js +45 -1
  28. package/lib/modules/element.js.map +1 -1
  29. package/lib/types/navigation.d.ts +6 -2
  30. package/lib/utils/extension.d.ts +1 -1
  31. package/lib/utils/extension.js +1 -1
  32. package/lib/utils/extension.js.map +1 -1
  33. package/lib/utils/foreign.d.ts +3 -0
  34. package/lib/utils/foreign.js +6 -3
  35. package/lib/utils/foreign.js.map +1 -1
  36. package/package.json +5 -4
  37. package/src/components/ForeignComponentContainer.test.tsx +1 -1
  38. package/src/components/ForeignComponentContainer.tsx +2 -1
  39. package/src/defaults/navigator_v5.tsx +96 -0
  40. package/src/defaults/navigator_v6.tsx +93 -0
  41. package/src/modules/element.test.ts +0 -10
  42. package/src/modules/element.ts +60 -2
  43. package/src/types/api.ts +1 -0
  44. package/src/types/navigation.ts +6 -2
  45. package/src/utils/extension.test.tsx +1 -1
  46. package/src/utils/extension.tsx +3 -2
  47. package/src/utils/foreign.test.ts +5 -5
  48. package/src/utils/foreign.ts +6 -2
@@ -1,12 +1,31 @@
1
1
  import { ExtensionSlot } from '../components';
2
- import { tryParseJson, noop, reactifyContent, renderInDom, changeDomPortal } from '../utils';
3
2
  import { Disposable, GlobalStateContext } from '../types';
3
+ import {
4
+ tryParseJson,
5
+ noop,
6
+ reactifyContent,
7
+ renderInDom,
8
+ changeDomPortal,
9
+ portalName,
10
+ extensionName,
11
+ slotName,
12
+ } from '../utils';
4
13
 
5
14
  export interface Updatable {
6
15
  (newProps: any): void;
7
16
  }
8
17
 
9
18
  if (typeof window !== 'undefined' && 'customElements' in window) {
19
+ /**
20
+ * This is a nice abstraction allowing anyone to actually use the extension system
21
+ * brought by Piral. Not all props of the extension system are actually exposed.
22
+ *
23
+ * Usage:
24
+ *
25
+ * ```
26
+ * <piral-extension name="my-ext-name"></piral-extension>
27
+ * ```
28
+ */
10
29
  class PiralExtension extends HTMLElement {
11
30
  dispose: Disposable = noop;
12
31
  update: Updatable = noop;
@@ -45,6 +64,8 @@ if (typeof window !== 'undefined' && 'customElements' in window) {
45
64
  }
46
65
 
47
66
  connectedCallback() {
67
+ this.style.display = 'contents';
68
+
48
69
  if (this.isConnected) {
49
70
  this.dispatchEvent(
50
71
  new CustomEvent('render-html', {
@@ -80,7 +101,44 @@ if (typeof window !== 'undefined' && 'customElements' in window) {
80
101
  }
81
102
  }
82
103
 
83
- customElements.define('piral-extension', PiralExtension);
104
+ customElements.define(extensionName, PiralExtension);
105
+
106
+ /**
107
+ * This is a boundary to host elements from other frameworks - effectively vanishing
108
+ * at runtime.
109
+ *
110
+ * Usage:
111
+ *
112
+ * ```
113
+ * <piral-portal pid="host-1234"></piral-portal>
114
+ * ```
115
+ */
116
+ class PiralPortal extends HTMLElement {
117
+ connectedCallback() {
118
+ this.style.display = 'contents';
119
+ }
120
+ }
121
+
122
+ customElements.define(portalName, PiralPortal);
123
+
124
+ /**
125
+ * This is a virtual element to aggregate rendering from other frameworks, mostly
126
+ * used like piral-portal, but without context-hosting capabilities. This would
127
+ * be used exclusively within a foreign framework, not from Piral to initiate.
128
+ *
129
+ * Usage:
130
+ *
131
+ * ```
132
+ * <piral-slot></piral-slot>
133
+ * ```
134
+ */
135
+ class PiralSlot extends HTMLElement {
136
+ connectedCallback() {
137
+ this.style.display = 'contents';
138
+ }
139
+ }
140
+
141
+ customElements.define(slotName, PiralSlot);
84
142
  }
85
143
 
86
144
  export function renderElement(
package/src/types/api.ts CHANGED
@@ -10,6 +10,7 @@ import type {
10
10
  PiletLoader,
11
11
  PiletLoadingStrategy,
12
12
  } from 'piral-base';
13
+ import type {} from 'piral-debug-utils';
13
14
  import type { PiletCustomApi, PiralCustomPageMeta } from './custom';
14
15
  import type { AnyComponent } from './components';
15
16
  import type { ExtensionParams, ExtensionSlotProps, PiralExtensionSlotMap } from './extension';
@@ -36,7 +36,7 @@ export interface NavigationLocation {
36
36
  * On the initial location, this will be the string default. On all subsequent
37
37
  * locations, this string will be a unique identifier.
38
38
  */
39
- key: string;
39
+ key?: string;
40
40
  }
41
41
 
42
42
  export interface NavigationListener {
@@ -53,7 +53,7 @@ export interface NavigationUpdate {
53
53
  }
54
54
 
55
55
  export interface NavigationTransition extends NavigationUpdate {
56
- retry(): void;
56
+ retry?(): void;
57
57
  }
58
58
 
59
59
  export interface NavigationApi {
@@ -85,6 +85,10 @@ export interface NavigationApi {
85
85
  * @returns The disposable for stopping the block.
86
86
  */
87
87
  listen(listener: NavigationListener): Disposable;
88
+ /**
89
+ * Gets the current path.
90
+ */
91
+ path: string;
88
92
  /**
89
93
  * The original router behind the navigation.
90
94
  */
@@ -16,6 +16,6 @@ describe('Util Extension.', () => {
16
16
  container.innerHTML = `<div>FOO<</div>`;
17
17
  const result = reactifyContent(container.childNodes) as React.ReactElement;
18
18
  const node = render(result);
19
- expect(node.container.querySelectorAll('slot').length).toBe(1);
19
+ expect(node.container.querySelectorAll('piral-slot').length).toBe(1);
20
20
  });
21
21
  });
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
- import { ExtensionComponentProps, WrappedComponent } from '../types';
2
+ import type {} from 'piral-debug-utils';
3
+ import type { ExtensionComponentProps, WrappedComponent } from '../types';
3
4
 
4
5
  function removeAll(nodes: Array<ChildNode>) {
5
6
  nodes.forEach((node) => node.remove());
@@ -18,7 +19,7 @@ const SlotCarrier: React.FC<SlotCarrierProps> = ({ nodes }) => {
18
19
  }, [nodes]);
19
20
 
20
21
  if (nodes.length) {
21
- return <slot ref={host} />;
22
+ return <piral-slot ref={host} />;
22
23
  }
23
24
 
24
25
  return null;
@@ -14,8 +14,8 @@ describe('Util Foreign.', () => {
14
14
  const context = {
15
15
  updatePortal: jest.fn(),
16
16
  } as any;
17
- const portalId = 'data-portal-id';
18
- const element = document.createElement('div') as HTMLDivElement;
17
+ const portalId = 'pid';
18
+ const element = document.createElement('piral-portal') as HTMLElement;
19
19
  element.setAttribute(portalId, '100');
20
20
 
21
21
  const result = changeDomPortal(portalId, current, context, element, DefaultLoadingIndicator, {});
@@ -43,8 +43,8 @@ describe('Util Foreign.', () => {
43
43
  const context = {
44
44
  showPortal: jest.fn(),
45
45
  } as any;
46
- const portalId = 'data-portal-id';
47
- const element = document.createElement('div') as HTMLDivElement;
46
+ const portalId = 'pid';
47
+ const element = document.createElement('piral-portal') as HTMLElement;
48
48
  element.setAttribute(portalId, '100');
49
49
  var [result] = renderInDom(context, element, DefaultLoadingIndicator, {});
50
50
  expect(result).toBe('100');
@@ -54,7 +54,7 @@ describe('Util Foreign.', () => {
54
54
  const context = {
55
55
  showPortal: jest.fn(),
56
56
  } as any;
57
- const element = document.createElement('div') as HTMLDivElement;
57
+ const element = document.createElement('piral-portal') as HTMLElement;
58
58
  var [result] = renderInDom(context, element, DefaultLoadingIndicator, {});
59
59
  expect(result).toBe('root');
60
60
  });
@@ -2,6 +2,10 @@ import { createElement, ComponentType, ReactPortal } from 'react';
2
2
  import { createPortal } from 'react-dom';
3
3
  import { GlobalStateContext, ForeignComponent } from '../types';
4
4
 
5
+ export const extensionName = 'piral-extension';
6
+ export const portalName = 'piral-portal';
7
+ export const slotName = 'piral-slot';
8
+
5
9
  export function attachDomPortal<TProps>(
6
10
  id: string,
7
11
  context: GlobalStateContext,
@@ -44,11 +48,11 @@ export function renderInDom<TProps>(
44
48
  component: ComponentType<TProps>,
45
49
  props: TProps,
46
50
  ) {
47
- const portalId = 'data-portal-id';
51
+ const portalId = 'pid';
48
52
  let parent: Node = element;
49
53
 
50
54
  while (parent) {
51
- if (parent instanceof Element && parent.hasAttribute(portalId)) {
55
+ if (parent instanceof Element && parent.localName === portalName && parent.hasAttribute(portalId)) {
52
56
  const id = parent.getAttribute(portalId);
53
57
  return attachDomPortal(id, context, element, component, props);
54
58
  }