@saasquatch/mint-components 2.1.8-22 → 2.1.8-24

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 (77) hide show
  1. package/dist/cjs/{ShadowViewAddon-643b83e2.js → ShadowViewAddon-1ed8faf9.js} +12 -8
  2. package/dist/cjs/loader.cjs.js +1 -1
  3. package/dist/cjs/mint-components.cjs.js +1 -1
  4. package/dist/cjs/sqm-big-stat_45.cjs.entry.js +4 -4
  5. package/dist/cjs/sqm-stencilbook.cjs.entry.js +590 -1146
  6. package/dist/collection/components/sqm-share-link/ShareLink.stories.js +1 -1
  7. package/dist/collection/components/sqm-share-link/UseShareLink.stories.js +1 -1
  8. package/dist/collection/components/sqm-share-link/sqm-share-link-view.js +37 -7
  9. package/dist/collection/components/sqm-share-link/sqm-share-link.js +24 -7
  10. package/dist/collection/components/sqm-share-link/useShareLink.js +3 -3
  11. package/dist/esm/{ShadowViewAddon-fcb6446a.js → ShadowViewAddon-395ab799.js} +12 -8
  12. package/dist/esm/loader.js +1 -1
  13. package/dist/esm/mint-components.js +1 -1
  14. package/dist/esm/sqm-big-stat_45.entry.js +4 -4
  15. package/dist/esm/sqm-stencilbook.entry.js +2773 -3329
  16. package/dist/esm-es5/{ShadowViewAddon-fcb6446a.js → ShadowViewAddon-395ab799.js} +1 -1
  17. package/dist/esm-es5/loader.js +1 -1
  18. package/dist/esm-es5/mint-components.js +1 -1
  19. package/dist/esm-es5/sqm-big-stat_45.entry.js +1 -1
  20. package/dist/esm-es5/sqm-stencilbook.entry.js +1 -1
  21. package/dist/mint-components/mint-components.esm.js +1 -1
  22. package/dist/mint-components/{p-3692c0da.system.entry.js → p-2b108f39.system.entry.js} +1 -1
  23. package/dist/mint-components/p-4b365f1f.system.js +1 -1
  24. package/dist/mint-components/{p-8d7548fb.system.entry.js → p-8e5a6491.system.entry.js} +1 -1
  25. package/dist/mint-components/{p-04502b80.entry.js → p-ba640335.entry.js} +2 -2
  26. package/dist/mint-components/{p-0eeb5438.js → p-cd79864c.js} +6 -6
  27. package/dist/mint-components/{p-5284bb02.system.js → p-d7adb7f3.system.js} +1 -1
  28. package/dist/mint-components/{p-31757712.entry.js → p-e6cf9daa.entry.js} +2 -2
  29. package/dist/types/components/sqm-share-link/sqm-share-link-view.d.ts +1 -1
  30. package/dist/types/components/sqm-share-link/sqm-share-link.d.ts +2 -1
  31. package/dist/types/components/sqm-share-link/useShareLink.d.ts +1 -1
  32. package/dist/types/components.d.ts +18 -234
  33. package/dist/types/global/android.d.ts +7 -0
  34. package/dist/types/global/demo.d.ts +2 -0
  35. package/dist/types/stories/features.d.ts +4 -0
  36. package/dist/types/stories/templates.d.ts +4 -0
  37. package/docs/docs.docx +0 -0
  38. package/docs/raisins.json +1 -1
  39. package/grapesjs/grapesjs.js +1 -1
  40. package/package.json +1 -1
  41. package/dist/cjs/sqm-share-link.cjs.entry.js +0 -271
  42. package/dist/cjs/useShareLink-1282123e.js +0 -422
  43. package/dist/cjs/useShareLink-3c22b1b9.js +0 -448
  44. package/dist/cjs/useShareLink-54e24928.js +0 -448
  45. package/dist/cjs/useShareLink-b664fbc7.js +0 -450
  46. package/dist/cjs/useShareLink-bf04b25c.js +0 -450
  47. package/dist/cjs/useShareLink-e8e2ae6d.js +0 -448
  48. package/dist/esm/sqm-share-link.entry.js +0 -267
  49. package/dist/esm/useShareLink-023284f3.js +0 -445
  50. package/dist/esm/useShareLink-436e9cad.js +0 -445
  51. package/dist/esm/useShareLink-4ba01373.js +0 -447
  52. package/dist/esm/useShareLink-79056582.js +0 -445
  53. package/dist/esm/useShareLink-a3329e33.js +0 -419
  54. package/dist/esm/useShareLink-bc20ec4c.js +0 -447
  55. package/dist/esm-es5/sqm-share-link.entry.js +0 -1
  56. package/dist/esm-es5/useShareLink-023284f3.js +0 -1
  57. package/dist/esm-es5/useShareLink-436e9cad.js +0 -1
  58. package/dist/esm-es5/useShareLink-4ba01373.js +0 -1
  59. package/dist/esm-es5/useShareLink-79056582.js +0 -1
  60. package/dist/esm-es5/useShareLink-a3329e33.js +0 -1
  61. package/dist/esm-es5/useShareLink-bc20ec4c.js +0 -1
  62. package/dist/mint-components/sqm-share-link.entry.js +0 -267
  63. package/dist/mint-components/sqm-share-link.system.entry.js +0 -1
  64. package/dist/mint-components/sqm-stencilbook.entry.js +0 -22106
  65. package/dist/mint-components/sqm-stencilbook.system.entry.js +0 -1
  66. package/dist/mint-components/useShareLink-023284f3.js +0 -445
  67. package/dist/mint-components/useShareLink-1d7c9fd8.system.js +0 -1
  68. package/dist/mint-components/useShareLink-211e061c.system.js +0 -1
  69. package/dist/mint-components/useShareLink-2de7ffce.system.js +0 -1
  70. package/dist/mint-components/useShareLink-436e9cad.js +0 -445
  71. package/dist/mint-components/useShareLink-454939f5.system.js +0 -1
  72. package/dist/mint-components/useShareLink-4ba01373.js +0 -447
  73. package/dist/mint-components/useShareLink-79056582.js +0 -445
  74. package/dist/mint-components/useShareLink-a3329e33.js +0 -419
  75. package/dist/mint-components/useShareLink-bc20ec4c.js +0 -447
  76. package/dist/mint-components/useShareLink-c05fe151.system.js +0 -1
  77. package/dist/mint-components/useShareLink-cb5abd96.system.js +0 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@saasquatch/mint-components",
3
3
  "title": "Mint Components",
4
- "version": "2.1.8-22",
4
+ "version": "2.1.8-24",
5
5
  "description": "A minimal design library with components for referral and loyalty experiences. Built with Shoelace components by Saasquatch.",
6
6
  "icon": "https://res.cloudinary.com/saasquatch/image/upload/v1652219900/squatch-assets/For_Mint.svg",
7
7
  "raisins": "docs/raisins.json",
@@ -1,271 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const index = require('./index-fd67d7bc.js');
6
- require('./global-746daf93.js');
7
- const domContextHooks_module = require('./dom-context-hooks.module-224e09d4.js');
8
- const index_module = require('./index.module-c79bd5b0.js');
9
- require('./GoogleFonts-039d880f.js');
10
- require('./jss-preset-default.esm-b48f0c33.js');
11
- require('./JSS-518e9b4d.js');
12
- require('./mixins-f51b04f1.js');
13
- const utils = require('./utils-e326d1b5.js');
14
- const cjs = require('./cjs-2bf512b9.js');
15
- require('./useReferralCodes-4304f68f.js');
16
- require('./copy-text-view-fd17b89a.js');
17
- const useShareLink = require('./useShareLink-1282123e.js');
18
-
19
- const ShareLink = class {
20
- constructor(hostRef) {
21
- index.registerInstance(this, hostRef);
22
- /**
23
- * Shown inside a tooltip after someone has successfully copied the link to their clipboard
24
- *
25
- * @uiName Tooltip text
26
- */
27
- this.tooltiptext = "Copied to Clipboard";
28
- /**
29
- * The number of milliseconds that the tooltip appears for
30
- *
31
- * @uiName Tooltip lifespan
32
- */
33
- this.tooltiplifespan = 1000;
34
- /**
35
- * Change the text alignment
36
- *
37
- * @uiName Share link alignment
38
- * @uiType string
39
- * @uiEnum ["left", "center", "right"]
40
- * @uiEnumNames ["Left", "Center", "Right"]
41
- * @uiGroup Style
42
- */
43
- this.textAlign = "left";
44
- /**
45
- * @uiName Copy button label
46
- */
47
- this.copyButtonLabel = "Copy Link";
48
- /**
49
- * The type of the button that is used (primary or secondary).
50
- * @uiName Button Type
51
- * @uiType string
52
- * @uiEnum ["primary", "secondary"]
53
- * @uiEnumNames ["Primary", "Secondary"]
54
- * @uiGroup Style
55
- */
56
- this.buttonType = "primary";
57
- /**
58
- * Set the copy button style and placement
59
- *
60
- * @uiName Button style
61
- * @uiType string
62
- * @uiEnum ["icon", "button-outside", "button-below"]
63
- * @uiEnumNames ["Icon", "Button outside", "Button below"]
64
- * @uiGroup Style
65
- */
66
- this.buttonStyle = "icon";
67
- /**
68
- * Enable users to customize their referral link
69
- *
70
- * @uiName Customize URL
71
- * @uiType boolean
72
- * @uiGroup Customize Vanity Link
73
- * @requiredFlavor impact
74
- */
75
- this.customizeUrl = false;
76
- /**
77
- * Text shown below the share link input to trigger customization
78
- *
79
- * @uiName Customize link label
80
- * @uiType string
81
- * @uiGroup Customize Vanity Link
82
- * @requiredFlavor impact
83
- */
84
- this.customizeLinkLabel = "Customize Link";
85
- /**
86
- * Text for the save button in editing mode
87
- *
88
- * @uiName Save button label
89
- * @uiType string
90
- * @uiGroup Customize Vanity Link
91
- * @requiredFlavor impact
92
- */
93
- this.saveLabelText = "Save";
94
- /**
95
- * Text for the cancel button in editing mode
96
- *
97
- * @uiName Cancel button label
98
- * @uiType string
99
- * @uiGroup Customize Vanity Link
100
- * @requiredFlavor impact
101
- */
102
- this.cancelLabelText = "Cancel";
103
- /**
104
- * Title text shown when the custom link is already taken
105
- *
106
- * @uiName Existing code conflict error title
107
- * @uiType string
108
- * @uiGroup Customize Vanity Link
109
- * @requiredFlavor impact
110
- */
111
- this.existingCodeConflictErrorTitle = "This link is already taken";
112
- /**
113
- * Description text shown when the custom link is already taken
114
- *
115
- * @uiName Existing code conflict error description
116
- * @uiType string
117
- * @uiGroup Customize Vanity Link
118
- * @requiredFlavor impact
119
- */
120
- this.existingCodeConflictErrorDescription = "Try adding numbers, a dash or underscore to create a unique link.";
121
- /**
122
- * Title text shown when the link contains invalid characters
123
- *
124
- * @uiName Invalid characters error title
125
- * @uiType string
126
- * @uiGroup Customize Vanity Link
127
- * @requiredFlavor impact
128
- */
129
- this.invalidCharactersErrorTitle = "Please use only letters, numbers, dashes and underscores";
130
- /**
131
- * Description text shown when the link contains invalid characters
132
- *
133
- * @uiName Invalid characters error description
134
- * @uiType string
135
- * @uiGroup Customize Vanity Link
136
- * @requiredFlavor impact
137
- */
138
- this.invalidCharactersErrorDescription = "Special characters can break the link when sharing.";
139
- /**
140
- * Title text shown when the link contains profanity
141
- *
142
- * @uiName Profanity error title
143
- * @uiType string
144
- * @uiGroup Customize Vanity Link
145
- * @requiredFlavor impact
146
- */
147
- this.profanityErrorTitle = "Please try a different link";
148
- /**
149
- * Description text shown when the link contains profanity
150
- *
151
- * @uiName Profanity error description
152
- * @uiType string
153
- * @uiGroup Customize Vanity Link
154
- * @requiredFlavor impact
155
- */
156
- this.profanityErrorDescription = "This link contains a restricted word.";
157
- /**
158
- * Text describing the edit limit
159
- *
160
- * @uiName Edit limit text
161
- * @uiType string
162
- * @uiGroup Customize Vanity Link
163
- * @requiredFlavor impact
164
- */
165
- this.editLimitText = "You can edit your link up to 5 times.";
166
- /**
167
- * Message shown when the edit limit has been reached. Use {supportLink} as a placeholder for the support link.
168
- *
169
- * @uiName Edit limit reached text
170
- * @uiType string
171
- * @uiGroup Customize Vanity Link
172
- * @requiredFlavor impact
173
- */
174
- this.editLimitReachedText = "5 edit limit reached. To make more changes, please contact {supportLink}.";
175
- /**
176
- * Display text for the support link in the edit limit reached message
177
- *
178
- * @uiName Support link text
179
- * @uiType string
180
- * @uiGroup Customize Vanity Link
181
- * @requiredFlavor impact
182
- */
183
- this.supportLinkText = "Support";
184
- /**
185
- * Tooltip text shown when link customization is disabled
186
- *
187
- * @uiName Customize disabled tooltip
188
- * @uiType string
189
- * @uiGroup Customize Vanity Link
190
- * @requiredFlavor impact
191
- */
192
- this.customizeDisabledTooltip = "Link customization is not available.";
193
- domContextHooks_module.h$1(this);
194
- }
195
- disconnectedCallback() { }
196
- render() {
197
- const thisProps = utils.getProps(this);
198
- const props = index_module.isDemo()
199
- ? useDemoShareLink(thisProps)
200
- : useShareLink.useShareLink(thisProps);
201
- return index.h(useShareLink.ShareLinkView, Object.assign({}, props));
202
- }
203
- };
204
- function useDemoShareLink(props) {
205
- var _a;
206
- const [open, setOpen] = domContextHooks_module.useState(false);
207
- const [isEditing, setIsEditing] = domContextHooks_module.useState(false);
208
- const [editValue, setEditValue] = domContextHooks_module.useState("");
209
- const copyString = "https://www.example.com/sharelink/abc";
210
- const domainPrefix = "https://www.example.com/";
211
- const baseProps = {
212
- copyTextViewProps: {
213
- copyString,
214
- tooltiptext: props.tooltiptext,
215
- textAlign: props.textAlign,
216
- buttonStyle: props.buttonStyle,
217
- backgroundColor: props.backgroundColor,
218
- textColor: props.textColor,
219
- borderRadius: props.borderRadius,
220
- buttonType: props.buttonType,
221
- copyButtonLabel: props.copyButtonLabel,
222
- borderColor: props.borderColor,
223
- open,
224
- onClick: () => {
225
- navigator.clipboard.writeText(copyString);
226
- setOpen(true);
227
- setTimeout(() => setOpen(false), props.tooltiplifespan);
228
- },
229
- },
230
- customizeUrl: props.customizeUrl,
231
- customizeLinkLabel: props.customizeLinkLabel,
232
- saveLabelText: props.saveLabelText,
233
- cancelLabelText: props.cancelLabelText,
234
- isEditing,
235
- editValue,
236
- domainPrefix,
237
- editsRemaining: 5,
238
- maxEdits: 5,
239
- limitReached: false,
240
- validationError: null,
241
- isValidating: false,
242
- isSaving: false,
243
- characterLimit: 15,
244
- minCharacters: 3,
245
- charactersRemaining: 15 - editValue.length,
246
- editLimitText: props.editLimitText,
247
- editLimitReachedText: props.editLimitReachedText,
248
- supportLinkText: props.supportLinkText,
249
- customizeDisabled: false,
250
- customizeDisabledTooltip: (_a = props.customizeDisabledTooltip) !== null && _a !== void 0 ? _a : "Link customization is not available.",
251
- onCustomizeClick: () => {
252
- setIsEditing(true);
253
- setEditValue("");
254
- },
255
- onEditValueChange: (value) => {
256
- setEditValue(value);
257
- },
258
- onSave: () => {
259
- setIsEditing(false);
260
- },
261
- onCancel: () => {
262
- setIsEditing(false);
263
- setEditValue("");
264
- },
265
- };
266
- return cjs.cjs(baseProps, props.demoData || {}, {
267
- arrayMerge: (_, a) => a,
268
- });
269
- }
270
-
271
- exports.sqm_share_link = ShareLink;
@@ -1,422 +0,0 @@
1
- 'use strict';
2
-
3
- const index = require('./index-fd67d7bc.js');
4
- const global = require('./global-746daf93.js');
5
- const domContextHooks_module = require('./dom-context-hooks.module-224e09d4.js');
6
- const index_module = require('./index.module-c79bd5b0.js');
7
- const JSS = require('./JSS-518e9b4d.js');
8
- const useReferralCodes = require('./useReferralCodes-4304f68f.js');
9
- const copyTextView = require('./copy-text-view-fd17b89a.js');
10
-
11
- const vanillaStyle = `
12
- :host {
13
- display: block;
14
- width: 100%;
15
- }
16
- `;
17
- function ShareLinkView(props) {
18
- const { copyTextViewProps, customizeUrl, customizeLinkLabel, saveLabelText, cancelLabelText, isEditing, editValue, domainPrefix, editsRemaining, maxEdits, limitReached, validationError, isValidating, isSaving, characterLimit, minCharacters, charactersRemaining, editLimitText, editLimitReachedText, supportLinkText, customizeDisabled, customizeDisabledTooltip, onCustomizeClick, onEditValueChange, onSave, onCancel, } = props;
19
- const style = {
20
- Container: {
21
- display: "flex",
22
- flexDirection: "column",
23
- gap: "var(--sl-spacing-xx-small)",
24
- width: "100%",
25
- },
26
- CustomizeLinkText: {
27
- margin: "0",
28
- fontSize: "var(--sl-font-size-small)",
29
- fontWeight: "600",
30
- cursor: "pointer",
31
- color: "var(--sl-color-neutral-900)",
32
- textAlign: "left",
33
- padding: "var(--sl-spacing-small)",
34
- "&:hover": {
35
- textDecoration: "underline",
36
- },
37
- },
38
- CustomizeLinkDisabled: {
39
- margin: "0",
40
- fontSize: "var(--sl-font-size-small)",
41
- fontWeight: "600",
42
- color: "var(--sl-color-neutral-400)",
43
- cursor: "default",
44
- textAlign: "left",
45
- padding: "var(--sl-spacing-small)",
46
- },
47
- EditContainer: {
48
- display: "flex",
49
- flexDirection: "column",
50
- gap: "var(--sl-spacing-x-small)",
51
- width: "100%",
52
- },
53
- EditInputWrapper: {
54
- display: "flex",
55
- alignItems: "center",
56
- width: "100%",
57
- border: "var(--sqm-border-thickness, 1px) solid var(--sqm-input-border-color, #d1d5db)",
58
- borderRadius: "var(--sqm-border-radius-normal, 4px)",
59
- background: "var(--sqm-input-background, #fff)",
60
- overflow: "hidden",
61
- "&:focus-within": {
62
- borderColor: "#999999",
63
- boxShadow: "0 0 0 var(--sl-focus-ring-width) var(--sl-input-focus-ring-color)",
64
- },
65
- },
66
- DomainPrefix: {
67
- padding: "0 0 0 var(--sl-spacing-medium)",
68
- fontSize: "var(--sl-font-size-medium)",
69
- color: "var(--sl-color-neutral-500)",
70
- whiteSpace: "nowrap",
71
- userSelect: "none",
72
- lineHeight: "var(--sl-input-height-medium)",
73
- },
74
- EditInput: {
75
- flex: "1",
76
- border: "none",
77
- outline: "none",
78
- padding: "0 var(--sl-spacing-medium) 0 0",
79
- fontSize: "var(--sl-font-size-medium)",
80
- fontFamily: "var(--sl-font-sans)",
81
- color: "var(--sl-input-color)",
82
- background: "transparent",
83
- lineHeight: "var(--sl-input-height-medium)",
84
- minWidth: "0",
85
- },
86
- EditLabel: {
87
- margin: "0",
88
- fontSize: "var(--sl-font-size-small)",
89
- color: "var(--sl-color-neutral-500)",
90
- },
91
- HelperText: {
92
- margin: "0",
93
- fontSize: "var(--sl-font-size-small)",
94
- color: "var(--sl-color-neutral-500)",
95
- },
96
- ErrorText: {
97
- margin: "0",
98
- fontSize: "var(--sl-font-size-small)",
99
- color: "var(--sqm-danger-color-text, #dc2626)",
100
- },
101
- ActionRow: {
102
- display: "flex",
103
- gap: "var(--sl-spacing-medium)",
104
- alignItems: "center",
105
- },
106
- LimitReachedContainer: {
107
- display: "flex",
108
- alignItems: "center",
109
- gap: "var(--sl-spacing-x-small)",
110
- },
111
- };
112
- const sheet = JSS.createStyleSheet(style);
113
- const styleString = sheet.toString();
114
- const errorMessageType = (validationError === null || validationError === void 0 ? void 0 : validationError.code) === "EXISTING_CODE_CONFLICT" ? "info" : "warning";
115
- const showCharactersRemaining = charactersRemaining <= 14;
116
- console.log(customizeUrl, limitReached, customizeDisabled, validationError, "customize URL state");
117
- // Editing state
118
- if (isEditing) {
119
- return (index.h("div", { class: sheet.classes.Container },
120
- index.h("style", { type: "text/css" },
121
- styleString,
122
- vanillaStyle),
123
- index.h("p", { class: sheet.classes.EditLabel }, "Enter your link"),
124
- index.h("div", { class: sheet.classes.EditInputWrapper },
125
- index.h("span", { class: sheet.classes.DomainPrefix }, domainPrefix),
126
- index.h("input", { class: sheet.classes.EditInput, type: "text", value: editValue, onInput: (e) => onEditValueChange(e.target.value), onKeyDown: (e) => {
127
- if (e.key === "/" || e.key === "@")
128
- e.preventDefault();
129
- }, disabled: isSaving, maxLength: characterLimit })),
130
- index.h("p", { class: sheet.classes.HelperText },
131
- editLimitText,
132
- showCharactersRemaining &&
133
- ` Characters remaining: ${charactersRemaining}`),
134
- validationError && (index.h("sqm-form-message", { type: errorMessageType, style: { paddingBottom: "var(--sl-spacing-xx-small)" } },
135
- index.h("p", { part: "alert-title" }, validationError.title),
136
- validationError.description)),
137
- isValidating && index.h("p", { class: sheet.classes.HelperText }, "Validating..."),
138
- index.h("div", { class: sheet.classes.ActionRow },
139
- index.h("sl-button", { type: "primary", onClick: onSave, disabled: isSaving ||
140
- isValidating ||
141
- !!validationError ||
142
- !editValue ||
143
- editValue.length < minCharacters }, isSaving ? "Saving..." : saveLabelText),
144
- index.h("sl-button", { type: "secondary", onClick: onCancel, disabled: isSaving }, cancelLabelText))));
145
- }
146
- // Default / Customized / Limit reached states
147
- return (index.h("div", { class: sheet.classes.Container },
148
- index.h("style", { type: "text/css" },
149
- styleString,
150
- vanillaStyle),
151
- index.h(copyTextView.CopyTextView, Object.assign({}, copyTextViewProps)),
152
- customizeUrl &&
153
- (customizeDisabled ? (index.h("sl-tooltip", { content: customizeDisabledTooltip, placement: "top", style: { display: "inline-block", width: "fit-content" } },
154
- index.h("p", { class: sheet.classes.CustomizeLinkDisabled }, customizeLinkLabel))) : (index.h("div", { class: sheet.classes.LimitReachedContainer },
155
- index.h("p", { class: limitReached
156
- ? sheet.classes.CustomizeLinkDisabled
157
- : sheet.classes.CustomizeLinkText, onClick: limitReached ? undefined : onCustomizeClick }, customizeLinkLabel),
158
- customizeUrl && limitReached && (index.h("p", { class: sheet.classes.HelperText }, global.intl.formatMessage({
159
- id: "editLimitReached",
160
- defaultMessage: editLimitReachedText,
161
- }, {
162
- supportLink: (index.h("a", { target: "_blank", href: "https://help.impact.com/other/readme/get-help-and-support" }, supportLinkText)),
163
- }))))))));
164
- }
165
-
166
- const MAX_EDITS = 5;
167
- const CHARACTER_LIMIT = 15;
168
- const MIN_CHARACTERS = 3;
169
- const MessageLinkQuery = index_module.dist.gql `
170
- query ($programId: ID) {
171
- user: viewer {
172
- ... on User {
173
- shareLink(programId: $programId)
174
- }
175
- }
176
- }
177
- `;
178
- const WIDGET_ENGAGEMENT_EVENT = index_module.dist.gql `
179
- mutation loadEvent($eventMeta: UserAnalyticsEvent!) {
180
- createUserAnalyticsEvent(eventMeta: $eventMeta)
181
- }
182
- `;
183
- const ADD_SHARE_LINK_CODE = index_module.dist.gql `
184
- mutation ($addShareLinkCodeInput: AddShareLinkCodeInput!) {
185
- addShareLinkCode(addShareLinkCodeInput: $addShareLinkCodeInput) {
186
- linkCode {
187
- linkCode
188
- shortUrl
189
- referralCode {
190
- code
191
- }
192
- }
193
- }
194
- }
195
- `;
196
- const VALIDATE_LINK_CODE = index_module.dist.gql `
197
- query validateLinkCode($linkCode: String!) {
198
- validateLinkCode(linkCode: $linkCode) {
199
- valid
200
- invalidReason
201
- }
202
- }
203
- `;
204
- const GET_LINK_DOMAIN = index_module.dist.gql `
205
- query getLinkDomain {
206
- tenantSettings {
207
- primaryLinkDomain {
208
- host
209
- }
210
- }
211
- }
212
- `;
213
- const SHARE_LINK_EDIT_COUNT = index_module.dist.gql `
214
- query shareLinkEditCount {
215
- viewer {
216
- ... on User {
217
- shareLinkCodes {
218
- totalCount
219
- data {
220
- isVanity
221
- }
222
- }
223
- }
224
- }
225
- }
226
- `;
227
- function parseShareUrl(url) {
228
- try {
229
- const parsed = new URL(url);
230
- return {
231
- url: parsed.origin + parsed.pathname,
232
- domain: parsed.origin + "/",
233
- path: parsed.pathname.slice(1),
234
- };
235
- }
236
- catch {
237
- return { url, domain: url, path: "" };
238
- }
239
- }
240
- function useShareLink(props) {
241
- var _a, _b, _c, _d, _e, _f, _g;
242
- const { programId = index_module.H() } = props;
243
- const user = index_module.J();
244
- const engagementMedium = index_module.B();
245
- const contextData = index_module.Fn(useReferralCodes.REFERRAL_CODES_NAMESPACE);
246
- const { data, refetch } = index_module.wn(MessageLinkQuery, { programId }, !(user === null || user === void 0 ? void 0 : user.jwt) || !!props.linkOverride || (contextData === null || contextData === void 0 ? void 0 : contextData.shareLink) !== undefined);
247
- const [sendLoadEvent] = index_module.$e(WIDGET_ENGAGEMENT_EVENT);
248
- const [setCopied] = index_module.$e(useReferralCodes.SET_CODE_COPIED);
249
- const [addShareLinkCode, { loading: isSaving }] = index_module.$e(ADD_SHARE_LINK_CODE);
250
- const [validateLinkCode] = index_module.Xe(VALIDATE_LINK_CODE);
251
- const { refresh } = index_module.Qe();
252
- const { data: linkDomainData } = index_module.wn(GET_LINK_DOMAIN, {}, !(user === null || user === void 0 ? void 0 : user.jwt) || !props.customizeUrl);
253
- const { data: editCountData, refetch: refetchEditCount } = index_module.wn(SHARE_LINK_EDIT_COUNT, {}, !(user === null || user === void 0 ? void 0 : user.jwt) || !props.customizeUrl);
254
- const { url: copyString, domain: domainPrefix, path: pathSuffix, } = parseShareUrl((_b = ((contextData === null || contextData === void 0 ? void 0 : contextData.shareLink) || ((_a = data === null || data === void 0 ? void 0 : data.user) === null || _a === void 0 ? void 0 : _a.shareLink))) !== null && _b !== void 0 ? _b :
255
- // Shown during loading
256
- "...");
257
- const [open, setOpen] = domContextHooks_module.useState(false);
258
- const [isEditing, setIsEditing] = domContextHooks_module.useState(false);
259
- const [editValue, setEditValue] = domContextHooks_module.useState("");
260
- const [validationError, setValidationError] = domContextHooks_module.useState(null);
261
- const [isValidating, setIsValidating] = domContextHooks_module.useState(false);
262
- const debounceTimerRef = domContextHooks_module.useRef(undefined);
263
- const hasPrimaryLinkDomain = ((_c = linkDomainData === null || linkDomainData === void 0 ? void 0 : linkDomainData.tenantSettings) === null || _c === void 0 ? void 0 : _c.primaryLinkDomain) != null;
264
- const customizeDisabled = !hasPrimaryLinkDomain;
265
- const vanityCount = (_g = (_f = (_e = (_d = editCountData === null || editCountData === void 0 ? void 0 : editCountData.viewer) === null || _d === void 0 ? void 0 : _d.shareLinkCodes) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.filter((code) => code.isVanity).length) !== null && _g !== void 0 ? _g : 0;
266
- const editCount = vanityCount;
267
- const editsRemaining = Math.max(0, MAX_EDITS - editCount);
268
- const limitReached = editsRemaining <= 0;
269
- function mapErrorCodeToInfo(errorCode) {
270
- if (!errorCode)
271
- return null;
272
- const errorMap = {
273
- EXISTING_CODE_CONFLICT: {
274
- code: "EXISTING_CODE_CONFLICT",
275
- title: props.existingCodeConflictErrorTitle,
276
- description: props.existingCodeConflictErrorDescription,
277
- },
278
- INVALID_CHARACTER: {
279
- code: "INVALID_CHARACTER",
280
- title: props.invalidCharactersErrorTitle,
281
- description: props.invalidCharactersErrorDescription,
282
- },
283
- BLOCKED_WORD: {
284
- code: "BLOCKED_WORD",
285
- title: props.profanityErrorTitle,
286
- description: props.profanityErrorDescription,
287
- },
288
- };
289
- return errorMap[errorCode];
290
- }
291
- async function onClick() {
292
- if (contextData) {
293
- await setCopied({ referralCode: contextData.referralCode });
294
- contextData.refresh();
295
- }
296
- // Should well supported: https://developer.mozilla.org/en-US/docs/Web/API/Clipboard#browser_compatibility
297
- // Only if called from a user-initiated event
298
- navigator.clipboard.writeText(copyString);
299
- setOpen(true);
300
- setTimeout(() => setOpen(false), props.tooltiplifespan);
301
- sendLoadEvent({
302
- eventMeta: {
303
- programId,
304
- id: user === null || user === void 0 ? void 0 : user.id,
305
- accountId: user === null || user === void 0 ? void 0 : user.accountId,
306
- type: "USER_REFERRAL_PROGRAM_ENGAGEMENT_EVENT",
307
- meta: {
308
- engagementMedium,
309
- shareMedium: "DIRECT",
310
- },
311
- },
312
- });
313
- }
314
- function onCustomizeClick() {
315
- if (limitReached || customizeDisabled)
316
- return;
317
- setIsEditing(true);
318
- setEditValue(editCount === 0 ? "" : pathSuffix);
319
- setValidationError(null);
320
- }
321
- function onEditValueChange(value) {
322
- const trimmed = value.slice(0, CHARACTER_LIMIT);
323
- setEditValue(trimmed);
324
- setValidationError(null);
325
- if (debounceTimerRef.current)
326
- clearTimeout(debounceTimerRef.current);
327
- if (!trimmed || trimmed.length < MIN_CHARACTERS) {
328
- setIsValidating(false);
329
- return;
330
- }
331
- setIsValidating(true);
332
- debounceTimerRef.current = setTimeout(async () => {
333
- var _a, _b;
334
- try {
335
- const result = await validateLinkCode({ linkCode: trimmed });
336
- if (!((_a = result === null || result === void 0 ? void 0 : result.validateLinkCode) === null || _a === void 0 ? void 0 : _a.valid)) {
337
- const reason = (_b = result === null || result === void 0 ? void 0 : result.validateLinkCode) === null || _b === void 0 ? void 0 : _b.invalidReason;
338
- console.log(reason, "validation error reason from validateLinkCode query");
339
- setValidationError(mapErrorCodeToInfo(reason));
340
- }
341
- }
342
- catch {
343
- // Validation query failed — don't block the user
344
- }
345
- setIsValidating(false);
346
- }, 2000);
347
- }
348
- async function onSave() {
349
- var _a, _b;
350
- if (!editValue ||
351
- editValue.length < MIN_CHARACTERS ||
352
- validationError ||
353
- isValidating)
354
- return;
355
- try {
356
- await addShareLinkCode({
357
- addShareLinkCodeInput: {
358
- userId: user === null || user === void 0 ? void 0 : user.id,
359
- accountId: user === null || user === void 0 ? void 0 : user.accountId,
360
- programId,
361
- linkCode: editValue,
362
- makeShareLinkCodePrimaryForReferralCode: true,
363
- },
364
- });
365
- setIsEditing(false);
366
- await Promise.all([refetch(), refetchEditCount()]);
367
- refresh();
368
- }
369
- catch (e) {
370
- const errorCode = (_a = e === null || e === void 0 ? void 0 : e.extensions) === null || _a === void 0 ? void 0 : _a.code;
371
- console.log(errorCode, "errorCode from addSharelInkCodeMutation");
372
- setValidationError((_b = mapErrorCodeToInfo(errorCode)) !== null && _b !== void 0 ? _b : {
373
- code: null,
374
- title: "Error",
375
- description: (e === null || e === void 0 ? void 0 : e.message) || "Failed to save custom link. Please try again.",
376
- });
377
- }
378
- }
379
- function onCancel() {
380
- setIsEditing(false);
381
- setEditValue("");
382
- setValidationError(null);
383
- setIsValidating(false);
384
- }
385
- console.log(validationError, "validation error state"); // TEMP --- IGNORE ---
386
- return {
387
- copyTextViewProps: {
388
- ...props,
389
- onClick,
390
- open,
391
- copyString,
392
- },
393
- customizeUrl: props.customizeUrl,
394
- customizeLinkLabel: props.customizeLinkLabel,
395
- saveLabelText: props.saveLabelText,
396
- cancelLabelText: props.cancelLabelText,
397
- isEditing,
398
- editValue,
399
- domainPrefix,
400
- editsRemaining,
401
- maxEdits: MAX_EDITS,
402
- limitReached,
403
- validationError,
404
- isValidating,
405
- isSaving,
406
- characterLimit: CHARACTER_LIMIT,
407
- minCharacters: MIN_CHARACTERS,
408
- charactersRemaining: CHARACTER_LIMIT - editValue.length,
409
- editLimitText: props.editLimitText,
410
- editLimitReachedText: props.editLimitReachedText,
411
- supportLinkText: props.supportLinkText,
412
- customizeDisabled,
413
- customizeDisabledTooltip: props.customizeDisabledTooltip,
414
- onCustomizeClick,
415
- onEditValueChange,
416
- onSave,
417
- onCancel,
418
- };
419
- }
420
-
421
- exports.ShareLinkView = ShareLinkView;
422
- exports.useShareLink = useShareLink;