glib-web 0.5.77

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 (204) hide show
  1. package/.eslintrc.js +37 -0
  2. package/LICENSE +201 -0
  3. package/README.md +33 -0
  4. package/action.js +167 -0
  5. package/actions/analytics/logEvent.js +26 -0
  6. package/actions/auth/creditCard.js +29 -0
  7. package/actions/auth/restart.js +5 -0
  8. package/actions/auth/saveCsrfToken.js +12 -0
  9. package/actions/cables/push.js +38 -0
  10. package/actions/dialogs/alert.js +15 -0
  11. package/actions/dialogs/close.js +7 -0
  12. package/actions/dialogs/notification.js +14 -0
  13. package/actions/dialogs/oauth.js +6 -0
  14. package/actions/dialogs/open.js +7 -0
  15. package/actions/dialogs/options.js +5 -0
  16. package/actions/dialogs/show.js +5 -0
  17. package/actions/forms/submit.js +15 -0
  18. package/actions/http/delete.js +7 -0
  19. package/actions/http/patch.js +7 -0
  20. package/actions/http/post.js +7 -0
  21. package/actions/http/put.js +7 -0
  22. package/actions/panels/scrollTo.js +18 -0
  23. package/actions/panels/scrollToBottom.js +11 -0
  24. package/actions/runMultiple.js +11 -0
  25. package/actions/sheets/select.js +5 -0
  26. package/actions/snackbars/alert.js +15 -0
  27. package/actions/snackbars/select.js +5 -0
  28. package/actions/timeouts/set.js +20 -0
  29. package/actions/windows/close.js +13 -0
  30. package/actions/windows/closeAll.js +16 -0
  31. package/actions/windows/closeWithReload.js +18 -0
  32. package/actions/windows/open.js +5 -0
  33. package/actions/windows/openWeb.js +5 -0
  34. package/actions/windows/refreshState.js +5 -0
  35. package/actions/windows/reload.js +24 -0
  36. package/actions/ws/push.js +35 -0
  37. package/app.vue +180 -0
  38. package/components/_button.vue +101 -0
  39. package/components/_dropdownMenu.vue +76 -0
  40. package/components/_icon.vue +50 -0
  41. package/components/_message.vue +25 -0
  42. package/components/avatar.vue +16 -0
  43. package/components/banners/alert.vue +49 -0
  44. package/components/banners/select.vue +82 -0
  45. package/components/button.vue +13 -0
  46. package/components/calendar.vue +105 -0
  47. package/components/charts/column.vue +26 -0
  48. package/components/charts/line.vue +61 -0
  49. package/components/chip.vue +24 -0
  50. package/components/component.vue +222 -0
  51. package/components/datetime.vue +54 -0
  52. package/components/fab.vue +33 -0
  53. package/components/fields/_patternText.vue +61 -0
  54. package/components/fields/_select.vue +86 -0
  55. package/components/fields/autocomplete.vue +73 -0
  56. package/components/fields/check.vue +104 -0
  57. package/components/fields/checkGroup.vue +51 -0
  58. package/components/fields/country/countries.js +251 -0
  59. package/components/fields/country/field.vue +81 -0
  60. package/components/fields/country/regions.js +12 -0
  61. package/components/fields/creditCard.vue +105 -0
  62. package/components/fields/date.vue +24 -0
  63. package/components/fields/datetime.vue +49 -0
  64. package/components/fields/dynamicGroup.vue +106 -0
  65. package/components/fields/dynamicSelect.vue +173 -0
  66. package/components/fields/file.vue +166 -0
  67. package/components/fields/googlePlace.vue +158 -0
  68. package/components/fields/hidden.vue +18 -0
  69. package/components/fields/location.vue +223 -0
  70. package/components/fields/newRichText.vue +191 -0
  71. package/components/fields/phone/countries.js +315 -0
  72. package/components/fields/phone/field.vue +348 -0
  73. package/components/fields/phone/sprite.css +1071 -0
  74. package/components/fields/radio.vue +64 -0
  75. package/components/fields/radioGroup.vue +93 -0
  76. package/components/fields/rating.vue +26 -0
  77. package/components/fields/richText.vue +172 -0
  78. package/components/fields/select.vue +17 -0
  79. package/components/fields/stripe/stripeFields.vue +93 -0
  80. package/components/fields/stripe/stripeIndividualFields.vue +207 -0
  81. package/components/fields/stripeExternalAccount.vue +135 -0
  82. package/components/fields/stripeToken.vue +59 -0
  83. package/components/fields/submit.vue +23 -0
  84. package/components/fields/text.vue +144 -0
  85. package/components/fields/textarea.vue +59 -0
  86. package/components/fields/timeZone.vue +22 -0
  87. package/components/fields/timer.vue +83 -0
  88. package/components/h1.vue +28 -0
  89. package/components/h2.vue +20 -0
  90. package/components/h3.vue +22 -0
  91. package/components/h4.vue +20 -0
  92. package/components/h5.vue +20 -0
  93. package/components/h6.vue +20 -0
  94. package/components/hr.vue +13 -0
  95. package/components/html.vue +13 -0
  96. package/components/icon.vue +25 -0
  97. package/components/image.vue +87 -0
  98. package/components/label.vue +62 -0
  99. package/components/map.vue +206 -0
  100. package/components/markdown.vue +52 -0
  101. package/components/mixins/events.js +178 -0
  102. package/components/mixins/generic.js +58 -0
  103. package/components/mixins/list/autoload.js +144 -0
  104. package/components/mixins/longClick.js +56 -0
  105. package/components/mixins/scrolling.js +35 -0
  106. package/components/mixins/styles.js +221 -0
  107. package/components/mixins/table/autoload.js +131 -0
  108. package/components/mixins/table/export.js +52 -0
  109. package/components/mixins/table/import.js +106 -0
  110. package/components/mixins/text.js +20 -0
  111. package/components/mixins/ws/actionCable.js +48 -0
  112. package/components/mixins/ws/phoenixSocket.js +117 -0
  113. package/components/p.vue +36 -0
  114. package/components/panels/carousel.vue +55 -0
  115. package/components/panels/column.vue +117 -0
  116. package/components/panels/custom.vue +52 -0
  117. package/components/panels/flow.vue +81 -0
  118. package/components/panels/form.vue +126 -0
  119. package/components/panels/horizontal.vue +73 -0
  120. package/components/panels/list.vue +241 -0
  121. package/components/panels/responsive.vue +88 -0
  122. package/components/panels/scroll.vue +68 -0
  123. package/components/panels/split.vue +52 -0
  124. package/components/panels/table.vue +234 -0
  125. package/components/panels/ul.vue +34 -0
  126. package/components/panels/vertical.vue +71 -0
  127. package/components/panels/web.vue +11 -0
  128. package/components/spacer.vue +11 -0
  129. package/components/switch.vue +42 -0
  130. package/components/tabBar.vue +44 -0
  131. package/extensions/array.js +20 -0
  132. package/extensions/string.js +21 -0
  133. package/index.js +195 -0
  134. package/keys.js +12 -0
  135. package/nav/appbar.vue +117 -0
  136. package/nav/content.vue +40 -0
  137. package/nav/dialog.vue +127 -0
  138. package/nav/drawer.vue +88 -0
  139. package/nav/drawerButton.vue +28 -0
  140. package/nav/drawerLabel.vue +21 -0
  141. package/nav/sheet.vue +57 -0
  142. package/nav/snackbar.vue +72 -0
  143. package/package.json +42 -0
  144. package/settings.json.example +21 -0
  145. package/static/plugins/alignment/alignment.js +76 -0
  146. package/static/plugins/alignment/alignment.min.js +1 -0
  147. package/static/plugins/beyondgrammar/beyondgrammar.js +46 -0
  148. package/static/plugins/beyondgrammar/beyondgrammar.min.js +1 -0
  149. package/static/plugins/blockcode/blockcode.js +110 -0
  150. package/static/plugins/blockcode/blockcode.min.js +1 -0
  151. package/static/plugins/clips/clips.js +44 -0
  152. package/static/plugins/clips/clips.min.js +1 -0
  153. package/static/plugins/counter/counter.js +60 -0
  154. package/static/plugins/counter/counter.min.js +1 -0
  155. package/static/plugins/definedlinks/definedlinks.js +64 -0
  156. package/static/plugins/definedlinks/definedlinks.min.js +1 -0
  157. package/static/plugins/handle/handle.js +173 -0
  158. package/static/plugins/handle/handle.min.js +1 -0
  159. package/static/plugins/icons/icons.js +72 -0
  160. package/static/plugins/icons/icons.min.js +1 -0
  161. package/static/plugins/imageposition/imageposition.js +85 -0
  162. package/static/plugins/imageposition/imageposition.min.js +1 -0
  163. package/static/plugins/inlineformat/inlineformat.js +85 -0
  164. package/static/plugins/inlineformat/inlineformat.min.js +1 -0
  165. package/static/plugins/removeformat/removeformat.js +28 -0
  166. package/static/plugins/removeformat/removeformat.min.js +1 -0
  167. package/static/plugins/selector/selector.js +96 -0
  168. package/static/plugins/selector/selector.min.js +1 -0
  169. package/static/plugins/specialchars/specialchars.js +63 -0
  170. package/static/plugins/specialchars/specialchars.min.js +1 -0
  171. package/static/plugins/textdirection/textdirection.js +55 -0
  172. package/static/plugins/textdirection/textdirection.min.js +1 -0
  173. package/static/plugins/textexpander/textexpander.js +46 -0
  174. package/static/plugins/textexpander/textexpander.min.js +1 -0
  175. package/static/plugins/underline/underline.js +27 -0
  176. package/static/plugins/underline/underline.min.js +1 -0
  177. package/static/redactorx.css +1344 -0
  178. package/static/redactorx.js +14254 -0
  179. package/static/redactorx.min.css +1 -0
  180. package/static/redactorx.min.js +1 -0
  181. package/static/redactorx.usm.min.js +2 -0
  182. package/styles/test.sass +3 -0
  183. package/styles/test.scss +5 -0
  184. package/templates/_menu.vue +38 -0
  185. package/templates/comment.vue +202 -0
  186. package/templates/featured.vue +32 -0
  187. package/templates/thumbnail.vue +138 -0
  188. package/templates/unsupported.vue +12 -0
  189. package/utils/app.js +14 -0
  190. package/utils/dom.js +13 -0
  191. package/utils/form.js +34 -0
  192. package/utils/format.js +14 -0
  193. package/utils/hash.js +29 -0
  194. package/utils/helper.js +44 -0
  195. package/utils/history.js +70 -0
  196. package/utils/http.js +209 -0
  197. package/utils/launch.js +135 -0
  198. package/utils/private/ws.js +22 -0
  199. package/utils/public.js +23 -0
  200. package/utils/settings.js +48 -0
  201. package/utils/storage.js +9 -0
  202. package/utils/type.js +69 -0
  203. package/utils/uploader.js +121 -0
  204. package/utils/url.js +132 -0
@@ -0,0 +1,25 @@
1
+ <template>
2
+ <a v-if="$href()" :href="$href()" :rel="$rel()" @click="$onClick()">
3
+ <common-icon :spec="iconSpec" />
4
+ </a>
5
+ <common-icon v-else :spec="iconSpec" />
6
+ </template>
7
+
8
+ <script>
9
+ export default {
10
+ props: {
11
+ spec: { type: Object, required: true },
12
+ isBusy: { type: Boolean }
13
+ },
14
+ computed: {
15
+ iconSpec() {
16
+ if (this.spec.spec) {
17
+ return this.spec.spec;
18
+ }
19
+ return this.spec;
20
+ }
21
+ }
22
+ };
23
+ </script>
24
+
25
+ <style scoped></style>
@@ -0,0 +1,87 @@
1
+ <template>
2
+ <!-- TODO: Add support for href and :rel="$rel()" -->
3
+ <v-img :src="spec.url || spec.base64Data" :style="styles" @click="$onClick()">
4
+ <!-- <v-progress-circular v-if="$isBusy" indeterminate /> -->
5
+ </v-img>
6
+ </template>
7
+
8
+ <script>
9
+ import Vue from "vue";
10
+
11
+ export default {
12
+ props: {
13
+ spec: { type: Object, required: true }
14
+ },
15
+ data() {
16
+ return {
17
+ styles: {}
18
+ };
19
+ },
20
+ // computed: {
21
+ // isOnClickPresent() {
22
+ // return this.spec.hasOwnProperty('onClick')
23
+ // }
24
+ // },
25
+ methods: {
26
+ // styles: function() {
27
+ // // const styles = this.genericStyles(Object.assign({ height: 210 }, this.spec))
28
+ // const styles = this.genericStyles(Object.assign({}, this.spec));
29
+ // return styles;
30
+ // }
31
+ $ready() {
32
+ const styles = this.genericStyles(Object.assign({}, this.spec));
33
+ this.styles = styles;
34
+
35
+ if (this.spec.url) {
36
+ const image = new Image();
37
+ image.src = this.spec.url;
38
+ image.onload = () => {
39
+ const fit = this.spec.fit || "clip";
40
+
41
+ switch (fit) {
42
+ case "crop":
43
+ this.fitCrop(image);
44
+ return;
45
+ default:
46
+ this.fitClip(image);
47
+ }
48
+ };
49
+ }
50
+ },
51
+ fitClip(image) {
52
+ let width, height;
53
+ const aspectRatio = image.naturalWidth / image.naturalHeight;
54
+
55
+ if (this.spec.width == "matchParent") {
56
+ width = "100%";
57
+ height = `${100 / aspectRatio}%`;
58
+ } else {
59
+ if (this.spec.width) {
60
+ width = `${this.spec.width}px`;
61
+ height = `${this.spec.width / aspectRatio}px`;
62
+ } else if (this.spec.height) {
63
+ width = `${this.spec.height * aspectRatio}px`;
64
+ height = `${this.spec.height}px`;
65
+ }
66
+ }
67
+
68
+ Vue.set(this.styles, "width", width);
69
+ Vue.set(this.styles, "height", height);
70
+ },
71
+ fitCrop(image) {
72
+ let width, height;
73
+
74
+ if (this.spec.width) {
75
+ width = `${this.spec.width}px`;
76
+ height = `${image.naturalHeight}px`;
77
+ } else if (this.spec.height) {
78
+ width = `${image.naturalWidth}px`;
79
+ height = `${this.spec.height}px`;
80
+ }
81
+
82
+ Vue.set(this.styles, "width", width);
83
+ Vue.set(this.styles, "height", height);
84
+ }
85
+ }
86
+ };
87
+ </script>
@@ -0,0 +1,62 @@
1
+ <template>
2
+ <a
3
+ v-if="spec.onClick"
4
+ :href="$href()"
5
+ :rel="$rel()"
6
+ :style="textStyles()"
7
+ :class="$classes()"
8
+ @click="$onClick()"
9
+ >{{ text }}</a
10
+ >
11
+ <span v-else :style="$styles()" :class="$classes()">{{ text }}</span>
12
+ </template>
13
+
14
+ <script>
15
+ import actionCableMixin from "./mixins/ws/actionCable";
16
+ import textMixin from "./mixins/text.js";
17
+
18
+ export default {
19
+ mixins: [actionCableMixin, textMixin],
20
+ props: {
21
+ spec: { type: Object, required: true }
22
+ },
23
+ data: function() {
24
+ return {
25
+ text: " "
26
+ };
27
+ },
28
+ methods: {
29
+ $ready() {
30
+ this.$wsInitActionCable(this.spec.actionCable);
31
+
32
+ this.text = this.spec.text;
33
+ },
34
+ action_set(spec) {
35
+ if (spec.user_id !== spec.filterKey) {
36
+ this.text = spec.text;
37
+ }
38
+ }
39
+ }
40
+ };
41
+ </script>
42
+
43
+ <style lang="scss" scoped>
44
+ span,
45
+ a {
46
+ /* white-space: pre-line; */
47
+ white-space: pre-wrap;
48
+
49
+ /* Without this, padding-top doesn't work */
50
+ display: inline-block;
51
+ line-height: 1;
52
+ }
53
+ span.muted {
54
+ opacity: 0.7;
55
+ }
56
+ span.small {
57
+ font-size: 80%;
58
+ }
59
+ a:hover {
60
+ text-decoration: none;
61
+ }
62
+ </style>
@@ -0,0 +1,206 @@
1
+ <template>
2
+ <!-- <div ref="map" :style="genericStyles()"></div> -->
3
+ <gmap-map
4
+ ref="map"
5
+ :center="center"
6
+ :zoom="zoom"
7
+ map-type-id="roadmap"
8
+ :style="genericStyles()"
9
+ @dragend="onMapDragEnd"
10
+ >
11
+ <gmap-info-window
12
+ :options="infoWindowOptions"
13
+ :position="infoWindowPosition"
14
+ :opened="infoWindowOpen"
15
+ @closeclick="onInfoWindowClose"
16
+ >
17
+ <template v-if="selectedMarker != null">
18
+ <strong>{{ selectedMarker.infoWindow.title }}</strong>
19
+ <div style="padding-top: 4px;">
20
+ {{ selectedMarker.infoWindow.subtitle }}
21
+ </div>
22
+ <panels-responsive
23
+ v-if="selectedMarker.infoWindow.body"
24
+ :spec="selectedMarker.infoWindow.body"
25
+ />
26
+ </template>
27
+ </gmap-info-window>
28
+
29
+ <!-- See http://localhost:3000/packs/js/vue_renderer-c97eb6266387b9f0887d.js for MarkerClustererOptions -->
30
+ <gmap-cluster
31
+ v-if="spec.cluster"
32
+ :calculator="_calculator"
33
+ :minimum-cluster-size="1"
34
+ >
35
+ <gmap-marker
36
+ v-for="(marker, index) in markers"
37
+ :key="index"
38
+ :position="{ lat: marker.latitude, lng: marker.longitude }"
39
+ :clickable="true"
40
+ :title="String(marker.clusterSize || 1)"
41
+ @click="onMarkerClick(marker, index)"
42
+ ></gmap-marker>
43
+ </gmap-cluster>
44
+ <template v-else>
45
+ <gmap-marker
46
+ v-for="(marker, index) in markers"
47
+ :key="index"
48
+ :position="{ lat: marker.latitude, lng: marker.longitude }"
49
+ :clickable="true"
50
+ @click="onMarkerClick(marker, index)"
51
+ ></gmap-marker>
52
+ </template>
53
+ </gmap-map>
54
+ </template>
55
+
56
+ <script>
57
+ import GmapCluster from "vue2-google-maps/dist/components/cluster";
58
+
59
+ export default {
60
+ components: {
61
+ "gmap-cluster": GmapCluster
62
+ },
63
+ props: {
64
+ spec: { type: Object, required: true }
65
+ },
66
+ data() {
67
+ return {
68
+ infoWindowOptions: {
69
+ pixelOffset: {
70
+ width: 0,
71
+ height: -35
72
+ }
73
+ },
74
+ infoWindowOpen: false,
75
+ infoWindowPosition: null,
76
+ selectedMarker: null,
77
+ center: { lat: 0, lng: 0 },
78
+ zoom: 11,
79
+ markers: []
80
+ };
81
+ },
82
+ methods: {
83
+ // See https://stackoverflow.com/questions/37597324/markercluster-one-marker-for-a-group for calculator example
84
+ _calculator(markers, numStyles) {
85
+ let sum = 0;
86
+ for (const marker of markers) {
87
+ sum += Number(marker.title);
88
+ }
89
+
90
+ return {
91
+ text: sum,
92
+ index: 0,
93
+ title: ""
94
+ };
95
+ },
96
+ // attachScript: function(elementId, url) {
97
+ // if (document.getElementById(elementId) == null) {
98
+ // const script = document.createElement('script')
99
+ // script.setAttribute('id', elementId)
100
+ // script.setAttribute('src', url)
101
+ // script.setAttribute('defer', 'defer')
102
+ // document.body.appendChild(script)
103
+ // }
104
+ // },
105
+ // renderGoogleMap: function() {
106
+ // const mapView = this.$refs.map
107
+ // const spec = this.spec
108
+
109
+ // window.googleMaps = window.googleMaps || {
110
+ // initializers: [],
111
+ // init: function() {
112
+ // for (const exec of this.initializers) {
113
+ // exec()
114
+ // }
115
+ // }
116
+ // }
117
+ // window.googleMaps.initializers.push(
118
+ // function() {
119
+ // const map = new google.maps.Map(mapView, {zoom: spec.zoom || 10})
120
+ // map.setCenter({lat: spec.latitude, lng: spec.longitude})
121
+ // //var marker = new google.maps.Marker({position: center, map: map})
122
+ // }
123
+ // )
124
+
125
+ // this.attachScript('__google_map_script', `https://maps.googleapis.com/maps/api/js?key=${process.env.GMAPS_API_KEY}&callback=googleMaps.init`)
126
+ // },
127
+ // renderBaiduMap: function() {
128
+ // const mapView = this.$refs.map
129
+ // const spec = this.spec
130
+
131
+ // window.baiduMaps = window.baiduMaps || {
132
+ // initializers: [],
133
+ // init: function() {
134
+ // for (const exec of this.initializers) {
135
+ // exec()
136
+ // }
137
+ // }
138
+ // }
139
+ // window.baiduMaps.initializers.push(
140
+ // function() {
141
+ // // NOTE: Outside of China, coordinate conversion is still not accurate. See Macomatic's answer on
142
+ // // https://stackoverflow.com/questions/29444803/does-a-google-maps-coordinate-map-to-the-same-location-in-baidu-maps
143
+ // // This is why the BMap.Convertor solution doesn't point to the right location during our testing.
144
+ // var map = new BMap.Map(mapView);
145
+ // map.centerAndZoom(new BMap.Point(123.404, 39.815), spec.zoom || 10)
146
+ // map.enableScrollWheelZoom()
147
+ // }
148
+ // )
149
+
150
+ // this.attachScript('__baidu_map_script', "http://api.map.baidu.com/api?v=1.5&ak=2b866a6daac9014292432d81fe9b47e3&callback=baiduMaps.init")
151
+ // },
152
+
153
+ $ready() {
154
+ const { latitude, longitude, zoom } = this.spec;
155
+ if (this.$type.isNumber(latitude) && this.$type.isNumber(longitude)) {
156
+ this.updateMapCenter(latitude, longitude);
157
+ }
158
+ this.$type.ifNumber(zoom, val => (this.zoom = val));
159
+ this.fetchMarkers();
160
+ },
161
+ updateMapCenter(lat, lng) {
162
+ this.center.lat = lat;
163
+ this.center.lng = lng;
164
+ },
165
+ fetchMarkers() {
166
+ const { lat, lng } = this.center;
167
+ const url = new URL(this.spec.dataUrl);
168
+ url.searchParams.append("lat", lat);
169
+ url.searchParams.append("long", lng);
170
+
171
+ Utils.http.execute({ url: url.toString() }, "GET", this, response => {
172
+ this.markers = response.pins;
173
+ });
174
+ },
175
+ onInfoWindowClose() {
176
+ this.infoWindowOpen = false;
177
+ this.infoWindowPosition = null;
178
+ this.selectedMarker = null;
179
+ },
180
+ onMarkerClick(marker, index) {
181
+ this.selectedMarker = marker;
182
+ this.infoWindowPosition = { lat: marker.latitude, lng: marker.longitude };
183
+ this.infoWindowOpen = true;
184
+ },
185
+ onMapDragEnd(e) {
186
+ const { center } = this.$refs.map.$mapObject;
187
+ this.updateMapCenter(center.lat(), center.lng());
188
+ this.fetchMarkers();
189
+ }
190
+ }
191
+ // mounted: function() {
192
+ // // switch (this.spec.provider) {
193
+ // // case 'baidu':
194
+ // // this.renderBaiduMap()
195
+ // // break
196
+ // // default:
197
+ // // this.renderGoogleMap()
198
+ // // }
199
+ // const { latitude, longitude, zoom } = this.spec
200
+ // this.updateMapCenter(latitude, longitude)
201
+ // this.zoom = zoom
202
+
203
+ // this.fetchMarkers()
204
+ // }
205
+ };
206
+ </script>
@@ -0,0 +1,52 @@
1
+ <template>
2
+ <div :style="genericStyles()" :class="$classes()">
3
+ <!-- eslint-disable-next-line vue/no-v-html -->
4
+ <span v-html="compiledText"></span>
5
+ <div
6
+ v-if="youtubeId"
7
+ :style="`width: 320px; overflow: hidden; max-height: 180px;`"
8
+ >
9
+ <youtube :video-id="youtubeId" fit-parent></youtube>
10
+ </div>
11
+ </div>
12
+ </template>
13
+
14
+ <script>
15
+ export default {
16
+ props: {
17
+ spec: { type: Object, required: true }
18
+ },
19
+ data() {
20
+ return {
21
+ youtubeId: null
22
+ };
23
+ },
24
+ computed: {
25
+ compiledText() {
26
+ return Utils.format.markdown(this.spec.text);
27
+ }
28
+ },
29
+ methods: {
30
+ $ready() {
31
+ if (this.spec.previewVideo) {
32
+ this.youtubeId = this.extractYoutubeId(this.spec.text);
33
+ console.log("Detected Youtube ID", this.youtubeId);
34
+ }
35
+ },
36
+ // From https://gist.github.com/takien/4077195
37
+ extractYoutubeId(url) {
38
+ var ID = "";
39
+ url = url
40
+ .replace(/(>|<)/gi, "")
41
+ .split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/);
42
+ if (url[2] !== undefined) {
43
+ ID = url[2].split(/[^0-9a-z_\-]/i);
44
+ ID = ID[0];
45
+ }
46
+ return ID;
47
+ }
48
+ }
49
+ };
50
+ </script>
51
+
52
+ <style scoped></style>
@@ -0,0 +1,178 @@
1
+ import Action from "../../action";
2
+ import UrlUtils from "../../utils/url";
3
+ import TypeUtils from "../../utils/type";
4
+
5
+ export default {
6
+ data() {
7
+ return {
8
+ // TODO: Consider replacing with an enum, e.g. executing with predefined values ('post', 'get', null)
9
+ // The complexity with this is that 'get' that comes after 'post' needs to show an indicator, e.g.
10
+ // Submit button needs to be disabled when redirecting after form submission
11
+ _isBusy: false,
12
+ _events: [],
13
+ _typingTimer: null
14
+ };
15
+ },
16
+ computed: {
17
+ _pageBody() {
18
+ return document.getElementById("page_body");
19
+ },
20
+ $isBusy() {
21
+ // Properties starting with $ or _ can only be accessed via $data
22
+ return this.$data._isBusy;
23
+ },
24
+ $isReady() {
25
+ return this.$data._events === null;
26
+ }
27
+ },
28
+ mounted() {
29
+ this._executeIfReady(false);
30
+ this.$mounted();
31
+ },
32
+ updated() {
33
+ this._executeIfReady(true);
34
+ this.$updated();
35
+ },
36
+ destroyed() {
37
+ this.$tearDown();
38
+ },
39
+ watch: {
40
+ // See Utils.http
41
+ "$root.vueApp.isStale": function(val, oldVal) {
42
+ // Make sure $ready() will be called in the next update
43
+ this._mountedUrl = null;
44
+ }
45
+ },
46
+ methods: {
47
+ $href: function(spec) {
48
+ const properties = spec || this.spec;
49
+ const onClick = properties.onClick;
50
+ if (TypeUtils.isObject(onClick)) {
51
+ switch (onClick.action) {
52
+ case "windows/open-v1":
53
+ case "windows/openWeb-v1":
54
+ case "windows/reload-v1":
55
+ return UrlUtils.htmlUrl(onClick.url);
56
+ }
57
+ }
58
+ return null;
59
+ },
60
+ $onClick: function(explicitEvent, spec) {
61
+ const properties = spec || this.spec;
62
+ const e = explicitEvent || event;
63
+
64
+ if (!properties.onClick) {
65
+ return; // Avoid blocking the event for parents.
66
+ }
67
+
68
+ // Ignore middle/right clicks
69
+ if (!e.metaKey && !e.ctrlKey && e.button === 0) {
70
+ e.preventDefault();
71
+ e.stopPropagation();
72
+ // Action.execute(properties.onClick, target || event.target, this);
73
+ Action.execute(properties.onClick, null, this);
74
+ }
75
+ },
76
+ $rel: function(spec) {
77
+ const properties = spec || this.spec;
78
+ const onClick = properties.onClick;
79
+ if (TypeUtils.isObject(onClick)) {
80
+ if (onClick.action === "windows/openWeb-v1") {
81
+ return "nofollow";
82
+ }
83
+ }
84
+ return null;
85
+ },
86
+ // Can be used for optimization, but not needed for now.
87
+ // $onLongPressFunction() {
88
+ // return this.spec.onLongPress ? this.$onLongPress : null;
89
+ // },
90
+ $onLongPress() {
91
+ GLib.action.execute(this.spec.onLongPress, null, this);
92
+ },
93
+ $addViewportChangeListeners: function(handler) {
94
+ window.addEventListener("load", handler);
95
+ window.addEventListener("resize", handler);
96
+ this._pageBody.addEventListener("scroll", handler);
97
+ },
98
+ $removeViewportChangeListeners: function(handler) {
99
+ window.removeEventListener("load", handler);
100
+ window.removeEventListener("resize", handler);
101
+ this._pageBody.removeEventListener("scroll", handler);
102
+ },
103
+ _executeIfReady(updated) {
104
+ if (updated) {
105
+ if (!this._renderingTheSamePage()) {
106
+ this.$tearDown();
107
+ this._ready();
108
+ }
109
+ } else {
110
+ this._ready();
111
+ }
112
+ },
113
+ _renderingTheSamePage() {
114
+ return this._mountedUrl === window.location.href;
115
+ },
116
+ _ready() {
117
+ this._mountedUrl = window.location.href;
118
+ this._updatedAt = new Date().getTime();
119
+
120
+ this.$data._events = [];
121
+
122
+ // Has to be executed before $ready()
123
+ this._linkFieldModels();
124
+
125
+ this.$ready();
126
+
127
+ // Make sure events are dispatched after $ready(). Dispatching them during $ready() causes errors.
128
+ for (const event of this.$data._events) {
129
+ // Execute later to ensure the parent has registered its event listener
130
+ // setTimeout(() => {
131
+ this.$el.dispatchEvent(event);
132
+ // }, 100)
133
+ }
134
+ this.$data._events = null;
135
+ },
136
+ $ready() {
137
+ // To be overridden
138
+ },
139
+ $tearDown() {
140
+ // To be overridden
141
+ },
142
+ $mounted() {
143
+ // To be overridden
144
+ },
145
+ $updated() {
146
+ // To be overridden
147
+ },
148
+ $dispatchEvent(name, data) {
149
+ const event = new Event(name, { bubbles: true });
150
+
151
+ // TODO: Deprecate
152
+ event.spec = data;
153
+
154
+ event.data = data;
155
+
156
+ if (this.$data._events) {
157
+ this.$data._events.push(event);
158
+ } else {
159
+ this.$el.dispatchEvent(event);
160
+ }
161
+ },
162
+ $onEvent(name, handler) {
163
+ this.$el.addEventListener(name, handler);
164
+ },
165
+ $onTyping({ duration = 2000 }) {
166
+ GLib.action.execute(this.spec.onTypeStart, null, this);
167
+ clearTimeout(this.timer);
168
+
169
+ this.timer = setTimeout(() => {
170
+ this._typingTimer = null;
171
+ GLib.action.execute(this.spec.onTypeEnd, null, this);
172
+ }, duration);
173
+ }
174
+ // $onZero() {
175
+ // GLib.action.execute(this.spec.onZero, null, this);
176
+ // },
177
+ }
178
+ };
@@ -0,0 +1,58 @@
1
+ export default {
2
+ methods: {
3
+ $closest(name) {
4
+ var parent = this.$parent;
5
+ while (parent != null) {
6
+ if (
7
+ Utils.type.isObject(parent.spec) &&
8
+ Utils.app.vueName(parent) == name
9
+ ) {
10
+ return parent;
11
+ }
12
+ parent = parent.$parent;
13
+ }
14
+ },
15
+ $validation(rules) {
16
+ var augmentedRules = rules || [];
17
+ Utils.type.ifObject(this.spec.validation, val => {
18
+ Utils.type.ifObject(val.required, spec => {
19
+ augmentedRules = augmentedRules.concat([
20
+ v => (v ? true : spec.message)
21
+ ]);
22
+ });
23
+ });
24
+ return augmentedRules;
25
+ },
26
+ $wsSubscribeEvents(spec) {
27
+ if (!Utils.type.isObject(spec)) {
28
+ return;
29
+ }
30
+
31
+ const topicName = spec.topic;
32
+ const events = spec.events;
33
+ if (!Utils.type.isString(topicName) || !Utils.type.isArray(events)) {
34
+ return;
35
+ }
36
+
37
+ const ws = window.vueApp.webSocket;
38
+ const channel = ws.channels[topicName];
39
+
40
+ if (!channel) {
41
+ console.log(`Topic not ready: '${topicName}'`);
42
+ setTimeout(() => {
43
+ // Wait until $wsInitPhoenixSocket() has executed.
44
+ this.$wsSubscribeEvents(spec);
45
+ }, 200);
46
+ return;
47
+ }
48
+
49
+ for (const eventName of events) {
50
+ console.log(`Registering event '${eventName}'`);
51
+ channel.on(eventName, payload => {
52
+ console.debug(`Received '${eventName}' event`, payload);
53
+ Utils.ws.handleResponse(payload.onResponse, this);
54
+ });
55
+ }
56
+ }
57
+ }
58
+ };