@integry/sdk 4.5.2 → 4.5.4
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/.vscode/launch.json +2 -2
- package/THIRD_PARTY_LICENSES +0 -37
- package/dist/esm/index.csm.d.ts +12 -2
- package/dist/esm/index.csm.js +7262 -1
- package/dist/umd/index.umd.d.ts +9 -1
- package/dist/umd/index.umd.js +7262 -1
- package/jest.config.cjs +10 -0
- package/package.json +10 -4
- package/src/components/AddTagButton/index.ts +23 -0
- package/src/components/BasicSelect/index.ts +114 -0
- package/src/components/BasicSelect/styles.module.scss +44 -0
- package/src/components/Button/index.ts +94 -0
- package/src/components/Button/styles.module.scss +152 -0
- package/src/components/CheckboxGroup/Checkbox.ts +104 -0
- package/src/components/CheckboxGroup/index.ts +190 -0
- package/src/components/CheckboxGroup/styles.module.scss +63 -0
- package/src/components/CollapsedMenu/index.ts +101 -0
- package/src/components/CollapsedMenu/styles.module.scss +46 -0
- package/src/components/ConfigureFieldWrapper/index.ts +85 -0
- package/src/components/ConfigureFieldWrapper/styles.module.scss +57 -0
- package/src/components/EditableText/index.ts +121 -0
- package/src/components/EditableText/styles.module.scss +38 -0
- package/src/components/EditableTextArea/index.ts +143 -0
- package/src/components/EditableTextArea/styles.module.scss +91 -0
- package/src/components/ErrorMessage/index.ts +16 -0
- package/src/components/ErrorMessage/styles.module.scss +19 -0
- package/src/components/ErrorPage/index.ts +42 -0
- package/src/components/ErrorPage/styles.module.scss +26 -0
- package/src/components/Footer/index.ts +41 -0
- package/src/components/Footer/styles.module.scss +40 -0
- package/src/components/HTMLContent/index.tsx +275 -0
- package/src/components/HTMLContent/styles.module.scss +3 -0
- package/src/components/InfoBox/index.ts +48 -0
- package/src/components/InfoBox/styles.module.scss +21 -0
- package/src/components/Input/BaseInput/index.ts +170 -0
- package/src/components/Input/BaseInput/styles.module.scss +94 -0
- package/src/components/Input/DateInput/index.ts +103 -0
- package/src/components/Input/DateInput/styles.module.scss +50 -0
- package/src/components/Input/Input/index.ts +206 -0
- package/src/components/Input/Input/styles.module.scss +14 -0
- package/src/components/Input/PasswordInput/index.ts +164 -0
- package/src/components/Input/PasswordInput/styles.module.scss +37 -0
- package/src/components/Input/index.ts +7 -0
- package/src/components/Label/index.ts +61 -0
- package/src/components/Label/styles.module.scss +41 -0
- package/src/components/LargeLoader/index.ts +25 -0
- package/src/components/LargeLoader/styles.module.scss +16 -0
- package/src/components/Listbox/ListBoxItem.ts +57 -0
- package/src/components/Listbox/index.ts +479 -0
- package/src/components/Listbox/styles.module.scss +197 -0
- package/src/components/Loader/index.ts +25 -0
- package/src/components/Loader/styles.module.scss +16 -0
- package/src/components/MediaGallery/MediaGalleryModal.ts +82 -0
- package/src/components/MediaGallery/MediaSlider.ts +76 -0
- package/src/components/MediaGallery/index.ts +92 -0
- package/src/components/MediaGallery/styles.module.scss +156 -0
- package/src/components/MediaUpload/index.ts +233 -0
- package/src/components/MediaUpload/styles.module.scss +118 -0
- package/src/components/Modal/index.ts +87 -0
- package/src/components/Modal/styles.module.scss +441 -0
- package/src/components/MultipurposeField/Dropdown/ListBoxItem.tsx +58 -0
- package/src/components/MultipurposeField/Dropdown/index.tsx +981 -0
- package/src/components/MultipurposeField/Dropdown/styles.module.scss +208 -0
- package/src/components/MultipurposeField/TagMenu/index.ts +384 -0
- package/src/components/MultipurposeField/TagMenu/styles.module.scss +136 -0
- package/src/components/MultipurposeField/TagOptions/index.tsx +83 -0
- package/src/components/MultipurposeField/TagOptions/styles.module.scss +95 -0
- package/src/components/MultipurposeField/index.tsx +687 -0
- package/src/components/MultipurposeField/styles.module.scss +56 -0
- package/src/components/NewModal/index.ts +69 -0
- package/src/components/NewModal/styles.module.scss +70 -0
- package/src/components/OverflowTooltip/index.tsx +59 -0
- package/src/components/PopUp/ConfirmationPopUp/index.ts +58 -0
- package/src/components/PopUp/ConfirmationPopUp/styles.module.scss +49 -0
- package/src/components/PopUp/SuccessPopUp/index.ts +62 -0
- package/src/components/PopUp/SuccessPopUp/styles.module.scss +38 -0
- package/src/components/RadioGroup/Radio.ts +129 -0
- package/src/components/RadioGroup/index.ts +169 -0
- package/src/components/RadioGroup/styles.module.scss +81 -0
- package/src/components/Search/index.ts +69 -0
- package/src/components/Search/styles.module.scss +149 -0
- package/src/components/TabBar/Tab.ts +33 -0
- package/src/components/TabBar/index.ts +64 -0
- package/src/components/TabBar/styles.module.scss +43 -0
- package/src/components/Tag/index.ts +29 -0
- package/src/components/Tag/styles.module.scss +57 -0
- package/src/components/TextArea/index.ts +172 -0
- package/src/components/TextArea/styles.module.scss +70 -0
- package/src/components/TextContent/index.tsx +128 -0
- package/src/components/TextContent/styles.module.scss +6 -0
- package/src/components/ThreeDotLoader/index.ts +39 -0
- package/src/components/ThreeDotLoader/styles.module.scss +41 -0
- package/src/components/TimeInput/index.ts +129 -0
- package/src/components/TimeInput/styles.module.scss +16 -0
- package/src/components/Toggle/index.ts +34 -0
- package/src/components/Toggle/styles.module.scss +56 -0
- package/src/components/Toggle-v2/index.ts +40 -0
- package/src/components/Toggle-v2/styles.module.scss +86 -0
- package/src/components/Tooltip/index.ts +271 -0
- package/src/components/Tooltip/styles.module.scss +105 -0
- package/src/components/form/ObjectField/index.ts +364 -0
- package/src/components/form/ObjectField/styles.module.scss +103 -0
- package/src/components/form/index.ts +3 -0
- package/src/contexts/AppContext.ts +12 -0
- package/src/declaration.d.ts +7 -0
- package/src/extensions/HMAC.ts +25 -0
- package/src/extensions/IntegryAPIError.ts +19 -0
- package/src/features/common/AccountDropdown/index.ts +291 -0
- package/src/features/common/AccountDropdown/styles.module.scss +19 -0
- package/src/features/common/ActionForm/index.ts +1818 -0
- package/src/features/common/ActionForm/styles.module.scss +23 -0
- package/src/features/common/AppCard/index.ts +207 -0
- package/src/features/common/AppCard/styles.module.scss +117 -0
- package/src/features/common/AppCardCompact/index.ts +189 -0
- package/src/features/common/AppCardCompact/styles.module.scss +141 -0
- package/src/features/common/AuthSelector/index.ts +537 -0
- package/src/features/common/AuthSelector/styles.module.scss +161 -0
- package/src/features/common/AuthSelectorCompact/index.ts +706 -0
- package/src/features/common/AuthSelectorCompact/styles.module.scss +219 -0
- package/src/features/common/AuthSelectorDropdown/index.ts +704 -0
- package/src/features/common/AuthSelectorDropdown/styles.module.scss +361 -0
- package/src/features/common/DynamicField/index.ts +229 -0
- package/src/features/common/DynamicField/styles.module.scss +67 -0
- package/src/features/common/DynamicTypedField/index.ts +217 -0
- package/src/features/common/DynamicTypedField/styles.module.scss +67 -0
- package/src/features/common/FunctionForm/index.ts +862 -0
- package/src/features/common/FunctionForm/styles.module.scss +163 -0
- package/src/features/common/MappingUI/index.ts +649 -0
- package/src/features/common/MappingUI/styles.module.scss +121 -0
- package/src/features/common/MarketplaceAppCard/index.ts +279 -0
- package/src/features/common/MarketplaceAppCard/styles.module.scss +231 -0
- package/src/features/common/MarketplaceAppCardCompact/index.ts +283 -0
- package/src/features/common/MarketplaceAppCardCompact/styles.module.scss +255 -0
- package/src/features/common/NewMappingUI/index.ts +515 -0
- package/src/features/common/NewMappingUI/styles.module.scss +113 -0
- package/src/features/common/RequestAppWidget/RequestAppModal/index.ts +67 -0
- package/src/features/common/RequestAppWidget/RequestAppModal/styles.module.scss +23 -0
- package/src/features/common/RequestAppWidget/index.ts +48 -0
- package/src/features/common/RequestAppWidget/request-app-form.ts +89 -0
- package/src/features/common/RequestAppWidget/styles.module.scss +43 -0
- package/src/features/common/SectionField/index.ts +272 -0
- package/src/features/common/SectionField/styles.module.scss +67 -0
- package/src/features/common/Step/index.ts +827 -0
- package/src/features/common/Step/styles.module.scss +12 -0
- package/src/features/common/StepNavigation/CollapsedSteps.ts +125 -0
- package/src/features/common/StepNavigation/NavItem.ts +111 -0
- package/src/features/common/StepNavigation/index.ts +257 -0
- package/src/features/common/StepNavigation/styles.module.scss +117 -0
- package/src/features/common/Steps/index.ts +1139 -0
- package/src/features/common/Steps/styles.module.scss +314 -0
- package/src/features/containers/AppFlowContainer/AppFlowListing/compactStyles.module.scss +383 -0
- package/src/features/containers/AppFlowContainer/AppFlowListing/flow-instance.tsx +367 -0
- package/src/features/containers/AppFlowContainer/AppFlowListing/flowCard.tsx +194 -0
- package/src/features/containers/AppFlowContainer/AppFlowListing/flowCardCompact.tsx +389 -0
- package/src/features/containers/AppFlowContainer/AppFlowListing/flowInstanceCompact.tsx +577 -0
- package/src/features/containers/AppFlowContainer/AppFlowListing/index.tsx +83 -0
- package/src/features/containers/AppFlowContainer/AppFlowListing/styles.module.scss +212 -0
- package/src/features/containers/AppFlowContainer/AppFlowWrap/app-page-loader.tsx +45 -0
- package/src/features/containers/AppFlowContainer/AppFlowWrap/index.tsx +1081 -0
- package/src/features/containers/AppFlowContainer/AppFlowWrap/styles.module.scss +452 -0
- package/src/features/containers/AppFlowContainer/Authentication/index.ts +610 -0
- package/src/features/containers/AppFlowContainer/Authentication/styles.module.scss +468 -0
- package/src/features/containers/AppFlowContainer/index.ts +114 -0
- package/src/features/containers/AppPageContainer/AppPage/index.tsx +262 -0
- package/src/features/containers/AppPageContainer/AppPage/styles.module.scss +120 -0
- package/src/features/containers/AppPageContainer/IntegrationCard/index.ts +165 -0
- package/src/features/containers/AppPageContainer/IntegrationCard/styles.module.scss +81 -0
- package/src/features/containers/AppPageContainer/index.tsx +93 -0
- package/src/features/containers/AppPageContainer/styles.module.scss +0 -0
- package/src/features/containers/AppsForFlows/index.ts +161 -0
- package/src/features/containers/AppsForFlows/styles.module.scss +280 -0
- package/src/features/containers/AppsForFlowsCompact/index.ts +161 -0
- package/src/features/containers/AppsForFlowsCompact/styles.module.scss +279 -0
- package/src/features/containers/AuthSetupContainer/AppSelection.ts +73 -0
- package/src/features/containers/AuthSetupContainer/AuthTypeSelection.ts +67 -0
- package/src/features/containers/AuthSetupContainer/Footer.ts +32 -0
- package/src/features/containers/AuthSetupContainer/Header.ts +39 -0
- package/src/features/containers/AuthSetupContainer/PostAdditionPopup.ts +27 -0
- package/src/features/containers/AuthSetupContainer/index.ts +349 -0
- package/src/features/containers/AuthSetupContainer/styles.module.scss +229 -0
- package/src/features/containers/FlowSetupContainer/index.ts +390 -0
- package/src/features/containers/FlowSetupContainer/styles.module.scss +18 -0
- package/src/features/containers/MarkeplaceApps/index.ts +574 -0
- package/src/features/containers/MarkeplaceApps/styles.module.scss +559 -0
- package/src/features/containers/MarketplaceAppsCompact/index.ts +576 -0
- package/src/features/containers/MarketplaceAppsCompact/styles.module.scss +546 -0
- package/src/features/containers/MarketplaceAppsContainer/index.ts +83 -0
- package/src/features/containers/MarketplaceContainer/AppCard/index.ts +91 -0
- package/src/features/containers/MarketplaceContainer/AppCard/styles.module.scss +66 -0
- package/src/features/containers/MarketplaceContainer/AppListing/index.ts +34 -0
- package/src/features/containers/MarketplaceContainer/AppListing/styles.module.scss +10 -0
- package/src/features/containers/MarketplaceContainer/MarketplaceContentWrap/index.ts +132 -0
- package/src/features/containers/MarketplaceContainer/MarketplaceContentWrap/styles.module.scss +117 -0
- package/src/features/containers/MarketplaceContainer/index.ts +242 -0
- package/src/features/containers/MarketplaceContainer/styles.module.scss +84 -0
- package/src/features/containers/SDKContainer/index.ts +817 -0
- package/src/features/containers/SDKContainer/styles.module.scss +266 -0
- package/src/features/containers/SDKDebugContainer/index.ts +137 -0
- package/src/features/containers/SDKDebugContainer/styles.module.scss +37 -0
- package/src/features/containers/SDKFailedContainer/index.ts +117 -0
- package/src/features/containers/SDKFailedContainer/styles.module.scss +57 -0
- package/src/features/integrations/IntegrationRow/Icons.ts +77 -0
- package/src/features/integrations/IntegrationRow/index.ts +129 -0
- package/src/features/integrations/IntegrationRow/styles.module.scss +62 -0
- package/src/features/integrations/IntegrationsHeader/index.ts +34 -0
- package/src/features/integrations/IntegrationsHeader/styles.module.scss +47 -0
- package/src/features/integrations/IntegrationsList/index.ts +252 -0
- package/src/features/integrations/IntegrationsList/styles.module.scss +67 -0
- package/src/features/templates/Template/index.ts +295 -0
- package/src/features/templates/Template/styles.module.scss +226 -0
- package/src/features/templates/TemplatesView/index.ts +368 -0
- package/src/features/templates/TemplatesView/styles.module.scss +71 -0
- package/src/features/templates/TemplatesViewCompact/index.ts +364 -0
- package/src/features/templates/TemplatesViewCompact/styles.module.scss +141 -0
- package/src/hooks/useAutosizeTextArea.ts +22 -0
- package/src/hooks/useCustomRef.ts +13 -0
- package/src/hooks/useDebounce.ts +17 -0
- package/src/hooks/useElementResize.ts +40 -0
- package/src/hooks/useEventListener.ts +44 -0
- package/src/hooks/useHover.ts +40 -0
- package/src/hooks/useOnClickOutside.ts +32 -0
- package/src/index.ts +2051 -0
- package/src/index.umd.ts +13 -0
- package/src/interfaces/index.ts +924 -0
- package/src/modules/api/index.ts +1315 -0
- package/src/modules/api/responseHandler.ts +38 -0
- package/src/modules/event-emitter/index.ts +72 -0
- package/src/modules/event-emitter/runners/abstract.ts +21 -0
- package/src/modules/event-emitter/runners/default.ts +11 -0
- package/src/modules/event-emitter/runners/ntimes.ts +28 -0
- package/src/modules/event-emitter/types.ts +34 -0
- package/src/store/actionFunctions.ts +1573 -0
- package/src/store/index.ts +17 -0
- package/src/store/initialState.ts +58 -0
- package/src/stories/Button.stories.tsx +83 -0
- package/src/stories/Checkbox/Checkbox.stories.tsx +41 -0
- package/src/stories/Checkbox/CheckboxGroup.stories.tsx +46 -0
- package/src/stories/EditableText.stories.tsx +35 -0
- package/src/stories/Input/BaseInput.stories.tsx +48 -0
- package/src/stories/Input/DateInput.stories.tsx +28 -0
- package/src/stories/Input/Input.stories.tsx +24 -0
- package/src/stories/Input/PasswordInput.stories.tsx +26 -0
- package/src/stories/Introduction.stories.mdx +211 -0
- package/src/stories/Label.stories.tsx +27 -0
- package/src/stories/Listbox.stories.tsx +122 -0
- package/src/stories/Radio/Radio.stories.tsx +39 -0
- package/src/stories/Radio/RadioGroup.stories.tsx +46 -0
- package/src/stories/StepNavigation/NavItem.stories.tsx +31 -0
- package/src/stories/StepNavigation/StepNavigation.stories.tsx +50 -0
- package/src/stories/TabBar.stories.tsx +31 -0
- package/src/stories/TextArea.stories.tsx +23 -0
- package/src/stories/TimeInput.stories.tsx +37 -0
- package/src/stories/Toggle.stories.tsx +33 -0
- package/src/stories/assets/code-brackets.svg +1 -0
- package/src/stories/assets/colors.svg +1 -0
- package/src/stories/assets/comments.svg +1 -0
- package/src/stories/assets/direction.svg +1 -0
- package/src/stories/assets/flow.svg +1 -0
- package/src/stories/assets/plugin.svg +1 -0
- package/src/stories/assets/repo.svg +1 -0
- package/src/stories/assets/stackalt.svg +1 -0
- package/src/types/index.ts +293 -0
- package/src/types/store.ts +366 -0
- package/src/types/utils.ts +19 -0
- package/src/utils/ActivityOutputUtils.ts +163 -0
- package/src/utils/common.ts +20 -0
- package/src/utils/copyToClipboard.ts +24 -0
- package/src/utils/datetime.ts +101 -0
- package/src/utils/getUrlParam.ts +11 -0
- package/src/utils/isAuthMessage.ts +16 -0
- package/src/utils/isBrowser.ts +1 -0
- package/src/utils/jsonEncodeDecode.ts +15 -0
- package/src/utils/objectUtils.ts +116 -0
- package/src/utils/popup.ts +30 -0
- package/src/utils/searchJson.ts +51 -0
- package/src/utils/stepUtils.ts +45 -0
- package/src/utils/truncate.ts +6 -0
- package/test/setup.ts +1 -0
- package/vitest.config.ts +10 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
|
|
3
|
+
import { UnfetchResponse } from '../../types';
|
|
4
|
+
import { IntegryAPIError } from '../../extensions/IntegryAPIError';
|
|
5
|
+
|
|
6
|
+
export const ResponseHandler = async <T>(
|
|
7
|
+
response: UnfetchResponse,
|
|
8
|
+
): Promise<{
|
|
9
|
+
data: T | null;
|
|
10
|
+
status: number;
|
|
11
|
+
}> => {
|
|
12
|
+
const debugMode = !!process.env.DEBUG;
|
|
13
|
+
|
|
14
|
+
if (response.ok) {
|
|
15
|
+
try {
|
|
16
|
+
const parsedResponse: T = await response.json();
|
|
17
|
+
// if (debugMode) console.log(parsedResponse);
|
|
18
|
+
return {
|
|
19
|
+
data: parsedResponse,
|
|
20
|
+
status: response.status,
|
|
21
|
+
};
|
|
22
|
+
} catch (error) {
|
|
23
|
+
if (debugMode) console.log('Response is not in json');
|
|
24
|
+
return {
|
|
25
|
+
data: null,
|
|
26
|
+
status: response.status,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
} else if (response.status === 405) {
|
|
30
|
+
return {
|
|
31
|
+
data: await response.json(),
|
|
32
|
+
status: response.status,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
if (debugMode) console.log('Received a non-2xx status code');
|
|
36
|
+
const error = new IntegryAPIError(response.statusText, response);
|
|
37
|
+
return Promise.reject(error);
|
|
38
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// https://github.com/infinitum11/inf-ee
|
|
2
|
+
|
|
3
|
+
import EventRunnerDefault from './runners/default';
|
|
4
|
+
import EventRunnerNTimes from './runners/ntimes';
|
|
5
|
+
import {
|
|
6
|
+
EventListenerStorage,
|
|
7
|
+
EventSet,
|
|
8
|
+
EventEmitterType,
|
|
9
|
+
HandlerRunner,
|
|
10
|
+
} from './types';
|
|
11
|
+
|
|
12
|
+
export class EventEmitter<ESet extends EventSet>
|
|
13
|
+
implements EventEmitterType<EventSet> {
|
|
14
|
+
private events: EventListenerStorage<ESet> = Object.create(null);
|
|
15
|
+
|
|
16
|
+
on<EventName extends keyof ESet>(
|
|
17
|
+
eventName: EventName,
|
|
18
|
+
handler: ESet[EventName],
|
|
19
|
+
): void {
|
|
20
|
+
this.addEventListener(eventName, new EventRunnerDefault(this, handler));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
once<EventName extends keyof ESet>(
|
|
24
|
+
eventName: EventName,
|
|
25
|
+
handler: ESet[EventName],
|
|
26
|
+
): void {
|
|
27
|
+
this.addEventListener(eventName, new EventRunnerNTimes(this, handler, 1));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
off<EventName extends keyof ESet>(
|
|
31
|
+
eventName: EventName,
|
|
32
|
+
handler: ESet[EventName],
|
|
33
|
+
): void {
|
|
34
|
+
const events = this.events[eventName];
|
|
35
|
+
if (!events?.length) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
this.events[eventName] = events.filter((h) => h.getHandler() !== handler);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
offAll(): void {
|
|
42
|
+
Object.keys(this.events).forEach((eventName) => {
|
|
43
|
+
const events = this.events[eventName];
|
|
44
|
+
if (events) {
|
|
45
|
+
events.length = 0;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
this.events = Object.create(null);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
emit<EventName extends keyof ESet>(
|
|
52
|
+
eventName: EventName,
|
|
53
|
+
...args: Parameters<ESet[EventName]>
|
|
54
|
+
): void {
|
|
55
|
+
const events = this.events[eventName];
|
|
56
|
+
if (events) {
|
|
57
|
+
events.forEach((handler) => handler.run(eventName, ...args));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private addEventListener<EventName extends keyof ESet>(
|
|
62
|
+
eventName: EventName,
|
|
63
|
+
runner: HandlerRunner<ESet, EventName>,
|
|
64
|
+
) {
|
|
65
|
+
const events = this.events[eventName];
|
|
66
|
+
if (Array.isArray(events)) {
|
|
67
|
+
events.push(runner);
|
|
68
|
+
} else {
|
|
69
|
+
this.events[eventName] = [runner];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { EventSet, EventEmitterType, HandlerRunner } from '../types';
|
|
2
|
+
|
|
3
|
+
export default abstract class EventRunnerAbstract<
|
|
4
|
+
ESet extends EventSet,
|
|
5
|
+
EventName extends keyof ESet
|
|
6
|
+
> implements HandlerRunner<ESet, EventName> {
|
|
7
|
+
// eslint-disable-next-line no-useless-constructor
|
|
8
|
+
constructor(
|
|
9
|
+
protected emitter: EventEmitterType<ESet>,
|
|
10
|
+
protected handler: ESet[EventName],
|
|
11
|
+
) {}
|
|
12
|
+
|
|
13
|
+
getHandler(): ESet[EventName] {
|
|
14
|
+
return this.handler;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
abstract run(
|
|
18
|
+
eventName: EventName,
|
|
19
|
+
...args: Parameters<ESet[EventName]>
|
|
20
|
+
): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EventSet } from '../types';
|
|
2
|
+
import EventRunnerAbstract from './abstract';
|
|
3
|
+
|
|
4
|
+
export default class EventRunnerDefault<
|
|
5
|
+
ESet extends EventSet,
|
|
6
|
+
EventName extends keyof ESet
|
|
7
|
+
> extends EventRunnerAbstract<ESet, EventName> {
|
|
8
|
+
run(_eventName: EventName, ...args: Parameters<ESet[EventName]>): void {
|
|
9
|
+
this.handler.apply(null, args);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { EventSet, EventEmitterType } from '../types';
|
|
2
|
+
import EventRunnerDefault from './default';
|
|
3
|
+
|
|
4
|
+
export default class EventRunnerNTimes<
|
|
5
|
+
ESet extends EventSet,
|
|
6
|
+
EventName extends keyof ESet
|
|
7
|
+
> extends EventRunnerDefault<ESet, EventName> {
|
|
8
|
+
private i = 0;
|
|
9
|
+
|
|
10
|
+
constructor(
|
|
11
|
+
emitter: EventEmitterType<ESet>,
|
|
12
|
+
handler: ESet[EventName],
|
|
13
|
+
private total = 1,
|
|
14
|
+
) {
|
|
15
|
+
super(emitter, handler);
|
|
16
|
+
if (this.total < 1) {
|
|
17
|
+
throw new Error(`{total} can not be less than 1`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
run(eventName: EventName, ...args: Parameters<ESet[EventName]>): void {
|
|
22
|
+
super.run(eventName, ...args);
|
|
23
|
+
// eslint-disable-next-line no-plusplus
|
|
24
|
+
if (++this.i >= this.total) {
|
|
25
|
+
this.emitter.off(eventName, this.handler);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2
|
+
export type EventSet = Record<string, (...args: any[]) => void>;
|
|
3
|
+
|
|
4
|
+
export interface HandlerRunner<
|
|
5
|
+
ESet extends EventSet,
|
|
6
|
+
EventName extends keyof ESet
|
|
7
|
+
> {
|
|
8
|
+
run(eventName: EventName, ...args: Parameters<ESet[EventName]>): void;
|
|
9
|
+
getHandler(): ESet[EventName];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type EventListenerStorage<ESet extends EventSet> = {
|
|
13
|
+
[EventName in keyof ESet]?: Array<HandlerRunner<ESet, EventName>>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export interface EventEmitterType<ESet extends EventSet> {
|
|
17
|
+
on<EventName extends keyof ESet>(
|
|
18
|
+
eventName: EventName,
|
|
19
|
+
handler: ESet[EventName],
|
|
20
|
+
): void;
|
|
21
|
+
once<EventName extends keyof ESet>(
|
|
22
|
+
eventName: EventName,
|
|
23
|
+
handler: ESet[EventName],
|
|
24
|
+
): void;
|
|
25
|
+
off<EventName extends keyof ESet>(
|
|
26
|
+
eventName: EventName,
|
|
27
|
+
handler: ESet[EventName],
|
|
28
|
+
): void;
|
|
29
|
+
offAll(): void;
|
|
30
|
+
emit<EventName extends keyof ESet>(
|
|
31
|
+
eventName: EventName,
|
|
32
|
+
...args: Parameters<ESet[EventName]>
|
|
33
|
+
): void;
|
|
34
|
+
}
|