fhdp-extenders 4.10.6-SNAPSHOT-1696606565019 → 4.10.6

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.
@@ -1,177 +1,177 @@
1
- export class Portal {
2
- constructor() {
3
- this.init();
4
- window['fhportal'] = this;
5
- }
6
-
7
- private MAX_VERSION = 2;
8
- private MIN_VERSION = 1;
9
- public static OBSERVER_CONFIG = { attributes: true, childList: true, subtree: true };
10
- public static OBSERVERS = [];
11
-
12
- private VERSION_STORE = {
13
- '1': this.version_1,
14
- '2': this.version_2
15
- }
16
-
17
- init() {
18
- if (!window['fhportal']) {
19
- const config = { attributes: true, childList: true, subtree: true };
20
- const observer = new MutationObserver(this.handleMutation);
21
- observer.observe(document.body, Portal.OBSERVER_CONFIG);
22
- }
23
- }
24
-
25
- version_1({sourceElement, portal, sourceId}) {
26
- const sourceCoords = sourceElement.getBoundingClientRect() as any;
27
- const portalCoords = portal.getBoundingClientRect() as any;
28
- if (portalCoords.x !== sourceCoords.x || portalCoords.y !== sourceCoords.y) {
29
- const newX = portalCoords.x - sourceCoords.x;
30
- const newY = portalCoords.y - sourceCoords.y;
31
- sourceElement.style.transform = `translate(${newX}px, ${newY}px)`;
32
- if (document.getElementById(sourceId).blur) {
33
- document.getElementById(sourceId).blur();
34
- }
35
- } else {
36
- setTimeout(() => {
37
- const sourceCoords = sourceElement.getBoundingClientRect() as any;
38
- const portalCoords = portal.getBoundingClientRect() as any;
39
- const newX = portalCoords.x - sourceCoords.x;
40
- const newY = portalCoords.y - sourceCoords.y;
41
- sourceElement.style.transform = `translate(${newX}px, ${newY}px)`;
42
- if (document.getElementById(sourceId).blur) {
43
- document.getElementById(sourceId).blur();
44
- }
45
- }, 500);
46
- }
47
- portal.setAttribute('used', 'true');
48
- }
49
-
50
- version_2({sourceElement, portal, sourceId}) {
51
- const replaceParentId = portal.getAttribute('replaceParentId')
52
- if (!!replaceParentId) {
53
- const oldParent = document.getElementsByClassName(replaceParentId)[0];
54
- if(!!oldParent) {
55
- oldParent.parentElement.appendChild(portal)
56
- oldParent.remove();
57
- }
58
- }
59
-
60
- portal.parentElement.appendChild(sourceElement);
61
- if (document.getElementById(sourceId) && document.getElementById(sourceId).blur) {
62
- document.getElementById(sourceId).blur();
63
- }
64
- portal.style.display = 'none';
65
- portal.setAttribute('used', 'true');
66
- const observer = new MutationObserver((mutationList, observer) => {
67
- if (!portal.parentElement.contains(sourceElement) && document.body.contains(portal)) {
68
- console.log("yoy nasty bastard!");
69
- portal.setAttribute('used', 'false');
70
- } else if (!document.body.contains(portal) || !document.body.contains(sourceElement)) {
71
- observer.disconnect();
72
- Portal.OBSERVERS[sourceId] = undefined;
73
- }
74
- });
75
- observer.observe(portal.parentElement, Portal.OBSERVER_CONFIG);
76
- if (Portal.OBSERVERS[sourceId]) {
77
- Portal.OBSERVERS[sourceId].disconnect();
78
- }
79
- Portal.OBSERVERS[sourceId] = observer;
80
- }
81
-
82
- processVersion(version: number, args: {[key: string]: any}) {
83
- const f = this.VERSION_STORE[`${version}`];
84
- console.log(version, args, f)
85
- if (f) {
86
- f(args)
87
- }
88
- }
89
-
90
-
91
-
92
- private handleMutation = (mutationList, observer) => {
93
- const portals = document.querySelectorAll('fh-portal[used="false"]');
94
- portals.forEach(portal => {
95
- try {
96
- const broken = portal.getAttribute('broken');
97
- if (!broken) {
98
- const searchClosestLike = portal.getAttribute('searchClosestLike');
99
- const searchParent = portal.getAttribute('searchParent');
100
- const sourceId = portal.getAttribute('objid');
101
- const classes = portal.getAttribute('classes');
102
- const wrapped = portal.getAttribute('wrapped');
103
- const layer = portal.getAttribute('layer');
104
- const v = portal.getAttribute('v');
105
- const removeWrapper = portal.getAttribute('removeWrapper');
106
- let isWrapped = false;
107
- let isRemoveWrapper = false;
108
- let isSearchClosest = false;
109
- let zIndex;
110
- let version;
111
- if (v !== undefined && !isNaN(Number.parseInt(v)) && Number.parseInt(v) >= this.MIN_VERSION && Number.parseInt(v) <= this.MAX_VERSION) {
112
- version = Number(v);
113
- } else {
114
- version = this.MAX_VERSION;
115
- }
116
- if (searchClosestLike) {
117
- isSearchClosest = searchClosestLike === 'true';
118
- }
119
- if (wrapped) {
120
- isWrapped = wrapped === 'true';
121
- }
122
- if (removeWrapper) {
123
- isRemoveWrapper = removeWrapper === 'true';
124
- }
125
- if (layer !== undefined) {
126
- zIndex = parseInt(layer);
127
- }
128
- let properClasses;
129
- if (classes) {
130
- properClasses = classes.split(',');
131
- }
132
-
133
- let sourceElement;
134
- if (isSearchClosest) {
135
- if (!searchParent) {
136
- console.error('missing searchParent!')
137
- } else {
138
- const parent = portal.closest(searchParent);
139
- sourceElement = parent.querySelector(`[id^='${sourceId}']`)
140
- }
141
- } else {
142
- sourceElement = document.getElementById(sourceId);
143
- }
144
- if (isWrapped) {
145
- while (!sourceElement.parentElement.classList.contains('wrapper')) {
146
- sourceElement = sourceElement.parentElement;
147
- }
148
- sourceElement = sourceElement.parentElement;
149
- } else if(isRemoveWrapper) {
150
- let parentWrapper = document.getElementById(sourceElement.id);
151
- while (!parentWrapper.parentElement.classList.contains('wrapper')) {
152
- parentWrapper = parentWrapper.parentElement;
153
- }
154
- parentWrapper.parentElement.remove();
155
- }
156
- if (zIndex) {
157
- sourceElement.style.zIndex = zIndex;
158
- }
159
- if (properClasses) {
160
- properClasses.forEach(cls => {
161
- sourceElement.classList.add(cls);
162
- });
163
- }
164
- if (sourceElement) {
165
- console.log(version, {sourceElement, portal, sourceId, properClasses});
166
- this.processVersion(version, {sourceElement, portal, sourceId, properClasses})
167
- } else {
168
- console.error(`There is no element (id: ${sourceId}) that can be portalled`);
169
- }
170
- }
171
- } catch (e) {
172
- portal.setAttribute('broken', 'true');
173
- console.error(e);
174
- }
175
- })
176
- }
177
- }
1
+ export class Portal {
2
+ constructor() {
3
+ this.init();
4
+ window['fhportal'] = this;
5
+ }
6
+
7
+ private MAX_VERSION = 2;
8
+ private MIN_VERSION = 1;
9
+ public static OBSERVER_CONFIG = { attributes: true, childList: true, subtree: true };
10
+ public static OBSERVERS = [];
11
+
12
+ private VERSION_STORE = {
13
+ '1': this.version_1,
14
+ '2': this.version_2
15
+ }
16
+
17
+ init() {
18
+ if (!window['fhportal']) {
19
+ const config = { attributes: true, childList: true, subtree: true };
20
+ const observer = new MutationObserver(this.handleMutation);
21
+ observer.observe(document.body, Portal.OBSERVER_CONFIG);
22
+ }
23
+ }
24
+
25
+ version_1({sourceElement, portal, sourceId}) {
26
+ const sourceCoords = sourceElement.getBoundingClientRect() as any;
27
+ const portalCoords = portal.getBoundingClientRect() as any;
28
+ if (portalCoords.x !== sourceCoords.x || portalCoords.y !== sourceCoords.y) {
29
+ const newX = portalCoords.x - sourceCoords.x;
30
+ const newY = portalCoords.y - sourceCoords.y;
31
+ sourceElement.style.transform = `translate(${newX}px, ${newY}px)`;
32
+ if (document.getElementById(sourceId).blur) {
33
+ document.getElementById(sourceId).blur();
34
+ }
35
+ } else {
36
+ setTimeout(() => {
37
+ const sourceCoords = sourceElement.getBoundingClientRect() as any;
38
+ const portalCoords = portal.getBoundingClientRect() as any;
39
+ const newX = portalCoords.x - sourceCoords.x;
40
+ const newY = portalCoords.y - sourceCoords.y;
41
+ sourceElement.style.transform = `translate(${newX}px, ${newY}px)`;
42
+ if (document.getElementById(sourceId).blur) {
43
+ document.getElementById(sourceId).blur();
44
+ }
45
+ }, 500);
46
+ }
47
+ portal.setAttribute('used', 'true');
48
+ }
49
+
50
+ version_2({sourceElement, portal, sourceId}) {
51
+ const replaceParentId = portal.getAttribute('replaceParentId')
52
+ if (!!replaceParentId) {
53
+ const oldParent = document.getElementsByClassName(replaceParentId)[0];
54
+ if(!!oldParent) {
55
+ oldParent.parentElement.appendChild(portal)
56
+ oldParent.remove();
57
+ }
58
+ }
59
+
60
+ portal.parentElement.appendChild(sourceElement);
61
+ if (document.getElementById(sourceId) && document.getElementById(sourceId).blur) {
62
+ document.getElementById(sourceId).blur();
63
+ }
64
+ portal.style.display = 'none';
65
+ portal.setAttribute('used', 'true');
66
+ const observer = new MutationObserver((mutationList, observer) => {
67
+ if (!portal.parentElement.contains(sourceElement) && document.body.contains(portal)) {
68
+ console.log("yoy nasty bastard!");
69
+ portal.setAttribute('used', 'false');
70
+ } else if (!document.body.contains(portal) || !document.body.contains(sourceElement)) {
71
+ observer.disconnect();
72
+ Portal.OBSERVERS[sourceId] = undefined;
73
+ }
74
+ });
75
+ observer.observe(portal.parentElement, Portal.OBSERVER_CONFIG);
76
+ if (Portal.OBSERVERS[sourceId]) {
77
+ Portal.OBSERVERS[sourceId].disconnect();
78
+ }
79
+ Portal.OBSERVERS[sourceId] = observer;
80
+ }
81
+
82
+ processVersion(version: number, args: {[key: string]: any}) {
83
+ const f = this.VERSION_STORE[`${version}`];
84
+ console.log(version, args, f)
85
+ if (f) {
86
+ f(args)
87
+ }
88
+ }
89
+
90
+
91
+
92
+ private handleMutation = (mutationList, observer) => {
93
+ const portals = document.querySelectorAll('fh-portal[used="false"]');
94
+ portals.forEach(portal => {
95
+ try {
96
+ const broken = portal.getAttribute('broken');
97
+ if (!broken) {
98
+ const searchClosestLike = portal.getAttribute('searchClosestLike');
99
+ const searchParent = portal.getAttribute('searchParent');
100
+ const sourceId = portal.getAttribute('objid');
101
+ const classes = portal.getAttribute('classes');
102
+ const wrapped = portal.getAttribute('wrapped');
103
+ const layer = portal.getAttribute('layer');
104
+ const v = portal.getAttribute('v');
105
+ const removeWrapper = portal.getAttribute('removeWrapper');
106
+ let isWrapped = false;
107
+ let isRemoveWrapper = false;
108
+ let isSearchClosest = false;
109
+ let zIndex;
110
+ let version;
111
+ if (v !== undefined && !isNaN(Number.parseInt(v)) && Number.parseInt(v) >= this.MIN_VERSION && Number.parseInt(v) <= this.MAX_VERSION) {
112
+ version = Number(v);
113
+ } else {
114
+ version = this.MAX_VERSION;
115
+ }
116
+ if (searchClosestLike) {
117
+ isSearchClosest = searchClosestLike === 'true';
118
+ }
119
+ if (wrapped) {
120
+ isWrapped = wrapped === 'true';
121
+ }
122
+ if (removeWrapper) {
123
+ isRemoveWrapper = removeWrapper === 'true';
124
+ }
125
+ if (layer !== undefined) {
126
+ zIndex = parseInt(layer);
127
+ }
128
+ let properClasses;
129
+ if (classes) {
130
+ properClasses = classes.split(',');
131
+ }
132
+
133
+ let sourceElement;
134
+ if (isSearchClosest) {
135
+ if (!searchParent) {
136
+ console.error('missing searchParent!')
137
+ } else {
138
+ const parent = portal.closest(searchParent);
139
+ sourceElement = parent.querySelector(`[id^='${sourceId}']`)
140
+ }
141
+ } else {
142
+ sourceElement = document.getElementById(sourceId);
143
+ }
144
+ if (isWrapped) {
145
+ while (!sourceElement.parentElement.classList.contains('wrapper')) {
146
+ sourceElement = sourceElement.parentElement;
147
+ }
148
+ sourceElement = sourceElement.parentElement;
149
+ } else if(isRemoveWrapper) {
150
+ let parentWrapper = document.getElementById(sourceElement.id);
151
+ while (!parentWrapper.parentElement.classList.contains('wrapper')) {
152
+ parentWrapper = parentWrapper.parentElement;
153
+ }
154
+ parentWrapper.parentElement.remove();
155
+ }
156
+ if (zIndex) {
157
+ sourceElement.style.zIndex = zIndex;
158
+ }
159
+ if (properClasses) {
160
+ properClasses.forEach(cls => {
161
+ sourceElement.classList.add(cls);
162
+ });
163
+ }
164
+ if (sourceElement) {
165
+ console.log(version, {sourceElement, portal, sourceId, properClasses});
166
+ this.processVersion(version, {sourceElement, portal, sourceId, properClasses})
167
+ } else {
168
+ console.error(`There is no element (id: ${sourceId}) that can be portalled`);
169
+ }
170
+ }
171
+ } catch (e) {
172
+ portal.setAttribute('broken', 'true');
173
+ console.error(e);
174
+ }
175
+ })
176
+ }
177
+ }
package/tsconfig.json CHANGED
@@ -1,18 +1,18 @@
1
- {
2
- "compilerOptions": {
3
- "jsx": "react",
4
- "sourceMap": true,
5
- "target": "es5",
6
- "outDir": "dist",
7
- "lib": ["es6", "dom"],
8
- "types": ["reflect-metadata", "jquery", "jqueryui", "bootstrap", "node"],
9
- "module": "commonjs",
10
- "baseUrl": "types",
11
- "moduleResolution": "node",
12
- "declaration": true,
13
- "experimentalDecorators": true,
14
- "emitDecoratorMetadata": true,
15
- "resolveJsonModule": true,
16
- },
17
- "exclude": ["node_modules", "target", "dist"]
18
- }
1
+ {
2
+ "compilerOptions": {
3
+ "jsx": "react",
4
+ "sourceMap": true,
5
+ "target": "es5",
6
+ "outDir": "dist",
7
+ "lib": ["es6", "dom"],
8
+ "types": ["reflect-metadata", "jquery", "jqueryui", "bootstrap", "node"],
9
+ "module": "commonjs",
10
+ "baseUrl": "types",
11
+ "moduleResolution": "node",
12
+ "declaration": true,
13
+ "experimentalDecorators": true,
14
+ "emitDecoratorMetadata": true,
15
+ "resolveJsonModule": true,
16
+ },
17
+ "exclude": ["node_modules", "target", "dist"]
18
+ }