native-document 1.0.279 → 1.0.281

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.
@@ -46,7 +46,7 @@ const ComponentRegistry = (function() {
46
46
  instance.anchor.setContent(newFactoryInstance);
47
47
  return;
48
48
  }
49
- const anchor = Anchor(factoryName);
49
+ const anchor = Anchor('Component : '+factoryName);
50
50
  const instance = {
51
51
  __hrm: true,
52
52
  anchor,
@@ -62,7 +62,9 @@ const ComponentRegistry = (function() {
62
62
  registryItem.instances.add(instance);
63
63
 
64
64
  attachLocalExtensions(instance, factoryInstance);
65
- factoryInstance.toNdElement = () => anchor;
65
+ factoryInstance.toNdElement = () => {
66
+ return anchor;
67
+ };
66
68
  return factoryInstance;
67
69
  };
68
70
  };
@@ -93,6 +95,10 @@ const ComponentRegistry = (function() {
93
95
  }
94
96
  DebugManager.log(`[HMR] Updating ${component.instances.size} instance(s) of ${id}`);
95
97
  const oldFactory = component.factory;
98
+ if(typeof newFactory !== 'function') {
99
+ DebugManager.log('[HMR] Updating factory is not a function : ', newFactory);
100
+ return;
101
+ }
96
102
  component.factory = newFactory;
97
103
  component.version++;
98
104
  const instances = Array.from(component.instances);
@@ -124,8 +130,8 @@ const ComponentRegistry = (function() {
124
130
  if (!timers) {
125
131
  return;
126
132
  }
127
- for(const item in timers) {
128
- item.cleaner(item.timerId);
133
+ for(const item of timers) {
134
+ item.cleaner();
129
135
  }
130
136
  },
131
137
  };
@@ -6,7 +6,8 @@ import transformNdForHrm from './src/transformers/transformNdForHrm.js';
6
6
 
7
7
  export default function NdViteDevtools(options) {
8
8
  const {
9
- include = /\.nd\.js$/,
9
+ include = /\\.js$/,
10
+ includeCustomFile = /\.nd\.js$/,
10
11
  preserveState = true,
11
12
  } = options;
12
13
 
@@ -34,21 +35,27 @@ export default function NdViteDevtools(options) {
34
35
  return modules.filter(Boolean);
35
36
  },
36
37
  transform(code, id) {
37
- if (!include.test(id)) {
38
+ if (include.test(id)) {
38
39
  if(isFileMustBeModified(id)) {
39
- return transformForHrm(code, id, { preserveState, ...options});
40
+ try {
41
+ return transformForHrm(code, id, { preserveState, ...options});
42
+ } catch (error) {
43
+ console.error(`[NativeDocument] Transform error in ${id}:`, error);
44
+ }
40
45
  }
41
46
  return null;
42
47
  }
43
- if (id.includes('node_modules') || id.includes('native-document')) {
48
+ if (id.includes('node_modules')) {
44
49
  return null;
45
50
  }
46
51
 
47
- try {
48
- return transformNdForHrm(code, id, { preserveState, ...options });
49
- } catch (error) {
50
- console.error(`[NativeDocument] Transform error in ${id}:`, error);
51
- return null;
52
+ if (includeCustomFile.test(id)) {
53
+ try {
54
+ return transformNdForHrm(code, id, { preserveState, ...options });
55
+ } catch (error) {
56
+ console.error(`[NativeDocument] Transform error in ${id}:`, error);
57
+ return null;
58
+ }
52
59
  }
53
60
  },
54
61
 
@@ -23,7 +23,16 @@ if (import.meta.hot) {
23
23
  return;
24
24
  }
25
25
 
26
- // console.log('[HMR Browser] Calling ComponentRegistry.update()');
26
+ console.log('[HMR Browser] Calling ComponentRegistry.update()');
27
+ try {
28
+ for(const componentId of componentIds) {
29
+ ComponentRegistry.cleanTimer(componentId);
30
+ }
31
+ ComponentRegistry.cleanTimer('${id}')
32
+ console.log('[HMR Browser] ✓ Clean timer successful');
33
+ } catch (error) {
34
+ console.error('[HMR Browser] ✗ Clean timers failed:', error);
35
+ }
27
36
  try {
28
37
  for(const componentId of componentIds) {
29
38
  ComponentRegistry.cleanTimer(componentId);
@@ -37,7 +46,7 @@ if (import.meta.hot) {
37
46
  ComponentRegistry.update('${id}', newModule.default, '${id}');
38
47
  // console.log('[HMR Browser] ✓ Update successful');
39
48
  } catch (error) {
40
- // console.error('[HMR Browser] ✗ Update failed:', error);
49
+ console.error('[HMR Browser] ✗ Update failed:', error);
41
50
  }
42
51
  });
43
52
 
@@ -4,7 +4,7 @@ export const timerSourceCode = () => {
4
4
 
5
5
  return 'const customSetTimeout = (contextId, targetId, , callback, delay, ...args) => {\n' +
6
6
  ' const timerId = window.setTimeout(callback, delay, ...args)' +
7
- ' ComponentRegistry.registerTimer(contextId, timerId, clearTimeout);\n' +
7
+ ' ComponentRegistry.registerTimer(contextId, timerId, () => clearTimeout(timerId));\n' +
8
8
  ' return timerId;\n' +
9
9
  '};\n' +
10
10
  '\n' +
@@ -12,9 +12,8 @@ export const timerSourceCode = () => {
12
12
  '\n',
13
13
  '\n',
14
14
  'const customSetInterval = (contextId, targetId, callback, delay, ...args) => {\n' +
15
- 'console.log({ targetId, callback, delay })\n' +
16
15
  ' const timerId = window.setInterval(callback, delay, ...args);\n' +
17
- ' ComponentRegistry.registerTimer(contextId, timerId, clearInterval);\n' +
16
+ ' ComponentRegistry.registerTimer(contextId, timerId, () => clearInterval(timerId));\n' +
18
17
  ' return timerId\n' +
19
18
  '};\n' +
20
19
  '\n' +
@@ -52,7 +52,7 @@ export function transformObservableDeclarations(code, id) {
52
52
  }
53
53
 
54
54
  export function isFileMustBeModified(file) {
55
- if(!file.includes('/src/') || file.includes('native-document') || file.includes('node_modules') || /\.test\.js$/.test(file)) {
55
+ if(!file.includes('/src/') || file.includes('node_modules') || /\.test\.js$/.test(file)) {
56
56
  return false;
57
57
  }
58
58
  const content = fs.readFileSync(file, 'utf-8');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "native-document",
3
- "version": "1.0.279",
3
+ "version": "1.0.281",
4
4
  "description": "A reactive JavaScript framework that preserves native DOM simplicity without sacrificing modern features",
5
5
  "author": "AfroCodeur <https://github.com/afrocodeur>",
6
6
  "license": "MIT",