cradova 2.0.0 → 2.1.1

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/README.md CHANGED
@@ -132,6 +132,19 @@ function HelloMessage(name) {
132
132
  return _("div", "Hello " + name);
133
133
  }
134
134
 
135
+
136
+ /*
137
+
138
+ when using router and screens
139
+
140
+ cradova will create a div with data-cra-id=cradova-app-wrapper
141
+
142
+ if it already exist cradova will use it instead
143
+
144
+ so if you want to use your own mount point then create a div with data-cra-id="cradova-app-wrapper"
145
+
146
+ */
147
+
135
148
  const home = new Screen({
136
149
  name: "hello page", // page title
137
150
  template: HelloMessage,
@@ -152,9 +165,9 @@ Router.route("/", home);
152
165
  ## State management
153
166
 
154
167
  ```js
155
- // dispatch - global (element) requires state ID
156
168
 
157
- // element can have this.updateState when shouldUpdate is true
169
+
170
+ // element can have this.updateState when the shouldUpdate props is true
158
171
 
159
172
  // Ref components
160
173
 
@@ -209,6 +222,15 @@ const nameRef = new Ref(function ( name ) {
209
222
  });
210
223
  });
211
224
 
225
+ /*
226
+ cradova Ref are component objects
227
+ with methods for rendering, pre-rendering, and updating a it dom elements.
228
+
229
+ Ref also has the feature to stash input values need by the components
230
+
231
+ */
232
+
233
+
212
234
  function Home() {
213
235
  return _("div.foo#bar",
214
236
  counter,
@@ -224,6 +246,28 @@ const home = new Screen({
224
246
  ...
225
247
  });
226
248
 
249
+ /*
250
+
251
+ Nice things about cradova screens
252
+
253
+ screens are rendered once by default to hack
254
+ responsiveness making your app work fast as user navigates.
255
+
256
+ this behavior can be override
257
+ by passing
258
+ prerender: false
259
+ in the constructor
260
+
261
+
262
+ Cradova screens has
263
+ onActivate() and
264
+ onDeactivate() methods
265
+
266
+ these allow you manage rendering
267
+ circle for each in your app
268
+
269
+ */
270
+
227
271
  Router.route("/", home);
228
272
  ```
229
273
 
package/dist/index.d.ts CHANGED
@@ -79,8 +79,8 @@ declare module "cradova" {
79
79
  * @param action function to execute
80
80
  */
81
81
  createAction(
82
- key: string | Record<string, (self?: this, data?: Type) => void>,
83
- action?: (self?: this, data?: Type) => void
82
+ key: string | Record<string, (data?: Type) => void>,
83
+ action?: (data?: Type) => void
84
84
  ): void;
85
85
  /**
86
86
  * Cradova Signal
@@ -317,8 +317,8 @@ declare module "cradova" {
317
317
  constructor(cradova_screen_initials: CradovaScreenType);
318
318
  setErrorHandler(errorHandler: () => void): void;
319
319
  package(): Promise<void>;
320
- onActivate(cb: (data: any) => Promise<void>): void;
321
- onDeactivate(cb: (data: any) => Promise<void>): void;
320
+ onActivate(cb: () => Promise<void> | void): void;
321
+ onDeactivate(cb: () => Promise<void> | void): void;
322
322
  addChild(...addOns: any[]): void;
323
323
  deActivate(): void;
324
324
  Activate(force?: boolean): Promise<void>;
@@ -475,7 +475,6 @@ declare module "cradova" {
475
475
  export const sub: ElementType<HTMLElement>;
476
476
  export const summary: ElementType<HTMLElement>;
477
477
  export const sup: ElementType<HTMLElement>;
478
- export const svg: ElementType<HTMLOrSVGElement>;
479
478
  export const table: ElementType<HTMLTableElement>;
480
479
  export const tbody: ElementType<HTMLTableColElement>;
481
480
  export const td: ElementType<HTMLTableCellElement>;
@@ -530,6 +529,18 @@ css(".btn:hover",
530
529
  condition: any,
531
530
  ...callback: (() => any)[]
532
531
  ): "" | (() => any)[];
532
+
533
+ export function loop(
534
+ datalist: any[],
535
+ component: (value: any, index?: number, array?: any[]) => HTMLElement
536
+ ): any;
537
+
538
+ export function svgNS(
539
+ type: string,
540
+ props: Record<string, any>,
541
+ ...children: any
542
+ ): HTMLElement;
543
+
533
544
  export function assertOr(
534
545
  condition: boolean,
535
546
  ifTrue: () => any,
package/dist/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  // lib/utils/init.ts
2
2
  var Init = function() {
3
- const Wrapper = document.createElement("div");
4
- Wrapper.setAttribute("data-cra-id", "cradova-app-wrapper");
5
- document.body.appendChild(Wrapper);
3
+ if (!document.querySelector("[data-cra-id=cradova-app-wrapper]")) {
4
+ const Wrapper = document.createElement("div");
5
+ Wrapper.setAttribute("data-cra-id", "cradova-app-wrapper");
6
+ document.body.appendChild(Wrapper);
7
+ }
6
8
  };
7
9
 
8
10
  // lib/utils/fns.ts
@@ -61,6 +63,9 @@ function assert(condition, ...callback) {
61
63
  }
62
64
  return "";
63
65
  }
66
+ function loop(datalist2, component) {
67
+ return Array.isArray(datalist2) && datalist2.map(component);
68
+ }
64
69
  function assertOr(condition, ifTrue, ifFalse) {
65
70
  if (condition) {
66
71
  return ifTrue;
@@ -227,6 +232,26 @@ var frag = function(children) {
227
232
  }
228
233
  return par;
229
234
  };
235
+ var svgNS = (type, props, ...children) => {
236
+ const sc = document.createElementNS(
237
+ props.xmlns || "http://www.w3.org/2000/svg",
238
+ type
239
+ );
240
+ delete props.xmlns;
241
+ for (const p2 in props) {
242
+ sc.setAttributeNS(null, p2, props[p2]);
243
+ }
244
+ for (let ch of children) {
245
+ if (typeof ch === "function") {
246
+ ch = ch();
247
+ }
248
+ if (typeof ch === "function") {
249
+ ch = ch();
250
+ }
251
+ sc.appendChild(ch);
252
+ }
253
+ return sc;
254
+ };
230
255
 
231
256
  // lib/utils/track.ts
232
257
  function cradovaDispatchTrack(nodes, state) {
@@ -389,7 +414,7 @@ var simpleStore = class {
389
414
  }
390
415
  }
391
416
  }
392
- bindRef(ref, key, prop) {
417
+ _bindRef(ref, key, prop) {
393
418
  if (ref && ref.updateState && prop) {
394
419
  this.ref.push({ prop, ref, key });
395
420
  if (ref.reader) {
@@ -519,7 +544,7 @@ var createSignal = class {
519
544
  throw new Error(
520
545
  `\u2718 Cradova err : can't set key ${String(
521
546
  key
522
- )} . store value is not a javascript object`
547
+ )} . store.value is not a javascript object`
523
548
  );
524
549
  }
525
550
  }
@@ -909,6 +934,24 @@ var cra = (element_initials) => {
909
934
  continue;
910
935
  }
911
936
  if (Array.isArray(child)) {
937
+ let rload2 = function(l) {
938
+ const fg = new DocumentFragment();
939
+ for (let ch of l) {
940
+ if (Array.isArray(ch)) {
941
+ fg.appendChild(rload2(ch));
942
+ } else {
943
+ if (typeof ch === "function") {
944
+ ch = ch();
945
+ }
946
+ if (typeof ch === "function") {
947
+ ch = ch();
948
+ }
949
+ fg.appendChild(ch);
950
+ }
951
+ }
952
+ return fg;
953
+ };
954
+ var rload = rload2;
912
955
  const arrCXLength = child.length;
913
956
  for (let p2 = 0; p2 < arrCXLength; p2++) {
914
957
  let childly = child[p2];
@@ -918,6 +961,9 @@ var cra = (element_initials) => {
918
961
  if (typeof childly === "function") {
919
962
  childly = childly();
920
963
  }
964
+ if (Array.isArray(childly)) {
965
+ childly = rload2(childly);
966
+ }
921
967
  if (isNode(childly)) {
922
968
  element.appendChild(childly);
923
969
  } else {
@@ -946,7 +992,7 @@ var cra = (element_initials) => {
946
992
  );
947
993
  }
948
994
  }
949
- if (typeof props === "object") {
995
+ if (typeof props === "object" && element) {
950
996
  for (const prop in props) {
951
997
  if (prop === "style" && typeof props[prop] === "object") {
952
998
  for (const [k, v] of Object.entries(props[prop])) {
@@ -960,6 +1006,10 @@ var cra = (element_initials) => {
960
1006
  }
961
1007
  continue;
962
1008
  }
1009
+ if (typeof element.style[prop] !== "undefined" && prop !== "src") {
1010
+ element.style[prop] = props[prop];
1011
+ continue;
1012
+ }
963
1013
  if (prop === "text" && typeof props[prop] === "string" && props[prop] !== "") {
964
1014
  text = props[prop];
965
1015
  continue;
@@ -982,7 +1032,7 @@ var cra = (element_initials) => {
982
1032
  }
983
1033
  if (Array.isArray(props[prop]) && props[prop][0] instanceof simpleStore) {
984
1034
  element.updateState = dispatch.bind(null, element);
985
- props[prop][0].bindRef(element, prop, props[prop][1]);
1035
+ props[prop][0]._bindRef(element, prop, props[prop][1]);
986
1036
  continue;
987
1037
  }
988
1038
  if (prop === "shouldUpdate" && props[prop] === true) {
@@ -1001,11 +1051,17 @@ var cra = (element_initials) => {
1001
1051
  if (typeof element[prop] !== "undefined") {
1002
1052
  element[prop] = props[prop];
1003
1053
  } else {
1054
+ if (prop.includes("data-")) {
1055
+ element.setAttribute(prop, props[prop]);
1056
+ continue;
1057
+ }
1004
1058
  element[prop] = props[prop];
1005
- if (prop !== "for" && prop !== "text" && prop !== "class" && !prop.includes("aria")) {
1059
+ if (prop !== "for" && prop !== "text" && prop !== "class" && prop !== "tabindex" && !prop.includes("aria")) {
1006
1060
  console.error(" \u2718 Cradova err: invalid html attribute ", {
1007
1061
  prop
1008
1062
  });
1063
+ } else {
1064
+ continue;
1009
1065
  }
1010
1066
  }
1011
1067
  } catch (error) {
@@ -1015,7 +1071,7 @@ var cra = (element_initials) => {
1015
1071
  }
1016
1072
  }
1017
1073
  if (text) {
1018
- element.innerText = text;
1074
+ element.appendChild(document.createTextNode(text));
1019
1075
  }
1020
1076
  if (typeof beforeMount === "function") {
1021
1077
  beforeMount.apply(element);
@@ -1118,7 +1174,6 @@ var style = cra("style");
1118
1174
  var sub = cra("sub");
1119
1175
  var summary = cra("summary");
1120
1176
  var sup = cra("sup");
1121
- var svg = cra("svg");
1122
1177
  var table = cra("table");
1123
1178
  var tbody = cra("tbody");
1124
1179
  var td = cra("td");
@@ -1269,6 +1324,24 @@ var _ = (...element_initials) => {
1269
1324
  continue;
1270
1325
  }
1271
1326
  if (Array.isArray(child)) {
1327
+ let rload2 = function(l) {
1328
+ const fg = new DocumentFragment();
1329
+ for (let ch of l) {
1330
+ if (Array.isArray(ch)) {
1331
+ fg.appendChild(rload2(ch));
1332
+ } else {
1333
+ if (typeof ch === "function") {
1334
+ ch = ch();
1335
+ }
1336
+ if (typeof ch === "function") {
1337
+ ch = ch();
1338
+ }
1339
+ fg.appendChild(ch);
1340
+ }
1341
+ }
1342
+ return fg;
1343
+ };
1344
+ var rload = rload2;
1272
1345
  const arrCXLength = child.length;
1273
1346
  for (let p2 = 0; p2 < arrCXLength; p2++) {
1274
1347
  let childly = child[p2];
@@ -1278,9 +1351,13 @@ var _ = (...element_initials) => {
1278
1351
  if (typeof childly === "function") {
1279
1352
  childly = childly();
1280
1353
  }
1354
+ if (Array.isArray(childly)) {
1355
+ childly = rload2(childly);
1356
+ }
1281
1357
  if (isNode(childly)) {
1282
1358
  element.appendChild(childly);
1283
1359
  } else {
1360
+ console.log(childly);
1284
1361
  if (typeof childly !== "undefined") {
1285
1362
  throw new Error(
1286
1363
  " \u2718 Cradova err: invalid child type: " + childly + " (" + typeof childly + ")"
@@ -1350,7 +1427,7 @@ var _ = (...element_initials) => {
1350
1427
  }
1351
1428
  if (Array.isArray(props[prop]) && props[prop][0] instanceof simpleStore) {
1352
1429
  element.updateState = dispatch.bind(null, element);
1353
- props[prop][0].bindRef(element, prop, props[prop][1]);
1430
+ props[prop][0]._bindRef(element, prop, props[prop][1]);
1354
1431
  continue;
1355
1432
  }
1356
1433
  if (prop === "shouldUpdate" && props[prop] === true) {
@@ -1369,11 +1446,17 @@ var _ = (...element_initials) => {
1369
1446
  if (typeof element[prop] !== "undefined") {
1370
1447
  element[prop] = props[prop];
1371
1448
  } else {
1449
+ if (prop.includes("data-")) {
1450
+ element.setAttribute(prop, props[prop]);
1451
+ continue;
1452
+ }
1372
1453
  element[prop] = props[prop];
1373
- if (prop !== "for" && prop !== "text" && prop !== "class" && !prop.includes("aria")) {
1454
+ if (prop !== "for" && prop !== "text" && prop !== "class" && prop !== "tabindex" && !prop.includes("aria")) {
1374
1455
  console.error(" \u2718 Cradova err: invalid html attribute ", {
1375
1456
  prop
1376
1457
  });
1458
+ } else {
1459
+ continue;
1377
1460
  }
1378
1461
  }
1379
1462
  } catch (error) {
@@ -1383,7 +1466,7 @@ var _ = (...element_initials) => {
1383
1466
  }
1384
1467
  }
1385
1468
  if (text) {
1386
- element.innerText = text;
1469
+ element.appendChild(document.createTextNode(text));
1387
1470
  }
1388
1471
  if (typeof beforeMount === "function") {
1389
1472
  beforeMount.apply(element);
@@ -1464,6 +1547,7 @@ export {
1464
1547
  legend,
1465
1548
  li,
1466
1549
  link,
1550
+ loop,
1467
1551
  main,
1468
1552
  map,
1469
1553
  mark,
@@ -1501,7 +1585,7 @@ export {
1501
1585
  sub,
1502
1586
  summary,
1503
1587
  sup,
1504
- svg,
1588
+ svgNS,
1505
1589
  table,
1506
1590
  tbody,
1507
1591
  td,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cradova",
3
- "version": "2.0.0",
3
+ "version": "2.1.1",
4
4
  "description": "Web framework for building web apps and PWAs",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",