create-gardener 2.1.0 → 2.1.2

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 (69) hide show
  1. package/package.json +1 -1
  2. package/template/build/backend/controllers/gardener/addPage.d.ts.map +1 -1
  3. package/template/build/backend/controllers/gardener/addPage.js +31 -21
  4. package/template/build/backend/controllers/gardener/addPage.js.map +1 -1
  5. package/template/build/backend/controllers/gardener/createStatic.d.ts.map +1 -1
  6. package/template/build/backend/controllers/gardener/createStatic.js +3 -1
  7. package/template/build/backend/controllers/gardener/createStatic.js.map +1 -1
  8. package/template/build/backend/libs/generateWebp.d.ts.map +1 -1
  9. package/template/build/backend/libs/generateWebp.js +0 -2
  10. package/template/build/backend/libs/generateWebp.js.map +1 -1
  11. package/template/build/backend/routes/gardener.route.js +5 -0
  12. package/template/build/backend/routes/gardener.route.js.map +1 -1
  13. package/template/build/frontend/static/bundle/bundle._.js +1 -0
  14. package/template/build/frontend/static/bundle/bundle._about.js +1 -0
  15. package/template/build/frontend/static/bundle/bundle._kartik.js +1 -0
  16. package/template/build/frontend/static/bundle/bundle._new.js +1 -0
  17. package/template/build/frontend/static/bundle/bundle._ritish.js +1 -0
  18. package/template/build/frontend/static/cache/gardener_100x100.webp +0 -0
  19. package/template/build/frontend/static/components/copybtn.js +16 -3
  20. package/template/build/frontend/static/components/footer.js +33 -0
  21. package/template/build/frontend/static/components/gardener/errorBox.js +47 -0
  22. package/template/build/frontend/static/components/gardener/hotReloadbtn.js +82 -0
  23. package/template/build/frontend/static/components/gardener/pageOverlayBtn.js +138 -0
  24. package/template/build/frontend/static/components/gardener/parserWindow.js +159 -0
  25. package/template/build/frontend/static/components/nonui/api.js +15 -2
  26. package/template/build/frontend/static/components/nonui/navigation.js +2 -2
  27. package/template/build/frontend/static/components/notification.js +1 -1
  28. package/template/build/frontend/static/gardener.js +129 -58
  29. package/template/build/frontend/static/gardenerConfig.js +1 -1
  30. package/template/build/frontend/static/gardenerDev.js +67 -401
  31. package/template/build/frontend/static/global.js +2 -2
  32. package/template/build/frontend/static/pages/pages._.js +7 -2
  33. package/template/build/frontend/static/pages/pages._about.js +2 -0
  34. package/template/build/frontend/static/pages/pages._kartik.js +2 -0
  35. package/template/build/frontend/static/pages/pages._new.js +2 -0
  36. package/template/build/frontend/static/pages/pages._ritish.js +2 -0
  37. package/template/build/frontend/static/style.css +1 -1
  38. package/template/build/frontend/static/style2.css +2 -2
  39. package/template/build/frontend/views/_.ejs +6 -2
  40. package/template/build/frontend/views/_about.ejs +126 -0
  41. package/template/build/frontend/views/_kartik.ejs +126 -0
  42. package/template/build/frontend/views/_new.ejs +126 -0
  43. package/template/build/frontend/views/_ritish.ejs +126 -0
  44. package/template/buildHelper.js +33 -2
  45. package/template/package.json +2 -1
  46. package/template/pnpm-lock.yaml +271 -0
  47. package/template/src/backend/controllers/gardener/addPage.ts +7 -1
  48. package/template/src/backend/controllers/gardener/createStatic.ts +94 -59
  49. package/template/src/backend/controllers/gardener/index.ts +0 -1
  50. package/template/src/backend/routes/gardener.route.ts +1 -2
  51. package/template/src/frontend/bundle/bundle._.js +2 -0
  52. package/template/src/frontend/bundle/bundle._about.js +1 -0
  53. package/template/src/frontend/bundle/bundle._kartik.js +1 -0
  54. package/template/src/frontend/bundle/bundle._new.js +1 -0
  55. package/template/src/frontend/bundle/bundle._ritish.js +1 -0
  56. package/template/src/frontend/static/components/nonui/navigation.js +2 -2
  57. package/template/src/frontend/static/components/notification.js +1 -1
  58. package/template/src/frontend/static/gardenerDev.js +2 -2
  59. package/template/src/frontend/static/global.js +1 -1
  60. package/template/src/frontend/static/pages/pages._.js +2 -2
  61. package/template/src/frontend/static/style.css +61 -31
  62. package/template/src/frontend/template/template._.ejs +5 -1
  63. package/template/src/frontend/views/_.ejs +6 -2
  64. package/template/build/frontend/static/gardener.test.js +0 -364
  65. package/template/build/frontend/static/zod.js +0 -8
  66. package/template/buildHelper.test.js +0 -78
  67. package/template/jest.config.js +0 -13
  68. package/template/src/frontend/static/gardener.test.js +0 -364
  69. package/template/src/frontend/static/zod.js +0 -8
@@ -1,124 +1,20 @@
1
- import { mode } from '/static/gardenerConfig.js'
2
- import { gardener, appendElement, fetchElement } from '/static/gardener.js'
1
+ import { mode } from './gardenerConfig.js'
2
+ import { gardener, appendElement, fetchElement } from './gardener.js'
3
+ import { addPagebtn } from './components/gardener/pageOverlayBtn.js';
4
+ import { parserWindow as parserWindowComponent } from './components/gardener/parserWindow.js';
5
+ import { hotReloadBtn, togglehotreload } from './components/gardener/hotReloadbtn.js';
6
+ import { gardenerError } from './components/gardener/errorBox.js';
3
7
 
4
8
  const body = fetchElement('body');
5
- let hotReloadtimeout;
6
9
 
7
- const config = {
8
- componentdir: 'static/components',
9
- hotreload: false
10
- }
11
10
 
12
11
 
13
12
 
14
- let hotReload;
15
- const localStore = localStorage.getItem('hotreload');
16
-
17
- if (localStore === null) hotReload = config.hotreload;
18
- else if (localStore === 'true') hotReload = true
19
- else if (localStore === 'false') hotReload = false
20
-
21
-
22
-
23
- // const addPagebtn = gardener({
24
- // t: 'button',
25
- // cn: ['pb-1.5', 'flex', 'items-center', 'justify-center', 'h-15', 'w-15', 'bg-green-300', 'fixed', 'bottom-22', 'right-2', 'rounded-full', 'text-5xl'],
26
- // children: [{ t: 'span', txt: '+' }],
27
- // events: {
28
- // click: opnPagedialog
29
- // }
30
- // });
31
-
32
- const pagebtns = gardener({
33
- t: 'div',
34
- cn: [
35
- 'fixed',
36
- 'bottom-20',
37
- 'right-4',
38
- 'flex',
39
- 'flex-col',
40
- 'gap-2',
41
- 'bg-white',
42
- 'shadow-lg',
43
- 'rounded-xl',
44
- 'p-3',
45
- 'z-50'
46
- ],
47
- children: [
48
- {
49
- t: 'button',
50
- cn: [
51
- 'px-4',
52
- 'py-2',
53
- 'bg-blue-500',
54
- 'text-white',
55
- 'rounded-lg',
56
- 'hover:bg-blue-600',
57
- 'transition'
58
- ],
59
- children: [{ t: 'span', txt: 'New Page' }],
60
- events: {
61
- click: opnPagedialog
62
- }
63
- },
64
- {
65
- t: 'button',
66
- cn: [
67
- 'px-4',
68
- 'py-2',
69
- 'bg-gray-800',
70
- 'text-white',
71
- 'rounded-lg',
72
- 'hover:bg-gray-900',
73
- 'transition'
74
- ],
75
- children: [{ t: 'span', txt: 'Save Template' }],
76
- events: {
77
- click: async () => {
78
- const result = await fetch('/savetemplate', {
79
- method: 'POST',
80
- headers: { "Content-Type": 'application/json' },
81
- body: JSON.stringify({ path: fetchElement('#fileName').innerText })
82
- });
83
-
84
- const data = await result.json(); // ✅ fix
85
- alert(data.message);
86
- }
87
- }
88
- }
89
- ]
90
- });
91
- const addPagebtn = gardener({
92
- t: 'div',
93
- cn: ['fixed', 'bottom-4', 'right-4', 'z-50'],
94
- events: {
95
- mouseenter: () => appendElement(addPagebtn, pagebtns),
96
- mouseleave: () => pagebtns.remove()
97
- },
98
- children: [
99
- {
100
- t: 'span',
101
- // cn: ['pb-1.5', 'flex', 'items-center', 'justify-center', 'h-15', 'w-15', 'bg-black', 'text-white', 'fixed', 'bottom-22', 'right-2'],
102
-
103
- cn: [
104
- 'flex',
105
- 'items-center',
106
- 'justify-center',
107
- 'h-14',
108
- 'w-14',
109
- 'bg-black',
110
- 'text-white',
111
- 'fixed',
112
- 'bottom-22',
113
- 'right-2',
114
- 'rounded-full',
115
- 'shadow-lg',
116
- 'cursor-pointer',
117
- ],
118
- txt: 'GR'
119
- }
120
- ]
121
- });
13
+
14
+
15
+
16
+
17
+
122
18
 
123
19
 
124
20
 
@@ -126,51 +22,11 @@ if (mode === 'dev') {
126
22
  appendElement(body, addPagebtn);
127
23
 
128
24
 
129
- appendElement(body, gardener({
130
- t: 'p',
131
- cn: ['bg-gray-200', 'fixed', 'bottom-0', 'z-100', 'right-0', 'border-b-1', 'p-2', 'rounded-md'],
132
- children: [
133
- {
134
- t: 'span',
135
- txt: 'Press '
136
- },
137
- {
138
- t: 'span',
139
- cn: ['text-green-500', 'font-bold'],
140
- txt: 'Alt+h'
141
- },
142
- {
143
- t: 'span',
144
- txt: ' to toggle Hot Reload'
145
- },
146
- {
147
- t: 'form',
148
- attr: {
149
- id: 'hrcheckbox',
150
- },
151
- events: {
152
- click: () => togglehotreload()
153
- },
154
- cn: ['p-2', 'bg-red-300'],
155
- children: [{
156
- t: 'label',
157
- txt: 'Hot Reload ',
158
- }
159
- , {
160
- t: 'input',
161
- cn: ['hrcheckbox'],
162
- attr: {
163
- type: 'checkbox'
164
- }
165
- }]
166
- }
167
- ]
168
- }))
25
+ appendElement(body, hotReloadBtn())
169
26
 
170
27
  togglehotreload();
171
28
  }
172
29
 
173
- //appendElement(body, gardener())
174
30
 
175
31
 
176
32
 
@@ -185,29 +41,6 @@ document.addEventListener('keydown', function(e) {
185
41
 
186
42
 
187
43
 
188
- function togglehotreload() {
189
- const hr = hotReload;
190
- const hrcheck = fetchElement('#hrcheckbox');
191
-
192
- localStorage.setItem('hotreload', hr);
193
-
194
- hotReload = !hotReload;
195
-
196
- if (hr) {
197
- hrcheck.style.background = '#66e666';
198
- fetchElement('.hrcheckbox').checked = true;
199
- localStorage.setItem('hotreload', 'true');
200
- hotReloadtimeout = setTimeout(() => window.location.reload(), 1000);
201
- }
202
- else {
203
- hrcheck.style.background = 'red';
204
- fetchElement('.hrcheckbox').checked = false;
205
- localStorage.setItem('hotreload', 'false');
206
- clearTimeout(hotReloadtimeout);
207
- }
208
-
209
- //localStorage.setItem('hotreload', hotReload);
210
- }
211
44
 
212
45
 
213
46
 
@@ -215,265 +48,98 @@ export function parserWindow(text) {
215
48
  if (mode !== 'dev') return;
216
49
 
217
50
 
218
- const result = gardener({
219
- t: 'div',
220
- cn: ['fixed', 'border-2', 'border-black', 'bg-gray-500', 'text-white', 'rounded-lg', 'z-90', 'w-2/4', 'h-2/4', 'left-1/4', 'flex', 'flex-col', 'justify-between', 'top-1/4'],
221
- children: [
222
- {
223
- t: 'div',
224
- cn: ['bg-gray-200', 'h-15', 'text-black', 'rounded-t-lg', 'flex', 'items-center', 'justify-around'],
225
- children: [
226
- {
227
- t: 'h3',
228
- cn: ['font-bold'],
229
- txt: 'Parser Window'
230
- },
231
- {
232
- t: 'div',
233
- cn: ['flex', 'gap-3'],
234
- children: [
235
- {
236
- t: 'button',
237
- cn: ['p-2', 'bg-green-300', 'rounded-lg', 'cursor-pointer'],
238
- txt: 'Copy Component',
239
- attr: { id: 'copybtn' },
240
- events: {
241
- click: () => { navigator.clipboard.writeText(text); fetchElement('#copybtn').innerText = 'copied'; }
242
- }
243
- },
244
- {
245
- t: 'button',
246
- cn: ['p-2', 'bg-red-300', 'rounded-lg', 'cursor-pointer'],
247
- txt: 'Add Component',
248
- events: {
249
- click: addComponentForm
250
- }
251
- }
252
- ]
253
- }
254
- ]
255
- },
256
- {
257
- t: 'p',
258
- cn: ['p-5', 'overflow-scroll'],
259
- txt: text
260
- },
261
- ]
262
- })
263
-
264
- function addComponentForm() {
265
- result.remove()
266
-
267
- const compform = gardener({
268
- t: 'form',
269
- events: {
270
- submit: (event) => {
271
- event.preventDefault()
272
- addComponent(text, `${fetchElement('.componentInp').value}`)
273
- compform.remove();
274
- }
275
- },
276
- cn: ['fixed', 'left-2/5', 'bg-gray-500', 'rounded-lg', 'block', 'top-2/5', 'p-2'],
277
- children: [
278
- {
279
- t: 'input',
280
- cn: ['bg-white', 'componentInp'],
281
- attr: {
282
- type: 'text',
283
- placeholder: 'Component Name'
284
- }
285
- }
286
- ]
287
- });
288
- appendElement(body, compform);
289
-
290
- fetchElement('.componentInp').focus();
291
- //setTimeout(() => result.remove(), 500);
292
- }
293
-
294
- appendElement(body, result);
295
- }
296
-
297
-
298
-
299
- async function addComponent(txt, path) {
300
- // await navigator.clipboard.writeText(txt);
301
- try {
302
- const res = await fetch('/addcomponent', {
303
- method: 'POST',
304
- headers: {
305
- "Content-Type": 'application/json'
306
- },
307
- body: JSON.stringify({ component: generateFile(txt, path), path: `${config.componentdir}/${path}.js` })
308
- })
309
-
310
- if (!res.ok) console.error('wrong');
51
+ const result = parserWindowComponent(text);
311
52
 
312
- const data = await res.json()
313
53
 
314
- }
315
- catch (err) {
316
- console.error(err);
317
- }
318
-
319
- }
320
-
321
- function opnPagedialog(btn = true) {
322
- if (btn) {
323
- const dialog = gardener({
324
- t: 'form', cn: ['addpageform', 'fixed', 'left-2/5', 'bg-gray-200', 'rounded-lg', 'block', 'top-2/5', 'p-2', 'flex', 'flex-col', 'p-5', 'gap-2'], events: {
325
- submit: async (e) => {
326
- try {
327
- e.preventDefault()
328
- const data = new FormData(e.target);
329
- const input = Object.fromEntries(data.entries());
330
-
331
- const response = await fetch('/addpage', {
332
- method: 'POST',
333
- headers: {
334
- "Content-Type": 'application/json'
335
- },
336
- body: JSON.stringify(input)
337
- }).then(res => res.json())
338
- opnPagedialog(false)
339
- window.location.href = `${input.page}`
340
- }
341
- catch (err) {
342
- console.log(err)
343
- }
344
-
345
- }
346
- }, children: [{
347
- t: 'label',
348
- txt: 'ENTER PATH FOR NEW PAGE'
349
- }, { t: 'input', attr: { name: 'page' }, cn: ['pathinput'] }]
350
-
351
- })
352
-
353
- appendElement(body, dialog);
354
- fetchElement('.pathinput').focus();
355
- }
356
- else {
357
- fetchElement('.addpageform').remove();
358
- }
54
+ appendElement(body, result);
359
55
  }
360
56
 
361
57
 
362
- function cleanStringAndList(input) {
363
- const pattern = /\?"?(\w+)"?\?/g;
364
- const vars = new Set();
365
- let match;
366
58
 
367
- while ((match = pattern.exec(input)) !== null) {
368
- vars.add(match[1]);
369
- }
370
-
371
- // Replace ?var? with "+var+" and clean up resulting empty strings or double quotes
372
- const cleanedString = input
373
- .replace(pattern, '"+$1+"')
374
- .replace(/^""\+/, '')
375
- .replace(/\+""$/, '');
376
59
 
377
- return {
378
- cleanedString,
379
- extractedList: [...vars].join(', ')
380
- };
381
- }
60
+ export function parser(element, isParent = true) {
61
+ try {
382
62
 
383
- function generateFile(obj, name) {
63
+ if (mode !== 'dev') return;
384
64
 
65
+ if (typeof element === 'string') {
66
+ element = fetchElement(element);
67
+ }
385
68
 
386
- const { cleanedString, extractedList } = cleanStringAndList(obj);
69
+ const obj = {
70
+ t: element.tagName.toLowerCase(),
71
+ };
387
72
 
388
- if (extractedList.length === 0) return `
389
- import { gardener, fetchElement, replaceElement } from '../gardener.js'
73
+ // add classes if present
74
+ if (element.classList.length) {
75
+ obj.cn = Array.from(element.classList);
76
+ }
390
77
 
391
- export function ${name}() {
392
- return gardener(${cleanedString})
393
- }
394
- `;
78
+ // add attributes if present
79
+ const attrs = {};
80
+ for (const attr of element.attributes) {
81
+ if (attr.name !== 'class') attrs[attr.name] = attr.value;
82
+ }
83
+ if (Object.keys(attrs).length) obj.attr = attrs;
84
+ // add text content (only if no children)
85
+ if (element.childNodes.length === 1 && element.firstChild.nodeType === Node.TEXT_NODE) {
86
+ obj.txt = element.textContent.trim();
395
87
 
396
- return `
397
- import { gardener, fetchElement, replaceElement } from '../gardener.js'
88
+ if (isParent) {
398
89
 
399
- export function ${name}({${extractedList}}) {
400
- return gardener(${cleanedString})
401
- }
402
- `;
403
- }
90
+ parserWindow(JSON.stringify(obj, null, 2))
91
+ }
404
92
 
93
+ return obj;
94
+ }
405
95
 
406
- // console.log(result.extractedList); // ["ritish"]
407
96
 
97
+ const children = [];
98
+ for (const child of element.childNodes) {
99
+ if (child.nodeType === Node.COMMENT_NODE) continue;
408
100
 
409
- export function parser(element, isParent = true) {
410
- if (typeof element === 'string') {
411
- element = fetchElement(element);
412
- }
101
+ if (child.nodeType === Node.TEXT_NODE && child.textContent.trim() === '') continue;
413
102
 
414
- const obj = {
415
- t: element.tagName.toLowerCase(),
416
- };
417
-
418
- // add classes if present
419
- if (element.classList.length) {
420
- obj.cn = Array.from(element.classList);
421
- }
103
+ if (child.nodeType === Node.TEXT_NODE) {
104
+ children.push({ t: 'span', txt: child.textContent.trim() });
105
+ continue;
106
+ }
107
+ children.push(parser(child, false));
108
+ }
109
+ if (children.length) obj.children = children;
422
110
 
423
- // add attributes if present
424
- const attrs = {};
425
- for (const attr of element.attributes) {
426
- if (attr.name !== 'class') attrs[attr.name] = attr.value;
427
- }
428
- if (Object.keys(attrs).length) obj.attr = attrs;
429
- // add text content (only if no children)
430
- if (element.childNodes.length === 1 && element.firstChild.nodeType === Node.TEXT_NODE) {
431
- obj.txt = element.textContent.trim();
432
111
 
433
112
  if (isParent) {
434
113
 
114
+
435
115
  parserWindow(JSON.stringify(obj, null, 2))
436
116
  }
437
117
 
438
- return obj;
439
- }
440
-
441
-
442
- // add children recursively
443
- const children = [];
444
- for (const child of element.childNodes) {
445
- if (child.nodeType === Node.COMMENT_NODE) continue;
118
+ return obj
446
119
 
447
- if (child.nodeType === Node.TEXT_NODE && child.textContent.trim() === '') continue;
448
120
 
449
- if (child.nodeType === Node.TEXT_NODE) {
450
- children.push({ t: 'span', txt: child.textContent.trim() });
451
- continue;
452
- }
453
- children.push(parser(child, false));
121
+ //Let Browser do the migration from html to json and then use copy paste
454
122
  }
455
- if (children.length) obj.children = children;
456
-
457
-
458
- if (isParent) {
459
-
460
-
461
- parserWindow(JSON.stringify(obj, null, 2))
123
+ catch (err) {
124
+ gardenerError(`parserError: ${err}`);
462
125
  }
463
126
 
464
- return obj
465
-
466
-
467
- //Let Browser do the migration from html to json and then use copy paste
468
127
  }
469
128
 
470
129
  export function addEl(parent, event, fun) {
471
- if (typeof parent === 'string') {
472
- parent = fetchElement(parent);
130
+ try {
131
+ if (typeof parent === 'string') {
132
+ parent = fetchElement(parent);
133
+ }
134
+ parent.addEventListener(event, fun)
135
+
136
+ }
137
+ catch (err) {
138
+ gardenerError(`addElError: ${err}`);
473
139
  }
474
- parent.addEventListener(event, fun)
475
140
  }
476
141
 
142
+
477
143
  export class State {
478
144
  constructor(value) {
479
145
  this.value = value;
@@ -1,4 +1,4 @@
1
- import { nextPagehandler, pageloader } from '/static/components/nonui/navigation.js';
1
+ import { nextPagehandler, pageloader } from './components/nonui/navigation.js';
2
2
 
3
- pageloader();
3
+ pageloader()
4
4
  nextPagehandler();
@@ -1,7 +1,11 @@
1
1
  import { copybtn } from "../components/copybtn.js";
2
+ import { pageloader } from "../components/nonui/navigation.js";
2
3
  import addNotification from "../components/notification.js";
3
- import { gardener, fetchElement, replaceElement, appendElement } from "/static/gardener.js";
4
- import { log, parser, addEl, State } from "/static/gardenerDev.js"
4
+ import { gardener, fetchElement, replaceElement, appendElement } from "../gardener.js";
5
+ import { log, parser, addEl, State } from "../gardenerDev.js"
6
+
7
+
8
+ // pageloader();
5
9
 
6
10
  addEl('.copybtn', 'click', () => {
7
11
  try {
@@ -18,3 +22,4 @@ addEl('.copybtn', 'click', () => {
18
22
 
19
23
 
20
24
 
25
+ // parser('body');
@@ -0,0 +1,2 @@
1
+ import { gardener, fetchElement, replaceElement, appendElement } from "../gardener.js";
2
+ import { log, parser, addEl, State } from "../gardenerDev.js"
@@ -0,0 +1,2 @@
1
+ import { gardener, fetchElement, replaceElement, appendElement } from "../gardener.js";
2
+ import { log, parser, addEl, State } from "../gardenerDev.js"
@@ -0,0 +1,2 @@
1
+ import { gardener, fetchElement, replaceElement, appendElement } from "../gardener.js";
2
+ import { log, parser, addEl, State } from "../gardenerDev.js"
@@ -0,0 +1,2 @@
1
+ import { gardener, fetchElement, replaceElement, appendElement } from "../gardener.js";
2
+ import { log, parser, addEl, State } from "../gardenerDev.js"