@panneau/core 4.0.74 → 4.0.78

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/utils.d.ts CHANGED
@@ -38,14 +38,15 @@ declare function formatDuration(timeInSeconds: number | string): string;
38
38
  /**
39
39
  * Internationalization message definition
40
40
  */
41
- interface Message extends MessageDescriptor {
42
- id: string;
43
- defaultMessage?: string;
44
- }
41
+ type Message = MessageDescriptor;
45
42
  /**
46
43
  * Label can be either a message object or any React node
47
44
  */
48
45
  type Label = Message | ReactNode;
46
+ /**
47
+ * Form control size
48
+ */
49
+ type ControlSize = 'lg' | 'sm' | null;
49
50
  /**
50
51
  * Generic item (base interface for data items)
51
52
  */
@@ -53,6 +54,23 @@ interface Item {
53
54
  id: string;
54
55
  [key: string]: unknown;
55
56
  }
57
+ /**
58
+ * Generic definition
59
+ */
60
+ interface Definition {
61
+ id: string;
62
+ component?: string | ElementType;
63
+ [key: string]: unknown;
64
+ }
65
+ interface RouteDefinition {
66
+ path?: string;
67
+ route?: string;
68
+ component: string | ElementType;
69
+ [key: string]: unknown;
70
+ }
71
+ interface PageDefinition {
72
+ component: string | ElementType;
73
+ }
56
74
 
57
75
  /**
58
76
  * Form Types
@@ -72,15 +90,23 @@ type SelectOption = string | number | {
72
90
  interface Field {
73
91
  name?: string;
74
92
  type?: string;
75
- component?: string | ElementType;
76
- label?: ReactNode;
93
+ label?: Label;
94
+ component?: string;
95
+ size?: ControlSize;
96
+ [key: string]: unknown;
77
97
  }
78
98
  /**
79
99
  * Form definition
80
100
  */
81
101
  interface Form {
82
- title: ReactNode;
102
+ title?: ReactNode;
83
103
  fields?: Field[];
104
+ method?: string | null;
105
+ action?: string | null;
106
+ submitButtonLabel?: Label | null;
107
+ [key: string]: unknown;
108
+ }
109
+ interface FormDefinition extends Form, Definition {
84
110
  }
85
111
 
86
112
  /**
@@ -138,15 +164,33 @@ interface ResourceIndex {
138
164
  fields?: Field[];
139
165
  [key: string]: unknown;
140
166
  }
167
+ interface ResourcePages {
168
+ index?: PageDefinition;
169
+ show?: PageDefinition;
170
+ create?: PageDefinition;
171
+ edit?: PageDefinition;
172
+ delete?: PageDefinition;
173
+ duplicate?: PageDefinition;
174
+ [key: string]: PageDefinition | undefined;
175
+ }
176
+ interface ResourceForms {
177
+ default: FormDefinition | null;
178
+ create: FormDefinition | null;
179
+ edit: FormDefinition | null;
180
+ delete: FormDefinition | null;
181
+ modal: FormDefinition | null;
182
+ [key: string]: FormDefinition | null;
183
+ }
141
184
  interface Resource {
142
185
  id: string;
143
186
  name: string;
144
187
  intl?: ResourceIntl;
145
188
  fields?: Field[];
146
189
  index?: ResourceIndex;
147
- forms?: Record<string, Form>;
148
- shows_in_navbar?: boolean;
190
+ forms?: ResourceForms;
149
191
  settings?: Record<string, unknown>;
192
+ extraRoutes?: RouteDefinition[];
193
+ pages?: ResourcePages;
150
194
  }
151
195
  /**
152
196
  * Filter definition
@@ -157,19 +201,6 @@ interface Filter {
157
201
  [key: string]: unknown;
158
202
  }
159
203
 
160
- /**
161
- * Panneau Definition Types
162
- * TypeScript interfaces for main Panneau configuration and definitions
163
- */
164
-
165
- /**
166
- * Generic definition
167
- */
168
- interface Definition {
169
- name?: string;
170
- [key: string]: unknown;
171
- }
172
-
173
204
  declare function getColumnsWithFields(resource: Resource, columns: TableColumn[] | null): Column[];
174
205
 
175
206
  interface ComponentResult {
@@ -181,7 +212,7 @@ declare function getComponent(component: string | {
181
212
  [key: string]: unknown;
182
213
  }): ComponentResult;
183
214
 
184
- declare function getComponentFromName(name?: string | ElementType | null, components?: Record<string, ElementType> | null, defaultComponent?: ElementType | null): ElementType | null;
215
+ declare function getComponentFromName(name?: string | ElementType | null, components?: Record<string, ElementType> | null, defaultComponent?: ElementType | string | null): ElementType | null;
185
216
 
186
217
  declare function getDefinitionFromId<T extends Definition = Definition>(id?: string | null, items?: T[] | null, defaultObject?: T | null): T | null;
187
218
 
package/dist/utils.js CHANGED
@@ -229,13 +229,14 @@ function getColumnsWithFields(resource, columns) {
229
229
 
230
230
  function getComponentFromName(name = null, components = {}, defaultComponent = null) {
231
231
  if (components === null || name === null) {
232
- return defaultComponent;
232
+ return !isString(defaultComponent) ? defaultComponent : null;
233
233
  }
234
234
  if (isObject(name) || isFunction(name)) {
235
235
  return name;
236
236
  }
237
237
  const pascalName = pascalCase(name);
238
- const component = components[pascalName] || components[name] || defaultComponent;
238
+ const pascalDefaultName = isString(defaultComponent) ? pascalCase(defaultComponent) : null;
239
+ const component = components[pascalName] || components[name] || (isString(pascalDefaultName) ? components[pascalDefaultName] : null) || (isString(defaultComponent) ? components[defaultComponent] : null) || defaultComponent;
239
240
  if (!component) {
240
241
  console.warn('Could not find component from name', name, pascalName, components);
241
242
  }
@@ -341,7 +342,7 @@ function getSelectOptions(options) {
341
342
  }
342
343
 
343
344
  function isMessage(message) {
344
- return isObject(message) && typeof message.defaultMessage !== 'undefined';
345
+ return isObject(message) && (typeof message.defaultMessage !== 'undefined' || typeof message.id !== 'undefined');
345
346
  }
346
347
 
347
348
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panneau/core",
3
- "version": "4.0.74",
3
+ "version": "4.0.78",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "javascript"
@@ -96,5 +96,5 @@
96
96
  "publishConfig": {
97
97
  "access": "public"
98
98
  },
99
- "gitHead": "122cadcf8ea5faacc035e7fe911fbdfb9fb87d26"
99
+ "gitHead": "669f20a39ca9545acbe0f2279c6d1af23e43ae6e"
100
100
  }