ywana-core8 0.0.196 → 0.0.200

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