yummies 4.11.0 → 4.12.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.
@@ -0,0 +1,7 @@
1
+ import type { AnyObject } from '../utils/types.js';
2
+ export declare class DeepObservableStruct<TData extends AnyObject> {
3
+ data: TData;
4
+ constructor(data: TData);
5
+ set(newData: Partial<TData>): void;
6
+ }
7
+ //# sourceMappingURL=deep-observable-struct.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep-observable-struct.d.ts","sourceRoot":"","sources":["../../src/mobx/deep-observable-struct.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,qBAAa,oBAAoB,CAAC,KAAK,SAAS,SAAS;IACvD,IAAI,EAAE,KAAK,CAAC;gBAEA,IAAI,EAAE,KAAK;IASvB,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC;CAoD5B"}
@@ -0,0 +1,57 @@
1
+ import { action, makeObservable, observable } from 'mobx';
2
+ import { typeGuard } from '../type-guard/index.js';
3
+ export class DeepObservableStruct {
4
+ data;
5
+ constructor(data) {
6
+ this.data = data;
7
+ makeObservable(this, {
8
+ data: observable.deep,
9
+ set: action,
10
+ });
11
+ }
12
+ set(newData) {
13
+ const stack = Object.keys(this.data).map((key) => [
14
+ key,
15
+ this.data,
16
+ newData,
17
+ ]);
18
+ let currentIndex = 0;
19
+ let stackLength = stack.length;
20
+ while (currentIndex < stackLength) {
21
+ const [key, currObservableData, newData] = stack[currentIndex];
22
+ const newValue = newData[key];
23
+ const currValue = currObservableData[key];
24
+ currentIndex++;
25
+ if (key in newData) {
26
+ if (typeGuard.isObject(newValue) && typeGuard.isObject(currValue)) {
27
+ const newValueKeys = Object.keys(newValue);
28
+ Object.keys(currValue).forEach((childKey) => {
29
+ if (!(childKey in newValue)) {
30
+ delete currObservableData[key][childKey];
31
+ }
32
+ });
33
+ newValueKeys.forEach((childKey) => {
34
+ const length = stack.push([
35
+ childKey,
36
+ currObservableData[key],
37
+ newValue,
38
+ ]);
39
+ stackLength = length;
40
+ });
41
+ }
42
+ else if (newValue !== currValue) {
43
+ currObservableData[key] = newValue;
44
+ }
45
+ }
46
+ else {
47
+ delete currObservableData[key];
48
+ }
49
+ }
50
+ Object.keys(newData).forEach((newDataKey) => {
51
+ if (!this.data[newDataKey]) {
52
+ // @ts-ignore
53
+ this.data[newDataKey] = newData[newDataKey];
54
+ }
55
+ });
56
+ }
57
+ }
@@ -0,0 +1,4 @@
1
+ import { type ObservableObjectAdministration } from 'mobx/dist/internal.js';
2
+ import type { AnyObject } from '../utils/types.js';
3
+ export declare const getMobxAdministration: (context: AnyObject) => ObservableObjectAdministration;
4
+ //# sourceMappingURL=get-mobx-administration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-mobx-administration.d.ts","sourceRoot":"","sources":["../../src/mobx/get-mobx-administration.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,8BAA8B,EACpC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,eAAO,MAAM,qBAAqB,GAChC,SAAS,SAAS,KACjB,8BAAgD,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { $mobx, } from 'mobx/dist/internal.js';
2
+ export const getMobxAdministration = (context) => context[$mobx];
@@ -0,0 +1,4 @@
1
+ export * from './deep-observable-struct.js';
2
+ export * from './get-mobx-administration.js';
3
+ export * from './lazy-observe.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mobx/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC"}
package/mobx/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './deep-observable-struct.js';
2
+ export * from './get-mobx-administration.js';
3
+ export * from './lazy-observe.js';
@@ -0,0 +1,8 @@
1
+ export declare const lazyObserve: <TMetaData = void>({ context, property, onStart, onEnd, endDelay, }: {
2
+ context: any;
3
+ property: any | any[];
4
+ onStart: () => TMetaData;
5
+ onEnd: (metaData: TMetaData, cleanupFn: VoidFunction) => void;
6
+ endDelay?: number;
7
+ }) => () => void;
8
+ //# sourceMappingURL=lazy-observe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lazy-observe.d.ts","sourceRoot":"","sources":["../../src/mobx/lazy-observe.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,GAAI,SAAS,GAAG,IAAI,EAAE,kDAM3C;IACD,OAAO,EAAE,GAAG,CAAC;IACb,QAAQ,EAAE,GAAG,GAAG,GAAG,EAAE,CAAC;IACtB,OAAO,EAAE,MAAM,SAAS,CAAC;IACzB,KAAK,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,KAAK,IAAI,CAAC;IAC9D,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,eAsCA,CAAC"}
@@ -0,0 +1,36 @@
1
+ import { onBecomeObserved, onBecomeUnobserved } from 'mobx';
2
+ export const lazyObserve = ({ context, property, onStart, onEnd, endDelay = 0, }) => {
3
+ let timeoutId;
4
+ let metaData;
5
+ const properties = Array.isArray(property) ? property : [property];
6
+ let isObserving = false;
7
+ const cleanup = () => {
8
+ if (!isObserving) {
9
+ return;
10
+ }
11
+ if (timeoutId) {
12
+ clearTimeout(timeoutId);
13
+ timeoutId = undefined;
14
+ }
15
+ timeoutId = setTimeout(() => {
16
+ onEnd(metaData, cleanup);
17
+ timeoutId = undefined;
18
+ metaData = undefined;
19
+ }, endDelay);
20
+ };
21
+ properties.forEach((property) => {
22
+ onBecomeObserved(context, property, () => {
23
+ if (isObserving) {
24
+ return;
25
+ }
26
+ isObserving = true;
27
+ if (timeoutId) {
28
+ clearTimeout(timeoutId);
29
+ timeoutId = undefined;
30
+ }
31
+ metaData = onStart();
32
+ });
33
+ onBecomeUnobserved(context, property, cleanup);
34
+ });
35
+ return cleanup;
36
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yummies",
3
- "version": "4.11.0",
3
+ "version": "4.12.0",
4
4
  "keywords": [],
5
5
  "author": "js2me",
6
6
  "license": "MIT",
@@ -14,6 +14,14 @@
14
14
  "type": "git",
15
15
  "url": "git://github.com/js2me/yummies"
16
16
  },
17
+ "peerDependencies": {
18
+ "mobx": "^6.12.4"
19
+ },
20
+ "peerDependenciesMeta": {
21
+ "mobx": {
22
+ "optional": true
23
+ }
24
+ },
17
25
  "dependencies": {
18
26
  "@types/insane": "^1.0.0",
19
27
  "class-variance-authority": "^0.7.1",
@@ -186,6 +194,31 @@
186
194
  "default": "./media.js",
187
195
  "types": "./media.d.ts"
188
196
  },
197
+ "./mobx/deep-observable-struct.test": {
198
+ "import": "./mobx/deep-observable-struct.test.js",
199
+ "default": "./mobx/deep-observable-struct.test.js",
200
+ "types": "./mobx/deep-observable-struct.test.d.ts"
201
+ },
202
+ "./mobx/deep-observable-struct": {
203
+ "import": "./mobx/deep-observable-struct.js",
204
+ "default": "./mobx/deep-observable-struct.js",
205
+ "types": "./mobx/deep-observable-struct.d.ts"
206
+ },
207
+ "./mobx/get-mobx-administration": {
208
+ "import": "./mobx/get-mobx-administration.js",
209
+ "default": "./mobx/get-mobx-administration.js",
210
+ "types": "./mobx/get-mobx-administration.d.ts"
211
+ },
212
+ "./mobx": {
213
+ "import": "./mobx/index.js",
214
+ "default": "./mobx/index.js",
215
+ "types": "./mobx/index.d.ts"
216
+ },
217
+ "./mobx/lazy-observe": {
218
+ "import": "./mobx/lazy-observe.js",
219
+ "default": "./mobx/lazy-observe.js",
220
+ "types": "./mobx/lazy-observe.d.ts"
221
+ },
189
222
  "./ms": {
190
223
  "import": "./ms.js",
191
224
  "default": "./ms.js",
@@ -1 +1 @@
1
- {"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../src/parser/number.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C,MAAM,WAAW,oBAAoB,CAAC,SAAS,GAAG,MAAM;IACtD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;CACtD;AAED,eAAO,MAAM,MAAM;KAAI,SAAS,kBACvB,KAAK,CAAC,OAAO,CAAC,iBACN,KAAK,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAC,GACpD,MAAM,GAAG,SAAS;;CA2CpB,CAAC"}
1
+ {"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../src/parser/number.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C,MAAM,WAAW,oBAAoB,CAAC,SAAS,GAAG,MAAM;IACtD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;CACtD;AAED,eAAO,MAAM,MAAM;KAAI,SAAS,kBACvB,KAAK,CAAC,OAAO,CAAC,iBACN,KAAK,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAC,GACpD,MAAM,GAAG,SAAS;;CA+CpB,CAAC"}
package/parser/number.js CHANGED
@@ -5,13 +5,19 @@ export const number = (input, userSettings) => {
5
5
  ...number.defaultSettings,
6
6
  ...userSettings,
7
7
  };
8
- const fallback = settings && 'fallback' in settings ? settings.fallback : 0;
8
+ const fallback = settings?.fallback ?? 0;
9
9
  let result;
10
10
  if (typeGuard.isNumber(input)) {
11
11
  result = input;
12
12
  }
13
13
  else if (typeGuard.isString(input)) {
14
- result = Number(skipSpaces(input).replace(',', '.'));
14
+ const formattedInput = skipSpaces(input).replace(',', '.');
15
+ if (formattedInput === '') {
16
+ result = fallback;
17
+ }
18
+ else {
19
+ result = Number(formattedInput);
20
+ }
15
21
  }
16
22
  else {
17
23
  result = fallback;