@weavy/uikit-react 12.1.0 → 14.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 (280) hide show
  1. package/changelog.md +60 -0
  2. package/dist/cjs/index.js +28 -6
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/types/client/WeavyClient.d.ts +8 -1
  5. package/dist/cjs/types/components/Attachment.d.ts +2 -1
  6. package/dist/cjs/types/components/Chat.d.ts +1 -1
  7. package/dist/cjs/types/components/Messages.d.ts +3 -1
  8. package/dist/cjs/types/components/PdfViewer.d.ts +3 -1
  9. package/dist/cjs/types/components/Preview.d.ts +8 -10
  10. package/dist/cjs/types/contexts/PreviewContext.d.ts +2 -1
  11. package/dist/cjs/types/contexts/WeavyContext.d.ts +2 -3
  12. package/dist/cjs/types/hooks/useConversations.d.ts +1 -1
  13. package/dist/cjs/types/hooks/useMutateMessage.d.ts +1 -1
  14. package/dist/cjs/types/hooks/useMutateRead.d.ts +1 -0
  15. package/dist/cjs/types/types/Chat.d.ts +2 -1
  16. package/dist/cjs/types/types/Message.d.ts +2 -0
  17. package/dist/cjs/types/types/types.d.ts +63 -9
  18. package/dist/cjs/types/ui/Spinner.d.ts +10 -0
  19. package/dist/cjs/types/utils/fileUtilities.d.ts +1 -4
  20. package/dist/css/weavy-chat.css +1803 -1041
  21. package/dist/css/weavy-messenger.css +2141 -1360
  22. package/dist/css/weavy.css +1943 -1162
  23. package/dist/esm/index.js +28 -6
  24. package/dist/esm/index.js.map +1 -1
  25. package/dist/esm/types/client/WeavyClient.d.ts +8 -1
  26. package/dist/esm/types/components/Attachment.d.ts +2 -1
  27. package/dist/esm/types/components/Chat.d.ts +1 -1
  28. package/dist/esm/types/components/Messages.d.ts +3 -1
  29. package/dist/esm/types/components/PdfViewer.d.ts +3 -1
  30. package/dist/esm/types/components/Preview.d.ts +8 -10
  31. package/dist/esm/types/contexts/PreviewContext.d.ts +2 -1
  32. package/dist/esm/types/contexts/WeavyContext.d.ts +2 -3
  33. package/dist/esm/types/hooks/useConversations.d.ts +1 -1
  34. package/dist/esm/types/hooks/useMutateMessage.d.ts +1 -1
  35. package/dist/esm/types/hooks/useMutateRead.d.ts +1 -0
  36. package/dist/esm/types/types/Chat.d.ts +2 -1
  37. package/dist/esm/types/types/Message.d.ts +2 -0
  38. package/dist/esm/types/types/types.d.ts +63 -9
  39. package/dist/esm/types/ui/Spinner.d.ts +10 -0
  40. package/dist/esm/types/utils/fileUtilities.d.ts +1 -4
  41. package/dist/index.d.ts +15 -7
  42. package/package.json +2 -2
  43. package/rollup.config.js +3 -1
  44. package/src/client/WeavyClient.ts +105 -29
  45. package/src/components/Attachment.tsx +8 -7
  46. package/src/components/Chat.tsx +8 -7
  47. package/src/components/Conversation.tsx +29 -23
  48. package/src/components/ConversationBadge.tsx +7 -5
  49. package/src/components/ConversationForm.tsx +1 -1
  50. package/src/components/ConversationList.tsx +59 -11
  51. package/src/components/ConversationListItem.tsx +71 -54
  52. package/src/components/FileBrowser.tsx +53 -50
  53. package/src/components/MeetingCard.tsx +35 -13
  54. package/src/components/Meetings.tsx +1 -1
  55. package/src/components/Message.tsx +41 -41
  56. package/src/components/Messages.tsx +62 -61
  57. package/src/components/Messenger.tsx +7 -2
  58. package/src/components/NewConversation.tsx +1 -1
  59. package/src/components/PdfViewer.tsx +93 -88
  60. package/src/components/Preview.tsx +115 -54
  61. package/src/components/Reactions.tsx +11 -5
  62. package/src/components/SearchUsers.tsx +21 -11
  63. package/src/components/SeenBy.tsx +13 -7
  64. package/src/components/Typing.tsx +11 -12
  65. package/src/contexts/PreviewContext.tsx +90 -16
  66. package/src/contexts/UserContext.tsx +1 -1
  67. package/src/contexts/WeavyContext.tsx +10 -7
  68. package/src/hooks/useBadge.ts +2 -6
  69. package/src/hooks/useChat.ts +3 -14
  70. package/src/hooks/useConversation.ts +1 -7
  71. package/src/hooks/useConversations.ts +15 -11
  72. package/src/hooks/useFileUploader.ts +6 -8
  73. package/src/hooks/useMembers.ts +1 -7
  74. package/src/hooks/useMessages.ts +1 -7
  75. package/src/hooks/useMutateChat.ts +6 -11
  76. package/src/hooks/useMutateConversation.ts +7 -10
  77. package/src/hooks/useMutateConversationName.ts +10 -12
  78. package/src/hooks/useMutateDeleteReaction.ts +3 -8
  79. package/src/hooks/useMutateExternalBlobs.ts +6 -11
  80. package/src/hooks/useMutateMeeting.ts +6 -11
  81. package/src/hooks/useMutateMembers.ts +8 -13
  82. package/src/hooks/useMutateMessage.ts +9 -18
  83. package/src/hooks/useMutatePinned.ts +3 -8
  84. package/src/hooks/useMutateReaction.ts +6 -12
  85. package/src/hooks/useMutateRead.ts +5 -12
  86. package/src/hooks/useMutateRemoveMembers.ts +7 -12
  87. package/src/hooks/useMutateTyping.ts +6 -11
  88. package/src/hooks/usePresence.ts +2 -3
  89. package/src/hooks/useReactions.ts +11 -12
  90. package/src/hooks/useSearchUsers.ts +1 -6
  91. package/src/hooks/useUser.ts +3 -14
  92. package/src/scss/theme/_alert.scss +61 -63
  93. package/src/scss/theme/_appbar.scss +105 -28
  94. package/src/scss/theme/_avatar.scss +23 -28
  95. package/src/scss/theme/_badge.scss +26 -18
  96. package/src/scss/theme/_buttons.scss +107 -52
  97. package/src/scss/theme/_card.scss +102 -4
  98. package/src/scss/theme/_checkbox.scss +16 -20
  99. package/src/scss/theme/_code-vscode-dark.scss +184 -0
  100. package/src/scss/theme/_code-vscode-light.scss +179 -0
  101. package/src/scss/theme/_code.scss +9 -114
  102. package/src/scss/theme/_comment-editor-cm.scss +97 -0
  103. package/src/scss/theme/_comment-editor.scss +129 -0
  104. package/src/scss/theme/_comments.scss +66 -0
  105. package/src/scss/theme/_content.scss +33 -5
  106. package/src/scss/theme/_conversations.scss +19 -78
  107. package/src/scss/theme/_dropdown.scss +102 -15
  108. package/src/scss/theme/_embed.scss +135 -0
  109. package/src/scss/theme/_facepile.scss +11 -0
  110. package/src/scss/theme/_filebrowser.scss +1 -1
  111. package/src/scss/theme/_files.scss +77 -48
  112. package/src/scss/theme/_grid.scss +8 -0
  113. package/src/scss/theme/_icons.scss +155 -19
  114. package/src/scss/theme/_image-grid.scss +7 -10
  115. package/src/scss/theme/_input.scss +160 -0
  116. package/src/scss/theme/_item.scss +169 -0
  117. package/src/scss/theme/_list.scss +57 -0
  118. package/src/scss/theme/_meeting.scss +11 -0
  119. package/src/scss/theme/_message-editor-cm.scss +95 -0
  120. package/src/scss/theme/_message-editor.scss +66 -20
  121. package/src/scss/theme/_messages.scss +51 -105
  122. package/src/scss/theme/_meta.scss +12 -0
  123. package/src/scss/theme/_overlays.scss +31 -76
  124. package/src/scss/theme/_pager.scss +5 -1
  125. package/src/scss/theme/_pane.scss +13 -2
  126. package/src/scss/theme/_panels.scss +34 -25
  127. package/src/scss/theme/_picker-list.scss +5 -3
  128. package/src/scss/theme/_placeholder.scss +19 -0
  129. package/src/scss/theme/_poll.scss +49 -0
  130. package/src/scss/theme/_post-editor-cm.scss +100 -0
  131. package/src/scss/theme/_post-editor.scss +127 -0
  132. package/src/scss/theme/_post.scss +83 -0
  133. package/src/scss/theme/_preview-code.scss +14 -0
  134. package/src/scss/theme/_preview-embed.scss +11 -5
  135. package/src/scss/theme/_preview-image.scss +8 -26
  136. package/src/scss/theme/_preview-media.scss +1 -0
  137. package/src/scss/theme/_preview-pdf.scss +10 -15
  138. package/src/scss/theme/_preview-text.scss +1 -1
  139. package/src/scss/theme/_preview.scss +59 -76
  140. package/src/scss/theme/_reactions.scss +48 -17
  141. package/src/scss/theme/_sheet.scss +59 -0
  142. package/src/scss/theme/_sidebar.scss +86 -0
  143. package/src/scss/theme/_spinner.scss +11 -7
  144. package/src/scss/theme/_tab.scss +72 -0
  145. package/src/scss/theme/_tables.scss +70 -23
  146. package/src/scss/theme/_toasts.scss +56 -26
  147. package/src/scss/theme/_type.scss +41 -0
  148. package/src/scss/theme/{mixins → base}/_backdrop.scss +0 -0
  149. package/src/scss/theme/{bootstrap/mixins → base}/_breakpoints.scss +9 -0
  150. package/src/scss/theme/base/_colors.scss +315 -0
  151. package/src/scss/theme/base/_md.scss +19 -0
  152. package/src/scss/theme/base/_palette.scss +130 -0
  153. package/src/scss/theme/{mixins → base}/_position.scss +5 -5
  154. package/src/scss/theme/base/_reboot.scss +51 -0
  155. package/src/scss/theme/base/_scroll.scss +180 -0
  156. package/src/scss/theme/base/_svg.scss +49 -0
  157. package/src/scss/theme/base/_text.scss +23 -0
  158. package/src/scss/theme/base/_vars.scss +203 -0
  159. package/src/scss/theme/{fonts → base/fonts}/_fontmapping-roboto.scss +0 -0
  160. package/src/scss/theme/{fonts → base/fonts}/_fontmapping-segoe-ui.scss +0 -0
  161. package/src/scss/theme/base/fonts/_index.scss +2 -0
  162. package/src/scss/weavy-chat.scss +11 -4
  163. package/src/scss/weavy-messenger.scss +38 -21
  164. package/src/types/Chat.ts +2 -1
  165. package/src/types/Message.ts +3 -1
  166. package/src/types/types.ts +72 -10
  167. package/src/ui/Icon.tsx +1 -1
  168. package/src/ui/Spinner.tsx +19 -0
  169. package/src/utils/fileUtilities.ts +11 -125
  170. package/src/utils/infiniteScroll.js +11 -2
  171. package/src/utils/postal-parent.js +398 -0
  172. package/src/utils/promise.js +187 -0
  173. package/src/utils/scrollbarDetection.js +68 -9
  174. package/src/utils/utils.js +547 -0
  175. package/src/scss/theme/_attachments.scss +0 -74
  176. package/src/scss/theme/_cm-editor.scss +0 -42
  177. package/src/scss/theme/_colors.scss +0 -520
  178. package/src/scss/theme/_config.scss +0 -6
  179. package/src/scss/theme/_inputs.scss +0 -28
  180. package/src/scss/theme/_nav.scss +0 -52
  181. package/src/scss/theme/_palette.scss +0 -165
  182. package/src/scss/theme/_preview-icon.scss +0 -41
  183. package/src/scss/theme/_reboot.scss +0 -41
  184. package/src/scss/theme/_root.scss +0 -2
  185. package/src/scss/theme/_scroll.scss +0 -55
  186. package/src/scss/theme/_search.scss +0 -68
  187. package/src/scss/theme/_turbo.scss +0 -17
  188. package/src/scss/theme/_variables.scss +0 -139
  189. package/src/scss/theme/bootstrap/_accordion.scss +0 -146
  190. package/src/scss/theme/bootstrap/_alert.scss +0 -71
  191. package/src/scss/theme/bootstrap/_badge.scss +0 -38
  192. package/src/scss/theme/bootstrap/_breadcrumb.scss +0 -40
  193. package/src/scss/theme/bootstrap/_button-group.scss +0 -142
  194. package/src/scss/theme/bootstrap/_buttons.scss +0 -186
  195. package/src/scss/theme/bootstrap/_card.scss +0 -234
  196. package/src/scss/theme/bootstrap/_carousel.scss +0 -229
  197. package/src/scss/theme/bootstrap/_close.scss +0 -40
  198. package/src/scss/theme/bootstrap/_containers.scss +0 -41
  199. package/src/scss/theme/bootstrap/_dropdown.scss +0 -248
  200. package/src/scss/theme/bootstrap/_forms.scss +0 -9
  201. package/src/scss/theme/bootstrap/_functions.scss +0 -302
  202. package/src/scss/theme/bootstrap/_grid.scss +0 -33
  203. package/src/scss/theme/bootstrap/_helpers.scss +0 -10
  204. package/src/scss/theme/bootstrap/_images.scss +0 -42
  205. package/src/scss/theme/bootstrap/_list-group.scss +0 -191
  206. package/src/scss/theme/bootstrap/_maps.scss +0 -54
  207. package/src/scss/theme/bootstrap/_mixins.scss +0 -43
  208. package/src/scss/theme/bootstrap/_modal.scss +0 -237
  209. package/src/scss/theme/bootstrap/_nav.scss +0 -172
  210. package/src/scss/theme/bootstrap/_navbar.scss +0 -276
  211. package/src/scss/theme/bootstrap/_offcanvas.scss +0 -143
  212. package/src/scss/theme/bootstrap/_pagination.scss +0 -109
  213. package/src/scss/theme/bootstrap/_placeholders.scss +0 -51
  214. package/src/scss/theme/bootstrap/_popover.scss +0 -196
  215. package/src/scss/theme/bootstrap/_progress.scss +0 -59
  216. package/src/scss/theme/bootstrap/_reboot.scss +0 -610
  217. package/src/scss/theme/bootstrap/_root.scss +0 -73
  218. package/src/scss/theme/bootstrap/_spinners.scss +0 -85
  219. package/src/scss/theme/bootstrap/_tables.scss +0 -164
  220. package/src/scss/theme/bootstrap/_toasts.scss +0 -70
  221. package/src/scss/theme/bootstrap/_tooltip.scss +0 -120
  222. package/src/scss/theme/bootstrap/_transitions.scss +0 -27
  223. package/src/scss/theme/bootstrap/_type.scss +0 -106
  224. package/src/scss/theme/bootstrap/_utilities.scss +0 -647
  225. package/src/scss/theme/bootstrap/_variables.scss +0 -1633
  226. package/src/scss/theme/bootstrap/forms/_floating-labels.scss +0 -74
  227. package/src/scss/theme/bootstrap/forms/_form-check.scss +0 -175
  228. package/src/scss/theme/bootstrap/forms/_form-control.scss +0 -194
  229. package/src/scss/theme/bootstrap/forms/_form-range.scss +0 -91
  230. package/src/scss/theme/bootstrap/forms/_form-select.scss +0 -71
  231. package/src/scss/theme/bootstrap/forms/_form-text.scss +0 -11
  232. package/src/scss/theme/bootstrap/forms/_input-group.scss +0 -129
  233. package/src/scss/theme/bootstrap/forms/_labels.scss +0 -36
  234. package/src/scss/theme/bootstrap/forms/_validation.scss +0 -12
  235. package/src/scss/theme/bootstrap/helpers/_clearfix.scss +0 -3
  236. package/src/scss/theme/bootstrap/helpers/_color-bg.scss +0 -10
  237. package/src/scss/theme/bootstrap/helpers/_colored-links.scss +0 -12
  238. package/src/scss/theme/bootstrap/helpers/_position.scss +0 -36
  239. package/src/scss/theme/bootstrap/helpers/_ratio.scss +0 -26
  240. package/src/scss/theme/bootstrap/helpers/_stacks.scss +0 -15
  241. package/src/scss/theme/bootstrap/helpers/_stretched-link.scss +0 -15
  242. package/src/scss/theme/bootstrap/helpers/_text-truncation.scss +0 -7
  243. package/src/scss/theme/bootstrap/helpers/_visually-hidden.scss +0 -8
  244. package/src/scss/theme/bootstrap/helpers/_vr.scss +0 -8
  245. package/src/scss/theme/bootstrap/mixins/_alert.scss +0 -15
  246. package/src/scss/theme/bootstrap/mixins/_backdrop.scss +0 -14
  247. package/src/scss/theme/bootstrap/mixins/_banner.scss +0 -9
  248. package/src/scss/theme/bootstrap/mixins/_border-radius.scss +0 -78
  249. package/src/scss/theme/bootstrap/mixins/_box-shadow.scss +0 -18
  250. package/src/scss/theme/bootstrap/mixins/_buttons.scss +0 -70
  251. package/src/scss/theme/bootstrap/mixins/_caret.scss +0 -64
  252. package/src/scss/theme/bootstrap/mixins/_clearfix.scss +0 -9
  253. package/src/scss/theme/bootstrap/mixins/_color-scheme.scss +0 -7
  254. package/src/scss/theme/bootstrap/mixins/_container.scss +0 -11
  255. package/src/scss/theme/bootstrap/mixins/_deprecate.scss +0 -10
  256. package/src/scss/theme/bootstrap/mixins/_forms.scss +0 -152
  257. package/src/scss/theme/bootstrap/mixins/_gradients.scss +0 -47
  258. package/src/scss/theme/bootstrap/mixins/_grid.scss +0 -151
  259. package/src/scss/theme/bootstrap/mixins/_image.scss +0 -16
  260. package/src/scss/theme/bootstrap/mixins/_list-group.scss +0 -24
  261. package/src/scss/theme/bootstrap/mixins/_lists.scss +0 -7
  262. package/src/scss/theme/bootstrap/mixins/_pagination.scss +0 -10
  263. package/src/scss/theme/bootstrap/mixins/_reset-text.scss +0 -17
  264. package/src/scss/theme/bootstrap/mixins/_resize.scss +0 -6
  265. package/src/scss/theme/bootstrap/mixins/_table-variants.scss +0 -24
  266. package/src/scss/theme/bootstrap/mixins/_text-truncate.scss +0 -8
  267. package/src/scss/theme/bootstrap/mixins/_transition.scss +0 -26
  268. package/src/scss/theme/bootstrap/mixins/_utilities.scss +0 -97
  269. package/src/scss/theme/bootstrap/mixins/_visually-hidden.scss +0 -29
  270. package/src/scss/theme/bootstrap/utilities/_api.scss +0 -47
  271. package/src/scss/theme/bootstrap/vendor/_rfs.scss +0 -354
  272. package/src/scss/theme/bs/_badge.scss +0 -20
  273. package/src/scss/theme/bs/_buttons.scss +0 -185
  274. package/src/scss/theme/bs/_dropdown.scss +0 -86
  275. package/src/scss/theme/bs/_forms.scss +0 -161
  276. package/src/scss/theme/bs/_list-group.scss +0 -73
  277. package/src/scss/theme/bs/_tables.scss +0 -46
  278. package/src/scss/theme/fonts/_index.scss +0 -2
  279. package/src/scss/theme/mixins/_palette.scss +0 -165
  280. package/src/scss/theme/mixins/_scrollbar.scss +0 -110
@@ -0,0 +1,547 @@
1
+ //console.debug("utils.js", window.name);
2
+
3
+ /**
4
+ * Generate a S4 alphanumeric 4 character sequence suitable for non-sensitive GUID generation etc.
5
+ */
6
+ export function S4() {
7
+ return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
8
+ }
9
+
10
+ /**
11
+ * Parse any HTML string into a HTMLCollection. Use parseHTML(html)[0] to get the first HTMLElement.
12
+ *
13
+ * @param {any} html
14
+ * @returns {HTMLCollection} List of all parsed HTMLElements
15
+ */
16
+ export function parseHTML(html) {
17
+ if ('content' in document.createElement('template')) {
18
+ var template = document.createElement('template');
19
+ template.innerHTML = html.trim();
20
+ return template.content.children;
21
+ } else {
22
+ // IE etc
23
+ var parseDoc = document.implementation.createHTMLDocument();
24
+ parseDoc.body.innerHTML = html.trim();
25
+ return parseDoc.body.children;
26
+ }
27
+ }
28
+
29
+ /*
30
+ * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
31
+ *
32
+ * Copyright (c) 2014-2017, Jon Schlinkert.
33
+ * Released under the MIT License.
34
+ */
35
+
36
+ /**
37
+ * Checks if an object is an object.
38
+ *
39
+ * @param {any} maybeObject - The object to check
40
+ * @returns {boolean} True if the object is an object
41
+ */
42
+ export function isObject(maybeObject) {
43
+ return Object.prototype.toString.call(maybeObject) === '[object Object]';
44
+ }
45
+
46
+ /**
47
+ * Checks if an object is a plain object {}, similar to jQuery.isPlainObject()
48
+ *
49
+ * @param {any} maybePlainObject - The object to check
50
+ * @returns {boolean} True if the object is plain
51
+ */
52
+ export function isPlainObject(maybePlainObject) {
53
+ var ctor, prot;
54
+
55
+ if (isObject(maybePlainObject) === false) return false;
56
+
57
+ // If has modified constructor
58
+ ctor = maybePlainObject.constructor;
59
+ if (ctor === undefined) return true;
60
+
61
+ // If has modified prototype
62
+ prot = ctor.prototype;
63
+ if (isObject(prot) === false) return false;
64
+
65
+ // If constructor does not have an Object-specific method
66
+ if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) {
67
+ return false;
68
+ }
69
+
70
+ // Most likely a plain Object
71
+ return true;
72
+ }
73
+
74
+ /**
75
+ * Check if an object is a jquery collection containing at least one item.
76
+ *
77
+ * @param {any} maybeJQuery
78
+ * @returns {boolean} True if object is jQuery containing at least one item
79
+ */
80
+ export function isJQuery(maybeJQuery) {
81
+ return !!(maybeJQuery && maybeJQuery.jquery && maybeJQuery.length)
82
+ }
83
+
84
+ /**
85
+ * Method for extending plainObjects/options, similar to Object.assign() but with deep/recursive merging. If the recursive setting is applied it will merge any plain object children. Note that Arrays are treated as data and not as tree structure when merging.
86
+ *
87
+ * The original options passed are left untouched.
88
+ *
89
+ * @param {Object} source - Original options.
90
+ * @param {Object} properties - Merged options that will replace options from the source.
91
+ * @param {boolean} [recursive=false] True will merge any sub-objects of the options recursively. Otherwise sub-objects are treated as data.
92
+ * @returns {Object} A new object containing the merged options.
93
+ */
94
+ export function assign(source, properties, recursive) {
95
+ source = source || {};
96
+ properties = properties || {};
97
+
98
+ var property;
99
+
100
+ // Make a copy
101
+ var copy = {};
102
+ for (property in source) {
103
+ if (Object.prototype.hasOwnProperty.call(source, property)) {
104
+ copy[property] = source[property];
105
+ }
106
+ }
107
+
108
+ // Apply properties to copy
109
+ for (property in properties) {
110
+ if (Object.prototype.hasOwnProperty.call(properties, property)) {
111
+ if (recursive && copy[property] && isPlainObject(copy[property]) && isPlainObject(properties[property])) {
112
+ copy[property] = assign(copy[property], properties[property], recursive);
113
+ } else {
114
+ copy[property] = properties[property];
115
+ }
116
+ }
117
+ }
118
+ return copy;
119
+ }
120
+
121
+ /**
122
+ * Always returns an Array.
123
+ *
124
+ * @example
125
+ * asArray(1); // [1]
126
+ * asArray([1]); // [1]
127
+ *
128
+ * @param {any} maybeArray
129
+ * @returns {Array}
130
+ */
131
+ export function asArray(maybeArray) {
132
+ return maybeArray && (Array.isArray(maybeArray) ? maybeArray : [maybeArray]) || [];
133
+ }
134
+
135
+ /**
136
+ * Returns an element from an HTMLElement, string query selector, html string or jquery element
137
+ *
138
+ * @param {any} elementOrSelector
139
+ * @returns {HTMLElement}
140
+ */
141
+ export function asElement(elementOrSelector) {
142
+ if (elementOrSelector) {
143
+ if (elementOrSelector instanceof HTMLElement) {
144
+ return elementOrSelector;
145
+ }
146
+
147
+ if (typeof elementOrSelector === "string") {
148
+ if (elementOrSelector.indexOf("<") === 0) {
149
+ return parseHTML(elementOrSelector)[0];
150
+ } else {
151
+ return document.querySelector(elementOrSelector);
152
+ }
153
+ }
154
+
155
+ if (isJQuery(elementOrSelector)) {
156
+ console.warn("Weavy: providing jQuery elements is deprecated, please provide a HTMLElement or selector query instead.")
157
+ return elementOrSelector[0];
158
+ }
159
+ }
160
+ }
161
+
162
+ /**
163
+ * Case insensitive string comparison
164
+ *
165
+ * @param {any} str1 - The first string to compare
166
+ * @param {any} str2 - The second string to compare
167
+ * @param {boolean} ignoreType - Skipe type check and use any stringified value
168
+ * @returns {boolean}
169
+ */
170
+ export function eqString(str1, str2, ignoreType) {
171
+ return (ignoreType || typeof str1 === "string" && typeof str2 === "string") && String(str1).toUpperCase() === String(str2).toUpperCase();
172
+ }
173
+
174
+ /**
175
+ * Compares two jQuery objects.
176
+ *
177
+ * @param {any} a - The first jQuery object to compare
178
+ * @param {any} b - The second jQuery object to compare
179
+ * @returns {boolean}
180
+ */
181
+ export function eqJQuery(a, b) {
182
+ return a && b && a.jquery && b.jquery && a.jquery === b.jquery && a.length === b.length && a.length === a.filter(b).length;
183
+ }
184
+
185
+ /**
186
+ * Compares two plain objects. Compares all the properties in a to any properties in b.
187
+ *
188
+ * @param {any} a - The plain object to compare with b
189
+ * @param {any} b - The plain object to compare properties from a to
190
+ * @param {any} skipLength - Do not compare the number of properties
191
+ * @returns {boolean}
192
+ */
193
+ export function eqObjects(a, b, skipLength) {
194
+ if (!isPlainObject(a) || !isPlainObject(b)) {
195
+ return false;
196
+ }
197
+
198
+ var aProps = Object.getOwnPropertyNames(a);
199
+ var bProps = Object.getOwnPropertyNames(b);
200
+
201
+ if (!skipLength && aProps.length !== bProps.length) {
202
+ return false;
203
+ }
204
+
205
+ for (var i = 0; i < aProps.length; i++) {
206
+ var propName = aProps[i];
207
+ var propA = a[propName];
208
+ var propB = b[propName];
209
+
210
+ if (propA !== propB && !eqJQuery(propA, propB) && !eqObjects(propA, propB, skipLength)) {
211
+ return false;
212
+ }
213
+ }
214
+
215
+ return true;
216
+ }
217
+
218
+
219
+ // JSON HELPERS
220
+
221
+ /**
222
+ * Removes HTMLElement and Node from object before serializing. Used with JSON.stringify().
223
+ *
224
+ * @example
225
+ * var jsonString = JSON.stringify(data, sanitizeJSON);
226
+ *
227
+ * @param {string} key
228
+ * @param {any} value
229
+ * @returns {any} - Returns the value or undefined if removed.
230
+ */
231
+ export function sanitizeJSON(key, value) {
232
+ // Filtering out DOM Elements and nodes
233
+ if (value instanceof HTMLElement || value instanceof Node) {
234
+ return undefined;
235
+ }
236
+ return value;
237
+ }
238
+
239
+ /**
240
+ * Changes a string to snake_case from camelCase, PascalCase and spinal-case.
241
+ *
242
+ * @param {string} str - The string to change to snake case
243
+ * @returns {string} The processed string as snake_case
244
+ */
245
+ export function toSnakeCase(str) {
246
+ if (str.length > 0) {
247
+ return str.replace(/([a-z\d])([A-Z]+)/g, '$1_$2').replace(/-|\s+/g, '_').toLowerCase();
248
+ } else {
249
+ return str;
250
+ }
251
+ }
252
+
253
+ /**
254
+ * Changes a string to camelCase from PascalCase, spinal-case and snake_case.
255
+ *
256
+ * @param {string} str - The string to change to camel case
257
+ * @param {boolean} pascal - Make ste string PascalCase
258
+ * @returns {string} The processed string as camelCase or PascalCase
259
+ */
260
+ export function toCamelCase(str, pascal) {
261
+ if (pascal) {
262
+ // to PascalCase
263
+ str = str[0].toUpperCase() + str.substring(1);
264
+ } else {
265
+ // from PascalCase
266
+ str = str[0].toLowerCase() + str.substring(1);
267
+ }
268
+
269
+ // from snake_case and spinal-case
270
+ return str.replace(/([-_][a-z])/ig, function ($1) {
271
+ return $1.toUpperCase()
272
+ .replace('-', '')
273
+ .replace('_', '');
274
+ });
275
+ }
276
+
277
+ /**
278
+ * Changes all object keys recursively to camelCase from PascalCase, spinal-case and snake_case.
279
+ *
280
+ * @param {Object} obj - The object containing keys to process
281
+ * @param {boolean} pascal - Make keys PascalCase
282
+ * @returns {Object} The processed object with any camelCase or PascalCase keys
283
+ */
284
+ export function keysToCamelCase(obj, pascal) {
285
+ if (isPlainObject(obj)) {
286
+ const n = {};
287
+
288
+ Object.keys(obj)
289
+ .forEach(function (k) {
290
+ n[toCamelCase(k, pascal)] = keysToCamelCase(obj[k], pascal);
291
+ });
292
+
293
+ return n;
294
+ } else if (Array.isArray(obj)) {
295
+ return obj.map(function (i) {
296
+ return keysToCamelCase(i, pascal);
297
+ });
298
+ }
299
+
300
+ return obj;
301
+ }
302
+
303
+ /**
304
+ * Changes all object keys recursively to PascalCase from camelCase, spinal-case and snake_case.
305
+ *
306
+ * @param {Object} obj - The object containing keys to process
307
+ * @returns {Object} The processed object with any PascalCase keys
308
+ */
309
+ export function keysToPascalCase(obj) {
310
+ return keysToCamelCase(obj, true);
311
+ }
312
+
313
+ /**
314
+ * Serializes a form to an object with data.
315
+ *
316
+ * @param {HTMLFormElement} form - The form to serialize
317
+ * @param {boolean} snake_case - Use snake case for property names
318
+ * @returns {Object}
319
+ */
320
+ export function serializeObject(form, snake_case) {
321
+ snake_case = snake_case || false;
322
+ var o = {};
323
+ var d = new FormData(form);
324
+
325
+ d.forEach((value, name) => {
326
+ var n = snake_case ? toSnakeCase(name) : name;
327
+ if (o[n] !== undefined) {
328
+ if (!o[n].push) {
329
+ o[n] = [o[n]];
330
+ }
331
+ o[n].push(value || '');
332
+ } else {
333
+ o[n] = value || '';
334
+ }
335
+ })
336
+ return o;
337
+ }
338
+
339
+
340
+ /**
341
+ * Processing of JSON in a fetch response
342
+ *
343
+ * @param {external:Response} response - The fetch response to parse
344
+ * @returns {Object|Response} The data if sucessful parsing, otherwise the response or an rejected error
345
+ */
346
+ export function processJSONResponse(response) {
347
+ if (response) {
348
+ let contentType = (response.headers.has("content-type") ? response.headers.get("content-type") : "").split(";")[0];
349
+
350
+ if (response.ok) {
351
+ if (contentType === "application/json") {
352
+ try {
353
+ return response.json().then(function (jsonResponse) {
354
+ return keysToCamelCase(jsonResponse);
355
+ }).catch(function () {
356
+ return null;
357
+ });
358
+ } catch (e) {
359
+ return null;
360
+ }
361
+ }
362
+ return response;
363
+ } else {
364
+ if (contentType.match(/json$/i)) {
365
+ try {
366
+ return response.json().then(function (jsonResponse) {
367
+ return keysToCamelCase(jsonResponse);
368
+ }).then(function (responseError) {
369
+ return Promise.reject(new Error(responseError.detail || responseError.title || responseError.message || response.statusText || responseError.status));
370
+ }, function () {
371
+ return Promise.reject(new Error(response.statusText));
372
+ });
373
+ } catch (e) {
374
+ /* Could not extract any details */ }
375
+ }
376
+ return Promise.reject(new Error(response.statusText));
377
+ }
378
+ }
379
+ }
380
+
381
+ // OTHER HELPERS
382
+ var _storageAvailable = [];
383
+
384
+ export function storageAvailable(type) {
385
+ if (!(type in _storageAvailable)) {
386
+ var storage;
387
+ try {
388
+ storage = window[type];
389
+ var x = '__storage_test__';
390
+ storage.setItem(x, x);
391
+ if (storage.getItem(x) !== x) {
392
+ var er = new Error("Mismatching storage items.");
393
+ er.name = "StorageMismatchError"
394
+ }
395
+ storage.removeItem(x);
396
+ _storageAvailable[type] = true;
397
+ } catch (e) {
398
+ return e instanceof DOMException && (
399
+ // everything except Firefox
400
+ e.code === 22 ||
401
+ // Firefox
402
+ e.code === 1014 ||
403
+ // test name field too, because code might not be present
404
+ e.name === 'StorageMismatchError' ||
405
+ // everything except Firefox
406
+ e.name === 'QuotaExceededError' ||
407
+ // Firefox
408
+ e.name === 'NS_ERROR_DOM_QUOTA_REACHED') &&
409
+ // acknowledge QuotaExceededError only if there's something already stored
410
+ (storage && storage.length !== 0);
411
+ }
412
+ }
413
+ return !!_storageAvailable[type];
414
+ }
415
+
416
+ // Fallback storage;
417
+ var _storage = new Map();
418
+
419
+ /**
420
+ * Stores data for the current domain in the weavy namespace.
421
+ *
422
+ * @category options
423
+ * @param {string} key - The name of the data
424
+ * @param {data} value - Data to store
425
+ * @param {boolean} [asJson=false] - True if the data in value should be stored as JSON
426
+ */
427
+ export function storeItem(key, value, asJson, type) {
428
+ var keyName = 'weavy_' + window.location.hostname + "_" + key;
429
+ type = type || 'localStorage';
430
+
431
+ try {
432
+ value = asJson ? JSON.stringify(value, sanitizeJSON) : value;
433
+
434
+ if (storageAvailable(type)) {
435
+ window[type].setItem(keyName, value);
436
+ } else {
437
+ throw new Error();
438
+ }
439
+ } catch (e) {
440
+ console.warning("Using fallback storage:", key);
441
+ _storage.set(keyName, value);
442
+ }
443
+ }
444
+
445
+ /**
446
+ * Retrieves data for the current domain from the weavy namespace.
447
+ *
448
+ * @category options
449
+ * @param {string} key - The name of the data to retrieve
450
+ * @param {boolean} [isJson=false] - True if the data shoul be decoded from JSON
451
+ * @returns {any}
452
+ */
453
+ export function retrieveItem(key, isJson, type) {
454
+ var value;
455
+ var keyName = 'weavy_' + window.location.hostname + "_" + key;
456
+ type = type || 'localStorage';
457
+
458
+ try {
459
+ if (storageAvailable(type)) {
460
+ value = window[type].getItem(keyName);
461
+ } else {
462
+ throw new Error();
463
+ }
464
+ } catch (e) {
465
+ console.warning("Retrieving fallback storage:", key);
466
+ value = _storage.get(keyName);
467
+ }
468
+
469
+ if (value && isJson) {
470
+ try {
471
+ return JSON.parse(value);
472
+ } catch (e) {
473
+ /* value was not JSON */ }
474
+ }
475
+
476
+ return value;
477
+ }
478
+
479
+ /**
480
+ * Same as jQuery.ready()
481
+ *
482
+ * @param {Function} fn
483
+ */
484
+ export function ready(fn) {
485
+ if (document.readyState !== 'loading') {
486
+ fn();
487
+ } else {
488
+ document.addEventListener('DOMContentLoaded', fn, {
489
+ once: true
490
+ });
491
+ }
492
+ }
493
+
494
+ /**
495
+ * Parses a hex color to rgb
496
+ *
497
+ * @param {string} hex - Hex color string #112233
498
+ * @returns Array<number>
499
+ */
500
+ export function HEXToRGB(hex) {
501
+ return hex.match(/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i).slice(1).map((n) => parseInt(n, 16));
502
+ }
503
+
504
+ /**
505
+ * Convert rgb color to hsl
506
+ *
507
+ * @param {number} r
508
+ * @param {number} g
509
+ * @param {number} b
510
+ * @returns Array<number>
511
+ */
512
+ export function RGBToHSL (r, g, b) {
513
+ r /= 255;
514
+ g /= 255;
515
+ b /= 255;
516
+ const l = Math.max(r, g, b);
517
+ const s = l - Math.min(r, g, b);
518
+ const h = s
519
+ ? l === r
520
+ ? (g - b) / s
521
+ : l === g
522
+ ? 2 + (b - r) / s
523
+ : 4 + (r - g) / s
524
+ : 0;
525
+ return [
526
+ 60 * h < 0 ? 60 * h + 360 : 60 * h,
527
+ 100 * (s ? (l <= 0.5 ? s / (2 * l - s) : s / (2 - (2 * l - s))) : 0),
528
+ (100 * (2 * l - s)) / 2,
529
+ ];
530
+ }
531
+
532
+ /**
533
+ * Concatenate className strings
534
+ *
535
+ * @param {string} classNames - Strings with space-separeated classNames
536
+ * @returns string
537
+ */
538
+ export function classNamesConcat(...classNames) {
539
+ let classList = new Set();
540
+ classNames.forEach((s) => s && s.split(" ").filter((x) => x).forEach((c) => classList.add(c)));
541
+ return Array.from(classList).join(" ");
542
+ }
543
+
544
+ /**
545
+ * @external Response
546
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Response
547
+ */
@@ -1,74 +0,0 @@
1
- @use "config" as *;
2
- @use "bs/list-group";
3
-
4
-
5
- .wy-attachments,
6
- .wy-meetings {
7
- border: none;
8
- border-radius: $border-radius-sm;
9
- flex: 1 1 100%;
10
- min-width: 0;
11
-
12
- .wy-attachment,
13
- .wy-meeting {
14
- border-left: none;
15
- border-right: none;
16
- }
17
-
18
- > * {
19
- padding: .25rem .5rem;
20
- }
21
-
22
- > :first-child {
23
- border-top: none;
24
- }
25
-
26
- > :last-child {
27
- //border-top: variables.$border-width solid variables.$border-color;
28
- border-bottom: none;
29
- }
30
- }
31
-
32
- .wy-attachment,
33
- .wy-meeting {
34
- @extend
35
- %list-group-item,
36
- %list-group-item-action;
37
-
38
- display: flex;
39
- align-items: center;
40
- cursor: pointer;
41
- }
42
-
43
- .wy-attachment-icon {
44
- flex: 0 0 auto;
45
- display: flex;
46
-
47
- .wy-icon, .wy-icon-stack {
48
- width: 3rem;
49
- height: 3rem;
50
- }
51
- }
52
-
53
- .wy-attachment-content {
54
- flex: 1 1 100%;
55
- min-width: 0;
56
- margin-left: .5rem;
57
- margin-right: .5rem;
58
- }
59
-
60
- .wy-attachment-title {
61
- font-family: $headings-font-family;
62
- font-style: $headings-font-style;
63
- font-weight: $headings-font-weight;
64
- color: $headings-color;
65
- @include text-truncate();
66
- @include font-size($h6-font-size);
67
- margin: 0;
68
- }
69
-
70
- .wy-attachment-meta {
71
- @include text-truncate();
72
- @include font-size($small-font-size);
73
- color: $text-muted;
74
- }
@@ -1,42 +0,0 @@
1
- @use "config" as *;
2
- @use "mixins/scrollbar";
3
- @use "message-editor";
4
-
5
- .ͼ1 .cm-scroller {
6
- font-family: unset;
7
- line-height: 1.25;
8
- }
9
-
10
- .ͼ1 .cm-widgetBuffer {
11
- vertical-align: unset;
12
- }
13
-
14
- .cm-editor {
15
- @extend %message-editor-textfield;
16
-
17
- &.cm-focused {
18
- /* default theme in codemirror seems difficult to override */
19
- outline: $light solid 1px !important;
20
- }
21
-
22
- .cm-content {
23
- @extend %message-editor-textcontent;
24
- }
25
-
26
- .cm-scroller {
27
- overflow: auto;
28
-
29
- .wy-scrollbars & {
30
- @include scrollbar.custom-scrollbar;
31
- }
32
- }
33
- }
34
-
35
- textarea.is-invalid + [data-editor-target] .cm-editor {
36
- padding-right: $input-height-inner;
37
- background-image: escape-svg($form-feedback-icon-invalid);
38
- background-repeat: no-repeat;
39
- background-position: right $input-height-inner-quarter top $input-height-inner-quarter;
40
- background-size: $input-height-inner-half $input-height-inner-half;
41
- outline-color: $form-feedback-invalid-color !important;
42
- }