@teamvortexsoftware/vortex-react-native 0.0.12 → 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.
Files changed (33) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +1227 -11
  3. package/package.json +102 -18
  4. package/dist/components/ShareButtons.js +0 -170
  5. package/dist/hooks/useThemeStyles.js +0 -39
  6. package/dist/hooks/useVortexInvite.js +0 -279
  7. package/dist/index.js +0 -5
  8. package/dist/shared/InvitationResult.js +0 -2
  9. package/dist/shared/api.js +0 -90
  10. package/dist/tests/TestVortexInvite.js +0 -134
  11. package/dist/types/components/ShareButtons.d.ts +0 -27
  12. package/dist/types/components/ShareButtons.d.ts.map +0 -1
  13. package/dist/types/hooks/useThemeStyles.d.ts +0 -34
  14. package/dist/types/hooks/useThemeStyles.d.ts.map +0 -1
  15. package/dist/types/hooks/useVortexInvite.d.ts +0 -41
  16. package/dist/types/hooks/useVortexInvite.d.ts.map +0 -1
  17. package/dist/types/index.d.ts +0 -2
  18. package/dist/types/index.d.ts.map +0 -1
  19. package/dist/types/shared/InvitationResult.d.ts +0 -24
  20. package/dist/types/shared/InvitationResult.d.ts.map +0 -1
  21. package/dist/types/shared/api.d.ts +0 -14
  22. package/dist/types/shared/api.d.ts.map +0 -1
  23. package/dist/types/tests/TestVortexInvite.d.ts +0 -4
  24. package/dist/types/tests/TestVortexInvite.d.ts.map +0 -1
  25. package/dist/types/utils/formUtils.d.ts +0 -85
  26. package/dist/types/utils/formUtils.d.ts.map +0 -1
  27. package/dist/types/utils/themeUtils.d.ts +0 -35
  28. package/dist/types/utils/themeUtils.d.ts.map +0 -1
  29. package/dist/types/vortexInvite.d.ts +0 -25
  30. package/dist/types/vortexInvite.d.ts.map +0 -1
  31. package/dist/utils/formUtils.js +0 -174
  32. package/dist/utils/themeUtils.js +0 -55
  33. package/dist/vortexInvite.js +0 -172
@@ -1,174 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractFormConfiguration = extractFormConfiguration;
4
- exports.convertFormStyleToRNStyle = convertFormStyleToRNStyle;
5
- exports.findComponentByRole = findComponentByRole;
6
- exports.mergeThemeAndComponentStyles = mergeThemeAndComponentStyles;
7
- exports.getEmailPlaceholder = getEmailPlaceholder;
8
- exports.getSubmitButtonLabel = getSubmitButtonLabel;
9
- exports.hasGridLayout = hasGridLayout;
10
- exports.hasEmailAndShareInSeparateColumns = hasEmailAndShareInSeparateColumns;
11
- /**
12
- * Extracts the form configuration from the widget configuration
13
- */
14
- function extractFormConfiguration(widgetConfiguration) {
15
- var _a, _b, _c;
16
- if (!((_c = (_b = (_a = widgetConfiguration === null || widgetConfiguration === void 0 ? void 0 : widgetConfiguration.configuration) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b["vortex.components.form"]) === null || _c === void 0 ? void 0 : _c.value)) {
17
- return null;
18
- }
19
- return widgetConfiguration.configuration.props["vortex.components.form"].value;
20
- }
21
- /**
22
- * Converts form component style object to React Native styles
23
- */
24
- function convertFormStyleToRNStyle(style) {
25
- if (!style)
26
- return {};
27
- const rnStyle = {};
28
- Object.keys(style).forEach((key) => {
29
- const styleObj = style[key];
30
- // Handle special cases like background-color to backgroundColor
31
- const normalizedKey = key.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
32
- // Use computedValue if available, otherwise use value
33
- if (styleObj.computedValue) {
34
- rnStyle[normalizedKey] = styleObj.computedValue;
35
- }
36
- else if (styleObj.value !== undefined) {
37
- // Handle numeric values
38
- if (typeof styleObj.value === 'string' && !isNaN(Number(styleObj.value))) {
39
- rnStyle[normalizedKey] = Number(styleObj.value);
40
- }
41
- else {
42
- rnStyle[normalizedKey] = styleObj.value;
43
- }
44
- }
45
- });
46
- return rnStyle;
47
- }
48
- /**
49
- * Find a specific component by role in the form configuration
50
- */
51
- function findComponentByRole(formConfig, role) {
52
- if (!formConfig)
53
- return null;
54
- const findComponent = (components) => {
55
- var _a;
56
- for (const component of components) {
57
- if (((_a = component.vortex) === null || _a === void 0 ? void 0 : _a.role) === role) {
58
- return component;
59
- }
60
- if (component.children) {
61
- const found = findComponent(component.children);
62
- if (found)
63
- return found;
64
- }
65
- }
66
- return null;
67
- };
68
- return findComponent(formConfig);
69
- }
70
- /**
71
- * Merges theme styles with component-specific styles from form configuration
72
- */
73
- function mergeThemeAndComponentStyles(themeStyles, themeColors, formConfig) {
74
- // Start with the base theme styles
75
- const mergedStyles = Object.assign({}, themeStyles);
76
- // Find submit button and email input components
77
- const submitButton = findComponentByRole(formConfig, 'submit');
78
- const emailInput = findComponentByRole(formConfig, 'email');
79
- // Merge submit button styles
80
- if (submitButton === null || submitButton === void 0 ? void 0 : submitButton.style) {
81
- const submitButtonStyle = convertFormStyleToRNStyle(submitButton.style);
82
- mergedStyles.primaryButton = Object.assign(Object.assign(Object.assign({}, mergedStyles.primaryButton), (submitButtonStyle['backgroundColor'] && { backgroundColor: submitButtonStyle['backgroundColor'] })), (submitButtonStyle['borderColor'] && { borderColor: submitButtonStyle['borderColor'] }));
83
- // Update button text if there's a color specified
84
- if (submitButtonStyle['color']) {
85
- mergedStyles.primaryButtonText = Object.assign(Object.assign({}, mergedStyles.primaryButtonText), { color: submitButtonStyle['color'] });
86
- }
87
- }
88
- // Merge email input styles
89
- if (emailInput === null || emailInput === void 0 ? void 0 : emailInput.style) {
90
- const emailInputStyle = convertFormStyleToRNStyle(emailInput.style);
91
- mergedStyles.inputStyles = Object.assign(Object.assign({}, mergedStyles.inputStyles), emailInputStyle);
92
- }
93
- return mergedStyles;
94
- }
95
- /**
96
- * Get email input placeholder from form configuration
97
- */
98
- function getEmailPlaceholder(formConfig) {
99
- const emailInput = findComponentByRole(formConfig, 'email');
100
- return (emailInput === null || emailInput === void 0 ? void 0 : emailInput.placeholder) || 'Enter email';
101
- }
102
- /**
103
- * Get submit button label from form configuration
104
- */
105
- function getSubmitButtonLabel(formConfig) {
106
- const submitButton = findComponentByRole(formConfig, 'submit');
107
- return (submitButton === null || submitButton === void 0 ? void 0 : submitButton.label) || 'Invite';
108
- }
109
- /**
110
- * Determines if the form layout uses a grid structure
111
- */
112
- function hasGridLayout(formConfig) {
113
- if (!formConfig)
114
- return false;
115
- const findGrid = (components) => {
116
- for (const component of components) {
117
- if (component.type === 'grid') {
118
- return true;
119
- }
120
- if (component.children) {
121
- const found = findGrid(component.children);
122
- if (found)
123
- return true;
124
- }
125
- }
126
- return false;
127
- };
128
- return findGrid(formConfig);
129
- }
130
- /**
131
- * Determines if email and share components are in separate grid items
132
- */
133
- function hasEmailAndShareInSeparateColumns(formConfig) {
134
- if (!formConfig)
135
- return false;
136
- // Look for a grid with multiple grid-items
137
- const findSeparateColumns = (components) => {
138
- for (const component of components) {
139
- if (component.type === 'grid' && component.children) {
140
- // Check if there are at least 2 grid-items
141
- const gridItems = component.children.filter(child => child.type === 'grid-item');
142
- if (gridItems.length >= 2) {
143
- // Check if one has email and one has share
144
- let hasEmailItem = false;
145
- let hasShareItem = false;
146
- for (const item of gridItems) {
147
- if (!item.children)
148
- continue;
149
- // Check for email component
150
- if (!hasEmailItem) {
151
- hasEmailItem = item.children.some(child => {
152
- var _a;
153
- return child.type === 'form' &&
154
- ((_a = child.children) === null || _a === void 0 ? void 0 : _a.some(formChild => { var _a; return ((_a = formChild.vortex) === null || _a === void 0 ? void 0 : _a.role) === 'email'; }));
155
- });
156
- }
157
- // Check for share component
158
- if (!hasShareItem) {
159
- hasShareItem = item.children.some(child => child.type === 'vortex.components.share');
160
- }
161
- }
162
- return hasEmailItem && hasShareItem;
163
- }
164
- }
165
- if (component.children) {
166
- const found = findSeparateColumns(component.children);
167
- if (found)
168
- return true;
169
- }
170
- }
171
- return false;
172
- };
173
- return findSeparateColumns(formConfig);
174
- }
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractThemeColors = extractThemeColors;
4
- exports.extractFeatureFlags = extractFeatureFlags;
5
- /**
6
- * Extracts theme colors from widget configuration
7
- */
8
- function extractThemeColors(widgetConfiguration) {
9
- var _a, _b;
10
- const options = (_a = widgetConfiguration === null || widgetConfiguration === void 0 ? void 0 : widgetConfiguration.configuration) === null || _a === void 0 ? void 0 : _a.props;
11
- const colors = ((_b = options === null || options === void 0 ? void 0 : options['vortex.theme.colors']) === null || _b === void 0 ? void 0 : _b.value) || [];
12
- const colorMap = {};
13
- colors.forEach((color) => {
14
- if (color.key && color.value) {
15
- colorMap[color.key] = color.value;
16
- }
17
- });
18
- return {
19
- containerBackground: colorMap['--container-background'] || '#ffffff',
20
- containerForeground: colorMap['--container-foreground-color'] || '#666666',
21
- containerBorder: colorMap['--container-border-color'] || '#c4c4c4',
22
- primaryButtonBackground: colorMap['--primary-button-background'] || '#197af3',
23
- primaryButtonForeground: colorMap['--primary-button-foreground-color'] || '#ffffff',
24
- primaryButtonBorder: colorMap['--primary-button-border-color'] || '#000000',
25
- secondaryButtonBackground: colorMap['--secondary-button-background'] || '#dfdfdf',
26
- secondaryButtonForeground: colorMap['--secondary-button-foreground-color'] || '#000000',
27
- secondaryButtonBorder: colorMap['--secondary-button-border-color'] || '#c4c4c4',
28
- };
29
- }
30
- /**
31
- * Extracts feature flags from widget configuration
32
- */
33
- function extractFeatureFlags(widgetConfiguration) {
34
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
35
- const features = Array.isArray((_c = (_b = (_a = widgetConfiguration === null || widgetConfiguration === void 0 ? void 0 : widgetConfiguration.configuration) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b['vortex.components']) === null || _c === void 0 ? void 0 : _c.value)
36
- ? (_f = (_e = (_d = widgetConfiguration === null || widgetConfiguration === void 0 ? void 0 : widgetConfiguration.configuration) === null || _d === void 0 ? void 0 : _d.props) === null || _e === void 0 ? void 0 : _e['vortex.components']) === null || _f === void 0 ? void 0 : _f.value
37
- : [];
38
- const shareOptions = Array.isArray((_j = (_h = (_g = widgetConfiguration === null || widgetConfiguration === void 0 ? void 0 : widgetConfiguration.configuration) === null || _g === void 0 ? void 0 : _g.props) === null || _h === void 0 ? void 0 : _h['vortex.components.share.options']) === null || _j === void 0 ? void 0 : _j.value)
39
- ? (_m = (_l = (_k = widgetConfiguration === null || widgetConfiguration === void 0 ? void 0 : widgetConfiguration.configuration) === null || _k === void 0 ? void 0 : _k.props) === null || _l === void 0 ? void 0 : _l['vortex.components.share.options']) === null || _m === void 0 ? void 0 : _m.value
40
- : [];
41
- return {
42
- shareableLinks: features.includes("vortex.components.emailinvitations"),
43
- emailInvitations: features.includes("vortex.components.share"),
44
- shareEnabled: features.includes("vortex.components.share"),
45
- shareOptionsCopyLink: shareOptions.includes("copyLink"),
46
- shareOptionsFacebookMessenger: shareOptions.includes("facebookMessenger"),
47
- shareOptionsInstagramDms: shareOptions.includes("instagramDms"),
48
- shareOptionsLinkedInMessaging: shareOptions.includes("linkedInMessaging"),
49
- shareOptionsNativeShareSheet: shareOptions.includes("nativeShareSheet"),
50
- shareOptionsQrCode: shareOptions.includes("qrCode"), // Only true if specifically included
51
- shareOptionsSms: shareOptions.includes("sms"),
52
- shareOptionsTwitterDms: shareOptions.includes("twitterDms"),
53
- shareOptionsWhatsApp: shareOptions.includes("whatsApp"),
54
- };
55
- }
@@ -1,172 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.VortexInvite = VortexInvite;
7
- const react_1 = __importDefault(require("react"));
8
- const react_native_1 = require("react-native");
9
- const useVortexInvite_1 = require("./hooks/useVortexInvite");
10
- const ShareButtons_1 = require("./components/ShareButtons");
11
- function VortexInvite({ widgetId, environmentId, vortexApiHost, isLoading = false, jwt, onSuccess, onError, contentTokens, }) {
12
- const { error, fetching, loading, email, setEmail, opacity, themeColors, themeStyles, has, inviteLoading, showSuccessMessage, handleInviteClick, handleShareLink, handleCopyLink, getShareableLink, formLayout, } = (0, useVortexInvite_1.useVortexInvite)({
13
- widgetId,
14
- environmentId,
15
- vortexApiHost,
16
- isLoading,
17
- jwt,
18
- onSuccess,
19
- onError,
20
- });
21
- if (error === null || error === void 0 ? void 0 : error.message) {
22
- return <react_native_1.Text data-testid="error">{error.message}</react_native_1.Text>;
23
- }
24
- if (fetching || loading) {
25
- return <react_native_1.Animated.View style={[styles.skeleton, { opacity }]}/>;
26
- }
27
- // Theme styles are now provided by the hook
28
- // If we have a grid layout with separate columns for email and share, we'll use that layout
29
- if ((formLayout === null || formLayout === void 0 ? void 0 : formLayout.isGridLayout) && (formLayout === null || formLayout === void 0 ? void 0 : formLayout.hasSeparateColumns)) {
30
- return (<react_native_1.View style={[styles.container, themeStyles.containerStyles]}>
31
- <react_native_1.View style={styles.gridContainer}>
32
- {/* Email invitation column */}
33
- {(has === null || has === void 0 ? void 0 : has.emailInvitations) && (<react_native_1.View style={styles.gridItem}>
34
- <react_native_1.Text style={[styles.introText, themeStyles.textStyles]}>Invite People</react_native_1.Text>
35
- <react_native_1.TextInput style={[styles.input, themeStyles.inputStyles]} placeholder={formLayout.emailPlaceholder} placeholderTextColor={themeColors.containerForeground} value={email} onChangeText={setEmail} autoCapitalize="none"/>
36
- <react_native_1.View style={styles.buttonContainer}>
37
- <react_native_1.Pressable style={[styles.submitButton, themeStyles.primaryButton, inviteLoading && styles.disabledButton]} onPress={() => handleInviteClick(contentTokens)} disabled={inviteLoading}>
38
- {inviteLoading ? (<react_native_1.ActivityIndicator size="small" color={themeColors.containerBackground}/>) : (<react_native_1.Text style={[styles.submitButtonText, themeStyles.primaryButtonText]}>
39
- {formLayout.submitButtonLabel}
40
- </react_native_1.Text>)}
41
- </react_native_1.Pressable>
42
- {showSuccessMessage && (<react_native_1.View style={styles.successMessageContainer}>
43
- <react_native_1.Text style={styles.successMessage}>Success!</react_native_1.Text>
44
- </react_native_1.View>)}
45
- </react_native_1.View>
46
- </react_native_1.View>)}
47
-
48
- {/* Share buttons column */}
49
- {(has === null || has === void 0 ? void 0 : has.shareableLinks) && (<react_native_1.View style={styles.gridItem}>
50
- <react_native_1.View style={styles.shareButtonsContainer}>
51
- <ShareButtons_1.ShareButtons has={has} themeColors={themeColors} themeStyles={themeStyles} handleShareLink={handleShareLink} handleCopyLink={handleCopyLink} shareableLink={getShareableLink()}/>
52
- </react_native_1.View>
53
- </react_native_1.View>)}
54
- </react_native_1.View>
55
- </react_native_1.View>);
56
- }
57
- // Default stacked layout
58
- return (<react_native_1.View style={[styles.container, themeStyles.containerStyles]}>
59
- {(has === null || has === void 0 ? void 0 : has.emailInvitations) && (<react_native_1.View style={styles.inviteContainer}>
60
- <react_native_1.Text style={[styles.introText, themeStyles.textStyles]}>Invite People</react_native_1.Text>
61
- <react_native_1.TextInput style={[styles.input, themeStyles.inputStyles]} placeholder={(formLayout === null || formLayout === void 0 ? void 0 : formLayout.emailPlaceholder) || 'Enter email'} placeholderTextColor={themeColors.containerForeground} value={email} onChangeText={setEmail} autoCapitalize="none"/>
62
- <react_native_1.View style={styles.buttonContainer}>
63
- <react_native_1.Pressable style={[styles.submitButton, themeStyles.primaryButton, inviteLoading && styles.disabledButton]} onPress={() => handleInviteClick(contentTokens)} disabled={inviteLoading}>
64
- {inviteLoading ? (<react_native_1.ActivityIndicator size="small" color={themeColors.containerBackground}/>) : (<react_native_1.Text style={[styles.submitButtonText, themeStyles.primaryButtonText]}>
65
- {(formLayout === null || formLayout === void 0 ? void 0 : formLayout.submitButtonLabel) || 'Invite'}
66
- </react_native_1.Text>)}
67
- </react_native_1.Pressable>
68
- {showSuccessMessage && (<react_native_1.View style={styles.successMessageContainer}>
69
- <react_native_1.Text style={styles.successMessage}>Success!</react_native_1.Text>
70
- </react_native_1.View>)}
71
- </react_native_1.View>
72
- </react_native_1.View>)}
73
-
74
- {(has === null || has === void 0 ? void 0 : has.shareableLinks) && (<react_native_1.View style={styles.shareContainer}>
75
- {(has === null || has === void 0 ? void 0 : has.emailInvitations) && <react_native_1.Text style={[styles.divider, themeStyles.textStyles]}>OR</react_native_1.Text>}
76
-
77
- <react_native_1.View style={styles.shareButtonsContainer}>
78
- <ShareButtons_1.ShareButtons has={has} themeColors={themeColors} themeStyles={themeStyles} handleShareLink={handleShareLink} handleCopyLink={handleCopyLink} shareableLink={getShareableLink()}/>
79
- </react_native_1.View>
80
- </react_native_1.View>)}
81
- </react_native_1.View>);
82
- }
83
- const styles = react_native_1.StyleSheet.create({
84
- container: {
85
- padding: 15,
86
- display: 'flex',
87
- flexDirection: 'column',
88
- borderRadius: 8,
89
- borderWidth: 1,
90
- },
91
- gridContainer: {
92
- flexDirection: 'row',
93
- flexWrap: 'wrap',
94
- justifyContent: 'space-between',
95
- },
96
- gridItem: {
97
- flex: 1,
98
- padding: 8,
99
- minWidth: 250, // Ensure items have minimum width for smaller screens
100
- },
101
- disabledButton: {
102
- opacity: 0.7,
103
- },
104
- successMessageContainer: {
105
- marginTop: 8,
106
- padding: 8,
107
- alignItems: 'center',
108
- width: '100%',
109
- },
110
- successMessage: {
111
- color: 'green',
112
- fontWeight: 'bold',
113
- fontSize: 16,
114
- },
115
- inviteContainer: {
116
- display: 'flex',
117
- flexDirection: 'column',
118
- justifyContent: 'center',
119
- alignItems: 'center',
120
- marginTop: 8,
121
- },
122
- introText: {
123
- marginBottom: 8,
124
- fontSize: 24,
125
- fontWeight: 'bold',
126
- textAlign: 'center',
127
- },
128
- input: {
129
- width: '100%',
130
- borderWidth: 1,
131
- padding: 10,
132
- borderRadius: 5,
133
- marginBottom: 8,
134
- },
135
- buttonContainer: {
136
- marginTop: 16,
137
- marginBottom: 8,
138
- width: '100%',
139
- },
140
- submitButton: {
141
- padding: 12,
142
- borderRadius: 5,
143
- alignItems: 'center',
144
- borderWidth: 1,
145
- },
146
- submitButtonText: {
147
- fontWeight: '500',
148
- textTransform: 'none',
149
- },
150
- skeleton: {
151
- width: '100%',
152
- height: 50,
153
- backgroundColor: 'lightgray',
154
- borderRadius: 5,
155
- },
156
- shareContainer: {
157
- marginTop: 16,
158
- alignItems: 'center',
159
- },
160
- divider: {
161
- marginVertical: 10,
162
- fontSize: 16,
163
- fontWeight: 'bold',
164
- textAlign: 'center',
165
- },
166
- shareButtonsContainer: {
167
- flexDirection: 'row',
168
- flexWrap: 'wrap',
169
- justifyContent: 'center',
170
- },
171
- // Share button styles moved to ShareButtons.tsx
172
- });