goodteditor-ui 1.0.14 → 1.0.16

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "goodteditor-ui",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "main": "index.js",
5
5
  "homepage": "https://goodt-ui.netlify.app/",
6
6
  "scripts": {
@@ -10,7 +10,8 @@
10
10
  "dev": "vue-styleguidist server",
11
11
  "docs:build": "set NODE_ENV=development && vue-styleguidist build",
12
12
  "docs:deploy": "npx netlify deploy --dir=docs --prod",
13
- "notify": "node ./ci/teams-notify.js"
13
+ "notify": "node ./ci/teams-notify.js",
14
+ "publish": "npm run docs:build && npm run docs:deploy && npm run notify"
14
15
  },
15
16
  "devDependencies": {
16
17
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
@@ -197,25 +197,30 @@ export default {
197
197
  readonly: this.readonly || !this.editable,
198
198
  },
199
199
  inputEvents: {
200
+ input: this.onInputInput,
200
201
  change: this.onInputChange,
201
202
  focus: this.onInputFocus,
202
203
  blur: this.onInputBlur,
203
204
  },
205
+ inputValue: '',
206
+ inputValueRaw: '',
204
207
  };
205
208
  },
206
209
  watch: {
207
210
  value: {
208
211
  handler(val) {
212
+ this.inputValueRaw = val;
213
+
209
214
  if (this.isRange) {
210
- let d = Array.isArray(val) ? val.map(this.toDate) : [];
211
- let [s, e] = d;
215
+ const d = Array.isArray(val) ? val.map(this.toDate) : [];
216
+ const [s, e] = d;
212
217
  if (s && e && isDateValid(s) && isDateValid(e) && s < e) {
213
218
  this.date = d;
214
219
  } else {
215
220
  this.date = [];
216
221
  }
217
222
  } else {
218
- let d = this.toDate(val);
223
+ const d = this.toDate(val);
219
224
  this.date = isDateValid(d) ? d : null;
220
225
  }
221
226
  },
@@ -256,47 +261,31 @@ export default {
256
261
  let input = this.getInputRef();
257
262
  input && input.focus();
258
263
  },
264
+ onInputInput({ target }) {
265
+ this.inputValueRaw = target.value;
266
+ },
259
267
  onInputChange(e) {
260
- let val = e.target.value;
261
- let data = null;
262
-
263
- if (this.isRange) {
264
- let d = val.split(this.delimiter).map(this.toDate);
265
- let [s, e] = d;
266
- data = isDateValid(s) && isDateValid(e) && s < e ? d.map(this.toValue) : [];
267
- } else {
268
- let d = this.toDate(val);
269
- data = isDateValid(d) ? this.toValue(d) : '';
270
- }
271
- /**
272
- * Input event
273
- * @property {String|Array} value
274
- */
275
- this.$emit('input', data);
276
- /**
277
- * Change event
278
- * @property {String|Array} value
279
- */
280
- this.$emit('change', data);
268
+ this.setDateFromString(e.target.value);
281
269
  },
282
270
  onInputFocus(e) {
283
271
  this.rootHasFocus = true;
284
272
  },
285
273
  onInputBlur(e) {
286
274
  this.rootHasFocus = false;
275
+ this.setDateFromString(this.inputValueRaw);
287
276
  },
288
277
  onDpChange(date) {
289
- let data = Array.isArray(date) ? date.map(this.toValue) : this.toValue(date);
278
+ const model = Array.isArray(date) ? date.map(this.toValue) : this.toValue(date);
290
279
  /**
291
280
  * Input event
292
- * @property {String} date
281
+ * @property {String|Array} value
293
282
  */
294
- this.$emit('input', data);
283
+ this.$emit('input', model);
295
284
  /**
296
285
  * Change event
297
- * @property {String} date
286
+ * @property {String|Array} value
298
287
  */
299
- this.$emit('change', data);
288
+ this.$emit('change', model);
300
289
  },
301
290
  onDpSetDate(date) {
302
291
  /**
@@ -305,6 +294,33 @@ export default {
305
294
  */
306
295
  this.$emit('set-date', date);
307
296
  },
297
+ setDateFromString(value) {
298
+ if (value == this.inputValue) {
299
+ return;
300
+ }
301
+ this.inputValue = value;
302
+
303
+ let model = null;
304
+
305
+ if (this.isRange) {
306
+ const d = value.split(this.delimiter).map(this.toDate);
307
+ const [s, e] = d;
308
+ model = isDateValid(s) && isDateValid(e) && s < e ? d.map(this.toValue) : [];
309
+ } else {
310
+ const d = this.toDate(value);
311
+ model = isDateValid(d) ? this.toValue(d) : '';
312
+ }
313
+ /**
314
+ * Input event
315
+ * @property {String|Array} value
316
+ */
317
+ this.$emit('input', model);
318
+ /**
319
+ * Change event
320
+ * @property {String|Array} value
321
+ */
322
+ this.$emit('change', model);
323
+ },
308
324
  },
309
325
  };
310
326
  </script>
@@ -23,6 +23,19 @@ import { Position, generateGetBoundingClientRect } from './utils/Helpers';
23
23
 
24
24
  const isElem = el => el instanceof HTMLElement;
25
25
 
26
+ const isCoordinates = (target) => {
27
+ if (Array.isArray(target) === false) {
28
+ return false;
29
+ }
30
+ if (target.length !== 2) {
31
+ return false;
32
+ }
33
+ if (target.some((item) => Number.isNaN(Number(item)))) {
34
+ return false;
35
+ }
36
+ return true;
37
+ }
38
+
26
39
  const Strategy = Object.freeze({
27
40
  ABSOLUTE: 'absolute',
28
41
  FIXED: 'fixed'
@@ -51,7 +64,7 @@ export default {
51
64
  },
52
65
  props: {
53
66
  /**
54
- * Target HTMLElement or selector used for positioning
67
+ * Target HTMLElement|selector|array of coordinates used for positioning
55
68
  */
56
69
  target: { default: null },
57
70
  /**
@@ -107,25 +120,11 @@ export default {
107
120
  default: false,
108
121
  },
109
122
  /**
110
- * Should follow the cursor
111
- */
112
- shouldFollowCursor: {
113
- type: Boolean,
114
- default: false
115
- },
116
- /**
117
- * Cursor coordinates [ x, y ]
118
- */
119
- cursorCoordinates: {
120
- type: Array,
121
- default: () => [0, 0]
122
- },
123
- /**
124
- * Whether handle events to control visibility
123
+ * Should respond to pointer events
125
124
  */
126
- isManualControlMode: {
125
+ shouldRespondToPointerEvents: {
127
126
  type: Boolean,
128
- default: false
127
+ default: true
129
128
  }
130
129
  },
131
130
  data() {
@@ -172,7 +171,7 @@ export default {
172
171
  return;
173
172
  }
174
173
 
175
- if (this.isManualControlMode === false) {
174
+ if (isCoordinates(this.target) === false) {
176
175
  this.addEventListeners();
177
176
  }
178
177
 
@@ -198,46 +197,51 @@ export default {
198
197
  document.removeEventListener('mousedown', this.onDocMouseDown);
199
198
  },
200
199
  calcStyle() {
201
- const { zIndex, autoWidth } = this;
200
+ const { zIndex, autoWidth, shouldRespondToPointerEvents } = this;
202
201
  const target = this.getTarget();
203
202
  const style = { zIndex };
204
203
  if (autoWidth && target) {
205
204
  const b = target.getBoundingClientRect();
206
205
  style.width = `${b.width}px`;
207
206
  }
207
+ if (shouldRespondToPointerEvents === false) {
208
+ style.pointerEvents = 'none';
209
+ }
208
210
  this.cssStyle = style;
209
211
  },
210
212
  getTarget() {
211
- let { target } = this;
212
- return isElem(target) ? target : document.querySelector(target);
213
+ const { target } = this;
214
+ return isCoordinates(target) ? null : isElem(target) ? target : document.querySelector(target);
213
215
  },
214
216
  setShow(val) {
215
217
  this.$nextTick(() => this.$emit('update:show', val));
216
218
  },
217
219
  createPopper() {
218
- const { shouldFollowCursor, options, $el: popper, cursorCoordinates } = this;
220
+ const { options, $el: popper } = this;
219
221
  const target = this.getTarget();
220
222
 
221
- if (shouldFollowCursor) {
222
- const [x, y] = cursorCoordinates;
223
+ if (target != null) {
224
+ this.popper = createPopper(target, popper, options);
225
+ this.$nextTick(this.updatePopper);
226
+ return;
227
+ }
228
+
229
+ if (isCoordinates(this.target)) {
230
+ const [x, y] = this.target;
223
231
  const virtualElem = {
224
232
  getBoundingClientRect: generateGetBoundingClientRect(x, y),
225
- contextElement: target
226
- }
227
-
233
+ };
228
234
  this.popper = createPopper(virtualElem, popper, options);
229
- this.unwatchCursorCoordinates = this.$watch('cursorCoordinates', ([x, y]) => {
235
+ this.$nextTick(this.updatePopper);
236
+ this.unwatchCursorCoordinates = this.$watch('target', ([x, y]) => {
230
237
  virtualElem.getBoundingClientRect = generateGetBoundingClientRect(x, y);
231
238
  this.popper?.update();
232
- })
233
- } else {
234
- this.popper = createPopper(target, popper, options);
239
+ });
235
240
  }
236
-
237
- this.$nextTick(() => {
238
- this.calcStyle();
239
- this.popper.update();
240
- });
241
+ },
242
+ updatePopper() {
243
+ this.calcStyle();
244
+ this.popper.update();
241
245
  },
242
246
  destroyPopper() {
243
247
  this.popper?.destroy();
@@ -245,7 +249,7 @@ export default {
245
249
  },
246
250
  handleReset() {
247
251
  this.unwatchCursorCoordinates?.();
248
- if (this.isManualControlMode === false) {
252
+ if (isCoordinates(this.target) === false) {
249
253
  this.removeEventListeners();
250
254
  }
251
255
  this.destroyPopper();