native-document 1.0.56 → 1.0.58
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,6 @@
|
|
|
1
1
|
import {Anchor} from "../../elements.js";
|
|
2
2
|
|
|
3
3
|
const ComponentRegistry = (function() {
|
|
4
|
-
console.log('ça s excecute')
|
|
5
|
-
|
|
6
4
|
const registry = new Map();
|
|
7
5
|
|
|
8
6
|
const wrapper = function(id, factory, metadata, registryItem) {
|
|
@@ -10,11 +8,9 @@ const ComponentRegistry = (function() {
|
|
|
10
8
|
|
|
11
9
|
return function(...args) {
|
|
12
10
|
const lastParams = args[0];
|
|
13
|
-
console.log({ lastParams })
|
|
14
11
|
if(lastParams?.__instance) {
|
|
15
12
|
const instance = lastParams.__instance;
|
|
16
|
-
const
|
|
17
|
-
const newInstance = factory(...componentArgs);
|
|
13
|
+
const newInstance = factory(...instance.context.args);
|
|
18
14
|
instance.anchor.setContent(newInstance);
|
|
19
15
|
return;
|
|
20
16
|
}
|
|
@@ -27,7 +23,6 @@ const ComponentRegistry = (function() {
|
|
|
27
23
|
args
|
|
28
24
|
}
|
|
29
25
|
});
|
|
30
|
-
console.log({ instance, anchor });
|
|
31
26
|
return anchor;
|
|
32
27
|
};
|
|
33
28
|
}
|
|
@@ -74,7 +69,6 @@ const ComponentRegistry = (function() {
|
|
|
74
69
|
}
|
|
75
70
|
},
|
|
76
71
|
updateInstance(instance, newFactory) {
|
|
77
|
-
console.log(Array.from(registry.entries()))
|
|
78
72
|
return newFactory({ __instance: instance });
|
|
79
73
|
}
|
|
80
74
|
};
|
|
@@ -11,21 +11,20 @@ const __filename = fileURLToPath(import.meta.url);
|
|
|
11
11
|
const __dirname = path.dirname(__filename);
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
export default function transformComponent(id, code) {
|
|
14
|
+
export default function transformComponent(id, code, options) {
|
|
15
15
|
let hasDefaultExport = false;
|
|
16
16
|
let componentName = null;
|
|
17
17
|
let exportStart = 0;
|
|
18
18
|
let exportEnd = 0;
|
|
19
19
|
// TODO: move this line outside the function
|
|
20
20
|
const hrmHookTemplate = fs.readFileSync(__dirname + '/hrm.hook.template.js', 'utf8');
|
|
21
|
-
const s = new MagicString(
|
|
21
|
+
const s = new MagicString(code);
|
|
22
22
|
const codeParsed = parse(code, {
|
|
23
23
|
sourceType: 'module',
|
|
24
24
|
plugins: []
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
traverse(codeParsed, {
|
|
27
|
+
traverse.default(codeParsed, {
|
|
29
28
|
ExportDefaultDeclaration(path) {
|
|
30
29
|
hasDefaultExport = true;
|
|
31
30
|
const declaration = path.node.declaration;
|
|
@@ -62,8 +61,7 @@ export default function transformComponent(id, code) {
|
|
|
62
61
|
hrmHookTemplateFormatted = hrmHookTemplateFormatted.replace(new RegExp("\\$\{"+key+"}", 'ig'), data[key]);
|
|
63
62
|
}
|
|
64
63
|
|
|
65
|
-
s.
|
|
66
|
-
s.append(code);
|
|
64
|
+
s.prepend('import ComponentRegistry from "native-document/src/hrm/ComponentRegistry";');
|
|
67
65
|
s.append(`export default ComponentRegistry.register('${id}', ${hrmComponentName}, { preserveState: ${options.preserveState} });`);
|
|
68
66
|
s.append(hrmHookTemplateFormatted);
|
|
69
67
|
|