@panneau/core 3.0.307 → 4.0.0

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.
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Form Types
3
+ * TypeScript interfaces for form-related components
4
+ */
5
+ import { ReactNode } from 'react';
6
+
7
+ import { Label } from './core';
8
+
9
+ /**
10
+ * Field option for select/radio inputs
11
+ */
12
+ export interface FieldOption {
13
+ value?: string;
14
+ label?: string;
15
+ }
16
+
17
+ /**
18
+ * Select option (more flexible than FieldOption)
19
+ */
20
+ export type SelectOption =
21
+ | string
22
+ | number
23
+ | {
24
+ value?: unknown;
25
+ label?: Label | string;
26
+ }
27
+ | Record<string, unknown>;
28
+
29
+ /**
30
+ * Field definition
31
+ */
32
+ export interface Field {
33
+ name?: string; // Not required on localized fields
34
+ type?: string;
35
+ component?: string;
36
+ label?: ReactNode;
37
+ }
38
+
39
+ /**
40
+ * Form definition
41
+ */
42
+ export interface Form {
43
+ title: ReactNode;
44
+ fields?: Field[];
45
+ }
46
+
47
+ /**
48
+ * Table column definition
49
+ */
50
+ export type TableColumn =
51
+ | string
52
+ | {
53
+ id?: string;
54
+ component?: string;
55
+ path?: string;
56
+ field?: string;
57
+ columnClassName?: string;
58
+ };
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Panneau TypeScript Type Definitions
3
+ *
4
+ * This module exports TypeScript interfaces corresponding to the PanneauPropTypes
5
+ * defined in packages/core/src/lib/PropTypes.js
6
+ *
7
+ * @module @panneau/core/types
8
+ */
9
+
10
+ // Core UI Types
11
+ export type {
12
+ Message,
13
+ Label,
14
+ StatusCode,
15
+ MenuItem,
16
+ Button,
17
+ ButtonTheme,
18
+ ButtonSize,
19
+ ButtonType,
20
+ DropdownAlign,
21
+ ControlSize,
22
+ FormStatus,
23
+ Feedback,
24
+ FormError,
25
+ Toggle,
26
+ Breadcrumb,
27
+ Font,
28
+ TrackingVariables,
29
+ TriggerUpdate,
30
+ } from './core';
31
+
32
+ // Form Types
33
+ export type { FieldOption, SelectOption, Field, Form, TableColumn } from './form';
34
+
35
+ // Resource Types
36
+ export type { Intl, Resource, Item, User, Media, Preview, Modal, Filter, Uppy } from './resource';
37
+
38
+ // Panneau Definition Types
39
+ export type { Routes, Page, PanneauDefinition, Definition } from './panneau';
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Panneau Definition Types
3
+ * TypeScript interfaces for main Panneau configuration and definitions
4
+ */
5
+
6
+ import { Intl, Resource } from './resource';
7
+
8
+ /**
9
+ * Panneau route configuration
10
+ */
11
+ export interface Routes {
12
+ 'resources.index': string;
13
+ 'resources.create': string;
14
+ 'resources.store': string;
15
+ 'resources.show': string;
16
+ 'resources.edit': string;
17
+ 'resources.update': string;
18
+ 'resources.delete': string;
19
+ 'resources.destroy': string;
20
+ 'resources.duplicate': string;
21
+ 'resources.clone': string;
22
+ 'resources.restore': string;
23
+ }
24
+
25
+ /**
26
+ * Page definition
27
+ */
28
+ export interface Page {
29
+ component: string;
30
+ [key: string]: unknown;
31
+ }
32
+
33
+ /**
34
+ * Panneau definition (main configuration)
35
+ */
36
+ export interface PanneauDefinition {
37
+ name?: string;
38
+ resources?: Resource[];
39
+ routes?: Routes;
40
+ pages?: Record<string, Page>;
41
+ intl?: Intl;
42
+ }
43
+
44
+ /**
45
+ * Generic definition
46
+ */
47
+ export interface Definition {
48
+ name?: string;
49
+ [key: string]: unknown;
50
+ }
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Resource Types
3
+ * TypeScript interfaces for resources, items, users, media, and other entities
4
+ */
5
+ import { Field } from './form';
6
+
7
+ /**
8
+ * Internationalization configuration
9
+ */
10
+ export interface Intl {
11
+ locale?: string;
12
+ messages?: Record<string, string>;
13
+ values?: Record<string, string>;
14
+ }
15
+
16
+ /**
17
+ * Resource definition
18
+ */
19
+ export interface Resource {
20
+ id: string;
21
+ name: string;
22
+ intl?: Intl;
23
+ fields?: Field[];
24
+ forms?: Record<string, unknown>;
25
+ shows_in_navbar?: boolean;
26
+ }
27
+
28
+ /**
29
+ * Generic item (base interface for data items)
30
+ */
31
+ export interface Item {
32
+ id: string;
33
+ [key: string]: unknown;
34
+ }
35
+
36
+ /**
37
+ * User definition
38
+ */
39
+ export interface User {
40
+ id?: number | string;
41
+ [key: string]: unknown;
42
+ }
43
+
44
+ /**
45
+ * Media file definition
46
+ */
47
+ export interface Media {
48
+ id: string;
49
+ name: string;
50
+ type: string;
51
+ thumbnail_url?: string;
52
+ [key: string]: unknown;
53
+ }
54
+
55
+ /**
56
+ * Preview definition
57
+ */
58
+ export interface Preview {
59
+ id?: string;
60
+ [key: string]: unknown;
61
+ }
62
+
63
+ /**
64
+ * Modal definition
65
+ */
66
+ export interface Modal {
67
+ name?: string;
68
+ [key: string]: unknown;
69
+ }
70
+
71
+ /**
72
+ * Filter definition
73
+ */
74
+ export interface Filter {
75
+ id?: string;
76
+ component?: string;
77
+ [key: string]: unknown;
78
+ }
79
+
80
+ /**
81
+ * Uppy configuration
82
+ */
83
+ export interface Uppy {
84
+ tus?: Record<string, unknown>;
85
+ [key: string]: unknown;
86
+ }
87
+
88
+ /**
89
+ * Uppy instance
90
+ */
91
+ export interface uppy {
92
+ [key: string]: unknown;
93
+ }
package/es/utils.js CHANGED
@@ -47,7 +47,7 @@ function checkClickable(el) {
47
47
  // return true;
48
48
  // }
49
49
 
50
- if (tags.map(function (it) {
50
+ if (tagName && tags.map(function (it) {
51
51
  return it.toLowerCase();
52
52
  }).indexOf(tagName.toLowerCase()) !== -1) {
53
53
  return true;
@@ -150,9 +150,9 @@ function _copyExecCommand() {
150
150
  // Make a selection object representing the range of text selected by the user
151
151
  selection = window.getSelection();
152
152
  range = window.document.createRange();
153
- selection.removeAllRanges();
153
+ selection === null || selection === void 0 || selection.removeAllRanges();
154
154
  range.selectNode(span);
155
- selection.addRange(range);
155
+ selection === null || selection === void 0 || selection.addRange(range);
156
156
 
157
157
  // Copy text to the clipboard
158
158
  success = false;
@@ -160,7 +160,7 @@ function _copyExecCommand() {
160
160
  success = window.document.execCommand('copy');
161
161
  } finally {
162
162
  // Cleanup
163
- selection.removeAllRanges();
163
+ selection === null || selection === void 0 || selection.removeAllRanges();
164
164
  window.document.body.removeChild(span);
165
165
  }
166
166
  if (success) {
@@ -222,7 +222,7 @@ var _flattenComponents = function flattenComponents(components) {
222
222
  };
223
223
 
224
224
  var formatDuration = function formatDuration(timeInSeconds) {
225
- var numberOfSeconds = parseInt(timeInSeconds, 10); // don't forget the second param
225
+ var numberOfSeconds = parseInt(String(timeInSeconds), 10); // don't forget the second param
226
226
  var hours = Math.floor(numberOfSeconds / 3600);
227
227
  var minutes = Math.floor((numberOfSeconds - hours * 3600) / 60);
228
228
  var seconds = numberOfSeconds - hours * 3600 - minutes * 60;
@@ -247,7 +247,7 @@ var getComponent = function getComponent(component) {
247
247
  var props = _objectWithoutProperties(_ref, _excluded$1);
248
248
  return {
249
249
  name: component,
250
- props: props
250
+ props: Object.keys(props).length > 0 ? props : null
251
251
  };
252
252
  };
253
253
 
@@ -257,12 +257,13 @@ var getColumnFromField = function getColumnFromField(field) {
257
257
  return null;
258
258
  }
259
259
  // eslint-disable-next-line camelcase
260
- var name = field.name,
261
- _field$components = field.components,
262
- _field$components2 = _field$components === void 0 ? {} : _field$components,
263
- _field$components2$di = _field$components2.display,
264
- display = _field$components2$di === void 0 ? null : _field$components2$di,
265
- label = field.label;
260
+ var _ref = field,
261
+ name = _ref.name,
262
+ _ref$components = _ref.components,
263
+ _ref$components2 = _ref$components === void 0 ? {} : _ref$components,
264
+ _ref$components2$disp = _ref$components2.display,
265
+ display = _ref$components2$disp === void 0 ? null : _ref$components2$disp,
266
+ label = _ref.label;
266
267
  var _getComponent = getComponent(display),
267
268
  _getComponent$name = _getComponent.name,
268
269
  componentName = _getComponent$name === void 0 ? null : _getComponent$name,
@@ -277,16 +278,17 @@ var getColumnFromField = function getColumnFromField(field) {
277
278
  });
278
279
  };
279
280
  var getColumnsWithFields = function getColumnsWithFields(resource, columns) {
280
- var fields = resource.fields;
281
+ var _resource$fields = resource.fields,
282
+ fields = _resource$fields === void 0 ? [] : _resource$fields;
281
283
  var newColumns = columns !== null ? columns.map(function (column) {
282
- var _ref = isString(column) ? {
284
+ var _ref2 = isString(column) ? {
283
285
  field: column
284
286
  } : column,
285
- _ref$id = _ref.id,
286
- colId = _ref$id === void 0 ? null : _ref$id,
287
- _ref$field = _ref.field,
288
- colField = _ref$field === void 0 ? null : _ref$field,
289
- otherProps = _objectWithoutProperties(_ref, _excluded);
287
+ _ref2$id = _ref2.id,
288
+ colId = _ref2$id === void 0 ? null : _ref2$id,
289
+ _ref2$field = _ref2.field,
290
+ colField = _ref2$field === void 0 ? null : _ref2$field,
291
+ otherProps = _objectWithoutProperties(_ref2, _excluded);
290
292
  var fieldName = colField || colId;
291
293
  return _objectSpread(_objectSpread(_objectSpread({}, fieldName !== null ? getColumnFromField(fields.find(function (it) {
292
294
  return it.name === fieldName;
@@ -307,7 +309,6 @@ var getComponentFromName = function getComponentFromName() {
307
309
  return defaultComponent;
308
310
  }
309
311
  var pascalName = pascalCase(name);
310
- // console.log(name, pascalName, components);
311
312
  var component = components[pascalName] || components[name] || defaultComponent;
312
313
  if (!component) {
313
314
  console.warn('Could not find component from name', name, pascalName, components);
@@ -375,7 +376,7 @@ var getFieldFromPath = function getFieldFromPath(path, fields, fieldManager) {
375
376
  itemsField = _ref$itemsField === void 0 ? null : _ref$itemsField;
376
377
  if (itemsField !== null && key.match(/^[0-9]+$/)) {
377
378
  return _objectSpread(_objectSpread({}, itemsField), {}, {
378
- name: path.join('/'),
379
+ name: (isArray(path) ? path : [path]).join('/'),
379
380
  listItems: true
380
381
  });
381
382
  }
@@ -390,7 +391,8 @@ var getFileName = function getFileName() {
390
391
  if (url === null || typeof url.match === 'undefined') {
391
392
  return null;
392
393
  }
393
- return url.match(/([^/]+)(\?.*)?$/)[1] || url;
394
+ var match = url.match(/([^/]+)(\?.*)?$/);
395
+ return match ? match[1] : url;
394
396
  };
395
397
 
396
398
  var getPathValue = function getPathValue(it, path) {
@@ -403,9 +405,10 @@ var getPathValue = function getPathValue(it, path) {
403
405
  var getSelectOptions = function getSelectOptions(options) {
404
406
  return options.map(function (it) {
405
407
  if (isObject(it)) {
406
- var _it$label = it.label,
407
- label = _it$label === void 0 ? null : _it$label,
408
- value = it.value;
408
+ var _ref = it,
409
+ _ref$label = _ref.label,
410
+ label = _ref$label === void 0 ? null : _ref$label,
411
+ value = _ref.value;
409
412
  if (label === null) {
410
413
  return {
411
414
  value: value,
@@ -540,14 +543,19 @@ function selectPage(pageSelected, items, selectedItems, onSelectionChange) {
540
543
 
541
544
  var _setValue = function setValue(value, keyParts, fieldValue) {
542
545
  var key = keyParts.shift();
546
+ if (!key) {
547
+ return value;
548
+ }
543
549
  var isArray = key.match(/^[0-9]+$/) !== null;
544
550
  if (value !== null || fieldValue !== null) {
545
551
  if (isArray) {
546
552
  var index = parseInt(key, 10);
547
- var newArrayValue = fieldValue !== null ? [].concat(_toConsumableArray(value.slice(0, index)), [keyParts.length > 0 ? _setValue(value !== null ? value[index] || null : null, keyParts, fieldValue) : fieldValue], _toConsumableArray(value.slice(index + 1))) : [].concat(_toConsumableArray(value.slice(0, index)), _toConsumableArray(value.slice(index + 1)));
553
+ var arrayValue = value;
554
+ var newArrayValue = fieldValue !== null ? [].concat(_toConsumableArray(arrayValue.slice(0, index)), [keyParts.length > 0 ? _setValue(arrayValue !== null ? arrayValue[index] || null : null, keyParts, fieldValue) : fieldValue], _toConsumableArray(arrayValue.slice(index + 1))) : [].concat(_toConsumableArray(arrayValue.slice(0, index)), _toConsumableArray(arrayValue.slice(index + 1)));
548
555
  return newArrayValue.length > 0 ? newArrayValue : null;
549
556
  }
550
- return _objectSpread(_objectSpread({}, value), {}, _defineProperty({}, key, keyParts.length > 0 ? _setValue(value !== null ? value[key] || null : null, keyParts, fieldValue) : fieldValue));
557
+ var objectValue = value;
558
+ return _objectSpread(_objectSpread({}, objectValue), {}, _defineProperty({}, key, keyParts.length > 0 ? _setValue(objectValue !== null ? objectValue[key] || null : null, keyParts, fieldValue) : fieldValue));
551
559
  }
552
560
  return null;
553
561
  };
@@ -571,7 +579,7 @@ var _validateFields = function validateFields(fields, value) {
571
579
  if (field.type === 'fields' && field.fields) {
572
580
  return _validateFields(field.fields, value);
573
581
  }
574
- var val = value && value[field.name] ? value[field.name] : false;
582
+ var val = value && field.name && value[field.name] ? value[field.name] : false;
575
583
  return !(field.required && !val);
576
584
  }
577
585
  return acc;