frontend-hamroun 1.2.77 → 1.2.79

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 (72) hide show
  1. package/dist/batch/package.json +1 -1
  2. package/dist/client-router/package.json +1 -1
  3. package/dist/component/package.json +1 -1
  4. package/dist/context/package.json +1 -1
  5. package/dist/event-bus/package.json +1 -1
  6. package/dist/forms/package.json +1 -1
  7. package/dist/hooks/package.json +1 -1
  8. package/dist/index.mjs +1 -0
  9. package/dist/jsx-runtime/package.json +1 -1
  10. package/dist/lifecycle-events/package.json +1 -1
  11. package/dist/package.json +1 -1
  12. package/dist/render-component/package.json +1 -1
  13. package/dist/renderer/package.json +1 -1
  14. package/dist/router/package.json +1 -1
  15. package/dist/server/package.json +1 -1
  16. package/dist/server/src/index.js +24 -23
  17. package/dist/server/src/index.js.map +1 -1
  18. package/dist/server/src/renderComponent.d.ts +8 -9
  19. package/dist/server/src/renderComponent.js +10 -5
  20. package/dist/server/src/renderComponent.js.map +1 -1
  21. package/dist/server/src/server/index.d.ts +23 -34
  22. package/dist/server/src/server/index.js +170 -50
  23. package/dist/server/src/server/index.js.map +1 -1
  24. package/dist/server/src/server/templates.d.ts +2 -0
  25. package/dist/server/src/server/templates.js +9 -5
  26. package/dist/server/src/server/templates.js.map +1 -1
  27. package/dist/server/src/server/utils.d.ts +1 -1
  28. package/dist/server/src/server/utils.js +1 -1
  29. package/dist/server/src/server/utils.js.map +1 -1
  30. package/dist/server/tsconfig.server.tsbuildinfo +1 -1
  31. package/dist/server-renderer/package.json +1 -1
  32. package/dist/store/package.json +1 -1
  33. package/dist/types/package.json +1 -1
  34. package/dist/utils/package.json +1 -1
  35. package/dist/vdom/package.json +1 -1
  36. package/dist/wasm/package.json +1 -1
  37. package/package.json +1 -1
  38. package/templates/complete-app/client.js +58 -0
  39. package/templates/complete-app/package-lock.json +2536 -0
  40. package/templates/complete-app/package.json +8 -31
  41. package/templates/complete-app/pages/about.js +119 -0
  42. package/templates/complete-app/pages/index.js +157 -0
  43. package/templates/complete-app/pages/wasm-demo.js +290 -0
  44. package/templates/complete-app/public/client.js +80 -0
  45. package/templates/complete-app/public/index.html +47 -0
  46. package/templates/complete-app/public/styles.css +446 -212
  47. package/templates/complete-app/readme.md +188 -0
  48. package/templates/complete-app/server.js +417 -0
  49. package/templates/complete-app/server.ts +275 -0
  50. package/templates/complete-app/src/App.tsx +59 -0
  51. package/templates/complete-app/src/client.ts +61 -0
  52. package/templates/complete-app/src/client.tsx +18 -0
  53. package/templates/complete-app/src/pages/index.tsx +51 -0
  54. package/templates/complete-app/src/server.ts +218 -0
  55. package/templates/complete-app/tsconfig.json +22 -0
  56. package/templates/complete-app/tsconfig.server.json +19 -0
  57. package/templates/complete-app/vite.config.js +57 -0
  58. package/templates/complete-app/vite.config.ts +30 -0
  59. package/templates/go/example.go +154 -99
  60. package/templates/complete-app/build.js +0 -284
  61. package/templates/complete-app/src/api/index.js +0 -31
  62. package/templates/complete-app/src/client.js +0 -93
  63. package/templates/complete-app/src/components/App.js +0 -66
  64. package/templates/complete-app/src/components/Footer.js +0 -19
  65. package/templates/complete-app/src/components/Header.js +0 -38
  66. package/templates/complete-app/src/pages/About.js +0 -59
  67. package/templates/complete-app/src/pages/Home.js +0 -54
  68. package/templates/complete-app/src/pages/WasmDemo.js +0 -136
  69. package/templates/complete-app/src/server.js +0 -186
  70. package/templates/complete-app/src/wasm/build.bat +0 -16
  71. package/templates/complete-app/src/wasm/build.sh +0 -16
  72. package/templates/complete-app/src/wasm/example.go +0 -101
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "useDefineForClassFields": true,
5
+ "lib": ["DOM", "DOM.Iterable", "ESNext"],
6
+ "allowJs": false,
7
+ "skipLibCheck": true,
8
+ "esModuleInterop": true,
9
+ "allowSyntheticDefaultImports": true,
10
+ "strict": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "module": "ESNext",
13
+ "moduleResolution": "Node",
14
+ "resolveJsonModule": true,
15
+ "isolatedModules": true,
16
+ "noEmit": true,
17
+ "jsx": "preserve",
18
+ "jsxFactory": "createElement",
19
+ "jsxFragmentFactory": "Fragment"
20
+ },
21
+ "include": ["src"]
22
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "target": "ES2020",
5
+ "module": "NodeNext",
6
+ "moduleResolution": "NodeNext",
7
+ "esModuleInterop": true,
8
+ "outDir": "./dist/server",
9
+ "declaration": true,
10
+ "sourceMap": true,
11
+ "strict": true,
12
+ "skipLibCheck": true,
13
+ "jsx": "react",
14
+ "jsxFactory": "createElement",
15
+ "jsxFragmentFactory": "Fragment"
16
+ },
17
+ "include": ["server.ts", "src/pages/**/*.tsx"],
18
+ "exclude": ["node_modules", "dist"]
19
+ }
@@ -0,0 +1,57 @@
1
+ import { defineConfig } from 'vite';
2
+ import { resolve } from 'path';
3
+
4
+ export default defineConfig({
5
+ // Configure JSX
6
+ esbuild: {
7
+ jsxFactory: 'createElement',
8
+ jsxFragment: 'Fragment',
9
+ jsxInject: `import { createElement, Fragment } from 'frontend-hamroun'`
10
+ },
11
+
12
+ // Configure build
13
+ build: {
14
+ outDir: 'dist/public',
15
+ emptyOutDir: true,
16
+ rollupOptions: {
17
+ input: {
18
+ client: resolve(__dirname, 'src/client.ts')
19
+ },
20
+ output: [
21
+ {
22
+ // ESM output
23
+ entryFileNames: 'assets/[name].mjs',
24
+ chunkFileNames: 'assets/[name]-[hash].mjs',
25
+ assetFileNames: 'assets/[name]-[hash].[ext]',
26
+ format: 'es',
27
+ },
28
+ {
29
+ // CommonJS output
30
+ entryFileNames: 'assets/[name].js',
31
+ chunkFileNames: 'assets/[name]-[hash].js',
32
+ assetFileNames: 'assets/[name]-[hash].[ext]',
33
+ format: 'cjs',
34
+ }
35
+ ]
36
+ }
37
+ },
38
+
39
+ // Add optimizations for frontend-hamroun
40
+ optimizeDeps: {
41
+ include: ['frontend-hamroun']
42
+ },
43
+
44
+ // Resolve aliases for better imports
45
+ resolve: {
46
+ alias: {
47
+ '@': resolve(__dirname, 'src')
48
+ }
49
+ },
50
+
51
+ // Development server
52
+ server: {
53
+ proxy: {
54
+ '/api': 'http://localhost:3000'
55
+ }
56
+ }
57
+ });
@@ -0,0 +1,30 @@
1
+ import { defineConfig } from 'vite';
2
+ import path from 'path';
3
+
4
+ export default defineConfig({
5
+ resolve: {
6
+ alias: {
7
+ 'frontend-hamroun': path.resolve(__dirname, 'node_modules/frontend-hamroun')
8
+ }
9
+ },
10
+ build: {
11
+ outDir: 'dist',
12
+ ssr: 'src/server.ts',
13
+ rollupOptions: {
14
+ input: {
15
+ client: './src/client.tsx',
16
+ server: './src/server.ts'
17
+ },
18
+ output: {
19
+ entryFileNames: '[name].js',
20
+ chunkFileNames: 'assets/[name]-[hash].js',
21
+ assetFileNames: 'assets/[name]-[hash].[ext]'
22
+ }
23
+ }
24
+ },
25
+ esbuild: {
26
+ jsxFactory: '_jsx',
27
+ jsxFragment: '_Fragment',
28
+ jsxInject: `import { jsx as _jsx, Fragment as _Fragment } from 'frontend-hamroun'`
29
+ }
30
+ });
@@ -4,147 +4,202 @@
4
4
  package main
5
5
 
6
6
  import (
7
- "encoding/json"
8
7
  "fmt"
8
+ "strconv"
9
+ "strings"
9
10
  "syscall/js"
10
11
  )
11
12
 
12
- // Basic arithmetic functions
13
- func add(this js.Value, args []js.Value) interface{} {
13
+ // Main function required for Go WebAssembly
14
+ func main() {
15
+ // Set up global functions that will be accessible from JavaScript
16
+ js.Global().Set("goAdd", js.FuncOf(goAdd))
17
+ js.Global().Set("goSubtract", js.FuncOf(goSubtract))
18
+ js.Global().Set("goMultiply", js.FuncOf(goMultiply))
19
+ js.Global().Set("goDivide", js.FuncOf(goDivide))
20
+ js.Global().Set("goReverseString", js.FuncOf(goReverseString))
21
+ js.Global().Set("goCalculateFactorial", js.FuncOf(goCalculateFactorial))
22
+ js.Global().Set("goProcessArray", js.FuncOf(goProcessArray))
23
+
24
+ // Keep the Go program running until the context is done
25
+ // This is necessary for WebAssembly modules
26
+ <-make(chan bool)
27
+ }
28
+
29
+ // goAdd adds two numbers and returns the result
30
+ func goAdd(this js.Value, args []js.Value) interface{} {
14
31
  if len(args) != 2 {
15
- return js.ValueOf("Error: add requires 2 arguments")
32
+ return map[string]interface{}{
33
+ "error": "Expected 2 arguments: number, number",
34
+ }
35
+ }
36
+
37
+ // Parse string arguments as numbers
38
+ a, errA := strconv.ParseFloat(args[0].String(), 64)
39
+ b, errB := strconv.ParseFloat(args[1].String(), 64)
40
+
41
+ // Check for parsing errors
42
+ if errA != nil || errB != nil {
43
+ return map[string]interface{}{
44
+ "error": "Arguments must be valid numbers",
45
+ }
16
46
  }
17
47
 
18
- a := args[0].Int()
19
- b := args[1].Int()
20
- return js.ValueOf(a + b)
48
+ // Return the result
49
+ return fmt.Sprintf("%g", a+b)
21
50
  }
22
51
 
23
- func subtract(this js.Value, args []js.Value) interface{} {
52
+ // goSubtract subtracts the second number from the first
53
+ func goSubtract(this js.Value, args []js.Value) interface{} {
24
54
  if len(args) != 2 {
25
- return js.ValueOf("Error: subtract requires 2 arguments")
55
+ return map[string]interface{}{
56
+ "error": "Expected 2 arguments: number, number",
57
+ }
58
+ }
59
+
60
+ // Parse string arguments as numbers
61
+ a, errA := strconv.ParseFloat(args[0].String(), 64)
62
+ b, errB := strconv.ParseFloat(args[1].String(), 64)
63
+
64
+ // Check for parsing errors
65
+ if errA != nil || errB != nil {
66
+ return map[string]interface{}{
67
+ "error": "Arguments must be valid numbers",
68
+ }
26
69
  }
27
70
 
28
- a := args[0].Int()
29
- b := args[1].Int()
30
- return js.ValueOf(a - b)
71
+ // Return the result
72
+ return fmt.Sprintf("%g", a-b)
31
73
  }
32
74
 
33
- func multiply(this js.Value, args []js.Value) interface{} {
75
+ // goMultiply multiplies two numbers
76
+ func goMultiply(this js.Value, args []js.Value) interface{} {
34
77
  if len(args) != 2 {
35
- return js.ValueOf("Error: multiply requires 2 arguments")
78
+ return map[string]interface{}{
79
+ "error": "Expected 2 arguments: number, number",
80
+ }
81
+ }
82
+
83
+ // Parse string arguments as numbers
84
+ a, errA := strconv.ParseFloat(args[0].String(), 64)
85
+ b, errB := strconv.ParseFloat(args[1].String(), 64)
86
+
87
+ // Check for parsing errors
88
+ if errA != nil || errB != nil {
89
+ return map[string]interface{}{
90
+ "error": "Arguments must be valid numbers",
91
+ }
36
92
  }
37
93
 
38
- a := args[0].Int()
39
- b := args[1].Int()
40
- return js.ValueOf(a * b)
94
+ // Return the result
95
+ return fmt.Sprintf("%g", a*b)
41
96
  }
42
97
 
43
- // String operations
44
- func concat(this js.Value, args []js.Value) interface{} {
45
- if len(args) < 1 {
46
- return js.ValueOf("")
98
+ // goDivide divides the first number by the second
99
+ func goDivide(this js.Value, args []js.Value) interface{} {
100
+ if len(args) != 2 {
101
+ return map[string]interface{}{
102
+ "error": "Expected 2 arguments: number, number",
103
+ }
104
+ }
105
+
106
+ // Parse string arguments as numbers
107
+ a, errA := strconv.ParseFloat(args[0].String(), 64)
108
+ b, errB := strconv.ParseFloat(args[1].String(), 64)
109
+
110
+ // Check for parsing errors
111
+ if errA != nil || errB != nil {
112
+ return map[string]interface{}{
113
+ "error": "Arguments must be valid numbers",
114
+ }
47
115
  }
48
116
 
49
- result := ""
50
- for _, arg := range args {
51
- result += arg.String()
117
+ // Check for division by zero
118
+ if b == 0 {
119
+ return map[string]interface{}{
120
+ "error": "Division by zero is not allowed",
121
+ }
52
122
  }
53
- return js.ValueOf(result)
123
+
124
+ // Return the result
125
+ return fmt.Sprintf("%g", a/b)
54
126
  }
55
127
 
56
- // JSON operations
57
- func parseJSON(this js.Value, args []js.Value) interface{} {
128
+ // goReverseString reverses a string
129
+ func goReverseString(this js.Value, args []js.Value) interface{} {
58
130
  if len(args) != 1 {
59
- return js.ValueOf("Error: parseJSON requires 1 argument")
131
+ return map[string]interface{}{
132
+ "error": "Expected 1 argument: string",
133
+ }
60
134
  }
61
135
 
62
- jsonStr := args[0].String()
63
- var result interface{}
64
- err := json.Unmarshal([]byte(jsonStr), &result)
65
- if err != nil {
66
- return js.ValueOf("Error parsing JSON: " + err.Error())
136
+ input := args[0].String()
137
+ runes := []rune(input)
138
+
139
+ // Reverse the string
140
+ for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
141
+ runes[i], runes[j] = runes[j], runes[i]
67
142
  }
68
143
 
69
- // Convert result to JS value
70
- return mapToJSValue(result)
144
+ return string(runes)
71
145
  }
72
146
 
73
- // Helper functions for JSON conversion
74
- func mapToJSValue(value interface{}) js.Value {
75
- switch v := value.(type) {
76
- case map[string]interface{}:
77
- result := js.Global().Get("Object").New()
78
- for key, val := range v {
79
- result.Set(key, mapToJSValue(val))
147
+ // goCalculateFactorial calculates the factorial of a number
148
+ func goCalculateFactorial(this js.Value, args []js.Value) interface{} {
149
+ if len(args) != 1 {
150
+ return map[string]interface{}{
151
+ "error": "Expected 1 argument: number",
80
152
  }
81
- return result
82
- case []interface{}:
83
- result := js.Global().Get("Array").New(len(v))
84
- for i, val := range v {
85
- result.SetIndex(i, mapToJSValue(val))
153
+ }
154
+
155
+ // Parse string argument as number
156
+ n, err := strconv.ParseInt(args[0].String(), 10, 64)
157
+
158
+ // Check for parsing errors
159
+ if err != nil {
160
+ return map[string]interface{}{
161
+ "error": "Argument must be a valid integer",
86
162
  }
87
- return result
88
- case string:
89
- return js.ValueOf(v)
90
- case float64:
91
- return js.ValueOf(v)
92
- case bool:
93
- return js.ValueOf(v)
94
- case nil:
95
- return js.ValueOf(nil)
96
- default:
97
- return js.ValueOf(fmt.Sprint(v))
98
163
  }
99
- }
100
164
 
101
- // Special utility functions for string handling between Go and JS
102
- func __stringToGo(this js.Value, args []js.Value) interface{} {
103
- if len(args) != 1 {
104
- return js.ValueOf(-1)
165
+ // Check for negative numbers
166
+ if n < 0 {
167
+ return map[string]interface{}{
168
+ "error": "Factorial is not defined for negative numbers",
169
+ }
105
170
  }
106
- return args[0] // Pass through
107
- }
108
171
 
109
- func __stringFromGo(this js.Value, args []js.Value) interface{} {
110
- if len(args) != 1 {
111
- return js.ValueOf("")
172
+ // Calculate factorial
173
+ result := int64(1)
174
+ for i := int64(2); i <= n; i++ {
175
+ result *= i
112
176
  }
113
- return args[0] // Pass through
177
+
178
+ return fmt.Sprintf("%d", result)
114
179
  }
115
180
 
116
- func __objectToGo(this js.Value, args []js.Value) interface{} {
117
- if len(args) != 1 {
118
- return js.ValueOf(-1)
181
+ // goProcessArray processes an array of values
182
+ func goProcessArray(this js.Value, args []js.Value) interface{} {
183
+ if len(args) != 1 || args[0].Type() != js.TypeString {
184
+ return map[string]interface{}{
185
+ "error": "Expected 1 argument: comma-separated string",
186
+ }
119
187
  }
120
- return args[0] // Pass through
121
- }
122
188
 
123
- func __objectFromGo(this js.Value, args []js.Value) interface{} {
124
- if len(args) != 1 {
125
- return js.ValueOf("")
189
+ // Split the input string by commas
190
+ input := args[0].String()
191
+ parts := strings.Split(input, ",")
192
+
193
+ // Process each part
194
+ var results []string
195
+ for _, part := range parts {
196
+ // Trim whitespace
197
+ trimmed := strings.TrimSpace(part)
198
+
199
+ // Convert to uppercase and add to results
200
+ results = append(results, strings.ToUpper(trimmed))
126
201
  }
127
- return args[0] // Pass through
128
- }
129
202
 
130
- func main() {
131
- fmt.Println("Go WebAssembly module initialized")
132
-
133
- // Register functions to make available to JavaScript
134
- js.Global().Set("goAdd", js.FuncOf(add))
135
- js.Global().Set("goSubtract", js.FuncOf(subtract))
136
- js.Global().Set("goMultiply", js.FuncOf(multiply))
137
- js.Global().Set("goConcat", js.FuncOf(concat))
138
- js.Global().Set("goParseJSON", js.FuncOf(parseJSON))
139
-
140
- // Register special utility functions for frontend-hamroun integration
141
- js.Global().Set("__stringToGo", js.FuncOf(__stringToGo))
142
- js.Global().Set("__stringFromGo", js.FuncOf(__stringFromGo))
143
- js.Global().Set("__objectToGo", js.FuncOf(__objectToGo))
144
- js.Global().Set("__objectFromGo", js.FuncOf(__objectFromGo))
145
-
146
- // Keep the program running
147
- c := make(chan struct{}, 0)
148
- fmt.Println("Go WebAssembly module ready")
149
- <-c
203
+ // Join the processed parts with commas
204
+ return strings.Join(results, ",")
150
205
  }