@lad-sapienza/scms-core 0.1.0-alpha.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.
Files changed (64) hide show
  1. package/LICENSE +14 -0
  2. package/README.md +73 -0
  3. package/components/BSNavbar.tsx +264 -0
  4. package/components/DataTb/DataTb.astro +33 -0
  5. package/components/DataTb/DataTb.tsx +340 -0
  6. package/components/DataTb/DataTbMdx.tsx +75 -0
  7. package/components/DataTb/README.md +275 -0
  8. package/components/DataTb/index.ts +36 -0
  9. package/components/DataTb/sources/ApiSource.tsx +89 -0
  10. package/components/DataTb/sources/CsvSource.tsx +69 -0
  11. package/components/DataTb/sources/DirectusSource.tsx +98 -0
  12. package/components/DataTb/sources/JsonSource.tsx +65 -0
  13. package/components/DataTb/sources/index.ts +17 -0
  14. package/components/DataTb/types.ts +215 -0
  15. package/components/DataTb/utils.ts +186 -0
  16. package/components/Gallery/Gallery.astro +65 -0
  17. package/components/Gallery/Gallery.tsx +136 -0
  18. package/components/Gallery/README.md +118 -0
  19. package/components/Gallery/__tests__/galleryUtils.test.ts +178 -0
  20. package/components/Gallery/galleryUtils.ts +186 -0
  21. package/components/Gallery/index.ts +7 -0
  22. package/components/Gallery/react-photoswipe-gallery.d.ts +26 -0
  23. package/components/Gallery/types.ts +46 -0
  24. package/components/Gallery/virtual-gallery.d.ts +15 -0
  25. package/components/Map/LayerControl.tsx +368 -0
  26. package/components/Map/Map.tsx +735 -0
  27. package/components/Map/MapMdx.tsx +37 -0
  28. package/components/Map/RasterLayerLibre.tsx +33 -0
  29. package/components/Map/Search/SearchOperators.ts +31 -0
  30. package/components/Map/Search/SearchUI.tsx +75 -0
  31. package/components/Map/Search/SearchUIAdvanced.tsx +289 -0
  32. package/components/Map/Search/SearchUISimple.tsx +115 -0
  33. package/components/Map/Search/index.ts +7 -0
  34. package/components/Map/defaultBasemaps.ts +88 -0
  35. package/components/Map/index.ts +6 -0
  36. package/components/Map/types.ts +179 -0
  37. package/components/Map/utils.ts +367 -0
  38. package/components/README.md +62 -0
  39. package/components/Record/Field.tsx +35 -0
  40. package/components/Record/Image.tsx +114 -0
  41. package/components/Record/RecordFetcher.tsx +127 -0
  42. package/components/Record/context.tsx +14 -0
  43. package/components/Record/index.ts +11 -0
  44. package/components/Record/useRecordFetcher.ts +104 -0
  45. package/components/Record/utils.ts +13 -0
  46. package/components/SEO/SEO.astro +132 -0
  47. package/components/TableOfContents/TableOfContents.astro +86 -0
  48. package/components/ZoteroGeoViewer/README.md +195 -0
  49. package/components/ZoteroGeoViewer/ZoteroGeoViewer.astro +26 -0
  50. package/components/ZoteroGeoViewer/ZoteroGeoViewer.tsx +483 -0
  51. package/components/ZoteroGeoViewer/ZoteroRecordsPreview.tsx +185 -0
  52. package/components/ZoteroGeoViewer/index.ts +16 -0
  53. package/components/ZoteroGeoViewer/types.ts +123 -0
  54. package/index.ts +26 -0
  55. package/integrations/__tests__/galleryIntegration.test.ts +70 -0
  56. package/integrations/contentAssetsIntegration.ts +132 -0
  57. package/integrations/directusLoader.ts +98 -0
  58. package/integrations/galleryIntegration.ts +78 -0
  59. package/package.json +56 -0
  60. package/scms.ts +95 -0
  61. package/utils/content.ts +88 -0
  62. package/utils/data-fetcher.ts +128 -0
  63. package/utils/directus-config.ts +160 -0
  64. package/utils/record-fetcher.ts +132 -0
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Simplified record fetching utility for Directus records
3
+ */
4
+
5
+ import { fetchData } from './data-fetcher.js';
6
+ import { directusShorthandToConfig } from './directus-config.js';
7
+
8
+ export interface GetRecordOptions {
9
+ table: string;
10
+ id: string;
11
+ fields?: string[];
12
+ url?: string;
13
+ token?: string;
14
+ }
15
+
16
+ /**
17
+ * Fetch a single record from Directus with simplified API
18
+ *
19
+ * @param options - Record fetching options
20
+ * @returns Promise resolving to the record object or null if not found
21
+ *
22
+ * @example
23
+ * ```js
24
+ * // Basic usage
25
+ * const record = await getRecord({ table: 'articles', id: '123' });
26
+ *
27
+ * // With specific fields
28
+ * const record = await getRecord({
29
+ * table: 'articles',
30
+ * id: '123',
31
+ * fields: ['title', 'content', 'author.*']
32
+ * });
33
+ *
34
+ * // With custom credentials
35
+ * const record = await getRecord({
36
+ * table: 'articles',
37
+ * id: '123',
38
+ * url: 'https://custom.directus.app',
39
+ * token: 'custom-token'
40
+ * });
41
+ * ```
42
+ */
43
+ export async function getRecord(options: GetRecordOptions): Promise<any | null> {
44
+ const {
45
+ table,
46
+ id,
47
+ fields = ['*.*.*'],
48
+ url = import.meta.env.PUBLIC_DIRECTUS_URL,
49
+ token = import.meta.env.PUBLIC_DIRECTUS_TOKEN
50
+ } = options;
51
+
52
+ try {
53
+ // Configure Directus connection
54
+ const config = directusShorthandToConfig({
55
+ table,
56
+ url,
57
+ token
58
+ });
59
+
60
+ if (!config) {
61
+ console.error('Failed to configure Directus connection');
62
+ return null;
63
+ }
64
+
65
+ // Normalize ID: convert to number if it looks numeric, otherwise keep as string
66
+ const normalizedId = /^\d+$/.test(id) ? Number(id) : id;
67
+
68
+ // Fetch the record
69
+ const recordData = await fetchData({
70
+ type: 'directus',
71
+ collection: table,
72
+ config: config.config,
73
+ itemId: normalizedId,
74
+ fields
75
+ });
76
+
77
+ // Return the first (and should be only) record
78
+ return recordData && recordData.length > 0 ? recordData[0] : null;
79
+
80
+ } catch (err) {
81
+ console.error(`Error fetching record ${id} from ${table}:`, err);
82
+ return null;
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Simplified function for the most common use case
88
+ *
89
+ * @param table - Directus table/collection name
90
+ * @param id - Record ID
91
+ * @returns Promise resolving to the record object or null
92
+ *
93
+ * @example
94
+ * ```js
95
+ * const record = await getRecordById('articles', '123');
96
+ * ```
97
+ */
98
+ export async function getRecordById(table: string, id: string): Promise<any | null> {
99
+ return getRecord({ table, id });
100
+ }
101
+
102
+ /**
103
+ * Ultra-simplified function for Astro dynamic routes
104
+ * Automatically extracts table and id from Astro.params
105
+ *
106
+ * @param astro - The Astro global object
107
+ * @returns Promise resolving to the record object or null
108
+ *
109
+ * @example
110
+ * ```astro
111
+ * ---
112
+ * const record = await getRecordFromParams(Astro);
113
+ * ---
114
+ * ```
115
+ */
116
+ export async function getRecordFromParams(astro: any): Promise<any | null> {
117
+ const { table, id } = astro.params;
118
+
119
+ if (!table || !id) {
120
+ return null;
121
+ }
122
+
123
+ const fieldsParam = astro?.url?.searchParams?.get('fields');
124
+ const fields = fieldsParam
125
+ ? fieldsParam
126
+ .split(',')
127
+ .map((field: string) => field.trim())
128
+ .filter(Boolean)
129
+ : undefined;
130
+
131
+ return getRecord({ table, id, fields });
132
+ }