native-document 1.0.151 → 1.0.152
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/cdn.js +4 -0
- package/components.js +1 -0
- package/dist/native-document.components.min.js +1422 -1667
- package/dist/native-document.dev.js +839 -1092
- package/dist/native-document.dev.js.map +1 -1
- package/dist/native-document.min.js +1 -1
- package/elements.js +5 -0
- package/index.js +3 -2
- package/package.json +1 -1
- package/src/components/BaseComponent.js +2 -6
- package/src/components/dropdown/helpers.js +2 -1
- package/src/core/data/ObservableItem.js +0 -113
- package/src/core/data/observable-helpers/observable.prototypes.js +119 -0
- package/src/core/utils/validator.js +4 -6
- package/src/core/wrappers/ElementCreator.js +0 -9
- package/src/core/wrappers/NDElement.js +3 -3
- package/src/core/wrappers/prototypes/nd-element-extensions.js +3 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates an ObservableWhen that represents whether the observable equals a specific value.
|
|
3
|
+
* Returns an object that can be subscribed to and will emit true/false.
|
|
4
|
+
*
|
|
5
|
+
* @param {*} value - The value to compare against
|
|
6
|
+
* @returns {ObservableWhen} An ObservableWhen instance that tracks when the observable equals the value
|
|
7
|
+
* @example
|
|
8
|
+
* const status = Observable('idle');
|
|
9
|
+
* const isLoading = status.when('loading');
|
|
10
|
+
* isLoading.subscribe(active => console.log('Loading:', active));
|
|
11
|
+
* status.set('loading'); // Logs: "Loading: true"
|
|
12
|
+
*/
|
|
13
|
+
import {ObservableWhen} from "../ObservableWhen";
|
|
14
|
+
import ObservableItem from "../ObservableItem";
|
|
15
|
+
import ObservableChecker from "../ObservableChecker";
|
|
16
|
+
import {Formatters} from "../../utils/formatters";
|
|
17
|
+
import NativeDocumentError from "../../errors/NativeDocumentError";
|
|
18
|
+
import {Observable} from "../Observable";
|
|
19
|
+
|
|
20
|
+
ObservableItem.prototype.when = function(value) {
|
|
21
|
+
return new ObservableWhen(this, value);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Create an Observable checker instance
|
|
28
|
+
* @param callback
|
|
29
|
+
* @returns {ObservableChecker}
|
|
30
|
+
*/
|
|
31
|
+
ObservableItem.prototype.check = function(callback) {
|
|
32
|
+
return new ObservableChecker(this, callback)
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
ObservableItem.prototype.transform = ObservableItem.prototype.check;
|
|
36
|
+
ObservableItem.prototype.pluck = function(property) {
|
|
37
|
+
return new ObservableChecker(this, (value) => value[property]);
|
|
38
|
+
};
|
|
39
|
+
ObservableItem.prototype.is = function(callbackOrValue) {
|
|
40
|
+
if(typeof callbackOrValue === 'function') {
|
|
41
|
+
return new ObservableChecker(this, callbackOrValue);
|
|
42
|
+
}
|
|
43
|
+
return new ObservableChecker(this, (value) => value === callbackOrValue);
|
|
44
|
+
};
|
|
45
|
+
ObservableItem.prototype.select = ObservableItem.prototype.check;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Creates a derived observable that formats the current value using Intl.
|
|
49
|
+
* Automatically reacts to both value changes and locale changes (Store.__nd.locale).
|
|
50
|
+
*
|
|
51
|
+
* @param {string | Function} type - Format type or custom formatter function
|
|
52
|
+
* @param {Object} [options={}] - Options passed to the formatter
|
|
53
|
+
* @returns {ObservableItem<string>}
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* // Currency
|
|
57
|
+
* price.format('currency') // "15 000 FCFA"
|
|
58
|
+
* price.format('currency', { currency: 'EUR' }) // "15 000,00 €"
|
|
59
|
+
* price.format('currency', { notation: 'compact' }) // "15 K FCFA"
|
|
60
|
+
*
|
|
61
|
+
* // Number
|
|
62
|
+
* count.format('number') // "15 000"
|
|
63
|
+
*
|
|
64
|
+
* // Percent
|
|
65
|
+
* rate.format('percent') // "15,0 %"
|
|
66
|
+
* rate.format('percent', { decimals: 2 }) // "15,00 %"
|
|
67
|
+
*
|
|
68
|
+
* // Date
|
|
69
|
+
* date.format('date') // "3 mars 2026"
|
|
70
|
+
* date.format('date', { dateStyle: 'full' }) // "mardi 3 mars 2026"
|
|
71
|
+
* date.format('date', { format: 'DD/MM/YYYY' }) // "03/03/2026"
|
|
72
|
+
* date.format('date', { format: 'DD MMM YYYY' }) // "03 mar 2026"
|
|
73
|
+
* date.format('date', { format: 'DD MMMM YYYY' }) // "03 mars 2026"
|
|
74
|
+
*
|
|
75
|
+
* // Time
|
|
76
|
+
* date.format('time') // "20:30"
|
|
77
|
+
* date.format('time', { second: '2-digit' }) // "20:30:00"
|
|
78
|
+
* date.format('time', { format: 'HH:mm:ss' }) // "20:30:00"
|
|
79
|
+
*
|
|
80
|
+
* // Datetime
|
|
81
|
+
* date.format('datetime') // "3 mars 2026, 20:30"
|
|
82
|
+
* date.format('datetime', { dateStyle: 'full' }) // "mardi 3 mars 2026, 20:30"
|
|
83
|
+
* date.format('datetime', { format: 'DD/MM/YYYY HH:mm' }) // "03/03/2026 20:30"
|
|
84
|
+
*
|
|
85
|
+
* // Relative
|
|
86
|
+
* date.format('relative') // "dans 11 jours"
|
|
87
|
+
* date.format('relative', { unit: 'month' }) // "dans 1 mois"
|
|
88
|
+
*
|
|
89
|
+
* // Plural
|
|
90
|
+
* count.format('plural', { singular: 'billet', plural: 'billets' }) // "3 billets"
|
|
91
|
+
*
|
|
92
|
+
* // Custom formatter
|
|
93
|
+
* price.format(value => `${value.toLocaleString()} FCFA`)
|
|
94
|
+
*
|
|
95
|
+
* // Reacts to locale changes automatically
|
|
96
|
+
* Store.setLocale('en-US');
|
|
97
|
+
*/
|
|
98
|
+
ObservableItem.prototype.format = function(type, options = {}) {
|
|
99
|
+
const self = this;
|
|
100
|
+
|
|
101
|
+
if (typeof type === 'function') {
|
|
102
|
+
return new ObservableChecker(self, type);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (process.env.NODE_ENV === 'development') {
|
|
106
|
+
if (!Formatters[type]) {
|
|
107
|
+
throw new NativeDocumentError(
|
|
108
|
+
`Observable.format : unknown type '${type}'. Available : ${Object.keys(Formatters).join(', ')}.`
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const formatter = Formatters[type];
|
|
114
|
+
const localeObservable = Formatters.locale;
|
|
115
|
+
|
|
116
|
+
return Observable.computed(() => formatter(self.val(), localeObservable.val(), options),
|
|
117
|
+
[self, localeObservable]
|
|
118
|
+
);
|
|
119
|
+
};
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import DebugManager from "./debug-manager";
|
|
2
2
|
import NativeDocumentError from "../errors/NativeDocumentError";
|
|
3
|
-
import ObservableChecker from "../data/ObservableChecker";
|
|
4
|
-
import {NDElement} from "../wrappers/NDElement";
|
|
5
3
|
|
|
6
4
|
const COMMON_NODE_TYPES = {
|
|
7
5
|
ELEMENT: 1,
|
|
@@ -40,7 +38,7 @@ const Validator = {
|
|
|
40
38
|
return value?.__Anchor__
|
|
41
39
|
},
|
|
42
40
|
isObservableChecker(value) {
|
|
43
|
-
return value?.__$isObservableChecker
|
|
41
|
+
return value?.__$isObservableChecker;
|
|
44
42
|
},
|
|
45
43
|
isArray(value) {
|
|
46
44
|
return Array.isArray(value);
|
|
@@ -81,12 +79,12 @@ const Validator = {
|
|
|
81
79
|
isValidChild(child) {
|
|
82
80
|
return child === null ||
|
|
83
81
|
this.isElement(child) ||
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
child.__$Observable ||
|
|
83
|
+
child?.__$isNDElement ||
|
|
86
84
|
['string', 'number', 'boolean'].includes(typeof child);
|
|
87
85
|
},
|
|
88
86
|
isNDElement(child) {
|
|
89
|
-
return child?.__$isNDElement
|
|
87
|
+
return child?.__$isNDElement;
|
|
90
88
|
},
|
|
91
89
|
isValidChildren(children) {
|
|
92
90
|
if (!Array.isArray(children)) {
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import Anchor from "../elements/anchor/anchor";
|
|
2
1
|
import Validator from "../utils/validator";
|
|
3
2
|
import AttributesWrapper, { bindClassAttribute, bindStyleAttribute } from "./AttributesWrapper";
|
|
4
3
|
import PluginsManager from "../utils/plugins-manager";
|
|
5
|
-
import './prototypes/nd-element-extensions';
|
|
6
|
-
import './prototypes/nd-element.transition.extensions';
|
|
7
|
-
import './prototypes/attributes-extensions';
|
|
8
|
-
import './prototypes/bind-class-extensions';
|
|
9
4
|
|
|
10
|
-
const $nodeCache = new Map();
|
|
11
5
|
let $textNodeCache = null;
|
|
12
6
|
|
|
13
7
|
export const ElementCreator = {
|
|
@@ -64,9 +58,6 @@ export const ElementCreator = {
|
|
|
64
58
|
const node = document.createElement(name);
|
|
65
59
|
return node.cloneNode();
|
|
66
60
|
},
|
|
67
|
-
createFragment: (name) => {
|
|
68
|
-
return Anchor('Fragment');
|
|
69
|
-
},
|
|
70
61
|
bindTextNode: (textNode, value) => {
|
|
71
62
|
if(value?.__$isObservable) {
|
|
72
63
|
value.subscribe(newValue => textNode.nodeValue = newValue);
|
|
@@ -2,8 +2,6 @@ import DocumentObserver from "./DocumentObserver";
|
|
|
2
2
|
import PluginsManager from "../utils/plugins-manager";
|
|
3
3
|
import NativeDocumentError from "../errors/NativeDocumentError.js";
|
|
4
4
|
import DebugManager from "../utils/debug-manager.js";
|
|
5
|
-
import Anchor from "../elements/anchor/anchor";
|
|
6
|
-
import {ElementCreator} from "./ElementCreator";
|
|
7
5
|
|
|
8
6
|
export function NDElement(element) {
|
|
9
7
|
this.$element = element;
|
|
@@ -15,11 +13,13 @@ export function NDElement(element) {
|
|
|
15
13
|
|
|
16
14
|
NDElement.prototype.__$isNDElement = true;
|
|
17
15
|
|
|
16
|
+
NDElement.$getChild = (el) => el;
|
|
17
|
+
|
|
18
18
|
NDElement.prototype.ghostDom = function(element) {
|
|
19
19
|
if(!this.$attachements) {
|
|
20
20
|
this.$attachements = document.createDocumentFragment();
|
|
21
21
|
}
|
|
22
|
-
this.$attachements.appendChild(
|
|
22
|
+
this.$attachements.appendChild(NDElement.$getChild(element));
|
|
23
23
|
return this;
|
|
24
24
|
};
|
|
25
25
|
|
|
@@ -5,6 +5,9 @@ import {ElementCreator} from "../ElementCreator";
|
|
|
5
5
|
import PluginsManager from "../../utils/plugins-manager";
|
|
6
6
|
import ObservableChecker from "../../data/ObservableChecker";
|
|
7
7
|
|
|
8
|
+
|
|
9
|
+
NDElement.$getChild = ElementCreator.getChild;
|
|
10
|
+
|
|
8
11
|
String.prototype.toNdElement = function () {
|
|
9
12
|
return ElementCreator.createStaticTextNode(null, this);
|
|
10
13
|
};
|