surveysparrow-ionic-plugin 2.0.3-beta.1 → 2.0.4-beta.1
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/dist/angular-ui/fesm2022/angular-ui.mjs +1203 -998
- package/dist/angular-ui/fesm2022/angular-ui.mjs.map +1 -1
- package/dist/angular-ui/index.d.ts +119 -5
- package/dist/docs.json +13 -5
- package/dist/esm/angular-ui/lib/public-api.js.map +1 -1
- package/dist/esm/angular-ui/lib/spotcheck.component.d.ts +30 -1
- package/dist/esm/angular-ui/lib/spotcheck.component.js +194 -4
- package/dist/esm/angular-ui/lib/spotcheck.component.js.map +1 -1
- package/dist/esm/angular-ui/lib/spotchecks/components/builder.component.d.ts +57 -0
- package/dist/esm/angular-ui/lib/spotchecks/components/builder.component.js +284 -0
- package/dist/esm/angular-ui/lib/spotchecks/components/builder.component.js.map +1 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/binding.d.ts +25 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/binding.js +107 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/binding.js.map +1 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/device.d.ts +11 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/device.js +48 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/device.js.map +1 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/executables.d.ts +4 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/executables.js +113 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/executables.js.map +1 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/listener.d.ts +9 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/listener.js +55 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/listener.js.map +1 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/render.d.ts +5 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/render.js +43 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/render.js.map +1 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/sentry.d.ts +7 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/sentry.js +115 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/sentry.js.map +1 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/storage.d.ts +3 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/storage.js +40 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/storage.js.map +1 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/survey-page.d.ts +22 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/survey-page.js +128 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/survey-page.js.map +1 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/version.d.ts +2 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/version.js +4 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/version.js.map +1 -0
- package/dist/esm/angular-ui/lib/spotchecks/index.d.ts +4 -3
- package/dist/esm/angular-ui/lib/spotchecks/index.js +2 -2
- package/dist/esm/angular-ui/lib/spotchecks/index.js.map +1 -1
- package/dist/esm/angular-ui/lib/spotchecks/spotcheck.d.ts +8 -0
- package/dist/esm/angular-ui/lib/spotchecks/spotcheck.js +147 -0
- package/dist/esm/angular-ui/lib/spotchecks/spotcheck.js.map +1 -0
- package/dist/esm/angular-ui/lib/spotchecks/state/store.d.ts +14 -0
- package/dist/esm/angular-ui/lib/spotchecks/state/store.js +109 -0
- package/dist/esm/angular-ui/lib/spotchecks/state/store.js.map +1 -0
- package/dist/esm/angular-ui/lib/spotchecks/types.d.ts +22 -58
- package/dist/esm/angular-ui/lib/spotchecks/types.js.map +1 -1
- package/dist/plugin.cjs.js +1211 -51762
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +1209 -51761
- package/dist/plugin.js.map +1 -1
- package/package.json +4 -8
- package/src/angular-ui/lib/public-api.ts +1 -1
- package/src/angular-ui/lib/spotcheck.component.ts +202 -5
- package/src/angular-ui/lib/spotchecks/components/builder.component.ts +254 -0
- package/src/angular-ui/lib/spotchecks/helpers/binding.ts +126 -0
- package/src/angular-ui/lib/spotchecks/helpers/device.ts +51 -0
- package/src/angular-ui/lib/spotchecks/helpers/executables.ts +124 -0
- package/src/angular-ui/lib/spotchecks/helpers/listener.ts +61 -0
- package/src/angular-ui/lib/spotchecks/helpers/render.ts +44 -0
- package/src/angular-ui/lib/spotchecks/helpers/sentry.ts +127 -0
- package/src/angular-ui/lib/spotchecks/helpers/storage.ts +37 -0
- package/src/angular-ui/lib/spotchecks/helpers/survey-page.ts +120 -0
- package/src/angular-ui/lib/spotchecks/helpers/version.ts +3 -0
- package/src/angular-ui/lib/spotchecks/index.ts +11 -3
- package/src/angular-ui/lib/spotchecks/spotcheck.ts +150 -0
- package/src/angular-ui/lib/spotchecks/state/store.ts +126 -0
- package/src/angular-ui/lib/spotchecks/types.ts +26 -59
- package/src/angular-ui/ng-package.json +9 -12
- package/src/angular-ui/package.json +9 -8
- package/dist/angular-ui/esm2022/angular-ui.mjs +0 -5
- package/dist/angular-ui/esm2022/public-api.mjs +0 -3
- package/dist/angular-ui/esm2022/spotcheck.component.mjs +0 -17
- package/dist/angular-ui/esm2022/spotchecks/SpotCheck.mjs +0 -51
- package/dist/angular-ui/esm2022/spotchecks/SpotCheckComponent.mjs +0 -410
- package/dist/angular-ui/esm2022/spotchecks/SpotCheckEventListener.mjs +0 -26
- package/dist/angular-ui/esm2022/spotchecks/SpotcheckStateService.mjs +0 -67
- package/dist/angular-ui/esm2022/spotchecks/api.mjs +0 -230
- package/dist/angular-ui/esm2022/spotchecks/helpers.mjs +0 -338
- package/dist/angular-ui/esm2022/spotchecks/index.mjs +0 -3
- package/dist/angular-ui/esm2022/spotchecks/storage.mjs +0 -7
- package/dist/angular-ui/esm2022/spotchecks/types.mjs +0 -2
- package/dist/angular-ui/public-api.d.ts +0 -2
- package/dist/angular-ui/spotcheck.component.d.ts +0 -5
- package/dist/angular-ui/spotchecks/SpotCheck.d.ts +0 -4
- package/dist/angular-ui/spotchecks/SpotCheckComponent.d.ts +0 -65
- package/dist/angular-ui/spotchecks/SpotCheckEventListener.d.ts +0 -16
- package/dist/angular-ui/spotchecks/SpotcheckStateService.d.ts +0 -12
- package/dist/angular-ui/spotchecks/api.d.ts +0 -15
- package/dist/angular-ui/spotchecks/helpers.d.ts +0 -30
- package/dist/angular-ui/spotchecks/index.d.ts +0 -3
- package/dist/angular-ui/spotchecks/storage.d.ts +0 -2
- package/dist/angular-ui/spotchecks/types.d.ts +0 -80
- package/dist/esm/angular-ui/lib/spotchecks/SpotCheck.d.ts +0 -4
- package/dist/esm/angular-ui/lib/spotchecks/SpotCheck.js +0 -51
- package/dist/esm/angular-ui/lib/spotchecks/SpotCheck.js.map +0 -1
- package/dist/esm/angular-ui/lib/spotchecks/SpotCheckComponent.d.ts +0 -56
- package/dist/esm/angular-ui/lib/spotchecks/SpotCheckComponent.js +0 -397
- package/dist/esm/angular-ui/lib/spotchecks/SpotCheckComponent.js.map +0 -1
- package/dist/esm/angular-ui/lib/spotchecks/SpotCheckEventListener.d.ts +0 -16
- package/dist/esm/angular-ui/lib/spotchecks/SpotCheckEventListener.js +0 -28
- package/dist/esm/angular-ui/lib/spotchecks/SpotCheckEventListener.js.map +0 -1
- package/dist/esm/angular-ui/lib/spotchecks/SpotcheckStateService.d.ts +0 -9
- package/dist/esm/angular-ui/lib/spotchecks/SpotcheckStateService.js +0 -72
- package/dist/esm/angular-ui/lib/spotchecks/SpotcheckStateService.js.map +0 -1
- package/dist/esm/angular-ui/lib/spotchecks/api.d.ts +0 -15
- package/dist/esm/angular-ui/lib/spotchecks/api.js +0 -232
- package/dist/esm/angular-ui/lib/spotchecks/api.js.map +0 -1
- package/dist/esm/angular-ui/lib/spotchecks/helpers.d.ts +0 -30
- package/dist/esm/angular-ui/lib/spotchecks/helpers.js +0 -304
- package/dist/esm/angular-ui/lib/spotchecks/helpers.js.map +0 -1
- package/dist/esm/angular-ui/lib/spotchecks/storage.d.ts +0 -2
- package/dist/esm/angular-ui/lib/spotchecks/storage.js +0 -7
- package/dist/esm/angular-ui/lib/spotchecks/storage.js.map +0 -1
- package/src/angular-ui/lib/spotchecks/SpotCheck.ts +0 -54
- package/src/angular-ui/lib/spotchecks/SpotCheckComponent.css +0 -7
- package/src/angular-ui/lib/spotchecks/SpotCheckComponent.html +0 -27
- package/src/angular-ui/lib/spotchecks/SpotCheckComponent.ts +0 -389
- package/src/angular-ui/lib/spotchecks/SpotCheckEventListener.ts +0 -50
- package/src/angular-ui/lib/spotchecks/SpotcheckStateService.ts +0 -66
- package/src/angular-ui/lib/spotchecks/api.ts +0 -286
- package/src/angular-ui/lib/spotchecks/helpers.ts +0 -414
- package/src/angular-ui/lib/spotchecks/storage.ts +0 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "surveysparrow-ionic-plugin",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4-beta.1",
|
|
4
4
|
"description": "SurveySparrow SDK enables you to collect feedback from your mobile app. Embed the Classic, Chat & NPS surveys in your ionic application seamlessly with few lines of code.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/plugin.cjs.js",
|
|
@@ -77,22 +77,20 @@
|
|
|
77
77
|
"@capacitor/device": "^7.0.2",
|
|
78
78
|
"@capacitor/docgen": "^0.3.0",
|
|
79
79
|
"@capacitor/ios": "^7.0.0",
|
|
80
|
-
"@ionic/angular": "^8.7.5",
|
|
81
80
|
"@ionic/eslint-config": "^0.4.0",
|
|
82
81
|
"@ionic/prettier-config": "^4.0.0",
|
|
83
82
|
"@ionic/swiftlint-config": "^2.0.0",
|
|
84
83
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
85
|
-
"axios": "^1.12.2",
|
|
86
84
|
"eslint": "^8.57.0",
|
|
87
|
-
"ng-packagr": "^
|
|
85
|
+
"ng-packagr": "^20.3.0",
|
|
88
86
|
"prettier": "^3.4.2",
|
|
89
87
|
"prettier-plugin-java": "^2.6.6",
|
|
90
88
|
"rimraf": "^6.0.1",
|
|
91
89
|
"rollup": "^4.30.1",
|
|
92
|
-
"rxjs": "^7.8.2",
|
|
93
90
|
"swiftlint": "^2.0.0",
|
|
94
91
|
"typescript": "5.8.3",
|
|
95
|
-
"
|
|
92
|
+
"@angular/router": "^20.3.2",
|
|
93
|
+
"rxjs": "^7.8.2"
|
|
96
94
|
},
|
|
97
95
|
"peerDependencies": {
|
|
98
96
|
"@capacitor/core": ">=7.0.0"
|
|
@@ -112,9 +110,7 @@
|
|
|
112
110
|
},
|
|
113
111
|
"dependencies": {
|
|
114
112
|
"@capacitor/device": "^7.0.2",
|
|
115
|
-
"axios": "^1.12.2",
|
|
116
113
|
"tslib": "^2.3.0",
|
|
117
|
-
"uuid": "^13.0.0",
|
|
118
114
|
"@types/node": "^24.5.2"
|
|
119
115
|
}
|
|
120
116
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './spotcheck.component';
|
|
2
|
-
export * from './spotchecks';
|
|
2
|
+
export * from './spotchecks';
|
|
@@ -1,10 +1,207 @@
|
|
|
1
|
-
import { Component } from '@angular/core';
|
|
2
|
-
import {
|
|
1
|
+
import { ChangeDetectorRef, Component, NgZone, OnDestroy, OnInit, PLATFORM_ID, inject } from '@angular/core';
|
|
2
|
+
import { NgIf, isPlatformBrowser } from '@angular/common';
|
|
3
|
+
import { GuardsCheckEnd, NavigationEnd, Router } from '@angular/router';
|
|
4
|
+
import { SsNodeComponent } from './spotchecks/components/builder.component';
|
|
5
|
+
import { componentStore, spotcheckStore } from './spotchecks/state/store';
|
|
6
|
+
import { dispatchWrapper, execute } from './spotchecks/helpers/executables';
|
|
7
|
+
import { captureP1Error } from './spotchecks/helpers/sentry';
|
|
8
|
+
import { setAppRunner } from './spotchecks/helpers/listener';
|
|
9
|
+
import { batched, guardedDetectChanges, hasCrashed, onCrash } from './spotchecks/helpers/render';
|
|
10
|
+
import type { BuilderContext, SchemaNode } from './spotchecks/helpers/binding';
|
|
3
11
|
|
|
12
|
+
// Path only: query or hash changes stay on the same screen.
|
|
13
|
+
const pathOf = (url: string) => (url || '').split(/[?#]/)[0];
|
|
14
|
+
|
|
15
|
+
// Only one <SpotCheck> renders; extra instances stay empty so they never touch the live page.
|
|
16
|
+
let owner: SpotCheck | null = null;
|
|
17
|
+
|
|
18
|
+
// Keyboard cover below this is browser chrome, not a keyboard.
|
|
19
|
+
const MIN_KEYBOARD_HEIGHT = 80;
|
|
20
|
+
|
|
21
|
+
// Place once at the app root: <SpotCheck />. One Angular codebase for web, Android and iOS.
|
|
4
22
|
@Component({
|
|
5
23
|
selector: 'SpotCheck',
|
|
6
|
-
template: `<SpotCheckComponent />`,
|
|
7
24
|
standalone: true,
|
|
8
|
-
imports: [
|
|
25
|
+
imports: [NgIf, SsNodeComponent],
|
|
26
|
+
styles: [':host { display: contents; }'],
|
|
27
|
+
template: `
|
|
28
|
+
<ss-node *ngIf="wrapperSchema" [node]="wrapperSchema" [ctx]="wrapperCtx"></ss-node>
|
|
29
|
+
<ss-node *ngIf="buttonSchema && buttonReady" [node]="buttonSchema" [ctx]="buttonCtx"></ss-node>
|
|
30
|
+
`,
|
|
9
31
|
})
|
|
10
|
-
export class SpotCheck {
|
|
32
|
+
export class SpotCheck implements OnInit, OnDestroy {
|
|
33
|
+
wrapperSchema: SchemaNode | null = null;
|
|
34
|
+
buttonSchema: SchemaNode | null = null;
|
|
35
|
+
wrapperCtx: BuilderContext = {};
|
|
36
|
+
buttonCtx: BuilderContext = {};
|
|
37
|
+
buttonReady = false;
|
|
38
|
+
|
|
39
|
+
private wrapperStyles: any = {
|
|
40
|
+
overlayStyle: { position: 'fixed', height: 0, opacity: 0, zIndex: -999999, pointerEvents: 'none' },
|
|
41
|
+
wrapperStyle: {},
|
|
42
|
+
};
|
|
43
|
+
private buttonStyles: any = {};
|
|
44
|
+
private destroyed = false;
|
|
45
|
+
private cleanups: Array<() => void> = [];
|
|
46
|
+
private lastInjectionKey: any[] = [];
|
|
47
|
+
private lastButtonKey: any[] = [];
|
|
48
|
+
private lastPath: string | null = null;
|
|
49
|
+
|
|
50
|
+
private readonly cdr = inject(ChangeDetectorRef);
|
|
51
|
+
private readonly zone = inject(NgZone);
|
|
52
|
+
private readonly router = inject(Router, { optional: true });
|
|
53
|
+
private readonly isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
|
|
54
|
+
|
|
55
|
+
private readonly webviewHandlers = {
|
|
56
|
+
classicWebViewRefCallback: (ref: any) => execute('webviewComponent.classicWebViewRefCallback', { ref }),
|
|
57
|
+
chatWebViewRefCallback: (ref: any) => execute('webviewComponent.chatWebViewRefCallback', { ref }),
|
|
58
|
+
handleOnMessage: (event: any) => execute('webviewComponent.handleWebViewMessage', { event }),
|
|
59
|
+
handleOnError: (error: any) => execute('webviewComponent.handleWebViewError', { error }),
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
private readonly buttonHandlers = {
|
|
63
|
+
handleSpotCheckButtonPress: () => execute('spotCheckButton.handleSpotCheckButtonPress'),
|
|
64
|
+
handleSideTabLayout: (event: any) => execute('spotCheckButton.handleSideTabLayout', { event }),
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
private readonly scheduleRender = batched(() => {
|
|
68
|
+
if (!this.destroyed) this.render();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
private readonly scheduleWrapperStyles = batched(() => {
|
|
72
|
+
if (this.destroyed) return;
|
|
73
|
+
execute('wrapper.getWrapperStyles', {
|
|
74
|
+
screenHeight: window.innerHeight,
|
|
75
|
+
screenWidth: window.innerWidth,
|
|
76
|
+
setStyles: (styles: any) => {
|
|
77
|
+
this.wrapperStyles = styles;
|
|
78
|
+
this.scheduleRender();
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
ngOnInit(): void {
|
|
84
|
+
// Server render (SSR) or a second instance: render nothing.
|
|
85
|
+
if (!this.isBrowser || owner) return;
|
|
86
|
+
owner = this;
|
|
87
|
+
// App callbacks run inside Angular so the app's own UI updates.
|
|
88
|
+
setAppRunner((fn) => this.zone.run(fn));
|
|
89
|
+
this.cleanups.push(spotcheckStore.subscribe(() => this.onStateChange()));
|
|
90
|
+
this.cleanups.push(componentStore.subscribe(() => this.onStateChange()));
|
|
91
|
+
this.cleanups.push(onCrash(() => this.hideAfterCrash()));
|
|
92
|
+
this.watchWindow();
|
|
93
|
+
this.watchRouter();
|
|
94
|
+
this.onStateChange();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
ngOnDestroy(): void {
|
|
98
|
+
if (owner === this) owner = null;
|
|
99
|
+
this.destroyed = true;
|
|
100
|
+
this.cleanups.forEach((cleanup) => cleanup());
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Same triggers as the other SDKs' Wrapper / WebViewComponent / SpotCheckButton effects.
|
|
104
|
+
private onStateChange(): void {
|
|
105
|
+
const state = spotcheckStore.getState().SpotCheckState;
|
|
106
|
+
const { webViewDetails, spotCheckDetails } = state;
|
|
107
|
+
|
|
108
|
+
this.scheduleWrapperStyles();
|
|
109
|
+
|
|
110
|
+
const injectionKey = [webViewDetails.isChatLoading, webViewDetails.isClassicLoading, webViewDetails.webViewInjectionData];
|
|
111
|
+
if (injectionKey.some((value, i) => value !== this.lastInjectionKey[i])) {
|
|
112
|
+
this.lastInjectionKey = injectionKey;
|
|
113
|
+
execute('webviewComponent.handleWebViewInjection');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const buttonKey = [spotCheckDetails.spotCheckButtonConfig, spotCheckDetails.isSpotCheckButton, spotCheckDetails.sideTabButtonWidth];
|
|
117
|
+
if (buttonKey.some((value, i) => value !== this.lastButtonKey[i])) {
|
|
118
|
+
this.lastButtonKey = buttonKey;
|
|
119
|
+
execute('spotCheckButton.getSpotCheckButtonStyles').then((result) => {
|
|
120
|
+
if (!result) return;
|
|
121
|
+
this.buttonStyles = result;
|
|
122
|
+
this.scheduleRender();
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
this.scheduleRender();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private render(): void {
|
|
130
|
+
if (hasCrashed()) return;
|
|
131
|
+
const state = spotcheckStore.getState().SpotCheckState;
|
|
132
|
+
const componentState = componentStore.getState().componentState;
|
|
133
|
+
const schemas = componentState.isLoaded ? componentState.schemas || {} : {};
|
|
134
|
+
|
|
135
|
+
this.wrapperSchema = schemas.wrapper || null;
|
|
136
|
+
this.buttonSchema = schemas.spotCheckButton || null;
|
|
137
|
+
this.wrapperCtx = {
|
|
138
|
+
state,
|
|
139
|
+
styles: this.wrapperStyles,
|
|
140
|
+
slots: {
|
|
141
|
+
children: {
|
|
142
|
+
schema: schemas.webviewComponent || null,
|
|
143
|
+
context: { state, handlers: this.webviewHandlers },
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
this.buttonCtx = { state, styles: this.buttonStyles, handlers: this.buttonHandlers };
|
|
148
|
+
// Wait for styles so the button never renders unstyled for a frame.
|
|
149
|
+
this.buttonReady = Object.keys(this.buttonStyles || {}).length > 0;
|
|
150
|
+
guardedDetectChanges(this.cdr, 'render');
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// After a failed draw, SpotCheck renders nothing for the rest of the session (RN error boundary parity).
|
|
154
|
+
private hideAfterCrash(): void {
|
|
155
|
+
this.wrapperSchema = null;
|
|
156
|
+
this.buttonSchema = null;
|
|
157
|
+
try {
|
|
158
|
+
this.cdr.detectChanges();
|
|
159
|
+
} catch {}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Screen size and the part of it the on-screen keyboard covers.
|
|
163
|
+
private watchWindow(): void {
|
|
164
|
+
const vv: any = (window as any).visualViewport;
|
|
165
|
+
const onResize = () => {
|
|
166
|
+
let keyboard = 0;
|
|
167
|
+
if (vv) keyboard = Math.round(window.innerHeight - vv.height - vv.offsetTop);
|
|
168
|
+
if (keyboard < MIN_KEYBOARD_HEIGHT) keyboard = 0;
|
|
169
|
+
const current = spotcheckStore.getState().SpotCheckState.spotCheckDetails.keyBoardHeight || 0;
|
|
170
|
+
if (keyboard !== current) dispatchWrapper({ spotCheckDetails: { keyBoardHeight: keyboard } });
|
|
171
|
+
else this.scheduleWrapperStyles();
|
|
172
|
+
};
|
|
173
|
+
this.zone.runOutsideAngular(() => {
|
|
174
|
+
window.addEventListener('resize', onResize);
|
|
175
|
+
vv?.addEventListener('resize', onResize);
|
|
176
|
+
vv?.addEventListener('scroll', onResize);
|
|
177
|
+
});
|
|
178
|
+
this.cleanups.push(() => {
|
|
179
|
+
window.removeEventListener('resize', onResize);
|
|
180
|
+
vv?.removeEventListener('resize', onResize);
|
|
181
|
+
vv?.removeEventListener('scroll', onResize);
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Leaving a screen closes its spotcheck. GuardsCheckEnd comes after guards and redirects
|
|
186
|
+
// (a blocked navigation keeps the survey) and before the new page's trackScreen.
|
|
187
|
+
private watchRouter(): void {
|
|
188
|
+
if (!this.router) return;
|
|
189
|
+
this.lastPath = this.router.navigated ? pathOf(this.router.url) : null;
|
|
190
|
+
const subscription = this.router.events.subscribe((event) => {
|
|
191
|
+
try {
|
|
192
|
+
if (event instanceof GuardsCheckEnd && event.shouldActivate) {
|
|
193
|
+
const next = pathOf(event.urlAfterRedirects);
|
|
194
|
+
if (this.lastPath !== null && next !== this.lastPath) {
|
|
195
|
+
execute('handleNavigationChange');
|
|
196
|
+
}
|
|
197
|
+
this.lastPath = next;
|
|
198
|
+
} else if (event instanceof NavigationEnd) {
|
|
199
|
+
this.lastPath = pathOf(event.urlAfterRedirects);
|
|
200
|
+
}
|
|
201
|
+
} catch (error: any) {
|
|
202
|
+
captureP1Error(error, 'GENERAL', { action: 'navigationListener', errorMessage: error?.message });
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
this.cleanups.push(() => subscription.unsubscribe());
|
|
206
|
+
}
|
|
207
|
+
}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ChangeDetectorRef,
|
|
3
|
+
Component,
|
|
4
|
+
Directive,
|
|
5
|
+
ElementRef,
|
|
6
|
+
EventEmitter,
|
|
7
|
+
Input,
|
|
8
|
+
NgZone,
|
|
9
|
+
OnChanges,
|
|
10
|
+
OnDestroy,
|
|
11
|
+
OnInit,
|
|
12
|
+
Output,
|
|
13
|
+
ViewEncapsulation,
|
|
14
|
+
forwardRef,
|
|
15
|
+
} from '@angular/core';
|
|
16
|
+
import { NgFor, NgIf, NgStyle, NgSwitch, NgSwitchCase } from '@angular/common';
|
|
17
|
+
import { componentStore, spotcheckStore } from '../state/store';
|
|
18
|
+
import { execute } from '../helpers/executables';
|
|
19
|
+
import { SurveyPage } from '../helpers/survey-page';
|
|
20
|
+
import { batched, guardedDetectChanges } from '../helpers/render';
|
|
21
|
+
import {
|
|
22
|
+
BuilderContext,
|
|
23
|
+
SchemaNode,
|
|
24
|
+
SlotContent,
|
|
25
|
+
evaluateCondition,
|
|
26
|
+
resolveBinding,
|
|
27
|
+
toCss,
|
|
28
|
+
} from '../helpers/binding';
|
|
29
|
+
|
|
30
|
+
// Reports the element's untransformed width like RN onLayout ({ nativeEvent: { layout } }).
|
|
31
|
+
@Directive({ selector: '[ssLayout]', standalone: true })
|
|
32
|
+
export class LayoutDirective implements OnInit, OnDestroy {
|
|
33
|
+
@Output() ssLayout = new EventEmitter<any>();
|
|
34
|
+
private observer?: ResizeObserver;
|
|
35
|
+
private last = '';
|
|
36
|
+
|
|
37
|
+
constructor(private el: ElementRef<HTMLElement>, private zone: NgZone) {}
|
|
38
|
+
|
|
39
|
+
ngOnInit(): void {
|
|
40
|
+
if (typeof ResizeObserver === 'undefined') return;
|
|
41
|
+
this.zone.runOutsideAngular(() => {
|
|
42
|
+
this.observer = new ResizeObserver(() => {
|
|
43
|
+
const node = this.el.nativeElement;
|
|
44
|
+
const layout = { x: node.offsetLeft, y: node.offsetTop, width: node.offsetWidth, height: node.offsetHeight };
|
|
45
|
+
const key = `${layout.width}x${layout.height}`;
|
|
46
|
+
if (key === this.last) return;
|
|
47
|
+
this.last = key;
|
|
48
|
+
this.ssLayout.emit({ nativeEvent: { layout } });
|
|
49
|
+
});
|
|
50
|
+
this.observer.observe(this.el.nativeElement);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
ngOnDestroy(): void {
|
|
55
|
+
this.observer?.disconnect();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Hosts one survey page; mirrors the RN WebViewRenderer (hidden pages stay 1x1 off-screen and keep loading).
|
|
60
|
+
@Component({
|
|
61
|
+
selector: 'ss-webview-renderer',
|
|
62
|
+
standalone: true,
|
|
63
|
+
template: '',
|
|
64
|
+
host: { '[style]': 'hostStyle' },
|
|
65
|
+
})
|
|
66
|
+
export class WebViewRendererComponent implements OnChanges, OnDestroy {
|
|
67
|
+
@Input() uri = '';
|
|
68
|
+
@Input() canShow = false;
|
|
69
|
+
@Input() onMessage?: (event: any) => void;
|
|
70
|
+
@Input() onError?: (error: any) => void;
|
|
71
|
+
@Input() refCallback?: (ref: any) => void;
|
|
72
|
+
|
|
73
|
+
hostStyle = '';
|
|
74
|
+
private page?: SurveyPage;
|
|
75
|
+
|
|
76
|
+
constructor(private el: ElementRef<HTMLElement>) {}
|
|
77
|
+
|
|
78
|
+
ngOnChanges(): void {
|
|
79
|
+
this.hostStyle = this.canShow
|
|
80
|
+
? 'display:block;position:relative;width:100%;height:100%;'
|
|
81
|
+
: 'display:block;position:absolute;left:-1000px;top:0;width:1px;height:1px;opacity:0;overflow:hidden;';
|
|
82
|
+
if (!this.uri) return;
|
|
83
|
+
if (!this.page) {
|
|
84
|
+
this.page = new SurveyPage(this.el.nativeElement, {
|
|
85
|
+
onMessage: (data) => this.onMessage?.({ nativeEvent: { data } }),
|
|
86
|
+
onError: (error) => this.onError?.(error),
|
|
87
|
+
});
|
|
88
|
+
this.refCallback?.(this.page);
|
|
89
|
+
}
|
|
90
|
+
this.page.load(this.uri);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
ngOnDestroy(): void {
|
|
94
|
+
this.refCallback?.(null);
|
|
95
|
+
this.page?.destroy();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Renders one backend schema node as HTML (same node rules as the other SDKs' Builder).
|
|
100
|
+
@Component({
|
|
101
|
+
selector: 'ss-node',
|
|
102
|
+
standalone: true,
|
|
103
|
+
encapsulation: ViewEncapsulation.None,
|
|
104
|
+
imports: [
|
|
105
|
+
NgIf, NgFor, NgStyle, NgSwitch, NgSwitchCase, LayoutDirective, WebViewRendererComponent,
|
|
106
|
+
forwardRef(() => CloseButtonComponent),
|
|
107
|
+
],
|
|
108
|
+
styles: [`
|
|
109
|
+
ss-node, ss-close-button { display: contents; }
|
|
110
|
+
.ss-node-box, .ss-node-pressable, .ss-node-text, .ss-node-image, .ss-node-svg { box-sizing: border-box; }
|
|
111
|
+
.ss-node-pressable { -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
|
|
112
|
+
.ss-node-pressable:active { opacity: 0.6; }
|
|
113
|
+
.ss-node-pressable:focus { outline: none; }
|
|
114
|
+
`],
|
|
115
|
+
template: `
|
|
116
|
+
<ng-container *ngIf="visible" [ngSwitch]="kind">
|
|
117
|
+
<ng-container *ngSwitchCase="'slot'">
|
|
118
|
+
<ss-node *ngIf="slot?.schema" [node]="slot!.schema!" [ctx]="slot!.context"></ss-node>
|
|
119
|
+
</ng-container>
|
|
120
|
+
<div *ngSwitchCase="'Box'" class="ss-node-box" [attr.data-ss-role]="role" [ngStyle]="css">
|
|
121
|
+
<ss-node *ngFor="let child of children; trackBy: byIndex" [node]="child" [ctx]="ctx"></ss-node>
|
|
122
|
+
</div>
|
|
123
|
+
<div *ngSwitchCase="'Pressable'" class="ss-node-pressable" role="button" tabindex="0"
|
|
124
|
+
[attr.data-ss-role]="role" [attr.aria-label]="props['ariaLabel'] || null" [ngStyle]="css"
|
|
125
|
+
(click)="press($event)" (keydown.enter)="press($event)" (ssLayout)="layout($event)">
|
|
126
|
+
<ss-node *ngFor="let child of children; trackBy: byIndex" [node]="child" [ctx]="ctx"></ss-node>
|
|
127
|
+
</div>
|
|
128
|
+
<span *ngSwitchCase="'Text'" class="ss-node-text" [ngStyle]="css">{{ content }}</span>
|
|
129
|
+
<!-- A failed image keeps its space but shows nothing, like iOS and Flutter. -->
|
|
130
|
+
<img *ngSwitchCase="'Image'" class="ss-node-image" [attr.data-ss-role]="role" [src]="props['src']" [ngStyle]="css" alt=""
|
|
131
|
+
(error)="$any($event.target).style.visibility = 'hidden'" (load)="$any($event.target).style.visibility = ''" />
|
|
132
|
+
<img *ngSwitchCase="'SvgXml'" class="ss-node-svg" [src]="svgSrc" [ngStyle]="css" alt="" />
|
|
133
|
+
<ss-close-button *ngSwitchCase="'CloseButton'"></ss-close-button>
|
|
134
|
+
<ss-webview-renderer *ngSwitchCase="'WebViewRenderer'"
|
|
135
|
+
[attr.data-ss-webview]="node.meta?.['webViewType']"
|
|
136
|
+
[uri]="props['uri']" [canShow]="props['canShow']" [onMessage]="props['onMessage']"
|
|
137
|
+
[onError]="props['onError']" [refCallback]="props['ref']"></ss-webview-renderer>
|
|
138
|
+
</ng-container>
|
|
139
|
+
`,
|
|
140
|
+
})
|
|
141
|
+
export class SsNodeComponent implements OnChanges {
|
|
142
|
+
@Input() node!: SchemaNode;
|
|
143
|
+
@Input() ctx: BuilderContext = {};
|
|
144
|
+
|
|
145
|
+
visible = false;
|
|
146
|
+
kind = '';
|
|
147
|
+
role: string | null = null;
|
|
148
|
+
props: Record<string, any> = {};
|
|
149
|
+
css: Record<string, string> | null = null;
|
|
150
|
+
content: any = null;
|
|
151
|
+
slot: SlotContent | null = null;
|
|
152
|
+
svgSrc = '';
|
|
153
|
+
children: SchemaNode[] = [];
|
|
154
|
+
|
|
155
|
+
// Binding results are computed once per render so templates see stable values.
|
|
156
|
+
ngOnChanges(): void {
|
|
157
|
+
const node = this.node;
|
|
158
|
+
const ctx = this.ctx || {};
|
|
159
|
+
this.slot = null;
|
|
160
|
+
if (!node) {
|
|
161
|
+
this.visible = false;
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (node.slot) {
|
|
165
|
+
this.kind = 'slot';
|
|
166
|
+
this.slot = ctx.slots?.[node.slot] || null;
|
|
167
|
+
this.visible = Boolean(this.slot);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
this.visible = node.if === undefined || evaluateCondition(node.if, ctx);
|
|
171
|
+
if (!this.visible) return;
|
|
172
|
+
this.kind = node.type || '';
|
|
173
|
+
this.role = (node.meta?.componentRole as string) || null;
|
|
174
|
+
this.props = node.props ? resolveBinding(node.props, ctx) || {} : {};
|
|
175
|
+
this.css = toCss(this.props['style']);
|
|
176
|
+
this.content = node.content !== undefined ? resolveBinding(node.content, ctx) : null;
|
|
177
|
+
this.children = node.children || [];
|
|
178
|
+
if (this.kind === 'SvgXml') {
|
|
179
|
+
const xml = typeof this.props['xml'] === 'string' ? this.props['xml'] : '';
|
|
180
|
+
// As an image, so markup in the icon can never run script.
|
|
181
|
+
this.svgSrc = xml ? `data:image/svg+xml;charset=utf-8,${encodeURIComponent(xml)}` : '';
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
byIndex(index: number): number {
|
|
186
|
+
return index;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
press(event: Event): void {
|
|
190
|
+
event.stopPropagation();
|
|
191
|
+
this.props['onPress']?.(event);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
layout(event: any): void {
|
|
195
|
+
this.props['onLayout']?.(event);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Backend-driven close button (schema closeButton + closeButton.getCloseButtonStyles).
|
|
200
|
+
@Component({
|
|
201
|
+
selector: 'ss-close-button',
|
|
202
|
+
standalone: true,
|
|
203
|
+
imports: [NgIf, SsNodeComponent],
|
|
204
|
+
template: `<ss-node *ngIf="schema" [node]="schema" [ctx]="ctx"></ss-node>`,
|
|
205
|
+
})
|
|
206
|
+
export class CloseButtonComponent implements OnInit, OnDestroy {
|
|
207
|
+
schema: SchemaNode | null = null;
|
|
208
|
+
ctx: BuilderContext = {};
|
|
209
|
+
|
|
210
|
+
private styles: any = {};
|
|
211
|
+
private styleKey: any[] = [];
|
|
212
|
+
private unsubscribers: Array<() => void> = [];
|
|
213
|
+
private readonly handlers = {
|
|
214
|
+
handleClosePress: () => {
|
|
215
|
+
execute('closeButton.handleCloseButton');
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
private destroyed = false;
|
|
220
|
+
private readonly scheduleRender = batched(() => {
|
|
221
|
+
if (this.destroyed) return;
|
|
222
|
+
this.ctx = { state: spotcheckStore.getState().SpotCheckState, styles: this.styles, handlers: this.handlers };
|
|
223
|
+
guardedDetectChanges(this.cdr, 'closeButtonRender');
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
constructor(private cdr: ChangeDetectorRef) {}
|
|
227
|
+
|
|
228
|
+
ngOnInit(): void {
|
|
229
|
+
this.unsubscribers.push(spotcheckStore.subscribe(() => this.update()));
|
|
230
|
+
this.unsubscribers.push(componentStore.subscribe(() => this.update()));
|
|
231
|
+
this.update();
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
ngOnDestroy(): void {
|
|
235
|
+
this.destroyed = true;
|
|
236
|
+
this.unsubscribers.forEach((unsubscribe) => unsubscribe());
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
private update(): void {
|
|
240
|
+
const state = spotcheckStore.getState().SpotCheckState;
|
|
241
|
+
const componentState = componentStore.getState().componentState;
|
|
242
|
+
this.schema = componentState.isLoaded ? componentState.schemas?.closeButton || null : null;
|
|
243
|
+
const key = [state.spotCheckDetails.closeButton, state.spotCheckDetails.isRTLLanguage];
|
|
244
|
+
if (key[0] !== this.styleKey[0] || key[1] !== this.styleKey[1]) {
|
|
245
|
+
this.styleKey = key;
|
|
246
|
+
execute('closeButton.getCloseButtonStyles').then((result) => {
|
|
247
|
+
if (!result) return;
|
|
248
|
+
this.styles = result;
|
|
249
|
+
this.scheduleRender();
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
this.scheduleRender();
|
|
253
|
+
}
|
|
254
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { captureP1Error } from './sentry';
|
|
2
|
+
import { execute, hasFunction } from './executables';
|
|
3
|
+
|
|
4
|
+
export interface SchemaNode {
|
|
5
|
+
type?: string;
|
|
6
|
+
props?: Record<string, any>;
|
|
7
|
+
children?: SchemaNode[];
|
|
8
|
+
if?: any;
|
|
9
|
+
slot?: string;
|
|
10
|
+
meta?: { componentRole?: string; [key: string]: unknown };
|
|
11
|
+
content?: any;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface SlotContent {
|
|
15
|
+
schema: SchemaNode | null;
|
|
16
|
+
context: BuilderContext;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface BuilderContext {
|
|
20
|
+
state?: any;
|
|
21
|
+
styles?: any;
|
|
22
|
+
slots?: Record<string, SlotContent>;
|
|
23
|
+
handlers?: Record<string, (...args: any[]) => void>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Same binding rules as the other SDKs' Builder.
|
|
27
|
+
const evaluateExpression = (expr: string, context: BuilderContext): any => {
|
|
28
|
+
try {
|
|
29
|
+
const safeContext = { state: context.state, styles: context.styles, Math };
|
|
30
|
+
const func = new Function(...Object.keys(safeContext), `return ${expr}`);
|
|
31
|
+
return func(...Object.values(safeContext));
|
|
32
|
+
} catch (error: any) {
|
|
33
|
+
captureP1Error(error, 'GENERAL', {
|
|
34
|
+
action: 'evaluateExpression',
|
|
35
|
+
expression: expr?.substring(0, 200),
|
|
36
|
+
errorMessage: error?.message,
|
|
37
|
+
});
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const readPath = (root: any, path: string) => {
|
|
43
|
+
let result = root;
|
|
44
|
+
for (const key of path.split('.')) result = result?.[key];
|
|
45
|
+
return result;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const resolveBinding = (value: any, context: BuilderContext): any => {
|
|
49
|
+
if (!value || typeof value !== 'object') return value;
|
|
50
|
+
if (Array.isArray(value)) return value.map((item) => resolveBinding(item, context));
|
|
51
|
+
|
|
52
|
+
if (value.$expr) return evaluateExpression(value.$expr, context);
|
|
53
|
+
if (value.$ref) return readPath(context, value.$ref);
|
|
54
|
+
if (value.$path) return readPath(context.state, value.$path);
|
|
55
|
+
if (value.$handler && context.handlers) return context.handlers[value.$handler];
|
|
56
|
+
|
|
57
|
+
// Generic action: `{ $execute: 'group.fn', args: {...} }` runs a backend function; unknown names do nothing.
|
|
58
|
+
if (typeof value.$execute === 'string') {
|
|
59
|
+
const functionName = value.$execute;
|
|
60
|
+
const args = value.args && typeof value.args === 'object' ? value.args : {};
|
|
61
|
+
return (event?: any) => {
|
|
62
|
+
if (!functionName || !hasFunction(functionName)) return;
|
|
63
|
+
const nativeEvent = event?.nativeEvent;
|
|
64
|
+
const eventData = nativeEvent && typeof nativeEvent === 'object' ? { ...nativeEvent } : undefined;
|
|
65
|
+
execute(functionName, eventData ? { ...args, event: eventData } : { ...args }).catch(() => {});
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (Array.isArray(value.$handlers) && context.handlers) {
|
|
70
|
+
return (...args: any[]) => {
|
|
71
|
+
value.$handlers.forEach((name: string) => context.handlers?.[name]?.(...args));
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const resolved: Record<string, any> = {};
|
|
76
|
+
for (const key in value) resolved[key] = resolveBinding(value[key], context);
|
|
77
|
+
return resolved;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const pair = (cond: any, op: string, context: BuilderContext) =>
|
|
81
|
+
cond[op].map((val: any) => resolveBinding(val, context));
|
|
82
|
+
|
|
83
|
+
export const evaluateCondition = (condition: any, context: BuilderContext): boolean => {
|
|
84
|
+
if (!condition) return true;
|
|
85
|
+
|
|
86
|
+
if (typeof condition === 'object' && !Array.isArray(condition)) {
|
|
87
|
+
if (Array.isArray(condition.$and)) return condition.$and.every((c: any) => evaluateCondition(c, context));
|
|
88
|
+
if (Array.isArray(condition.$or)) return condition.$or.some((c: any) => evaluateCondition(c, context));
|
|
89
|
+
if (condition.$not !== undefined) return !evaluateCondition(condition.$not, context);
|
|
90
|
+
if (Array.isArray(condition.$eq) && condition.$eq.length === 2) {
|
|
91
|
+
const [l, r] = pair(condition, '$eq', context);
|
|
92
|
+
return l === r;
|
|
93
|
+
}
|
|
94
|
+
if (Array.isArray(condition.$ne) && condition.$ne.length === 2) {
|
|
95
|
+
const [l, r] = pair(condition, '$ne', context);
|
|
96
|
+
return l !== r;
|
|
97
|
+
}
|
|
98
|
+
if (Array.isArray(condition.$gt) && condition.$gt.length === 2) {
|
|
99
|
+
const [l, r] = pair(condition, '$gt', context);
|
|
100
|
+
return l > r;
|
|
101
|
+
}
|
|
102
|
+
if (Array.isArray(condition.$lt) && condition.$lt.length === 2) {
|
|
103
|
+
const [l, r] = pair(condition, '$lt', context);
|
|
104
|
+
return l < r;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return Boolean(resolveBinding(condition, context));
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// CSS properties that take plain numbers; every other number is px.
|
|
112
|
+
const UNITLESS = new Set([
|
|
113
|
+
'opacity', 'zIndex', 'flex', 'flexGrow', 'flexShrink', 'fontWeight', 'order', 'aspectRatio', 'scale',
|
|
114
|
+
]);
|
|
115
|
+
|
|
116
|
+
// Backend styles are CSS objects with camelCase keys.
|
|
117
|
+
export const toCss = (style: any): Record<string, string> | null => {
|
|
118
|
+
if (!style || typeof style !== 'object' || Array.isArray(style)) return null;
|
|
119
|
+
const css: Record<string, string> = {};
|
|
120
|
+
for (const key of Object.keys(style)) {
|
|
121
|
+
const value = style[key];
|
|
122
|
+
if (value == null || typeof value === 'object') continue;
|
|
123
|
+
css[key] = typeof value === 'number' && !UNITLESS.has(key) ? `${value}px` : String(value);
|
|
124
|
+
}
|
|
125
|
+
return css;
|
|
126
|
+
};
|