native-document 1.0.63 → 1.0.64
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,8 +1,31 @@
|
|
|
1
1
|
import {Anchor} from "../../../elements.js";
|
|
2
|
+
import Validator from "../../utils/validator";
|
|
2
3
|
|
|
3
4
|
const ComponentRegistry = (function() {
|
|
4
5
|
const registry = new Map();
|
|
5
6
|
|
|
7
|
+
const attachLocalExtensions = (instance, factoryInstance) => {
|
|
8
|
+
if(!factoryInstance.$localExtensions) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const extensions = Object.fromEntries(factoryInstance.$localExtensions);
|
|
12
|
+
for(const name in extensions) {
|
|
13
|
+
instance.anchor[name] = function() {
|
|
14
|
+
const result = extensions[name](...arguments);
|
|
15
|
+
if(result === null || result === undefined) {
|
|
16
|
+
return instance.anchor;
|
|
17
|
+
}
|
|
18
|
+
if(Validator.isFragment(result) || Validator.isElement(result) || Validator.isNDElement(result)) {
|
|
19
|
+
instance.anchor.setContent(result);
|
|
20
|
+
return instance.anchor;
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
instance.anchor.$localExtensions = factoryInstance.$localExtensions;
|
|
26
|
+
instance.extensions = Object.keys(extensions);
|
|
27
|
+
};
|
|
28
|
+
|
|
6
29
|
const wrapper = function(id, factory, metadata, registryItem) {
|
|
7
30
|
const factoryName = factory.name;
|
|
8
31
|
|
|
@@ -10,13 +33,21 @@ const ComponentRegistry = (function() {
|
|
|
10
33
|
const firstParam = args[0];
|
|
11
34
|
if(firstParam?.__instance) {
|
|
12
35
|
const instance = firstParam.__instance;
|
|
13
|
-
const
|
|
14
|
-
|
|
36
|
+
const newFactoryInstance = factory(...instance.context.args, instance);
|
|
37
|
+
|
|
38
|
+
if(instance.extensions) {
|
|
39
|
+
instance.extensions.forEach((extensionName) => {
|
|
40
|
+
instance.anchor[extensionName] = undefined;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
attachLocalExtensions(instance, newFactoryInstance);
|
|
44
|
+
instance.anchor.setContent(newFactoryInstance);
|
|
15
45
|
return;
|
|
16
46
|
}
|
|
17
47
|
const anchor = Anchor(factoryName);
|
|
18
48
|
const instance = {
|
|
19
49
|
anchor,
|
|
50
|
+
extensions: null,
|
|
20
51
|
context: {
|
|
21
52
|
args,
|
|
22
53
|
states: new Map()
|
|
@@ -25,6 +56,8 @@ const ComponentRegistry = (function() {
|
|
|
25
56
|
const factoryInstance = factory(...args, instance);
|
|
26
57
|
anchor.setContent(factoryInstance);
|
|
27
58
|
registryItem.instances.add(instance);
|
|
59
|
+
|
|
60
|
+
attachLocalExtensions(instance, factoryInstance);
|
|
28
61
|
return anchor;
|
|
29
62
|
};
|
|
30
63
|
}
|
|
@@ -17,12 +17,6 @@ if (import.meta.hot) {
|
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
// const NativeDocument = window.NativeDocument;
|
|
21
|
-
// if (!NativeDocument) {
|
|
22
|
-
// console.error('[HMR Browser] NativeDocument not found on window!');
|
|
23
|
-
// return;
|
|
24
|
-
// }
|
|
25
|
-
|
|
26
20
|
if (!ComponentRegistry) {
|
|
27
21
|
console.error('[HMR Browser] ComponentRegistry not found!');
|
|
28
22
|
return;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
function Observable(name, instance, value, ...args) {
|
|
3
|
+
if(!instance?.context) {
|
|
4
|
+
return __OriginalObservable__(value, ...args);
|
|
5
|
+
}
|
|
3
6
|
if(instance.context.states.has(name)) {
|
|
4
7
|
const item = instance.context.states.get(name);
|
|
5
8
|
if(item.value !== value) {
|
|
@@ -18,6 +21,9 @@ function Observable(name, instance, value, ...args) {
|
|
|
18
21
|
};
|
|
19
22
|
|
|
20
23
|
Observable.init = function(name, instance, value, ...args) {
|
|
24
|
+
if(!instance?.context) {
|
|
25
|
+
return __OriginalObservable__.init(value, ...args);
|
|
26
|
+
}
|
|
21
27
|
if(instance.context.states.has(name)) {
|
|
22
28
|
const item = instance.context.states.get(name);
|
|
23
29
|
|
|
@@ -37,6 +43,9 @@ Observable.init = function(name, instance, value, ...args) {
|
|
|
37
43
|
};
|
|
38
44
|
|
|
39
45
|
Observable.array = function(name, instance, value, ...args) {
|
|
46
|
+
if(!instance?.context) {
|
|
47
|
+
return __OriginalObservable__.array(value, ...args);
|
|
48
|
+
}
|
|
40
49
|
if(instance.context.states.has(name)) {
|
|
41
50
|
const item = instance.context.states.get(name);
|
|
42
51
|
if(item.value !== JSON.stringify(value)) {
|