@panneau/core 3.0.300 → 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,133 @@
1
+ /**
2
+ * Core UI Types
3
+ * TypeScript interfaces corresponding to PanneauPropTypes
4
+ */
5
+ import { ReactNode } from 'react';
6
+
7
+ /**
8
+ * Internationalization message definition
9
+ */
10
+ export interface Message {
11
+ id: string;
12
+ defaultMessage?: string;
13
+ }
14
+
15
+ /**
16
+ * Label can be either a message object or any React node
17
+ */
18
+ export type Label = Message | ReactNode;
19
+
20
+ /**
21
+ * HTTP status code (number or string)
22
+ */
23
+ export type StatusCode = number | string;
24
+
25
+ /**
26
+ * Menu item definition
27
+ */
28
+ export interface MenuItem {
29
+ id?: number | string;
30
+ label?: Label;
31
+ url?: string;
32
+ external?: boolean;
33
+ active?: boolean;
34
+ }
35
+
36
+ /**
37
+ * Button definition
38
+ */
39
+ export interface Button {
40
+ id?: string;
41
+ label?: Label;
42
+ onClick?: () => void;
43
+ href?: string;
44
+ target?: string;
45
+ theme?: ButtonTheme;
46
+ size?: ButtonSize;
47
+ type?: ButtonType;
48
+ disabled?: boolean;
49
+ external?: boolean;
50
+ }
51
+
52
+ /**
53
+ * Button theme variants (Bootstrap 5)
54
+ */
55
+ export type ButtonTheme =
56
+ | 'primary'
57
+ | 'secondary'
58
+ | 'success'
59
+ | 'danger'
60
+ | 'warning'
61
+ | 'info'
62
+ | 'light'
63
+ | 'dark'
64
+ | null;
65
+
66
+ /**
67
+ * Button size variants
68
+ */
69
+ export type ButtonSize = 'lg' | 'md' | 'sm' | null;
70
+
71
+ /**
72
+ * Button type attribute
73
+ */
74
+ export type ButtonType = 'button' | 'submit';
75
+
76
+ /**
77
+ * Dropdown alignment
78
+ */
79
+ export type DropdownAlign = 'start' | 'end';
80
+
81
+ /**
82
+ * Form control size
83
+ */
84
+ export type ControlSize = 'lg' | 'sm' | null;
85
+
86
+ /**
87
+ * Form status states
88
+ */
89
+ export type FormStatus = 'loading' | 'success' | 'error' | null;
90
+
91
+ /**
92
+ * Form feedback states
93
+ */
94
+ export type Feedback = 'valid' | 'invalid' | 'loading' | null;
95
+
96
+ /**
97
+ * Form error object
98
+ */
99
+ export interface FormError {
100
+ message?: string;
101
+ }
102
+
103
+ /**
104
+ * Toggle definition
105
+ */
106
+ export interface Toggle {
107
+ key?: string;
108
+ label?: string;
109
+ }
110
+
111
+ /**
112
+ * Breadcrumb definition
113
+ */
114
+ export interface Breadcrumb {
115
+ url?: string;
116
+ }
117
+
118
+ /**
119
+ * Font definition
120
+ */
121
+ export interface Font {
122
+ // Properties to be defined based on requirements
123
+ }
124
+
125
+ /**
126
+ * Tracking variables
127
+ */
128
+ export type TrackingVariables = Record<string, unknown>;
129
+
130
+ /**
131
+ * Trigger update identifier
132
+ */
133
+ export type TriggerUpdate = string;
@@ -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
@@ -2,7 +2,7 @@ import isNumber from 'lodash-es/isNumber';
2
2
  import { snakeCase } from 'snake-case';
3
3
  import isObject from 'lodash-es/isObject';
4
4
  import { useEffect, isValidElement } from 'react';
5
- import _regeneratorRuntime from '@babel/runtime/helpers/regeneratorRuntime';
5
+ import _regenerator from '@babel/runtime/helpers/regenerator';
6
6
  import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
7
7
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
8
8
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
@@ -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;
@@ -110,20 +110,17 @@ function copyClipboardApi(_x) {
110
110
  return _copyClipboardApi.apply(this, arguments);
111
111
  }
112
112
  function _copyClipboardApi() {
113
- _copyClipboardApi = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(text) {
114
- return _regeneratorRuntime().wrap(function _callee$(_context) {
115
- while (1) switch (_context.prev = _context.next) {
113
+ _copyClipboardApi = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(text) {
114
+ return _regenerator().w(function (_context) {
115
+ while (1) switch (_context.n) {
116
116
  case 0:
117
117
  if (navigator.clipboard) {
118
- _context.next = 2;
118
+ _context.n = 1;
119
119
  break;
120
120
  }
121
121
  throw makeError();
122
- case 2:
123
- return _context.abrupt("return", navigator.clipboard.writeText(text));
124
- case 3:
125
- case "end":
126
- return _context.stop();
122
+ case 1:
123
+ return _context.a(2, navigator.clipboard.writeText(text));
127
124
  }
128
125
  }, _callee);
129
126
  }));
@@ -133,10 +130,10 @@ function copyExecCommand(_x2) {
133
130
  return _copyExecCommand.apply(this, arguments);
134
131
  }
135
132
  function _copyExecCommand() {
136
- _copyExecCommand = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(text) {
133
+ _copyExecCommand = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(text) {
137
134
  var span, selection, range, success;
138
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
139
- while (1) switch (_context2.prev = _context2.next) {
135
+ return _regenerator().w(function (_context2) {
136
+ while (1) switch (_context2.n) {
140
137
  case 0:
141
138
  // Put the text to copy into a <span>
142
139
  span = document.createElement('span');
@@ -153,9 +150,9 @@ function _copyExecCommand() {
153
150
  // Make a selection object representing the range of text selected by the user
154
151
  selection = window.getSelection();
155
152
  range = window.document.createRange();
156
- selection.removeAllRanges();
153
+ selection === null || selection === void 0 || selection.removeAllRanges();
157
154
  range.selectNode(span);
158
- selection.addRange(range);
155
+ selection === null || selection === void 0 || selection.addRange(range);
159
156
 
160
157
  // Copy text to the clipboard
161
158
  success = false;
@@ -163,17 +160,16 @@ function _copyExecCommand() {
163
160
  success = window.document.execCommand('copy');
164
161
  } finally {
165
162
  // Cleanup
166
- selection.removeAllRanges();
163
+ selection === null || selection === void 0 || selection.removeAllRanges();
167
164
  window.document.body.removeChild(span);
168
165
  }
169
166
  if (success) {
170
- _context2.next = 15;
167
+ _context2.n = 1;
171
168
  break;
172
169
  }
173
170
  throw makeError();
174
- case 15:
175
- case "end":
176
- return _context2.stop();
171
+ case 1:
172
+ return _context2.a(2);
177
173
  }
178
174
  }, _callee2);
179
175
  }));
@@ -183,34 +179,34 @@ function copyToClipboard(_x3) {
183
179
  return _copyToClipboard.apply(this, arguments);
184
180
  }
185
181
  function _copyToClipboard() {
186
- _copyToClipboard = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(text) {
187
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
188
- while (1) switch (_context3.prev = _context3.next) {
182
+ _copyToClipboard = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(text) {
183
+ var _t, _t2;
184
+ return _regenerator().w(function (_context3) {
185
+ while (1) switch (_context3.p = _context3.n) {
189
186
  case 0:
190
- _context3.prev = 0;
191
- _context3.next = 3;
187
+ _context3.p = 0;
188
+ _context3.n = 1;
192
189
  return copyClipboardApi(text);
193
- case 3:
194
- _context3.next = 15;
190
+ case 1:
191
+ _context3.n = 6;
195
192
  break;
196
- case 5:
197
- _context3.prev = 5;
198
- _context3.t0 = _context3["catch"](0);
199
- _context3.prev = 7;
200
- _context3.next = 10;
193
+ case 2:
194
+ _context3.p = 2;
195
+ _t = _context3.v;
196
+ _context3.p = 3;
197
+ _context3.n = 4;
201
198
  return copyExecCommand(text);
202
- case 10:
203
- _context3.next = 15;
199
+ case 4:
200
+ _context3.n = 6;
204
201
  break;
205
- case 12:
206
- _context3.prev = 12;
207
- _context3.t1 = _context3["catch"](7);
208
- throw _context3.t1 || _context3.t0 || makeError();
209
- case 15:
210
- case "end":
211
- return _context3.stop();
202
+ case 5:
203
+ _context3.p = 5;
204
+ _t2 = _context3.v;
205
+ throw _t2 || _t || makeError();
206
+ case 6:
207
+ return _context3.a(2);
212
208
  }
213
- }, _callee3, null, [[0, 5], [7, 12]]);
209
+ }, _callee3, null, [[3, 5], [0, 2]]);
214
210
  }));
215
211
  return _copyToClipboard.apply(this, arguments);
216
212
  }
@@ -226,7 +222,7 @@ var _flattenComponents = function flattenComponents(components) {
226
222
  };
227
223
 
228
224
  var formatDuration = function formatDuration(timeInSeconds) {
229
- var numberOfSeconds = parseInt(timeInSeconds, 10); // don't forget the second param
225
+ var numberOfSeconds = parseInt(String(timeInSeconds), 10); // don't forget the second param
230
226
  var hours = Math.floor(numberOfSeconds / 3600);
231
227
  var minutes = Math.floor((numberOfSeconds - hours * 3600) / 60);
232
228
  var seconds = numberOfSeconds - hours * 3600 - minutes * 60;
@@ -251,7 +247,7 @@ var getComponent = function getComponent(component) {
251
247
  var props = _objectWithoutProperties(_ref, _excluded$1);
252
248
  return {
253
249
  name: component,
254
- props: props
250
+ props: Object.keys(props).length > 0 ? props : null
255
251
  };
256
252
  };
257
253
 
@@ -261,12 +257,13 @@ var getColumnFromField = function getColumnFromField(field) {
261
257
  return null;
262
258
  }
263
259
  // eslint-disable-next-line camelcase
264
- var name = field.name,
265
- _field$components = field.components,
266
- _field$components2 = _field$components === void 0 ? {} : _field$components,
267
- _field$components2$di = _field$components2.display,
268
- display = _field$components2$di === void 0 ? null : _field$components2$di,
269
- 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;
270
267
  var _getComponent = getComponent(display),
271
268
  _getComponent$name = _getComponent.name,
272
269
  componentName = _getComponent$name === void 0 ? null : _getComponent$name,
@@ -281,16 +278,17 @@ var getColumnFromField = function getColumnFromField(field) {
281
278
  });
282
279
  };
283
280
  var getColumnsWithFields = function getColumnsWithFields(resource, columns) {
284
- var fields = resource.fields;
281
+ var _resource$fields = resource.fields,
282
+ fields = _resource$fields === void 0 ? [] : _resource$fields;
285
283
  var newColumns = columns !== null ? columns.map(function (column) {
286
- var _ref = isString(column) ? {
284
+ var _ref2 = isString(column) ? {
287
285
  field: column
288
286
  } : column,
289
- _ref$id = _ref.id,
290
- colId = _ref$id === void 0 ? null : _ref$id,
291
- _ref$field = _ref.field,
292
- colField = _ref$field === void 0 ? null : _ref$field,
293
- 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);
294
292
  var fieldName = colField || colId;
295
293
  return _objectSpread(_objectSpread(_objectSpread({}, fieldName !== null ? getColumnFromField(fields.find(function (it) {
296
294
  return it.name === fieldName;
@@ -311,7 +309,6 @@ var getComponentFromName = function getComponentFromName() {
311
309
  return defaultComponent;
312
310
  }
313
311
  var pascalName = pascalCase(name);
314
- // console.log(name, pascalName, components);
315
312
  var component = components[pascalName] || components[name] || defaultComponent;
316
313
  if (!component) {
317
314
  console.warn('Could not find component from name', name, pascalName, components);
@@ -379,7 +376,7 @@ var getFieldFromPath = function getFieldFromPath(path, fields, fieldManager) {
379
376
  itemsField = _ref$itemsField === void 0 ? null : _ref$itemsField;
380
377
  if (itemsField !== null && key.match(/^[0-9]+$/)) {
381
378
  return _objectSpread(_objectSpread({}, itemsField), {}, {
382
- name: path.join('/'),
379
+ name: (isArray(path) ? path : [path]).join('/'),
383
380
  listItems: true
384
381
  });
385
382
  }
@@ -394,7 +391,8 @@ var getFileName = function getFileName() {
394
391
  if (url === null || typeof url.match === 'undefined') {
395
392
  return null;
396
393
  }
397
- return url.match(/([^/]+)(\?.*)?$/)[1] || url;
394
+ var match = url.match(/([^/]+)(\?.*)?$/);
395
+ return match ? match[1] : url;
398
396
  };
399
397
 
400
398
  var getPathValue = function getPathValue(it, path) {
@@ -407,9 +405,10 @@ var getPathValue = function getPathValue(it, path) {
407
405
  var getSelectOptions = function getSelectOptions(options) {
408
406
  return options.map(function (it) {
409
407
  if (isObject(it)) {
410
- var _it$label = it.label,
411
- label = _it$label === void 0 ? null : _it$label,
412
- 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;
413
412
  if (label === null) {
414
413
  return {
415
414
  value: value,
@@ -544,14 +543,19 @@ function selectPage(pageSelected, items, selectedItems, onSelectionChange) {
544
543
 
545
544
  var _setValue = function setValue(value, keyParts, fieldValue) {
546
545
  var key = keyParts.shift();
546
+ if (!key) {
547
+ return value;
548
+ }
547
549
  var isArray = key.match(/^[0-9]+$/) !== null;
548
550
  if (value !== null || fieldValue !== null) {
549
551
  if (isArray) {
550
552
  var index = parseInt(key, 10);
551
- 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)));
552
555
  return newArrayValue.length > 0 ? newArrayValue : null;
553
556
  }
554
- 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));
555
559
  }
556
560
  return null;
557
561
  };
@@ -575,7 +579,7 @@ var _validateFields = function validateFields(fields, value) {
575
579
  if (field.type === 'fields' && field.fields) {
576
580
  return _validateFields(field.fields, value);
577
581
  }
578
- var val = value && value[field.name] ? value[field.name] : false;
582
+ var val = value && field.name && value[field.name] ? value[field.name] : false;
579
583
  return !(field.required && !val);
580
584
  }
581
585
  return acc;