@telia-ace/widget-ui 1.0.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.
- package/LICENSE.txt +6 -0
- package/README.md +3 -0
- package/lib/components/anchor-link.d.ts +4 -0
- package/lib/components/anchor-link.js +7 -0
- package/lib/components/button.d.ts +4 -0
- package/lib/components/button.js +64 -0
- package/lib/components/checkbox.d.ts +7 -0
- package/lib/components/checkbox.js +39 -0
- package/lib/components/drawer/drawer.d.ts +21 -0
- package/lib/components/drawer/drawer.js +150 -0
- package/lib/components/drawer/index.d.ts +3 -0
- package/lib/components/drawer/index.js +29 -0
- package/lib/components/dropdown/dropdown.d.ts +9 -0
- package/lib/components/dropdown/dropdown.js +155 -0
- package/lib/components/dropdown/index.d.ts +4 -0
- package/lib/components/dropdown/index.js +10 -0
- package/lib/components/dropdown/use-position.d.ts +5 -0
- package/lib/components/dropdown/use-position.js +57 -0
- package/lib/components/empty.d.ts +4 -0
- package/lib/components/empty.js +40 -0
- package/lib/components/grid.d.ts +7 -0
- package/lib/components/grid.js +64 -0
- package/lib/components/html.d.ts +12 -0
- package/lib/components/html.js +78 -0
- package/lib/components/icon.d.ts +7 -0
- package/lib/components/icon.js +35 -0
- package/lib/components/index.d.ts +58 -0
- package/lib/components/index.js +69 -0
- package/lib/components/input.d.ts +10 -0
- package/lib/components/input.js +94 -0
- package/lib/components/item-list.d.ts +10 -0
- package/lib/components/item-list.js +62 -0
- package/lib/components/item-tree.d.ts +13 -0
- package/lib/components/item-tree.js +55 -0
- package/lib/components/lightbox.d.ts +6 -0
- package/lib/components/lightbox.js +92 -0
- package/lib/components/link.d.ts +11 -0
- package/lib/components/link.js +99 -0
- package/lib/components/list.d.ts +9 -0
- package/lib/components/list.js +56 -0
- package/lib/components/modal/confirm.d.ts +12 -0
- package/lib/components/modal/confirm.js +61 -0
- package/lib/components/modal/index.d.ts +4 -0
- package/lib/components/modal/index.js +10 -0
- package/lib/components/modal/modal.d.ts +10 -0
- package/lib/components/modal/modal.js +127 -0
- package/lib/components/not-found.d.ts +9 -0
- package/lib/components/not-found.js +55 -0
- package/lib/components/overlay.d.ts +8 -0
- package/lib/components/overlay.js +73 -0
- package/lib/components/paragraph.d.ts +11 -0
- package/lib/components/paragraph.js +66 -0
- package/lib/components/portal.d.ts +7 -0
- package/lib/components/portal.js +61 -0
- package/lib/components/route-link.d.ts +11 -0
- package/lib/components/route-link.js +115 -0
- package/lib/components/symbol-badge.d.ts +15 -0
- package/lib/components/symbol-badge.js +197 -0
- package/lib/components/tab-stop.d.ts +18 -0
- package/lib/components/tab-stop.js +100 -0
- package/lib/components/text-link.d.ts +8 -0
- package/lib/components/text-link.js +62 -0
- package/lib/components/text.d.ts +4 -0
- package/lib/components/text.js +35 -0
- package/lib/components/timestamp.d.ts +13 -0
- package/lib/components/timestamp.js +39 -0
- package/lib/components/tooltip.d.ts +8 -0
- package/lib/components/tooltip.js +127 -0
- package/lib/components/transition-component.d.ts +30 -0
- package/lib/components/transition-component.js +77 -0
- package/lib/components/typography.d.ts +9 -0
- package/lib/components/typography.js +43 -0
- package/lib/components/widget-link.d.ts +10 -0
- package/lib/components/widget-link.js +116 -0
- package/lib/contexts/index.d.ts +9 -0
- package/lib/contexts/index.js +15 -0
- package/lib/create-react-component.d.ts +11 -0
- package/lib/create-react-component.js +18 -0
- package/lib/hooks/index.d.ts +27 -0
- package/lib/hooks/index.js +58 -0
- package/lib/hooks/use-action.d.ts +4 -0
- package/lib/hooks/use-action.js +21 -0
- package/lib/hooks/use-children.d.ts +4 -0
- package/lib/hooks/use-children.js +70 -0
- package/lib/hooks/use-columns.d.ts +2 -0
- package/lib/hooks/use-columns.js +6 -0
- package/lib/hooks/use-component-descriptor.d.ts +2 -0
- package/lib/hooks/use-component-descriptor.js +6 -0
- package/lib/hooks/use-component-node.d.ts +6 -0
- package/lib/hooks/use-component-node.js +37 -0
- package/lib/hooks/use-component-platform.d.ts +4 -0
- package/lib/hooks/use-component-platform.js +39 -0
- package/lib/hooks/use-component.d.ts +3 -0
- package/lib/hooks/use-component.js +57 -0
- package/lib/hooks/use-container.d.ts +2 -0
- package/lib/hooks/use-container.js +6 -0
- package/lib/hooks/use-context.d.ts +3 -0
- package/lib/hooks/use-context.js +50 -0
- package/lib/hooks/use-dispatch.d.ts +3 -0
- package/lib/hooks/use-dispatch.js +64 -0
- package/lib/hooks/use-event-listener.d.ts +2 -0
- package/lib/hooks/use-event-listener.js +21 -0
- package/lib/hooks/use-events.d.ts +3 -0
- package/lib/hooks/use-events.js +12 -0
- package/lib/hooks/use-is-mounted.d.ts +3 -0
- package/lib/hooks/use-is-mounted.js +14 -0
- package/lib/hooks/use-key-press.d.ts +2 -0
- package/lib/hooks/use-key-press.js +46 -0
- package/lib/hooks/use-layout.d.ts +3 -0
- package/lib/hooks/use-layout.js +50 -0
- package/lib/hooks/use-previous.d.ts +2 -0
- package/lib/hooks/use-previous.js +11 -0
- package/lib/hooks/use-properties.d.ts +6 -0
- package/lib/hooks/use-properties.js +9 -0
- package/lib/hooks/use-render-state.d.ts +4 -0
- package/lib/hooks/use-render-state.js +66 -0
- package/lib/hooks/use-route-data.d.ts +4 -0
- package/lib/hooks/use-route-data.js +54 -0
- package/lib/hooks/use-router.d.ts +3 -0
- package/lib/hooks/use-router.js +9 -0
- package/lib/hooks/use-scroll.d.ts +2 -0
- package/lib/hooks/use-scroll.js +71 -0
- package/lib/hooks/use-settings.d.ts +3 -0
- package/lib/hooks/use-settings.js +38 -0
- package/lib/hooks/use-toggle.d.ts +2 -0
- package/lib/hooks/use-toggle.js +28 -0
- package/lib/hooks/use-transition-end.d.ts +2 -0
- package/lib/hooks/use-transition-end.js +62 -0
- package/lib/hooks/use-unique-menu.d.ts +2 -0
- package/lib/hooks/use-unique-menu.js +15 -0
- package/lib/hooks/use-widget-event.d.ts +3 -0
- package/lib/hooks/use-widget-event.js +21 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +92 -0
- package/lib/styles.d.ts +19 -0
- package/lib/styles.js +53 -0
- package/lib/utils/animations.d.ts +18 -0
- package/lib/utils/animations.js +104 -0
- package/lib/utils/browser.d.ts +12 -0
- package/lib/utils/browser.js +54 -0
- package/lib/utils/convert-to-string-attributes.d.ts +2 -0
- package/lib/utils/convert-to-string-attributes.js +23 -0
- package/lib/utils/create-empty-component.d.ts +4 -0
- package/lib/utils/create-empty-component.js +25 -0
- package/lib/utils/embedded-link-mapper.d.ts +4 -0
- package/lib/utils/embedded-link-mapper.js +62 -0
- package/lib/utils/filter-css-props.d.ts +8 -0
- package/lib/utils/filter-css-props.js +28 -0
- package/lib/utils/generic-hash-link.d.ts +8 -0
- package/lib/utils/generic-hash-link.js +70 -0
- package/lib/utils/heading-styles.d.ts +1 -0
- package/lib/utils/heading-styles.js +48 -0
- package/lib/utils/index.d.ts +12 -0
- package/lib/utils/index.js +28 -0
- package/lib/utils/process-html-string.d.ts +4 -0
- package/lib/utils/process-html-string.js +16 -0
- package/lib/utils/render-instructions.d.ts +8 -0
- package/lib/utils/render-instructions.js +19 -0
- package/lib-esm/components/anchor-link.d.ts +4 -0
- package/lib-esm/components/anchor-link.js +5 -0
- package/lib-esm/components/button.d.ts +4 -0
- package/lib-esm/components/button.js +36 -0
- package/lib-esm/components/checkbox.d.ts +7 -0
- package/lib-esm/components/checkbox.js +34 -0
- package/lib-esm/components/drawer/drawer.d.ts +21 -0
- package/lib-esm/components/drawer/drawer.js +121 -0
- package/lib-esm/components/drawer/index.d.ts +3 -0
- package/lib-esm/components/drawer/index.js +3 -0
- package/lib-esm/components/dropdown/dropdown.d.ts +9 -0
- package/lib-esm/components/dropdown/dropdown.js +127 -0
- package/lib-esm/components/dropdown/index.d.ts +4 -0
- package/lib-esm/components/dropdown/index.js +3 -0
- package/lib-esm/components/dropdown/use-position.d.ts +5 -0
- package/lib-esm/components/dropdown/use-position.js +53 -0
- package/lib-esm/components/empty.d.ts +4 -0
- package/lib-esm/components/empty.js +35 -0
- package/lib-esm/components/grid.d.ts +7 -0
- package/lib-esm/components/grid.js +36 -0
- package/lib-esm/components/html.d.ts +12 -0
- package/lib-esm/components/html.js +53 -0
- package/lib-esm/components/icon.d.ts +7 -0
- package/lib-esm/components/icon.js +30 -0
- package/lib-esm/components/index.d.ts +58 -0
- package/lib-esm/components/index.js +30 -0
- package/lib-esm/components/input.d.ts +10 -0
- package/lib-esm/components/input.js +69 -0
- package/lib-esm/components/item-list.d.ts +10 -0
- package/lib-esm/components/item-list.js +34 -0
- package/lib-esm/components/item-tree.d.ts +13 -0
- package/lib-esm/components/item-tree.js +50 -0
- package/lib-esm/components/lightbox.d.ts +6 -0
- package/lib-esm/components/lightbox.js +64 -0
- package/lib-esm/components/link.d.ts +11 -0
- package/lib-esm/components/link.js +71 -0
- package/lib-esm/components/list.d.ts +9 -0
- package/lib-esm/components/list.js +31 -0
- package/lib-esm/components/modal/confirm.d.ts +12 -0
- package/lib-esm/components/modal/confirm.js +33 -0
- package/lib-esm/components/modal/index.d.ts +4 -0
- package/lib-esm/components/modal/index.js +3 -0
- package/lib-esm/components/modal/modal.d.ts +10 -0
- package/lib-esm/components/modal/modal.js +99 -0
- package/lib-esm/components/not-found.d.ts +9 -0
- package/lib-esm/components/not-found.js +27 -0
- package/lib-esm/components/overlay.d.ts +8 -0
- package/lib-esm/components/overlay.js +45 -0
- package/lib-esm/components/paragraph.d.ts +11 -0
- package/lib-esm/components/paragraph.js +38 -0
- package/lib-esm/components/portal.d.ts +7 -0
- package/lib-esm/components/portal.js +36 -0
- package/lib-esm/components/route-link.d.ts +11 -0
- package/lib-esm/components/route-link.js +90 -0
- package/lib-esm/components/symbol-badge.d.ts +15 -0
- package/lib-esm/components/symbol-badge.js +192 -0
- package/lib-esm/components/tab-stop.d.ts +18 -0
- package/lib-esm/components/tab-stop.js +75 -0
- package/lib-esm/components/text-link.d.ts +8 -0
- package/lib-esm/components/text-link.js +34 -0
- package/lib-esm/components/text.d.ts +4 -0
- package/lib-esm/components/text.js +30 -0
- package/lib-esm/components/timestamp.d.ts +13 -0
- package/lib-esm/components/timestamp.js +33 -0
- package/lib-esm/components/tooltip.d.ts +8 -0
- package/lib-esm/components/tooltip.js +99 -0
- package/lib-esm/components/transition-component.d.ts +30 -0
- package/lib-esm/components/transition-component.js +72 -0
- package/lib-esm/components/typography.d.ts +9 -0
- package/lib-esm/components/typography.js +38 -0
- package/lib-esm/components/widget-link.d.ts +10 -0
- package/lib-esm/components/widget-link.js +88 -0
- package/lib-esm/contexts/index.d.ts +9 -0
- package/lib-esm/contexts/index.js +12 -0
- package/lib-esm/create-react-component.d.ts +11 -0
- package/lib-esm/create-react-component.js +16 -0
- package/lib-esm/hooks/index.d.ts +27 -0
- package/lib-esm/hooks/index.js +26 -0
- package/lib-esm/hooks/use-action.d.ts +4 -0
- package/lib-esm/hooks/use-action.js +14 -0
- package/lib-esm/hooks/use-children.d.ts +4 -0
- package/lib-esm/hooks/use-children.js +65 -0
- package/lib-esm/hooks/use-columns.d.ts +2 -0
- package/lib-esm/hooks/use-columns.js +4 -0
- package/lib-esm/hooks/use-component-descriptor.d.ts +2 -0
- package/lib-esm/hooks/use-component-descriptor.js +4 -0
- package/lib-esm/hooks/use-component-node.d.ts +6 -0
- package/lib-esm/hooks/use-component-node.js +35 -0
- package/lib-esm/hooks/use-component-platform.d.ts +4 -0
- package/lib-esm/hooks/use-component-platform.js +34 -0
- package/lib-esm/hooks/use-component.d.ts +3 -0
- package/lib-esm/hooks/use-component.js +52 -0
- package/lib-esm/hooks/use-container.d.ts +2 -0
- package/lib-esm/hooks/use-container.js +4 -0
- package/lib-esm/hooks/use-context.d.ts +3 -0
- package/lib-esm/hooks/use-context.js +45 -0
- package/lib-esm/hooks/use-dispatch.d.ts +3 -0
- package/lib-esm/hooks/use-dispatch.js +59 -0
- package/lib-esm/hooks/use-event-listener.d.ts +2 -0
- package/lib-esm/hooks/use-event-listener.js +19 -0
- package/lib-esm/hooks/use-events.d.ts +3 -0
- package/lib-esm/hooks/use-events.js +7 -0
- package/lib-esm/hooks/use-is-mounted.d.ts +3 -0
- package/lib-esm/hooks/use-is-mounted.js +12 -0
- package/lib-esm/hooks/use-key-press.d.ts +2 -0
- package/lib-esm/hooks/use-key-press.js +41 -0
- package/lib-esm/hooks/use-layout.d.ts +3 -0
- package/lib-esm/hooks/use-layout.js +45 -0
- package/lib-esm/hooks/use-previous.d.ts +2 -0
- package/lib-esm/hooks/use-previous.js +9 -0
- package/lib-esm/hooks/use-properties.d.ts +6 -0
- package/lib-esm/hooks/use-properties.js +7 -0
- package/lib-esm/hooks/use-render-state.d.ts +4 -0
- package/lib-esm/hooks/use-render-state.js +61 -0
- package/lib-esm/hooks/use-route-data.d.ts +4 -0
- package/lib-esm/hooks/use-route-data.js +49 -0
- package/lib-esm/hooks/use-router.d.ts +3 -0
- package/lib-esm/hooks/use-router.js +7 -0
- package/lib-esm/hooks/use-scroll.d.ts +2 -0
- package/lib-esm/hooks/use-scroll.js +66 -0
- package/lib-esm/hooks/use-settings.d.ts +3 -0
- package/lib-esm/hooks/use-settings.js +33 -0
- package/lib-esm/hooks/use-toggle.d.ts +2 -0
- package/lib-esm/hooks/use-toggle.js +26 -0
- package/lib-esm/hooks/use-transition-end.d.ts +2 -0
- package/lib-esm/hooks/use-transition-end.js +60 -0
- package/lib-esm/hooks/use-unique-menu.d.ts +2 -0
- package/lib-esm/hooks/use-unique-menu.js +10 -0
- package/lib-esm/hooks/use-widget-event.d.ts +3 -0
- package/lib-esm/hooks/use-widget-event.js +16 -0
- package/lib-esm/index.d.ts +9 -0
- package/lib-esm/index.js +7 -0
- package/lib-esm/styles.d.ts +19 -0
- package/lib-esm/styles.js +26 -0
- package/lib-esm/utils/animations.d.ts +18 -0
- package/lib-esm/utils/animations.js +101 -0
- package/lib-esm/utils/browser.d.ts +12 -0
- package/lib-esm/utils/browser.js +51 -0
- package/lib-esm/utils/convert-to-string-attributes.d.ts +2 -0
- package/lib-esm/utils/convert-to-string-attributes.js +21 -0
- package/lib-esm/utils/create-empty-component.d.ts +4 -0
- package/lib-esm/utils/create-empty-component.js +20 -0
- package/lib-esm/utils/embedded-link-mapper.d.ts +4 -0
- package/lib-esm/utils/embedded-link-mapper.js +57 -0
- package/lib-esm/utils/filter-css-props.d.ts +8 -0
- package/lib-esm/utils/filter-css-props.js +25 -0
- package/lib-esm/utils/generic-hash-link.d.ts +8 -0
- package/lib-esm/utils/generic-hash-link.js +63 -0
- package/lib-esm/utils/heading-styles.d.ts +1 -0
- package/lib-esm/utils/heading-styles.js +44 -0
- package/lib-esm/utils/index.d.ts +12 -0
- package/lib-esm/utils/index.js +10 -0
- package/lib-esm/utils/process-html-string.d.ts +4 -0
- package/lib-esm/utils/process-html-string.js +10 -0
- package/lib-esm/utils/render-instructions.d.ts +8 -0
- package/lib-esm/utils/render-instructions.js +12 -0
- package/package.json +47 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Transition } from 'react-transition-group';
|
|
3
|
+
import { transitionComposer } from '../utils';
|
|
4
|
+
/**
|
|
5
|
+
* Wrapper component for Transition from 'react-transition-group'
|
|
6
|
+
* Controls animated enter/exit transitions of a child component bu dynamically creating
|
|
7
|
+
* css that is forwarded to the child component.
|
|
8
|
+
*
|
|
9
|
+
* TODO:
|
|
10
|
+
* Extend to accept more specific transitions (TransitionStateSettings) to enable different
|
|
11
|
+
* enter and exit animations, timings and easings
|
|
12
|
+
*/
|
|
13
|
+
var TransitionComponent = function (props) {
|
|
14
|
+
var inState = props.in, _a = props.mountOnEnter, mountOnEnter = _a === void 0 ? true : _a, _b = props.unmountOnExit, unmountOnExit = _b === void 0 ? true : _b, timeout = props.timeout, children = props.children, transitions = props.transitions;
|
|
15
|
+
var generateTransitionDefinition = function () {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
if (!transitions || transitions === 'none') {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (typeof transitions === 'string') {
|
|
21
|
+
return {
|
|
22
|
+
enter: {
|
|
23
|
+
transitionKeys: transitions,
|
|
24
|
+
duration: !!timeout
|
|
25
|
+
? typeof timeout === 'number'
|
|
26
|
+
? timeout
|
|
27
|
+
: timeout.enter
|
|
28
|
+
: 200,
|
|
29
|
+
easing: 'ease-in',
|
|
30
|
+
},
|
|
31
|
+
exit: {
|
|
32
|
+
transitionKeys: transitions,
|
|
33
|
+
duration: !!timeout
|
|
34
|
+
? typeof timeout === 'number'
|
|
35
|
+
? timeout
|
|
36
|
+
: timeout.exit
|
|
37
|
+
: 200,
|
|
38
|
+
easing: 'ease-out',
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
if (typeof transitions === 'object') {
|
|
43
|
+
var enter = transitions.enter, exit = transitions.exit;
|
|
44
|
+
return {
|
|
45
|
+
enter: {
|
|
46
|
+
transitionKeys: (_a = transitions.enter) === null || _a === void 0 ? void 0 : _a.type,
|
|
47
|
+
duration: !!timeout
|
|
48
|
+
? typeof timeout === 'number'
|
|
49
|
+
? timeout
|
|
50
|
+
: timeout.enter
|
|
51
|
+
: 200,
|
|
52
|
+
easing: !!enter.easing ? enter.easing : 'ease-in',
|
|
53
|
+
},
|
|
54
|
+
exit: {
|
|
55
|
+
transitionKeys: (_b = transitions.enter) === null || _b === void 0 ? void 0 : _b.type,
|
|
56
|
+
duration: !!timeout
|
|
57
|
+
? typeof timeout === 'number'
|
|
58
|
+
? timeout
|
|
59
|
+
: timeout.enter
|
|
60
|
+
: 200,
|
|
61
|
+
easing: !!exit.easing ? exit.easing : 'ease-out',
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var def = generateTransitionDefinition();
|
|
67
|
+
return (React.createElement(Transition, { timeout: {
|
|
68
|
+
enter: (def && def.enter.duration) || 0,
|
|
69
|
+
exit: (def && def.exit.duration) || 0,
|
|
70
|
+
}, in: inState, appear: true, mountOnEnter: mountOnEnter, unmountOnExit: unmountOnExit, onEnter: function (node) { return node.clientHeight; } }, function (state) { return children && children(state, def && transitionComposer.compose(state, def)); }));
|
|
71
|
+
};
|
|
72
|
+
export default TransitionComponent;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare type TypographyVariant = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p' | 'span';
|
|
3
|
+
export declare type Props = {
|
|
4
|
+
variant: TypographyVariant;
|
|
5
|
+
component?: React.ElementType;
|
|
6
|
+
className?: string;
|
|
7
|
+
};
|
|
8
|
+
declare const Typography: React.FC<Props>;
|
|
9
|
+
export default Typography;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
2
|
+
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
3
|
+
return cooked;
|
|
4
|
+
};
|
|
5
|
+
var __assign = (this && this.__assign) || function () {
|
|
6
|
+
__assign = Object.assign || function(t) {
|
|
7
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
8
|
+
s = arguments[i];
|
|
9
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
10
|
+
t[p] = s[p];
|
|
11
|
+
}
|
|
12
|
+
return t;
|
|
13
|
+
};
|
|
14
|
+
return __assign.apply(this, arguments);
|
|
15
|
+
};
|
|
16
|
+
import React from 'react';
|
|
17
|
+
import styled from 'styled-components';
|
|
18
|
+
import { useContext } from '../hooks';
|
|
19
|
+
var defaultVariantMapping = {
|
|
20
|
+
h1: 'h1',
|
|
21
|
+
h2: 'h2',
|
|
22
|
+
h3: 'h3',
|
|
23
|
+
h4: 'h4',
|
|
24
|
+
h5: 'h5',
|
|
25
|
+
h6: 'h6',
|
|
26
|
+
p: 'p',
|
|
27
|
+
span: 'span',
|
|
28
|
+
};
|
|
29
|
+
var Typography = function (_a) {
|
|
30
|
+
var variant = _a.variant, component = _a.component, className = _a.className, children = _a.children;
|
|
31
|
+
var _b = useContext().typographyVariantMapping, typographyVariantMapping = _b === void 0 ? {} : _b;
|
|
32
|
+
var variantMapping = __assign(__assign({}, defaultVariantMapping), typographyVariantMapping);
|
|
33
|
+
var Component = component || variantMapping[variant] || 'span';
|
|
34
|
+
return (React.createElement(Base, { className: className, as: Component }, children));
|
|
35
|
+
};
|
|
36
|
+
var Base = styled.span(templateObject_1 || (templateObject_1 = __makeTemplateObject([""], [""])));
|
|
37
|
+
export default Typography;
|
|
38
|
+
var templateObject_1;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Props as LinkProps } from './link';
|
|
3
|
+
export declare type Props = Merge<LinkProps, {
|
|
4
|
+
widgetName: string;
|
|
5
|
+
activationOptions?: {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
};
|
|
8
|
+
}>;
|
|
9
|
+
declare const _default: React.ForwardRefExoticComponent<Pick<Props, "to" | "key" | keyof React.AnchorHTMLAttributes<HTMLAnchorElement> | "disabled" | "routeName" | "params" | "widgetName" | "activationOptions"> & React.RefAttributes<HTMLAnchorElement>>;
|
|
10
|
+
export default _default;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
import { WidgetRenderState } from '@telia-ace/widget-core';
|
|
24
|
+
import { appendClassNames } from '@telia-ace/widget-utilities';
|
|
25
|
+
import { WidgetState } from '@webprovisions/platform';
|
|
26
|
+
import React, { forwardRef, useEffect } from 'react';
|
|
27
|
+
import { useContainer } from '../hooks';
|
|
28
|
+
import Link from './link';
|
|
29
|
+
export default forwardRef(function (_a, ref) {
|
|
30
|
+
var className = _a.className, children = _a.children, _b = _a.onClick, onClick = _b === void 0 ? function () { } : _b, widgetName = _a.widgetName, activationOptions = _a.activationOptions, other = __rest(_a, ["className", "children", "onClick", "widgetName", "activationOptions"]);
|
|
31
|
+
var container = useContainer();
|
|
32
|
+
var getWidget = function () {
|
|
33
|
+
var implementation = container.get('$widget').implementation;
|
|
34
|
+
return implementation.widgets.get(widgetName);
|
|
35
|
+
};
|
|
36
|
+
useEffect(function () {
|
|
37
|
+
var widget = getWidget();
|
|
38
|
+
widget === null || widget === void 0 ? void 0 : widget.activate(activationOptions).then(function () { return widget.invoke('attach'); });
|
|
39
|
+
return function () {
|
|
40
|
+
widget === null || widget === void 0 ? void 0 : widget.deactivate();
|
|
41
|
+
};
|
|
42
|
+
}, [widgetName]);
|
|
43
|
+
var openWidget = function (e) {
|
|
44
|
+
var widget = getWidget();
|
|
45
|
+
var target = e.currentTarget;
|
|
46
|
+
if (widget) {
|
|
47
|
+
var toggle = function () {
|
|
48
|
+
widget
|
|
49
|
+
.invoke('renderState')
|
|
50
|
+
.then(function (renderState) {
|
|
51
|
+
return renderState === WidgetRenderState.open
|
|
52
|
+
? widget.invoke('close')
|
|
53
|
+
: widget.invoke('open');
|
|
54
|
+
})
|
|
55
|
+
.then(function () {
|
|
56
|
+
widget.events.subscribeOnce('widget:area-rendered', function (event, data) {
|
|
57
|
+
var widgetDOMElement = container.get('widgetDOMElement');
|
|
58
|
+
if (widgetDOMElement) {
|
|
59
|
+
widget.events.dispatch('widget:modal-opened', {
|
|
60
|
+
name: widget.name,
|
|
61
|
+
ref: target,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
if (widget.state === WidgetState.Deactivated) {
|
|
68
|
+
widget
|
|
69
|
+
.activate(activationOptions)
|
|
70
|
+
.then(function () { return widget.invoke('attach'); })
|
|
71
|
+
.then(toggle);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
toggle();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
var onEnter = function (e) {
|
|
79
|
+
if (e.key === 'Enter') {
|
|
80
|
+
e.preventDefault();
|
|
81
|
+
openWidget(e);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
return (React.createElement(Link, __assign({ className: appendClassNames(className, 'humany-widget-link'), onKeyDown: onEnter, onClick: function (e) {
|
|
85
|
+
onClick(e);
|
|
86
|
+
openWidget(e);
|
|
87
|
+
} }, other, { ref: ref }), children));
|
|
88
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ComponentDescriptor, ComponentNodeProperties } from '@telia-ace/widget-core';
|
|
3
|
+
import { RoutingService } from '@telia-ace/widget-routing';
|
|
4
|
+
import { Container } from '@webprovisions/platform';
|
|
5
|
+
export declare const ContainerContext: import("react").Context<Container>;
|
|
6
|
+
export declare const ColumnContext: import("react").Context<number>;
|
|
7
|
+
export declare const ComponentNodeContext: import("react").Context<ComponentDescriptor>;
|
|
8
|
+
export declare const ComponentPropertyContext: import("react").Context<ComponentNodeProperties>;
|
|
9
|
+
export declare const RoutingContext: import("react").Context<RoutingService | null>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Container } from '@webprovisions/platform';
|
|
2
|
+
import { createContext } from 'react';
|
|
3
|
+
export var ContainerContext = createContext(new Container());
|
|
4
|
+
export var ColumnContext = createContext(1);
|
|
5
|
+
export var ComponentNodeContext = createContext({
|
|
6
|
+
id: '',
|
|
7
|
+
type: '',
|
|
8
|
+
name: '',
|
|
9
|
+
branch: '',
|
|
10
|
+
});
|
|
11
|
+
export var ComponentPropertyContext = createContext({});
|
|
12
|
+
export var RoutingContext = createContext(null);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ExtendComponentHandler, ExtendComponentOptions, ReactComponent } from '@telia-ace/widget-core';
|
|
2
|
+
import { Container } from '@webprovisions/platform';
|
|
3
|
+
/**
|
|
4
|
+
* Registers a React component on the component platform.
|
|
5
|
+
* @param container Container to register the component on.
|
|
6
|
+
* @param type Type name to resolve the component from configuration.
|
|
7
|
+
* @param reactComponent Promise resolving to the React component for rendering.
|
|
8
|
+
* @param fn Handler for controlling the component.
|
|
9
|
+
*/
|
|
10
|
+
declare const createReactComponent: (container: Container, type: string, reactComponent: ReactComponent, fn?: ExtendComponentHandler | undefined, options?: ExtendComponentOptions | undefined) => Promise<void>;
|
|
11
|
+
export default createReactComponent;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { extendComponent, } from '@telia-ace/widget-core';
|
|
2
|
+
import { lazy } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Registers a React component on the component platform.
|
|
5
|
+
* @param container Container to register the component on.
|
|
6
|
+
* @param type Type name to resolve the component from configuration.
|
|
7
|
+
* @param reactComponent Promise resolving to the React component for rendering.
|
|
8
|
+
* @param fn Handler for controlling the component.
|
|
9
|
+
*/
|
|
10
|
+
var createReactComponent = function (container, type, reactComponent, fn, options) {
|
|
11
|
+
return container.getAsync('componentResolver').then(function (componentResolver) {
|
|
12
|
+
componentResolver.registerComponent(type, lazy(function () { return reactComponent; }));
|
|
13
|
+
return extendComponent(container, type, fn || (function () { }), type, options);
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
export default createReactComponent;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export { default as useAction } from './use-action';
|
|
2
|
+
export { default as useChildren } from './use-children';
|
|
3
|
+
export { default as useColumns } from './use-columns';
|
|
4
|
+
export { default as useComponent } from './use-component';
|
|
5
|
+
export { default as useComponentDescriptor } from './use-component-descriptor';
|
|
6
|
+
export { default as useComponentNode } from './use-component-node';
|
|
7
|
+
export { default as useComponentPlatform } from './use-component-platform';
|
|
8
|
+
export { default as useContainer } from './use-container';
|
|
9
|
+
export { default as useContext } from './use-context';
|
|
10
|
+
export { default as useDispatch } from './use-dispatch';
|
|
11
|
+
export type { DispatchAction } from './use-dispatch';
|
|
12
|
+
export { default as useEventListener } from './use-event-listener';
|
|
13
|
+
export { default as useEvents } from './use-events';
|
|
14
|
+
export { default as useIsMounted } from './use-is-mounted';
|
|
15
|
+
export { default as useKeyPress } from './use-key-press';
|
|
16
|
+
export { default as useLayout } from './use-layout';
|
|
17
|
+
export { default as usePrevious } from './use-previous';
|
|
18
|
+
export { default as useProperties } from './use-properties';
|
|
19
|
+
export { default as useRenderState } from './use-render-state';
|
|
20
|
+
export { default as useRouteData } from './use-route-data';
|
|
21
|
+
export { default as useRouter } from './use-router';
|
|
22
|
+
export { default as useScroll } from './use-scroll';
|
|
23
|
+
export { default as useSettings } from './use-settings';
|
|
24
|
+
export { default as useToggle } from './use-toggle';
|
|
25
|
+
export { default as useTransitionEnd } from './use-transition-end';
|
|
26
|
+
export { default as useUniqueMenu } from './use-unique-menu';
|
|
27
|
+
export { default as useWidgetEvent } from './use-widget-event';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export { default as useAction } from './use-action';
|
|
2
|
+
export { default as useChildren } from './use-children';
|
|
3
|
+
export { default as useColumns } from './use-columns';
|
|
4
|
+
export { default as useComponent } from './use-component';
|
|
5
|
+
export { default as useComponentDescriptor } from './use-component-descriptor';
|
|
6
|
+
export { default as useComponentNode } from './use-component-node';
|
|
7
|
+
export { default as useComponentPlatform } from './use-component-platform';
|
|
8
|
+
export { default as useContainer } from './use-container';
|
|
9
|
+
export { default as useContext } from './use-context';
|
|
10
|
+
export { default as useDispatch } from './use-dispatch';
|
|
11
|
+
export { default as useEventListener } from './use-event-listener';
|
|
12
|
+
export { default as useEvents } from './use-events';
|
|
13
|
+
export { default as useIsMounted } from './use-is-mounted';
|
|
14
|
+
export { default as useKeyPress } from './use-key-press';
|
|
15
|
+
export { default as useLayout } from './use-layout';
|
|
16
|
+
export { default as usePrevious } from './use-previous';
|
|
17
|
+
export { default as useProperties } from './use-properties';
|
|
18
|
+
export { default as useRenderState } from './use-render-state';
|
|
19
|
+
export { default as useRouteData } from './use-route-data';
|
|
20
|
+
export { default as useRouter } from './use-router';
|
|
21
|
+
export { default as useScroll } from './use-scroll';
|
|
22
|
+
export { default as useSettings } from './use-settings';
|
|
23
|
+
export { default as useToggle } from './use-toggle';
|
|
24
|
+
export { default as useTransitionEnd } from './use-transition-end';
|
|
25
|
+
export { default as useUniqueMenu } from './use-unique-menu';
|
|
26
|
+
export { default as useWidgetEvent } from './use-widget-event';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import useComponentDescriptor from './use-component-descriptor';
|
|
2
|
+
import useContainer from './use-container';
|
|
3
|
+
export var useAction = function (passedOrigin, passedContainer) {
|
|
4
|
+
var origin = useComponentDescriptor().id;
|
|
5
|
+
var container = useContainer();
|
|
6
|
+
return function (action, value) {
|
|
7
|
+
(passedContainer || container)
|
|
8
|
+
.getAsync('actionResolver')
|
|
9
|
+
.then(function (resolver) {
|
|
10
|
+
resolver.action(passedOrigin || origin, action, value);
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export default useAction;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
2
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
+
if (!m) return o;
|
|
4
|
+
var i = m.call(o), r, ar = [], e;
|
|
5
|
+
try {
|
|
6
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
7
|
+
}
|
|
8
|
+
catch (error) { e = { error: error }; }
|
|
9
|
+
finally {
|
|
10
|
+
try {
|
|
11
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
12
|
+
}
|
|
13
|
+
finally { if (e) throw e.error; }
|
|
14
|
+
}
|
|
15
|
+
return ar;
|
|
16
|
+
};
|
|
17
|
+
import { asDescriptor, createEventSubscriber, } from '@telia-ace/widget-core';
|
|
18
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
19
|
+
import useComponentNode from './use-component-node';
|
|
20
|
+
import useComponentPlatform from './use-component-platform';
|
|
21
|
+
import useIsMounted from './use-is-mounted';
|
|
22
|
+
var useChildren = function () {
|
|
23
|
+
var node = useComponentNode();
|
|
24
|
+
var components = useComponentPlatform();
|
|
25
|
+
var _a = __read(useState([]), 2), children = _a[0], setChildren = _a[1];
|
|
26
|
+
var isMounted = useIsMounted();
|
|
27
|
+
var updateChildren = useCallback(function (node) {
|
|
28
|
+
if (components && isMounted.current) {
|
|
29
|
+
var branch = components.getBranch(node);
|
|
30
|
+
var children_1 = node.getChildren(branch).map(function (child) { return asDescriptor(child); });
|
|
31
|
+
setChildren(children_1);
|
|
32
|
+
}
|
|
33
|
+
}, [isMounted, components, setChildren]);
|
|
34
|
+
useEffect(function () {
|
|
35
|
+
if (node) {
|
|
36
|
+
updateChildren(node);
|
|
37
|
+
}
|
|
38
|
+
}, [node, components]);
|
|
39
|
+
useEffect(function () {
|
|
40
|
+
if (components) {
|
|
41
|
+
var _a = __read(createEventSubscriber(components.events), 2), subscribe = _a[0], unsubscribe_1 = _a[1];
|
|
42
|
+
subscribe('components:set-layout', function (event, data) {
|
|
43
|
+
if (node === data.node.parent || data.node.parent === components.nodes.root) {
|
|
44
|
+
updateChildren(data.node.parent);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
subscribe('components:node-appended', function (event, data) {
|
|
48
|
+
if (node === data.node.parent || data.node.parent === components.nodes.root) {
|
|
49
|
+
updateChildren(data.node.parent);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
subscribe('components:node-removed', function (event, _a) {
|
|
53
|
+
var parentNode = _a.parentNode;
|
|
54
|
+
if (parentNode === node || parentNode === components.nodes.root) {
|
|
55
|
+
updateChildren(parentNode);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return function () {
|
|
59
|
+
unsubscribe_1();
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}, [node, components, updateChildren]);
|
|
63
|
+
return children;
|
|
64
|
+
};
|
|
65
|
+
export default useChildren;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
2
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
+
if (!m) return o;
|
|
4
|
+
var i = m.call(o), r, ar = [], e;
|
|
5
|
+
try {
|
|
6
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
7
|
+
}
|
|
8
|
+
catch (error) { e = { error: error }; }
|
|
9
|
+
finally {
|
|
10
|
+
try {
|
|
11
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
12
|
+
}
|
|
13
|
+
finally { if (e) throw e.error; }
|
|
14
|
+
}
|
|
15
|
+
return ar;
|
|
16
|
+
};
|
|
17
|
+
import { useContext, useEffect, useState } from 'react';
|
|
18
|
+
import { useComponentPlatform } from '.';
|
|
19
|
+
import { ComponentNodeContext } from '../contexts';
|
|
20
|
+
/**
|
|
21
|
+
* Provides the `ComponentNode` for the current context.
|
|
22
|
+
*/
|
|
23
|
+
var useComponentNode = function (id) {
|
|
24
|
+
var descriptor = useContext(ComponentNodeContext);
|
|
25
|
+
var components = useComponentPlatform();
|
|
26
|
+
var _a = __read(useState(), 2), node = _a[0], setNode = _a[1];
|
|
27
|
+
useEffect(function () {
|
|
28
|
+
if ((id || descriptor.id) && components) {
|
|
29
|
+
var node_1 = components.nodes.get(id || descriptor.id);
|
|
30
|
+
setNode(node_1);
|
|
31
|
+
}
|
|
32
|
+
}, [id, descriptor.id, components]);
|
|
33
|
+
return node;
|
|
34
|
+
};
|
|
35
|
+
export default useComponentNode;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
2
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
+
if (!m) return o;
|
|
4
|
+
var i = m.call(o), r, ar = [], e;
|
|
5
|
+
try {
|
|
6
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
7
|
+
}
|
|
8
|
+
catch (error) { e = { error: error }; }
|
|
9
|
+
finally {
|
|
10
|
+
try {
|
|
11
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
12
|
+
}
|
|
13
|
+
finally { if (e) throw e.error; }
|
|
14
|
+
}
|
|
15
|
+
return ar;
|
|
16
|
+
};
|
|
17
|
+
import { ComponentPlatform } from '@telia-ace/widget-core';
|
|
18
|
+
import { useEffect, useState } from 'react';
|
|
19
|
+
import useContainer from './use-container';
|
|
20
|
+
import useIsMounted from './use-is-mounted';
|
|
21
|
+
var useComponentPlatform = function (passedContainer) {
|
|
22
|
+
var container = useContainer();
|
|
23
|
+
var _a = __read(useState(null), 2), componentPlatform = _a[0], setComponentPlatform = _a[1];
|
|
24
|
+
var isMounted = useIsMounted();
|
|
25
|
+
useEffect(function () {
|
|
26
|
+
ComponentPlatform.getInstance(passedContainer || container).then(function (platform) {
|
|
27
|
+
if (isMounted.current) {
|
|
28
|
+
setComponentPlatform(platform);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}, [isMounted]);
|
|
32
|
+
return componentPlatform;
|
|
33
|
+
};
|
|
34
|
+
export default useComponentPlatform;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
2
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
+
if (!m) return o;
|
|
4
|
+
var i = m.call(o), r, ar = [], e;
|
|
5
|
+
try {
|
|
6
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
7
|
+
}
|
|
8
|
+
catch (error) { e = { error: error }; }
|
|
9
|
+
finally {
|
|
10
|
+
try {
|
|
11
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
12
|
+
}
|
|
13
|
+
finally { if (e) throw e.error; }
|
|
14
|
+
}
|
|
15
|
+
return ar;
|
|
16
|
+
};
|
|
17
|
+
import { useEffect, useState } from 'react';
|
|
18
|
+
import useComponentDescriptor from './use-component-descriptor';
|
|
19
|
+
import useContainer from './use-container';
|
|
20
|
+
import useIsMounted from './use-is-mounted';
|
|
21
|
+
var useComponent = function (passedType, passedContainer) {
|
|
22
|
+
var descriptor = useComponentDescriptor();
|
|
23
|
+
var container = useContainer();
|
|
24
|
+
var _a = __read(useState(undefined), 2), component = _a[0], setComponent = _a[1];
|
|
25
|
+
var isMounted = useIsMounted();
|
|
26
|
+
var type = passedType || descriptor.type || '';
|
|
27
|
+
useEffect(function () {
|
|
28
|
+
if (type) {
|
|
29
|
+
var unsubscribe_1;
|
|
30
|
+
(passedContainer || container)
|
|
31
|
+
.getAsync('componentResolver')
|
|
32
|
+
.then(function (resolver) {
|
|
33
|
+
if (isMounted.current) {
|
|
34
|
+
var component_1 = resolver.getComponent(type);
|
|
35
|
+
setComponent(component_1);
|
|
36
|
+
}
|
|
37
|
+
unsubscribe_1 = resolver.registerResolver(type, function (component) {
|
|
38
|
+
if (isMounted.current) {
|
|
39
|
+
setComponent(component);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
return function () {
|
|
44
|
+
if (unsubscribe_1) {
|
|
45
|
+
unsubscribe_1();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}, [isMounted, type, passedContainer, container]);
|
|
50
|
+
return component;
|
|
51
|
+
};
|
|
52
|
+
export default useComponent;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
2
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
+
if (!m) return o;
|
|
4
|
+
var i = m.call(o), r, ar = [], e;
|
|
5
|
+
try {
|
|
6
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
7
|
+
}
|
|
8
|
+
catch (error) { e = { error: error }; }
|
|
9
|
+
finally {
|
|
10
|
+
try {
|
|
11
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
12
|
+
}
|
|
13
|
+
finally { if (e) throw e.error; }
|
|
14
|
+
}
|
|
15
|
+
return ar;
|
|
16
|
+
};
|
|
17
|
+
import { useEffect, useState } from 'react';
|
|
18
|
+
import useComponentNode from './use-component-node';
|
|
19
|
+
import useComponentPlatform from './use-component-platform';
|
|
20
|
+
import useIsMounted from './use-is-mounted';
|
|
21
|
+
var useContext = function (id) {
|
|
22
|
+
var node = useComponentNode(id);
|
|
23
|
+
var components = useComponentPlatform();
|
|
24
|
+
var _a = __read(useState({}), 2), context = _a[0], setContext = _a[1];
|
|
25
|
+
var isMounted = useIsMounted();
|
|
26
|
+
useEffect(function () {
|
|
27
|
+
if (node && isMounted.current) {
|
|
28
|
+
setContext(node.attributes.context);
|
|
29
|
+
}
|
|
30
|
+
}, [isMounted, node]);
|
|
31
|
+
useEffect(function () {
|
|
32
|
+
if (components) {
|
|
33
|
+
var unsubscribe_1 = components.events.subscribe('components:context-changed', function (event, data) {
|
|
34
|
+
if (node === data.node && isMounted.current) {
|
|
35
|
+
setContext(data.node.attributes.context);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return function () {
|
|
39
|
+
unsubscribe_1();
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}, [isMounted, components]);
|
|
43
|
+
return context;
|
|
44
|
+
};
|
|
45
|
+
export default useContext;
|