@internetarchive/modal-manager 0.2.12 → 0.3.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.
Files changed (84) hide show
  1. package/.editorconfig +29 -29
  2. package/.eslintrc.js +14 -14
  3. package/.github/workflows/ci.yml +26 -26
  4. package/.github/workflows/gh-pages-main.yml +42 -0
  5. package/.github/workflows/pr-preview.yml +40 -0
  6. package/LICENSE +661 -661
  7. package/README.md +139 -139
  8. package/custom-elements.json +170 -170
  9. package/dist/index.d.ts +7 -7
  10. package/dist/index.js +5 -5
  11. package/dist/index.js.map +1 -1
  12. package/dist/src/modal-config.d.ts +92 -92
  13. package/dist/src/modal-config.js +22 -22
  14. package/dist/src/modal-config.js.map +1 -1
  15. package/dist/src/modal-manager-host-bridge-interface.d.ts +12 -12
  16. package/dist/src/modal-manager-host-bridge-interface.js +1 -0
  17. package/dist/src/modal-manager-host-bridge-interface.js.map +1 -1
  18. package/dist/src/modal-manager-host-bridge.d.ts +34 -34
  19. package/dist/src/modal-manager-host-bridge.js +62 -62
  20. package/dist/src/modal-manager-host-bridge.js.map +1 -1
  21. package/dist/src/modal-manager-interface.d.ts +25 -25
  22. package/dist/src/modal-manager-interface.js +1 -0
  23. package/dist/src/modal-manager-interface.js.map +1 -1
  24. package/dist/src/modal-manager-mode.d.ts +10 -10
  25. package/dist/src/modal-manager-mode.js +11 -11
  26. package/dist/src/modal-manager-mode.js.map +1 -1
  27. package/dist/src/modal-manager.d.ts +108 -108
  28. package/dist/src/modal-manager.js +192 -189
  29. package/dist/src/modal-manager.js.map +1 -1
  30. package/dist/src/modal-template.d.ts +32 -32
  31. package/dist/src/modal-template.js +276 -276
  32. package/dist/src/modal-template.js.map +1 -1
  33. package/dist/test/modal-config.test.d.ts +1 -1
  34. package/dist/test/modal-config.test.js +61 -61
  35. package/dist/test/modal-config.test.js.map +1 -1
  36. package/dist/test/modal-manager.test.d.ts +1 -1
  37. package/dist/test/modal-manager.test.js +204 -200
  38. package/dist/test/modal-manager.test.js.map +1 -1
  39. package/dist/test/modal-template.test.d.ts +1 -1
  40. package/dist/test/modal-template.test.js +95 -95
  41. package/dist/test/modal-template.test.js.map +1 -1
  42. package/dist/vite.config.d.ts +2 -0
  43. package/dist/vite.config.js +23 -0
  44. package/dist/vite.config.js.map +1 -0
  45. package/docs/assets/css/main.css +2678 -2678
  46. package/docs/classes/_src_modal_config_.modalconfig.html +429 -429
  47. package/docs/classes/_src_modal_manager_.modalmanager.html +7702 -7702
  48. package/docs/classes/_src_modal_manager_host_bridge_.modalmanagerhostbridge.html +409 -409
  49. package/docs/classes/_src_modal_template_.modaltemplate.html +7096 -7096
  50. package/docs/enums/_src_modal_manager_mode_.modalmanagermode.html +196 -196
  51. package/docs/globals.html +150 -150
  52. package/docs/index.html +252 -252
  53. package/docs/interfaces/_src_modal_manager_host_bridge_interface_.modalmanagerhostbridgeinterface.html +210 -210
  54. package/docs/interfaces/_src_modal_manager_interface_.modalmanagerinterface.html +7095 -7095
  55. package/docs/modules/_index_.html +208 -208
  56. package/docs/modules/_src_modal_config_.html +146 -146
  57. package/docs/modules/_src_modal_manager_.html +146 -146
  58. package/docs/modules/_src_modal_manager_host_bridge_.html +146 -146
  59. package/docs/modules/_src_modal_manager_host_bridge_interface_.html +146 -146
  60. package/docs/modules/_src_modal_manager_interface_.html +146 -146
  61. package/docs/modules/_src_modal_manager_mode_.html +146 -146
  62. package/docs/modules/_src_modal_template_.html +146 -146
  63. package/docs/modules/_test_modal_config_test_.html +106 -106
  64. package/docs/modules/_test_modal_manager_test_.html +106 -106
  65. package/docs/modules/_test_modal_template_test_.html +106 -106
  66. package/{demo/index.html → index.html} +278 -278
  67. package/index.ts +7 -7
  68. package/karma.conf.js +24 -24
  69. package/package.json +85 -82
  70. package/renovate.json +7 -0
  71. package/src/modal-config.ts +117 -117
  72. package/src/modal-manager-host-bridge-interface.ts +13 -13
  73. package/src/modal-manager-host-bridge.ts +82 -82
  74. package/src/modal-manager-interface.ts +28 -28
  75. package/src/modal-manager-mode.ts +10 -10
  76. package/src/modal-manager.ts +230 -228
  77. package/src/modal-template.ts +279 -279
  78. package/test/modal-config.test.ts +69 -69
  79. package/test/modal-manager.test.ts +250 -245
  80. package/test/modal-template.test.ts +111 -111
  81. package/tsconfig.json +21 -20
  82. package/vite.config.ts +23 -0
  83. /package/{demo → assets/images}/100x100.jpg +0 -0
  84. /package/{demo → assets/images}/200x200.jpg +0 -0
package/package.json CHANGED
@@ -1,82 +1,85 @@
1
- {
2
- "name": "@internetarchive/modal-manager",
3
- "version": "0.2.12",
4
- "description": "A Modal Manager Web Component",
5
- "repository": {
6
- "type": "git",
7
- "url": "https://github.com/internetarchive/iaux-modal-manager.git"
8
- },
9
- "license": "AGPL-3.0-only",
10
- "main": "dist/index.js",
11
- "module": "dist/index.js",
12
- "types": "dist/index.d.ts",
13
- "scripts": {
14
- "prepare": "npm run build",
15
- "start": "concurrently --kill-others --names tsc,es-dev-server \"npm run tsc:watch\" \"es-dev-server --app-index demo/index.html --node-resolve --open --watch --preserve-symlinks\"",
16
- "docs": "typedoc",
17
- "build": "tsc",
18
- "tsc:watch": "tsc --watch",
19
- "lint:eslint": "eslint --ext .ts . --ignore-path .gitignore",
20
- "format:eslint": "eslint --ext .ts . --fix --ignore-path .gitignore",
21
- "lint:prettier": "prettier \"**/*.ts\" --check --ignore-path .gitignore",
22
- "format:prettier": "prettier \"**/*.ts\" --write --ignore-path .gitignore",
23
- "lint": "npm run lint:eslint && npm run lint:prettier",
24
- "format": "npm run format:eslint && npm run format:prettier",
25
- "circular": "madge --circular .",
26
- "test": "tsc && npm run lint && npm run circular && karma start --coverage",
27
- "test:watch": "concurrently --kill-others --names tsc,karma \"npm run tsc:watch\" \"karma start --auto-watch=true --single-run=false\""
28
- },
29
- "dependencies": {
30
- "@internetarchive/ia-activity-indicator": "^0.0.4",
31
- "@internetarchive/icon-close": "^1.3.2",
32
- "@internetarchive/icon-ia-logo": "^1.3.2",
33
- "@internetarchive/icon-user": "^1.3.2",
34
- "lit": "^2.2.2",
35
- "throttle-debounce": "^5.0.0"
36
- },
37
- "devDependencies": {
38
- "@open-wc/eslint-config": "^2.0.0",
39
- "@open-wc/testing": "^3.0.3",
40
- "@open-wc/testing-karma": "^3.0.0",
41
- "@types/mocha": "^9.0.0",
42
- "@types/node": "13.11.1",
43
- "@types/throttle-debounce": "^5.0.0",
44
- "@typescript-eslint/eslint-plugin": "^2.20.0",
45
- "@typescript-eslint/parser": "^2.20.0",
46
- "concurrently": "^5.1.0",
47
- "deepmerge": "^3.2.0",
48
- "es-dev-server": "^1.23.0",
49
- "eslint": "^6.1.0",
50
- "eslint-config-prettier": "^6.11.0",
51
- "husky": "^1.0.0",
52
- "lint-staged": "^8.0.0",
53
- "lit-html": "^2.0.2",
54
- "madge": "^4.0.1",
55
- "prettier": "^2.0.4",
56
- "tslib": "^1.11.0",
57
- "typedoc": "^0.17.8",
58
- "typescript": "^3.9.7"
59
- },
60
- "eslintConfig": {
61
- "extends": [
62
- "@open-wc/eslint-config",
63
- "eslint-config-prettier"
64
- ]
65
- },
66
- "prettier": {
67
- "singleQuote": true,
68
- "arrowParens": "avoid"
69
- },
70
- "husky": {
71
- "hooks": {
72
- "pre-commit": "lint-staged"
73
- }
74
- },
75
- "lint-staged": {
76
- "*.ts": [
77
- "eslint --fix",
78
- "prettier --write",
79
- "git add"
80
- ]
81
- }
82
- }
1
+ {
2
+ "name": "@internetarchive/modal-manager",
3
+ "version": "0.3.0",
4
+ "description": "A Modal Manager Web Component",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/internetarchive/iaux-modal-manager.git"
8
+ },
9
+ "license": "AGPL-3.0-only",
10
+ "main": "dist/index.js",
11
+ "module": "dist/index.js",
12
+ "types": "dist/index.d.ts",
13
+ "scripts": {
14
+ "prepare": "npm run build && husky install",
15
+ "prepare:ghpages": "rimraf ghpages && npm run prepare && vite build && cp -R assets/images ghpages/assets/images",
16
+ "start": "concurrently --kill-others --names tsc,es-dev-server \"npm run tsc:watch\" \"es-dev-server --app-index index.html --node-resolve --open --watch --preserve-symlinks\"",
17
+ "docs": "typedoc",
18
+ "build": "tsc",
19
+ "tsc:watch": "tsc --watch",
20
+ "lint:eslint": "eslint --ext .ts . --ignore-path .gitignore",
21
+ "format:eslint": "eslint --ext .ts . --fix --ignore-path .gitignore",
22
+ "lint:prettier": "prettier \"**/*.ts\" --check --ignore-path .gitignore",
23
+ "format:prettier": "prettier \"**/*.ts\" --write --ignore-path .gitignore",
24
+ "lint": "npm run lint:eslint && npm run lint:prettier",
25
+ "format": "npm run format:eslint && npm run format:prettier",
26
+ "circular": "madge --circular .",
27
+ "test": "tsc && npm run lint && npm run circular && karma start --coverage",
28
+ "test:watch": "concurrently --kill-others --names tsc,karma \"npm run tsc:watch\" \"karma start --auto-watch=true --single-run=false\""
29
+ },
30
+ "dependencies": {
31
+ "@internetarchive/ia-activity-indicator": "^0.0.4",
32
+ "@internetarchive/icon-close": "^1.3.2",
33
+ "@internetarchive/icon-ia-logo": "^1.3.2",
34
+ "@internetarchive/icon-user": "^1.3.2",
35
+ "lit": "^2.2.2",
36
+ "throttle-debounce": "^5.0.0"
37
+ },
38
+ "devDependencies": {
39
+ "@open-wc/eslint-config": "^2.0.0",
40
+ "@open-wc/testing": "^3.0.3",
41
+ "@open-wc/testing-karma": "^3.0.0",
42
+ "@types/mocha": "^9.0.0",
43
+ "@types/node": "^20.8.4",
44
+ "@types/throttle-debounce": "^5.0.0",
45
+ "@typescript-eslint/eslint-plugin": "^2.20.0",
46
+ "@typescript-eslint/parser": "^2.20.0",
47
+ "concurrently": "^5.1.0",
48
+ "deepmerge": "^3.2.0",
49
+ "es-dev-server": "^1.23.0",
50
+ "eslint": "^6.1.0",
51
+ "eslint-config-prettier": "^6.11.0",
52
+ "husky": "^7.0.0",
53
+ "lint-staged": "^14.0.1",
54
+ "lit-html": "^2.0.2",
55
+ "madge": "^4.0.1",
56
+ "prettier": "^2.0.4",
57
+ "rimraf": "^5.0.5",
58
+ "tslib": "^1.11.0",
59
+ "typedoc": "^0.17.8",
60
+ "typescript": "^4.4.4",
61
+ "vite": "^4.4.11"
62
+ },
63
+ "eslintConfig": {
64
+ "extends": [
65
+ "@open-wc/eslint-config",
66
+ "eslint-config-prettier"
67
+ ]
68
+ },
69
+ "prettier": {
70
+ "singleQuote": true,
71
+ "arrowParens": "avoid"
72
+ },
73
+ "husky": {
74
+ "hooks": {
75
+ "pre-commit": "lint-staged"
76
+ }
77
+ },
78
+ "lint-staged": {
79
+ "*.ts": [
80
+ "eslint --fix",
81
+ "prettier --write",
82
+ "git add"
83
+ ]
84
+ }
85
+ }
package/renovate.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
+ "extends": [
4
+ "config:base",
5
+ ":preserveSemverRanges"
6
+ ]
7
+ }
@@ -1,117 +1,117 @@
1
- import { TemplateResult } from 'lit';
2
-
3
- /**
4
- * Configuration to show a modal
5
- *
6
- * @export
7
- * @class ModalConfig
8
- */
9
- export class ModalConfig {
10
- /**
11
- * The title that shows in the header
12
- *
13
- * @type {(TemplateResult | undefined)}
14
- * @memberof ModalConfig
15
- */
16
- title?: TemplateResult;
17
-
18
- /**
19
- * The subtitle shown in the header under the title
20
- *
21
- * @type {(TemplateResult | undefined)}
22
- * @memberof ModalConfig
23
- */
24
- subtitle?: TemplateResult;
25
-
26
- /**
27
- * The headline shown at the top of the content section
28
- *
29
- * @type {(TemplateResult | undefined)}
30
- * @memberof ModalConfig
31
- */
32
- headline?: TemplateResult;
33
-
34
- /**
35
- * The text shown below the headline in the content section
36
- *
37
- * @type {(TemplateResult | undefined)}
38
- * @memberof ModalConfig
39
- */
40
- message?: TemplateResult;
41
-
42
- /**
43
- * The background color of the header
44
- *
45
- * @memberof ModalConfig
46
- */
47
- headerColor: string;
48
-
49
- /**
50
- * The background color of the body
51
- *
52
- * @memberof ModalConfig
53
- */
54
- bodyColor: string;
55
-
56
- /**
57
- * Show or hide the processing indicator
58
- *
59
- * @memberof ModalConfig
60
- */
61
- showProcessingIndicator: boolean;
62
-
63
- /**
64
- * Set the processing image mode, currently `processing` or `complete`
65
- *
66
- * @memberof ModalConfig
67
- */
68
- processingImageMode: string;
69
-
70
- /**
71
- * Show the close button
72
- *
73
- * @memberof ModalConfig
74
- */
75
- showCloseButton: boolean;
76
-
77
- /**
78
- * Show the close button
79
- *
80
- * @memberof ModalConfig
81
- */
82
- showHeaderLogo: boolean;
83
-
84
- /**
85
- * Close the modal if the user taps on the background
86
- *
87
- * @memberof ModalConfig
88
- */
89
- closeOnBackdropClick: boolean;
90
-
91
- constructor(options?: {
92
- title?: TemplateResult;
93
- subtitle?: TemplateResult;
94
- headline?: TemplateResult;
95
- message?: TemplateResult;
96
- headerColor?: string;
97
- bodyColor?: string;
98
- showProcessingIndicator?: boolean;
99
- processingImageMode?: string;
100
- showCloseButton?: boolean;
101
- showHeaderLogo?: boolean;
102
- closeOnBackdropClick?: boolean;
103
- }) {
104
- this.title = options?.title;
105
- this.subtitle = options?.subtitle;
106
- this.headline = options?.headline;
107
- this.message = options?.message;
108
-
109
- this.headerColor = options?.headerColor ?? '#55A183';
110
- this.bodyColor = options?.bodyColor ?? '#f5f5f7';
111
- this.showProcessingIndicator = options?.showProcessingIndicator ?? false;
112
- this.processingImageMode = options?.processingImageMode ?? 'complete';
113
- this.showCloseButton = options?.showCloseButton ?? true;
114
- this.showHeaderLogo = options?.showHeaderLogo ?? true;
115
- this.closeOnBackdropClick = options?.closeOnBackdropClick ?? true;
116
- }
117
- }
1
+ import { TemplateResult } from 'lit';
2
+
3
+ /**
4
+ * Configuration to show a modal
5
+ *
6
+ * @export
7
+ * @class ModalConfig
8
+ */
9
+ export class ModalConfig {
10
+ /**
11
+ * The title that shows in the header
12
+ *
13
+ * @type {(TemplateResult | undefined)}
14
+ * @memberof ModalConfig
15
+ */
16
+ title?: TemplateResult;
17
+
18
+ /**
19
+ * The subtitle shown in the header under the title
20
+ *
21
+ * @type {(TemplateResult | undefined)}
22
+ * @memberof ModalConfig
23
+ */
24
+ subtitle?: TemplateResult;
25
+
26
+ /**
27
+ * The headline shown at the top of the content section
28
+ *
29
+ * @type {(TemplateResult | undefined)}
30
+ * @memberof ModalConfig
31
+ */
32
+ headline?: TemplateResult;
33
+
34
+ /**
35
+ * The text shown below the headline in the content section
36
+ *
37
+ * @type {(TemplateResult | undefined)}
38
+ * @memberof ModalConfig
39
+ */
40
+ message?: TemplateResult;
41
+
42
+ /**
43
+ * The background color of the header
44
+ *
45
+ * @memberof ModalConfig
46
+ */
47
+ headerColor: string;
48
+
49
+ /**
50
+ * The background color of the body
51
+ *
52
+ * @memberof ModalConfig
53
+ */
54
+ bodyColor: string;
55
+
56
+ /**
57
+ * Show or hide the processing indicator
58
+ *
59
+ * @memberof ModalConfig
60
+ */
61
+ showProcessingIndicator: boolean;
62
+
63
+ /**
64
+ * Set the processing image mode, currently `processing` or `complete`
65
+ *
66
+ * @memberof ModalConfig
67
+ */
68
+ processingImageMode: string;
69
+
70
+ /**
71
+ * Show the close button
72
+ *
73
+ * @memberof ModalConfig
74
+ */
75
+ showCloseButton: boolean;
76
+
77
+ /**
78
+ * Show the close button
79
+ *
80
+ * @memberof ModalConfig
81
+ */
82
+ showHeaderLogo: boolean;
83
+
84
+ /**
85
+ * Close the modal if the user taps on the background
86
+ *
87
+ * @memberof ModalConfig
88
+ */
89
+ closeOnBackdropClick: boolean;
90
+
91
+ constructor(options?: {
92
+ title?: TemplateResult;
93
+ subtitle?: TemplateResult;
94
+ headline?: TemplateResult;
95
+ message?: TemplateResult;
96
+ headerColor?: string;
97
+ bodyColor?: string;
98
+ showProcessingIndicator?: boolean;
99
+ processingImageMode?: string;
100
+ showCloseButton?: boolean;
101
+ showHeaderLogo?: boolean;
102
+ closeOnBackdropClick?: boolean;
103
+ }) {
104
+ this.title = options?.title;
105
+ this.subtitle = options?.subtitle;
106
+ this.headline = options?.headline;
107
+ this.message = options?.message;
108
+
109
+ this.headerColor = options?.headerColor ?? '#55A183';
110
+ this.bodyColor = options?.bodyColor ?? '#f5f5f7';
111
+ this.showProcessingIndicator = options?.showProcessingIndicator ?? false;
112
+ this.processingImageMode = options?.processingImageMode ?? 'complete';
113
+ this.showCloseButton = options?.showCloseButton ?? true;
114
+ this.showHeaderLogo = options?.showHeaderLogo ?? true;
115
+ this.closeOnBackdropClick = options?.closeOnBackdropClick ?? true;
116
+ }
117
+ }
@@ -1,13 +1,13 @@
1
- import { ModalManagerMode } from './modal-manager-mode';
2
-
3
- /**
4
- * The ModalManagerHostBridgeInterface is a delegate interface for
5
- * the host to implement environment-specific changes when the modal
6
- * is open or closed.
7
- *
8
- * A default implementation is provided, but can be overridden if
9
- * it does not work for the environment.
10
- */
11
- export interface ModalManagerHostBridgeInterface {
12
- handleModeChange(mode: ModalManagerMode): void;
13
- }
1
+ import { ModalManagerMode } from './modal-manager-mode';
2
+
3
+ /**
4
+ * The ModalManagerHostBridgeInterface is a delegate interface for
5
+ * the host to implement environment-specific changes when the modal
6
+ * is open or closed.
7
+ *
8
+ * A default implementation is provided, but can be overridden if
9
+ * it does not work for the environment.
10
+ */
11
+ export interface ModalManagerHostBridgeInterface {
12
+ handleModeChange(mode: ModalManagerMode): void;
13
+ }
@@ -1,82 +1,82 @@
1
- import { throttle } from 'throttle-debounce';
2
-
3
- import { ModalManagerHostBridgeInterface } from './modal-manager-host-bridge-interface';
4
- import { ModalManagerInterface } from './modal-manager-interface';
5
- import { ModalManagerMode } from './modal-manager-mode';
6
-
7
- /**
8
- * The `ModalManagerHostBridge` is a bridge between the `ModalManager` and the
9
- * host that sets up environment-specific changes when the modal opens and closes.
10
- *
11
- * For instance, when the modal opens, this adds a class to the `<body>` tag for styling
12
- * and adds a `resize` listener to fix a Safari shadow root issue.
13
- *
14
- * Consumers can create their own `ModalManagerHostBridgeInterface` classes and pass
15
- * them into the `ModalManager` if this one does not work for their environment.
16
- *
17
- * @export
18
- * @class ModalManagerHostBridge
19
- * @implements {ModalManagerHostBridgeInterface}
20
- */
21
- export class ModalManagerHostBridge implements ModalManagerHostBridgeInterface {
22
- private modalManager: ModalManagerInterface;
23
-
24
- constructor(modalManager: ModalManagerInterface) {
25
- this.modalManager = modalManager;
26
- }
27
-
28
- /**
29
- * Handle the mode change
30
- *
31
- * @private
32
- * @memberof ModalManager
33
- */
34
- handleModeChange(mode: ModalManagerMode): void {
35
- switch (mode) {
36
- case ModalManagerMode.Open:
37
- this.startResizeListener();
38
- this.stopDocumentScroll();
39
- break;
40
- case ModalManagerMode.Closed:
41
- this.stopResizeListener();
42
- this.resumeDocumentScroll();
43
- break;
44
- }
45
- }
46
-
47
- private windowResizeThrottler: throttle<() => void> = throttle(
48
- 100,
49
- this.updateModalContainerHeight,
50
- { noLeading: false, noTrailing: false }
51
- ).bind(this);
52
-
53
- // This is a workaround for Safari. Safari does not update shadowRoot elements calculated
54
- // based on the viewport size (ie. `calc(100vh - 10px)`). It does an initial calculation correctly,
55
- // but resizing the window does not cause the calculation to update. Firefox and Chrome both handle
56
- // this correctly.
57
- // It doesn't matter what css variable you set, it is just forcing Safari to do an update.
58
- // Also note that the value has to change on each update for Safari to do the update,
59
- // ie. you can't just set a static value.
60
- private updateModalContainerHeight(): void {
61
- this.modalManager.style.setProperty(
62
- '--containerHeight',
63
- `${window.innerHeight}px`
64
- );
65
- }
66
-
67
- private stopDocumentScroll(): void {
68
- document.body.classList.add('modal-manager-open');
69
- }
70
-
71
- private resumeDocumentScroll(): void {
72
- document.body.classList.remove('modal-manager-open');
73
- }
74
-
75
- private startResizeListener(): void {
76
- window.addEventListener('resize', this.windowResizeThrottler);
77
- }
78
-
79
- private stopResizeListener(): void {
80
- window.removeEventListener('resize', this.windowResizeThrottler);
81
- }
82
- }
1
+ import { throttle } from 'throttle-debounce';
2
+
3
+ import { ModalManagerHostBridgeInterface } from './modal-manager-host-bridge-interface';
4
+ import { ModalManagerInterface } from './modal-manager-interface';
5
+ import { ModalManagerMode } from './modal-manager-mode';
6
+
7
+ /**
8
+ * The `ModalManagerHostBridge` is a bridge between the `ModalManager` and the
9
+ * host that sets up environment-specific changes when the modal opens and closes.
10
+ *
11
+ * For instance, when the modal opens, this adds a class to the `<body>` tag for styling
12
+ * and adds a `resize` listener to fix a Safari shadow root issue.
13
+ *
14
+ * Consumers can create their own `ModalManagerHostBridgeInterface` classes and pass
15
+ * them into the `ModalManager` if this one does not work for their environment.
16
+ *
17
+ * @export
18
+ * @class ModalManagerHostBridge
19
+ * @implements {ModalManagerHostBridgeInterface}
20
+ */
21
+ export class ModalManagerHostBridge implements ModalManagerHostBridgeInterface {
22
+ private modalManager: ModalManagerInterface;
23
+
24
+ constructor(modalManager: ModalManagerInterface) {
25
+ this.modalManager = modalManager;
26
+ }
27
+
28
+ /**
29
+ * Handle the mode change
30
+ *
31
+ * @private
32
+ * @memberof ModalManager
33
+ */
34
+ handleModeChange(mode: ModalManagerMode): void {
35
+ switch (mode) {
36
+ case ModalManagerMode.Open:
37
+ this.startResizeListener();
38
+ this.stopDocumentScroll();
39
+ break;
40
+ case ModalManagerMode.Closed:
41
+ this.stopResizeListener();
42
+ this.resumeDocumentScroll();
43
+ break;
44
+ }
45
+ }
46
+
47
+ private windowResizeThrottler: throttle<() => void> = throttle(
48
+ 100,
49
+ this.updateModalContainerHeight,
50
+ { noLeading: false, noTrailing: false }
51
+ ).bind(this);
52
+
53
+ // This is a workaround for Safari. Safari does not update shadowRoot elements calculated
54
+ // based on the viewport size (ie. `calc(100vh - 10px)`). It does an initial calculation correctly,
55
+ // but resizing the window does not cause the calculation to update. Firefox and Chrome both handle
56
+ // this correctly.
57
+ // It doesn't matter what css variable you set, it is just forcing Safari to do an update.
58
+ // Also note that the value has to change on each update for Safari to do the update,
59
+ // ie. you can't just set a static value.
60
+ private updateModalContainerHeight(): void {
61
+ this.modalManager.style.setProperty(
62
+ '--containerHeight',
63
+ `${window.innerHeight}px`
64
+ );
65
+ }
66
+
67
+ private stopDocumentScroll(): void {
68
+ document.body.classList.add('modal-manager-open');
69
+ }
70
+
71
+ private resumeDocumentScroll(): void {
72
+ document.body.classList.remove('modal-manager-open');
73
+ }
74
+
75
+ private startResizeListener(): void {
76
+ window.addEventListener('resize', this.windowResizeThrottler);
77
+ }
78
+
79
+ private stopResizeListener(): void {
80
+ window.removeEventListener('resize', this.windowResizeThrottler);
81
+ }
82
+ }
@@ -1,28 +1,28 @@
1
- import { LitElement, TemplateResult } from 'lit';
2
- import { ModalConfig } from './modal-config';
3
- import { ModalManagerMode } from './modal-manager-mode';
4
-
5
- export interface ModalManagerInterface extends LitElement {
6
- /**
7
- * Get the current modal mode.
8
- */
9
- getMode(): ModalManagerMode;
10
-
11
- /**
12
- * Show a modal from a given ModalConfig
13
- *
14
- * @param config ModalConfig
15
- * @param customModalContent TemplateResult | undefined
16
- * @param userClosedModalCallback () => void | undefined an optional callback when the modal is closed
17
- */
18
- showModal(options: {
19
- config: ModalConfig;
20
- customModalContent?: TemplateResult;
21
- userClosedModalCallback?: () => void;
22
- }): Promise<void>;
23
-
24
- /**
25
- * Close the currently open modal
26
- */
27
- closeModal(): void;
28
- }
1
+ import { LitElement, TemplateResult } from 'lit';
2
+ import { ModalConfig } from './modal-config';
3
+ import { ModalManagerMode } from './modal-manager-mode';
4
+
5
+ export interface ModalManagerInterface extends LitElement {
6
+ /**
7
+ * Get the current modal mode.
8
+ */
9
+ getMode(): ModalManagerMode;
10
+
11
+ /**
12
+ * Show a modal from a given ModalConfig
13
+ *
14
+ * @param config ModalConfig
15
+ * @param customModalContent TemplateResult | undefined
16
+ * @param userClosedModalCallback () => void | undefined an optional callback when the modal is closed
17
+ */
18
+ showModal(options: {
19
+ config: ModalConfig;
20
+ customModalContent?: TemplateResult;
21
+ userClosedModalCallback?: () => void;
22
+ }): Promise<void>;
23
+
24
+ /**
25
+ * Close the currently open modal
26
+ */
27
+ closeModal(): void;
28
+ }