@sedoo/unidoo 0.1.16 → 0.1.17

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.
package/src/plugin.js CHANGED
@@ -1,202 +1,240 @@
1
1
  // Import vue components
2
2
  // import * as components from './components/index'
3
3
  // var components = {}
4
+ import vueCustomElement from "vue-custom-element";
4
5
 
5
6
  // install function executed by Vue.use()
6
7
  function install(Vue) {
7
- if (install.installed) return
8
- install.installed = true
9
-
10
- // For each matching file name...
11
- requireComponent.keys().forEach((fileName) => {
12
- // Get the component config
13
- const componentConfig = requireComponent(fileName)
14
- // Get the PascalCase version of the component name
15
- const componentName = fileName
16
- .split('/')
17
- .pop()
18
- .replace(/\.\w+$/, '')
19
- // components[componentName] = componentConfig.default || componentConfig
20
- // Globally register the component
21
- Vue.component(componentName, componentConfig.default || componentConfig)
22
- })
23
- // Register Global event to show AppMessage, related to AppSnackbar
24
- // https://medium.com/@panzelva/writing-modals-for-vue-js-callable-from-anywhere-6994d180451
25
- this.EventBus = new Vue()
26
- Vue.prototype.$unidooAlert = {
27
- show(params) {
28
- plugin.EventBus.$emit("unidoo-alert-show", params)
29
- },
30
-
31
- defaultParams(params) {
32
- plugin.EventBus.$emit("unidoo-alert-params", params)
33
- },
34
-
35
- showSuccess(message, closeButtonLabel) {
36
- if (closeButtonLabel) {
37
- this.showMessage(message, "success", 4000, 'top', closeButtonLabel)
38
- } else {
39
- this.showMessage(message, "success")
40
- }
41
- },
42
-
43
- /**
44
- * Display the given error message for 8 seconds
45
- * @param {string} message
46
- */
47
- showError(message, closeButtonLabel) {
48
- if (closeButtonLabel) {
49
- this.showMessage(message, "error", 8000, 'top', closeButtonLabel)
50
- } else {
51
- this.showMessage(message, "error", 8000)
52
- }
53
- },
54
-
55
- /**
56
- * This method return the message from an error object ResponseStatusException or RuntimeException
57
- * @param {string} prefix e.g. 'An error has occured :'
58
- * @param {*} error The error object from the catch(function(error)
59
- * @returns {string} The error message
60
- */
61
- formatError(prefix, error) {
62
- let message = 'An error has occured'
63
- if (typeof error === 'object') {
64
- if (error.response && error.response.data && error.response.data.message) {
65
- message = prefix + ' ' + error.response.data.message
66
- } else if (error.message) {
67
- message = prefix + ' ' + error.message
68
- }
69
- }
70
- return message
71
- },
72
-
73
- showMessage(message, type, timeout, position, closeButtonLabel) {
74
- const params = {}
75
- if (position) {
76
- params.position = position
77
- }
78
-
79
- if (timeout) {
80
- params.timeout = timeout
81
- }
82
-
83
- if (closeButtonLabel) {
84
- params.closeButtonLabel = closeButtonLabel
85
- }
86
-
87
- params.message = message
88
- params.type = type
89
- this.show(params)
90
- },
8
+ if (install.installed) return;
9
+ install.installed = true;
10
+
11
+ Vue.use(vueCustomElement);
12
+
13
+ // For each matching file name...
14
+ requireComponent.keys().forEach((fileName) => {
15
+ // Get the component config
16
+ const componentConfig = requireComponent(fileName);
17
+ // Get the PascalCase version of the component name
18
+ const componentName = fileName
19
+ .split("/")
20
+ .pop()
21
+ .replace(/\.\w+$/, "");
22
+ // components[componentName] = componentConfig.default || componentConfig
23
+ // Globally register the component
24
+ Vue.component(componentName, componentConfig.default || componentConfig);
25
+ // Use Vue.customElement to enable the be able to use the component UnidooMapGeoFeatures as a custom element in WordPress
26
+ if (componentName === "UnidooMapGeoFeatures") {
27
+ const kebabCaseComponentName = "unidoo-map-geo-features";
28
+ Vue.customElement(
29
+ kebabCaseComponentName,
30
+ componentConfig.default || componentConfig
31
+ );
91
32
  }
92
-
93
- Vue.prototype.$unidooUuid = {
94
- randomUuidV4() {
95
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
96
- var r = Math.random() * 16 | 0;
97
- var v = c === 'x' ? r : (r & 0x3 | 0x8);
98
- return v.toString(16);
99
- });
100
- },
101
- }
102
-
103
- Vue.prototype.$unidooConfirmDialog = {
104
- showWithParams(params) {
105
- plugin.EventBus.$emit("unidoo-confirm-dialog-show", params)
106
- },
107
-
108
- defaultParams(params) {
109
- plugin.EventBus.$emit("unidoo-confirm-dialog-params", params)
110
- },
111
-
112
- show(callback, message, title, titleClasses, width, cancelButtonLabel, confirmButtonLabel) {
113
- const params = {}
114
- if (callback) {
115
- params.callback = callback
116
- }
117
-
118
- if (message) {
119
- params.message = message
120
- }
121
-
122
- if (title) {
123
- params.title = title
124
- }
125
-
126
- if (titleClasses) {
127
- params.titleClasses = titleClasses
128
- }
129
-
130
- if (width) {
131
- params.width = width
132
- }
133
-
134
- if (cancelButtonLabel) {
135
- params.cancelButtonLabel = cancelButtonLabel
136
- }
137
-
138
- if (confirmButtonLabel) {
139
- params.confirmButtonLabel = confirmButtonLabel
140
- }
141
-
142
- this.showWithParams(params)
143
- },
144
-
145
- }
146
-
147
- Vue.prototype.$unidooCrudTable = {
148
- show(params) {
149
- plugin.EventBus.$emit("unidoo-crud-show", params)
150
- },
151
- }
152
-
153
- Vue.prototype.$unidooHeatmap = {
154
- setDate(date, key) {
155
- plugin.EventBus.$emit("unidoo-heatmap-set-date", { date: date, key: key })
156
- },
157
-
158
- getDate(key) {
159
- plugin.EventBus.$emit("unidoo-heatmap-get-date", { key: key })
33
+ });
34
+ // Register Global event to show AppMessage, related to AppSnackbar
35
+ // https://medium.com/@panzelva/writing-modals-for-vue-js-callable-from-anywhere-6994d180451
36
+ this.EventBus = new Vue();
37
+ Vue.prototype.$unidooAlert = {
38
+ show(params) {
39
+ plugin.EventBus.$emit("unidoo-alert-show", params);
40
+ },
41
+
42
+ defaultParams(params) {
43
+ plugin.EventBus.$emit("unidoo-alert-params", params);
44
+ },
45
+
46
+ showSuccess(message, closeButtonLabel) {
47
+ if (closeButtonLabel) {
48
+ this.showMessage(message, "success", 4000, "top", closeButtonLabel);
49
+ } else {
50
+ this.showMessage(message, "success");
51
+ }
52
+ },
53
+
54
+ showWarning(message, closeButtonLabel) {
55
+ if (closeButtonLabel) {
56
+ this.showMessage(message, "warning", 6000, "top", closeButtonLabel);
57
+ } else {
58
+ this.showMessage(message, "warning", 6000);
59
+ }
60
+ },
61
+
62
+ /**
63
+ * Display the given error message for 8 seconds
64
+ * @param {string} message
65
+ */
66
+ showError(message, closeButtonLabel) {
67
+ if (closeButtonLabel) {
68
+ this.showMessage(message, "error", 8000, "top", closeButtonLabel);
69
+ } else {
70
+ this.showMessage(message, "error", 8000);
71
+ }
72
+ },
73
+
74
+ /**
75
+ * This method return the message from an error object ResponseStatusException or RuntimeException
76
+ * @param {string} prefix e.g. 'An error has occured :'
77
+ * @param {*} error The error object from the catch(function(error)
78
+ * @returns {string} The error message
79
+ */
80
+ formatError(prefix, error) {
81
+ let message = "An error has occured";
82
+ if (typeof error === "object") {
83
+ if (
84
+ error.response &&
85
+ error.response.data &&
86
+ error.response.data.message
87
+ ) {
88
+ message = prefix + " " + error.response.data.message;
89
+ } else if (error.message) {
90
+ message = prefix + " " + error.message;
160
91
  }
161
- }
162
-
163
- Vue.prototype.$unidooDateSwitcher = {
164
- update(data, key) {
165
- plugin.EventBus.$emit("unidoo-dateswitcher-update", { data: data, key: key })
166
- },
167
- }
92
+ }
93
+ return message;
94
+ },
95
+
96
+ showMessage(message, type, timeout, position, closeButtonLabel) {
97
+ const params = {};
98
+ if (position) {
99
+ params.position = position;
100
+ }
101
+
102
+ if (timeout) {
103
+ params.timeout = timeout;
104
+ }
105
+
106
+ if (closeButtonLabel) {
107
+ params.closeButtonLabel = closeButtonLabel;
108
+ }
109
+
110
+ params.message = message;
111
+ params.type = type;
112
+ this.show(params);
113
+ },
114
+ };
115
+
116
+ Vue.prototype.$unidooUuid = {
117
+ randomUuidV4() {
118
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(
119
+ c
120
+ ) {
121
+ var r = (Math.random() * 16) | 0;
122
+ var v = c === "x" ? r : (r & 0x3) | 0x8;
123
+ return v.toString(16);
124
+ });
125
+ },
126
+ };
127
+
128
+ Vue.prototype.$unidooConfirmDialog = {
129
+ showWithParams(params) {
130
+ plugin.EventBus.$emit("unidoo-confirm-dialog-show", params);
131
+ },
132
+
133
+ defaultParams(params) {
134
+ plugin.EventBus.$emit("unidoo-confirm-dialog-params", params);
135
+ },
136
+
137
+ show(
138
+ callback,
139
+ message,
140
+ title,
141
+ titleClasses,
142
+ width,
143
+ cancelButtonLabel,
144
+ confirmButtonLabel
145
+ ) {
146
+ const params = {};
147
+ if (callback) {
148
+ params.callback = callback;
149
+ }
150
+
151
+ if (message) {
152
+ params.message = message;
153
+ }
154
+
155
+ if (title) {
156
+ params.title = title;
157
+ }
158
+
159
+ if (titleClasses) {
160
+ params.titleClasses = titleClasses;
161
+ }
162
+
163
+ if (width) {
164
+ params.width = width;
165
+ }
166
+
167
+ if (cancelButtonLabel) {
168
+ params.cancelButtonLabel = cancelButtonLabel;
169
+ }
170
+
171
+ if (confirmButtonLabel) {
172
+ params.confirmButtonLabel = confirmButtonLabel;
173
+ }
174
+
175
+ this.showWithParams(params);
176
+ },
177
+ };
178
+
179
+ Vue.prototype.$unidooCrudTable = {
180
+ show(params) {
181
+ plugin.EventBus.$emit("unidoo-crud-show", params);
182
+ },
183
+ };
184
+
185
+ Vue.prototype.$unidooHeatmap = {
186
+ setDate(date, key) {
187
+ plugin.EventBus.$emit("unidoo-heatmap-set-date", {
188
+ date: date,
189
+ key: key,
190
+ });
191
+ },
192
+
193
+ getDate(key) {
194
+ plugin.EventBus.$emit("unidoo-heatmap-get-date", { key: key });
195
+ },
196
+ };
197
+
198
+ Vue.prototype.$unidooDateSwitcher = {
199
+ update(data, key) {
200
+ plugin.EventBus.$emit("unidoo-dateswitcher-update", {
201
+ data: data,
202
+ key: key,
203
+ });
204
+ },
205
+ };
168
206
  }
169
207
 
170
208
  // Create module definition for Vue.use()
171
209
  const plugin = {
172
- install
173
- }
210
+ install,
211
+ };
174
212
 
175
213
  // To auto-install when vue is found
176
214
 
177
- let GlobalVue = null
178
- if (typeof window !== 'undefined') {
179
- GlobalVue = window.Vue
180
- } else if (typeof global !== 'undefined') {
181
- GlobalVue = global.Vue
215
+ let GlobalVue = null;
216
+ if (typeof window !== "undefined") {
217
+ GlobalVue = window.Vue;
218
+ } else if (typeof global !== "undefined") {
219
+ GlobalVue = global.Vue;
182
220
  }
183
221
  if (GlobalVue) {
184
- GlobalVue.use(plugin)
222
+ GlobalVue.use(plugin);
185
223
  }
186
224
 
187
225
  const requireComponent = require.context(
188
- // Look for files in the current directory
189
- './components',
190
- // Look in subdirectories
191
- true,
192
- // Only include "_base-" prefixed .vue files
193
- /[\w-]+\.vue$/
194
- )
226
+ // Look for files in the current directory
227
+ "./components",
228
+ // Look in subdirectories
229
+ true,
230
+ // Only include "_base-" prefixed .vue files
231
+ /[\w-]+\.vue$/
232
+ );
195
233
 
196
234
  // Default export is library as a whole, registered via Vue.use()
197
- export default plugin
235
+ export default plugin;
198
236
 
199
237
  // To allow individual component use, export components
200
238
  // each can be registered via Vue.component()
201
239
  // console.log({components})
202
- // export {components}
240
+ // export {components}