native-document 1.0.95 → 1.0.99

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.
Files changed (44) hide show
  1. package/{src/devtools/hrm → devtools}/ComponentRegistry.js +2 -2
  2. package/devtools/index.js +8 -0
  3. package/{src/devtools/plugin.js → devtools/plugin/dev-tools-plugin.js} +2 -2
  4. package/{src/devtools/hrm/nd-vite-hot-reload.js → devtools/transformers/nd-vite-devtools.js} +16 -6
  5. package/devtools/transformers/src/transformComponentForHrm.js +74 -0
  6. package/devtools/transformers/src/transformJsFile.js +9 -0
  7. package/devtools/transformers/src/utils.js +79 -0
  8. package/{src/devtools/hrm → devtools/transformers/templates}/hrm.orbservable.hook.template.js +8 -0
  9. package/devtools/widget/Widget.js +48 -0
  10. package/devtools/widget/widget.css +81 -0
  11. package/devtools/widget.js +23 -0
  12. package/dist/native-document.components.min.js +1953 -1245
  13. package/dist/native-document.dev.js +2022 -1375
  14. package/dist/native-document.dev.js.map +1 -1
  15. package/dist/native-document.devtools.min.js +1 -1
  16. package/dist/native-document.min.js +1 -1
  17. package/docs/cache.md +1 -1
  18. package/docs/core-concepts.md +1 -1
  19. package/docs/native-document-element.md +51 -15
  20. package/docs/observables.md +333 -315
  21. package/docs/state-management.md +198 -193
  22. package/package.json +1 -1
  23. package/readme.md +1 -1
  24. package/rollup.config.js +1 -1
  25. package/src/core/data/ObservableArray.js +67 -0
  26. package/src/core/data/ObservableChecker.js +2 -0
  27. package/src/core/data/ObservableItem.js +97 -0
  28. package/src/core/data/ObservableObject.js +183 -0
  29. package/src/core/data/Store.js +364 -34
  30. package/src/core/data/observable-helpers/object.js +2 -166
  31. package/src/core/utils/formatters.js +91 -0
  32. package/src/core/utils/localstorage.js +57 -0
  33. package/src/core/utils/validator.js +0 -2
  34. package/src/fetch/NativeFetch.js +5 -2
  35. package/types/observable.d.ts +73 -15
  36. package/types/plugins-manager.d.ts +1 -1
  37. package/types/store.d.ts +33 -6
  38. package/hrm.js +0 -7
  39. package/src/devtools/app/App.js +0 -66
  40. package/src/devtools/app/app.css +0 -0
  41. package/src/devtools/hrm/transformComponent.js +0 -129
  42. package/src/devtools/index.js +0 -18
  43. package/src/devtools/widget/DevToolsWidget.js +0 -26
  44. /package/{src/devtools/hrm → devtools/transformers/templates}/hrm.hook.template.js +0 -0
@@ -1,129 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- // import { parse } from '@babel/parser';
4
- import MagicString from 'magic-string';
5
-
6
- import { fileURLToPath } from 'node:url';
7
- import { parse } from '@babel/parser';
8
- import { default as traverse } from '@babel/traverse';
9
-
10
- const __filename = fileURLToPath(import.meta.url);
11
- const __dirname = path.dirname(__filename);
12
-
13
- const renameImportedObservables = (content, match) => {
14
- let isObservableFound = false;
15
- let isObservableShortFound = false;
16
- const transformedContentArray = match.split(',').map(item => {
17
- let trimmed = item.trim();
18
-
19
- if (trimmed === 'Observable') {
20
- isObservableFound = true;
21
- return 'Observable as __OriginalObservable__';
22
- }
23
- if (trimmed === '$') {
24
- isObservableShortFound = true;
25
- return '$ as __$__';
26
- }
27
-
28
- return ` ${trimmed}`;
29
- });
30
- if(!isObservableFound && isObservableShortFound) {
31
- transformedContentArray.push('Observable as __OriginalObservable__')
32
- }
33
- const transformedContent = transformedContentArray.join(', ');
34
-
35
- return `import {${transformedContent} } from 'native-document'`;
36
- };
37
-
38
- function transformObservableImports(code, params) {
39
- const renameImportationCode = code.replace(/import\s+\{([^}]+?)\}\s+from\s+['"]native-document['"]/g, renameImportedObservables);
40
- const isRenamed = renameImportationCode !== code;
41
-
42
- const s = new MagicString(renameImportationCode);
43
- if(isRenamed) {
44
- //Todo: move this code outside the function
45
- const hrmObservableHookTemplate = fs.readFileSync(__dirname + '/hrm.orbservable.hook.template.js', 'utf8');
46
- s.append(template(
47
- hrmObservableHookTemplate,
48
- params ?? {}
49
- ));
50
- }
51
-
52
- return s.toString();
53
- }
54
-
55
- function transformObservableDeclarations(code) {
56
- const regex = /(const|let|var)\s+([\w$]+)\s*=\s*(\$|Observable)(\.(?:init|array|json))?\s*\(/g;
57
-
58
- return code.replace(regex, (match, varType, varName, caller, method) => {
59
- const obsName = method ? `${caller}${method}` : 'Observable';
60
- return `${varType} ${varName} = ${obsName}('${varName}', arguments[arguments.length - 1], `;
61
- });
62
- }
63
-
64
- function template(code, params) {
65
- let codeFormatted = code;
66
- for(const key in params) {
67
- codeFormatted = codeFormatted.replace(new RegExp("\\$\{"+key+"}", 'ig'), params[key]);
68
- }
69
- return codeFormatted;
70
- }
71
-
72
- export default function transformComponent(id, code, options) {
73
- let hasDefaultExport = false;
74
- let componentName = null;
75
- let exportStart = 0;
76
- let exportEnd = 0;
77
- // TODO: move this line outside the function
78
- const hrmHookTemplate = fs.readFileSync(__dirname + '/hrm.hook.template.js', 'utf8');
79
- const formattedCode = transformObservableDeclarations(
80
- transformObservableImports(code, { id, ...options }),
81
- );
82
- const s = new MagicString(formattedCode);
83
- const codeParsed = parse(formattedCode, {
84
- sourceType: 'module',
85
- plugins: []
86
- });
87
-
88
- traverse.default(codeParsed, {
89
- ExportDefaultDeclaration(path) {
90
- hasDefaultExport = true;
91
- const declaration = path.node.declaration;
92
-
93
- if (declaration.id) {
94
- componentName = declaration.id.name;
95
- } else if (declaration.type === 'Identifier') {
96
- componentName = declaration.name;
97
- } else {
98
- componentName = 'AnonymousComponent';
99
- }
100
-
101
- exportStart = path.node.start;
102
- exportEnd = path.node.end;
103
- },
104
- });
105
- if (!hasDefaultExport) {
106
- return null;
107
- }
108
-
109
- const originalExport = formattedCode.slice(exportStart, exportEnd);
110
- const hrmComponentName = `__HRM_${componentName}__`;
111
- const newExport = originalExport.replace(
112
- 'export default',
113
- `const ${hrmComponentName} =`
114
- );
115
- s.overwrite(exportStart, exportEnd, newExport);
116
-
117
- const hrmHookTemplateFormatted = template(hrmHookTemplate, {
118
- id
119
- });
120
-
121
- s.prepend('import ComponentRegistry from "native-document/src/devtools/hrm/ComponentRegistry";');
122
- s.append(`export default ComponentRegistry.register('${id}', ${hrmComponentName}, { preserveState: ${options.preserveState} });`);
123
- s.append(hrmHookTemplateFormatted);
124
-
125
- return {
126
- code: s.toString(),
127
- map: s.generateMap({ source: id, hires: true })
128
- };
129
- }
@@ -1,18 +0,0 @@
1
- import App from './app/App';
2
- import {DevToolsPlugin} from "./plugin";
3
-
4
- const Devtools = (function () {
5
-
6
- return {
7
- config() {
8
- console.log('devtool init configuratzion');
9
- },
10
- init() {
11
- const app = App();
12
- document.body.parentNode.appendChild(app.$element);
13
- },
14
- plugin: DevToolsPlugin
15
- }
16
- }());
17
-
18
- export default Devtools;
@@ -1,26 +0,0 @@
1
- import {Div, Button} from "../../../elements";
2
- import {DevToolService} from "../plugin";
3
-
4
- export default function DevToolsWidget() {
5
- let shouldFollowPointer = false;
6
- const setFullScreen = () => {
7
- alert('Move to full-screen');
8
- }
9
-
10
- const $element = Div({ class: 'devtools-app-panel-widget', style: 'left: 50%; top: 95%' }, [
11
- Div({ class: 'widget-label'}, DevToolService.createdObservable),
12
- Button({ class: 'widget-button' }, 'Full').nd.onClick(setFullScreen)
13
- ]);
14
-
15
- $element.nd
16
- .onStopMouseDown(() => shouldFollowPointer = true)
17
- .onMouseUp((event) => shouldFollowPointer = false);
18
-
19
- document.addEventListener('mousemove', (event) => {
20
- if(shouldFollowPointer) {
21
- $element.style = 'left: '+event.clientX+'px; top: '+event.clientY+'px';
22
- }
23
- });
24
-
25
- return $element;
26
- };