ywana-core8 0.0.197 → 0.0.198

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,6 +1533,7 @@
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
 
@@ -1338,11 +1568,19 @@
1338
1568
 
1339
1569
  var StringCellViewer = function StringCellViewer(_ref4) {
1340
1570
  var value = _ref4.value,
1571
+ format = _ref4.format,
1341
1572
  options = _ref4.options;
1342
1573
  var option = options ? options.find(function (o) {
1343
1574
  return o.value === value;
1344
1575
  }) : null;
1345
1576
  var text = option ? option.label : value;
1577
+
1578
+ switch (format) {
1579
+ case FORMATS.DATE:
1580
+ text = new Date(text).toLocaleDateString();
1581
+ break;
1582
+ }
1583
+
1346
1584
  return /*#__PURE__*/React__default["default"].createElement("div", {
1347
1585
  className: "field-editor string-viewer"
1348
1586
  }, text);
@@ -2267,234 +2505,6 @@
2267
2505
  }) : 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
2506
  };
2269
2507
 
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
2508
  /**
2499
2509
  * Content Form
2500
2510
  */
@@ -2942,7 +2952,7 @@
2942
2952
  });
2943
2953
  return /*#__PURE__*/React__default["default"].createElement("div", {
2944
2954
  className: "entity-editor"
2945
- }, /*#__PURE__*/React__default["default"].createElement("header", null, "\u2202", /*#__PURE__*/React__default["default"].createElement(Text, {
2955
+ }, /*#__PURE__*/React__default["default"].createElement("header", null, /*#__PURE__*/React__default["default"].createElement(Text, {
2946
2956
  use: "caption"
2947
2957
  }, label)), /*#__PURE__*/React__default["default"].createElement("main", null, fields.map(function (field) {
2948
2958
  return /*#__PURE__*/React__default["default"].createElement(FieldEditor, {
@@ -4676,6 +4686,7 @@
4676
4686
  id: field.id,
4677
4687
  label: field.label,
4678
4688
  type: field.type,
4689
+ format: field.format,
4679
4690
  onChange: field.id === "checked" ? checkOne : field.editable ? change : null,
4680
4691
 
4681
4692
  /* checked has it´s own handler */