hayun-vite 0.12.0 → 0.14.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/src/Form/Form.js CHANGED
@@ -9,18 +9,19 @@ import MultiText from "../MultiText/MultiText.js";
9
9
  const svgNS = "http://www.w3.org/2000/svg";
10
10
 
11
11
  export default class Form {
12
- constructor({ container, template } = {}) {
12
+ constructor({ container, template, mode = "production" } = {}) {
13
13
  this.template = template;
14
14
  this.container = container;
15
+ this.mode = mode;
15
16
  this.data = {};
16
17
  let { width, height, margin, paper } = template;
17
- this.page = this.create({ paper, margin });
18
- this.page.style.display = 'none';
18
+ this.svg = this.create({ paper, margin }); // اس‌وی‌جی مادر فرم را صفحه نامگذاری میکنیم بذاریم همون اس‌وی‌جی؟
19
+ this.svg.style.display = 'none';
19
20
  let dims;
20
21
  // رسم مارجین های فرم
21
- this.drawMarginLines({ container: this.page, width, height });
22
+ this.drawMarginLines({ container: this.svg, width, height });
22
23
 
23
- const sections = new Sections({ container: this.page, dims: template });
24
+ const sections = new Sections({ container: this.svg, dims: template });
24
25
  this.sections = sections;
25
26
 
26
27
  if (sections.header) {
@@ -57,51 +58,53 @@ export default class Form {
57
58
  })
58
59
  }
59
60
  if (sections['Speech Titles']) {
60
- dims= template['Speech Titles'];
61
+ dims = template['Speech Titles'];
61
62
  const titles = new MultiText({ container: sections['Speech Titles'], dims });
62
63
  }
63
64
  if (sections['RSpeech']) {
64
- dims= template.RSpeech
65
- this.RSpeech = new Speech({ container: sections.RSpeech, side: 'R', dims})
65
+ dims = template.RSpeech
66
+ this.RSpeech = new Speech({ container: sections.RSpeech, side: 'R', dims })
66
67
  }
67
68
  if (sections.LSpeech) {
68
- dims= template.LSpeech
69
+ dims = template.LSpeech
69
70
  this.LSpeech = new Speech({ container: sections.LSpeech, side: 'L', dims })
70
71
  }
71
72
  if (sections['Tympanogram Titles']) {
72
- dims= template['Tympanogram Titles'];
73
+ dims = template['Tympanogram Titles'];
73
74
  new MultiText({ container: sections['Tympanogram Titles'], dims });
74
75
  }
75
76
  if (sections.RTympanogram) {
76
- dims= template.RTympanogram
77
+ dims = template.RTympanogram
77
78
  this.RTympanogram = new Tympanogram({ container: sections.RTympanogram, side: 'R', dims })
78
79
  }
79
80
  if (sections.LTympanogram) {
80
- dims= template.LTympanogram
81
+ dims = template.LTympanogram
81
82
  this.LTympanogram = new Tympanogram({ container: sections.LTympanogram, side: 'L', dims })
82
83
  }
83
84
  if (sections['Reflex Titles']) {
84
- dims= template['Reflex Titles'];
85
+ dims = template['Reflex Titles'];
85
86
  const titles = new MultiText({ container: sections['Reflex Titles'], dims });
86
87
  }
87
88
  if (sections.RReflex) {
88
- dims= template.RReflex
89
+ dims = template.RReflex
89
90
  this.RReflex = new Reflex({ container: sections.RReflex, side: 'R', dims })
90
91
  }
91
92
  if (sections.LReflex) {
92
- dims= template.LReflex
93
+ dims = template.LReflex
93
94
  this.LReflex = new Reflex({ container: sections.LReflex, side: 'L', dims })
94
95
  }
95
96
  if (sections.report) {
96
- dims= template.report;
97
+ dims = template.report;
97
98
  this.report = new MultiText({ container: sections.report, dims })
98
99
  }
99
100
  if (sections.footer) {
100
- dims= template.footer;
101
- this.footer = new MultiText({ container: sections.footer, dims})
101
+ dims = template.footer;
102
+ this.footer = new MultiText({ container: sections.footer, dims })
102
103
  }
103
104
 
104
- this.container.appendChild(this.page);
105
+ this.container.appendChild(this.svg);
106
+
107
+ this.addEvent()
105
108
  }
106
109
 
107
110
 
@@ -130,43 +133,35 @@ export default class Form {
130
133
  return svg
131
134
  }
132
135
 
133
- update({ data, officeData, patientData, sessionIndex = 0 }) {
136
+ update({ officeData, patientData, sessionIndex = 0 }) {
134
137
 
135
138
  const session = patientData.sessions[sessionIndex]
136
- // Prevent undefined error
137
- if (!data) {
138
- data = {
139
- common: {
140
- audiometer: "",
141
- tympanometers: "",
142
- },
143
- header: {
144
- officeName: officeData.name,
145
- officeLogo: officeData.logo,
146
- createDate: patientData.sessions[sessionIndex]?.createDate,
147
- },
148
- patient: {
149
- name: patientData.name,
150
- lastName: patientData.lastName,
151
- gender: patientData?.gender,
152
- // خط زیر محاسبه درست سن هست. موقتا کامنت می‌شود تا در اپ اصلی فیلد سن رو در سشن ها قرار دهیم
153
- // age: patientData.sessions[sessionIndex]?.age,
154
- age: patientData?.age,
155
- referrer: patientData.sessions[sessionIndex]?.referrer,
156
- date: new Date().toLocaleDateString('fa-IR'),
157
-
158
- },
159
- footer: {
160
- address: officeData.addresses[0],
161
- tel: officeData.tels[0],
162
- },
163
- id: +sessionIndex + 1,
164
- };
165
- // data = { audiogram: {}, common: {}, footer: {}, header: {}, patient: {}, reflex: {}, report: {}, speech: {}, tympanometry: {} }
166
- }
167
- // find which data reach and then call corresponding update function
168
- // get array of keys (audiogram, header, footer, ...)
169
- let keys = Object.keys(data)
139
+
140
+ let data = {
141
+
142
+ header: {
143
+ officeName: officeData.name,
144
+ officeLogo: officeData.logos[officeData.selectedLogoIndex],
145
+ createDate: patientData.sessions[sessionIndex]?.createDate,
146
+ },
147
+ patient: {
148
+ name: patientData.name,
149
+ lastName: patientData.lastName,
150
+ gender: patientData?.gender,
151
+ // خط زیر محاسبه درست سن هست. موقتا کامنت می‌شود تا در اپ اصلی فیلد سن رو در سشن ها قرار دهیم
152
+ // age: patientData.sessions[sessionIndex]?.age,
153
+ age: patientData?.age,
154
+ referrer: patientData.sessions[sessionIndex]?.referrer,
155
+ date: new Date().toLocaleDateString('fa-IR'),
156
+ },
157
+ footer: {
158
+ address: officeData.addresses[0],
159
+ tel: officeData.tels[0],
160
+ },
161
+ id: +sessionIndex + 1,
162
+ };
163
+
164
+ // let keys = Object.keys(data)
170
165
  // if (keys.includes("header")) {
171
166
 
172
167
  this.header?.update(data.header)
@@ -175,7 +170,6 @@ export default class Form {
175
170
  this.patient?.update(data.patient)
176
171
  // }
177
172
  // if (keys.includes("history")) {
178
-
179
173
  this.history?.update(session?.history)
180
174
  this.data.history = session.history;
181
175
  // }
@@ -204,11 +198,8 @@ export default class Form {
204
198
  this.data.report = session.report;
205
199
  // }
206
200
  // if (keys.includes("footer")) {
207
- // console.log("footer Data:", data?.footer);
208
-
209
201
  this.footer?.update(data?.footer)
210
202
  this.data.footer = data.footer;
211
- // }
212
203
  }
213
204
 
214
205
  // خطوط نقطه چین مارجین فرم
@@ -224,4 +215,12 @@ export default class Form {
224
215
  `;
225
216
  putRect({ container, x: 0, y: 0, width, height, style, className: 'no-print' })
226
217
  }
218
+
219
+ // افزودن رویداد کلیک روی فرم
220
+ addEvent({ } = {}) {
221
+ this.svg.addEventListener("click", e => {
222
+ console.log(e.target.dataset['name']);
223
+
224
+ })
225
+ }
227
226
  }
@@ -1,31 +1,28 @@
1
- const svgNS = "http://www.w3.org/2000/svg";
1
+ // import '../styles.css' // برای تست منتقل شد به فایل ایندکس اصلی اچ‌تی‌ام‌ال و برای توسعه منتقل شده به ایندکس جی اس
2
+ import printForm from "./printForm.js"
3
+ import Form from "../Form/Form.js"
4
+ import putGrid from "../common/putGrid.js"
2
5
 
3
- import printForm from "./printForm.js";
4
- import Form from "../Form/Form.js";
5
- // import combo from "./templates/combo.js"; // این در حقیقیت یک تمپلت هست
6
- // import rasaAud from "./templates/rasa_audiometry.js";
7
- // import rasaTymp from './templates/rasa_tymp_reflex.js'
6
+ const svgNS = "http://www.w3.org/2000/svg"
8
7
 
9
- // خط کد زیر لازم هست
10
- // import '/fonts/webfonts/Vazirmatn-Regular.woff2'
11
- import '../styles.css'
12
- import putLine from "../common/putLine.js";
8
+ import templCombo from "../../assets/templates/templCombo.js" // این در حقیقیت یک تمپلت هست
9
+ import templAudiometry from "../../assets/templates/templAudiometry.js"
13
10
 
14
11
  // کلاس جدید که فرم‌های مختلف را نمایش میدهد
15
12
  export default class Forms {
16
13
  constructor({ assets, container, templates, defaultTemplateIndex = 0, mode = 'production' } = {}) {
17
14
  this.container = container
18
15
  this.mode = mode;
19
- // this.addForms({ templates: [rasaAud, rasaTymp, combo], defaultTemplateIndex })
20
- this.addForms({ templates, defaultTemplateIndex })
16
+ this.forms = [] // آرایه آبجکت های فرم های مختلف
17
+ this.addForms({ templates: [templCombo, templAudiometry], defaultTemplateIndex })
21
18
  }
22
19
 
23
20
  // افزودن فرم
24
21
  addForms({ templates, defaultTemplateIndex }) {
22
+ const forms = this.forms;
25
23
  const container = this.container
26
24
  // ایجاد یک دیو برای قرار دادن دکمه ها و لینک های فرم
27
25
  const div = document.createElement('div');
28
-
29
26
  div.style = 'border: 1px solid brown; margin: 0; padding: 0;'
30
27
  container.appendChild(div);
31
28
 
@@ -33,101 +30,88 @@ export default class Forms {
33
30
  let className = 'button-form persian';
34
31
  const btns = [];
35
32
 
36
- const forms = []; // آرایه آبجکت های فرم های مختلف
37
- this.forms = forms;
38
-
39
33
  templates.
40
34
  forEach((template, index) => {
35
+
41
36
  this.mode == 'develop' &&
42
- (btns[index] = this.putButton({ container: div, text: template.label, className }));
43
- this.forms.push(new Form({ container, template }));
44
- });
37
+ (btns[index] = this.putButton({ container: div, text: template.label, className }))
38
+ this.forms.push(new Form({ container, template, mode: this.mode }))
39
+ })
40
+
45
41
 
46
42
  // انتخاب فرم پیش‌فرض
47
- let selectedIndex = defaultTemplateIndex;
48
- forms[selectedIndex].page.style.display = 'block';
49
- this.selectedForm = this.forms[selectedIndex];
50
- (this.mode == 'develop') && (btns[selectedIndex].style.backgroundColor = ' #1c15e1');
43
+ let selectedIndex = defaultTemplateIndex
44
+ this.selectedIndex = selectedIndex // برای استفاده در متد آپدیت
51
45
 
52
- if (this.mode == 'develop') {
46
+ forms[selectedIndex].svg.style.display = 'block'
47
+ // this.selectedForm = this.forms[selectedIndex] // سمی‌کالن واجب
53
48
 
54
- const printBtn = this.putButton({ container: div, text: 'چاپ', className });
55
- // تعریف رویداد دکمه چاپ فرم نمایشی
56
- printBtn.addEventListener('click', () => { printForm({ container: this.selectedForm.page }) });
49
+ this.mode == 'develop' &&
50
+ (btns[selectedIndex].style.backgroundColor = ' #1c15e1') // اگر عبارت اول توی پرانتز باشه سمی‌کالن واجب
57
51
 
52
+ // به ازای هر فرم یک دکمه هم به دیو بالای فرم اضافه میکند در حالت دولوپ
53
+ // افزودن دکمه مربوطه به فرمها به دام
54
+ this.mode == 'develop' &&
58
55
  btns.forEach((btn, index) => {
59
56
  btn.addEventListener('click', () => {
60
57
  // Hide All forms
61
58
  forms.forEach((form, i) => {
62
- form.page.style.display = 'none'
59
+ form.svg.style.display = 'none'
63
60
  btns[i].style.backgroundColor = ' #7472e2'
61
+ })
64
62
 
65
- });
66
-
67
- forms[index].page.style.display = 'block';
63
+ forms[index].svg.style.display = 'block'
68
64
  btns[index].style.backgroundColor = ' #1c15e1'
69
65
 
70
- this.selectedForm = forms[index];
66
+ // this.selectedForm = forms[index]
71
67
  selectedIndex = index
72
- this.update(this.allData);
68
+ this.selectedIndex = selectedIndex
69
+ this.update(this.dataParams)
73
70
  })
74
- })
71
+ }) // سمی‌کالن واجب
75
72
 
76
- // دکمه نمایش و پنهان خطوط سکشن
77
- this.putButton({ container: div, text: 'Show/Hide Section Borders', className })
78
- .addEventListener('click', () => {
79
- this.toggleDisplay({ container: forms[selectedIndex].page, borderName: 'section-border' })
80
- });
81
-
82
- // دکمه نمایش و پنهان خطوط بوردر
83
- this.putButton({ container: div, text: 'Show/Hide Box Borders', className })
84
- .addEventListener('click', () => {
85
- this.toggleDisplay({ container: forms[selectedIndex].page, borderName: 'box-border' })
86
- });
87
-
88
- // دکمه نمایش و پنهان شطرنجی
89
- this.putButton({ container: div, text: 'Show/Hide Grid', className })
90
- .addEventListener('mouseenter', () => {
91
- this.grid({ container: forms[selectedIndex].page })
92
- });
93
- // فراخوانی تابع شطرنجی در اولین اجرا
94
- this.grid({ container: forms[selectedIndex].page })
95
- }
73
+ // افزودن چهار دکمه چاپ صفحه فرم انتخاب شده و تاگل پنهان یا نمایش
74
+ this.mode == 'develop' &&
75
+ this.addButtons({ container: div, className, svg: forms[selectedIndex].svg })
96
76
  }
97
77
 
98
- grid({ container }) {
99
- console.log(container);
100
- const cord = { xStart: -5, yStart: -5, xEnd: 210 - 5, yEnd: 297 - 5, xStep: 1, yStep: 1 }
101
- let { xStart, yStart, xEnd, yEnd, xStep, yStep } = cord
102
-
103
- // رسم خطوط افقی
104
- let style = 'stroke: blue; stroke-width: 0.05 ; stroke-opacity: 0.8; stroke-dasharray: 0.2;'
105
- let x1 = xStart
106
- let y1
78
+ // افزودن چهار دکمه چاپ صفحه فرم انتخاب شده و تاگل پنهان یا نمایش
79
+ addButtons({ container, className, svg }) {
107
80
 
108
- let x2 = xEnd
109
- let y2
81
+ // تعریف دکمه و رویداد دکمه چاپ صفحه فرم نمایشی
82
+ this.putButton({ container, text: 'چاپ', className })
83
+ .addEventListener('click', () => {
84
+ printForm({ container: this.forms[this.selectedIndex].svg })
85
+ });
110
86
 
111
- for (let y1 = yStart; y1 <= yEnd; y1 += yStep) {
112
- y2 = y1
113
- putLine({ container, x1, y1, x2, y2, style, name: 'grid' })
114
- }
87
+ // دکمه و رویداد نمایش و پنهان خطوط سکشن
88
+ this.putButton({ container, text: 'Show/Hide Section Borders', className })
89
+ .addEventListener('click', () => {
90
+ this.toggleDisplay({ container: svg, borderName: 'section-border' })
91
+ });
115
92
 
116
- // رسم خطوط عمودی
117
- y1 = yStart
118
- for (x1 = xStart; x1 <= xEnd; x1 += xStep) {
119
- const x2 = x1
120
- putLine({ container, x1, y1, x2, y2, style, name: 'grid' })
121
- }
93
+ // دکمه و رویداد نمایش و پنهان خطوط بوردر
94
+ this.putButton({ container, text: 'Show/Hide Box Borders', className })
95
+ .addEventListener('click', () => {
96
+ this.toggleDisplay({ container: svg, borderName: 'box-border' })
97
+ });
122
98
 
99
+ // دکمه نمایش و پنهان شطرنجی
100
+ this.putButton({ container, text: 'Show/Hide Grid', className })
101
+ .addEventListener('mouseenter', () => {
102
+ putGrid({ container: svg })
103
+ });
104
+ // فراخوانی تابع شطرنجی در اولین اجرا
105
+ // putGrid({ container: forms[selectedIndex].svg })
123
106
 
124
107
  }
125
108
 
126
109
  // این تابع یک بار از بیرون کلاس فراخوانی میشه و یک بار وقتی از داخل تمپلت فرم را عوض میکنیم
127
- update({ data, officeData, patientData, sessionIndex = 0 }) {
110
+ update({ officeData, patientData, sessionIndex = 0 }) {
128
111
  // ذخیره کل دیتا برای استفاده داخلی آپدیت فرم انتخاب شده
129
- this.allData = { data, officeData, patientData, sessionIndex }
130
- this.selectedForm.update({ data, officeData, patientData, sessionIndex })
112
+ this.dataParams = { officeData, patientData, sessionIndex }
113
+ // this.selectedForm.update({ officeData, patientData, sessionIndex })
114
+ this.forms[this.selectedIndex].update(this.dataParams)
131
115
  }
132
116
 
133
117
  // توابع داخلی ایجاد دکمه و لینک های بالای فرم
@@ -0,0 +1,18 @@
1
+ import { officeData, patientData } from "../../assets/data/sampleData";
2
+ import templAudiometry from "../../assets/templates/templAudiometry";
3
+ import templCombo from "../../assets/templates/templCombo";
4
+ import Forms from "./Forms";
5
+
6
+ document.querySelector('#app').innerHTML = `
7
+ <div id="test"></div>
8
+ `;
9
+
10
+ const container = document.getElementById('test')
11
+
12
+ const forms = new Forms({ container, templates: [templCombo, templAudiometry], mode: 'develop' });
13
+
14
+ forms.update({ officeData, patientData, sessionIndex: 0 })
15
+
16
+ // خط برای کپی پیست نقشی در کد ندارد
17
+
18
+
@@ -18,11 +18,11 @@ export default class Header {
18
18
  let x = dims.margin.left;
19
19
  let y = dims.margin.top;
20
20
 
21
- const svg = putSVG({ x, y, width, height, style: 'direction: rtl !important; user-select: none;' })
21
+ const svg = putSVG({ x, y, width, height, style: 'font-family: Vazir; direction: rtl !important; user-select: none;' })
22
22
 
23
23
  // Logo
24
24
  let image = document.createElementNS(svgNS, "image");
25
- image.setAttribute("data-name", "officeLogo")
25
+ image.setAttribute("data-name", "officeLogo") // برای تابع آپدیت استفاده می‌شود
26
26
  image.setAttribute("width", "17");
27
27
  image.setAttribute("height", height - 1);
28
28
  image.setAttribute("x", width - 16);
@@ -30,14 +30,10 @@ export default class Header {
30
30
  svg.appendChild(image);
31
31
 
32
32
  let style = `
33
- user-select: none;
34
- direction: rtl;
35
- /* text-align: center; */
36
- font-family: Vazir;
37
33
  font-size: 0.8mm;
38
34
  font-weight: bolder;
39
- text-anchor: start; /*تراز افقی*/
40
- dominant-baseline: auto; /* تراز عمودی*/
35
+ text-anchor: start;
36
+ dominant-baseline: auto;
41
37
  `;
42
38
 
43
39
  // اگر مقدار استروک درست بود لیبل ها را چاپ کن
@@ -87,16 +87,18 @@ export default class MultiText {
87
87
  const textInput = this.container.querySelector(`text[data-name=${input.name}]`)
88
88
 
89
89
  // پیدا کردن کاراکترهای رفتن به سرخط در متن
90
- const textLines = value.toString().split(/\n|\r|\r\n/);
91
- const x = textInput.getAttribute('x')
92
- // اگر متن چند خطی بود
93
- if (textLines.length >= 2) {
94
- let y = 5;
95
- textLines.forEach(value => {
96
- putTspan({ container: textInput, value, x, y });
97
- y += 6;
98
- })
99
- } else textInput.innerHTML = value || "";
90
+ if (value) {
91
+ const textLines = value.toString().split(/\n|\r|\r\n/);
92
+ const x = textInput.getAttribute('x')
93
+ // اگر متن چند خطی بود
94
+ if (textLines.length >= 2) {
95
+ let y = 5;
96
+ textLines.forEach(value => {
97
+ putTspan({ container: textInput, value, x, y });
98
+ y += 6;
99
+ })
100
+ } else textInput.innerHTML = value || "";
101
+ }
100
102
  });
101
103
  }
102
104
  }