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.
- package/package.json +1 -1
- package/template/build/backend/controllers/gardener/addPage.d.ts.map +1 -1
- package/template/build/backend/controllers/gardener/addPage.js +31 -21
- package/template/build/backend/controllers/gardener/addPage.js.map +1 -1
- package/template/build/backend/controllers/gardener/createStatic.d.ts.map +1 -1
- package/template/build/backend/controllers/gardener/createStatic.js +3 -1
- package/template/build/backend/controllers/gardener/createStatic.js.map +1 -1
- package/template/build/backend/libs/generateWebp.d.ts.map +1 -1
- package/template/build/backend/libs/generateWebp.js +0 -2
- package/template/build/backend/libs/generateWebp.js.map +1 -1
- package/template/build/backend/routes/gardener.route.js +5 -0
- package/template/build/backend/routes/gardener.route.js.map +1 -1
- package/template/build/frontend/static/bundle/bundle._.js +1 -0
- package/template/build/frontend/static/bundle/bundle._about.js +1 -0
- package/template/build/frontend/static/bundle/bundle._kartik.js +1 -0
- package/template/build/frontend/static/bundle/bundle._new.js +1 -0
- package/template/build/frontend/static/bundle/bundle._ritish.js +1 -0
- package/template/build/frontend/static/cache/gardener_100x100.webp +0 -0
- package/template/build/frontend/static/components/copybtn.js +16 -3
- package/template/build/frontend/static/components/footer.js +33 -0
- package/template/build/frontend/static/components/gardener/errorBox.js +47 -0
- package/template/build/frontend/static/components/gardener/hotReloadbtn.js +82 -0
- package/template/build/frontend/static/components/gardener/pageOverlayBtn.js +138 -0
- package/template/build/frontend/static/components/gardener/parserWindow.js +159 -0
- package/template/build/frontend/static/components/nonui/api.js +15 -2
- package/template/build/frontend/static/components/nonui/navigation.js +2 -2
- package/template/build/frontend/static/components/notification.js +1 -1
- package/template/build/frontend/static/gardener.js +129 -58
- package/template/build/frontend/static/gardenerConfig.js +1 -1
- package/template/build/frontend/static/gardenerDev.js +67 -401
- package/template/build/frontend/static/global.js +2 -2
- package/template/build/frontend/static/pages/pages._.js +7 -2
- package/template/build/frontend/static/pages/pages._about.js +2 -0
- package/template/build/frontend/static/pages/pages._kartik.js +2 -0
- package/template/build/frontend/static/pages/pages._new.js +2 -0
- package/template/build/frontend/static/pages/pages._ritish.js +2 -0
- package/template/build/frontend/static/style.css +1 -1
- package/template/build/frontend/static/style2.css +2 -2
- package/template/build/frontend/views/_.ejs +6 -2
- package/template/build/frontend/views/_about.ejs +126 -0
- package/template/build/frontend/views/_kartik.ejs +126 -0
- package/template/build/frontend/views/_new.ejs +126 -0
- package/template/build/frontend/views/_ritish.ejs +126 -0
- package/template/buildHelper.js +33 -2
- package/template/package.json +2 -1
- package/template/pnpm-lock.yaml +271 -0
- package/template/src/backend/controllers/gardener/addPage.ts +7 -1
- package/template/src/backend/controllers/gardener/createStatic.ts +94 -59
- package/template/src/backend/controllers/gardener/index.ts +0 -1
- package/template/src/backend/routes/gardener.route.ts +1 -2
- package/template/src/frontend/bundle/bundle._.js +2 -0
- package/template/src/frontend/bundle/bundle._about.js +1 -0
- package/template/src/frontend/bundle/bundle._kartik.js +1 -0
- package/template/src/frontend/bundle/bundle._new.js +1 -0
- package/template/src/frontend/bundle/bundle._ritish.js +1 -0
- package/template/src/frontend/static/components/nonui/navigation.js +2 -2
- package/template/src/frontend/static/components/notification.js +1 -1
- package/template/src/frontend/static/gardenerDev.js +2 -2
- package/template/src/frontend/static/global.js +1 -1
- package/template/src/frontend/static/pages/pages._.js +2 -2
- package/template/src/frontend/static/style.css +61 -31
- package/template/src/frontend/template/template._.ejs +5 -1
- package/template/src/frontend/views/_.ejs +6 -2
- package/template/build/frontend/static/gardener.test.js +0 -364
- package/template/build/frontend/static/zod.js +0 -8
- package/template/buildHelper.test.js +0 -78
- package/template/jest.config.js +0 -13
- package/template/src/frontend/static/gardener.test.js +0 -364
- package/template/src/frontend/static/zod.js +0 -8
|
@@ -1,124 +1,20 @@
|
|
|
1
|
-
import { mode } from '
|
|
2
|
-
import { gardener, appendElement, fetchElement } from '
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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,
|
|
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 =
|
|
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
|
-
|
|
378
|
-
|
|
379
|
-
extractedList: [...vars].join(', ')
|
|
380
|
-
};
|
|
381
|
-
}
|
|
60
|
+
export function parser(element, isParent = true) {
|
|
61
|
+
try {
|
|
382
62
|
|
|
383
|
-
|
|
63
|
+
if (mode !== 'dev') return;
|
|
384
64
|
|
|
65
|
+
if (typeof element === 'string') {
|
|
66
|
+
element = fetchElement(element);
|
|
67
|
+
}
|
|
385
68
|
|
|
386
|
-
|
|
69
|
+
const obj = {
|
|
70
|
+
t: element.tagName.toLowerCase(),
|
|
71
|
+
};
|
|
387
72
|
|
|
388
|
-
|
|
389
|
-
|
|
73
|
+
// add classes if present
|
|
74
|
+
if (element.classList.length) {
|
|
75
|
+
obj.cn = Array.from(element.classList);
|
|
76
|
+
}
|
|
390
77
|
|
|
391
|
-
|
|
392
|
-
|
|
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
|
-
|
|
397
|
-
import { gardener, fetchElement, replaceElement } from '../gardener.js'
|
|
88
|
+
if (isParent) {
|
|
398
89
|
|
|
399
|
-
|
|
400
|
-
|
|
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
|
-
|
|
410
|
-
if (typeof element === 'string') {
|
|
411
|
-
element = fetchElement(element);
|
|
412
|
-
}
|
|
101
|
+
if (child.nodeType === Node.TEXT_NODE && child.textContent.trim() === '') continue;
|
|
413
102
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
obj.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
472
|
-
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,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 "
|
|
4
|
-
import { log, parser, addEl, State } from "
|
|
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');
|