@milaboratories/uikit 2.3.8 → 2.3.10

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 (35) hide show
  1. package/.turbo/turbo-build.log +21 -19
  2. package/.turbo/turbo-type-check.log +1 -1
  3. package/CHANGELOG.md +14 -0
  4. package/dist/components/PlAutocomplete/PlAutocomplete.vue.js +1 -1
  5. package/dist/components/PlDropdown/PlDropdown.vue.js +1 -1
  6. package/dist/components/PlDropdownLegacy/PlDropdownLegacy.vue.js +1 -1
  7. package/dist/components/PlDropdownMulti/PlDropdownMulti.vue.js +1 -1
  8. package/dist/components/PlFileInput/PlFileInput.vue.js +1 -1
  9. package/dist/components/PlNumberField/PlNumberField.vue.d.ts.map +1 -1
  10. package/dist/components/PlNumberField/PlNumberField.vue.js +75 -70
  11. package/dist/components/PlNumberField/PlNumberField.vue.js.map +1 -1
  12. package/dist/components/PlTextArea/PlTextArea.vue.js +1 -1
  13. package/dist/components/PlTextField/PlTextField.vue.js +1 -1
  14. package/dist/composition/computedCached.d.ts +12 -0
  15. package/dist/composition/computedCached.d.ts.map +1 -0
  16. package/dist/composition/computedCached.js +24 -0
  17. package/dist/composition/computedCached.js.map +1 -0
  18. package/dist/composition/watchCached.d.ts +9 -0
  19. package/dist/composition/watchCached.d.ts.map +1 -0
  20. package/dist/composition/watchCached.js +31 -0
  21. package/dist/composition/watchCached.js.map +1 -0
  22. package/dist/generated/components/svg/images/{SvgRequired.vue2.js → SvgRequired.vue.js} +1 -1
  23. package/dist/generated/components/svg/images/SvgRequired.vue.js.map +1 -0
  24. package/dist/index.d.ts +2 -0
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +45 -41
  27. package/dist/index.js.map +1 -1
  28. package/dist/sdk/model/dist/index.js +1 -1
  29. package/dist/sdk/model/dist/index.js.map +1 -1
  30. package/package.json +2 -2
  31. package/src/components/PlNumberField/PlNumberField.vue +10 -2
  32. package/src/composition/computedCached.ts +58 -0
  33. package/src/composition/watchCached.ts +45 -0
  34. package/src/index.ts +2 -0
  35. package/dist/generated/components/svg/images/SvgRequired.vue2.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milaboratories/uikit",
3
- "version": "2.3.8",
3
+ "version": "2.3.10",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "exports": {
@@ -24,7 +24,7 @@
24
24
  "d3": "^7.9.0",
25
25
  "resize-observer-polyfill": "^1.5.1",
26
26
  "@milaboratories/helpers": "^1.6.17",
27
- "@platforma-sdk/model": "^1.39.18"
27
+ "@platforma-sdk/model": "^1.40.0"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@vitejs/plugin-vue": "^5.2.3",
@@ -152,6 +152,10 @@ const isDecrementDisabled = computed(() => {
152
152
  return false;
153
153
  });
154
154
 
155
+ const multiplier = computed(() =>
156
+ 10 ** (props.step.toString().split('.').at(1)?.length ?? 0),
157
+ );
158
+
155
159
  function increment() {
156
160
  const parsedValue = innerNumberValue.value;
157
161
  if (!isIncrementDisabled.value) {
@@ -159,7 +163,9 @@ function increment() {
159
163
  if (parsedValue === undefined) {
160
164
  nV = props.minValue ? props.minValue : 0;
161
165
  } else {
162
- nV = (parsedValue || 0) + props.step;
166
+ nV = ((parsedValue || 0) * multiplier.value
167
+ + props.step * multiplier.value)
168
+ / multiplier.value;
163
169
  }
164
170
  modelValue.value = props.maxValue !== undefined ? Math.min(props.maxValue, nV) : nV;
165
171
  }
@@ -172,7 +178,9 @@ function decrement() {
172
178
  if (parsedValue === undefined) {
173
179
  nV = 0;
174
180
  } else {
175
- nV = +(parsedValue || 0) - props.step;
181
+ nV = ((parsedValue || 0) * multiplier.value
182
+ - props.step * multiplier.value)
183
+ / multiplier.value;
176
184
  }
177
185
  modelValue.value = props.minValue !== undefined ? Math.max(props.minValue, nV) : nV;
178
186
  }
@@ -0,0 +1,58 @@
1
+ import { isJsonEqual } from '@milaboratories/helpers';
2
+ import {
3
+ computed,
4
+ ref,
5
+ watch,
6
+ type ComputedGetter,
7
+ type ComputedSetter,
8
+ type ComputedRef,
9
+ type WritableComputedRef,
10
+ } from 'vue';
11
+
12
+ export function computedCached<T>(options: {
13
+ get: ComputedGetter<T>;
14
+ set: ComputedSetter<T>;
15
+ deep?: boolean;
16
+ }): WritableComputedRef<T>;
17
+ export function computedCached<T>(options: {
18
+ get: ComputedGetter<T>;
19
+ deep?: boolean;
20
+ }): ComputedRef<T>;
21
+ export function computedCached<T>(getter: ComputedGetter<T>): ComputedRef<T>;
22
+ export function computedCached<T>(options: ComputedGetter<T> | {
23
+ get: ComputedGetter<T>;
24
+ set?: ComputedSetter<T>;
25
+ deep?: boolean;
26
+ }) {
27
+ if (typeof options === 'function') {
28
+ options = {
29
+ get: options,
30
+ };
31
+ }
32
+ const { get: getter, set: setter, deep } = options;
33
+
34
+ const cachedValue = ref<T>(getter());
35
+ watch(
36
+ getter,
37
+ (newValue) => {
38
+ if (!isJsonEqual(newValue, cachedValue.value)) {
39
+ cachedValue.value = newValue;
40
+ }
41
+ },
42
+ { deep },
43
+ );
44
+
45
+ if (setter) {
46
+ return computed({
47
+ get: () => cachedValue.value,
48
+ set: (newValue) => {
49
+ if (!isJsonEqual(newValue, cachedValue.value)) {
50
+ cachedValue.value = newValue;
51
+ setter(newValue);
52
+ }
53
+ },
54
+ });
55
+ } else {
56
+ return computed(() => cachedValue.value);
57
+ }
58
+ }
@@ -0,0 +1,45 @@
1
+ import { isJsonEqual } from '@milaboratories/helpers';
2
+ import {
3
+ ref,
4
+ watch,
5
+ type WatchCallback,
6
+ type WatchHandle,
7
+ type WatchSource,
8
+ } from 'vue';
9
+
10
+ type MaybeUndefined<T, I> = I extends true ? T | undefined : T;
11
+ export interface WatchCachedOptions<Immediate = boolean> {
12
+ immediate?: Immediate;
13
+ deep?: boolean;
14
+ // when `once` is needed, caching is useless, use plain watch instead
15
+ }
16
+ export function watchCached<T, Immediate extends Readonly<boolean> = false>(
17
+ source: WatchSource<T>,
18
+ cb: WatchCallback<T, MaybeUndefined<T, Immediate>>,
19
+ options?: WatchCachedOptions<Immediate>,
20
+ ): WatchHandle {
21
+ const cachedValue = ref<T>();
22
+ const handle = watch(
23
+ source,
24
+ (newValue) => {
25
+ if (!isJsonEqual(newValue, cachedValue.value)) {
26
+ cachedValue.value = newValue;
27
+ }
28
+ },
29
+ {
30
+ deep: options?.deep,
31
+ immediate: true, // always initialize cachedValue
32
+ },
33
+ );
34
+ watch<T, Immediate>(
35
+ () => cachedValue.value as T, // `as T` is safe as we always initialize cachedValue
36
+ cb, // separate watch so that `onWatcherCleanup` would only be triggerred here
37
+ {
38
+ // standard vue `WatchOptions` conform to `WatchCachedOptions` interface,
39
+ // so construct new options to remove unsupported entries
40
+ deep: options?.deep,
41
+ immediate: options?.immediate,
42
+ },
43
+ );
44
+ return handle; // stopping first handle would effectively stop the second one
45
+ }
package/src/index.ts CHANGED
@@ -110,6 +110,8 @@ export { useQuery } from './composition/useQuery.ts';
110
110
  export { useDraggable } from './composition/useDraggable';
111
111
  export { useComponentProp } from './composition/useComponentProp';
112
112
  export * from './composition/useWatchFetch';
113
+ export * from './composition/watchCached';
114
+ export * from './composition/computedCached';
113
115
 
114
116
  /**
115
117
  * Utils/Partials
@@ -1 +0,0 @@
1
- {"version":3,"file":"SvgRequired.vue2.js","sources":["../../../../../src/generated/components/svg/images/SvgRequired.vue"],"sourcesContent":["<!-- ⚠️ AUTOGENERATED. DO NOT EDIT. -->\n<script lang=\"ts\">\nimport '../svg-styles.css';\nexport default { name: 'SvgRequired' };\n</script>\n\n<template>\n <div class=\"svg-icon SvgRequired\" style=\"width: 5px; height: 12px\" />\n</template>\n\n<style>\n .SvgRequired { background-image: url(\"data:image/svg+xml;utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%225%22%20height%3D%2212%22%20viewBox%3D%220%200%205%2012%22%20fill%3D%22none%22%3E%3Cpath%20d%3D%22M1.51685%204.8L2.5%203.34159L3.47612%204.8L4.39607%204.12743L3.31461%202.7469L5%202.25133L4.64888%201.16106L3.00562%201.77699L3.06882%200H1.93118L1.99438%201.77699L0.351124%201.16106L0%202.25133L1.68539%202.7469L0.59691%204.12743L1.51685%204.8Z%22%20fill%3D%22%23F1222F%22%2F%3E%3C%2Fsvg%3E\"); }\n</style>\n"],"names":["_hoisted_1"],"mappings":";;;;AAOoC,MAAAA,IAAA;AAAA,EAAA,OAAA;AAAA;;;;;;"}