cradova 1.0.8 → 1.0.10

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 (46) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/index.d.ts +9 -391
  3. package/dist/index.js +53 -34
  4. package/dist/module.d.ts +437 -0
  5. package/dist/module.d.ts.map +1 -0
  6. package/dist/module.js +131 -87
  7. package/dist/module.js.map +1 -1
  8. package/dist/sacho/loadCss.d.ts +1 -0
  9. package/dist/sacho/swipe.d.ts +12 -0
  10. package/dist/sacho/swipe.js +13 -25
  11. package/dist/sacho/swipe1.d.ts +12 -0
  12. package/dist/scripts/Router.d.ts +8 -0
  13. package/dist/scripts/Router.js +3 -5
  14. package/dist/scripts/Scaffold.d.ts +8 -0
  15. package/dist/scripts/Scaffold.js +19 -5
  16. package/dist/scripts/Screen.d.ts +54 -0
  17. package/dist/scripts/Screen.js +40 -29
  18. package/dist/scripts/ajax.d.ts +16 -0
  19. package/dist/scripts/createSignal.d.ts +124 -0
  20. package/dist/scripts/fns.d.ts +151 -0
  21. package/dist/scripts/fns.js +15 -3
  22. package/dist/scripts/init.d.ts +1 -0
  23. package/dist/scripts/init.js +4 -3
  24. package/dist/scripts/track.d.ts +8 -0
  25. package/dist/scripts/track.js +6 -1
  26. package/dist/scripts/utils.d.ts +1 -0
  27. package/dist/scripts/utils.js +10 -0
  28. package/dist/types.d.ts +248 -0
  29. package/package.json +28 -11
  30. package/tsconfig.json +2 -2
  31. package/dist/index.d.ts.map +0 -1
  32. package/dist/index.js.map +0 -1
  33. package/src/index.ts +0 -496
  34. package/src/sacho/loadCss.ts +0 -216
  35. package/src/sacho/style.css +0 -187
  36. package/src/sacho/swipe.ts +0 -138
  37. package/src/sacho/swipe1.ts +0 -136
  38. package/src/scripts/Router.ts +0 -269
  39. package/src/scripts/Scaffold.ts +0 -51
  40. package/src/scripts/Screen.ts +0 -180
  41. package/src/scripts/ajax.ts +0 -83
  42. package/src/scripts/createSignal.ts +0 -273
  43. package/src/scripts/fns.ts +0 -615
  44. package/src/scripts/init.ts +0 -9
  45. package/src/scripts/track.ts +0 -158
  46. package/src/types.ts +0 -287
package/CHANGELOG.md CHANGED
@@ -36,3 +36,9 @@ and we went along with it.
36
36
  - bug fixes
37
37
  - big performance gain
38
38
  - battle testing green
39
+
40
+ ## 1.0.7
41
+
42
+ - bug fixes
43
+ - big performance gain
44
+ - battle testing green
package/dist/index.d.ts CHANGED
@@ -1,392 +1,12 @@
1
- /**
2
- * swipe
3
- * ---
4
- * Now you can detect swipes the best way possible
5
- *
6
- * @param callabck
7
- * @param touching?
8
- */
9
- export function swipe(callabck: (swipe_data: Record<string, number>) => void, touching?: boolean): {
10
- start(): void;
11
- stop(): void;
12
- };
13
- /**
14
- * Cradova Signal
15
- * ----
16
- * create stateful data store.
17
- * ability to:
18
- * - create a store
19
- * - create actions and fire them
20
- * - bind a Ref or RefList
21
- * - listen to changes
22
- * - persist changes to localStorage
23
- * - go back and forward in value history
24
- * - set keys instead of all values
25
- * - update a cradova Ref/RefList automatically
26
- * @constructor initial: any, props: {useHistory, persist}
27
- */
28
- export class createSignal {
29
- value: any;
30
- constructor(initial: unknown, props?: {
31
- useHistory?: boolean;
32
- persistName?: string | undefined;
33
- });
34
- /**
35
- * Cradova Signal
36
- * ----
37
- * set signal value
38
- * @param value - signal value
39
- * @returns void
40
- */
41
- set(value: unknown, shouldRefRender?: boolean): void;
42
- /**
43
- * Cradova Signal
44
- * ----
45
- * set a key value if it's an object
46
- * @param name - name of the key
47
- * @param value - value of the key
48
- * @returns void
49
- */
50
- setKey(name: string, value: any, shouldRefRender?: boolean): void;
51
- /**
52
- * Cradova Signal
53
- * ----
54
- * set a prop value inside an object prop of the store
55
- * @param key - a prop of the store - object value
56
- * @param name - prop of the key object
57
- * @param value - value of the name
58
- * @returns void
59
- */
60
- setPath(key: string, name: string, value: any, shouldRefRender?: boolean): void;
61
- /**
62
- * Cradova Signal
63
- * ----
64
- * set a prop value inside an array prop of the store
65
- * @param key - a prop of the store - object value
66
- * @param index - index of the key object
67
- * @param value - value of the index
68
- * @returns void
69
- */
70
- setIndex(key: string, index: number, value: any, shouldRefRender?: boolean): void;
71
- /**
72
- * Cradova Signal
73
- * ----
74
- * set a key to signal an action
75
- * @param name - name of the action
76
- * @param action function to execute
77
- */
78
- createAction(name: string | Record<string, (self?: any, data?: any) => void>, action?: (self?: any, data?: any) => void): void;
79
- /**
80
- * Cradova Signal
81
- * ----
82
- * fires an action if available
83
- * @param name - string name of the action
84
- * @param data - data for the action
85
- */
86
- fireAction(name: string, data?: any): void;
87
- /**
88
- * Cradova Signal
89
- * ----
90
- * set a auto - rendering component for this store
91
- *
92
- * @param Ref component to bind to.
93
- * @param path a property in the object to send to attached ref
94
- */
95
- bindRef(Ref: any, path?: string): void;
96
- /**
97
- * Cradova Signal
98
- * ----
99
- * set signal value to a future one
100
- * @returns void
101
- */
102
- forward(): void;
103
- /**
104
- * Cradova Signal
105
- * ----
106
- * set signal value to a old past one
107
- * @returns void
108
- */
109
- backward(): void;
110
- /**
111
- * Cradova Signal
112
- * ----
113
- * set a update listener on value changes
114
- * @param callback
115
- */
116
- listen(callback: (a: any) => void): void;
117
- /**
118
- * Cradova Signal
119
- * ----
120
- * get value */
121
- get(): any;
122
- /**
123
- * Cradova Signal
124
- * ----
125
- * clear the history on local storage
126
- */
127
- clearPersist(): void;
128
- }
129
- type CradovaScreenType = {
130
- name: string;
131
- template: Function | HTMLElement;
132
- transition?: string;
133
- callBack?: (html?: any, data?: Record<string, any>) => void;
134
- persist?: boolean;
135
- effect: (fn: () => any) => void;
136
- };
137
- type RouterRouteObject = {
138
- controller: (params: object, force?: boolean) => any;
139
- deactivate: (params: object) => any;
140
- packager: (params: any) => void;
141
- };
142
- /**
143
- * Cradova Router
144
- * ---
145
- * Facilitates navigation within the application and initializes
146
- * page views based on the matched routes.
147
- */
148
- type RouterType = {
149
- /**
150
- * Registers a route.
151
- *
152
- * @param {string} path Route path.
153
- * @param {any} screen the cradova document tree for the route.
154
- */
155
- route: (path: string, screen: CradovaScreenType) => void;
156
- routes: Record<string, RouterRouteObject>;
157
- lastNavigatedRoute: string | null;
158
- lastNavigatedRouteController: RouterRouteObject | null;
159
- nextRouteController: RouterRouteObject | null;
160
- params: Record<string, any>;
161
- /**
162
- * n/a
163
- */
164
- router: (e: any, force?: boolean) => void;
165
- /**
166
- * get a screen ready before time.
167
- *
168
- * @param {string} path Route path.
169
- * @param {any} data data for the screen.
170
- */
171
- packageScreen: (path: string, data?: any) => void;
172
- pageShow: ((path: string) => void) | null;
173
- pageHide: ((path: string) => void) | null;
174
- onPageShow: (callback: () => void) => void;
175
- onPageHide: (callback: () => void) => void;
176
- /**
177
- * Cradova Router
178
- * ------
179
- *
180
- * Navigates to a designated screen in your app
181
- */
182
- navigate: (href: string, data?: Record<string, any> | null, force?: boolean) => void;
183
- } | Record<string, any>;
184
- /**
185
- * Cradova Router
186
- * ---
187
- * Facilitates navigation within the application and initializes
188
- * page views based on the matched routes.
189
- */
190
- export const Router: RouterType;
191
- /**
192
- * @param name
193
- * @param template
194
- * @param transitions
195
- */
196
- export class Screen {
197
- /**
198
- * this is the name of the screen that appears as the title
199
- */
200
- name: string;
201
- secondaryChildren: Array<any>;
202
- static SCALE_IN: string;
203
- static SCALE_OUT: string;
204
- static CIRCLE_IN: string;
205
- static CIRCLE_OUT: string;
206
- static FADE_OUT: string;
207
- static FADE_IN: string;
208
- static SLIDE_UP: string;
209
- static SLIDE_DOWN: string;
210
- static SLIDE_LEFT: string;
211
- static SLIDE_RIGHT: string;
212
- /**
213
- * this tells cradova to persist state on the screen or not
214
- * persisting is better
215
- */
216
- persist: boolean;
217
- rendered: boolean;
218
- constructor(cradova_screen_initials: CradovaScreenType);
219
- effect(fn: () => unknown | Promise<unknown>): Promise<void>;
220
- package(data: any): Promise<void>;
221
- onActivate(cb: (data: any) => void): void;
222
- onDeactivate(cb: (data: any) => void): void;
223
- addChild(...addOns: any[]): void;
224
- detach(): void;
225
- Activate(data: any, force: boolean): Promise<void>;
226
- }
227
- export class Scaffold {
228
- push(label: string, data?: unknown, force?: boolean): Promise<void>;
229
- pop(data?: unknown, force?: boolean): Promise<void>;
230
- addScaffolds(scaffolds: Record<string, CradovaScreenType>): Promise<void>;
231
- }
232
- export const controls: () => void;
233
- export function uuid(num?: number): string;
234
- export function PromptBeforeLeave(callback?: (e: any) => void): void;
235
- /**
236
- Write CSS media in javascript
237
-
238
- @example
239
-
240
- _.media("min-width: 790px",
241
- ["#container",
242
- {
243
- width: "100%",
244
- height: "100%",
245
- "background-color": "#0000"
246
- }],
247
-
248
- ["#header",
249
- {
250
- width: "100%",
251
- height: "20%",
252
- "background-color": "#fff"
253
- }]
254
- )
255
- */
256
- export function media(value: string, ...properties: any[]): void;
257
- /**
258
- Write CSS styles in Javascript
259
- @example
260
-
261
- css("#container",
262
- {
263
- height: "100%",
264
- height: "100%",
265
- background-color: "#ff9800"
266
- })
267
-
268
- css(".btn:hover",
269
- {
270
- height: "100%",
271
- height: "100%",
272
- background-color: "#ff9800"
273
- })
274
-
275
- */
276
- export function css(identifier: string, properties: Record<string, string>): void;
277
- /**
278
- Write animation value in javascript
279
-
280
- @example
281
-
282
- _.animate("polarization",
283
- ["from",
284
- {
285
- transform: "scale3D(2)" ,
286
- height: "10%",
287
- "background-color": "#0000"
288
- }],
289
-
290
- ["to",
291
- {
292
- transform: "scale3D(1)" ,
293
- height: "100%",
294
- "background-color": "#ff9800"
295
- }]
296
- )
297
-
298
- */
299
- export function animate(identifier: string, ...properties: any[]): void;
300
- /**
301
- *
302
- * @param {expression} condition
303
- * @param {function} callback
304
- */
305
- export function assert(condition: any, ...callback: (() => any)[]): "" | (() => any)[];
306
- export function assertOr(condition: any, ifTrue: () => any, ifFalse: () => any): () => any;
307
- /**
308
- * Create element and get a callback to update their state
309
- * no need to manage stateIDs
310
- * ----------------------------------------------------------------
311
- *
312
- * @param element_initials
313
- * @param props
314
- * @returns
315
- */
316
- export function RefElement(element_initials?: string, props?: Record<string, string>): {
317
- render(data: any): any;
318
- updateState(state: Record<string, any>): void;
319
- };
320
- export const ls: Record<string, Function>;
321
- export function fullScreen(e: Element): {
322
- set(): void;
323
- exist(): void;
324
- };
325
- export class RefList {
326
- constructor(component: (...data: any) => any);
327
- stale(datas: any): void;
328
- render(datas?: any): any;
329
- updateState(datas: any[]): void;
330
- }
331
- /**
332
- * Cradova Ref
333
- * -------
334
- * create dynamic components
335
- *
336
- */
337
- export class Ref {
338
- constructor(component: (...data: any) => any);
339
- stale(...data: any): void;
340
- /**
341
- * Cradova Ref
342
- * ---
343
- * returns html with cradova reference
344
- * @param data
345
- * @returns html
346
- */
347
- render(...data: any): () => any;
348
- onStateUpdate(cb: any): void;
349
- /**
350
- * Cradova Ref
351
- * ---
352
- * update ref component with new data and update the dom.
353
- * @param data
354
- * @returns void
355
- */
356
- updateState(...data: any): void;
357
- remove(): void;
358
- }
359
- /**
360
- * Document fragment
361
- * @param children
362
- * @returns
363
- */
364
- type fragmentTYPE = () => (() => HTMLElement) | HTMLElement;
365
- export const frag: (...children: fragmentTYPE[]) => DocumentFragment;
366
- /**
367
- * Send a new state to specified element with stateID
368
- *
369
- * @param stateID
370
- * @param state
371
- * @returns element(s)
372
- */
373
- export function dispatch(stateID: string | Record<string, any>, state?: Record<string, any>): Node[];
374
- /**
375
- *
376
- * Cradova Ajax
377
- * ------------------
378
- * your new axios alternative
379
- * supports files upload
380
- * @param url string
381
- * @param {{method: string;data;header;callbacks;}} opts
382
- * @returns any
383
- */
384
- export function Ajax(url: string | URL, opts?: {
385
- method?: string;
386
- data?: Record<string, any>;
387
- header?: Record<string, any>;
388
- callbacks?: Record<string, (arg: any) => void>;
389
- } | any): Promise<unknown>;
1
+ export { swipe } from "./sacho/swipe";
2
+ export { Signal as createSignal } from "./scripts/createSignal";
3
+ export { Router } from "./scripts/Router";
4
+ export { Screen } from "./scripts/Screen";
5
+ export { Scaffold } from "./scripts/Scaffold";
6
+ export { dispatch } from "./scripts/track";
7
+ export { Ajax } from "./scripts/ajax";
8
+ export { IsElementInView } from "./scripts/utils";
9
+ export { frag, fullScreen, assert, uuid, animate, controls, PromptBeforeLeave, RefElement, css, media, ls, Ref, RefList, assertOr, } from "./scripts/fns";
390
10
  /**
391
11
  * Creates new cradova HTML element
392
12
  * @example
@@ -424,5 +44,3 @@ export function Ajax(url: string | URL, opts?: {
424
44
  */
425
45
  declare const _: any;
426
46
  export default _;
427
-
428
- //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-undef */
1
2
  /*
2
3
 
3
4
  """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
@@ -46,6 +47,7 @@ export { Screen } from "./scripts/Screen";
46
47
  export { Scaffold } from "./scripts/Scaffold";
47
48
  export { dispatch } from "./scripts/track";
48
49
  export { Ajax } from "./scripts/ajax";
50
+ export { IsElementInView } from "./scripts/utils";
49
51
  export { frag, fullScreen, assert, uuid, animate, controls, PromptBeforeLeave, RefElement, css, media, ls, Ref, RefList, assertOr, } from "./scripts/fns";
50
52
  import { Init } from "./scripts/init";
51
53
  ("use strict");
@@ -190,24 +192,14 @@ const _ = (...element_initials) => {
190
192
  let childrens2rd = [], props = {}, text;
191
193
  for (let i = 0; i < incoming.length; i++) {
192
194
  if (typeof incoming[i] === "function" ||
193
- incoming[i] instanceof HTMLElement
194
- // ||
195
- // incoming[i].tagName
196
- ) {
195
+ incoming[i] instanceof HTMLElement) {
197
196
  childrens2rd.push(incoming[i]);
198
197
  continue;
199
198
  }
200
- if (
201
- // !incoming[i].tagName &&
202
- !(incoming[i] instanceof HTMLElement) &&
203
- !Array.isArray(incoming[i]) &&
204
- typeof incoming[i] === "object" &&
205
- !incoming[i].tagName) {
199
+ if (!Array.isArray(incoming[i]) && typeof incoming[i] === "object") {
206
200
  if (incoming[i].beforeMount) {
207
201
  beforeMount = incoming[i]["beforeMount"];
208
- continue;
209
- }
210
- if (incoming[i].composedPath) {
202
+ incoming[i]["beforeMount"] = undefined;
211
203
  continue;
212
204
  }
213
205
  props = incoming[i];
@@ -219,6 +211,8 @@ const _ = (...element_initials) => {
219
211
  continue;
220
212
  }
221
213
  }
214
+ // @ts-ignore
215
+ incoming = undefined;
222
216
  if (childrens.length) {
223
217
  childrens2rd.push(...childrens);
224
218
  }
@@ -236,15 +230,26 @@ const _ = (...element_initials) => {
236
230
  element.className = initials.className.trim();
237
231
  }
238
232
  if (initials.ID) {
239
- element.id = initials.ID.trim();
233
+ element.setAttribute("id", initials.ID.trim());
240
234
  }
241
235
  if (initials.innerValue) {
242
- element.append(initials.innerValue);
236
+ element.innerText = initials.innerValue;
243
237
  }
244
238
  for (const prop in properties) {
245
239
  if (prop === "style" && typeof properties[prop] === "object") {
246
240
  for (const [k, v] of Object.entries(properties[prop])) {
247
- element.style[k] = v;
241
+ if ((element.style[k] === "" && k !== "src") ||
242
+ typeof element.style[k] === "string") {
243
+ element.style[k] = v;
244
+ }
245
+ else {
246
+ console.error(element);
247
+ throw new Error("✘ Cradova err : " +
248
+ element +
249
+ " does not have " +
250
+ k +
251
+ " as a valid css style property");
252
+ }
248
253
  }
249
254
  continue;
250
255
  }
@@ -262,7 +267,7 @@ const _ = (...element_initials) => {
262
267
  continue;
263
268
  }
264
269
  if (prop === "text") {
265
- element.innerText = properties[prop];
270
+ text = properties[prop];
266
271
  continue;
267
272
  }
268
273
  try {
@@ -283,7 +288,14 @@ const _ = (...element_initials) => {
283
288
  for (const prop in props) {
284
289
  if (prop === "style" && typeof props[prop] === "object") {
285
290
  for (const [k, v] of Object.entries(props[prop])) {
286
- element.style[k] = v;
291
+ if (typeof element.style[k] !== "undefined" && k !== "src") {
292
+ element.style[k] = v;
293
+ }
294
+ else {
295
+ throw new Error("✘ Cradova err : " +
296
+ k +
297
+ " is not a valid css style property");
298
+ }
287
299
  }
288
300
  continue;
289
301
  }
@@ -292,7 +304,7 @@ const _ = (...element_initials) => {
292
304
  continue;
293
305
  }
294
306
  if (prop === "text" && typeof props[prop] === "string") {
295
- element.innerText = props[prop];
307
+ text = props[prop];
296
308
  continue;
297
309
  }
298
310
  if (prop === "class" && typeof props[prop] === "string") {
@@ -301,6 +313,7 @@ const _ = (...element_initials) => {
301
313
  }
302
314
  if (prop === "beforeMount") {
303
315
  beforeMount = props["beforeMount"];
316
+ props["beforeMount"] = undefined;
304
317
  continue;
305
318
  }
306
319
  try {
@@ -365,8 +378,7 @@ const _ = (...element_initials) => {
365
378
  }
366
379
  const child = childrens2rd[i];
367
380
  if (child instanceof HTMLElement ||
368
- child instanceof DocumentFragment ||
369
- typeof child === "string") {
381
+ child instanceof DocumentFragment) {
370
382
  element.append(child);
371
383
  // @ts-ignore
372
384
  if (child.afterMount) {
@@ -377,20 +389,23 @@ const _ = (...element_initials) => {
377
389
  }
378
390
  }
379
391
  else {
380
- console.error(" ✘ Cradova err: got", child);
381
- throw new Error(" ✘ Cradova err: invalid child type: " +
382
- "(" +
383
- typeof child +
384
- ")");
392
+ if (typeof child === "string") {
393
+ text = child;
394
+ }
395
+ else {
396
+ console.error(" ✘ Cradova err: got", child);
397
+ throw new Error(" ✘ Cradova err: invalid child type: " +
398
+ "(" +
399
+ typeof child +
400
+ ")");
401
+ }
385
402
  }
386
403
  }
387
404
  }
388
405
  //
389
406
  if (text) {
390
- element.append(text);
407
+ element.innerText = text;
391
408
  }
392
- // TODO: this will be updated to use data-stateid soon
393
- // speed test still going on
394
409
  if (element.stateID) {
395
410
  // adding cradova dynamic signature
396
411
  element.classList.add("cra_child_doc");
@@ -405,11 +420,15 @@ const _ = (...element_initials) => {
405
420
  console.error(" ✘ Cradova err: NO TEMPLATE STRING PROVIDED");
406
421
  return () => "NO TEMPLATE STRING PROVIDED";
407
422
  }
408
- const CradovaElement = identify(element_initials);
409
- if (!CradovaElement) {
410
- throw new Error(" ✘ Cradova err: invalid element initials " + element_initials);
411
- }
412
- return CradovaElement;
423
+ // const CradovaElement: () => HTMLElement | undefined =
424
+ // identify(element_initials);
425
+ // if (!CradovaElement) {
426
+ // throw new Error(
427
+ // " ✘ Cradova err: invalid element initials " + element_initials
428
+ // );
429
+ // }
430
+ // return CradovaElement;
431
+ return identify(element_initials);
413
432
  };
414
433
  Init();
415
434
  export default _;