ywana-core8 0.0.17 → 0.0.18

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.
@@ -3128,7 +3128,7 @@ var CollectionAdder = function CollectionAdder(_ref11) {
3128
3128
  * Create Content Dialog
3129
3129
  */
3130
3130
 
3131
- var CreateContentDialog = function CreateContentDialog(_ref) {
3131
+ var CreateContentDialog$1 = function CreateContentDialog(_ref) {
3132
3132
  var label = _ref.label,
3133
3133
  type = _ref.type,
3134
3134
  _ref$value = _ref.value,
@@ -3295,6 +3295,101 @@ var EditContentDialog = function EditContentDialog(_ref) {
3295
3295
  }));
3296
3296
  };
3297
3297
 
3298
+ /**
3299
+ * Create Content Dialog
3300
+ */
3301
+
3302
+ var CreateContentDialog = function CreateContentDialog(_ref) {
3303
+ var label = _ref.label,
3304
+ type = _ref.type,
3305
+ validator = _ref.validator,
3306
+ onOK = _ref.onOK,
3307
+ _ref$onActionClose = _ref.onActionClose,
3308
+ onActionClose = _ref$onActionClose === void 0 ? true : _ref$onActionClose;
3309
+ var site = useContext(SiteContext);
3310
+
3311
+ var _useState = useState({}),
3312
+ form = _useState[0],
3313
+ setForm = _useState[1];
3314
+
3315
+ var _useState2 = useState(false),
3316
+ isValid = _useState2[0],
3317
+ setValid = _useState2[1];
3318
+
3319
+ var _useState3 = useState([]),
3320
+ errors = _useState3[0],
3321
+ setErrors = _useState3[1];
3322
+
3323
+ function change(form, validForm) {
3324
+ setForm(form);
3325
+
3326
+ if (validator) {
3327
+ var _validator = validator(form),
3328
+ validation = _validator.validation,
3329
+ _validator$errors = _validator.errors,
3330
+ _errors = _validator$errors === void 0 ? [] : _validator$errors;
3331
+
3332
+ setValid(validForm && validation);
3333
+ setErrors(_errors);
3334
+ } else {
3335
+ setValid(validForm);
3336
+ }
3337
+ }
3338
+
3339
+ function onAction(action) {
3340
+ if (action === 'OK' && onOK) onOK(form);
3341
+ if (action === 'CLOSE' || onActionClose === true) site.closeDialog();
3342
+ }
3343
+
3344
+ function isRequired(field) {
3345
+ var _field$required = field.required,
3346
+ required = _field$required === void 0 ? false : _field$required;
3347
+ return required;
3348
+ }
3349
+
3350
+ function isOptional(field) {
3351
+ var _field$creation = field.creation,
3352
+ creation = _field$creation === void 0 ? false : _field$creation;
3353
+ return creation;
3354
+ }
3355
+
3356
+ var actions = /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Button, {
3357
+ label: "CLOSE",
3358
+ action: function action() {
3359
+ return onAction("CLOSE");
3360
+ }
3361
+ }), /*#__PURE__*/React.createElement(Button, {
3362
+ label: "OK",
3363
+ action: function action() {
3364
+ return onAction("OK");
3365
+ },
3366
+ disabled: !isValid,
3367
+ raised: true
3368
+ }));
3369
+ var title = /*#__PURE__*/React.createElement(Text, {
3370
+ use: "headline6"
3371
+ }, label);
3372
+ var content = new Content(type, form);
3373
+ return /*#__PURE__*/React.createElement(Dialog, {
3374
+ title: title,
3375
+ open: true,
3376
+ onAction: onAction,
3377
+ actions: actions
3378
+ }, /*#__PURE__*/React.createElement(ContentForm, {
3379
+ content: content,
3380
+ filter: function filter(field) {
3381
+ return isRequired(field) || isOptional(field);
3382
+ },
3383
+ onChange: change
3384
+ }), errors.map(function (error) {
3385
+ return /*#__PURE__*/React.createElement(Text, {
3386
+ use: "overline",
3387
+ tag: "div",
3388
+ className: "error"
3389
+ }, error);
3390
+ }));
3391
+ };
3392
+
3298
3393
  function _catch(body, recover) {
3299
3394
  try {
3300
3395
  var result = body();
@@ -3370,8 +3465,8 @@ var CollectionPage = function CollectionPage(props) {
3370
3465
  }
3371
3466
  };
3372
3467
 
3373
- site.openDialog( /*#__PURE__*/React.createElement(EditContentDialog, {
3374
- label: "Crear " + name,
3468
+ site.openDialog( /*#__PURE__*/React.createElement(CreateContentDialog, {
3469
+ label: "" + name,
3375
3470
  type: schema,
3376
3471
  onOK: onOK
3377
3472
  }));
@@ -4075,5 +4170,5 @@ var isFunction = function isFunction(value) {
4075
4170
  return value && (Object.prototype.toString.call(value) === "[object Function]" || "function" === typeof value || value instanceof Function);
4076
4171
  };
4077
4172
 
4078
- export { Button, CheckBox, Chip, Chips, CircularProgress, CollectionContext, CollectionEditor$1 as CollectionEditor, CollectionPage, Content, ContentEditor, ContentForm, CreateContentDialog, DataTable, Dialog, DropDown, EditContentDialog, FieldEditor, Form, HTTPClient, Header, Icon, Kanban, KanbanCard, KanbanColumn, LinearProgress, List, ListEditor, LoginBox, Menu, MenuIcon, MenuItem, MenuSeparator, Page, PageContext, PageProvider, Property, RadioButton, ResetPasswordBox, Section, Session, Site, SiteContext, SiteProvider, Stack, TYPES, Tab, TabbedContentEditor, Tabs, Text, TextField, TokenField, Tree, TreeItem, TreeNode, TreededContentEditor, UploadArea, UploadDialog, UploadFile, Uploader, Viewer, isFunction };
4173
+ export { Button, CheckBox, Chip, Chips, CircularProgress, CollectionContext, CollectionEditor$1 as CollectionEditor, CollectionPage, Content, ContentEditor, ContentForm, CreateContentDialog$1 as CreateContentDialog, DataTable, Dialog, DropDown, EditContentDialog, FieldEditor, Form, HTTPClient, Header, Icon, Kanban, KanbanCard, KanbanColumn, LinearProgress, List, ListEditor, LoginBox, Menu, MenuIcon, MenuItem, MenuSeparator, Page, PageContext, PageProvider, Property, RadioButton, ResetPasswordBox, Section, Session, Site, SiteContext, SiteProvider, Stack, TYPES, Tab, TabbedContentEditor, Tabs, Text, TextField, TokenField, Tree, TreeItem, TreeNode, TreededContentEditor, UploadArea, UploadDialog, UploadFile, Uploader, Viewer, isFunction };
4079
4174
  //# sourceMappingURL=index.modern.js.map