|
1 | | -import { WMLUIProperty,WMLUIFrameworkType, WMLUIGlobal, WMLDeepPartial } from "./models"; |
| 1 | +import {WMLUIFrameworkType, WMLUIGlobal, WMLDeepPartial, WML_DOCUMENT, WML_WINDOW } from "./models"; |
| 2 | + |
2 | 3 |
|
3 | 4 | export function detectFramework(): WMLUIFrameworkType { |
4 | | - let myWindow: any = window ?? {}; |
| 5 | + |
| 6 | + |
5 | 7 | let detectedFramework: WMLUIFrameworkType = 'VanillaJS'; |
6 | 8 |
|
7 | | - const isReact = !!document.querySelector('[data-reactroot], [data-reactid]'); |
8 | | - const isAngular = !!myWindow.ng || !!document.querySelector('[ng-version]'); |
9 | | - const isVue = !!myWindow.Vue; |
10 | | - const isSvelte = !!document.querySelector('[class*="svelte-"]'); |
11 | | - const isEmber = !!myWindow.Ember || !!document.querySelector('[id*="ember"]'); |
12 | | - const isBackbone = !!myWindow.Backbone; |
13 | | - const isPreact = !!myWindow.preact || !!document.querySelector('[data-preactroot]'); |
14 | | - const isNext = !!document.querySelector('#__next') || !!myWindow.__NEXT_DATA__; |
15 | | - const isNuxt = !!myWindow.__NUXT__; |
16 | | - const isGatsby = !!myWindow.___gatsby; |
17 | | - const isRemix = typeof myWindow.__remixManifest !== 'undefined'; |
18 | | - const isNest = !!document.querySelector('[ng-version]') && !!myWindow.NestFactory; |
19 | | - const isLit = !!myWindow.litHtml || !!document.querySelector('template[shadowroot]'); |
20 | | - const isAlpine = !!myWindow.Alpine; |
21 | | - const isMithril = !!myWindow.m || !!document.querySelector('[data-mithril]'); |
22 | | - const isAurelia = !!myWindow.Aurelia; |
23 | | - const isRiot = !!myWindow.riot; |
24 | | - const isInferno = !!myWindow.Inferno; |
25 | | - const isStencil = !!document.querySelector('script[data-stencil-namespace]'); |
| 9 | + const isReact = !!WML_DOCUMENT.querySelector?.('[data-reactroot], [data-reactid]'); |
| 10 | + const isAngular = !!WML_WINDOW.ng || !!WML_DOCUMENT.querySelector?.('[ng-version]'); |
| 11 | + const isVue = !!WML_WINDOW.Vue; |
| 12 | + const isSvelte = !!WML_DOCUMENT.querySelector?.('[class*="svelte-"]'); |
| 13 | + const isEmber = !!WML_WINDOW.Ember || !!WML_DOCUMENT.querySelector?.('[id*="ember"]'); |
| 14 | + const isBackbone = !!WML_WINDOW.Backbone; |
| 15 | + const isPreact = !!WML_WINDOW.preact || !!WML_DOCUMENT.querySelector?.('[data-preactroot]'); |
| 16 | + const isNext = !!WML_DOCUMENT.querySelector?.('#__next') || !!WML_WINDOW.__NEXT_DATA__; |
| 17 | + const isNuxt = !!WML_WINDOW.__NUXT__; |
| 18 | + const isGatsby = !!WML_WINDOW.___gatsby; |
| 19 | + const isRemix = typeof WML_WINDOW.__remixManifest !== 'undefined'; |
| 20 | + const isNest = !!WML_DOCUMENT.querySelector?.('[ng-version]') && !!WML_WINDOW.NestFactory; |
| 21 | + const isLit = !!WML_WINDOW.litHtml || !!WML_DOCUMENT.querySelector?.('template[shadowroot]'); |
| 22 | + const isAlpine = !!WML_WINDOW.Alpine; |
| 23 | + const isMithril = !!WML_WINDOW.m || !!WML_DOCUMENT.querySelector?.('[data-mithril]'); |
| 24 | + const isAurelia = !!WML_WINDOW.Aurelia; |
| 25 | + const isRiot = !!WML_WINDOW.riot; |
| 26 | + const isInferno = !!WML_WINDOW.Inferno; |
| 27 | + const isStencil = !!WML_DOCUMENT.querySelector?.('script[data-stencil-namespace]'); |
26 | 28 |
|
27 | 29 | if (isReact) detectedFramework = 'React'; |
28 | 30 | else if (isAngular) detectedFramework = 'Angular'; |
@@ -68,7 +70,8 @@ export function getGlobalObject ():any { |
68 | 70 | return globalThis; // ECMAScript standard global object |
69 | 71 | } |
70 | 72 | if (typeof window !== 'undefined') { |
71 | | - return window; // Browser environment |
| 73 | + // TODO double check if this should be returned |
| 74 | + return WML_WINDOW; // Browser environment |
72 | 75 | } |
73 | 76 | // @ts-ignore |
74 | 77 | if (typeof global !== 'undefined') { |
@@ -164,43 +167,40 @@ export let toggleClassString =(targetClass:string,classList:Array<string>,pred |
164 | 167 | /** |
165 | 168 | * @obsolete, cant get to work properly |
166 | 169 | */ |
167 | | -let WMLUIPropertyDecorator = (target:any,key:any)=>{ |
168 | | - let text = target[key]; |
169 | | - let uiProperty = new WMLUIProperty({ |
170 | | - text |
171 | | - }) |
172 | | - const getter = () => uiProperty; |
173 | | - |
174 | | - const setter = (newValue: any) => { |
175 | | - uiProperty = newValue; |
176 | | - }; |
177 | | - |
178 | | - Object.defineProperty(target, key, { |
179 | | - get: getter, |
180 | | - set: setter, |
181 | | - enumerable: true, |
182 | | - configurable: true, |
183 | | - }); |
184 | | -} |
| 170 | +// let WMLUIPropertyDecorator = (target:any,key:any)=>{ |
| 171 | +// let text = target[key]; |
| 172 | +// let uiProperty = new WMLUIProperty({ |
| 173 | +// text |
| 174 | +// }) |
| 175 | +// const getter = () => uiProperty; |
| 176 | + |
| 177 | +// const setter = (newValue: any) => { |
| 178 | +// uiProperty = newValue; |
| 179 | +// }; |
| 180 | + |
| 181 | +// Object.defineProperty(target, key, { |
| 182 | +// get: getter, |
| 183 | +// set: setter, |
| 184 | +// enumerable: true, |
| 185 | +// configurable: true, |
| 186 | +// }); |
| 187 | +// } |
185 | 188 |
|
186 | 189 |
|
187 | 190 | export let generateRandomNumber = (range: number = 100, additional: number = 0) => { |
188 | 191 | return Math.floor(Math.random() * range) + additional |
189 | 192 | } |
190 | 193 |
|
191 | | - |
192 | 194 | export let generateRandomColor = () => { |
193 | 195 | let randomNumber = generateRandomNumber(0xFFFFFF); |
194 | 196 | let hexColor = randomNumber.toString(16).padStart(6, '0'); |
195 | 197 | return `#${hexColor}`; |
196 | 198 | }; |
197 | 199 |
|
198 | | - |
199 | 200 | export let selectRandomOptionFromArray = (myArray: Array<any>, index?: number) => { |
200 | 201 | return myArray[generateRandomNumber(index ?? myArray.length)] |
201 | 202 | } |
202 | 203 |
|
203 | | - |
204 | 204 | export const replaceValuesWithPaths = <T = any>( |
205 | 205 | obj: any, |
206 | 206 | path = "", |
|
0 commit comments