@descope/sdk-mixins 0.0.0-next-0e292820-20250415

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 (201) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +0 -0
  3. package/dist/cjs/constants.js +6 -0
  4. package/dist/cjs/constants.js.map +1 -0
  5. package/dist/cjs/index.js +41 -0
  6. package/dist/cjs/index.js.map +1 -0
  7. package/dist/cjs/mixins/baseUrlMixin.js +14 -0
  8. package/dist/cjs/mixins/baseUrlMixin.js.map +1 -0
  9. package/dist/cjs/mixins/configMixin/configMixin.js +53 -0
  10. package/dist/cjs/mixins/configMixin/configMixin.js.map +1 -0
  11. package/dist/cjs/mixins/configMixin/constants.js +6 -0
  12. package/dist/cjs/mixins/configMixin/constants.js.map +1 -0
  13. package/dist/cjs/mixins/cookieConfigMixin.js +14 -0
  14. package/dist/cjs/mixins/cookieConfigMixin.js.map +1 -0
  15. package/dist/cjs/mixins/createStateManagementMixin.js +47 -0
  16. package/dist/cjs/mixins/createStateManagementMixin.js.map +1 -0
  17. package/dist/cjs/mixins/createValidateAttributesMixin/commonValidators.js +7 -0
  18. package/dist/cjs/mixins/createValidateAttributesMixin/commonValidators.js.map +1 -0
  19. package/dist/cjs/mixins/createValidateAttributesMixin/createValidateAttributesMixin.js +40 -0
  20. package/dist/cjs/mixins/createValidateAttributesMixin/createValidateAttributesMixin.js.map +1 -0
  21. package/dist/cjs/mixins/debuggerMixin/debugger-wc.js +237 -0
  22. package/dist/cjs/mixins/debuggerMixin/debugger-wc.js.map +1 -0
  23. package/dist/cjs/mixins/debuggerMixin/debuggerMixin.js +73 -0
  24. package/dist/cjs/mixins/debuggerMixin/debuggerMixin.js.map +1 -0
  25. package/dist/cjs/mixins/debuggerMixin/helpers.js +76 -0
  26. package/dist/cjs/mixins/debuggerMixin/helpers.js.map +1 -0
  27. package/dist/cjs/mixins/descopeUiMixin/constants.js +25 -0
  28. package/dist/cjs/mixins/descopeUiMixin/constants.js.map +1 -0
  29. package/dist/cjs/mixins/descopeUiMixin/descopeUiMixin.js +168 -0
  30. package/dist/cjs/mixins/descopeUiMixin/descopeUiMixin.js.map +1 -0
  31. package/dist/cjs/mixins/descopeUiMixin/helpers.js +18 -0
  32. package/dist/cjs/mixins/descopeUiMixin/helpers.js.map +1 -0
  33. package/dist/cjs/mixins/formMixin.js +57 -0
  34. package/dist/cjs/mixins/formMixin.js.map +1 -0
  35. package/dist/cjs/mixins/initElementMixin.js +39 -0
  36. package/dist/cjs/mixins/initElementMixin.js.map +1 -0
  37. package/dist/cjs/mixins/initLifecycleMixin.js +29 -0
  38. package/dist/cjs/mixins/initLifecycleMixin.js.map +1 -0
  39. package/dist/cjs/mixins/loggerMixin/loggerMixin.js +37 -0
  40. package/dist/cjs/mixins/loggerMixin/loggerMixin.js.map +1 -0
  41. package/dist/cjs/mixins/modalMixin/constants.js +6 -0
  42. package/dist/cjs/mixins/modalMixin/constants.js.map +1 -0
  43. package/dist/cjs/mixins/modalMixin/helpers.js +14 -0
  44. package/dist/cjs/mixins/modalMixin/helpers.js.map +1 -0
  45. package/dist/cjs/mixins/modalMixin/modalMixin.js +47 -0
  46. package/dist/cjs/mixins/modalMixin/modalMixin.js.map +1 -0
  47. package/dist/cjs/mixins/notificationsMixin/constants.js +6 -0
  48. package/dist/cjs/mixins/notificationsMixin/constants.js.map +1 -0
  49. package/dist/cjs/mixins/notificationsMixin/helpers.js +14 -0
  50. package/dist/cjs/mixins/notificationsMixin/helpers.js.map +1 -0
  51. package/dist/cjs/mixins/notificationsMixin/notificationsMixin.js +50 -0
  52. package/dist/cjs/mixins/notificationsMixin/notificationsMixin.js.map +1 -0
  53. package/dist/cjs/mixins/observeAttributesMixin/helpers.js +17 -0
  54. package/dist/cjs/mixins/observeAttributesMixin/helpers.js.map +1 -0
  55. package/dist/cjs/mixins/observeAttributesMixin/observeAttributesMixin.js +47 -0
  56. package/dist/cjs/mixins/observeAttributesMixin/observeAttributesMixin.js.map +1 -0
  57. package/dist/cjs/mixins/projectIdMixin.js +17 -0
  58. package/dist/cjs/mixins/projectIdMixin.js.map +1 -0
  59. package/dist/cjs/mixins/resetMixin.js +47 -0
  60. package/dist/cjs/mixins/resetMixin.js.map +1 -0
  61. package/dist/cjs/mixins/staticResourcesMixin/constants.js +13 -0
  62. package/dist/cjs/mixins/staticResourcesMixin/constants.js.map +1 -0
  63. package/dist/cjs/mixins/staticResourcesMixin/fetchWithFallbacks.js +43 -0
  64. package/dist/cjs/mixins/staticResourcesMixin/fetchWithFallbacks.js.map +1 -0
  65. package/dist/cjs/mixins/staticResourcesMixin/index.js +9 -0
  66. package/dist/cjs/mixins/staticResourcesMixin/index.js.map +1 -0
  67. package/dist/cjs/mixins/staticResourcesMixin/staticResourcesMixin.js +101 -0
  68. package/dist/cjs/mixins/staticResourcesMixin/staticResourcesMixin.js.map +1 -0
  69. package/dist/cjs/mixins/themeMixin/constants.js +7 -0
  70. package/dist/cjs/mixins/themeMixin/constants.js.map +1 -0
  71. package/dist/cjs/mixins/themeMixin/helpers.js +34 -0
  72. package/dist/cjs/mixins/themeMixin/helpers.js.map +1 -0
  73. package/dist/cjs/mixins/themeMixin/index.js +8 -0
  74. package/dist/cjs/mixins/themeMixin/index.js.map +1 -0
  75. package/dist/cjs/mixins/themeMixin/themeMixin.js +179 -0
  76. package/dist/cjs/mixins/themeMixin/themeMixin.js.map +1 -0
  77. package/dist/cjs/package.json +1 -0
  78. package/dist/esm/constants.js +4 -0
  79. package/dist/esm/constants.js.map +1 -0
  80. package/dist/esm/index.js +18 -0
  81. package/dist/esm/index.js.map +1 -0
  82. package/dist/esm/mixins/baseUrlMixin.js +12 -0
  83. package/dist/esm/mixins/baseUrlMixin.js.map +1 -0
  84. package/dist/esm/mixins/configMixin/configMixin.js +51 -0
  85. package/dist/esm/mixins/configMixin/configMixin.js.map +1 -0
  86. package/dist/esm/mixins/configMixin/constants.js +4 -0
  87. package/dist/esm/mixins/configMixin/constants.js.map +1 -0
  88. package/dist/esm/mixins/cookieConfigMixin.js +12 -0
  89. package/dist/esm/mixins/cookieConfigMixin.js.map +1 -0
  90. package/dist/esm/mixins/createStateManagementMixin.js +45 -0
  91. package/dist/esm/mixins/createStateManagementMixin.js.map +1 -0
  92. package/dist/esm/mixins/createValidateAttributesMixin/commonValidators.js +5 -0
  93. package/dist/esm/mixins/createValidateAttributesMixin/commonValidators.js.map +1 -0
  94. package/dist/esm/mixins/createValidateAttributesMixin/createValidateAttributesMixin.js +38 -0
  95. package/dist/esm/mixins/createValidateAttributesMixin/createValidateAttributesMixin.js.map +1 -0
  96. package/dist/esm/mixins/debuggerMixin/debugger-wc.js +233 -0
  97. package/dist/esm/mixins/debuggerMixin/debugger-wc.js.map +1 -0
  98. package/dist/esm/mixins/debuggerMixin/debuggerMixin.js +71 -0
  99. package/dist/esm/mixins/debuggerMixin/debuggerMixin.js.map +1 -0
  100. package/dist/esm/mixins/debuggerMixin/helpers.js +72 -0
  101. package/dist/esm/mixins/debuggerMixin/helpers.js.map +1 -0
  102. package/dist/esm/mixins/descopeUiMixin/constants.js +16 -0
  103. package/dist/esm/mixins/descopeUiMixin/constants.js.map +1 -0
  104. package/dist/esm/mixins/descopeUiMixin/descopeUiMixin.js +166 -0
  105. package/dist/esm/mixins/descopeUiMixin/descopeUiMixin.js.map +1 -0
  106. package/dist/esm/mixins/descopeUiMixin/helpers.js +14 -0
  107. package/dist/esm/mixins/descopeUiMixin/helpers.js.map +1 -0
  108. package/dist/esm/mixins/formMixin.js +55 -0
  109. package/dist/esm/mixins/formMixin.js.map +1 -0
  110. package/dist/esm/mixins/initElementMixin.js +37 -0
  111. package/dist/esm/mixins/initElementMixin.js.map +1 -0
  112. package/dist/esm/mixins/initLifecycleMixin.js +27 -0
  113. package/dist/esm/mixins/initLifecycleMixin.js.map +1 -0
  114. package/dist/esm/mixins/loggerMixin/loggerMixin.js +35 -0
  115. package/dist/esm/mixins/loggerMixin/loggerMixin.js.map +1 -0
  116. package/dist/esm/mixins/modalMixin/constants.js +4 -0
  117. package/dist/esm/mixins/modalMixin/constants.js.map +1 -0
  118. package/dist/esm/mixins/modalMixin/helpers.js +12 -0
  119. package/dist/esm/mixins/modalMixin/helpers.js.map +1 -0
  120. package/dist/esm/mixins/modalMixin/modalMixin.js +45 -0
  121. package/dist/esm/mixins/modalMixin/modalMixin.js.map +1 -0
  122. package/dist/esm/mixins/notificationsMixin/constants.js +4 -0
  123. package/dist/esm/mixins/notificationsMixin/constants.js.map +1 -0
  124. package/dist/esm/mixins/notificationsMixin/helpers.js +12 -0
  125. package/dist/esm/mixins/notificationsMixin/helpers.js.map +1 -0
  126. package/dist/esm/mixins/notificationsMixin/notificationsMixin.js +48 -0
  127. package/dist/esm/mixins/notificationsMixin/notificationsMixin.js.map +1 -0
  128. package/dist/esm/mixins/observeAttributesMixin/helpers.js +15 -0
  129. package/dist/esm/mixins/observeAttributesMixin/helpers.js.map +1 -0
  130. package/dist/esm/mixins/observeAttributesMixin/observeAttributesMixin.js +45 -0
  131. package/dist/esm/mixins/observeAttributesMixin/observeAttributesMixin.js.map +1 -0
  132. package/dist/esm/mixins/projectIdMixin.js +15 -0
  133. package/dist/esm/mixins/projectIdMixin.js.map +1 -0
  134. package/dist/esm/mixins/resetMixin.js +45 -0
  135. package/dist/esm/mixins/resetMixin.js.map +1 -0
  136. package/dist/esm/mixins/staticResourcesMixin/constants.js +9 -0
  137. package/dist/esm/mixins/staticResourcesMixin/constants.js.map +1 -0
  138. package/dist/esm/mixins/staticResourcesMixin/fetchWithFallbacks.js +41 -0
  139. package/dist/esm/mixins/staticResourcesMixin/fetchWithFallbacks.js.map +1 -0
  140. package/dist/esm/mixins/staticResourcesMixin/index.js +2 -0
  141. package/dist/esm/mixins/staticResourcesMixin/index.js.map +1 -0
  142. package/dist/esm/mixins/staticResourcesMixin/staticResourcesMixin.js +98 -0
  143. package/dist/esm/mixins/staticResourcesMixin/staticResourcesMixin.js.map +1 -0
  144. package/dist/esm/mixins/themeMixin/constants.js +5 -0
  145. package/dist/esm/mixins/themeMixin/constants.js.map +1 -0
  146. package/dist/esm/mixins/themeMixin/helpers.js +31 -0
  147. package/dist/esm/mixins/themeMixin/helpers.js.map +1 -0
  148. package/dist/esm/mixins/themeMixin/index.js +2 -0
  149. package/dist/esm/mixins/themeMixin/index.js.map +1 -0
  150. package/dist/esm/mixins/themeMixin/themeMixin.js +177 -0
  151. package/dist/esm/mixins/themeMixin/themeMixin.js.map +1 -0
  152. package/dist/index.d.ts +6169 -0
  153. package/dist/types/constants.d.ts +1 -0
  154. package/dist/types/index.d.ts +23 -0
  155. package/dist/types/mixins/baseUrlMixin.d.ts +331 -0
  156. package/dist/types/mixins/configMixin/configMixin.d.ts +363 -0
  157. package/dist/types/mixins/configMixin/constants.d.ts +1 -0
  158. package/dist/types/mixins/configMixin/index.d.ts +2 -0
  159. package/dist/types/mixins/configMixin/types.d.ts +66 -0
  160. package/dist/types/mixins/cookieConfigMixin.d.ts +331 -0
  161. package/dist/types/mixins/createStateManagementMixin.d.ts +341 -0
  162. package/dist/types/mixins/createValidateAttributesMixin/commonValidators.d.ts +1 -0
  163. package/dist/types/mixins/createValidateAttributesMixin/createValidateAttributesMixin.d.ts +346 -0
  164. package/dist/types/mixins/createValidateAttributesMixin/index.d.ts +1 -0
  165. package/dist/types/mixins/debuggerMixin/debugger-wc.d.ts +9 -0
  166. package/dist/types/mixins/debuggerMixin/debuggerMixin.d.ts +347 -0
  167. package/dist/types/mixins/debuggerMixin/helpers.d.ts +4 -0
  168. package/dist/types/mixins/debuggerMixin/index.d.ts +1 -0
  169. package/dist/types/mixins/debuggerMixin/types.d.ts +12 -0
  170. package/dist/types/mixins/descopeUiMixin/constants.d.ts +8 -0
  171. package/dist/types/mixins/descopeUiMixin/descopeUiMixin.d.ts +378 -0
  172. package/dist/types/mixins/descopeUiMixin/helpers.d.ts +3 -0
  173. package/dist/types/mixins/descopeUiMixin/index.d.ts +1 -0
  174. package/dist/types/mixins/formMixin.d.ts +345 -0
  175. package/dist/types/mixins/initElementMixin.d.ts +332 -0
  176. package/dist/types/mixins/initLifecycleMixin.d.ts +332 -0
  177. package/dist/types/mixins/loggerMixin/index.d.ts +2 -0
  178. package/dist/types/mixins/loggerMixin/loggerMixin.d.ts +339 -0
  179. package/dist/types/mixins/loggerMixin/types.d.ts +6 -0
  180. package/dist/types/mixins/modalMixin/constants.d.ts +1 -0
  181. package/dist/types/mixins/modalMixin/helpers.d.ts +1 -0
  182. package/dist/types/mixins/modalMixin/index.d.ts +1 -0
  183. package/dist/types/mixins/modalMixin/modalMixin.d.ts +408 -0
  184. package/dist/types/mixins/notificationsMixin/constants.d.ts +1 -0
  185. package/dist/types/mixins/notificationsMixin/helpers.d.ts +1 -0
  186. package/dist/types/mixins/notificationsMixin/index.d.ts +1 -0
  187. package/dist/types/mixins/notificationsMixin/notificationsMixin.d.ts +427 -0
  188. package/dist/types/mixins/observeAttributesMixin/helpers.d.ts +1 -0
  189. package/dist/types/mixins/observeAttributesMixin/index.d.ts +1 -0
  190. package/dist/types/mixins/observeAttributesMixin/observeAttributesMixin.d.ts +342 -0
  191. package/dist/types/mixins/projectIdMixin.d.ts +342 -0
  192. package/dist/types/mixins/resetMixin.d.ts +344 -0
  193. package/dist/types/mixins/staticResourcesMixin/constants.d.ts +4 -0
  194. package/dist/types/mixins/staticResourcesMixin/fetchWithFallbacks.d.ts +7 -0
  195. package/dist/types/mixins/staticResourcesMixin/index.d.ts +1 -0
  196. package/dist/types/mixins/staticResourcesMixin/staticResourcesMixin.d.ts +362 -0
  197. package/dist/types/mixins/themeMixin/constants.d.ts +2 -0
  198. package/dist/types/mixins/themeMixin/helpers.d.ts +5 -0
  199. package/dist/types/mixins/themeMixin/index.d.ts +1 -0
  200. package/dist/types/mixins/themeMixin/themeMixin.d.ts +408 -0
  201. package/package.json +125 -0
@@ -0,0 +1,233 @@
1
+ import { __classPrivateFieldGet, __classPrivateFieldSet } from 'tslib';
2
+ import { State } from '@descope/sdk-helpers';
3
+ import { dragElement, addOnResize, limitCoordinateToScreenBoundaries } from './helpers.js';
4
+
5
+ var _Debugger_instances, _Debugger_messagesState, _Debugger_rootEle, _Debugger_contentEle, _Debugger_headerEle, _Debugger_eventsCbRefs, _Debugger_onNewMessages, _Debugger_renderMessages, _Debugger_setCollapsibleMessages, _Debugger_onWindowResize;
6
+ const INITIAL_POS_THRESHOLD = 32;
7
+ const INITIAL_WIDTH = 300;
8
+ const INITIAL_HEIGHT = 200;
9
+ const MIN_SIZE = 200;
10
+ const template = document.createElement('template');
11
+ template.innerHTML = `
12
+ <div style="top:${INITIAL_POS_THRESHOLD}px; left:${window.innerWidth - INITIAL_WIDTH - INITIAL_POS_THRESHOLD}px;" class="debugger">
13
+ <div class="header">
14
+ <span>Debugger messages</span>
15
+ </div>
16
+ <div class="content">
17
+ <div class="empty-state">
18
+ No errors detected 👀
19
+ </div>
20
+ </div>
21
+ </div>
22
+ `;
23
+ const icon = `<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
24
+ <path d="M5.99984 13.167L8.99984 10.167L11.9998 13.167L13.1665 12.0003L10.1665 9.00033L13.1665 6.00033L11.9998 4.83366L8.99984 7.83366L5.99984 4.83366L4.83317 6.00033L7.83317 9.00033L4.83317 12.0003L5.99984 13.167ZM8.99984 17.3337C7.84706 17.3337 6.76373 17.1148 5.74984 16.677C4.73595 16.2398 3.854 15.6462 3.104 14.8962C2.354 14.1462 1.76039 13.2642 1.32317 12.2503C0.885393 11.2364 0.666504 10.1531 0.666504 9.00033C0.666504 7.84755 0.885393 6.76421 1.32317 5.75033C1.76039 4.73644 2.354 3.85449 3.104 3.10449C3.854 2.35449 4.73595 1.7606 5.74984 1.32283C6.76373 0.885603 7.84706 0.666992 8.99984 0.666992C10.1526 0.666992 11.2359 0.885603 12.2498 1.32283C13.2637 1.7606 14.1457 2.35449 14.8957 3.10449C15.6457 3.85449 16.2393 4.73644 16.6765 5.75033C17.1143 6.76421 17.3332 7.84755 17.3332 9.00033C17.3332 10.1531 17.1143 11.2364 16.6765 12.2503C16.2393 13.2642 15.6457 14.1462 14.8957 14.8962C14.1457 15.6462 13.2637 16.2398 12.2498 16.677C11.2359 17.1148 10.1526 17.3337 8.99984 17.3337ZM8.99984 15.667C10.8609 15.667 12.4373 15.0212 13.729 13.7295C15.0207 12.4378 15.6665 10.8614 15.6665 9.00033C15.6665 7.13921 15.0207 5.56283 13.729 4.27116C12.4373 2.97949 10.8609 2.33366 8.99984 2.33366C7.13873 2.33366 5.56234 2.97949 4.27067 4.27116C2.979 5.56283 2.33317 7.13921 2.33317 9.00033C2.33317 10.8614 2.979 12.4378 4.27067 13.7295C5.56234 15.0212 7.13873 15.667 8.99984 15.667Z" fill="#ED404A"/>
25
+ </svg>
26
+ `;
27
+ const style = `
28
+ .debugger {
29
+ all: initial;
30
+ width: ${INITIAL_WIDTH}px;
31
+ height: ${INITIAL_HEIGHT}px;
32
+ background-color: #FAFAFA;
33
+ position: fixed;
34
+ font-family: "Helvetica Neue", sans-serif;
35
+ box-shadow: rgba(0, 0, 0, 0.1) 0px 5px 10px;
36
+ border-radius: 8px;
37
+ overflow: hidden;
38
+ border: 1px solid lightgrey;
39
+ pointer-events: initial;
40
+ display: flex;
41
+ flex-direction: column;
42
+ min-width: ${MIN_SIZE}px;
43
+ max-width: 600px;
44
+ max-height: calc(100% - ${INITIAL_POS_THRESHOLD * 2}px);
45
+ min-height: ${MIN_SIZE}px;
46
+ resize: both;
47
+ }
48
+
49
+ .header {
50
+ padding: 8px 16px;
51
+ display: flex;
52
+ align-items: center;
53
+ background-color: #EEEEEE;
54
+ cursor: move;
55
+ border-bottom: 1px solid #e0e0e0;
56
+ }
57
+
58
+ .content {
59
+ font-size: 14px;
60
+ flex-grow: 1;
61
+ overflow: auto;
62
+ }
63
+
64
+ .msg {
65
+ border-bottom: 1px solid lightgrey;
66
+ padding: 8px 16px;
67
+ display: flex;
68
+ gap: 5px;
69
+ background-color: #FAFAFA;
70
+ }
71
+
72
+ .msg.collapsible {
73
+ cursor: pointer;
74
+ }
75
+
76
+ .empty-state {
77
+ padding: 8px 16px;
78
+ background-color: #FAFAFA;
79
+ }
80
+
81
+
82
+ .msg.collapsible:not(.collapsed) {
83
+ background-color: #F5F5F5;
84
+ }
85
+
86
+ .msg_title {
87
+ padding-bottom: 5px;
88
+ display: flex;
89
+ gap: 8px;
90
+ font-weight: 500;
91
+ }
92
+
93
+ .msg svg {
94
+ padding: 1px;
95
+ flex-shrink: 0;
96
+ margin-top: -2px;
97
+ }
98
+
99
+ .msg_content {
100
+ overflow: hidden;
101
+ flex-grow: 1;
102
+ margin-right:5px;
103
+ }
104
+
105
+ .msg_desc {
106
+ color: #646464;
107
+ cursor: initial;
108
+ word-wrap: break-word;
109
+ }
110
+
111
+ .msg.collapsed .msg_desc {
112
+ overflow: hidden;
113
+ text-overflow: ellipsis;
114
+ white-space: nowrap;
115
+ }
116
+
117
+ .msg.collapsible.collapsed .chevron {
118
+ transform: rotate(-45deg) translateX(-2px);
119
+ }
120
+
121
+ .msg.collapsible .chevron {
122
+ content: "";
123
+ width:6px;
124
+ height:6px;
125
+ border-bottom: 2px solid grey;
126
+ border-right: 2px solid grey;
127
+ transform: rotate(45deg) translateX(-1px);
128
+ margin: 5px;
129
+ flex-shrink:0;
130
+ }
131
+ `;
132
+ class Debugger extends HTMLElement {
133
+ constructor() {
134
+ var _a, _b;
135
+ var _c;
136
+ super();
137
+ _Debugger_instances.add(this);
138
+ _Debugger_messagesState.set(this, new State({ messages: [] }));
139
+ _Debugger_rootEle.set(this, void 0);
140
+ _Debugger_contentEle.set(this, void 0);
141
+ _Debugger_headerEle.set(this, void 0);
142
+ _Debugger_eventsCbRefs.set(this, {
143
+ resize: __classPrivateFieldGet(this, _Debugger_instances, "m", _Debugger_onWindowResize).bind(this),
144
+ });
145
+ this.attachShadow({ mode: 'open' });
146
+ (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.appendChild(template.content.cloneNode(true));
147
+ const sheet = new CSSStyleSheet();
148
+ sheet.replaceSync(style);
149
+ (_b = (_c = this.shadowRoot).adoptedStyleSheets) !== null && _b !== void 0 ? _b : (_c.adoptedStyleSheets = []);
150
+ this.shadowRoot.adoptedStyleSheets = [
151
+ ...this.shadowRoot.adoptedStyleSheets,
152
+ sheet,
153
+ ];
154
+ __classPrivateFieldSet(this, _Debugger_rootEle, this.shadowRoot.querySelector('.debugger'), "f");
155
+ __classPrivateFieldSet(this, _Debugger_contentEle, __classPrivateFieldGet(this, _Debugger_rootEle, "f").querySelector('.content'), "f");
156
+ __classPrivateFieldSet(this, _Debugger_headerEle, __classPrivateFieldGet(this, _Debugger_rootEle, "f").querySelector('.header'), "f");
157
+ }
158
+ updateData(data) {
159
+ __classPrivateFieldGet(this, _Debugger_messagesState, "f").update((state) => ({
160
+ messages: state.messages.concat(data),
161
+ }));
162
+ }
163
+ connectedCallback() {
164
+ dragElement(__classPrivateFieldGet(this, _Debugger_rootEle, "f"), __classPrivateFieldGet(this, _Debugger_headerEle, "f"), {
165
+ top: 'all',
166
+ bottom: 100,
167
+ left: 100,
168
+ right: 100,
169
+ });
170
+ window.addEventListener('resize', __classPrivateFieldGet(this, _Debugger_eventsCbRefs, "f").resize);
171
+ addOnResize(__classPrivateFieldGet(this, _Debugger_rootEle, "f"));
172
+ __classPrivateFieldGet(this, _Debugger_rootEle, "f").onresize = __classPrivateFieldGet(this, _Debugger_instances, "m", _Debugger_setCollapsibleMessages).bind(this);
173
+ __classPrivateFieldGet(this, _Debugger_messagesState, "f").subscribe(__classPrivateFieldGet(this, _Debugger_instances, "m", _Debugger_onNewMessages).bind(this));
174
+ }
175
+ disconnectedCallback() {
176
+ __classPrivateFieldGet(this, _Debugger_messagesState, "f").unsubscribeAll();
177
+ window.removeEventListener('resize', __classPrivateFieldGet(this, _Debugger_eventsCbRefs, "f").resize);
178
+ }
179
+ }
180
+ _Debugger_messagesState = new WeakMap(), _Debugger_rootEle = new WeakMap(), _Debugger_contentEle = new WeakMap(), _Debugger_headerEle = new WeakMap(), _Debugger_eventsCbRefs = new WeakMap(), _Debugger_instances = new WeakSet(), _Debugger_onNewMessages = function _Debugger_onNewMessages(data) {
181
+ __classPrivateFieldGet(this, _Debugger_instances, "m", _Debugger_renderMessages).call(this, data);
182
+ __classPrivateFieldGet(this, _Debugger_instances, "m", _Debugger_setCollapsibleMessages).call(this);
183
+ }, _Debugger_renderMessages = function _Debugger_renderMessages(data) {
184
+ __classPrivateFieldGet(this, _Debugger_contentEle, "f").innerHTML = data.messages
185
+ .map((message) => `
186
+ <div class="msg">
187
+ ${icon}
188
+ <div class="msg_content">
189
+ <div class="msg_title">
190
+ ${message.title}
191
+ </div>
192
+ <div class="msg_desc">
193
+ ${message.description || ''}
194
+ </div>
195
+ </div>
196
+ <div class="chevron"></div>
197
+ </div>
198
+ `)
199
+ .join('');
200
+ }, _Debugger_setCollapsibleMessages = function _Debugger_setCollapsibleMessages() {
201
+ __classPrivateFieldGet(this, _Debugger_contentEle, "f").querySelectorAll('.msg').forEach((element) => {
202
+ const ele = element;
203
+ const descEle = ele.querySelector('.msg_desc');
204
+ const lineHeight = 20;
205
+ const isScroll = descEle.scrollWidth > descEle.clientWidth;
206
+ const isMultiLine = descEle.clientHeight > lineHeight;
207
+ const isCollapsible = isScroll || isMultiLine;
208
+ if (isCollapsible) {
209
+ ele.classList.add('collapsible');
210
+ ele.onclick = (e) => {
211
+ // message description should not toggle collapse
212
+ if (!e.target.classList.contains('msg_desc')) {
213
+ ele.classList.toggle('collapsed');
214
+ }
215
+ };
216
+ }
217
+ else {
218
+ ele.classList.remove('collapsible');
219
+ ele.onclick = null;
220
+ }
221
+ });
222
+ }, _Debugger_onWindowResize = function _Debugger_onWindowResize() {
223
+ // when window is resizing we want to make sure debugger is still visible
224
+ const [left, top] = limitCoordinateToScreenBoundaries(__classPrivateFieldGet(this, _Debugger_rootEle, "f"), Number.parseInt(__classPrivateFieldGet(this, _Debugger_rootEle, "f").style.left, 10), Number.parseInt(__classPrivateFieldGet(this, _Debugger_rootEle, "f").style.top, 10), { top: 'all', bottom: 100, left: 100, right: 100 });
225
+ __classPrivateFieldGet(this, _Debugger_rootEle, "f").style.top = `${top}px`;
226
+ __classPrivateFieldGet(this, _Debugger_rootEle, "f").style.left = `${left}px`;
227
+ };
228
+ if (!customElements.get('descope-debugger')) {
229
+ customElements.define('descope-debugger', Debugger);
230
+ }
231
+
232
+ export { Debugger as default };
233
+ //# sourceMappingURL=debugger-wc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debugger-wc.js","sources":["../../../../src/mixins/debuggerMixin/debugger-wc.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport { State } from '@descope/sdk-helpers';\nimport {\n addOnResize,\n dragElement,\n limitCoordinateToScreenBoundaries,\n} from './helpers';\nimport { DebuggerMessage } from './types';\n\nconst INITIAL_POS_THRESHOLD = 32;\nconst INITIAL_WIDTH = 300;\nconst INITIAL_HEIGHT = 200;\nconst MIN_SIZE = 200;\n\nconst template = document.createElement('template');\ntemplate.innerHTML = `\n<div style=\"top:${INITIAL_POS_THRESHOLD}px; left:${\n window.innerWidth - INITIAL_WIDTH - INITIAL_POS_THRESHOLD\n}px;\" class=\"debugger\">\n <div class=\"header\">\n <span>Debugger messages</span>\n </div>\n <div class=\"content\">\n <div class=\"empty-state\">\n No errors detected 👀\n </div>\n </div>\n</div>\n`;\n\nconst icon = `<svg width=\"18\" height=\"18\" viewBox=\"0 0 18 18\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n<path d=\"M5.99984 13.167L8.99984 10.167L11.9998 13.167L13.1665 12.0003L10.1665 9.00033L13.1665 6.00033L11.9998 4.83366L8.99984 7.83366L5.99984 4.83366L4.83317 6.00033L7.83317 9.00033L4.83317 12.0003L5.99984 13.167ZM8.99984 17.3337C7.84706 17.3337 6.76373 17.1148 5.74984 16.677C4.73595 16.2398 3.854 15.6462 3.104 14.8962C2.354 14.1462 1.76039 13.2642 1.32317 12.2503C0.885393 11.2364 0.666504 10.1531 0.666504 9.00033C0.666504 7.84755 0.885393 6.76421 1.32317 5.75033C1.76039 4.73644 2.354 3.85449 3.104 3.10449C3.854 2.35449 4.73595 1.7606 5.74984 1.32283C6.76373 0.885603 7.84706 0.666992 8.99984 0.666992C10.1526 0.666992 11.2359 0.885603 12.2498 1.32283C13.2637 1.7606 14.1457 2.35449 14.8957 3.10449C15.6457 3.85449 16.2393 4.73644 16.6765 5.75033C17.1143 6.76421 17.3332 7.84755 17.3332 9.00033C17.3332 10.1531 17.1143 11.2364 16.6765 12.2503C16.2393 13.2642 15.6457 14.1462 14.8957 14.8962C14.1457 15.6462 13.2637 16.2398 12.2498 16.677C11.2359 17.1148 10.1526 17.3337 8.99984 17.3337ZM8.99984 15.667C10.8609 15.667 12.4373 15.0212 13.729 13.7295C15.0207 12.4378 15.6665 10.8614 15.6665 9.00033C15.6665 7.13921 15.0207 5.56283 13.729 4.27116C12.4373 2.97949 10.8609 2.33366 8.99984 2.33366C7.13873 2.33366 5.56234 2.97949 4.27067 4.27116C2.979 5.56283 2.33317 7.13921 2.33317 9.00033C2.33317 10.8614 2.979 12.4378 4.27067 13.7295C5.56234 15.0212 7.13873 15.667 8.99984 15.667Z\" fill=\"#ED404A\"/>\n</svg>\n`;\n\nconst style = `\n.debugger {\n all: initial;\n width: ${INITIAL_WIDTH}px;\n height: ${INITIAL_HEIGHT}px;\n background-color: #FAFAFA;\n position: fixed;\n font-family: \"Helvetica Neue\", sans-serif;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 5px 10px;\n border-radius: 8px;\n overflow: hidden;\n border: 1px solid lightgrey;\n pointer-events: initial;\n display: flex;\n flex-direction: column;\n min-width: ${MIN_SIZE}px;\n max-width: 600px;\n max-height: calc(100% - ${INITIAL_POS_THRESHOLD * 2}px);\n min-height: ${MIN_SIZE}px;\n resize: both;\n }\n\n .header {\n padding: 8px 16px;\n display: flex;\n align-items: center;\n background-color: #EEEEEE;\n cursor: move;\n border-bottom: 1px solid #e0e0e0;\n }\n\n .content {\n font-size: 14px;\n flex-grow: 1;\n overflow: auto;\n }\n\n .msg {\n border-bottom: 1px solid lightgrey;\n padding: 8px 16px;\n display: flex;\n gap: 5px;\n background-color: #FAFAFA;\n }\n\n .msg.collapsible {\n cursor: pointer;\n }\n\n .empty-state {\n padding: 8px 16px;\n background-color: #FAFAFA;\n }\n\n\n .msg.collapsible:not(.collapsed) {\n background-color: #F5F5F5;\n }\n\n .msg_title {\n padding-bottom: 5px;\n display: flex;\n gap: 8px;\n font-weight: 500;\n }\n\n .msg svg {\n padding: 1px;\n flex-shrink: 0;\n margin-top: -2px;\n }\n\n .msg_content {\n overflow: hidden;\n flex-grow: 1;\n margin-right:5px;\n }\n\n .msg_desc {\n color: #646464;\n cursor: initial;\n word-wrap: break-word;\n }\n\n .msg.collapsed .msg_desc {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n .msg.collapsible.collapsed .chevron {\n transform: rotate(-45deg) translateX(-2px);\n }\n\n .msg.collapsible .chevron {\n content: \"\";\n width:6px;\n height:6px;\n border-bottom: 2px solid grey;\n border-right: 2px solid grey;\n transform: rotate(45deg) translateX(-1px);\n margin: 5px;\n flex-shrink:0;\n }\n`;\n\ntype MessagesState = { messages: DebuggerMessage[] };\n\nclass Debugger extends HTMLElement {\n #messagesState = new State<MessagesState>({ messages: [] });\n\n #rootEle: HTMLDivElement;\n\n #contentEle: HTMLDivElement;\n\n #headerEle: HTMLDivElement;\n\n #eventsCbRefs = {\n resize: this.#onWindowResize.bind(this),\n };\n\n constructor() {\n super();\n\n this.attachShadow({ mode: 'open' });\n this.shadowRoot?.appendChild(template.content.cloneNode(true));\n const sheet = new CSSStyleSheet();\n sheet.replaceSync(style);\n this.shadowRoot.adoptedStyleSheets ??= [];\n this.shadowRoot.adoptedStyleSheets = [\n ...this.shadowRoot.adoptedStyleSheets,\n sheet,\n ];\n\n this.#rootEle =\n this.shadowRoot!.querySelector<HTMLDivElement>('.debugger')!;\n this.#contentEle = this.#rootEle.querySelector<HTMLDivElement>('.content')!;\n this.#headerEle = this.#rootEle.querySelector<HTMLDivElement>('.header')!;\n }\n\n updateData(data: DebuggerMessage | DebuggerMessage[]) {\n this.#messagesState.update((state) => ({\n messages: state.messages.concat(data),\n }));\n }\n\n #onNewMessages(data: MessagesState) {\n this.#renderMessages(data);\n this.#setCollapsibleMessages();\n }\n\n #renderMessages(data: MessagesState) {\n this.#contentEle.innerHTML = data.messages\n .map(\n (message) => `\n <div class=\"msg\">\n ${icon}\n <div class=\"msg_content\">\n <div class=\"msg_title\">\n ${message.title}\n </div>\n <div class=\"msg_desc\">\n ${message.description || ''}\n </div>\n </div>\n <div class=\"chevron\"></div>\n </div>\n `,\n )\n .join('');\n }\n\n #setCollapsibleMessages() {\n this.#contentEle.querySelectorAll('.msg').forEach((element: Element) => {\n const ele = element as HTMLElement;\n const descEle = ele.querySelector('.msg_desc');\n const lineHeight = 20;\n const isScroll = descEle!.scrollWidth > descEle!.clientWidth;\n const isMultiLine = descEle!.clientHeight > lineHeight;\n const isCollapsible = isScroll || isMultiLine;\n\n if (isCollapsible) {\n ele.classList.add('collapsible');\n ele.onclick = (e: MouseEvent) => {\n // message description should not toggle collapse\n if (!(e.target as HTMLElement).classList.contains('msg_desc')) {\n ele.classList.toggle('collapsed');\n }\n };\n } else {\n ele.classList.remove('collapsible');\n ele.onclick = null;\n }\n });\n }\n\n #onWindowResize() {\n // when window is resizing we want to make sure debugger is still visible\n const [left, top] = limitCoordinateToScreenBoundaries(\n this.#rootEle,\n Number.parseInt(this.#rootEle.style.left, 10),\n Number.parseInt(this.#rootEle.style.top, 10),\n { top: 'all', bottom: 100, left: 100, right: 100 },\n );\n this.#rootEle.style.top = `${top}px`;\n this.#rootEle.style.left = `${left}px`;\n }\n\n connectedCallback() {\n dragElement(this.#rootEle, this.#headerEle, {\n top: 'all',\n bottom: 100,\n left: 100,\n right: 100,\n });\n\n window.addEventListener('resize', this.#eventsCbRefs.resize);\n\n addOnResize(this.#rootEle);\n this.#rootEle.onresize = this.#setCollapsibleMessages.bind(this);\n\n this.#messagesState.subscribe(this.#onNewMessages.bind(this));\n }\n\n disconnectedCallback() {\n this.#messagesState.unsubscribeAll();\n window.removeEventListener('resize', this.#eventsCbRefs.resize);\n }\n}\n\nif (!customElements.get('descope-debugger')) {\n customElements.define('descope-debugger', Debugger);\n}\n\nexport default Debugger;\n"],"names":[],"mappings":";;;;;AASA,MAAM,qBAAqB,GAAG,EAAE,CAAC;AACjC,MAAM,aAAa,GAAG,GAAG,CAAC;AAC1B,MAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,MAAM,QAAQ,GAAG,GAAG,CAAC;AAErB,MAAM,QAAQ,GAAG,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;AACpD,QAAQ,CAAC,SAAS,GAAG,CAAA;AACH,gBAAA,EAAA,qBAAqB,YACrC,MAAM,CAAC,UAAU,GAAG,aAAa,GAAG,qBACtC,CAAA;;;;;;;;;;CAUC,CAAC;AAEF,MAAM,IAAI,GAAG,CAAA;;;CAGZ,CAAC;AAEF,MAAM,KAAK,GAAG,CAAA;;;aAGD,aAAa,CAAA;cACZ,cAAc,CAAA;;;;;;;;;;;iBAWX,QAAQ,CAAA;;AAEK,4BAAA,EAAA,qBAAqB,GAAG,CAAC,CAAA;kBACrC,QAAQ,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsFzB,CAAC;AAIF,MAAM,QAAS,SAAQ,WAAW,CAAA;AAahC,IAAA,WAAA,GAAA;;;AACE,QAAA,KAAK,EAAE,CAAC;;QAbV,uBAAiB,CAAA,GAAA,CAAA,IAAA,EAAA,IAAI,KAAK,CAAgB,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC,CAAA;QAE5D,iBAAyB,CAAA,GAAA,CAAA,IAAA,EAAA,KAAA,CAAA,CAAA,C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,EAAS,iBAAA,EAAA,GAAA,CAAA,CAAC,KAAK,CAAC,GAAG,GAAG,CAAA,EAAG,GAAG,CAAA,EAAA,CAAI,CAAC;IACrC,sBAAA,CAAA,IAAI,EAAS,iBAAA,EAAA,GAAA,CAAA,CAAC,KAAK,CAAC,IAAI,GAAG,CAAA,EAAG,IAAI,CAAA,EAAA,CAAI,CAAC;AACzC,CAAC,CAAA;AAwBH,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,kBAAkB,CAAC,EAAE;AAC3C,IAAA,cAAc,CAAC,MAAM,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC;AACtD;;;;"}
@@ -0,0 +1,71 @@
1
+ import { __classPrivateFieldGet, __classPrivateFieldSet } from 'tslib';
2
+ import { createSingletonMixin, compose } from '@descope/sdk-helpers';
3
+ import { initLifecycleMixin } from '../initLifecycleMixin.js';
4
+ import { loggerMixin } from '../loggerMixin/loggerMixin.js';
5
+
6
+ const debuggerMixin = createSingletonMixin((superclass) => { var _DebuggerMixinClass_instances, _DebuggerMixinClass_debuggerEle, _DebuggerMixinClass_disableDebugger, _DebuggerMixinClass_enableDebugger, _DebuggerMixinClass_handleDebugMode, _DebuggerMixinClass_updateDebuggerMessages, _a; return _a = class DebuggerMixinClass extends compose(initLifecycleMixin, loggerMixin)(superclass) {
7
+ constructor() {
8
+ super(...arguments);
9
+ _DebuggerMixinClass_instances.add(this);
10
+ _DebuggerMixinClass_debuggerEle.set(this, void 0);
11
+ this.attributeChangedCallback = (attrName, oldValue, newValue) => {
12
+ var _b;
13
+ (_b = super.attributeChangedCallback) === null || _b === void 0 ? void 0 : _b.call(this, attrName, oldValue, newValue);
14
+ if (attrName === 'debug') {
15
+ __classPrivateFieldGet(this, _DebuggerMixinClass_instances, "m", _DebuggerMixinClass_handleDebugMode).call(this);
16
+ }
17
+ };
18
+ }
19
+ get debug() {
20
+ return this.getAttribute('debug') === 'true';
21
+ }
22
+ onLogEvent(logLevel, args) {
23
+ var _b;
24
+ (_b = super.onLogEvent) === null || _b === void 0 ? void 0 : _b.call(this, logLevel, args);
25
+ if (logLevel === 'error') {
26
+ __classPrivateFieldGet(this, _DebuggerMixinClass_instances, "m", _DebuggerMixinClass_updateDebuggerMessages).call(this, args[0] || 'Error', args[1]);
27
+ }
28
+ }
29
+ async init() {
30
+ var _b;
31
+ await ((_b = super.init) === null || _b === void 0 ? void 0 : _b.call(this));
32
+ __classPrivateFieldGet(this, _DebuggerMixinClass_instances, "m", _DebuggerMixinClass_handleDebugMode).call(this);
33
+ }
34
+ },
35
+ _DebuggerMixinClass_debuggerEle = new WeakMap(),
36
+ _DebuggerMixinClass_instances = new WeakSet(),
37
+ _DebuggerMixinClass_disableDebugger = function _DebuggerMixinClass_disableDebugger() {
38
+ var _b;
39
+ (_b = __classPrivateFieldGet(this, _DebuggerMixinClass_debuggerEle, "f")) === null || _b === void 0 ? void 0 : _b.remove();
40
+ __classPrivateFieldSet(this, _DebuggerMixinClass_debuggerEle, null, "f");
41
+ },
42
+ _DebuggerMixinClass_enableDebugger = async function _DebuggerMixinClass_enableDebugger() {
43
+ __classPrivateFieldSet(this, _DebuggerMixinClass_debuggerEle, document.createElement('descope-debugger'), "f");
44
+ Object.assign(__classPrivateFieldGet(this, _DebuggerMixinClass_debuggerEle, "f").style, {
45
+ position: 'fixed',
46
+ top: '0',
47
+ right: '0',
48
+ height: '100vh',
49
+ width: '100vw',
50
+ pointerEvents: 'none',
51
+ zIndex: 99999,
52
+ });
53
+ // we are importing the debugger dynamically so we won't load it when it's not needed
54
+ await import('./debugger-wc.js');
55
+ document.body.appendChild(__classPrivateFieldGet(this, _DebuggerMixinClass_debuggerEle, "f"));
56
+ },
57
+ _DebuggerMixinClass_handleDebugMode = function _DebuggerMixinClass_handleDebugMode() {
58
+ if (this.debug)
59
+ __classPrivateFieldGet(this, _DebuggerMixinClass_instances, "m", _DebuggerMixinClass_enableDebugger).call(this);
60
+ else
61
+ __classPrivateFieldGet(this, _DebuggerMixinClass_instances, "m", _DebuggerMixinClass_disableDebugger).call(this);
62
+ },
63
+ _DebuggerMixinClass_updateDebuggerMessages = function _DebuggerMixinClass_updateDebuggerMessages(title, description) {
64
+ var _b;
65
+ if (title)
66
+ (_b = __classPrivateFieldGet(this, _DebuggerMixinClass_debuggerEle, "f")) === null || _b === void 0 ? void 0 : _b.updateData({ title, description });
67
+ },
68
+ _a; });
69
+
70
+ export { debuggerMixin };
71
+ //# sourceMappingURL=debuggerMixin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debuggerMixin.js","sources":["../../../../src/mixins/debuggerMixin/debuggerMixin.ts"],"sourcesContent":["import { compose, createSingletonMixin } from '@descope/sdk-helpers';\nimport { initLifecycleMixin } from '../initLifecycleMixin';\nimport { LogLevel, loggerMixin } from '../loggerMixin';\nimport { DebuggerMessage } from './types';\n\nexport const debuggerMixin = createSingletonMixin(\n <T extends CustomElementConstructor>(superclass: T) =>\n class DebuggerMixinClass extends compose(\n initLifecycleMixin,\n loggerMixin,\n )(superclass) {\n #debuggerEle:\n | (HTMLElement & {\n updateData: (data: DebuggerMessage | DebuggerMessage[]) => void;\n })\n | null;\n\n #disableDebugger() {\n this.#debuggerEle?.remove();\n this.#debuggerEle = null;\n }\n\n async #enableDebugger() {\n this.#debuggerEle = document.createElement(\n 'descope-debugger',\n ) as HTMLElement & {\n updateData: (data: DebuggerMessage | DebuggerMessage[]) => void;\n };\n\n Object.assign(this.#debuggerEle.style, {\n position: 'fixed',\n top: '0',\n right: '0',\n height: '100vh',\n width: '100vw',\n pointerEvents: 'none',\n zIndex: 99999,\n });\n\n // we are importing the debugger dynamically so we won't load it when it's not needed\n await import('./debugger-wc');\n\n document.body.appendChild(this.#debuggerEle);\n }\n\n attributeChangedCallback = (\n attrName: string,\n oldValue: string | null,\n newValue: string | null,\n ) => {\n super.attributeChangedCallback?.(attrName, oldValue, newValue);\n\n if (attrName === 'debug') {\n this.#handleDebugMode();\n }\n };\n\n get debug() {\n return this.getAttribute('debug') === 'true';\n }\n\n #handleDebugMode() {\n if (this.debug) this.#enableDebugger();\n else this.#disableDebugger();\n }\n\n onLogEvent(logLevel: LogLevel, args: any[]) {\n super.onLogEvent?.(logLevel, args);\n if (logLevel === 'error') {\n this.#updateDebuggerMessages(args[0] || 'Error', args[1]);\n }\n }\n\n async init() {\n await super.init?.();\n\n this.#handleDebugMode();\n }\n\n #updateDebuggerMessages(title: string, description: string) {\n if (title) this.#debuggerEle?.updateData({ title, description });\n }\n },\n);\n"],"names":[],"mappings":";;;;;MAKa,aAAa,GAAG,oBAAoB,CAC/C,CAAqC,UAAa,KAAI,EAAA,IAAA,6BAAA,EAAA,+BAAA,EAAA,mCAAA,EAAA,kCAAA,EAAA,mCAAA,EAAA,0CAAA,EAAA,EAAA,CAAA,CAAA,OAAA,EAAA,GACpD,MAAM,kBAAmB,SAAQ,OAAO,CACtC,kBAAkB,EAClB,WAAW,CACZ,CAAC,UAAU,CAAC,CAAA;AAHb,QAAA,WAAA,GAAA;;;YAIE,+BAIS,CAAA,GAAA,CAAA,IAAA,EAAA,KAAA,CAAA,CAAA,CAAA;YA8BT,IAAwB,CAAA,wBAAA,GAAG,CACzB,QAAgB,EAChB,QAAuB,EACvB,QAAuB,KACrB;;gBACF,CAAA,EAAA,GAAA,KAAK,CAAC,wBAAwB,MAAG,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,IAAA,CAAA,IAAA,EAAA,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAE/D,gBAAA,IAAI,QAAQ,KAAK,OAAO,EAAE;AACxB,oBAAA,sBAAA,CAAA,IAAI,EAAA,6BAAA,EAAA,GAAA,EAAA,mCAAA,CAAiB,CAArB,IAAA,CAAA,IAAI,CAAmB,CAAC;iBACzB;AACH,aAAC,CAAC;SA2BH;AAzBC,QAAA,IAAI,KAAK,GAAA;YACP,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,KAAK,MAAM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AA,CAAA,IAAI,EAAa,+BAAA,EAAA,GAAA,CAAA,CAAC,KAAK,EAAE;AACrC,YAAA,QAAQ,EAAE,OAAO;AACjB,YAAA,GAAG,EAAE,GAAG;AACR,YAAA,KAAK,EAAE,GAAG;AACV,YAAA,MAAM,EAAE,OAAO;AACf,YAAA,KAAK,EAAE,OAAO;AACd,YAAA,aAAa,EAAE,MAAM;AACrB,YAAA,MAAM,EAAE,KAAK;AACd,SAAA,CAAC,CAAC;;AAGH,QAAA,MAAM,OAAO,kBAAe,CAAC,CAAC;QAE9B,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,sBAAA,CAAA,IAAI,EAAa,+BAAA,EAAA,GAAA,CAAA,CAAC,CAAC;KAC9C;;QAmBC,IAAI,IAAI,CAAC,KAAK;AAAE,YAAA,sBAAA,CAAA,IAAI,EAAA,6BAAA,EAAA,GAAA,EAAA,kCAAA,CAAgB,CAApB,IAAA,CAAA,IAAI,CAAkB,CAAC;;AAClC,YAAA,sBAAA,CAAA,IAAI,EAAA,6BAAA,EAAA,GAAA,EAAA,mCAAA,CAAiB,CAArB,IAAA,CAAA,IAAI,CAAmB,CAAC;KAC9B;AAeuB,IAAA,0CAAA,GAAA,SAAA,0CAAA,CAAA,KAAa,EAAE,WAAmB,EAAA;;AACxD,QAAA,IAAI,KAAK;AAAE,YAAA,CAAA,EAAA,GAAA,sBAAA,CAAA,IAAI,EAAa,+BAAA,EAAA,GAAA,CAAA,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAE,UAAU,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC;KAClE;AACF,IAAA,EAAA,CAAA,EAAA;;;;"}
@@ -0,0 +1,72 @@
1
+ const limitCoordinateToScreenBoundaries = (ele, x, y, boundaries = {}) => {
2
+ var _a, _b, _c, _d;
3
+ return [
4
+ Math.min(Math.max(x, (boundaries.left === 'all' ? ele.offsetWidth : (_a = boundaries.left) !== null && _a !== void 0 ? _a : 0) -
5
+ ele.offsetWidth), window.innerWidth -
6
+ (boundaries.right === 'all' ? ele.offsetWidth : (_b = boundaries.right) !== null && _b !== void 0 ? _b : 0)),
7
+ Math.min(Math.max(y, (boundaries.top === 'all' ? ele.offsetHeight : (_c = boundaries.top) !== null && _c !== void 0 ? _c : 0) -
8
+ ele.offsetHeight), window.innerHeight -
9
+ (boundaries.bottom === 'all' ? ele.offsetHeight : (_d = boundaries.bottom) !== null && _d !== void 0 ? _d : 0)),
10
+ ];
11
+ };
12
+ const dragElement = (ele, triggerEle, keepVisible) => {
13
+ let deltaX = 0;
14
+ let deltaY = 0;
15
+ let currentX = 0;
16
+ let currentY = 0;
17
+ function elementDrag(e) {
18
+ e.preventDefault();
19
+ // calculate the new cursor position:
20
+ deltaX = currentX - e.clientX;
21
+ deltaY = currentY - e.clientY;
22
+ currentX = e.clientX;
23
+ currentY = e.clientY;
24
+ // set the element's new position:
25
+ const [left, top] = limitCoordinateToScreenBoundaries(ele, ele.offsetLeft - deltaX, ele.offsetTop - deltaY, keepVisible);
26
+ // eslint-disable-next-line no-param-reassign
27
+ ele.style.top = `${top}px`;
28
+ // eslint-disable-next-line no-param-reassign
29
+ ele.style.left = `${left}px`;
30
+ }
31
+ function closeDragElement() {
32
+ // stop moving when mouse button is released:
33
+ document.onmouseup = null;
34
+ document.onmousemove = null;
35
+ }
36
+ function dragMouseDown(e) {
37
+ e.preventDefault();
38
+ // get the mouse cursor position at startup:
39
+ currentX = e.clientX;
40
+ currentY = e.clientY;
41
+ document.onmouseup = closeDragElement;
42
+ // call a function whenever the cursor moves:
43
+ document.onmousemove = elementDrag;
44
+ }
45
+ if (triggerEle) {
46
+ // if provided, the triggerEle is where you move the div from
47
+ // eslint-disable-next-line no-param-reassign
48
+ triggerEle.onmousedown = dragMouseDown;
49
+ }
50
+ else {
51
+ // otherwise, move the DIV from anywhere inside the DIV:
52
+ // eslint-disable-next-line no-param-reassign
53
+ ele.onmousedown = dragMouseDown;
54
+ }
55
+ };
56
+ const addOnResize = (ele) => {
57
+ // eslint-disable-next-line no-param-reassign
58
+ ele.onmousemove = (e) => {
59
+ var _a;
60
+ // eslint-disable-next-line prefer-destructuring
61
+ const target = e.target;
62
+ if ((target.w && target.w !== target.offsetWidth) ||
63
+ (target.h && target.h !== target.offsetHeight)) {
64
+ (_a = ele.onresize) === null || _a === void 0 ? void 0 : _a.call(ele, e);
65
+ }
66
+ target.w = target.offsetWidth;
67
+ target.h = target.offsetHeight;
68
+ };
69
+ };
70
+
71
+ export { addOnResize, dragElement, limitCoordinateToScreenBoundaries };
72
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sources":["../../../../src/mixins/debuggerMixin/helpers.ts"],"sourcesContent":["import { Boundaries } from './types';\n\ntype Target = {\n w: number;\n h: number;\n offsetWidth: number;\n offsetHeight: number;\n};\n\nexport const limitCoordinateToScreenBoundaries = (\n ele: HTMLElement,\n x: number,\n y: number,\n boundaries: Boundaries = {},\n) => [\n Math.min(\n Math.max(\n x,\n (boundaries.left === 'all' ? ele.offsetWidth : boundaries.left ?? 0) -\n ele.offsetWidth,\n ),\n window.innerWidth -\n (boundaries.right === 'all' ? ele.offsetWidth : boundaries.right ?? 0),\n ),\n Math.min(\n Math.max(\n y,\n (boundaries.top === 'all' ? ele.offsetHeight : boundaries.top ?? 0) -\n ele.offsetHeight,\n ),\n window.innerHeight -\n (boundaries.bottom === 'all' ? ele.offsetHeight : boundaries.bottom ?? 0),\n ),\n];\n\nexport const dragElement = (\n ele: HTMLElement,\n triggerEle?: HTMLElement,\n keepVisible?: Boundaries,\n) => {\n let deltaX = 0;\n let deltaY = 0;\n let currentX = 0;\n let currentY = 0;\n\n function elementDrag(e: MouseEvent) {\n e.preventDefault();\n // calculate the new cursor position:\n deltaX = currentX - e.clientX;\n deltaY = currentY - e.clientY;\n currentX = e.clientX;\n currentY = e.clientY;\n // set the element's new position:\n const [left, top] = limitCoordinateToScreenBoundaries(\n ele,\n ele.offsetLeft - deltaX,\n ele.offsetTop - deltaY,\n keepVisible,\n );\n // eslint-disable-next-line no-param-reassign\n ele.style.top = `${top}px`;\n // eslint-disable-next-line no-param-reassign\n ele.style.left = `${left}px`;\n }\n\n function closeDragElement() {\n // stop moving when mouse button is released:\n document.onmouseup = null;\n document.onmousemove = null;\n }\n\n function dragMouseDown(e: MouseEvent) {\n e.preventDefault();\n // get the mouse cursor position at startup:\n currentX = e.clientX;\n currentY = e.clientY;\n document.onmouseup = closeDragElement;\n // call a function whenever the cursor moves:\n document.onmousemove = elementDrag;\n }\n\n if (triggerEle) {\n // if provided, the triggerEle is where you move the div from\n // eslint-disable-next-line no-param-reassign\n triggerEle.onmousedown = dragMouseDown;\n } else {\n // otherwise, move the DIV from anywhere inside the DIV:\n\n // eslint-disable-next-line no-param-reassign\n ele.onmousedown = dragMouseDown;\n }\n};\n\nexport const addOnResize = (ele: HTMLElement) => {\n // eslint-disable-next-line no-param-reassign\n ele.onmousemove = (e) => {\n // eslint-disable-next-line prefer-destructuring\n const target: Target = e.target! as EventTarget & Target;\n if (\n (target.w && target.w !== target.offsetWidth) ||\n (target.h && target.h !== target.offsetHeight)\n ) {\n ele.onresize?.(e);\n }\n target.w = target.offsetWidth;\n target.h = target.offsetHeight;\n };\n};\n"],"names":[],"mappings":"AASO,MAAM,iCAAiC,GAAG,CAC/C,GAAgB,EAChB,CAAS,EACT,CAAS,EACT,UAAyB,GAAA,EAAE,KACzB;;IAAC,OAAA;AACH,QAAA,IAAI,CAAC,GAAG,CACN,IAAI,CAAC,GAAG,CACN,CAAC,EACD,CAAC,UAAU,CAAC,IAAI,KAAK,KAAK,GAAG,GAAG,CAAC,WAAW,GAAG,CAAA,EAAA,GAAA,UAAU,CAAC,IAAI,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAAA,GAAI,CAAC;AACjE,YAAA,GAAG,CAAC,WAAW,CAClB,EACD,MAAM,CAAC,UAA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AAQ,MAAG,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,IAAA,CAAA,GAAA,EAAA,CAAC,CAAC,CAAC;SACnB;AACD,QAAA,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC;AAC9B,QAAA,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,YAAY,CAAC;AACjC,KAAC,CAAC;AACJ;;;;"}
@@ -0,0 +1,16 @@
1
+ import { IS_LOCAL_STORAGE } from '../../constants.js';
2
+
3
+ const DESCOPE_UI_SCRIPT_ID = 'load-descope-ui';
4
+ const DESCOPE_UI_FALLBACK_SCRIPT_ID = 'load-descope-ui-fallback-script';
5
+ const DESCOPE_UI_FALLBACK_2_SCRIPT_ID = 'load-descope-ui-fallback-script-2';
6
+ const UI_COMPONENTS_URL_KEY = 'base.ui.components.url';
7
+ const UI_COMPONENTS_URL = (IS_LOCAL_STORAGE && localStorage.getItem(UI_COMPONENTS_URL_KEY)) ||
8
+ 'https://descopecdn.com/npm/@descope/web-components-ui@<version>/dist/umd/index.js';
9
+ const UI_COMPONENTS_FALLBACK_URL = (IS_LOCAL_STORAGE && localStorage.getItem(UI_COMPONENTS_URL_KEY)) ||
10
+ 'https://static.descope.com/npm/@descope/web-components-ui@<version>/dist/umd/index.js';
11
+ const UI_COMPONENTS_FALLBACK_2_URL = (IS_LOCAL_STORAGE && localStorage.getItem(UI_COMPONENTS_URL_KEY)) ||
12
+ 'https://cdn.jsdelivr.net/npm/@descope/web-components-ui@<version>/dist/umd/index.js';
13
+ const UI_COMPONENTS_URL_VERSION_PLACEHOLDER = '<version>';
14
+
15
+ export { DESCOPE_UI_FALLBACK_2_SCRIPT_ID, DESCOPE_UI_FALLBACK_SCRIPT_ID, DESCOPE_UI_SCRIPT_ID, UI_COMPONENTS_FALLBACK_2_URL, UI_COMPONENTS_FALLBACK_URL, UI_COMPONENTS_URL, UI_COMPONENTS_URL_KEY, UI_COMPONENTS_URL_VERSION_PLACEHOLDER };
16
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sources":["../../../../src/mixins/descopeUiMixin/constants.ts"],"sourcesContent":["import { IS_LOCAL_STORAGE } from '../../constants';\n\nexport const DESCOPE_UI_SCRIPT_ID = 'load-descope-ui';\nexport const DESCOPE_UI_FALLBACK_SCRIPT_ID = 'load-descope-ui-fallback-script';\nexport const DESCOPE_UI_FALLBACK_2_SCRIPT_ID =\n 'load-descope-ui-fallback-script-2';\n\nexport const UI_COMPONENTS_URL_KEY = 'base.ui.components.url';\n\nexport const UI_COMPONENTS_URL =\n (IS_LOCAL_STORAGE && localStorage.getItem(UI_COMPONENTS_URL_KEY)) ||\n 'https://descopecdn.com/npm/@descope/web-components-ui@<version>/dist/umd/index.js';\n\nexport const UI_COMPONENTS_FALLBACK_URL =\n (IS_LOCAL_STORAGE && localStorage.getItem(UI_COMPONENTS_URL_KEY)) ||\n 'https://static.descope.com/npm/@descope/web-components-ui@<version>/dist/umd/index.js';\n\nexport const UI_COMPONENTS_FALLBACK_2_URL =\n (IS_LOCAL_STORAGE && localStorage.getItem(UI_COMPONENTS_URL_KEY)) ||\n 'https://cdn.jsdelivr.net/npm/@descope/web-components-ui@<version>/dist/umd/index.js';\n\nexport const UI_COMPONENTS_URL_VERSION_PLACEHOLDER = '<version>';\n"],"names":[],"mappings":";;AAEO,MAAM,oBAAoB,GAAG,kBAAkB;AAC/C,MAAM,6BAA6B,GAAG,kCAAkC;AACxE,MAAM,+BAA+B,GAC1C,oCAAoC;AAE/B,MAAM,qBAAqB,GAAG,yBAAyB;AAEvD,MAAM,iBAAiB,GAC5B,CAAC,gBAAgB,IAAI,YAAY,CAAC,OAAO,CAAC,qBAAqB,CAAC;AAChE,IAAA,oFAAoF;AAE/E,MAAM,0BAA0B,GACrC,CAAC,gBAAgB,IAAI,YAAY,CAAC,OAAO,CAAC,qBAAqB,CAAC;AAChE,IAAA,wFAAwF;AAEnF,MAAM,4BAA4B,GACvC,CAAC,gBAAgB,IAAI,YAAY,CAAC,OAAO,CAAC,qBAAqB,CAAC;AAChE,IAAA,sFAAsF;AAEjF,MAAM,qCAAqC,GAAG;;;;"}
@@ -0,0 +1,166 @@
1
+ import { __classPrivateFieldGet, __classPrivateFieldSet } from 'tslib';
2
+ import { createSingletonMixin, compose } from '@descope/sdk-helpers';
3
+ import { configMixin } from '../configMixin/configMixin.js';
4
+ import { loggerMixin } from '../loggerMixin/loggerMixin.js';
5
+ import { DESCOPE_UI_SCRIPT_ID, UI_COMPONENTS_URL, DESCOPE_UI_FALLBACK_2_SCRIPT_ID, UI_COMPONENTS_FALLBACK_2_URL, DESCOPE_UI_FALLBACK_SCRIPT_ID, UI_COMPONENTS_FALLBACK_URL } from './constants.js';
6
+ import { getDescopeUiComponentsList, setupScript, generateScriptUrl } from './helpers.js';
7
+
8
+ const descopeUiMixin = createSingletonMixin((superclass) => {
9
+ var _DescopeUiMixinClass_instances, _DescopeUiMixinClass_errorCbsSym, _DescopeUiMixinClass_loadCbsSym, _DescopeUiMixinClass_getComponentsVersion, _DescopeUiMixinClass_exposeAlternateEvents, _DescopeUiMixinClass_handleFallbackScript, _DescopeUiMixinClass_registerEvents, _DescopeUiMixinClass_getDescopeUiLoadingScript, _DescopeUiMixinClass_descopeUi, _DescopeUiMixinClass_loadDescopeUiComponent, _DescopeUiMixinClass_getDescopeUi, _a;
10
+ const BaseClass = compose(loggerMixin, configMixin)(superclass);
11
+ return _a = class DescopeUiMixinClass extends BaseClass {
12
+ constructor() {
13
+ super(...arguments);
14
+ _DescopeUiMixinClass_instances.add(this);
15
+ _DescopeUiMixinClass_errorCbsSym.set(this, Symbol('errorCbs'));
16
+ _DescopeUiMixinClass_loadCbsSym.set(this, Symbol('loadCbs'));
17
+ _DescopeUiMixinClass_descopeUi.set(this, void 0);
18
+ }
19
+ get descopeUi() {
20
+ if (!__classPrivateFieldGet(this, _DescopeUiMixinClass_descopeUi, "f")) {
21
+ __classPrivateFieldSet(this, _DescopeUiMixinClass_descopeUi, __classPrivateFieldGet(this, _DescopeUiMixinClass_instances, "m", _DescopeUiMixinClass_getDescopeUi).call(this), "f");
22
+ }
23
+ return __classPrivateFieldGet(this, _DescopeUiMixinClass_descopeUi, "f");
24
+ }
25
+ async loadDescopeUiComponents(templateOrComponentNames) {
26
+ const descopeUiComponentsList = Array.isArray(templateOrComponentNames)
27
+ ? templateOrComponentNames
28
+ : getDescopeUiComponentsList(templateOrComponentNames);
29
+ return Promise.all(descopeUiComponentsList.map((componentName) => __classPrivateFieldGet(this, _DescopeUiMixinClass_instances, "m", _DescopeUiMixinClass_loadDescopeUiComponent).call(this, componentName)));
30
+ }
31
+ get baseCdnUrl() {
32
+ return this.getAttribute('base-cdn-url');
33
+ }
34
+ },
35
+ _DescopeUiMixinClass_errorCbsSym = new WeakMap(),
36
+ _DescopeUiMixinClass_loadCbsSym = new WeakMap(),
37
+ _DescopeUiMixinClass_descopeUi = new WeakMap(),
38
+ _DescopeUiMixinClass_instances = new WeakSet(),
39
+ _DescopeUiMixinClass_getComponentsVersion =
40
+ // eslint-disable-next-line class-methods-use-this
41
+ async function _DescopeUiMixinClass_getComponentsVersion() {
42
+ var _b;
43
+ const config = await this.config;
44
+ const componentsVersion = (_b = config === null || config === void 0 ? void 0 : config.projectConfig) === null || _b === void 0 ? void 0 : _b.componentsVersion;
45
+ if (!componentsVersion) {
46
+ this.logger.error('Could not get components version');
47
+ }
48
+ else {
49
+ this.logger.debug(`Got component version "${componentsVersion}"`);
50
+ }
51
+ return componentsVersion;
52
+ },
53
+ _DescopeUiMixinClass_exposeAlternateEvents = function _DescopeUiMixinClass_exposeAlternateEvents(scriptEle) {
54
+ const errorCbsSym = __classPrivateFieldGet(this, _DescopeUiMixinClass_errorCbsSym, "f");
55
+ const loadCbsSym = __classPrivateFieldGet(this, _DescopeUiMixinClass_loadCbsSym, "f");
56
+ // eslint-disable-next-line no-param-reassign
57
+ scriptEle[errorCbsSym] = [];
58
+ // eslint-disable-next-line no-param-reassign
59
+ scriptEle[loadCbsSym] = [];
60
+ Object.defineProperty(scriptEle, 'onerror', {
61
+ set(cb) {
62
+ scriptEle[errorCbsSym].push(cb);
63
+ },
64
+ });
65
+ Object.defineProperty(scriptEle, 'onload', {
66
+ set(cb) {
67
+ scriptEle[loadCbsSym].push(cb);
68
+ },
69
+ });
70
+ },
71
+ _DescopeUiMixinClass_handleFallbackScript = async function _DescopeUiMixinClass_handleFallbackScript(errorCbs, loadCbs, elemId, scriptUrl) {
72
+ this.logger.debug('Trying to load DescopeUI from a fallback URL');
73
+ const fallbackScriptEle = setupScript(elemId);
74
+ document.body.append(fallbackScriptEle);
75
+ fallbackScriptEle.addEventListener('error', () => {
76
+ errorCbs.forEach((cb) => cb(`Cannot load DescopeUI from fallback URL, Make sure this URL is valid and return the correct script: "${fallbackScriptEle.src}"`));
77
+ });
78
+ fallbackScriptEle.addEventListener('load', () => {
79
+ loadCbs.forEach((cb) => cb());
80
+ });
81
+ fallbackScriptEle.src = generateScriptUrl(scriptUrl, await __classPrivateFieldGet(this, _DescopeUiMixinClass_instances, "m", _DescopeUiMixinClass_getComponentsVersion).call(this));
82
+ },
83
+ _DescopeUiMixinClass_registerEvents = function _DescopeUiMixinClass_registerEvents(scriptEle) {
84
+ scriptEle.addEventListener('error', () => {
85
+ scriptEle[__classPrivateFieldGet(this, _DescopeUiMixinClass_errorCbsSym, "f")].forEach((cb) => cb(`Cannot load DescopeUI from main URL, Make sure this URL is valid and return the correct script: "${scriptEle.src}"`));
86
+ // in case we could not load DescopeUI from the main URL, we are trying to load it from a fallback URL
87
+ __classPrivateFieldGet(this, _DescopeUiMixinClass_instances, "m", _DescopeUiMixinClass_handleFallbackScript).call(this, [
88
+ // we are adding a second fallback
89
+ __classPrivateFieldGet(this, _DescopeUiMixinClass_instances, "m", _DescopeUiMixinClass_handleFallbackScript).bind(this, scriptEle[__classPrivateFieldGet(this, _DescopeUiMixinClass_errorCbsSym, "f")], scriptEle[__classPrivateFieldGet(this, _DescopeUiMixinClass_loadCbsSym, "f")], DESCOPE_UI_FALLBACK_2_SCRIPT_ID, UI_COMPONENTS_FALLBACK_2_URL),
90
+ ...scriptEle[__classPrivateFieldGet(this, _DescopeUiMixinClass_errorCbsSym, "f")],
91
+ ], scriptEle[__classPrivateFieldGet(this, _DescopeUiMixinClass_loadCbsSym, "f")], DESCOPE_UI_FALLBACK_SCRIPT_ID, UI_COMPONENTS_FALLBACK_URL);
92
+ });
93
+ scriptEle.addEventListener('load', () => {
94
+ scriptEle[__classPrivateFieldGet(this, _DescopeUiMixinClass_loadCbsSym, "f")].forEach((cb) => cb());
95
+ });
96
+ },
97
+ _DescopeUiMixinClass_getDescopeUiLoadingScript = async function _DescopeUiMixinClass_getDescopeUiLoadingScript() {
98
+ if (!document.querySelector(`script#${DESCOPE_UI_SCRIPT_ID}`)) {
99
+ this.logger.debug('DescopeUI loading script does not exist, creating it', this);
100
+ const scriptEle = setupScript(DESCOPE_UI_SCRIPT_ID);
101
+ document.body.append(scriptEle);
102
+ __classPrivateFieldGet(this, _DescopeUiMixinClass_instances, "m", _DescopeUiMixinClass_exposeAlternateEvents).call(this, scriptEle);
103
+ __classPrivateFieldGet(this, _DescopeUiMixinClass_instances, "m", _DescopeUiMixinClass_registerEvents).call(this, scriptEle);
104
+ scriptEle.src = generateScriptUrl(this.baseCdnUrl || UI_COMPONENTS_URL, await __classPrivateFieldGet(this, _DescopeUiMixinClass_instances, "m", _DescopeUiMixinClass_getComponentsVersion).call(this));
105
+ }
106
+ else {
107
+ this.logger.debug('DescopeUI loading script already exists', this);
108
+ }
109
+ return document.getElementById(DESCOPE_UI_SCRIPT_ID);
110
+ },
111
+ _DescopeUiMixinClass_loadDescopeUiComponent = async function _DescopeUiMixinClass_loadDescopeUiComponent(componentName) {
112
+ const isComponentAlreadyDefined = !!customElements.get(componentName);
113
+ if (isComponentAlreadyDefined) {
114
+ this.logger.debug(`Loading component "${componentName}" is skipped as it is already defined`);
115
+ return undefined;
116
+ }
117
+ const descopeUI = await this.descopeUi;
118
+ if (!descopeUI[componentName]) {
119
+ this.logger.error(`Cannot load UI component "${componentName}"`, `Descope UI does not have a component named "${componentName}", available components are: "${Object.keys(descopeUI).join(', ')}"`);
120
+ return undefined;
121
+ }
122
+ try {
123
+ // eslint-disable-next-line @typescript-eslint/return-await
124
+ return await descopeUI[componentName]();
125
+ }
126
+ catch (e) {
127
+ // this error is thrown when trying to register a component which is already registered
128
+ // when running 2 flows on the same page, it might happen that the register fn is called twice
129
+ // in case it happens, we are silently ignore the error
130
+ if (e.name === 'NotSupportedError') {
131
+ // eslint-disable-next-line no-console
132
+ console.debug(`Encountered an error while attempting to define the "${componentName}" component, it is likely that this component is already defined`);
133
+ }
134
+ else {
135
+ throw e;
136
+ }
137
+ }
138
+ return undefined;
139
+ },
140
+ _DescopeUiMixinClass_getDescopeUi = function _DescopeUiMixinClass_getDescopeUi() {
141
+ return new Promise((res) => {
142
+ if (globalThis.DescopeUI) {
143
+ res(globalThis.DescopeUI);
144
+ }
145
+ __classPrivateFieldGet(this, _DescopeUiMixinClass_instances, "m", _DescopeUiMixinClass_getDescopeUiLoadingScript).call(this).then((scriptEle) => {
146
+ // eslint-disable-next-line no-param-reassign
147
+ scriptEle.onerror = this.logger.error;
148
+ // eslint-disable-next-line no-param-reassign
149
+ scriptEle.onload = () => {
150
+ this.logger.debug('DescopeUI was loaded');
151
+ res(globalThis.DescopeUI);
152
+ };
153
+ // in case the load event was dispatched before we registered, we have a fallback
154
+ setTimeout(() => {
155
+ if (globalThis.DescopeUI) {
156
+ res(globalThis.DescopeUI);
157
+ }
158
+ });
159
+ });
160
+ });
161
+ },
162
+ _a;
163
+ });
164
+
165
+ export { descopeUiMixin };
166
+ //# sourceMappingURL=descopeUiMixin.js.map