aprog 2.2.1 → 2.2.3

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/index.js CHANGED
@@ -15,10 +15,11 @@ export { cookie, storage, session, cacheKey, downloadFile } from './src/storage.
15
15
  export { paginate, parseData, __paginate, __counter } from './src/paginate.js';
16
16
  export { saveItem, loadItem, setSecretKey } from './src/secretStorage.js';
17
17
  export {
18
- pushHTMLElementPrototype, pushAfterHTMLElementPrototype,
19
- pushBeforeHTMLElementPrototype, dataHTMLElementPrototype,
20
- toKebabCaseStringPrototype, toSnakeCaseStringPrototype,
21
- repeatHTMLElementPrototype
18
+ pushHTMLElementPrototype, prepushHTMLElementPrototype,
19
+ pushAfterHTMLElementPrototype, pushBeforeHTMLElementPrototype,
20
+ dataHTMLElementPrototype, toKebabCaseStringPrototype,
21
+ toSnakeCaseStringPrototype, repeatHTMLElementPrototype,
22
+ replaceChildrenHTMLElementPrototype
22
23
  } from './src/html.js';
23
24
  export { prism } from "./src/prism.js";
24
25
  export { uniquePage } from "./src/pages.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aprog",
3
- "version": "2.2.1",
3
+ "version": "2.2.3",
4
4
  "description": "Допоміжна JavaScript-бібліотека для проєктів",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -4,55 +4,53 @@ class StateWrapper {
4
4
  constructor(initialValue) {
5
5
  this.#value = initialValue;
6
6
 
7
- return new Proxy(this, {
8
- get: (target, prop) => {
7
+ const handler = {
8
+ get: (target, prop, receiver) => {
9
+ if (prop === 'val') return target.#value;
10
+
9
11
  if (prop === 'set') {
10
12
  return (newValue) => {
11
- target.#value = typeof newValue === 'function'
12
- ? newValue(target.#value)
13
- : newValue;
13
+ target.#value = typeof newValue === 'function' ? newValue(target.#value) : newValue;
14
14
  };
15
15
  }
16
16
 
17
- if (prop === 'value') {
18
- return target.#value;
17
+ if (prop === 'merge') {
18
+ return (patch) => {
19
+ if (typeof target.#value === 'object' && target.#value !== null) {
20
+ target.#value = { ...target.#value, ...patch };
21
+ }
22
+ };
19
23
  }
20
24
 
21
- if (typeof target.#value === 'object' && target.#value !== null && prop in target.#value) {
25
+ if (prop === 'toJSON') return () => target.#value;
26
+ if (prop === 'toString') return () => String(target.#value);
27
+ if (prop === 'valueOf') return () => target.#value;
28
+
29
+ if (
30
+ typeof target.#value === 'object' &&
31
+ target.#value !== null &&
32
+ prop in target.#value
33
+ ) {
22
34
  return target.#value[prop];
23
35
  }
24
36
 
25
- return Reflect.get(target, prop);
37
+ return Reflect.get(target, prop, receiver);
26
38
  },
27
39
 
28
- set: (target, prop, val) => {
40
+ set: (target, prop, newVal) => {
29
41
  if (typeof target.#value === 'object' && target.#value !== null) {
30
- target.#value[prop] = val;
42
+ target.#value[prop] = newVal;
31
43
  return true;
32
44
  }
33
45
  return false;
34
46
  },
47
+ };
35
48
 
36
- apply: (_, __, ___) => {
37
- return target.#value;
38
- },
39
-
40
- getPrototypeOf: (target) => {
41
- return Object.getPrototypeOf(target.#value);
42
- },
43
-
44
- has: (target, key) => {
45
- return key in target.#value;
46
- },
47
-
48
- ownKeys: (target) => {
49
- return Reflect.ownKeys(target.#value);
50
- },
49
+ return new Proxy(this, handler);
50
+ }
51
51
 
52
- getOwnPropertyDescriptor: (target, key) => {
53
- return Object.getOwnPropertyDescriptor(target.#value, key);
54
- }
55
- });
52
+ valueOf() {
53
+ return this.#value;
56
54
  }
57
55
  }
58
56
 
@@ -25,6 +25,7 @@ export const ButtonConstructor = {
25
25
  type = undefined,
26
26
  text = "",
27
27
  callback = () => {},
28
+ ...props
28
29
  } = {}) {
29
30
  return this.is = button({
30
31
  id: id || GUID(),
@@ -32,7 +33,8 @@ export const ButtonConstructor = {
32
33
  style: style,
33
34
  ...(type && {type: type}),
34
35
  value: text,
35
- onClick: callback
36
+ onClick: callback,
37
+ ...props
36
38
  });
37
39
  },
38
40
 
@@ -28,17 +28,21 @@ export const InputConstructor = {
28
28
  value = undefined,
29
29
  nameCallback = "onInput",
30
30
  callback = () => {},
31
+ ...props
31
32
  } = {}) {
32
- return this.is = input({
33
+ this.is = input({
33
34
  id: id || GUID(),
34
35
  class: `${this.class} input ${className}`.trim(),
35
36
  style: style,
36
37
  ...(type && {type: type}),
37
- focus: focus,
38
38
  ...(placeholder && {placeholder: placeholder}),
39
39
  ...(value && {value: value}),
40
40
  [nameCallback]: callback,
41
+ ...props
41
42
  });
43
+
44
+ if (focus) queueMicrotask(() => this.is.focus());
45
+ return this.is;
42
46
  },
43
47
 
44
48
  /**
@@ -25,6 +25,7 @@ export const SelectConstructor = {
25
25
  option = undefined,
26
26
  options = undefined,
27
27
  callback = () => {},
28
+ ...props
28
29
  } = {}) {
29
30
  return this.is = select({
30
31
  id: id || GUID(),
@@ -33,6 +34,7 @@ export const SelectConstructor = {
33
34
  ...(option && {option: option}),
34
35
  ...(options && {options: options}),
35
36
  onChange: callback,
37
+ ...props
36
38
  });
37
39
  },
38
40
 
package/src/html.js CHANGED
@@ -7,6 +7,15 @@ export function pushHTMLElementPrototype() {
7
7
  }
8
8
  }
9
9
 
10
+ export function prepushHTMLElementPrototype() {
11
+ if (!HTMLElement.prototype.prepush) {
12
+ HTMLElement.prototype.prepush = function(element) {
13
+ this.innerHTML = null;
14
+ this.prepend(element);
15
+ };
16
+ }
17
+ }
18
+
10
19
  export function pushAfterHTMLElementPrototype() {
11
20
  if (!HTMLElement.prototype.pushAfter) {
12
21
  HTMLElement.prototype.pushAfter = function (element, existingChild) {