chayns-api 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/.babelrc +30 -0
- package/.eslintrc +17 -0
- package/.github/workflows/deploy_docs.yml +28 -0
- package/LICENSE +21 -0
- package/README.md +47 -0
- package/dist/cjs/calls/dialogs/alert.js +19 -0
- package/dist/cjs/calls/dialogs/chaynsDialog.js +59 -0
- package/dist/cjs/calls/dialogs/close.js +13 -0
- package/dist/cjs/calls/dialogs/communication.js +71 -0
- package/dist/cjs/calls/dialogs/confirm.js +33 -0
- package/dist/cjs/calls/dialogs/date.js +187 -0
- package/dist/cjs/calls/dialogs/dropUpAlert.js +12 -0
- package/dist/cjs/calls/dialogs/fileSelect.js +39 -0
- package/dist/cjs/calls/dialogs/iFrame.js +43 -0
- package/dist/cjs/calls/dialogs/index.js +178 -0
- package/dist/cjs/calls/dialogs/input.js +33 -0
- package/dist/cjs/calls/dialogs/mediaSelect.js +27 -0
- package/dist/cjs/calls/dialogs/open.js +19 -0
- package/dist/cjs/calls/dialogs/select.js +55 -0
- package/dist/cjs/calls/dialogs/signature.js +24 -0
- package/dist/cjs/calls/dialogs/toast.js +18 -0
- package/dist/cjs/calls/dialogs/utils/callback.js +12 -0
- package/dist/cjs/calls/dialogs/utils/environment.js +10 -0
- package/dist/cjs/calls/dialogs/utils/is.js +21 -0
- package/dist/cjs/calls/getUserInfo.js +40 -0
- package/dist/cjs/calls/index.js +300 -0
- package/dist/cjs/calls/sendMessage.js +120 -0
- package/dist/cjs/calls/visibilityChangeListener.js +38 -0
- package/dist/cjs/client.js +93 -0
- package/dist/cjs/components/ChaynsContext.js +12 -0
- package/dist/cjs/components/ChaynsModuleProvider.js +457 -0
- package/dist/cjs/components/ChaynsProvider.js +116 -0
- package/dist/cjs/components/WaitUntil.js +31 -0
- package/dist/cjs/components/withCompatMode.js +55 -0
- package/dist/cjs/helper/apiListenerHelper.js +34 -0
- package/dist/cjs/hooks/geoLocationListener.js +50 -0
- package/dist/cjs/hooks/index.js +153 -0
- package/dist/cjs/hooks/scrollListener.js +102 -0
- package/dist/cjs/hooks/useAccessToken.js +28 -0
- package/dist/cjs/hooks/useCurrentPage.js +13 -0
- package/dist/cjs/hooks/useCustomData.js +13 -0
- package/dist/cjs/hooks/useDevice.js +13 -0
- package/dist/cjs/hooks/useEnvironment.js +13 -0
- package/dist/cjs/hooks/useFunctions.js +16 -0
- package/dist/cjs/hooks/useIsAdminMode.js +16 -0
- package/dist/cjs/hooks/useLanguage.js +13 -0
- package/dist/cjs/hooks/usePages.js +38 -0
- package/dist/cjs/hooks/useParameters.js +13 -0
- package/dist/cjs/hooks/useSite.js +13 -0
- package/dist/cjs/hooks/useUser.js +14 -0
- package/dist/cjs/hooks/useValues.js +16 -0
- package/dist/cjs/hooks/windowMetricsListener.js +58 -0
- package/dist/cjs/host/ChaynsHost.js +102 -0
- package/dist/cjs/host/iframe/HostIframe.js +133 -0
- package/dist/cjs/host/iframe/utils/useUpdateData.js +21 -0
- package/dist/cjs/host/module/ModuleHost.js +82 -0
- package/dist/cjs/host/module/PagemakerFrame.js +105 -0
- package/dist/cjs/host/module/utils/loadComponent.js +61 -0
- package/dist/cjs/host/module/utils/useDynamicScript.js +61 -0
- package/dist/cjs/index.js +117 -0
- package/dist/cjs/types/DynamicApiImport.d.js +5 -0
- package/dist/cjs/types/IChaynsReact.js +235 -0
- package/dist/cjs/types/dialog.js +5 -0
- package/dist/cjs/util/appCall.js +23 -0
- package/dist/cjs/util/deviceHelper.js +71 -0
- package/dist/cjs/util/heightHelper.js +40 -0
- package/dist/cjs/util/postIframeForm.js +32 -0
- package/dist/cjs/wrapper/AppWrapper.js +244 -0
- package/dist/cjs/wrapper/FrameWrapper.js +288 -0
- package/dist/cjs/wrapper/ModuleFederationWrapper.js +61 -0
- package/dist/cjs/wrapper/SsrWrapper.js +30 -0
- package/dist/esm/calls/dialogs/alert.js +15 -0
- package/dist/esm/calls/dialogs/chaynsDialog.js +48 -0
- package/dist/esm/calls/dialogs/close.js +7 -0
- package/dist/esm/calls/dialogs/communication.js +66 -0
- package/dist/esm/calls/dialogs/confirm.js +30 -0
- package/dist/esm/calls/dialogs/date.js +211 -0
- package/dist/esm/calls/dialogs/dropUpAlert.js +7 -0
- package/dist/esm/calls/dialogs/fileSelect.js +32 -0
- package/dist/esm/calls/dialogs/iFrame.js +37 -0
- package/dist/esm/calls/dialogs/index.js +14 -0
- package/dist/esm/calls/dialogs/input.js +26 -0
- package/dist/esm/calls/dialogs/mediaSelect.js +22 -0
- package/dist/esm/calls/dialogs/open.js +13 -0
- package/dist/esm/calls/dialogs/select.js +47 -0
- package/dist/esm/calls/dialogs/signature.js +18 -0
- package/dist/esm/calls/dialogs/toast.js +13 -0
- package/dist/esm/calls/dialogs/utils/callback.js +7 -0
- package/dist/esm/calls/dialogs/utils/environment.js +3 -0
- package/dist/esm/calls/dialogs/utils/is.js +12 -0
- package/dist/esm/calls/getUserInfo.js +33 -0
- package/dist/esm/calls/index.js +323 -0
- package/dist/esm/calls/sendMessage.js +111 -0
- package/dist/esm/calls/visibilityChangeListener.js +30 -0
- package/dist/esm/client.js +8 -0
- package/dist/esm/components/ChaynsContext.js +4 -0
- package/dist/esm/components/ChaynsModuleProvider.js +517 -0
- package/dist/esm/components/ChaynsProvider.js +109 -0
- package/dist/esm/components/WaitUntil.js +25 -0
- package/dist/esm/components/withCompatMode.js +47 -0
- package/dist/esm/helper/apiListenerHelper.js +25 -0
- package/dist/esm/hooks/geoLocationListener.js +43 -0
- package/dist/esm/hooks/index.js +16 -0
- package/dist/esm/hooks/scrollListener.js +95 -0
- package/dist/esm/hooks/useAccessToken.js +22 -0
- package/dist/esm/hooks/useCurrentPage.js +7 -0
- package/dist/esm/hooks/useCustomData.js +7 -0
- package/dist/esm/hooks/useDevice.js +6 -0
- package/dist/esm/hooks/useEnvironment.js +6 -0
- package/dist/esm/hooks/useFunctions.js +9 -0
- package/dist/esm/hooks/useIsAdminMode.js +9 -0
- package/dist/esm/hooks/useLanguage.js +6 -0
- package/dist/esm/hooks/usePages.js +32 -0
- package/dist/esm/hooks/useParameters.js +6 -0
- package/dist/esm/hooks/useSite.js +6 -0
- package/dist/esm/hooks/useUser.js +7 -0
- package/dist/esm/hooks/useValues.js +9 -0
- package/dist/esm/hooks/windowMetricsListener.js +51 -0
- package/dist/esm/host/ChaynsHost.js +95 -0
- package/dist/esm/host/iframe/HostIframe.js +124 -0
- package/dist/esm/host/iframe/utils/useUpdateData.js +14 -0
- package/dist/esm/host/module/ModuleHost.js +74 -0
- package/dist/esm/host/module/PagemakerFrame.js +97 -0
- package/dist/esm/host/module/utils/loadComponent.js +55 -0
- package/dist/esm/host/module/utils/useDynamicScript.js +50 -0
- package/dist/esm/index.js +16 -0
- package/dist/esm/types/DynamicApiImport.d.js +1 -0
- package/dist/esm/types/IChaynsReact.js +215 -0
- package/dist/esm/types/dialog.js +1 -0
- package/dist/esm/util/appCall.js +16 -0
- package/dist/esm/util/deviceHelper.js +62 -0
- package/dist/esm/util/heightHelper.js +32 -0
- package/dist/esm/util/postIframeForm.js +26 -0
- package/dist/esm/wrapper/AppWrapper.js +241 -0
- package/dist/esm/wrapper/FrameWrapper.js +279 -0
- package/dist/esm/wrapper/ModuleFederationWrapper.js +56 -0
- package/dist/esm/wrapper/SsrWrapper.js +23 -0
- package/dist/types/calls/dialogs/alert.d.ts +1 -0
- package/dist/types/calls/dialogs/chaynsDialog.d.ts +24 -0
- package/dist/types/calls/dialogs/close.d.ts +1 -0
- package/dist/types/calls/dialogs/communication.d.ts +3 -0
- package/dist/types/calls/dialogs/confirm.d.ts +13 -0
- package/dist/types/calls/dialogs/date.d.ts +96 -0
- package/dist/types/calls/dialogs/dropUpAlert.d.ts +5 -0
- package/dist/types/calls/dialogs/fileSelect.d.ts +16 -0
- package/dist/types/calls/dialogs/iFrame.d.ts +10 -0
- package/dist/types/calls/dialogs/index.d.ts +14 -0
- package/dist/types/calls/dialogs/input.d.ts +15 -0
- package/dist/types/calls/dialogs/mediaSelect.d.ts +8 -0
- package/dist/types/calls/dialogs/open.d.ts +1 -0
- package/dist/types/calls/dialogs/select.d.ts +6 -0
- package/dist/types/calls/dialogs/signature.d.ts +7 -0
- package/dist/types/calls/dialogs/toast.d.ts +1 -0
- package/dist/types/calls/dialogs/utils/callback.d.ts +1 -0
- package/dist/types/calls/dialogs/utils/environment.d.ts +3 -0
- package/dist/types/calls/dialogs/utils/is.d.ts +4 -0
- package/dist/types/calls/getUserInfo.d.ts +9 -0
- package/dist/types/calls/index.d.ts +231 -0
- package/dist/types/calls/sendMessage.d.ts +13 -0
- package/dist/types/calls/visibilityChangeListener.d.ts +9 -0
- package/dist/types/client.d.ts +7 -0
- package/dist/types/components/ChaynsContext.d.ts +3 -0
- package/dist/types/components/ChaynsModuleProvider.d.ts +170 -0
- package/dist/types/components/ChaynsProvider.d.ts +13 -0
- package/dist/types/components/WaitUntil.d.ts +7 -0
- package/dist/types/components/withCompatMode.d.ts +13 -0
- package/dist/types/helper/apiListenerHelper.d.ts +6 -0
- package/dist/types/hooks/geoLocationListener.d.ts +18 -0
- package/dist/types/hooks/index.d.ts +16 -0
- package/dist/types/hooks/scrollListener.d.ts +28 -0
- package/dist/types/hooks/useAccessToken.d.ts +5 -0
- package/dist/types/hooks/useCurrentPage.d.ts +4 -0
- package/dist/types/hooks/useCustomData.d.ts +4 -0
- package/dist/types/hooks/useDevice.d.ts +5 -0
- package/dist/types/hooks/useEnvironment.d.ts +5 -0
- package/dist/types/hooks/useFunctions.d.ts +5 -0
- package/dist/types/hooks/useIsAdminMode.d.ts +4 -0
- package/dist/types/hooks/useLanguage.d.ts +5 -0
- package/dist/types/hooks/usePages.d.ts +14 -0
- package/dist/types/hooks/useParameters.d.ts +5 -0
- package/dist/types/hooks/useSite.d.ts +5 -0
- package/dist/types/hooks/useUser.d.ts +5 -0
- package/dist/types/hooks/useValues.d.ts +5 -0
- package/dist/types/hooks/windowMetricsListener.d.ts +11 -0
- package/dist/types/host/ChaynsHost.d.ts +27 -0
- package/dist/types/host/iframe/HostIframe.d.ts +24 -0
- package/dist/types/host/iframe/utils/useUpdateData.d.ts +3 -0
- package/dist/types/host/module/ModuleHost.d.ts +23 -0
- package/dist/types/host/module/PagemakerFrame.d.ts +22 -0
- package/dist/types/host/module/utils/loadComponent.d.ts +1 -0
- package/dist/types/host/module/utils/useDynamicScript.d.ts +9 -0
- package/dist/types/index.d.ts +16 -0
- package/dist/types/types/IChaynsReact.d.ts +590 -0
- package/dist/types/types/dialog.d.ts +41 -0
- package/dist/types/util/appCall.d.ts +2 -0
- package/dist/types/util/deviceHelper.d.ts +7 -0
- package/dist/types/util/heightHelper.d.ts +1 -0
- package/dist/types/util/postIframeForm.d.ts +1 -0
- package/dist/types/wrapper/AppWrapper.d.ts +16 -0
- package/dist/types/wrapper/FrameWrapper.d.ts +15 -0
- package/dist/types/wrapper/ModuleFederationWrapper.d.ts +10 -0
- package/dist/types/wrapper/SsrWrapper.d.ts +11 -0
- package/package.json +76 -0
- package/toolkit.config.js +52 -0
- package/tsconfig.json +56 -0
package/.babelrc
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"esm": {
|
|
4
|
+
"presets": [
|
|
5
|
+
[
|
|
6
|
+
"@babel/preset-env",
|
|
7
|
+
{
|
|
8
|
+
"targets": ">0.5%, not dead, not op_mini all, chrome 71",
|
|
9
|
+
"modules": false
|
|
10
|
+
}
|
|
11
|
+
],
|
|
12
|
+
"@babel/preset-react",
|
|
13
|
+
"@babel/preset-typescript"
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
"cjs": {
|
|
17
|
+
"presets": [
|
|
18
|
+
[
|
|
19
|
+
"@babel/preset-env",
|
|
20
|
+
{
|
|
21
|
+
"targets": { "node": 12 },
|
|
22
|
+
"modules": "commonjs"
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"@babel/preset-react",
|
|
26
|
+
"@babel/preset-typescript"
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
package/.eslintrc
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@chayns-toolkit",
|
|
3
|
+
"rules": {
|
|
4
|
+
"no-void": "off",
|
|
5
|
+
"react/function-component-definition": [
|
|
6
|
+
"error",
|
|
7
|
+
{
|
|
8
|
+
"namedComponents": "arrow-function",
|
|
9
|
+
"unnamedComponents": "arrow-function"
|
|
10
|
+
}
|
|
11
|
+
],
|
|
12
|
+
"@typescript-eslint/require-await": "off",
|
|
13
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
14
|
+
"class-methods-use-this": "off",
|
|
15
|
+
"react/jsx-props-no-spreading": "off"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
name: Deploy Docs to GitHub Pages
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
paths:
|
|
6
|
+
- "website/**"
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
deploy:
|
|
11
|
+
runs-on: ubuntu-20.04
|
|
12
|
+
steps:
|
|
13
|
+
- name: Checkout repo
|
|
14
|
+
uses: actions/checkout@v2
|
|
15
|
+
|
|
16
|
+
- name: Use Node 16
|
|
17
|
+
uses: actions/setup-node@v1
|
|
18
|
+
with:
|
|
19
|
+
node-version: 16
|
|
20
|
+
|
|
21
|
+
- name: Build
|
|
22
|
+
run: npm run build-docs
|
|
23
|
+
|
|
24
|
+
- name: Deploy to GitHub Pages
|
|
25
|
+
uses: peaceiris/actions-gh-pages@v3
|
|
26
|
+
with:
|
|
27
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
28
|
+
publish_dir: ./website/build
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Tobit.Software
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# [chayns react api](https://github.com/TobitSoftware/chayns-api) · []() []() []()
|
|
2
|
+
|
|
3
|
+
The chayns-api provides information and useful functions to your page. The information and functions are provided by react hooks and normal functions.
|
|
4
|
+
A list of all functions and hooks can be found [here](https://tobitsoftware.github.io/chayns-api/docs).
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
It is recommended to setup your new chayns page with the [create-chayns-app](https://github.com/TobitSoftware/create-chayns-app).
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Migrate old project
|
|
12
|
+
1. Install chayns-api package
|
|
13
|
+
```sh
|
|
14
|
+
# NPM
|
|
15
|
+
$ npm install chayns-api
|
|
16
|
+
|
|
17
|
+
# Yarn
|
|
18
|
+
$ yarn add chayns-api
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
2. Wrap your App component with the "ChaynsProvider" component. In all components which are under the ChaynsProvider you can use hooks and chayns functions.
|
|
22
|
+
```jsx
|
|
23
|
+
<ChaynsProvider>
|
|
24
|
+
<App/>
|
|
25
|
+
</ChaynsProvider>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Example
|
|
29
|
+
|
|
30
|
+
```jsx
|
|
31
|
+
import { useUser } from 'chayns-api';
|
|
32
|
+
|
|
33
|
+
const FirstName = () => {
|
|
34
|
+
const user = useUser();
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<div>{user?.firstName}</div>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Getting started
|
|
43
|
+
|
|
44
|
+
More information to setup chayns-api can be found in the [documentation](https://tobitsoftware.github.io/chayns-api/docs).
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
## License
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.alert = alert;
|
|
7
|
+
var _chaynsDialog = require("./chaynsDialog");
|
|
8
|
+
function alert(title = '', message = '') {
|
|
9
|
+
return (0, _chaynsDialog.chaynsDialog)({
|
|
10
|
+
'dialog': {
|
|
11
|
+
title,
|
|
12
|
+
message,
|
|
13
|
+
'buttons': [{
|
|
14
|
+
'text': _chaynsDialog.buttonText.OK,
|
|
15
|
+
'buttonType': _chaynsDialog.buttonType.POSITIVE
|
|
16
|
+
}]
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.buttonType = exports.buttonText = void 0;
|
|
7
|
+
exports.chaynsDialog = chaynsDialog;
|
|
8
|
+
exports.dialogAction = void 0;
|
|
9
|
+
var _open = require("./open");
|
|
10
|
+
var _callback = require("./utils/callback");
|
|
11
|
+
const buttonText = {
|
|
12
|
+
'YES': {
|
|
13
|
+
'de': 'Ja',
|
|
14
|
+
'en': 'Yes',
|
|
15
|
+
'nl': 'Ja'
|
|
16
|
+
}['de'] || 'Yes',
|
|
17
|
+
// TODO: Language
|
|
18
|
+
'NO': {
|
|
19
|
+
'de': 'Nein',
|
|
20
|
+
'en': 'No',
|
|
21
|
+
'nl': 'Nee'
|
|
22
|
+
}['de'] || 'No',
|
|
23
|
+
'OK': 'OK',
|
|
24
|
+
'CANCEL': {
|
|
25
|
+
'de': 'Abbrechen',
|
|
26
|
+
'en': 'Cancel',
|
|
27
|
+
'nl': 'Annuleren'
|
|
28
|
+
}['de'] || 'Cancel'
|
|
29
|
+
};
|
|
30
|
+
exports.buttonText = buttonText;
|
|
31
|
+
const buttonType = {
|
|
32
|
+
'CANCEL': -1,
|
|
33
|
+
'NEGATIVE': 0,
|
|
34
|
+
'POSITIVE': 1
|
|
35
|
+
};
|
|
36
|
+
exports.buttonType = buttonType;
|
|
37
|
+
const dialogAction = {
|
|
38
|
+
'ALERT_CONFIRM': 178,
|
|
39
|
+
'INPUT': 173,
|
|
40
|
+
'SELECT': 174,
|
|
41
|
+
'DATE': 175,
|
|
42
|
+
'ADVANCED_DATE': 176,
|
|
43
|
+
'DROP_UP_ALERT': 177,
|
|
44
|
+
'MEDIA_SELECT': 179,
|
|
45
|
+
'FILE_SELECT': 180,
|
|
46
|
+
'SIGNATURE': 181,
|
|
47
|
+
'IFRAME': 191
|
|
48
|
+
};
|
|
49
|
+
exports.dialogAction = dialogAction;
|
|
50
|
+
function chaynsDialog(config) {
|
|
51
|
+
const callbackName = 'chaynsDialog';
|
|
52
|
+
config.callback = (0, _callback.getCallbackName)(callbackName);
|
|
53
|
+
if (config.dialog) {
|
|
54
|
+
config.dialog.callType = dialogAction.ALERT_CONFIRM;
|
|
55
|
+
// @ts-ignore
|
|
56
|
+
return (0, _open.open)(config.dialog).then(data => Promise.resolve(data.selection ? data : data.buttonType));
|
|
57
|
+
}
|
|
58
|
+
return "unsupported";
|
|
59
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.addDialogDataListener = addDialogDataListener;
|
|
7
|
+
exports.removeDialogDataListener = removeDialogDataListener;
|
|
8
|
+
exports.sendData = sendData;
|
|
9
|
+
var _index = require("../index");
|
|
10
|
+
// @ts-nocheck
|
|
11
|
+
|
|
12
|
+
function sendData(data, isApiEvent) {
|
|
13
|
+
return (0, _index.invokeDialogCall)({
|
|
14
|
+
action: 218,
|
|
15
|
+
value: {
|
|
16
|
+
data,
|
|
17
|
+
isApiEvent
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
const listeners = [];
|
|
22
|
+
const apiListeners = [];
|
|
23
|
+
function _dialogDataListener(e = {}) {
|
|
24
|
+
if (!e.data || !e.data.action && typeof e.data !== 'string') {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const messageObj = e.data.action ? e.data : JSON.parse(e.data.match(/(\{(?:.*)\})/)[0]);
|
|
28
|
+
if (messageObj.action === 218) {
|
|
29
|
+
const {
|
|
30
|
+
data
|
|
31
|
+
} = messageObj.value;
|
|
32
|
+
if (messageObj.value.isApiEvent) {
|
|
33
|
+
apiListeners.forEach(listener => {
|
|
34
|
+
listener(data);
|
|
35
|
+
});
|
|
36
|
+
} else {
|
|
37
|
+
listeners.forEach(listener => {
|
|
38
|
+
listener(data);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function addDialogDataListener(callback, getApiEvents = false) {
|
|
44
|
+
if (listeners.length === 0 || apiListeners.length === 0) {
|
|
45
|
+
window.addEventListener('message', _dialogDataListener);
|
|
46
|
+
}
|
|
47
|
+
if (getApiEvents) {
|
|
48
|
+
apiListeners.push(callback);
|
|
49
|
+
} else {
|
|
50
|
+
listeners.push(callback);
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
function removeDialogDataListener(callback, getApiEvents = false) {
|
|
55
|
+
let index;
|
|
56
|
+
if (getApiEvents) {
|
|
57
|
+
index = apiListeners.indexOf(callback);
|
|
58
|
+
if (index !== -1) {
|
|
59
|
+
apiListeners.splice(index, 1);
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
index = listeners.indexOf(callback);
|
|
63
|
+
if (index !== -1) {
|
|
64
|
+
listeners.splice(index, 1);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (listeners.length === 0 && apiListeners.length === 0) {
|
|
68
|
+
window.removeEventListener('message', _dialogDataListener);
|
|
69
|
+
}
|
|
70
|
+
return index !== -1;
|
|
71
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.confirm = confirm;
|
|
7
|
+
var _chaynsDialog = require("./chaynsDialog");
|
|
8
|
+
function confirm(title = '', message = '', config = {}) {
|
|
9
|
+
// backward compatibility
|
|
10
|
+
if (Array.isArray(config)) {
|
|
11
|
+
config = {
|
|
12
|
+
'buttons': config
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
if (!config.buttons || !Array.isArray(config.buttons)) {
|
|
16
|
+
config.buttons = [{
|
|
17
|
+
'text': _chaynsDialog.buttonText.YES,
|
|
18
|
+
'buttonType': _chaynsDialog.buttonType.POSITIVE
|
|
19
|
+
}, {
|
|
20
|
+
'text': _chaynsDialog.buttonText.NO,
|
|
21
|
+
'buttonType': _chaynsDialog.buttonType.NEGATIVE
|
|
22
|
+
}];
|
|
23
|
+
}
|
|
24
|
+
return (0, _chaynsDialog.chaynsDialog)({
|
|
25
|
+
'dialog': {
|
|
26
|
+
title,
|
|
27
|
+
message,
|
|
28
|
+
'buttons': config.buttons,
|
|
29
|
+
'links': config.links,
|
|
30
|
+
'select': config.select
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.advancedDate = advancedDate;
|
|
7
|
+
exports.date = date;
|
|
8
|
+
exports.dateType = void 0;
|
|
9
|
+
var _chaynsDialog = require("./chaynsDialog");
|
|
10
|
+
var _is = require("./utils/is");
|
|
11
|
+
var _open = require("./open");
|
|
12
|
+
var _index = require("../index");
|
|
13
|
+
function date(config = {}) {
|
|
14
|
+
let {
|
|
15
|
+
preSelect,
|
|
16
|
+
minDate,
|
|
17
|
+
maxDate,
|
|
18
|
+
title,
|
|
19
|
+
message,
|
|
20
|
+
minuteInterval,
|
|
21
|
+
autoSelectDate
|
|
22
|
+
} = config,
|
|
23
|
+
type = config.dateType || dateType.DATE;
|
|
24
|
+
|
|
25
|
+
// This will fix the iOS problem with not preselectedDate without user interaction. That it return the wrog time.
|
|
26
|
+
const {
|
|
27
|
+
os,
|
|
28
|
+
app
|
|
29
|
+
} = (0, _index.getDevice)();
|
|
30
|
+
if (minuteInterval && minuteInterval > 1 && os === 'iOS' && app) {
|
|
31
|
+
preSelect = roundInterval(preSelect, minuteInterval);
|
|
32
|
+
} else {
|
|
33
|
+
preSelect = validateValue(preSelect);
|
|
34
|
+
}
|
|
35
|
+
minDate = validateValue(minDate);
|
|
36
|
+
maxDate = validateValue(maxDate);
|
|
37
|
+
let buttons = [];
|
|
38
|
+
buttons = [{
|
|
39
|
+
'text': _chaynsDialog.buttonText.OK,
|
|
40
|
+
'buttonType': _chaynsDialog.buttonType.POSITIVE
|
|
41
|
+
}];
|
|
42
|
+
return (0, _open.open)({
|
|
43
|
+
'callType': _chaynsDialog.dialogAction.DATE,
|
|
44
|
+
type,
|
|
45
|
+
'selectedDate': preSelect,
|
|
46
|
+
minDate,
|
|
47
|
+
maxDate,
|
|
48
|
+
title,
|
|
49
|
+
message,
|
|
50
|
+
buttons,
|
|
51
|
+
minuteInterval,
|
|
52
|
+
autoSelectDate
|
|
53
|
+
}).then(data => {
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
return Promise.resolve(data.selectedDate);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function advancedDate(config = {}) {
|
|
59
|
+
let {
|
|
60
|
+
preSelect,
|
|
61
|
+
minDate,
|
|
62
|
+
maxDate,
|
|
63
|
+
title,
|
|
64
|
+
message,
|
|
65
|
+
minuteInterval,
|
|
66
|
+
buttons,
|
|
67
|
+
multiselect,
|
|
68
|
+
disabledDates,
|
|
69
|
+
textBlocks,
|
|
70
|
+
monthSelect,
|
|
71
|
+
yearSelect,
|
|
72
|
+
interval,
|
|
73
|
+
maxInterval,
|
|
74
|
+
minInterval,
|
|
75
|
+
disabledIntervals,
|
|
76
|
+
disabledWeekDayIntervals,
|
|
77
|
+
getLocalTime,
|
|
78
|
+
autoSelectDate
|
|
79
|
+
} = config,
|
|
80
|
+
// minInterval and maxInterval in minutes
|
|
81
|
+
type = config.dateType || dateType.DATE;
|
|
82
|
+
minDate = validateValue(minDate);
|
|
83
|
+
maxDate = validateValue(maxDate);
|
|
84
|
+
const {
|
|
85
|
+
os,
|
|
86
|
+
app
|
|
87
|
+
} = (0, _index.getDevice)();
|
|
88
|
+
if (!preSelect) preSelect = {};
|
|
89
|
+
if (Array.isArray(preSelect)) {
|
|
90
|
+
preSelect = preSelect.map(p => validateValue(p));
|
|
91
|
+
} else if ((0, _is.isObject)(preSelect)) {
|
|
92
|
+
if (preSelect.start && preSelect.end) {
|
|
93
|
+
if (minuteInterval && minuteInterval > 1 && os === 'iOS' && app) {
|
|
94
|
+
preSelect = [roundInterval(preSelect.start, minuteInterval), roundInterval(preSelect.end, minuteInterval)];
|
|
95
|
+
} else {
|
|
96
|
+
preSelect = [validateValue(preSelect.start), validateValue(preSelect.end)];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
// This will fix the iOS problem with not preselectedDate without user interaction. That it return the wrong time.
|
|
101
|
+
// eslint-disable-next-line no-lonely-if
|
|
102
|
+
if (minuteInterval && minuteInterval > 1 && os === 'iOS' && app) {
|
|
103
|
+
preSelect = roundInterval(preSelect, minuteInterval);
|
|
104
|
+
} else {
|
|
105
|
+
preSelect = validateValue(preSelect);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (Array.isArray(disabledDates)) {
|
|
109
|
+
disabledDates = disabledDates.map(d => validateValue(d));
|
|
110
|
+
}
|
|
111
|
+
if (!buttons || !Array.isArray(buttons)) {
|
|
112
|
+
buttons = [{
|
|
113
|
+
'text': _chaynsDialog.buttonText.OK,
|
|
114
|
+
'buttonType': _chaynsDialog.buttonType.POSITIVE
|
|
115
|
+
}];
|
|
116
|
+
}
|
|
117
|
+
return (0, _open.open)({
|
|
118
|
+
'callType': _chaynsDialog.dialogAction.ADVANCED_DATE,
|
|
119
|
+
type,
|
|
120
|
+
'selectedDate': Array.isArray(preSelect) ? undefined : preSelect,
|
|
121
|
+
minDate,
|
|
122
|
+
maxDate,
|
|
123
|
+
title,
|
|
124
|
+
message,
|
|
125
|
+
minuteInterval,
|
|
126
|
+
buttons,
|
|
127
|
+
multiselect,
|
|
128
|
+
'selectedDates': Array.isArray(preSelect) ? preSelect : undefined,
|
|
129
|
+
disabledDates,
|
|
130
|
+
textBlocks,
|
|
131
|
+
monthSelect,
|
|
132
|
+
yearSelect,
|
|
133
|
+
interval,
|
|
134
|
+
minInterval,
|
|
135
|
+
maxInterval,
|
|
136
|
+
disabledIntervals,
|
|
137
|
+
disabledWeekDayIntervals,
|
|
138
|
+
getLocalTime,
|
|
139
|
+
autoSelectDate
|
|
140
|
+
}).then(data => {
|
|
141
|
+
return Promise.resolve(data);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* @typedef {number} dateDialogType
|
|
147
|
+
*/
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Enum for date dialog
|
|
151
|
+
* <div>DATE will open a dialog where you can select a special day</div>
|
|
152
|
+
* <div>TIME will open a dialog where you can only select a special time</div>
|
|
153
|
+
* <div>DATE_TIME will open a dialog where you can select a special time on a special day</div>
|
|
154
|
+
* @readonly
|
|
155
|
+
* @enum {dateDialogType}
|
|
156
|
+
* @type {{DATE: number, TIME: number, DATE_TIME: number}}
|
|
157
|
+
*/
|
|
158
|
+
const dateType = {
|
|
159
|
+
'DATE': 1,
|
|
160
|
+
'TIME': 2,
|
|
161
|
+
'DATE_TIME': 3
|
|
162
|
+
};
|
|
163
|
+
exports.dateType = dateType;
|
|
164
|
+
function validateValue(value) {
|
|
165
|
+
if (!(0, _is.isNumber)(value)) {
|
|
166
|
+
if ((0, _is.isDate)(value)) {
|
|
167
|
+
// TODO: Find out whats the purpose of parsing to int
|
|
168
|
+
return parseInt(value.getTime() / 1000 + "", 10);
|
|
169
|
+
}
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
return value;
|
|
173
|
+
}
|
|
174
|
+
function roundInterval(preDate = new Date(), interval) {
|
|
175
|
+
if (!(0, _is.isDate)(preDate)) {
|
|
176
|
+
if ((0, _is.isNumber)(preDate)) {
|
|
177
|
+
preDate = new Date(preDate);
|
|
178
|
+
} else {
|
|
179
|
+
return -1;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
let minutes = preDate.getMinutes();
|
|
183
|
+
preDate.setMinutes(minutes - minutes % interval);
|
|
184
|
+
preDate.setSeconds(0);
|
|
185
|
+
// TODO: Why?
|
|
186
|
+
return parseInt(preDate.getTime() / 1000 + "", 10);
|
|
187
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.dropUpAlert = dropUpAlert;
|
|
7
|
+
var _open = require("./open");
|
|
8
|
+
var _chaynsDialog = require("./chaynsDialog");
|
|
9
|
+
function dropUpAlert(dialog = {}) {
|
|
10
|
+
dialog.callType = _chaynsDialog.dialogAction.DROP_UP_ALERT;
|
|
11
|
+
return (0, _open.open)(dialog);
|
|
12
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.fileSelect = fileSelect;
|
|
7
|
+
exports.fileType = void 0;
|
|
8
|
+
var _chaynsDialog = require("./chaynsDialog");
|
|
9
|
+
var _open = require("./open");
|
|
10
|
+
var _index = require("../index");
|
|
11
|
+
const fileType = {
|
|
12
|
+
'IMAGE': 'image',
|
|
13
|
+
'VIDEO': 'video',
|
|
14
|
+
'AUDIO': 'audio',
|
|
15
|
+
'DOCUMENT': ['application/x-latex', 'application/x-tex', 'text/', 'application/json', 'application/pdf', 'application/msword', 'application/msexcel', 'application/mspowerpoint', 'application/vnd.ms-word', 'application/vnd.ms-excel', 'application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument', 'application/vnd.oasis.opendocument']
|
|
16
|
+
};
|
|
17
|
+
exports.fileType = fileType;
|
|
18
|
+
async function fileSelect(dialog = {}) {
|
|
19
|
+
if (!dialog.buttons || !Array.isArray(dialog.buttons)) {
|
|
20
|
+
dialog.buttons = [];
|
|
21
|
+
if (dialog.multiselect || dialog.directory) {
|
|
22
|
+
dialog.buttons.push({
|
|
23
|
+
'text': _chaynsDialog.buttonText.OK,
|
|
24
|
+
'buttonType': _chaynsDialog.buttonType.POSITIVE
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
dialog.buttons.push({
|
|
28
|
+
'text': _chaynsDialog.buttonText.CANCEL,
|
|
29
|
+
'buttonType': _chaynsDialog.buttonType.NEGATIVE
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
dialog.callType = _chaynsDialog.dialogAction.FILE_SELECT;
|
|
33
|
+
const user = (0, _index.getUser)();
|
|
34
|
+
if (!user) {
|
|
35
|
+
return (0, _index.login)();
|
|
36
|
+
}
|
|
37
|
+
dialog.chaynsToken = (await (0, _index.getAccessToken)()).accessToken;
|
|
38
|
+
return (0, _open.open)(dialog);
|
|
39
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports._chaynsCallResponder = _chaynsCallResponder;
|
|
7
|
+
exports.iFrame = iFrame;
|
|
8
|
+
var _chaynsDialog = require("./chaynsDialog");
|
|
9
|
+
var _open = require("./open");
|
|
10
|
+
var _communication = require("./communication");
|
|
11
|
+
var _index = require("../index");
|
|
12
|
+
function iFrame(dialog = {
|
|
13
|
+
url: ""
|
|
14
|
+
}) {
|
|
15
|
+
if (!dialog.buttons || !Array.isArray(dialog.buttons)) {
|
|
16
|
+
dialog.buttons = [{
|
|
17
|
+
'text': _chaynsDialog.buttonText.YES,
|
|
18
|
+
'buttonType': _chaynsDialog.buttonType.POSITIVE
|
|
19
|
+
}, {
|
|
20
|
+
'text': _chaynsDialog.buttonText.NO,
|
|
21
|
+
'buttonType': _chaynsDialog.buttonType.NEGATIVE
|
|
22
|
+
}];
|
|
23
|
+
}
|
|
24
|
+
dialog.tappIframeName = window.name;
|
|
25
|
+
dialog.callType = _chaynsDialog.dialogAction.IFRAME;
|
|
26
|
+
const site = (0, _index.getSite)();
|
|
27
|
+
dialog.url = `${dialog.url}${dialog.url.indexOf('?') >= 0 ? '&' : '?'}siteId=${site.id}`;
|
|
28
|
+
(0, _communication.addDialogDataListener)(_chaynsCallResponder, true);
|
|
29
|
+
return (0, _open.open)(dialog);
|
|
30
|
+
}
|
|
31
|
+
function _chaynsCallResponder(obj) {
|
|
32
|
+
if (obj.call.value.callback) {
|
|
33
|
+
const call = JSON.parse(JSON.stringify(obj)); // deep copy
|
|
34
|
+
(0, _index.invokeDialogCall)(obj).then(result => {
|
|
35
|
+
(0, _communication.sendData)({
|
|
36
|
+
result,
|
|
37
|
+
call
|
|
38
|
+
}, true);
|
|
39
|
+
});
|
|
40
|
+
} else {
|
|
41
|
+
(0, _index.invokeDialogCall)(obj);
|
|
42
|
+
}
|
|
43
|
+
}
|