ywana-core8 0.0.197 → 0.0.201

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/index.cjs CHANGED
@@ -1025,6 +1025,234 @@ var DropDown = function DropDown(props) {
1025
1025
  }) : null, renderOptions());
1026
1026
  };
1027
1027
 
1028
+ /**
1029
+ * TYPES
1030
+ */
1031
+ var TYPES = {
1032
+ STRING: 'String',
1033
+ NUMBER: 'Number',
1034
+ BOOLEAN: 'Boolean',
1035
+ ARRAY: 'Array',
1036
+ ENTITY: 'Object',
1037
+ FUNCTION: 'Function'
1038
+ };
1039
+ /**
1040
+ * FORMATS
1041
+ */
1042
+
1043
+ var FORMATS = {
1044
+ NONE: '',
1045
+ DATE: 'date',
1046
+ EMAIL: 'email',
1047
+ HTML: 'HTML',
1048
+ URL: 'URL'
1049
+ };
1050
+ /**
1051
+ * CHECK
1052
+ */
1053
+
1054
+ var CHECK = Object.values(TYPES).reduce(function (obj, name) {
1055
+ obj['is' + name] = function (x) {
1056
+ return toString.call(x) == '[object ' + name + ']';
1057
+ };
1058
+
1059
+ return obj;
1060
+ }, {});
1061
+ /**
1062
+ * Content Type
1063
+ */
1064
+
1065
+ var ContentType = /*#__PURE__*/function () {
1066
+ function ContentType(schema) {
1067
+ this._schema = schema;
1068
+ }
1069
+
1070
+ var _proto = ContentType.prototype;
1071
+
1072
+ _proto.checkType = function checkType(_ref, data) {
1073
+ var type = _ref.type,
1074
+ item = _ref.item;
1075
+ var valid = true;
1076
+ var validChildren = true;
1077
+
1078
+ if (item) {
1079
+ var child = new ContentType(item);
1080
+
1081
+ switch (type) {
1082
+ case TYPES.ARRAY:
1083
+ valid = CHECK['is' + type](data);
1084
+ validChildren = data.every(function (element) {
1085
+ return child.validate(element);
1086
+ });
1087
+ break;
1088
+
1089
+ case TYPES.ENTITY:
1090
+ valid = CHECK['is' + type](data);
1091
+ validChildren = child.validate(data);
1092
+ break;
1093
+
1094
+ case TYPES.NUMBER:
1095
+ valid = CHECK['is' + type](data.value);
1096
+ validChildren = true;
1097
+ break;
1098
+
1099
+ default:
1100
+ valid = true;
1101
+ validChildren = true;
1102
+ }
1103
+ }
1104
+
1105
+ return valid && validChildren;
1106
+ }
1107
+ /**
1108
+ * Validate entity data
1109
+ * - Inspect required attributes only
1110
+ * - Check attributes type
1111
+ */
1112
+ ;
1113
+
1114
+ _proto.validate = function validate(data) {
1115
+ var _this = this;
1116
+
1117
+ var attributes = Object.entries(this._schema);
1118
+ return attributes.filter(function (_ref2) {
1119
+ var attr = _ref2[1];
1120
+ return attr.required === true;
1121
+ }).every(function (_ref3) {
1122
+ var name = _ref3[0],
1123
+ attr = _ref3[1];
1124
+ return data[name] !== undefined ? _this.checkType(attr, data[name]) : false;
1125
+ });
1126
+ }
1127
+ /**
1128
+ * Content Type Form
1129
+ */
1130
+ ;
1131
+
1132
+ _proto.form = function form(data) {
1133
+ var entries = Object.entries(this._schema);
1134
+ var form = entries.reduce(function (form, _ref4) {
1135
+ var id = _ref4[0],
1136
+ field = _ref4[1];
1137
+ form[id] = Object.assign({}, field, {
1138
+ value: data[id]
1139
+ });
1140
+ return form;
1141
+ }, {});
1142
+ return form;
1143
+ }
1144
+ /**
1145
+ * Content Type Sections
1146
+ */
1147
+ ;
1148
+
1149
+ _proto.sections = function sections(data) {
1150
+ var form = this.form(data);
1151
+ var fields = Object.values(form);
1152
+ var sections = fields.reduce(function (sections, field) {
1153
+ var section = field.section;
1154
+ var title = section ? section : '';
1155
+ if (!sections.hasOwnProperty(title)) sections[title] = {
1156
+ title: title,
1157
+ fields: []
1158
+ };
1159
+ sections[title].fields.push(field);
1160
+ return sections;
1161
+ }, {});
1162
+ return Object.values(sections);
1163
+ }
1164
+ /**
1165
+ * value
1166
+ */
1167
+ ;
1168
+
1169
+ _proto.value = function value(data) {
1170
+ var fields = Object.entries(this._schema);
1171
+ var next = fields.reduce(function (next, _ref5) {
1172
+ var name = _ref5[0],
1173
+ field = _ref5[1];
1174
+ var type = field.type,
1175
+ item = field.item;
1176
+ var entryData = data ? data[name] : null;
1177
+
1178
+ switch (type) {
1179
+ case TYPES.STRING:
1180
+ next[name] = entryData || field["default"];
1181
+ break;
1182
+
1183
+ case TYPES.NUMBER:
1184
+ next[name] = entryData || field["default"];
1185
+ break;
1186
+
1187
+ case TYPES.BOOLEAN:
1188
+ next[name] = entryData || field["default"];
1189
+ break;
1190
+
1191
+ case TYPES.ENTITY:
1192
+ var child1 = new ContentType(item);
1193
+ next[name] = child1.value(entryData);
1194
+ break;
1195
+
1196
+ case TYPES.ARRAY:
1197
+ if (item === TYPES.STRING) {
1198
+ next[name] = entryData ? entryData : [];
1199
+ } else {
1200
+ var child2 = new ContentType(item);
1201
+ next[name] = entryData ? entryData.map(function (data2) {
1202
+ return child2.value(data2);
1203
+ }) : [];
1204
+ }
1205
+
1206
+ break;
1207
+
1208
+ default:
1209
+ next[name] = field;
1210
+ break;
1211
+ }
1212
+
1213
+ return next;
1214
+ }, {});
1215
+ return next;
1216
+ };
1217
+
1218
+ return ContentType;
1219
+ }();
1220
+ /**
1221
+ * Content
1222
+ */
1223
+
1224
+ var Content = /*#__PURE__*/function () {
1225
+ function Content(type, value) {
1226
+ this.type = type;
1227
+ this._type = new ContentType(type);
1228
+ this._value = value;
1229
+ }
1230
+
1231
+ var _proto2 = Content.prototype;
1232
+
1233
+ _proto2.isValid = function isValid() {
1234
+ return this._type.validate(this._value);
1235
+ };
1236
+
1237
+ _proto2.value = function value() {
1238
+ return this._type.value(this._value);
1239
+ };
1240
+
1241
+ _proto2.form = function form() {
1242
+ return this._type.form(this._value);
1243
+ };
1244
+
1245
+ _proto2.sections = function sections() {
1246
+ return this._type.sections(this._value);
1247
+ };
1248
+
1249
+ _proto2.update = function update(value) {
1250
+ this._value = value;
1251
+ };
1252
+
1253
+ return Content;
1254
+ }();
1255
+
1028
1256
  var isFunction$1 = function isFunction(value) {
1029
1257
  return value && (Object.prototype.toString.call(value) === "[object Function]" || "function" === typeof value || value instanceof Function);
1030
1258
  };
@@ -1188,6 +1416,7 @@ var DataTableCell = function DataTableCell(_ref2) {
1188
1416
  min = column.min,
1189
1417
  max = column.max,
1190
1418
  _onChange = column.onChange,
1419
+ format = column.format,
1191
1420
  options = column.options;
1192
1421
 
1193
1422
  if (id === "checked") {
@@ -1307,9 +1536,16 @@ var DataTableCell = function DataTableCell(_ref2) {
1307
1536
  return /*#__PURE__*/React__default["default"].createElement(StringCellViewer, {
1308
1537
  id: id,
1309
1538
  value: cell,
1539
+ format: format,
1310
1540
  options: options
1311
1541
  });
1312
1542
 
1543
+ case TYPES.ENTITY:
1544
+ return /*#__PURE__*/React__default["default"].createElement(EntityCellViewer, {
1545
+ id: id,
1546
+ value: cell
1547
+ });
1548
+
1313
1549
  default:
1314
1550
  return cell;
1315
1551
  }
@@ -1321,14 +1557,26 @@ var DataTableCell = function DataTableCell(_ref2) {
1321
1557
  className: column.id
1322
1558
  }, render(column.type));
1323
1559
  };
1560
+
1561
+ var EntityCellViewer = function EntityCellViewer(_ref3) {
1562
+ var id = _ref3.id,
1563
+ value = _ref3.value;
1564
+ console.log(id, value);
1565
+ var subcells = value ? Object.values(value) : [1, 2, 3];
1566
+ return /*#__PURE__*/React__default["default"].createElement("div", {
1567
+ className: "entity-cell-viewer"
1568
+ }, subcells.map(function (v) {
1569
+ return /*#__PURE__*/React__default["default"].createElement("div", null, v);
1570
+ }));
1571
+ };
1324
1572
  /**
1325
1573
  * Boolean Cell Viewer
1326
1574
  */
1327
1575
 
1328
1576
 
1329
- var BooleanCellViewer = function BooleanCellViewer(_ref3) {
1330
- var _ref3$value = _ref3.value,
1331
- value = _ref3$value === void 0 ? false : _ref3$value;
1577
+ var BooleanCellViewer = function BooleanCellViewer(_ref4) {
1578
+ var _ref4$value = _ref4.value,
1579
+ value = _ref4$value === void 0 ? false : _ref4$value;
1332
1580
  var icon = value === true ? "check_box" : "check_box_outline_blank";
1333
1581
  return /*#__PURE__*/React__default["default"].createElement(Icon, {
1334
1582
  icon: icon
@@ -1339,13 +1587,21 @@ var BooleanCellViewer = function BooleanCellViewer(_ref3) {
1339
1587
  */
1340
1588
 
1341
1589
 
1342
- var StringCellViewer = function StringCellViewer(_ref4) {
1343
- var value = _ref4.value,
1344
- options = _ref4.options;
1590
+ var StringCellViewer = function StringCellViewer(_ref5) {
1591
+ var value = _ref5.value,
1592
+ format = _ref5.format,
1593
+ options = _ref5.options;
1345
1594
  var option = options ? options.find(function (o) {
1346
1595
  return o.value === value;
1347
1596
  }) : null;
1348
1597
  var text = option ? option.label : value;
1598
+
1599
+ switch (format) {
1600
+ case FORMATS.DATE:
1601
+ text = new Date(text).toLocaleString();
1602
+ break;
1603
+ }
1604
+
1349
1605
  return /*#__PURE__*/React__default["default"].createElement("div", {
1350
1606
  className: "field-editor string-viewer"
1351
1607
  }, text);
@@ -1355,12 +1611,12 @@ var StringCellViewer = function StringCellViewer(_ref4) {
1355
1611
  */
1356
1612
 
1357
1613
 
1358
- var StringCellEditor = function StringCellEditor(_ref5) {
1359
- var id = _ref5.id,
1360
- _ref5$value = _ref5.value,
1361
- value = _ref5$value === void 0 ? '' : _ref5$value,
1362
- options = _ref5.options,
1363
- onChange = _ref5.onChange;
1614
+ var StringCellEditor = function StringCellEditor(_ref6) {
1615
+ var id = _ref6.id,
1616
+ _ref6$value = _ref6.value,
1617
+ value = _ref6$value === void 0 ? '' : _ref6$value,
1618
+ options = _ref6.options,
1619
+ onChange = _ref6.onChange;
1364
1620
 
1365
1621
  function change(id, value) {
1366
1622
  if (onChange) onChange(id, value);
@@ -2270,234 +2526,6 @@ var Dialog = function Dialog(props) {
2270
2526
  }) : null, /*#__PURE__*/React__default["default"].createElement(Text, null, title)), /*#__PURE__*/React__default["default"].createElement("main", null, children), /*#__PURE__*/React__default["default"].createElement("footer", null, actions))));
2271
2527
  };
2272
2528
 
2273
- /**
2274
- * TYPES
2275
- */
2276
- var TYPES = {
2277
- STRING: 'String',
2278
- NUMBER: 'Number',
2279
- BOOLEAN: 'Boolean',
2280
- ARRAY: 'Array',
2281
- ENTITY: 'Object',
2282
- FUNCTION: 'Function'
2283
- };
2284
- /**
2285
- * FORMATS
2286
- */
2287
-
2288
- var FORMATS = {
2289
- NONE: '',
2290
- DATE: 'date',
2291
- EMAIL: 'email',
2292
- HTML: 'HTML',
2293
- URL: 'URL'
2294
- };
2295
- /**
2296
- * CHECK
2297
- */
2298
-
2299
- var CHECK = Object.values(TYPES).reduce(function (obj, name) {
2300
- obj['is' + name] = function (x) {
2301
- return toString.call(x) == '[object ' + name + ']';
2302
- };
2303
-
2304
- return obj;
2305
- }, {});
2306
- /**
2307
- * Content Type
2308
- */
2309
-
2310
- var ContentType = /*#__PURE__*/function () {
2311
- function ContentType(schema) {
2312
- this._schema = schema;
2313
- }
2314
-
2315
- var _proto = ContentType.prototype;
2316
-
2317
- _proto.checkType = function checkType(_ref, data) {
2318
- var type = _ref.type,
2319
- item = _ref.item;
2320
- var valid = true;
2321
- var validChildren = true;
2322
-
2323
- if (item) {
2324
- var child = new ContentType(item);
2325
-
2326
- switch (type) {
2327
- case TYPES.ARRAY:
2328
- valid = CHECK['is' + type](data);
2329
- validChildren = data.every(function (element) {
2330
- return child.validate(element);
2331
- });
2332
- break;
2333
-
2334
- case TYPES.ENTITY:
2335
- valid = CHECK['is' + type](data);
2336
- validChildren = child.validate(data);
2337
- break;
2338
-
2339
- case TYPES.NUMBER:
2340
- valid = CHECK['is' + type](data.value);
2341
- validChildren = true;
2342
- break;
2343
-
2344
- default:
2345
- valid = true;
2346
- validChildren = true;
2347
- }
2348
- }
2349
-
2350
- return valid && validChildren;
2351
- }
2352
- /**
2353
- * Validate entity data
2354
- * - Inspect required attributes only
2355
- * - Check attributes type
2356
- */
2357
- ;
2358
-
2359
- _proto.validate = function validate(data) {
2360
- var _this = this;
2361
-
2362
- var attributes = Object.entries(this._schema);
2363
- return attributes.filter(function (_ref2) {
2364
- var attr = _ref2[1];
2365
- return attr.required === true;
2366
- }).every(function (_ref3) {
2367
- var name = _ref3[0],
2368
- attr = _ref3[1];
2369
- return data[name] !== undefined ? _this.checkType(attr, data[name]) : false;
2370
- });
2371
- }
2372
- /**
2373
- * Content Type Form
2374
- */
2375
- ;
2376
-
2377
- _proto.form = function form(data) {
2378
- var entries = Object.entries(this._schema);
2379
- var form = entries.reduce(function (form, _ref4) {
2380
- var id = _ref4[0],
2381
- field = _ref4[1];
2382
- form[id] = Object.assign({}, field, {
2383
- value: data[id]
2384
- });
2385
- return form;
2386
- }, {});
2387
- return form;
2388
- }
2389
- /**
2390
- * Content Type Sections
2391
- */
2392
- ;
2393
-
2394
- _proto.sections = function sections(data) {
2395
- var form = this.form(data);
2396
- var fields = Object.values(form);
2397
- var sections = fields.reduce(function (sections, field) {
2398
- var section = field.section;
2399
- var title = section ? section : '';
2400
- if (!sections.hasOwnProperty(title)) sections[title] = {
2401
- title: title,
2402
- fields: []
2403
- };
2404
- sections[title].fields.push(field);
2405
- return sections;
2406
- }, {});
2407
- return Object.values(sections);
2408
- }
2409
- /**
2410
- * value
2411
- */
2412
- ;
2413
-
2414
- _proto.value = function value(data) {
2415
- var fields = Object.entries(this._schema);
2416
- var next = fields.reduce(function (next, _ref5) {
2417
- var name = _ref5[0],
2418
- field = _ref5[1];
2419
- var type = field.type,
2420
- item = field.item;
2421
- var entryData = data ? data[name] : null;
2422
-
2423
- switch (type) {
2424
- case TYPES.STRING:
2425
- next[name] = entryData || field["default"];
2426
- break;
2427
-
2428
- case TYPES.NUMBER:
2429
- next[name] = entryData || field["default"];
2430
- break;
2431
-
2432
- case TYPES.BOOLEAN:
2433
- next[name] = entryData || field["default"];
2434
- break;
2435
-
2436
- case TYPES.ENTITY:
2437
- var child1 = new ContentType(item);
2438
- next[name] = child1.value(entryData);
2439
- break;
2440
-
2441
- case TYPES.ARRAY:
2442
- if (item === TYPES.STRING) {
2443
- next[name] = entryData ? entryData : [];
2444
- } else {
2445
- var child2 = new ContentType(item);
2446
- next[name] = entryData ? entryData.map(function (data2) {
2447
- return child2.value(data2);
2448
- }) : [];
2449
- }
2450
-
2451
- break;
2452
-
2453
- default:
2454
- next[name] = field;
2455
- break;
2456
- }
2457
-
2458
- return next;
2459
- }, {});
2460
- return next;
2461
- };
2462
-
2463
- return ContentType;
2464
- }();
2465
- /**
2466
- * Content
2467
- */
2468
-
2469
- var Content = /*#__PURE__*/function () {
2470
- function Content(type, value) {
2471
- this.type = type;
2472
- this._type = new ContentType(type);
2473
- this._value = value;
2474
- }
2475
-
2476
- var _proto2 = Content.prototype;
2477
-
2478
- _proto2.isValid = function isValid() {
2479
- return this._type.validate(this._value);
2480
- };
2481
-
2482
- _proto2.value = function value() {
2483
- return this._type.value(this._value);
2484
- };
2485
-
2486
- _proto2.form = function form() {
2487
- return this._type.form(this._value);
2488
- };
2489
-
2490
- _proto2.sections = function sections() {
2491
- return this._type.sections(this._value);
2492
- };
2493
-
2494
- _proto2.update = function update(value) {
2495
- this._value = value;
2496
- };
2497
-
2498
- return Content;
2499
- }();
2500
-
2501
2529
  /**
2502
2530
  * Content Form
2503
2531
  */
@@ -2945,7 +2973,7 @@ var EntityEditor = function EntityEditor(_ref5) {
2945
2973
  });
2946
2974
  return /*#__PURE__*/React__default["default"].createElement("div", {
2947
2975
  className: "entity-editor"
2948
- }, /*#__PURE__*/React__default["default"].createElement("header", null, "\u2202", /*#__PURE__*/React__default["default"].createElement(Text, {
2976
+ }, /*#__PURE__*/React__default["default"].createElement("header", null, /*#__PURE__*/React__default["default"].createElement(Text, {
2949
2977
  use: "caption"
2950
2978
  }, label)), /*#__PURE__*/React__default["default"].createElement("main", null, fields.map(function (field) {
2951
2979
  return /*#__PURE__*/React__default["default"].createElement(FieldEditor, {
@@ -4679,6 +4707,7 @@ var TableEditor = function TableEditor(props) {
4679
4707
  id: field.id,
4680
4708
  label: field.label,
4681
4709
  type: field.type,
4710
+ format: field.format,
4682
4711
  onChange: field.id === "checked" ? checkOne : field.editable ? change : null,
4683
4712
 
4684
4713
  /* checked has it´s own handler */