cradova 1.2.0 → 1.3.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/dist/types.ts ADDED
@@ -0,0 +1,402 @@
1
+ export type CradovaElementType = Record<string, any>;
2
+ // FIXME: This is too rough for use a type for cradova element type
3
+ // replaced with any for
4
+
5
+ /**
6
+ * Creates new cradova HTML element
7
+ * @example
8
+ * _("p") // or _("p.class") or _("p#id") or _("p.class#id")
9
+ * using inline props
10
+ * _("p",{
11
+ * text: "am a p tag",
12
+ * style: {
13
+ * color: "blue"
14
+ * }
15
+ * )
16
+ * adding children
17
+ * _("p",
18
+ * _("span",{text:" am a span tag like so",
19
+ * {style: {color: "brown"}
20
+ * })
21
+ * )
22
+ *
23
+ * props and children
24
+ * _("p",
25
+ * // props first
26
+ * {
27
+ * text: "am a p tag",
28
+ * style: {
29
+ * color: "blue"
30
+ * },
31
+ * // all children goes after
32
+ * _("span",{text:" am a span tag like so",
33
+ * {style: {color: "brown"}
34
+ * })
35
+ * )
36
+ *
37
+ * @param {...any} element_initials
38
+ * @returns function - cradova element
39
+ */
40
+
41
+ export type CradovaHTMLElementType = (
42
+ ...element_initials: any[]
43
+ ) =>
44
+ | ((...element_initials: any[]) => "NO TEMPLATE STRING PROVIDED")
45
+ | ((...element_initials: any[]) => HTMLElement | undefined);
46
+
47
+ export type CradovaScreenType = {
48
+ /**
49
+ * Cradova screen
50
+ * ---
51
+ * title of the page
52
+ * @param data
53
+ * @returns void
54
+ *
55
+ *
56
+ * .
57
+ *
58
+ */
59
+ name: string;
60
+ /**
61
+ * Cradova screen
62
+ * ---
63
+ * The component for the screen
64
+ * @param data
65
+ * @returns void
66
+ *
67
+ *
68
+ * .
69
+ *
70
+ */
71
+ template: Function | HTMLElement;
72
+ /**
73
+ * Cradova screen
74
+ * ---
75
+ * Screen transition from the screen class
76
+ * @param data
77
+ * @returns void
78
+ *
79
+ *
80
+ * .
81
+ *
82
+ */
83
+ transition?: string;
84
+ /**
85
+ * Cradova screen
86
+ * ---
87
+ * gets called when the the screen is displayed
88
+ * @param data
89
+ * @returns void
90
+ *
91
+ *
92
+ * .
93
+ *
94
+ */
95
+ onActivate: (fn: (data: any) => void) => Promise<void>;
96
+ /**
97
+ * Cradova screen
98
+ * ---
99
+ * Should this screen be cached after first render?
100
+ * @param data
101
+ * @returns void
102
+ *
103
+ *
104
+ * .
105
+ *
106
+ */
107
+ persist?: boolean;
108
+ /**
109
+ * Cradova screen
110
+ * ---
111
+ * run once on first render and update the screen immediately.
112
+ * @param fn () => void
113
+ * @returns void
114
+ *
115
+ *
116
+ * .
117
+ *
118
+ */
119
+ effect(fn: () => void | Promise<void>): void;
120
+ /**
121
+ * Cradova screen
122
+ * ---
123
+ * runs on first render.
124
+ * @param data
125
+ * @returns void
126
+ *
127
+ *
128
+ * .
129
+ *
130
+ */
131
+ updateState: (data: any) => any;
132
+ };
133
+
134
+ export type RefType = {
135
+ /**
136
+ * Cradova Ref
137
+ * ---
138
+ * returns html with cradova reference
139
+ * @param data
140
+ * @returns html
141
+ *
142
+ *
143
+ * .
144
+ *
145
+ */
146
+ render: (data: any) => () => HTMLElement;
147
+ /**
148
+ * Cradova Ref
149
+ * ---
150
+ * update ref component with new data and update the dom.
151
+ * @param data
152
+ * @returns void
153
+ *
154
+ *
155
+ * .
156
+ *
157
+ */
158
+ updateState: (data: any) => any;
159
+ /**
160
+ * Cradova Ref
161
+ * ---
162
+ * runs on first render and every update.
163
+ * @returns void
164
+ *
165
+ * .
166
+ */
167
+ effect: (fn: () => any) => void;
168
+ };
169
+
170
+ /**
171
+ * Cradova Signal
172
+ * ----
173
+ * create stateful data store.
174
+ * ability to:
175
+ * - create a store
176
+ * - create actions and fire them
177
+ * - bind a Ref or RefList
178
+ * - listen to changes
179
+ * - persist changes to localStorage
180
+ * - go back and forward in value history
181
+ * - set keys instead of all values
182
+ * - update a cradova Ref/RefList automatically
183
+ * @constructor initial: any, props: {useHistory, persist}
184
+ */
185
+
186
+ export type SignalType = {
187
+ // constructor(
188
+ // initial: unknown,
189
+ // props?: { useHistory?: boolean; persistName?: string | undefined }
190
+ // ): void;
191
+ /**
192
+ * Cradova Signal
193
+ * ----
194
+ * current value of this signal*/
195
+ value: any;
196
+ /**
197
+ * Cradova Signal
198
+ * ----
199
+ * set signal value
200
+ * @param value - signal value
201
+ * @returns void
202
+ *
203
+ *
204
+ * .
205
+ *
206
+ */
207
+ set: (value: unknown, shouldRefRender?: boolean) => void;
208
+
209
+ /**
210
+ * Cradova Signal
211
+ * ----
212
+ * set a key value if it's an object
213
+ * @param name - name of the key
214
+ * @param value - value of the key
215
+ * @returns void
216
+ *
217
+ *
218
+ * .
219
+ *
220
+ */
221
+
222
+ setKey: (name: string, value: any, shouldRefRender?: boolean) => void;
223
+ /**
224
+ * Cradova Signal
225
+ * ----
226
+ * set a prop value inside an object prop of the store
227
+ * @param key - a prop of the store - object value
228
+ * @param name - prop of the key object
229
+ * @param value - value of the name
230
+ * @returns void
231
+ *
232
+ *
233
+ * .
234
+ *
235
+ */
236
+
237
+ setPath: (
238
+ key: string,
239
+ name: string,
240
+ value: any,
241
+ shouldRefRender?: boolean
242
+ ) => void;
243
+ /**
244
+ * Cradova Signal
245
+ * ----
246
+ * set a prop value inside an array prop of the store
247
+ * @param key - a prop of the store - object value
248
+ * @param index - index of the key object
249
+ * @param value - value of the index
250
+ * @returns void
251
+ *
252
+ *
253
+ * .
254
+ *
255
+ */
256
+ setIndex: (
257
+ key: string,
258
+ index: number,
259
+ value: any,
260
+ shouldRefRender?: boolean
261
+ ) => void;
262
+ /**
263
+ * Cradova Signal
264
+ * ----
265
+ * set a key to signal an action
266
+ * @param name - name of the action
267
+ * @param action function to execute
268
+ */
269
+ createAction: (
270
+ name: string | Record<string, (self?: any, data?: any) => void>,
271
+ action?: (self?: any, data?: any) => void
272
+ ) => void;
273
+ /**
274
+ * Cradova Signal
275
+ * ----
276
+ * fires an action if available
277
+ * @param name - string name of the action
278
+ * @param data - data for the action
279
+ */
280
+ fireAction: (name: string, data?: any) => void;
281
+
282
+ /**
283
+ * Cradova Signal
284
+ * ----
285
+ * set a auto - rendering component for this store
286
+ *
287
+ * @param Ref component to bind to.
288
+ * @param path a property in the object to send to attached ref
289
+ */
290
+ bindRef: (Ref: any, path?: string) => void;
291
+ /**
292
+ * Cradova Signal
293
+ * ----
294
+ * set signal value to a future one
295
+ * @returns void
296
+ *
297
+ *
298
+ * .
299
+ *
300
+ */
301
+ forward: (data: any) => any;
302
+ /**
303
+ * Cradova Signal
304
+ * ----
305
+ * set signal value to a old past one
306
+ * @returns void
307
+ *
308
+ *
309
+ * .
310
+ *
311
+ */
312
+ backward: () => void;
313
+ /**
314
+ * Cradova Signal
315
+ * ----
316
+ * set a update listener on value changes
317
+ * @param callback
318
+ */
319
+ listen: (callback: (a: any) => void) => void;
320
+ /**
321
+ * Cradova Signal
322
+ * ----
323
+ * get value */
324
+ get: () => any;
325
+ /**
326
+ * Cradova Signal
327
+ * ----
328
+ * clear the history on local storage
329
+ */
330
+ clearPersist: (data: any) => void;
331
+ };
332
+
333
+ export type RouterRouteObject = {
334
+ controller: (params: object, force?: boolean) => any;
335
+ deactivate: (params: object) => any;
336
+ packager: (params: any) => void;
337
+ };
338
+
339
+ /**
340
+ * Cradova Router
341
+ * ---
342
+ * Facilitates navigation within the application and initializes
343
+ * page views based on the matched routes.
344
+ */
345
+
346
+ export type RouterType =
347
+ | {
348
+ /**
349
+ * Registers a route.
350
+ *
351
+ * @param {string} path Route path.
352
+ * @param {any} screen the cradova document tree for the route.
353
+ */
354
+ route: (path: string, screen: CradovaScreenType) => void;
355
+ routes: Record<string, RouterRouteObject>;
356
+ lastNavigatedRoute: string | null;
357
+ lastNavigatedRouteController: RouterRouteObject | null;
358
+ nextRouteController: RouterRouteObject | null;
359
+ params: Record<string, any>;
360
+ /**
361
+ * n/a
362
+ */
363
+ router: (e: any, force?: boolean) => void;
364
+ /**
365
+ * get a screen ready before time.
366
+ *
367
+ * @param {string} path Route path.
368
+ * @param {any} data data for the screen.
369
+ */
370
+ packageScreen: (path: string, data?: any) => void;
371
+ pageShow: ((path: string) => void) | null;
372
+ pageHide: ((path: string) => void) | null;
373
+ onPageShow: (callback: () => void) => void;
374
+ onPageHide: (callback: () => void) => void;
375
+ /**
376
+ * Cradova Router
377
+ * ------
378
+ *
379
+ * Navigates to a designated screen in your app
380
+ */
381
+ navigate: (
382
+ href: string,
383
+ data?: Record<string, any> | null,
384
+ force?: boolean
385
+ ) => void;
386
+ }
387
+ | Record<string, any>;
388
+
389
+ export type fragmentTYPE = () => (() => HTMLElement) | HTMLElement;
390
+
391
+ /**
392
+ *
393
+ * Cradova Ajax
394
+ * ------------------
395
+ * your new axios alternative
396
+ * supports files upload
397
+ * @param url - string
398
+ * @param opts - {method?: string; data?: object; header?: object; callbacks?: function;}
399
+ * @returns any
400
+ */
401
+
402
+ export type Ajax = (url: string | URL, opts?: any) => Promise<any>;
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "cradova",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Web framework for building web apps and PWAs",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
7
7
  "files": [
8
- "dist/index.d.ts"
8
+ "dist/index.d.ts",
9
+ "dist/types.ts"
9
10
  ],
10
11
  "repository": {
11
12
  "type": "git",