@srikanthsai27/afrisure-blockly-expression 1.0.0

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/README.md ADDED
@@ -0,0 +1,226 @@
1
+ # Afrisure Blockly Expression Library
2
+
3
+ A reusable Angular library for building visual block-based expressions using Google Blockly.
4
+
5
+ ## Features
6
+
7
+ - 🧩 **Visual Expression Builder**: Drag-and-drop interface for creating complex expressions
8
+ - 🎨 **Custom Blocks**: Math operations (addition, subtraction, multiplication, division, max, min)
9
+ - 🔢 **Dynamic Variables**: Support for custom lookup variables
10
+ - 💾 **Save/Load**: Serialize and deserialize block configurations
11
+ - 🎯 **Type-Safe**: Full TypeScript support
12
+ - 🌐 **i18n Ready**: Built with ngx-translate support
13
+
14
+ ## Installation
15
+
16
+ ### From NPM (After Publishing)
17
+ ```bash
18
+ npm install afrisure-blockly-expression
19
+ ```
20
+
21
+ ### Local Development
22
+ The library is already built and available in your workspace at:
23
+ ```
24
+ dist/afrisure-blockly-expression
25
+ ```
26
+
27
+ ## Dependencies
28
+
29
+ This library requires the following peer dependencies:
30
+
31
+ ```json
32
+ {
33
+ "@angular/common": "^20.0.0",
34
+ "@angular/core": "^20.0.0",
35
+ "@angular/material": "^20.0.0",
36
+ "@ngx-translate/core": "^16.0.0",
37
+ "blockly": "^10.4.3",
38
+ "@blockly/continuous-toolbox": "^5.0.19",
39
+ "@blockly/toolbox-search": "^1.2.11",
40
+ "@blockly/zoom-to-fit": "^5.0.18"
41
+ }
42
+ ```
43
+
44
+ ## Usage
45
+
46
+ ### 1. Import the Component
47
+
48
+ ```typescript
49
+ import { Component } from '@angular/core';
50
+ import { MatDialog } from '@angular/material/dialog';
51
+ import { BlocklyExpression } from 'afrisure-blockly-expression';
52
+
53
+ @Component({
54
+ selector: 'app-my-component',
55
+ template: `
56
+ <button (click)="openBlocklyDialog()">
57
+ Open Expression Builder
58
+ </button>
59
+ `
60
+ })
61
+ export class MyComponent {
62
+ constructor(private dialog: MatDialog) {}
63
+
64
+ openBlocklyDialog() {
65
+ const dialogRef = this.dialog.open(BlocklyExpression, {
66
+ width: '90vw',
67
+ height: '90vh',
68
+ disableClose: true,
69
+ data: {
70
+ InputBlockyExpression: {
71
+ lookup: [
72
+ { id: 'var1', name: 'Variable 1', type: '' },
73
+ { id: 'var2', name: 'Variable 2', type: '' },
74
+ { id: 'var3', name: 'Variable 3', type: '' }
75
+ ],
76
+ blockExpressionJSON: {
77
+ loadexpression: null // or previously saved JSON string
78
+ }
79
+ }
80
+ }
81
+ });
82
+
83
+ dialogRef.afterClosed().subscribe(result => {
84
+ if (result) {
85
+ console.log('Expression:', result.expression);
86
+ console.log('JavaScript Code:', result.javascriptCode);
87
+ console.log('Saved State:', result.loadexpression);
88
+ }
89
+ });
90
+ }
91
+ }
92
+ ```
93
+
94
+ ### 2. Test the Library
95
+
96
+ Navigate to the test page in your application:
97
+ ```
98
+ http://localhost:1223/blockly-test
99
+ ```
100
+
101
+ ## API Reference
102
+
103
+ ### BlocklyExpression Component
104
+
105
+ #### Input Data Structure
106
+
107
+ ```typescript
108
+ interface BlocklyInputData {
109
+ InputBlockyExpression: {
110
+ lookup: Array<{
111
+ id: string;
112
+ name: string;
113
+ type: string;
114
+ }>;
115
+ blockExpressionJSON: {
116
+ loadexpression: string | null;
117
+ };
118
+ };
119
+ }
120
+ ```
121
+
122
+ #### Output Data Structure
123
+
124
+ ```typescript
125
+ interface BlocklyOutputData {
126
+ expression: string; // Generated expression string
127
+ javascriptCode: string; // JavaScript code representation
128
+ loadexpression: string; // Serialized block configuration (JSON)
129
+ }
130
+ ```
131
+
132
+ ### Available Blocks
133
+
134
+ #### Math Operations
135
+ - **Addition**: Add 2 or more numbers
136
+ - **Subtraction**: Subtract 2 or more numbers
137
+ - **Multiplication**: Multiply 2 or more numbers
138
+ - **Division**: Divide 2 or more numbers
139
+ - **Max**: Get maximum of 2 or more numbers
140
+ - **Min**: Get minimum of 2 or more numbers
141
+
142
+ #### Logical Operations
143
+ - **If/Else**: Conditional logic
144
+ - **Comparison**: Equal, Not Equal, Less Than, Greater Than, etc.
145
+ - **Boolean**: True/False values
146
+
147
+ #### Values
148
+ - **Number**: Numeric input
149
+ - **String**: Text input
150
+ - **Variables**: Custom lookup variables
151
+
152
+ ## Exported Components & Services
153
+
154
+ ```typescript
155
+ // Components
156
+ export { BlocklyExpression } from './lib/components/blockly-expression/blockly-expression';
157
+ export { PopUpTemplate } from './lib/components/pop-up-template/pop-up-template';
158
+
159
+ // Services
160
+ export { LoaderService } from './lib/services/loader.service';
161
+
162
+ // Modules
163
+ export { MaterialModule } from './lib/material.module';
164
+ ```
165
+
166
+ ## Building the Library
167
+
168
+ ```bash
169
+ # Build the library
170
+ ng build afrisure-blockly-expression
171
+
172
+ # Build output location
173
+ dist/afrisure-blockly-expression
174
+ ```
175
+
176
+ ## Publishing to NPM
177
+
178
+ ```bash
179
+ # Navigate to build output
180
+ cd dist/afrisure-blockly-expression
181
+
182
+ # Login to NPM (if not already logged in)
183
+ npm login
184
+
185
+ # Publish
186
+ npm publish --access public
187
+ ```
188
+
189
+ ## Development
190
+
191
+ ### Project Structure
192
+ ```
193
+ projects/afrisure-blockly-expression/
194
+ ├── src/
195
+ │ ├── lib/
196
+ │ │ ├── components/
197
+ │ │ │ ├── blockly-expression/
198
+ │ │ │ │ ├── blockly-expression.ts
199
+ │ │ │ │ ├── blockly-expression.html
200
+ │ │ │ │ └── blockly-expression.scss
201
+ │ │ │ └── pop-up-template/
202
+ │ │ │ ├── pop-up-template.ts
203
+ │ │ │ ├── pop-up-template.html
204
+ │ │ │ └── pop-up-template.scss
205
+ │ │ ├── services/
206
+ │ │ │ └── loader.service.ts
207
+ │ │ └── material.module.ts
208
+ │ └── public-api.ts
209
+ ├── package.json
210
+ ├── ng-package.json
211
+ └── README.md
212
+ ```
213
+
214
+ ## License
215
+
216
+ This library is part of the Afrisure Product Configuration project.
217
+
218
+ ## Support
219
+
220
+ For issues and feature requests, please contact the development team.
221
+
222
+ ---
223
+
224
+ **Version**: 0.0.1
225
+ **Author**: Afrisure Development Team
226
+ **Last Updated**: January 2026