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.
- package/app.codegen +6 -135
- package/esm/components/ForeignComponentContainer.js +1 -1
- package/esm/components/ForeignComponentContainer.js.map +1 -1
- package/esm/defaults/navigator_v5.d.ts +6 -0
- package/esm/defaults/navigator_v5.js +77 -0
- package/esm/defaults/navigator_v5.js.map +1 -0
- package/esm/defaults/navigator_v6.d.ts +6 -0
- package/esm/defaults/navigator_v6.js +73 -0
- package/esm/defaults/navigator_v6.js.map +1 -0
- package/esm/modules/element.js +46 -2
- package/esm/modules/element.js.map +1 -1
- package/esm/types/navigation.d.ts +6 -2
- package/esm/utils/extension.d.ts +1 -1
- package/esm/utils/extension.js +1 -1
- package/esm/utils/extension.js.map +1 -1
- package/esm/utils/foreign.d.ts +3 -0
- package/esm/utils/foreign.js +5 -2
- package/esm/utils/foreign.js.map +1 -1
- package/lib/components/ForeignComponentContainer.js +1 -1
- package/lib/components/ForeignComponentContainer.js.map +1 -1
- package/lib/defaults/navigator_v5.d.ts +6 -0
- package/lib/defaults/navigator_v5.js +84 -0
- package/lib/defaults/navigator_v5.js.map +1 -0
- package/lib/defaults/navigator_v6.d.ts +6 -0
- package/lib/defaults/navigator_v6.js +80 -0
- package/lib/defaults/navigator_v6.js.map +1 -0
- package/lib/modules/element.js +45 -1
- package/lib/modules/element.js.map +1 -1
- package/lib/types/navigation.d.ts +6 -2
- package/lib/utils/extension.d.ts +1 -1
- package/lib/utils/extension.js +1 -1
- package/lib/utils/extension.js.map +1 -1
- package/lib/utils/foreign.d.ts +3 -0
- package/lib/utils/foreign.js +6 -3
- package/lib/utils/foreign.js.map +1 -1
- package/package.json +5 -4
- package/src/components/ForeignComponentContainer.test.tsx +1 -1
- package/src/components/ForeignComponentContainer.tsx +2 -1
- package/src/defaults/navigator_v5.tsx +96 -0
- package/src/defaults/navigator_v6.tsx +93 -0
- package/src/modules/element.test.ts +0 -10
- package/src/modules/element.ts +60 -2
- package/src/types/api.ts +1 -0
- package/src/types/navigation.ts +6 -2
- package/src/utils/extension.test.tsx +1 -1
- package/src/utils/extension.tsx +3 -2
- package/src/utils/foreign.test.ts +5 -5
- package/src/utils/foreign.ts +6 -2
package/src/modules/element.ts
CHANGED
|
@@ -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(
|
|
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';
|
package/src/types/navigation.ts
CHANGED
|
@@ -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
|
|
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
|
});
|
package/src/utils/extension.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
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 = '
|
|
18
|
-
const element = document.createElement('
|
|
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 = '
|
|
47
|
-
const element = document.createElement('
|
|
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('
|
|
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
|
});
|
package/src/utils/foreign.ts
CHANGED
|
@@ -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 = '
|
|
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
|
}
|